]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
Merge pull request #10969 from donaldsharp/test_multicast_remove_support_bundle_colle...
[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_nexthop.h"
57 #include "bgpd/bgp_network.h"
58 #include "bgpd/bgp_open.h"
59 #include "bgpd/bgp_regex.h"
60 #include "bgpd/bgp_route.h"
61 #include "bgpd/bgp_mplsvpn.h"
62 #include "bgpd/bgp_zebra.h"
63 #include "bgpd/bgp_table.h"
64 #include "bgpd/bgp_vty.h"
65 #include "bgpd/bgp_mpath.h"
66 #include "bgpd/bgp_packet.h"
67 #include "bgpd/bgp_updgrp.h"
68 #include "bgpd/bgp_bfd.h"
69 #include "bgpd/bgp_io.h"
70 #include "bgpd/bgp_evpn.h"
71 #include "bgpd/bgp_evpn_vty.h"
72 #include "bgpd/bgp_evpn_mh.h"
73 #include "bgpd/bgp_addpath.h"
74 #include "bgpd/bgp_mac.h"
75 #include "bgpd/bgp_flowspec.h"
76 #include "bgpd/bgp_conditional_adv.h"
77 #ifdef ENABLE_BGP_VNC
78 #include "bgpd/rfapi/bgp_rfapi_cfg.h"
79 #endif
80
81 FRR_CFG_DEFAULT_BOOL(BGP_IMPORT_CHECK,
82 {
83 .val_bool = false,
84 .match_profile = "traditional",
85 .match_version = "< 7.4",
86 },
87 { .val_bool = true },
88 );
89 FRR_CFG_DEFAULT_BOOL(BGP_SHOW_HOSTNAME,
90 { .val_bool = true, .match_profile = "datacenter", },
91 { .val_bool = false },
92 );
93 FRR_CFG_DEFAULT_BOOL(BGP_SHOW_NEXTHOP_HOSTNAME,
94 { .val_bool = true, .match_profile = "datacenter", },
95 { .val_bool = false },
96 );
97 FRR_CFG_DEFAULT_BOOL(BGP_LOG_NEIGHBOR_CHANGES,
98 { .val_bool = true, .match_profile = "datacenter", },
99 { .val_bool = false },
100 );
101 FRR_CFG_DEFAULT_BOOL(BGP_DETERMINISTIC_MED,
102 { .val_bool = true, .match_profile = "datacenter", },
103 { .val_bool = false },
104 );
105 FRR_CFG_DEFAULT_ULONG(BGP_CONNECT_RETRY,
106 { .val_ulong = 10, .match_profile = "datacenter", },
107 { .val_ulong = 120 },
108 );
109 FRR_CFG_DEFAULT_ULONG(BGP_HOLDTIME,
110 { .val_ulong = 9, .match_profile = "datacenter", },
111 { .val_ulong = 180 },
112 );
113 FRR_CFG_DEFAULT_ULONG(BGP_KEEPALIVE,
114 { .val_ulong = 3, .match_profile = "datacenter", },
115 { .val_ulong = 60 },
116 );
117 FRR_CFG_DEFAULT_BOOL(BGP_EBGP_REQUIRES_POLICY,
118 { .val_bool = false, .match_profile = "datacenter", },
119 { .val_bool = false, .match_version = "< 7.4", },
120 { .val_bool = true },
121 );
122 FRR_CFG_DEFAULT_BOOL(BGP_SUPPRESS_DUPLICATES,
123 { .val_bool = false, .match_version = "< 7.6", },
124 { .val_bool = true },
125 );
126
127 DEFINE_HOOK(bgp_inst_config_write,
128 (struct bgp *bgp, struct vty *vty),
129 (bgp, vty));
130 DEFINE_HOOK(bgp_snmp_update_last_changed, (struct bgp *bgp), (bgp));
131 DEFINE_HOOK(bgp_snmp_init_stats, (struct bgp *bgp), (bgp));
132
133 static struct peer_group *listen_range_exists(struct bgp *bgp,
134 struct prefix *range, int exact);
135
136 /* Show BGP peer's information. */
137 enum show_type {
138 show_all,
139 show_peer,
140 show_ipv4_all,
141 show_ipv6_all,
142 show_ipv4_peer,
143 show_ipv6_peer
144 };
145
146 static struct peer_group *listen_range_exists(struct bgp *bgp,
147 struct prefix *range, int exact);
148
149 static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
150 struct bgp *bgp,
151 bool use_json,
152 json_object *json);
153
154 static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
155 enum show_type type,
156 const char *ip_str,
157 afi_t afi, bool use_json);
158
159 static enum node_type bgp_node_type(afi_t afi, safi_t safi)
160 {
161 switch (afi) {
162 case AFI_IP:
163 switch (safi) {
164 case SAFI_UNICAST:
165 return BGP_IPV4_NODE;
166 case SAFI_MULTICAST:
167 return BGP_IPV4M_NODE;
168 case SAFI_LABELED_UNICAST:
169 return BGP_IPV4L_NODE;
170 case SAFI_MPLS_VPN:
171 return BGP_VPNV4_NODE;
172 case SAFI_FLOWSPEC:
173 return BGP_FLOWSPECV4_NODE;
174 default:
175 /* not expected */
176 return BGP_IPV4_NODE;
177 }
178 case AFI_IP6:
179 switch (safi) {
180 case SAFI_UNICAST:
181 return BGP_IPV6_NODE;
182 case SAFI_MULTICAST:
183 return BGP_IPV6M_NODE;
184 case SAFI_LABELED_UNICAST:
185 return BGP_IPV6L_NODE;
186 case SAFI_MPLS_VPN:
187 return BGP_VPNV6_NODE;
188 case SAFI_FLOWSPEC:
189 return BGP_FLOWSPECV6_NODE;
190 default:
191 /* not expected */
192 return BGP_IPV4_NODE;
193 }
194 case AFI_L2VPN:
195 return BGP_EVPN_NODE;
196 case AFI_UNSPEC:
197 case AFI_MAX:
198 // We should never be here but to clarify the switch statement..
199 return BGP_IPV4_NODE;
200 }
201
202 // Impossible to happen
203 return BGP_IPV4_NODE;
204 }
205
206 static const char *get_afi_safi_vty_str(afi_t afi, safi_t safi)
207 {
208 if (afi == AFI_IP) {
209 if (safi == SAFI_UNICAST)
210 return "IPv4 Unicast";
211 if (safi == SAFI_MULTICAST)
212 return "IPv4 Multicast";
213 if (safi == SAFI_LABELED_UNICAST)
214 return "IPv4 Labeled Unicast";
215 if (safi == SAFI_MPLS_VPN)
216 return "IPv4 VPN";
217 if (safi == SAFI_ENCAP)
218 return "IPv4 Encap";
219 if (safi == SAFI_FLOWSPEC)
220 return "IPv4 Flowspec";
221 } else if (afi == AFI_IP6) {
222 if (safi == SAFI_UNICAST)
223 return "IPv6 Unicast";
224 if (safi == SAFI_MULTICAST)
225 return "IPv6 Multicast";
226 if (safi == SAFI_LABELED_UNICAST)
227 return "IPv6 Labeled Unicast";
228 if (safi == SAFI_MPLS_VPN)
229 return "IPv6 VPN";
230 if (safi == SAFI_ENCAP)
231 return "IPv6 Encap";
232 if (safi == SAFI_FLOWSPEC)
233 return "IPv6 Flowspec";
234 } else if (afi == AFI_L2VPN) {
235 if (safi == SAFI_EVPN)
236 return "L2VPN EVPN";
237 }
238
239 return "Unknown";
240 }
241
242 /*
243 * Please note that we have intentionally camelCased
244 * the return strings here. So if you want
245 * to use this function, please ensure you
246 * are doing this within json output
247 */
248 static const char *get_afi_safi_json_str(afi_t afi, safi_t safi)
249 {
250 if (afi == AFI_IP) {
251 if (safi == SAFI_UNICAST)
252 return "ipv4Unicast";
253 if (safi == SAFI_MULTICAST)
254 return "ipv4Multicast";
255 if (safi == SAFI_LABELED_UNICAST)
256 return "ipv4LabeledUnicast";
257 if (safi == SAFI_MPLS_VPN)
258 return "ipv4Vpn";
259 if (safi == SAFI_ENCAP)
260 return "ipv4Encap";
261 if (safi == SAFI_FLOWSPEC)
262 return "ipv4Flowspec";
263 } else if (afi == AFI_IP6) {
264 if (safi == SAFI_UNICAST)
265 return "ipv6Unicast";
266 if (safi == SAFI_MULTICAST)
267 return "ipv6Multicast";
268 if (safi == SAFI_LABELED_UNICAST)
269 return "ipv6LabeledUnicast";
270 if (safi == SAFI_MPLS_VPN)
271 return "ipv6Vpn";
272 if (safi == SAFI_ENCAP)
273 return "ipv6Encap";
274 if (safi == SAFI_FLOWSPEC)
275 return "ipv6Flowspec";
276 } else if (afi == AFI_L2VPN) {
277 if (safi == SAFI_EVPN)
278 return "l2VpnEvpn";
279 }
280
281 return "Unknown";
282 }
283
284 /* unset srv6 locator */
285 static int bgp_srv6_locator_unset(struct bgp *bgp)
286 {
287 int ret;
288 struct listnode *node, *nnode;
289 struct srv6_locator_chunk *chunk;
290 struct bgp_srv6_function *func;
291 struct bgp *bgp_vrf;
292 struct in6_addr *tovpn_sid;
293
294 /* release chunk notification via ZAPI */
295 ret = bgp_zebra_srv6_manager_release_locator_chunk(
296 bgp->srv6_locator_name);
297 if (ret < 0)
298 return -1;
299
300 /* refresh chunks */
301 for (ALL_LIST_ELEMENTS(bgp->srv6_locator_chunks, node, nnode, chunk))
302 listnode_delete(bgp->srv6_locator_chunks, chunk);
303
304 /* refresh functions */
305 for (ALL_LIST_ELEMENTS(bgp->srv6_functions, node, nnode, func))
306 listnode_delete(bgp->srv6_functions, func);
307
308 /* refresh tovpn_sid */
309 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp_vrf)) {
310 if (bgp_vrf->inst_type != BGP_INSTANCE_TYPE_VRF)
311 continue;
312
313 /* refresh vpnv4 tovpn_sid */
314 tovpn_sid = bgp_vrf->vpn_policy[AFI_IP].tovpn_sid;
315 if (tovpn_sid)
316 XFREE(MTYPE_BGP_SRV6_SID,
317 bgp_vrf->vpn_policy[AFI_IP].tovpn_sid);
318
319 /* refresh vpnv6 tovpn_sid */
320 tovpn_sid = bgp_vrf->vpn_policy[AFI_IP6].tovpn_sid;
321 if (tovpn_sid)
322 XFREE(MTYPE_BGP_SRV6_SID,
323 bgp_vrf->vpn_policy[AFI_IP6].tovpn_sid);
324 }
325
326 /* update vpn bgp processes */
327 vpn_leak_postchange_all();
328
329 /* clear locator name */
330 memset(bgp->srv6_locator_name, 0, sizeof(bgp->srv6_locator_name));
331
332 return 0;
333 }
334
335 /* Utility function to get address family from current node. */
336 afi_t bgp_node_afi(struct vty *vty)
337 {
338 afi_t afi;
339 switch (vty->node) {
340 case BGP_IPV6_NODE:
341 case BGP_IPV6M_NODE:
342 case BGP_IPV6L_NODE:
343 case BGP_VPNV6_NODE:
344 case BGP_FLOWSPECV6_NODE:
345 afi = AFI_IP6;
346 break;
347 case BGP_EVPN_NODE:
348 afi = AFI_L2VPN;
349 break;
350 default:
351 afi = AFI_IP;
352 break;
353 }
354 return afi;
355 }
356
357 /* Utility function to get subsequent address family from current
358 node. */
359 safi_t bgp_node_safi(struct vty *vty)
360 {
361 safi_t safi;
362 switch (vty->node) {
363 case BGP_VPNV4_NODE:
364 case BGP_VPNV6_NODE:
365 safi = SAFI_MPLS_VPN;
366 break;
367 case BGP_IPV4M_NODE:
368 case BGP_IPV6M_NODE:
369 safi = SAFI_MULTICAST;
370 break;
371 case BGP_EVPN_NODE:
372 safi = SAFI_EVPN;
373 break;
374 case BGP_IPV4L_NODE:
375 case BGP_IPV6L_NODE:
376 safi = SAFI_LABELED_UNICAST;
377 break;
378 case BGP_FLOWSPECV4_NODE:
379 case BGP_FLOWSPECV6_NODE:
380 safi = SAFI_FLOWSPEC;
381 break;
382 default:
383 safi = SAFI_UNICAST;
384 break;
385 }
386 return safi;
387 }
388
389 /**
390 * Converts an AFI in string form to afi_t
391 *
392 * @param afi string, one of
393 * - "ipv4"
394 * - "ipv6"
395 * - "l2vpn"
396 * @return the corresponding afi_t
397 */
398 afi_t bgp_vty_afi_from_str(const char *afi_str)
399 {
400 afi_t afi = AFI_MAX; /* unknown */
401 if (strmatch(afi_str, "ipv4"))
402 afi = AFI_IP;
403 else if (strmatch(afi_str, "ipv6"))
404 afi = AFI_IP6;
405 else if (strmatch(afi_str, "l2vpn"))
406 afi = AFI_L2VPN;
407 return afi;
408 }
409
410 int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
411 afi_t *afi)
412 {
413 int ret = 0;
414 if (argv_find(argv, argc, "ipv4", index)) {
415 ret = 1;
416 if (afi)
417 *afi = AFI_IP;
418 } else if (argv_find(argv, argc, "ipv6", index)) {
419 ret = 1;
420 if (afi)
421 *afi = AFI_IP6;
422 } else if (argv_find(argv, argc, "l2vpn", index)) {
423 ret = 1;
424 if (afi)
425 *afi = AFI_L2VPN;
426 }
427 return ret;
428 }
429
430 /* supports <unicast|multicast|vpn|labeled-unicast> */
431 safi_t bgp_vty_safi_from_str(const char *safi_str)
432 {
433 safi_t safi = SAFI_MAX; /* unknown */
434 if (strmatch(safi_str, "multicast"))
435 safi = SAFI_MULTICAST;
436 else if (strmatch(safi_str, "unicast"))
437 safi = SAFI_UNICAST;
438 else if (strmatch(safi_str, "vpn"))
439 safi = SAFI_MPLS_VPN;
440 else if (strmatch(safi_str, "evpn"))
441 safi = SAFI_EVPN;
442 else if (strmatch(safi_str, "labeled-unicast"))
443 safi = SAFI_LABELED_UNICAST;
444 else if (strmatch(safi_str, "flowspec"))
445 safi = SAFI_FLOWSPEC;
446 return safi;
447 }
448
449 int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
450 safi_t *safi)
451 {
452 int ret = 0;
453 if (argv_find(argv, argc, "unicast", index)) {
454 ret = 1;
455 if (safi)
456 *safi = SAFI_UNICAST;
457 } else if (argv_find(argv, argc, "multicast", index)) {
458 ret = 1;
459 if (safi)
460 *safi = SAFI_MULTICAST;
461 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
462 ret = 1;
463 if (safi)
464 *safi = SAFI_LABELED_UNICAST;
465 } else if (argv_find(argv, argc, "vpn", index)) {
466 ret = 1;
467 if (safi)
468 *safi = SAFI_MPLS_VPN;
469 } else if (argv_find(argv, argc, "evpn", index)) {
470 ret = 1;
471 if (safi)
472 *safi = SAFI_EVPN;
473 } else if (argv_find(argv, argc, "flowspec", index)) {
474 ret = 1;
475 if (safi)
476 *safi = SAFI_FLOWSPEC;
477 }
478 return ret;
479 }
480
481 /*
482 * Convert an afi_t/safi_t pair to matching BGP_DEFAULT_AF* flag.
483 *
484 * afi
485 * address-family identifier
486 *
487 * safi
488 * subsequent address-family identifier
489 *
490 * Returns:
491 * default_af string corresponding to the supplied afi/safi pair.
492 * If afi/safi is invalid or if flag for afi/safi doesn't exist,
493 * return -1.
494 */
495 static const char *get_bgp_default_af_flag(afi_t afi, safi_t safi)
496 {
497 switch (afi) {
498 case AFI_IP:
499 switch (safi) {
500 case SAFI_UNICAST:
501 return "ipv4-unicast";
502 case SAFI_MULTICAST:
503 return "ipv4-multicast";
504 case SAFI_MPLS_VPN:
505 return "ipv4-vpn";
506 case SAFI_ENCAP:
507 return "ipv4-encap";
508 case SAFI_LABELED_UNICAST:
509 return "ipv4-labeled-unicast";
510 case SAFI_FLOWSPEC:
511 return "ipv4-flowspec";
512 default:
513 return "unknown-afi/safi";
514 }
515 break;
516 case AFI_IP6:
517 switch (safi) {
518 case SAFI_UNICAST:
519 return "ipv6-unicast";
520 case SAFI_MULTICAST:
521 return "ipv6-multicast";
522 case SAFI_MPLS_VPN:
523 return "ipv6-vpn";
524 case SAFI_ENCAP:
525 return "ipv6-encap";
526 case SAFI_LABELED_UNICAST:
527 return "ipv6-labeled-unicast";
528 case SAFI_FLOWSPEC:
529 return "ipv6-flowspec";
530 default:
531 return "unknown-afi/safi";
532 }
533 break;
534 case AFI_L2VPN:
535 switch (safi) {
536 case SAFI_EVPN:
537 return "l2vpn-evpn";
538 default:
539 return "unknown-afi/safi";
540 }
541 case AFI_UNSPEC:
542 case AFI_MAX:
543 return "unknown-afi/safi";
544 }
545 /* all AFIs are accounted for above, so this shouldn't happen */
546 return "unknown-afi/safi";
547 }
548
549 int bgp_get_vty(struct bgp **bgp, as_t *as, const char *name,
550 enum bgp_instance_type inst_type)
551 {
552 int ret = bgp_get(bgp, as, name, inst_type);
553
554 if (ret == BGP_CREATED) {
555 bgp_timers_set(*bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
556 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
557
558 if (DFLT_BGP_IMPORT_CHECK)
559 SET_FLAG((*bgp)->flags, BGP_FLAG_IMPORT_CHECK);
560 if (DFLT_BGP_SHOW_HOSTNAME)
561 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_HOSTNAME);
562 if (DFLT_BGP_SHOW_NEXTHOP_HOSTNAME)
563 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
564 if (DFLT_BGP_LOG_NEIGHBOR_CHANGES)
565 SET_FLAG((*bgp)->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
566 if (DFLT_BGP_DETERMINISTIC_MED)
567 SET_FLAG((*bgp)->flags, BGP_FLAG_DETERMINISTIC_MED);
568 if (DFLT_BGP_EBGP_REQUIRES_POLICY)
569 SET_FLAG((*bgp)->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
570 if (DFLT_BGP_SUPPRESS_DUPLICATES)
571 SET_FLAG((*bgp)->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
572
573 ret = BGP_SUCCESS;
574 }
575 return ret;
576 }
577
578 /*
579 * bgp_vty_find_and_parse_afi_safi_bgp
580 *
581 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
582 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
583 * to appropriate values for the calling function. This is to allow the
584 * calling function to make decisions appropriate for the show command
585 * that is being parsed.
586 *
587 * The show commands are generally of the form:
588 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
589 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
590 *
591 * Since we use argv_find if the show command in particular doesn't have:
592 * [ip]
593 * [<view|vrf> VIEWVRFNAME]
594 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
595 * The command parsing should still be ok.
596 *
597 * vty -> The vty for the command so we can output some useful data in
598 * the event of a parse error in the vrf.
599 * argv -> The command tokens
600 * argc -> How many command tokens we have
601 * idx -> The current place in the command, generally should be 0 for this
602 * function
603 * afi -> The parsed afi if it was included in the show command, returned here
604 * safi -> The parsed safi if it was included in the show command, returned here
605 * bgp -> Pointer to the bgp data structure we need to fill in.
606 * use_json -> json is configured or not
607 *
608 * The function returns the correct location in the parse tree for the
609 * last token found.
610 *
611 * Returns 0 for failure to parse correctly, else the idx position of where
612 * it found the last token.
613 */
614 int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
615 struct cmd_token **argv, int argc,
616 int *idx, afi_t *afi, safi_t *safi,
617 struct bgp **bgp, bool use_json)
618 {
619 char *vrf_name = NULL;
620
621 assert(afi);
622 assert(safi);
623 assert(bgp);
624
625 if (argv_find(argv, argc, "ip", idx))
626 *afi = AFI_IP;
627
628 if (argv_find(argv, argc, "view", idx))
629 vrf_name = argv[*idx + 1]->arg;
630 else if (argv_find(argv, argc, "vrf", idx)) {
631 vrf_name = argv[*idx + 1]->arg;
632 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
633 vrf_name = NULL;
634 }
635 if (vrf_name) {
636 if (strmatch(vrf_name, "all"))
637 *bgp = NULL;
638 else {
639 *bgp = bgp_lookup_by_name(vrf_name);
640 if (!*bgp) {
641 if (use_json) {
642 json_object *json = NULL;
643 json = json_object_new_object();
644 json_object_string_add(
645 json, "warning",
646 "View/Vrf is unknown");
647 vty_json(vty, json);
648 }
649 else
650 vty_out(vty, "View/Vrf %s is unknown\n",
651 vrf_name);
652 *idx = 0;
653 return 0;
654 }
655 }
656 } else {
657 *bgp = bgp_get_default();
658 if (!*bgp) {
659 if (use_json) {
660 json_object *json = NULL;
661 json = json_object_new_object();
662 json_object_string_add(
663 json, "warning",
664 "Default BGP instance not found");
665 vty_json(vty, json);
666 }
667 else
668 vty_out(vty,
669 "Default BGP instance not found\n");
670 *idx = 0;
671 return 0;
672 }
673 }
674
675 if (argv_find_and_parse_afi(argv, argc, idx, afi))
676 argv_find_and_parse_safi(argv, argc, idx, safi);
677
678 *idx += 1;
679 return *idx;
680 }
681
682 static bool peer_address_self_check(struct bgp *bgp, union sockunion *su)
683 {
684 struct interface *ifp = NULL;
685 struct listnode *node;
686 struct bgp_listener *listener;
687 union sockunion all_su;
688
689 if (su->sa.sa_family == AF_INET) {
690 (void)str2sockunion("0.0.0.0", &all_su);
691 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
692 } else if (su->sa.sa_family == AF_INET6) {
693 (void)str2sockunion("::", &all_su);
694 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
695 su->sin6.sin6_scope_id,
696 bgp->vrf_id);
697 }
698
699 if (ifp) {
700 for (ALL_LIST_ELEMENTS_RO(bm->listen_sockets, node, listener)) {
701 if (sockunion_family(su) !=
702 sockunion_family(&listener->su))
703 continue;
704
705 /* If 0.0.0.0/:: is a listener, then treat as self and
706 * reject.
707 */
708 if (!sockunion_cmp(&listener->su, su) ||
709 !sockunion_cmp(&listener->su, &all_su))
710 return true;
711 }
712 }
713
714 return false;
715 }
716
717 /* Utility function for looking up peer from VTY. */
718 /* This is used only for configuration, so disallow if attempted on
719 * a dynamic neighbor.
720 */
721 static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
722 {
723 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
724 int ret;
725 union sockunion su;
726 struct peer *peer;
727
728 if (!bgp) {
729 return NULL;
730 }
731
732 ret = str2sockunion(ip_str, &su);
733 if (ret < 0) {
734 peer = peer_lookup_by_conf_if(bgp, ip_str);
735 if (!peer) {
736 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
737 == NULL) {
738 vty_out(vty,
739 "%% Malformed address or name: %s\n",
740 ip_str);
741 return NULL;
742 }
743 }
744 } else {
745 peer = peer_lookup(bgp, &su);
746 if (!peer) {
747 vty_out(vty,
748 "%% Specify remote-as or peer-group commands first\n");
749 return NULL;
750 }
751 if (peer_dynamic_neighbor(peer)) {
752 vty_out(vty,
753 "%% Operation not allowed on a dynamic neighbor\n");
754 return NULL;
755 }
756 }
757 return peer;
758 }
759
760 /* Utility function for looking up peer or peer group. */
761 /* This is used only for configuration, so disallow if attempted on
762 * a dynamic neighbor.
763 */
764 struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
765 {
766 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
767 int ret;
768 union sockunion su;
769 struct peer *peer = NULL;
770 struct peer_group *group = NULL;
771
772 if (!bgp) {
773 return NULL;
774 }
775
776 ret = str2sockunion(peer_str, &su);
777 if (ret == 0) {
778 /* IP address, locate peer. */
779 peer = peer_lookup(bgp, &su);
780 } else {
781 /* Not IP, could match either peer configured on interface or a
782 * group. */
783 peer = peer_lookup_by_conf_if(bgp, peer_str);
784 if (!peer)
785 group = peer_group_lookup(bgp, peer_str);
786 }
787
788 if (peer) {
789 if (peer_dynamic_neighbor(peer)) {
790 vty_out(vty,
791 "%% Operation not allowed on a dynamic neighbor\n");
792 return NULL;
793 }
794
795 return peer;
796 }
797
798 if (group)
799 return group->conf;
800
801 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
802
803 return NULL;
804 }
805
806 int bgp_vty_return(struct vty *vty, enum bgp_create_error_code ret)
807 {
808 const char *str = NULL;
809
810 switch (ret) {
811 case BGP_SUCCESS:
812 case BGP_CREATED:
813 case BGP_GR_NO_OPERATION:
814 break;
815 case BGP_ERR_INVALID_VALUE:
816 str = "Invalid value";
817 break;
818 case BGP_ERR_INVALID_FLAG:
819 str = "Invalid flag";
820 break;
821 case BGP_ERR_PEER_GROUP_SHUTDOWN:
822 str = "Peer-group has been shutdown. Activate the peer-group first";
823 break;
824 case BGP_ERR_PEER_FLAG_CONFLICT:
825 str = "Can't set override-capability and strict-capability-match at the same time";
826 break;
827 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
828 str = "Specify remote-as or peer-group remote AS first";
829 break;
830 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
831 str = "Cannot change the peer-group. Deconfigure first";
832 break;
833 case BGP_ERR_PEER_GROUP_MISMATCH:
834 str = "Peer is not a member of this peer-group";
835 break;
836 case BGP_ERR_PEER_FILTER_CONFLICT:
837 str = "Prefix/distribute list can not co-exist";
838 break;
839 case BGP_ERR_NOT_INTERNAL_PEER:
840 str = "Invalid command. Not an internal neighbor";
841 break;
842 case BGP_ERR_REMOVE_PRIVATE_AS:
843 str = "remove-private-AS cannot be configured for IBGP peers";
844 break;
845 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
846 str = "Local-AS allowed only for EBGP peers";
847 break;
848 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
849 str = "Cannot have local-as same as BGP AS number";
850 break;
851 case BGP_ERR_TCPSIG_FAILED:
852 str = "Error while applying TCP-Sig to session(s)";
853 break;
854 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
855 str = "ebgp-multihop and ttl-security cannot be configured together";
856 break;
857 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
858 str = "ttl-security only allowed for EBGP peers";
859 break;
860 case BGP_ERR_AS_OVERRIDE:
861 str = "as-override cannot be configured for IBGP peers";
862 break;
863 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
864 str = "Invalid limit for number of dynamic neighbors";
865 break;
866 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
867 str = "Dynamic neighbor listen range already exists";
868 break;
869 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
870 str = "Operation not allowed on a dynamic neighbor";
871 break;
872 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
873 str = "Operation not allowed on a directly connected neighbor";
874 break;
875 case BGP_ERR_PEER_SAFI_CONFLICT:
876 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
877 break;
878 case BGP_ERR_GR_INVALID_CMD:
879 str = "The Graceful Restart command used is not valid at this moment.";
880 break;
881 case BGP_ERR_GR_OPERATION_FAILED:
882 str = "The Graceful Restart Operation failed due to an err.";
883 break;
884 case BGP_ERR_PEER_GROUP_MEMBER:
885 str = "Peer-group member cannot override remote-as of peer-group.";
886 break;
887 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
888 str = "Peer-group members must be all internal or all external.";
889 break;
890 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_NOT_FOUND:
891 str = "Range specified cannot be deleted because it is not part of current config.";
892 break;
893 case BGP_ERR_INSTANCE_MISMATCH:
894 str = "Instance specified does not match the current instance.";
895 break;
896 case BGP_ERR_NO_INTERFACE_CONFIG:
897 str = "Interface specified is not being used for interface based peer.";
898 break;
899 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
900 str = "No configuration already specified for soft reconfiguration.";
901 break;
902 case BGP_ERR_AS_MISMATCH:
903 str = "BGP is already running.";
904 break;
905 case BGP_ERR_AF_UNCONFIGURED:
906 str = "AFI/SAFI specified is not currently configured.";
907 break;
908 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS_REMOTE_AS:
909 str = "AS specified for local as is the same as the remote as and this is not allowed.";
910 break;
911 case BGP_ERR_INVALID_AS:
912 str = "Confederation AS specified is the same AS as our AS.";
913 break;
914 }
915 if (str) {
916 vty_out(vty, "%% %s\n", str);
917 return CMD_WARNING_CONFIG_FAILED;
918 }
919 return CMD_SUCCESS;
920 }
921
922 /* BGP clear sort. */
923 enum clear_sort {
924 clear_all,
925 clear_peer,
926 clear_group,
927 clear_external,
928 clear_as
929 };
930
931 static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
932 safi_t safi, int error)
933 {
934 switch (error) {
935 case BGP_ERR_AF_UNCONFIGURED:
936 vty_out(vty,
937 "%%BGP: Enable %s address family for the neighbor %s\n",
938 get_afi_safi_str(afi, safi, false), peer->host);
939 break;
940 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
941 vty_out(vty,
942 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
943 peer->host);
944 break;
945 default:
946 break;
947 }
948 }
949
950 static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi,
951 struct listnode **nnode, enum bgp_clear_type stype)
952 {
953 int ret = 0;
954 struct peer_af *paf;
955
956 /* if afi/.safi not specified, spin thru all of them */
957 if ((afi == AFI_UNSPEC) && (safi == SAFI_UNSPEC)) {
958 afi_t tmp_afi;
959 safi_t tmp_safi;
960 enum bgp_af_index index;
961
962 for (index = BGP_AF_START; index < BGP_AF_MAX; index++) {
963 paf = peer->peer_af_array[index];
964 if (!paf)
965 continue;
966
967 if (paf && paf->subgroup)
968 SET_FLAG(paf->subgroup->sflags,
969 SUBGRP_STATUS_FORCE_UPDATES);
970
971 tmp_afi = paf->afi;
972 tmp_safi = paf->safi;
973 if (!peer->afc[tmp_afi][tmp_safi])
974 continue;
975
976 if (stype == BGP_CLEAR_SOFT_NONE)
977 ret = peer_clear(peer, nnode);
978 else
979 ret = peer_clear_soft(peer, tmp_afi, tmp_safi,
980 stype);
981 }
982 /* if afi specified and safi not, spin thru safis on this afi */
983 } else if (safi == SAFI_UNSPEC) {
984 safi_t tmp_safi;
985
986 for (tmp_safi = SAFI_UNICAST;
987 tmp_safi < SAFI_MAX; tmp_safi++) {
988 if (!peer->afc[afi][tmp_safi])
989 continue;
990
991 paf = peer_af_find(peer, afi, tmp_safi);
992 if (paf && paf->subgroup)
993 SET_FLAG(paf->subgroup->sflags,
994 SUBGRP_STATUS_FORCE_UPDATES);
995
996 if (stype == BGP_CLEAR_SOFT_NONE)
997 ret = peer_clear(peer, nnode);
998 else
999 ret = peer_clear_soft(peer, afi,
1000 tmp_safi, stype);
1001 }
1002 /* both afi/safi specified, let the caller know if not defined */
1003 } else {
1004 if (!peer->afc[afi][safi])
1005 return 1;
1006
1007 paf = peer_af_find(peer, afi, safi);
1008 if (paf && paf->subgroup)
1009 SET_FLAG(paf->subgroup->sflags,
1010 SUBGRP_STATUS_FORCE_UPDATES);
1011
1012 if (stype == BGP_CLEAR_SOFT_NONE)
1013 ret = peer_clear(peer, nnode);
1014 else
1015 ret = peer_clear_soft(peer, afi, safi, stype);
1016 }
1017
1018 return ret;
1019 }
1020
1021 /* `clear ip bgp' functions. */
1022 static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
1023 enum clear_sort sort, enum bgp_clear_type stype,
1024 const char *arg)
1025 {
1026 int ret = 0;
1027 bool found = false;
1028 struct peer *peer;
1029
1030 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
1031
1032 /* Clear all neighbors. */
1033 /*
1034 * Pass along pointer to next node to peer_clear() when walking all
1035 * nodes on the BGP instance as that may get freed if it is a
1036 * doppelganger
1037 */
1038 if (sort == clear_all) {
1039 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1040
1041 bgp_peer_gr_flags_update(peer);
1042
1043 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1044 gr_router_detected = true;
1045
1046 ret = bgp_peer_clear(peer, afi, safi, &nnode,
1047 stype);
1048
1049 if (ret < 0)
1050 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1051 }
1052
1053 if (gr_router_detected
1054 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1055 bgp_zebra_send_capabilities(bgp, false);
1056 } else if (!gr_router_detected
1057 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1058 bgp_zebra_send_capabilities(bgp, true);
1059 }
1060
1061 /* This is to apply read-only mode on this clear. */
1062 if (stype == BGP_CLEAR_SOFT_NONE)
1063 bgp->update_delay_over = 0;
1064
1065 return CMD_SUCCESS;
1066 }
1067
1068 /* Clear specified neighbor. */
1069 if (sort == clear_peer) {
1070 union sockunion su;
1071
1072 /* Make sockunion for lookup. */
1073 ret = str2sockunion(arg, &su);
1074 if (ret < 0) {
1075 peer = peer_lookup_by_conf_if(bgp, arg);
1076 if (!peer) {
1077 peer = peer_lookup_by_hostname(bgp, arg);
1078 if (!peer) {
1079 vty_out(vty,
1080 "Malformed address or name: %s\n",
1081 arg);
1082 return CMD_WARNING;
1083 }
1084 }
1085 } else {
1086 peer = peer_lookup(bgp, &su);
1087 if (!peer) {
1088 vty_out(vty,
1089 "%%BGP: Unknown neighbor - \"%s\"\n",
1090 arg);
1091 return CMD_WARNING;
1092 }
1093 }
1094
1095 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
1096 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
1097
1098 ret = bgp_peer_clear(peer, afi, safi, NULL, stype);
1099
1100 /* if afi/safi not defined for this peer, let caller know */
1101 if (ret == 1)
1102 ret = BGP_ERR_AF_UNCONFIGURED;
1103
1104 if (ret < 0)
1105 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1106
1107 return CMD_SUCCESS;
1108 }
1109
1110 /* Clear all neighbors belonging to a specific peer-group. */
1111 if (sort == clear_group) {
1112 struct peer_group *group;
1113
1114 group = peer_group_lookup(bgp, arg);
1115 if (!group) {
1116 vty_out(vty, "%%BGP: No such peer-group %s\n", arg);
1117 return CMD_WARNING;
1118 }
1119
1120 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
1121 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1122
1123 if (ret < 0)
1124 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1125 else
1126 found = true;
1127 }
1128
1129 if (!found)
1130 vty_out(vty,
1131 "%%BGP: No %s peer belonging to peer-group %s is configured\n",
1132 get_afi_safi_str(afi, safi, false), arg);
1133
1134 return CMD_SUCCESS;
1135 }
1136
1137 /* Clear all external (eBGP) neighbors. */
1138 if (sort == clear_external) {
1139 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1140 if (peer->sort == BGP_PEER_IBGP)
1141 continue;
1142
1143 bgp_peer_gr_flags_update(peer);
1144
1145 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1146 gr_router_detected = true;
1147
1148 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1149
1150 if (ret < 0)
1151 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1152 else
1153 found = true;
1154 }
1155
1156 if (gr_router_detected
1157 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1158 bgp_zebra_send_capabilities(bgp, false);
1159 } else if (!gr_router_detected
1160 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1161 bgp_zebra_send_capabilities(bgp, true);
1162 }
1163
1164 if (!found)
1165 vty_out(vty,
1166 "%%BGP: No external %s peer is configured\n",
1167 get_afi_safi_str(afi, safi, false));
1168
1169 return CMD_SUCCESS;
1170 }
1171
1172 /* Clear all neighbors belonging to a specific AS. */
1173 if (sort == clear_as) {
1174 as_t as = strtoul(arg, NULL, 10);
1175
1176 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1177 if (peer->as != as)
1178 continue;
1179
1180 bgp_peer_gr_flags_update(peer);
1181
1182 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1183 gr_router_detected = true;
1184
1185 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1186
1187 if (ret < 0)
1188 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1189 else
1190 found = true;
1191 }
1192
1193 if (gr_router_detected
1194 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1195 bgp_zebra_send_capabilities(bgp, false);
1196 } else if (!gr_router_detected
1197 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1198 bgp_zebra_send_capabilities(bgp, true);
1199 }
1200
1201 if (!found)
1202 vty_out(vty,
1203 "%%BGP: No %s peer is configured with AS %s\n",
1204 get_afi_safi_str(afi, safi, false), arg);
1205
1206 return CMD_SUCCESS;
1207 }
1208
1209 return CMD_SUCCESS;
1210 }
1211
1212 static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
1213 safi_t safi, enum clear_sort sort,
1214 enum bgp_clear_type stype, const char *arg)
1215 {
1216 struct bgp *bgp;
1217
1218 /* BGP structure lookup. */
1219 if (name) {
1220 bgp = bgp_lookup_by_name(name);
1221 if (bgp == NULL) {
1222 vty_out(vty, "Can't find BGP instance %s\n", name);
1223 return CMD_WARNING;
1224 }
1225 } else {
1226 bgp = bgp_get_default();
1227 if (bgp == NULL) {
1228 vty_out(vty, "No BGP process is configured\n");
1229 return CMD_WARNING;
1230 }
1231 }
1232
1233 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
1234 }
1235
1236 /* clear soft inbound */
1237 static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
1238 {
1239 afi_t afi;
1240 safi_t safi;
1241
1242 FOREACH_AFI_SAFI (afi, safi)
1243 bgp_clear_vty(vty, name, afi, safi, clear_all,
1244 BGP_CLEAR_SOFT_IN, NULL);
1245 }
1246
1247 /* clear soft outbound */
1248 static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
1249 {
1250 afi_t afi;
1251 safi_t safi;
1252
1253 FOREACH_AFI_SAFI (afi, safi)
1254 bgp_clear_vty(vty, name, afi, safi, clear_all,
1255 BGP_CLEAR_SOFT_OUT, NULL);
1256 }
1257
1258
1259 #ifndef VTYSH_EXTRACT_PL
1260 #include "bgpd/bgp_vty_clippy.c"
1261 #endif
1262
1263 DEFUN_HIDDEN (bgp_local_mac,
1264 bgp_local_mac_cmd,
1265 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
1266 BGP_STR
1267 "Local MAC config\n"
1268 "VxLAN Network Identifier\n"
1269 "VNI number\n"
1270 "local mac\n"
1271 "mac address\n"
1272 "mac-mobility sequence\n"
1273 "seq number\n")
1274 {
1275 int rv;
1276 vni_t vni;
1277 struct ethaddr mac;
1278 struct ipaddr ip;
1279 uint32_t seq;
1280 struct bgp *bgp;
1281
1282 vni = strtoul(argv[3]->arg, NULL, 10);
1283 if (!prefix_str2mac(argv[5]->arg, &mac)) {
1284 vty_out(vty, "%% Malformed MAC address\n");
1285 return CMD_WARNING;
1286 }
1287 memset(&ip, 0, sizeof(ip));
1288 seq = strtoul(argv[7]->arg, NULL, 10);
1289
1290 bgp = bgp_get_default();
1291 if (!bgp) {
1292 vty_out(vty, "Default BGP instance is not there\n");
1293 return CMD_WARNING;
1294 }
1295
1296 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq,
1297 zero_esi);
1298 if (rv < 0) {
1299 vty_out(vty, "Internal error\n");
1300 return CMD_WARNING;
1301 }
1302
1303 return CMD_SUCCESS;
1304 }
1305
1306 DEFUN_HIDDEN (no_bgp_local_mac,
1307 no_bgp_local_mac_cmd,
1308 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
1309 NO_STR
1310 BGP_STR
1311 "Local MAC config\n"
1312 "VxLAN Network Identifier\n"
1313 "VNI number\n"
1314 "local mac\n"
1315 "mac address\n")
1316 {
1317 int rv;
1318 vni_t vni;
1319 struct ethaddr mac;
1320 struct ipaddr ip;
1321 struct bgp *bgp;
1322
1323 vni = strtoul(argv[4]->arg, NULL, 10);
1324 if (!prefix_str2mac(argv[6]->arg, &mac)) {
1325 vty_out(vty, "%% Malformed MAC address\n");
1326 return CMD_WARNING;
1327 }
1328 memset(&ip, 0, sizeof(ip));
1329
1330 bgp = bgp_get_default();
1331 if (!bgp) {
1332 vty_out(vty, "Default BGP instance is not there\n");
1333 return CMD_WARNING;
1334 }
1335
1336 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
1337 if (rv < 0) {
1338 vty_out(vty, "Internal error\n");
1339 return CMD_WARNING;
1340 }
1341
1342 return CMD_SUCCESS;
1343 }
1344
1345 DEFUN (no_synchronization,
1346 no_synchronization_cmd,
1347 "no synchronization",
1348 NO_STR
1349 "Perform IGP synchronization\n")
1350 {
1351 return CMD_SUCCESS;
1352 }
1353
1354 DEFUN (no_auto_summary,
1355 no_auto_summary_cmd,
1356 "no auto-summary",
1357 NO_STR
1358 "Enable automatic network number summarization\n")
1359 {
1360 return CMD_SUCCESS;
1361 }
1362
1363 /* "router bgp" commands. */
1364 DEFUN_NOSH (router_bgp,
1365 router_bgp_cmd,
1366 "router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1367 ROUTER_STR
1368 BGP_STR
1369 AS_STR
1370 BGP_INSTANCE_HELP_STR)
1371 {
1372 int idx_asn = 2;
1373 int idx_view_vrf = 3;
1374 int idx_vrf = 4;
1375 int is_new_bgp = 0;
1376 int ret;
1377 as_t as;
1378 struct bgp *bgp;
1379 const char *name = NULL;
1380 enum bgp_instance_type inst_type;
1381
1382 // "router bgp" without an ASN
1383 if (argc == 2) {
1384 // Pending: Make VRF option available for ASN less config
1385 bgp = bgp_get_default();
1386
1387 if (bgp == NULL) {
1388 vty_out(vty, "%% No BGP process is configured\n");
1389 return CMD_WARNING_CONFIG_FAILED;
1390 }
1391
1392 if (listcount(bm->bgp) > 1) {
1393 vty_out(vty, "%% Please specify ASN and VRF\n");
1394 return CMD_WARNING_CONFIG_FAILED;
1395 }
1396 }
1397
1398 // "router bgp X"
1399 else {
1400 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1401
1402 if (as == BGP_PRIVATE_AS_MAX || as == BGP_AS4_MAX)
1403 vty_out(vty, "Reserved AS used (%u|%u); AS is %u\n",
1404 BGP_PRIVATE_AS_MAX, BGP_AS4_MAX, as);
1405
1406 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1407 if (argc > 3) {
1408 name = argv[idx_vrf]->arg;
1409
1410 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1411 if (strmatch(name, VRF_DEFAULT_NAME))
1412 name = NULL;
1413 else
1414 inst_type = BGP_INSTANCE_TYPE_VRF;
1415 } else if (!strcmp(argv[idx_view_vrf]->text, "view"))
1416 inst_type = BGP_INSTANCE_TYPE_VIEW;
1417 }
1418
1419 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1420 is_new_bgp = (bgp_lookup(as, name) == NULL);
1421
1422 ret = bgp_get_vty(&bgp, &as, name, inst_type);
1423 switch (ret) {
1424 case BGP_ERR_AS_MISMATCH:
1425 vty_out(vty, "BGP is already running; AS is %u\n", as);
1426 return CMD_WARNING_CONFIG_FAILED;
1427 case BGP_ERR_INSTANCE_MISMATCH:
1428 vty_out(vty,
1429 "BGP instance name and AS number mismatch\n");
1430 vty_out(vty,
1431 "BGP instance is already running; AS is %u\n",
1432 as);
1433 return CMD_WARNING_CONFIG_FAILED;
1434 }
1435
1436 /*
1437 * If we just instantiated the default instance, complete
1438 * any pending VRF-VPN leaking that was configured via
1439 * earlier "router bgp X vrf FOO" blocks.
1440 */
1441 if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1442 vpn_leak_postchange_all();
1443
1444 if (inst_type == BGP_INSTANCE_TYPE_VRF)
1445 bgp_vpn_leak_export(bgp);
1446 /* Pending: handle when user tries to change a view to vrf n vv.
1447 */
1448 }
1449
1450 /* unset the auto created flag as the user config is now present */
1451 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
1452 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1453
1454 return CMD_SUCCESS;
1455 }
1456
1457 /* "no router bgp" commands. */
1458 DEFUN (no_router_bgp,
1459 no_router_bgp_cmd,
1460 "no router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1461 NO_STR
1462 ROUTER_STR
1463 BGP_STR
1464 AS_STR
1465 BGP_INSTANCE_HELP_STR)
1466 {
1467 int idx_asn = 3;
1468 int idx_vrf = 5;
1469 as_t as;
1470 struct bgp *bgp;
1471 const char *name = NULL;
1472
1473 // "no router bgp" without an ASN
1474 if (argc == 3) {
1475 // Pending: Make VRF option available for ASN less config
1476 bgp = bgp_get_default();
1477
1478 if (bgp == NULL) {
1479 vty_out(vty, "%% No BGP process is configured\n");
1480 return CMD_WARNING_CONFIG_FAILED;
1481 }
1482
1483 if (listcount(bm->bgp) > 1) {
1484 vty_out(vty, "%% Please specify ASN and VRF\n");
1485 return CMD_WARNING_CONFIG_FAILED;
1486 }
1487
1488 if (bgp->l3vni) {
1489 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1490 bgp->l3vni);
1491 return CMD_WARNING_CONFIG_FAILED;
1492 }
1493 } else {
1494 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1495
1496 if (argc > 4) {
1497 name = argv[idx_vrf]->arg;
1498 if (strmatch(argv[idx_vrf - 1]->text, "vrf")
1499 && strmatch(name, VRF_DEFAULT_NAME))
1500 name = NULL;
1501 }
1502
1503 /* Lookup bgp structure. */
1504 bgp = bgp_lookup(as, name);
1505 if (!bgp) {
1506 vty_out(vty, "%% Can't find BGP instance\n");
1507 return CMD_WARNING_CONFIG_FAILED;
1508 }
1509
1510 if (bgp->l3vni) {
1511 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1512 bgp->l3vni);
1513 return CMD_WARNING_CONFIG_FAILED;
1514 }
1515
1516 /* Cannot delete default instance if vrf instances exist */
1517 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
1518 struct listnode *node;
1519 struct bgp *tmp_bgp;
1520
1521 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, tmp_bgp)) {
1522 if (tmp_bgp->inst_type != BGP_INSTANCE_TYPE_VRF)
1523 continue;
1524 if (CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1525 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1526 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1527 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1528 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1529 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1530 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1531 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1532 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1533 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1534 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1535 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1536 (bgp == bgp_get_evpn() &&
1537 (CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1538 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST) ||
1539 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1540 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST_GW_IP) ||
1541 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1542 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST) ||
1543 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1544 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST_GW_IP))) ||
1545 (tmp_bgp->vnihash && hashcount(tmp_bgp->vnihash))) {
1546 vty_out(vty,
1547 "%% Cannot delete default BGP instance. Dependent VRF instances exist\n");
1548 return CMD_WARNING_CONFIG_FAILED;
1549 }
1550 }
1551 }
1552 }
1553
1554 bgp_delete(bgp);
1555
1556 return CMD_SUCCESS;
1557 }
1558
1559
1560 /* BGP router-id. */
1561
1562 DEFPY (bgp_router_id,
1563 bgp_router_id_cmd,
1564 "bgp router-id A.B.C.D",
1565 BGP_STR
1566 "Override configured router identifier\n"
1567 "Manually configured router identifier\n")
1568 {
1569 VTY_DECLVAR_CONTEXT(bgp, bgp);
1570 bgp_router_id_static_set(bgp, router_id);
1571 return CMD_SUCCESS;
1572 }
1573
1574 DEFPY (no_bgp_router_id,
1575 no_bgp_router_id_cmd,
1576 "no bgp router-id [A.B.C.D]",
1577 NO_STR
1578 BGP_STR
1579 "Override configured router identifier\n"
1580 "Manually configured router identifier\n")
1581 {
1582 VTY_DECLVAR_CONTEXT(bgp, bgp);
1583
1584 if (router_id_str) {
1585 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1586 vty_out(vty, "%% BGP router-id doesn't match\n");
1587 return CMD_WARNING_CONFIG_FAILED;
1588 }
1589 }
1590
1591 router_id.s_addr = 0;
1592 bgp_router_id_static_set(bgp, router_id);
1593
1594 return CMD_SUCCESS;
1595 }
1596
1597 DEFPY(bgp_community_alias, bgp_community_alias_cmd,
1598 "[no$no] bgp community alias WORD$community ALIAS_NAME$alias_name",
1599 NO_STR BGP_STR
1600 "Add community specific parameters\n"
1601 "Create an alias for a community\n"
1602 "Community (AA:BB or AA:BB:CC)\n"
1603 "Alias name\n")
1604 {
1605 struct community_alias ca1;
1606 struct community_alias ca2;
1607 struct community_alias *lookup_community;
1608 struct community_alias *lookup_alias;
1609
1610 if (!community_str2com(community) && !lcommunity_str2com(community)) {
1611 vty_out(vty, "Invalid community format\n");
1612 return CMD_WARNING;
1613 }
1614
1615 memset(&ca1, 0, sizeof(ca1));
1616 memset(&ca2, 0, sizeof(ca2));
1617 strlcpy(ca1.community, community, sizeof(ca1.community));
1618 strlcpy(ca1.alias, alias_name, sizeof(ca1.alias));
1619
1620 lookup_community = bgp_ca_community_lookup(&ca1);
1621 lookup_alias = bgp_ca_alias_lookup(&ca1);
1622
1623 if (no) {
1624 bgp_ca_alias_delete(&ca1);
1625 bgp_ca_community_delete(&ca1);
1626 } else {
1627 if (lookup_alias) {
1628 /* Lookup if community hash table has an item
1629 * with the same alias name.
1630 */
1631 strlcpy(ca2.community, lookup_alias->community,
1632 sizeof(ca2.community));
1633 if (bgp_ca_community_lookup(&ca2)) {
1634 vty_out(vty,
1635 "community (%s) already has this alias (%s)\n",
1636 lookup_alias->community,
1637 lookup_alias->alias);
1638 return CMD_WARNING;
1639 }
1640 bgp_ca_alias_delete(&ca1);
1641 }
1642
1643 if (lookup_community)
1644 bgp_ca_community_delete(&ca1);
1645
1646 bgp_ca_alias_insert(&ca1);
1647 bgp_ca_community_insert(&ca1);
1648 }
1649
1650 return CMD_SUCCESS;
1651 }
1652
1653 DEFPY (bgp_global_suppress_fib_pending,
1654 bgp_global_suppress_fib_pending_cmd,
1655 "[no] bgp suppress-fib-pending",
1656 NO_STR
1657 BGP_STR
1658 "Advertise only routes that are programmed in kernel to peers globally\n")
1659 {
1660 bm_wait_for_fib_set(!no);
1661
1662 return CMD_SUCCESS;
1663 }
1664
1665 DEFPY (bgp_suppress_fib_pending,
1666 bgp_suppress_fib_pending_cmd,
1667 "[no] bgp suppress-fib-pending",
1668 NO_STR
1669 BGP_STR
1670 "Advertise only routes that are programmed in kernel to peers\n")
1671 {
1672 VTY_DECLVAR_CONTEXT(bgp, bgp);
1673
1674 bgp_suppress_fib_pending_set(bgp, !no);
1675 return CMD_SUCCESS;
1676 }
1677
1678
1679 /* BGP Cluster ID. */
1680 DEFUN (bgp_cluster_id,
1681 bgp_cluster_id_cmd,
1682 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1683 BGP_STR
1684 "Configure Route-Reflector Cluster-id\n"
1685 "Route-Reflector Cluster-id in IP address format\n"
1686 "Route-Reflector Cluster-id as 32 bit quantity\n")
1687 {
1688 VTY_DECLVAR_CONTEXT(bgp, bgp);
1689 int idx_ipv4 = 2;
1690 int ret;
1691 struct in_addr cluster;
1692
1693 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1694 if (!ret) {
1695 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1696 return CMD_WARNING_CONFIG_FAILED;
1697 }
1698
1699 bgp_cluster_id_set(bgp, &cluster);
1700 bgp_clear_star_soft_out(vty, bgp->name);
1701
1702 return CMD_SUCCESS;
1703 }
1704
1705 DEFUN (no_bgp_cluster_id,
1706 no_bgp_cluster_id_cmd,
1707 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1708 NO_STR
1709 BGP_STR
1710 "Configure Route-Reflector Cluster-id\n"
1711 "Route-Reflector Cluster-id in IP address format\n"
1712 "Route-Reflector Cluster-id as 32 bit quantity\n")
1713 {
1714 VTY_DECLVAR_CONTEXT(bgp, bgp);
1715 bgp_cluster_id_unset(bgp);
1716 bgp_clear_star_soft_out(vty, bgp->name);
1717
1718 return CMD_SUCCESS;
1719 }
1720
1721 DEFPY (bgp_norib,
1722 bgp_norib_cmd,
1723 "bgp no-rib",
1724 BGP_STR
1725 "Disable BGP route installation to RIB (Zebra)\n")
1726 {
1727 if (bgp_option_check(BGP_OPT_NO_FIB)) {
1728 vty_out(vty,
1729 "%% No-RIB option is already set, nothing to do here.\n");
1730 return CMD_SUCCESS;
1731 }
1732
1733 bgp_option_norib_set_runtime();
1734
1735 return CMD_SUCCESS;
1736 }
1737
1738 DEFPY (no_bgp_norib,
1739 no_bgp_norib_cmd,
1740 "no bgp no-rib",
1741 NO_STR
1742 BGP_STR
1743 "Disable BGP route installation to RIB (Zebra)\n")
1744 {
1745 if (!bgp_option_check(BGP_OPT_NO_FIB)) {
1746 vty_out(vty,
1747 "%% No-RIB option is not set, nothing to do here.\n");
1748 return CMD_SUCCESS;
1749 }
1750
1751 bgp_option_norib_unset_runtime();
1752
1753 return CMD_SUCCESS;
1754 }
1755
1756 DEFPY (no_bgp_send_extra_data,
1757 no_bgp_send_extra_data_cmd,
1758 "[no] bgp send-extra-data zebra",
1759 NO_STR
1760 BGP_STR
1761 "Extra data to Zebra for display/use\n"
1762 "To zebra\n")
1763 {
1764 if (no)
1765 UNSET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1766 else
1767 SET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1768
1769 return CMD_SUCCESS;
1770 }
1771
1772 DEFUN (bgp_confederation_identifier,
1773 bgp_confederation_identifier_cmd,
1774 "bgp confederation identifier (1-4294967295)",
1775 BGP_STR
1776 "AS confederation parameters\n"
1777 "AS number\n"
1778 "Set routing domain confederation AS\n")
1779 {
1780 VTY_DECLVAR_CONTEXT(bgp, bgp);
1781 int idx_number = 3;
1782 as_t as;
1783
1784 as = strtoul(argv[idx_number]->arg, NULL, 10);
1785
1786 bgp_confederation_id_set(bgp, as);
1787
1788 return CMD_SUCCESS;
1789 }
1790
1791 DEFUN (no_bgp_confederation_identifier,
1792 no_bgp_confederation_identifier_cmd,
1793 "no bgp confederation identifier [(1-4294967295)]",
1794 NO_STR
1795 BGP_STR
1796 "AS confederation parameters\n"
1797 "AS number\n"
1798 "Set routing domain confederation AS\n")
1799 {
1800 VTY_DECLVAR_CONTEXT(bgp, bgp);
1801 bgp_confederation_id_unset(bgp);
1802
1803 return CMD_SUCCESS;
1804 }
1805
1806 DEFUN (bgp_confederation_peers,
1807 bgp_confederation_peers_cmd,
1808 "bgp confederation peers (1-4294967295)...",
1809 BGP_STR
1810 "AS confederation parameters\n"
1811 "Peer ASs in BGP confederation\n"
1812 AS_STR)
1813 {
1814 VTY_DECLVAR_CONTEXT(bgp, bgp);
1815 int idx_asn = 3;
1816 as_t as;
1817 int i;
1818
1819 for (i = idx_asn; i < argc; i++) {
1820 as = strtoul(argv[i]->arg, NULL, 10);
1821
1822 if (bgp->as == as) {
1823 vty_out(vty,
1824 "%% Local member-AS not allowed in confed peer list\n");
1825 continue;
1826 }
1827
1828 bgp_confederation_peers_add(bgp, as);
1829 }
1830 return CMD_SUCCESS;
1831 }
1832
1833 DEFUN (no_bgp_confederation_peers,
1834 no_bgp_confederation_peers_cmd,
1835 "no bgp confederation peers (1-4294967295)...",
1836 NO_STR
1837 BGP_STR
1838 "AS confederation parameters\n"
1839 "Peer ASs in BGP confederation\n"
1840 AS_STR)
1841 {
1842 VTY_DECLVAR_CONTEXT(bgp, bgp);
1843 int idx_asn = 4;
1844 as_t as;
1845 int i;
1846
1847 for (i = idx_asn; i < argc; i++) {
1848 as = strtoul(argv[i]->arg, NULL, 10);
1849
1850 bgp_confederation_peers_remove(bgp, as);
1851 }
1852 return CMD_SUCCESS;
1853 }
1854
1855 /**
1856 * Central routine for maximum-paths configuration.
1857 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1858 * @set: 1 for setting values, 0 for removing the max-paths config.
1859 */
1860 static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
1861 const char *mpaths, uint16_t options,
1862 int set)
1863 {
1864 VTY_DECLVAR_CONTEXT(bgp, bgp);
1865 uint16_t maxpaths = 0;
1866 int ret;
1867 afi_t afi;
1868 safi_t safi;
1869
1870 afi = bgp_node_afi(vty);
1871 safi = bgp_node_safi(vty);
1872
1873 if (set) {
1874 maxpaths = strtol(mpaths, NULL, 10);
1875 if (maxpaths > multipath_num) {
1876 vty_out(vty,
1877 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1878 maxpaths, multipath_num);
1879 return CMD_WARNING_CONFIG_FAILED;
1880 }
1881 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1882 options);
1883 } else
1884 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1885
1886 if (ret < 0) {
1887 vty_out(vty,
1888 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1889 (set == 1) ? "" : "un",
1890 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1891 maxpaths, afi, safi);
1892 return CMD_WARNING_CONFIG_FAILED;
1893 }
1894
1895 bgp_recalculate_all_bestpaths(bgp);
1896
1897 return CMD_SUCCESS;
1898 }
1899
1900 DEFUN (bgp_maxmed_admin,
1901 bgp_maxmed_admin_cmd,
1902 "bgp max-med administrative ",
1903 BGP_STR
1904 "Advertise routes with max-med\n"
1905 "Administratively applied, for an indefinite period\n")
1906 {
1907 VTY_DECLVAR_CONTEXT(bgp, bgp);
1908
1909 bgp->v_maxmed_admin = 1;
1910 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1911
1912 bgp_maxmed_update(bgp);
1913
1914 return CMD_SUCCESS;
1915 }
1916
1917 DEFUN (bgp_maxmed_admin_medv,
1918 bgp_maxmed_admin_medv_cmd,
1919 "bgp max-med administrative (0-4294967295)",
1920 BGP_STR
1921 "Advertise routes with max-med\n"
1922 "Administratively applied, for an indefinite period\n"
1923 "Max MED value to be used\n")
1924 {
1925 VTY_DECLVAR_CONTEXT(bgp, bgp);
1926 int idx_number = 3;
1927
1928 bgp->v_maxmed_admin = 1;
1929 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
1930
1931 bgp_maxmed_update(bgp);
1932
1933 return CMD_SUCCESS;
1934 }
1935
1936 DEFUN (no_bgp_maxmed_admin,
1937 no_bgp_maxmed_admin_cmd,
1938 "no bgp max-med administrative [(0-4294967295)]",
1939 NO_STR
1940 BGP_STR
1941 "Advertise routes with max-med\n"
1942 "Administratively applied, for an indefinite period\n"
1943 "Max MED value to be used\n")
1944 {
1945 VTY_DECLVAR_CONTEXT(bgp, bgp);
1946 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1947 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1948 bgp_maxmed_update(bgp);
1949
1950 return CMD_SUCCESS;
1951 }
1952
1953 DEFUN (bgp_maxmed_onstartup,
1954 bgp_maxmed_onstartup_cmd,
1955 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
1956 BGP_STR
1957 "Advertise routes with max-med\n"
1958 "Effective on a startup\n"
1959 "Time (seconds) period for max-med\n"
1960 "Max MED value to be used\n")
1961 {
1962 VTY_DECLVAR_CONTEXT(bgp, bgp);
1963 int idx = 0;
1964
1965 argv_find(argv, argc, "(5-86400)", &idx);
1966 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
1967 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1968 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
1969 else
1970 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1971
1972 bgp_maxmed_update(bgp);
1973
1974 return CMD_SUCCESS;
1975 }
1976
1977 DEFUN (no_bgp_maxmed_onstartup,
1978 no_bgp_maxmed_onstartup_cmd,
1979 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
1980 NO_STR
1981 BGP_STR
1982 "Advertise routes with max-med\n"
1983 "Effective on a startup\n"
1984 "Time (seconds) period for max-med\n"
1985 "Max MED value to be used\n")
1986 {
1987 VTY_DECLVAR_CONTEXT(bgp, bgp);
1988
1989 /* Cancel max-med onstartup if its on */
1990 if (bgp->t_maxmed_onstartup) {
1991 thread_cancel(&bgp->t_maxmed_onstartup);
1992 bgp->maxmed_onstartup_over = 1;
1993 }
1994
1995 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
1996 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1997
1998 bgp_maxmed_update(bgp);
1999
2000 return CMD_SUCCESS;
2001 }
2002
2003 static int bgp_global_update_delay_config_vty(struct vty *vty,
2004 uint16_t update_delay,
2005 uint16_t establish_wait)
2006 {
2007 struct listnode *node, *nnode;
2008 struct bgp *bgp;
2009 bool vrf_cfg = false;
2010
2011 /*
2012 * See if update-delay is set per-vrf and warn user to delete it
2013 * Note that we only need to check this if this is the first time
2014 * setting the global config.
2015 */
2016 if (bm->v_update_delay == BGP_UPDATE_DELAY_DEF) {
2017 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2018 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
2019 vty_out(vty,
2020 "%% update-delay configuration found in vrf %s\n",
2021 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT
2022 ? VRF_DEFAULT_NAME
2023 : bgp->name);
2024 vrf_cfg = true;
2025 }
2026 }
2027 }
2028
2029 if (vrf_cfg) {
2030 vty_out(vty,
2031 "%%Failed: global update-delay config not permitted\n");
2032 return CMD_WARNING;
2033 }
2034
2035 if (!establish_wait) { /* update-delay <delay> */
2036 bm->v_update_delay = update_delay;
2037 bm->v_establish_wait = bm->v_update_delay;
2038 } else {
2039 /* update-delay <delay> <establish-wait> */
2040 if (update_delay < establish_wait) {
2041 vty_out(vty,
2042 "%%Failed: update-delay less than the establish-wait!\n");
2043 return CMD_WARNING_CONFIG_FAILED;
2044 }
2045
2046 bm->v_update_delay = update_delay;
2047 bm->v_establish_wait = establish_wait;
2048 }
2049
2050 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2051 bgp->v_update_delay = bm->v_update_delay;
2052 bgp->v_establish_wait = bm->v_establish_wait;
2053 }
2054
2055 return CMD_SUCCESS;
2056 }
2057
2058 static int bgp_global_update_delay_deconfig_vty(struct vty *vty)
2059 {
2060 struct listnode *node, *nnode;
2061 struct bgp *bgp;
2062
2063 bm->v_update_delay = BGP_UPDATE_DELAY_DEF;
2064 bm->v_establish_wait = bm->v_update_delay;
2065
2066 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2067 bgp->v_update_delay = bm->v_update_delay;
2068 bgp->v_establish_wait = bm->v_establish_wait;
2069 }
2070
2071 return CMD_SUCCESS;
2072 }
2073
2074 static int bgp_update_delay_config_vty(struct vty *vty, uint16_t update_delay,
2075 uint16_t establish_wait)
2076 {
2077 VTY_DECLVAR_CONTEXT(bgp, bgp);
2078
2079 /* if configured globally, per-instance config is not allowed */
2080 if (bm->v_update_delay) {
2081 vty_out(vty,
2082 "%%Failed: per-vrf update-delay config not permitted with global update-delay\n");
2083 return CMD_WARNING_CONFIG_FAILED;
2084 }
2085
2086
2087 if (!establish_wait) /* update-delay <delay> */
2088 {
2089 bgp->v_update_delay = update_delay;
2090 bgp->v_establish_wait = bgp->v_update_delay;
2091 return CMD_SUCCESS;
2092 }
2093
2094 /* update-delay <delay> <establish-wait> */
2095 if (update_delay < establish_wait) {
2096 vty_out(vty,
2097 "%%Failed: update-delay less than the establish-wait!\n");
2098 return CMD_WARNING_CONFIG_FAILED;
2099 }
2100
2101 bgp->v_update_delay = update_delay;
2102 bgp->v_establish_wait = establish_wait;
2103
2104 return CMD_SUCCESS;
2105 }
2106
2107 static int bgp_update_delay_deconfig_vty(struct vty *vty)
2108 {
2109 VTY_DECLVAR_CONTEXT(bgp, bgp);
2110
2111 /* If configured globally, cannot remove from one bgp instance */
2112 if (bm->v_update_delay) {
2113 vty_out(vty,
2114 "%%Failed: bgp update-delay configured globally. Delete per-vrf not permitted\n");
2115 return CMD_WARNING_CONFIG_FAILED;
2116 }
2117 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
2118 bgp->v_establish_wait = bgp->v_update_delay;
2119
2120 return CMD_SUCCESS;
2121 }
2122
2123 void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
2124 {
2125 /* If configured globally, no need to display per-instance value */
2126 if (bgp->v_update_delay != bm->v_update_delay) {
2127 vty_out(vty, " update-delay %d", bgp->v_update_delay);
2128 if (bgp->v_update_delay != bgp->v_establish_wait)
2129 vty_out(vty, " %d", bgp->v_establish_wait);
2130 vty_out(vty, "\n");
2131 }
2132 }
2133
2134 /* Global update-delay configuration */
2135 DEFPY (bgp_global_update_delay,
2136 bgp_global_update_delay_cmd,
2137 "bgp update-delay (0-3600)$delay [(1-3600)$wait]",
2138 BGP_STR
2139 "Force initial delay for best-path and updates for all bgp instances\n"
2140 "Max delay in seconds\n"
2141 "Establish wait in seconds\n")
2142 {
2143 return bgp_global_update_delay_config_vty(vty, delay, wait);
2144 }
2145
2146 /* Global update-delay deconfiguration */
2147 DEFPY (no_bgp_global_update_delay,
2148 no_bgp_global_update_delay_cmd,
2149 "no bgp update-delay [(0-3600) [(1-3600)]]",
2150 NO_STR
2151 BGP_STR
2152 "Force initial delay for best-path and updates\n"
2153 "Max delay in seconds\n"
2154 "Establish wait in seconds\n")
2155 {
2156 return bgp_global_update_delay_deconfig_vty(vty);
2157 }
2158
2159 /* Update-delay configuration */
2160
2161 DEFPY (bgp_update_delay,
2162 bgp_update_delay_cmd,
2163 "update-delay (0-3600)$delay [(1-3600)$wait]",
2164 "Force initial delay for best-path and updates\n"
2165 "Max delay in seconds\n"
2166 "Establish wait in seconds\n")
2167 {
2168 return bgp_update_delay_config_vty(vty, delay, wait);
2169 }
2170
2171 /* Update-delay deconfiguration */
2172 DEFPY (no_bgp_update_delay,
2173 no_bgp_update_delay_cmd,
2174 "no update-delay [(0-3600) [(1-3600)]]",
2175 NO_STR
2176 "Force initial delay for best-path and updates\n"
2177 "Max delay in seconds\n"
2178 "Establish wait in seconds\n")
2179 {
2180 return bgp_update_delay_deconfig_vty(vty);
2181 }
2182
2183
2184 static int bgp_wpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2185 bool set)
2186 {
2187 VTY_DECLVAR_CONTEXT(bgp, bgp);
2188
2189 quanta = set ? quanta : BGP_WRITE_PACKET_MAX;
2190 atomic_store_explicit(&bgp->wpkt_quanta, quanta, memory_order_relaxed);
2191
2192 return CMD_SUCCESS;
2193 }
2194
2195 static int bgp_rpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2196 bool set)
2197 {
2198 VTY_DECLVAR_CONTEXT(bgp, bgp);
2199
2200 quanta = set ? quanta : BGP_READ_PACKET_MAX;
2201 atomic_store_explicit(&bgp->rpkt_quanta, quanta, memory_order_relaxed);
2202
2203 return CMD_SUCCESS;
2204 }
2205
2206 void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
2207 {
2208 uint32_t quanta =
2209 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
2210 if (quanta != BGP_WRITE_PACKET_MAX)
2211 vty_out(vty, " write-quanta %d\n", quanta);
2212 }
2213
2214 void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
2215 {
2216 uint32_t quanta =
2217 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
2218 if (quanta != BGP_READ_PACKET_MAX)
2219 vty_out(vty, " read-quanta %d\n", quanta);
2220 }
2221
2222 /* Packet quanta configuration
2223 *
2224 * XXX: The value set here controls the size of a stack buffer in the IO
2225 * thread. When changing these limits be careful to prevent stack overflow.
2226 *
2227 * Furthermore, the maximums used here should correspond to
2228 * BGP_WRITE_PACKET_MAX and BGP_READ_PACKET_MAX.
2229 */
2230 DEFPY (bgp_wpkt_quanta,
2231 bgp_wpkt_quanta_cmd,
2232 "[no] write-quanta (1-64)$quanta",
2233 NO_STR
2234 "How many packets to write to peer socket per run\n"
2235 "Number of packets\n")
2236 {
2237 return bgp_wpkt_quanta_config_vty(vty, quanta, !no);
2238 }
2239
2240 DEFPY (bgp_rpkt_quanta,
2241 bgp_rpkt_quanta_cmd,
2242 "[no] read-quanta (1-10)$quanta",
2243 NO_STR
2244 "How many packets to read from peer socket per I/O cycle\n"
2245 "Number of packets\n")
2246 {
2247 return bgp_rpkt_quanta_config_vty(vty, quanta, !no);
2248 }
2249
2250 void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
2251 {
2252 if (!bgp->heuristic_coalesce)
2253 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
2254 }
2255
2256
2257 DEFUN (bgp_coalesce_time,
2258 bgp_coalesce_time_cmd,
2259 "coalesce-time (0-4294967295)",
2260 "Subgroup coalesce timer\n"
2261 "Subgroup coalesce timer value (in ms)\n")
2262 {
2263 VTY_DECLVAR_CONTEXT(bgp, bgp);
2264
2265 int idx = 0;
2266 argv_find(argv, argc, "(0-4294967295)", &idx);
2267 bgp->heuristic_coalesce = false;
2268 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
2269 return CMD_SUCCESS;
2270 }
2271
2272 DEFUN (no_bgp_coalesce_time,
2273 no_bgp_coalesce_time_cmd,
2274 "no coalesce-time (0-4294967295)",
2275 NO_STR
2276 "Subgroup coalesce timer\n"
2277 "Subgroup coalesce timer value (in ms)\n")
2278 {
2279 VTY_DECLVAR_CONTEXT(bgp, bgp);
2280
2281 bgp->heuristic_coalesce = true;
2282 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
2283 return CMD_SUCCESS;
2284 }
2285
2286 /* Maximum-paths configuration */
2287 DEFUN (bgp_maxpaths,
2288 bgp_maxpaths_cmd,
2289 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2290 "Forward packets over multiple paths\n"
2291 "Number of paths\n")
2292 {
2293 int idx_number = 1;
2294 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
2295 argv[idx_number]->arg, 0, 1);
2296 }
2297
2298 ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
2299 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2300 "Forward packets over multiple paths\n"
2301 "Number of paths\n")
2302
2303 DEFUN (bgp_maxpaths_ibgp,
2304 bgp_maxpaths_ibgp_cmd,
2305 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2306 "Forward packets over multiple paths\n"
2307 "iBGP-multipath\n"
2308 "Number of paths\n")
2309 {
2310 int idx_number = 2;
2311 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
2312 argv[idx_number]->arg, 0, 1);
2313 }
2314
2315 ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
2316 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2317 "Forward packets over multiple paths\n"
2318 "iBGP-multipath\n"
2319 "Number of paths\n")
2320
2321 DEFUN (bgp_maxpaths_ibgp_cluster,
2322 bgp_maxpaths_ibgp_cluster_cmd,
2323 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
2324 "Forward packets over multiple paths\n"
2325 "iBGP-multipath\n"
2326 "Number of paths\n"
2327 "Match the cluster length\n")
2328 {
2329 int idx_number = 2;
2330 return bgp_maxpaths_config_vty(
2331 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
2332 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
2333 }
2334
2335 ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
2336 "maximum-paths ibgp " CMD_RANGE_STR(
2337 1, MULTIPATH_NUM) " equal-cluster-length",
2338 "Forward packets over multiple paths\n"
2339 "iBGP-multipath\n"
2340 "Number of paths\n"
2341 "Match the cluster length\n")
2342
2343 DEFUN (no_bgp_maxpaths,
2344 no_bgp_maxpaths_cmd,
2345 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
2346 NO_STR
2347 "Forward packets over multiple paths\n"
2348 "Number of paths\n")
2349 {
2350 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
2351 }
2352
2353 ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
2354 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
2355 "Forward packets over multiple paths\n"
2356 "Number of paths\n")
2357
2358 DEFUN (no_bgp_maxpaths_ibgp,
2359 no_bgp_maxpaths_ibgp_cmd,
2360 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
2361 NO_STR
2362 "Forward packets over multiple paths\n"
2363 "iBGP-multipath\n"
2364 "Number of paths\n"
2365 "Match the cluster length\n")
2366 {
2367 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
2368 }
2369
2370 ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
2371 "no maximum-paths ibgp [" CMD_RANGE_STR(
2372 1, MULTIPATH_NUM) " [equal-cluster-length]]",
2373 NO_STR
2374 "Forward packets over multiple paths\n"
2375 "iBGP-multipath\n"
2376 "Number of paths\n"
2377 "Match the cluster length\n")
2378
2379 static void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp,
2380 afi_t afi, safi_t safi)
2381 {
2382 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != multipath_num) {
2383 vty_out(vty, " maximum-paths %d\n",
2384 bgp->maxpaths[afi][safi].maxpaths_ebgp);
2385 }
2386
2387 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != multipath_num) {
2388 vty_out(vty, " maximum-paths ibgp %d",
2389 bgp->maxpaths[afi][safi].maxpaths_ibgp);
2390 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
2391 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
2392 vty_out(vty, " equal-cluster-length");
2393 vty_out(vty, "\n");
2394 }
2395 }
2396
2397 /* BGP timers. */
2398
2399 DEFUN (bgp_timers,
2400 bgp_timers_cmd,
2401 "timers bgp (0-65535) (0-65535)",
2402 "Adjust routing timers\n"
2403 "BGP timers\n"
2404 "Keepalive interval\n"
2405 "Holdtime\n")
2406 {
2407 VTY_DECLVAR_CONTEXT(bgp, bgp);
2408 int idx_number = 2;
2409 int idx_number_2 = 3;
2410 unsigned long keepalive = 0;
2411 unsigned long holdtime = 0;
2412
2413 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
2414 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
2415
2416 /* Holdtime value check. */
2417 if (holdtime < 3 && holdtime != 0) {
2418 vty_out(vty,
2419 "%% hold time value must be either 0 or greater than 3\n");
2420 return CMD_WARNING_CONFIG_FAILED;
2421 }
2422
2423 bgp_timers_set(bgp, keepalive, holdtime, DFLT_BGP_CONNECT_RETRY,
2424 BGP_DEFAULT_DELAYOPEN);
2425
2426 return CMD_SUCCESS;
2427 }
2428
2429 DEFUN (no_bgp_timers,
2430 no_bgp_timers_cmd,
2431 "no timers bgp [(0-65535) (0-65535)]",
2432 NO_STR
2433 "Adjust routing timers\n"
2434 "BGP timers\n"
2435 "Keepalive interval\n"
2436 "Holdtime\n")
2437 {
2438 VTY_DECLVAR_CONTEXT(bgp, bgp);
2439 bgp_timers_set(bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
2440 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
2441
2442 return CMD_SUCCESS;
2443 }
2444
2445 /* BGP minimum holdtime. */
2446
2447 DEFUN(bgp_minimum_holdtime, bgp_minimum_holdtime_cmd,
2448 "bgp minimum-holdtime (1-65535)",
2449 "BGP specific commands\n"
2450 "BGP minimum holdtime\n"
2451 "Seconds\n")
2452 {
2453 VTY_DECLVAR_CONTEXT(bgp, bgp);
2454 int idx_number = 2;
2455 unsigned long min_holdtime;
2456
2457 min_holdtime = strtoul(argv[idx_number]->arg, NULL, 10);
2458
2459 bgp->default_min_holdtime = min_holdtime;
2460
2461 return CMD_SUCCESS;
2462 }
2463
2464 DEFUN(no_bgp_minimum_holdtime, no_bgp_minimum_holdtime_cmd,
2465 "no bgp minimum-holdtime [(1-65535)]",
2466 NO_STR
2467 "BGP specific commands\n"
2468 "BGP minimum holdtime\n"
2469 "Seconds\n")
2470 {
2471 VTY_DECLVAR_CONTEXT(bgp, bgp);
2472
2473 bgp->default_min_holdtime = 0;
2474
2475 return CMD_SUCCESS;
2476 }
2477
2478 DEFUN (bgp_client_to_client_reflection,
2479 bgp_client_to_client_reflection_cmd,
2480 "bgp client-to-client reflection",
2481 BGP_STR
2482 "Configure client to client route reflection\n"
2483 "reflection of routes allowed\n")
2484 {
2485 VTY_DECLVAR_CONTEXT(bgp, bgp);
2486 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2487 bgp_clear_star_soft_out(vty, bgp->name);
2488
2489 return CMD_SUCCESS;
2490 }
2491
2492 DEFUN (no_bgp_client_to_client_reflection,
2493 no_bgp_client_to_client_reflection_cmd,
2494 "no bgp client-to-client reflection",
2495 NO_STR
2496 BGP_STR
2497 "Configure client to client route reflection\n"
2498 "reflection of routes allowed\n")
2499 {
2500 VTY_DECLVAR_CONTEXT(bgp, bgp);
2501 SET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2502 bgp_clear_star_soft_out(vty, bgp->name);
2503
2504 return CMD_SUCCESS;
2505 }
2506
2507 /* "bgp always-compare-med" configuration. */
2508 DEFUN (bgp_always_compare_med,
2509 bgp_always_compare_med_cmd,
2510 "bgp always-compare-med",
2511 BGP_STR
2512 "Allow comparing MED from different neighbors\n")
2513 {
2514 VTY_DECLVAR_CONTEXT(bgp, bgp);
2515 SET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2516 bgp_recalculate_all_bestpaths(bgp);
2517
2518 return CMD_SUCCESS;
2519 }
2520
2521 DEFUN (no_bgp_always_compare_med,
2522 no_bgp_always_compare_med_cmd,
2523 "no bgp always-compare-med",
2524 NO_STR
2525 BGP_STR
2526 "Allow comparing MED from different neighbors\n")
2527 {
2528 VTY_DECLVAR_CONTEXT(bgp, bgp);
2529 UNSET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2530 bgp_recalculate_all_bestpaths(bgp);
2531
2532 return CMD_SUCCESS;
2533 }
2534
2535
2536 DEFUN(bgp_ebgp_requires_policy, bgp_ebgp_requires_policy_cmd,
2537 "bgp ebgp-requires-policy",
2538 BGP_STR
2539 "Require in and out policy for eBGP peers (RFC8212)\n")
2540 {
2541 VTY_DECLVAR_CONTEXT(bgp, bgp);
2542 SET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2543 return CMD_SUCCESS;
2544 }
2545
2546 DEFUN(no_bgp_ebgp_requires_policy, no_bgp_ebgp_requires_policy_cmd,
2547 "no bgp ebgp-requires-policy",
2548 NO_STR
2549 BGP_STR
2550 "Require in and out policy for eBGP peers (RFC8212)\n")
2551 {
2552 VTY_DECLVAR_CONTEXT(bgp, bgp);
2553 UNSET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2554 return CMD_SUCCESS;
2555 }
2556
2557 DEFUN(bgp_suppress_duplicates, bgp_suppress_duplicates_cmd,
2558 "bgp suppress-duplicates",
2559 BGP_STR
2560 "Suppress duplicate updates if the route actually not changed\n")
2561 {
2562 VTY_DECLVAR_CONTEXT(bgp, bgp);
2563 SET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2564 return CMD_SUCCESS;
2565 }
2566
2567 DEFUN(no_bgp_suppress_duplicates, no_bgp_suppress_duplicates_cmd,
2568 "no bgp suppress-duplicates",
2569 NO_STR
2570 BGP_STR
2571 "Suppress duplicate updates if the route actually not changed\n")
2572 {
2573 VTY_DECLVAR_CONTEXT(bgp, bgp);
2574 UNSET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2575 return CMD_SUCCESS;
2576 }
2577
2578 DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd,
2579 "bgp reject-as-sets",
2580 BGP_STR
2581 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2582 {
2583 VTY_DECLVAR_CONTEXT(bgp, bgp);
2584 struct listnode *node, *nnode;
2585 struct peer *peer;
2586
2587 bgp->reject_as_sets = true;
2588
2589 /* Reset existing BGP sessions to reject routes
2590 * with aspath containing AS_SET or AS_CONFED_SET.
2591 */
2592 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2593 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2594 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2595 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2596 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2597 }
2598 }
2599
2600 return CMD_SUCCESS;
2601 }
2602
2603 DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd,
2604 "no bgp reject-as-sets",
2605 NO_STR
2606 BGP_STR
2607 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2608 {
2609 VTY_DECLVAR_CONTEXT(bgp, bgp);
2610 struct listnode *node, *nnode;
2611 struct peer *peer;
2612
2613 bgp->reject_as_sets = false;
2614
2615 /* Reset existing BGP sessions to reject routes
2616 * with aspath containing AS_SET or AS_CONFED_SET.
2617 */
2618 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2619 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2620 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2621 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2622 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2623 }
2624 }
2625
2626 return CMD_SUCCESS;
2627 }
2628
2629 /* "bgp deterministic-med" configuration. */
2630 DEFUN (bgp_deterministic_med,
2631 bgp_deterministic_med_cmd,
2632 "bgp deterministic-med",
2633 BGP_STR
2634 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2635 {
2636 VTY_DECLVAR_CONTEXT(bgp, bgp);
2637
2638 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2639 SET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2640 bgp_recalculate_all_bestpaths(bgp);
2641 }
2642
2643 return CMD_SUCCESS;
2644 }
2645
2646 DEFUN (no_bgp_deterministic_med,
2647 no_bgp_deterministic_med_cmd,
2648 "no bgp deterministic-med",
2649 NO_STR
2650 BGP_STR
2651 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2652 {
2653 VTY_DECLVAR_CONTEXT(bgp, bgp);
2654 int bestpath_per_as_used;
2655 afi_t afi;
2656 safi_t safi;
2657 struct peer *peer;
2658 struct listnode *node, *nnode;
2659
2660 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2661 bestpath_per_as_used = 0;
2662
2663 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2664 FOREACH_AFI_SAFI (afi, safi)
2665 if (bgp_addpath_dmed_required(
2666 peer->addpath_type[afi][safi])) {
2667 bestpath_per_as_used = 1;
2668 break;
2669 }
2670
2671 if (bestpath_per_as_used)
2672 break;
2673 }
2674
2675 if (bestpath_per_as_used) {
2676 vty_out(vty,
2677 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
2678 return CMD_WARNING_CONFIG_FAILED;
2679 } else {
2680 UNSET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2681 bgp_recalculate_all_bestpaths(bgp);
2682 }
2683 }
2684
2685 return CMD_SUCCESS;
2686 }
2687
2688 /* "bgp graceful-restart mode" configuration. */
2689 DEFUN (bgp_graceful_restart,
2690 bgp_graceful_restart_cmd,
2691 "bgp graceful-restart",
2692 BGP_STR
2693 GR_CMD
2694 )
2695 {
2696 int ret = BGP_GR_FAILURE;
2697
2698 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2699 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : START ");
2700
2701 VTY_DECLVAR_CONTEXT(bgp, bgp);
2702
2703 ret = bgp_gr_update_all(bgp, GLOBAL_GR_CMD);
2704
2705 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2706 ret);
2707
2708 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2709 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : END ");
2710 vty_out(vty,
2711 "Graceful restart configuration changed, reset all peers to take effect\n");
2712 return bgp_vty_return(vty, ret);
2713 }
2714
2715 DEFUN (no_bgp_graceful_restart,
2716 no_bgp_graceful_restart_cmd,
2717 "no bgp graceful-restart",
2718 NO_STR
2719 BGP_STR
2720 NO_GR_CMD
2721 )
2722 {
2723 VTY_DECLVAR_CONTEXT(bgp, bgp);
2724
2725 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2726 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : START ");
2727
2728 int ret = BGP_GR_FAILURE;
2729
2730 ret = bgp_gr_update_all(bgp, NO_GLOBAL_GR_CMD);
2731
2732 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2733 ret);
2734
2735 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2736 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : END ");
2737 vty_out(vty,
2738 "Graceful restart configuration changed, reset all peers to take effect\n");
2739
2740 return bgp_vty_return(vty, ret);
2741 }
2742
2743 DEFUN (bgp_graceful_restart_stalepath_time,
2744 bgp_graceful_restart_stalepath_time_cmd,
2745 "bgp graceful-restart stalepath-time (1-4095)",
2746 BGP_STR
2747 "Graceful restart capability parameters\n"
2748 "Set the max time to hold onto restarting peer's stale paths\n"
2749 "Delay value (seconds)\n")
2750 {
2751 VTY_DECLVAR_CONTEXT(bgp, bgp);
2752 int idx_number = 3;
2753 uint32_t stalepath;
2754
2755 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2756 bgp->stalepath_time = stalepath;
2757 return CMD_SUCCESS;
2758 }
2759
2760 DEFUN (bgp_graceful_restart_restart_time,
2761 bgp_graceful_restart_restart_time_cmd,
2762 "bgp graceful-restart restart-time (0-4095)",
2763 BGP_STR
2764 "Graceful restart capability parameters\n"
2765 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2766 "Delay value (seconds)\n")
2767 {
2768 VTY_DECLVAR_CONTEXT(bgp, bgp);
2769 int idx_number = 3;
2770 uint32_t restart;
2771
2772 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2773 bgp->restart_time = restart;
2774 return CMD_SUCCESS;
2775 }
2776
2777 DEFUN (bgp_graceful_restart_select_defer_time,
2778 bgp_graceful_restart_select_defer_time_cmd,
2779 "bgp graceful-restart select-defer-time (0-3600)",
2780 BGP_STR
2781 "Graceful restart capability parameters\n"
2782 "Set the time to defer the BGP route selection after restart\n"
2783 "Delay value (seconds, 0 - disable)\n")
2784 {
2785 VTY_DECLVAR_CONTEXT(bgp, bgp);
2786 int idx_number = 3;
2787 uint32_t defer_time;
2788
2789 defer_time = strtoul(argv[idx_number]->arg, NULL, 10);
2790 bgp->select_defer_time = defer_time;
2791 if (defer_time == 0)
2792 SET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2793 else
2794 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2795
2796 return CMD_SUCCESS;
2797 }
2798
2799 DEFUN (no_bgp_graceful_restart_stalepath_time,
2800 no_bgp_graceful_restart_stalepath_time_cmd,
2801 "no bgp graceful-restart stalepath-time [(1-4095)]",
2802 NO_STR
2803 BGP_STR
2804 "Graceful restart capability parameters\n"
2805 "Set the max time to hold onto restarting peer's stale paths\n"
2806 "Delay value (seconds)\n")
2807 {
2808 VTY_DECLVAR_CONTEXT(bgp, bgp);
2809
2810 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2811 return CMD_SUCCESS;
2812 }
2813
2814 DEFUN (no_bgp_graceful_restart_restart_time,
2815 no_bgp_graceful_restart_restart_time_cmd,
2816 "no bgp graceful-restart restart-time [(0-4095)]",
2817 NO_STR
2818 BGP_STR
2819 "Graceful restart capability parameters\n"
2820 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2821 "Delay value (seconds)\n")
2822 {
2823 VTY_DECLVAR_CONTEXT(bgp, bgp);
2824
2825 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2826 return CMD_SUCCESS;
2827 }
2828
2829 DEFUN (no_bgp_graceful_restart_select_defer_time,
2830 no_bgp_graceful_restart_select_defer_time_cmd,
2831 "no bgp graceful-restart select-defer-time [(0-3600)]",
2832 NO_STR
2833 BGP_STR
2834 "Graceful restart capability parameters\n"
2835 "Set the time to defer the BGP route selection after restart\n"
2836 "Delay value (seconds)\n")
2837 {
2838 VTY_DECLVAR_CONTEXT(bgp, bgp);
2839
2840 bgp->select_defer_time = BGP_DEFAULT_SELECT_DEFERRAL_TIME;
2841 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2842
2843 return CMD_SUCCESS;
2844 }
2845
2846 DEFUN (bgp_graceful_restart_preserve_fw,
2847 bgp_graceful_restart_preserve_fw_cmd,
2848 "bgp graceful-restart preserve-fw-state",
2849 BGP_STR
2850 "Graceful restart capability parameters\n"
2851 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
2852 {
2853 VTY_DECLVAR_CONTEXT(bgp, bgp);
2854 SET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
2855 return CMD_SUCCESS;
2856 }
2857
2858 DEFUN (no_bgp_graceful_restart_preserve_fw,
2859 no_bgp_graceful_restart_preserve_fw_cmd,
2860 "no bgp graceful-restart preserve-fw-state",
2861 NO_STR
2862 BGP_STR
2863 "Graceful restart capability parameters\n"
2864 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
2865 {
2866 VTY_DECLVAR_CONTEXT(bgp, bgp);
2867 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
2868 return CMD_SUCCESS;
2869 }
2870
2871 DEFUN (bgp_graceful_restart_disable,
2872 bgp_graceful_restart_disable_cmd,
2873 "bgp graceful-restart-disable",
2874 BGP_STR
2875 GR_DISABLE)
2876 {
2877 int ret = BGP_GR_FAILURE;
2878
2879 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2880 zlog_debug(
2881 "[BGP_GR] bgp_graceful_restart_disable_cmd : START ");
2882
2883 VTY_DECLVAR_CONTEXT(bgp, bgp);
2884
2885 ret = bgp_gr_update_all(bgp, GLOBAL_DISABLE_CMD);
2886
2887 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
2888 bgp->peer, ret);
2889
2890 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2891 zlog_debug(
2892 "[BGP_GR] bgp_graceful_restart_disable_cmd : END ");
2893 vty_out(vty,
2894 "Graceful restart configuration changed, reset all peers to take effect\n");
2895
2896 return bgp_vty_return(vty, ret);
2897 }
2898
2899 DEFUN (no_bgp_graceful_restart_disable,
2900 no_bgp_graceful_restart_disable_cmd,
2901 "no bgp graceful-restart-disable",
2902 NO_STR
2903 BGP_STR
2904 NO_GR_DISABLE
2905 )
2906 {
2907 VTY_DECLVAR_CONTEXT(bgp, bgp);
2908
2909 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2910 zlog_debug(
2911 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : START ");
2912
2913 int ret = BGP_GR_FAILURE;
2914
2915 ret = bgp_gr_update_all(bgp, NO_GLOBAL_DISABLE_CMD);
2916
2917 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2918 ret);
2919
2920 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2921 zlog_debug(
2922 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : END ");
2923 vty_out(vty,
2924 "Graceful restart configuration changed, reset all peers to take effect\n");
2925
2926 return bgp_vty_return(vty, ret);
2927 }
2928
2929 DEFUN (bgp_neighbor_graceful_restart_set,
2930 bgp_neighbor_graceful_restart_set_cmd,
2931 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
2932 NEIGHBOR_STR
2933 NEIGHBOR_ADDR_STR2
2934 GR_NEIGHBOR_CMD
2935 )
2936 {
2937 int idx_peer = 1;
2938 struct peer *peer;
2939 int ret = BGP_GR_FAILURE;
2940
2941 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2942
2943 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2944 zlog_debug(
2945 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : START ");
2946
2947 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2948 if (!peer)
2949 return CMD_WARNING_CONFIG_FAILED;
2950
2951 ret = bgp_neighbor_graceful_restart(peer, PEER_GR_CMD);
2952
2953 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2954 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
2955
2956 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2957 zlog_debug(
2958 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : END ");
2959 vty_out(vty,
2960 "Graceful restart configuration changed, reset this peer to take effect\n");
2961
2962 return bgp_vty_return(vty, ret);
2963 }
2964
2965 DEFUN (no_bgp_neighbor_graceful_restart,
2966 no_bgp_neighbor_graceful_restart_set_cmd,
2967 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
2968 NO_STR
2969 NEIGHBOR_STR
2970 NEIGHBOR_ADDR_STR2
2971 NO_GR_NEIGHBOR_CMD
2972 )
2973 {
2974 int idx_peer = 2;
2975 int ret = BGP_GR_FAILURE;
2976 struct peer *peer;
2977
2978 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2979
2980 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2981 if (!peer)
2982 return CMD_WARNING_CONFIG_FAILED;
2983
2984 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2985 zlog_debug(
2986 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : START ");
2987
2988 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_GR_CMD);
2989
2990 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2991 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
2992
2993 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2994 zlog_debug(
2995 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : END ");
2996 vty_out(vty,
2997 "Graceful restart configuration changed, reset this peer to take effect\n");
2998
2999 return bgp_vty_return(vty, ret);
3000 }
3001
3002 DEFUN (bgp_neighbor_graceful_restart_helper_set,
3003 bgp_neighbor_graceful_restart_helper_set_cmd,
3004 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3005 NEIGHBOR_STR
3006 NEIGHBOR_ADDR_STR2
3007 GR_NEIGHBOR_HELPER_CMD
3008 )
3009 {
3010 int idx_peer = 1;
3011 struct peer *peer;
3012 int ret = BGP_GR_FAILURE;
3013
3014 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3015
3016 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3017 zlog_debug(
3018 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : START ");
3019
3020 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3021
3022 if (!peer)
3023 return CMD_WARNING_CONFIG_FAILED;
3024
3025
3026 ret = bgp_neighbor_graceful_restart(peer, PEER_HELPER_CMD);
3027
3028 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3029 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3030
3031 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3032 zlog_debug(
3033 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : END ");
3034 vty_out(vty,
3035 "Graceful restart configuration changed, reset this peer to take effect\n");
3036
3037 return bgp_vty_return(vty, ret);
3038 }
3039
3040 DEFUN (no_bgp_neighbor_graceful_restart_helper,
3041 no_bgp_neighbor_graceful_restart_helper_set_cmd,
3042 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3043 NO_STR
3044 NEIGHBOR_STR
3045 NEIGHBOR_ADDR_STR2
3046 NO_GR_NEIGHBOR_HELPER_CMD
3047 )
3048 {
3049 int idx_peer = 2;
3050 int ret = BGP_GR_FAILURE;
3051 struct peer *peer;
3052
3053 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3054
3055 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3056 if (!peer)
3057 return CMD_WARNING_CONFIG_FAILED;
3058
3059 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3060 zlog_debug(
3061 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : START ");
3062
3063 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_HELPER_CMD);
3064
3065 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3066 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3067
3068 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3069 zlog_debug(
3070 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : END ");
3071 vty_out(vty,
3072 "Graceful restart configuration changed, reset this peer to take effect\n");
3073
3074 return bgp_vty_return(vty, ret);
3075 }
3076
3077 DEFUN (bgp_neighbor_graceful_restart_disable_set,
3078 bgp_neighbor_graceful_restart_disable_set_cmd,
3079 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3080 NEIGHBOR_STR
3081 NEIGHBOR_ADDR_STR2
3082 GR_NEIGHBOR_DISABLE_CMD
3083 )
3084 {
3085 int idx_peer = 1;
3086 struct peer *peer;
3087 int ret = BGP_GR_FAILURE;
3088
3089 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3090
3091 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3092 zlog_debug(
3093 "[BGP_GR] bgp_neighbor_graceful_restart_disable_set_cmd : START ");
3094
3095 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3096 if (!peer)
3097 return CMD_WARNING_CONFIG_FAILED;
3098
3099 ret = bgp_neighbor_graceful_restart(peer, PEER_DISABLE_CMD);
3100
3101 if (peer->bgp->t_startup)
3102 bgp_peer_gr_flags_update(peer);
3103
3104 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3105 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3106
3107 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3108 zlog_debug(
3109 "[BGP_GR]bgp_neighbor_graceful_restart_disable_set_cmd : END ");
3110 vty_out(vty,
3111 "Graceful restart configuration changed, reset this peer to take effect\n");
3112
3113 return bgp_vty_return(vty, ret);
3114 }
3115
3116 DEFUN (no_bgp_neighbor_graceful_restart_disable,
3117 no_bgp_neighbor_graceful_restart_disable_set_cmd,
3118 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3119 NO_STR
3120 NEIGHBOR_STR
3121 NEIGHBOR_ADDR_STR2
3122 NO_GR_NEIGHBOR_DISABLE_CMD
3123 )
3124 {
3125 int idx_peer = 2;
3126 int ret = BGP_GR_FAILURE;
3127 struct peer *peer;
3128
3129 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3130
3131 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3132 if (!peer)
3133 return CMD_WARNING_CONFIG_FAILED;
3134
3135 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3136 zlog_debug(
3137 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : START ");
3138
3139 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_DISABLE_CMD);
3140
3141 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3142 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3143
3144 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3145 zlog_debug(
3146 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : END ");
3147 vty_out(vty,
3148 "Graceful restart configuration changed, reset this peer to take effect\n");
3149
3150 return bgp_vty_return(vty, ret);
3151 }
3152
3153 DEFUN_HIDDEN (bgp_graceful_restart_disable_eor,
3154 bgp_graceful_restart_disable_eor_cmd,
3155 "bgp graceful-restart disable-eor",
3156 BGP_STR
3157 "Graceful restart configuration parameters\n"
3158 "Disable EOR Check\n")
3159 {
3160 VTY_DECLVAR_CONTEXT(bgp, bgp);
3161 SET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
3162
3163 return CMD_SUCCESS;
3164 }
3165
3166 DEFUN_HIDDEN (no_bgp_graceful_restart_disable_eor,
3167 no_bgp_graceful_restart_disable_eor_cmd,
3168 "no bgp graceful-restart disable-eor",
3169 NO_STR
3170 BGP_STR
3171 "Graceful restart configuration parameters\n"
3172 "Disable EOR Check\n")
3173 {
3174 VTY_DECLVAR_CONTEXT(bgp, bgp);
3175 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
3176
3177 return CMD_SUCCESS;
3178 }
3179
3180 DEFUN (bgp_graceful_restart_rib_stale_time,
3181 bgp_graceful_restart_rib_stale_time_cmd,
3182 "bgp graceful-restart rib-stale-time (1-3600)",
3183 BGP_STR
3184 "Graceful restart configuration parameters\n"
3185 "Specify the stale route removal timer in rib\n"
3186 "Delay value (seconds)\n")
3187 {
3188 VTY_DECLVAR_CONTEXT(bgp, bgp);
3189 int idx_number = 3;
3190 uint32_t stale_time;
3191
3192 stale_time = strtoul(argv[idx_number]->arg, NULL, 10);
3193 bgp->rib_stale_time = stale_time;
3194 /* Send the stale timer update message to RIB */
3195 if (bgp_zebra_stale_timer_update(bgp))
3196 return CMD_WARNING;
3197
3198 return CMD_SUCCESS;
3199 }
3200
3201 DEFUN (no_bgp_graceful_restart_rib_stale_time,
3202 no_bgp_graceful_restart_rib_stale_time_cmd,
3203 "no bgp graceful-restart rib-stale-time [(1-3600)]",
3204 NO_STR
3205 BGP_STR
3206 "Graceful restart configuration parameters\n"
3207 "Specify the stale route removal timer in rib\n"
3208 "Delay value (seconds)\n")
3209 {
3210 VTY_DECLVAR_CONTEXT(bgp, bgp);
3211
3212 bgp->rib_stale_time = BGP_DEFAULT_RIB_STALE_TIME;
3213 /* Send the stale timer update message to RIB */
3214 if (bgp_zebra_stale_timer_update(bgp))
3215 return CMD_WARNING;
3216
3217 return CMD_SUCCESS;
3218 }
3219
3220 DEFUN(bgp_llgr_stalepath_time, bgp_llgr_stalepath_time_cmd,
3221 "bgp long-lived-graceful-restart stale-time (1-4294967295)",
3222 BGP_STR
3223 "Enable Long-lived Graceful Restart\n"
3224 "Specifies maximum time to wait before purging long-lived stale routes\n"
3225 "Stale time value (seconds)\n")
3226 {
3227 VTY_DECLVAR_CONTEXT(bgp, bgp);
3228
3229 uint32_t llgr_stale_time;
3230
3231 llgr_stale_time = strtoul(argv[3]->arg, NULL, 10);
3232 bgp->llgr_stale_time = llgr_stale_time;
3233
3234 return CMD_SUCCESS;
3235 }
3236
3237 DEFUN(no_bgp_llgr_stalepath_time, no_bgp_llgr_stalepath_time_cmd,
3238 "no bgp long-lived-graceful-restart stale-time [(1-4294967295)]",
3239 NO_STR BGP_STR
3240 "Enable Long-lived Graceful Restart\n"
3241 "Specifies maximum time to wait before purging long-lived stale routes\n"
3242 "Stale time value (seconds)\n")
3243 {
3244 VTY_DECLVAR_CONTEXT(bgp, bgp);
3245
3246 bgp->llgr_stale_time = BGP_DEFAULT_LLGR_STALE_TIME;
3247
3248 return CMD_SUCCESS;
3249 }
3250
3251 static inline void bgp_initiate_graceful_shut_unshut(struct vty *vty,
3252 struct bgp *bgp)
3253 {
3254 bgp_static_redo_import_check(bgp);
3255 bgp_redistribute_redo(bgp);
3256 bgp_clear_star_soft_out(vty, bgp->name);
3257 bgp_clear_star_soft_in(vty, bgp->name);
3258 }
3259
3260 static int bgp_global_graceful_shutdown_config_vty(struct vty *vty)
3261 {
3262 struct listnode *node, *nnode;
3263 struct bgp *bgp;
3264 bool vrf_cfg = false;
3265
3266 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3267 return CMD_SUCCESS;
3268
3269 /* See if graceful-shutdown is set per-vrf and warn user to delete */
3270 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3271 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3272 vty_out(vty,
3273 "%% graceful-shutdown configuration found in vrf %s\n",
3274 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT ?
3275 VRF_DEFAULT_NAME : bgp->name);
3276 vrf_cfg = true;
3277 }
3278 }
3279
3280 if (vrf_cfg) {
3281 vty_out(vty,
3282 "%%Failed: global graceful-shutdown not permitted\n");
3283 return CMD_WARNING;
3284 }
3285
3286 /* Set flag globally */
3287 SET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3288
3289 /* Initiate processing for all BGP instances. */
3290 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3291 bgp_initiate_graceful_shut_unshut(vty, bgp);
3292
3293 return CMD_SUCCESS;
3294 }
3295
3296 static int bgp_global_graceful_shutdown_deconfig_vty(struct vty *vty)
3297 {
3298 struct listnode *node, *nnode;
3299 struct bgp *bgp;
3300
3301 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3302 return CMD_SUCCESS;
3303
3304 /* Unset flag globally */
3305 UNSET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3306
3307 /* Initiate processing for all BGP instances. */
3308 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3309 bgp_initiate_graceful_shut_unshut(vty, bgp);
3310
3311 return CMD_SUCCESS;
3312 }
3313
3314 /* "bgp graceful-shutdown" configuration */
3315 DEFUN (bgp_graceful_shutdown,
3316 bgp_graceful_shutdown_cmd,
3317 "bgp graceful-shutdown",
3318 BGP_STR
3319 "Graceful shutdown parameters\n")
3320 {
3321 if (vty->node == CONFIG_NODE)
3322 return bgp_global_graceful_shutdown_config_vty(vty);
3323
3324 VTY_DECLVAR_CONTEXT(bgp, bgp);
3325
3326 /* if configured globally, per-instance config is not allowed */
3327 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3328 vty_out(vty,
3329 "%%Failed: per-vrf graceful-shutdown config not permitted with global graceful-shutdown\n");
3330 return CMD_WARNING_CONFIG_FAILED;
3331 }
3332
3333 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3334 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3335 bgp_initiate_graceful_shut_unshut(vty, bgp);
3336 }
3337
3338 return CMD_SUCCESS;
3339 }
3340
3341 DEFUN (no_bgp_graceful_shutdown,
3342 no_bgp_graceful_shutdown_cmd,
3343 "no bgp graceful-shutdown",
3344 NO_STR
3345 BGP_STR
3346 "Graceful shutdown parameters\n")
3347 {
3348 if (vty->node == CONFIG_NODE)
3349 return bgp_global_graceful_shutdown_deconfig_vty(vty);
3350
3351 VTY_DECLVAR_CONTEXT(bgp, bgp);
3352
3353 /* If configured globally, cannot remove from one bgp instance */
3354 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3355 vty_out(vty,
3356 "%%Failed: bgp graceful-shutdown configured globally. Delete per-vrf not permitted\n");
3357 return CMD_WARNING_CONFIG_FAILED;
3358 }
3359
3360 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3361 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3362 bgp_initiate_graceful_shut_unshut(vty, bgp);
3363 }
3364
3365 return CMD_SUCCESS;
3366 }
3367
3368 /* "bgp fast-external-failover" configuration. */
3369 DEFUN (bgp_fast_external_failover,
3370 bgp_fast_external_failover_cmd,
3371 "bgp fast-external-failover",
3372 BGP_STR
3373 "Immediately reset session if a link to a directly connected external peer goes down\n")
3374 {
3375 VTY_DECLVAR_CONTEXT(bgp, bgp);
3376 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3377 return CMD_SUCCESS;
3378 }
3379
3380 DEFUN (no_bgp_fast_external_failover,
3381 no_bgp_fast_external_failover_cmd,
3382 "no bgp fast-external-failover",
3383 NO_STR
3384 BGP_STR
3385 "Immediately reset session if a link to a directly connected external peer goes down\n")
3386 {
3387 VTY_DECLVAR_CONTEXT(bgp, bgp);
3388 SET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3389 return CMD_SUCCESS;
3390 }
3391
3392 /* "bgp bestpath compare-routerid" configuration. */
3393 DEFUN (bgp_bestpath_compare_router_id,
3394 bgp_bestpath_compare_router_id_cmd,
3395 "bgp bestpath compare-routerid",
3396 BGP_STR
3397 "Change the default bestpath selection\n"
3398 "Compare router-id for identical EBGP paths\n")
3399 {
3400 VTY_DECLVAR_CONTEXT(bgp, bgp);
3401 SET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3402 bgp_recalculate_all_bestpaths(bgp);
3403
3404 return CMD_SUCCESS;
3405 }
3406
3407 DEFUN (no_bgp_bestpath_compare_router_id,
3408 no_bgp_bestpath_compare_router_id_cmd,
3409 "no bgp bestpath compare-routerid",
3410 NO_STR
3411 BGP_STR
3412 "Change the default bestpath selection\n"
3413 "Compare router-id for identical EBGP paths\n")
3414 {
3415 VTY_DECLVAR_CONTEXT(bgp, bgp);
3416 UNSET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3417 bgp_recalculate_all_bestpaths(bgp);
3418
3419 return CMD_SUCCESS;
3420 }
3421
3422 /* "bgp bestpath as-path ignore" configuration. */
3423 DEFUN (bgp_bestpath_aspath_ignore,
3424 bgp_bestpath_aspath_ignore_cmd,
3425 "bgp bestpath as-path ignore",
3426 BGP_STR
3427 "Change the default bestpath selection\n"
3428 "AS-path attribute\n"
3429 "Ignore as-path length in selecting a route\n")
3430 {
3431 VTY_DECLVAR_CONTEXT(bgp, bgp);
3432 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3433 bgp_recalculate_all_bestpaths(bgp);
3434
3435 return CMD_SUCCESS;
3436 }
3437
3438 DEFUN (no_bgp_bestpath_aspath_ignore,
3439 no_bgp_bestpath_aspath_ignore_cmd,
3440 "no bgp bestpath as-path ignore",
3441 NO_STR
3442 BGP_STR
3443 "Change the default bestpath selection\n"
3444 "AS-path attribute\n"
3445 "Ignore as-path length in selecting a route\n")
3446 {
3447 VTY_DECLVAR_CONTEXT(bgp, bgp);
3448 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3449 bgp_recalculate_all_bestpaths(bgp);
3450
3451 return CMD_SUCCESS;
3452 }
3453
3454 /* "bgp bestpath as-path confed" configuration. */
3455 DEFUN (bgp_bestpath_aspath_confed,
3456 bgp_bestpath_aspath_confed_cmd,
3457 "bgp bestpath as-path confed",
3458 BGP_STR
3459 "Change the default bestpath selection\n"
3460 "AS-path attribute\n"
3461 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3462 {
3463 VTY_DECLVAR_CONTEXT(bgp, bgp);
3464 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3465 bgp_recalculate_all_bestpaths(bgp);
3466
3467 return CMD_SUCCESS;
3468 }
3469
3470 DEFUN (no_bgp_bestpath_aspath_confed,
3471 no_bgp_bestpath_aspath_confed_cmd,
3472 "no bgp bestpath as-path confed",
3473 NO_STR
3474 BGP_STR
3475 "Change the default bestpath selection\n"
3476 "AS-path attribute\n"
3477 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3478 {
3479 VTY_DECLVAR_CONTEXT(bgp, bgp);
3480 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3481 bgp_recalculate_all_bestpaths(bgp);
3482
3483 return CMD_SUCCESS;
3484 }
3485
3486 /* "bgp bestpath as-path multipath-relax" configuration. */
3487 DEFUN (bgp_bestpath_aspath_multipath_relax,
3488 bgp_bestpath_aspath_multipath_relax_cmd,
3489 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
3490 BGP_STR
3491 "Change the default bestpath selection\n"
3492 "AS-path attribute\n"
3493 "Allow load sharing across routes that have different AS paths (but same length)\n"
3494 "Generate an AS_SET\n"
3495 "Do not generate an AS_SET\n")
3496 {
3497 VTY_DECLVAR_CONTEXT(bgp, bgp);
3498 int idx = 0;
3499 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
3500
3501 /* no-as-set is now the default behavior so we can silently
3502 * ignore it */
3503 if (argv_find(argv, argc, "as-set", &idx))
3504 SET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3505 else
3506 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3507
3508 bgp_recalculate_all_bestpaths(bgp);
3509
3510 return CMD_SUCCESS;
3511 }
3512
3513 DEFUN (no_bgp_bestpath_aspath_multipath_relax,
3514 no_bgp_bestpath_aspath_multipath_relax_cmd,
3515 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
3516 NO_STR
3517 BGP_STR
3518 "Change the default bestpath selection\n"
3519 "AS-path attribute\n"
3520 "Allow load sharing across routes that have different AS paths (but same length)\n"
3521 "Generate an AS_SET\n"
3522 "Do not generate an AS_SET\n")
3523 {
3524 VTY_DECLVAR_CONTEXT(bgp, bgp);
3525 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
3526 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3527 bgp_recalculate_all_bestpaths(bgp);
3528
3529 return CMD_SUCCESS;
3530 }
3531
3532 /* "bgp bestpath peer-type multipath-relax" configuration. */
3533 DEFUN(bgp_bestpath_peer_type_multipath_relax,
3534 bgp_bestpath_peer_type_multipath_relax_cmd,
3535 "bgp bestpath peer-type multipath-relax",
3536 BGP_STR
3537 "Change the default bestpath selection\n"
3538 "Peer type\n"
3539 "Allow load sharing across routes learned from different peer types\n")
3540 {
3541 VTY_DECLVAR_CONTEXT(bgp, bgp);
3542 SET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3543 bgp_recalculate_all_bestpaths(bgp);
3544
3545 return CMD_SUCCESS;
3546 }
3547
3548 DEFUN(no_bgp_bestpath_peer_type_multipath_relax,
3549 no_bgp_bestpath_peer_type_multipath_relax_cmd,
3550 "no bgp bestpath peer-type multipath-relax",
3551 NO_STR BGP_STR
3552 "Change the default bestpath selection\n"
3553 "Peer type\n"
3554 "Allow load sharing across routes learned from different peer types\n")
3555 {
3556 VTY_DECLVAR_CONTEXT(bgp, bgp);
3557 UNSET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3558 bgp_recalculate_all_bestpaths(bgp);
3559
3560 return CMD_SUCCESS;
3561 }
3562
3563 /* "bgp log-neighbor-changes" configuration. */
3564 DEFUN (bgp_log_neighbor_changes,
3565 bgp_log_neighbor_changes_cmd,
3566 "bgp log-neighbor-changes",
3567 BGP_STR
3568 "Log neighbor up/down and reset reason\n")
3569 {
3570 VTY_DECLVAR_CONTEXT(bgp, bgp);
3571 SET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3572 return CMD_SUCCESS;
3573 }
3574
3575 DEFUN (no_bgp_log_neighbor_changes,
3576 no_bgp_log_neighbor_changes_cmd,
3577 "no bgp log-neighbor-changes",
3578 NO_STR
3579 BGP_STR
3580 "Log neighbor up/down and reset reason\n")
3581 {
3582 VTY_DECLVAR_CONTEXT(bgp, bgp);
3583 UNSET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3584 return CMD_SUCCESS;
3585 }
3586
3587 /* "bgp bestpath med" configuration. */
3588 DEFUN (bgp_bestpath_med,
3589 bgp_bestpath_med_cmd,
3590 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
3591 BGP_STR
3592 "Change the default bestpath selection\n"
3593 "MED attribute\n"
3594 "Compare MED among confederation paths\n"
3595 "Treat missing MED as the least preferred one\n"
3596 "Treat missing MED as the least preferred one\n"
3597 "Compare MED among confederation paths\n")
3598 {
3599 VTY_DECLVAR_CONTEXT(bgp, bgp);
3600
3601 int idx = 0;
3602 if (argv_find(argv, argc, "confed", &idx))
3603 SET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
3604 idx = 0;
3605 if (argv_find(argv, argc, "missing-as-worst", &idx))
3606 SET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
3607
3608 bgp_recalculate_all_bestpaths(bgp);
3609
3610 return CMD_SUCCESS;
3611 }
3612
3613 DEFUN (no_bgp_bestpath_med,
3614 no_bgp_bestpath_med_cmd,
3615 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
3616 NO_STR
3617 BGP_STR
3618 "Change the default bestpath selection\n"
3619 "MED attribute\n"
3620 "Compare MED among confederation paths\n"
3621 "Treat missing MED as the least preferred one\n"
3622 "Treat missing MED as the least preferred one\n"
3623 "Compare MED among confederation paths\n")
3624 {
3625 VTY_DECLVAR_CONTEXT(bgp, bgp);
3626
3627 int idx = 0;
3628 if (argv_find(argv, argc, "confed", &idx))
3629 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
3630 idx = 0;
3631 if (argv_find(argv, argc, "missing-as-worst", &idx))
3632 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
3633
3634 bgp_recalculate_all_bestpaths(bgp);
3635
3636 return CMD_SUCCESS;
3637 }
3638
3639 /* "bgp bestpath bandwidth" configuration. */
3640 DEFPY (bgp_bestpath_bw,
3641 bgp_bestpath_bw_cmd,
3642 "bgp bestpath bandwidth <ignore|skip-missing|default-weight-for-missing>$bw_cfg",
3643 BGP_STR
3644 "Change the default bestpath selection\n"
3645 "Link Bandwidth attribute\n"
3646 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3647 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3648 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3649 {
3650 VTY_DECLVAR_CONTEXT(bgp, bgp);
3651 afi_t afi;
3652 safi_t safi;
3653
3654 if (!bw_cfg) {
3655 vty_out(vty, "%% Bandwidth configuration must be specified\n");
3656 return CMD_ERR_INCOMPLETE;
3657 }
3658 if (!strcmp(bw_cfg, "ignore"))
3659 bgp->lb_handling = BGP_LINK_BW_IGNORE_BW;
3660 else if (!strcmp(bw_cfg, "skip-missing"))
3661 bgp->lb_handling = BGP_LINK_BW_SKIP_MISSING;
3662 else if (!strcmp(bw_cfg, "default-weight-for-missing"))
3663 bgp->lb_handling = BGP_LINK_BW_DEFWT_4_MISSING;
3664 else
3665 return CMD_ERR_NO_MATCH;
3666
3667 /* This config is used in route install, so redo that. */
3668 FOREACH_AFI_SAFI (afi, safi) {
3669 if (!bgp_fibupd_safi(safi))
3670 continue;
3671 bgp_zebra_announce_table(bgp, afi, safi);
3672 }
3673
3674 return CMD_SUCCESS;
3675 }
3676
3677 DEFPY (no_bgp_bestpath_bw,
3678 no_bgp_bestpath_bw_cmd,
3679 "no bgp bestpath bandwidth [<ignore|skip-missing|default-weight-for-missing>$bw_cfg]",
3680 NO_STR
3681 BGP_STR
3682 "Change the default bestpath selection\n"
3683 "Link Bandwidth attribute\n"
3684 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3685 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3686 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3687 {
3688 VTY_DECLVAR_CONTEXT(bgp, bgp);
3689 afi_t afi;
3690 safi_t safi;
3691
3692 bgp->lb_handling = BGP_LINK_BW_ECMP;
3693
3694 /* This config is used in route install, so redo that. */
3695 FOREACH_AFI_SAFI (afi, safi) {
3696 if (!bgp_fibupd_safi(safi))
3697 continue;
3698 bgp_zebra_announce_table(bgp, afi, safi);
3699 }
3700 return CMD_SUCCESS;
3701 }
3702
3703 DEFPY(bgp_default_afi_safi, bgp_default_afi_safi_cmd,
3704 "[no] bgp default <ipv4-unicast|"
3705 "ipv4-multicast|"
3706 "ipv4-vpn|"
3707 "ipv4-labeled-unicast|"
3708 "ipv4-flowspec|"
3709 "ipv6-unicast|"
3710 "ipv6-multicast|"
3711 "ipv6-vpn|"
3712 "ipv6-labeled-unicast|"
3713 "ipv6-flowspec|"
3714 "l2vpn-evpn>$afi_safi",
3715 NO_STR
3716 BGP_STR
3717 "Configure BGP defaults\n"
3718 "Activate ipv4-unicast for a peer by default\n"
3719 "Activate ipv4-multicast for a peer by default\n"
3720 "Activate ipv4-vpn for a peer by default\n"
3721 "Activate ipv4-labeled-unicast for a peer by default\n"
3722 "Activate ipv4-flowspec for a peer by default\n"
3723 "Activate ipv6-unicast for a peer by default\n"
3724 "Activate ipv6-multicast for a peer by default\n"
3725 "Activate ipv6-vpn for a peer by default\n"
3726 "Activate ipv6-labeled-unicast for a peer by default\n"
3727 "Activate ipv6-flowspec for a peer by default\n"
3728 "Activate l2vpn-evpn for a peer by default\n")
3729 {
3730 VTY_DECLVAR_CONTEXT(bgp, bgp);
3731 char afi_safi_str[strlen(afi_safi) + 1];
3732 char *afi_safi_str_tok;
3733
3734 strlcpy(afi_safi_str, afi_safi, sizeof(afi_safi_str));
3735 char *afi_str = strtok_r(afi_safi_str, "-", &afi_safi_str_tok);
3736 char *safi_str = strtok_r(NULL, "-", &afi_safi_str_tok);
3737 afi_t afi = bgp_vty_afi_from_str(afi_str);
3738 safi_t safi;
3739
3740 if (strmatch(safi_str, "labeled"))
3741 safi = bgp_vty_safi_from_str("labeled-unicast");
3742 else
3743 safi = bgp_vty_safi_from_str(safi_str);
3744
3745 if (no)
3746 bgp->default_af[afi][safi] = false;
3747 else {
3748 if ((safi == SAFI_LABELED_UNICAST
3749 && bgp->default_af[afi][SAFI_UNICAST])
3750 || (safi == SAFI_UNICAST
3751 && bgp->default_af[afi][SAFI_LABELED_UNICAST]))
3752 bgp_vty_return(vty, BGP_ERR_PEER_SAFI_CONFLICT);
3753 else
3754 bgp->default_af[afi][safi] = true;
3755 }
3756
3757 return CMD_SUCCESS;
3758 }
3759
3760 /* Display hostname in certain command outputs */
3761 DEFUN (bgp_default_show_hostname,
3762 bgp_default_show_hostname_cmd,
3763 "bgp default show-hostname",
3764 BGP_STR
3765 "Configure BGP defaults\n"
3766 "Show hostname in certain command outputs\n")
3767 {
3768 VTY_DECLVAR_CONTEXT(bgp, bgp);
3769 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
3770 return CMD_SUCCESS;
3771 }
3772
3773 DEFUN (no_bgp_default_show_hostname,
3774 no_bgp_default_show_hostname_cmd,
3775 "no bgp default show-hostname",
3776 NO_STR
3777 BGP_STR
3778 "Configure BGP defaults\n"
3779 "Show hostname in certain command outputs\n")
3780 {
3781 VTY_DECLVAR_CONTEXT(bgp, bgp);
3782 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
3783 return CMD_SUCCESS;
3784 }
3785
3786 /* Display hostname in certain command outputs */
3787 DEFUN (bgp_default_show_nexthop_hostname,
3788 bgp_default_show_nexthop_hostname_cmd,
3789 "bgp default show-nexthop-hostname",
3790 BGP_STR
3791 "Configure BGP defaults\n"
3792 "Show hostname for nexthop in certain command outputs\n")
3793 {
3794 VTY_DECLVAR_CONTEXT(bgp, bgp);
3795 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
3796 return CMD_SUCCESS;
3797 }
3798
3799 DEFUN (no_bgp_default_show_nexthop_hostname,
3800 no_bgp_default_show_nexthop_hostname_cmd,
3801 "no bgp default show-nexthop-hostname",
3802 NO_STR
3803 BGP_STR
3804 "Configure BGP defaults\n"
3805 "Show hostname for nexthop in certain command outputs\n")
3806 {
3807 VTY_DECLVAR_CONTEXT(bgp, bgp);
3808 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
3809 return CMD_SUCCESS;
3810 }
3811
3812 /* "bgp network import-check" configuration. */
3813 DEFUN (bgp_network_import_check,
3814 bgp_network_import_check_cmd,
3815 "bgp network import-check",
3816 BGP_STR
3817 "BGP network command\n"
3818 "Check BGP network route exists in IGP\n")
3819 {
3820 VTY_DECLVAR_CONTEXT(bgp, bgp);
3821 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
3822 SET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
3823 bgp_static_redo_import_check(bgp);
3824 }
3825
3826 return CMD_SUCCESS;
3827 }
3828
3829 ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
3830 "bgp network import-check exact",
3831 BGP_STR
3832 "BGP network command\n"
3833 "Check BGP network route exists in IGP\n"
3834 "Match route precisely\n")
3835
3836 DEFUN (no_bgp_network_import_check,
3837 no_bgp_network_import_check_cmd,
3838 "no bgp network import-check",
3839 NO_STR
3840 BGP_STR
3841 "BGP network command\n"
3842 "Check BGP network route exists in IGP\n")
3843 {
3844 VTY_DECLVAR_CONTEXT(bgp, bgp);
3845 if (CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
3846 UNSET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
3847 bgp_static_redo_import_check(bgp);
3848 }
3849
3850 return CMD_SUCCESS;
3851 }
3852
3853 DEFUN (bgp_default_local_preference,
3854 bgp_default_local_preference_cmd,
3855 "bgp default local-preference (0-4294967295)",
3856 BGP_STR
3857 "Configure BGP defaults\n"
3858 "local preference (higher=more preferred)\n"
3859 "Configure default local preference value\n")
3860 {
3861 VTY_DECLVAR_CONTEXT(bgp, bgp);
3862 int idx_number = 3;
3863 uint32_t local_pref;
3864
3865 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
3866
3867 bgp_default_local_preference_set(bgp, local_pref);
3868 bgp_clear_star_soft_in(vty, bgp->name);
3869
3870 return CMD_SUCCESS;
3871 }
3872
3873 DEFUN (no_bgp_default_local_preference,
3874 no_bgp_default_local_preference_cmd,
3875 "no bgp default local-preference [(0-4294967295)]",
3876 NO_STR
3877 BGP_STR
3878 "Configure BGP defaults\n"
3879 "local preference (higher=more preferred)\n"
3880 "Configure default local preference value\n")
3881 {
3882 VTY_DECLVAR_CONTEXT(bgp, bgp);
3883 bgp_default_local_preference_unset(bgp);
3884 bgp_clear_star_soft_in(vty, bgp->name);
3885
3886 return CMD_SUCCESS;
3887 }
3888
3889
3890 DEFUN (bgp_default_subgroup_pkt_queue_max,
3891 bgp_default_subgroup_pkt_queue_max_cmd,
3892 "bgp default subgroup-pkt-queue-max (20-100)",
3893 BGP_STR
3894 "Configure BGP defaults\n"
3895 "subgroup-pkt-queue-max\n"
3896 "Configure subgroup packet queue max\n")
3897 {
3898 VTY_DECLVAR_CONTEXT(bgp, bgp);
3899 int idx_number = 3;
3900 uint32_t max_size;
3901
3902 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
3903
3904 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
3905
3906 return CMD_SUCCESS;
3907 }
3908
3909 DEFUN (no_bgp_default_subgroup_pkt_queue_max,
3910 no_bgp_default_subgroup_pkt_queue_max_cmd,
3911 "no bgp default subgroup-pkt-queue-max [(20-100)]",
3912 NO_STR
3913 BGP_STR
3914 "Configure BGP defaults\n"
3915 "subgroup-pkt-queue-max\n"
3916 "Configure subgroup packet queue max\n")
3917 {
3918 VTY_DECLVAR_CONTEXT(bgp, bgp);
3919 bgp_default_subgroup_pkt_queue_max_unset(bgp);
3920 return CMD_SUCCESS;
3921 }
3922
3923
3924 DEFUN (bgp_rr_allow_outbound_policy,
3925 bgp_rr_allow_outbound_policy_cmd,
3926 "bgp route-reflector allow-outbound-policy",
3927 BGP_STR
3928 "Allow modifications made by out route-map\n"
3929 "on ibgp neighbors\n")
3930 {
3931 VTY_DECLVAR_CONTEXT(bgp, bgp);
3932
3933 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
3934 SET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
3935 update_group_announce_rrclients(bgp);
3936 bgp_clear_star_soft_out(vty, bgp->name);
3937 }
3938
3939 return CMD_SUCCESS;
3940 }
3941
3942 DEFUN (no_bgp_rr_allow_outbound_policy,
3943 no_bgp_rr_allow_outbound_policy_cmd,
3944 "no bgp route-reflector allow-outbound-policy",
3945 NO_STR
3946 BGP_STR
3947 "Allow modifications made by out route-map\n"
3948 "on ibgp neighbors\n")
3949 {
3950 VTY_DECLVAR_CONTEXT(bgp, bgp);
3951
3952 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
3953 UNSET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
3954 update_group_announce_rrclients(bgp);
3955 bgp_clear_star_soft_out(vty, bgp->name);
3956 }
3957
3958 return CMD_SUCCESS;
3959 }
3960
3961 DEFUN (bgp_listen_limit,
3962 bgp_listen_limit_cmd,
3963 "bgp listen limit (1-65535)",
3964 BGP_STR
3965 "BGP Dynamic Neighbors listen commands\n"
3966 "Maximum number of BGP Dynamic Neighbors that can be created\n"
3967 "Configure Dynamic Neighbors listen limit value\n")
3968 {
3969 VTY_DECLVAR_CONTEXT(bgp, bgp);
3970 int idx_number = 3;
3971 int listen_limit;
3972
3973 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
3974
3975 bgp_listen_limit_set(bgp, listen_limit);
3976
3977 return CMD_SUCCESS;
3978 }
3979
3980 DEFUN (no_bgp_listen_limit,
3981 no_bgp_listen_limit_cmd,
3982 "no bgp listen limit [(1-65535)]",
3983 NO_STR
3984 BGP_STR
3985 "BGP Dynamic Neighbors listen commands\n"
3986 "Maximum number of BGP Dynamic Neighbors that can be created\n"
3987 "Configure Dynamic Neighbors listen limit value\n")
3988 {
3989 VTY_DECLVAR_CONTEXT(bgp, bgp);
3990 bgp_listen_limit_unset(bgp);
3991 return CMD_SUCCESS;
3992 }
3993
3994
3995 /*
3996 * Check if this listen range is already configured. Check for exact
3997 * match or overlap based on input.
3998 */
3999 static struct peer_group *listen_range_exists(struct bgp *bgp,
4000 struct prefix *range, int exact)
4001 {
4002 struct listnode *node, *nnode;
4003 struct listnode *node1, *nnode1;
4004 struct peer_group *group;
4005 struct prefix *lr;
4006 afi_t afi;
4007 int match;
4008
4009 afi = family2afi(range->family);
4010 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4011 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
4012 lr)) {
4013 if (exact)
4014 match = prefix_same(range, lr);
4015 else
4016 match = (prefix_match(range, lr)
4017 || prefix_match(lr, range));
4018 if (match)
4019 return group;
4020 }
4021 }
4022
4023 return NULL;
4024 }
4025
4026 DEFUN (bgp_listen_range,
4027 bgp_listen_range_cmd,
4028 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
4029 BGP_STR
4030 "Configure BGP dynamic neighbors listen range\n"
4031 "Configure BGP dynamic neighbors listen range\n"
4032 NEIGHBOR_ADDR_STR
4033 "Member of the peer-group\n"
4034 "Peer-group name\n")
4035 {
4036 VTY_DECLVAR_CONTEXT(bgp, bgp);
4037 struct prefix range;
4038 struct peer_group *group, *existing_group;
4039 afi_t afi;
4040 int ret;
4041 int idx = 0;
4042
4043 argv_find(argv, argc, "A.B.C.D/M", &idx);
4044 argv_find(argv, argc, "X:X::X:X/M", &idx);
4045 char *prefix = argv[idx]->arg;
4046 argv_find(argv, argc, "PGNAME", &idx);
4047 char *peergroup = argv[idx]->arg;
4048
4049 /* Convert IP prefix string to struct prefix. */
4050 ret = str2prefix(prefix, &range);
4051 if (!ret) {
4052 vty_out(vty, "%% Malformed listen range\n");
4053 return CMD_WARNING_CONFIG_FAILED;
4054 }
4055
4056 afi = family2afi(range.family);
4057
4058 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4059 vty_out(vty,
4060 "%% Malformed listen range (link-local address)\n");
4061 return CMD_WARNING_CONFIG_FAILED;
4062 }
4063
4064 apply_mask(&range);
4065
4066 /* Check if same listen range is already configured. */
4067 existing_group = listen_range_exists(bgp, &range, 1);
4068 if (existing_group) {
4069 if (strcmp(existing_group->name, peergroup) == 0)
4070 return CMD_SUCCESS;
4071 else {
4072 vty_out(vty,
4073 "%% Same listen range is attached to peer-group %s\n",
4074 existing_group->name);
4075 return CMD_WARNING_CONFIG_FAILED;
4076 }
4077 }
4078
4079 /* Check if an overlapping listen range exists. */
4080 if (listen_range_exists(bgp, &range, 0)) {
4081 vty_out(vty,
4082 "%% Listen range overlaps with existing listen range\n");
4083 return CMD_WARNING_CONFIG_FAILED;
4084 }
4085
4086 group = peer_group_lookup(bgp, peergroup);
4087 if (!group) {
4088 vty_out(vty, "%% Configure the peer-group first\n");
4089 return CMD_WARNING_CONFIG_FAILED;
4090 }
4091
4092 ret = peer_group_listen_range_add(group, &range);
4093 return bgp_vty_return(vty, ret);
4094 }
4095
4096 DEFUN (no_bgp_listen_range,
4097 no_bgp_listen_range_cmd,
4098 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
4099 NO_STR
4100 BGP_STR
4101 "Unconfigure BGP dynamic neighbors listen range\n"
4102 "Unconfigure BGP dynamic neighbors listen range\n"
4103 NEIGHBOR_ADDR_STR
4104 "Member of the peer-group\n"
4105 "Peer-group name\n")
4106 {
4107 VTY_DECLVAR_CONTEXT(bgp, bgp);
4108 struct prefix range;
4109 struct peer_group *group;
4110 afi_t afi;
4111 int ret;
4112 int idx = 0;
4113
4114 argv_find(argv, argc, "A.B.C.D/M", &idx);
4115 argv_find(argv, argc, "X:X::X:X/M", &idx);
4116 char *prefix = argv[idx]->arg;
4117 argv_find(argv, argc, "PGNAME", &idx);
4118 char *peergroup = argv[idx]->arg;
4119
4120 /* Convert IP prefix string to struct prefix. */
4121 ret = str2prefix(prefix, &range);
4122 if (!ret) {
4123 vty_out(vty, "%% Malformed listen range\n");
4124 return CMD_WARNING_CONFIG_FAILED;
4125 }
4126
4127 afi = family2afi(range.family);
4128
4129 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4130 vty_out(vty,
4131 "%% Malformed listen range (link-local address)\n");
4132 return CMD_WARNING_CONFIG_FAILED;
4133 }
4134
4135 apply_mask(&range);
4136
4137 group = peer_group_lookup(bgp, peergroup);
4138 if (!group) {
4139 vty_out(vty, "%% Peer-group does not exist\n");
4140 return CMD_WARNING_CONFIG_FAILED;
4141 }
4142
4143 ret = peer_group_listen_range_del(group, &range);
4144 return bgp_vty_return(vty, ret);
4145 }
4146
4147 void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
4148 {
4149 struct peer_group *group;
4150 struct listnode *node, *nnode, *rnode, *nrnode;
4151 struct prefix *range;
4152 afi_t afi;
4153
4154 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
4155 vty_out(vty, " bgp listen limit %d\n",
4156 bgp->dynamic_neighbors_limit);
4157
4158 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4159 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
4160 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
4161 nrnode, range)) {
4162 vty_out(vty,
4163 " bgp listen range %pFX peer-group %s\n",
4164 range, group->name);
4165 }
4166 }
4167 }
4168 }
4169
4170
4171 DEFUN (bgp_disable_connected_route_check,
4172 bgp_disable_connected_route_check_cmd,
4173 "bgp disable-ebgp-connected-route-check",
4174 BGP_STR
4175 "Disable checking if nexthop is connected on ebgp sessions\n")
4176 {
4177 VTY_DECLVAR_CONTEXT(bgp, bgp);
4178 SET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4179 bgp_clear_star_soft_in(vty, bgp->name);
4180
4181 return CMD_SUCCESS;
4182 }
4183
4184 DEFUN (no_bgp_disable_connected_route_check,
4185 no_bgp_disable_connected_route_check_cmd,
4186 "no bgp disable-ebgp-connected-route-check",
4187 NO_STR
4188 BGP_STR
4189 "Disable checking if nexthop is connected on ebgp sessions\n")
4190 {
4191 VTY_DECLVAR_CONTEXT(bgp, bgp);
4192 UNSET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4193 bgp_clear_star_soft_in(vty, bgp->name);
4194
4195 return CMD_SUCCESS;
4196 }
4197
4198
4199 static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
4200 const char *as_str)
4201 {
4202 VTY_DECLVAR_CONTEXT(bgp, bgp);
4203 int ret;
4204 as_t as;
4205 int as_type = AS_SPECIFIED;
4206 union sockunion su;
4207
4208 if (as_str[0] == 'i') {
4209 as = 0;
4210 as_type = AS_INTERNAL;
4211 } else if (as_str[0] == 'e') {
4212 as = 0;
4213 as_type = AS_EXTERNAL;
4214 } else {
4215 /* Get AS number. */
4216 as = strtoul(as_str, NULL, 10);
4217 }
4218
4219 /* If peer is peer group or interface peer, call proper function. */
4220 ret = str2sockunion(peer_str, &su);
4221 if (ret < 0) {
4222 struct peer *peer;
4223
4224 /* Check if existing interface peer */
4225 peer = peer_lookup_by_conf_if(bgp, peer_str);
4226
4227 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type);
4228
4229 /* if not interface peer, check peer-group settings */
4230 if (ret < 0 && !peer) {
4231 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
4232 if (ret < 0) {
4233 vty_out(vty,
4234 "%% Create the peer-group or interface first\n");
4235 return CMD_WARNING_CONFIG_FAILED;
4236 }
4237 return CMD_SUCCESS;
4238 }
4239 } else {
4240 if (peer_address_self_check(bgp, &su)) {
4241 vty_out(vty,
4242 "%% Can not configure the local system as neighbor\n");
4243 return CMD_WARNING_CONFIG_FAILED;
4244 }
4245 ret = peer_remote_as(bgp, &su, NULL, &as, as_type);
4246 }
4247
4248 return bgp_vty_return(vty, ret);
4249 }
4250
4251 DEFUN (bgp_default_shutdown,
4252 bgp_default_shutdown_cmd,
4253 "[no] bgp default shutdown",
4254 NO_STR
4255 BGP_STR
4256 "Configure BGP defaults\n"
4257 "Apply administrative shutdown to newly configured peers\n")
4258 {
4259 VTY_DECLVAR_CONTEXT(bgp, bgp);
4260 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
4261 return CMD_SUCCESS;
4262 }
4263
4264 DEFPY(bgp_shutdown_msg, bgp_shutdown_msg_cmd, "bgp shutdown message MSG...",
4265 BGP_STR
4266 "Administrative shutdown of the BGP instance\n"
4267 "Add a shutdown message (RFC 8203)\n"
4268 "Shutdown message\n")
4269 {
4270 char *msgstr = NULL;
4271
4272 VTY_DECLVAR_CONTEXT(bgp, bgp);
4273
4274 if (argc > 3)
4275 msgstr = argv_concat(argv, argc, 3);
4276
4277 if (msgstr && strlen(msgstr) > BGP_ADMIN_SHUTDOWN_MSG_LEN) {
4278 vty_out(vty, "%% Shutdown message size exceeded %d\n",
4279 BGP_ADMIN_SHUTDOWN_MSG_LEN);
4280 return CMD_WARNING_CONFIG_FAILED;
4281 }
4282
4283 bgp_shutdown_enable(bgp, msgstr);
4284 XFREE(MTYPE_TMP, msgstr);
4285
4286 return CMD_SUCCESS;
4287 }
4288
4289 DEFPY(bgp_shutdown, bgp_shutdown_cmd, "bgp shutdown",
4290 BGP_STR "Administrative shutdown of the BGP instance\n")
4291 {
4292 VTY_DECLVAR_CONTEXT(bgp, bgp);
4293
4294 bgp_shutdown_enable(bgp, NULL);
4295
4296 return CMD_SUCCESS;
4297 }
4298
4299 DEFPY(no_bgp_shutdown, no_bgp_shutdown_cmd, "no bgp shutdown",
4300 NO_STR BGP_STR "Administrative shutdown of the BGP instance\n")
4301 {
4302 VTY_DECLVAR_CONTEXT(bgp, bgp);
4303
4304 bgp_shutdown_disable(bgp);
4305
4306 return CMD_SUCCESS;
4307 }
4308
4309 ALIAS(no_bgp_shutdown, no_bgp_shutdown_msg_cmd,
4310 "no bgp shutdown message MSG...", NO_STR BGP_STR
4311 "Administrative shutdown of the BGP instance\n"
4312 "Add a shutdown message (RFC 8203)\n" "Shutdown message\n")
4313
4314 DEFUN (neighbor_remote_as,
4315 neighbor_remote_as_cmd,
4316 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
4317 NEIGHBOR_STR
4318 NEIGHBOR_ADDR_STR2
4319 "Specify a BGP neighbor\n"
4320 AS_STR
4321 "Internal BGP peer\n"
4322 "External BGP peer\n")
4323 {
4324 int idx_peer = 1;
4325 int idx_remote_as = 3;
4326 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
4327 argv[idx_remote_as]->arg);
4328 }
4329 /* Enable fast convergence of bgp sessions. If this is enabled, bgp
4330 * sessions do not wait for hold timer expiry to bring down the sessions
4331 * when nexthop becomes unreachable
4332 */
4333 DEFUN(bgp_fast_convergence, bgp_fast_convergence_cmd, "bgp fast-convergence",
4334 BGP_STR "Fast convergence for bgp sessions\n")
4335 {
4336 VTY_DECLVAR_CONTEXT(bgp, bgp);
4337 bgp->fast_convergence = true;
4338
4339 return CMD_SUCCESS;
4340 }
4341
4342 DEFUN(no_bgp_fast_convergence, no_bgp_fast_convergence_cmd,
4343 "no bgp fast-convergence",
4344 NO_STR BGP_STR "Fast convergence for bgp sessions\n")
4345 {
4346 VTY_DECLVAR_CONTEXT(bgp, bgp);
4347 bgp->fast_convergence = false;
4348
4349 return CMD_SUCCESS;
4350 }
4351
4352 static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
4353 int v6only,
4354 const char *peer_group_name,
4355 const char *as_str)
4356 {
4357 VTY_DECLVAR_CONTEXT(bgp, bgp);
4358 as_t as = 0;
4359 int as_type = AS_UNSPECIFIED;
4360 struct peer *peer;
4361 struct peer_group *group;
4362 int ret = 0;
4363
4364 group = peer_group_lookup(bgp, conf_if);
4365
4366 if (group) {
4367 vty_out(vty, "%% Name conflict with peer-group \n");
4368 return CMD_WARNING_CONFIG_FAILED;
4369 }
4370
4371 if (as_str) {
4372 if (as_str[0] == 'i') {
4373 as_type = AS_INTERNAL;
4374 } else if (as_str[0] == 'e') {
4375 as_type = AS_EXTERNAL;
4376 } else {
4377 /* Get AS number. */
4378 as = strtoul(as_str, NULL, 10);
4379 as_type = AS_SPECIFIED;
4380 }
4381 }
4382
4383 peer = peer_lookup_by_conf_if(bgp, conf_if);
4384 if (peer) {
4385 if (as_str)
4386 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type);
4387 } else {
4388 peer = peer_create(NULL, conf_if, bgp, bgp->as, as, as_type,
4389 NULL);
4390
4391 if (!peer) {
4392 vty_out(vty, "%% BGP failed to create peer\n");
4393 return CMD_WARNING_CONFIG_FAILED;
4394 }
4395
4396 if (v6only)
4397 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
4398
4399 /* Request zebra to initiate IPv6 RAs on this interface. We do
4400 * this
4401 * any unnumbered peer in order to not worry about run-time
4402 * transitions
4403 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
4404 * address
4405 * gets deleted later etc.)
4406 */
4407 if (peer->ifp)
4408 bgp_zebra_initiate_radv(bgp, peer);
4409 }
4410
4411 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
4412 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
4413 if (v6only)
4414 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
4415 else
4416 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
4417
4418 /* v6only flag changed. Reset bgp seesion */
4419 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
4420 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
4421 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
4422 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
4423 } else
4424 bgp_session_reset(peer);
4425 }
4426
4427 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
4428 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
4429 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
4430 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
4431 }
4432
4433 if (peer_group_name) {
4434 group = peer_group_lookup(bgp, peer_group_name);
4435 if (!group) {
4436 vty_out(vty, "%% Configure the peer-group first\n");
4437 return CMD_WARNING_CONFIG_FAILED;
4438 }
4439
4440 ret = peer_group_bind(bgp, NULL, peer, group, &as);
4441 }
4442
4443 return bgp_vty_return(vty, ret);
4444 }
4445
4446 DEFUN (neighbor_interface_config,
4447 neighbor_interface_config_cmd,
4448 "neighbor WORD interface [peer-group PGNAME]",
4449 NEIGHBOR_STR
4450 "Interface name or neighbor tag\n"
4451 "Enable BGP on interface\n"
4452 "Member of the peer-group\n"
4453 "Peer-group name\n")
4454 {
4455 int idx_word = 1;
4456 int idx_peer_group_word = 4;
4457
4458 if (argc > idx_peer_group_word)
4459 return peer_conf_interface_get(
4460 vty, argv[idx_word]->arg, 0,
4461 argv[idx_peer_group_word]->arg, NULL);
4462 else
4463 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0,
4464 NULL, NULL);
4465 }
4466
4467 DEFUN (neighbor_interface_config_v6only,
4468 neighbor_interface_config_v6only_cmd,
4469 "neighbor WORD interface v6only [peer-group PGNAME]",
4470 NEIGHBOR_STR
4471 "Interface name or neighbor tag\n"
4472 "Enable BGP on interface\n"
4473 "Enable BGP with v6 link-local only\n"
4474 "Member of the peer-group\n"
4475 "Peer-group name\n")
4476 {
4477 int idx_word = 1;
4478 int idx_peer_group_word = 5;
4479
4480 if (argc > idx_peer_group_word)
4481 return peer_conf_interface_get(
4482 vty, argv[idx_word]->arg, 1,
4483 argv[idx_peer_group_word]->arg, NULL);
4484
4485 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL, NULL);
4486 }
4487
4488
4489 DEFUN (neighbor_interface_config_remote_as,
4490 neighbor_interface_config_remote_as_cmd,
4491 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
4492 NEIGHBOR_STR
4493 "Interface name or neighbor tag\n"
4494 "Enable BGP on interface\n"
4495 "Specify a BGP neighbor\n"
4496 AS_STR
4497 "Internal BGP peer\n"
4498 "External BGP peer\n")
4499 {
4500 int idx_word = 1;
4501 int idx_remote_as = 4;
4502 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0, NULL,
4503 argv[idx_remote_as]->arg);
4504 }
4505
4506 DEFUN (neighbor_interface_v6only_config_remote_as,
4507 neighbor_interface_v6only_config_remote_as_cmd,
4508 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
4509 NEIGHBOR_STR
4510 "Interface name or neighbor tag\n"
4511 "Enable BGP with v6 link-local only\n"
4512 "Enable BGP on interface\n"
4513 "Specify a BGP neighbor\n"
4514 AS_STR
4515 "Internal BGP peer\n"
4516 "External BGP peer\n")
4517 {
4518 int idx_word = 1;
4519 int idx_remote_as = 5;
4520 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL,
4521 argv[idx_remote_as]->arg);
4522 }
4523
4524 DEFUN (neighbor_peer_group,
4525 neighbor_peer_group_cmd,
4526 "neighbor WORD peer-group",
4527 NEIGHBOR_STR
4528 "Interface name or neighbor tag\n"
4529 "Configure peer-group\n")
4530 {
4531 VTY_DECLVAR_CONTEXT(bgp, bgp);
4532 int idx_word = 1;
4533 struct peer *peer;
4534 struct peer_group *group;
4535
4536 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4537 if (peer) {
4538 vty_out(vty, "%% Name conflict with interface: \n");
4539 return CMD_WARNING_CONFIG_FAILED;
4540 }
4541
4542 group = peer_group_get(bgp, argv[idx_word]->arg);
4543 if (!group) {
4544 vty_out(vty, "%% BGP failed to find or create peer-group\n");
4545 return CMD_WARNING_CONFIG_FAILED;
4546 }
4547
4548 return CMD_SUCCESS;
4549 }
4550
4551 DEFUN (no_neighbor,
4552 no_neighbor_cmd,
4553 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
4554 NO_STR
4555 NEIGHBOR_STR
4556 NEIGHBOR_ADDR_STR2
4557 "Specify a BGP neighbor\n"
4558 AS_STR
4559 "Internal BGP peer\n"
4560 "External BGP peer\n")
4561 {
4562 VTY_DECLVAR_CONTEXT(bgp, bgp);
4563 int idx_peer = 2;
4564 int ret;
4565 union sockunion su;
4566 struct peer_group *group;
4567 struct peer *peer;
4568 struct peer *other;
4569
4570 ret = str2sockunion(argv[idx_peer]->arg, &su);
4571 if (ret < 0) {
4572 /* look up for neighbor by interface name config. */
4573 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4574 if (peer) {
4575 /* Request zebra to terminate IPv6 RAs on this
4576 * interface. */
4577 if (peer->ifp)
4578 bgp_zebra_terminate_radv(peer->bgp, peer);
4579 peer_notify_unconfig(peer);
4580 peer_delete(peer);
4581 return CMD_SUCCESS;
4582 }
4583
4584 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
4585 if (group) {
4586 peer_group_notify_unconfig(group);
4587 peer_group_delete(group);
4588 } else {
4589 vty_out(vty, "%% Create the peer-group first\n");
4590 return CMD_WARNING_CONFIG_FAILED;
4591 }
4592 } else {
4593 peer = peer_lookup(bgp, &su);
4594 if (peer) {
4595 if (peer_dynamic_neighbor(peer)) {
4596 vty_out(vty,
4597 "%% Operation not allowed on a dynamic neighbor\n");
4598 return CMD_WARNING_CONFIG_FAILED;
4599 }
4600
4601 other = peer->doppelganger;
4602
4603 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
4604 bgp_zebra_terminate_radv(peer->bgp, peer);
4605
4606 peer_notify_unconfig(peer);
4607 peer_delete(peer);
4608 if (other && other->status != Deleted) {
4609 peer_notify_unconfig(other);
4610 peer_delete(other);
4611 }
4612 }
4613 }
4614
4615 return CMD_SUCCESS;
4616 }
4617
4618 DEFUN (no_neighbor_interface_config,
4619 no_neighbor_interface_config_cmd,
4620 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
4621 NO_STR
4622 NEIGHBOR_STR
4623 "Interface name\n"
4624 "Configure BGP on interface\n"
4625 "Enable BGP with v6 link-local only\n"
4626 "Member of the peer-group\n"
4627 "Peer-group name\n"
4628 "Specify a BGP neighbor\n"
4629 AS_STR
4630 "Internal BGP peer\n"
4631 "External BGP peer\n")
4632 {
4633 VTY_DECLVAR_CONTEXT(bgp, bgp);
4634 int idx_word = 2;
4635 struct peer *peer;
4636
4637 /* look up for neighbor by interface name config. */
4638 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4639 if (peer) {
4640 /* Request zebra to terminate IPv6 RAs on this interface. */
4641 if (peer->ifp)
4642 bgp_zebra_terminate_radv(peer->bgp, peer);
4643 peer_notify_unconfig(peer);
4644 peer_delete(peer);
4645 } else {
4646 vty_out(vty, "%% Create the bgp interface first\n");
4647 return CMD_WARNING_CONFIG_FAILED;
4648 }
4649 return CMD_SUCCESS;
4650 }
4651
4652 DEFUN (no_neighbor_peer_group,
4653 no_neighbor_peer_group_cmd,
4654 "no neighbor WORD peer-group",
4655 NO_STR
4656 NEIGHBOR_STR
4657 "Neighbor tag\n"
4658 "Configure peer-group\n")
4659 {
4660 VTY_DECLVAR_CONTEXT(bgp, bgp);
4661 int idx_word = 2;
4662 struct peer_group *group;
4663
4664 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4665 if (group) {
4666 peer_group_notify_unconfig(group);
4667 peer_group_delete(group);
4668 } else {
4669 vty_out(vty, "%% Create the peer-group first\n");
4670 return CMD_WARNING_CONFIG_FAILED;
4671 }
4672 return CMD_SUCCESS;
4673 }
4674
4675 DEFUN (no_neighbor_interface_peer_group_remote_as,
4676 no_neighbor_interface_peer_group_remote_as_cmd,
4677 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
4678 NO_STR
4679 NEIGHBOR_STR
4680 "Interface name or neighbor tag\n"
4681 "Specify a BGP neighbor\n"
4682 AS_STR
4683 "Internal BGP peer\n"
4684 "External BGP peer\n")
4685 {
4686 VTY_DECLVAR_CONTEXT(bgp, bgp);
4687 int idx_word = 2;
4688 struct peer_group *group;
4689 struct peer *peer;
4690
4691 /* look up for neighbor by interface name config. */
4692 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4693 if (peer) {
4694 peer_as_change(peer, 0, AS_UNSPECIFIED);
4695 return CMD_SUCCESS;
4696 }
4697
4698 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4699 if (group)
4700 peer_group_remote_as_delete(group);
4701 else {
4702 vty_out(vty, "%% Create the peer-group or interface first\n");
4703 return CMD_WARNING_CONFIG_FAILED;
4704 }
4705 return CMD_SUCCESS;
4706 }
4707
4708 DEFUN (neighbor_local_as,
4709 neighbor_local_as_cmd,
4710 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
4711 NEIGHBOR_STR
4712 NEIGHBOR_ADDR_STR2
4713 "Specify a local-as number\n"
4714 "AS number used as local AS\n")
4715 {
4716 int idx_peer = 1;
4717 int idx_number = 3;
4718 struct peer *peer;
4719 int ret;
4720 as_t as;
4721
4722 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4723 if (!peer)
4724 return CMD_WARNING_CONFIG_FAILED;
4725
4726 as = strtoul(argv[idx_number]->arg, NULL, 10);
4727 ret = peer_local_as_set(peer, as, 0, 0);
4728 return bgp_vty_return(vty, ret);
4729 }
4730
4731 DEFUN (neighbor_local_as_no_prepend,
4732 neighbor_local_as_no_prepend_cmd,
4733 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
4734 NEIGHBOR_STR
4735 NEIGHBOR_ADDR_STR2
4736 "Specify a local-as number\n"
4737 "AS number used as local AS\n"
4738 "Do not prepend local-as to updates from ebgp peers\n")
4739 {
4740 int idx_peer = 1;
4741 int idx_number = 3;
4742 struct peer *peer;
4743 int ret;
4744 as_t as;
4745
4746 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4747 if (!peer)
4748 return CMD_WARNING_CONFIG_FAILED;
4749
4750 as = strtoul(argv[idx_number]->arg, NULL, 10);
4751 ret = peer_local_as_set(peer, as, 1, 0);
4752 return bgp_vty_return(vty, ret);
4753 }
4754
4755 DEFUN (neighbor_local_as_no_prepend_replace_as,
4756 neighbor_local_as_no_prepend_replace_as_cmd,
4757 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
4758 NEIGHBOR_STR
4759 NEIGHBOR_ADDR_STR2
4760 "Specify a local-as number\n"
4761 "AS number used as local AS\n"
4762 "Do not prepend local-as to updates from ebgp peers\n"
4763 "Do not prepend local-as to updates from ibgp peers\n")
4764 {
4765 int idx_peer = 1;
4766 int idx_number = 3;
4767 struct peer *peer;
4768 int ret;
4769 as_t as;
4770
4771 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4772 if (!peer)
4773 return CMD_WARNING_CONFIG_FAILED;
4774
4775 as = strtoul(argv[idx_number]->arg, NULL, 10);
4776 ret = peer_local_as_set(peer, as, 1, 1);
4777 return bgp_vty_return(vty, ret);
4778 }
4779
4780 DEFUN (no_neighbor_local_as,
4781 no_neighbor_local_as_cmd,
4782 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
4783 NO_STR
4784 NEIGHBOR_STR
4785 NEIGHBOR_ADDR_STR2
4786 "Specify a local-as number\n"
4787 "AS number used as local AS\n"
4788 "Do not prepend local-as to updates from ebgp peers\n"
4789 "Do not prepend local-as to updates from ibgp peers\n")
4790 {
4791 int idx_peer = 2;
4792 struct peer *peer;
4793 int ret;
4794
4795 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4796 if (!peer)
4797 return CMD_WARNING_CONFIG_FAILED;
4798
4799 ret = peer_local_as_unset(peer);
4800 return bgp_vty_return(vty, ret);
4801 }
4802
4803
4804 DEFUN (neighbor_solo,
4805 neighbor_solo_cmd,
4806 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
4807 NEIGHBOR_STR
4808 NEIGHBOR_ADDR_STR2
4809 "Solo peer - part of its own update group\n")
4810 {
4811 int idx_peer = 1;
4812 struct peer *peer;
4813 int ret;
4814
4815 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4816 if (!peer)
4817 return CMD_WARNING_CONFIG_FAILED;
4818
4819 ret = update_group_adjust_soloness(peer, 1);
4820 return bgp_vty_return(vty, ret);
4821 }
4822
4823 DEFUN (no_neighbor_solo,
4824 no_neighbor_solo_cmd,
4825 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
4826 NO_STR
4827 NEIGHBOR_STR
4828 NEIGHBOR_ADDR_STR2
4829 "Solo peer - part of its own update group\n")
4830 {
4831 int idx_peer = 2;
4832 struct peer *peer;
4833 int ret;
4834
4835 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4836 if (!peer)
4837 return CMD_WARNING_CONFIG_FAILED;
4838
4839 ret = update_group_adjust_soloness(peer, 0);
4840 return bgp_vty_return(vty, ret);
4841 }
4842
4843 DEFUN (neighbor_password,
4844 neighbor_password_cmd,
4845 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
4846 NEIGHBOR_STR
4847 NEIGHBOR_ADDR_STR2
4848 "Set a password\n"
4849 "The password\n")
4850 {
4851 int idx_peer = 1;
4852 int idx_line = 3;
4853 struct peer *peer;
4854 int ret;
4855
4856 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4857 if (!peer)
4858 return CMD_WARNING_CONFIG_FAILED;
4859
4860 ret = peer_password_set(peer, argv[idx_line]->arg);
4861 return bgp_vty_return(vty, ret);
4862 }
4863
4864 DEFUN (no_neighbor_password,
4865 no_neighbor_password_cmd,
4866 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
4867 NO_STR
4868 NEIGHBOR_STR
4869 NEIGHBOR_ADDR_STR2
4870 "Set a password\n"
4871 "The password\n")
4872 {
4873 int idx_peer = 2;
4874 struct peer *peer;
4875 int ret;
4876
4877 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4878 if (!peer)
4879 return CMD_WARNING_CONFIG_FAILED;
4880
4881 ret = peer_password_unset(peer);
4882 return bgp_vty_return(vty, ret);
4883 }
4884
4885 DEFUN (neighbor_activate,
4886 neighbor_activate_cmd,
4887 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4888 NEIGHBOR_STR
4889 NEIGHBOR_ADDR_STR2
4890 "Enable the Address Family for this Neighbor\n")
4891 {
4892 int idx_peer = 1;
4893 int ret;
4894 struct peer *peer;
4895
4896 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4897 if (!peer)
4898 return CMD_WARNING_CONFIG_FAILED;
4899
4900 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
4901 return bgp_vty_return(vty, ret);
4902 }
4903
4904 ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
4905 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4906 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4907 "Enable the Address Family for this Neighbor\n")
4908
4909 DEFUN (no_neighbor_activate,
4910 no_neighbor_activate_cmd,
4911 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4912 NO_STR
4913 NEIGHBOR_STR
4914 NEIGHBOR_ADDR_STR2
4915 "Enable the Address Family for this Neighbor\n")
4916 {
4917 int idx_peer = 2;
4918 int ret;
4919 struct peer *peer;
4920
4921 /* Lookup peer. */
4922 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4923 if (!peer)
4924 return CMD_WARNING_CONFIG_FAILED;
4925
4926 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
4927 return bgp_vty_return(vty, ret);
4928 }
4929
4930 ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
4931 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4932 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4933 "Enable the Address Family for this Neighbor\n")
4934
4935 DEFUN (neighbor_set_peer_group,
4936 neighbor_set_peer_group_cmd,
4937 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
4938 NEIGHBOR_STR
4939 NEIGHBOR_ADDR_STR2
4940 "Member of the peer-group\n"
4941 "Peer-group name\n")
4942 {
4943 VTY_DECLVAR_CONTEXT(bgp, bgp);
4944 int idx_peer = 1;
4945 int idx_word = 3;
4946 int ret;
4947 as_t as;
4948 union sockunion su;
4949 struct peer *peer;
4950 struct peer_group *group;
4951
4952 ret = str2sockunion(argv[idx_peer]->arg, &su);
4953 if (ret < 0) {
4954 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4955 if (!peer) {
4956 vty_out(vty, "%% Malformed address or name: %s\n",
4957 argv[idx_peer]->arg);
4958 return CMD_WARNING_CONFIG_FAILED;
4959 }
4960 } else {
4961 if (peer_address_self_check(bgp, &su)) {
4962 vty_out(vty,
4963 "%% Can not configure the local system as neighbor\n");
4964 return CMD_WARNING_CONFIG_FAILED;
4965 }
4966
4967 /* Disallow for dynamic neighbor. */
4968 peer = peer_lookup(bgp, &su);
4969 if (peer && peer_dynamic_neighbor(peer)) {
4970 vty_out(vty,
4971 "%% Operation not allowed on a dynamic neighbor\n");
4972 return CMD_WARNING_CONFIG_FAILED;
4973 }
4974 }
4975
4976 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4977 if (!group) {
4978 vty_out(vty, "%% Configure the peer-group first\n");
4979 return CMD_WARNING_CONFIG_FAILED;
4980 }
4981
4982 ret = peer_group_bind(bgp, &su, peer, group, &as);
4983
4984 return bgp_vty_return(vty, ret);
4985 }
4986
4987 ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
4988 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
4989 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4990 "Member of the peer-group\n"
4991 "Peer-group name\n")
4992
4993 DEFUN (no_neighbor_set_peer_group,
4994 no_neighbor_set_peer_group_cmd,
4995 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
4996 NO_STR
4997 NEIGHBOR_STR
4998 NEIGHBOR_ADDR_STR2
4999 "Member of the peer-group\n"
5000 "Peer-group name\n")
5001 {
5002 VTY_DECLVAR_CONTEXT(bgp, bgp);
5003 int idx_peer = 2;
5004 int idx_word = 4;
5005 int ret;
5006 struct peer *peer;
5007 struct peer_group *group;
5008
5009 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
5010 if (!peer)
5011 return CMD_WARNING_CONFIG_FAILED;
5012
5013 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5014 if (!group) {
5015 vty_out(vty, "%% Configure the peer-group first\n");
5016 return CMD_WARNING_CONFIG_FAILED;
5017 }
5018
5019 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
5020 bgp_zebra_terminate_radv(peer->bgp, peer);
5021
5022 peer_notify_unconfig(peer);
5023 ret = peer_delete(peer);
5024
5025 return bgp_vty_return(vty, ret);
5026 }
5027
5028 ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
5029 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5030 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5031 "Member of the peer-group\n"
5032 "Peer-group name\n")
5033
5034 static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
5035 uint32_t flag, int set)
5036 {
5037 int ret;
5038 struct peer *peer;
5039
5040 peer = peer_and_group_lookup_vty(vty, ip_str);
5041 if (!peer)
5042 return CMD_WARNING_CONFIG_FAILED;
5043
5044 /*
5045 * If 'neighbor <interface>', then this is for directly connected peers,
5046 * we should not accept disable-connected-check.
5047 */
5048 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
5049 vty_out(vty,
5050 "%s is directly connected peer, cannot accept disable-connected-check\n",
5051 ip_str);
5052 return CMD_WARNING_CONFIG_FAILED;
5053 }
5054
5055 if (!set && flag == PEER_FLAG_SHUTDOWN)
5056 peer_tx_shutdown_message_unset(peer);
5057
5058 if (set)
5059 ret = peer_flag_set(peer, flag);
5060 else
5061 ret = peer_flag_unset(peer, flag);
5062
5063 return bgp_vty_return(vty, ret);
5064 }
5065
5066 static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
5067 {
5068 return peer_flag_modify_vty(vty, ip_str, flag, 1);
5069 }
5070
5071 static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
5072 uint32_t flag)
5073 {
5074 return peer_flag_modify_vty(vty, ip_str, flag, 0);
5075 }
5076
5077 /* neighbor passive. */
5078 DEFUN (neighbor_passive,
5079 neighbor_passive_cmd,
5080 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5081 NEIGHBOR_STR
5082 NEIGHBOR_ADDR_STR2
5083 "Don't send open messages to this neighbor\n")
5084 {
5085 int idx_peer = 1;
5086 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
5087 }
5088
5089 DEFUN (no_neighbor_passive,
5090 no_neighbor_passive_cmd,
5091 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5092 NO_STR
5093 NEIGHBOR_STR
5094 NEIGHBOR_ADDR_STR2
5095 "Don't send open messages to this neighbor\n")
5096 {
5097 int idx_peer = 2;
5098 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
5099 }
5100
5101 /* neighbor shutdown. */
5102 DEFUN (neighbor_shutdown_msg,
5103 neighbor_shutdown_msg_cmd,
5104 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5105 NEIGHBOR_STR
5106 NEIGHBOR_ADDR_STR2
5107 "Administratively shut down this neighbor\n"
5108 "Add a shutdown message (RFC 8203)\n"
5109 "Shutdown message\n")
5110 {
5111 int idx_peer = 1;
5112
5113 if (argc >= 5) {
5114 struct peer *peer =
5115 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5116 char *message;
5117
5118 if (!peer)
5119 return CMD_WARNING_CONFIG_FAILED;
5120 message = argv_concat(argv, argc, 4);
5121 peer_tx_shutdown_message_set(peer, message);
5122 XFREE(MTYPE_TMP, message);
5123 }
5124
5125 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
5126 }
5127
5128 ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
5129 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5130 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5131 "Administratively shut down this neighbor\n")
5132
5133 DEFUN (no_neighbor_shutdown_msg,
5134 no_neighbor_shutdown_msg_cmd,
5135 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5136 NO_STR
5137 NEIGHBOR_STR
5138 NEIGHBOR_ADDR_STR2
5139 "Administratively shut down this neighbor\n"
5140 "Remove a shutdown message (RFC 8203)\n"
5141 "Shutdown message\n")
5142 {
5143 int idx_peer = 2;
5144
5145 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5146 PEER_FLAG_SHUTDOWN);
5147 }
5148
5149 ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
5150 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5151 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5152 "Administratively shut down this neighbor\n")
5153
5154 DEFUN(neighbor_shutdown_rtt,
5155 neighbor_shutdown_rtt_cmd,
5156 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt (1-65535) [count (1-255)]",
5157 NEIGHBOR_STR
5158 NEIGHBOR_ADDR_STR2
5159 "Administratively shut down this neighbor\n"
5160 "Shutdown if round-trip-time is higher than expected\n"
5161 "Round-trip-time in milliseconds\n"
5162 "Specify the number of keepalives before shutdown\n"
5163 "The number of keepalives with higher RTT to shutdown\n")
5164 {
5165 int idx_peer = 1;
5166 int idx_rtt = 4;
5167 int idx_count = 0;
5168 struct peer *peer;
5169
5170 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5171
5172 if (!peer)
5173 return CMD_WARNING_CONFIG_FAILED;
5174
5175 peer->rtt_expected = strtol(argv[idx_rtt]->arg, NULL, 10);
5176
5177 if (argv_find(argv, argc, "count", &idx_count))
5178 peer->rtt_keepalive_conf =
5179 strtol(argv[idx_count + 1]->arg, NULL, 10);
5180
5181 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5182 PEER_FLAG_RTT_SHUTDOWN);
5183 }
5184
5185 DEFUN(no_neighbor_shutdown_rtt,
5186 no_neighbor_shutdown_rtt_cmd,
5187 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt [(1-65535) [count (1-255)]]",
5188 NO_STR
5189 NEIGHBOR_STR
5190 NEIGHBOR_ADDR_STR2
5191 "Administratively shut down this neighbor\n"
5192 "Shutdown if round-trip-time is higher than expected\n"
5193 "Round-trip-time in milliseconds\n"
5194 "Specify the number of keepalives before shutdown\n"
5195 "The number of keepalives with higher RTT to shutdown\n")
5196 {
5197 int idx_peer = 2;
5198 struct peer *peer;
5199
5200 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5201
5202 if (!peer)
5203 return CMD_WARNING_CONFIG_FAILED;
5204
5205 peer->rtt_expected = 0;
5206 peer->rtt_keepalive_conf = 1;
5207
5208 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5209 PEER_FLAG_RTT_SHUTDOWN);
5210 }
5211
5212 /* neighbor capability dynamic. */
5213 DEFUN (neighbor_capability_dynamic,
5214 neighbor_capability_dynamic_cmd,
5215 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5216 NEIGHBOR_STR
5217 NEIGHBOR_ADDR_STR2
5218 "Advertise capability to the peer\n"
5219 "Advertise dynamic capability to this neighbor\n")
5220 {
5221 int idx_peer = 1;
5222 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5223 PEER_FLAG_DYNAMIC_CAPABILITY);
5224 }
5225
5226 DEFUN (no_neighbor_capability_dynamic,
5227 no_neighbor_capability_dynamic_cmd,
5228 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5229 NO_STR
5230 NEIGHBOR_STR
5231 NEIGHBOR_ADDR_STR2
5232 "Advertise capability to the peer\n"
5233 "Advertise dynamic capability to this neighbor\n")
5234 {
5235 int idx_peer = 2;
5236 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5237 PEER_FLAG_DYNAMIC_CAPABILITY);
5238 }
5239
5240 /* neighbor dont-capability-negotiate */
5241 DEFUN (neighbor_dont_capability_negotiate,
5242 neighbor_dont_capability_negotiate_cmd,
5243 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
5244 NEIGHBOR_STR
5245 NEIGHBOR_ADDR_STR2
5246 "Do not perform capability negotiation\n")
5247 {
5248 int idx_peer = 1;
5249 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5250 PEER_FLAG_DONT_CAPABILITY);
5251 }
5252
5253 DEFUN (no_neighbor_dont_capability_negotiate,
5254 no_neighbor_dont_capability_negotiate_cmd,
5255 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
5256 NO_STR
5257 NEIGHBOR_STR
5258 NEIGHBOR_ADDR_STR2
5259 "Do not perform capability negotiation\n")
5260 {
5261 int idx_peer = 2;
5262 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5263 PEER_FLAG_DONT_CAPABILITY);
5264 }
5265
5266 /* neighbor capability extended next hop encoding */
5267 DEFUN (neighbor_capability_enhe,
5268 neighbor_capability_enhe_cmd,
5269 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5270 NEIGHBOR_STR
5271 NEIGHBOR_ADDR_STR2
5272 "Advertise capability to the peer\n"
5273 "Advertise extended next-hop capability to the peer\n")
5274 {
5275 int idx_peer = 1;
5276 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5277 PEER_FLAG_CAPABILITY_ENHE);
5278 }
5279
5280 DEFUN (no_neighbor_capability_enhe,
5281 no_neighbor_capability_enhe_cmd,
5282 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5283 NO_STR
5284 NEIGHBOR_STR
5285 NEIGHBOR_ADDR_STR2
5286 "Advertise capability to the peer\n"
5287 "Advertise extended next-hop capability to the peer\n")
5288 {
5289 int idx_peer = 2;
5290 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5291 PEER_FLAG_CAPABILITY_ENHE);
5292 }
5293
5294 static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
5295 afi_t afi, safi_t safi, uint32_t flag,
5296 int set)
5297 {
5298 int ret;
5299 struct peer *peer;
5300
5301 peer = peer_and_group_lookup_vty(vty, peer_str);
5302 if (!peer)
5303 return CMD_WARNING_CONFIG_FAILED;
5304
5305 if (set)
5306 ret = peer_af_flag_set(peer, afi, safi, flag);
5307 else
5308 ret = peer_af_flag_unset(peer, afi, safi, flag);
5309
5310 return bgp_vty_return(vty, ret);
5311 }
5312
5313 static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
5314 afi_t afi, safi_t safi, uint32_t flag)
5315 {
5316 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
5317 }
5318
5319 static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
5320 afi_t afi, safi_t safi, uint32_t flag)
5321 {
5322 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
5323 }
5324
5325 /* neighbor capability orf prefix-list. */
5326 DEFUN (neighbor_capability_orf_prefix,
5327 neighbor_capability_orf_prefix_cmd,
5328 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5329 NEIGHBOR_STR
5330 NEIGHBOR_ADDR_STR2
5331 "Advertise capability to the peer\n"
5332 "Advertise ORF capability to the peer\n"
5333 "Advertise prefixlist ORF capability to this neighbor\n"
5334 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5335 "Capability to RECEIVE the ORF from this neighbor\n"
5336 "Capability to SEND the ORF to this neighbor\n")
5337 {
5338 int idx_send_recv = 5;
5339 char *peer_str = argv[1]->arg;
5340 struct peer *peer;
5341 afi_t afi = bgp_node_afi(vty);
5342 safi_t safi = bgp_node_safi(vty);
5343
5344 peer = peer_and_group_lookup_vty(vty, peer_str);
5345 if (!peer)
5346 return CMD_WARNING_CONFIG_FAILED;
5347
5348 if (strmatch(argv[idx_send_recv]->text, "send"))
5349 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5350 PEER_FLAG_ORF_PREFIX_SM);
5351
5352 if (strmatch(argv[idx_send_recv]->text, "receive"))
5353 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5354 PEER_FLAG_ORF_PREFIX_RM);
5355
5356 if (strmatch(argv[idx_send_recv]->text, "both"))
5357 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5358 PEER_FLAG_ORF_PREFIX_SM)
5359 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5360 PEER_FLAG_ORF_PREFIX_RM);
5361
5362 return CMD_WARNING_CONFIG_FAILED;
5363 }
5364
5365 ALIAS_HIDDEN(
5366 neighbor_capability_orf_prefix,
5367 neighbor_capability_orf_prefix_hidden_cmd,
5368 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5369 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5370 "Advertise capability to the peer\n"
5371 "Advertise ORF capability to the peer\n"
5372 "Advertise prefixlist ORF capability to this neighbor\n"
5373 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5374 "Capability to RECEIVE the ORF from this neighbor\n"
5375 "Capability to SEND the ORF to this neighbor\n")
5376
5377 DEFUN (no_neighbor_capability_orf_prefix,
5378 no_neighbor_capability_orf_prefix_cmd,
5379 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5380 NO_STR
5381 NEIGHBOR_STR
5382 NEIGHBOR_ADDR_STR2
5383 "Advertise capability to the peer\n"
5384 "Advertise ORF capability to the peer\n"
5385 "Advertise prefixlist ORF capability to this neighbor\n"
5386 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5387 "Capability to RECEIVE the ORF from this neighbor\n"
5388 "Capability to SEND the ORF to this neighbor\n")
5389 {
5390 int idx_send_recv = 6;
5391 char *peer_str = argv[2]->arg;
5392 struct peer *peer;
5393 afi_t afi = bgp_node_afi(vty);
5394 safi_t safi = bgp_node_safi(vty);
5395
5396 peer = peer_and_group_lookup_vty(vty, peer_str);
5397 if (!peer)
5398 return CMD_WARNING_CONFIG_FAILED;
5399
5400 if (strmatch(argv[idx_send_recv]->text, "send"))
5401 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5402 PEER_FLAG_ORF_PREFIX_SM);
5403
5404 if (strmatch(argv[idx_send_recv]->text, "receive"))
5405 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5406 PEER_FLAG_ORF_PREFIX_RM);
5407
5408 if (strmatch(argv[idx_send_recv]->text, "both"))
5409 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5410 PEER_FLAG_ORF_PREFIX_SM)
5411 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5412 PEER_FLAG_ORF_PREFIX_RM);
5413
5414 return CMD_WARNING_CONFIG_FAILED;
5415 }
5416
5417 ALIAS_HIDDEN(
5418 no_neighbor_capability_orf_prefix,
5419 no_neighbor_capability_orf_prefix_hidden_cmd,
5420 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5421 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5422 "Advertise capability to the peer\n"
5423 "Advertise ORF capability to the peer\n"
5424 "Advertise prefixlist ORF capability to this neighbor\n"
5425 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5426 "Capability to RECEIVE the ORF from this neighbor\n"
5427 "Capability to SEND the ORF to this neighbor\n")
5428
5429 /* neighbor next-hop-self. */
5430 DEFUN (neighbor_nexthop_self,
5431 neighbor_nexthop_self_cmd,
5432 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5433 NEIGHBOR_STR
5434 NEIGHBOR_ADDR_STR2
5435 "Disable the next hop calculation for this neighbor\n")
5436 {
5437 int idx_peer = 1;
5438 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5439 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
5440 }
5441
5442 ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
5443 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5444 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5445 "Disable the next hop calculation for this neighbor\n")
5446
5447 /* neighbor next-hop-self. */
5448 DEFUN (neighbor_nexthop_self_force,
5449 neighbor_nexthop_self_force_cmd,
5450 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5451 NEIGHBOR_STR
5452 NEIGHBOR_ADDR_STR2
5453 "Disable the next hop calculation for this neighbor\n"
5454 "Set the next hop to self for reflected routes\n")
5455 {
5456 int idx_peer = 1;
5457 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5458 bgp_node_safi(vty),
5459 PEER_FLAG_FORCE_NEXTHOP_SELF);
5460 }
5461
5462 ALIAS_HIDDEN(neighbor_nexthop_self_force,
5463 neighbor_nexthop_self_force_hidden_cmd,
5464 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5465 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5466 "Disable the next hop calculation for this neighbor\n"
5467 "Set the next hop to self for reflected routes\n")
5468
5469 ALIAS_HIDDEN(neighbor_nexthop_self_force,
5470 neighbor_nexthop_self_all_hidden_cmd,
5471 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5472 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5473 "Disable the next hop calculation for this neighbor\n"
5474 "Set the next hop to self for reflected routes\n")
5475
5476 DEFUN (no_neighbor_nexthop_self,
5477 no_neighbor_nexthop_self_cmd,
5478 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5479 NO_STR
5480 NEIGHBOR_STR
5481 NEIGHBOR_ADDR_STR2
5482 "Disable the next hop calculation for this neighbor\n")
5483 {
5484 int idx_peer = 2;
5485 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5486 bgp_node_afi(vty), bgp_node_safi(vty),
5487 PEER_FLAG_NEXTHOP_SELF);
5488 }
5489
5490 ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
5491 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5492 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5493 "Disable the next hop calculation for this neighbor\n")
5494
5495 DEFUN (no_neighbor_nexthop_self_force,
5496 no_neighbor_nexthop_self_force_cmd,
5497 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5498 NO_STR
5499 NEIGHBOR_STR
5500 NEIGHBOR_ADDR_STR2
5501 "Disable the next hop calculation for this neighbor\n"
5502 "Set the next hop to self for reflected routes\n")
5503 {
5504 int idx_peer = 2;
5505 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5506 bgp_node_afi(vty), bgp_node_safi(vty),
5507 PEER_FLAG_FORCE_NEXTHOP_SELF);
5508 }
5509
5510 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5511 no_neighbor_nexthop_self_force_hidden_cmd,
5512 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5513 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5514 "Disable the next hop calculation for this neighbor\n"
5515 "Set the next hop to self for reflected routes\n")
5516
5517 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5518 no_neighbor_nexthop_self_all_hidden_cmd,
5519 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5520 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5521 "Disable the next hop calculation for this neighbor\n"
5522 "Set the next hop to self for reflected routes\n")
5523
5524 /* neighbor as-override */
5525 DEFUN (neighbor_as_override,
5526 neighbor_as_override_cmd,
5527 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5528 NEIGHBOR_STR
5529 NEIGHBOR_ADDR_STR2
5530 "Override ASNs in outbound updates if aspath equals remote-as\n")
5531 {
5532 int idx_peer = 1;
5533 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5534 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
5535 }
5536
5537 ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
5538 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5539 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5540 "Override ASNs in outbound updates if aspath equals remote-as\n")
5541
5542 DEFUN (no_neighbor_as_override,
5543 no_neighbor_as_override_cmd,
5544 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5545 NO_STR
5546 NEIGHBOR_STR
5547 NEIGHBOR_ADDR_STR2
5548 "Override ASNs in outbound updates if aspath equals remote-as\n")
5549 {
5550 int idx_peer = 2;
5551 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5552 bgp_node_afi(vty), bgp_node_safi(vty),
5553 PEER_FLAG_AS_OVERRIDE);
5554 }
5555
5556 ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
5557 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5558 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5559 "Override ASNs in outbound updates if aspath equals remote-as\n")
5560
5561 /* neighbor remove-private-AS. */
5562 DEFUN (neighbor_remove_private_as,
5563 neighbor_remove_private_as_cmd,
5564 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5565 NEIGHBOR_STR
5566 NEIGHBOR_ADDR_STR2
5567 "Remove private ASNs in outbound updates\n")
5568 {
5569 int idx_peer = 1;
5570 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5571 bgp_node_safi(vty),
5572 PEER_FLAG_REMOVE_PRIVATE_AS);
5573 }
5574
5575 ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
5576 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5577 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5578 "Remove private ASNs in outbound updates\n")
5579
5580 DEFUN (neighbor_remove_private_as_all,
5581 neighbor_remove_private_as_all_cmd,
5582 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5583 NEIGHBOR_STR
5584 NEIGHBOR_ADDR_STR2
5585 "Remove private ASNs in outbound updates\n"
5586 "Apply to all AS numbers\n")
5587 {
5588 int idx_peer = 1;
5589 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5590 bgp_node_safi(vty),
5591 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5592 }
5593
5594 ALIAS_HIDDEN(neighbor_remove_private_as_all,
5595 neighbor_remove_private_as_all_hidden_cmd,
5596 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5597 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5598 "Remove private ASNs in outbound updates\n"
5599 "Apply to all AS numbers")
5600
5601 DEFUN (neighbor_remove_private_as_replace_as,
5602 neighbor_remove_private_as_replace_as_cmd,
5603 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5604 NEIGHBOR_STR
5605 NEIGHBOR_ADDR_STR2
5606 "Remove private ASNs in outbound updates\n"
5607 "Replace private ASNs with our ASN in outbound updates\n")
5608 {
5609 int idx_peer = 1;
5610 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5611 bgp_node_safi(vty),
5612 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5613 }
5614
5615 ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
5616 neighbor_remove_private_as_replace_as_hidden_cmd,
5617 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5618 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5619 "Remove private ASNs in outbound updates\n"
5620 "Replace private ASNs with our ASN in outbound updates\n")
5621
5622 DEFUN (neighbor_remove_private_as_all_replace_as,
5623 neighbor_remove_private_as_all_replace_as_cmd,
5624 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5625 NEIGHBOR_STR
5626 NEIGHBOR_ADDR_STR2
5627 "Remove private ASNs in outbound updates\n"
5628 "Apply to all AS numbers\n"
5629 "Replace private ASNs with our ASN in outbound updates\n")
5630 {
5631 int idx_peer = 1;
5632 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5633 bgp_node_safi(vty),
5634 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5635 }
5636
5637 ALIAS_HIDDEN(
5638 neighbor_remove_private_as_all_replace_as,
5639 neighbor_remove_private_as_all_replace_as_hidden_cmd,
5640 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5641 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5642 "Remove private ASNs in outbound updates\n"
5643 "Apply to all AS numbers\n"
5644 "Replace private ASNs with our ASN in outbound updates\n")
5645
5646 DEFUN (no_neighbor_remove_private_as,
5647 no_neighbor_remove_private_as_cmd,
5648 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5649 NO_STR
5650 NEIGHBOR_STR
5651 NEIGHBOR_ADDR_STR2
5652 "Remove private ASNs in outbound updates\n")
5653 {
5654 int idx_peer = 2;
5655 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5656 bgp_node_afi(vty), bgp_node_safi(vty),
5657 PEER_FLAG_REMOVE_PRIVATE_AS);
5658 }
5659
5660 ALIAS_HIDDEN(no_neighbor_remove_private_as,
5661 no_neighbor_remove_private_as_hidden_cmd,
5662 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5663 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5664 "Remove private ASNs in outbound updates\n")
5665
5666 DEFUN (no_neighbor_remove_private_as_all,
5667 no_neighbor_remove_private_as_all_cmd,
5668 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5669 NO_STR
5670 NEIGHBOR_STR
5671 NEIGHBOR_ADDR_STR2
5672 "Remove private ASNs in outbound updates\n"
5673 "Apply to all AS numbers\n")
5674 {
5675 int idx_peer = 2;
5676 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5677 bgp_node_afi(vty), bgp_node_safi(vty),
5678 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5679 }
5680
5681 ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
5682 no_neighbor_remove_private_as_all_hidden_cmd,
5683 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5684 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5685 "Remove private ASNs in outbound updates\n"
5686 "Apply to all AS numbers\n")
5687
5688 DEFUN (no_neighbor_remove_private_as_replace_as,
5689 no_neighbor_remove_private_as_replace_as_cmd,
5690 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5691 NO_STR
5692 NEIGHBOR_STR
5693 NEIGHBOR_ADDR_STR2
5694 "Remove private ASNs in outbound updates\n"
5695 "Replace private ASNs with our ASN in outbound updates\n")
5696 {
5697 int idx_peer = 2;
5698 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5699 bgp_node_afi(vty), bgp_node_safi(vty),
5700 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5701 }
5702
5703 ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
5704 no_neighbor_remove_private_as_replace_as_hidden_cmd,
5705 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5706 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5707 "Remove private ASNs in outbound updates\n"
5708 "Replace private ASNs with our ASN in outbound updates\n")
5709
5710 DEFUN (no_neighbor_remove_private_as_all_replace_as,
5711 no_neighbor_remove_private_as_all_replace_as_cmd,
5712 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5713 NO_STR
5714 NEIGHBOR_STR
5715 NEIGHBOR_ADDR_STR2
5716 "Remove private ASNs in outbound updates\n"
5717 "Apply to all AS numbers\n"
5718 "Replace private ASNs with our ASN in outbound updates\n")
5719 {
5720 int idx_peer = 2;
5721 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5722 bgp_node_afi(vty), bgp_node_safi(vty),
5723 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5724 }
5725
5726 ALIAS_HIDDEN(
5727 no_neighbor_remove_private_as_all_replace_as,
5728 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
5729 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5730 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5731 "Remove private ASNs in outbound updates\n"
5732 "Apply to all AS numbers\n"
5733 "Replace private ASNs with our ASN in outbound updates\n")
5734
5735
5736 /* neighbor send-community. */
5737 DEFUN (neighbor_send_community,
5738 neighbor_send_community_cmd,
5739 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5740 NEIGHBOR_STR
5741 NEIGHBOR_ADDR_STR2
5742 "Send Community attribute to this neighbor\n")
5743 {
5744 int idx_peer = 1;
5745
5746 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5747 bgp_node_safi(vty),
5748 PEER_FLAG_SEND_COMMUNITY);
5749 }
5750
5751 ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
5752 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5753 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5754 "Send Community attribute to this neighbor\n")
5755
5756 DEFUN (no_neighbor_send_community,
5757 no_neighbor_send_community_cmd,
5758 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5759 NO_STR
5760 NEIGHBOR_STR
5761 NEIGHBOR_ADDR_STR2
5762 "Send Community attribute to this neighbor\n")
5763 {
5764 int idx_peer = 2;
5765
5766 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5767 bgp_node_afi(vty), bgp_node_safi(vty),
5768 PEER_FLAG_SEND_COMMUNITY);
5769 }
5770
5771 ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
5772 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5773 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5774 "Send Community attribute to this neighbor\n")
5775
5776 /* neighbor send-community extended. */
5777 DEFUN (neighbor_send_community_type,
5778 neighbor_send_community_type_cmd,
5779 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5780 NEIGHBOR_STR
5781 NEIGHBOR_ADDR_STR2
5782 "Send Community attribute to this neighbor\n"
5783 "Send Standard and Extended Community attributes\n"
5784 "Send Standard, Large and Extended Community attributes\n"
5785 "Send Extended Community attributes\n"
5786 "Send Standard Community attributes\n"
5787 "Send Large Community attributes\n")
5788 {
5789 const char *type = argv[argc - 1]->text;
5790 char *peer_str = argv[1]->arg;
5791 struct peer *peer;
5792 afi_t afi = bgp_node_afi(vty);
5793 safi_t safi = bgp_node_safi(vty);
5794
5795 peer = peer_and_group_lookup_vty(vty, peer_str);
5796 if (!peer)
5797 return CMD_WARNING_CONFIG_FAILED;
5798
5799 if (strmatch(type, "standard"))
5800 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5801 PEER_FLAG_SEND_COMMUNITY);
5802
5803 if (strmatch(type, "extended"))
5804 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5805 PEER_FLAG_SEND_EXT_COMMUNITY);
5806
5807 if (strmatch(type, "large"))
5808 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5809 PEER_FLAG_SEND_LARGE_COMMUNITY);
5810
5811 if (strmatch(type, "both")) {
5812 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5813 PEER_FLAG_SEND_COMMUNITY)
5814 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5815 PEER_FLAG_SEND_EXT_COMMUNITY);
5816 }
5817 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5818 PEER_FLAG_SEND_COMMUNITY)
5819 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5820 PEER_FLAG_SEND_EXT_COMMUNITY)
5821 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5822 PEER_FLAG_SEND_LARGE_COMMUNITY);
5823 }
5824
5825 ALIAS_HIDDEN(
5826 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
5827 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5828 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5829 "Send Community attribute to this neighbor\n"
5830 "Send Standard and Extended Community attributes\n"
5831 "Send Standard, Large and Extended Community attributes\n"
5832 "Send Extended Community attributes\n"
5833 "Send Standard Community attributes\n"
5834 "Send Large Community attributes\n")
5835
5836 DEFUN (no_neighbor_send_community_type,
5837 no_neighbor_send_community_type_cmd,
5838 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5839 NO_STR
5840 NEIGHBOR_STR
5841 NEIGHBOR_ADDR_STR2
5842 "Send Community attribute to this neighbor\n"
5843 "Send Standard and Extended Community attributes\n"
5844 "Send Standard, Large and Extended Community attributes\n"
5845 "Send Extended Community attributes\n"
5846 "Send Standard Community attributes\n"
5847 "Send Large Community attributes\n")
5848 {
5849 const char *type = argv[argc - 1]->text;
5850 char *peer_str = argv[2]->arg;
5851 struct peer *peer;
5852 afi_t afi = bgp_node_afi(vty);
5853 safi_t safi = bgp_node_safi(vty);
5854
5855 peer = peer_and_group_lookup_vty(vty, peer_str);
5856 if (!peer)
5857 return CMD_WARNING_CONFIG_FAILED;
5858
5859 if (strmatch(type, "standard"))
5860 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5861 PEER_FLAG_SEND_COMMUNITY);
5862
5863 if (strmatch(type, "extended"))
5864 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5865 PEER_FLAG_SEND_EXT_COMMUNITY);
5866
5867 if (strmatch(type, "large"))
5868 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5869 PEER_FLAG_SEND_LARGE_COMMUNITY);
5870
5871 if (strmatch(type, "both")) {
5872
5873 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5874 PEER_FLAG_SEND_COMMUNITY)
5875 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5876 PEER_FLAG_SEND_EXT_COMMUNITY);
5877 }
5878
5879 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5880 PEER_FLAG_SEND_COMMUNITY)
5881 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5882 PEER_FLAG_SEND_EXT_COMMUNITY)
5883 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5884 PEER_FLAG_SEND_LARGE_COMMUNITY);
5885 }
5886
5887 ALIAS_HIDDEN(
5888 no_neighbor_send_community_type,
5889 no_neighbor_send_community_type_hidden_cmd,
5890 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5891 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5892 "Send Community attribute to this neighbor\n"
5893 "Send Standard and Extended Community attributes\n"
5894 "Send Standard, Large and Extended Community attributes\n"
5895 "Send Extended Community attributes\n"
5896 "Send Standard Community attributes\n"
5897 "Send Large Community attributes\n")
5898
5899 /* neighbor soft-reconfig. */
5900 DEFUN (neighbor_soft_reconfiguration,
5901 neighbor_soft_reconfiguration_cmd,
5902 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
5903 NEIGHBOR_STR
5904 NEIGHBOR_ADDR_STR2
5905 "Per neighbor soft reconfiguration\n"
5906 "Allow inbound soft reconfiguration for this neighbor\n")
5907 {
5908 int idx_peer = 1;
5909 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5910 bgp_node_safi(vty),
5911 PEER_FLAG_SOFT_RECONFIG);
5912 }
5913
5914 ALIAS_HIDDEN(neighbor_soft_reconfiguration,
5915 neighbor_soft_reconfiguration_hidden_cmd,
5916 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
5917 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5918 "Per neighbor soft reconfiguration\n"
5919 "Allow inbound soft reconfiguration for this neighbor\n")
5920
5921 DEFUN (no_neighbor_soft_reconfiguration,
5922 no_neighbor_soft_reconfiguration_cmd,
5923 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
5924 NO_STR
5925 NEIGHBOR_STR
5926 NEIGHBOR_ADDR_STR2
5927 "Per neighbor soft reconfiguration\n"
5928 "Allow inbound soft reconfiguration for this neighbor\n")
5929 {
5930 int idx_peer = 2;
5931 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5932 bgp_node_afi(vty), bgp_node_safi(vty),
5933 PEER_FLAG_SOFT_RECONFIG);
5934 }
5935
5936 ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
5937 no_neighbor_soft_reconfiguration_hidden_cmd,
5938 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
5939 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5940 "Per neighbor soft reconfiguration\n"
5941 "Allow inbound soft reconfiguration for this neighbor\n")
5942
5943 DEFUN (neighbor_route_reflector_client,
5944 neighbor_route_reflector_client_cmd,
5945 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
5946 NEIGHBOR_STR
5947 NEIGHBOR_ADDR_STR2
5948 "Configure a neighbor as Route Reflector client\n")
5949 {
5950 int idx_peer = 1;
5951 struct peer *peer;
5952
5953
5954 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5955 if (!peer)
5956 return CMD_WARNING_CONFIG_FAILED;
5957
5958 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5959 bgp_node_safi(vty),
5960 PEER_FLAG_REFLECTOR_CLIENT);
5961 }
5962
5963 ALIAS_HIDDEN(neighbor_route_reflector_client,
5964 neighbor_route_reflector_client_hidden_cmd,
5965 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
5966 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5967 "Configure a neighbor as Route Reflector client\n")
5968
5969 DEFUN (no_neighbor_route_reflector_client,
5970 no_neighbor_route_reflector_client_cmd,
5971 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
5972 NO_STR
5973 NEIGHBOR_STR
5974 NEIGHBOR_ADDR_STR2
5975 "Configure a neighbor as Route Reflector client\n")
5976 {
5977 int idx_peer = 2;
5978 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5979 bgp_node_afi(vty), bgp_node_safi(vty),
5980 PEER_FLAG_REFLECTOR_CLIENT);
5981 }
5982
5983 ALIAS_HIDDEN(no_neighbor_route_reflector_client,
5984 no_neighbor_route_reflector_client_hidden_cmd,
5985 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
5986 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5987 "Configure a neighbor as Route Reflector client\n")
5988
5989 /* neighbor route-server-client. */
5990 DEFUN (neighbor_route_server_client,
5991 neighbor_route_server_client_cmd,
5992 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
5993 NEIGHBOR_STR
5994 NEIGHBOR_ADDR_STR2
5995 "Configure a neighbor as Route Server client\n")
5996 {
5997 int idx_peer = 1;
5998 struct peer *peer;
5999
6000 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6001 if (!peer)
6002 return CMD_WARNING_CONFIG_FAILED;
6003 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6004 bgp_node_safi(vty),
6005 PEER_FLAG_RSERVER_CLIENT);
6006 }
6007
6008 ALIAS_HIDDEN(neighbor_route_server_client,
6009 neighbor_route_server_client_hidden_cmd,
6010 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6011 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6012 "Configure a neighbor as Route Server client\n")
6013
6014 DEFUN (no_neighbor_route_server_client,
6015 no_neighbor_route_server_client_cmd,
6016 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6017 NO_STR
6018 NEIGHBOR_STR
6019 NEIGHBOR_ADDR_STR2
6020 "Configure a neighbor as Route Server client\n")
6021 {
6022 int idx_peer = 2;
6023 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6024 bgp_node_afi(vty), bgp_node_safi(vty),
6025 PEER_FLAG_RSERVER_CLIENT);
6026 }
6027
6028 ALIAS_HIDDEN(no_neighbor_route_server_client,
6029 no_neighbor_route_server_client_hidden_cmd,
6030 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6031 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6032 "Configure a neighbor as Route Server client\n")
6033
6034 DEFUN (neighbor_nexthop_local_unchanged,
6035 neighbor_nexthop_local_unchanged_cmd,
6036 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
6037 NEIGHBOR_STR
6038 NEIGHBOR_ADDR_STR2
6039 "Configure treatment of outgoing link-local nexthop attribute\n"
6040 "Leave link-local nexthop unchanged for this peer\n")
6041 {
6042 int idx_peer = 1;
6043 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6044 bgp_node_safi(vty),
6045 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
6046 }
6047
6048 DEFUN (no_neighbor_nexthop_local_unchanged,
6049 no_neighbor_nexthop_local_unchanged_cmd,
6050 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
6051 NO_STR
6052 NEIGHBOR_STR
6053 NEIGHBOR_ADDR_STR2
6054 "Configure treatment of outgoing link-local-nexthop attribute\n"
6055 "Leave link-local nexthop unchanged for this peer\n")
6056 {
6057 int idx_peer = 2;
6058 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6059 bgp_node_afi(vty), bgp_node_safi(vty),
6060 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
6061 }
6062
6063 DEFUN (neighbor_attr_unchanged,
6064 neighbor_attr_unchanged_cmd,
6065 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6066 NEIGHBOR_STR
6067 NEIGHBOR_ADDR_STR2
6068 "BGP attribute is propagated unchanged to this neighbor\n"
6069 "As-path attribute\n"
6070 "Nexthop attribute\n"
6071 "Med attribute\n")
6072 {
6073 int idx = 0;
6074 char *peer_str = argv[1]->arg;
6075 struct peer *peer;
6076 bool aspath = false;
6077 bool nexthop = false;
6078 bool med = false;
6079 afi_t afi = bgp_node_afi(vty);
6080 safi_t safi = bgp_node_safi(vty);
6081 int ret = 0;
6082
6083 peer = peer_and_group_lookup_vty(vty, peer_str);
6084 if (!peer)
6085 return CMD_WARNING_CONFIG_FAILED;
6086
6087 if (argv_find(argv, argc, "as-path", &idx))
6088 aspath = true;
6089
6090 idx = 0;
6091 if (argv_find(argv, argc, "next-hop", &idx))
6092 nexthop = true;
6093
6094 idx = 0;
6095 if (argv_find(argv, argc, "med", &idx))
6096 med = true;
6097
6098 /* no flags means all of them! */
6099 if (!aspath && !nexthop && !med) {
6100 ret = peer_af_flag_set_vty(vty, peer_str, afi, safi,
6101 PEER_FLAG_AS_PATH_UNCHANGED);
6102 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6103 PEER_FLAG_NEXTHOP_UNCHANGED);
6104 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6105 PEER_FLAG_MED_UNCHANGED);
6106 } else {
6107 if (!aspath) {
6108 if (peer_af_flag_check(peer, afi, safi,
6109 PEER_FLAG_AS_PATH_UNCHANGED)) {
6110 ret |= peer_af_flag_unset_vty(
6111 vty, peer_str, afi, safi,
6112 PEER_FLAG_AS_PATH_UNCHANGED);
6113 }
6114 } else
6115 ret |= peer_af_flag_set_vty(
6116 vty, peer_str, afi, safi,
6117 PEER_FLAG_AS_PATH_UNCHANGED);
6118
6119 if (!nexthop) {
6120 if (peer_af_flag_check(peer, afi, safi,
6121 PEER_FLAG_NEXTHOP_UNCHANGED)) {
6122 ret |= peer_af_flag_unset_vty(
6123 vty, peer_str, afi, safi,
6124 PEER_FLAG_NEXTHOP_UNCHANGED);
6125 }
6126 } else
6127 ret |= peer_af_flag_set_vty(
6128 vty, peer_str, afi, safi,
6129 PEER_FLAG_NEXTHOP_UNCHANGED);
6130
6131 if (!med) {
6132 if (peer_af_flag_check(peer, afi, safi,
6133 PEER_FLAG_MED_UNCHANGED)) {
6134 ret |= peer_af_flag_unset_vty(
6135 vty, peer_str, afi, safi,
6136 PEER_FLAG_MED_UNCHANGED);
6137 }
6138 } else
6139 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6140 PEER_FLAG_MED_UNCHANGED);
6141 }
6142
6143 return ret;
6144 }
6145
6146 ALIAS_HIDDEN(
6147 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
6148 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6149 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6150 "BGP attribute is propagated unchanged to this neighbor\n"
6151 "As-path attribute\n"
6152 "Nexthop attribute\n"
6153 "Med attribute\n")
6154
6155 DEFUN (no_neighbor_attr_unchanged,
6156 no_neighbor_attr_unchanged_cmd,
6157 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6158 NO_STR
6159 NEIGHBOR_STR
6160 NEIGHBOR_ADDR_STR2
6161 "BGP attribute is propagated unchanged to this neighbor\n"
6162 "As-path attribute\n"
6163 "Nexthop attribute\n"
6164 "Med attribute\n")
6165 {
6166 int idx = 0;
6167 char *peer_str = argv[2]->arg;
6168 struct peer *peer;
6169 bool aspath = false;
6170 bool nexthop = false;
6171 bool med = false;
6172 afi_t afi = bgp_node_afi(vty);
6173 safi_t safi = bgp_node_safi(vty);
6174 int ret = 0;
6175
6176 peer = peer_and_group_lookup_vty(vty, peer_str);
6177 if (!peer)
6178 return CMD_WARNING_CONFIG_FAILED;
6179
6180 if (argv_find(argv, argc, "as-path", &idx))
6181 aspath = true;
6182
6183 idx = 0;
6184 if (argv_find(argv, argc, "next-hop", &idx))
6185 nexthop = true;
6186
6187 idx = 0;
6188 if (argv_find(argv, argc, "med", &idx))
6189 med = true;
6190
6191 if (!aspath && !nexthop && !med) // no flags means all of them!
6192 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6193 PEER_FLAG_AS_PATH_UNCHANGED)
6194 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6195 PEER_FLAG_NEXTHOP_UNCHANGED)
6196 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6197 PEER_FLAG_MED_UNCHANGED);
6198
6199 if (aspath)
6200 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6201 PEER_FLAG_AS_PATH_UNCHANGED);
6202
6203 if (nexthop)
6204 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6205 PEER_FLAG_NEXTHOP_UNCHANGED);
6206
6207 if (med)
6208 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6209 PEER_FLAG_MED_UNCHANGED);
6210
6211 return ret;
6212 }
6213
6214 ALIAS_HIDDEN(
6215 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
6216 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6217 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6218 "BGP attribute is propagated unchanged to this neighbor\n"
6219 "As-path attribute\n"
6220 "Nexthop attribute\n"
6221 "Med attribute\n")
6222
6223 /* EBGP multihop configuration. */
6224 static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
6225 const char *ttl_str)
6226 {
6227 struct peer *peer;
6228 unsigned int ttl;
6229
6230 peer = peer_and_group_lookup_vty(vty, ip_str);
6231 if (!peer)
6232 return CMD_WARNING_CONFIG_FAILED;
6233
6234 if (peer->conf_if)
6235 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
6236
6237 if (!ttl_str)
6238 ttl = MAXTTL;
6239 else
6240 ttl = strtoul(ttl_str, NULL, 10);
6241
6242 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
6243 }
6244
6245 static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
6246 {
6247 struct peer *peer;
6248
6249 peer = peer_and_group_lookup_vty(vty, ip_str);
6250 if (!peer)
6251 return CMD_WARNING_CONFIG_FAILED;
6252
6253 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
6254 }
6255
6256 /* neighbor ebgp-multihop. */
6257 DEFUN (neighbor_ebgp_multihop,
6258 neighbor_ebgp_multihop_cmd,
6259 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
6260 NEIGHBOR_STR
6261 NEIGHBOR_ADDR_STR2
6262 "Allow EBGP neighbors not on directly connected networks\n")
6263 {
6264 int idx_peer = 1;
6265 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
6266 }
6267
6268 DEFUN (neighbor_ebgp_multihop_ttl,
6269 neighbor_ebgp_multihop_ttl_cmd,
6270 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
6271 NEIGHBOR_STR
6272 NEIGHBOR_ADDR_STR2
6273 "Allow EBGP neighbors not on directly connected networks\n"
6274 "maximum hop count\n")
6275 {
6276 int idx_peer = 1;
6277 int idx_number = 3;
6278 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
6279 argv[idx_number]->arg);
6280 }
6281
6282 DEFUN (no_neighbor_ebgp_multihop,
6283 no_neighbor_ebgp_multihop_cmd,
6284 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
6285 NO_STR
6286 NEIGHBOR_STR
6287 NEIGHBOR_ADDR_STR2
6288 "Allow EBGP neighbors not on directly connected networks\n"
6289 "maximum hop count\n")
6290 {
6291 int idx_peer = 2;
6292 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
6293 }
6294
6295
6296 /* disable-connected-check */
6297 DEFUN (neighbor_disable_connected_check,
6298 neighbor_disable_connected_check_cmd,
6299 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6300 NEIGHBOR_STR
6301 NEIGHBOR_ADDR_STR2
6302 "one-hop away EBGP peer using loopback address\n"
6303 "Enforce EBGP neighbors perform multihop\n")
6304 {
6305 int idx_peer = 1;
6306 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6307 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6308 }
6309
6310 DEFUN (no_neighbor_disable_connected_check,
6311 no_neighbor_disable_connected_check_cmd,
6312 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6313 NO_STR
6314 NEIGHBOR_STR
6315 NEIGHBOR_ADDR_STR2
6316 "one-hop away EBGP peer using loopback address\n"
6317 "Enforce EBGP neighbors perform multihop\n")
6318 {
6319 int idx_peer = 2;
6320 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6321 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6322 }
6323
6324 /* disable-link-bw-encoding-ieee */
6325 DEFUN(neighbor_disable_link_bw_encoding_ieee,
6326 neighbor_disable_link_bw_encoding_ieee_cmd,
6327 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6328 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6329 "Disable IEEE floating-point encoding for extended community bandwidth\n")
6330 {
6331 int idx_peer = 1;
6332
6333 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6334 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6335 }
6336
6337 DEFUN(no_neighbor_disable_link_bw_encoding_ieee,
6338 no_neighbor_disable_link_bw_encoding_ieee_cmd,
6339 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6340 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6341 "Disable IEEE floating-point encoding for extended community bandwidth\n")
6342 {
6343 int idx_peer = 2;
6344
6345 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6346 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6347 }
6348
6349 /* extended-optional-parameters */
6350 DEFUN(neighbor_extended_optional_parameters,
6351 neighbor_extended_optional_parameters_cmd,
6352 "neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6353 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6354 "Force the extended optional parameters format for OPEN messages\n")
6355 {
6356 int idx_peer = 1;
6357
6358 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6359 PEER_FLAG_EXTENDED_OPT_PARAMS);
6360 }
6361
6362 DEFUN(no_neighbor_extended_optional_parameters,
6363 no_neighbor_extended_optional_parameters_cmd,
6364 "no neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6365 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6366 "Force the extended optional parameters format for OPEN messages\n")
6367 {
6368 int idx_peer = 2;
6369
6370 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6371 PEER_FLAG_EXTENDED_OPT_PARAMS);
6372 }
6373
6374 /* enforce-first-as */
6375 DEFUN (neighbor_enforce_first_as,
6376 neighbor_enforce_first_as_cmd,
6377 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6378 NEIGHBOR_STR
6379 NEIGHBOR_ADDR_STR2
6380 "Enforce the first AS for EBGP routes\n")
6381 {
6382 int idx_peer = 1;
6383
6384 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6385 PEER_FLAG_ENFORCE_FIRST_AS);
6386 }
6387
6388 DEFUN (no_neighbor_enforce_first_as,
6389 no_neighbor_enforce_first_as_cmd,
6390 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6391 NO_STR
6392 NEIGHBOR_STR
6393 NEIGHBOR_ADDR_STR2
6394 "Enforce the first AS for EBGP routes\n")
6395 {
6396 int idx_peer = 2;
6397
6398 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6399 PEER_FLAG_ENFORCE_FIRST_AS);
6400 }
6401
6402
6403 DEFUN (neighbor_description,
6404 neighbor_description_cmd,
6405 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6406 NEIGHBOR_STR
6407 NEIGHBOR_ADDR_STR2
6408 "Neighbor specific description\n"
6409 "Up to 80 characters describing this neighbor\n")
6410 {
6411 int idx_peer = 1;
6412 int idx_line = 3;
6413 struct peer *peer;
6414 char *str;
6415
6416 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6417 if (!peer)
6418 return CMD_WARNING_CONFIG_FAILED;
6419
6420 str = argv_concat(argv, argc, idx_line);
6421
6422 peer_description_set(peer, str);
6423
6424 XFREE(MTYPE_TMP, str);
6425
6426 return CMD_SUCCESS;
6427 }
6428
6429 DEFUN (no_neighbor_description,
6430 no_neighbor_description_cmd,
6431 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
6432 NO_STR
6433 NEIGHBOR_STR
6434 NEIGHBOR_ADDR_STR2
6435 "Neighbor specific description\n")
6436 {
6437 int idx_peer = 2;
6438 struct peer *peer;
6439
6440 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6441 if (!peer)
6442 return CMD_WARNING_CONFIG_FAILED;
6443
6444 peer_description_unset(peer);
6445
6446 return CMD_SUCCESS;
6447 }
6448
6449 ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
6450 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6451 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6452 "Neighbor specific description\n"
6453 "Up to 80 characters describing this neighbor\n")
6454
6455 /* Neighbor update-source. */
6456 static int peer_update_source_vty(struct vty *vty, const char *peer_str,
6457 const char *source_str)
6458 {
6459 struct peer *peer;
6460 struct prefix p;
6461 union sockunion su;
6462
6463 peer = peer_and_group_lookup_vty(vty, peer_str);
6464 if (!peer)
6465 return CMD_WARNING_CONFIG_FAILED;
6466
6467 if (peer->conf_if)
6468 return CMD_WARNING;
6469
6470 if (source_str) {
6471 if (str2sockunion(source_str, &su) == 0)
6472 peer_update_source_addr_set(peer, &su);
6473 else {
6474 if (str2prefix(source_str, &p)) {
6475 vty_out(vty,
6476 "%% Invalid update-source, remove prefix length \n");
6477 return CMD_WARNING_CONFIG_FAILED;
6478 } else
6479 peer_update_source_if_set(peer, source_str);
6480 }
6481 } else
6482 peer_update_source_unset(peer);
6483
6484 return CMD_SUCCESS;
6485 }
6486
6487 #define BGP_UPDATE_SOURCE_HELP_STR \
6488 "IPv4 address\n" \
6489 "IPv6 address\n" \
6490 "Interface name (requires zebra to be running)\n"
6491
6492 DEFUN (neighbor_update_source,
6493 neighbor_update_source_cmd,
6494 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
6495 NEIGHBOR_STR
6496 NEIGHBOR_ADDR_STR2
6497 "Source of routing updates\n"
6498 BGP_UPDATE_SOURCE_HELP_STR)
6499 {
6500 int idx_peer = 1;
6501 int idx_peer_2 = 3;
6502 return peer_update_source_vty(vty, argv[idx_peer]->arg,
6503 argv[idx_peer_2]->arg);
6504 }
6505
6506 DEFUN (no_neighbor_update_source,
6507 no_neighbor_update_source_cmd,
6508 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
6509 NO_STR
6510 NEIGHBOR_STR
6511 NEIGHBOR_ADDR_STR2
6512 "Source of routing updates\n"
6513 BGP_UPDATE_SOURCE_HELP_STR)
6514 {
6515 int idx_peer = 2;
6516 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
6517 }
6518
6519 static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
6520 afi_t afi, safi_t safi,
6521 const char *rmap, int set)
6522 {
6523 int ret;
6524 struct peer *peer;
6525 struct route_map *route_map = NULL;
6526
6527 peer = peer_and_group_lookup_vty(vty, peer_str);
6528 if (!peer)
6529 return CMD_WARNING_CONFIG_FAILED;
6530
6531 if (set) {
6532 if (rmap)
6533 route_map = route_map_lookup_warn_noexist(vty, rmap);
6534 ret = peer_default_originate_set(peer, afi, safi,
6535 rmap, route_map);
6536 } else
6537 ret = peer_default_originate_unset(peer, afi, safi);
6538
6539 return bgp_vty_return(vty, ret);
6540 }
6541
6542 /* neighbor default-originate. */
6543 DEFUN (neighbor_default_originate,
6544 neighbor_default_originate_cmd,
6545 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
6546 NEIGHBOR_STR
6547 NEIGHBOR_ADDR_STR2
6548 "Originate default route to this neighbor\n")
6549 {
6550 int idx_peer = 1;
6551 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6552 bgp_node_afi(vty),
6553 bgp_node_safi(vty), NULL, 1);
6554 }
6555
6556 ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
6557 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
6558 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6559 "Originate default route to this neighbor\n")
6560
6561 DEFUN (neighbor_default_originate_rmap,
6562 neighbor_default_originate_rmap_cmd,
6563 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
6564 NEIGHBOR_STR
6565 NEIGHBOR_ADDR_STR2
6566 "Originate default route to this neighbor\n"
6567 "Route-map to specify criteria to originate default\n"
6568 "route-map name\n")
6569 {
6570 int idx_peer = 1;
6571 int idx_word = 4;
6572 return peer_default_originate_set_vty(
6573 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6574 argv[idx_word]->arg, 1);
6575 }
6576
6577 ALIAS_HIDDEN(
6578 neighbor_default_originate_rmap,
6579 neighbor_default_originate_rmap_hidden_cmd,
6580 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
6581 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6582 "Originate default route to this neighbor\n"
6583 "Route-map to specify criteria to originate default\n"
6584 "route-map name\n")
6585
6586 DEFUN (no_neighbor_default_originate,
6587 no_neighbor_default_originate_cmd,
6588 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
6589 NO_STR
6590 NEIGHBOR_STR
6591 NEIGHBOR_ADDR_STR2
6592 "Originate default route to this neighbor\n"
6593 "Route-map to specify criteria to originate default\n"
6594 "route-map name\n")
6595 {
6596 int idx_peer = 2;
6597 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6598 bgp_node_afi(vty),
6599 bgp_node_safi(vty), NULL, 0);
6600 }
6601
6602 ALIAS_HIDDEN(
6603 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
6604 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
6605 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6606 "Originate default route to this neighbor\n"
6607 "Route-map to specify criteria to originate default\n"
6608 "route-map name\n")
6609
6610
6611 /* Set neighbor's BGP port. */
6612 static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
6613 const char *port_str)
6614 {
6615 struct peer *peer;
6616 uint16_t port;
6617 struct servent *sp;
6618
6619 peer = peer_lookup_vty(vty, ip_str);
6620 if (!peer)
6621 return CMD_WARNING_CONFIG_FAILED;
6622
6623 if (!port_str) {
6624 sp = getservbyname("bgp", "tcp");
6625 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
6626 } else {
6627 port = strtoul(port_str, NULL, 10);
6628 }
6629
6630 peer_port_set(peer, port);
6631
6632 return CMD_SUCCESS;
6633 }
6634
6635 /* Set specified peer's BGP port. */
6636 DEFUN (neighbor_port,
6637 neighbor_port_cmd,
6638 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
6639 NEIGHBOR_STR
6640 NEIGHBOR_ADDR_STR
6641 "Neighbor's BGP port\n"
6642 "TCP port number\n")
6643 {
6644 int idx_ip = 1;
6645 int idx_number = 3;
6646 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
6647 argv[idx_number]->arg);
6648 }
6649
6650 DEFUN (no_neighbor_port,
6651 no_neighbor_port_cmd,
6652 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
6653 NO_STR
6654 NEIGHBOR_STR
6655 NEIGHBOR_ADDR_STR
6656 "Neighbor's BGP port\n"
6657 "TCP port number\n")
6658 {
6659 int idx_ip = 2;
6660 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
6661 }
6662
6663
6664 /* neighbor weight. */
6665 static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
6666 safi_t safi, const char *weight_str)
6667 {
6668 int ret;
6669 struct peer *peer;
6670 unsigned long weight;
6671
6672 peer = peer_and_group_lookup_vty(vty, ip_str);
6673 if (!peer)
6674 return CMD_WARNING_CONFIG_FAILED;
6675
6676 weight = strtoul(weight_str, NULL, 10);
6677
6678 ret = peer_weight_set(peer, afi, safi, weight);
6679 return bgp_vty_return(vty, ret);
6680 }
6681
6682 static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
6683 safi_t safi)
6684 {
6685 int ret;
6686 struct peer *peer;
6687
6688 peer = peer_and_group_lookup_vty(vty, ip_str);
6689 if (!peer)
6690 return CMD_WARNING_CONFIG_FAILED;
6691
6692 ret = peer_weight_unset(peer, afi, safi);
6693 return bgp_vty_return(vty, ret);
6694 }
6695
6696 DEFUN (neighbor_weight,
6697 neighbor_weight_cmd,
6698 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
6699 NEIGHBOR_STR
6700 NEIGHBOR_ADDR_STR2
6701 "Set default weight for routes from this neighbor\n"
6702 "default weight\n")
6703 {
6704 int idx_peer = 1;
6705 int idx_number = 3;
6706 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6707 bgp_node_safi(vty), argv[idx_number]->arg);
6708 }
6709
6710 ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
6711 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
6712 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6713 "Set default weight for routes from this neighbor\n"
6714 "default weight\n")
6715
6716 DEFUN (no_neighbor_weight,
6717 no_neighbor_weight_cmd,
6718 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
6719 NO_STR
6720 NEIGHBOR_STR
6721 NEIGHBOR_ADDR_STR2
6722 "Set default weight for routes from this neighbor\n"
6723 "default weight\n")
6724 {
6725 int idx_peer = 2;
6726 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
6727 bgp_node_afi(vty), bgp_node_safi(vty));
6728 }
6729
6730 ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
6731 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
6732 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6733 "Set default weight for routes from this neighbor\n"
6734 "default weight\n")
6735
6736
6737 /* Override capability negotiation. */
6738 DEFUN (neighbor_override_capability,
6739 neighbor_override_capability_cmd,
6740 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
6741 NEIGHBOR_STR
6742 NEIGHBOR_ADDR_STR2
6743 "Override capability negotiation result\n")
6744 {
6745 int idx_peer = 1;
6746 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6747 PEER_FLAG_OVERRIDE_CAPABILITY);
6748 }
6749
6750 DEFUN (no_neighbor_override_capability,
6751 no_neighbor_override_capability_cmd,
6752 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
6753 NO_STR
6754 NEIGHBOR_STR
6755 NEIGHBOR_ADDR_STR2
6756 "Override capability negotiation result\n")
6757 {
6758 int idx_peer = 2;
6759 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6760 PEER_FLAG_OVERRIDE_CAPABILITY);
6761 }
6762
6763 DEFUN (neighbor_strict_capability,
6764 neighbor_strict_capability_cmd,
6765 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
6766 NEIGHBOR_STR
6767 NEIGHBOR_ADDR_STR2
6768 "Strict capability negotiation match\n")
6769 {
6770 int idx_peer = 1;
6771
6772 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6773 PEER_FLAG_STRICT_CAP_MATCH);
6774 }
6775
6776 DEFUN (no_neighbor_strict_capability,
6777 no_neighbor_strict_capability_cmd,
6778 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
6779 NO_STR
6780 NEIGHBOR_STR
6781 NEIGHBOR_ADDR_STR2
6782 "Strict capability negotiation match\n")
6783 {
6784 int idx_peer = 2;
6785
6786 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6787 PEER_FLAG_STRICT_CAP_MATCH);
6788 }
6789
6790 static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
6791 const char *keep_str, const char *hold_str)
6792 {
6793 int ret;
6794 struct peer *peer;
6795 uint32_t keepalive;
6796 uint32_t holdtime;
6797
6798 peer = peer_and_group_lookup_vty(vty, ip_str);
6799 if (!peer)
6800 return CMD_WARNING_CONFIG_FAILED;
6801
6802 keepalive = strtoul(keep_str, NULL, 10);
6803 holdtime = strtoul(hold_str, NULL, 10);
6804
6805 ret = peer_timers_set(peer, keepalive, holdtime);
6806
6807 return bgp_vty_return(vty, ret);
6808 }
6809
6810 static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
6811 {
6812 int ret;
6813 struct peer *peer;
6814
6815 peer = peer_and_group_lookup_vty(vty, ip_str);
6816 if (!peer)
6817 return CMD_WARNING_CONFIG_FAILED;
6818
6819 ret = peer_timers_unset(peer);
6820
6821 return bgp_vty_return(vty, ret);
6822 }
6823
6824 DEFUN (neighbor_timers,
6825 neighbor_timers_cmd,
6826 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
6827 NEIGHBOR_STR
6828 NEIGHBOR_ADDR_STR2
6829 "BGP per neighbor timers\n"
6830 "Keepalive interval\n"
6831 "Holdtime\n")
6832 {
6833 int idx_peer = 1;
6834 int idx_number = 3;
6835 int idx_number_2 = 4;
6836 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
6837 argv[idx_number]->arg,
6838 argv[idx_number_2]->arg);
6839 }
6840
6841 DEFUN (no_neighbor_timers,
6842 no_neighbor_timers_cmd,
6843 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
6844 NO_STR
6845 NEIGHBOR_STR
6846 NEIGHBOR_ADDR_STR2
6847 "BGP per neighbor timers\n"
6848 "Keepalive interval\n"
6849 "Holdtime\n")
6850 {
6851 int idx_peer = 2;
6852 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
6853 }
6854
6855
6856 static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
6857 const char *time_str)
6858 {
6859 int ret;
6860 struct peer *peer;
6861 uint32_t connect;
6862
6863 peer = peer_and_group_lookup_vty(vty, ip_str);
6864 if (!peer)
6865 return CMD_WARNING_CONFIG_FAILED;
6866
6867 connect = strtoul(time_str, NULL, 10);
6868
6869 ret = peer_timers_connect_set(peer, connect);
6870
6871 return bgp_vty_return(vty, ret);
6872 }
6873
6874 static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
6875 {
6876 int ret;
6877 struct peer *peer;
6878
6879 peer = peer_and_group_lookup_vty(vty, ip_str);
6880 if (!peer)
6881 return CMD_WARNING_CONFIG_FAILED;
6882
6883 ret = peer_timers_connect_unset(peer);
6884
6885 return bgp_vty_return(vty, ret);
6886 }
6887
6888 DEFUN (neighbor_timers_connect,
6889 neighbor_timers_connect_cmd,
6890 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
6891 NEIGHBOR_STR
6892 NEIGHBOR_ADDR_STR2
6893 "BGP per neighbor timers\n"
6894 "BGP connect timer\n"
6895 "Connect timer\n")
6896 {
6897 int idx_peer = 1;
6898 int idx_number = 4;
6899 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
6900 argv[idx_number]->arg);
6901 }
6902
6903 DEFUN (no_neighbor_timers_connect,
6904 no_neighbor_timers_connect_cmd,
6905 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
6906 NO_STR
6907 NEIGHBOR_STR
6908 NEIGHBOR_ADDR_STR2
6909 "BGP per neighbor timers\n"
6910 "BGP connect timer\n"
6911 "Connect timer\n")
6912 {
6913 int idx_peer = 2;
6914 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
6915 }
6916
6917 DEFPY (neighbor_timers_delayopen,
6918 neighbor_timers_delayopen_cmd,
6919 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen (1-240)$interval",
6920 NEIGHBOR_STR
6921 NEIGHBOR_ADDR_STR2
6922 "BGP per neighbor timers\n"
6923 "RFC 4271 DelayOpenTimer\n"
6924 "DelayOpenTime timer interval\n")
6925 {
6926 struct peer *peer;
6927
6928 peer = peer_and_group_lookup_vty(vty, neighbor);
6929 if (!peer)
6930 return CMD_WARNING_CONFIG_FAILED;
6931
6932 if (!interval) {
6933 if (peer_timers_delayopen_unset(peer))
6934 return CMD_WARNING_CONFIG_FAILED;
6935 } else {
6936 if (peer_timers_delayopen_set(peer, interval))
6937 return CMD_WARNING_CONFIG_FAILED;
6938 }
6939
6940 return CMD_SUCCESS;
6941 }
6942
6943 DEFPY (no_neighbor_timers_delayopen,
6944 no_neighbor_timers_delayopen_cmd,
6945 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen [(0-65535)]",
6946 NO_STR
6947 NEIGHBOR_STR
6948 NEIGHBOR_ADDR_STR2
6949 "BGP per neighbor timers\n"
6950 "RFC 4271 DelayOpenTimer\n"
6951 "DelayOpenTime timer interval\n")
6952 {
6953 struct peer *peer;
6954
6955 peer = peer_and_group_lookup_vty(vty, neighbor);
6956 if (!peer)
6957 return CMD_WARNING_CONFIG_FAILED;
6958
6959 if (peer_timers_delayopen_unset(peer))
6960 return CMD_WARNING_CONFIG_FAILED;
6961
6962 return CMD_SUCCESS;
6963 }
6964
6965 static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
6966 const char *time_str, int set)
6967 {
6968 int ret;
6969 struct peer *peer;
6970 uint32_t routeadv = 0;
6971
6972 peer = peer_and_group_lookup_vty(vty, ip_str);
6973 if (!peer)
6974 return CMD_WARNING_CONFIG_FAILED;
6975
6976 if (time_str)
6977 routeadv = strtoul(time_str, NULL, 10);
6978
6979 if (set)
6980 ret = peer_advertise_interval_set(peer, routeadv);
6981 else
6982 ret = peer_advertise_interval_unset(peer);
6983
6984 return bgp_vty_return(vty, ret);
6985 }
6986
6987 DEFUN (neighbor_advertise_interval,
6988 neighbor_advertise_interval_cmd,
6989 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
6990 NEIGHBOR_STR
6991 NEIGHBOR_ADDR_STR2
6992 "Minimum interval between sending BGP routing updates\n"
6993 "time in seconds\n")
6994 {
6995 int idx_peer = 1;
6996 int idx_number = 3;
6997 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
6998 argv[idx_number]->arg, 1);
6999 }
7000
7001 DEFUN (no_neighbor_advertise_interval,
7002 no_neighbor_advertise_interval_cmd,
7003 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
7004 NO_STR
7005 NEIGHBOR_STR
7006 NEIGHBOR_ADDR_STR2
7007 "Minimum interval between sending BGP routing updates\n"
7008 "time in seconds\n")
7009 {
7010 int idx_peer = 2;
7011 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
7012 }
7013
7014
7015 /* Time to wait before processing route-map updates */
7016 DEFUN (bgp_set_route_map_delay_timer,
7017 bgp_set_route_map_delay_timer_cmd,
7018 "bgp route-map delay-timer (0-600)",
7019 SET_STR
7020 "BGP route-map delay timer\n"
7021 "Time in secs to wait before processing route-map changes\n"
7022 "0 disables the timer, no route updates happen when route-maps change\n")
7023 {
7024 int idx_number = 3;
7025 uint32_t rmap_delay_timer;
7026
7027 if (argv[idx_number]->arg) {
7028 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
7029 bm->rmap_update_timer = rmap_delay_timer;
7030
7031 /* if the dynamic update handling is being disabled, and a timer
7032 * is
7033 * running, stop the timer and act as if the timer has already
7034 * fired.
7035 */
7036 if (!rmap_delay_timer && bm->t_rmap_update) {
7037 BGP_TIMER_OFF(bm->t_rmap_update);
7038 thread_execute(bm->master, bgp_route_map_update_timer,
7039 NULL, 0);
7040 }
7041 return CMD_SUCCESS;
7042 } else {
7043 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
7044 return CMD_WARNING_CONFIG_FAILED;
7045 }
7046 }
7047
7048 DEFUN (no_bgp_set_route_map_delay_timer,
7049 no_bgp_set_route_map_delay_timer_cmd,
7050 "no bgp route-map delay-timer [(0-600)]",
7051 NO_STR
7052 BGP_STR
7053 "Default BGP route-map delay timer\n"
7054 "Reset to default time to wait for processing route-map changes\n"
7055 "0 disables the timer, no route updates happen when route-maps change\n")
7056 {
7057
7058 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
7059
7060 return CMD_SUCCESS;
7061 }
7062
7063 /* neighbor interface */
7064 static int peer_interface_vty(struct vty *vty, const char *ip_str,
7065 const char *str)
7066 {
7067 struct peer *peer;
7068
7069 peer = peer_lookup_vty(vty, ip_str);
7070 if (!peer || peer->conf_if) {
7071 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
7072 return CMD_WARNING_CONFIG_FAILED;
7073 }
7074
7075 if (str)
7076 peer_interface_set(peer, str);
7077 else
7078 peer_interface_unset(peer);
7079
7080 return CMD_SUCCESS;
7081 }
7082
7083 DEFUN (neighbor_interface,
7084 neighbor_interface_cmd,
7085 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
7086 NEIGHBOR_STR
7087 NEIGHBOR_ADDR_STR
7088 "Interface\n"
7089 "Interface name\n")
7090 {
7091 int idx_ip = 1;
7092 int idx_word = 3;
7093
7094 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
7095 }
7096
7097 DEFUN (no_neighbor_interface,
7098 no_neighbor_interface_cmd,
7099 "no neighbor <A.B.C.D|X:X::X:X> interface WORD",
7100 NO_STR
7101 NEIGHBOR_STR
7102 NEIGHBOR_ADDR_STR
7103 "Interface\n"
7104 "Interface name\n")
7105 {
7106 int idx_peer = 2;
7107
7108 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
7109 }
7110
7111 DEFUN (neighbor_distribute_list,
7112 neighbor_distribute_list_cmd,
7113 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7114 NEIGHBOR_STR
7115 NEIGHBOR_ADDR_STR2
7116 "Filter updates to/from this neighbor\n"
7117 "IP Access-list name\n"
7118 "Filter incoming updates\n"
7119 "Filter outgoing updates\n")
7120 {
7121 int idx_peer = 1;
7122 int idx_acl = 3;
7123 int direct, ret;
7124 struct peer *peer;
7125
7126 const char *pstr = argv[idx_peer]->arg;
7127 const char *acl = argv[idx_acl]->arg;
7128 const char *inout = argv[argc - 1]->text;
7129
7130 peer = peer_and_group_lookup_vty(vty, pstr);
7131 if (!peer)
7132 return CMD_WARNING_CONFIG_FAILED;
7133
7134 /* Check filter direction. */
7135 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7136 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7137 direct, acl);
7138
7139 return bgp_vty_return(vty, ret);
7140 }
7141
7142 ALIAS_HIDDEN(
7143 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
7144 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7145 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7146 "Filter updates to/from this neighbor\n"
7147 "IP Access-list name\n"
7148 "Filter incoming updates\n"
7149 "Filter outgoing updates\n")
7150
7151 DEFUN (no_neighbor_distribute_list,
7152 no_neighbor_distribute_list_cmd,
7153 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7154 NO_STR
7155 NEIGHBOR_STR
7156 NEIGHBOR_ADDR_STR2
7157 "Filter updates to/from this neighbor\n"
7158 "IP Access-list name\n"
7159 "Filter incoming updates\n"
7160 "Filter outgoing updates\n")
7161 {
7162 int idx_peer = 2;
7163 int direct, ret;
7164 struct peer *peer;
7165
7166 const char *pstr = argv[idx_peer]->arg;
7167 const char *inout = argv[argc - 1]->text;
7168
7169 peer = peer_and_group_lookup_vty(vty, pstr);
7170 if (!peer)
7171 return CMD_WARNING_CONFIG_FAILED;
7172
7173 /* Check filter direction. */
7174 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7175 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7176 direct);
7177
7178 return bgp_vty_return(vty, ret);
7179 }
7180
7181 ALIAS_HIDDEN(
7182 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
7183 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7184 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7185 "Filter updates to/from this neighbor\n"
7186 "IP Access-list name\n"
7187 "Filter incoming updates\n"
7188 "Filter outgoing updates\n")
7189
7190 /* Set prefix list to the peer. */
7191 static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
7192 afi_t afi, safi_t safi,
7193 const char *name_str,
7194 const char *direct_str)
7195 {
7196 int ret;
7197 int direct = FILTER_IN;
7198 struct peer *peer;
7199
7200 peer = peer_and_group_lookup_vty(vty, ip_str);
7201 if (!peer)
7202 return CMD_WARNING_CONFIG_FAILED;
7203
7204 /* Check filter direction. */
7205 if (strncmp(direct_str, "i", 1) == 0)
7206 direct = FILTER_IN;
7207 else if (strncmp(direct_str, "o", 1) == 0)
7208 direct = FILTER_OUT;
7209
7210 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
7211
7212 return bgp_vty_return(vty, ret);
7213 }
7214
7215 static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
7216 afi_t afi, safi_t safi,
7217 const char *direct_str)
7218 {
7219 int ret;
7220 struct peer *peer;
7221 int direct = FILTER_IN;
7222
7223 peer = peer_and_group_lookup_vty(vty, ip_str);
7224 if (!peer)
7225 return CMD_WARNING_CONFIG_FAILED;
7226
7227 /* Check filter direction. */
7228 if (strncmp(direct_str, "i", 1) == 0)
7229 direct = FILTER_IN;
7230 else if (strncmp(direct_str, "o", 1) == 0)
7231 direct = FILTER_OUT;
7232
7233 ret = peer_prefix_list_unset(peer, afi, safi, direct);
7234
7235 return bgp_vty_return(vty, ret);
7236 }
7237
7238 DEFUN (neighbor_prefix_list,
7239 neighbor_prefix_list_cmd,
7240 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7241 NEIGHBOR_STR
7242 NEIGHBOR_ADDR_STR2
7243 "Filter updates to/from this neighbor\n"
7244 "Name of a prefix list\n"
7245 "Filter incoming updates\n"
7246 "Filter outgoing updates\n")
7247 {
7248 int idx_peer = 1;
7249 int idx_word = 3;
7250 int idx_in_out = 4;
7251 return peer_prefix_list_set_vty(
7252 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7253 argv[idx_word]->arg, argv[idx_in_out]->arg);
7254 }
7255
7256 ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
7257 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7258 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7259 "Filter updates to/from this neighbor\n"
7260 "Name of a prefix list\n"
7261 "Filter incoming updates\n"
7262 "Filter outgoing updates\n")
7263
7264 DEFUN (no_neighbor_prefix_list,
7265 no_neighbor_prefix_list_cmd,
7266 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7267 NO_STR
7268 NEIGHBOR_STR
7269 NEIGHBOR_ADDR_STR2
7270 "Filter updates to/from this neighbor\n"
7271 "Name of a prefix list\n"
7272 "Filter incoming updates\n"
7273 "Filter outgoing updates\n")
7274 {
7275 int idx_peer = 2;
7276 int idx_in_out = 5;
7277 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
7278 bgp_node_afi(vty), bgp_node_safi(vty),
7279 argv[idx_in_out]->arg);
7280 }
7281
7282 ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
7283 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7284 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7285 "Filter updates to/from this neighbor\n"
7286 "Name of a prefix list\n"
7287 "Filter incoming updates\n"
7288 "Filter outgoing updates\n")
7289
7290 static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7291 safi_t safi, const char *name_str,
7292 const char *direct_str)
7293 {
7294 int ret;
7295 struct peer *peer;
7296 int direct = FILTER_IN;
7297
7298 peer = peer_and_group_lookup_vty(vty, ip_str);
7299 if (!peer)
7300 return CMD_WARNING_CONFIG_FAILED;
7301
7302 /* Check filter direction. */
7303 if (strncmp(direct_str, "i", 1) == 0)
7304 direct = FILTER_IN;
7305 else if (strncmp(direct_str, "o", 1) == 0)
7306 direct = FILTER_OUT;
7307
7308 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
7309
7310 return bgp_vty_return(vty, ret);
7311 }
7312
7313 static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7314 safi_t safi, const char *direct_str)
7315 {
7316 int ret;
7317 struct peer *peer;
7318 int direct = FILTER_IN;
7319
7320 peer = peer_and_group_lookup_vty(vty, ip_str);
7321 if (!peer)
7322 return CMD_WARNING_CONFIG_FAILED;
7323
7324 /* Check filter direction. */
7325 if (strncmp(direct_str, "i", 1) == 0)
7326 direct = FILTER_IN;
7327 else if (strncmp(direct_str, "o", 1) == 0)
7328 direct = FILTER_OUT;
7329
7330 ret = peer_aslist_unset(peer, afi, safi, direct);
7331
7332 return bgp_vty_return(vty, ret);
7333 }
7334
7335 DEFUN (neighbor_filter_list,
7336 neighbor_filter_list_cmd,
7337 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7338 NEIGHBOR_STR
7339 NEIGHBOR_ADDR_STR2
7340 "Establish BGP filters\n"
7341 "AS path access-list name\n"
7342 "Filter incoming routes\n"
7343 "Filter outgoing routes\n")
7344 {
7345 int idx_peer = 1;
7346 int idx_word = 3;
7347 int idx_in_out = 4;
7348 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7349 bgp_node_safi(vty), argv[idx_word]->arg,
7350 argv[idx_in_out]->arg);
7351 }
7352
7353 ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
7354 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7355 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7356 "Establish BGP filters\n"
7357 "AS path access-list name\n"
7358 "Filter incoming routes\n"
7359 "Filter outgoing routes\n")
7360
7361 DEFUN (no_neighbor_filter_list,
7362 no_neighbor_filter_list_cmd,
7363 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7364 NO_STR
7365 NEIGHBOR_STR
7366 NEIGHBOR_ADDR_STR2
7367 "Establish BGP filters\n"
7368 "AS path access-list name\n"
7369 "Filter incoming routes\n"
7370 "Filter outgoing routes\n")
7371 {
7372 int idx_peer = 2;
7373 int idx_in_out = 5;
7374 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
7375 bgp_node_afi(vty), bgp_node_safi(vty),
7376 argv[idx_in_out]->arg);
7377 }
7378
7379 ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
7380 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7381 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7382 "Establish BGP filters\n"
7383 "AS path access-list name\n"
7384 "Filter incoming routes\n"
7385 "Filter outgoing routes\n")
7386
7387 /* Set advertise-map to the peer. */
7388 static int peer_advertise_map_set_vty(struct vty *vty, const char *ip_str,
7389 afi_t afi, safi_t safi,
7390 const char *advertise_str,
7391 const char *condition_str, bool condition,
7392 bool set)
7393 {
7394 int ret = CMD_WARNING_CONFIG_FAILED;
7395 struct peer *peer;
7396 struct route_map *advertise_map;
7397 struct route_map *condition_map;
7398
7399 peer = peer_and_group_lookup_vty(vty, ip_str);
7400 if (!peer)
7401 return ret;
7402
7403 condition_map = route_map_lookup_warn_noexist(vty, condition_str);
7404 advertise_map = route_map_lookup_warn_noexist(vty, advertise_str);
7405
7406 if (set)
7407 ret = peer_advertise_map_set(peer, afi, safi, advertise_str,
7408 advertise_map, condition_str,
7409 condition_map, condition);
7410 else
7411 ret = peer_advertise_map_unset(peer, afi, safi, advertise_str,
7412 advertise_map, condition_str,
7413 condition_map, condition);
7414
7415 return bgp_vty_return(vty, ret);
7416 }
7417
7418 DEFPY (bgp_condadv_period,
7419 bgp_condadv_period_cmd,
7420 "[no$no] bgp conditional-advertisement timer (5-240)$period",
7421 NO_STR
7422 BGP_STR
7423 "Conditional advertisement settings\n"
7424 "Set period to rescan BGP table to check if condition is met\n"
7425 "Period between BGP table scans, in seconds; default 60\n")
7426 {
7427 VTY_DECLVAR_CONTEXT(bgp, bgp);
7428
7429 bgp->condition_check_period =
7430 no ? DEFAULT_CONDITIONAL_ROUTES_POLL_TIME : period;
7431
7432 return CMD_SUCCESS;
7433 }
7434
7435 DEFPY (neighbor_advertise_map,
7436 neighbor_advertise_map_cmd,
7437 "[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",
7438 NO_STR
7439 NEIGHBOR_STR
7440 NEIGHBOR_ADDR_STR2
7441 "Route-map to conditionally advertise routes\n"
7442 "Name of advertise map\n"
7443 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7444 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
7445 "Name of the exist or non exist map\n")
7446 {
7447 bool condition = CONDITION_EXIST;
7448
7449 if (!strcmp(exist, "non-exist-map"))
7450 condition = CONDITION_NON_EXIST;
7451
7452 return peer_advertise_map_set_vty(vty, neighbor, bgp_node_afi(vty),
7453 bgp_node_safi(vty), advertise_str,
7454 condition_str, condition, !no);
7455 }
7456
7457 ALIAS_HIDDEN(neighbor_advertise_map, neighbor_advertise_map_hidden_cmd,
7458 "[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",
7459 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7460 "Route-map to conditionally advertise routes\n"
7461 "Name of advertise map\n"
7462 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7463 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
7464 "Name of the exist or non exist map\n")
7465
7466 /* Set route-map to the peer. */
7467 static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
7468 afi_t afi, safi_t safi, const char *name_str,
7469 const char *direct_str)
7470 {
7471 int ret;
7472 struct peer *peer;
7473 int direct = RMAP_IN;
7474 struct route_map *route_map;
7475
7476 peer = peer_and_group_lookup_vty(vty, ip_str);
7477 if (!peer)
7478 return CMD_WARNING_CONFIG_FAILED;
7479
7480 /* Check filter direction. */
7481 if (strncmp(direct_str, "in", 2) == 0)
7482 direct = RMAP_IN;
7483 else if (strncmp(direct_str, "o", 1) == 0)
7484 direct = RMAP_OUT;
7485
7486 route_map = route_map_lookup_warn_noexist(vty, name_str);
7487 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
7488
7489 return bgp_vty_return(vty, ret);
7490 }
7491
7492 static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
7493 afi_t afi, safi_t safi,
7494 const char *direct_str)
7495 {
7496 int ret;
7497 struct peer *peer;
7498 int direct = RMAP_IN;
7499
7500 peer = peer_and_group_lookup_vty(vty, ip_str);
7501 if (!peer)
7502 return CMD_WARNING_CONFIG_FAILED;
7503
7504 /* Check filter direction. */
7505 if (strncmp(direct_str, "in", 2) == 0)
7506 direct = RMAP_IN;
7507 else if (strncmp(direct_str, "o", 1) == 0)
7508 direct = RMAP_OUT;
7509
7510 ret = peer_route_map_unset(peer, afi, safi, direct);
7511
7512 return bgp_vty_return(vty, ret);
7513 }
7514
7515 DEFUN (neighbor_route_map,
7516 neighbor_route_map_cmd,
7517 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
7518 NEIGHBOR_STR
7519 NEIGHBOR_ADDR_STR2
7520 "Apply route map to neighbor\n"
7521 "Name of route map\n"
7522 "Apply map to incoming routes\n"
7523 "Apply map to outbound routes\n")
7524 {
7525 int idx_peer = 1;
7526 int idx_word = 3;
7527 int idx_in_out = 4;
7528 return peer_route_map_set_vty(
7529 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7530 argv[idx_word]->arg, argv[idx_in_out]->arg);
7531 }
7532
7533 ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
7534 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
7535 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7536 "Apply route map to neighbor\n"
7537 "Name of route map\n"
7538 "Apply map to incoming routes\n"
7539 "Apply map to outbound routes\n")
7540
7541 DEFUN (no_neighbor_route_map,
7542 no_neighbor_route_map_cmd,
7543 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
7544 NO_STR
7545 NEIGHBOR_STR
7546 NEIGHBOR_ADDR_STR2
7547 "Apply route map to neighbor\n"
7548 "Name of route map\n"
7549 "Apply map to incoming routes\n"
7550 "Apply map to outbound routes\n")
7551 {
7552 int idx_peer = 2;
7553 int idx_in_out = 5;
7554 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
7555 bgp_node_afi(vty), bgp_node_safi(vty),
7556 argv[idx_in_out]->arg);
7557 }
7558
7559 ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
7560 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
7561 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7562 "Apply route map to neighbor\n"
7563 "Name of route map\n"
7564 "Apply map to incoming routes\n"
7565 "Apply map to outbound routes\n")
7566
7567 /* Set unsuppress-map to the peer. */
7568 static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
7569 afi_t afi, safi_t safi,
7570 const char *name_str)
7571 {
7572 int ret;
7573 struct peer *peer;
7574 struct route_map *route_map;
7575
7576 peer = peer_and_group_lookup_vty(vty, ip_str);
7577 if (!peer)
7578 return CMD_WARNING_CONFIG_FAILED;
7579
7580 route_map = route_map_lookup_warn_noexist(vty, name_str);
7581 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
7582
7583 return bgp_vty_return(vty, ret);
7584 }
7585
7586 /* Unset route-map from the peer. */
7587 static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
7588 afi_t afi, safi_t safi)
7589 {
7590 int ret;
7591 struct peer *peer;
7592
7593 peer = peer_and_group_lookup_vty(vty, ip_str);
7594 if (!peer)
7595 return CMD_WARNING_CONFIG_FAILED;
7596
7597 ret = peer_unsuppress_map_unset(peer, afi, safi);
7598
7599 return bgp_vty_return(vty, ret);
7600 }
7601
7602 DEFUN (neighbor_unsuppress_map,
7603 neighbor_unsuppress_map_cmd,
7604 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7605 NEIGHBOR_STR
7606 NEIGHBOR_ADDR_STR2
7607 "Route-map to selectively unsuppress suppressed routes\n"
7608 "Name of route map\n")
7609 {
7610 int idx_peer = 1;
7611 int idx_word = 3;
7612 return peer_unsuppress_map_set_vty(
7613 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7614 argv[idx_word]->arg);
7615 }
7616
7617 ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
7618 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7619 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7620 "Route-map to selectively unsuppress suppressed routes\n"
7621 "Name of route map\n")
7622
7623 DEFUN (no_neighbor_unsuppress_map,
7624 no_neighbor_unsuppress_map_cmd,
7625 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7626 NO_STR
7627 NEIGHBOR_STR
7628 NEIGHBOR_ADDR_STR2
7629 "Route-map to selectively unsuppress suppressed routes\n"
7630 "Name of route map\n")
7631 {
7632 int idx_peer = 2;
7633 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
7634 bgp_node_afi(vty),
7635 bgp_node_safi(vty));
7636 }
7637
7638 ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
7639 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7640 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7641 "Route-map to selectively unsuppress suppressed routes\n"
7642 "Name of route map\n")
7643
7644 static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
7645 afi_t afi, safi_t safi,
7646 const char *num_str,
7647 const char *threshold_str, int warning,
7648 const char *restart_str,
7649 const char *force_str)
7650 {
7651 int ret;
7652 struct peer *peer;
7653 uint32_t max;
7654 uint8_t threshold;
7655 uint16_t restart;
7656
7657 peer = peer_and_group_lookup_vty(vty, ip_str);
7658 if (!peer)
7659 return CMD_WARNING_CONFIG_FAILED;
7660
7661 max = strtoul(num_str, NULL, 10);
7662 if (threshold_str)
7663 threshold = atoi(threshold_str);
7664 else
7665 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
7666
7667 if (restart_str)
7668 restart = atoi(restart_str);
7669 else
7670 restart = 0;
7671
7672 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
7673 restart, force_str ? true : false);
7674
7675 return bgp_vty_return(vty, ret);
7676 }
7677
7678 static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
7679 afi_t afi, safi_t safi)
7680 {
7681 int ret;
7682 struct peer *peer;
7683
7684 peer = peer_and_group_lookup_vty(vty, ip_str);
7685 if (!peer)
7686 return CMD_WARNING_CONFIG_FAILED;
7687
7688 ret = peer_maximum_prefix_unset(peer, afi, safi);
7689
7690 return bgp_vty_return(vty, ret);
7691 }
7692
7693 /* Maximum number of prefix to be sent to the neighbor. */
7694 DEFUN(neighbor_maximum_prefix_out,
7695 neighbor_maximum_prefix_out_cmd,
7696 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out (1-4294967295)",
7697 NEIGHBOR_STR
7698 NEIGHBOR_ADDR_STR2
7699 "Maximum number of prefixes to be sent to this peer\n"
7700 "Maximum no. of prefix limit\n")
7701 {
7702 int ret;
7703 int idx_peer = 1;
7704 int idx_number = 3;
7705 struct peer *peer;
7706 uint32_t max;
7707 afi_t afi = bgp_node_afi(vty);
7708 safi_t safi = bgp_node_safi(vty);
7709
7710 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7711 if (!peer)
7712 return CMD_WARNING_CONFIG_FAILED;
7713
7714 max = strtoul(argv[idx_number]->arg, NULL, 10);
7715
7716 ret = peer_maximum_prefix_out_set(peer, afi, safi, max);
7717
7718 return bgp_vty_return(vty, ret);
7719 }
7720
7721 DEFUN(no_neighbor_maximum_prefix_out,
7722 no_neighbor_maximum_prefix_out_cmd,
7723 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out [(1-4294967295)]",
7724 NO_STR
7725 NEIGHBOR_STR
7726 NEIGHBOR_ADDR_STR2
7727 "Maximum number of prefixes to be sent to this peer\n"
7728 "Maximum no. of prefix limit\n")
7729 {
7730 int ret;
7731 int idx_peer = 2;
7732 struct peer *peer;
7733 afi_t afi = bgp_node_afi(vty);
7734 safi_t safi = bgp_node_safi(vty);
7735
7736 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7737 if (!peer)
7738 return CMD_WARNING_CONFIG_FAILED;
7739
7740 ret = peer_maximum_prefix_out_unset(peer, afi, safi);
7741
7742 return bgp_vty_return(vty, ret);
7743 }
7744
7745 /* Maximum number of prefix configuration. Prefix count is different
7746 for each peer configuration. So this configuration can be set for
7747 each peer configuration. */
7748 DEFUN (neighbor_maximum_prefix,
7749 neighbor_maximum_prefix_cmd,
7750 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
7751 NEIGHBOR_STR
7752 NEIGHBOR_ADDR_STR2
7753 "Maximum number of prefix accept from this peer\n"
7754 "maximum no. of prefix limit\n"
7755 "Force checking all received routes not only accepted\n")
7756 {
7757 int idx_peer = 1;
7758 int idx_number = 3;
7759 int idx_force = 0;
7760 char *force = NULL;
7761
7762 if (argv_find(argv, argc, "force", &idx_force))
7763 force = argv[idx_force]->arg;
7764
7765 return peer_maximum_prefix_set_vty(
7766 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7767 argv[idx_number]->arg, NULL, 0, NULL, force);
7768 }
7769
7770 ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
7771 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
7772 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7773 "Maximum number of prefix accept from this peer\n"
7774 "maximum no. of prefix limit\n"
7775 "Force checking all received routes not only accepted\n")
7776
7777 DEFUN (neighbor_maximum_prefix_threshold,
7778 neighbor_maximum_prefix_threshold_cmd,
7779 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
7780 NEIGHBOR_STR
7781 NEIGHBOR_ADDR_STR2
7782 "Maximum number of prefix accept from this peer\n"
7783 "maximum no. of prefix limit\n"
7784 "Threshold value (%) at which to generate a warning msg\n"
7785 "Force checking all received routes not only accepted\n")
7786 {
7787 int idx_peer = 1;
7788 int idx_number = 3;
7789 int idx_number_2 = 4;
7790 int idx_force = 0;
7791 char *force = NULL;
7792
7793 if (argv_find(argv, argc, "force", &idx_force))
7794 force = argv[idx_force]->arg;
7795
7796 return peer_maximum_prefix_set_vty(
7797 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7798 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL, force);
7799 }
7800
7801 ALIAS_HIDDEN(
7802 neighbor_maximum_prefix_threshold,
7803 neighbor_maximum_prefix_threshold_hidden_cmd,
7804 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
7805 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7806 "Maximum number of prefix accept from this peer\n"
7807 "maximum no. of prefix limit\n"
7808 "Threshold value (%) at which to generate a warning msg\n"
7809 "Force checking all received routes not only accepted\n")
7810
7811 DEFUN (neighbor_maximum_prefix_warning,
7812 neighbor_maximum_prefix_warning_cmd,
7813 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
7814 NEIGHBOR_STR
7815 NEIGHBOR_ADDR_STR2
7816 "Maximum number of prefix accept from this peer\n"
7817 "maximum no. of prefix limit\n"
7818 "Only give warning message when limit is exceeded\n"
7819 "Force checking all received routes not only accepted\n")
7820 {
7821 int idx_peer = 1;
7822 int idx_number = 3;
7823 int idx_force = 0;
7824 char *force = NULL;
7825
7826 if (argv_find(argv, argc, "force", &idx_force))
7827 force = argv[idx_force]->arg;
7828
7829 return peer_maximum_prefix_set_vty(
7830 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7831 argv[idx_number]->arg, NULL, 1, NULL, force);
7832 }
7833
7834 ALIAS_HIDDEN(
7835 neighbor_maximum_prefix_warning,
7836 neighbor_maximum_prefix_warning_hidden_cmd,
7837 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
7838 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7839 "Maximum number of prefix accept from this peer\n"
7840 "maximum no. of prefix limit\n"
7841 "Only give warning message when limit is exceeded\n"
7842 "Force checking all received routes not only accepted\n")
7843
7844 DEFUN (neighbor_maximum_prefix_threshold_warning,
7845 neighbor_maximum_prefix_threshold_warning_cmd,
7846 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
7847 NEIGHBOR_STR
7848 NEIGHBOR_ADDR_STR2
7849 "Maximum number of prefix accept from this peer\n"
7850 "maximum no. of prefix limit\n"
7851 "Threshold value (%) at which to generate a warning msg\n"
7852 "Only give warning message when limit is exceeded\n"
7853 "Force checking all received routes not only accepted\n")
7854 {
7855 int idx_peer = 1;
7856 int idx_number = 3;
7857 int idx_number_2 = 4;
7858 int idx_force = 0;
7859 char *force = NULL;
7860
7861 if (argv_find(argv, argc, "force", &idx_force))
7862 force = argv[idx_force]->arg;
7863
7864 return peer_maximum_prefix_set_vty(
7865 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7866 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL, force);
7867 }
7868
7869 ALIAS_HIDDEN(
7870 neighbor_maximum_prefix_threshold_warning,
7871 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
7872 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
7873 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7874 "Maximum number of prefix accept from this peer\n"
7875 "maximum no. of prefix limit\n"
7876 "Threshold value (%) at which to generate a warning msg\n"
7877 "Only give warning message when limit is exceeded\n"
7878 "Force checking all received routes not only accepted\n")
7879
7880 DEFUN (neighbor_maximum_prefix_restart,
7881 neighbor_maximum_prefix_restart_cmd,
7882 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
7883 NEIGHBOR_STR
7884 NEIGHBOR_ADDR_STR2
7885 "Maximum number of prefix accept from this peer\n"
7886 "maximum no. of prefix limit\n"
7887 "Restart bgp connection after limit is exceeded\n"
7888 "Restart interval in minutes\n"
7889 "Force checking all received routes not only accepted\n")
7890 {
7891 int idx_peer = 1;
7892 int idx_number = 3;
7893 int idx_number_2 = 5;
7894 int idx_force = 0;
7895 char *force = NULL;
7896
7897 if (argv_find(argv, argc, "force", &idx_force))
7898 force = argv[idx_force]->arg;
7899
7900 return peer_maximum_prefix_set_vty(
7901 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7902 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg, force);
7903 }
7904
7905 ALIAS_HIDDEN(
7906 neighbor_maximum_prefix_restart,
7907 neighbor_maximum_prefix_restart_hidden_cmd,
7908 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
7909 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7910 "Maximum number of prefix accept from this peer\n"
7911 "maximum no. of prefix limit\n"
7912 "Restart bgp connection after limit is exceeded\n"
7913 "Restart interval in minutes\n"
7914 "Force checking all received routes not only accepted\n")
7915
7916 DEFUN (neighbor_maximum_prefix_threshold_restart,
7917 neighbor_maximum_prefix_threshold_restart_cmd,
7918 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
7919 NEIGHBOR_STR
7920 NEIGHBOR_ADDR_STR2
7921 "Maximum number of prefixes to accept from this peer\n"
7922 "maximum no. of prefix limit\n"
7923 "Threshold value (%) at which to generate a warning msg\n"
7924 "Restart bgp connection after limit is exceeded\n"
7925 "Restart interval in minutes\n"
7926 "Force checking all received routes not only accepted\n")
7927 {
7928 int idx_peer = 1;
7929 int idx_number = 3;
7930 int idx_number_2 = 4;
7931 int idx_number_3 = 6;
7932 int idx_force = 0;
7933 char *force = NULL;
7934
7935 if (argv_find(argv, argc, "force", &idx_force))
7936 force = argv[idx_force]->arg;
7937
7938 return peer_maximum_prefix_set_vty(
7939 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7940 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
7941 argv[idx_number_3]->arg, force);
7942 }
7943
7944 ALIAS_HIDDEN(
7945 neighbor_maximum_prefix_threshold_restart,
7946 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
7947 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
7948 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7949 "Maximum number of prefixes to accept from this peer\n"
7950 "maximum no. of prefix limit\n"
7951 "Threshold value (%) at which to generate a warning msg\n"
7952 "Restart bgp connection after limit is exceeded\n"
7953 "Restart interval in minutes\n"
7954 "Force checking all received routes not only accepted\n")
7955
7956 DEFUN (no_neighbor_maximum_prefix,
7957 no_neighbor_maximum_prefix_cmd,
7958 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
7959 NO_STR
7960 NEIGHBOR_STR
7961 NEIGHBOR_ADDR_STR2
7962 "Maximum number of prefixes to accept from this peer\n"
7963 "maximum no. of prefix limit\n"
7964 "Threshold value (%) at which to generate a warning msg\n"
7965 "Restart bgp connection after limit is exceeded\n"
7966 "Restart interval in minutes\n"
7967 "Only give warning message when limit is exceeded\n"
7968 "Force checking all received routes not only accepted\n")
7969 {
7970 int idx_peer = 2;
7971 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
7972 bgp_node_afi(vty),
7973 bgp_node_safi(vty));
7974 }
7975
7976 ALIAS_HIDDEN(
7977 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
7978 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
7979 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7980 "Maximum number of prefixes to accept from this peer\n"
7981 "maximum no. of prefix limit\n"
7982 "Threshold value (%) at which to generate a warning msg\n"
7983 "Restart bgp connection after limit is exceeded\n"
7984 "Restart interval in minutes\n"
7985 "Only give warning message when limit is exceeded\n"
7986 "Force checking all received routes not only accepted\n")
7987
7988
7989 /* "neighbor allowas-in" */
7990 DEFUN (neighbor_allowas_in,
7991 neighbor_allowas_in_cmd,
7992 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
7993 NEIGHBOR_STR
7994 NEIGHBOR_ADDR_STR2
7995 "Accept as-path with my AS present in it\n"
7996 "Number of occurrences of AS number\n"
7997 "Only accept my AS in the as-path if the route was originated in my AS\n")
7998 {
7999 int idx_peer = 1;
8000 int idx_number_origin = 3;
8001 int ret;
8002 int origin = 0;
8003 struct peer *peer;
8004 int allow_num = 0;
8005
8006 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8007 if (!peer)
8008 return CMD_WARNING_CONFIG_FAILED;
8009
8010 if (argc <= idx_number_origin)
8011 allow_num = 3;
8012 else {
8013 if (argv[idx_number_origin]->type == WORD_TKN)
8014 origin = 1;
8015 else
8016 allow_num = atoi(argv[idx_number_origin]->arg);
8017 }
8018
8019 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8020 allow_num, origin);
8021
8022 return bgp_vty_return(vty, ret);
8023 }
8024
8025 ALIAS_HIDDEN(
8026 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
8027 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8028 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8029 "Accept as-path with my AS present in it\n"
8030 "Number of occurrences of AS number\n"
8031 "Only accept my AS in the as-path if the route was originated in my AS\n")
8032
8033 DEFUN (no_neighbor_allowas_in,
8034 no_neighbor_allowas_in_cmd,
8035 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8036 NO_STR
8037 NEIGHBOR_STR
8038 NEIGHBOR_ADDR_STR2
8039 "allow local ASN appears in aspath attribute\n"
8040 "Number of occurrences of AS number\n"
8041 "Only accept my AS in the as-path if the route was originated in my AS\n")
8042 {
8043 int idx_peer = 2;
8044 int ret;
8045 struct peer *peer;
8046
8047 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8048 if (!peer)
8049 return CMD_WARNING_CONFIG_FAILED;
8050
8051 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
8052 bgp_node_safi(vty));
8053
8054 return bgp_vty_return(vty, ret);
8055 }
8056
8057 ALIAS_HIDDEN(
8058 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
8059 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8060 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8061 "allow local ASN appears in aspath attribute\n"
8062 "Number of occurrences of AS number\n"
8063 "Only accept my AS in the as-path if the route was originated in my AS\n")
8064
8065 DEFUN (neighbor_ttl_security,
8066 neighbor_ttl_security_cmd,
8067 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8068 NEIGHBOR_STR
8069 NEIGHBOR_ADDR_STR2
8070 "BGP ttl-security parameters\n"
8071 "Specify the maximum number of hops to the BGP peer\n"
8072 "Number of hops to BGP peer\n")
8073 {
8074 int idx_peer = 1;
8075 int idx_number = 4;
8076 struct peer *peer;
8077 int gtsm_hops;
8078
8079 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8080 if (!peer)
8081 return CMD_WARNING_CONFIG_FAILED;
8082
8083 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
8084
8085 /*
8086 * If 'neighbor swpX', then this is for directly connected peers,
8087 * we should not accept a ttl-security hops value greater than 1.
8088 */
8089 if (peer->conf_if && (gtsm_hops > BGP_GTSM_HOPS_CONNECTED)) {
8090 vty_out(vty,
8091 "%s is directly connected peer, hops cannot exceed 1\n",
8092 argv[idx_peer]->arg);
8093 return CMD_WARNING_CONFIG_FAILED;
8094 }
8095
8096 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
8097 }
8098
8099 DEFUN (no_neighbor_ttl_security,
8100 no_neighbor_ttl_security_cmd,
8101 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8102 NO_STR
8103 NEIGHBOR_STR
8104 NEIGHBOR_ADDR_STR2
8105 "BGP ttl-security parameters\n"
8106 "Specify the maximum number of hops to the BGP peer\n"
8107 "Number of hops to BGP peer\n")
8108 {
8109 int idx_peer = 2;
8110 struct peer *peer;
8111
8112 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8113 if (!peer)
8114 return CMD_WARNING_CONFIG_FAILED;
8115
8116 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
8117 }
8118
8119 /* disable-addpath-rx */
8120 DEFUN(neighbor_disable_addpath_rx,
8121 neighbor_disable_addpath_rx_cmd,
8122 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8123 NEIGHBOR_STR
8124 NEIGHBOR_ADDR_STR2
8125 "Do not accept additional paths\n")
8126 {
8127 char *peer_str = argv[1]->arg;
8128 struct peer *peer;
8129 afi_t afi = bgp_node_afi(vty);
8130 safi_t safi = bgp_node_safi(vty);
8131
8132 peer = peer_and_group_lookup_vty(vty, peer_str);
8133 if (!peer)
8134 return CMD_WARNING_CONFIG_FAILED;
8135
8136 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
8137 PEER_FLAG_DISABLE_ADDPATH_RX);
8138 }
8139
8140 DEFUN(no_neighbor_disable_addpath_rx,
8141 no_neighbor_disable_addpath_rx_cmd,
8142 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8143 NO_STR
8144 NEIGHBOR_STR
8145 NEIGHBOR_ADDR_STR2
8146 "Do not accept additional paths\n")
8147 {
8148 char *peer_str = argv[2]->arg;
8149 struct peer *peer;
8150 afi_t afi = bgp_node_afi(vty);
8151 safi_t safi = bgp_node_safi(vty);
8152
8153 peer = peer_and_group_lookup_vty(vty, peer_str);
8154 if (!peer)
8155 return CMD_WARNING_CONFIG_FAILED;
8156
8157 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
8158 PEER_FLAG_DISABLE_ADDPATH_RX);
8159 }
8160
8161 DEFUN (neighbor_addpath_tx_all_paths,
8162 neighbor_addpath_tx_all_paths_cmd,
8163 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8164 NEIGHBOR_STR
8165 NEIGHBOR_ADDR_STR2
8166 "Use addpath to advertise all paths to a neighbor\n")
8167 {
8168 int idx_peer = 1;
8169 struct peer *peer;
8170
8171 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8172 if (!peer)
8173 return CMD_WARNING_CONFIG_FAILED;
8174
8175 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8176 BGP_ADDPATH_ALL);
8177 return CMD_SUCCESS;
8178 }
8179
8180 ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
8181 neighbor_addpath_tx_all_paths_hidden_cmd,
8182 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8183 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8184 "Use addpath to advertise all paths to a neighbor\n")
8185
8186 DEFUN (no_neighbor_addpath_tx_all_paths,
8187 no_neighbor_addpath_tx_all_paths_cmd,
8188 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8189 NO_STR
8190 NEIGHBOR_STR
8191 NEIGHBOR_ADDR_STR2
8192 "Use addpath to advertise all paths to a neighbor\n")
8193 {
8194 int idx_peer = 2;
8195 struct peer *peer;
8196
8197 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8198 if (!peer)
8199 return CMD_WARNING_CONFIG_FAILED;
8200
8201 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8202 != BGP_ADDPATH_ALL) {
8203 vty_out(vty,
8204 "%% Peer not currently configured to transmit all paths.");
8205 return CMD_WARNING_CONFIG_FAILED;
8206 }
8207
8208 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8209 BGP_ADDPATH_NONE);
8210
8211 return CMD_SUCCESS;
8212 }
8213
8214 ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
8215 no_neighbor_addpath_tx_all_paths_hidden_cmd,
8216 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8217 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8218 "Use addpath to advertise all paths to a neighbor\n")
8219
8220 DEFUN (neighbor_addpath_tx_bestpath_per_as,
8221 neighbor_addpath_tx_bestpath_per_as_cmd,
8222 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8223 NEIGHBOR_STR
8224 NEIGHBOR_ADDR_STR2
8225 "Use addpath to advertise the bestpath per each neighboring AS\n")
8226 {
8227 int idx_peer = 1;
8228 struct peer *peer;
8229
8230 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8231 if (!peer)
8232 return CMD_WARNING_CONFIG_FAILED;
8233
8234 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8235 BGP_ADDPATH_BEST_PER_AS);
8236
8237 return CMD_SUCCESS;
8238 }
8239
8240 ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
8241 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8242 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8243 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8244 "Use addpath to advertise the bestpath per each neighboring AS\n")
8245
8246 DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
8247 no_neighbor_addpath_tx_bestpath_per_as_cmd,
8248 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8249 NO_STR
8250 NEIGHBOR_STR
8251 NEIGHBOR_ADDR_STR2
8252 "Use addpath to advertise the bestpath per each neighboring AS\n")
8253 {
8254 int idx_peer = 2;
8255 struct peer *peer;
8256
8257 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8258 if (!peer)
8259 return CMD_WARNING_CONFIG_FAILED;
8260
8261 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8262 != BGP_ADDPATH_BEST_PER_AS) {
8263 vty_out(vty,
8264 "%% Peer not currently configured to transmit all best path per as.");
8265 return CMD_WARNING_CONFIG_FAILED;
8266 }
8267
8268 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8269 BGP_ADDPATH_NONE);
8270
8271 return CMD_SUCCESS;
8272 }
8273
8274 ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
8275 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8276 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8277 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8278 "Use addpath to advertise the bestpath per each neighboring AS\n")
8279
8280 DEFPY(
8281 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
8282 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8283 NEIGHBOR_STR
8284 NEIGHBOR_ADDR_STR2
8285 "Detect AS loops before sending to neighbor\n")
8286 {
8287 struct peer *peer;
8288
8289 peer = peer_and_group_lookup_vty(vty, neighbor);
8290 if (!peer)
8291 return CMD_WARNING_CONFIG_FAILED;
8292
8293 peer->as_path_loop_detection = true;
8294
8295 return CMD_SUCCESS;
8296 }
8297
8298 DEFPY(
8299 no_neighbor_aspath_loop_detection,
8300 no_neighbor_aspath_loop_detection_cmd,
8301 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8302 NO_STR
8303 NEIGHBOR_STR
8304 NEIGHBOR_ADDR_STR2
8305 "Detect AS loops before sending to neighbor\n")
8306 {
8307 struct peer *peer;
8308
8309 peer = peer_and_group_lookup_vty(vty, neighbor);
8310 if (!peer)
8311 return CMD_WARNING_CONFIG_FAILED;
8312
8313 peer->as_path_loop_detection = false;
8314
8315 return CMD_SUCCESS;
8316 }
8317
8318 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
8319 struct ecommunity **list, bool is_rt6)
8320 {
8321 struct ecommunity *ecom = NULL;
8322 struct ecommunity *ecomadd;
8323
8324 for (; argc; --argc, ++argv) {
8325 if (is_rt6)
8326 ecomadd = ecommunity_str2com_ipv6(argv[0]->arg,
8327 ECOMMUNITY_ROUTE_TARGET,
8328 0);
8329 else
8330 ecomadd = ecommunity_str2com(argv[0]->arg,
8331 ECOMMUNITY_ROUTE_TARGET,
8332 0);
8333 if (!ecomadd) {
8334 vty_out(vty, "Malformed community-list value\n");
8335 if (ecom)
8336 ecommunity_free(&ecom);
8337 return CMD_WARNING_CONFIG_FAILED;
8338 }
8339
8340 if (ecom) {
8341 ecommunity_merge(ecom, ecomadd);
8342 ecommunity_free(&ecomadd);
8343 } else {
8344 ecom = ecomadd;
8345 }
8346 }
8347
8348 if (*list) {
8349 ecommunity_free(&*list);
8350 }
8351 *list = ecom;
8352
8353 return CMD_SUCCESS;
8354 }
8355
8356 /*
8357 * v2vimport is true if we are handling a `import vrf ...` command
8358 */
8359 static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
8360 {
8361 afi_t afi;
8362
8363 switch (vty->node) {
8364 case BGP_IPV4_NODE:
8365 afi = AFI_IP;
8366 break;
8367 case BGP_IPV6_NODE:
8368 afi = AFI_IP6;
8369 break;
8370 default:
8371 vty_out(vty,
8372 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
8373 return AFI_MAX;
8374 }
8375
8376 if (!v2vimport) {
8377 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8378 BGP_CONFIG_VRF_TO_VRF_IMPORT)
8379 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8380 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
8381 vty_out(vty,
8382 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
8383 return AFI_MAX;
8384 }
8385 } else {
8386 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8387 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
8388 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8389 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
8390 vty_out(vty,
8391 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
8392 return AFI_MAX;
8393 }
8394 }
8395 return afi;
8396 }
8397
8398 DEFPY (af_rd_vpn_export,
8399 af_rd_vpn_export_cmd,
8400 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
8401 NO_STR
8402 "Specify route distinguisher\n"
8403 "Between current address-family and vpn\n"
8404 "For routes leaked from current address-family to vpn\n"
8405 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
8406 {
8407 VTY_DECLVAR_CONTEXT(bgp, bgp);
8408 struct prefix_rd prd;
8409 int ret;
8410 afi_t afi;
8411 int idx = 0;
8412 bool yes = true;
8413
8414 if (argv_find(argv, argc, "no", &idx))
8415 yes = false;
8416
8417 if (yes) {
8418 ret = str2prefix_rd(rd_str, &prd);
8419 if (!ret) {
8420 vty_out(vty, "%% Malformed rd\n");
8421 return CMD_WARNING_CONFIG_FAILED;
8422 }
8423 }
8424
8425 afi = vpn_policy_getafi(vty, bgp, false);
8426 if (afi == AFI_MAX)
8427 return CMD_WARNING_CONFIG_FAILED;
8428
8429 /*
8430 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8431 */
8432 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8433 bgp_get_default(), bgp);
8434
8435 if (yes) {
8436 bgp->vpn_policy[afi].tovpn_rd = prd;
8437 SET_FLAG(bgp->vpn_policy[afi].flags,
8438 BGP_VPN_POLICY_TOVPN_RD_SET);
8439 } else {
8440 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8441 BGP_VPN_POLICY_TOVPN_RD_SET);
8442 }
8443
8444 /* post-change: re-export vpn routes */
8445 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8446 bgp_get_default(), bgp);
8447
8448 return CMD_SUCCESS;
8449 }
8450
8451 ALIAS (af_rd_vpn_export,
8452 af_no_rd_vpn_export_cmd,
8453 "no rd vpn export",
8454 NO_STR
8455 "Specify route distinguisher\n"
8456 "Between current address-family and vpn\n"
8457 "For routes leaked from current address-family to vpn\n")
8458
8459 DEFPY (af_label_vpn_export,
8460 af_label_vpn_export_cmd,
8461 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
8462 NO_STR
8463 "label value for VRF\n"
8464 "Between current address-family and vpn\n"
8465 "For routes leaked from current address-family to vpn\n"
8466 "Label Value <0-1048575>\n"
8467 "Automatically assign a label\n")
8468 {
8469 VTY_DECLVAR_CONTEXT(bgp, bgp);
8470 mpls_label_t label = MPLS_LABEL_NONE;
8471 afi_t afi;
8472 int idx = 0;
8473 bool yes = true;
8474
8475 if (argv_find(argv, argc, "no", &idx))
8476 yes = false;
8477
8478 /* If "no ...", squash trailing parameter */
8479 if (!yes)
8480 label_auto = NULL;
8481
8482 if (yes) {
8483 if (!label_auto)
8484 label = label_val; /* parser should force unsigned */
8485 }
8486
8487 afi = vpn_policy_getafi(vty, bgp, false);
8488 if (afi == AFI_MAX)
8489 return CMD_WARNING_CONFIG_FAILED;
8490
8491
8492 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8493 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
8494 /* no change */
8495 return CMD_SUCCESS;
8496
8497 /*
8498 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8499 */
8500 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8501 bgp_get_default(), bgp);
8502
8503 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8504 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
8505
8506 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
8507
8508 /*
8509 * label has previously been automatically
8510 * assigned by labelpool: release it
8511 *
8512 * NB if tovpn_label == MPLS_LABEL_NONE it
8513 * means the automatic assignment is in flight
8514 * and therefore the labelpool callback must
8515 * detect that the auto label is not needed.
8516 */
8517
8518 bgp_lp_release(LP_TYPE_VRF,
8519 &bgp->vpn_policy[afi],
8520 bgp->vpn_policy[afi].tovpn_label);
8521 }
8522 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8523 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
8524 }
8525
8526 bgp->vpn_policy[afi].tovpn_label = label;
8527 if (label_auto) {
8528 SET_FLAG(bgp->vpn_policy[afi].flags,
8529 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
8530 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
8531 vpn_leak_label_callback);
8532 }
8533
8534 /* post-change: re-export vpn routes */
8535 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8536 bgp_get_default(), bgp);
8537
8538 hook_call(bgp_snmp_update_last_changed, bgp);
8539 return CMD_SUCCESS;
8540 }
8541
8542 DEFPY (af_sid_vpn_export,
8543 af_sid_vpn_export_cmd,
8544 "[no] sid vpn export <(1-255)$sid_idx|auto$sid_auto>",
8545 NO_STR
8546 "sid value for VRF\n"
8547 "Between current address-family and vpn\n"
8548 "For routes leaked from current address-family to vpn\n"
8549 "Sid allocation index\n"
8550 "Automatically assign a label\n")
8551 {
8552 VTY_DECLVAR_CONTEXT(bgp, bgp);
8553 afi_t afi;
8554 int debug = 0;
8555 int idx = 0;
8556 bool yes = true;
8557
8558 if (argv_find(argv, argc, "no", &idx))
8559 yes = false;
8560 debug = (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF) |
8561 BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF));
8562
8563 afi = vpn_policy_getafi(vty, bgp, false);
8564 if (afi == AFI_MAX)
8565 return CMD_WARNING_CONFIG_FAILED;
8566
8567 if (!yes) {
8568 /* implement me */
8569 vty_out(vty, "It's not implemented\n");
8570 return CMD_WARNING_CONFIG_FAILED;
8571 }
8572
8573 /* skip when it's already configured */
8574 if ((sid_idx != 0 && bgp->vpn_policy[afi].tovpn_sid_index != 0)
8575 || (sid_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8576 BGP_VPN_POLICY_TOVPN_SID_AUTO)))
8577 return CMD_SUCCESS;
8578
8579 /*
8580 * mode change between sid_idx and sid_auto isn't supported.
8581 * user must negate sid vpn export when they want to change the mode
8582 */
8583 if ((sid_auto && bgp->vpn_policy[afi].tovpn_sid_index != 0)
8584 || (sid_idx != 0 && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8585 BGP_VPN_POLICY_TOVPN_SID_AUTO))) {
8586 vty_out(vty, "it's already configured as %s.\n",
8587 sid_auto ? "auto-mode" : "idx-mode");
8588 return CMD_WARNING_CONFIG_FAILED;
8589 }
8590
8591 /* pre-change */
8592 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8593 bgp_get_default(), bgp);
8594
8595 if (sid_auto) {
8596 /* SID allocation auto-mode */
8597 if (debug)
8598 zlog_debug("%s: auto sid alloc.", __func__);
8599 SET_FLAG(bgp->vpn_policy[afi].flags,
8600 BGP_VPN_POLICY_TOVPN_SID_AUTO);
8601 } else {
8602 /* SID allocation index-mode */
8603 if (debug)
8604 zlog_debug("%s: idx %ld sid alloc.", __func__, sid_idx);
8605 bgp->vpn_policy[afi].tovpn_sid_index = sid_idx;
8606 }
8607
8608 /* post-change */
8609 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8610 bgp_get_default(), bgp);
8611 return CMD_SUCCESS;
8612 }
8613
8614 ALIAS (af_label_vpn_export,
8615 af_no_label_vpn_export_cmd,
8616 "no label vpn export",
8617 NO_STR
8618 "label value for VRF\n"
8619 "Between current address-family and vpn\n"
8620 "For routes leaked from current address-family to vpn\n")
8621
8622 DEFPY (af_nexthop_vpn_export,
8623 af_nexthop_vpn_export_cmd,
8624 "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
8625 NO_STR
8626 "Specify next hop to use for VRF advertised prefixes\n"
8627 "Between current address-family and vpn\n"
8628 "For routes leaked from current address-family to vpn\n"
8629 "IPv4 prefix\n"
8630 "IPv6 prefix\n")
8631 {
8632 VTY_DECLVAR_CONTEXT(bgp, bgp);
8633 afi_t afi;
8634 struct prefix p;
8635
8636 if (!no) {
8637 if (!nexthop_su) {
8638 vty_out(vty, "%% Nexthop required\n");
8639 return CMD_WARNING_CONFIG_FAILED;
8640 }
8641 if (!sockunion2hostprefix(nexthop_su, &p))
8642 return CMD_WARNING_CONFIG_FAILED;
8643 }
8644
8645 afi = vpn_policy_getafi(vty, bgp, false);
8646 if (afi == AFI_MAX)
8647 return CMD_WARNING_CONFIG_FAILED;
8648
8649 /*
8650 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8651 */
8652 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8653 bgp_get_default(), bgp);
8654
8655 if (!no) {
8656 bgp->vpn_policy[afi].tovpn_nexthop = p;
8657 SET_FLAG(bgp->vpn_policy[afi].flags,
8658 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
8659 } else {
8660 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8661 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
8662 }
8663
8664 /* post-change: re-export vpn routes */
8665 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8666 bgp_get_default(), bgp);
8667
8668 return CMD_SUCCESS;
8669 }
8670
8671 static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
8672 {
8673 if (!strcmp(dstr, "import")) {
8674 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
8675 } else if (!strcmp(dstr, "export")) {
8676 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
8677 } else if (!strcmp(dstr, "both")) {
8678 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
8679 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
8680 } else {
8681 vty_out(vty, "%% direction parse error\n");
8682 return CMD_WARNING_CONFIG_FAILED;
8683 }
8684 return CMD_SUCCESS;
8685 }
8686
8687 DEFPY (af_rt_vpn_imexport,
8688 af_rt_vpn_imexport_cmd,
8689 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
8690 NO_STR
8691 "Specify route target list\n"
8692 "Specify route target list\n"
8693 "Between current address-family and vpn\n"
8694 "For routes leaked from vpn to current address-family: match any\n"
8695 "For routes leaked from current address-family to vpn: set\n"
8696 "both import: match any and export: set\n"
8697 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
8698 {
8699 VTY_DECLVAR_CONTEXT(bgp, bgp);
8700 int ret;
8701 struct ecommunity *ecom = NULL;
8702 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
8703 vpn_policy_direction_t dir;
8704 afi_t afi;
8705 int idx = 0;
8706 bool yes = true;
8707
8708 if (argv_find(argv, argc, "no", &idx))
8709 yes = false;
8710
8711 afi = vpn_policy_getafi(vty, bgp, false);
8712 if (afi == AFI_MAX)
8713 return CMD_WARNING_CONFIG_FAILED;
8714
8715 ret = vpn_policy_getdirs(vty, direction_str, dodir);
8716 if (ret != CMD_SUCCESS)
8717 return ret;
8718
8719 if (yes) {
8720 if (!argv_find(argv, argc, "RTLIST", &idx)) {
8721 vty_out(vty, "%% Missing RTLIST\n");
8722 return CMD_WARNING_CONFIG_FAILED;
8723 }
8724 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, false);
8725 if (ret != CMD_SUCCESS) {
8726 return ret;
8727 }
8728 }
8729
8730 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
8731 if (!dodir[dir])
8732 continue;
8733
8734 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
8735
8736 if (yes) {
8737 if (bgp->vpn_policy[afi].rtlist[dir])
8738 ecommunity_free(
8739 &bgp->vpn_policy[afi].rtlist[dir]);
8740 bgp->vpn_policy[afi].rtlist[dir] =
8741 ecommunity_dup(ecom);
8742 } else {
8743 if (bgp->vpn_policy[afi].rtlist[dir])
8744 ecommunity_free(
8745 &bgp->vpn_policy[afi].rtlist[dir]);
8746 bgp->vpn_policy[afi].rtlist[dir] = NULL;
8747 }
8748
8749 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
8750 }
8751
8752 if (ecom)
8753 ecommunity_free(&ecom);
8754
8755 return CMD_SUCCESS;
8756 }
8757
8758 ALIAS (af_rt_vpn_imexport,
8759 af_no_rt_vpn_imexport_cmd,
8760 "no <rt|route-target> vpn <import|export|both>$direction_str",
8761 NO_STR
8762 "Specify route target list\n"
8763 "Specify route target list\n"
8764 "Between current address-family and vpn\n"
8765 "For routes leaked from vpn to current address-family\n"
8766 "For routes leaked from current address-family to vpn\n"
8767 "both import and export\n")
8768
8769 DEFPY (af_route_map_vpn_imexport,
8770 af_route_map_vpn_imexport_cmd,
8771 /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
8772 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
8773 NO_STR
8774 "Specify route map\n"
8775 "Between current address-family and vpn\n"
8776 "For routes leaked from vpn to current address-family\n"
8777 "For routes leaked from current address-family to vpn\n"
8778 "name of route-map\n")
8779 {
8780 VTY_DECLVAR_CONTEXT(bgp, bgp);
8781 int ret;
8782 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
8783 vpn_policy_direction_t dir;
8784 afi_t afi;
8785 int idx = 0;
8786 bool yes = true;
8787
8788 if (argv_find(argv, argc, "no", &idx))
8789 yes = false;
8790
8791 afi = vpn_policy_getafi(vty, bgp, false);
8792 if (afi == AFI_MAX)
8793 return CMD_WARNING_CONFIG_FAILED;
8794
8795 ret = vpn_policy_getdirs(vty, direction_str, dodir);
8796 if (ret != CMD_SUCCESS)
8797 return ret;
8798
8799 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
8800 if (!dodir[dir])
8801 continue;
8802
8803 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
8804
8805 if (yes) {
8806 if (bgp->vpn_policy[afi].rmap_name[dir])
8807 XFREE(MTYPE_ROUTE_MAP_NAME,
8808 bgp->vpn_policy[afi].rmap_name[dir]);
8809 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
8810 MTYPE_ROUTE_MAP_NAME, rmap_str);
8811 bgp->vpn_policy[afi].rmap[dir] =
8812 route_map_lookup_warn_noexist(vty, rmap_str);
8813 if (!bgp->vpn_policy[afi].rmap[dir])
8814 return CMD_SUCCESS;
8815 } else {
8816 if (bgp->vpn_policy[afi].rmap_name[dir])
8817 XFREE(MTYPE_ROUTE_MAP_NAME,
8818 bgp->vpn_policy[afi].rmap_name[dir]);
8819 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
8820 bgp->vpn_policy[afi].rmap[dir] = NULL;
8821 }
8822
8823 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
8824 }
8825
8826 return CMD_SUCCESS;
8827 }
8828
8829 ALIAS (af_route_map_vpn_imexport,
8830 af_no_route_map_vpn_imexport_cmd,
8831 "no route-map vpn <import|export>$direction_str",
8832 NO_STR
8833 "Specify route map\n"
8834 "Between current address-family and vpn\n"
8835 "For routes leaked from vpn to current address-family\n"
8836 "For routes leaked from current address-family to vpn\n")
8837
8838 DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
8839 "import vrf route-map RMAP$rmap_str",
8840 "Import routes from another VRF\n"
8841 "Vrf routes being filtered\n"
8842 "Specify route map\n"
8843 "name of route-map\n")
8844 {
8845 VTY_DECLVAR_CONTEXT(bgp, bgp);
8846 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
8847 afi_t afi;
8848 struct bgp *bgp_default;
8849
8850 afi = vpn_policy_getafi(vty, bgp, true);
8851 if (afi == AFI_MAX)
8852 return CMD_WARNING_CONFIG_FAILED;
8853
8854 bgp_default = bgp_get_default();
8855 if (!bgp_default) {
8856 int32_t ret;
8857 as_t as = bgp->as;
8858
8859 /* Auto-create assuming the same AS */
8860 ret = bgp_get_vty(&bgp_default, &as, NULL,
8861 BGP_INSTANCE_TYPE_DEFAULT);
8862
8863 if (ret) {
8864 vty_out(vty,
8865 "VRF default is not configured as a bgp instance\n");
8866 return CMD_WARNING;
8867 }
8868 }
8869
8870 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
8871
8872 if (bgp->vpn_policy[afi].rmap_name[dir])
8873 XFREE(MTYPE_ROUTE_MAP_NAME,
8874 bgp->vpn_policy[afi].rmap_name[dir]);
8875 bgp->vpn_policy[afi].rmap_name[dir] =
8876 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
8877 bgp->vpn_policy[afi].rmap[dir] =
8878 route_map_lookup_warn_noexist(vty, rmap_str);
8879 if (!bgp->vpn_policy[afi].rmap[dir])
8880 return CMD_SUCCESS;
8881
8882 SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8883 BGP_CONFIG_VRF_TO_VRF_IMPORT);
8884
8885 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
8886
8887 return CMD_SUCCESS;
8888 }
8889
8890 DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
8891 "no import vrf route-map [RMAP$rmap_str]",
8892 NO_STR
8893 "Import routes from another VRF\n"
8894 "Vrf routes being filtered\n"
8895 "Specify route map\n"
8896 "name of route-map\n")
8897 {
8898 VTY_DECLVAR_CONTEXT(bgp, bgp);
8899 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
8900 afi_t afi;
8901
8902 afi = vpn_policy_getafi(vty, bgp, true);
8903 if (afi == AFI_MAX)
8904 return CMD_WARNING_CONFIG_FAILED;
8905
8906 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
8907
8908 if (bgp->vpn_policy[afi].rmap_name[dir])
8909 XFREE(MTYPE_ROUTE_MAP_NAME,
8910 bgp->vpn_policy[afi].rmap_name[dir]);
8911 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
8912 bgp->vpn_policy[afi].rmap[dir] = NULL;
8913
8914 if (bgp->vpn_policy[afi].import_vrf->count == 0)
8915 UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8916 BGP_CONFIG_VRF_TO_VRF_IMPORT);
8917
8918 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
8919
8920 return CMD_SUCCESS;
8921 }
8922
8923 DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
8924 "[no] import vrf VIEWVRFNAME$import_name",
8925 NO_STR
8926 "Import routes from another VRF\n"
8927 "VRF to import from\n"
8928 "The name of the VRF\n")
8929 {
8930 VTY_DECLVAR_CONTEXT(bgp, bgp);
8931 struct listnode *node;
8932 struct bgp *vrf_bgp, *bgp_default;
8933 int32_t ret = 0;
8934 as_t as = bgp->as;
8935 bool remove = false;
8936 int32_t idx = 0;
8937 char *vname;
8938 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
8939 safi_t safi;
8940 afi_t afi;
8941
8942 if (import_name == NULL) {
8943 vty_out(vty, "%% Missing import name\n");
8944 return CMD_WARNING;
8945 }
8946
8947 if (strcmp(import_name, "route-map") == 0) {
8948 vty_out(vty, "%% Must include route-map name\n");
8949 return CMD_WARNING;
8950 }
8951
8952 if (argv_find(argv, argc, "no", &idx))
8953 remove = true;
8954
8955 afi = vpn_policy_getafi(vty, bgp, true);
8956 if (afi == AFI_MAX)
8957 return CMD_WARNING_CONFIG_FAILED;
8958
8959 safi = bgp_node_safi(vty);
8960
8961 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
8962 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
8963 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
8964 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
8965 remove ? "unimport" : "import", import_name);
8966 return CMD_WARNING;
8967 }
8968
8969 bgp_default = bgp_get_default();
8970 if (!bgp_default) {
8971 /* Auto-create assuming the same AS */
8972 ret = bgp_get_vty(&bgp_default, &as, NULL,
8973 BGP_INSTANCE_TYPE_DEFAULT);
8974
8975 if (ret) {
8976 vty_out(vty,
8977 "VRF default is not configured as a bgp instance\n");
8978 return CMD_WARNING;
8979 }
8980 }
8981
8982 vrf_bgp = bgp_lookup_by_name(import_name);
8983 if (!vrf_bgp) {
8984 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
8985 vrf_bgp = bgp_default;
8986 else
8987 /* Auto-create assuming the same AS */
8988 ret = bgp_get_vty(&vrf_bgp, &as, import_name, bgp_type);
8989
8990 if (ret) {
8991 vty_out(vty,
8992 "VRF %s is not configured as a bgp instance\n",
8993 import_name);
8994 return CMD_WARNING;
8995 }
8996 }
8997
8998 if (remove) {
8999 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
9000 } else {
9001 /* Already importing from "import_vrf"? */
9002 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
9003 vname)) {
9004 if (strcmp(vname, import_name) == 0)
9005 return CMD_WARNING;
9006 }
9007
9008 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
9009 }
9010
9011 return CMD_SUCCESS;
9012 }
9013
9014 /* This command is valid only in a bgp vrf instance or the default instance */
9015 DEFPY (bgp_imexport_vpn,
9016 bgp_imexport_vpn_cmd,
9017 "[no] <import|export>$direction_str vpn",
9018 NO_STR
9019 "Import routes to this address-family\n"
9020 "Export routes from this address-family\n"
9021 "to/from default instance VPN RIB\n")
9022 {
9023 VTY_DECLVAR_CONTEXT(bgp, bgp);
9024 int previous_state;
9025 afi_t afi;
9026 safi_t safi;
9027 int idx = 0;
9028 bool yes = true;
9029 int flag;
9030 vpn_policy_direction_t dir;
9031
9032 if (argv_find(argv, argc, "no", &idx))
9033 yes = false;
9034
9035 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
9036 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
9037
9038 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
9039 return CMD_WARNING_CONFIG_FAILED;
9040 }
9041
9042 afi = bgp_node_afi(vty);
9043 safi = bgp_node_safi(vty);
9044 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
9045 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
9046 return CMD_WARNING_CONFIG_FAILED;
9047 }
9048
9049 if (!strcmp(direction_str, "import")) {
9050 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
9051 dir = BGP_VPN_POLICY_DIR_FROMVPN;
9052 } else if (!strcmp(direction_str, "export")) {
9053 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
9054 dir = BGP_VPN_POLICY_DIR_TOVPN;
9055 } else {
9056 vty_out(vty, "%% unknown direction %s\n", direction_str);
9057 return CMD_WARNING_CONFIG_FAILED;
9058 }
9059
9060 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
9061
9062 if (yes) {
9063 SET_FLAG(bgp->af_flags[afi][safi], flag);
9064 if (!previous_state) {
9065 /* trigger export current vrf */
9066 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9067 }
9068 } else {
9069 if (previous_state) {
9070 /* trigger un-export current vrf */
9071 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9072 }
9073 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
9074 }
9075
9076 hook_call(bgp_snmp_init_stats, bgp);
9077
9078 return CMD_SUCCESS;
9079 }
9080
9081 DEFPY (af_routetarget_import,
9082 af_routetarget_import_cmd,
9083 "[no] <rt|route-target|route-target6|rt6> redirect import RTLIST...",
9084 NO_STR
9085 "Specify route target list\n"
9086 "Specify route target list\n"
9087 "Specify route target list\n"
9088 "Specify route target list\n"
9089 "Flow-spec redirect type route target\n"
9090 "Import routes to this address-family\n"
9091 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN|IPV6:MN)\n")
9092 {
9093 VTY_DECLVAR_CONTEXT(bgp, bgp);
9094 int ret;
9095 struct ecommunity *ecom = NULL;
9096 afi_t afi;
9097 int idx = 0, idx_unused = 0;
9098 bool yes = true;
9099 bool rt6 = false;
9100
9101 if (argv_find(argv, argc, "no", &idx))
9102 yes = false;
9103
9104 if (argv_find(argv, argc, "rt6", &idx_unused) ||
9105 argv_find(argv, argc, "route-target6", &idx_unused))
9106 rt6 = true;
9107
9108 afi = vpn_policy_getafi(vty, bgp, false);
9109 if (afi == AFI_MAX)
9110 return CMD_WARNING_CONFIG_FAILED;
9111
9112 if (rt6 && afi != AFI_IP6)
9113 return CMD_WARNING_CONFIG_FAILED;
9114
9115 if (yes) {
9116 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9117 vty_out(vty, "%% Missing RTLIST\n");
9118 return CMD_WARNING_CONFIG_FAILED;
9119 }
9120 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, rt6);
9121 if (ret != CMD_SUCCESS)
9122 return ret;
9123 }
9124
9125 if (yes) {
9126 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9127 ecommunity_free(&bgp->vpn_policy[afi]
9128 .import_redirect_rtlist);
9129 bgp->vpn_policy[afi].import_redirect_rtlist =
9130 ecommunity_dup(ecom);
9131 } else {
9132 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9133 ecommunity_free(&bgp->vpn_policy[afi]
9134 .import_redirect_rtlist);
9135 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
9136 }
9137
9138 if (ecom)
9139 ecommunity_free(&ecom);
9140
9141 return CMD_SUCCESS;
9142 }
9143
9144 DEFUN_NOSH (address_family_ipv4_safi,
9145 address_family_ipv4_safi_cmd,
9146 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9147 "Enter Address Family command mode\n"
9148 "Address Family\n"
9149 BGP_SAFI_WITH_LABEL_HELP_STR)
9150 {
9151
9152 if (argc == 3) {
9153 VTY_DECLVAR_CONTEXT(bgp, bgp);
9154 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9155 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
9156 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9157 && safi != SAFI_EVPN) {
9158 vty_out(vty,
9159 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9160 return CMD_WARNING_CONFIG_FAILED;
9161 }
9162 vty->node = bgp_node_type(AFI_IP, safi);
9163 } else
9164 vty->node = BGP_IPV4_NODE;
9165
9166 return CMD_SUCCESS;
9167 }
9168
9169 DEFUN_NOSH (address_family_ipv6_safi,
9170 address_family_ipv6_safi_cmd,
9171 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9172 "Enter Address Family command mode\n"
9173 "Address Family\n"
9174 BGP_SAFI_WITH_LABEL_HELP_STR)
9175 {
9176 if (argc == 3) {
9177 VTY_DECLVAR_CONTEXT(bgp, bgp);
9178 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9179 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
9180 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9181 && safi != SAFI_EVPN) {
9182 vty_out(vty,
9183 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9184 return CMD_WARNING_CONFIG_FAILED;
9185 }
9186 vty->node = bgp_node_type(AFI_IP6, safi);
9187 } else
9188 vty->node = BGP_IPV6_NODE;
9189
9190 return CMD_SUCCESS;
9191 }
9192
9193 #ifdef KEEP_OLD_VPN_COMMANDS
9194 DEFUN_NOSH (address_family_vpnv4,
9195 address_family_vpnv4_cmd,
9196 "address-family vpnv4 [unicast]",
9197 "Enter Address Family command mode\n"
9198 "Address Family\n"
9199 "Address Family modifier\n")
9200 {
9201 vty->node = BGP_VPNV4_NODE;
9202 return CMD_SUCCESS;
9203 }
9204
9205 DEFUN_NOSH (address_family_vpnv6,
9206 address_family_vpnv6_cmd,
9207 "address-family vpnv6 [unicast]",
9208 "Enter Address Family command mode\n"
9209 "Address Family\n"
9210 "Address Family modifier\n")
9211 {
9212 vty->node = BGP_VPNV6_NODE;
9213 return CMD_SUCCESS;
9214 }
9215 #endif /* KEEP_OLD_VPN_COMMANDS */
9216
9217 DEFUN_NOSH (address_family_evpn,
9218 address_family_evpn_cmd,
9219 "address-family l2vpn evpn",
9220 "Enter Address Family command mode\n"
9221 "Address Family\n"
9222 "Address Family modifier\n")
9223 {
9224 VTY_DECLVAR_CONTEXT(bgp, bgp);
9225 vty->node = BGP_EVPN_NODE;
9226 return CMD_SUCCESS;
9227 }
9228
9229 DEFUN_NOSH (bgp_segment_routing_srv6,
9230 bgp_segment_routing_srv6_cmd,
9231 "segment-routing srv6",
9232 "Segment-Routing configuration\n"
9233 "Segment-Routing SRv6 configuration\n")
9234 {
9235 VTY_DECLVAR_CONTEXT(bgp, bgp);
9236 bgp->srv6_enabled = true;
9237 vty->node = BGP_SRV6_NODE;
9238 return CMD_SUCCESS;
9239 }
9240
9241 DEFUN (no_bgp_segment_routing_srv6,
9242 no_bgp_segment_routing_srv6_cmd,
9243 "no segment-routing srv6",
9244 NO_STR
9245 "Segment-Routing configuration\n"
9246 "Segment-Routing SRv6 configuration\n")
9247 {
9248 VTY_DECLVAR_CONTEXT(bgp, bgp);
9249
9250 if (strlen(bgp->srv6_locator_name) > 0)
9251 if (bgp_srv6_locator_unset(bgp) < 0)
9252 return CMD_WARNING_CONFIG_FAILED;
9253
9254 bgp->srv6_enabled = false;
9255 return CMD_SUCCESS;
9256 }
9257
9258 DEFPY (bgp_srv6_locator,
9259 bgp_srv6_locator_cmd,
9260 "locator NAME$name",
9261 "Specify SRv6 locator\n"
9262 "Specify SRv6 locator\n")
9263 {
9264 VTY_DECLVAR_CONTEXT(bgp, bgp);
9265 int ret;
9266
9267 if (strlen(bgp->srv6_locator_name) > 0
9268 && strcmp(name, bgp->srv6_locator_name) != 0) {
9269 vty_out(vty, "srv6 locator is already configured\n");
9270 return CMD_WARNING_CONFIG_FAILED;
9271 }
9272
9273 snprintf(bgp->srv6_locator_name,
9274 sizeof(bgp->srv6_locator_name), "%s", name);
9275
9276 ret = bgp_zebra_srv6_manager_get_locator_chunk(name);
9277 if (ret < 0)
9278 return CMD_WARNING_CONFIG_FAILED;
9279
9280 return CMD_SUCCESS;
9281 }
9282
9283 DEFPY (no_bgp_srv6_locator,
9284 no_bgp_srv6_locator_cmd,
9285 "no locator NAME$name",
9286 NO_STR
9287 "Specify SRv6 locator\n"
9288 "Specify SRv6 locator\n")
9289 {
9290 VTY_DECLVAR_CONTEXT(bgp, bgp);
9291
9292 /* when locator isn't configured, do nothing */
9293 if (strlen(bgp->srv6_locator_name) < 1)
9294 return CMD_SUCCESS;
9295
9296 /* name validation */
9297 if (strcmp(name, bgp->srv6_locator_name) != 0) {
9298 vty_out(vty, "%% No srv6 locator is configured\n");
9299 return CMD_WARNING_CONFIG_FAILED;
9300 }
9301
9302 /* unset locator */
9303 if (bgp_srv6_locator_unset(bgp) < 0)
9304 return CMD_WARNING_CONFIG_FAILED;
9305
9306 return CMD_SUCCESS;
9307 }
9308
9309 DEFPY (show_bgp_srv6,
9310 show_bgp_srv6_cmd,
9311 "show bgp segment-routing srv6",
9312 SHOW_STR
9313 BGP_STR
9314 "BGP Segment Routing\n"
9315 "BGP Segment Routing SRv6\n")
9316 {
9317 struct bgp *bgp;
9318 struct listnode *node;
9319 struct srv6_locator_chunk *chunk;
9320 struct bgp_srv6_function *func;
9321 struct in6_addr *tovpn4_sid;
9322 struct in6_addr *tovpn6_sid;
9323 char buf[256];
9324 char buf_tovpn4_sid[256];
9325 char buf_tovpn6_sid[256];
9326
9327 bgp = bgp_get_default();
9328 if (!bgp)
9329 return CMD_SUCCESS;
9330
9331 vty_out(vty, "locator_name: %s\n", bgp->srv6_locator_name);
9332 vty_out(vty, "locator_chunks:\n");
9333 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_locator_chunks, node, chunk)) {
9334 prefix2str(&chunk->prefix, buf, sizeof(buf));
9335 vty_out(vty, "- %s\n", buf);
9336 }
9337
9338 vty_out(vty, "functions:\n");
9339 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_functions, node, func)) {
9340 inet_ntop(AF_INET6, &func->sid, buf, sizeof(buf));
9341 vty_out(vty, "- sid: %s\n", buf);
9342 vty_out(vty, " locator: %s\n", func->locator_name);
9343 }
9344
9345 vty_out(vty, "bgps:\n");
9346 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp)) {
9347 vty_out(vty, "- name: %s\n",
9348 bgp->name ? bgp->name : "default");
9349
9350 tovpn4_sid = bgp->vpn_policy[AFI_IP].tovpn_sid;
9351 tovpn6_sid = bgp->vpn_policy[AFI_IP6].tovpn_sid;
9352 if (tovpn4_sid)
9353 inet_ntop(AF_INET6, tovpn4_sid, buf_tovpn4_sid,
9354 sizeof(buf_tovpn4_sid));
9355 if (tovpn6_sid)
9356 inet_ntop(AF_INET6, tovpn6_sid, buf_tovpn6_sid,
9357 sizeof(buf_tovpn6_sid));
9358
9359 vty_out(vty, " vpn_policy[AFI_IP].tovpn_sid: %s\n",
9360 tovpn4_sid ? buf_tovpn4_sid : "none");
9361 vty_out(vty, " vpn_policy[AFI_IP6].tovpn_sid: %s\n",
9362 tovpn6_sid ? buf_tovpn6_sid : "none");
9363 }
9364
9365 return CMD_SUCCESS;
9366 }
9367
9368 DEFUN_NOSH (exit_address_family,
9369 exit_address_family_cmd,
9370 "exit-address-family",
9371 "Exit from Address Family configuration mode\n")
9372 {
9373 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
9374 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
9375 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
9376 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
9377 || vty->node == BGP_EVPN_NODE
9378 || vty->node == BGP_FLOWSPECV4_NODE
9379 || vty->node == BGP_FLOWSPECV6_NODE)
9380 vty->node = BGP_NODE;
9381 return CMD_SUCCESS;
9382 }
9383
9384 /* Recalculate bestpath and re-advertise a prefix */
9385 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
9386 const char *ip_str, afi_t afi, safi_t safi,
9387 struct prefix_rd *prd)
9388 {
9389 int ret;
9390 struct prefix match;
9391 struct bgp_dest *dest;
9392 struct bgp_dest *rm;
9393 struct bgp *bgp;
9394 struct bgp_table *table;
9395 struct bgp_table *rib;
9396
9397 /* BGP structure lookup. */
9398 if (view_name) {
9399 bgp = bgp_lookup_by_name(view_name);
9400 if (bgp == NULL) {
9401 vty_out(vty, "%% Can't find BGP instance %s\n",
9402 view_name);
9403 return CMD_WARNING;
9404 }
9405 } else {
9406 bgp = bgp_get_default();
9407 if (bgp == NULL) {
9408 vty_out(vty, "%% No BGP process is configured\n");
9409 return CMD_WARNING;
9410 }
9411 }
9412
9413 /* Check IP address argument. */
9414 ret = str2prefix(ip_str, &match);
9415 if (!ret) {
9416 vty_out(vty, "%% address is malformed\n");
9417 return CMD_WARNING;
9418 }
9419
9420 match.family = afi2family(afi);
9421 rib = bgp->rib[afi][safi];
9422
9423 if (safi == SAFI_MPLS_VPN) {
9424 for (dest = bgp_table_top(rib); dest;
9425 dest = bgp_route_next(dest)) {
9426 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
9427
9428 if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
9429 continue;
9430
9431 table = bgp_dest_get_bgp_table_info(dest);
9432 if (table == NULL)
9433 continue;
9434
9435 rm = bgp_node_match(table, &match);
9436 if (rm != NULL) {
9437 const struct prefix *rm_p =
9438 bgp_dest_get_prefix(rm);
9439
9440 if (rm_p->prefixlen == match.prefixlen) {
9441 SET_FLAG(rm->flags,
9442 BGP_NODE_USER_CLEAR);
9443 bgp_process(bgp, rm, afi, safi);
9444 }
9445 bgp_dest_unlock_node(rm);
9446 }
9447 }
9448 } else {
9449 dest = bgp_node_match(rib, &match);
9450 if (dest != NULL) {
9451 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
9452
9453 if (dest_p->prefixlen == match.prefixlen) {
9454 SET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
9455 bgp_process(bgp, dest, afi, safi);
9456 }
9457 bgp_dest_unlock_node(dest);
9458 }
9459 }
9460
9461 return CMD_SUCCESS;
9462 }
9463
9464 /* one clear bgp command to rule them all */
9465 DEFUN (clear_ip_bgp_all,
9466 clear_ip_bgp_all_cmd,
9467 "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>]",
9468 CLEAR_STR
9469 IP_STR
9470 BGP_STR
9471 BGP_INSTANCE_HELP_STR
9472 BGP_AFI_HELP_STR
9473 "Address Family\n"
9474 BGP_SAFI_WITH_LABEL_HELP_STR
9475 "Address Family modifier\n"
9476 "Clear all peers\n"
9477 "BGP IPv4 neighbor to clear\n"
9478 "BGP IPv6 neighbor to clear\n"
9479 "BGP neighbor on interface to clear\n"
9480 "Clear peers with the AS number\n"
9481 "Clear all external peers\n"
9482 "Clear all members of peer-group\n"
9483 "BGP peer-group name\n"
9484 BGP_SOFT_STR
9485 BGP_SOFT_IN_STR
9486 BGP_SOFT_OUT_STR
9487 BGP_SOFT_IN_STR
9488 "Push out prefix-list ORF and do inbound soft reconfig\n"
9489 BGP_SOFT_OUT_STR
9490 "Reset message statistics\n")
9491 {
9492 char *vrf = NULL;
9493
9494 afi_t afi = AFI_UNSPEC;
9495 safi_t safi = SAFI_UNSPEC;
9496 enum clear_sort clr_sort = clear_peer;
9497 enum bgp_clear_type clr_type;
9498 char *clr_arg = NULL;
9499
9500 int idx = 0;
9501
9502 /* clear [ip] bgp */
9503 if (argv_find(argv, argc, "ip", &idx))
9504 afi = AFI_IP;
9505
9506 /* [<vrf> VIEWVRFNAME] */
9507 if (argv_find(argv, argc, "vrf", &idx)) {
9508 vrf = argv[idx + 1]->arg;
9509 idx += 2;
9510 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9511 vrf = NULL;
9512 } else if (argv_find(argv, argc, "view", &idx)) {
9513 /* [<view> VIEWVRFNAME] */
9514 vrf = argv[idx + 1]->arg;
9515 idx += 2;
9516 }
9517 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
9518 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
9519 argv_find_and_parse_safi(argv, argc, &idx, &safi);
9520
9521 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
9522 if (argv_find(argv, argc, "*", &idx)) {
9523 clr_sort = clear_all;
9524 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
9525 clr_sort = clear_peer;
9526 clr_arg = argv[idx]->arg;
9527 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
9528 clr_sort = clear_peer;
9529 clr_arg = argv[idx]->arg;
9530 } else if (argv_find(argv, argc, "peer-group", &idx)) {
9531 clr_sort = clear_group;
9532 idx++;
9533 clr_arg = argv[idx]->arg;
9534 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
9535 clr_sort = clear_peer;
9536 clr_arg = argv[idx]->arg;
9537 } else if (argv_find(argv, argc, "WORD", &idx)) {
9538 clr_sort = clear_peer;
9539 clr_arg = argv[idx]->arg;
9540 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
9541 clr_sort = clear_as;
9542 clr_arg = argv[idx]->arg;
9543 } else if (argv_find(argv, argc, "external", &idx)) {
9544 clr_sort = clear_external;
9545 }
9546
9547 /* [<soft [<in|out>]|in [prefix-filter]|out|message-stats>] */
9548 if (argv_find(argv, argc, "soft", &idx)) {
9549 if (argv_find(argv, argc, "in", &idx)
9550 || argv_find(argv, argc, "out", &idx))
9551 clr_type = strmatch(argv[idx]->text, "in")
9552 ? BGP_CLEAR_SOFT_IN
9553 : BGP_CLEAR_SOFT_OUT;
9554 else
9555 clr_type = BGP_CLEAR_SOFT_BOTH;
9556 } else if (argv_find(argv, argc, "in", &idx)) {
9557 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
9558 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
9559 : BGP_CLEAR_SOFT_IN;
9560 } else if (argv_find(argv, argc, "out", &idx)) {
9561 clr_type = BGP_CLEAR_SOFT_OUT;
9562 } else if (argv_find(argv, argc, "message-stats", &idx)) {
9563 clr_type = BGP_CLEAR_MESSAGE_STATS;
9564 } else
9565 clr_type = BGP_CLEAR_SOFT_NONE;
9566
9567 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
9568 }
9569
9570 DEFUN (clear_ip_bgp_prefix,
9571 clear_ip_bgp_prefix_cmd,
9572 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
9573 CLEAR_STR
9574 IP_STR
9575 BGP_STR
9576 BGP_INSTANCE_HELP_STR
9577 "Clear bestpath and re-advertise\n"
9578 "IPv4 prefix\n")
9579 {
9580 char *vrf = NULL;
9581 char *prefix = NULL;
9582
9583 int idx = 0;
9584
9585 /* [<view|vrf> VIEWVRFNAME] */
9586 if (argv_find(argv, argc, "vrf", &idx)) {
9587 vrf = argv[idx + 1]->arg;
9588 idx += 2;
9589 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9590 vrf = NULL;
9591 } else if (argv_find(argv, argc, "view", &idx)) {
9592 /* [<view> VIEWVRFNAME] */
9593 vrf = argv[idx + 1]->arg;
9594 idx += 2;
9595 }
9596
9597 prefix = argv[argc - 1]->arg;
9598
9599 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
9600 }
9601
9602 DEFUN (clear_bgp_ipv6_safi_prefix,
9603 clear_bgp_ipv6_safi_prefix_cmd,
9604 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
9605 CLEAR_STR
9606 IP_STR
9607 BGP_STR
9608 "Address Family\n"
9609 BGP_SAFI_HELP_STR
9610 "Clear bestpath and re-advertise\n"
9611 "IPv6 prefix\n")
9612 {
9613 int idx_safi = 0;
9614 int idx_ipv6_prefix = 0;
9615 safi_t safi = SAFI_UNICAST;
9616 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
9617 argv[idx_ipv6_prefix]->arg : NULL;
9618
9619 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
9620 return bgp_clear_prefix(
9621 vty, NULL, prefix, AFI_IP6,
9622 safi, NULL);
9623 }
9624
9625 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
9626 clear_bgp_instance_ipv6_safi_prefix_cmd,
9627 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
9628 CLEAR_STR
9629 IP_STR
9630 BGP_STR
9631 BGP_INSTANCE_HELP_STR
9632 "Address Family\n"
9633 BGP_SAFI_HELP_STR
9634 "Clear bestpath and re-advertise\n"
9635 "IPv6 prefix\n")
9636 {
9637 int idx_safi = 0;
9638 int idx_vrfview = 0;
9639 int idx_ipv6_prefix = 0;
9640 safi_t safi = SAFI_UNICAST;
9641 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
9642 argv[idx_ipv6_prefix]->arg : NULL;
9643 char *vrfview = NULL;
9644
9645 /* [<view|vrf> VIEWVRFNAME] */
9646 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
9647 vrfview = argv[idx_vrfview + 1]->arg;
9648 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
9649 vrfview = NULL;
9650 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
9651 /* [<view> VIEWVRFNAME] */
9652 vrfview = argv[idx_vrfview + 1]->arg;
9653 }
9654 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
9655
9656 return bgp_clear_prefix(
9657 vty, vrfview, prefix,
9658 AFI_IP6, safi, NULL);
9659 }
9660
9661 DEFUN (show_bgp_views,
9662 show_bgp_views_cmd,
9663 "show [ip] bgp views",
9664 SHOW_STR
9665 IP_STR
9666 BGP_STR
9667 "Show the defined BGP views\n")
9668 {
9669 struct list *inst = bm->bgp;
9670 struct listnode *node;
9671 struct bgp *bgp;
9672
9673 vty_out(vty, "Defined BGP views:\n");
9674 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
9675 /* Skip VRFs. */
9676 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
9677 continue;
9678 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
9679 bgp->as);
9680 }
9681
9682 return CMD_SUCCESS;
9683 }
9684
9685 DEFUN (show_bgp_vrfs,
9686 show_bgp_vrfs_cmd,
9687 "show [ip] bgp vrfs [json]",
9688 SHOW_STR
9689 IP_STR
9690 BGP_STR
9691 "Show BGP VRFs\n"
9692 JSON_STR)
9693 {
9694 char buf[ETHER_ADDR_STRLEN];
9695 struct list *inst = bm->bgp;
9696 struct listnode *node;
9697 struct bgp *bgp;
9698 bool uj = use_json(argc, argv);
9699 json_object *json = NULL;
9700 json_object *json_vrfs = NULL;
9701 int count = 0;
9702
9703 if (uj) {
9704 json = json_object_new_object();
9705 json_vrfs = json_object_new_object();
9706 }
9707
9708 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
9709 const char *name, *type;
9710 struct peer *peer;
9711 struct listnode *node2, *nnode2;
9712 int peers_cfg, peers_estb;
9713 json_object *json_vrf = NULL;
9714
9715 /* Skip Views. */
9716 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
9717 continue;
9718
9719 count++;
9720 if (!uj && count == 1) {
9721 vty_out(vty,
9722 "%4s %-5s %-16s %9s %10s %-37s\n",
9723 "Type", "Id", "routerId", "#PeersCfg",
9724 "#PeersEstb", "Name");
9725 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
9726 "L3-VNI", "RouterMAC", "Interface");
9727 }
9728
9729 peers_cfg = peers_estb = 0;
9730 if (uj)
9731 json_vrf = json_object_new_object();
9732
9733
9734 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
9735 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
9736 continue;
9737 peers_cfg++;
9738 if (peer_established(peer))
9739 peers_estb++;
9740 }
9741
9742 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
9743 name = VRF_DEFAULT_NAME;
9744 type = "DFLT";
9745 } else {
9746 name = bgp->name;
9747 type = "VRF";
9748 }
9749
9750
9751 if (uj) {
9752 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
9753 ? -1
9754 : (int64_t)bgp->vrf_id;
9755 char buf[BUFSIZ] = {0};
9756
9757 json_object_string_add(json_vrf, "type", type);
9758 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
9759 json_object_string_addf(json_vrf, "routerId", "%pI4",
9760 &bgp->router_id);
9761 json_object_int_add(json_vrf, "numConfiguredPeers",
9762 peers_cfg);
9763 json_object_int_add(json_vrf, "numEstablishedPeers",
9764 peers_estb);
9765
9766 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
9767 json_object_string_add(
9768 json_vrf, "rmac",
9769 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
9770 json_object_string_add(json_vrf, "interface",
9771 ifindex2ifname(bgp->l3vni_svi_ifindex,
9772 bgp->vrf_id));
9773 json_object_object_add(json_vrfs, name, json_vrf);
9774 } else {
9775 vty_out(vty, "%4s %-5d %-16pI4 %-9u %-10u %-37s\n",
9776 type,
9777 bgp->vrf_id == VRF_UNKNOWN ? -1
9778 : (int)bgp->vrf_id,
9779 &bgp->router_id, peers_cfg, peers_estb, name);
9780 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
9781 bgp->l3vni,
9782 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
9783 ifindex2ifname(bgp->l3vni_svi_ifindex,
9784 bgp->vrf_id));
9785 }
9786 }
9787
9788 if (uj) {
9789 json_object_object_add(json, "vrfs", json_vrfs);
9790
9791 json_object_int_add(json, "totalVrfs", count);
9792
9793 vty_json(vty, json);
9794 } else {
9795 if (count)
9796 vty_out(vty,
9797 "\nTotal number of VRFs (including default): %d\n",
9798 count);
9799 }
9800
9801 return CMD_SUCCESS;
9802 }
9803
9804 DEFUN (show_bgp_mac_hash,
9805 show_bgp_mac_hash_cmd,
9806 "show bgp mac hash",
9807 SHOW_STR
9808 BGP_STR
9809 "Mac Address\n"
9810 "Mac Address database\n")
9811 {
9812 bgp_mac_dump_table(vty);
9813
9814 return CMD_SUCCESS;
9815 }
9816
9817 static void show_tip_entry(struct hash_bucket *bucket, void *args)
9818 {
9819 struct vty *vty = (struct vty *)args;
9820 struct tip_addr *tip = (struct tip_addr *)bucket->data;
9821
9822 vty_out(vty, "addr: %pI4, count: %d\n", &tip->addr, tip->refcnt);
9823 }
9824
9825 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
9826 {
9827 vty_out(vty, "self nexthop database:\n");
9828 bgp_nexthop_show_address_hash(vty, bgp);
9829
9830 vty_out(vty, "Tunnel-ip database:\n");
9831 hash_iterate(bgp->tip_hash,
9832 (void (*)(struct hash_bucket *, void *))show_tip_entry,
9833 vty);
9834 }
9835
9836 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
9837 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
9838 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
9839 "martian next-hops\n"
9840 "martian next-hop database\n")
9841 {
9842 struct bgp *bgp = NULL;
9843 int idx = 0;
9844 char *name = NULL;
9845
9846 /* [<vrf> VIEWVRFNAME] */
9847 if (argv_find(argv, argc, "vrf", &idx)) {
9848 name = argv[idx + 1]->arg;
9849 if (name && strmatch(name, VRF_DEFAULT_NAME))
9850 name = NULL;
9851 } else if (argv_find(argv, argc, "view", &idx))
9852 /* [<view> VIEWVRFNAME] */
9853 name = argv[idx + 1]->arg;
9854 if (name)
9855 bgp = bgp_lookup_by_name(name);
9856 else
9857 bgp = bgp_get_default();
9858
9859 if (!bgp) {
9860 vty_out(vty, "%% No BGP process is configured\n");
9861 return CMD_WARNING;
9862 }
9863 bgp_show_martian_nexthops(vty, bgp);
9864
9865 return CMD_SUCCESS;
9866 }
9867
9868 DEFUN (show_bgp_memory,
9869 show_bgp_memory_cmd,
9870 "show [ip] bgp memory",
9871 SHOW_STR
9872 IP_STR
9873 BGP_STR
9874 "Global BGP memory statistics\n")
9875 {
9876 char memstrbuf[MTYPE_MEMSTR_LEN];
9877 unsigned long count;
9878
9879 /* RIB related usage stats */
9880 count = mtype_stats_alloc(MTYPE_BGP_NODE);
9881 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
9882 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9883 count * sizeof(struct bgp_dest)));
9884
9885 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
9886 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
9887 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9888 count * sizeof(struct bgp_path_info)));
9889 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
9890 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
9891 count,
9892 mtype_memstr(
9893 memstrbuf, sizeof(memstrbuf),
9894 count * sizeof(struct bgp_path_info_extra)));
9895
9896 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
9897 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
9898 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9899 count * sizeof(struct bgp_static)));
9900
9901 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
9902 vty_out(vty, "%ld Packets, using %s of memory\n", count,
9903 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9904 count * sizeof(struct bpacket)));
9905
9906 /* Adj-In/Out */
9907 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
9908 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
9909 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9910 count * sizeof(struct bgp_adj_in)));
9911 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
9912 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
9913 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9914 count * sizeof(struct bgp_adj_out)));
9915
9916 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
9917 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
9918 count,
9919 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9920 count * sizeof(struct bgp_nexthop_cache)));
9921
9922 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
9923 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
9924 count,
9925 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9926 count * sizeof(struct bgp_damp_info)));
9927
9928 /* Attributes */
9929 count = attr_count();
9930 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
9931 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9932 count * sizeof(struct attr)));
9933
9934 if ((count = attr_unknown_count()))
9935 vty_out(vty, "%ld unknown attributes\n", count);
9936
9937 /* AS_PATH attributes */
9938 count = aspath_count();
9939 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
9940 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9941 count * sizeof(struct aspath)));
9942
9943 count = mtype_stats_alloc(MTYPE_AS_SEG);
9944 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
9945 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9946 count * sizeof(struct assegment)));
9947
9948 /* Other attributes */
9949 if ((count = community_count()))
9950 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
9951 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
9952 count * sizeof(struct community)));
9953 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
9954 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
9955 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
9956 count * sizeof(struct ecommunity)));
9957 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
9958 vty_out(vty,
9959 "%ld BGP large-community entries, using %s of memory\n",
9960 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
9961 count * sizeof(struct lcommunity)));
9962
9963 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
9964 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
9965 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9966 count * sizeof(struct cluster_list)));
9967
9968 /* Peer related usage */
9969 count = mtype_stats_alloc(MTYPE_BGP_PEER);
9970 vty_out(vty, "%ld peers, using %s of memory\n", count,
9971 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9972 count * sizeof(struct peer)));
9973
9974 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
9975 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
9976 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9977 count * sizeof(struct peer_group)));
9978
9979 /* Other */
9980 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
9981 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
9982 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
9983 count * sizeof(regex_t)));
9984 return CMD_SUCCESS;
9985 }
9986
9987 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
9988 {
9989 json_object *bestpath = json_object_new_object();
9990
9991 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
9992 json_object_string_add(bestpath, "asPath", "ignore");
9993
9994 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
9995 json_object_string_add(bestpath, "asPath", "confed");
9996
9997 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
9998 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
9999 json_object_string_add(bestpath, "multiPathRelax",
10000 "as-set");
10001 else
10002 json_object_string_add(bestpath, "multiPathRelax",
10003 "true");
10004 } else
10005 json_object_string_add(bestpath, "multiPathRelax", "false");
10006
10007 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
10008 json_object_boolean_true_add(bestpath, "peerTypeRelax");
10009
10010 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
10011 json_object_string_add(bestpath, "compareRouterId", "true");
10012 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
10013 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
10014 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
10015 json_object_string_add(bestpath, "med", "confed");
10016 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
10017 json_object_string_add(bestpath, "med",
10018 "missing-as-worst");
10019 else
10020 json_object_string_add(bestpath, "med", "true");
10021 }
10022
10023 json_object_object_add(json, "bestPath", bestpath);
10024 }
10025
10026 /* Print the error code/subcode for why the peer is down */
10027 static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
10028 json_object *json_peer, bool use_json)
10029 {
10030 const char *code_str;
10031 const char *subcode_str;
10032
10033 if (use_json) {
10034 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10035 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10036 char errorcodesubcode_hexstr[5];
10037 char errorcodesubcode_str[256];
10038
10039 code_str = bgp_notify_code_str(peer->notify.code);
10040 subcode_str = bgp_notify_subcode_str(
10041 peer->notify.code,
10042 peer->notify.subcode);
10043
10044 snprintf(errorcodesubcode_hexstr,
10045 sizeof(errorcodesubcode_hexstr), "%02X%02X",
10046 peer->notify.code, peer->notify.subcode);
10047 json_object_string_add(json_peer,
10048 "lastErrorCodeSubcode",
10049 errorcodesubcode_hexstr);
10050 snprintf(errorcodesubcode_str, 255, "%s%s",
10051 code_str, subcode_str);
10052 json_object_string_add(json_peer,
10053 "lastNotificationReason",
10054 errorcodesubcode_str);
10055 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10056 && peer->notify.code == BGP_NOTIFY_CEASE
10057 && (peer->notify.subcode
10058 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10059 || peer->notify.subcode
10060 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10061 && peer->notify.length) {
10062 char msgbuf[1024];
10063 const char *msg_str;
10064
10065 msg_str = bgp_notify_admin_message(
10066 msgbuf, sizeof(msgbuf),
10067 (uint8_t *)peer->notify.data,
10068 peer->notify.length);
10069 if (msg_str)
10070 json_object_string_add(
10071 json_peer,
10072 "lastShutdownDescription",
10073 msg_str);
10074 }
10075
10076 }
10077 json_object_string_add(json_peer, "lastResetDueTo",
10078 peer_down_str[(int)peer->last_reset]);
10079 json_object_int_add(json_peer, "lastResetCode",
10080 peer->last_reset);
10081 } else {
10082 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10083 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10084 code_str = bgp_notify_code_str(peer->notify.code);
10085 subcode_str =
10086 bgp_notify_subcode_str(peer->notify.code,
10087 peer->notify.subcode);
10088 vty_out(vty, " Notification %s (%s%s)\n",
10089 peer->last_reset == PEER_DOWN_NOTIFY_SEND
10090 ? "sent"
10091 : "received",
10092 code_str, subcode_str);
10093 } else {
10094 vty_out(vty, " %s\n",
10095 peer_down_str[(int)peer->last_reset]);
10096 }
10097 }
10098 }
10099
10100 static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
10101 safi_t safi)
10102 {
10103 return ((!peer_established(peer)) || !peer->afc_recv[afi][safi]);
10104 }
10105
10106 static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
10107 struct peer *peer, json_object *json_peer,
10108 int max_neighbor_width, bool use_json)
10109 {
10110 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10111 int len;
10112
10113 if (use_json) {
10114 if (peer_dynamic_neighbor(peer))
10115 json_object_boolean_true_add(json_peer,
10116 "dynamicPeer");
10117 if (peer->hostname)
10118 json_object_string_add(json_peer, "hostname",
10119 peer->hostname);
10120
10121 if (peer->domainname)
10122 json_object_string_add(json_peer, "domainname",
10123 peer->domainname);
10124 json_object_int_add(json_peer, "connectionsEstablished",
10125 peer->established);
10126 json_object_int_add(json_peer, "connectionsDropped",
10127 peer->dropped);
10128 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10129 use_json, json_peer);
10130 if (peer_established(peer))
10131 json_object_string_add(json_peer, "lastResetDueTo",
10132 "AFI/SAFI Not Negotiated");
10133 else
10134 bgp_show_peer_reset(NULL, peer, json_peer, true);
10135 } else {
10136 dn_flag[1] = '\0';
10137 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
10138 if (peer->hostname
10139 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
10140 len = vty_out(vty, "%s%s(%s)", dn_flag,
10141 peer->hostname, peer->host);
10142 else
10143 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10144
10145 /* pad the neighbor column with spaces */
10146 if (len < max_neighbor_width)
10147 vty_out(vty, "%*s", max_neighbor_width - len,
10148 " ");
10149 vty_out(vty, "%7d %7d %9s", peer->established,
10150 peer->dropped,
10151 peer_uptime(peer->uptime, timebuf,
10152 BGP_UPTIME_LEN, 0, NULL));
10153 if (peer_established(peer))
10154 vty_out(vty, " AFI/SAFI Not Negotiated\n");
10155 else
10156 bgp_show_peer_reset(vty, peer, NULL,
10157 false);
10158 }
10159 }
10160
10161 /* Strip peer's description to the given size. */
10162 static char *bgp_peer_description_stripped(char *desc, uint32_t size)
10163 {
10164 static char stripped[BUFSIZ];
10165 uint32_t len = size > strlen(desc) ? strlen(desc) : size;
10166
10167 strlcpy(stripped, desc, len + 1);
10168
10169 return stripped;
10170 }
10171
10172 /* Determine whether var peer should be filtered out of the summary. */
10173 static bool bgp_show_summary_is_peer_filtered(struct peer *peer,
10174 struct peer *fpeer, int as_type,
10175 as_t as)
10176 {
10177
10178 /* filter neighbor XXXX */
10179 if (fpeer && fpeer != peer)
10180 return true;
10181
10182 /* filter remote-as (internal|external) */
10183 if (as_type != AS_UNSPECIFIED) {
10184 if (peer->as_type == AS_SPECIFIED) {
10185 if (as_type == AS_INTERNAL) {
10186 if (peer->as != peer->local_as)
10187 return true;
10188 } else if (peer->as == peer->local_as)
10189 return true;
10190 } else if (as_type != peer->as_type)
10191 return true;
10192 } else if (as && as != peer->as) /* filter remote-as XXX */
10193 return true;
10194
10195 return false;
10196 }
10197
10198 /* Show BGP peer's summary information.
10199 *
10200 * Peer's description is stripped according to if `wide` option is given
10201 * or not.
10202 *
10203 * When adding new columns to `show bgp summary` output, please make
10204 * sure `Desc` is the lastest column to show because it can contain
10205 * whitespaces and the whole output will be tricky.
10206 */
10207 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
10208 struct peer *fpeer, int as_type, as_t as,
10209 uint16_t show_flags)
10210 {
10211 struct peer *peer;
10212 struct listnode *node, *nnode;
10213 unsigned int count = 0, dn_count = 0;
10214 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10215 char neighbor_buf[VTY_BUFSIZ];
10216 int neighbor_col_default_width = 16;
10217 int len, failed_count = 0;
10218 unsigned int filtered_count = 0;
10219 int max_neighbor_width = 0;
10220 int pfx_rcd_safi;
10221 json_object *json = NULL;
10222 json_object *json_peer = NULL;
10223 json_object *json_peers = NULL;
10224 struct peer_af *paf;
10225 struct bgp_filter *filter;
10226 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
10227 bool show_failed = CHECK_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
10228 bool show_established =
10229 CHECK_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
10230 bool show_wide = CHECK_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
10231 bool show_terse = CHECK_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
10232
10233 /* labeled-unicast routes are installed in the unicast table so in order
10234 * to
10235 * display the correct PfxRcd value we must look at SAFI_UNICAST
10236 */
10237
10238 if (safi == SAFI_LABELED_UNICAST)
10239 pfx_rcd_safi = SAFI_UNICAST;
10240 else
10241 pfx_rcd_safi = safi;
10242
10243 if (use_json) {
10244 json = json_object_new_object();
10245 json_peers = json_object_new_object();
10246 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10247 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10248 as_type, as)) {
10249 filtered_count++;
10250 count++;
10251 continue;
10252 }
10253
10254 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10255 continue;
10256
10257 if (peer->afc[afi][safi]) {
10258 /* See if we have at least a single failed peer */
10259 if (bgp_has_peer_failed(peer, afi, safi))
10260 failed_count++;
10261 count++;
10262 }
10263 if (peer_dynamic_neighbor(peer))
10264 dn_count++;
10265 }
10266
10267 } else {
10268 /* Loop over all neighbors that will be displayed to determine
10269 * how many
10270 * characters are needed for the Neighbor column
10271 */
10272 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10273 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10274 as_type, as)) {
10275 filtered_count++;
10276 count++;
10277 continue;
10278 }
10279
10280 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10281 continue;
10282
10283 if (peer->afc[afi][safi]) {
10284 memset(dn_flag, '\0', sizeof(dn_flag));
10285 if (peer_dynamic_neighbor(peer))
10286 dn_flag[0] = '*';
10287
10288 if (peer->hostname
10289 && CHECK_FLAG(bgp->flags,
10290 BGP_FLAG_SHOW_HOSTNAME))
10291 snprintf(neighbor_buf,
10292 sizeof(neighbor_buf),
10293 "%s%s(%s) ", dn_flag,
10294 peer->hostname, peer->host);
10295 else
10296 snprintf(neighbor_buf,
10297 sizeof(neighbor_buf), "%s%s ",
10298 dn_flag, peer->host);
10299
10300 len = strlen(neighbor_buf);
10301
10302 if (len > max_neighbor_width)
10303 max_neighbor_width = len;
10304
10305 /* See if we have at least a single failed peer */
10306 if (bgp_has_peer_failed(peer, afi, safi))
10307 failed_count++;
10308 count++;
10309 }
10310 }
10311
10312 /* Originally we displayed the Neighbor column as 16
10313 * characters wide so make that the default
10314 */
10315 if (max_neighbor_width < neighbor_col_default_width)
10316 max_neighbor_width = neighbor_col_default_width;
10317 }
10318
10319 if (show_failed && !failed_count) {
10320 if (use_json) {
10321 json_object_int_add(json, "failedPeersCount", 0);
10322 json_object_int_add(json, "dynamicPeers", dn_count);
10323 json_object_int_add(json, "totalPeers", count);
10324
10325 vty_json(vty, json);
10326 } else {
10327 vty_out(vty, "%% No failed BGP neighbors found\n");
10328 }
10329 return CMD_SUCCESS;
10330 }
10331
10332 count = 0; /* Reset the value as its used again */
10333 filtered_count = 0;
10334 dn_count = 0;
10335 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10336 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10337 continue;
10338
10339 if (!peer->afc[afi][safi])
10340 continue;
10341
10342 if (!count) {
10343 unsigned long ents;
10344 char memstrbuf[MTYPE_MEMSTR_LEN];
10345 int64_t vrf_id_ui;
10346
10347 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10348 ? -1
10349 : (int64_t)bgp->vrf_id;
10350
10351 /* Usage summary and header */
10352 if (use_json) {
10353 json_object_string_addf(json, "routerId",
10354 "%pI4",
10355 &bgp->router_id);
10356 json_object_int_add(json, "as", bgp->as);
10357 json_object_int_add(json, "vrfId", vrf_id_ui);
10358 json_object_string_add(
10359 json, "vrfName",
10360 (bgp->inst_type
10361 == BGP_INSTANCE_TYPE_DEFAULT)
10362 ? VRF_DEFAULT_NAME
10363 : bgp->name);
10364 } else {
10365 vty_out(vty,
10366 "BGP router identifier %pI4, local AS number %u vrf-id %d",
10367 &bgp->router_id, bgp->as,
10368 bgp->vrf_id == VRF_UNKNOWN
10369 ? -1
10370 : (int)bgp->vrf_id);
10371 vty_out(vty, "\n");
10372 }
10373
10374 if (bgp_update_delay_configured(bgp)) {
10375 if (use_json) {
10376 json_object_int_add(
10377 json, "updateDelayLimit",
10378 bgp->v_update_delay);
10379
10380 if (bgp->v_update_delay
10381 != bgp->v_establish_wait)
10382 json_object_int_add(
10383 json,
10384 "updateDelayEstablishWait",
10385 bgp->v_establish_wait);
10386
10387 if (bgp_update_delay_active(bgp)) {
10388 json_object_string_add(
10389 json,
10390 "updateDelayFirstNeighbor",
10391 bgp->update_delay_begin_time);
10392 json_object_boolean_true_add(
10393 json,
10394 "updateDelayInProgress");
10395 } else {
10396 if (bgp->update_delay_over) {
10397 json_object_string_add(
10398 json,
10399 "updateDelayFirstNeighbor",
10400 bgp->update_delay_begin_time);
10401 json_object_string_add(
10402 json,
10403 "updateDelayBestpathResumed",
10404 bgp->update_delay_end_time);
10405 json_object_string_add(
10406 json,
10407 "updateDelayZebraUpdateResume",
10408 bgp->update_delay_zebra_resume_time);
10409 json_object_string_add(
10410 json,
10411 "updateDelayPeerUpdateResume",
10412 bgp->update_delay_peers_resume_time);
10413 }
10414 }
10415 } else {
10416 vty_out(vty,
10417 "Read-only mode update-delay limit: %d seconds\n",
10418 bgp->v_update_delay);
10419 if (bgp->v_update_delay
10420 != bgp->v_establish_wait)
10421 vty_out(vty,
10422 " Establish wait: %d seconds\n",
10423 bgp->v_establish_wait);
10424
10425 if (bgp_update_delay_active(bgp)) {
10426 vty_out(vty,
10427 " First neighbor established: %s\n",
10428 bgp->update_delay_begin_time);
10429 vty_out(vty,
10430 " Delay in progress\n");
10431 } else {
10432 if (bgp->update_delay_over) {
10433 vty_out(vty,
10434 " First neighbor established: %s\n",
10435 bgp->update_delay_begin_time);
10436 vty_out(vty,
10437 " Best-paths resumed: %s\n",
10438 bgp->update_delay_end_time);
10439 vty_out(vty,
10440 " zebra update resumed: %s\n",
10441 bgp->update_delay_zebra_resume_time);
10442 vty_out(vty,
10443 " peers update resumed: %s\n",
10444 bgp->update_delay_peers_resume_time);
10445 }
10446 }
10447 }
10448 }
10449
10450 if (use_json) {
10451 if (bgp_maxmed_onstartup_configured(bgp)
10452 && bgp->maxmed_active)
10453 json_object_boolean_true_add(
10454 json, "maxMedOnStartup");
10455 if (bgp->v_maxmed_admin)
10456 json_object_boolean_true_add(
10457 json, "maxMedAdministrative");
10458
10459 json_object_int_add(
10460 json, "tableVersion",
10461 bgp_table_version(bgp->rib[afi][safi]));
10462
10463 ents = bgp_table_count(bgp->rib[afi][safi]);
10464 json_object_int_add(json, "ribCount", ents);
10465 json_object_int_add(
10466 json, "ribMemory",
10467 ents * sizeof(struct bgp_dest));
10468
10469 ents = bgp->af_peer_count[afi][safi];
10470 json_object_int_add(json, "peerCount", ents);
10471 json_object_int_add(json, "peerMemory",
10472 ents * sizeof(struct peer));
10473
10474 if ((ents = listcount(bgp->group))) {
10475 json_object_int_add(
10476 json, "peerGroupCount", ents);
10477 json_object_int_add(
10478 json, "peerGroupMemory",
10479 ents * sizeof(struct
10480 peer_group));
10481 }
10482
10483 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10484 BGP_CONFIG_DAMPENING))
10485 json_object_boolean_true_add(
10486 json, "dampeningEnabled");
10487 } else {
10488 if (!show_terse) {
10489 if (bgp_maxmed_onstartup_configured(bgp)
10490 && bgp->maxmed_active)
10491 vty_out(vty,
10492 "Max-med on-startup active\n");
10493 if (bgp->v_maxmed_admin)
10494 vty_out(vty,
10495 "Max-med administrative active\n");
10496
10497 vty_out(vty,
10498 "BGP table version %" PRIu64
10499 "\n",
10500 bgp_table_version(
10501 bgp->rib[afi][safi]));
10502
10503 ents = bgp_table_count(
10504 bgp->rib[afi][safi]);
10505 vty_out(vty,
10506 "RIB entries %ld, using %s of memory\n",
10507 ents,
10508 mtype_memstr(
10509 memstrbuf,
10510 sizeof(memstrbuf),
10511 ents
10512 * sizeof(
10513 struct
10514 bgp_dest)));
10515
10516 /* Peer related usage */
10517 ents = bgp->af_peer_count[afi][safi];
10518 vty_out(vty,
10519 "Peers %ld, using %s of memory\n",
10520 ents,
10521 mtype_memstr(
10522 memstrbuf,
10523 sizeof(memstrbuf),
10524 ents
10525 * sizeof(
10526 struct
10527 peer)));
10528
10529 if ((ents = listcount(bgp->group)))
10530 vty_out(vty,
10531 "Peer groups %ld, using %s of memory\n",
10532 ents,
10533 mtype_memstr(
10534 memstrbuf,
10535 sizeof(memstrbuf),
10536 ents
10537 * sizeof(
10538 struct
10539 peer_group)));
10540
10541 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10542 BGP_CONFIG_DAMPENING))
10543 vty_out(vty,
10544 "Dampening enabled.\n");
10545 }
10546 if (show_failed) {
10547 vty_out(vty, "\n");
10548
10549 /* Subtract 8 here because 'Neighbor' is
10550 * 8 characters */
10551 vty_out(vty, "Neighbor");
10552 vty_out(vty, "%*s",
10553 max_neighbor_width - 8, " ");
10554 vty_out(vty,
10555 BGP_SHOW_SUMMARY_HEADER_FAILED);
10556 }
10557 }
10558 }
10559
10560 paf = peer_af_find(peer, afi, safi);
10561 filter = &peer->filter[afi][safi];
10562
10563 count++;
10564 /* Works for both failed & successful cases */
10565 if (peer_dynamic_neighbor(peer))
10566 dn_count++;
10567
10568 if (use_json) {
10569 json_peer = NULL;
10570 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10571 as_type, as)) {
10572 filtered_count++;
10573 continue;
10574 }
10575 if (show_failed &&
10576 bgp_has_peer_failed(peer, afi, safi)) {
10577 json_peer = json_object_new_object();
10578 bgp_show_failed_summary(vty, bgp, peer,
10579 json_peer, 0, use_json);
10580 } else if (!show_failed) {
10581 if (show_established
10582 && bgp_has_peer_failed(peer, afi, safi)) {
10583 filtered_count++;
10584 continue;
10585 }
10586
10587 json_peer = json_object_new_object();
10588 if (peer_dynamic_neighbor(peer)) {
10589 json_object_boolean_true_add(json_peer,
10590 "dynamicPeer");
10591 }
10592
10593 if (peer->hostname)
10594 json_object_string_add(json_peer, "hostname",
10595 peer->hostname);
10596
10597 if (peer->domainname)
10598 json_object_string_add(json_peer, "domainname",
10599 peer->domainname);
10600
10601 json_object_int_add(json_peer, "remoteAs", peer->as);
10602 json_object_int_add(
10603 json_peer, "localAs",
10604 peer->change_local_as
10605 ? peer->change_local_as
10606 : peer->local_as);
10607 json_object_int_add(json_peer, "version", 4);
10608 json_object_int_add(json_peer, "msgRcvd",
10609 PEER_TOTAL_RX(peer));
10610 json_object_int_add(json_peer, "msgSent",
10611 PEER_TOTAL_TX(peer));
10612
10613 atomic_size_t outq_count, inq_count;
10614 outq_count = atomic_load_explicit(
10615 &peer->obuf->count,
10616 memory_order_relaxed);
10617 inq_count = atomic_load_explicit(
10618 &peer->ibuf->count,
10619 memory_order_relaxed);
10620
10621 json_object_int_add(json_peer, "tableVersion",
10622 peer->version[afi][safi]);
10623 json_object_int_add(json_peer, "outq",
10624 outq_count);
10625 json_object_int_add(json_peer, "inq",
10626 inq_count);
10627 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10628 use_json, json_peer);
10629
10630 json_object_int_add(json_peer, "pfxRcd",
10631 peer->pcount[afi][pfx_rcd_safi]);
10632
10633 if (paf && PAF_SUBGRP(paf))
10634 json_object_int_add(
10635 json_peer, "pfxSnt",
10636 (PAF_SUBGRP(paf))->scount);
10637 else
10638 json_object_int_add(json_peer, "pfxSnt",
10639 0);
10640
10641 /* BGP FSM state */
10642 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
10643 || CHECK_FLAG(peer->bgp->flags,
10644 BGP_FLAG_SHUTDOWN))
10645 json_object_string_add(json_peer,
10646 "state",
10647 "Idle (Admin)");
10648 else if (peer->afc_recv[afi][safi])
10649 json_object_string_add(
10650 json_peer, "state",
10651 lookup_msg(bgp_status_msg,
10652 peer->status, NULL));
10653 else if (CHECK_FLAG(
10654 peer->sflags,
10655 PEER_STATUS_PREFIX_OVERFLOW))
10656 json_object_string_add(json_peer,
10657 "state",
10658 "Idle (PfxCt)");
10659 else
10660 json_object_string_add(
10661 json_peer, "state",
10662 lookup_msg(bgp_status_msg,
10663 peer->status, NULL));
10664
10665 /* BGP peer state */
10666 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
10667 || CHECK_FLAG(peer->bgp->flags,
10668 BGP_FLAG_SHUTDOWN))
10669 json_object_string_add(json_peer,
10670 "peerState",
10671 "Admin");
10672 else if (CHECK_FLAG(
10673 peer->sflags,
10674 PEER_STATUS_PREFIX_OVERFLOW))
10675 json_object_string_add(json_peer,
10676 "peerState",
10677 "PfxCt");
10678 else if (CHECK_FLAG(peer->flags,
10679 PEER_FLAG_PASSIVE))
10680 json_object_string_add(json_peer,
10681 "peerState",
10682 "Passive");
10683 else if (CHECK_FLAG(peer->sflags,
10684 PEER_STATUS_NSF_WAIT))
10685 json_object_string_add(json_peer,
10686 "peerState",
10687 "NSF passive");
10688 else if (CHECK_FLAG(
10689 peer->bgp->flags,
10690 BGP_FLAG_EBGP_REQUIRES_POLICY)
10691 && (!bgp_inbound_policy_exists(peer,
10692 filter)
10693 || !bgp_outbound_policy_exists(
10694 peer, filter)))
10695 json_object_string_add(json_peer,
10696 "peerState",
10697 "Policy");
10698 else
10699 json_object_string_add(
10700 json_peer, "peerState", "OK");
10701
10702 json_object_int_add(json_peer, "connectionsEstablished",
10703 peer->established);
10704 json_object_int_add(json_peer, "connectionsDropped",
10705 peer->dropped);
10706 if (peer->desc)
10707 json_object_string_add(
10708 json_peer, "desc", peer->desc);
10709 }
10710 /* Avoid creating empty peer dicts in JSON */
10711 if (json_peer == NULL)
10712 continue;
10713
10714 if (peer->conf_if)
10715 json_object_string_add(json_peer, "idType",
10716 "interface");
10717 else if (peer->su.sa.sa_family == AF_INET)
10718 json_object_string_add(json_peer, "idType",
10719 "ipv4");
10720 else if (peer->su.sa.sa_family == AF_INET6)
10721 json_object_string_add(json_peer, "idType",
10722 "ipv6");
10723 json_object_object_add(json_peers, peer->host,
10724 json_peer);
10725 } else {
10726 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10727 as_type, as)) {
10728 filtered_count++;
10729 continue;
10730 }
10731 if (show_failed &&
10732 bgp_has_peer_failed(peer, afi, safi)) {
10733 bgp_show_failed_summary(vty, bgp, peer, NULL,
10734 max_neighbor_width,
10735 use_json);
10736 } else if (!show_failed) {
10737 if (show_established
10738 && bgp_has_peer_failed(peer, afi, safi)) {
10739 filtered_count++;
10740 continue;
10741 }
10742
10743 if ((count - filtered_count) == 1) {
10744 /* display headline before the first
10745 * neighbor line */
10746 vty_out(vty, "\n");
10747
10748 /* Subtract 8 here because 'Neighbor' is
10749 * 8 characters */
10750 vty_out(vty, "Neighbor");
10751 vty_out(vty, "%*s",
10752 max_neighbor_width - 8, " ");
10753 vty_out(vty,
10754 show_wide
10755 ? BGP_SHOW_SUMMARY_HEADER_ALL_WIDE
10756 : BGP_SHOW_SUMMARY_HEADER_ALL);
10757 }
10758
10759 memset(dn_flag, '\0', sizeof(dn_flag));
10760 if (peer_dynamic_neighbor(peer)) {
10761 dn_flag[0] = '*';
10762 }
10763
10764 if (peer->hostname
10765 && CHECK_FLAG(bgp->flags,
10766 BGP_FLAG_SHOW_HOSTNAME))
10767 len = vty_out(vty, "%s%s(%s)", dn_flag,
10768 peer->hostname,
10769 peer->host);
10770 else
10771 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10772
10773 /* pad the neighbor column with spaces */
10774 if (len < max_neighbor_width)
10775 vty_out(vty, "%*s", max_neighbor_width - len,
10776 " ");
10777
10778 atomic_size_t outq_count, inq_count;
10779 outq_count = atomic_load_explicit(
10780 &peer->obuf->count,
10781 memory_order_relaxed);
10782 inq_count = atomic_load_explicit(
10783 &peer->ibuf->count,
10784 memory_order_relaxed);
10785
10786 if (show_wide)
10787 vty_out(vty,
10788 "4 %10u %10u %9u %9u %8" PRIu64
10789 " %4zu %4zu %8s",
10790 peer->as,
10791 peer->change_local_as
10792 ? peer->change_local_as
10793 : peer->local_as,
10794 PEER_TOTAL_RX(peer),
10795 PEER_TOTAL_TX(peer),
10796 peer->version[afi][safi],
10797 inq_count, outq_count,
10798 peer_uptime(peer->uptime,
10799 timebuf,
10800 BGP_UPTIME_LEN, 0,
10801 NULL));
10802 else
10803 vty_out(vty, "4 %10u %9u %9u %8" PRIu64
10804 " %4zu %4zu %8s",
10805 peer->as, PEER_TOTAL_RX(peer),
10806 PEER_TOTAL_TX(peer),
10807 peer->version[afi][safi],
10808 inq_count, outq_count,
10809 peer_uptime(peer->uptime,
10810 timebuf,
10811 BGP_UPTIME_LEN, 0,
10812 NULL));
10813
10814 if (peer_established(peer)) {
10815 if (peer->afc_recv[afi][safi]) {
10816 if (CHECK_FLAG(
10817 bgp->flags,
10818 BGP_FLAG_EBGP_REQUIRES_POLICY)
10819 && !bgp_inbound_policy_exists(
10820 peer, filter))
10821 vty_out(vty, " %12s",
10822 "(Policy)");
10823 else
10824 vty_out(vty,
10825 " %12u",
10826 peer->pcount
10827 [afi]
10828 [pfx_rcd_safi]);
10829 } else {
10830 vty_out(vty, " NoNeg");
10831 }
10832
10833 if (paf && PAF_SUBGRP(paf)) {
10834 if (CHECK_FLAG(
10835 bgp->flags,
10836 BGP_FLAG_EBGP_REQUIRES_POLICY)
10837 && !bgp_outbound_policy_exists(
10838 peer, filter))
10839 vty_out(vty, " %8s",
10840 "(Policy)");
10841 else
10842 vty_out(vty,
10843 " %8u",
10844 (PAF_SUBGRP(
10845 paf))
10846 ->scount);
10847 } else {
10848 vty_out(vty, " NoNeg");
10849 }
10850 } else {
10851 if (CHECK_FLAG(peer->flags,
10852 PEER_FLAG_SHUTDOWN)
10853 || CHECK_FLAG(peer->bgp->flags,
10854 BGP_FLAG_SHUTDOWN))
10855 vty_out(vty, " Idle (Admin)");
10856 else if (CHECK_FLAG(
10857 peer->sflags,
10858 PEER_STATUS_PREFIX_OVERFLOW))
10859 vty_out(vty, " Idle (PfxCt)");
10860 else
10861 vty_out(vty, " %12s",
10862 lookup_msg(bgp_status_msg,
10863 peer->status, NULL));
10864
10865 vty_out(vty, " %8u", 0);
10866 }
10867 /* Make sure `Desc` column is the lastest in
10868 * the output.
10869 */
10870 if (peer->desc)
10871 vty_out(vty, " %s",
10872 bgp_peer_description_stripped(
10873 peer->desc,
10874 show_wide ? 64 : 20));
10875 else
10876 vty_out(vty, " N/A");
10877 vty_out(vty, "\n");
10878 }
10879
10880 }
10881 }
10882
10883 if (use_json) {
10884 json_object_object_add(json, "peers", json_peers);
10885 json_object_int_add(json, "failedPeers", failed_count);
10886 json_object_int_add(json, "displayedPeers",
10887 count - filtered_count);
10888 json_object_int_add(json, "totalPeers", count);
10889 json_object_int_add(json, "dynamicPeers", dn_count);
10890
10891 if (!show_failed)
10892 bgp_show_bestpath_json(bgp, json);
10893
10894 vty_json(vty, json);
10895 } else {
10896 if (count) {
10897 if (filtered_count == count)
10898 vty_out(vty, "\n%% No matching neighbor\n");
10899 else {
10900 if (show_failed)
10901 vty_out(vty, "\nDisplayed neighbors %d",
10902 failed_count);
10903 else if (as_type != AS_UNSPECIFIED || as
10904 || fpeer || show_established)
10905 vty_out(vty, "\nDisplayed neighbors %d",
10906 count - filtered_count);
10907
10908 vty_out(vty, "\nTotal number of neighbors %d\n",
10909 count);
10910 }
10911 } else {
10912 vty_out(vty, "No %s neighbor is configured\n",
10913 get_afi_safi_str(afi, safi, false));
10914 }
10915
10916 if (dn_count) {
10917 vty_out(vty, "* - dynamic neighbor\n");
10918 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
10919 dn_count, bgp->dynamic_neighbors_limit);
10920 }
10921 }
10922
10923 return CMD_SUCCESS;
10924 }
10925
10926 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
10927 int safi, struct peer *fpeer, int as_type,
10928 as_t as, uint16_t show_flags)
10929 {
10930 int is_first = 1;
10931 int afi_wildcard = (afi == AFI_MAX);
10932 int safi_wildcard = (safi == SAFI_MAX);
10933 int is_wildcard = (afi_wildcard || safi_wildcard);
10934 bool nbr_output = false;
10935 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
10936
10937 if (use_json && is_wildcard)
10938 vty_out(vty, "{\n");
10939 if (afi_wildcard)
10940 afi = 1; /* AFI_IP */
10941 while (afi < AFI_MAX) {
10942 if (safi_wildcard)
10943 safi = 1; /* SAFI_UNICAST */
10944 while (safi < SAFI_MAX) {
10945 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
10946 nbr_output = true;
10947
10948 if (is_wildcard) {
10949 /*
10950 * So limit output to those afi/safi
10951 * pairs that
10952 * actualy have something interesting in
10953 * them
10954 */
10955 if (use_json) {
10956 if (!is_first)
10957 vty_out(vty, ",\n");
10958 else
10959 is_first = 0;
10960
10961 vty_out(vty, "\"%s\":",
10962 get_afi_safi_str(afi,
10963 safi,
10964 true));
10965 } else {
10966 vty_out(vty,
10967 "\n%s Summary (%s):\n",
10968 get_afi_safi_str(afi,
10969 safi,
10970 false),
10971 bgp->name_pretty);
10972 }
10973 }
10974 bgp_show_summary(vty, bgp, afi, safi, fpeer,
10975 as_type, as, show_flags);
10976 }
10977 safi++;
10978 if (!safi_wildcard)
10979 safi = SAFI_MAX;
10980 }
10981 afi++;
10982 if (!afi_wildcard)
10983 afi = AFI_MAX;
10984 }
10985
10986 if (use_json && is_wildcard)
10987 vty_out(vty, "}\n");
10988 else if (!nbr_output) {
10989 if (use_json)
10990 vty_out(vty, "{}\n");
10991 else
10992 vty_out(vty, "%% No BGP neighbors found in %s\n",
10993 bgp->name_pretty);
10994 }
10995 }
10996
10997 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
10998 safi_t safi,
10999 const char *neighbor,
11000 int as_type, as_t as,
11001 uint16_t show_flags)
11002 {
11003 struct listnode *node, *nnode;
11004 struct bgp *bgp;
11005 struct peer *fpeer = NULL;
11006 int is_first = 1;
11007 bool nbr_output = false;
11008 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11009
11010 if (use_json)
11011 vty_out(vty, "{\n");
11012
11013 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11014 nbr_output = true;
11015 if (use_json) {
11016 if (!is_first)
11017 vty_out(vty, ",\n");
11018 else
11019 is_first = 0;
11020
11021 vty_out(vty, "\"%s\":",
11022 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11023 ? VRF_DEFAULT_NAME
11024 : bgp->name);
11025 }
11026 if (neighbor) {
11027 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11028 use_json);
11029 if (!fpeer)
11030 continue;
11031 }
11032 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11033 as, show_flags);
11034 }
11035
11036 if (use_json)
11037 vty_out(vty, "}\n");
11038 else if (!nbr_output)
11039 vty_out(vty, "%% BGP instance not found\n");
11040 }
11041
11042 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
11043 safi_t safi, const char *neighbor, int as_type,
11044 as_t as, uint16_t show_flags)
11045 {
11046 struct bgp *bgp;
11047 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11048 struct peer *fpeer = NULL;
11049
11050 if (name) {
11051 if (strmatch(name, "all")) {
11052 bgp_show_all_instances_summary_vty(vty, afi, safi,
11053 neighbor, as_type,
11054 as, show_flags);
11055 return CMD_SUCCESS;
11056 } else {
11057 bgp = bgp_lookup_by_name(name);
11058
11059 if (!bgp) {
11060 if (use_json)
11061 vty_out(vty, "{}\n");
11062 else
11063 vty_out(vty,
11064 "%% BGP instance not found\n");
11065 return CMD_WARNING;
11066 }
11067
11068 if (neighbor) {
11069 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11070 use_json);
11071 if (!fpeer)
11072 return CMD_WARNING;
11073 }
11074 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer,
11075 as_type, as, show_flags);
11076 return CMD_SUCCESS;
11077 }
11078 }
11079
11080 bgp = bgp_get_default();
11081
11082 if (bgp) {
11083 if (neighbor) {
11084 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11085 use_json);
11086 if (!fpeer)
11087 return CMD_WARNING;
11088 }
11089 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11090 as, show_flags);
11091 } else {
11092 if (use_json)
11093 vty_out(vty, "{}\n");
11094 else
11095 vty_out(vty, "%% BGP instance not found\n");
11096 return CMD_WARNING;
11097 }
11098
11099 return CMD_SUCCESS;
11100 }
11101
11102 /* `show [ip] bgp summary' commands. */
11103 DEFPY(show_ip_bgp_summary, show_ip_bgp_summary_cmd,
11104 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [" BGP_AFI_CMD_STR
11105 " [" BGP_SAFI_WITH_LABEL_CMD_STR
11106 "]] [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]",
11107 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11108 BGP_SAFI_WITH_LABEL_HELP_STR
11109 "Display the entries for all address families\n"
11110 "Summary of BGP neighbor status\n"
11111 "Show only sessions in Established state\n"
11112 "Show only sessions not in Established state\n"
11113 "Show only the specified neighbor session\n"
11114 "Neighbor to display information about\n"
11115 "Neighbor to display information about\n"
11116 "Neighbor on BGP configured interface\n"
11117 "Show only the specified remote AS sessions\n"
11118 "AS number\n"
11119 "Internal (iBGP) AS sessions\n"
11120 "External (eBGP) AS sessions\n"
11121 "Shorten the information on BGP instances\n"
11122 "Increase table width for longer output\n" JSON_STR)
11123 {
11124 char *vrf = NULL;
11125 afi_t afi = AFI_MAX;
11126 safi_t safi = SAFI_MAX;
11127 as_t as = 0; /* 0 means AS filter not set */
11128 int as_type = AS_UNSPECIFIED;
11129 uint16_t show_flags = 0;
11130
11131 int idx = 0;
11132
11133 /* show [ip] bgp */
11134 if (!all && argv_find(argv, argc, "ip", &idx))
11135 afi = AFI_IP;
11136 /* [<vrf> VIEWVRFNAME] */
11137 if (argv_find(argv, argc, "vrf", &idx)) {
11138 vrf = argv[idx + 1]->arg;
11139 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11140 vrf = NULL;
11141 } else if (argv_find(argv, argc, "view", &idx))
11142 /* [<view> VIEWVRFNAME] */
11143 vrf = argv[idx + 1]->arg;
11144 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11145 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11146 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11147 }
11148
11149 if (argv_find(argv, argc, "failed", &idx))
11150 SET_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
11151
11152 if (argv_find(argv, argc, "established", &idx))
11153 SET_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
11154
11155 if (argv_find(argv, argc, "remote-as", &idx)) {
11156 if (argv[idx + 1]->arg[0] == 'i')
11157 as_type = AS_INTERNAL;
11158 else if (argv[idx + 1]->arg[0] == 'e')
11159 as_type = AS_EXTERNAL;
11160 else
11161 as = (as_t)atoi(argv[idx + 1]->arg);
11162 }
11163
11164 if (argv_find(argv, argc, "terse", &idx))
11165 SET_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
11166
11167 if (argv_find(argv, argc, "wide", &idx))
11168 SET_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
11169
11170 if (argv_find(argv, argc, "json", &idx))
11171 SET_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11172
11173 return bgp_show_summary_vty(vty, vrf, afi, safi, neighbor, as_type, as,
11174 show_flags);
11175 }
11176
11177 const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
11178 {
11179 if (for_json)
11180 return get_afi_safi_json_str(afi, safi);
11181 else
11182 return get_afi_safi_vty_str(afi, safi);
11183 }
11184
11185
11186 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
11187 afi_t afi, safi_t safi,
11188 uint16_t adv_smcap, uint16_t adv_rmcap,
11189 uint16_t rcv_smcap, uint16_t rcv_rmcap,
11190 bool use_json, json_object *json_pref)
11191 {
11192 /* Send-Mode */
11193 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11194 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
11195 if (use_json) {
11196 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11197 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11198 json_object_string_add(json_pref, "sendMode",
11199 "advertisedAndReceived");
11200 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11201 json_object_string_add(json_pref, "sendMode",
11202 "advertised");
11203 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11204 json_object_string_add(json_pref, "sendMode",
11205 "received");
11206 } else {
11207 vty_out(vty, " Send-mode: ");
11208 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11209 vty_out(vty, "advertised");
11210 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11211 vty_out(vty, "%sreceived",
11212 CHECK_FLAG(p->af_cap[afi][safi],
11213 adv_smcap)
11214 ? ", "
11215 : "");
11216 vty_out(vty, "\n");
11217 }
11218 }
11219
11220 /* Receive-Mode */
11221 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11222 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
11223 if (use_json) {
11224 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11225 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11226 json_object_string_add(json_pref, "recvMode",
11227 "advertisedAndReceived");
11228 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11229 json_object_string_add(json_pref, "recvMode",
11230 "advertised");
11231 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11232 json_object_string_add(json_pref, "recvMode",
11233 "received");
11234 } else {
11235 vty_out(vty, " Receive-mode: ");
11236 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11237 vty_out(vty, "advertised");
11238 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11239 vty_out(vty, "%sreceived",
11240 CHECK_FLAG(p->af_cap[afi][safi],
11241 adv_rmcap)
11242 ? ", "
11243 : "");
11244 vty_out(vty, "\n");
11245 }
11246 }
11247 }
11248
11249 static void bgp_show_neighnor_graceful_restart_rbit(struct vty *vty,
11250 struct peer *p,
11251 bool use_json,
11252 json_object *json)
11253 {
11254 bool rbit_status = false;
11255
11256 if (!use_json)
11257 vty_out(vty, "\n R bit: ");
11258
11259 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
11260 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
11261 && (peer_established(p))) {
11262
11263 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_BIT_RCV))
11264 rbit_status = true;
11265 else
11266 rbit_status = false;
11267 }
11268
11269 if (rbit_status) {
11270 if (use_json)
11271 json_object_boolean_true_add(json, "rBit");
11272 else
11273 vty_out(vty, "True\n");
11274 } else {
11275 if (use_json)
11276 json_object_boolean_false_add(json, "rBit");
11277 else
11278 vty_out(vty, "False\n");
11279 }
11280 }
11281
11282 static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
11283 struct peer *peer,
11284 bool use_json,
11285 json_object *json)
11286 {
11287 const char *mode = "NotApplicable";
11288
11289 if (!use_json)
11290 vty_out(vty, "\n Remote GR Mode: ");
11291
11292 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
11293 && (peer_established(peer))) {
11294
11295 if ((peer->nsf_af_count == 0)
11296 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11297
11298 mode = "Disable";
11299
11300 } else if (peer->nsf_af_count == 0
11301 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11302
11303 mode = "Helper";
11304
11305 } else if (peer->nsf_af_count != 0
11306 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11307
11308 mode = "Restart";
11309 }
11310 }
11311
11312 if (use_json) {
11313 json_object_string_add(json, "remoteGrMode", mode);
11314 } else
11315 vty_out(vty, mode, "\n");
11316 }
11317
11318 static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
11319 struct peer *p,
11320 bool use_json,
11321 json_object *json)
11322 {
11323 const char *mode = "Invalid";
11324
11325 if (!use_json)
11326 vty_out(vty, " Local GR Mode: ");
11327
11328 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
11329 mode = "Helper";
11330 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
11331 mode = "Restart";
11332 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
11333 mode = "Disable";
11334 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
11335 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
11336 mode = "Helper*";
11337 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
11338 mode = "Restart*";
11339 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
11340 mode = "Disable*";
11341 else
11342 mode = "Invalid*";
11343 }
11344
11345 if (use_json) {
11346 json_object_string_add(json, "localGrMode", mode);
11347 } else {
11348 vty_out(vty, mode, "\n");
11349 }
11350 }
11351
11352 static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
11353 struct vty *vty, struct peer *peer, bool use_json, json_object *json)
11354 {
11355 afi_t afi;
11356 safi_t safi;
11357 json_object *json_afi_safi = NULL;
11358 json_object *json_timer = NULL;
11359 json_object *json_endofrib_status = NULL;
11360 bool eor_flag = false;
11361
11362 FOREACH_AFI_SAFI_NSF (afi, safi) {
11363 if (!peer->afc[afi][safi])
11364 continue;
11365
11366 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV) ||
11367 !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
11368 continue;
11369
11370 if (use_json) {
11371 json_afi_safi = json_object_new_object();
11372 json_endofrib_status = json_object_new_object();
11373 json_timer = json_object_new_object();
11374 }
11375
11376 if (peer->eor_stime[afi][safi] >= peer->pkt_stime[afi][safi])
11377 eor_flag = true;
11378 else
11379 eor_flag = false;
11380
11381 if (!use_json) {
11382 vty_out(vty, " %s:\n",
11383 get_afi_safi_str(afi, safi, false));
11384
11385 vty_out(vty, " F bit: ");
11386 }
11387
11388 if (peer->nsf[afi][safi] &&
11389 CHECK_FLAG(peer->af_cap[afi][safi],
11390 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
11391
11392 if (use_json) {
11393 json_object_boolean_true_add(json_afi_safi,
11394 "fBit");
11395 } else
11396 vty_out(vty, "True\n");
11397 } else {
11398 if (use_json)
11399 json_object_boolean_false_add(json_afi_safi,
11400 "fBit");
11401 else
11402 vty_out(vty, "False\n");
11403 }
11404
11405 if (!use_json)
11406 vty_out(vty, " End-of-RIB sent: ");
11407
11408 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11409 PEER_STATUS_EOR_SEND)) {
11410 if (use_json) {
11411 json_object_boolean_true_add(
11412 json_endofrib_status, "endOfRibSend");
11413
11414 PRINT_EOR_JSON(eor_flag);
11415 } else {
11416 vty_out(vty, "Yes\n");
11417 vty_out(vty,
11418 " End-of-RIB sent after update: ");
11419
11420 PRINT_EOR(eor_flag);
11421 }
11422 } else {
11423 if (use_json) {
11424 json_object_boolean_false_add(
11425 json_endofrib_status, "endOfRibSend");
11426 json_object_boolean_false_add(
11427 json_endofrib_status,
11428 "endOfRibSentAfterUpdate");
11429 } else {
11430 vty_out(vty, "No\n");
11431 vty_out(vty,
11432 " End-of-RIB sent after update: ");
11433 vty_out(vty, "No\n");
11434 }
11435 }
11436
11437 if (!use_json)
11438 vty_out(vty, " End-of-RIB received: ");
11439
11440 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11441 PEER_STATUS_EOR_RECEIVED)) {
11442 if (use_json)
11443 json_object_boolean_true_add(
11444 json_endofrib_status, "endOfRibRecv");
11445 else
11446 vty_out(vty, "Yes\n");
11447 } else {
11448 if (use_json)
11449 json_object_boolean_false_add(
11450 json_endofrib_status, "endOfRibRecv");
11451 else
11452 vty_out(vty, "No\n");
11453 }
11454
11455 if (use_json) {
11456 json_object_int_add(json_timer, "stalePathTimer",
11457 peer->bgp->stalepath_time);
11458
11459 if (peer->t_gr_stale != NULL) {
11460 json_object_int_add(json_timer,
11461 "stalePathTimerRemaining",
11462 thread_timer_remain_second(
11463 peer->t_gr_stale));
11464 }
11465
11466 /* Display Configured Selection
11467 * Deferral only when when
11468 * Gr mode is enabled.
11469 */
11470 if (CHECK_FLAG(peer->flags,
11471 PEER_FLAG_GRACEFUL_RESTART)) {
11472 json_object_int_add(json_timer,
11473 "selectionDeferralTimer",
11474 peer->bgp->stalepath_time);
11475 }
11476
11477 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
11478 NULL) {
11479
11480 json_object_int_add(
11481 json_timer,
11482 "selectionDeferralTimerRemaining",
11483 thread_timer_remain_second(
11484 peer->bgp->gr_info[afi][safi]
11485 .t_select_deferral));
11486 }
11487 } else {
11488 vty_out(vty, " Timers:\n");
11489 vty_out(vty,
11490 " Configured Stale Path Time(sec): %u\n",
11491 peer->bgp->stalepath_time);
11492
11493 if (peer->t_gr_stale != NULL)
11494 vty_out(vty,
11495 " Stale Path Remaining(sec): %ld\n",
11496 thread_timer_remain_second(
11497 peer->t_gr_stale));
11498 /* Display Configured Selection
11499 * Deferral only when when
11500 * Gr mode is enabled.
11501 */
11502 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
11503 vty_out(vty,
11504 " Configured Selection Deferral Time(sec): %u\n",
11505 peer->bgp->select_defer_time);
11506
11507 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
11508 NULL)
11509 vty_out(vty,
11510 " Selection Deferral Time Remaining(sec): %ld\n",
11511 thread_timer_remain_second(
11512 peer->bgp->gr_info[afi][safi]
11513 .t_select_deferral));
11514 }
11515 if (use_json) {
11516 json_object_object_add(json_afi_safi, "endOfRibStatus",
11517 json_endofrib_status);
11518 json_object_object_add(json_afi_safi, "timers",
11519 json_timer);
11520 json_object_object_add(
11521 json, get_afi_safi_str(afi, safi, true),
11522 json_afi_safi);
11523 }
11524 }
11525 }
11526
11527 static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
11528 struct peer *p,
11529 bool use_json,
11530 json_object *json)
11531 {
11532 if (use_json) {
11533 json_object *json_timer = NULL;
11534
11535 json_timer = json_object_new_object();
11536
11537 json_object_int_add(json_timer, "configuredRestartTimer",
11538 p->bgp->restart_time);
11539
11540 json_object_int_add(json_timer, "receivedRestartTimer",
11541 p->v_gr_restart);
11542
11543 if (p->t_gr_restart != NULL)
11544 json_object_int_add(
11545 json_timer, "restartTimerRemaining",
11546 thread_timer_remain_second(p->t_gr_restart));
11547
11548 json_object_object_add(json, "timers", json_timer);
11549 } else {
11550
11551 vty_out(vty, " Timers:\n");
11552 vty_out(vty, " Configured Restart Time(sec): %u\n",
11553 p->bgp->restart_time);
11554
11555 vty_out(vty, " Received Restart Time(sec): %u\n",
11556 p->v_gr_restart);
11557 if (p->t_gr_restart != NULL)
11558 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
11559 thread_timer_remain_second(p->t_gr_restart));
11560 if (p->t_gr_restart != NULL) {
11561 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
11562 thread_timer_remain_second(p->t_gr_restart));
11563 }
11564 }
11565 }
11566
11567 static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
11568 bool use_json, json_object *json)
11569 {
11570 char buf[SU_ADDRSTRLEN] = {0};
11571 char dn_flag[2] = {0};
11572 /* '*' + v6 address of neighbor */
11573 char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
11574
11575 if (!p->conf_if && peer_dynamic_neighbor(p))
11576 dn_flag[0] = '*';
11577
11578 if (p->conf_if) {
11579 if (use_json)
11580 json_object_string_add(
11581 json, "neighborAddr",
11582 BGP_PEER_SU_UNSPEC(p)
11583 ? "none"
11584 : sockunion2str(&p->su, buf,
11585 SU_ADDRSTRLEN));
11586 else
11587 vty_out(vty, "BGP neighbor on %s: %s\n", p->conf_if,
11588 BGP_PEER_SU_UNSPEC(p)
11589 ? "none"
11590 : sockunion2str(&p->su, buf,
11591 SU_ADDRSTRLEN));
11592 } else {
11593 snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
11594 p->host);
11595
11596 if (use_json)
11597 json_object_string_add(json, "neighborAddr",
11598 neighborAddr);
11599 else
11600 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
11601 }
11602
11603 /* more gr info in new format */
11604 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json);
11605 }
11606
11607 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
11608 safi_t safi, bool use_json,
11609 json_object *json_neigh)
11610 {
11611 struct bgp_filter *filter;
11612 struct peer_af *paf;
11613 char orf_pfx_name[BUFSIZ];
11614 int orf_pfx_count;
11615 json_object *json_af = NULL;
11616 json_object *json_prefA = NULL;
11617 json_object *json_prefB = NULL;
11618 json_object *json_addr = NULL;
11619 json_object *json_advmap = NULL;
11620
11621 if (use_json) {
11622 json_addr = json_object_new_object();
11623 json_af = json_object_new_object();
11624 filter = &p->filter[afi][safi];
11625
11626 if (peer_group_active(p))
11627 json_object_string_add(json_addr, "peerGroupMember",
11628 p->group->name);
11629
11630 paf = peer_af_find(p, afi, safi);
11631 if (paf && PAF_SUBGRP(paf)) {
11632 json_object_int_add(json_addr, "updateGroupId",
11633 PAF_UPDGRP(paf)->id);
11634 json_object_int_add(json_addr, "subGroupId",
11635 PAF_SUBGRP(paf)->id);
11636 json_object_int_add(json_addr, "packetQueueLength",
11637 bpacket_queue_virtual_length(paf));
11638 }
11639
11640 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11641 || CHECK_FLAG(p->af_cap[afi][safi],
11642 PEER_CAP_ORF_PREFIX_SM_RCV)
11643 || CHECK_FLAG(p->af_cap[afi][safi],
11644 PEER_CAP_ORF_PREFIX_RM_ADV)
11645 || CHECK_FLAG(p->af_cap[afi][safi],
11646 PEER_CAP_ORF_PREFIX_RM_RCV)) {
11647 json_object_int_add(json_af, "orfType",
11648 ORF_TYPE_PREFIX);
11649 json_prefA = json_object_new_object();
11650 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
11651 PEER_CAP_ORF_PREFIX_SM_ADV,
11652 PEER_CAP_ORF_PREFIX_RM_ADV,
11653 PEER_CAP_ORF_PREFIX_SM_RCV,
11654 PEER_CAP_ORF_PREFIX_RM_RCV,
11655 use_json, json_prefA);
11656 json_object_object_add(json_af, "orfPrefixList",
11657 json_prefA);
11658 }
11659
11660 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11661 || CHECK_FLAG(p->af_cap[afi][safi],
11662 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11663 || CHECK_FLAG(p->af_cap[afi][safi],
11664 PEER_CAP_ORF_PREFIX_RM_ADV)
11665 || CHECK_FLAG(p->af_cap[afi][safi],
11666 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
11667 json_object_int_add(json_af, "orfOldType",
11668 ORF_TYPE_PREFIX_OLD);
11669 json_prefB = json_object_new_object();
11670 bgp_show_peer_afi_orf_cap(
11671 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
11672 PEER_CAP_ORF_PREFIX_RM_ADV,
11673 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
11674 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
11675 json_prefB);
11676 json_object_object_add(json_af, "orfOldPrefixList",
11677 json_prefB);
11678 }
11679
11680 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11681 || CHECK_FLAG(p->af_cap[afi][safi],
11682 PEER_CAP_ORF_PREFIX_SM_RCV)
11683 || CHECK_FLAG(p->af_cap[afi][safi],
11684 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11685 || CHECK_FLAG(p->af_cap[afi][safi],
11686 PEER_CAP_ORF_PREFIX_RM_ADV)
11687 || CHECK_FLAG(p->af_cap[afi][safi],
11688 PEER_CAP_ORF_PREFIX_RM_RCV)
11689 || CHECK_FLAG(p->af_cap[afi][safi],
11690 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
11691 json_object_object_add(json_addr, "afDependentCap",
11692 json_af);
11693 else
11694 json_object_free(json_af);
11695
11696 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
11697 p->host, afi, safi);
11698 orf_pfx_count = prefix_bgp_show_prefix_list(
11699 NULL, afi, orf_pfx_name, use_json);
11700
11701 if (CHECK_FLAG(p->af_sflags[afi][safi],
11702 PEER_STATUS_ORF_PREFIX_SEND)
11703 || orf_pfx_count) {
11704 if (CHECK_FLAG(p->af_sflags[afi][safi],
11705 PEER_STATUS_ORF_PREFIX_SEND))
11706 json_object_boolean_true_add(json_neigh,
11707 "orfSent");
11708 if (orf_pfx_count)
11709 json_object_int_add(json_addr, "orfRecvCounter",
11710 orf_pfx_count);
11711 }
11712 if (CHECK_FLAG(p->af_sflags[afi][safi],
11713 PEER_STATUS_ORF_WAIT_REFRESH))
11714 json_object_string_add(
11715 json_addr, "orfFirstUpdate",
11716 "deferredUntilORFOrRouteRefreshRecvd");
11717
11718 if (CHECK_FLAG(p->af_flags[afi][safi],
11719 PEER_FLAG_REFLECTOR_CLIENT))
11720 json_object_boolean_true_add(json_addr,
11721 "routeReflectorClient");
11722 if (CHECK_FLAG(p->af_flags[afi][safi],
11723 PEER_FLAG_RSERVER_CLIENT))
11724 json_object_boolean_true_add(json_addr,
11725 "routeServerClient");
11726 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
11727 json_object_boolean_true_add(json_addr,
11728 "inboundSoftConfigPermit");
11729
11730 if (CHECK_FLAG(p->af_flags[afi][safi],
11731 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
11732 json_object_boolean_true_add(
11733 json_addr,
11734 "privateAsNumsAllReplacedInUpdatesToNbr");
11735 else if (CHECK_FLAG(p->af_flags[afi][safi],
11736 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
11737 json_object_boolean_true_add(
11738 json_addr,
11739 "privateAsNumsReplacedInUpdatesToNbr");
11740 else if (CHECK_FLAG(p->af_flags[afi][safi],
11741 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
11742 json_object_boolean_true_add(
11743 json_addr,
11744 "privateAsNumsAllRemovedInUpdatesToNbr");
11745 else if (CHECK_FLAG(p->af_flags[afi][safi],
11746 PEER_FLAG_REMOVE_PRIVATE_AS))
11747 json_object_boolean_true_add(
11748 json_addr,
11749 "privateAsNumsRemovedInUpdatesToNbr");
11750
11751 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
11752 json_object_boolean_true_add(
11753 json_addr,
11754 bgp_addpath_names(p->addpath_type[afi][safi])
11755 ->type_json_name);
11756
11757 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
11758 json_object_string_add(json_addr,
11759 "overrideASNsInOutboundUpdates",
11760 "ifAspathEqualRemoteAs");
11761
11762 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
11763 || CHECK_FLAG(p->af_flags[afi][safi],
11764 PEER_FLAG_FORCE_NEXTHOP_SELF))
11765 json_object_boolean_true_add(json_addr,
11766 "routerAlwaysNextHop");
11767 if (CHECK_FLAG(p->af_flags[afi][safi],
11768 PEER_FLAG_AS_PATH_UNCHANGED))
11769 json_object_boolean_true_add(
11770 json_addr, "unchangedAsPathPropogatedToNbr");
11771 if (CHECK_FLAG(p->af_flags[afi][safi],
11772 PEER_FLAG_NEXTHOP_UNCHANGED))
11773 json_object_boolean_true_add(
11774 json_addr, "unchangedNextHopPropogatedToNbr");
11775 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
11776 json_object_boolean_true_add(
11777 json_addr, "unchangedMedPropogatedToNbr");
11778 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
11779 || CHECK_FLAG(p->af_flags[afi][safi],
11780 PEER_FLAG_SEND_EXT_COMMUNITY)) {
11781 if (CHECK_FLAG(p->af_flags[afi][safi],
11782 PEER_FLAG_SEND_COMMUNITY)
11783 && CHECK_FLAG(p->af_flags[afi][safi],
11784 PEER_FLAG_SEND_EXT_COMMUNITY))
11785 json_object_string_add(json_addr,
11786 "commAttriSentToNbr",
11787 "extendedAndStandard");
11788 else if (CHECK_FLAG(p->af_flags[afi][safi],
11789 PEER_FLAG_SEND_EXT_COMMUNITY))
11790 json_object_string_add(json_addr,
11791 "commAttriSentToNbr",
11792 "extended");
11793 else
11794 json_object_string_add(json_addr,
11795 "commAttriSentToNbr",
11796 "standard");
11797 }
11798 if (CHECK_FLAG(p->af_flags[afi][safi],
11799 PEER_FLAG_DEFAULT_ORIGINATE)) {
11800 if (p->default_rmap[afi][safi].name)
11801 json_object_string_add(
11802 json_addr, "defaultRouteMap",
11803 p->default_rmap[afi][safi].name);
11804
11805 if (paf && PAF_SUBGRP(paf)
11806 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
11807 SUBGRP_STATUS_DEFAULT_ORIGINATE))
11808 json_object_boolean_true_add(json_addr,
11809 "defaultSent");
11810 else
11811 json_object_boolean_true_add(json_addr,
11812 "defaultNotSent");
11813 }
11814
11815 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
11816 if (is_evpn_enabled())
11817 json_object_boolean_true_add(
11818 json_addr, "advertiseAllVnis");
11819 }
11820
11821 if (filter->plist[FILTER_IN].name
11822 || filter->dlist[FILTER_IN].name
11823 || filter->aslist[FILTER_IN].name
11824 || filter->map[RMAP_IN].name)
11825 json_object_boolean_true_add(json_addr,
11826 "inboundPathPolicyConfig");
11827 if (filter->plist[FILTER_OUT].name
11828 || filter->dlist[FILTER_OUT].name
11829 || filter->aslist[FILTER_OUT].name
11830 || filter->map[RMAP_OUT].name || filter->usmap.name)
11831 json_object_boolean_true_add(
11832 json_addr, "outboundPathPolicyConfig");
11833
11834 /* prefix-list */
11835 if (filter->plist[FILTER_IN].name)
11836 json_object_string_add(json_addr,
11837 "incomingUpdatePrefixFilterList",
11838 filter->plist[FILTER_IN].name);
11839 if (filter->plist[FILTER_OUT].name)
11840 json_object_string_add(json_addr,
11841 "outgoingUpdatePrefixFilterList",
11842 filter->plist[FILTER_OUT].name);
11843
11844 /* distribute-list */
11845 if (filter->dlist[FILTER_IN].name)
11846 json_object_string_add(
11847 json_addr, "incomingUpdateNetworkFilterList",
11848 filter->dlist[FILTER_IN].name);
11849 if (filter->dlist[FILTER_OUT].name)
11850 json_object_string_add(
11851 json_addr, "outgoingUpdateNetworkFilterList",
11852 filter->dlist[FILTER_OUT].name);
11853
11854 /* filter-list. */
11855 if (filter->aslist[FILTER_IN].name)
11856 json_object_string_add(json_addr,
11857 "incomingUpdateAsPathFilterList",
11858 filter->aslist[FILTER_IN].name);
11859 if (filter->aslist[FILTER_OUT].name)
11860 json_object_string_add(json_addr,
11861 "outgoingUpdateAsPathFilterList",
11862 filter->aslist[FILTER_OUT].name);
11863
11864 /* route-map. */
11865 if (filter->map[RMAP_IN].name)
11866 json_object_string_add(
11867 json_addr, "routeMapForIncomingAdvertisements",
11868 filter->map[RMAP_IN].name);
11869 if (filter->map[RMAP_OUT].name)
11870 json_object_string_add(
11871 json_addr, "routeMapForOutgoingAdvertisements",
11872 filter->map[RMAP_OUT].name);
11873
11874 /* ebgp-requires-policy (inbound) */
11875 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
11876 && !bgp_inbound_policy_exists(p, filter))
11877 json_object_string_add(
11878 json_addr, "inboundEbgpRequiresPolicy",
11879 "Inbound updates discarded due to missing policy");
11880
11881 /* ebgp-requires-policy (outbound) */
11882 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
11883 && (!bgp_outbound_policy_exists(p, filter)))
11884 json_object_string_add(
11885 json_addr, "outboundEbgpRequiresPolicy",
11886 "Outbound updates discarded due to missing policy");
11887
11888 /* unsuppress-map */
11889 if (filter->usmap.name)
11890 json_object_string_add(json_addr,
11891 "selectiveUnsuppressRouteMap",
11892 filter->usmap.name);
11893
11894 /* advertise-map */
11895 if (filter->advmap.aname) {
11896 json_advmap = json_object_new_object();
11897 json_object_string_add(json_advmap, "condition",
11898 filter->advmap.condition
11899 ? "EXIST"
11900 : "NON_EXIST");
11901 json_object_string_add(json_advmap, "conditionMap",
11902 filter->advmap.cname);
11903 json_object_string_add(json_advmap, "advertiseMap",
11904 filter->advmap.aname);
11905 json_object_string_add(json_advmap, "advertiseStatus",
11906 filter->advmap.update_type
11907 == ADVERTISE
11908 ? "Advertise"
11909 : "Withdraw");
11910 json_object_object_add(json_addr, "advertiseMap",
11911 json_advmap);
11912 }
11913
11914 /* Receive prefix count */
11915 json_object_int_add(json_addr, "acceptedPrefixCounter",
11916 p->pcount[afi][safi]);
11917 if (paf && PAF_SUBGRP(paf))
11918 json_object_int_add(json_addr, "sentPrefixCounter",
11919 (PAF_SUBGRP(paf))->scount);
11920
11921 /* Maximum prefix */
11922 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
11923 json_object_int_add(json_addr, "prefixOutAllowedMax",
11924 p->pmax_out[afi][safi]);
11925
11926 /* Maximum prefix */
11927 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
11928 json_object_int_add(json_addr, "prefixAllowedMax",
11929 p->pmax[afi][safi]);
11930 if (CHECK_FLAG(p->af_flags[afi][safi],
11931 PEER_FLAG_MAX_PREFIX_WARNING))
11932 json_object_boolean_true_add(
11933 json_addr, "prefixAllowedMaxWarning");
11934 json_object_int_add(json_addr,
11935 "prefixAllowedWarningThresh",
11936 p->pmax_threshold[afi][safi]);
11937 if (p->pmax_restart[afi][safi])
11938 json_object_int_add(
11939 json_addr,
11940 "prefixAllowedRestartIntervalMsecs",
11941 p->pmax_restart[afi][safi] * 60000);
11942 }
11943 json_object_object_add(json_neigh,
11944 get_afi_safi_str(afi, safi, true),
11945 json_addr);
11946
11947 } else {
11948 filter = &p->filter[afi][safi];
11949
11950 vty_out(vty, " For address family: %s\n",
11951 get_afi_safi_str(afi, safi, false));
11952
11953 if (peer_group_active(p))
11954 vty_out(vty, " %s peer-group member\n",
11955 p->group->name);
11956
11957 paf = peer_af_find(p, afi, safi);
11958 if (paf && PAF_SUBGRP(paf)) {
11959 vty_out(vty, " Update group %" PRIu64", subgroup %" PRIu64 "\n",
11960 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
11961 vty_out(vty, " Packet Queue length %d\n",
11962 bpacket_queue_virtual_length(paf));
11963 } else {
11964 vty_out(vty, " Not part of any update group\n");
11965 }
11966 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11967 || CHECK_FLAG(p->af_cap[afi][safi],
11968 PEER_CAP_ORF_PREFIX_SM_RCV)
11969 || CHECK_FLAG(p->af_cap[afi][safi],
11970 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11971 || CHECK_FLAG(p->af_cap[afi][safi],
11972 PEER_CAP_ORF_PREFIX_RM_ADV)
11973 || CHECK_FLAG(p->af_cap[afi][safi],
11974 PEER_CAP_ORF_PREFIX_RM_RCV)
11975 || CHECK_FLAG(p->af_cap[afi][safi],
11976 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
11977 vty_out(vty, " AF-dependant capabilities:\n");
11978
11979 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11980 || CHECK_FLAG(p->af_cap[afi][safi],
11981 PEER_CAP_ORF_PREFIX_SM_RCV)
11982 || CHECK_FLAG(p->af_cap[afi][safi],
11983 PEER_CAP_ORF_PREFIX_RM_ADV)
11984 || CHECK_FLAG(p->af_cap[afi][safi],
11985 PEER_CAP_ORF_PREFIX_RM_RCV)) {
11986 vty_out(vty,
11987 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
11988 ORF_TYPE_PREFIX);
11989 bgp_show_peer_afi_orf_cap(
11990 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
11991 PEER_CAP_ORF_PREFIX_RM_ADV,
11992 PEER_CAP_ORF_PREFIX_SM_RCV,
11993 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
11994 }
11995 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11996 || CHECK_FLAG(p->af_cap[afi][safi],
11997 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11998 || CHECK_FLAG(p->af_cap[afi][safi],
11999 PEER_CAP_ORF_PREFIX_RM_ADV)
12000 || CHECK_FLAG(p->af_cap[afi][safi],
12001 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12002 vty_out(vty,
12003 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12004 ORF_TYPE_PREFIX_OLD);
12005 bgp_show_peer_afi_orf_cap(
12006 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12007 PEER_CAP_ORF_PREFIX_RM_ADV,
12008 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12009 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
12010 }
12011
12012 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12013 p->host, afi, safi);
12014 orf_pfx_count = prefix_bgp_show_prefix_list(
12015 NULL, afi, orf_pfx_name, use_json);
12016
12017 if (CHECK_FLAG(p->af_sflags[afi][safi],
12018 PEER_STATUS_ORF_PREFIX_SEND)
12019 || orf_pfx_count) {
12020 vty_out(vty, " Outbound Route Filter (ORF):");
12021 if (CHECK_FLAG(p->af_sflags[afi][safi],
12022 PEER_STATUS_ORF_PREFIX_SEND))
12023 vty_out(vty, " sent;");
12024 if (orf_pfx_count)
12025 vty_out(vty, " received (%d entries)",
12026 orf_pfx_count);
12027 vty_out(vty, "\n");
12028 }
12029 if (CHECK_FLAG(p->af_sflags[afi][safi],
12030 PEER_STATUS_ORF_WAIT_REFRESH))
12031 vty_out(vty,
12032 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
12033
12034 if (CHECK_FLAG(p->af_flags[afi][safi],
12035 PEER_FLAG_REFLECTOR_CLIENT))
12036 vty_out(vty, " Route-Reflector Client\n");
12037 if (CHECK_FLAG(p->af_flags[afi][safi],
12038 PEER_FLAG_RSERVER_CLIENT))
12039 vty_out(vty, " Route-Server Client\n");
12040 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12041 vty_out(vty,
12042 " Inbound soft reconfiguration allowed\n");
12043
12044 if (CHECK_FLAG(p->af_flags[afi][safi],
12045 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12046 vty_out(vty,
12047 " Private AS numbers (all) replaced in updates to this neighbor\n");
12048 else if (CHECK_FLAG(p->af_flags[afi][safi],
12049 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12050 vty_out(vty,
12051 " Private AS numbers replaced in updates to this neighbor\n");
12052 else if (CHECK_FLAG(p->af_flags[afi][safi],
12053 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12054 vty_out(vty,
12055 " Private AS numbers (all) removed in updates to this neighbor\n");
12056 else if (CHECK_FLAG(p->af_flags[afi][safi],
12057 PEER_FLAG_REMOVE_PRIVATE_AS))
12058 vty_out(vty,
12059 " Private AS numbers removed in updates to this neighbor\n");
12060
12061 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12062 vty_out(vty, " %s\n",
12063 bgp_addpath_names(p->addpath_type[afi][safi])
12064 ->human_description);
12065
12066 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12067 vty_out(vty,
12068 " Override ASNs in outbound updates if aspath equals remote-as\n");
12069
12070 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12071 || CHECK_FLAG(p->af_flags[afi][safi],
12072 PEER_FLAG_FORCE_NEXTHOP_SELF))
12073 vty_out(vty, " NEXT_HOP is always this router\n");
12074 if (CHECK_FLAG(p->af_flags[afi][safi],
12075 PEER_FLAG_AS_PATH_UNCHANGED))
12076 vty_out(vty,
12077 " AS_PATH is propagated unchanged to this neighbor\n");
12078 if (CHECK_FLAG(p->af_flags[afi][safi],
12079 PEER_FLAG_NEXTHOP_UNCHANGED))
12080 vty_out(vty,
12081 " NEXT_HOP is propagated unchanged to this neighbor\n");
12082 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12083 vty_out(vty,
12084 " MED is propagated unchanged to this neighbor\n");
12085 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12086 || CHECK_FLAG(p->af_flags[afi][safi],
12087 PEER_FLAG_SEND_EXT_COMMUNITY)
12088 || CHECK_FLAG(p->af_flags[afi][safi],
12089 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
12090 vty_out(vty,
12091 " Community attribute sent to this neighbor");
12092 if (CHECK_FLAG(p->af_flags[afi][safi],
12093 PEER_FLAG_SEND_COMMUNITY)
12094 && CHECK_FLAG(p->af_flags[afi][safi],
12095 PEER_FLAG_SEND_EXT_COMMUNITY)
12096 && CHECK_FLAG(p->af_flags[afi][safi],
12097 PEER_FLAG_SEND_LARGE_COMMUNITY))
12098 vty_out(vty, "(all)\n");
12099 else if (CHECK_FLAG(p->af_flags[afi][safi],
12100 PEER_FLAG_SEND_LARGE_COMMUNITY))
12101 vty_out(vty, "(large)\n");
12102 else if (CHECK_FLAG(p->af_flags[afi][safi],
12103 PEER_FLAG_SEND_EXT_COMMUNITY))
12104 vty_out(vty, "(extended)\n");
12105 else
12106 vty_out(vty, "(standard)\n");
12107 }
12108 if (CHECK_FLAG(p->af_flags[afi][safi],
12109 PEER_FLAG_DEFAULT_ORIGINATE)) {
12110 vty_out(vty, " Default information originate,");
12111
12112 if (p->default_rmap[afi][safi].name)
12113 vty_out(vty, " default route-map %s%s,",
12114 p->default_rmap[afi][safi].map ? "*"
12115 : "",
12116 p->default_rmap[afi][safi].name);
12117 if (paf && PAF_SUBGRP(paf)
12118 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12119 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12120 vty_out(vty, " default sent\n");
12121 else
12122 vty_out(vty, " default not sent\n");
12123 }
12124
12125 /* advertise-vni-all */
12126 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
12127 if (is_evpn_enabled())
12128 vty_out(vty, " advertise-all-vni\n");
12129 }
12130
12131 if (filter->plist[FILTER_IN].name
12132 || filter->dlist[FILTER_IN].name
12133 || filter->aslist[FILTER_IN].name
12134 || filter->map[RMAP_IN].name)
12135 vty_out(vty, " Inbound path policy configured\n");
12136 if (filter->plist[FILTER_OUT].name
12137 || filter->dlist[FILTER_OUT].name
12138 || filter->aslist[FILTER_OUT].name
12139 || filter->map[RMAP_OUT].name || filter->usmap.name)
12140 vty_out(vty, " Outbound path policy configured\n");
12141
12142 /* prefix-list */
12143 if (filter->plist[FILTER_IN].name)
12144 vty_out(vty,
12145 " Incoming update prefix filter list is %s%s\n",
12146 filter->plist[FILTER_IN].plist ? "*" : "",
12147 filter->plist[FILTER_IN].name);
12148 if (filter->plist[FILTER_OUT].name)
12149 vty_out(vty,
12150 " Outgoing update prefix filter list is %s%s\n",
12151 filter->plist[FILTER_OUT].plist ? "*" : "",
12152 filter->plist[FILTER_OUT].name);
12153
12154 /* distribute-list */
12155 if (filter->dlist[FILTER_IN].name)
12156 vty_out(vty,
12157 " Incoming update network filter list is %s%s\n",
12158 filter->dlist[FILTER_IN].alist ? "*" : "",
12159 filter->dlist[FILTER_IN].name);
12160 if (filter->dlist[FILTER_OUT].name)
12161 vty_out(vty,
12162 " Outgoing update network filter list is %s%s\n",
12163 filter->dlist[FILTER_OUT].alist ? "*" : "",
12164 filter->dlist[FILTER_OUT].name);
12165
12166 /* filter-list. */
12167 if (filter->aslist[FILTER_IN].name)
12168 vty_out(vty,
12169 " Incoming update AS path filter list is %s%s\n",
12170 filter->aslist[FILTER_IN].aslist ? "*" : "",
12171 filter->aslist[FILTER_IN].name);
12172 if (filter->aslist[FILTER_OUT].name)
12173 vty_out(vty,
12174 " Outgoing update AS path filter list is %s%s\n",
12175 filter->aslist[FILTER_OUT].aslist ? "*" : "",
12176 filter->aslist[FILTER_OUT].name);
12177
12178 /* route-map. */
12179 if (filter->map[RMAP_IN].name)
12180 vty_out(vty,
12181 " Route map for incoming advertisements is %s%s\n",
12182 filter->map[RMAP_IN].map ? "*" : "",
12183 filter->map[RMAP_IN].name);
12184 if (filter->map[RMAP_OUT].name)
12185 vty_out(vty,
12186 " Route map for outgoing advertisements is %s%s\n",
12187 filter->map[RMAP_OUT].map ? "*" : "",
12188 filter->map[RMAP_OUT].name);
12189
12190 /* ebgp-requires-policy (inbound) */
12191 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12192 && !bgp_inbound_policy_exists(p, filter))
12193 vty_out(vty,
12194 " Inbound updates discarded due to missing policy\n");
12195
12196 /* ebgp-requires-policy (outbound) */
12197 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12198 && !bgp_outbound_policy_exists(p, filter))
12199 vty_out(vty,
12200 " Outbound updates discarded due to missing policy\n");
12201
12202 /* unsuppress-map */
12203 if (filter->usmap.name)
12204 vty_out(vty,
12205 " Route map for selective unsuppress is %s%s\n",
12206 filter->usmap.map ? "*" : "",
12207 filter->usmap.name);
12208
12209 /* advertise-map */
12210 if (filter->advmap.aname && filter->advmap.cname)
12211 vty_out(vty,
12212 " Condition %s, Condition-map %s%s, Advertise-map %s%s, status: %s\n",
12213 filter->advmap.condition ? "EXIST"
12214 : "NON_EXIST",
12215 filter->advmap.cmap ? "*" : "",
12216 filter->advmap.cname,
12217 filter->advmap.amap ? "*" : "",
12218 filter->advmap.aname,
12219 filter->advmap.update_type == ADVERTISE
12220 ? "Advertise"
12221 : "Withdraw");
12222
12223 /* Receive prefix count */
12224 vty_out(vty, " %u accepted prefixes\n",
12225 p->pcount[afi][safi]);
12226
12227 /* maximum-prefix-out */
12228 if (CHECK_FLAG(p->af_flags[afi][safi],
12229 PEER_FLAG_MAX_PREFIX_OUT))
12230 vty_out(vty,
12231 " Maximum allowed prefixes sent %u\n",
12232 p->pmax_out[afi][safi]);
12233
12234 /* Maximum prefix */
12235 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12236 vty_out(vty,
12237 " Maximum prefixes allowed %u%s\n",
12238 p->pmax[afi][safi],
12239 CHECK_FLAG(p->af_flags[afi][safi],
12240 PEER_FLAG_MAX_PREFIX_WARNING)
12241 ? " (warning-only)"
12242 : "");
12243 vty_out(vty, " Threshold for warning message %d%%",
12244 p->pmax_threshold[afi][safi]);
12245 if (p->pmax_restart[afi][safi])
12246 vty_out(vty, ", restart interval %d min",
12247 p->pmax_restart[afi][safi]);
12248 vty_out(vty, "\n");
12249 }
12250
12251 vty_out(vty, "\n");
12252 }
12253 }
12254
12255 static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
12256 json_object *json)
12257 {
12258 struct bgp *bgp;
12259 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
12260 char timebuf[BGP_UPTIME_LEN];
12261 char dn_flag[2];
12262 afi_t afi;
12263 safi_t safi;
12264 uint16_t i;
12265 uint8_t *msg;
12266 json_object *json_neigh = NULL;
12267 time_t epoch_tbuf;
12268 uint32_t sync_tcp_mss;
12269
12270 bgp = p->bgp;
12271
12272 if (use_json)
12273 json_neigh = json_object_new_object();
12274
12275 memset(dn_flag, '\0', sizeof(dn_flag));
12276 if (!p->conf_if && peer_dynamic_neighbor(p))
12277 dn_flag[0] = '*';
12278
12279 if (!use_json) {
12280 if (p->conf_if) /* Configured interface name. */
12281 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
12282 BGP_PEER_SU_UNSPEC(p)
12283 ? "None"
12284 : sockunion2str(&p->su, buf,
12285 SU_ADDRSTRLEN));
12286 else /* Configured IP address. */
12287 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
12288 p->host);
12289 }
12290
12291 if (use_json) {
12292 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
12293 json_object_string_add(json_neigh, "bgpNeighborAddr",
12294 "none");
12295 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
12296 json_object_string_add(
12297 json_neigh, "bgpNeighborAddr",
12298 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
12299
12300 json_object_int_add(json_neigh, "remoteAs", p->as);
12301
12302 if (p->change_local_as)
12303 json_object_int_add(json_neigh, "localAs",
12304 p->change_local_as);
12305 else
12306 json_object_int_add(json_neigh, "localAs", p->local_as);
12307
12308 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
12309 json_object_boolean_true_add(json_neigh,
12310 "localAsNoPrepend");
12311
12312 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
12313 json_object_boolean_true_add(json_neigh,
12314 "localAsReplaceAs");
12315 } else {
12316 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
12317 || (p->as_type == AS_INTERNAL))
12318 vty_out(vty, "remote AS %u, ", p->as);
12319 else
12320 vty_out(vty, "remote AS Unspecified, ");
12321 vty_out(vty, "local AS %u%s%s, ",
12322 p->change_local_as ? p->change_local_as : p->local_as,
12323 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
12324 ? " no-prepend"
12325 : "",
12326 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
12327 ? " replace-as"
12328 : "");
12329 }
12330 /* peer type internal or confed-internal */
12331 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
12332 if (use_json) {
12333 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12334 json_object_boolean_true_add(
12335 json_neigh, "nbrConfedInternalLink");
12336 else
12337 json_object_boolean_true_add(json_neigh,
12338 "nbrInternalLink");
12339 } else {
12340 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12341 vty_out(vty, "confed-internal link\n");
12342 else
12343 vty_out(vty, "internal link\n");
12344 }
12345 /* peer type external or confed-external */
12346 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
12347 if (use_json) {
12348 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12349 json_object_boolean_true_add(
12350 json_neigh, "nbrConfedExternalLink");
12351 else
12352 json_object_boolean_true_add(json_neigh,
12353 "nbrExternalLink");
12354 } else {
12355 if (bgp_confederation_peers_check(bgp, p->as))
12356 vty_out(vty, "confed-external link\n");
12357 else
12358 vty_out(vty, "external link\n");
12359 }
12360 } else {
12361 if (use_json)
12362 json_object_boolean_true_add(json_neigh,
12363 "nbrUnspecifiedLink");
12364 else
12365 vty_out(vty, "unspecified link\n");
12366 }
12367
12368 /* Description. */
12369 if (p->desc) {
12370 if (use_json)
12371 json_object_string_add(json_neigh, "nbrDesc", p->desc);
12372 else
12373 vty_out(vty, " Description: %s\n", p->desc);
12374 }
12375
12376 if (p->hostname) {
12377 if (use_json) {
12378 if (p->hostname)
12379 json_object_string_add(json_neigh, "hostname",
12380 p->hostname);
12381
12382 if (p->domainname)
12383 json_object_string_add(json_neigh, "domainname",
12384 p->domainname);
12385 } else {
12386 if (p->domainname && (p->domainname[0] != '\0'))
12387 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
12388 p->domainname);
12389 else
12390 vty_out(vty, "Hostname: %s\n", p->hostname);
12391 }
12392 }
12393
12394 /* Peer-group */
12395 if (p->group) {
12396 if (use_json) {
12397 json_object_string_add(json_neigh, "peerGroup",
12398 p->group->name);
12399
12400 if (dn_flag[0]) {
12401 struct prefix prefix, *range = NULL;
12402
12403 if (sockunion2hostprefix(&(p->su), &prefix))
12404 range = peer_group_lookup_dynamic_neighbor_range(
12405 p->group, &prefix);
12406
12407 if (range) {
12408 json_object_string_addf(
12409 json_neigh,
12410 "peerSubnetRangeGroup", "%pFX",
12411 range);
12412 }
12413 }
12414 } else {
12415 vty_out(vty,
12416 " Member of peer-group %s for session parameters\n",
12417 p->group->name);
12418
12419 if (dn_flag[0]) {
12420 struct prefix prefix, *range = NULL;
12421
12422 if (sockunion2hostprefix(&(p->su), &prefix))
12423 range = peer_group_lookup_dynamic_neighbor_range(
12424 p->group, &prefix);
12425
12426 if (range) {
12427 vty_out(vty,
12428 " Belongs to the subnet range group: %pFX\n",
12429 range);
12430 }
12431 }
12432 }
12433 }
12434
12435 if (use_json) {
12436 /* Administrative shutdown. */
12437 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12438 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
12439 json_object_boolean_true_add(json_neigh,
12440 "adminShutDown");
12441
12442 /* BGP Version. */
12443 json_object_int_add(json_neigh, "bgpVersion", 4);
12444 json_object_string_addf(json_neigh, "remoteRouterId", "%pI4",
12445 &p->remote_id);
12446 json_object_string_addf(json_neigh, "localRouterId", "%pI4",
12447 &bgp->router_id);
12448
12449 /* Confederation */
12450 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12451 && bgp_confederation_peers_check(bgp, p->as))
12452 json_object_boolean_true_add(json_neigh,
12453 "nbrCommonAdmin");
12454
12455 /* Status. */
12456 json_object_string_add(
12457 json_neigh, "bgpState",
12458 lookup_msg(bgp_status_msg, p->status, NULL));
12459
12460 if (peer_established(p)) {
12461 time_t uptime;
12462
12463 uptime = bgp_clock();
12464 uptime -= p->uptime;
12465 epoch_tbuf = time(NULL) - uptime;
12466
12467 json_object_int_add(json_neigh, "bgpTimerUpMsec",
12468 uptime * 1000);
12469 json_object_string_add(json_neigh, "bgpTimerUpString",
12470 peer_uptime(p->uptime, timebuf,
12471 BGP_UPTIME_LEN, 0,
12472 NULL));
12473 json_object_int_add(json_neigh,
12474 "bgpTimerUpEstablishedEpoch",
12475 epoch_tbuf);
12476 }
12477
12478 else if (p->status == Active) {
12479 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12480 json_object_string_add(json_neigh, "bgpStateIs",
12481 "passive");
12482 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12483 json_object_string_add(json_neigh, "bgpStateIs",
12484 "passiveNSF");
12485 }
12486
12487 /* read timer */
12488 time_t uptime;
12489 struct tm tm;
12490
12491 uptime = bgp_clock();
12492 uptime -= p->readtime;
12493 gmtime_r(&uptime, &tm);
12494
12495 json_object_int_add(json_neigh, "bgpTimerLastRead",
12496 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12497 + (tm.tm_hour * 3600000));
12498
12499 uptime = bgp_clock();
12500 uptime -= p->last_write;
12501 gmtime_r(&uptime, &tm);
12502
12503 json_object_int_add(json_neigh, "bgpTimerLastWrite",
12504 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12505 + (tm.tm_hour * 3600000));
12506
12507 uptime = bgp_clock();
12508 uptime -= p->update_time;
12509 gmtime_r(&uptime, &tm);
12510
12511 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
12512 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12513 + (tm.tm_hour * 3600000));
12514
12515 /* Configured timer values. */
12516 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
12517 p->v_holdtime * 1000);
12518 json_object_int_add(json_neigh,
12519 "bgpTimerKeepAliveIntervalMsecs",
12520 p->v_keepalive * 1000);
12521 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN)) {
12522 json_object_int_add(json_neigh,
12523 "bgpTimerDelayOpenTimeMsecs",
12524 p->v_delayopen * 1000);
12525 }
12526
12527 /* Configured and Synced tcp-mss value for peer */
12528 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
12529 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
12530 json_object_int_add(json_neigh, "bgpTcpMssConfigured",
12531 p->tcp_mss);
12532 json_object_int_add(json_neigh, "bgpTcpMssSynced",
12533 sync_tcp_mss);
12534 }
12535
12536 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
12537 json_object_int_add(json_neigh,
12538 "bgpTimerConfiguredHoldTimeMsecs",
12539 p->holdtime * 1000);
12540 json_object_int_add(
12541 json_neigh,
12542 "bgpTimerConfiguredKeepAliveIntervalMsecs",
12543 p->keepalive * 1000);
12544 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
12545 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
12546 json_object_int_add(json_neigh,
12547 "bgpTimerConfiguredHoldTimeMsecs",
12548 bgp->default_holdtime);
12549 json_object_int_add(
12550 json_neigh,
12551 "bgpTimerConfiguredKeepAliveIntervalMsecs",
12552 bgp->default_keepalive);
12553 }
12554
12555 /* Extended Optional Parameters Length for BGP OPEN Message */
12556 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
12557 json_object_boolean_true_add(
12558 json_neigh, "extendedOptionalParametersLength");
12559 else
12560 json_object_boolean_false_add(
12561 json_neigh, "extendedOptionalParametersLength");
12562
12563 /* Conditional advertisements */
12564 json_object_int_add(
12565 json_neigh,
12566 "bgpTimerConfiguredConditionalAdvertisementsSec",
12567 bgp->condition_check_period);
12568 if (thread_is_scheduled(bgp->t_condition_check))
12569 json_object_int_add(
12570 json_neigh,
12571 "bgpTimerUntilConditionalAdvertisementsSec",
12572 thread_timer_remain_second(
12573 bgp->t_condition_check));
12574 } else {
12575 /* Administrative shutdown. */
12576 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12577 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
12578 vty_out(vty, " Administratively shut down\n");
12579
12580 /* BGP Version. */
12581 vty_out(vty, " BGP version 4");
12582 vty_out(vty, ", remote router ID %s",
12583 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
12584 vty_out(vty, ", local router ID %s\n",
12585 inet_ntop(AF_INET, &bgp->router_id, buf1,
12586 sizeof(buf1)));
12587
12588 /* Confederation */
12589 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12590 && bgp_confederation_peers_check(bgp, p->as))
12591 vty_out(vty,
12592 " Neighbor under common administration\n");
12593
12594 /* Status. */
12595 vty_out(vty, " BGP state = %s",
12596 lookup_msg(bgp_status_msg, p->status, NULL));
12597
12598 if (peer_established(p))
12599 vty_out(vty, ", up for %8s",
12600 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
12601 0, NULL));
12602
12603 else if (p->status == Active) {
12604 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12605 vty_out(vty, " (passive)");
12606 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12607 vty_out(vty, " (NSF passive)");
12608 }
12609 vty_out(vty, "\n");
12610
12611 /* read timer */
12612 vty_out(vty, " Last read %s",
12613 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
12614 NULL));
12615 vty_out(vty, ", Last write %s\n",
12616 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
12617 NULL));
12618
12619 /* Configured timer values. */
12620 vty_out(vty,
12621 " Hold time is %d, keepalive interval is %d seconds\n",
12622 p->v_holdtime, p->v_keepalive);
12623 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
12624 vty_out(vty, " Configured hold time is %d",
12625 p->holdtime);
12626 vty_out(vty, ", keepalive interval is %d seconds\n",
12627 p->keepalive);
12628 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
12629 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
12630 vty_out(vty, " Configured hold time is %d",
12631 bgp->default_holdtime);
12632 vty_out(vty, ", keepalive interval is %d seconds\n",
12633 bgp->default_keepalive);
12634 }
12635 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN))
12636 vty_out(vty,
12637 " Configured DelayOpenTime is %d seconds\n",
12638 p->delayopen);
12639
12640 /* Configured and synced tcp-mss value for peer */
12641 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
12642 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
12643 vty_out(vty, " Configured tcp-mss is %d", p->tcp_mss);
12644 vty_out(vty, ", synced tcp-mss is %d\n", sync_tcp_mss);
12645 }
12646
12647 /* Extended Optional Parameters Length for BGP OPEN Message */
12648 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
12649 vty_out(vty,
12650 " Extended Optional Parameters Length is enabled\n");
12651
12652 /* Conditional advertisements */
12653 vty_out(vty,
12654 " Configured conditional advertisements interval is %d seconds\n",
12655 bgp->condition_check_period);
12656 if (thread_is_scheduled(bgp->t_condition_check))
12657 vty_out(vty,
12658 " Time until conditional advertisements begin is %lu seconds\n",
12659 thread_timer_remain_second(
12660 bgp->t_condition_check));
12661 }
12662 /* Capability. */
12663 if (peer_established(p) &&
12664 (p->cap || peer_afc_advertised(p) || peer_afc_received(p))) {
12665 if (use_json) {
12666 json_object *json_cap = NULL;
12667
12668 json_cap = json_object_new_object();
12669
12670 /* AS4 */
12671 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
12672 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
12673 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV) &&
12674 CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
12675 json_object_string_add(
12676 json_cap, "4byteAs",
12677 "advertisedAndReceived");
12678 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
12679 json_object_string_add(json_cap,
12680 "4byteAs",
12681 "advertised");
12682 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
12683 json_object_string_add(json_cap,
12684 "4byteAs",
12685 "received");
12686 }
12687
12688 /* Extended Message Support */
12689 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV) &&
12690 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV))
12691 json_object_string_add(json_cap,
12692 "extendedMessage",
12693 "advertisedAndReceived");
12694 else if (CHECK_FLAG(p->cap,
12695 PEER_CAP_EXTENDED_MESSAGE_ADV))
12696 json_object_string_add(json_cap,
12697 "extendedMessage",
12698 "advertised");
12699 else if (CHECK_FLAG(p->cap,
12700 PEER_CAP_EXTENDED_MESSAGE_RCV))
12701 json_object_string_add(json_cap,
12702 "extendedMessage",
12703 "received");
12704
12705 /* AddPath */
12706 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
12707 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
12708 json_object *json_add = NULL;
12709 const char *print_store;
12710
12711 json_add = json_object_new_object();
12712
12713 FOREACH_AFI_SAFI (afi, safi) {
12714 json_object *json_sub = NULL;
12715 json_sub = json_object_new_object();
12716 print_store = get_afi_safi_str(
12717 afi, safi, true);
12718
12719 if (CHECK_FLAG(
12720 p->af_cap[afi][safi],
12721 PEER_CAP_ADDPATH_AF_TX_ADV) ||
12722 CHECK_FLAG(
12723 p->af_cap[afi][safi],
12724 PEER_CAP_ADDPATH_AF_TX_RCV)) {
12725 if (CHECK_FLAG(
12726 p->af_cap[afi]
12727 [safi],
12728 PEER_CAP_ADDPATH_AF_TX_ADV) &&
12729 CHECK_FLAG(
12730 p->af_cap[afi]
12731 [safi],
12732 PEER_CAP_ADDPATH_AF_TX_RCV))
12733 json_object_boolean_true_add(
12734 json_sub,
12735 "txAdvertisedAndReceived");
12736 else if (
12737 CHECK_FLAG(
12738 p->af_cap[afi]
12739 [safi],
12740 PEER_CAP_ADDPATH_AF_TX_ADV))
12741 json_object_boolean_true_add(
12742 json_sub,
12743 "txAdvertised");
12744 else if (
12745 CHECK_FLAG(
12746 p->af_cap[afi]
12747 [safi],
12748 PEER_CAP_ADDPATH_AF_TX_RCV))
12749 json_object_boolean_true_add(
12750 json_sub,
12751 "txReceived");
12752 }
12753
12754 if (CHECK_FLAG(
12755 p->af_cap[afi][safi],
12756 PEER_CAP_ADDPATH_AF_RX_ADV) ||
12757 CHECK_FLAG(
12758 p->af_cap[afi][safi],
12759 PEER_CAP_ADDPATH_AF_RX_RCV)) {
12760 if (CHECK_FLAG(
12761 p->af_cap[afi]
12762 [safi],
12763 PEER_CAP_ADDPATH_AF_RX_ADV) &&
12764 CHECK_FLAG(
12765 p->af_cap[afi]
12766 [safi],
12767 PEER_CAP_ADDPATH_AF_RX_RCV))
12768 json_object_boolean_true_add(
12769 json_sub,
12770 "rxAdvertisedAndReceived");
12771 else if (
12772 CHECK_FLAG(
12773 p->af_cap[afi]
12774 [safi],
12775 PEER_CAP_ADDPATH_AF_RX_ADV))
12776 json_object_boolean_true_add(
12777 json_sub,
12778 "rxAdvertised");
12779 else if (
12780 CHECK_FLAG(
12781 p->af_cap[afi]
12782 [safi],
12783 PEER_CAP_ADDPATH_AF_RX_RCV))
12784 json_object_boolean_true_add(
12785 json_sub,
12786 "rxReceived");
12787 }
12788
12789 if (CHECK_FLAG(
12790 p->af_cap[afi][safi],
12791 PEER_CAP_ADDPATH_AF_TX_ADV) ||
12792 CHECK_FLAG(
12793 p->af_cap[afi][safi],
12794 PEER_CAP_ADDPATH_AF_TX_RCV) ||
12795 CHECK_FLAG(
12796 p->af_cap[afi][safi],
12797 PEER_CAP_ADDPATH_AF_RX_ADV) ||
12798 CHECK_FLAG(
12799 p->af_cap[afi][safi],
12800 PEER_CAP_ADDPATH_AF_RX_RCV))
12801 json_object_object_add(
12802 json_add, print_store,
12803 json_sub);
12804 else
12805 json_object_free(json_sub);
12806 }
12807
12808 json_object_object_add(json_cap, "addPath",
12809 json_add);
12810 }
12811
12812 /* Dynamic */
12813 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
12814 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
12815 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV) &&
12816 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
12817 json_object_string_add(
12818 json_cap, "dynamic",
12819 "advertisedAndReceived");
12820 else if (CHECK_FLAG(p->cap,
12821 PEER_CAP_DYNAMIC_ADV))
12822 json_object_string_add(json_cap,
12823 "dynamic",
12824 "advertised");
12825 else if (CHECK_FLAG(p->cap,
12826 PEER_CAP_DYNAMIC_RCV))
12827 json_object_string_add(json_cap,
12828 "dynamic",
12829 "received");
12830 }
12831
12832 /* Extended nexthop */
12833 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
12834 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
12835 json_object *json_nxt = NULL;
12836 const char *print_store;
12837
12838
12839 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV) &&
12840 CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
12841 json_object_string_add(
12842 json_cap, "extendedNexthop",
12843 "advertisedAndReceived");
12844 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
12845 json_object_string_add(
12846 json_cap, "extendedNexthop",
12847 "advertised");
12848 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
12849 json_object_string_add(
12850 json_cap, "extendedNexthop",
12851 "received");
12852
12853 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
12854 json_nxt = json_object_new_object();
12855
12856 for (safi = SAFI_UNICAST;
12857 safi < SAFI_MAX; safi++) {
12858 if (CHECK_FLAG(
12859 p->af_cap[AFI_IP]
12860 [safi],
12861 PEER_CAP_ENHE_AF_RCV)) {
12862 print_store =
12863 get_afi_safi_str(
12864 AFI_IP,
12865 safi,
12866 true);
12867 json_object_string_add(
12868 json_nxt,
12869 print_store,
12870 "recieved"); /* misspelled for compatibility */
12871 }
12872 }
12873 json_object_object_add(
12874 json_cap,
12875 "extendedNexthopFamililesByPeer",
12876 json_nxt);
12877 }
12878 }
12879
12880 /* Long-lived Graceful Restart */
12881 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
12882 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
12883 json_object *json_llgr = NULL;
12884 const char *afi_safi_str;
12885
12886 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV) &&
12887 CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
12888 json_object_string_add(
12889 json_cap,
12890 "longLivedGracefulRestart",
12891 "advertisedAndReceived");
12892 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
12893 json_object_string_add(
12894 json_cap,
12895 "longLivedGracefulRestart",
12896 "advertised");
12897 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
12898 json_object_string_add(
12899 json_cap,
12900 "longLivedGracefulRestart",
12901 "received");
12902
12903 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
12904 json_llgr = json_object_new_object();
12905
12906 FOREACH_AFI_SAFI (afi, safi) {
12907 if (CHECK_FLAG(
12908 p->af_cap[afi]
12909 [safi],
12910 PEER_CAP_ENHE_AF_RCV)) {
12911 afi_safi_str =
12912 get_afi_safi_str(
12913 afi,
12914 safi,
12915 true);
12916 json_object_string_add(
12917 json_llgr,
12918 afi_safi_str,
12919 "received");
12920 }
12921 }
12922 json_object_object_add(
12923 json_cap,
12924 "longLivedGracefulRestartByPeer",
12925 json_llgr);
12926 }
12927 }
12928
12929 /* Route Refresh */
12930 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
12931 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
12932 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
12933 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) &&
12934 (CHECK_FLAG(p->cap,
12935 PEER_CAP_REFRESH_NEW_RCV) ||
12936 CHECK_FLAG(p->cap,
12937 PEER_CAP_REFRESH_OLD_RCV))) {
12938 if (CHECK_FLAG(
12939 p->cap,
12940 PEER_CAP_REFRESH_OLD_RCV) &&
12941 CHECK_FLAG(
12942 p->cap,
12943 PEER_CAP_REFRESH_NEW_RCV))
12944 json_object_string_add(
12945 json_cap,
12946 "routeRefresh",
12947 "advertisedAndReceivedOldNew");
12948 else {
12949 if (CHECK_FLAG(
12950 p->cap,
12951 PEER_CAP_REFRESH_OLD_RCV))
12952 json_object_string_add(
12953 json_cap,
12954 "routeRefresh",
12955 "advertisedAndReceivedOld");
12956 else
12957 json_object_string_add(
12958 json_cap,
12959 "routeRefresh",
12960 "advertisedAndReceivedNew");
12961 }
12962 } else if (CHECK_FLAG(p->cap,
12963 PEER_CAP_REFRESH_ADV))
12964 json_object_string_add(json_cap,
12965 "routeRefresh",
12966 "advertised");
12967 else if (CHECK_FLAG(p->cap,
12968 PEER_CAP_REFRESH_NEW_RCV) ||
12969 CHECK_FLAG(p->cap,
12970 PEER_CAP_REFRESH_OLD_RCV))
12971 json_object_string_add(json_cap,
12972 "routeRefresh",
12973 "received");
12974 }
12975
12976 /* Enhanced Route Refresh */
12977 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
12978 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
12979 if (CHECK_FLAG(p->cap,
12980 PEER_CAP_ENHANCED_RR_ADV) &&
12981 CHECK_FLAG(p->cap,
12982 PEER_CAP_ENHANCED_RR_RCV))
12983 json_object_string_add(
12984 json_cap,
12985 "enhancedRouteRefresh",
12986 "advertisedAndReceived");
12987 else if (CHECK_FLAG(p->cap,
12988 PEER_CAP_ENHANCED_RR_ADV))
12989 json_object_string_add(
12990 json_cap,
12991 "enhancedRouteRefresh",
12992 "advertised");
12993 else if (CHECK_FLAG(p->cap,
12994 PEER_CAP_ENHANCED_RR_RCV))
12995 json_object_string_add(
12996 json_cap,
12997 "enhancedRouteRefresh",
12998 "received");
12999 }
13000
13001 /* Multiprotocol Extensions */
13002 json_object *json_multi = NULL;
13003
13004 json_multi = json_object_new_object();
13005
13006 FOREACH_AFI_SAFI (afi, safi) {
13007 if (p->afc_adv[afi][safi] ||
13008 p->afc_recv[afi][safi]) {
13009 json_object *json_exten = NULL;
13010 json_exten = json_object_new_object();
13011
13012 if (p->afc_adv[afi][safi] &&
13013 p->afc_recv[afi][safi])
13014 json_object_boolean_true_add(
13015 json_exten,
13016 "advertisedAndReceived");
13017 else if (p->afc_adv[afi][safi])
13018 json_object_boolean_true_add(
13019 json_exten,
13020 "advertised");
13021 else if (p->afc_recv[afi][safi])
13022 json_object_boolean_true_add(
13023 json_exten, "received");
13024
13025 json_object_object_add(
13026 json_multi,
13027 get_afi_safi_str(afi, safi,
13028 true),
13029 json_exten);
13030 }
13031 }
13032 json_object_object_add(json_cap,
13033 "multiprotocolExtensions",
13034 json_multi);
13035
13036 /* Hostname capabilities */
13037 json_object *json_hname = NULL;
13038
13039 json_hname = json_object_new_object();
13040
13041 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13042 json_object_string_add(
13043 json_hname, "advHostName",
13044 bgp->peer_self->hostname
13045 ? bgp->peer_self->hostname
13046 : "n/a");
13047 json_object_string_add(
13048 json_hname, "advDomainName",
13049 bgp->peer_self->domainname
13050 ? bgp->peer_self->domainname
13051 : "n/a");
13052 }
13053
13054
13055 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13056 json_object_string_add(
13057 json_hname, "rcvHostName",
13058 p->hostname ? p->hostname : "n/a");
13059 json_object_string_add(
13060 json_hname, "rcvDomainName",
13061 p->domainname ? p->domainname : "n/a");
13062 }
13063
13064 json_object_object_add(json_cap, "hostName",
13065 json_hname);
13066
13067 /* Graceful Restart */
13068 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
13069 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
13070 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV) &&
13071 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
13072 json_object_string_add(
13073 json_cap, "gracefulRestart",
13074 "advertisedAndReceived");
13075 else if (CHECK_FLAG(p->cap,
13076 PEER_CAP_RESTART_ADV))
13077 json_object_string_add(
13078 json_cap,
13079 "gracefulRestartCapability",
13080 "advertised");
13081 else if (CHECK_FLAG(p->cap,
13082 PEER_CAP_RESTART_RCV))
13083 json_object_string_add(
13084 json_cap,
13085 "gracefulRestartCapability",
13086 "received");
13087
13088 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13089 int restart_af_count = 0;
13090 json_object *json_restart = NULL;
13091 json_restart = json_object_new_object();
13092
13093 json_object_int_add(
13094 json_cap,
13095 "gracefulRestartRemoteTimerMsecs",
13096 p->v_gr_restart * 1000);
13097
13098 FOREACH_AFI_SAFI (afi, safi) {
13099 if (CHECK_FLAG(
13100 p->af_cap[afi]
13101 [safi],
13102 PEER_CAP_RESTART_AF_RCV)) {
13103 json_object *json_sub =
13104 NULL;
13105 json_sub =
13106 json_object_new_object();
13107
13108 if (CHECK_FLAG(
13109 p->af_cap
13110 [afi]
13111 [safi],
13112 PEER_CAP_RESTART_AF_PRESERVE_RCV))
13113 json_object_boolean_true_add(
13114 json_sub,
13115 "preserved");
13116 restart_af_count++;
13117 json_object_object_add(
13118 json_restart,
13119 get_afi_safi_str(
13120 afi,
13121 safi,
13122 true),
13123 json_sub);
13124 }
13125 }
13126 if (!restart_af_count) {
13127 json_object_string_add(
13128 json_cap,
13129 "addressFamiliesByPeer",
13130 "none");
13131 json_object_free(json_restart);
13132 } else
13133 json_object_object_add(
13134 json_cap,
13135 "addressFamiliesByPeer",
13136 json_restart);
13137 }
13138 }
13139 json_object_object_add(
13140 json_neigh, "neighborCapabilities", json_cap);
13141 } else {
13142 vty_out(vty, " Neighbor capabilities:\n");
13143
13144 /* AS4 */
13145 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
13146 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13147 vty_out(vty, " 4 Byte AS:");
13148 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
13149 vty_out(vty, " advertised");
13150 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13151 vty_out(vty, " %sreceived",
13152 CHECK_FLAG(p->cap,
13153 PEER_CAP_AS4_ADV)
13154 ? "and "
13155 : "");
13156 vty_out(vty, "\n");
13157 }
13158
13159 /* Extended Message Support */
13160 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV) ||
13161 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV)) {
13162 vty_out(vty, " Extended Message:");
13163 if (CHECK_FLAG(p->cap,
13164 PEER_CAP_EXTENDED_MESSAGE_ADV))
13165 vty_out(vty, " advertised");
13166 if (CHECK_FLAG(p->cap,
13167 PEER_CAP_EXTENDED_MESSAGE_RCV))
13168 vty_out(vty, " %sreceived",
13169 CHECK_FLAG(
13170 p->cap,
13171 PEER_CAP_EXTENDED_MESSAGE_ADV)
13172 ? "and "
13173 : "");
13174 vty_out(vty, "\n");
13175 }
13176
13177 /* AddPath */
13178 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
13179 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
13180 vty_out(vty, " AddPath:\n");
13181
13182 FOREACH_AFI_SAFI (afi, safi) {
13183 if (CHECK_FLAG(
13184 p->af_cap[afi][safi],
13185 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13186 CHECK_FLAG(
13187 p->af_cap[afi][safi],
13188 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13189 vty_out(vty, " %s: TX ",
13190 get_afi_safi_str(
13191 afi, safi,
13192 false));
13193
13194 if (CHECK_FLAG(
13195 p->af_cap[afi]
13196 [safi],
13197 PEER_CAP_ADDPATH_AF_TX_ADV))
13198 vty_out(vty,
13199 "advertised");
13200
13201 if (CHECK_FLAG(
13202 p->af_cap[afi]
13203 [safi],
13204 PEER_CAP_ADDPATH_AF_TX_RCV))
13205 vty_out(vty,
13206 "%sreceived",
13207 CHECK_FLAG(
13208 p->af_cap
13209 [afi]
13210 [safi],
13211 PEER_CAP_ADDPATH_AF_TX_ADV)
13212 ? " and "
13213 : "");
13214
13215 vty_out(vty, "\n");
13216 }
13217
13218 if (CHECK_FLAG(
13219 p->af_cap[afi][safi],
13220 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13221 CHECK_FLAG(
13222 p->af_cap[afi][safi],
13223 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13224 vty_out(vty, " %s: RX ",
13225 get_afi_safi_str(
13226 afi, safi,
13227 false));
13228
13229 if (CHECK_FLAG(
13230 p->af_cap[afi]
13231 [safi],
13232 PEER_CAP_ADDPATH_AF_RX_ADV))
13233 vty_out(vty,
13234 "advertised");
13235
13236 if (CHECK_FLAG(
13237 p->af_cap[afi]
13238 [safi],
13239 PEER_CAP_ADDPATH_AF_RX_RCV))
13240 vty_out(vty,
13241 "%sreceived",
13242 CHECK_FLAG(
13243 p->af_cap
13244 [afi]
13245 [safi],
13246 PEER_CAP_ADDPATH_AF_RX_ADV)
13247 ? " and "
13248 : "");
13249
13250 vty_out(vty, "\n");
13251 }
13252 }
13253 }
13254
13255 /* Dynamic */
13256 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
13257 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
13258 vty_out(vty, " Dynamic:");
13259 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV))
13260 vty_out(vty, " advertised");
13261 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
13262 vty_out(vty, " %sreceived",
13263 CHECK_FLAG(p->cap,
13264 PEER_CAP_DYNAMIC_ADV)
13265 ? "and "
13266 : "");
13267 vty_out(vty, "\n");
13268 }
13269
13270 /* Extended nexthop */
13271 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
13272 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13273 vty_out(vty, " Extended nexthop:");
13274 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
13275 vty_out(vty, " advertised");
13276 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13277 vty_out(vty, " %sreceived",
13278 CHECK_FLAG(p->cap,
13279 PEER_CAP_ENHE_ADV)
13280 ? "and "
13281 : "");
13282 vty_out(vty, "\n");
13283
13284 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
13285 vty_out(vty,
13286 " Address families by peer:\n ");
13287 for (safi = SAFI_UNICAST;
13288 safi < SAFI_MAX; safi++)
13289 if (CHECK_FLAG(
13290 p->af_cap[AFI_IP]
13291 [safi],
13292 PEER_CAP_ENHE_AF_RCV))
13293 vty_out(vty,
13294 " %s\n",
13295 get_afi_safi_str(
13296 AFI_IP,
13297 safi,
13298 false));
13299 }
13300 }
13301
13302 /* Long-lived Graceful Restart */
13303 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
13304 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
13305 vty_out(vty,
13306 " Long-lived Graceful Restart:");
13307 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
13308 vty_out(vty, " advertised");
13309 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13310 vty_out(vty, " %sreceived",
13311 CHECK_FLAG(p->cap,
13312 PEER_CAP_LLGR_ADV)
13313 ? "and "
13314 : "");
13315 vty_out(vty, "\n");
13316
13317 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
13318 vty_out(vty,
13319 " Address families by peer:\n");
13320 FOREACH_AFI_SAFI (afi, safi)
13321 if (CHECK_FLAG(
13322 p->af_cap[afi]
13323 [safi],
13324 PEER_CAP_LLGR_AF_RCV))
13325 vty_out(vty,
13326 " %s\n",
13327 get_afi_safi_str(
13328 afi,
13329 safi,
13330 false));
13331 }
13332 }
13333
13334 /* Route Refresh */
13335 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
13336 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
13337 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
13338 vty_out(vty, " Route refresh:");
13339 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV))
13340 vty_out(vty, " advertised");
13341 if (CHECK_FLAG(p->cap,
13342 PEER_CAP_REFRESH_NEW_RCV) ||
13343 CHECK_FLAG(p->cap,
13344 PEER_CAP_REFRESH_OLD_RCV))
13345 vty_out(vty, " %sreceived(%s)",
13346 CHECK_FLAG(p->cap,
13347 PEER_CAP_REFRESH_ADV)
13348 ? "and "
13349 : "",
13350 (CHECK_FLAG(
13351 p->cap,
13352 PEER_CAP_REFRESH_OLD_RCV) &&
13353 CHECK_FLAG(
13354 p->cap,
13355 PEER_CAP_REFRESH_NEW_RCV))
13356 ? "old & new"
13357 : CHECK_FLAG(
13358 p->cap,
13359 PEER_CAP_REFRESH_OLD_RCV)
13360 ? "old"
13361 : "new");
13362
13363 vty_out(vty, "\n");
13364 }
13365
13366 /* Enhanced Route Refresh */
13367 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
13368 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
13369 vty_out(vty, " Enhanced Route Refresh:");
13370 if (CHECK_FLAG(p->cap,
13371 PEER_CAP_ENHANCED_RR_ADV))
13372 vty_out(vty, " advertised");
13373 if (CHECK_FLAG(p->cap,
13374 PEER_CAP_ENHANCED_RR_RCV))
13375 vty_out(vty, " %sreceived",
13376 CHECK_FLAG(p->cap,
13377 PEER_CAP_REFRESH_ADV)
13378 ? "and "
13379 : "");
13380 vty_out(vty, "\n");
13381 }
13382
13383 /* Multiprotocol Extensions */
13384 FOREACH_AFI_SAFI (afi, safi)
13385 if (p->afc_adv[afi][safi] ||
13386 p->afc_recv[afi][safi]) {
13387 vty_out(vty, " Address Family %s:",
13388 get_afi_safi_str(afi, safi,
13389 false));
13390 if (p->afc_adv[afi][safi])
13391 vty_out(vty, " advertised");
13392 if (p->afc_recv[afi][safi])
13393 vty_out(vty, " %sreceived",
13394 p->afc_adv[afi][safi]
13395 ? "and "
13396 : "");
13397 vty_out(vty, "\n");
13398 }
13399
13400 /* Hostname capability */
13401 vty_out(vty, " Hostname Capability:");
13402
13403 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13404 vty_out(vty,
13405 " advertised (name: %s,domain name: %s)",
13406 bgp->peer_self->hostname
13407 ? bgp->peer_self->hostname
13408 : "n/a",
13409 bgp->peer_self->domainname
13410 ? bgp->peer_self->domainname
13411 : "n/a");
13412 } else {
13413 vty_out(vty, " not advertised");
13414 }
13415
13416 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13417 vty_out(vty,
13418 " received (name: %s,domain name: %s)",
13419 p->hostname ? p->hostname : "n/a",
13420 p->domainname ? p->domainname : "n/a");
13421 } else {
13422 vty_out(vty, " not received");
13423 }
13424
13425 vty_out(vty, "\n");
13426
13427 /* Graceful Restart */
13428 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
13429 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
13430 vty_out(vty,
13431 " Graceful Restart Capability:");
13432 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV))
13433 vty_out(vty, " advertised");
13434 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
13435 vty_out(vty, " %sreceived",
13436 CHECK_FLAG(p->cap,
13437 PEER_CAP_RESTART_ADV)
13438 ? "and "
13439 : "");
13440 vty_out(vty, "\n");
13441
13442 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13443 int restart_af_count = 0;
13444
13445 vty_out(vty,
13446 " Remote Restart timer is %d seconds\n",
13447 p->v_gr_restart);
13448 vty_out(vty,
13449 " Address families by peer:\n ");
13450
13451 FOREACH_AFI_SAFI (afi, safi)
13452 if (CHECK_FLAG(
13453 p->af_cap[afi]
13454 [safi],
13455 PEER_CAP_RESTART_AF_RCV)) {
13456 vty_out(vty, "%s%s(%s)",
13457 restart_af_count
13458 ? ", "
13459 : "",
13460 get_afi_safi_str(
13461 afi,
13462 safi,
13463 false),
13464 CHECK_FLAG(
13465 p->af_cap
13466 [afi]
13467 [safi],
13468 PEER_CAP_RESTART_AF_PRESERVE_RCV)
13469 ? "preserved"
13470 : "not preserved");
13471 restart_af_count++;
13472 }
13473 if (!restart_af_count)
13474 vty_out(vty, "none");
13475 vty_out(vty, "\n");
13476 }
13477 } /* Graceful Restart */
13478 }
13479 }
13480
13481 /* graceful restart information */
13482 json_object *json_grace = NULL;
13483 json_object *json_grace_send = NULL;
13484 json_object *json_grace_recv = NULL;
13485 int eor_send_af_count = 0;
13486 int eor_receive_af_count = 0;
13487
13488 if (use_json) {
13489 json_grace = json_object_new_object();
13490 json_grace_send = json_object_new_object();
13491 json_grace_recv = json_object_new_object();
13492
13493 if ((peer_established(p)) &&
13494 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13495 FOREACH_AFI_SAFI (afi, safi) {
13496 if (CHECK_FLAG(p->af_sflags[afi][safi],
13497 PEER_STATUS_EOR_SEND)) {
13498 json_object_boolean_true_add(
13499 json_grace_send,
13500 get_afi_safi_str(afi, safi,
13501 true));
13502 eor_send_af_count++;
13503 }
13504 }
13505 FOREACH_AFI_SAFI (afi, safi) {
13506 if (CHECK_FLAG(p->af_sflags[afi][safi],
13507 PEER_STATUS_EOR_RECEIVED)) {
13508 json_object_boolean_true_add(
13509 json_grace_recv,
13510 get_afi_safi_str(afi, safi,
13511 true));
13512 eor_receive_af_count++;
13513 }
13514 }
13515 }
13516 json_object_object_add(json_grace, "endOfRibSend",
13517 json_grace_send);
13518 json_object_object_add(json_grace, "endOfRibRecv",
13519 json_grace_recv);
13520
13521
13522 if (p->t_gr_restart)
13523 json_object_int_add(
13524 json_grace, "gracefulRestartTimerMsecs",
13525 thread_timer_remain_second(p->t_gr_restart) *
13526 1000);
13527
13528 if (p->t_gr_stale)
13529 json_object_int_add(
13530 json_grace, "gracefulStalepathTimerMsecs",
13531 thread_timer_remain_second(p->t_gr_stale) *
13532 1000);
13533 /* more gr info in new format */
13534 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json_grace);
13535 json_object_object_add(json_neigh, "gracefulRestartInfo",
13536 json_grace);
13537 } else {
13538 vty_out(vty, " Graceful restart information:\n");
13539 if ((peer_established(p)) &&
13540 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13541
13542 vty_out(vty, " End-of-RIB send: ");
13543 FOREACH_AFI_SAFI (afi, safi) {
13544 if (CHECK_FLAG(p->af_sflags[afi][safi],
13545 PEER_STATUS_EOR_SEND)) {
13546 vty_out(vty, "%s%s",
13547 eor_send_af_count ? ", " : "",
13548 get_afi_safi_str(afi, safi,
13549 false));
13550 eor_send_af_count++;
13551 }
13552 }
13553 vty_out(vty, "\n");
13554 vty_out(vty, " End-of-RIB received: ");
13555 FOREACH_AFI_SAFI (afi, safi) {
13556 if (CHECK_FLAG(p->af_sflags[afi][safi],
13557 PEER_STATUS_EOR_RECEIVED)) {
13558 vty_out(vty, "%s%s",
13559 eor_receive_af_count ? ", "
13560 : "",
13561 get_afi_safi_str(afi, safi,
13562 false));
13563 eor_receive_af_count++;
13564 }
13565 }
13566 vty_out(vty, "\n");
13567 }
13568
13569 if (p->t_gr_restart)
13570 vty_out(vty,
13571 " The remaining time of restart timer is %ld\n",
13572 thread_timer_remain_second(p->t_gr_restart));
13573
13574 if (p->t_gr_stale)
13575 vty_out(vty,
13576 " The remaining time of stalepath timer is %ld\n",
13577 thread_timer_remain_second(p->t_gr_stale));
13578
13579 /* more gr info in new format */
13580 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, NULL);
13581 }
13582
13583 if (use_json) {
13584 json_object *json_stat = NULL;
13585 json_stat = json_object_new_object();
13586 /* Packet counts. */
13587
13588 atomic_size_t outq_count, inq_count;
13589 outq_count = atomic_load_explicit(&p->obuf->count,
13590 memory_order_relaxed);
13591 inq_count = atomic_load_explicit(&p->ibuf->count,
13592 memory_order_relaxed);
13593
13594 json_object_int_add(json_stat, "depthInq",
13595 (unsigned long)inq_count);
13596 json_object_int_add(json_stat, "depthOutq",
13597 (unsigned long)outq_count);
13598 json_object_int_add(json_stat, "opensSent",
13599 atomic_load_explicit(&p->open_out,
13600 memory_order_relaxed));
13601 json_object_int_add(json_stat, "opensRecv",
13602 atomic_load_explicit(&p->open_in,
13603 memory_order_relaxed));
13604 json_object_int_add(json_stat, "notificationsSent",
13605 atomic_load_explicit(&p->notify_out,
13606 memory_order_relaxed));
13607 json_object_int_add(json_stat, "notificationsRecv",
13608 atomic_load_explicit(&p->notify_in,
13609 memory_order_relaxed));
13610 json_object_int_add(json_stat, "updatesSent",
13611 atomic_load_explicit(&p->update_out,
13612 memory_order_relaxed));
13613 json_object_int_add(json_stat, "updatesRecv",
13614 atomic_load_explicit(&p->update_in,
13615 memory_order_relaxed));
13616 json_object_int_add(json_stat, "keepalivesSent",
13617 atomic_load_explicit(&p->keepalive_out,
13618 memory_order_relaxed));
13619 json_object_int_add(json_stat, "keepalivesRecv",
13620 atomic_load_explicit(&p->keepalive_in,
13621 memory_order_relaxed));
13622 json_object_int_add(json_stat, "routeRefreshSent",
13623 atomic_load_explicit(&p->refresh_out,
13624 memory_order_relaxed));
13625 json_object_int_add(json_stat, "routeRefreshRecv",
13626 atomic_load_explicit(&p->refresh_in,
13627 memory_order_relaxed));
13628 json_object_int_add(json_stat, "capabilitySent",
13629 atomic_load_explicit(&p->dynamic_cap_out,
13630 memory_order_relaxed));
13631 json_object_int_add(json_stat, "capabilityRecv",
13632 atomic_load_explicit(&p->dynamic_cap_in,
13633 memory_order_relaxed));
13634 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
13635 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
13636 json_object_object_add(json_neigh, "messageStats", json_stat);
13637 } else {
13638 atomic_size_t outq_count, inq_count, open_out, open_in,
13639 notify_out, notify_in, update_out, update_in,
13640 keepalive_out, keepalive_in, refresh_out, refresh_in,
13641 dynamic_cap_out, dynamic_cap_in;
13642 outq_count = atomic_load_explicit(&p->obuf->count,
13643 memory_order_relaxed);
13644 inq_count = atomic_load_explicit(&p->ibuf->count,
13645 memory_order_relaxed);
13646 open_out = atomic_load_explicit(&p->open_out,
13647 memory_order_relaxed);
13648 open_in =
13649 atomic_load_explicit(&p->open_in, memory_order_relaxed);
13650 notify_out = atomic_load_explicit(&p->notify_out,
13651 memory_order_relaxed);
13652 notify_in = atomic_load_explicit(&p->notify_in,
13653 memory_order_relaxed);
13654 update_out = atomic_load_explicit(&p->update_out,
13655 memory_order_relaxed);
13656 update_in = atomic_load_explicit(&p->update_in,
13657 memory_order_relaxed);
13658 keepalive_out = atomic_load_explicit(&p->keepalive_out,
13659 memory_order_relaxed);
13660 keepalive_in = atomic_load_explicit(&p->keepalive_in,
13661 memory_order_relaxed);
13662 refresh_out = atomic_load_explicit(&p->refresh_out,
13663 memory_order_relaxed);
13664 refresh_in = atomic_load_explicit(&p->refresh_in,
13665 memory_order_relaxed);
13666 dynamic_cap_out = atomic_load_explicit(&p->dynamic_cap_out,
13667 memory_order_relaxed);
13668 dynamic_cap_in = atomic_load_explicit(&p->dynamic_cap_in,
13669 memory_order_relaxed);
13670
13671 /* Packet counts. */
13672 vty_out(vty, " Message statistics:\n");
13673 vty_out(vty, " Inq depth is %zu\n", inq_count);
13674 vty_out(vty, " Outq depth is %zu\n", outq_count);
13675 vty_out(vty, " Sent Rcvd\n");
13676 vty_out(vty, " Opens: %10zu %10zu\n", open_out,
13677 open_in);
13678 vty_out(vty, " Notifications: %10zu %10zu\n", notify_out,
13679 notify_in);
13680 vty_out(vty, " Updates: %10zu %10zu\n", update_out,
13681 update_in);
13682 vty_out(vty, " Keepalives: %10zu %10zu\n", keepalive_out,
13683 keepalive_in);
13684 vty_out(vty, " Route Refresh: %10zu %10zu\n", refresh_out,
13685 refresh_in);
13686 vty_out(vty, " Capability: %10zu %10zu\n",
13687 dynamic_cap_out, dynamic_cap_in);
13688 vty_out(vty, " Total: %10u %10u\n",
13689 (uint32_t)PEER_TOTAL_TX(p), (uint32_t)PEER_TOTAL_RX(p));
13690 }
13691
13692 if (use_json) {
13693 /* advertisement-interval */
13694 json_object_int_add(json_neigh,
13695 "minBtwnAdvertisementRunsTimerMsecs",
13696 p->v_routeadv * 1000);
13697
13698 /* Update-source. */
13699 if (p->update_if || p->update_source) {
13700 if (p->update_if)
13701 json_object_string_add(json_neigh,
13702 "updateSource",
13703 p->update_if);
13704 else if (p->update_source)
13705 json_object_string_add(
13706 json_neigh, "updateSource",
13707 sockunion2str(p->update_source, buf1,
13708 SU_ADDRSTRLEN));
13709 }
13710 } else {
13711 /* advertisement-interval */
13712 vty_out(vty,
13713 " Minimum time between advertisement runs is %d seconds\n",
13714 p->v_routeadv);
13715
13716 /* Update-source. */
13717 if (p->update_if || p->update_source) {
13718 vty_out(vty, " Update source is ");
13719 if (p->update_if)
13720 vty_out(vty, "%s", p->update_if);
13721 else if (p->update_source)
13722 vty_out(vty, "%s",
13723 sockunion2str(p->update_source, buf1,
13724 SU_ADDRSTRLEN));
13725 vty_out(vty, "\n");
13726 }
13727
13728 vty_out(vty, "\n");
13729 }
13730
13731 /* Address Family Information */
13732 json_object *json_hold = NULL;
13733
13734 if (use_json)
13735 json_hold = json_object_new_object();
13736
13737 FOREACH_AFI_SAFI (afi, safi)
13738 if (p->afc[afi][safi])
13739 bgp_show_peer_afi(vty, p, afi, safi, use_json,
13740 json_hold);
13741
13742 if (use_json) {
13743 json_object_object_add(json_neigh, "addressFamilyInfo",
13744 json_hold);
13745 json_object_int_add(json_neigh, "connectionsEstablished",
13746 p->established);
13747 json_object_int_add(json_neigh, "connectionsDropped",
13748 p->dropped);
13749 } else
13750 vty_out(vty, " Connections established %d; dropped %d\n",
13751 p->established, p->dropped);
13752
13753 if (!p->last_reset) {
13754 if (use_json)
13755 json_object_string_add(json_neigh, "lastReset",
13756 "never");
13757 else
13758 vty_out(vty, " Last reset never\n");
13759 } else {
13760 if (use_json) {
13761 time_t uptime;
13762 struct tm tm;
13763
13764 uptime = bgp_clock();
13765 uptime -= p->resettime;
13766 gmtime_r(&uptime, &tm);
13767
13768 json_object_int_add(json_neigh, "lastResetTimerMsecs",
13769 (tm.tm_sec * 1000)
13770 + (tm.tm_min * 60000)
13771 + (tm.tm_hour * 3600000));
13772 bgp_show_peer_reset(NULL, p, json_neigh, true);
13773 } else {
13774 vty_out(vty, " Last reset %s, ",
13775 peer_uptime(p->resettime, timebuf,
13776 BGP_UPTIME_LEN, 0, NULL));
13777
13778 bgp_show_peer_reset(vty, p, NULL, false);
13779 if (p->last_reset_cause_size) {
13780 msg = p->last_reset_cause;
13781 vty_out(vty,
13782 " Message received that caused BGP to send a NOTIFICATION:\n ");
13783 for (i = 1; i <= p->last_reset_cause_size;
13784 i++) {
13785 vty_out(vty, "%02X", *msg++);
13786
13787 if (i != p->last_reset_cause_size) {
13788 if (i % 16 == 0) {
13789 vty_out(vty, "\n ");
13790 } else if (i % 4 == 0) {
13791 vty_out(vty, " ");
13792 }
13793 }
13794 }
13795 vty_out(vty, "\n");
13796 }
13797 }
13798 }
13799
13800 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
13801 if (use_json)
13802 json_object_boolean_true_add(json_neigh,
13803 "prefixesConfigExceedMax");
13804 else
13805 vty_out(vty,
13806 " Peer had exceeded the max. no. of prefixes configured.\n");
13807
13808 if (p->t_pmax_restart) {
13809 if (use_json) {
13810 json_object_boolean_true_add(
13811 json_neigh, "reducePrefixNumFrom");
13812 json_object_int_add(json_neigh,
13813 "restartInTimerMsec",
13814 thread_timer_remain_second(
13815 p->t_pmax_restart)
13816 * 1000);
13817 } else
13818 vty_out(vty,
13819 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
13820 p->host, thread_timer_remain_second(
13821 p->t_pmax_restart));
13822 } else {
13823 if (use_json)
13824 json_object_boolean_true_add(
13825 json_neigh,
13826 "reducePrefixNumAndClearIpBgp");
13827 else
13828 vty_out(vty,
13829 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
13830 p->host);
13831 }
13832 }
13833
13834 /* EBGP Multihop and GTSM */
13835 if (p->sort != BGP_PEER_IBGP) {
13836 if (use_json) {
13837 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
13838 json_object_int_add(json_neigh,
13839 "externalBgpNbrMaxHopsAway",
13840 p->gtsm_hops);
13841 else if (p->ttl > BGP_DEFAULT_TTL)
13842 json_object_int_add(json_neigh,
13843 "externalBgpNbrMaxHopsAway",
13844 p->ttl);
13845 } else {
13846 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
13847 vty_out(vty,
13848 " External BGP neighbor may be up to %d hops away.\n",
13849 p->gtsm_hops);
13850 else if (p->ttl > BGP_DEFAULT_TTL)
13851 vty_out(vty,
13852 " External BGP neighbor may be up to %d hops away.\n",
13853 p->ttl);
13854 }
13855 } else {
13856 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED) {
13857 if (use_json)
13858 json_object_int_add(json_neigh,
13859 "internalBgpNbrMaxHopsAway",
13860 p->gtsm_hops);
13861 else
13862 vty_out(vty,
13863 " Internal BGP neighbor may be up to %d hops away.\n",
13864 p->gtsm_hops);
13865 }
13866 }
13867
13868 /* Local address. */
13869 if (p->su_local) {
13870 if (use_json) {
13871 json_object_string_add(json_neigh, "hostLocal",
13872 sockunion2str(p->su_local, buf1,
13873 SU_ADDRSTRLEN));
13874 json_object_int_add(json_neigh, "portLocal",
13875 ntohs(p->su_local->sin.sin_port));
13876 } else
13877 vty_out(vty, "Local host: %s, Local port: %d\n",
13878 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
13879 ntohs(p->su_local->sin.sin_port));
13880 }
13881
13882 /* Remote address. */
13883 if (p->su_remote) {
13884 if (use_json) {
13885 json_object_string_add(json_neigh, "hostForeign",
13886 sockunion2str(p->su_remote, buf1,
13887 SU_ADDRSTRLEN));
13888 json_object_int_add(json_neigh, "portForeign",
13889 ntohs(p->su_remote->sin.sin_port));
13890 } else
13891 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
13892 sockunion2str(p->su_remote, buf1,
13893 SU_ADDRSTRLEN),
13894 ntohs(p->su_remote->sin.sin_port));
13895 }
13896
13897 /* Nexthop display. */
13898 if (p->su_local) {
13899 if (use_json) {
13900 json_object_string_addf(json_neigh, "nexthop", "%pI4",
13901 &p->nexthop.v4);
13902 json_object_string_addf(json_neigh, "nexthopGlobal",
13903 "%pI6", &p->nexthop.v6_global);
13904 json_object_string_addf(json_neigh, "nexthopLocal",
13905 "%pI6", &p->nexthop.v6_local);
13906 if (p->shared_network)
13907 json_object_string_add(json_neigh,
13908 "bgpConnection",
13909 "sharedNetwork");
13910 else
13911 json_object_string_add(json_neigh,
13912 "bgpConnection",
13913 "nonSharedNetwork");
13914 } else {
13915 vty_out(vty, "Nexthop: %s\n",
13916 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
13917 sizeof(buf1)));
13918 vty_out(vty, "Nexthop global: %s\n",
13919 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
13920 sizeof(buf1)));
13921 vty_out(vty, "Nexthop local: %s\n",
13922 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
13923 sizeof(buf1)));
13924 vty_out(vty, "BGP connection: %s\n",
13925 p->shared_network ? "shared network"
13926 : "non shared network");
13927 }
13928 }
13929
13930 /* Timer information. */
13931 if (use_json) {
13932 json_object_int_add(json_neigh, "connectRetryTimer",
13933 p->v_connect);
13934 if (peer_established(p) && p->rtt)
13935 json_object_int_add(json_neigh, "estimatedRttInMsecs",
13936 p->rtt);
13937 if (p->t_start)
13938 json_object_int_add(
13939 json_neigh, "nextStartTimerDueInMsecs",
13940 thread_timer_remain_second(p->t_start) * 1000);
13941 if (p->t_connect)
13942 json_object_int_add(
13943 json_neigh, "nextConnectTimerDueInMsecs",
13944 thread_timer_remain_second(p->t_connect)
13945 * 1000);
13946 if (p->t_routeadv) {
13947 json_object_int_add(json_neigh, "mraiInterval",
13948 p->v_routeadv);
13949 json_object_int_add(
13950 json_neigh, "mraiTimerExpireInMsecs",
13951 thread_timer_remain_second(p->t_routeadv)
13952 * 1000);
13953 }
13954 if (p->password)
13955 json_object_int_add(json_neigh, "authenticationEnabled",
13956 1);
13957
13958 if (p->t_read)
13959 json_object_string_add(json_neigh, "readThread", "on");
13960 else
13961 json_object_string_add(json_neigh, "readThread", "off");
13962
13963 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
13964 json_object_string_add(json_neigh, "writeThread", "on");
13965 else
13966 json_object_string_add(json_neigh, "writeThread",
13967 "off");
13968 } else {
13969 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
13970 p->v_connect);
13971 if (peer_established(p) && p->rtt)
13972 vty_out(vty, "Estimated round trip time: %d ms\n",
13973 p->rtt);
13974 if (p->t_start)
13975 vty_out(vty, "Next start timer due in %ld seconds\n",
13976 thread_timer_remain_second(p->t_start));
13977 if (p->t_connect)
13978 vty_out(vty, "Next connect timer due in %ld seconds\n",
13979 thread_timer_remain_second(p->t_connect));
13980 if (p->t_routeadv)
13981 vty_out(vty,
13982 "MRAI (interval %u) timer expires in %ld seconds\n",
13983 p->v_routeadv,
13984 thread_timer_remain_second(p->t_routeadv));
13985 if (p->password)
13986 vty_out(vty, "Peer Authentication Enabled\n");
13987
13988 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
13989 p->t_read ? "on" : "off",
13990 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
13991 ? "on"
13992 : "off", p->fd);
13993 }
13994
13995 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
13996 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
13997 bgp_capability_vty_out(vty, p, use_json, json_neigh);
13998
13999 if (!use_json)
14000 vty_out(vty, "\n");
14001
14002 /* BFD information. */
14003 if (p->bfd_config)
14004 bgp_bfd_show_info(vty, p, json_neigh);
14005
14006 if (use_json) {
14007 if (p->conf_if) /* Configured interface name. */
14008 json_object_object_add(json, p->conf_if, json_neigh);
14009 else /* Configured IP address. */
14010 json_object_object_add(json, p->host, json_neigh);
14011 }
14012 }
14013
14014 static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
14015 enum show_type type,
14016 union sockunion *su,
14017 const char *conf_if, afi_t afi,
14018 bool use_json)
14019 {
14020 struct listnode *node, *nnode;
14021 struct peer *peer;
14022 int find = 0;
14023 safi_t safi = SAFI_UNICAST;
14024 json_object *json = NULL;
14025 json_object *json_neighbor = NULL;
14026
14027 if (use_json) {
14028 json = json_object_new_object();
14029 json_neighbor = json_object_new_object();
14030 }
14031
14032 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14033
14034 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14035 continue;
14036
14037 if ((peer->afc[afi][safi]) == 0)
14038 continue;
14039
14040 if (type == show_all) {
14041 bgp_show_peer_gr_status(vty, peer, use_json,
14042 json_neighbor);
14043
14044 if (use_json) {
14045 json_object_object_add(json, peer->host,
14046 json_neighbor);
14047 json_neighbor = NULL;
14048 }
14049
14050 } else if (type == show_peer) {
14051 if (conf_if) {
14052 if ((peer->conf_if
14053 && !strcmp(peer->conf_if, conf_if))
14054 || (peer->hostname
14055 && !strcmp(peer->hostname, conf_if))) {
14056 find = 1;
14057 bgp_show_peer_gr_status(vty, peer,
14058 use_json,
14059 json_neighbor);
14060 }
14061 } else {
14062 if (sockunion_same(&peer->su, su)) {
14063 find = 1;
14064 bgp_show_peer_gr_status(vty, peer,
14065 use_json,
14066 json_neighbor);
14067 }
14068 }
14069 if (use_json && find)
14070 json_object_object_add(json, peer->host,
14071 json_neighbor);
14072 }
14073
14074 if (find) {
14075 json_neighbor = NULL;
14076 break;
14077 }
14078 }
14079
14080 if (type == show_peer && !find) {
14081 if (use_json)
14082 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14083 else
14084 vty_out(vty, "%% No such neighbor\n");
14085 }
14086 if (use_json) {
14087 if (json_neighbor)
14088 json_object_free(json_neighbor);
14089 vty_json(vty, json);
14090 } else {
14091 vty_out(vty, "\n");
14092 }
14093
14094 return CMD_SUCCESS;
14095 }
14096
14097 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
14098 enum show_type type, union sockunion *su,
14099 const char *conf_if, bool use_json,
14100 json_object *json)
14101 {
14102 struct listnode *node, *nnode;
14103 struct peer *peer;
14104 int find = 0;
14105 bool nbr_output = false;
14106 afi_t afi = AFI_MAX;
14107 safi_t safi = SAFI_MAX;
14108
14109 if (type == show_ipv4_peer || type == show_ipv4_all) {
14110 afi = AFI_IP;
14111 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
14112 afi = AFI_IP6;
14113 }
14114
14115 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14116 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14117 continue;
14118
14119 switch (type) {
14120 case show_all:
14121 bgp_show_peer(vty, peer, use_json, json);
14122 nbr_output = true;
14123 break;
14124 case show_peer:
14125 if (conf_if) {
14126 if ((peer->conf_if
14127 && !strcmp(peer->conf_if, conf_if))
14128 || (peer->hostname
14129 && !strcmp(peer->hostname, conf_if))) {
14130 find = 1;
14131 bgp_show_peer(vty, peer, use_json,
14132 json);
14133 }
14134 } else {
14135 if (sockunion_same(&peer->su, su)) {
14136 find = 1;
14137 bgp_show_peer(vty, peer, use_json,
14138 json);
14139 }
14140 }
14141 break;
14142 case show_ipv4_peer:
14143 case show_ipv6_peer:
14144 FOREACH_SAFI (safi) {
14145 if (peer->afc[afi][safi]) {
14146 if (conf_if) {
14147 if ((peer->conf_if
14148 && !strcmp(peer->conf_if, conf_if))
14149 || (peer->hostname
14150 && !strcmp(peer->hostname, conf_if))) {
14151 find = 1;
14152 bgp_show_peer(vty, peer, use_json,
14153 json);
14154 break;
14155 }
14156 } else {
14157 if (sockunion_same(&peer->su, su)) {
14158 find = 1;
14159 bgp_show_peer(vty, peer, use_json,
14160 json);
14161 break;
14162 }
14163 }
14164 }
14165 }
14166 break;
14167 case show_ipv4_all:
14168 case show_ipv6_all:
14169 FOREACH_SAFI (safi) {
14170 if (peer->afc[afi][safi]) {
14171 bgp_show_peer(vty, peer, use_json, json);
14172 nbr_output = true;
14173 break;
14174 }
14175 }
14176 break;
14177 }
14178 }
14179
14180 if ((type == show_peer || type == show_ipv4_peer ||
14181 type == show_ipv6_peer) && !find) {
14182 if (use_json)
14183 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14184 else
14185 vty_out(vty, "%% No such neighbor in this view/vrf\n");
14186 }
14187
14188 if (type != show_peer && type != show_ipv4_peer &&
14189 type != show_ipv6_peer && !nbr_output && !use_json)
14190 vty_out(vty, "%% No BGP neighbors found\n");
14191
14192 if (use_json) {
14193 vty_out(vty, "%s\n", json_object_to_json_string_ext(
14194 json, JSON_C_TO_STRING_PRETTY));
14195 } else {
14196 vty_out(vty, "\n");
14197 }
14198
14199 return CMD_SUCCESS;
14200 }
14201
14202 static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
14203 enum show_type type,
14204 const char *ip_str,
14205 afi_t afi, bool use_json)
14206 {
14207
14208 int ret;
14209 struct bgp *bgp;
14210 union sockunion su;
14211
14212 bgp = bgp_get_default();
14213
14214 if (!bgp)
14215 return;
14216
14217 if (!use_json)
14218 bgp_show_global_graceful_restart_mode_vty(vty, bgp, use_json,
14219 NULL);
14220
14221 if (ip_str) {
14222 ret = str2sockunion(ip_str, &su);
14223 if (ret < 0)
14224 bgp_show_neighbor_graceful_restart(
14225 vty, bgp, type, NULL, ip_str, afi, use_json);
14226 else
14227 bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
14228 NULL, afi, use_json);
14229 } else
14230 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
14231 afi, use_json);
14232 }
14233
14234 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
14235 enum show_type type,
14236 const char *ip_str,
14237 bool use_json)
14238 {
14239 struct listnode *node, *nnode;
14240 struct bgp *bgp;
14241 union sockunion su;
14242 json_object *json = NULL;
14243 int ret, is_first = 1;
14244 bool nbr_output = false;
14245
14246 if (use_json)
14247 vty_out(vty, "{\n");
14248
14249 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
14250 nbr_output = true;
14251 if (use_json) {
14252 if (!(json = json_object_new_object())) {
14253 flog_err(
14254 EC_BGP_JSON_MEM_ERROR,
14255 "Unable to allocate memory for JSON object");
14256 vty_out(vty,
14257 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
14258 return;
14259 }
14260
14261 json_object_int_add(json, "vrfId",
14262 (bgp->vrf_id == VRF_UNKNOWN)
14263 ? -1
14264 : (int64_t)bgp->vrf_id);
14265 json_object_string_add(
14266 json, "vrfName",
14267 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14268 ? VRF_DEFAULT_NAME
14269 : bgp->name);
14270
14271 if (!is_first)
14272 vty_out(vty, ",\n");
14273 else
14274 is_first = 0;
14275
14276 vty_out(vty, "\"%s\":",
14277 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14278 ? VRF_DEFAULT_NAME
14279 : bgp->name);
14280 } else {
14281 vty_out(vty, "\nInstance %s:\n",
14282 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14283 ? VRF_DEFAULT_NAME
14284 : bgp->name);
14285 }
14286
14287 if (type == show_peer || type == show_ipv4_peer ||
14288 type == show_ipv6_peer) {
14289 ret = str2sockunion(ip_str, &su);
14290 if (ret < 0)
14291 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14292 use_json, json);
14293 else
14294 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14295 use_json, json);
14296 } else {
14297 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
14298 use_json, json);
14299 }
14300 json_object_free(json);
14301 json = NULL;
14302 }
14303
14304 if (use_json)
14305 vty_out(vty, "}\n");
14306 else if (!nbr_output)
14307 vty_out(vty, "%% BGP instance not found\n");
14308 }
14309
14310 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
14311 enum show_type type, const char *ip_str,
14312 bool use_json)
14313 {
14314 int ret;
14315 struct bgp *bgp;
14316 union sockunion su;
14317 json_object *json = NULL;
14318
14319 if (name) {
14320 if (strmatch(name, "all")) {
14321 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
14322 use_json);
14323 return CMD_SUCCESS;
14324 } else {
14325 bgp = bgp_lookup_by_name(name);
14326 if (!bgp) {
14327 if (use_json) {
14328 json = json_object_new_object();
14329 vty_json(vty, json);
14330 } else
14331 vty_out(vty,
14332 "%% BGP instance not found\n");
14333
14334 return CMD_WARNING;
14335 }
14336 }
14337 } else {
14338 bgp = bgp_get_default();
14339 }
14340
14341 if (bgp) {
14342 json = json_object_new_object();
14343 if (ip_str) {
14344 ret = str2sockunion(ip_str, &su);
14345 if (ret < 0)
14346 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14347 use_json, json);
14348 else
14349 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14350 use_json, json);
14351 } else {
14352 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
14353 json);
14354 }
14355 json_object_free(json);
14356 } else {
14357 if (use_json)
14358 vty_out(vty, "{}\n");
14359 else
14360 vty_out(vty, "%% BGP instance not found\n");
14361 }
14362
14363 return CMD_SUCCESS;
14364 }
14365
14366
14367
14368 /* "show [ip] bgp neighbors graceful-restart" commands. */
14369 DEFUN (show_ip_bgp_neighbors_gracrful_restart,
14370 show_ip_bgp_neighbors_graceful_restart_cmd,
14371 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
14372 SHOW_STR
14373 BGP_STR
14374 IP_STR
14375 IPV6_STR
14376 NEIGHBOR_STR
14377 "Neighbor to display information about\n"
14378 "Neighbor to display information about\n"
14379 "Neighbor on BGP configured interface\n"
14380 GR_SHOW
14381 JSON_STR)
14382 {
14383 char *sh_arg = NULL;
14384 enum show_type sh_type;
14385 int idx = 0;
14386 afi_t afi = AFI_MAX;
14387 bool uj = use_json(argc, argv);
14388
14389 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
14390 afi = AFI_MAX;
14391
14392 idx++;
14393
14394 if (argv_find(argv, argc, "A.B.C.D", &idx)
14395 || argv_find(argv, argc, "X:X::X:X", &idx)
14396 || argv_find(argv, argc, "WORD", &idx)) {
14397 sh_type = show_peer;
14398 sh_arg = argv[idx]->arg;
14399 } else
14400 sh_type = show_all;
14401
14402 if (!argv_find(argv, argc, "graceful-restart", &idx))
14403 return CMD_SUCCESS;
14404
14405
14406 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
14407 afi, uj);
14408 }
14409
14410 /* "show [ip] bgp neighbors" commands. */
14411 DEFUN (show_ip_bgp_neighbors,
14412 show_ip_bgp_neighbors_cmd,
14413 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
14414 SHOW_STR
14415 IP_STR
14416 BGP_STR
14417 BGP_INSTANCE_HELP_STR
14418 "Address Family\n"
14419 "Address Family\n"
14420 "Detailed information on TCP and BGP neighbor connections\n"
14421 "Neighbor to display information about\n"
14422 "Neighbor to display information about\n"
14423 "Neighbor on BGP configured interface\n"
14424 JSON_STR)
14425 {
14426 char *vrf = NULL;
14427 char *sh_arg = NULL;
14428 enum show_type sh_type;
14429 afi_t afi = AFI_MAX;
14430
14431 bool uj = use_json(argc, argv);
14432
14433 int idx = 0;
14434
14435 /* [<vrf> VIEWVRFNAME] */
14436 if (argv_find(argv, argc, "vrf", &idx)) {
14437 vrf = argv[idx + 1]->arg;
14438 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
14439 vrf = NULL;
14440 } else if (argv_find(argv, argc, "view", &idx))
14441 /* [<view> VIEWVRFNAME] */
14442 vrf = argv[idx + 1]->arg;
14443
14444 idx++;
14445
14446 if (argv_find(argv, argc, "ipv4", &idx)) {
14447 sh_type = show_ipv4_all;
14448 afi = AFI_IP;
14449 } else if (argv_find(argv, argc, "ipv6", &idx)) {
14450 sh_type = show_ipv6_all;
14451 afi = AFI_IP6;
14452 } else {
14453 sh_type = show_all;
14454 }
14455
14456 if (argv_find(argv, argc, "A.B.C.D", &idx)
14457 || argv_find(argv, argc, "X:X::X:X", &idx)
14458 || argv_find(argv, argc, "WORD", &idx)) {
14459 sh_type = show_peer;
14460 sh_arg = argv[idx]->arg;
14461 }
14462
14463 if (sh_type == show_peer && afi == AFI_IP) {
14464 sh_type = show_ipv4_peer;
14465 } else if (sh_type == show_peer && afi == AFI_IP6) {
14466 sh_type = show_ipv6_peer;
14467 }
14468
14469 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
14470 }
14471
14472 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
14473 paths' and `show ip mbgp paths'. Those functions results are the
14474 same.*/
14475 DEFUN (show_ip_bgp_paths,
14476 show_ip_bgp_paths_cmd,
14477 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
14478 SHOW_STR
14479 IP_STR
14480 BGP_STR
14481 BGP_SAFI_HELP_STR
14482 "Path information\n")
14483 {
14484 vty_out(vty, "Address Refcnt Path\n");
14485 aspath_print_all_vty(vty);
14486 return CMD_SUCCESS;
14487 }
14488
14489 #include "hash.h"
14490
14491 static void community_show_all_iterator(struct hash_bucket *bucket,
14492 struct vty *vty)
14493 {
14494 struct community *com;
14495
14496 com = (struct community *)bucket->data;
14497 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
14498 community_str(com, false, false));
14499 }
14500
14501 /* Show BGP's community internal data. */
14502 DEFUN (show_ip_bgp_community_info,
14503 show_ip_bgp_community_info_cmd,
14504 "show [ip] bgp community-info",
14505 SHOW_STR
14506 IP_STR
14507 BGP_STR
14508 "List all bgp community information\n")
14509 {
14510 vty_out(vty, "Address Refcnt Community\n");
14511
14512 hash_iterate(community_hash(),
14513 (void (*)(struct hash_bucket *,
14514 void *))community_show_all_iterator,
14515 vty);
14516
14517 return CMD_SUCCESS;
14518 }
14519
14520 static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
14521 struct vty *vty)
14522 {
14523 struct lcommunity *lcom;
14524
14525 lcom = (struct lcommunity *)bucket->data;
14526 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
14527 lcommunity_str(lcom, false, false));
14528 }
14529
14530 /* Show BGP's community internal data. */
14531 DEFUN (show_ip_bgp_lcommunity_info,
14532 show_ip_bgp_lcommunity_info_cmd,
14533 "show ip bgp large-community-info",
14534 SHOW_STR
14535 IP_STR
14536 BGP_STR
14537 "List all bgp large-community information\n")
14538 {
14539 vty_out(vty, "Address Refcnt Large-community\n");
14540
14541 hash_iterate(lcommunity_hash(),
14542 (void (*)(struct hash_bucket *,
14543 void *))lcommunity_show_all_iterator,
14544 vty);
14545
14546 return CMD_SUCCESS;
14547 }
14548 /* Graceful Restart */
14549
14550 static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
14551 struct bgp *bgp,
14552 bool use_json,
14553 json_object *json)
14554 {
14555
14556
14557 vty_out(vty, "\n%s", SHOW_GR_HEADER);
14558
14559 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
14560
14561 switch (bgp_global_gr_mode) {
14562
14563 case GLOBAL_HELPER:
14564 vty_out(vty, "Global BGP GR Mode : Helper\n");
14565 break;
14566
14567 case GLOBAL_GR:
14568 vty_out(vty, "Global BGP GR Mode : Restart\n");
14569 break;
14570
14571 case GLOBAL_DISABLE:
14572 vty_out(vty, "Global BGP GR Mode : Disable\n");
14573 break;
14574
14575 case GLOBAL_INVALID:
14576 vty_out(vty,
14577 "Global BGP GR Mode Invalid\n");
14578 break;
14579 }
14580 vty_out(vty, "\n");
14581 }
14582
14583 static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
14584 enum show_type type,
14585 const char *ip_str,
14586 afi_t afi, bool use_json)
14587 {
14588 if ((afi == AFI_MAX) && (ip_str == NULL)) {
14589 afi = AFI_IP;
14590
14591 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
14592
14593 bgp_show_neighbor_graceful_restart_vty(
14594 vty, type, ip_str, afi, use_json);
14595 afi++;
14596 }
14597 } else if (afi != AFI_MAX) {
14598 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
14599 use_json);
14600 } else {
14601 return CMD_ERR_INCOMPLETE;
14602 }
14603
14604 return CMD_SUCCESS;
14605 }
14606 /* Graceful Restart */
14607
14608 DEFUN (show_ip_bgp_attr_info,
14609 show_ip_bgp_attr_info_cmd,
14610 "show [ip] bgp attribute-info",
14611 SHOW_STR
14612 IP_STR
14613 BGP_STR
14614 "List all bgp attribute information\n")
14615 {
14616 attr_show_all(vty);
14617 return CMD_SUCCESS;
14618 }
14619
14620 static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
14621 afi_t afi, safi_t safi,
14622 bool use_json, json_object *json)
14623 {
14624 struct bgp *bgp;
14625 struct listnode *node;
14626 char *vname;
14627 char buf1[INET6_ADDRSTRLEN];
14628 char *ecom_str;
14629 vpn_policy_direction_t dir;
14630
14631 if (json) {
14632 json_object *json_import_vrfs = NULL;
14633 json_object *json_export_vrfs = NULL;
14634
14635 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
14636
14637 if (!bgp) {
14638 vty_json(vty, json);
14639
14640 return CMD_WARNING;
14641 }
14642
14643 /* Provide context for the block */
14644 json_object_string_add(json, "vrf", name ? name : "default");
14645 json_object_string_add(json, "afiSafi",
14646 get_afi_safi_str(afi, safi, true));
14647
14648 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14649 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
14650 json_object_string_add(json, "importFromVrfs", "none");
14651 json_object_string_add(json, "importRts", "none");
14652 } else {
14653 json_import_vrfs = json_object_new_array();
14654
14655 for (ALL_LIST_ELEMENTS_RO(
14656 bgp->vpn_policy[afi].import_vrf,
14657 node, vname))
14658 json_object_array_add(json_import_vrfs,
14659 json_object_new_string(vname));
14660
14661 json_object_object_add(json, "importFromVrfs",
14662 json_import_vrfs);
14663 dir = BGP_VPN_POLICY_DIR_FROMVPN;
14664 if (bgp->vpn_policy[afi].rtlist[dir]) {
14665 ecom_str = ecommunity_ecom2str(
14666 bgp->vpn_policy[afi].rtlist[dir],
14667 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
14668 json_object_string_add(json, "importRts",
14669 ecom_str);
14670 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14671 } else
14672 json_object_string_add(json, "importRts",
14673 "none");
14674 }
14675
14676 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14677 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
14678 json_object_string_add(json, "exportToVrfs", "none");
14679 json_object_string_add(json, "routeDistinguisher",
14680 "none");
14681 json_object_string_add(json, "exportRts", "none");
14682 } else {
14683 json_export_vrfs = json_object_new_array();
14684
14685 for (ALL_LIST_ELEMENTS_RO(
14686 bgp->vpn_policy[afi].export_vrf,
14687 node, vname))
14688 json_object_array_add(json_export_vrfs,
14689 json_object_new_string(vname));
14690 json_object_object_add(json, "exportToVrfs",
14691 json_export_vrfs);
14692 json_object_string_add(json, "routeDistinguisher",
14693 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
14694 buf1, RD_ADDRSTRLEN));
14695
14696 dir = BGP_VPN_POLICY_DIR_TOVPN;
14697 if (bgp->vpn_policy[afi].rtlist[dir]) {
14698 ecom_str = ecommunity_ecom2str(
14699 bgp->vpn_policy[afi].rtlist[dir],
14700 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
14701 json_object_string_add(json, "exportRts",
14702 ecom_str);
14703 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14704 } else
14705 json_object_string_add(json, "exportRts",
14706 "none");
14707 }
14708
14709 if (use_json) {
14710 vty_json(vty, json);
14711 }
14712 } else {
14713 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
14714
14715 if (!bgp) {
14716 vty_out(vty, "%% No such BGP instance exist\n");
14717 return CMD_WARNING;
14718 }
14719
14720 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14721 BGP_CONFIG_VRF_TO_VRF_IMPORT))
14722 vty_out(vty,
14723 "This VRF is not importing %s routes from any other VRF\n",
14724 get_afi_safi_str(afi, safi, false));
14725 else {
14726 vty_out(vty,
14727 "This VRF is importing %s routes from the following VRFs:\n",
14728 get_afi_safi_str(afi, safi, false));
14729
14730 for (ALL_LIST_ELEMENTS_RO(
14731 bgp->vpn_policy[afi].import_vrf,
14732 node, vname))
14733 vty_out(vty, " %s\n", vname);
14734
14735 dir = BGP_VPN_POLICY_DIR_FROMVPN;
14736 ecom_str = NULL;
14737 if (bgp->vpn_policy[afi].rtlist[dir]) {
14738 ecom_str = ecommunity_ecom2str(
14739 bgp->vpn_policy[afi].rtlist[dir],
14740 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
14741 vty_out(vty, "Import RT(s): %s\n", ecom_str);
14742
14743 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14744 } else
14745 vty_out(vty, "Import RT(s):\n");
14746 }
14747
14748 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14749 BGP_CONFIG_VRF_TO_VRF_EXPORT))
14750 vty_out(vty,
14751 "This VRF is not exporting %s routes to any other VRF\n",
14752 get_afi_safi_str(afi, safi, false));
14753 else {
14754 vty_out(vty,
14755 "This VRF is exporting %s routes to the following VRFs:\n",
14756 get_afi_safi_str(afi, safi, false));
14757
14758 for (ALL_LIST_ELEMENTS_RO(
14759 bgp->vpn_policy[afi].export_vrf,
14760 node, vname))
14761 vty_out(vty, " %s\n", vname);
14762
14763 vty_out(vty, "RD: %s\n",
14764 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
14765 buf1, RD_ADDRSTRLEN));
14766
14767 dir = BGP_VPN_POLICY_DIR_TOVPN;
14768 if (bgp->vpn_policy[afi].rtlist[dir]) {
14769 ecom_str = ecommunity_ecom2str(
14770 bgp->vpn_policy[afi].rtlist[dir],
14771 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
14772 vty_out(vty, "Export RT: %s\n", ecom_str);
14773 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14774 } else
14775 vty_out(vty, "Import RT(s):\n");
14776 }
14777 }
14778
14779 return CMD_SUCCESS;
14780 }
14781
14782 static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
14783 safi_t safi, bool use_json)
14784 {
14785 struct listnode *node, *nnode;
14786 struct bgp *bgp;
14787 char *vrf_name = NULL;
14788 json_object *json = NULL;
14789 json_object *json_vrf = NULL;
14790 json_object *json_vrfs = NULL;
14791
14792 if (use_json) {
14793 json = json_object_new_object();
14794 json_vrfs = json_object_new_object();
14795 }
14796
14797 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
14798
14799 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
14800 vrf_name = bgp->name;
14801
14802 if (use_json) {
14803 json_vrf = json_object_new_object();
14804 } else {
14805 vty_out(vty, "\nInstance %s:\n",
14806 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14807 ? VRF_DEFAULT_NAME : bgp->name);
14808 }
14809 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
14810 if (use_json) {
14811 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14812 json_object_object_add(json_vrfs,
14813 VRF_DEFAULT_NAME, json_vrf);
14814 else
14815 json_object_object_add(json_vrfs, vrf_name,
14816 json_vrf);
14817 }
14818 }
14819
14820 if (use_json) {
14821 json_object_object_add(json, "vrfs", json_vrfs);
14822 vty_json(vty, json);
14823 }
14824
14825 return CMD_SUCCESS;
14826 }
14827
14828 /* "show [ip] bgp route-leak" command. */
14829 DEFUN (show_ip_bgp_route_leak,
14830 show_ip_bgp_route_leak_cmd,
14831 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
14832 SHOW_STR
14833 IP_STR
14834 BGP_STR
14835 BGP_INSTANCE_HELP_STR
14836 BGP_AFI_HELP_STR
14837 BGP_SAFI_HELP_STR
14838 "Route leaking information\n"
14839 JSON_STR)
14840 {
14841 char *vrf = NULL;
14842 afi_t afi = AFI_MAX;
14843 safi_t safi = SAFI_MAX;
14844
14845 bool uj = use_json(argc, argv);
14846 int idx = 0;
14847 json_object *json = NULL;
14848
14849 /* show [ip] bgp */
14850 if (argv_find(argv, argc, "ip", &idx)) {
14851 afi = AFI_IP;
14852 safi = SAFI_UNICAST;
14853 }
14854 /* [vrf VIEWVRFNAME] */
14855 if (argv_find(argv, argc, "view", &idx)) {
14856 vty_out(vty,
14857 "%% This command is not applicable to BGP views\n");
14858 return CMD_WARNING;
14859 }
14860
14861 if (argv_find(argv, argc, "vrf", &idx)) {
14862 vrf = argv[idx + 1]->arg;
14863 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
14864 vrf = NULL;
14865 }
14866 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
14867 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
14868 argv_find_and_parse_safi(argv, argc, &idx, &safi);
14869
14870 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
14871 vty_out(vty,
14872 "%% This command is applicable only for unicast ipv4|ipv6\n");
14873 return CMD_WARNING;
14874 }
14875
14876 if (vrf && strmatch(vrf, "all"))
14877 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
14878
14879 if (uj)
14880 json = json_object_new_object();
14881
14882 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
14883 }
14884
14885 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
14886 safi_t safi)
14887 {
14888 struct listnode *node, *nnode;
14889 struct bgp *bgp;
14890
14891 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
14892 vty_out(vty, "\nInstance %s:\n",
14893 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14894 ? VRF_DEFAULT_NAME
14895 : bgp->name);
14896 update_group_show(bgp, afi, safi, vty, 0);
14897 }
14898 }
14899
14900 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
14901 int safi, uint64_t subgrp_id)
14902 {
14903 struct bgp *bgp;
14904
14905 if (name) {
14906 if (strmatch(name, "all")) {
14907 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
14908 return CMD_SUCCESS;
14909 } else {
14910 bgp = bgp_lookup_by_name(name);
14911 }
14912 } else {
14913 bgp = bgp_get_default();
14914 }
14915
14916 if (bgp)
14917 update_group_show(bgp, afi, safi, vty, subgrp_id);
14918 return CMD_SUCCESS;
14919 }
14920
14921 DEFUN (show_ip_bgp_updgrps,
14922 show_ip_bgp_updgrps_cmd,
14923 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
14924 SHOW_STR
14925 IP_STR
14926 BGP_STR
14927 BGP_INSTANCE_HELP_STR
14928 BGP_AFI_HELP_STR
14929 BGP_SAFI_WITH_LABEL_HELP_STR
14930 "Detailed info about dynamic update groups\n"
14931 "Specific subgroup to display detailed info for\n")
14932 {
14933 char *vrf = NULL;
14934 afi_t afi = AFI_IP6;
14935 safi_t safi = SAFI_UNICAST;
14936 uint64_t subgrp_id = 0;
14937
14938 int idx = 0;
14939
14940 /* show [ip] bgp */
14941 if (argv_find(argv, argc, "ip", &idx))
14942 afi = AFI_IP;
14943 /* [<vrf> VIEWVRFNAME] */
14944 if (argv_find(argv, argc, "vrf", &idx)) {
14945 vrf = argv[idx + 1]->arg;
14946 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
14947 vrf = NULL;
14948 } else if (argv_find(argv, argc, "view", &idx))
14949 /* [<view> VIEWVRFNAME] */
14950 vrf = argv[idx + 1]->arg;
14951 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
14952 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
14953 argv_find_and_parse_safi(argv, argc, &idx, &safi);
14954 }
14955
14956 /* get subgroup id, if provided */
14957 idx = argc - 1;
14958 if (argv[idx]->type == VARIABLE_TKN)
14959 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
14960
14961 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
14962 }
14963
14964 DEFUN (show_bgp_instance_all_ipv6_updgrps,
14965 show_bgp_instance_all_ipv6_updgrps_cmd,
14966 "show [ip] bgp <view|vrf> all update-groups",
14967 SHOW_STR
14968 IP_STR
14969 BGP_STR
14970 BGP_INSTANCE_ALL_HELP_STR
14971 "Detailed info about dynamic update groups\n")
14972 {
14973 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
14974 return CMD_SUCCESS;
14975 }
14976
14977 DEFUN (show_bgp_l2vpn_evpn_updgrps,
14978 show_bgp_l2vpn_evpn_updgrps_cmd,
14979 "show [ip] bgp l2vpn evpn update-groups",
14980 SHOW_STR
14981 IP_STR
14982 BGP_STR
14983 "l2vpn address family\n"
14984 "evpn sub-address family\n"
14985 "Detailed info about dynamic update groups\n")
14986 {
14987 char *vrf = NULL;
14988 uint64_t subgrp_id = 0;
14989
14990 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
14991 return CMD_SUCCESS;
14992 }
14993
14994 DEFUN (show_bgp_updgrps_stats,
14995 show_bgp_updgrps_stats_cmd,
14996 "show [ip] bgp update-groups statistics",
14997 SHOW_STR
14998 IP_STR
14999 BGP_STR
15000 "Detailed info about dynamic update groups\n"
15001 "Statistics\n")
15002 {
15003 struct bgp *bgp;
15004
15005 bgp = bgp_get_default();
15006 if (bgp)
15007 update_group_show_stats(bgp, vty);
15008
15009 return CMD_SUCCESS;
15010 }
15011
15012 DEFUN (show_bgp_instance_updgrps_stats,
15013 show_bgp_instance_updgrps_stats_cmd,
15014 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
15015 SHOW_STR
15016 IP_STR
15017 BGP_STR
15018 BGP_INSTANCE_HELP_STR
15019 "Detailed info about dynamic update groups\n"
15020 "Statistics\n")
15021 {
15022 int idx_word = 3;
15023 struct bgp *bgp;
15024
15025 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
15026 if (bgp)
15027 update_group_show_stats(bgp, vty);
15028
15029 return CMD_SUCCESS;
15030 }
15031
15032 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
15033 afi_t afi, safi_t safi,
15034 const char *what, uint64_t subgrp_id)
15035 {
15036 struct bgp *bgp;
15037
15038 if (name)
15039 bgp = bgp_lookup_by_name(name);
15040 else
15041 bgp = bgp_get_default();
15042
15043 if (bgp) {
15044 if (!strcmp(what, "advertise-queue"))
15045 update_group_show_adj_queue(bgp, afi, safi, vty,
15046 subgrp_id);
15047 else if (!strcmp(what, "advertised-routes"))
15048 update_group_show_advertised(bgp, afi, safi, vty,
15049 subgrp_id);
15050 else if (!strcmp(what, "packet-queue"))
15051 update_group_show_packet_queue(bgp, afi, safi, vty,
15052 subgrp_id);
15053 }
15054 }
15055
15056 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
15057 show_ip_bgp_instance_updgrps_adj_s_cmd,
15058 "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",
15059 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
15060 BGP_SAFI_HELP_STR
15061 "Detailed info about dynamic update groups\n"
15062 "Specific subgroup to display info for\n"
15063 "Advertisement queue\n"
15064 "Announced routes\n"
15065 "Packet queue\n")
15066 {
15067 uint64_t subgrp_id = 0;
15068 afi_t afiz;
15069 safi_t safiz;
15070 if (sgid)
15071 subgrp_id = strtoull(sgid, NULL, 10);
15072
15073 if (!ip && !afi)
15074 afiz = AFI_IP6;
15075 if (!ip && afi)
15076 afiz = bgp_vty_afi_from_str(afi);
15077 if (ip && !afi)
15078 afiz = AFI_IP;
15079 if (ip && afi) {
15080 afiz = bgp_vty_afi_from_str(afi);
15081 if (afiz != AFI_IP)
15082 vty_out(vty,
15083 "%% Cannot specify both 'ip' and 'ipv6'\n");
15084 return CMD_WARNING;
15085 }
15086
15087 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
15088
15089 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
15090 return CMD_SUCCESS;
15091 }
15092
15093 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group,
15094 json_object *json)
15095 {
15096 struct listnode *node, *nnode;
15097 struct prefix *range;
15098 struct peer *conf;
15099 struct peer *peer;
15100 afi_t afi;
15101 safi_t safi;
15102 const char *peer_status;
15103 int lr_count;
15104 int dynamic;
15105 bool af_cfgd;
15106 json_object *json_peer_group = NULL;
15107 json_object *json_peer_group_afc = NULL;
15108 json_object *json_peer_group_members = NULL;
15109 json_object *json_peer_group_dynamic = NULL;
15110 json_object *json_peer_group_dynamic_af = NULL;
15111 json_object *json_peer_group_ranges = NULL;
15112
15113 conf = group->conf;
15114
15115 if (json) {
15116 json_peer_group = json_object_new_object();
15117 json_peer_group_afc = json_object_new_array();
15118 }
15119
15120 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
15121 if (json)
15122 json_object_int_add(json_peer_group, "remoteAs",
15123 conf->as);
15124 else
15125 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15126 group->name, conf->as);
15127 } else if (conf->as_type == AS_INTERNAL) {
15128 if (json)
15129 json_object_int_add(json_peer_group, "remoteAs",
15130 group->bgp->as);
15131 else
15132 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15133 group->name, group->bgp->as);
15134 } else {
15135 if (!json)
15136 vty_out(vty, "\nBGP peer-group %s\n", group->name);
15137 }
15138
15139 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL)) {
15140 if (json)
15141 json_object_string_add(json_peer_group, "type",
15142 "internal");
15143 else
15144 vty_out(vty, " Peer-group type is internal\n");
15145 } else {
15146 if (json)
15147 json_object_string_add(json_peer_group, "type",
15148 "external");
15149 else
15150 vty_out(vty, " Peer-group type is external\n");
15151 }
15152
15153 /* Display AFs configured. */
15154 if (!json)
15155 vty_out(vty, " Configured address-families:");
15156
15157 FOREACH_AFI_SAFI (afi, safi) {
15158 if (conf->afc[afi][safi]) {
15159 af_cfgd = true;
15160 if (json)
15161 json_object_array_add(
15162 json_peer_group_afc,
15163 json_object_new_string(get_afi_safi_str(
15164 afi, safi, false)));
15165 else
15166 vty_out(vty, " %s;",
15167 get_afi_safi_str(afi, safi, false));
15168 }
15169 }
15170
15171 if (json) {
15172 json_object_object_add(json_peer_group,
15173 "addressFamiliesConfigured",
15174 json_peer_group_afc);
15175 } else {
15176 if (!af_cfgd)
15177 vty_out(vty, " none\n");
15178 else
15179 vty_out(vty, "\n");
15180 }
15181
15182 /* Display listen ranges (for dynamic neighbors), if any */
15183 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
15184 lr_count = listcount(group->listen_range[afi]);
15185 if (lr_count) {
15186 if (json) {
15187 if (!json_peer_group_dynamic)
15188 json_peer_group_dynamic =
15189 json_object_new_object();
15190
15191 json_peer_group_dynamic_af =
15192 json_object_new_object();
15193 json_peer_group_ranges =
15194 json_object_new_array();
15195 json_object_int_add(json_peer_group_dynamic_af,
15196 "count", lr_count);
15197 } else {
15198 vty_out(vty, " %d %s listen range(s)\n",
15199 lr_count, afi2str(afi));
15200 }
15201
15202 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
15203 nnode, range)) {
15204 if (json) {
15205 char buf[BUFSIZ];
15206
15207 snprintfrr(buf, sizeof(buf), "%pFX",
15208 range);
15209
15210 json_object_array_add(
15211 json_peer_group_ranges,
15212 json_object_new_string(buf));
15213 } else {
15214 vty_out(vty, " %pFX\n", range);
15215 }
15216 }
15217
15218 if (json) {
15219 json_object_object_add(
15220 json_peer_group_dynamic_af, "ranges",
15221 json_peer_group_ranges);
15222
15223 json_object_object_add(
15224 json_peer_group_dynamic, afi2str(afi),
15225 json_peer_group_dynamic_af);
15226 }
15227 }
15228 }
15229
15230 if (json_peer_group_dynamic)
15231 json_object_object_add(json_peer_group, "dynamicRanges",
15232 json_peer_group_dynamic);
15233
15234 /* Display group members and their status */
15235 if (listcount(group->peer)) {
15236 if (json)
15237 json_peer_group_members = json_object_new_object();
15238 else
15239 vty_out(vty, " Peer-group members:\n");
15240 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
15241 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
15242 || CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHUTDOWN))
15243 peer_status = "Idle (Admin)";
15244 else if (CHECK_FLAG(peer->sflags,
15245 PEER_STATUS_PREFIX_OVERFLOW))
15246 peer_status = "Idle (PfxCt)";
15247 else
15248 peer_status = lookup_msg(bgp_status_msg,
15249 peer->status, NULL);
15250
15251 dynamic = peer_dynamic_neighbor(peer);
15252
15253 if (json) {
15254 json_object *json_peer_group_member =
15255 json_object_new_object();
15256
15257 json_object_string_add(json_peer_group_member,
15258 "status", peer_status);
15259
15260 if (dynamic)
15261 json_object_boolean_true_add(
15262 json_peer_group_member,
15263 "dynamic");
15264
15265 json_object_object_add(json_peer_group_members,
15266 peer->host,
15267 json_peer_group_member);
15268 } else {
15269 vty_out(vty, " %s %s %s \n", peer->host,
15270 dynamic ? "(dynamic)" : "",
15271 peer_status);
15272 }
15273 }
15274 if (json)
15275 json_object_object_add(json_peer_group, "members",
15276 json_peer_group_members);
15277 }
15278
15279 if (json)
15280 json_object_object_add(json, group->name, json_peer_group);
15281
15282 return CMD_SUCCESS;
15283 }
15284
15285 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
15286 const char *group_name, bool uj)
15287 {
15288 struct bgp *bgp;
15289 struct listnode *node, *nnode;
15290 struct peer_group *group;
15291 bool found = false;
15292 json_object *json = NULL;
15293
15294 if (uj)
15295 json = json_object_new_object();
15296
15297 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15298
15299 if (!bgp) {
15300 if (uj)
15301 vty_json(vty, json);
15302 else
15303 vty_out(vty, "%% BGP instance not found\n");
15304
15305 return CMD_WARNING;
15306 }
15307
15308 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
15309 if (group_name) {
15310 if (strmatch(group->name, group_name)) {
15311 bgp_show_one_peer_group(vty, group, json);
15312 found = true;
15313 break;
15314 }
15315 } else {
15316 bgp_show_one_peer_group(vty, group, json);
15317 }
15318 }
15319
15320 if (group_name && !found && !uj)
15321 vty_out(vty, "%% No such peer-group\n");
15322
15323 if (uj)
15324 vty_json(vty, json);
15325
15326 return CMD_SUCCESS;
15327 }
15328
15329 DEFUN(show_ip_bgp_peer_groups, show_ip_bgp_peer_groups_cmd,
15330 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME] [json]",
15331 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR
15332 "Detailed information on BGP peer groups\n"
15333 "Peer group name\n" JSON_STR)
15334 {
15335 char *vrf, *pg;
15336 int idx = 0;
15337 bool uj = use_json(argc, argv);
15338
15339 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
15340 : NULL;
15341 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
15342
15343 return bgp_show_peer_group_vty(vty, vrf, pg, uj);
15344 }
15345
15346
15347 /* Redistribute VTY commands. */
15348
15349 DEFUN (bgp_redistribute_ipv4,
15350 bgp_redistribute_ipv4_cmd,
15351 "redistribute " FRR_IP_REDIST_STR_BGPD,
15352 "Redistribute information from another routing protocol\n"
15353 FRR_IP_REDIST_HELP_STR_BGPD)
15354 {
15355 VTY_DECLVAR_CONTEXT(bgp, bgp);
15356 int idx_protocol = 1;
15357 int type;
15358
15359 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15360 if (type < 0) {
15361 vty_out(vty, "%% Invalid route type\n");
15362 return CMD_WARNING_CONFIG_FAILED;
15363 }
15364
15365 bgp_redist_add(bgp, AFI_IP, type, 0);
15366 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
15367 }
15368
15369 ALIAS_HIDDEN(
15370 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
15371 "redistribute " FRR_IP_REDIST_STR_BGPD,
15372 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
15373
15374 DEFUN (bgp_redistribute_ipv4_rmap,
15375 bgp_redistribute_ipv4_rmap_cmd,
15376 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
15377 "Redistribute information from another routing protocol\n"
15378 FRR_IP_REDIST_HELP_STR_BGPD
15379 "Route map reference\n"
15380 "Pointer to route-map entries\n")
15381 {
15382 VTY_DECLVAR_CONTEXT(bgp, bgp);
15383 int idx_protocol = 1;
15384 int idx_word = 3;
15385 int type;
15386 struct bgp_redist *red;
15387 bool changed;
15388 struct route_map *route_map = route_map_lookup_warn_noexist(
15389 vty, argv[idx_word]->arg);
15390
15391 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15392 if (type < 0) {
15393 vty_out(vty, "%% Invalid route type\n");
15394 return CMD_WARNING_CONFIG_FAILED;
15395 }
15396
15397 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15398 changed =
15399 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15400 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
15401 }
15402
15403 ALIAS_HIDDEN(
15404 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
15405 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
15406 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15407 "Route map reference\n"
15408 "Pointer to route-map entries\n")
15409
15410 DEFUN (bgp_redistribute_ipv4_metric,
15411 bgp_redistribute_ipv4_metric_cmd,
15412 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15413 "Redistribute information from another routing protocol\n"
15414 FRR_IP_REDIST_HELP_STR_BGPD
15415 "Metric for redistributed routes\n"
15416 "Default metric\n")
15417 {
15418 VTY_DECLVAR_CONTEXT(bgp, bgp);
15419 int idx_protocol = 1;
15420 int idx_number = 3;
15421 int type;
15422 uint32_t metric;
15423 struct bgp_redist *red;
15424 bool changed;
15425
15426 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15427 if (type < 0) {
15428 vty_out(vty, "%% Invalid route type\n");
15429 return CMD_WARNING_CONFIG_FAILED;
15430 }
15431 metric = strtoul(argv[idx_number]->arg, NULL, 10);
15432
15433 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15434 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15435 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
15436 }
15437
15438 ALIAS_HIDDEN(
15439 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
15440 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15441 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15442 "Metric for redistributed routes\n"
15443 "Default metric\n")
15444
15445 DEFUN (bgp_redistribute_ipv4_rmap_metric,
15446 bgp_redistribute_ipv4_rmap_metric_cmd,
15447 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
15448 "Redistribute information from another routing protocol\n"
15449 FRR_IP_REDIST_HELP_STR_BGPD
15450 "Route map reference\n"
15451 "Pointer to route-map entries\n"
15452 "Metric for redistributed routes\n"
15453 "Default metric\n")
15454 {
15455 VTY_DECLVAR_CONTEXT(bgp, bgp);
15456 int idx_protocol = 1;
15457 int idx_word = 3;
15458 int idx_number = 5;
15459 int type;
15460 uint32_t metric;
15461 struct bgp_redist *red;
15462 bool changed;
15463 struct route_map *route_map =
15464 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15465
15466 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15467 if (type < 0) {
15468 vty_out(vty, "%% Invalid route type\n");
15469 return CMD_WARNING_CONFIG_FAILED;
15470 }
15471 metric = strtoul(argv[idx_number]->arg, NULL, 10);
15472
15473 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15474 changed =
15475 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15476 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15477 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
15478 }
15479
15480 ALIAS_HIDDEN(
15481 bgp_redistribute_ipv4_rmap_metric,
15482 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
15483 "redistribute " FRR_IP_REDIST_STR_BGPD
15484 " route-map WORD metric (0-4294967295)",
15485 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15486 "Route map reference\n"
15487 "Pointer to route-map entries\n"
15488 "Metric for redistributed routes\n"
15489 "Default metric\n")
15490
15491 DEFUN (bgp_redistribute_ipv4_metric_rmap,
15492 bgp_redistribute_ipv4_metric_rmap_cmd,
15493 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
15494 "Redistribute information from another routing protocol\n"
15495 FRR_IP_REDIST_HELP_STR_BGPD
15496 "Metric for redistributed routes\n"
15497 "Default metric\n"
15498 "Route map reference\n"
15499 "Pointer to route-map entries\n")
15500 {
15501 VTY_DECLVAR_CONTEXT(bgp, bgp);
15502 int idx_protocol = 1;
15503 int idx_number = 3;
15504 int idx_word = 5;
15505 int type;
15506 uint32_t metric;
15507 struct bgp_redist *red;
15508 bool changed;
15509 struct route_map *route_map =
15510 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15511
15512 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15513 if (type < 0) {
15514 vty_out(vty, "%% Invalid route type\n");
15515 return CMD_WARNING_CONFIG_FAILED;
15516 }
15517 metric = strtoul(argv[idx_number]->arg, NULL, 10);
15518
15519 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15520 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15521 changed |=
15522 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15523 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
15524 }
15525
15526 ALIAS_HIDDEN(
15527 bgp_redistribute_ipv4_metric_rmap,
15528 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
15529 "redistribute " FRR_IP_REDIST_STR_BGPD
15530 " metric (0-4294967295) route-map WORD",
15531 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15532 "Metric for redistributed routes\n"
15533 "Default metric\n"
15534 "Route map reference\n"
15535 "Pointer to route-map entries\n")
15536
15537 DEFUN (bgp_redistribute_ipv4_ospf,
15538 bgp_redistribute_ipv4_ospf_cmd,
15539 "redistribute <ospf|table> (1-65535)",
15540 "Redistribute information from another routing protocol\n"
15541 "Open Shortest Path First (OSPFv2)\n"
15542 "Non-main Kernel Routing Table\n"
15543 "Instance ID/Table ID\n")
15544 {
15545 VTY_DECLVAR_CONTEXT(bgp, bgp);
15546 int idx_ospf_table = 1;
15547 int idx_number = 2;
15548 unsigned short instance;
15549 unsigned short protocol;
15550
15551 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15552
15553 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15554 protocol = ZEBRA_ROUTE_OSPF;
15555 else
15556 protocol = ZEBRA_ROUTE_TABLE;
15557
15558 bgp_redist_add(bgp, AFI_IP, protocol, instance);
15559 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
15560 }
15561
15562 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
15563 "redistribute <ospf|table> (1-65535)",
15564 "Redistribute information from another routing protocol\n"
15565 "Open Shortest Path First (OSPFv2)\n"
15566 "Non-main Kernel Routing Table\n"
15567 "Instance ID/Table ID\n")
15568
15569 DEFUN (bgp_redistribute_ipv4_ospf_rmap,
15570 bgp_redistribute_ipv4_ospf_rmap_cmd,
15571 "redistribute <ospf|table> (1-65535) route-map WORD",
15572 "Redistribute information from another routing protocol\n"
15573 "Open Shortest Path First (OSPFv2)\n"
15574 "Non-main Kernel Routing Table\n"
15575 "Instance ID/Table ID\n"
15576 "Route map reference\n"
15577 "Pointer to route-map entries\n")
15578 {
15579 VTY_DECLVAR_CONTEXT(bgp, bgp);
15580 int idx_ospf_table = 1;
15581 int idx_number = 2;
15582 int idx_word = 4;
15583 struct bgp_redist *red;
15584 unsigned short instance;
15585 int protocol;
15586 bool changed;
15587 struct route_map *route_map =
15588 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15589
15590 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15591 protocol = ZEBRA_ROUTE_OSPF;
15592 else
15593 protocol = ZEBRA_ROUTE_TABLE;
15594
15595 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15596 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
15597 changed =
15598 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15599 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
15600 }
15601
15602 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
15603 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
15604 "redistribute <ospf|table> (1-65535) route-map WORD",
15605 "Redistribute information from another routing protocol\n"
15606 "Open Shortest Path First (OSPFv2)\n"
15607 "Non-main Kernel Routing Table\n"
15608 "Instance ID/Table ID\n"
15609 "Route map reference\n"
15610 "Pointer to route-map entries\n")
15611
15612 DEFUN (bgp_redistribute_ipv4_ospf_metric,
15613 bgp_redistribute_ipv4_ospf_metric_cmd,
15614 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
15615 "Redistribute information from another routing protocol\n"
15616 "Open Shortest Path First (OSPFv2)\n"
15617 "Non-main Kernel Routing Table\n"
15618 "Instance ID/Table ID\n"
15619 "Metric for redistributed routes\n"
15620 "Default metric\n")
15621 {
15622 VTY_DECLVAR_CONTEXT(bgp, bgp);
15623 int idx_ospf_table = 1;
15624 int idx_number = 2;
15625 int idx_number_2 = 4;
15626 uint32_t metric;
15627 struct bgp_redist *red;
15628 unsigned short instance;
15629 int protocol;
15630 bool changed;
15631
15632 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15633 protocol = ZEBRA_ROUTE_OSPF;
15634 else
15635 protocol = ZEBRA_ROUTE_TABLE;
15636
15637 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15638 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
15639
15640 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
15641 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
15642 metric);
15643 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
15644 }
15645
15646 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
15647 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
15648 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
15649 "Redistribute information from another routing protocol\n"
15650 "Open Shortest Path First (OSPFv2)\n"
15651 "Non-main Kernel Routing Table\n"
15652 "Instance ID/Table ID\n"
15653 "Metric for redistributed routes\n"
15654 "Default metric\n")
15655
15656 DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
15657 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
15658 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
15659 "Redistribute information from another routing protocol\n"
15660 "Open Shortest Path First (OSPFv2)\n"
15661 "Non-main Kernel Routing Table\n"
15662 "Instance ID/Table ID\n"
15663 "Route map reference\n"
15664 "Pointer to route-map entries\n"
15665 "Metric for redistributed routes\n"
15666 "Default metric\n")
15667 {
15668 VTY_DECLVAR_CONTEXT(bgp, bgp);
15669 int idx_ospf_table = 1;
15670 int idx_number = 2;
15671 int idx_word = 4;
15672 int idx_number_2 = 6;
15673 uint32_t metric;
15674 struct bgp_redist *red;
15675 unsigned short instance;
15676 int protocol;
15677 bool changed;
15678 struct route_map *route_map =
15679 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15680
15681 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15682 protocol = ZEBRA_ROUTE_OSPF;
15683 else
15684 protocol = ZEBRA_ROUTE_TABLE;
15685
15686 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15687 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
15688
15689 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
15690 changed =
15691 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15692 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
15693 metric);
15694 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
15695 }
15696
15697 ALIAS_HIDDEN(
15698 bgp_redistribute_ipv4_ospf_rmap_metric,
15699 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
15700 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
15701 "Redistribute information from another routing protocol\n"
15702 "Open Shortest Path First (OSPFv2)\n"
15703 "Non-main Kernel Routing Table\n"
15704 "Instance ID/Table ID\n"
15705 "Route map reference\n"
15706 "Pointer to route-map entries\n"
15707 "Metric for redistributed routes\n"
15708 "Default metric\n")
15709
15710 DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
15711 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
15712 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
15713 "Redistribute information from another routing protocol\n"
15714 "Open Shortest Path First (OSPFv2)\n"
15715 "Non-main Kernel Routing Table\n"
15716 "Instance ID/Table ID\n"
15717 "Metric for redistributed routes\n"
15718 "Default metric\n"
15719 "Route map reference\n"
15720 "Pointer to route-map entries\n")
15721 {
15722 VTY_DECLVAR_CONTEXT(bgp, bgp);
15723 int idx_ospf_table = 1;
15724 int idx_number = 2;
15725 int idx_number_2 = 4;
15726 int idx_word = 6;
15727 uint32_t metric;
15728 struct bgp_redist *red;
15729 unsigned short instance;
15730 int protocol;
15731 bool changed;
15732 struct route_map *route_map =
15733 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15734
15735 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15736 protocol = ZEBRA_ROUTE_OSPF;
15737 else
15738 protocol = ZEBRA_ROUTE_TABLE;
15739
15740 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15741 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
15742
15743 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
15744 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
15745 metric);
15746 changed |=
15747 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15748 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
15749 }
15750
15751 ALIAS_HIDDEN(
15752 bgp_redistribute_ipv4_ospf_metric_rmap,
15753 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
15754 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
15755 "Redistribute information from another routing protocol\n"
15756 "Open Shortest Path First (OSPFv2)\n"
15757 "Non-main Kernel Routing Table\n"
15758 "Instance ID/Table ID\n"
15759 "Metric for redistributed routes\n"
15760 "Default metric\n"
15761 "Route map reference\n"
15762 "Pointer to route-map entries\n")
15763
15764 DEFUN (no_bgp_redistribute_ipv4_ospf,
15765 no_bgp_redistribute_ipv4_ospf_cmd,
15766 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
15767 NO_STR
15768 "Redistribute information from another routing protocol\n"
15769 "Open Shortest Path First (OSPFv2)\n"
15770 "Non-main Kernel Routing Table\n"
15771 "Instance ID/Table ID\n"
15772 "Metric for redistributed routes\n"
15773 "Default metric\n"
15774 "Route map reference\n"
15775 "Pointer to route-map entries\n")
15776 {
15777 VTY_DECLVAR_CONTEXT(bgp, bgp);
15778 int idx_ospf_table = 2;
15779 int idx_number = 3;
15780 unsigned short instance;
15781 int protocol;
15782
15783 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15784 protocol = ZEBRA_ROUTE_OSPF;
15785 else
15786 protocol = ZEBRA_ROUTE_TABLE;
15787
15788 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15789 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
15790 }
15791
15792 ALIAS_HIDDEN(
15793 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
15794 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
15795 NO_STR
15796 "Redistribute information from another routing protocol\n"
15797 "Open Shortest Path First (OSPFv2)\n"
15798 "Non-main Kernel Routing Table\n"
15799 "Instance ID/Table ID\n"
15800 "Metric for redistributed routes\n"
15801 "Default metric\n"
15802 "Route map reference\n"
15803 "Pointer to route-map entries\n")
15804
15805 DEFUN (no_bgp_redistribute_ipv4,
15806 no_bgp_redistribute_ipv4_cmd,
15807 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
15808 NO_STR
15809 "Redistribute information from another routing protocol\n"
15810 FRR_IP_REDIST_HELP_STR_BGPD
15811 "Metric for redistributed routes\n"
15812 "Default metric\n"
15813 "Route map reference\n"
15814 "Pointer to route-map entries\n")
15815 {
15816 VTY_DECLVAR_CONTEXT(bgp, bgp);
15817 int idx_protocol = 2;
15818 int type;
15819
15820 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15821 if (type < 0) {
15822 vty_out(vty, "%% Invalid route type\n");
15823 return CMD_WARNING_CONFIG_FAILED;
15824 }
15825 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
15826 }
15827
15828 ALIAS_HIDDEN(
15829 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
15830 "no redistribute " FRR_IP_REDIST_STR_BGPD
15831 " [{metric (0-4294967295)|route-map WORD}]",
15832 NO_STR
15833 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15834 "Metric for redistributed routes\n"
15835 "Default metric\n"
15836 "Route map reference\n"
15837 "Pointer to route-map entries\n")
15838
15839 DEFUN (bgp_redistribute_ipv6,
15840 bgp_redistribute_ipv6_cmd,
15841 "redistribute " FRR_IP6_REDIST_STR_BGPD,
15842 "Redistribute information from another routing protocol\n"
15843 FRR_IP6_REDIST_HELP_STR_BGPD)
15844 {
15845 VTY_DECLVAR_CONTEXT(bgp, bgp);
15846 int idx_protocol = 1;
15847 int type;
15848
15849 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
15850 if (type < 0) {
15851 vty_out(vty, "%% Invalid route type\n");
15852 return CMD_WARNING_CONFIG_FAILED;
15853 }
15854
15855 bgp_redist_add(bgp, AFI_IP6, type, 0);
15856 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
15857 }
15858
15859 DEFUN (bgp_redistribute_ipv6_rmap,
15860 bgp_redistribute_ipv6_rmap_cmd,
15861 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
15862 "Redistribute information from another routing protocol\n"
15863 FRR_IP6_REDIST_HELP_STR_BGPD
15864 "Route map reference\n"
15865 "Pointer to route-map entries\n")
15866 {
15867 VTY_DECLVAR_CONTEXT(bgp, bgp);
15868 int idx_protocol = 1;
15869 int idx_word = 3;
15870 int type;
15871 struct bgp_redist *red;
15872 bool changed;
15873 struct route_map *route_map =
15874 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15875
15876 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
15877 if (type < 0) {
15878 vty_out(vty, "%% Invalid route type\n");
15879 return CMD_WARNING_CONFIG_FAILED;
15880 }
15881
15882 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
15883 changed =
15884 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15885 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
15886 }
15887
15888 DEFUN (bgp_redistribute_ipv6_metric,
15889 bgp_redistribute_ipv6_metric_cmd,
15890 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
15891 "Redistribute information from another routing protocol\n"
15892 FRR_IP6_REDIST_HELP_STR_BGPD
15893 "Metric for redistributed routes\n"
15894 "Default metric\n")
15895 {
15896 VTY_DECLVAR_CONTEXT(bgp, bgp);
15897 int idx_protocol = 1;
15898 int idx_number = 3;
15899 int type;
15900 uint32_t metric;
15901 struct bgp_redist *red;
15902 bool changed;
15903
15904 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
15905 if (type < 0) {
15906 vty_out(vty, "%% Invalid route type\n");
15907 return CMD_WARNING_CONFIG_FAILED;
15908 }
15909 metric = strtoul(argv[idx_number]->arg, NULL, 10);
15910
15911 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
15912 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
15913 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
15914 }
15915
15916 DEFUN (bgp_redistribute_ipv6_rmap_metric,
15917 bgp_redistribute_ipv6_rmap_metric_cmd,
15918 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
15919 "Redistribute information from another routing protocol\n"
15920 FRR_IP6_REDIST_HELP_STR_BGPD
15921 "Route map reference\n"
15922 "Pointer to route-map entries\n"
15923 "Metric for redistributed routes\n"
15924 "Default metric\n")
15925 {
15926 VTY_DECLVAR_CONTEXT(bgp, bgp);
15927 int idx_protocol = 1;
15928 int idx_word = 3;
15929 int idx_number = 5;
15930 int type;
15931 uint32_t metric;
15932 struct bgp_redist *red;
15933 bool changed;
15934 struct route_map *route_map =
15935 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15936
15937 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
15938 if (type < 0) {
15939 vty_out(vty, "%% Invalid route type\n");
15940 return CMD_WARNING_CONFIG_FAILED;
15941 }
15942 metric = strtoul(argv[idx_number]->arg, NULL, 10);
15943
15944 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
15945 changed =
15946 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15947 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
15948 metric);
15949 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
15950 }
15951
15952 DEFUN (bgp_redistribute_ipv6_metric_rmap,
15953 bgp_redistribute_ipv6_metric_rmap_cmd,
15954 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
15955 "Redistribute information from another routing protocol\n"
15956 FRR_IP6_REDIST_HELP_STR_BGPD
15957 "Metric for redistributed routes\n"
15958 "Default metric\n"
15959 "Route map reference\n"
15960 "Pointer to route-map entries\n")
15961 {
15962 VTY_DECLVAR_CONTEXT(bgp, bgp);
15963 int idx_protocol = 1;
15964 int idx_number = 3;
15965 int idx_word = 5;
15966 int type;
15967 uint32_t metric;
15968 struct bgp_redist *red;
15969 bool changed;
15970 struct route_map *route_map =
15971 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15972
15973 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
15974 if (type < 0) {
15975 vty_out(vty, "%% Invalid route type\n");
15976 return CMD_WARNING_CONFIG_FAILED;
15977 }
15978 metric = strtoul(argv[idx_number]->arg, NULL, 10);
15979
15980 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
15981 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
15982 metric);
15983 changed |=
15984 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15985 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
15986 }
15987
15988 DEFUN (no_bgp_redistribute_ipv6,
15989 no_bgp_redistribute_ipv6_cmd,
15990 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
15991 NO_STR
15992 "Redistribute information from another routing protocol\n"
15993 FRR_IP6_REDIST_HELP_STR_BGPD
15994 "Metric for redistributed routes\n"
15995 "Default metric\n"
15996 "Route map reference\n"
15997 "Pointer to route-map entries\n")
15998 {
15999 VTY_DECLVAR_CONTEXT(bgp, bgp);
16000 int idx_protocol = 2;
16001 int type;
16002
16003 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16004 if (type < 0) {
16005 vty_out(vty, "%% Invalid route type\n");
16006 return CMD_WARNING_CONFIG_FAILED;
16007 }
16008
16009 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
16010 }
16011
16012 /* Neighbor update tcp-mss. */
16013 static int peer_tcp_mss_vty(struct vty *vty, const char *peer_str,
16014 const char *tcp_mss_str)
16015 {
16016 struct peer *peer;
16017 uint32_t tcp_mss_val = 0;
16018
16019 peer = peer_and_group_lookup_vty(vty, peer_str);
16020 if (!peer)
16021 return CMD_WARNING_CONFIG_FAILED;
16022
16023 if (tcp_mss_str) {
16024 tcp_mss_val = strtoul(tcp_mss_str, NULL, 10);
16025 peer_tcp_mss_set(peer, tcp_mss_val);
16026 } else {
16027 peer_tcp_mss_unset(peer);
16028 }
16029
16030 return CMD_SUCCESS;
16031 }
16032
16033 DEFUN(neighbor_tcp_mss, neighbor_tcp_mss_cmd,
16034 "neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss (1-65535)",
16035 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16036 "TCP max segment size\n"
16037 "TCP MSS value\n")
16038 {
16039 int peer_index = 1;
16040 int mss_index = 3;
16041
16042 vty_out(vty,
16043 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16044 return peer_tcp_mss_vty(vty, argv[peer_index]->arg,
16045 argv[mss_index]->arg);
16046 }
16047
16048 DEFUN(no_neighbor_tcp_mss, no_neighbor_tcp_mss_cmd,
16049 "no neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss [(1-65535)]",
16050 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16051 "TCP max segment size\n"
16052 "TCP MSS value\n")
16053 {
16054 int peer_index = 2;
16055
16056 vty_out(vty,
16057 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16058 return peer_tcp_mss_vty(vty, argv[peer_index]->arg, NULL);
16059 }
16060
16061 static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
16062 afi_t afi, safi_t safi)
16063 {
16064 int i;
16065
16066 /* Unicast redistribution only. */
16067 if (safi != SAFI_UNICAST)
16068 return;
16069
16070 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
16071 /* Redistribute BGP does not make sense. */
16072 if (i != ZEBRA_ROUTE_BGP) {
16073 struct list *red_list;
16074 struct listnode *node;
16075 struct bgp_redist *red;
16076
16077 red_list = bgp->redist[afi][i];
16078 if (!red_list)
16079 continue;
16080
16081 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
16082 /* "redistribute" configuration. */
16083 vty_out(vty, " redistribute %s",
16084 zebra_route_string(i));
16085 if (red->instance)
16086 vty_out(vty, " %d", red->instance);
16087 if (red->redist_metric_flag)
16088 vty_out(vty, " metric %u",
16089 red->redist_metric);
16090 if (red->rmap.name)
16091 vty_out(vty, " route-map %s",
16092 red->rmap.name);
16093 vty_out(vty, "\n");
16094 }
16095 }
16096 }
16097 }
16098
16099 /* peer-group helpers for config-write */
16100
16101 static bool peergroup_flag_check(struct peer *peer, uint32_t flag)
16102 {
16103 if (!peer_group_active(peer)) {
16104 if (CHECK_FLAG(peer->flags_invert, flag))
16105 return !CHECK_FLAG(peer->flags, flag);
16106 else
16107 return !!CHECK_FLAG(peer->flags, flag);
16108 }
16109
16110 return !!CHECK_FLAG(peer->flags_override, flag);
16111 }
16112
16113 static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
16114 uint32_t flag)
16115 {
16116 if (!peer_group_active(peer)) {
16117 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
16118 return !peer_af_flag_check(peer, afi, safi, flag);
16119 else
16120 return !!peer_af_flag_check(peer, afi, safi, flag);
16121 }
16122
16123 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
16124 }
16125
16126 static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
16127 uint8_t type, int direct)
16128 {
16129 struct bgp_filter *filter;
16130
16131 if (peer_group_active(peer))
16132 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
16133 type);
16134
16135 filter = &peer->filter[afi][safi];
16136 switch (type) {
16137 case PEER_FT_DISTRIBUTE_LIST:
16138 return !!(filter->dlist[direct].name);
16139 case PEER_FT_FILTER_LIST:
16140 return !!(filter->aslist[direct].name);
16141 case PEER_FT_PREFIX_LIST:
16142 return !!(filter->plist[direct].name);
16143 case PEER_FT_ROUTE_MAP:
16144 return !!(filter->map[direct].name);
16145 case PEER_FT_UNSUPPRESS_MAP:
16146 return !!(filter->usmap.name);
16147 case PEER_FT_ADVERTISE_MAP:
16148 return !!(filter->advmap.aname
16149 && ((filter->advmap.condition == direct)
16150 && filter->advmap.cname));
16151 default:
16152 return false;
16153 }
16154 }
16155
16156 /* Return true if the addpath type is set for peer and different from
16157 * peer-group.
16158 */
16159 static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi,
16160 safi_t safi)
16161 {
16162 enum bgp_addpath_strat type, g_type;
16163
16164 type = peer->addpath_type[afi][safi];
16165
16166 if (type != BGP_ADDPATH_NONE) {
16167 if (peer_group_active(peer)) {
16168 g_type = peer->group->conf->addpath_type[afi][safi];
16169
16170 if (type != g_type)
16171 return true;
16172 else
16173 return false;
16174 }
16175
16176 return true;
16177 }
16178
16179 return false;
16180 }
16181
16182 /* This is part of the address-family block (unicast only) */
16183 static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
16184 afi_t afi)
16185 {
16186 int indent = 2;
16187 uint32_t tovpn_sid_index = 0;
16188
16189 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
16190 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16191 BGP_CONFIG_VRF_TO_VRF_IMPORT))
16192 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
16193 bgp->vpn_policy[afi]
16194 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16195 else
16196 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
16197 bgp->vpn_policy[afi]
16198 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16199 }
16200 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16201 BGP_CONFIG_VRF_TO_VRF_IMPORT)
16202 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16203 BGP_CONFIG_VRF_TO_VRF_EXPORT))
16204 return;
16205
16206 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16207 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
16208
16209 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
16210
16211 } else {
16212 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
16213 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
16214 bgp->vpn_policy[afi].tovpn_label);
16215 }
16216 }
16217
16218 tovpn_sid_index = bgp->vpn_policy[afi].tovpn_sid_index;
16219 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16220 BGP_VPN_POLICY_TOVPN_SID_AUTO)) {
16221 vty_out(vty, "%*ssid vpn export %s\n", indent, "", "auto");
16222 } else if (tovpn_sid_index != 0) {
16223 vty_out(vty, "%*ssid vpn export %d\n", indent, "",
16224 tovpn_sid_index);
16225 }
16226
16227 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16228 BGP_VPN_POLICY_TOVPN_RD_SET)) {
16229 char buf[RD_ADDRSTRLEN];
16230 vty_out(vty, "%*srd vpn export %s\n", indent, "",
16231 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
16232 sizeof(buf)));
16233 }
16234 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16235 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
16236
16237 char buf[PREFIX_STRLEN];
16238 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
16239 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
16240 sizeof(buf))) {
16241
16242 vty_out(vty, "%*snexthop vpn export %s\n",
16243 indent, "", buf);
16244 }
16245 }
16246 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
16247 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
16248 && ecommunity_cmp(
16249 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16250 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
16251
16252 char *b = ecommunity_ecom2str(
16253 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16254 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
16255 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
16256 XFREE(MTYPE_ECOMMUNITY_STR, b);
16257 } else {
16258 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
16259 char *b = ecommunity_ecom2str(
16260 bgp->vpn_policy[afi]
16261 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16262 ECOMMUNITY_FORMAT_ROUTE_MAP,
16263 ECOMMUNITY_ROUTE_TARGET);
16264 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
16265 XFREE(MTYPE_ECOMMUNITY_STR, b);
16266 }
16267 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
16268 char *b = ecommunity_ecom2str(
16269 bgp->vpn_policy[afi]
16270 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16271 ECOMMUNITY_FORMAT_ROUTE_MAP,
16272 ECOMMUNITY_ROUTE_TARGET);
16273 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
16274 XFREE(MTYPE_ECOMMUNITY_STR, b);
16275 }
16276 }
16277
16278 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
16279 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
16280 bgp->vpn_policy[afi]
16281 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
16282
16283 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
16284 char *b = ecommunity_ecom2str(
16285 bgp->vpn_policy[afi]
16286 .import_redirect_rtlist,
16287 ECOMMUNITY_FORMAT_ROUTE_MAP,
16288 ECOMMUNITY_ROUTE_TARGET);
16289
16290 if (bgp->vpn_policy[afi].import_redirect_rtlist->unit_size
16291 != ECOMMUNITY_SIZE)
16292 vty_out(vty, "%*srt6 redirect import %s\n",
16293 indent, "", b);
16294 else
16295 vty_out(vty, "%*srt redirect import %s\n",
16296 indent, "", b);
16297 XFREE(MTYPE_ECOMMUNITY_STR, b);
16298 }
16299 }
16300
16301 static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
16302 afi_t afi, safi_t safi)
16303 {
16304 struct bgp_filter *filter;
16305 char *addr;
16306
16307 addr = peer->host;
16308 filter = &peer->filter[afi][safi];
16309
16310 /* distribute-list. */
16311 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16312 FILTER_IN))
16313 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
16314 filter->dlist[FILTER_IN].name);
16315
16316 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16317 FILTER_OUT))
16318 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
16319 filter->dlist[FILTER_OUT].name);
16320
16321 /* prefix-list. */
16322 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16323 FILTER_IN))
16324 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
16325 filter->plist[FILTER_IN].name);
16326
16327 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16328 FILTER_OUT))
16329 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
16330 filter->plist[FILTER_OUT].name);
16331
16332 /* route-map. */
16333 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
16334 vty_out(vty, " neighbor %s route-map %s in\n", addr,
16335 filter->map[RMAP_IN].name);
16336
16337 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
16338 RMAP_OUT))
16339 vty_out(vty, " neighbor %s route-map %s out\n", addr,
16340 filter->map[RMAP_OUT].name);
16341
16342 /* unsuppress-map */
16343 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
16344 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
16345 filter->usmap.name);
16346
16347 /* advertise-map : always applied in OUT direction*/
16348 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16349 CONDITION_NON_EXIST))
16350 vty_out(vty,
16351 " neighbor %s advertise-map %s non-exist-map %s\n",
16352 addr, filter->advmap.aname, filter->advmap.cname);
16353
16354 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16355 CONDITION_EXIST))
16356 vty_out(vty, " neighbor %s advertise-map %s exist-map %s\n",
16357 addr, filter->advmap.aname, filter->advmap.cname);
16358
16359 /* filter-list. */
16360 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16361 FILTER_IN))
16362 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
16363 filter->aslist[FILTER_IN].name);
16364
16365 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16366 FILTER_OUT))
16367 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
16368 filter->aslist[FILTER_OUT].name);
16369 }
16370
16371 /* BGP peer configuration display function. */
16372 static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
16373 struct peer *peer)
16374 {
16375 struct peer *g_peer = NULL;
16376 char buf[SU_ADDRSTRLEN];
16377 char *addr;
16378 int if_pg_printed = false;
16379 int if_ras_printed = false;
16380
16381 /* Skip dynamic neighbors. */
16382 if (peer_dynamic_neighbor(peer))
16383 return;
16384
16385 if (peer->conf_if)
16386 addr = peer->conf_if;
16387 else
16388 addr = peer->host;
16389
16390 /************************************
16391 ****** Global to the neighbor ******
16392 ************************************/
16393 if (peer->conf_if) {
16394 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
16395 vty_out(vty, " neighbor %s interface v6only", addr);
16396 else
16397 vty_out(vty, " neighbor %s interface", addr);
16398
16399 if (peer_group_active(peer)) {
16400 vty_out(vty, " peer-group %s", peer->group->name);
16401 if_pg_printed = true;
16402 } else if (peer->as_type == AS_SPECIFIED) {
16403 vty_out(vty, " remote-as %u", peer->as);
16404 if_ras_printed = true;
16405 } else if (peer->as_type == AS_INTERNAL) {
16406 vty_out(vty, " remote-as internal");
16407 if_ras_printed = true;
16408 } else if (peer->as_type == AS_EXTERNAL) {
16409 vty_out(vty, " remote-as external");
16410 if_ras_printed = true;
16411 }
16412
16413 vty_out(vty, "\n");
16414 }
16415
16416 /* remote-as and peer-group */
16417 /* peer is a member of a peer-group */
16418 if (peer_group_active(peer)) {
16419 g_peer = peer->group->conf;
16420
16421 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
16422 if (peer->as_type == AS_SPECIFIED) {
16423 vty_out(vty, " neighbor %s remote-as %u\n",
16424 addr, peer->as);
16425 } else if (peer->as_type == AS_INTERNAL) {
16426 vty_out(vty,
16427 " neighbor %s remote-as internal\n",
16428 addr);
16429 } else if (peer->as_type == AS_EXTERNAL) {
16430 vty_out(vty,
16431 " neighbor %s remote-as external\n",
16432 addr);
16433 }
16434 }
16435
16436 /* For swpX peers we displayed the peer-group
16437 * via 'neighbor swpX interface peer-group PGNAME' */
16438 if (!if_pg_printed)
16439 vty_out(vty, " neighbor %s peer-group %s\n", addr,
16440 peer->group->name);
16441 }
16442
16443 /* peer is NOT a member of a peer-group */
16444 else {
16445 /* peer is a peer-group, declare the peer-group */
16446 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
16447 vty_out(vty, " neighbor %s peer-group\n", addr);
16448 }
16449
16450 if (!if_ras_printed) {
16451 if (peer->as_type == AS_SPECIFIED) {
16452 vty_out(vty, " neighbor %s remote-as %u\n",
16453 addr, peer->as);
16454 } else if (peer->as_type == AS_INTERNAL) {
16455 vty_out(vty,
16456 " neighbor %s remote-as internal\n",
16457 addr);
16458 } else if (peer->as_type == AS_EXTERNAL) {
16459 vty_out(vty,
16460 " neighbor %s remote-as external\n",
16461 addr);
16462 }
16463 }
16464 }
16465
16466 /* local-as */
16467 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
16468 vty_out(vty, " neighbor %s local-as %u", addr,
16469 peer->change_local_as);
16470 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
16471 vty_out(vty, " no-prepend");
16472 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
16473 vty_out(vty, " replace-as");
16474 vty_out(vty, "\n");
16475 }
16476
16477 /* description */
16478 if (peer->desc) {
16479 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
16480 }
16481
16482 /* shutdown */
16483 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
16484 if (peer->tx_shutdown_message)
16485 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
16486 peer->tx_shutdown_message);
16487 else
16488 vty_out(vty, " neighbor %s shutdown\n", addr);
16489 }
16490
16491 if (peergroup_flag_check(peer, PEER_FLAG_RTT_SHUTDOWN))
16492 vty_out(vty, " neighbor %s shutdown rtt %u count %u\n", addr,
16493 peer->rtt_expected, peer->rtt_keepalive_conf);
16494
16495 /* bfd */
16496 if (peer->bfd_config)
16497 bgp_bfd_peer_config_write(vty, peer, addr);
16498
16499 /* password */
16500 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
16501 vty_out(vty, " neighbor %s password %s\n", addr,
16502 peer->password);
16503
16504 /* neighbor solo */
16505 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
16506 if (!peer_group_active(peer)) {
16507 vty_out(vty, " neighbor %s solo\n", addr);
16508 }
16509 }
16510
16511 /* BGP port */
16512 if (peer->port != BGP_PORT_DEFAULT) {
16513 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
16514 }
16515
16516 /* Local interface name */
16517 if (peer->ifname) {
16518 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
16519 }
16520
16521 /* TCP max segment size */
16522 if (CHECK_FLAG(peer->flags, PEER_FLAG_TCP_MSS))
16523 vty_out(vty, " neighbor %s tcp-mss %d\n", addr, peer->tcp_mss);
16524
16525 /* passive */
16526 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
16527 vty_out(vty, " neighbor %s passive\n", addr);
16528
16529 /* ebgp-multihop */
16530 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
16531 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
16532 && peer->ttl == MAXTTL)) {
16533 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
16534 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
16535 peer->ttl);
16536 }
16537 }
16538
16539 /* ttl-security hops */
16540 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
16541 if (!peer_group_active(peer)
16542 || g_peer->gtsm_hops != peer->gtsm_hops) {
16543 vty_out(vty, " neighbor %s ttl-security hops %d\n",
16544 addr, peer->gtsm_hops);
16545 }
16546 }
16547
16548 /* disable-connected-check */
16549 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
16550 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
16551
16552 /* link-bw-encoding-ieee */
16553 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE))
16554 vty_out(vty, " neighbor %s disable-link-bw-encoding-ieee\n",
16555 addr);
16556
16557 /* extended-optional-parameters */
16558 if (peergroup_flag_check(peer, PEER_FLAG_EXTENDED_OPT_PARAMS))
16559 vty_out(vty, " neighbor %s extended-optional-parameters\n",
16560 addr);
16561
16562 /* enforce-first-as */
16563 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
16564 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
16565
16566 /* update-source */
16567 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
16568 if (peer->update_source)
16569 vty_out(vty, " neighbor %s update-source %s\n", addr,
16570 sockunion2str(peer->update_source, buf,
16571 SU_ADDRSTRLEN));
16572 else if (peer->update_if)
16573 vty_out(vty, " neighbor %s update-source %s\n", addr,
16574 peer->update_if);
16575 }
16576
16577 /* advertisement-interval */
16578 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
16579 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
16580 peer->routeadv);
16581
16582 /* timers */
16583 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
16584 vty_out(vty, " neighbor %s timers %u %u\n", addr,
16585 peer->keepalive, peer->holdtime);
16586
16587 /* timers connect */
16588 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
16589 vty_out(vty, " neighbor %s timers connect %u\n", addr,
16590 peer->connect);
16591 /* need special-case handling for changed default values due to
16592 * config profile / version (because there is no "timers bgp connect"
16593 * command, we need to save this per-peer :/)
16594 */
16595 else if (!peer_group_active(peer) && !peer->connect &&
16596 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
16597 vty_out(vty, " neighbor %s timers connect %u\n", addr,
16598 peer->bgp->default_connect_retry);
16599
16600 /* timers delayopen */
16601 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_DELAYOPEN))
16602 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
16603 peer->delayopen);
16604 /* Save config even though flag is not set if default values have been
16605 * changed
16606 */
16607 else if (!peer_group_active(peer) && !peer->delayopen
16608 && peer->bgp->default_delayopen != BGP_DEFAULT_DELAYOPEN)
16609 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
16610 peer->bgp->default_delayopen);
16611
16612 /* capability dynamic */
16613 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
16614 vty_out(vty, " neighbor %s capability dynamic\n", addr);
16615
16616 /* capability extended-nexthop */
16617 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
16618 if (CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE))
16619 vty_out(vty,
16620 " no neighbor %s capability extended-nexthop\n",
16621 addr);
16622 else if (!peer->conf_if)
16623 vty_out(vty,
16624 " neighbor %s capability extended-nexthop\n",
16625 addr);
16626 }
16627
16628 /* dont-capability-negotiation */
16629 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
16630 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
16631
16632 /* override-capability */
16633 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
16634 vty_out(vty, " neighbor %s override-capability\n", addr);
16635
16636 /* strict-capability-match */
16637 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
16638 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
16639
16640 /* Sender side AS path loop detection. */
16641 if (peer->as_path_loop_detection)
16642 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
16643 addr);
16644
16645 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
16646 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
16647
16648 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
16649 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
16650 vty_out(vty,
16651 " neighbor %s graceful-restart-helper\n", addr);
16652 } else if (CHECK_FLAG(
16653 peer->peer_gr_new_status_flag,
16654 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
16655 vty_out(vty,
16656 " neighbor %s graceful-restart\n", addr);
16657 } else if (
16658 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
16659 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
16660 && !(CHECK_FLAG(
16661 peer->peer_gr_new_status_flag,
16662 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
16663 vty_out(vty, " neighbor %s graceful-restart-disable\n",
16664 addr);
16665 }
16666 }
16667 }
16668
16669 /* BGP peer configuration display function. */
16670 static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
16671 struct peer *peer, afi_t afi, safi_t safi)
16672 {
16673 struct peer *g_peer = NULL;
16674 char *addr;
16675 bool flag_scomm, flag_secomm, flag_slcomm;
16676
16677 /* Skip dynamic neighbors. */
16678 if (peer_dynamic_neighbor(peer))
16679 return;
16680
16681 if (peer->conf_if)
16682 addr = peer->conf_if;
16683 else
16684 addr = peer->host;
16685
16686 /************************************
16687 ****** Per AF to the neighbor ******
16688 ************************************/
16689 if (peer_group_active(peer)) {
16690 g_peer = peer->group->conf;
16691
16692 /* If the peer-group is active but peer is not, print a 'no
16693 * activate' */
16694 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
16695 vty_out(vty, " no neighbor %s activate\n", addr);
16696 }
16697
16698 /* If the peer-group is not active but peer is, print an
16699 'activate' */
16700 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
16701 vty_out(vty, " neighbor %s activate\n", addr);
16702 }
16703 } else {
16704 if (peer->afc[afi][safi]) {
16705 if (safi == SAFI_ENCAP)
16706 vty_out(vty, " neighbor %s activate\n", addr);
16707 else if (!bgp->default_af[afi][safi])
16708 vty_out(vty, " neighbor %s activate\n", addr);
16709 } else {
16710 if (bgp->default_af[afi][safi])
16711 vty_out(vty, " no neighbor %s activate\n",
16712 addr);
16713 }
16714 }
16715
16716 /* addpath TX knobs */
16717 if (peergroup_af_addpath_check(peer, afi, safi)) {
16718 switch (peer->addpath_type[afi][safi]) {
16719 case BGP_ADDPATH_ALL:
16720 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
16721 addr);
16722 break;
16723 case BGP_ADDPATH_BEST_PER_AS:
16724 vty_out(vty,
16725 " neighbor %s addpath-tx-bestpath-per-AS\n",
16726 addr);
16727 break;
16728 case BGP_ADDPATH_MAX:
16729 case BGP_ADDPATH_NONE:
16730 break;
16731 }
16732 }
16733
16734 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_DISABLE_ADDPATH_RX))
16735 vty_out(vty, " neighbor %s disable-addpath-rx\n", addr);
16736
16737 /* ORF capability. */
16738 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
16739 || peergroup_af_flag_check(peer, afi, safi,
16740 PEER_FLAG_ORF_PREFIX_RM)) {
16741 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
16742
16743 if (peergroup_af_flag_check(peer, afi, safi,
16744 PEER_FLAG_ORF_PREFIX_SM)
16745 && peergroup_af_flag_check(peer, afi, safi,
16746 PEER_FLAG_ORF_PREFIX_RM))
16747 vty_out(vty, " both");
16748 else if (peergroup_af_flag_check(peer, afi, safi,
16749 PEER_FLAG_ORF_PREFIX_SM))
16750 vty_out(vty, " send");
16751 else
16752 vty_out(vty, " receive");
16753 vty_out(vty, "\n");
16754 }
16755
16756 /* Route reflector client. */
16757 if (peergroup_af_flag_check(peer, afi, safi,
16758 PEER_FLAG_REFLECTOR_CLIENT)) {
16759 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
16760 }
16761
16762 /* next-hop-self force */
16763 if (peergroup_af_flag_check(peer, afi, safi,
16764 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
16765 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
16766 }
16767
16768 /* next-hop-self */
16769 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
16770 vty_out(vty, " neighbor %s next-hop-self\n", addr);
16771 }
16772
16773 /* remove-private-AS */
16774 if (peergroup_af_flag_check(peer, afi, safi,
16775 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
16776 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
16777 addr);
16778 }
16779
16780 else if (peergroup_af_flag_check(peer, afi, safi,
16781 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
16782 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
16783 addr);
16784 }
16785
16786 else if (peergroup_af_flag_check(peer, afi, safi,
16787 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
16788 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
16789 }
16790
16791 else if (peergroup_af_flag_check(peer, afi, safi,
16792 PEER_FLAG_REMOVE_PRIVATE_AS)) {
16793 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
16794 }
16795
16796 /* as-override */
16797 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
16798 vty_out(vty, " neighbor %s as-override\n", addr);
16799 }
16800
16801 /* send-community print. */
16802 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
16803 PEER_FLAG_SEND_COMMUNITY);
16804 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
16805 PEER_FLAG_SEND_EXT_COMMUNITY);
16806 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
16807 PEER_FLAG_SEND_LARGE_COMMUNITY);
16808
16809 if (flag_scomm && flag_secomm && flag_slcomm) {
16810 vty_out(vty, " no neighbor %s send-community all\n", addr);
16811 } else {
16812 if (flag_scomm)
16813 vty_out(vty, " no neighbor %s send-community\n", addr);
16814 if (flag_secomm)
16815 vty_out(vty,
16816 " no neighbor %s send-community extended\n",
16817 addr);
16818
16819 if (flag_slcomm)
16820 vty_out(vty, " no neighbor %s send-community large\n",
16821 addr);
16822 }
16823
16824 /* Default information */
16825 if (peergroup_af_flag_check(peer, afi, safi,
16826 PEER_FLAG_DEFAULT_ORIGINATE)) {
16827 vty_out(vty, " neighbor %s default-originate", addr);
16828
16829 if (peer->default_rmap[afi][safi].name)
16830 vty_out(vty, " route-map %s",
16831 peer->default_rmap[afi][safi].name);
16832
16833 vty_out(vty, "\n");
16834 }
16835
16836 /* Soft reconfiguration inbound. */
16837 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
16838 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
16839 addr);
16840 }
16841
16842 /* maximum-prefix. */
16843 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
16844 vty_out(vty, " neighbor %s maximum-prefix %u", addr,
16845 peer->pmax[afi][safi]);
16846
16847 if (peer->pmax_threshold[afi][safi]
16848 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
16849 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
16850 if (peer_af_flag_check(peer, afi, safi,
16851 PEER_FLAG_MAX_PREFIX_WARNING))
16852 vty_out(vty, " warning-only");
16853 if (peer->pmax_restart[afi][safi])
16854 vty_out(vty, " restart %u",
16855 peer->pmax_restart[afi][safi]);
16856 if (peer_af_flag_check(peer, afi, safi,
16857 PEER_FLAG_MAX_PREFIX_FORCE))
16858 vty_out(vty, " force");
16859
16860 vty_out(vty, "\n");
16861 }
16862
16863 /* maximum-prefix-out */
16864 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
16865 vty_out(vty, " neighbor %s maximum-prefix-out %u\n",
16866 addr, peer->pmax_out[afi][safi]);
16867
16868 /* Route server client. */
16869 if (peergroup_af_flag_check(peer, afi, safi,
16870 PEER_FLAG_RSERVER_CLIENT)) {
16871 vty_out(vty, " neighbor %s route-server-client\n", addr);
16872 }
16873
16874 /* Nexthop-local unchanged. */
16875 if (peergroup_af_flag_check(peer, afi, safi,
16876 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
16877 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
16878 }
16879
16880 /* allowas-in <1-10> */
16881 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
16882 if (peer_af_flag_check(peer, afi, safi,
16883 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
16884 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
16885 } else if (peer->allowas_in[afi][safi] == 3) {
16886 vty_out(vty, " neighbor %s allowas-in\n", addr);
16887 } else {
16888 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
16889 peer->allowas_in[afi][safi]);
16890 }
16891 }
16892
16893 /* weight */
16894 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
16895 vty_out(vty, " neighbor %s weight %lu\n", addr,
16896 peer->weight[afi][safi]);
16897
16898 /* Filter. */
16899 bgp_config_write_filter(vty, peer, afi, safi);
16900
16901 /* atribute-unchanged. */
16902 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
16903 || (safi != SAFI_EVPN
16904 && peer_af_flag_check(peer, afi, safi,
16905 PEER_FLAG_NEXTHOP_UNCHANGED))
16906 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
16907
16908 if (!peer_group_active(peer)
16909 || peergroup_af_flag_check(peer, afi, safi,
16910 PEER_FLAG_AS_PATH_UNCHANGED)
16911 || peergroup_af_flag_check(peer, afi, safi,
16912 PEER_FLAG_NEXTHOP_UNCHANGED)
16913 || peergroup_af_flag_check(peer, afi, safi,
16914 PEER_FLAG_MED_UNCHANGED)) {
16915
16916 vty_out(vty,
16917 " neighbor %s attribute-unchanged%s%s%s\n",
16918 addr,
16919 peer_af_flag_check(peer, afi, safi,
16920 PEER_FLAG_AS_PATH_UNCHANGED)
16921 ? " as-path"
16922 : "",
16923 peer_af_flag_check(peer, afi, safi,
16924 PEER_FLAG_NEXTHOP_UNCHANGED)
16925 ? " next-hop"
16926 : "",
16927 peer_af_flag_check(peer, afi, safi,
16928 PEER_FLAG_MED_UNCHANGED)
16929 ? " med"
16930 : "");
16931 }
16932 }
16933 }
16934
16935 /* Address family based peer configuration display. */
16936 static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
16937 safi_t safi)
16938 {
16939 struct peer *peer;
16940 struct peer_group *group;
16941 struct listnode *node, *nnode;
16942
16943
16944 vty_frame(vty, " !\n address-family ");
16945 if (afi == AFI_IP) {
16946 if (safi == SAFI_UNICAST)
16947 vty_frame(vty, "ipv4 unicast");
16948 else if (safi == SAFI_LABELED_UNICAST)
16949 vty_frame(vty, "ipv4 labeled-unicast");
16950 else if (safi == SAFI_MULTICAST)
16951 vty_frame(vty, "ipv4 multicast");
16952 else if (safi == SAFI_MPLS_VPN)
16953 vty_frame(vty, "ipv4 vpn");
16954 else if (safi == SAFI_ENCAP)
16955 vty_frame(vty, "ipv4 encap");
16956 else if (safi == SAFI_FLOWSPEC)
16957 vty_frame(vty, "ipv4 flowspec");
16958 } else if (afi == AFI_IP6) {
16959 if (safi == SAFI_UNICAST)
16960 vty_frame(vty, "ipv6 unicast");
16961 else if (safi == SAFI_LABELED_UNICAST)
16962 vty_frame(vty, "ipv6 labeled-unicast");
16963 else if (safi == SAFI_MULTICAST)
16964 vty_frame(vty, "ipv6 multicast");
16965 else if (safi == SAFI_MPLS_VPN)
16966 vty_frame(vty, "ipv6 vpn");
16967 else if (safi == SAFI_ENCAP)
16968 vty_frame(vty, "ipv6 encap");
16969 else if (safi == SAFI_FLOWSPEC)
16970 vty_frame(vty, "ipv6 flowspec");
16971 } else if (afi == AFI_L2VPN) {
16972 if (safi == SAFI_EVPN)
16973 vty_frame(vty, "l2vpn evpn");
16974 }
16975 vty_frame(vty, "\n");
16976
16977 bgp_config_write_distance(vty, bgp, afi, safi);
16978
16979 bgp_config_write_network(vty, bgp, afi, safi);
16980
16981 bgp_config_write_redistribute(vty, bgp, afi, safi);
16982
16983 /* BGP flag dampening. */
16984 if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
16985 bgp_config_write_damp(vty, afi, safi);
16986
16987 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
16988 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
16989
16990 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
16991 /* Do not display doppelganger peers */
16992 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
16993 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
16994 }
16995
16996 bgp_config_write_maxpaths(vty, bgp, afi, safi);
16997 bgp_config_write_table_map(vty, bgp, afi, safi);
16998
16999 if (safi == SAFI_EVPN)
17000 bgp_config_write_evpn_info(vty, bgp, afi, safi);
17001
17002 if (safi == SAFI_FLOWSPEC)
17003 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
17004
17005 if (safi == SAFI_UNICAST) {
17006 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
17007 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17008 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
17009
17010 vty_out(vty, " export vpn\n");
17011 }
17012 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17013 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
17014
17015 vty_out(vty, " import vpn\n");
17016 }
17017 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17018 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
17019 char *name;
17020
17021 for (ALL_LIST_ELEMENTS_RO(
17022 bgp->vpn_policy[afi].import_vrf, node,
17023 name))
17024 vty_out(vty, " import vrf %s\n", name);
17025 }
17026 }
17027
17028 vty_endframe(vty, " exit-address-family\n");
17029 }
17030
17031 int bgp_config_write(struct vty *vty)
17032 {
17033 struct bgp *bgp;
17034 struct peer_group *group;
17035 struct peer *peer;
17036 struct listnode *node, *nnode;
17037 struct listnode *mnode, *mnnode;
17038 afi_t afi;
17039 safi_t safi;
17040
17041 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
17042 vty_out(vty, "bgp route-map delay-timer %u\n",
17043 bm->rmap_update_timer);
17044
17045 if (bm->v_update_delay != BGP_UPDATE_DELAY_DEF) {
17046 vty_out(vty, "bgp update-delay %d", bm->v_update_delay);
17047 if (bm->v_update_delay != bm->v_establish_wait)
17048 vty_out(vty, " %d", bm->v_establish_wait);
17049 vty_out(vty, "\n");
17050 }
17051
17052 if (bm->wait_for_fib)
17053 vty_out(vty, "bgp suppress-fib-pending\n");
17054
17055 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17056 vty_out(vty, "bgp graceful-shutdown\n");
17057
17058 /* No-RIB (Zebra) option flag configuration */
17059 if (bgp_option_check(BGP_OPT_NO_FIB))
17060 vty_out(vty, "bgp no-rib\n");
17061
17062 if (CHECK_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA))
17063 vty_out(vty, "bgp send-extra-data zebra\n");
17064
17065 /* BGP configuration. */
17066 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
17067
17068 /* skip all auto created vrf as they dont have user config */
17069 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
17070 continue;
17071
17072 /* Router bgp ASN */
17073 vty_out(vty, "router bgp %u", bgp->as);
17074
17075 if (bgp->name)
17076 vty_out(vty, " %s %s",
17077 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
17078 ? "view" : "vrf", bgp->name);
17079 vty_out(vty, "\n");
17080
17081 /* BGP fast-external-failover. */
17082 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
17083 vty_out(vty, " no bgp fast-external-failover\n");
17084
17085 /* BGP router ID. */
17086 if (bgp->router_id_static.s_addr != INADDR_ANY)
17087 vty_out(vty, " bgp router-id %pI4\n",
17088 &bgp->router_id_static);
17089
17090 /* Suppress fib pending */
17091 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_FIB_PENDING))
17092 vty_out(vty, " bgp suppress-fib-pending\n");
17093
17094 /* BGP log-neighbor-changes. */
17095 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
17096 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
17097 vty_out(vty, " %sbgp log-neighbor-changes\n",
17098 CHECK_FLAG(bgp->flags,
17099 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
17100 ? ""
17101 : "no ");
17102
17103 /* BGP configuration. */
17104 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
17105 vty_out(vty, " bgp always-compare-med\n");
17106
17107 /* RFC8212 default eBGP policy. */
17108 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
17109 != SAVE_BGP_EBGP_REQUIRES_POLICY)
17110 vty_out(vty, " %sbgp ebgp-requires-policy\n",
17111 CHECK_FLAG(bgp->flags,
17112 BGP_FLAG_EBGP_REQUIRES_POLICY)
17113 ? ""
17114 : "no ");
17115
17116 /* draft-ietf-idr-deprecate-as-set-confed-set */
17117 if (bgp->reject_as_sets)
17118 vty_out(vty, " bgp reject-as-sets\n");
17119
17120 /* Suppress duplicate updates if the route actually not changed
17121 */
17122 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES)
17123 != SAVE_BGP_SUPPRESS_DUPLICATES)
17124 vty_out(vty, " %sbgp suppress-duplicates\n",
17125 CHECK_FLAG(bgp->flags,
17126 BGP_FLAG_SUPPRESS_DUPLICATES)
17127 ? ""
17128 : "no ");
17129
17130 /* BGP default <afi>-<safi> */
17131 FOREACH_AFI_SAFI (afi, safi) {
17132 if (afi == AFI_IP && safi == SAFI_UNICAST) {
17133 if (!bgp->default_af[afi][safi])
17134 vty_out(vty, " no bgp default %s\n",
17135 get_bgp_default_af_flag(afi,
17136 safi));
17137 } else if (bgp->default_af[afi][safi])
17138 vty_out(vty, " bgp default %s\n",
17139 get_bgp_default_af_flag(afi, safi));
17140 }
17141
17142 /* BGP default local-preference. */
17143 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
17144 vty_out(vty, " bgp default local-preference %u\n",
17145 bgp->default_local_pref);
17146
17147 /* BGP default show-hostname */
17148 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
17149 != SAVE_BGP_SHOW_HOSTNAME)
17150 vty_out(vty, " %sbgp default show-hostname\n",
17151 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
17152 ? ""
17153 : "no ");
17154
17155 /* BGP default show-nexthop-hostname */
17156 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17157 != SAVE_BGP_SHOW_HOSTNAME)
17158 vty_out(vty, " %sbgp default show-nexthop-hostname\n",
17159 CHECK_FLAG(bgp->flags,
17160 BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17161 ? ""
17162 : "no ");
17163
17164 /* BGP default subgroup-pkt-queue-max. */
17165 if (bgp->default_subgroup_pkt_queue_max
17166 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
17167 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
17168 bgp->default_subgroup_pkt_queue_max);
17169
17170 /* BGP client-to-client reflection. */
17171 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
17172 vty_out(vty, " no bgp client-to-client reflection\n");
17173
17174 /* BGP cluster ID. */
17175 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
17176 vty_out(vty, " bgp cluster-id %pI4\n",
17177 &bgp->cluster_id);
17178
17179 /* Disable ebgp connected nexthop check */
17180 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
17181 vty_out(vty,
17182 " bgp disable-ebgp-connected-route-check\n");
17183
17184 /* Confederation identifier*/
17185 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
17186 vty_out(vty, " bgp confederation identifier %u\n",
17187 bgp->confed_id);
17188
17189 /* Confederation peer */
17190 if (bgp->confed_peers_cnt > 0) {
17191 int i;
17192
17193 vty_out(vty, " bgp confederation peers");
17194
17195 for (i = 0; i < bgp->confed_peers_cnt; i++)
17196 vty_out(vty, " %u", bgp->confed_peers[i]);
17197
17198 vty_out(vty, "\n");
17199 }
17200
17201 /* BGP deterministic-med. */
17202 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
17203 != SAVE_BGP_DETERMINISTIC_MED)
17204 vty_out(vty, " %sbgp deterministic-med\n",
17205 CHECK_FLAG(bgp->flags,
17206 BGP_FLAG_DETERMINISTIC_MED)
17207 ? ""
17208 : "no ");
17209
17210 /* BGP update-delay. */
17211 bgp_config_write_update_delay(vty, bgp);
17212
17213 if (bgp->v_maxmed_onstartup
17214 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
17215 vty_out(vty, " bgp max-med on-startup %u",
17216 bgp->v_maxmed_onstartup);
17217 if (bgp->maxmed_onstartup_value
17218 != BGP_MAXMED_VALUE_DEFAULT)
17219 vty_out(vty, " %u",
17220 bgp->maxmed_onstartup_value);
17221 vty_out(vty, "\n");
17222 }
17223 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
17224 vty_out(vty, " bgp max-med administrative");
17225 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
17226 vty_out(vty, " %u", bgp->maxmed_admin_value);
17227 vty_out(vty, "\n");
17228 }
17229
17230 /* write quanta */
17231 bgp_config_write_wpkt_quanta(vty, bgp);
17232 /* read quanta */
17233 bgp_config_write_rpkt_quanta(vty, bgp);
17234
17235 /* coalesce time */
17236 bgp_config_write_coalesce_time(vty, bgp);
17237
17238 /* BGP per-instance graceful-shutdown */
17239 /* BGP-wide settings and per-instance settings are mutually
17240 * exclusive.
17241 */
17242 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17243 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
17244 vty_out(vty, " bgp graceful-shutdown\n");
17245
17246 /* Long-lived Graceful Restart */
17247 if (bgp->llgr_stale_time != BGP_DEFAULT_LLGR_STALE_TIME)
17248 vty_out(vty,
17249 " bgp long-lived-graceful-restart stale-time %u\n",
17250 bgp->llgr_stale_time);
17251
17252 /* BGP graceful-restart. */
17253 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
17254 vty_out(vty,
17255 " bgp graceful-restart stalepath-time %u\n",
17256 bgp->stalepath_time);
17257
17258 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
17259 vty_out(vty, " bgp graceful-restart restart-time %u\n",
17260 bgp->restart_time);
17261
17262 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
17263 vty_out(vty,
17264 " bgp graceful-restart select-defer-time %u\n",
17265 bgp->select_defer_time);
17266
17267 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
17268 vty_out(vty, " bgp graceful-restart\n");
17269
17270 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
17271 vty_out(vty, " bgp graceful-restart-disable\n");
17272
17273 /* BGP graceful-restart Preserve State F bit. */
17274 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
17275 vty_out(vty,
17276 " bgp graceful-restart preserve-fw-state\n");
17277
17278 /* Stale timer for RIB */
17279 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
17280 vty_out(vty,
17281 " bgp graceful-restart rib-stale-time %u\n",
17282 bgp->rib_stale_time);
17283
17284 /* BGP bestpath method. */
17285 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
17286 vty_out(vty, " bgp bestpath as-path ignore\n");
17287 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
17288 vty_out(vty, " bgp bestpath as-path confed\n");
17289
17290 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
17291 if (CHECK_FLAG(bgp->flags,
17292 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
17293 vty_out(vty,
17294 " bgp bestpath as-path multipath-relax as-set\n");
17295 } else {
17296 vty_out(vty,
17297 " bgp bestpath as-path multipath-relax\n");
17298 }
17299 }
17300
17301 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
17302 vty_out(vty,
17303 " bgp route-reflector allow-outbound-policy\n");
17304 }
17305 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
17306 vty_out(vty, " bgp bestpath compare-routerid\n");
17307 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
17308 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
17309 vty_out(vty, " bgp bestpath med");
17310 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
17311 vty_out(vty, " confed");
17312 if (CHECK_FLAG(bgp->flags,
17313 BGP_FLAG_MED_MISSING_AS_WORST))
17314 vty_out(vty, " missing-as-worst");
17315 vty_out(vty, "\n");
17316 }
17317
17318 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
17319 vty_out(vty,
17320 " bgp bestpath peer-type multipath-relax\n");
17321
17322 /* Link bandwidth handling. */
17323 if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW)
17324 vty_out(vty, " bgp bestpath bandwidth ignore\n");
17325 else if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
17326 vty_out(vty, " bgp bestpath bandwidth skip-missing\n");
17327 else if (bgp->lb_handling == BGP_LINK_BW_DEFWT_4_MISSING)
17328 vty_out(vty, " bgp bestpath bandwidth default-weight-for-missing\n");
17329
17330 /* BGP network import check. */
17331 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
17332 != SAVE_BGP_IMPORT_CHECK)
17333 vty_out(vty, " %sbgp network import-check\n",
17334 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
17335 ? ""
17336 : "no ");
17337
17338 /* BGP timers configuration. */
17339 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
17340 || bgp->default_holdtime != SAVE_BGP_HOLDTIME)
17341 vty_out(vty, " timers bgp %u %u\n",
17342 bgp->default_keepalive, bgp->default_holdtime);
17343
17344 /* BGP minimum holdtime configuration. */
17345 if (bgp->default_min_holdtime != SAVE_BGP_HOLDTIME
17346 && bgp->default_min_holdtime != 0)
17347 vty_out(vty, " bgp minimum-holdtime %u\n",
17348 bgp->default_min_holdtime);
17349
17350 /* Conditional advertisement timer configuration */
17351 if (bgp->condition_check_period
17352 != DEFAULT_CONDITIONAL_ROUTES_POLL_TIME)
17353 vty_out(vty,
17354 " bgp conditional-advertisement timer %u\n",
17355 bgp->condition_check_period);
17356
17357 /* peer-group */
17358 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
17359 bgp_config_write_peer_global(vty, bgp, group->conf);
17360 }
17361
17362 /* Normal neighbor configuration. */
17363 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17364 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17365 bgp_config_write_peer_global(vty, bgp, peer);
17366 }
17367
17368 /* listen range and limit for dynamic BGP neighbors */
17369 bgp_config_write_listen(vty, bgp);
17370
17371 /*
17372 * BGP default autoshutdown neighbors
17373 *
17374 * This must be placed after any peer and peer-group
17375 * configuration, to avoid setting all peers to shutdown after
17376 * a daemon restart, which is undesired behavior. (see #2286)
17377 */
17378 if (bgp->autoshutdown)
17379 vty_out(vty, " bgp default shutdown\n");
17380
17381 /* BGP instance administrative shutdown */
17382 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN))
17383 vty_out(vty, " bgp shutdown\n");
17384
17385 if (bgp->fast_convergence)
17386 vty_out(vty, " bgp fast-convergence\n");
17387
17388 if (bgp->srv6_enabled) {
17389 vty_frame(vty, " !\n segment-routing srv6\n");
17390 if (strlen(bgp->srv6_locator_name))
17391 vty_out(vty, " locator %s\n",
17392 bgp->srv6_locator_name);
17393 vty_endframe(vty, " exit\n");
17394 }
17395
17396
17397 /* IPv4 unicast configuration. */
17398 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
17399
17400 /* IPv4 multicast configuration. */
17401 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
17402
17403 /* IPv4 labeled-unicast configuration. */
17404 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
17405
17406 /* IPv4 VPN configuration. */
17407 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
17408
17409 /* ENCAPv4 configuration. */
17410 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
17411
17412 /* FLOWSPEC v4 configuration. */
17413 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
17414
17415 /* IPv6 unicast configuration. */
17416 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
17417
17418 /* IPv6 multicast configuration. */
17419 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
17420
17421 /* IPv6 labeled-unicast configuration. */
17422 bgp_config_write_family(vty, bgp, AFI_IP6,
17423 SAFI_LABELED_UNICAST);
17424
17425 /* IPv6 VPN configuration. */
17426 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
17427
17428 /* ENCAPv6 configuration. */
17429 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
17430
17431 /* FLOWSPEC v6 configuration. */
17432 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
17433
17434 /* EVPN configuration. */
17435 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
17436
17437 hook_call(bgp_inst_config_write, bgp, vty);
17438
17439 #ifdef ENABLE_BGP_VNC
17440 bgp_rfapi_cfg_write(vty, bgp);
17441 #endif
17442
17443 vty_out(vty, "exit\n");
17444 vty_out(vty, "!\n");
17445 }
17446 return 0;
17447 }
17448
17449
17450 /* BGP node structure. */
17451 static struct cmd_node bgp_node = {
17452 .name = "bgp",
17453 .node = BGP_NODE,
17454 .parent_node = CONFIG_NODE,
17455 .prompt = "%s(config-router)# ",
17456 .config_write = bgp_config_write,
17457 };
17458
17459 static struct cmd_node bgp_ipv4_unicast_node = {
17460 .name = "bgp ipv4 unicast",
17461 .node = BGP_IPV4_NODE,
17462 .parent_node = BGP_NODE,
17463 .prompt = "%s(config-router-af)# ",
17464 .no_xpath = true,
17465 };
17466
17467 static struct cmd_node bgp_ipv4_multicast_node = {
17468 .name = "bgp ipv4 multicast",
17469 .node = BGP_IPV4M_NODE,
17470 .parent_node = BGP_NODE,
17471 .prompt = "%s(config-router-af)# ",
17472 .no_xpath = true,
17473 };
17474
17475 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
17476 .name = "bgp ipv4 labeled unicast",
17477 .node = BGP_IPV4L_NODE,
17478 .parent_node = BGP_NODE,
17479 .prompt = "%s(config-router-af)# ",
17480 .no_xpath = true,
17481 };
17482
17483 static struct cmd_node bgp_ipv6_unicast_node = {
17484 .name = "bgp ipv6 unicast",
17485 .node = BGP_IPV6_NODE,
17486 .parent_node = BGP_NODE,
17487 .prompt = "%s(config-router-af)# ",
17488 .no_xpath = true,
17489 };
17490
17491 static struct cmd_node bgp_ipv6_multicast_node = {
17492 .name = "bgp ipv6 multicast",
17493 .node = BGP_IPV6M_NODE,
17494 .parent_node = BGP_NODE,
17495 .prompt = "%s(config-router-af)# ",
17496 .no_xpath = true,
17497 };
17498
17499 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
17500 .name = "bgp ipv6 labeled unicast",
17501 .node = BGP_IPV6L_NODE,
17502 .parent_node = BGP_NODE,
17503 .prompt = "%s(config-router-af)# ",
17504 .no_xpath = true,
17505 };
17506
17507 static struct cmd_node bgp_vpnv4_node = {
17508 .name = "bgp vpnv4",
17509 .node = BGP_VPNV4_NODE,
17510 .parent_node = BGP_NODE,
17511 .prompt = "%s(config-router-af)# ",
17512 .no_xpath = true,
17513 };
17514
17515 static struct cmd_node bgp_vpnv6_node = {
17516 .name = "bgp vpnv6",
17517 .node = BGP_VPNV6_NODE,
17518 .parent_node = BGP_NODE,
17519 .prompt = "%s(config-router-af-vpnv6)# ",
17520 .no_xpath = true,
17521 };
17522
17523 static struct cmd_node bgp_evpn_node = {
17524 .name = "bgp evpn",
17525 .node = BGP_EVPN_NODE,
17526 .parent_node = BGP_NODE,
17527 .prompt = "%s(config-router-evpn)# ",
17528 .no_xpath = true,
17529 };
17530
17531 static struct cmd_node bgp_evpn_vni_node = {
17532 .name = "bgp evpn vni",
17533 .node = BGP_EVPN_VNI_NODE,
17534 .parent_node = BGP_EVPN_NODE,
17535 .prompt = "%s(config-router-af-vni)# ",
17536 };
17537
17538 static struct cmd_node bgp_flowspecv4_node = {
17539 .name = "bgp ipv4 flowspec",
17540 .node = BGP_FLOWSPECV4_NODE,
17541 .parent_node = BGP_NODE,
17542 .prompt = "%s(config-router-af)# ",
17543 .no_xpath = true,
17544 };
17545
17546 static struct cmd_node bgp_flowspecv6_node = {
17547 .name = "bgp ipv6 flowspec",
17548 .node = BGP_FLOWSPECV6_NODE,
17549 .parent_node = BGP_NODE,
17550 .prompt = "%s(config-router-af-vpnv6)# ",
17551 .no_xpath = true,
17552 };
17553
17554 static struct cmd_node bgp_srv6_node = {
17555 .name = "bgp srv6",
17556 .node = BGP_SRV6_NODE,
17557 .parent_node = BGP_NODE,
17558 .prompt = "%s(config-router-srv6)# ",
17559 };
17560
17561 static void community_list_vty(void);
17562
17563 static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
17564 {
17565 struct bgp *bgp;
17566 struct peer_group *group;
17567 struct listnode *lnbgp, *lnpeer;
17568
17569 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
17570 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
17571 vector_set(comps,
17572 XSTRDUP(MTYPE_COMPLETION, group->name));
17573 }
17574 }
17575
17576 static void bgp_ac_peer(vector comps, struct cmd_token *token)
17577 {
17578 struct bgp *bgp;
17579 struct peer *peer;
17580 struct listnode *lnbgp, *lnpeer;
17581
17582 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
17583 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
17584 /* only provide suggestions on the appropriate input
17585 * token type,
17586 * they'll otherwise show up multiple times */
17587 enum cmd_token_type match_type;
17588 char *name = peer->host;
17589
17590 if (peer->conf_if) {
17591 match_type = VARIABLE_TKN;
17592 name = peer->conf_if;
17593 } else if (strchr(peer->host, ':'))
17594 match_type = IPV6_TKN;
17595 else
17596 match_type = IPV4_TKN;
17597
17598 if (token->type != match_type)
17599 continue;
17600
17601 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
17602 }
17603 }
17604 }
17605
17606 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
17607 {
17608 bgp_ac_peer(comps, token);
17609
17610 if (token->type == VARIABLE_TKN)
17611 bgp_ac_peergroup(comps, token);
17612 }
17613
17614 static const struct cmd_variable_handler bgp_var_neighbor[] = {
17615 {.varname = "neighbor", .completions = bgp_ac_neighbor},
17616 {.varname = "neighbors", .completions = bgp_ac_neighbor},
17617 {.varname = "peer", .completions = bgp_ac_neighbor},
17618 {.completions = NULL}};
17619
17620 static const struct cmd_variable_handler bgp_var_peergroup[] = {
17621 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
17622 {.completions = NULL} };
17623
17624 DEFINE_HOOK(bgp_config_end, (struct bgp *bgp), (bgp));
17625
17626 static struct thread *t_bgp_cfg;
17627
17628 bool bgp_config_inprocess(void)
17629 {
17630 return thread_is_scheduled(t_bgp_cfg);
17631 }
17632
17633 static void bgp_config_finish(struct thread *t)
17634 {
17635 struct listnode *node;
17636 struct bgp *bgp;
17637
17638 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp))
17639 hook_call(bgp_config_end, bgp);
17640 }
17641
17642 static void bgp_config_start(void)
17643 {
17644 #define BGP_PRE_CONFIG_MAX_WAIT_SECONDS 600
17645 THREAD_OFF(t_bgp_cfg);
17646 thread_add_timer(bm->master, bgp_config_finish, NULL,
17647 BGP_PRE_CONFIG_MAX_WAIT_SECONDS, &t_bgp_cfg);
17648 }
17649
17650 /* When we receive a hook the configuration is read,
17651 * we start a timer to make sure we postpone sending
17652 * EoR before route-maps are processed.
17653 * This is especially valid if using `bgp route-map delay-timer`.
17654 */
17655 static void bgp_config_end(void)
17656 {
17657 #define BGP_POST_CONFIG_DELAY_SECONDS 1
17658 uint32_t bgp_post_config_delay =
17659 thread_is_scheduled(bm->t_rmap_update)
17660 ? thread_timer_remain_second(bm->t_rmap_update)
17661 : BGP_POST_CONFIG_DELAY_SECONDS;
17662
17663 /* If BGP config processing thread isn't running, then
17664 * we can return and rely it's properly handled.
17665 */
17666 if (!bgp_config_inprocess())
17667 return;
17668
17669 THREAD_OFF(t_bgp_cfg);
17670
17671 /* Start a new timer to make sure we don't send EoR
17672 * before route-maps are processed.
17673 */
17674 thread_add_timer(bm->master, bgp_config_finish, NULL,
17675 bgp_post_config_delay, &t_bgp_cfg);
17676 }
17677
17678 void bgp_vty_init(void)
17679 {
17680 cmd_variable_handler_register(bgp_var_neighbor);
17681 cmd_variable_handler_register(bgp_var_peergroup);
17682
17683 cmd_init_config_callbacks(bgp_config_start, bgp_config_end);
17684
17685 /* Install bgp top node. */
17686 install_node(&bgp_node);
17687 install_node(&bgp_ipv4_unicast_node);
17688 install_node(&bgp_ipv4_multicast_node);
17689 install_node(&bgp_ipv4_labeled_unicast_node);
17690 install_node(&bgp_ipv6_unicast_node);
17691 install_node(&bgp_ipv6_multicast_node);
17692 install_node(&bgp_ipv6_labeled_unicast_node);
17693 install_node(&bgp_vpnv4_node);
17694 install_node(&bgp_vpnv6_node);
17695 install_node(&bgp_evpn_node);
17696 install_node(&bgp_evpn_vni_node);
17697 install_node(&bgp_flowspecv4_node);
17698 install_node(&bgp_flowspecv6_node);
17699 install_node(&bgp_srv6_node);
17700
17701 /* Install default VTY commands to new nodes. */
17702 install_default(BGP_NODE);
17703 install_default(BGP_IPV4_NODE);
17704 install_default(BGP_IPV4M_NODE);
17705 install_default(BGP_IPV4L_NODE);
17706 install_default(BGP_IPV6_NODE);
17707 install_default(BGP_IPV6M_NODE);
17708 install_default(BGP_IPV6L_NODE);
17709 install_default(BGP_VPNV4_NODE);
17710 install_default(BGP_VPNV6_NODE);
17711 install_default(BGP_FLOWSPECV4_NODE);
17712 install_default(BGP_FLOWSPECV6_NODE);
17713 install_default(BGP_EVPN_NODE);
17714 install_default(BGP_EVPN_VNI_NODE);
17715 install_default(BGP_SRV6_NODE);
17716
17717 /* "bgp local-mac" hidden commands. */
17718 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
17719 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
17720
17721 /* "bgp suppress-fib-pending" global */
17722 install_element(CONFIG_NODE, &bgp_global_suppress_fib_pending_cmd);
17723
17724 /* bgp route-map delay-timer commands. */
17725 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
17726 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
17727
17728 /* bgp fast-convergence command */
17729 install_element(BGP_NODE, &bgp_fast_convergence_cmd);
17730 install_element(BGP_NODE, &no_bgp_fast_convergence_cmd);
17731
17732 /* global bgp update-delay command */
17733 install_element(CONFIG_NODE, &bgp_global_update_delay_cmd);
17734 install_element(CONFIG_NODE, &no_bgp_global_update_delay_cmd);
17735
17736 /* global bgp graceful-shutdown command */
17737 install_element(CONFIG_NODE, &bgp_graceful_shutdown_cmd);
17738 install_element(CONFIG_NODE, &no_bgp_graceful_shutdown_cmd);
17739
17740 /* Dummy commands (Currently not supported) */
17741 install_element(BGP_NODE, &no_synchronization_cmd);
17742 install_element(BGP_NODE, &no_auto_summary_cmd);
17743
17744 /* "router bgp" commands. */
17745 install_element(CONFIG_NODE, &router_bgp_cmd);
17746
17747 /* "no router bgp" commands. */
17748 install_element(CONFIG_NODE, &no_router_bgp_cmd);
17749
17750 /* "bgp router-id" commands. */
17751 install_element(BGP_NODE, &bgp_router_id_cmd);
17752 install_element(BGP_NODE, &no_bgp_router_id_cmd);
17753
17754 /* "bgp suppress-fib-pending" command */
17755 install_element(BGP_NODE, &bgp_suppress_fib_pending_cmd);
17756
17757 /* "bgp cluster-id" commands. */
17758 install_element(BGP_NODE, &bgp_cluster_id_cmd);
17759 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
17760
17761 /* "bgp no-rib" commands. */
17762 install_element(CONFIG_NODE, &bgp_norib_cmd);
17763 install_element(CONFIG_NODE, &no_bgp_norib_cmd);
17764
17765 install_element(CONFIG_NODE, &no_bgp_send_extra_data_cmd);
17766
17767 /* "bgp confederation" commands. */
17768 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
17769 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
17770
17771 /* "bgp confederation peers" commands. */
17772 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
17773 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
17774
17775 /* bgp max-med command */
17776 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
17777 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
17778 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
17779 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
17780 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
17781
17782 /* bgp disable-ebgp-connected-nh-check */
17783 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
17784 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
17785
17786 /* bgp update-delay command */
17787 install_element(BGP_NODE, &bgp_update_delay_cmd);
17788 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
17789
17790 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
17791 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
17792
17793 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
17794 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
17795
17796 /* "maximum-paths" commands. */
17797 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
17798 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
17799 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
17800 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
17801 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
17802 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
17803 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
17804 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
17805 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
17806 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
17807 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17808 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
17809 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
17810 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17811 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
17812
17813 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_cmd);
17814 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_cmd);
17815 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cmd);
17816 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17817 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_ibgp_cmd);
17818 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
17819 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
17820 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
17821 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17822 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
17823
17824 /* "timers bgp" commands. */
17825 install_element(BGP_NODE, &bgp_timers_cmd);
17826 install_element(BGP_NODE, &no_bgp_timers_cmd);
17827
17828 /* "minimum-holdtime" commands. */
17829 install_element(BGP_NODE, &bgp_minimum_holdtime_cmd);
17830 install_element(BGP_NODE, &no_bgp_minimum_holdtime_cmd);
17831
17832 /* route-map delay-timer commands - per instance for backwards compat.
17833 */
17834 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
17835 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
17836
17837 /* "bgp client-to-client reflection" commands */
17838 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
17839 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
17840
17841 /* "bgp always-compare-med" commands */
17842 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
17843 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
17844
17845 /* bgp ebgp-requires-policy */
17846 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
17847 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
17848
17849 /* bgp suppress-duplicates */
17850 install_element(BGP_NODE, &bgp_suppress_duplicates_cmd);
17851 install_element(BGP_NODE, &no_bgp_suppress_duplicates_cmd);
17852
17853 /* bgp reject-as-sets */
17854 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
17855 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
17856
17857 /* "bgp deterministic-med" commands */
17858 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
17859 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
17860
17861 /* "bgp graceful-restart" command */
17862 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
17863 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
17864
17865 /* "bgp graceful-restart-disable" command */
17866 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
17867 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
17868
17869 /* "neighbor a:b:c:d graceful-restart" command */
17870 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
17871 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
17872
17873 /* "neighbor a:b:c:d graceful-restart-disable" command */
17874 install_element(BGP_NODE,
17875 &bgp_neighbor_graceful_restart_disable_set_cmd);
17876 install_element(BGP_NODE,
17877 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
17878
17879 /* "neighbor a:b:c:d graceful-restart-helper" command */
17880 install_element(BGP_NODE,
17881 &bgp_neighbor_graceful_restart_helper_set_cmd);
17882 install_element(BGP_NODE,
17883 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
17884
17885 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
17886 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
17887 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
17888 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
17889 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
17890 install_element(BGP_NODE,
17891 &no_bgp_graceful_restart_select_defer_time_cmd);
17892 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
17893 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
17894
17895 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
17896 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
17897 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
17898 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
17899
17900 /* "bgp graceful-shutdown" commands */
17901 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
17902 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
17903
17904 /* "bgp long-lived-graceful-restart" commands */
17905 install_element(BGP_NODE, &bgp_llgr_stalepath_time_cmd);
17906 install_element(BGP_NODE, &no_bgp_llgr_stalepath_time_cmd);
17907
17908 /* "bgp fast-external-failover" commands */
17909 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
17910 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
17911
17912 /* "bgp bestpath compare-routerid" commands */
17913 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
17914 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
17915
17916 /* "bgp bestpath as-path ignore" commands */
17917 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
17918 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
17919
17920 /* "bgp bestpath as-path confed" commands */
17921 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
17922 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
17923
17924 /* "bgp bestpath as-path multipath-relax" commands */
17925 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
17926 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
17927
17928 /* "bgp bestpath peer-type multipath-relax" commands */
17929 install_element(BGP_NODE, &bgp_bestpath_peer_type_multipath_relax_cmd);
17930 install_element(BGP_NODE,
17931 &no_bgp_bestpath_peer_type_multipath_relax_cmd);
17932
17933 /* "bgp log-neighbor-changes" commands */
17934 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
17935 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
17936
17937 /* "bgp bestpath med" commands */
17938 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
17939 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
17940
17941 /* "bgp bestpath bandwidth" commands */
17942 install_element(BGP_NODE, &bgp_bestpath_bw_cmd);
17943 install_element(BGP_NODE, &no_bgp_bestpath_bw_cmd);
17944
17945 /* "no bgp default <afi>-<safi>" commands. */
17946 install_element(BGP_NODE, &bgp_default_afi_safi_cmd);
17947
17948 /* "bgp network import-check" commands. */
17949 install_element(BGP_NODE, &bgp_network_import_check_cmd);
17950 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
17951 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
17952
17953 /* "bgp default local-preference" commands. */
17954 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
17955 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
17956
17957 /* bgp default show-hostname */
17958 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
17959 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
17960
17961 /* bgp default show-nexthop-hostname */
17962 install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
17963 install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
17964
17965 /* "bgp default subgroup-pkt-queue-max" commands. */
17966 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
17967 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
17968
17969 /* bgp ibgp-allow-policy-mods command */
17970 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
17971 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
17972
17973 /* "bgp listen limit" commands. */
17974 install_element(BGP_NODE, &bgp_listen_limit_cmd);
17975 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
17976
17977 /* "bgp listen range" commands. */
17978 install_element(BGP_NODE, &bgp_listen_range_cmd);
17979 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
17980
17981 /* "bgp default shutdown" command */
17982 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
17983
17984 /* "bgp shutdown" commands */
17985 install_element(BGP_NODE, &bgp_shutdown_cmd);
17986 install_element(BGP_NODE, &bgp_shutdown_msg_cmd);
17987 install_element(BGP_NODE, &no_bgp_shutdown_cmd);
17988 install_element(BGP_NODE, &no_bgp_shutdown_msg_cmd);
17989
17990 /* "neighbor remote-as" commands. */
17991 install_element(BGP_NODE, &neighbor_remote_as_cmd);
17992 install_element(BGP_NODE, &neighbor_interface_config_cmd);
17993 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
17994 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
17995 install_element(BGP_NODE,
17996 &neighbor_interface_v6only_config_remote_as_cmd);
17997 install_element(BGP_NODE, &no_neighbor_cmd);
17998 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
17999
18000 /* "neighbor peer-group" commands. */
18001 install_element(BGP_NODE, &neighbor_peer_group_cmd);
18002 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
18003 install_element(BGP_NODE,
18004 &no_neighbor_interface_peer_group_remote_as_cmd);
18005
18006 /* "neighbor local-as" commands. */
18007 install_element(BGP_NODE, &neighbor_local_as_cmd);
18008 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
18009 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
18010 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
18011
18012 /* "neighbor solo" commands. */
18013 install_element(BGP_NODE, &neighbor_solo_cmd);
18014 install_element(BGP_NODE, &no_neighbor_solo_cmd);
18015
18016 /* "neighbor password" commands. */
18017 install_element(BGP_NODE, &neighbor_password_cmd);
18018 install_element(BGP_NODE, &no_neighbor_password_cmd);
18019
18020 /* "neighbor activate" commands. */
18021 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
18022 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
18023 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
18024 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
18025 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
18026 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
18027 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
18028 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
18029 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
18030 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
18031 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
18032 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
18033
18034 /* "no neighbor activate" commands. */
18035 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
18036 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
18037 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
18038 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
18039 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
18040 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
18041 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
18042 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
18043 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
18044 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
18045 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
18046 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
18047
18048 /* "neighbor peer-group" set commands. */
18049 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
18050 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
18051 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
18052 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
18053 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
18054 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
18055 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
18056 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
18057 install_element(BGP_FLOWSPECV4_NODE,
18058 &neighbor_set_peer_group_hidden_cmd);
18059 install_element(BGP_FLOWSPECV6_NODE,
18060 &neighbor_set_peer_group_hidden_cmd);
18061
18062 /* "no neighbor peer-group unset" commands. */
18063 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
18064 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18065 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18066 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18067 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18068 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18069 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18070 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18071 install_element(BGP_FLOWSPECV4_NODE,
18072 &no_neighbor_set_peer_group_hidden_cmd);
18073 install_element(BGP_FLOWSPECV6_NODE,
18074 &no_neighbor_set_peer_group_hidden_cmd);
18075
18076 /* "neighbor softreconfiguration inbound" commands.*/
18077 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
18078 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
18079 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
18080 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
18081 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
18082 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
18083 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
18084 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
18085 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
18086 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
18087 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
18088 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
18089 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
18090 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
18091 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
18092 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
18093 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
18094 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
18095 install_element(BGP_FLOWSPECV4_NODE,
18096 &neighbor_soft_reconfiguration_cmd);
18097 install_element(BGP_FLOWSPECV4_NODE,
18098 &no_neighbor_soft_reconfiguration_cmd);
18099 install_element(BGP_FLOWSPECV6_NODE,
18100 &neighbor_soft_reconfiguration_cmd);
18101 install_element(BGP_FLOWSPECV6_NODE,
18102 &no_neighbor_soft_reconfiguration_cmd);
18103 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
18104 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
18105
18106 /* "neighbor attribute-unchanged" commands. */
18107 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
18108 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
18109 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
18110 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
18111 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
18112 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
18113 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
18114 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
18115 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
18116 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
18117 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
18118 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
18119 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
18120 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
18121 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
18122 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
18123 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
18124 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
18125
18126 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
18127 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
18128
18129 install_element(BGP_FLOWSPECV4_NODE, &neighbor_attr_unchanged_cmd);
18130 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_attr_unchanged_cmd);
18131 install_element(BGP_FLOWSPECV6_NODE, &neighbor_attr_unchanged_cmd);
18132 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_attr_unchanged_cmd);
18133
18134 /* "nexthop-local unchanged" commands */
18135 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
18136 install_element(BGP_IPV6_NODE,
18137 &no_neighbor_nexthop_local_unchanged_cmd);
18138
18139 /* "neighbor next-hop-self" commands. */
18140 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
18141 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
18142 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
18143 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
18144 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
18145 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
18146 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
18147 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
18148 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
18149 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
18150 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
18151 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
18152 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
18153 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
18154 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
18155 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
18156 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
18157 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
18158 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
18159 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
18160
18161 /* "neighbor next-hop-self force" commands. */
18162 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
18163 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
18164 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18165 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
18166 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
18167 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
18168 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18169 install_element(BGP_IPV4_NODE,
18170 &no_neighbor_nexthop_self_all_hidden_cmd);
18171 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
18172 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
18173 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18174 install_element(BGP_IPV4M_NODE,
18175 &no_neighbor_nexthop_self_all_hidden_cmd);
18176 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
18177 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
18178 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18179 install_element(BGP_IPV4L_NODE,
18180 &no_neighbor_nexthop_self_all_hidden_cmd);
18181 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
18182 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
18183 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18184 install_element(BGP_IPV6_NODE,
18185 &no_neighbor_nexthop_self_all_hidden_cmd);
18186 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
18187 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
18188 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18189 install_element(BGP_IPV6M_NODE,
18190 &no_neighbor_nexthop_self_all_hidden_cmd);
18191 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
18192 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
18193 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18194 install_element(BGP_IPV6L_NODE,
18195 &no_neighbor_nexthop_self_all_hidden_cmd);
18196 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
18197 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
18198 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18199 install_element(BGP_VPNV4_NODE,
18200 &no_neighbor_nexthop_self_all_hidden_cmd);
18201 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
18202 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
18203 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18204 install_element(BGP_VPNV6_NODE,
18205 &no_neighbor_nexthop_self_all_hidden_cmd);
18206 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_force_cmd);
18207 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_force_cmd);
18208
18209 /* "neighbor as-override" commands. */
18210 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
18211 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
18212 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
18213 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
18214 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
18215 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
18216 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
18217 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
18218 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
18219 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
18220 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
18221 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
18222 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
18223 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
18224 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
18225 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
18226 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
18227 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
18228
18229 /* "neighbor remove-private-AS" commands. */
18230 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
18231 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
18232 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
18233 install_element(BGP_NODE,
18234 &no_neighbor_remove_private_as_all_hidden_cmd);
18235 install_element(BGP_NODE,
18236 &neighbor_remove_private_as_replace_as_hidden_cmd);
18237 install_element(BGP_NODE,
18238 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
18239 install_element(BGP_NODE,
18240 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
18241 install_element(
18242 BGP_NODE,
18243 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
18244 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
18245 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
18246 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
18247 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18248 install_element(BGP_IPV4_NODE,
18249 &neighbor_remove_private_as_replace_as_cmd);
18250 install_element(BGP_IPV4_NODE,
18251 &no_neighbor_remove_private_as_replace_as_cmd);
18252 install_element(BGP_IPV4_NODE,
18253 &neighbor_remove_private_as_all_replace_as_cmd);
18254 install_element(BGP_IPV4_NODE,
18255 &no_neighbor_remove_private_as_all_replace_as_cmd);
18256 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
18257 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
18258 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
18259 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
18260 install_element(BGP_IPV4M_NODE,
18261 &neighbor_remove_private_as_replace_as_cmd);
18262 install_element(BGP_IPV4M_NODE,
18263 &no_neighbor_remove_private_as_replace_as_cmd);
18264 install_element(BGP_IPV4M_NODE,
18265 &neighbor_remove_private_as_all_replace_as_cmd);
18266 install_element(BGP_IPV4M_NODE,
18267 &no_neighbor_remove_private_as_all_replace_as_cmd);
18268 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
18269 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
18270 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
18271 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
18272 install_element(BGP_IPV4L_NODE,
18273 &neighbor_remove_private_as_replace_as_cmd);
18274 install_element(BGP_IPV4L_NODE,
18275 &no_neighbor_remove_private_as_replace_as_cmd);
18276 install_element(BGP_IPV4L_NODE,
18277 &neighbor_remove_private_as_all_replace_as_cmd);
18278 install_element(BGP_IPV4L_NODE,
18279 &no_neighbor_remove_private_as_all_replace_as_cmd);
18280 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
18281 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
18282 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
18283 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18284 install_element(BGP_IPV6_NODE,
18285 &neighbor_remove_private_as_replace_as_cmd);
18286 install_element(BGP_IPV6_NODE,
18287 &no_neighbor_remove_private_as_replace_as_cmd);
18288 install_element(BGP_IPV6_NODE,
18289 &neighbor_remove_private_as_all_replace_as_cmd);
18290 install_element(BGP_IPV6_NODE,
18291 &no_neighbor_remove_private_as_all_replace_as_cmd);
18292 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
18293 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
18294 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
18295 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
18296 install_element(BGP_IPV6M_NODE,
18297 &neighbor_remove_private_as_replace_as_cmd);
18298 install_element(BGP_IPV6M_NODE,
18299 &no_neighbor_remove_private_as_replace_as_cmd);
18300 install_element(BGP_IPV6M_NODE,
18301 &neighbor_remove_private_as_all_replace_as_cmd);
18302 install_element(BGP_IPV6M_NODE,
18303 &no_neighbor_remove_private_as_all_replace_as_cmd);
18304 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
18305 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
18306 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
18307 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
18308 install_element(BGP_IPV6L_NODE,
18309 &neighbor_remove_private_as_replace_as_cmd);
18310 install_element(BGP_IPV6L_NODE,
18311 &no_neighbor_remove_private_as_replace_as_cmd);
18312 install_element(BGP_IPV6L_NODE,
18313 &neighbor_remove_private_as_all_replace_as_cmd);
18314 install_element(BGP_IPV6L_NODE,
18315 &no_neighbor_remove_private_as_all_replace_as_cmd);
18316 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
18317 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
18318 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
18319 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18320 install_element(BGP_VPNV4_NODE,
18321 &neighbor_remove_private_as_replace_as_cmd);
18322 install_element(BGP_VPNV4_NODE,
18323 &no_neighbor_remove_private_as_replace_as_cmd);
18324 install_element(BGP_VPNV4_NODE,
18325 &neighbor_remove_private_as_all_replace_as_cmd);
18326 install_element(BGP_VPNV4_NODE,
18327 &no_neighbor_remove_private_as_all_replace_as_cmd);
18328 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
18329 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
18330 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
18331 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18332 install_element(BGP_VPNV6_NODE,
18333 &neighbor_remove_private_as_replace_as_cmd);
18334 install_element(BGP_VPNV6_NODE,
18335 &no_neighbor_remove_private_as_replace_as_cmd);
18336 install_element(BGP_VPNV6_NODE,
18337 &neighbor_remove_private_as_all_replace_as_cmd);
18338 install_element(BGP_VPNV6_NODE,
18339 &no_neighbor_remove_private_as_all_replace_as_cmd);
18340
18341 /* "neighbor send-community" commands.*/
18342 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
18343 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
18344 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
18345 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
18346 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
18347 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
18348 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
18349 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
18350 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
18351 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
18352 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
18353 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
18354 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
18355 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
18356 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
18357 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
18358 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
18359 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
18360 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
18361 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
18362 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
18363 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
18364 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
18365 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
18366 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
18367 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
18368 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
18369 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
18370 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
18371 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
18372 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
18373 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
18374 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
18375 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
18376 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
18377 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
18378
18379 /* "neighbor route-reflector" commands.*/
18380 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
18381 install_element(BGP_NODE,
18382 &no_neighbor_route_reflector_client_hidden_cmd);
18383 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
18384 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
18385 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
18386 install_element(BGP_IPV4M_NODE,
18387 &no_neighbor_route_reflector_client_cmd);
18388 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
18389 install_element(BGP_IPV4L_NODE,
18390 &no_neighbor_route_reflector_client_cmd);
18391 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
18392 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
18393 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
18394 install_element(BGP_IPV6M_NODE,
18395 &no_neighbor_route_reflector_client_cmd);
18396 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
18397 install_element(BGP_IPV6L_NODE,
18398 &no_neighbor_route_reflector_client_cmd);
18399 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
18400 install_element(BGP_VPNV4_NODE,
18401 &no_neighbor_route_reflector_client_cmd);
18402 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
18403 install_element(BGP_VPNV6_NODE,
18404 &no_neighbor_route_reflector_client_cmd);
18405 install_element(BGP_FLOWSPECV4_NODE,
18406 &neighbor_route_reflector_client_cmd);
18407 install_element(BGP_FLOWSPECV4_NODE,
18408 &no_neighbor_route_reflector_client_cmd);
18409 install_element(BGP_FLOWSPECV6_NODE,
18410 &neighbor_route_reflector_client_cmd);
18411 install_element(BGP_FLOWSPECV6_NODE,
18412 &no_neighbor_route_reflector_client_cmd);
18413 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
18414 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
18415
18416 /* "neighbor route-server" commands.*/
18417 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
18418 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
18419 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
18420 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
18421 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
18422 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
18423 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
18424 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
18425 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
18426 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
18427 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
18428 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
18429 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
18430 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
18431 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
18432 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
18433 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
18434 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
18435 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
18436 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
18437 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
18438 install_element(BGP_FLOWSPECV4_NODE,
18439 &no_neighbor_route_server_client_cmd);
18440 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
18441 install_element(BGP_FLOWSPECV6_NODE,
18442 &no_neighbor_route_server_client_cmd);
18443
18444 /* "neighbor disable-addpath-rx" commands. */
18445 install_element(BGP_IPV4_NODE, &neighbor_disable_addpath_rx_cmd);
18446 install_element(BGP_IPV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
18447 install_element(BGP_IPV4M_NODE, &neighbor_disable_addpath_rx_cmd);
18448 install_element(BGP_IPV4M_NODE, &no_neighbor_disable_addpath_rx_cmd);
18449 install_element(BGP_IPV4L_NODE, &neighbor_disable_addpath_rx_cmd);
18450 install_element(BGP_IPV4L_NODE, &no_neighbor_disable_addpath_rx_cmd);
18451 install_element(BGP_IPV6_NODE, &neighbor_disable_addpath_rx_cmd);
18452 install_element(BGP_IPV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
18453 install_element(BGP_IPV6M_NODE, &neighbor_disable_addpath_rx_cmd);
18454 install_element(BGP_IPV6M_NODE, &no_neighbor_disable_addpath_rx_cmd);
18455 install_element(BGP_IPV6L_NODE, &neighbor_disable_addpath_rx_cmd);
18456 install_element(BGP_IPV6L_NODE, &no_neighbor_disable_addpath_rx_cmd);
18457 install_element(BGP_VPNV4_NODE, &neighbor_disable_addpath_rx_cmd);
18458 install_element(BGP_VPNV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
18459 install_element(BGP_VPNV6_NODE, &neighbor_disable_addpath_rx_cmd);
18460 install_element(BGP_VPNV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
18461
18462 /* "neighbor addpath-tx-all-paths" commands.*/
18463 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
18464 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
18465 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
18466 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18467 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
18468 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18469 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
18470 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18471 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
18472 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18473 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
18474 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18475 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
18476 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18477 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
18478 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18479 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
18480 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18481
18482 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
18483 install_element(BGP_NODE,
18484 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
18485 install_element(BGP_NODE,
18486 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
18487 install_element(BGP_IPV4_NODE,
18488 &neighbor_addpath_tx_bestpath_per_as_cmd);
18489 install_element(BGP_IPV4_NODE,
18490 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18491 install_element(BGP_IPV4M_NODE,
18492 &neighbor_addpath_tx_bestpath_per_as_cmd);
18493 install_element(BGP_IPV4M_NODE,
18494 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18495 install_element(BGP_IPV4L_NODE,
18496 &neighbor_addpath_tx_bestpath_per_as_cmd);
18497 install_element(BGP_IPV4L_NODE,
18498 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18499 install_element(BGP_IPV6_NODE,
18500 &neighbor_addpath_tx_bestpath_per_as_cmd);
18501 install_element(BGP_IPV6_NODE,
18502 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18503 install_element(BGP_IPV6M_NODE,
18504 &neighbor_addpath_tx_bestpath_per_as_cmd);
18505 install_element(BGP_IPV6M_NODE,
18506 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18507 install_element(BGP_IPV6L_NODE,
18508 &neighbor_addpath_tx_bestpath_per_as_cmd);
18509 install_element(BGP_IPV6L_NODE,
18510 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18511 install_element(BGP_VPNV4_NODE,
18512 &neighbor_addpath_tx_bestpath_per_as_cmd);
18513 install_element(BGP_VPNV4_NODE,
18514 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18515 install_element(BGP_VPNV6_NODE,
18516 &neighbor_addpath_tx_bestpath_per_as_cmd);
18517 install_element(BGP_VPNV6_NODE,
18518 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18519
18520 /* "neighbor sender-as-path-loop-detection" commands. */
18521 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
18522 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
18523
18524 /* "neighbor passive" commands. */
18525 install_element(BGP_NODE, &neighbor_passive_cmd);
18526 install_element(BGP_NODE, &no_neighbor_passive_cmd);
18527
18528
18529 /* "neighbor shutdown" commands. */
18530 install_element(BGP_NODE, &neighbor_shutdown_cmd);
18531 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
18532 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
18533 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
18534 install_element(BGP_NODE, &neighbor_shutdown_rtt_cmd);
18535 install_element(BGP_NODE, &no_neighbor_shutdown_rtt_cmd);
18536
18537 /* "neighbor capability extended-nexthop" commands.*/
18538 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
18539 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
18540
18541 /* "neighbor capability orf prefix-list" commands.*/
18542 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
18543 install_element(BGP_NODE,
18544 &no_neighbor_capability_orf_prefix_hidden_cmd);
18545 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
18546 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
18547 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
18548 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
18549 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
18550 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
18551 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
18552 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
18553 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
18554 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
18555 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
18556 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
18557
18558 /* "neighbor capability dynamic" commands.*/
18559 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
18560 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
18561
18562 /* "neighbor dont-capability-negotiate" commands. */
18563 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
18564 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
18565
18566 /* "neighbor ebgp-multihop" commands. */
18567 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
18568 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
18569 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
18570
18571 /* "neighbor disable-connected-check" commands. */
18572 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
18573 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
18574
18575 /* "neighbor disable-link-bw-encoding-ieee" commands. */
18576 install_element(BGP_NODE, &neighbor_disable_link_bw_encoding_ieee_cmd);
18577 install_element(BGP_NODE,
18578 &no_neighbor_disable_link_bw_encoding_ieee_cmd);
18579
18580 /* "neighbor extended-optional-parameters" commands. */
18581 install_element(BGP_NODE, &neighbor_extended_optional_parameters_cmd);
18582 install_element(BGP_NODE,
18583 &no_neighbor_extended_optional_parameters_cmd);
18584
18585 /* "neighbor enforce-first-as" commands. */
18586 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
18587 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
18588
18589 /* "neighbor description" commands. */
18590 install_element(BGP_NODE, &neighbor_description_cmd);
18591 install_element(BGP_NODE, &no_neighbor_description_cmd);
18592 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
18593
18594 /* "neighbor update-source" commands. "*/
18595 install_element(BGP_NODE, &neighbor_update_source_cmd);
18596 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
18597
18598 /* "neighbor default-originate" commands. */
18599 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
18600 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
18601 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
18602 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
18603 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
18604 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
18605 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
18606 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
18607 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
18608 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
18609 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
18610 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
18611 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
18612 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
18613 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
18614 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
18615 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
18616 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
18617 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
18618 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
18619 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
18620
18621 /* "neighbor port" commands. */
18622 install_element(BGP_NODE, &neighbor_port_cmd);
18623 install_element(BGP_NODE, &no_neighbor_port_cmd);
18624
18625 /* "neighbor weight" commands. */
18626 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
18627 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
18628
18629 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
18630 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
18631 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
18632 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
18633 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
18634 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
18635 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
18636 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
18637 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
18638 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
18639 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
18640 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
18641 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
18642 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
18643 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
18644 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
18645
18646 /* "neighbor override-capability" commands. */
18647 install_element(BGP_NODE, &neighbor_override_capability_cmd);
18648 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
18649
18650 /* "neighbor strict-capability-match" commands. */
18651 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
18652 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
18653
18654 /* "neighbor timers" commands. */
18655 install_element(BGP_NODE, &neighbor_timers_cmd);
18656 install_element(BGP_NODE, &no_neighbor_timers_cmd);
18657
18658 /* "neighbor timers connect" commands. */
18659 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
18660 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
18661
18662 /* "neighbor timers delayopen" commands. */
18663 install_element(BGP_NODE, &neighbor_timers_delayopen_cmd);
18664 install_element(BGP_NODE, &no_neighbor_timers_delayopen_cmd);
18665
18666 /* "neighbor advertisement-interval" commands. */
18667 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
18668 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
18669
18670 /* "neighbor interface" commands. */
18671 install_element(BGP_NODE, &neighbor_interface_cmd);
18672 install_element(BGP_NODE, &no_neighbor_interface_cmd);
18673
18674 /* "neighbor distribute" commands. */
18675 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
18676 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
18677 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
18678 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
18679 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
18680 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
18681 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
18682 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
18683 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
18684 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
18685 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
18686 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
18687 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
18688 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
18689 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
18690 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
18691 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
18692 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
18693
18694 /* "neighbor prefix-list" commands. */
18695 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
18696 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
18697 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
18698 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
18699 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
18700 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
18701 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
18702 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
18703 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
18704 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
18705 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
18706 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
18707 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
18708 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
18709 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
18710 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
18711 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
18712 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
18713 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
18714 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
18715 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
18716 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
18717
18718 /* "neighbor filter-list" commands. */
18719 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
18720 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
18721 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
18722 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
18723 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
18724 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
18725 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
18726 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
18727 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
18728 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
18729 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
18730 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
18731 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
18732 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
18733 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
18734 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
18735 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
18736 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
18737 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
18738 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
18739 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
18740 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
18741
18742 /* "neighbor route-map" commands. */
18743 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
18744 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
18745 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
18746 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
18747 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
18748 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
18749 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
18750 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
18751 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
18752 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
18753 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
18754 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
18755 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
18756 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
18757 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
18758 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
18759 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
18760 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
18761 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
18762 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
18763 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
18764 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
18765 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
18766 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
18767
18768 /* "neighbor unsuppress-map" commands. */
18769 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
18770 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
18771 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
18772 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
18773 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
18774 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
18775 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
18776 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
18777 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
18778 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
18779 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
18780 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
18781 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
18782 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
18783 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
18784 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
18785 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
18786 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
18787
18788 /* "neighbor advertise-map" commands. */
18789 install_element(BGP_NODE, &bgp_condadv_period_cmd);
18790 install_element(BGP_NODE, &neighbor_advertise_map_hidden_cmd);
18791 install_element(BGP_IPV4_NODE, &neighbor_advertise_map_cmd);
18792 install_element(BGP_IPV4M_NODE, &neighbor_advertise_map_cmd);
18793 install_element(BGP_IPV4L_NODE, &neighbor_advertise_map_cmd);
18794 install_element(BGP_IPV6_NODE, &neighbor_advertise_map_cmd);
18795 install_element(BGP_IPV6M_NODE, &neighbor_advertise_map_cmd);
18796 install_element(BGP_IPV6L_NODE, &neighbor_advertise_map_cmd);
18797 install_element(BGP_VPNV4_NODE, &neighbor_advertise_map_cmd);
18798 install_element(BGP_VPNV6_NODE, &neighbor_advertise_map_cmd);
18799
18800 /* neighbor maximum-prefix-out commands. */
18801 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
18802 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
18803 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
18804 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
18805 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
18806 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
18807 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
18808 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
18809 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
18810 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
18811 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
18812 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
18813 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
18814 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
18815 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
18816 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
18817 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
18818 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
18819
18820 /* "neighbor maximum-prefix" commands. */
18821 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
18822 install_element(BGP_NODE,
18823 &neighbor_maximum_prefix_threshold_hidden_cmd);
18824 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
18825 install_element(BGP_NODE,
18826 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
18827 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
18828 install_element(BGP_NODE,
18829 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
18830 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
18831 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
18832 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
18833 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
18834 install_element(BGP_IPV4_NODE,
18835 &neighbor_maximum_prefix_threshold_warning_cmd);
18836 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
18837 install_element(BGP_IPV4_NODE,
18838 &neighbor_maximum_prefix_threshold_restart_cmd);
18839 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
18840 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
18841 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
18842 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
18843 install_element(BGP_IPV4M_NODE,
18844 &neighbor_maximum_prefix_threshold_warning_cmd);
18845 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
18846 install_element(BGP_IPV4M_NODE,
18847 &neighbor_maximum_prefix_threshold_restart_cmd);
18848 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
18849 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
18850 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
18851 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
18852 install_element(BGP_IPV4L_NODE,
18853 &neighbor_maximum_prefix_threshold_warning_cmd);
18854 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
18855 install_element(BGP_IPV4L_NODE,
18856 &neighbor_maximum_prefix_threshold_restart_cmd);
18857 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
18858 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
18859 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
18860 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
18861 install_element(BGP_IPV6_NODE,
18862 &neighbor_maximum_prefix_threshold_warning_cmd);
18863 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
18864 install_element(BGP_IPV6_NODE,
18865 &neighbor_maximum_prefix_threshold_restart_cmd);
18866 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
18867 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
18868 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
18869 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
18870 install_element(BGP_IPV6M_NODE,
18871 &neighbor_maximum_prefix_threshold_warning_cmd);
18872 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
18873 install_element(BGP_IPV6M_NODE,
18874 &neighbor_maximum_prefix_threshold_restart_cmd);
18875 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
18876 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
18877 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
18878 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
18879 install_element(BGP_IPV6L_NODE,
18880 &neighbor_maximum_prefix_threshold_warning_cmd);
18881 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
18882 install_element(BGP_IPV6L_NODE,
18883 &neighbor_maximum_prefix_threshold_restart_cmd);
18884 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
18885 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
18886 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
18887 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
18888 install_element(BGP_VPNV4_NODE,
18889 &neighbor_maximum_prefix_threshold_warning_cmd);
18890 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
18891 install_element(BGP_VPNV4_NODE,
18892 &neighbor_maximum_prefix_threshold_restart_cmd);
18893 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
18894 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
18895 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
18896 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
18897 install_element(BGP_VPNV6_NODE,
18898 &neighbor_maximum_prefix_threshold_warning_cmd);
18899 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
18900 install_element(BGP_VPNV6_NODE,
18901 &neighbor_maximum_prefix_threshold_restart_cmd);
18902 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
18903
18904 /* "neighbor allowas-in" */
18905 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
18906 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
18907 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
18908 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
18909 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
18910 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
18911 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
18912 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
18913 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
18914 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
18915 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
18916 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
18917 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
18918 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
18919 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
18920 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
18921 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
18922 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
18923 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
18924 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
18925
18926 /* address-family commands. */
18927 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
18928 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
18929 #ifdef KEEP_OLD_VPN_COMMANDS
18930 install_element(BGP_NODE, &address_family_vpnv4_cmd);
18931 install_element(BGP_NODE, &address_family_vpnv6_cmd);
18932 #endif /* KEEP_OLD_VPN_COMMANDS */
18933
18934 install_element(BGP_NODE, &address_family_evpn_cmd);
18935
18936 /* "exit-address-family" command. */
18937 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
18938 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
18939 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
18940 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
18941 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
18942 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
18943 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
18944 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
18945 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
18946 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
18947 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
18948
18949 /* "clear ip bgp commands" */
18950 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
18951
18952 /* clear ip bgp prefix */
18953 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
18954 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
18955 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
18956
18957 /* "show [ip] bgp summary" commands. */
18958 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
18959 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
18960 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
18961 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
18962 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
18963 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
18964 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
18965
18966 /* "show [ip] bgp neighbors" commands. */
18967 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
18968
18969 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
18970
18971 /* "show [ip] bgp peer-group" commands. */
18972 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
18973
18974 /* "show [ip] bgp paths" commands. */
18975 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
18976
18977 /* "show [ip] bgp community" commands. */
18978 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
18979
18980 /* "show ip bgp large-community" commands. */
18981 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
18982 /* "show [ip] bgp attribute-info" commands. */
18983 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
18984 /* "show [ip] bgp route-leak" command */
18985 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
18986
18987 /* "redistribute" commands. */
18988 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
18989 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
18990 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
18991 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
18992 install_element(BGP_NODE,
18993 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
18994 install_element(BGP_NODE,
18995 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
18996 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
18997 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
18998 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
18999 install_element(BGP_NODE,
19000 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
19001 install_element(BGP_NODE,
19002 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
19003 install_element(BGP_NODE,
19004 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
19005 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
19006 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
19007 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
19008 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
19009 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
19010 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
19011 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
19012 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
19013 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
19014 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
19015 install_element(BGP_IPV4_NODE,
19016 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
19017 install_element(BGP_IPV4_NODE,
19018 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
19019 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
19020 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
19021 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
19022 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
19023 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
19024 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
19025
19026 /* import|export vpn [route-map WORD] */
19027 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
19028 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
19029
19030 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
19031 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
19032
19033 /* ttl_security commands */
19034 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
19035 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
19036
19037 /* "show [ip] bgp memory" commands. */
19038 install_element(VIEW_NODE, &show_bgp_memory_cmd);
19039
19040 /* "show bgp martian next-hop" */
19041 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
19042
19043 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
19044
19045 /* "show [ip] bgp views" commands. */
19046 install_element(VIEW_NODE, &show_bgp_views_cmd);
19047
19048 /* "show [ip] bgp vrfs" commands. */
19049 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
19050
19051 /* Community-list. */
19052 community_list_vty();
19053
19054 community_alias_vty();
19055
19056 /* vpn-policy commands */
19057 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
19058 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
19059 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
19060 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
19061 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
19062 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
19063 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
19064 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
19065 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
19066 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
19067 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
19068 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
19069
19070 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
19071 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
19072
19073 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
19074 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
19075 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
19076 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
19077 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
19078 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
19079 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
19080 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
19081 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
19082 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
19083
19084 /* tcp-mss command */
19085 install_element(BGP_NODE, &neighbor_tcp_mss_cmd);
19086 install_element(BGP_NODE, &no_neighbor_tcp_mss_cmd);
19087
19088 /* srv6 commands */
19089 install_element(VIEW_NODE, &show_bgp_srv6_cmd);
19090 install_element(BGP_NODE, &bgp_segment_routing_srv6_cmd);
19091 install_element(BGP_NODE, &no_bgp_segment_routing_srv6_cmd);
19092 install_element(BGP_SRV6_NODE, &bgp_srv6_locator_cmd);
19093 install_element(BGP_SRV6_NODE, &no_bgp_srv6_locator_cmd);
19094 install_element(BGP_IPV4_NODE, &af_sid_vpn_export_cmd);
19095 install_element(BGP_IPV6_NODE, &af_sid_vpn_export_cmd);
19096 }
19097
19098 #include "memory.h"
19099 #include "bgp_regex.h"
19100 #include "bgp_clist.h"
19101 #include "bgp_ecommunity.h"
19102
19103 /* VTY functions. */
19104
19105 /* Direction value to string conversion. */
19106 static const char *community_direct_str(int direct)
19107 {
19108 switch (direct) {
19109 case COMMUNITY_DENY:
19110 return "deny";
19111 case COMMUNITY_PERMIT:
19112 return "permit";
19113 default:
19114 return "unknown";
19115 }
19116 }
19117
19118 /* Display error string. */
19119 static void community_list_perror(struct vty *vty, int ret)
19120 {
19121 switch (ret) {
19122 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
19123 vty_out(vty, "%% Can't find community-list\n");
19124 break;
19125 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
19126 vty_out(vty, "%% Malformed community-list value\n");
19127 break;
19128 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
19129 vty_out(vty,
19130 "%% Community name conflict, previously defined as standard community\n");
19131 break;
19132 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
19133 vty_out(vty,
19134 "%% Community name conflict, previously defined as expanded community\n");
19135 break;
19136 }
19137 }
19138
19139 /* "community-list" keyword help string. */
19140 #define COMMUNITY_LIST_STR "Add a community list entry\n"
19141
19142 /*community-list standard */
19143 DEFUN (community_list_standard,
19144 bgp_community_list_standard_cmd,
19145 "bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
19146 BGP_STR
19147 COMMUNITY_LIST_STR
19148 "Community list number (standard)\n"
19149 "Add an standard community-list entry\n"
19150 "Community list name\n"
19151 "Sequence number of an entry\n"
19152 "Sequence number\n"
19153 "Specify community to reject\n"
19154 "Specify community to accept\n"
19155 COMMUNITY_VAL_STR)
19156 {
19157 char *cl_name_or_number = NULL;
19158 char *seq = NULL;
19159 int direct = 0;
19160 int style = COMMUNITY_LIST_STANDARD;
19161 int idx = 0;
19162
19163 argv_find(argv, argc, "(0-4294967295)", &idx);
19164 if (idx)
19165 seq = argv[idx]->arg;
19166
19167 idx = 0;
19168 argv_find(argv, argc, "(1-99)", &idx);
19169 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
19170 cl_name_or_number = argv[idx]->arg;
19171 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19172 : COMMUNITY_DENY;
19173 argv_find(argv, argc, "AA:NN", &idx);
19174 char *str = argv_concat(argv, argc, idx);
19175
19176 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19177 direct, style);
19178
19179 XFREE(MTYPE_TMP, str);
19180
19181 if (ret < 0) {
19182 /* Display error string. */
19183 community_list_perror(vty, ret);
19184 return CMD_WARNING_CONFIG_FAILED;
19185 }
19186
19187 return CMD_SUCCESS;
19188 }
19189
19190 DEFUN (no_community_list_standard_all,
19191 no_bgp_community_list_standard_all_cmd,
19192 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
19193 NO_STR
19194 BGP_STR
19195 COMMUNITY_LIST_STR
19196 "Community list number (standard)\n"
19197 "Add an standard community-list entry\n"
19198 "Community list name\n"
19199 "Sequence number of an entry\n"
19200 "Sequence number\n"
19201 "Specify community to reject\n"
19202 "Specify community to accept\n"
19203 COMMUNITY_VAL_STR)
19204 {
19205 char *cl_name_or_number = NULL;
19206 char *str = NULL;
19207 int direct = 0;
19208 int style = COMMUNITY_LIST_STANDARD;
19209 char *seq = NULL;
19210 int idx = 0;
19211
19212 argv_find(argv, argc, "(0-4294967295)", &idx);
19213 if (idx)
19214 seq = argv[idx]->arg;
19215
19216 idx = 0;
19217 argv_find(argv, argc, "permit", &idx);
19218 argv_find(argv, argc, "deny", &idx);
19219
19220 if (idx) {
19221 direct = argv_find(argv, argc, "permit", &idx)
19222 ? COMMUNITY_PERMIT
19223 : COMMUNITY_DENY;
19224
19225 idx = 0;
19226 argv_find(argv, argc, "AA:NN", &idx);
19227 str = argv_concat(argv, argc, idx);
19228 }
19229
19230 idx = 0;
19231 argv_find(argv, argc, "(1-99)", &idx);
19232 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
19233 cl_name_or_number = argv[idx]->arg;
19234
19235 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
19236 direct, style);
19237
19238 XFREE(MTYPE_TMP, str);
19239
19240 if (ret < 0) {
19241 community_list_perror(vty, ret);
19242 return CMD_WARNING_CONFIG_FAILED;
19243 }
19244
19245 return CMD_SUCCESS;
19246 }
19247
19248 ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
19249 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME>",
19250 NO_STR BGP_STR COMMUNITY_LIST_STR
19251 "Community list number (standard)\n"
19252 "Add an standard community-list entry\n"
19253 "Community list name\n")
19254
19255 /*community-list expanded */
19256 DEFUN (community_list_expanded_all,
19257 bgp_community_list_expanded_all_cmd,
19258 "bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
19259 BGP_STR
19260 COMMUNITY_LIST_STR
19261 "Community list number (expanded)\n"
19262 "Add an expanded community-list entry\n"
19263 "Community list name\n"
19264 "Sequence number of an entry\n"
19265 "Sequence number\n"
19266 "Specify community to reject\n"
19267 "Specify community to accept\n"
19268 COMMUNITY_VAL_STR)
19269 {
19270 char *cl_name_or_number = NULL;
19271 char *seq = NULL;
19272 int direct = 0;
19273 int style = COMMUNITY_LIST_EXPANDED;
19274 int idx = 0;
19275
19276 argv_find(argv, argc, "(0-4294967295)", &idx);
19277 if (idx)
19278 seq = argv[idx]->arg;
19279
19280 idx = 0;
19281
19282 argv_find(argv, argc, "(100-500)", &idx);
19283 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
19284 cl_name_or_number = argv[idx]->arg;
19285 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19286 : COMMUNITY_DENY;
19287 argv_find(argv, argc, "AA:NN", &idx);
19288 char *str = argv_concat(argv, argc, idx);
19289
19290 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19291 direct, style);
19292
19293 XFREE(MTYPE_TMP, str);
19294
19295 if (ret < 0) {
19296 /* Display error string. */
19297 community_list_perror(vty, ret);
19298 return CMD_WARNING_CONFIG_FAILED;
19299 }
19300
19301 return CMD_SUCCESS;
19302 }
19303
19304 DEFUN (no_community_list_expanded_all,
19305 no_bgp_community_list_expanded_all_cmd,
19306 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
19307 NO_STR
19308 BGP_STR
19309 COMMUNITY_LIST_STR
19310 "Community list number (expanded)\n"
19311 "Add an expanded community-list entry\n"
19312 "Community list name\n"
19313 "Sequence number of an entry\n"
19314 "Sequence number\n"
19315 "Specify community to reject\n"
19316 "Specify community to accept\n"
19317 COMMUNITY_VAL_STR)
19318 {
19319 char *cl_name_or_number = NULL;
19320 char *seq = NULL;
19321 char *str = NULL;
19322 int direct = 0;
19323 int style = COMMUNITY_LIST_EXPANDED;
19324 int idx = 0;
19325
19326 argv_find(argv, argc, "(0-4294967295)", &idx);
19327 if (idx)
19328 seq = argv[idx]->arg;
19329
19330 idx = 0;
19331 argv_find(argv, argc, "permit", &idx);
19332 argv_find(argv, argc, "deny", &idx);
19333
19334 if (idx) {
19335 direct = argv_find(argv, argc, "permit", &idx)
19336 ? COMMUNITY_PERMIT
19337 : COMMUNITY_DENY;
19338
19339 idx = 0;
19340 argv_find(argv, argc, "AA:NN", &idx);
19341 str = argv_concat(argv, argc, idx);
19342 }
19343
19344 idx = 0;
19345 argv_find(argv, argc, "(100-500)", &idx);
19346 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
19347 cl_name_or_number = argv[idx]->arg;
19348
19349 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
19350 direct, style);
19351
19352 XFREE(MTYPE_TMP, str);
19353
19354 if (ret < 0) {
19355 community_list_perror(vty, ret);
19356 return CMD_WARNING_CONFIG_FAILED;
19357 }
19358
19359 return CMD_SUCCESS;
19360 }
19361
19362 ALIAS(no_community_list_expanded_all,
19363 no_bgp_community_list_expanded_all_list_cmd,
19364 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME>",
19365 NO_STR BGP_STR COMMUNITY_LIST_STR
19366 "Community list number (expanded)\n"
19367 "Add an expanded community-list entry\n"
19368 "Community list name\n")
19369
19370 /* Return configuration string of community-list entry. */
19371 static const char *community_list_config_str(struct community_entry *entry)
19372 {
19373 const char *str;
19374
19375 if (entry->any)
19376 str = "";
19377 else {
19378 if (entry->style == COMMUNITY_LIST_STANDARD)
19379 str = community_str(entry->u.com, false, false);
19380 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
19381 str = lcommunity_str(entry->u.lcom, false, false);
19382 else
19383 str = entry->config;
19384 }
19385 return str;
19386 }
19387
19388 static void community_list_show(struct vty *vty, struct community_list *list)
19389 {
19390 struct community_entry *entry;
19391
19392 for (entry = list->head; entry; entry = entry->next) {
19393 if (entry == list->head) {
19394 if (all_digit(list->name))
19395 vty_out(vty, "Community %s list %s\n",
19396 entry->style == COMMUNITY_LIST_STANDARD
19397 ? "standard"
19398 : "(expanded) access",
19399 list->name);
19400 else
19401 vty_out(vty, "Named Community %s list %s\n",
19402 entry->style == COMMUNITY_LIST_STANDARD
19403 ? "standard"
19404 : "expanded",
19405 list->name);
19406 }
19407 if (entry->any)
19408 vty_out(vty, " %s\n",
19409 community_direct_str(entry->direct));
19410 else
19411 vty_out(vty, " %s %s\n",
19412 community_direct_str(entry->direct),
19413 community_list_config_str(entry));
19414 }
19415 }
19416
19417 DEFUN (show_community_list,
19418 show_bgp_community_list_cmd,
19419 "show bgp community-list",
19420 SHOW_STR
19421 BGP_STR
19422 "List community-list\n")
19423 {
19424 struct community_list *list;
19425 struct community_list_master *cm;
19426
19427 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
19428 if (!cm)
19429 return CMD_SUCCESS;
19430
19431 for (list = cm->num.head; list; list = list->next)
19432 community_list_show(vty, list);
19433
19434 for (list = cm->str.head; list; list = list->next)
19435 community_list_show(vty, list);
19436
19437 return CMD_SUCCESS;
19438 }
19439
19440 DEFUN (show_community_list_arg,
19441 show_bgp_community_list_arg_cmd,
19442 "show bgp community-list <(1-500)|COMMUNITY_LIST_NAME> detail",
19443 SHOW_STR
19444 BGP_STR
19445 "List community-list\n"
19446 "Community-list number\n"
19447 "Community-list name\n"
19448 "Detailed information on community-list\n")
19449 {
19450 int idx_comm_list = 3;
19451 struct community_list *list;
19452
19453 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
19454 COMMUNITY_LIST_MASTER);
19455 if (!list) {
19456 vty_out(vty, "%% Can't find community-list\n");
19457 return CMD_WARNING;
19458 }
19459
19460 community_list_show(vty, list);
19461
19462 return CMD_SUCCESS;
19463 }
19464
19465 /*
19466 * Large Community code.
19467 */
19468 static int lcommunity_list_set_vty(struct vty *vty, int argc,
19469 struct cmd_token **argv, int style,
19470 int reject_all_digit_name)
19471 {
19472 int ret;
19473 int direct;
19474 char *str;
19475 int idx = 0;
19476 char *cl_name;
19477 char *seq = NULL;
19478
19479 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19480 seq = argv[idx]->arg;
19481
19482 idx = 0;
19483 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19484 : COMMUNITY_DENY;
19485
19486 /* All digit name check. */
19487 idx = 0;
19488 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
19489 argv_find(argv, argc, "(1-99)", &idx);
19490 argv_find(argv, argc, "(100-500)", &idx);
19491 cl_name = argv[idx]->arg;
19492 if (reject_all_digit_name && all_digit(cl_name)) {
19493 vty_out(vty, "%% Community name cannot have all digits\n");
19494 return CMD_WARNING_CONFIG_FAILED;
19495 }
19496
19497 idx = 0;
19498 argv_find(argv, argc, "AA:BB:CC", &idx);
19499 argv_find(argv, argc, "LINE", &idx);
19500 /* Concat community string argument. */
19501 if (idx)
19502 str = argv_concat(argv, argc, idx);
19503 else
19504 str = NULL;
19505
19506 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
19507
19508 /* Free temporary community list string allocated by
19509 argv_concat(). */
19510 XFREE(MTYPE_TMP, str);
19511
19512 if (ret < 0) {
19513 community_list_perror(vty, ret);
19514 return CMD_WARNING_CONFIG_FAILED;
19515 }
19516 return CMD_SUCCESS;
19517 }
19518
19519 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
19520 struct cmd_token **argv, int style)
19521 {
19522 int ret;
19523 int direct = 0;
19524 char *str = NULL;
19525 int idx = 0;
19526 char *seq = NULL;
19527
19528 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19529 seq = argv[idx]->arg;
19530
19531 idx = 0;
19532 argv_find(argv, argc, "permit", &idx);
19533 argv_find(argv, argc, "deny", &idx);
19534
19535 if (idx) {
19536 /* Check the list direct. */
19537 if (strncmp(argv[idx]->arg, "p", 1) == 0)
19538 direct = COMMUNITY_PERMIT;
19539 else
19540 direct = COMMUNITY_DENY;
19541
19542 idx = 0;
19543 argv_find(argv, argc, "LINE", &idx);
19544 argv_find(argv, argc, "AA:AA:NN", &idx);
19545 /* Concat community string argument. */
19546 str = argv_concat(argv, argc, idx);
19547 }
19548
19549 idx = 0;
19550 argv_find(argv, argc, "(1-99)", &idx);
19551 argv_find(argv, argc, "(100-500)", &idx);
19552 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
19553
19554 /* Unset community list. */
19555 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
19556 style);
19557
19558 /* Free temporary community list string allocated by
19559 argv_concat(). */
19560 XFREE(MTYPE_TMP, str);
19561
19562 if (ret < 0) {
19563 community_list_perror(vty, ret);
19564 return CMD_WARNING_CONFIG_FAILED;
19565 }
19566
19567 return CMD_SUCCESS;
19568 }
19569
19570 /* "large-community-list" keyword help string. */
19571 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
19572 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
19573
19574 DEFUN (lcommunity_list_standard,
19575 bgp_lcommunity_list_standard_cmd,
19576 "bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
19577 BGP_STR
19578 LCOMMUNITY_LIST_STR
19579 "Large Community list number (standard)\n"
19580 "Sequence number of an entry\n"
19581 "Sequence number\n"
19582 "Specify large community to reject\n"
19583 "Specify large community to accept\n"
19584 LCOMMUNITY_VAL_STR)
19585 {
19586 return lcommunity_list_set_vty(vty, argc, argv,
19587 LARGE_COMMUNITY_LIST_STANDARD, 0);
19588 }
19589
19590 DEFUN (lcommunity_list_expanded,
19591 bgp_lcommunity_list_expanded_cmd,
19592 "bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
19593 BGP_STR
19594 LCOMMUNITY_LIST_STR
19595 "Large Community list number (expanded)\n"
19596 "Sequence number of an entry\n"
19597 "Sequence number\n"
19598 "Specify large community to reject\n"
19599 "Specify large community to accept\n"
19600 "An ordered list as a regular-expression\n")
19601 {
19602 return lcommunity_list_set_vty(vty, argc, argv,
19603 LARGE_COMMUNITY_LIST_EXPANDED, 0);
19604 }
19605
19606 DEFUN (lcommunity_list_name_standard,
19607 bgp_lcommunity_list_name_standard_cmd,
19608 "bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
19609 BGP_STR
19610 LCOMMUNITY_LIST_STR
19611 "Specify standard large-community-list\n"
19612 "Large Community list name\n"
19613 "Sequence number of an entry\n"
19614 "Sequence number\n"
19615 "Specify large community to reject\n"
19616 "Specify large community to accept\n"
19617 LCOMMUNITY_VAL_STR)
19618 {
19619 return lcommunity_list_set_vty(vty, argc, argv,
19620 LARGE_COMMUNITY_LIST_STANDARD, 1);
19621 }
19622
19623 DEFUN (lcommunity_list_name_expanded,
19624 bgp_lcommunity_list_name_expanded_cmd,
19625 "bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
19626 BGP_STR
19627 LCOMMUNITY_LIST_STR
19628 "Specify expanded large-community-list\n"
19629 "Large Community list name\n"
19630 "Sequence number of an entry\n"
19631 "Sequence number\n"
19632 "Specify large community to reject\n"
19633 "Specify large community to accept\n"
19634 "An ordered list as a regular-expression\n")
19635 {
19636 return lcommunity_list_set_vty(vty, argc, argv,
19637 LARGE_COMMUNITY_LIST_EXPANDED, 1);
19638 }
19639
19640 DEFUN (no_lcommunity_list_all,
19641 no_bgp_lcommunity_list_all_cmd,
19642 "no bgp large-community-list <(1-99)|(100-500)|LCOMMUNITY_LIST_NAME>",
19643 NO_STR
19644 BGP_STR
19645 LCOMMUNITY_LIST_STR
19646 "Large Community list number (standard)\n"
19647 "Large Community list number (expanded)\n"
19648 "Large Community list name\n")
19649 {
19650 return lcommunity_list_unset_vty(vty, argc, argv,
19651 LARGE_COMMUNITY_LIST_STANDARD);
19652 }
19653
19654 DEFUN (no_lcommunity_list_name_standard_all,
19655 no_bgp_lcommunity_list_name_standard_all_cmd,
19656 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME",
19657 NO_STR
19658 BGP_STR
19659 LCOMMUNITY_LIST_STR
19660 "Specify standard large-community-list\n"
19661 "Large Community list name\n")
19662 {
19663 return lcommunity_list_unset_vty(vty, argc, argv,
19664 LARGE_COMMUNITY_LIST_STANDARD);
19665 }
19666
19667 DEFUN (no_lcommunity_list_name_expanded_all,
19668 no_bgp_lcommunity_list_name_expanded_all_cmd,
19669 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME",
19670 NO_STR
19671 BGP_STR
19672 LCOMMUNITY_LIST_STR
19673 "Specify expanded large-community-list\n"
19674 "Large Community list name\n")
19675 {
19676 return lcommunity_list_unset_vty(vty, argc, argv,
19677 LARGE_COMMUNITY_LIST_EXPANDED);
19678 }
19679
19680 DEFUN (no_lcommunity_list_standard,
19681 no_bgp_lcommunity_list_standard_cmd,
19682 "no bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
19683 NO_STR
19684 BGP_STR
19685 LCOMMUNITY_LIST_STR
19686 "Large Community list number (standard)\n"
19687 "Sequence number of an entry\n"
19688 "Sequence number\n"
19689 "Specify large community to reject\n"
19690 "Specify large community to accept\n"
19691 LCOMMUNITY_VAL_STR)
19692 {
19693 return lcommunity_list_unset_vty(vty, argc, argv,
19694 LARGE_COMMUNITY_LIST_STANDARD);
19695 }
19696
19697 DEFUN (no_lcommunity_list_expanded,
19698 no_bgp_lcommunity_list_expanded_cmd,
19699 "no bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
19700 NO_STR
19701 BGP_STR
19702 LCOMMUNITY_LIST_STR
19703 "Large Community list number (expanded)\n"
19704 "Sequence number of an entry\n"
19705 "Sequence number\n"
19706 "Specify large community to reject\n"
19707 "Specify large community to accept\n"
19708 "An ordered list as a regular-expression\n")
19709 {
19710 return lcommunity_list_unset_vty(vty, argc, argv,
19711 LARGE_COMMUNITY_LIST_EXPANDED);
19712 }
19713
19714 DEFUN (no_lcommunity_list_name_standard,
19715 no_bgp_lcommunity_list_name_standard_cmd,
19716 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
19717 NO_STR
19718 BGP_STR
19719 LCOMMUNITY_LIST_STR
19720 "Specify standard large-community-list\n"
19721 "Large Community list name\n"
19722 "Sequence number of an entry\n"
19723 "Sequence number\n"
19724 "Specify large community to reject\n"
19725 "Specify large community to accept\n"
19726 LCOMMUNITY_VAL_STR)
19727 {
19728 return lcommunity_list_unset_vty(vty, argc, argv,
19729 LARGE_COMMUNITY_LIST_STANDARD);
19730 }
19731
19732 DEFUN (no_lcommunity_list_name_expanded,
19733 no_bgp_lcommunity_list_name_expanded_cmd,
19734 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
19735 NO_STR
19736 BGP_STR
19737 LCOMMUNITY_LIST_STR
19738 "Specify expanded large-community-list\n"
19739 "Large community list name\n"
19740 "Sequence number of an entry\n"
19741 "Sequence number\n"
19742 "Specify large community to reject\n"
19743 "Specify large community to accept\n"
19744 "An ordered list as a regular-expression\n")
19745 {
19746 return lcommunity_list_unset_vty(vty, argc, argv,
19747 LARGE_COMMUNITY_LIST_EXPANDED);
19748 }
19749
19750 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
19751 {
19752 struct community_entry *entry;
19753
19754 for (entry = list->head; entry; entry = entry->next) {
19755 if (entry == list->head) {
19756 if (all_digit(list->name))
19757 vty_out(vty, "Large community %s list %s\n",
19758 entry->style ==
19759 LARGE_COMMUNITY_LIST_STANDARD
19760 ? "standard"
19761 : "(expanded) access",
19762 list->name);
19763 else
19764 vty_out(vty,
19765 "Named large community %s list %s\n",
19766 entry->style ==
19767 LARGE_COMMUNITY_LIST_STANDARD
19768 ? "standard"
19769 : "expanded",
19770 list->name);
19771 }
19772 if (entry->any)
19773 vty_out(vty, " %s\n",
19774 community_direct_str(entry->direct));
19775 else
19776 vty_out(vty, " %s %s\n",
19777 community_direct_str(entry->direct),
19778 community_list_config_str(entry));
19779 }
19780 }
19781
19782 DEFUN (show_lcommunity_list,
19783 show_bgp_lcommunity_list_cmd,
19784 "show bgp large-community-list",
19785 SHOW_STR
19786 BGP_STR
19787 "List large-community list\n")
19788 {
19789 struct community_list *list;
19790 struct community_list_master *cm;
19791
19792 cm = community_list_master_lookup(bgp_clist,
19793 LARGE_COMMUNITY_LIST_MASTER);
19794 if (!cm)
19795 return CMD_SUCCESS;
19796
19797 for (list = cm->num.head; list; list = list->next)
19798 lcommunity_list_show(vty, list);
19799
19800 for (list = cm->str.head; list; list = list->next)
19801 lcommunity_list_show(vty, list);
19802
19803 return CMD_SUCCESS;
19804 }
19805
19806 DEFUN (show_lcommunity_list_arg,
19807 show_bgp_lcommunity_list_arg_cmd,
19808 "show bgp large-community-list <(1-500)|LCOMMUNITY_LIST_NAME> detail",
19809 SHOW_STR
19810 BGP_STR
19811 "List large-community list\n"
19812 "Large-community-list number\n"
19813 "Large-community-list name\n"
19814 "Detailed information on large-community-list\n")
19815 {
19816 struct community_list *list;
19817
19818 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
19819 LARGE_COMMUNITY_LIST_MASTER);
19820 if (!list) {
19821 vty_out(vty, "%% Can't find large-community-list\n");
19822 return CMD_WARNING;
19823 }
19824
19825 lcommunity_list_show(vty, list);
19826
19827 return CMD_SUCCESS;
19828 }
19829
19830 /* "extcommunity-list" keyword help string. */
19831 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
19832 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
19833
19834 DEFUN (extcommunity_list_standard,
19835 bgp_extcommunity_list_standard_cmd,
19836 "bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
19837 BGP_STR
19838 EXTCOMMUNITY_LIST_STR
19839 "Extended Community list number (standard)\n"
19840 "Specify standard extcommunity-list\n"
19841 "Community list name\n"
19842 "Sequence number of an entry\n"
19843 "Sequence number\n"
19844 "Specify community to reject\n"
19845 "Specify community to accept\n"
19846 EXTCOMMUNITY_VAL_STR)
19847 {
19848 int style = EXTCOMMUNITY_LIST_STANDARD;
19849 int direct = 0;
19850 char *cl_number_or_name = NULL;
19851 char *seq = NULL;
19852
19853 int idx = 0;
19854
19855 argv_find(argv, argc, "(1-99)", &idx);
19856 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
19857 cl_number_or_name = argv[idx]->arg;
19858
19859 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19860 seq = argv[idx]->arg;
19861
19862 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19863 : COMMUNITY_DENY;
19864 argv_find(argv, argc, "AA:NN", &idx);
19865 char *str = argv_concat(argv, argc, idx);
19866
19867 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
19868 direct, style);
19869
19870 XFREE(MTYPE_TMP, str);
19871
19872 if (ret < 0) {
19873 community_list_perror(vty, ret);
19874 return CMD_WARNING_CONFIG_FAILED;
19875 }
19876
19877 return CMD_SUCCESS;
19878 }
19879
19880 DEFUN (extcommunity_list_name_expanded,
19881 bgp_extcommunity_list_name_expanded_cmd,
19882 "bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
19883 BGP_STR
19884 EXTCOMMUNITY_LIST_STR
19885 "Extended Community list number (expanded)\n"
19886 "Specify expanded extcommunity-list\n"
19887 "Extended Community list name\n"
19888 "Sequence number of an entry\n"
19889 "Sequence number\n"
19890 "Specify community to reject\n"
19891 "Specify community to accept\n"
19892 "An ordered list as a regular-expression\n")
19893 {
19894 int style = EXTCOMMUNITY_LIST_EXPANDED;
19895 int direct = 0;
19896 char *cl_number_or_name = NULL;
19897 char *seq = NULL;
19898 int idx = 0;
19899
19900 argv_find(argv, argc, "(100-500)", &idx);
19901 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
19902 cl_number_or_name = argv[idx]->arg;
19903
19904 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19905 seq = argv[idx]->arg;
19906
19907 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19908 : COMMUNITY_DENY;
19909 argv_find(argv, argc, "LINE", &idx);
19910 char *str = argv_concat(argv, argc, idx);
19911
19912 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
19913 direct, style);
19914
19915 XFREE(MTYPE_TMP, str);
19916
19917 if (ret < 0) {
19918 community_list_perror(vty, ret);
19919 return CMD_WARNING_CONFIG_FAILED;
19920 }
19921
19922 return CMD_SUCCESS;
19923 }
19924
19925 DEFUN (no_extcommunity_list_standard_all,
19926 no_bgp_extcommunity_list_standard_all_cmd,
19927 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
19928 NO_STR
19929 BGP_STR
19930 EXTCOMMUNITY_LIST_STR
19931 "Extended Community list number (standard)\n"
19932 "Specify standard extcommunity-list\n"
19933 "Community list name\n"
19934 "Sequence number of an entry\n"
19935 "Sequence number\n"
19936 "Specify community to reject\n"
19937 "Specify community to accept\n"
19938 EXTCOMMUNITY_VAL_STR)
19939 {
19940 int style = EXTCOMMUNITY_LIST_STANDARD;
19941 int direct = 0;
19942 char *cl_number_or_name = NULL;
19943 char *str = NULL;
19944 char *seq = NULL;
19945 int idx = 0;
19946
19947 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19948 seq = argv[idx]->arg;
19949
19950 idx = 0;
19951 argv_find(argv, argc, "permit", &idx);
19952 argv_find(argv, argc, "deny", &idx);
19953 if (idx) {
19954 direct = argv_find(argv, argc, "permit", &idx)
19955 ? COMMUNITY_PERMIT
19956 : COMMUNITY_DENY;
19957
19958 idx = 0;
19959 argv_find(argv, argc, "AA:NN", &idx);
19960 str = argv_concat(argv, argc, idx);
19961 }
19962
19963 idx = 0;
19964 argv_find(argv, argc, "(1-99)", &idx);
19965 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
19966 cl_number_or_name = argv[idx]->arg;
19967
19968 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
19969 seq, direct, style);
19970
19971 XFREE(MTYPE_TMP, str);
19972
19973 if (ret < 0) {
19974 community_list_perror(vty, ret);
19975 return CMD_WARNING_CONFIG_FAILED;
19976 }
19977
19978 return CMD_SUCCESS;
19979 }
19980
19981 ALIAS(no_extcommunity_list_standard_all,
19982 no_bgp_extcommunity_list_standard_all_list_cmd,
19983 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME>",
19984 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
19985 "Extended Community list number (standard)\n"
19986 "Specify standard extcommunity-list\n"
19987 "Community list name\n")
19988
19989 DEFUN (no_extcommunity_list_expanded_all,
19990 no_bgp_extcommunity_list_expanded_all_cmd,
19991 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
19992 NO_STR
19993 BGP_STR
19994 EXTCOMMUNITY_LIST_STR
19995 "Extended Community list number (expanded)\n"
19996 "Specify expanded extcommunity-list\n"
19997 "Extended Community list name\n"
19998 "Sequence number of an entry\n"
19999 "Sequence number\n"
20000 "Specify community to reject\n"
20001 "Specify community to accept\n"
20002 "An ordered list as a regular-expression\n")
20003 {
20004 int style = EXTCOMMUNITY_LIST_EXPANDED;
20005 int direct = 0;
20006 char *cl_number_or_name = NULL;
20007 char *str = NULL;
20008 char *seq = NULL;
20009 int idx = 0;
20010
20011 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20012 seq = argv[idx]->arg;
20013
20014 idx = 0;
20015 argv_find(argv, argc, "permit", &idx);
20016 argv_find(argv, argc, "deny", &idx);
20017
20018 if (idx) {
20019 direct = argv_find(argv, argc, "permit", &idx)
20020 ? COMMUNITY_PERMIT
20021 : COMMUNITY_DENY;
20022
20023 idx = 0;
20024 argv_find(argv, argc, "LINE", &idx);
20025 str = argv_concat(argv, argc, idx);
20026 }
20027
20028 idx = 0;
20029 argv_find(argv, argc, "(100-500)", &idx);
20030 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
20031 cl_number_or_name = argv[idx]->arg;
20032
20033 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
20034 seq, direct, style);
20035
20036 XFREE(MTYPE_TMP, str);
20037
20038 if (ret < 0) {
20039 community_list_perror(vty, ret);
20040 return CMD_WARNING_CONFIG_FAILED;
20041 }
20042
20043 return CMD_SUCCESS;
20044 }
20045
20046 ALIAS(no_extcommunity_list_expanded_all,
20047 no_bgp_extcommunity_list_expanded_all_list_cmd,
20048 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME>",
20049 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
20050 "Extended Community list number (expanded)\n"
20051 "Specify expanded extcommunity-list\n"
20052 "Extended Community list name\n")
20053
20054 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
20055 {
20056 struct community_entry *entry;
20057
20058 for (entry = list->head; entry; entry = entry->next) {
20059 if (entry == list->head) {
20060 if (all_digit(list->name))
20061 vty_out(vty, "Extended community %s list %s\n",
20062 entry->style == EXTCOMMUNITY_LIST_STANDARD
20063 ? "standard"
20064 : "(expanded) access",
20065 list->name);
20066 else
20067 vty_out(vty,
20068 "Named extended community %s list %s\n",
20069 entry->style == EXTCOMMUNITY_LIST_STANDARD
20070 ? "standard"
20071 : "expanded",
20072 list->name);
20073 }
20074 if (entry->any)
20075 vty_out(vty, " %s\n",
20076 community_direct_str(entry->direct));
20077 else
20078 vty_out(vty, " %s %s\n",
20079 community_direct_str(entry->direct),
20080 community_list_config_str(entry));
20081 }
20082 }
20083
20084 DEFUN (show_extcommunity_list,
20085 show_bgp_extcommunity_list_cmd,
20086 "show bgp extcommunity-list",
20087 SHOW_STR
20088 BGP_STR
20089 "List extended-community list\n")
20090 {
20091 struct community_list *list;
20092 struct community_list_master *cm;
20093
20094 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
20095 if (!cm)
20096 return CMD_SUCCESS;
20097
20098 for (list = cm->num.head; list; list = list->next)
20099 extcommunity_list_show(vty, list);
20100
20101 for (list = cm->str.head; list; list = list->next)
20102 extcommunity_list_show(vty, list);
20103
20104 return CMD_SUCCESS;
20105 }
20106
20107 DEFUN (show_extcommunity_list_arg,
20108 show_bgp_extcommunity_list_arg_cmd,
20109 "show bgp extcommunity-list <(1-500)|EXTCOMMUNITY_LIST_NAME> detail",
20110 SHOW_STR
20111 BGP_STR
20112 "List extended-community list\n"
20113 "Extcommunity-list number\n"
20114 "Extcommunity-list name\n"
20115 "Detailed information on extcommunity-list\n")
20116 {
20117 int idx_comm_list = 3;
20118 struct community_list *list;
20119
20120 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
20121 EXTCOMMUNITY_LIST_MASTER);
20122 if (!list) {
20123 vty_out(vty, "%% Can't find extcommunity-list\n");
20124 return CMD_WARNING;
20125 }
20126
20127 extcommunity_list_show(vty, list);
20128
20129 return CMD_SUCCESS;
20130 }
20131
20132 /* Display community-list and extcommunity-list configuration. */
20133 static int community_list_config_write(struct vty *vty)
20134 {
20135 struct community_list *list;
20136 struct community_entry *entry;
20137 struct community_list_master *cm;
20138 int write = 0;
20139
20140 /* Community-list. */
20141 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
20142
20143 for (list = cm->num.head; list; list = list->next)
20144 for (entry = list->head; entry; entry = entry->next) {
20145 vty_out(vty,
20146 "bgp community-list %s seq %" PRId64 " %s %s\n",
20147 list->name, entry->seq,
20148 community_direct_str(entry->direct),
20149 community_list_config_str(entry));
20150 write++;
20151 }
20152 for (list = cm->str.head; list; list = list->next)
20153 for (entry = list->head; entry; entry = entry->next) {
20154 vty_out(vty,
20155 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
20156 entry->style == COMMUNITY_LIST_STANDARD
20157 ? "standard"
20158 : "expanded",
20159 list->name, entry->seq,
20160 community_direct_str(entry->direct),
20161 community_list_config_str(entry));
20162 write++;
20163 }
20164
20165 /* Extcommunity-list. */
20166 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
20167
20168 for (list = cm->num.head; list; list = list->next)
20169 for (entry = list->head; entry; entry = entry->next) {
20170 vty_out(vty,
20171 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
20172 list->name, entry->seq,
20173 community_direct_str(entry->direct),
20174 community_list_config_str(entry));
20175 write++;
20176 }
20177 for (list = cm->str.head; list; list = list->next)
20178 for (entry = list->head; entry; entry = entry->next) {
20179 vty_out(vty,
20180 "bgp extcommunity-list %s %s seq %" PRId64" %s %s\n",
20181 entry->style == EXTCOMMUNITY_LIST_STANDARD
20182 ? "standard"
20183 : "expanded",
20184 list->name, entry->seq,
20185 community_direct_str(entry->direct),
20186 community_list_config_str(entry));
20187 write++;
20188 }
20189
20190
20191 /* lcommunity-list. */
20192 cm = community_list_master_lookup(bgp_clist,
20193 LARGE_COMMUNITY_LIST_MASTER);
20194
20195 for (list = cm->num.head; list; list = list->next)
20196 for (entry = list->head; entry; entry = entry->next) {
20197 vty_out(vty,
20198 "bgp large-community-list %s seq %" PRId64" %s %s\n",
20199 list->name, entry->seq,
20200 community_direct_str(entry->direct),
20201 community_list_config_str(entry));
20202 write++;
20203 }
20204 for (list = cm->str.head; list; list = list->next)
20205 for (entry = list->head; entry; entry = entry->next) {
20206 vty_out(vty,
20207 "bgp large-community-list %s %s seq %" PRId64" %s %s\n",
20208
20209 entry->style == LARGE_COMMUNITY_LIST_STANDARD
20210 ? "standard"
20211 : "expanded",
20212 list->name, entry->seq, community_direct_str(entry->direct),
20213 community_list_config_str(entry));
20214 write++;
20215 }
20216
20217 return write;
20218 }
20219
20220 static int community_list_config_write(struct vty *vty);
20221 static struct cmd_node community_list_node = {
20222 .name = "community list",
20223 .node = COMMUNITY_LIST_NODE,
20224 .prompt = "",
20225 .config_write = community_list_config_write,
20226 };
20227
20228 static void community_list_vty(void)
20229 {
20230 install_node(&community_list_node);
20231
20232 /* Community-list. */
20233 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
20234 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
20235 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
20236 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
20237 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
20238 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
20239 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
20240 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
20241
20242 /* Extcommunity-list. */
20243 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
20244 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
20245 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
20246 install_element(CONFIG_NODE,
20247 &no_bgp_extcommunity_list_standard_all_list_cmd);
20248 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
20249 install_element(CONFIG_NODE,
20250 &no_bgp_extcommunity_list_expanded_all_list_cmd);
20251 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
20252 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
20253
20254 /* Large Community List */
20255 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
20256 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
20257 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
20258 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
20259 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
20260 install_element(CONFIG_NODE,
20261 &no_bgp_lcommunity_list_name_standard_all_cmd);
20262 install_element(CONFIG_NODE,
20263 &no_bgp_lcommunity_list_name_expanded_all_cmd);
20264 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
20265 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
20266 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
20267 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
20268 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
20269 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
20270
20271 bgp_community_list_command_completion_setup();
20272 }
20273
20274 static struct cmd_node community_alias_node = {
20275 .name = "community alias",
20276 .node = COMMUNITY_ALIAS_NODE,
20277 .prompt = "",
20278 .config_write = bgp_community_alias_write,
20279 };
20280
20281 void community_alias_vty(void)
20282 {
20283 install_node(&community_alias_node);
20284
20285 /* Community-list. */
20286 install_element(CONFIG_NODE, &bgp_community_alias_cmd);
20287
20288 bgp_community_alias_command_completion_setup();
20289 }