]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
Merge pull request #8120 from ton31337/feature/bgp_ipv6_default_activated
[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_errors.h"
26 #include "lib/zclient.h"
27 #include "lib/printfrr.h"
28 #include "prefix.h"
29 #include "plist.h"
30 #include "buffer.h"
31 #include "linklist.h"
32 #include "stream.h"
33 #include "thread.h"
34 #include "log.h"
35 #include "memory.h"
36 #include "lib_vty.h"
37 #include "hash.h"
38 #include "queue.h"
39 #include "filter.h"
40 #include "frrstr.h"
41
42 #include "bgpd/bgpd.h"
43 #include "bgpd/bgp_attr_evpn.h"
44 #include "bgpd/bgp_advertise.h"
45 #include "bgpd/bgp_attr.h"
46 #include "bgpd/bgp_aspath.h"
47 #include "bgpd/bgp_community.h"
48 #include "bgpd/bgp_ecommunity.h"
49 #include "bgpd/bgp_lcommunity.h"
50 #include "bgpd/bgp_damp.h"
51 #include "bgpd/bgp_debug.h"
52 #include "bgpd/bgp_errors.h"
53 #include "bgpd/bgp_fsm.h"
54 #include "bgpd/bgp_nexthop.h"
55 #include "bgpd/bgp_open.h"
56 #include "bgpd/bgp_regex.h"
57 #include "bgpd/bgp_route.h"
58 #include "bgpd/bgp_mplsvpn.h"
59 #include "bgpd/bgp_zebra.h"
60 #include "bgpd/bgp_table.h"
61 #include "bgpd/bgp_vty.h"
62 #include "bgpd/bgp_mpath.h"
63 #include "bgpd/bgp_packet.h"
64 #include "bgpd/bgp_updgrp.h"
65 #include "bgpd/bgp_bfd.h"
66 #include "bgpd/bgp_io.h"
67 #include "bgpd/bgp_evpn.h"
68 #include "bgpd/bgp_evpn_vty.h"
69 #include "bgpd/bgp_evpn_mh.h"
70 #include "bgpd/bgp_addpath.h"
71 #include "bgpd/bgp_mac.h"
72 #include "bgpd/bgp_flowspec.h"
73 #ifdef ENABLE_BGP_VNC
74 #include "bgpd/rfapi/bgp_rfapi_cfg.h"
75 #endif
76
77 #include "northbound.h"
78 #include "northbound_cli.h"
79 #include "bgpd/bgp_nb.h"
80
81
82 FRR_CFG_DEFAULT_BOOL(BGP_IMPORT_CHECK,
83 {
84 .val_bool = false,
85 .match_profile = "traditional",
86 .match_version = "< 7.4",
87 },
88 { .val_bool = true },
89 );
90 FRR_CFG_DEFAULT_BOOL(BGP_SHOW_HOSTNAME,
91 { .val_bool = true, .match_profile = "datacenter", },
92 { .val_bool = false },
93 );
94 FRR_CFG_DEFAULT_BOOL(BGP_SHOW_NEXTHOP_HOSTNAME,
95 { .val_bool = true, .match_profile = "datacenter", },
96 { .val_bool = false },
97 );
98 FRR_CFG_DEFAULT_BOOL(BGP_LOG_NEIGHBOR_CHANGES,
99 { .val_bool = true, .match_profile = "datacenter", },
100 { .val_bool = false },
101 );
102 FRR_CFG_DEFAULT_BOOL(BGP_DETERMINISTIC_MED,
103 { .val_bool = true, .match_profile = "datacenter", },
104 { .val_bool = false },
105 );
106 FRR_CFG_DEFAULT_ULONG(BGP_CONNECT_RETRY,
107 { .val_ulong = 10, .match_profile = "datacenter", },
108 { .val_ulong = 120 },
109 );
110 FRR_CFG_DEFAULT_ULONG(BGP_HOLDTIME,
111 { .val_ulong = 9, .match_profile = "datacenter", },
112 { .val_ulong = 180 },
113 );
114 FRR_CFG_DEFAULT_ULONG(BGP_KEEPALIVE,
115 { .val_ulong = 3, .match_profile = "datacenter", },
116 { .val_ulong = 60 },
117 );
118 FRR_CFG_DEFAULT_BOOL(BGP_EBGP_REQUIRES_POLICY,
119 { .val_bool = false, .match_profile = "datacenter", },
120 { .val_bool = false, .match_version = "< 7.4", },
121 { .val_bool = true },
122 );
123 FRR_CFG_DEFAULT_BOOL(BGP_SUPPRESS_DUPLICATES,
124 { .val_bool = false, .match_version = "< 7.6", },
125 { .val_bool = true },
126 );
127
128 DEFINE_HOOK(bgp_inst_config_write,
129 (struct bgp *bgp, struct vty *vty),
130 (bgp, vty));
131 DEFINE_HOOK(bgp_snmp_update_last_changed, (struct bgp *bgp), (bgp));
132
133 #define GR_NO_OPER \
134 "The Graceful Restart No Operation was executed as cmd same as previous one."
135 #define GR_INVALID \
136 "The Graceful Restart command used is not valid at this moment."
137 static struct peer_group *listen_range_exists(struct bgp *bgp,
138 struct prefix *range, int exact);
139
140 /* Show BGP peer's information. */
141 enum show_type {
142 show_all,
143 show_peer,
144 show_ipv4_all,
145 show_ipv6_all,
146 show_ipv4_peer,
147 show_ipv6_peer
148 };
149
150 static struct peer_group *listen_range_exists(struct bgp *bgp,
151 struct prefix *range, int exact);
152
153 static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
154 struct bgp *bgp,
155 bool use_json,
156 json_object *json);
157
158 static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
159 enum show_type type,
160 const char *ip_str,
161 afi_t afi, bool use_json);
162
163 static int peer_and_group_lookup_nb(struct vty *vty, const char *peer_str,
164 char *base_xpath, int xpath_len,
165 char *abs_xpath);
166
167 static enum node_type bgp_node_type(afi_t afi, safi_t safi)
168 {
169 switch (afi) {
170 case AFI_IP:
171 switch (safi) {
172 case SAFI_UNICAST:
173 return BGP_IPV4_NODE;
174 case SAFI_MULTICAST:
175 return BGP_IPV4M_NODE;
176 case SAFI_LABELED_UNICAST:
177 return BGP_IPV4L_NODE;
178 case SAFI_MPLS_VPN:
179 return BGP_VPNV4_NODE;
180 case SAFI_FLOWSPEC:
181 return BGP_FLOWSPECV4_NODE;
182 default:
183 /* not expected */
184 return BGP_IPV4_NODE;
185 }
186 break;
187 case AFI_IP6:
188 switch (safi) {
189 case SAFI_UNICAST:
190 return BGP_IPV6_NODE;
191 case SAFI_MULTICAST:
192 return BGP_IPV6M_NODE;
193 case SAFI_LABELED_UNICAST:
194 return BGP_IPV6L_NODE;
195 case SAFI_MPLS_VPN:
196 return BGP_VPNV6_NODE;
197 case SAFI_FLOWSPEC:
198 return BGP_FLOWSPECV6_NODE;
199 default:
200 /* not expected */
201 return BGP_IPV4_NODE;
202 }
203 break;
204 case AFI_L2VPN:
205 return BGP_EVPN_NODE;
206 case AFI_UNSPEC:
207 case AFI_MAX:
208 // We should never be here but to clarify the switch statement..
209 return BGP_IPV4_NODE;
210 }
211
212 // Impossible to happen
213 return BGP_IPV4_NODE;
214 }
215
216 static const char *get_afi_safi_vty_str(afi_t afi, safi_t safi)
217 {
218 if (afi == AFI_IP) {
219 if (safi == SAFI_UNICAST)
220 return "IPv4 Unicast";
221 if (safi == SAFI_MULTICAST)
222 return "IPv4 Multicast";
223 if (safi == SAFI_LABELED_UNICAST)
224 return "IPv4 Labeled Unicast";
225 if (safi == SAFI_MPLS_VPN)
226 return "IPv4 VPN";
227 if (safi == SAFI_ENCAP)
228 return "IPv4 Encap";
229 if (safi == SAFI_FLOWSPEC)
230 return "IPv4 Flowspec";
231 } else if (afi == AFI_IP6) {
232 if (safi == SAFI_UNICAST)
233 return "IPv6 Unicast";
234 if (safi == SAFI_MULTICAST)
235 return "IPv6 Multicast";
236 if (safi == SAFI_LABELED_UNICAST)
237 return "IPv6 Labeled Unicast";
238 if (safi == SAFI_MPLS_VPN)
239 return "IPv6 VPN";
240 if (safi == SAFI_ENCAP)
241 return "IPv6 Encap";
242 if (safi == SAFI_FLOWSPEC)
243 return "IPv6 Flowspec";
244 } else if (afi == AFI_L2VPN) {
245 if (safi == SAFI_EVPN)
246 return "L2VPN EVPN";
247 }
248
249 return "Unknown";
250 }
251
252 /*
253 * Please note that we have intentionally camelCased
254 * the return strings here. So if you want
255 * to use this function, please ensure you
256 * are doing this within json output
257 */
258 static const char *get_afi_safi_json_str(afi_t afi, safi_t safi)
259 {
260 if (afi == AFI_IP) {
261 if (safi == SAFI_UNICAST)
262 return "ipv4Unicast";
263 if (safi == SAFI_MULTICAST)
264 return "ipv4Multicast";
265 if (safi == SAFI_LABELED_UNICAST)
266 return "ipv4LabeledUnicast";
267 if (safi == SAFI_MPLS_VPN)
268 return "ipv4Vpn";
269 if (safi == SAFI_ENCAP)
270 return "ipv4Encap";
271 if (safi == SAFI_FLOWSPEC)
272 return "ipv4Flowspec";
273 } else if (afi == AFI_IP6) {
274 if (safi == SAFI_UNICAST)
275 return "ipv6Unicast";
276 if (safi == SAFI_MULTICAST)
277 return "ipv6Multicast";
278 if (safi == SAFI_LABELED_UNICAST)
279 return "ipv6LabeledUnicast";
280 if (safi == SAFI_MPLS_VPN)
281 return "ipv6Vpn";
282 if (safi == SAFI_ENCAP)
283 return "ipv6Encap";
284 if (safi == SAFI_FLOWSPEC)
285 return "ipv6Flowspec";
286 } else if (afi == AFI_L2VPN) {
287 if (safi == SAFI_EVPN)
288 return "l2VpnEvpn";
289 }
290
291 return "Unknown";
292 }
293
294 /* return string maps to afi-safi specific container names
295 * defined in bgp yang file.
296 */
297 const char *bgp_afi_safi_get_container_str(afi_t afi, safi_t safi)
298 {
299 if (afi == AFI_IP) {
300 if (safi == SAFI_UNICAST)
301 return "ipv4-unicast";
302 if (safi == SAFI_MULTICAST)
303 return "ipv4-multicast";
304 if (safi == SAFI_LABELED_UNICAST)
305 return "ipv4-labeled-unicast";
306 if (safi == SAFI_MPLS_VPN)
307 return "l3vpn-ipv4-unicast";
308 if (safi == SAFI_FLOWSPEC)
309 return "ipv4-flowspec";
310 } else if (afi == AFI_IP6) {
311 if (safi == SAFI_UNICAST)
312 return "ipv6-unicast";
313 if (safi == SAFI_MULTICAST)
314 return "ipv6-multicast";
315 if (safi == SAFI_LABELED_UNICAST)
316 return "ipv6-labeled-unicast";
317 if (safi == SAFI_MPLS_VPN)
318 return "l3vpn-ipv6-unicast";
319 if (safi == SAFI_FLOWSPEC)
320 return "ipv6-flowspec";
321 } else if (afi == AFI_L2VPN) {
322 if (safi == SAFI_EVPN)
323 return "l2vpn-evpn";
324 }
325
326 return "Unknown";
327 }
328
329 /* Utility function to get address family from current node. */
330 afi_t bgp_node_afi(struct vty *vty)
331 {
332 afi_t afi;
333 switch (vty->node) {
334 case BGP_IPV6_NODE:
335 case BGP_IPV6M_NODE:
336 case BGP_IPV6L_NODE:
337 case BGP_VPNV6_NODE:
338 case BGP_FLOWSPECV6_NODE:
339 afi = AFI_IP6;
340 break;
341 case BGP_EVPN_NODE:
342 afi = AFI_L2VPN;
343 break;
344 default:
345 afi = AFI_IP;
346 break;
347 }
348 return afi;
349 }
350
351 /* Utility function to get subsequent address family from current
352 node. */
353 safi_t bgp_node_safi(struct vty *vty)
354 {
355 safi_t safi;
356 switch (vty->node) {
357 case BGP_VPNV4_NODE:
358 case BGP_VPNV6_NODE:
359 safi = SAFI_MPLS_VPN;
360 break;
361 case BGP_IPV4M_NODE:
362 case BGP_IPV6M_NODE:
363 safi = SAFI_MULTICAST;
364 break;
365 case BGP_EVPN_NODE:
366 safi = SAFI_EVPN;
367 break;
368 case BGP_IPV4L_NODE:
369 case BGP_IPV6L_NODE:
370 safi = SAFI_LABELED_UNICAST;
371 break;
372 case BGP_FLOWSPECV4_NODE:
373 case BGP_FLOWSPECV6_NODE:
374 safi = SAFI_FLOWSPEC;
375 break;
376 default:
377 safi = SAFI_UNICAST;
378 break;
379 }
380 return safi;
381 }
382
383 /**
384 * Converts an AFI in string form to afi_t
385 *
386 * @param afi string, one of
387 * - "ipv4"
388 * - "ipv6"
389 * - "l2vpn"
390 * @return the corresponding afi_t
391 */
392 afi_t bgp_vty_afi_from_str(const char *afi_str)
393 {
394 afi_t afi = AFI_MAX; /* unknown */
395 if (strmatch(afi_str, "ipv4"))
396 afi = AFI_IP;
397 else if (strmatch(afi_str, "ipv6"))
398 afi = AFI_IP6;
399 else if (strmatch(afi_str, "l2vpn"))
400 afi = AFI_L2VPN;
401 return afi;
402 }
403
404 int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
405 afi_t *afi)
406 {
407 int ret = 0;
408 if (argv_find(argv, argc, "ipv4", index)) {
409 ret = 1;
410 if (afi)
411 *afi = AFI_IP;
412 } else if (argv_find(argv, argc, "ipv6", index)) {
413 ret = 1;
414 if (afi)
415 *afi = AFI_IP6;
416 } else if (argv_find(argv, argc, "l2vpn", index)) {
417 ret = 1;
418 if (afi)
419 *afi = AFI_L2VPN;
420 }
421 return ret;
422 }
423
424 /* supports <unicast|multicast|vpn|labeled-unicast> */
425 safi_t bgp_vty_safi_from_str(const char *safi_str)
426 {
427 safi_t safi = SAFI_MAX; /* unknown */
428 if (strmatch(safi_str, "multicast"))
429 safi = SAFI_MULTICAST;
430 else if (strmatch(safi_str, "unicast"))
431 safi = SAFI_UNICAST;
432 else if (strmatch(safi_str, "vpn"))
433 safi = SAFI_MPLS_VPN;
434 else if (strmatch(safi_str, "evpn"))
435 safi = SAFI_EVPN;
436 else if (strmatch(safi_str, "labeled-unicast"))
437 safi = SAFI_LABELED_UNICAST;
438 else if (strmatch(safi_str, "flowspec"))
439 safi = SAFI_FLOWSPEC;
440 return safi;
441 }
442
443 int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
444 safi_t *safi)
445 {
446 int ret = 0;
447 if (argv_find(argv, argc, "unicast", index)) {
448 ret = 1;
449 if (safi)
450 *safi = SAFI_UNICAST;
451 } else if (argv_find(argv, argc, "multicast", index)) {
452 ret = 1;
453 if (safi)
454 *safi = SAFI_MULTICAST;
455 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
456 ret = 1;
457 if (safi)
458 *safi = SAFI_LABELED_UNICAST;
459 } else if (argv_find(argv, argc, "vpn", index)) {
460 ret = 1;
461 if (safi)
462 *safi = SAFI_MPLS_VPN;
463 } else if (argv_find(argv, argc, "evpn", index)) {
464 ret = 1;
465 if (safi)
466 *safi = SAFI_EVPN;
467 } else if (argv_find(argv, argc, "flowspec", index)) {
468 ret = 1;
469 if (safi)
470 *safi = SAFI_FLOWSPEC;
471 }
472 return ret;
473 }
474
475 int bgp_get_vty(struct bgp **bgp, as_t *as, const char *name,
476 enum bgp_instance_type inst_type)
477 {
478 int ret = bgp_get(bgp, as, name, inst_type);
479
480 if (ret == BGP_CREATED) {
481 bgp_timers_set(*bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
482 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
483
484 if (DFLT_BGP_IMPORT_CHECK)
485 SET_FLAG((*bgp)->flags, BGP_FLAG_IMPORT_CHECK);
486 if (DFLT_BGP_SHOW_HOSTNAME)
487 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_HOSTNAME);
488 if (DFLT_BGP_SHOW_NEXTHOP_HOSTNAME)
489 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
490 if (DFLT_BGP_LOG_NEIGHBOR_CHANGES)
491 SET_FLAG((*bgp)->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
492 if (DFLT_BGP_DETERMINISTIC_MED)
493 SET_FLAG((*bgp)->flags, BGP_FLAG_DETERMINISTIC_MED);
494 if (DFLT_BGP_EBGP_REQUIRES_POLICY)
495 SET_FLAG((*bgp)->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
496 if (DFLT_BGP_SUPPRESS_DUPLICATES)
497 SET_FLAG((*bgp)->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
498
499 ret = BGP_SUCCESS;
500 }
501 return ret;
502 }
503
504 /*
505 * bgp_vty_find_and_parse_afi_safi_bgp
506 *
507 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
508 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
509 * to appropriate values for the calling function. This is to allow the
510 * calling function to make decisions appropriate for the show command
511 * that is being parsed.
512 *
513 * The show commands are generally of the form:
514 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
515 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
516 *
517 * Since we use argv_find if the show command in particular doesn't have:
518 * [ip]
519 * [<view|vrf> VIEWVRFNAME]
520 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
521 * The command parsing should still be ok.
522 *
523 * vty -> The vty for the command so we can output some useful data in
524 * the event of a parse error in the vrf.
525 * argv -> The command tokens
526 * argc -> How many command tokens we have
527 * idx -> The current place in the command, generally should be 0 for this
528 * function
529 * afi -> The parsed afi if it was included in the show command, returned here
530 * safi -> The parsed safi if it was included in the show command, returned here
531 * bgp -> Pointer to the bgp data structure we need to fill in.
532 * use_json -> json is configured or not
533 *
534 * The function returns the correct location in the parse tree for the
535 * last token found.
536 *
537 * Returns 0 for failure to parse correctly, else the idx position of where
538 * it found the last token.
539 */
540 int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
541 struct cmd_token **argv, int argc,
542 int *idx, afi_t *afi, safi_t *safi,
543 struct bgp **bgp, bool use_json)
544 {
545 char *vrf_name = NULL;
546
547 assert(afi);
548 assert(safi);
549 assert(bgp);
550
551 if (argv_find(argv, argc, "ip", idx))
552 *afi = AFI_IP;
553
554 if (argv_find(argv, argc, "view", idx))
555 vrf_name = argv[*idx + 1]->arg;
556 else if (argv_find(argv, argc, "vrf", idx)) {
557 vrf_name = argv[*idx + 1]->arg;
558 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
559 vrf_name = NULL;
560 }
561 if (vrf_name) {
562 if (strmatch(vrf_name, "all"))
563 *bgp = NULL;
564 else {
565 *bgp = bgp_lookup_by_name(vrf_name);
566 if (!*bgp) {
567 if (use_json) {
568 json_object *json = NULL;
569 json = json_object_new_object();
570 json_object_string_add(
571 json, "warning",
572 "View/Vrf is unknown");
573 vty_out(vty, "%s\n",
574 json_object_to_json_string_ext(json,
575 JSON_C_TO_STRING_PRETTY));
576 json_object_free(json);
577 }
578 else
579 vty_out(vty, "View/Vrf %s is unknown\n",
580 vrf_name);
581 *idx = 0;
582 return 0;
583 }
584 }
585 } else {
586 *bgp = bgp_get_default();
587 if (!*bgp) {
588 if (use_json) {
589 json_object *json = NULL;
590 json = json_object_new_object();
591 json_object_string_add(
592 json, "warning",
593 "Default BGP instance not found");
594 vty_out(vty, "%s\n",
595 json_object_to_json_string_ext(json,
596 JSON_C_TO_STRING_PRETTY));
597 json_object_free(json);
598 }
599 else
600 vty_out(vty,
601 "Default BGP instance not found\n");
602 *idx = 0;
603 return 0;
604 }
605 }
606
607 if (argv_find_and_parse_afi(argv, argc, idx, afi))
608 argv_find_and_parse_safi(argv, argc, idx, safi);
609
610 *idx += 1;
611 return *idx;
612 }
613
614 bool peer_address_self_check(struct bgp *bgp, union sockunion *su)
615 {
616 struct interface *ifp = NULL;
617
618 if (su->sa.sa_family == AF_INET)
619 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
620 else if (su->sa.sa_family == AF_INET6)
621 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
622 su->sin6.sin6_scope_id,
623 bgp->vrf_id);
624
625 if (ifp)
626 return true;
627
628 return false;
629 }
630
631 /* Utility function for looking up peer or peer group. */
632 /* This is used only for configuration, so disallow if attempted on
633 * a dynamic neighbor.
634 */
635 struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
636 {
637 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
638 int ret;
639 union sockunion su;
640 struct peer *peer = NULL;
641 struct peer_group *group = NULL;
642
643 if (!bgp) {
644 return NULL;
645 }
646
647 ret = str2sockunion(peer_str, &su);
648 if (ret == 0) {
649 /* IP address, locate peer. */
650 peer = peer_lookup(bgp, &su);
651 } else {
652 /* Not IP, could match either peer configured on interface or a
653 * group. */
654 peer = peer_lookup_by_conf_if(bgp, peer_str);
655 if (!peer)
656 group = peer_group_lookup(bgp, peer_str);
657 }
658
659 if (peer) {
660 if (peer_dynamic_neighbor(peer)) {
661 vty_out(vty,
662 "%% Operation not allowed on a dynamic neighbor\n");
663 return NULL;
664 }
665
666 return peer;
667 }
668
669 if (group)
670 return group->conf;
671
672 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
673
674 return NULL;
675 }
676
677 int bgp_nb_errmsg_return(char *errmsg, size_t errmsg_len, int ret)
678 {
679 const char *str = NULL;
680
681 switch (ret) {
682 case BGP_ERR_INVALID_VALUE:
683 str = "Invalid value";
684 break;
685 case BGP_ERR_INVALID_FLAG:
686 str = "Invalid flag";
687 break;
688 case BGP_ERR_PEER_GROUP_SHUTDOWN:
689 str = "Peer-group has been shutdown. Activate the peer-group first";
690 break;
691 case BGP_ERR_PEER_FLAG_CONFLICT:
692 str = "Can't set override-capability and strict-capability-match at the same time";
693 break;
694 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
695 str = "Specify remote-as or peer-group remote AS first";
696 break;
697 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
698 str = "Cannot change the peer-group. Deconfigure first";
699 break;
700 case BGP_ERR_PEER_GROUP_MISMATCH:
701 str = "Peer is not a member of this peer-group";
702 break;
703 case BGP_ERR_PEER_FILTER_CONFLICT:
704 str = "Prefix/distribute list can not co-exist";
705 break;
706 case BGP_ERR_NOT_INTERNAL_PEER:
707 str = "Invalid command. Not an internal neighbor";
708 break;
709 case BGP_ERR_REMOVE_PRIVATE_AS:
710 str = "remove-private-AS cannot be configured for IBGP peers";
711 break;
712 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
713 str = "Local-AS allowed only for EBGP peers";
714 break;
715 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
716 str = "Cannot have local-as same as BGP AS number";
717 break;
718 case BGP_ERR_TCPSIG_FAILED:
719 str = "Error while applying TCP-Sig to session(s)";
720 break;
721 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
722 str = "ebgp-multihop and ttl-security cannot be configured together";
723 break;
724 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
725 str = "ttl-security only allowed for EBGP peers";
726 break;
727 case BGP_ERR_AS_OVERRIDE:
728 str = "as-override cannot be configured for IBGP peers";
729 break;
730 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
731 str = "Invalid limit for number of dynamic neighbors";
732 break;
733 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
734 str = "Dynamic neighbor listen range already exists";
735 break;
736 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
737 str = "Operation not allowed on a dynamic neighbor";
738 break;
739 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
740 str = "Operation not allowed on a directly connected neighbor";
741 break;
742 case BGP_ERR_PEER_SAFI_CONFLICT:
743 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
744 break;
745 case BGP_ERR_GR_INVALID_CMD:
746 str = "The Graceful Restart command used is not valid at this moment.";
747 break;
748 case BGP_ERR_GR_OPERATION_FAILED:
749 str = "The Graceful Restart Operation failed due to an err.";
750 break;
751 case BGP_GR_NO_OPERATION:
752 str = GR_NO_OPER;
753 break;
754 case BGP_ERR_PEER_GROUP_MEMBER:
755 str = "Peer-group member cannot override remote-as of peer-group";
756 break;
757 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
758 str = "Peer-group members must be all internal or all external";
759 break;
760 }
761 if (str) {
762 snprintf(errmsg, errmsg_len, "%s", str);
763 return -1;
764 }
765
766 return 0;
767 }
768
769 int bgp_vty_return(struct vty *vty, int ret)
770 {
771 const char *str = NULL;
772
773 switch (ret) {
774 case BGP_ERR_INVALID_VALUE:
775 str = "Invalid value";
776 break;
777 case BGP_ERR_INVALID_FLAG:
778 str = "Invalid flag";
779 break;
780 case BGP_ERR_PEER_GROUP_SHUTDOWN:
781 str = "Peer-group has been shutdown. Activate the peer-group first";
782 break;
783 case BGP_ERR_PEER_FLAG_CONFLICT:
784 str = "Can't set override-capability and strict-capability-match at the same time";
785 break;
786 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
787 str = "Specify remote-as or peer-group remote AS first";
788 break;
789 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
790 str = "Cannot change the peer-group. Deconfigure first";
791 break;
792 case BGP_ERR_PEER_GROUP_MISMATCH:
793 str = "Peer is not a member of this peer-group";
794 break;
795 case BGP_ERR_PEER_FILTER_CONFLICT:
796 str = "Prefix/distribute list can not co-exist";
797 break;
798 case BGP_ERR_NOT_INTERNAL_PEER:
799 str = "Invalid command. Not an internal neighbor";
800 break;
801 case BGP_ERR_REMOVE_PRIVATE_AS:
802 str = "remove-private-AS cannot be configured for IBGP peers";
803 break;
804 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
805 str = "Local-AS allowed only for EBGP peers";
806 break;
807 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
808 str = "Cannot have local-as same as BGP AS number";
809 break;
810 case BGP_ERR_TCPSIG_FAILED:
811 str = "Error while applying TCP-Sig to session(s)";
812 break;
813 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
814 str = "ebgp-multihop and ttl-security cannot be configured together";
815 break;
816 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
817 str = "ttl-security only allowed for EBGP peers";
818 break;
819 case BGP_ERR_AS_OVERRIDE:
820 str = "as-override cannot be configured for IBGP peers";
821 break;
822 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
823 str = "Invalid limit for number of dynamic neighbors";
824 break;
825 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
826 str = "Dynamic neighbor listen range already exists";
827 break;
828 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
829 str = "Operation not allowed on a dynamic neighbor";
830 break;
831 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
832 str = "Operation not allowed on a directly connected neighbor";
833 break;
834 case BGP_ERR_PEER_SAFI_CONFLICT:
835 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
836 break;
837 case BGP_ERR_GR_INVALID_CMD:
838 str = "The Graceful Restart command used is not valid at this moment.";
839 break;
840 case BGP_ERR_GR_OPERATION_FAILED:
841 str = "The Graceful Restart Operation failed due to an err.";
842 break;
843 case BGP_GR_NO_OPERATION:
844 str = GR_NO_OPER;
845 break;
846 }
847 if (str) {
848 vty_out(vty, "%% %s\n", str);
849 return CMD_WARNING_CONFIG_FAILED;
850 }
851 return CMD_SUCCESS;
852 }
853
854 /* BGP clear sort. */
855 enum clear_sort {
856 clear_all,
857 clear_peer,
858 clear_group,
859 clear_external,
860 clear_as
861 };
862
863 static void bgp_clear_vty_error(struct peer *peer, afi_t afi, safi_t safi,
864 int error, char *errmsg, size_t errmsg_len)
865 {
866 switch (error) {
867 case BGP_ERR_AF_UNCONFIGURED:
868 snprintf(errmsg, errmsg_len,
869 "%%BGP: Enable %s address family for the neighbor %s",
870 get_afi_safi_str(afi, safi, false), peer->host);
871 break;
872 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
873 snprintf(
874 errmsg, errmsg_len,
875 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig",
876 peer->host);
877 break;
878 default:
879 break;
880 }
881 }
882
883 static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi,
884 struct listnode **nnode, enum bgp_clear_type stype)
885 {
886 int ret = 0;
887 struct peer_af *paf;
888
889 /* if afi/.safi not specified, spin thru all of them */
890 if ((afi == AFI_UNSPEC) && (safi == SAFI_UNSPEC)) {
891 afi_t tmp_afi;
892 safi_t tmp_safi;
893
894 FOREACH_AFI_SAFI (tmp_afi, tmp_safi) {
895 paf = peer_af_find(peer, tmp_afi, tmp_safi);
896 if (paf && paf->subgroup)
897 SET_FLAG(paf->subgroup->sflags,
898 SUBGRP_STATUS_FORCE_UPDATES);
899
900 if (!peer->afc[tmp_afi][tmp_safi])
901 continue;
902
903 if (stype == BGP_CLEAR_SOFT_NONE)
904 ret = peer_clear(peer, nnode);
905 else
906 ret = peer_clear_soft(peer, tmp_afi, tmp_safi,
907 stype);
908 }
909 /* if afi specified and safi not, spin thru safis on this afi */
910 } else if (safi == SAFI_UNSPEC) {
911 safi_t tmp_safi;
912
913 for (tmp_safi = SAFI_UNICAST;
914 tmp_safi < SAFI_MAX; tmp_safi++) {
915 if (!peer->afc[afi][tmp_safi])
916 continue;
917
918 paf = peer_af_find(peer, afi, tmp_safi);
919 if (paf && paf->subgroup)
920 SET_FLAG(paf->subgroup->sflags,
921 SUBGRP_STATUS_FORCE_UPDATES);
922
923 if (stype == BGP_CLEAR_SOFT_NONE)
924 ret = peer_clear(peer, nnode);
925 else
926 ret = peer_clear_soft(peer, afi,
927 tmp_safi, stype);
928 }
929 /* both afi/safi specified, let the caller know if not defined */
930 } else {
931 if (!peer->afc[afi][safi])
932 return 1;
933
934 paf = peer_af_find(peer, afi, safi);
935 if (paf && paf->subgroup)
936 SET_FLAG(paf->subgroup->sflags,
937 SUBGRP_STATUS_FORCE_UPDATES);
938
939 if (stype == BGP_CLEAR_SOFT_NONE)
940 ret = peer_clear(peer, nnode);
941 else
942 ret = peer_clear_soft(peer, afi, safi, stype);
943 }
944
945 return ret;
946 }
947
948 /* `clear ip bgp' functions. */
949 static int bgp_clear(struct bgp *bgp, afi_t afi, safi_t safi,
950 enum clear_sort sort, enum bgp_clear_type stype,
951 const char *arg, char *errmsg, size_t errmsg_len)
952 {
953 int ret = 0;
954 bool found = false;
955 struct peer *peer;
956
957 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
958
959 /* Clear all neighbors. */
960 /*
961 * Pass along pointer to next node to peer_clear() when walking all
962 * nodes on the BGP instance as that may get freed if it is a
963 * doppelganger
964 */
965 if (sort == clear_all) {
966 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
967
968 bgp_peer_gr_flags_update(peer);
969
970 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
971 gr_router_detected = true;
972
973 ret = bgp_peer_clear(peer, afi, safi, &nnode,
974 stype);
975
976 if (ret < 0)
977 bgp_clear_vty_error(peer, afi, safi, ret,
978 errmsg, errmsg_len);
979 }
980
981 if (gr_router_detected
982 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
983 bgp_zebra_send_capabilities(bgp, false);
984 } else if (!gr_router_detected
985 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
986 bgp_zebra_send_capabilities(bgp, true);
987 }
988
989 /* This is to apply read-only mode on this clear. */
990 if (stype == BGP_CLEAR_SOFT_NONE)
991 bgp->update_delay_over = 0;
992
993 return CMD_SUCCESS;
994 }
995
996 /* Clear specified neighbor. */
997 if (sort == clear_peer) {
998 union sockunion su;
999
1000 /* Make sockunion for lookup. */
1001 ret = str2sockunion(arg, &su);
1002 if (ret < 0) {
1003 peer = peer_lookup_by_conf_if(bgp, arg);
1004 if (!peer) {
1005 peer = peer_lookup_by_hostname(bgp, arg);
1006 if (!peer) {
1007 snprintf(
1008 errmsg, errmsg_len,
1009 "Malformed address or name: %s",
1010 arg);
1011 return CMD_WARNING;
1012 }
1013 }
1014 } else {
1015 peer = peer_lookup(bgp, &su);
1016 if (!peer) {
1017 snprintf(errmsg, errmsg_len,
1018 "%%BGP: Unknown neighbor - \"%s\"",
1019 arg);
1020 return CMD_WARNING;
1021 }
1022 }
1023
1024 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
1025 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
1026
1027 ret = bgp_peer_clear(peer, afi, safi, NULL, stype);
1028
1029 /* if afi/safi not defined for this peer, let caller know */
1030 if (ret == 1)
1031 ret = BGP_ERR_AF_UNCONFIGURED;
1032
1033 if (ret < 0)
1034 bgp_clear_vty_error(peer, afi, safi, ret, errmsg,
1035 errmsg_len);
1036
1037 return CMD_SUCCESS;
1038 }
1039
1040 /* Clear all neighbors belonging to a specific peer-group. */
1041 if (sort == clear_group) {
1042 struct peer_group *group;
1043
1044 group = peer_group_lookup(bgp, arg);
1045 if (!group) {
1046 snprintf(errmsg, errmsg_len,
1047 "%%BGP: No such peer-group %s", arg);
1048 return CMD_WARNING;
1049 }
1050
1051 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
1052 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1053
1054 if (ret < 0)
1055 bgp_clear_vty_error(peer, afi, safi, ret,
1056 errmsg, errmsg_len);
1057 else
1058 found = true;
1059 }
1060
1061 if (!found)
1062 snprintf(
1063 errmsg, errmsg_len,
1064 "%%BGP: No %s peer belonging to peer-group %s is configured",
1065 get_afi_safi_str(afi, safi, false), arg);
1066
1067 return CMD_SUCCESS;
1068 }
1069
1070 /* Clear all external (eBGP) neighbors. */
1071 if (sort == clear_external) {
1072 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1073 if (peer->sort == BGP_PEER_IBGP)
1074 continue;
1075
1076 bgp_peer_gr_flags_update(peer);
1077
1078 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1079 gr_router_detected = true;
1080
1081 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1082
1083 if (ret < 0)
1084 bgp_clear_vty_error(peer, afi, safi, ret,
1085 errmsg, errmsg_len);
1086 else
1087 found = true;
1088 }
1089
1090 if (gr_router_detected
1091 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1092 bgp_zebra_send_capabilities(bgp, false);
1093 } else if (!gr_router_detected
1094 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1095 bgp_zebra_send_capabilities(bgp, true);
1096 }
1097
1098 if (!found)
1099 snprintf(errmsg, errmsg_len,
1100 "%%BGP: No external %s peer is configured",
1101 get_afi_safi_str(afi, safi, false));
1102
1103 return CMD_SUCCESS;
1104 }
1105
1106 /* Clear all neighbors belonging to a specific AS. */
1107 if (sort == clear_as) {
1108 as_t as = strtoul(arg, NULL, 10);
1109
1110 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1111 if (peer->as != as)
1112 continue;
1113
1114 bgp_peer_gr_flags_update(peer);
1115
1116 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1117 gr_router_detected = true;
1118
1119 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1120
1121 if (ret < 0)
1122 bgp_clear_vty_error(peer, afi, safi, ret,
1123 errmsg, errmsg_len);
1124 else
1125 found = true;
1126 }
1127
1128 if (gr_router_detected
1129 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1130 bgp_zebra_send_capabilities(bgp, false);
1131 } else if (!gr_router_detected
1132 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1133 bgp_zebra_send_capabilities(bgp, true);
1134 }
1135
1136 if (!found)
1137 snprintf(errmsg, errmsg_len,
1138 "%%BGP: No %s peer is configured with AS %s",
1139 get_afi_safi_str(afi, safi, false), arg);
1140
1141 return CMD_SUCCESS;
1142 }
1143
1144 return CMD_SUCCESS;
1145 }
1146
1147 static int bgp_clear_vty(const char *name, afi_t afi, safi_t safi,
1148 enum clear_sort sort, enum bgp_clear_type stype,
1149 const char *arg, char *errmsg, size_t errmsg_len)
1150 {
1151 struct bgp *bgp;
1152
1153 /* BGP structure lookup. */
1154 if (name) {
1155 bgp = bgp_lookup_by_name(name);
1156 if (bgp == NULL) {
1157 snprintf(errmsg, errmsg_len,
1158 "Can't find BGP instance %s", name);
1159 return CMD_WARNING;
1160 }
1161 } else {
1162 bgp = bgp_get_default();
1163 if (bgp == NULL) {
1164 snprintf(errmsg, errmsg_len,
1165 "No BGP process is configured");
1166 return CMD_WARNING;
1167 }
1168 }
1169
1170 return bgp_clear(bgp, afi, safi, sort, stype, arg, errmsg, errmsg_len);
1171 }
1172
1173 /* clear soft inbound */
1174 int bgp_clear_star_soft_in(const char *name, char *errmsg, size_t errmsg_len)
1175 {
1176 afi_t afi;
1177 safi_t safi;
1178 int ret;
1179
1180 FOREACH_AFI_SAFI (afi, safi) {
1181 ret = bgp_clear_vty(name, afi, safi, clear_all,
1182 BGP_CLEAR_SOFT_IN, NULL, errmsg,
1183 errmsg_len);
1184 if (ret != CMD_SUCCESS)
1185 return -1;
1186 }
1187
1188 return 0;
1189 }
1190
1191 /* clear soft outbound */
1192 int bgp_clear_star_soft_out(const char *name, char *errmsg, size_t errmsg_len)
1193 {
1194 afi_t afi;
1195 safi_t safi;
1196 int ret;
1197
1198 FOREACH_AFI_SAFI (afi, safi) {
1199 ret = bgp_clear_vty(name, afi, safi, clear_all,
1200 BGP_CLEAR_SOFT_OUT, NULL, errmsg,
1201 errmsg_len);
1202 if (ret != CMD_SUCCESS)
1203 return -1;
1204 }
1205
1206 return 0;
1207 }
1208
1209
1210 #ifndef VTYSH_EXTRACT_PL
1211 #include "bgpd/bgp_vty_clippy.c"
1212 #endif
1213
1214 DEFUN_HIDDEN (bgp_local_mac,
1215 bgp_local_mac_cmd,
1216 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
1217 BGP_STR
1218 "Local MAC config\n"
1219 "VxLAN Network Identifier\n"
1220 "VNI number\n"
1221 "local mac\n"
1222 "mac address\n"
1223 "mac-mobility sequence\n"
1224 "seq number\n")
1225 {
1226 int rv;
1227 vni_t vni;
1228 struct ethaddr mac;
1229 struct ipaddr ip;
1230 uint32_t seq;
1231 struct bgp *bgp;
1232
1233 vni = strtoul(argv[3]->arg, NULL, 10);
1234 if (!prefix_str2mac(argv[5]->arg, &mac)) {
1235 vty_out(vty, "%% Malformed MAC address\n");
1236 return CMD_WARNING;
1237 }
1238 memset(&ip, 0, sizeof(ip));
1239 seq = strtoul(argv[7]->arg, NULL, 10);
1240
1241 bgp = bgp_get_default();
1242 if (!bgp) {
1243 vty_out(vty, "Default BGP instance is not there\n");
1244 return CMD_WARNING;
1245 }
1246
1247 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq,
1248 zero_esi);
1249 if (rv < 0) {
1250 vty_out(vty, "Internal error\n");
1251 return CMD_WARNING;
1252 }
1253
1254 return CMD_SUCCESS;
1255 }
1256
1257 DEFUN_HIDDEN (no_bgp_local_mac,
1258 no_bgp_local_mac_cmd,
1259 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
1260 NO_STR
1261 BGP_STR
1262 "Local MAC config\n"
1263 "VxLAN Network Identifier\n"
1264 "VNI number\n"
1265 "local mac\n"
1266 "mac address\n")
1267 {
1268 int rv;
1269 vni_t vni;
1270 struct ethaddr mac;
1271 struct ipaddr ip;
1272 struct bgp *bgp;
1273
1274 vni = strtoul(argv[4]->arg, NULL, 10);
1275 if (!prefix_str2mac(argv[6]->arg, &mac)) {
1276 vty_out(vty, "%% Malformed MAC address\n");
1277 return CMD_WARNING;
1278 }
1279 memset(&ip, 0, sizeof(ip));
1280
1281 bgp = bgp_get_default();
1282 if (!bgp) {
1283 vty_out(vty, "Default BGP instance is not there\n");
1284 return CMD_WARNING;
1285 }
1286
1287 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
1288 if (rv < 0) {
1289 vty_out(vty, "Internal error\n");
1290 return CMD_WARNING;
1291 }
1292
1293 return CMD_SUCCESS;
1294 }
1295
1296 DEFUN (no_synchronization,
1297 no_synchronization_cmd,
1298 "no synchronization",
1299 NO_STR
1300 "Perform IGP synchronization\n")
1301 {
1302 return CMD_SUCCESS;
1303 }
1304
1305 DEFUN (no_auto_summary,
1306 no_auto_summary_cmd,
1307 "no auto-summary",
1308 NO_STR
1309 "Enable automatic network number summarization\n")
1310 {
1311 return CMD_SUCCESS;
1312 }
1313
1314 /* "router bgp" commands. */
1315 DEFUN_YANG_NOSH(router_bgp,
1316 router_bgp_cmd,
1317 "router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1318 ROUTER_STR BGP_STR AS_STR BGP_INSTANCE_HELP_STR)
1319 {
1320 int idx_asn = 2;
1321 int idx_view_vrf = 3;
1322 int idx_vrf = 4;
1323 int ret = CMD_SUCCESS;
1324 as_t as;
1325 struct bgp *bgp;
1326 const char *name = NULL;
1327 char as_str[12] = {'\0'};
1328 enum bgp_instance_type inst_type;
1329 char base_xpath[XPATH_MAXLEN];
1330
1331 // "router bgp" without an ASN
1332 if (argc == 2) {
1333 // Pending: Make VRF option available for ASN less config
1334 bgp = bgp_get_default();
1335
1336 if (bgp == NULL) {
1337 vty_out(vty, "%% No BGP process is configured\n");
1338 return CMD_WARNING_CONFIG_FAILED;
1339 }
1340
1341 if (listcount(bm->bgp) > 1) {
1342 vty_out(vty, "%% Please specify ASN and VRF\n");
1343 return CMD_WARNING_CONFIG_FAILED;
1344 }
1345
1346 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_GLOBAL_XPATH,
1347 "frr-bgp:bgp", "bgp", VRF_DEFAULT_NAME);
1348
1349 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
1350 snprintf(as_str, 12, "%d", bgp->as);
1351 nb_cli_enqueue_change(vty, "./global/local-as", NB_OP_MODIFY,
1352 as_str);
1353 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW) {
1354 nb_cli_enqueue_change(vty,
1355 "./global/instance-type-view",
1356 NB_OP_MODIFY, "true");
1357 }
1358
1359 nb_cli_pending_commit_check(vty);
1360 ret = nb_cli_apply_changes(vty, base_xpath);
1361 if (ret == CMD_SUCCESS) {
1362 VTY_PUSH_XPATH(BGP_NODE, base_xpath);
1363
1364 /*
1365 * For backward compatibility with old commands we still
1366 * need to use the qobj infrastructure.
1367 */
1368 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1369 }
1370 return ret;
1371 }
1372
1373 // "router bgp X"
1374 else {
1375
1376 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1377 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1378 if (argc > 3) {
1379 name = argv[idx_vrf]->arg;
1380
1381 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1382 if (strmatch(name, VRF_DEFAULT_NAME))
1383 name = NULL;
1384 else
1385 inst_type = BGP_INSTANCE_TYPE_VRF;
1386 } else if (!strcmp(argv[idx_view_vrf]->text, "view")) {
1387 inst_type = BGP_INSTANCE_TYPE_VIEW;
1388 }
1389 }
1390 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_GLOBAL_XPATH,
1391 "frr-bgp:bgp", "bgp", name ? name : VRF_DEFAULT_NAME);
1392
1393 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
1394 nb_cli_enqueue_change(vty, "./global/local-as", NB_OP_MODIFY,
1395 argv[idx_asn]->arg);
1396 if (inst_type == BGP_INSTANCE_TYPE_VIEW) {
1397 nb_cli_enqueue_change(vty,
1398 "./global/instance-type-view",
1399 NB_OP_MODIFY, "true");
1400 }
1401
1402 nb_cli_pending_commit_check(vty);
1403 ret = nb_cli_apply_changes(vty, base_xpath);
1404 if (ret == CMD_SUCCESS) {
1405 VTY_PUSH_XPATH(BGP_NODE, base_xpath);
1406
1407 /*
1408 * For backward compatibility with old commands we still
1409 * need to use the qobj infrastructure.
1410 */
1411 bgp = bgp_lookup(as, name);
1412 if (bgp)
1413 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1414 }
1415 }
1416
1417 return ret;
1418 }
1419
1420 /* "no router bgp" commands. */
1421 DEFUN_YANG(no_router_bgp,
1422 no_router_bgp_cmd,
1423 "no router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1424 NO_STR ROUTER_STR BGP_STR AS_STR BGP_INSTANCE_HELP_STR)
1425 {
1426 int idx_asn = 3;
1427 int idx_vrf = 5;
1428 as_t as = 0;
1429 struct bgp *bgp;
1430 const char *name = NULL;
1431 char base_xpath[XPATH_MAXLEN];
1432 const struct lyd_node *bgp_glb_dnode;
1433
1434 // "no router bgp" without an ASN
1435 if (argc == 3) {
1436 // Pending: Make VRF option available for ASN less config
1437 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_GLOBAL_XPATH,
1438 "frr-bgp:bgp", "bgp", VRF_DEFAULT_NAME);
1439
1440 bgp_glb_dnode = yang_dnode_get(vty->candidate_config->dnode,
1441 base_xpath);
1442 if (!bgp_glb_dnode) {
1443 vty_out(vty, "%% No BGP process is configured\n");
1444 return CMD_WARNING_CONFIG_FAILED;
1445 }
1446
1447 if (listcount(bm->bgp) > 1) {
1448 vty_out(vty, "%% Please specify ASN and VRF\n");
1449 return CMD_WARNING_CONFIG_FAILED;
1450 }
1451
1452 /* tcli mode bgp would not be set until apply stage. */
1453 bgp = nb_running_get_entry(bgp_glb_dnode, NULL, false);
1454 if (!bgp)
1455 return CMD_SUCCESS;
1456
1457 if (bgp->l3vni) {
1458 vty_out(vty, "%% Please unconfigure l3vni %u",
1459 bgp->l3vni);
1460 return CMD_WARNING_CONFIG_FAILED;
1461 }
1462 } else {
1463 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1464
1465 if (argc > 4)
1466 name = argv[idx_vrf]->arg;
1467
1468 /* Lookup bgp structure. */
1469 bgp = bgp_lookup(as, name);
1470 if (!bgp) {
1471 vty_out(vty, "%% Can't find BGP instance\n");
1472 return CMD_WARNING_CONFIG_FAILED;
1473 }
1474
1475 if (bgp->l3vni) {
1476 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1477 bgp->l3vni);
1478 return CMD_WARNING_CONFIG_FAILED;
1479 }
1480
1481 /* Cannot delete default instance if vrf instances exist */
1482 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
1483 struct listnode *node;
1484 struct bgp *tmp_bgp;
1485
1486 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, tmp_bgp)) {
1487 if (tmp_bgp->inst_type != BGP_INSTANCE_TYPE_VRF)
1488 continue;
1489 if (CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1490 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1491 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1492 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1493 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1494 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1495 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1496 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1497 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1498 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1499 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1500 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1501 (bgp == bgp_get_evpn() &&
1502 (CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1503 BGP_L2VPN_EVPN_ADVERTISE_IPV4_UNICAST) ||
1504 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1505 BGP_L2VPN_EVPN_ADVERTISE_IPV6_UNICAST))) ||
1506 (tmp_bgp->vnihash && hashcount(tmp_bgp->vnihash))) {
1507 vty_out(vty,
1508 "%% Cannot delete default BGP instance. Dependent VRF instances exist\n");
1509 return CMD_WARNING_CONFIG_FAILED;
1510 }
1511 }
1512 }
1513 }
1514 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_GLOBAL_XPATH,
1515 "frr-bgp:bgp", "bgp",
1516 bgp->name ? bgp->name : VRF_DEFAULT_NAME);
1517
1518 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
1519
1520 return nb_cli_apply_changes(vty, base_xpath);
1521 }
1522
1523 void cli_show_router_bgp(struct vty *vty, struct lyd_node *dnode,
1524 bool show_defaults)
1525 {
1526 const struct lyd_node *vrf_dnode;
1527 const char *vrf_name;
1528 as_t as;
1529
1530 vrf_dnode = yang_dnode_get_parent(dnode, "control-plane-protocol");
1531 vrf_name = yang_dnode_get_string(vrf_dnode, "./vrf");
1532 as = yang_dnode_get_uint32(dnode, "./global/local-as");
1533
1534 vty_out(vty, "!\n");
1535 vty_out(vty, "router bgp %u", as);
1536 if (!strmatch(vrf_name, VRF_DEFAULT_NAME))
1537 vty_out(vty, " vrf %s", vrf_name);
1538 vty_out(vty, "\n");
1539 }
1540
1541 /* BGP router-id. */
1542
1543 DEFPY_YANG(bgp_router_id, bgp_router_id_cmd, "bgp router-id A.B.C.D",
1544 BGP_STR
1545 "Override configured router identifier\n"
1546 "Manually configured router identifier\n")
1547 {
1548 nb_cli_enqueue_change(vty, "./global/router-id", NB_OP_MODIFY,
1549 router_id_str);
1550
1551 return nb_cli_apply_changes(vty, NULL);
1552 }
1553
1554 DEFPY_YANG(no_bgp_router_id, no_bgp_router_id_cmd, "no bgp router-id [A.B.C.D]",
1555 NO_STR BGP_STR
1556 "Override configured router identifier\n"
1557 "Manually configured router identifier\n")
1558 {
1559 nb_cli_enqueue_change(vty, "./global/router-id", NB_OP_DESTROY,
1560 router_id_str ? router_id_str : NULL);
1561
1562 return nb_cli_apply_changes(vty, NULL);
1563 }
1564
1565 void cli_show_router_bgp_router_id(struct vty *vty, struct lyd_node *dnode,
1566 bool show_defaults)
1567 {
1568 vty_out(vty, " bgp router-id %s\n", yang_dnode_get_string(dnode, NULL));
1569 }
1570
1571 DEFPY (bgp_global_suppress_fib_pending,
1572 bgp_global_suppress_fib_pending_cmd,
1573 "[no] bgp suppress-fib-pending",
1574 NO_STR
1575 BGP_STR
1576 "Advertise only routes that are programmed in kernel to peers globally\n")
1577 {
1578 bm_wait_for_fib_set(!no);
1579
1580 return CMD_SUCCESS;
1581 }
1582
1583 DEFPY (bgp_suppress_fib_pending,
1584 bgp_suppress_fib_pending_cmd,
1585 "[no] bgp suppress-fib-pending",
1586 NO_STR
1587 BGP_STR
1588 "Advertise only routes that are programmed in kernel to peers\n")
1589 {
1590 VTY_DECLVAR_CONTEXT(bgp, bgp);
1591
1592 bgp_suppress_fib_pending_set(bgp, !no);
1593 return CMD_SUCCESS;
1594 }
1595
1596
1597 /* BGP Cluster ID. */
1598 DEFUN_YANG(bgp_cluster_id,
1599 bgp_cluster_id_cmd,
1600 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1601 BGP_STR
1602 "Configure Route-Reflector Cluster-id\n"
1603 "Route-Reflector Cluster-id in IP address format\n"
1604 "Route-Reflector Cluster-id as 32 bit quantity\n")
1605 {
1606 int idx_ipv4 = 2;
1607
1608 nb_cli_enqueue_change(
1609 vty, "./global/route-reflector/route-reflector-cluster-id",
1610 NB_OP_MODIFY, argv[idx_ipv4]->arg);
1611
1612 return nb_cli_apply_changes(vty, NULL);
1613 }
1614
1615 DEFUN_YANG(no_bgp_cluster_id,
1616 no_bgp_cluster_id_cmd,
1617 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1618 NO_STR BGP_STR
1619 "Configure Route-Reflector Cluster-id\n"
1620 "Route-Reflector Cluster-id in IP address format\n"
1621 "Route-Reflector Cluster-id as 32 bit quantity\n")
1622 {
1623 nb_cli_enqueue_change(
1624 vty, "./global/route-reflector/route-reflector-cluster-id",
1625 NB_OP_DESTROY, NULL);
1626
1627 return nb_cli_apply_changes(vty, NULL);
1628 }
1629
1630 DEFPY (bgp_norib,
1631 bgp_norib_cmd,
1632 "bgp no-rib",
1633 BGP_STR
1634 "Disable BGP route installation to RIB (Zebra)\n")
1635 {
1636 if (bgp_option_check(BGP_OPT_NO_FIB)) {
1637 vty_out(vty,
1638 "%% No-RIB option is already set, nothing to do here.\n");
1639 return CMD_SUCCESS;
1640 }
1641
1642 bgp_option_norib_set_runtime();
1643
1644 return CMD_SUCCESS;
1645 }
1646
1647 DEFPY (no_bgp_norib,
1648 no_bgp_norib_cmd,
1649 "no bgp no-rib",
1650 NO_STR
1651 BGP_STR
1652 "Disable BGP route installation to RIB (Zebra)\n")
1653 {
1654 if (!bgp_option_check(BGP_OPT_NO_FIB)) {
1655 vty_out(vty,
1656 "%% No-RIB option is not set, nothing to do here.\n");
1657 return CMD_SUCCESS;
1658 }
1659
1660 bgp_option_norib_unset_runtime();
1661
1662 return CMD_SUCCESS;
1663 }
1664
1665 DEFPY (no_bgp_send_extra_data,
1666 no_bgp_send_extra_data_cmd,
1667 "[no] bgp send-extra-data zebra",
1668 NO_STR
1669 BGP_STR
1670 "Extra data to Zebra for display/use\n"
1671 "To zebra\n")
1672 {
1673 if (no)
1674 UNSET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1675 else
1676 SET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1677
1678 return CMD_SUCCESS;
1679 }
1680
1681 DEFUN_YANG(bgp_confederation_identifier,
1682 bgp_confederation_identifier_cmd,
1683 "bgp confederation identifier (1-4294967295)",
1684 "BGP specific commands\n"
1685 "AS confederation parameters\n"
1686 "AS number\n"
1687 "Set routing domain confederation AS\n")
1688 {
1689 int idx_number = 3;
1690
1691 nb_cli_enqueue_change(vty, "./global/confederation/identifier",
1692 NB_OP_MODIFY, argv[idx_number]->arg);
1693
1694 return nb_cli_apply_changes(vty, NULL);
1695 }
1696
1697 DEFUN_YANG(no_bgp_confederation_identifier,
1698 no_bgp_confederation_identifier_cmd,
1699 "no bgp confederation identifier [(1-4294967295)]",
1700 NO_STR
1701 "BGP specific commands\n"
1702 "AS confederation parameters\n"
1703 "AS number\n"
1704 "Set routing domain confederation AS\n")
1705 {
1706 nb_cli_enqueue_change(vty, "./global/confederation/identifier",
1707 NB_OP_DESTROY, NULL);
1708
1709 return nb_cli_apply_changes(vty, NULL);
1710 }
1711
1712 void cli_show_router_bgp_confederation_identifier(struct vty *vty,
1713 struct lyd_node *dnode,
1714 bool show_defaults)
1715 {
1716 vty_out(vty, " bgp confederation identifier %u\n",
1717 yang_dnode_get_uint32(dnode, NULL));
1718 }
1719
1720 DEFUN_YANG(bgp_confederation_peers,
1721 bgp_confederation_peers_cmd,
1722 "bgp confederation peers (1-4294967295)...",
1723 "BGP specific commands\n"
1724 "AS confederation parameters\n"
1725 "Peer ASs in BGP confederation\n" AS_STR)
1726 {
1727 int idx_asn = 3;
1728 int i;
1729
1730 for (i = idx_asn; i < argc; i++)
1731 nb_cli_enqueue_change(vty, "./global/confederation/member-as",
1732 NB_OP_CREATE, argv[i]->arg);
1733
1734 return nb_cli_apply_changes(vty, NULL);
1735 }
1736
1737 DEFUN_YANG(no_bgp_confederation_peers,
1738 no_bgp_confederation_peers_cmd,
1739 "no bgp confederation peers (1-4294967295)...",
1740 NO_STR
1741 "BGP specific commands\n"
1742 "AS confederation parameters\n"
1743 "Peer ASs in BGP confederation\n" AS_STR)
1744 {
1745 int idx_asn = 4;
1746 int i;
1747
1748 for (i = idx_asn; i < argc; i++)
1749 nb_cli_enqueue_change(vty, "./global/confederation/member-as",
1750 NB_OP_DESTROY, argv[i]->arg);
1751
1752 return nb_cli_apply_changes(vty, NULL);
1753 }
1754
1755 void cli_show_router_bgp_confederation_member_as(struct vty *vty,
1756 struct lyd_node *dnode,
1757 bool show_defaults)
1758 {
1759 vty_out(vty, " bgp confederation peers %u \n",
1760 yang_dnode_get_uint32(dnode, NULL));
1761 }
1762
1763 /**
1764 * Central routine for maximum-paths configuration.
1765 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1766 * @set: 1 for setting values, 0 for removing the max-paths config.
1767 */
1768 int bgp_maxpaths_config_vty(struct bgp *bgp, afi_t afi, safi_t safi,
1769 int peer_type, uint16_t maxpaths, uint16_t options,
1770 int set, char *errmsg, size_t errmsg_len)
1771 {
1772 int ret;
1773
1774 if (set) {
1775 if (maxpaths > multipath_num) {
1776 snprintf(
1777 errmsg, errmsg_len,
1778 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1779 maxpaths, multipath_num);
1780 return CMD_WARNING_CONFIG_FAILED;
1781 }
1782 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1783 options);
1784 } else
1785 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1786
1787 if (ret < 0) {
1788 snprintf(
1789 errmsg, errmsg_len,
1790 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1791 (set == 1) ? "" : "un",
1792 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1793 maxpaths, afi, safi);
1794 return CMD_WARNING_CONFIG_FAILED;
1795 }
1796
1797 bgp_recalculate_all_bestpaths(bgp);
1798
1799 return CMD_SUCCESS;
1800 }
1801
1802 void cli_show_router_bgp_med_config(struct vty *vty, struct lyd_node *dnode,
1803 bool show_defaults)
1804 {
1805 if (yang_dnode_get_bool(dnode, "./enable-med-admin")) {
1806 uint32_t med_admin_val;
1807
1808 vty_out(vty, " bgp max-med administrative");
1809 if ((med_admin_val =
1810 yang_dnode_get_uint32(dnode, "./max-med-admin"))
1811 != BGP_MAXMED_VALUE_DEFAULT)
1812 vty_out(vty, " %u", med_admin_val);
1813 vty_out(vty, "\n");
1814 }
1815
1816 if (yang_dnode_exists(dnode, "./max-med-onstart-up-time")) {
1817 uint32_t onstartup_val;
1818
1819 vty_out(vty, " bgp max-med on-startup %u",
1820 yang_dnode_get_uint32(dnode,
1821 "./max-med-onstart-up-time"));
1822 onstartup_val = yang_dnode_get_uint32(
1823 dnode, "./max-med-onstart-up-value");
1824 if (onstartup_val != BGP_MAXMED_VALUE_DEFAULT)
1825 vty_out(vty, " %u", onstartup_val);
1826
1827 vty_out(vty, "\n");
1828 }
1829 }
1830
1831 DEFUN_YANG(bgp_maxmed_admin,
1832 bgp_maxmed_admin_cmd,
1833 "bgp max-med administrative ",
1834 BGP_STR
1835 "Advertise routes with max-med\n"
1836 "Administratively applied, for an indefinite period\n")
1837 {
1838 nb_cli_enqueue_change(vty, "./global/med-config/enable-med-admin",
1839 NB_OP_MODIFY, "true");
1840
1841 return nb_cli_apply_changes(vty, NULL);
1842 }
1843
1844 DEFUN_YANG(bgp_maxmed_admin_medv,
1845 bgp_maxmed_admin_medv_cmd,
1846 "bgp max-med administrative (0-4294967295)",
1847 BGP_STR
1848 "Advertise routes with max-med\n"
1849 "Administratively applied, for an indefinite period\n"
1850 "Max MED value to be used\n")
1851 {
1852 int idx_number = 3;
1853
1854 nb_cli_enqueue_change(vty, "./global/med-config/enable-med-admin",
1855 NB_OP_MODIFY, "true");
1856
1857 nb_cli_enqueue_change(vty, "./global/med-config/max-med-admin",
1858 NB_OP_MODIFY, argv[idx_number]->arg);
1859
1860 return nb_cli_apply_changes(vty, NULL);
1861 }
1862
1863 DEFUN_YANG(no_bgp_maxmed_admin,
1864 no_bgp_maxmed_admin_cmd,
1865 "no bgp max-med administrative [(0-4294967295)]",
1866 NO_STR BGP_STR
1867 "Advertise routes with max-med\n"
1868 "Administratively applied, for an indefinite period\n"
1869 "Max MED value to be used\n")
1870 {
1871 nb_cli_enqueue_change(vty, "./global/med-config/enable-med-admin",
1872 NB_OP_MODIFY, "false");
1873
1874 nb_cli_enqueue_change(vty, "./global/med-config/max-med-admin",
1875 NB_OP_MODIFY, NULL);
1876
1877 return nb_cli_apply_changes(vty, NULL);
1878 }
1879
1880 DEFUN_YANG (bgp_maxmed_onstartup,
1881 bgp_maxmed_onstartup_cmd,
1882 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
1883 BGP_STR
1884 "Advertise routes with max-med\n"
1885 "Effective on a startup\n"
1886 "Time (seconds) period for max-med\n"
1887 "Max MED value to be used\n")
1888 {
1889 int idx = 0;
1890
1891 argv_find(argv, argc, "(5-86400)", &idx);
1892 nb_cli_enqueue_change(vty,
1893 "./global/med-config/max-med-onstart-up-time",
1894 NB_OP_MODIFY, argv[idx]->arg);
1895
1896 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1897 nb_cli_enqueue_change(
1898 vty, "./global/med-config/max-med-onstart-up-value",
1899 NB_OP_MODIFY, argv[idx]->arg);
1900 else
1901 nb_cli_enqueue_change(
1902 vty, "./global/med-config/max-med-onstart-up-value",
1903 NB_OP_MODIFY, NULL);
1904
1905 return nb_cli_apply_changes(vty, NULL);
1906 }
1907
1908 DEFUN_YANG (no_bgp_maxmed_onstartup,
1909 no_bgp_maxmed_onstartup_cmd,
1910 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
1911 NO_STR BGP_STR
1912 "Advertise routes with max-med\n"
1913 "Effective on a startup\n"
1914 "Time (seconds) period for max-med\n"
1915 "Max MED value to be used\n")
1916 {
1917 nb_cli_enqueue_change(vty,
1918 "./global/med-config/max-med-onstart-up-time",
1919 NB_OP_DESTROY, NULL);
1920
1921 nb_cli_enqueue_change(vty,
1922 "./global/med-config/max-med-onstart-up-value",
1923 NB_OP_MODIFY, NULL);
1924
1925 return nb_cli_apply_changes(vty, NULL);
1926 }
1927
1928 static int bgp_global_update_delay_config_vty(struct vty *vty,
1929 uint16_t update_delay,
1930 uint16_t establish_wait)
1931 {
1932 struct listnode *node, *nnode;
1933 struct bgp *bgp;
1934 bool vrf_cfg = false;
1935
1936 /*
1937 * See if update-delay is set per-vrf and warn user to delete it
1938 * Note that we only need to check this if this is the first time
1939 * setting the global config.
1940 */
1941 if (bm->v_update_delay == BGP_UPDATE_DELAY_DEF) {
1942 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
1943 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1944 vty_out(vty,
1945 "%% update-delay configuration found in vrf %s\n",
1946 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT
1947 ? VRF_DEFAULT_NAME
1948 : bgp->name);
1949 vrf_cfg = true;
1950 }
1951 }
1952 }
1953
1954 if (vrf_cfg) {
1955 vty_out(vty,
1956 "%%Failed: global update-delay config not permitted\n");
1957 return CMD_WARNING;
1958 }
1959
1960 if (!establish_wait) { /* update-delay <delay> */
1961 bm->v_update_delay = update_delay;
1962 bm->v_establish_wait = bm->v_update_delay;
1963 } else {
1964 /* update-delay <delay> <establish-wait> */
1965 if (update_delay < establish_wait) {
1966 vty_out(vty,
1967 "%%Failed: update-delay less than the establish-wait!\n");
1968 return CMD_WARNING_CONFIG_FAILED;
1969 }
1970
1971 bm->v_update_delay = update_delay;
1972 bm->v_establish_wait = establish_wait;
1973 }
1974
1975 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
1976 bgp->v_update_delay = bm->v_update_delay;
1977 bgp->v_establish_wait = bm->v_establish_wait;
1978 }
1979
1980 return CMD_SUCCESS;
1981 }
1982
1983 static int bgp_global_update_delay_deconfig_vty(struct vty *vty)
1984 {
1985 struct listnode *node, *nnode;
1986 struct bgp *bgp;
1987
1988 bm->v_update_delay = BGP_UPDATE_DELAY_DEF;
1989 bm->v_establish_wait = bm->v_update_delay;
1990
1991 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
1992 bgp->v_update_delay = bm->v_update_delay;
1993 bgp->v_establish_wait = bm->v_establish_wait;
1994 }
1995
1996 return CMD_SUCCESS;
1997 }
1998
1999 static int bgp_update_delay_config_vty(struct vty *vty, uint16_t update_delay,
2000 uint16_t establish_wait)
2001 {
2002 VTY_DECLVAR_CONTEXT(bgp, bgp);
2003
2004 /* if configured globally, per-instance config is not allowed */
2005 if (bm->v_update_delay) {
2006 vty_out(vty,
2007 "%%Failed: per-vrf update-delay config not permitted with global update-delay\n");
2008 return CMD_WARNING_CONFIG_FAILED;
2009 }
2010
2011
2012 if (!establish_wait) /* update-delay <delay> */
2013 {
2014 bgp->v_update_delay = update_delay;
2015 bgp->v_establish_wait = bgp->v_update_delay;
2016 return CMD_SUCCESS;
2017 }
2018
2019 /* update-delay <delay> <establish-wait> */
2020 if (update_delay < establish_wait) {
2021 vty_out(vty,
2022 "%%Failed: update-delay less than the establish-wait!\n");
2023 return CMD_WARNING_CONFIG_FAILED;
2024 }
2025
2026 bgp->v_update_delay = update_delay;
2027 bgp->v_establish_wait = establish_wait;
2028
2029 return CMD_SUCCESS;
2030 }
2031
2032 static int bgp_update_delay_deconfig_vty(struct vty *vty)
2033 {
2034 VTY_DECLVAR_CONTEXT(bgp, bgp);
2035
2036 /* If configured globally, cannot remove from one bgp instance */
2037 if (bm->v_update_delay) {
2038 vty_out(vty,
2039 "%%Failed: bgp update-delay configured globally. Delete per-vrf not permitted\n");
2040 return CMD_WARNING_CONFIG_FAILED;
2041 }
2042 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
2043 bgp->v_establish_wait = bgp->v_update_delay;
2044
2045 return CMD_SUCCESS;
2046 }
2047
2048 void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
2049 {
2050 /* If configured globally, no need to display per-instance value */
2051 if (bgp->v_update_delay != bm->v_update_delay) {
2052 vty_out(vty, " update-delay %d", bgp->v_update_delay);
2053 if (bgp->v_update_delay != bgp->v_establish_wait)
2054 vty_out(vty, " %d", bgp->v_establish_wait);
2055 vty_out(vty, "\n");
2056 }
2057 }
2058
2059 /* Global update-delay configuration */
2060 DEFPY (bgp_global_update_delay,
2061 bgp_global_update_delay_cmd,
2062 "bgp update-delay (0-3600)$delay [(1-3600)$wait]",
2063 BGP_STR
2064 "Force initial delay for best-path and updates for all bgp instances\n"
2065 "Max delay in seconds\n"
2066 "Establish wait in seconds\n")
2067 {
2068 return bgp_global_update_delay_config_vty(vty, delay, wait);
2069 }
2070
2071 /* Global update-delay deconfiguration */
2072 DEFPY (no_bgp_global_update_delay,
2073 no_bgp_global_update_delay_cmd,
2074 "no bgp update-delay [(0-3600) [(1-3600)]]",
2075 NO_STR
2076 BGP_STR
2077 "Force initial delay for best-path and updates\n"
2078 "Max delay in seconds\n"
2079 "Establish wait in seconds\n")
2080 {
2081 return bgp_global_update_delay_deconfig_vty(vty);
2082 }
2083
2084 /* Update-delay configuration */
2085
2086 DEFPY (bgp_update_delay,
2087 bgp_update_delay_cmd,
2088 "update-delay (0-3600)$delay [(1-3600)$wait]",
2089 "Force initial delay for best-path and updates\n"
2090 "Max delay in seconds\n"
2091 "Establish wait in seconds\n")
2092 {
2093 return bgp_update_delay_config_vty(vty, delay, wait);
2094 }
2095
2096 /* Update-delay deconfiguration */
2097 DEFPY (no_bgp_update_delay,
2098 no_bgp_update_delay_cmd,
2099 "no update-delay [(0-3600) [(1-3600)]]",
2100 NO_STR
2101 "Force initial delay for best-path and updates\n"
2102 "Max delay in seconds\n"
2103 "Establish wait in seconds\n")
2104 {
2105 return bgp_update_delay_deconfig_vty(vty);
2106 }
2107
2108
2109 int bgp_wpkt_quanta_config_vty(struct bgp *bgp, uint32_t quanta, bool set)
2110 {
2111 quanta = set ? quanta : BGP_WRITE_PACKET_MAX;
2112 atomic_store_explicit(&bgp->wpkt_quanta, quanta, memory_order_relaxed);
2113
2114 return CMD_SUCCESS;
2115 }
2116
2117 int bgp_rpkt_quanta_config_vty(struct bgp *bgp, uint32_t quanta, bool set)
2118 {
2119 quanta = set ? quanta : BGP_READ_PACKET_MAX;
2120 atomic_store_explicit(&bgp->rpkt_quanta, quanta, memory_order_relaxed);
2121
2122 return CMD_SUCCESS;
2123 }
2124
2125 void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
2126 {
2127 uint32_t quanta =
2128 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
2129 if (quanta != BGP_WRITE_PACKET_MAX)
2130 vty_out(vty, " write-quanta %d\n", quanta);
2131 }
2132
2133 void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
2134 {
2135 uint32_t quanta =
2136 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
2137 if (quanta != BGP_READ_PACKET_MAX)
2138 vty_out(vty, " read-quanta %d\n", quanta);
2139 }
2140
2141 /* Packet quanta configuration
2142 *
2143 * XXX: The value set here controls the size of a stack buffer in the IO
2144 * thread. When changing these limits be careful to prevent stack overflow.
2145 *
2146 * Furthermore, the maximums used here should correspond to
2147 * BGP_WRITE_PACKET_MAX and BGP_READ_PACKET_MAX.
2148 */
2149 DEFPY_YANG (bgp_wpkt_quanta,
2150 bgp_wpkt_quanta_cmd,
2151 "[no] write-quanta (1-64)$quanta",
2152 NO_STR
2153 "How many packets to write to peer socket per run\n"
2154 "Number of packets\n")
2155 {
2156 if (!no)
2157 nb_cli_enqueue_change(
2158 vty,
2159 "./global/global-neighbor-config/packet-quanta-config/wpkt-quanta",
2160 NB_OP_MODIFY, quanta_str);
2161 else
2162 nb_cli_enqueue_change(
2163 vty,
2164 "./global/global-neighbor-config/packet-quanta-config/wpkt-quanta",
2165 NB_OP_MODIFY, NULL);
2166
2167 return nb_cli_apply_changes(vty, NULL);
2168 }
2169
2170 DEFPY_YANG (bgp_rpkt_quanta,
2171 bgp_rpkt_quanta_cmd,
2172 "[no] read-quanta (1-10)$quanta",
2173 NO_STR
2174 "How many packets to read from peer socket per I/O cycle\n"
2175 "Number of packets\n")
2176 {
2177 if (!no)
2178 nb_cli_enqueue_change(
2179 vty,
2180 "./global/global-neighbor-config/packet-quanta-config/rpkt-quanta",
2181 NB_OP_MODIFY, quanta_str);
2182 else
2183 nb_cli_enqueue_change(
2184 vty,
2185 "./global/global-neighbor-config/packet-quanta-config/rpkt-quanta",
2186 NB_OP_MODIFY, NULL);
2187
2188 return nb_cli_apply_changes(vty, NULL);
2189 }
2190
2191 void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
2192 {
2193 if (!bgp->heuristic_coalesce)
2194 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
2195 }
2196
2197 void cli_show_router_global_update_group_config_coalesce_time(
2198 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
2199 {
2200 vty_out(vty, " coalesce-time %u\n", yang_dnode_get_uint32(dnode, NULL));
2201 }
2202
2203
2204 DEFUN_YANG (bgp_coalesce_time,
2205 bgp_coalesce_time_cmd,
2206 "coalesce-time (0-4294967295)",
2207 "Subgroup coalesce timer\n"
2208 "Subgroup coalesce timer value (in ms)\n")
2209 {
2210 int idx = 0;
2211
2212 argv_find(argv, argc, "(0-4294967295)", &idx);
2213 nb_cli_enqueue_change(
2214 vty, "./global/global-update-group-config/coalesce-time",
2215 NB_OP_MODIFY, argv[idx]->arg);
2216
2217 return nb_cli_apply_changes(vty, NULL);
2218 }
2219
2220 DEFUN_YANG(no_bgp_coalesce_time,
2221 no_bgp_coalesce_time_cmd,
2222 "no coalesce-time (0-4294967295)",
2223 NO_STR
2224 "Subgroup coalesce timer\n"
2225 "Subgroup coalesce timer value (in ms)\n")
2226 {
2227 nb_cli_enqueue_change(
2228 vty, "./global/global-update-group-config/coalesce-time",
2229 NB_OP_MODIFY, NULL);
2230
2231 return nb_cli_apply_changes(vty, NULL);
2232 }
2233
2234 /* Maximum-paths configuration */
2235 DEFUN_YANG (bgp_maxpaths,
2236 bgp_maxpaths_cmd,
2237 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2238 "Forward packets over multiple paths\n"
2239 "Number of paths\n")
2240 {
2241 int idx_number = 1;
2242 char base_xpath[XPATH_MAXLEN];
2243 afi_t afi;
2244 safi_t safi;
2245
2246 afi = bgp_node_afi(vty);
2247 safi = bgp_node_safi(vty);
2248
2249 snprintf(
2250 base_xpath, sizeof(base_xpath),
2251 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ebgp/maximum-paths",
2252 yang_afi_safi_value2identity(afi, safi),
2253 bgp_afi_safi_get_container_str(afi, safi));
2254
2255 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY,
2256 argv[idx_number]->arg);
2257
2258 return nb_cli_apply_changes(vty, NULL);
2259 }
2260
2261 void cli_show_bgp_global_afi_safi_unicast_use_multiple_paths_ebgp_maximum_paths(
2262 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
2263 {
2264 vty_out(vty, " maximum-paths %d\n",
2265 yang_dnode_get_uint16(dnode, NULL));
2266 }
2267
2268 ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
2269 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2270 "Forward packets over multiple paths\n"
2271 "Number of paths\n")
2272
2273 DEFUN_YANG (bgp_maxpaths_ibgp,
2274 bgp_maxpaths_ibgp_cmd,
2275 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2276 "Forward packets over multiple paths\n"
2277 "iBGP-multipath\n"
2278 "Number of paths\n")
2279 {
2280 int idx_number = 2;
2281 char base_xpath[XPATH_MAXLEN];
2282 afi_t afi;
2283 safi_t safi;
2284
2285 afi = bgp_node_afi(vty);
2286 safi = bgp_node_safi(vty);
2287
2288 snprintf(
2289 base_xpath, sizeof(base_xpath),
2290 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/maximum-paths",
2291 yang_afi_safi_value2identity(afi, safi),
2292 bgp_afi_safi_get_container_str(afi, safi));
2293
2294 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY,
2295 argv[idx_number]->arg);
2296
2297 return nb_cli_apply_changes(vty, NULL);
2298 }
2299
2300 ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
2301 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2302 "Forward packets over multiple paths\n"
2303 "iBGP-multipath\n"
2304 "Number of paths\n")
2305
2306 DEFUN_YANG (bgp_maxpaths_ibgp_cluster,
2307 bgp_maxpaths_ibgp_cluster_cmd,
2308 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
2309 "Forward packets over multiple paths\n"
2310 "iBGP-multipath\n"
2311 "Number of paths\n"
2312 "Match the cluster length\n")
2313 {
2314 int idx_number = 2;
2315 char base_xpath[XPATH_MAXLEN];
2316 afi_t afi;
2317 safi_t safi;
2318
2319 afi = bgp_node_afi(vty);
2320 safi = bgp_node_safi(vty);
2321
2322 snprintf(
2323 base_xpath, sizeof(base_xpath),
2324 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/maximum-paths",
2325 yang_afi_safi_value2identity(afi, safi),
2326 bgp_afi_safi_get_container_str(afi, safi));
2327
2328 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY,
2329 argv[idx_number]->arg);
2330
2331 snprintf(
2332 base_xpath, sizeof(base_xpath),
2333 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/cluster-length-list",
2334 yang_afi_safi_value2identity(afi, safi),
2335 bgp_afi_safi_get_container_str(afi, safi));
2336
2337 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, "true");
2338
2339 return nb_cli_apply_changes(vty, NULL);
2340 }
2341
2342 void cli_show_bgp_global_afi_safi_ip_unicast_use_multiple_paths_ibgp_maximum_paths(
2343 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
2344 {
2345 vty_out(vty, " maximum-paths ibgp %d",
2346 yang_dnode_get_uint16(dnode, "./maximum-paths"));
2347 if (yang_dnode_get_bool(dnode, "./cluster-length-list"))
2348 vty_out(vty, " equal-cluster-length");
2349 vty_out(vty, "\n");
2350 }
2351
2352 ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
2353 "maximum-paths ibgp " CMD_RANGE_STR(
2354 1, MULTIPATH_NUM) " equal-cluster-length",
2355 "Forward packets over multiple paths\n"
2356 "iBGP-multipath\n"
2357 "Number of paths\n"
2358 "Match the cluster length\n")
2359
2360 DEFUN_YANG (no_bgp_maxpaths,
2361 no_bgp_maxpaths_cmd,
2362 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
2363 NO_STR
2364 "Forward packets over multiple paths\n"
2365 "Number of paths\n")
2366 {
2367 char base_xpath[XPATH_MAXLEN];
2368 afi_t afi;
2369 safi_t safi;
2370
2371 afi = bgp_node_afi(vty);
2372 safi = bgp_node_safi(vty);
2373
2374 snprintf(
2375 base_xpath, sizeof(base_xpath),
2376 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ebgp/maximum-paths",
2377 yang_afi_safi_value2identity(afi, safi),
2378 bgp_afi_safi_get_container_str(afi, safi));
2379
2380 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, NULL);
2381
2382 return nb_cli_apply_changes(vty, NULL);
2383 }
2384
2385 ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
2386 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
2387 "Forward packets over multiple paths\n"
2388 "Number of paths\n")
2389
2390 DEFUN_YANG (no_bgp_maxpaths_ibgp,
2391 no_bgp_maxpaths_ibgp_cmd,
2392 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
2393 NO_STR
2394 "Forward packets over multiple paths\n"
2395 "iBGP-multipath\n"
2396 "Number of paths\n"
2397 "Match the cluster length\n")
2398 {
2399 char base_xpath[XPATH_MAXLEN];
2400 afi_t afi;
2401 safi_t safi;
2402
2403 afi = bgp_node_afi(vty);
2404 safi = bgp_node_safi(vty);
2405
2406 snprintf(
2407 base_xpath, sizeof(base_xpath),
2408 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/maximum-paths",
2409 yang_afi_safi_value2identity(afi, safi),
2410 bgp_afi_safi_get_container_str(afi, safi));
2411
2412 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, NULL);
2413
2414 snprintf(
2415 base_xpath, sizeof(base_xpath),
2416 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/cluster-length-list",
2417 yang_afi_safi_value2identity(afi, safi),
2418 bgp_afi_safi_get_container_str(afi, safi));
2419
2420 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, "false");
2421
2422 return nb_cli_apply_changes(vty, NULL);
2423 }
2424
2425 ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
2426 "no maximum-paths ibgp [" CMD_RANGE_STR(
2427 1, MULTIPATH_NUM) " [equal-cluster-length]]",
2428 NO_STR
2429 "Forward packets over multiple paths\n"
2430 "iBGP-multipath\n"
2431 "Number of paths\n"
2432 "Match the cluster length\n")
2433
2434 static void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp,
2435 afi_t afi, safi_t safi)
2436 {
2437 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != multipath_num) {
2438 vty_out(vty, " maximum-paths %d\n",
2439 bgp->maxpaths[afi][safi].maxpaths_ebgp);
2440 }
2441
2442 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != multipath_num) {
2443 vty_out(vty, " maximum-paths ibgp %d",
2444 bgp->maxpaths[afi][safi].maxpaths_ibgp);
2445 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
2446 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
2447 vty_out(vty, " equal-cluster-length");
2448 vty_out(vty, "\n");
2449 }
2450 }
2451
2452 /* BGP timers. */
2453
2454 DEFUN_YANG (bgp_timers,
2455 bgp_timers_cmd,
2456 "timers bgp (0-65535) (0-65535)",
2457 "Adjust routing timers\n"
2458 "BGP timers\n"
2459 "Keepalive interval\n"
2460 "Holdtime\n")
2461 {
2462 int idx_number = 2;
2463 int idx_number_2 = 3;
2464
2465 nb_cli_enqueue_change(vty, "./global/global-config-timers/keepalive",
2466 NB_OP_MODIFY, argv[idx_number]->arg);
2467 nb_cli_enqueue_change(vty, "./global/global-config-timers/hold-time",
2468 NB_OP_MODIFY, argv[idx_number_2]->arg);
2469
2470 return nb_cli_apply_changes(vty, NULL);
2471 }
2472
2473 DEFUN_YANG (no_bgp_timers,
2474 no_bgp_timers_cmd,
2475 "no timers bgp [(0-65535) (0-65535)]",
2476 NO_STR
2477 "Adjust routing timers\n"
2478 "BGP timers\n"
2479 "Keepalive interval\n"
2480 "Holdtime\n")
2481 {
2482 nb_cli_enqueue_change(vty, "./global/global-config-timers/keepalive",
2483 NB_OP_DESTROY, NULL);
2484 nb_cli_enqueue_change(vty, "./global/global-config-timers/hold-time",
2485 NB_OP_DESTROY, NULL);
2486
2487 return nb_cli_apply_changes(vty, NULL);
2488 }
2489
2490 void cli_show_router_bgp_route_reflector(struct vty *vty,
2491 struct lyd_node *dnode,
2492 bool show_defaults)
2493 {
2494 if (yang_dnode_get_bool(dnode, "./no-client-reflect"))
2495 vty_out(vty, " no bgp client-to-client reflection\n");
2496
2497 if (yang_dnode_get_bool(dnode, "./allow-outbound-policy"))
2498 vty_out(vty, " bgp route-reflector allow-outbound-policy\n");
2499
2500 if (yang_dnode_exists(dnode, "./route-reflector-cluster-id"))
2501 vty_out(vty, " bgp cluster-id %s\n",
2502 yang_dnode_get_string(dnode,
2503 "./route-reflector-cluster-id"));
2504 }
2505
2506 DEFUN_YANG(bgp_client_to_client_reflection,
2507 bgp_client_to_client_reflection_cmd,
2508 "bgp client-to-client reflection",
2509 "BGP specific commands\n"
2510 "Configure client to client route reflection\n"
2511 "reflection of routes allowed\n")
2512 {
2513 nb_cli_enqueue_change(vty, "./global/route-reflector/no-client-reflect",
2514 NB_OP_MODIFY, "false");
2515
2516 return nb_cli_apply_changes(vty, NULL);
2517 }
2518
2519 DEFUN_YANG(no_bgp_client_to_client_reflection,
2520 no_bgp_client_to_client_reflection_cmd,
2521 "no bgp client-to-client reflection",
2522 NO_STR
2523 "BGP specific commands\n"
2524 "Configure client to client route reflection\n"
2525 "reflection of routes allowed\n")
2526 {
2527 nb_cli_enqueue_change(vty, "./global/route-reflector/no-client-reflect",
2528 NB_OP_MODIFY, "true");
2529
2530 return nb_cli_apply_changes(vty, NULL);
2531 }
2532
2533 void cli_show_router_bgp_route_selection(struct vty *vty,
2534 struct lyd_node *dnode,
2535 bool show_defaults)
2536 {
2537
2538 if (yang_dnode_get_bool(dnode, "./always-compare-med"))
2539 vty_out(vty, " bgp always-compare-med\n");
2540
2541 if (yang_dnode_get_bool(dnode, "./ignore-as-path-length"))
2542 vty_out(vty, " bgp bestpath as-path ignore\n");
2543
2544 if (yang_dnode_get_bool(dnode, "./aspath-confed"))
2545 vty_out(vty, " bgp bestpath as-path confed\n");
2546
2547 if (yang_dnode_get_bool(dnode, "./external-compare-router-id"))
2548 vty_out(vty, " bgp bestpath compare-routerid\n");
2549
2550 if (yang_dnode_get_bool(dnode, "./allow-multiple-as")) {
2551 if (yang_dnode_get_bool(dnode, "./multi-path-as-set"))
2552 vty_out(vty,
2553 " bgp bestpath as-path multipath-relax as-set\n");
2554 else
2555 vty_out(vty, " bgp bestpath as-path multipath-relax\n");
2556 }
2557
2558 if (yang_dnode_get_bool(dnode, "./deterministic-med"))
2559 vty_out(vty, " bgp deterministic-med\n");
2560
2561 if (yang_dnode_get_bool(dnode, "./confed-med")
2562 || yang_dnode_get_bool(dnode, "./missing-as-worst-med")) {
2563 vty_out(vty, " bgp bestpath med");
2564 if (yang_dnode_get_bool(dnode, "./confed-med"))
2565 vty_out(vty, " confed");
2566 if (yang_dnode_get_bool(dnode, "./missing-as-worst-med"))
2567 vty_out(vty, " missing-as-worst");
2568 vty_out(vty, "\n");
2569 }
2570 }
2571
2572 /* "bgp always-compare-med" configuration. */
2573 DEFUN_YANG(bgp_always_compare_med,
2574 bgp_always_compare_med_cmd,
2575 "bgp always-compare-med",
2576 "BGP specific commands\n"
2577 "Allow comparing MED from different neighbors\n")
2578 {
2579 nb_cli_enqueue_change(
2580 vty, "./global/route-selection-options/always-compare-med",
2581 NB_OP_MODIFY, "true");
2582
2583 return nb_cli_apply_changes(vty, NULL);
2584 }
2585
2586 DEFUN_YANG(no_bgp_always_compare_med,
2587 no_bgp_always_compare_med_cmd,
2588 "no bgp always-compare-med",
2589 NO_STR
2590 "BGP specific commands\n"
2591 "Allow comparing MED from different neighbors\n")
2592 {
2593 nb_cli_enqueue_change(
2594 vty, "./global/route-selection-options/always-compare-med",
2595 NB_OP_MODIFY, "false");
2596
2597 return nb_cli_apply_changes(vty, NULL);
2598 }
2599
2600 DEFUN_YANG(bgp_suppress_duplicates,
2601 bgp_suppress_duplicates_cmd,
2602 "bgp suppress-duplicates",
2603 "BGP specific commands\n"
2604 "Suppress duplicate updates if the route actually not changed\n")
2605 {
2606 nb_cli_enqueue_change(vty, "./global/suppress-duplicates",
2607 NB_OP_MODIFY, "true");
2608 return nb_cli_apply_changes(vty, NULL);
2609 }
2610
2611 DEFUN_YANG(no_bgp_suppress_duplicates,
2612 no_bgp_suppress_duplicates_cmd,
2613 "no bgp suppress-duplicates",
2614 NO_STR
2615 "BGP specific commands\n"
2616 "Suppress duplicate updates if the route actually not changed\n")
2617 {
2618 nb_cli_enqueue_change(vty, "./global/suppress-duplicates",
2619 NB_OP_MODIFY, "false");
2620 return nb_cli_apply_changes(vty, NULL);
2621 }
2622
2623 void cli_show_router_bgp_suppress_duplicates(struct vty *vty,
2624 struct lyd_node *dnode,
2625 bool show_defaults)
2626 {
2627 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_SUPPRESS_DUPLICATES)
2628 vty_out(vty, " bgp suppress-duplicates\n");
2629 }
2630
2631 DEFUN_YANG(bgp_ebgp_requires_policy,
2632 bgp_ebgp_requires_policy_cmd,
2633 "bgp ebgp-requires-policy",
2634 "BGP specific commands\n"
2635 "Require in and out policy for eBGP peers (RFC8212)\n")
2636 {
2637 nb_cli_enqueue_change(vty, "./global/ebgp-requires-policy",
2638 NB_OP_MODIFY, "true");
2639 return nb_cli_apply_changes(vty, NULL);
2640 }
2641
2642 DEFUN_YANG(no_bgp_ebgp_requires_policy,
2643 no_bgp_ebgp_requires_policy_cmd,
2644 "no bgp ebgp-requires-policy",
2645 NO_STR
2646 "BGP specific commands\n"
2647 "Require in and out policy for eBGP peers (RFC8212)\n")
2648 {
2649 nb_cli_enqueue_change(vty, "./global/ebgp-requires-policy",
2650 NB_OP_MODIFY, "false");
2651 return nb_cli_apply_changes(vty, NULL);
2652 }
2653
2654 void cli_show_router_bgp_ebgp_requires_policy(struct vty *vty,
2655 struct lyd_node *dnode,
2656 bool show_defaults)
2657 {
2658 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_EBGP_REQUIRES_POLICY)
2659 vty_out(vty, " bgp ebgp-requires-policy\n");
2660 }
2661
2662 DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd,
2663 "bgp reject-as-sets",
2664 "BGP specific commands\n"
2665 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2666 {
2667 VTY_DECLVAR_CONTEXT(bgp, bgp);
2668 struct listnode *node, *nnode;
2669 struct peer *peer;
2670
2671 bgp->reject_as_sets = true;
2672
2673 /* Reset existing BGP sessions to reject routes
2674 * with aspath containing AS_SET or AS_CONFED_SET.
2675 */
2676 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2677 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2678 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2679 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2680 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2681 }
2682 }
2683
2684 return CMD_SUCCESS;
2685 }
2686
2687 DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd,
2688 "no bgp reject-as-sets",
2689 NO_STR
2690 "BGP specific commands\n"
2691 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2692 {
2693 VTY_DECLVAR_CONTEXT(bgp, bgp);
2694 struct listnode *node, *nnode;
2695 struct peer *peer;
2696
2697 bgp->reject_as_sets = false;
2698
2699 /* Reset existing BGP sessions to reject routes
2700 * with aspath containing AS_SET or AS_CONFED_SET.
2701 */
2702 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2703 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2704 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2705 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2706 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2707 }
2708 }
2709
2710 return CMD_SUCCESS;
2711 }
2712
2713 /* "bgp deterministic-med" configuration. */
2714 DEFUN_YANG (bgp_deterministic_med,
2715 bgp_deterministic_med_cmd,
2716 "bgp deterministic-med",
2717 "BGP specific commands\n"
2718 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2719 {
2720 nb_cli_enqueue_change(
2721 vty, "./global/route-selection-options/deterministic-med",
2722 NB_OP_MODIFY, "true");
2723
2724 return nb_cli_apply_changes(vty, NULL);
2725 }
2726
2727 DEFUN_YANG (no_bgp_deterministic_med,
2728 no_bgp_deterministic_med_cmd,
2729 "no bgp deterministic-med",
2730 NO_STR
2731 "BGP specific commands\n"
2732 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2733 {
2734 nb_cli_enqueue_change(
2735 vty, "./global/route-selection-options/deterministic-med",
2736 NB_OP_MODIFY, "false");
2737
2738 return nb_cli_apply_changes(vty, NULL);
2739 }
2740
2741 /* "bgp graceful-restart mode" configuration. */
2742 DEFUN (bgp_graceful_restart,
2743 bgp_graceful_restart_cmd,
2744 "bgp graceful-restart",
2745 "BGP specific commands\n"
2746 GR_CMD
2747 )
2748 {
2749 int ret = BGP_GR_FAILURE;
2750
2751 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2752 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : START ");
2753
2754 VTY_DECLVAR_CONTEXT(bgp, bgp);
2755
2756 ret = bgp_gr_update_all(bgp, GLOBAL_GR_CMD);
2757
2758 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2759 ret);
2760
2761 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2762 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : END ");
2763 vty_out(vty,
2764 "Graceful restart configuration changed, reset all peers to take effect\n");
2765 return bgp_vty_return(vty, ret);
2766 }
2767
2768 DEFUN (no_bgp_graceful_restart,
2769 no_bgp_graceful_restart_cmd,
2770 "no bgp graceful-restart",
2771 NO_STR
2772 "BGP specific commands\n"
2773 NO_GR_CMD
2774 )
2775 {
2776 VTY_DECLVAR_CONTEXT(bgp, bgp);
2777
2778 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2779 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : START ");
2780
2781 int ret = BGP_GR_FAILURE;
2782
2783 ret = bgp_gr_update_all(bgp, NO_GLOBAL_GR_CMD);
2784
2785 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2786 ret);
2787
2788 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2789 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : END ");
2790 vty_out(vty,
2791 "Graceful restart configuration changed, reset all peers to take effect\n");
2792
2793 return bgp_vty_return(vty, ret);
2794 }
2795
2796 DEFUN (bgp_graceful_restart_stalepath_time,
2797 bgp_graceful_restart_stalepath_time_cmd,
2798 "bgp graceful-restart stalepath-time (1-4095)",
2799 "BGP specific commands\n"
2800 "Graceful restart capability parameters\n"
2801 "Set the max time to hold onto restarting peer's stale paths\n"
2802 "Delay value (seconds)\n")
2803 {
2804 VTY_DECLVAR_CONTEXT(bgp, bgp);
2805 int idx_number = 3;
2806 uint32_t stalepath;
2807
2808 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2809 bgp->stalepath_time = stalepath;
2810 return CMD_SUCCESS;
2811 }
2812
2813 DEFUN (bgp_graceful_restart_restart_time,
2814 bgp_graceful_restart_restart_time_cmd,
2815 "bgp graceful-restart restart-time (1-4095)",
2816 "BGP specific commands\n"
2817 "Graceful restart capability parameters\n"
2818 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2819 "Delay value (seconds)\n")
2820 {
2821 VTY_DECLVAR_CONTEXT(bgp, bgp);
2822 int idx_number = 3;
2823 uint32_t restart;
2824
2825 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2826 bgp->restart_time = restart;
2827 return CMD_SUCCESS;
2828 }
2829
2830 DEFUN (bgp_graceful_restart_select_defer_time,
2831 bgp_graceful_restart_select_defer_time_cmd,
2832 "bgp graceful-restart select-defer-time (0-3600)",
2833 "BGP specific commands\n"
2834 "Graceful restart capability parameters\n"
2835 "Set the time to defer the BGP route selection after restart\n"
2836 "Delay value (seconds, 0 - disable)\n")
2837 {
2838 VTY_DECLVAR_CONTEXT(bgp, bgp);
2839 int idx_number = 3;
2840 uint32_t defer_time;
2841
2842 defer_time = strtoul(argv[idx_number]->arg, NULL, 10);
2843 bgp->select_defer_time = defer_time;
2844 if (defer_time == 0)
2845 SET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2846 else
2847 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2848
2849 return CMD_SUCCESS;
2850 }
2851
2852 DEFUN (no_bgp_graceful_restart_stalepath_time,
2853 no_bgp_graceful_restart_stalepath_time_cmd,
2854 "no bgp graceful-restart stalepath-time [(1-4095)]",
2855 NO_STR
2856 "BGP specific commands\n"
2857 "Graceful restart capability parameters\n"
2858 "Set the max time to hold onto restarting peer's stale paths\n"
2859 "Delay value (seconds)\n")
2860 {
2861 VTY_DECLVAR_CONTEXT(bgp, bgp);
2862
2863 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2864 return CMD_SUCCESS;
2865 }
2866
2867 DEFUN (no_bgp_graceful_restart_restart_time,
2868 no_bgp_graceful_restart_restart_time_cmd,
2869 "no bgp graceful-restart restart-time [(1-4095)]",
2870 NO_STR
2871 "BGP specific commands\n"
2872 "Graceful restart capability parameters\n"
2873 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2874 "Delay value (seconds)\n")
2875 {
2876 VTY_DECLVAR_CONTEXT(bgp, bgp);
2877
2878 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2879 return CMD_SUCCESS;
2880 }
2881
2882 DEFUN (no_bgp_graceful_restart_select_defer_time,
2883 no_bgp_graceful_restart_select_defer_time_cmd,
2884 "no bgp graceful-restart select-defer-time [(0-3600)]",
2885 NO_STR
2886 "BGP specific commands\n"
2887 "Graceful restart capability parameters\n"
2888 "Set the time to defer the BGP route selection after restart\n"
2889 "Delay value (seconds)\n")
2890 {
2891 VTY_DECLVAR_CONTEXT(bgp, bgp);
2892
2893 bgp->select_defer_time = BGP_DEFAULT_SELECT_DEFERRAL_TIME;
2894 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2895
2896 return CMD_SUCCESS;
2897 }
2898
2899 DEFUN (bgp_graceful_restart_preserve_fw,
2900 bgp_graceful_restart_preserve_fw_cmd,
2901 "bgp graceful-restart preserve-fw-state",
2902 "BGP specific commands\n"
2903 "Graceful restart capability parameters\n"
2904 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
2905 {
2906 VTY_DECLVAR_CONTEXT(bgp, bgp);
2907 SET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
2908 return CMD_SUCCESS;
2909 }
2910
2911 DEFUN (no_bgp_graceful_restart_preserve_fw,
2912 no_bgp_graceful_restart_preserve_fw_cmd,
2913 "no bgp graceful-restart preserve-fw-state",
2914 NO_STR
2915 "BGP specific commands\n"
2916 "Graceful restart capability parameters\n"
2917 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
2918 {
2919 VTY_DECLVAR_CONTEXT(bgp, bgp);
2920 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
2921 return CMD_SUCCESS;
2922 }
2923
2924 DEFUN (bgp_graceful_restart_disable,
2925 bgp_graceful_restart_disable_cmd,
2926 "bgp graceful-restart-disable",
2927 "BGP specific commands\n"
2928 GR_DISABLE)
2929 {
2930 int ret = BGP_GR_FAILURE;
2931
2932 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2933 zlog_debug(
2934 "[BGP_GR] bgp_graceful_restart_disable_cmd : START ");
2935
2936 VTY_DECLVAR_CONTEXT(bgp, bgp);
2937
2938 ret = bgp_gr_update_all(bgp, GLOBAL_DISABLE_CMD);
2939
2940 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
2941 bgp->peer, ret);
2942
2943 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2944 zlog_debug(
2945 "[BGP_GR] bgp_graceful_restart_disable_cmd : END ");
2946 vty_out(vty,
2947 "Graceful restart configuration changed, reset all peers to take effect\n");
2948
2949 return bgp_vty_return(vty, ret);
2950 }
2951
2952 DEFUN (no_bgp_graceful_restart_disable,
2953 no_bgp_graceful_restart_disable_cmd,
2954 "no bgp graceful-restart-disable",
2955 NO_STR
2956 "BGP specific commands\n"
2957 NO_GR_DISABLE
2958 )
2959 {
2960 VTY_DECLVAR_CONTEXT(bgp, bgp);
2961
2962 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2963 zlog_debug(
2964 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : START ");
2965
2966 int ret = BGP_GR_FAILURE;
2967
2968 ret = bgp_gr_update_all(bgp, NO_GLOBAL_DISABLE_CMD);
2969
2970 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2971 ret);
2972
2973 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2974 zlog_debug(
2975 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : END ");
2976 vty_out(vty,
2977 "Graceful restart configuration changed, reset all peers to take effect\n");
2978
2979 return bgp_vty_return(vty, ret);
2980 }
2981
2982 DEFUN (bgp_neighbor_graceful_restart_set,
2983 bgp_neighbor_graceful_restart_set_cmd,
2984 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
2985 NEIGHBOR_STR
2986 NEIGHBOR_ADDR_STR2
2987 GR_NEIGHBOR_CMD
2988 )
2989 {
2990 int idx_peer = 1;
2991 struct peer *peer;
2992 int ret = BGP_GR_FAILURE;
2993
2994 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2995
2996 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2997 zlog_debug(
2998 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : START ");
2999
3000 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3001 if (!peer)
3002 return CMD_WARNING_CONFIG_FAILED;
3003
3004 ret = bgp_neighbor_graceful_restart(peer, PEER_GR_CMD);
3005
3006 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3007 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3008
3009 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3010 zlog_debug(
3011 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : END ");
3012 vty_out(vty,
3013 "Graceful restart configuration changed, reset this peer to take effect\n");
3014
3015 return bgp_vty_return(vty, ret);
3016 }
3017
3018 DEFUN (no_bgp_neighbor_graceful_restart,
3019 no_bgp_neighbor_graceful_restart_set_cmd,
3020 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3021 NO_STR
3022 NEIGHBOR_STR
3023 NEIGHBOR_ADDR_STR2
3024 NO_GR_NEIGHBOR_CMD
3025 )
3026 {
3027 int idx_peer = 2;
3028 int ret = BGP_GR_FAILURE;
3029 struct peer *peer;
3030
3031 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3032
3033 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3034 if (!peer)
3035 return CMD_WARNING_CONFIG_FAILED;
3036
3037 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3038 zlog_debug(
3039 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : START ");
3040
3041 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_GR_CMD);
3042
3043 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3044 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3045
3046 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3047 zlog_debug(
3048 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : END ");
3049 vty_out(vty,
3050 "Graceful restart configuration changed, reset this peer to take effect\n");
3051
3052 return bgp_vty_return(vty, ret);
3053 }
3054
3055 DEFUN (bgp_neighbor_graceful_restart_helper_set,
3056 bgp_neighbor_graceful_restart_helper_set_cmd,
3057 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3058 NEIGHBOR_STR
3059 NEIGHBOR_ADDR_STR2
3060 GR_NEIGHBOR_HELPER_CMD
3061 )
3062 {
3063 int idx_peer = 1;
3064 struct peer *peer;
3065 int ret = BGP_GR_FAILURE;
3066
3067 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3068
3069 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3070 zlog_debug(
3071 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : START ");
3072
3073 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3074
3075 if (!peer)
3076 return CMD_WARNING_CONFIG_FAILED;
3077
3078
3079 ret = bgp_neighbor_graceful_restart(peer, PEER_HELPER_CMD);
3080
3081 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3082 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3083
3084 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3085 zlog_debug(
3086 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : END ");
3087 vty_out(vty,
3088 "Graceful restart configuration changed, reset this peer to take effect\n");
3089
3090 return bgp_vty_return(vty, ret);
3091 }
3092
3093 DEFUN (no_bgp_neighbor_graceful_restart_helper,
3094 no_bgp_neighbor_graceful_restart_helper_set_cmd,
3095 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3096 NO_STR
3097 NEIGHBOR_STR
3098 NEIGHBOR_ADDR_STR2
3099 NO_GR_NEIGHBOR_HELPER_CMD
3100 )
3101 {
3102 int idx_peer = 2;
3103 int ret = BGP_GR_FAILURE;
3104 struct peer *peer;
3105
3106 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3107
3108 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3109 if (!peer)
3110 return CMD_WARNING_CONFIG_FAILED;
3111
3112 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3113 zlog_debug(
3114 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : START ");
3115
3116 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_HELPER_CMD);
3117
3118 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3119 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3120
3121 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3122 zlog_debug(
3123 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : END ");
3124 vty_out(vty,
3125 "Graceful restart configuration changed, reset this peer to take effect\n");
3126
3127 return bgp_vty_return(vty, ret);
3128 }
3129
3130 DEFUN (bgp_neighbor_graceful_restart_disable_set,
3131 bgp_neighbor_graceful_restart_disable_set_cmd,
3132 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3133 NEIGHBOR_STR
3134 NEIGHBOR_ADDR_STR2
3135 GR_NEIGHBOR_DISABLE_CMD
3136 )
3137 {
3138 int idx_peer = 1;
3139 struct peer *peer;
3140 int ret = BGP_GR_FAILURE;
3141
3142 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3143
3144 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3145 zlog_debug(
3146 "[BGP_GR] bgp_neighbor_graceful_restart_disable_set_cmd : START ");
3147
3148 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3149 if (!peer)
3150 return CMD_WARNING_CONFIG_FAILED;
3151
3152 ret = bgp_neighbor_graceful_restart(peer, PEER_DISABLE_CMD);
3153
3154 if (peer->bgp->t_startup)
3155 bgp_peer_gr_flags_update(peer);
3156
3157 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3158 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3159
3160 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3161 zlog_debug(
3162 "[BGP_GR]bgp_neighbor_graceful_restart_disable_set_cmd : END ");
3163 vty_out(vty,
3164 "Graceful restart configuration changed, reset this peer to take effect\n");
3165
3166 return bgp_vty_return(vty, ret);
3167 }
3168
3169 DEFUN (no_bgp_neighbor_graceful_restart_disable,
3170 no_bgp_neighbor_graceful_restart_disable_set_cmd,
3171 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3172 NO_STR
3173 NEIGHBOR_STR
3174 NEIGHBOR_ADDR_STR2
3175 NO_GR_NEIGHBOR_DISABLE_CMD
3176 )
3177 {
3178 int idx_peer = 2;
3179 int ret = BGP_GR_FAILURE;
3180 struct peer *peer;
3181
3182 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3183
3184 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3185 if (!peer)
3186 return CMD_WARNING_CONFIG_FAILED;
3187
3188 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3189 zlog_debug(
3190 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : START ");
3191
3192 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_DISABLE_CMD);
3193
3194 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3195 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3196
3197 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3198 zlog_debug(
3199 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : END ");
3200 vty_out(vty,
3201 "Graceful restart configuration changed, reset this peer to take effect\n");
3202
3203 return bgp_vty_return(vty, ret);
3204 }
3205
3206 DEFUN_HIDDEN (bgp_graceful_restart_disable_eor,
3207 bgp_graceful_restart_disable_eor_cmd,
3208 "bgp graceful-restart disable-eor",
3209 "BGP specific commands\n"
3210 "Graceful restart configuration parameters\n"
3211 "Disable EOR Check\n")
3212 {
3213 VTY_DECLVAR_CONTEXT(bgp, bgp);
3214 SET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
3215
3216 return CMD_SUCCESS;
3217 }
3218
3219 DEFUN_HIDDEN (no_bgp_graceful_restart_disable_eor,
3220 no_bgp_graceful_restart_disable_eor_cmd,
3221 "no bgp graceful-restart disable-eor",
3222 NO_STR
3223 "BGP specific commands\n"
3224 "Graceful restart configuration parameters\n"
3225 "Disable EOR Check\n")
3226 {
3227 VTY_DECLVAR_CONTEXT(bgp, bgp);
3228 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
3229
3230 return CMD_SUCCESS;
3231 }
3232
3233 DEFUN (bgp_graceful_restart_rib_stale_time,
3234 bgp_graceful_restart_rib_stale_time_cmd,
3235 "bgp graceful-restart rib-stale-time (1-3600)",
3236 "BGP specific commands\n"
3237 "Graceful restart configuration parameters\n"
3238 "Specify the stale route removal timer in rib\n"
3239 "Delay value (seconds)\n")
3240 {
3241 VTY_DECLVAR_CONTEXT(bgp, bgp);
3242 int idx_number = 3;
3243 uint32_t stale_time;
3244
3245 stale_time = strtoul(argv[idx_number]->arg, NULL, 10);
3246 bgp->rib_stale_time = stale_time;
3247 /* Send the stale timer update message to RIB */
3248 if (bgp_zebra_stale_timer_update(bgp))
3249 return CMD_WARNING;
3250
3251 return CMD_SUCCESS;
3252 }
3253
3254 DEFUN (no_bgp_graceful_restart_rib_stale_time,
3255 no_bgp_graceful_restart_rib_stale_time_cmd,
3256 "no bgp graceful-restart rib-stale-time [(1-3600)]",
3257 NO_STR
3258 "BGP specific commands\n"
3259 "Graceful restart configuration parameters\n"
3260 "Specify the stale route removal timer in rib\n"
3261 "Delay value (seconds)\n")
3262 {
3263 VTY_DECLVAR_CONTEXT(bgp, bgp);
3264
3265 bgp->rib_stale_time = BGP_DEFAULT_RIB_STALE_TIME;
3266 /* Send the stale timer update message to RIB */
3267 if (bgp_zebra_stale_timer_update(bgp))
3268 return CMD_WARNING;
3269
3270 return CMD_SUCCESS;
3271 }
3272
3273 static inline int bgp_initiate_graceful_shut_unshut(struct bgp *bgp,
3274 char *errmsg,
3275 size_t errmsg_len)
3276 {
3277 bgp_static_redo_import_check(bgp);
3278 bgp_redistribute_redo(bgp);
3279 if (bgp_clear_star_soft_out(bgp->name, errmsg, errmsg_len) < 0)
3280 return -1;
3281 if (bgp_clear_star_soft_in(bgp->name, errmsg, errmsg_len) < 0)
3282 return -1;
3283
3284 return 0;
3285 }
3286
3287 static int bgp_global_graceful_shutdown_config_vty(struct vty *vty)
3288 {
3289 struct listnode *node, *nnode;
3290 struct bgp *bgp;
3291 bool vrf_cfg = false;
3292 char errmsg[BUFSIZ] = {'\0'};
3293
3294 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3295 return CMD_SUCCESS;
3296
3297 /* See if graceful-shutdown is set per-vrf and warn user to delete */
3298 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3299 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3300 vty_out(vty,
3301 "%% graceful-shutdown configuration found in vrf %s\n",
3302 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT ?
3303 VRF_DEFAULT_NAME : bgp->name);
3304 vrf_cfg = true;
3305 }
3306 }
3307
3308 if (vrf_cfg) {
3309 vty_out(vty,
3310 "%%Failed: global graceful-shutdown not permitted\n");
3311 return CMD_WARNING;
3312 }
3313
3314 /* Set flag globally */
3315 SET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3316
3317 /* Initiate processing for all BGP instances. */
3318 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3319 if (bgp_initiate_graceful_shut_unshut(bgp, errmsg,
3320 sizeof(errmsg))
3321 < 0)
3322 if (strlen(errmsg))
3323 vty_out(vty, "%s\n", errmsg);
3324 }
3325
3326 return CMD_SUCCESS;
3327 }
3328
3329 static int bgp_global_graceful_shutdown_deconfig_vty(struct vty *vty)
3330 {
3331 struct listnode *node, *nnode;
3332 struct bgp *bgp;
3333 char errmsg[BUFSIZ] = {'\0'};
3334
3335 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3336 return CMD_SUCCESS;
3337
3338 /* Unset flag globally */
3339 UNSET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3340
3341 /* Initiate processing for all BGP instances. */
3342 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3343 if (bgp_initiate_graceful_shut_unshut(bgp, errmsg,
3344 sizeof(errmsg))
3345 < 0)
3346 if (strlen(errmsg))
3347 vty_out(vty, "%s\n", errmsg);
3348 }
3349
3350 return CMD_SUCCESS;
3351 }
3352
3353 /* "bgp graceful-shutdown" configuration */
3354 DEFUN (bgp_graceful_shutdown,
3355 bgp_graceful_shutdown_cmd,
3356 "bgp graceful-shutdown",
3357 BGP_STR
3358 "Graceful shutdown parameters\n")
3359 {
3360 if (vty->node == CONFIG_NODE)
3361 return bgp_global_graceful_shutdown_config_vty(vty);
3362
3363 nb_cli_enqueue_change(vty, "./global/graceful-shutdown/enable",
3364 NB_OP_MODIFY, "true");
3365
3366 return nb_cli_apply_changes(vty, NULL);
3367 }
3368
3369 DEFUN_YANG (no_bgp_graceful_shutdown,
3370 no_bgp_graceful_shutdown_cmd,
3371 "no bgp graceful-shutdown",
3372 NO_STR
3373 BGP_STR
3374 "Graceful shutdown parameters\n")
3375 {
3376 if (vty->node == CONFIG_NODE)
3377 return bgp_global_graceful_shutdown_deconfig_vty(vty);
3378
3379 nb_cli_enqueue_change(vty, "./global/graceful-shutdown/enable",
3380 NB_OP_MODIFY, "false");
3381
3382 return nb_cli_apply_changes(vty, NULL);
3383 }
3384
3385 void cli_show_router_bgp_graceful_shutdown(struct vty *vty,
3386 struct lyd_node *dnode,
3387 bool show_defaults)
3388 {
3389 if (yang_dnode_get_bool(dnode, NULL))
3390 vty_out(vty, " bgp graceful-shutdown\n");
3391 }
3392
3393 /* "bgp fast-external-failover" configuration. */
3394 DEFUN_YANG (bgp_fast_external_failover,
3395 bgp_fast_external_failover_cmd,
3396 "bgp fast-external-failover",
3397 BGP_STR
3398 "Immediately reset session if a link to a directly connected external peer goes down\n")
3399 {
3400 nb_cli_enqueue_change(vty, "./global/fast-external-failover",
3401 NB_OP_MODIFY, "false");
3402
3403 return nb_cli_apply_changes(vty, NULL);
3404 }
3405
3406 DEFUN_YANG (no_bgp_fast_external_failover,
3407 no_bgp_fast_external_failover_cmd,
3408 "no bgp fast-external-failover",
3409 NO_STR
3410 BGP_STR
3411 "Immediately reset session if a link to a directly connected external peer goes down\n")
3412 {
3413 nb_cli_enqueue_change(vty, "./global/fast-external-failover",
3414 NB_OP_MODIFY, "true");
3415
3416 return nb_cli_apply_changes(vty, NULL);
3417 }
3418
3419 void cli_show_router_bgp_fast_external_failover(struct vty *vty,
3420 struct lyd_node *dnode,
3421 bool show_defaults)
3422 {
3423 if (!yang_dnode_get_bool(dnode, NULL))
3424 vty_out(vty, " no bgp fast-external-failover\n");
3425 }
3426
3427 /* "bgp bestpath compare-routerid" configuration. */
3428 DEFUN_YANG(bgp_bestpath_compare_router_id,
3429 bgp_bestpath_compare_router_id_cmd,
3430 "bgp bestpath compare-routerid",
3431 "BGP specific commands\n"
3432 "Change the default bestpath selection\n"
3433 "Compare router-id for identical EBGP paths\n")
3434 {
3435 nb_cli_enqueue_change(
3436 vty,
3437 "./global/route-selection-options/external-compare-router-id",
3438 NB_OP_MODIFY, "true");
3439
3440 return nb_cli_apply_changes(vty, NULL);
3441 }
3442
3443 DEFUN_YANG(no_bgp_bestpath_compare_router_id,
3444 no_bgp_bestpath_compare_router_id_cmd,
3445 "no bgp bestpath compare-routerid",
3446 NO_STR
3447 "BGP specific commands\n"
3448 "Change the default bestpath selection\n"
3449 "Compare router-id for identical EBGP paths\n")
3450 {
3451 nb_cli_enqueue_change(
3452 vty,
3453 "./global/route-selection-options/external-compare-router-id",
3454 NB_OP_MODIFY, "false");
3455
3456 return nb_cli_apply_changes(vty, NULL);
3457 }
3458
3459 /* "bgp bestpath as-path ignore" configuration. */
3460 DEFUN_YANG(bgp_bestpath_aspath_ignore,
3461 bgp_bestpath_aspath_ignore_cmd,
3462 "bgp bestpath as-path ignore",
3463 "BGP specific commands\n"
3464 "Change the default bestpath selection\n"
3465 "AS-path attribute\n"
3466 "Ignore as-path length in selecting a route\n")
3467 {
3468 nb_cli_enqueue_change(
3469 vty, "./global/route-selection-options/ignore-as-path-length",
3470 NB_OP_MODIFY, "true");
3471
3472 return nb_cli_apply_changes(vty, NULL);
3473 }
3474
3475 DEFUN_YANG(no_bgp_bestpath_aspath_ignore,
3476 no_bgp_bestpath_aspath_ignore_cmd,
3477 "no bgp bestpath as-path ignore",
3478 NO_STR
3479 "BGP specific commands\n"
3480 "Change the default bestpath selection\n"
3481 "AS-path attribute\n"
3482 "Ignore as-path length in selecting a route\n")
3483 {
3484 nb_cli_enqueue_change(
3485 vty, "./global/route-selection-options/ignore-as-path-length",
3486 NB_OP_MODIFY, "false");
3487
3488 return nb_cli_apply_changes(vty, NULL);
3489 }
3490
3491 /* "bgp bestpath as-path confed" configuration. */
3492 DEFUN_YANG (bgp_bestpath_aspath_confed,
3493 bgp_bestpath_aspath_confed_cmd,
3494 "bgp bestpath as-path confed",
3495 "BGP specific commands\n"
3496 "Change the default bestpath selection\n"
3497 "AS-path attribute\n"
3498 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3499 {
3500 nb_cli_enqueue_change(vty,
3501 "./global/route-selection-options/aspath-confed",
3502 NB_OP_MODIFY, "true");
3503
3504 return nb_cli_apply_changes(vty, NULL);
3505 }
3506
3507 DEFUN_YANG (no_bgp_bestpath_aspath_confed,
3508 no_bgp_bestpath_aspath_confed_cmd,
3509 "no bgp bestpath as-path confed",
3510 NO_STR
3511 "BGP specific commands\n"
3512 "Change the default bestpath selection\n"
3513 "AS-path attribute\n"
3514 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3515 {
3516 nb_cli_enqueue_change(vty,
3517 "./global/route-selection-options/aspath-confed",
3518 NB_OP_MODIFY, "false");
3519
3520 return nb_cli_apply_changes(vty, NULL);
3521 }
3522
3523 /* "bgp bestpath as-path multipath-relax" configuration. */
3524 DEFUN_YANG (bgp_bestpath_aspath_multipath_relax,
3525 bgp_bestpath_aspath_multipath_relax_cmd,
3526 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
3527 "BGP specific commands\n"
3528 "Change the default bestpath selection\n"
3529 "AS-path attribute\n"
3530 "Allow load sharing across routes that have different AS paths (but same length)\n"
3531 "Generate an AS_SET\n"
3532 "Do not generate an AS_SET\n")
3533 {
3534 int idx = 0;
3535
3536 nb_cli_enqueue_change(
3537 vty, "./global/route-selection-options/allow-multiple-as",
3538 NB_OP_MODIFY, "true");
3539 if (argv_find(argv, argc, "as-set", &idx))
3540 nb_cli_enqueue_change(
3541 vty,
3542 "./global/route-selection-options/multi-path-as-set",
3543 NB_OP_MODIFY, "true");
3544 else
3545 nb_cli_enqueue_change(
3546 vty,
3547 "./global/route-selection-options/multi-path-as-set",
3548 NB_OP_MODIFY, "false");
3549
3550 return nb_cli_apply_changes(vty, NULL);
3551 }
3552
3553 DEFUN_YANG (no_bgp_bestpath_aspath_multipath_relax,
3554 no_bgp_bestpath_aspath_multipath_relax_cmd,
3555 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
3556 NO_STR
3557 "BGP specific commands\n"
3558 "Change the default bestpath selection\n"
3559 "AS-path attribute\n"
3560 "Allow load sharing across routes that have different AS paths (but same length)\n"
3561 "Generate an AS_SET\n"
3562 "Do not generate an AS_SET\n")
3563 {
3564 nb_cli_enqueue_change(
3565 vty, "./global/route-selection-options/allow-multiple-as",
3566 NB_OP_MODIFY, "false");
3567 nb_cli_enqueue_change(
3568 vty, "./global/route-selection-options/multi-path-as-set",
3569 NB_OP_MODIFY, "false");
3570
3571 return nb_cli_apply_changes(vty, NULL);
3572 }
3573
3574 /* "bgp log-neighbor-changes" configuration. */
3575 DEFUN_YANG(bgp_log_neighbor_changes,
3576 bgp_log_neighbor_changes_cmd,
3577 "bgp log-neighbor-changes",
3578 "BGP specific commands\n"
3579 "Log neighbor up/down and reset reason\n")
3580 {
3581 nb_cli_enqueue_change(
3582 vty, "./global/global-neighbor-config/log-neighbor-changes",
3583 NB_OP_MODIFY, "true");
3584
3585 return nb_cli_apply_changes(vty, NULL);
3586 }
3587
3588 DEFUN_YANG(no_bgp_log_neighbor_changes,
3589 no_bgp_log_neighbor_changes_cmd,
3590 "no bgp log-neighbor-changes",
3591 NO_STR
3592 "BGP specific commands\n"
3593 "Log neighbor up/down and reset reason\n")
3594 {
3595 nb_cli_enqueue_change(
3596 vty, "./global/global-neighbor-config/log-neighbor-changes",
3597 NB_OP_MODIFY, "false");
3598
3599 return nb_cli_apply_changes(vty, NULL);
3600 }
3601
3602 /* "bgp bestpath med" configuration. */
3603 DEFUN_YANG (bgp_bestpath_med,
3604 bgp_bestpath_med_cmd,
3605 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
3606 "BGP specific commands\n"
3607 "Change the default bestpath selection\n"
3608 "MED attribute\n"
3609 "Compare MED among confederation paths\n"
3610 "Treat missing MED as the least preferred one\n"
3611 "Treat missing MED as the least preferred one\n"
3612 "Compare MED among confederation paths\n")
3613 {
3614 int idx = 0;
3615 bool confed = false;
3616 bool worst_med = false;
3617
3618
3619 if (argv_find(argv, argc, "confed", &idx))
3620 confed = true;
3621
3622 nb_cli_enqueue_change(vty,
3623 "./global/route-selection-options/confed-med",
3624 NB_OP_MODIFY, confed ? "true" : "false");
3625
3626 idx = 0;
3627 if (argv_find(argv, argc, "missing-as-worst", &idx))
3628 worst_med = true;
3629
3630 nb_cli_enqueue_change(
3631 vty, "./global/route-selection-options/missing-as-worst-med",
3632 NB_OP_MODIFY, worst_med ? "true" : "false");
3633
3634 return nb_cli_apply_changes(vty, NULL);
3635 }
3636
3637 DEFUN_YANG (no_bgp_bestpath_med,
3638 no_bgp_bestpath_med_cmd,
3639 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
3640 NO_STR
3641 "BGP specific commands\n"
3642 "Change the default bestpath selection\n"
3643 "MED attribute\n"
3644 "Compare MED among confederation paths\n"
3645 "Treat missing MED as the least preferred one\n"
3646 "Treat missing MED as the least preferred one\n"
3647 "Compare MED among confederation paths\n")
3648 {
3649 int idx = 0;
3650
3651 if (argv_find(argv, argc, "confed", &idx))
3652 nb_cli_enqueue_change(
3653 vty, "./global/route-selection-options/confed-med",
3654 NB_OP_MODIFY, "false");
3655
3656 idx = 0;
3657 if (argv_find(argv, argc, "missing-as-worst", &idx))
3658 nb_cli_enqueue_change(
3659 vty,
3660 "./global/route-selection-options/missing-as-worst-med",
3661 NB_OP_MODIFY, "false");
3662
3663 return nb_cli_apply_changes(vty, NULL);
3664 }
3665
3666 /* "bgp bestpath bandwidth" configuration. */
3667 DEFPY (bgp_bestpath_bw,
3668 bgp_bestpath_bw_cmd,
3669 "bgp bestpath bandwidth <ignore|skip-missing|default-weight-for-missing>$bw_cfg",
3670 "BGP specific commands\n"
3671 "Change the default bestpath selection\n"
3672 "Link Bandwidth attribute\n"
3673 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3674 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3675 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3676 {
3677 VTY_DECLVAR_CONTEXT(bgp, bgp);
3678 afi_t afi;
3679 safi_t safi;
3680
3681 if (!bw_cfg) {
3682 vty_out(vty, "%% Bandwidth configuration must be specified\n");
3683 return CMD_ERR_INCOMPLETE;
3684 }
3685 if (!strcmp(bw_cfg, "ignore"))
3686 bgp->lb_handling = BGP_LINK_BW_IGNORE_BW;
3687 else if (!strcmp(bw_cfg, "skip-missing"))
3688 bgp->lb_handling = BGP_LINK_BW_SKIP_MISSING;
3689 else if (!strcmp(bw_cfg, "default-weight-for-missing"))
3690 bgp->lb_handling = BGP_LINK_BW_DEFWT_4_MISSING;
3691 else
3692 return CMD_ERR_NO_MATCH;
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
3701 return CMD_SUCCESS;
3702 }
3703
3704 DEFPY (no_bgp_bestpath_bw,
3705 no_bgp_bestpath_bw_cmd,
3706 "no bgp bestpath bandwidth [<ignore|skip-missing|default-weight-for-missing>$bw_cfg]",
3707 NO_STR
3708 "BGP specific commands\n"
3709 "Change the default bestpath selection\n"
3710 "Link Bandwidth attribute\n"
3711 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3712 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3713 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3714 {
3715 VTY_DECLVAR_CONTEXT(bgp, bgp);
3716 afi_t afi;
3717 safi_t safi;
3718
3719 bgp->lb_handling = BGP_LINK_BW_ECMP;
3720
3721 /* This config is used in route install, so redo that. */
3722 FOREACH_AFI_SAFI (afi, safi) {
3723 if (!bgp_fibupd_safi(safi))
3724 continue;
3725 bgp_zebra_announce_table(bgp, afi, safi);
3726 }
3727 return CMD_SUCCESS;
3728 }
3729
3730 /* "no bgp default ipv6-unicast". */
3731 DEFUN(no_bgp_default_ipv6_unicast, no_bgp_default_ipv6_unicast_cmd,
3732 "no bgp default ipv6-unicast", NO_STR
3733 "BGP specific commands\n"
3734 "Configure BGP defaults\n"
3735 "Activate ipv6-unicast for a peer by default\n")
3736 {
3737 VTY_DECLVAR_CONTEXT(bgp, bgp);
3738 UNSET_FLAG(bgp->flags, BGP_FLAG_DEFAULT_IPV6);
3739 return CMD_SUCCESS;
3740 }
3741
3742 DEFUN(bgp_default_ipv6_unicast, bgp_default_ipv6_unicast_cmd,
3743 "bgp default ipv6-unicast",
3744 "BGP specific commands\n"
3745 "Configure BGP defaults\n"
3746 "Activate ipv6-unicast for a peer by default\n")
3747 {
3748 VTY_DECLVAR_CONTEXT(bgp, bgp);
3749 SET_FLAG(bgp->flags, BGP_FLAG_DEFAULT_IPV6);
3750 return CMD_SUCCESS;
3751 }
3752
3753 /* "no bgp default ipv4-unicast". */
3754 DEFUN (no_bgp_default_ipv4_unicast,
3755 no_bgp_default_ipv4_unicast_cmd,
3756 "no bgp default ipv4-unicast",
3757 NO_STR
3758 "BGP specific commands\n"
3759 "Configure BGP defaults\n"
3760 "Activate ipv4-unicast for a peer by default\n")
3761 {
3762 VTY_DECLVAR_CONTEXT(bgp, bgp);
3763 SET_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4);
3764 return CMD_SUCCESS;
3765 }
3766
3767 DEFUN (bgp_default_ipv4_unicast,
3768 bgp_default_ipv4_unicast_cmd,
3769 "bgp default ipv4-unicast",
3770 "BGP specific commands\n"
3771 "Configure BGP defaults\n"
3772 "Activate ipv4-unicast for a peer by default\n")
3773 {
3774 VTY_DECLVAR_CONTEXT(bgp, bgp);
3775 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4);
3776 return CMD_SUCCESS;
3777 }
3778
3779 /* Display hostname in certain command outputs */
3780 DEFUN_YANG (bgp_default_show_hostname,
3781 bgp_default_show_hostname_cmd,
3782 "bgp default show-hostname",
3783 "BGP specific commands\n"
3784 "Configure BGP defaults\n"
3785 "Show hostname in certain command outputs\n")
3786 {
3787 nb_cli_enqueue_change(vty, "./global/show-hostname", NB_OP_MODIFY,
3788 "true");
3789
3790 return nb_cli_apply_changes(vty, NULL);
3791 }
3792
3793 DEFUN_YANG(no_bgp_default_show_hostname,
3794 no_bgp_default_show_hostname_cmd,
3795 "no bgp default show-hostname",
3796 NO_STR
3797 "BGP specific commands\n"
3798 "Configure BGP defaults\n"
3799 "Show hostname in certain command outputs\n")
3800 {
3801 nb_cli_enqueue_change(vty, "./global/show-hostname", NB_OP_MODIFY,
3802 "false");
3803
3804 return nb_cli_apply_changes(vty, NULL);
3805 }
3806
3807 void cli_show_router_bgp_show_hostname(struct vty *vty, struct lyd_node *dnode,
3808 bool show_defaults)
3809 {
3810 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_SHOW_HOSTNAME)
3811 vty_out(vty, " bgp default show-hostname\n");
3812 }
3813
3814 /* Display hostname in certain command outputs */
3815 DEFUN_YANG(bgp_default_show_nexthop_hostname,
3816 bgp_default_show_nexthop_hostname_cmd,
3817 "bgp default show-nexthop-hostname",
3818 "BGP specific commands\n"
3819 "Configure BGP defaults\n"
3820 "Show hostname for nexthop in certain command outputs\n")
3821 {
3822 nb_cli_enqueue_change(vty, "./global/show-nexthop-hostname",
3823 NB_OP_MODIFY, "true");
3824
3825 return nb_cli_apply_changes(vty, NULL);
3826 }
3827
3828 DEFUN (no_bgp_default_show_nexthop_hostname,
3829 no_bgp_default_show_nexthop_hostname_cmd,
3830 "no bgp default show-nexthop-hostname",
3831 NO_STR
3832 "BGP specific commands\n"
3833 "Configure BGP defaults\n"
3834 "Show hostname for nexthop in certain command outputs\n")
3835 {
3836 nb_cli_enqueue_change(vty, "./global/show-nexthop-hostname",
3837 NB_OP_MODIFY, "false");
3838
3839 return nb_cli_apply_changes(vty, NULL);
3840 }
3841
3842 void cli_show_router_bgp_show_nexthop_hostname(struct vty *vty,
3843 struct lyd_node *dnode,
3844 bool show_defaults)
3845 {
3846 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_SHOW_HOSTNAME)
3847 vty_out(vty, " bgp default show-nexthop-hostname\n");
3848 }
3849
3850 /* "bgp network import-check" configuration. */
3851 DEFUN_YANG(bgp_network_import_check,
3852 bgp_network_import_check_cmd,
3853 "bgp network import-check",
3854 "BGP specific commands\n"
3855 "BGP network command\n"
3856 "Check BGP network route exists in IGP\n")
3857 {
3858 nb_cli_enqueue_change(vty, "./global/import-check", NB_OP_MODIFY,
3859 "true");
3860
3861 return nb_cli_apply_changes(vty, NULL);
3862 }
3863
3864 ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
3865 "bgp network import-check exact",
3866 "BGP specific commands\n"
3867 "BGP network command\n"
3868 "Check BGP network route exists in IGP\n"
3869 "Match route precisely\n")
3870
3871 DEFUN_YANG(no_bgp_network_import_check,
3872 no_bgp_network_import_check_cmd,
3873 "no bgp network import-check",
3874 NO_STR
3875 "BGP specific commands\n"
3876 "BGP network command\n"
3877 "Check BGP network route exists in IGP\n")
3878 {
3879 nb_cli_enqueue_change(vty, "./global/import-check", NB_OP_MODIFY,
3880 "false");
3881
3882 return nb_cli_apply_changes(vty, NULL);
3883 }
3884
3885 void cli_show_router_bgp_import_check(struct vty *vty, struct lyd_node *dnode,
3886 bool show_defaults)
3887 {
3888 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_IMPORT_CHECK)
3889 vty_out(vty, " bgp network import-check\n");
3890 }
3891
3892 DEFUN_YANG(bgp_default_local_preference,
3893 bgp_default_local_preference_cmd,
3894 "bgp default local-preference (0-4294967295)",
3895 "BGP specific commands\n"
3896 "Configure BGP defaults\n"
3897 "local preference (higher=more preferred)\n"
3898 "Configure default local preference value\n")
3899 {
3900 int idx_number = 3;
3901
3902 nb_cli_enqueue_change(vty, "./global/local-pref", NB_OP_MODIFY,
3903 argv[idx_number]->arg);
3904
3905 return nb_cli_apply_changes(vty, NULL);
3906 }
3907
3908 DEFUN_YANG(no_bgp_default_local_preference,
3909 no_bgp_default_local_preference_cmd,
3910 "no bgp default local-preference [(0-4294967295)]",
3911 NO_STR
3912 "BGP specific commands\n"
3913 "Configure BGP defaults\n"
3914 "local preference (higher=more preferred)\n"
3915 "Configure default local preference value\n")
3916 {
3917 nb_cli_enqueue_change(vty, "./global/local-pref", NB_OP_MODIFY, NULL);
3918
3919 return nb_cli_apply_changes(vty, NULL);
3920 }
3921
3922 void cli_show_router_bgp_local_pref(struct vty *vty, struct lyd_node *dnode,
3923 bool show_defaults)
3924 {
3925 vty_out(vty, " bgp default local-preference %u\n",
3926 yang_dnode_get_uint32(dnode, NULL));
3927 }
3928
3929
3930 DEFUN_YANG(bgp_default_subgroup_pkt_queue_max,
3931 bgp_default_subgroup_pkt_queue_max_cmd,
3932 "bgp default subgroup-pkt-queue-max (20-100)",
3933 "BGP specific commands\n"
3934 "Configure BGP defaults\n"
3935 "subgroup-pkt-queue-max\n"
3936 "Configure subgroup packet queue max\n")
3937 {
3938 int idx_number = 3;
3939
3940 nb_cli_enqueue_change(
3941 vty,
3942 "./global/global-update-group-config/subgroup-pkt-queue-size",
3943 NB_OP_MODIFY, argv[idx_number]->arg);
3944
3945 return nb_cli_apply_changes(vty, NULL);
3946 }
3947
3948 DEFUN_YANG(no_bgp_default_subgroup_pkt_queue_max,
3949 no_bgp_default_subgroup_pkt_queue_max_cmd,
3950 "no bgp default subgroup-pkt-queue-max [(20-100)]",
3951 NO_STR
3952 "BGP specific commands\n"
3953 "Configure BGP defaults\n"
3954 "subgroup-pkt-queue-max\n"
3955 "Configure subgroup packet queue max\n")
3956 {
3957 nb_cli_enqueue_change(
3958 vty,
3959 "./global/global-update-group-config/subgroup-pkt-queue-size",
3960 NB_OP_MODIFY, NULL);
3961
3962 return nb_cli_apply_changes(vty, NULL);
3963 }
3964
3965 void cli_show_router_global_update_group_config_subgroup_pkt_queue_size(
3966 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
3967 {
3968 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
3969 yang_dnode_get_uint32(dnode, NULL));
3970 }
3971
3972 DEFUN_YANG(bgp_rr_allow_outbound_policy,
3973 bgp_rr_allow_outbound_policy_cmd,
3974 "bgp route-reflector allow-outbound-policy",
3975 "BGP specific commands\n"
3976 "Allow modifications made by out route-map\n"
3977 "on ibgp neighbors\n")
3978 {
3979 nb_cli_enqueue_change(vty,
3980 "./global/route-reflector/allow-outbound-policy",
3981 NB_OP_MODIFY, "true");
3982
3983 return nb_cli_apply_changes(vty, NULL);
3984 }
3985
3986 DEFUN_YANG(no_bgp_rr_allow_outbound_policy,
3987 no_bgp_rr_allow_outbound_policy_cmd,
3988 "no bgp route-reflector allow-outbound-policy",
3989 NO_STR
3990 "BGP specific commands\n"
3991 "Allow modifications made by out route-map\n"
3992 "on ibgp neighbors\n")
3993 {
3994 nb_cli_enqueue_change(vty,
3995 "./global/route-reflector/allow-outbound-policy",
3996 NB_OP_MODIFY, "false");
3997
3998 return nb_cli_apply_changes(vty, NULL);
3999 }
4000
4001
4002 void cli_show_router_global_neighbor_config(struct vty *vty,
4003 struct lyd_node *dnode,
4004 bool show_defaults)
4005 {
4006 uint32_t write_quanta, read_quanta;
4007
4008 if (yang_dnode_get_bool(dnode, "./log-neighbor-changes"))
4009 vty_out(vty, " bgp log-neighbor-changes\n");
4010
4011 if (yang_dnode_exists(dnode, "./dynamic-neighbors-limit")) {
4012 uint32_t listen_limit = yang_dnode_get_uint32(
4013 dnode, "./dynamic-neighbors-limit");
4014 vty_out(vty, " bgp listen limit %u\n", listen_limit);
4015 }
4016
4017 write_quanta = yang_dnode_get_uint32(
4018 dnode, "./packet-quanta-config/wpkt-quanta");
4019 if (write_quanta != BGP_WRITE_PACKET_MAX)
4020 vty_out(vty, " write-quanta %d\n", write_quanta);
4021
4022 read_quanta = yang_dnode_get_uint32(
4023 dnode, "./packet-quanta-config/rpkt-quanta");
4024
4025 if (read_quanta != BGP_READ_PACKET_MAX)
4026 vty_out(vty, " read-quanta %d\n", read_quanta);
4027 }
4028
4029 DEFUN_YANG(bgp_listen_limit,
4030 bgp_listen_limit_cmd,
4031 "bgp listen limit (1-5000)",
4032 "BGP specific commands\n"
4033 "BGP Dynamic Neighbors listen commands\n"
4034 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4035 "Configure Dynamic Neighbors listen limit value\n")
4036 {
4037 int idx_number = 3;
4038
4039 nb_cli_enqueue_change(
4040 vty, "./global/global-neighbor-config/dynamic-neighbors-limit",
4041 NB_OP_MODIFY, argv[idx_number]->arg);
4042
4043 return nb_cli_apply_changes(vty, NULL);
4044 }
4045
4046 DEFUN_YANG(no_bgp_listen_limit,
4047 no_bgp_listen_limit_cmd,
4048 "no bgp listen limit [(1-5000)]",
4049 NO_STR
4050 "BGP specific commands\n"
4051 "BGP Dynamic Neighbors listen commands\n"
4052 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4053 "Configure Dynamic Neighbors listen limit value\n")
4054 {
4055 nb_cli_enqueue_change(
4056 vty, "./global/global-neighbor-config/dynamic-neighbors-limit",
4057 NB_OP_DESTROY, NULL);
4058
4059 return nb_cli_apply_changes(vty, NULL);
4060 }
4061
4062
4063 /*
4064 * Check if this listen range is already configured. Check for exact
4065 * match or overlap based on input.
4066 */
4067 static struct peer_group *listen_range_exists(struct bgp *bgp,
4068 struct prefix *range, int exact)
4069 {
4070 struct listnode *node, *nnode;
4071 struct listnode *node1, *nnode1;
4072 struct peer_group *group;
4073 struct prefix *lr;
4074 afi_t afi;
4075 int match;
4076
4077 afi = family2afi(range->family);
4078 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4079 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
4080 lr)) {
4081 if (exact)
4082 match = prefix_same(range, lr);
4083 else
4084 match = (prefix_match(range, lr)
4085 || prefix_match(lr, range));
4086 if (match)
4087 return group;
4088 }
4089 }
4090
4091 return NULL;
4092 }
4093
4094 DEFUN (bgp_listen_range,
4095 bgp_listen_range_cmd,
4096 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
4097 "BGP specific commands\n"
4098 "Configure BGP dynamic neighbors listen range\n"
4099 "Configure BGP dynamic neighbors listen range\n"
4100 NEIGHBOR_ADDR_STR
4101 "Member of the peer-group\n"
4102 "Peer-group name\n")
4103 {
4104 VTY_DECLVAR_CONTEXT(bgp, bgp);
4105 struct prefix range;
4106 struct peer_group *group, *existing_group;
4107 afi_t afi;
4108 int ret;
4109 int idx = 0;
4110
4111 argv_find(argv, argc, "A.B.C.D/M", &idx);
4112 argv_find(argv, argc, "X:X::X:X/M", &idx);
4113 char *prefix = argv[idx]->arg;
4114 argv_find(argv, argc, "PGNAME", &idx);
4115 char *peergroup = argv[idx]->arg;
4116
4117 /* Convert IP prefix string to struct prefix. */
4118 ret = str2prefix(prefix, &range);
4119 if (!ret) {
4120 vty_out(vty, "%% Malformed listen range\n");
4121 return CMD_WARNING_CONFIG_FAILED;
4122 }
4123
4124 afi = family2afi(range.family);
4125
4126 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4127 vty_out(vty,
4128 "%% Malformed listen range (link-local address)\n");
4129 return CMD_WARNING_CONFIG_FAILED;
4130 }
4131
4132 apply_mask(&range);
4133
4134 /* Check if same listen range is already configured. */
4135 existing_group = listen_range_exists(bgp, &range, 1);
4136 if (existing_group) {
4137 if (strcmp(existing_group->name, peergroup) == 0)
4138 return CMD_SUCCESS;
4139 else {
4140 vty_out(vty,
4141 "%% Same listen range is attached to peer-group %s\n",
4142 existing_group->name);
4143 return CMD_WARNING_CONFIG_FAILED;
4144 }
4145 }
4146
4147 /* Check if an overlapping listen range exists. */
4148 if (listen_range_exists(bgp, &range, 0)) {
4149 vty_out(vty,
4150 "%% Listen range overlaps with existing listen range\n");
4151 return CMD_WARNING_CONFIG_FAILED;
4152 }
4153
4154 group = peer_group_lookup(bgp, peergroup);
4155 if (!group) {
4156 vty_out(vty, "%% Configure the peer-group first\n");
4157 return CMD_WARNING_CONFIG_FAILED;
4158 }
4159
4160 ret = peer_group_listen_range_add(group, &range);
4161 return bgp_vty_return(vty, ret);
4162 }
4163
4164 DEFUN (no_bgp_listen_range,
4165 no_bgp_listen_range_cmd,
4166 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
4167 NO_STR
4168 "BGP specific commands\n"
4169 "Unconfigure BGP dynamic neighbors listen range\n"
4170 "Unconfigure BGP dynamic neighbors listen range\n"
4171 NEIGHBOR_ADDR_STR
4172 "Member of the peer-group\n"
4173 "Peer-group name\n")
4174 {
4175 VTY_DECLVAR_CONTEXT(bgp, bgp);
4176 struct prefix range;
4177 struct peer_group *group;
4178 afi_t afi;
4179 int ret;
4180 int idx = 0;
4181
4182 argv_find(argv, argc, "A.B.C.D/M", &idx);
4183 argv_find(argv, argc, "X:X::X:X/M", &idx);
4184 char *prefix = argv[idx]->arg;
4185 argv_find(argv, argc, "PGNAME", &idx);
4186 char *peergroup = argv[idx]->arg;
4187
4188 /* Convert IP prefix string to struct prefix. */
4189 ret = str2prefix(prefix, &range);
4190 if (!ret) {
4191 vty_out(vty, "%% Malformed listen range\n");
4192 return CMD_WARNING_CONFIG_FAILED;
4193 }
4194
4195 afi = family2afi(range.family);
4196
4197 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4198 vty_out(vty,
4199 "%% Malformed listen range (link-local address)\n");
4200 return CMD_WARNING_CONFIG_FAILED;
4201 }
4202
4203 apply_mask(&range);
4204
4205 group = peer_group_lookup(bgp, peergroup);
4206 if (!group) {
4207 vty_out(vty, "%% Peer-group does not exist\n");
4208 return CMD_WARNING_CONFIG_FAILED;
4209 }
4210
4211 ret = peer_group_listen_range_del(group, &range);
4212 return bgp_vty_return(vty, ret);
4213 }
4214
4215 void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
4216 {
4217 struct peer_group *group;
4218 struct listnode *node, *nnode, *rnode, *nrnode;
4219 struct prefix *range;
4220 afi_t afi;
4221
4222 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
4223 vty_out(vty, " bgp listen limit %d\n",
4224 bgp->dynamic_neighbors_limit);
4225
4226 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4227 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
4228 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
4229 nrnode, range)) {
4230 vty_out(vty,
4231 " bgp listen range %pFX peer-group %s\n",
4232 range, group->name);
4233 }
4234 }
4235 }
4236 }
4237
4238
4239 DEFUN_YANG(bgp_disable_connected_route_check,
4240 bgp_disable_connected_route_check_cmd,
4241 "bgp disable-ebgp-connected-route-check",
4242 "BGP specific commands\n"
4243 "Disable checking if nexthop is connected on ebgp sessions\n")
4244 {
4245 nb_cli_enqueue_change(vty,
4246 "./global/ebgp-multihop-connected-route-check",
4247 NB_OP_MODIFY, "true");
4248
4249 return nb_cli_apply_changes(vty, NULL);
4250 }
4251
4252 DEFUN_YANG(no_bgp_disable_connected_route_check,
4253 no_bgp_disable_connected_route_check_cmd,
4254 "no bgp disable-ebgp-connected-route-check",
4255 NO_STR
4256 "BGP specific commands\n"
4257 "Disable checking if nexthop is connected on ebgp sessions\n")
4258 {
4259 nb_cli_enqueue_change(vty,
4260 "./global/ebgp-multihop-connected-route-check",
4261 NB_OP_MODIFY, "false");
4262
4263 return nb_cli_apply_changes(vty, NULL);
4264 }
4265
4266 void cli_show_router_global_ebgp_multihop_connected_route_check(
4267 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
4268 {
4269 if (yang_dnode_get_bool(dnode, NULL))
4270 vty_out(vty, " bgp disable-ebgp-connected-route-check\n");
4271 }
4272
4273 DEFUN_YANG(bgp_default_shutdown,
4274 bgp_default_shutdown_cmd,
4275 "[no] bgp default shutdown",
4276 NO_STR BGP_STR
4277 "Configure BGP defaults\n"
4278 "Apply administrative shutdown to newly configured peers\n")
4279 {
4280 nb_cli_enqueue_change(vty, "./global/default-shutdown", NB_OP_MODIFY,
4281 strmatch(argv[0]->text, "no") ? "false" : "true");
4282
4283 return nb_cli_apply_changes(vty, NULL);
4284 }
4285
4286 void cli_show_router_bgp_default_shutdown(struct vty *vty,
4287 struct lyd_node *dnode,
4288 bool show_defaults)
4289 {
4290 if (yang_dnode_get_bool(dnode, NULL))
4291 vty_out(vty, " bgp default shutdown\n");
4292 }
4293
4294 DEFPY(bgp_shutdown_msg, bgp_shutdown_msg_cmd, "bgp shutdown message MSG...",
4295 BGP_STR
4296 "Administrative shutdown of the BGP instance\n"
4297 "Add a shutdown message (RFC 8203)\n"
4298 "Shutdown message\n")
4299 {
4300 char *msgstr = NULL;
4301
4302 VTY_DECLVAR_CONTEXT(bgp, bgp);
4303
4304 if (argc > 3)
4305 msgstr = argv_concat(argv, argc, 3);
4306
4307 bgp_shutdown_enable(bgp, msgstr);
4308 XFREE(MTYPE_TMP, msgstr);
4309
4310 return CMD_SUCCESS;
4311 }
4312
4313 DEFPY(bgp_shutdown, bgp_shutdown_cmd, "bgp shutdown",
4314 BGP_STR "Administrative shutdown of the BGP instance\n")
4315 {
4316 VTY_DECLVAR_CONTEXT(bgp, bgp);
4317
4318 bgp_shutdown_enable(bgp, NULL);
4319
4320 return CMD_SUCCESS;
4321 }
4322
4323 DEFPY(no_bgp_shutdown, no_bgp_shutdown_cmd, "no bgp shutdown",
4324 NO_STR BGP_STR "Administrative shutdown of the BGP instance\n")
4325 {
4326 VTY_DECLVAR_CONTEXT(bgp, bgp);
4327
4328 bgp_shutdown_disable(bgp);
4329
4330 return CMD_SUCCESS;
4331 }
4332
4333 ALIAS(no_bgp_shutdown, no_bgp_shutdown_msg_cmd,
4334 "no bgp shutdown message MSG...", NO_STR BGP_STR
4335 "Administrative shutdown of the BGP instance\n"
4336 "Add a shutdown message (RFC 8203)\n" "Shutdown message\n")
4337
4338 DEFUN_YANG(neighbor_remote_as,
4339 neighbor_remote_as_cmd,
4340 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
4341 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4342 "Specify a BGP neighbor\n" AS_STR
4343 "Internal BGP peer\n"
4344 "External BGP peer\n")
4345 {
4346 int idx_peer = 1;
4347 int idx_remote_as = 3;
4348 char base_xpath[XPATH_MAXLEN];
4349 char unnbr_xpath[XPATH_MAXLEN];
4350 char prgrp_xpath[XPATH_MAXLEN];
4351 union sockunion su;
4352 const char *as_type_str = "as-specified";
4353
4354 if (str2sockunion(argv[idx_peer]->arg, &su) < 0) {
4355 snprintf(unnbr_xpath, sizeof(unnbr_xpath),
4356 FRR_BGP_NEIGHBOR_UNNUM_XPATH, argv[idx_peer]->arg, "");
4357
4358 snprintf(prgrp_xpath, sizeof(prgrp_xpath),
4359 FRR_BGP_PEER_GROUP_XPATH, argv[idx_peer]->arg, "");
4360
4361 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
4362 VTY_CURR_XPATH, unnbr_xpath + 1)) {
4363 strlcpy(base_xpath, unnbr_xpath, sizeof(base_xpath));
4364 } else if (yang_dnode_exists(vty->candidate_config->dnode,
4365 "%s%s", VTY_CURR_XPATH,
4366 prgrp_xpath + 1)) {
4367 snprintf(base_xpath, sizeof(base_xpath),
4368 FRR_BGP_PEER_GROUP_XPATH, argv[idx_peer]->arg,
4369 "");
4370 } else {
4371 vty_out(vty,
4372 "%% Create the peer-group or interface first\n");
4373 return CMD_WARNING_CONFIG_FAILED;
4374 }
4375 } else {
4376 snprintf(base_xpath, sizeof(base_xpath),
4377 FRR_BGP_NEIGHBOR_NUM_XPATH, argv[idx_peer]->arg, "");
4378 }
4379
4380 if (argv[idx_remote_as]->arg[0] == 'i') {
4381 as_type_str = "internal";
4382 } else if (argv[idx_remote_as]->arg[0] == 'e') {
4383 as_type_str = "external";
4384 } else {
4385 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as",
4386 NB_OP_MODIFY, argv[idx_remote_as]->arg);
4387 }
4388 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as-type",
4389 NB_OP_MODIFY, as_type_str);
4390
4391 return nb_cli_apply_changes(vty, base_xpath);
4392 }
4393
4394 int peer_conf_interface_create(struct bgp *bgp, const char *conf_if,
4395 bool v6only, const char *peer_group_name,
4396 int as_type, as_t as, char *errmsg,
4397 size_t errmsg_len)
4398 {
4399 struct peer *peer;
4400 struct peer_group *group;
4401 int ret = 0;
4402
4403 group = peer_group_lookup(bgp, conf_if);
4404
4405 if (group) {
4406 snprintf(errmsg, errmsg_len,
4407 "Name conflict with peer-group \n");
4408 return -1;
4409 }
4410
4411 peer = peer_lookup_by_conf_if(bgp, conf_if);
4412 if (peer) {
4413 if (as_type != AS_UNSPECIFIED)
4414 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type);
4415 } else {
4416 peer = peer_create(NULL, conf_if, bgp, bgp->as, as, as_type,
4417 NULL);
4418
4419 if (!peer) {
4420 snprintf(errmsg, errmsg_len,
4421 "BGP failed to create peer\n");
4422 return -1;
4423 }
4424
4425 if (v6only)
4426 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
4427
4428 /* Request zebra to initiate IPv6 RAs on this interface. We do
4429 * this
4430 * any unnumbered peer in order to not worry about run-time
4431 * transitions
4432 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
4433 * address
4434 * gets deleted later etc.)
4435 */
4436 if (peer->ifp)
4437 bgp_zebra_initiate_radv(bgp, peer);
4438 }
4439
4440 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
4441 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
4442 if (v6only)
4443 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
4444 else
4445 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
4446
4447 /* v6only flag changed. Reset bgp seesion */
4448 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
4449 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
4450 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
4451 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
4452 } else
4453 bgp_session_reset(peer);
4454 }
4455
4456 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
4457 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
4458 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
4459 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
4460 }
4461
4462 if (peer_group_name) {
4463 group = peer_group_lookup(bgp, peer_group_name);
4464 if (!group) {
4465 snprintf(errmsg, errmsg_len,
4466 "Configure the peer-group first\n");
4467 return -1;
4468 }
4469
4470 ret = peer_group_bind(bgp, NULL, peer, group, &as);
4471 }
4472
4473 return bgp_nb_errmsg_return(errmsg, errmsg_len, ret);
4474 }
4475
4476 DEFUN_YANG(neighbor_interface_config,
4477 neighbor_interface_config_cmd,
4478 "neighbor WORD interface [peer-group PGNAME]",
4479 NEIGHBOR_STR
4480 "Interface name or neighbor tag\n"
4481 "Enable BGP on interface\n"
4482 "Member of the peer-group\n"
4483 "Peer-group name\n")
4484 {
4485 int idx_word = 1;
4486 int idx_peer_group_word = 4;
4487 char base_xpath[XPATH_MAXLEN];
4488
4489 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4490 argv[idx_word]->arg, "");
4491
4492 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
4493 if (argc > idx_peer_group_word)
4494 nb_cli_enqueue_change(vty, "./peer-group", NB_OP_MODIFY,
4495 argv[idx_peer_group_word]->arg);
4496
4497 return nb_cli_apply_changes(vty, base_xpath);
4498 }
4499
4500 DEFUN_YANG(neighbor_interface_config_v6only,
4501 neighbor_interface_config_v6only_cmd,
4502 "neighbor WORD interface v6only [peer-group PGNAME]",
4503 NEIGHBOR_STR
4504 "Interface name or neighbor tag\n"
4505 "Enable BGP on interface\n"
4506 "Enable BGP with v6 link-local only\n"
4507 "Member of the peer-group\n"
4508 "Peer-group name\n")
4509 {
4510 int idx_word = 1;
4511 int idx_peer_group_word = 5;
4512 char base_xpath[XPATH_MAXLEN];
4513
4514 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4515 argv[idx_word]->arg, "");
4516
4517 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
4518 if (argc > idx_peer_group_word)
4519 nb_cli_enqueue_change(vty, "./peer-group", NB_OP_MODIFY,
4520 argv[idx_peer_group_word]->arg);
4521
4522 nb_cli_enqueue_change(vty, "./v6only", NB_OP_MODIFY, "true");
4523
4524 return nb_cli_apply_changes(vty, base_xpath);
4525 }
4526
4527
4528 DEFUN_YANG(
4529 neighbor_interface_config_remote_as,
4530 neighbor_interface_config_remote_as_cmd,
4531 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
4532 NEIGHBOR_STR
4533 "Interface name or neighbor tag\n"
4534 "Enable BGP on interface\n"
4535 "Specify a BGP neighbor\n" AS_STR
4536 "Internal BGP peer\n"
4537 "External BGP peer\n")
4538 {
4539 int idx_word = 1;
4540 int idx_remote_as = 4;
4541 char base_xpath[XPATH_MAXLEN];
4542 const char *as_type_str = "as-specified";
4543
4544 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4545 argv[idx_word]->arg, "");
4546
4547 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
4548
4549 if (argv[idx_remote_as]->arg[0] == 'i') {
4550 as_type_str = "internal";
4551 } else if (argv[idx_remote_as]->arg[0] == 'e') {
4552 as_type_str = "external";
4553 } else {
4554 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as",
4555 NB_OP_MODIFY, argv[idx_remote_as]->arg);
4556 }
4557 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as-type",
4558 NB_OP_MODIFY, as_type_str);
4559
4560 return nb_cli_apply_changes(vty, base_xpath);
4561 }
4562
4563 DEFUN_YANG(
4564 neighbor_interface_v6only_config_remote_as,
4565 neighbor_interface_v6only_config_remote_as_cmd,
4566 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
4567 NEIGHBOR_STR
4568 "Interface name or neighbor tag\n"
4569 "Enable BGP with v6 link-local only\n"
4570 "Enable BGP on interface\n"
4571 "Specify a BGP neighbor\n" AS_STR
4572 "Internal BGP peer\n"
4573 "External BGP peer\n")
4574 {
4575 int idx_word = 1;
4576 int idx_remote_as = 5;
4577 char base_xpath[XPATH_MAXLEN];
4578 const char *as_type_str = "as-specified";
4579
4580 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4581 argv[idx_word]->arg, "");
4582
4583 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
4584
4585 nb_cli_enqueue_change(vty, "./v6only", NB_OP_MODIFY, "true");
4586
4587 if (argv[idx_remote_as]->arg[0] == 'i') {
4588 as_type_str = "internal";
4589 } else if (argv[idx_remote_as]->arg[0] == 'e') {
4590 as_type_str = "external";
4591 } else {
4592 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as",
4593 NB_OP_MODIFY, argv[idx_remote_as]->arg);
4594 }
4595 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as-type",
4596 NB_OP_MODIFY, as_type_str);
4597
4598 return nb_cli_apply_changes(vty, base_xpath);
4599 }
4600
4601 DEFUN_YANG(neighbor_peer_group, neighbor_peer_group_cmd,
4602 "neighbor WORD peer-group",
4603 NEIGHBOR_STR
4604 "Interface name or neighbor tag\n"
4605 "Configure peer-group\n")
4606 {
4607 char base_xpath[XPATH_MAXLEN];
4608 int idx_word = 1;
4609
4610 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_PEER_GROUP_XPATH,
4611 argv[idx_word]->arg, "");
4612
4613 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
4614
4615 return nb_cli_apply_changes(vty, base_xpath);
4616 }
4617
4618 DEFUN_YANG(no_neighbor,
4619 no_neighbor_cmd,
4620 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
4621 NO_STR NEIGHBOR_STR
4622 NEIGHBOR_ADDR_STR2
4623 "Specify a BGP neighbor\n" AS_STR
4624 "Internal BGP peer\n"
4625 "External BGP peer\n")
4626 {
4627 int idx_peer = 2;
4628 char base_xpath[XPATH_MAXLEN];
4629 char num_xpath[XPATH_MAXLEN];
4630 char unnbr_xpath[XPATH_MAXLEN];
4631 char prgrp_xpath[XPATH_MAXLEN];
4632 union sockunion su;
4633
4634 if (str2sockunion(argv[idx_peer]->arg, &su) == 0) {
4635 snprintf(num_xpath, sizeof(num_xpath),
4636 FRR_BGP_NEIGHBOR_NUM_XPATH, argv[idx_peer]->arg, "");
4637 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
4638 VTY_CURR_XPATH, num_xpath + 1)) {
4639 strlcpy(base_xpath, num_xpath, sizeof(base_xpath));
4640 }
4641 } else {
4642 snprintf(unnbr_xpath, sizeof(unnbr_xpath),
4643 FRR_BGP_NEIGHBOR_UNNUM_XPATH, argv[idx_peer]->arg, "");
4644
4645 snprintf(prgrp_xpath, sizeof(prgrp_xpath),
4646 FRR_BGP_PEER_GROUP_XPATH, argv[idx_peer]->arg, "");
4647
4648 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
4649 VTY_CURR_XPATH, unnbr_xpath + 1)) {
4650 strlcpy(base_xpath, unnbr_xpath, sizeof(base_xpath));
4651 } else if (yang_dnode_exists(vty->candidate_config->dnode,
4652 "%s%s", VTY_CURR_XPATH,
4653 prgrp_xpath + 1)) {
4654 strlcpy(base_xpath, prgrp_xpath, sizeof(base_xpath));
4655 } else {
4656 vty_out(vty,
4657 "%% Create the peer-group or interface first\n");
4658 return CMD_WARNING_CONFIG_FAILED;
4659 }
4660 }
4661
4662 nb_cli_enqueue_change(vty, base_xpath, NB_OP_DESTROY, NULL);
4663
4664 return nb_cli_apply_changes(vty, NULL);
4665 }
4666
4667 DEFUN_YANG(no_neighbor_interface_config,
4668 no_neighbor_interface_config_cmd,
4669 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
4670 NO_STR NEIGHBOR_STR
4671 "Interface name\n"
4672 "Configure BGP on interface\n"
4673 "Enable BGP with v6 link-local only\n"
4674 "Member of the peer-group\n"
4675 "Peer-group name\n"
4676 "Specify a BGP neighbor\n" AS_STR
4677 "Internal BGP peer\n"
4678 "External BGP peer\n")
4679 {
4680 int idx_word = 2;
4681 char base_xpath[XPATH_MAXLEN];
4682
4683 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4684 argv[idx_word]->arg, "");
4685
4686 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
4687
4688 return nb_cli_apply_changes(vty, base_xpath);
4689 }
4690
4691 DEFUN_YANG(no_neighbor_peer_group,
4692 no_neighbor_peer_group_cmd,
4693 "no neighbor WORD peer-group",
4694 NO_STR NEIGHBOR_STR
4695 "Neighbor tag\n"
4696 "Configure peer-group\n")
4697 {
4698 char base_xpath[XPATH_MAXLEN];
4699 int idx_word = 2;
4700
4701 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_PEER_GROUP_XPATH,
4702 argv[idx_word]->arg, "");
4703
4704 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
4705
4706 return nb_cli_apply_changes(vty, base_xpath);
4707 }
4708
4709 DEFUN_YANG(no_neighbor_interface_peer_group_remote_as,
4710 no_neighbor_interface_peer_group_remote_as_cmd,
4711 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
4712 NO_STR NEIGHBOR_STR
4713 "Interface name or neighbor tag\n"
4714 "Specify a BGP neighbor\n" AS_STR
4715 "Internal BGP peer\n"
4716 "External BGP peer\n")
4717 {
4718 int idx_peer = 2;
4719 char base_xpath[XPATH_MAXLEN];
4720 char unnbr_xpath[XPATH_MAXLEN];
4721 char prgrp_xpath[XPATH_MAXLEN];
4722
4723 snprintf(unnbr_xpath, sizeof(unnbr_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4724 argv[idx_peer]->arg, "");
4725
4726 snprintf(prgrp_xpath, sizeof(prgrp_xpath), FRR_BGP_PEER_GROUP_XPATH,
4727 argv[idx_peer]->arg, "");
4728
4729 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
4730 VTY_CURR_XPATH, unnbr_xpath + 1)) {
4731 strlcpy(base_xpath, unnbr_xpath, sizeof(base_xpath));
4732 } else if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
4733 VTY_CURR_XPATH, prgrp_xpath + 1)) {
4734 strlcpy(base_xpath, prgrp_xpath, sizeof(base_xpath));
4735 } else {
4736 vty_out(vty, "%% Create the peer-group or interface first\n");
4737 return CMD_WARNING_CONFIG_FAILED;
4738 }
4739
4740 strlcat(base_xpath, "/neighbor-remote-as/remote-as-type",
4741 sizeof(base_xpath));
4742
4743 nb_cli_enqueue_change(vty, base_xpath, NB_OP_DESTROY, NULL);
4744
4745 return nb_cli_apply_changes(vty, NULL);
4746 }
4747
4748 DEFUN_YANG(neighbor_local_as,
4749 neighbor_local_as_cmd,
4750 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
4751 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4752 "Specify a local-as number\n"
4753 "AS number used as local AS\n")
4754 {
4755 int idx_peer = 1;
4756 int idx_number = 3;
4757 char base_xpath[XPATH_MAXLEN];
4758
4759 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4760 sizeof(base_xpath), NULL)
4761 < 0)
4762 return CMD_WARNING_CONFIG_FAILED;
4763
4764 nb_cli_enqueue_change(vty, "./local-as/local-as", NB_OP_MODIFY,
4765 argv[idx_number]->arg);
4766
4767 return nb_cli_apply_changes(vty, base_xpath);
4768 }
4769
4770 DEFUN_YANG(
4771 neighbor_local_as_no_prepend, neighbor_local_as_no_prepend_cmd,
4772 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
4773 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4774 "Specify a local-as number\n"
4775 "AS number used as local AS\n"
4776 "Do not prepend local-as to updates from ebgp peers\n")
4777 {
4778 int idx_peer = 1;
4779 int idx_number = 3;
4780 char base_xpath[XPATH_MAXLEN];
4781
4782 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4783 sizeof(base_xpath), NULL)
4784 < 0)
4785 return CMD_WARNING_CONFIG_FAILED;
4786
4787 nb_cli_enqueue_change(vty, "./local-as/local-as", NB_OP_MODIFY,
4788 argv[idx_number]->arg);
4789 nb_cli_enqueue_change(vty, "./local-as/no-prepend", NB_OP_MODIFY,
4790 "true");
4791
4792 return nb_cli_apply_changes(vty, base_xpath);
4793 }
4794
4795 DEFUN_YANG(
4796 neighbor_local_as_no_prepend_replace_as,
4797 neighbor_local_as_no_prepend_replace_as_cmd,
4798 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
4799 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4800 "Specify a local-as number\n"
4801 "AS number used as local AS\n"
4802 "Do not prepend local-as to updates from ebgp peers\n"
4803 "Do not prepend local-as to updates from ibgp peers\n")
4804 {
4805 int idx_peer = 1;
4806 int idx_number = 3;
4807 char base_xpath[XPATH_MAXLEN];
4808
4809 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4810 sizeof(base_xpath), NULL)
4811 < 0)
4812 return CMD_WARNING_CONFIG_FAILED;
4813
4814 nb_cli_enqueue_change(vty, "./local-as/local-as", NB_OP_MODIFY,
4815 argv[idx_number]->arg);
4816 nb_cli_enqueue_change(vty, "./local-as/no-prepend", NB_OP_MODIFY,
4817 "true");
4818 nb_cli_enqueue_change(vty, "./local-as/no-replace-as", NB_OP_MODIFY,
4819 "true");
4820
4821 return nb_cli_apply_changes(vty, base_xpath);
4822 }
4823
4824 DEFUN_YANG(no_neighbor_local_as,
4825 no_neighbor_local_as_cmd,
4826 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
4827 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4828 "Specify a local-as number\n"
4829 "AS number used as local AS\n"
4830 "Do not prepend local-as to updates from ebgp peers\n"
4831 "Do not prepend local-as to updates from ibgp peers\n")
4832 {
4833 int idx_peer = 2;
4834 char base_xpath[XPATH_MAXLEN];
4835
4836 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4837 sizeof(base_xpath), NULL)
4838 < 0)
4839 return CMD_WARNING_CONFIG_FAILED;
4840
4841 nb_cli_enqueue_change(vty, "./local-as/local-as", NB_OP_DESTROY, NULL);
4842 nb_cli_enqueue_change(vty, "./local-as/no-prepend", NB_OP_MODIFY,
4843 "false");
4844 nb_cli_enqueue_change(vty, "./local-as/no-replace-as", NB_OP_MODIFY,
4845 "false");
4846
4847 return nb_cli_apply_changes(vty, base_xpath);
4848 }
4849
4850
4851 DEFUN (neighbor_solo,
4852 neighbor_solo_cmd,
4853 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
4854 NEIGHBOR_STR
4855 NEIGHBOR_ADDR_STR2
4856 "Solo peer - part of its own update group\n")
4857 {
4858 int idx_peer = 1;
4859 struct peer *peer;
4860 int ret;
4861
4862 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4863 if (!peer)
4864 return CMD_WARNING_CONFIG_FAILED;
4865
4866 ret = update_group_adjust_soloness(peer, 1);
4867 return bgp_vty_return(vty, ret);
4868 }
4869
4870 DEFUN (no_neighbor_solo,
4871 no_neighbor_solo_cmd,
4872 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
4873 NO_STR
4874 NEIGHBOR_STR
4875 NEIGHBOR_ADDR_STR2
4876 "Solo peer - part of its own update group\n")
4877 {
4878 int idx_peer = 2;
4879 struct peer *peer;
4880 int ret;
4881
4882 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4883 if (!peer)
4884 return CMD_WARNING_CONFIG_FAILED;
4885
4886 ret = update_group_adjust_soloness(peer, 0);
4887 return bgp_vty_return(vty, ret);
4888 }
4889
4890 DEFUN_YANG(neighbor_password,
4891 neighbor_password_cmd,
4892 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
4893 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4894 "Set a password\n"
4895 "The password\n")
4896 {
4897 int idx_peer = 1;
4898 int idx_line = 3;
4899 char base_xpath[XPATH_MAXLEN];
4900
4901 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4902 sizeof(base_xpath), NULL)
4903 < 0)
4904 return CMD_WARNING_CONFIG_FAILED;
4905
4906 nb_cli_enqueue_change(vty, "./password", NB_OP_MODIFY,
4907 argv[idx_line]->arg);
4908
4909 return nb_cli_apply_changes(vty, base_xpath);
4910 }
4911
4912 DEFUN_YANG(no_neighbor_password,
4913 no_neighbor_password_cmd,
4914 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
4915 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4916 "Set a password\n"
4917 "The password\n")
4918 {
4919 int idx_peer = 2;
4920 char base_xpath[XPATH_MAXLEN];
4921
4922 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4923 sizeof(base_xpath), NULL)
4924 < 0)
4925 return CMD_WARNING_CONFIG_FAILED;
4926
4927 nb_cli_enqueue_change(vty, "./password", NB_OP_DESTROY, NULL);
4928
4929 return nb_cli_apply_changes(vty, base_xpath);
4930 }
4931
4932 DEFUN_YANG(neighbor_activate,
4933 neighbor_activate_cmd,
4934 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4935 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4936 "Enable the Address Family for this Neighbor\n")
4937 {
4938 int idx_peer = 1;
4939 char base_xpath[XPATH_MAXLEN];
4940 char af_xpath[XPATH_MAXLEN];
4941 afi_t afi = bgp_node_afi(vty);
4942 safi_t safi = bgp_node_safi(vty);
4943
4944 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
4945 yang_afi_safi_value2identity(afi, safi));
4946 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4947 sizeof(base_xpath), af_xpath)
4948 < 0)
4949 return CMD_WARNING_CONFIG_FAILED;
4950
4951 nb_cli_enqueue_change(vty, "./enabled", NB_OP_MODIFY, "true");
4952
4953 return nb_cli_apply_changes(vty, base_xpath);
4954 }
4955
4956 ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
4957 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4958 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4959 "Enable the Address Family for this Neighbor\n")
4960
4961 DEFUN_YANG(no_neighbor_activate,
4962 no_neighbor_activate_cmd,
4963 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4964 NO_STR NEIGHBOR_STR
4965 NEIGHBOR_ADDR_STR2
4966 "Enable the Address Family for this Neighbor\n")
4967 {
4968 int idx_peer = 2;
4969 char base_xpath[XPATH_MAXLEN];
4970 char af_xpath[XPATH_MAXLEN];
4971 afi_t afi = bgp_node_afi(vty);
4972 safi_t safi = bgp_node_safi(vty);
4973
4974 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
4975 yang_afi_safi_value2identity(afi, safi));
4976
4977 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4978 sizeof(base_xpath), af_xpath)
4979 < 0)
4980 return CMD_WARNING_CONFIG_FAILED;
4981
4982 nb_cli_enqueue_change(vty, "./enabled", NB_OP_MODIFY, "false");
4983
4984 return nb_cli_apply_changes(vty, base_xpath);
4985 }
4986
4987 ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
4988 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4989 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4990 "Enable the Address Family for this Neighbor\n")
4991
4992 DEFUN (neighbor_set_peer_group,
4993 neighbor_set_peer_group_cmd,
4994 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
4995 NEIGHBOR_STR
4996 NEIGHBOR_ADDR_STR2
4997 "Member of the peer-group\n"
4998 "Peer-group name\n")
4999 {
5000 VTY_DECLVAR_CONTEXT(bgp, bgp);
5001 int idx_peer = 1;
5002 int idx_word = 3;
5003 int ret;
5004 as_t as;
5005 union sockunion su;
5006 struct peer *peer;
5007 struct peer_group *group;
5008
5009 ret = str2sockunion(argv[idx_peer]->arg, &su);
5010 if (ret < 0) {
5011 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
5012 if (!peer) {
5013 vty_out(vty, "%% Malformed address or name: %s\n",
5014 argv[idx_peer]->arg);
5015 return CMD_WARNING_CONFIG_FAILED;
5016 }
5017 } else {
5018 if (peer_address_self_check(bgp, &su)) {
5019 vty_out(vty,
5020 "%% Can not configure the local system as neighbor\n");
5021 return CMD_WARNING_CONFIG_FAILED;
5022 }
5023
5024 /* Disallow for dynamic neighbor. */
5025 peer = peer_lookup(bgp, &su);
5026 if (peer && peer_dynamic_neighbor(peer)) {
5027 vty_out(vty,
5028 "%% Operation not allowed on a dynamic neighbor\n");
5029 return CMD_WARNING_CONFIG_FAILED;
5030 }
5031 }
5032
5033 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5034 if (!group) {
5035 vty_out(vty, "%% Configure the peer-group first\n");
5036 return CMD_WARNING_CONFIG_FAILED;
5037 }
5038
5039 ret = peer_group_bind(bgp, &su, peer, group, &as);
5040
5041 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
5042 vty_out(vty,
5043 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
5044 as);
5045 return CMD_WARNING_CONFIG_FAILED;
5046 }
5047
5048 return bgp_vty_return(vty, ret);
5049 }
5050
5051 ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
5052 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5053 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5054 "Member of the peer-group\n"
5055 "Peer-group name\n")
5056
5057 DEFUN_YANG (no_neighbor_set_peer_group,
5058 no_neighbor_set_peer_group_cmd,
5059 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group [PGNAME]",
5060 NO_STR
5061 NEIGHBOR_STR
5062 NEIGHBOR_ADDR_STR2
5063 "Member of the peer-group\n"
5064 "Peer-group name\n")
5065 {
5066 int idx_peer = 2;
5067 char base_xpath[XPATH_MAXLEN];
5068
5069 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5070 sizeof(base_xpath), NULL)
5071 < 0)
5072 return CMD_WARNING_CONFIG_FAILED;
5073
5074 nb_cli_enqueue_change(vty, "./peer-group", NB_OP_DESTROY, NULL);
5075
5076 return nb_cli_apply_changes(vty, base_xpath);
5077 }
5078
5079 ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
5080 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group [PGNAME]",
5081 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5082 "Member of the peer-group\n"
5083 "Peer-group name\n")
5084
5085 static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
5086 uint32_t flag, int set)
5087 {
5088 int ret;
5089 struct peer *peer;
5090
5091 peer = peer_and_group_lookup_vty(vty, ip_str);
5092 if (!peer)
5093 return CMD_WARNING_CONFIG_FAILED;
5094
5095 /*
5096 * If 'neighbor <interface>', then this is for directly connected peers,
5097 * we should not accept disable-connected-check.
5098 */
5099 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
5100 vty_out(vty,
5101 "%s is directly connected peer, cannot accept disable-connected-check\n",
5102 ip_str);
5103 return CMD_WARNING_CONFIG_FAILED;
5104 }
5105
5106 if (!set && flag == PEER_FLAG_SHUTDOWN)
5107 peer_tx_shutdown_message_unset(peer);
5108
5109 if (set)
5110 ret = peer_flag_set(peer, flag);
5111 else
5112 ret = peer_flag_unset(peer, flag);
5113
5114 return bgp_vty_return(vty, ret);
5115 }
5116
5117 static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
5118 {
5119 return peer_flag_modify_vty(vty, ip_str, flag, 1);
5120 }
5121
5122 static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
5123 uint32_t flag)
5124 {
5125 return peer_flag_modify_vty(vty, ip_str, flag, 0);
5126 }
5127
5128 int peer_flag_modify_nb(struct bgp *bgp, const char *ip_str, struct peer *peer,
5129 uint32_t flag, bool set, char *errmsg,
5130 size_t errmsg_len)
5131 {
5132 int ret;
5133
5134 /*
5135 * If 'neighbor <interface>', then this is for directly connected peers,
5136 * we should not accept disable-connected-check.
5137 */
5138 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
5139 snprintf(
5140 errmsg, errmsg_len,
5141 "%s is directly connected peer, cannot accept disable-connected-check\n",
5142 ip_str);
5143 return -1;
5144 }
5145
5146 if (!set && flag == PEER_FLAG_SHUTDOWN)
5147 peer_tx_shutdown_message_unset(peer);
5148
5149 if (set)
5150 ret = peer_flag_set(peer, flag);
5151 else
5152 ret = peer_flag_unset(peer, flag);
5153
5154 return bgp_nb_errmsg_return(errmsg, errmsg_len, ret);
5155 }
5156
5157 /* neighbor passive. */
5158 DEFUN_YANG(neighbor_passive,
5159 neighbor_passive_cmd,
5160 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5161 NEIGHBOR_STR
5162 NEIGHBOR_ADDR_STR2
5163 "Don't send open messages to this neighbor\n")
5164 {
5165 int idx_peer = 1;
5166 char base_xpath[XPATH_MAXLEN];
5167
5168 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5169 sizeof(base_xpath), NULL)
5170 < 0)
5171 return CMD_WARNING_CONFIG_FAILED;
5172
5173 nb_cli_enqueue_change(vty, "./passive-mode", NB_OP_MODIFY, "true");
5174
5175 return nb_cli_apply_changes(vty, base_xpath);
5176 }
5177
5178 DEFUN_YANG(no_neighbor_passive,
5179 no_neighbor_passive_cmd,
5180 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5181 NO_STR NEIGHBOR_STR
5182 NEIGHBOR_ADDR_STR2
5183 "Don't send open messages to this neighbor\n")
5184 {
5185 int idx_peer = 2;
5186 char base_xpath[XPATH_MAXLEN];
5187
5188 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5189 sizeof(base_xpath), NULL)
5190 < 0)
5191 return CMD_WARNING_CONFIG_FAILED;
5192
5193 nb_cli_enqueue_change(vty, "./passive-mode", NB_OP_MODIFY, "false");
5194
5195 return nb_cli_apply_changes(vty, base_xpath);
5196 }
5197
5198 /* neighbor shutdown. */
5199 DEFUN_YANG(neighbor_shutdown_msg,
5200 neighbor_shutdown_msg_cmd,
5201 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5202 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5203 "Administratively shut down this neighbor\n"
5204 "Add a shutdown message (RFC 8203)\n"
5205 "Shutdown message\n")
5206 {
5207 int idx_peer = 1;
5208 char base_xpath[XPATH_MAXLEN];
5209
5210 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5211 sizeof(base_xpath), NULL)
5212 < 0)
5213 return CMD_WARNING_CONFIG_FAILED;
5214
5215 if (argc >= 5) {
5216 char *message;
5217
5218 message = argv_concat(argv, argc, 4);
5219 nb_cli_enqueue_change(vty, "./admin-shutdown/message",
5220 NB_OP_MODIFY, message);
5221 }
5222
5223 nb_cli_enqueue_change(vty, "./admin-shutdown/enable", NB_OP_MODIFY,
5224 "true");
5225
5226 return nb_cli_apply_changes(vty, base_xpath);
5227 }
5228
5229 ALIAS_YANG(neighbor_shutdown_msg, neighbor_shutdown_cmd,
5230 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5231 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5232 "Administratively shut down this neighbor\n")
5233
5234 DEFUN_YANG(no_neighbor_shutdown_msg,
5235 no_neighbor_shutdown_msg_cmd,
5236 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5237 NO_STR NEIGHBOR_STR
5238 NEIGHBOR_ADDR_STR2
5239 "Administratively shut down this neighbor\n"
5240 "Remove a shutdown message (RFC 8203)\n"
5241 "Shutdown message\n")
5242 {
5243 int idx_peer = 2;
5244 char base_xpath[XPATH_MAXLEN];
5245
5246 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5247 sizeof(base_xpath), NULL)
5248 < 0)
5249 return CMD_WARNING_CONFIG_FAILED;
5250
5251 nb_cli_enqueue_change(vty, "./admin-shutdown/enable", NB_OP_MODIFY,
5252 "false");
5253
5254 return nb_cli_apply_changes(vty, base_xpath);
5255 }
5256
5257 ALIAS_YANG(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
5258 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5259 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5260 "Administratively shut down this neighbor\n")
5261
5262 DEFUN(neighbor_shutdown_rtt,
5263 neighbor_shutdown_rtt_cmd,
5264 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt (1-65535) [count (1-255)]",
5265 NEIGHBOR_STR
5266 NEIGHBOR_ADDR_STR2
5267 "Administratively shut down this neighbor\n"
5268 "Shutdown if round-trip-time is higher than expected\n"
5269 "Round-trip-time in milliseconds\n"
5270 "Specify the number of keepalives before shutdown\n"
5271 "The number of keepalives with higher RTT to shutdown\n")
5272 {
5273 int idx_peer = 1;
5274 int idx_rtt = 4;
5275 int idx_count = 0;
5276 struct peer *peer;
5277
5278 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5279
5280 if (!peer)
5281 return CMD_WARNING_CONFIG_FAILED;
5282
5283 peer->rtt_expected = strtol(argv[idx_rtt]->arg, NULL, 10);
5284
5285 if (argv_find(argv, argc, "count", &idx_count))
5286 peer->rtt_keepalive_conf =
5287 strtol(argv[idx_count + 1]->arg, NULL, 10);
5288
5289 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5290 PEER_FLAG_RTT_SHUTDOWN);
5291 }
5292
5293 DEFUN(no_neighbor_shutdown_rtt,
5294 no_neighbor_shutdown_rtt_cmd,
5295 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt [(1-65535) [count (1-255)]]",
5296 NO_STR
5297 NEIGHBOR_STR
5298 NEIGHBOR_ADDR_STR2
5299 "Administratively shut down this neighbor\n"
5300 "Shutdown if round-trip-time is higher than expected\n"
5301 "Round-trip-time in milliseconds\n"
5302 "Specify the number of keepalives before shutdown\n"
5303 "The number of keepalives with higher RTT to shutdown\n")
5304 {
5305 int idx_peer = 2;
5306 struct peer *peer;
5307
5308 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5309
5310 if (!peer)
5311 return CMD_WARNING_CONFIG_FAILED;
5312
5313 peer->rtt_expected = 0;
5314 peer->rtt_keepalive_conf = 1;
5315
5316 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5317 PEER_FLAG_RTT_SHUTDOWN);
5318 }
5319
5320 /* neighbor capability dynamic. */
5321 DEFUN_YANG (neighbor_capability_dynamic,
5322 neighbor_capability_dynamic_cmd,
5323 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5324 NEIGHBOR_STR
5325 NEIGHBOR_ADDR_STR2
5326 "Advertise capability to the peer\n"
5327 "Advertise dynamic capability to this neighbor\n")
5328 {
5329 int idx_peer = 1;
5330 char base_xpath[XPATH_MAXLEN];
5331
5332 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5333 sizeof(base_xpath), NULL)
5334 < 0)
5335 return CMD_WARNING_CONFIG_FAILED;
5336
5337 nb_cli_enqueue_change(vty, "./capability-options/dynamic-capability",
5338 NB_OP_MODIFY, "true");
5339
5340 return nb_cli_apply_changes(vty, base_xpath);
5341 }
5342
5343 DEFUN_YANG (no_neighbor_capability_dynamic,
5344 no_neighbor_capability_dynamic_cmd,
5345 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5346 NO_STR
5347 NEIGHBOR_STR
5348 NEIGHBOR_ADDR_STR2
5349 "Advertise capability to the peer\n"
5350 "Advertise dynamic capability to this neighbor\n")
5351 {
5352 int idx_peer = 2;
5353 char base_xpath[XPATH_MAXLEN];
5354
5355 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5356 sizeof(base_xpath), NULL)
5357 < 0)
5358 return CMD_WARNING_CONFIG_FAILED;
5359
5360 nb_cli_enqueue_change(vty, "./capability-options/dynamic-capability",
5361 NB_OP_MODIFY, "false");
5362
5363 return nb_cli_apply_changes(vty, base_xpath);
5364 }
5365
5366 /* neighbor dont-capability-negotiate */
5367 DEFUN (neighbor_dont_capability_negotiate,
5368 neighbor_dont_capability_negotiate_cmd,
5369 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
5370 NEIGHBOR_STR
5371 NEIGHBOR_ADDR_STR2
5372 "Do not perform capability negotiation\n")
5373 {
5374 int idx_peer = 1;
5375 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5376 PEER_FLAG_DONT_CAPABILITY);
5377 }
5378
5379 DEFUN (no_neighbor_dont_capability_negotiate,
5380 no_neighbor_dont_capability_negotiate_cmd,
5381 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
5382 NO_STR
5383 NEIGHBOR_STR
5384 NEIGHBOR_ADDR_STR2
5385 "Do not perform capability negotiation\n")
5386 {
5387 int idx_peer = 2;
5388 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5389 PEER_FLAG_DONT_CAPABILITY);
5390 }
5391
5392 /* neighbor capability extended next hop encoding */
5393 DEFUN_YANG (neighbor_capability_enhe,
5394 neighbor_capability_enhe_cmd,
5395 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5396 NEIGHBOR_STR
5397 NEIGHBOR_ADDR_STR2
5398 "Advertise capability to the peer\n"
5399 "Advertise extended next-hop capability to the peer\n")
5400 {
5401 int idx_peer = 1;
5402 char base_xpath[XPATH_MAXLEN];
5403
5404 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5405 sizeof(base_xpath), NULL)
5406 < 0)
5407 return CMD_WARNING_CONFIG_FAILED;
5408
5409 nb_cli_enqueue_change(
5410 vty, "./capability-options/extended-nexthop-capability",
5411 NB_OP_MODIFY, "true");
5412
5413 return nb_cli_apply_changes(vty, base_xpath);
5414 }
5415
5416 DEFUN_YANG (no_neighbor_capability_enhe,
5417 no_neighbor_capability_enhe_cmd,
5418 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5419 NO_STR
5420 NEIGHBOR_STR
5421 NEIGHBOR_ADDR_STR2
5422 "Advertise capability to the peer\n"
5423 "Advertise extended next-hop capability to the peer\n")
5424 {
5425 int idx_peer = 2;
5426 char base_xpath[XPATH_MAXLEN];
5427
5428 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5429 sizeof(base_xpath), NULL)
5430 < 0)
5431 return CMD_WARNING_CONFIG_FAILED;
5432
5433 nb_cli_enqueue_change(
5434 vty, "./capability-options/extended-nexthop-capability",
5435 NB_OP_MODIFY, "false");
5436
5437 return nb_cli_apply_changes(vty, base_xpath);
5438 }
5439
5440 int peer_af_flag_modify_nb(struct peer *peer, afi_t afi, safi_t safi,
5441 uint32_t flag, int set, char *errmsg,
5442 size_t errmsg_len)
5443 {
5444 int ret;
5445
5446 if (set)
5447 ret = peer_af_flag_set(peer, afi, safi, flag);
5448 else
5449 ret = peer_af_flag_unset(peer, afi, safi, flag);
5450
5451 return bgp_nb_errmsg_return(errmsg, errmsg_len, ret);
5452 }
5453
5454 static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
5455 afi_t afi, safi_t safi, uint32_t flag,
5456 int set)
5457 {
5458 int ret;
5459 struct peer *peer;
5460
5461 peer = peer_and_group_lookup_vty(vty, peer_str);
5462 if (!peer)
5463 return CMD_WARNING_CONFIG_FAILED;
5464
5465 if (set)
5466 ret = peer_af_flag_set(peer, afi, safi, flag);
5467 else
5468 ret = peer_af_flag_unset(peer, afi, safi, flag);
5469
5470 return bgp_vty_return(vty, ret);
5471 }
5472
5473 static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
5474 afi_t afi, safi_t safi, uint32_t flag)
5475 {
5476 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
5477 }
5478
5479 static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
5480 afi_t afi, safi_t safi, uint32_t flag)
5481 {
5482 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
5483 }
5484
5485 /* neighbor capability orf prefix-list. */
5486 DEFUN (neighbor_capability_orf_prefix,
5487 neighbor_capability_orf_prefix_cmd,
5488 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5489 NEIGHBOR_STR
5490 NEIGHBOR_ADDR_STR2
5491 "Advertise capability to the peer\n"
5492 "Advertise ORF capability to the peer\n"
5493 "Advertise prefixlist ORF capability to this neighbor\n"
5494 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5495 "Capability to RECEIVE the ORF from this neighbor\n"
5496 "Capability to SEND the ORF to this neighbor\n")
5497 {
5498 int idx_send_recv = 5;
5499 char *peer_str = argv[1]->arg;
5500 struct peer *peer;
5501 afi_t afi = bgp_node_afi(vty);
5502 safi_t safi = bgp_node_safi(vty);
5503
5504 peer = peer_and_group_lookup_vty(vty, peer_str);
5505 if (!peer)
5506 return CMD_WARNING_CONFIG_FAILED;
5507
5508 if (strmatch(argv[idx_send_recv]->text, "send"))
5509 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5510 PEER_FLAG_ORF_PREFIX_SM);
5511
5512 if (strmatch(argv[idx_send_recv]->text, "receive"))
5513 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5514 PEER_FLAG_ORF_PREFIX_RM);
5515
5516 if (strmatch(argv[idx_send_recv]->text, "both"))
5517 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5518 PEER_FLAG_ORF_PREFIX_SM)
5519 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5520 PEER_FLAG_ORF_PREFIX_RM);
5521
5522 return CMD_WARNING_CONFIG_FAILED;
5523 }
5524
5525 ALIAS_HIDDEN(
5526 neighbor_capability_orf_prefix,
5527 neighbor_capability_orf_prefix_hidden_cmd,
5528 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5529 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5530 "Advertise capability to the peer\n"
5531 "Advertise ORF capability to the peer\n"
5532 "Advertise prefixlist ORF capability to this neighbor\n"
5533 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5534 "Capability to RECEIVE the ORF from this neighbor\n"
5535 "Capability to SEND the ORF to this neighbor\n")
5536
5537 DEFUN (no_neighbor_capability_orf_prefix,
5538 no_neighbor_capability_orf_prefix_cmd,
5539 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5540 NO_STR
5541 NEIGHBOR_STR
5542 NEIGHBOR_ADDR_STR2
5543 "Advertise capability to the peer\n"
5544 "Advertise ORF capability to the peer\n"
5545 "Advertise prefixlist ORF capability to this neighbor\n"
5546 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5547 "Capability to RECEIVE the ORF from this neighbor\n"
5548 "Capability to SEND the ORF to this neighbor\n")
5549 {
5550 int idx_send_recv = 6;
5551 char *peer_str = argv[2]->arg;
5552 struct peer *peer;
5553 afi_t afi = bgp_node_afi(vty);
5554 safi_t safi = bgp_node_safi(vty);
5555
5556 peer = peer_and_group_lookup_vty(vty, peer_str);
5557 if (!peer)
5558 return CMD_WARNING_CONFIG_FAILED;
5559
5560 if (strmatch(argv[idx_send_recv]->text, "send"))
5561 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5562 PEER_FLAG_ORF_PREFIX_SM);
5563
5564 if (strmatch(argv[idx_send_recv]->text, "receive"))
5565 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5566 PEER_FLAG_ORF_PREFIX_RM);
5567
5568 if (strmatch(argv[idx_send_recv]->text, "both"))
5569 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5570 PEER_FLAG_ORF_PREFIX_SM)
5571 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5572 PEER_FLAG_ORF_PREFIX_RM);
5573
5574 return CMD_WARNING_CONFIG_FAILED;
5575 }
5576
5577 ALIAS_HIDDEN(
5578 no_neighbor_capability_orf_prefix,
5579 no_neighbor_capability_orf_prefix_hidden_cmd,
5580 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5581 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5582 "Advertise capability to the peer\n"
5583 "Advertise ORF capability to the peer\n"
5584 "Advertise prefixlist ORF capability to this neighbor\n"
5585 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5586 "Capability to RECEIVE the ORF from this neighbor\n"
5587 "Capability to SEND the ORF to this neighbor\n")
5588
5589 /* neighbor next-hop-self. */
5590 DEFUN_YANG (neighbor_nexthop_self,
5591 neighbor_nexthop_self_cmd,
5592 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5593 NEIGHBOR_STR
5594 NEIGHBOR_ADDR_STR2
5595 "Disable the next hop calculation for this neighbor\n")
5596 {
5597 int idx_peer = 1;
5598 char base_xpath[XPATH_MAXLEN];
5599 char af_xpath[XPATH_MAXLEN];
5600 char attr_xpath[XPATH_MAXLEN];
5601 afi_t afi = bgp_node_afi(vty);
5602 safi_t safi = bgp_node_safi(vty);
5603
5604 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5605 yang_afi_safi_value2identity(afi, safi));
5606
5607 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5608 sizeof(base_xpath), af_xpath)
5609 < 0)
5610 return CMD_WARNING_CONFIG_FAILED;
5611
5612 snprintf(attr_xpath, sizeof(attr_xpath),
5613 "./%s/nexthop-self/next-hop-self",
5614 bgp_afi_safi_get_container_str(afi, safi));
5615
5616 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5617
5618 return nb_cli_apply_changes(vty, base_xpath);
5619 }
5620
5621 ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
5622 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5623 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5624 "Disable the next hop calculation for this neighbor\n")
5625
5626 /* neighbor next-hop-self. */
5627 DEFUN_YANG(neighbor_nexthop_self_force,
5628 neighbor_nexthop_self_force_cmd,
5629 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5630 NEIGHBOR_STR
5631 NEIGHBOR_ADDR_STR2
5632 "Disable the next hop calculation for this neighbor\n"
5633 "Set the next hop to self for reflected routes\n")
5634 {
5635 int idx_peer = 1;
5636 char base_xpath[XPATH_MAXLEN];
5637 char af_xpath[XPATH_MAXLEN];
5638 char attr_xpath[XPATH_MAXLEN];
5639 afi_t afi = bgp_node_afi(vty);
5640 safi_t safi = bgp_node_safi(vty);
5641
5642 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5643 yang_afi_safi_value2identity(afi, safi));
5644
5645 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5646 sizeof(base_xpath), af_xpath)
5647 < 0)
5648 return CMD_WARNING_CONFIG_FAILED;
5649
5650 snprintf(attr_xpath, sizeof(attr_xpath),
5651 "./%s/nexthop-self/next-hop-self-force",
5652 bgp_afi_safi_get_container_str(afi, safi));
5653
5654 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5655
5656 return nb_cli_apply_changes(vty, base_xpath);
5657 }
5658
5659 ALIAS_HIDDEN(neighbor_nexthop_self_force,
5660 neighbor_nexthop_self_force_hidden_cmd,
5661 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5662 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5663 "Disable the next hop calculation for this neighbor\n"
5664 "Set the next hop to self for reflected routes\n")
5665
5666 ALIAS_HIDDEN(neighbor_nexthop_self_force,
5667 neighbor_nexthop_self_all_hidden_cmd,
5668 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5669 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5670 "Disable the next hop calculation for this neighbor\n"
5671 "Set the next hop to self for reflected routes\n")
5672
5673 DEFUN_YANG (no_neighbor_nexthop_self,
5674 no_neighbor_nexthop_self_cmd,
5675 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5676 NO_STR
5677 NEIGHBOR_STR
5678 NEIGHBOR_ADDR_STR2
5679 "Disable the next hop calculation for this neighbor\n")
5680 {
5681 int idx_peer = 2;
5682 char base_xpath[XPATH_MAXLEN];
5683 char af_xpath[XPATH_MAXLEN];
5684 char attr_xpath[XPATH_MAXLEN];
5685 afi_t afi = bgp_node_afi(vty);
5686 safi_t safi = bgp_node_safi(vty);
5687
5688 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5689 yang_afi_safi_value2identity(afi, safi));
5690
5691 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5692 sizeof(base_xpath), af_xpath)
5693 < 0)
5694 return CMD_WARNING_CONFIG_FAILED;
5695
5696 snprintf(attr_xpath, sizeof(attr_xpath),
5697 "./%s/nexthop-self/next-hop-self",
5698 bgp_afi_safi_get_container_str(afi, safi));
5699
5700 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5701
5702 return nb_cli_apply_changes(vty, base_xpath);
5703 }
5704
5705 ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
5706 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5707 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5708 "Disable the next hop calculation for this neighbor\n")
5709
5710 DEFUN_YANG (no_neighbor_nexthop_self_force,
5711 no_neighbor_nexthop_self_force_cmd,
5712 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5713 NO_STR
5714 NEIGHBOR_STR
5715 NEIGHBOR_ADDR_STR2
5716 "Disable the next hop calculation for this neighbor\n"
5717 "Set the next hop to self for reflected routes\n")
5718 {
5719 int idx_peer = 2;
5720 char base_xpath[XPATH_MAXLEN];
5721 char af_xpath[XPATH_MAXLEN];
5722 char attr_xpath[XPATH_MAXLEN];
5723 afi_t afi = bgp_node_afi(vty);
5724 safi_t safi = bgp_node_safi(vty);
5725
5726 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5727 yang_afi_safi_value2identity(afi, safi));
5728
5729 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5730 sizeof(base_xpath), af_xpath)
5731 < 0)
5732 return CMD_WARNING_CONFIG_FAILED;
5733
5734 snprintf(attr_xpath, sizeof(attr_xpath),
5735 "./%s/nexthop-self/next-hop-self-force",
5736 bgp_afi_safi_get_container_str(afi, safi));
5737
5738 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5739
5740 return nb_cli_apply_changes(vty, base_xpath);
5741 }
5742
5743 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5744 no_neighbor_nexthop_self_force_hidden_cmd,
5745 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5746 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5747 "Disable the next hop calculation for this neighbor\n"
5748 "Set the next hop to self for reflected routes\n")
5749
5750 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5751 no_neighbor_nexthop_self_all_hidden_cmd,
5752 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5753 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5754 "Disable the next hop calculation for this neighbor\n"
5755 "Set the next hop to self for reflected routes\n")
5756
5757 /* neighbor as-override */
5758 DEFUN_YANG (neighbor_as_override,
5759 neighbor_as_override_cmd,
5760 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5761 NEIGHBOR_STR
5762 NEIGHBOR_ADDR_STR2
5763 "Override ASNs in outbound updates if aspath equals remote-as\n")
5764 {
5765 int idx_peer = 1;
5766 char base_xpath[XPATH_MAXLEN];
5767 char af_xpath[XPATH_MAXLEN];
5768 char attr_xpath[XPATH_MAXLEN];
5769 afi_t afi = bgp_node_afi(vty);
5770 safi_t safi = bgp_node_safi(vty);
5771
5772 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5773 yang_afi_safi_value2identity(afi, safi));
5774
5775 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5776 sizeof(base_xpath), af_xpath)
5777 < 0)
5778 return CMD_WARNING_CONFIG_FAILED;
5779
5780 snprintf(attr_xpath, sizeof(attr_xpath),
5781 "./%s/as-path-options/replace-peer-as",
5782 bgp_afi_safi_get_container_str(afi, safi));
5783
5784 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5785
5786 return nb_cli_apply_changes(vty, base_xpath);
5787 }
5788
5789 ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
5790 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5791 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5792 "Override ASNs in outbound updates if aspath equals remote-as\n")
5793
5794 DEFUN_YANG (no_neighbor_as_override,
5795 no_neighbor_as_override_cmd,
5796 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5797 NO_STR
5798 NEIGHBOR_STR
5799 NEIGHBOR_ADDR_STR2
5800 "Override ASNs in outbound updates if aspath equals remote-as\n")
5801 {
5802 int idx_peer = 2;
5803 char base_xpath[XPATH_MAXLEN];
5804 char af_xpath[XPATH_MAXLEN];
5805 char attr_xpath[XPATH_MAXLEN];
5806 afi_t afi = bgp_node_afi(vty);
5807 safi_t safi = bgp_node_safi(vty);
5808
5809 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5810 yang_afi_safi_value2identity(afi, safi));
5811
5812 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5813 sizeof(base_xpath), af_xpath)
5814 < 0)
5815 return CMD_WARNING_CONFIG_FAILED;
5816
5817 snprintf(attr_xpath, sizeof(attr_xpath),
5818 "./%s/as-path-options/replace-peer-as",
5819 bgp_afi_safi_get_container_str(afi, safi));
5820
5821 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5822
5823 return nb_cli_apply_changes(vty, base_xpath);
5824 }
5825
5826 ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
5827 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5828 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5829 "Override ASNs in outbound updates if aspath equals remote-as\n")
5830
5831 /* neighbor remove-private-AS. */
5832 DEFUN_YANG (neighbor_remove_private_as,
5833 neighbor_remove_private_as_cmd,
5834 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5835 NEIGHBOR_STR
5836 NEIGHBOR_ADDR_STR2
5837 "Remove private ASNs in outbound updates\n")
5838 {
5839 int idx_peer = 1;
5840 char base_xpath[XPATH_MAXLEN];
5841 char af_xpath[XPATH_MAXLEN];
5842 char attr_xpath[XPATH_MAXLEN];
5843 afi_t afi = bgp_node_afi(vty);
5844 safi_t safi = bgp_node_safi(vty);
5845
5846 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5847 yang_afi_safi_value2identity(afi, safi));
5848
5849 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5850 sizeof(base_xpath), af_xpath)
5851 < 0)
5852 return CMD_WARNING_CONFIG_FAILED;
5853
5854 snprintf(attr_xpath, sizeof(attr_xpath),
5855 "./%s/private-as/remove-private-as",
5856 bgp_afi_safi_get_container_str(afi, safi));
5857
5858 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5859
5860 return nb_cli_apply_changes(vty, base_xpath);
5861 }
5862
5863 ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
5864 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5865 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5866 "Remove private ASNs in outbound updates\n")
5867
5868 DEFUN_YANG (neighbor_remove_private_as_all,
5869 neighbor_remove_private_as_all_cmd,
5870 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5871 NEIGHBOR_STR
5872 NEIGHBOR_ADDR_STR2
5873 "Remove private ASNs in outbound updates\n"
5874 "Apply to all AS numbers\n")
5875 {
5876 int idx_peer = 1;
5877 char base_xpath[XPATH_MAXLEN];
5878 char af_xpath[XPATH_MAXLEN];
5879 char attr_xpath[XPATH_MAXLEN];
5880 afi_t afi = bgp_node_afi(vty);
5881 safi_t safi = bgp_node_safi(vty);
5882
5883 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5884 yang_afi_safi_value2identity(afi, safi));
5885
5886 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5887 sizeof(base_xpath), af_xpath)
5888 < 0)
5889 return CMD_WARNING_CONFIG_FAILED;
5890
5891 snprintf(attr_xpath, sizeof(attr_xpath),
5892 "./%s/private-as/remove-private-as-all",
5893 bgp_afi_safi_get_container_str(afi, safi));
5894
5895 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5896
5897 return nb_cli_apply_changes(vty, base_xpath);
5898 }
5899
5900 ALIAS_HIDDEN(neighbor_remove_private_as_all,
5901 neighbor_remove_private_as_all_hidden_cmd,
5902 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5903 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5904 "Remove private ASNs in outbound updates\n"
5905 "Apply to all AS numbers")
5906
5907 DEFUN_YANG (neighbor_remove_private_as_replace_as,
5908 neighbor_remove_private_as_replace_as_cmd,
5909 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5910 NEIGHBOR_STR
5911 NEIGHBOR_ADDR_STR2
5912 "Remove private ASNs in outbound updates\n"
5913 "Replace private ASNs with our ASN in outbound updates\n")
5914 {
5915 int idx_peer = 1;
5916 char base_xpath[XPATH_MAXLEN];
5917 char af_xpath[XPATH_MAXLEN];
5918 char attr_xpath[XPATH_MAXLEN];
5919 afi_t afi = bgp_node_afi(vty);
5920 safi_t safi = bgp_node_safi(vty);
5921
5922 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5923 yang_afi_safi_value2identity(afi, safi));
5924
5925 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5926 sizeof(base_xpath), af_xpath)
5927 < 0)
5928 return CMD_WARNING_CONFIG_FAILED;
5929
5930 snprintf(attr_xpath, sizeof(attr_xpath),
5931 "./%s/private-as/remove-private-as-replace",
5932 bgp_afi_safi_get_container_str(afi, safi));
5933
5934 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5935
5936 return nb_cli_apply_changes(vty, base_xpath);
5937 }
5938
5939 ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
5940 neighbor_remove_private_as_replace_as_hidden_cmd,
5941 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5942 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5943 "Remove private ASNs in outbound updates\n"
5944 "Replace private ASNs with our ASN in outbound updates\n")
5945
5946 DEFUN_YANG (neighbor_remove_private_as_all_replace_as,
5947 neighbor_remove_private_as_all_replace_as_cmd,
5948 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5949 NEIGHBOR_STR
5950 NEIGHBOR_ADDR_STR2
5951 "Remove private ASNs in outbound updates\n"
5952 "Apply to all AS numbers\n"
5953 "Replace private ASNs with our ASN in outbound updates\n")
5954 {
5955 int idx_peer = 1;
5956 char base_xpath[XPATH_MAXLEN];
5957 char af_xpath[XPATH_MAXLEN];
5958 char attr_xpath[XPATH_MAXLEN];
5959 afi_t afi = bgp_node_afi(vty);
5960 safi_t safi = bgp_node_safi(vty);
5961
5962 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5963 yang_afi_safi_value2identity(afi, safi));
5964
5965 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5966 sizeof(base_xpath), af_xpath)
5967 < 0)
5968 return CMD_WARNING_CONFIG_FAILED;
5969
5970 snprintf(attr_xpath, sizeof(attr_xpath),
5971 "./%s/private-as/remove-private-as-all-replace",
5972 bgp_afi_safi_get_container_str(afi, safi));
5973
5974 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5975
5976 return nb_cli_apply_changes(vty, base_xpath);
5977 }
5978
5979 ALIAS_HIDDEN(
5980 neighbor_remove_private_as_all_replace_as,
5981 neighbor_remove_private_as_all_replace_as_hidden_cmd,
5982 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5983 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5984 "Remove private ASNs in outbound updates\n"
5985 "Apply to all AS numbers\n"
5986 "Replace private ASNs with our ASN in outbound updates\n")
5987
5988 DEFUN_YANG (no_neighbor_remove_private_as,
5989 no_neighbor_remove_private_as_cmd,
5990 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5991 NO_STR
5992 NEIGHBOR_STR
5993 NEIGHBOR_ADDR_STR2
5994 "Remove private ASNs in outbound updates\n")
5995 {
5996 int idx_peer = 2;
5997 char base_xpath[XPATH_MAXLEN];
5998 char af_xpath[XPATH_MAXLEN];
5999 char attr_xpath[XPATH_MAXLEN];
6000 afi_t afi = bgp_node_afi(vty);
6001 safi_t safi = bgp_node_safi(vty);
6002
6003 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6004 yang_afi_safi_value2identity(afi, safi));
6005
6006 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6007 sizeof(base_xpath), af_xpath)
6008 < 0)
6009 return CMD_WARNING_CONFIG_FAILED;
6010
6011 snprintf(attr_xpath, sizeof(attr_xpath),
6012 "./%s/private-as/remove-private-as",
6013 bgp_afi_safi_get_container_str(afi, safi));
6014
6015 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6016
6017 return nb_cli_apply_changes(vty, base_xpath);
6018 }
6019
6020 ALIAS_HIDDEN(no_neighbor_remove_private_as,
6021 no_neighbor_remove_private_as_hidden_cmd,
6022 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
6023 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6024 "Remove private ASNs in outbound updates\n")
6025
6026 DEFUN_YANG (no_neighbor_remove_private_as_all,
6027 no_neighbor_remove_private_as_all_cmd,
6028 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
6029 NO_STR
6030 NEIGHBOR_STR
6031 NEIGHBOR_ADDR_STR2
6032 "Remove private ASNs in outbound updates\n"
6033 "Apply to all AS numbers\n")
6034 {
6035 int idx_peer = 2;
6036 char base_xpath[XPATH_MAXLEN];
6037 char af_xpath[XPATH_MAXLEN];
6038 char attr_xpath[XPATH_MAXLEN];
6039 afi_t afi = bgp_node_afi(vty);
6040 safi_t safi = bgp_node_safi(vty);
6041
6042 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6043 yang_afi_safi_value2identity(afi, safi));
6044
6045 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6046 sizeof(base_xpath), af_xpath)
6047 < 0)
6048 return CMD_WARNING_CONFIG_FAILED;
6049
6050 snprintf(attr_xpath, sizeof(attr_xpath),
6051 "./%s/private-as/remove-private-as-all",
6052 bgp_afi_safi_get_container_str(afi, safi));
6053
6054 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6055
6056 return nb_cli_apply_changes(vty, base_xpath);
6057 }
6058
6059 ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
6060 no_neighbor_remove_private_as_all_hidden_cmd,
6061 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
6062 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6063 "Remove private ASNs in outbound updates\n"
6064 "Apply to all AS numbers\n")
6065
6066 DEFUN_YANG (no_neighbor_remove_private_as_replace_as,
6067 no_neighbor_remove_private_as_replace_as_cmd,
6068 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
6069 NO_STR
6070 NEIGHBOR_STR
6071 NEIGHBOR_ADDR_STR2
6072 "Remove private ASNs in outbound updates\n"
6073 "Replace private ASNs with our ASN in outbound updates\n")
6074 {
6075 int idx_peer = 2;
6076 char base_xpath[XPATH_MAXLEN];
6077 char af_xpath[XPATH_MAXLEN];
6078 char attr_xpath[XPATH_MAXLEN];
6079 afi_t afi = bgp_node_afi(vty);
6080 safi_t safi = bgp_node_safi(vty);
6081
6082 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6083 yang_afi_safi_value2identity(afi, safi));
6084
6085 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6086 sizeof(base_xpath), af_xpath)
6087 < 0)
6088 return CMD_WARNING_CONFIG_FAILED;
6089
6090 snprintf(attr_xpath, sizeof(attr_xpath),
6091 "./%s/private-as/remove-private-as-replace",
6092 bgp_afi_safi_get_container_str(afi, safi));
6093
6094 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6095
6096 return nb_cli_apply_changes(vty, base_xpath);
6097 }
6098
6099 ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
6100 no_neighbor_remove_private_as_replace_as_hidden_cmd,
6101 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
6102 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6103 "Remove private ASNs in outbound updates\n"
6104 "Replace private ASNs with our ASN in outbound updates\n")
6105
6106 DEFUN_YANG (no_neighbor_remove_private_as_all_replace_as,
6107 no_neighbor_remove_private_as_all_replace_as_cmd,
6108 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
6109 NO_STR
6110 NEIGHBOR_STR
6111 NEIGHBOR_ADDR_STR2
6112 "Remove private ASNs in outbound updates\n"
6113 "Apply to all AS numbers\n"
6114 "Replace private ASNs with our ASN in outbound updates\n")
6115 {
6116 int idx_peer = 2;
6117 char base_xpath[XPATH_MAXLEN];
6118 char af_xpath[XPATH_MAXLEN];
6119 char attr_xpath[XPATH_MAXLEN];
6120 afi_t afi = bgp_node_afi(vty);
6121 safi_t safi = bgp_node_safi(vty);
6122
6123 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6124 yang_afi_safi_value2identity(afi, safi));
6125
6126 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6127 sizeof(base_xpath), af_xpath)
6128 < 0)
6129 return CMD_WARNING_CONFIG_FAILED;
6130
6131 snprintf(attr_xpath, sizeof(attr_xpath),
6132 "./%s/private-as/remove-private-as-all-replace",
6133 bgp_afi_safi_get_container_str(afi, safi));
6134
6135 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6136
6137 return nb_cli_apply_changes(vty, base_xpath);
6138 }
6139
6140 ALIAS_HIDDEN(
6141 no_neighbor_remove_private_as_all_replace_as,
6142 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
6143 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
6144 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6145 "Remove private ASNs in outbound updates\n"
6146 "Apply to all AS numbers\n"
6147 "Replace private ASNs with our ASN in outbound updates\n")
6148
6149
6150 /* neighbor send-community. */
6151 DEFUN_YANG (neighbor_send_community,
6152 neighbor_send_community_cmd,
6153 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6154 NEIGHBOR_STR
6155 NEIGHBOR_ADDR_STR2
6156 "Send Community attribute to this neighbor\n")
6157 {
6158 int idx_peer = 1;
6159 char *peer_str = argv[idx_peer]->arg;
6160 char base_xpath[XPATH_MAXLEN];
6161 char af_xpath[XPATH_MAXLEN];
6162 char std_xpath[XPATH_MAXLEN];
6163 afi_t afi = bgp_node_afi(vty);
6164 safi_t safi = bgp_node_safi(vty);
6165
6166 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6167 yang_afi_safi_value2identity(afi, safi));
6168
6169 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6170 sizeof(base_xpath), af_xpath)
6171 < 0)
6172 return CMD_WARNING_CONFIG_FAILED;
6173
6174 snprintf(std_xpath, sizeof(std_xpath),
6175 "./%s/send-community/send-community",
6176 bgp_afi_safi_get_container_str(afi, safi));
6177
6178 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "true");
6179
6180 return nb_cli_apply_changes(vty, base_xpath);
6181 }
6182
6183 ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
6184 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6185 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6186 "Send Community attribute to this neighbor\n")
6187
6188 DEFUN_YANG (no_neighbor_send_community,
6189 no_neighbor_send_community_cmd,
6190 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6191 NO_STR
6192 NEIGHBOR_STR
6193 NEIGHBOR_ADDR_STR2
6194 "Send Community attribute to this neighbor\n")
6195 {
6196 int idx_peer = 2;
6197 char *peer_str = argv[idx_peer]->arg;
6198 char base_xpath[XPATH_MAXLEN];
6199 char af_xpath[XPATH_MAXLEN];
6200 char std_xpath[XPATH_MAXLEN];
6201 afi_t afi = bgp_node_afi(vty);
6202 safi_t safi = bgp_node_safi(vty);
6203
6204 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6205 yang_afi_safi_value2identity(afi, safi));
6206
6207 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6208 sizeof(base_xpath), af_xpath)
6209 < 0)
6210 return CMD_WARNING_CONFIG_FAILED;
6211
6212 snprintf(std_xpath, sizeof(std_xpath),
6213 "./%s/send-community/send-community",
6214 bgp_afi_safi_get_container_str(afi, safi));
6215
6216 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "false");
6217
6218 return nb_cli_apply_changes(vty, base_xpath);
6219 }
6220
6221 ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
6222 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6223 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6224 "Send Community attribute to this neighbor\n")
6225
6226 /* neighbor send-community extended. */
6227 DEFUN_YANG (neighbor_send_community_type,
6228 neighbor_send_community_type_cmd,
6229 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6230 NEIGHBOR_STR
6231 NEIGHBOR_ADDR_STR2
6232 "Send Community attribute to this neighbor\n"
6233 "Send Standard and Extended Community attributes\n"
6234 "Send Standard, Large and Extended Community attributes\n"
6235 "Send Extended Community attributes\n"
6236 "Send Standard Community attributes\n"
6237 "Send Large Community attributes\n")
6238 {
6239 const char *type = argv[argc - 1]->text;
6240 char *peer_str = argv[1]->arg;
6241 char base_xpath[XPATH_MAXLEN];
6242 char af_xpath[XPATH_MAXLEN];
6243 char std_xpath[XPATH_MAXLEN];
6244 char ext_xpath[XPATH_MAXLEN];
6245 char lrg_xpath[XPATH_MAXLEN];
6246 afi_t afi = bgp_node_afi(vty);
6247 safi_t safi = bgp_node_safi(vty);
6248
6249 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6250 yang_afi_safi_value2identity(afi, safi));
6251
6252 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6253 sizeof(base_xpath), af_xpath)
6254 < 0)
6255 return CMD_WARNING_CONFIG_FAILED;
6256
6257 if (strmatch(type, "standard")) {
6258 snprintf(std_xpath, sizeof(std_xpath),
6259 "./%s/send-community/send-community",
6260 bgp_afi_safi_get_container_str(afi, safi));
6261
6262 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "true");
6263 }
6264
6265 if (strmatch(type, "extended")) {
6266 snprintf(ext_xpath, sizeof(ext_xpath),
6267 "./%s/send-community/send-ext-community",
6268 bgp_afi_safi_get_container_str(afi, safi));
6269
6270 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "true");
6271 }
6272
6273 if (strmatch(type, "large")) {
6274 snprintf(lrg_xpath, sizeof(lrg_xpath),
6275 "./%s/send-community/send-large-community",
6276 bgp_afi_safi_get_container_str(afi, safi));
6277
6278 nb_cli_enqueue_change(vty, lrg_xpath, NB_OP_MODIFY, "true");
6279 }
6280
6281 if (strmatch(type, "both")) {
6282 snprintf(std_xpath, sizeof(std_xpath),
6283 "./%s/send-community/send-community",
6284 bgp_afi_safi_get_container_str(afi, safi));
6285
6286 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "true");
6287
6288 snprintf(ext_xpath, sizeof(ext_xpath),
6289 "./%s/send-community/send-ext-community",
6290 bgp_afi_safi_get_container_str(afi, safi));
6291
6292 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "true");
6293 }
6294
6295 if (strmatch(type, "all")) {
6296 snprintf(std_xpath, sizeof(std_xpath),
6297 "./%s/send-community/send-community",
6298 bgp_afi_safi_get_container_str(afi, safi));
6299
6300 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "true");
6301
6302 snprintf(ext_xpath, sizeof(ext_xpath),
6303 "./%s/send-community/send-ext-community",
6304 bgp_afi_safi_get_container_str(afi, safi));
6305
6306 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "true");
6307
6308 snprintf(lrg_xpath, sizeof(lrg_xpath),
6309 "./%s/send-community/send-large-community",
6310 bgp_afi_safi_get_container_str(afi, safi));
6311
6312 nb_cli_enqueue_change(vty, lrg_xpath, NB_OP_MODIFY, "true");
6313 }
6314
6315 return nb_cli_apply_changes(vty, base_xpath);
6316 }
6317
6318 ALIAS_HIDDEN(
6319 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
6320 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6321 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6322 "Send Community attribute to this neighbor\n"
6323 "Send Standard and Extended Community attributes\n"
6324 "Send Standard, Large and Extended Community attributes\n"
6325 "Send Extended Community attributes\n"
6326 "Send Standard Community attributes\n"
6327 "Send Large Community attributes\n")
6328
6329 DEFUN_YANG (no_neighbor_send_community_type,
6330 no_neighbor_send_community_type_cmd,
6331 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6332 NO_STR
6333 NEIGHBOR_STR
6334 NEIGHBOR_ADDR_STR2
6335 "Send Community attribute to this neighbor\n"
6336 "Send Standard and Extended Community attributes\n"
6337 "Send Standard, Large and Extended Community attributes\n"
6338 "Send Extended Community attributes\n"
6339 "Send Standard Community attributes\n"
6340 "Send Large Community attributes\n")
6341 {
6342 const char *type = argv[argc - 1]->text;
6343 char *peer_str = argv[2]->arg;
6344 char base_xpath[XPATH_MAXLEN];
6345 char af_xpath[XPATH_MAXLEN];
6346 char std_xpath[XPATH_MAXLEN];
6347 char ext_xpath[XPATH_MAXLEN];
6348 char lrg_xpath[XPATH_MAXLEN];
6349 afi_t afi = bgp_node_afi(vty);
6350 safi_t safi = bgp_node_safi(vty);
6351
6352 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6353 yang_afi_safi_value2identity(afi, safi));
6354
6355 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6356 sizeof(base_xpath), af_xpath)
6357 < 0)
6358 return CMD_WARNING_CONFIG_FAILED;
6359
6360 if (strmatch(type, "standard")) {
6361 snprintf(std_xpath, sizeof(std_xpath),
6362 "./%s/send-community/send-community",
6363 bgp_afi_safi_get_container_str(afi, safi));
6364
6365 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "false");
6366 }
6367
6368 if (strmatch(type, "extended")) {
6369 snprintf(ext_xpath, sizeof(ext_xpath),
6370 "./%s/send-community/send-ext-community",
6371 bgp_afi_safi_get_container_str(afi, safi));
6372
6373 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "false");
6374 }
6375
6376 if (strmatch(type, "large")) {
6377 snprintf(lrg_xpath, sizeof(lrg_xpath),
6378 "./%s/send-community/send-large-community",
6379 bgp_afi_safi_get_container_str(afi, safi));
6380
6381 nb_cli_enqueue_change(vty, lrg_xpath, NB_OP_MODIFY, "false");
6382 }
6383
6384 if (strmatch(type, "both")) {
6385 snprintf(std_xpath, sizeof(std_xpath),
6386 "./%s/send-community/send-community",
6387 bgp_afi_safi_get_container_str(afi, safi));
6388
6389 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "false");
6390
6391 snprintf(ext_xpath, sizeof(ext_xpath),
6392 "./%s/send-community/send-ext-community",
6393 bgp_afi_safi_get_container_str(afi, safi));
6394
6395 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "false");
6396 }
6397
6398 if (strmatch(type, "all")) {
6399 snprintf(std_xpath, sizeof(std_xpath),
6400 "./%s/send-community/send-community",
6401 bgp_afi_safi_get_container_str(afi, safi));
6402
6403 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "false");
6404
6405 snprintf(ext_xpath, sizeof(ext_xpath),
6406 "./%s/send-community/send-ext-community",
6407 bgp_afi_safi_get_container_str(afi, safi));
6408
6409 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "false");
6410
6411 snprintf(lrg_xpath, sizeof(lrg_xpath),
6412 "./%s/send-community/send-large-community",
6413 bgp_afi_safi_get_container_str(afi, safi));
6414
6415 nb_cli_enqueue_change(vty, lrg_xpath, NB_OP_MODIFY, "false");
6416 }
6417
6418 return nb_cli_apply_changes(vty, base_xpath);
6419 }
6420
6421 ALIAS_HIDDEN(
6422 no_neighbor_send_community_type,
6423 no_neighbor_send_community_type_hidden_cmd,
6424 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6425 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6426 "Send Community attribute to this neighbor\n"
6427 "Send Standard and Extended Community attributes\n"
6428 "Send Standard, Large and Extended Community attributes\n"
6429 "Send Extended Community attributes\n"
6430 "Send Standard Community attributes\n"
6431 "Send Large Community attributes\n")
6432
6433 /* neighbor soft-reconfig. */
6434 DEFUN_YANG (neighbor_soft_reconfiguration,
6435 neighbor_soft_reconfiguration_cmd,
6436 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6437 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6438 "Per neighbor soft reconfiguration\n"
6439 "Allow inbound soft reconfiguration for this neighbor\n")
6440 {
6441 int idx_peer = 1;
6442 char base_xpath[XPATH_MAXLEN];
6443 char af_xpath[XPATH_MAXLEN];
6444 char soft_xpath[XPATH_MAXLEN];
6445 afi_t afi = bgp_node_afi(vty);
6446 safi_t safi = bgp_node_safi(vty);
6447
6448 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6449 yang_afi_safi_value2identity(afi, safi));
6450
6451 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6452 sizeof(base_xpath), af_xpath)
6453 < 0)
6454 return CMD_WARNING_CONFIG_FAILED;
6455
6456 snprintf(soft_xpath, sizeof(soft_xpath), "./%s/soft-reconfiguration",
6457 bgp_afi_safi_get_container_str(afi, safi));
6458
6459 nb_cli_enqueue_change(vty, soft_xpath, NB_OP_MODIFY, "true");
6460
6461 return nb_cli_apply_changes(vty, base_xpath);
6462 }
6463
6464 ALIAS_HIDDEN(neighbor_soft_reconfiguration,
6465 neighbor_soft_reconfiguration_hidden_cmd,
6466 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6467 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6468 "Per neighbor soft reconfiguration\n"
6469 "Allow inbound soft reconfiguration for this neighbor\n")
6470
6471 DEFUN_YANG (no_neighbor_soft_reconfiguration,
6472 no_neighbor_soft_reconfiguration_cmd,
6473 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6474 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6475 "Per neighbor soft reconfiguration\n"
6476 "Allow inbound soft reconfiguration for this neighbor\n")
6477 {
6478 int idx_peer = 2;
6479 char base_xpath[XPATH_MAXLEN];
6480 char af_xpath[XPATH_MAXLEN];
6481 char soft_xpath[XPATH_MAXLEN];
6482 afi_t afi = bgp_node_afi(vty);
6483 safi_t safi = bgp_node_safi(vty);
6484
6485 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6486 yang_afi_safi_value2identity(afi, safi));
6487
6488 snprintf(soft_xpath, sizeof(soft_xpath), "./%s/soft-reconfiguration",
6489 bgp_afi_safi_get_container_str(afi, safi));
6490
6491 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6492 sizeof(base_xpath), af_xpath)
6493 < 0)
6494 return CMD_WARNING_CONFIG_FAILED;
6495
6496 nb_cli_enqueue_change(vty, soft_xpath, NB_OP_MODIFY, "false");
6497
6498 return nb_cli_apply_changes(vty, base_xpath);
6499 }
6500
6501 ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
6502 no_neighbor_soft_reconfiguration_hidden_cmd,
6503 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6504 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6505 "Per neighbor soft reconfiguration\n"
6506 "Allow inbound soft reconfiguration for this neighbor\n")
6507
6508 DEFUN_YANG (neighbor_route_reflector_client,
6509 neighbor_route_reflector_client_cmd,
6510 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6511 NEIGHBOR_STR
6512 NEIGHBOR_ADDR_STR2
6513 "Configure a neighbor as Route Reflector client\n")
6514 {
6515 int idx_peer = 1;
6516 char base_xpath[XPATH_MAXLEN];
6517 char af_xpath[XPATH_MAXLEN];
6518 char attr_xpath[XPATH_MAXLEN];
6519 afi_t afi = bgp_node_afi(vty);
6520 safi_t safi = bgp_node_safi(vty);
6521
6522 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6523 yang_afi_safi_value2identity(afi, safi));
6524
6525 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6526 sizeof(base_xpath), af_xpath)
6527 < 0)
6528 return CMD_WARNING_CONFIG_FAILED;
6529
6530 snprintf(attr_xpath, sizeof(attr_xpath),
6531 "./%s/route-reflector/route-reflector-client",
6532 bgp_afi_safi_get_container_str(afi, safi));
6533
6534 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
6535
6536 return nb_cli_apply_changes(vty, base_xpath);
6537 }
6538
6539 ALIAS_HIDDEN(neighbor_route_reflector_client,
6540 neighbor_route_reflector_client_hidden_cmd,
6541 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6542 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6543 "Configure a neighbor as Route Reflector client\n")
6544
6545 DEFUN_YANG (no_neighbor_route_reflector_client,
6546 no_neighbor_route_reflector_client_cmd,
6547 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6548 NO_STR
6549 NEIGHBOR_STR
6550 NEIGHBOR_ADDR_STR2
6551 "Configure a neighbor as Route Reflector client\n")
6552 {
6553 int idx_peer = 2;
6554 char base_xpath[XPATH_MAXLEN];
6555 char af_xpath[XPATH_MAXLEN];
6556 char attr_xpath[XPATH_MAXLEN];
6557 afi_t afi = bgp_node_afi(vty);
6558 safi_t safi = bgp_node_safi(vty);
6559
6560 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6561 yang_afi_safi_value2identity(afi, safi));
6562
6563 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6564 sizeof(base_xpath), af_xpath)
6565 < 0)
6566 return CMD_WARNING_CONFIG_FAILED;
6567
6568 snprintf(attr_xpath, sizeof(attr_xpath),
6569 "./%s/route-reflector/route-reflector-client",
6570 bgp_afi_safi_get_container_str(afi, safi));
6571
6572 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6573
6574 return nb_cli_apply_changes(vty, base_xpath);
6575 }
6576
6577 ALIAS_HIDDEN(no_neighbor_route_reflector_client,
6578 no_neighbor_route_reflector_client_hidden_cmd,
6579 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6580 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6581 "Configure a neighbor as Route Reflector client\n")
6582
6583 /* neighbor route-server-client. */
6584 DEFUN_YANG (neighbor_route_server_client,
6585 neighbor_route_server_client_cmd,
6586 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6587 NEIGHBOR_STR
6588 NEIGHBOR_ADDR_STR2
6589 "Configure a neighbor as Route Server client\n")
6590 {
6591 int idx_peer = 1;
6592 char base_xpath[XPATH_MAXLEN];
6593 char af_xpath[XPATH_MAXLEN];
6594 char attr_xpath[XPATH_MAXLEN];
6595 afi_t afi = bgp_node_afi(vty);
6596 safi_t safi = bgp_node_safi(vty);
6597
6598 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6599 yang_afi_safi_value2identity(afi, safi));
6600
6601 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6602 sizeof(base_xpath), af_xpath)
6603 < 0)
6604 return CMD_WARNING_CONFIG_FAILED;
6605
6606 snprintf(attr_xpath, sizeof(attr_xpath),
6607 "./%s/route-server/route-server-client",
6608 bgp_afi_safi_get_container_str(afi, safi));
6609
6610 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
6611
6612 return nb_cli_apply_changes(vty, base_xpath);
6613 }
6614
6615 ALIAS_HIDDEN(neighbor_route_server_client,
6616 neighbor_route_server_client_hidden_cmd,
6617 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6618 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6619 "Configure a neighbor as Route Server client\n")
6620
6621 DEFUN_YANG (no_neighbor_route_server_client,
6622 no_neighbor_route_server_client_cmd,
6623 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6624 NO_STR
6625 NEIGHBOR_STR
6626 NEIGHBOR_ADDR_STR2
6627 "Configure a neighbor as Route Server client\n")
6628 {
6629 int idx_peer = 2;
6630 char base_xpath[XPATH_MAXLEN];
6631 char af_xpath[XPATH_MAXLEN];
6632 char attr_xpath[XPATH_MAXLEN];
6633 afi_t afi = bgp_node_afi(vty);
6634 safi_t safi = bgp_node_safi(vty);
6635
6636 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6637 yang_afi_safi_value2identity(afi, safi));
6638
6639 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6640 sizeof(base_xpath), af_xpath)
6641 < 0)
6642 return CMD_WARNING_CONFIG_FAILED;
6643
6644 snprintf(attr_xpath, sizeof(attr_xpath),
6645 "./%s/route-server/route-server-client",
6646 bgp_afi_safi_get_container_str(afi, safi));
6647
6648 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6649
6650 return nb_cli_apply_changes(vty, base_xpath);
6651 }
6652
6653 ALIAS_HIDDEN(no_neighbor_route_server_client,
6654 no_neighbor_route_server_client_hidden_cmd,
6655 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6656 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6657 "Configure a neighbor as Route Server client\n")
6658
6659 DEFUN (neighbor_nexthop_local_unchanged,
6660 neighbor_nexthop_local_unchanged_cmd,
6661 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
6662 NEIGHBOR_STR
6663 NEIGHBOR_ADDR_STR2
6664 "Configure treatment of outgoing link-local nexthop attribute\n"
6665 "Leave link-local nexthop unchanged for this peer\n")
6666 {
6667 int idx_peer = 1;
6668 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6669 bgp_node_safi(vty),
6670 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
6671 }
6672
6673 DEFUN (no_neighbor_nexthop_local_unchanged,
6674 no_neighbor_nexthop_local_unchanged_cmd,
6675 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
6676 NO_STR
6677 NEIGHBOR_STR
6678 NEIGHBOR_ADDR_STR2
6679 "Configure treatment of outgoing link-local-nexthop attribute\n"
6680 "Leave link-local nexthop unchanged for this peer\n")
6681 {
6682 int idx_peer = 2;
6683 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6684 bgp_node_afi(vty), bgp_node_safi(vty),
6685 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
6686 }
6687
6688 DEFUN_YANG (neighbor_attr_unchanged,
6689 neighbor_attr_unchanged_cmd,
6690 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6691 NEIGHBOR_STR
6692 NEIGHBOR_ADDR_STR2
6693 "BGP attribute is propagated unchanged to this neighbor\n"
6694 "As-path attribute\n"
6695 "Nexthop attribute\n"
6696 "Med attribute\n")
6697 {
6698 int idx = 0;
6699 char *peer_str = argv[1]->arg;
6700 bool aspath = false;
6701 bool nexthop = false;
6702 bool med = false;
6703 afi_t afi = bgp_node_afi(vty);
6704 safi_t safi = bgp_node_safi(vty);
6705 char base_xpath[XPATH_MAXLEN];
6706 char af_xpath[XPATH_MAXLEN];
6707 char as_xpath[XPATH_MAXLEN];
6708 char nxthop_xpath[XPATH_MAXLEN];
6709 char med_xpath[XPATH_MAXLEN];
6710
6711 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6712 yang_afi_safi_value2identity(afi, safi));
6713
6714 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6715 sizeof(base_xpath), af_xpath)
6716 < 0)
6717 return CMD_WARNING_CONFIG_FAILED;
6718
6719 if (argv_find(argv, argc, "as-path", &idx))
6720 aspath = true;
6721
6722 idx = 0;
6723 if (argv_find(argv, argc, "next-hop", &idx))
6724 nexthop = true;
6725
6726 idx = 0;
6727 if (argv_find(argv, argc, "med", &idx))
6728 med = true;
6729
6730 snprintf(as_xpath, sizeof(as_xpath),
6731 "./%s/attr-unchanged/as-path-unchanged",
6732 bgp_afi_safi_get_container_str(afi, safi));
6733 snprintf(nxthop_xpath, sizeof(nxthop_xpath),
6734 "./%s/attr-unchanged/next-hop-unchanged",
6735 bgp_afi_safi_get_container_str(afi, safi));
6736 snprintf(med_xpath, sizeof(med_xpath),
6737 "./%s/attr-unchanged/med-unchanged",
6738 bgp_afi_safi_get_container_str(afi, safi));
6739
6740 /* no flags means all of them! */
6741 if (!aspath && !nexthop && !med) {
6742 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY, "true");
6743 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY, "true");
6744 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY, "true");
6745 } else {
6746 if (!aspath)
6747 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY,
6748 "false");
6749 else
6750 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY,
6751 "true");
6752
6753 if (!nexthop)
6754 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY,
6755 "false");
6756 else
6757 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY,
6758 "true");
6759
6760 if (!med)
6761 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY,
6762 "false");
6763 else
6764 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY,
6765 "true");
6766 }
6767
6768 return nb_cli_apply_changes(vty, base_xpath);
6769 }
6770
6771 ALIAS_HIDDEN(
6772 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
6773 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6774 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6775 "BGP attribute is propagated unchanged to this neighbor\n"
6776 "As-path attribute\n"
6777 "Nexthop attribute\n"
6778 "Med attribute\n")
6779
6780 DEFUN_YANG (no_neighbor_attr_unchanged,
6781 no_neighbor_attr_unchanged_cmd,
6782 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6783 NO_STR
6784 NEIGHBOR_STR
6785 NEIGHBOR_ADDR_STR2
6786 "BGP attribute is propagated unchanged to this neighbor\n"
6787 "As-path attribute\n"
6788 "Nexthop attribute\n"
6789 "Med attribute\n")
6790 {
6791 int idx = 0;
6792 char *peer_str = argv[2]->arg;
6793 bool aspath = false;
6794 bool nexthop = false;
6795 bool med = false;
6796 afi_t afi = bgp_node_afi(vty);
6797 safi_t safi = bgp_node_safi(vty);
6798 char base_xpath[XPATH_MAXLEN];
6799 char af_xpath[XPATH_MAXLEN];
6800 char as_xpath[XPATH_MAXLEN];
6801 char nxthop_xpath[XPATH_MAXLEN];
6802 char med_xpath[XPATH_MAXLEN];
6803
6804 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6805 yang_afi_safi_value2identity(afi, safi));
6806
6807 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6808 sizeof(base_xpath), af_xpath)
6809 < 0)
6810 return CMD_WARNING_CONFIG_FAILED;
6811
6812 if (argv_find(argv, argc, "as-path", &idx))
6813 aspath = true;
6814
6815 idx = 0;
6816 if (argv_find(argv, argc, "next-hop", &idx))
6817 nexthop = true;
6818
6819 idx = 0;
6820 if (argv_find(argv, argc, "med", &idx))
6821 med = true;
6822
6823 snprintf(as_xpath, sizeof(as_xpath),
6824 "./%s/attr-unchanged/as-path-unchanged",
6825 bgp_afi_safi_get_container_str(afi, safi));
6826 snprintf(nxthop_xpath, sizeof(nxthop_xpath),
6827 "./%s/attr-unchanged/next-hop-unchanged",
6828 bgp_afi_safi_get_container_str(afi, safi));
6829 snprintf(med_xpath, sizeof(med_xpath),
6830 "./%s/attr-unchanged/med-unchanged",
6831 bgp_afi_safi_get_container_str(afi, safi));
6832
6833 /* no flags means all of them! */
6834 if (!aspath && !nexthop && !med) {
6835 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY, "false");
6836 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY, "false");
6837 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY, "false");
6838 }
6839
6840 if (aspath)
6841 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY, "false");
6842
6843 if (nexthop)
6844 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY, "false");
6845
6846 if (med)
6847 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY, "false");
6848
6849 return nb_cli_apply_changes(vty, base_xpath);
6850 }
6851
6852 ALIAS_HIDDEN(
6853 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
6854 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6855 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6856 "BGP attribute is propagated unchanged to this neighbor\n"
6857 "As-path attribute\n"
6858 "Nexthop attribute\n"
6859 "Med attribute\n")
6860
6861 /* neighbor ebgp-multihop. */
6862 DEFUN_YANG (neighbor_ebgp_multihop,
6863 neighbor_ebgp_multihop_cmd,
6864 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
6865 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6866 "Allow EBGP neighbors not on directly connected networks\n")
6867 {
6868 int idx_peer = 1;
6869 char base_xpath[XPATH_MAXLEN];
6870
6871 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6872 sizeof(base_xpath), NULL)
6873 < 0)
6874 return CMD_WARNING_CONFIG_FAILED;
6875
6876 nb_cli_enqueue_change(vty, "./ebgp-multihop/enabled", NB_OP_MODIFY,
6877 "true");
6878
6879 return nb_cli_apply_changes(vty, base_xpath);
6880 }
6881
6882 DEFUN_YANG (neighbor_ebgp_multihop_ttl,
6883 neighbor_ebgp_multihop_ttl_cmd,
6884 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
6885 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6886 "Allow EBGP neighbors not on directly connected networks\n"
6887 "maximum hop count\n")
6888 {
6889 int idx_peer = 1;
6890 int idx_number = 3;
6891 char base_xpath[XPATH_MAXLEN];
6892
6893 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6894 sizeof(base_xpath), NULL)
6895 < 0)
6896 return CMD_WARNING_CONFIG_FAILED;
6897
6898 nb_cli_enqueue_change(vty, "./ebgp-multihop/multihop-ttl", NB_OP_MODIFY,
6899 argv[idx_number]->arg);
6900
6901 return nb_cli_apply_changes(vty, base_xpath);
6902 }
6903
6904 DEFUN_YANG (no_neighbor_ebgp_multihop,
6905 no_neighbor_ebgp_multihop_cmd,
6906 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
6907 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6908 "Allow EBGP neighbors not on directly connected networks\n"
6909 "maximum hop count\n")
6910 {
6911 int idx_peer = 2;
6912 char base_xpath[XPATH_MAXLEN];
6913
6914 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6915 sizeof(base_xpath), NULL)
6916 < 0)
6917 return CMD_WARNING_CONFIG_FAILED;
6918
6919 if (argc > 4)
6920 nb_cli_enqueue_change(vty, "./ebgp-multihop/multihop-ttl",
6921 NB_OP_DESTROY, NULL);
6922 else
6923 nb_cli_enqueue_change(vty, "./ebgp-multihop/enabled",
6924 NB_OP_MODIFY, "false");
6925
6926 return nb_cli_apply_changes(vty, base_xpath);
6927 }
6928
6929
6930 /* disable-connected-check */
6931 DEFUN_YANG (neighbor_disable_connected_check,
6932 neighbor_disable_connected_check_cmd,
6933 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6934 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6935 "one-hop away EBGP peer using loopback address\n"
6936 "Enforce EBGP neighbors perform multihop\n")
6937 {
6938 int idx_peer = 1;
6939 char base_xpath[XPATH_MAXLEN];
6940
6941 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6942 sizeof(base_xpath), NULL)
6943 < 0)
6944 return CMD_WARNING_CONFIG_FAILED;
6945
6946 nb_cli_enqueue_change(vty, "./ebgp-multihop/disable-connected-check",
6947 NB_OP_MODIFY, "true");
6948
6949 return nb_cli_apply_changes(vty, base_xpath);
6950 }
6951
6952 DEFUN_YANG (no_neighbor_disable_connected_check,
6953 no_neighbor_disable_connected_check_cmd,
6954 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6955 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6956 "one-hop away EBGP peer using loopback address\n"
6957 "Enforce EBGP neighbors perform multihop\n")
6958 {
6959 int idx_peer = 2;
6960 char base_xpath[XPATH_MAXLEN];
6961
6962 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6963 sizeof(base_xpath), NULL)
6964 < 0)
6965 return CMD_WARNING_CONFIG_FAILED;
6966
6967 nb_cli_enqueue_change(vty, "./ebgp-multihop/disable-connected-check",
6968 NB_OP_MODIFY, "false");
6969
6970 return nb_cli_apply_changes(vty, base_xpath);
6971 }
6972
6973
6974 /* enforce-first-as */
6975 DEFUN_YANG (neighbor_enforce_first_as,
6976 neighbor_enforce_first_as_cmd,
6977 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6978 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6979 "Enforce the first AS for EBGP routes\n")
6980 {
6981 int idx_peer = 1;
6982 char base_xpath[XPATH_MAXLEN];
6983
6984 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6985 sizeof(base_xpath), NULL)
6986 < 0)
6987 return CMD_WARNING_CONFIG_FAILED;
6988
6989 nb_cli_enqueue_change(vty, "./enforce-first-as", NB_OP_MODIFY, "true");
6990
6991 return nb_cli_apply_changes(vty, base_xpath);
6992 }
6993
6994 DEFUN_YANG (no_neighbor_enforce_first_as,
6995 no_neighbor_enforce_first_as_cmd,
6996 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6997 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6998 "Enforce the first AS for EBGP routes\n")
6999 {
7000 int idx_peer = 2;
7001 char base_xpath[XPATH_MAXLEN];
7002
7003 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7004 sizeof(base_xpath), NULL)
7005 < 0)
7006 return CMD_WARNING_CONFIG_FAILED;
7007
7008 nb_cli_enqueue_change(vty, "./enforce-first-as", NB_OP_MODIFY, "false");
7009
7010 return nb_cli_apply_changes(vty, base_xpath);
7011 }
7012
7013 static int peer_and_group_lookup_nb(struct vty *vty, const char *peer_str,
7014 char *base_xpath, int xpath_len,
7015 char *xpath)
7016 {
7017 union sockunion su;
7018 char num_xpath[XPATH_MAXLEN];
7019 char unnbr_xpath[XPATH_MAXLEN];
7020 char prgrp_xpath[XPATH_MAXLEN];
7021
7022 if (str2sockunion(peer_str, &su) == 0) {
7023 snprintf(num_xpath, sizeof(num_xpath),
7024 "/neighbors/neighbor[remote-address='%s']", peer_str);
7025 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
7026 VTY_CURR_XPATH, num_xpath)) {
7027 snprintf(base_xpath, xpath_len,
7028 FRR_BGP_NEIGHBOR_NUM_XPATH, peer_str,
7029 xpath ? xpath : "");
7030 } else {
7031 vty_out(vty,
7032 "%% Specify remote-as or peer-group commands first\n");
7033 return -1;
7034 }
7035
7036 } else {
7037 snprintf(unnbr_xpath, sizeof(unnbr_xpath),
7038 "/neighbors/unnumbered-neighbor[interface='%s']",
7039 peer_str);
7040
7041 snprintf(prgrp_xpath, sizeof(prgrp_xpath),
7042 "/peer-groups/peer-group[peer-group-name='%s']",
7043 peer_str);
7044
7045 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
7046 VTY_CURR_XPATH, unnbr_xpath)) {
7047 snprintf(base_xpath, xpath_len,
7048 FRR_BGP_NEIGHBOR_UNNUM_XPATH, peer_str,
7049 xpath ? xpath : "");
7050 } else if (yang_dnode_exists(vty->candidate_config->dnode,
7051 "%s%s", VTY_CURR_XPATH,
7052 prgrp_xpath)) {
7053 snprintf(base_xpath, xpath_len,
7054 FRR_BGP_PEER_GROUP_XPATH, peer_str,
7055 xpath ? xpath : "");
7056 } else {
7057 vty_out(vty,
7058 "%% Create the peer-group or interface first\n");
7059 return -1;
7060 }
7061 }
7062
7063 return 0;
7064 }
7065
7066 DEFUN_YANG (neighbor_description,
7067 neighbor_description_cmd,
7068 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
7069 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7070 "Neighbor specific description\n"
7071 "Up to 80 characters describing this neighbor\n")
7072 {
7073 int idx_peer = 1;
7074 int idx_line = 3;
7075 int ret;
7076 char base_xpath[XPATH_MAXLEN];
7077 char *str;
7078
7079 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7080 sizeof(base_xpath), NULL)
7081 < 0)
7082 return CMD_WARNING_CONFIG_FAILED;
7083
7084 str = argv_concat(argv, argc, idx_line);
7085
7086 nb_cli_enqueue_change(vty, "./description", NB_OP_MODIFY, str);
7087
7088 ret = nb_cli_apply_changes(vty, base_xpath);
7089
7090 XFREE(MTYPE_TMP, str);
7091
7092 return ret;
7093 }
7094
7095 DEFUN_YANG (no_neighbor_description,
7096 no_neighbor_description_cmd,
7097 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
7098 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7099 "Neighbor specific description\n")
7100 {
7101 int idx_peer = 2;
7102 char base_xpath[XPATH_MAXLEN];
7103
7104 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7105 sizeof(base_xpath), NULL)
7106 < 0)
7107 return CMD_WARNING_CONFIG_FAILED;
7108
7109 nb_cli_enqueue_change(vty, "./description", NB_OP_DESTROY, NULL);
7110
7111 return nb_cli_apply_changes(vty, base_xpath);
7112 }
7113
7114 ALIAS_YANG(no_neighbor_description, no_neighbor_description_comment_cmd,
7115 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
7116 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7117 "Neighbor specific description\n"
7118 "Up to 80 characters describing this neighbor\n")
7119
7120 #define BGP_UPDATE_SOURCE_HELP_STR \
7121 "IPv4 address\n" \
7122 "IPv6 address\n" \
7123 "Interface name (requires zebra to be running)\n"
7124
7125 DEFUN_YANG (neighbor_update_source,
7126 neighbor_update_source_cmd,
7127 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
7128 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7129 "Source of routing updates\n"
7130 BGP_UPDATE_SOURCE_HELP_STR)
7131 {
7132 int idx_peer = 1;
7133 int idx_peer_2 = 3;
7134 union sockunion su;
7135 char base_xpath[XPATH_MAXLEN];
7136
7137 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7138 sizeof(base_xpath), NULL)
7139 < 0)
7140 return CMD_WARNING_CONFIG_FAILED;
7141
7142 if (str2sockunion(argv[idx_peer_2]->arg, &su) == 0)
7143 nb_cli_enqueue_change(vty, "./update-source/ip", NB_OP_MODIFY,
7144 argv[idx_peer_2]->arg);
7145 else
7146 nb_cli_enqueue_change(vty, "./update-source/interface",
7147 NB_OP_MODIFY, argv[idx_peer_2]->arg);
7148
7149 return nb_cli_apply_changes(vty, base_xpath);
7150 }
7151
7152 DEFUN_YANG (no_neighbor_update_source,
7153 no_neighbor_update_source_cmd,
7154 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
7155 NO_STR NEIGHBOR_STR
7156 NEIGHBOR_ADDR_STR2
7157 "Source of routing updates\n"
7158 BGP_UPDATE_SOURCE_HELP_STR)
7159 {
7160 int idx_peer = 2;
7161 char base_xpath[XPATH_MAXLEN];
7162
7163 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7164 sizeof(base_xpath), NULL)
7165 < 0)
7166 return CMD_WARNING_CONFIG_FAILED;
7167
7168 nb_cli_enqueue_change(vty, "./update-source/ip", NB_OP_DESTROY, NULL);
7169 nb_cli_enqueue_change(vty, "./update-source/interface", NB_OP_DESTROY,
7170 NULL);
7171
7172 return nb_cli_apply_changes(vty, base_xpath);
7173 }
7174
7175 static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
7176 afi_t afi, safi_t safi,
7177 const char *rmap, int set)
7178 {
7179 int ret;
7180 struct peer *peer;
7181 struct route_map *route_map = NULL;
7182
7183 peer = peer_and_group_lookup_vty(vty, peer_str);
7184 if (!peer)
7185 return CMD_WARNING_CONFIG_FAILED;
7186
7187 if (set) {
7188 if (rmap)
7189 route_map = route_map_lookup_warn_noexist(vty, rmap);
7190 ret = peer_default_originate_set(peer, afi, safi,
7191 rmap, route_map);
7192 } else
7193 ret = peer_default_originate_unset(peer, afi, safi);
7194
7195 return bgp_vty_return(vty, ret);
7196 }
7197
7198 /* neighbor default-originate. */
7199 DEFUN (neighbor_default_originate,
7200 neighbor_default_originate_cmd,
7201 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
7202 NEIGHBOR_STR
7203 NEIGHBOR_ADDR_STR2
7204 "Originate default route to this neighbor\n")
7205 {
7206 int idx_peer = 1;
7207 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
7208 bgp_node_afi(vty),
7209 bgp_node_safi(vty), NULL, 1);
7210 }
7211
7212 ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
7213 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
7214 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7215 "Originate default route to this neighbor\n")
7216
7217 DEFUN (neighbor_default_originate_rmap,
7218 neighbor_default_originate_rmap_cmd,
7219 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
7220 NEIGHBOR_STR
7221 NEIGHBOR_ADDR_STR2
7222 "Originate default route to this neighbor\n"
7223 "Route-map to specify criteria to originate default\n"
7224 "route-map name\n")
7225 {
7226 int idx_peer = 1;
7227 int idx_word = 4;
7228 return peer_default_originate_set_vty(
7229 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7230 argv[idx_word]->arg, 1);
7231 }
7232
7233 ALIAS_HIDDEN(
7234 neighbor_default_originate_rmap,
7235 neighbor_default_originate_rmap_hidden_cmd,
7236 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
7237 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7238 "Originate default route to this neighbor\n"
7239 "Route-map to specify criteria to originate default\n"
7240 "route-map name\n")
7241
7242 DEFUN (no_neighbor_default_originate,
7243 no_neighbor_default_originate_cmd,
7244 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
7245 NO_STR
7246 NEIGHBOR_STR
7247 NEIGHBOR_ADDR_STR2
7248 "Originate default route to this neighbor\n"
7249 "Route-map to specify criteria to originate default\n"
7250 "route-map name\n")
7251 {
7252 int idx_peer = 2;
7253 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
7254 bgp_node_afi(vty),
7255 bgp_node_safi(vty), NULL, 0);
7256 }
7257
7258 ALIAS_HIDDEN(
7259 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
7260 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
7261 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7262 "Originate default route to this neighbor\n"
7263 "Route-map to specify criteria to originate default\n"
7264 "route-map name\n")
7265
7266
7267 /* Set specified peer's BGP port. */
7268 DEFUN_YANG (neighbor_port,
7269 neighbor_port_cmd,
7270 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
7271 NEIGHBOR_STR
7272 NEIGHBOR_ADDR_STR
7273 "Neighbor's BGP port\n"
7274 "TCP port number\n")
7275 {
7276 int idx_ip = 1;
7277 int idx_number = 3;
7278 char base_xpath[XPATH_MAXLEN];
7279
7280 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_NUM_XPATH,
7281 argv[idx_ip]->arg, "");
7282
7283 nb_cli_enqueue_change(vty, "./local-port", NB_OP_MODIFY,
7284 argv[idx_number]->arg);
7285
7286 return nb_cli_apply_changes(vty, base_xpath);
7287 }
7288
7289 DEFUN_YANG (no_neighbor_port,
7290 no_neighbor_port_cmd,
7291 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
7292 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR
7293 "Neighbor's BGP port\n"
7294 "TCP port number\n")
7295 {
7296 int idx_ip = 2;
7297 char base_xpath[XPATH_MAXLEN];
7298
7299 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_NUM_XPATH,
7300 argv[idx_ip]->arg, "");
7301
7302 nb_cli_enqueue_change(vty, "./local-port", NB_OP_DESTROY, NULL);
7303
7304 return nb_cli_apply_changes(vty, base_xpath);
7305 }
7306
7307 DEFUN_YANG (neighbor_weight,
7308 neighbor_weight_cmd,
7309 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7310 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7311 "Set default weight for routes from this neighbor\n"
7312 "default weight\n")
7313 {
7314 int idx_peer = 1;
7315 int idx_number = 3;
7316 char base_xpath[XPATH_MAXLEN];
7317 char af_xpath[XPATH_MAXLEN];
7318 char attr_xpath[XPATH_MAXLEN];
7319 afi_t afi = bgp_node_afi(vty);
7320 safi_t safi = bgp_node_safi(vty);
7321
7322 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
7323 yang_afi_safi_value2identity(afi, safi));
7324
7325 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7326 sizeof(base_xpath), af_xpath)
7327 < 0)
7328 return CMD_WARNING_CONFIG_FAILED;
7329
7330 snprintf(attr_xpath, sizeof(attr_xpath), "./%s/weight/weight-attribute",
7331 bgp_afi_safi_get_container_str(afi, safi));
7332
7333 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY,
7334 argv[idx_number]->arg);
7335
7336 return nb_cli_apply_changes(vty, base_xpath);
7337 }
7338
7339 ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
7340 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7341 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7342 "Set default weight for routes from this neighbor\n"
7343 "default weight\n")
7344
7345 DEFUN_YANG (no_neighbor_weight,
7346 no_neighbor_weight_cmd,
7347 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7348 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7349 "Set default weight for routes from this neighbor\n"
7350 "default weight\n")
7351 {
7352 int idx_peer = 2;
7353 char base_xpath[XPATH_MAXLEN];
7354 char af_xpath[XPATH_MAXLEN];
7355 char attr_xpath[XPATH_MAXLEN];
7356 afi_t afi = bgp_node_afi(vty);
7357 safi_t safi = bgp_node_safi(vty);
7358
7359 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
7360 yang_afi_safi_value2identity(afi, safi));
7361
7362 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7363 sizeof(base_xpath), af_xpath)
7364 < 0)
7365 return CMD_WARNING_CONFIG_FAILED;
7366
7367 snprintf(attr_xpath, sizeof(attr_xpath), "./%s/weight/weight-attribute",
7368 bgp_afi_safi_get_container_str(afi, safi));
7369
7370 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_DESTROY, NULL);
7371
7372 return nb_cli_apply_changes(vty, base_xpath);
7373 }
7374
7375 ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
7376 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7377 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7378 "Set default weight for routes from this neighbor\n"
7379 "default weight\n")
7380
7381
7382 /* Override capability negotiation. */
7383 DEFUN_YANG (neighbor_override_capability,
7384 neighbor_override_capability_cmd,
7385 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7386 NEIGHBOR_STR
7387 NEIGHBOR_ADDR_STR2
7388 "Override capability negotiation result\n")
7389 {
7390 int idx_peer = 1;
7391 char base_xpath[XPATH_MAXLEN];
7392
7393 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7394 sizeof(base_xpath), NULL)
7395 < 0)
7396 return CMD_WARNING_CONFIG_FAILED;
7397
7398 nb_cli_enqueue_change(
7399 vty, "./capability-options/override-capability",
7400 NB_OP_MODIFY, "true");
7401
7402 return nb_cli_apply_changes(vty, base_xpath);
7403 }
7404
7405 DEFUN_YANG (no_neighbor_override_capability,
7406 no_neighbor_override_capability_cmd,
7407 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7408 NO_STR
7409 NEIGHBOR_STR
7410 NEIGHBOR_ADDR_STR2
7411 "Override capability negotiation result\n")
7412 {
7413 int idx_peer = 2;
7414 char base_xpath[XPATH_MAXLEN];
7415
7416 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7417 sizeof(base_xpath), NULL)
7418 < 0)
7419 return CMD_WARNING_CONFIG_FAILED;
7420
7421 nb_cli_enqueue_change(
7422 vty, "./capability-options/override-capability",
7423 NB_OP_MODIFY, "false");
7424
7425 return nb_cli_apply_changes(vty, base_xpath);
7426 }
7427
7428 DEFUN_YANG (neighbor_strict_capability,
7429 neighbor_strict_capability_cmd,
7430 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7431 NEIGHBOR_STR
7432 NEIGHBOR_ADDR_STR2
7433 "Strict capability negotiation match\n")
7434 {
7435 int idx_peer = 1;
7436 char base_xpath[XPATH_MAXLEN];
7437
7438 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7439 sizeof(base_xpath), NULL)
7440 < 0)
7441 return CMD_WARNING_CONFIG_FAILED;
7442
7443 nb_cli_enqueue_change(
7444 vty, "./capability-options/strict-capability",
7445 NB_OP_MODIFY, "true");
7446
7447 return nb_cli_apply_changes(vty, base_xpath);
7448 }
7449
7450 DEFUN_YANG (no_neighbor_strict_capability,
7451 no_neighbor_strict_capability_cmd,
7452 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7453 NO_STR
7454 NEIGHBOR_STR
7455 NEIGHBOR_ADDR_STR2
7456 "Strict capability negotiation match\n")
7457 {
7458 int idx_peer = 2;
7459 char base_xpath[XPATH_MAXLEN];
7460
7461 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7462 sizeof(base_xpath), NULL)
7463 < 0)
7464 return CMD_WARNING_CONFIG_FAILED;
7465
7466 nb_cli_enqueue_change(
7467 vty, "./capability-options/strict-capability",
7468 NB_OP_MODIFY, "false");
7469
7470 return nb_cli_apply_changes(vty, base_xpath);
7471 }
7472
7473 DEFUN_YANG (neighbor_timers,
7474 neighbor_timers_cmd,
7475 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
7476 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7477 "BGP per neighbor timers\n"
7478 "Keepalive interval\n"
7479 "Holdtime\n")
7480 {
7481 int idx_peer = 1;
7482 int idx_number = 3;
7483 int idx_number_2 = 4;
7484 char base_xpath[XPATH_MAXLEN];
7485
7486 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7487 sizeof(base_xpath), NULL)
7488 < 0)
7489 return CMD_WARNING_CONFIG_FAILED;
7490
7491 nb_cli_enqueue_change(vty, "./timers/keepalive", NB_OP_MODIFY,
7492 argv[idx_number]->arg);
7493
7494 nb_cli_enqueue_change(vty, "./timers/hold-time", NB_OP_MODIFY,
7495 argv[idx_number_2]->arg);
7496
7497 return nb_cli_apply_changes(vty, base_xpath);
7498 }
7499
7500 DEFUN_YANG (no_neighbor_timers,
7501 no_neighbor_timers_cmd,
7502 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
7503 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7504 "BGP per neighbor timers\n"
7505 "Keepalive interval\n"
7506 "Holdtime\n")
7507 {
7508 int idx_peer = 2;
7509 char base_xpath[XPATH_MAXLEN];
7510
7511 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7512 sizeof(base_xpath), NULL)
7513 < 0)
7514 return CMD_WARNING_CONFIG_FAILED;
7515
7516 nb_cli_enqueue_change(vty, "./timers/hold-time", NB_OP_DESTROY, NULL);
7517
7518 nb_cli_enqueue_change(vty, "./timers/keepalive", NB_OP_DESTROY, NULL);
7519
7520 return nb_cli_apply_changes(vty, base_xpath);
7521 }
7522
7523 DEFUN_YANG (neighbor_timers_connect,
7524 neighbor_timers_connect_cmd,
7525 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
7526 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7527 "BGP per neighbor timers\n"
7528 "BGP connect timer\n"
7529 "Connect timer\n")
7530 {
7531 int idx_peer = 1;
7532 int idx_number = 4;
7533 char base_xpath[XPATH_MAXLEN];
7534
7535 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7536 sizeof(base_xpath), NULL)
7537 < 0)
7538 return CMD_WARNING_CONFIG_FAILED;
7539
7540 nb_cli_enqueue_change(vty, "./timers/connect-time", NB_OP_MODIFY,
7541 argv[idx_number]->arg);
7542
7543 return nb_cli_apply_changes(vty, base_xpath);
7544 }
7545
7546 DEFUN_YANG (no_neighbor_timers_connect,
7547 no_neighbor_timers_connect_cmd,
7548 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
7549 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7550 "BGP per neighbor timers\n"
7551 "BGP connect timer\n"
7552 "Connect timer\n")
7553 {
7554 int idx_peer = 2;
7555 char base_xpath[XPATH_MAXLEN];
7556
7557 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7558 sizeof(base_xpath), NULL)
7559 < 0)
7560 return CMD_WARNING_CONFIG_FAILED;
7561
7562 nb_cli_enqueue_change(vty, "./timers/connect-time", NB_OP_DESTROY,
7563 NULL);
7564
7565 return nb_cli_apply_changes(vty, base_xpath);
7566 }
7567
7568 DEFPY (neighbor_timers_delayopen,
7569 neighbor_timers_delayopen_cmd,
7570 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen (1-240)$interval",
7571 NEIGHBOR_STR
7572 NEIGHBOR_ADDR_STR2
7573 "BGP per neighbor timers\n"
7574 "RFC 4271 DelayOpenTimer\n"
7575 "DelayOpenTime timer interval\n")
7576 {
7577 struct peer *peer;
7578
7579 peer = peer_and_group_lookup_vty(vty, neighbor);
7580 if (!peer)
7581 return CMD_WARNING_CONFIG_FAILED;
7582
7583 if (!interval) {
7584 if (peer_timers_delayopen_unset(peer))
7585 return CMD_WARNING_CONFIG_FAILED;
7586 } else {
7587 if (peer_timers_delayopen_set(peer, interval))
7588 return CMD_WARNING_CONFIG_FAILED;
7589 }
7590
7591 return CMD_SUCCESS;
7592 }
7593
7594 DEFPY (no_neighbor_timers_delayopen,
7595 no_neighbor_timers_delayopen_cmd,
7596 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen [(0-65535)]",
7597 NO_STR
7598 NEIGHBOR_STR
7599 NEIGHBOR_ADDR_STR2
7600 "BGP per neighbor timers\n"
7601 "RFC 4271 DelayOpenTimer\n"
7602 "DelayOpenTime timer interval\n")
7603 {
7604 struct peer *peer;
7605
7606 peer = peer_and_group_lookup_vty(vty, neighbor);
7607 if (!peer)
7608 return CMD_WARNING_CONFIG_FAILED;
7609
7610 if (peer_timers_delayopen_unset(peer))
7611 return CMD_WARNING_CONFIG_FAILED;
7612
7613 return CMD_SUCCESS;
7614 }
7615
7616 DEFUN_YANG (neighbor_advertise_interval,
7617 neighbor_advertise_interval_cmd,
7618 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
7619 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7620 "Minimum interval between sending BGP routing updates\n"
7621 "time in seconds\n")
7622 {
7623 int idx_peer = 1;
7624 int idx_number = 3;
7625 char base_xpath[XPATH_MAXLEN];
7626
7627 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7628 sizeof(base_xpath), NULL)
7629 < 0)
7630 return CMD_WARNING_CONFIG_FAILED;
7631
7632 nb_cli_enqueue_change(vty, "./timers/advertise-interval", NB_OP_MODIFY,
7633 argv[idx_number]->arg);
7634
7635 return nb_cli_apply_changes(vty, base_xpath);
7636 }
7637
7638 DEFUN_YANG (no_neighbor_advertise_interval,
7639 no_neighbor_advertise_interval_cmd,
7640 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
7641 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7642 "Minimum interval between sending BGP routing updates\n"
7643 "time in seconds\n")
7644 {
7645 int idx_peer = 2;
7646 char base_xpath[XPATH_MAXLEN];
7647
7648 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7649 sizeof(base_xpath), NULL)
7650 < 0)
7651 return CMD_WARNING_CONFIG_FAILED;
7652
7653 nb_cli_enqueue_change(vty, "./timers/advertise-interval", NB_OP_DESTROY,
7654 NULL);
7655
7656 return nb_cli_apply_changes(vty, base_xpath);
7657 }
7658
7659
7660 /* Time to wait before processing route-map updates */
7661 DEFUN (bgp_set_route_map_delay_timer,
7662 bgp_set_route_map_delay_timer_cmd,
7663 "bgp route-map delay-timer (0-600)",
7664 SET_STR
7665 "BGP route-map delay timer\n"
7666 "Time in secs to wait before processing route-map changes\n"
7667 "0 disables the timer, no route updates happen when route-maps change\n")
7668 {
7669 int idx_number = 3;
7670 uint32_t rmap_delay_timer;
7671
7672 if (argv[idx_number]->arg) {
7673 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
7674 bm->rmap_update_timer = rmap_delay_timer;
7675
7676 /* if the dynamic update handling is being disabled, and a timer
7677 * is
7678 * running, stop the timer and act as if the timer has already
7679 * fired.
7680 */
7681 if (!rmap_delay_timer && bm->t_rmap_update) {
7682 BGP_TIMER_OFF(bm->t_rmap_update);
7683 thread_execute(bm->master, bgp_route_map_update_timer,
7684 NULL, 0);
7685 }
7686 return CMD_SUCCESS;
7687 } else {
7688 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
7689 return CMD_WARNING_CONFIG_FAILED;
7690 }
7691 }
7692
7693 DEFUN (no_bgp_set_route_map_delay_timer,
7694 no_bgp_set_route_map_delay_timer_cmd,
7695 "no bgp route-map delay-timer [(0-600)]",
7696 NO_STR
7697 BGP_STR
7698 "Default BGP route-map delay timer\n"
7699 "Reset to default time to wait for processing route-map changes\n"
7700 "0 disables the timer, no route updates happen when route-maps change\n")
7701 {
7702
7703 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
7704
7705 return CMD_SUCCESS;
7706 }
7707
7708 DEFUN_YANG (neighbor_interface,
7709 neighbor_interface_cmd,
7710 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
7711 NEIGHBOR_STR NEIGHBOR_ADDR_STR
7712 "Interface\n"
7713 "Interface name\n")
7714 {
7715 int idx_ip = 1;
7716 int idx_word = 3;
7717 char base_xpath[XPATH_MAXLEN];
7718
7719 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_NUM_XPATH,
7720 argv[idx_ip]->arg, "");
7721
7722 nb_cli_enqueue_change(vty, "./local-interface", NB_OP_MODIFY,
7723 argv[idx_word]->arg);
7724
7725 return nb_cli_apply_changes(vty, base_xpath);
7726 }
7727
7728 DEFUN_YANG (no_neighbor_interface,
7729 no_neighbor_interface_cmd,
7730 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
7731 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7732 "Interface\n"
7733 "Interface name\n")
7734 {
7735 int idx_peer = 2;
7736 char base_xpath[XPATH_MAXLEN];
7737
7738 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_NUM_XPATH,
7739 argv[idx_peer]->arg, "");
7740
7741 nb_cli_enqueue_change(vty, "./local-interface", NB_OP_DESTROY, NULL);
7742
7743 return nb_cli_apply_changes(vty, base_xpath);
7744 }
7745
7746 DEFUN (neighbor_distribute_list,
7747 neighbor_distribute_list_cmd,
7748 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
7749 NEIGHBOR_STR
7750 NEIGHBOR_ADDR_STR2
7751 "Filter updates to/from this neighbor\n"
7752 "IP access-list number\n"
7753 "IP access-list number (expanded range)\n"
7754 "IP Access-list name\n"
7755 "Filter incoming updates\n"
7756 "Filter outgoing updates\n")
7757 {
7758 int idx_peer = 1;
7759 int idx_acl = 3;
7760 int direct, ret;
7761 struct peer *peer;
7762
7763 const char *pstr = argv[idx_peer]->arg;
7764 const char *acl = argv[idx_acl]->arg;
7765 const char *inout = argv[argc - 1]->text;
7766
7767 peer = peer_and_group_lookup_vty(vty, pstr);
7768 if (!peer)
7769 return CMD_WARNING_CONFIG_FAILED;
7770
7771 /* Check filter direction. */
7772 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7773 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7774 direct, acl);
7775
7776 return bgp_vty_return(vty, ret);
7777 }
7778
7779 ALIAS_HIDDEN(
7780 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
7781 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
7782 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7783 "Filter updates to/from this neighbor\n"
7784 "IP access-list number\n"
7785 "IP access-list number (expanded range)\n"
7786 "IP Access-list name\n"
7787 "Filter incoming updates\n"
7788 "Filter outgoing updates\n")
7789
7790 DEFUN (no_neighbor_distribute_list,
7791 no_neighbor_distribute_list_cmd,
7792 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
7793 NO_STR
7794 NEIGHBOR_STR
7795 NEIGHBOR_ADDR_STR2
7796 "Filter updates to/from this neighbor\n"
7797 "IP access-list number\n"
7798 "IP access-list number (expanded range)\n"
7799 "IP Access-list name\n"
7800 "Filter incoming updates\n"
7801 "Filter outgoing updates\n")
7802 {
7803 int idx_peer = 2;
7804 int direct, ret;
7805 struct peer *peer;
7806
7807 const char *pstr = argv[idx_peer]->arg;
7808 const char *inout = argv[argc - 1]->text;
7809
7810 peer = peer_and_group_lookup_vty(vty, pstr);
7811 if (!peer)
7812 return CMD_WARNING_CONFIG_FAILED;
7813
7814 /* Check filter direction. */
7815 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7816 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7817 direct);
7818
7819 return bgp_vty_return(vty, ret);
7820 }
7821
7822 ALIAS_HIDDEN(
7823 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
7824 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
7825 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7826 "Filter updates to/from this neighbor\n"
7827 "IP access-list number\n"
7828 "IP access-list number (expanded range)\n"
7829 "IP Access-list name\n"
7830 "Filter incoming updates\n"
7831 "Filter outgoing updates\n")
7832
7833 /* Set prefix list to the peer. */
7834 DEFPY_YANG(
7835 neighbor_prefix_list, neighbor_prefix_list_cmd,
7836 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor_str prefix-list WORD$prefix_str <in|out>$direction",
7837 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7838 "Filter updates to/from this neighbor\n"
7839 "Name of a prefix list\n"
7840 "Filter incoming updates\n"
7841 "Filter outgoing updates\n")
7842 {
7843 char base_xpath[XPATH_MAXLEN];
7844 char af_xpath[XPATH_MAXLEN];
7845 char plist_xpath[XPATH_MAXLEN];
7846 afi_t afi = bgp_node_afi(vty);
7847 safi_t safi = bgp_node_safi(vty);
7848
7849 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
7850 yang_afi_safi_value2identity(afi, safi));
7851 if (peer_and_group_lookup_nb(vty, neighbor_str, base_xpath,
7852 sizeof(base_xpath), af_xpath)
7853 < 0)
7854 return CMD_WARNING_CONFIG_FAILED;
7855
7856 if (strmatch(direction, "in"))
7857 snprintf(plist_xpath, sizeof(plist_xpath),
7858 "./%s/filter-config/plist-import",
7859 bgp_afi_safi_get_container_str(afi, safi));
7860 else if (strmatch(direction, "out"))
7861 snprintf(plist_xpath, sizeof(plist_xpath),
7862 "./%s/filter-config/plist-export",
7863 bgp_afi_safi_get_container_str(afi, safi));
7864
7865 if (!no)
7866 nb_cli_enqueue_change(vty, plist_xpath, NB_OP_MODIFY,
7867 prefix_str);
7868 else
7869 nb_cli_enqueue_change(vty, plist_xpath, NB_OP_DESTROY, NULL);
7870
7871 return nb_cli_apply_changes(vty, base_xpath);
7872 }
7873
7874 ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
7875 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7876 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7877 "Filter updates to/from this neighbor\n"
7878 "Name of a prefix list\n"
7879 "Filter incoming updates\n"
7880 "Filter outgoing updates\n")
7881
7882 static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7883 safi_t safi, const char *name_str,
7884 const char *direct_str)
7885 {
7886 int ret;
7887 struct peer *peer;
7888 int direct = FILTER_IN;
7889
7890 peer = peer_and_group_lookup_vty(vty, ip_str);
7891 if (!peer)
7892 return CMD_WARNING_CONFIG_FAILED;
7893
7894 /* Check filter direction. */
7895 if (strncmp(direct_str, "i", 1) == 0)
7896 direct = FILTER_IN;
7897 else if (strncmp(direct_str, "o", 1) == 0)
7898 direct = FILTER_OUT;
7899
7900 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
7901
7902 return bgp_vty_return(vty, ret);
7903 }
7904
7905 static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7906 safi_t safi, const char *direct_str)
7907 {
7908 int ret;
7909 struct peer *peer;
7910 int direct = FILTER_IN;
7911
7912 peer = peer_and_group_lookup_vty(vty, ip_str);
7913 if (!peer)
7914 return CMD_WARNING_CONFIG_FAILED;
7915
7916 /* Check filter direction. */
7917 if (strncmp(direct_str, "i", 1) == 0)
7918 direct = FILTER_IN;
7919 else if (strncmp(direct_str, "o", 1) == 0)
7920 direct = FILTER_OUT;
7921
7922 ret = peer_aslist_unset(peer, afi, safi, direct);
7923
7924 return bgp_vty_return(vty, ret);
7925 }
7926
7927 DEFUN (neighbor_filter_list,
7928 neighbor_filter_list_cmd,
7929 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
7930 NEIGHBOR_STR
7931 NEIGHBOR_ADDR_STR2
7932 "Establish BGP filters\n"
7933 "AS path access-list name\n"
7934 "Filter incoming routes\n"
7935 "Filter outgoing routes\n")
7936 {
7937 int idx_peer = 1;
7938 int idx_word = 3;
7939 int idx_in_out = 4;
7940 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7941 bgp_node_safi(vty), argv[idx_word]->arg,
7942 argv[idx_in_out]->arg);
7943 }
7944
7945 ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
7946 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
7947 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7948 "Establish BGP filters\n"
7949 "AS path access-list name\n"
7950 "Filter incoming routes\n"
7951 "Filter outgoing routes\n")
7952
7953 DEFUN (no_neighbor_filter_list,
7954 no_neighbor_filter_list_cmd,
7955 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
7956 NO_STR
7957 NEIGHBOR_STR
7958 NEIGHBOR_ADDR_STR2
7959 "Establish BGP filters\n"
7960 "AS path access-list name\n"
7961 "Filter incoming routes\n"
7962 "Filter outgoing routes\n")
7963 {
7964 int idx_peer = 2;
7965 int idx_in_out = 5;
7966 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
7967 bgp_node_afi(vty), bgp_node_safi(vty),
7968 argv[idx_in_out]->arg);
7969 }
7970
7971 ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
7972 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
7973 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7974 "Establish BGP filters\n"
7975 "AS path access-list name\n"
7976 "Filter incoming routes\n"
7977 "Filter outgoing routes\n")
7978
7979 /* Set advertise-map to the peer. */
7980 static int peer_advertise_map_set_vty(struct vty *vty, const char *ip_str,
7981 afi_t afi, safi_t safi,
7982 const char *advertise_str,
7983 const char *condition_str, bool condition,
7984 bool set)
7985 {
7986 int ret = CMD_WARNING_CONFIG_FAILED;
7987 struct peer *peer;
7988 struct route_map *advertise_map;
7989 struct route_map *condition_map;
7990
7991 peer = peer_and_group_lookup_vty(vty, ip_str);
7992 if (!peer)
7993 return ret;
7994
7995 condition_map = route_map_lookup_warn_noexist(vty, condition_str);
7996 advertise_map = route_map_lookup_warn_noexist(vty, advertise_str);
7997
7998 if (set)
7999 ret = peer_advertise_map_set(peer, afi, safi, advertise_str,
8000 advertise_map, condition_str,
8001 condition_map, condition);
8002 else
8003 ret = peer_advertise_map_unset(peer, afi, safi, advertise_str,
8004 advertise_map, condition_str,
8005 condition_map, condition);
8006
8007 return bgp_vty_return(vty, ret);
8008 }
8009
8010 DEFPY (neighbor_advertise_map,
8011 neighbor_advertise_map_cmd,
8012 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor advertise-map WORD$advertise_str <exist-map|non-exist-map>$exist WORD$condition_str",
8013 NO_STR
8014 NEIGHBOR_STR
8015 NEIGHBOR_ADDR_STR2
8016 "Route-map to conditionally advertise routes\n"
8017 "Name of advertise map\n"
8018 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
8019 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
8020 "Name of the exist or non exist map\n")
8021 {
8022 bool condition = CONDITION_EXIST;
8023
8024 if (!strcmp(exist, "non-exist-map"))
8025 condition = CONDITION_NON_EXIST;
8026
8027 return peer_advertise_map_set_vty(vty, neighbor, bgp_node_afi(vty),
8028 bgp_node_safi(vty), advertise_str,
8029 condition_str, condition, !no);
8030 }
8031
8032 ALIAS_HIDDEN(neighbor_advertise_map, neighbor_advertise_map_hidden_cmd,
8033 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor advertise-map WORD$advertise_str <exist-map|non-exist-map>$exist WORD$condition_str",
8034 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8035 "Route-map to conditionally advertise routes\n"
8036 "Name of advertise map\n"
8037 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
8038 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
8039 "Name of the exist or non exist map\n")
8040
8041 /* Set route-map to the peer. */
8042 DEFPY_YANG(
8043 neighbor_route_map, neighbor_route_map_cmd,
8044 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor_str route-map WORD$rmap_str <in|out>$direction",
8045 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8046 "Apply route map to neighbor\n"
8047 "Name of route map\n"
8048 "Apply map to incoming routes\n"
8049 "Apply map to outbound routes\n")
8050 {
8051 char base_xpath[XPATH_MAXLEN];
8052 char af_xpath[XPATH_MAXLEN];
8053 char rmap_xpath[XPATH_MAXLEN];
8054 afi_t afi = bgp_node_afi(vty);
8055 safi_t safi = bgp_node_safi(vty);
8056
8057 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8058 yang_afi_safi_value2identity(afi, safi));
8059 if (peer_and_group_lookup_nb(vty, neighbor_str, base_xpath,
8060 sizeof(base_xpath), af_xpath)
8061 < 0)
8062 return CMD_WARNING_CONFIG_FAILED;
8063
8064 if (strmatch(direction, "in"))
8065 snprintf(rmap_xpath, sizeof(rmap_xpath),
8066 "./%s/filter-config/rmap-import",
8067 bgp_afi_safi_get_container_str(afi, safi));
8068 else if (strmatch(direction, "out"))
8069 snprintf(rmap_xpath, sizeof(rmap_xpath),
8070 "./%s/filter-config/rmap-export",
8071 bgp_afi_safi_get_container_str(afi, safi));
8072
8073 if (!no) {
8074 if (!yang_dnode_exists(
8075 vty->candidate_config->dnode,
8076 "/frr-route-map:lib/route-map[name='%s']",
8077 rmap_str)) {
8078 if (vty_shell_serv(vty))
8079 vty_out(vty,
8080 "The route-map '%s' does not exist.\n",
8081 rmap_str);
8082 }
8083 nb_cli_enqueue_change(vty, rmap_xpath, NB_OP_MODIFY, rmap_str);
8084 } else
8085 nb_cli_enqueue_change(vty, rmap_xpath, NB_OP_DESTROY, NULL);
8086
8087 return nb_cli_apply_changes(vty, base_xpath);
8088 }
8089
8090 /* Set unsuppress-map to the peer. */
8091 static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
8092 afi_t afi, safi_t safi,
8093 const char *name_str)
8094 {
8095 int ret;
8096 struct peer *peer;
8097 struct route_map *route_map;
8098
8099 peer = peer_and_group_lookup_vty(vty, ip_str);
8100 if (!peer)
8101 return CMD_WARNING_CONFIG_FAILED;
8102
8103 route_map = route_map_lookup_warn_noexist(vty, name_str);
8104 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
8105
8106 return bgp_vty_return(vty, ret);
8107 }
8108
8109 /* Unset route-map from the peer. */
8110 static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
8111 afi_t afi, safi_t safi)
8112 {
8113 int ret;
8114 struct peer *peer;
8115
8116 peer = peer_and_group_lookup_vty(vty, ip_str);
8117 if (!peer)
8118 return CMD_WARNING_CONFIG_FAILED;
8119
8120 ret = peer_unsuppress_map_unset(peer, afi, safi);
8121
8122 return bgp_vty_return(vty, ret);
8123 }
8124
8125 DEFUN (neighbor_unsuppress_map,
8126 neighbor_unsuppress_map_cmd,
8127 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8128 NEIGHBOR_STR
8129 NEIGHBOR_ADDR_STR2
8130 "Route-map to selectively unsuppress suppressed routes\n"
8131 "Name of route map\n")
8132 {
8133 int idx_peer = 1;
8134 int idx_word = 3;
8135 return peer_unsuppress_map_set_vty(
8136 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8137 argv[idx_word]->arg);
8138 }
8139
8140 ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
8141 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8142 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8143 "Route-map to selectively unsuppress suppressed routes\n"
8144 "Name of route map\n")
8145
8146 DEFUN (no_neighbor_unsuppress_map,
8147 no_neighbor_unsuppress_map_cmd,
8148 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8149 NO_STR
8150 NEIGHBOR_STR
8151 NEIGHBOR_ADDR_STR2
8152 "Route-map to selectively unsuppress suppressed routes\n"
8153 "Name of route map\n")
8154 {
8155 int idx_peer = 2;
8156 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
8157 bgp_node_afi(vty),
8158 bgp_node_safi(vty));
8159 }
8160
8161 ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
8162 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8163 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8164 "Route-map to selectively unsuppress suppressed routes\n"
8165 "Name of route map\n")
8166
8167 /* Maximum number of prefix to be sent to the neighbor. */
8168 DEFUN_YANG(neighbor_maximum_prefix_out,
8169 neighbor_maximum_prefix_out_cmd,
8170 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out (1-4294967295)",
8171 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8172 "Maximum number of prefixes to be sent to this peer\n"
8173 "Maximum no. of prefix limit\n")
8174 {
8175 char base_xpath[XPATH_MAXLEN];
8176 char af_xpath[XPATH_MAXLEN];
8177 char attr_xpath[XPATH_MAXLEN];
8178 int idx_peer = 1;
8179 int idx_number = 3;
8180 afi_t afi = bgp_node_afi(vty);
8181 safi_t safi = bgp_node_safi(vty);
8182
8183 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8184 yang_afi_safi_value2identity(afi, safi));
8185 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8186 sizeof(base_xpath), af_xpath)
8187 < 0)
8188 return CMD_WARNING_CONFIG_FAILED;
8189
8190 snprintf(attr_xpath, sizeof(attr_xpath),
8191 "/%s/prefix-limit/direction-list[direction='out']",
8192 bgp_afi_safi_get_container_str(afi, safi));
8193 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8194
8195 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8196
8197 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8198 argv[idx_number]->arg);
8199
8200 return nb_cli_apply_changes(vty, base_xpath);
8201 }
8202
8203 DEFUN_YANG(no_neighbor_maximum_prefix_out,
8204 no_neighbor_maximum_prefix_out_cmd,
8205 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out",
8206 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8207 "Maximum number of prefixes to be sent to this peer\n")
8208 {
8209 char base_xpath[XPATH_MAXLEN];
8210 char af_xpath[XPATH_MAXLEN];
8211 char attr_xpath[XPATH_MAXLEN];
8212 int idx_peer = 2;
8213 afi_t afi = bgp_node_afi(vty);
8214 safi_t safi = bgp_node_safi(vty);
8215
8216 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8217 yang_afi_safi_value2identity(afi, safi));
8218 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8219 sizeof(base_xpath), af_xpath)
8220 < 0)
8221 return CMD_WARNING_CONFIG_FAILED;
8222
8223 snprintf(attr_xpath, sizeof(attr_xpath),
8224 "/%s/prefix-limit/direction-list[direction='out']",
8225 bgp_afi_safi_get_container_str(afi, safi));
8226 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8227
8228 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
8229
8230 return nb_cli_apply_changes(vty, base_xpath);
8231 }
8232
8233 /* Maximum number of prefix configuration. Prefix count is different
8234 for each peer configuration. So this configuration can be set for
8235 each peer configuration. */
8236 DEFUN_YANG(neighbor_maximum_prefix,
8237 neighbor_maximum_prefix_cmd,
8238 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
8239 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8240 "Maximum number of prefix accept from this peer\n"
8241 "maximum no. of prefix limit\n"
8242 "Force checking all received routes not only accepted\n")
8243 {
8244 int idx_peer = 1;
8245 int idx_number = 3;
8246 int idx_force = 0;
8247 char base_xpath[XPATH_MAXLEN];
8248 char af_xpath[XPATH_MAXLEN];
8249 char attr_xpath[XPATH_MAXLEN];
8250 afi_t afi = bgp_node_afi(vty);
8251 safi_t safi = bgp_node_safi(vty);
8252
8253 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8254 yang_afi_safi_value2identity(afi, safi));
8255 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8256 sizeof(base_xpath), af_xpath)
8257 < 0)
8258 return CMD_WARNING_CONFIG_FAILED;
8259
8260 snprintf(attr_xpath, sizeof(attr_xpath),
8261 "/%s/prefix-limit/direction-list[direction='in']",
8262 bgp_afi_safi_get_container_str(afi, safi));
8263 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8264
8265 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8266
8267 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8268 argv[idx_number]->arg);
8269 if (argv_find(argv, argc, "force", &idx_force))
8270 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8271 "true");
8272
8273 return nb_cli_apply_changes(vty, base_xpath);
8274 }
8275
8276 ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
8277 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
8278 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8279 "Maximum number of prefix accept from this peer\n"
8280 "maximum no. of prefix limit\n"
8281 "Force checking all received routes not only accepted\n")
8282
8283 DEFUN_YANG(neighbor_maximum_prefix_threshold,
8284 neighbor_maximum_prefix_threshold_cmd,
8285 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
8286 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8287 "Maximum number of prefix accept from this peer\n"
8288 "maximum no. of prefix limit\n"
8289 "Threshold value (%) at which to generate a warning msg\n"
8290 "Force checking all received routes not only accepted\n")
8291 {
8292 int idx_peer = 1;
8293 int idx_number = 3;
8294 int idx_number_2 = 4;
8295 int idx_force = 0;
8296 char base_xpath[XPATH_MAXLEN];
8297 char af_xpath[XPATH_MAXLEN];
8298 char attr_xpath[XPATH_MAXLEN];
8299 afi_t afi = bgp_node_afi(vty);
8300 safi_t safi = bgp_node_safi(vty);
8301
8302 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8303 yang_afi_safi_value2identity(afi, safi));
8304 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8305 sizeof(base_xpath), af_xpath)
8306 < 0)
8307 return CMD_WARNING_CONFIG_FAILED;
8308
8309 snprintf(attr_xpath, sizeof(attr_xpath),
8310 "/%s/prefix-limit/direction-list[direction='in']",
8311 bgp_afi_safi_get_container_str(afi, safi));
8312 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8313
8314 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8315
8316 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8317 argv[idx_number]->arg);
8318
8319 nb_cli_enqueue_change(vty, "./options/shutdown-threshold-pct",
8320 NB_OP_MODIFY, argv[idx_number_2]->arg);
8321
8322 if (argv_find(argv, argc, "force", &idx_force))
8323 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8324 "true");
8325
8326 return nb_cli_apply_changes(vty, base_xpath);
8327 }
8328
8329 ALIAS_HIDDEN(
8330 neighbor_maximum_prefix_threshold,
8331 neighbor_maximum_prefix_threshold_hidden_cmd,
8332 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
8333 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8334 "Maximum number of prefix accept from this peer\n"
8335 "maximum no. of prefix limit\n"
8336 "Threshold value (%) at which to generate a warning msg\n"
8337 "Force checking all received routes not only accepted\n")
8338
8339 DEFUN_YANG(neighbor_maximum_prefix_warning,
8340 neighbor_maximum_prefix_warning_cmd,
8341 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
8342 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8343 "Maximum number of prefix accept from this peer\n"
8344 "maximum no. of prefix limit\n"
8345 "Only give warning message when limit is exceeded\n"
8346 "Force checking all received routes not only accepted\n")
8347 {
8348 int idx_peer = 1;
8349 int idx_number = 3;
8350 int idx_force = 0;
8351 char base_xpath[XPATH_MAXLEN];
8352 char af_xpath[XPATH_MAXLEN];
8353 char attr_xpath[XPATH_MAXLEN];
8354 afi_t afi = bgp_node_afi(vty);
8355 safi_t safi = bgp_node_safi(vty);
8356
8357 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8358 yang_afi_safi_value2identity(afi, safi));
8359 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8360 sizeof(base_xpath), af_xpath)
8361 < 0)
8362 return CMD_WARNING_CONFIG_FAILED;
8363
8364 snprintf(attr_xpath, sizeof(attr_xpath),
8365 "/%s/prefix-limit/direction-list[direction='in']",
8366 bgp_afi_safi_get_container_str(afi, safi));
8367 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8368
8369 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8370
8371 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8372 argv[idx_number]->arg);
8373
8374 nb_cli_enqueue_change(vty, "./options/warning-only", NB_OP_MODIFY,
8375 "true");
8376 if (argv_find(argv, argc, "force", &idx_force))
8377 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8378 "true");
8379
8380 return nb_cli_apply_changes(vty, base_xpath);
8381 }
8382
8383 ALIAS_HIDDEN(
8384 neighbor_maximum_prefix_warning,
8385 neighbor_maximum_prefix_warning_hidden_cmd,
8386 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
8387 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8388 "Maximum number of prefix accept from this peer\n"
8389 "maximum no. of prefix limit\n"
8390 "Only give warning message when limit is exceeded\n"
8391 "Force checking all received routes not only accepted\n")
8392
8393 DEFUN_YANG(neighbor_maximum_prefix_threshold_warning,
8394 neighbor_maximum_prefix_threshold_warning_cmd,
8395 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
8396 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8397 "Maximum number of prefix accept from this peer\n"
8398 "maximum no. of prefix limit\n"
8399 "Threshold value (%) at which to generate a warning msg\n"
8400 "Only give warning message when limit is exceeded\n"
8401 "Force checking all received routes not only accepted\n")
8402 {
8403 int idx_peer = 1;
8404 int idx_number = 3;
8405 int idx_number_2 = 4;
8406 int idx_force = 0;
8407 char base_xpath[XPATH_MAXLEN];
8408 char af_xpath[XPATH_MAXLEN];
8409 char attr_xpath[XPATH_MAXLEN];
8410 afi_t afi = bgp_node_afi(vty);
8411 safi_t safi = bgp_node_safi(vty);
8412
8413 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8414 yang_afi_safi_value2identity(afi, safi));
8415 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8416 sizeof(base_xpath), af_xpath)
8417 < 0)
8418 return CMD_WARNING_CONFIG_FAILED;
8419
8420 snprintf(attr_xpath, sizeof(attr_xpath),
8421 "/%s/prefix-limit/direction-list[direction='in']",
8422 bgp_afi_safi_get_container_str(afi, safi));
8423 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8424
8425 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8426
8427 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8428 argv[idx_number]->arg);
8429 nb_cli_enqueue_change(vty, "./options/tw-shutdown-threshold-pct",
8430 NB_OP_MODIFY, argv[idx_number_2]->arg);
8431 nb_cli_enqueue_change(vty, "./options/tw-warning-only", NB_OP_MODIFY,
8432 "true");
8433 if (argv_find(argv, argc, "force", &idx_force))
8434 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8435 "true");
8436
8437 return nb_cli_apply_changes(vty, base_xpath);
8438 }
8439
8440 ALIAS_HIDDEN(
8441 neighbor_maximum_prefix_threshold_warning,
8442 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
8443 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
8444 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8445 "Maximum number of prefix accept from this peer\n"
8446 "maximum no. of prefix limit\n"
8447 "Threshold value (%) at which to generate a warning msg\n"
8448 "Only give warning message when limit is exceeded\n"
8449 "Force checking all received routes not only accepted\n")
8450
8451 DEFUN_YANG(neighbor_maximum_prefix_restart,
8452 neighbor_maximum_prefix_restart_cmd,
8453 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8454 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8455 "Maximum number of prefix accept from this peer\n"
8456 "maximum no. of prefix limit\n"
8457 "Restart bgp connection after limit is exceeded\n"
8458 "Restart interval in minutes\n"
8459 "Force checking all received routes not only accepted\n")
8460 {
8461 int idx_peer = 1;
8462 int idx_number = 3;
8463 int idx_number_2 = 5;
8464 int idx_force = 0;
8465 char base_xpath[XPATH_MAXLEN];
8466 char af_xpath[XPATH_MAXLEN];
8467 char attr_xpath[XPATH_MAXLEN];
8468 afi_t afi = bgp_node_afi(vty);
8469 safi_t safi = bgp_node_safi(vty);
8470
8471 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8472 yang_afi_safi_value2identity(afi, safi));
8473 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8474 sizeof(base_xpath), af_xpath)
8475 < 0)
8476 return CMD_WARNING_CONFIG_FAILED;
8477
8478 snprintf(attr_xpath, sizeof(attr_xpath),
8479 "/%s/prefix-limit/direction-list[direction='in']",
8480 bgp_afi_safi_get_container_str(afi, safi));
8481 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8482
8483 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8484
8485 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8486 argv[idx_number]->arg);
8487 nb_cli_enqueue_change(vty, "./options/restart-timer", NB_OP_MODIFY,
8488 argv[idx_number_2]->arg);
8489 if (argv_find(argv, argc, "force", &idx_force))
8490 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8491 "true");
8492
8493 return nb_cli_apply_changes(vty, base_xpath);
8494 }
8495
8496 ALIAS_HIDDEN(
8497 neighbor_maximum_prefix_restart,
8498 neighbor_maximum_prefix_restart_hidden_cmd,
8499 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8500 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8501 "Maximum number of prefix accept from this peer\n"
8502 "maximum no. of prefix limit\n"
8503 "Restart bgp connection after limit is exceeded\n"
8504 "Restart interval in minutes\n"
8505 "Force checking all received routes not only accepted\n")
8506
8507 DEFUN_YANG(neighbor_maximum_prefix_threshold_restart,
8508 neighbor_maximum_prefix_threshold_restart_cmd,
8509 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8510 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8511 "Maximum number of prefixes to accept from this peer\n"
8512 "maximum no. of prefix limit\n"
8513 "Threshold value (%) at which to generate a warning msg\n"
8514 "Restart bgp connection after limit is exceeded\n"
8515 "Restart interval in minutes\n"
8516 "Force checking all received routes not only accepted\n")
8517 {
8518 int idx_peer = 1;
8519 int idx_number = 3;
8520 int idx_number_2 = 4;
8521 int idx_number_3 = 6;
8522 int idx_force = 0;
8523 char base_xpath[XPATH_MAXLEN];
8524 char af_xpath[XPATH_MAXLEN];
8525 char attr_xpath[XPATH_MAXLEN];
8526 afi_t afi = bgp_node_afi(vty);
8527 safi_t safi = bgp_node_safi(vty);
8528
8529 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8530 yang_afi_safi_value2identity(afi, safi));
8531 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8532 sizeof(base_xpath), af_xpath)
8533 < 0)
8534 return CMD_WARNING_CONFIG_FAILED;
8535
8536 snprintf(attr_xpath, sizeof(attr_xpath),
8537 "/%s/prefix-limit/direction-list[direction='in']",
8538 bgp_afi_safi_get_container_str(afi, safi));
8539 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8540
8541 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8542
8543 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8544 argv[idx_number]->arg);
8545 nb_cli_enqueue_change(vty, "./options/tr-shutdown-threshold-pct",
8546 NB_OP_MODIFY, argv[idx_number_2]->arg);
8547 nb_cli_enqueue_change(vty, "./options/tr-restart-timer", NB_OP_MODIFY,
8548 argv[idx_number_3]->arg);
8549 if (argv_find(argv, argc, "force", &idx_force))
8550 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8551 "true");
8552
8553 return nb_cli_apply_changes(vty, base_xpath);
8554 }
8555
8556 ALIAS_HIDDEN(
8557 neighbor_maximum_prefix_threshold_restart,
8558 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
8559 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8560 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8561 "Maximum number of prefixes to accept from this peer\n"
8562 "maximum no. of prefix limit\n"
8563 "Threshold value (%) at which to generate a warning msg\n"
8564 "Restart bgp connection after limit is exceeded\n"
8565 "Restart interval in minutes\n"
8566 "Force checking all received routes not only accepted\n")
8567
8568 DEFUN_YANG(no_neighbor_maximum_prefix,
8569 no_neighbor_maximum_prefix_cmd,
8570 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8571 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8572 "Maximum number of prefixes to accept from this peer\n"
8573 "maximum no. of prefix limit\n"
8574 "Threshold value (%) at which to generate a warning msg\n"
8575 "Restart bgp connection after limit is exceeded\n"
8576 "Restart interval in minutes\n"
8577 "Only give warning message when limit is exceeded\n"
8578 "Force checking all received routes not only accepted\n")
8579 {
8580 int idx_peer = 2;
8581 char base_xpath[XPATH_MAXLEN];
8582 char af_xpath[XPATH_MAXLEN];
8583 char attr_xpath[XPATH_MAXLEN];
8584 afi_t afi = bgp_node_afi(vty);
8585 safi_t safi = bgp_node_safi(vty);
8586
8587 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8588 yang_afi_safi_value2identity(afi, safi));
8589 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8590 sizeof(base_xpath), af_xpath)
8591 < 0)
8592 return CMD_WARNING_CONFIG_FAILED;
8593
8594 snprintf(attr_xpath, sizeof(attr_xpath),
8595 "/%s/prefix-limit/direction-list[direction='in']",
8596 bgp_afi_safi_get_container_str(afi, safi));
8597 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8598
8599 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
8600
8601 return nb_cli_apply_changes(vty, base_xpath);
8602 }
8603
8604 ALIAS_HIDDEN(
8605 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
8606 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8607 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8608 "Maximum number of prefixes to accept from this peer\n"
8609 "maximum no. of prefix limit\n"
8610 "Threshold value (%) at which to generate a warning msg\n"
8611 "Restart bgp connection after limit is exceeded\n"
8612 "Restart interval in minutes\n"
8613 "Only give warning message when limit is exceeded\n"
8614 "Force checking all received routes not only accepted\n")
8615
8616
8617 /* "neighbor allowas-in" */
8618 DEFUN (neighbor_allowas_in,
8619 neighbor_allowas_in_cmd,
8620 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8621 NEIGHBOR_STR
8622 NEIGHBOR_ADDR_STR2
8623 "Accept as-path with my AS present in it\n"
8624 "Number of occurrences of AS number\n"
8625 "Only accept my AS in the as-path if the route was originated in my AS\n")
8626 {
8627 int idx_peer = 1;
8628 int idx_number_origin = 3;
8629 int ret;
8630 int origin = 0;
8631 struct peer *peer;
8632 int allow_num = 0;
8633
8634 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8635 if (!peer)
8636 return CMD_WARNING_CONFIG_FAILED;
8637
8638 if (argc <= idx_number_origin)
8639 allow_num = 3;
8640 else {
8641 if (argv[idx_number_origin]->type == WORD_TKN)
8642 origin = 1;
8643 else
8644 allow_num = atoi(argv[idx_number_origin]->arg);
8645 }
8646
8647 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8648 allow_num, origin);
8649
8650 return bgp_vty_return(vty, ret);
8651 }
8652
8653 ALIAS_HIDDEN(
8654 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
8655 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8656 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8657 "Accept as-path with my AS present in it\n"
8658 "Number of occurrences of AS number\n"
8659 "Only accept my AS in the as-path if the route was originated in my AS\n")
8660
8661 DEFUN (no_neighbor_allowas_in,
8662 no_neighbor_allowas_in_cmd,
8663 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8664 NO_STR
8665 NEIGHBOR_STR
8666 NEIGHBOR_ADDR_STR2
8667 "allow local ASN appears in aspath attribute\n"
8668 "Number of occurrences of AS number\n"
8669 "Only accept my AS in the as-path if the route was originated in my AS\n")
8670 {
8671 int idx_peer = 2;
8672 int ret;
8673 struct peer *peer;
8674
8675 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8676 if (!peer)
8677 return CMD_WARNING_CONFIG_FAILED;
8678
8679 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
8680 bgp_node_safi(vty));
8681
8682 return bgp_vty_return(vty, ret);
8683 }
8684
8685 ALIAS_HIDDEN(
8686 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
8687 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8688 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8689 "allow local ASN appears in aspath attribute\n"
8690 "Number of occurrences of AS number\n"
8691 "Only accept my AS in the as-path if the route was originated in my AS\n")
8692
8693 DEFUN_YANG (neighbor_ttl_security,
8694 neighbor_ttl_security_cmd,
8695 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8696 NEIGHBOR_STR
8697 NEIGHBOR_ADDR_STR2
8698 "BGP ttl-security parameters\n"
8699 "Specify the maximum number of hops to the BGP peer\n"
8700 "Number of hops to BGP peer\n")
8701 {
8702 int idx_peer = 1;
8703 int idx_number = 4;
8704 char base_xpath[XPATH_MAXLEN];
8705
8706 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8707 sizeof(base_xpath), NULL)
8708 < 0)
8709 return CMD_WARNING_CONFIG_FAILED;
8710
8711 nb_cli_enqueue_change(vty, "./ttl-security", NB_OP_MODIFY,
8712 argv[idx_number]->arg);
8713
8714 return nb_cli_apply_changes(vty, base_xpath);
8715 }
8716
8717 DEFUN_YANG(no_neighbor_ttl_security,
8718 no_neighbor_ttl_security_cmd,
8719 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8720 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8721 "BGP ttl-security parameters\n"
8722 "Specify the maximum number of hops to the BGP peer\n"
8723 "Number of hops to BGP peer\n")
8724 {
8725 int idx_peer = 2;
8726 char base_xpath[XPATH_MAXLEN];
8727
8728 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8729 sizeof(base_xpath), NULL)
8730 < 0)
8731 return CMD_WARNING_CONFIG_FAILED;
8732
8733 nb_cli_enqueue_change(vty, "./ttl-security", NB_OP_DESTROY, NULL);
8734
8735 return nb_cli_apply_changes(vty, base_xpath);
8736 }
8737
8738 DEFUN (neighbor_addpath_tx_all_paths,
8739 neighbor_addpath_tx_all_paths_cmd,
8740 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8741 NEIGHBOR_STR
8742 NEIGHBOR_ADDR_STR2
8743 "Use addpath to advertise all paths to a neighbor\n")
8744 {
8745 int idx_peer = 1;
8746 struct peer *peer;
8747
8748 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8749 if (!peer)
8750 return CMD_WARNING_CONFIG_FAILED;
8751
8752 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8753 BGP_ADDPATH_ALL);
8754 return CMD_SUCCESS;
8755 }
8756
8757 ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
8758 neighbor_addpath_tx_all_paths_hidden_cmd,
8759 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8760 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8761 "Use addpath to advertise all paths to a neighbor\n")
8762
8763 DEFUN (no_neighbor_addpath_tx_all_paths,
8764 no_neighbor_addpath_tx_all_paths_cmd,
8765 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8766 NO_STR
8767 NEIGHBOR_STR
8768 NEIGHBOR_ADDR_STR2
8769 "Use addpath to advertise all paths to a neighbor\n")
8770 {
8771 int idx_peer = 2;
8772 struct peer *peer;
8773
8774 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8775 if (!peer)
8776 return CMD_WARNING_CONFIG_FAILED;
8777
8778 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8779 != BGP_ADDPATH_ALL) {
8780 vty_out(vty,
8781 "%% Peer not currently configured to transmit all paths.");
8782 return CMD_WARNING_CONFIG_FAILED;
8783 }
8784
8785 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8786 BGP_ADDPATH_NONE);
8787
8788 return CMD_SUCCESS;
8789 }
8790
8791 ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
8792 no_neighbor_addpath_tx_all_paths_hidden_cmd,
8793 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8794 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8795 "Use addpath to advertise all paths to a neighbor\n")
8796
8797 DEFUN (neighbor_addpath_tx_bestpath_per_as,
8798 neighbor_addpath_tx_bestpath_per_as_cmd,
8799 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8800 NEIGHBOR_STR
8801 NEIGHBOR_ADDR_STR2
8802 "Use addpath to advertise the bestpath per each neighboring AS\n")
8803 {
8804 int idx_peer = 1;
8805 struct peer *peer;
8806
8807 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8808 if (!peer)
8809 return CMD_WARNING_CONFIG_FAILED;
8810
8811 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8812 BGP_ADDPATH_BEST_PER_AS);
8813
8814 return CMD_SUCCESS;
8815 }
8816
8817 ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
8818 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8819 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8820 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8821 "Use addpath to advertise the bestpath per each neighboring AS\n")
8822
8823 DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
8824 no_neighbor_addpath_tx_bestpath_per_as_cmd,
8825 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8826 NO_STR
8827 NEIGHBOR_STR
8828 NEIGHBOR_ADDR_STR2
8829 "Use addpath to advertise the bestpath per each neighboring AS\n")
8830 {
8831 int idx_peer = 2;
8832 struct peer *peer;
8833
8834 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8835 if (!peer)
8836 return CMD_WARNING_CONFIG_FAILED;
8837
8838 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8839 != BGP_ADDPATH_BEST_PER_AS) {
8840 vty_out(vty,
8841 "%% Peer not currently configured to transmit all best path per as.");
8842 return CMD_WARNING_CONFIG_FAILED;
8843 }
8844
8845 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8846 BGP_ADDPATH_NONE);
8847
8848 return CMD_SUCCESS;
8849 }
8850
8851 ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
8852 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8853 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8854 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8855 "Use addpath to advertise the bestpath per each neighboring AS\n")
8856
8857 DEFPY(
8858 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
8859 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8860 NEIGHBOR_STR
8861 NEIGHBOR_ADDR_STR2
8862 "Detect AS loops before sending to neighbor\n")
8863 {
8864 struct peer *peer;
8865
8866 peer = peer_and_group_lookup_vty(vty, neighbor);
8867 if (!peer)
8868 return CMD_WARNING_CONFIG_FAILED;
8869
8870 peer->as_path_loop_detection = true;
8871
8872 return CMD_SUCCESS;
8873 }
8874
8875 DEFPY(
8876 no_neighbor_aspath_loop_detection,
8877 no_neighbor_aspath_loop_detection_cmd,
8878 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8879 NO_STR
8880 NEIGHBOR_STR
8881 NEIGHBOR_ADDR_STR2
8882 "Detect AS loops before sending to neighbor\n")
8883 {
8884 struct peer *peer;
8885
8886 peer = peer_and_group_lookup_vty(vty, neighbor);
8887 if (!peer)
8888 return CMD_WARNING_CONFIG_FAILED;
8889
8890 peer->as_path_loop_detection = false;
8891
8892 return CMD_SUCCESS;
8893 }
8894
8895 DEFPY(neighbor_damp,
8896 neighbor_damp_cmd,
8897 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor dampening [(1-45)$half [(1-20000)$reuse (1-20000)$suppress (1-255)$max]]",
8898 NEIGHBOR_STR
8899 NEIGHBOR_ADDR_STR2
8900 "Enable neighbor route-flap dampening\n"
8901 "Half-life time for the penalty\n"
8902 "Value to start reusing a route\n"
8903 "Value to start suppressing a route\n"
8904 "Maximum duration to suppress a stable route\n")
8905 {
8906 struct peer *peer = peer_and_group_lookup_vty(vty, neighbor);
8907
8908 if (!peer)
8909 return CMD_WARNING_CONFIG_FAILED;
8910 if (!half)
8911 half = DEFAULT_HALF_LIFE;
8912 if (!reuse) {
8913 reuse = DEFAULT_REUSE;
8914 suppress = DEFAULT_SUPPRESS;
8915 max = half * 4;
8916 }
8917 if (suppress < reuse) {
8918 vty_out(vty,
8919 "Suppress value cannot be less than reuse value\n");
8920 return CMD_WARNING_CONFIG_FAILED;
8921 }
8922 bgp_peer_damp_enable(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8923 half * 60, reuse, suppress, max * 60);
8924 return CMD_SUCCESS;
8925 }
8926
8927 DEFPY(no_neighbor_damp,
8928 no_neighbor_damp_cmd,
8929 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor dampening [HALF [REUSE SUPPRESS MAX]]",
8930 NO_STR
8931 NEIGHBOR_STR
8932 NEIGHBOR_ADDR_STR2
8933 "Enable neighbor route-flap dampening\n"
8934 "Half-life time for the penalty\n"
8935 "Value to start reusing a route\n"
8936 "Value to start suppressing a route\n"
8937 "Maximum duration to suppress a stable route\n")
8938 {
8939 struct peer *peer = peer_and_group_lookup_vty(vty, neighbor);
8940
8941 if (!peer)
8942 return CMD_WARNING_CONFIG_FAILED;
8943 bgp_peer_damp_disable(peer, bgp_node_afi(vty), bgp_node_safi(vty));
8944 return CMD_SUCCESS;
8945 }
8946
8947 DEFPY (show_ip_bgp_neighbor_damp_param,
8948 show_ip_bgp_neighbor_damp_param_cmd,
8949 "show [ip] bgp [<ipv4|ipv6> [unicast]] neighbors <A.B.C.D|X:X::X:X|WORD>$neighbor dampening parameters [json]$json",
8950 SHOW_STR
8951 IP_STR
8952 BGP_STR
8953 BGP_AFI_HELP_STR
8954 "Address Family modifier\n"
8955 NEIGHBOR_STR
8956 NEIGHBOR_ADDR_STR2
8957 "Neighbor route-flap dampening information\n"
8958 "Display detail of configured dampening parameters\n"
8959 JSON_STR)
8960 {
8961 bool use_json = false;
8962 int idx = 0;
8963 afi_t afi = AFI_IP;
8964 safi_t safi = SAFI_UNICAST;
8965 struct peer *peer;
8966
8967 if (argv_find(argv, argc, "ip", &idx))
8968 afi = AFI_IP;
8969 if (argv_find(argv, argc, "ipv4", &idx))
8970 afi = AFI_IP;
8971 if (argv_find(argv, argc, "ipv6", &idx))
8972 afi = AFI_IP6;
8973 peer = peer_and_group_lookup_vty(vty, neighbor);
8974 if (!peer)
8975 return CMD_WARNING;
8976 if (json)
8977 use_json = true;
8978 bgp_show_peer_dampening_parameters(vty, peer, afi, safi, use_json);
8979 return CMD_SUCCESS;
8980 }
8981
8982 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
8983 struct ecommunity **list, bool is_rt6)
8984 {
8985 struct ecommunity *ecom = NULL;
8986 struct ecommunity *ecomadd;
8987
8988 for (; argc; --argc, ++argv) {
8989 if (is_rt6)
8990 ecomadd = ecommunity_str2com_ipv6(argv[0]->arg,
8991 ECOMMUNITY_ROUTE_TARGET,
8992 0);
8993 else
8994 ecomadd = ecommunity_str2com(argv[0]->arg,
8995 ECOMMUNITY_ROUTE_TARGET,
8996 0);
8997 if (!ecomadd) {
8998 vty_out(vty, "Malformed community-list value\n");
8999 if (ecom)
9000 ecommunity_free(&ecom);
9001 return CMD_WARNING_CONFIG_FAILED;
9002 }
9003
9004 if (ecom) {
9005 ecommunity_merge(ecom, ecomadd);
9006 ecommunity_free(&ecomadd);
9007 } else {
9008 ecom = ecomadd;
9009 }
9010 }
9011
9012 if (*list) {
9013 ecommunity_free(&*list);
9014 }
9015 *list = ecom;
9016
9017 return CMD_SUCCESS;
9018 }
9019
9020 bool vpn_policy_check_import(struct bgp *bgp, afi_t afi, safi_t safi,
9021 bool v2vimport, char *errmsg, size_t errmsg_len)
9022 {
9023 if (!v2vimport) {
9024 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9025 BGP_CONFIG_VRF_TO_VRF_IMPORT)
9026 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9027 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
9028 snprintf(
9029 errmsg, errmsg_len, "%s",
9030 "%% error: Please unconfigure import vrf commands before using vpn commands");
9031 return false;
9032 }
9033 } else {
9034 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9035 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
9036 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9037 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
9038 snprintf(
9039 errmsg, errmsg_len, "%s",
9040 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands");
9041 return false;
9042 }
9043 }
9044 return true;
9045 }
9046
9047 /*
9048 * v2vimport is true if we are handling a `import vrf ...` command
9049 */
9050 static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
9051 {
9052 afi_t afi;
9053
9054 switch (vty->node) {
9055 case BGP_IPV4_NODE:
9056 afi = AFI_IP;
9057 break;
9058 case BGP_IPV6_NODE:
9059 afi = AFI_IP6;
9060 break;
9061 default:
9062 vty_out(vty,
9063 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
9064 return AFI_MAX;
9065 }
9066
9067 if (!v2vimport) {
9068 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9069 BGP_CONFIG_VRF_TO_VRF_IMPORT)
9070 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9071 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
9072 vty_out(vty,
9073 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
9074 return AFI_MAX;
9075 }
9076 } else {
9077 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9078 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
9079 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9080 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
9081 vty_out(vty,
9082 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
9083 return AFI_MAX;
9084 }
9085 }
9086 return afi;
9087 }
9088
9089 DEFPY_YANG(
9090 af_rd_vpn_export,
9091 af_rd_vpn_export_cmd,
9092 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
9093 NO_STR
9094 "Specify route distinguisher\n"
9095 "Between current address-family and vpn\n"
9096 "For routes leaked from current address-family to vpn\n"
9097 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
9098 {
9099 char base_xpath[XPATH_MAXLEN];
9100 afi_t afi;
9101 safi_t safi;
9102 int idx = 0;
9103
9104 afi = bgp_node_afi(vty);
9105 safi = bgp_node_safi(vty);
9106
9107 snprintf(
9108 base_xpath, sizeof(base_xpath),
9109 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config",
9110 yang_afi_safi_value2identity(afi, safi),
9111 bgp_afi_safi_get_container_str(afi, safi));
9112
9113 if (argv_find(argv, argc, "no", &idx))
9114 nb_cli_enqueue_change(vty, "./rd", NB_OP_DESTROY, NULL);
9115 else
9116 nb_cli_enqueue_change(vty, "./rd", NB_OP_MODIFY, rd_str);
9117
9118 return nb_cli_apply_changes(vty, base_xpath);
9119 }
9120
9121 void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rd(
9122 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9123 {
9124 int indent = 2;
9125
9126 vty_out(vty, "%*srd vpn export %s\n", indent, "",
9127 yang_dnode_get_string(dnode, NULL));
9128 }
9129
9130 ALIAS (af_rd_vpn_export,
9131 af_no_rd_vpn_export_cmd,
9132 "no rd vpn export",
9133 NO_STR
9134 "Specify route distinguisher\n"
9135 "Between current address-family and vpn\n"
9136 "For routes leaked from current address-family to vpn\n")
9137
9138 DEFPY (af_label_vpn_export,
9139 af_label_vpn_export_cmd,
9140 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
9141 NO_STR
9142 "label value for VRF\n"
9143 "Between current address-family and vpn\n"
9144 "For routes leaked from current address-family to vpn\n"
9145 "Label Value <0-1048575>\n"
9146 "Automatically assign a label\n")
9147 {
9148 VTY_DECLVAR_CONTEXT(bgp, bgp);
9149 mpls_label_t label = MPLS_LABEL_NONE;
9150 afi_t afi;
9151 int idx = 0;
9152 bool yes = true;
9153
9154 if (argv_find(argv, argc, "no", &idx))
9155 yes = false;
9156
9157 /* If "no ...", squash trailing parameter */
9158 if (!yes)
9159 label_auto = NULL;
9160
9161 if (yes) {
9162 if (!label_auto)
9163 label = label_val; /* parser should force unsigned */
9164 }
9165
9166 afi = vpn_policy_getafi(vty, bgp, false);
9167 if (afi == AFI_MAX)
9168 return CMD_WARNING_CONFIG_FAILED;
9169
9170
9171 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9172 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
9173 /* no change */
9174 return CMD_SUCCESS;
9175
9176 /*
9177 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
9178 */
9179 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9180 bgp_get_default(), bgp);
9181
9182 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9183 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
9184
9185 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
9186
9187 /*
9188 * label has previously been automatically
9189 * assigned by labelpool: release it
9190 *
9191 * NB if tovpn_label == MPLS_LABEL_NONE it
9192 * means the automatic assignment is in flight
9193 * and therefore the labelpool callback must
9194 * detect that the auto label is not needed.
9195 */
9196
9197 bgp_lp_release(LP_TYPE_VRF,
9198 &bgp->vpn_policy[afi],
9199 bgp->vpn_policy[afi].tovpn_label);
9200 }
9201 UNSET_FLAG(bgp->vpn_policy[afi].flags,
9202 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
9203 }
9204
9205 bgp->vpn_policy[afi].tovpn_label = label;
9206 if (label_auto) {
9207 SET_FLAG(bgp->vpn_policy[afi].flags,
9208 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
9209 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
9210 vpn_leak_label_callback);
9211 }
9212
9213 /* post-change: re-export vpn routes */
9214 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9215 bgp_get_default(), bgp);
9216
9217 hook_call(bgp_snmp_update_last_changed, bgp);
9218 return CMD_SUCCESS;
9219 }
9220
9221 ALIAS (af_label_vpn_export,
9222 af_no_label_vpn_export_cmd,
9223 "no label vpn export",
9224 NO_STR
9225 "label value for VRF\n"
9226 "Between current address-family and vpn\n"
9227 "For routes leaked from current address-family to vpn\n")
9228
9229 DEFPY_YANG (af_nexthop_vpn_export,
9230 af_nexthop_vpn_export_cmd,
9231 "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
9232 NO_STR
9233 "Specify next hop to use for VRF advertised prefixes\n"
9234 "Between current address-family and vpn\n"
9235 "For routes leaked from current address-family to vpn\n"
9236 "IPv4 prefix\n"
9237 "IPv6 prefix\n")
9238 {
9239 char base_xpath[XPATH_MAXLEN];
9240 afi_t afi;
9241 safi_t safi;
9242 int idx = 0;
9243 struct prefix p;
9244
9245 if (!no) {
9246 if (!nexthop_su) {
9247 vty_out(vty, "%% Nexthop required\n");
9248 return CMD_WARNING_CONFIG_FAILED;
9249 }
9250 if (!sockunion2hostprefix(nexthop_su, &p))
9251 return CMD_WARNING_CONFIG_FAILED;
9252 }
9253
9254 afi = bgp_node_afi(vty);
9255 safi = bgp_node_safi(vty);
9256
9257 snprintf(
9258 base_xpath, sizeof(base_xpath),
9259 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config",
9260 yang_afi_safi_value2identity(afi, safi),
9261 bgp_afi_safi_get_container_str(afi, safi));
9262
9263 if (argv_find(argv, argc, "no", &idx))
9264 nb_cli_enqueue_change(vty, "./nexthop", NB_OP_DESTROY, NULL);
9265 else
9266 nb_cli_enqueue_change(vty, "./nexthop", NB_OP_MODIFY,
9267 nexthop_su_str);
9268
9269 return nb_cli_apply_changes(vty, base_xpath);
9270 }
9271
9272 void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_nexthop(
9273 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9274 {
9275 int indent = 2;
9276
9277 vty_out(vty, "%*snexthop vpn export %s\n", indent, "",
9278 yang_dnode_get_string(dnode, NULL));
9279 }
9280
9281 static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
9282 {
9283 if (!strcmp(dstr, "import")) {
9284 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9285 } else if (!strcmp(dstr, "export")) {
9286 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9287 } else if (!strcmp(dstr, "both")) {
9288 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9289 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9290 } else {
9291 vty_out(vty, "%% direction parse error\n");
9292 return CMD_WARNING_CONFIG_FAILED;
9293 }
9294 return CMD_SUCCESS;
9295 }
9296
9297 DEFPY (af_rt_vpn_imexport,
9298 af_rt_vpn_imexport_cmd,
9299 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
9300 NO_STR
9301 "Specify route target list\n"
9302 "Specify route target list\n"
9303 "Between current address-family and vpn\n"
9304 "For routes leaked from vpn to current address-family: match any\n"
9305 "For routes leaked from current address-family to vpn: set\n"
9306 "both import: match any and export: set\n"
9307 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
9308 {
9309 VTY_DECLVAR_CONTEXT(bgp, bgp);
9310 int ret;
9311 struct ecommunity *ecom = NULL;
9312 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
9313 vpn_policy_direction_t dir;
9314 afi_t afi;
9315 int idx = 0;
9316 bool yes = true;
9317
9318 if (argv_find(argv, argc, "no", &idx))
9319 yes = false;
9320
9321 afi = vpn_policy_getafi(vty, bgp, false);
9322 if (afi == AFI_MAX)
9323 return CMD_WARNING_CONFIG_FAILED;
9324
9325 ret = vpn_policy_getdirs(vty, direction_str, dodir);
9326 if (ret != CMD_SUCCESS)
9327 return ret;
9328
9329 if (yes) {
9330 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9331 vty_out(vty, "%% Missing RTLIST\n");
9332 return CMD_WARNING_CONFIG_FAILED;
9333 }
9334 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, false);
9335 if (ret != CMD_SUCCESS) {
9336 return ret;
9337 }
9338 }
9339
9340 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9341 if (!dodir[dir])
9342 continue;
9343
9344 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9345
9346 if (yes) {
9347 if (bgp->vpn_policy[afi].rtlist[dir])
9348 ecommunity_free(
9349 &bgp->vpn_policy[afi].rtlist[dir]);
9350 bgp->vpn_policy[afi].rtlist[dir] =
9351 ecommunity_dup(ecom);
9352 } else {
9353 if (bgp->vpn_policy[afi].rtlist[dir])
9354 ecommunity_free(
9355 &bgp->vpn_policy[afi].rtlist[dir]);
9356 bgp->vpn_policy[afi].rtlist[dir] = NULL;
9357 }
9358
9359 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9360 }
9361
9362 if (ecom)
9363 ecommunity_free(&ecom);
9364
9365 return CMD_SUCCESS;
9366 }
9367
9368 ALIAS (af_rt_vpn_imexport,
9369 af_no_rt_vpn_imexport_cmd,
9370 "no <rt|route-target> vpn <import|export|both>$direction_str",
9371 NO_STR
9372 "Specify route target list\n"
9373 "Specify route target list\n"
9374 "Between current address-family and vpn\n"
9375 "For routes leaked from vpn to current address-family\n"
9376 "For routes leaked from current address-family to vpn\n"
9377 "both import and export\n")
9378
9379 DEFPY_YANG (af_route_map_vpn_imexport,
9380 af_route_map_vpn_imexport_cmd,
9381 /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
9382 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
9383 NO_STR
9384 "Specify route map\n"
9385 "Between current address-family and vpn\n"
9386 "For routes leaked from vpn to current address-family\n"
9387 "For routes leaked from current address-family to vpn\n"
9388 "name of route-map\n")
9389 {
9390 char base_xpath[XPATH_MAXLEN];
9391 afi_t afi;
9392 safi_t safi;
9393 int idx = 0;
9394
9395 afi = bgp_node_afi(vty);
9396 safi = bgp_node_safi(vty);
9397
9398 snprintf(
9399 base_xpath, sizeof(base_xpath),
9400 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config",
9401 yang_afi_safi_value2identity(afi, safi),
9402 bgp_afi_safi_get_container_str(afi, safi));
9403
9404 if (argv_find(argv, argc, "no", &idx)) {
9405 if (!strcmp(direction_str, "import"))
9406 nb_cli_enqueue_change(vty, "./rmap-import",
9407 NB_OP_DESTROY, NULL);
9408 else if (!strcmp(direction_str, "export"))
9409 nb_cli_enqueue_change(vty, "./rmap-export",
9410 NB_OP_DESTROY, NULL);
9411 } else {
9412 if (!strcmp(direction_str, "import"))
9413 nb_cli_enqueue_change(vty, "./rmap-import",
9414 NB_OP_MODIFY, rmap_str);
9415 if (!strcmp(direction_str, "export"))
9416 nb_cli_enqueue_change(vty, "./rmap-export",
9417 NB_OP_MODIFY, rmap_str);
9418 }
9419 return nb_cli_apply_changes(vty, base_xpath);
9420 }
9421
9422 void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rmap_import(
9423 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9424 {
9425 int indent = 2;
9426
9427 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
9428 yang_dnode_get_string(dnode, NULL));
9429 }
9430
9431 void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rmap_export(
9432 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9433 {
9434 int indent = 2;
9435
9436 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
9437 yang_dnode_get_string(dnode, NULL));
9438 }
9439
9440 ALIAS (af_route_map_vpn_imexport,
9441 af_no_route_map_vpn_imexport_cmd,
9442 "no route-map vpn <import|export>$direction_str",
9443 NO_STR
9444 "Specify route map\n"
9445 "Between current address-family and vpn\n"
9446 "For routes leaked from vpn to current address-family\n"
9447 "For routes leaked from current address-family to vpn\n")
9448
9449 DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
9450 "import vrf route-map RMAP$rmap_str",
9451 "Import routes from another VRF\n"
9452 "Vrf routes being filtered\n"
9453 "Specify route map\n"
9454 "name of route-map\n")
9455 {
9456 VTY_DECLVAR_CONTEXT(bgp, bgp);
9457 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
9458 afi_t afi;
9459 struct bgp *bgp_default;
9460
9461 afi = vpn_policy_getafi(vty, bgp, true);
9462 if (afi == AFI_MAX)
9463 return CMD_WARNING_CONFIG_FAILED;
9464
9465 bgp_default = bgp_get_default();
9466 if (!bgp_default) {
9467 int32_t ret;
9468 as_t as = bgp->as;
9469
9470 /* Auto-create assuming the same AS */
9471 ret = bgp_get_vty(&bgp_default, &as, NULL,
9472 BGP_INSTANCE_TYPE_DEFAULT);
9473
9474 if (ret) {
9475 vty_out(vty,
9476 "VRF default is not configured as a bgp instance\n");
9477 return CMD_WARNING;
9478 }
9479 }
9480
9481 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9482
9483 if (bgp->vpn_policy[afi].rmap_name[dir])
9484 XFREE(MTYPE_ROUTE_MAP_NAME,
9485 bgp->vpn_policy[afi].rmap_name[dir]);
9486 bgp->vpn_policy[afi].rmap_name[dir] =
9487 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
9488 bgp->vpn_policy[afi].rmap[dir] =
9489 route_map_lookup_warn_noexist(vty, rmap_str);
9490 if (!bgp->vpn_policy[afi].rmap[dir])
9491 return CMD_SUCCESS;
9492
9493 SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9494 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9495
9496 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9497
9498 return CMD_SUCCESS;
9499 }
9500
9501 DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
9502 "no import vrf route-map [RMAP$rmap_str]",
9503 NO_STR
9504 "Import routes from another VRF\n"
9505 "Vrf routes being filtered\n"
9506 "Specify route map\n"
9507 "name of route-map\n")
9508 {
9509 VTY_DECLVAR_CONTEXT(bgp, bgp);
9510 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
9511 afi_t afi;
9512
9513 afi = vpn_policy_getafi(vty, bgp, true);
9514 if (afi == AFI_MAX)
9515 return CMD_WARNING_CONFIG_FAILED;
9516
9517 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9518
9519 if (bgp->vpn_policy[afi].rmap_name[dir])
9520 XFREE(MTYPE_ROUTE_MAP_NAME,
9521 bgp->vpn_policy[afi].rmap_name[dir]);
9522 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9523 bgp->vpn_policy[afi].rmap[dir] = NULL;
9524
9525 if (bgp->vpn_policy[afi].import_vrf->count == 0)
9526 UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9527 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9528
9529 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9530
9531 return CMD_SUCCESS;
9532 }
9533
9534 DEFPY_YANG(bgp_imexport_vrf,
9535 bgp_imexport_vrf_cmd,
9536 "[no] import vrf VIEWVRFNAME$import_name",
9537 NO_STR
9538 "Import routes from another VRF\n"
9539 "VRF to import from\n"
9540 "The name of the VRF\n")
9541 {
9542 char base_xpath[XPATH_MAXLEN];
9543 safi_t safi;
9544 afi_t afi;
9545 int32_t idx = 0;
9546
9547 if (import_name == NULL) {
9548 vty_out(vty, "%% Missing import name\n");
9549 return CMD_WARNING;
9550 }
9551
9552 if (strcmp(import_name, "route-map") == 0) {
9553 vty_out(vty, "%% Must include route-map name\n");
9554 return CMD_WARNING;
9555 }
9556
9557 afi = bgp_node_afi(vty);
9558 safi = bgp_node_safi(vty);
9559
9560 snprintf(
9561 base_xpath, sizeof(base_xpath),
9562 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config/import-vrf-list[vrf='%s']",
9563 yang_afi_safi_value2identity(afi, safi),
9564 bgp_afi_safi_get_container_str(afi, safi), import_name);
9565
9566 if (argv_find(argv, argc, "no", &idx))
9567 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
9568 else
9569 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
9570
9571 return nb_cli_apply_changes(vty, base_xpath);
9572 }
9573
9574 void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_import_vrfs(
9575 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9576 {
9577 vty_out(vty, " import vrf %s\n",
9578 yang_dnode_get_string(dnode, "./vrf"));
9579 }
9580
9581 /* This command is valid only in a bgp vrf instance or the default instance */
9582 DEFPY_YANG (bgp_imexport_vpn,
9583 bgp_imexport_vpn_cmd,
9584 "[no] <import|export>$direction_str vpn",
9585 NO_STR
9586 "Import routes to this address-family\n"
9587 "Export routes from this address-family\n"
9588 "to/from default instance VPN RIB\n")
9589 {
9590 char base_xpath[XPATH_MAXLEN];
9591 safi_t safi;
9592 afi_t afi;
9593 int32_t idx = 0;
9594
9595 afi = bgp_node_afi(vty);
9596 safi = bgp_node_safi(vty);
9597
9598 if (!strcmp(direction_str, "import")) {
9599 snprintf(
9600 base_xpath, sizeof(base_xpath),
9601 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config/import-vpn",
9602 yang_afi_safi_value2identity(afi, safi),
9603 bgp_afi_safi_get_container_str(afi, safi));
9604 } else if (!strcmp(direction_str, "export")) {
9605 snprintf(
9606 base_xpath, sizeof(base_xpath),
9607 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config/export-vpn",
9608 yang_afi_safi_value2identity(afi, safi),
9609 bgp_afi_safi_get_container_str(afi, safi));
9610 } else {
9611 vty_out(vty, "%% unknown direction %s\n", direction_str);
9612 return CMD_WARNING_CONFIG_FAILED;
9613 }
9614
9615 if (argv_find(argv, argc, "no", &idx))
9616 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
9617 else
9618 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, "true");
9619
9620 return nb_cli_apply_changes(vty, base_xpath);
9621 }
9622
9623 void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_import_vpn(
9624 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9625 {
9626 if (yang_dnode_get_bool(dnode, NULL))
9627 vty_out(vty, " import vpn\n");
9628 }
9629
9630 void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_export_vpn(
9631 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9632 {
9633 if (yang_dnode_get_bool(dnode, NULL))
9634 vty_out(vty, " export vpn\n");
9635 }
9636
9637 DEFPY (af_routetarget_import,
9638 af_routetarget_import_cmd,
9639 "[no] <rt|route-target|route-target6|rt6> redirect import RTLIST...",
9640 NO_STR
9641 "Specify route target list\n"
9642 "Specify route target list\n"
9643 "Specify route target list\n"
9644 "Specify route target list\n"
9645 "Flow-spec redirect type route target\n"
9646 "Import routes to this address-family\n"
9647 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN|IPV6:MN)\n")
9648 {
9649 VTY_DECLVAR_CONTEXT(bgp, bgp);
9650 int ret;
9651 struct ecommunity *ecom = NULL;
9652 afi_t afi;
9653 int idx = 0, idx_unused = 0;
9654 bool yes = true;
9655 bool rt6 = false;
9656
9657 if (argv_find(argv, argc, "no", &idx))
9658 yes = false;
9659
9660 if (argv_find(argv, argc, "rt6", &idx_unused) ||
9661 argv_find(argv, argc, "route-target6", &idx_unused))
9662 rt6 = true;
9663
9664 afi = vpn_policy_getafi(vty, bgp, false);
9665 if (afi == AFI_MAX)
9666 return CMD_WARNING_CONFIG_FAILED;
9667
9668 if (rt6 && afi != AFI_IP6)
9669 return CMD_WARNING_CONFIG_FAILED;
9670
9671 if (yes) {
9672 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9673 vty_out(vty, "%% Missing RTLIST\n");
9674 return CMD_WARNING_CONFIG_FAILED;
9675 }
9676 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, rt6);
9677 if (ret != CMD_SUCCESS)
9678 return ret;
9679 }
9680
9681 if (yes) {
9682 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9683 ecommunity_free(&bgp->vpn_policy[afi]
9684 .import_redirect_rtlist);
9685 bgp->vpn_policy[afi].import_redirect_rtlist =
9686 ecommunity_dup(ecom);
9687 } else {
9688 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9689 ecommunity_free(&bgp->vpn_policy[afi]
9690 .import_redirect_rtlist);
9691 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
9692 }
9693
9694 if (ecom)
9695 ecommunity_free(&ecom);
9696
9697 return CMD_SUCCESS;
9698 }
9699
9700 void cli_show_bgp_global_afi_safi_header(struct vty *vty,
9701 struct lyd_node *dnode,
9702 bool show_defaults)
9703 {
9704 const char *af_name;
9705 afi_t afi;
9706 safi_t safi;
9707
9708 af_name = yang_dnode_get_string(dnode, "./afi-safi-name");
9709 yang_afi_safi_identity2value(af_name, &afi, &safi);
9710
9711 vty_out(vty, " !\n address-family ");
9712 if (afi == AFI_IP) {
9713 if (safi == SAFI_UNICAST)
9714 vty_out(vty, "ipv4 unicast");
9715 else if (safi == SAFI_LABELED_UNICAST)
9716 vty_out(vty, "ipv4 labeled-unicast");
9717 else if (safi == SAFI_MULTICAST)
9718 vty_out(vty, "ipv4 multicast");
9719 else if (safi == SAFI_MPLS_VPN)
9720 vty_out(vty, "ipv4 vpn");
9721 else if (safi == SAFI_ENCAP)
9722 vty_out(vty, "ipv4 encap");
9723 else if (safi == SAFI_FLOWSPEC)
9724 vty_out(vty, "ipv4 flowspec");
9725 } else if (afi == AFI_IP6) {
9726 if (safi == SAFI_UNICAST)
9727 vty_out(vty, "ipv6 unicast");
9728 else if (safi == SAFI_LABELED_UNICAST)
9729 vty_out(vty, "ipv6 labeled-unicast");
9730 else if (safi == SAFI_MULTICAST)
9731 vty_out(vty, "ipv6 multicast");
9732 else if (safi == SAFI_MPLS_VPN)
9733 vty_out(vty, "ipv6 vpn");
9734 else if (safi == SAFI_ENCAP)
9735 vty_out(vty, "ipv6 encap");
9736 else if (safi == SAFI_FLOWSPEC)
9737 vty_out(vty, "ipv6 flowspec");
9738 } else if (afi == AFI_L2VPN) {
9739 if (safi == SAFI_EVPN)
9740 vty_out(vty, "l2vpn evpn");
9741 }
9742 vty_out(vty, "\n");
9743 }
9744
9745 DEFUN_NOSH (address_family_ipv4_safi,
9746 address_family_ipv4_safi_cmd,
9747 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9748 "Enter Address Family command mode\n"
9749 "Address Family\n"
9750 BGP_SAFI_WITH_LABEL_HELP_STR)
9751 {
9752
9753 safi_t safi = SAFI_UNICAST;
9754 const struct lyd_node *vrf_dnode, *bgp_glb_dnode;
9755 const char *vrf_name = NULL;
9756
9757 if (argc == 3) {
9758 safi = bgp_vty_safi_from_str(argv[2]->text);
9759
9760 bgp_glb_dnode = yang_dnode_get(vty->candidate_config->dnode,
9761 VTY_CURR_XPATH);
9762 vrf_dnode = yang_dnode_get_parent(bgp_glb_dnode,
9763 "control-plane-protocol");
9764 vrf_name = yang_dnode_get_string(vrf_dnode, "./vrf");
9765
9766 if (!strmatch(vrf_name, VRF_DEFAULT_NAME)
9767 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9768 && safi != SAFI_EVPN) {
9769 vty_out(vty,
9770 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9771 return CMD_WARNING_CONFIG_FAILED;
9772 }
9773 }
9774 vty->node = bgp_node_type(AFI_IP, safi);
9775
9776 return CMD_SUCCESS;
9777 }
9778
9779 DEFUN_NOSH (address_family_ipv6_safi,
9780 address_family_ipv6_safi_cmd,
9781 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9782 "Enter Address Family command mode\n"
9783 "Address Family\n"
9784 BGP_SAFI_WITH_LABEL_HELP_STR)
9785 {
9786 safi_t safi = SAFI_UNICAST;
9787 const struct lyd_node *vrf_dnode, *bgp_glb_dnode;
9788 const char *vrf_name = NULL;
9789
9790 if (argc == 3) {
9791 safi = bgp_vty_safi_from_str(argv[2]->text);
9792 bgp_glb_dnode = yang_dnode_get(vty->candidate_config->dnode,
9793 VTY_CURR_XPATH);
9794 vrf_dnode = yang_dnode_get_parent(bgp_glb_dnode,
9795 "control-plane-protocol");
9796 vrf_name = yang_dnode_get_string(vrf_dnode, "./vrf");
9797
9798 if (!strmatch(vrf_name, VRF_DEFAULT_NAME)
9799 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9800 && safi != SAFI_EVPN) {
9801 vty_out(vty,
9802 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9803 return CMD_WARNING_CONFIG_FAILED;
9804 }
9805 }
9806 vty->node = bgp_node_type(AFI_IP6, safi);
9807
9808 return CMD_SUCCESS;
9809 }
9810
9811 #ifdef KEEP_OLD_VPN_COMMANDS
9812 DEFUN_NOSH (address_family_vpnv4,
9813 address_family_vpnv4_cmd,
9814 "address-family vpnv4 [unicast]",
9815 "Enter Address Family command mode\n"
9816 "Address Family\n"
9817 "Address Family modifier\n")
9818 {
9819 vty->node = BGP_VPNV4_NODE;
9820 return CMD_SUCCESS;
9821 }
9822
9823 DEFUN_NOSH (address_family_vpnv6,
9824 address_family_vpnv6_cmd,
9825 "address-family vpnv6 [unicast]",
9826 "Enter Address Family command mode\n"
9827 "Address Family\n"
9828 "Address Family modifier\n")
9829 {
9830 vty->node = BGP_VPNV6_NODE;
9831 return CMD_SUCCESS;
9832 }
9833 #endif /* KEEP_OLD_VPN_COMMANDS */
9834
9835 DEFUN_NOSH (address_family_evpn,
9836 address_family_evpn_cmd,
9837 "address-family l2vpn evpn",
9838 "Enter Address Family command mode\n"
9839 "Address Family\n"
9840 "Address Family modifier\n")
9841 {
9842 VTY_DECLVAR_CONTEXT(bgp, bgp);
9843 vty->node = BGP_EVPN_NODE;
9844 return CMD_SUCCESS;
9845 }
9846
9847 DEFUN_NOSH (exit_address_family,
9848 exit_address_family_cmd,
9849 "exit-address-family",
9850 "Exit from Address Family configuration mode\n")
9851 {
9852 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
9853 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
9854 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
9855 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
9856 || vty->node == BGP_EVPN_NODE
9857 || vty->node == BGP_FLOWSPECV4_NODE
9858 || vty->node == BGP_FLOWSPECV6_NODE)
9859 vty->node = BGP_NODE;
9860 return CMD_SUCCESS;
9861 }
9862
9863 void cli_show_bgp_global_afi_safi_header_end(struct vty *vty,
9864 struct lyd_node *dnode
9865 __attribute__((__unused__)))
9866 {
9867 vty_out(vty, " exit-address-family\n");
9868 }
9869
9870 /* Recalculate bestpath and re-advertise a prefix */
9871 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
9872 const char *ip_str, afi_t afi, safi_t safi,
9873 struct prefix_rd *prd)
9874 {
9875 int ret;
9876 struct prefix match;
9877 struct bgp_dest *dest;
9878 struct bgp_dest *rm;
9879 struct bgp *bgp;
9880 struct bgp_table *table;
9881 struct bgp_table *rib;
9882
9883 /* BGP structure lookup. */
9884 if (view_name) {
9885 bgp = bgp_lookup_by_name(view_name);
9886 if (bgp == NULL) {
9887 vty_out(vty, "%% Can't find BGP instance %s\n",
9888 view_name);
9889 return CMD_WARNING;
9890 }
9891 } else {
9892 bgp = bgp_get_default();
9893 if (bgp == NULL) {
9894 vty_out(vty, "%% No BGP process is configured\n");
9895 return CMD_WARNING;
9896 }
9897 }
9898
9899 /* Check IP address argument. */
9900 ret = str2prefix(ip_str, &match);
9901 if (!ret) {
9902 vty_out(vty, "%% address is malformed\n");
9903 return CMD_WARNING;
9904 }
9905
9906 match.family = afi2family(afi);
9907 rib = bgp->rib[afi][safi];
9908
9909 if (safi == SAFI_MPLS_VPN) {
9910 for (dest = bgp_table_top(rib); dest;
9911 dest = bgp_route_next(dest)) {
9912 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
9913
9914 if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
9915 continue;
9916
9917 table = bgp_dest_get_bgp_table_info(dest);
9918 if (table == NULL)
9919 continue;
9920
9921 if ((rm = bgp_node_match(table, &match)) != NULL) {
9922 const struct prefix *rm_p =
9923 bgp_dest_get_prefix(rm);
9924
9925 if (rm_p->prefixlen == match.prefixlen) {
9926 SET_FLAG(rm->flags,
9927 BGP_NODE_USER_CLEAR);
9928 bgp_process(bgp, rm, afi, safi);
9929 }
9930 bgp_dest_unlock_node(rm);
9931 }
9932 }
9933 } else {
9934 if ((dest = bgp_node_match(rib, &match)) != NULL) {
9935 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
9936
9937 if (dest_p->prefixlen == match.prefixlen) {
9938 SET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
9939 bgp_process(bgp, dest, afi, safi);
9940 }
9941 bgp_dest_unlock_node(dest);
9942 }
9943 }
9944
9945 return CMD_SUCCESS;
9946 }
9947
9948 /* one clear bgp command to rule them all */
9949 DEFUN (clear_ip_bgp_all,
9950 clear_ip_bgp_all_cmd,
9951 "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>]",
9952 CLEAR_STR
9953 IP_STR
9954 BGP_STR
9955 BGP_INSTANCE_HELP_STR
9956 BGP_AFI_HELP_STR
9957 "Address Family\n"
9958 BGP_SAFI_WITH_LABEL_HELP_STR
9959 "Address Family modifier\n"
9960 "Clear all peers\n"
9961 "BGP IPv4 neighbor to clear\n"
9962 "BGP IPv6 neighbor to clear\n"
9963 "BGP neighbor on interface to clear\n"
9964 "Clear peers with the AS number\n"
9965 "Clear all external peers\n"
9966 "Clear all members of peer-group\n"
9967 "BGP peer-group name\n"
9968 BGP_SOFT_STR
9969 BGP_SOFT_IN_STR
9970 BGP_SOFT_OUT_STR
9971 BGP_SOFT_IN_STR
9972 "Push out prefix-list ORF and do inbound soft reconfig\n"
9973 BGP_SOFT_OUT_STR)
9974 {
9975 char *vrf = NULL;
9976
9977 afi_t afi = AFI_UNSPEC;
9978 safi_t safi = SAFI_UNSPEC;
9979 enum clear_sort clr_sort = clear_peer;
9980 enum bgp_clear_type clr_type;
9981 char *clr_arg = NULL;
9982
9983 int idx = 0;
9984 char errmsg[BUFSIZ] = {'\0'};
9985 int ret;
9986
9987 /* clear [ip] bgp */
9988 if (argv_find(argv, argc, "ip", &idx))
9989 afi = AFI_IP;
9990
9991 /* [<vrf> VIEWVRFNAME] */
9992 if (argv_find(argv, argc, "vrf", &idx)) {
9993 vrf = argv[idx + 1]->arg;
9994 idx += 2;
9995 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9996 vrf = NULL;
9997 } else if (argv_find(argv, argc, "view", &idx)) {
9998 /* [<view> VIEWVRFNAME] */
9999 vrf = argv[idx + 1]->arg;
10000 idx += 2;
10001 }
10002 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
10003 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
10004 argv_find_and_parse_safi(argv, argc, &idx, &safi);
10005
10006 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
10007 if (argv_find(argv, argc, "*", &idx)) {
10008 clr_sort = clear_all;
10009 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
10010 clr_sort = clear_peer;
10011 clr_arg = argv[idx]->arg;
10012 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
10013 clr_sort = clear_peer;
10014 clr_arg = argv[idx]->arg;
10015 } else if (argv_find(argv, argc, "peer-group", &idx)) {
10016 clr_sort = clear_group;
10017 idx++;
10018 clr_arg = argv[idx]->arg;
10019 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
10020 clr_sort = clear_peer;
10021 clr_arg = argv[idx]->arg;
10022 } else if (argv_find(argv, argc, "WORD", &idx)) {
10023 clr_sort = clear_peer;
10024 clr_arg = argv[idx]->arg;
10025 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
10026 clr_sort = clear_as;
10027 clr_arg = argv[idx]->arg;
10028 } else if (argv_find(argv, argc, "external", &idx)) {
10029 clr_sort = clear_external;
10030 }
10031
10032 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
10033 if (argv_find(argv, argc, "soft", &idx)) {
10034 if (argv_find(argv, argc, "in", &idx)
10035 || argv_find(argv, argc, "out", &idx))
10036 clr_type = strmatch(argv[idx]->text, "in")
10037 ? BGP_CLEAR_SOFT_IN
10038 : BGP_CLEAR_SOFT_OUT;
10039 else
10040 clr_type = BGP_CLEAR_SOFT_BOTH;
10041 } else if (argv_find(argv, argc, "in", &idx)) {
10042 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
10043 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
10044 : BGP_CLEAR_SOFT_IN;
10045 } else if (argv_find(argv, argc, "out", &idx)) {
10046 clr_type = BGP_CLEAR_SOFT_OUT;
10047 } else
10048 clr_type = BGP_CLEAR_SOFT_NONE;
10049
10050 ret = bgp_clear_vty(vrf, afi, safi, clr_sort, clr_type, clr_arg, errmsg,
10051 sizeof(errmsg));
10052 if (ret != NB_OK)
10053 vty_out(vty, "Error description: %s\n", errmsg);
10054
10055 return ret;
10056 }
10057
10058 DEFUN (clear_ip_bgp_prefix,
10059 clear_ip_bgp_prefix_cmd,
10060 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
10061 CLEAR_STR
10062 IP_STR
10063 BGP_STR
10064 BGP_INSTANCE_HELP_STR
10065 "Clear bestpath and re-advertise\n"
10066 "IPv4 prefix\n")
10067 {
10068 char *vrf = NULL;
10069 char *prefix = NULL;
10070
10071 int idx = 0;
10072
10073 /* [<view|vrf> VIEWVRFNAME] */
10074 if (argv_find(argv, argc, "vrf", &idx)) {
10075 vrf = argv[idx + 1]->arg;
10076 idx += 2;
10077 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
10078 vrf = NULL;
10079 } else if (argv_find(argv, argc, "view", &idx)) {
10080 /* [<view> VIEWVRFNAME] */
10081 vrf = argv[idx + 1]->arg;
10082 idx += 2;
10083 }
10084
10085 prefix = argv[argc - 1]->arg;
10086
10087 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
10088 }
10089
10090 DEFUN (clear_bgp_ipv6_safi_prefix,
10091 clear_bgp_ipv6_safi_prefix_cmd,
10092 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
10093 CLEAR_STR
10094 IP_STR
10095 BGP_STR
10096 "Address Family\n"
10097 BGP_SAFI_HELP_STR
10098 "Clear bestpath and re-advertise\n"
10099 "IPv6 prefix\n")
10100 {
10101 int idx_safi = 0;
10102 int idx_ipv6_prefix = 0;
10103 safi_t safi = SAFI_UNICAST;
10104 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
10105 argv[idx_ipv6_prefix]->arg : NULL;
10106
10107 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
10108 return bgp_clear_prefix(
10109 vty, NULL, prefix, AFI_IP6,
10110 safi, NULL);
10111 }
10112
10113 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
10114 clear_bgp_instance_ipv6_safi_prefix_cmd,
10115 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
10116 CLEAR_STR
10117 IP_STR
10118 BGP_STR
10119 BGP_INSTANCE_HELP_STR
10120 "Address Family\n"
10121 BGP_SAFI_HELP_STR
10122 "Clear bestpath and re-advertise\n"
10123 "IPv6 prefix\n")
10124 {
10125 int idx_safi = 0;
10126 int idx_vrfview = 0;
10127 int idx_ipv6_prefix = 0;
10128 safi_t safi = SAFI_UNICAST;
10129 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
10130 argv[idx_ipv6_prefix]->arg : NULL;
10131 char *vrfview = NULL;
10132
10133 /* [<view|vrf> VIEWVRFNAME] */
10134 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
10135 vrfview = argv[idx_vrfview + 1]->arg;
10136 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
10137 vrfview = NULL;
10138 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
10139 /* [<view> VIEWVRFNAME] */
10140 vrfview = argv[idx_vrfview + 1]->arg;
10141 }
10142 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
10143
10144 return bgp_clear_prefix(
10145 vty, vrfview, prefix,
10146 AFI_IP6, safi, NULL);
10147 }
10148
10149 DEFUN (show_bgp_views,
10150 show_bgp_views_cmd,
10151 "show [ip] bgp views",
10152 SHOW_STR
10153 IP_STR
10154 BGP_STR
10155 "Show the defined BGP views\n")
10156 {
10157 struct list *inst = bm->bgp;
10158 struct listnode *node;
10159 struct bgp *bgp;
10160
10161 vty_out(vty, "Defined BGP views:\n");
10162 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10163 /* Skip VRFs. */
10164 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
10165 continue;
10166 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
10167 bgp->as);
10168 }
10169
10170 return CMD_SUCCESS;
10171 }
10172
10173 DEFUN (show_bgp_vrfs,
10174 show_bgp_vrfs_cmd,
10175 "show [ip] bgp vrfs [json]",
10176 SHOW_STR
10177 IP_STR
10178 BGP_STR
10179 "Show BGP VRFs\n"
10180 JSON_STR)
10181 {
10182 char buf[ETHER_ADDR_STRLEN];
10183 struct list *inst = bm->bgp;
10184 struct listnode *node;
10185 struct bgp *bgp;
10186 bool uj = use_json(argc, argv);
10187 json_object *json = NULL;
10188 json_object *json_vrfs = NULL;
10189 int count = 0;
10190
10191 if (uj) {
10192 json = json_object_new_object();
10193 json_vrfs = json_object_new_object();
10194 }
10195
10196 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10197 const char *name, *type;
10198 struct peer *peer;
10199 struct listnode *node2, *nnode2;
10200 int peers_cfg, peers_estb;
10201 json_object *json_vrf = NULL;
10202
10203 /* Skip Views. */
10204 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
10205 continue;
10206
10207 count++;
10208 if (!uj && count == 1) {
10209 vty_out(vty,
10210 "%4s %-5s %-16s %9s %10s %-37s\n",
10211 "Type", "Id", "routerId", "#PeersCfg",
10212 "#PeersEstb", "Name");
10213 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
10214 "L3-VNI", "RouterMAC", "Interface");
10215 }
10216
10217 peers_cfg = peers_estb = 0;
10218 if (uj)
10219 json_vrf = json_object_new_object();
10220
10221
10222 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
10223 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10224 continue;
10225 peers_cfg++;
10226 if (peer->status == Established)
10227 peers_estb++;
10228 }
10229
10230 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
10231 name = VRF_DEFAULT_NAME;
10232 type = "DFLT";
10233 } else {
10234 name = bgp->name;
10235 type = "VRF";
10236 }
10237
10238
10239 if (uj) {
10240 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10241 ? -1
10242 : (int64_t)bgp->vrf_id;
10243 char buf[BUFSIZ] = {0};
10244
10245 json_object_string_add(json_vrf, "type", type);
10246 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
10247 json_object_string_add(json_vrf, "routerId",
10248 inet_ntop(AF_INET,
10249 &bgp->router_id, buf,
10250 sizeof(buf)));
10251 json_object_int_add(json_vrf, "numConfiguredPeers",
10252 peers_cfg);
10253 json_object_int_add(json_vrf, "numEstablishedPeers",
10254 peers_estb);
10255
10256 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
10257 json_object_string_add(
10258 json_vrf, "rmac",
10259 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
10260 json_object_string_add(json_vrf, "interface",
10261 ifindex2ifname(bgp->l3vni_svi_ifindex,
10262 bgp->vrf_id));
10263 json_object_object_add(json_vrfs, name, json_vrf);
10264 } else {
10265 vty_out(vty, "%4s %-5d %-16pI4 %-9u %-10u %-37s\n",
10266 type,
10267 bgp->vrf_id == VRF_UNKNOWN ? -1
10268 : (int)bgp->vrf_id,
10269 &bgp->router_id, peers_cfg, peers_estb, name);
10270 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
10271 bgp->l3vni,
10272 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
10273 ifindex2ifname(bgp->l3vni_svi_ifindex,
10274 bgp->vrf_id));
10275 }
10276 }
10277
10278 if (uj) {
10279 json_object_object_add(json, "vrfs", json_vrfs);
10280
10281 json_object_int_add(json, "totalVrfs", count);
10282
10283 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10284 json, JSON_C_TO_STRING_PRETTY));
10285 json_object_free(json);
10286 } else {
10287 if (count)
10288 vty_out(vty,
10289 "\nTotal number of VRFs (including default): %d\n",
10290 count);
10291 }
10292
10293 return CMD_SUCCESS;
10294 }
10295
10296 DEFUN (show_bgp_mac_hash,
10297 show_bgp_mac_hash_cmd,
10298 "show bgp mac hash",
10299 SHOW_STR
10300 BGP_STR
10301 "Mac Address\n"
10302 "Mac Address database\n")
10303 {
10304 bgp_mac_dump_table(vty);
10305
10306 return CMD_SUCCESS;
10307 }
10308
10309 static void show_tip_entry(struct hash_bucket *bucket, void *args)
10310 {
10311 struct vty *vty = (struct vty *)args;
10312 struct tip_addr *tip = (struct tip_addr *)bucket->data;
10313
10314 vty_out(vty, "addr: %pI4, count: %d\n", &tip->addr, tip->refcnt);
10315 }
10316
10317 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
10318 {
10319 vty_out(vty, "self nexthop database:\n");
10320 bgp_nexthop_show_address_hash(vty, bgp);
10321
10322 vty_out(vty, "Tunnel-ip database:\n");
10323 hash_iterate(bgp->tip_hash,
10324 (void (*)(struct hash_bucket *, void *))show_tip_entry,
10325 vty);
10326 }
10327
10328 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
10329 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
10330 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
10331 "martian next-hops\n"
10332 "martian next-hop database\n")
10333 {
10334 struct bgp *bgp = NULL;
10335 int idx = 0;
10336 char *name = NULL;
10337
10338 /* [<vrf> VIEWVRFNAME] */
10339 if (argv_find(argv, argc, "vrf", &idx)) {
10340 name = argv[idx + 1]->arg;
10341 if (name && strmatch(name, VRF_DEFAULT_NAME))
10342 name = NULL;
10343 } else if (argv_find(argv, argc, "view", &idx))
10344 /* [<view> VIEWVRFNAME] */
10345 name = argv[idx + 1]->arg;
10346 if (name)
10347 bgp = bgp_lookup_by_name(name);
10348 else
10349 bgp = bgp_get_default();
10350
10351 if (!bgp) {
10352 vty_out(vty, "%% No BGP process is configured\n");
10353 return CMD_WARNING;
10354 }
10355 bgp_show_martian_nexthops(vty, bgp);
10356
10357 return CMD_SUCCESS;
10358 }
10359
10360 DEFUN (show_bgp_memory,
10361 show_bgp_memory_cmd,
10362 "show [ip] bgp memory",
10363 SHOW_STR
10364 IP_STR
10365 BGP_STR
10366 "Global BGP memory statistics\n")
10367 {
10368 char memstrbuf[MTYPE_MEMSTR_LEN];
10369 unsigned long count;
10370
10371 /* RIB related usage stats */
10372 count = mtype_stats_alloc(MTYPE_BGP_NODE);
10373 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
10374 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10375 count * sizeof(struct bgp_dest)));
10376
10377 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
10378 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
10379 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10380 count * sizeof(struct bgp_path_info)));
10381 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
10382 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
10383 count,
10384 mtype_memstr(
10385 memstrbuf, sizeof(memstrbuf),
10386 count * sizeof(struct bgp_path_info_extra)));
10387
10388 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
10389 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
10390 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10391 count * sizeof(struct bgp_static)));
10392
10393 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
10394 vty_out(vty, "%ld Packets, using %s of memory\n", count,
10395 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10396 count * sizeof(struct bpacket)));
10397
10398 /* Adj-In/Out */
10399 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
10400 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
10401 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10402 count * sizeof(struct bgp_adj_in)));
10403 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
10404 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
10405 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10406 count * sizeof(struct bgp_adj_out)));
10407
10408 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
10409 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
10410 count,
10411 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10412 count * sizeof(struct bgp_nexthop_cache)));
10413
10414 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
10415 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
10416 count,
10417 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10418 count * sizeof(struct bgp_damp_info)));
10419
10420 /* Attributes */
10421 count = attr_count();
10422 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
10423 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10424 count * sizeof(struct attr)));
10425
10426 if ((count = attr_unknown_count()))
10427 vty_out(vty, "%ld unknown attributes\n", count);
10428
10429 /* AS_PATH attributes */
10430 count = aspath_count();
10431 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
10432 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10433 count * sizeof(struct aspath)));
10434
10435 count = mtype_stats_alloc(MTYPE_AS_SEG);
10436 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
10437 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10438 count * sizeof(struct assegment)));
10439
10440 /* Other attributes */
10441 if ((count = community_count()))
10442 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
10443 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10444 count * sizeof(struct community)));
10445 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
10446 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
10447 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10448 count * sizeof(struct ecommunity)));
10449 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
10450 vty_out(vty,
10451 "%ld BGP large-community entries, using %s of memory\n",
10452 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10453 count * sizeof(struct lcommunity)));
10454
10455 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
10456 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
10457 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10458 count * sizeof(struct cluster_list)));
10459
10460 /* Peer related usage */
10461 count = mtype_stats_alloc(MTYPE_BGP_PEER);
10462 vty_out(vty, "%ld peers, using %s of memory\n", count,
10463 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10464 count * sizeof(struct peer)));
10465
10466 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
10467 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
10468 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10469 count * sizeof(struct peer_group)));
10470
10471 /* Other */
10472 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
10473 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
10474 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10475 count * sizeof(regex_t)));
10476 return CMD_SUCCESS;
10477 }
10478
10479 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
10480 {
10481 json_object *bestpath = json_object_new_object();
10482
10483 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
10484 json_object_string_add(bestpath, "asPath", "ignore");
10485
10486 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
10487 json_object_string_add(bestpath, "asPath", "confed");
10488
10489 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
10490 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
10491 json_object_string_add(bestpath, "multiPathRelax",
10492 "as-set");
10493 else
10494 json_object_string_add(bestpath, "multiPathRelax",
10495 "true");
10496 } else
10497 json_object_string_add(bestpath, "multiPathRelax", "false");
10498
10499 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
10500 json_object_string_add(bestpath, "compareRouterId", "true");
10501 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
10502 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
10503 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
10504 json_object_string_add(bestpath, "med", "confed");
10505 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
10506 json_object_string_add(bestpath, "med",
10507 "missing-as-worst");
10508 else
10509 json_object_string_add(bestpath, "med", "true");
10510 }
10511
10512 json_object_object_add(json, "bestPath", bestpath);
10513 }
10514
10515 /* Print the error code/subcode for why the peer is down */
10516 static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
10517 json_object *json_peer, bool use_json)
10518 {
10519 const char *code_str;
10520 const char *subcode_str;
10521
10522 if (use_json) {
10523 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10524 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10525 char errorcodesubcode_hexstr[5];
10526 char errorcodesubcode_str[256];
10527
10528 code_str = bgp_notify_code_str(peer->notify.code);
10529 subcode_str = bgp_notify_subcode_str(
10530 peer->notify.code,
10531 peer->notify.subcode);
10532
10533 snprintf(errorcodesubcode_hexstr,
10534 sizeof(errorcodesubcode_hexstr), "%02X%02X",
10535 peer->notify.code, peer->notify.subcode);
10536 json_object_string_add(json_peer,
10537 "lastErrorCodeSubcode",
10538 errorcodesubcode_hexstr);
10539 snprintf(errorcodesubcode_str, 255, "%s%s",
10540 code_str, subcode_str);
10541 json_object_string_add(json_peer,
10542 "lastNotificationReason",
10543 errorcodesubcode_str);
10544 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10545 && peer->notify.code == BGP_NOTIFY_CEASE
10546 && (peer->notify.subcode
10547 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10548 || peer->notify.subcode
10549 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10550 && peer->notify.length) {
10551 char msgbuf[1024];
10552 const char *msg_str;
10553
10554 msg_str = bgp_notify_admin_message(
10555 msgbuf, sizeof(msgbuf),
10556 (uint8_t *)peer->notify.data,
10557 peer->notify.length);
10558 if (msg_str)
10559 json_object_string_add(
10560 json_peer,
10561 "lastShutdownDescription",
10562 msg_str);
10563 }
10564
10565 }
10566 json_object_string_add(json_peer, "lastResetDueTo",
10567 peer_down_str[(int)peer->last_reset]);
10568 json_object_int_add(json_peer, "lastResetCode",
10569 peer->last_reset);
10570 } else {
10571 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10572 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10573 code_str = bgp_notify_code_str(peer->notify.code);
10574 subcode_str =
10575 bgp_notify_subcode_str(peer->notify.code,
10576 peer->notify.subcode);
10577 vty_out(vty, " Notification %s (%s%s)\n",
10578 peer->last_reset == PEER_DOWN_NOTIFY_SEND
10579 ? "sent"
10580 : "received",
10581 code_str, subcode_str);
10582 } else {
10583 vty_out(vty, " %s\n",
10584 peer_down_str[(int)peer->last_reset]);
10585 }
10586 }
10587 }
10588
10589 static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
10590 safi_t safi)
10591 {
10592 return ((peer->status != Established) ||
10593 !peer->afc_recv[afi][safi]);
10594 }
10595
10596 static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
10597 struct peer *peer, json_object *json_peer,
10598 int max_neighbor_width, bool use_json)
10599 {
10600 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10601 int len;
10602
10603 if (use_json) {
10604 if (peer_dynamic_neighbor(peer))
10605 json_object_boolean_true_add(json_peer,
10606 "dynamicPeer");
10607 if (peer->hostname)
10608 json_object_string_add(json_peer, "hostname",
10609 peer->hostname);
10610
10611 if (peer->domainname)
10612 json_object_string_add(json_peer, "domainname",
10613 peer->domainname);
10614 json_object_int_add(json_peer, "connectionsEstablished",
10615 peer->established);
10616 json_object_int_add(json_peer, "connectionsDropped",
10617 peer->dropped);
10618 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10619 use_json, json_peer);
10620 if (peer->status == Established)
10621 json_object_string_add(json_peer, "lastResetDueTo",
10622 "AFI/SAFI Not Negotiated");
10623 else
10624 bgp_show_peer_reset(NULL, peer, json_peer, true);
10625 } else {
10626 dn_flag[1] = '\0';
10627 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
10628 if (peer->hostname
10629 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
10630 len = vty_out(vty, "%s%s(%s)", dn_flag,
10631 peer->hostname, peer->host);
10632 else
10633 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10634
10635 /* pad the neighbor column with spaces */
10636 if (len < max_neighbor_width)
10637 vty_out(vty, "%*s", max_neighbor_width - len,
10638 " ");
10639 vty_out(vty, "%7d %7d %9s", peer->established,
10640 peer->dropped,
10641 peer_uptime(peer->uptime, timebuf,
10642 BGP_UPTIME_LEN, 0, NULL));
10643 if (peer->status == Established)
10644 vty_out(vty, " AFI/SAFI Not Negotiated\n");
10645 else
10646 bgp_show_peer_reset(vty, peer, NULL,
10647 false);
10648 }
10649 }
10650
10651 /* If the peer's description includes whitespaces
10652 * then return the first occurrence. Also strip description
10653 * to the given size if needed.
10654 */
10655 static char *bgp_peer_description_stripped(char *desc, uint32_t size)
10656 {
10657 static char stripped[BUFSIZ];
10658 char *pnt;
10659 uint32_t len = size > strlen(desc) ? strlen(desc) : size;
10660
10661 pnt = strchr(desc, ' ');
10662 if (pnt)
10663 len = size > (uint32_t)(pnt - desc) ? (uint32_t)(pnt - desc)
10664 : size;
10665
10666 strlcpy(stripped, desc, len + 1);
10667
10668 return stripped;
10669 }
10670
10671 /* Show BGP peer's summary information. */
10672 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
10673 uint8_t show_flags)
10674 {
10675 struct peer *peer;
10676 struct listnode *node, *nnode;
10677 unsigned int count = 0, dn_count = 0;
10678 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10679 char neighbor_buf[VTY_BUFSIZ];
10680 int neighbor_col_default_width = 16;
10681 int len, failed_count = 0;
10682 int max_neighbor_width = 0;
10683 int pfx_rcd_safi;
10684 json_object *json = NULL;
10685 json_object *json_peer = NULL;
10686 json_object *json_peers = NULL;
10687 struct peer_af *paf;
10688 struct bgp_filter *filter;
10689 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
10690 bool show_failed = CHECK_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
10691 bool show_established =
10692 CHECK_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
10693 bool show_wide = CHECK_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
10694
10695 /* labeled-unicast routes are installed in the unicast table so in order
10696 * to
10697 * display the correct PfxRcd value we must look at SAFI_UNICAST
10698 */
10699
10700 if (safi == SAFI_LABELED_UNICAST)
10701 pfx_rcd_safi = SAFI_UNICAST;
10702 else
10703 pfx_rcd_safi = safi;
10704
10705 if (use_json) {
10706 json = json_object_new_object();
10707 json_peers = json_object_new_object();
10708 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10709 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10710 continue;
10711
10712 if (peer->afc[afi][safi]) {
10713 /* See if we have at least a single failed peer */
10714 if (bgp_has_peer_failed(peer, afi, safi))
10715 failed_count++;
10716 count++;
10717 }
10718 if (peer_dynamic_neighbor(peer))
10719 dn_count++;
10720 }
10721
10722 } else {
10723 /* Loop over all neighbors that will be displayed to determine
10724 * how many
10725 * characters are needed for the Neighbor column
10726 */
10727 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10728 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10729 continue;
10730
10731 if (peer->afc[afi][safi]) {
10732 memset(dn_flag, '\0', sizeof(dn_flag));
10733 if (peer_dynamic_neighbor(peer))
10734 dn_flag[0] = '*';
10735
10736 if (peer->hostname
10737 && CHECK_FLAG(bgp->flags,
10738 BGP_FLAG_SHOW_HOSTNAME))
10739 snprintf(neighbor_buf,
10740 sizeof(neighbor_buf),
10741 "%s%s(%s) ", dn_flag,
10742 peer->hostname, peer->host);
10743 else
10744 snprintf(neighbor_buf,
10745 sizeof(neighbor_buf), "%s%s ",
10746 dn_flag, peer->host);
10747
10748 len = strlen(neighbor_buf);
10749
10750 if (len > max_neighbor_width)
10751 max_neighbor_width = len;
10752
10753 /* See if we have at least a single failed peer */
10754 if (bgp_has_peer_failed(peer, afi, safi))
10755 failed_count++;
10756 count++;
10757 }
10758 }
10759
10760 /* Originally we displayed the Neighbor column as 16
10761 * characters wide so make that the default
10762 */
10763 if (max_neighbor_width < neighbor_col_default_width)
10764 max_neighbor_width = neighbor_col_default_width;
10765 }
10766
10767 if (show_failed && !failed_count) {
10768 if (use_json) {
10769 json_object_int_add(json, "failedPeersCount", 0);
10770 json_object_int_add(json, "dynamicPeers", dn_count);
10771 json_object_int_add(json, "totalPeers", count);
10772
10773 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10774 json, JSON_C_TO_STRING_PRETTY));
10775 json_object_free(json);
10776 } else {
10777 vty_out(vty, "%% No failed BGP neighbors found\n");
10778 vty_out(vty, "\nTotal number of neighbors %d\n", count);
10779 }
10780 return CMD_SUCCESS;
10781 }
10782
10783 count = 0; /* Reset the value as its used again */
10784 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10785 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10786 continue;
10787
10788 if (!peer->afc[afi][safi])
10789 continue;
10790
10791 if (!count) {
10792 unsigned long ents;
10793 char memstrbuf[MTYPE_MEMSTR_LEN];
10794 int64_t vrf_id_ui;
10795
10796 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10797 ? -1
10798 : (int64_t)bgp->vrf_id;
10799
10800 /* Usage summary and header */
10801 if (use_json) {
10802 char buf[BUFSIZ] = {0};
10803
10804 json_object_string_add(
10805 json, "routerId",
10806 inet_ntop(AF_INET, &bgp->router_id, buf,
10807 sizeof(buf)));
10808 json_object_int_add(json, "as", bgp->as);
10809 json_object_int_add(json, "vrfId", vrf_id_ui);
10810 json_object_string_add(
10811 json, "vrfName",
10812 (bgp->inst_type
10813 == BGP_INSTANCE_TYPE_DEFAULT)
10814 ? VRF_DEFAULT_NAME
10815 : bgp->name);
10816 } else {
10817 vty_out(vty,
10818 "BGP router identifier %pI4, local AS number %u vrf-id %d",
10819 &bgp->router_id, bgp->as,
10820 bgp->vrf_id == VRF_UNKNOWN
10821 ? -1
10822 : (int)bgp->vrf_id);
10823 vty_out(vty, "\n");
10824 }
10825
10826 if (bgp_update_delay_configured(bgp)) {
10827 if (use_json) {
10828 json_object_int_add(
10829 json, "updateDelayLimit",
10830 bgp->v_update_delay);
10831
10832 if (bgp->v_update_delay
10833 != bgp->v_establish_wait)
10834 json_object_int_add(
10835 json,
10836 "updateDelayEstablishWait",
10837 bgp->v_establish_wait);
10838
10839 if (bgp_update_delay_active(bgp)) {
10840 json_object_string_add(
10841 json,
10842 "updateDelayFirstNeighbor",
10843 bgp->update_delay_begin_time);
10844 json_object_boolean_true_add(
10845 json,
10846 "updateDelayInProgress");
10847 } else {
10848 if (bgp->update_delay_over) {
10849 json_object_string_add(
10850 json,
10851 "updateDelayFirstNeighbor",
10852 bgp->update_delay_begin_time);
10853 json_object_string_add(
10854 json,
10855 "updateDelayBestpathResumed",
10856 bgp->update_delay_end_time);
10857 json_object_string_add(
10858 json,
10859 "updateDelayZebraUpdateResume",
10860 bgp->update_delay_zebra_resume_time);
10861 json_object_string_add(
10862 json,
10863 "updateDelayPeerUpdateResume",
10864 bgp->update_delay_peers_resume_time);
10865 }
10866 }
10867 } else {
10868 vty_out(vty,
10869 "Read-only mode update-delay limit: %d seconds\n",
10870 bgp->v_update_delay);
10871 if (bgp->v_update_delay
10872 != bgp->v_establish_wait)
10873 vty_out(vty,
10874 " Establish wait: %d seconds\n",
10875 bgp->v_establish_wait);
10876
10877 if (bgp_update_delay_active(bgp)) {
10878 vty_out(vty,
10879 " First neighbor established: %s\n",
10880 bgp->update_delay_begin_time);
10881 vty_out(vty,
10882 " Delay in progress\n");
10883 } else {
10884 if (bgp->update_delay_over) {
10885 vty_out(vty,
10886 " First neighbor established: %s\n",
10887 bgp->update_delay_begin_time);
10888 vty_out(vty,
10889 " Best-paths resumed: %s\n",
10890 bgp->update_delay_end_time);
10891 vty_out(vty,
10892 " zebra update resumed: %s\n",
10893 bgp->update_delay_zebra_resume_time);
10894 vty_out(vty,
10895 " peers update resumed: %s\n",
10896 bgp->update_delay_peers_resume_time);
10897 }
10898 }
10899 }
10900 }
10901
10902 if (use_json) {
10903 if (bgp_maxmed_onstartup_configured(bgp)
10904 && bgp->maxmed_active)
10905 json_object_boolean_true_add(
10906 json, "maxMedOnStartup");
10907 if (bgp->v_maxmed_admin)
10908 json_object_boolean_true_add(
10909 json, "maxMedAdministrative");
10910
10911 json_object_int_add(
10912 json, "tableVersion",
10913 bgp_table_version(bgp->rib[afi][safi]));
10914
10915 ents = bgp_table_count(bgp->rib[afi][safi]);
10916 json_object_int_add(json, "ribCount", ents);
10917 json_object_int_add(
10918 json, "ribMemory",
10919 ents * sizeof(struct bgp_dest));
10920
10921 ents = bgp->af_peer_count[afi][safi];
10922 json_object_int_add(json, "peerCount", ents);
10923 json_object_int_add(json, "peerMemory",
10924 ents * sizeof(struct peer));
10925
10926 if ((ents = listcount(bgp->group))) {
10927 json_object_int_add(
10928 json, "peerGroupCount", ents);
10929 json_object_int_add(
10930 json, "peerGroupMemory",
10931 ents * sizeof(struct
10932 peer_group));
10933 }
10934
10935 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10936 BGP_CONFIG_DAMPENING))
10937 json_object_boolean_true_add(
10938 json, "dampeningEnabled");
10939 } else {
10940 if (bgp_maxmed_onstartup_configured(bgp)
10941 && bgp->maxmed_active)
10942 vty_out(vty,
10943 "Max-med on-startup active\n");
10944 if (bgp->v_maxmed_admin)
10945 vty_out(vty,
10946 "Max-med administrative active\n");
10947
10948 vty_out(vty, "BGP table version %" PRIu64 "\n",
10949 bgp_table_version(bgp->rib[afi][safi]));
10950
10951 ents = bgp_table_count(bgp->rib[afi][safi]);
10952 vty_out(vty,
10953 "RIB entries %ld, using %s of memory\n",
10954 ents,
10955 mtype_memstr(
10956 memstrbuf, sizeof(memstrbuf),
10957 ents
10958 * sizeof(struct
10959 bgp_dest)));
10960
10961 /* Peer related usage */
10962 ents = bgp->af_peer_count[afi][safi];
10963 vty_out(vty, "Peers %ld, using %s of memory\n",
10964 ents,
10965 mtype_memstr(
10966 memstrbuf, sizeof(memstrbuf),
10967 ents * sizeof(struct peer)));
10968
10969 if ((ents = listcount(bgp->group)))
10970 vty_out(vty,
10971 "Peer groups %ld, using %s of memory\n",
10972 ents,
10973 mtype_memstr(
10974 memstrbuf,
10975 sizeof(memstrbuf),
10976 ents * sizeof(struct
10977 peer_group)));
10978
10979 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10980 BGP_CONFIG_DAMPENING))
10981 vty_out(vty, "Dampening enabled.\n");
10982 vty_out(vty, "\n");
10983
10984 /* Subtract 8 here because 'Neighbor' is
10985 * 8 characters */
10986 vty_out(vty, "Neighbor");
10987 vty_out(vty, "%*s", max_neighbor_width - 8,
10988 " ");
10989 if (show_failed)
10990 vty_out(vty,
10991 BGP_SHOW_SUMMARY_HEADER_FAILED);
10992 else
10993 vty_out(vty,
10994 show_wide
10995 ? BGP_SHOW_SUMMARY_HEADER_ALL_WIDE
10996 : BGP_SHOW_SUMMARY_HEADER_ALL);
10997 }
10998 }
10999
11000 paf = peer_af_find(peer, afi, safi);
11001 filter = &peer->filter[afi][safi];
11002
11003 count++;
11004 /* Works for both failed & successful cases */
11005 if (peer_dynamic_neighbor(peer))
11006 dn_count++;
11007
11008 if (use_json) {
11009 json_peer = NULL;
11010
11011 if (show_failed &&
11012 bgp_has_peer_failed(peer, afi, safi)) {
11013 json_peer = json_object_new_object();
11014 bgp_show_failed_summary(vty, bgp, peer,
11015 json_peer, 0, use_json);
11016 } else if (!show_failed) {
11017 if (show_established
11018 && bgp_has_peer_failed(peer, afi, safi))
11019 continue;
11020
11021 json_peer = json_object_new_object();
11022 if (peer_dynamic_neighbor(peer)) {
11023 json_object_boolean_true_add(json_peer,
11024 "dynamicPeer");
11025 }
11026
11027 if (peer->hostname)
11028 json_object_string_add(json_peer, "hostname",
11029 peer->hostname);
11030
11031 if (peer->domainname)
11032 json_object_string_add(json_peer, "domainname",
11033 peer->domainname);
11034
11035 json_object_int_add(json_peer, "remoteAs", peer->as);
11036 json_object_int_add(
11037 json_peer, "localAs",
11038 peer->change_local_as
11039 ? peer->change_local_as
11040 : peer->local_as);
11041 json_object_int_add(json_peer, "version", 4);
11042 json_object_int_add(json_peer, "msgRcvd",
11043 PEER_TOTAL_RX(peer));
11044 json_object_int_add(json_peer, "msgSent",
11045 PEER_TOTAL_TX(peer));
11046
11047 atomic_size_t outq_count, inq_count;
11048 outq_count = atomic_load_explicit(
11049 &peer->obuf->count,
11050 memory_order_relaxed);
11051 inq_count = atomic_load_explicit(
11052 &peer->ibuf->count,
11053 memory_order_relaxed);
11054
11055 json_object_int_add(json_peer, "tableVersion",
11056 peer->version[afi][safi]);
11057 json_object_int_add(json_peer, "outq",
11058 outq_count);
11059 json_object_int_add(json_peer, "inq",
11060 inq_count);
11061 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
11062 use_json, json_peer);
11063
11064 json_object_int_add(json_peer, "pfxRcd",
11065 peer->pcount[afi][pfx_rcd_safi]);
11066
11067 if (paf && PAF_SUBGRP(paf))
11068 json_object_int_add(
11069 json_peer, "pfxSnt",
11070 (PAF_SUBGRP(paf))->scount);
11071 else
11072 json_object_int_add(json_peer, "pfxSnt",
11073 0);
11074
11075 /* BGP FSM state */
11076 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
11077 || CHECK_FLAG(peer->bgp->flags,
11078 BGP_FLAG_SHUTDOWN))
11079 json_object_string_add(json_peer,
11080 "state",
11081 "Idle (Admin)");
11082 else if (peer->afc_recv[afi][safi])
11083 json_object_string_add(
11084 json_peer, "state",
11085 lookup_msg(bgp_status_msg,
11086 peer->status, NULL));
11087 else if (CHECK_FLAG(
11088 peer->sflags,
11089 PEER_STATUS_PREFIX_OVERFLOW))
11090 json_object_string_add(json_peer,
11091 "state",
11092 "Idle (PfxCt)");
11093 else
11094 json_object_string_add(
11095 json_peer, "state",
11096 lookup_msg(bgp_status_msg,
11097 peer->status, NULL));
11098
11099 /* BGP peer state */
11100 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
11101 || CHECK_FLAG(peer->bgp->flags,
11102 BGP_FLAG_SHUTDOWN))
11103 json_object_string_add(json_peer,
11104 "peerState",
11105 "Admin");
11106 else if (CHECK_FLAG(
11107 peer->sflags,
11108 PEER_STATUS_PREFIX_OVERFLOW))
11109 json_object_string_add(json_peer,
11110 "peerState",
11111 "PfxCt");
11112 else if (CHECK_FLAG(peer->flags,
11113 PEER_FLAG_PASSIVE))
11114 json_object_string_add(json_peer,
11115 "peerState",
11116 "Passive");
11117 else if (CHECK_FLAG(peer->sflags,
11118 PEER_STATUS_NSF_WAIT))
11119 json_object_string_add(json_peer,
11120 "peerState",
11121 "NSF passive");
11122 else if (CHECK_FLAG(
11123 peer->bgp->flags,
11124 BGP_FLAG_EBGP_REQUIRES_POLICY)
11125 && (!bgp_inbound_policy_exists(peer,
11126 filter)
11127 || !bgp_outbound_policy_exists(
11128 peer, filter)))
11129 json_object_string_add(json_peer,
11130 "peerState",
11131 "Policy");
11132 else
11133 json_object_string_add(
11134 json_peer, "peerState", "OK");
11135
11136 json_object_int_add(json_peer, "connectionsEstablished",
11137 peer->established);
11138 json_object_int_add(json_peer, "connectionsDropped",
11139 peer->dropped);
11140 if (peer->desc)
11141 json_object_string_add(
11142 json_peer, "desc", peer->desc);
11143 }
11144 /* Avoid creating empty peer dicts in JSON */
11145 if (json_peer == NULL)
11146 continue;
11147
11148 if (peer->conf_if)
11149 json_object_string_add(json_peer, "idType",
11150 "interface");
11151 else if (peer->su.sa.sa_family == AF_INET)
11152 json_object_string_add(json_peer, "idType",
11153 "ipv4");
11154 else if (peer->su.sa.sa_family == AF_INET6)
11155 json_object_string_add(json_peer, "idType",
11156 "ipv6");
11157 json_object_object_add(json_peers, peer->host,
11158 json_peer);
11159 } else {
11160 if (show_failed &&
11161 bgp_has_peer_failed(peer, afi, safi)) {
11162 bgp_show_failed_summary(vty, bgp, peer, NULL,
11163 max_neighbor_width,
11164 use_json);
11165 } else if (!show_failed) {
11166 if (show_established
11167 && bgp_has_peer_failed(peer, afi, safi))
11168 continue;
11169
11170 memset(dn_flag, '\0', sizeof(dn_flag));
11171 if (peer_dynamic_neighbor(peer)) {
11172 dn_flag[0] = '*';
11173 }
11174
11175 if (peer->hostname
11176 && CHECK_FLAG(bgp->flags,
11177 BGP_FLAG_SHOW_HOSTNAME))
11178 len = vty_out(vty, "%s%s(%s)", dn_flag,
11179 peer->hostname,
11180 peer->host);
11181 else
11182 len = vty_out(vty, "%s%s", dn_flag, peer->host);
11183
11184 /* pad the neighbor column with spaces */
11185 if (len < max_neighbor_width)
11186 vty_out(vty, "%*s", max_neighbor_width - len,
11187 " ");
11188
11189 atomic_size_t outq_count, inq_count;
11190 outq_count = atomic_load_explicit(
11191 &peer->obuf->count,
11192 memory_order_relaxed);
11193 inq_count = atomic_load_explicit(
11194 &peer->ibuf->count,
11195 memory_order_relaxed);
11196
11197 if (show_wide)
11198 vty_out(vty,
11199 "4 %10u %10u %9u %9u %8" PRIu64
11200 " %4zu %4zu %8s",
11201 peer->as,
11202 peer->change_local_as
11203 ? peer->change_local_as
11204 : peer->local_as,
11205 PEER_TOTAL_RX(peer),
11206 PEER_TOTAL_TX(peer),
11207 peer->version[afi][safi],
11208 inq_count, outq_count,
11209 peer_uptime(peer->uptime,
11210 timebuf,
11211 BGP_UPTIME_LEN, 0,
11212 NULL));
11213 else
11214 vty_out(vty, "4 %10u %9u %9u %8" PRIu64
11215 " %4zu %4zu %8s",
11216 peer->as, PEER_TOTAL_RX(peer),
11217 PEER_TOTAL_TX(peer),
11218 peer->version[afi][safi],
11219 inq_count, outq_count,
11220 peer_uptime(peer->uptime,
11221 timebuf,
11222 BGP_UPTIME_LEN, 0,
11223 NULL));
11224
11225 if (peer->status == Established) {
11226 if (peer->afc_recv[afi][safi]) {
11227 if (CHECK_FLAG(
11228 bgp->flags,
11229 BGP_FLAG_EBGP_REQUIRES_POLICY)
11230 && !bgp_inbound_policy_exists(
11231 peer, filter))
11232 vty_out(vty, " %12s",
11233 "(Policy)");
11234 else
11235 vty_out(vty,
11236 " %12u",
11237 peer->pcount
11238 [afi]
11239 [pfx_rcd_safi]);
11240 } else {
11241 vty_out(vty, " NoNeg");
11242 }
11243
11244 if (paf && PAF_SUBGRP(paf)) {
11245 if (CHECK_FLAG(
11246 bgp->flags,
11247 BGP_FLAG_EBGP_REQUIRES_POLICY)
11248 && !bgp_outbound_policy_exists(
11249 peer, filter))
11250 vty_out(vty, " %8s",
11251 "(Policy)");
11252 else
11253 vty_out(vty,
11254 " %8u",
11255 (PAF_SUBGRP(
11256 paf))
11257 ->scount);
11258 } else {
11259 vty_out(vty, " NoNeg");
11260 }
11261 } else {
11262 if (CHECK_FLAG(peer->flags,
11263 PEER_FLAG_SHUTDOWN)
11264 || CHECK_FLAG(peer->bgp->flags,
11265 BGP_FLAG_SHUTDOWN))
11266 vty_out(vty, " Idle (Admin)");
11267 else if (CHECK_FLAG(
11268 peer->sflags,
11269 PEER_STATUS_PREFIX_OVERFLOW))
11270 vty_out(vty, " Idle (PfxCt)");
11271 else
11272 vty_out(vty, " %12s",
11273 lookup_msg(bgp_status_msg,
11274 peer->status, NULL));
11275
11276 vty_out(vty, " %8u", 0);
11277 }
11278 if (peer->desc)
11279 vty_out(vty, " %s",
11280 bgp_peer_description_stripped(
11281 peer->desc,
11282 show_wide ? 64 : 20));
11283 else
11284 vty_out(vty, " N/A");
11285 vty_out(vty, "\n");
11286 }
11287
11288 }
11289 }
11290
11291 if (use_json) {
11292 json_object_object_add(json, "peers", json_peers);
11293 json_object_int_add(json, "failedPeers", failed_count);
11294 json_object_int_add(json, "totalPeers", count);
11295 json_object_int_add(json, "dynamicPeers", dn_count);
11296
11297 if (!show_failed)
11298 bgp_show_bestpath_json(bgp, json);
11299
11300 vty_out(vty, "%s\n", json_object_to_json_string_ext(
11301 json, JSON_C_TO_STRING_PRETTY));
11302 json_object_free(json);
11303 } else {
11304 if (count)
11305 vty_out(vty, "\nTotal number of neighbors %d\n", count);
11306 else {
11307 vty_out(vty, "No %s neighbor is configured\n",
11308 get_afi_safi_str(afi, safi, false));
11309 }
11310
11311 if (dn_count) {
11312 vty_out(vty, "* - dynamic neighbor\n");
11313 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
11314 dn_count, bgp->dynamic_neighbors_limit);
11315 }
11316 }
11317
11318 return CMD_SUCCESS;
11319 }
11320
11321 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
11322 int safi, uint8_t show_flags)
11323 {
11324 int is_first = 1;
11325 int afi_wildcard = (afi == AFI_MAX);
11326 int safi_wildcard = (safi == SAFI_MAX);
11327 int is_wildcard = (afi_wildcard || safi_wildcard);
11328 bool nbr_output = false;
11329 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11330
11331 if (use_json && is_wildcard)
11332 vty_out(vty, "{\n");
11333 if (afi_wildcard)
11334 afi = 1; /* AFI_IP */
11335 while (afi < AFI_MAX) {
11336 if (safi_wildcard)
11337 safi = 1; /* SAFI_UNICAST */
11338 while (safi < SAFI_MAX) {
11339 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
11340 nbr_output = true;
11341
11342 if (is_wildcard) {
11343 /*
11344 * So limit output to those afi/safi
11345 * pairs that
11346 * actualy have something interesting in
11347 * them
11348 */
11349 if (use_json) {
11350 if (!is_first)
11351 vty_out(vty, ",\n");
11352 else
11353 is_first = 0;
11354
11355 vty_out(vty, "\"%s\":",
11356 get_afi_safi_str(afi,
11357 safi,
11358 true));
11359 } else {
11360 vty_out(vty, "\n%s Summary:\n",
11361 get_afi_safi_str(afi,
11362 safi,
11363 false));
11364 }
11365 }
11366 bgp_show_summary(vty, bgp, afi, safi,
11367 show_flags);
11368 }
11369 safi++;
11370 if (!safi_wildcard)
11371 safi = SAFI_MAX;
11372 }
11373 afi++;
11374 if (!afi_wildcard)
11375 afi = AFI_MAX;
11376 }
11377
11378 if (use_json && is_wildcard)
11379 vty_out(vty, "}\n");
11380 else if (!nbr_output) {
11381 if (use_json)
11382 vty_out(vty, "{}\n");
11383 else
11384 vty_out(vty, "%% No BGP neighbors found\n");
11385 }
11386 }
11387
11388 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
11389 safi_t safi, uint8_t show_flags)
11390 {
11391 struct listnode *node, *nnode;
11392 struct bgp *bgp;
11393 int is_first = 1;
11394 bool nbr_output = false;
11395 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11396
11397 if (use_json)
11398 vty_out(vty, "{\n");
11399
11400 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11401 nbr_output = true;
11402 if (use_json) {
11403 if (!is_first)
11404 vty_out(vty, ",\n");
11405 else
11406 is_first = 0;
11407
11408 vty_out(vty, "\"%s\":",
11409 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11410 ? VRF_DEFAULT_NAME
11411 : bgp->name);
11412 } else {
11413 vty_out(vty, "\nInstance %s:\n",
11414 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11415 ? VRF_DEFAULT_NAME
11416 : bgp->name);
11417 }
11418 bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_flags);
11419 }
11420
11421 if (use_json)
11422 vty_out(vty, "}\n");
11423 else if (!nbr_output)
11424 vty_out(vty, "%% BGP instance not found\n");
11425 }
11426
11427 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
11428 safi_t safi, uint8_t show_flags)
11429 {
11430 struct bgp *bgp;
11431 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11432
11433 if (name) {
11434 if (strmatch(name, "all")) {
11435 bgp_show_all_instances_summary_vty(vty, afi, safi,
11436 show_flags);
11437 return CMD_SUCCESS;
11438 } else {
11439 bgp = bgp_lookup_by_name(name);
11440
11441 if (!bgp) {
11442 if (use_json)
11443 vty_out(vty, "{}\n");
11444 else
11445 vty_out(vty,
11446 "%% BGP instance not found\n");
11447 return CMD_WARNING;
11448 }
11449
11450 bgp_show_summary_afi_safi(vty, bgp, afi, safi,
11451 show_flags);
11452 return CMD_SUCCESS;
11453 }
11454 }
11455
11456 bgp = bgp_get_default();
11457
11458 if (bgp)
11459 bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_flags);
11460 else {
11461 if (use_json)
11462 vty_out(vty, "{}\n");
11463 else
11464 vty_out(vty, "%% BGP instance not found\n");
11465 return CMD_WARNING;
11466 }
11467
11468 return CMD_SUCCESS;
11469 }
11470
11471 /* `show [ip] bgp summary' commands. */
11472 DEFPY (show_ip_bgp_summary,
11473 show_ip_bgp_summary_cmd,
11474 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] [all$all] summary [established|failed] [wide] [json$uj]",
11475 SHOW_STR
11476 IP_STR
11477 BGP_STR
11478 BGP_INSTANCE_HELP_STR
11479 BGP_AFI_HELP_STR
11480 BGP_SAFI_WITH_LABEL_HELP_STR
11481 "Display the entries for all address families\n"
11482 "Summary of BGP neighbor status\n"
11483 "Show only sessions in Established state\n"
11484 "Show only sessions not in Established state\n"
11485 "Increase table width for longer output\n"
11486 JSON_STR)
11487 {
11488 char *vrf = NULL;
11489 afi_t afi = AFI_MAX;
11490 safi_t safi = SAFI_MAX;
11491 uint8_t show_flags = 0;
11492
11493 int idx = 0;
11494
11495 /* show [ip] bgp */
11496 if (!all && argv_find(argv, argc, "ip", &idx))
11497 afi = AFI_IP;
11498 /* [<vrf> VIEWVRFNAME] */
11499 if (argv_find(argv, argc, "vrf", &idx)) {
11500 vrf = argv[idx + 1]->arg;
11501 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11502 vrf = NULL;
11503 } else if (argv_find(argv, argc, "view", &idx))
11504 /* [<view> VIEWVRFNAME] */
11505 vrf = argv[idx + 1]->arg;
11506 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11507 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11508 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11509 }
11510
11511 if (argv_find(argv, argc, "failed", &idx))
11512 SET_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
11513
11514 if (argv_find(argv, argc, "established", &idx))
11515 SET_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
11516
11517 if (argv_find(argv, argc, "wide", &idx))
11518 SET_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
11519
11520 if (argv_find(argv, argc, "json", &idx))
11521 SET_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11522
11523 return bgp_show_summary_vty(vty, vrf, afi, safi, show_flags);
11524 }
11525
11526 const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
11527 {
11528 if (for_json)
11529 return get_afi_safi_json_str(afi, safi);
11530 else
11531 return get_afi_safi_vty_str(afi, safi);
11532 }
11533
11534
11535 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
11536 afi_t afi, safi_t safi,
11537 uint16_t adv_smcap, uint16_t adv_rmcap,
11538 uint16_t rcv_smcap, uint16_t rcv_rmcap,
11539 bool use_json, json_object *json_pref)
11540 {
11541 /* Send-Mode */
11542 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11543 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
11544 if (use_json) {
11545 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11546 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11547 json_object_string_add(json_pref, "sendMode",
11548 "advertisedAndReceived");
11549 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11550 json_object_string_add(json_pref, "sendMode",
11551 "advertised");
11552 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11553 json_object_string_add(json_pref, "sendMode",
11554 "received");
11555 } else {
11556 vty_out(vty, " Send-mode: ");
11557 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11558 vty_out(vty, "advertised");
11559 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11560 vty_out(vty, "%sreceived",
11561 CHECK_FLAG(p->af_cap[afi][safi],
11562 adv_smcap)
11563 ? ", "
11564 : "");
11565 vty_out(vty, "\n");
11566 }
11567 }
11568
11569 /* Receive-Mode */
11570 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11571 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
11572 if (use_json) {
11573 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11574 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11575 json_object_string_add(json_pref, "recvMode",
11576 "advertisedAndReceived");
11577 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11578 json_object_string_add(json_pref, "recvMode",
11579 "advertised");
11580 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11581 json_object_string_add(json_pref, "recvMode",
11582 "received");
11583 } else {
11584 vty_out(vty, " Receive-mode: ");
11585 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11586 vty_out(vty, "advertised");
11587 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11588 vty_out(vty, "%sreceived",
11589 CHECK_FLAG(p->af_cap[afi][safi],
11590 adv_rmcap)
11591 ? ", "
11592 : "");
11593 vty_out(vty, "\n");
11594 }
11595 }
11596 }
11597
11598 static void bgp_show_neighnor_graceful_restart_rbit(struct vty *vty,
11599 struct peer *p,
11600 bool use_json,
11601 json_object *json)
11602 {
11603 bool rbit_status = false;
11604
11605 if (!use_json)
11606 vty_out(vty, "\n R bit: ");
11607
11608 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
11609 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
11610 && (p->status == Established)) {
11611
11612 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_BIT_RCV))
11613 rbit_status = true;
11614 else
11615 rbit_status = false;
11616 }
11617
11618 if (rbit_status) {
11619 if (use_json)
11620 json_object_boolean_true_add(json, "rBit");
11621 else
11622 vty_out(vty, "True\n");
11623 } else {
11624 if (use_json)
11625 json_object_boolean_false_add(json, "rBit");
11626 else
11627 vty_out(vty, "False\n");
11628 }
11629 }
11630
11631 static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
11632 struct peer *peer,
11633 bool use_json,
11634 json_object *json)
11635 {
11636 const char *mode = "NotApplicable";
11637
11638 if (!use_json)
11639 vty_out(vty, "\n Remote GR Mode: ");
11640
11641 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
11642 && (peer->status == Established)) {
11643
11644 if ((peer->nsf_af_count == 0)
11645 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11646
11647 mode = "Disable";
11648
11649 } else if (peer->nsf_af_count == 0
11650 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11651
11652 mode = "Helper";
11653
11654 } else if (peer->nsf_af_count != 0
11655 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11656
11657 mode = "Restart";
11658 }
11659 }
11660
11661 if (use_json) {
11662 json_object_string_add(json, "remoteGrMode", mode);
11663 } else
11664 vty_out(vty, mode, "\n");
11665 }
11666
11667 static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
11668 struct peer *p,
11669 bool use_json,
11670 json_object *json)
11671 {
11672 const char *mode = "Invalid";
11673
11674 if (!use_json)
11675 vty_out(vty, " Local GR Mode: ");
11676
11677 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
11678 mode = "Helper";
11679 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
11680 mode = "Restart";
11681 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
11682 mode = "Disable";
11683 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
11684 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
11685 mode = "Helper*";
11686 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
11687 mode = "Restart*";
11688 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
11689 mode = "Disable*";
11690 else
11691 mode = "Invalid*";
11692 }
11693
11694 if (use_json) {
11695 json_object_string_add(json, "localGrMode", mode);
11696 } else {
11697 vty_out(vty, mode, "\n");
11698 }
11699 }
11700
11701 static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
11702 struct vty *vty, struct peer *peer, bool use_json, json_object *json)
11703 {
11704 afi_t afi;
11705 safi_t safi;
11706 json_object *json_afi_safi = NULL;
11707 json_object *json_timer = NULL;
11708 json_object *json_endofrib_status = NULL;
11709 bool eor_flag = false;
11710
11711 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
11712 for (safi = SAFI_UNICAST; safi <= SAFI_MPLS_VPN; safi++) {
11713 if (!peer->afc[afi][safi])
11714 continue;
11715
11716 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
11717 || !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
11718 continue;
11719
11720 if (use_json) {
11721 json_afi_safi = json_object_new_object();
11722 json_endofrib_status = json_object_new_object();
11723 json_timer = json_object_new_object();
11724 }
11725
11726 if (peer->eor_stime[afi][safi]
11727 >= peer->pkt_stime[afi][safi])
11728 eor_flag = true;
11729 else
11730 eor_flag = false;
11731
11732 if (!use_json) {
11733 vty_out(vty, " %s:\n",
11734 get_afi_safi_str(afi, safi, false));
11735
11736 vty_out(vty, " F bit: ");
11737 }
11738
11739 if (peer->nsf[afi][safi]
11740 && CHECK_FLAG(peer->af_cap[afi][safi],
11741 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
11742
11743 if (use_json) {
11744 json_object_boolean_true_add(
11745 json_afi_safi, "fBit");
11746 } else
11747 vty_out(vty, "True\n");
11748 } else {
11749 if (use_json)
11750 json_object_boolean_false_add(
11751 json_afi_safi, "fBit");
11752 else
11753 vty_out(vty, "False\n");
11754 }
11755
11756 if (!use_json)
11757 vty_out(vty, " End-of-RIB sent: ");
11758
11759 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11760 PEER_STATUS_EOR_SEND)) {
11761 if (use_json) {
11762 json_object_boolean_true_add(
11763 json_endofrib_status,
11764 "endOfRibSend");
11765
11766 PRINT_EOR_JSON(eor_flag);
11767 } else {
11768 vty_out(vty, "Yes\n");
11769 vty_out(vty,
11770 " End-of-RIB sent after update: ");
11771
11772 PRINT_EOR(eor_flag);
11773 }
11774 } else {
11775 if (use_json) {
11776 json_object_boolean_false_add(
11777 json_endofrib_status,
11778 "endOfRibSend");
11779 json_object_boolean_false_add(
11780 json_endofrib_status,
11781 "endOfRibSentAfterUpdate");
11782 } else {
11783 vty_out(vty, "No\n");
11784 vty_out(vty,
11785 " End-of-RIB sent after update: ");
11786 vty_out(vty, "No\n");
11787 }
11788 }
11789
11790 if (!use_json)
11791 vty_out(vty, " End-of-RIB received: ");
11792
11793 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11794 PEER_STATUS_EOR_RECEIVED)) {
11795 if (use_json)
11796 json_object_boolean_true_add(
11797 json_endofrib_status,
11798 "endOfRibRecv");
11799 else
11800 vty_out(vty, "Yes\n");
11801 } else {
11802 if (use_json)
11803 json_object_boolean_false_add(
11804 json_endofrib_status,
11805 "endOfRibRecv");
11806 else
11807 vty_out(vty, "No\n");
11808 }
11809
11810 if (use_json) {
11811 json_object_int_add(json_timer,
11812 "stalePathTimer",
11813 peer->bgp->stalepath_time);
11814
11815 if (peer->t_gr_stale != NULL) {
11816 json_object_int_add(
11817 json_timer,
11818 "stalePathTimerRemaining",
11819 thread_timer_remain_second(
11820 peer->t_gr_stale));
11821 }
11822
11823 /* Display Configured Selection
11824 * Deferral only when when
11825 * Gr mode is enabled.
11826 */
11827 if (CHECK_FLAG(peer->flags,
11828 PEER_FLAG_GRACEFUL_RESTART)) {
11829 json_object_int_add(
11830 json_timer,
11831 "selectionDeferralTimer",
11832 peer->bgp->stalepath_time);
11833 }
11834
11835 if (peer->bgp->gr_info[afi][safi]
11836 .t_select_deferral
11837 != NULL) {
11838
11839 json_object_int_add(
11840 json_timer,
11841 "selectionDeferralTimerRemaining",
11842 thread_timer_remain_second(
11843 peer->bgp
11844 ->gr_info[afi]
11845 [safi]
11846 .t_select_deferral));
11847 }
11848 } else {
11849 vty_out(vty, " Timers:\n");
11850 vty_out(vty,
11851 " Configured Stale Path Time(sec): %u\n",
11852 peer->bgp->stalepath_time);
11853
11854 if (peer->t_gr_stale != NULL)
11855 vty_out(vty,
11856 " Stale Path Remaining(sec): %ld\n",
11857 thread_timer_remain_second(
11858 peer->t_gr_stale));
11859 /* Display Configured Selection
11860 * Deferral only when when
11861 * Gr mode is enabled.
11862 */
11863 if (CHECK_FLAG(peer->flags,
11864 PEER_FLAG_GRACEFUL_RESTART))
11865 vty_out(vty,
11866 " Configured Selection Deferral Time(sec): %u\n",
11867 peer->bgp->select_defer_time);
11868
11869 if (peer->bgp->gr_info[afi][safi]
11870 .t_select_deferral
11871 != NULL)
11872 vty_out(vty,
11873 " Selection Deferral Time Remaining(sec): %ld\n",
11874 thread_timer_remain_second(
11875 peer->bgp
11876 ->gr_info[afi]
11877 [safi]
11878 .t_select_deferral));
11879 }
11880 if (use_json) {
11881 json_object_object_add(json_afi_safi,
11882 "endOfRibStatus",
11883 json_endofrib_status);
11884 json_object_object_add(json_afi_safi, "timers",
11885 json_timer);
11886 json_object_object_add(
11887 json, get_afi_safi_str(afi, safi, true),
11888 json_afi_safi);
11889 }
11890 }
11891 }
11892 }
11893
11894 static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
11895 struct peer *p,
11896 bool use_json,
11897 json_object *json)
11898 {
11899 if (use_json) {
11900 json_object *json_timer = NULL;
11901
11902 json_timer = json_object_new_object();
11903
11904 json_object_int_add(json_timer, "configuredRestartTimer",
11905 p->bgp->restart_time);
11906
11907 json_object_int_add(json_timer, "receivedRestartTimer",
11908 p->v_gr_restart);
11909
11910 if (p->t_gr_restart != NULL)
11911 json_object_int_add(
11912 json_timer, "restartTimerRemaining",
11913 thread_timer_remain_second(p->t_gr_restart));
11914
11915 json_object_object_add(json, "timers", json_timer);
11916 } else {
11917
11918 vty_out(vty, " Timers:\n");
11919 vty_out(vty, " Configured Restart Time(sec): %u\n",
11920 p->bgp->restart_time);
11921
11922 vty_out(vty, " Received Restart Time(sec): %u\n",
11923 p->v_gr_restart);
11924 if (p->t_gr_restart != NULL)
11925 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
11926 thread_timer_remain_second(p->t_gr_restart));
11927 if (p->t_gr_restart != NULL) {
11928 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
11929 thread_timer_remain_second(p->t_gr_restart));
11930 }
11931 }
11932 }
11933
11934 static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
11935 bool use_json, json_object *json)
11936 {
11937 char buf[SU_ADDRSTRLEN] = {0};
11938 char dn_flag[2] = {0};
11939 /* '*' + v6 address of neighbor */
11940 char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
11941
11942 if (!p->conf_if && peer_dynamic_neighbor(p))
11943 dn_flag[0] = '*';
11944
11945 if (p->conf_if) {
11946 if (use_json)
11947 json_object_string_add(
11948 json, "neighborAddr",
11949 BGP_PEER_SU_UNSPEC(p)
11950 ? "none"
11951 : sockunion2str(&p->su, buf,
11952 SU_ADDRSTRLEN));
11953 else
11954 vty_out(vty, "BGP neighbor on %s: %s\n", p->conf_if,
11955 BGP_PEER_SU_UNSPEC(p)
11956 ? "none"
11957 : sockunion2str(&p->su, buf,
11958 SU_ADDRSTRLEN));
11959 } else {
11960 snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
11961 p->host);
11962
11963 if (use_json)
11964 json_object_string_add(json, "neighborAddr",
11965 neighborAddr);
11966 else
11967 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
11968 }
11969
11970 /* more gr info in new format */
11971 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json);
11972 }
11973
11974 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
11975 safi_t safi, bool use_json,
11976 json_object *json_neigh)
11977 {
11978 struct bgp_filter *filter;
11979 struct peer_af *paf;
11980 char orf_pfx_name[BUFSIZ];
11981 int orf_pfx_count;
11982 json_object *json_af = NULL;
11983 json_object *json_prefA = NULL;
11984 json_object *json_prefB = NULL;
11985 json_object *json_addr = NULL;
11986 json_object *json_advmap = NULL;
11987
11988 if (use_json) {
11989 json_addr = json_object_new_object();
11990 json_af = json_object_new_object();
11991 filter = &p->filter[afi][safi];
11992
11993 if (peer_group_active(p))
11994 json_object_string_add(json_addr, "peerGroupMember",
11995 p->group->name);
11996
11997 paf = peer_af_find(p, afi, safi);
11998 if (paf && PAF_SUBGRP(paf)) {
11999 json_object_int_add(json_addr, "updateGroupId",
12000 PAF_UPDGRP(paf)->id);
12001 json_object_int_add(json_addr, "subGroupId",
12002 PAF_SUBGRP(paf)->id);
12003 json_object_int_add(json_addr, "packetQueueLength",
12004 bpacket_queue_virtual_length(paf));
12005 }
12006
12007 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12008 || CHECK_FLAG(p->af_cap[afi][safi],
12009 PEER_CAP_ORF_PREFIX_SM_RCV)
12010 || CHECK_FLAG(p->af_cap[afi][safi],
12011 PEER_CAP_ORF_PREFIX_RM_ADV)
12012 || CHECK_FLAG(p->af_cap[afi][safi],
12013 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12014 json_object_int_add(json_af, "orfType",
12015 ORF_TYPE_PREFIX);
12016 json_prefA = json_object_new_object();
12017 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
12018 PEER_CAP_ORF_PREFIX_SM_ADV,
12019 PEER_CAP_ORF_PREFIX_RM_ADV,
12020 PEER_CAP_ORF_PREFIX_SM_RCV,
12021 PEER_CAP_ORF_PREFIX_RM_RCV,
12022 use_json, json_prefA);
12023 json_object_object_add(json_af, "orfPrefixList",
12024 json_prefA);
12025 }
12026
12027 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12028 || CHECK_FLAG(p->af_cap[afi][safi],
12029 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12030 || CHECK_FLAG(p->af_cap[afi][safi],
12031 PEER_CAP_ORF_PREFIX_RM_ADV)
12032 || CHECK_FLAG(p->af_cap[afi][safi],
12033 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12034 json_object_int_add(json_af, "orfOldType",
12035 ORF_TYPE_PREFIX_OLD);
12036 json_prefB = json_object_new_object();
12037 bgp_show_peer_afi_orf_cap(
12038 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12039 PEER_CAP_ORF_PREFIX_RM_ADV,
12040 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12041 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
12042 json_prefB);
12043 json_object_object_add(json_af, "orfOldPrefixList",
12044 json_prefB);
12045 }
12046
12047 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12048 || CHECK_FLAG(p->af_cap[afi][safi],
12049 PEER_CAP_ORF_PREFIX_SM_RCV)
12050 || CHECK_FLAG(p->af_cap[afi][safi],
12051 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12052 || CHECK_FLAG(p->af_cap[afi][safi],
12053 PEER_CAP_ORF_PREFIX_RM_ADV)
12054 || CHECK_FLAG(p->af_cap[afi][safi],
12055 PEER_CAP_ORF_PREFIX_RM_RCV)
12056 || CHECK_FLAG(p->af_cap[afi][safi],
12057 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12058 json_object_object_add(json_addr, "afDependentCap",
12059 json_af);
12060 else
12061 json_object_free(json_af);
12062
12063 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12064 p->host, afi, safi);
12065 orf_pfx_count = prefix_bgp_show_prefix_list(
12066 NULL, afi, orf_pfx_name, use_json);
12067
12068 if (CHECK_FLAG(p->af_sflags[afi][safi],
12069 PEER_STATUS_ORF_PREFIX_SEND)
12070 || orf_pfx_count) {
12071 if (CHECK_FLAG(p->af_sflags[afi][safi],
12072 PEER_STATUS_ORF_PREFIX_SEND))
12073 json_object_boolean_true_add(json_neigh,
12074 "orfSent");
12075 if (orf_pfx_count)
12076 json_object_int_add(json_addr, "orfRecvCounter",
12077 orf_pfx_count);
12078 }
12079 if (CHECK_FLAG(p->af_sflags[afi][safi],
12080 PEER_STATUS_ORF_WAIT_REFRESH))
12081 json_object_string_add(
12082 json_addr, "orfFirstUpdate",
12083 "deferredUntilORFOrRouteRefreshRecvd");
12084
12085 if (CHECK_FLAG(p->af_flags[afi][safi],
12086 PEER_FLAG_REFLECTOR_CLIENT))
12087 json_object_boolean_true_add(json_addr,
12088 "routeReflectorClient");
12089 if (CHECK_FLAG(p->af_flags[afi][safi],
12090 PEER_FLAG_RSERVER_CLIENT))
12091 json_object_boolean_true_add(json_addr,
12092 "routeServerClient");
12093 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12094 json_object_boolean_true_add(json_addr,
12095 "inboundSoftConfigPermit");
12096
12097 if (CHECK_FLAG(p->af_flags[afi][safi],
12098 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12099 json_object_boolean_true_add(
12100 json_addr,
12101 "privateAsNumsAllReplacedInUpdatesToNbr");
12102 else if (CHECK_FLAG(p->af_flags[afi][safi],
12103 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12104 json_object_boolean_true_add(
12105 json_addr,
12106 "privateAsNumsReplacedInUpdatesToNbr");
12107 else if (CHECK_FLAG(p->af_flags[afi][safi],
12108 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12109 json_object_boolean_true_add(
12110 json_addr,
12111 "privateAsNumsAllRemovedInUpdatesToNbr");
12112 else if (CHECK_FLAG(p->af_flags[afi][safi],
12113 PEER_FLAG_REMOVE_PRIVATE_AS))
12114 json_object_boolean_true_add(
12115 json_addr,
12116 "privateAsNumsRemovedInUpdatesToNbr");
12117
12118 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12119 json_object_boolean_true_add(
12120 json_addr,
12121 bgp_addpath_names(p->addpath_type[afi][safi])
12122 ->type_json_name);
12123
12124 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12125 json_object_string_add(json_addr,
12126 "overrideASNsInOutboundUpdates",
12127 "ifAspathEqualRemoteAs");
12128
12129 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12130 || CHECK_FLAG(p->af_flags[afi][safi],
12131 PEER_FLAG_FORCE_NEXTHOP_SELF))
12132 json_object_boolean_true_add(json_addr,
12133 "routerAlwaysNextHop");
12134 if (CHECK_FLAG(p->af_flags[afi][safi],
12135 PEER_FLAG_AS_PATH_UNCHANGED))
12136 json_object_boolean_true_add(
12137 json_addr, "unchangedAsPathPropogatedToNbr");
12138 if (CHECK_FLAG(p->af_flags[afi][safi],
12139 PEER_FLAG_NEXTHOP_UNCHANGED))
12140 json_object_boolean_true_add(
12141 json_addr, "unchangedNextHopPropogatedToNbr");
12142 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12143 json_object_boolean_true_add(
12144 json_addr, "unchangedMedPropogatedToNbr");
12145 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12146 || CHECK_FLAG(p->af_flags[afi][safi],
12147 PEER_FLAG_SEND_EXT_COMMUNITY)) {
12148 if (CHECK_FLAG(p->af_flags[afi][safi],
12149 PEER_FLAG_SEND_COMMUNITY)
12150 && CHECK_FLAG(p->af_flags[afi][safi],
12151 PEER_FLAG_SEND_EXT_COMMUNITY))
12152 json_object_string_add(json_addr,
12153 "commAttriSentToNbr",
12154 "extendedAndStandard");
12155 else if (CHECK_FLAG(p->af_flags[afi][safi],
12156 PEER_FLAG_SEND_EXT_COMMUNITY))
12157 json_object_string_add(json_addr,
12158 "commAttriSentToNbr",
12159 "extended");
12160 else
12161 json_object_string_add(json_addr,
12162 "commAttriSentToNbr",
12163 "standard");
12164 }
12165 if (CHECK_FLAG(p->af_flags[afi][safi],
12166 PEER_FLAG_DEFAULT_ORIGINATE)) {
12167 if (p->default_rmap[afi][safi].name)
12168 json_object_string_add(
12169 json_addr, "defaultRouteMap",
12170 p->default_rmap[afi][safi].name);
12171
12172 if (paf && PAF_SUBGRP(paf)
12173 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12174 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12175 json_object_boolean_true_add(json_addr,
12176 "defaultSent");
12177 else
12178 json_object_boolean_true_add(json_addr,
12179 "defaultNotSent");
12180 }
12181
12182 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
12183 if (is_evpn_enabled())
12184 json_object_boolean_true_add(
12185 json_addr, "advertiseAllVnis");
12186 }
12187
12188 if (filter->plist[FILTER_IN].name
12189 || filter->dlist[FILTER_IN].name
12190 || filter->aslist[FILTER_IN].name
12191 || filter->map[RMAP_IN].name)
12192 json_object_boolean_true_add(json_addr,
12193 "inboundPathPolicyConfig");
12194 if (filter->plist[FILTER_OUT].name
12195 || filter->dlist[FILTER_OUT].name
12196 || filter->aslist[FILTER_OUT].name
12197 || filter->map[RMAP_OUT].name || filter->usmap.name)
12198 json_object_boolean_true_add(
12199 json_addr, "outboundPathPolicyConfig");
12200
12201 /* prefix-list */
12202 if (filter->plist[FILTER_IN].name)
12203 json_object_string_add(json_addr,
12204 "incomingUpdatePrefixFilterList",
12205 filter->plist[FILTER_IN].name);
12206 if (filter->plist[FILTER_OUT].name)
12207 json_object_string_add(json_addr,
12208 "outgoingUpdatePrefixFilterList",
12209 filter->plist[FILTER_OUT].name);
12210
12211 /* distribute-list */
12212 if (filter->dlist[FILTER_IN].name)
12213 json_object_string_add(
12214 json_addr, "incomingUpdateNetworkFilterList",
12215 filter->dlist[FILTER_IN].name);
12216 if (filter->dlist[FILTER_OUT].name)
12217 json_object_string_add(
12218 json_addr, "outgoingUpdateNetworkFilterList",
12219 filter->dlist[FILTER_OUT].name);
12220
12221 /* filter-list. */
12222 if (filter->aslist[FILTER_IN].name)
12223 json_object_string_add(json_addr,
12224 "incomingUpdateAsPathFilterList",
12225 filter->aslist[FILTER_IN].name);
12226 if (filter->aslist[FILTER_OUT].name)
12227 json_object_string_add(json_addr,
12228 "outgoingUpdateAsPathFilterList",
12229 filter->aslist[FILTER_OUT].name);
12230
12231 /* route-map. */
12232 if (filter->map[RMAP_IN].name)
12233 json_object_string_add(
12234 json_addr, "routeMapForIncomingAdvertisements",
12235 filter->map[RMAP_IN].name);
12236 if (filter->map[RMAP_OUT].name)
12237 json_object_string_add(
12238 json_addr, "routeMapForOutgoingAdvertisements",
12239 filter->map[RMAP_OUT].name);
12240
12241 /* ebgp-requires-policy (inbound) */
12242 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12243 && !bgp_inbound_policy_exists(p, filter))
12244 json_object_string_add(
12245 json_addr, "inboundEbgpRequiresPolicy",
12246 "Inbound updates discarded due to missing policy");
12247
12248 /* ebgp-requires-policy (outbound) */
12249 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12250 && (!bgp_outbound_policy_exists(p, filter)))
12251 json_object_string_add(
12252 json_addr, "outboundEbgpRequiresPolicy",
12253 "Outbound updates discarded due to missing policy");
12254
12255 /* unsuppress-map */
12256 if (filter->usmap.name)
12257 json_object_string_add(json_addr,
12258 "selectiveUnsuppressRouteMap",
12259 filter->usmap.name);
12260
12261 /* advertise-map */
12262 if (filter->advmap.aname) {
12263 json_advmap = json_object_new_object();
12264 json_object_string_add(json_advmap, "condition",
12265 filter->advmap.condition
12266 ? "EXIST"
12267 : "NON_EXIST");
12268 json_object_string_add(json_advmap, "conditionMap",
12269 filter->advmap.cname);
12270 json_object_string_add(json_advmap, "advertiseMap",
12271 filter->advmap.aname);
12272 json_object_string_add(json_advmap, "advertiseStatus",
12273 filter->advmap.update_type
12274 == ADVERTISE
12275 ? "Advertise"
12276 : "Withdraw");
12277 json_object_object_add(json_addr, "advertiseMap",
12278 json_advmap);
12279 }
12280
12281 /* Receive prefix count */
12282 json_object_int_add(json_addr, "acceptedPrefixCounter",
12283 p->pcount[afi][safi]);
12284 if (paf && PAF_SUBGRP(paf))
12285 json_object_int_add(json_addr, "sentPrefixCounter",
12286 (PAF_SUBGRP(paf))->scount);
12287
12288 /* Maximum prefix */
12289 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
12290 json_object_int_add(json_addr, "prefixOutAllowedMax",
12291 p->pmax_out[afi][safi]);
12292
12293 /* Maximum prefix */
12294 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12295 json_object_int_add(json_addr, "prefixAllowedMax",
12296 p->pmax[afi][safi]);
12297 if (CHECK_FLAG(p->af_flags[afi][safi],
12298 PEER_FLAG_MAX_PREFIX_WARNING))
12299 json_object_boolean_true_add(
12300 json_addr, "prefixAllowedMaxWarning");
12301 json_object_int_add(json_addr,
12302 "prefixAllowedWarningThresh",
12303 p->pmax_threshold[afi][safi]);
12304 if (p->pmax_restart[afi][safi])
12305 json_object_int_add(
12306 json_addr,
12307 "prefixAllowedRestartIntervalMsecs",
12308 p->pmax_restart[afi][safi] * 60000);
12309 }
12310 json_object_object_add(json_neigh,
12311 get_afi_safi_str(afi, safi, true),
12312 json_addr);
12313
12314 } else {
12315 filter = &p->filter[afi][safi];
12316
12317 vty_out(vty, " For address family: %s\n",
12318 get_afi_safi_str(afi, safi, false));
12319
12320 if (peer_group_active(p))
12321 vty_out(vty, " %s peer-group member\n",
12322 p->group->name);
12323
12324 paf = peer_af_find(p, afi, safi);
12325 if (paf && PAF_SUBGRP(paf)) {
12326 vty_out(vty, " Update group %" PRIu64", subgroup %" PRIu64 "\n",
12327 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
12328 vty_out(vty, " Packet Queue length %d\n",
12329 bpacket_queue_virtual_length(paf));
12330 } else {
12331 vty_out(vty, " Not part of any update group\n");
12332 }
12333 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12334 || CHECK_FLAG(p->af_cap[afi][safi],
12335 PEER_CAP_ORF_PREFIX_SM_RCV)
12336 || CHECK_FLAG(p->af_cap[afi][safi],
12337 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12338 || CHECK_FLAG(p->af_cap[afi][safi],
12339 PEER_CAP_ORF_PREFIX_RM_ADV)
12340 || CHECK_FLAG(p->af_cap[afi][safi],
12341 PEER_CAP_ORF_PREFIX_RM_RCV)
12342 || CHECK_FLAG(p->af_cap[afi][safi],
12343 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12344 vty_out(vty, " AF-dependant capabilities:\n");
12345
12346 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12347 || CHECK_FLAG(p->af_cap[afi][safi],
12348 PEER_CAP_ORF_PREFIX_SM_RCV)
12349 || CHECK_FLAG(p->af_cap[afi][safi],
12350 PEER_CAP_ORF_PREFIX_RM_ADV)
12351 || CHECK_FLAG(p->af_cap[afi][safi],
12352 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12353 vty_out(vty,
12354 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12355 ORF_TYPE_PREFIX);
12356 bgp_show_peer_afi_orf_cap(
12357 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12358 PEER_CAP_ORF_PREFIX_RM_ADV,
12359 PEER_CAP_ORF_PREFIX_SM_RCV,
12360 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
12361 }
12362 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12363 || CHECK_FLAG(p->af_cap[afi][safi],
12364 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12365 || CHECK_FLAG(p->af_cap[afi][safi],
12366 PEER_CAP_ORF_PREFIX_RM_ADV)
12367 || CHECK_FLAG(p->af_cap[afi][safi],
12368 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12369 vty_out(vty,
12370 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12371 ORF_TYPE_PREFIX_OLD);
12372 bgp_show_peer_afi_orf_cap(
12373 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12374 PEER_CAP_ORF_PREFIX_RM_ADV,
12375 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12376 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
12377 }
12378
12379 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12380 p->host, afi, safi);
12381 orf_pfx_count = prefix_bgp_show_prefix_list(
12382 NULL, afi, orf_pfx_name, use_json);
12383
12384 if (CHECK_FLAG(p->af_sflags[afi][safi],
12385 PEER_STATUS_ORF_PREFIX_SEND)
12386 || orf_pfx_count) {
12387 vty_out(vty, " Outbound Route Filter (ORF):");
12388 if (CHECK_FLAG(p->af_sflags[afi][safi],
12389 PEER_STATUS_ORF_PREFIX_SEND))
12390 vty_out(vty, " sent;");
12391 if (orf_pfx_count)
12392 vty_out(vty, " received (%d entries)",
12393 orf_pfx_count);
12394 vty_out(vty, "\n");
12395 }
12396 if (CHECK_FLAG(p->af_sflags[afi][safi],
12397 PEER_STATUS_ORF_WAIT_REFRESH))
12398 vty_out(vty,
12399 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
12400
12401 if (CHECK_FLAG(p->af_flags[afi][safi],
12402 PEER_FLAG_REFLECTOR_CLIENT))
12403 vty_out(vty, " Route-Reflector Client\n");
12404 if (CHECK_FLAG(p->af_flags[afi][safi],
12405 PEER_FLAG_RSERVER_CLIENT))
12406 vty_out(vty, " Route-Server Client\n");
12407 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12408 vty_out(vty,
12409 " Inbound soft reconfiguration allowed\n");
12410
12411 if (CHECK_FLAG(p->af_flags[afi][safi],
12412 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12413 vty_out(vty,
12414 " Private AS numbers (all) replaced in updates to this neighbor\n");
12415 else if (CHECK_FLAG(p->af_flags[afi][safi],
12416 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12417 vty_out(vty,
12418 " Private AS numbers replaced in updates to this neighbor\n");
12419 else if (CHECK_FLAG(p->af_flags[afi][safi],
12420 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12421 vty_out(vty,
12422 " Private AS numbers (all) removed in updates to this neighbor\n");
12423 else if (CHECK_FLAG(p->af_flags[afi][safi],
12424 PEER_FLAG_REMOVE_PRIVATE_AS))
12425 vty_out(vty,
12426 " Private AS numbers removed in updates to this neighbor\n");
12427
12428 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12429 vty_out(vty, " %s\n",
12430 bgp_addpath_names(p->addpath_type[afi][safi])
12431 ->human_description);
12432
12433 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12434 vty_out(vty,
12435 " Override ASNs in outbound updates if aspath equals remote-as\n");
12436
12437 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12438 || CHECK_FLAG(p->af_flags[afi][safi],
12439 PEER_FLAG_FORCE_NEXTHOP_SELF))
12440 vty_out(vty, " NEXT_HOP is always this router\n");
12441 if (CHECK_FLAG(p->af_flags[afi][safi],
12442 PEER_FLAG_AS_PATH_UNCHANGED))
12443 vty_out(vty,
12444 " AS_PATH is propagated unchanged to this neighbor\n");
12445 if (CHECK_FLAG(p->af_flags[afi][safi],
12446 PEER_FLAG_NEXTHOP_UNCHANGED))
12447 vty_out(vty,
12448 " NEXT_HOP is propagated unchanged to this neighbor\n");
12449 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12450 vty_out(vty,
12451 " MED is propagated unchanged to this neighbor\n");
12452 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12453 || CHECK_FLAG(p->af_flags[afi][safi],
12454 PEER_FLAG_SEND_EXT_COMMUNITY)
12455 || CHECK_FLAG(p->af_flags[afi][safi],
12456 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
12457 vty_out(vty,
12458 " Community attribute sent to this neighbor");
12459 if (CHECK_FLAG(p->af_flags[afi][safi],
12460 PEER_FLAG_SEND_COMMUNITY)
12461 && CHECK_FLAG(p->af_flags[afi][safi],
12462 PEER_FLAG_SEND_EXT_COMMUNITY)
12463 && CHECK_FLAG(p->af_flags[afi][safi],
12464 PEER_FLAG_SEND_LARGE_COMMUNITY))
12465 vty_out(vty, "(all)\n");
12466 else if (CHECK_FLAG(p->af_flags[afi][safi],
12467 PEER_FLAG_SEND_LARGE_COMMUNITY))
12468 vty_out(vty, "(large)\n");
12469 else if (CHECK_FLAG(p->af_flags[afi][safi],
12470 PEER_FLAG_SEND_EXT_COMMUNITY))
12471 vty_out(vty, "(extended)\n");
12472 else
12473 vty_out(vty, "(standard)\n");
12474 }
12475 if (CHECK_FLAG(p->af_flags[afi][safi],
12476 PEER_FLAG_DEFAULT_ORIGINATE)) {
12477 vty_out(vty, " Default information originate,");
12478
12479 if (p->default_rmap[afi][safi].name)
12480 vty_out(vty, " default route-map %s%s,",
12481 p->default_rmap[afi][safi].map ? "*"
12482 : "",
12483 p->default_rmap[afi][safi].name);
12484 if (paf && PAF_SUBGRP(paf)
12485 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12486 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12487 vty_out(vty, " default sent\n");
12488 else
12489 vty_out(vty, " default not sent\n");
12490 }
12491
12492 /* advertise-vni-all */
12493 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
12494 if (is_evpn_enabled())
12495 vty_out(vty, " advertise-all-vni\n");
12496 }
12497
12498 if (filter->plist[FILTER_IN].name
12499 || filter->dlist[FILTER_IN].name
12500 || filter->aslist[FILTER_IN].name
12501 || filter->map[RMAP_IN].name)
12502 vty_out(vty, " Inbound path policy configured\n");
12503 if (filter->plist[FILTER_OUT].name
12504 || filter->dlist[FILTER_OUT].name
12505 || filter->aslist[FILTER_OUT].name
12506 || filter->map[RMAP_OUT].name || filter->usmap.name)
12507 vty_out(vty, " Outbound path policy configured\n");
12508
12509 /* prefix-list */
12510 if (filter->plist[FILTER_IN].name)
12511 vty_out(vty,
12512 " Incoming update prefix filter list is %s%s\n",
12513 filter->plist[FILTER_IN].plist ? "*" : "",
12514 filter->plist[FILTER_IN].name);
12515 if (filter->plist[FILTER_OUT].name)
12516 vty_out(vty,
12517 " Outgoing update prefix filter list is %s%s\n",
12518 filter->plist[FILTER_OUT].plist ? "*" : "",
12519 filter->plist[FILTER_OUT].name);
12520
12521 /* distribute-list */
12522 if (filter->dlist[FILTER_IN].name)
12523 vty_out(vty,
12524 " Incoming update network filter list is %s%s\n",
12525 filter->dlist[FILTER_IN].alist ? "*" : "",
12526 filter->dlist[FILTER_IN].name);
12527 if (filter->dlist[FILTER_OUT].name)
12528 vty_out(vty,
12529 " Outgoing update network filter list is %s%s\n",
12530 filter->dlist[FILTER_OUT].alist ? "*" : "",
12531 filter->dlist[FILTER_OUT].name);
12532
12533 /* filter-list. */
12534 if (filter->aslist[FILTER_IN].name)
12535 vty_out(vty,
12536 " Incoming update AS path filter list is %s%s\n",
12537 filter->aslist[FILTER_IN].aslist ? "*" : "",
12538 filter->aslist[FILTER_IN].name);
12539 if (filter->aslist[FILTER_OUT].name)
12540 vty_out(vty,
12541 " Outgoing update AS path filter list is %s%s\n",
12542 filter->aslist[FILTER_OUT].aslist ? "*" : "",
12543 filter->aslist[FILTER_OUT].name);
12544
12545 /* route-map. */
12546 if (filter->map[RMAP_IN].name)
12547 vty_out(vty,
12548 " Route map for incoming advertisements is %s%s\n",
12549 filter->map[RMAP_IN].map ? "*" : "",
12550 filter->map[RMAP_IN].name);
12551 if (filter->map[RMAP_OUT].name)
12552 vty_out(vty,
12553 " Route map for outgoing advertisements is %s%s\n",
12554 filter->map[RMAP_OUT].map ? "*" : "",
12555 filter->map[RMAP_OUT].name);
12556
12557 /* ebgp-requires-policy (inbound) */
12558 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12559 && !bgp_inbound_policy_exists(p, filter))
12560 vty_out(vty,
12561 " Inbound updates discarded due to missing policy\n");
12562
12563 /* ebgp-requires-policy (outbound) */
12564 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12565 && !bgp_outbound_policy_exists(p, filter))
12566 vty_out(vty,
12567 " Outbound updates discarded due to missing policy\n");
12568
12569 /* unsuppress-map */
12570 if (filter->usmap.name)
12571 vty_out(vty,
12572 " Route map for selective unsuppress is %s%s\n",
12573 filter->usmap.map ? "*" : "",
12574 filter->usmap.name);
12575
12576 /* advertise-map */
12577 if (filter->advmap.aname && filter->advmap.cname)
12578 vty_out(vty,
12579 " Condition %s, Condition-map %s%s, Advertise-map %s%s, status: %s\n",
12580 filter->advmap.condition ? "EXIST"
12581 : "NON_EXIST",
12582 filter->advmap.cmap ? "*" : "",
12583 filter->advmap.cname,
12584 filter->advmap.amap ? "*" : "",
12585 filter->advmap.aname,
12586 filter->advmap.update_type == ADVERTISE
12587 ? "Advertise"
12588 : "Withdraw");
12589
12590 /* Receive prefix count */
12591 vty_out(vty, " %u accepted prefixes\n",
12592 p->pcount[afi][safi]);
12593
12594 /* maximum-prefix-out */
12595 if (CHECK_FLAG(p->af_flags[afi][safi],
12596 PEER_FLAG_MAX_PREFIX_OUT))
12597 vty_out(vty,
12598 " Maximum allowed prefixes sent %u\n",
12599 p->pmax_out[afi][safi]);
12600
12601 /* Maximum prefix */
12602 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12603 vty_out(vty,
12604 " Maximum prefixes allowed %u%s\n",
12605 p->pmax[afi][safi],
12606 CHECK_FLAG(p->af_flags[afi][safi],
12607 PEER_FLAG_MAX_PREFIX_WARNING)
12608 ? " (warning-only)"
12609 : "");
12610 vty_out(vty, " Threshold for warning message %d%%",
12611 p->pmax_threshold[afi][safi]);
12612 if (p->pmax_restart[afi][safi])
12613 vty_out(vty, ", restart interval %d min",
12614 p->pmax_restart[afi][safi]);
12615 vty_out(vty, "\n");
12616 }
12617
12618 vty_out(vty, "\n");
12619 }
12620 }
12621
12622 static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
12623 json_object *json)
12624 {
12625 struct bgp *bgp;
12626 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
12627 char timebuf[BGP_UPTIME_LEN];
12628 char dn_flag[2];
12629 afi_t afi;
12630 safi_t safi;
12631 uint16_t i;
12632 uint8_t *msg;
12633 json_object *json_neigh = NULL;
12634 time_t epoch_tbuf;
12635
12636 bgp = p->bgp;
12637
12638 if (use_json)
12639 json_neigh = json_object_new_object();
12640
12641 memset(dn_flag, '\0', sizeof(dn_flag));
12642 if (!p->conf_if && peer_dynamic_neighbor(p))
12643 dn_flag[0] = '*';
12644
12645 if (!use_json) {
12646 if (p->conf_if) /* Configured interface name. */
12647 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
12648 BGP_PEER_SU_UNSPEC(p)
12649 ? "None"
12650 : sockunion2str(&p->su, buf,
12651 SU_ADDRSTRLEN));
12652 else /* Configured IP address. */
12653 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
12654 p->host);
12655 }
12656
12657 if (use_json) {
12658 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
12659 json_object_string_add(json_neigh, "bgpNeighborAddr",
12660 "none");
12661 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
12662 json_object_string_add(
12663 json_neigh, "bgpNeighborAddr",
12664 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
12665
12666 json_object_int_add(json_neigh, "remoteAs", p->as);
12667
12668 if (p->change_local_as)
12669 json_object_int_add(json_neigh, "localAs",
12670 p->change_local_as);
12671 else
12672 json_object_int_add(json_neigh, "localAs", p->local_as);
12673
12674 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
12675 json_object_boolean_true_add(json_neigh,
12676 "localAsNoPrepend");
12677
12678 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
12679 json_object_boolean_true_add(json_neigh,
12680 "localAsReplaceAs");
12681 } else {
12682 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
12683 || (p->as_type == AS_INTERNAL))
12684 vty_out(vty, "remote AS %u, ", p->as);
12685 else
12686 vty_out(vty, "remote AS Unspecified, ");
12687 vty_out(vty, "local AS %u%s%s, ",
12688 p->change_local_as ? p->change_local_as : p->local_as,
12689 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
12690 ? " no-prepend"
12691 : "",
12692 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
12693 ? " replace-as"
12694 : "");
12695 }
12696 /* peer type internal or confed-internal */
12697 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
12698 if (use_json) {
12699 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12700 json_object_boolean_true_add(
12701 json_neigh, "nbrConfedInternalLink");
12702 else
12703 json_object_boolean_true_add(json_neigh,
12704 "nbrInternalLink");
12705 } else {
12706 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12707 vty_out(vty, "confed-internal link\n");
12708 else
12709 vty_out(vty, "internal link\n");
12710 }
12711 /* peer type external or confed-external */
12712 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
12713 if (use_json) {
12714 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12715 json_object_boolean_true_add(
12716 json_neigh, "nbrConfedExternalLink");
12717 else
12718 json_object_boolean_true_add(json_neigh,
12719 "nbrExternalLink");
12720 } else {
12721 if (bgp_confederation_peers_check(bgp, p->as))
12722 vty_out(vty, "confed-external link\n");
12723 else
12724 vty_out(vty, "external link\n");
12725 }
12726 } else {
12727 if (use_json)
12728 json_object_boolean_true_add(json_neigh,
12729 "nbrUnspecifiedLink");
12730 else
12731 vty_out(vty, "unspecified link\n");
12732 }
12733
12734 /* Description. */
12735 if (p->desc) {
12736 if (use_json)
12737 json_object_string_add(json_neigh, "nbrDesc", p->desc);
12738 else
12739 vty_out(vty, " Description: %s\n", p->desc);
12740 }
12741
12742 if (p->hostname) {
12743 if (use_json) {
12744 if (p->hostname)
12745 json_object_string_add(json_neigh, "hostname",
12746 p->hostname);
12747
12748 if (p->domainname)
12749 json_object_string_add(json_neigh, "domainname",
12750 p->domainname);
12751 } else {
12752 if (p->domainname && (p->domainname[0] != '\0'))
12753 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
12754 p->domainname);
12755 else
12756 vty_out(vty, "Hostname: %s\n", p->hostname);
12757 }
12758 }
12759
12760 /* Peer-group */
12761 if (p->group) {
12762 if (use_json) {
12763 json_object_string_add(json_neigh, "peerGroup",
12764 p->group->name);
12765
12766 if (dn_flag[0]) {
12767 struct prefix prefix, *range = NULL;
12768
12769 if (sockunion2hostprefix(&(p->su), &prefix))
12770 range = peer_group_lookup_dynamic_neighbor_range(
12771 p->group, &prefix);
12772
12773 if (range) {
12774 prefix2str(range, buf1, sizeof(buf1));
12775 json_object_string_add(
12776 json_neigh,
12777 "peerSubnetRangeGroup", buf1);
12778 }
12779 }
12780 } else {
12781 vty_out(vty,
12782 " Member of peer-group %s for session parameters\n",
12783 p->group->name);
12784
12785 if (dn_flag[0]) {
12786 struct prefix prefix, *range = NULL;
12787
12788 if (sockunion2hostprefix(&(p->su), &prefix))
12789 range = peer_group_lookup_dynamic_neighbor_range(
12790 p->group, &prefix);
12791
12792 if (range) {
12793 vty_out(vty,
12794 " Belongs to the subnet range group: %pFX\n",
12795 range);
12796 }
12797 }
12798 }
12799 }
12800
12801 if (use_json) {
12802 /* Administrative shutdown. */
12803 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12804 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
12805 json_object_boolean_true_add(json_neigh,
12806 "adminShutDown");
12807
12808 /* BGP Version. */
12809 json_object_int_add(json_neigh, "bgpVersion", 4);
12810 json_object_string_add(
12811 json_neigh, "remoteRouterId",
12812 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
12813 json_object_string_add(
12814 json_neigh, "localRouterId",
12815 inet_ntop(AF_INET, &bgp->router_id, buf1,
12816 sizeof(buf1)));
12817
12818 /* Confederation */
12819 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12820 && bgp_confederation_peers_check(bgp, p->as))
12821 json_object_boolean_true_add(json_neigh,
12822 "nbrCommonAdmin");
12823
12824 /* Status. */
12825 json_object_string_add(
12826 json_neigh, "bgpState",
12827 lookup_msg(bgp_status_msg, p->status, NULL));
12828
12829 if (p->status == Established) {
12830 time_t uptime;
12831
12832 uptime = bgp_clock();
12833 uptime -= p->uptime;
12834 epoch_tbuf = time(NULL) - uptime;
12835
12836 json_object_int_add(json_neigh, "bgpTimerUpMsec",
12837 uptime * 1000);
12838 json_object_string_add(json_neigh, "bgpTimerUpString",
12839 peer_uptime(p->uptime, timebuf,
12840 BGP_UPTIME_LEN, 0,
12841 NULL));
12842 json_object_int_add(json_neigh,
12843 "bgpTimerUpEstablishedEpoch",
12844 epoch_tbuf);
12845 }
12846
12847 else if (p->status == Active) {
12848 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12849 json_object_string_add(json_neigh, "bgpStateIs",
12850 "passive");
12851 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12852 json_object_string_add(json_neigh, "bgpStateIs",
12853 "passiveNSF");
12854 }
12855
12856 /* read timer */
12857 time_t uptime;
12858 struct tm tm;
12859
12860 uptime = bgp_clock();
12861 uptime -= p->readtime;
12862 gmtime_r(&uptime, &tm);
12863
12864 json_object_int_add(json_neigh, "bgpTimerLastRead",
12865 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12866 + (tm.tm_hour * 3600000));
12867
12868 uptime = bgp_clock();
12869 uptime -= p->last_write;
12870 gmtime_r(&uptime, &tm);
12871
12872 json_object_int_add(json_neigh, "bgpTimerLastWrite",
12873 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12874 + (tm.tm_hour * 3600000));
12875
12876 uptime = bgp_clock();
12877 uptime -= p->update_time;
12878 gmtime_r(&uptime, &tm);
12879
12880 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
12881 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12882 + (tm.tm_hour * 3600000));
12883
12884 /* Configured timer values. */
12885 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
12886 p->v_holdtime * 1000);
12887 json_object_int_add(json_neigh,
12888 "bgpTimerKeepAliveIntervalMsecs",
12889 p->v_keepalive * 1000);
12890 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN)) {
12891 json_object_int_add(json_neigh,
12892 "bgpTimerDelayOpenTimeMsecs",
12893 p->v_delayopen * 1000);
12894 }
12895
12896 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
12897 json_object_int_add(json_neigh,
12898 "bgpTimerConfiguredHoldTimeMsecs",
12899 p->holdtime * 1000);
12900 json_object_int_add(
12901 json_neigh,
12902 "bgpTimerConfiguredKeepAliveIntervalMsecs",
12903 p->keepalive * 1000);
12904 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
12905 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
12906 json_object_int_add(json_neigh,
12907 "bgpTimerConfiguredHoldTimeMsecs",
12908 bgp->default_holdtime);
12909 json_object_int_add(
12910 json_neigh,
12911 "bgpTimerConfiguredKeepAliveIntervalMsecs",
12912 bgp->default_keepalive);
12913 }
12914 } else {
12915 /* Administrative shutdown. */
12916 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12917 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
12918 vty_out(vty, " Administratively shut down\n");
12919
12920 /* BGP Version. */
12921 vty_out(vty, " BGP version 4");
12922 vty_out(vty, ", remote router ID %s",
12923 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
12924 vty_out(vty, ", local router ID %s\n",
12925 inet_ntop(AF_INET, &bgp->router_id, buf1,
12926 sizeof(buf1)));
12927
12928 /* Confederation */
12929 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12930 && bgp_confederation_peers_check(bgp, p->as))
12931 vty_out(vty,
12932 " Neighbor under common administration\n");
12933
12934 /* Status. */
12935 vty_out(vty, " BGP state = %s",
12936 lookup_msg(bgp_status_msg, p->status, NULL));
12937
12938 if (p->status == Established)
12939 vty_out(vty, ", up for %8s",
12940 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
12941 0, NULL));
12942
12943 else if (p->status == Active) {
12944 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12945 vty_out(vty, " (passive)");
12946 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12947 vty_out(vty, " (NSF passive)");
12948 }
12949 vty_out(vty, "\n");
12950
12951 /* read timer */
12952 vty_out(vty, " Last read %s",
12953 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
12954 NULL));
12955 vty_out(vty, ", Last write %s\n",
12956 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
12957 NULL));
12958
12959 /* Configured timer values. */
12960 vty_out(vty,
12961 " Hold time is %d, keepalive interval is %d seconds\n",
12962 p->v_holdtime, p->v_keepalive);
12963 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
12964 vty_out(vty, " Configured hold time is %d",
12965 p->holdtime);
12966 vty_out(vty, ", keepalive interval is %d seconds\n",
12967 p->keepalive);
12968 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
12969 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
12970 vty_out(vty, " Configured hold time is %d",
12971 bgp->default_holdtime);
12972 vty_out(vty, ", keepalive interval is %d seconds\n",
12973 bgp->default_keepalive);
12974 }
12975 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN))
12976 vty_out(vty,
12977 " Configured DelayOpenTime is %d seconds\n",
12978 p->delayopen);
12979 }
12980 /* Capability. */
12981 if (p->status == Established) {
12982 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
12983 || p->afc_recv[AFI_IP][SAFI_UNICAST]
12984 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
12985 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
12986 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
12987 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
12988 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
12989 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
12990 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
12991 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
12992 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
12993 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
12994 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
12995 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
12996 || p->afc_adv[AFI_IP][SAFI_ENCAP]
12997 || p->afc_recv[AFI_IP][SAFI_ENCAP]
12998 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
12999 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
13000 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
13001 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
13002 if (use_json) {
13003 json_object *json_cap = NULL;
13004
13005 json_cap = json_object_new_object();
13006
13007 /* AS4 */
13008 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
13009 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13010 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
13011 && CHECK_FLAG(p->cap,
13012 PEER_CAP_AS4_RCV))
13013 json_object_string_add(
13014 json_cap, "4byteAs",
13015 "advertisedAndReceived");
13016 else if (CHECK_FLAG(p->cap,
13017 PEER_CAP_AS4_ADV))
13018 json_object_string_add(
13019 json_cap, "4byteAs",
13020 "advertised");
13021 else if (CHECK_FLAG(p->cap,
13022 PEER_CAP_AS4_RCV))
13023 json_object_string_add(
13024 json_cap, "4byteAs",
13025 "received");
13026 }
13027
13028 /* Extended Message Support */
13029 if (CHECK_FLAG(p->cap,
13030 PEER_CAP_EXTENDED_MESSAGE_ADV)
13031 && CHECK_FLAG(
13032 p->cap,
13033 PEER_CAP_EXTENDED_MESSAGE_RCV))
13034 json_object_string_add(
13035 json_cap, "extendedMessage",
13036 "advertisedAndReceived");
13037 else if (CHECK_FLAG(
13038 p->cap,
13039 PEER_CAP_EXTENDED_MESSAGE_ADV))
13040 json_object_string_add(
13041 json_cap, "extendedMessage",
13042 "advertised");
13043 else if (CHECK_FLAG(
13044 p->cap,
13045 PEER_CAP_EXTENDED_MESSAGE_RCV))
13046 json_object_string_add(
13047 json_cap, "extendedMessage",
13048 "received");
13049
13050 /* AddPath */
13051 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
13052 || CHECK_FLAG(p->cap,
13053 PEER_CAP_ADDPATH_ADV)) {
13054 json_object *json_add = NULL;
13055 const char *print_store;
13056
13057 json_add = json_object_new_object();
13058
13059 FOREACH_AFI_SAFI (afi, safi) {
13060 json_object *json_sub = NULL;
13061 json_sub =
13062 json_object_new_object();
13063 print_store = get_afi_safi_str(
13064 afi, safi, true);
13065
13066 if (CHECK_FLAG(
13067 p->af_cap[afi]
13068 [safi],
13069 PEER_CAP_ADDPATH_AF_TX_ADV)
13070 || CHECK_FLAG(
13071 p->af_cap[afi]
13072 [safi],
13073 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13074 if (CHECK_FLAG(
13075 p->af_cap
13076 [afi]
13077 [safi],
13078 PEER_CAP_ADDPATH_AF_TX_ADV)
13079 && CHECK_FLAG(
13080 p->af_cap
13081 [afi]
13082 [safi],
13083 PEER_CAP_ADDPATH_AF_TX_RCV))
13084 json_object_boolean_true_add(
13085 json_sub,
13086 "txAdvertisedAndReceived");
13087 else if (
13088 CHECK_FLAG(
13089 p->af_cap
13090 [afi]
13091 [safi],
13092 PEER_CAP_ADDPATH_AF_TX_ADV))
13093 json_object_boolean_true_add(
13094 json_sub,
13095 "txAdvertised");
13096 else if (
13097 CHECK_FLAG(
13098 p->af_cap
13099 [afi]
13100 [safi],
13101 PEER_CAP_ADDPATH_AF_TX_RCV))
13102 json_object_boolean_true_add(
13103 json_sub,
13104 "txReceived");
13105 }
13106
13107 if (CHECK_FLAG(
13108 p->af_cap[afi]
13109 [safi],
13110 PEER_CAP_ADDPATH_AF_RX_ADV)
13111 || CHECK_FLAG(
13112 p->af_cap[afi]
13113 [safi],
13114 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13115 if (CHECK_FLAG(
13116 p->af_cap
13117 [afi]
13118 [safi],
13119 PEER_CAP_ADDPATH_AF_RX_ADV)
13120 && CHECK_FLAG(
13121 p->af_cap
13122 [afi]
13123 [safi],
13124 PEER_CAP_ADDPATH_AF_RX_RCV))
13125 json_object_boolean_true_add(
13126 json_sub,
13127 "rxAdvertisedAndReceived");
13128 else if (
13129 CHECK_FLAG(
13130 p->af_cap
13131 [afi]
13132 [safi],
13133 PEER_CAP_ADDPATH_AF_RX_ADV))
13134 json_object_boolean_true_add(
13135 json_sub,
13136 "rxAdvertised");
13137 else if (
13138 CHECK_FLAG(
13139 p->af_cap
13140 [afi]
13141 [safi],
13142 PEER_CAP_ADDPATH_AF_RX_RCV))
13143 json_object_boolean_true_add(
13144 json_sub,
13145 "rxReceived");
13146 }
13147
13148 if (CHECK_FLAG(
13149 p->af_cap[afi]
13150 [safi],
13151 PEER_CAP_ADDPATH_AF_TX_ADV)
13152 || CHECK_FLAG(
13153 p->af_cap[afi]
13154 [safi],
13155 PEER_CAP_ADDPATH_AF_TX_RCV)
13156 || CHECK_FLAG(
13157 p->af_cap[afi]
13158 [safi],
13159 PEER_CAP_ADDPATH_AF_RX_ADV)
13160 || CHECK_FLAG(
13161 p->af_cap[afi]
13162 [safi],
13163 PEER_CAP_ADDPATH_AF_RX_RCV))
13164 json_object_object_add(
13165 json_add,
13166 print_store,
13167 json_sub);
13168 else
13169 json_object_free(
13170 json_sub);
13171 }
13172
13173 json_object_object_add(
13174 json_cap, "addPath", json_add);
13175 }
13176
13177 /* Dynamic */
13178 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
13179 || CHECK_FLAG(p->cap,
13180 PEER_CAP_DYNAMIC_ADV)) {
13181 if (CHECK_FLAG(p->cap,
13182 PEER_CAP_DYNAMIC_ADV)
13183 && CHECK_FLAG(p->cap,
13184 PEER_CAP_DYNAMIC_RCV))
13185 json_object_string_add(
13186 json_cap, "dynamic",
13187 "advertisedAndReceived");
13188 else if (CHECK_FLAG(
13189 p->cap,
13190 PEER_CAP_DYNAMIC_ADV))
13191 json_object_string_add(
13192 json_cap, "dynamic",
13193 "advertised");
13194 else if (CHECK_FLAG(
13195 p->cap,
13196 PEER_CAP_DYNAMIC_RCV))
13197 json_object_string_add(
13198 json_cap, "dynamic",
13199 "received");
13200 }
13201
13202 /* Extended nexthop */
13203 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
13204 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13205 json_object *json_nxt = NULL;
13206 const char *print_store;
13207
13208
13209 if (CHECK_FLAG(p->cap,
13210 PEER_CAP_ENHE_ADV)
13211 && CHECK_FLAG(p->cap,
13212 PEER_CAP_ENHE_RCV))
13213 json_object_string_add(
13214 json_cap,
13215 "extendedNexthop",
13216 "advertisedAndReceived");
13217 else if (CHECK_FLAG(p->cap,
13218 PEER_CAP_ENHE_ADV))
13219 json_object_string_add(
13220 json_cap,
13221 "extendedNexthop",
13222 "advertised");
13223 else if (CHECK_FLAG(p->cap,
13224 PEER_CAP_ENHE_RCV))
13225 json_object_string_add(
13226 json_cap,
13227 "extendedNexthop",
13228 "received");
13229
13230 if (CHECK_FLAG(p->cap,
13231 PEER_CAP_ENHE_RCV)) {
13232 json_nxt =
13233 json_object_new_object();
13234
13235 for (safi = SAFI_UNICAST;
13236 safi < SAFI_MAX; safi++) {
13237 if (CHECK_FLAG(
13238 p->af_cap
13239 [AFI_IP]
13240 [safi],
13241 PEER_CAP_ENHE_AF_RCV)) {
13242 print_store = get_afi_safi_str(
13243 AFI_IP,
13244 safi, true);
13245 json_object_string_add(
13246 json_nxt,
13247 print_store,
13248 "recieved"); /* misspelled for compatibility */
13249 }
13250 }
13251 json_object_object_add(
13252 json_cap,
13253 "extendedNexthopFamililesByPeer",
13254 json_nxt);
13255 }
13256 }
13257
13258 /* Route Refresh */
13259 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
13260 || CHECK_FLAG(p->cap,
13261 PEER_CAP_REFRESH_NEW_RCV)
13262 || CHECK_FLAG(p->cap,
13263 PEER_CAP_REFRESH_OLD_RCV)) {
13264 if (CHECK_FLAG(p->cap,
13265 PEER_CAP_REFRESH_ADV)
13266 && (CHECK_FLAG(
13267 p->cap,
13268 PEER_CAP_REFRESH_NEW_RCV)
13269 || CHECK_FLAG(
13270 p->cap,
13271 PEER_CAP_REFRESH_OLD_RCV))) {
13272 if (CHECK_FLAG(
13273 p->cap,
13274 PEER_CAP_REFRESH_OLD_RCV)
13275 && CHECK_FLAG(
13276 p->cap,
13277 PEER_CAP_REFRESH_NEW_RCV))
13278 json_object_string_add(
13279 json_cap,
13280 "routeRefresh",
13281 "advertisedAndReceivedOldNew");
13282 else {
13283 if (CHECK_FLAG(
13284 p->cap,
13285 PEER_CAP_REFRESH_OLD_RCV))
13286 json_object_string_add(
13287 json_cap,
13288 "routeRefresh",
13289 "advertisedAndReceivedOld");
13290 else
13291 json_object_string_add(
13292 json_cap,
13293 "routeRefresh",
13294 "advertisedAndReceivedNew");
13295 }
13296 } else if (
13297 CHECK_FLAG(
13298 p->cap,
13299 PEER_CAP_REFRESH_ADV))
13300 json_object_string_add(
13301 json_cap,
13302 "routeRefresh",
13303 "advertised");
13304 else if (
13305 CHECK_FLAG(
13306 p->cap,
13307 PEER_CAP_REFRESH_NEW_RCV)
13308 || CHECK_FLAG(
13309 p->cap,
13310 PEER_CAP_REFRESH_OLD_RCV))
13311 json_object_string_add(
13312 json_cap,
13313 "routeRefresh",
13314 "received");
13315 }
13316
13317 /* Enhanced Route Refresh */
13318 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV)
13319 || CHECK_FLAG(p->cap,
13320 PEER_CAP_ENHANCED_RR_RCV)) {
13321 if (CHECK_FLAG(p->cap,
13322 PEER_CAP_ENHANCED_RR_ADV)
13323 && CHECK_FLAG(
13324 p->cap,
13325 PEER_CAP_ENHANCED_RR_RCV))
13326 json_object_string_add(
13327 json_cap,
13328 "enhancedRouteRefresh",
13329 "advertisedAndReceived");
13330 else if (
13331 CHECK_FLAG(
13332 p->cap,
13333 PEER_CAP_ENHANCED_RR_ADV))
13334 json_object_string_add(
13335 json_cap,
13336 "enhancedRouteRefresh",
13337 "advertised");
13338 else if (
13339 CHECK_FLAG(
13340 p->cap,
13341 PEER_CAP_ENHANCED_RR_RCV))
13342 json_object_string_add(
13343 json_cap,
13344 "enhancedRouteRefresh",
13345 "received");
13346 }
13347
13348 /* Multiprotocol Extensions */
13349 json_object *json_multi = NULL;
13350 json_multi = json_object_new_object();
13351
13352 FOREACH_AFI_SAFI (afi, safi) {
13353 if (p->afc_adv[afi][safi]
13354 || p->afc_recv[afi][safi]) {
13355 json_object *json_exten = NULL;
13356 json_exten =
13357 json_object_new_object();
13358
13359 if (p->afc_adv[afi][safi]
13360 && p->afc_recv[afi][safi])
13361 json_object_boolean_true_add(
13362 json_exten,
13363 "advertisedAndReceived");
13364 else if (p->afc_adv[afi][safi])
13365 json_object_boolean_true_add(
13366 json_exten,
13367 "advertised");
13368 else if (p->afc_recv[afi][safi])
13369 json_object_boolean_true_add(
13370 json_exten,
13371 "received");
13372
13373 json_object_object_add(
13374 json_multi,
13375 get_afi_safi_str(afi,
13376 safi,
13377 true),
13378 json_exten);
13379 }
13380 }
13381 json_object_object_add(
13382 json_cap, "multiprotocolExtensions",
13383 json_multi);
13384
13385 /* Hostname capabilities */
13386 json_object *json_hname = NULL;
13387
13388 json_hname = json_object_new_object();
13389
13390 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13391 json_object_string_add(
13392 json_hname, "advHostName",
13393 bgp->peer_self->hostname
13394 ? bgp->peer_self
13395 ->hostname
13396 : "n/a");
13397 json_object_string_add(
13398 json_hname, "advDomainName",
13399 bgp->peer_self->domainname
13400 ? bgp->peer_self
13401 ->domainname
13402 : "n/a");
13403 }
13404
13405
13406 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13407 json_object_string_add(
13408 json_hname, "rcvHostName",
13409 p->hostname ? p->hostname
13410 : "n/a");
13411 json_object_string_add(
13412 json_hname, "rcvDomainName",
13413 p->domainname ? p->domainname
13414 : "n/a");
13415 }
13416
13417 json_object_object_add(json_cap, "hostName",
13418 json_hname);
13419
13420 /* Gracefull Restart */
13421 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
13422 || CHECK_FLAG(p->cap,
13423 PEER_CAP_RESTART_ADV)) {
13424 if (CHECK_FLAG(p->cap,
13425 PEER_CAP_RESTART_ADV)
13426 && CHECK_FLAG(p->cap,
13427 PEER_CAP_RESTART_RCV))
13428 json_object_string_add(
13429 json_cap,
13430 "gracefulRestart",
13431 "advertisedAndReceived");
13432 else if (CHECK_FLAG(
13433 p->cap,
13434 PEER_CAP_RESTART_ADV))
13435 json_object_string_add(
13436 json_cap,
13437 "gracefulRestartCapability",
13438 "advertised");
13439 else if (CHECK_FLAG(
13440 p->cap,
13441 PEER_CAP_RESTART_RCV))
13442 json_object_string_add(
13443 json_cap,
13444 "gracefulRestartCapability",
13445 "received");
13446
13447 if (CHECK_FLAG(p->cap,
13448 PEER_CAP_RESTART_RCV)) {
13449 int restart_af_count = 0;
13450 json_object *json_restart =
13451 NULL;
13452 json_restart =
13453 json_object_new_object();
13454
13455 json_object_int_add(
13456 json_cap,
13457 "gracefulRestartRemoteTimerMsecs",
13458 p->v_gr_restart * 1000);
13459
13460 FOREACH_AFI_SAFI (afi, safi) {
13461 if (CHECK_FLAG(
13462 p->af_cap
13463 [afi]
13464 [safi],
13465 PEER_CAP_RESTART_AF_RCV)) {
13466 json_object *
13467 json_sub =
13468 NULL;
13469 json_sub =
13470 json_object_new_object();
13471
13472 if (CHECK_FLAG(
13473 p->af_cap
13474 [afi]
13475 [safi],
13476 PEER_CAP_RESTART_AF_PRESERVE_RCV))
13477 json_object_boolean_true_add(
13478 json_sub,
13479 "preserved");
13480 restart_af_count++;
13481 json_object_object_add(
13482 json_restart,
13483 get_afi_safi_str(
13484 afi,
13485 safi,
13486 true),
13487 json_sub);
13488 }
13489 }
13490 if (!restart_af_count) {
13491 json_object_string_add(
13492 json_cap,
13493 "addressFamiliesByPeer",
13494 "none");
13495 json_object_free(
13496 json_restart);
13497 } else
13498 json_object_object_add(
13499 json_cap,
13500 "addressFamiliesByPeer",
13501 json_restart);
13502 }
13503 }
13504 json_object_object_add(json_neigh,
13505 "neighborCapabilities",
13506 json_cap);
13507 } else {
13508 vty_out(vty, " Neighbor capabilities:\n");
13509
13510 /* AS4 */
13511 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
13512 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13513 vty_out(vty, " 4 Byte AS:");
13514 if (CHECK_FLAG(p->cap,
13515 PEER_CAP_AS4_ADV))
13516 vty_out(vty, " advertised");
13517 if (CHECK_FLAG(p->cap,
13518 PEER_CAP_AS4_RCV))
13519 vty_out(vty, " %sreceived",
13520 CHECK_FLAG(
13521 p->cap,
13522 PEER_CAP_AS4_ADV)
13523 ? "and "
13524 : "");
13525 vty_out(vty, "\n");
13526 }
13527
13528 /* Extended Message Support */
13529 if (CHECK_FLAG(p->cap,
13530 PEER_CAP_EXTENDED_MESSAGE_RCV)
13531 || CHECK_FLAG(
13532 p->cap,
13533 PEER_CAP_EXTENDED_MESSAGE_ADV)) {
13534 vty_out(vty, " Extended Message:");
13535 if (CHECK_FLAG(
13536 p->cap,
13537 PEER_CAP_EXTENDED_MESSAGE_ADV))
13538 vty_out(vty, " advertised");
13539 if (CHECK_FLAG(
13540 p->cap,
13541 PEER_CAP_EXTENDED_MESSAGE_RCV))
13542 vty_out(vty, " %sreceived",
13543 CHECK_FLAG(
13544 p->cap,
13545 PEER_CAP_EXTENDED_MESSAGE_ADV)
13546 ? "and "
13547 : "");
13548 vty_out(vty, "\n");
13549 }
13550
13551 /* AddPath */
13552 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
13553 || CHECK_FLAG(p->cap,
13554 PEER_CAP_ADDPATH_ADV)) {
13555 vty_out(vty, " AddPath:\n");
13556
13557 FOREACH_AFI_SAFI (afi, safi) {
13558 if (CHECK_FLAG(
13559 p->af_cap[afi]
13560 [safi],
13561 PEER_CAP_ADDPATH_AF_TX_ADV)
13562 || CHECK_FLAG(
13563 p->af_cap[afi]
13564 [safi],
13565 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13566 vty_out(vty,
13567 " %s: TX ",
13568 get_afi_safi_str(
13569 afi,
13570 safi,
13571 false));
13572
13573 if (CHECK_FLAG(
13574 p->af_cap
13575 [afi]
13576 [safi],
13577 PEER_CAP_ADDPATH_AF_TX_ADV))
13578 vty_out(vty,
13579 "advertised %s",
13580 get_afi_safi_str(
13581 afi,
13582 safi,
13583 false));
13584
13585 if (CHECK_FLAG(
13586 p->af_cap
13587 [afi]
13588 [safi],
13589 PEER_CAP_ADDPATH_AF_TX_RCV))
13590 vty_out(vty,
13591 "%sreceived",
13592 CHECK_FLAG(
13593 p->af_cap
13594 [afi]
13595 [safi],
13596 PEER_CAP_ADDPATH_AF_TX_ADV)
13597 ? " and "
13598 : "");
13599
13600 vty_out(vty, "\n");
13601 }
13602
13603 if (CHECK_FLAG(
13604 p->af_cap[afi]
13605 [safi],
13606 PEER_CAP_ADDPATH_AF_RX_ADV)
13607 || CHECK_FLAG(
13608 p->af_cap[afi]
13609 [safi],
13610 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13611 vty_out(vty,
13612 " %s: RX ",
13613 get_afi_safi_str(
13614 afi,
13615 safi,
13616 false));
13617
13618 if (CHECK_FLAG(
13619 p->af_cap
13620 [afi]
13621 [safi],
13622 PEER_CAP_ADDPATH_AF_RX_ADV))
13623 vty_out(vty,
13624 "advertised %s",
13625 get_afi_safi_str(
13626 afi,
13627 safi,
13628 false));
13629
13630 if (CHECK_FLAG(
13631 p->af_cap
13632 [afi]
13633 [safi],
13634 PEER_CAP_ADDPATH_AF_RX_RCV))
13635 vty_out(vty,
13636 "%sreceived",
13637 CHECK_FLAG(
13638 p->af_cap
13639 [afi]
13640 [safi],
13641 PEER_CAP_ADDPATH_AF_RX_ADV)
13642 ? " and "
13643 : "");
13644
13645 vty_out(vty, "\n");
13646 }
13647 }
13648 }
13649
13650 /* Dynamic */
13651 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
13652 || CHECK_FLAG(p->cap,
13653 PEER_CAP_DYNAMIC_ADV)) {
13654 vty_out(vty, " Dynamic:");
13655 if (CHECK_FLAG(p->cap,
13656 PEER_CAP_DYNAMIC_ADV))
13657 vty_out(vty, " advertised");
13658 if (CHECK_FLAG(p->cap,
13659 PEER_CAP_DYNAMIC_RCV))
13660 vty_out(vty, " %sreceived",
13661 CHECK_FLAG(
13662 p->cap,
13663 PEER_CAP_DYNAMIC_ADV)
13664 ? "and "
13665 : "");
13666 vty_out(vty, "\n");
13667 }
13668
13669 /* Extended nexthop */
13670 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
13671 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13672 vty_out(vty, " Extended nexthop:");
13673 if (CHECK_FLAG(p->cap,
13674 PEER_CAP_ENHE_ADV))
13675 vty_out(vty, " advertised");
13676 if (CHECK_FLAG(p->cap,
13677 PEER_CAP_ENHE_RCV))
13678 vty_out(vty, " %sreceived",
13679 CHECK_FLAG(
13680 p->cap,
13681 PEER_CAP_ENHE_ADV)
13682 ? "and "
13683 : "");
13684 vty_out(vty, "\n");
13685
13686 if (CHECK_FLAG(p->cap,
13687 PEER_CAP_ENHE_RCV)) {
13688 vty_out(vty,
13689 " Address families by peer:\n ");
13690 for (safi = SAFI_UNICAST;
13691 safi < SAFI_MAX; safi++)
13692 if (CHECK_FLAG(
13693 p->af_cap
13694 [AFI_IP]
13695 [safi],
13696 PEER_CAP_ENHE_AF_RCV))
13697 vty_out(vty,
13698 " %s\n",
13699 get_afi_safi_str(
13700 AFI_IP,
13701 safi,
13702 false));
13703 }
13704 }
13705
13706 /* Route Refresh */
13707 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
13708 || CHECK_FLAG(p->cap,
13709 PEER_CAP_REFRESH_NEW_RCV)
13710 || CHECK_FLAG(p->cap,
13711 PEER_CAP_REFRESH_OLD_RCV)) {
13712 vty_out(vty, " Route refresh:");
13713 if (CHECK_FLAG(p->cap,
13714 PEER_CAP_REFRESH_ADV))
13715 vty_out(vty, " advertised");
13716 if (CHECK_FLAG(p->cap,
13717 PEER_CAP_REFRESH_NEW_RCV)
13718 || CHECK_FLAG(
13719 p->cap,
13720 PEER_CAP_REFRESH_OLD_RCV))
13721 vty_out(vty, " %sreceived(%s)",
13722 CHECK_FLAG(
13723 p->cap,
13724 PEER_CAP_REFRESH_ADV)
13725 ? "and "
13726 : "",
13727 (CHECK_FLAG(
13728 p->cap,
13729 PEER_CAP_REFRESH_OLD_RCV)
13730 && CHECK_FLAG(
13731 p->cap,
13732 PEER_CAP_REFRESH_NEW_RCV))
13733 ? "old & new"
13734 : CHECK_FLAG(
13735 p->cap,
13736 PEER_CAP_REFRESH_OLD_RCV)
13737 ? "old"
13738 : "new");
13739
13740 vty_out(vty, "\n");
13741 }
13742
13743 /* Enhanced Route Refresh */
13744 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV)
13745 || CHECK_FLAG(p->cap,
13746 PEER_CAP_ENHANCED_RR_RCV)) {
13747 vty_out(vty,
13748 " Enhanced Route Refresh:");
13749 if (CHECK_FLAG(
13750 p->cap,
13751 PEER_CAP_ENHANCED_RR_ADV))
13752 vty_out(vty, " advertised");
13753 if (CHECK_FLAG(
13754 p->cap,
13755 PEER_CAP_ENHANCED_RR_RCV))
13756 vty_out(vty, " %sreceived",
13757 CHECK_FLAG(
13758 p->cap,
13759 PEER_CAP_REFRESH_ADV)
13760 ? "and "
13761 : "");
13762 vty_out(vty, "\n");
13763 }
13764
13765 /* Multiprotocol Extensions */
13766 FOREACH_AFI_SAFI (afi, safi)
13767 if (p->afc_adv[afi][safi]
13768 || p->afc_recv[afi][safi]) {
13769 vty_out(vty,
13770 " Address Family %s:",
13771 get_afi_safi_str(
13772 afi,
13773 safi,
13774 false));
13775 if (p->afc_adv[afi][safi])
13776 vty_out(vty,
13777 " advertised");
13778 if (p->afc_recv[afi][safi])
13779 vty_out(vty,
13780 " %sreceived",
13781 p->afc_adv[afi]
13782 [safi]
13783 ? "and "
13784 : "");
13785 vty_out(vty, "\n");
13786 }
13787
13788 /* Hostname capability */
13789 vty_out(vty, " Hostname Capability:");
13790
13791 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13792 vty_out(vty,
13793 " advertised (name: %s,domain name: %s)",
13794 bgp->peer_self->hostname
13795 ? bgp->peer_self
13796 ->hostname
13797 : "n/a",
13798 bgp->peer_self->domainname
13799 ? bgp->peer_self
13800 ->domainname
13801 : "n/a");
13802 } else {
13803 vty_out(vty, " not advertised");
13804 }
13805
13806 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13807 vty_out(vty,
13808 " received (name: %s,domain name: %s)",
13809 p->hostname ? p->hostname
13810 : "n/a",
13811 p->domainname ? p->domainname
13812 : "n/a");
13813 } else {
13814 vty_out(vty, " not received");
13815 }
13816
13817 vty_out(vty, "\n");
13818
13819 /* Graceful Restart */
13820 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
13821 || CHECK_FLAG(p->cap,
13822 PEER_CAP_RESTART_ADV)) {
13823 vty_out(vty,
13824 " Graceful Restart Capability:");
13825 if (CHECK_FLAG(p->cap,
13826 PEER_CAP_RESTART_ADV))
13827 vty_out(vty, " advertised");
13828 if (CHECK_FLAG(p->cap,
13829 PEER_CAP_RESTART_RCV))
13830 vty_out(vty, " %sreceived",
13831 CHECK_FLAG(
13832 p->cap,
13833 PEER_CAP_RESTART_ADV)
13834 ? "and "
13835 : "");
13836 vty_out(vty, "\n");
13837
13838 if (CHECK_FLAG(p->cap,
13839 PEER_CAP_RESTART_RCV)) {
13840 int restart_af_count = 0;
13841
13842 vty_out(vty,
13843 " Remote Restart timer is %d seconds\n",
13844 p->v_gr_restart);
13845 vty_out(vty,
13846 " Address families by peer:\n ");
13847
13848 FOREACH_AFI_SAFI (afi, safi)
13849 if (CHECK_FLAG(
13850 p->af_cap
13851 [afi]
13852 [safi],
13853 PEER_CAP_RESTART_AF_RCV)) {
13854 vty_out(vty,
13855 "%s%s(%s)",
13856 restart_af_count
13857 ? ", "
13858 : "",
13859 get_afi_safi_str(
13860 afi,
13861 safi,
13862 false),
13863 CHECK_FLAG(
13864 p->af_cap
13865 [afi]
13866 [safi],
13867 PEER_CAP_RESTART_AF_PRESERVE_RCV)
13868 ? "preserved"
13869 : "not preserved");
13870 restart_af_count++;
13871 }
13872 if (!restart_af_count)
13873 vty_out(vty, "none");
13874 vty_out(vty, "\n");
13875 }
13876 } /* Gracefull Restart */
13877 }
13878 }
13879 }
13880
13881 /* graceful restart information */
13882 json_object *json_grace = NULL;
13883 json_object *json_grace_send = NULL;
13884 json_object *json_grace_recv = NULL;
13885 int eor_send_af_count = 0;
13886 int eor_receive_af_count = 0;
13887
13888 if (use_json) {
13889 json_grace = json_object_new_object();
13890 json_grace_send = json_object_new_object();
13891 json_grace_recv = json_object_new_object();
13892
13893 if ((p->status == Established)
13894 && CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13895 FOREACH_AFI_SAFI (afi, safi) {
13896 if (CHECK_FLAG(p->af_sflags[afi][safi],
13897 PEER_STATUS_EOR_SEND)) {
13898 json_object_boolean_true_add(
13899 json_grace_send,
13900 get_afi_safi_str(afi,
13901 safi,
13902 true));
13903 eor_send_af_count++;
13904 }
13905 }
13906 FOREACH_AFI_SAFI (afi, safi) {
13907 if (CHECK_FLAG(
13908 p->af_sflags[afi][safi],
13909 PEER_STATUS_EOR_RECEIVED)) {
13910 json_object_boolean_true_add(
13911 json_grace_recv,
13912 get_afi_safi_str(afi,
13913 safi,
13914 true));
13915 eor_receive_af_count++;
13916 }
13917 }
13918 }
13919 json_object_object_add(json_grace, "endOfRibSend",
13920 json_grace_send);
13921 json_object_object_add(json_grace, "endOfRibRecv",
13922 json_grace_recv);
13923
13924
13925 if (p->t_gr_restart)
13926 json_object_int_add(json_grace,
13927 "gracefulRestartTimerMsecs",
13928 thread_timer_remain_second(
13929 p->t_gr_restart)
13930 * 1000);
13931
13932 if (p->t_gr_stale)
13933 json_object_int_add(
13934 json_grace,
13935 "gracefulStalepathTimerMsecs",
13936 thread_timer_remain_second(
13937 p->t_gr_stale)
13938 * 1000);
13939 /* more gr info in new format */
13940 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json,
13941 json_grace);
13942 json_object_object_add(
13943 json_neigh, "gracefulRestartInfo", json_grace);
13944 } else {
13945 vty_out(vty, " Graceful restart information:\n");
13946 if ((p->status == Established)
13947 && CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13948
13949 vty_out(vty, " End-of-RIB send: ");
13950 FOREACH_AFI_SAFI (afi, safi) {
13951 if (CHECK_FLAG(p->af_sflags[afi][safi],
13952 PEER_STATUS_EOR_SEND)) {
13953 vty_out(vty, "%s%s",
13954 eor_send_af_count ? ", "
13955 : "",
13956 get_afi_safi_str(
13957 afi, safi,
13958 false));
13959 eor_send_af_count++;
13960 }
13961 }
13962 vty_out(vty, "\n");
13963 vty_out(vty, " End-of-RIB received: ");
13964 FOREACH_AFI_SAFI (afi, safi) {
13965 if (CHECK_FLAG(
13966 p->af_sflags[afi][safi],
13967 PEER_STATUS_EOR_RECEIVED)) {
13968 vty_out(vty, "%s%s",
13969 eor_receive_af_count
13970 ? ", "
13971 : "",
13972 get_afi_safi_str(afi,
13973 safi,
13974 false));
13975 eor_receive_af_count++;
13976 }
13977 }
13978 vty_out(vty, "\n");
13979 }
13980
13981 if (p->t_gr_restart)
13982 vty_out(vty,
13983 " The remaining time of restart timer is %ld\n",
13984 thread_timer_remain_second(
13985 p->t_gr_restart));
13986
13987 if (p->t_gr_stale)
13988 vty_out(vty,
13989 " The remaining time of stalepath timer is %ld\n",
13990 thread_timer_remain_second(
13991 p->t_gr_stale));
13992
13993 /* more gr info in new format */
13994 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, NULL);
13995 }
13996
13997 if (use_json) {
13998 json_object *json_stat = NULL;
13999 json_stat = json_object_new_object();
14000 /* Packet counts. */
14001
14002 atomic_size_t outq_count, inq_count;
14003 outq_count = atomic_load_explicit(&p->obuf->count,
14004 memory_order_relaxed);
14005 inq_count = atomic_load_explicit(&p->ibuf->count,
14006 memory_order_relaxed);
14007
14008 json_object_int_add(json_stat, "depthInq",
14009 (unsigned long)inq_count);
14010 json_object_int_add(json_stat, "depthOutq",
14011 (unsigned long)outq_count);
14012 json_object_int_add(json_stat, "opensSent",
14013 atomic_load_explicit(&p->open_out,
14014 memory_order_relaxed));
14015 json_object_int_add(json_stat, "opensRecv",
14016 atomic_load_explicit(&p->open_in,
14017 memory_order_relaxed));
14018 json_object_int_add(json_stat, "notificationsSent",
14019 atomic_load_explicit(&p->notify_out,
14020 memory_order_relaxed));
14021 json_object_int_add(json_stat, "notificationsRecv",
14022 atomic_load_explicit(&p->notify_in,
14023 memory_order_relaxed));
14024 json_object_int_add(json_stat, "updatesSent",
14025 atomic_load_explicit(&p->update_out,
14026 memory_order_relaxed));
14027 json_object_int_add(json_stat, "updatesRecv",
14028 atomic_load_explicit(&p->update_in,
14029 memory_order_relaxed));
14030 json_object_int_add(json_stat, "keepalivesSent",
14031 atomic_load_explicit(&p->keepalive_out,
14032 memory_order_relaxed));
14033 json_object_int_add(json_stat, "keepalivesRecv",
14034 atomic_load_explicit(&p->keepalive_in,
14035 memory_order_relaxed));
14036 json_object_int_add(json_stat, "routeRefreshSent",
14037 atomic_load_explicit(&p->refresh_out,
14038 memory_order_relaxed));
14039 json_object_int_add(json_stat, "routeRefreshRecv",
14040 atomic_load_explicit(&p->refresh_in,
14041 memory_order_relaxed));
14042 json_object_int_add(json_stat, "capabilitySent",
14043 atomic_load_explicit(&p->dynamic_cap_out,
14044 memory_order_relaxed));
14045 json_object_int_add(json_stat, "capabilityRecv",
14046 atomic_load_explicit(&p->dynamic_cap_in,
14047 memory_order_relaxed));
14048 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
14049 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
14050 json_object_object_add(json_neigh, "messageStats", json_stat);
14051 } else {
14052 atomic_size_t outq_count, inq_count;
14053 outq_count = atomic_load_explicit(&p->obuf->count,
14054 memory_order_relaxed);
14055 inq_count = atomic_load_explicit(&p->ibuf->count,
14056 memory_order_relaxed);
14057
14058 /* Packet counts. */
14059 vty_out(vty, " Message statistics:\n");
14060 vty_out(vty, " Inq depth is %zu\n", inq_count);
14061 vty_out(vty, " Outq depth is %zu\n", outq_count);
14062 vty_out(vty, " Sent Rcvd\n");
14063 vty_out(vty, " Opens: %10d %10d\n",
14064 atomic_load_explicit(&p->open_out,
14065 memory_order_relaxed),
14066 atomic_load_explicit(&p->open_in,
14067 memory_order_relaxed));
14068 vty_out(vty, " Notifications: %10d %10d\n",
14069 atomic_load_explicit(&p->notify_out,
14070 memory_order_relaxed),
14071 atomic_load_explicit(&p->notify_in,
14072 memory_order_relaxed));
14073 vty_out(vty, " Updates: %10d %10d\n",
14074 atomic_load_explicit(&p->update_out,
14075 memory_order_relaxed),
14076 atomic_load_explicit(&p->update_in,
14077 memory_order_relaxed));
14078 vty_out(vty, " Keepalives: %10d %10d\n",
14079 atomic_load_explicit(&p->keepalive_out,
14080 memory_order_relaxed),
14081 atomic_load_explicit(&p->keepalive_in,
14082 memory_order_relaxed));
14083 vty_out(vty, " Route Refresh: %10d %10d\n",
14084 atomic_load_explicit(&p->refresh_out,
14085 memory_order_relaxed),
14086 atomic_load_explicit(&p->refresh_in,
14087 memory_order_relaxed));
14088 vty_out(vty, " Capability: %10d %10d\n",
14089 atomic_load_explicit(&p->dynamic_cap_out,
14090 memory_order_relaxed),
14091 atomic_load_explicit(&p->dynamic_cap_in,
14092 memory_order_relaxed));
14093 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
14094 PEER_TOTAL_RX(p));
14095 }
14096
14097 if (use_json) {
14098 /* advertisement-interval */
14099 json_object_int_add(json_neigh,
14100 "minBtwnAdvertisementRunsTimerMsecs",
14101 p->v_routeadv * 1000);
14102
14103 /* Update-source. */
14104 if (p->update_if || p->update_source) {
14105 if (p->update_if)
14106 json_object_string_add(json_neigh,
14107 "updateSource",
14108 p->update_if);
14109 else if (p->update_source)
14110 json_object_string_add(
14111 json_neigh, "updateSource",
14112 sockunion2str(p->update_source, buf1,
14113 SU_ADDRSTRLEN));
14114 }
14115 } else {
14116 /* advertisement-interval */
14117 vty_out(vty,
14118 " Minimum time between advertisement runs is %d seconds\n",
14119 p->v_routeadv);
14120
14121 /* Update-source. */
14122 if (p->update_if || p->update_source) {
14123 vty_out(vty, " Update source is ");
14124 if (p->update_if)
14125 vty_out(vty, "%s", p->update_if);
14126 else if (p->update_source)
14127 vty_out(vty, "%s",
14128 sockunion2str(p->update_source, buf1,
14129 SU_ADDRSTRLEN));
14130 vty_out(vty, "\n");
14131 }
14132
14133 vty_out(vty, "\n");
14134 }
14135
14136 /* Address Family Information */
14137 json_object *json_hold = NULL;
14138
14139 if (use_json)
14140 json_hold = json_object_new_object();
14141
14142 FOREACH_AFI_SAFI (afi, safi)
14143 if (p->afc[afi][safi])
14144 bgp_show_peer_afi(vty, p, afi, safi, use_json,
14145 json_hold);
14146
14147 if (use_json) {
14148 json_object_object_add(json_neigh, "addressFamilyInfo",
14149 json_hold);
14150 json_object_int_add(json_neigh, "connectionsEstablished",
14151 p->established);
14152 json_object_int_add(json_neigh, "connectionsDropped",
14153 p->dropped);
14154 } else
14155 vty_out(vty, " Connections established %d; dropped %d\n",
14156 p->established, p->dropped);
14157
14158 if (!p->last_reset) {
14159 if (use_json)
14160 json_object_string_add(json_neigh, "lastReset",
14161 "never");
14162 else
14163 vty_out(vty, " Last reset never\n");
14164 } else {
14165 if (use_json) {
14166 time_t uptime;
14167 struct tm tm;
14168
14169 uptime = bgp_clock();
14170 uptime -= p->resettime;
14171 gmtime_r(&uptime, &tm);
14172
14173 json_object_int_add(json_neigh, "lastResetTimerMsecs",
14174 (tm.tm_sec * 1000)
14175 + (tm.tm_min * 60000)
14176 + (tm.tm_hour * 3600000));
14177 bgp_show_peer_reset(NULL, p, json_neigh, true);
14178 } else {
14179 vty_out(vty, " Last reset %s, ",
14180 peer_uptime(p->resettime, timebuf,
14181 BGP_UPTIME_LEN, 0, NULL));
14182
14183 bgp_show_peer_reset(vty, p, NULL, false);
14184 if (p->last_reset_cause_size) {
14185 msg = p->last_reset_cause;
14186 vty_out(vty,
14187 " Message received that caused BGP to send a NOTIFICATION:\n ");
14188 for (i = 1; i <= p->last_reset_cause_size;
14189 i++) {
14190 vty_out(vty, "%02X", *msg++);
14191
14192 if (i != p->last_reset_cause_size) {
14193 if (i % 16 == 0) {
14194 vty_out(vty, "\n ");
14195 } else if (i % 4 == 0) {
14196 vty_out(vty, " ");
14197 }
14198 }
14199 }
14200 vty_out(vty, "\n");
14201 }
14202 }
14203 }
14204
14205 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
14206 if (use_json)
14207 json_object_boolean_true_add(json_neigh,
14208 "prefixesConfigExceedMax");
14209 else
14210 vty_out(vty,
14211 " Peer had exceeded the max. no. of prefixes configured.\n");
14212
14213 if (p->t_pmax_restart) {
14214 if (use_json) {
14215 json_object_boolean_true_add(
14216 json_neigh, "reducePrefixNumFrom");
14217 json_object_int_add(json_neigh,
14218 "restartInTimerMsec",
14219 thread_timer_remain_second(
14220 p->t_pmax_restart)
14221 * 1000);
14222 } else
14223 vty_out(vty,
14224 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
14225 p->host, thread_timer_remain_second(
14226 p->t_pmax_restart));
14227 } else {
14228 if (use_json)
14229 json_object_boolean_true_add(
14230 json_neigh,
14231 "reducePrefixNumAndClearIpBgp");
14232 else
14233 vty_out(vty,
14234 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
14235 p->host);
14236 }
14237 }
14238
14239 /* EBGP Multihop and GTSM */
14240 if (p->sort != BGP_PEER_IBGP) {
14241 if (use_json) {
14242 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14243 json_object_int_add(json_neigh,
14244 "externalBgpNbrMaxHopsAway",
14245 p->gtsm_hops);
14246 else if (p->ttl > BGP_DEFAULT_TTL)
14247 json_object_int_add(json_neigh,
14248 "externalBgpNbrMaxHopsAway",
14249 p->ttl);
14250 } else {
14251 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14252 vty_out(vty,
14253 " External BGP neighbor may be up to %d hops away.\n",
14254 p->gtsm_hops);
14255 else if (p->ttl > BGP_DEFAULT_TTL)
14256 vty_out(vty,
14257 " External BGP neighbor may be up to %d hops away.\n",
14258 p->ttl);
14259 }
14260 } else {
14261 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED) {
14262 if (use_json)
14263 json_object_int_add(json_neigh,
14264 "internalBgpNbrMaxHopsAway",
14265 p->gtsm_hops);
14266 else
14267 vty_out(vty,
14268 " Internal BGP neighbor may be up to %d hops away.\n",
14269 p->gtsm_hops);
14270 }
14271 }
14272
14273 /* Local address. */
14274 if (p->su_local) {
14275 if (use_json) {
14276 json_object_string_add(json_neigh, "hostLocal",
14277 sockunion2str(p->su_local, buf1,
14278 SU_ADDRSTRLEN));
14279 json_object_int_add(json_neigh, "portLocal",
14280 ntohs(p->su_local->sin.sin_port));
14281 } else
14282 vty_out(vty, "Local host: %s, Local port: %d\n",
14283 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
14284 ntohs(p->su_local->sin.sin_port));
14285 }
14286
14287 /* Remote address. */
14288 if (p->su_remote) {
14289 if (use_json) {
14290 json_object_string_add(json_neigh, "hostForeign",
14291 sockunion2str(p->su_remote, buf1,
14292 SU_ADDRSTRLEN));
14293 json_object_int_add(json_neigh, "portForeign",
14294 ntohs(p->su_remote->sin.sin_port));
14295 } else
14296 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
14297 sockunion2str(p->su_remote, buf1,
14298 SU_ADDRSTRLEN),
14299 ntohs(p->su_remote->sin.sin_port));
14300 }
14301
14302 /* Nexthop display. */
14303 if (p->su_local) {
14304 if (use_json) {
14305 json_object_string_add(json_neigh, "nexthop",
14306 inet_ntop(AF_INET,
14307 &p->nexthop.v4, buf1,
14308 sizeof(buf1)));
14309 json_object_string_add(json_neigh, "nexthopGlobal",
14310 inet_ntop(AF_INET6,
14311 &p->nexthop.v6_global,
14312 buf1, sizeof(buf1)));
14313 json_object_string_add(json_neigh, "nexthopLocal",
14314 inet_ntop(AF_INET6,
14315 &p->nexthop.v6_local,
14316 buf1, sizeof(buf1)));
14317 if (p->shared_network)
14318 json_object_string_add(json_neigh,
14319 "bgpConnection",
14320 "sharedNetwork");
14321 else
14322 json_object_string_add(json_neigh,
14323 "bgpConnection",
14324 "nonSharedNetwork");
14325 } else {
14326 vty_out(vty, "Nexthop: %s\n",
14327 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
14328 sizeof(buf1)));
14329 vty_out(vty, "Nexthop global: %s\n",
14330 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
14331 sizeof(buf1)));
14332 vty_out(vty, "Nexthop local: %s\n",
14333 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
14334 sizeof(buf1)));
14335 vty_out(vty, "BGP connection: %s\n",
14336 p->shared_network ? "shared network"
14337 : "non shared network");
14338 }
14339 }
14340
14341 /* Timer information. */
14342 if (use_json) {
14343 json_object_int_add(json_neigh, "connectRetryTimer",
14344 p->v_connect);
14345 if (p->status == Established && p->rtt)
14346 json_object_int_add(json_neigh, "estimatedRttInMsecs",
14347 p->rtt);
14348 if (p->t_start)
14349 json_object_int_add(
14350 json_neigh, "nextStartTimerDueInMsecs",
14351 thread_timer_remain_second(p->t_start) * 1000);
14352 if (p->t_connect)
14353 json_object_int_add(
14354 json_neigh, "nextConnectTimerDueInMsecs",
14355 thread_timer_remain_second(p->t_connect)
14356 * 1000);
14357 if (p->t_routeadv) {
14358 json_object_int_add(json_neigh, "mraiInterval",
14359 p->v_routeadv);
14360 json_object_int_add(
14361 json_neigh, "mraiTimerExpireInMsecs",
14362 thread_timer_remain_second(p->t_routeadv)
14363 * 1000);
14364 }
14365 if (p->password)
14366 json_object_int_add(json_neigh, "authenticationEnabled",
14367 1);
14368
14369 if (p->t_read)
14370 json_object_string_add(json_neigh, "readThread", "on");
14371 else
14372 json_object_string_add(json_neigh, "readThread", "off");
14373
14374 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
14375 json_object_string_add(json_neigh, "writeThread", "on");
14376 else
14377 json_object_string_add(json_neigh, "writeThread",
14378 "off");
14379 } else {
14380 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
14381 p->v_connect);
14382 if (p->status == Established && p->rtt)
14383 vty_out(vty, "Estimated round trip time: %d ms\n",
14384 p->rtt);
14385 if (p->t_start)
14386 vty_out(vty, "Next start timer due in %ld seconds\n",
14387 thread_timer_remain_second(p->t_start));
14388 if (p->t_connect)
14389 vty_out(vty, "Next connect timer due in %ld seconds\n",
14390 thread_timer_remain_second(p->t_connect));
14391 if (p->t_routeadv)
14392 vty_out(vty,
14393 "MRAI (interval %u) timer expires in %ld seconds\n",
14394 p->v_routeadv,
14395 thread_timer_remain_second(p->t_routeadv));
14396 if (p->password)
14397 vty_out(vty, "Peer Authentication Enabled\n");
14398
14399 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
14400 p->t_read ? "on" : "off",
14401 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
14402 ? "on"
14403 : "off", p->fd);
14404 }
14405
14406 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
14407 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
14408 bgp_capability_vty_out(vty, p, use_json, json_neigh);
14409
14410 if (!use_json)
14411 vty_out(vty, "\n");
14412
14413 /* BFD information. */
14414 bgp_bfd_show_info(vty, p, use_json, json_neigh);
14415
14416 if (use_json) {
14417 if (p->conf_if) /* Configured interface name. */
14418 json_object_object_add(json, p->conf_if, json_neigh);
14419 else /* Configured IP address. */
14420 json_object_object_add(json, p->host, json_neigh);
14421 }
14422 }
14423
14424 static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
14425 enum show_type type,
14426 union sockunion *su,
14427 const char *conf_if, afi_t afi,
14428 bool use_json)
14429 {
14430 struct listnode *node, *nnode;
14431 struct peer *peer;
14432 int find = 0;
14433 safi_t safi = SAFI_UNICAST;
14434 json_object *json = NULL;
14435 json_object *json_neighbor = NULL;
14436
14437 if (use_json) {
14438 json = json_object_new_object();
14439 json_neighbor = json_object_new_object();
14440 }
14441
14442 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14443
14444 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14445 continue;
14446
14447 if ((peer->afc[afi][safi]) == 0)
14448 continue;
14449
14450 if (type == show_all) {
14451 bgp_show_peer_gr_status(vty, peer, use_json,
14452 json_neighbor);
14453
14454 if (use_json) {
14455 json_object_object_add(json, peer->host,
14456 json_neighbor);
14457 json_neighbor = NULL;
14458 }
14459
14460 } else if (type == show_peer) {
14461 if (conf_if) {
14462 if ((peer->conf_if
14463 && !strcmp(peer->conf_if, conf_if))
14464 || (peer->hostname
14465 && !strcmp(peer->hostname, conf_if))) {
14466 find = 1;
14467 bgp_show_peer_gr_status(vty, peer,
14468 use_json,
14469 json_neighbor);
14470 }
14471 } else {
14472 if (sockunion_same(&peer->su, su)) {
14473 find = 1;
14474 bgp_show_peer_gr_status(vty, peer,
14475 use_json,
14476 json_neighbor);
14477 }
14478 }
14479 if (use_json && find)
14480 json_object_object_add(json, peer->host,
14481 json_neighbor);
14482 }
14483
14484 if (find) {
14485 json_neighbor = NULL;
14486 break;
14487 }
14488 }
14489
14490 if (type == show_peer && !find) {
14491 if (use_json)
14492 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14493 else
14494 vty_out(vty, "%% No such neighbor\n");
14495 }
14496 if (use_json) {
14497 vty_out(vty, "%s\n",
14498 json_object_to_json_string_ext(
14499 json, JSON_C_TO_STRING_PRETTY));
14500
14501 if (json_neighbor)
14502 json_object_free(json_neighbor);
14503 json_object_free(json);
14504 } else {
14505 vty_out(vty, "\n");
14506 }
14507
14508 return CMD_SUCCESS;
14509 }
14510
14511 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
14512 enum show_type type, union sockunion *su,
14513 const char *conf_if, bool use_json,
14514 json_object *json)
14515 {
14516 struct listnode *node, *nnode;
14517 struct peer *peer;
14518 int find = 0;
14519 bool nbr_output = false;
14520 afi_t afi = AFI_MAX;
14521 safi_t safi = SAFI_MAX;
14522
14523 if (type == show_ipv4_peer || type == show_ipv4_all) {
14524 afi = AFI_IP;
14525 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
14526 afi = AFI_IP6;
14527 }
14528
14529 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14530 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14531 continue;
14532
14533 switch (type) {
14534 case show_all:
14535 bgp_show_peer(vty, peer, use_json, json);
14536 nbr_output = true;
14537 break;
14538 case show_peer:
14539 if (conf_if) {
14540 if ((peer->conf_if
14541 && !strcmp(peer->conf_if, conf_if))
14542 || (peer->hostname
14543 && !strcmp(peer->hostname, conf_if))) {
14544 find = 1;
14545 bgp_show_peer(vty, peer, use_json,
14546 json);
14547 }
14548 } else {
14549 if (sockunion_same(&peer->su, su)) {
14550 find = 1;
14551 bgp_show_peer(vty, peer, use_json,
14552 json);
14553 }
14554 }
14555 break;
14556 case show_ipv4_peer:
14557 case show_ipv6_peer:
14558 FOREACH_SAFI (safi) {
14559 if (peer->afc[afi][safi]) {
14560 if (conf_if) {
14561 if ((peer->conf_if
14562 && !strcmp(peer->conf_if, conf_if))
14563 || (peer->hostname
14564 && !strcmp(peer->hostname, conf_if))) {
14565 find = 1;
14566 bgp_show_peer(vty, peer, use_json,
14567 json);
14568 break;
14569 }
14570 } else {
14571 if (sockunion_same(&peer->su, su)) {
14572 find = 1;
14573 bgp_show_peer(vty, peer, use_json,
14574 json);
14575 break;
14576 }
14577 }
14578 }
14579 }
14580 break;
14581 case show_ipv4_all:
14582 case show_ipv6_all:
14583 FOREACH_SAFI (safi) {
14584 if (peer->afc[afi][safi]) {
14585 bgp_show_peer(vty, peer, use_json, json);
14586 nbr_output = true;
14587 break;
14588 }
14589 }
14590 break;
14591 }
14592 }
14593
14594 if ((type == show_peer || type == show_ipv4_peer ||
14595 type == show_ipv6_peer) && !find) {
14596 if (use_json)
14597 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14598 else
14599 vty_out(vty, "%% No such neighbor in this view/vrf\n");
14600 }
14601
14602 if (type != show_peer && type != show_ipv4_peer &&
14603 type != show_ipv6_peer && !nbr_output && !use_json)
14604 vty_out(vty, "%% No BGP neighbors found\n");
14605
14606 if (use_json) {
14607 vty_out(vty, "%s\n", json_object_to_json_string_ext(
14608 json, JSON_C_TO_STRING_PRETTY));
14609 } else {
14610 vty_out(vty, "\n");
14611 }
14612
14613 return CMD_SUCCESS;
14614 }
14615
14616 static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
14617 enum show_type type,
14618 const char *ip_str,
14619 afi_t afi, bool use_json)
14620 {
14621
14622 int ret;
14623 struct bgp *bgp;
14624 union sockunion su;
14625
14626 bgp = bgp_get_default();
14627
14628 if (!bgp)
14629 return;
14630
14631 if (!use_json)
14632 bgp_show_global_graceful_restart_mode_vty(vty, bgp, use_json,
14633 NULL);
14634
14635 if (ip_str) {
14636 ret = str2sockunion(ip_str, &su);
14637 if (ret < 0)
14638 bgp_show_neighbor_graceful_restart(
14639 vty, bgp, type, NULL, ip_str, afi, use_json);
14640 else
14641 bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
14642 NULL, afi, use_json);
14643 } else
14644 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
14645 afi, use_json);
14646 }
14647
14648 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
14649 enum show_type type,
14650 const char *ip_str,
14651 bool use_json)
14652 {
14653 struct listnode *node, *nnode;
14654 struct bgp *bgp;
14655 union sockunion su;
14656 json_object *json = NULL;
14657 int ret, is_first = 1;
14658 bool nbr_output = false;
14659
14660 if (use_json)
14661 vty_out(vty, "{\n");
14662
14663 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
14664 nbr_output = true;
14665 if (use_json) {
14666 if (!(json = json_object_new_object())) {
14667 flog_err(
14668 EC_BGP_JSON_MEM_ERROR,
14669 "Unable to allocate memory for JSON object");
14670 vty_out(vty,
14671 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
14672 return;
14673 }
14674
14675 json_object_int_add(json, "vrfId",
14676 (bgp->vrf_id == VRF_UNKNOWN)
14677 ? -1
14678 : (int64_t)bgp->vrf_id);
14679 json_object_string_add(
14680 json, "vrfName",
14681 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14682 ? VRF_DEFAULT_NAME
14683 : bgp->name);
14684
14685 if (!is_first)
14686 vty_out(vty, ",\n");
14687 else
14688 is_first = 0;
14689
14690 vty_out(vty, "\"%s\":",
14691 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14692 ? VRF_DEFAULT_NAME
14693 : bgp->name);
14694 } else {
14695 vty_out(vty, "\nInstance %s:\n",
14696 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14697 ? VRF_DEFAULT_NAME
14698 : bgp->name);
14699 }
14700
14701 if (type == show_peer || type == show_ipv4_peer ||
14702 type == show_ipv6_peer) {
14703 ret = str2sockunion(ip_str, &su);
14704 if (ret < 0)
14705 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14706 use_json, json);
14707 else
14708 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14709 use_json, json);
14710 } else {
14711 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
14712 use_json, json);
14713 }
14714 json_object_free(json);
14715 json = NULL;
14716 }
14717
14718 if (use_json)
14719 vty_out(vty, "}\n");
14720 else if (!nbr_output)
14721 vty_out(vty, "%% BGP instance not found\n");
14722 }
14723
14724 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
14725 enum show_type type, const char *ip_str,
14726 bool use_json)
14727 {
14728 int ret;
14729 struct bgp *bgp;
14730 union sockunion su;
14731 json_object *json = NULL;
14732
14733 if (name) {
14734 if (strmatch(name, "all")) {
14735 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
14736 use_json);
14737 return CMD_SUCCESS;
14738 } else {
14739 bgp = bgp_lookup_by_name(name);
14740 if (!bgp) {
14741 if (use_json) {
14742 json = json_object_new_object();
14743 vty_out(vty, "%s\n",
14744 json_object_to_json_string_ext(
14745 json,
14746 JSON_C_TO_STRING_PRETTY));
14747 json_object_free(json);
14748 } else
14749 vty_out(vty,
14750 "%% BGP instance not found\n");
14751
14752 return CMD_WARNING;
14753 }
14754 }
14755 } else {
14756 bgp = bgp_get_default();
14757 }
14758
14759 if (bgp) {
14760 json = json_object_new_object();
14761 if (ip_str) {
14762 ret = str2sockunion(ip_str, &su);
14763 if (ret < 0)
14764 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14765 use_json, json);
14766 else
14767 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14768 use_json, json);
14769 } else {
14770 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
14771 json);
14772 }
14773 json_object_free(json);
14774 } else {
14775 if (use_json)
14776 vty_out(vty, "{}\n");
14777 else
14778 vty_out(vty, "%% BGP instance not found\n");
14779 }
14780
14781 return CMD_SUCCESS;
14782 }
14783
14784
14785
14786 /* "show [ip] bgp neighbors graceful-restart" commands. */
14787 DEFUN (show_ip_bgp_neighbors_gracrful_restart,
14788 show_ip_bgp_neighbors_graceful_restart_cmd,
14789 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
14790 SHOW_STR
14791 BGP_STR
14792 IP_STR
14793 IPV6_STR
14794 NEIGHBOR_STR
14795 "Neighbor to display information about\n"
14796 "Neighbor to display information about\n"
14797 "Neighbor on BGP configured interface\n"
14798 GR_SHOW
14799 JSON_STR)
14800 {
14801 char *sh_arg = NULL;
14802 enum show_type sh_type;
14803 int idx = 0;
14804 afi_t afi = AFI_MAX;
14805 bool uj = use_json(argc, argv);
14806
14807 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
14808 afi = AFI_MAX;
14809
14810 idx++;
14811
14812 if (argv_find(argv, argc, "A.B.C.D", &idx)
14813 || argv_find(argv, argc, "X:X::X:X", &idx)
14814 || argv_find(argv, argc, "WORD", &idx)) {
14815 sh_type = show_peer;
14816 sh_arg = argv[idx]->arg;
14817 } else
14818 sh_type = show_all;
14819
14820 if (!argv_find(argv, argc, "graceful-restart", &idx))
14821 return CMD_SUCCESS;
14822
14823
14824 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
14825 afi, uj);
14826 }
14827
14828 /* "show [ip] bgp neighbors" commands. */
14829 DEFUN (show_ip_bgp_neighbors,
14830 show_ip_bgp_neighbors_cmd,
14831 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
14832 SHOW_STR
14833 IP_STR
14834 BGP_STR
14835 BGP_INSTANCE_HELP_STR
14836 "Address Family\n"
14837 "Address Family\n"
14838 "Detailed information on TCP and BGP neighbor connections\n"
14839 "Neighbor to display information about\n"
14840 "Neighbor to display information about\n"
14841 "Neighbor on BGP configured interface\n"
14842 JSON_STR)
14843 {
14844 char *vrf = NULL;
14845 char *sh_arg = NULL;
14846 enum show_type sh_type;
14847 afi_t afi = AFI_MAX;
14848
14849 bool uj = use_json(argc, argv);
14850
14851 int idx = 0;
14852
14853 /* [<vrf> VIEWVRFNAME] */
14854 if (argv_find(argv, argc, "vrf", &idx)) {
14855 vrf = argv[idx + 1]->arg;
14856 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
14857 vrf = NULL;
14858 } else if (argv_find(argv, argc, "view", &idx))
14859 /* [<view> VIEWVRFNAME] */
14860 vrf = argv[idx + 1]->arg;
14861
14862 idx++;
14863
14864 if (argv_find(argv, argc, "ipv4", &idx)) {
14865 sh_type = show_ipv4_all;
14866 afi = AFI_IP;
14867 } else if (argv_find(argv, argc, "ipv6", &idx)) {
14868 sh_type = show_ipv6_all;
14869 afi = AFI_IP6;
14870 } else {
14871 sh_type = show_all;
14872 }
14873
14874 if (argv_find(argv, argc, "A.B.C.D", &idx)
14875 || argv_find(argv, argc, "X:X::X:X", &idx)
14876 || argv_find(argv, argc, "WORD", &idx)) {
14877 sh_type = show_peer;
14878 sh_arg = argv[idx]->arg;
14879 }
14880
14881 if (sh_type == show_peer && afi == AFI_IP) {
14882 sh_type = show_ipv4_peer;
14883 } else if (sh_type == show_peer && afi == AFI_IP6) {
14884 sh_type = show_ipv6_peer;
14885 }
14886
14887 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
14888 }
14889
14890 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
14891 paths' and `show ip mbgp paths'. Those functions results are the
14892 same.*/
14893 DEFUN (show_ip_bgp_paths,
14894 show_ip_bgp_paths_cmd,
14895 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
14896 SHOW_STR
14897 IP_STR
14898 BGP_STR
14899 BGP_SAFI_HELP_STR
14900 "Path information\n")
14901 {
14902 vty_out(vty, "Address Refcnt Path\n");
14903 aspath_print_all_vty(vty);
14904 return CMD_SUCCESS;
14905 }
14906
14907 #include "hash.h"
14908
14909 static void community_show_all_iterator(struct hash_bucket *bucket,
14910 struct vty *vty)
14911 {
14912 struct community *com;
14913
14914 com = (struct community *)bucket->data;
14915 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
14916 community_str(com, false));
14917 }
14918
14919 /* Show BGP's community internal data. */
14920 DEFUN (show_ip_bgp_community_info,
14921 show_ip_bgp_community_info_cmd,
14922 "show [ip] bgp community-info",
14923 SHOW_STR
14924 IP_STR
14925 BGP_STR
14926 "List all bgp community information\n")
14927 {
14928 vty_out(vty, "Address Refcnt Community\n");
14929
14930 hash_iterate(community_hash(),
14931 (void (*)(struct hash_bucket *,
14932 void *))community_show_all_iterator,
14933 vty);
14934
14935 return CMD_SUCCESS;
14936 }
14937
14938 static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
14939 struct vty *vty)
14940 {
14941 struct lcommunity *lcom;
14942
14943 lcom = (struct lcommunity *)bucket->data;
14944 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
14945 lcommunity_str(lcom, false));
14946 }
14947
14948 /* Show BGP's community internal data. */
14949 DEFUN (show_ip_bgp_lcommunity_info,
14950 show_ip_bgp_lcommunity_info_cmd,
14951 "show ip bgp large-community-info",
14952 SHOW_STR
14953 IP_STR
14954 BGP_STR
14955 "List all bgp large-community information\n")
14956 {
14957 vty_out(vty, "Address Refcnt Large-community\n");
14958
14959 hash_iterate(lcommunity_hash(),
14960 (void (*)(struct hash_bucket *,
14961 void *))lcommunity_show_all_iterator,
14962 vty);
14963
14964 return CMD_SUCCESS;
14965 }
14966 /* Graceful Restart */
14967
14968 static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
14969 struct bgp *bgp,
14970 bool use_json,
14971 json_object *json)
14972 {
14973
14974
14975 vty_out(vty, "\n%s", SHOW_GR_HEADER);
14976
14977 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
14978
14979 switch (bgp_global_gr_mode) {
14980
14981 case GLOBAL_HELPER:
14982 vty_out(vty, "Global BGP GR Mode : Helper\n");
14983 break;
14984
14985 case GLOBAL_GR:
14986 vty_out(vty, "Global BGP GR Mode : Restart\n");
14987 break;
14988
14989 case GLOBAL_DISABLE:
14990 vty_out(vty, "Global BGP GR Mode : Disable\n");
14991 break;
14992
14993 case GLOBAL_INVALID:
14994 vty_out(vty,
14995 "Global BGP GR Mode Invalid\n");
14996 break;
14997 }
14998 vty_out(vty, "\n");
14999 }
15000
15001 static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
15002 enum show_type type,
15003 const char *ip_str,
15004 afi_t afi, bool use_json)
15005 {
15006 if ((afi == AFI_MAX) && (ip_str == NULL)) {
15007 afi = AFI_IP;
15008
15009 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
15010
15011 bgp_show_neighbor_graceful_restart_vty(
15012 vty, type, ip_str, afi, use_json);
15013 afi++;
15014 }
15015 } else if (afi != AFI_MAX) {
15016 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
15017 use_json);
15018 } else {
15019 return CMD_ERR_INCOMPLETE;
15020 }
15021
15022 return CMD_SUCCESS;
15023 }
15024 /* Graceful Restart */
15025
15026 DEFUN (show_ip_bgp_attr_info,
15027 show_ip_bgp_attr_info_cmd,
15028 "show [ip] bgp attribute-info",
15029 SHOW_STR
15030 IP_STR
15031 BGP_STR
15032 "List all bgp attribute information\n")
15033 {
15034 attr_show_all(vty);
15035 return CMD_SUCCESS;
15036 }
15037
15038 static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
15039 afi_t afi, safi_t safi,
15040 bool use_json, json_object *json)
15041 {
15042 struct bgp *bgp;
15043 struct listnode *node;
15044 char *vname;
15045 char buf1[INET6_ADDRSTRLEN];
15046 char *ecom_str;
15047 vpn_policy_direction_t dir;
15048
15049 if (json) {
15050 json_object *json_import_vrfs = NULL;
15051 json_object *json_export_vrfs = NULL;
15052
15053 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15054
15055 if (!bgp) {
15056 vty_out(vty, "%s\n",
15057 json_object_to_json_string_ext(
15058 json,
15059 JSON_C_TO_STRING_PRETTY));
15060 json_object_free(json);
15061
15062 return CMD_WARNING;
15063 }
15064
15065 /* Provide context for the block */
15066 json_object_string_add(json, "vrf", name ? name : "default");
15067 json_object_string_add(json, "afiSafi",
15068 get_afi_safi_str(afi, safi, true));
15069
15070 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15071 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
15072 json_object_string_add(json, "importFromVrfs", "none");
15073 json_object_string_add(json, "importRts", "none");
15074 } else {
15075 json_import_vrfs = json_object_new_array();
15076
15077 for (ALL_LIST_ELEMENTS_RO(
15078 bgp->vpn_policy[afi].import_vrf,
15079 node, vname))
15080 json_object_array_add(json_import_vrfs,
15081 json_object_new_string(vname));
15082
15083 json_object_object_add(json, "importFromVrfs",
15084 json_import_vrfs);
15085 dir = BGP_VPN_POLICY_DIR_FROMVPN;
15086 if (bgp->vpn_policy[afi].rtlist[dir]) {
15087 ecom_str = ecommunity_ecom2str(
15088 bgp->vpn_policy[afi].rtlist[dir],
15089 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15090 json_object_string_add(json, "importRts",
15091 ecom_str);
15092 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15093 } else
15094 json_object_string_add(json, "importRts",
15095 "none");
15096 }
15097
15098 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15099 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
15100 json_object_string_add(json, "exportToVrfs", "none");
15101 json_object_string_add(json, "routeDistinguisher",
15102 "none");
15103 json_object_string_add(json, "exportRts", "none");
15104 } else {
15105 json_export_vrfs = json_object_new_array();
15106
15107 for (ALL_LIST_ELEMENTS_RO(
15108 bgp->vpn_policy[afi].export_vrf,
15109 node, vname))
15110 json_object_array_add(json_export_vrfs,
15111 json_object_new_string(vname));
15112 json_object_object_add(json, "exportToVrfs",
15113 json_export_vrfs);
15114 json_object_string_add(json, "routeDistinguisher",
15115 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
15116 buf1, RD_ADDRSTRLEN));
15117
15118 dir = BGP_VPN_POLICY_DIR_TOVPN;
15119 if (bgp->vpn_policy[afi].rtlist[dir]) {
15120 ecom_str = ecommunity_ecom2str(
15121 bgp->vpn_policy[afi].rtlist[dir],
15122 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15123 json_object_string_add(json, "exportRts",
15124 ecom_str);
15125 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15126 } else
15127 json_object_string_add(json, "exportRts",
15128 "none");
15129 }
15130
15131 if (use_json) {
15132 vty_out(vty, "%s\n",
15133 json_object_to_json_string_ext(json,
15134 JSON_C_TO_STRING_PRETTY));
15135 json_object_free(json);
15136 }
15137 } else {
15138 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15139
15140 if (!bgp) {
15141 vty_out(vty, "%% No such BGP instance exist\n");
15142 return CMD_WARNING;
15143 }
15144
15145 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15146 BGP_CONFIG_VRF_TO_VRF_IMPORT))
15147 vty_out(vty,
15148 "This VRF is not importing %s routes from any other VRF\n",
15149 get_afi_safi_str(afi, safi, false));
15150 else {
15151 vty_out(vty,
15152 "This VRF is importing %s routes from the following VRFs:\n",
15153 get_afi_safi_str(afi, safi, false));
15154
15155 for (ALL_LIST_ELEMENTS_RO(
15156 bgp->vpn_policy[afi].import_vrf,
15157 node, vname))
15158 vty_out(vty, " %s\n", vname);
15159
15160 dir = BGP_VPN_POLICY_DIR_FROMVPN;
15161 ecom_str = NULL;
15162 if (bgp->vpn_policy[afi].rtlist[dir]) {
15163 ecom_str = ecommunity_ecom2str(
15164 bgp->vpn_policy[afi].rtlist[dir],
15165 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15166 vty_out(vty, "Import RT(s): %s\n", ecom_str);
15167
15168 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15169 } else
15170 vty_out(vty, "Import RT(s):\n");
15171 }
15172
15173 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15174 BGP_CONFIG_VRF_TO_VRF_EXPORT))
15175 vty_out(vty,
15176 "This VRF is not exporting %s routes to any other VRF\n",
15177 get_afi_safi_str(afi, safi, false));
15178 else {
15179 vty_out(vty,
15180 "This VRF is exporting %s routes to the following VRFs:\n",
15181 get_afi_safi_str(afi, safi, false));
15182
15183 for (ALL_LIST_ELEMENTS_RO(
15184 bgp->vpn_policy[afi].export_vrf,
15185 node, vname))
15186 vty_out(vty, " %s\n", vname);
15187
15188 vty_out(vty, "RD: %s\n",
15189 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
15190 buf1, RD_ADDRSTRLEN));
15191
15192 dir = BGP_VPN_POLICY_DIR_TOVPN;
15193 if (bgp->vpn_policy[afi].rtlist[dir]) {
15194 ecom_str = ecommunity_ecom2str(
15195 bgp->vpn_policy[afi].rtlist[dir],
15196 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15197 vty_out(vty, "Export RT: %s\n", ecom_str);
15198 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15199 } else
15200 vty_out(vty, "Import RT(s):\n");
15201 }
15202 }
15203
15204 return CMD_SUCCESS;
15205 }
15206
15207 static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
15208 safi_t safi, bool use_json)
15209 {
15210 struct listnode *node, *nnode;
15211 struct bgp *bgp;
15212 char *vrf_name = NULL;
15213 json_object *json = NULL;
15214 json_object *json_vrf = NULL;
15215 json_object *json_vrfs = NULL;
15216
15217 if (use_json) {
15218 json = json_object_new_object();
15219 json_vrfs = json_object_new_object();
15220 }
15221
15222 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15223
15224 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
15225 vrf_name = bgp->name;
15226
15227 if (use_json) {
15228 json_vrf = json_object_new_object();
15229 } else {
15230 vty_out(vty, "\nInstance %s:\n",
15231 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15232 ? VRF_DEFAULT_NAME : bgp->name);
15233 }
15234 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
15235 if (use_json) {
15236 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15237 json_object_object_add(json_vrfs,
15238 VRF_DEFAULT_NAME, json_vrf);
15239 else
15240 json_object_object_add(json_vrfs, vrf_name,
15241 json_vrf);
15242 }
15243 }
15244
15245 if (use_json) {
15246 json_object_object_add(json, "vrfs", json_vrfs);
15247 vty_out(vty, "%s\n", json_object_to_json_string_ext(json,
15248 JSON_C_TO_STRING_PRETTY));
15249 json_object_free(json);
15250 }
15251
15252 return CMD_SUCCESS;
15253 }
15254
15255 /* "show [ip] bgp route-leak" command. */
15256 DEFUN (show_ip_bgp_route_leak,
15257 show_ip_bgp_route_leak_cmd,
15258 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
15259 SHOW_STR
15260 IP_STR
15261 BGP_STR
15262 BGP_INSTANCE_HELP_STR
15263 BGP_AFI_HELP_STR
15264 BGP_SAFI_HELP_STR
15265 "Route leaking information\n"
15266 JSON_STR)
15267 {
15268 char *vrf = NULL;
15269 afi_t afi = AFI_MAX;
15270 safi_t safi = SAFI_MAX;
15271
15272 bool uj = use_json(argc, argv);
15273 int idx = 0;
15274 json_object *json = NULL;
15275
15276 /* show [ip] bgp */
15277 if (argv_find(argv, argc, "ip", &idx)) {
15278 afi = AFI_IP;
15279 safi = SAFI_UNICAST;
15280 }
15281 /* [vrf VIEWVRFNAME] */
15282 if (argv_find(argv, argc, "view", &idx)) {
15283 vty_out(vty,
15284 "%% This command is not applicable to BGP views\n");
15285 return CMD_WARNING;
15286 }
15287
15288 if (argv_find(argv, argc, "vrf", &idx)) {
15289 vrf = argv[idx + 1]->arg;
15290 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15291 vrf = NULL;
15292 }
15293 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15294 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
15295 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15296 }
15297
15298 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
15299 vty_out(vty,
15300 "%% This command is applicable only for unicast ipv4|ipv6\n");
15301 return CMD_WARNING;
15302 }
15303
15304 if (vrf && strmatch(vrf, "all"))
15305 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
15306
15307 if (uj)
15308 json = json_object_new_object();
15309
15310 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
15311 }
15312
15313 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
15314 safi_t safi)
15315 {
15316 struct listnode *node, *nnode;
15317 struct bgp *bgp;
15318
15319 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15320 vty_out(vty, "\nInstance %s:\n",
15321 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15322 ? VRF_DEFAULT_NAME
15323 : bgp->name);
15324 update_group_show(bgp, afi, safi, vty, 0);
15325 }
15326 }
15327
15328 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
15329 int safi, uint64_t subgrp_id)
15330 {
15331 struct bgp *bgp;
15332
15333 if (name) {
15334 if (strmatch(name, "all")) {
15335 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
15336 return CMD_SUCCESS;
15337 } else {
15338 bgp = bgp_lookup_by_name(name);
15339 }
15340 } else {
15341 bgp = bgp_get_default();
15342 }
15343
15344 if (bgp)
15345 update_group_show(bgp, afi, safi, vty, subgrp_id);
15346 return CMD_SUCCESS;
15347 }
15348
15349 DEFUN (show_ip_bgp_updgrps,
15350 show_ip_bgp_updgrps_cmd,
15351 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
15352 SHOW_STR
15353 IP_STR
15354 BGP_STR
15355 BGP_INSTANCE_HELP_STR
15356 BGP_AFI_HELP_STR
15357 BGP_SAFI_WITH_LABEL_HELP_STR
15358 "Detailed info about dynamic update groups\n"
15359 "Specific subgroup to display detailed info for\n")
15360 {
15361 char *vrf = NULL;
15362 afi_t afi = AFI_IP6;
15363 safi_t safi = SAFI_UNICAST;
15364 uint64_t subgrp_id = 0;
15365
15366 int idx = 0;
15367
15368 /* show [ip] bgp */
15369 if (argv_find(argv, argc, "ip", &idx))
15370 afi = AFI_IP;
15371 /* [<vrf> VIEWVRFNAME] */
15372 if (argv_find(argv, argc, "vrf", &idx)) {
15373 vrf = argv[idx + 1]->arg;
15374 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15375 vrf = NULL;
15376 } else if (argv_find(argv, argc, "view", &idx))
15377 /* [<view> VIEWVRFNAME] */
15378 vrf = argv[idx + 1]->arg;
15379 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15380 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
15381 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15382 }
15383
15384 /* get subgroup id, if provided */
15385 idx = argc - 1;
15386 if (argv[idx]->type == VARIABLE_TKN)
15387 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
15388
15389 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
15390 }
15391
15392 DEFUN (show_bgp_instance_all_ipv6_updgrps,
15393 show_bgp_instance_all_ipv6_updgrps_cmd,
15394 "show [ip] bgp <view|vrf> all update-groups",
15395 SHOW_STR
15396 IP_STR
15397 BGP_STR
15398 BGP_INSTANCE_ALL_HELP_STR
15399 "Detailed info about dynamic update groups\n")
15400 {
15401 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
15402 return CMD_SUCCESS;
15403 }
15404
15405 DEFUN (show_bgp_l2vpn_evpn_updgrps,
15406 show_bgp_l2vpn_evpn_updgrps_cmd,
15407 "show [ip] bgp l2vpn evpn update-groups",
15408 SHOW_STR
15409 IP_STR
15410 BGP_STR
15411 "l2vpn address family\n"
15412 "evpn sub-address family\n"
15413 "Detailed info about dynamic update groups\n")
15414 {
15415 char *vrf = NULL;
15416 uint64_t subgrp_id = 0;
15417
15418 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
15419 return CMD_SUCCESS;
15420 }
15421
15422 DEFUN (show_bgp_updgrps_stats,
15423 show_bgp_updgrps_stats_cmd,
15424 "show [ip] bgp update-groups statistics",
15425 SHOW_STR
15426 IP_STR
15427 BGP_STR
15428 "Detailed info about dynamic update groups\n"
15429 "Statistics\n")
15430 {
15431 struct bgp *bgp;
15432
15433 bgp = bgp_get_default();
15434 if (bgp)
15435 update_group_show_stats(bgp, vty);
15436
15437 return CMD_SUCCESS;
15438 }
15439
15440 DEFUN (show_bgp_instance_updgrps_stats,
15441 show_bgp_instance_updgrps_stats_cmd,
15442 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
15443 SHOW_STR
15444 IP_STR
15445 BGP_STR
15446 BGP_INSTANCE_HELP_STR
15447 "Detailed info about dynamic update groups\n"
15448 "Statistics\n")
15449 {
15450 int idx_word = 3;
15451 struct bgp *bgp;
15452
15453 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
15454 if (bgp)
15455 update_group_show_stats(bgp, vty);
15456
15457 return CMD_SUCCESS;
15458 }
15459
15460 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
15461 afi_t afi, safi_t safi,
15462 const char *what, uint64_t subgrp_id)
15463 {
15464 struct bgp *bgp;
15465
15466 if (name)
15467 bgp = bgp_lookup_by_name(name);
15468 else
15469 bgp = bgp_get_default();
15470
15471 if (bgp) {
15472 if (!strcmp(what, "advertise-queue"))
15473 update_group_show_adj_queue(bgp, afi, safi, vty,
15474 subgrp_id);
15475 else if (!strcmp(what, "advertised-routes"))
15476 update_group_show_advertised(bgp, afi, safi, vty,
15477 subgrp_id);
15478 else if (!strcmp(what, "packet-queue"))
15479 update_group_show_packet_queue(bgp, afi, safi, vty,
15480 subgrp_id);
15481 }
15482 }
15483
15484 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
15485 show_ip_bgp_instance_updgrps_adj_s_cmd,
15486 "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",
15487 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
15488 BGP_SAFI_HELP_STR
15489 "Detailed info about dynamic update groups\n"
15490 "Specific subgroup to display info for\n"
15491 "Advertisement queue\n"
15492 "Announced routes\n"
15493 "Packet queue\n")
15494 {
15495 uint64_t subgrp_id = 0;
15496 afi_t afiz;
15497 safi_t safiz;
15498 if (sgid)
15499 subgrp_id = strtoull(sgid, NULL, 10);
15500
15501 if (!ip && !afi)
15502 afiz = AFI_IP6;
15503 if (!ip && afi)
15504 afiz = bgp_vty_afi_from_str(afi);
15505 if (ip && !afi)
15506 afiz = AFI_IP;
15507 if (ip && afi) {
15508 afiz = bgp_vty_afi_from_str(afi);
15509 if (afiz != AFI_IP)
15510 vty_out(vty,
15511 "%% Cannot specify both 'ip' and 'ipv6'\n");
15512 return CMD_WARNING;
15513 }
15514
15515 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
15516
15517 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
15518 return CMD_SUCCESS;
15519 }
15520
15521 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group,
15522 json_object *json)
15523 {
15524 struct listnode *node, *nnode;
15525 struct prefix *range;
15526 struct peer *conf;
15527 struct peer *peer;
15528 afi_t afi;
15529 safi_t safi;
15530 const char *peer_status;
15531 int lr_count;
15532 int dynamic;
15533 bool af_cfgd;
15534 json_object *json_peer_group = NULL;
15535 json_object *json_peer_group_afc = NULL;
15536 json_object *json_peer_group_members = NULL;
15537 json_object *json_peer_group_dynamic = NULL;
15538 json_object *json_peer_group_dynamic_af = NULL;
15539 json_object *json_peer_group_ranges = NULL;
15540
15541 conf = group->conf;
15542
15543 if (json) {
15544 json_peer_group = json_object_new_object();
15545 json_peer_group_afc = json_object_new_array();
15546 }
15547
15548 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
15549 if (json)
15550 json_object_int_add(json_peer_group, "remoteAs",
15551 conf->as);
15552 else
15553 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15554 group->name, conf->as);
15555 } else if (conf->as_type == AS_INTERNAL) {
15556 if (json)
15557 json_object_int_add(json_peer_group, "remoteAs",
15558 group->bgp->as);
15559 else
15560 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15561 group->name, group->bgp->as);
15562 } else {
15563 if (!json)
15564 vty_out(vty, "\nBGP peer-group %s\n", group->name);
15565 }
15566
15567 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL)) {
15568 if (json)
15569 json_object_string_add(json_peer_group, "type",
15570 "internal");
15571 else
15572 vty_out(vty, " Peer-group type is internal\n");
15573 } else {
15574 if (json)
15575 json_object_string_add(json_peer_group, "type",
15576 "external");
15577 else
15578 vty_out(vty, " Peer-group type is external\n");
15579 }
15580
15581 /* Display AFs configured. */
15582 if (!json)
15583 vty_out(vty, " Configured address-families:");
15584
15585 FOREACH_AFI_SAFI (afi, safi) {
15586 if (conf->afc[afi][safi]) {
15587 af_cfgd = true;
15588 if (json)
15589 json_object_array_add(
15590 json_peer_group_afc,
15591 json_object_new_string(get_afi_safi_str(
15592 afi, safi, false)));
15593 else
15594 vty_out(vty, " %s;",
15595 get_afi_safi_str(afi, safi, false));
15596 }
15597 }
15598
15599 if (json) {
15600 json_object_object_add(json_peer_group,
15601 "addressFamiliesConfigured",
15602 json_peer_group_afc);
15603 } else {
15604 if (!af_cfgd)
15605 vty_out(vty, " none\n");
15606 else
15607 vty_out(vty, "\n");
15608 }
15609
15610 /* Display listen ranges (for dynamic neighbors), if any */
15611 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
15612 lr_count = listcount(group->listen_range[afi]);
15613 if (lr_count) {
15614 if (json) {
15615 if (!json_peer_group_dynamic)
15616 json_peer_group_dynamic =
15617 json_object_new_object();
15618
15619 json_peer_group_dynamic_af =
15620 json_object_new_object();
15621 json_peer_group_ranges =
15622 json_object_new_array();
15623 json_object_int_add(json_peer_group_dynamic_af,
15624 "count", lr_count);
15625 } else {
15626 vty_out(vty, " %d %s listen range(s)\n",
15627 lr_count, afi2str(afi));
15628 }
15629
15630 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
15631 nnode, range)) {
15632 if (json) {
15633 char buf[BUFSIZ];
15634
15635 snprintfrr(buf, sizeof(buf), "%pFX",
15636 range);
15637
15638 json_object_array_add(
15639 json_peer_group_ranges,
15640 json_object_new_string(buf));
15641 } else {
15642 vty_out(vty, " %pFX\n", range);
15643 }
15644 }
15645
15646 if (json) {
15647 json_object_object_add(
15648 json_peer_group_dynamic_af, "ranges",
15649 json_peer_group_ranges);
15650
15651 json_object_object_add(
15652 json_peer_group_dynamic, afi2str(afi),
15653 json_peer_group_dynamic_af);
15654 }
15655 }
15656 }
15657
15658 if (json_peer_group_dynamic)
15659 json_object_object_add(json_peer_group, "dynamicRanges",
15660 json_peer_group_dynamic);
15661
15662 /* Display group members and their status */
15663 if (listcount(group->peer)) {
15664 if (json)
15665 json_peer_group_members = json_object_new_object();
15666 else
15667 vty_out(vty, " Peer-group members:\n");
15668 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
15669 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
15670 || CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHUTDOWN))
15671 peer_status = "Idle (Admin)";
15672 else if (CHECK_FLAG(peer->sflags,
15673 PEER_STATUS_PREFIX_OVERFLOW))
15674 peer_status = "Idle (PfxCt)";
15675 else
15676 peer_status = lookup_msg(bgp_status_msg,
15677 peer->status, NULL);
15678
15679 dynamic = peer_dynamic_neighbor(peer);
15680
15681 if (json) {
15682 json_object *json_peer_group_member =
15683 json_object_new_object();
15684
15685 json_object_string_add(json_peer_group_member,
15686 "status", peer_status);
15687
15688 if (dynamic)
15689 json_object_boolean_true_add(
15690 json_peer_group_member,
15691 "dynamic");
15692
15693 json_object_object_add(json_peer_group_members,
15694 peer->host,
15695 json_peer_group_member);
15696 } else {
15697 vty_out(vty, " %s %s %s \n", peer->host,
15698 dynamic ? "(dynamic)" : "",
15699 peer_status);
15700 }
15701 }
15702 if (json)
15703 json_object_object_add(json_peer_group, "members",
15704 json_peer_group_members);
15705 }
15706
15707 if (json)
15708 json_object_object_add(json, group->name, json_peer_group);
15709
15710 return CMD_SUCCESS;
15711 }
15712
15713 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
15714 const char *group_name, bool uj)
15715 {
15716 struct bgp *bgp;
15717 struct listnode *node, *nnode;
15718 struct peer_group *group;
15719 bool found = false;
15720 json_object *json = NULL;
15721
15722 if (uj)
15723 json = json_object_new_object();
15724
15725 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15726
15727 if (!bgp) {
15728 if (uj) {
15729 vty_out(vty, "%s\n",
15730 json_object_to_json_string_ext(
15731 json, JSON_C_TO_STRING_PRETTY));
15732 json_object_free(json);
15733 } else {
15734 vty_out(vty, "%% BGP instance not found\n");
15735 }
15736
15737 return CMD_WARNING;
15738 }
15739
15740 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
15741 if (group_name) {
15742 if (strmatch(group->name, group_name)) {
15743 bgp_show_one_peer_group(vty, group, json);
15744 found = true;
15745 break;
15746 }
15747 } else {
15748 bgp_show_one_peer_group(vty, group, json);
15749 }
15750 }
15751
15752 if (group_name && !found && !uj)
15753 vty_out(vty, "%% No such peer-group\n");
15754
15755 if (uj) {
15756 vty_out(vty, "%s\n",
15757 json_object_to_json_string_ext(
15758 json, JSON_C_TO_STRING_PRETTY));
15759 json_object_free(json);
15760 }
15761
15762 return CMD_SUCCESS;
15763 }
15764
15765 DEFUN(show_ip_bgp_peer_groups, show_ip_bgp_peer_groups_cmd,
15766 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME] [json]",
15767 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR
15768 "Detailed information on BGP peer groups\n"
15769 "Peer group name\n" JSON_STR)
15770 {
15771 char *vrf, *pg;
15772 int idx = 0;
15773 bool uj = use_json(argc, argv);
15774
15775 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
15776 : NULL;
15777 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
15778
15779 return bgp_show_peer_group_vty(vty, vrf, pg, uj);
15780 }
15781
15782
15783 /* Redistribute VTY commands. */
15784
15785 DEFUN_YANG (bgp_redistribute_ipv4,
15786 bgp_redistribute_ipv4_cmd,
15787 "redistribute " FRR_IP_REDIST_STR_BGPD,
15788 "Redistribute information from another routing protocol\n"
15789 FRR_IP_REDIST_HELP_STR_BGPD)
15790 {
15791 int idx_protocol = 1;
15792 char base_xpath[XPATH_MAXLEN];
15793
15794 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15795 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15796 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15797 argv[idx_protocol]->text, "0");
15798
15799 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15800
15801 return nb_cli_apply_changes(vty, base_xpath);
15802 }
15803
15804 ALIAS_HIDDEN(
15805 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
15806 "redistribute " FRR_IP_REDIST_STR_BGPD,
15807 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
15808
15809 DEFUN_YANG (bgp_redistribute_ipv4_rmap,
15810 bgp_redistribute_ipv4_rmap_cmd,
15811 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
15812 "Redistribute information from another routing protocol\n"
15813 FRR_IP_REDIST_HELP_STR_BGPD
15814 "Route map reference\n"
15815 "Pointer to route-map entries\n")
15816 {
15817 int idx_protocol = 1;
15818 int idx_word = 3;
15819 char base_xpath[XPATH_MAXLEN];
15820
15821 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15822 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15823 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15824 argv[idx_protocol]->text, "0");
15825
15826 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15827 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15828 argv[idx_word]->arg);
15829
15830 return nb_cli_apply_changes(vty, base_xpath);
15831 }
15832
15833 ALIAS_HIDDEN(
15834 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
15835 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
15836 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15837 "Route map reference\n"
15838 "Pointer to route-map entries\n")
15839
15840 DEFUN_YANG (bgp_redistribute_ipv4_metric,
15841 bgp_redistribute_ipv4_metric_cmd,
15842 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15843 "Redistribute information from another routing protocol\n"
15844 FRR_IP_REDIST_HELP_STR_BGPD
15845 "Metric for redistributed routes\n"
15846 "Default metric\n")
15847 {
15848 int idx_protocol = 1;
15849 int idx_number = 3;
15850 char base_xpath[XPATH_MAXLEN];
15851
15852 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15853 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15854 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15855 argv[idx_protocol]->text, "0");
15856
15857 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15858 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15859 argv[idx_number]->arg);
15860
15861 return nb_cli_apply_changes(vty, base_xpath);
15862 }
15863
15864 ALIAS_HIDDEN(
15865 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
15866 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15867 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15868 "Metric for redistributed routes\n"
15869 "Default metric\n")
15870
15871 DEFUN_YANG(
15872 bgp_redistribute_ipv4_rmap_metric,
15873 bgp_redistribute_ipv4_rmap_metric_cmd,
15874 "redistribute " FRR_IP_REDIST_STR_BGPD
15875 " route-map WORD metric (0-4294967295)",
15876 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15877 "Route map reference\n"
15878 "Pointer to route-map entries\n"
15879 "Metric for redistributed routes\n"
15880 "Default metric\n")
15881 {
15882 int idx_protocol = 1;
15883 int idx_word = 3;
15884 int idx_number = 5;
15885 char base_xpath[XPATH_MAXLEN];
15886
15887 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15888 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15889 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15890 argv[idx_protocol]->text, "0");
15891
15892 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15893 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15894 argv[idx_word]->arg);
15895 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15896 argv[idx_number]->arg);
15897
15898 return nb_cli_apply_changes(vty, base_xpath);
15899 }
15900
15901 ALIAS_HIDDEN(
15902 bgp_redistribute_ipv4_rmap_metric,
15903 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
15904 "redistribute " FRR_IP_REDIST_STR_BGPD
15905 " route-map WORD metric (0-4294967295)",
15906 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15907 "Route map reference\n"
15908 "Pointer to route-map entries\n"
15909 "Metric for redistributed routes\n"
15910 "Default metric\n")
15911
15912 DEFUN_YANG(
15913 bgp_redistribute_ipv4_metric_rmap,
15914 bgp_redistribute_ipv4_metric_rmap_cmd,
15915 "redistribute " FRR_IP_REDIST_STR_BGPD
15916 " metric (0-4294967295) route-map WORD",
15917 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15918 "Metric for redistributed routes\n"
15919 "Default metric\n"
15920 "Route map reference\n"
15921 "Pointer to route-map entries\n")
15922 {
15923 int idx_protocol = 1;
15924 int idx_word = 5;
15925 int idx_number = 3;
15926 char base_xpath[XPATH_MAXLEN];
15927
15928 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15929 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15930 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15931 argv[idx_protocol]->text, "0");
15932
15933 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15934 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15935 argv[idx_number]->arg);
15936 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15937 argv[idx_word]->arg);
15938
15939 return nb_cli_apply_changes(vty, base_xpath);
15940 }
15941
15942 ALIAS_HIDDEN(
15943 bgp_redistribute_ipv4_metric_rmap,
15944 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
15945 "redistribute " FRR_IP_REDIST_STR_BGPD
15946 " metric (0-4294967295) route-map WORD",
15947 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15948 "Metric for redistributed routes\n"
15949 "Default metric\n"
15950 "Route map reference\n"
15951 "Pointer to route-map entries\n")
15952
15953 DEFUN_YANG (bgp_redistribute_ipv4_ospf,
15954 bgp_redistribute_ipv4_ospf_cmd,
15955 "redistribute <ospf|table> (1-65535)",
15956 "Redistribute information from another routing protocol\n"
15957 "Open Shortest Path First (OSPFv2)\n"
15958 "Non-main Kernel Routing Table\n"
15959 "Instance ID/Table ID\n")
15960 {
15961 int idx_protocol = 1;
15962 int idx_number = 2;
15963 char base_xpath[XPATH_MAXLEN];
15964
15965 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15966 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15967 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15968 argv[idx_protocol]->text, argv[idx_number]->arg);
15969
15970 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15971
15972 return nb_cli_apply_changes(vty, base_xpath);
15973 }
15974
15975 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
15976 "redistribute <ospf|table> (1-65535)",
15977 "Redistribute information from another routing protocol\n"
15978 "Open Shortest Path First (OSPFv2)\n"
15979 "Non-main Kernel Routing Table\n"
15980 "Instance ID/Table ID\n")
15981
15982 DEFUN_YANG (bgp_redistribute_ipv4_ospf_rmap,
15983 bgp_redistribute_ipv4_ospf_rmap_cmd,
15984 "redistribute <ospf|table> (1-65535) route-map WORD",
15985 "Redistribute information from another routing protocol\n"
15986 "Open Shortest Path First (OSPFv2)\n"
15987 "Non-main Kernel Routing Table\n"
15988 "Instance ID/Table ID\n"
15989 "Route map reference\n"
15990 "Pointer to route-map entries\n")
15991 {
15992 int idx_protocol = 1;
15993 int idx_number = 2;
15994 int idx_word = 4;
15995 char base_xpath[XPATH_MAXLEN];
15996
15997 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15998 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15999 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16000 argv[idx_protocol]->text, argv[idx_number]->arg);
16001
16002 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16003
16004 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16005 argv[idx_word]->arg);
16006
16007 return nb_cli_apply_changes(vty, base_xpath);
16008 }
16009
16010 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
16011 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
16012 "redistribute <ospf|table> (1-65535) route-map WORD",
16013 "Redistribute information from another routing protocol\n"
16014 "Open Shortest Path First (OSPFv2)\n"
16015 "Non-main Kernel Routing Table\n"
16016 "Instance ID/Table ID\n"
16017 "Route map reference\n"
16018 "Pointer to route-map entries\n")
16019
16020 DEFUN_YANG(bgp_redistribute_ipv4_ospf_metric,
16021 bgp_redistribute_ipv4_ospf_metric_cmd,
16022 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
16023 "Redistribute information from another routing protocol\n"
16024 "Open Shortest Path First (OSPFv2)\n"
16025 "Non-main Kernel Routing Table\n"
16026 "Instance ID/Table ID\n"
16027 "Metric for redistributed routes\n"
16028 "Default metric\n")
16029 {
16030 int idx_protocol = 1;
16031 int idx_number = 2;
16032 int idx_number_2 = 4;
16033 char base_xpath[XPATH_MAXLEN];
16034
16035 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16036 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16037 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16038 argv[idx_protocol]->text, argv[idx_number]->arg);
16039
16040 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16041
16042 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16043 argv[idx_number_2]->arg);
16044
16045 return nb_cli_apply_changes(vty, base_xpath);
16046 }
16047
16048 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
16049 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
16050 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
16051 "Redistribute information from another routing protocol\n"
16052 "Open Shortest Path First (OSPFv2)\n"
16053 "Non-main Kernel Routing Table\n"
16054 "Instance ID/Table ID\n"
16055 "Metric for redistributed routes\n"
16056 "Default metric\n")
16057
16058 DEFUN_YANG(
16059 bgp_redistribute_ipv4_ospf_rmap_metric,
16060 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
16061 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
16062 "Redistribute information from another routing protocol\n"
16063 "Open Shortest Path First (OSPFv2)\n"
16064 "Non-main Kernel Routing Table\n"
16065 "Instance ID/Table ID\n"
16066 "Route map reference\n"
16067 "Pointer to route-map entries\n"
16068 "Metric for redistributed routes\n"
16069 "Default metric\n")
16070 {
16071 int idx_protocol = 1;
16072 int idx_number = 2;
16073 int idx_word = 4;
16074 int idx_number_2 = 6;
16075 char base_xpath[XPATH_MAXLEN];
16076
16077 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16078 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16079 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16080 argv[idx_protocol]->text, argv[idx_number]->arg);
16081
16082 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16083
16084 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16085 argv[idx_word]->arg);
16086 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16087 argv[idx_number_2]->arg);
16088
16089 return nb_cli_apply_changes(vty, base_xpath);
16090 }
16091
16092 ALIAS_HIDDEN(
16093 bgp_redistribute_ipv4_ospf_rmap_metric,
16094 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
16095 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
16096 "Redistribute information from another routing protocol\n"
16097 "Open Shortest Path First (OSPFv2)\n"
16098 "Non-main Kernel Routing Table\n"
16099 "Instance ID/Table ID\n"
16100 "Route map reference\n"
16101 "Pointer to route-map entries\n"
16102 "Metric for redistributed routes\n"
16103 "Default metric\n")
16104
16105 DEFUN_YANG(
16106 bgp_redistribute_ipv4_ospf_metric_rmap,
16107 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
16108 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
16109 "Redistribute information from another routing protocol\n"
16110 "Open Shortest Path First (OSPFv2)\n"
16111 "Non-main Kernel Routing Table\n"
16112 "Instance ID/Table ID\n"
16113 "Metric for redistributed routes\n"
16114 "Default metric\n"
16115 "Route map reference\n"
16116 "Pointer to route-map entries\n")
16117 {
16118 int idx_protocol = 1;
16119 int idx_number = 2;
16120 int idx_number_2 = 4;
16121 int idx_word = 6;
16122 char base_xpath[XPATH_MAXLEN];
16123
16124 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16125 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16126 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16127 argv[idx_protocol]->text, argv[idx_number]->arg);
16128
16129 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16130
16131 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16132 argv[idx_number_2]->arg);
16133 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16134 argv[idx_word]->arg);
16135
16136 return nb_cli_apply_changes(vty, base_xpath);
16137 }
16138
16139 ALIAS_HIDDEN(
16140 bgp_redistribute_ipv4_ospf_metric_rmap,
16141 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
16142 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
16143 "Redistribute information from another routing protocol\n"
16144 "Open Shortest Path First (OSPFv2)\n"
16145 "Non-main Kernel Routing Table\n"
16146 "Instance ID/Table ID\n"
16147 "Metric for redistributed routes\n"
16148 "Default metric\n"
16149 "Route map reference\n"
16150 "Pointer to route-map entries\n")
16151
16152 DEFUN_YANG (no_bgp_redistribute_ipv4_ospf,
16153 no_bgp_redistribute_ipv4_ospf_cmd,
16154 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
16155 NO_STR
16156 "Redistribute information from another routing protocol\n"
16157 "Open Shortest Path First (OSPFv2)\n"
16158 "Non-main Kernel Routing Table\n"
16159 "Instance ID/Table ID\n"
16160 "Metric for redistributed routes\n"
16161 "Default metric\n"
16162 "Route map reference\n"
16163 "Pointer to route-map entries\n")
16164 {
16165 int idx_protocol = 2;
16166 int idx_number = 3;
16167 char base_xpath[XPATH_MAXLEN];
16168
16169 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16170 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16171 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16172 argv[idx_protocol]->text, argv[idx_number]->arg);
16173
16174 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
16175
16176 return nb_cli_apply_changes(vty, base_xpath);
16177 }
16178
16179 ALIAS_HIDDEN(
16180 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
16181 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
16182 NO_STR
16183 "Redistribute information from another routing protocol\n"
16184 "Open Shortest Path First (OSPFv2)\n"
16185 "Non-main Kernel Routing Table\n"
16186 "Instance ID/Table ID\n"
16187 "Metric for redistributed routes\n"
16188 "Default metric\n"
16189 "Route map reference\n"
16190 "Pointer to route-map entries\n")
16191
16192 DEFUN_YANG (no_bgp_redistribute_ipv4,
16193 no_bgp_redistribute_ipv4_cmd,
16194 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
16195 NO_STR
16196 "Redistribute information from another routing protocol\n"
16197 FRR_IP_REDIST_HELP_STR_BGPD
16198 "Metric for redistributed routes\n"
16199 "Default metric\n"
16200 "Route map reference\n"
16201 "Pointer to route-map entries\n")
16202 {
16203 int idx_protocol = 2;
16204 char base_xpath[XPATH_MAXLEN];
16205
16206 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16207 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16208 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16209 argv[idx_protocol]->text, "0");
16210
16211 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
16212
16213 return nb_cli_apply_changes(vty, base_xpath);
16214 }
16215
16216 ALIAS_HIDDEN(
16217 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
16218 "no redistribute " FRR_IP_REDIST_STR_BGPD
16219 " [{metric (0-4294967295)|route-map WORD}]",
16220 NO_STR
16221 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16222 "Metric for redistributed routes\n"
16223 "Default metric\n"
16224 "Route map reference\n"
16225 "Pointer to route-map entries\n")
16226
16227 DEFUN_YANG (bgp_redistribute_ipv6,
16228 bgp_redistribute_ipv6_cmd,
16229 "redistribute " FRR_IP6_REDIST_STR_BGPD,
16230 "Redistribute information from another routing protocol\n"
16231 FRR_IP6_REDIST_HELP_STR_BGPD)
16232 {
16233 int idx_protocol = 1;
16234 char base_xpath[XPATH_MAXLEN];
16235
16236 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16237 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16238 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16239 argv[idx_protocol]->text, "0");
16240
16241 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16242
16243 return nb_cli_apply_changes(vty, base_xpath);
16244 }
16245
16246 DEFUN_YANG (bgp_redistribute_ipv6_rmap,
16247 bgp_redistribute_ipv6_rmap_cmd,
16248 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
16249 "Redistribute information from another routing protocol\n"
16250 FRR_IP6_REDIST_HELP_STR_BGPD
16251 "Route map reference\n"
16252 "Pointer to route-map entries\n")
16253 {
16254 int idx_protocol = 1;
16255 int idx_word = 3;
16256 char base_xpath[XPATH_MAXLEN];
16257
16258 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16259 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16260 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16261 argv[idx_protocol]->text, "0");
16262
16263 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16264 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16265 argv[idx_word]->arg);
16266
16267 return nb_cli_apply_changes(vty, base_xpath);
16268 }
16269
16270 DEFUN_YANG (bgp_redistribute_ipv6_metric,
16271 bgp_redistribute_ipv6_metric_cmd,
16272 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
16273 "Redistribute information from another routing protocol\n"
16274 FRR_IP6_REDIST_HELP_STR_BGPD
16275 "Metric for redistributed routes\n"
16276 "Default metric\n")
16277 {
16278 int idx_protocol = 1;
16279 int idx_number = 3;
16280 char base_xpath[XPATH_MAXLEN];
16281
16282 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16283 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16284 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16285 argv[idx_protocol]->text, "0");
16286
16287 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16288 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16289 argv[idx_number]->arg);
16290
16291 return nb_cli_apply_changes(vty, base_xpath);
16292 }
16293
16294 DEFUN_YANG(
16295 bgp_redistribute_ipv6_rmap_metric,
16296 bgp_redistribute_ipv6_rmap_metric_cmd,
16297 "redistribute " FRR_IP6_REDIST_STR_BGPD
16298 " route-map WORD metric (0-4294967295)",
16299 "Redistribute information from another routing protocol\n" FRR_IP6_REDIST_HELP_STR_BGPD
16300 "Route map reference\n"
16301 "Pointer to route-map entries\n"
16302 "Metric for redistributed routes\n"
16303 "Default metric\n")
16304 {
16305 int idx_protocol = 1;
16306 int idx_word = 3;
16307 int idx_number = 5;
16308 char base_xpath[XPATH_MAXLEN];
16309
16310 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16311 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16312 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16313 argv[idx_protocol]->text, "0");
16314
16315 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16316 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16317 argv[idx_word]->arg);
16318 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16319 argv[idx_number]->arg);
16320
16321 return nb_cli_apply_changes(vty, base_xpath);
16322 }
16323
16324 DEFUN_YANG(
16325 bgp_redistribute_ipv6_metric_rmap,
16326 bgp_redistribute_ipv6_metric_rmap_cmd,
16327 "redistribute " FRR_IP6_REDIST_STR_BGPD
16328 " metric (0-4294967295) route-map WORD",
16329 "Redistribute information from another routing protocol\n" FRR_IP6_REDIST_HELP_STR_BGPD
16330 "Metric for redistributed routes\n"
16331 "Default metric\n"
16332 "Route map reference\n"
16333 "Pointer to route-map entries\n")
16334 {
16335 int idx_protocol = 1;
16336 int idx_word = 5;
16337 int idx_number = 3;
16338 char base_xpath[XPATH_MAXLEN];
16339
16340 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16341 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16342 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16343 argv[idx_protocol]->text, "0");
16344
16345 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16346 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16347 argv[idx_number]->arg);
16348 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16349 argv[idx_word]->arg);
16350
16351 return nb_cli_apply_changes(vty, base_xpath);
16352 }
16353
16354 DEFUN_YANG(
16355 no_bgp_redistribute_ipv6,
16356 no_bgp_redistribute_ipv6_cmd,
16357 "no redistribute " FRR_IP6_REDIST_STR_BGPD
16358 " [{metric (0-4294967295)|route-map WORD}]",
16359 NO_STR
16360 "Redistribute information from another routing protocol\n" FRR_IP6_REDIST_HELP_STR_BGPD
16361 "Metric for redistributed routes\n"
16362 "Default metric\n"
16363 "Route map reference\n"
16364 "Pointer to route-map entries\n")
16365 {
16366 int idx_protocol = 2;
16367 char base_xpath[XPATH_MAXLEN];
16368
16369 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16370 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16371 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16372 argv[idx_protocol]->text, "0");
16373
16374 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
16375
16376 return nb_cli_apply_changes(vty, base_xpath);
16377 }
16378
16379 void cli_show_bgp_global_afi_safi_ip_unicast_redistribution_list(
16380 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
16381 {
16382 uint32_t instance = 0;
16383
16384 vty_out(vty, " redistribute %s",
16385 yang_dnode_get_string(dnode, "./route-type"));
16386 if ((instance = yang_dnode_get_uint16(dnode, "./route-instance")))
16387 vty_out(vty, " %d", instance);
16388 if (yang_dnode_exists(dnode, "./metric"))
16389 vty_out(vty, " metric %u",
16390 yang_dnode_get_uint32(dnode, "./metric"));
16391 if (yang_dnode_exists(dnode, "./rmap-policy-import"))
16392 vty_out(vty, " route-map %s",
16393 yang_dnode_get_string(dnode, "./rmap-policy-import"));
16394 vty_out(vty, "\n");
16395 }
16396
16397 static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
16398 afi_t afi, safi_t safi)
16399 {
16400 int i;
16401
16402 /* Unicast redistribution only. */
16403 if (safi != SAFI_UNICAST)
16404 return;
16405
16406 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
16407 /* Redistribute BGP does not make sense. */
16408 if (i != ZEBRA_ROUTE_BGP) {
16409 struct list *red_list;
16410 struct listnode *node;
16411 struct bgp_redist *red;
16412
16413 red_list = bgp->redist[afi][i];
16414 if (!red_list)
16415 continue;
16416
16417 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
16418 /* "redistribute" configuration. */
16419 vty_out(vty, " redistribute %s",
16420 zebra_route_string(i));
16421 if (red->instance)
16422 vty_out(vty, " %d", red->instance);
16423 if (red->redist_metric_flag)
16424 vty_out(vty, " metric %u",
16425 red->redist_metric);
16426 if (red->rmap.name)
16427 vty_out(vty, " route-map %s",
16428 red->rmap.name);
16429 vty_out(vty, "\n");
16430 }
16431 }
16432 }
16433 }
16434
16435 /* peer-group helpers for config-write */
16436
16437 static bool peergroup_flag_check(struct peer *peer, uint32_t flag)
16438 {
16439 if (!peer_group_active(peer)) {
16440 if (CHECK_FLAG(peer->flags_invert, flag))
16441 return !CHECK_FLAG(peer->flags, flag);
16442 else
16443 return !!CHECK_FLAG(peer->flags, flag);
16444 }
16445
16446 return !!CHECK_FLAG(peer->flags_override, flag);
16447 }
16448
16449 static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
16450 uint32_t flag)
16451 {
16452 if (!peer_group_active(peer)) {
16453 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
16454 return !peer_af_flag_check(peer, afi, safi, flag);
16455 else
16456 return !!peer_af_flag_check(peer, afi, safi, flag);
16457 }
16458
16459 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
16460 }
16461
16462 static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
16463 uint8_t type, int direct)
16464 {
16465 struct bgp_filter *filter;
16466
16467 if (peer_group_active(peer))
16468 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
16469 type);
16470
16471 filter = &peer->filter[afi][safi];
16472 switch (type) {
16473 case PEER_FT_DISTRIBUTE_LIST:
16474 return !!(filter->dlist[direct].name);
16475 case PEER_FT_FILTER_LIST:
16476 return !!(filter->aslist[direct].name);
16477 case PEER_FT_PREFIX_LIST:
16478 return !!(filter->plist[direct].name);
16479 case PEER_FT_ROUTE_MAP:
16480 return !!(filter->map[direct].name);
16481 case PEER_FT_UNSUPPRESS_MAP:
16482 return !!(filter->usmap.name);
16483 case PEER_FT_ADVERTISE_MAP:
16484 return !!(filter->advmap.aname
16485 && ((filter->advmap.condition == direct)
16486 && filter->advmap.cname));
16487 default:
16488 return false;
16489 }
16490 }
16491
16492 /* Return true if the addpath type is set for peer and different from
16493 * peer-group.
16494 */
16495 static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi,
16496 safi_t safi)
16497 {
16498 enum bgp_addpath_strat type, g_type;
16499
16500 type = peer->addpath_type[afi][safi];
16501
16502 if (type != BGP_ADDPATH_NONE) {
16503 if (peer_group_active(peer)) {
16504 g_type = peer->group->conf->addpath_type[afi][safi];
16505
16506 if (type != g_type)
16507 return true;
16508 else
16509 return false;
16510 }
16511
16512 return true;
16513 }
16514
16515 return false;
16516 }
16517
16518 /* This is part of the address-family block (unicast only) */
16519 static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
16520 afi_t afi)
16521 {
16522 int indent = 2;
16523
16524 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
16525 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16526 BGP_CONFIG_VRF_TO_VRF_IMPORT))
16527 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
16528 bgp->vpn_policy[afi]
16529 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16530 else
16531 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
16532 bgp->vpn_policy[afi]
16533 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16534 }
16535 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16536 BGP_CONFIG_VRF_TO_VRF_IMPORT)
16537 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16538 BGP_CONFIG_VRF_TO_VRF_EXPORT))
16539 return;
16540
16541 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16542 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
16543
16544 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
16545
16546 } else {
16547 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
16548 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
16549 bgp->vpn_policy[afi].tovpn_label);
16550 }
16551 }
16552 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16553 BGP_VPN_POLICY_TOVPN_RD_SET)) {
16554 char buf[RD_ADDRSTRLEN];
16555 vty_out(vty, "%*srd vpn export %s\n", indent, "",
16556 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
16557 sizeof(buf)));
16558 }
16559 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16560 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
16561
16562 char buf[PREFIX_STRLEN];
16563 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
16564 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
16565 sizeof(buf))) {
16566
16567 vty_out(vty, "%*snexthop vpn export %s\n",
16568 indent, "", buf);
16569 }
16570 }
16571 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
16572 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
16573 && ecommunity_cmp(
16574 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16575 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
16576
16577 char *b = ecommunity_ecom2str(
16578 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16579 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
16580 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
16581 XFREE(MTYPE_ECOMMUNITY_STR, b);
16582 } else {
16583 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
16584 char *b = ecommunity_ecom2str(
16585 bgp->vpn_policy[afi]
16586 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16587 ECOMMUNITY_FORMAT_ROUTE_MAP,
16588 ECOMMUNITY_ROUTE_TARGET);
16589 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
16590 XFREE(MTYPE_ECOMMUNITY_STR, b);
16591 }
16592 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
16593 char *b = ecommunity_ecom2str(
16594 bgp->vpn_policy[afi]
16595 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16596 ECOMMUNITY_FORMAT_ROUTE_MAP,
16597 ECOMMUNITY_ROUTE_TARGET);
16598 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
16599 XFREE(MTYPE_ECOMMUNITY_STR, b);
16600 }
16601 }
16602
16603 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
16604 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
16605 bgp->vpn_policy[afi]
16606 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
16607
16608 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
16609 char *b = ecommunity_ecom2str(
16610 bgp->vpn_policy[afi]
16611 .import_redirect_rtlist,
16612 ECOMMUNITY_FORMAT_ROUTE_MAP,
16613 ECOMMUNITY_ROUTE_TARGET);
16614
16615 if (bgp->vpn_policy[afi].import_redirect_rtlist->unit_size
16616 != ECOMMUNITY_SIZE)
16617 vty_out(vty, "%*srt6 redirect import %s\n",
16618 indent, "", b);
16619 else
16620 vty_out(vty, "%*srt redirect import %s\n",
16621 indent, "", b);
16622 XFREE(MTYPE_ECOMMUNITY_STR, b);
16623 }
16624 }
16625
16626 static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
16627 afi_t afi, safi_t safi)
16628 {
16629 struct bgp_filter *filter;
16630 char *addr;
16631
16632 addr = peer->host;
16633 filter = &peer->filter[afi][safi];
16634
16635 /* distribute-list. */
16636 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16637 FILTER_IN))
16638 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
16639 filter->dlist[FILTER_IN].name);
16640
16641 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16642 FILTER_OUT))
16643 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
16644 filter->dlist[FILTER_OUT].name);
16645
16646 /* prefix-list. */
16647 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16648 FILTER_IN))
16649 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
16650 filter->plist[FILTER_IN].name);
16651
16652 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16653 FILTER_OUT))
16654 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
16655 filter->plist[FILTER_OUT].name);
16656
16657 /* route-map. */
16658 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
16659 vty_out(vty, " neighbor %s route-map %s in\n", addr,
16660 filter->map[RMAP_IN].name);
16661
16662 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
16663 RMAP_OUT))
16664 vty_out(vty, " neighbor %s route-map %s out\n", addr,
16665 filter->map[RMAP_OUT].name);
16666
16667 /* unsuppress-map */
16668 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
16669 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
16670 filter->usmap.name);
16671
16672 /* advertise-map : always applied in OUT direction*/
16673 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16674 CONDITION_NON_EXIST))
16675 vty_out(vty,
16676 " neighbor %s advertise-map %s non-exist-map %s\n",
16677 addr, filter->advmap.aname, filter->advmap.cname);
16678
16679 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16680 CONDITION_EXIST))
16681 vty_out(vty, " neighbor %s advertise-map %s exist-map %s\n",
16682 addr, filter->advmap.aname, filter->advmap.cname);
16683
16684 /* filter-list. */
16685 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16686 FILTER_IN))
16687 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
16688 filter->aslist[FILTER_IN].name);
16689
16690 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16691 FILTER_OUT))
16692 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
16693 filter->aslist[FILTER_OUT].name);
16694 }
16695
16696 /* BGP peer configuration display function. */
16697 static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
16698 struct peer *peer)
16699 {
16700 struct peer *g_peer = NULL;
16701 char buf[SU_ADDRSTRLEN];
16702 char *addr;
16703 int if_pg_printed = false;
16704 int if_ras_printed = false;
16705
16706 /* Skip dynamic neighbors. */
16707 if (peer_dynamic_neighbor(peer))
16708 return;
16709
16710 if (peer->conf_if)
16711 addr = peer->conf_if;
16712 else
16713 addr = peer->host;
16714
16715 /************************************
16716 ****** Global to the neighbor ******
16717 ************************************/
16718 if (peer->conf_if) {
16719 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
16720 vty_out(vty, " neighbor %s interface v6only", addr);
16721 else
16722 vty_out(vty, " neighbor %s interface", addr);
16723
16724 if (peer_group_active(peer)) {
16725 vty_out(vty, " peer-group %s", peer->group->name);
16726 if_pg_printed = true;
16727 } else if (peer->as_type == AS_SPECIFIED) {
16728 vty_out(vty, " remote-as %u", peer->as);
16729 if_ras_printed = true;
16730 } else if (peer->as_type == AS_INTERNAL) {
16731 vty_out(vty, " remote-as internal");
16732 if_ras_printed = true;
16733 } else if (peer->as_type == AS_EXTERNAL) {
16734 vty_out(vty, " remote-as external");
16735 if_ras_printed = true;
16736 }
16737
16738 vty_out(vty, "\n");
16739 }
16740
16741 /* remote-as and peer-group */
16742 /* peer is a member of a peer-group */
16743 if (peer_group_active(peer)) {
16744 g_peer = peer->group->conf;
16745
16746 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
16747 if (peer->as_type == AS_SPECIFIED) {
16748 vty_out(vty, " neighbor %s remote-as %u\n",
16749 addr, peer->as);
16750 } else if (peer->as_type == AS_INTERNAL) {
16751 vty_out(vty,
16752 " neighbor %s remote-as internal\n",
16753 addr);
16754 } else if (peer->as_type == AS_EXTERNAL) {
16755 vty_out(vty,
16756 " neighbor %s remote-as external\n",
16757 addr);
16758 }
16759 }
16760
16761 /* For swpX peers we displayed the peer-group
16762 * via 'neighbor swpX interface peer-group PGNAME' */
16763 if (!if_pg_printed)
16764 vty_out(vty, " neighbor %s peer-group %s\n", addr,
16765 peer->group->name);
16766 }
16767
16768 /* peer is NOT a member of a peer-group */
16769 else {
16770 /* peer is a peer-group, declare the peer-group */
16771 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
16772 vty_out(vty, " neighbor %s peer-group\n", addr);
16773 }
16774
16775 if (!if_ras_printed) {
16776 if (peer->as_type == AS_SPECIFIED) {
16777 vty_out(vty, " neighbor %s remote-as %u\n",
16778 addr, peer->as);
16779 } else if (peer->as_type == AS_INTERNAL) {
16780 vty_out(vty,
16781 " neighbor %s remote-as internal\n",
16782 addr);
16783 } else if (peer->as_type == AS_EXTERNAL) {
16784 vty_out(vty,
16785 " neighbor %s remote-as external\n",
16786 addr);
16787 }
16788 }
16789 }
16790
16791 /* local-as */
16792 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
16793 vty_out(vty, " neighbor %s local-as %u", addr,
16794 peer->change_local_as);
16795 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
16796 vty_out(vty, " no-prepend");
16797 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
16798 vty_out(vty, " replace-as");
16799 vty_out(vty, "\n");
16800 }
16801
16802 /* description */
16803 if (peer->desc) {
16804 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
16805 }
16806
16807 /* shutdown */
16808 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
16809 if (peer->tx_shutdown_message)
16810 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
16811 peer->tx_shutdown_message);
16812 else
16813 vty_out(vty, " neighbor %s shutdown\n", addr);
16814 }
16815
16816 if (peergroup_flag_check(peer, PEER_FLAG_RTT_SHUTDOWN))
16817 vty_out(vty, " neighbor %s shutdown rtt %u count %u\n", addr,
16818 peer->rtt_expected, peer->rtt_keepalive_conf);
16819
16820 /* bfd */
16821 if (peer->bfd_info) {
16822 if (!peer_group_active(peer) || !g_peer->bfd_info) {
16823 bgp_bfd_peer_config_write(vty, peer, addr);
16824 }
16825 }
16826
16827 /* password */
16828 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
16829 vty_out(vty, " neighbor %s password %s\n", addr,
16830 peer->password);
16831
16832 /* neighbor solo */
16833 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
16834 if (!peer_group_active(peer)) {
16835 vty_out(vty, " neighbor %s solo\n", addr);
16836 }
16837 }
16838
16839 /* BGP port */
16840 if (peer->port != BGP_PORT_DEFAULT) {
16841 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
16842 }
16843
16844 /* Local interface name */
16845 if (peer->ifname) {
16846 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
16847 }
16848
16849 /* passive */
16850 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
16851 vty_out(vty, " neighbor %s passive\n", addr);
16852
16853 /* ebgp-multihop */
16854 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
16855 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
16856 && peer->ttl == MAXTTL)) {
16857 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
16858 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
16859 peer->ttl);
16860 }
16861 }
16862
16863 /* ttl-security hops */
16864 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
16865 if (!peer_group_active(peer)
16866 || g_peer->gtsm_hops != peer->gtsm_hops) {
16867 vty_out(vty, " neighbor %s ttl-security hops %d\n",
16868 addr, peer->gtsm_hops);
16869 }
16870 }
16871
16872 /* disable-connected-check */
16873 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
16874 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
16875
16876 /* enforce-first-as */
16877 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
16878 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
16879
16880 /* update-source */
16881 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
16882 if (peer->update_source)
16883 vty_out(vty, " neighbor %s update-source %s\n", addr,
16884 sockunion2str(peer->update_source, buf,
16885 SU_ADDRSTRLEN));
16886 else if (peer->update_if)
16887 vty_out(vty, " neighbor %s update-source %s\n", addr,
16888 peer->update_if);
16889 }
16890
16891 /* advertisement-interval */
16892 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
16893 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
16894 peer->routeadv);
16895
16896 /* timers */
16897 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
16898 vty_out(vty, " neighbor %s timers %u %u\n", addr,
16899 peer->keepalive, peer->holdtime);
16900
16901 /* timers connect */
16902 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
16903 vty_out(vty, " neighbor %s timers connect %u\n", addr,
16904 peer->connect);
16905 /* need special-case handling for changed default values due to
16906 * config profile / version (because there is no "timers bgp connect"
16907 * command, we need to save this per-peer :/)
16908 */
16909 else if (!peer_group_active(peer) && !peer->connect &&
16910 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
16911 vty_out(vty, " neighbor %s timers connect %u\n", addr,
16912 peer->bgp->default_connect_retry);
16913
16914 /* timers delayopen */
16915 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_DELAYOPEN))
16916 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
16917 peer->delayopen);
16918 /* Save config even though flag is not set if default values have been
16919 * changed
16920 */
16921 else if (!peer_group_active(peer) && !peer->delayopen
16922 && peer->bgp->default_delayopen != BGP_DEFAULT_DELAYOPEN)
16923 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
16924 peer->bgp->default_delayopen);
16925
16926 /* capability dynamic */
16927 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
16928 vty_out(vty, " neighbor %s capability dynamic\n", addr);
16929
16930 /* capability extended-nexthop */
16931 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
16932 if (!peer->conf_if) {
16933 if (CHECK_FLAG(peer->flags_invert,
16934 PEER_FLAG_CAPABILITY_ENHE))
16935 vty_out(vty,
16936 " no neighbor %s capability extended-nexthop\n",
16937 addr);
16938 else
16939 vty_out(vty,
16940 " neighbor %s capability extended-nexthop\n",
16941 addr);
16942 }
16943 }
16944
16945 /* dont-capability-negotiation */
16946 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
16947 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
16948
16949 /* override-capability */
16950 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
16951 vty_out(vty, " neighbor %s override-capability\n", addr);
16952
16953 /* strict-capability-match */
16954 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
16955 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
16956
16957 /* Sender side AS path loop detection. */
16958 if (peer->as_path_loop_detection)
16959 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
16960 addr);
16961
16962 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
16963 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
16964
16965 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
16966 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
16967 vty_out(vty,
16968 " neighbor %s graceful-restart-helper\n", addr);
16969 } else if (CHECK_FLAG(
16970 peer->peer_gr_new_status_flag,
16971 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
16972 vty_out(vty,
16973 " neighbor %s graceful-restart\n", addr);
16974 } else if (
16975 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
16976 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
16977 && !(CHECK_FLAG(
16978 peer->peer_gr_new_status_flag,
16979 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
16980 vty_out(vty, " neighbor %s graceful-restart-disable\n",
16981 addr);
16982 }
16983 }
16984 }
16985
16986 /* BGP peer configuration display function. */
16987 static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
16988 struct peer *peer, afi_t afi, safi_t safi)
16989 {
16990 struct peer *g_peer = NULL;
16991 char *addr;
16992 bool flag_scomm, flag_secomm, flag_slcomm;
16993
16994 /* Skip dynamic neighbors. */
16995 if (peer_dynamic_neighbor(peer))
16996 return;
16997
16998 if (peer->conf_if)
16999 addr = peer->conf_if;
17000 else
17001 addr = peer->host;
17002
17003 /************************************
17004 ****** Per AF to the neighbor ******
17005 ************************************/
17006 if (peer_group_active(peer)) {
17007 g_peer = peer->group->conf;
17008
17009 /* If the peer-group is active but peer is not, print a 'no
17010 * activate' */
17011 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
17012 vty_out(vty, " no neighbor %s activate\n", addr);
17013 }
17014
17015 /* If the peer-group is not active but peer is, print an
17016 'activate' */
17017 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
17018 vty_out(vty, " neighbor %s activate\n", addr);
17019 }
17020 } else {
17021 if (peer->afc[afi][safi]) {
17022 if ((afi == AFI_IP || afi == AFI_IP6)
17023 && safi == SAFI_UNICAST) {
17024 if (afi == AFI_IP
17025 && CHECK_FLAG(bgp->flags,
17026 BGP_FLAG_NO_DEFAULT_IPV4)) {
17027 vty_out(vty, " neighbor %s activate\n",
17028 addr);
17029 } else if (afi == AFI_IP6
17030 && !CHECK_FLAG(
17031 bgp->flags,
17032 BGP_FLAG_DEFAULT_IPV6)) {
17033 vty_out(vty, " neighbor %s activate\n",
17034 addr);
17035 }
17036 } else {
17037 vty_out(vty, " neighbor %s activate\n", addr);
17038 }
17039 } else {
17040 if ((afi == AFI_IP || afi == AFI_IP6)
17041 && safi == SAFI_UNICAST) {
17042 if (afi == AFI_IP
17043 && !CHECK_FLAG(bgp->flags,
17044 BGP_FLAG_NO_DEFAULT_IPV4)) {
17045 vty_out(vty,
17046 " no neighbor %s activate\n",
17047 addr);
17048 } else if (afi == AFI_IP6
17049 && CHECK_FLAG(
17050 bgp->flags,
17051 BGP_FLAG_DEFAULT_IPV6)) {
17052 vty_out(vty,
17053 " no neighbor %s activate\n",
17054 addr);
17055 }
17056 }
17057 }
17058 }
17059
17060 /* addpath TX knobs */
17061 if (peergroup_af_addpath_check(peer, afi, safi)) {
17062 switch (peer->addpath_type[afi][safi]) {
17063 case BGP_ADDPATH_ALL:
17064 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
17065 addr);
17066 break;
17067 case BGP_ADDPATH_BEST_PER_AS:
17068 vty_out(vty,
17069 " neighbor %s addpath-tx-bestpath-per-AS\n",
17070 addr);
17071 break;
17072 case BGP_ADDPATH_MAX:
17073 case BGP_ADDPATH_NONE:
17074 break;
17075 }
17076 }
17077
17078 /* ORF capability. */
17079 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
17080 || peergroup_af_flag_check(peer, afi, safi,
17081 PEER_FLAG_ORF_PREFIX_RM)) {
17082 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
17083
17084 if (peergroup_af_flag_check(peer, afi, safi,
17085 PEER_FLAG_ORF_PREFIX_SM)
17086 && peergroup_af_flag_check(peer, afi, safi,
17087 PEER_FLAG_ORF_PREFIX_RM))
17088 vty_out(vty, " both");
17089 else if (peergroup_af_flag_check(peer, afi, safi,
17090 PEER_FLAG_ORF_PREFIX_SM))
17091 vty_out(vty, " send");
17092 else
17093 vty_out(vty, " receive");
17094 vty_out(vty, "\n");
17095 }
17096
17097 /* Route reflector client. */
17098 if (peergroup_af_flag_check(peer, afi, safi,
17099 PEER_FLAG_REFLECTOR_CLIENT)) {
17100 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
17101 }
17102
17103 /* next-hop-self force */
17104 if (peergroup_af_flag_check(peer, afi, safi,
17105 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
17106 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
17107 }
17108
17109 /* next-hop-self */
17110 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
17111 vty_out(vty, " neighbor %s next-hop-self\n", addr);
17112 }
17113
17114 /* remove-private-AS */
17115 if (peergroup_af_flag_check(peer, afi, safi,
17116 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
17117 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
17118 addr);
17119 }
17120
17121 else if (peergroup_af_flag_check(peer, afi, safi,
17122 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
17123 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
17124 addr);
17125 }
17126
17127 else if (peergroup_af_flag_check(peer, afi, safi,
17128 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
17129 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
17130 }
17131
17132 else if (peergroup_af_flag_check(peer, afi, safi,
17133 PEER_FLAG_REMOVE_PRIVATE_AS)) {
17134 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
17135 }
17136
17137 /* as-override */
17138 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
17139 vty_out(vty, " neighbor %s as-override\n", addr);
17140 }
17141
17142 /* send-community print. */
17143 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
17144 PEER_FLAG_SEND_COMMUNITY);
17145 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
17146 PEER_FLAG_SEND_EXT_COMMUNITY);
17147 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
17148 PEER_FLAG_SEND_LARGE_COMMUNITY);
17149
17150 if (flag_scomm && flag_secomm && flag_slcomm) {
17151 vty_out(vty, " no neighbor %s send-community all\n", addr);
17152 } else {
17153 if (flag_scomm)
17154 vty_out(vty, " no neighbor %s send-community\n", addr);
17155 if (flag_secomm)
17156 vty_out(vty,
17157 " no neighbor %s send-community extended\n",
17158 addr);
17159
17160 if (flag_slcomm)
17161 vty_out(vty, " no neighbor %s send-community large\n",
17162 addr);
17163 }
17164
17165 /* Default information */
17166 if (peergroup_af_flag_check(peer, afi, safi,
17167 PEER_FLAG_DEFAULT_ORIGINATE)) {
17168 vty_out(vty, " neighbor %s default-originate", addr);
17169
17170 if (peer->default_rmap[afi][safi].name)
17171 vty_out(vty, " route-map %s",
17172 peer->default_rmap[afi][safi].name);
17173
17174 vty_out(vty, "\n");
17175 }
17176
17177 /* Soft reconfiguration inbound. */
17178 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
17179 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
17180 addr);
17181 }
17182
17183 /* maximum-prefix. */
17184 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
17185 vty_out(vty, " neighbor %s maximum-prefix %u", addr,
17186 peer->pmax[afi][safi]);
17187
17188 if (peer->pmax_threshold[afi][safi]
17189 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
17190 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
17191 if (peer_af_flag_check(peer, afi, safi,
17192 PEER_FLAG_MAX_PREFIX_WARNING))
17193 vty_out(vty, " warning-only");
17194 if (peer->pmax_restart[afi][safi])
17195 vty_out(vty, " restart %u",
17196 peer->pmax_restart[afi][safi]);
17197 if (peer_af_flag_check(peer, afi, safi,
17198 PEER_FLAG_MAX_PREFIX_FORCE))
17199 vty_out(vty, " force");
17200
17201 vty_out(vty, "\n");
17202 }
17203
17204 /* maximum-prefix-out */
17205 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
17206 vty_out(vty, " neighbor %s maximum-prefix-out %u\n",
17207 addr, peer->pmax_out[afi][safi]);
17208
17209 /* Route server client. */
17210 if (peergroup_af_flag_check(peer, afi, safi,
17211 PEER_FLAG_RSERVER_CLIENT)) {
17212 vty_out(vty, " neighbor %s route-server-client\n", addr);
17213 }
17214
17215 /* Nexthop-local unchanged. */
17216 if (peergroup_af_flag_check(peer, afi, safi,
17217 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
17218 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
17219 }
17220
17221 /* allowas-in <1-10> */
17222 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
17223 if (peer_af_flag_check(peer, afi, safi,
17224 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
17225 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
17226 } else if (peer->allowas_in[afi][safi] == 3) {
17227 vty_out(vty, " neighbor %s allowas-in\n", addr);
17228 } else {
17229 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
17230 peer->allowas_in[afi][safi]);
17231 }
17232 }
17233
17234 /* weight */
17235 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
17236 vty_out(vty, " neighbor %s weight %lu\n", addr,
17237 peer->weight[afi][safi]);
17238
17239 /* Filter. */
17240 bgp_config_write_filter(vty, peer, afi, safi);
17241
17242 /* atribute-unchanged. */
17243 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
17244 || (safi != SAFI_EVPN
17245 && peer_af_flag_check(peer, afi, safi,
17246 PEER_FLAG_NEXTHOP_UNCHANGED))
17247 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
17248
17249 if (!peer_group_active(peer)
17250 || peergroup_af_flag_check(peer, afi, safi,
17251 PEER_FLAG_AS_PATH_UNCHANGED)
17252 || peergroup_af_flag_check(peer, afi, safi,
17253 PEER_FLAG_NEXTHOP_UNCHANGED)
17254 || peergroup_af_flag_check(peer, afi, safi,
17255 PEER_FLAG_MED_UNCHANGED)) {
17256
17257 vty_out(vty,
17258 " neighbor %s attribute-unchanged%s%s%s\n",
17259 addr,
17260 peer_af_flag_check(peer, afi, safi,
17261 PEER_FLAG_AS_PATH_UNCHANGED)
17262 ? " as-path"
17263 : "",
17264 peer_af_flag_check(peer, afi, safi,
17265 PEER_FLAG_NEXTHOP_UNCHANGED)
17266 ? " next-hop"
17267 : "",
17268 peer_af_flag_check(peer, afi, safi,
17269 PEER_FLAG_MED_UNCHANGED)
17270 ? " med"
17271 : "");
17272 }
17273 }
17274 }
17275
17276 /* Address family based peer configuration display. */
17277 static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
17278 safi_t safi)
17279 {
17280 struct peer *peer;
17281 struct peer_group *group;
17282 struct listnode *node, *nnode;
17283
17284
17285 vty_frame(vty, " !\n address-family ");
17286 if (afi == AFI_IP) {
17287 if (safi == SAFI_UNICAST)
17288 vty_frame(vty, "ipv4 unicast");
17289 else if (safi == SAFI_LABELED_UNICAST)
17290 vty_frame(vty, "ipv4 labeled-unicast");
17291 else if (safi == SAFI_MULTICAST)
17292 vty_frame(vty, "ipv4 multicast");
17293 else if (safi == SAFI_MPLS_VPN)
17294 vty_frame(vty, "ipv4 vpn");
17295 else if (safi == SAFI_ENCAP)
17296 vty_frame(vty, "ipv4 encap");
17297 else if (safi == SAFI_FLOWSPEC)
17298 vty_frame(vty, "ipv4 flowspec");
17299 } else if (afi == AFI_IP6) {
17300 if (safi == SAFI_UNICAST)
17301 vty_frame(vty, "ipv6 unicast");
17302 else if (safi == SAFI_LABELED_UNICAST)
17303 vty_frame(vty, "ipv6 labeled-unicast");
17304 else if (safi == SAFI_MULTICAST)
17305 vty_frame(vty, "ipv6 multicast");
17306 else if (safi == SAFI_MPLS_VPN)
17307 vty_frame(vty, "ipv6 vpn");
17308 else if (safi == SAFI_ENCAP)
17309 vty_frame(vty, "ipv6 encap");
17310 else if (safi == SAFI_FLOWSPEC)
17311 vty_frame(vty, "ipv6 flowspec");
17312 } else if (afi == AFI_L2VPN) {
17313 if (safi == SAFI_EVPN)
17314 vty_frame(vty, "l2vpn evpn");
17315 }
17316 vty_frame(vty, "\n");
17317
17318 bgp_config_write_distance(vty, bgp, afi, safi);
17319
17320 bgp_config_write_network(vty, bgp, afi, safi);
17321
17322 bgp_config_write_redistribute(vty, bgp, afi, safi);
17323
17324 /* BGP flag dampening. */
17325 if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
17326 bgp_config_write_damp(vty, bgp, afi, safi);
17327 for (ALL_LIST_ELEMENTS_RO(bgp->group, node, group))
17328 if (peer_af_flag_check(group->conf, afi, safi,
17329 PEER_FLAG_CONFIG_DAMPENING))
17330 bgp_config_write_peer_damp(vty, group->conf, afi, safi);
17331 for (ALL_LIST_ELEMENTS_RO(bgp->peer, node, peer))
17332 if (peer_af_flag_check(peer, afi, safi,
17333 PEER_FLAG_CONFIG_DAMPENING))
17334 bgp_config_write_peer_damp(vty, peer, afi, safi);
17335
17336 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
17337 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
17338
17339 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17340 /* Skip dynamic neighbors. */
17341 if (peer_dynamic_neighbor(peer))
17342 continue;
17343
17344 /* Do not display doppelganger peers */
17345 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17346 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
17347 }
17348
17349 bgp_config_write_maxpaths(vty, bgp, afi, safi);
17350 bgp_config_write_table_map(vty, bgp, afi, safi);
17351
17352 if (safi == SAFI_EVPN)
17353 bgp_config_write_evpn_info(vty, bgp, afi, safi);
17354
17355 if (safi == SAFI_FLOWSPEC)
17356 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
17357
17358 if (safi == SAFI_UNICAST) {
17359 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
17360 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17361 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
17362
17363 vty_out(vty, " export vpn\n");
17364 }
17365 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17366 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
17367
17368 vty_out(vty, " import vpn\n");
17369 }
17370 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17371 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
17372 char *name;
17373
17374 for (ALL_LIST_ELEMENTS_RO(
17375 bgp->vpn_policy[afi].import_vrf, node,
17376 name))
17377 vty_out(vty, " import vrf %s\n", name);
17378 }
17379 }
17380
17381 vty_endframe(vty, " exit-address-family\n");
17382 }
17383
17384 int bgp_config_write(struct vty *vty)
17385 {
17386 struct bgp *bgp;
17387 struct peer_group *group;
17388 struct peer *peer;
17389 struct listnode *node, *nnode;
17390 struct listnode *mnode, *mnnode;
17391
17392 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
17393 vty_out(vty, "bgp route-map delay-timer %u\n",
17394 bm->rmap_update_timer);
17395
17396 if (bm->v_update_delay != BGP_UPDATE_DELAY_DEF) {
17397 vty_out(vty, "bgp update-delay %d", bm->v_update_delay);
17398 if (bm->v_update_delay != bm->v_establish_wait)
17399 vty_out(vty, " %d", bm->v_establish_wait);
17400 vty_out(vty, "\n");
17401 }
17402
17403 if (bm->wait_for_fib)
17404 vty_out(vty, "bgp suppress-fib-pending\n");
17405
17406 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17407 vty_out(vty, "bgp graceful-shutdown\n");
17408
17409 /* No-RIB (Zebra) option flag configuration */
17410 if (bgp_option_check(BGP_OPT_NO_FIB))
17411 vty_out(vty, "bgp no-rib\n");
17412
17413 if (!CHECK_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA))
17414 vty_out(vty, "no bgp send-extra-data zebra\n");
17415
17416 /* BGP configuration. */
17417 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
17418
17419 /* skip all auto created vrf as they dont have user config */
17420 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
17421 continue;
17422
17423 /* Router bgp ASN */
17424 vty_out(vty, "router bgp %u", bgp->as);
17425
17426 if (bgp->name)
17427 vty_out(vty, " %s %s",
17428 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
17429 ? "view" : "vrf", bgp->name);
17430 vty_out(vty, "\n");
17431
17432 /* BGP fast-external-failover. */
17433 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
17434 vty_out(vty, " no bgp fast-external-failover\n");
17435
17436 /* BGP router ID. */
17437 if (bgp->router_id_static.s_addr != INADDR_ANY)
17438 vty_out(vty, " bgp router-id %pI4\n",
17439 &bgp->router_id_static);
17440
17441 /* Suppress fib pending */
17442 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_FIB_PENDING))
17443 vty_out(vty, " bgp suppress-fib-pending\n");
17444
17445 /* BGP log-neighbor-changes. */
17446 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
17447 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
17448 vty_out(vty, " %sbgp log-neighbor-changes\n",
17449 CHECK_FLAG(bgp->flags,
17450 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
17451 ? ""
17452 : "no ");
17453
17454 /* BGP configuration. */
17455 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
17456 vty_out(vty, " bgp always-compare-med\n");
17457
17458 /* RFC8212 default eBGP policy. */
17459 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
17460 != SAVE_BGP_EBGP_REQUIRES_POLICY)
17461 vty_out(vty, " %sbgp ebgp-requires-policy\n",
17462 CHECK_FLAG(bgp->flags,
17463 BGP_FLAG_EBGP_REQUIRES_POLICY)
17464 ? ""
17465 : "no ");
17466
17467 /* draft-ietf-idr-deprecate-as-set-confed-set */
17468 if (bgp->reject_as_sets)
17469 vty_out(vty, " bgp reject-as-sets\n");
17470
17471 /* Suppress duplicate updates if the route actually not changed
17472 */
17473 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES)
17474 != SAVE_BGP_SUPPRESS_DUPLICATES)
17475 vty_out(vty, " %sbgp suppress-duplicates\n",
17476 CHECK_FLAG(bgp->flags,
17477 BGP_FLAG_SUPPRESS_DUPLICATES)
17478 ? ""
17479 : "no ");
17480
17481 /* BGP default ipv4-unicast. */
17482 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4))
17483 vty_out(vty, " no bgp default ipv4-unicast\n");
17484
17485 /* BGP default ipv6-unicast. */
17486 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DEFAULT_IPV6))
17487 vty_out(vty, " bgp default ipv6-unicast\n");
17488
17489 /* BGP default local-preference. */
17490 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
17491 vty_out(vty, " bgp default local-preference %u\n",
17492 bgp->default_local_pref);
17493
17494 /* BGP default show-hostname */
17495 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
17496 != SAVE_BGP_SHOW_HOSTNAME)
17497 vty_out(vty, " %sbgp default show-hostname\n",
17498 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
17499 ? ""
17500 : "no ");
17501
17502 /* BGP default show-nexthop-hostname */
17503 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17504 != SAVE_BGP_SHOW_HOSTNAME)
17505 vty_out(vty, " %sbgp default show-nexthop-hostname\n",
17506 CHECK_FLAG(bgp->flags,
17507 BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17508 ? ""
17509 : "no ");
17510
17511 /* BGP default subgroup-pkt-queue-max. */
17512 if (bgp->default_subgroup_pkt_queue_max
17513 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
17514 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
17515 bgp->default_subgroup_pkt_queue_max);
17516
17517 /* BGP client-to-client reflection. */
17518 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
17519 vty_out(vty, " no bgp client-to-client reflection\n");
17520
17521 /* BGP cluster ID. */
17522 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
17523 vty_out(vty, " bgp cluster-id %pI4\n",
17524 &bgp->cluster_id);
17525
17526 /* Disable ebgp connected nexthop check */
17527 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
17528 vty_out(vty,
17529 " bgp disable-ebgp-connected-route-check\n");
17530
17531 /* Confederation identifier*/
17532 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
17533 vty_out(vty, " bgp confederation identifier %u\n",
17534 bgp->confed_id);
17535
17536 /* Confederation peer */
17537 if (bgp->confed_peers_cnt > 0) {
17538 int i;
17539
17540 vty_out(vty, " bgp confederation peers");
17541
17542 for (i = 0; i < bgp->confed_peers_cnt; i++)
17543 vty_out(vty, " %u", bgp->confed_peers[i]);
17544
17545 vty_out(vty, "\n");
17546 }
17547
17548 /* BGP deterministic-med. */
17549 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
17550 != SAVE_BGP_DETERMINISTIC_MED)
17551 vty_out(vty, " %sbgp deterministic-med\n",
17552 CHECK_FLAG(bgp->flags,
17553 BGP_FLAG_DETERMINISTIC_MED)
17554 ? ""
17555 : "no ");
17556
17557 /* BGP update-delay. */
17558 bgp_config_write_update_delay(vty, bgp);
17559
17560 if (bgp->v_maxmed_onstartup
17561 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
17562 vty_out(vty, " bgp max-med on-startup %u",
17563 bgp->v_maxmed_onstartup);
17564 if (bgp->maxmed_onstartup_value
17565 != BGP_MAXMED_VALUE_DEFAULT)
17566 vty_out(vty, " %u",
17567 bgp->maxmed_onstartup_value);
17568 vty_out(vty, "\n");
17569 }
17570 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
17571 vty_out(vty, " bgp max-med administrative");
17572 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
17573 vty_out(vty, " %u", bgp->maxmed_admin_value);
17574 vty_out(vty, "\n");
17575 }
17576
17577 /* write quanta */
17578 bgp_config_write_wpkt_quanta(vty, bgp);
17579 /* read quanta */
17580 bgp_config_write_rpkt_quanta(vty, bgp);
17581
17582 /* coalesce time */
17583 bgp_config_write_coalesce_time(vty, bgp);
17584
17585 /* BGP per-instance graceful-shutdown */
17586 /* BGP-wide settings and per-instance settings are mutually
17587 * exclusive.
17588 */
17589 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17590 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
17591 vty_out(vty, " bgp graceful-shutdown\n");
17592
17593 /* BGP graceful-restart. */
17594 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
17595 vty_out(vty,
17596 " bgp graceful-restart stalepath-time %u\n",
17597 bgp->stalepath_time);
17598
17599 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
17600 vty_out(vty, " bgp graceful-restart restart-time %u\n",
17601 bgp->restart_time);
17602
17603 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
17604 vty_out(vty,
17605 " bgp graceful-restart select-defer-time %u\n",
17606 bgp->select_defer_time);
17607
17608 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
17609 vty_out(vty, " bgp graceful-restart\n");
17610
17611 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
17612 vty_out(vty, " bgp graceful-restart-disable\n");
17613
17614 /* BGP graceful-restart Preserve State F bit. */
17615 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
17616 vty_out(vty,
17617 " bgp graceful-restart preserve-fw-state\n");
17618
17619 /* Stale timer for RIB */
17620 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
17621 vty_out(vty,
17622 " bgp graceful-restart rib-stale-time %u\n",
17623 bgp->rib_stale_time);
17624
17625 /* BGP bestpath method. */
17626 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
17627 vty_out(vty, " bgp bestpath as-path ignore\n");
17628 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
17629 vty_out(vty, " bgp bestpath as-path confed\n");
17630
17631 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
17632 if (CHECK_FLAG(bgp->flags,
17633 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
17634 vty_out(vty,
17635 " bgp bestpath as-path multipath-relax as-set\n");
17636 } else {
17637 vty_out(vty,
17638 " bgp bestpath as-path multipath-relax\n");
17639 }
17640 }
17641
17642 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
17643 vty_out(vty,
17644 " bgp route-reflector allow-outbound-policy\n");
17645 }
17646 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
17647 vty_out(vty, " bgp bestpath compare-routerid\n");
17648 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
17649 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
17650 vty_out(vty, " bgp bestpath med");
17651 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
17652 vty_out(vty, " confed");
17653 if (CHECK_FLAG(bgp->flags,
17654 BGP_FLAG_MED_MISSING_AS_WORST))
17655 vty_out(vty, " missing-as-worst");
17656 vty_out(vty, "\n");
17657 }
17658
17659 /* Link bandwidth handling. */
17660 if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW)
17661 vty_out(vty, " bgp bestpath bandwidth ignore\n");
17662 else if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
17663 vty_out(vty, " bgp bestpath bandwidth skip-missing\n");
17664 else if (bgp->lb_handling == BGP_LINK_BW_DEFWT_4_MISSING)
17665 vty_out(vty, " bgp bestpath bandwidth default-weight-for-missing\n");
17666
17667 /* BGP network import check. */
17668 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
17669 != SAVE_BGP_IMPORT_CHECK)
17670 vty_out(vty, " %sbgp network import-check\n",
17671 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
17672 ? ""
17673 : "no ");
17674
17675 /* BGP timers configuration. */
17676 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
17677 && bgp->default_holdtime != SAVE_BGP_HOLDTIME)
17678 vty_out(vty, " timers bgp %u %u\n",
17679 bgp->default_keepalive, bgp->default_holdtime);
17680
17681 /* peer-group */
17682 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
17683 bgp_config_write_peer_global(vty, bgp, group->conf);
17684 }
17685
17686 /* Normal neighbor configuration. */
17687 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17688 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17689 bgp_config_write_peer_global(vty, bgp, peer);
17690 }
17691
17692 /* listen range and limit for dynamic BGP neighbors */
17693 bgp_config_write_listen(vty, bgp);
17694
17695 /*
17696 * BGP default autoshutdown neighbors
17697 *
17698 * This must be placed after any peer and peer-group
17699 * configuration, to avoid setting all peers to shutdown after
17700 * a daemon restart, which is undesired behavior. (see #2286)
17701 */
17702 if (bgp->autoshutdown)
17703 vty_out(vty, " bgp default shutdown\n");
17704
17705 /* BGP instance administrative shutdown */
17706 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN))
17707 vty_out(vty, " bgp shutdown\n");
17708
17709 /* IPv4 unicast configuration. */
17710 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
17711
17712 /* IPv4 multicast configuration. */
17713 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
17714
17715 /* IPv4 labeled-unicast configuration. */
17716 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
17717
17718 /* IPv4 VPN configuration. */
17719 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
17720
17721 /* ENCAPv4 configuration. */
17722 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
17723
17724 /* FLOWSPEC v4 configuration. */
17725 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
17726
17727 /* IPv6 unicast configuration. */
17728 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
17729
17730 /* IPv6 multicast configuration. */
17731 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
17732
17733 /* IPv6 labeled-unicast configuration. */
17734 bgp_config_write_family(vty, bgp, AFI_IP6,
17735 SAFI_LABELED_UNICAST);
17736
17737 /* IPv6 VPN configuration. */
17738 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
17739
17740 /* ENCAPv6 configuration. */
17741 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
17742
17743 /* FLOWSPEC v6 configuration. */
17744 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
17745
17746 /* EVPN configuration. */
17747 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
17748
17749 hook_call(bgp_inst_config_write, bgp, vty);
17750
17751 #ifdef ENABLE_BGP_VNC
17752 bgp_rfapi_cfg_write(vty, bgp);
17753 #endif
17754
17755 vty_out(vty, "!\n");
17756 }
17757 return 0;
17758 }
17759
17760
17761 /* BGP node structure. */
17762 static struct cmd_node bgp_node = {
17763 .name = "bgp",
17764 .node = BGP_NODE,
17765 .parent_node = CONFIG_NODE,
17766 .prompt = "%s(config-router)# ",
17767 .config_write = bgp_config_write,
17768 };
17769
17770 static struct cmd_node bgp_ipv4_unicast_node = {
17771 .name = "bgp ipv4 unicast",
17772 .node = BGP_IPV4_NODE,
17773 .parent_node = BGP_NODE,
17774 .prompt = "%s(config-router-af)# ",
17775 };
17776
17777 static struct cmd_node bgp_ipv4_multicast_node = {
17778 .name = "bgp ipv4 multicast",
17779 .node = BGP_IPV4M_NODE,
17780 .parent_node = BGP_NODE,
17781 .prompt = "%s(config-router-af)# ",
17782 };
17783
17784 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
17785 .name = "bgp ipv4 labeled unicast",
17786 .node = BGP_IPV4L_NODE,
17787 .parent_node = BGP_NODE,
17788 .prompt = "%s(config-router-af)# ",
17789 };
17790
17791 static struct cmd_node bgp_ipv6_unicast_node = {
17792 .name = "bgp ipv6",
17793 .node = BGP_IPV6_NODE,
17794 .parent_node = BGP_NODE,
17795 .prompt = "%s(config-router-af)# ",
17796 };
17797
17798 static struct cmd_node bgp_ipv6_multicast_node = {
17799 .name = "bgp ipv6 multicast",
17800 .node = BGP_IPV6M_NODE,
17801 .parent_node = BGP_NODE,
17802 .prompt = "%s(config-router-af)# ",
17803 };
17804
17805 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
17806 .name = "bgp ipv6 labeled unicast",
17807 .node = BGP_IPV6L_NODE,
17808 .parent_node = BGP_NODE,
17809 .prompt = "%s(config-router-af)# ",
17810 };
17811
17812 static struct cmd_node bgp_vpnv4_node = {
17813 .name = "bgp vpnv4",
17814 .node = BGP_VPNV4_NODE,
17815 .parent_node = BGP_NODE,
17816 .prompt = "%s(config-router-af)# ",
17817 };
17818
17819 static struct cmd_node bgp_vpnv6_node = {
17820 .name = "bgp vpnv6",
17821 .node = BGP_VPNV6_NODE,
17822 .parent_node = BGP_NODE,
17823 .prompt = "%s(config-router-af-vpnv6)# ",
17824 };
17825
17826 static struct cmd_node bgp_evpn_node = {
17827 .name = "bgp evpn",
17828 .node = BGP_EVPN_NODE,
17829 .parent_node = BGP_NODE,
17830 .prompt = "%s(config-router-evpn)# ",
17831 };
17832
17833 static struct cmd_node bgp_evpn_vni_node = {
17834 .name = "bgp evpn vni",
17835 .node = BGP_EVPN_VNI_NODE,
17836 .parent_node = BGP_EVPN_NODE,
17837 .prompt = "%s(config-router-af-vni)# ",
17838 };
17839
17840 static struct cmd_node bgp_flowspecv4_node = {
17841 .name = "bgp ipv4 flowspec",
17842 .node = BGP_FLOWSPECV4_NODE,
17843 .parent_node = BGP_NODE,
17844 .prompt = "%s(config-router-af)# ",
17845 };
17846
17847 static struct cmd_node bgp_flowspecv6_node = {
17848 .name = "bgp ipv6 flowspec",
17849 .node = BGP_FLOWSPECV6_NODE,
17850 .parent_node = BGP_NODE,
17851 .prompt = "%s(config-router-af-vpnv6)# ",
17852 };
17853
17854 static void community_list_vty(void);
17855
17856 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
17857 {
17858 struct bgp *bgp;
17859 struct peer *peer;
17860 struct listnode *lnbgp, *lnpeer;
17861
17862 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
17863 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
17864 /* only provide suggestions on the appropriate input
17865 * token type,
17866 * they'll otherwise show up multiple times */
17867 enum cmd_token_type match_type;
17868 char *name = peer->host;
17869
17870 if (peer->conf_if) {
17871 match_type = VARIABLE_TKN;
17872 name = peer->conf_if;
17873 } else if (strchr(peer->host, ':'))
17874 match_type = IPV6_TKN;
17875 else
17876 match_type = IPV4_TKN;
17877
17878 if (token->type != match_type)
17879 continue;
17880
17881 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
17882 }
17883 }
17884 }
17885
17886 static const struct cmd_variable_handler bgp_var_neighbor[] = {
17887 {.varname = "neighbor", .completions = bgp_ac_neighbor},
17888 {.varname = "neighbors", .completions = bgp_ac_neighbor},
17889 {.varname = "peer", .completions = bgp_ac_neighbor},
17890 {.completions = NULL}};
17891
17892 static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
17893 {
17894 struct bgp *bgp;
17895 struct peer_group *group;
17896 struct listnode *lnbgp, *lnpeer;
17897
17898 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
17899 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
17900 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
17901 group->name));
17902 }
17903 }
17904
17905 static const struct cmd_variable_handler bgp_var_peergroup[] = {
17906 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
17907 {.completions = NULL} };
17908
17909 void bgp_vty_init(void)
17910 {
17911 cmd_variable_handler_register(bgp_var_neighbor);
17912 cmd_variable_handler_register(bgp_var_peergroup);
17913
17914 /* Install bgp top node. */
17915 install_node(&bgp_node);
17916 install_node(&bgp_ipv4_unicast_node);
17917 install_node(&bgp_ipv4_multicast_node);
17918 install_node(&bgp_ipv4_labeled_unicast_node);
17919 install_node(&bgp_ipv6_unicast_node);
17920 install_node(&bgp_ipv6_multicast_node);
17921 install_node(&bgp_ipv6_labeled_unicast_node);
17922 install_node(&bgp_vpnv4_node);
17923 install_node(&bgp_vpnv6_node);
17924 install_node(&bgp_evpn_node);
17925 install_node(&bgp_evpn_vni_node);
17926 install_node(&bgp_flowspecv4_node);
17927 install_node(&bgp_flowspecv6_node);
17928
17929 /* Install default VTY commands to new nodes. */
17930 install_default(BGP_NODE);
17931 install_default(BGP_IPV4_NODE);
17932 install_default(BGP_IPV4M_NODE);
17933 install_default(BGP_IPV4L_NODE);
17934 install_default(BGP_IPV6_NODE);
17935 install_default(BGP_IPV6M_NODE);
17936 install_default(BGP_IPV6L_NODE);
17937 install_default(BGP_VPNV4_NODE);
17938 install_default(BGP_VPNV6_NODE);
17939 install_default(BGP_FLOWSPECV4_NODE);
17940 install_default(BGP_FLOWSPECV6_NODE);
17941 install_default(BGP_EVPN_NODE);
17942 install_default(BGP_EVPN_VNI_NODE);
17943
17944 /* "bgp local-mac" hidden commands. */
17945 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
17946 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
17947
17948 /* "bgp suppress-fib-pending" global */
17949 install_element(CONFIG_NODE, &bgp_global_suppress_fib_pending_cmd);
17950
17951 /* bgp route-map delay-timer commands. */
17952 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
17953 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
17954
17955 /* global bgp update-delay command */
17956 install_element(CONFIG_NODE, &bgp_global_update_delay_cmd);
17957 install_element(CONFIG_NODE, &no_bgp_global_update_delay_cmd);
17958
17959 /* global bgp graceful-shutdown command */
17960 install_element(CONFIG_NODE, &bgp_graceful_shutdown_cmd);
17961 install_element(CONFIG_NODE, &no_bgp_graceful_shutdown_cmd);
17962
17963 /* Dummy commands (Currently not supported) */
17964 install_element(BGP_NODE, &no_synchronization_cmd);
17965 install_element(BGP_NODE, &no_auto_summary_cmd);
17966
17967 /* "router bgp" commands. */
17968 install_element(CONFIG_NODE, &router_bgp_cmd);
17969
17970 /* "no router bgp" commands. */
17971 install_element(CONFIG_NODE, &no_router_bgp_cmd);
17972
17973 /* "bgp router-id" commands. */
17974 install_element(BGP_NODE, &bgp_router_id_cmd);
17975 install_element(BGP_NODE, &no_bgp_router_id_cmd);
17976
17977 /* "bgp suppress-fib-pending" command */
17978 install_element(BGP_NODE, &bgp_suppress_fib_pending_cmd);
17979
17980 /* "bgp cluster-id" commands. */
17981 install_element(BGP_NODE, &bgp_cluster_id_cmd);
17982 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
17983
17984 /* "bgp no-rib" commands. */
17985 install_element(CONFIG_NODE, &bgp_norib_cmd);
17986 install_element(CONFIG_NODE, &no_bgp_norib_cmd);
17987
17988 install_element(CONFIG_NODE, &no_bgp_send_extra_data_cmd);
17989
17990 /* "bgp confederation" commands. */
17991 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
17992 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
17993
17994 /* "bgp confederation peers" commands. */
17995 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
17996 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
17997
17998 /* bgp max-med command */
17999 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
18000 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
18001 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
18002 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
18003 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
18004
18005 /* bgp disable-ebgp-connected-nh-check */
18006 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
18007 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
18008
18009 /* bgp update-delay command */
18010 install_element(BGP_NODE, &bgp_update_delay_cmd);
18011 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
18012
18013 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
18014 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
18015
18016 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
18017 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
18018
18019 /* "maximum-paths" commands. */
18020 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
18021 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
18022 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
18023 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
18024 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
18025 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
18026 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
18027 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
18028 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
18029 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
18030 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18031 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
18032 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
18033 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18034 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
18035
18036 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_cmd);
18037 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_cmd);
18038 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cmd);
18039 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18040 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_ibgp_cmd);
18041 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
18042 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
18043 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
18044 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18045 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
18046
18047 /* "timers bgp" commands. */
18048 install_element(BGP_NODE, &bgp_timers_cmd);
18049 install_element(BGP_NODE, &no_bgp_timers_cmd);
18050
18051 /* route-map delay-timer commands - per instance for backwards compat.
18052 */
18053 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
18054 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
18055
18056 /* "bgp client-to-client reflection" commands */
18057 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
18058 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
18059
18060 /* "bgp always-compare-med" commands */
18061 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
18062 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
18063
18064 /* bgp ebgp-requires-policy */
18065 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
18066 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
18067
18068 /* bgp suppress-duplicates */
18069 install_element(BGP_NODE, &bgp_suppress_duplicates_cmd);
18070 install_element(BGP_NODE, &no_bgp_suppress_duplicates_cmd);
18071
18072 /* bgp reject-as-sets */
18073 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
18074 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
18075
18076 /* "bgp deterministic-med" commands */
18077 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
18078 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
18079
18080 /* "bgp graceful-restart" command */
18081 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
18082 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
18083
18084 /* "bgp graceful-restart-disable" command */
18085 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
18086 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
18087
18088 /* "neighbor a:b:c:d graceful-restart" command */
18089 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
18090 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
18091
18092 /* "neighbor a:b:c:d graceful-restart-disable" command */
18093 install_element(BGP_NODE,
18094 &bgp_neighbor_graceful_restart_disable_set_cmd);
18095 install_element(BGP_NODE,
18096 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
18097
18098 /* "neighbor a:b:c:d graceful-restart-helper" command */
18099 install_element(BGP_NODE,
18100 &bgp_neighbor_graceful_restart_helper_set_cmd);
18101 install_element(BGP_NODE,
18102 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
18103
18104 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
18105 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
18106 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
18107 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
18108 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
18109 install_element(BGP_NODE,
18110 &no_bgp_graceful_restart_select_defer_time_cmd);
18111 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
18112 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
18113
18114 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
18115 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
18116 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
18117 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
18118
18119 /* "bgp graceful-shutdown" commands */
18120 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
18121 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
18122
18123 /* "bgp fast-external-failover" commands */
18124 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
18125 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
18126
18127 /* "bgp bestpath compare-routerid" commands */
18128 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
18129 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
18130
18131 /* "bgp bestpath as-path ignore" commands */
18132 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
18133 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
18134
18135 /* "bgp bestpath as-path confed" commands */
18136 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
18137 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
18138
18139 /* "bgp bestpath as-path multipath-relax" commands */
18140 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
18141 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
18142
18143 /* "bgp log-neighbor-changes" commands */
18144 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
18145 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
18146
18147 /* "bgp bestpath med" commands */
18148 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
18149 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
18150
18151 /* "bgp bestpath bandwidth" commands */
18152 install_element(BGP_NODE, &bgp_bestpath_bw_cmd);
18153 install_element(BGP_NODE, &no_bgp_bestpath_bw_cmd);
18154
18155 /* "no bgp default ipv4-unicast" commands. */
18156 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
18157 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
18158
18159 /* "no bgp default ipv6-unicast" commands. */
18160 install_element(BGP_NODE, &no_bgp_default_ipv6_unicast_cmd);
18161 install_element(BGP_NODE, &bgp_default_ipv6_unicast_cmd);
18162
18163 /* "bgp network import-check" commands. */
18164 install_element(BGP_NODE, &bgp_network_import_check_cmd);
18165 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
18166 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
18167
18168 /* "bgp default local-preference" commands. */
18169 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
18170 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
18171
18172 /* bgp default show-hostname */
18173 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
18174 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
18175
18176 /* bgp default show-nexthop-hostname */
18177 install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
18178 install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
18179
18180 /* "bgp default subgroup-pkt-queue-max" commands. */
18181 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
18182 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
18183
18184 /* bgp ibgp-allow-policy-mods command */
18185 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
18186 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
18187
18188 /* "bgp listen limit" commands. */
18189 install_element(BGP_NODE, &bgp_listen_limit_cmd);
18190 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
18191
18192 /* "bgp listen range" commands. */
18193 install_element(BGP_NODE, &bgp_listen_range_cmd);
18194 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
18195
18196 /* "bgp default shutdown" command */
18197 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
18198
18199 /* "bgp shutdown" commands */
18200 install_element(BGP_NODE, &bgp_shutdown_cmd);
18201 install_element(BGP_NODE, &bgp_shutdown_msg_cmd);
18202 install_element(BGP_NODE, &no_bgp_shutdown_cmd);
18203 install_element(BGP_NODE, &no_bgp_shutdown_msg_cmd);
18204
18205 /* "neighbor remote-as" commands. */
18206 install_element(BGP_NODE, &neighbor_remote_as_cmd);
18207 install_element(BGP_NODE, &neighbor_interface_config_cmd);
18208 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
18209 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
18210 install_element(BGP_NODE,
18211 &neighbor_interface_v6only_config_remote_as_cmd);
18212 install_element(BGP_NODE, &no_neighbor_cmd);
18213 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
18214
18215 /* "neighbor peer-group" commands. */
18216 install_element(BGP_NODE, &neighbor_peer_group_cmd);
18217 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
18218 install_element(BGP_NODE,
18219 &no_neighbor_interface_peer_group_remote_as_cmd);
18220
18221 /* "neighbor local-as" commands. */
18222 install_element(BGP_NODE, &neighbor_local_as_cmd);
18223 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
18224 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
18225 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
18226
18227 /* "neighbor solo" commands. */
18228 install_element(BGP_NODE, &neighbor_solo_cmd);
18229 install_element(BGP_NODE, &no_neighbor_solo_cmd);
18230
18231 /* "neighbor password" commands. */
18232 install_element(BGP_NODE, &neighbor_password_cmd);
18233 install_element(BGP_NODE, &no_neighbor_password_cmd);
18234
18235 /* "neighbor activate" commands. */
18236 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
18237 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
18238 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
18239 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
18240 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
18241 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
18242 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
18243 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
18244 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
18245 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
18246 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
18247 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
18248
18249 /* "no neighbor activate" commands. */
18250 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
18251 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
18252 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
18253 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
18254 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
18255 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
18256 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
18257 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
18258 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
18259 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
18260 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
18261 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
18262
18263 /* "neighbor peer-group" set commands. */
18264 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
18265 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
18266 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
18267 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
18268 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
18269 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
18270 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
18271 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
18272 install_element(BGP_FLOWSPECV4_NODE,
18273 &neighbor_set_peer_group_hidden_cmd);
18274 install_element(BGP_FLOWSPECV6_NODE,
18275 &neighbor_set_peer_group_hidden_cmd);
18276
18277 /* "no neighbor peer-group unset" commands. */
18278 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
18279 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18280 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18281 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18282 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18283 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18284 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18285 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18286 install_element(BGP_FLOWSPECV4_NODE,
18287 &no_neighbor_set_peer_group_hidden_cmd);
18288 install_element(BGP_FLOWSPECV6_NODE,
18289 &no_neighbor_set_peer_group_hidden_cmd);
18290
18291 /* "neighbor softreconfiguration inbound" commands.*/
18292 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
18293 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
18294 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
18295 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
18296 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
18297 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
18298 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
18299 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
18300 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
18301 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
18302 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
18303 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
18304 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
18305 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
18306 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
18307 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
18308 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
18309 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
18310 install_element(BGP_FLOWSPECV4_NODE,
18311 &neighbor_soft_reconfiguration_cmd);
18312 install_element(BGP_FLOWSPECV4_NODE,
18313 &no_neighbor_soft_reconfiguration_cmd);
18314 install_element(BGP_FLOWSPECV6_NODE,
18315 &neighbor_soft_reconfiguration_cmd);
18316 install_element(BGP_FLOWSPECV6_NODE,
18317 &no_neighbor_soft_reconfiguration_cmd);
18318 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
18319 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
18320
18321 /* "neighbor attribute-unchanged" commands. */
18322 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
18323 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
18324 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
18325 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
18326 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
18327 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
18328 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
18329 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
18330 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
18331 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
18332 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
18333 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
18334 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
18335 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
18336 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
18337 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
18338 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
18339 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
18340
18341 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
18342 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
18343
18344 install_element(BGP_FLOWSPECV4_NODE, &neighbor_attr_unchanged_cmd);
18345 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_attr_unchanged_cmd);
18346 install_element(BGP_FLOWSPECV6_NODE, &neighbor_attr_unchanged_cmd);
18347 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_attr_unchanged_cmd);
18348
18349 /* "nexthop-local unchanged" commands */
18350 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
18351 install_element(BGP_IPV6_NODE,
18352 &no_neighbor_nexthop_local_unchanged_cmd);
18353
18354 /* "neighbor next-hop-self" commands. */
18355 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
18356 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
18357 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
18358 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
18359 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
18360 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
18361 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
18362 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
18363 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
18364 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
18365 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
18366 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
18367 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
18368 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
18369 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
18370 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
18371 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
18372 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
18373 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
18374 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
18375
18376 /* "neighbor next-hop-self force" commands. */
18377 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
18378 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
18379 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18380 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
18381 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
18382 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
18383 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18384 install_element(BGP_IPV4_NODE,
18385 &no_neighbor_nexthop_self_all_hidden_cmd);
18386 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
18387 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
18388 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18389 install_element(BGP_IPV4M_NODE,
18390 &no_neighbor_nexthop_self_all_hidden_cmd);
18391 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
18392 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
18393 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18394 install_element(BGP_IPV4L_NODE,
18395 &no_neighbor_nexthop_self_all_hidden_cmd);
18396 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
18397 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
18398 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18399 install_element(BGP_IPV6_NODE,
18400 &no_neighbor_nexthop_self_all_hidden_cmd);
18401 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
18402 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
18403 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18404 install_element(BGP_IPV6M_NODE,
18405 &no_neighbor_nexthop_self_all_hidden_cmd);
18406 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
18407 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
18408 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18409 install_element(BGP_IPV6L_NODE,
18410 &no_neighbor_nexthop_self_all_hidden_cmd);
18411 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
18412 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
18413 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18414 install_element(BGP_VPNV4_NODE,
18415 &no_neighbor_nexthop_self_all_hidden_cmd);
18416 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
18417 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
18418 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18419 install_element(BGP_VPNV6_NODE,
18420 &no_neighbor_nexthop_self_all_hidden_cmd);
18421 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_force_cmd);
18422 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_force_cmd);
18423
18424 /* "neighbor as-override" commands. */
18425 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
18426 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
18427 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
18428 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
18429 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
18430 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
18431 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
18432 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
18433 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
18434 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
18435 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
18436 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
18437 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
18438 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
18439 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
18440 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
18441 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
18442 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
18443
18444 /* "neighbor remove-private-AS" commands. */
18445 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
18446 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
18447 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
18448 install_element(BGP_NODE,
18449 &no_neighbor_remove_private_as_all_hidden_cmd);
18450 install_element(BGP_NODE,
18451 &neighbor_remove_private_as_replace_as_hidden_cmd);
18452 install_element(BGP_NODE,
18453 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
18454 install_element(BGP_NODE,
18455 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
18456 install_element(
18457 BGP_NODE,
18458 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
18459 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
18460 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
18461 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
18462 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18463 install_element(BGP_IPV4_NODE,
18464 &neighbor_remove_private_as_replace_as_cmd);
18465 install_element(BGP_IPV4_NODE,
18466 &no_neighbor_remove_private_as_replace_as_cmd);
18467 install_element(BGP_IPV4_NODE,
18468 &neighbor_remove_private_as_all_replace_as_cmd);
18469 install_element(BGP_IPV4_NODE,
18470 &no_neighbor_remove_private_as_all_replace_as_cmd);
18471 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
18472 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
18473 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
18474 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
18475 install_element(BGP_IPV4M_NODE,
18476 &neighbor_remove_private_as_replace_as_cmd);
18477 install_element(BGP_IPV4M_NODE,
18478 &no_neighbor_remove_private_as_replace_as_cmd);
18479 install_element(BGP_IPV4M_NODE,
18480 &neighbor_remove_private_as_all_replace_as_cmd);
18481 install_element(BGP_IPV4M_NODE,
18482 &no_neighbor_remove_private_as_all_replace_as_cmd);
18483 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
18484 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
18485 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
18486 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
18487 install_element(BGP_IPV4L_NODE,
18488 &neighbor_remove_private_as_replace_as_cmd);
18489 install_element(BGP_IPV4L_NODE,
18490 &no_neighbor_remove_private_as_replace_as_cmd);
18491 install_element(BGP_IPV4L_NODE,
18492 &neighbor_remove_private_as_all_replace_as_cmd);
18493 install_element(BGP_IPV4L_NODE,
18494 &no_neighbor_remove_private_as_all_replace_as_cmd);
18495 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
18496 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
18497 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
18498 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18499 install_element(BGP_IPV6_NODE,
18500 &neighbor_remove_private_as_replace_as_cmd);
18501 install_element(BGP_IPV6_NODE,
18502 &no_neighbor_remove_private_as_replace_as_cmd);
18503 install_element(BGP_IPV6_NODE,
18504 &neighbor_remove_private_as_all_replace_as_cmd);
18505 install_element(BGP_IPV6_NODE,
18506 &no_neighbor_remove_private_as_all_replace_as_cmd);
18507 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
18508 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
18509 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
18510 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
18511 install_element(BGP_IPV6M_NODE,
18512 &neighbor_remove_private_as_replace_as_cmd);
18513 install_element(BGP_IPV6M_NODE,
18514 &no_neighbor_remove_private_as_replace_as_cmd);
18515 install_element(BGP_IPV6M_NODE,
18516 &neighbor_remove_private_as_all_replace_as_cmd);
18517 install_element(BGP_IPV6M_NODE,
18518 &no_neighbor_remove_private_as_all_replace_as_cmd);
18519 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
18520 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
18521 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
18522 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
18523 install_element(BGP_IPV6L_NODE,
18524 &neighbor_remove_private_as_replace_as_cmd);
18525 install_element(BGP_IPV6L_NODE,
18526 &no_neighbor_remove_private_as_replace_as_cmd);
18527 install_element(BGP_IPV6L_NODE,
18528 &neighbor_remove_private_as_all_replace_as_cmd);
18529 install_element(BGP_IPV6L_NODE,
18530 &no_neighbor_remove_private_as_all_replace_as_cmd);
18531 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
18532 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
18533 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
18534 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18535 install_element(BGP_VPNV4_NODE,
18536 &neighbor_remove_private_as_replace_as_cmd);
18537 install_element(BGP_VPNV4_NODE,
18538 &no_neighbor_remove_private_as_replace_as_cmd);
18539 install_element(BGP_VPNV4_NODE,
18540 &neighbor_remove_private_as_all_replace_as_cmd);
18541 install_element(BGP_VPNV4_NODE,
18542 &no_neighbor_remove_private_as_all_replace_as_cmd);
18543 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
18544 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
18545 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
18546 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18547 install_element(BGP_VPNV6_NODE,
18548 &neighbor_remove_private_as_replace_as_cmd);
18549 install_element(BGP_VPNV6_NODE,
18550 &no_neighbor_remove_private_as_replace_as_cmd);
18551 install_element(BGP_VPNV6_NODE,
18552 &neighbor_remove_private_as_all_replace_as_cmd);
18553 install_element(BGP_VPNV6_NODE,
18554 &no_neighbor_remove_private_as_all_replace_as_cmd);
18555
18556 /* "neighbor send-community" commands.*/
18557 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
18558 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
18559 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
18560 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
18561 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
18562 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
18563 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
18564 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
18565 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
18566 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
18567 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
18568 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
18569 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
18570 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
18571 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
18572 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
18573 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
18574 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
18575 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
18576 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
18577 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
18578 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
18579 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
18580 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
18581 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
18582 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
18583 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
18584 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
18585 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
18586 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
18587 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
18588 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
18589 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
18590 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
18591 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
18592 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
18593
18594 /* "neighbor route-reflector" commands.*/
18595 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
18596 install_element(BGP_NODE,
18597 &no_neighbor_route_reflector_client_hidden_cmd);
18598 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
18599 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
18600 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
18601 install_element(BGP_IPV4M_NODE,
18602 &no_neighbor_route_reflector_client_cmd);
18603 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
18604 install_element(BGP_IPV4L_NODE,
18605 &no_neighbor_route_reflector_client_cmd);
18606 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
18607 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
18608 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
18609 install_element(BGP_IPV6M_NODE,
18610 &no_neighbor_route_reflector_client_cmd);
18611 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
18612 install_element(BGP_IPV6L_NODE,
18613 &no_neighbor_route_reflector_client_cmd);
18614 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
18615 install_element(BGP_VPNV4_NODE,
18616 &no_neighbor_route_reflector_client_cmd);
18617 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
18618 install_element(BGP_VPNV6_NODE,
18619 &no_neighbor_route_reflector_client_cmd);
18620 install_element(BGP_FLOWSPECV4_NODE,
18621 &neighbor_route_reflector_client_cmd);
18622 install_element(BGP_FLOWSPECV4_NODE,
18623 &no_neighbor_route_reflector_client_cmd);
18624 install_element(BGP_FLOWSPECV6_NODE,
18625 &neighbor_route_reflector_client_cmd);
18626 install_element(BGP_FLOWSPECV6_NODE,
18627 &no_neighbor_route_reflector_client_cmd);
18628 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
18629 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
18630
18631 /* "neighbor route-server" commands.*/
18632 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
18633 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
18634 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
18635 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
18636 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
18637 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
18638 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
18639 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
18640 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
18641 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
18642 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
18643 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
18644 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
18645 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
18646 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
18647 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
18648 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
18649 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
18650 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
18651 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
18652 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
18653 install_element(BGP_FLOWSPECV4_NODE,
18654 &no_neighbor_route_server_client_cmd);
18655 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
18656 install_element(BGP_FLOWSPECV6_NODE,
18657 &no_neighbor_route_server_client_cmd);
18658
18659 /* "neighbor addpath-tx-all-paths" commands.*/
18660 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
18661 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
18662 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
18663 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18664 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
18665 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18666 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
18667 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18668 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
18669 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18670 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
18671 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18672 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
18673 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18674 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
18675 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18676 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
18677 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18678
18679 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
18680 install_element(BGP_NODE,
18681 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
18682 install_element(BGP_NODE,
18683 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
18684 install_element(BGP_IPV4_NODE,
18685 &neighbor_addpath_tx_bestpath_per_as_cmd);
18686 install_element(BGP_IPV4_NODE,
18687 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18688 install_element(BGP_IPV4M_NODE,
18689 &neighbor_addpath_tx_bestpath_per_as_cmd);
18690 install_element(BGP_IPV4M_NODE,
18691 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18692 install_element(BGP_IPV4L_NODE,
18693 &neighbor_addpath_tx_bestpath_per_as_cmd);
18694 install_element(BGP_IPV4L_NODE,
18695 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18696 install_element(BGP_IPV6_NODE,
18697 &neighbor_addpath_tx_bestpath_per_as_cmd);
18698 install_element(BGP_IPV6_NODE,
18699 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18700 install_element(BGP_IPV6M_NODE,
18701 &neighbor_addpath_tx_bestpath_per_as_cmd);
18702 install_element(BGP_IPV6M_NODE,
18703 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18704 install_element(BGP_IPV6L_NODE,
18705 &neighbor_addpath_tx_bestpath_per_as_cmd);
18706 install_element(BGP_IPV6L_NODE,
18707 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18708 install_element(BGP_VPNV4_NODE,
18709 &neighbor_addpath_tx_bestpath_per_as_cmd);
18710 install_element(BGP_VPNV4_NODE,
18711 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18712 install_element(BGP_VPNV6_NODE,
18713 &neighbor_addpath_tx_bestpath_per_as_cmd);
18714 install_element(BGP_VPNV6_NODE,
18715 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18716
18717 /* "neighbor sender-as-path-loop-detection" commands. */
18718 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
18719 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
18720
18721 /* "neighbor passive" commands. */
18722 install_element(BGP_NODE, &neighbor_passive_cmd);
18723 install_element(BGP_NODE, &no_neighbor_passive_cmd);
18724
18725
18726 /* "neighbor shutdown" commands. */
18727 install_element(BGP_NODE, &neighbor_shutdown_cmd);
18728 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
18729 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
18730 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
18731 install_element(BGP_NODE, &neighbor_shutdown_rtt_cmd);
18732 install_element(BGP_NODE, &no_neighbor_shutdown_rtt_cmd);
18733
18734 /* "neighbor capability extended-nexthop" commands.*/
18735 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
18736 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
18737
18738 /* "neighbor capability orf prefix-list" commands.*/
18739 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
18740 install_element(BGP_NODE,
18741 &no_neighbor_capability_orf_prefix_hidden_cmd);
18742 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
18743 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
18744 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
18745 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
18746 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
18747 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
18748 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
18749 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
18750 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
18751 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
18752 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
18753 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
18754
18755 /* "neighbor capability dynamic" commands.*/
18756 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
18757 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
18758
18759 /* "neighbor dont-capability-negotiate" commands. */
18760 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
18761 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
18762
18763 /* "neighbor ebgp-multihop" commands. */
18764 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
18765 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
18766 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
18767
18768 /* "neighbor disable-connected-check" commands. */
18769 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
18770 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
18771
18772 /* "neighbor enforce-first-as" commands. */
18773 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
18774 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
18775
18776 /* "neighbor description" commands. */
18777 install_element(BGP_NODE, &neighbor_description_cmd);
18778 install_element(BGP_NODE, &no_neighbor_description_cmd);
18779 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
18780
18781 /* "neighbor update-source" commands. "*/
18782 install_element(BGP_NODE, &neighbor_update_source_cmd);
18783 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
18784
18785 /* "neighbor default-originate" commands. */
18786 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
18787 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
18788 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
18789 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
18790 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
18791 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
18792 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
18793 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
18794 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
18795 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
18796 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
18797 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
18798 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
18799 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
18800 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
18801 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
18802 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
18803 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
18804 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
18805 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
18806 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
18807
18808 /* "neighbor port" commands. */
18809 install_element(BGP_NODE, &neighbor_port_cmd);
18810 install_element(BGP_NODE, &no_neighbor_port_cmd);
18811
18812 /* "neighbor weight" commands. */
18813 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
18814 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
18815
18816 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
18817 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
18818 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
18819 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
18820 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
18821 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
18822 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
18823 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
18824 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
18825 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
18826 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
18827 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
18828 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
18829 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
18830 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
18831 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
18832
18833 /* "neighbor override-capability" commands. */
18834 install_element(BGP_NODE, &neighbor_override_capability_cmd);
18835 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
18836
18837 /* "neighbor strict-capability-match" commands. */
18838 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
18839 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
18840
18841 /* "neighbor timers" commands. */
18842 install_element(BGP_NODE, &neighbor_timers_cmd);
18843 install_element(BGP_NODE, &no_neighbor_timers_cmd);
18844
18845 /* "neighbor timers connect" commands. */
18846 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
18847 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
18848
18849 /* "neighbor timers delayopen" commands. */
18850 install_element(BGP_NODE, &neighbor_timers_delayopen_cmd);
18851 install_element(BGP_NODE, &no_neighbor_timers_delayopen_cmd);
18852
18853 /* "neighbor advertisement-interval" commands. */
18854 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
18855 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
18856
18857 /* "neighbor interface" commands. */
18858 install_element(BGP_NODE, &neighbor_interface_cmd);
18859 install_element(BGP_NODE, &no_neighbor_interface_cmd);
18860
18861 /* "neighbor distribute" commands. */
18862 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
18863 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
18864 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
18865 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
18866 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
18867 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
18868 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
18869 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
18870 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
18871 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
18872 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
18873 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
18874 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
18875 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
18876 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
18877 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
18878 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
18879 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
18880
18881 /* "neighbor prefix-list" commands. */
18882 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
18883 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
18884 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
18885 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
18886 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
18887 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
18888 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
18889 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
18890 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
18891 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
18892 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
18893
18894 /* "neighbor filter-list" commands. */
18895 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
18896 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
18897 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
18898 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
18899 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
18900 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
18901 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
18902 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
18903 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
18904 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
18905 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
18906 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
18907 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
18908 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
18909 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
18910 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
18911 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
18912 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
18913 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
18914 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
18915 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
18916 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
18917
18918 /* "neighbor route-map" commands. */
18919 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
18920 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
18921 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
18922 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
18923 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
18924 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
18925 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
18926 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
18927 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
18928 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
18929 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
18930
18931 /* "neighbor unsuppress-map" commands. */
18932 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
18933 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
18934 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
18935 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
18936 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
18937 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
18938 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
18939 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
18940 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
18941 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
18942 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
18943 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
18944 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
18945 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
18946 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
18947 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
18948 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
18949 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
18950
18951 /* "neighbor advertise-map" commands. */
18952 install_element(BGP_NODE, &neighbor_advertise_map_hidden_cmd);
18953 install_element(BGP_IPV4_NODE, &neighbor_advertise_map_cmd);
18954 install_element(BGP_IPV4M_NODE, &neighbor_advertise_map_cmd);
18955 install_element(BGP_IPV4L_NODE, &neighbor_advertise_map_cmd);
18956 install_element(BGP_IPV6_NODE, &neighbor_advertise_map_cmd);
18957 install_element(BGP_IPV6M_NODE, &neighbor_advertise_map_cmd);
18958 install_element(BGP_IPV6L_NODE, &neighbor_advertise_map_cmd);
18959 install_element(BGP_VPNV4_NODE, &neighbor_advertise_map_cmd);
18960 install_element(BGP_VPNV6_NODE, &neighbor_advertise_map_cmd);
18961
18962 /* neighbor maximum-prefix-out commands. */
18963 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
18964 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
18965 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
18966 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
18967 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
18968 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
18969 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
18970 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
18971 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
18972 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
18973 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
18974 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
18975 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
18976 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
18977 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
18978 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
18979 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
18980 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
18981
18982 /* "neighbor maximum-prefix" commands. */
18983 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
18984 install_element(BGP_NODE,
18985 &neighbor_maximum_prefix_threshold_hidden_cmd);
18986 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
18987 install_element(BGP_NODE,
18988 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
18989 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
18990 install_element(BGP_NODE,
18991 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
18992 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
18993 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
18994 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
18995 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
18996 install_element(BGP_IPV4_NODE,
18997 &neighbor_maximum_prefix_threshold_warning_cmd);
18998 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
18999 install_element(BGP_IPV4_NODE,
19000 &neighbor_maximum_prefix_threshold_restart_cmd);
19001 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
19002 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
19003 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
19004 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
19005 install_element(BGP_IPV4M_NODE,
19006 &neighbor_maximum_prefix_threshold_warning_cmd);
19007 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
19008 install_element(BGP_IPV4M_NODE,
19009 &neighbor_maximum_prefix_threshold_restart_cmd);
19010 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
19011 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
19012 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
19013 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
19014 install_element(BGP_IPV4L_NODE,
19015 &neighbor_maximum_prefix_threshold_warning_cmd);
19016 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
19017 install_element(BGP_IPV4L_NODE,
19018 &neighbor_maximum_prefix_threshold_restart_cmd);
19019 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
19020 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
19021 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
19022 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
19023 install_element(BGP_IPV6_NODE,
19024 &neighbor_maximum_prefix_threshold_warning_cmd);
19025 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
19026 install_element(BGP_IPV6_NODE,
19027 &neighbor_maximum_prefix_threshold_restart_cmd);
19028 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
19029 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
19030 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
19031 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
19032 install_element(BGP_IPV6M_NODE,
19033 &neighbor_maximum_prefix_threshold_warning_cmd);
19034 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
19035 install_element(BGP_IPV6M_NODE,
19036 &neighbor_maximum_prefix_threshold_restart_cmd);
19037 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
19038 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
19039 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
19040 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
19041 install_element(BGP_IPV6L_NODE,
19042 &neighbor_maximum_prefix_threshold_warning_cmd);
19043 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
19044 install_element(BGP_IPV6L_NODE,
19045 &neighbor_maximum_prefix_threshold_restart_cmd);
19046 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
19047 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
19048 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
19049 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
19050 install_element(BGP_VPNV4_NODE,
19051 &neighbor_maximum_prefix_threshold_warning_cmd);
19052 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
19053 install_element(BGP_VPNV4_NODE,
19054 &neighbor_maximum_prefix_threshold_restart_cmd);
19055 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
19056 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
19057 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
19058 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
19059 install_element(BGP_VPNV6_NODE,
19060 &neighbor_maximum_prefix_threshold_warning_cmd);
19061 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
19062 install_element(BGP_VPNV6_NODE,
19063 &neighbor_maximum_prefix_threshold_restart_cmd);
19064 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
19065
19066 /* "neighbor allowas-in" */
19067 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
19068 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
19069 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
19070 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
19071 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
19072 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
19073 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
19074 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
19075 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
19076 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
19077 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
19078 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
19079 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
19080 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
19081 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
19082 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
19083 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
19084 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
19085 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
19086 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
19087
19088 /* "neighbor dampening" commands. */
19089 install_element(BGP_NODE, &neighbor_damp_cmd);
19090 install_element(BGP_NODE, &no_neighbor_damp_cmd);
19091 install_element(BGP_IPV4_NODE, &neighbor_damp_cmd);
19092 install_element(BGP_IPV4_NODE, &no_neighbor_damp_cmd);
19093 install_element(BGP_IPV4M_NODE, &neighbor_damp_cmd);
19094 install_element(BGP_IPV4M_NODE, &no_neighbor_damp_cmd);
19095 install_element(BGP_IPV4L_NODE, &neighbor_damp_cmd);
19096 install_element(BGP_IPV4L_NODE, &no_neighbor_damp_cmd);
19097 install_element(BGP_IPV6_NODE, &neighbor_damp_cmd);
19098 install_element(BGP_IPV6_NODE, &no_neighbor_damp_cmd);
19099 install_element(BGP_IPV6M_NODE, &neighbor_damp_cmd);
19100 install_element(BGP_IPV6M_NODE, &no_neighbor_damp_cmd);
19101 install_element(BGP_IPV6L_NODE, &neighbor_damp_cmd);
19102 install_element(BGP_IPV6L_NODE, &no_neighbor_damp_cmd);
19103 install_element(VIEW_NODE, &show_ip_bgp_neighbor_damp_param_cmd);
19104
19105 /* address-family commands. */
19106 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
19107 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
19108 #ifdef KEEP_OLD_VPN_COMMANDS
19109 install_element(BGP_NODE, &address_family_vpnv4_cmd);
19110 install_element(BGP_NODE, &address_family_vpnv6_cmd);
19111 #endif /* KEEP_OLD_VPN_COMMANDS */
19112
19113 install_element(BGP_NODE, &address_family_evpn_cmd);
19114
19115 /* "exit-address-family" command. */
19116 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
19117 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
19118 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
19119 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
19120 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
19121 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
19122 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
19123 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
19124 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
19125 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
19126 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
19127
19128 /* "clear ip bgp commands" */
19129 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
19130
19131 /* clear ip bgp prefix */
19132 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
19133 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
19134 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
19135
19136 /* "show [ip] bgp summary" commands. */
19137 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
19138 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
19139 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
19140 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
19141 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
19142 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
19143 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
19144
19145 /* "show [ip] bgp neighbors" commands. */
19146 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
19147
19148 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
19149
19150 /* "show [ip] bgp peer-group" commands. */
19151 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
19152
19153 /* "show [ip] bgp paths" commands. */
19154 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
19155
19156 /* "show [ip] bgp community" commands. */
19157 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
19158
19159 /* "show ip bgp large-community" commands. */
19160 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
19161 /* "show [ip] bgp attribute-info" commands. */
19162 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
19163 /* "show [ip] bgp route-leak" command */
19164 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
19165
19166 /* "redistribute" commands. */
19167 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
19168 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
19169 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
19170 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
19171 install_element(BGP_NODE,
19172 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
19173 install_element(BGP_NODE,
19174 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
19175 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
19176 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
19177 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
19178 install_element(BGP_NODE,
19179 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
19180 install_element(BGP_NODE,
19181 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
19182 install_element(BGP_NODE,
19183 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
19184 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
19185 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
19186 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
19187 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
19188 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
19189 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
19190 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
19191 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
19192 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
19193 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
19194 install_element(BGP_IPV4_NODE,
19195 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
19196 install_element(BGP_IPV4_NODE,
19197 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
19198 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
19199 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
19200 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
19201 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
19202 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
19203 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
19204
19205 /* import|export vpn [route-map WORD] */
19206 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
19207 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
19208
19209 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
19210 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
19211
19212 /* ttl_security commands */
19213 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
19214 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
19215
19216 /* "show [ip] bgp memory" commands. */
19217 install_element(VIEW_NODE, &show_bgp_memory_cmd);
19218
19219 /* "show bgp martian next-hop" */
19220 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
19221
19222 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
19223
19224 /* "show [ip] bgp views" commands. */
19225 install_element(VIEW_NODE, &show_bgp_views_cmd);
19226
19227 /* "show [ip] bgp vrfs" commands. */
19228 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
19229
19230 /* Community-list. */
19231 community_list_vty();
19232
19233 /* vpn-policy commands */
19234 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
19235 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
19236 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
19237 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
19238 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
19239 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
19240 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
19241 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
19242 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
19243 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
19244 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
19245 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
19246
19247 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
19248 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
19249
19250 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
19251 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
19252 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
19253 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
19254 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
19255 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
19256 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
19257 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
19258 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
19259 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
19260 }
19261
19262 #include "memory.h"
19263 #include "bgp_regex.h"
19264 #include "bgp_clist.h"
19265 #include "bgp_ecommunity.h"
19266
19267 /* VTY functions. */
19268
19269 /* Direction value to string conversion. */
19270 static const char *community_direct_str(int direct)
19271 {
19272 switch (direct) {
19273 case COMMUNITY_DENY:
19274 return "deny";
19275 case COMMUNITY_PERMIT:
19276 return "permit";
19277 default:
19278 return "unknown";
19279 }
19280 }
19281
19282 /* Display error string. */
19283 static void community_list_perror(struct vty *vty, int ret)
19284 {
19285 switch (ret) {
19286 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
19287 vty_out(vty, "%% Can't find community-list\n");
19288 break;
19289 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
19290 vty_out(vty, "%% Malformed community-list value\n");
19291 break;
19292 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
19293 vty_out(vty,
19294 "%% Community name conflict, previously defined as standard community\n");
19295 break;
19296 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
19297 vty_out(vty,
19298 "%% Community name conflict, previously defined as expanded community\n");
19299 break;
19300 }
19301 }
19302
19303 /* "community-list" keyword help string. */
19304 #define COMMUNITY_LIST_STR "Add a community list entry\n"
19305
19306 /*community-list standard */
19307 DEFUN (community_list_standard,
19308 bgp_community_list_standard_cmd,
19309 "bgp community-list <(1-99)|standard WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
19310 BGP_STR
19311 COMMUNITY_LIST_STR
19312 "Community list number (standard)\n"
19313 "Add an standard community-list entry\n"
19314 "Community list name\n"
19315 "Sequence number of an entry\n"
19316 "Sequence number\n"
19317 "Specify community to reject\n"
19318 "Specify community to accept\n"
19319 COMMUNITY_VAL_STR)
19320 {
19321 char *cl_name_or_number = NULL;
19322 char *seq = NULL;
19323 int direct = 0;
19324 int style = COMMUNITY_LIST_STANDARD;
19325 int idx = 0;
19326
19327 argv_find(argv, argc, "(0-4294967295)", &idx);
19328 if (idx)
19329 seq = argv[idx]->arg;
19330
19331 idx = 0;
19332 argv_find(argv, argc, "(1-99)", &idx);
19333 argv_find(argv, argc, "WORD", &idx);
19334 cl_name_or_number = argv[idx]->arg;
19335 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19336 : COMMUNITY_DENY;
19337 argv_find(argv, argc, "AA:NN", &idx);
19338 char *str = argv_concat(argv, argc, idx);
19339
19340 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19341 direct, style);
19342
19343 XFREE(MTYPE_TMP, str);
19344
19345 if (ret < 0) {
19346 /* Display error string. */
19347 community_list_perror(vty, ret);
19348 return CMD_WARNING_CONFIG_FAILED;
19349 }
19350
19351 return CMD_SUCCESS;
19352 }
19353
19354 DEFUN (no_community_list_standard_all,
19355 no_bgp_community_list_standard_all_cmd,
19356 "no bgp community-list <(1-99)|standard WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
19357 NO_STR
19358 BGP_STR
19359 COMMUNITY_LIST_STR
19360 "Community list number (standard)\n"
19361 "Add an standard community-list entry\n"
19362 "Community list name\n"
19363 "Sequence number of an entry\n"
19364 "Sequence number\n"
19365 "Specify community to reject\n"
19366 "Specify community to accept\n"
19367 COMMUNITY_VAL_STR)
19368 {
19369 char *cl_name_or_number = NULL;
19370 char *str = NULL;
19371 int direct = 0;
19372 int style = COMMUNITY_LIST_STANDARD;
19373 char *seq = NULL;
19374 int idx = 0;
19375
19376 argv_find(argv, argc, "(0-4294967295)", &idx);
19377 if (idx)
19378 seq = argv[idx]->arg;
19379
19380 idx = 0;
19381 argv_find(argv, argc, "permit", &idx);
19382 argv_find(argv, argc, "deny", &idx);
19383
19384 if (idx) {
19385 direct = argv_find(argv, argc, "permit", &idx)
19386 ? COMMUNITY_PERMIT
19387 : COMMUNITY_DENY;
19388
19389 idx = 0;
19390 argv_find(argv, argc, "AA:NN", &idx);
19391 str = argv_concat(argv, argc, idx);
19392 }
19393
19394 idx = 0;
19395 argv_find(argv, argc, "(1-99)", &idx);
19396 argv_find(argv, argc, "WORD", &idx);
19397 cl_name_or_number = argv[idx]->arg;
19398
19399 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
19400 direct, style);
19401
19402 XFREE(MTYPE_TMP, str);
19403
19404 if (ret < 0) {
19405 community_list_perror(vty, ret);
19406 return CMD_WARNING_CONFIG_FAILED;
19407 }
19408
19409 return CMD_SUCCESS;
19410 }
19411
19412 ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
19413 "no bgp community-list <(1-99)|standard WORD>",
19414 NO_STR BGP_STR COMMUNITY_LIST_STR
19415 "Community list number (standard)\n"
19416 "Add an standard community-list entry\n"
19417 "Community list name\n")
19418
19419 /*community-list expanded */
19420 DEFUN (community_list_expanded_all,
19421 bgp_community_list_expanded_all_cmd,
19422 "bgp community-list <(100-500)|expanded WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
19423 BGP_STR
19424 COMMUNITY_LIST_STR
19425 "Community list number (expanded)\n"
19426 "Add an expanded community-list entry\n"
19427 "Community list name\n"
19428 "Sequence number of an entry\n"
19429 "Sequence number\n"
19430 "Specify community to reject\n"
19431 "Specify community to accept\n"
19432 COMMUNITY_VAL_STR)
19433 {
19434 char *cl_name_or_number = NULL;
19435 char *seq = NULL;
19436 int direct = 0;
19437 int style = COMMUNITY_LIST_EXPANDED;
19438 int idx = 0;
19439
19440 argv_find(argv, argc, "(0-4294967295)", &idx);
19441 if (idx)
19442 seq = argv[idx]->arg;
19443
19444 idx = 0;
19445
19446 argv_find(argv, argc, "(100-500)", &idx);
19447 argv_find(argv, argc, "WORD", &idx);
19448 cl_name_or_number = argv[idx]->arg;
19449 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19450 : COMMUNITY_DENY;
19451 argv_find(argv, argc, "AA:NN", &idx);
19452 char *str = argv_concat(argv, argc, idx);
19453
19454 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19455 direct, style);
19456
19457 XFREE(MTYPE_TMP, str);
19458
19459 if (ret < 0) {
19460 /* Display error string. */
19461 community_list_perror(vty, ret);
19462 return CMD_WARNING_CONFIG_FAILED;
19463 }
19464
19465 return CMD_SUCCESS;
19466 }
19467
19468 DEFUN (no_community_list_expanded_all,
19469 no_bgp_community_list_expanded_all_cmd,
19470 "no bgp community-list <(100-500)|expanded WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
19471 NO_STR
19472 BGP_STR
19473 COMMUNITY_LIST_STR
19474 "Community list number (expanded)\n"
19475 "Add an expanded community-list entry\n"
19476 "Community list name\n"
19477 "Sequence number of an entry\n"
19478 "Sequence number\n"
19479 "Specify community to reject\n"
19480 "Specify community to accept\n"
19481 COMMUNITY_VAL_STR)
19482 {
19483 char *cl_name_or_number = NULL;
19484 char *seq = NULL;
19485 char *str = NULL;
19486 int direct = 0;
19487 int style = COMMUNITY_LIST_EXPANDED;
19488 int idx = 0;
19489
19490 argv_find(argv, argc, "(0-4294967295)", &idx);
19491 if (idx)
19492 seq = argv[idx]->arg;
19493
19494 idx = 0;
19495 argv_find(argv, argc, "permit", &idx);
19496 argv_find(argv, argc, "deny", &idx);
19497
19498 if (idx) {
19499 direct = argv_find(argv, argc, "permit", &idx)
19500 ? COMMUNITY_PERMIT
19501 : COMMUNITY_DENY;
19502
19503 idx = 0;
19504 argv_find(argv, argc, "AA:NN", &idx);
19505 str = argv_concat(argv, argc, idx);
19506 }
19507
19508 idx = 0;
19509 argv_find(argv, argc, "(100-500)", &idx);
19510 argv_find(argv, argc, "WORD", &idx);
19511 cl_name_or_number = argv[idx]->arg;
19512
19513 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
19514 direct, style);
19515
19516 XFREE(MTYPE_TMP, str);
19517
19518 if (ret < 0) {
19519 community_list_perror(vty, ret);
19520 return CMD_WARNING_CONFIG_FAILED;
19521 }
19522
19523 return CMD_SUCCESS;
19524 }
19525
19526 ALIAS(no_community_list_expanded_all,
19527 no_bgp_community_list_expanded_all_list_cmd,
19528 "no bgp community-list <(100-500)|expanded WORD>",
19529 NO_STR BGP_STR COMMUNITY_LIST_STR
19530 "Community list number (expanded)\n"
19531 "Add an expanded community-list entry\n"
19532 "Community list name\n")
19533
19534 /* Return configuration string of community-list entry. */
19535 static const char *community_list_config_str(struct community_entry *entry)
19536 {
19537 const char *str;
19538
19539 if (entry->any)
19540 str = "";
19541 else {
19542 if (entry->style == COMMUNITY_LIST_STANDARD)
19543 str = community_str(entry->u.com, false);
19544 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
19545 str = lcommunity_str(entry->u.lcom, false);
19546 else
19547 str = entry->config;
19548 }
19549 return str;
19550 }
19551
19552 static void community_list_show(struct vty *vty, struct community_list *list)
19553 {
19554 struct community_entry *entry;
19555
19556 for (entry = list->head; entry; entry = entry->next) {
19557 if (entry == list->head) {
19558 if (all_digit(list->name))
19559 vty_out(vty, "Community %s list %s\n",
19560 entry->style == COMMUNITY_LIST_STANDARD
19561 ? "standard"
19562 : "(expanded) access",
19563 list->name);
19564 else
19565 vty_out(vty, "Named Community %s list %s\n",
19566 entry->style == COMMUNITY_LIST_STANDARD
19567 ? "standard"
19568 : "expanded",
19569 list->name);
19570 }
19571 if (entry->any)
19572 vty_out(vty, " %s\n",
19573 community_direct_str(entry->direct));
19574 else
19575 vty_out(vty, " %s %s\n",
19576 community_direct_str(entry->direct),
19577 community_list_config_str(entry));
19578 }
19579 }
19580
19581 DEFUN (show_community_list,
19582 show_bgp_community_list_cmd,
19583 "show bgp community-list",
19584 SHOW_STR
19585 BGP_STR
19586 "List community-list\n")
19587 {
19588 struct community_list *list;
19589 struct community_list_master *cm;
19590
19591 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
19592 if (!cm)
19593 return CMD_SUCCESS;
19594
19595 for (list = cm->num.head; list; list = list->next)
19596 community_list_show(vty, list);
19597
19598 for (list = cm->str.head; list; list = list->next)
19599 community_list_show(vty, list);
19600
19601 return CMD_SUCCESS;
19602 }
19603
19604 DEFUN (show_community_list_arg,
19605 show_bgp_community_list_arg_cmd,
19606 "show bgp community-list <(1-500)|WORD> detail",
19607 SHOW_STR
19608 BGP_STR
19609 "List community-list\n"
19610 "Community-list number\n"
19611 "Community-list name\n"
19612 "Detailed information on community-list\n")
19613 {
19614 int idx_comm_list = 3;
19615 struct community_list *list;
19616
19617 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
19618 COMMUNITY_LIST_MASTER);
19619 if (!list) {
19620 vty_out(vty, "%% Can't find community-list\n");
19621 return CMD_WARNING;
19622 }
19623
19624 community_list_show(vty, list);
19625
19626 return CMD_SUCCESS;
19627 }
19628
19629 /*
19630 * Large Community code.
19631 */
19632 static int lcommunity_list_set_vty(struct vty *vty, int argc,
19633 struct cmd_token **argv, int style,
19634 int reject_all_digit_name)
19635 {
19636 int ret;
19637 int direct;
19638 char *str;
19639 int idx = 0;
19640 char *cl_name;
19641 char *seq = NULL;
19642
19643 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19644 seq = argv[idx]->arg;
19645
19646 idx = 0;
19647 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19648 : COMMUNITY_DENY;
19649
19650 /* All digit name check. */
19651 idx = 0;
19652 argv_find(argv, argc, "WORD", &idx);
19653 argv_find(argv, argc, "(1-99)", &idx);
19654 argv_find(argv, argc, "(100-500)", &idx);
19655 cl_name = argv[idx]->arg;
19656 if (reject_all_digit_name && all_digit(cl_name)) {
19657 vty_out(vty, "%% Community name cannot have all digits\n");
19658 return CMD_WARNING_CONFIG_FAILED;
19659 }
19660
19661 idx = 0;
19662 argv_find(argv, argc, "AA:BB:CC", &idx);
19663 argv_find(argv, argc, "LINE", &idx);
19664 /* Concat community string argument. */
19665 if (idx)
19666 str = argv_concat(argv, argc, idx);
19667 else
19668 str = NULL;
19669
19670 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
19671
19672 /* Free temporary community list string allocated by
19673 argv_concat(). */
19674 XFREE(MTYPE_TMP, str);
19675
19676 if (ret < 0) {
19677 community_list_perror(vty, ret);
19678 return CMD_WARNING_CONFIG_FAILED;
19679 }
19680 return CMD_SUCCESS;
19681 }
19682
19683 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
19684 struct cmd_token **argv, int style)
19685 {
19686 int ret;
19687 int direct = 0;
19688 char *str = NULL;
19689 int idx = 0;
19690 char *seq = NULL;
19691
19692 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19693 seq = argv[idx]->arg;
19694
19695 idx = 0;
19696 argv_find(argv, argc, "permit", &idx);
19697 argv_find(argv, argc, "deny", &idx);
19698
19699 if (idx) {
19700 /* Check the list direct. */
19701 if (strncmp(argv[idx]->arg, "p", 1) == 0)
19702 direct = COMMUNITY_PERMIT;
19703 else
19704 direct = COMMUNITY_DENY;
19705
19706 idx = 0;
19707 argv_find(argv, argc, "LINE", &idx);
19708 argv_find(argv, argc, "AA:AA:NN", &idx);
19709 /* Concat community string argument. */
19710 str = argv_concat(argv, argc, idx);
19711 }
19712
19713 idx = 0;
19714 argv_find(argv, argc, "(1-99)", &idx);
19715 argv_find(argv, argc, "(100-500)", &idx);
19716 argv_find(argv, argc, "WORD", &idx);
19717
19718 /* Unset community list. */
19719 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
19720 style);
19721
19722 /* Free temporary community list string allocated by
19723 argv_concat(). */
19724 XFREE(MTYPE_TMP, str);
19725
19726 if (ret < 0) {
19727 community_list_perror(vty, ret);
19728 return CMD_WARNING_CONFIG_FAILED;
19729 }
19730
19731 return CMD_SUCCESS;
19732 }
19733
19734 /* "large-community-list" keyword help string. */
19735 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
19736 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
19737
19738 DEFUN (lcommunity_list_standard,
19739 bgp_lcommunity_list_standard_cmd,
19740 "bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
19741 BGP_STR
19742 LCOMMUNITY_LIST_STR
19743 "Large Community list number (standard)\n"
19744 "Sequence number of an entry\n"
19745 "Sequence number\n"
19746 "Specify large community to reject\n"
19747 "Specify large community to accept\n"
19748 LCOMMUNITY_VAL_STR)
19749 {
19750 return lcommunity_list_set_vty(vty, argc, argv,
19751 LARGE_COMMUNITY_LIST_STANDARD, 0);
19752 }
19753
19754 DEFUN (lcommunity_list_expanded,
19755 bgp_lcommunity_list_expanded_cmd,
19756 "bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
19757 BGP_STR
19758 LCOMMUNITY_LIST_STR
19759 "Large Community list number (expanded)\n"
19760 "Sequence number of an entry\n"
19761 "Sequence number\n"
19762 "Specify large community to reject\n"
19763 "Specify large community to accept\n"
19764 "An ordered list as a regular-expression\n")
19765 {
19766 return lcommunity_list_set_vty(vty, argc, argv,
19767 LARGE_COMMUNITY_LIST_EXPANDED, 0);
19768 }
19769
19770 DEFUN (lcommunity_list_name_standard,
19771 bgp_lcommunity_list_name_standard_cmd,
19772 "bgp large-community-list standard WORD [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
19773 BGP_STR
19774 LCOMMUNITY_LIST_STR
19775 "Specify standard large-community-list\n"
19776 "Large Community list name\n"
19777 "Sequence number of an entry\n"
19778 "Sequence number\n"
19779 "Specify large community to reject\n"
19780 "Specify large community to accept\n"
19781 LCOMMUNITY_VAL_STR)
19782 {
19783 return lcommunity_list_set_vty(vty, argc, argv,
19784 LARGE_COMMUNITY_LIST_STANDARD, 1);
19785 }
19786
19787 DEFUN (lcommunity_list_name_expanded,
19788 bgp_lcommunity_list_name_expanded_cmd,
19789 "bgp large-community-list expanded WORD [seq (0-4294967295)] <deny|permit> LINE...",
19790 BGP_STR
19791 LCOMMUNITY_LIST_STR
19792 "Specify expanded large-community-list\n"
19793 "Large Community list name\n"
19794 "Sequence number of an entry\n"
19795 "Sequence number\n"
19796 "Specify large community to reject\n"
19797 "Specify large community to accept\n"
19798 "An ordered list as a regular-expression\n")
19799 {
19800 return lcommunity_list_set_vty(vty, argc, argv,
19801 LARGE_COMMUNITY_LIST_EXPANDED, 1);
19802 }
19803
19804 DEFUN (no_lcommunity_list_all,
19805 no_bgp_lcommunity_list_all_cmd,
19806 "no bgp large-community-list <(1-99)|(100-500)|WORD>",
19807 NO_STR
19808 BGP_STR
19809 LCOMMUNITY_LIST_STR
19810 "Large Community list number (standard)\n"
19811 "Large Community list number (expanded)\n"
19812 "Large Community list name\n")
19813 {
19814 return lcommunity_list_unset_vty(vty, argc, argv,
19815 LARGE_COMMUNITY_LIST_STANDARD);
19816 }
19817
19818 DEFUN (no_lcommunity_list_name_standard_all,
19819 no_bgp_lcommunity_list_name_standard_all_cmd,
19820 "no bgp large-community-list standard WORD",
19821 NO_STR
19822 BGP_STR
19823 LCOMMUNITY_LIST_STR
19824 "Specify standard large-community-list\n"
19825 "Large Community list name\n")
19826 {
19827 return lcommunity_list_unset_vty(vty, argc, argv,
19828 LARGE_COMMUNITY_LIST_STANDARD);
19829 }
19830
19831 DEFUN (no_lcommunity_list_name_expanded_all,
19832 no_bgp_lcommunity_list_name_expanded_all_cmd,
19833 "no bgp large-community-list expanded WORD",
19834 NO_STR
19835 BGP_STR
19836 LCOMMUNITY_LIST_STR
19837 "Specify expanded large-community-list\n"
19838 "Large Community list name\n")
19839 {
19840 return lcommunity_list_unset_vty(vty, argc, argv,
19841 LARGE_COMMUNITY_LIST_EXPANDED);
19842 }
19843
19844 DEFUN (no_lcommunity_list_standard,
19845 no_bgp_lcommunity_list_standard_cmd,
19846 "no bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
19847 NO_STR
19848 BGP_STR
19849 LCOMMUNITY_LIST_STR
19850 "Large Community list number (standard)\n"
19851 "Sequence number of an entry\n"
19852 "Sequence number\n"
19853 "Specify large community to reject\n"
19854 "Specify large community to accept\n"
19855 LCOMMUNITY_VAL_STR)
19856 {
19857 return lcommunity_list_unset_vty(vty, argc, argv,
19858 LARGE_COMMUNITY_LIST_STANDARD);
19859 }
19860
19861 DEFUN (no_lcommunity_list_expanded,
19862 no_bgp_lcommunity_list_expanded_cmd,
19863 "no bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
19864 NO_STR
19865 BGP_STR
19866 LCOMMUNITY_LIST_STR
19867 "Large Community list number (expanded)\n"
19868 "Sequence number of an entry\n"
19869 "Sequence number\n"
19870 "Specify large community to reject\n"
19871 "Specify large community to accept\n"
19872 "An ordered list as a regular-expression\n")
19873 {
19874 return lcommunity_list_unset_vty(vty, argc, argv,
19875 LARGE_COMMUNITY_LIST_EXPANDED);
19876 }
19877
19878 DEFUN (no_lcommunity_list_name_standard,
19879 no_bgp_lcommunity_list_name_standard_cmd,
19880 "no bgp large-community-list standard WORD [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
19881 NO_STR
19882 BGP_STR
19883 LCOMMUNITY_LIST_STR
19884 "Specify standard large-community-list\n"
19885 "Large Community list name\n"
19886 "Sequence number of an entry\n"
19887 "Sequence number\n"
19888 "Specify large community to reject\n"
19889 "Specify large community to accept\n"
19890 LCOMMUNITY_VAL_STR)
19891 {
19892 return lcommunity_list_unset_vty(vty, argc, argv,
19893 LARGE_COMMUNITY_LIST_STANDARD);
19894 }
19895
19896 DEFUN (no_lcommunity_list_name_expanded,
19897 no_bgp_lcommunity_list_name_expanded_cmd,
19898 "no bgp large-community-list expanded WORD [seq (0-4294967295)] <deny|permit> LINE...",
19899 NO_STR
19900 BGP_STR
19901 LCOMMUNITY_LIST_STR
19902 "Specify expanded large-community-list\n"
19903 "Large community list name\n"
19904 "Sequence number of an entry\n"
19905 "Sequence number\n"
19906 "Specify large community to reject\n"
19907 "Specify large community to accept\n"
19908 "An ordered list as a regular-expression\n")
19909 {
19910 return lcommunity_list_unset_vty(vty, argc, argv,
19911 LARGE_COMMUNITY_LIST_EXPANDED);
19912 }
19913
19914 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
19915 {
19916 struct community_entry *entry;
19917
19918 for (entry = list->head; entry; entry = entry->next) {
19919 if (entry == list->head) {
19920 if (all_digit(list->name))
19921 vty_out(vty, "Large community %s list %s\n",
19922 entry->style ==
19923 LARGE_COMMUNITY_LIST_STANDARD
19924 ? "standard"
19925 : "(expanded) access",
19926 list->name);
19927 else
19928 vty_out(vty,
19929 "Named large community %s list %s\n",
19930 entry->style ==
19931 LARGE_COMMUNITY_LIST_STANDARD
19932 ? "standard"
19933 : "expanded",
19934 list->name);
19935 }
19936 if (entry->any)
19937 vty_out(vty, " %s\n",
19938 community_direct_str(entry->direct));
19939 else
19940 vty_out(vty, " %s %s\n",
19941 community_direct_str(entry->direct),
19942 community_list_config_str(entry));
19943 }
19944 }
19945
19946 DEFUN (show_lcommunity_list,
19947 show_bgp_lcommunity_list_cmd,
19948 "show bgp large-community-list",
19949 SHOW_STR
19950 BGP_STR
19951 "List large-community list\n")
19952 {
19953 struct community_list *list;
19954 struct community_list_master *cm;
19955
19956 cm = community_list_master_lookup(bgp_clist,
19957 LARGE_COMMUNITY_LIST_MASTER);
19958 if (!cm)
19959 return CMD_SUCCESS;
19960
19961 for (list = cm->num.head; list; list = list->next)
19962 lcommunity_list_show(vty, list);
19963
19964 for (list = cm->str.head; list; list = list->next)
19965 lcommunity_list_show(vty, list);
19966
19967 return CMD_SUCCESS;
19968 }
19969
19970 DEFUN (show_lcommunity_list_arg,
19971 show_bgp_lcommunity_list_arg_cmd,
19972 "show bgp large-community-list <(1-500)|WORD> detail",
19973 SHOW_STR
19974 BGP_STR
19975 "List large-community list\n"
19976 "Large-community-list number\n"
19977 "Large-community-list name\n"
19978 "Detailed information on large-community-list\n")
19979 {
19980 struct community_list *list;
19981
19982 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
19983 LARGE_COMMUNITY_LIST_MASTER);
19984 if (!list) {
19985 vty_out(vty, "%% Can't find large-community-list\n");
19986 return CMD_WARNING;
19987 }
19988
19989 lcommunity_list_show(vty, list);
19990
19991 return CMD_SUCCESS;
19992 }
19993
19994 /* "extcommunity-list" keyword help string. */
19995 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
19996 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
19997
19998 DEFUN (extcommunity_list_standard,
19999 bgp_extcommunity_list_standard_cmd,
20000 "bgp extcommunity-list <(1-99)|standard WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
20001 BGP_STR
20002 EXTCOMMUNITY_LIST_STR
20003 "Extended Community list number (standard)\n"
20004 "Specify standard extcommunity-list\n"
20005 "Community list name\n"
20006 "Sequence number of an entry\n"
20007 "Sequence number\n"
20008 "Specify community to reject\n"
20009 "Specify community to accept\n"
20010 EXTCOMMUNITY_VAL_STR)
20011 {
20012 int style = EXTCOMMUNITY_LIST_STANDARD;
20013 int direct = 0;
20014 char *cl_number_or_name = NULL;
20015 char *seq = NULL;
20016
20017 int idx = 0;
20018
20019 argv_find(argv, argc, "(1-99)", &idx);
20020 argv_find(argv, argc, "WORD", &idx);
20021 cl_number_or_name = argv[idx]->arg;
20022
20023 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20024 seq = argv[idx]->arg;
20025
20026 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20027 : COMMUNITY_DENY;
20028 argv_find(argv, argc, "AA:NN", &idx);
20029 char *str = argv_concat(argv, argc, idx);
20030
20031 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
20032 direct, style);
20033
20034 XFREE(MTYPE_TMP, str);
20035
20036 if (ret < 0) {
20037 community_list_perror(vty, ret);
20038 return CMD_WARNING_CONFIG_FAILED;
20039 }
20040
20041 return CMD_SUCCESS;
20042 }
20043
20044 DEFUN (extcommunity_list_name_expanded,
20045 bgp_extcommunity_list_name_expanded_cmd,
20046 "bgp extcommunity-list <(100-500)|expanded WORD> [seq (0-4294967295)] <deny|permit> LINE...",
20047 BGP_STR
20048 EXTCOMMUNITY_LIST_STR
20049 "Extended Community list number (expanded)\n"
20050 "Specify expanded extcommunity-list\n"
20051 "Extended Community list name\n"
20052 "Sequence number of an entry\n"
20053 "Sequence number\n"
20054 "Specify community to reject\n"
20055 "Specify community to accept\n"
20056 "An ordered list as a regular-expression\n")
20057 {
20058 int style = EXTCOMMUNITY_LIST_EXPANDED;
20059 int direct = 0;
20060 char *cl_number_or_name = NULL;
20061 char *seq = NULL;
20062 int idx = 0;
20063
20064 argv_find(argv, argc, "(100-500)", &idx);
20065 argv_find(argv, argc, "WORD", &idx);
20066 cl_number_or_name = argv[idx]->arg;
20067
20068 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20069 seq = argv[idx]->arg;
20070
20071 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20072 : COMMUNITY_DENY;
20073 argv_find(argv, argc, "LINE", &idx);
20074 char *str = argv_concat(argv, argc, idx);
20075
20076 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
20077 direct, style);
20078
20079 XFREE(MTYPE_TMP, str);
20080
20081 if (ret < 0) {
20082 community_list_perror(vty, ret);
20083 return CMD_WARNING_CONFIG_FAILED;
20084 }
20085
20086 return CMD_SUCCESS;
20087 }
20088
20089 DEFUN (no_extcommunity_list_standard_all,
20090 no_bgp_extcommunity_list_standard_all_cmd,
20091 "no bgp extcommunity-list <(1-99)|standard WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
20092 NO_STR
20093 BGP_STR
20094 EXTCOMMUNITY_LIST_STR
20095 "Extended Community list number (standard)\n"
20096 "Specify standard extcommunity-list\n"
20097 "Community list name\n"
20098 "Sequence number of an entry\n"
20099 "Sequence number\n"
20100 "Specify community to reject\n"
20101 "Specify community to accept\n"
20102 EXTCOMMUNITY_VAL_STR)
20103 {
20104 int style = EXTCOMMUNITY_LIST_STANDARD;
20105 int direct = 0;
20106 char *cl_number_or_name = NULL;
20107 char *str = NULL;
20108 char *seq = NULL;
20109 int idx = 0;
20110
20111 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20112 seq = argv[idx]->arg;
20113
20114 idx = 0;
20115 argv_find(argv, argc, "permit", &idx);
20116 argv_find(argv, argc, "deny", &idx);
20117 if (idx) {
20118 direct = argv_find(argv, argc, "permit", &idx)
20119 ? COMMUNITY_PERMIT
20120 : COMMUNITY_DENY;
20121
20122 idx = 0;
20123 argv_find(argv, argc, "AA:NN", &idx);
20124 str = argv_concat(argv, argc, idx);
20125 }
20126
20127 idx = 0;
20128 argv_find(argv, argc, "(1-99)", &idx);
20129 argv_find(argv, argc, "WORD", &idx);
20130 cl_number_or_name = argv[idx]->arg;
20131
20132 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
20133 seq, direct, style);
20134
20135 XFREE(MTYPE_TMP, str);
20136
20137 if (ret < 0) {
20138 community_list_perror(vty, ret);
20139 return CMD_WARNING_CONFIG_FAILED;
20140 }
20141
20142 return CMD_SUCCESS;
20143 }
20144
20145 ALIAS(no_extcommunity_list_standard_all,
20146 no_bgp_extcommunity_list_standard_all_list_cmd,
20147 "no bgp extcommunity-list <(1-99)|standard WORD>",
20148 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
20149 "Extended Community list number (standard)\n"
20150 "Specify standard extcommunity-list\n"
20151 "Community list name\n")
20152
20153 DEFUN (no_extcommunity_list_expanded_all,
20154 no_bgp_extcommunity_list_expanded_all_cmd,
20155 "no bgp extcommunity-list <(100-500)|expanded WORD> [seq (0-4294967295)] <deny|permit> LINE...",
20156 NO_STR
20157 BGP_STR
20158 EXTCOMMUNITY_LIST_STR
20159 "Extended Community list number (expanded)\n"
20160 "Specify expanded extcommunity-list\n"
20161 "Extended Community list name\n"
20162 "Sequence number of an entry\n"
20163 "Sequence number\n"
20164 "Specify community to reject\n"
20165 "Specify community to accept\n"
20166 "An ordered list as a regular-expression\n")
20167 {
20168 int style = EXTCOMMUNITY_LIST_EXPANDED;
20169 int direct = 0;
20170 char *cl_number_or_name = NULL;
20171 char *str = NULL;
20172 char *seq = NULL;
20173 int idx = 0;
20174
20175 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20176 seq = argv[idx]->arg;
20177
20178 idx = 0;
20179 argv_find(argv, argc, "permit", &idx);
20180 argv_find(argv, argc, "deny", &idx);
20181
20182 if (idx) {
20183 direct = argv_find(argv, argc, "permit", &idx)
20184 ? COMMUNITY_PERMIT
20185 : COMMUNITY_DENY;
20186
20187 idx = 0;
20188 argv_find(argv, argc, "LINE", &idx);
20189 str = argv_concat(argv, argc, idx);
20190 }
20191
20192 idx = 0;
20193 argv_find(argv, argc, "(100-500)", &idx);
20194 argv_find(argv, argc, "WORD", &idx);
20195 cl_number_or_name = argv[idx]->arg;
20196
20197 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
20198 seq, direct, style);
20199
20200 XFREE(MTYPE_TMP, str);
20201
20202 if (ret < 0) {
20203 community_list_perror(vty, ret);
20204 return CMD_WARNING_CONFIG_FAILED;
20205 }
20206
20207 return CMD_SUCCESS;
20208 }
20209
20210 ALIAS(no_extcommunity_list_expanded_all,
20211 no_bgp_extcommunity_list_expanded_all_list_cmd,
20212 "no bgp extcommunity-list <(100-500)|expanded WORD>",
20213 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
20214 "Extended Community list number (expanded)\n"
20215 "Specify expanded extcommunity-list\n"
20216 "Extended Community list name\n")
20217
20218 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
20219 {
20220 struct community_entry *entry;
20221
20222 for (entry = list->head; entry; entry = entry->next) {
20223 if (entry == list->head) {
20224 if (all_digit(list->name))
20225 vty_out(vty, "Extended community %s list %s\n",
20226 entry->style == EXTCOMMUNITY_LIST_STANDARD
20227 ? "standard"
20228 : "(expanded) access",
20229 list->name);
20230 else
20231 vty_out(vty,
20232 "Named extended community %s list %s\n",
20233 entry->style == EXTCOMMUNITY_LIST_STANDARD
20234 ? "standard"
20235 : "expanded",
20236 list->name);
20237 }
20238 if (entry->any)
20239 vty_out(vty, " %s\n",
20240 community_direct_str(entry->direct));
20241 else
20242 vty_out(vty, " %s %s\n",
20243 community_direct_str(entry->direct),
20244 community_list_config_str(entry));
20245 }
20246 }
20247
20248 DEFUN (show_extcommunity_list,
20249 show_bgp_extcommunity_list_cmd,
20250 "show bgp extcommunity-list",
20251 SHOW_STR
20252 BGP_STR
20253 "List extended-community list\n")
20254 {
20255 struct community_list *list;
20256 struct community_list_master *cm;
20257
20258 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
20259 if (!cm)
20260 return CMD_SUCCESS;
20261
20262 for (list = cm->num.head; list; list = list->next)
20263 extcommunity_list_show(vty, list);
20264
20265 for (list = cm->str.head; list; list = list->next)
20266 extcommunity_list_show(vty, list);
20267
20268 return CMD_SUCCESS;
20269 }
20270
20271 DEFUN (show_extcommunity_list_arg,
20272 show_bgp_extcommunity_list_arg_cmd,
20273 "show bgp extcommunity-list <(1-500)|WORD> detail",
20274 SHOW_STR
20275 BGP_STR
20276 "List extended-community list\n"
20277 "Extcommunity-list number\n"
20278 "Extcommunity-list name\n"
20279 "Detailed information on extcommunity-list\n")
20280 {
20281 int idx_comm_list = 3;
20282 struct community_list *list;
20283
20284 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
20285 EXTCOMMUNITY_LIST_MASTER);
20286 if (!list) {
20287 vty_out(vty, "%% Can't find extcommunity-list\n");
20288 return CMD_WARNING;
20289 }
20290
20291 extcommunity_list_show(vty, list);
20292
20293 return CMD_SUCCESS;
20294 }
20295
20296 /* Display community-list and extcommunity-list configuration. */
20297 static int community_list_config_write(struct vty *vty)
20298 {
20299 struct community_list *list;
20300 struct community_entry *entry;
20301 struct community_list_master *cm;
20302 int write = 0;
20303
20304 /* Community-list. */
20305 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
20306
20307 for (list = cm->num.head; list; list = list->next)
20308 for (entry = list->head; entry; entry = entry->next) {
20309 vty_out(vty,
20310 "bgp community-list %s seq %" PRId64 " %s %s\n",
20311 list->name, entry->seq,
20312 community_direct_str(entry->direct),
20313 community_list_config_str(entry));
20314 write++;
20315 }
20316 for (list = cm->str.head; list; list = list->next)
20317 for (entry = list->head; entry; entry = entry->next) {
20318 vty_out(vty,
20319 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
20320 entry->style == COMMUNITY_LIST_STANDARD
20321 ? "standard"
20322 : "expanded",
20323 list->name, entry->seq,
20324 community_direct_str(entry->direct),
20325 community_list_config_str(entry));
20326 write++;
20327 }
20328
20329 /* Extcommunity-list. */
20330 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
20331
20332 for (list = cm->num.head; list; list = list->next)
20333 for (entry = list->head; entry; entry = entry->next) {
20334 vty_out(vty,
20335 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
20336 list->name, entry->seq,
20337 community_direct_str(entry->direct),
20338 community_list_config_str(entry));
20339 write++;
20340 }
20341 for (list = cm->str.head; list; list = list->next)
20342 for (entry = list->head; entry; entry = entry->next) {
20343 vty_out(vty,
20344 "bgp extcommunity-list %s %s seq %" PRId64" %s %s\n",
20345 entry->style == EXTCOMMUNITY_LIST_STANDARD
20346 ? "standard"
20347 : "expanded",
20348 list->name, entry->seq,
20349 community_direct_str(entry->direct),
20350 community_list_config_str(entry));
20351 write++;
20352 }
20353
20354
20355 /* lcommunity-list. */
20356 cm = community_list_master_lookup(bgp_clist,
20357 LARGE_COMMUNITY_LIST_MASTER);
20358
20359 for (list = cm->num.head; list; list = list->next)
20360 for (entry = list->head; entry; entry = entry->next) {
20361 vty_out(vty,
20362 "bgp large-community-list %s seq %" PRId64" %s %s\n",
20363 list->name, entry->seq,
20364 community_direct_str(entry->direct),
20365 community_list_config_str(entry));
20366 write++;
20367 }
20368 for (list = cm->str.head; list; list = list->next)
20369 for (entry = list->head; entry; entry = entry->next) {
20370 vty_out(vty,
20371 "bgp large-community-list %s %s seq %" PRId64" %s %s\n",
20372
20373 entry->style == LARGE_COMMUNITY_LIST_STANDARD
20374 ? "standard"
20375 : "expanded",
20376 list->name, entry->seq, community_direct_str(entry->direct),
20377 community_list_config_str(entry));
20378 write++;
20379 }
20380
20381 return write;
20382 }
20383
20384 static int community_list_config_write(struct vty *vty);
20385 static struct cmd_node community_list_node = {
20386 .name = "community list",
20387 .node = COMMUNITY_LIST_NODE,
20388 .prompt = "",
20389 .config_write = community_list_config_write,
20390 };
20391
20392 static void community_list_vty(void)
20393 {
20394 install_node(&community_list_node);
20395
20396 /* Community-list. */
20397 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
20398 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
20399 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
20400 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
20401 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
20402 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
20403 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
20404 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
20405
20406 /* Extcommunity-list. */
20407 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
20408 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
20409 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
20410 install_element(CONFIG_NODE,
20411 &no_bgp_extcommunity_list_standard_all_list_cmd);
20412 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
20413 install_element(CONFIG_NODE,
20414 &no_bgp_extcommunity_list_expanded_all_list_cmd);
20415 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
20416 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
20417
20418 /* Large Community List */
20419 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
20420 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
20421 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
20422 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
20423 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
20424 install_element(CONFIG_NODE,
20425 &no_bgp_lcommunity_list_name_standard_all_cmd);
20426 install_element(CONFIG_NODE,
20427 &no_bgp_lcommunity_list_name_expanded_all_cmd);
20428 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
20429 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
20430 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
20431 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
20432 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
20433 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
20434 }