]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
*: require semicolon after DEFINE_HOOK & co.
[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 "prefix.h"
28 #include "plist.h"
29 #include "buffer.h"
30 #include "linklist.h"
31 #include "stream.h"
32 #include "thread.h"
33 #include "log.h"
34 #include "memory.h"
35 #include "lib_vty.h"
36 #include "hash.h"
37 #include "queue.h"
38 #include "filter.h"
39 #include "frrstr.h"
40
41 #include "bgpd/bgpd.h"
42 #include "bgpd/bgp_attr_evpn.h"
43 #include "bgpd/bgp_advertise.h"
44 #include "bgpd/bgp_attr.h"
45 #include "bgpd/bgp_aspath.h"
46 #include "bgpd/bgp_community.h"
47 #include "bgpd/bgp_ecommunity.h"
48 #include "bgpd/bgp_lcommunity.h"
49 #include "bgpd/bgp_damp.h"
50 #include "bgpd/bgp_debug.h"
51 #include "bgpd/bgp_errors.h"
52 #include "bgpd/bgp_fsm.h"
53 #include "bgpd/bgp_nexthop.h"
54 #include "bgpd/bgp_open.h"
55 #include "bgpd/bgp_regex.h"
56 #include "bgpd/bgp_route.h"
57 #include "bgpd/bgp_mplsvpn.h"
58 #include "bgpd/bgp_zebra.h"
59 #include "bgpd/bgp_table.h"
60 #include "bgpd/bgp_vty.h"
61 #include "bgpd/bgp_mpath.h"
62 #include "bgpd/bgp_packet.h"
63 #include "bgpd/bgp_updgrp.h"
64 #include "bgpd/bgp_bfd.h"
65 #include "bgpd/bgp_io.h"
66 #include "bgpd/bgp_evpn.h"
67 #include "bgpd/bgp_evpn_vty.h"
68 #include "bgpd/bgp_evpn_mh.h"
69 #include "bgpd/bgp_addpath.h"
70 #include "bgpd/bgp_mac.h"
71 #include "bgpd/bgp_flowspec.h"
72 #ifdef ENABLE_BGP_VNC
73 #include "bgpd/rfapi/bgp_rfapi_cfg.h"
74 #endif
75
76 #include "northbound.h"
77 #include "northbound_cli.h"
78 #include "bgpd/bgp_nb.h"
79
80
81 FRR_CFG_DEFAULT_BOOL(BGP_IMPORT_CHECK,
82 {
83 .val_bool = false,
84 .match_profile = "traditional",
85 .match_version = "< 7.4",
86 },
87 { .val_bool = true },
88 )
89 FRR_CFG_DEFAULT_BOOL(BGP_SHOW_HOSTNAME,
90 { .val_bool = true, .match_profile = "datacenter", },
91 { .val_bool = false },
92 )
93 FRR_CFG_DEFAULT_BOOL(BGP_SHOW_NEXTHOP_HOSTNAME,
94 { .val_bool = true, .match_profile = "datacenter", },
95 { .val_bool = false },
96 )
97 FRR_CFG_DEFAULT_BOOL(BGP_LOG_NEIGHBOR_CHANGES,
98 { .val_bool = true, .match_profile = "datacenter", },
99 { .val_bool = false },
100 )
101 FRR_CFG_DEFAULT_BOOL(BGP_DETERMINISTIC_MED,
102 { .val_bool = true, .match_profile = "datacenter", },
103 { .val_bool = false },
104 )
105 FRR_CFG_DEFAULT_ULONG(BGP_CONNECT_RETRY,
106 { .val_ulong = 10, .match_profile = "datacenter", },
107 { .val_ulong = 120 },
108 )
109 FRR_CFG_DEFAULT_ULONG(BGP_HOLDTIME,
110 { .val_ulong = 9, .match_profile = "datacenter", },
111 { .val_ulong = 180 },
112 )
113 FRR_CFG_DEFAULT_ULONG(BGP_KEEPALIVE,
114 { .val_ulong = 3, .match_profile = "datacenter", },
115 { .val_ulong = 60 },
116 )
117 FRR_CFG_DEFAULT_BOOL(BGP_EBGP_REQUIRES_POLICY,
118 { .val_bool = false, .match_profile = "datacenter", },
119 { .val_bool = false, .match_version = "< 7.4", },
120 { .val_bool = true },
121 )
122 FRR_CFG_DEFAULT_BOOL(BGP_SUPPRESS_DUPLICATES,
123 { .val_bool = false, .match_version = "< 7.6", },
124 { .val_bool = true },
125 )
126
127 DEFINE_HOOK(bgp_inst_config_write,
128 (struct bgp *bgp, struct vty *vty),
129 (bgp, vty));
130 DEFINE_HOOK(bgp_snmp_update_last_changed, (struct bgp *bgp), (bgp));
131
132 #define GR_NO_OPER \
133 "The Graceful Restart No Operation was executed as cmd same as previous one."
134 #define GR_INVALID \
135 "The Graceful Restart command used is not valid at this moment."
136 static struct peer_group *listen_range_exists(struct bgp *bgp,
137 struct prefix *range, int exact);
138
139 /* Show BGP peer's information. */
140 enum show_type {
141 show_all,
142 show_peer,
143 show_ipv4_all,
144 show_ipv6_all,
145 show_ipv4_peer,
146 show_ipv6_peer
147 };
148
149 static struct peer_group *listen_range_exists(struct bgp *bgp,
150 struct prefix *range, int exact);
151
152 static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
153 struct bgp *bgp,
154 bool use_json,
155 json_object *json);
156
157 static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
158 enum show_type type,
159 const char *ip_str,
160 afi_t afi, bool use_json);
161
162 static int peer_and_group_lookup_nb(struct vty *vty, const char *peer_str,
163 char *base_xpath, int xpath_len,
164 char *abs_xpath);
165
166 static enum node_type bgp_node_type(afi_t afi, safi_t safi)
167 {
168 switch (afi) {
169 case AFI_IP:
170 switch (safi) {
171 case SAFI_UNICAST:
172 return BGP_IPV4_NODE;
173 case SAFI_MULTICAST:
174 return BGP_IPV4M_NODE;
175 case SAFI_LABELED_UNICAST:
176 return BGP_IPV4L_NODE;
177 case SAFI_MPLS_VPN:
178 return BGP_VPNV4_NODE;
179 case SAFI_FLOWSPEC:
180 return BGP_FLOWSPECV4_NODE;
181 default:
182 /* not expected */
183 return BGP_IPV4_NODE;
184 }
185 break;
186 case AFI_IP6:
187 switch (safi) {
188 case SAFI_UNICAST:
189 return BGP_IPV6_NODE;
190 case SAFI_MULTICAST:
191 return BGP_IPV6M_NODE;
192 case SAFI_LABELED_UNICAST:
193 return BGP_IPV6L_NODE;
194 case SAFI_MPLS_VPN:
195 return BGP_VPNV6_NODE;
196 case SAFI_FLOWSPEC:
197 return BGP_FLOWSPECV6_NODE;
198 default:
199 /* not expected */
200 return BGP_IPV4_NODE;
201 }
202 break;
203 case AFI_L2VPN:
204 return BGP_EVPN_NODE;
205 case AFI_UNSPEC:
206 case AFI_MAX:
207 // We should never be here but to clarify the switch statement..
208 return BGP_IPV4_NODE;
209 }
210
211 // Impossible to happen
212 return BGP_IPV4_NODE;
213 }
214
215 static const char *get_afi_safi_vty_str(afi_t afi, safi_t safi)
216 {
217 if (afi == AFI_IP) {
218 if (safi == SAFI_UNICAST)
219 return "IPv4 Unicast";
220 if (safi == SAFI_MULTICAST)
221 return "IPv4 Multicast";
222 if (safi == SAFI_LABELED_UNICAST)
223 return "IPv4 Labeled Unicast";
224 if (safi == SAFI_MPLS_VPN)
225 return "IPv4 VPN";
226 if (safi == SAFI_ENCAP)
227 return "IPv4 Encap";
228 if (safi == SAFI_FLOWSPEC)
229 return "IPv4 Flowspec";
230 } else if (afi == AFI_IP6) {
231 if (safi == SAFI_UNICAST)
232 return "IPv6 Unicast";
233 if (safi == SAFI_MULTICAST)
234 return "IPv6 Multicast";
235 if (safi == SAFI_LABELED_UNICAST)
236 return "IPv6 Labeled Unicast";
237 if (safi == SAFI_MPLS_VPN)
238 return "IPv6 VPN";
239 if (safi == SAFI_ENCAP)
240 return "IPv6 Encap";
241 if (safi == SAFI_FLOWSPEC)
242 return "IPv6 Flowspec";
243 } else if (afi == AFI_L2VPN) {
244 if (safi == SAFI_EVPN)
245 return "L2VPN EVPN";
246 }
247
248 return "Unknown";
249 }
250
251 /*
252 * Please note that we have intentionally camelCased
253 * the return strings here. So if you want
254 * to use this function, please ensure you
255 * are doing this within json output
256 */
257 static const char *get_afi_safi_json_str(afi_t afi, safi_t safi)
258 {
259 if (afi == AFI_IP) {
260 if (safi == SAFI_UNICAST)
261 return "ipv4Unicast";
262 if (safi == SAFI_MULTICAST)
263 return "ipv4Multicast";
264 if (safi == SAFI_LABELED_UNICAST)
265 return "ipv4LabeledUnicast";
266 if (safi == SAFI_MPLS_VPN)
267 return "ipv4Vpn";
268 if (safi == SAFI_ENCAP)
269 return "ipv4Encap";
270 if (safi == SAFI_FLOWSPEC)
271 return "ipv4Flowspec";
272 } else if (afi == AFI_IP6) {
273 if (safi == SAFI_UNICAST)
274 return "ipv6Unicast";
275 if (safi == SAFI_MULTICAST)
276 return "ipv6Multicast";
277 if (safi == SAFI_LABELED_UNICAST)
278 return "ipv6LabeledUnicast";
279 if (safi == SAFI_MPLS_VPN)
280 return "ipv6Vpn";
281 if (safi == SAFI_ENCAP)
282 return "ipv6Encap";
283 if (safi == SAFI_FLOWSPEC)
284 return "ipv6Flowspec";
285 } else if (afi == AFI_L2VPN) {
286 if (safi == SAFI_EVPN)
287 return "l2VpnEvpn";
288 }
289
290 return "Unknown";
291 }
292
293 /* return string maps to afi-safi specific container names
294 * defined in bgp yang file.
295 */
296 const char *bgp_afi_safi_get_container_str(afi_t afi, safi_t safi)
297 {
298 if (afi == AFI_IP) {
299 if (safi == SAFI_UNICAST)
300 return "ipv4-unicast";
301 if (safi == SAFI_MULTICAST)
302 return "ipv4-multicast";
303 if (safi == SAFI_LABELED_UNICAST)
304 return "ipv4-labeled-unicast";
305 if (safi == SAFI_MPLS_VPN)
306 return "l3vpn-ipv4-unicast";
307 if (safi == SAFI_FLOWSPEC)
308 return "ipv4-flowspec";
309 } else if (afi == AFI_IP6) {
310 if (safi == SAFI_UNICAST)
311 return "ipv6-unicast";
312 if (safi == SAFI_MULTICAST)
313 return "ipv6-multicast";
314 if (safi == SAFI_LABELED_UNICAST)
315 return "ipv6-labeled-unicast";
316 if (safi == SAFI_MPLS_VPN)
317 return "l3vpn-ipv6-unicast";
318 if (safi == SAFI_FLOWSPEC)
319 return "ipv6-flowspec";
320 } else if (afi == AFI_L2VPN) {
321 if (safi == SAFI_EVPN)
322 return "l2vpn-evpn";
323 }
324
325 return "Unknown";
326 }
327
328 /* Utility function to get address family from current node. */
329 afi_t bgp_node_afi(struct vty *vty)
330 {
331 afi_t afi;
332 switch (vty->node) {
333 case BGP_IPV6_NODE:
334 case BGP_IPV6M_NODE:
335 case BGP_IPV6L_NODE:
336 case BGP_VPNV6_NODE:
337 case BGP_FLOWSPECV6_NODE:
338 afi = AFI_IP6;
339 break;
340 case BGP_EVPN_NODE:
341 afi = AFI_L2VPN;
342 break;
343 default:
344 afi = AFI_IP;
345 break;
346 }
347 return afi;
348 }
349
350 /* Utility function to get subsequent address family from current
351 node. */
352 safi_t bgp_node_safi(struct vty *vty)
353 {
354 safi_t safi;
355 switch (vty->node) {
356 case BGP_VPNV4_NODE:
357 case BGP_VPNV6_NODE:
358 safi = SAFI_MPLS_VPN;
359 break;
360 case BGP_IPV4M_NODE:
361 case BGP_IPV6M_NODE:
362 safi = SAFI_MULTICAST;
363 break;
364 case BGP_EVPN_NODE:
365 safi = SAFI_EVPN;
366 break;
367 case BGP_IPV4L_NODE:
368 case BGP_IPV6L_NODE:
369 safi = SAFI_LABELED_UNICAST;
370 break;
371 case BGP_FLOWSPECV4_NODE:
372 case BGP_FLOWSPECV6_NODE:
373 safi = SAFI_FLOWSPEC;
374 break;
375 default:
376 safi = SAFI_UNICAST;
377 break;
378 }
379 return safi;
380 }
381
382 /**
383 * Converts an AFI in string form to afi_t
384 *
385 * @param afi string, one of
386 * - "ipv4"
387 * - "ipv6"
388 * - "l2vpn"
389 * @return the corresponding afi_t
390 */
391 afi_t bgp_vty_afi_from_str(const char *afi_str)
392 {
393 afi_t afi = AFI_MAX; /* unknown */
394 if (strmatch(afi_str, "ipv4"))
395 afi = AFI_IP;
396 else if (strmatch(afi_str, "ipv6"))
397 afi = AFI_IP6;
398 else if (strmatch(afi_str, "l2vpn"))
399 afi = AFI_L2VPN;
400 return afi;
401 }
402
403 int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
404 afi_t *afi)
405 {
406 int ret = 0;
407 if (argv_find(argv, argc, "ipv4", index)) {
408 ret = 1;
409 if (afi)
410 *afi = AFI_IP;
411 } else if (argv_find(argv, argc, "ipv6", index)) {
412 ret = 1;
413 if (afi)
414 *afi = AFI_IP6;
415 } else if (argv_find(argv, argc, "l2vpn", index)) {
416 ret = 1;
417 if (afi)
418 *afi = AFI_L2VPN;
419 }
420 return ret;
421 }
422
423 /* supports <unicast|multicast|vpn|labeled-unicast> */
424 safi_t bgp_vty_safi_from_str(const char *safi_str)
425 {
426 safi_t safi = SAFI_MAX; /* unknown */
427 if (strmatch(safi_str, "multicast"))
428 safi = SAFI_MULTICAST;
429 else if (strmatch(safi_str, "unicast"))
430 safi = SAFI_UNICAST;
431 else if (strmatch(safi_str, "vpn"))
432 safi = SAFI_MPLS_VPN;
433 else if (strmatch(safi_str, "evpn"))
434 safi = SAFI_EVPN;
435 else if (strmatch(safi_str, "labeled-unicast"))
436 safi = SAFI_LABELED_UNICAST;
437 else if (strmatch(safi_str, "flowspec"))
438 safi = SAFI_FLOWSPEC;
439 return safi;
440 }
441
442 int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
443 safi_t *safi)
444 {
445 int ret = 0;
446 if (argv_find(argv, argc, "unicast", index)) {
447 ret = 1;
448 if (safi)
449 *safi = SAFI_UNICAST;
450 } else if (argv_find(argv, argc, "multicast", index)) {
451 ret = 1;
452 if (safi)
453 *safi = SAFI_MULTICAST;
454 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
455 ret = 1;
456 if (safi)
457 *safi = SAFI_LABELED_UNICAST;
458 } else if (argv_find(argv, argc, "vpn", index)) {
459 ret = 1;
460 if (safi)
461 *safi = SAFI_MPLS_VPN;
462 } else if (argv_find(argv, argc, "evpn", index)) {
463 ret = 1;
464 if (safi)
465 *safi = SAFI_EVPN;
466 } else if (argv_find(argv, argc, "flowspec", index)) {
467 ret = 1;
468 if (safi)
469 *safi = SAFI_FLOWSPEC;
470 }
471 return ret;
472 }
473
474 int bgp_get_vty(struct bgp **bgp, as_t *as, const char *name,
475 enum bgp_instance_type inst_type)
476 {
477 int ret = bgp_get(bgp, as, name, inst_type);
478
479 if (ret == BGP_CREATED) {
480 bgp_timers_set(*bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
481 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
482
483 if (DFLT_BGP_IMPORT_CHECK)
484 SET_FLAG((*bgp)->flags, BGP_FLAG_IMPORT_CHECK);
485 if (DFLT_BGP_SHOW_HOSTNAME)
486 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_HOSTNAME);
487 if (DFLT_BGP_SHOW_NEXTHOP_HOSTNAME)
488 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
489 if (DFLT_BGP_LOG_NEIGHBOR_CHANGES)
490 SET_FLAG((*bgp)->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
491 if (DFLT_BGP_DETERMINISTIC_MED)
492 SET_FLAG((*bgp)->flags, BGP_FLAG_DETERMINISTIC_MED);
493 if (DFLT_BGP_EBGP_REQUIRES_POLICY)
494 SET_FLAG((*bgp)->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
495 if (DFLT_BGP_SUPPRESS_DUPLICATES)
496 SET_FLAG((*bgp)->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
497
498 ret = BGP_SUCCESS;
499 }
500 return ret;
501 }
502
503 /*
504 * bgp_vty_find_and_parse_afi_safi_bgp
505 *
506 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
507 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
508 * to appropriate values for the calling function. This is to allow the
509 * calling function to make decisions appropriate for the show command
510 * that is being parsed.
511 *
512 * The show commands are generally of the form:
513 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
514 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
515 *
516 * Since we use argv_find if the show command in particular doesn't have:
517 * [ip]
518 * [<view|vrf> VIEWVRFNAME]
519 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
520 * The command parsing should still be ok.
521 *
522 * vty -> The vty for the command so we can output some useful data in
523 * the event of a parse error in the vrf.
524 * argv -> The command tokens
525 * argc -> How many command tokens we have
526 * idx -> The current place in the command, generally should be 0 for this
527 * function
528 * afi -> The parsed afi if it was included in the show command, returned here
529 * safi -> The parsed safi if it was included in the show command, returned here
530 * bgp -> Pointer to the bgp data structure we need to fill in.
531 * use_json -> json is configured or not
532 *
533 * The function returns the correct location in the parse tree for the
534 * last token found.
535 *
536 * Returns 0 for failure to parse correctly, else the idx position of where
537 * it found the last token.
538 */
539 int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
540 struct cmd_token **argv, int argc,
541 int *idx, afi_t *afi, safi_t *safi,
542 struct bgp **bgp, bool use_json)
543 {
544 char *vrf_name = NULL;
545
546 assert(afi);
547 assert(safi);
548 assert(bgp);
549
550 if (argv_find(argv, argc, "ip", idx))
551 *afi = AFI_IP;
552
553 if (argv_find(argv, argc, "view", idx))
554 vrf_name = argv[*idx + 1]->arg;
555 else if (argv_find(argv, argc, "vrf", idx)) {
556 vrf_name = argv[*idx + 1]->arg;
557 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
558 vrf_name = NULL;
559 }
560 if (vrf_name) {
561 if (strmatch(vrf_name, "all"))
562 *bgp = NULL;
563 else {
564 *bgp = bgp_lookup_by_name(vrf_name);
565 if (!*bgp) {
566 if (use_json) {
567 json_object *json = NULL;
568 json = json_object_new_object();
569 json_object_string_add(
570 json, "warning",
571 "View/Vrf is unknown");
572 vty_out(vty, "%s\n",
573 json_object_to_json_string_ext(json,
574 JSON_C_TO_STRING_PRETTY));
575 json_object_free(json);
576 }
577 else
578 vty_out(vty, "View/Vrf %s is unknown\n",
579 vrf_name);
580 *idx = 0;
581 return 0;
582 }
583 }
584 } else {
585 *bgp = bgp_get_default();
586 if (!*bgp) {
587 if (use_json) {
588 json_object *json = NULL;
589 json = json_object_new_object();
590 json_object_string_add(
591 json, "warning",
592 "Default BGP instance not found");
593 vty_out(vty, "%s\n",
594 json_object_to_json_string_ext(json,
595 JSON_C_TO_STRING_PRETTY));
596 json_object_free(json);
597 }
598 else
599 vty_out(vty,
600 "Default BGP instance not found\n");
601 *idx = 0;
602 return 0;
603 }
604 }
605
606 if (argv_find_and_parse_afi(argv, argc, idx, afi))
607 argv_find_and_parse_safi(argv, argc, idx, safi);
608
609 *idx += 1;
610 return *idx;
611 }
612
613 bool peer_address_self_check(struct bgp *bgp, union sockunion *su)
614 {
615 struct interface *ifp = NULL;
616
617 if (su->sa.sa_family == AF_INET)
618 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
619 else if (su->sa.sa_family == AF_INET6)
620 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
621 su->sin6.sin6_scope_id,
622 bgp->vrf_id);
623
624 if (ifp)
625 return true;
626
627 return false;
628 }
629
630 /* Utility function for looking up peer or peer group. */
631 /* This is used only for configuration, so disallow if attempted on
632 * a dynamic neighbor.
633 */
634 struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
635 {
636 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
637 int ret;
638 union sockunion su;
639 struct peer *peer = NULL;
640 struct peer_group *group = NULL;
641
642 if (!bgp) {
643 return NULL;
644 }
645
646 ret = str2sockunion(peer_str, &su);
647 if (ret == 0) {
648 /* IP address, locate peer. */
649 peer = peer_lookup(bgp, &su);
650 } else {
651 /* Not IP, could match either peer configured on interface or a
652 * group. */
653 peer = peer_lookup_by_conf_if(bgp, peer_str);
654 if (!peer)
655 group = peer_group_lookup(bgp, peer_str);
656 }
657
658 if (peer) {
659 if (peer_dynamic_neighbor(peer)) {
660 vty_out(vty,
661 "%% Operation not allowed on a dynamic neighbor\n");
662 return NULL;
663 }
664
665 return peer;
666 }
667
668 if (group)
669 return group->conf;
670
671 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
672
673 return NULL;
674 }
675
676 int bgp_nb_errmsg_return(char *errmsg, size_t errmsg_len, int ret)
677 {
678 const char *str = NULL;
679
680 switch (ret) {
681 case BGP_ERR_INVALID_VALUE:
682 str = "Invalid value";
683 break;
684 case BGP_ERR_INVALID_FLAG:
685 str = "Invalid flag";
686 break;
687 case BGP_ERR_PEER_GROUP_SHUTDOWN:
688 str = "Peer-group has been shutdown. Activate the peer-group first";
689 break;
690 case BGP_ERR_PEER_FLAG_CONFLICT:
691 str = "Can't set override-capability and strict-capability-match at the same time";
692 break;
693 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
694 str = "Specify remote-as or peer-group remote AS first";
695 break;
696 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
697 str = "Cannot change the peer-group. Deconfigure first";
698 break;
699 case BGP_ERR_PEER_GROUP_MISMATCH:
700 str = "Peer is not a member of this peer-group";
701 break;
702 case BGP_ERR_PEER_FILTER_CONFLICT:
703 str = "Prefix/distribute list can not co-exist";
704 break;
705 case BGP_ERR_NOT_INTERNAL_PEER:
706 str = "Invalid command. Not an internal neighbor";
707 break;
708 case BGP_ERR_REMOVE_PRIVATE_AS:
709 str = "remove-private-AS cannot be configured for IBGP peers";
710 break;
711 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
712 str = "Local-AS allowed only for EBGP peers";
713 break;
714 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
715 str = "Cannot have local-as same as BGP AS number";
716 break;
717 case BGP_ERR_TCPSIG_FAILED:
718 str = "Error while applying TCP-Sig to session(s)";
719 break;
720 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
721 str = "ebgp-multihop and ttl-security cannot be configured together";
722 break;
723 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
724 str = "ttl-security only allowed for EBGP peers";
725 break;
726 case BGP_ERR_AS_OVERRIDE:
727 str = "as-override cannot be configured for IBGP peers";
728 break;
729 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
730 str = "Invalid limit for number of dynamic neighbors";
731 break;
732 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
733 str = "Dynamic neighbor listen range already exists";
734 break;
735 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
736 str = "Operation not allowed on a dynamic neighbor";
737 break;
738 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
739 str = "Operation not allowed on a directly connected neighbor";
740 break;
741 case BGP_ERR_PEER_SAFI_CONFLICT:
742 str = GR_INVALID;
743 break;
744 case BGP_ERR_GR_INVALID_CMD:
745 str = "The Graceful Restart command used is not valid at this moment.";
746 break;
747 case BGP_ERR_GR_OPERATION_FAILED:
748 str = "The Graceful Restart Operation failed due to an err.";
749 break;
750 case BGP_GR_NO_OPERATION:
751 str = GR_NO_OPER;
752 break;
753 case BGP_ERR_PEER_GROUP_MEMBER:
754 str = "Peer-group member cannot override remote-as of peer-group";
755 break;
756 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
757 str = "Peer-group members must be all internal or all external";
758 break;
759 }
760 if (str) {
761 snprintf(errmsg, errmsg_len, "%s", str);
762 return -1;
763 }
764
765 return 0;
766 }
767
768 int bgp_vty_return(struct vty *vty, int ret)
769 {
770 const char *str = NULL;
771
772 switch (ret) {
773 case BGP_ERR_INVALID_VALUE:
774 str = "Invalid value";
775 break;
776 case BGP_ERR_INVALID_FLAG:
777 str = "Invalid flag";
778 break;
779 case BGP_ERR_PEER_GROUP_SHUTDOWN:
780 str = "Peer-group has been shutdown. Activate the peer-group first";
781 break;
782 case BGP_ERR_PEER_FLAG_CONFLICT:
783 str = "Can't set override-capability and strict-capability-match at the same time";
784 break;
785 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
786 str = "Specify remote-as or peer-group remote AS first";
787 break;
788 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
789 str = "Cannot change the peer-group. Deconfigure first";
790 break;
791 case BGP_ERR_PEER_GROUP_MISMATCH:
792 str = "Peer is not a member of this peer-group";
793 break;
794 case BGP_ERR_PEER_FILTER_CONFLICT:
795 str = "Prefix/distribute list can not co-exist";
796 break;
797 case BGP_ERR_NOT_INTERNAL_PEER:
798 str = "Invalid command. Not an internal neighbor";
799 break;
800 case BGP_ERR_REMOVE_PRIVATE_AS:
801 str = "remove-private-AS cannot be configured for IBGP peers";
802 break;
803 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
804 str = "Local-AS allowed only for EBGP peers";
805 break;
806 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
807 str = "Cannot have local-as same as BGP AS number";
808 break;
809 case BGP_ERR_TCPSIG_FAILED:
810 str = "Error while applying TCP-Sig to session(s)";
811 break;
812 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
813 str = "ebgp-multihop and ttl-security cannot be configured together";
814 break;
815 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
816 str = "ttl-security only allowed for EBGP peers";
817 break;
818 case BGP_ERR_AS_OVERRIDE:
819 str = "as-override cannot be configured for IBGP peers";
820 break;
821 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
822 str = "Invalid limit for number of dynamic neighbors";
823 break;
824 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
825 str = "Dynamic neighbor listen range already exists";
826 break;
827 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
828 str = "Operation not allowed on a dynamic neighbor";
829 break;
830 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
831 str = "Operation not allowed on a directly connected neighbor";
832 break;
833 case BGP_ERR_PEER_SAFI_CONFLICT:
834 str = GR_INVALID;
835 break;
836 case BGP_ERR_GR_INVALID_CMD:
837 str = "The Graceful Restart command used is not valid at this moment.";
838 break;
839 case BGP_ERR_GR_OPERATION_FAILED:
840 str = "The Graceful Restart Operation failed due to an err.";
841 break;
842 case BGP_GR_NO_OPERATION:
843 str = GR_NO_OPER;
844 break;
845 }
846 if (str) {
847 vty_out(vty, "%% %s\n", str);
848 return CMD_WARNING_CONFIG_FAILED;
849 }
850 return CMD_SUCCESS;
851 }
852
853 /* BGP clear sort. */
854 enum clear_sort {
855 clear_all,
856 clear_peer,
857 clear_group,
858 clear_external,
859 clear_as
860 };
861
862 static void bgp_clear_vty_error(struct peer *peer, afi_t afi, safi_t safi,
863 int error, char *errmsg, size_t errmsg_len)
864 {
865 switch (error) {
866 case BGP_ERR_AF_UNCONFIGURED:
867 snprintf(errmsg, errmsg_len,
868 "%%BGP: Enable %s address family for the neighbor %s",
869 get_afi_safi_str(afi, safi, false), peer->host);
870 break;
871 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
872 snprintf(
873 errmsg, errmsg_len,
874 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig",
875 peer->host);
876 break;
877 default:
878 break;
879 }
880 }
881
882 static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi,
883 struct listnode **nnode, enum bgp_clear_type stype)
884 {
885 int ret = 0;
886 struct peer_af *paf;
887
888 /* if afi/.safi not specified, spin thru all of them */
889 if ((afi == AFI_UNSPEC) && (safi == SAFI_UNSPEC)) {
890 afi_t tmp_afi;
891 safi_t tmp_safi;
892
893 FOREACH_AFI_SAFI (tmp_afi, tmp_safi) {
894 paf = peer_af_find(peer, tmp_afi, tmp_safi);
895 if (paf && paf->subgroup)
896 SET_FLAG(paf->subgroup->sflags,
897 SUBGRP_STATUS_FORCE_UPDATES);
898
899 if (!peer->afc[tmp_afi][tmp_safi])
900 continue;
901
902 if (stype == BGP_CLEAR_SOFT_NONE)
903 ret = peer_clear(peer, nnode);
904 else
905 ret = peer_clear_soft(peer, tmp_afi, tmp_safi,
906 stype);
907 }
908 /* if afi specified and safi not, spin thru safis on this afi */
909 } else if (safi == SAFI_UNSPEC) {
910 safi_t tmp_safi;
911
912 for (tmp_safi = SAFI_UNICAST;
913 tmp_safi < SAFI_MAX; tmp_safi++) {
914 if (!peer->afc[afi][tmp_safi])
915 continue;
916
917 paf = peer_af_find(peer, afi, tmp_safi);
918 if (paf && paf->subgroup)
919 SET_FLAG(paf->subgroup->sflags,
920 SUBGRP_STATUS_FORCE_UPDATES);
921
922 if (stype == BGP_CLEAR_SOFT_NONE)
923 ret = peer_clear(peer, nnode);
924 else
925 ret = peer_clear_soft(peer, afi,
926 tmp_safi, stype);
927 }
928 /* both afi/safi specified, let the caller know if not defined */
929 } else {
930 if (!peer->afc[afi][safi])
931 return 1;
932
933 paf = peer_af_find(peer, afi, safi);
934 if (paf && paf->subgroup)
935 SET_FLAG(paf->subgroup->sflags,
936 SUBGRP_STATUS_FORCE_UPDATES);
937
938 if (stype == BGP_CLEAR_SOFT_NONE)
939 ret = peer_clear(peer, nnode);
940 else
941 ret = peer_clear_soft(peer, afi, safi, stype);
942 }
943
944 return ret;
945 }
946
947 /* `clear ip bgp' functions. */
948 static int bgp_clear(struct bgp *bgp, afi_t afi, safi_t safi,
949 enum clear_sort sort, enum bgp_clear_type stype,
950 const char *arg, char *errmsg, size_t errmsg_len)
951 {
952 int ret = 0;
953 bool found = false;
954 struct peer *peer;
955
956 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
957
958 /* Clear all neighbors. */
959 /*
960 * Pass along pointer to next node to peer_clear() when walking all
961 * nodes on the BGP instance as that may get freed if it is a
962 * doppelganger
963 */
964 if (sort == clear_all) {
965 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
966
967 bgp_peer_gr_flags_update(peer);
968
969 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
970 gr_router_detected = true;
971
972 ret = bgp_peer_clear(peer, afi, safi, &nnode,
973 stype);
974
975 if (ret < 0)
976 bgp_clear_vty_error(peer, afi, safi, ret,
977 errmsg, errmsg_len);
978 }
979
980 if (gr_router_detected
981 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
982 bgp_zebra_send_capabilities(bgp, false);
983 } else if (!gr_router_detected
984 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
985 bgp_zebra_send_capabilities(bgp, true);
986 }
987
988 /* This is to apply read-only mode on this clear. */
989 if (stype == BGP_CLEAR_SOFT_NONE)
990 bgp->update_delay_over = 0;
991
992 return CMD_SUCCESS;
993 }
994
995 /* Clear specified neighbor. */
996 if (sort == clear_peer) {
997 union sockunion su;
998
999 /* Make sockunion for lookup. */
1000 ret = str2sockunion(arg, &su);
1001 if (ret < 0) {
1002 peer = peer_lookup_by_conf_if(bgp, arg);
1003 if (!peer) {
1004 peer = peer_lookup_by_hostname(bgp, arg);
1005 if (!peer) {
1006 snprintf(
1007 errmsg, errmsg_len,
1008 "Malformed address or name: %s",
1009 arg);
1010 return CMD_WARNING;
1011 }
1012 }
1013 } else {
1014 peer = peer_lookup(bgp, &su);
1015 if (!peer) {
1016 snprintf(errmsg, errmsg_len,
1017 "%%BGP: Unknown neighbor - \"%s\"",
1018 arg);
1019 return CMD_WARNING;
1020 }
1021 }
1022
1023 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
1024 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
1025
1026 ret = bgp_peer_clear(peer, afi, safi, NULL, stype);
1027
1028 /* if afi/safi not defined for this peer, let caller know */
1029 if (ret == 1)
1030 ret = BGP_ERR_AF_UNCONFIGURED;
1031
1032 if (ret < 0)
1033 bgp_clear_vty_error(peer, afi, safi, ret, errmsg,
1034 errmsg_len);
1035
1036 return CMD_SUCCESS;
1037 }
1038
1039 /* Clear all neighbors belonging to a specific peer-group. */
1040 if (sort == clear_group) {
1041 struct peer_group *group;
1042
1043 group = peer_group_lookup(bgp, arg);
1044 if (!group) {
1045 snprintf(errmsg, errmsg_len,
1046 "%%BGP: No such peer-group %s", arg);
1047 return CMD_WARNING;
1048 }
1049
1050 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
1051 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1052
1053 if (ret < 0)
1054 bgp_clear_vty_error(peer, afi, safi, ret,
1055 errmsg, errmsg_len);
1056 else
1057 found = true;
1058 }
1059
1060 if (!found)
1061 snprintf(
1062 errmsg, errmsg_len,
1063 "%%BGP: No %s peer belonging to peer-group %s is configured",
1064 get_afi_safi_str(afi, safi, false), arg);
1065
1066 return CMD_SUCCESS;
1067 }
1068
1069 /* Clear all external (eBGP) neighbors. */
1070 if (sort == clear_external) {
1071 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1072 if (peer->sort == BGP_PEER_IBGP)
1073 continue;
1074
1075 bgp_peer_gr_flags_update(peer);
1076
1077 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1078 gr_router_detected = true;
1079
1080 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1081
1082 if (ret < 0)
1083 bgp_clear_vty_error(peer, afi, safi, ret,
1084 errmsg, errmsg_len);
1085 else
1086 found = true;
1087 }
1088
1089 if (gr_router_detected
1090 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1091 bgp_zebra_send_capabilities(bgp, false);
1092 } else if (!gr_router_detected
1093 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1094 bgp_zebra_send_capabilities(bgp, true);
1095 }
1096
1097 if (!found)
1098 snprintf(errmsg, errmsg_len,
1099 "%%BGP: No external %s peer is configured",
1100 get_afi_safi_str(afi, safi, false));
1101
1102 return CMD_SUCCESS;
1103 }
1104
1105 /* Clear all neighbors belonging to a specific AS. */
1106 if (sort == clear_as) {
1107 as_t as = strtoul(arg, NULL, 10);
1108
1109 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1110 if (peer->as != as)
1111 continue;
1112
1113 bgp_peer_gr_flags_update(peer);
1114
1115 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1116 gr_router_detected = true;
1117
1118 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1119
1120 if (ret < 0)
1121 bgp_clear_vty_error(peer, afi, safi, ret,
1122 errmsg, errmsg_len);
1123 else
1124 found = true;
1125 }
1126
1127 if (gr_router_detected
1128 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1129 bgp_zebra_send_capabilities(bgp, false);
1130 } else if (!gr_router_detected
1131 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1132 bgp_zebra_send_capabilities(bgp, true);
1133 }
1134
1135 if (!found)
1136 snprintf(errmsg, errmsg_len,
1137 "%%BGP: No %s peer is configured with AS %s",
1138 get_afi_safi_str(afi, safi, false), arg);
1139
1140 return CMD_SUCCESS;
1141 }
1142
1143 return CMD_SUCCESS;
1144 }
1145
1146 static int bgp_clear_vty(const char *name, afi_t afi, safi_t safi,
1147 enum clear_sort sort, enum bgp_clear_type stype,
1148 const char *arg, char *errmsg, size_t errmsg_len)
1149 {
1150 struct bgp *bgp;
1151
1152 /* BGP structure lookup. */
1153 if (name) {
1154 bgp = bgp_lookup_by_name(name);
1155 if (bgp == NULL) {
1156 snprintf(errmsg, errmsg_len,
1157 "Can't find BGP instance %s", name);
1158 return CMD_WARNING;
1159 }
1160 } else {
1161 bgp = bgp_get_default();
1162 if (bgp == NULL) {
1163 snprintf(errmsg, errmsg_len,
1164 "No BGP process is configured");
1165 return CMD_WARNING;
1166 }
1167 }
1168
1169 return bgp_clear(bgp, afi, safi, sort, stype, arg, errmsg, errmsg_len);
1170 }
1171
1172 /* clear soft inbound */
1173 int bgp_clear_star_soft_in(const char *name, char *errmsg, size_t errmsg_len)
1174 {
1175 afi_t afi;
1176 safi_t safi;
1177 int ret;
1178
1179 FOREACH_AFI_SAFI (afi, safi) {
1180 ret = bgp_clear_vty(name, afi, safi, clear_all,
1181 BGP_CLEAR_SOFT_IN, NULL, errmsg,
1182 errmsg_len);
1183 if (ret != CMD_SUCCESS)
1184 return -1;
1185 }
1186
1187 return 0;
1188 }
1189
1190 /* clear soft outbound */
1191 int bgp_clear_star_soft_out(const char *name, char *errmsg, size_t errmsg_len)
1192 {
1193 afi_t afi;
1194 safi_t safi;
1195 int ret;
1196
1197 FOREACH_AFI_SAFI (afi, safi) {
1198 ret = bgp_clear_vty(name, afi, safi, clear_all,
1199 BGP_CLEAR_SOFT_OUT, NULL, errmsg,
1200 errmsg_len);
1201 if (ret != CMD_SUCCESS)
1202 return -1;
1203 }
1204
1205 return 0;
1206 }
1207
1208
1209 #ifndef VTYSH_EXTRACT_PL
1210 #include "bgpd/bgp_vty_clippy.c"
1211 #endif
1212
1213 DEFUN_HIDDEN (bgp_local_mac,
1214 bgp_local_mac_cmd,
1215 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
1216 BGP_STR
1217 "Local MAC config\n"
1218 "VxLAN Network Identifier\n"
1219 "VNI number\n"
1220 "local mac\n"
1221 "mac address\n"
1222 "mac-mobility sequence\n"
1223 "seq number\n")
1224 {
1225 int rv;
1226 vni_t vni;
1227 struct ethaddr mac;
1228 struct ipaddr ip;
1229 uint32_t seq;
1230 struct bgp *bgp;
1231
1232 vni = strtoul(argv[3]->arg, NULL, 10);
1233 if (!prefix_str2mac(argv[5]->arg, &mac)) {
1234 vty_out(vty, "%% Malformed MAC address\n");
1235 return CMD_WARNING;
1236 }
1237 memset(&ip, 0, sizeof(ip));
1238 seq = strtoul(argv[7]->arg, NULL, 10);
1239
1240 bgp = bgp_get_default();
1241 if (!bgp) {
1242 vty_out(vty, "Default BGP instance is not there\n");
1243 return CMD_WARNING;
1244 }
1245
1246 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq,
1247 zero_esi);
1248 if (rv < 0) {
1249 vty_out(vty, "Internal error\n");
1250 return CMD_WARNING;
1251 }
1252
1253 return CMD_SUCCESS;
1254 }
1255
1256 DEFUN_HIDDEN (no_bgp_local_mac,
1257 no_bgp_local_mac_cmd,
1258 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
1259 NO_STR
1260 BGP_STR
1261 "Local MAC config\n"
1262 "VxLAN Network Identifier\n"
1263 "VNI number\n"
1264 "local mac\n"
1265 "mac address\n")
1266 {
1267 int rv;
1268 vni_t vni;
1269 struct ethaddr mac;
1270 struct ipaddr ip;
1271 struct bgp *bgp;
1272
1273 vni = strtoul(argv[4]->arg, NULL, 10);
1274 if (!prefix_str2mac(argv[6]->arg, &mac)) {
1275 vty_out(vty, "%% Malformed MAC address\n");
1276 return CMD_WARNING;
1277 }
1278 memset(&ip, 0, sizeof(ip));
1279
1280 bgp = bgp_get_default();
1281 if (!bgp) {
1282 vty_out(vty, "Default BGP instance is not there\n");
1283 return CMD_WARNING;
1284 }
1285
1286 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
1287 if (rv < 0) {
1288 vty_out(vty, "Internal error\n");
1289 return CMD_WARNING;
1290 }
1291
1292 return CMD_SUCCESS;
1293 }
1294
1295 DEFUN (no_synchronization,
1296 no_synchronization_cmd,
1297 "no synchronization",
1298 NO_STR
1299 "Perform IGP synchronization\n")
1300 {
1301 return CMD_SUCCESS;
1302 }
1303
1304 DEFUN (no_auto_summary,
1305 no_auto_summary_cmd,
1306 "no auto-summary",
1307 NO_STR
1308 "Enable automatic network number summarization\n")
1309 {
1310 return CMD_SUCCESS;
1311 }
1312
1313 /* "router bgp" commands. */
1314 DEFUN_YANG_NOSH(router_bgp,
1315 router_bgp_cmd,
1316 "router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1317 ROUTER_STR BGP_STR AS_STR BGP_INSTANCE_HELP_STR)
1318 {
1319 int idx_asn = 2;
1320 int idx_view_vrf = 3;
1321 int idx_vrf = 4;
1322 int ret = CMD_SUCCESS;
1323 as_t as;
1324 struct bgp *bgp;
1325 const char *name = NULL;
1326 char as_str[12] = {'\0'};
1327 enum bgp_instance_type inst_type;
1328 char base_xpath[XPATH_MAXLEN];
1329
1330 // "router bgp" without an ASN
1331 if (argc == 2) {
1332 // Pending: Make VRF option available for ASN less config
1333 bgp = bgp_get_default();
1334
1335 if (bgp == NULL) {
1336 vty_out(vty, "%% No BGP process is configured\n");
1337 return CMD_WARNING_CONFIG_FAILED;
1338 }
1339
1340 if (listcount(bm->bgp) > 1) {
1341 vty_out(vty, "%% Please specify ASN and VRF\n");
1342 return CMD_WARNING_CONFIG_FAILED;
1343 }
1344
1345 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_GLOBAL_XPATH,
1346 "frr-bgp:bgp", "bgp", VRF_DEFAULT_NAME);
1347
1348 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
1349 snprintf(as_str, 12, "%d", bgp->as);
1350 nb_cli_enqueue_change(vty, "./global/local-as", NB_OP_MODIFY,
1351 as_str);
1352 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW) {
1353 nb_cli_enqueue_change(vty,
1354 "./global/instance-type-view",
1355 NB_OP_MODIFY, "true");
1356 }
1357
1358 nb_cli_pending_commit_check(vty);
1359 ret = nb_cli_apply_changes(vty, base_xpath);
1360 if (ret == CMD_SUCCESS) {
1361 VTY_PUSH_XPATH(BGP_NODE, base_xpath);
1362
1363 /*
1364 * For backward compatibility with old commands we still
1365 * need to use the qobj infrastructure.
1366 */
1367 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1368 }
1369 return ret;
1370 }
1371
1372 // "router bgp X"
1373 else {
1374
1375 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1376 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1377 if (argc > 3) {
1378 name = argv[idx_vrf]->arg;
1379
1380 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1381 if (strmatch(name, VRF_DEFAULT_NAME))
1382 name = NULL;
1383 else
1384 inst_type = BGP_INSTANCE_TYPE_VRF;
1385 } else if (!strcmp(argv[idx_view_vrf]->text, "view")) {
1386 inst_type = BGP_INSTANCE_TYPE_VIEW;
1387 }
1388 }
1389 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_GLOBAL_XPATH,
1390 "frr-bgp:bgp", "bgp", name ? name : VRF_DEFAULT_NAME);
1391
1392 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
1393 nb_cli_enqueue_change(vty, "./global/local-as", NB_OP_MODIFY,
1394 argv[idx_asn]->arg);
1395 if (inst_type == BGP_INSTANCE_TYPE_VIEW) {
1396 nb_cli_enqueue_change(vty,
1397 "./global/instance-type-view",
1398 NB_OP_MODIFY, "true");
1399 }
1400
1401 nb_cli_pending_commit_check(vty);
1402 ret = nb_cli_apply_changes(vty, base_xpath);
1403 if (ret == CMD_SUCCESS) {
1404 VTY_PUSH_XPATH(BGP_NODE, base_xpath);
1405
1406 /*
1407 * For backward compatibility with old commands we still
1408 * need to use the qobj infrastructure.
1409 */
1410 bgp = bgp_lookup(as, name);
1411 if (bgp)
1412 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1413 }
1414 }
1415
1416 return ret;
1417 }
1418
1419 /* "no router bgp" commands. */
1420 DEFUN_YANG(no_router_bgp,
1421 no_router_bgp_cmd,
1422 "no router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1423 NO_STR ROUTER_STR BGP_STR AS_STR BGP_INSTANCE_HELP_STR)
1424 {
1425 int idx_asn = 3;
1426 int idx_vrf = 5;
1427 as_t as = 0;
1428 struct bgp *bgp;
1429 const char *name = NULL;
1430 char base_xpath[XPATH_MAXLEN];
1431 const struct lyd_node *bgp_glb_dnode;
1432
1433 // "no router bgp" without an ASN
1434 if (argc == 3) {
1435 // Pending: Make VRF option available for ASN less config
1436 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_GLOBAL_XPATH,
1437 "frr-bgp:bgp", "bgp", VRF_DEFAULT_NAME);
1438
1439 bgp_glb_dnode = yang_dnode_get(vty->candidate_config->dnode,
1440 base_xpath);
1441 if (!bgp_glb_dnode) {
1442 vty_out(vty, "%% No BGP process is configured\n");
1443 return CMD_WARNING_CONFIG_FAILED;
1444 }
1445
1446 if (listcount(bm->bgp) > 1) {
1447 vty_out(vty, "%% Please specify ASN and VRF\n");
1448 return CMD_WARNING_CONFIG_FAILED;
1449 }
1450
1451 /* tcli mode bgp would not be set until apply stage. */
1452 bgp = nb_running_get_entry(bgp_glb_dnode, NULL, false);
1453 if (!bgp)
1454 return CMD_SUCCESS;
1455
1456 if (bgp->l3vni) {
1457 vty_out(vty, "%% Please unconfigure l3vni %u",
1458 bgp->l3vni);
1459 return CMD_WARNING_CONFIG_FAILED;
1460 }
1461 } else {
1462 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1463
1464 if (argc > 4)
1465 name = argv[idx_vrf]->arg;
1466
1467 /* Lookup bgp structure. */
1468 bgp = bgp_lookup(as, name);
1469 if (!bgp) {
1470 vty_out(vty, "%% Can't find BGP instance\n");
1471 return CMD_WARNING_CONFIG_FAILED;
1472 }
1473
1474 if (bgp->l3vni) {
1475 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1476 bgp->l3vni);
1477 return CMD_WARNING_CONFIG_FAILED;
1478 }
1479
1480 /* Cannot delete default instance if vrf instances exist */
1481 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
1482 struct listnode *node;
1483 struct bgp *tmp_bgp;
1484
1485 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, tmp_bgp)) {
1486 if (tmp_bgp->inst_type != BGP_INSTANCE_TYPE_VRF)
1487 continue;
1488 if (CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1489 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1490 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1491 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1492 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1493 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1494 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1495 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1496 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1497 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1498 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1499 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1500 (bgp == bgp_get_evpn() &&
1501 (CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1502 BGP_L2VPN_EVPN_ADVERTISE_IPV4_UNICAST) ||
1503 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1504 BGP_L2VPN_EVPN_ADVERTISE_IPV6_UNICAST))) ||
1505 (tmp_bgp->vnihash && hashcount(tmp_bgp->vnihash))) {
1506 vty_out(vty,
1507 "%% Cannot delete default BGP instance. Dependent VRF instances exist\n");
1508 return CMD_WARNING_CONFIG_FAILED;
1509 }
1510 }
1511 }
1512 }
1513 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_GLOBAL_XPATH,
1514 "frr-bgp:bgp", "bgp",
1515 bgp->name ? bgp->name : VRF_DEFAULT_NAME);
1516
1517 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
1518
1519 return nb_cli_apply_changes(vty, base_xpath);
1520 }
1521
1522 void cli_show_router_bgp(struct vty *vty, struct lyd_node *dnode,
1523 bool show_defaults)
1524 {
1525 const struct lyd_node *vrf_dnode;
1526 const char *vrf_name;
1527 as_t as;
1528
1529 vrf_dnode = yang_dnode_get_parent(dnode, "control-plane-protocol");
1530 vrf_name = yang_dnode_get_string(vrf_dnode, "./vrf");
1531 as = yang_dnode_get_uint32(dnode, "./global/local-as");
1532
1533 vty_out(vty, "!\n");
1534 vty_out(vty, "router bgp %u", as);
1535 if (!strmatch(vrf_name, VRF_DEFAULT_NAME))
1536 vty_out(vty, " vrf %s", vrf_name);
1537 vty_out(vty, "\n");
1538 }
1539
1540 /* BGP router-id. */
1541
1542 DEFPY_YANG(bgp_router_id, bgp_router_id_cmd, "bgp router-id A.B.C.D",
1543 BGP_STR
1544 "Override configured router identifier\n"
1545 "Manually configured router identifier\n")
1546 {
1547 nb_cli_enqueue_change(vty, "./global/router-id", NB_OP_MODIFY,
1548 router_id_str);
1549
1550 return nb_cli_apply_changes(vty, NULL);
1551 }
1552
1553 DEFPY_YANG(no_bgp_router_id, no_bgp_router_id_cmd, "no bgp router-id [A.B.C.D]",
1554 NO_STR BGP_STR
1555 "Override configured router identifier\n"
1556 "Manually configured router identifier\n")
1557 {
1558 nb_cli_enqueue_change(vty, "./global/router-id", NB_OP_DESTROY,
1559 router_id_str ? router_id_str : NULL);
1560
1561 return nb_cli_apply_changes(vty, NULL);
1562 }
1563
1564 void cli_show_router_bgp_router_id(struct vty *vty, struct lyd_node *dnode,
1565 bool show_defaults)
1566 {
1567 vty_out(vty, " bgp router-id %s\n", yang_dnode_get_string(dnode, NULL));
1568 }
1569
1570 DEFPY (bgp_global_suppress_fib_pending,
1571 bgp_global_suppress_fib_pending_cmd,
1572 "[no] bgp suppress-fib-pending",
1573 NO_STR
1574 BGP_STR
1575 "Advertise only routes that are programmed in kernel to peers globally\n")
1576 {
1577 bm_wait_for_fib_set(!no);
1578
1579 return CMD_SUCCESS;
1580 }
1581
1582 DEFPY (bgp_suppress_fib_pending,
1583 bgp_suppress_fib_pending_cmd,
1584 "[no] bgp suppress-fib-pending",
1585 NO_STR
1586 BGP_STR
1587 "Advertise only routes that are programmed in kernel to peers\n")
1588 {
1589 VTY_DECLVAR_CONTEXT(bgp, bgp);
1590
1591 bgp_suppress_fib_pending_set(bgp, !no);
1592 return CMD_SUCCESS;
1593 }
1594
1595
1596 /* BGP Cluster ID. */
1597 DEFUN_YANG(bgp_cluster_id,
1598 bgp_cluster_id_cmd,
1599 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1600 BGP_STR
1601 "Configure Route-Reflector Cluster-id\n"
1602 "Route-Reflector Cluster-id in IP address format\n"
1603 "Route-Reflector Cluster-id as 32 bit quantity\n")
1604 {
1605 int idx_ipv4 = 2;
1606
1607 nb_cli_enqueue_change(
1608 vty, "./global/route-reflector/route-reflector-cluster-id",
1609 NB_OP_MODIFY, argv[idx_ipv4]->arg);
1610
1611 return nb_cli_apply_changes(vty, NULL);
1612 }
1613
1614 DEFUN_YANG(no_bgp_cluster_id,
1615 no_bgp_cluster_id_cmd,
1616 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1617 NO_STR BGP_STR
1618 "Configure Route-Reflector Cluster-id\n"
1619 "Route-Reflector Cluster-id in IP address format\n"
1620 "Route-Reflector Cluster-id as 32 bit quantity\n")
1621 {
1622 nb_cli_enqueue_change(
1623 vty, "./global/route-reflector/route-reflector-cluster-id",
1624 NB_OP_DESTROY, NULL);
1625
1626 return nb_cli_apply_changes(vty, NULL);
1627 }
1628
1629 DEFPY (bgp_norib,
1630 bgp_norib_cmd,
1631 "bgp no-rib",
1632 BGP_STR
1633 "Disable BGP route installation to RIB (Zebra)\n")
1634 {
1635 if (bgp_option_check(BGP_OPT_NO_FIB)) {
1636 vty_out(vty,
1637 "%% No-RIB option is already set, nothing to do here.\n");
1638 return CMD_SUCCESS;
1639 }
1640
1641 bgp_option_norib_set_runtime();
1642
1643 return CMD_SUCCESS;
1644 }
1645
1646 DEFPY (no_bgp_norib,
1647 no_bgp_norib_cmd,
1648 "no bgp no-rib",
1649 NO_STR
1650 BGP_STR
1651 "Disable BGP route installation to RIB (Zebra)\n")
1652 {
1653 if (!bgp_option_check(BGP_OPT_NO_FIB)) {
1654 vty_out(vty,
1655 "%% No-RIB option is not set, nothing to do here.\n");
1656 return CMD_SUCCESS;
1657 }
1658
1659 bgp_option_norib_unset_runtime();
1660
1661 return CMD_SUCCESS;
1662 }
1663
1664 DEFPY (no_bgp_send_extra_data,
1665 no_bgp_send_extra_data_cmd,
1666 "[no] bgp send-extra-data zebra",
1667 NO_STR
1668 BGP_STR
1669 "Extra data to Zebra for display/use\n"
1670 "To zebra\n")
1671 {
1672 if (no)
1673 UNSET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1674 else
1675 SET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1676
1677 return CMD_SUCCESS;
1678 }
1679
1680 DEFUN_YANG(bgp_confederation_identifier,
1681 bgp_confederation_identifier_cmd,
1682 "bgp confederation identifier (1-4294967295)",
1683 "BGP specific commands\n"
1684 "AS confederation parameters\n"
1685 "AS number\n"
1686 "Set routing domain confederation AS\n")
1687 {
1688 int idx_number = 3;
1689
1690 nb_cli_enqueue_change(vty, "./global/confederation/identifier",
1691 NB_OP_MODIFY, argv[idx_number]->arg);
1692
1693 return nb_cli_apply_changes(vty, NULL);
1694 }
1695
1696 DEFUN_YANG(no_bgp_confederation_identifier,
1697 no_bgp_confederation_identifier_cmd,
1698 "no bgp confederation identifier [(1-4294967295)]",
1699 NO_STR
1700 "BGP specific commands\n"
1701 "AS confederation parameters\n"
1702 "AS number\n"
1703 "Set routing domain confederation AS\n")
1704 {
1705 nb_cli_enqueue_change(vty, "./global/confederation/identifier",
1706 NB_OP_DESTROY, NULL);
1707
1708 return nb_cli_apply_changes(vty, NULL);
1709 }
1710
1711 void cli_show_router_bgp_confederation_identifier(struct vty *vty,
1712 struct lyd_node *dnode,
1713 bool show_defaults)
1714 {
1715 vty_out(vty, " bgp confederation identifier %u\n",
1716 yang_dnode_get_uint32(dnode, NULL));
1717 }
1718
1719 DEFUN_YANG(bgp_confederation_peers,
1720 bgp_confederation_peers_cmd,
1721 "bgp confederation peers (1-4294967295)...",
1722 "BGP specific commands\n"
1723 "AS confederation parameters\n"
1724 "Peer ASs in BGP confederation\n" AS_STR)
1725 {
1726 int idx_asn = 3;
1727 int i;
1728
1729 for (i = idx_asn; i < argc; i++)
1730 nb_cli_enqueue_change(vty, "./global/confederation/member-as",
1731 NB_OP_CREATE, argv[i]->arg);
1732
1733 return nb_cli_apply_changes(vty, NULL);
1734 }
1735
1736 DEFUN_YANG(no_bgp_confederation_peers,
1737 no_bgp_confederation_peers_cmd,
1738 "no bgp confederation peers (1-4294967295)...",
1739 NO_STR
1740 "BGP specific commands\n"
1741 "AS confederation parameters\n"
1742 "Peer ASs in BGP confederation\n" AS_STR)
1743 {
1744 int idx_asn = 4;
1745 int i;
1746
1747 for (i = idx_asn; i < argc; i++)
1748 nb_cli_enqueue_change(vty, "./global/confederation/member-as",
1749 NB_OP_DESTROY, argv[i]->arg);
1750
1751 return nb_cli_apply_changes(vty, NULL);
1752 }
1753
1754 void cli_show_router_bgp_confederation_member_as(struct vty *vty,
1755 struct lyd_node *dnode,
1756 bool show_defaults)
1757 {
1758 vty_out(vty, " bgp confederation peers %u \n",
1759 yang_dnode_get_uint32(dnode, NULL));
1760 }
1761
1762 /**
1763 * Central routine for maximum-paths configuration.
1764 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1765 * @set: 1 for setting values, 0 for removing the max-paths config.
1766 */
1767 int bgp_maxpaths_config_vty(struct bgp *bgp, afi_t afi, safi_t safi,
1768 int peer_type, uint16_t maxpaths, uint16_t options,
1769 int set, char *errmsg, size_t errmsg_len)
1770 {
1771 int ret;
1772
1773 if (set) {
1774 if (maxpaths > multipath_num) {
1775 snprintf(
1776 errmsg, errmsg_len,
1777 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1778 maxpaths, multipath_num);
1779 return CMD_WARNING_CONFIG_FAILED;
1780 }
1781 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1782 options);
1783 } else
1784 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1785
1786 if (ret < 0) {
1787 snprintf(
1788 errmsg, errmsg_len,
1789 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1790 (set == 1) ? "" : "un",
1791 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1792 maxpaths, afi, safi);
1793 return CMD_WARNING_CONFIG_FAILED;
1794 }
1795
1796 bgp_recalculate_all_bestpaths(bgp);
1797
1798 return CMD_SUCCESS;
1799 }
1800
1801 void cli_show_router_bgp_med_config(struct vty *vty, struct lyd_node *dnode,
1802 bool show_defaults)
1803 {
1804 if (yang_dnode_get_bool(dnode, "./enable-med-admin")) {
1805 uint32_t med_admin_val;
1806
1807 vty_out(vty, " bgp max-med administrative");
1808 if ((med_admin_val =
1809 yang_dnode_get_uint32(dnode, "./max-med-admin"))
1810 != BGP_MAXMED_VALUE_DEFAULT)
1811 vty_out(vty, " %u", med_admin_val);
1812 vty_out(vty, "\n");
1813 }
1814
1815 if (yang_dnode_exists(dnode, "./max-med-onstart-up-time")) {
1816 uint32_t onstartup_val;
1817
1818 vty_out(vty, " bgp max-med on-startup %u",
1819 yang_dnode_get_uint32(dnode,
1820 "./max-med-onstart-up-time"));
1821 onstartup_val = yang_dnode_get_uint32(
1822 dnode, "./max-med-onstart-up-value");
1823 if (onstartup_val != BGP_MAXMED_VALUE_DEFAULT)
1824 vty_out(vty, " %u", onstartup_val);
1825
1826 vty_out(vty, "\n");
1827 }
1828 }
1829
1830 DEFUN_YANG(bgp_maxmed_admin,
1831 bgp_maxmed_admin_cmd,
1832 "bgp max-med administrative ",
1833 BGP_STR
1834 "Advertise routes with max-med\n"
1835 "Administratively applied, for an indefinite period\n")
1836 {
1837 nb_cli_enqueue_change(vty, "./global/med-config/enable-med-admin",
1838 NB_OP_MODIFY, "true");
1839
1840 return nb_cli_apply_changes(vty, NULL);
1841 }
1842
1843 DEFUN_YANG(bgp_maxmed_admin_medv,
1844 bgp_maxmed_admin_medv_cmd,
1845 "bgp max-med administrative (0-4294967295)",
1846 BGP_STR
1847 "Advertise routes with max-med\n"
1848 "Administratively applied, for an indefinite period\n"
1849 "Max MED value to be used\n")
1850 {
1851 int idx_number = 3;
1852
1853 nb_cli_enqueue_change(vty, "./global/med-config/enable-med-admin",
1854 NB_OP_MODIFY, "true");
1855
1856 nb_cli_enqueue_change(vty, "./global/med-config/max-med-admin",
1857 NB_OP_MODIFY, argv[idx_number]->arg);
1858
1859 return nb_cli_apply_changes(vty, NULL);
1860 }
1861
1862 DEFUN_YANG(no_bgp_maxmed_admin,
1863 no_bgp_maxmed_admin_cmd,
1864 "no bgp max-med administrative [(0-4294967295)]",
1865 NO_STR BGP_STR
1866 "Advertise routes with max-med\n"
1867 "Administratively applied, for an indefinite period\n"
1868 "Max MED value to be used\n")
1869 {
1870 nb_cli_enqueue_change(vty, "./global/med-config/enable-med-admin",
1871 NB_OP_MODIFY, "false");
1872
1873 nb_cli_enqueue_change(vty, "./global/med-config/max-med-admin",
1874 NB_OP_MODIFY, NULL);
1875
1876 return nb_cli_apply_changes(vty, NULL);
1877 }
1878
1879 DEFUN_YANG (bgp_maxmed_onstartup,
1880 bgp_maxmed_onstartup_cmd,
1881 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
1882 BGP_STR
1883 "Advertise routes with max-med\n"
1884 "Effective on a startup\n"
1885 "Time (seconds) period for max-med\n"
1886 "Max MED value to be used\n")
1887 {
1888 int idx = 0;
1889
1890 argv_find(argv, argc, "(5-86400)", &idx);
1891 nb_cli_enqueue_change(vty,
1892 "./global/med-config/max-med-onstart-up-time",
1893 NB_OP_MODIFY, argv[idx]->arg);
1894
1895 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1896 nb_cli_enqueue_change(
1897 vty, "./global/med-config/max-med-onstart-up-value",
1898 NB_OP_MODIFY, argv[idx]->arg);
1899 else
1900 nb_cli_enqueue_change(
1901 vty, "./global/med-config/max-med-onstart-up-value",
1902 NB_OP_MODIFY, NULL);
1903
1904 return nb_cli_apply_changes(vty, NULL);
1905 }
1906
1907 DEFUN_YANG (no_bgp_maxmed_onstartup,
1908 no_bgp_maxmed_onstartup_cmd,
1909 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
1910 NO_STR BGP_STR
1911 "Advertise routes with max-med\n"
1912 "Effective on a startup\n"
1913 "Time (seconds) period for max-med\n"
1914 "Max MED value to be used\n")
1915 {
1916 nb_cli_enqueue_change(vty,
1917 "./global/med-config/max-med-onstart-up-time",
1918 NB_OP_DESTROY, NULL);
1919
1920 nb_cli_enqueue_change(vty,
1921 "./global/med-config/max-med-onstart-up-value",
1922 NB_OP_MODIFY, NULL);
1923
1924 return nb_cli_apply_changes(vty, NULL);
1925 }
1926
1927 static int bgp_global_update_delay_config_vty(struct vty *vty,
1928 uint16_t update_delay,
1929 uint16_t establish_wait)
1930 {
1931 struct listnode *node, *nnode;
1932 struct bgp *bgp;
1933 bool vrf_cfg = false;
1934
1935 /*
1936 * See if update-delay is set per-vrf and warn user to delete it
1937 * Note that we only need to check this if this is the first time
1938 * setting the global config.
1939 */
1940 if (bm->v_update_delay == BGP_UPDATE_DELAY_DEF) {
1941 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
1942 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1943 vty_out(vty,
1944 "%% update-delay configuration found in vrf %s\n",
1945 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT
1946 ? VRF_DEFAULT_NAME
1947 : bgp->name);
1948 vrf_cfg = true;
1949 }
1950 }
1951 }
1952
1953 if (vrf_cfg) {
1954 vty_out(vty,
1955 "%%Failed: global update-delay config not permitted\n");
1956 return CMD_WARNING;
1957 }
1958
1959 if (!establish_wait) { /* update-delay <delay> */
1960 bm->v_update_delay = update_delay;
1961 bm->v_establish_wait = bm->v_update_delay;
1962 } else {
1963 /* update-delay <delay> <establish-wait> */
1964 if (update_delay < establish_wait) {
1965 vty_out(vty,
1966 "%%Failed: update-delay less than the establish-wait!\n");
1967 return CMD_WARNING_CONFIG_FAILED;
1968 }
1969
1970 bm->v_update_delay = update_delay;
1971 bm->v_establish_wait = establish_wait;
1972 }
1973
1974 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
1975 bgp->v_update_delay = bm->v_update_delay;
1976 bgp->v_establish_wait = bm->v_establish_wait;
1977 }
1978
1979 return CMD_SUCCESS;
1980 }
1981
1982 static int bgp_global_update_delay_deconfig_vty(struct vty *vty)
1983 {
1984 struct listnode *node, *nnode;
1985 struct bgp *bgp;
1986
1987 bm->v_update_delay = BGP_UPDATE_DELAY_DEF;
1988 bm->v_establish_wait = bm->v_update_delay;
1989
1990 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
1991 bgp->v_update_delay = bm->v_update_delay;
1992 bgp->v_establish_wait = bm->v_establish_wait;
1993 }
1994
1995 return CMD_SUCCESS;
1996 }
1997
1998 static int bgp_update_delay_config_vty(struct vty *vty, uint16_t update_delay,
1999 uint16_t establish_wait)
2000 {
2001 VTY_DECLVAR_CONTEXT(bgp, bgp);
2002
2003 /* if configured globally, per-instance config is not allowed */
2004 if (bm->v_update_delay) {
2005 vty_out(vty,
2006 "%%Failed: per-vrf update-delay config not permitted with global update-delay\n");
2007 return CMD_WARNING_CONFIG_FAILED;
2008 }
2009
2010
2011 if (!establish_wait) /* update-delay <delay> */
2012 {
2013 bgp->v_update_delay = update_delay;
2014 bgp->v_establish_wait = bgp->v_update_delay;
2015 return CMD_SUCCESS;
2016 }
2017
2018 /* update-delay <delay> <establish-wait> */
2019 if (update_delay < establish_wait) {
2020 vty_out(vty,
2021 "%%Failed: update-delay less than the establish-wait!\n");
2022 return CMD_WARNING_CONFIG_FAILED;
2023 }
2024
2025 bgp->v_update_delay = update_delay;
2026 bgp->v_establish_wait = establish_wait;
2027
2028 return CMD_SUCCESS;
2029 }
2030
2031 static int bgp_update_delay_deconfig_vty(struct vty *vty)
2032 {
2033 VTY_DECLVAR_CONTEXT(bgp, bgp);
2034
2035 /* If configured globally, cannot remove from one bgp instance */
2036 if (bm->v_update_delay) {
2037 vty_out(vty,
2038 "%%Failed: bgp update-delay configured globally. Delete per-vrf not permitted\n");
2039 return CMD_WARNING_CONFIG_FAILED;
2040 }
2041 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
2042 bgp->v_establish_wait = bgp->v_update_delay;
2043
2044 return CMD_SUCCESS;
2045 }
2046
2047 void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
2048 {
2049 /* If configured globally, no need to display per-instance value */
2050 if (bgp->v_update_delay != bm->v_update_delay) {
2051 vty_out(vty, " update-delay %d", bgp->v_update_delay);
2052 if (bgp->v_update_delay != bgp->v_establish_wait)
2053 vty_out(vty, " %d", bgp->v_establish_wait);
2054 vty_out(vty, "\n");
2055 }
2056 }
2057
2058 /* Global update-delay configuration */
2059 DEFPY (bgp_global_update_delay,
2060 bgp_global_update_delay_cmd,
2061 "bgp update-delay (0-3600)$delay [(1-3600)$wait]",
2062 BGP_STR
2063 "Force initial delay for best-path and updates for all bgp instances\n"
2064 "Max delay in seconds\n"
2065 "Establish wait in seconds\n")
2066 {
2067 return bgp_global_update_delay_config_vty(vty, delay, wait);
2068 }
2069
2070 /* Global update-delay deconfiguration */
2071 DEFPY (no_bgp_global_update_delay,
2072 no_bgp_global_update_delay_cmd,
2073 "no bgp update-delay [(0-3600) [(1-3600)]]",
2074 NO_STR
2075 BGP_STR
2076 "Force initial delay for best-path and updates\n"
2077 "Max delay in seconds\n"
2078 "Establish wait in seconds\n")
2079 {
2080 return bgp_global_update_delay_deconfig_vty(vty);
2081 }
2082
2083 /* Update-delay configuration */
2084
2085 DEFPY (bgp_update_delay,
2086 bgp_update_delay_cmd,
2087 "update-delay (0-3600)$delay [(1-3600)$wait]",
2088 "Force initial delay for best-path and updates\n"
2089 "Max delay in seconds\n"
2090 "Establish wait in seconds\n")
2091 {
2092 return bgp_update_delay_config_vty(vty, delay, wait);
2093 }
2094
2095 /* Update-delay deconfiguration */
2096 DEFPY (no_bgp_update_delay,
2097 no_bgp_update_delay_cmd,
2098 "no update-delay [(0-3600) [(1-3600)]]",
2099 NO_STR
2100 "Force initial delay for best-path and updates\n"
2101 "Max delay in seconds\n"
2102 "Establish wait in seconds\n")
2103 {
2104 return bgp_update_delay_deconfig_vty(vty);
2105 }
2106
2107
2108 int bgp_wpkt_quanta_config_vty(struct bgp *bgp, uint32_t quanta, bool set)
2109 {
2110 quanta = set ? quanta : BGP_WRITE_PACKET_MAX;
2111 atomic_store_explicit(&bgp->wpkt_quanta, quanta, memory_order_relaxed);
2112
2113 return CMD_SUCCESS;
2114 }
2115
2116 int bgp_rpkt_quanta_config_vty(struct bgp *bgp, uint32_t quanta, bool set)
2117 {
2118 quanta = set ? quanta : BGP_READ_PACKET_MAX;
2119 atomic_store_explicit(&bgp->rpkt_quanta, quanta, memory_order_relaxed);
2120
2121 return CMD_SUCCESS;
2122 }
2123
2124 void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
2125 {
2126 uint32_t quanta =
2127 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
2128 if (quanta != BGP_WRITE_PACKET_MAX)
2129 vty_out(vty, " write-quanta %d\n", quanta);
2130 }
2131
2132 void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
2133 {
2134 uint32_t quanta =
2135 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
2136 if (quanta != BGP_READ_PACKET_MAX)
2137 vty_out(vty, " read-quanta %d\n", quanta);
2138 }
2139
2140 /* Packet quanta configuration
2141 *
2142 * XXX: The value set here controls the size of a stack buffer in the IO
2143 * thread. When changing these limits be careful to prevent stack overflow.
2144 *
2145 * Furthermore, the maximums used here should correspond to
2146 * BGP_WRITE_PACKET_MAX and BGP_READ_PACKET_MAX.
2147 */
2148 DEFPY_YANG (bgp_wpkt_quanta,
2149 bgp_wpkt_quanta_cmd,
2150 "[no] write-quanta (1-64)$quanta",
2151 NO_STR
2152 "How many packets to write to peer socket per run\n"
2153 "Number of packets\n")
2154 {
2155 if (!no)
2156 nb_cli_enqueue_change(
2157 vty,
2158 "./global/global-neighbor-config/packet-quanta-config/wpkt-quanta",
2159 NB_OP_MODIFY, quanta_str);
2160 else
2161 nb_cli_enqueue_change(
2162 vty,
2163 "./global/global-neighbor-config/packet-quanta-config/wpkt-quanta",
2164 NB_OP_MODIFY, NULL);
2165
2166 return nb_cli_apply_changes(vty, NULL);
2167 }
2168
2169 DEFPY_YANG (bgp_rpkt_quanta,
2170 bgp_rpkt_quanta_cmd,
2171 "[no] read-quanta (1-10)$quanta",
2172 NO_STR
2173 "How many packets to read from peer socket per I/O cycle\n"
2174 "Number of packets\n")
2175 {
2176 if (!no)
2177 nb_cli_enqueue_change(
2178 vty,
2179 "./global/global-neighbor-config/packet-quanta-config/rpkt-quanta",
2180 NB_OP_MODIFY, quanta_str);
2181 else
2182 nb_cli_enqueue_change(
2183 vty,
2184 "./global/global-neighbor-config/packet-quanta-config/rpkt-quanta",
2185 NB_OP_MODIFY, NULL);
2186
2187 return nb_cli_apply_changes(vty, NULL);
2188 }
2189
2190 void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
2191 {
2192 if (!bgp->heuristic_coalesce)
2193 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
2194 }
2195
2196 void cli_show_router_global_update_group_config_coalesce_time(
2197 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
2198 {
2199 vty_out(vty, " coalesce-time %u\n", yang_dnode_get_uint32(dnode, NULL));
2200 }
2201
2202
2203 DEFUN_YANG (bgp_coalesce_time,
2204 bgp_coalesce_time_cmd,
2205 "coalesce-time (0-4294967295)",
2206 "Subgroup coalesce timer\n"
2207 "Subgroup coalesce timer value (in ms)\n")
2208 {
2209 int idx = 0;
2210
2211 argv_find(argv, argc, "(0-4294967295)", &idx);
2212 nb_cli_enqueue_change(
2213 vty, "./global/global-update-group-config/coalesce-time",
2214 NB_OP_MODIFY, argv[idx]->arg);
2215
2216 return nb_cli_apply_changes(vty, NULL);
2217 }
2218
2219 DEFUN_YANG(no_bgp_coalesce_time,
2220 no_bgp_coalesce_time_cmd,
2221 "no coalesce-time (0-4294967295)",
2222 NO_STR
2223 "Subgroup coalesce timer\n"
2224 "Subgroup coalesce timer value (in ms)\n")
2225 {
2226 nb_cli_enqueue_change(
2227 vty, "./global/global-update-group-config/coalesce-time",
2228 NB_OP_MODIFY, NULL);
2229
2230 return nb_cli_apply_changes(vty, NULL);
2231 }
2232
2233 /* Maximum-paths configuration */
2234 DEFUN_YANG (bgp_maxpaths,
2235 bgp_maxpaths_cmd,
2236 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2237 "Forward packets over multiple paths\n"
2238 "Number of paths\n")
2239 {
2240 int idx_number = 1;
2241 char base_xpath[XPATH_MAXLEN];
2242 afi_t afi;
2243 safi_t safi;
2244
2245 afi = bgp_node_afi(vty);
2246 safi = bgp_node_safi(vty);
2247
2248 snprintf(
2249 base_xpath, sizeof(base_xpath),
2250 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ebgp/maximum-paths",
2251 yang_afi_safi_value2identity(afi, safi),
2252 bgp_afi_safi_get_container_str(afi, safi));
2253
2254 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY,
2255 argv[idx_number]->arg);
2256
2257 return nb_cli_apply_changes(vty, NULL);
2258 }
2259
2260 void cli_show_bgp_global_afi_safi_unicast_use_multiple_paths_ebgp_maximum_paths(
2261 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
2262 {
2263 vty_out(vty, " maximum-paths %d\n",
2264 yang_dnode_get_uint16(dnode, NULL));
2265 }
2266
2267 ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
2268 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2269 "Forward packets over multiple paths\n"
2270 "Number of paths\n")
2271
2272 DEFUN_YANG (bgp_maxpaths_ibgp,
2273 bgp_maxpaths_ibgp_cmd,
2274 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2275 "Forward packets over multiple paths\n"
2276 "iBGP-multipath\n"
2277 "Number of paths\n")
2278 {
2279 int idx_number = 2;
2280 char base_xpath[XPATH_MAXLEN];
2281 afi_t afi;
2282 safi_t safi;
2283
2284 afi = bgp_node_afi(vty);
2285 safi = bgp_node_safi(vty);
2286
2287 snprintf(
2288 base_xpath, sizeof(base_xpath),
2289 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/maximum-paths",
2290 yang_afi_safi_value2identity(afi, safi),
2291 bgp_afi_safi_get_container_str(afi, safi));
2292
2293 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY,
2294 argv[idx_number]->arg);
2295
2296 return nb_cli_apply_changes(vty, NULL);
2297 }
2298
2299 ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
2300 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2301 "Forward packets over multiple paths\n"
2302 "iBGP-multipath\n"
2303 "Number of paths\n")
2304
2305 DEFUN_YANG (bgp_maxpaths_ibgp_cluster,
2306 bgp_maxpaths_ibgp_cluster_cmd,
2307 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
2308 "Forward packets over multiple paths\n"
2309 "iBGP-multipath\n"
2310 "Number of paths\n"
2311 "Match the cluster length\n")
2312 {
2313 int idx_number = 2;
2314 char base_xpath[XPATH_MAXLEN];
2315 afi_t afi;
2316 safi_t safi;
2317
2318 afi = bgp_node_afi(vty);
2319 safi = bgp_node_safi(vty);
2320
2321 snprintf(
2322 base_xpath, sizeof(base_xpath),
2323 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/maximum-paths",
2324 yang_afi_safi_value2identity(afi, safi),
2325 bgp_afi_safi_get_container_str(afi, safi));
2326
2327 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY,
2328 argv[idx_number]->arg);
2329
2330 snprintf(
2331 base_xpath, sizeof(base_xpath),
2332 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/cluster-length-list",
2333 yang_afi_safi_value2identity(afi, safi),
2334 bgp_afi_safi_get_container_str(afi, safi));
2335
2336 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, "true");
2337
2338 return nb_cli_apply_changes(vty, NULL);
2339 }
2340
2341 void cli_show_bgp_global_afi_safi_ip_unicast_use_multiple_paths_ibgp_maximum_paths(
2342 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
2343 {
2344 vty_out(vty, " maximum-paths ibgp %d",
2345 yang_dnode_get_uint16(dnode, "./maximum-paths"));
2346 if (yang_dnode_get_bool(dnode, "./cluster-length-list"))
2347 vty_out(vty, " equal-cluster-length");
2348 vty_out(vty, "\n");
2349 }
2350
2351 ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
2352 "maximum-paths ibgp " CMD_RANGE_STR(
2353 1, MULTIPATH_NUM) " equal-cluster-length",
2354 "Forward packets over multiple paths\n"
2355 "iBGP-multipath\n"
2356 "Number of paths\n"
2357 "Match the cluster length\n")
2358
2359 DEFUN_YANG (no_bgp_maxpaths,
2360 no_bgp_maxpaths_cmd,
2361 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
2362 NO_STR
2363 "Forward packets over multiple paths\n"
2364 "Number of paths\n")
2365 {
2366 char base_xpath[XPATH_MAXLEN];
2367 afi_t afi;
2368 safi_t safi;
2369
2370 afi = bgp_node_afi(vty);
2371 safi = bgp_node_safi(vty);
2372
2373 snprintf(
2374 base_xpath, sizeof(base_xpath),
2375 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ebgp/maximum-paths",
2376 yang_afi_safi_value2identity(afi, safi),
2377 bgp_afi_safi_get_container_str(afi, safi));
2378
2379 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, NULL);
2380
2381 return nb_cli_apply_changes(vty, NULL);
2382 }
2383
2384 ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
2385 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
2386 "Forward packets over multiple paths\n"
2387 "Number of paths\n")
2388
2389 DEFUN_YANG (no_bgp_maxpaths_ibgp,
2390 no_bgp_maxpaths_ibgp_cmd,
2391 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
2392 NO_STR
2393 "Forward packets over multiple paths\n"
2394 "iBGP-multipath\n"
2395 "Number of paths\n"
2396 "Match the cluster length\n")
2397 {
2398 char base_xpath[XPATH_MAXLEN];
2399 afi_t afi;
2400 safi_t safi;
2401
2402 afi = bgp_node_afi(vty);
2403 safi = bgp_node_safi(vty);
2404
2405 snprintf(
2406 base_xpath, sizeof(base_xpath),
2407 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/maximum-paths",
2408 yang_afi_safi_value2identity(afi, safi),
2409 bgp_afi_safi_get_container_str(afi, safi));
2410
2411 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, NULL);
2412
2413 snprintf(
2414 base_xpath, sizeof(base_xpath),
2415 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/cluster-length-list",
2416 yang_afi_safi_value2identity(afi, safi),
2417 bgp_afi_safi_get_container_str(afi, safi));
2418
2419 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, "false");
2420
2421 return nb_cli_apply_changes(vty, NULL);
2422 }
2423
2424 ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
2425 "no maximum-paths ibgp [" CMD_RANGE_STR(
2426 1, MULTIPATH_NUM) " [equal-cluster-length]]",
2427 NO_STR
2428 "Forward packets over multiple paths\n"
2429 "iBGP-multipath\n"
2430 "Number of paths\n"
2431 "Match the cluster length\n")
2432
2433 static void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp,
2434 afi_t afi, safi_t safi)
2435 {
2436 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != multipath_num) {
2437 vty_out(vty, " maximum-paths %d\n",
2438 bgp->maxpaths[afi][safi].maxpaths_ebgp);
2439 }
2440
2441 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != multipath_num) {
2442 vty_out(vty, " maximum-paths ibgp %d",
2443 bgp->maxpaths[afi][safi].maxpaths_ibgp);
2444 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
2445 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
2446 vty_out(vty, " equal-cluster-length");
2447 vty_out(vty, "\n");
2448 }
2449 }
2450
2451 /* BGP timers. */
2452
2453 DEFUN_YANG (bgp_timers,
2454 bgp_timers_cmd,
2455 "timers bgp (0-65535) (0-65535)",
2456 "Adjust routing timers\n"
2457 "BGP timers\n"
2458 "Keepalive interval\n"
2459 "Holdtime\n")
2460 {
2461 int idx_number = 2;
2462 int idx_number_2 = 3;
2463
2464 nb_cli_enqueue_change(vty, "./global/global-config-timers/keepalive",
2465 NB_OP_MODIFY, argv[idx_number]->arg);
2466 nb_cli_enqueue_change(vty, "./global/global-config-timers/hold-time",
2467 NB_OP_MODIFY, argv[idx_number_2]->arg);
2468
2469 return nb_cli_apply_changes(vty, NULL);
2470 }
2471
2472 DEFUN_YANG (no_bgp_timers,
2473 no_bgp_timers_cmd,
2474 "no timers bgp [(0-65535) (0-65535)]",
2475 NO_STR
2476 "Adjust routing timers\n"
2477 "BGP timers\n"
2478 "Keepalive interval\n"
2479 "Holdtime\n")
2480 {
2481 nb_cli_enqueue_change(vty, "./global/global-config-timers/keepalive",
2482 NB_OP_DESTROY, NULL);
2483 nb_cli_enqueue_change(vty, "./global/global-config-timers/hold-time",
2484 NB_OP_DESTROY, NULL);
2485
2486 return nb_cli_apply_changes(vty, NULL);
2487 }
2488
2489 void cli_show_router_bgp_route_reflector(struct vty *vty,
2490 struct lyd_node *dnode,
2491 bool show_defaults)
2492 {
2493 if (yang_dnode_get_bool(dnode, "./no-client-reflect"))
2494 vty_out(vty, " no bgp client-to-client reflection\n");
2495
2496 if (yang_dnode_get_bool(dnode, "./allow-outbound-policy"))
2497 vty_out(vty, " bgp route-reflector allow-outbound-policy\n");
2498
2499 if (yang_dnode_exists(dnode, "./route-reflector-cluster-id"))
2500 vty_out(vty, " bgp cluster-id %s\n",
2501 yang_dnode_get_string(dnode,
2502 "./route-reflector-cluster-id"));
2503 }
2504
2505 DEFUN_YANG(bgp_client_to_client_reflection,
2506 bgp_client_to_client_reflection_cmd,
2507 "bgp client-to-client reflection",
2508 "BGP specific commands\n"
2509 "Configure client to client route reflection\n"
2510 "reflection of routes allowed\n")
2511 {
2512 nb_cli_enqueue_change(vty, "./global/route-reflector/no-client-reflect",
2513 NB_OP_MODIFY, "false");
2514
2515 return nb_cli_apply_changes(vty, NULL);
2516 }
2517
2518 DEFUN_YANG(no_bgp_client_to_client_reflection,
2519 no_bgp_client_to_client_reflection_cmd,
2520 "no bgp client-to-client reflection",
2521 NO_STR
2522 "BGP specific commands\n"
2523 "Configure client to client route reflection\n"
2524 "reflection of routes allowed\n")
2525 {
2526 nb_cli_enqueue_change(vty, "./global/route-reflector/no-client-reflect",
2527 NB_OP_MODIFY, "true");
2528
2529 return nb_cli_apply_changes(vty, NULL);
2530 }
2531
2532 void cli_show_router_bgp_route_selection(struct vty *vty,
2533 struct lyd_node *dnode,
2534 bool show_defaults)
2535 {
2536
2537 if (yang_dnode_get_bool(dnode, "./always-compare-med"))
2538 vty_out(vty, " bgp always-compare-med\n");
2539
2540 if (yang_dnode_get_bool(dnode, "./ignore-as-path-length"))
2541 vty_out(vty, " bgp bestpath as-path ignore\n");
2542
2543 if (yang_dnode_get_bool(dnode, "./aspath-confed"))
2544 vty_out(vty, " bgp bestpath as-path confed\n");
2545
2546 if (yang_dnode_get_bool(dnode, "./external-compare-router-id"))
2547 vty_out(vty, " bgp bestpath compare-routerid\n");
2548
2549 if (yang_dnode_get_bool(dnode, "./allow-multiple-as")) {
2550 if (yang_dnode_get_bool(dnode, "./multi-path-as-set"))
2551 vty_out(vty,
2552 " bgp bestpath as-path multipath-relax as-set\n");
2553 else
2554 vty_out(vty, " bgp bestpath as-path multipath-relax\n");
2555 }
2556
2557 if (yang_dnode_get_bool(dnode, "./deterministic-med"))
2558 vty_out(vty, " bgp deterministic-med\n");
2559
2560 if (yang_dnode_get_bool(dnode, "./confed-med")
2561 || yang_dnode_get_bool(dnode, "./missing-as-worst-med")) {
2562 vty_out(vty, " bgp bestpath med");
2563 if (yang_dnode_get_bool(dnode, "./confed-med"))
2564 vty_out(vty, " confed");
2565 if (yang_dnode_get_bool(dnode, "./missing-as-worst-med"))
2566 vty_out(vty, " missing-as-worst");
2567 vty_out(vty, "\n");
2568 }
2569 }
2570
2571 /* "bgp always-compare-med" configuration. */
2572 DEFUN_YANG(bgp_always_compare_med,
2573 bgp_always_compare_med_cmd,
2574 "bgp always-compare-med",
2575 "BGP specific commands\n"
2576 "Allow comparing MED from different neighbors\n")
2577 {
2578 nb_cli_enqueue_change(
2579 vty, "./global/route-selection-options/always-compare-med",
2580 NB_OP_MODIFY, "true");
2581
2582 return nb_cli_apply_changes(vty, NULL);
2583 }
2584
2585 DEFUN_YANG(no_bgp_always_compare_med,
2586 no_bgp_always_compare_med_cmd,
2587 "no bgp always-compare-med",
2588 NO_STR
2589 "BGP specific commands\n"
2590 "Allow comparing MED from different neighbors\n")
2591 {
2592 nb_cli_enqueue_change(
2593 vty, "./global/route-selection-options/always-compare-med",
2594 NB_OP_MODIFY, "false");
2595
2596 return nb_cli_apply_changes(vty, NULL);
2597 }
2598
2599 DEFUN_YANG(bgp_suppress_duplicates,
2600 bgp_suppress_duplicates_cmd,
2601 "bgp suppress-duplicates",
2602 "BGP specific commands\n"
2603 "Suppress duplicate updates if the route actually not changed\n")
2604 {
2605 nb_cli_enqueue_change(vty, "./global/suppress-duplicates",
2606 NB_OP_MODIFY, "true");
2607 return nb_cli_apply_changes(vty, NULL);
2608 }
2609
2610 DEFUN_YANG(no_bgp_suppress_duplicates,
2611 no_bgp_suppress_duplicates_cmd,
2612 "no bgp suppress-duplicates",
2613 NO_STR
2614 "BGP specific commands\n"
2615 "Suppress duplicate updates if the route actually not changed\n")
2616 {
2617 nb_cli_enqueue_change(vty, "./global/suppress-duplicates",
2618 NB_OP_MODIFY, "false");
2619 return nb_cli_apply_changes(vty, NULL);
2620 }
2621
2622 void cli_show_router_bgp_suppress_duplicates(struct vty *vty,
2623 struct lyd_node *dnode,
2624 bool show_defaults)
2625 {
2626 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_SUPPRESS_DUPLICATES)
2627 vty_out(vty, " bgp suppress-duplicates\n");
2628 }
2629
2630 DEFUN_YANG(bgp_ebgp_requires_policy,
2631 bgp_ebgp_requires_policy_cmd,
2632 "bgp ebgp-requires-policy",
2633 "BGP specific commands\n"
2634 "Require in and out policy for eBGP peers (RFC8212)\n")
2635 {
2636 nb_cli_enqueue_change(vty, "./global/ebgp-requires-policy",
2637 NB_OP_MODIFY, "true");
2638 return nb_cli_apply_changes(vty, NULL);
2639 }
2640
2641 DEFUN_YANG(no_bgp_ebgp_requires_policy,
2642 no_bgp_ebgp_requires_policy_cmd,
2643 "no bgp ebgp-requires-policy",
2644 NO_STR
2645 "BGP specific commands\n"
2646 "Require in and out policy for eBGP peers (RFC8212)\n")
2647 {
2648 nb_cli_enqueue_change(vty, "./global/ebgp-requires-policy",
2649 NB_OP_MODIFY, "false");
2650 return nb_cli_apply_changes(vty, NULL);
2651 }
2652
2653 void cli_show_router_bgp_ebgp_requires_policy(struct vty *vty,
2654 struct lyd_node *dnode,
2655 bool show_defaults)
2656 {
2657 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_EBGP_REQUIRES_POLICY)
2658 vty_out(vty, " bgp ebgp-requires-policy\n");
2659 }
2660
2661 DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd,
2662 "bgp reject-as-sets",
2663 "BGP specific commands\n"
2664 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2665 {
2666 VTY_DECLVAR_CONTEXT(bgp, bgp);
2667 struct listnode *node, *nnode;
2668 struct peer *peer;
2669
2670 bgp->reject_as_sets = true;
2671
2672 /* Reset existing BGP sessions to reject routes
2673 * with aspath containing AS_SET or AS_CONFED_SET.
2674 */
2675 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2676 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2677 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2678 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2679 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2680 }
2681 }
2682
2683 return CMD_SUCCESS;
2684 }
2685
2686 DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd,
2687 "no bgp reject-as-sets",
2688 NO_STR
2689 "BGP specific commands\n"
2690 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2691 {
2692 VTY_DECLVAR_CONTEXT(bgp, bgp);
2693 struct listnode *node, *nnode;
2694 struct peer *peer;
2695
2696 bgp->reject_as_sets = false;
2697
2698 /* Reset existing BGP sessions to reject routes
2699 * with aspath containing AS_SET or AS_CONFED_SET.
2700 */
2701 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2702 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2703 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2704 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2705 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2706 }
2707 }
2708
2709 return CMD_SUCCESS;
2710 }
2711
2712 /* "bgp deterministic-med" configuration. */
2713 DEFUN_YANG (bgp_deterministic_med,
2714 bgp_deterministic_med_cmd,
2715 "bgp deterministic-med",
2716 "BGP specific commands\n"
2717 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2718 {
2719 nb_cli_enqueue_change(
2720 vty, "./global/route-selection-options/deterministic-med",
2721 NB_OP_MODIFY, "true");
2722
2723 return nb_cli_apply_changes(vty, NULL);
2724 }
2725
2726 DEFUN_YANG (no_bgp_deterministic_med,
2727 no_bgp_deterministic_med_cmd,
2728 "no bgp deterministic-med",
2729 NO_STR
2730 "BGP specific commands\n"
2731 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2732 {
2733 nb_cli_enqueue_change(
2734 vty, "./global/route-selection-options/deterministic-med",
2735 NB_OP_MODIFY, "false");
2736
2737 return nb_cli_apply_changes(vty, NULL);
2738 }
2739
2740 /* "bgp graceful-restart mode" configuration. */
2741 DEFUN (bgp_graceful_restart,
2742 bgp_graceful_restart_cmd,
2743 "bgp graceful-restart",
2744 "BGP specific commands\n"
2745 GR_CMD
2746 )
2747 {
2748 int ret = BGP_GR_FAILURE;
2749
2750 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2751 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : START ");
2752
2753 VTY_DECLVAR_CONTEXT(bgp, bgp);
2754
2755 ret = bgp_gr_update_all(bgp, GLOBAL_GR_CMD);
2756
2757 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2758 ret);
2759
2760 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2761 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : END ");
2762 vty_out(vty,
2763 "Graceful restart configuration changed, reset all peers to take effect\n");
2764 return bgp_vty_return(vty, ret);
2765 }
2766
2767 DEFUN (no_bgp_graceful_restart,
2768 no_bgp_graceful_restart_cmd,
2769 "no bgp graceful-restart",
2770 NO_STR
2771 "BGP specific commands\n"
2772 NO_GR_CMD
2773 )
2774 {
2775 VTY_DECLVAR_CONTEXT(bgp, bgp);
2776
2777 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2778 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : START ");
2779
2780 int ret = BGP_GR_FAILURE;
2781
2782 ret = bgp_gr_update_all(bgp, NO_GLOBAL_GR_CMD);
2783
2784 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2785 ret);
2786
2787 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2788 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : END ");
2789 vty_out(vty,
2790 "Graceful restart configuration changed, reset all peers to take effect\n");
2791
2792 return bgp_vty_return(vty, ret);
2793 }
2794
2795 DEFUN (bgp_graceful_restart_stalepath_time,
2796 bgp_graceful_restart_stalepath_time_cmd,
2797 "bgp graceful-restart stalepath-time (1-4095)",
2798 "BGP specific commands\n"
2799 "Graceful restart capability parameters\n"
2800 "Set the max time to hold onto restarting peer's stale paths\n"
2801 "Delay value (seconds)\n")
2802 {
2803 VTY_DECLVAR_CONTEXT(bgp, bgp);
2804 int idx_number = 3;
2805 uint32_t stalepath;
2806
2807 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2808 bgp->stalepath_time = stalepath;
2809 return CMD_SUCCESS;
2810 }
2811
2812 DEFUN (bgp_graceful_restart_restart_time,
2813 bgp_graceful_restart_restart_time_cmd,
2814 "bgp graceful-restart restart-time (1-4095)",
2815 "BGP specific commands\n"
2816 "Graceful restart capability parameters\n"
2817 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2818 "Delay value (seconds)\n")
2819 {
2820 VTY_DECLVAR_CONTEXT(bgp, bgp);
2821 int idx_number = 3;
2822 uint32_t restart;
2823
2824 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2825 bgp->restart_time = restart;
2826 return CMD_SUCCESS;
2827 }
2828
2829 DEFUN (bgp_graceful_restart_select_defer_time,
2830 bgp_graceful_restart_select_defer_time_cmd,
2831 "bgp graceful-restart select-defer-time (0-3600)",
2832 "BGP specific commands\n"
2833 "Graceful restart capability parameters\n"
2834 "Set the time to defer the BGP route selection after restart\n"
2835 "Delay value (seconds, 0 - disable)\n")
2836 {
2837 VTY_DECLVAR_CONTEXT(bgp, bgp);
2838 int idx_number = 3;
2839 uint32_t defer_time;
2840
2841 defer_time = strtoul(argv[idx_number]->arg, NULL, 10);
2842 bgp->select_defer_time = defer_time;
2843 if (defer_time == 0)
2844 SET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2845 else
2846 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2847
2848 return CMD_SUCCESS;
2849 }
2850
2851 DEFUN (no_bgp_graceful_restart_stalepath_time,
2852 no_bgp_graceful_restart_stalepath_time_cmd,
2853 "no bgp graceful-restart stalepath-time [(1-4095)]",
2854 NO_STR
2855 "BGP specific commands\n"
2856 "Graceful restart capability parameters\n"
2857 "Set the max time to hold onto restarting peer's stale paths\n"
2858 "Delay value (seconds)\n")
2859 {
2860 VTY_DECLVAR_CONTEXT(bgp, bgp);
2861
2862 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2863 return CMD_SUCCESS;
2864 }
2865
2866 DEFUN (no_bgp_graceful_restart_restart_time,
2867 no_bgp_graceful_restart_restart_time_cmd,
2868 "no bgp graceful-restart restart-time [(1-4095)]",
2869 NO_STR
2870 "BGP specific commands\n"
2871 "Graceful restart capability parameters\n"
2872 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2873 "Delay value (seconds)\n")
2874 {
2875 VTY_DECLVAR_CONTEXT(bgp, bgp);
2876
2877 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2878 return CMD_SUCCESS;
2879 }
2880
2881 DEFUN (no_bgp_graceful_restart_select_defer_time,
2882 no_bgp_graceful_restart_select_defer_time_cmd,
2883 "no bgp graceful-restart select-defer-time [(0-3600)]",
2884 NO_STR
2885 "BGP specific commands\n"
2886 "Graceful restart capability parameters\n"
2887 "Set the time to defer the BGP route selection after restart\n"
2888 "Delay value (seconds)\n")
2889 {
2890 VTY_DECLVAR_CONTEXT(bgp, bgp);
2891
2892 bgp->select_defer_time = BGP_DEFAULT_SELECT_DEFERRAL_TIME;
2893 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2894
2895 return CMD_SUCCESS;
2896 }
2897
2898 DEFUN (bgp_graceful_restart_preserve_fw,
2899 bgp_graceful_restart_preserve_fw_cmd,
2900 "bgp graceful-restart preserve-fw-state",
2901 "BGP specific commands\n"
2902 "Graceful restart capability parameters\n"
2903 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
2904 {
2905 VTY_DECLVAR_CONTEXT(bgp, bgp);
2906 SET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
2907 return CMD_SUCCESS;
2908 }
2909
2910 DEFUN (no_bgp_graceful_restart_preserve_fw,
2911 no_bgp_graceful_restart_preserve_fw_cmd,
2912 "no bgp graceful-restart preserve-fw-state",
2913 NO_STR
2914 "BGP specific commands\n"
2915 "Graceful restart capability parameters\n"
2916 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
2917 {
2918 VTY_DECLVAR_CONTEXT(bgp, bgp);
2919 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
2920 return CMD_SUCCESS;
2921 }
2922
2923 DEFUN (bgp_graceful_restart_disable,
2924 bgp_graceful_restart_disable_cmd,
2925 "bgp graceful-restart-disable",
2926 "BGP specific commands\n"
2927 GR_DISABLE)
2928 {
2929 int ret = BGP_GR_FAILURE;
2930
2931 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2932 zlog_debug(
2933 "[BGP_GR] bgp_graceful_restart_disable_cmd : START ");
2934
2935 VTY_DECLVAR_CONTEXT(bgp, bgp);
2936
2937 ret = bgp_gr_update_all(bgp, GLOBAL_DISABLE_CMD);
2938
2939 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
2940 bgp->peer, ret);
2941
2942 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2943 zlog_debug(
2944 "[BGP_GR] bgp_graceful_restart_disable_cmd : END ");
2945 vty_out(vty,
2946 "Graceful restart configuration changed, reset all peers to take effect\n");
2947
2948 return bgp_vty_return(vty, ret);
2949 }
2950
2951 DEFUN (no_bgp_graceful_restart_disable,
2952 no_bgp_graceful_restart_disable_cmd,
2953 "no bgp graceful-restart-disable",
2954 NO_STR
2955 "BGP specific commands\n"
2956 NO_GR_DISABLE
2957 )
2958 {
2959 VTY_DECLVAR_CONTEXT(bgp, bgp);
2960
2961 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2962 zlog_debug(
2963 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : START ");
2964
2965 int ret = BGP_GR_FAILURE;
2966
2967 ret = bgp_gr_update_all(bgp, NO_GLOBAL_DISABLE_CMD);
2968
2969 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2970 ret);
2971
2972 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2973 zlog_debug(
2974 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : END ");
2975 vty_out(vty,
2976 "Graceful restart configuration changed, reset all peers to take effect\n");
2977
2978 return bgp_vty_return(vty, ret);
2979 }
2980
2981 DEFUN (bgp_neighbor_graceful_restart_set,
2982 bgp_neighbor_graceful_restart_set_cmd,
2983 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
2984 NEIGHBOR_STR
2985 NEIGHBOR_ADDR_STR2
2986 GR_NEIGHBOR_CMD
2987 )
2988 {
2989 int idx_peer = 1;
2990 struct peer *peer;
2991 int ret = BGP_GR_FAILURE;
2992
2993 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2994
2995 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2996 zlog_debug(
2997 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : START ");
2998
2999 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3000 if (!peer)
3001 return CMD_WARNING_CONFIG_FAILED;
3002
3003 ret = bgp_neighbor_graceful_restart(peer, PEER_GR_CMD);
3004
3005 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3006 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3007
3008 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3009 zlog_debug(
3010 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : END ");
3011 vty_out(vty,
3012 "Graceful restart configuration changed, reset this peer to take effect\n");
3013
3014 return bgp_vty_return(vty, ret);
3015 }
3016
3017 DEFUN (no_bgp_neighbor_graceful_restart,
3018 no_bgp_neighbor_graceful_restart_set_cmd,
3019 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3020 NO_STR
3021 NEIGHBOR_STR
3022 NEIGHBOR_ADDR_STR2
3023 NO_GR_NEIGHBOR_CMD
3024 )
3025 {
3026 int idx_peer = 2;
3027 int ret = BGP_GR_FAILURE;
3028 struct peer *peer;
3029
3030 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3031
3032 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3033 if (!peer)
3034 return CMD_WARNING_CONFIG_FAILED;
3035
3036 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3037 zlog_debug(
3038 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : START ");
3039
3040 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_GR_CMD);
3041
3042 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3043 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3044
3045 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3046 zlog_debug(
3047 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : END ");
3048 vty_out(vty,
3049 "Graceful restart configuration changed, reset this peer to take effect\n");
3050
3051 return bgp_vty_return(vty, ret);
3052 }
3053
3054 DEFUN (bgp_neighbor_graceful_restart_helper_set,
3055 bgp_neighbor_graceful_restart_helper_set_cmd,
3056 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3057 NEIGHBOR_STR
3058 NEIGHBOR_ADDR_STR2
3059 GR_NEIGHBOR_HELPER_CMD
3060 )
3061 {
3062 int idx_peer = 1;
3063 struct peer *peer;
3064 int ret = BGP_GR_FAILURE;
3065
3066 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3067
3068 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3069 zlog_debug(
3070 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : START ");
3071
3072 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3073
3074 if (!peer)
3075 return CMD_WARNING_CONFIG_FAILED;
3076
3077
3078 ret = bgp_neighbor_graceful_restart(peer, PEER_HELPER_CMD);
3079
3080 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3081 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3082
3083 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3084 zlog_debug(
3085 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : END ");
3086 vty_out(vty,
3087 "Graceful restart configuration changed, reset this peer to take effect\n");
3088
3089 return bgp_vty_return(vty, ret);
3090 }
3091
3092 DEFUN (no_bgp_neighbor_graceful_restart_helper,
3093 no_bgp_neighbor_graceful_restart_helper_set_cmd,
3094 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3095 NO_STR
3096 NEIGHBOR_STR
3097 NEIGHBOR_ADDR_STR2
3098 NO_GR_NEIGHBOR_HELPER_CMD
3099 )
3100 {
3101 int idx_peer = 2;
3102 int ret = BGP_GR_FAILURE;
3103 struct peer *peer;
3104
3105 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3106
3107 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3108 if (!peer)
3109 return CMD_WARNING_CONFIG_FAILED;
3110
3111 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3112 zlog_debug(
3113 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : START ");
3114
3115 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_HELPER_CMD);
3116
3117 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3118 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3119
3120 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3121 zlog_debug(
3122 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : END ");
3123 vty_out(vty,
3124 "Graceful restart configuration changed, reset this peer to take effect\n");
3125
3126 return bgp_vty_return(vty, ret);
3127 }
3128
3129 DEFUN (bgp_neighbor_graceful_restart_disable_set,
3130 bgp_neighbor_graceful_restart_disable_set_cmd,
3131 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3132 NEIGHBOR_STR
3133 NEIGHBOR_ADDR_STR2
3134 GR_NEIGHBOR_DISABLE_CMD
3135 )
3136 {
3137 int idx_peer = 1;
3138 struct peer *peer;
3139 int ret = BGP_GR_FAILURE;
3140
3141 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3142
3143 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3144 zlog_debug(
3145 "[BGP_GR] bgp_neighbor_graceful_restart_disable_set_cmd : START ");
3146
3147 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3148 if (!peer)
3149 return CMD_WARNING_CONFIG_FAILED;
3150
3151 ret = bgp_neighbor_graceful_restart(peer, PEER_DISABLE_CMD);
3152
3153 if (peer->bgp->t_startup)
3154 bgp_peer_gr_flags_update(peer);
3155
3156 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3157 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3158
3159 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3160 zlog_debug(
3161 "[BGP_GR]bgp_neighbor_graceful_restart_disable_set_cmd : END ");
3162 vty_out(vty,
3163 "Graceful restart configuration changed, reset this peer to take effect\n");
3164
3165 return bgp_vty_return(vty, ret);
3166 }
3167
3168 DEFUN (no_bgp_neighbor_graceful_restart_disable,
3169 no_bgp_neighbor_graceful_restart_disable_set_cmd,
3170 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3171 NO_STR
3172 NEIGHBOR_STR
3173 NEIGHBOR_ADDR_STR2
3174 NO_GR_NEIGHBOR_DISABLE_CMD
3175 )
3176 {
3177 int idx_peer = 2;
3178 int ret = BGP_GR_FAILURE;
3179 struct peer *peer;
3180
3181 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3182
3183 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3184 if (!peer)
3185 return CMD_WARNING_CONFIG_FAILED;
3186
3187 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3188 zlog_debug(
3189 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : START ");
3190
3191 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_DISABLE_CMD);
3192
3193 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3194 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3195
3196 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3197 zlog_debug(
3198 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : END ");
3199 vty_out(vty,
3200 "Graceful restart configuration changed, reset this peer to take effect\n");
3201
3202 return bgp_vty_return(vty, ret);
3203 }
3204
3205 DEFUN_HIDDEN (bgp_graceful_restart_disable_eor,
3206 bgp_graceful_restart_disable_eor_cmd,
3207 "bgp graceful-restart disable-eor",
3208 "BGP specific commands\n"
3209 "Graceful restart configuration parameters\n"
3210 "Disable EOR Check\n")
3211 {
3212 VTY_DECLVAR_CONTEXT(bgp, bgp);
3213 SET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
3214
3215 return CMD_SUCCESS;
3216 }
3217
3218 DEFUN_HIDDEN (no_bgp_graceful_restart_disable_eor,
3219 no_bgp_graceful_restart_disable_eor_cmd,
3220 "no bgp graceful-restart disable-eor",
3221 NO_STR
3222 "BGP specific commands\n"
3223 "Graceful restart configuration parameters\n"
3224 "Disable EOR Check\n")
3225 {
3226 VTY_DECLVAR_CONTEXT(bgp, bgp);
3227 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
3228
3229 return CMD_SUCCESS;
3230 }
3231
3232 DEFUN (bgp_graceful_restart_rib_stale_time,
3233 bgp_graceful_restart_rib_stale_time_cmd,
3234 "bgp graceful-restart rib-stale-time (1-3600)",
3235 "BGP specific commands\n"
3236 "Graceful restart configuration parameters\n"
3237 "Specify the stale route removal timer in rib\n"
3238 "Delay value (seconds)\n")
3239 {
3240 VTY_DECLVAR_CONTEXT(bgp, bgp);
3241 int idx_number = 3;
3242 uint32_t stale_time;
3243
3244 stale_time = strtoul(argv[idx_number]->arg, NULL, 10);
3245 bgp->rib_stale_time = stale_time;
3246 /* Send the stale timer update message to RIB */
3247 if (bgp_zebra_stale_timer_update(bgp))
3248 return CMD_WARNING;
3249
3250 return CMD_SUCCESS;
3251 }
3252
3253 DEFUN (no_bgp_graceful_restart_rib_stale_time,
3254 no_bgp_graceful_restart_rib_stale_time_cmd,
3255 "no bgp graceful-restart rib-stale-time [(1-3600)]",
3256 NO_STR
3257 "BGP specific commands\n"
3258 "Graceful restart configuration parameters\n"
3259 "Specify the stale route removal timer in rib\n"
3260 "Delay value (seconds)\n")
3261 {
3262 VTY_DECLVAR_CONTEXT(bgp, bgp);
3263
3264 bgp->rib_stale_time = BGP_DEFAULT_RIB_STALE_TIME;
3265 /* Send the stale timer update message to RIB */
3266 if (bgp_zebra_stale_timer_update(bgp))
3267 return CMD_WARNING;
3268
3269 return CMD_SUCCESS;
3270 }
3271
3272 static inline int bgp_initiate_graceful_shut_unshut(struct bgp *bgp,
3273 char *errmsg,
3274 size_t errmsg_len)
3275 {
3276 bgp_static_redo_import_check(bgp);
3277 bgp_redistribute_redo(bgp);
3278 if (bgp_clear_star_soft_out(bgp->name, errmsg, errmsg_len) < 0)
3279 return -1;
3280 if (bgp_clear_star_soft_in(bgp->name, errmsg, errmsg_len) < 0)
3281 return -1;
3282
3283 return 0;
3284 }
3285
3286 static int bgp_global_graceful_shutdown_config_vty(struct vty *vty)
3287 {
3288 struct listnode *node, *nnode;
3289 struct bgp *bgp;
3290 bool vrf_cfg = false;
3291 char errmsg[BUFSIZ] = {'\0'};
3292
3293 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3294 return CMD_SUCCESS;
3295
3296 /* See if graceful-shutdown is set per-vrf and warn user to delete */
3297 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3298 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3299 vty_out(vty,
3300 "%% graceful-shutdown configuration found in vrf %s\n",
3301 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT ?
3302 VRF_DEFAULT_NAME : bgp->name);
3303 vrf_cfg = true;
3304 }
3305 }
3306
3307 if (vrf_cfg) {
3308 vty_out(vty,
3309 "%%Failed: global graceful-shutdown not permitted\n");
3310 return CMD_WARNING;
3311 }
3312
3313 /* Set flag globally */
3314 SET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3315
3316 /* Initiate processing for all BGP instances. */
3317 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3318 if (bgp_initiate_graceful_shut_unshut(bgp, errmsg,
3319 sizeof(errmsg))
3320 < 0)
3321 if (strlen(errmsg))
3322 vty_out(vty, "%s\n", errmsg);
3323 }
3324
3325 return CMD_SUCCESS;
3326 }
3327
3328 static int bgp_global_graceful_shutdown_deconfig_vty(struct vty *vty)
3329 {
3330 struct listnode *node, *nnode;
3331 struct bgp *bgp;
3332 char errmsg[BUFSIZ] = {'\0'};
3333
3334 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3335 return CMD_SUCCESS;
3336
3337 /* Unset flag globally */
3338 UNSET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3339
3340 /* Initiate processing for all BGP instances. */
3341 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3342 if (bgp_initiate_graceful_shut_unshut(bgp, errmsg,
3343 sizeof(errmsg))
3344 < 0)
3345 if (strlen(errmsg))
3346 vty_out(vty, "%s\n", errmsg);
3347 }
3348
3349 return CMD_SUCCESS;
3350 }
3351
3352 /* "bgp graceful-shutdown" configuration */
3353 DEFUN (bgp_graceful_shutdown,
3354 bgp_graceful_shutdown_cmd,
3355 "bgp graceful-shutdown",
3356 BGP_STR
3357 "Graceful shutdown parameters\n")
3358 {
3359 if (vty->node == CONFIG_NODE)
3360 return bgp_global_graceful_shutdown_config_vty(vty);
3361
3362 nb_cli_enqueue_change(vty, "./global/graceful-shutdown/enable",
3363 NB_OP_MODIFY, "true");
3364
3365 return nb_cli_apply_changes(vty, NULL);
3366 }
3367
3368 DEFUN_YANG (no_bgp_graceful_shutdown,
3369 no_bgp_graceful_shutdown_cmd,
3370 "no bgp graceful-shutdown",
3371 NO_STR
3372 BGP_STR
3373 "Graceful shutdown parameters\n")
3374 {
3375 if (vty->node == CONFIG_NODE)
3376 return bgp_global_graceful_shutdown_deconfig_vty(vty);
3377
3378 nb_cli_enqueue_change(vty, "./global/graceful-shutdown/enable",
3379 NB_OP_MODIFY, "false");
3380
3381 return nb_cli_apply_changes(vty, NULL);
3382 }
3383
3384 void cli_show_router_bgp_graceful_shutdown(struct vty *vty,
3385 struct lyd_node *dnode,
3386 bool show_defaults)
3387 {
3388 if (yang_dnode_get_bool(dnode, NULL))
3389 vty_out(vty, " bgp graceful-shutdown\n");
3390 }
3391
3392 /* "bgp fast-external-failover" configuration. */
3393 DEFUN_YANG (bgp_fast_external_failover,
3394 bgp_fast_external_failover_cmd,
3395 "bgp fast-external-failover",
3396 BGP_STR
3397 "Immediately reset session if a link to a directly connected external peer goes down\n")
3398 {
3399 nb_cli_enqueue_change(vty, "./global/fast-external-failover",
3400 NB_OP_MODIFY, "false");
3401
3402 return nb_cli_apply_changes(vty, NULL);
3403 }
3404
3405 DEFUN_YANG (no_bgp_fast_external_failover,
3406 no_bgp_fast_external_failover_cmd,
3407 "no bgp fast-external-failover",
3408 NO_STR
3409 BGP_STR
3410 "Immediately reset session if a link to a directly connected external peer goes down\n")
3411 {
3412 nb_cli_enqueue_change(vty, "./global/fast-external-failover",
3413 NB_OP_MODIFY, "true");
3414
3415 return nb_cli_apply_changes(vty, NULL);
3416 }
3417
3418 void cli_show_router_bgp_fast_external_failover(struct vty *vty,
3419 struct lyd_node *dnode,
3420 bool show_defaults)
3421 {
3422 if (!yang_dnode_get_bool(dnode, NULL))
3423 vty_out(vty, " no bgp fast-external-failover\n");
3424 }
3425
3426 /* "bgp bestpath compare-routerid" configuration. */
3427 DEFUN_YANG(bgp_bestpath_compare_router_id,
3428 bgp_bestpath_compare_router_id_cmd,
3429 "bgp bestpath compare-routerid",
3430 "BGP specific commands\n"
3431 "Change the default bestpath selection\n"
3432 "Compare router-id for identical EBGP paths\n")
3433 {
3434 nb_cli_enqueue_change(
3435 vty,
3436 "./global/route-selection-options/external-compare-router-id",
3437 NB_OP_MODIFY, "true");
3438
3439 return nb_cli_apply_changes(vty, NULL);
3440 }
3441
3442 DEFUN_YANG(no_bgp_bestpath_compare_router_id,
3443 no_bgp_bestpath_compare_router_id_cmd,
3444 "no bgp bestpath compare-routerid",
3445 NO_STR
3446 "BGP specific commands\n"
3447 "Change the default bestpath selection\n"
3448 "Compare router-id for identical EBGP paths\n")
3449 {
3450 nb_cli_enqueue_change(
3451 vty,
3452 "./global/route-selection-options/external-compare-router-id",
3453 NB_OP_MODIFY, "false");
3454
3455 return nb_cli_apply_changes(vty, NULL);
3456 }
3457
3458 /* "bgp bestpath as-path ignore" configuration. */
3459 DEFUN_YANG(bgp_bestpath_aspath_ignore,
3460 bgp_bestpath_aspath_ignore_cmd,
3461 "bgp bestpath as-path ignore",
3462 "BGP specific commands\n"
3463 "Change the default bestpath selection\n"
3464 "AS-path attribute\n"
3465 "Ignore as-path length in selecting a route\n")
3466 {
3467 nb_cli_enqueue_change(
3468 vty, "./global/route-selection-options/ignore-as-path-length",
3469 NB_OP_MODIFY, "true");
3470
3471 return nb_cli_apply_changes(vty, NULL);
3472 }
3473
3474 DEFUN_YANG(no_bgp_bestpath_aspath_ignore,
3475 no_bgp_bestpath_aspath_ignore_cmd,
3476 "no bgp bestpath as-path ignore",
3477 NO_STR
3478 "BGP specific commands\n"
3479 "Change the default bestpath selection\n"
3480 "AS-path attribute\n"
3481 "Ignore as-path length in selecting a route\n")
3482 {
3483 nb_cli_enqueue_change(
3484 vty, "./global/route-selection-options/ignore-as-path-length",
3485 NB_OP_MODIFY, "false");
3486
3487 return nb_cli_apply_changes(vty, NULL);
3488 }
3489
3490 /* "bgp bestpath as-path confed" configuration. */
3491 DEFUN_YANG (bgp_bestpath_aspath_confed,
3492 bgp_bestpath_aspath_confed_cmd,
3493 "bgp bestpath as-path confed",
3494 "BGP specific commands\n"
3495 "Change the default bestpath selection\n"
3496 "AS-path attribute\n"
3497 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3498 {
3499 nb_cli_enqueue_change(vty,
3500 "./global/route-selection-options/aspath-confed",
3501 NB_OP_MODIFY, "true");
3502
3503 return nb_cli_apply_changes(vty, NULL);
3504 }
3505
3506 DEFUN_YANG (no_bgp_bestpath_aspath_confed,
3507 no_bgp_bestpath_aspath_confed_cmd,
3508 "no bgp bestpath as-path confed",
3509 NO_STR
3510 "BGP specific commands\n"
3511 "Change the default bestpath selection\n"
3512 "AS-path attribute\n"
3513 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3514 {
3515 nb_cli_enqueue_change(vty,
3516 "./global/route-selection-options/aspath-confed",
3517 NB_OP_MODIFY, "false");
3518
3519 return nb_cli_apply_changes(vty, NULL);
3520 }
3521
3522 /* "bgp bestpath as-path multipath-relax" configuration. */
3523 DEFUN_YANG (bgp_bestpath_aspath_multipath_relax,
3524 bgp_bestpath_aspath_multipath_relax_cmd,
3525 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
3526 "BGP specific commands\n"
3527 "Change the default bestpath selection\n"
3528 "AS-path attribute\n"
3529 "Allow load sharing across routes that have different AS paths (but same length)\n"
3530 "Generate an AS_SET\n"
3531 "Do not generate an AS_SET\n")
3532 {
3533 int idx = 0;
3534
3535 nb_cli_enqueue_change(
3536 vty, "./global/route-selection-options/allow-multiple-as",
3537 NB_OP_MODIFY, "true");
3538 if (argv_find(argv, argc, "as-set", &idx))
3539 nb_cli_enqueue_change(
3540 vty,
3541 "./global/route-selection-options/multi-path-as-set",
3542 NB_OP_MODIFY, "true");
3543 else
3544 nb_cli_enqueue_change(
3545 vty,
3546 "./global/route-selection-options/multi-path-as-set",
3547 NB_OP_MODIFY, "false");
3548
3549 return nb_cli_apply_changes(vty, NULL);
3550 }
3551
3552 DEFUN_YANG (no_bgp_bestpath_aspath_multipath_relax,
3553 no_bgp_bestpath_aspath_multipath_relax_cmd,
3554 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
3555 NO_STR
3556 "BGP specific commands\n"
3557 "Change the default bestpath selection\n"
3558 "AS-path attribute\n"
3559 "Allow load sharing across routes that have different AS paths (but same length)\n"
3560 "Generate an AS_SET\n"
3561 "Do not generate an AS_SET\n")
3562 {
3563 nb_cli_enqueue_change(
3564 vty, "./global/route-selection-options/allow-multiple-as",
3565 NB_OP_MODIFY, "false");
3566 nb_cli_enqueue_change(
3567 vty, "./global/route-selection-options/multi-path-as-set",
3568 NB_OP_MODIFY, "false");
3569
3570 return nb_cli_apply_changes(vty, NULL);
3571 }
3572
3573 /* "bgp log-neighbor-changes" configuration. */
3574 DEFUN_YANG(bgp_log_neighbor_changes,
3575 bgp_log_neighbor_changes_cmd,
3576 "bgp log-neighbor-changes",
3577 "BGP specific commands\n"
3578 "Log neighbor up/down and reset reason\n")
3579 {
3580 nb_cli_enqueue_change(
3581 vty, "./global/global-neighbor-config/log-neighbor-changes",
3582 NB_OP_MODIFY, "true");
3583
3584 return nb_cli_apply_changes(vty, NULL);
3585 }
3586
3587 DEFUN_YANG(no_bgp_log_neighbor_changes,
3588 no_bgp_log_neighbor_changes_cmd,
3589 "no bgp log-neighbor-changes",
3590 NO_STR
3591 "BGP specific commands\n"
3592 "Log neighbor up/down and reset reason\n")
3593 {
3594 nb_cli_enqueue_change(
3595 vty, "./global/global-neighbor-config/log-neighbor-changes",
3596 NB_OP_MODIFY, "false");
3597
3598 return nb_cli_apply_changes(vty, NULL);
3599 }
3600
3601 /* "bgp bestpath med" configuration. */
3602 DEFUN_YANG (bgp_bestpath_med,
3603 bgp_bestpath_med_cmd,
3604 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
3605 "BGP specific commands\n"
3606 "Change the default bestpath selection\n"
3607 "MED attribute\n"
3608 "Compare MED among confederation paths\n"
3609 "Treat missing MED as the least preferred one\n"
3610 "Treat missing MED as the least preferred one\n"
3611 "Compare MED among confederation paths\n")
3612 {
3613 int idx = 0;
3614 bool confed = false;
3615 bool worst_med = false;
3616
3617
3618 if (argv_find(argv, argc, "confed", &idx))
3619 confed = true;
3620
3621 nb_cli_enqueue_change(vty,
3622 "./global/route-selection-options/confed-med",
3623 NB_OP_MODIFY, confed ? "true" : "false");
3624
3625 idx = 0;
3626 if (argv_find(argv, argc, "missing-as-worst", &idx))
3627 worst_med = true;
3628
3629 nb_cli_enqueue_change(
3630 vty, "./global/route-selection-options/missing-as-worst-med",
3631 NB_OP_MODIFY, worst_med ? "true" : "false");
3632
3633 return nb_cli_apply_changes(vty, NULL);
3634 }
3635
3636 DEFUN_YANG (no_bgp_bestpath_med,
3637 no_bgp_bestpath_med_cmd,
3638 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
3639 NO_STR
3640 "BGP specific commands\n"
3641 "Change the default bestpath selection\n"
3642 "MED attribute\n"
3643 "Compare MED among confederation paths\n"
3644 "Treat missing MED as the least preferred one\n"
3645 "Treat missing MED as the least preferred one\n"
3646 "Compare MED among confederation paths\n")
3647 {
3648 int idx = 0;
3649
3650 if (argv_find(argv, argc, "confed", &idx))
3651 nb_cli_enqueue_change(
3652 vty, "./global/route-selection-options/confed-med",
3653 NB_OP_MODIFY, "false");
3654
3655 idx = 0;
3656 if (argv_find(argv, argc, "missing-as-worst", &idx))
3657 nb_cli_enqueue_change(
3658 vty,
3659 "./global/route-selection-options/missing-as-worst-med",
3660 NB_OP_MODIFY, "false");
3661
3662 return nb_cli_apply_changes(vty, NULL);
3663 }
3664
3665 /* "bgp bestpath bandwidth" configuration. */
3666 DEFPY (bgp_bestpath_bw,
3667 bgp_bestpath_bw_cmd,
3668 "bgp bestpath bandwidth <ignore|skip-missing|default-weight-for-missing>$bw_cfg",
3669 "BGP specific commands\n"
3670 "Change the default bestpath selection\n"
3671 "Link Bandwidth attribute\n"
3672 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3673 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3674 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3675 {
3676 VTY_DECLVAR_CONTEXT(bgp, bgp);
3677 afi_t afi;
3678 safi_t safi;
3679
3680 if (!bw_cfg) {
3681 vty_out(vty, "%% Bandwidth configuration must be specified\n");
3682 return CMD_ERR_INCOMPLETE;
3683 }
3684 if (!strcmp(bw_cfg, "ignore"))
3685 bgp->lb_handling = BGP_LINK_BW_IGNORE_BW;
3686 else if (!strcmp(bw_cfg, "skip-missing"))
3687 bgp->lb_handling = BGP_LINK_BW_SKIP_MISSING;
3688 else if (!strcmp(bw_cfg, "default-weight-for-missing"))
3689 bgp->lb_handling = BGP_LINK_BW_DEFWT_4_MISSING;
3690 else
3691 return CMD_ERR_NO_MATCH;
3692
3693 /* This config is used in route install, so redo that. */
3694 FOREACH_AFI_SAFI (afi, safi) {
3695 if (!bgp_fibupd_safi(safi))
3696 continue;
3697 bgp_zebra_announce_table(bgp, afi, safi);
3698 }
3699
3700 return CMD_SUCCESS;
3701 }
3702
3703 DEFPY (no_bgp_bestpath_bw,
3704 no_bgp_bestpath_bw_cmd,
3705 "no bgp bestpath bandwidth [<ignore|skip-missing|default-weight-for-missing>$bw_cfg]",
3706 NO_STR
3707 "BGP specific commands\n"
3708 "Change the default bestpath selection\n"
3709 "Link Bandwidth attribute\n"
3710 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3711 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3712 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3713 {
3714 VTY_DECLVAR_CONTEXT(bgp, bgp);
3715 afi_t afi;
3716 safi_t safi;
3717
3718 bgp->lb_handling = BGP_LINK_BW_ECMP;
3719
3720 /* This config is used in route install, so redo that. */
3721 FOREACH_AFI_SAFI (afi, safi) {
3722 if (!bgp_fibupd_safi(safi))
3723 continue;
3724 bgp_zebra_announce_table(bgp, afi, safi);
3725 }
3726 return CMD_SUCCESS;
3727 }
3728
3729 /* "no bgp default ipv4-unicast". */
3730 DEFUN (no_bgp_default_ipv4_unicast,
3731 no_bgp_default_ipv4_unicast_cmd,
3732 "no bgp default ipv4-unicast",
3733 NO_STR
3734 "BGP specific commands\n"
3735 "Configure BGP defaults\n"
3736 "Activate ipv4-unicast for a peer by default\n")
3737 {
3738 VTY_DECLVAR_CONTEXT(bgp, bgp);
3739 SET_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4);
3740 return CMD_SUCCESS;
3741 }
3742
3743 DEFUN (bgp_default_ipv4_unicast,
3744 bgp_default_ipv4_unicast_cmd,
3745 "bgp default ipv4-unicast",
3746 "BGP specific commands\n"
3747 "Configure BGP defaults\n"
3748 "Activate ipv4-unicast for a peer by default\n")
3749 {
3750 VTY_DECLVAR_CONTEXT(bgp, bgp);
3751 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4);
3752 return CMD_SUCCESS;
3753 }
3754
3755 /* Display hostname in certain command outputs */
3756 DEFUN_YANG (bgp_default_show_hostname,
3757 bgp_default_show_hostname_cmd,
3758 "bgp default show-hostname",
3759 "BGP specific commands\n"
3760 "Configure BGP defaults\n"
3761 "Show hostname in certain command outputs\n")
3762 {
3763 nb_cli_enqueue_change(vty, "./global/show-hostname", NB_OP_MODIFY,
3764 "true");
3765
3766 return nb_cli_apply_changes(vty, NULL);
3767 }
3768
3769 DEFUN_YANG(no_bgp_default_show_hostname,
3770 no_bgp_default_show_hostname_cmd,
3771 "no bgp default show-hostname",
3772 NO_STR
3773 "BGP specific commands\n"
3774 "Configure BGP defaults\n"
3775 "Show hostname in certain command outputs\n")
3776 {
3777 nb_cli_enqueue_change(vty, "./global/show-hostname", NB_OP_MODIFY,
3778 "false");
3779
3780 return nb_cli_apply_changes(vty, NULL);
3781 }
3782
3783 void cli_show_router_bgp_show_hostname(struct vty *vty, struct lyd_node *dnode,
3784 bool show_defaults)
3785 {
3786 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_SHOW_HOSTNAME)
3787 vty_out(vty, " bgp default show-hostname\n");
3788 }
3789
3790 /* Display hostname in certain command outputs */
3791 DEFUN_YANG(bgp_default_show_nexthop_hostname,
3792 bgp_default_show_nexthop_hostname_cmd,
3793 "bgp default show-nexthop-hostname",
3794 "BGP specific commands\n"
3795 "Configure BGP defaults\n"
3796 "Show hostname for nexthop in certain command outputs\n")
3797 {
3798 nb_cli_enqueue_change(vty, "./global/show-nexthop-hostname",
3799 NB_OP_MODIFY, "true");
3800
3801 return nb_cli_apply_changes(vty, NULL);
3802 }
3803
3804 DEFUN (no_bgp_default_show_nexthop_hostname,
3805 no_bgp_default_show_nexthop_hostname_cmd,
3806 "no bgp default show-nexthop-hostname",
3807 NO_STR
3808 "BGP specific commands\n"
3809 "Configure BGP defaults\n"
3810 "Show hostname for nexthop in certain command outputs\n")
3811 {
3812 nb_cli_enqueue_change(vty, "./global/show-nexthop-hostname",
3813 NB_OP_MODIFY, "false");
3814
3815 return nb_cli_apply_changes(vty, NULL);
3816 }
3817
3818 void cli_show_router_bgp_show_nexthop_hostname(struct vty *vty,
3819 struct lyd_node *dnode,
3820 bool show_defaults)
3821 {
3822 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_SHOW_HOSTNAME)
3823 vty_out(vty, " bgp default show-nexthop-hostname\n");
3824 }
3825
3826 /* "bgp network import-check" configuration. */
3827 DEFUN_YANG(bgp_network_import_check,
3828 bgp_network_import_check_cmd,
3829 "bgp network import-check",
3830 "BGP specific commands\n"
3831 "BGP network command\n"
3832 "Check BGP network route exists in IGP\n")
3833 {
3834 nb_cli_enqueue_change(vty, "./global/import-check", NB_OP_MODIFY,
3835 "true");
3836
3837 return nb_cli_apply_changes(vty, NULL);
3838 }
3839
3840 ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
3841 "bgp network import-check exact",
3842 "BGP specific commands\n"
3843 "BGP network command\n"
3844 "Check BGP network route exists in IGP\n"
3845 "Match route precisely\n")
3846
3847 DEFUN_YANG(no_bgp_network_import_check,
3848 no_bgp_network_import_check_cmd,
3849 "no bgp network import-check",
3850 NO_STR
3851 "BGP specific commands\n"
3852 "BGP network command\n"
3853 "Check BGP network route exists in IGP\n")
3854 {
3855 nb_cli_enqueue_change(vty, "./global/import-check", NB_OP_MODIFY,
3856 "false");
3857
3858 return nb_cli_apply_changes(vty, NULL);
3859 }
3860
3861 void cli_show_router_bgp_import_check(struct vty *vty, struct lyd_node *dnode,
3862 bool show_defaults)
3863 {
3864 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_IMPORT_CHECK)
3865 vty_out(vty, " bgp network import-check\n");
3866 }
3867
3868 DEFUN_YANG(bgp_default_local_preference,
3869 bgp_default_local_preference_cmd,
3870 "bgp default local-preference (0-4294967295)",
3871 "BGP specific commands\n"
3872 "Configure BGP defaults\n"
3873 "local preference (higher=more preferred)\n"
3874 "Configure default local preference value\n")
3875 {
3876 int idx_number = 3;
3877
3878 nb_cli_enqueue_change(vty, "./global/local-pref", NB_OP_MODIFY,
3879 argv[idx_number]->arg);
3880
3881 return nb_cli_apply_changes(vty, NULL);
3882 }
3883
3884 DEFUN_YANG(no_bgp_default_local_preference,
3885 no_bgp_default_local_preference_cmd,
3886 "no bgp default local-preference [(0-4294967295)]",
3887 NO_STR
3888 "BGP specific commands\n"
3889 "Configure BGP defaults\n"
3890 "local preference (higher=more preferred)\n"
3891 "Configure default local preference value\n")
3892 {
3893 nb_cli_enqueue_change(vty, "./global/local-pref", NB_OP_MODIFY, NULL);
3894
3895 return nb_cli_apply_changes(vty, NULL);
3896 }
3897
3898 void cli_show_router_bgp_local_pref(struct vty *vty, struct lyd_node *dnode,
3899 bool show_defaults)
3900 {
3901 vty_out(vty, " bgp default local-preference %u\n",
3902 yang_dnode_get_uint32(dnode, NULL));
3903 }
3904
3905
3906 DEFUN_YANG(bgp_default_subgroup_pkt_queue_max,
3907 bgp_default_subgroup_pkt_queue_max_cmd,
3908 "bgp default subgroup-pkt-queue-max (20-100)",
3909 "BGP specific commands\n"
3910 "Configure BGP defaults\n"
3911 "subgroup-pkt-queue-max\n"
3912 "Configure subgroup packet queue max\n")
3913 {
3914 int idx_number = 3;
3915
3916 nb_cli_enqueue_change(
3917 vty,
3918 "./global/global-update-group-config/subgroup-pkt-queue-size",
3919 NB_OP_MODIFY, argv[idx_number]->arg);
3920
3921 return nb_cli_apply_changes(vty, NULL);
3922 }
3923
3924 DEFUN_YANG(no_bgp_default_subgroup_pkt_queue_max,
3925 no_bgp_default_subgroup_pkt_queue_max_cmd,
3926 "no bgp default subgroup-pkt-queue-max [(20-100)]",
3927 NO_STR
3928 "BGP specific commands\n"
3929 "Configure BGP defaults\n"
3930 "subgroup-pkt-queue-max\n"
3931 "Configure subgroup packet queue max\n")
3932 {
3933 nb_cli_enqueue_change(
3934 vty,
3935 "./global/global-update-group-config/subgroup-pkt-queue-size",
3936 NB_OP_MODIFY, NULL);
3937
3938 return nb_cli_apply_changes(vty, NULL);
3939 }
3940
3941 void cli_show_router_global_update_group_config_subgroup_pkt_queue_size(
3942 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
3943 {
3944 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
3945 yang_dnode_get_uint32(dnode, NULL));
3946 }
3947
3948 DEFUN_YANG(bgp_rr_allow_outbound_policy,
3949 bgp_rr_allow_outbound_policy_cmd,
3950 "bgp route-reflector allow-outbound-policy",
3951 "BGP specific commands\n"
3952 "Allow modifications made by out route-map\n"
3953 "on ibgp neighbors\n")
3954 {
3955 nb_cli_enqueue_change(vty,
3956 "./global/route-reflector/allow-outbound-policy",
3957 NB_OP_MODIFY, "true");
3958
3959 return nb_cli_apply_changes(vty, NULL);
3960 }
3961
3962 DEFUN_YANG(no_bgp_rr_allow_outbound_policy,
3963 no_bgp_rr_allow_outbound_policy_cmd,
3964 "no bgp route-reflector allow-outbound-policy",
3965 NO_STR
3966 "BGP specific commands\n"
3967 "Allow modifications made by out route-map\n"
3968 "on ibgp neighbors\n")
3969 {
3970 nb_cli_enqueue_change(vty,
3971 "./global/route-reflector/allow-outbound-policy",
3972 NB_OP_MODIFY, "false");
3973
3974 return nb_cli_apply_changes(vty, NULL);
3975 }
3976
3977
3978 void cli_show_router_global_neighbor_config(struct vty *vty,
3979 struct lyd_node *dnode,
3980 bool show_defaults)
3981 {
3982 uint32_t write_quanta, read_quanta;
3983
3984 if (yang_dnode_get_bool(dnode, "./log-neighbor-changes"))
3985 vty_out(vty, " bgp log-neighbor-changes\n");
3986
3987 if (yang_dnode_exists(dnode, "./dynamic-neighbors-limit")) {
3988 uint32_t listen_limit = yang_dnode_get_uint32(
3989 dnode, "./dynamic-neighbors-limit");
3990 vty_out(vty, " bgp listen limit %u\n", listen_limit);
3991 }
3992
3993 write_quanta = yang_dnode_get_uint32(
3994 dnode, "./packet-quanta-config/wpkt-quanta");
3995 if (write_quanta != BGP_WRITE_PACKET_MAX)
3996 vty_out(vty, " write-quanta %d\n", write_quanta);
3997
3998 read_quanta = yang_dnode_get_uint32(
3999 dnode, "./packet-quanta-config/rpkt-quanta");
4000
4001 if (read_quanta != BGP_READ_PACKET_MAX)
4002 vty_out(vty, " read-quanta %d\n", read_quanta);
4003 }
4004
4005 DEFUN_YANG(bgp_listen_limit,
4006 bgp_listen_limit_cmd,
4007 "bgp listen limit (1-5000)",
4008 "BGP specific commands\n"
4009 "BGP Dynamic Neighbors listen commands\n"
4010 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4011 "Configure Dynamic Neighbors listen limit value\n")
4012 {
4013 int idx_number = 3;
4014
4015 nb_cli_enqueue_change(
4016 vty, "./global/global-neighbor-config/dynamic-neighbors-limit",
4017 NB_OP_MODIFY, argv[idx_number]->arg);
4018
4019 return nb_cli_apply_changes(vty, NULL);
4020 }
4021
4022 DEFUN_YANG(no_bgp_listen_limit,
4023 no_bgp_listen_limit_cmd,
4024 "no bgp listen limit [(1-5000)]",
4025 NO_STR
4026 "BGP specific commands\n"
4027 "BGP Dynamic Neighbors listen commands\n"
4028 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4029 "Configure Dynamic Neighbors listen limit value\n")
4030 {
4031 nb_cli_enqueue_change(
4032 vty, "./global/global-neighbor-config/dynamic-neighbors-limit",
4033 NB_OP_DESTROY, NULL);
4034
4035 return nb_cli_apply_changes(vty, NULL);
4036 }
4037
4038
4039 /*
4040 * Check if this listen range is already configured. Check for exact
4041 * match or overlap based on input.
4042 */
4043 static struct peer_group *listen_range_exists(struct bgp *bgp,
4044 struct prefix *range, int exact)
4045 {
4046 struct listnode *node, *nnode;
4047 struct listnode *node1, *nnode1;
4048 struct peer_group *group;
4049 struct prefix *lr;
4050 afi_t afi;
4051 int match;
4052
4053 afi = family2afi(range->family);
4054 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4055 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
4056 lr)) {
4057 if (exact)
4058 match = prefix_same(range, lr);
4059 else
4060 match = (prefix_match(range, lr)
4061 || prefix_match(lr, range));
4062 if (match)
4063 return group;
4064 }
4065 }
4066
4067 return NULL;
4068 }
4069
4070 DEFUN (bgp_listen_range,
4071 bgp_listen_range_cmd,
4072 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
4073 "BGP specific commands\n"
4074 "Configure BGP dynamic neighbors listen range\n"
4075 "Configure BGP dynamic neighbors listen range\n"
4076 NEIGHBOR_ADDR_STR
4077 "Member of the peer-group\n"
4078 "Peer-group name\n")
4079 {
4080 VTY_DECLVAR_CONTEXT(bgp, bgp);
4081 struct prefix range;
4082 struct peer_group *group, *existing_group;
4083 afi_t afi;
4084 int ret;
4085 int idx = 0;
4086
4087 argv_find(argv, argc, "A.B.C.D/M", &idx);
4088 argv_find(argv, argc, "X:X::X:X/M", &idx);
4089 char *prefix = argv[idx]->arg;
4090 argv_find(argv, argc, "PGNAME", &idx);
4091 char *peergroup = argv[idx]->arg;
4092
4093 /* Convert IP prefix string to struct prefix. */
4094 ret = str2prefix(prefix, &range);
4095 if (!ret) {
4096 vty_out(vty, "%% Malformed listen range\n");
4097 return CMD_WARNING_CONFIG_FAILED;
4098 }
4099
4100 afi = family2afi(range.family);
4101
4102 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4103 vty_out(vty,
4104 "%% Malformed listen range (link-local address)\n");
4105 return CMD_WARNING_CONFIG_FAILED;
4106 }
4107
4108 apply_mask(&range);
4109
4110 /* Check if same listen range is already configured. */
4111 existing_group = listen_range_exists(bgp, &range, 1);
4112 if (existing_group) {
4113 if (strcmp(existing_group->name, peergroup) == 0)
4114 return CMD_SUCCESS;
4115 else {
4116 vty_out(vty,
4117 "%% Same listen range is attached to peer-group %s\n",
4118 existing_group->name);
4119 return CMD_WARNING_CONFIG_FAILED;
4120 }
4121 }
4122
4123 /* Check if an overlapping listen range exists. */
4124 if (listen_range_exists(bgp, &range, 0)) {
4125 vty_out(vty,
4126 "%% Listen range overlaps with existing listen range\n");
4127 return CMD_WARNING_CONFIG_FAILED;
4128 }
4129
4130 group = peer_group_lookup(bgp, peergroup);
4131 if (!group) {
4132 vty_out(vty, "%% Configure the peer-group first\n");
4133 return CMD_WARNING_CONFIG_FAILED;
4134 }
4135
4136 ret = peer_group_listen_range_add(group, &range);
4137 return bgp_vty_return(vty, ret);
4138 }
4139
4140 DEFUN (no_bgp_listen_range,
4141 no_bgp_listen_range_cmd,
4142 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
4143 NO_STR
4144 "BGP specific commands\n"
4145 "Unconfigure BGP dynamic neighbors listen range\n"
4146 "Unconfigure BGP dynamic neighbors listen range\n"
4147 NEIGHBOR_ADDR_STR
4148 "Member of the peer-group\n"
4149 "Peer-group name\n")
4150 {
4151 VTY_DECLVAR_CONTEXT(bgp, bgp);
4152 struct prefix range;
4153 struct peer_group *group;
4154 afi_t afi;
4155 int ret;
4156 int idx = 0;
4157
4158 argv_find(argv, argc, "A.B.C.D/M", &idx);
4159 argv_find(argv, argc, "X:X::X:X/M", &idx);
4160 char *prefix = argv[idx]->arg;
4161 argv_find(argv, argc, "PGNAME", &idx);
4162 char *peergroup = argv[idx]->arg;
4163
4164 /* Convert IP prefix string to struct prefix. */
4165 ret = str2prefix(prefix, &range);
4166 if (!ret) {
4167 vty_out(vty, "%% Malformed listen range\n");
4168 return CMD_WARNING_CONFIG_FAILED;
4169 }
4170
4171 afi = family2afi(range.family);
4172
4173 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4174 vty_out(vty,
4175 "%% Malformed listen range (link-local address)\n");
4176 return CMD_WARNING_CONFIG_FAILED;
4177 }
4178
4179 apply_mask(&range);
4180
4181 group = peer_group_lookup(bgp, peergroup);
4182 if (!group) {
4183 vty_out(vty, "%% Peer-group does not exist\n");
4184 return CMD_WARNING_CONFIG_FAILED;
4185 }
4186
4187 ret = peer_group_listen_range_del(group, &range);
4188 return bgp_vty_return(vty, ret);
4189 }
4190
4191 void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
4192 {
4193 struct peer_group *group;
4194 struct listnode *node, *nnode, *rnode, *nrnode;
4195 struct prefix *range;
4196 afi_t afi;
4197
4198 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
4199 vty_out(vty, " bgp listen limit %d\n",
4200 bgp->dynamic_neighbors_limit);
4201
4202 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4203 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
4204 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
4205 nrnode, range)) {
4206 vty_out(vty,
4207 " bgp listen range %pFX peer-group %s\n",
4208 range, group->name);
4209 }
4210 }
4211 }
4212 }
4213
4214
4215 DEFUN_YANG(bgp_disable_connected_route_check,
4216 bgp_disable_connected_route_check_cmd,
4217 "bgp disable-ebgp-connected-route-check",
4218 "BGP specific commands\n"
4219 "Disable checking if nexthop is connected on ebgp sessions\n")
4220 {
4221 nb_cli_enqueue_change(vty,
4222 "./global/ebgp-multihop-connected-route-check",
4223 NB_OP_MODIFY, "true");
4224
4225 return nb_cli_apply_changes(vty, NULL);
4226 }
4227
4228 DEFUN_YANG(no_bgp_disable_connected_route_check,
4229 no_bgp_disable_connected_route_check_cmd,
4230 "no bgp disable-ebgp-connected-route-check",
4231 NO_STR
4232 "BGP specific commands\n"
4233 "Disable checking if nexthop is connected on ebgp sessions\n")
4234 {
4235 nb_cli_enqueue_change(vty,
4236 "./global/ebgp-multihop-connected-route-check",
4237 NB_OP_MODIFY, "false");
4238
4239 return nb_cli_apply_changes(vty, NULL);
4240 }
4241
4242 void cli_show_router_global_ebgp_multihop_connected_route_check(
4243 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
4244 {
4245 if (yang_dnode_get_bool(dnode, NULL))
4246 vty_out(vty, " bgp disable-ebgp-connected-route-check\n");
4247 }
4248
4249 DEFUN_YANG(bgp_default_shutdown,
4250 bgp_default_shutdown_cmd,
4251 "[no] bgp default shutdown",
4252 NO_STR BGP_STR
4253 "Configure BGP defaults\n"
4254 "Apply administrative shutdown to newly configured peers\n")
4255 {
4256 nb_cli_enqueue_change(vty, "./global/default-shutdown", NB_OP_MODIFY,
4257 strmatch(argv[0]->text, "no") ? "false" : "true");
4258
4259 return nb_cli_apply_changes(vty, NULL);
4260 }
4261
4262 void cli_show_router_bgp_default_shutdown(struct vty *vty,
4263 struct lyd_node *dnode,
4264 bool show_defaults)
4265 {
4266 if (yang_dnode_get_bool(dnode, NULL))
4267 vty_out(vty, " bgp default shutdown\n");
4268 }
4269
4270 DEFPY(bgp_shutdown_msg, bgp_shutdown_msg_cmd, "bgp shutdown message MSG...",
4271 BGP_STR
4272 "Administrative shutdown of the BGP instance\n"
4273 "Add a shutdown message (RFC 8203)\n"
4274 "Shutdown message\n")
4275 {
4276 char *msgstr = NULL;
4277
4278 VTY_DECLVAR_CONTEXT(bgp, bgp);
4279
4280 if (argc > 3)
4281 msgstr = argv_concat(argv, argc, 3);
4282
4283 bgp_shutdown_enable(bgp, msgstr);
4284 XFREE(MTYPE_TMP, msgstr);
4285
4286 return CMD_SUCCESS;
4287 }
4288
4289 DEFPY(bgp_shutdown, bgp_shutdown_cmd, "bgp shutdown",
4290 BGP_STR "Administrative shutdown of the BGP instance\n")
4291 {
4292 VTY_DECLVAR_CONTEXT(bgp, bgp);
4293
4294 bgp_shutdown_enable(bgp, NULL);
4295
4296 return CMD_SUCCESS;
4297 }
4298
4299 DEFPY(no_bgp_shutdown, no_bgp_shutdown_cmd, "no bgp shutdown",
4300 NO_STR BGP_STR "Administrative shutdown of the BGP instance\n")
4301 {
4302 VTY_DECLVAR_CONTEXT(bgp, bgp);
4303
4304 bgp_shutdown_disable(bgp);
4305
4306 return CMD_SUCCESS;
4307 }
4308
4309 ALIAS(no_bgp_shutdown, no_bgp_shutdown_msg_cmd,
4310 "no bgp shutdown message MSG...", NO_STR BGP_STR
4311 "Administrative shutdown of the BGP instance\n"
4312 "Add a shutdown message (RFC 8203)\n" "Shutdown message\n")
4313
4314 DEFUN_YANG(neighbor_remote_as,
4315 neighbor_remote_as_cmd,
4316 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
4317 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4318 "Specify a BGP neighbor\n" AS_STR
4319 "Internal BGP peer\n"
4320 "External BGP peer\n")
4321 {
4322 int idx_peer = 1;
4323 int idx_remote_as = 3;
4324 char base_xpath[XPATH_MAXLEN];
4325 char unnbr_xpath[XPATH_MAXLEN];
4326 char prgrp_xpath[XPATH_MAXLEN];
4327 union sockunion su;
4328 const char *as_type_str = "as-specified";
4329
4330 if (str2sockunion(argv[idx_peer]->arg, &su) < 0) {
4331 snprintf(unnbr_xpath, sizeof(unnbr_xpath),
4332 FRR_BGP_NEIGHBOR_UNNUM_XPATH, argv[idx_peer]->arg, "");
4333
4334 snprintf(prgrp_xpath, sizeof(prgrp_xpath),
4335 FRR_BGP_PEER_GROUP_XPATH, argv[idx_peer]->arg, "");
4336
4337 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
4338 VTY_CURR_XPATH, unnbr_xpath + 1)) {
4339 strlcpy(base_xpath, unnbr_xpath, sizeof(base_xpath));
4340 } else if (yang_dnode_exists(vty->candidate_config->dnode,
4341 "%s%s", VTY_CURR_XPATH,
4342 prgrp_xpath + 1)) {
4343 snprintf(base_xpath, sizeof(base_xpath),
4344 FRR_BGP_PEER_GROUP_XPATH, argv[idx_peer]->arg,
4345 "");
4346 } else {
4347 vty_out(vty,
4348 "%% Create the peer-group or interface first\n");
4349 return CMD_WARNING_CONFIG_FAILED;
4350 }
4351 } else {
4352 snprintf(base_xpath, sizeof(base_xpath),
4353 FRR_BGP_NEIGHBOR_NUM_XPATH, argv[idx_peer]->arg, "");
4354 }
4355
4356 if (argv[idx_remote_as]->arg[0] == 'i') {
4357 as_type_str = "internal";
4358 } else if (argv[idx_remote_as]->arg[0] == 'e') {
4359 as_type_str = "external";
4360 } else {
4361 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as",
4362 NB_OP_MODIFY, argv[idx_remote_as]->arg);
4363 }
4364 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as-type",
4365 NB_OP_MODIFY, as_type_str);
4366
4367 return nb_cli_apply_changes(vty, base_xpath);
4368 }
4369
4370 int peer_conf_interface_create(struct bgp *bgp, const char *conf_if, afi_t afi,
4371 safi_t safi, bool v6only,
4372 const char *peer_group_name, int as_type,
4373 as_t as, char *errmsg, size_t errmsg_len)
4374 {
4375 struct peer *peer;
4376 struct peer_group *group;
4377 int ret = 0;
4378
4379 group = peer_group_lookup(bgp, conf_if);
4380
4381 if (group) {
4382 snprintf(errmsg, errmsg_len,
4383 "Name conflict with peer-group \n");
4384 return -1;
4385 }
4386
4387 peer = peer_lookup_by_conf_if(bgp, conf_if);
4388 if (peer) {
4389 if (as_type != AS_UNSPECIFIED)
4390 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type,
4391 afi, safi);
4392 } else {
4393 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4)
4394 && afi == AFI_IP && safi == SAFI_UNICAST)
4395 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
4396 as_type, 0, 0, NULL);
4397 else
4398 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
4399 as_type, afi, safi, NULL);
4400
4401 if (!peer) {
4402 snprintf(errmsg, errmsg_len,
4403 "BGP failed to create peer\n");
4404 return -1;
4405 }
4406
4407 if (v6only)
4408 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
4409
4410 /* Request zebra to initiate IPv6 RAs on this interface. We do
4411 * this
4412 * any unnumbered peer in order to not worry about run-time
4413 * transitions
4414 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
4415 * address
4416 * gets deleted later etc.)
4417 */
4418 if (peer->ifp)
4419 bgp_zebra_initiate_radv(bgp, peer);
4420 }
4421
4422 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
4423 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
4424 if (v6only)
4425 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
4426 else
4427 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
4428
4429 /* v6only flag changed. Reset bgp seesion */
4430 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
4431 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
4432 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
4433 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
4434 } else
4435 bgp_session_reset(peer);
4436 }
4437
4438 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
4439 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
4440 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
4441 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
4442 }
4443
4444 if (peer_group_name) {
4445 group = peer_group_lookup(bgp, peer_group_name);
4446 if (!group) {
4447 snprintf(errmsg, errmsg_len,
4448 "Configure the peer-group first\n");
4449 return -1;
4450 }
4451
4452 ret = peer_group_bind(bgp, NULL, peer, group, &as);
4453 }
4454
4455 return bgp_nb_errmsg_return(errmsg, errmsg_len, ret);
4456 }
4457
4458 DEFUN_YANG(neighbor_interface_config,
4459 neighbor_interface_config_cmd,
4460 "neighbor WORD interface [peer-group PGNAME]",
4461 NEIGHBOR_STR
4462 "Interface name or neighbor tag\n"
4463 "Enable BGP on interface\n"
4464 "Member of the peer-group\n"
4465 "Peer-group name\n")
4466 {
4467 int idx_word = 1;
4468 int idx_peer_group_word = 4;
4469 char base_xpath[XPATH_MAXLEN];
4470
4471 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4472 argv[idx_word]->arg, "");
4473
4474 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
4475 if (argc > idx_peer_group_word)
4476 nb_cli_enqueue_change(vty, "./peer-group", NB_OP_MODIFY,
4477 argv[idx_peer_group_word]->arg);
4478
4479 return nb_cli_apply_changes(vty, base_xpath);
4480 }
4481
4482 DEFUN_YANG(neighbor_interface_config_v6only,
4483 neighbor_interface_config_v6only_cmd,
4484 "neighbor WORD interface v6only [peer-group PGNAME]",
4485 NEIGHBOR_STR
4486 "Interface name or neighbor tag\n"
4487 "Enable BGP on interface\n"
4488 "Enable BGP with v6 link-local only\n"
4489 "Member of the peer-group\n"
4490 "Peer-group name\n")
4491 {
4492 int idx_word = 1;
4493 int idx_peer_group_word = 5;
4494 char base_xpath[XPATH_MAXLEN];
4495
4496 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4497 argv[idx_word]->arg, "");
4498
4499 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
4500 if (argc > idx_peer_group_word)
4501 nb_cli_enqueue_change(vty, "./peer-group", NB_OP_MODIFY,
4502 argv[idx_peer_group_word]->arg);
4503
4504 nb_cli_enqueue_change(vty, "./v6only", NB_OP_MODIFY, "true");
4505
4506 return nb_cli_apply_changes(vty, base_xpath);
4507 }
4508
4509
4510 DEFUN_YANG(
4511 neighbor_interface_config_remote_as,
4512 neighbor_interface_config_remote_as_cmd,
4513 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
4514 NEIGHBOR_STR
4515 "Interface name or neighbor tag\n"
4516 "Enable BGP on interface\n"
4517 "Specify a BGP neighbor\n" AS_STR
4518 "Internal BGP peer\n"
4519 "External BGP peer\n")
4520 {
4521 int idx_word = 1;
4522 int idx_remote_as = 4;
4523 char base_xpath[XPATH_MAXLEN];
4524 const char *as_type_str = "as-specified";
4525
4526 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4527 argv[idx_word]->arg, "");
4528
4529 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
4530
4531 if (argv[idx_remote_as]->arg[0] == 'i') {
4532 as_type_str = "internal";
4533 } else if (argv[idx_remote_as]->arg[0] == 'e') {
4534 as_type_str = "external";
4535 } else {
4536 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as",
4537 NB_OP_MODIFY, argv[idx_remote_as]->arg);
4538 }
4539 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as-type",
4540 NB_OP_MODIFY, as_type_str);
4541
4542 return nb_cli_apply_changes(vty, base_xpath);
4543 }
4544
4545 DEFUN_YANG(
4546 neighbor_interface_v6only_config_remote_as,
4547 neighbor_interface_v6only_config_remote_as_cmd,
4548 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
4549 NEIGHBOR_STR
4550 "Interface name or neighbor tag\n"
4551 "Enable BGP with v6 link-local only\n"
4552 "Enable BGP on interface\n"
4553 "Specify a BGP neighbor\n" AS_STR
4554 "Internal BGP peer\n"
4555 "External BGP peer\n")
4556 {
4557 int idx_word = 1;
4558 int idx_remote_as = 5;
4559 char base_xpath[XPATH_MAXLEN];
4560 const char *as_type_str = "as-specified";
4561
4562 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4563 argv[idx_word]->arg, "");
4564
4565 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
4566
4567 nb_cli_enqueue_change(vty, "./v6only", NB_OP_MODIFY, "true");
4568
4569 if (argv[idx_remote_as]->arg[0] == 'i') {
4570 as_type_str = "internal";
4571 } else if (argv[idx_remote_as]->arg[0] == 'e') {
4572 as_type_str = "external";
4573 } else {
4574 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as",
4575 NB_OP_MODIFY, argv[idx_remote_as]->arg);
4576 }
4577 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as-type",
4578 NB_OP_MODIFY, as_type_str);
4579
4580 return nb_cli_apply_changes(vty, base_xpath);
4581 }
4582
4583 DEFUN_YANG(neighbor_peer_group, neighbor_peer_group_cmd,
4584 "neighbor WORD peer-group",
4585 NEIGHBOR_STR
4586 "Interface name or neighbor tag\n"
4587 "Configure peer-group\n")
4588 {
4589 char base_xpath[XPATH_MAXLEN];
4590 int idx_word = 1;
4591
4592 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_PEER_GROUP_XPATH,
4593 argv[idx_word]->arg, "");
4594
4595 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
4596
4597 return nb_cli_apply_changes(vty, base_xpath);
4598 }
4599
4600 DEFUN_YANG(no_neighbor,
4601 no_neighbor_cmd,
4602 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
4603 NO_STR NEIGHBOR_STR
4604 NEIGHBOR_ADDR_STR2
4605 "Specify a BGP neighbor\n" AS_STR
4606 "Internal BGP peer\n"
4607 "External BGP peer\n")
4608 {
4609 int idx_peer = 2;
4610 char base_xpath[XPATH_MAXLEN];
4611 char num_xpath[XPATH_MAXLEN];
4612 char unnbr_xpath[XPATH_MAXLEN];
4613 char prgrp_xpath[XPATH_MAXLEN];
4614 union sockunion su;
4615
4616 if (str2sockunion(argv[idx_peer]->arg, &su) == 0) {
4617 snprintf(num_xpath, sizeof(num_xpath),
4618 FRR_BGP_NEIGHBOR_NUM_XPATH, argv[idx_peer]->arg, "");
4619 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
4620 VTY_CURR_XPATH, num_xpath + 1)) {
4621 strlcpy(base_xpath, num_xpath, sizeof(base_xpath));
4622 }
4623 } else {
4624 snprintf(unnbr_xpath, sizeof(unnbr_xpath),
4625 FRR_BGP_NEIGHBOR_UNNUM_XPATH, argv[idx_peer]->arg, "");
4626
4627 snprintf(prgrp_xpath, sizeof(prgrp_xpath),
4628 FRR_BGP_PEER_GROUP_XPATH, argv[idx_peer]->arg, "");
4629
4630 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
4631 VTY_CURR_XPATH, unnbr_xpath + 1)) {
4632 strlcpy(base_xpath, unnbr_xpath, sizeof(base_xpath));
4633 } else if (yang_dnode_exists(vty->candidate_config->dnode,
4634 "%s%s", VTY_CURR_XPATH,
4635 prgrp_xpath + 1)) {
4636 strlcpy(base_xpath, prgrp_xpath, sizeof(base_xpath));
4637 } else {
4638 vty_out(vty,
4639 "%% Create the peer-group or interface first\n");
4640 return CMD_WARNING_CONFIG_FAILED;
4641 }
4642 }
4643
4644 nb_cli_enqueue_change(vty, base_xpath, NB_OP_DESTROY, NULL);
4645
4646 return nb_cli_apply_changes(vty, NULL);
4647 }
4648
4649 DEFUN_YANG(no_neighbor_interface_config,
4650 no_neighbor_interface_config_cmd,
4651 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
4652 NO_STR NEIGHBOR_STR
4653 "Interface name\n"
4654 "Configure BGP on interface\n"
4655 "Enable BGP with v6 link-local only\n"
4656 "Member of the peer-group\n"
4657 "Peer-group name\n"
4658 "Specify a BGP neighbor\n" AS_STR
4659 "Internal BGP peer\n"
4660 "External BGP peer\n")
4661 {
4662 int idx_word = 2;
4663 char base_xpath[XPATH_MAXLEN];
4664
4665 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4666 argv[idx_word]->arg, "");
4667
4668 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
4669
4670 return nb_cli_apply_changes(vty, base_xpath);
4671 }
4672
4673 DEFUN_YANG(no_neighbor_peer_group,
4674 no_neighbor_peer_group_cmd,
4675 "no neighbor WORD peer-group",
4676 NO_STR NEIGHBOR_STR
4677 "Neighbor tag\n"
4678 "Configure peer-group\n")
4679 {
4680 char base_xpath[XPATH_MAXLEN];
4681 int idx_word = 2;
4682
4683 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_PEER_GROUP_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_interface_peer_group_remote_as,
4692 no_neighbor_interface_peer_group_remote_as_cmd,
4693 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
4694 NO_STR NEIGHBOR_STR
4695 "Interface name or neighbor tag\n"
4696 "Specify a BGP neighbor\n" AS_STR
4697 "Internal BGP peer\n"
4698 "External BGP peer\n")
4699 {
4700 int idx_peer = 2;
4701 char base_xpath[XPATH_MAXLEN];
4702 char unnbr_xpath[XPATH_MAXLEN];
4703 char prgrp_xpath[XPATH_MAXLEN];
4704
4705 snprintf(unnbr_xpath, sizeof(unnbr_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4706 argv[idx_peer]->arg, "");
4707
4708 snprintf(prgrp_xpath, sizeof(prgrp_xpath), FRR_BGP_PEER_GROUP_XPATH,
4709 argv[idx_peer]->arg, "");
4710
4711 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
4712 VTY_CURR_XPATH, unnbr_xpath + 1)) {
4713 strlcpy(base_xpath, unnbr_xpath, sizeof(base_xpath));
4714 } else if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
4715 VTY_CURR_XPATH, prgrp_xpath + 1)) {
4716 strlcpy(base_xpath, prgrp_xpath, sizeof(base_xpath));
4717 } else {
4718 vty_out(vty, "%% Create the peer-group or interface first\n");
4719 return CMD_WARNING_CONFIG_FAILED;
4720 }
4721
4722 strlcat(base_xpath, "/neighbor-remote-as/remote-as-type",
4723 sizeof(base_xpath));
4724
4725 nb_cli_enqueue_change(vty, base_xpath, NB_OP_DESTROY, NULL);
4726
4727 return nb_cli_apply_changes(vty, NULL);
4728 }
4729
4730 DEFUN_YANG(neighbor_local_as,
4731 neighbor_local_as_cmd,
4732 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
4733 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4734 "Specify a local-as number\n"
4735 "AS number used as local AS\n")
4736 {
4737 int idx_peer = 1;
4738 int idx_number = 3;
4739 char base_xpath[XPATH_MAXLEN];
4740
4741 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4742 sizeof(base_xpath), NULL)
4743 < 0)
4744 return CMD_WARNING_CONFIG_FAILED;
4745
4746 nb_cli_enqueue_change(vty, "./local-as/local-as", NB_OP_MODIFY,
4747 argv[idx_number]->arg);
4748
4749 return nb_cli_apply_changes(vty, base_xpath);
4750 }
4751
4752 DEFUN_YANG(
4753 neighbor_local_as_no_prepend, neighbor_local_as_no_prepend_cmd,
4754 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
4755 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4756 "Specify a local-as number\n"
4757 "AS number used as local AS\n"
4758 "Do not prepend local-as to updates from ebgp peers\n")
4759 {
4760 int idx_peer = 1;
4761 int idx_number = 3;
4762 char base_xpath[XPATH_MAXLEN];
4763
4764 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4765 sizeof(base_xpath), NULL)
4766 < 0)
4767 return CMD_WARNING_CONFIG_FAILED;
4768
4769 nb_cli_enqueue_change(vty, "./local-as/local-as", NB_OP_MODIFY,
4770 argv[idx_number]->arg);
4771 nb_cli_enqueue_change(vty, "./local-as/no-prepend", NB_OP_MODIFY,
4772 "true");
4773
4774 return nb_cli_apply_changes(vty, base_xpath);
4775 }
4776
4777 DEFUN_YANG(
4778 neighbor_local_as_no_prepend_replace_as,
4779 neighbor_local_as_no_prepend_replace_as_cmd,
4780 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
4781 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4782 "Specify a local-as number\n"
4783 "AS number used as local AS\n"
4784 "Do not prepend local-as to updates from ebgp peers\n"
4785 "Do not prepend local-as to updates from ibgp peers\n")
4786 {
4787 int idx_peer = 1;
4788 int idx_number = 3;
4789 char base_xpath[XPATH_MAXLEN];
4790
4791 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4792 sizeof(base_xpath), NULL)
4793 < 0)
4794 return CMD_WARNING_CONFIG_FAILED;
4795
4796 nb_cli_enqueue_change(vty, "./local-as/local-as", NB_OP_MODIFY,
4797 argv[idx_number]->arg);
4798 nb_cli_enqueue_change(vty, "./local-as/no-prepend", NB_OP_MODIFY,
4799 "true");
4800 nb_cli_enqueue_change(vty, "./local-as/no-replace-as", NB_OP_MODIFY,
4801 "true");
4802
4803 return nb_cli_apply_changes(vty, base_xpath);
4804 }
4805
4806 DEFUN_YANG(no_neighbor_local_as,
4807 no_neighbor_local_as_cmd,
4808 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
4809 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4810 "Specify a local-as number\n"
4811 "AS number used as local AS\n"
4812 "Do not prepend local-as to updates from ebgp peers\n"
4813 "Do not prepend local-as to updates from ibgp peers\n")
4814 {
4815 int idx_peer = 2;
4816 char base_xpath[XPATH_MAXLEN];
4817
4818 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4819 sizeof(base_xpath), NULL)
4820 < 0)
4821 return CMD_WARNING_CONFIG_FAILED;
4822
4823 nb_cli_enqueue_change(vty, "./local-as/local-as", NB_OP_DESTROY, NULL);
4824 nb_cli_enqueue_change(vty, "./local-as/no-prepend", NB_OP_MODIFY,
4825 "false");
4826 nb_cli_enqueue_change(vty, "./local-as/no-replace-as", NB_OP_MODIFY,
4827 "false");
4828
4829 return nb_cli_apply_changes(vty, base_xpath);
4830 }
4831
4832
4833 DEFUN (neighbor_solo,
4834 neighbor_solo_cmd,
4835 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
4836 NEIGHBOR_STR
4837 NEIGHBOR_ADDR_STR2
4838 "Solo peer - part of its own update group\n")
4839 {
4840 int idx_peer = 1;
4841 struct peer *peer;
4842 int ret;
4843
4844 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4845 if (!peer)
4846 return CMD_WARNING_CONFIG_FAILED;
4847
4848 ret = update_group_adjust_soloness(peer, 1);
4849 return bgp_vty_return(vty, ret);
4850 }
4851
4852 DEFUN (no_neighbor_solo,
4853 no_neighbor_solo_cmd,
4854 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
4855 NO_STR
4856 NEIGHBOR_STR
4857 NEIGHBOR_ADDR_STR2
4858 "Solo peer - part of its own update group\n")
4859 {
4860 int idx_peer = 2;
4861 struct peer *peer;
4862 int ret;
4863
4864 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4865 if (!peer)
4866 return CMD_WARNING_CONFIG_FAILED;
4867
4868 ret = update_group_adjust_soloness(peer, 0);
4869 return bgp_vty_return(vty, ret);
4870 }
4871
4872 DEFUN_YANG(neighbor_password,
4873 neighbor_password_cmd,
4874 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
4875 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4876 "Set a password\n"
4877 "The password\n")
4878 {
4879 int idx_peer = 1;
4880 int idx_line = 3;
4881 char base_xpath[XPATH_MAXLEN];
4882
4883 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4884 sizeof(base_xpath), NULL)
4885 < 0)
4886 return CMD_WARNING_CONFIG_FAILED;
4887
4888 nb_cli_enqueue_change(vty, "./password", NB_OP_MODIFY,
4889 argv[idx_line]->arg);
4890
4891 return nb_cli_apply_changes(vty, base_xpath);
4892 }
4893
4894 DEFUN_YANG(no_neighbor_password,
4895 no_neighbor_password_cmd,
4896 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
4897 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4898 "Set a password\n"
4899 "The password\n")
4900 {
4901 int idx_peer = 2;
4902 char base_xpath[XPATH_MAXLEN];
4903
4904 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4905 sizeof(base_xpath), NULL)
4906 < 0)
4907 return CMD_WARNING_CONFIG_FAILED;
4908
4909 nb_cli_enqueue_change(vty, "./password", NB_OP_DESTROY, NULL);
4910
4911 return nb_cli_apply_changes(vty, base_xpath);
4912 }
4913
4914 DEFUN_YANG(neighbor_activate,
4915 neighbor_activate_cmd,
4916 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4917 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4918 "Enable the Address Family for this Neighbor\n")
4919 {
4920 int idx_peer = 1;
4921 char base_xpath[XPATH_MAXLEN];
4922 char af_xpath[XPATH_MAXLEN];
4923 afi_t afi = bgp_node_afi(vty);
4924 safi_t safi = bgp_node_safi(vty);
4925
4926 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
4927 yang_afi_safi_value2identity(afi, safi));
4928 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4929 sizeof(base_xpath), af_xpath)
4930 < 0)
4931 return CMD_WARNING_CONFIG_FAILED;
4932
4933 nb_cli_enqueue_change(vty, "./enabled", NB_OP_MODIFY, "true");
4934
4935 return nb_cli_apply_changes(vty, base_xpath);
4936 }
4937
4938 ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
4939 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4940 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4941 "Enable the Address Family for this Neighbor\n")
4942
4943 DEFUN_YANG(no_neighbor_activate,
4944 no_neighbor_activate_cmd,
4945 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4946 NO_STR NEIGHBOR_STR
4947 NEIGHBOR_ADDR_STR2
4948 "Enable the Address Family for this Neighbor\n")
4949 {
4950 int idx_peer = 2;
4951 char base_xpath[XPATH_MAXLEN];
4952 char af_xpath[XPATH_MAXLEN];
4953 afi_t afi = bgp_node_afi(vty);
4954 safi_t safi = bgp_node_safi(vty);
4955
4956 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
4957 yang_afi_safi_value2identity(afi, safi));
4958
4959 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4960 sizeof(base_xpath), af_xpath)
4961 < 0)
4962 return CMD_WARNING_CONFIG_FAILED;
4963
4964 nb_cli_enqueue_change(vty, "./enabled", NB_OP_MODIFY, "false");
4965
4966 return nb_cli_apply_changes(vty, base_xpath);
4967 }
4968
4969 ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
4970 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4971 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4972 "Enable the Address Family for this Neighbor\n")
4973
4974 DEFUN (neighbor_set_peer_group,
4975 neighbor_set_peer_group_cmd,
4976 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
4977 NEIGHBOR_STR
4978 NEIGHBOR_ADDR_STR2
4979 "Member of the peer-group\n"
4980 "Peer-group name\n")
4981 {
4982 VTY_DECLVAR_CONTEXT(bgp, bgp);
4983 int idx_peer = 1;
4984 int idx_word = 3;
4985 int ret;
4986 as_t as;
4987 union sockunion su;
4988 struct peer *peer;
4989 struct peer_group *group;
4990
4991 ret = str2sockunion(argv[idx_peer]->arg, &su);
4992 if (ret < 0) {
4993 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4994 if (!peer) {
4995 vty_out(vty, "%% Malformed address or name: %s\n",
4996 argv[idx_peer]->arg);
4997 return CMD_WARNING_CONFIG_FAILED;
4998 }
4999 } else {
5000 if (peer_address_self_check(bgp, &su)) {
5001 vty_out(vty,
5002 "%% Can not configure the local system as neighbor\n");
5003 return CMD_WARNING_CONFIG_FAILED;
5004 }
5005
5006 /* Disallow for dynamic neighbor. */
5007 peer = peer_lookup(bgp, &su);
5008 if (peer && peer_dynamic_neighbor(peer)) {
5009 vty_out(vty,
5010 "%% Operation not allowed on a dynamic neighbor\n");
5011 return CMD_WARNING_CONFIG_FAILED;
5012 }
5013 }
5014
5015 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5016 if (!group) {
5017 vty_out(vty, "%% Configure the peer-group first\n");
5018 return CMD_WARNING_CONFIG_FAILED;
5019 }
5020
5021 ret = peer_group_bind(bgp, &su, peer, group, &as);
5022
5023 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
5024 vty_out(vty,
5025 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
5026 as);
5027 return CMD_WARNING_CONFIG_FAILED;
5028 }
5029
5030 return bgp_vty_return(vty, ret);
5031 }
5032
5033 ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
5034 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5035 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5036 "Member of the peer-group\n"
5037 "Peer-group name\n")
5038
5039 DEFUN_YANG (no_neighbor_set_peer_group,
5040 no_neighbor_set_peer_group_cmd,
5041 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group [PGNAME]",
5042 NO_STR
5043 NEIGHBOR_STR
5044 NEIGHBOR_ADDR_STR2
5045 "Member of the peer-group\n"
5046 "Peer-group name\n")
5047 {
5048 int idx_peer = 2;
5049 char base_xpath[XPATH_MAXLEN];
5050
5051 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5052 sizeof(base_xpath), NULL)
5053 < 0)
5054 return CMD_WARNING_CONFIG_FAILED;
5055
5056 nb_cli_enqueue_change(vty, "./peer-group", NB_OP_DESTROY, NULL);
5057
5058 return nb_cli_apply_changes(vty, base_xpath);
5059 }
5060
5061 ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
5062 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group [PGNAME]",
5063 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5064 "Member of the peer-group\n"
5065 "Peer-group name\n")
5066
5067 static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
5068 uint32_t flag, int set)
5069 {
5070 int ret;
5071 struct peer *peer;
5072
5073 peer = peer_and_group_lookup_vty(vty, ip_str);
5074 if (!peer)
5075 return CMD_WARNING_CONFIG_FAILED;
5076
5077 /*
5078 * If 'neighbor <interface>', then this is for directly connected peers,
5079 * we should not accept disable-connected-check.
5080 */
5081 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
5082 vty_out(vty,
5083 "%s is directly connected peer, cannot accept disable-connected-check\n",
5084 ip_str);
5085 return CMD_WARNING_CONFIG_FAILED;
5086 }
5087
5088 if (!set && flag == PEER_FLAG_SHUTDOWN)
5089 peer_tx_shutdown_message_unset(peer);
5090
5091 if (set)
5092 ret = peer_flag_set(peer, flag);
5093 else
5094 ret = peer_flag_unset(peer, flag);
5095
5096 return bgp_vty_return(vty, ret);
5097 }
5098
5099 static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
5100 {
5101 return peer_flag_modify_vty(vty, ip_str, flag, 1);
5102 }
5103
5104 static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
5105 uint32_t flag)
5106 {
5107 return peer_flag_modify_vty(vty, ip_str, flag, 0);
5108 }
5109
5110 int peer_flag_modify_nb(struct bgp *bgp, const char *ip_str, struct peer *peer,
5111 uint32_t flag, bool set, char *errmsg,
5112 size_t errmsg_len)
5113 {
5114 int ret;
5115
5116 /*
5117 * If 'neighbor <interface>', then this is for directly connected peers,
5118 * we should not accept disable-connected-check.
5119 */
5120 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
5121 snprintf(
5122 errmsg, errmsg_len,
5123 "%s is directly connected peer, cannot accept disable-connected-check\n",
5124 ip_str);
5125 return -1;
5126 }
5127
5128 if (!set && flag == PEER_FLAG_SHUTDOWN)
5129 peer_tx_shutdown_message_unset(peer);
5130
5131 if (set)
5132 ret = peer_flag_set(peer, flag);
5133 else
5134 ret = peer_flag_unset(peer, flag);
5135
5136 return bgp_nb_errmsg_return(errmsg, errmsg_len, ret);
5137 }
5138
5139 /* neighbor passive. */
5140 DEFUN_YANG(neighbor_passive,
5141 neighbor_passive_cmd,
5142 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5143 NEIGHBOR_STR
5144 NEIGHBOR_ADDR_STR2
5145 "Don't send open messages to this neighbor\n")
5146 {
5147 int idx_peer = 1;
5148 char base_xpath[XPATH_MAXLEN];
5149
5150 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5151 sizeof(base_xpath), NULL)
5152 < 0)
5153 return CMD_WARNING_CONFIG_FAILED;
5154
5155 nb_cli_enqueue_change(vty, "./passive-mode", NB_OP_MODIFY, "true");
5156
5157 return nb_cli_apply_changes(vty, base_xpath);
5158 }
5159
5160 DEFUN_YANG(no_neighbor_passive,
5161 no_neighbor_passive_cmd,
5162 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5163 NO_STR NEIGHBOR_STR
5164 NEIGHBOR_ADDR_STR2
5165 "Don't send open messages to this neighbor\n")
5166 {
5167 int idx_peer = 2;
5168 char base_xpath[XPATH_MAXLEN];
5169
5170 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5171 sizeof(base_xpath), NULL)
5172 < 0)
5173 return CMD_WARNING_CONFIG_FAILED;
5174
5175 nb_cli_enqueue_change(vty, "./passive-mode", NB_OP_MODIFY, "false");
5176
5177 return nb_cli_apply_changes(vty, base_xpath);
5178 }
5179
5180 /* neighbor shutdown. */
5181 DEFUN_YANG(neighbor_shutdown_msg,
5182 neighbor_shutdown_msg_cmd,
5183 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5184 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5185 "Administratively shut down this neighbor\n"
5186 "Add a shutdown message (RFC 8203)\n"
5187 "Shutdown message\n")
5188 {
5189 int idx_peer = 1;
5190 char base_xpath[XPATH_MAXLEN];
5191
5192 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5193 sizeof(base_xpath), NULL)
5194 < 0)
5195 return CMD_WARNING_CONFIG_FAILED;
5196
5197 if (argc >= 5) {
5198 char *message;
5199
5200 message = argv_concat(argv, argc, 4);
5201 nb_cli_enqueue_change(vty, "./admin-shutdown/message",
5202 NB_OP_MODIFY, message);
5203 }
5204
5205 nb_cli_enqueue_change(vty, "./admin-shutdown/enable", NB_OP_MODIFY,
5206 "true");
5207
5208 return nb_cli_apply_changes(vty, base_xpath);
5209 }
5210
5211 ALIAS_YANG(neighbor_shutdown_msg, neighbor_shutdown_cmd,
5212 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5213 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5214 "Administratively shut down this neighbor\n")
5215
5216 DEFUN_YANG(no_neighbor_shutdown_msg,
5217 no_neighbor_shutdown_msg_cmd,
5218 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5219 NO_STR NEIGHBOR_STR
5220 NEIGHBOR_ADDR_STR2
5221 "Administratively shut down this neighbor\n"
5222 "Remove a shutdown message (RFC 8203)\n"
5223 "Shutdown message\n")
5224 {
5225 int idx_peer = 2;
5226 char base_xpath[XPATH_MAXLEN];
5227
5228 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5229 sizeof(base_xpath), NULL)
5230 < 0)
5231 return CMD_WARNING_CONFIG_FAILED;
5232
5233 nb_cli_enqueue_change(vty, "./admin-shutdown/enable", NB_OP_MODIFY,
5234 "false");
5235
5236 return nb_cli_apply_changes(vty, base_xpath);
5237 }
5238
5239 ALIAS_YANG(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
5240 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5241 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5242 "Administratively shut down this neighbor\n")
5243
5244 DEFUN(neighbor_shutdown_rtt,
5245 neighbor_shutdown_rtt_cmd,
5246 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt (1-65535) [count (1-255)]",
5247 NEIGHBOR_STR
5248 NEIGHBOR_ADDR_STR2
5249 "Administratively shut down this neighbor\n"
5250 "Shutdown if round-trip-time is higher than expected\n"
5251 "Round-trip-time in milliseconds\n"
5252 "Specify the number of keepalives before shutdown\n"
5253 "The number of keepalives with higher RTT to shutdown\n")
5254 {
5255 int idx_peer = 1;
5256 int idx_rtt = 4;
5257 int idx_count = 0;
5258 struct peer *peer;
5259
5260 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5261
5262 if (!peer)
5263 return CMD_WARNING_CONFIG_FAILED;
5264
5265 peer->rtt_expected = strtol(argv[idx_rtt]->arg, NULL, 10);
5266
5267 if (argv_find(argv, argc, "count", &idx_count))
5268 peer->rtt_keepalive_conf =
5269 strtol(argv[idx_count + 1]->arg, NULL, 10);
5270
5271 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5272 PEER_FLAG_RTT_SHUTDOWN);
5273 }
5274
5275 DEFUN(no_neighbor_shutdown_rtt,
5276 no_neighbor_shutdown_rtt_cmd,
5277 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt [(1-65535) [count (1-255)]]",
5278 NO_STR
5279 NEIGHBOR_STR
5280 NEIGHBOR_ADDR_STR2
5281 "Administratively shut down this neighbor\n"
5282 "Shutdown if round-trip-time is higher than expected\n"
5283 "Round-trip-time in milliseconds\n"
5284 "Specify the number of keepalives before shutdown\n"
5285 "The number of keepalives with higher RTT to shutdown\n")
5286 {
5287 int idx_peer = 2;
5288 struct peer *peer;
5289
5290 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5291
5292 if (!peer)
5293 return CMD_WARNING_CONFIG_FAILED;
5294
5295 peer->rtt_expected = 0;
5296 peer->rtt_keepalive_conf = 1;
5297
5298 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5299 PEER_FLAG_RTT_SHUTDOWN);
5300 }
5301
5302 /* neighbor capability dynamic. */
5303 DEFUN_YANG (neighbor_capability_dynamic,
5304 neighbor_capability_dynamic_cmd,
5305 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5306 NEIGHBOR_STR
5307 NEIGHBOR_ADDR_STR2
5308 "Advertise capability to the peer\n"
5309 "Advertise dynamic capability to this neighbor\n")
5310 {
5311 int idx_peer = 1;
5312 char base_xpath[XPATH_MAXLEN];
5313
5314 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5315 sizeof(base_xpath), NULL)
5316 < 0)
5317 return CMD_WARNING_CONFIG_FAILED;
5318
5319 nb_cli_enqueue_change(vty, "./capability-options/dynamic-capability",
5320 NB_OP_MODIFY, "true");
5321
5322 return nb_cli_apply_changes(vty, base_xpath);
5323 }
5324
5325 DEFUN_YANG (no_neighbor_capability_dynamic,
5326 no_neighbor_capability_dynamic_cmd,
5327 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5328 NO_STR
5329 NEIGHBOR_STR
5330 NEIGHBOR_ADDR_STR2
5331 "Advertise capability to the peer\n"
5332 "Advertise dynamic capability to this neighbor\n")
5333 {
5334 int idx_peer = 2;
5335 char base_xpath[XPATH_MAXLEN];
5336
5337 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5338 sizeof(base_xpath), NULL)
5339 < 0)
5340 return CMD_WARNING_CONFIG_FAILED;
5341
5342 nb_cli_enqueue_change(vty, "./capability-options/dynamic-capability",
5343 NB_OP_MODIFY, "false");
5344
5345 return nb_cli_apply_changes(vty, base_xpath);
5346 }
5347
5348 /* neighbor dont-capability-negotiate */
5349 DEFUN (neighbor_dont_capability_negotiate,
5350 neighbor_dont_capability_negotiate_cmd,
5351 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
5352 NEIGHBOR_STR
5353 NEIGHBOR_ADDR_STR2
5354 "Do not perform capability negotiation\n")
5355 {
5356 int idx_peer = 1;
5357 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5358 PEER_FLAG_DONT_CAPABILITY);
5359 }
5360
5361 DEFUN (no_neighbor_dont_capability_negotiate,
5362 no_neighbor_dont_capability_negotiate_cmd,
5363 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
5364 NO_STR
5365 NEIGHBOR_STR
5366 NEIGHBOR_ADDR_STR2
5367 "Do not perform capability negotiation\n")
5368 {
5369 int idx_peer = 2;
5370 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5371 PEER_FLAG_DONT_CAPABILITY);
5372 }
5373
5374 /* neighbor capability extended next hop encoding */
5375 DEFUN_YANG (neighbor_capability_enhe,
5376 neighbor_capability_enhe_cmd,
5377 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5378 NEIGHBOR_STR
5379 NEIGHBOR_ADDR_STR2
5380 "Advertise capability to the peer\n"
5381 "Advertise extended next-hop capability to the peer\n")
5382 {
5383 int idx_peer = 1;
5384 char base_xpath[XPATH_MAXLEN];
5385
5386 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5387 sizeof(base_xpath), NULL)
5388 < 0)
5389 return CMD_WARNING_CONFIG_FAILED;
5390
5391 nb_cli_enqueue_change(
5392 vty, "./capability-options/extended-nexthop-capability",
5393 NB_OP_MODIFY, "true");
5394
5395 return nb_cli_apply_changes(vty, base_xpath);
5396 }
5397
5398 DEFUN_YANG (no_neighbor_capability_enhe,
5399 no_neighbor_capability_enhe_cmd,
5400 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5401 NO_STR
5402 NEIGHBOR_STR
5403 NEIGHBOR_ADDR_STR2
5404 "Advertise capability to the peer\n"
5405 "Advertise extended next-hop capability to the peer\n")
5406 {
5407 int idx_peer = 2;
5408 char base_xpath[XPATH_MAXLEN];
5409
5410 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5411 sizeof(base_xpath), NULL)
5412 < 0)
5413 return CMD_WARNING_CONFIG_FAILED;
5414
5415 nb_cli_enqueue_change(
5416 vty, "./capability-options/extended-nexthop-capability",
5417 NB_OP_MODIFY, "false");
5418
5419 return nb_cli_apply_changes(vty, base_xpath);
5420 }
5421
5422 int peer_af_flag_modify_nb(struct peer *peer, afi_t afi, safi_t safi,
5423 uint32_t flag, int set, char *errmsg,
5424 size_t errmsg_len)
5425 {
5426 int ret;
5427
5428 if (set)
5429 ret = peer_af_flag_set(peer, afi, safi, flag);
5430 else
5431 ret = peer_af_flag_unset(peer, afi, safi, flag);
5432
5433 return bgp_nb_errmsg_return(errmsg, errmsg_len, ret);
5434 }
5435
5436 static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
5437 afi_t afi, safi_t safi, uint32_t flag,
5438 int set)
5439 {
5440 int ret;
5441 struct peer *peer;
5442
5443 peer = peer_and_group_lookup_vty(vty, peer_str);
5444 if (!peer)
5445 return CMD_WARNING_CONFIG_FAILED;
5446
5447 if (set)
5448 ret = peer_af_flag_set(peer, afi, safi, flag);
5449 else
5450 ret = peer_af_flag_unset(peer, afi, safi, flag);
5451
5452 return bgp_vty_return(vty, ret);
5453 }
5454
5455 static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
5456 afi_t afi, safi_t safi, uint32_t flag)
5457 {
5458 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
5459 }
5460
5461 static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
5462 afi_t afi, safi_t safi, uint32_t flag)
5463 {
5464 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
5465 }
5466
5467 /* neighbor capability orf prefix-list. */
5468 DEFUN (neighbor_capability_orf_prefix,
5469 neighbor_capability_orf_prefix_cmd,
5470 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5471 NEIGHBOR_STR
5472 NEIGHBOR_ADDR_STR2
5473 "Advertise capability to the peer\n"
5474 "Advertise ORF capability to the peer\n"
5475 "Advertise prefixlist ORF capability to this neighbor\n"
5476 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5477 "Capability to RECEIVE the ORF from this neighbor\n"
5478 "Capability to SEND the ORF to this neighbor\n")
5479 {
5480 int idx_send_recv = 5;
5481 char *peer_str = argv[1]->arg;
5482 struct peer *peer;
5483 afi_t afi = bgp_node_afi(vty);
5484 safi_t safi = bgp_node_safi(vty);
5485
5486 peer = peer_and_group_lookup_vty(vty, peer_str);
5487 if (!peer)
5488 return CMD_WARNING_CONFIG_FAILED;
5489
5490 if (strmatch(argv[idx_send_recv]->text, "send"))
5491 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5492 PEER_FLAG_ORF_PREFIX_SM);
5493
5494 if (strmatch(argv[idx_send_recv]->text, "receive"))
5495 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5496 PEER_FLAG_ORF_PREFIX_RM);
5497
5498 if (strmatch(argv[idx_send_recv]->text, "both"))
5499 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5500 PEER_FLAG_ORF_PREFIX_SM)
5501 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5502 PEER_FLAG_ORF_PREFIX_RM);
5503
5504 return CMD_WARNING_CONFIG_FAILED;
5505 }
5506
5507 ALIAS_HIDDEN(
5508 neighbor_capability_orf_prefix,
5509 neighbor_capability_orf_prefix_hidden_cmd,
5510 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5511 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5512 "Advertise capability to the peer\n"
5513 "Advertise ORF capability to the peer\n"
5514 "Advertise prefixlist ORF capability to this neighbor\n"
5515 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5516 "Capability to RECEIVE the ORF from this neighbor\n"
5517 "Capability to SEND the ORF to this neighbor\n")
5518
5519 DEFUN (no_neighbor_capability_orf_prefix,
5520 no_neighbor_capability_orf_prefix_cmd,
5521 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5522 NO_STR
5523 NEIGHBOR_STR
5524 NEIGHBOR_ADDR_STR2
5525 "Advertise capability to the peer\n"
5526 "Advertise ORF capability to the peer\n"
5527 "Advertise prefixlist ORF capability to this neighbor\n"
5528 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5529 "Capability to RECEIVE the ORF from this neighbor\n"
5530 "Capability to SEND the ORF to this neighbor\n")
5531 {
5532 int idx_send_recv = 6;
5533 char *peer_str = argv[2]->arg;
5534 struct peer *peer;
5535 afi_t afi = bgp_node_afi(vty);
5536 safi_t safi = bgp_node_safi(vty);
5537
5538 peer = peer_and_group_lookup_vty(vty, peer_str);
5539 if (!peer)
5540 return CMD_WARNING_CONFIG_FAILED;
5541
5542 if (strmatch(argv[idx_send_recv]->text, "send"))
5543 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5544 PEER_FLAG_ORF_PREFIX_SM);
5545
5546 if (strmatch(argv[idx_send_recv]->text, "receive"))
5547 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5548 PEER_FLAG_ORF_PREFIX_RM);
5549
5550 if (strmatch(argv[idx_send_recv]->text, "both"))
5551 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5552 PEER_FLAG_ORF_PREFIX_SM)
5553 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5554 PEER_FLAG_ORF_PREFIX_RM);
5555
5556 return CMD_WARNING_CONFIG_FAILED;
5557 }
5558
5559 ALIAS_HIDDEN(
5560 no_neighbor_capability_orf_prefix,
5561 no_neighbor_capability_orf_prefix_hidden_cmd,
5562 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5563 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5564 "Advertise capability to the peer\n"
5565 "Advertise ORF capability to the peer\n"
5566 "Advertise prefixlist ORF capability to this neighbor\n"
5567 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5568 "Capability to RECEIVE the ORF from this neighbor\n"
5569 "Capability to SEND the ORF to this neighbor\n")
5570
5571 /* neighbor next-hop-self. */
5572 DEFUN_YANG (neighbor_nexthop_self,
5573 neighbor_nexthop_self_cmd,
5574 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5575 NEIGHBOR_STR
5576 NEIGHBOR_ADDR_STR2
5577 "Disable the next hop calculation for this neighbor\n")
5578 {
5579 int idx_peer = 1;
5580 char base_xpath[XPATH_MAXLEN];
5581 char af_xpath[XPATH_MAXLEN];
5582 char attr_xpath[XPATH_MAXLEN];
5583 afi_t afi = bgp_node_afi(vty);
5584 safi_t safi = bgp_node_safi(vty);
5585
5586 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5587 yang_afi_safi_value2identity(afi, safi));
5588
5589 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5590 sizeof(base_xpath), af_xpath)
5591 < 0)
5592 return CMD_WARNING_CONFIG_FAILED;
5593
5594 snprintf(attr_xpath, sizeof(attr_xpath),
5595 "./%s/nexthop-self/next-hop-self",
5596 bgp_afi_safi_get_container_str(afi, safi));
5597
5598 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5599
5600 return nb_cli_apply_changes(vty, base_xpath);
5601 }
5602
5603 ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
5604 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5605 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5606 "Disable the next hop calculation for this neighbor\n")
5607
5608 /* neighbor next-hop-self. */
5609 DEFUN_YANG(neighbor_nexthop_self_force,
5610 neighbor_nexthop_self_force_cmd,
5611 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5612 NEIGHBOR_STR
5613 NEIGHBOR_ADDR_STR2
5614 "Disable the next hop calculation for this neighbor\n"
5615 "Set the next hop to self for reflected routes\n")
5616 {
5617 int idx_peer = 1;
5618 char base_xpath[XPATH_MAXLEN];
5619 char af_xpath[XPATH_MAXLEN];
5620 char attr_xpath[XPATH_MAXLEN];
5621 afi_t afi = bgp_node_afi(vty);
5622 safi_t safi = bgp_node_safi(vty);
5623
5624 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5625 yang_afi_safi_value2identity(afi, safi));
5626
5627 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5628 sizeof(base_xpath), af_xpath)
5629 < 0)
5630 return CMD_WARNING_CONFIG_FAILED;
5631
5632 snprintf(attr_xpath, sizeof(attr_xpath),
5633 "./%s/nexthop-self/next-hop-self-force",
5634 bgp_afi_safi_get_container_str(afi, safi));
5635
5636 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5637
5638 return nb_cli_apply_changes(vty, base_xpath);
5639 }
5640
5641 ALIAS_HIDDEN(neighbor_nexthop_self_force,
5642 neighbor_nexthop_self_force_hidden_cmd,
5643 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5644 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5645 "Disable the next hop calculation for this neighbor\n"
5646 "Set the next hop to self for reflected routes\n")
5647
5648 ALIAS_HIDDEN(neighbor_nexthop_self_force,
5649 neighbor_nexthop_self_all_hidden_cmd,
5650 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5651 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5652 "Disable the next hop calculation for this neighbor\n"
5653 "Set the next hop to self for reflected routes\n")
5654
5655 DEFUN_YANG (no_neighbor_nexthop_self,
5656 no_neighbor_nexthop_self_cmd,
5657 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5658 NO_STR
5659 NEIGHBOR_STR
5660 NEIGHBOR_ADDR_STR2
5661 "Disable the next hop calculation for this neighbor\n")
5662 {
5663 int idx_peer = 2;
5664 char base_xpath[XPATH_MAXLEN];
5665 char af_xpath[XPATH_MAXLEN];
5666 char attr_xpath[XPATH_MAXLEN];
5667 afi_t afi = bgp_node_afi(vty);
5668 safi_t safi = bgp_node_safi(vty);
5669
5670 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5671 yang_afi_safi_value2identity(afi, safi));
5672
5673 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5674 sizeof(base_xpath), af_xpath)
5675 < 0)
5676 return CMD_WARNING_CONFIG_FAILED;
5677
5678 snprintf(attr_xpath, sizeof(attr_xpath),
5679 "./%s/nexthop-self/next-hop-self",
5680 bgp_afi_safi_get_container_str(afi, safi));
5681
5682 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5683
5684 return nb_cli_apply_changes(vty, base_xpath);
5685 }
5686
5687 ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
5688 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5689 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5690 "Disable the next hop calculation for this neighbor\n")
5691
5692 DEFUN_YANG (no_neighbor_nexthop_self_force,
5693 no_neighbor_nexthop_self_force_cmd,
5694 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5695 NO_STR
5696 NEIGHBOR_STR
5697 NEIGHBOR_ADDR_STR2
5698 "Disable the next hop calculation for this neighbor\n"
5699 "Set the next hop to self for reflected routes\n")
5700 {
5701 int idx_peer = 2;
5702 char base_xpath[XPATH_MAXLEN];
5703 char af_xpath[XPATH_MAXLEN];
5704 char attr_xpath[XPATH_MAXLEN];
5705 afi_t afi = bgp_node_afi(vty);
5706 safi_t safi = bgp_node_safi(vty);
5707
5708 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5709 yang_afi_safi_value2identity(afi, safi));
5710
5711 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5712 sizeof(base_xpath), af_xpath)
5713 < 0)
5714 return CMD_WARNING_CONFIG_FAILED;
5715
5716 snprintf(attr_xpath, sizeof(attr_xpath),
5717 "./%s/nexthop-self/next-hop-self-force",
5718 bgp_afi_safi_get_container_str(afi, safi));
5719
5720 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5721
5722 return nb_cli_apply_changes(vty, base_xpath);
5723 }
5724
5725 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5726 no_neighbor_nexthop_self_force_hidden_cmd,
5727 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5728 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5729 "Disable the next hop calculation for this neighbor\n"
5730 "Set the next hop to self for reflected routes\n")
5731
5732 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5733 no_neighbor_nexthop_self_all_hidden_cmd,
5734 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5735 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5736 "Disable the next hop calculation for this neighbor\n"
5737 "Set the next hop to self for reflected routes\n")
5738
5739 /* neighbor as-override */
5740 DEFUN_YANG (neighbor_as_override,
5741 neighbor_as_override_cmd,
5742 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5743 NEIGHBOR_STR
5744 NEIGHBOR_ADDR_STR2
5745 "Override ASNs in outbound updates if aspath equals remote-as\n")
5746 {
5747 int idx_peer = 1;
5748 char base_xpath[XPATH_MAXLEN];
5749 char af_xpath[XPATH_MAXLEN];
5750 char attr_xpath[XPATH_MAXLEN];
5751 afi_t afi = bgp_node_afi(vty);
5752 safi_t safi = bgp_node_safi(vty);
5753
5754 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5755 yang_afi_safi_value2identity(afi, safi));
5756
5757 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5758 sizeof(base_xpath), af_xpath)
5759 < 0)
5760 return CMD_WARNING_CONFIG_FAILED;
5761
5762 snprintf(attr_xpath, sizeof(attr_xpath),
5763 "./%s/as-path-options/replace-peer-as",
5764 bgp_afi_safi_get_container_str(afi, safi));
5765
5766 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5767
5768 return nb_cli_apply_changes(vty, base_xpath);
5769 }
5770
5771 ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
5772 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5773 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5774 "Override ASNs in outbound updates if aspath equals remote-as\n")
5775
5776 DEFUN_YANG (no_neighbor_as_override,
5777 no_neighbor_as_override_cmd,
5778 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5779 NO_STR
5780 NEIGHBOR_STR
5781 NEIGHBOR_ADDR_STR2
5782 "Override ASNs in outbound updates if aspath equals remote-as\n")
5783 {
5784 int idx_peer = 2;
5785 char base_xpath[XPATH_MAXLEN];
5786 char af_xpath[XPATH_MAXLEN];
5787 char attr_xpath[XPATH_MAXLEN];
5788 afi_t afi = bgp_node_afi(vty);
5789 safi_t safi = bgp_node_safi(vty);
5790
5791 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5792 yang_afi_safi_value2identity(afi, safi));
5793
5794 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5795 sizeof(base_xpath), af_xpath)
5796 < 0)
5797 return CMD_WARNING_CONFIG_FAILED;
5798
5799 snprintf(attr_xpath, sizeof(attr_xpath),
5800 "./%s/as-path-options/replace-peer-as",
5801 bgp_afi_safi_get_container_str(afi, safi));
5802
5803 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5804
5805 return nb_cli_apply_changes(vty, base_xpath);
5806 }
5807
5808 ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
5809 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5810 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5811 "Override ASNs in outbound updates if aspath equals remote-as\n")
5812
5813 /* neighbor remove-private-AS. */
5814 DEFUN_YANG (neighbor_remove_private_as,
5815 neighbor_remove_private_as_cmd,
5816 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5817 NEIGHBOR_STR
5818 NEIGHBOR_ADDR_STR2
5819 "Remove private ASNs in outbound updates\n")
5820 {
5821 int idx_peer = 1;
5822 char base_xpath[XPATH_MAXLEN];
5823 char af_xpath[XPATH_MAXLEN];
5824 char attr_xpath[XPATH_MAXLEN];
5825 afi_t afi = bgp_node_afi(vty);
5826 safi_t safi = bgp_node_safi(vty);
5827
5828 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5829 yang_afi_safi_value2identity(afi, safi));
5830
5831 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5832 sizeof(base_xpath), af_xpath)
5833 < 0)
5834 return CMD_WARNING_CONFIG_FAILED;
5835
5836 snprintf(attr_xpath, sizeof(attr_xpath),
5837 "./%s/private-as/remove-private-as",
5838 bgp_afi_safi_get_container_str(afi, safi));
5839
5840 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5841
5842 return nb_cli_apply_changes(vty, base_xpath);
5843 }
5844
5845 ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
5846 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5847 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5848 "Remove private ASNs in outbound updates\n")
5849
5850 DEFUN_YANG (neighbor_remove_private_as_all,
5851 neighbor_remove_private_as_all_cmd,
5852 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5853 NEIGHBOR_STR
5854 NEIGHBOR_ADDR_STR2
5855 "Remove private ASNs in outbound updates\n"
5856 "Apply to all AS numbers\n")
5857 {
5858 int idx_peer = 1;
5859 char base_xpath[XPATH_MAXLEN];
5860 char af_xpath[XPATH_MAXLEN];
5861 char attr_xpath[XPATH_MAXLEN];
5862 afi_t afi = bgp_node_afi(vty);
5863 safi_t safi = bgp_node_safi(vty);
5864
5865 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5866 yang_afi_safi_value2identity(afi, safi));
5867
5868 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5869 sizeof(base_xpath), af_xpath)
5870 < 0)
5871 return CMD_WARNING_CONFIG_FAILED;
5872
5873 snprintf(attr_xpath, sizeof(attr_xpath),
5874 "./%s/private-as/remove-private-as-all",
5875 bgp_afi_safi_get_container_str(afi, safi));
5876
5877 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5878
5879 return nb_cli_apply_changes(vty, base_xpath);
5880 }
5881
5882 ALIAS_HIDDEN(neighbor_remove_private_as_all,
5883 neighbor_remove_private_as_all_hidden_cmd,
5884 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5885 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5886 "Remove private ASNs in outbound updates\n"
5887 "Apply to all AS numbers")
5888
5889 DEFUN_YANG (neighbor_remove_private_as_replace_as,
5890 neighbor_remove_private_as_replace_as_cmd,
5891 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5892 NEIGHBOR_STR
5893 NEIGHBOR_ADDR_STR2
5894 "Remove private ASNs in outbound updates\n"
5895 "Replace private ASNs with our ASN in outbound updates\n")
5896 {
5897 int idx_peer = 1;
5898 char base_xpath[XPATH_MAXLEN];
5899 char af_xpath[XPATH_MAXLEN];
5900 char attr_xpath[XPATH_MAXLEN];
5901 afi_t afi = bgp_node_afi(vty);
5902 safi_t safi = bgp_node_safi(vty);
5903
5904 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5905 yang_afi_safi_value2identity(afi, safi));
5906
5907 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5908 sizeof(base_xpath), af_xpath)
5909 < 0)
5910 return CMD_WARNING_CONFIG_FAILED;
5911
5912 snprintf(attr_xpath, sizeof(attr_xpath),
5913 "./%s/private-as/remove-private-as-replace",
5914 bgp_afi_safi_get_container_str(afi, safi));
5915
5916 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5917
5918 return nb_cli_apply_changes(vty, base_xpath);
5919 }
5920
5921 ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
5922 neighbor_remove_private_as_replace_as_hidden_cmd,
5923 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5924 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5925 "Remove private ASNs in outbound updates\n"
5926 "Replace private ASNs with our ASN in outbound updates\n")
5927
5928 DEFUN_YANG (neighbor_remove_private_as_all_replace_as,
5929 neighbor_remove_private_as_all_replace_as_cmd,
5930 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5931 NEIGHBOR_STR
5932 NEIGHBOR_ADDR_STR2
5933 "Remove private ASNs in outbound updates\n"
5934 "Apply to all AS numbers\n"
5935 "Replace private ASNs with our ASN in outbound updates\n")
5936 {
5937 int idx_peer = 1;
5938 char base_xpath[XPATH_MAXLEN];
5939 char af_xpath[XPATH_MAXLEN];
5940 char attr_xpath[XPATH_MAXLEN];
5941 afi_t afi = bgp_node_afi(vty);
5942 safi_t safi = bgp_node_safi(vty);
5943
5944 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5945 yang_afi_safi_value2identity(afi, safi));
5946
5947 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5948 sizeof(base_xpath), af_xpath)
5949 < 0)
5950 return CMD_WARNING_CONFIG_FAILED;
5951
5952 snprintf(attr_xpath, sizeof(attr_xpath),
5953 "./%s/private-as/remove-private-as-all-replace",
5954 bgp_afi_safi_get_container_str(afi, safi));
5955
5956 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5957
5958 return nb_cli_apply_changes(vty, base_xpath);
5959 }
5960
5961 ALIAS_HIDDEN(
5962 neighbor_remove_private_as_all_replace_as,
5963 neighbor_remove_private_as_all_replace_as_hidden_cmd,
5964 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5965 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5966 "Remove private ASNs in outbound updates\n"
5967 "Apply to all AS numbers\n"
5968 "Replace private ASNs with our ASN in outbound updates\n")
5969
5970 DEFUN_YANG (no_neighbor_remove_private_as,
5971 no_neighbor_remove_private_as_cmd,
5972 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5973 NO_STR
5974 NEIGHBOR_STR
5975 NEIGHBOR_ADDR_STR2
5976 "Remove private ASNs in outbound updates\n")
5977 {
5978 int idx_peer = 2;
5979 char base_xpath[XPATH_MAXLEN];
5980 char af_xpath[XPATH_MAXLEN];
5981 char attr_xpath[XPATH_MAXLEN];
5982 afi_t afi = bgp_node_afi(vty);
5983 safi_t safi = bgp_node_safi(vty);
5984
5985 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5986 yang_afi_safi_value2identity(afi, safi));
5987
5988 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5989 sizeof(base_xpath), af_xpath)
5990 < 0)
5991 return CMD_WARNING_CONFIG_FAILED;
5992
5993 snprintf(attr_xpath, sizeof(attr_xpath),
5994 "./%s/private-as/remove-private-as",
5995 bgp_afi_safi_get_container_str(afi, safi));
5996
5997 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5998
5999 return nb_cli_apply_changes(vty, base_xpath);
6000 }
6001
6002 ALIAS_HIDDEN(no_neighbor_remove_private_as,
6003 no_neighbor_remove_private_as_hidden_cmd,
6004 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
6005 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6006 "Remove private ASNs in outbound updates\n")
6007
6008 DEFUN_YANG (no_neighbor_remove_private_as_all,
6009 no_neighbor_remove_private_as_all_cmd,
6010 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
6011 NO_STR
6012 NEIGHBOR_STR
6013 NEIGHBOR_ADDR_STR2
6014 "Remove private ASNs in outbound updates\n"
6015 "Apply to all AS numbers\n")
6016 {
6017 int idx_peer = 2;
6018 char base_xpath[XPATH_MAXLEN];
6019 char af_xpath[XPATH_MAXLEN];
6020 char attr_xpath[XPATH_MAXLEN];
6021 afi_t afi = bgp_node_afi(vty);
6022 safi_t safi = bgp_node_safi(vty);
6023
6024 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6025 yang_afi_safi_value2identity(afi, safi));
6026
6027 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6028 sizeof(base_xpath), af_xpath)
6029 < 0)
6030 return CMD_WARNING_CONFIG_FAILED;
6031
6032 snprintf(attr_xpath, sizeof(attr_xpath),
6033 "./%s/private-as/remove-private-as-all",
6034 bgp_afi_safi_get_container_str(afi, safi));
6035
6036 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6037
6038 return nb_cli_apply_changes(vty, base_xpath);
6039 }
6040
6041 ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
6042 no_neighbor_remove_private_as_all_hidden_cmd,
6043 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
6044 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6045 "Remove private ASNs in outbound updates\n"
6046 "Apply to all AS numbers\n")
6047
6048 DEFUN_YANG (no_neighbor_remove_private_as_replace_as,
6049 no_neighbor_remove_private_as_replace_as_cmd,
6050 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
6051 NO_STR
6052 NEIGHBOR_STR
6053 NEIGHBOR_ADDR_STR2
6054 "Remove private ASNs in outbound updates\n"
6055 "Replace private ASNs with our ASN in outbound updates\n")
6056 {
6057 int idx_peer = 2;
6058 char base_xpath[XPATH_MAXLEN];
6059 char af_xpath[XPATH_MAXLEN];
6060 char attr_xpath[XPATH_MAXLEN];
6061 afi_t afi = bgp_node_afi(vty);
6062 safi_t safi = bgp_node_safi(vty);
6063
6064 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6065 yang_afi_safi_value2identity(afi, safi));
6066
6067 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6068 sizeof(base_xpath), af_xpath)
6069 < 0)
6070 return CMD_WARNING_CONFIG_FAILED;
6071
6072 snprintf(attr_xpath, sizeof(attr_xpath),
6073 "./%s/private-as/remove-private-as-replace",
6074 bgp_afi_safi_get_container_str(afi, safi));
6075
6076 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6077
6078 return nb_cli_apply_changes(vty, base_xpath);
6079 }
6080
6081 ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
6082 no_neighbor_remove_private_as_replace_as_hidden_cmd,
6083 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
6084 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6085 "Remove private ASNs in outbound updates\n"
6086 "Replace private ASNs with our ASN in outbound updates\n")
6087
6088 DEFUN_YANG (no_neighbor_remove_private_as_all_replace_as,
6089 no_neighbor_remove_private_as_all_replace_as_cmd,
6090 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
6091 NO_STR
6092 NEIGHBOR_STR
6093 NEIGHBOR_ADDR_STR2
6094 "Remove private ASNs in outbound updates\n"
6095 "Apply to all AS numbers\n"
6096 "Replace private ASNs with our ASN in outbound updates\n")
6097 {
6098 int idx_peer = 2;
6099 char base_xpath[XPATH_MAXLEN];
6100 char af_xpath[XPATH_MAXLEN];
6101 char attr_xpath[XPATH_MAXLEN];
6102 afi_t afi = bgp_node_afi(vty);
6103 safi_t safi = bgp_node_safi(vty);
6104
6105 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6106 yang_afi_safi_value2identity(afi, safi));
6107
6108 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6109 sizeof(base_xpath), af_xpath)
6110 < 0)
6111 return CMD_WARNING_CONFIG_FAILED;
6112
6113 snprintf(attr_xpath, sizeof(attr_xpath),
6114 "./%s/private-as/remove-private-as-all-replace",
6115 bgp_afi_safi_get_container_str(afi, safi));
6116
6117 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6118
6119 return nb_cli_apply_changes(vty, base_xpath);
6120 }
6121
6122 ALIAS_HIDDEN(
6123 no_neighbor_remove_private_as_all_replace_as,
6124 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
6125 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
6126 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6127 "Remove private ASNs in outbound updates\n"
6128 "Apply to all AS numbers\n"
6129 "Replace private ASNs with our ASN in outbound updates\n")
6130
6131
6132 /* neighbor send-community. */
6133 DEFUN_YANG (neighbor_send_community,
6134 neighbor_send_community_cmd,
6135 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6136 NEIGHBOR_STR
6137 NEIGHBOR_ADDR_STR2
6138 "Send Community attribute to this neighbor\n")
6139 {
6140 int idx_peer = 1;
6141
6142 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6143 bgp_node_safi(vty),
6144 PEER_FLAG_SEND_COMMUNITY);
6145 }
6146
6147 ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
6148 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6149 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6150 "Send Community attribute to this neighbor\n")
6151
6152 DEFUN_YANG (no_neighbor_send_community,
6153 no_neighbor_send_community_cmd,
6154 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6155 NO_STR
6156 NEIGHBOR_STR
6157 NEIGHBOR_ADDR_STR2
6158 "Send Community attribute to this neighbor\n")
6159 {
6160 int idx_peer = 2;
6161
6162 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6163 bgp_node_afi(vty), bgp_node_safi(vty),
6164 PEER_FLAG_SEND_COMMUNITY);
6165 }
6166
6167 ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
6168 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6169 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6170 "Send Community attribute to this neighbor\n")
6171
6172 /* neighbor send-community extended. */
6173 DEFUN_YANG (neighbor_send_community_type,
6174 neighbor_send_community_type_cmd,
6175 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6176 NEIGHBOR_STR
6177 NEIGHBOR_ADDR_STR2
6178 "Send Community attribute to this neighbor\n"
6179 "Send Standard and Extended Community attributes\n"
6180 "Send Standard, Large and Extended Community attributes\n"
6181 "Send Extended Community attributes\n"
6182 "Send Standard Community attributes\n"
6183 "Send Large Community attributes\n")
6184 {
6185 const char *type = argv[argc - 1]->text;
6186 char *peer_str = argv[1]->arg;
6187 char base_xpath[XPATH_MAXLEN];
6188 char af_xpath[XPATH_MAXLEN];
6189 char std_xpath[XPATH_MAXLEN];
6190 char ext_xpath[XPATH_MAXLEN];
6191 char lrg_xpath[XPATH_MAXLEN];
6192 afi_t afi = bgp_node_afi(vty);
6193 safi_t safi = bgp_node_safi(vty);
6194
6195 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6196 yang_afi_safi_value2identity(afi, safi));
6197
6198 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6199 sizeof(base_xpath), af_xpath)
6200 < 0)
6201 return CMD_WARNING_CONFIG_FAILED;
6202
6203 if (strmatch(type, "standard")) {
6204 snprintf(std_xpath, sizeof(std_xpath),
6205 "./%s/send-community/send-community",
6206 bgp_afi_safi_get_container_str(afi, safi));
6207
6208 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "true");
6209 }
6210
6211 if (strmatch(type, "extended")) {
6212 snprintf(ext_xpath, sizeof(ext_xpath),
6213 "./%s/send-community/send-ext-community",
6214 bgp_afi_safi_get_container_str(afi, safi));
6215
6216 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "true");
6217 }
6218
6219 if (strmatch(type, "large")) {
6220 snprintf(lrg_xpath, sizeof(lrg_xpath),
6221 "./%s/send-community/send-large-community",
6222 bgp_afi_safi_get_container_str(afi, safi));
6223
6224 nb_cli_enqueue_change(vty, lrg_xpath, NB_OP_MODIFY, "true");
6225 }
6226
6227 if (strmatch(type, "both")) {
6228 snprintf(std_xpath, sizeof(std_xpath),
6229 "./%s/send-community/send-community",
6230 bgp_afi_safi_get_container_str(afi, safi));
6231
6232 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "true");
6233
6234 snprintf(ext_xpath, sizeof(ext_xpath),
6235 "./%s/send-community/send-ext-community",
6236 bgp_afi_safi_get_container_str(afi, safi));
6237
6238 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "true");
6239 }
6240
6241 if (strmatch(type, "all")) {
6242 snprintf(std_xpath, sizeof(std_xpath),
6243 "./%s/send-community/send-community",
6244 bgp_afi_safi_get_container_str(afi, safi));
6245
6246 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "true");
6247
6248 snprintf(ext_xpath, sizeof(ext_xpath),
6249 "./%s/send-community/send-ext-community",
6250 bgp_afi_safi_get_container_str(afi, safi));
6251
6252 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "true");
6253
6254 snprintf(lrg_xpath, sizeof(lrg_xpath),
6255 "./%s/send-community/send-large-community",
6256 bgp_afi_safi_get_container_str(afi, safi));
6257
6258 nb_cli_enqueue_change(vty, lrg_xpath, NB_OP_MODIFY, "true");
6259 }
6260
6261 return nb_cli_apply_changes(vty, base_xpath);
6262 }
6263
6264 ALIAS_HIDDEN(
6265 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
6266 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6267 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6268 "Send Community attribute to this neighbor\n"
6269 "Send Standard and Extended Community attributes\n"
6270 "Send Standard, Large and Extended Community attributes\n"
6271 "Send Extended Community attributes\n"
6272 "Send Standard Community attributes\n"
6273 "Send Large Community attributes\n")
6274
6275 DEFUN_YANG (no_neighbor_send_community_type,
6276 no_neighbor_send_community_type_cmd,
6277 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6278 NO_STR
6279 NEIGHBOR_STR
6280 NEIGHBOR_ADDR_STR2
6281 "Send Community attribute to this neighbor\n"
6282 "Send Standard and Extended Community attributes\n"
6283 "Send Standard, Large and Extended Community attributes\n"
6284 "Send Extended Community attributes\n"
6285 "Send Standard Community attributes\n"
6286 "Send Large Community attributes\n")
6287 {
6288 const char *type = argv[argc - 1]->text;
6289 char *peer_str = argv[2]->arg;
6290 char base_xpath[XPATH_MAXLEN];
6291 char af_xpath[XPATH_MAXLEN];
6292 char std_xpath[XPATH_MAXLEN];
6293 char ext_xpath[XPATH_MAXLEN];
6294 char lrg_xpath[XPATH_MAXLEN];
6295 afi_t afi = bgp_node_afi(vty);
6296 safi_t safi = bgp_node_safi(vty);
6297
6298 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6299 yang_afi_safi_value2identity(afi, safi));
6300
6301 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6302 sizeof(base_xpath), af_xpath)
6303 < 0)
6304 return CMD_WARNING_CONFIG_FAILED;
6305
6306 if (strmatch(type, "standard")) {
6307 snprintf(std_xpath, sizeof(std_xpath),
6308 "./%s/send-community/send-community",
6309 bgp_afi_safi_get_container_str(afi, safi));
6310
6311 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "false");
6312 }
6313
6314 if (strmatch(type, "extended")) {
6315 snprintf(ext_xpath, sizeof(ext_xpath),
6316 "./%s/send-community/send-ext-community",
6317 bgp_afi_safi_get_container_str(afi, safi));
6318
6319 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "false");
6320 }
6321
6322 if (strmatch(type, "large")) {
6323 snprintf(lrg_xpath, sizeof(lrg_xpath),
6324 "./%s/send-community/send-large-community",
6325 bgp_afi_safi_get_container_str(afi, safi));
6326
6327 nb_cli_enqueue_change(vty, lrg_xpath, NB_OP_MODIFY, "false");
6328 }
6329
6330 if (strmatch(type, "both")) {
6331 snprintf(std_xpath, sizeof(std_xpath),
6332 "./%s/send-community/send-community",
6333 bgp_afi_safi_get_container_str(afi, safi));
6334
6335 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "false");
6336
6337 snprintf(ext_xpath, sizeof(ext_xpath),
6338 "./%s/send-community/send-ext-community",
6339 bgp_afi_safi_get_container_str(afi, safi));
6340
6341 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "false");
6342 }
6343
6344 if (strmatch(type, "all")) {
6345 snprintf(std_xpath, sizeof(std_xpath),
6346 "./%s/send-community/send-community",
6347 bgp_afi_safi_get_container_str(afi, safi));
6348
6349 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "false");
6350
6351 snprintf(ext_xpath, sizeof(ext_xpath),
6352 "./%s/send-community/send-ext-community",
6353 bgp_afi_safi_get_container_str(afi, safi));
6354
6355 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "false");
6356
6357 snprintf(lrg_xpath, sizeof(lrg_xpath),
6358 "./%s/send-community/send-large-community",
6359 bgp_afi_safi_get_container_str(afi, safi));
6360
6361 nb_cli_enqueue_change(vty, lrg_xpath, NB_OP_MODIFY, "false");
6362 }
6363
6364 return nb_cli_apply_changes(vty, base_xpath);
6365 }
6366
6367 ALIAS_HIDDEN(
6368 no_neighbor_send_community_type,
6369 no_neighbor_send_community_type_hidden_cmd,
6370 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6371 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6372 "Send Community attribute to this neighbor\n"
6373 "Send Standard and Extended Community attributes\n"
6374 "Send Standard, Large and Extended Community attributes\n"
6375 "Send Extended Community attributes\n"
6376 "Send Standard Community attributes\n"
6377 "Send Large Community attributes\n")
6378
6379 /* neighbor soft-reconfig. */
6380 DEFUN_YANG (neighbor_soft_reconfiguration,
6381 neighbor_soft_reconfiguration_cmd,
6382 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6383 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6384 "Per neighbor soft reconfiguration\n"
6385 "Allow inbound soft reconfiguration for this neighbor\n")
6386 {
6387 int idx_peer = 1;
6388 char base_xpath[XPATH_MAXLEN];
6389 char af_xpath[XPATH_MAXLEN];
6390 char soft_xpath[XPATH_MAXLEN];
6391 afi_t afi = bgp_node_afi(vty);
6392 safi_t safi = bgp_node_safi(vty);
6393
6394 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6395 yang_afi_safi_value2identity(afi, safi));
6396
6397 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6398 sizeof(base_xpath), af_xpath)
6399 < 0)
6400 return CMD_WARNING_CONFIG_FAILED;
6401
6402 snprintf(soft_xpath, sizeof(soft_xpath), "./%s/soft-reconfiguration",
6403 bgp_afi_safi_get_container_str(afi, safi));
6404
6405 nb_cli_enqueue_change(vty, soft_xpath, NB_OP_MODIFY, "true");
6406
6407 return nb_cli_apply_changes(vty, base_xpath);
6408 }
6409
6410 ALIAS_HIDDEN(neighbor_soft_reconfiguration,
6411 neighbor_soft_reconfiguration_hidden_cmd,
6412 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6413 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6414 "Per neighbor soft reconfiguration\n"
6415 "Allow inbound soft reconfiguration for this neighbor\n")
6416
6417 DEFUN_YANG (no_neighbor_soft_reconfiguration,
6418 no_neighbor_soft_reconfiguration_cmd,
6419 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6420 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6421 "Per neighbor soft reconfiguration\n"
6422 "Allow inbound soft reconfiguration for this neighbor\n")
6423 {
6424 int idx_peer = 2;
6425 char base_xpath[XPATH_MAXLEN];
6426 char af_xpath[XPATH_MAXLEN];
6427 char soft_xpath[XPATH_MAXLEN];
6428 afi_t afi = bgp_node_afi(vty);
6429 safi_t safi = bgp_node_safi(vty);
6430
6431 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6432 yang_afi_safi_value2identity(afi, safi));
6433
6434 snprintf(soft_xpath, sizeof(soft_xpath), "./%s/soft-reconfiguration",
6435 bgp_afi_safi_get_container_str(afi, safi));
6436
6437 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6438 sizeof(base_xpath), af_xpath)
6439 < 0)
6440 return CMD_WARNING_CONFIG_FAILED;
6441
6442 nb_cli_enqueue_change(vty, soft_xpath, NB_OP_MODIFY, "false");
6443
6444 return nb_cli_apply_changes(vty, base_xpath);
6445 }
6446
6447 ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
6448 no_neighbor_soft_reconfiguration_hidden_cmd,
6449 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6450 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6451 "Per neighbor soft reconfiguration\n"
6452 "Allow inbound soft reconfiguration for this neighbor\n")
6453
6454 DEFUN_YANG (neighbor_route_reflector_client,
6455 neighbor_route_reflector_client_cmd,
6456 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6457 NEIGHBOR_STR
6458 NEIGHBOR_ADDR_STR2
6459 "Configure a neighbor as Route Reflector client\n")
6460 {
6461 int idx_peer = 1;
6462 char base_xpath[XPATH_MAXLEN];
6463 char af_xpath[XPATH_MAXLEN];
6464 char attr_xpath[XPATH_MAXLEN];
6465 afi_t afi = bgp_node_afi(vty);
6466 safi_t safi = bgp_node_safi(vty);
6467
6468 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6469 yang_afi_safi_value2identity(afi, safi));
6470
6471 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6472 sizeof(base_xpath), af_xpath)
6473 < 0)
6474 return CMD_WARNING_CONFIG_FAILED;
6475
6476 snprintf(attr_xpath, sizeof(attr_xpath),
6477 "./%s/route-reflector/route-reflector-client",
6478 bgp_afi_safi_get_container_str(afi, safi));
6479
6480 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
6481
6482 return nb_cli_apply_changes(vty, base_xpath);
6483 }
6484
6485 ALIAS_HIDDEN(neighbor_route_reflector_client,
6486 neighbor_route_reflector_client_hidden_cmd,
6487 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6488 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6489 "Configure a neighbor as Route Reflector client\n")
6490
6491 DEFUN_YANG (no_neighbor_route_reflector_client,
6492 no_neighbor_route_reflector_client_cmd,
6493 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6494 NO_STR
6495 NEIGHBOR_STR
6496 NEIGHBOR_ADDR_STR2
6497 "Configure a neighbor as Route Reflector client\n")
6498 {
6499 int idx_peer = 2;
6500 char base_xpath[XPATH_MAXLEN];
6501 char af_xpath[XPATH_MAXLEN];
6502 char attr_xpath[XPATH_MAXLEN];
6503 afi_t afi = bgp_node_afi(vty);
6504 safi_t safi = bgp_node_safi(vty);
6505
6506 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6507 yang_afi_safi_value2identity(afi, safi));
6508
6509 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6510 sizeof(base_xpath), af_xpath)
6511 < 0)
6512 return CMD_WARNING_CONFIG_FAILED;
6513
6514 snprintf(attr_xpath, sizeof(attr_xpath),
6515 "./%s/route-reflector/route-reflector-client",
6516 bgp_afi_safi_get_container_str(afi, safi));
6517
6518 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6519
6520 return nb_cli_apply_changes(vty, base_xpath);
6521 }
6522
6523 ALIAS_HIDDEN(no_neighbor_route_reflector_client,
6524 no_neighbor_route_reflector_client_hidden_cmd,
6525 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6526 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6527 "Configure a neighbor as Route Reflector client\n")
6528
6529 /* neighbor route-server-client. */
6530 DEFUN_YANG (neighbor_route_server_client,
6531 neighbor_route_server_client_cmd,
6532 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6533 NEIGHBOR_STR
6534 NEIGHBOR_ADDR_STR2
6535 "Configure a neighbor as Route Server client\n")
6536 {
6537 int idx_peer = 1;
6538 char base_xpath[XPATH_MAXLEN];
6539 char af_xpath[XPATH_MAXLEN];
6540 char attr_xpath[XPATH_MAXLEN];
6541 afi_t afi = bgp_node_afi(vty);
6542 safi_t safi = bgp_node_safi(vty);
6543
6544 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6545 yang_afi_safi_value2identity(afi, safi));
6546
6547 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6548 sizeof(base_xpath), af_xpath)
6549 < 0)
6550 return CMD_WARNING_CONFIG_FAILED;
6551
6552 snprintf(attr_xpath, sizeof(attr_xpath),
6553 "./%s/route-server/route-server-client",
6554 bgp_afi_safi_get_container_str(afi, safi));
6555
6556 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
6557
6558 return nb_cli_apply_changes(vty, base_xpath);
6559 }
6560
6561 ALIAS_HIDDEN(neighbor_route_server_client,
6562 neighbor_route_server_client_hidden_cmd,
6563 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6564 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6565 "Configure a neighbor as Route Server client\n")
6566
6567 DEFUN_YANG (no_neighbor_route_server_client,
6568 no_neighbor_route_server_client_cmd,
6569 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6570 NO_STR
6571 NEIGHBOR_STR
6572 NEIGHBOR_ADDR_STR2
6573 "Configure a neighbor as Route Server client\n")
6574 {
6575 int idx_peer = 2;
6576 char base_xpath[XPATH_MAXLEN];
6577 char af_xpath[XPATH_MAXLEN];
6578 char attr_xpath[XPATH_MAXLEN];
6579 afi_t afi = bgp_node_afi(vty);
6580 safi_t safi = bgp_node_safi(vty);
6581
6582 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6583 yang_afi_safi_value2identity(afi, safi));
6584
6585 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6586 sizeof(base_xpath), af_xpath)
6587 < 0)
6588 return CMD_WARNING_CONFIG_FAILED;
6589
6590 snprintf(attr_xpath, sizeof(attr_xpath),
6591 "./%s/route-server/route-server-client",
6592 bgp_afi_safi_get_container_str(afi, safi));
6593
6594 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6595
6596 return nb_cli_apply_changes(vty, base_xpath);
6597 }
6598
6599 ALIAS_HIDDEN(no_neighbor_route_server_client,
6600 no_neighbor_route_server_client_hidden_cmd,
6601 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6602 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6603 "Configure a neighbor as Route Server client\n")
6604
6605 DEFUN (neighbor_nexthop_local_unchanged,
6606 neighbor_nexthop_local_unchanged_cmd,
6607 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
6608 NEIGHBOR_STR
6609 NEIGHBOR_ADDR_STR2
6610 "Configure treatment of outgoing link-local nexthop attribute\n"
6611 "Leave link-local nexthop unchanged for this peer\n")
6612 {
6613 int idx_peer = 1;
6614 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6615 bgp_node_safi(vty),
6616 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
6617 }
6618
6619 DEFUN (no_neighbor_nexthop_local_unchanged,
6620 no_neighbor_nexthop_local_unchanged_cmd,
6621 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
6622 NO_STR
6623 NEIGHBOR_STR
6624 NEIGHBOR_ADDR_STR2
6625 "Configure treatment of outgoing link-local-nexthop attribute\n"
6626 "Leave link-local nexthop unchanged for this peer\n")
6627 {
6628 int idx_peer = 2;
6629 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6630 bgp_node_afi(vty), bgp_node_safi(vty),
6631 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
6632 }
6633
6634 DEFUN_YANG (neighbor_attr_unchanged,
6635 neighbor_attr_unchanged_cmd,
6636 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6637 NEIGHBOR_STR
6638 NEIGHBOR_ADDR_STR2
6639 "BGP attribute is propagated unchanged to this neighbor\n"
6640 "As-path attribute\n"
6641 "Nexthop attribute\n"
6642 "Med attribute\n")
6643 {
6644 int idx = 0;
6645 char *peer_str = argv[1]->arg;
6646 bool aspath = false;
6647 bool nexthop = false;
6648 bool med = false;
6649 afi_t afi = bgp_node_afi(vty);
6650 safi_t safi = bgp_node_safi(vty);
6651 char base_xpath[XPATH_MAXLEN];
6652 char af_xpath[XPATH_MAXLEN];
6653 char as_xpath[XPATH_MAXLEN];
6654 char nxthop_xpath[XPATH_MAXLEN];
6655 char med_xpath[XPATH_MAXLEN];
6656
6657 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6658 yang_afi_safi_value2identity(afi, safi));
6659
6660 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6661 sizeof(base_xpath), af_xpath)
6662 < 0)
6663 return CMD_WARNING_CONFIG_FAILED;
6664
6665 if (argv_find(argv, argc, "as-path", &idx))
6666 aspath = true;
6667
6668 idx = 0;
6669 if (argv_find(argv, argc, "next-hop", &idx))
6670 nexthop = true;
6671
6672 idx = 0;
6673 if (argv_find(argv, argc, "med", &idx))
6674 med = true;
6675
6676 snprintf(as_xpath, sizeof(as_xpath),
6677 "./%s/attr-unchanged/as-path-unchanged",
6678 bgp_afi_safi_get_container_str(afi, safi));
6679 snprintf(nxthop_xpath, sizeof(nxthop_xpath),
6680 "./%s/attr-unchanged/next-hop-unchanged",
6681 bgp_afi_safi_get_container_str(afi, safi));
6682 snprintf(med_xpath, sizeof(med_xpath),
6683 "./%s/attr-unchanged/med-unchanged",
6684 bgp_afi_safi_get_container_str(afi, safi));
6685
6686 /* no flags means all of them! */
6687 if (!aspath && !nexthop && !med) {
6688 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY, "true");
6689 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY, "true");
6690 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY, "true");
6691 } else {
6692 if (!aspath)
6693 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY,
6694 "false");
6695 else
6696 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY,
6697 "true");
6698
6699 if (!nexthop)
6700 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY,
6701 "false");
6702 else
6703 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY,
6704 "true");
6705
6706 if (!med)
6707 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY,
6708 "false");
6709 else
6710 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY,
6711 "true");
6712 }
6713
6714 return nb_cli_apply_changes(vty, base_xpath);
6715 }
6716
6717 ALIAS_HIDDEN(
6718 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
6719 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6720 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6721 "BGP attribute is propagated unchanged to this neighbor\n"
6722 "As-path attribute\n"
6723 "Nexthop attribute\n"
6724 "Med attribute\n")
6725
6726 DEFUN_YANG (no_neighbor_attr_unchanged,
6727 no_neighbor_attr_unchanged_cmd,
6728 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6729 NO_STR
6730 NEIGHBOR_STR
6731 NEIGHBOR_ADDR_STR2
6732 "BGP attribute is propagated unchanged to this neighbor\n"
6733 "As-path attribute\n"
6734 "Nexthop attribute\n"
6735 "Med attribute\n")
6736 {
6737 int idx = 0;
6738 char *peer_str = argv[2]->arg;
6739 bool aspath = false;
6740 bool nexthop = false;
6741 bool med = false;
6742 afi_t afi = bgp_node_afi(vty);
6743 safi_t safi = bgp_node_safi(vty);
6744 char base_xpath[XPATH_MAXLEN];
6745 char af_xpath[XPATH_MAXLEN];
6746 char as_xpath[XPATH_MAXLEN];
6747 char nxthop_xpath[XPATH_MAXLEN];
6748 char med_xpath[XPATH_MAXLEN];
6749
6750 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6751 yang_afi_safi_value2identity(afi, safi));
6752
6753 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6754 sizeof(base_xpath), af_xpath)
6755 < 0)
6756 return CMD_WARNING_CONFIG_FAILED;
6757
6758 if (argv_find(argv, argc, "as-path", &idx))
6759 aspath = true;
6760
6761 idx = 0;
6762 if (argv_find(argv, argc, "next-hop", &idx))
6763 nexthop = true;
6764
6765 idx = 0;
6766 if (argv_find(argv, argc, "med", &idx))
6767 med = true;
6768
6769 snprintf(as_xpath, sizeof(as_xpath),
6770 "./%s/attr-unchanged/as-path-unchanged",
6771 bgp_afi_safi_get_container_str(afi, safi));
6772 snprintf(nxthop_xpath, sizeof(nxthop_xpath),
6773 "./%s/attr-unchanged/next-hop-unchanged",
6774 bgp_afi_safi_get_container_str(afi, safi));
6775 snprintf(med_xpath, sizeof(med_xpath),
6776 "./%s/attr-unchanged/med-unchanged",
6777 bgp_afi_safi_get_container_str(afi, safi));
6778
6779 /* no flags means all of them! */
6780 if (!aspath && !nexthop && !med) {
6781 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY, "false");
6782 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY, "false");
6783 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY, "false");
6784 }
6785
6786 if (aspath)
6787 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY, "false");
6788
6789 if (nexthop)
6790 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY, "false");
6791
6792 if (med)
6793 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY, "false");
6794
6795 return nb_cli_apply_changes(vty, base_xpath);
6796 }
6797
6798 ALIAS_HIDDEN(
6799 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
6800 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6801 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6802 "BGP attribute is propagated unchanged to this neighbor\n"
6803 "As-path attribute\n"
6804 "Nexthop attribute\n"
6805 "Med attribute\n")
6806
6807 /* neighbor ebgp-multihop. */
6808 DEFUN_YANG (neighbor_ebgp_multihop,
6809 neighbor_ebgp_multihop_cmd,
6810 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
6811 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6812 "Allow EBGP neighbors not on directly connected networks\n")
6813 {
6814 int idx_peer = 1;
6815 char base_xpath[XPATH_MAXLEN];
6816
6817 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6818 sizeof(base_xpath), NULL)
6819 < 0)
6820 return CMD_WARNING_CONFIG_FAILED;
6821
6822 nb_cli_enqueue_change(vty, "./ebgp-multihop/enabled", NB_OP_MODIFY,
6823 "true");
6824
6825 return nb_cli_apply_changes(vty, base_xpath);
6826 }
6827
6828 DEFUN_YANG (neighbor_ebgp_multihop_ttl,
6829 neighbor_ebgp_multihop_ttl_cmd,
6830 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
6831 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6832 "Allow EBGP neighbors not on directly connected networks\n"
6833 "maximum hop count\n")
6834 {
6835 int idx_peer = 1;
6836 int idx_number = 3;
6837 char base_xpath[XPATH_MAXLEN];
6838
6839 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6840 sizeof(base_xpath), NULL)
6841 < 0)
6842 return CMD_WARNING_CONFIG_FAILED;
6843
6844 nb_cli_enqueue_change(vty, "./ebgp-multihop/multihop-ttl", NB_OP_MODIFY,
6845 argv[idx_number]->arg);
6846
6847 return nb_cli_apply_changes(vty, base_xpath);
6848 }
6849
6850 DEFUN_YANG (no_neighbor_ebgp_multihop,
6851 no_neighbor_ebgp_multihop_cmd,
6852 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
6853 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6854 "Allow EBGP neighbors not on directly connected networks\n"
6855 "maximum hop count\n")
6856 {
6857 int idx_peer = 2;
6858 char base_xpath[XPATH_MAXLEN];
6859
6860 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6861 sizeof(base_xpath), NULL)
6862 < 0)
6863 return CMD_WARNING_CONFIG_FAILED;
6864
6865 if (argc > 4)
6866 nb_cli_enqueue_change(vty, "./ebgp-multihop/multihop-ttl",
6867 NB_OP_DESTROY, NULL);
6868 else
6869 nb_cli_enqueue_change(vty, "./ebgp-multihop/enabled",
6870 NB_OP_MODIFY, "false");
6871
6872 return nb_cli_apply_changes(vty, base_xpath);
6873 }
6874
6875
6876 /* disable-connected-check */
6877 DEFUN_YANG (neighbor_disable_connected_check,
6878 neighbor_disable_connected_check_cmd,
6879 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6880 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6881 "one-hop away EBGP peer using loopback address\n"
6882 "Enforce EBGP neighbors perform multihop\n")
6883 {
6884 int idx_peer = 1;
6885 char base_xpath[XPATH_MAXLEN];
6886
6887 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6888 sizeof(base_xpath), NULL)
6889 < 0)
6890 return CMD_WARNING_CONFIG_FAILED;
6891
6892 nb_cli_enqueue_change(vty, "./ebgp-multihop/disable-connected-check",
6893 NB_OP_MODIFY, "true");
6894
6895 return nb_cli_apply_changes(vty, base_xpath);
6896 }
6897
6898 DEFUN_YANG (no_neighbor_disable_connected_check,
6899 no_neighbor_disable_connected_check_cmd,
6900 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6901 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6902 "one-hop away EBGP peer using loopback address\n"
6903 "Enforce EBGP neighbors perform multihop\n")
6904 {
6905 int idx_peer = 2;
6906 char base_xpath[XPATH_MAXLEN];
6907
6908 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6909 sizeof(base_xpath), NULL)
6910 < 0)
6911 return CMD_WARNING_CONFIG_FAILED;
6912
6913 nb_cli_enqueue_change(vty, "./ebgp-multihop/disable-connected-check",
6914 NB_OP_MODIFY, "false");
6915
6916 return nb_cli_apply_changes(vty, base_xpath);
6917 }
6918
6919
6920 /* enforce-first-as */
6921 DEFUN_YANG (neighbor_enforce_first_as,
6922 neighbor_enforce_first_as_cmd,
6923 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6924 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6925 "Enforce the first AS for EBGP routes\n")
6926 {
6927 int idx_peer = 1;
6928 char base_xpath[XPATH_MAXLEN];
6929
6930 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6931 sizeof(base_xpath), NULL)
6932 < 0)
6933 return CMD_WARNING_CONFIG_FAILED;
6934
6935 nb_cli_enqueue_change(vty, "./enforce-first-as", NB_OP_MODIFY, "true");
6936
6937 return nb_cli_apply_changes(vty, base_xpath);
6938 }
6939
6940 DEFUN_YANG (no_neighbor_enforce_first_as,
6941 no_neighbor_enforce_first_as_cmd,
6942 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6943 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6944 "Enforce the first AS for EBGP routes\n")
6945 {
6946 int idx_peer = 2;
6947 char base_xpath[XPATH_MAXLEN];
6948
6949 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6950 sizeof(base_xpath), NULL)
6951 < 0)
6952 return CMD_WARNING_CONFIG_FAILED;
6953
6954 nb_cli_enqueue_change(vty, "./enforce-first-as", NB_OP_MODIFY, "false");
6955
6956 return nb_cli_apply_changes(vty, base_xpath);
6957 }
6958
6959 static int peer_and_group_lookup_nb(struct vty *vty, const char *peer_str,
6960 char *base_xpath, int xpath_len,
6961 char *xpath)
6962 {
6963 union sockunion su;
6964 char num_xpath[XPATH_MAXLEN];
6965 char unnbr_xpath[XPATH_MAXLEN];
6966 char prgrp_xpath[XPATH_MAXLEN];
6967
6968 if (str2sockunion(peer_str, &su) == 0) {
6969 snprintf(num_xpath, sizeof(num_xpath),
6970 "/neighbors/neighbor[remote-address='%s']", peer_str);
6971 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
6972 VTY_CURR_XPATH, num_xpath)) {
6973 snprintf(base_xpath, xpath_len,
6974 FRR_BGP_NEIGHBOR_NUM_XPATH, peer_str,
6975 xpath ? xpath : "");
6976 } else {
6977 vty_out(vty,
6978 "%% Specify remote-as or peer-group commands first\n");
6979 return -1;
6980 }
6981
6982 } else {
6983 snprintf(unnbr_xpath, sizeof(unnbr_xpath),
6984 "/neighbors/unnumbered-neighbor[interface='%s']",
6985 peer_str);
6986
6987 snprintf(prgrp_xpath, sizeof(prgrp_xpath),
6988 "/peer-groups/peer-group[peer-group-name='%s']",
6989 peer_str);
6990
6991 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
6992 VTY_CURR_XPATH, unnbr_xpath)) {
6993 snprintf(base_xpath, xpath_len,
6994 FRR_BGP_NEIGHBOR_UNNUM_XPATH, peer_str,
6995 xpath ? xpath : "");
6996 } else if (yang_dnode_exists(vty->candidate_config->dnode,
6997 "%s%s", VTY_CURR_XPATH,
6998 prgrp_xpath)) {
6999 snprintf(base_xpath, xpath_len,
7000 FRR_BGP_PEER_GROUP_XPATH, peer_str,
7001 xpath ? xpath : "");
7002 } else {
7003 vty_out(vty,
7004 "%% Create the peer-group or interface first\n");
7005 return -1;
7006 }
7007 }
7008
7009 return 0;
7010 }
7011
7012 DEFUN_YANG (neighbor_description,
7013 neighbor_description_cmd,
7014 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
7015 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7016 "Neighbor specific description\n"
7017 "Up to 80 characters describing this neighbor\n")
7018 {
7019 int idx_peer = 1;
7020 int idx_line = 3;
7021 int ret;
7022 char base_xpath[XPATH_MAXLEN];
7023 char *str;
7024
7025 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7026 sizeof(base_xpath), NULL)
7027 < 0)
7028 return CMD_WARNING_CONFIG_FAILED;
7029
7030 str = argv_concat(argv, argc, idx_line);
7031
7032 nb_cli_enqueue_change(vty, "./description", NB_OP_MODIFY, str);
7033
7034 ret = nb_cli_apply_changes(vty, base_xpath);
7035
7036 XFREE(MTYPE_TMP, str);
7037
7038 return ret;
7039 }
7040
7041 DEFUN_YANG (no_neighbor_description,
7042 no_neighbor_description_cmd,
7043 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
7044 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7045 "Neighbor specific description\n")
7046 {
7047 int idx_peer = 2;
7048 char base_xpath[XPATH_MAXLEN];
7049
7050 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7051 sizeof(base_xpath), NULL)
7052 < 0)
7053 return CMD_WARNING_CONFIG_FAILED;
7054
7055 nb_cli_enqueue_change(vty, "./description", NB_OP_DESTROY, NULL);
7056
7057 return nb_cli_apply_changes(vty, base_xpath);
7058 }
7059
7060 ALIAS_YANG(no_neighbor_description, no_neighbor_description_comment_cmd,
7061 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
7062 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7063 "Neighbor specific description\n"
7064 "Up to 80 characters describing this neighbor\n")
7065
7066 #define BGP_UPDATE_SOURCE_HELP_STR \
7067 "IPv4 address\n" \
7068 "IPv6 address\n" \
7069 "Interface name (requires zebra to be running)\n"
7070
7071 DEFUN_YANG (neighbor_update_source,
7072 neighbor_update_source_cmd,
7073 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
7074 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7075 "Source of routing updates\n"
7076 BGP_UPDATE_SOURCE_HELP_STR)
7077 {
7078 int idx_peer = 1;
7079 int idx_peer_2 = 3;
7080 union sockunion su;
7081 char base_xpath[XPATH_MAXLEN];
7082
7083 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7084 sizeof(base_xpath), NULL)
7085 < 0)
7086 return CMD_WARNING_CONFIG_FAILED;
7087
7088 if (str2sockunion(argv[idx_peer_2]->arg, &su) == 0)
7089 nb_cli_enqueue_change(vty, "./update-source/ip", NB_OP_MODIFY,
7090 argv[idx_peer_2]->arg);
7091 else
7092 nb_cli_enqueue_change(vty, "./update-source/interface",
7093 NB_OP_MODIFY, argv[idx_peer_2]->arg);
7094
7095 return nb_cli_apply_changes(vty, base_xpath);
7096 }
7097
7098 DEFUN_YANG (no_neighbor_update_source,
7099 no_neighbor_update_source_cmd,
7100 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
7101 NO_STR NEIGHBOR_STR
7102 NEIGHBOR_ADDR_STR2
7103 "Source of routing updates\n"
7104 BGP_UPDATE_SOURCE_HELP_STR)
7105 {
7106 int idx_peer = 2;
7107 char base_xpath[XPATH_MAXLEN];
7108
7109 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7110 sizeof(base_xpath), NULL)
7111 < 0)
7112 return CMD_WARNING_CONFIG_FAILED;
7113
7114 nb_cli_enqueue_change(vty, "./update-source/ip", NB_OP_DESTROY, NULL);
7115 nb_cli_enqueue_change(vty, "./update-source/interface", NB_OP_DESTROY,
7116 NULL);
7117
7118 return nb_cli_apply_changes(vty, base_xpath);
7119 }
7120
7121 static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
7122 afi_t afi, safi_t safi,
7123 const char *rmap, int set)
7124 {
7125 int ret;
7126 struct peer *peer;
7127 struct route_map *route_map = NULL;
7128
7129 peer = peer_and_group_lookup_vty(vty, peer_str);
7130 if (!peer)
7131 return CMD_WARNING_CONFIG_FAILED;
7132
7133 if (set) {
7134 if (rmap)
7135 route_map = route_map_lookup_warn_noexist(vty, rmap);
7136 ret = peer_default_originate_set(peer, afi, safi,
7137 rmap, route_map);
7138 } else
7139 ret = peer_default_originate_unset(peer, afi, safi);
7140
7141 return bgp_vty_return(vty, ret);
7142 }
7143
7144 /* neighbor default-originate. */
7145 DEFUN (neighbor_default_originate,
7146 neighbor_default_originate_cmd,
7147 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
7148 NEIGHBOR_STR
7149 NEIGHBOR_ADDR_STR2
7150 "Originate default route to this neighbor\n")
7151 {
7152 int idx_peer = 1;
7153 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
7154 bgp_node_afi(vty),
7155 bgp_node_safi(vty), NULL, 1);
7156 }
7157
7158 ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
7159 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
7160 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7161 "Originate default route to this neighbor\n")
7162
7163 DEFUN (neighbor_default_originate_rmap,
7164 neighbor_default_originate_rmap_cmd,
7165 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
7166 NEIGHBOR_STR
7167 NEIGHBOR_ADDR_STR2
7168 "Originate default route to this neighbor\n"
7169 "Route-map to specify criteria to originate default\n"
7170 "route-map name\n")
7171 {
7172 int idx_peer = 1;
7173 int idx_word = 4;
7174 return peer_default_originate_set_vty(
7175 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7176 argv[idx_word]->arg, 1);
7177 }
7178
7179 ALIAS_HIDDEN(
7180 neighbor_default_originate_rmap,
7181 neighbor_default_originate_rmap_hidden_cmd,
7182 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
7183 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7184 "Originate default route to this neighbor\n"
7185 "Route-map to specify criteria to originate default\n"
7186 "route-map name\n")
7187
7188 DEFUN (no_neighbor_default_originate,
7189 no_neighbor_default_originate_cmd,
7190 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
7191 NO_STR
7192 NEIGHBOR_STR
7193 NEIGHBOR_ADDR_STR2
7194 "Originate default route to this neighbor\n"
7195 "Route-map to specify criteria to originate default\n"
7196 "route-map name\n")
7197 {
7198 int idx_peer = 2;
7199 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
7200 bgp_node_afi(vty),
7201 bgp_node_safi(vty), NULL, 0);
7202 }
7203
7204 ALIAS_HIDDEN(
7205 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
7206 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
7207 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7208 "Originate default route to this neighbor\n"
7209 "Route-map to specify criteria to originate default\n"
7210 "route-map name\n")
7211
7212
7213 /* Set specified peer's BGP port. */
7214 DEFUN_YANG (neighbor_port,
7215 neighbor_port_cmd,
7216 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
7217 NEIGHBOR_STR
7218 NEIGHBOR_ADDR_STR
7219 "Neighbor's BGP port\n"
7220 "TCP port number\n")
7221 {
7222 int idx_ip = 1;
7223 int idx_number = 3;
7224 char base_xpath[XPATH_MAXLEN];
7225
7226 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_NUM_XPATH,
7227 argv[idx_ip]->arg, "");
7228
7229 nb_cli_enqueue_change(vty, "./local-port", NB_OP_MODIFY,
7230 argv[idx_number]->arg);
7231
7232 return nb_cli_apply_changes(vty, base_xpath);
7233 }
7234
7235 DEFUN_YANG (no_neighbor_port,
7236 no_neighbor_port_cmd,
7237 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
7238 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR
7239 "Neighbor's BGP port\n"
7240 "TCP port number\n")
7241 {
7242 int idx_ip = 2;
7243 char base_xpath[XPATH_MAXLEN];
7244
7245 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_NUM_XPATH,
7246 argv[idx_ip]->arg, "");
7247
7248 nb_cli_enqueue_change(vty, "./local-port", NB_OP_DESTROY, NULL);
7249
7250 return nb_cli_apply_changes(vty, base_xpath);
7251 }
7252
7253 DEFUN_YANG (neighbor_weight,
7254 neighbor_weight_cmd,
7255 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7256 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7257 "Set default weight for routes from this neighbor\n"
7258 "default weight\n")
7259 {
7260 int idx_peer = 1;
7261 int idx_number = 3;
7262 char base_xpath[XPATH_MAXLEN];
7263 char af_xpath[XPATH_MAXLEN];
7264 char attr_xpath[XPATH_MAXLEN];
7265 afi_t afi = bgp_node_afi(vty);
7266 safi_t safi = bgp_node_safi(vty);
7267
7268 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
7269 yang_afi_safi_value2identity(afi, safi));
7270
7271 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7272 sizeof(base_xpath), af_xpath)
7273 < 0)
7274 return CMD_WARNING_CONFIG_FAILED;
7275
7276 snprintf(attr_xpath, sizeof(attr_xpath), "./%s/weight/weight-attribute",
7277 bgp_afi_safi_get_container_str(afi, safi));
7278
7279 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY,
7280 argv[idx_number]->arg);
7281
7282 return nb_cli_apply_changes(vty, base_xpath);
7283 }
7284
7285 ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
7286 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7287 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7288 "Set default weight for routes from this neighbor\n"
7289 "default weight\n")
7290
7291 DEFUN_YANG (no_neighbor_weight,
7292 no_neighbor_weight_cmd,
7293 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7294 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7295 "Set default weight for routes from this neighbor\n"
7296 "default weight\n")
7297 {
7298 int idx_peer = 2;
7299 char base_xpath[XPATH_MAXLEN];
7300 char af_xpath[XPATH_MAXLEN];
7301 char attr_xpath[XPATH_MAXLEN];
7302 afi_t afi = bgp_node_afi(vty);
7303 safi_t safi = bgp_node_safi(vty);
7304
7305 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
7306 yang_afi_safi_value2identity(afi, safi));
7307
7308 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7309 sizeof(base_xpath), af_xpath)
7310 < 0)
7311 return CMD_WARNING_CONFIG_FAILED;
7312
7313 snprintf(attr_xpath, sizeof(attr_xpath), "./%s/weight/weight-attribute",
7314 bgp_afi_safi_get_container_str(afi, safi));
7315
7316 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_DESTROY, NULL);
7317
7318 return nb_cli_apply_changes(vty, base_xpath);
7319 }
7320
7321 ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
7322 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7323 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7324 "Set default weight for routes from this neighbor\n"
7325 "default weight\n")
7326
7327
7328 /* Override capability negotiation. */
7329 DEFUN_YANG (neighbor_override_capability,
7330 neighbor_override_capability_cmd,
7331 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7332 NEIGHBOR_STR
7333 NEIGHBOR_ADDR_STR2
7334 "Override capability negotiation result\n")
7335 {
7336 int idx_peer = 1;
7337 char base_xpath[XPATH_MAXLEN];
7338
7339 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7340 sizeof(base_xpath), NULL)
7341 < 0)
7342 return CMD_WARNING_CONFIG_FAILED;
7343
7344 nb_cli_enqueue_change(
7345 vty, "./capability-options/override-capability",
7346 NB_OP_MODIFY, "true");
7347
7348 return nb_cli_apply_changes(vty, base_xpath);
7349 }
7350
7351 DEFUN_YANG (no_neighbor_override_capability,
7352 no_neighbor_override_capability_cmd,
7353 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7354 NO_STR
7355 NEIGHBOR_STR
7356 NEIGHBOR_ADDR_STR2
7357 "Override capability negotiation result\n")
7358 {
7359 int idx_peer = 2;
7360 char base_xpath[XPATH_MAXLEN];
7361
7362 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7363 sizeof(base_xpath), NULL)
7364 < 0)
7365 return CMD_WARNING_CONFIG_FAILED;
7366
7367 nb_cli_enqueue_change(
7368 vty, "./capability-options/override-capability",
7369 NB_OP_MODIFY, "false");
7370
7371 return nb_cli_apply_changes(vty, base_xpath);
7372 }
7373
7374 DEFUN_YANG (neighbor_strict_capability,
7375 neighbor_strict_capability_cmd,
7376 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7377 NEIGHBOR_STR
7378 NEIGHBOR_ADDR_STR2
7379 "Strict capability negotiation match\n")
7380 {
7381 int idx_peer = 1;
7382 char base_xpath[XPATH_MAXLEN];
7383
7384 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7385 sizeof(base_xpath), NULL)
7386 < 0)
7387 return CMD_WARNING_CONFIG_FAILED;
7388
7389 nb_cli_enqueue_change(
7390 vty, "./capability-options/strict-capability",
7391 NB_OP_MODIFY, "true");
7392
7393 return nb_cli_apply_changes(vty, base_xpath);
7394 }
7395
7396 DEFUN_YANG (no_neighbor_strict_capability,
7397 no_neighbor_strict_capability_cmd,
7398 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7399 NO_STR
7400 NEIGHBOR_STR
7401 NEIGHBOR_ADDR_STR2
7402 "Strict capability negotiation match\n")
7403 {
7404 int idx_peer = 2;
7405 char base_xpath[XPATH_MAXLEN];
7406
7407 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7408 sizeof(base_xpath), NULL)
7409 < 0)
7410 return CMD_WARNING_CONFIG_FAILED;
7411
7412 nb_cli_enqueue_change(
7413 vty, "./capability-options/strict-capability",
7414 NB_OP_MODIFY, "false");
7415
7416 return nb_cli_apply_changes(vty, base_xpath);
7417 }
7418
7419 DEFUN_YANG (neighbor_timers,
7420 neighbor_timers_cmd,
7421 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
7422 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7423 "BGP per neighbor timers\n"
7424 "Keepalive interval\n"
7425 "Holdtime\n")
7426 {
7427 int idx_peer = 1;
7428 int idx_number = 3;
7429 int idx_number_2 = 4;
7430 char base_xpath[XPATH_MAXLEN];
7431
7432 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7433 sizeof(base_xpath), NULL)
7434 < 0)
7435 return CMD_WARNING_CONFIG_FAILED;
7436
7437 nb_cli_enqueue_change(vty, "./timers/keepalive", NB_OP_MODIFY,
7438 argv[idx_number]->arg);
7439
7440 nb_cli_enqueue_change(vty, "./timers/hold-time", NB_OP_MODIFY,
7441 argv[idx_number_2]->arg);
7442
7443 return nb_cli_apply_changes(vty, base_xpath);
7444 }
7445
7446 DEFUN_YANG (no_neighbor_timers,
7447 no_neighbor_timers_cmd,
7448 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
7449 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7450 "BGP per neighbor timers\n"
7451 "Keepalive interval\n"
7452 "Holdtime\n")
7453 {
7454 int idx_peer = 2;
7455 char base_xpath[XPATH_MAXLEN];
7456
7457 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7458 sizeof(base_xpath), NULL)
7459 < 0)
7460 return CMD_WARNING_CONFIG_FAILED;
7461
7462 nb_cli_enqueue_change(vty, "./timers/hold-time", NB_OP_DESTROY, NULL);
7463
7464 nb_cli_enqueue_change(vty, "./timers/keepalive", NB_OP_DESTROY, NULL);
7465
7466 return nb_cli_apply_changes(vty, base_xpath);
7467 }
7468
7469 DEFUN_YANG (neighbor_timers_connect,
7470 neighbor_timers_connect_cmd,
7471 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
7472 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7473 "BGP per neighbor timers\n"
7474 "BGP connect timer\n"
7475 "Connect timer\n")
7476 {
7477 int idx_peer = 1;
7478 int idx_number = 4;
7479 char base_xpath[XPATH_MAXLEN];
7480
7481 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7482 sizeof(base_xpath), NULL)
7483 < 0)
7484 return CMD_WARNING_CONFIG_FAILED;
7485
7486 nb_cli_enqueue_change(vty, "./timers/connect-time", NB_OP_MODIFY,
7487 argv[idx_number]->arg);
7488
7489 return nb_cli_apply_changes(vty, base_xpath);
7490 }
7491
7492 DEFUN_YANG (no_neighbor_timers_connect,
7493 no_neighbor_timers_connect_cmd,
7494 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
7495 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7496 "BGP per neighbor timers\n"
7497 "BGP connect timer\n"
7498 "Connect timer\n")
7499 {
7500 int idx_peer = 2;
7501 char base_xpath[XPATH_MAXLEN];
7502
7503 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7504 sizeof(base_xpath), NULL)
7505 < 0)
7506 return CMD_WARNING_CONFIG_FAILED;
7507
7508 nb_cli_enqueue_change(vty, "./timers/connect-time", NB_OP_DESTROY,
7509 NULL);
7510
7511 return nb_cli_apply_changes(vty, base_xpath);
7512 }
7513
7514 DEFPY (neighbor_timers_delayopen,
7515 neighbor_timers_delayopen_cmd,
7516 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen (1-240)$interval",
7517 NEIGHBOR_STR
7518 NEIGHBOR_ADDR_STR2
7519 "BGP per neighbor timers\n"
7520 "RFC 4271 DelayOpenTimer\n"
7521 "DelayOpenTime timer interval\n")
7522 {
7523 struct peer *peer;
7524
7525 peer = peer_and_group_lookup_vty(vty, neighbor);
7526 if (!peer)
7527 return CMD_WARNING_CONFIG_FAILED;
7528
7529 if (!interval) {
7530 if (peer_timers_delayopen_unset(peer))
7531 return CMD_WARNING_CONFIG_FAILED;
7532 } else {
7533 if (peer_timers_delayopen_set(peer, interval))
7534 return CMD_WARNING_CONFIG_FAILED;
7535 }
7536
7537 return CMD_SUCCESS;
7538 }
7539
7540 DEFPY (no_neighbor_timers_delayopen,
7541 no_neighbor_timers_delayopen_cmd,
7542 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen [(0-65535)]",
7543 NO_STR
7544 NEIGHBOR_STR
7545 NEIGHBOR_ADDR_STR2
7546 "BGP per neighbor timers\n"
7547 "RFC 4271 DelayOpenTimer\n"
7548 "DelayOpenTime timer interval\n")
7549 {
7550 struct peer *peer;
7551
7552 peer = peer_and_group_lookup_vty(vty, neighbor);
7553 if (!peer)
7554 return CMD_WARNING_CONFIG_FAILED;
7555
7556 if (peer_timers_delayopen_unset(peer))
7557 return CMD_WARNING_CONFIG_FAILED;
7558
7559 return CMD_SUCCESS;
7560 }
7561
7562 DEFUN_YANG (neighbor_advertise_interval,
7563 neighbor_advertise_interval_cmd,
7564 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
7565 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7566 "Minimum interval between sending BGP routing updates\n"
7567 "time in seconds\n")
7568 {
7569 int idx_peer = 1;
7570 int idx_number = 3;
7571 char base_xpath[XPATH_MAXLEN];
7572
7573 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7574 sizeof(base_xpath), NULL)
7575 < 0)
7576 return CMD_WARNING_CONFIG_FAILED;
7577
7578 nb_cli_enqueue_change(vty, "./timers/advertise-interval", NB_OP_MODIFY,
7579 argv[idx_number]->arg);
7580
7581 return nb_cli_apply_changes(vty, base_xpath);
7582 }
7583
7584 DEFUN_YANG (no_neighbor_advertise_interval,
7585 no_neighbor_advertise_interval_cmd,
7586 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
7587 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7588 "Minimum interval between sending BGP routing updates\n"
7589 "time in seconds\n")
7590 {
7591 int idx_peer = 2;
7592 char base_xpath[XPATH_MAXLEN];
7593
7594 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7595 sizeof(base_xpath), NULL)
7596 < 0)
7597 return CMD_WARNING_CONFIG_FAILED;
7598
7599 nb_cli_enqueue_change(vty, "./timers/advertise-interval", NB_OP_DESTROY,
7600 NULL);
7601
7602 return nb_cli_apply_changes(vty, base_xpath);
7603 }
7604
7605
7606 /* Time to wait before processing route-map updates */
7607 DEFUN (bgp_set_route_map_delay_timer,
7608 bgp_set_route_map_delay_timer_cmd,
7609 "bgp route-map delay-timer (0-600)",
7610 SET_STR
7611 "BGP route-map delay timer\n"
7612 "Time in secs to wait before processing route-map changes\n"
7613 "0 disables the timer, no route updates happen when route-maps change\n")
7614 {
7615 int idx_number = 3;
7616 uint32_t rmap_delay_timer;
7617
7618 if (argv[idx_number]->arg) {
7619 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
7620 bm->rmap_update_timer = rmap_delay_timer;
7621
7622 /* if the dynamic update handling is being disabled, and a timer
7623 * is
7624 * running, stop the timer and act as if the timer has already
7625 * fired.
7626 */
7627 if (!rmap_delay_timer && bm->t_rmap_update) {
7628 BGP_TIMER_OFF(bm->t_rmap_update);
7629 thread_execute(bm->master, bgp_route_map_update_timer,
7630 NULL, 0);
7631 }
7632 return CMD_SUCCESS;
7633 } else {
7634 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
7635 return CMD_WARNING_CONFIG_FAILED;
7636 }
7637 }
7638
7639 DEFUN (no_bgp_set_route_map_delay_timer,
7640 no_bgp_set_route_map_delay_timer_cmd,
7641 "no bgp route-map delay-timer [(0-600)]",
7642 NO_STR
7643 BGP_STR
7644 "Default BGP route-map delay timer\n"
7645 "Reset to default time to wait for processing route-map changes\n"
7646 "0 disables the timer, no route updates happen when route-maps change\n")
7647 {
7648
7649 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
7650
7651 return CMD_SUCCESS;
7652 }
7653
7654 DEFUN_YANG (neighbor_interface,
7655 neighbor_interface_cmd,
7656 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
7657 NEIGHBOR_STR NEIGHBOR_ADDR_STR
7658 "Interface\n"
7659 "Interface name\n")
7660 {
7661 int idx_ip = 1;
7662 int idx_word = 3;
7663 char base_xpath[XPATH_MAXLEN];
7664
7665 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_NUM_XPATH,
7666 argv[idx_ip]->arg, "");
7667
7668 nb_cli_enqueue_change(vty, "./local-interface", NB_OP_MODIFY,
7669 argv[idx_word]->arg);
7670
7671 return nb_cli_apply_changes(vty, base_xpath);
7672 }
7673
7674 DEFUN_YANG (no_neighbor_interface,
7675 no_neighbor_interface_cmd,
7676 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
7677 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7678 "Interface\n"
7679 "Interface name\n")
7680 {
7681 int idx_peer = 2;
7682 char base_xpath[XPATH_MAXLEN];
7683
7684 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_NUM_XPATH,
7685 argv[idx_peer]->arg, "");
7686
7687 nb_cli_enqueue_change(vty, "./local-interface", NB_OP_DESTROY, NULL);
7688
7689 return nb_cli_apply_changes(vty, base_xpath);
7690 }
7691
7692 DEFUN (neighbor_distribute_list,
7693 neighbor_distribute_list_cmd,
7694 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
7695 NEIGHBOR_STR
7696 NEIGHBOR_ADDR_STR2
7697 "Filter updates to/from this neighbor\n"
7698 "IP access-list number\n"
7699 "IP access-list number (expanded range)\n"
7700 "IP Access-list name\n"
7701 "Filter incoming updates\n"
7702 "Filter outgoing updates\n")
7703 {
7704 int idx_peer = 1;
7705 int idx_acl = 3;
7706 int direct, ret;
7707 struct peer *peer;
7708
7709 const char *pstr = argv[idx_peer]->arg;
7710 const char *acl = argv[idx_acl]->arg;
7711 const char *inout = argv[argc - 1]->text;
7712
7713 peer = peer_and_group_lookup_vty(vty, pstr);
7714 if (!peer)
7715 return CMD_WARNING_CONFIG_FAILED;
7716
7717 /* Check filter direction. */
7718 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7719 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7720 direct, acl);
7721
7722 return bgp_vty_return(vty, ret);
7723 }
7724
7725 ALIAS_HIDDEN(
7726 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
7727 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
7728 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7729 "Filter updates to/from this neighbor\n"
7730 "IP access-list number\n"
7731 "IP access-list number (expanded range)\n"
7732 "IP Access-list name\n"
7733 "Filter incoming updates\n"
7734 "Filter outgoing updates\n")
7735
7736 DEFUN (no_neighbor_distribute_list,
7737 no_neighbor_distribute_list_cmd,
7738 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
7739 NO_STR
7740 NEIGHBOR_STR
7741 NEIGHBOR_ADDR_STR2
7742 "Filter updates to/from this neighbor\n"
7743 "IP access-list number\n"
7744 "IP access-list number (expanded range)\n"
7745 "IP Access-list name\n"
7746 "Filter incoming updates\n"
7747 "Filter outgoing updates\n")
7748 {
7749 int idx_peer = 2;
7750 int direct, ret;
7751 struct peer *peer;
7752
7753 const char *pstr = argv[idx_peer]->arg;
7754 const char *inout = argv[argc - 1]->text;
7755
7756 peer = peer_and_group_lookup_vty(vty, pstr);
7757 if (!peer)
7758 return CMD_WARNING_CONFIG_FAILED;
7759
7760 /* Check filter direction. */
7761 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7762 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7763 direct);
7764
7765 return bgp_vty_return(vty, ret);
7766 }
7767
7768 ALIAS_HIDDEN(
7769 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
7770 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
7771 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7772 "Filter updates to/from this neighbor\n"
7773 "IP access-list number\n"
7774 "IP access-list number (expanded range)\n"
7775 "IP Access-list name\n"
7776 "Filter incoming updates\n"
7777 "Filter outgoing updates\n")
7778
7779 /* Set prefix list to the peer. */
7780 DEFPY_YANG(
7781 neighbor_prefix_list, neighbor_prefix_list_cmd,
7782 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor_str prefix-list WORD$prefix_str <in|out>$direction",
7783 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7784 "Filter updates to/from this neighbor\n"
7785 "Name of a prefix list\n"
7786 "Filter incoming updates\n"
7787 "Filter outgoing updates\n")
7788 {
7789 char base_xpath[XPATH_MAXLEN];
7790 char af_xpath[XPATH_MAXLEN];
7791 char plist_xpath[XPATH_MAXLEN];
7792 afi_t afi = bgp_node_afi(vty);
7793 safi_t safi = bgp_node_safi(vty);
7794
7795 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
7796 yang_afi_safi_value2identity(afi, safi));
7797 if (peer_and_group_lookup_nb(vty, neighbor_str, base_xpath,
7798 sizeof(base_xpath), af_xpath)
7799 < 0)
7800 return CMD_WARNING_CONFIG_FAILED;
7801
7802 if (strmatch(direction, "in"))
7803 snprintf(plist_xpath, sizeof(plist_xpath),
7804 "./%s/filter-config/plist-import",
7805 bgp_afi_safi_get_container_str(afi, safi));
7806 else if (strmatch(direction, "out"))
7807 snprintf(plist_xpath, sizeof(plist_xpath),
7808 "./%s/filter-config/plist-export",
7809 bgp_afi_safi_get_container_str(afi, safi));
7810
7811 if (!no)
7812 nb_cli_enqueue_change(vty, plist_xpath, NB_OP_MODIFY,
7813 prefix_str);
7814 else
7815 nb_cli_enqueue_change(vty, plist_xpath, NB_OP_DESTROY, NULL);
7816
7817 return nb_cli_apply_changes(vty, base_xpath);
7818 }
7819
7820 ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
7821 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7822 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7823 "Filter updates to/from this neighbor\n"
7824 "Name of a prefix list\n"
7825 "Filter incoming updates\n"
7826 "Filter outgoing updates\n")
7827
7828 static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7829 safi_t safi, const char *name_str,
7830 const char *direct_str)
7831 {
7832 int ret;
7833 struct peer *peer;
7834 int direct = FILTER_IN;
7835
7836 peer = peer_and_group_lookup_vty(vty, ip_str);
7837 if (!peer)
7838 return CMD_WARNING_CONFIG_FAILED;
7839
7840 /* Check filter direction. */
7841 if (strncmp(direct_str, "i", 1) == 0)
7842 direct = FILTER_IN;
7843 else if (strncmp(direct_str, "o", 1) == 0)
7844 direct = FILTER_OUT;
7845
7846 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
7847
7848 return bgp_vty_return(vty, ret);
7849 }
7850
7851 static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7852 safi_t safi, const char *direct_str)
7853 {
7854 int ret;
7855 struct peer *peer;
7856 int direct = FILTER_IN;
7857
7858 peer = peer_and_group_lookup_vty(vty, ip_str);
7859 if (!peer)
7860 return CMD_WARNING_CONFIG_FAILED;
7861
7862 /* Check filter direction. */
7863 if (strncmp(direct_str, "i", 1) == 0)
7864 direct = FILTER_IN;
7865 else if (strncmp(direct_str, "o", 1) == 0)
7866 direct = FILTER_OUT;
7867
7868 ret = peer_aslist_unset(peer, afi, safi, direct);
7869
7870 return bgp_vty_return(vty, ret);
7871 }
7872
7873 DEFUN (neighbor_filter_list,
7874 neighbor_filter_list_cmd,
7875 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
7876 NEIGHBOR_STR
7877 NEIGHBOR_ADDR_STR2
7878 "Establish BGP filters\n"
7879 "AS path access-list name\n"
7880 "Filter incoming routes\n"
7881 "Filter outgoing routes\n")
7882 {
7883 int idx_peer = 1;
7884 int idx_word = 3;
7885 int idx_in_out = 4;
7886 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7887 bgp_node_safi(vty), argv[idx_word]->arg,
7888 argv[idx_in_out]->arg);
7889 }
7890
7891 ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
7892 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
7893 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7894 "Establish BGP filters\n"
7895 "AS path access-list name\n"
7896 "Filter incoming routes\n"
7897 "Filter outgoing routes\n")
7898
7899 DEFUN (no_neighbor_filter_list,
7900 no_neighbor_filter_list_cmd,
7901 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
7902 NO_STR
7903 NEIGHBOR_STR
7904 NEIGHBOR_ADDR_STR2
7905 "Establish BGP filters\n"
7906 "AS path access-list name\n"
7907 "Filter incoming routes\n"
7908 "Filter outgoing routes\n")
7909 {
7910 int idx_peer = 2;
7911 int idx_in_out = 5;
7912 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
7913 bgp_node_afi(vty), bgp_node_safi(vty),
7914 argv[idx_in_out]->arg);
7915 }
7916
7917 ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
7918 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
7919 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7920 "Establish BGP filters\n"
7921 "AS path access-list name\n"
7922 "Filter incoming routes\n"
7923 "Filter outgoing routes\n")
7924
7925 /* Set advertise-map to the peer. */
7926 static int peer_advertise_map_set_vty(struct vty *vty, const char *ip_str,
7927 afi_t afi, safi_t safi,
7928 const char *advertise_str,
7929 const char *condition_str, bool condition,
7930 bool set)
7931 {
7932 int ret = CMD_WARNING_CONFIG_FAILED;
7933 struct peer *peer;
7934 struct route_map *advertise_map;
7935 struct route_map *condition_map;
7936
7937 peer = peer_and_group_lookup_vty(vty, ip_str);
7938 if (!peer)
7939 return ret;
7940
7941 condition_map = route_map_lookup_warn_noexist(vty, condition_str);
7942 advertise_map = route_map_lookup_warn_noexist(vty, advertise_str);
7943
7944 if (set)
7945 ret = peer_advertise_map_set(peer, afi, safi, advertise_str,
7946 advertise_map, condition_str,
7947 condition_map, condition);
7948 else
7949 ret = peer_advertise_map_unset(peer, afi, safi, advertise_str,
7950 advertise_map, condition_str,
7951 condition_map, condition);
7952
7953 return bgp_vty_return(vty, ret);
7954 }
7955
7956 DEFPY (neighbor_advertise_map,
7957 neighbor_advertise_map_cmd,
7958 "[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",
7959 NO_STR
7960 NEIGHBOR_STR
7961 NEIGHBOR_ADDR_STR2
7962 "Route-map to conditionally advertise routes\n"
7963 "Name of advertise map\n"
7964 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7965 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
7966 "Name of the exist or non exist map\n")
7967 {
7968 bool condition = CONDITION_EXIST;
7969
7970 if (!strcmp(exist, "non-exist-map"))
7971 condition = CONDITION_NON_EXIST;
7972
7973 return peer_advertise_map_set_vty(vty, neighbor, bgp_node_afi(vty),
7974 bgp_node_safi(vty), advertise_str,
7975 condition_str, condition, !no);
7976 }
7977
7978 ALIAS_HIDDEN(neighbor_advertise_map, neighbor_advertise_map_hidden_cmd,
7979 "[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",
7980 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7981 "Route-map to conditionally advertise routes\n"
7982 "Name of advertise map\n"
7983 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7984 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
7985 "Name of the exist or non exist map\n")
7986
7987 /* Set route-map to the peer. */
7988 DEFPY_YANG(
7989 neighbor_route_map, neighbor_route_map_cmd,
7990 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor_str route-map WORD$rmap_str <in|out>$direction",
7991 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7992 "Apply route map to neighbor\n"
7993 "Name of route map\n"
7994 "Apply map to incoming routes\n"
7995 "Apply map to outbound routes\n")
7996 {
7997 char base_xpath[XPATH_MAXLEN];
7998 char af_xpath[XPATH_MAXLEN];
7999 char rmap_xpath[XPATH_MAXLEN];
8000 afi_t afi = bgp_node_afi(vty);
8001 safi_t safi = bgp_node_safi(vty);
8002
8003 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8004 yang_afi_safi_value2identity(afi, safi));
8005 if (peer_and_group_lookup_nb(vty, neighbor_str, base_xpath,
8006 sizeof(base_xpath), af_xpath)
8007 < 0)
8008 return CMD_WARNING_CONFIG_FAILED;
8009
8010 if (strmatch(direction, "in"))
8011 snprintf(rmap_xpath, sizeof(rmap_xpath),
8012 "./%s/filter-config/rmap-import",
8013 bgp_afi_safi_get_container_str(afi, safi));
8014 else if (strmatch(direction, "out"))
8015 snprintf(rmap_xpath, sizeof(rmap_xpath),
8016 "./%s/filter-config/rmap-export",
8017 bgp_afi_safi_get_container_str(afi, safi));
8018
8019 if (!no) {
8020 if (!yang_dnode_exists(
8021 vty->candidate_config->dnode,
8022 "/frr-route-map:lib/route-map[name='%s']",
8023 rmap_str)) {
8024 if (vty_shell_serv(vty))
8025 vty_out(vty,
8026 "The route-map '%s' does not exist.\n",
8027 rmap_str);
8028 }
8029 nb_cli_enqueue_change(vty, rmap_xpath, NB_OP_MODIFY, rmap_str);
8030 } else
8031 nb_cli_enqueue_change(vty, rmap_xpath, NB_OP_DESTROY, NULL);
8032
8033 return nb_cli_apply_changes(vty, base_xpath);
8034 }
8035
8036 /* Set unsuppress-map to the peer. */
8037 static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
8038 afi_t afi, safi_t safi,
8039 const char *name_str)
8040 {
8041 int ret;
8042 struct peer *peer;
8043 struct route_map *route_map;
8044
8045 peer = peer_and_group_lookup_vty(vty, ip_str);
8046 if (!peer)
8047 return CMD_WARNING_CONFIG_FAILED;
8048
8049 route_map = route_map_lookup_warn_noexist(vty, name_str);
8050 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
8051
8052 return bgp_vty_return(vty, ret);
8053 }
8054
8055 /* Unset route-map from the peer. */
8056 static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
8057 afi_t afi, safi_t safi)
8058 {
8059 int ret;
8060 struct peer *peer;
8061
8062 peer = peer_and_group_lookup_vty(vty, ip_str);
8063 if (!peer)
8064 return CMD_WARNING_CONFIG_FAILED;
8065
8066 ret = peer_unsuppress_map_unset(peer, afi, safi);
8067
8068 return bgp_vty_return(vty, ret);
8069 }
8070
8071 DEFUN (neighbor_unsuppress_map,
8072 neighbor_unsuppress_map_cmd,
8073 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8074 NEIGHBOR_STR
8075 NEIGHBOR_ADDR_STR2
8076 "Route-map to selectively unsuppress suppressed routes\n"
8077 "Name of route map\n")
8078 {
8079 int idx_peer = 1;
8080 int idx_word = 3;
8081 return peer_unsuppress_map_set_vty(
8082 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8083 argv[idx_word]->arg);
8084 }
8085
8086 ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
8087 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8088 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8089 "Route-map to selectively unsuppress suppressed routes\n"
8090 "Name of route map\n")
8091
8092 DEFUN (no_neighbor_unsuppress_map,
8093 no_neighbor_unsuppress_map_cmd,
8094 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8095 NO_STR
8096 NEIGHBOR_STR
8097 NEIGHBOR_ADDR_STR2
8098 "Route-map to selectively unsuppress suppressed routes\n"
8099 "Name of route map\n")
8100 {
8101 int idx_peer = 2;
8102 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
8103 bgp_node_afi(vty),
8104 bgp_node_safi(vty));
8105 }
8106
8107 ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
8108 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8109 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8110 "Route-map to selectively unsuppress suppressed routes\n"
8111 "Name of route map\n")
8112
8113 /* Maximum number of prefix to be sent to the neighbor. */
8114 DEFUN_YANG(neighbor_maximum_prefix_out,
8115 neighbor_maximum_prefix_out_cmd,
8116 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out (1-4294967295)",
8117 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8118 "Maximum number of prefixes to be sent to this peer\n"
8119 "Maximum no. of prefix limit\n")
8120 {
8121 char base_xpath[XPATH_MAXLEN];
8122 char af_xpath[XPATH_MAXLEN];
8123 char attr_xpath[XPATH_MAXLEN];
8124 int idx_peer = 1;
8125 int idx_number = 3;
8126 afi_t afi = bgp_node_afi(vty);
8127 safi_t safi = bgp_node_safi(vty);
8128
8129 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8130 yang_afi_safi_value2identity(afi, safi));
8131 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8132 sizeof(base_xpath), af_xpath)
8133 < 0)
8134 return CMD_WARNING_CONFIG_FAILED;
8135
8136 snprintf(attr_xpath, sizeof(attr_xpath),
8137 "/%s/prefix-limit/direction-list[direction='out']",
8138 bgp_afi_safi_get_container_str(afi, safi));
8139 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8140
8141 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8142
8143 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8144 argv[idx_number]->arg);
8145
8146 return nb_cli_apply_changes(vty, base_xpath);
8147 }
8148
8149 DEFUN_YANG(no_neighbor_maximum_prefix_out,
8150 no_neighbor_maximum_prefix_out_cmd,
8151 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out",
8152 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8153 "Maximum number of prefixes to be sent to this peer\n")
8154 {
8155 char base_xpath[XPATH_MAXLEN];
8156 char af_xpath[XPATH_MAXLEN];
8157 char attr_xpath[XPATH_MAXLEN];
8158 int idx_peer = 2;
8159 afi_t afi = bgp_node_afi(vty);
8160 safi_t safi = bgp_node_safi(vty);
8161
8162 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8163 yang_afi_safi_value2identity(afi, safi));
8164 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8165 sizeof(base_xpath), af_xpath)
8166 < 0)
8167 return CMD_WARNING_CONFIG_FAILED;
8168
8169 snprintf(attr_xpath, sizeof(attr_xpath),
8170 "/%s/prefix-limit/direction-list[direction='out']",
8171 bgp_afi_safi_get_container_str(afi, safi));
8172 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8173
8174 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
8175
8176 return nb_cli_apply_changes(vty, base_xpath);
8177 }
8178
8179 /* Maximum number of prefix configuration. Prefix count is different
8180 for each peer configuration. So this configuration can be set for
8181 each peer configuration. */
8182 DEFUN_YANG(neighbor_maximum_prefix,
8183 neighbor_maximum_prefix_cmd,
8184 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
8185 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8186 "Maximum number of prefix accept from this peer\n"
8187 "maximum no. of prefix limit\n"
8188 "Force checking all received routes not only accepted\n")
8189 {
8190 int idx_peer = 1;
8191 int idx_number = 3;
8192 int idx_force = 0;
8193 char base_xpath[XPATH_MAXLEN];
8194 char af_xpath[XPATH_MAXLEN];
8195 char attr_xpath[XPATH_MAXLEN];
8196 afi_t afi = bgp_node_afi(vty);
8197 safi_t safi = bgp_node_safi(vty);
8198
8199 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8200 yang_afi_safi_value2identity(afi, safi));
8201 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8202 sizeof(base_xpath), af_xpath)
8203 < 0)
8204 return CMD_WARNING_CONFIG_FAILED;
8205
8206 snprintf(attr_xpath, sizeof(attr_xpath),
8207 "/%s/prefix-limit/direction-list[direction='in']",
8208 bgp_afi_safi_get_container_str(afi, safi));
8209 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8210
8211 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8212
8213 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8214 argv[idx_number]->arg);
8215 if (argv_find(argv, argc, "force", &idx_force))
8216 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8217 "true");
8218
8219 return nb_cli_apply_changes(vty, base_xpath);
8220 }
8221
8222 ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
8223 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
8224 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8225 "Maximum number of prefix accept from this peer\n"
8226 "maximum no. of prefix limit\n"
8227 "Force checking all received routes not only accepted\n")
8228
8229 DEFUN_YANG(neighbor_maximum_prefix_threshold,
8230 neighbor_maximum_prefix_threshold_cmd,
8231 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
8232 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8233 "Maximum number of prefix accept from this peer\n"
8234 "maximum no. of prefix limit\n"
8235 "Threshold value (%) at which to generate a warning msg\n"
8236 "Force checking all received routes not only accepted\n")
8237 {
8238 int idx_peer = 1;
8239 int idx_number = 3;
8240 int idx_number_2 = 4;
8241 int idx_force = 0;
8242 char base_xpath[XPATH_MAXLEN];
8243 char af_xpath[XPATH_MAXLEN];
8244 char attr_xpath[XPATH_MAXLEN];
8245 afi_t afi = bgp_node_afi(vty);
8246 safi_t safi = bgp_node_safi(vty);
8247
8248 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8249 yang_afi_safi_value2identity(afi, safi));
8250 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8251 sizeof(base_xpath), af_xpath)
8252 < 0)
8253 return CMD_WARNING_CONFIG_FAILED;
8254
8255 snprintf(attr_xpath, sizeof(attr_xpath),
8256 "/%s/prefix-limit/direction-list[direction='in']",
8257 bgp_afi_safi_get_container_str(afi, safi));
8258 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8259
8260 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8261
8262 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8263 argv[idx_number]->arg);
8264
8265 nb_cli_enqueue_change(vty, "./options/shutdown-threshold-pct",
8266 NB_OP_MODIFY, argv[idx_number_2]->arg);
8267
8268 if (argv_find(argv, argc, "force", &idx_force))
8269 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8270 "true");
8271
8272 return nb_cli_apply_changes(vty, base_xpath);
8273 }
8274
8275 ALIAS_HIDDEN(
8276 neighbor_maximum_prefix_threshold,
8277 neighbor_maximum_prefix_threshold_hidden_cmd,
8278 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
8279 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8280 "Maximum number of prefix accept from this peer\n"
8281 "maximum no. of prefix limit\n"
8282 "Threshold value (%) at which to generate a warning msg\n"
8283 "Force checking all received routes not only accepted\n")
8284
8285 DEFUN_YANG(neighbor_maximum_prefix_warning,
8286 neighbor_maximum_prefix_warning_cmd,
8287 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
8288 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8289 "Maximum number of prefix accept from this peer\n"
8290 "maximum no. of prefix limit\n"
8291 "Only give warning message when limit is exceeded\n"
8292 "Force checking all received routes not only accepted\n")
8293 {
8294 int idx_peer = 1;
8295 int idx_number = 3;
8296 int idx_force = 0;
8297 char base_xpath[XPATH_MAXLEN];
8298 char af_xpath[XPATH_MAXLEN];
8299 char attr_xpath[XPATH_MAXLEN];
8300 afi_t afi = bgp_node_afi(vty);
8301 safi_t safi = bgp_node_safi(vty);
8302
8303 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8304 yang_afi_safi_value2identity(afi, safi));
8305 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8306 sizeof(base_xpath), af_xpath)
8307 < 0)
8308 return CMD_WARNING_CONFIG_FAILED;
8309
8310 snprintf(attr_xpath, sizeof(attr_xpath),
8311 "/%s/prefix-limit/direction-list[direction='in']",
8312 bgp_afi_safi_get_container_str(afi, safi));
8313 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8314
8315 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8316
8317 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8318 argv[idx_number]->arg);
8319
8320 nb_cli_enqueue_change(vty, "./options/warning-only", NB_OP_MODIFY,
8321 "true");
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_warning,
8331 neighbor_maximum_prefix_warning_hidden_cmd,
8332 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [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 "Only give warning message when limit is exceeded\n"
8337 "Force checking all received routes not only accepted\n")
8338
8339 DEFUN_YANG(neighbor_maximum_prefix_threshold_warning,
8340 neighbor_maximum_prefix_threshold_warning_cmd,
8341 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) 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 "Threshold value (%) at which to generate a warning msg\n"
8346 "Only give warning message when limit is exceeded\n"
8347 "Force checking all received routes not only accepted\n")
8348 {
8349 int idx_peer = 1;
8350 int idx_number = 3;
8351 int idx_number_2 = 4;
8352 int idx_force = 0;
8353 char base_xpath[XPATH_MAXLEN];
8354 char af_xpath[XPATH_MAXLEN];
8355 char attr_xpath[XPATH_MAXLEN];
8356 afi_t afi = bgp_node_afi(vty);
8357 safi_t safi = bgp_node_safi(vty);
8358
8359 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8360 yang_afi_safi_value2identity(afi, safi));
8361 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8362 sizeof(base_xpath), af_xpath)
8363 < 0)
8364 return CMD_WARNING_CONFIG_FAILED;
8365
8366 snprintf(attr_xpath, sizeof(attr_xpath),
8367 "/%s/prefix-limit/direction-list[direction='in']",
8368 bgp_afi_safi_get_container_str(afi, safi));
8369 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8370
8371 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8372
8373 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8374 argv[idx_number]->arg);
8375 nb_cli_enqueue_change(vty, "./options/tw-shutdown-threshold-pct",
8376 NB_OP_MODIFY, argv[idx_number_2]->arg);
8377 nb_cli_enqueue_change(vty, "./options/tw-warning-only", NB_OP_MODIFY,
8378 "true");
8379 if (argv_find(argv, argc, "force", &idx_force))
8380 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8381 "true");
8382
8383 return nb_cli_apply_changes(vty, base_xpath);
8384 }
8385
8386 ALIAS_HIDDEN(
8387 neighbor_maximum_prefix_threshold_warning,
8388 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
8389 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
8390 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8391 "Maximum number of prefix accept from this peer\n"
8392 "maximum no. of prefix limit\n"
8393 "Threshold value (%) at which to generate a warning msg\n"
8394 "Only give warning message when limit is exceeded\n"
8395 "Force checking all received routes not only accepted\n")
8396
8397 DEFUN_YANG(neighbor_maximum_prefix_restart,
8398 neighbor_maximum_prefix_restart_cmd,
8399 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8400 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8401 "Maximum number of prefix accept from this peer\n"
8402 "maximum no. of prefix limit\n"
8403 "Restart bgp connection after limit is exceeded\n"
8404 "Restart interval in minutes\n"
8405 "Force checking all received routes not only accepted\n")
8406 {
8407 int idx_peer = 1;
8408 int idx_number = 3;
8409 int idx_number_2 = 5;
8410 int idx_force = 0;
8411 char base_xpath[XPATH_MAXLEN];
8412 char af_xpath[XPATH_MAXLEN];
8413 char attr_xpath[XPATH_MAXLEN];
8414 afi_t afi = bgp_node_afi(vty);
8415 safi_t safi = bgp_node_safi(vty);
8416
8417 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8418 yang_afi_safi_value2identity(afi, safi));
8419 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8420 sizeof(base_xpath), af_xpath)
8421 < 0)
8422 return CMD_WARNING_CONFIG_FAILED;
8423
8424 snprintf(attr_xpath, sizeof(attr_xpath),
8425 "/%s/prefix-limit/direction-list[direction='in']",
8426 bgp_afi_safi_get_container_str(afi, safi));
8427 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8428
8429 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8430
8431 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8432 argv[idx_number]->arg);
8433 nb_cli_enqueue_change(vty, "./options/restart-timer", NB_OP_MODIFY,
8434 argv[idx_number_2]->arg);
8435 if (argv_find(argv, argc, "force", &idx_force))
8436 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8437 "true");
8438
8439 return nb_cli_apply_changes(vty, base_xpath);
8440 }
8441
8442 ALIAS_HIDDEN(
8443 neighbor_maximum_prefix_restart,
8444 neighbor_maximum_prefix_restart_hidden_cmd,
8445 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8446 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8447 "Maximum number of prefix accept from this peer\n"
8448 "maximum no. of prefix limit\n"
8449 "Restart bgp connection after limit is exceeded\n"
8450 "Restart interval in minutes\n"
8451 "Force checking all received routes not only accepted\n")
8452
8453 DEFUN_YANG(neighbor_maximum_prefix_threshold_restart,
8454 neighbor_maximum_prefix_threshold_restart_cmd,
8455 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8456 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8457 "Maximum number of prefixes to accept from this peer\n"
8458 "maximum no. of prefix limit\n"
8459 "Threshold value (%) at which to generate a warning msg\n"
8460 "Restart bgp connection after limit is exceeded\n"
8461 "Restart interval in minutes\n"
8462 "Force checking all received routes not only accepted\n")
8463 {
8464 int idx_peer = 1;
8465 int idx_number = 3;
8466 int idx_number_2 = 4;
8467 int idx_number_3 = 6;
8468 int idx_force = 0;
8469 char base_xpath[XPATH_MAXLEN];
8470 char af_xpath[XPATH_MAXLEN];
8471 char attr_xpath[XPATH_MAXLEN];
8472 afi_t afi = bgp_node_afi(vty);
8473 safi_t safi = bgp_node_safi(vty);
8474
8475 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8476 yang_afi_safi_value2identity(afi, safi));
8477 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8478 sizeof(base_xpath), af_xpath)
8479 < 0)
8480 return CMD_WARNING_CONFIG_FAILED;
8481
8482 snprintf(attr_xpath, sizeof(attr_xpath),
8483 "/%s/prefix-limit/direction-list[direction='in']",
8484 bgp_afi_safi_get_container_str(afi, safi));
8485 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8486
8487 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8488
8489 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8490 argv[idx_number]->arg);
8491 nb_cli_enqueue_change(vty, "./options/tr-shutdown-threshold-pct",
8492 NB_OP_MODIFY, argv[idx_number_2]->arg);
8493 nb_cli_enqueue_change(vty, "./options/tr-restart-timer", NB_OP_MODIFY,
8494 argv[idx_number_3]->arg);
8495 if (argv_find(argv, argc, "force", &idx_force))
8496 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8497 "true");
8498
8499 return nb_cli_apply_changes(vty, base_xpath);
8500 }
8501
8502 ALIAS_HIDDEN(
8503 neighbor_maximum_prefix_threshold_restart,
8504 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
8505 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8506 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8507 "Maximum number of prefixes to accept from this peer\n"
8508 "maximum no. of prefix limit\n"
8509 "Threshold value (%) at which to generate a warning msg\n"
8510 "Restart bgp connection after limit is exceeded\n"
8511 "Restart interval in minutes\n"
8512 "Force checking all received routes not only accepted\n")
8513
8514 DEFUN_YANG(no_neighbor_maximum_prefix,
8515 no_neighbor_maximum_prefix_cmd,
8516 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8517 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8518 "Maximum number of prefixes to accept from this peer\n"
8519 "maximum no. of prefix limit\n"
8520 "Threshold value (%) at which to generate a warning msg\n"
8521 "Restart bgp connection after limit is exceeded\n"
8522 "Restart interval in minutes\n"
8523 "Only give warning message when limit is exceeded\n"
8524 "Force checking all received routes not only accepted\n")
8525 {
8526 int idx_peer = 2;
8527 char base_xpath[XPATH_MAXLEN];
8528 char af_xpath[XPATH_MAXLEN];
8529 char attr_xpath[XPATH_MAXLEN];
8530 afi_t afi = bgp_node_afi(vty);
8531 safi_t safi = bgp_node_safi(vty);
8532
8533 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8534 yang_afi_safi_value2identity(afi, safi));
8535 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8536 sizeof(base_xpath), af_xpath)
8537 < 0)
8538 return CMD_WARNING_CONFIG_FAILED;
8539
8540 snprintf(attr_xpath, sizeof(attr_xpath),
8541 "/%s/prefix-limit/direction-list[direction='in']",
8542 bgp_afi_safi_get_container_str(afi, safi));
8543 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8544
8545 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
8546
8547 return nb_cli_apply_changes(vty, base_xpath);
8548 }
8549
8550 ALIAS_HIDDEN(
8551 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
8552 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8553 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8554 "Maximum number of prefixes to accept from this peer\n"
8555 "maximum no. of prefix limit\n"
8556 "Threshold value (%) at which to generate a warning msg\n"
8557 "Restart bgp connection after limit is exceeded\n"
8558 "Restart interval in minutes\n"
8559 "Only give warning message when limit is exceeded\n"
8560 "Force checking all received routes not only accepted\n")
8561
8562
8563 /* "neighbor allowas-in" */
8564 DEFUN (neighbor_allowas_in,
8565 neighbor_allowas_in_cmd,
8566 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8567 NEIGHBOR_STR
8568 NEIGHBOR_ADDR_STR2
8569 "Accept as-path with my AS present in it\n"
8570 "Number of occurrences of AS number\n"
8571 "Only accept my AS in the as-path if the route was originated in my AS\n")
8572 {
8573 int idx_peer = 1;
8574 int idx_number_origin = 3;
8575 int ret;
8576 int origin = 0;
8577 struct peer *peer;
8578 int allow_num = 0;
8579
8580 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8581 if (!peer)
8582 return CMD_WARNING_CONFIG_FAILED;
8583
8584 if (argc <= idx_number_origin)
8585 allow_num = 3;
8586 else {
8587 if (argv[idx_number_origin]->type == WORD_TKN)
8588 origin = 1;
8589 else
8590 allow_num = atoi(argv[idx_number_origin]->arg);
8591 }
8592
8593 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8594 allow_num, origin);
8595
8596 return bgp_vty_return(vty, ret);
8597 }
8598
8599 ALIAS_HIDDEN(
8600 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
8601 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8602 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8603 "Accept as-path with my AS present in it\n"
8604 "Number of occurrences of AS number\n"
8605 "Only accept my AS in the as-path if the route was originated in my AS\n")
8606
8607 DEFUN (no_neighbor_allowas_in,
8608 no_neighbor_allowas_in_cmd,
8609 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8610 NO_STR
8611 NEIGHBOR_STR
8612 NEIGHBOR_ADDR_STR2
8613 "allow local ASN appears in aspath attribute\n"
8614 "Number of occurrences of AS number\n"
8615 "Only accept my AS in the as-path if the route was originated in my AS\n")
8616 {
8617 int idx_peer = 2;
8618 int ret;
8619 struct peer *peer;
8620
8621 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8622 if (!peer)
8623 return CMD_WARNING_CONFIG_FAILED;
8624
8625 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
8626 bgp_node_safi(vty));
8627
8628 return bgp_vty_return(vty, ret);
8629 }
8630
8631 ALIAS_HIDDEN(
8632 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
8633 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8634 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8635 "allow local ASN appears in aspath attribute\n"
8636 "Number of occurrences of AS number\n"
8637 "Only accept my AS in the as-path if the route was originated in my AS\n")
8638
8639 DEFUN_YANG (neighbor_ttl_security,
8640 neighbor_ttl_security_cmd,
8641 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8642 NEIGHBOR_STR
8643 NEIGHBOR_ADDR_STR2
8644 "BGP ttl-security parameters\n"
8645 "Specify the maximum number of hops to the BGP peer\n"
8646 "Number of hops to BGP peer\n")
8647 {
8648 int idx_peer = 1;
8649 int idx_number = 4;
8650 char base_xpath[XPATH_MAXLEN];
8651
8652 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8653 sizeof(base_xpath), NULL)
8654 < 0)
8655 return CMD_WARNING_CONFIG_FAILED;
8656
8657 nb_cli_enqueue_change(vty, "./ttl-security", NB_OP_MODIFY,
8658 argv[idx_number]->arg);
8659
8660 return nb_cli_apply_changes(vty, base_xpath);
8661 }
8662
8663 DEFUN_YANG(no_neighbor_ttl_security,
8664 no_neighbor_ttl_security_cmd,
8665 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8666 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8667 "BGP ttl-security parameters\n"
8668 "Specify the maximum number of hops to the BGP peer\n"
8669 "Number of hops to BGP peer\n")
8670 {
8671 int idx_peer = 2;
8672 char base_xpath[XPATH_MAXLEN];
8673
8674 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8675 sizeof(base_xpath), NULL)
8676 < 0)
8677 return CMD_WARNING_CONFIG_FAILED;
8678
8679 nb_cli_enqueue_change(vty, "./ttl-security", NB_OP_DESTROY, NULL);
8680
8681 return nb_cli_apply_changes(vty, base_xpath);
8682 }
8683
8684 DEFUN (neighbor_addpath_tx_all_paths,
8685 neighbor_addpath_tx_all_paths_cmd,
8686 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8687 NEIGHBOR_STR
8688 NEIGHBOR_ADDR_STR2
8689 "Use addpath to advertise all paths to a neighbor\n")
8690 {
8691 int idx_peer = 1;
8692 struct peer *peer;
8693
8694 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8695 if (!peer)
8696 return CMD_WARNING_CONFIG_FAILED;
8697
8698 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8699 BGP_ADDPATH_ALL);
8700 return CMD_SUCCESS;
8701 }
8702
8703 ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
8704 neighbor_addpath_tx_all_paths_hidden_cmd,
8705 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8706 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8707 "Use addpath to advertise all paths to a neighbor\n")
8708
8709 DEFUN (no_neighbor_addpath_tx_all_paths,
8710 no_neighbor_addpath_tx_all_paths_cmd,
8711 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8712 NO_STR
8713 NEIGHBOR_STR
8714 NEIGHBOR_ADDR_STR2
8715 "Use addpath to advertise all paths to a neighbor\n")
8716 {
8717 int idx_peer = 2;
8718 struct peer *peer;
8719
8720 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8721 if (!peer)
8722 return CMD_WARNING_CONFIG_FAILED;
8723
8724 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8725 != BGP_ADDPATH_ALL) {
8726 vty_out(vty,
8727 "%% Peer not currently configured to transmit all paths.");
8728 return CMD_WARNING_CONFIG_FAILED;
8729 }
8730
8731 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8732 BGP_ADDPATH_NONE);
8733
8734 return CMD_SUCCESS;
8735 }
8736
8737 ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
8738 no_neighbor_addpath_tx_all_paths_hidden_cmd,
8739 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8740 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8741 "Use addpath to advertise all paths to a neighbor\n")
8742
8743 DEFUN (neighbor_addpath_tx_bestpath_per_as,
8744 neighbor_addpath_tx_bestpath_per_as_cmd,
8745 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8746 NEIGHBOR_STR
8747 NEIGHBOR_ADDR_STR2
8748 "Use addpath to advertise the bestpath per each neighboring AS\n")
8749 {
8750 int idx_peer = 1;
8751 struct peer *peer;
8752
8753 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8754 if (!peer)
8755 return CMD_WARNING_CONFIG_FAILED;
8756
8757 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8758 BGP_ADDPATH_BEST_PER_AS);
8759
8760 return CMD_SUCCESS;
8761 }
8762
8763 ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
8764 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8765 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8766 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8767 "Use addpath to advertise the bestpath per each neighboring AS\n")
8768
8769 DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
8770 no_neighbor_addpath_tx_bestpath_per_as_cmd,
8771 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8772 NO_STR
8773 NEIGHBOR_STR
8774 NEIGHBOR_ADDR_STR2
8775 "Use addpath to advertise the bestpath per each neighboring AS\n")
8776 {
8777 int idx_peer = 2;
8778 struct peer *peer;
8779
8780 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8781 if (!peer)
8782 return CMD_WARNING_CONFIG_FAILED;
8783
8784 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8785 != BGP_ADDPATH_BEST_PER_AS) {
8786 vty_out(vty,
8787 "%% Peer not currently configured to transmit all best path per as.");
8788 return CMD_WARNING_CONFIG_FAILED;
8789 }
8790
8791 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8792 BGP_ADDPATH_NONE);
8793
8794 return CMD_SUCCESS;
8795 }
8796
8797 ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
8798 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8799 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8800 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8801 "Use addpath to advertise the bestpath per each neighboring AS\n")
8802
8803 DEFPY(
8804 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
8805 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8806 NEIGHBOR_STR
8807 NEIGHBOR_ADDR_STR2
8808 "Detect AS loops before sending to neighbor\n")
8809 {
8810 struct peer *peer;
8811
8812 peer = peer_and_group_lookup_vty(vty, neighbor);
8813 if (!peer)
8814 return CMD_WARNING_CONFIG_FAILED;
8815
8816 peer->as_path_loop_detection = true;
8817
8818 return CMD_SUCCESS;
8819 }
8820
8821 DEFPY(
8822 no_neighbor_aspath_loop_detection,
8823 no_neighbor_aspath_loop_detection_cmd,
8824 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8825 NO_STR
8826 NEIGHBOR_STR
8827 NEIGHBOR_ADDR_STR2
8828 "Detect AS loops before sending to neighbor\n")
8829 {
8830 struct peer *peer;
8831
8832 peer = peer_and_group_lookup_vty(vty, neighbor);
8833 if (!peer)
8834 return CMD_WARNING_CONFIG_FAILED;
8835
8836 peer->as_path_loop_detection = false;
8837
8838 return CMD_SUCCESS;
8839 }
8840
8841 DEFPY(neighbor_damp,
8842 neighbor_damp_cmd,
8843 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor dampening [(1-45)$half [(1-20000)$reuse (1-20000)$suppress (1-255)$max]]",
8844 NEIGHBOR_STR
8845 NEIGHBOR_ADDR_STR2
8846 "Enable neighbor route-flap dampening\n"
8847 "Half-life time for the penalty\n"
8848 "Value to start reusing a route\n"
8849 "Value to start suppressing a route\n"
8850 "Maximum duration to suppress a stable route\n")
8851 {
8852 struct peer *peer = peer_and_group_lookup_vty(vty, neighbor);
8853
8854 if (!peer)
8855 return CMD_WARNING_CONFIG_FAILED;
8856 if (!half)
8857 half = DEFAULT_HALF_LIFE;
8858 if (!reuse) {
8859 reuse = DEFAULT_REUSE;
8860 suppress = DEFAULT_SUPPRESS;
8861 max = half * 4;
8862 }
8863 if (suppress < reuse) {
8864 vty_out(vty,
8865 "Suppress value cannot be less than reuse value\n");
8866 return CMD_WARNING_CONFIG_FAILED;
8867 }
8868 bgp_peer_damp_enable(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8869 half * 60, reuse, suppress, max * 60);
8870 return CMD_SUCCESS;
8871 }
8872
8873 DEFPY(no_neighbor_damp,
8874 no_neighbor_damp_cmd,
8875 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor dampening [HALF [REUSE SUPPRESS MAX]]",
8876 NO_STR
8877 NEIGHBOR_STR
8878 NEIGHBOR_ADDR_STR2
8879 "Enable neighbor route-flap dampening\n"
8880 "Half-life time for the penalty\n"
8881 "Value to start reusing a route\n"
8882 "Value to start suppressing a route\n"
8883 "Maximum duration to suppress a stable route\n")
8884 {
8885 struct peer *peer = peer_and_group_lookup_vty(vty, neighbor);
8886
8887 if (!peer)
8888 return CMD_WARNING_CONFIG_FAILED;
8889 bgp_peer_damp_disable(peer, bgp_node_afi(vty), bgp_node_safi(vty));
8890 return CMD_SUCCESS;
8891 }
8892
8893 DEFPY (show_ip_bgp_neighbor_damp_param,
8894 show_ip_bgp_neighbor_damp_param_cmd,
8895 "show [ip] bgp [<ipv4|ipv6> [unicast]] neighbors <A.B.C.D|X:X::X:X|WORD>$neighbor dampening parameters [json]$json",
8896 SHOW_STR
8897 IP_STR
8898 BGP_STR
8899 BGP_AFI_HELP_STR
8900 "Address Family modifier\n"
8901 NEIGHBOR_STR
8902 NEIGHBOR_ADDR_STR2
8903 "Neighbor route-flap dampening information\n"
8904 "Display detail of configured dampening parameters\n"
8905 JSON_STR)
8906 {
8907 bool use_json = false;
8908 int idx = 0;
8909 afi_t afi = AFI_IP;
8910 safi_t safi = SAFI_UNICAST;
8911 struct peer *peer;
8912
8913 if (argv_find(argv, argc, "ip", &idx))
8914 afi = AFI_IP;
8915 if (argv_find(argv, argc, "ipv4", &idx))
8916 afi = AFI_IP;
8917 if (argv_find(argv, argc, "ipv6", &idx))
8918 afi = AFI_IP6;
8919 peer = peer_and_group_lookup_vty(vty, neighbor);
8920 if (!peer)
8921 return CMD_WARNING;
8922 if (json)
8923 use_json = true;
8924 bgp_show_peer_dampening_parameters(vty, peer, afi, safi, use_json);
8925 return CMD_SUCCESS;
8926 }
8927
8928 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
8929 struct ecommunity **list, bool is_rt6)
8930 {
8931 struct ecommunity *ecom = NULL;
8932 struct ecommunity *ecomadd;
8933
8934 for (; argc; --argc, ++argv) {
8935 if (is_rt6)
8936 ecomadd = ecommunity_str2com_ipv6(argv[0]->arg,
8937 ECOMMUNITY_ROUTE_TARGET,
8938 0);
8939 else
8940 ecomadd = ecommunity_str2com(argv[0]->arg,
8941 ECOMMUNITY_ROUTE_TARGET,
8942 0);
8943 if (!ecomadd) {
8944 vty_out(vty, "Malformed community-list value\n");
8945 if (ecom)
8946 ecommunity_free(&ecom);
8947 return CMD_WARNING_CONFIG_FAILED;
8948 }
8949
8950 if (ecom) {
8951 ecommunity_merge(ecom, ecomadd);
8952 ecommunity_free(&ecomadd);
8953 } else {
8954 ecom = ecomadd;
8955 }
8956 }
8957
8958 if (*list) {
8959 ecommunity_free(&*list);
8960 }
8961 *list = ecom;
8962
8963 return CMD_SUCCESS;
8964 }
8965
8966 bool vpn_policy_check_import(struct bgp *bgp, afi_t afi, safi_t safi,
8967 bool v2vimport, char *errmsg, size_t errmsg_len)
8968 {
8969 if (!v2vimport) {
8970 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8971 BGP_CONFIG_VRF_TO_VRF_IMPORT)
8972 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8973 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
8974 snprintf(
8975 errmsg, errmsg_len, "%s",
8976 "%% error: Please unconfigure import vrf commands before using vpn commands");
8977 return false;
8978 }
8979 } else {
8980 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8981 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
8982 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8983 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
8984 snprintf(
8985 errmsg, errmsg_len, "%s",
8986 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands");
8987 return false;
8988 }
8989 }
8990 return true;
8991 }
8992
8993 /*
8994 * v2vimport is true if we are handling a `import vrf ...` command
8995 */
8996 static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
8997 {
8998 afi_t afi;
8999
9000 switch (vty->node) {
9001 case BGP_IPV4_NODE:
9002 afi = AFI_IP;
9003 break;
9004 case BGP_IPV6_NODE:
9005 afi = AFI_IP6;
9006 break;
9007 default:
9008 vty_out(vty,
9009 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
9010 return AFI_MAX;
9011 }
9012
9013 if (!v2vimport) {
9014 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9015 BGP_CONFIG_VRF_TO_VRF_IMPORT)
9016 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9017 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
9018 vty_out(vty,
9019 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
9020 return AFI_MAX;
9021 }
9022 } else {
9023 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9024 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
9025 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9026 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
9027 vty_out(vty,
9028 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
9029 return AFI_MAX;
9030 }
9031 }
9032 return afi;
9033 }
9034
9035 DEFPY_YANG(
9036 af_rd_vpn_export,
9037 af_rd_vpn_export_cmd,
9038 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
9039 NO_STR
9040 "Specify route distinguisher\n"
9041 "Between current address-family and vpn\n"
9042 "For routes leaked from current address-family to vpn\n"
9043 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
9044 {
9045 char base_xpath[XPATH_MAXLEN];
9046 afi_t afi;
9047 safi_t safi;
9048 int idx = 0;
9049
9050 afi = bgp_node_afi(vty);
9051 safi = bgp_node_safi(vty);
9052
9053 snprintf(
9054 base_xpath, sizeof(base_xpath),
9055 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config",
9056 yang_afi_safi_value2identity(afi, safi),
9057 bgp_afi_safi_get_container_str(afi, safi));
9058
9059 if (argv_find(argv, argc, "no", &idx))
9060 nb_cli_enqueue_change(vty, "./rd", NB_OP_DESTROY, NULL);
9061 else
9062 nb_cli_enqueue_change(vty, "./rd", NB_OP_MODIFY, rd_str);
9063
9064 return nb_cli_apply_changes(vty, base_xpath);
9065 }
9066
9067 void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rd(
9068 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9069 {
9070 int indent = 2;
9071
9072 vty_out(vty, "%*srd vpn export %s\n", indent, "",
9073 yang_dnode_get_string(dnode, NULL));
9074 }
9075
9076 ALIAS (af_rd_vpn_export,
9077 af_no_rd_vpn_export_cmd,
9078 "no rd vpn export",
9079 NO_STR
9080 "Specify route distinguisher\n"
9081 "Between current address-family and vpn\n"
9082 "For routes leaked from current address-family to vpn\n")
9083
9084 DEFPY (af_label_vpn_export,
9085 af_label_vpn_export_cmd,
9086 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
9087 NO_STR
9088 "label value for VRF\n"
9089 "Between current address-family and vpn\n"
9090 "For routes leaked from current address-family to vpn\n"
9091 "Label Value <0-1048575>\n"
9092 "Automatically assign a label\n")
9093 {
9094 VTY_DECLVAR_CONTEXT(bgp, bgp);
9095 mpls_label_t label = MPLS_LABEL_NONE;
9096 afi_t afi;
9097 int idx = 0;
9098 bool yes = true;
9099
9100 if (argv_find(argv, argc, "no", &idx))
9101 yes = false;
9102
9103 /* If "no ...", squash trailing parameter */
9104 if (!yes)
9105 label_auto = NULL;
9106
9107 if (yes) {
9108 if (!label_auto)
9109 label = label_val; /* parser should force unsigned */
9110 }
9111
9112 afi = vpn_policy_getafi(vty, bgp, false);
9113 if (afi == AFI_MAX)
9114 return CMD_WARNING_CONFIG_FAILED;
9115
9116
9117 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9118 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
9119 /* no change */
9120 return CMD_SUCCESS;
9121
9122 /*
9123 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
9124 */
9125 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9126 bgp_get_default(), bgp);
9127
9128 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9129 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
9130
9131 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
9132
9133 /*
9134 * label has previously been automatically
9135 * assigned by labelpool: release it
9136 *
9137 * NB if tovpn_label == MPLS_LABEL_NONE it
9138 * means the automatic assignment is in flight
9139 * and therefore the labelpool callback must
9140 * detect that the auto label is not needed.
9141 */
9142
9143 bgp_lp_release(LP_TYPE_VRF,
9144 &bgp->vpn_policy[afi],
9145 bgp->vpn_policy[afi].tovpn_label);
9146 }
9147 UNSET_FLAG(bgp->vpn_policy[afi].flags,
9148 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
9149 }
9150
9151 bgp->vpn_policy[afi].tovpn_label = label;
9152 if (label_auto) {
9153 SET_FLAG(bgp->vpn_policy[afi].flags,
9154 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
9155 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
9156 vpn_leak_label_callback);
9157 }
9158
9159 /* post-change: re-export vpn routes */
9160 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9161 bgp_get_default(), bgp);
9162
9163 hook_call(bgp_snmp_update_last_changed, bgp);
9164 return CMD_SUCCESS;
9165 }
9166
9167 ALIAS (af_label_vpn_export,
9168 af_no_label_vpn_export_cmd,
9169 "no label vpn export",
9170 NO_STR
9171 "label value for VRF\n"
9172 "Between current address-family and vpn\n"
9173 "For routes leaked from current address-family to vpn\n")
9174
9175 DEFPY_YANG (af_nexthop_vpn_export,
9176 af_nexthop_vpn_export_cmd,
9177 "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
9178 NO_STR
9179 "Specify next hop to use for VRF advertised prefixes\n"
9180 "Between current address-family and vpn\n"
9181 "For routes leaked from current address-family to vpn\n"
9182 "IPv4 prefix\n"
9183 "IPv6 prefix\n")
9184 {
9185 char base_xpath[XPATH_MAXLEN];
9186 afi_t afi;
9187 safi_t safi;
9188 int idx = 0;
9189 struct prefix p;
9190
9191 if (!no) {
9192 if (!nexthop_su) {
9193 vty_out(vty, "%% Nexthop required\n");
9194 return CMD_WARNING_CONFIG_FAILED;
9195 }
9196 if (!sockunion2hostprefix(nexthop_su, &p))
9197 return CMD_WARNING_CONFIG_FAILED;
9198 }
9199
9200 afi = bgp_node_afi(vty);
9201 safi = bgp_node_safi(vty);
9202
9203 snprintf(
9204 base_xpath, sizeof(base_xpath),
9205 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config",
9206 yang_afi_safi_value2identity(afi, safi),
9207 bgp_afi_safi_get_container_str(afi, safi));
9208
9209 if (argv_find(argv, argc, "no", &idx))
9210 nb_cli_enqueue_change(vty, "./nexthop", NB_OP_DESTROY, NULL);
9211 else
9212 nb_cli_enqueue_change(vty, "./nexthop", NB_OP_MODIFY,
9213 nexthop_su_str);
9214
9215 return nb_cli_apply_changes(vty, base_xpath);
9216 }
9217
9218 void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_nexthop(
9219 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9220 {
9221 int indent = 2;
9222
9223 vty_out(vty, "%*snexthop vpn export %s\n", indent, "",
9224 yang_dnode_get_string(dnode, NULL));
9225 }
9226
9227 static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
9228 {
9229 if (!strcmp(dstr, "import")) {
9230 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9231 } else if (!strcmp(dstr, "export")) {
9232 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9233 } else if (!strcmp(dstr, "both")) {
9234 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9235 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9236 } else {
9237 vty_out(vty, "%% direction parse error\n");
9238 return CMD_WARNING_CONFIG_FAILED;
9239 }
9240 return CMD_SUCCESS;
9241 }
9242
9243 DEFPY (af_rt_vpn_imexport,
9244 af_rt_vpn_imexport_cmd,
9245 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
9246 NO_STR
9247 "Specify route target list\n"
9248 "Specify route target list\n"
9249 "Between current address-family and vpn\n"
9250 "For routes leaked from vpn to current address-family: match any\n"
9251 "For routes leaked from current address-family to vpn: set\n"
9252 "both import: match any and export: set\n"
9253 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
9254 {
9255 VTY_DECLVAR_CONTEXT(bgp, bgp);
9256 int ret;
9257 struct ecommunity *ecom = NULL;
9258 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
9259 vpn_policy_direction_t dir;
9260 afi_t afi;
9261 int idx = 0;
9262 bool yes = true;
9263
9264 if (argv_find(argv, argc, "no", &idx))
9265 yes = false;
9266
9267 afi = vpn_policy_getafi(vty, bgp, false);
9268 if (afi == AFI_MAX)
9269 return CMD_WARNING_CONFIG_FAILED;
9270
9271 ret = vpn_policy_getdirs(vty, direction_str, dodir);
9272 if (ret != CMD_SUCCESS)
9273 return ret;
9274
9275 if (yes) {
9276 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9277 vty_out(vty, "%% Missing RTLIST\n");
9278 return CMD_WARNING_CONFIG_FAILED;
9279 }
9280 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, false);
9281 if (ret != CMD_SUCCESS) {
9282 return ret;
9283 }
9284 }
9285
9286 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9287 if (!dodir[dir])
9288 continue;
9289
9290 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9291
9292 if (yes) {
9293 if (bgp->vpn_policy[afi].rtlist[dir])
9294 ecommunity_free(
9295 &bgp->vpn_policy[afi].rtlist[dir]);
9296 bgp->vpn_policy[afi].rtlist[dir] =
9297 ecommunity_dup(ecom);
9298 } else {
9299 if (bgp->vpn_policy[afi].rtlist[dir])
9300 ecommunity_free(
9301 &bgp->vpn_policy[afi].rtlist[dir]);
9302 bgp->vpn_policy[afi].rtlist[dir] = NULL;
9303 }
9304
9305 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9306 }
9307
9308 if (ecom)
9309 ecommunity_free(&ecom);
9310
9311 return CMD_SUCCESS;
9312 }
9313
9314 ALIAS (af_rt_vpn_imexport,
9315 af_no_rt_vpn_imexport_cmd,
9316 "no <rt|route-target> vpn <import|export|both>$direction_str",
9317 NO_STR
9318 "Specify route target list\n"
9319 "Specify route target list\n"
9320 "Between current address-family and vpn\n"
9321 "For routes leaked from vpn to current address-family\n"
9322 "For routes leaked from current address-family to vpn\n"
9323 "both import and export\n")
9324
9325 DEFPY_YANG (af_route_map_vpn_imexport,
9326 af_route_map_vpn_imexport_cmd,
9327 /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
9328 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
9329 NO_STR
9330 "Specify route map\n"
9331 "Between current address-family and vpn\n"
9332 "For routes leaked from vpn to current address-family\n"
9333 "For routes leaked from current address-family to vpn\n"
9334 "name of route-map\n")
9335 {
9336 char base_xpath[XPATH_MAXLEN];
9337 afi_t afi;
9338 safi_t safi;
9339 int idx = 0;
9340
9341 afi = bgp_node_afi(vty);
9342 safi = bgp_node_safi(vty);
9343
9344 snprintf(
9345 base_xpath, sizeof(base_xpath),
9346 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config",
9347 yang_afi_safi_value2identity(afi, safi),
9348 bgp_afi_safi_get_container_str(afi, safi));
9349
9350 if (argv_find(argv, argc, "no", &idx)) {
9351 if (!strcmp(direction_str, "import"))
9352 nb_cli_enqueue_change(vty, "./rmap-import",
9353 NB_OP_DESTROY, NULL);
9354 else if (!strcmp(direction_str, "export"))
9355 nb_cli_enqueue_change(vty, "./rmap-export",
9356 NB_OP_DESTROY, NULL);
9357 } else {
9358 if (!strcmp(direction_str, "import"))
9359 nb_cli_enqueue_change(vty, "./rmap-import",
9360 NB_OP_MODIFY, rmap_str);
9361 if (!strcmp(direction_str, "export"))
9362 nb_cli_enqueue_change(vty, "./rmap-export",
9363 NB_OP_MODIFY, rmap_str);
9364 }
9365 return nb_cli_apply_changes(vty, base_xpath);
9366 }
9367
9368 void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rmap_import(
9369 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9370 {
9371 int indent = 2;
9372
9373 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
9374 yang_dnode_get_string(dnode, NULL));
9375 }
9376
9377 void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rmap_export(
9378 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9379 {
9380 int indent = 2;
9381
9382 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
9383 yang_dnode_get_string(dnode, NULL));
9384 }
9385
9386 ALIAS (af_route_map_vpn_imexport,
9387 af_no_route_map_vpn_imexport_cmd,
9388 "no route-map vpn <import|export>$direction_str",
9389 NO_STR
9390 "Specify route map\n"
9391 "Between current address-family and vpn\n"
9392 "For routes leaked from vpn to current address-family\n"
9393 "For routes leaked from current address-family to vpn\n")
9394
9395 DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
9396 "import vrf route-map RMAP$rmap_str",
9397 "Import routes from another VRF\n"
9398 "Vrf routes being filtered\n"
9399 "Specify route map\n"
9400 "name of route-map\n")
9401 {
9402 VTY_DECLVAR_CONTEXT(bgp, bgp);
9403 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
9404 afi_t afi;
9405 struct bgp *bgp_default;
9406
9407 afi = vpn_policy_getafi(vty, bgp, true);
9408 if (afi == AFI_MAX)
9409 return CMD_WARNING_CONFIG_FAILED;
9410
9411 bgp_default = bgp_get_default();
9412 if (!bgp_default) {
9413 int32_t ret;
9414 as_t as = bgp->as;
9415
9416 /* Auto-create assuming the same AS */
9417 ret = bgp_get_vty(&bgp_default, &as, NULL,
9418 BGP_INSTANCE_TYPE_DEFAULT);
9419
9420 if (ret) {
9421 vty_out(vty,
9422 "VRF default is not configured as a bgp instance\n");
9423 return CMD_WARNING;
9424 }
9425 }
9426
9427 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9428
9429 if (bgp->vpn_policy[afi].rmap_name[dir])
9430 XFREE(MTYPE_ROUTE_MAP_NAME,
9431 bgp->vpn_policy[afi].rmap_name[dir]);
9432 bgp->vpn_policy[afi].rmap_name[dir] =
9433 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
9434 bgp->vpn_policy[afi].rmap[dir] =
9435 route_map_lookup_warn_noexist(vty, rmap_str);
9436 if (!bgp->vpn_policy[afi].rmap[dir])
9437 return CMD_SUCCESS;
9438
9439 SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9440 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9441
9442 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9443
9444 return CMD_SUCCESS;
9445 }
9446
9447 DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
9448 "no import vrf route-map [RMAP$rmap_str]",
9449 NO_STR
9450 "Import routes from another VRF\n"
9451 "Vrf routes being filtered\n"
9452 "Specify route map\n"
9453 "name of route-map\n")
9454 {
9455 VTY_DECLVAR_CONTEXT(bgp, bgp);
9456 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
9457 afi_t afi;
9458
9459 afi = vpn_policy_getafi(vty, bgp, true);
9460 if (afi == AFI_MAX)
9461 return CMD_WARNING_CONFIG_FAILED;
9462
9463 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9464
9465 if (bgp->vpn_policy[afi].rmap_name[dir])
9466 XFREE(MTYPE_ROUTE_MAP_NAME,
9467 bgp->vpn_policy[afi].rmap_name[dir]);
9468 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9469 bgp->vpn_policy[afi].rmap[dir] = NULL;
9470
9471 if (bgp->vpn_policy[afi].import_vrf->count == 0)
9472 UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9473 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9474
9475 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9476
9477 return CMD_SUCCESS;
9478 }
9479
9480 DEFPY_YANG(bgp_imexport_vrf,
9481 bgp_imexport_vrf_cmd,
9482 "[no] import vrf VIEWVRFNAME$import_name",
9483 NO_STR
9484 "Import routes from another VRF\n"
9485 "VRF to import from\n"
9486 "The name of the VRF\n")
9487 {
9488 char base_xpath[XPATH_MAXLEN];
9489 safi_t safi;
9490 afi_t afi;
9491 int32_t idx = 0;
9492
9493 if (import_name == NULL) {
9494 vty_out(vty, "%% Missing import name\n");
9495 return CMD_WARNING;
9496 }
9497
9498 if (strcmp(import_name, "route-map") == 0) {
9499 vty_out(vty, "%% Must include route-map name\n");
9500 return CMD_WARNING;
9501 }
9502
9503 afi = bgp_node_afi(vty);
9504 safi = bgp_node_safi(vty);
9505
9506 snprintf(
9507 base_xpath, sizeof(base_xpath),
9508 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config/import-vrf-list[vrf='%s']",
9509 yang_afi_safi_value2identity(afi, safi),
9510 bgp_afi_safi_get_container_str(afi, safi), import_name);
9511
9512 if (argv_find(argv, argc, "no", &idx))
9513 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
9514 else
9515 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
9516
9517 return nb_cli_apply_changes(vty, base_xpath);
9518 }
9519
9520 void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_import_vrfs(
9521 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9522 {
9523 vty_out(vty, " import vrf %s\n",
9524 yang_dnode_get_string(dnode, "./vrf"));
9525 }
9526
9527 /* This command is valid only in a bgp vrf instance or the default instance */
9528 DEFPY_YANG (bgp_imexport_vpn,
9529 bgp_imexport_vpn_cmd,
9530 "[no] <import|export>$direction_str vpn",
9531 NO_STR
9532 "Import routes to this address-family\n"
9533 "Export routes from this address-family\n"
9534 "to/from default instance VPN RIB\n")
9535 {
9536 char base_xpath[XPATH_MAXLEN];
9537 safi_t safi;
9538 afi_t afi;
9539 int32_t idx = 0;
9540
9541 afi = bgp_node_afi(vty);
9542 safi = bgp_node_safi(vty);
9543
9544 if (!strcmp(direction_str, "import")) {
9545 snprintf(
9546 base_xpath, sizeof(base_xpath),
9547 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config/import-vpn",
9548 yang_afi_safi_value2identity(afi, safi),
9549 bgp_afi_safi_get_container_str(afi, safi));
9550 } else if (!strcmp(direction_str, "export")) {
9551 snprintf(
9552 base_xpath, sizeof(base_xpath),
9553 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config/export-vpn",
9554 yang_afi_safi_value2identity(afi, safi),
9555 bgp_afi_safi_get_container_str(afi, safi));
9556 } else {
9557 vty_out(vty, "%% unknown direction %s\n", direction_str);
9558 return CMD_WARNING_CONFIG_FAILED;
9559 }
9560
9561 if (argv_find(argv, argc, "no", &idx))
9562 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
9563 else
9564 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, "true");
9565
9566 return nb_cli_apply_changes(vty, base_xpath);
9567 }
9568
9569 void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_import_vpn(
9570 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9571 {
9572 if (yang_dnode_get_bool(dnode, NULL))
9573 vty_out(vty, " import vpn\n");
9574 }
9575
9576 void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_export_vpn(
9577 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9578 {
9579 if (yang_dnode_get_bool(dnode, NULL))
9580 vty_out(vty, " export vpn\n");
9581 }
9582
9583 DEFPY (af_routetarget_import,
9584 af_routetarget_import_cmd,
9585 "[no] <rt|route-target|route-target6|rt6> redirect import RTLIST...",
9586 NO_STR
9587 "Specify route target list\n"
9588 "Specify route target list\n"
9589 "Specify route target list\n"
9590 "Specify route target list\n"
9591 "Flow-spec redirect type route target\n"
9592 "Import routes to this address-family\n"
9593 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN|IPV6:MN)\n")
9594 {
9595 VTY_DECLVAR_CONTEXT(bgp, bgp);
9596 int ret;
9597 struct ecommunity *ecom = NULL;
9598 afi_t afi;
9599 int idx = 0, idx_unused = 0;
9600 bool yes = true;
9601 bool rt6 = false;
9602
9603 if (argv_find(argv, argc, "no", &idx))
9604 yes = false;
9605
9606 if (argv_find(argv, argc, "rt6", &idx_unused) ||
9607 argv_find(argv, argc, "route-target6", &idx_unused))
9608 rt6 = true;
9609
9610 afi = vpn_policy_getafi(vty, bgp, false);
9611 if (afi == AFI_MAX)
9612 return CMD_WARNING_CONFIG_FAILED;
9613
9614 if (rt6 && afi != AFI_IP6)
9615 return CMD_WARNING_CONFIG_FAILED;
9616
9617 if (yes) {
9618 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9619 vty_out(vty, "%% Missing RTLIST\n");
9620 return CMD_WARNING_CONFIG_FAILED;
9621 }
9622 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, rt6);
9623 if (ret != CMD_SUCCESS)
9624 return ret;
9625 }
9626
9627 if (yes) {
9628 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9629 ecommunity_free(&bgp->vpn_policy[afi]
9630 .import_redirect_rtlist);
9631 bgp->vpn_policy[afi].import_redirect_rtlist =
9632 ecommunity_dup(ecom);
9633 } else {
9634 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9635 ecommunity_free(&bgp->vpn_policy[afi]
9636 .import_redirect_rtlist);
9637 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
9638 }
9639
9640 if (ecom)
9641 ecommunity_free(&ecom);
9642
9643 return CMD_SUCCESS;
9644 }
9645
9646 void cli_show_bgp_global_afi_safi_header(struct vty *vty,
9647 struct lyd_node *dnode,
9648 bool show_defaults)
9649 {
9650 const char *af_name;
9651 afi_t afi;
9652 safi_t safi;
9653
9654 af_name = yang_dnode_get_string(dnode, "./afi-safi-name");
9655 yang_afi_safi_identity2value(af_name, &afi, &safi);
9656
9657 vty_out(vty, " !\n address-family ");
9658 if (afi == AFI_IP) {
9659 if (safi == SAFI_UNICAST)
9660 vty_out(vty, "ipv4 unicast");
9661 else if (safi == SAFI_LABELED_UNICAST)
9662 vty_out(vty, "ipv4 labeled-unicast");
9663 else if (safi == SAFI_MULTICAST)
9664 vty_out(vty, "ipv4 multicast");
9665 else if (safi == SAFI_MPLS_VPN)
9666 vty_out(vty, "ipv4 vpn");
9667 else if (safi == SAFI_ENCAP)
9668 vty_out(vty, "ipv4 encap");
9669 else if (safi == SAFI_FLOWSPEC)
9670 vty_out(vty, "ipv4 flowspec");
9671 } else if (afi == AFI_IP6) {
9672 if (safi == SAFI_UNICAST)
9673 vty_out(vty, "ipv6 unicast");
9674 else if (safi == SAFI_LABELED_UNICAST)
9675 vty_out(vty, "ipv6 labeled-unicast");
9676 else if (safi == SAFI_MULTICAST)
9677 vty_out(vty, "ipv6 multicast");
9678 else if (safi == SAFI_MPLS_VPN)
9679 vty_out(vty, "ipv6 vpn");
9680 else if (safi == SAFI_ENCAP)
9681 vty_out(vty, "ipv6 encap");
9682 else if (safi == SAFI_FLOWSPEC)
9683 vty_out(vty, "ipv6 flowspec");
9684 } else if (afi == AFI_L2VPN) {
9685 if (safi == SAFI_EVPN)
9686 vty_out(vty, "l2vpn evpn");
9687 }
9688 vty_out(vty, "\n");
9689 }
9690
9691 DEFUN_NOSH (address_family_ipv4_safi,
9692 address_family_ipv4_safi_cmd,
9693 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9694 "Enter Address Family command mode\n"
9695 "Address Family\n"
9696 BGP_SAFI_WITH_LABEL_HELP_STR)
9697 {
9698
9699 safi_t safi = SAFI_UNICAST;
9700 const struct lyd_node *vrf_dnode, *bgp_glb_dnode;
9701 const char *vrf_name = NULL;
9702
9703 if (argc == 3) {
9704 safi = bgp_vty_safi_from_str(argv[2]->text);
9705
9706 bgp_glb_dnode = yang_dnode_get(vty->candidate_config->dnode,
9707 VTY_CURR_XPATH);
9708 vrf_dnode = yang_dnode_get_parent(bgp_glb_dnode,
9709 "control-plane-protocol");
9710 vrf_name = yang_dnode_get_string(vrf_dnode, "./vrf");
9711
9712 if (!strmatch(vrf_name, VRF_DEFAULT_NAME)
9713 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9714 && safi != SAFI_EVPN) {
9715 vty_out(vty,
9716 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9717 return CMD_WARNING_CONFIG_FAILED;
9718 }
9719 }
9720 vty->node = bgp_node_type(AFI_IP, safi);
9721
9722 return CMD_SUCCESS;
9723 }
9724
9725 DEFUN_NOSH (address_family_ipv6_safi,
9726 address_family_ipv6_safi_cmd,
9727 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9728 "Enter Address Family command mode\n"
9729 "Address Family\n"
9730 BGP_SAFI_WITH_LABEL_HELP_STR)
9731 {
9732 safi_t safi = SAFI_UNICAST;
9733 const struct lyd_node *vrf_dnode, *bgp_glb_dnode;
9734 const char *vrf_name = NULL;
9735
9736 if (argc == 3) {
9737 safi = bgp_vty_safi_from_str(argv[2]->text);
9738 bgp_glb_dnode = yang_dnode_get(vty->candidate_config->dnode,
9739 VTY_CURR_XPATH);
9740 vrf_dnode = yang_dnode_get_parent(bgp_glb_dnode,
9741 "control-plane-protocol");
9742 vrf_name = yang_dnode_get_string(vrf_dnode, "./vrf");
9743
9744 if (!strmatch(vrf_name, VRF_DEFAULT_NAME)
9745 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9746 && safi != SAFI_EVPN) {
9747 vty_out(vty,
9748 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9749 return CMD_WARNING_CONFIG_FAILED;
9750 }
9751 }
9752 vty->node = bgp_node_type(AFI_IP6, safi);
9753
9754 return CMD_SUCCESS;
9755 }
9756
9757 #ifdef KEEP_OLD_VPN_COMMANDS
9758 DEFUN_NOSH (address_family_vpnv4,
9759 address_family_vpnv4_cmd,
9760 "address-family vpnv4 [unicast]",
9761 "Enter Address Family command mode\n"
9762 "Address Family\n"
9763 "Address Family modifier\n")
9764 {
9765 vty->node = BGP_VPNV4_NODE;
9766 return CMD_SUCCESS;
9767 }
9768
9769 DEFUN_NOSH (address_family_vpnv6,
9770 address_family_vpnv6_cmd,
9771 "address-family vpnv6 [unicast]",
9772 "Enter Address Family command mode\n"
9773 "Address Family\n"
9774 "Address Family modifier\n")
9775 {
9776 vty->node = BGP_VPNV6_NODE;
9777 return CMD_SUCCESS;
9778 }
9779 #endif /* KEEP_OLD_VPN_COMMANDS */
9780
9781 DEFUN_NOSH (address_family_evpn,
9782 address_family_evpn_cmd,
9783 "address-family l2vpn evpn",
9784 "Enter Address Family command mode\n"
9785 "Address Family\n"
9786 "Address Family modifier\n")
9787 {
9788 VTY_DECLVAR_CONTEXT(bgp, bgp);
9789 vty->node = BGP_EVPN_NODE;
9790 return CMD_SUCCESS;
9791 }
9792
9793 DEFUN_NOSH (exit_address_family,
9794 exit_address_family_cmd,
9795 "exit-address-family",
9796 "Exit from Address Family configuration mode\n")
9797 {
9798 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
9799 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
9800 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
9801 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
9802 || vty->node == BGP_EVPN_NODE
9803 || vty->node == BGP_FLOWSPECV4_NODE
9804 || vty->node == BGP_FLOWSPECV6_NODE)
9805 vty->node = BGP_NODE;
9806 return CMD_SUCCESS;
9807 }
9808
9809 void cli_show_bgp_global_afi_safi_header_end(struct vty *vty,
9810 struct lyd_node *dnode
9811 __attribute__((__unused__)))
9812 {
9813 vty_out(vty, " exit-address-family\n");
9814 }
9815
9816 /* Recalculate bestpath and re-advertise a prefix */
9817 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
9818 const char *ip_str, afi_t afi, safi_t safi,
9819 struct prefix_rd *prd)
9820 {
9821 int ret;
9822 struct prefix match;
9823 struct bgp_dest *dest;
9824 struct bgp_dest *rm;
9825 struct bgp *bgp;
9826 struct bgp_table *table;
9827 struct bgp_table *rib;
9828
9829 /* BGP structure lookup. */
9830 if (view_name) {
9831 bgp = bgp_lookup_by_name(view_name);
9832 if (bgp == NULL) {
9833 vty_out(vty, "%% Can't find BGP instance %s\n",
9834 view_name);
9835 return CMD_WARNING;
9836 }
9837 } else {
9838 bgp = bgp_get_default();
9839 if (bgp == NULL) {
9840 vty_out(vty, "%% No BGP process is configured\n");
9841 return CMD_WARNING;
9842 }
9843 }
9844
9845 /* Check IP address argument. */
9846 ret = str2prefix(ip_str, &match);
9847 if (!ret) {
9848 vty_out(vty, "%% address is malformed\n");
9849 return CMD_WARNING;
9850 }
9851
9852 match.family = afi2family(afi);
9853 rib = bgp->rib[afi][safi];
9854
9855 if (safi == SAFI_MPLS_VPN) {
9856 for (dest = bgp_table_top(rib); dest;
9857 dest = bgp_route_next(dest)) {
9858 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
9859
9860 if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
9861 continue;
9862
9863 table = bgp_dest_get_bgp_table_info(dest);
9864 if (table == NULL)
9865 continue;
9866
9867 if ((rm = bgp_node_match(table, &match)) != NULL) {
9868 const struct prefix *rm_p =
9869 bgp_dest_get_prefix(rm);
9870
9871 if (rm_p->prefixlen == match.prefixlen) {
9872 SET_FLAG(rm->flags,
9873 BGP_NODE_USER_CLEAR);
9874 bgp_process(bgp, rm, afi, safi);
9875 }
9876 bgp_dest_unlock_node(rm);
9877 }
9878 }
9879 } else {
9880 if ((dest = bgp_node_match(rib, &match)) != NULL) {
9881 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
9882
9883 if (dest_p->prefixlen == match.prefixlen) {
9884 SET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
9885 bgp_process(bgp, dest, afi, safi);
9886 }
9887 bgp_dest_unlock_node(dest);
9888 }
9889 }
9890
9891 return CMD_SUCCESS;
9892 }
9893
9894 /* one clear bgp command to rule them all */
9895 DEFUN (clear_ip_bgp_all,
9896 clear_ip_bgp_all_cmd,
9897 "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>]",
9898 CLEAR_STR
9899 IP_STR
9900 BGP_STR
9901 BGP_INSTANCE_HELP_STR
9902 BGP_AFI_HELP_STR
9903 "Address Family\n"
9904 BGP_SAFI_WITH_LABEL_HELP_STR
9905 "Address Family modifier\n"
9906 "Clear all peers\n"
9907 "BGP IPv4 neighbor to clear\n"
9908 "BGP IPv6 neighbor to clear\n"
9909 "BGP neighbor on interface to clear\n"
9910 "Clear peers with the AS number\n"
9911 "Clear all external peers\n"
9912 "Clear all members of peer-group\n"
9913 "BGP peer-group name\n"
9914 BGP_SOFT_STR
9915 BGP_SOFT_IN_STR
9916 BGP_SOFT_OUT_STR
9917 BGP_SOFT_IN_STR
9918 "Push out prefix-list ORF and do inbound soft reconfig\n"
9919 BGP_SOFT_OUT_STR)
9920 {
9921 char *vrf = NULL;
9922
9923 afi_t afi = AFI_UNSPEC;
9924 safi_t safi = SAFI_UNSPEC;
9925 enum clear_sort clr_sort = clear_peer;
9926 enum bgp_clear_type clr_type;
9927 char *clr_arg = NULL;
9928
9929 int idx = 0;
9930 char errmsg[BUFSIZ] = {'\0'};
9931 int ret;
9932
9933 /* clear [ip] bgp */
9934 if (argv_find(argv, argc, "ip", &idx))
9935 afi = AFI_IP;
9936
9937 /* [<vrf> VIEWVRFNAME] */
9938 if (argv_find(argv, argc, "vrf", &idx)) {
9939 vrf = argv[idx + 1]->arg;
9940 idx += 2;
9941 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9942 vrf = NULL;
9943 } else if (argv_find(argv, argc, "view", &idx)) {
9944 /* [<view> VIEWVRFNAME] */
9945 vrf = argv[idx + 1]->arg;
9946 idx += 2;
9947 }
9948 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
9949 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
9950 argv_find_and_parse_safi(argv, argc, &idx, &safi);
9951
9952 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
9953 if (argv_find(argv, argc, "*", &idx)) {
9954 clr_sort = clear_all;
9955 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
9956 clr_sort = clear_peer;
9957 clr_arg = argv[idx]->arg;
9958 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
9959 clr_sort = clear_peer;
9960 clr_arg = argv[idx]->arg;
9961 } else if (argv_find(argv, argc, "peer-group", &idx)) {
9962 clr_sort = clear_group;
9963 idx++;
9964 clr_arg = argv[idx]->arg;
9965 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
9966 clr_sort = clear_peer;
9967 clr_arg = argv[idx]->arg;
9968 } else if (argv_find(argv, argc, "WORD", &idx)) {
9969 clr_sort = clear_peer;
9970 clr_arg = argv[idx]->arg;
9971 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
9972 clr_sort = clear_as;
9973 clr_arg = argv[idx]->arg;
9974 } else if (argv_find(argv, argc, "external", &idx)) {
9975 clr_sort = clear_external;
9976 }
9977
9978 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
9979 if (argv_find(argv, argc, "soft", &idx)) {
9980 if (argv_find(argv, argc, "in", &idx)
9981 || argv_find(argv, argc, "out", &idx))
9982 clr_type = strmatch(argv[idx]->text, "in")
9983 ? BGP_CLEAR_SOFT_IN
9984 : BGP_CLEAR_SOFT_OUT;
9985 else
9986 clr_type = BGP_CLEAR_SOFT_BOTH;
9987 } else if (argv_find(argv, argc, "in", &idx)) {
9988 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
9989 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
9990 : BGP_CLEAR_SOFT_IN;
9991 } else if (argv_find(argv, argc, "out", &idx)) {
9992 clr_type = BGP_CLEAR_SOFT_OUT;
9993 } else
9994 clr_type = BGP_CLEAR_SOFT_NONE;
9995
9996 ret = bgp_clear_vty(vrf, afi, safi, clr_sort, clr_type, clr_arg, errmsg,
9997 sizeof(errmsg));
9998 if (ret != NB_OK)
9999 vty_out(vty, "Error description: %s\n", errmsg);
10000
10001 return ret;
10002 }
10003
10004 DEFUN (clear_ip_bgp_prefix,
10005 clear_ip_bgp_prefix_cmd,
10006 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
10007 CLEAR_STR
10008 IP_STR
10009 BGP_STR
10010 BGP_INSTANCE_HELP_STR
10011 "Clear bestpath and re-advertise\n"
10012 "IPv4 prefix\n")
10013 {
10014 char *vrf = NULL;
10015 char *prefix = NULL;
10016
10017 int idx = 0;
10018
10019 /* [<view|vrf> VIEWVRFNAME] */
10020 if (argv_find(argv, argc, "vrf", &idx)) {
10021 vrf = argv[idx + 1]->arg;
10022 idx += 2;
10023 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
10024 vrf = NULL;
10025 } else if (argv_find(argv, argc, "view", &idx)) {
10026 /* [<view> VIEWVRFNAME] */
10027 vrf = argv[idx + 1]->arg;
10028 idx += 2;
10029 }
10030
10031 prefix = argv[argc - 1]->arg;
10032
10033 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
10034 }
10035
10036 DEFUN (clear_bgp_ipv6_safi_prefix,
10037 clear_bgp_ipv6_safi_prefix_cmd,
10038 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
10039 CLEAR_STR
10040 IP_STR
10041 BGP_STR
10042 "Address Family\n"
10043 BGP_SAFI_HELP_STR
10044 "Clear bestpath and re-advertise\n"
10045 "IPv6 prefix\n")
10046 {
10047 int idx_safi = 0;
10048 int idx_ipv6_prefix = 0;
10049 safi_t safi = SAFI_UNICAST;
10050 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
10051 argv[idx_ipv6_prefix]->arg : NULL;
10052
10053 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
10054 return bgp_clear_prefix(
10055 vty, NULL, prefix, AFI_IP6,
10056 safi, NULL);
10057 }
10058
10059 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
10060 clear_bgp_instance_ipv6_safi_prefix_cmd,
10061 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
10062 CLEAR_STR
10063 IP_STR
10064 BGP_STR
10065 BGP_INSTANCE_HELP_STR
10066 "Address Family\n"
10067 BGP_SAFI_HELP_STR
10068 "Clear bestpath and re-advertise\n"
10069 "IPv6 prefix\n")
10070 {
10071 int idx_safi = 0;
10072 int idx_vrfview = 0;
10073 int idx_ipv6_prefix = 0;
10074 safi_t safi = SAFI_UNICAST;
10075 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
10076 argv[idx_ipv6_prefix]->arg : NULL;
10077 char *vrfview = NULL;
10078
10079 /* [<view|vrf> VIEWVRFNAME] */
10080 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
10081 vrfview = argv[idx_vrfview + 1]->arg;
10082 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
10083 vrfview = NULL;
10084 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
10085 /* [<view> VIEWVRFNAME] */
10086 vrfview = argv[idx_vrfview + 1]->arg;
10087 }
10088 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
10089
10090 return bgp_clear_prefix(
10091 vty, vrfview, prefix,
10092 AFI_IP6, safi, NULL);
10093 }
10094
10095 DEFUN (show_bgp_views,
10096 show_bgp_views_cmd,
10097 "show [ip] bgp views",
10098 SHOW_STR
10099 IP_STR
10100 BGP_STR
10101 "Show the defined BGP views\n")
10102 {
10103 struct list *inst = bm->bgp;
10104 struct listnode *node;
10105 struct bgp *bgp;
10106
10107 vty_out(vty, "Defined BGP views:\n");
10108 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10109 /* Skip VRFs. */
10110 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
10111 continue;
10112 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
10113 bgp->as);
10114 }
10115
10116 return CMD_SUCCESS;
10117 }
10118
10119 DEFUN (show_bgp_vrfs,
10120 show_bgp_vrfs_cmd,
10121 "show [ip] bgp vrfs [json]",
10122 SHOW_STR
10123 IP_STR
10124 BGP_STR
10125 "Show BGP VRFs\n"
10126 JSON_STR)
10127 {
10128 char buf[ETHER_ADDR_STRLEN];
10129 struct list *inst = bm->bgp;
10130 struct listnode *node;
10131 struct bgp *bgp;
10132 bool uj = use_json(argc, argv);
10133 json_object *json = NULL;
10134 json_object *json_vrfs = NULL;
10135 int count = 0;
10136
10137 if (uj) {
10138 json = json_object_new_object();
10139 json_vrfs = json_object_new_object();
10140 }
10141
10142 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10143 const char *name, *type;
10144 struct peer *peer;
10145 struct listnode *node2, *nnode2;
10146 int peers_cfg, peers_estb;
10147 json_object *json_vrf = NULL;
10148
10149 /* Skip Views. */
10150 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
10151 continue;
10152
10153 count++;
10154 if (!uj && count == 1) {
10155 vty_out(vty,
10156 "%4s %-5s %-16s %9s %10s %-37s\n",
10157 "Type", "Id", "routerId", "#PeersCfg",
10158 "#PeersEstb", "Name");
10159 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
10160 "L3-VNI", "RouterMAC", "Interface");
10161 }
10162
10163 peers_cfg = peers_estb = 0;
10164 if (uj)
10165 json_vrf = json_object_new_object();
10166
10167
10168 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
10169 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10170 continue;
10171 peers_cfg++;
10172 if (peer->status == Established)
10173 peers_estb++;
10174 }
10175
10176 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
10177 name = VRF_DEFAULT_NAME;
10178 type = "DFLT";
10179 } else {
10180 name = bgp->name;
10181 type = "VRF";
10182 }
10183
10184
10185 if (uj) {
10186 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10187 ? -1
10188 : (int64_t)bgp->vrf_id;
10189 char buf[BUFSIZ] = {0};
10190
10191 json_object_string_add(json_vrf, "type", type);
10192 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
10193 json_object_string_add(json_vrf, "routerId",
10194 inet_ntop(AF_INET,
10195 &bgp->router_id, buf,
10196 sizeof(buf)));
10197 json_object_int_add(json_vrf, "numConfiguredPeers",
10198 peers_cfg);
10199 json_object_int_add(json_vrf, "numEstablishedPeers",
10200 peers_estb);
10201
10202 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
10203 json_object_string_add(
10204 json_vrf, "rmac",
10205 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
10206 json_object_string_add(json_vrf, "interface",
10207 ifindex2ifname(bgp->l3vni_svi_ifindex,
10208 bgp->vrf_id));
10209 json_object_object_add(json_vrfs, name, json_vrf);
10210 } else {
10211 vty_out(vty, "%4s %-5d %-16pI4 %-9u %-10u %-37s\n",
10212 type,
10213 bgp->vrf_id == VRF_UNKNOWN ? -1
10214 : (int)bgp->vrf_id,
10215 &bgp->router_id, peers_cfg, peers_estb, name);
10216 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
10217 bgp->l3vni,
10218 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
10219 ifindex2ifname(bgp->l3vni_svi_ifindex,
10220 bgp->vrf_id));
10221 }
10222 }
10223
10224 if (uj) {
10225 json_object_object_add(json, "vrfs", json_vrfs);
10226
10227 json_object_int_add(json, "totalVrfs", count);
10228
10229 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10230 json, JSON_C_TO_STRING_PRETTY));
10231 json_object_free(json);
10232 } else {
10233 if (count)
10234 vty_out(vty,
10235 "\nTotal number of VRFs (including default): %d\n",
10236 count);
10237 }
10238
10239 return CMD_SUCCESS;
10240 }
10241
10242 DEFUN (show_bgp_mac_hash,
10243 show_bgp_mac_hash_cmd,
10244 "show bgp mac hash",
10245 SHOW_STR
10246 BGP_STR
10247 "Mac Address\n"
10248 "Mac Address database\n")
10249 {
10250 bgp_mac_dump_table(vty);
10251
10252 return CMD_SUCCESS;
10253 }
10254
10255 static void show_tip_entry(struct hash_bucket *bucket, void *args)
10256 {
10257 struct vty *vty = (struct vty *)args;
10258 struct tip_addr *tip = (struct tip_addr *)bucket->data;
10259
10260 vty_out(vty, "addr: %pI4, count: %d\n", &tip->addr, tip->refcnt);
10261 }
10262
10263 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
10264 {
10265 vty_out(vty, "self nexthop database:\n");
10266 bgp_nexthop_show_address_hash(vty, bgp);
10267
10268 vty_out(vty, "Tunnel-ip database:\n");
10269 hash_iterate(bgp->tip_hash,
10270 (void (*)(struct hash_bucket *, void *))show_tip_entry,
10271 vty);
10272 }
10273
10274 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
10275 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
10276 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
10277 "martian next-hops\n"
10278 "martian next-hop database\n")
10279 {
10280 struct bgp *bgp = NULL;
10281 int idx = 0;
10282 char *name = NULL;
10283
10284 /* [<vrf> VIEWVRFNAME] */
10285 if (argv_find(argv, argc, "vrf", &idx)) {
10286 name = argv[idx + 1]->arg;
10287 if (name && strmatch(name, VRF_DEFAULT_NAME))
10288 name = NULL;
10289 } else if (argv_find(argv, argc, "view", &idx))
10290 /* [<view> VIEWVRFNAME] */
10291 name = argv[idx + 1]->arg;
10292 if (name)
10293 bgp = bgp_lookup_by_name(name);
10294 else
10295 bgp = bgp_get_default();
10296
10297 if (!bgp) {
10298 vty_out(vty, "%% No BGP process is configured\n");
10299 return CMD_WARNING;
10300 }
10301 bgp_show_martian_nexthops(vty, bgp);
10302
10303 return CMD_SUCCESS;
10304 }
10305
10306 DEFUN (show_bgp_memory,
10307 show_bgp_memory_cmd,
10308 "show [ip] bgp memory",
10309 SHOW_STR
10310 IP_STR
10311 BGP_STR
10312 "Global BGP memory statistics\n")
10313 {
10314 char memstrbuf[MTYPE_MEMSTR_LEN];
10315 unsigned long count;
10316
10317 /* RIB related usage stats */
10318 count = mtype_stats_alloc(MTYPE_BGP_NODE);
10319 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
10320 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10321 count * sizeof(struct bgp_dest)));
10322
10323 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
10324 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
10325 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10326 count * sizeof(struct bgp_path_info)));
10327 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
10328 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
10329 count,
10330 mtype_memstr(
10331 memstrbuf, sizeof(memstrbuf),
10332 count * sizeof(struct bgp_path_info_extra)));
10333
10334 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
10335 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
10336 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10337 count * sizeof(struct bgp_static)));
10338
10339 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
10340 vty_out(vty, "%ld Packets, using %s of memory\n", count,
10341 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10342 count * sizeof(struct bpacket)));
10343
10344 /* Adj-In/Out */
10345 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
10346 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
10347 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10348 count * sizeof(struct bgp_adj_in)));
10349 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
10350 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
10351 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10352 count * sizeof(struct bgp_adj_out)));
10353
10354 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
10355 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
10356 count,
10357 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10358 count * sizeof(struct bgp_nexthop_cache)));
10359
10360 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
10361 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
10362 count,
10363 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10364 count * sizeof(struct bgp_damp_info)));
10365
10366 /* Attributes */
10367 count = attr_count();
10368 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
10369 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10370 count * sizeof(struct attr)));
10371
10372 if ((count = attr_unknown_count()))
10373 vty_out(vty, "%ld unknown attributes\n", count);
10374
10375 /* AS_PATH attributes */
10376 count = aspath_count();
10377 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
10378 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10379 count * sizeof(struct aspath)));
10380
10381 count = mtype_stats_alloc(MTYPE_AS_SEG);
10382 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
10383 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10384 count * sizeof(struct assegment)));
10385
10386 /* Other attributes */
10387 if ((count = community_count()))
10388 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
10389 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10390 count * sizeof(struct community)));
10391 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
10392 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
10393 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10394 count * sizeof(struct ecommunity)));
10395 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
10396 vty_out(vty,
10397 "%ld BGP large-community entries, using %s of memory\n",
10398 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10399 count * sizeof(struct lcommunity)));
10400
10401 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
10402 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
10403 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10404 count * sizeof(struct cluster_list)));
10405
10406 /* Peer related usage */
10407 count = mtype_stats_alloc(MTYPE_BGP_PEER);
10408 vty_out(vty, "%ld peers, using %s of memory\n", count,
10409 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10410 count * sizeof(struct peer)));
10411
10412 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
10413 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
10414 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10415 count * sizeof(struct peer_group)));
10416
10417 /* Other */
10418 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
10419 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
10420 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10421 count * sizeof(regex_t)));
10422 return CMD_SUCCESS;
10423 }
10424
10425 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
10426 {
10427 json_object *bestpath = json_object_new_object();
10428
10429 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
10430 json_object_string_add(bestpath, "asPath", "ignore");
10431
10432 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
10433 json_object_string_add(bestpath, "asPath", "confed");
10434
10435 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
10436 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
10437 json_object_string_add(bestpath, "multiPathRelax",
10438 "as-set");
10439 else
10440 json_object_string_add(bestpath, "multiPathRelax",
10441 "true");
10442 } else
10443 json_object_string_add(bestpath, "multiPathRelax", "false");
10444
10445 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
10446 json_object_string_add(bestpath, "compareRouterId", "true");
10447 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
10448 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
10449 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
10450 json_object_string_add(bestpath, "med", "confed");
10451 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
10452 json_object_string_add(bestpath, "med",
10453 "missing-as-worst");
10454 else
10455 json_object_string_add(bestpath, "med", "true");
10456 }
10457
10458 json_object_object_add(json, "bestPath", bestpath);
10459 }
10460
10461 /* Print the error code/subcode for why the peer is down */
10462 static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
10463 json_object *json_peer, bool use_json)
10464 {
10465 const char *code_str;
10466 const char *subcode_str;
10467
10468 if (use_json) {
10469 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10470 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10471 char errorcodesubcode_hexstr[5];
10472 char errorcodesubcode_str[256];
10473
10474 code_str = bgp_notify_code_str(peer->notify.code);
10475 subcode_str = bgp_notify_subcode_str(
10476 peer->notify.code,
10477 peer->notify.subcode);
10478
10479 snprintf(errorcodesubcode_hexstr,
10480 sizeof(errorcodesubcode_hexstr), "%02X%02X",
10481 peer->notify.code, peer->notify.subcode);
10482 json_object_string_add(json_peer,
10483 "lastErrorCodeSubcode",
10484 errorcodesubcode_hexstr);
10485 snprintf(errorcodesubcode_str, 255, "%s%s",
10486 code_str, subcode_str);
10487 json_object_string_add(json_peer,
10488 "lastNotificationReason",
10489 errorcodesubcode_str);
10490 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10491 && peer->notify.code == BGP_NOTIFY_CEASE
10492 && (peer->notify.subcode
10493 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10494 || peer->notify.subcode
10495 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10496 && peer->notify.length) {
10497 char msgbuf[1024];
10498 const char *msg_str;
10499
10500 msg_str = bgp_notify_admin_message(
10501 msgbuf, sizeof(msgbuf),
10502 (uint8_t *)peer->notify.data,
10503 peer->notify.length);
10504 if (msg_str)
10505 json_object_string_add(
10506 json_peer,
10507 "lastShutdownDescription",
10508 msg_str);
10509 }
10510
10511 }
10512 json_object_string_add(json_peer, "lastResetDueTo",
10513 peer_down_str[(int)peer->last_reset]);
10514 json_object_int_add(json_peer, "lastResetCode",
10515 peer->last_reset);
10516 } else {
10517 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10518 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10519 code_str = bgp_notify_code_str(peer->notify.code);
10520 subcode_str =
10521 bgp_notify_subcode_str(peer->notify.code,
10522 peer->notify.subcode);
10523 vty_out(vty, " Notification %s (%s%s)\n",
10524 peer->last_reset == PEER_DOWN_NOTIFY_SEND
10525 ? "sent"
10526 : "received",
10527 code_str, subcode_str);
10528 } else {
10529 vty_out(vty, " %s\n",
10530 peer_down_str[(int)peer->last_reset]);
10531 }
10532 }
10533 }
10534
10535 static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
10536 safi_t safi)
10537 {
10538 return ((peer->status != Established) ||
10539 !peer->afc_recv[afi][safi]);
10540 }
10541
10542 static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
10543 struct peer *peer, json_object *json_peer,
10544 int max_neighbor_width, bool use_json)
10545 {
10546 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10547 int len;
10548
10549 if (use_json) {
10550 if (peer_dynamic_neighbor(peer))
10551 json_object_boolean_true_add(json_peer,
10552 "dynamicPeer");
10553 if (peer->hostname)
10554 json_object_string_add(json_peer, "hostname",
10555 peer->hostname);
10556
10557 if (peer->domainname)
10558 json_object_string_add(json_peer, "domainname",
10559 peer->domainname);
10560 json_object_int_add(json_peer, "connectionsEstablished",
10561 peer->established);
10562 json_object_int_add(json_peer, "connectionsDropped",
10563 peer->dropped);
10564 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10565 use_json, json_peer);
10566 if (peer->status == Established)
10567 json_object_string_add(json_peer, "lastResetDueTo",
10568 "AFI/SAFI Not Negotiated");
10569 else
10570 bgp_show_peer_reset(NULL, peer, json_peer, true);
10571 } else {
10572 dn_flag[1] = '\0';
10573 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
10574 if (peer->hostname
10575 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
10576 len = vty_out(vty, "%s%s(%s)", dn_flag,
10577 peer->hostname, peer->host);
10578 else
10579 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10580
10581 /* pad the neighbor column with spaces */
10582 if (len < max_neighbor_width)
10583 vty_out(vty, "%*s", max_neighbor_width - len,
10584 " ");
10585 vty_out(vty, "%7d %7d %9s", peer->established,
10586 peer->dropped,
10587 peer_uptime(peer->uptime, timebuf,
10588 BGP_UPTIME_LEN, 0, NULL));
10589 if (peer->status == Established)
10590 vty_out(vty, " AFI/SAFI Not Negotiated\n");
10591 else
10592 bgp_show_peer_reset(vty, peer, NULL,
10593 false);
10594 }
10595 }
10596
10597 /* If the peer's description includes whitespaces
10598 * then return the first occurrence. Also strip description
10599 * to the given size if needed.
10600 */
10601 static char *bgp_peer_description_stripped(char *desc, uint32_t size)
10602 {
10603 static char stripped[BUFSIZ];
10604 char *pnt;
10605 uint32_t len = size > strlen(desc) ? strlen(desc) : size;
10606
10607 pnt = strchr(desc, ' ');
10608 if (pnt)
10609 len = size > (uint32_t)(pnt - desc) ? (uint32_t)(pnt - desc)
10610 : size;
10611
10612 strlcpy(stripped, desc, len + 1);
10613
10614 return stripped;
10615 }
10616
10617 /* Show BGP peer's summary information. */
10618 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
10619 uint8_t show_flags)
10620 {
10621 struct peer *peer;
10622 struct listnode *node, *nnode;
10623 unsigned int count = 0, dn_count = 0;
10624 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10625 char neighbor_buf[VTY_BUFSIZ];
10626 int neighbor_col_default_width = 16;
10627 int len, failed_count = 0;
10628 int max_neighbor_width = 0;
10629 int pfx_rcd_safi;
10630 json_object *json = NULL;
10631 json_object *json_peer = NULL;
10632 json_object *json_peers = NULL;
10633 struct peer_af *paf;
10634 struct bgp_filter *filter;
10635 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
10636 bool show_failed = CHECK_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
10637 bool show_established =
10638 CHECK_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
10639 bool show_wide = CHECK_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
10640
10641 /* labeled-unicast routes are installed in the unicast table so in order
10642 * to
10643 * display the correct PfxRcd value we must look at SAFI_UNICAST
10644 */
10645
10646 if (safi == SAFI_LABELED_UNICAST)
10647 pfx_rcd_safi = SAFI_UNICAST;
10648 else
10649 pfx_rcd_safi = safi;
10650
10651 if (use_json) {
10652 json = json_object_new_object();
10653 json_peers = json_object_new_object();
10654 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10655 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10656 continue;
10657
10658 if (peer->afc[afi][safi]) {
10659 /* See if we have at least a single failed peer */
10660 if (bgp_has_peer_failed(peer, afi, safi))
10661 failed_count++;
10662 count++;
10663 }
10664 if (peer_dynamic_neighbor(peer))
10665 dn_count++;
10666 }
10667
10668 } else {
10669 /* Loop over all neighbors that will be displayed to determine
10670 * how many
10671 * characters are needed for the Neighbor column
10672 */
10673 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10674 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10675 continue;
10676
10677 if (peer->afc[afi][safi]) {
10678 memset(dn_flag, '\0', sizeof(dn_flag));
10679 if (peer_dynamic_neighbor(peer))
10680 dn_flag[0] = '*';
10681
10682 if (peer->hostname
10683 && CHECK_FLAG(bgp->flags,
10684 BGP_FLAG_SHOW_HOSTNAME))
10685 snprintf(neighbor_buf,
10686 sizeof(neighbor_buf),
10687 "%s%s(%s) ", dn_flag,
10688 peer->hostname, peer->host);
10689 else
10690 snprintf(neighbor_buf,
10691 sizeof(neighbor_buf), "%s%s ",
10692 dn_flag, peer->host);
10693
10694 len = strlen(neighbor_buf);
10695
10696 if (len > max_neighbor_width)
10697 max_neighbor_width = len;
10698
10699 /* See if we have at least a single failed peer */
10700 if (bgp_has_peer_failed(peer, afi, safi))
10701 failed_count++;
10702 count++;
10703 }
10704 }
10705
10706 /* Originally we displayed the Neighbor column as 16
10707 * characters wide so make that the default
10708 */
10709 if (max_neighbor_width < neighbor_col_default_width)
10710 max_neighbor_width = neighbor_col_default_width;
10711 }
10712
10713 if (show_failed && !failed_count) {
10714 if (use_json) {
10715 json_object_int_add(json, "failedPeersCount", 0);
10716 json_object_int_add(json, "dynamicPeers", dn_count);
10717 json_object_int_add(json, "totalPeers", count);
10718
10719 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10720 json, JSON_C_TO_STRING_PRETTY));
10721 json_object_free(json);
10722 } else {
10723 vty_out(vty, "%% No failed BGP neighbors found\n");
10724 vty_out(vty, "\nTotal number of neighbors %d\n", count);
10725 }
10726 return CMD_SUCCESS;
10727 }
10728
10729 count = 0; /* Reset the value as its used again */
10730 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10731 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10732 continue;
10733
10734 if (!peer->afc[afi][safi])
10735 continue;
10736
10737 if (!count) {
10738 unsigned long ents;
10739 char memstrbuf[MTYPE_MEMSTR_LEN];
10740 int64_t vrf_id_ui;
10741
10742 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10743 ? -1
10744 : (int64_t)bgp->vrf_id;
10745
10746 /* Usage summary and header */
10747 if (use_json) {
10748 char buf[BUFSIZ] = {0};
10749
10750 json_object_string_add(
10751 json, "routerId",
10752 inet_ntop(AF_INET, &bgp->router_id, buf,
10753 sizeof(buf)));
10754 json_object_int_add(json, "as", bgp->as);
10755 json_object_int_add(json, "vrfId", vrf_id_ui);
10756 json_object_string_add(
10757 json, "vrfName",
10758 (bgp->inst_type
10759 == BGP_INSTANCE_TYPE_DEFAULT)
10760 ? VRF_DEFAULT_NAME
10761 : bgp->name);
10762 } else {
10763 vty_out(vty,
10764 "BGP router identifier %pI4, local AS number %u vrf-id %d",
10765 &bgp->router_id, bgp->as,
10766 bgp->vrf_id == VRF_UNKNOWN
10767 ? -1
10768 : (int)bgp->vrf_id);
10769 vty_out(vty, "\n");
10770 }
10771
10772 if (bgp_update_delay_configured(bgp)) {
10773 if (use_json) {
10774 json_object_int_add(
10775 json, "updateDelayLimit",
10776 bgp->v_update_delay);
10777
10778 if (bgp->v_update_delay
10779 != bgp->v_establish_wait)
10780 json_object_int_add(
10781 json,
10782 "updateDelayEstablishWait",
10783 bgp->v_establish_wait);
10784
10785 if (bgp_update_delay_active(bgp)) {
10786 json_object_string_add(
10787 json,
10788 "updateDelayFirstNeighbor",
10789 bgp->update_delay_begin_time);
10790 json_object_boolean_true_add(
10791 json,
10792 "updateDelayInProgress");
10793 } else {
10794 if (bgp->update_delay_over) {
10795 json_object_string_add(
10796 json,
10797 "updateDelayFirstNeighbor",
10798 bgp->update_delay_begin_time);
10799 json_object_string_add(
10800 json,
10801 "updateDelayBestpathResumed",
10802 bgp->update_delay_end_time);
10803 json_object_string_add(
10804 json,
10805 "updateDelayZebraUpdateResume",
10806 bgp->update_delay_zebra_resume_time);
10807 json_object_string_add(
10808 json,
10809 "updateDelayPeerUpdateResume",
10810 bgp->update_delay_peers_resume_time);
10811 }
10812 }
10813 } else {
10814 vty_out(vty,
10815 "Read-only mode update-delay limit: %d seconds\n",
10816 bgp->v_update_delay);
10817 if (bgp->v_update_delay
10818 != bgp->v_establish_wait)
10819 vty_out(vty,
10820 " Establish wait: %d seconds\n",
10821 bgp->v_establish_wait);
10822
10823 if (bgp_update_delay_active(bgp)) {
10824 vty_out(vty,
10825 " First neighbor established: %s\n",
10826 bgp->update_delay_begin_time);
10827 vty_out(vty,
10828 " Delay in progress\n");
10829 } else {
10830 if (bgp->update_delay_over) {
10831 vty_out(vty,
10832 " First neighbor established: %s\n",
10833 bgp->update_delay_begin_time);
10834 vty_out(vty,
10835 " Best-paths resumed: %s\n",
10836 bgp->update_delay_end_time);
10837 vty_out(vty,
10838 " zebra update resumed: %s\n",
10839 bgp->update_delay_zebra_resume_time);
10840 vty_out(vty,
10841 " peers update resumed: %s\n",
10842 bgp->update_delay_peers_resume_time);
10843 }
10844 }
10845 }
10846 }
10847
10848 if (use_json) {
10849 if (bgp_maxmed_onstartup_configured(bgp)
10850 && bgp->maxmed_active)
10851 json_object_boolean_true_add(
10852 json, "maxMedOnStartup");
10853 if (bgp->v_maxmed_admin)
10854 json_object_boolean_true_add(
10855 json, "maxMedAdministrative");
10856
10857 json_object_int_add(
10858 json, "tableVersion",
10859 bgp_table_version(bgp->rib[afi][safi]));
10860
10861 ents = bgp_table_count(bgp->rib[afi][safi]);
10862 json_object_int_add(json, "ribCount", ents);
10863 json_object_int_add(
10864 json, "ribMemory",
10865 ents * sizeof(struct bgp_dest));
10866
10867 ents = bgp->af_peer_count[afi][safi];
10868 json_object_int_add(json, "peerCount", ents);
10869 json_object_int_add(json, "peerMemory",
10870 ents * sizeof(struct peer));
10871
10872 if ((ents = listcount(bgp->group))) {
10873 json_object_int_add(
10874 json, "peerGroupCount", ents);
10875 json_object_int_add(
10876 json, "peerGroupMemory",
10877 ents * sizeof(struct
10878 peer_group));
10879 }
10880
10881 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10882 BGP_CONFIG_DAMPENING))
10883 json_object_boolean_true_add(
10884 json, "dampeningEnabled");
10885 } else {
10886 if (bgp_maxmed_onstartup_configured(bgp)
10887 && bgp->maxmed_active)
10888 vty_out(vty,
10889 "Max-med on-startup active\n");
10890 if (bgp->v_maxmed_admin)
10891 vty_out(vty,
10892 "Max-med administrative active\n");
10893
10894 vty_out(vty, "BGP table version %" PRIu64 "\n",
10895 bgp_table_version(bgp->rib[afi][safi]));
10896
10897 ents = bgp_table_count(bgp->rib[afi][safi]);
10898 vty_out(vty,
10899 "RIB entries %ld, using %s of memory\n",
10900 ents,
10901 mtype_memstr(
10902 memstrbuf, sizeof(memstrbuf),
10903 ents
10904 * sizeof(struct
10905 bgp_dest)));
10906
10907 /* Peer related usage */
10908 ents = bgp->af_peer_count[afi][safi];
10909 vty_out(vty, "Peers %ld, using %s of memory\n",
10910 ents,
10911 mtype_memstr(
10912 memstrbuf, sizeof(memstrbuf),
10913 ents * sizeof(struct peer)));
10914
10915 if ((ents = listcount(bgp->group)))
10916 vty_out(vty,
10917 "Peer groups %ld, using %s of memory\n",
10918 ents,
10919 mtype_memstr(
10920 memstrbuf,
10921 sizeof(memstrbuf),
10922 ents * sizeof(struct
10923 peer_group)));
10924
10925 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10926 BGP_CONFIG_DAMPENING))
10927 vty_out(vty, "Dampening enabled.\n");
10928 vty_out(vty, "\n");
10929
10930 /* Subtract 8 here because 'Neighbor' is
10931 * 8 characters */
10932 vty_out(vty, "Neighbor");
10933 vty_out(vty, "%*s", max_neighbor_width - 8,
10934 " ");
10935 if (show_failed)
10936 vty_out(vty,
10937 BGP_SHOW_SUMMARY_HEADER_FAILED);
10938 else
10939 vty_out(vty,
10940 show_wide
10941 ? BGP_SHOW_SUMMARY_HEADER_ALL_WIDE
10942 : BGP_SHOW_SUMMARY_HEADER_ALL);
10943 }
10944 }
10945
10946 paf = peer_af_find(peer, afi, safi);
10947 filter = &peer->filter[afi][safi];
10948
10949 count++;
10950 /* Works for both failed & successful cases */
10951 if (peer_dynamic_neighbor(peer))
10952 dn_count++;
10953
10954 if (use_json) {
10955 json_peer = NULL;
10956
10957 if (show_failed &&
10958 bgp_has_peer_failed(peer, afi, safi)) {
10959 json_peer = json_object_new_object();
10960 bgp_show_failed_summary(vty, bgp, peer,
10961 json_peer, 0, use_json);
10962 } else if (!show_failed) {
10963 if (show_established
10964 && bgp_has_peer_failed(peer, afi, safi))
10965 continue;
10966
10967 json_peer = json_object_new_object();
10968 if (peer_dynamic_neighbor(peer)) {
10969 json_object_boolean_true_add(json_peer,
10970 "dynamicPeer");
10971 }
10972
10973 if (peer->hostname)
10974 json_object_string_add(json_peer, "hostname",
10975 peer->hostname);
10976
10977 if (peer->domainname)
10978 json_object_string_add(json_peer, "domainname",
10979 peer->domainname);
10980
10981 json_object_int_add(json_peer, "remoteAs", peer->as);
10982 json_object_int_add(
10983 json_peer, "localAs",
10984 peer->change_local_as
10985 ? peer->change_local_as
10986 : peer->local_as);
10987 json_object_int_add(json_peer, "version", 4);
10988 json_object_int_add(json_peer, "msgRcvd",
10989 PEER_TOTAL_RX(peer));
10990 json_object_int_add(json_peer, "msgSent",
10991 PEER_TOTAL_TX(peer));
10992
10993 atomic_size_t outq_count, inq_count;
10994 outq_count = atomic_load_explicit(
10995 &peer->obuf->count,
10996 memory_order_relaxed);
10997 inq_count = atomic_load_explicit(
10998 &peer->ibuf->count,
10999 memory_order_relaxed);
11000
11001 json_object_int_add(json_peer, "tableVersion",
11002 peer->version[afi][safi]);
11003 json_object_int_add(json_peer, "outq",
11004 outq_count);
11005 json_object_int_add(json_peer, "inq",
11006 inq_count);
11007 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
11008 use_json, json_peer);
11009
11010 json_object_int_add(json_peer, "pfxRcd",
11011 peer->pcount[afi][pfx_rcd_safi]);
11012
11013 if (paf && PAF_SUBGRP(paf))
11014 json_object_int_add(
11015 json_peer, "pfxSnt",
11016 (PAF_SUBGRP(paf))->scount);
11017 else
11018 json_object_int_add(json_peer, "pfxSnt",
11019 0);
11020
11021 /* BGP FSM state */
11022 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
11023 || CHECK_FLAG(peer->bgp->flags,
11024 BGP_FLAG_SHUTDOWN))
11025 json_object_string_add(json_peer,
11026 "state",
11027 "Idle (Admin)");
11028 else if (peer->afc_recv[afi][safi])
11029 json_object_string_add(
11030 json_peer, "state",
11031 lookup_msg(bgp_status_msg,
11032 peer->status, NULL));
11033 else if (CHECK_FLAG(
11034 peer->sflags,
11035 PEER_STATUS_PREFIX_OVERFLOW))
11036 json_object_string_add(json_peer,
11037 "state",
11038 "Idle (PfxCt)");
11039 else
11040 json_object_string_add(
11041 json_peer, "state",
11042 lookup_msg(bgp_status_msg,
11043 peer->status, NULL));
11044
11045 /* BGP peer state */
11046 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
11047 || CHECK_FLAG(peer->bgp->flags,
11048 BGP_FLAG_SHUTDOWN))
11049 json_object_string_add(json_peer,
11050 "peerState",
11051 "Admin");
11052 else if (CHECK_FLAG(
11053 peer->sflags,
11054 PEER_STATUS_PREFIX_OVERFLOW))
11055 json_object_string_add(json_peer,
11056 "peerState",
11057 "PfxCt");
11058 else if (CHECK_FLAG(peer->flags,
11059 PEER_FLAG_PASSIVE))
11060 json_object_string_add(json_peer,
11061 "peerState",
11062 "Passive");
11063 else if (CHECK_FLAG(peer->sflags,
11064 PEER_STATUS_NSF_WAIT))
11065 json_object_string_add(json_peer,
11066 "peerState",
11067 "NSF passive");
11068 else if (CHECK_FLAG(
11069 peer->bgp->flags,
11070 BGP_FLAG_EBGP_REQUIRES_POLICY)
11071 && (!bgp_inbound_policy_exists(peer,
11072 filter)
11073 || !bgp_outbound_policy_exists(
11074 peer, filter)))
11075 json_object_string_add(json_peer,
11076 "peerState",
11077 "Policy");
11078 else
11079 json_object_string_add(
11080 json_peer, "peerState", "OK");
11081
11082 json_object_int_add(json_peer, "connectionsEstablished",
11083 peer->established);
11084 json_object_int_add(json_peer, "connectionsDropped",
11085 peer->dropped);
11086 if (peer->desc)
11087 json_object_string_add(
11088 json_peer, "desc", peer->desc);
11089 }
11090 /* Avoid creating empty peer dicts in JSON */
11091 if (json_peer == NULL)
11092 continue;
11093
11094 if (peer->conf_if)
11095 json_object_string_add(json_peer, "idType",
11096 "interface");
11097 else if (peer->su.sa.sa_family == AF_INET)
11098 json_object_string_add(json_peer, "idType",
11099 "ipv4");
11100 else if (peer->su.sa.sa_family == AF_INET6)
11101 json_object_string_add(json_peer, "idType",
11102 "ipv6");
11103 json_object_object_add(json_peers, peer->host,
11104 json_peer);
11105 } else {
11106 if (show_failed &&
11107 bgp_has_peer_failed(peer, afi, safi)) {
11108 bgp_show_failed_summary(vty, bgp, peer, NULL,
11109 max_neighbor_width,
11110 use_json);
11111 } else if (!show_failed) {
11112 if (show_established
11113 && bgp_has_peer_failed(peer, afi, safi))
11114 continue;
11115
11116 memset(dn_flag, '\0', sizeof(dn_flag));
11117 if (peer_dynamic_neighbor(peer)) {
11118 dn_flag[0] = '*';
11119 }
11120
11121 if (peer->hostname
11122 && CHECK_FLAG(bgp->flags,
11123 BGP_FLAG_SHOW_HOSTNAME))
11124 len = vty_out(vty, "%s%s(%s)", dn_flag,
11125 peer->hostname,
11126 peer->host);
11127 else
11128 len = vty_out(vty, "%s%s", dn_flag, peer->host);
11129
11130 /* pad the neighbor column with spaces */
11131 if (len < max_neighbor_width)
11132 vty_out(vty, "%*s", max_neighbor_width - len,
11133 " ");
11134
11135 atomic_size_t outq_count, inq_count;
11136 outq_count = atomic_load_explicit(
11137 &peer->obuf->count,
11138 memory_order_relaxed);
11139 inq_count = atomic_load_explicit(
11140 &peer->ibuf->count,
11141 memory_order_relaxed);
11142
11143 if (show_wide)
11144 vty_out(vty,
11145 "4 %10u %10u %9u %9u %8" PRIu64
11146 " %4zu %4zu %8s",
11147 peer->as,
11148 peer->change_local_as
11149 ? peer->change_local_as
11150 : peer->local_as,
11151 PEER_TOTAL_RX(peer),
11152 PEER_TOTAL_TX(peer),
11153 peer->version[afi][safi],
11154 inq_count, outq_count,
11155 peer_uptime(peer->uptime,
11156 timebuf,
11157 BGP_UPTIME_LEN, 0,
11158 NULL));
11159 else
11160 vty_out(vty, "4 %10u %9u %9u %8" PRIu64
11161 " %4zu %4zu %8s",
11162 peer->as, PEER_TOTAL_RX(peer),
11163 PEER_TOTAL_TX(peer),
11164 peer->version[afi][safi],
11165 inq_count, outq_count,
11166 peer_uptime(peer->uptime,
11167 timebuf,
11168 BGP_UPTIME_LEN, 0,
11169 NULL));
11170
11171 if (peer->status == Established) {
11172 if (peer->afc_recv[afi][safi]) {
11173 if (CHECK_FLAG(
11174 bgp->flags,
11175 BGP_FLAG_EBGP_REQUIRES_POLICY)
11176 && !bgp_inbound_policy_exists(
11177 peer, filter))
11178 vty_out(vty, " %12s",
11179 "(Policy)");
11180 else
11181 vty_out(vty,
11182 " %12u",
11183 peer->pcount
11184 [afi]
11185 [pfx_rcd_safi]);
11186 } else {
11187 vty_out(vty, " NoNeg");
11188 }
11189
11190 if (paf && PAF_SUBGRP(paf)) {
11191 if (CHECK_FLAG(
11192 bgp->flags,
11193 BGP_FLAG_EBGP_REQUIRES_POLICY)
11194 && !bgp_outbound_policy_exists(
11195 peer, filter))
11196 vty_out(vty, " %8s",
11197 "(Policy)");
11198 else
11199 vty_out(vty,
11200 " %8u",
11201 (PAF_SUBGRP(
11202 paf))
11203 ->scount);
11204 } else {
11205 vty_out(vty, " NoNeg");
11206 }
11207 } else {
11208 if (CHECK_FLAG(peer->flags,
11209 PEER_FLAG_SHUTDOWN)
11210 || CHECK_FLAG(peer->bgp->flags,
11211 BGP_FLAG_SHUTDOWN))
11212 vty_out(vty, " Idle (Admin)");
11213 else if (CHECK_FLAG(
11214 peer->sflags,
11215 PEER_STATUS_PREFIX_OVERFLOW))
11216 vty_out(vty, " Idle (PfxCt)");
11217 else
11218 vty_out(vty, " %12s",
11219 lookup_msg(bgp_status_msg,
11220 peer->status, NULL));
11221
11222 vty_out(vty, " %8u", 0);
11223 }
11224 if (peer->desc)
11225 vty_out(vty, " %s",
11226 bgp_peer_description_stripped(
11227 peer->desc,
11228 show_wide ? 64 : 20));
11229 else
11230 vty_out(vty, " N/A");
11231 vty_out(vty, "\n");
11232 }
11233
11234 }
11235 }
11236
11237 if (use_json) {
11238 json_object_object_add(json, "peers", json_peers);
11239 json_object_int_add(json, "failedPeers", failed_count);
11240 json_object_int_add(json, "totalPeers", count);
11241 json_object_int_add(json, "dynamicPeers", dn_count);
11242
11243 if (!show_failed)
11244 bgp_show_bestpath_json(bgp, json);
11245
11246 vty_out(vty, "%s\n", json_object_to_json_string_ext(
11247 json, JSON_C_TO_STRING_PRETTY));
11248 json_object_free(json);
11249 } else {
11250 if (count)
11251 vty_out(vty, "\nTotal number of neighbors %d\n", count);
11252 else {
11253 vty_out(vty, "No %s neighbor is configured\n",
11254 get_afi_safi_str(afi, safi, false));
11255 }
11256
11257 if (dn_count) {
11258 vty_out(vty, "* - dynamic neighbor\n");
11259 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
11260 dn_count, bgp->dynamic_neighbors_limit);
11261 }
11262 }
11263
11264 return CMD_SUCCESS;
11265 }
11266
11267 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
11268 int safi, uint8_t show_flags)
11269 {
11270 int is_first = 1;
11271 int afi_wildcard = (afi == AFI_MAX);
11272 int safi_wildcard = (safi == SAFI_MAX);
11273 int is_wildcard = (afi_wildcard || safi_wildcard);
11274 bool nbr_output = false;
11275 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11276
11277 if (use_json && is_wildcard)
11278 vty_out(vty, "{\n");
11279 if (afi_wildcard)
11280 afi = 1; /* AFI_IP */
11281 while (afi < AFI_MAX) {
11282 if (safi_wildcard)
11283 safi = 1; /* SAFI_UNICAST */
11284 while (safi < SAFI_MAX) {
11285 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
11286 nbr_output = true;
11287
11288 if (is_wildcard) {
11289 /*
11290 * So limit output to those afi/safi
11291 * pairs that
11292 * actualy have something interesting in
11293 * them
11294 */
11295 if (use_json) {
11296 if (!is_first)
11297 vty_out(vty, ",\n");
11298 else
11299 is_first = 0;
11300
11301 vty_out(vty, "\"%s\":",
11302 get_afi_safi_str(afi,
11303 safi,
11304 true));
11305 } else {
11306 vty_out(vty, "\n%s Summary:\n",
11307 get_afi_safi_str(afi,
11308 safi,
11309 false));
11310 }
11311 }
11312 bgp_show_summary(vty, bgp, afi, safi,
11313 show_flags);
11314 }
11315 safi++;
11316 if (!safi_wildcard)
11317 safi = SAFI_MAX;
11318 }
11319 afi++;
11320 if (!afi_wildcard)
11321 afi = AFI_MAX;
11322 }
11323
11324 if (use_json && is_wildcard)
11325 vty_out(vty, "}\n");
11326 else if (!nbr_output) {
11327 if (use_json)
11328 vty_out(vty, "{}\n");
11329 else
11330 vty_out(vty, "%% No BGP neighbors found\n");
11331 }
11332 }
11333
11334 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
11335 safi_t safi, uint8_t show_flags)
11336 {
11337 struct listnode *node, *nnode;
11338 struct bgp *bgp;
11339 int is_first = 1;
11340 bool nbr_output = false;
11341 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11342
11343 if (use_json)
11344 vty_out(vty, "{\n");
11345
11346 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11347 nbr_output = true;
11348 if (use_json) {
11349 if (!is_first)
11350 vty_out(vty, ",\n");
11351 else
11352 is_first = 0;
11353
11354 vty_out(vty, "\"%s\":",
11355 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11356 ? VRF_DEFAULT_NAME
11357 : bgp->name);
11358 } else {
11359 vty_out(vty, "\nInstance %s:\n",
11360 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11361 ? VRF_DEFAULT_NAME
11362 : bgp->name);
11363 }
11364 bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_flags);
11365 }
11366
11367 if (use_json)
11368 vty_out(vty, "}\n");
11369 else if (!nbr_output)
11370 vty_out(vty, "%% BGP instance not found\n");
11371 }
11372
11373 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
11374 safi_t safi, uint8_t show_flags)
11375 {
11376 struct bgp *bgp;
11377 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11378
11379 if (name) {
11380 if (strmatch(name, "all")) {
11381 bgp_show_all_instances_summary_vty(vty, afi, safi,
11382 show_flags);
11383 return CMD_SUCCESS;
11384 } else {
11385 bgp = bgp_lookup_by_name(name);
11386
11387 if (!bgp) {
11388 if (use_json)
11389 vty_out(vty, "{}\n");
11390 else
11391 vty_out(vty,
11392 "%% BGP instance not found\n");
11393 return CMD_WARNING;
11394 }
11395
11396 bgp_show_summary_afi_safi(vty, bgp, afi, safi,
11397 show_flags);
11398 return CMD_SUCCESS;
11399 }
11400 }
11401
11402 bgp = bgp_get_default();
11403
11404 if (bgp)
11405 bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_flags);
11406 else {
11407 if (use_json)
11408 vty_out(vty, "{}\n");
11409 else
11410 vty_out(vty, "%% BGP instance not found\n");
11411 return CMD_WARNING;
11412 }
11413
11414 return CMD_SUCCESS;
11415 }
11416
11417 /* `show [ip] bgp summary' commands. */
11418 DEFPY (show_ip_bgp_summary,
11419 show_ip_bgp_summary_cmd,
11420 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] [all$all] summary [established|failed] [wide] [json$uj]",
11421 SHOW_STR
11422 IP_STR
11423 BGP_STR
11424 BGP_INSTANCE_HELP_STR
11425 BGP_AFI_HELP_STR
11426 BGP_SAFI_WITH_LABEL_HELP_STR
11427 "Display the entries for all address families\n"
11428 "Summary of BGP neighbor status\n"
11429 "Show only sessions in Established state\n"
11430 "Show only sessions not in Established state\n"
11431 "Increase table width for longer output\n"
11432 JSON_STR)
11433 {
11434 char *vrf = NULL;
11435 afi_t afi = AFI_MAX;
11436 safi_t safi = SAFI_MAX;
11437 uint8_t show_flags = 0;
11438
11439 int idx = 0;
11440
11441 /* show [ip] bgp */
11442 if (!all && argv_find(argv, argc, "ip", &idx))
11443 afi = AFI_IP;
11444 /* [<vrf> VIEWVRFNAME] */
11445 if (argv_find(argv, argc, "vrf", &idx)) {
11446 vrf = argv[idx + 1]->arg;
11447 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11448 vrf = NULL;
11449 } else if (argv_find(argv, argc, "view", &idx))
11450 /* [<view> VIEWVRFNAME] */
11451 vrf = argv[idx + 1]->arg;
11452 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11453 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11454 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11455 }
11456
11457 if (argv_find(argv, argc, "failed", &idx))
11458 SET_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
11459
11460 if (argv_find(argv, argc, "established", &idx))
11461 SET_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
11462
11463 if (argv_find(argv, argc, "wide", &idx))
11464 SET_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
11465
11466 if (argv_find(argv, argc, "json", &idx))
11467 SET_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11468
11469 return bgp_show_summary_vty(vty, vrf, afi, safi, show_flags);
11470 }
11471
11472 const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
11473 {
11474 if (for_json)
11475 return get_afi_safi_json_str(afi, safi);
11476 else
11477 return get_afi_safi_vty_str(afi, safi);
11478 }
11479
11480
11481 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
11482 afi_t afi, safi_t safi,
11483 uint16_t adv_smcap, uint16_t adv_rmcap,
11484 uint16_t rcv_smcap, uint16_t rcv_rmcap,
11485 bool use_json, json_object *json_pref)
11486 {
11487 /* Send-Mode */
11488 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11489 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
11490 if (use_json) {
11491 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11492 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11493 json_object_string_add(json_pref, "sendMode",
11494 "advertisedAndReceived");
11495 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11496 json_object_string_add(json_pref, "sendMode",
11497 "advertised");
11498 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11499 json_object_string_add(json_pref, "sendMode",
11500 "received");
11501 } else {
11502 vty_out(vty, " Send-mode: ");
11503 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11504 vty_out(vty, "advertised");
11505 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11506 vty_out(vty, "%sreceived",
11507 CHECK_FLAG(p->af_cap[afi][safi],
11508 adv_smcap)
11509 ? ", "
11510 : "");
11511 vty_out(vty, "\n");
11512 }
11513 }
11514
11515 /* Receive-Mode */
11516 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11517 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
11518 if (use_json) {
11519 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11520 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11521 json_object_string_add(json_pref, "recvMode",
11522 "advertisedAndReceived");
11523 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11524 json_object_string_add(json_pref, "recvMode",
11525 "advertised");
11526 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11527 json_object_string_add(json_pref, "recvMode",
11528 "received");
11529 } else {
11530 vty_out(vty, " Receive-mode: ");
11531 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11532 vty_out(vty, "advertised");
11533 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11534 vty_out(vty, "%sreceived",
11535 CHECK_FLAG(p->af_cap[afi][safi],
11536 adv_rmcap)
11537 ? ", "
11538 : "");
11539 vty_out(vty, "\n");
11540 }
11541 }
11542 }
11543
11544 static void bgp_show_neighnor_graceful_restart_rbit(struct vty *vty,
11545 struct peer *p,
11546 bool use_json,
11547 json_object *json)
11548 {
11549 bool rbit_status = false;
11550
11551 if (!use_json)
11552 vty_out(vty, "\n R bit: ");
11553
11554 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
11555 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
11556 && (p->status == Established)) {
11557
11558 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_BIT_RCV))
11559 rbit_status = true;
11560 else
11561 rbit_status = false;
11562 }
11563
11564 if (rbit_status) {
11565 if (use_json)
11566 json_object_boolean_true_add(json, "rBit");
11567 else
11568 vty_out(vty, "True\n");
11569 } else {
11570 if (use_json)
11571 json_object_boolean_false_add(json, "rBit");
11572 else
11573 vty_out(vty, "False\n");
11574 }
11575 }
11576
11577 static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
11578 struct peer *peer,
11579 bool use_json,
11580 json_object *json)
11581 {
11582 const char *mode = "NotApplicable";
11583
11584 if (!use_json)
11585 vty_out(vty, "\n Remote GR Mode: ");
11586
11587 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
11588 && (peer->status == Established)) {
11589
11590 if ((peer->nsf_af_count == 0)
11591 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11592
11593 mode = "Disable";
11594
11595 } else if (peer->nsf_af_count == 0
11596 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11597
11598 mode = "Helper";
11599
11600 } else if (peer->nsf_af_count != 0
11601 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11602
11603 mode = "Restart";
11604 }
11605 }
11606
11607 if (use_json) {
11608 json_object_string_add(json, "remoteGrMode", mode);
11609 } else
11610 vty_out(vty, mode, "\n");
11611 }
11612
11613 static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
11614 struct peer *p,
11615 bool use_json,
11616 json_object *json)
11617 {
11618 const char *mode = "Invalid";
11619
11620 if (!use_json)
11621 vty_out(vty, " Local GR Mode: ");
11622
11623 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
11624 mode = "Helper";
11625 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
11626 mode = "Restart";
11627 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
11628 mode = "Disable";
11629 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
11630 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
11631 mode = "Helper*";
11632 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
11633 mode = "Restart*";
11634 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
11635 mode = "Disable*";
11636 else
11637 mode = "Invalid*";
11638 }
11639
11640 if (use_json) {
11641 json_object_string_add(json, "localGrMode", mode);
11642 } else {
11643 vty_out(vty, mode, "\n");
11644 }
11645 }
11646
11647 static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
11648 struct vty *vty, struct peer *peer, bool use_json, json_object *json)
11649 {
11650 afi_t afi;
11651 safi_t safi;
11652 json_object *json_afi_safi = NULL;
11653 json_object *json_timer = NULL;
11654 json_object *json_endofrib_status = NULL;
11655 bool eor_flag = false;
11656
11657 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
11658 for (safi = SAFI_UNICAST; safi <= SAFI_MPLS_VPN; safi++) {
11659 if (!peer->afc[afi][safi])
11660 continue;
11661
11662 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
11663 || !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
11664 continue;
11665
11666 if (use_json) {
11667 json_afi_safi = json_object_new_object();
11668 json_endofrib_status = json_object_new_object();
11669 json_timer = json_object_new_object();
11670 }
11671
11672 if (peer->eor_stime[afi][safi]
11673 >= peer->pkt_stime[afi][safi])
11674 eor_flag = true;
11675 else
11676 eor_flag = false;
11677
11678 if (!use_json) {
11679 vty_out(vty, " %s:\n",
11680 get_afi_safi_str(afi, safi, false));
11681
11682 vty_out(vty, " F bit: ");
11683 }
11684
11685 if (peer->nsf[afi][safi]
11686 && CHECK_FLAG(peer->af_cap[afi][safi],
11687 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
11688
11689 if (use_json) {
11690 json_object_boolean_true_add(
11691 json_afi_safi, "fBit");
11692 } else
11693 vty_out(vty, "True\n");
11694 } else {
11695 if (use_json)
11696 json_object_boolean_false_add(
11697 json_afi_safi, "fBit");
11698 else
11699 vty_out(vty, "False\n");
11700 }
11701
11702 if (!use_json)
11703 vty_out(vty, " End-of-RIB sent: ");
11704
11705 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11706 PEER_STATUS_EOR_SEND)) {
11707 if (use_json) {
11708 json_object_boolean_true_add(
11709 json_endofrib_status,
11710 "endOfRibSend");
11711
11712 PRINT_EOR_JSON(eor_flag);
11713 } else {
11714 vty_out(vty, "Yes\n");
11715 vty_out(vty,
11716 " End-of-RIB sent after update: ");
11717
11718 PRINT_EOR(eor_flag);
11719 }
11720 } else {
11721 if (use_json) {
11722 json_object_boolean_false_add(
11723 json_endofrib_status,
11724 "endOfRibSend");
11725 json_object_boolean_false_add(
11726 json_endofrib_status,
11727 "endOfRibSentAfterUpdate");
11728 } else {
11729 vty_out(vty, "No\n");
11730 vty_out(vty,
11731 " End-of-RIB sent after update: ");
11732 vty_out(vty, "No\n");
11733 }
11734 }
11735
11736 if (!use_json)
11737 vty_out(vty, " End-of-RIB received: ");
11738
11739 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11740 PEER_STATUS_EOR_RECEIVED)) {
11741 if (use_json)
11742 json_object_boolean_true_add(
11743 json_endofrib_status,
11744 "endOfRibRecv");
11745 else
11746 vty_out(vty, "Yes\n");
11747 } else {
11748 if (use_json)
11749 json_object_boolean_false_add(
11750 json_endofrib_status,
11751 "endOfRibRecv");
11752 else
11753 vty_out(vty, "No\n");
11754 }
11755
11756 if (use_json) {
11757 json_object_int_add(json_timer,
11758 "stalePathTimer",
11759 peer->bgp->stalepath_time);
11760
11761 if (peer->t_gr_stale != NULL) {
11762 json_object_int_add(
11763 json_timer,
11764 "stalePathTimerRemaining",
11765 thread_timer_remain_second(
11766 peer->t_gr_stale));
11767 }
11768
11769 /* Display Configured Selection
11770 * Deferral only when when
11771 * Gr mode is enabled.
11772 */
11773 if (CHECK_FLAG(peer->flags,
11774 PEER_FLAG_GRACEFUL_RESTART)) {
11775 json_object_int_add(
11776 json_timer,
11777 "selectionDeferralTimer",
11778 peer->bgp->stalepath_time);
11779 }
11780
11781 if (peer->bgp->gr_info[afi][safi]
11782 .t_select_deferral
11783 != NULL) {
11784
11785 json_object_int_add(
11786 json_timer,
11787 "selectionDeferralTimerRemaining",
11788 thread_timer_remain_second(
11789 peer->bgp
11790 ->gr_info[afi]
11791 [safi]
11792 .t_select_deferral));
11793 }
11794 } else {
11795 vty_out(vty, " Timers:\n");
11796 vty_out(vty,
11797 " Configured Stale Path Time(sec): %u\n",
11798 peer->bgp->stalepath_time);
11799
11800 if (peer->t_gr_stale != NULL)
11801 vty_out(vty,
11802 " Stale Path Remaining(sec): %ld\n",
11803 thread_timer_remain_second(
11804 peer->t_gr_stale));
11805 /* Display Configured Selection
11806 * Deferral only when when
11807 * Gr mode is enabled.
11808 */
11809 if (CHECK_FLAG(peer->flags,
11810 PEER_FLAG_GRACEFUL_RESTART))
11811 vty_out(vty,
11812 " Configured Selection Deferral Time(sec): %u\n",
11813 peer->bgp->select_defer_time);
11814
11815 if (peer->bgp->gr_info[afi][safi]
11816 .t_select_deferral
11817 != NULL)
11818 vty_out(vty,
11819 " Selection Deferral Time Remaining(sec): %ld\n",
11820 thread_timer_remain_second(
11821 peer->bgp
11822 ->gr_info[afi]
11823 [safi]
11824 .t_select_deferral));
11825 }
11826 if (use_json) {
11827 json_object_object_add(json_afi_safi,
11828 "endOfRibStatus",
11829 json_endofrib_status);
11830 json_object_object_add(json_afi_safi, "timers",
11831 json_timer);
11832 json_object_object_add(
11833 json, get_afi_safi_str(afi, safi, true),
11834 json_afi_safi);
11835 }
11836 }
11837 }
11838 }
11839
11840 static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
11841 struct peer *p,
11842 bool use_json,
11843 json_object *json)
11844 {
11845 if (use_json) {
11846 json_object *json_timer = NULL;
11847
11848 json_timer = json_object_new_object();
11849
11850 json_object_int_add(json_timer, "configuredRestartTimer",
11851 p->bgp->restart_time);
11852
11853 json_object_int_add(json_timer, "receivedRestartTimer",
11854 p->v_gr_restart);
11855
11856 if (p->t_gr_restart != NULL)
11857 json_object_int_add(
11858 json_timer, "restartTimerRemaining",
11859 thread_timer_remain_second(p->t_gr_restart));
11860
11861 json_object_object_add(json, "timers", json_timer);
11862 } else {
11863
11864 vty_out(vty, " Timers:\n");
11865 vty_out(vty, " Configured Restart Time(sec): %u\n",
11866 p->bgp->restart_time);
11867
11868 vty_out(vty, " Received Restart Time(sec): %u\n",
11869 p->v_gr_restart);
11870 if (p->t_gr_restart != NULL)
11871 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
11872 thread_timer_remain_second(p->t_gr_restart));
11873 if (p->t_gr_restart != NULL) {
11874 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
11875 thread_timer_remain_second(p->t_gr_restart));
11876 }
11877 }
11878 }
11879
11880 static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
11881 bool use_json, json_object *json)
11882 {
11883 char buf[SU_ADDRSTRLEN] = {0};
11884 char dn_flag[2] = {0};
11885 /* '*' + v6 address of neighbor */
11886 char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
11887
11888 if (!p->conf_if && peer_dynamic_neighbor(p))
11889 dn_flag[0] = '*';
11890
11891 if (p->conf_if) {
11892 if (use_json)
11893 json_object_string_add(
11894 json, "neighborAddr",
11895 BGP_PEER_SU_UNSPEC(p)
11896 ? "none"
11897 : sockunion2str(&p->su, buf,
11898 SU_ADDRSTRLEN));
11899 else
11900 vty_out(vty, "BGP neighbor on %s: %s\n", p->conf_if,
11901 BGP_PEER_SU_UNSPEC(p)
11902 ? "none"
11903 : sockunion2str(&p->su, buf,
11904 SU_ADDRSTRLEN));
11905 } else {
11906 snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
11907 p->host);
11908
11909 if (use_json)
11910 json_object_string_add(json, "neighborAddr",
11911 neighborAddr);
11912 else
11913 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
11914 }
11915
11916 /* more gr info in new format */
11917 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json);
11918 }
11919
11920 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
11921 safi_t safi, bool use_json,
11922 json_object *json_neigh)
11923 {
11924 struct bgp_filter *filter;
11925 struct peer_af *paf;
11926 char orf_pfx_name[BUFSIZ];
11927 int orf_pfx_count;
11928 json_object *json_af = NULL;
11929 json_object *json_prefA = NULL;
11930 json_object *json_prefB = NULL;
11931 json_object *json_addr = NULL;
11932 json_object *json_advmap = NULL;
11933
11934 if (use_json) {
11935 json_addr = json_object_new_object();
11936 json_af = json_object_new_object();
11937 filter = &p->filter[afi][safi];
11938
11939 if (peer_group_active(p))
11940 json_object_string_add(json_addr, "peerGroupMember",
11941 p->group->name);
11942
11943 paf = peer_af_find(p, afi, safi);
11944 if (paf && PAF_SUBGRP(paf)) {
11945 json_object_int_add(json_addr, "updateGroupId",
11946 PAF_UPDGRP(paf)->id);
11947 json_object_int_add(json_addr, "subGroupId",
11948 PAF_SUBGRP(paf)->id);
11949 json_object_int_add(json_addr, "packetQueueLength",
11950 bpacket_queue_virtual_length(paf));
11951 }
11952
11953 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11954 || CHECK_FLAG(p->af_cap[afi][safi],
11955 PEER_CAP_ORF_PREFIX_SM_RCV)
11956 || CHECK_FLAG(p->af_cap[afi][safi],
11957 PEER_CAP_ORF_PREFIX_RM_ADV)
11958 || CHECK_FLAG(p->af_cap[afi][safi],
11959 PEER_CAP_ORF_PREFIX_RM_RCV)) {
11960 json_object_int_add(json_af, "orfType",
11961 ORF_TYPE_PREFIX);
11962 json_prefA = json_object_new_object();
11963 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
11964 PEER_CAP_ORF_PREFIX_SM_ADV,
11965 PEER_CAP_ORF_PREFIX_RM_ADV,
11966 PEER_CAP_ORF_PREFIX_SM_RCV,
11967 PEER_CAP_ORF_PREFIX_RM_RCV,
11968 use_json, json_prefA);
11969 json_object_object_add(json_af, "orfPrefixList",
11970 json_prefA);
11971 }
11972
11973 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11974 || CHECK_FLAG(p->af_cap[afi][safi],
11975 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11976 || CHECK_FLAG(p->af_cap[afi][safi],
11977 PEER_CAP_ORF_PREFIX_RM_ADV)
11978 || CHECK_FLAG(p->af_cap[afi][safi],
11979 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
11980 json_object_int_add(json_af, "orfOldType",
11981 ORF_TYPE_PREFIX_OLD);
11982 json_prefB = json_object_new_object();
11983 bgp_show_peer_afi_orf_cap(
11984 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
11985 PEER_CAP_ORF_PREFIX_RM_ADV,
11986 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
11987 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
11988 json_prefB);
11989 json_object_object_add(json_af, "orfOldPrefixList",
11990 json_prefB);
11991 }
11992
11993 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11994 || CHECK_FLAG(p->af_cap[afi][safi],
11995 PEER_CAP_ORF_PREFIX_SM_RCV)
11996 || CHECK_FLAG(p->af_cap[afi][safi],
11997 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11998 || CHECK_FLAG(p->af_cap[afi][safi],
11999 PEER_CAP_ORF_PREFIX_RM_ADV)
12000 || CHECK_FLAG(p->af_cap[afi][safi],
12001 PEER_CAP_ORF_PREFIX_RM_RCV)
12002 || CHECK_FLAG(p->af_cap[afi][safi],
12003 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12004 json_object_object_add(json_addr, "afDependentCap",
12005 json_af);
12006 else
12007 json_object_free(json_af);
12008
12009 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12010 p->host, afi, safi);
12011 orf_pfx_count = prefix_bgp_show_prefix_list(
12012 NULL, afi, orf_pfx_name, use_json);
12013
12014 if (CHECK_FLAG(p->af_sflags[afi][safi],
12015 PEER_STATUS_ORF_PREFIX_SEND)
12016 || orf_pfx_count) {
12017 if (CHECK_FLAG(p->af_sflags[afi][safi],
12018 PEER_STATUS_ORF_PREFIX_SEND))
12019 json_object_boolean_true_add(json_neigh,
12020 "orfSent");
12021 if (orf_pfx_count)
12022 json_object_int_add(json_addr, "orfRecvCounter",
12023 orf_pfx_count);
12024 }
12025 if (CHECK_FLAG(p->af_sflags[afi][safi],
12026 PEER_STATUS_ORF_WAIT_REFRESH))
12027 json_object_string_add(
12028 json_addr, "orfFirstUpdate",
12029 "deferredUntilORFOrRouteRefreshRecvd");
12030
12031 if (CHECK_FLAG(p->af_flags[afi][safi],
12032 PEER_FLAG_REFLECTOR_CLIENT))
12033 json_object_boolean_true_add(json_addr,
12034 "routeReflectorClient");
12035 if (CHECK_FLAG(p->af_flags[afi][safi],
12036 PEER_FLAG_RSERVER_CLIENT))
12037 json_object_boolean_true_add(json_addr,
12038 "routeServerClient");
12039 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12040 json_object_boolean_true_add(json_addr,
12041 "inboundSoftConfigPermit");
12042
12043 if (CHECK_FLAG(p->af_flags[afi][safi],
12044 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12045 json_object_boolean_true_add(
12046 json_addr,
12047 "privateAsNumsAllReplacedInUpdatesToNbr");
12048 else if (CHECK_FLAG(p->af_flags[afi][safi],
12049 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12050 json_object_boolean_true_add(
12051 json_addr,
12052 "privateAsNumsReplacedInUpdatesToNbr");
12053 else if (CHECK_FLAG(p->af_flags[afi][safi],
12054 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12055 json_object_boolean_true_add(
12056 json_addr,
12057 "privateAsNumsAllRemovedInUpdatesToNbr");
12058 else if (CHECK_FLAG(p->af_flags[afi][safi],
12059 PEER_FLAG_REMOVE_PRIVATE_AS))
12060 json_object_boolean_true_add(
12061 json_addr,
12062 "privateAsNumsRemovedInUpdatesToNbr");
12063
12064 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12065 json_object_boolean_true_add(
12066 json_addr,
12067 bgp_addpath_names(p->addpath_type[afi][safi])
12068 ->type_json_name);
12069
12070 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12071 json_object_string_add(json_addr,
12072 "overrideASNsInOutboundUpdates",
12073 "ifAspathEqualRemoteAs");
12074
12075 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12076 || CHECK_FLAG(p->af_flags[afi][safi],
12077 PEER_FLAG_FORCE_NEXTHOP_SELF))
12078 json_object_boolean_true_add(json_addr,
12079 "routerAlwaysNextHop");
12080 if (CHECK_FLAG(p->af_flags[afi][safi],
12081 PEER_FLAG_AS_PATH_UNCHANGED))
12082 json_object_boolean_true_add(
12083 json_addr, "unchangedAsPathPropogatedToNbr");
12084 if (CHECK_FLAG(p->af_flags[afi][safi],
12085 PEER_FLAG_NEXTHOP_UNCHANGED))
12086 json_object_boolean_true_add(
12087 json_addr, "unchangedNextHopPropogatedToNbr");
12088 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12089 json_object_boolean_true_add(
12090 json_addr, "unchangedMedPropogatedToNbr");
12091 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12092 || CHECK_FLAG(p->af_flags[afi][safi],
12093 PEER_FLAG_SEND_EXT_COMMUNITY)) {
12094 if (CHECK_FLAG(p->af_flags[afi][safi],
12095 PEER_FLAG_SEND_COMMUNITY)
12096 && CHECK_FLAG(p->af_flags[afi][safi],
12097 PEER_FLAG_SEND_EXT_COMMUNITY))
12098 json_object_string_add(json_addr,
12099 "commAttriSentToNbr",
12100 "extendedAndStandard");
12101 else if (CHECK_FLAG(p->af_flags[afi][safi],
12102 PEER_FLAG_SEND_EXT_COMMUNITY))
12103 json_object_string_add(json_addr,
12104 "commAttriSentToNbr",
12105 "extended");
12106 else
12107 json_object_string_add(json_addr,
12108 "commAttriSentToNbr",
12109 "standard");
12110 }
12111 if (CHECK_FLAG(p->af_flags[afi][safi],
12112 PEER_FLAG_DEFAULT_ORIGINATE)) {
12113 if (p->default_rmap[afi][safi].name)
12114 json_object_string_add(
12115 json_addr, "defaultRouteMap",
12116 p->default_rmap[afi][safi].name);
12117
12118 if (paf && PAF_SUBGRP(paf)
12119 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12120 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12121 json_object_boolean_true_add(json_addr,
12122 "defaultSent");
12123 else
12124 json_object_boolean_true_add(json_addr,
12125 "defaultNotSent");
12126 }
12127
12128 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
12129 if (is_evpn_enabled())
12130 json_object_boolean_true_add(
12131 json_addr, "advertiseAllVnis");
12132 }
12133
12134 if (filter->plist[FILTER_IN].name
12135 || filter->dlist[FILTER_IN].name
12136 || filter->aslist[FILTER_IN].name
12137 || filter->map[RMAP_IN].name)
12138 json_object_boolean_true_add(json_addr,
12139 "inboundPathPolicyConfig");
12140 if (filter->plist[FILTER_OUT].name
12141 || filter->dlist[FILTER_OUT].name
12142 || filter->aslist[FILTER_OUT].name
12143 || filter->map[RMAP_OUT].name || filter->usmap.name)
12144 json_object_boolean_true_add(
12145 json_addr, "outboundPathPolicyConfig");
12146
12147 /* prefix-list */
12148 if (filter->plist[FILTER_IN].name)
12149 json_object_string_add(json_addr,
12150 "incomingUpdatePrefixFilterList",
12151 filter->plist[FILTER_IN].name);
12152 if (filter->plist[FILTER_OUT].name)
12153 json_object_string_add(json_addr,
12154 "outgoingUpdatePrefixFilterList",
12155 filter->plist[FILTER_OUT].name);
12156
12157 /* distribute-list */
12158 if (filter->dlist[FILTER_IN].name)
12159 json_object_string_add(
12160 json_addr, "incomingUpdateNetworkFilterList",
12161 filter->dlist[FILTER_IN].name);
12162 if (filter->dlist[FILTER_OUT].name)
12163 json_object_string_add(
12164 json_addr, "outgoingUpdateNetworkFilterList",
12165 filter->dlist[FILTER_OUT].name);
12166
12167 /* filter-list. */
12168 if (filter->aslist[FILTER_IN].name)
12169 json_object_string_add(json_addr,
12170 "incomingUpdateAsPathFilterList",
12171 filter->aslist[FILTER_IN].name);
12172 if (filter->aslist[FILTER_OUT].name)
12173 json_object_string_add(json_addr,
12174 "outgoingUpdateAsPathFilterList",
12175 filter->aslist[FILTER_OUT].name);
12176
12177 /* route-map. */
12178 if (filter->map[RMAP_IN].name)
12179 json_object_string_add(
12180 json_addr, "routeMapForIncomingAdvertisements",
12181 filter->map[RMAP_IN].name);
12182 if (filter->map[RMAP_OUT].name)
12183 json_object_string_add(
12184 json_addr, "routeMapForOutgoingAdvertisements",
12185 filter->map[RMAP_OUT].name);
12186
12187 /* ebgp-requires-policy (inbound) */
12188 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12189 && !bgp_inbound_policy_exists(p, filter))
12190 json_object_string_add(
12191 json_addr, "inboundEbgpRequiresPolicy",
12192 "Inbound updates discarded due to missing policy");
12193
12194 /* ebgp-requires-policy (outbound) */
12195 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12196 && (!bgp_outbound_policy_exists(p, filter)))
12197 json_object_string_add(
12198 json_addr, "outboundEbgpRequiresPolicy",
12199 "Outbound updates discarded due to missing policy");
12200
12201 /* unsuppress-map */
12202 if (filter->usmap.name)
12203 json_object_string_add(json_addr,
12204 "selectiveUnsuppressRouteMap",
12205 filter->usmap.name);
12206
12207 /* advertise-map */
12208 if (filter->advmap.aname) {
12209 json_advmap = json_object_new_object();
12210 json_object_string_add(json_advmap, "condition",
12211 filter->advmap.condition
12212 ? "EXIST"
12213 : "NON_EXIST");
12214 json_object_string_add(json_advmap, "conditionMap",
12215 filter->advmap.cname);
12216 json_object_string_add(json_advmap, "advertiseMap",
12217 filter->advmap.aname);
12218 json_object_string_add(json_advmap, "advertiseStatus",
12219 filter->advmap.update_type
12220 == ADVERTISE
12221 ? "Advertise"
12222 : "Withdraw");
12223 json_object_object_add(json_addr, "advertiseMap",
12224 json_advmap);
12225 }
12226
12227 /* Receive prefix count */
12228 json_object_int_add(json_addr, "acceptedPrefixCounter",
12229 p->pcount[afi][safi]);
12230 if (paf && PAF_SUBGRP(paf))
12231 json_object_int_add(json_addr, "sentPrefixCounter",
12232 (PAF_SUBGRP(paf))->scount);
12233
12234 /* Maximum prefix */
12235 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
12236 json_object_int_add(json_addr, "prefixOutAllowedMax",
12237 p->pmax_out[afi][safi]);
12238
12239 /* Maximum prefix */
12240 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12241 json_object_int_add(json_addr, "prefixAllowedMax",
12242 p->pmax[afi][safi]);
12243 if (CHECK_FLAG(p->af_flags[afi][safi],
12244 PEER_FLAG_MAX_PREFIX_WARNING))
12245 json_object_boolean_true_add(
12246 json_addr, "prefixAllowedMaxWarning");
12247 json_object_int_add(json_addr,
12248 "prefixAllowedWarningThresh",
12249 p->pmax_threshold[afi][safi]);
12250 if (p->pmax_restart[afi][safi])
12251 json_object_int_add(
12252 json_addr,
12253 "prefixAllowedRestartIntervalMsecs",
12254 p->pmax_restart[afi][safi] * 60000);
12255 }
12256 json_object_object_add(json_neigh,
12257 get_afi_safi_str(afi, safi, true),
12258 json_addr);
12259
12260 } else {
12261 filter = &p->filter[afi][safi];
12262
12263 vty_out(vty, " For address family: %s\n",
12264 get_afi_safi_str(afi, safi, false));
12265
12266 if (peer_group_active(p))
12267 vty_out(vty, " %s peer-group member\n",
12268 p->group->name);
12269
12270 paf = peer_af_find(p, afi, safi);
12271 if (paf && PAF_SUBGRP(paf)) {
12272 vty_out(vty, " Update group %" PRIu64", subgroup %" PRIu64 "\n",
12273 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
12274 vty_out(vty, " Packet Queue length %d\n",
12275 bpacket_queue_virtual_length(paf));
12276 } else {
12277 vty_out(vty, " Not part of any update group\n");
12278 }
12279 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12280 || CHECK_FLAG(p->af_cap[afi][safi],
12281 PEER_CAP_ORF_PREFIX_SM_RCV)
12282 || CHECK_FLAG(p->af_cap[afi][safi],
12283 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12284 || CHECK_FLAG(p->af_cap[afi][safi],
12285 PEER_CAP_ORF_PREFIX_RM_ADV)
12286 || CHECK_FLAG(p->af_cap[afi][safi],
12287 PEER_CAP_ORF_PREFIX_RM_RCV)
12288 || CHECK_FLAG(p->af_cap[afi][safi],
12289 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12290 vty_out(vty, " AF-dependant capabilities:\n");
12291
12292 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12293 || CHECK_FLAG(p->af_cap[afi][safi],
12294 PEER_CAP_ORF_PREFIX_SM_RCV)
12295 || CHECK_FLAG(p->af_cap[afi][safi],
12296 PEER_CAP_ORF_PREFIX_RM_ADV)
12297 || CHECK_FLAG(p->af_cap[afi][safi],
12298 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12299 vty_out(vty,
12300 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12301 ORF_TYPE_PREFIX);
12302 bgp_show_peer_afi_orf_cap(
12303 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12304 PEER_CAP_ORF_PREFIX_RM_ADV,
12305 PEER_CAP_ORF_PREFIX_SM_RCV,
12306 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
12307 }
12308 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12309 || CHECK_FLAG(p->af_cap[afi][safi],
12310 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12311 || CHECK_FLAG(p->af_cap[afi][safi],
12312 PEER_CAP_ORF_PREFIX_RM_ADV)
12313 || CHECK_FLAG(p->af_cap[afi][safi],
12314 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12315 vty_out(vty,
12316 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12317 ORF_TYPE_PREFIX_OLD);
12318 bgp_show_peer_afi_orf_cap(
12319 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12320 PEER_CAP_ORF_PREFIX_RM_ADV,
12321 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12322 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
12323 }
12324
12325 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12326 p->host, afi, safi);
12327 orf_pfx_count = prefix_bgp_show_prefix_list(
12328 NULL, afi, orf_pfx_name, use_json);
12329
12330 if (CHECK_FLAG(p->af_sflags[afi][safi],
12331 PEER_STATUS_ORF_PREFIX_SEND)
12332 || orf_pfx_count) {
12333 vty_out(vty, " Outbound Route Filter (ORF):");
12334 if (CHECK_FLAG(p->af_sflags[afi][safi],
12335 PEER_STATUS_ORF_PREFIX_SEND))
12336 vty_out(vty, " sent;");
12337 if (orf_pfx_count)
12338 vty_out(vty, " received (%d entries)",
12339 orf_pfx_count);
12340 vty_out(vty, "\n");
12341 }
12342 if (CHECK_FLAG(p->af_sflags[afi][safi],
12343 PEER_STATUS_ORF_WAIT_REFRESH))
12344 vty_out(vty,
12345 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
12346
12347 if (CHECK_FLAG(p->af_flags[afi][safi],
12348 PEER_FLAG_REFLECTOR_CLIENT))
12349 vty_out(vty, " Route-Reflector Client\n");
12350 if (CHECK_FLAG(p->af_flags[afi][safi],
12351 PEER_FLAG_RSERVER_CLIENT))
12352 vty_out(vty, " Route-Server Client\n");
12353 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12354 vty_out(vty,
12355 " Inbound soft reconfiguration allowed\n");
12356
12357 if (CHECK_FLAG(p->af_flags[afi][safi],
12358 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12359 vty_out(vty,
12360 " Private AS numbers (all) replaced in updates to this neighbor\n");
12361 else if (CHECK_FLAG(p->af_flags[afi][safi],
12362 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12363 vty_out(vty,
12364 " Private AS numbers replaced in updates to this neighbor\n");
12365 else if (CHECK_FLAG(p->af_flags[afi][safi],
12366 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12367 vty_out(vty,
12368 " Private AS numbers (all) removed in updates to this neighbor\n");
12369 else if (CHECK_FLAG(p->af_flags[afi][safi],
12370 PEER_FLAG_REMOVE_PRIVATE_AS))
12371 vty_out(vty,
12372 " Private AS numbers removed in updates to this neighbor\n");
12373
12374 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12375 vty_out(vty, " %s\n",
12376 bgp_addpath_names(p->addpath_type[afi][safi])
12377 ->human_description);
12378
12379 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12380 vty_out(vty,
12381 " Override ASNs in outbound updates if aspath equals remote-as\n");
12382
12383 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12384 || CHECK_FLAG(p->af_flags[afi][safi],
12385 PEER_FLAG_FORCE_NEXTHOP_SELF))
12386 vty_out(vty, " NEXT_HOP is always this router\n");
12387 if (CHECK_FLAG(p->af_flags[afi][safi],
12388 PEER_FLAG_AS_PATH_UNCHANGED))
12389 vty_out(vty,
12390 " AS_PATH is propagated unchanged to this neighbor\n");
12391 if (CHECK_FLAG(p->af_flags[afi][safi],
12392 PEER_FLAG_NEXTHOP_UNCHANGED))
12393 vty_out(vty,
12394 " NEXT_HOP is propagated unchanged to this neighbor\n");
12395 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12396 vty_out(vty,
12397 " MED is propagated unchanged to this neighbor\n");
12398 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12399 || CHECK_FLAG(p->af_flags[afi][safi],
12400 PEER_FLAG_SEND_EXT_COMMUNITY)
12401 || CHECK_FLAG(p->af_flags[afi][safi],
12402 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
12403 vty_out(vty,
12404 " Community attribute sent to this neighbor");
12405 if (CHECK_FLAG(p->af_flags[afi][safi],
12406 PEER_FLAG_SEND_COMMUNITY)
12407 && CHECK_FLAG(p->af_flags[afi][safi],
12408 PEER_FLAG_SEND_EXT_COMMUNITY)
12409 && CHECK_FLAG(p->af_flags[afi][safi],
12410 PEER_FLAG_SEND_LARGE_COMMUNITY))
12411 vty_out(vty, "(all)\n");
12412 else if (CHECK_FLAG(p->af_flags[afi][safi],
12413 PEER_FLAG_SEND_LARGE_COMMUNITY))
12414 vty_out(vty, "(large)\n");
12415 else if (CHECK_FLAG(p->af_flags[afi][safi],
12416 PEER_FLAG_SEND_EXT_COMMUNITY))
12417 vty_out(vty, "(extended)\n");
12418 else
12419 vty_out(vty, "(standard)\n");
12420 }
12421 if (CHECK_FLAG(p->af_flags[afi][safi],
12422 PEER_FLAG_DEFAULT_ORIGINATE)) {
12423 vty_out(vty, " Default information originate,");
12424
12425 if (p->default_rmap[afi][safi].name)
12426 vty_out(vty, " default route-map %s%s,",
12427 p->default_rmap[afi][safi].map ? "*"
12428 : "",
12429 p->default_rmap[afi][safi].name);
12430 if (paf && PAF_SUBGRP(paf)
12431 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12432 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12433 vty_out(vty, " default sent\n");
12434 else
12435 vty_out(vty, " default not sent\n");
12436 }
12437
12438 /* advertise-vni-all */
12439 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
12440 if (is_evpn_enabled())
12441 vty_out(vty, " advertise-all-vni\n");
12442 }
12443
12444 if (filter->plist[FILTER_IN].name
12445 || filter->dlist[FILTER_IN].name
12446 || filter->aslist[FILTER_IN].name
12447 || filter->map[RMAP_IN].name)
12448 vty_out(vty, " Inbound path policy configured\n");
12449 if (filter->plist[FILTER_OUT].name
12450 || filter->dlist[FILTER_OUT].name
12451 || filter->aslist[FILTER_OUT].name
12452 || filter->map[RMAP_OUT].name || filter->usmap.name)
12453 vty_out(vty, " Outbound path policy configured\n");
12454
12455 /* prefix-list */
12456 if (filter->plist[FILTER_IN].name)
12457 vty_out(vty,
12458 " Incoming update prefix filter list is %s%s\n",
12459 filter->plist[FILTER_IN].plist ? "*" : "",
12460 filter->plist[FILTER_IN].name);
12461 if (filter->plist[FILTER_OUT].name)
12462 vty_out(vty,
12463 " Outgoing update prefix filter list is %s%s\n",
12464 filter->plist[FILTER_OUT].plist ? "*" : "",
12465 filter->plist[FILTER_OUT].name);
12466
12467 /* distribute-list */
12468 if (filter->dlist[FILTER_IN].name)
12469 vty_out(vty,
12470 " Incoming update network filter list is %s%s\n",
12471 filter->dlist[FILTER_IN].alist ? "*" : "",
12472 filter->dlist[FILTER_IN].name);
12473 if (filter->dlist[FILTER_OUT].name)
12474 vty_out(vty,
12475 " Outgoing update network filter list is %s%s\n",
12476 filter->dlist[FILTER_OUT].alist ? "*" : "",
12477 filter->dlist[FILTER_OUT].name);
12478
12479 /* filter-list. */
12480 if (filter->aslist[FILTER_IN].name)
12481 vty_out(vty,
12482 " Incoming update AS path filter list is %s%s\n",
12483 filter->aslist[FILTER_IN].aslist ? "*" : "",
12484 filter->aslist[FILTER_IN].name);
12485 if (filter->aslist[FILTER_OUT].name)
12486 vty_out(vty,
12487 " Outgoing update AS path filter list is %s%s\n",
12488 filter->aslist[FILTER_OUT].aslist ? "*" : "",
12489 filter->aslist[FILTER_OUT].name);
12490
12491 /* route-map. */
12492 if (filter->map[RMAP_IN].name)
12493 vty_out(vty,
12494 " Route map for incoming advertisements is %s%s\n",
12495 filter->map[RMAP_IN].map ? "*" : "",
12496 filter->map[RMAP_IN].name);
12497 if (filter->map[RMAP_OUT].name)
12498 vty_out(vty,
12499 " Route map for outgoing advertisements is %s%s\n",
12500 filter->map[RMAP_OUT].map ? "*" : "",
12501 filter->map[RMAP_OUT].name);
12502
12503 /* ebgp-requires-policy (inbound) */
12504 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12505 && !bgp_inbound_policy_exists(p, filter))
12506 vty_out(vty,
12507 " Inbound updates discarded due to missing policy\n");
12508
12509 /* ebgp-requires-policy (outbound) */
12510 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12511 && !bgp_outbound_policy_exists(p, filter))
12512 vty_out(vty,
12513 " Outbound updates discarded due to missing policy\n");
12514
12515 /* unsuppress-map */
12516 if (filter->usmap.name)
12517 vty_out(vty,
12518 " Route map for selective unsuppress is %s%s\n",
12519 filter->usmap.map ? "*" : "",
12520 filter->usmap.name);
12521
12522 /* advertise-map */
12523 if (filter->advmap.aname && filter->advmap.cname)
12524 vty_out(vty,
12525 " Condition %s, Condition-map %s%s, Advertise-map %s%s, status: %s\n",
12526 filter->advmap.condition ? "EXIST"
12527 : "NON_EXIST",
12528 filter->advmap.cmap ? "*" : "",
12529 filter->advmap.cname,
12530 filter->advmap.amap ? "*" : "",
12531 filter->advmap.aname,
12532 filter->advmap.update_type == ADVERTISE
12533 ? "Advertise"
12534 : "Withdraw");
12535
12536 /* Receive prefix count */
12537 vty_out(vty, " %u accepted prefixes\n",
12538 p->pcount[afi][safi]);
12539
12540 /* maximum-prefix-out */
12541 if (CHECK_FLAG(p->af_flags[afi][safi],
12542 PEER_FLAG_MAX_PREFIX_OUT))
12543 vty_out(vty,
12544 " Maximum allowed prefixes sent %u\n",
12545 p->pmax_out[afi][safi]);
12546
12547 /* Maximum prefix */
12548 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12549 vty_out(vty,
12550 " Maximum prefixes allowed %u%s\n",
12551 p->pmax[afi][safi],
12552 CHECK_FLAG(p->af_flags[afi][safi],
12553 PEER_FLAG_MAX_PREFIX_WARNING)
12554 ? " (warning-only)"
12555 : "");
12556 vty_out(vty, " Threshold for warning message %d%%",
12557 p->pmax_threshold[afi][safi]);
12558 if (p->pmax_restart[afi][safi])
12559 vty_out(vty, ", restart interval %d min",
12560 p->pmax_restart[afi][safi]);
12561 vty_out(vty, "\n");
12562 }
12563
12564 vty_out(vty, "\n");
12565 }
12566 }
12567
12568 static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
12569 json_object *json)
12570 {
12571 struct bgp *bgp;
12572 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
12573 char timebuf[BGP_UPTIME_LEN];
12574 char dn_flag[2];
12575 afi_t afi;
12576 safi_t safi;
12577 uint16_t i;
12578 uint8_t *msg;
12579 json_object *json_neigh = NULL;
12580 time_t epoch_tbuf;
12581
12582 bgp = p->bgp;
12583
12584 if (use_json)
12585 json_neigh = json_object_new_object();
12586
12587 memset(dn_flag, '\0', sizeof(dn_flag));
12588 if (!p->conf_if && peer_dynamic_neighbor(p))
12589 dn_flag[0] = '*';
12590
12591 if (!use_json) {
12592 if (p->conf_if) /* Configured interface name. */
12593 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
12594 BGP_PEER_SU_UNSPEC(p)
12595 ? "None"
12596 : sockunion2str(&p->su, buf,
12597 SU_ADDRSTRLEN));
12598 else /* Configured IP address. */
12599 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
12600 p->host);
12601 }
12602
12603 if (use_json) {
12604 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
12605 json_object_string_add(json_neigh, "bgpNeighborAddr",
12606 "none");
12607 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
12608 json_object_string_add(
12609 json_neigh, "bgpNeighborAddr",
12610 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
12611
12612 json_object_int_add(json_neigh, "remoteAs", p->as);
12613
12614 if (p->change_local_as)
12615 json_object_int_add(json_neigh, "localAs",
12616 p->change_local_as);
12617 else
12618 json_object_int_add(json_neigh, "localAs", p->local_as);
12619
12620 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
12621 json_object_boolean_true_add(json_neigh,
12622 "localAsNoPrepend");
12623
12624 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
12625 json_object_boolean_true_add(json_neigh,
12626 "localAsReplaceAs");
12627 } else {
12628 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
12629 || (p->as_type == AS_INTERNAL))
12630 vty_out(vty, "remote AS %u, ", p->as);
12631 else
12632 vty_out(vty, "remote AS Unspecified, ");
12633 vty_out(vty, "local AS %u%s%s, ",
12634 p->change_local_as ? p->change_local_as : p->local_as,
12635 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
12636 ? " no-prepend"
12637 : "",
12638 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
12639 ? " replace-as"
12640 : "");
12641 }
12642 /* peer type internal or confed-internal */
12643 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
12644 if (use_json) {
12645 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12646 json_object_boolean_true_add(
12647 json_neigh, "nbrConfedInternalLink");
12648 else
12649 json_object_boolean_true_add(json_neigh,
12650 "nbrInternalLink");
12651 } else {
12652 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12653 vty_out(vty, "confed-internal link\n");
12654 else
12655 vty_out(vty, "internal link\n");
12656 }
12657 /* peer type external or confed-external */
12658 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
12659 if (use_json) {
12660 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12661 json_object_boolean_true_add(
12662 json_neigh, "nbrConfedExternalLink");
12663 else
12664 json_object_boolean_true_add(json_neigh,
12665 "nbrExternalLink");
12666 } else {
12667 if (bgp_confederation_peers_check(bgp, p->as))
12668 vty_out(vty, "confed-external link\n");
12669 else
12670 vty_out(vty, "external link\n");
12671 }
12672 } else {
12673 if (use_json)
12674 json_object_boolean_true_add(json_neigh,
12675 "nbrUnspecifiedLink");
12676 else
12677 vty_out(vty, "unspecified link\n");
12678 }
12679
12680 /* Description. */
12681 if (p->desc) {
12682 if (use_json)
12683 json_object_string_add(json_neigh, "nbrDesc", p->desc);
12684 else
12685 vty_out(vty, " Description: %s\n", p->desc);
12686 }
12687
12688 if (p->hostname) {
12689 if (use_json) {
12690 if (p->hostname)
12691 json_object_string_add(json_neigh, "hostname",
12692 p->hostname);
12693
12694 if (p->domainname)
12695 json_object_string_add(json_neigh, "domainname",
12696 p->domainname);
12697 } else {
12698 if (p->domainname && (p->domainname[0] != '\0'))
12699 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
12700 p->domainname);
12701 else
12702 vty_out(vty, "Hostname: %s\n", p->hostname);
12703 }
12704 }
12705
12706 /* Peer-group */
12707 if (p->group) {
12708 if (use_json) {
12709 json_object_string_add(json_neigh, "peerGroup",
12710 p->group->name);
12711
12712 if (dn_flag[0]) {
12713 struct prefix prefix, *range = NULL;
12714
12715 if (sockunion2hostprefix(&(p->su), &prefix))
12716 range = peer_group_lookup_dynamic_neighbor_range(
12717 p->group, &prefix);
12718
12719 if (range) {
12720 prefix2str(range, buf1, sizeof(buf1));
12721 json_object_string_add(
12722 json_neigh,
12723 "peerSubnetRangeGroup", buf1);
12724 }
12725 }
12726 } else {
12727 vty_out(vty,
12728 " Member of peer-group %s for session parameters\n",
12729 p->group->name);
12730
12731 if (dn_flag[0]) {
12732 struct prefix prefix, *range = NULL;
12733
12734 if (sockunion2hostprefix(&(p->su), &prefix))
12735 range = peer_group_lookup_dynamic_neighbor_range(
12736 p->group, &prefix);
12737
12738 if (range) {
12739 vty_out(vty,
12740 " Belongs to the subnet range group: %pFX\n",
12741 range);
12742 }
12743 }
12744 }
12745 }
12746
12747 if (use_json) {
12748 /* Administrative shutdown. */
12749 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12750 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
12751 json_object_boolean_true_add(json_neigh,
12752 "adminShutDown");
12753
12754 /* BGP Version. */
12755 json_object_int_add(json_neigh, "bgpVersion", 4);
12756 json_object_string_add(
12757 json_neigh, "remoteRouterId",
12758 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
12759 json_object_string_add(
12760 json_neigh, "localRouterId",
12761 inet_ntop(AF_INET, &bgp->router_id, buf1,
12762 sizeof(buf1)));
12763
12764 /* Confederation */
12765 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12766 && bgp_confederation_peers_check(bgp, p->as))
12767 json_object_boolean_true_add(json_neigh,
12768 "nbrCommonAdmin");
12769
12770 /* Status. */
12771 json_object_string_add(
12772 json_neigh, "bgpState",
12773 lookup_msg(bgp_status_msg, p->status, NULL));
12774
12775 if (p->status == Established) {
12776 time_t uptime;
12777
12778 uptime = bgp_clock();
12779 uptime -= p->uptime;
12780 epoch_tbuf = time(NULL) - uptime;
12781
12782 json_object_int_add(json_neigh, "bgpTimerUpMsec",
12783 uptime * 1000);
12784 json_object_string_add(json_neigh, "bgpTimerUpString",
12785 peer_uptime(p->uptime, timebuf,
12786 BGP_UPTIME_LEN, 0,
12787 NULL));
12788 json_object_int_add(json_neigh,
12789 "bgpTimerUpEstablishedEpoch",
12790 epoch_tbuf);
12791 }
12792
12793 else if (p->status == Active) {
12794 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12795 json_object_string_add(json_neigh, "bgpStateIs",
12796 "passive");
12797 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12798 json_object_string_add(json_neigh, "bgpStateIs",
12799 "passiveNSF");
12800 }
12801
12802 /* read timer */
12803 time_t uptime;
12804 struct tm tm;
12805
12806 uptime = bgp_clock();
12807 uptime -= p->readtime;
12808 gmtime_r(&uptime, &tm);
12809
12810 json_object_int_add(json_neigh, "bgpTimerLastRead",
12811 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12812 + (tm.tm_hour * 3600000));
12813
12814 uptime = bgp_clock();
12815 uptime -= p->last_write;
12816 gmtime_r(&uptime, &tm);
12817
12818 json_object_int_add(json_neigh, "bgpTimerLastWrite",
12819 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12820 + (tm.tm_hour * 3600000));
12821
12822 uptime = bgp_clock();
12823 uptime -= p->update_time;
12824 gmtime_r(&uptime, &tm);
12825
12826 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
12827 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12828 + (tm.tm_hour * 3600000));
12829
12830 /* Configured timer values. */
12831 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
12832 p->v_holdtime * 1000);
12833 json_object_int_add(json_neigh,
12834 "bgpTimerKeepAliveIntervalMsecs",
12835 p->v_keepalive * 1000);
12836 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN)) {
12837 json_object_int_add(json_neigh,
12838 "bgpTimerDelayOpenTimeMsecs",
12839 p->v_delayopen * 1000);
12840 }
12841
12842 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
12843 json_object_int_add(json_neigh,
12844 "bgpTimerConfiguredHoldTimeMsecs",
12845 p->holdtime * 1000);
12846 json_object_int_add(
12847 json_neigh,
12848 "bgpTimerConfiguredKeepAliveIntervalMsecs",
12849 p->keepalive * 1000);
12850 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
12851 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
12852 json_object_int_add(json_neigh,
12853 "bgpTimerConfiguredHoldTimeMsecs",
12854 bgp->default_holdtime);
12855 json_object_int_add(
12856 json_neigh,
12857 "bgpTimerConfiguredKeepAliveIntervalMsecs",
12858 bgp->default_keepalive);
12859 }
12860 } else {
12861 /* Administrative shutdown. */
12862 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12863 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
12864 vty_out(vty, " Administratively shut down\n");
12865
12866 /* BGP Version. */
12867 vty_out(vty, " BGP version 4");
12868 vty_out(vty, ", remote router ID %s",
12869 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
12870 vty_out(vty, ", local router ID %s\n",
12871 inet_ntop(AF_INET, &bgp->router_id, buf1,
12872 sizeof(buf1)));
12873
12874 /* Confederation */
12875 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12876 && bgp_confederation_peers_check(bgp, p->as))
12877 vty_out(vty,
12878 " Neighbor under common administration\n");
12879
12880 /* Status. */
12881 vty_out(vty, " BGP state = %s",
12882 lookup_msg(bgp_status_msg, p->status, NULL));
12883
12884 if (p->status == Established)
12885 vty_out(vty, ", up for %8s",
12886 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
12887 0, NULL));
12888
12889 else if (p->status == Active) {
12890 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12891 vty_out(vty, " (passive)");
12892 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12893 vty_out(vty, " (NSF passive)");
12894 }
12895 vty_out(vty, "\n");
12896
12897 /* read timer */
12898 vty_out(vty, " Last read %s",
12899 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
12900 NULL));
12901 vty_out(vty, ", Last write %s\n",
12902 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
12903 NULL));
12904
12905 /* Configured timer values. */
12906 vty_out(vty,
12907 " Hold time is %d, keepalive interval is %d seconds\n",
12908 p->v_holdtime, p->v_keepalive);
12909 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
12910 vty_out(vty, " Configured hold time is %d",
12911 p->holdtime);
12912 vty_out(vty, ", keepalive interval is %d seconds\n",
12913 p->keepalive);
12914 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
12915 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
12916 vty_out(vty, " Configured hold time is %d",
12917 bgp->default_holdtime);
12918 vty_out(vty, ", keepalive interval is %d seconds\n",
12919 bgp->default_keepalive);
12920 }
12921 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN))
12922 vty_out(vty,
12923 " Configured DelayOpenTime is %d seconds\n",
12924 p->delayopen);
12925 }
12926 /* Capability. */
12927 if (p->status == Established) {
12928 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
12929 || p->afc_recv[AFI_IP][SAFI_UNICAST]
12930 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
12931 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
12932 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
12933 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
12934 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
12935 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
12936 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
12937 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
12938 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
12939 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
12940 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
12941 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
12942 || p->afc_adv[AFI_IP][SAFI_ENCAP]
12943 || p->afc_recv[AFI_IP][SAFI_ENCAP]
12944 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
12945 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
12946 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
12947 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
12948 if (use_json) {
12949 json_object *json_cap = NULL;
12950
12951 json_cap = json_object_new_object();
12952
12953 /* AS4 */
12954 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
12955 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
12956 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
12957 && CHECK_FLAG(p->cap,
12958 PEER_CAP_AS4_RCV))
12959 json_object_string_add(
12960 json_cap, "4byteAs",
12961 "advertisedAndReceived");
12962 else if (CHECK_FLAG(p->cap,
12963 PEER_CAP_AS4_ADV))
12964 json_object_string_add(
12965 json_cap, "4byteAs",
12966 "advertised");
12967 else if (CHECK_FLAG(p->cap,
12968 PEER_CAP_AS4_RCV))
12969 json_object_string_add(
12970 json_cap, "4byteAs",
12971 "received");
12972 }
12973
12974 /* Extended Message Support */
12975 if (CHECK_FLAG(p->cap,
12976 PEER_CAP_EXTENDED_MESSAGE_ADV)
12977 && CHECK_FLAG(
12978 p->cap,
12979 PEER_CAP_EXTENDED_MESSAGE_RCV))
12980 json_object_string_add(
12981 json_cap, "extendedMessage",
12982 "advertisedAndReceived");
12983 else if (CHECK_FLAG(
12984 p->cap,
12985 PEER_CAP_EXTENDED_MESSAGE_ADV))
12986 json_object_string_add(
12987 json_cap, "extendedMessage",
12988 "advertised");
12989 else if (CHECK_FLAG(
12990 p->cap,
12991 PEER_CAP_EXTENDED_MESSAGE_RCV))
12992 json_object_string_add(
12993 json_cap, "extendedMessage",
12994 "received");
12995
12996 /* AddPath */
12997 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
12998 || CHECK_FLAG(p->cap,
12999 PEER_CAP_ADDPATH_ADV)) {
13000 json_object *json_add = NULL;
13001 const char *print_store;
13002
13003 json_add = json_object_new_object();
13004
13005 FOREACH_AFI_SAFI (afi, safi) {
13006 json_object *json_sub = NULL;
13007 json_sub =
13008 json_object_new_object();
13009 print_store = get_afi_safi_str(
13010 afi, safi, true);
13011
13012 if (CHECK_FLAG(
13013 p->af_cap[afi]
13014 [safi],
13015 PEER_CAP_ADDPATH_AF_TX_ADV)
13016 || CHECK_FLAG(
13017 p->af_cap[afi]
13018 [safi],
13019 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13020 if (CHECK_FLAG(
13021 p->af_cap
13022 [afi]
13023 [safi],
13024 PEER_CAP_ADDPATH_AF_TX_ADV)
13025 && CHECK_FLAG(
13026 p->af_cap
13027 [afi]
13028 [safi],
13029 PEER_CAP_ADDPATH_AF_TX_RCV))
13030 json_object_boolean_true_add(
13031 json_sub,
13032 "txAdvertisedAndReceived");
13033 else if (
13034 CHECK_FLAG(
13035 p->af_cap
13036 [afi]
13037 [safi],
13038 PEER_CAP_ADDPATH_AF_TX_ADV))
13039 json_object_boolean_true_add(
13040 json_sub,
13041 "txAdvertised");
13042 else if (
13043 CHECK_FLAG(
13044 p->af_cap
13045 [afi]
13046 [safi],
13047 PEER_CAP_ADDPATH_AF_TX_RCV))
13048 json_object_boolean_true_add(
13049 json_sub,
13050 "txReceived");
13051 }
13052
13053 if (CHECK_FLAG(
13054 p->af_cap[afi]
13055 [safi],
13056 PEER_CAP_ADDPATH_AF_RX_ADV)
13057 || CHECK_FLAG(
13058 p->af_cap[afi]
13059 [safi],
13060 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13061 if (CHECK_FLAG(
13062 p->af_cap
13063 [afi]
13064 [safi],
13065 PEER_CAP_ADDPATH_AF_RX_ADV)
13066 && CHECK_FLAG(
13067 p->af_cap
13068 [afi]
13069 [safi],
13070 PEER_CAP_ADDPATH_AF_RX_RCV))
13071 json_object_boolean_true_add(
13072 json_sub,
13073 "rxAdvertisedAndReceived");
13074 else if (
13075 CHECK_FLAG(
13076 p->af_cap
13077 [afi]
13078 [safi],
13079 PEER_CAP_ADDPATH_AF_RX_ADV))
13080 json_object_boolean_true_add(
13081 json_sub,
13082 "rxAdvertised");
13083 else if (
13084 CHECK_FLAG(
13085 p->af_cap
13086 [afi]
13087 [safi],
13088 PEER_CAP_ADDPATH_AF_RX_RCV))
13089 json_object_boolean_true_add(
13090 json_sub,
13091 "rxReceived");
13092 }
13093
13094 if (CHECK_FLAG(
13095 p->af_cap[afi]
13096 [safi],
13097 PEER_CAP_ADDPATH_AF_TX_ADV)
13098 || CHECK_FLAG(
13099 p->af_cap[afi]
13100 [safi],
13101 PEER_CAP_ADDPATH_AF_TX_RCV)
13102 || CHECK_FLAG(
13103 p->af_cap[afi]
13104 [safi],
13105 PEER_CAP_ADDPATH_AF_RX_ADV)
13106 || CHECK_FLAG(
13107 p->af_cap[afi]
13108 [safi],
13109 PEER_CAP_ADDPATH_AF_RX_RCV))
13110 json_object_object_add(
13111 json_add,
13112 print_store,
13113 json_sub);
13114 else
13115 json_object_free(
13116 json_sub);
13117 }
13118
13119 json_object_object_add(
13120 json_cap, "addPath", json_add);
13121 }
13122
13123 /* Dynamic */
13124 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
13125 || CHECK_FLAG(p->cap,
13126 PEER_CAP_DYNAMIC_ADV)) {
13127 if (CHECK_FLAG(p->cap,
13128 PEER_CAP_DYNAMIC_ADV)
13129 && CHECK_FLAG(p->cap,
13130 PEER_CAP_DYNAMIC_RCV))
13131 json_object_string_add(
13132 json_cap, "dynamic",
13133 "advertisedAndReceived");
13134 else if (CHECK_FLAG(
13135 p->cap,
13136 PEER_CAP_DYNAMIC_ADV))
13137 json_object_string_add(
13138 json_cap, "dynamic",
13139 "advertised");
13140 else if (CHECK_FLAG(
13141 p->cap,
13142 PEER_CAP_DYNAMIC_RCV))
13143 json_object_string_add(
13144 json_cap, "dynamic",
13145 "received");
13146 }
13147
13148 /* Extended nexthop */
13149 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
13150 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13151 json_object *json_nxt = NULL;
13152 const char *print_store;
13153
13154
13155 if (CHECK_FLAG(p->cap,
13156 PEER_CAP_ENHE_ADV)
13157 && CHECK_FLAG(p->cap,
13158 PEER_CAP_ENHE_RCV))
13159 json_object_string_add(
13160 json_cap,
13161 "extendedNexthop",
13162 "advertisedAndReceived");
13163 else if (CHECK_FLAG(p->cap,
13164 PEER_CAP_ENHE_ADV))
13165 json_object_string_add(
13166 json_cap,
13167 "extendedNexthop",
13168 "advertised");
13169 else if (CHECK_FLAG(p->cap,
13170 PEER_CAP_ENHE_RCV))
13171 json_object_string_add(
13172 json_cap,
13173 "extendedNexthop",
13174 "received");
13175
13176 if (CHECK_FLAG(p->cap,
13177 PEER_CAP_ENHE_RCV)) {
13178 json_nxt =
13179 json_object_new_object();
13180
13181 for (safi = SAFI_UNICAST;
13182 safi < SAFI_MAX; safi++) {
13183 if (CHECK_FLAG(
13184 p->af_cap
13185 [AFI_IP]
13186 [safi],
13187 PEER_CAP_ENHE_AF_RCV)) {
13188 print_store = get_afi_safi_str(
13189 AFI_IP,
13190 safi, true);
13191 json_object_string_add(
13192 json_nxt,
13193 print_store,
13194 "recieved"); /* misspelled for compatibility */
13195 }
13196 }
13197 json_object_object_add(
13198 json_cap,
13199 "extendedNexthopFamililesByPeer",
13200 json_nxt);
13201 }
13202 }
13203
13204 /* Route Refresh */
13205 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
13206 || CHECK_FLAG(p->cap,
13207 PEER_CAP_REFRESH_NEW_RCV)
13208 || CHECK_FLAG(p->cap,
13209 PEER_CAP_REFRESH_OLD_RCV)) {
13210 if (CHECK_FLAG(p->cap,
13211 PEER_CAP_REFRESH_ADV)
13212 && (CHECK_FLAG(
13213 p->cap,
13214 PEER_CAP_REFRESH_NEW_RCV)
13215 || CHECK_FLAG(
13216 p->cap,
13217 PEER_CAP_REFRESH_OLD_RCV))) {
13218 if (CHECK_FLAG(
13219 p->cap,
13220 PEER_CAP_REFRESH_OLD_RCV)
13221 && CHECK_FLAG(
13222 p->cap,
13223 PEER_CAP_REFRESH_NEW_RCV))
13224 json_object_string_add(
13225 json_cap,
13226 "routeRefresh",
13227 "advertisedAndReceivedOldNew");
13228 else {
13229 if (CHECK_FLAG(
13230 p->cap,
13231 PEER_CAP_REFRESH_OLD_RCV))
13232 json_object_string_add(
13233 json_cap,
13234 "routeRefresh",
13235 "advertisedAndReceivedOld");
13236 else
13237 json_object_string_add(
13238 json_cap,
13239 "routeRefresh",
13240 "advertisedAndReceivedNew");
13241 }
13242 } else if (
13243 CHECK_FLAG(
13244 p->cap,
13245 PEER_CAP_REFRESH_ADV))
13246 json_object_string_add(
13247 json_cap,
13248 "routeRefresh",
13249 "advertised");
13250 else if (
13251 CHECK_FLAG(
13252 p->cap,
13253 PEER_CAP_REFRESH_NEW_RCV)
13254 || CHECK_FLAG(
13255 p->cap,
13256 PEER_CAP_REFRESH_OLD_RCV))
13257 json_object_string_add(
13258 json_cap,
13259 "routeRefresh",
13260 "received");
13261 }
13262
13263 /* Enhanced Route Refresh */
13264 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV)
13265 || CHECK_FLAG(p->cap,
13266 PEER_CAP_ENHANCED_RR_RCV)) {
13267 if (CHECK_FLAG(p->cap,
13268 PEER_CAP_ENHANCED_RR_ADV)
13269 && CHECK_FLAG(
13270 p->cap,
13271 PEER_CAP_ENHANCED_RR_RCV))
13272 json_object_string_add(
13273 json_cap,
13274 "enhancedRouteRefresh",
13275 "advertisedAndReceived");
13276 else if (
13277 CHECK_FLAG(
13278 p->cap,
13279 PEER_CAP_ENHANCED_RR_ADV))
13280 json_object_string_add(
13281 json_cap,
13282 "enhancedRouteRefresh",
13283 "advertised");
13284 else if (
13285 CHECK_FLAG(
13286 p->cap,
13287 PEER_CAP_ENHANCED_RR_RCV))
13288 json_object_string_add(
13289 json_cap,
13290 "enhancedRouteRefresh",
13291 "received");
13292 }
13293
13294 /* Multiprotocol Extensions */
13295 json_object *json_multi = NULL;
13296 json_multi = json_object_new_object();
13297
13298 FOREACH_AFI_SAFI (afi, safi) {
13299 if (p->afc_adv[afi][safi]
13300 || p->afc_recv[afi][safi]) {
13301 json_object *json_exten = NULL;
13302 json_exten =
13303 json_object_new_object();
13304
13305 if (p->afc_adv[afi][safi]
13306 && p->afc_recv[afi][safi])
13307 json_object_boolean_true_add(
13308 json_exten,
13309 "advertisedAndReceived");
13310 else if (p->afc_adv[afi][safi])
13311 json_object_boolean_true_add(
13312 json_exten,
13313 "advertised");
13314 else if (p->afc_recv[afi][safi])
13315 json_object_boolean_true_add(
13316 json_exten,
13317 "received");
13318
13319 json_object_object_add(
13320 json_multi,
13321 get_afi_safi_str(afi,
13322 safi,
13323 true),
13324 json_exten);
13325 }
13326 }
13327 json_object_object_add(
13328 json_cap, "multiprotocolExtensions",
13329 json_multi);
13330
13331 /* Hostname capabilities */
13332 json_object *json_hname = NULL;
13333
13334 json_hname = json_object_new_object();
13335
13336 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13337 json_object_string_add(
13338 json_hname, "advHostName",
13339 bgp->peer_self->hostname
13340 ? bgp->peer_self
13341 ->hostname
13342 : "n/a");
13343 json_object_string_add(
13344 json_hname, "advDomainName",
13345 bgp->peer_self->domainname
13346 ? bgp->peer_self
13347 ->domainname
13348 : "n/a");
13349 }
13350
13351
13352 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13353 json_object_string_add(
13354 json_hname, "rcvHostName",
13355 p->hostname ? p->hostname
13356 : "n/a");
13357 json_object_string_add(
13358 json_hname, "rcvDomainName",
13359 p->domainname ? p->domainname
13360 : "n/a");
13361 }
13362
13363 json_object_object_add(json_cap, "hostName",
13364 json_hname);
13365
13366 /* Gracefull Restart */
13367 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
13368 || CHECK_FLAG(p->cap,
13369 PEER_CAP_RESTART_ADV)) {
13370 if (CHECK_FLAG(p->cap,
13371 PEER_CAP_RESTART_ADV)
13372 && CHECK_FLAG(p->cap,
13373 PEER_CAP_RESTART_RCV))
13374 json_object_string_add(
13375 json_cap,
13376 "gracefulRestart",
13377 "advertisedAndReceived");
13378 else if (CHECK_FLAG(
13379 p->cap,
13380 PEER_CAP_RESTART_ADV))
13381 json_object_string_add(
13382 json_cap,
13383 "gracefulRestartCapability",
13384 "advertised");
13385 else if (CHECK_FLAG(
13386 p->cap,
13387 PEER_CAP_RESTART_RCV))
13388 json_object_string_add(
13389 json_cap,
13390 "gracefulRestartCapability",
13391 "received");
13392
13393 if (CHECK_FLAG(p->cap,
13394 PEER_CAP_RESTART_RCV)) {
13395 int restart_af_count = 0;
13396 json_object *json_restart =
13397 NULL;
13398 json_restart =
13399 json_object_new_object();
13400
13401 json_object_int_add(
13402 json_cap,
13403 "gracefulRestartRemoteTimerMsecs",
13404 p->v_gr_restart * 1000);
13405
13406 FOREACH_AFI_SAFI (afi, safi) {
13407 if (CHECK_FLAG(
13408 p->af_cap
13409 [afi]
13410 [safi],
13411 PEER_CAP_RESTART_AF_RCV)) {
13412 json_object *
13413 json_sub =
13414 NULL;
13415 json_sub =
13416 json_object_new_object();
13417
13418 if (CHECK_FLAG(
13419 p->af_cap
13420 [afi]
13421 [safi],
13422 PEER_CAP_RESTART_AF_PRESERVE_RCV))
13423 json_object_boolean_true_add(
13424 json_sub,
13425 "preserved");
13426 restart_af_count++;
13427 json_object_object_add(
13428 json_restart,
13429 get_afi_safi_str(
13430 afi,
13431 safi,
13432 true),
13433 json_sub);
13434 }
13435 }
13436 if (!restart_af_count) {
13437 json_object_string_add(
13438 json_cap,
13439 "addressFamiliesByPeer",
13440 "none");
13441 json_object_free(
13442 json_restart);
13443 } else
13444 json_object_object_add(
13445 json_cap,
13446 "addressFamiliesByPeer",
13447 json_restart);
13448 }
13449 }
13450 json_object_object_add(json_neigh,
13451 "neighborCapabilities",
13452 json_cap);
13453 } else {
13454 vty_out(vty, " Neighbor capabilities:\n");
13455
13456 /* AS4 */
13457 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
13458 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13459 vty_out(vty, " 4 Byte AS:");
13460 if (CHECK_FLAG(p->cap,
13461 PEER_CAP_AS4_ADV))
13462 vty_out(vty, " advertised");
13463 if (CHECK_FLAG(p->cap,
13464 PEER_CAP_AS4_RCV))
13465 vty_out(vty, " %sreceived",
13466 CHECK_FLAG(
13467 p->cap,
13468 PEER_CAP_AS4_ADV)
13469 ? "and "
13470 : "");
13471 vty_out(vty, "\n");
13472 }
13473
13474 /* Extended Message Support */
13475 if (CHECK_FLAG(p->cap,
13476 PEER_CAP_EXTENDED_MESSAGE_RCV)
13477 || CHECK_FLAG(
13478 p->cap,
13479 PEER_CAP_EXTENDED_MESSAGE_ADV)) {
13480 vty_out(vty, " Extended Message:");
13481 if (CHECK_FLAG(
13482 p->cap,
13483 PEER_CAP_EXTENDED_MESSAGE_ADV))
13484 vty_out(vty, " advertised");
13485 if (CHECK_FLAG(
13486 p->cap,
13487 PEER_CAP_EXTENDED_MESSAGE_RCV))
13488 vty_out(vty, " %sreceived",
13489 CHECK_FLAG(
13490 p->cap,
13491 PEER_CAP_EXTENDED_MESSAGE_ADV)
13492 ? "and "
13493 : "");
13494 vty_out(vty, "\n");
13495 }
13496
13497 /* AddPath */
13498 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
13499 || CHECK_FLAG(p->cap,
13500 PEER_CAP_ADDPATH_ADV)) {
13501 vty_out(vty, " AddPath:\n");
13502
13503 FOREACH_AFI_SAFI (afi, safi) {
13504 if (CHECK_FLAG(
13505 p->af_cap[afi]
13506 [safi],
13507 PEER_CAP_ADDPATH_AF_TX_ADV)
13508 || CHECK_FLAG(
13509 p->af_cap[afi]
13510 [safi],
13511 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13512 vty_out(vty,
13513 " %s: TX ",
13514 get_afi_safi_str(
13515 afi,
13516 safi,
13517 false));
13518
13519 if (CHECK_FLAG(
13520 p->af_cap
13521 [afi]
13522 [safi],
13523 PEER_CAP_ADDPATH_AF_TX_ADV))
13524 vty_out(vty,
13525 "advertised %s",
13526 get_afi_safi_str(
13527 afi,
13528 safi,
13529 false));
13530
13531 if (CHECK_FLAG(
13532 p->af_cap
13533 [afi]
13534 [safi],
13535 PEER_CAP_ADDPATH_AF_TX_RCV))
13536 vty_out(vty,
13537 "%sreceived",
13538 CHECK_FLAG(
13539 p->af_cap
13540 [afi]
13541 [safi],
13542 PEER_CAP_ADDPATH_AF_TX_ADV)
13543 ? " and "
13544 : "");
13545
13546 vty_out(vty, "\n");
13547 }
13548
13549 if (CHECK_FLAG(
13550 p->af_cap[afi]
13551 [safi],
13552 PEER_CAP_ADDPATH_AF_RX_ADV)
13553 || CHECK_FLAG(
13554 p->af_cap[afi]
13555 [safi],
13556 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13557 vty_out(vty,
13558 " %s: RX ",
13559 get_afi_safi_str(
13560 afi,
13561 safi,
13562 false));
13563
13564 if (CHECK_FLAG(
13565 p->af_cap
13566 [afi]
13567 [safi],
13568 PEER_CAP_ADDPATH_AF_RX_ADV))
13569 vty_out(vty,
13570 "advertised %s",
13571 get_afi_safi_str(
13572 afi,
13573 safi,
13574 false));
13575
13576 if (CHECK_FLAG(
13577 p->af_cap
13578 [afi]
13579 [safi],
13580 PEER_CAP_ADDPATH_AF_RX_RCV))
13581 vty_out(vty,
13582 "%sreceived",
13583 CHECK_FLAG(
13584 p->af_cap
13585 [afi]
13586 [safi],
13587 PEER_CAP_ADDPATH_AF_RX_ADV)
13588 ? " and "
13589 : "");
13590
13591 vty_out(vty, "\n");
13592 }
13593 }
13594 }
13595
13596 /* Dynamic */
13597 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
13598 || CHECK_FLAG(p->cap,
13599 PEER_CAP_DYNAMIC_ADV)) {
13600 vty_out(vty, " Dynamic:");
13601 if (CHECK_FLAG(p->cap,
13602 PEER_CAP_DYNAMIC_ADV))
13603 vty_out(vty, " advertised");
13604 if (CHECK_FLAG(p->cap,
13605 PEER_CAP_DYNAMIC_RCV))
13606 vty_out(vty, " %sreceived",
13607 CHECK_FLAG(
13608 p->cap,
13609 PEER_CAP_DYNAMIC_ADV)
13610 ? "and "
13611 : "");
13612 vty_out(vty, "\n");
13613 }
13614
13615 /* Extended nexthop */
13616 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
13617 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13618 vty_out(vty, " Extended nexthop:");
13619 if (CHECK_FLAG(p->cap,
13620 PEER_CAP_ENHE_ADV))
13621 vty_out(vty, " advertised");
13622 if (CHECK_FLAG(p->cap,
13623 PEER_CAP_ENHE_RCV))
13624 vty_out(vty, " %sreceived",
13625 CHECK_FLAG(
13626 p->cap,
13627 PEER_CAP_ENHE_ADV)
13628 ? "and "
13629 : "");
13630 vty_out(vty, "\n");
13631
13632 if (CHECK_FLAG(p->cap,
13633 PEER_CAP_ENHE_RCV)) {
13634 vty_out(vty,
13635 " Address families by peer:\n ");
13636 for (safi = SAFI_UNICAST;
13637 safi < SAFI_MAX; safi++)
13638 if (CHECK_FLAG(
13639 p->af_cap
13640 [AFI_IP]
13641 [safi],
13642 PEER_CAP_ENHE_AF_RCV))
13643 vty_out(vty,
13644 " %s\n",
13645 get_afi_safi_str(
13646 AFI_IP,
13647 safi,
13648 false));
13649 }
13650 }
13651
13652 /* Route Refresh */
13653 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
13654 || CHECK_FLAG(p->cap,
13655 PEER_CAP_REFRESH_NEW_RCV)
13656 || CHECK_FLAG(p->cap,
13657 PEER_CAP_REFRESH_OLD_RCV)) {
13658 vty_out(vty, " Route refresh:");
13659 if (CHECK_FLAG(p->cap,
13660 PEER_CAP_REFRESH_ADV))
13661 vty_out(vty, " advertised");
13662 if (CHECK_FLAG(p->cap,
13663 PEER_CAP_REFRESH_NEW_RCV)
13664 || CHECK_FLAG(
13665 p->cap,
13666 PEER_CAP_REFRESH_OLD_RCV))
13667 vty_out(vty, " %sreceived(%s)",
13668 CHECK_FLAG(
13669 p->cap,
13670 PEER_CAP_REFRESH_ADV)
13671 ? "and "
13672 : "",
13673 (CHECK_FLAG(
13674 p->cap,
13675 PEER_CAP_REFRESH_OLD_RCV)
13676 && CHECK_FLAG(
13677 p->cap,
13678 PEER_CAP_REFRESH_NEW_RCV))
13679 ? "old & new"
13680 : CHECK_FLAG(
13681 p->cap,
13682 PEER_CAP_REFRESH_OLD_RCV)
13683 ? "old"
13684 : "new");
13685
13686 vty_out(vty, "\n");
13687 }
13688
13689 /* Enhanced Route Refresh */
13690 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV)
13691 || CHECK_FLAG(p->cap,
13692 PEER_CAP_ENHANCED_RR_RCV)) {
13693 vty_out(vty,
13694 " Enhanced Route Refresh:");
13695 if (CHECK_FLAG(
13696 p->cap,
13697 PEER_CAP_ENHANCED_RR_ADV))
13698 vty_out(vty, " advertised");
13699 if (CHECK_FLAG(
13700 p->cap,
13701 PEER_CAP_ENHANCED_RR_RCV))
13702 vty_out(vty, " %sreceived",
13703 CHECK_FLAG(
13704 p->cap,
13705 PEER_CAP_REFRESH_ADV)
13706 ? "and "
13707 : "");
13708 vty_out(vty, "\n");
13709 }
13710
13711 /* Multiprotocol Extensions */
13712 FOREACH_AFI_SAFI (afi, safi)
13713 if (p->afc_adv[afi][safi]
13714 || p->afc_recv[afi][safi]) {
13715 vty_out(vty,
13716 " Address Family %s:",
13717 get_afi_safi_str(
13718 afi,
13719 safi,
13720 false));
13721 if (p->afc_adv[afi][safi])
13722 vty_out(vty,
13723 " advertised");
13724 if (p->afc_recv[afi][safi])
13725 vty_out(vty,
13726 " %sreceived",
13727 p->afc_adv[afi]
13728 [safi]
13729 ? "and "
13730 : "");
13731 vty_out(vty, "\n");
13732 }
13733
13734 /* Hostname capability */
13735 vty_out(vty, " Hostname Capability:");
13736
13737 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13738 vty_out(vty,
13739 " advertised (name: %s,domain name: %s)",
13740 bgp->peer_self->hostname
13741 ? bgp->peer_self
13742 ->hostname
13743 : "n/a",
13744 bgp->peer_self->domainname
13745 ? bgp->peer_self
13746 ->domainname
13747 : "n/a");
13748 } else {
13749 vty_out(vty, " not advertised");
13750 }
13751
13752 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13753 vty_out(vty,
13754 " received (name: %s,domain name: %s)",
13755 p->hostname ? p->hostname
13756 : "n/a",
13757 p->domainname ? p->domainname
13758 : "n/a");
13759 } else {
13760 vty_out(vty, " not received");
13761 }
13762
13763 vty_out(vty, "\n");
13764
13765 /* Graceful Restart */
13766 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
13767 || CHECK_FLAG(p->cap,
13768 PEER_CAP_RESTART_ADV)) {
13769 vty_out(vty,
13770 " Graceful Restart Capability:");
13771 if (CHECK_FLAG(p->cap,
13772 PEER_CAP_RESTART_ADV))
13773 vty_out(vty, " advertised");
13774 if (CHECK_FLAG(p->cap,
13775 PEER_CAP_RESTART_RCV))
13776 vty_out(vty, " %sreceived",
13777 CHECK_FLAG(
13778 p->cap,
13779 PEER_CAP_RESTART_ADV)
13780 ? "and "
13781 : "");
13782 vty_out(vty, "\n");
13783
13784 if (CHECK_FLAG(p->cap,
13785 PEER_CAP_RESTART_RCV)) {
13786 int restart_af_count = 0;
13787
13788 vty_out(vty,
13789 " Remote Restart timer is %d seconds\n",
13790 p->v_gr_restart);
13791 vty_out(vty,
13792 " Address families by peer:\n ");
13793
13794 FOREACH_AFI_SAFI (afi, safi)
13795 if (CHECK_FLAG(
13796 p->af_cap
13797 [afi]
13798 [safi],
13799 PEER_CAP_RESTART_AF_RCV)) {
13800 vty_out(vty,
13801 "%s%s(%s)",
13802 restart_af_count
13803 ? ", "
13804 : "",
13805 get_afi_safi_str(
13806 afi,
13807 safi,
13808 false),
13809 CHECK_FLAG(
13810 p->af_cap
13811 [afi]
13812 [safi],
13813 PEER_CAP_RESTART_AF_PRESERVE_RCV)
13814 ? "preserved"
13815 : "not preserved");
13816 restart_af_count++;
13817 }
13818 if (!restart_af_count)
13819 vty_out(vty, "none");
13820 vty_out(vty, "\n");
13821 }
13822 } /* Gracefull Restart */
13823 }
13824 }
13825 }
13826
13827 /* graceful restart information */
13828 json_object *json_grace = NULL;
13829 json_object *json_grace_send = NULL;
13830 json_object *json_grace_recv = NULL;
13831 int eor_send_af_count = 0;
13832 int eor_receive_af_count = 0;
13833
13834 if (use_json) {
13835 json_grace = json_object_new_object();
13836 json_grace_send = json_object_new_object();
13837 json_grace_recv = json_object_new_object();
13838
13839 if ((p->status == Established)
13840 && CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13841 FOREACH_AFI_SAFI (afi, safi) {
13842 if (CHECK_FLAG(p->af_sflags[afi][safi],
13843 PEER_STATUS_EOR_SEND)) {
13844 json_object_boolean_true_add(
13845 json_grace_send,
13846 get_afi_safi_str(afi,
13847 safi,
13848 true));
13849 eor_send_af_count++;
13850 }
13851 }
13852 FOREACH_AFI_SAFI (afi, safi) {
13853 if (CHECK_FLAG(
13854 p->af_sflags[afi][safi],
13855 PEER_STATUS_EOR_RECEIVED)) {
13856 json_object_boolean_true_add(
13857 json_grace_recv,
13858 get_afi_safi_str(afi,
13859 safi,
13860 true));
13861 eor_receive_af_count++;
13862 }
13863 }
13864 }
13865 json_object_object_add(json_grace, "endOfRibSend",
13866 json_grace_send);
13867 json_object_object_add(json_grace, "endOfRibRecv",
13868 json_grace_recv);
13869
13870
13871 if (p->t_gr_restart)
13872 json_object_int_add(json_grace,
13873 "gracefulRestartTimerMsecs",
13874 thread_timer_remain_second(
13875 p->t_gr_restart)
13876 * 1000);
13877
13878 if (p->t_gr_stale)
13879 json_object_int_add(
13880 json_grace,
13881 "gracefulStalepathTimerMsecs",
13882 thread_timer_remain_second(
13883 p->t_gr_stale)
13884 * 1000);
13885 /* more gr info in new format */
13886 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json,
13887 json_grace);
13888 json_object_object_add(
13889 json_neigh, "gracefulRestartInfo", json_grace);
13890 } else {
13891 vty_out(vty, " Graceful restart information:\n");
13892 if ((p->status == Established)
13893 && CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13894
13895 vty_out(vty, " End-of-RIB send: ");
13896 FOREACH_AFI_SAFI (afi, safi) {
13897 if (CHECK_FLAG(p->af_sflags[afi][safi],
13898 PEER_STATUS_EOR_SEND)) {
13899 vty_out(vty, "%s%s",
13900 eor_send_af_count ? ", "
13901 : "",
13902 get_afi_safi_str(
13903 afi, safi,
13904 false));
13905 eor_send_af_count++;
13906 }
13907 }
13908 vty_out(vty, "\n");
13909 vty_out(vty, " End-of-RIB received: ");
13910 FOREACH_AFI_SAFI (afi, safi) {
13911 if (CHECK_FLAG(
13912 p->af_sflags[afi][safi],
13913 PEER_STATUS_EOR_RECEIVED)) {
13914 vty_out(vty, "%s%s",
13915 eor_receive_af_count
13916 ? ", "
13917 : "",
13918 get_afi_safi_str(afi,
13919 safi,
13920 false));
13921 eor_receive_af_count++;
13922 }
13923 }
13924 vty_out(vty, "\n");
13925 }
13926
13927 if (p->t_gr_restart)
13928 vty_out(vty,
13929 " The remaining time of restart timer is %ld\n",
13930 thread_timer_remain_second(
13931 p->t_gr_restart));
13932
13933 if (p->t_gr_stale)
13934 vty_out(vty,
13935 " The remaining time of stalepath timer is %ld\n",
13936 thread_timer_remain_second(
13937 p->t_gr_stale));
13938
13939 /* more gr info in new format */
13940 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, NULL);
13941 }
13942
13943 if (use_json) {
13944 json_object *json_stat = NULL;
13945 json_stat = json_object_new_object();
13946 /* Packet counts. */
13947
13948 atomic_size_t outq_count, inq_count;
13949 outq_count = atomic_load_explicit(&p->obuf->count,
13950 memory_order_relaxed);
13951 inq_count = atomic_load_explicit(&p->ibuf->count,
13952 memory_order_relaxed);
13953
13954 json_object_int_add(json_stat, "depthInq",
13955 (unsigned long)inq_count);
13956 json_object_int_add(json_stat, "depthOutq",
13957 (unsigned long)outq_count);
13958 json_object_int_add(json_stat, "opensSent",
13959 atomic_load_explicit(&p->open_out,
13960 memory_order_relaxed));
13961 json_object_int_add(json_stat, "opensRecv",
13962 atomic_load_explicit(&p->open_in,
13963 memory_order_relaxed));
13964 json_object_int_add(json_stat, "notificationsSent",
13965 atomic_load_explicit(&p->notify_out,
13966 memory_order_relaxed));
13967 json_object_int_add(json_stat, "notificationsRecv",
13968 atomic_load_explicit(&p->notify_in,
13969 memory_order_relaxed));
13970 json_object_int_add(json_stat, "updatesSent",
13971 atomic_load_explicit(&p->update_out,
13972 memory_order_relaxed));
13973 json_object_int_add(json_stat, "updatesRecv",
13974 atomic_load_explicit(&p->update_in,
13975 memory_order_relaxed));
13976 json_object_int_add(json_stat, "keepalivesSent",
13977 atomic_load_explicit(&p->keepalive_out,
13978 memory_order_relaxed));
13979 json_object_int_add(json_stat, "keepalivesRecv",
13980 atomic_load_explicit(&p->keepalive_in,
13981 memory_order_relaxed));
13982 json_object_int_add(json_stat, "routeRefreshSent",
13983 atomic_load_explicit(&p->refresh_out,
13984 memory_order_relaxed));
13985 json_object_int_add(json_stat, "routeRefreshRecv",
13986 atomic_load_explicit(&p->refresh_in,
13987 memory_order_relaxed));
13988 json_object_int_add(json_stat, "capabilitySent",
13989 atomic_load_explicit(&p->dynamic_cap_out,
13990 memory_order_relaxed));
13991 json_object_int_add(json_stat, "capabilityRecv",
13992 atomic_load_explicit(&p->dynamic_cap_in,
13993 memory_order_relaxed));
13994 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
13995 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
13996 json_object_object_add(json_neigh, "messageStats", json_stat);
13997 } else {
13998 atomic_size_t outq_count, inq_count;
13999 outq_count = atomic_load_explicit(&p->obuf->count,
14000 memory_order_relaxed);
14001 inq_count = atomic_load_explicit(&p->ibuf->count,
14002 memory_order_relaxed);
14003
14004 /* Packet counts. */
14005 vty_out(vty, " Message statistics:\n");
14006 vty_out(vty, " Inq depth is %zu\n", inq_count);
14007 vty_out(vty, " Outq depth is %zu\n", outq_count);
14008 vty_out(vty, " Sent Rcvd\n");
14009 vty_out(vty, " Opens: %10d %10d\n",
14010 atomic_load_explicit(&p->open_out,
14011 memory_order_relaxed),
14012 atomic_load_explicit(&p->open_in,
14013 memory_order_relaxed));
14014 vty_out(vty, " Notifications: %10d %10d\n",
14015 atomic_load_explicit(&p->notify_out,
14016 memory_order_relaxed),
14017 atomic_load_explicit(&p->notify_in,
14018 memory_order_relaxed));
14019 vty_out(vty, " Updates: %10d %10d\n",
14020 atomic_load_explicit(&p->update_out,
14021 memory_order_relaxed),
14022 atomic_load_explicit(&p->update_in,
14023 memory_order_relaxed));
14024 vty_out(vty, " Keepalives: %10d %10d\n",
14025 atomic_load_explicit(&p->keepalive_out,
14026 memory_order_relaxed),
14027 atomic_load_explicit(&p->keepalive_in,
14028 memory_order_relaxed));
14029 vty_out(vty, " Route Refresh: %10d %10d\n",
14030 atomic_load_explicit(&p->refresh_out,
14031 memory_order_relaxed),
14032 atomic_load_explicit(&p->refresh_in,
14033 memory_order_relaxed));
14034 vty_out(vty, " Capability: %10d %10d\n",
14035 atomic_load_explicit(&p->dynamic_cap_out,
14036 memory_order_relaxed),
14037 atomic_load_explicit(&p->dynamic_cap_in,
14038 memory_order_relaxed));
14039 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
14040 PEER_TOTAL_RX(p));
14041 }
14042
14043 if (use_json) {
14044 /* advertisement-interval */
14045 json_object_int_add(json_neigh,
14046 "minBtwnAdvertisementRunsTimerMsecs",
14047 p->v_routeadv * 1000);
14048
14049 /* Update-source. */
14050 if (p->update_if || p->update_source) {
14051 if (p->update_if)
14052 json_object_string_add(json_neigh,
14053 "updateSource",
14054 p->update_if);
14055 else if (p->update_source)
14056 json_object_string_add(
14057 json_neigh, "updateSource",
14058 sockunion2str(p->update_source, buf1,
14059 SU_ADDRSTRLEN));
14060 }
14061 } else {
14062 /* advertisement-interval */
14063 vty_out(vty,
14064 " Minimum time between advertisement runs is %d seconds\n",
14065 p->v_routeadv);
14066
14067 /* Update-source. */
14068 if (p->update_if || p->update_source) {
14069 vty_out(vty, " Update source is ");
14070 if (p->update_if)
14071 vty_out(vty, "%s", p->update_if);
14072 else if (p->update_source)
14073 vty_out(vty, "%s",
14074 sockunion2str(p->update_source, buf1,
14075 SU_ADDRSTRLEN));
14076 vty_out(vty, "\n");
14077 }
14078
14079 vty_out(vty, "\n");
14080 }
14081
14082 /* Address Family Information */
14083 json_object *json_hold = NULL;
14084
14085 if (use_json)
14086 json_hold = json_object_new_object();
14087
14088 FOREACH_AFI_SAFI (afi, safi)
14089 if (p->afc[afi][safi])
14090 bgp_show_peer_afi(vty, p, afi, safi, use_json,
14091 json_hold);
14092
14093 if (use_json) {
14094 json_object_object_add(json_neigh, "addressFamilyInfo",
14095 json_hold);
14096 json_object_int_add(json_neigh, "connectionsEstablished",
14097 p->established);
14098 json_object_int_add(json_neigh, "connectionsDropped",
14099 p->dropped);
14100 } else
14101 vty_out(vty, " Connections established %d; dropped %d\n",
14102 p->established, p->dropped);
14103
14104 if (!p->last_reset) {
14105 if (use_json)
14106 json_object_string_add(json_neigh, "lastReset",
14107 "never");
14108 else
14109 vty_out(vty, " Last reset never\n");
14110 } else {
14111 if (use_json) {
14112 time_t uptime;
14113 struct tm tm;
14114
14115 uptime = bgp_clock();
14116 uptime -= p->resettime;
14117 gmtime_r(&uptime, &tm);
14118
14119 json_object_int_add(json_neigh, "lastResetTimerMsecs",
14120 (tm.tm_sec * 1000)
14121 + (tm.tm_min * 60000)
14122 + (tm.tm_hour * 3600000));
14123 bgp_show_peer_reset(NULL, p, json_neigh, true);
14124 } else {
14125 vty_out(vty, " Last reset %s, ",
14126 peer_uptime(p->resettime, timebuf,
14127 BGP_UPTIME_LEN, 0, NULL));
14128
14129 bgp_show_peer_reset(vty, p, NULL, false);
14130 if (p->last_reset_cause_size) {
14131 msg = p->last_reset_cause;
14132 vty_out(vty,
14133 " Message received that caused BGP to send a NOTIFICATION:\n ");
14134 for (i = 1; i <= p->last_reset_cause_size;
14135 i++) {
14136 vty_out(vty, "%02X", *msg++);
14137
14138 if (i != p->last_reset_cause_size) {
14139 if (i % 16 == 0) {
14140 vty_out(vty, "\n ");
14141 } else if (i % 4 == 0) {
14142 vty_out(vty, " ");
14143 }
14144 }
14145 }
14146 vty_out(vty, "\n");
14147 }
14148 }
14149 }
14150
14151 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
14152 if (use_json)
14153 json_object_boolean_true_add(json_neigh,
14154 "prefixesConfigExceedMax");
14155 else
14156 vty_out(vty,
14157 " Peer had exceeded the max. no. of prefixes configured.\n");
14158
14159 if (p->t_pmax_restart) {
14160 if (use_json) {
14161 json_object_boolean_true_add(
14162 json_neigh, "reducePrefixNumFrom");
14163 json_object_int_add(json_neigh,
14164 "restartInTimerMsec",
14165 thread_timer_remain_second(
14166 p->t_pmax_restart)
14167 * 1000);
14168 } else
14169 vty_out(vty,
14170 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
14171 p->host, thread_timer_remain_second(
14172 p->t_pmax_restart));
14173 } else {
14174 if (use_json)
14175 json_object_boolean_true_add(
14176 json_neigh,
14177 "reducePrefixNumAndClearIpBgp");
14178 else
14179 vty_out(vty,
14180 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
14181 p->host);
14182 }
14183 }
14184
14185 /* EBGP Multihop and GTSM */
14186 if (p->sort != BGP_PEER_IBGP) {
14187 if (use_json) {
14188 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14189 json_object_int_add(json_neigh,
14190 "externalBgpNbrMaxHopsAway",
14191 p->gtsm_hops);
14192 else if (p->ttl > BGP_DEFAULT_TTL)
14193 json_object_int_add(json_neigh,
14194 "externalBgpNbrMaxHopsAway",
14195 p->ttl);
14196 } else {
14197 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14198 vty_out(vty,
14199 " External BGP neighbor may be up to %d hops away.\n",
14200 p->gtsm_hops);
14201 else if (p->ttl > BGP_DEFAULT_TTL)
14202 vty_out(vty,
14203 " External BGP neighbor may be up to %d hops away.\n",
14204 p->ttl);
14205 }
14206 } else {
14207 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED) {
14208 if (use_json)
14209 json_object_int_add(json_neigh,
14210 "internalBgpNbrMaxHopsAway",
14211 p->gtsm_hops);
14212 else
14213 vty_out(vty,
14214 " Internal BGP neighbor may be up to %d hops away.\n",
14215 p->gtsm_hops);
14216 }
14217 }
14218
14219 /* Local address. */
14220 if (p->su_local) {
14221 if (use_json) {
14222 json_object_string_add(json_neigh, "hostLocal",
14223 sockunion2str(p->su_local, buf1,
14224 SU_ADDRSTRLEN));
14225 json_object_int_add(json_neigh, "portLocal",
14226 ntohs(p->su_local->sin.sin_port));
14227 } else
14228 vty_out(vty, "Local host: %s, Local port: %d\n",
14229 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
14230 ntohs(p->su_local->sin.sin_port));
14231 }
14232
14233 /* Remote address. */
14234 if (p->su_remote) {
14235 if (use_json) {
14236 json_object_string_add(json_neigh, "hostForeign",
14237 sockunion2str(p->su_remote, buf1,
14238 SU_ADDRSTRLEN));
14239 json_object_int_add(json_neigh, "portForeign",
14240 ntohs(p->su_remote->sin.sin_port));
14241 } else
14242 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
14243 sockunion2str(p->su_remote, buf1,
14244 SU_ADDRSTRLEN),
14245 ntohs(p->su_remote->sin.sin_port));
14246 }
14247
14248 /* Nexthop display. */
14249 if (p->su_local) {
14250 if (use_json) {
14251 json_object_string_add(json_neigh, "nexthop",
14252 inet_ntop(AF_INET,
14253 &p->nexthop.v4, buf1,
14254 sizeof(buf1)));
14255 json_object_string_add(json_neigh, "nexthopGlobal",
14256 inet_ntop(AF_INET6,
14257 &p->nexthop.v6_global,
14258 buf1, sizeof(buf1)));
14259 json_object_string_add(json_neigh, "nexthopLocal",
14260 inet_ntop(AF_INET6,
14261 &p->nexthop.v6_local,
14262 buf1, sizeof(buf1)));
14263 if (p->shared_network)
14264 json_object_string_add(json_neigh,
14265 "bgpConnection",
14266 "sharedNetwork");
14267 else
14268 json_object_string_add(json_neigh,
14269 "bgpConnection",
14270 "nonSharedNetwork");
14271 } else {
14272 vty_out(vty, "Nexthop: %s\n",
14273 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
14274 sizeof(buf1)));
14275 vty_out(vty, "Nexthop global: %s\n",
14276 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
14277 sizeof(buf1)));
14278 vty_out(vty, "Nexthop local: %s\n",
14279 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
14280 sizeof(buf1)));
14281 vty_out(vty, "BGP connection: %s\n",
14282 p->shared_network ? "shared network"
14283 : "non shared network");
14284 }
14285 }
14286
14287 /* Timer information. */
14288 if (use_json) {
14289 json_object_int_add(json_neigh, "connectRetryTimer",
14290 p->v_connect);
14291 if (p->status == Established && p->rtt)
14292 json_object_int_add(json_neigh, "estimatedRttInMsecs",
14293 p->rtt);
14294 if (p->t_start)
14295 json_object_int_add(
14296 json_neigh, "nextStartTimerDueInMsecs",
14297 thread_timer_remain_second(p->t_start) * 1000);
14298 if (p->t_connect)
14299 json_object_int_add(
14300 json_neigh, "nextConnectTimerDueInMsecs",
14301 thread_timer_remain_second(p->t_connect)
14302 * 1000);
14303 if (p->t_routeadv) {
14304 json_object_int_add(json_neigh, "mraiInterval",
14305 p->v_routeadv);
14306 json_object_int_add(
14307 json_neigh, "mraiTimerExpireInMsecs",
14308 thread_timer_remain_second(p->t_routeadv)
14309 * 1000);
14310 }
14311 if (p->password)
14312 json_object_int_add(json_neigh, "authenticationEnabled",
14313 1);
14314
14315 if (p->t_read)
14316 json_object_string_add(json_neigh, "readThread", "on");
14317 else
14318 json_object_string_add(json_neigh, "readThread", "off");
14319
14320 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
14321 json_object_string_add(json_neigh, "writeThread", "on");
14322 else
14323 json_object_string_add(json_neigh, "writeThread",
14324 "off");
14325 } else {
14326 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
14327 p->v_connect);
14328 if (p->status == Established && p->rtt)
14329 vty_out(vty, "Estimated round trip time: %d ms\n",
14330 p->rtt);
14331 if (p->t_start)
14332 vty_out(vty, "Next start timer due in %ld seconds\n",
14333 thread_timer_remain_second(p->t_start));
14334 if (p->t_connect)
14335 vty_out(vty, "Next connect timer due in %ld seconds\n",
14336 thread_timer_remain_second(p->t_connect));
14337 if (p->t_routeadv)
14338 vty_out(vty,
14339 "MRAI (interval %u) timer expires in %ld seconds\n",
14340 p->v_routeadv,
14341 thread_timer_remain_second(p->t_routeadv));
14342 if (p->password)
14343 vty_out(vty, "Peer Authentication Enabled\n");
14344
14345 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
14346 p->t_read ? "on" : "off",
14347 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
14348 ? "on"
14349 : "off", p->fd);
14350 }
14351
14352 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
14353 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
14354 bgp_capability_vty_out(vty, p, use_json, json_neigh);
14355
14356 if (!use_json)
14357 vty_out(vty, "\n");
14358
14359 /* BFD information. */
14360 bgp_bfd_show_info(vty, p, use_json, json_neigh);
14361
14362 if (use_json) {
14363 if (p->conf_if) /* Configured interface name. */
14364 json_object_object_add(json, p->conf_if, json_neigh);
14365 else /* Configured IP address. */
14366 json_object_object_add(json, p->host, json_neigh);
14367 }
14368 }
14369
14370 static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
14371 enum show_type type,
14372 union sockunion *su,
14373 const char *conf_if, afi_t afi,
14374 bool use_json)
14375 {
14376 struct listnode *node, *nnode;
14377 struct peer *peer;
14378 int find = 0;
14379 safi_t safi = SAFI_UNICAST;
14380 json_object *json = NULL;
14381 json_object *json_neighbor = NULL;
14382
14383 if (use_json) {
14384 json = json_object_new_object();
14385 json_neighbor = json_object_new_object();
14386 }
14387
14388 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14389
14390 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14391 continue;
14392
14393 if ((peer->afc[afi][safi]) == 0)
14394 continue;
14395
14396 if (type == show_all) {
14397 bgp_show_peer_gr_status(vty, peer, use_json,
14398 json_neighbor);
14399
14400 if (use_json) {
14401 json_object_object_add(json, peer->host,
14402 json_neighbor);
14403 json_neighbor = NULL;
14404 }
14405
14406 } else if (type == show_peer) {
14407 if (conf_if) {
14408 if ((peer->conf_if
14409 && !strcmp(peer->conf_if, conf_if))
14410 || (peer->hostname
14411 && !strcmp(peer->hostname, conf_if))) {
14412 find = 1;
14413 bgp_show_peer_gr_status(vty, peer,
14414 use_json,
14415 json_neighbor);
14416 }
14417 } else {
14418 if (sockunion_same(&peer->su, su)) {
14419 find = 1;
14420 bgp_show_peer_gr_status(vty, peer,
14421 use_json,
14422 json_neighbor);
14423 }
14424 }
14425 if (use_json && find)
14426 json_object_object_add(json, peer->host,
14427 json_neighbor);
14428 }
14429
14430 if (find) {
14431 json_neighbor = NULL;
14432 break;
14433 }
14434 }
14435
14436 if (type == show_peer && !find) {
14437 if (use_json)
14438 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14439 else
14440 vty_out(vty, "%% No such neighbor\n");
14441 }
14442 if (use_json) {
14443 vty_out(vty, "%s\n",
14444 json_object_to_json_string_ext(
14445 json, JSON_C_TO_STRING_PRETTY));
14446
14447 if (json_neighbor)
14448 json_object_free(json_neighbor);
14449 json_object_free(json);
14450 } else {
14451 vty_out(vty, "\n");
14452 }
14453
14454 return CMD_SUCCESS;
14455 }
14456
14457 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
14458 enum show_type type, union sockunion *su,
14459 const char *conf_if, bool use_json,
14460 json_object *json)
14461 {
14462 struct listnode *node, *nnode;
14463 struct peer *peer;
14464 int find = 0;
14465 bool nbr_output = false;
14466 afi_t afi = AFI_MAX;
14467 safi_t safi = SAFI_MAX;
14468
14469 if (type == show_ipv4_peer || type == show_ipv4_all) {
14470 afi = AFI_IP;
14471 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
14472 afi = AFI_IP6;
14473 }
14474
14475 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14476 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14477 continue;
14478
14479 switch (type) {
14480 case show_all:
14481 bgp_show_peer(vty, peer, use_json, json);
14482 nbr_output = true;
14483 break;
14484 case show_peer:
14485 if (conf_if) {
14486 if ((peer->conf_if
14487 && !strcmp(peer->conf_if, conf_if))
14488 || (peer->hostname
14489 && !strcmp(peer->hostname, conf_if))) {
14490 find = 1;
14491 bgp_show_peer(vty, peer, use_json,
14492 json);
14493 }
14494 } else {
14495 if (sockunion_same(&peer->su, su)) {
14496 find = 1;
14497 bgp_show_peer(vty, peer, use_json,
14498 json);
14499 }
14500 }
14501 break;
14502 case show_ipv4_peer:
14503 case show_ipv6_peer:
14504 FOREACH_SAFI (safi) {
14505 if (peer->afc[afi][safi]) {
14506 if (conf_if) {
14507 if ((peer->conf_if
14508 && !strcmp(peer->conf_if, conf_if))
14509 || (peer->hostname
14510 && !strcmp(peer->hostname, conf_if))) {
14511 find = 1;
14512 bgp_show_peer(vty, peer, use_json,
14513 json);
14514 break;
14515 }
14516 } else {
14517 if (sockunion_same(&peer->su, su)) {
14518 find = 1;
14519 bgp_show_peer(vty, peer, use_json,
14520 json);
14521 break;
14522 }
14523 }
14524 }
14525 }
14526 break;
14527 case show_ipv4_all:
14528 case show_ipv6_all:
14529 FOREACH_SAFI (safi) {
14530 if (peer->afc[afi][safi]) {
14531 bgp_show_peer(vty, peer, use_json, json);
14532 nbr_output = true;
14533 break;
14534 }
14535 }
14536 break;
14537 }
14538 }
14539
14540 if ((type == show_peer || type == show_ipv4_peer ||
14541 type == show_ipv6_peer) && !find) {
14542 if (use_json)
14543 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14544 else
14545 vty_out(vty, "%% No such neighbor in this view/vrf\n");
14546 }
14547
14548 if (type != show_peer && type != show_ipv4_peer &&
14549 type != show_ipv6_peer && !nbr_output && !use_json)
14550 vty_out(vty, "%% No BGP neighbors found\n");
14551
14552 if (use_json) {
14553 vty_out(vty, "%s\n", json_object_to_json_string_ext(
14554 json, JSON_C_TO_STRING_PRETTY));
14555 } else {
14556 vty_out(vty, "\n");
14557 }
14558
14559 return CMD_SUCCESS;
14560 }
14561
14562 static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
14563 enum show_type type,
14564 const char *ip_str,
14565 afi_t afi, bool use_json)
14566 {
14567
14568 int ret;
14569 struct bgp *bgp;
14570 union sockunion su;
14571
14572 bgp = bgp_get_default();
14573
14574 if (!bgp)
14575 return;
14576
14577 if (!use_json)
14578 bgp_show_global_graceful_restart_mode_vty(vty, bgp, use_json,
14579 NULL);
14580
14581 if (ip_str) {
14582 ret = str2sockunion(ip_str, &su);
14583 if (ret < 0)
14584 bgp_show_neighbor_graceful_restart(
14585 vty, bgp, type, NULL, ip_str, afi, use_json);
14586 else
14587 bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
14588 NULL, afi, use_json);
14589 } else
14590 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
14591 afi, use_json);
14592 }
14593
14594 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
14595 enum show_type type,
14596 const char *ip_str,
14597 bool use_json)
14598 {
14599 struct listnode *node, *nnode;
14600 struct bgp *bgp;
14601 union sockunion su;
14602 json_object *json = NULL;
14603 int ret, is_first = 1;
14604 bool nbr_output = false;
14605
14606 if (use_json)
14607 vty_out(vty, "{\n");
14608
14609 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
14610 nbr_output = true;
14611 if (use_json) {
14612 if (!(json = json_object_new_object())) {
14613 flog_err(
14614 EC_BGP_JSON_MEM_ERROR,
14615 "Unable to allocate memory for JSON object");
14616 vty_out(vty,
14617 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
14618 return;
14619 }
14620
14621 json_object_int_add(json, "vrfId",
14622 (bgp->vrf_id == VRF_UNKNOWN)
14623 ? -1
14624 : (int64_t)bgp->vrf_id);
14625 json_object_string_add(
14626 json, "vrfName",
14627 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14628 ? VRF_DEFAULT_NAME
14629 : bgp->name);
14630
14631 if (!is_first)
14632 vty_out(vty, ",\n");
14633 else
14634 is_first = 0;
14635
14636 vty_out(vty, "\"%s\":",
14637 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14638 ? VRF_DEFAULT_NAME
14639 : bgp->name);
14640 } else {
14641 vty_out(vty, "\nInstance %s:\n",
14642 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14643 ? VRF_DEFAULT_NAME
14644 : bgp->name);
14645 }
14646
14647 if (type == show_peer || type == show_ipv4_peer ||
14648 type == show_ipv6_peer) {
14649 ret = str2sockunion(ip_str, &su);
14650 if (ret < 0)
14651 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14652 use_json, json);
14653 else
14654 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14655 use_json, json);
14656 } else {
14657 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
14658 use_json, json);
14659 }
14660 json_object_free(json);
14661 json = NULL;
14662 }
14663
14664 if (use_json)
14665 vty_out(vty, "}\n");
14666 else if (!nbr_output)
14667 vty_out(vty, "%% BGP instance not found\n");
14668 }
14669
14670 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
14671 enum show_type type, const char *ip_str,
14672 bool use_json)
14673 {
14674 int ret;
14675 struct bgp *bgp;
14676 union sockunion su;
14677 json_object *json = NULL;
14678
14679 if (name) {
14680 if (strmatch(name, "all")) {
14681 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
14682 use_json);
14683 return CMD_SUCCESS;
14684 } else {
14685 bgp = bgp_lookup_by_name(name);
14686 if (!bgp) {
14687 if (use_json) {
14688 json = json_object_new_object();
14689 vty_out(vty, "%s\n",
14690 json_object_to_json_string_ext(
14691 json,
14692 JSON_C_TO_STRING_PRETTY));
14693 json_object_free(json);
14694 } else
14695 vty_out(vty,
14696 "%% BGP instance not found\n");
14697
14698 return CMD_WARNING;
14699 }
14700 }
14701 } else {
14702 bgp = bgp_get_default();
14703 }
14704
14705 if (bgp) {
14706 json = json_object_new_object();
14707 if (ip_str) {
14708 ret = str2sockunion(ip_str, &su);
14709 if (ret < 0)
14710 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14711 use_json, json);
14712 else
14713 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14714 use_json, json);
14715 } else {
14716 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
14717 json);
14718 }
14719 json_object_free(json);
14720 } else {
14721 if (use_json)
14722 vty_out(vty, "{}\n");
14723 else
14724 vty_out(vty, "%% BGP instance not found\n");
14725 }
14726
14727 return CMD_SUCCESS;
14728 }
14729
14730
14731
14732 /* "show [ip] bgp neighbors graceful-restart" commands. */
14733 DEFUN (show_ip_bgp_neighbors_gracrful_restart,
14734 show_ip_bgp_neighbors_graceful_restart_cmd,
14735 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
14736 SHOW_STR
14737 BGP_STR
14738 IP_STR
14739 IPV6_STR
14740 NEIGHBOR_STR
14741 "Neighbor to display information about\n"
14742 "Neighbor to display information about\n"
14743 "Neighbor on BGP configured interface\n"
14744 GR_SHOW
14745 JSON_STR)
14746 {
14747 char *sh_arg = NULL;
14748 enum show_type sh_type;
14749 int idx = 0;
14750 afi_t afi = AFI_MAX;
14751 bool uj = use_json(argc, argv);
14752
14753 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
14754 afi = AFI_MAX;
14755
14756 idx++;
14757
14758 if (argv_find(argv, argc, "A.B.C.D", &idx)
14759 || argv_find(argv, argc, "X:X::X:X", &idx)
14760 || argv_find(argv, argc, "WORD", &idx)) {
14761 sh_type = show_peer;
14762 sh_arg = argv[idx]->arg;
14763 } else
14764 sh_type = show_all;
14765
14766 if (!argv_find(argv, argc, "graceful-restart", &idx))
14767 return CMD_SUCCESS;
14768
14769
14770 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
14771 afi, uj);
14772 }
14773
14774 /* "show [ip] bgp neighbors" commands. */
14775 DEFUN (show_ip_bgp_neighbors,
14776 show_ip_bgp_neighbors_cmd,
14777 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
14778 SHOW_STR
14779 IP_STR
14780 BGP_STR
14781 BGP_INSTANCE_HELP_STR
14782 "Address Family\n"
14783 "Address Family\n"
14784 "Detailed information on TCP and BGP neighbor connections\n"
14785 "Neighbor to display information about\n"
14786 "Neighbor to display information about\n"
14787 "Neighbor on BGP configured interface\n"
14788 JSON_STR)
14789 {
14790 char *vrf = NULL;
14791 char *sh_arg = NULL;
14792 enum show_type sh_type;
14793 afi_t afi = AFI_MAX;
14794
14795 bool uj = use_json(argc, argv);
14796
14797 int idx = 0;
14798
14799 /* [<vrf> VIEWVRFNAME] */
14800 if (argv_find(argv, argc, "vrf", &idx)) {
14801 vrf = argv[idx + 1]->arg;
14802 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
14803 vrf = NULL;
14804 } else if (argv_find(argv, argc, "view", &idx))
14805 /* [<view> VIEWVRFNAME] */
14806 vrf = argv[idx + 1]->arg;
14807
14808 idx++;
14809
14810 if (argv_find(argv, argc, "ipv4", &idx)) {
14811 sh_type = show_ipv4_all;
14812 afi = AFI_IP;
14813 } else if (argv_find(argv, argc, "ipv6", &idx)) {
14814 sh_type = show_ipv6_all;
14815 afi = AFI_IP6;
14816 } else {
14817 sh_type = show_all;
14818 }
14819
14820 if (argv_find(argv, argc, "A.B.C.D", &idx)
14821 || argv_find(argv, argc, "X:X::X:X", &idx)
14822 || argv_find(argv, argc, "WORD", &idx)) {
14823 sh_type = show_peer;
14824 sh_arg = argv[idx]->arg;
14825 }
14826
14827 if (sh_type == show_peer && afi == AFI_IP) {
14828 sh_type = show_ipv4_peer;
14829 } else if (sh_type == show_peer && afi == AFI_IP6) {
14830 sh_type = show_ipv6_peer;
14831 }
14832
14833 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
14834 }
14835
14836 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
14837 paths' and `show ip mbgp paths'. Those functions results are the
14838 same.*/
14839 DEFUN (show_ip_bgp_paths,
14840 show_ip_bgp_paths_cmd,
14841 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
14842 SHOW_STR
14843 IP_STR
14844 BGP_STR
14845 BGP_SAFI_HELP_STR
14846 "Path information\n")
14847 {
14848 vty_out(vty, "Address Refcnt Path\n");
14849 aspath_print_all_vty(vty);
14850 return CMD_SUCCESS;
14851 }
14852
14853 #include "hash.h"
14854
14855 static void community_show_all_iterator(struct hash_bucket *bucket,
14856 struct vty *vty)
14857 {
14858 struct community *com;
14859
14860 com = (struct community *)bucket->data;
14861 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
14862 community_str(com, false));
14863 }
14864
14865 /* Show BGP's community internal data. */
14866 DEFUN (show_ip_bgp_community_info,
14867 show_ip_bgp_community_info_cmd,
14868 "show [ip] bgp community-info",
14869 SHOW_STR
14870 IP_STR
14871 BGP_STR
14872 "List all bgp community information\n")
14873 {
14874 vty_out(vty, "Address Refcnt Community\n");
14875
14876 hash_iterate(community_hash(),
14877 (void (*)(struct hash_bucket *,
14878 void *))community_show_all_iterator,
14879 vty);
14880
14881 return CMD_SUCCESS;
14882 }
14883
14884 static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
14885 struct vty *vty)
14886 {
14887 struct lcommunity *lcom;
14888
14889 lcom = (struct lcommunity *)bucket->data;
14890 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
14891 lcommunity_str(lcom, false));
14892 }
14893
14894 /* Show BGP's community internal data. */
14895 DEFUN (show_ip_bgp_lcommunity_info,
14896 show_ip_bgp_lcommunity_info_cmd,
14897 "show ip bgp large-community-info",
14898 SHOW_STR
14899 IP_STR
14900 BGP_STR
14901 "List all bgp large-community information\n")
14902 {
14903 vty_out(vty, "Address Refcnt Large-community\n");
14904
14905 hash_iterate(lcommunity_hash(),
14906 (void (*)(struct hash_bucket *,
14907 void *))lcommunity_show_all_iterator,
14908 vty);
14909
14910 return CMD_SUCCESS;
14911 }
14912 /* Graceful Restart */
14913
14914 static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
14915 struct bgp *bgp,
14916 bool use_json,
14917 json_object *json)
14918 {
14919
14920
14921 vty_out(vty, "\n%s", SHOW_GR_HEADER);
14922
14923 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
14924
14925 switch (bgp_global_gr_mode) {
14926
14927 case GLOBAL_HELPER:
14928 vty_out(vty, "Global BGP GR Mode : Helper\n");
14929 break;
14930
14931 case GLOBAL_GR:
14932 vty_out(vty, "Global BGP GR Mode : Restart\n");
14933 break;
14934
14935 case GLOBAL_DISABLE:
14936 vty_out(vty, "Global BGP GR Mode : Disable\n");
14937 break;
14938
14939 case GLOBAL_INVALID:
14940 vty_out(vty,
14941 "Global BGP GR Mode Invalid\n");
14942 break;
14943 }
14944 vty_out(vty, "\n");
14945 }
14946
14947 static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
14948 enum show_type type,
14949 const char *ip_str,
14950 afi_t afi, bool use_json)
14951 {
14952 if ((afi == AFI_MAX) && (ip_str == NULL)) {
14953 afi = AFI_IP;
14954
14955 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
14956
14957 bgp_show_neighbor_graceful_restart_vty(
14958 vty, type, ip_str, afi, use_json);
14959 afi++;
14960 }
14961 } else if (afi != AFI_MAX) {
14962 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
14963 use_json);
14964 } else {
14965 return CMD_ERR_INCOMPLETE;
14966 }
14967
14968 return CMD_SUCCESS;
14969 }
14970 /* Graceful Restart */
14971
14972 DEFUN (show_ip_bgp_attr_info,
14973 show_ip_bgp_attr_info_cmd,
14974 "show [ip] bgp attribute-info",
14975 SHOW_STR
14976 IP_STR
14977 BGP_STR
14978 "List all bgp attribute information\n")
14979 {
14980 attr_show_all(vty);
14981 return CMD_SUCCESS;
14982 }
14983
14984 static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
14985 afi_t afi, safi_t safi,
14986 bool use_json, json_object *json)
14987 {
14988 struct bgp *bgp;
14989 struct listnode *node;
14990 char *vname;
14991 char buf1[INET6_ADDRSTRLEN];
14992 char *ecom_str;
14993 vpn_policy_direction_t dir;
14994
14995 if (json) {
14996 json_object *json_import_vrfs = NULL;
14997 json_object *json_export_vrfs = NULL;
14998
14999 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15000
15001 if (!bgp) {
15002 vty_out(vty, "%s\n",
15003 json_object_to_json_string_ext(
15004 json,
15005 JSON_C_TO_STRING_PRETTY));
15006 json_object_free(json);
15007
15008 return CMD_WARNING;
15009 }
15010
15011 /* Provide context for the block */
15012 json_object_string_add(json, "vrf", name ? name : "default");
15013 json_object_string_add(json, "afiSafi",
15014 get_afi_safi_str(afi, safi, true));
15015
15016 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15017 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
15018 json_object_string_add(json, "importFromVrfs", "none");
15019 json_object_string_add(json, "importRts", "none");
15020 } else {
15021 json_import_vrfs = json_object_new_array();
15022
15023 for (ALL_LIST_ELEMENTS_RO(
15024 bgp->vpn_policy[afi].import_vrf,
15025 node, vname))
15026 json_object_array_add(json_import_vrfs,
15027 json_object_new_string(vname));
15028
15029 json_object_object_add(json, "importFromVrfs",
15030 json_import_vrfs);
15031 dir = BGP_VPN_POLICY_DIR_FROMVPN;
15032 if (bgp->vpn_policy[afi].rtlist[dir]) {
15033 ecom_str = ecommunity_ecom2str(
15034 bgp->vpn_policy[afi].rtlist[dir],
15035 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15036 json_object_string_add(json, "importRts",
15037 ecom_str);
15038 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15039 } else
15040 json_object_string_add(json, "importRts",
15041 "none");
15042 }
15043
15044 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15045 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
15046 json_object_string_add(json, "exportToVrfs", "none");
15047 json_object_string_add(json, "routeDistinguisher",
15048 "none");
15049 json_object_string_add(json, "exportRts", "none");
15050 } else {
15051 json_export_vrfs = json_object_new_array();
15052
15053 for (ALL_LIST_ELEMENTS_RO(
15054 bgp->vpn_policy[afi].export_vrf,
15055 node, vname))
15056 json_object_array_add(json_export_vrfs,
15057 json_object_new_string(vname));
15058 json_object_object_add(json, "exportToVrfs",
15059 json_export_vrfs);
15060 json_object_string_add(json, "routeDistinguisher",
15061 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
15062 buf1, RD_ADDRSTRLEN));
15063
15064 dir = BGP_VPN_POLICY_DIR_TOVPN;
15065 if (bgp->vpn_policy[afi].rtlist[dir]) {
15066 ecom_str = ecommunity_ecom2str(
15067 bgp->vpn_policy[afi].rtlist[dir],
15068 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15069 json_object_string_add(json, "exportRts",
15070 ecom_str);
15071 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15072 } else
15073 json_object_string_add(json, "exportRts",
15074 "none");
15075 }
15076
15077 if (use_json) {
15078 vty_out(vty, "%s\n",
15079 json_object_to_json_string_ext(json,
15080 JSON_C_TO_STRING_PRETTY));
15081 json_object_free(json);
15082 }
15083 } else {
15084 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15085
15086 if (!bgp) {
15087 vty_out(vty, "%% No such BGP instance exist\n");
15088 return CMD_WARNING;
15089 }
15090
15091 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15092 BGP_CONFIG_VRF_TO_VRF_IMPORT))
15093 vty_out(vty,
15094 "This VRF is not importing %s routes from any other VRF\n",
15095 get_afi_safi_str(afi, safi, false));
15096 else {
15097 vty_out(vty,
15098 "This VRF is importing %s routes from the following VRFs:\n",
15099 get_afi_safi_str(afi, safi, false));
15100
15101 for (ALL_LIST_ELEMENTS_RO(
15102 bgp->vpn_policy[afi].import_vrf,
15103 node, vname))
15104 vty_out(vty, " %s\n", vname);
15105
15106 dir = BGP_VPN_POLICY_DIR_FROMVPN;
15107 ecom_str = NULL;
15108 if (bgp->vpn_policy[afi].rtlist[dir]) {
15109 ecom_str = ecommunity_ecom2str(
15110 bgp->vpn_policy[afi].rtlist[dir],
15111 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15112 vty_out(vty, "Import RT(s): %s\n", ecom_str);
15113
15114 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15115 } else
15116 vty_out(vty, "Import RT(s):\n");
15117 }
15118
15119 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15120 BGP_CONFIG_VRF_TO_VRF_EXPORT))
15121 vty_out(vty,
15122 "This VRF is not exporting %s routes to any other VRF\n",
15123 get_afi_safi_str(afi, safi, false));
15124 else {
15125 vty_out(vty,
15126 "This VRF is exporting %s routes to the following VRFs:\n",
15127 get_afi_safi_str(afi, safi, false));
15128
15129 for (ALL_LIST_ELEMENTS_RO(
15130 bgp->vpn_policy[afi].export_vrf,
15131 node, vname))
15132 vty_out(vty, " %s\n", vname);
15133
15134 vty_out(vty, "RD: %s\n",
15135 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
15136 buf1, RD_ADDRSTRLEN));
15137
15138 dir = BGP_VPN_POLICY_DIR_TOVPN;
15139 if (bgp->vpn_policy[afi].rtlist[dir]) {
15140 ecom_str = ecommunity_ecom2str(
15141 bgp->vpn_policy[afi].rtlist[dir],
15142 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15143 vty_out(vty, "Export RT: %s\n", ecom_str);
15144 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15145 } else
15146 vty_out(vty, "Import RT(s):\n");
15147 }
15148 }
15149
15150 return CMD_SUCCESS;
15151 }
15152
15153 static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
15154 safi_t safi, bool use_json)
15155 {
15156 struct listnode *node, *nnode;
15157 struct bgp *bgp;
15158 char *vrf_name = NULL;
15159 json_object *json = NULL;
15160 json_object *json_vrf = NULL;
15161 json_object *json_vrfs = NULL;
15162
15163 if (use_json) {
15164 json = json_object_new_object();
15165 json_vrfs = json_object_new_object();
15166 }
15167
15168 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15169
15170 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
15171 vrf_name = bgp->name;
15172
15173 if (use_json) {
15174 json_vrf = json_object_new_object();
15175 } else {
15176 vty_out(vty, "\nInstance %s:\n",
15177 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15178 ? VRF_DEFAULT_NAME : bgp->name);
15179 }
15180 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
15181 if (use_json) {
15182 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15183 json_object_object_add(json_vrfs,
15184 VRF_DEFAULT_NAME, json_vrf);
15185 else
15186 json_object_object_add(json_vrfs, vrf_name,
15187 json_vrf);
15188 }
15189 }
15190
15191 if (use_json) {
15192 json_object_object_add(json, "vrfs", json_vrfs);
15193 vty_out(vty, "%s\n", json_object_to_json_string_ext(json,
15194 JSON_C_TO_STRING_PRETTY));
15195 json_object_free(json);
15196 }
15197
15198 return CMD_SUCCESS;
15199 }
15200
15201 /* "show [ip] bgp route-leak" command. */
15202 DEFUN (show_ip_bgp_route_leak,
15203 show_ip_bgp_route_leak_cmd,
15204 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
15205 SHOW_STR
15206 IP_STR
15207 BGP_STR
15208 BGP_INSTANCE_HELP_STR
15209 BGP_AFI_HELP_STR
15210 BGP_SAFI_HELP_STR
15211 "Route leaking information\n"
15212 JSON_STR)
15213 {
15214 char *vrf = NULL;
15215 afi_t afi = AFI_MAX;
15216 safi_t safi = SAFI_MAX;
15217
15218 bool uj = use_json(argc, argv);
15219 int idx = 0;
15220 json_object *json = NULL;
15221
15222 /* show [ip] bgp */
15223 if (argv_find(argv, argc, "ip", &idx)) {
15224 afi = AFI_IP;
15225 safi = SAFI_UNICAST;
15226 }
15227 /* [vrf VIEWVRFNAME] */
15228 if (argv_find(argv, argc, "view", &idx)) {
15229 vty_out(vty,
15230 "%% This command is not applicable to BGP views\n");
15231 return CMD_WARNING;
15232 }
15233
15234 if (argv_find(argv, argc, "vrf", &idx)) {
15235 vrf = argv[idx + 1]->arg;
15236 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15237 vrf = NULL;
15238 }
15239 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15240 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
15241 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15242 }
15243
15244 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
15245 vty_out(vty,
15246 "%% This command is applicable only for unicast ipv4|ipv6\n");
15247 return CMD_WARNING;
15248 }
15249
15250 if (vrf && strmatch(vrf, "all"))
15251 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
15252
15253 if (uj)
15254 json = json_object_new_object();
15255
15256 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
15257 }
15258
15259 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
15260 safi_t safi)
15261 {
15262 struct listnode *node, *nnode;
15263 struct bgp *bgp;
15264
15265 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15266 vty_out(vty, "\nInstance %s:\n",
15267 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15268 ? VRF_DEFAULT_NAME
15269 : bgp->name);
15270 update_group_show(bgp, afi, safi, vty, 0);
15271 }
15272 }
15273
15274 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
15275 int safi, uint64_t subgrp_id)
15276 {
15277 struct bgp *bgp;
15278
15279 if (name) {
15280 if (strmatch(name, "all")) {
15281 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
15282 return CMD_SUCCESS;
15283 } else {
15284 bgp = bgp_lookup_by_name(name);
15285 }
15286 } else {
15287 bgp = bgp_get_default();
15288 }
15289
15290 if (bgp)
15291 update_group_show(bgp, afi, safi, vty, subgrp_id);
15292 return CMD_SUCCESS;
15293 }
15294
15295 DEFUN (show_ip_bgp_updgrps,
15296 show_ip_bgp_updgrps_cmd,
15297 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
15298 SHOW_STR
15299 IP_STR
15300 BGP_STR
15301 BGP_INSTANCE_HELP_STR
15302 BGP_AFI_HELP_STR
15303 BGP_SAFI_WITH_LABEL_HELP_STR
15304 "Detailed info about dynamic update groups\n"
15305 "Specific subgroup to display detailed info for\n")
15306 {
15307 char *vrf = NULL;
15308 afi_t afi = AFI_IP6;
15309 safi_t safi = SAFI_UNICAST;
15310 uint64_t subgrp_id = 0;
15311
15312 int idx = 0;
15313
15314 /* show [ip] bgp */
15315 if (argv_find(argv, argc, "ip", &idx))
15316 afi = AFI_IP;
15317 /* [<vrf> VIEWVRFNAME] */
15318 if (argv_find(argv, argc, "vrf", &idx)) {
15319 vrf = argv[idx + 1]->arg;
15320 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15321 vrf = NULL;
15322 } else if (argv_find(argv, argc, "view", &idx))
15323 /* [<view> VIEWVRFNAME] */
15324 vrf = argv[idx + 1]->arg;
15325 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15326 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
15327 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15328 }
15329
15330 /* get subgroup id, if provided */
15331 idx = argc - 1;
15332 if (argv[idx]->type == VARIABLE_TKN)
15333 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
15334
15335 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
15336 }
15337
15338 DEFUN (show_bgp_instance_all_ipv6_updgrps,
15339 show_bgp_instance_all_ipv6_updgrps_cmd,
15340 "show [ip] bgp <view|vrf> all update-groups",
15341 SHOW_STR
15342 IP_STR
15343 BGP_STR
15344 BGP_INSTANCE_ALL_HELP_STR
15345 "Detailed info about dynamic update groups\n")
15346 {
15347 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
15348 return CMD_SUCCESS;
15349 }
15350
15351 DEFUN (show_bgp_l2vpn_evpn_updgrps,
15352 show_bgp_l2vpn_evpn_updgrps_cmd,
15353 "show [ip] bgp l2vpn evpn update-groups",
15354 SHOW_STR
15355 IP_STR
15356 BGP_STR
15357 "l2vpn address family\n"
15358 "evpn sub-address family\n"
15359 "Detailed info about dynamic update groups\n")
15360 {
15361 char *vrf = NULL;
15362 uint64_t subgrp_id = 0;
15363
15364 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
15365 return CMD_SUCCESS;
15366 }
15367
15368 DEFUN (show_bgp_updgrps_stats,
15369 show_bgp_updgrps_stats_cmd,
15370 "show [ip] bgp update-groups statistics",
15371 SHOW_STR
15372 IP_STR
15373 BGP_STR
15374 "Detailed info about dynamic update groups\n"
15375 "Statistics\n")
15376 {
15377 struct bgp *bgp;
15378
15379 bgp = bgp_get_default();
15380 if (bgp)
15381 update_group_show_stats(bgp, vty);
15382
15383 return CMD_SUCCESS;
15384 }
15385
15386 DEFUN (show_bgp_instance_updgrps_stats,
15387 show_bgp_instance_updgrps_stats_cmd,
15388 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
15389 SHOW_STR
15390 IP_STR
15391 BGP_STR
15392 BGP_INSTANCE_HELP_STR
15393 "Detailed info about dynamic update groups\n"
15394 "Statistics\n")
15395 {
15396 int idx_word = 3;
15397 struct bgp *bgp;
15398
15399 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
15400 if (bgp)
15401 update_group_show_stats(bgp, vty);
15402
15403 return CMD_SUCCESS;
15404 }
15405
15406 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
15407 afi_t afi, safi_t safi,
15408 const char *what, uint64_t subgrp_id)
15409 {
15410 struct bgp *bgp;
15411
15412 if (name)
15413 bgp = bgp_lookup_by_name(name);
15414 else
15415 bgp = bgp_get_default();
15416
15417 if (bgp) {
15418 if (!strcmp(what, "advertise-queue"))
15419 update_group_show_adj_queue(bgp, afi, safi, vty,
15420 subgrp_id);
15421 else if (!strcmp(what, "advertised-routes"))
15422 update_group_show_advertised(bgp, afi, safi, vty,
15423 subgrp_id);
15424 else if (!strcmp(what, "packet-queue"))
15425 update_group_show_packet_queue(bgp, afi, safi, vty,
15426 subgrp_id);
15427 }
15428 }
15429
15430 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
15431 show_ip_bgp_instance_updgrps_adj_s_cmd,
15432 "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",
15433 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
15434 BGP_SAFI_HELP_STR
15435 "Detailed info about dynamic update groups\n"
15436 "Specific subgroup to display info for\n"
15437 "Advertisement queue\n"
15438 "Announced routes\n"
15439 "Packet queue\n")
15440 {
15441 uint64_t subgrp_id = 0;
15442 afi_t afiz;
15443 safi_t safiz;
15444 if (sgid)
15445 subgrp_id = strtoull(sgid, NULL, 10);
15446
15447 if (!ip && !afi)
15448 afiz = AFI_IP6;
15449 if (!ip && afi)
15450 afiz = bgp_vty_afi_from_str(afi);
15451 if (ip && !afi)
15452 afiz = AFI_IP;
15453 if (ip && afi) {
15454 afiz = bgp_vty_afi_from_str(afi);
15455 if (afiz != AFI_IP)
15456 vty_out(vty,
15457 "%% Cannot specify both 'ip' and 'ipv6'\n");
15458 return CMD_WARNING;
15459 }
15460
15461 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
15462
15463 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
15464 return CMD_SUCCESS;
15465 }
15466
15467 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
15468 {
15469 struct listnode *node, *nnode;
15470 struct prefix *range;
15471 struct peer *conf;
15472 struct peer *peer;
15473 afi_t afi;
15474 safi_t safi;
15475 const char *peer_status;
15476 const char *af_str;
15477 int lr_count;
15478 int dynamic;
15479 int af_cfgd;
15480
15481 conf = group->conf;
15482
15483 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
15484 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15485 group->name, conf->as);
15486 } else if (conf->as_type == AS_INTERNAL) {
15487 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15488 group->name, group->bgp->as);
15489 } else {
15490 vty_out(vty, "\nBGP peer-group %s\n", group->name);
15491 }
15492
15493 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
15494 vty_out(vty, " Peer-group type is internal\n");
15495 else
15496 vty_out(vty, " Peer-group type is external\n");
15497
15498 /* Display AFs configured. */
15499 vty_out(vty, " Configured address-families:");
15500 FOREACH_AFI_SAFI (afi, safi) {
15501 if (conf->afc[afi][safi]) {
15502 af_cfgd = 1;
15503 vty_out(vty, " %s;", get_afi_safi_str(afi, safi, false));
15504 }
15505 }
15506 if (!af_cfgd)
15507 vty_out(vty, " none\n");
15508 else
15509 vty_out(vty, "\n");
15510
15511 /* Display listen ranges (for dynamic neighbors), if any */
15512 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
15513 if (afi == AFI_IP)
15514 af_str = "IPv4";
15515 else if (afi == AFI_IP6)
15516 af_str = "IPv6";
15517 else
15518 af_str = "???";
15519 lr_count = listcount(group->listen_range[afi]);
15520 if (lr_count) {
15521 vty_out(vty, " %d %s listen range(s)\n", lr_count,
15522 af_str);
15523
15524
15525 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
15526 nnode, range))
15527 vty_out(vty, " %pFX\n", range);
15528 }
15529 }
15530
15531 /* Display group members and their status */
15532 if (listcount(group->peer)) {
15533 vty_out(vty, " Peer-group members:\n");
15534 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
15535 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
15536 || CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHUTDOWN))
15537 peer_status = "Idle (Admin)";
15538 else if (CHECK_FLAG(peer->sflags,
15539 PEER_STATUS_PREFIX_OVERFLOW))
15540 peer_status = "Idle (PfxCt)";
15541 else
15542 peer_status = lookup_msg(bgp_status_msg,
15543 peer->status, NULL);
15544
15545 dynamic = peer_dynamic_neighbor(peer);
15546 vty_out(vty, " %s %s %s \n", peer->host,
15547 dynamic ? "(dynamic)" : "", peer_status);
15548 }
15549 }
15550
15551 return CMD_SUCCESS;
15552 }
15553
15554 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
15555 const char *group_name)
15556 {
15557 struct bgp *bgp;
15558 struct listnode *node, *nnode;
15559 struct peer_group *group;
15560 bool found = false;
15561
15562 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15563
15564 if (!bgp) {
15565 vty_out(vty, "%% BGP instance not found\n");
15566 return CMD_WARNING;
15567 }
15568
15569 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
15570 if (group_name) {
15571 if (strmatch(group->name, group_name)) {
15572 bgp_show_one_peer_group(vty, group);
15573 found = true;
15574 break;
15575 }
15576 } else {
15577 bgp_show_one_peer_group(vty, group);
15578 }
15579 }
15580
15581 if (group_name && !found)
15582 vty_out(vty, "%% No such peer-group\n");
15583
15584 return CMD_SUCCESS;
15585 }
15586
15587 DEFUN (show_ip_bgp_peer_groups,
15588 show_ip_bgp_peer_groups_cmd,
15589 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
15590 SHOW_STR
15591 IP_STR
15592 BGP_STR
15593 BGP_INSTANCE_HELP_STR
15594 "Detailed information on BGP peer groups\n"
15595 "Peer group name\n")
15596 {
15597 char *vrf, *pg;
15598 int idx = 0;
15599
15600 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
15601 : NULL;
15602 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
15603
15604 return bgp_show_peer_group_vty(vty, vrf, pg);
15605 }
15606
15607
15608 /* Redistribute VTY commands. */
15609
15610 DEFUN_YANG (bgp_redistribute_ipv4,
15611 bgp_redistribute_ipv4_cmd,
15612 "redistribute " FRR_IP_REDIST_STR_BGPD,
15613 "Redistribute information from another routing protocol\n"
15614 FRR_IP_REDIST_HELP_STR_BGPD)
15615 {
15616 int idx_protocol = 1;
15617 char base_xpath[XPATH_MAXLEN];
15618
15619 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15620 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15621 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15622 argv[idx_protocol]->text, "0");
15623
15624 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15625
15626 return nb_cli_apply_changes(vty, base_xpath);
15627 }
15628
15629 ALIAS_HIDDEN(
15630 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
15631 "redistribute " FRR_IP_REDIST_STR_BGPD,
15632 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
15633
15634 DEFUN_YANG (bgp_redistribute_ipv4_rmap,
15635 bgp_redistribute_ipv4_rmap_cmd,
15636 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
15637 "Redistribute information from another routing protocol\n"
15638 FRR_IP_REDIST_HELP_STR_BGPD
15639 "Route map reference\n"
15640 "Pointer to route-map entries\n")
15641 {
15642 int idx_protocol = 1;
15643 int idx_word = 3;
15644 char base_xpath[XPATH_MAXLEN];
15645
15646 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15647 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15648 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15649 argv[idx_protocol]->text, "0");
15650
15651 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15652 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15653 argv[idx_word]->arg);
15654
15655 return nb_cli_apply_changes(vty, base_xpath);
15656 }
15657
15658 ALIAS_HIDDEN(
15659 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
15660 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
15661 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15662 "Route map reference\n"
15663 "Pointer to route-map entries\n")
15664
15665 DEFUN_YANG (bgp_redistribute_ipv4_metric,
15666 bgp_redistribute_ipv4_metric_cmd,
15667 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15668 "Redistribute information from another routing protocol\n"
15669 FRR_IP_REDIST_HELP_STR_BGPD
15670 "Metric for redistributed routes\n"
15671 "Default metric\n")
15672 {
15673 int idx_protocol = 1;
15674 int idx_number = 3;
15675 char base_xpath[XPATH_MAXLEN];
15676
15677 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15678 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15679 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15680 argv[idx_protocol]->text, "0");
15681
15682 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15683 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15684 argv[idx_number]->arg);
15685
15686 return nb_cli_apply_changes(vty, base_xpath);
15687 }
15688
15689 ALIAS_HIDDEN(
15690 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
15691 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15692 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15693 "Metric for redistributed routes\n"
15694 "Default metric\n")
15695
15696 DEFUN_YANG(
15697 bgp_redistribute_ipv4_rmap_metric,
15698 bgp_redistribute_ipv4_rmap_metric_cmd,
15699 "redistribute " FRR_IP_REDIST_STR_BGPD
15700 " route-map WORD metric (0-4294967295)",
15701 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15702 "Route map reference\n"
15703 "Pointer to route-map entries\n"
15704 "Metric for redistributed routes\n"
15705 "Default metric\n")
15706 {
15707 int idx_protocol = 1;
15708 int idx_word = 3;
15709 int idx_number = 5;
15710 char base_xpath[XPATH_MAXLEN];
15711
15712 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15713 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15714 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15715 argv[idx_protocol]->text, "0");
15716
15717 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15718 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15719 argv[idx_word]->arg);
15720 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15721 argv[idx_number]->arg);
15722
15723 return nb_cli_apply_changes(vty, base_xpath);
15724 }
15725
15726 ALIAS_HIDDEN(
15727 bgp_redistribute_ipv4_rmap_metric,
15728 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
15729 "redistribute " FRR_IP_REDIST_STR_BGPD
15730 " route-map WORD metric (0-4294967295)",
15731 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15732 "Route map reference\n"
15733 "Pointer to route-map entries\n"
15734 "Metric for redistributed routes\n"
15735 "Default metric\n")
15736
15737 DEFUN_YANG(
15738 bgp_redistribute_ipv4_metric_rmap,
15739 bgp_redistribute_ipv4_metric_rmap_cmd,
15740 "redistribute " FRR_IP_REDIST_STR_BGPD
15741 " metric (0-4294967295) route-map WORD",
15742 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15743 "Metric for redistributed routes\n"
15744 "Default metric\n"
15745 "Route map reference\n"
15746 "Pointer to route-map entries\n")
15747 {
15748 int idx_protocol = 1;
15749 int idx_word = 5;
15750 int idx_number = 3;
15751 char base_xpath[XPATH_MAXLEN];
15752
15753 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15754 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15755 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15756 argv[idx_protocol]->text, "0");
15757
15758 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15759 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15760 argv[idx_number]->arg);
15761 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15762 argv[idx_word]->arg);
15763
15764 return nb_cli_apply_changes(vty, base_xpath);
15765 }
15766
15767 ALIAS_HIDDEN(
15768 bgp_redistribute_ipv4_metric_rmap,
15769 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
15770 "redistribute " FRR_IP_REDIST_STR_BGPD
15771 " metric (0-4294967295) route-map WORD",
15772 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15773 "Metric for redistributed routes\n"
15774 "Default metric\n"
15775 "Route map reference\n"
15776 "Pointer to route-map entries\n")
15777
15778 DEFUN_YANG (bgp_redistribute_ipv4_ospf,
15779 bgp_redistribute_ipv4_ospf_cmd,
15780 "redistribute <ospf|table> (1-65535)",
15781 "Redistribute information from another routing protocol\n"
15782 "Open Shortest Path First (OSPFv2)\n"
15783 "Non-main Kernel Routing Table\n"
15784 "Instance ID/Table ID\n")
15785 {
15786 int idx_protocol = 1;
15787 int idx_number = 2;
15788 char base_xpath[XPATH_MAXLEN];
15789
15790 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15791 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15792 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15793 argv[idx_protocol]->text, argv[idx_number]->arg);
15794
15795 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15796
15797 return nb_cli_apply_changes(vty, base_xpath);
15798 }
15799
15800 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
15801 "redistribute <ospf|table> (1-65535)",
15802 "Redistribute information from another routing protocol\n"
15803 "Open Shortest Path First (OSPFv2)\n"
15804 "Non-main Kernel Routing Table\n"
15805 "Instance ID/Table ID\n")
15806
15807 DEFUN_YANG (bgp_redistribute_ipv4_ospf_rmap,
15808 bgp_redistribute_ipv4_ospf_rmap_cmd,
15809 "redistribute <ospf|table> (1-65535) route-map WORD",
15810 "Redistribute information from another routing protocol\n"
15811 "Open Shortest Path First (OSPFv2)\n"
15812 "Non-main Kernel Routing Table\n"
15813 "Instance ID/Table ID\n"
15814 "Route map reference\n"
15815 "Pointer to route-map entries\n")
15816 {
15817 int idx_protocol = 1;
15818 int idx_number = 2;
15819 int idx_word = 4;
15820 char base_xpath[XPATH_MAXLEN];
15821
15822 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15823 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15824 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15825 argv[idx_protocol]->text, argv[idx_number]->arg);
15826
15827 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15828
15829 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15830 argv[idx_word]->arg);
15831
15832 return nb_cli_apply_changes(vty, base_xpath);
15833 }
15834
15835 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
15836 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
15837 "redistribute <ospf|table> (1-65535) route-map WORD",
15838 "Redistribute information from another routing protocol\n"
15839 "Open Shortest Path First (OSPFv2)\n"
15840 "Non-main Kernel Routing Table\n"
15841 "Instance ID/Table ID\n"
15842 "Route map reference\n"
15843 "Pointer to route-map entries\n")
15844
15845 DEFUN_YANG(bgp_redistribute_ipv4_ospf_metric,
15846 bgp_redistribute_ipv4_ospf_metric_cmd,
15847 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
15848 "Redistribute information from another routing protocol\n"
15849 "Open Shortest Path First (OSPFv2)\n"
15850 "Non-main Kernel Routing Table\n"
15851 "Instance ID/Table ID\n"
15852 "Metric for redistributed routes\n"
15853 "Default metric\n")
15854 {
15855 int idx_protocol = 1;
15856 int idx_number = 2;
15857 int idx_number_2 = 4;
15858 char base_xpath[XPATH_MAXLEN];
15859
15860 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15861 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15862 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15863 argv[idx_protocol]->text, argv[idx_number]->arg);
15864
15865 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15866
15867 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15868 argv[idx_number_2]->arg);
15869
15870 return nb_cli_apply_changes(vty, base_xpath);
15871 }
15872
15873 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
15874 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
15875 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
15876 "Redistribute information from another routing protocol\n"
15877 "Open Shortest Path First (OSPFv2)\n"
15878 "Non-main Kernel Routing Table\n"
15879 "Instance ID/Table ID\n"
15880 "Metric for redistributed routes\n"
15881 "Default metric\n")
15882
15883 DEFUN_YANG(
15884 bgp_redistribute_ipv4_ospf_rmap_metric,
15885 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
15886 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
15887 "Redistribute information from another routing protocol\n"
15888 "Open Shortest Path First (OSPFv2)\n"
15889 "Non-main Kernel Routing Table\n"
15890 "Instance ID/Table ID\n"
15891 "Route map reference\n"
15892 "Pointer to route-map entries\n"
15893 "Metric for redistributed routes\n"
15894 "Default metric\n")
15895 {
15896 int idx_protocol = 1;
15897 int idx_number = 2;
15898 int idx_word = 4;
15899 int idx_number_2 = 6;
15900 char base_xpath[XPATH_MAXLEN];
15901
15902 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15903 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15904 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15905 argv[idx_protocol]->text, argv[idx_number]->arg);
15906
15907 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15908
15909 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15910 argv[idx_word]->arg);
15911 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15912 argv[idx_number_2]->arg);
15913
15914 return nb_cli_apply_changes(vty, base_xpath);
15915 }
15916
15917 ALIAS_HIDDEN(
15918 bgp_redistribute_ipv4_ospf_rmap_metric,
15919 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
15920 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
15921 "Redistribute information from another routing protocol\n"
15922 "Open Shortest Path First (OSPFv2)\n"
15923 "Non-main Kernel Routing Table\n"
15924 "Instance ID/Table ID\n"
15925 "Route map reference\n"
15926 "Pointer to route-map entries\n"
15927 "Metric for redistributed routes\n"
15928 "Default metric\n")
15929
15930 DEFUN_YANG(
15931 bgp_redistribute_ipv4_ospf_metric_rmap,
15932 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
15933 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
15934 "Redistribute information from another routing protocol\n"
15935 "Open Shortest Path First (OSPFv2)\n"
15936 "Non-main Kernel Routing Table\n"
15937 "Instance ID/Table ID\n"
15938 "Metric for redistributed routes\n"
15939 "Default metric\n"
15940 "Route map reference\n"
15941 "Pointer to route-map entries\n")
15942 {
15943 int idx_protocol = 1;
15944 int idx_number = 2;
15945 int idx_number_2 = 4;
15946 int idx_word = 6;
15947 char base_xpath[XPATH_MAXLEN];
15948
15949 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15950 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15951 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15952 argv[idx_protocol]->text, argv[idx_number]->arg);
15953
15954 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15955
15956 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15957 argv[idx_number_2]->arg);
15958 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15959 argv[idx_word]->arg);
15960
15961 return nb_cli_apply_changes(vty, base_xpath);
15962 }
15963
15964 ALIAS_HIDDEN(
15965 bgp_redistribute_ipv4_ospf_metric_rmap,
15966 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
15967 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
15968 "Redistribute information from another routing protocol\n"
15969 "Open Shortest Path First (OSPFv2)\n"
15970 "Non-main Kernel Routing Table\n"
15971 "Instance ID/Table ID\n"
15972 "Metric for redistributed routes\n"
15973 "Default metric\n"
15974 "Route map reference\n"
15975 "Pointer to route-map entries\n")
15976
15977 DEFUN_YANG (no_bgp_redistribute_ipv4_ospf,
15978 no_bgp_redistribute_ipv4_ospf_cmd,
15979 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
15980 NO_STR
15981 "Redistribute information from another routing protocol\n"
15982 "Open Shortest Path First (OSPFv2)\n"
15983 "Non-main Kernel Routing Table\n"
15984 "Instance ID/Table ID\n"
15985 "Metric for redistributed routes\n"
15986 "Default metric\n"
15987 "Route map reference\n"
15988 "Pointer to route-map entries\n")
15989 {
15990 int idx_protocol = 2;
15991 int idx_number = 3;
15992 char base_xpath[XPATH_MAXLEN];
15993
15994 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15995 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15996 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15997 argv[idx_protocol]->text, argv[idx_number]->arg);
15998
15999 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
16000
16001 return nb_cli_apply_changes(vty, base_xpath);
16002 }
16003
16004 ALIAS_HIDDEN(
16005 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
16006 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
16007 NO_STR
16008 "Redistribute information from another routing protocol\n"
16009 "Open Shortest Path First (OSPFv2)\n"
16010 "Non-main Kernel Routing Table\n"
16011 "Instance ID/Table ID\n"
16012 "Metric for redistributed routes\n"
16013 "Default metric\n"
16014 "Route map reference\n"
16015 "Pointer to route-map entries\n")
16016
16017 DEFUN_YANG (no_bgp_redistribute_ipv4,
16018 no_bgp_redistribute_ipv4_cmd,
16019 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
16020 NO_STR
16021 "Redistribute information from another routing protocol\n"
16022 FRR_IP_REDIST_HELP_STR_BGPD
16023 "Metric for redistributed routes\n"
16024 "Default metric\n"
16025 "Route map reference\n"
16026 "Pointer to route-map entries\n")
16027 {
16028 int idx_protocol = 2;
16029 char base_xpath[XPATH_MAXLEN];
16030
16031 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16032 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16033 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16034 argv[idx_protocol]->text, "0");
16035
16036 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
16037
16038 return nb_cli_apply_changes(vty, base_xpath);
16039 }
16040
16041 ALIAS_HIDDEN(
16042 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
16043 "no redistribute " FRR_IP_REDIST_STR_BGPD
16044 " [{metric (0-4294967295)|route-map WORD}]",
16045 NO_STR
16046 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16047 "Metric for redistributed routes\n"
16048 "Default metric\n"
16049 "Route map reference\n"
16050 "Pointer to route-map entries\n")
16051
16052 DEFUN_YANG (bgp_redistribute_ipv6,
16053 bgp_redistribute_ipv6_cmd,
16054 "redistribute " FRR_IP6_REDIST_STR_BGPD,
16055 "Redistribute information from another routing protocol\n"
16056 FRR_IP6_REDIST_HELP_STR_BGPD)
16057 {
16058 int idx_protocol = 1;
16059 char base_xpath[XPATH_MAXLEN];
16060
16061 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16062 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16063 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16064 argv[idx_protocol]->text, "0");
16065
16066 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16067
16068 return nb_cli_apply_changes(vty, base_xpath);
16069 }
16070
16071 DEFUN_YANG (bgp_redistribute_ipv6_rmap,
16072 bgp_redistribute_ipv6_rmap_cmd,
16073 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
16074 "Redistribute information from another routing protocol\n"
16075 FRR_IP6_REDIST_HELP_STR_BGPD
16076 "Route map reference\n"
16077 "Pointer to route-map entries\n")
16078 {
16079 int idx_protocol = 1;
16080 int idx_word = 3;
16081 char base_xpath[XPATH_MAXLEN];
16082
16083 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16084 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16085 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16086 argv[idx_protocol]->text, "0");
16087
16088 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16089 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16090 argv[idx_word]->arg);
16091
16092 return nb_cli_apply_changes(vty, base_xpath);
16093 }
16094
16095 DEFUN_YANG (bgp_redistribute_ipv6_metric,
16096 bgp_redistribute_ipv6_metric_cmd,
16097 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
16098 "Redistribute information from another routing protocol\n"
16099 FRR_IP6_REDIST_HELP_STR_BGPD
16100 "Metric for redistributed routes\n"
16101 "Default metric\n")
16102 {
16103 int idx_protocol = 1;
16104 int idx_number = 3;
16105 char base_xpath[XPATH_MAXLEN];
16106
16107 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16108 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16109 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16110 argv[idx_protocol]->text, "0");
16111
16112 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16113 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16114 argv[idx_number]->arg);
16115
16116 return nb_cli_apply_changes(vty, base_xpath);
16117 }
16118
16119 DEFUN_YANG(
16120 bgp_redistribute_ipv6_rmap_metric,
16121 bgp_redistribute_ipv6_rmap_metric_cmd,
16122 "redistribute " FRR_IP6_REDIST_STR_BGPD
16123 " route-map WORD metric (0-4294967295)",
16124 "Redistribute information from another routing protocol\n" FRR_IP6_REDIST_HELP_STR_BGPD
16125 "Route map reference\n"
16126 "Pointer to route-map entries\n"
16127 "Metric for redistributed routes\n"
16128 "Default metric\n")
16129 {
16130 int idx_protocol = 1;
16131 int idx_word = 3;
16132 int idx_number = 5;
16133 char base_xpath[XPATH_MAXLEN];
16134
16135 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16136 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16137 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16138 argv[idx_protocol]->text, "0");
16139
16140 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16141 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16142 argv[idx_word]->arg);
16143 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16144 argv[idx_number]->arg);
16145
16146 return nb_cli_apply_changes(vty, base_xpath);
16147 }
16148
16149 DEFUN_YANG(
16150 bgp_redistribute_ipv6_metric_rmap,
16151 bgp_redistribute_ipv6_metric_rmap_cmd,
16152 "redistribute " FRR_IP6_REDIST_STR_BGPD
16153 " metric (0-4294967295) route-map WORD",
16154 "Redistribute information from another routing protocol\n" FRR_IP6_REDIST_HELP_STR_BGPD
16155 "Metric for redistributed routes\n"
16156 "Default metric\n"
16157 "Route map reference\n"
16158 "Pointer to route-map entries\n")
16159 {
16160 int idx_protocol = 1;
16161 int idx_word = 5;
16162 int idx_number = 3;
16163 char base_xpath[XPATH_MAXLEN];
16164
16165 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16166 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16167 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16168 argv[idx_protocol]->text, "0");
16169
16170 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16171 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16172 argv[idx_number]->arg);
16173 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16174 argv[idx_word]->arg);
16175
16176 return nb_cli_apply_changes(vty, base_xpath);
16177 }
16178
16179 DEFUN_YANG(
16180 no_bgp_redistribute_ipv6,
16181 no_bgp_redistribute_ipv6_cmd,
16182 "no redistribute " FRR_IP6_REDIST_STR_BGPD
16183 " [{metric (0-4294967295)|route-map WORD}]",
16184 NO_STR
16185 "Redistribute information from another routing protocol\n" FRR_IP6_REDIST_HELP_STR_BGPD
16186 "Metric for redistributed routes\n"
16187 "Default metric\n"
16188 "Route map reference\n"
16189 "Pointer to route-map entries\n")
16190 {
16191 int idx_protocol = 2;
16192 char base_xpath[XPATH_MAXLEN];
16193
16194 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16195 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16196 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16197 argv[idx_protocol]->text, "0");
16198
16199 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
16200
16201 return nb_cli_apply_changes(vty, base_xpath);
16202 }
16203
16204 void cli_show_bgp_global_afi_safi_ip_unicast_redistribution_list(
16205 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
16206 {
16207 uint32_t instance = 0;
16208
16209 vty_out(vty, " redistribute %s",
16210 yang_dnode_get_string(dnode, "./route-type"));
16211 if ((instance = yang_dnode_get_uint16(dnode, "./route-instance")))
16212 vty_out(vty, " %d", instance);
16213 if (yang_dnode_exists(dnode, "./metric"))
16214 vty_out(vty, " metric %u",
16215 yang_dnode_get_uint32(dnode, "./metric"));
16216 if (yang_dnode_exists(dnode, "./rmap-policy-import"))
16217 vty_out(vty, " route-map %s",
16218 yang_dnode_get_string(dnode, "./rmap-policy-import"));
16219 vty_out(vty, "\n");
16220 }
16221
16222 static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
16223 afi_t afi, safi_t safi)
16224 {
16225 int i;
16226
16227 /* Unicast redistribution only. */
16228 if (safi != SAFI_UNICAST)
16229 return;
16230
16231 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
16232 /* Redistribute BGP does not make sense. */
16233 if (i != ZEBRA_ROUTE_BGP) {
16234 struct list *red_list;
16235 struct listnode *node;
16236 struct bgp_redist *red;
16237
16238 red_list = bgp->redist[afi][i];
16239 if (!red_list)
16240 continue;
16241
16242 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
16243 /* "redistribute" configuration. */
16244 vty_out(vty, " redistribute %s",
16245 zebra_route_string(i));
16246 if (red->instance)
16247 vty_out(vty, " %d", red->instance);
16248 if (red->redist_metric_flag)
16249 vty_out(vty, " metric %u",
16250 red->redist_metric);
16251 if (red->rmap.name)
16252 vty_out(vty, " route-map %s",
16253 red->rmap.name);
16254 vty_out(vty, "\n");
16255 }
16256 }
16257 }
16258 }
16259
16260 /* peer-group helpers for config-write */
16261
16262 static bool peergroup_flag_check(struct peer *peer, uint32_t flag)
16263 {
16264 if (!peer_group_active(peer)) {
16265 if (CHECK_FLAG(peer->flags_invert, flag))
16266 return !CHECK_FLAG(peer->flags, flag);
16267 else
16268 return !!CHECK_FLAG(peer->flags, flag);
16269 }
16270
16271 return !!CHECK_FLAG(peer->flags_override, flag);
16272 }
16273
16274 static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
16275 uint32_t flag)
16276 {
16277 if (!peer_group_active(peer)) {
16278 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
16279 return !peer_af_flag_check(peer, afi, safi, flag);
16280 else
16281 return !!peer_af_flag_check(peer, afi, safi, flag);
16282 }
16283
16284 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
16285 }
16286
16287 static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
16288 uint8_t type, int direct)
16289 {
16290 struct bgp_filter *filter;
16291
16292 if (peer_group_active(peer))
16293 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
16294 type);
16295
16296 filter = &peer->filter[afi][safi];
16297 switch (type) {
16298 case PEER_FT_DISTRIBUTE_LIST:
16299 return !!(filter->dlist[direct].name);
16300 case PEER_FT_FILTER_LIST:
16301 return !!(filter->aslist[direct].name);
16302 case PEER_FT_PREFIX_LIST:
16303 return !!(filter->plist[direct].name);
16304 case PEER_FT_ROUTE_MAP:
16305 return !!(filter->map[direct].name);
16306 case PEER_FT_UNSUPPRESS_MAP:
16307 return !!(filter->usmap.name);
16308 case PEER_FT_ADVERTISE_MAP:
16309 return !!(filter->advmap.aname
16310 && ((filter->advmap.condition == direct)
16311 && filter->advmap.cname));
16312 default:
16313 return false;
16314 }
16315 }
16316
16317 /* Return true if the addpath type is set for peer and different from
16318 * peer-group.
16319 */
16320 static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi,
16321 safi_t safi)
16322 {
16323 enum bgp_addpath_strat type, g_type;
16324
16325 type = peer->addpath_type[afi][safi];
16326
16327 if (type != BGP_ADDPATH_NONE) {
16328 if (peer_group_active(peer)) {
16329 g_type = peer->group->conf->addpath_type[afi][safi];
16330
16331 if (type != g_type)
16332 return true;
16333 else
16334 return false;
16335 }
16336
16337 return true;
16338 }
16339
16340 return false;
16341 }
16342
16343 /* This is part of the address-family block (unicast only) */
16344 static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
16345 afi_t afi)
16346 {
16347 int indent = 2;
16348
16349 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
16350 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16351 BGP_CONFIG_VRF_TO_VRF_IMPORT))
16352 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
16353 bgp->vpn_policy[afi]
16354 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16355 else
16356 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
16357 bgp->vpn_policy[afi]
16358 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16359 }
16360 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16361 BGP_CONFIG_VRF_TO_VRF_IMPORT)
16362 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16363 BGP_CONFIG_VRF_TO_VRF_EXPORT))
16364 return;
16365
16366 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16367 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
16368
16369 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
16370
16371 } else {
16372 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
16373 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
16374 bgp->vpn_policy[afi].tovpn_label);
16375 }
16376 }
16377 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16378 BGP_VPN_POLICY_TOVPN_RD_SET)) {
16379 char buf[RD_ADDRSTRLEN];
16380 vty_out(vty, "%*srd vpn export %s\n", indent, "",
16381 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
16382 sizeof(buf)));
16383 }
16384 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16385 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
16386
16387 char buf[PREFIX_STRLEN];
16388 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
16389 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
16390 sizeof(buf))) {
16391
16392 vty_out(vty, "%*snexthop vpn export %s\n",
16393 indent, "", buf);
16394 }
16395 }
16396 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
16397 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
16398 && ecommunity_cmp(
16399 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16400 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
16401
16402 char *b = ecommunity_ecom2str(
16403 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16404 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
16405 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
16406 XFREE(MTYPE_ECOMMUNITY_STR, b);
16407 } else {
16408 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
16409 char *b = ecommunity_ecom2str(
16410 bgp->vpn_policy[afi]
16411 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16412 ECOMMUNITY_FORMAT_ROUTE_MAP,
16413 ECOMMUNITY_ROUTE_TARGET);
16414 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
16415 XFREE(MTYPE_ECOMMUNITY_STR, b);
16416 }
16417 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
16418 char *b = ecommunity_ecom2str(
16419 bgp->vpn_policy[afi]
16420 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16421 ECOMMUNITY_FORMAT_ROUTE_MAP,
16422 ECOMMUNITY_ROUTE_TARGET);
16423 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
16424 XFREE(MTYPE_ECOMMUNITY_STR, b);
16425 }
16426 }
16427
16428 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
16429 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
16430 bgp->vpn_policy[afi]
16431 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
16432
16433 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
16434 char *b = ecommunity_ecom2str(
16435 bgp->vpn_policy[afi]
16436 .import_redirect_rtlist,
16437 ECOMMUNITY_FORMAT_ROUTE_MAP,
16438 ECOMMUNITY_ROUTE_TARGET);
16439
16440 if (bgp->vpn_policy[afi].import_redirect_rtlist->unit_size
16441 != ECOMMUNITY_SIZE)
16442 vty_out(vty, "%*srt6 redirect import %s\n",
16443 indent, "", b);
16444 else
16445 vty_out(vty, "%*srt redirect import %s\n",
16446 indent, "", b);
16447 XFREE(MTYPE_ECOMMUNITY_STR, b);
16448 }
16449 }
16450
16451 static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
16452 afi_t afi, safi_t safi)
16453 {
16454 struct bgp_filter *filter;
16455 char *addr;
16456
16457 addr = peer->host;
16458 filter = &peer->filter[afi][safi];
16459
16460 /* distribute-list. */
16461 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16462 FILTER_IN))
16463 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
16464 filter->dlist[FILTER_IN].name);
16465
16466 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16467 FILTER_OUT))
16468 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
16469 filter->dlist[FILTER_OUT].name);
16470
16471 /* prefix-list. */
16472 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16473 FILTER_IN))
16474 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
16475 filter->plist[FILTER_IN].name);
16476
16477 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16478 FILTER_OUT))
16479 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
16480 filter->plist[FILTER_OUT].name);
16481
16482 /* route-map. */
16483 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
16484 vty_out(vty, " neighbor %s route-map %s in\n", addr,
16485 filter->map[RMAP_IN].name);
16486
16487 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
16488 RMAP_OUT))
16489 vty_out(vty, " neighbor %s route-map %s out\n", addr,
16490 filter->map[RMAP_OUT].name);
16491
16492 /* unsuppress-map */
16493 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
16494 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
16495 filter->usmap.name);
16496
16497 /* advertise-map : always applied in OUT direction*/
16498 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16499 CONDITION_NON_EXIST))
16500 vty_out(vty,
16501 " neighbor %s advertise-map %s non-exist-map %s\n",
16502 addr, filter->advmap.aname, filter->advmap.cname);
16503
16504 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16505 CONDITION_EXIST))
16506 vty_out(vty, " neighbor %s advertise-map %s exist-map %s\n",
16507 addr, filter->advmap.aname, filter->advmap.cname);
16508
16509 /* filter-list. */
16510 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16511 FILTER_IN))
16512 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
16513 filter->aslist[FILTER_IN].name);
16514
16515 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16516 FILTER_OUT))
16517 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
16518 filter->aslist[FILTER_OUT].name);
16519 }
16520
16521 /* BGP peer configuration display function. */
16522 static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
16523 struct peer *peer)
16524 {
16525 struct peer *g_peer = NULL;
16526 char buf[SU_ADDRSTRLEN];
16527 char *addr;
16528 int if_pg_printed = false;
16529 int if_ras_printed = false;
16530
16531 /* Skip dynamic neighbors. */
16532 if (peer_dynamic_neighbor(peer))
16533 return;
16534
16535 if (peer->conf_if)
16536 addr = peer->conf_if;
16537 else
16538 addr = peer->host;
16539
16540 /************************************
16541 ****** Global to the neighbor ******
16542 ************************************/
16543 if (peer->conf_if) {
16544 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
16545 vty_out(vty, " neighbor %s interface v6only", addr);
16546 else
16547 vty_out(vty, " neighbor %s interface", addr);
16548
16549 if (peer_group_active(peer)) {
16550 vty_out(vty, " peer-group %s", peer->group->name);
16551 if_pg_printed = true;
16552 } else if (peer->as_type == AS_SPECIFIED) {
16553 vty_out(vty, " remote-as %u", peer->as);
16554 if_ras_printed = true;
16555 } else if (peer->as_type == AS_INTERNAL) {
16556 vty_out(vty, " remote-as internal");
16557 if_ras_printed = true;
16558 } else if (peer->as_type == AS_EXTERNAL) {
16559 vty_out(vty, " remote-as external");
16560 if_ras_printed = true;
16561 }
16562
16563 vty_out(vty, "\n");
16564 }
16565
16566 /* remote-as and peer-group */
16567 /* peer is a member of a peer-group */
16568 if (peer_group_active(peer)) {
16569 g_peer = peer->group->conf;
16570
16571 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
16572 if (peer->as_type == AS_SPECIFIED) {
16573 vty_out(vty, " neighbor %s remote-as %u\n",
16574 addr, peer->as);
16575 } else if (peer->as_type == AS_INTERNAL) {
16576 vty_out(vty,
16577 " neighbor %s remote-as internal\n",
16578 addr);
16579 } else if (peer->as_type == AS_EXTERNAL) {
16580 vty_out(vty,
16581 " neighbor %s remote-as external\n",
16582 addr);
16583 }
16584 }
16585
16586 /* For swpX peers we displayed the peer-group
16587 * via 'neighbor swpX interface peer-group PGNAME' */
16588 if (!if_pg_printed)
16589 vty_out(vty, " neighbor %s peer-group %s\n", addr,
16590 peer->group->name);
16591 }
16592
16593 /* peer is NOT a member of a peer-group */
16594 else {
16595 /* peer is a peer-group, declare the peer-group */
16596 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
16597 vty_out(vty, " neighbor %s peer-group\n", addr);
16598 }
16599
16600 if (!if_ras_printed) {
16601 if (peer->as_type == AS_SPECIFIED) {
16602 vty_out(vty, " neighbor %s remote-as %u\n",
16603 addr, peer->as);
16604 } else if (peer->as_type == AS_INTERNAL) {
16605 vty_out(vty,
16606 " neighbor %s remote-as internal\n",
16607 addr);
16608 } else if (peer->as_type == AS_EXTERNAL) {
16609 vty_out(vty,
16610 " neighbor %s remote-as external\n",
16611 addr);
16612 }
16613 }
16614 }
16615
16616 /* local-as */
16617 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
16618 vty_out(vty, " neighbor %s local-as %u", addr,
16619 peer->change_local_as);
16620 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
16621 vty_out(vty, " no-prepend");
16622 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
16623 vty_out(vty, " replace-as");
16624 vty_out(vty, "\n");
16625 }
16626
16627 /* description */
16628 if (peer->desc) {
16629 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
16630 }
16631
16632 /* shutdown */
16633 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
16634 if (peer->tx_shutdown_message)
16635 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
16636 peer->tx_shutdown_message);
16637 else
16638 vty_out(vty, " neighbor %s shutdown\n", addr);
16639 }
16640
16641 if (peergroup_flag_check(peer, PEER_FLAG_RTT_SHUTDOWN))
16642 vty_out(vty, " neighbor %s shutdown rtt %u count %u\n", addr,
16643 peer->rtt_expected, peer->rtt_keepalive_conf);
16644
16645 /* bfd */
16646 if (peer->bfd_info) {
16647 if (!peer_group_active(peer) || !g_peer->bfd_info) {
16648 bgp_bfd_peer_config_write(vty, peer, addr);
16649 }
16650 }
16651
16652 /* password */
16653 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
16654 vty_out(vty, " neighbor %s password %s\n", addr,
16655 peer->password);
16656
16657 /* neighbor solo */
16658 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
16659 if (!peer_group_active(peer)) {
16660 vty_out(vty, " neighbor %s solo\n", addr);
16661 }
16662 }
16663
16664 /* BGP port */
16665 if (peer->port != BGP_PORT_DEFAULT) {
16666 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
16667 }
16668
16669 /* Local interface name */
16670 if (peer->ifname) {
16671 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
16672 }
16673
16674 /* passive */
16675 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
16676 vty_out(vty, " neighbor %s passive\n", addr);
16677
16678 /* ebgp-multihop */
16679 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
16680 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
16681 && peer->ttl == MAXTTL)) {
16682 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
16683 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
16684 peer->ttl);
16685 }
16686 }
16687
16688 /* ttl-security hops */
16689 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
16690 if (!peer_group_active(peer)
16691 || g_peer->gtsm_hops != peer->gtsm_hops) {
16692 vty_out(vty, " neighbor %s ttl-security hops %d\n",
16693 addr, peer->gtsm_hops);
16694 }
16695 }
16696
16697 /* disable-connected-check */
16698 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
16699 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
16700
16701 /* enforce-first-as */
16702 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
16703 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
16704
16705 /* update-source */
16706 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
16707 if (peer->update_source)
16708 vty_out(vty, " neighbor %s update-source %s\n", addr,
16709 sockunion2str(peer->update_source, buf,
16710 SU_ADDRSTRLEN));
16711 else if (peer->update_if)
16712 vty_out(vty, " neighbor %s update-source %s\n", addr,
16713 peer->update_if);
16714 }
16715
16716 /* advertisement-interval */
16717 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
16718 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
16719 peer->routeadv);
16720
16721 /* timers */
16722 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
16723 vty_out(vty, " neighbor %s timers %u %u\n", addr,
16724 peer->keepalive, peer->holdtime);
16725
16726 /* timers connect */
16727 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
16728 vty_out(vty, " neighbor %s timers connect %u\n", addr,
16729 peer->connect);
16730 /* need special-case handling for changed default values due to
16731 * config profile / version (because there is no "timers bgp connect"
16732 * command, we need to save this per-peer :/)
16733 */
16734 else if (!peer_group_active(peer) && !peer->connect &&
16735 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
16736 vty_out(vty, " neighbor %s timers connect %u\n", addr,
16737 peer->bgp->default_connect_retry);
16738
16739 /* timers delayopen */
16740 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_DELAYOPEN))
16741 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
16742 peer->delayopen);
16743 /* Save config even though flag is not set if default values have been
16744 * changed
16745 */
16746 else if (!peer_group_active(peer) && !peer->delayopen
16747 && peer->bgp->default_delayopen != BGP_DEFAULT_DELAYOPEN)
16748 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
16749 peer->bgp->default_delayopen);
16750
16751 /* capability dynamic */
16752 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
16753 vty_out(vty, " neighbor %s capability dynamic\n", addr);
16754
16755 /* capability extended-nexthop */
16756 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
16757 if (!peer->conf_if) {
16758 if (CHECK_FLAG(peer->flags_invert,
16759 PEER_FLAG_CAPABILITY_ENHE))
16760 vty_out(vty,
16761 " no neighbor %s capability extended-nexthop\n",
16762 addr);
16763 else
16764 vty_out(vty,
16765 " neighbor %s capability extended-nexthop\n",
16766 addr);
16767 }
16768 }
16769
16770 /* dont-capability-negotiation */
16771 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
16772 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
16773
16774 /* override-capability */
16775 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
16776 vty_out(vty, " neighbor %s override-capability\n", addr);
16777
16778 /* strict-capability-match */
16779 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
16780 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
16781
16782 /* Sender side AS path loop detection. */
16783 if (peer->as_path_loop_detection)
16784 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
16785 addr);
16786
16787 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
16788 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
16789
16790 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
16791 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
16792 vty_out(vty,
16793 " neighbor %s graceful-restart-helper\n", addr);
16794 } else if (CHECK_FLAG(
16795 peer->peer_gr_new_status_flag,
16796 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
16797 vty_out(vty,
16798 " neighbor %s graceful-restart\n", addr);
16799 } else if (
16800 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
16801 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
16802 && !(CHECK_FLAG(
16803 peer->peer_gr_new_status_flag,
16804 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
16805 vty_out(vty, " neighbor %s graceful-restart-disable\n",
16806 addr);
16807 }
16808 }
16809 }
16810
16811 /* BGP peer configuration display function. */
16812 static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
16813 struct peer *peer, afi_t afi, safi_t safi)
16814 {
16815 struct peer *g_peer = NULL;
16816 char *addr;
16817 bool flag_scomm, flag_secomm, flag_slcomm;
16818
16819 /* Skip dynamic neighbors. */
16820 if (peer_dynamic_neighbor(peer))
16821 return;
16822
16823 if (peer->conf_if)
16824 addr = peer->conf_if;
16825 else
16826 addr = peer->host;
16827
16828 /************************************
16829 ****** Per AF to the neighbor ******
16830 ************************************/
16831 if (peer_group_active(peer)) {
16832 g_peer = peer->group->conf;
16833
16834 /* If the peer-group is active but peer is not, print a 'no
16835 * activate' */
16836 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
16837 vty_out(vty, " no neighbor %s activate\n", addr);
16838 }
16839
16840 /* If the peer-group is not active but peer is, print an
16841 'activate' */
16842 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
16843 vty_out(vty, " neighbor %s activate\n", addr);
16844 }
16845 } else {
16846 if (peer->afc[afi][safi]) {
16847 if ((afi == AFI_IP) && (safi == SAFI_UNICAST)) {
16848 if (CHECK_FLAG(bgp->flags,
16849 BGP_FLAG_NO_DEFAULT_IPV4)) {
16850 vty_out(vty, " neighbor %s activate\n",
16851 addr);
16852 }
16853 } else
16854 vty_out(vty, " neighbor %s activate\n", addr);
16855 } else {
16856 if ((afi == AFI_IP) && (safi == SAFI_UNICAST)) {
16857 if (!CHECK_FLAG(bgp->flags,
16858 BGP_FLAG_NO_DEFAULT_IPV4)) {
16859 vty_out(vty,
16860 " no neighbor %s activate\n",
16861 addr);
16862 }
16863 }
16864 }
16865 }
16866
16867 /* addpath TX knobs */
16868 if (peergroup_af_addpath_check(peer, afi, safi)) {
16869 switch (peer->addpath_type[afi][safi]) {
16870 case BGP_ADDPATH_ALL:
16871 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
16872 addr);
16873 break;
16874 case BGP_ADDPATH_BEST_PER_AS:
16875 vty_out(vty,
16876 " neighbor %s addpath-tx-bestpath-per-AS\n",
16877 addr);
16878 break;
16879 case BGP_ADDPATH_MAX:
16880 case BGP_ADDPATH_NONE:
16881 break;
16882 }
16883 }
16884
16885 /* ORF capability. */
16886 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
16887 || peergroup_af_flag_check(peer, afi, safi,
16888 PEER_FLAG_ORF_PREFIX_RM)) {
16889 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
16890
16891 if (peergroup_af_flag_check(peer, afi, safi,
16892 PEER_FLAG_ORF_PREFIX_SM)
16893 && peergroup_af_flag_check(peer, afi, safi,
16894 PEER_FLAG_ORF_PREFIX_RM))
16895 vty_out(vty, " both");
16896 else if (peergroup_af_flag_check(peer, afi, safi,
16897 PEER_FLAG_ORF_PREFIX_SM))
16898 vty_out(vty, " send");
16899 else
16900 vty_out(vty, " receive");
16901 vty_out(vty, "\n");
16902 }
16903
16904 /* Route reflector client. */
16905 if (peergroup_af_flag_check(peer, afi, safi,
16906 PEER_FLAG_REFLECTOR_CLIENT)) {
16907 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
16908 }
16909
16910 /* next-hop-self force */
16911 if (peergroup_af_flag_check(peer, afi, safi,
16912 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
16913 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
16914 }
16915
16916 /* next-hop-self */
16917 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
16918 vty_out(vty, " neighbor %s next-hop-self\n", addr);
16919 }
16920
16921 /* remove-private-AS */
16922 if (peergroup_af_flag_check(peer, afi, safi,
16923 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
16924 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
16925 addr);
16926 }
16927
16928 else if (peergroup_af_flag_check(peer, afi, safi,
16929 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
16930 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
16931 addr);
16932 }
16933
16934 else if (peergroup_af_flag_check(peer, afi, safi,
16935 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
16936 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
16937 }
16938
16939 else if (peergroup_af_flag_check(peer, afi, safi,
16940 PEER_FLAG_REMOVE_PRIVATE_AS)) {
16941 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
16942 }
16943
16944 /* as-override */
16945 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
16946 vty_out(vty, " neighbor %s as-override\n", addr);
16947 }
16948
16949 /* send-community print. */
16950 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
16951 PEER_FLAG_SEND_COMMUNITY);
16952 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
16953 PEER_FLAG_SEND_EXT_COMMUNITY);
16954 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
16955 PEER_FLAG_SEND_LARGE_COMMUNITY);
16956
16957 if (flag_scomm && flag_secomm && flag_slcomm) {
16958 vty_out(vty, " no neighbor %s send-community all\n", addr);
16959 } else {
16960 if (flag_scomm)
16961 vty_out(vty, " no neighbor %s send-community\n", addr);
16962 if (flag_secomm)
16963 vty_out(vty,
16964 " no neighbor %s send-community extended\n",
16965 addr);
16966
16967 if (flag_slcomm)
16968 vty_out(vty, " no neighbor %s send-community large\n",
16969 addr);
16970 }
16971
16972 /* Default information */
16973 if (peergroup_af_flag_check(peer, afi, safi,
16974 PEER_FLAG_DEFAULT_ORIGINATE)) {
16975 vty_out(vty, " neighbor %s default-originate", addr);
16976
16977 if (peer->default_rmap[afi][safi].name)
16978 vty_out(vty, " route-map %s",
16979 peer->default_rmap[afi][safi].name);
16980
16981 vty_out(vty, "\n");
16982 }
16983
16984 /* Soft reconfiguration inbound. */
16985 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
16986 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
16987 addr);
16988 }
16989
16990 /* maximum-prefix. */
16991 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
16992 vty_out(vty, " neighbor %s maximum-prefix %u", addr,
16993 peer->pmax[afi][safi]);
16994
16995 if (peer->pmax_threshold[afi][safi]
16996 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
16997 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
16998 if (peer_af_flag_check(peer, afi, safi,
16999 PEER_FLAG_MAX_PREFIX_WARNING))
17000 vty_out(vty, " warning-only");
17001 if (peer->pmax_restart[afi][safi])
17002 vty_out(vty, " restart %u",
17003 peer->pmax_restart[afi][safi]);
17004 if (peer_af_flag_check(peer, afi, safi,
17005 PEER_FLAG_MAX_PREFIX_FORCE))
17006 vty_out(vty, " force");
17007
17008 vty_out(vty, "\n");
17009 }
17010
17011 /* maximum-prefix-out */
17012 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
17013 vty_out(vty, " neighbor %s maximum-prefix-out %u\n",
17014 addr, peer->pmax_out[afi][safi]);
17015
17016 /* Route server client. */
17017 if (peergroup_af_flag_check(peer, afi, safi,
17018 PEER_FLAG_RSERVER_CLIENT)) {
17019 vty_out(vty, " neighbor %s route-server-client\n", addr);
17020 }
17021
17022 /* Nexthop-local unchanged. */
17023 if (peergroup_af_flag_check(peer, afi, safi,
17024 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
17025 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
17026 }
17027
17028 /* allowas-in <1-10> */
17029 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
17030 if (peer_af_flag_check(peer, afi, safi,
17031 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
17032 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
17033 } else if (peer->allowas_in[afi][safi] == 3) {
17034 vty_out(vty, " neighbor %s allowas-in\n", addr);
17035 } else {
17036 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
17037 peer->allowas_in[afi][safi]);
17038 }
17039 }
17040
17041 /* weight */
17042 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
17043 vty_out(vty, " neighbor %s weight %lu\n", addr,
17044 peer->weight[afi][safi]);
17045
17046 /* Filter. */
17047 bgp_config_write_filter(vty, peer, afi, safi);
17048
17049 /* atribute-unchanged. */
17050 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
17051 || (safi != SAFI_EVPN
17052 && peer_af_flag_check(peer, afi, safi,
17053 PEER_FLAG_NEXTHOP_UNCHANGED))
17054 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
17055
17056 if (!peer_group_active(peer)
17057 || peergroup_af_flag_check(peer, afi, safi,
17058 PEER_FLAG_AS_PATH_UNCHANGED)
17059 || peergroup_af_flag_check(peer, afi, safi,
17060 PEER_FLAG_NEXTHOP_UNCHANGED)
17061 || peergroup_af_flag_check(peer, afi, safi,
17062 PEER_FLAG_MED_UNCHANGED)) {
17063
17064 vty_out(vty,
17065 " neighbor %s attribute-unchanged%s%s%s\n",
17066 addr,
17067 peer_af_flag_check(peer, afi, safi,
17068 PEER_FLAG_AS_PATH_UNCHANGED)
17069 ? " as-path"
17070 : "",
17071 peer_af_flag_check(peer, afi, safi,
17072 PEER_FLAG_NEXTHOP_UNCHANGED)
17073 ? " next-hop"
17074 : "",
17075 peer_af_flag_check(peer, afi, safi,
17076 PEER_FLAG_MED_UNCHANGED)
17077 ? " med"
17078 : "");
17079 }
17080 }
17081 }
17082
17083 /* Address family based peer configuration display. */
17084 static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
17085 safi_t safi)
17086 {
17087 struct peer *peer;
17088 struct peer_group *group;
17089 struct listnode *node, *nnode;
17090
17091
17092 vty_frame(vty, " !\n address-family ");
17093 if (afi == AFI_IP) {
17094 if (safi == SAFI_UNICAST)
17095 vty_frame(vty, "ipv4 unicast");
17096 else if (safi == SAFI_LABELED_UNICAST)
17097 vty_frame(vty, "ipv4 labeled-unicast");
17098 else if (safi == SAFI_MULTICAST)
17099 vty_frame(vty, "ipv4 multicast");
17100 else if (safi == SAFI_MPLS_VPN)
17101 vty_frame(vty, "ipv4 vpn");
17102 else if (safi == SAFI_ENCAP)
17103 vty_frame(vty, "ipv4 encap");
17104 else if (safi == SAFI_FLOWSPEC)
17105 vty_frame(vty, "ipv4 flowspec");
17106 } else if (afi == AFI_IP6) {
17107 if (safi == SAFI_UNICAST)
17108 vty_frame(vty, "ipv6 unicast");
17109 else if (safi == SAFI_LABELED_UNICAST)
17110 vty_frame(vty, "ipv6 labeled-unicast");
17111 else if (safi == SAFI_MULTICAST)
17112 vty_frame(vty, "ipv6 multicast");
17113 else if (safi == SAFI_MPLS_VPN)
17114 vty_frame(vty, "ipv6 vpn");
17115 else if (safi == SAFI_ENCAP)
17116 vty_frame(vty, "ipv6 encap");
17117 else if (safi == SAFI_FLOWSPEC)
17118 vty_frame(vty, "ipv6 flowspec");
17119 } else if (afi == AFI_L2VPN) {
17120 if (safi == SAFI_EVPN)
17121 vty_frame(vty, "l2vpn evpn");
17122 }
17123 vty_frame(vty, "\n");
17124
17125 bgp_config_write_distance(vty, bgp, afi, safi);
17126
17127 bgp_config_write_network(vty, bgp, afi, safi);
17128
17129 bgp_config_write_redistribute(vty, bgp, afi, safi);
17130
17131 /* BGP flag dampening. */
17132 if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
17133 bgp_config_write_damp(vty, bgp, afi, safi);
17134 for (ALL_LIST_ELEMENTS_RO(bgp->group, node, group))
17135 if (peer_af_flag_check(group->conf, afi, safi,
17136 PEER_FLAG_CONFIG_DAMPENING))
17137 bgp_config_write_peer_damp(vty, group->conf, afi, safi);
17138 for (ALL_LIST_ELEMENTS_RO(bgp->peer, node, peer))
17139 if (peer_af_flag_check(peer, afi, safi,
17140 PEER_FLAG_CONFIG_DAMPENING))
17141 bgp_config_write_peer_damp(vty, peer, afi, safi);
17142
17143 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
17144 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
17145
17146 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17147 /* Skip dynamic neighbors. */
17148 if (peer_dynamic_neighbor(peer))
17149 continue;
17150
17151 /* Do not display doppelganger peers */
17152 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17153 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
17154 }
17155
17156 bgp_config_write_maxpaths(vty, bgp, afi, safi);
17157 bgp_config_write_table_map(vty, bgp, afi, safi);
17158
17159 if (safi == SAFI_EVPN)
17160 bgp_config_write_evpn_info(vty, bgp, afi, safi);
17161
17162 if (safi == SAFI_FLOWSPEC)
17163 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
17164
17165 if (safi == SAFI_UNICAST) {
17166 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
17167 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17168 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
17169
17170 vty_out(vty, " export vpn\n");
17171 }
17172 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17173 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
17174
17175 vty_out(vty, " import vpn\n");
17176 }
17177 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17178 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
17179 char *name;
17180
17181 for (ALL_LIST_ELEMENTS_RO(
17182 bgp->vpn_policy[afi].import_vrf, node,
17183 name))
17184 vty_out(vty, " import vrf %s\n", name);
17185 }
17186 }
17187
17188 vty_endframe(vty, " exit-address-family\n");
17189 }
17190
17191 int bgp_config_write(struct vty *vty)
17192 {
17193 struct bgp *bgp;
17194 struct peer_group *group;
17195 struct peer *peer;
17196 struct listnode *node, *nnode;
17197 struct listnode *mnode, *mnnode;
17198
17199 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
17200 vty_out(vty, "bgp route-map delay-timer %u\n",
17201 bm->rmap_update_timer);
17202
17203 if (bm->v_update_delay != BGP_UPDATE_DELAY_DEF) {
17204 vty_out(vty, "bgp update-delay %d", bm->v_update_delay);
17205 if (bm->v_update_delay != bm->v_establish_wait)
17206 vty_out(vty, " %d", bm->v_establish_wait);
17207 vty_out(vty, "\n");
17208 }
17209
17210 if (bm->wait_for_fib)
17211 vty_out(vty, "bgp suppress-fib-pending\n");
17212
17213 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17214 vty_out(vty, "bgp graceful-shutdown\n");
17215
17216 /* No-RIB (Zebra) option flag configuration */
17217 if (bgp_option_check(BGP_OPT_NO_FIB))
17218 vty_out(vty, "bgp no-rib\n");
17219
17220 if (!CHECK_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA))
17221 vty_out(vty, "no bgp send-extra-data zebra\n");
17222
17223 /* BGP configuration. */
17224 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
17225
17226 /* skip all auto created vrf as they dont have user config */
17227 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
17228 continue;
17229
17230 /* Router bgp ASN */
17231 vty_out(vty, "router bgp %u", bgp->as);
17232
17233 if (bgp->name)
17234 vty_out(vty, " %s %s",
17235 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
17236 ? "view" : "vrf", bgp->name);
17237 vty_out(vty, "\n");
17238
17239 /* BGP fast-external-failover. */
17240 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
17241 vty_out(vty, " no bgp fast-external-failover\n");
17242
17243 /* BGP router ID. */
17244 if (bgp->router_id_static.s_addr != INADDR_ANY)
17245 vty_out(vty, " bgp router-id %pI4\n",
17246 &bgp->router_id_static);
17247
17248 /* Suppress fib pending */
17249 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_FIB_PENDING))
17250 vty_out(vty, " bgp suppress-fib-pending\n");
17251
17252 /* BGP log-neighbor-changes. */
17253 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
17254 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
17255 vty_out(vty, " %sbgp log-neighbor-changes\n",
17256 CHECK_FLAG(bgp->flags,
17257 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
17258 ? ""
17259 : "no ");
17260
17261 /* BGP configuration. */
17262 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
17263 vty_out(vty, " bgp always-compare-med\n");
17264
17265 /* RFC8212 default eBGP policy. */
17266 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
17267 != SAVE_BGP_EBGP_REQUIRES_POLICY)
17268 vty_out(vty, " %sbgp ebgp-requires-policy\n",
17269 CHECK_FLAG(bgp->flags,
17270 BGP_FLAG_EBGP_REQUIRES_POLICY)
17271 ? ""
17272 : "no ");
17273
17274 /* draft-ietf-idr-deprecate-as-set-confed-set */
17275 if (bgp->reject_as_sets)
17276 vty_out(vty, " bgp reject-as-sets\n");
17277
17278 /* Suppress duplicate updates if the route actually not changed
17279 */
17280 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES)
17281 != SAVE_BGP_SUPPRESS_DUPLICATES)
17282 vty_out(vty, " %sbgp suppress-duplicates\n",
17283 CHECK_FLAG(bgp->flags,
17284 BGP_FLAG_SUPPRESS_DUPLICATES)
17285 ? ""
17286 : "no ");
17287
17288 /* BGP default ipv4-unicast. */
17289 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4))
17290 vty_out(vty, " no bgp default ipv4-unicast\n");
17291
17292 /* BGP default local-preference. */
17293 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
17294 vty_out(vty, " bgp default local-preference %u\n",
17295 bgp->default_local_pref);
17296
17297 /* BGP default show-hostname */
17298 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
17299 != SAVE_BGP_SHOW_HOSTNAME)
17300 vty_out(vty, " %sbgp default show-hostname\n",
17301 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
17302 ? ""
17303 : "no ");
17304
17305 /* BGP default show-nexthop-hostname */
17306 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17307 != SAVE_BGP_SHOW_HOSTNAME)
17308 vty_out(vty, " %sbgp default show-nexthop-hostname\n",
17309 CHECK_FLAG(bgp->flags,
17310 BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17311 ? ""
17312 : "no ");
17313
17314 /* BGP default subgroup-pkt-queue-max. */
17315 if (bgp->default_subgroup_pkt_queue_max
17316 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
17317 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
17318 bgp->default_subgroup_pkt_queue_max);
17319
17320 /* BGP client-to-client reflection. */
17321 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
17322 vty_out(vty, " no bgp client-to-client reflection\n");
17323
17324 /* BGP cluster ID. */
17325 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
17326 vty_out(vty, " bgp cluster-id %pI4\n",
17327 &bgp->cluster_id);
17328
17329 /* Disable ebgp connected nexthop check */
17330 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
17331 vty_out(vty,
17332 " bgp disable-ebgp-connected-route-check\n");
17333
17334 /* Confederation identifier*/
17335 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
17336 vty_out(vty, " bgp confederation identifier %u\n",
17337 bgp->confed_id);
17338
17339 /* Confederation peer */
17340 if (bgp->confed_peers_cnt > 0) {
17341 int i;
17342
17343 vty_out(vty, " bgp confederation peers");
17344
17345 for (i = 0; i < bgp->confed_peers_cnt; i++)
17346 vty_out(vty, " %u", bgp->confed_peers[i]);
17347
17348 vty_out(vty, "\n");
17349 }
17350
17351 /* BGP deterministic-med. */
17352 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
17353 != SAVE_BGP_DETERMINISTIC_MED)
17354 vty_out(vty, " %sbgp deterministic-med\n",
17355 CHECK_FLAG(bgp->flags,
17356 BGP_FLAG_DETERMINISTIC_MED)
17357 ? ""
17358 : "no ");
17359
17360 /* BGP update-delay. */
17361 bgp_config_write_update_delay(vty, bgp);
17362
17363 if (bgp->v_maxmed_onstartup
17364 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
17365 vty_out(vty, " bgp max-med on-startup %u",
17366 bgp->v_maxmed_onstartup);
17367 if (bgp->maxmed_onstartup_value
17368 != BGP_MAXMED_VALUE_DEFAULT)
17369 vty_out(vty, " %u",
17370 bgp->maxmed_onstartup_value);
17371 vty_out(vty, "\n");
17372 }
17373 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
17374 vty_out(vty, " bgp max-med administrative");
17375 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
17376 vty_out(vty, " %u", bgp->maxmed_admin_value);
17377 vty_out(vty, "\n");
17378 }
17379
17380 /* write quanta */
17381 bgp_config_write_wpkt_quanta(vty, bgp);
17382 /* read quanta */
17383 bgp_config_write_rpkt_quanta(vty, bgp);
17384
17385 /* coalesce time */
17386 bgp_config_write_coalesce_time(vty, bgp);
17387
17388 /* BGP per-instance graceful-shutdown */
17389 /* BGP-wide settings and per-instance settings are mutually
17390 * exclusive.
17391 */
17392 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17393 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
17394 vty_out(vty, " bgp graceful-shutdown\n");
17395
17396 /* BGP graceful-restart. */
17397 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
17398 vty_out(vty,
17399 " bgp graceful-restart stalepath-time %u\n",
17400 bgp->stalepath_time);
17401
17402 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
17403 vty_out(vty, " bgp graceful-restart restart-time %u\n",
17404 bgp->restart_time);
17405
17406 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
17407 vty_out(vty,
17408 " bgp graceful-restart select-defer-time %u\n",
17409 bgp->select_defer_time);
17410
17411 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
17412 vty_out(vty, " bgp graceful-restart\n");
17413
17414 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
17415 vty_out(vty, " bgp graceful-restart-disable\n");
17416
17417 /* BGP graceful-restart Preserve State F bit. */
17418 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
17419 vty_out(vty,
17420 " bgp graceful-restart preserve-fw-state\n");
17421
17422 /* Stale timer for RIB */
17423 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
17424 vty_out(vty,
17425 " bgp graceful-restart rib-stale-time %u\n",
17426 bgp->rib_stale_time);
17427
17428 /* BGP bestpath method. */
17429 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
17430 vty_out(vty, " bgp bestpath as-path ignore\n");
17431 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
17432 vty_out(vty, " bgp bestpath as-path confed\n");
17433
17434 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
17435 if (CHECK_FLAG(bgp->flags,
17436 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
17437 vty_out(vty,
17438 " bgp bestpath as-path multipath-relax as-set\n");
17439 } else {
17440 vty_out(vty,
17441 " bgp bestpath as-path multipath-relax\n");
17442 }
17443 }
17444
17445 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
17446 vty_out(vty,
17447 " bgp route-reflector allow-outbound-policy\n");
17448 }
17449 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
17450 vty_out(vty, " bgp bestpath compare-routerid\n");
17451 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
17452 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
17453 vty_out(vty, " bgp bestpath med");
17454 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
17455 vty_out(vty, " confed");
17456 if (CHECK_FLAG(bgp->flags,
17457 BGP_FLAG_MED_MISSING_AS_WORST))
17458 vty_out(vty, " missing-as-worst");
17459 vty_out(vty, "\n");
17460 }
17461
17462 /* Link bandwidth handling. */
17463 if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW)
17464 vty_out(vty, " bgp bestpath bandwidth ignore\n");
17465 else if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
17466 vty_out(vty, " bgp bestpath bandwidth skip-missing\n");
17467 else if (bgp->lb_handling == BGP_LINK_BW_DEFWT_4_MISSING)
17468 vty_out(vty, " bgp bestpath bandwidth default-weight-for-missing\n");
17469
17470 /* BGP network import check. */
17471 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
17472 != SAVE_BGP_IMPORT_CHECK)
17473 vty_out(vty, " %sbgp network import-check\n",
17474 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
17475 ? ""
17476 : "no ");
17477
17478 /* BGP timers configuration. */
17479 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
17480 && bgp->default_holdtime != SAVE_BGP_HOLDTIME)
17481 vty_out(vty, " timers bgp %u %u\n",
17482 bgp->default_keepalive, bgp->default_holdtime);
17483
17484 /* peer-group */
17485 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
17486 bgp_config_write_peer_global(vty, bgp, group->conf);
17487 }
17488
17489 /* Normal neighbor configuration. */
17490 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17491 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17492 bgp_config_write_peer_global(vty, bgp, peer);
17493 }
17494
17495 /* listen range and limit for dynamic BGP neighbors */
17496 bgp_config_write_listen(vty, bgp);
17497
17498 /*
17499 * BGP default autoshutdown neighbors
17500 *
17501 * This must be placed after any peer and peer-group
17502 * configuration, to avoid setting all peers to shutdown after
17503 * a daemon restart, which is undesired behavior. (see #2286)
17504 */
17505 if (bgp->autoshutdown)
17506 vty_out(vty, " bgp default shutdown\n");
17507
17508 /* BGP instance administrative shutdown */
17509 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN))
17510 vty_out(vty, " bgp shutdown\n");
17511
17512 /* IPv4 unicast configuration. */
17513 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
17514
17515 /* IPv4 multicast configuration. */
17516 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
17517
17518 /* IPv4 labeled-unicast configuration. */
17519 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
17520
17521 /* IPv4 VPN configuration. */
17522 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
17523
17524 /* ENCAPv4 configuration. */
17525 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
17526
17527 /* FLOWSPEC v4 configuration. */
17528 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
17529
17530 /* IPv6 unicast configuration. */
17531 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
17532
17533 /* IPv6 multicast configuration. */
17534 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
17535
17536 /* IPv6 labeled-unicast configuration. */
17537 bgp_config_write_family(vty, bgp, AFI_IP6,
17538 SAFI_LABELED_UNICAST);
17539
17540 /* IPv6 VPN configuration. */
17541 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
17542
17543 /* ENCAPv6 configuration. */
17544 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
17545
17546 /* FLOWSPEC v6 configuration. */
17547 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
17548
17549 /* EVPN configuration. */
17550 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
17551
17552 hook_call(bgp_inst_config_write, bgp, vty);
17553
17554 #ifdef ENABLE_BGP_VNC
17555 bgp_rfapi_cfg_write(vty, bgp);
17556 #endif
17557
17558 vty_out(vty, "!\n");
17559 }
17560 return 0;
17561 }
17562
17563
17564 /* BGP node structure. */
17565 static struct cmd_node bgp_node = {
17566 .name = "bgp",
17567 .node = BGP_NODE,
17568 .parent_node = CONFIG_NODE,
17569 .prompt = "%s(config-router)# ",
17570 .config_write = bgp_config_write,
17571 };
17572
17573 static struct cmd_node bgp_ipv4_unicast_node = {
17574 .name = "bgp ipv4 unicast",
17575 .node = BGP_IPV4_NODE,
17576 .parent_node = BGP_NODE,
17577 .prompt = "%s(config-router-af)# ",
17578 };
17579
17580 static struct cmd_node bgp_ipv4_multicast_node = {
17581 .name = "bgp ipv4 multicast",
17582 .node = BGP_IPV4M_NODE,
17583 .parent_node = BGP_NODE,
17584 .prompt = "%s(config-router-af)# ",
17585 };
17586
17587 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
17588 .name = "bgp ipv4 labeled unicast",
17589 .node = BGP_IPV4L_NODE,
17590 .parent_node = BGP_NODE,
17591 .prompt = "%s(config-router-af)# ",
17592 };
17593
17594 static struct cmd_node bgp_ipv6_unicast_node = {
17595 .name = "bgp ipv6",
17596 .node = BGP_IPV6_NODE,
17597 .parent_node = BGP_NODE,
17598 .prompt = "%s(config-router-af)# ",
17599 };
17600
17601 static struct cmd_node bgp_ipv6_multicast_node = {
17602 .name = "bgp ipv6 multicast",
17603 .node = BGP_IPV6M_NODE,
17604 .parent_node = BGP_NODE,
17605 .prompt = "%s(config-router-af)# ",
17606 };
17607
17608 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
17609 .name = "bgp ipv6 labeled unicast",
17610 .node = BGP_IPV6L_NODE,
17611 .parent_node = BGP_NODE,
17612 .prompt = "%s(config-router-af)# ",
17613 };
17614
17615 static struct cmd_node bgp_vpnv4_node = {
17616 .name = "bgp vpnv4",
17617 .node = BGP_VPNV4_NODE,
17618 .parent_node = BGP_NODE,
17619 .prompt = "%s(config-router-af)# ",
17620 };
17621
17622 static struct cmd_node bgp_vpnv6_node = {
17623 .name = "bgp vpnv6",
17624 .node = BGP_VPNV6_NODE,
17625 .parent_node = BGP_NODE,
17626 .prompt = "%s(config-router-af-vpnv6)# ",
17627 };
17628
17629 static struct cmd_node bgp_evpn_node = {
17630 .name = "bgp evpn",
17631 .node = BGP_EVPN_NODE,
17632 .parent_node = BGP_NODE,
17633 .prompt = "%s(config-router-evpn)# ",
17634 };
17635
17636 static struct cmd_node bgp_evpn_vni_node = {
17637 .name = "bgp evpn vni",
17638 .node = BGP_EVPN_VNI_NODE,
17639 .parent_node = BGP_EVPN_NODE,
17640 .prompt = "%s(config-router-af-vni)# ",
17641 };
17642
17643 static struct cmd_node bgp_flowspecv4_node = {
17644 .name = "bgp ipv4 flowspec",
17645 .node = BGP_FLOWSPECV4_NODE,
17646 .parent_node = BGP_NODE,
17647 .prompt = "%s(config-router-af)# ",
17648 };
17649
17650 static struct cmd_node bgp_flowspecv6_node = {
17651 .name = "bgp ipv6 flowspec",
17652 .node = BGP_FLOWSPECV6_NODE,
17653 .parent_node = BGP_NODE,
17654 .prompt = "%s(config-router-af-vpnv6)# ",
17655 };
17656
17657 static void community_list_vty(void);
17658
17659 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
17660 {
17661 struct bgp *bgp;
17662 struct peer *peer;
17663 struct listnode *lnbgp, *lnpeer;
17664
17665 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
17666 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
17667 /* only provide suggestions on the appropriate input
17668 * token type,
17669 * they'll otherwise show up multiple times */
17670 enum cmd_token_type match_type;
17671 char *name = peer->host;
17672
17673 if (peer->conf_if) {
17674 match_type = VARIABLE_TKN;
17675 name = peer->conf_if;
17676 } else if (strchr(peer->host, ':'))
17677 match_type = IPV6_TKN;
17678 else
17679 match_type = IPV4_TKN;
17680
17681 if (token->type != match_type)
17682 continue;
17683
17684 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
17685 }
17686 }
17687 }
17688
17689 static const struct cmd_variable_handler bgp_var_neighbor[] = {
17690 {.varname = "neighbor", .completions = bgp_ac_neighbor},
17691 {.varname = "neighbors", .completions = bgp_ac_neighbor},
17692 {.varname = "peer", .completions = bgp_ac_neighbor},
17693 {.completions = NULL}};
17694
17695 static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
17696 {
17697 struct bgp *bgp;
17698 struct peer_group *group;
17699 struct listnode *lnbgp, *lnpeer;
17700
17701 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
17702 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
17703 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
17704 group->name));
17705 }
17706 }
17707
17708 static const struct cmd_variable_handler bgp_var_peergroup[] = {
17709 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
17710 {.completions = NULL} };
17711
17712 void bgp_vty_init(void)
17713 {
17714 cmd_variable_handler_register(bgp_var_neighbor);
17715 cmd_variable_handler_register(bgp_var_peergroup);
17716
17717 /* Install bgp top node. */
17718 install_node(&bgp_node);
17719 install_node(&bgp_ipv4_unicast_node);
17720 install_node(&bgp_ipv4_multicast_node);
17721 install_node(&bgp_ipv4_labeled_unicast_node);
17722 install_node(&bgp_ipv6_unicast_node);
17723 install_node(&bgp_ipv6_multicast_node);
17724 install_node(&bgp_ipv6_labeled_unicast_node);
17725 install_node(&bgp_vpnv4_node);
17726 install_node(&bgp_vpnv6_node);
17727 install_node(&bgp_evpn_node);
17728 install_node(&bgp_evpn_vni_node);
17729 install_node(&bgp_flowspecv4_node);
17730 install_node(&bgp_flowspecv6_node);
17731
17732 /* Install default VTY commands to new nodes. */
17733 install_default(BGP_NODE);
17734 install_default(BGP_IPV4_NODE);
17735 install_default(BGP_IPV4M_NODE);
17736 install_default(BGP_IPV4L_NODE);
17737 install_default(BGP_IPV6_NODE);
17738 install_default(BGP_IPV6M_NODE);
17739 install_default(BGP_IPV6L_NODE);
17740 install_default(BGP_VPNV4_NODE);
17741 install_default(BGP_VPNV6_NODE);
17742 install_default(BGP_FLOWSPECV4_NODE);
17743 install_default(BGP_FLOWSPECV6_NODE);
17744 install_default(BGP_EVPN_NODE);
17745 install_default(BGP_EVPN_VNI_NODE);
17746
17747 /* "bgp local-mac" hidden commands. */
17748 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
17749 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
17750
17751 /* "bgp suppress-fib-pending" global */
17752 install_element(CONFIG_NODE, &bgp_global_suppress_fib_pending_cmd);
17753
17754 /* bgp route-map delay-timer commands. */
17755 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
17756 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
17757
17758 /* global bgp update-delay command */
17759 install_element(CONFIG_NODE, &bgp_global_update_delay_cmd);
17760 install_element(CONFIG_NODE, &no_bgp_global_update_delay_cmd);
17761
17762 /* global bgp graceful-shutdown command */
17763 install_element(CONFIG_NODE, &bgp_graceful_shutdown_cmd);
17764 install_element(CONFIG_NODE, &no_bgp_graceful_shutdown_cmd);
17765
17766 /* Dummy commands (Currently not supported) */
17767 install_element(BGP_NODE, &no_synchronization_cmd);
17768 install_element(BGP_NODE, &no_auto_summary_cmd);
17769
17770 /* "router bgp" commands. */
17771 install_element(CONFIG_NODE, &router_bgp_cmd);
17772
17773 /* "no router bgp" commands. */
17774 install_element(CONFIG_NODE, &no_router_bgp_cmd);
17775
17776 /* "bgp router-id" commands. */
17777 install_element(BGP_NODE, &bgp_router_id_cmd);
17778 install_element(BGP_NODE, &no_bgp_router_id_cmd);
17779
17780 /* "bgp suppress-fib-pending" command */
17781 install_element(BGP_NODE, &bgp_suppress_fib_pending_cmd);
17782
17783 /* "bgp cluster-id" commands. */
17784 install_element(BGP_NODE, &bgp_cluster_id_cmd);
17785 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
17786
17787 /* "bgp no-rib" commands. */
17788 install_element(CONFIG_NODE, &bgp_norib_cmd);
17789 install_element(CONFIG_NODE, &no_bgp_norib_cmd);
17790
17791 install_element(CONFIG_NODE, &no_bgp_send_extra_data_cmd);
17792
17793 /* "bgp confederation" commands. */
17794 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
17795 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
17796
17797 /* "bgp confederation peers" commands. */
17798 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
17799 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
17800
17801 /* bgp max-med command */
17802 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
17803 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
17804 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
17805 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
17806 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
17807
17808 /* bgp disable-ebgp-connected-nh-check */
17809 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
17810 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
17811
17812 /* bgp update-delay command */
17813 install_element(BGP_NODE, &bgp_update_delay_cmd);
17814 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
17815
17816 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
17817 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
17818
17819 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
17820 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
17821
17822 /* "maximum-paths" commands. */
17823 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
17824 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
17825 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
17826 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
17827 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
17828 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
17829 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
17830 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
17831 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
17832 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
17833 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17834 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
17835 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
17836 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17837 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
17838
17839 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_cmd);
17840 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_cmd);
17841 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cmd);
17842 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17843 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_ibgp_cmd);
17844 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
17845 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
17846 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
17847 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17848 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
17849
17850 /* "timers bgp" commands. */
17851 install_element(BGP_NODE, &bgp_timers_cmd);
17852 install_element(BGP_NODE, &no_bgp_timers_cmd);
17853
17854 /* route-map delay-timer commands - per instance for backwards compat.
17855 */
17856 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
17857 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
17858
17859 /* "bgp client-to-client reflection" commands */
17860 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
17861 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
17862
17863 /* "bgp always-compare-med" commands */
17864 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
17865 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
17866
17867 /* bgp ebgp-requires-policy */
17868 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
17869 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
17870
17871 /* bgp suppress-duplicates */
17872 install_element(BGP_NODE, &bgp_suppress_duplicates_cmd);
17873 install_element(BGP_NODE, &no_bgp_suppress_duplicates_cmd);
17874
17875 /* bgp reject-as-sets */
17876 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
17877 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
17878
17879 /* "bgp deterministic-med" commands */
17880 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
17881 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
17882
17883 /* "bgp graceful-restart" command */
17884 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
17885 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
17886
17887 /* "bgp graceful-restart-disable" command */
17888 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
17889 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
17890
17891 /* "neighbor a:b:c:d graceful-restart" command */
17892 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
17893 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
17894
17895 /* "neighbor a:b:c:d graceful-restart-disable" command */
17896 install_element(BGP_NODE,
17897 &bgp_neighbor_graceful_restart_disable_set_cmd);
17898 install_element(BGP_NODE,
17899 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
17900
17901 /* "neighbor a:b:c:d graceful-restart-helper" command */
17902 install_element(BGP_NODE,
17903 &bgp_neighbor_graceful_restart_helper_set_cmd);
17904 install_element(BGP_NODE,
17905 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
17906
17907 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
17908 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
17909 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
17910 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
17911 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
17912 install_element(BGP_NODE,
17913 &no_bgp_graceful_restart_select_defer_time_cmd);
17914 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
17915 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
17916
17917 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
17918 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
17919 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
17920 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
17921
17922 /* "bgp graceful-shutdown" commands */
17923 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
17924 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
17925
17926 /* "bgp fast-external-failover" commands */
17927 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
17928 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
17929
17930 /* "bgp bestpath compare-routerid" commands */
17931 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
17932 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
17933
17934 /* "bgp bestpath as-path ignore" commands */
17935 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
17936 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
17937
17938 /* "bgp bestpath as-path confed" commands */
17939 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
17940 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
17941
17942 /* "bgp bestpath as-path multipath-relax" commands */
17943 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
17944 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
17945
17946 /* "bgp log-neighbor-changes" commands */
17947 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
17948 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
17949
17950 /* "bgp bestpath med" commands */
17951 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
17952 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
17953
17954 /* "bgp bestpath bandwidth" commands */
17955 install_element(BGP_NODE, &bgp_bestpath_bw_cmd);
17956 install_element(BGP_NODE, &no_bgp_bestpath_bw_cmd);
17957
17958 /* "no bgp default ipv4-unicast" commands. */
17959 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
17960 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
17961
17962 /* "bgp network import-check" commands. */
17963 install_element(BGP_NODE, &bgp_network_import_check_cmd);
17964 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
17965 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
17966
17967 /* "bgp default local-preference" commands. */
17968 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
17969 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
17970
17971 /* bgp default show-hostname */
17972 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
17973 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
17974
17975 /* bgp default show-nexthop-hostname */
17976 install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
17977 install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
17978
17979 /* "bgp default subgroup-pkt-queue-max" commands. */
17980 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
17981 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
17982
17983 /* bgp ibgp-allow-policy-mods command */
17984 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
17985 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
17986
17987 /* "bgp listen limit" commands. */
17988 install_element(BGP_NODE, &bgp_listen_limit_cmd);
17989 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
17990
17991 /* "bgp listen range" commands. */
17992 install_element(BGP_NODE, &bgp_listen_range_cmd);
17993 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
17994
17995 /* "bgp default shutdown" command */
17996 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
17997
17998 /* "bgp shutdown" commands */
17999 install_element(BGP_NODE, &bgp_shutdown_cmd);
18000 install_element(BGP_NODE, &bgp_shutdown_msg_cmd);
18001 install_element(BGP_NODE, &no_bgp_shutdown_cmd);
18002 install_element(BGP_NODE, &no_bgp_shutdown_msg_cmd);
18003
18004 /* "neighbor remote-as" commands. */
18005 install_element(BGP_NODE, &neighbor_remote_as_cmd);
18006 install_element(BGP_NODE, &neighbor_interface_config_cmd);
18007 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
18008 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
18009 install_element(BGP_NODE,
18010 &neighbor_interface_v6only_config_remote_as_cmd);
18011 install_element(BGP_NODE, &no_neighbor_cmd);
18012 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
18013
18014 /* "neighbor peer-group" commands. */
18015 install_element(BGP_NODE, &neighbor_peer_group_cmd);
18016 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
18017 install_element(BGP_NODE,
18018 &no_neighbor_interface_peer_group_remote_as_cmd);
18019
18020 /* "neighbor local-as" commands. */
18021 install_element(BGP_NODE, &neighbor_local_as_cmd);
18022 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
18023 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
18024 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
18025
18026 /* "neighbor solo" commands. */
18027 install_element(BGP_NODE, &neighbor_solo_cmd);
18028 install_element(BGP_NODE, &no_neighbor_solo_cmd);
18029
18030 /* "neighbor password" commands. */
18031 install_element(BGP_NODE, &neighbor_password_cmd);
18032 install_element(BGP_NODE, &no_neighbor_password_cmd);
18033
18034 /* "neighbor activate" commands. */
18035 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
18036 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
18037 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
18038 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
18039 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
18040 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
18041 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
18042 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
18043 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
18044 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
18045 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
18046 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
18047
18048 /* "no neighbor activate" commands. */
18049 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
18050 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
18051 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
18052 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
18053 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
18054 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
18055 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
18056 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
18057 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
18058 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
18059 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
18060 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
18061
18062 /* "neighbor peer-group" set commands. */
18063 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
18064 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
18065 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
18066 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
18067 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
18068 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
18069 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
18070 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
18071 install_element(BGP_FLOWSPECV4_NODE,
18072 &neighbor_set_peer_group_hidden_cmd);
18073 install_element(BGP_FLOWSPECV6_NODE,
18074 &neighbor_set_peer_group_hidden_cmd);
18075
18076 /* "no neighbor peer-group unset" commands. */
18077 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
18078 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18079 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18080 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18081 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18082 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18083 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18084 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18085 install_element(BGP_FLOWSPECV4_NODE,
18086 &no_neighbor_set_peer_group_hidden_cmd);
18087 install_element(BGP_FLOWSPECV6_NODE,
18088 &no_neighbor_set_peer_group_hidden_cmd);
18089
18090 /* "neighbor softreconfiguration inbound" commands.*/
18091 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
18092 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
18093 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
18094 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
18095 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
18096 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
18097 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
18098 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
18099 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
18100 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
18101 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
18102 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
18103 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
18104 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
18105 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
18106 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
18107 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
18108 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
18109 install_element(BGP_FLOWSPECV4_NODE,
18110 &neighbor_soft_reconfiguration_cmd);
18111 install_element(BGP_FLOWSPECV4_NODE,
18112 &no_neighbor_soft_reconfiguration_cmd);
18113 install_element(BGP_FLOWSPECV6_NODE,
18114 &neighbor_soft_reconfiguration_cmd);
18115 install_element(BGP_FLOWSPECV6_NODE,
18116 &no_neighbor_soft_reconfiguration_cmd);
18117 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
18118 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
18119
18120 /* "neighbor attribute-unchanged" commands. */
18121 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
18122 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
18123 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
18124 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
18125 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
18126 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
18127 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
18128 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
18129 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
18130 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
18131 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
18132 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
18133 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
18134 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
18135 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
18136 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
18137 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
18138 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
18139
18140 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
18141 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
18142
18143 install_element(BGP_FLOWSPECV4_NODE, &neighbor_attr_unchanged_cmd);
18144 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_attr_unchanged_cmd);
18145 install_element(BGP_FLOWSPECV6_NODE, &neighbor_attr_unchanged_cmd);
18146 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_attr_unchanged_cmd);
18147
18148 /* "nexthop-local unchanged" commands */
18149 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
18150 install_element(BGP_IPV6_NODE,
18151 &no_neighbor_nexthop_local_unchanged_cmd);
18152
18153 /* "neighbor next-hop-self" commands. */
18154 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
18155 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
18156 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
18157 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
18158 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
18159 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
18160 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
18161 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
18162 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
18163 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
18164 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
18165 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
18166 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
18167 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
18168 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
18169 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
18170 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
18171 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
18172 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
18173 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
18174
18175 /* "neighbor next-hop-self force" commands. */
18176 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
18177 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
18178 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18179 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
18180 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
18181 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
18182 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18183 install_element(BGP_IPV4_NODE,
18184 &no_neighbor_nexthop_self_all_hidden_cmd);
18185 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
18186 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
18187 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18188 install_element(BGP_IPV4M_NODE,
18189 &no_neighbor_nexthop_self_all_hidden_cmd);
18190 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
18191 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
18192 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18193 install_element(BGP_IPV4L_NODE,
18194 &no_neighbor_nexthop_self_all_hidden_cmd);
18195 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
18196 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
18197 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18198 install_element(BGP_IPV6_NODE,
18199 &no_neighbor_nexthop_self_all_hidden_cmd);
18200 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
18201 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
18202 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18203 install_element(BGP_IPV6M_NODE,
18204 &no_neighbor_nexthop_self_all_hidden_cmd);
18205 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
18206 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
18207 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18208 install_element(BGP_IPV6L_NODE,
18209 &no_neighbor_nexthop_self_all_hidden_cmd);
18210 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
18211 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
18212 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18213 install_element(BGP_VPNV4_NODE,
18214 &no_neighbor_nexthop_self_all_hidden_cmd);
18215 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
18216 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
18217 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18218 install_element(BGP_VPNV6_NODE,
18219 &no_neighbor_nexthop_self_all_hidden_cmd);
18220 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_force_cmd);
18221 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_force_cmd);
18222
18223 /* "neighbor as-override" commands. */
18224 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
18225 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
18226 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
18227 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
18228 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
18229 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
18230 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
18231 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
18232 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
18233 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
18234 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
18235 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
18236 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
18237 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
18238 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
18239 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
18240 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
18241 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
18242
18243 /* "neighbor remove-private-AS" commands. */
18244 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
18245 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
18246 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
18247 install_element(BGP_NODE,
18248 &no_neighbor_remove_private_as_all_hidden_cmd);
18249 install_element(BGP_NODE,
18250 &neighbor_remove_private_as_replace_as_hidden_cmd);
18251 install_element(BGP_NODE,
18252 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
18253 install_element(BGP_NODE,
18254 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
18255 install_element(
18256 BGP_NODE,
18257 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
18258 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
18259 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
18260 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
18261 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18262 install_element(BGP_IPV4_NODE,
18263 &neighbor_remove_private_as_replace_as_cmd);
18264 install_element(BGP_IPV4_NODE,
18265 &no_neighbor_remove_private_as_replace_as_cmd);
18266 install_element(BGP_IPV4_NODE,
18267 &neighbor_remove_private_as_all_replace_as_cmd);
18268 install_element(BGP_IPV4_NODE,
18269 &no_neighbor_remove_private_as_all_replace_as_cmd);
18270 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
18271 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
18272 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
18273 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
18274 install_element(BGP_IPV4M_NODE,
18275 &neighbor_remove_private_as_replace_as_cmd);
18276 install_element(BGP_IPV4M_NODE,
18277 &no_neighbor_remove_private_as_replace_as_cmd);
18278 install_element(BGP_IPV4M_NODE,
18279 &neighbor_remove_private_as_all_replace_as_cmd);
18280 install_element(BGP_IPV4M_NODE,
18281 &no_neighbor_remove_private_as_all_replace_as_cmd);
18282 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
18283 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
18284 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
18285 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
18286 install_element(BGP_IPV4L_NODE,
18287 &neighbor_remove_private_as_replace_as_cmd);
18288 install_element(BGP_IPV4L_NODE,
18289 &no_neighbor_remove_private_as_replace_as_cmd);
18290 install_element(BGP_IPV4L_NODE,
18291 &neighbor_remove_private_as_all_replace_as_cmd);
18292 install_element(BGP_IPV4L_NODE,
18293 &no_neighbor_remove_private_as_all_replace_as_cmd);
18294 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
18295 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
18296 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
18297 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18298 install_element(BGP_IPV6_NODE,
18299 &neighbor_remove_private_as_replace_as_cmd);
18300 install_element(BGP_IPV6_NODE,
18301 &no_neighbor_remove_private_as_replace_as_cmd);
18302 install_element(BGP_IPV6_NODE,
18303 &neighbor_remove_private_as_all_replace_as_cmd);
18304 install_element(BGP_IPV6_NODE,
18305 &no_neighbor_remove_private_as_all_replace_as_cmd);
18306 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
18307 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
18308 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
18309 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
18310 install_element(BGP_IPV6M_NODE,
18311 &neighbor_remove_private_as_replace_as_cmd);
18312 install_element(BGP_IPV6M_NODE,
18313 &no_neighbor_remove_private_as_replace_as_cmd);
18314 install_element(BGP_IPV6M_NODE,
18315 &neighbor_remove_private_as_all_replace_as_cmd);
18316 install_element(BGP_IPV6M_NODE,
18317 &no_neighbor_remove_private_as_all_replace_as_cmd);
18318 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
18319 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
18320 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
18321 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
18322 install_element(BGP_IPV6L_NODE,
18323 &neighbor_remove_private_as_replace_as_cmd);
18324 install_element(BGP_IPV6L_NODE,
18325 &no_neighbor_remove_private_as_replace_as_cmd);
18326 install_element(BGP_IPV6L_NODE,
18327 &neighbor_remove_private_as_all_replace_as_cmd);
18328 install_element(BGP_IPV6L_NODE,
18329 &no_neighbor_remove_private_as_all_replace_as_cmd);
18330 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
18331 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
18332 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
18333 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18334 install_element(BGP_VPNV4_NODE,
18335 &neighbor_remove_private_as_replace_as_cmd);
18336 install_element(BGP_VPNV4_NODE,
18337 &no_neighbor_remove_private_as_replace_as_cmd);
18338 install_element(BGP_VPNV4_NODE,
18339 &neighbor_remove_private_as_all_replace_as_cmd);
18340 install_element(BGP_VPNV4_NODE,
18341 &no_neighbor_remove_private_as_all_replace_as_cmd);
18342 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
18343 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
18344 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
18345 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18346 install_element(BGP_VPNV6_NODE,
18347 &neighbor_remove_private_as_replace_as_cmd);
18348 install_element(BGP_VPNV6_NODE,
18349 &no_neighbor_remove_private_as_replace_as_cmd);
18350 install_element(BGP_VPNV6_NODE,
18351 &neighbor_remove_private_as_all_replace_as_cmd);
18352 install_element(BGP_VPNV6_NODE,
18353 &no_neighbor_remove_private_as_all_replace_as_cmd);
18354
18355 /* "neighbor send-community" commands.*/
18356 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
18357 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
18358 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
18359 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
18360 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
18361 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
18362 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
18363 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
18364 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
18365 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
18366 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
18367 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
18368 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
18369 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
18370 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
18371 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
18372 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
18373 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
18374 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
18375 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
18376 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
18377 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
18378 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
18379 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
18380 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
18381 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
18382 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
18383 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
18384 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
18385 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
18386 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
18387 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
18388 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
18389 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
18390 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
18391 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
18392
18393 /* "neighbor route-reflector" commands.*/
18394 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
18395 install_element(BGP_NODE,
18396 &no_neighbor_route_reflector_client_hidden_cmd);
18397 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
18398 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
18399 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
18400 install_element(BGP_IPV4M_NODE,
18401 &no_neighbor_route_reflector_client_cmd);
18402 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
18403 install_element(BGP_IPV4L_NODE,
18404 &no_neighbor_route_reflector_client_cmd);
18405 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
18406 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
18407 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
18408 install_element(BGP_IPV6M_NODE,
18409 &no_neighbor_route_reflector_client_cmd);
18410 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
18411 install_element(BGP_IPV6L_NODE,
18412 &no_neighbor_route_reflector_client_cmd);
18413 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
18414 install_element(BGP_VPNV4_NODE,
18415 &no_neighbor_route_reflector_client_cmd);
18416 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
18417 install_element(BGP_VPNV6_NODE,
18418 &no_neighbor_route_reflector_client_cmd);
18419 install_element(BGP_FLOWSPECV4_NODE,
18420 &neighbor_route_reflector_client_cmd);
18421 install_element(BGP_FLOWSPECV4_NODE,
18422 &no_neighbor_route_reflector_client_cmd);
18423 install_element(BGP_FLOWSPECV6_NODE,
18424 &neighbor_route_reflector_client_cmd);
18425 install_element(BGP_FLOWSPECV6_NODE,
18426 &no_neighbor_route_reflector_client_cmd);
18427 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
18428 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
18429
18430 /* "neighbor route-server" commands.*/
18431 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
18432 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
18433 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
18434 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
18435 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
18436 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
18437 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
18438 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
18439 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
18440 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
18441 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
18442 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
18443 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
18444 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
18445 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
18446 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
18447 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
18448 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
18449 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
18450 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
18451 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
18452 install_element(BGP_FLOWSPECV4_NODE,
18453 &no_neighbor_route_server_client_cmd);
18454 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
18455 install_element(BGP_FLOWSPECV6_NODE,
18456 &no_neighbor_route_server_client_cmd);
18457
18458 /* "neighbor addpath-tx-all-paths" commands.*/
18459 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
18460 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
18461 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
18462 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18463 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
18464 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18465 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
18466 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18467 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
18468 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18469 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
18470 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18471 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
18472 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18473 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
18474 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18475 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
18476 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18477
18478 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
18479 install_element(BGP_NODE,
18480 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
18481 install_element(BGP_NODE,
18482 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
18483 install_element(BGP_IPV4_NODE,
18484 &neighbor_addpath_tx_bestpath_per_as_cmd);
18485 install_element(BGP_IPV4_NODE,
18486 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18487 install_element(BGP_IPV4M_NODE,
18488 &neighbor_addpath_tx_bestpath_per_as_cmd);
18489 install_element(BGP_IPV4M_NODE,
18490 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18491 install_element(BGP_IPV4L_NODE,
18492 &neighbor_addpath_tx_bestpath_per_as_cmd);
18493 install_element(BGP_IPV4L_NODE,
18494 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18495 install_element(BGP_IPV6_NODE,
18496 &neighbor_addpath_tx_bestpath_per_as_cmd);
18497 install_element(BGP_IPV6_NODE,
18498 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18499 install_element(BGP_IPV6M_NODE,
18500 &neighbor_addpath_tx_bestpath_per_as_cmd);
18501 install_element(BGP_IPV6M_NODE,
18502 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18503 install_element(BGP_IPV6L_NODE,
18504 &neighbor_addpath_tx_bestpath_per_as_cmd);
18505 install_element(BGP_IPV6L_NODE,
18506 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18507 install_element(BGP_VPNV4_NODE,
18508 &neighbor_addpath_tx_bestpath_per_as_cmd);
18509 install_element(BGP_VPNV4_NODE,
18510 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18511 install_element(BGP_VPNV6_NODE,
18512 &neighbor_addpath_tx_bestpath_per_as_cmd);
18513 install_element(BGP_VPNV6_NODE,
18514 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18515
18516 /* "neighbor sender-as-path-loop-detection" commands. */
18517 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
18518 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
18519
18520 /* "neighbor passive" commands. */
18521 install_element(BGP_NODE, &neighbor_passive_cmd);
18522 install_element(BGP_NODE, &no_neighbor_passive_cmd);
18523
18524
18525 /* "neighbor shutdown" commands. */
18526 install_element(BGP_NODE, &neighbor_shutdown_cmd);
18527 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
18528 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
18529 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
18530 install_element(BGP_NODE, &neighbor_shutdown_rtt_cmd);
18531 install_element(BGP_NODE, &no_neighbor_shutdown_rtt_cmd);
18532
18533 /* "neighbor capability extended-nexthop" commands.*/
18534 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
18535 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
18536
18537 /* "neighbor capability orf prefix-list" commands.*/
18538 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
18539 install_element(BGP_NODE,
18540 &no_neighbor_capability_orf_prefix_hidden_cmd);
18541 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
18542 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
18543 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
18544 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
18545 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
18546 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
18547 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
18548 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
18549 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
18550 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
18551 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
18552 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
18553
18554 /* "neighbor capability dynamic" commands.*/
18555 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
18556 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
18557
18558 /* "neighbor dont-capability-negotiate" commands. */
18559 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
18560 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
18561
18562 /* "neighbor ebgp-multihop" commands. */
18563 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
18564 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
18565 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
18566
18567 /* "neighbor disable-connected-check" commands. */
18568 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
18569 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
18570
18571 /* "neighbor enforce-first-as" commands. */
18572 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
18573 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
18574
18575 /* "neighbor description" commands. */
18576 install_element(BGP_NODE, &neighbor_description_cmd);
18577 install_element(BGP_NODE, &no_neighbor_description_cmd);
18578 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
18579
18580 /* "neighbor update-source" commands. "*/
18581 install_element(BGP_NODE, &neighbor_update_source_cmd);
18582 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
18583
18584 /* "neighbor default-originate" commands. */
18585 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
18586 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
18587 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
18588 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
18589 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
18590 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
18591 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
18592 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
18593 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
18594 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
18595 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
18596 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
18597 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
18598 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
18599 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
18600 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
18601 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
18602 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
18603 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
18604 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
18605 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
18606
18607 /* "neighbor port" commands. */
18608 install_element(BGP_NODE, &neighbor_port_cmd);
18609 install_element(BGP_NODE, &no_neighbor_port_cmd);
18610
18611 /* "neighbor weight" commands. */
18612 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
18613 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
18614
18615 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
18616 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
18617 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
18618 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
18619 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
18620 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
18621 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
18622 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
18623 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
18624 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
18625 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
18626 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
18627 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
18628 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
18629 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
18630 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
18631
18632 /* "neighbor override-capability" commands. */
18633 install_element(BGP_NODE, &neighbor_override_capability_cmd);
18634 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
18635
18636 /* "neighbor strict-capability-match" commands. */
18637 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
18638 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
18639
18640 /* "neighbor timers" commands. */
18641 install_element(BGP_NODE, &neighbor_timers_cmd);
18642 install_element(BGP_NODE, &no_neighbor_timers_cmd);
18643
18644 /* "neighbor timers connect" commands. */
18645 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
18646 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
18647
18648 /* "neighbor timers delayopen" commands. */
18649 install_element(BGP_NODE, &neighbor_timers_delayopen_cmd);
18650 install_element(BGP_NODE, &no_neighbor_timers_delayopen_cmd);
18651
18652 /* "neighbor advertisement-interval" commands. */
18653 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
18654 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
18655
18656 /* "neighbor interface" commands. */
18657 install_element(BGP_NODE, &neighbor_interface_cmd);
18658 install_element(BGP_NODE, &no_neighbor_interface_cmd);
18659
18660 /* "neighbor distribute" commands. */
18661 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
18662 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
18663 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
18664 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
18665 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
18666 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
18667 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
18668 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
18669 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
18670 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
18671 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
18672 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
18673 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
18674 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
18675 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
18676 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
18677 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
18678 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
18679
18680 /* "neighbor prefix-list" commands. */
18681 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
18682 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
18683 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
18684 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
18685 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
18686 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
18687 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
18688 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
18689 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
18690 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
18691 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
18692
18693 /* "neighbor filter-list" commands. */
18694 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
18695 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
18696 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
18697 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
18698 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
18699 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
18700 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
18701 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
18702 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
18703 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
18704 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
18705 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
18706 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
18707 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
18708 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
18709 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
18710 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
18711 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
18712 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
18713 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
18714 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
18715 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
18716
18717 /* "neighbor route-map" commands. */
18718 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
18719 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
18720 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
18721 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
18722 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
18723 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
18724 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
18725 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
18726 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
18727 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
18728 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
18729
18730 /* "neighbor unsuppress-map" commands. */
18731 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
18732 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
18733 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
18734 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
18735 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
18736 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
18737 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
18738 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
18739 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
18740 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
18741 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
18742 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
18743 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
18744 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
18745 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
18746 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
18747 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
18748 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
18749
18750 /* "neighbor advertise-map" commands. */
18751 install_element(BGP_NODE, &neighbor_advertise_map_hidden_cmd);
18752 install_element(BGP_IPV4_NODE, &neighbor_advertise_map_cmd);
18753 install_element(BGP_IPV4M_NODE, &neighbor_advertise_map_cmd);
18754 install_element(BGP_IPV4L_NODE, &neighbor_advertise_map_cmd);
18755 install_element(BGP_IPV6_NODE, &neighbor_advertise_map_cmd);
18756 install_element(BGP_IPV6M_NODE, &neighbor_advertise_map_cmd);
18757 install_element(BGP_IPV6L_NODE, &neighbor_advertise_map_cmd);
18758 install_element(BGP_VPNV4_NODE, &neighbor_advertise_map_cmd);
18759 install_element(BGP_VPNV6_NODE, &neighbor_advertise_map_cmd);
18760
18761 /* neighbor maximum-prefix-out commands. */
18762 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
18763 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
18764 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
18765 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
18766 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
18767 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
18768 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
18769 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
18770 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
18771 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
18772 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
18773 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
18774 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
18775 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
18776 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
18777 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
18778 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
18779 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
18780
18781 /* "neighbor maximum-prefix" commands. */
18782 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
18783 install_element(BGP_NODE,
18784 &neighbor_maximum_prefix_threshold_hidden_cmd);
18785 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
18786 install_element(BGP_NODE,
18787 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
18788 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
18789 install_element(BGP_NODE,
18790 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
18791 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
18792 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
18793 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
18794 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
18795 install_element(BGP_IPV4_NODE,
18796 &neighbor_maximum_prefix_threshold_warning_cmd);
18797 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
18798 install_element(BGP_IPV4_NODE,
18799 &neighbor_maximum_prefix_threshold_restart_cmd);
18800 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
18801 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
18802 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
18803 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
18804 install_element(BGP_IPV4M_NODE,
18805 &neighbor_maximum_prefix_threshold_warning_cmd);
18806 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
18807 install_element(BGP_IPV4M_NODE,
18808 &neighbor_maximum_prefix_threshold_restart_cmd);
18809 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
18810 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
18811 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
18812 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
18813 install_element(BGP_IPV4L_NODE,
18814 &neighbor_maximum_prefix_threshold_warning_cmd);
18815 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
18816 install_element(BGP_IPV4L_NODE,
18817 &neighbor_maximum_prefix_threshold_restart_cmd);
18818 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
18819 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
18820 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
18821 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
18822 install_element(BGP_IPV6_NODE,
18823 &neighbor_maximum_prefix_threshold_warning_cmd);
18824 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
18825 install_element(BGP_IPV6_NODE,
18826 &neighbor_maximum_prefix_threshold_restart_cmd);
18827 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
18828 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
18829 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
18830 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
18831 install_element(BGP_IPV6M_NODE,
18832 &neighbor_maximum_prefix_threshold_warning_cmd);
18833 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
18834 install_element(BGP_IPV6M_NODE,
18835 &neighbor_maximum_prefix_threshold_restart_cmd);
18836 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
18837 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
18838 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
18839 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
18840 install_element(BGP_IPV6L_NODE,
18841 &neighbor_maximum_prefix_threshold_warning_cmd);
18842 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
18843 install_element(BGP_IPV6L_NODE,
18844 &neighbor_maximum_prefix_threshold_restart_cmd);
18845 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
18846 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
18847 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
18848 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
18849 install_element(BGP_VPNV4_NODE,
18850 &neighbor_maximum_prefix_threshold_warning_cmd);
18851 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
18852 install_element(BGP_VPNV4_NODE,
18853 &neighbor_maximum_prefix_threshold_restart_cmd);
18854 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
18855 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
18856 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
18857 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
18858 install_element(BGP_VPNV6_NODE,
18859 &neighbor_maximum_prefix_threshold_warning_cmd);
18860 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
18861 install_element(BGP_VPNV6_NODE,
18862 &neighbor_maximum_prefix_threshold_restart_cmd);
18863 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
18864
18865 /* "neighbor allowas-in" */
18866 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
18867 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
18868 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
18869 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
18870 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
18871 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
18872 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
18873 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
18874 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
18875 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
18876 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
18877 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
18878 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
18879 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
18880 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
18881 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
18882 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
18883 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
18884 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
18885 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
18886
18887 /* "neighbor dampening" commands. */
18888 install_element(BGP_NODE, &neighbor_damp_cmd);
18889 install_element(BGP_NODE, &no_neighbor_damp_cmd);
18890 install_element(BGP_IPV4_NODE, &neighbor_damp_cmd);
18891 install_element(BGP_IPV4_NODE, &no_neighbor_damp_cmd);
18892 install_element(BGP_IPV4M_NODE, &neighbor_damp_cmd);
18893 install_element(BGP_IPV4M_NODE, &no_neighbor_damp_cmd);
18894 install_element(BGP_IPV4L_NODE, &neighbor_damp_cmd);
18895 install_element(BGP_IPV4L_NODE, &no_neighbor_damp_cmd);
18896 install_element(BGP_IPV6_NODE, &neighbor_damp_cmd);
18897 install_element(BGP_IPV6_NODE, &no_neighbor_damp_cmd);
18898 install_element(BGP_IPV6M_NODE, &neighbor_damp_cmd);
18899 install_element(BGP_IPV6M_NODE, &no_neighbor_damp_cmd);
18900 install_element(BGP_IPV6L_NODE, &neighbor_damp_cmd);
18901 install_element(BGP_IPV6L_NODE, &no_neighbor_damp_cmd);
18902 install_element(VIEW_NODE, &show_ip_bgp_neighbor_damp_param_cmd);
18903
18904 /* address-family commands. */
18905 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
18906 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
18907 #ifdef KEEP_OLD_VPN_COMMANDS
18908 install_element(BGP_NODE, &address_family_vpnv4_cmd);
18909 install_element(BGP_NODE, &address_family_vpnv6_cmd);
18910 #endif /* KEEP_OLD_VPN_COMMANDS */
18911
18912 install_element(BGP_NODE, &address_family_evpn_cmd);
18913
18914 /* "exit-address-family" command. */
18915 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
18916 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
18917 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
18918 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
18919 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
18920 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
18921 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
18922 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
18923 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
18924 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
18925 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
18926
18927 /* "clear ip bgp commands" */
18928 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
18929
18930 /* clear ip bgp prefix */
18931 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
18932 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
18933 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
18934
18935 /* "show [ip] bgp summary" commands. */
18936 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
18937 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
18938 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
18939 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
18940 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
18941 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
18942 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
18943
18944 /* "show [ip] bgp neighbors" commands. */
18945 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
18946
18947 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
18948
18949 /* "show [ip] bgp peer-group" commands. */
18950 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
18951
18952 /* "show [ip] bgp paths" commands. */
18953 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
18954
18955 /* "show [ip] bgp community" commands. */
18956 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
18957
18958 /* "show ip bgp large-community" commands. */
18959 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
18960 /* "show [ip] bgp attribute-info" commands. */
18961 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
18962 /* "show [ip] bgp route-leak" command */
18963 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
18964
18965 /* "redistribute" commands. */
18966 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
18967 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
18968 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
18969 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
18970 install_element(BGP_NODE,
18971 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
18972 install_element(BGP_NODE,
18973 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
18974 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
18975 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
18976 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
18977 install_element(BGP_NODE,
18978 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
18979 install_element(BGP_NODE,
18980 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
18981 install_element(BGP_NODE,
18982 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
18983 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
18984 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
18985 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
18986 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
18987 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
18988 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
18989 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
18990 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
18991 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
18992 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
18993 install_element(BGP_IPV4_NODE,
18994 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
18995 install_element(BGP_IPV4_NODE,
18996 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
18997 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
18998 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
18999 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
19000 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
19001 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
19002 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
19003
19004 /* import|export vpn [route-map WORD] */
19005 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
19006 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
19007
19008 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
19009 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
19010
19011 /* ttl_security commands */
19012 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
19013 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
19014
19015 /* "show [ip] bgp memory" commands. */
19016 install_element(VIEW_NODE, &show_bgp_memory_cmd);
19017
19018 /* "show bgp martian next-hop" */
19019 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
19020
19021 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
19022
19023 /* "show [ip] bgp views" commands. */
19024 install_element(VIEW_NODE, &show_bgp_views_cmd);
19025
19026 /* "show [ip] bgp vrfs" commands. */
19027 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
19028
19029 /* Community-list. */
19030 community_list_vty();
19031
19032 /* vpn-policy commands */
19033 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
19034 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
19035 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
19036 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
19037 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
19038 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
19039 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
19040 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
19041 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
19042 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
19043 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
19044 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
19045
19046 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
19047 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
19048
19049 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
19050 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
19051 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
19052 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
19053 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
19054 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
19055 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
19056 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
19057 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
19058 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
19059 }
19060
19061 #include "memory.h"
19062 #include "bgp_regex.h"
19063 #include "bgp_clist.h"
19064 #include "bgp_ecommunity.h"
19065
19066 /* VTY functions. */
19067
19068 /* Direction value to string conversion. */
19069 static const char *community_direct_str(int direct)
19070 {
19071 switch (direct) {
19072 case COMMUNITY_DENY:
19073 return "deny";
19074 case COMMUNITY_PERMIT:
19075 return "permit";
19076 default:
19077 return "unknown";
19078 }
19079 }
19080
19081 /* Display error string. */
19082 static void community_list_perror(struct vty *vty, int ret)
19083 {
19084 switch (ret) {
19085 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
19086 vty_out(vty, "%% Can't find community-list\n");
19087 break;
19088 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
19089 vty_out(vty, "%% Malformed community-list value\n");
19090 break;
19091 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
19092 vty_out(vty,
19093 "%% Community name conflict, previously defined as standard community\n");
19094 break;
19095 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
19096 vty_out(vty,
19097 "%% Community name conflict, previously defined as expanded community\n");
19098 break;
19099 }
19100 }
19101
19102 /* "community-list" keyword help string. */
19103 #define COMMUNITY_LIST_STR "Add a community list entry\n"
19104
19105 /*community-list standard */
19106 DEFUN (community_list_standard,
19107 bgp_community_list_standard_cmd,
19108 "bgp community-list <(1-99)|standard WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
19109 BGP_STR
19110 COMMUNITY_LIST_STR
19111 "Community list number (standard)\n"
19112 "Add an standard community-list entry\n"
19113 "Community list name\n"
19114 "Sequence number of an entry\n"
19115 "Sequence number\n"
19116 "Specify community to reject\n"
19117 "Specify community to accept\n"
19118 COMMUNITY_VAL_STR)
19119 {
19120 char *cl_name_or_number = NULL;
19121 char *seq = NULL;
19122 int direct = 0;
19123 int style = COMMUNITY_LIST_STANDARD;
19124 int idx = 0;
19125
19126 argv_find(argv, argc, "(0-4294967295)", &idx);
19127 if (idx)
19128 seq = argv[idx]->arg;
19129
19130 idx = 0;
19131 argv_find(argv, argc, "(1-99)", &idx);
19132 argv_find(argv, argc, "WORD", &idx);
19133 cl_name_or_number = argv[idx]->arg;
19134 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19135 : COMMUNITY_DENY;
19136 argv_find(argv, argc, "AA:NN", &idx);
19137 char *str = argv_concat(argv, argc, idx);
19138
19139 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19140 direct, style);
19141
19142 XFREE(MTYPE_TMP, str);
19143
19144 if (ret < 0) {
19145 /* Display error string. */
19146 community_list_perror(vty, ret);
19147 return CMD_WARNING_CONFIG_FAILED;
19148 }
19149
19150 return CMD_SUCCESS;
19151 }
19152
19153 DEFUN (no_community_list_standard_all,
19154 no_bgp_community_list_standard_all_cmd,
19155 "no bgp community-list <(1-99)|standard WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
19156 NO_STR
19157 BGP_STR
19158 COMMUNITY_LIST_STR
19159 "Community list number (standard)\n"
19160 "Add an standard community-list entry\n"
19161 "Community list name\n"
19162 "Sequence number of an entry\n"
19163 "Sequence number\n"
19164 "Specify community to reject\n"
19165 "Specify community to accept\n"
19166 COMMUNITY_VAL_STR)
19167 {
19168 char *cl_name_or_number = NULL;
19169 char *str = NULL;
19170 int direct = 0;
19171 int style = COMMUNITY_LIST_STANDARD;
19172 char *seq = NULL;
19173 int idx = 0;
19174
19175 argv_find(argv, argc, "(0-4294967295)", &idx);
19176 if (idx)
19177 seq = argv[idx]->arg;
19178
19179 idx = 0;
19180 argv_find(argv, argc, "permit", &idx);
19181 argv_find(argv, argc, "deny", &idx);
19182
19183 if (idx) {
19184 direct = argv_find(argv, argc, "permit", &idx)
19185 ? COMMUNITY_PERMIT
19186 : COMMUNITY_DENY;
19187
19188 idx = 0;
19189 argv_find(argv, argc, "AA:NN", &idx);
19190 str = argv_concat(argv, argc, idx);
19191 }
19192
19193 idx = 0;
19194 argv_find(argv, argc, "(1-99)", &idx);
19195 argv_find(argv, argc, "WORD", &idx);
19196 cl_name_or_number = argv[idx]->arg;
19197
19198 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
19199 direct, style);
19200
19201 XFREE(MTYPE_TMP, str);
19202
19203 if (ret < 0) {
19204 community_list_perror(vty, ret);
19205 return CMD_WARNING_CONFIG_FAILED;
19206 }
19207
19208 return CMD_SUCCESS;
19209 }
19210
19211 ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
19212 "no bgp community-list <(1-99)|standard WORD>",
19213 NO_STR BGP_STR COMMUNITY_LIST_STR
19214 "Community list number (standard)\n"
19215 "Add an standard community-list entry\n"
19216 "Community list name\n")
19217
19218 /*community-list expanded */
19219 DEFUN (community_list_expanded_all,
19220 bgp_community_list_expanded_all_cmd,
19221 "bgp community-list <(100-500)|expanded WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
19222 BGP_STR
19223 COMMUNITY_LIST_STR
19224 "Community list number (expanded)\n"
19225 "Add an expanded community-list entry\n"
19226 "Community list name\n"
19227 "Sequence number of an entry\n"
19228 "Sequence number\n"
19229 "Specify community to reject\n"
19230 "Specify community to accept\n"
19231 COMMUNITY_VAL_STR)
19232 {
19233 char *cl_name_or_number = NULL;
19234 char *seq = NULL;
19235 int direct = 0;
19236 int style = COMMUNITY_LIST_EXPANDED;
19237 int idx = 0;
19238
19239 argv_find(argv, argc, "(0-4294967295)", &idx);
19240 if (idx)
19241 seq = argv[idx]->arg;
19242
19243 idx = 0;
19244
19245 argv_find(argv, argc, "(100-500)", &idx);
19246 argv_find(argv, argc, "WORD", &idx);
19247 cl_name_or_number = argv[idx]->arg;
19248 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19249 : COMMUNITY_DENY;
19250 argv_find(argv, argc, "AA:NN", &idx);
19251 char *str = argv_concat(argv, argc, idx);
19252
19253 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19254 direct, style);
19255
19256 XFREE(MTYPE_TMP, str);
19257
19258 if (ret < 0) {
19259 /* Display error string. */
19260 community_list_perror(vty, ret);
19261 return CMD_WARNING_CONFIG_FAILED;
19262 }
19263
19264 return CMD_SUCCESS;
19265 }
19266
19267 DEFUN (no_community_list_expanded_all,
19268 no_bgp_community_list_expanded_all_cmd,
19269 "no bgp community-list <(100-500)|expanded WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
19270 NO_STR
19271 BGP_STR
19272 COMMUNITY_LIST_STR
19273 "Community list number (expanded)\n"
19274 "Add an expanded community-list entry\n"
19275 "Community list name\n"
19276 "Sequence number of an entry\n"
19277 "Sequence number\n"
19278 "Specify community to reject\n"
19279 "Specify community to accept\n"
19280 COMMUNITY_VAL_STR)
19281 {
19282 char *cl_name_or_number = NULL;
19283 char *seq = NULL;
19284 char *str = NULL;
19285 int direct = 0;
19286 int style = COMMUNITY_LIST_EXPANDED;
19287 int idx = 0;
19288
19289 argv_find(argv, argc, "(0-4294967295)", &idx);
19290 if (idx)
19291 seq = argv[idx]->arg;
19292
19293 idx = 0;
19294 argv_find(argv, argc, "permit", &idx);
19295 argv_find(argv, argc, "deny", &idx);
19296
19297 if (idx) {
19298 direct = argv_find(argv, argc, "permit", &idx)
19299 ? COMMUNITY_PERMIT
19300 : COMMUNITY_DENY;
19301
19302 idx = 0;
19303 argv_find(argv, argc, "AA:NN", &idx);
19304 str = argv_concat(argv, argc, idx);
19305 }
19306
19307 idx = 0;
19308 argv_find(argv, argc, "(100-500)", &idx);
19309 argv_find(argv, argc, "WORD", &idx);
19310 cl_name_or_number = argv[idx]->arg;
19311
19312 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
19313 direct, style);
19314
19315 XFREE(MTYPE_TMP, str);
19316
19317 if (ret < 0) {
19318 community_list_perror(vty, ret);
19319 return CMD_WARNING_CONFIG_FAILED;
19320 }
19321
19322 return CMD_SUCCESS;
19323 }
19324
19325 ALIAS(no_community_list_expanded_all,
19326 no_bgp_community_list_expanded_all_list_cmd,
19327 "no bgp community-list <(100-500)|expanded WORD>",
19328 NO_STR BGP_STR COMMUNITY_LIST_STR
19329 "Community list number (expanded)\n"
19330 "Add an expanded community-list entry\n"
19331 "Community list name\n")
19332
19333 /* Return configuration string of community-list entry. */
19334 static const char *community_list_config_str(struct community_entry *entry)
19335 {
19336 const char *str;
19337
19338 if (entry->any)
19339 str = "";
19340 else {
19341 if (entry->style == COMMUNITY_LIST_STANDARD)
19342 str = community_str(entry->u.com, false);
19343 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
19344 str = lcommunity_str(entry->u.lcom, false);
19345 else
19346 str = entry->config;
19347 }
19348 return str;
19349 }
19350
19351 static void community_list_show(struct vty *vty, struct community_list *list)
19352 {
19353 struct community_entry *entry;
19354
19355 for (entry = list->head; entry; entry = entry->next) {
19356 if (entry == list->head) {
19357 if (all_digit(list->name))
19358 vty_out(vty, "Community %s list %s\n",
19359 entry->style == COMMUNITY_LIST_STANDARD
19360 ? "standard"
19361 : "(expanded) access",
19362 list->name);
19363 else
19364 vty_out(vty, "Named Community %s list %s\n",
19365 entry->style == COMMUNITY_LIST_STANDARD
19366 ? "standard"
19367 : "expanded",
19368 list->name);
19369 }
19370 if (entry->any)
19371 vty_out(vty, " %s\n",
19372 community_direct_str(entry->direct));
19373 else
19374 vty_out(vty, " %s %s\n",
19375 community_direct_str(entry->direct),
19376 community_list_config_str(entry));
19377 }
19378 }
19379
19380 DEFUN (show_community_list,
19381 show_bgp_community_list_cmd,
19382 "show bgp community-list",
19383 SHOW_STR
19384 BGP_STR
19385 "List community-list\n")
19386 {
19387 struct community_list *list;
19388 struct community_list_master *cm;
19389
19390 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
19391 if (!cm)
19392 return CMD_SUCCESS;
19393
19394 for (list = cm->num.head; list; list = list->next)
19395 community_list_show(vty, list);
19396
19397 for (list = cm->str.head; list; list = list->next)
19398 community_list_show(vty, list);
19399
19400 return CMD_SUCCESS;
19401 }
19402
19403 DEFUN (show_community_list_arg,
19404 show_bgp_community_list_arg_cmd,
19405 "show bgp community-list <(1-500)|WORD> detail",
19406 SHOW_STR
19407 BGP_STR
19408 "List community-list\n"
19409 "Community-list number\n"
19410 "Community-list name\n"
19411 "Detailed information on community-list\n")
19412 {
19413 int idx_comm_list = 3;
19414 struct community_list *list;
19415
19416 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
19417 COMMUNITY_LIST_MASTER);
19418 if (!list) {
19419 vty_out(vty, "%% Can't find community-list\n");
19420 return CMD_WARNING;
19421 }
19422
19423 community_list_show(vty, list);
19424
19425 return CMD_SUCCESS;
19426 }
19427
19428 /*
19429 * Large Community code.
19430 */
19431 static int lcommunity_list_set_vty(struct vty *vty, int argc,
19432 struct cmd_token **argv, int style,
19433 int reject_all_digit_name)
19434 {
19435 int ret;
19436 int direct;
19437 char *str;
19438 int idx = 0;
19439 char *cl_name;
19440 char *seq = NULL;
19441
19442 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19443 seq = argv[idx]->arg;
19444
19445 idx = 0;
19446 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19447 : COMMUNITY_DENY;
19448
19449 /* All digit name check. */
19450 idx = 0;
19451 argv_find(argv, argc, "WORD", &idx);
19452 argv_find(argv, argc, "(1-99)", &idx);
19453 argv_find(argv, argc, "(100-500)", &idx);
19454 cl_name = argv[idx]->arg;
19455 if (reject_all_digit_name && all_digit(cl_name)) {
19456 vty_out(vty, "%% Community name cannot have all digits\n");
19457 return CMD_WARNING_CONFIG_FAILED;
19458 }
19459
19460 idx = 0;
19461 argv_find(argv, argc, "AA:BB:CC", &idx);
19462 argv_find(argv, argc, "LINE", &idx);
19463 /* Concat community string argument. */
19464 if (idx)
19465 str = argv_concat(argv, argc, idx);
19466 else
19467 str = NULL;
19468
19469 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
19470
19471 /* Free temporary community list string allocated by
19472 argv_concat(). */
19473 XFREE(MTYPE_TMP, str);
19474
19475 if (ret < 0) {
19476 community_list_perror(vty, ret);
19477 return CMD_WARNING_CONFIG_FAILED;
19478 }
19479 return CMD_SUCCESS;
19480 }
19481
19482 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
19483 struct cmd_token **argv, int style)
19484 {
19485 int ret;
19486 int direct = 0;
19487 char *str = NULL;
19488 int idx = 0;
19489 char *seq = NULL;
19490
19491 if (argv_find(argv, argc, "(0-4294967295)", &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 /* Check the list direct. */
19500 if (strncmp(argv[idx]->arg, "p", 1) == 0)
19501 direct = COMMUNITY_PERMIT;
19502 else
19503 direct = COMMUNITY_DENY;
19504
19505 idx = 0;
19506 argv_find(argv, argc, "LINE", &idx);
19507 argv_find(argv, argc, "AA:AA:NN", &idx);
19508 /* Concat community string argument. */
19509 str = argv_concat(argv, argc, idx);
19510 }
19511
19512 idx = 0;
19513 argv_find(argv, argc, "(1-99)", &idx);
19514 argv_find(argv, argc, "(100-500)", &idx);
19515 argv_find(argv, argc, "WORD", &idx);
19516
19517 /* Unset community list. */
19518 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
19519 style);
19520
19521 /* Free temporary community list string allocated by
19522 argv_concat(). */
19523 XFREE(MTYPE_TMP, str);
19524
19525 if (ret < 0) {
19526 community_list_perror(vty, ret);
19527 return CMD_WARNING_CONFIG_FAILED;
19528 }
19529
19530 return CMD_SUCCESS;
19531 }
19532
19533 /* "large-community-list" keyword help string. */
19534 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
19535 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
19536
19537 DEFUN (lcommunity_list_standard,
19538 bgp_lcommunity_list_standard_cmd,
19539 "bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
19540 BGP_STR
19541 LCOMMUNITY_LIST_STR
19542 "Large Community list number (standard)\n"
19543 "Sequence number of an entry\n"
19544 "Sequence number\n"
19545 "Specify large community to reject\n"
19546 "Specify large community to accept\n"
19547 LCOMMUNITY_VAL_STR)
19548 {
19549 return lcommunity_list_set_vty(vty, argc, argv,
19550 LARGE_COMMUNITY_LIST_STANDARD, 0);
19551 }
19552
19553 DEFUN (lcommunity_list_expanded,
19554 bgp_lcommunity_list_expanded_cmd,
19555 "bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
19556 BGP_STR
19557 LCOMMUNITY_LIST_STR
19558 "Large Community list number (expanded)\n"
19559 "Sequence number of an entry\n"
19560 "Sequence number\n"
19561 "Specify large community to reject\n"
19562 "Specify large community to accept\n"
19563 "An ordered list as a regular-expression\n")
19564 {
19565 return lcommunity_list_set_vty(vty, argc, argv,
19566 LARGE_COMMUNITY_LIST_EXPANDED, 0);
19567 }
19568
19569 DEFUN (lcommunity_list_name_standard,
19570 bgp_lcommunity_list_name_standard_cmd,
19571 "bgp large-community-list standard WORD [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
19572 BGP_STR
19573 LCOMMUNITY_LIST_STR
19574 "Specify standard large-community-list\n"
19575 "Large Community list name\n"
19576 "Sequence number of an entry\n"
19577 "Sequence number\n"
19578 "Specify large community to reject\n"
19579 "Specify large community to accept\n"
19580 LCOMMUNITY_VAL_STR)
19581 {
19582 return lcommunity_list_set_vty(vty, argc, argv,
19583 LARGE_COMMUNITY_LIST_STANDARD, 1);
19584 }
19585
19586 DEFUN (lcommunity_list_name_expanded,
19587 bgp_lcommunity_list_name_expanded_cmd,
19588 "bgp large-community-list expanded WORD [seq (0-4294967295)] <deny|permit> LINE...",
19589 BGP_STR
19590 LCOMMUNITY_LIST_STR
19591 "Specify expanded large-community-list\n"
19592 "Large Community list name\n"
19593 "Sequence number of an entry\n"
19594 "Sequence number\n"
19595 "Specify large community to reject\n"
19596 "Specify large community to accept\n"
19597 "An ordered list as a regular-expression\n")
19598 {
19599 return lcommunity_list_set_vty(vty, argc, argv,
19600 LARGE_COMMUNITY_LIST_EXPANDED, 1);
19601 }
19602
19603 DEFUN (no_lcommunity_list_all,
19604 no_bgp_lcommunity_list_all_cmd,
19605 "no bgp large-community-list <(1-99)|(100-500)|WORD>",
19606 NO_STR
19607 BGP_STR
19608 LCOMMUNITY_LIST_STR
19609 "Large Community list number (standard)\n"
19610 "Large Community list number (expanded)\n"
19611 "Large Community list name\n")
19612 {
19613 return lcommunity_list_unset_vty(vty, argc, argv,
19614 LARGE_COMMUNITY_LIST_STANDARD);
19615 }
19616
19617 DEFUN (no_lcommunity_list_name_standard_all,
19618 no_bgp_lcommunity_list_name_standard_all_cmd,
19619 "no bgp large-community-list standard WORD",
19620 NO_STR
19621 BGP_STR
19622 LCOMMUNITY_LIST_STR
19623 "Specify standard large-community-list\n"
19624 "Large Community list name\n")
19625 {
19626 return lcommunity_list_unset_vty(vty, argc, argv,
19627 LARGE_COMMUNITY_LIST_STANDARD);
19628 }
19629
19630 DEFUN (no_lcommunity_list_name_expanded_all,
19631 no_bgp_lcommunity_list_name_expanded_all_cmd,
19632 "no bgp large-community-list expanded WORD",
19633 NO_STR
19634 BGP_STR
19635 LCOMMUNITY_LIST_STR
19636 "Specify expanded large-community-list\n"
19637 "Large Community list name\n")
19638 {
19639 return lcommunity_list_unset_vty(vty, argc, argv,
19640 LARGE_COMMUNITY_LIST_EXPANDED);
19641 }
19642
19643 DEFUN (no_lcommunity_list_standard,
19644 no_bgp_lcommunity_list_standard_cmd,
19645 "no bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
19646 NO_STR
19647 BGP_STR
19648 LCOMMUNITY_LIST_STR
19649 "Large Community list number (standard)\n"
19650 "Sequence number of an entry\n"
19651 "Sequence number\n"
19652 "Specify large community to reject\n"
19653 "Specify large community to accept\n"
19654 LCOMMUNITY_VAL_STR)
19655 {
19656 return lcommunity_list_unset_vty(vty, argc, argv,
19657 LARGE_COMMUNITY_LIST_STANDARD);
19658 }
19659
19660 DEFUN (no_lcommunity_list_expanded,
19661 no_bgp_lcommunity_list_expanded_cmd,
19662 "no bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
19663 NO_STR
19664 BGP_STR
19665 LCOMMUNITY_LIST_STR
19666 "Large Community list number (expanded)\n"
19667 "Sequence number of an entry\n"
19668 "Sequence number\n"
19669 "Specify large community to reject\n"
19670 "Specify large community to accept\n"
19671 "An ordered list as a regular-expression\n")
19672 {
19673 return lcommunity_list_unset_vty(vty, argc, argv,
19674 LARGE_COMMUNITY_LIST_EXPANDED);
19675 }
19676
19677 DEFUN (no_lcommunity_list_name_standard,
19678 no_bgp_lcommunity_list_name_standard_cmd,
19679 "no bgp large-community-list standard WORD [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
19680 NO_STR
19681 BGP_STR
19682 LCOMMUNITY_LIST_STR
19683 "Specify standard large-community-list\n"
19684 "Large Community list name\n"
19685 "Sequence number of an entry\n"
19686 "Sequence number\n"
19687 "Specify large community to reject\n"
19688 "Specify large community to accept\n"
19689 LCOMMUNITY_VAL_STR)
19690 {
19691 return lcommunity_list_unset_vty(vty, argc, argv,
19692 LARGE_COMMUNITY_LIST_STANDARD);
19693 }
19694
19695 DEFUN (no_lcommunity_list_name_expanded,
19696 no_bgp_lcommunity_list_name_expanded_cmd,
19697 "no bgp large-community-list expanded WORD [seq (0-4294967295)] <deny|permit> LINE...",
19698 NO_STR
19699 BGP_STR
19700 LCOMMUNITY_LIST_STR
19701 "Specify expanded large-community-list\n"
19702 "Large community list name\n"
19703 "Sequence number of an entry\n"
19704 "Sequence number\n"
19705 "Specify large community to reject\n"
19706 "Specify large community to accept\n"
19707 "An ordered list as a regular-expression\n")
19708 {
19709 return lcommunity_list_unset_vty(vty, argc, argv,
19710 LARGE_COMMUNITY_LIST_EXPANDED);
19711 }
19712
19713 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
19714 {
19715 struct community_entry *entry;
19716
19717 for (entry = list->head; entry; entry = entry->next) {
19718 if (entry == list->head) {
19719 if (all_digit(list->name))
19720 vty_out(vty, "Large community %s list %s\n",
19721 entry->style ==
19722 LARGE_COMMUNITY_LIST_STANDARD
19723 ? "standard"
19724 : "(expanded) access",
19725 list->name);
19726 else
19727 vty_out(vty,
19728 "Named large community %s list %s\n",
19729 entry->style ==
19730 LARGE_COMMUNITY_LIST_STANDARD
19731 ? "standard"
19732 : "expanded",
19733 list->name);
19734 }
19735 if (entry->any)
19736 vty_out(vty, " %s\n",
19737 community_direct_str(entry->direct));
19738 else
19739 vty_out(vty, " %s %s\n",
19740 community_direct_str(entry->direct),
19741 community_list_config_str(entry));
19742 }
19743 }
19744
19745 DEFUN (show_lcommunity_list,
19746 show_bgp_lcommunity_list_cmd,
19747 "show bgp large-community-list",
19748 SHOW_STR
19749 BGP_STR
19750 "List large-community list\n")
19751 {
19752 struct community_list *list;
19753 struct community_list_master *cm;
19754
19755 cm = community_list_master_lookup(bgp_clist,
19756 LARGE_COMMUNITY_LIST_MASTER);
19757 if (!cm)
19758 return CMD_SUCCESS;
19759
19760 for (list = cm->num.head; list; list = list->next)
19761 lcommunity_list_show(vty, list);
19762
19763 for (list = cm->str.head; list; list = list->next)
19764 lcommunity_list_show(vty, list);
19765
19766 return CMD_SUCCESS;
19767 }
19768
19769 DEFUN (show_lcommunity_list_arg,
19770 show_bgp_lcommunity_list_arg_cmd,
19771 "show bgp large-community-list <(1-500)|WORD> detail",
19772 SHOW_STR
19773 BGP_STR
19774 "List large-community list\n"
19775 "Large-community-list number\n"
19776 "Large-community-list name\n"
19777 "Detailed information on large-community-list\n")
19778 {
19779 struct community_list *list;
19780
19781 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
19782 LARGE_COMMUNITY_LIST_MASTER);
19783 if (!list) {
19784 vty_out(vty, "%% Can't find large-community-list\n");
19785 return CMD_WARNING;
19786 }
19787
19788 lcommunity_list_show(vty, list);
19789
19790 return CMD_SUCCESS;
19791 }
19792
19793 /* "extcommunity-list" keyword help string. */
19794 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
19795 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
19796
19797 DEFUN (extcommunity_list_standard,
19798 bgp_extcommunity_list_standard_cmd,
19799 "bgp extcommunity-list <(1-99)|standard WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
19800 BGP_STR
19801 EXTCOMMUNITY_LIST_STR
19802 "Extended Community list number (standard)\n"
19803 "Specify standard extcommunity-list\n"
19804 "Community list name\n"
19805 "Sequence number of an entry\n"
19806 "Sequence number\n"
19807 "Specify community to reject\n"
19808 "Specify community to accept\n"
19809 EXTCOMMUNITY_VAL_STR)
19810 {
19811 int style = EXTCOMMUNITY_LIST_STANDARD;
19812 int direct = 0;
19813 char *cl_number_or_name = NULL;
19814 char *seq = NULL;
19815
19816 int idx = 0;
19817
19818 argv_find(argv, argc, "(1-99)", &idx);
19819 argv_find(argv, argc, "WORD", &idx);
19820 cl_number_or_name = argv[idx]->arg;
19821
19822 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19823 seq = argv[idx]->arg;
19824
19825 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19826 : COMMUNITY_DENY;
19827 argv_find(argv, argc, "AA:NN", &idx);
19828 char *str = argv_concat(argv, argc, idx);
19829
19830 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
19831 direct, style);
19832
19833 XFREE(MTYPE_TMP, str);
19834
19835 if (ret < 0) {
19836 community_list_perror(vty, ret);
19837 return CMD_WARNING_CONFIG_FAILED;
19838 }
19839
19840 return CMD_SUCCESS;
19841 }
19842
19843 DEFUN (extcommunity_list_name_expanded,
19844 bgp_extcommunity_list_name_expanded_cmd,
19845 "bgp extcommunity-list <(100-500)|expanded WORD> [seq (0-4294967295)] <deny|permit> LINE...",
19846 BGP_STR
19847 EXTCOMMUNITY_LIST_STR
19848 "Extended Community list number (expanded)\n"
19849 "Specify expanded extcommunity-list\n"
19850 "Extended Community list name\n"
19851 "Sequence number of an entry\n"
19852 "Sequence number\n"
19853 "Specify community to reject\n"
19854 "Specify community to accept\n"
19855 "An ordered list as a regular-expression\n")
19856 {
19857 int style = EXTCOMMUNITY_LIST_EXPANDED;
19858 int direct = 0;
19859 char *cl_number_or_name = NULL;
19860 char *seq = NULL;
19861 int idx = 0;
19862
19863 argv_find(argv, argc, "(100-500)", &idx);
19864 argv_find(argv, argc, "WORD", &idx);
19865 cl_number_or_name = argv[idx]->arg;
19866
19867 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19868 seq = argv[idx]->arg;
19869
19870 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19871 : COMMUNITY_DENY;
19872 argv_find(argv, argc, "LINE", &idx);
19873 char *str = argv_concat(argv, argc, idx);
19874
19875 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
19876 direct, style);
19877
19878 XFREE(MTYPE_TMP, str);
19879
19880 if (ret < 0) {
19881 community_list_perror(vty, ret);
19882 return CMD_WARNING_CONFIG_FAILED;
19883 }
19884
19885 return CMD_SUCCESS;
19886 }
19887
19888 DEFUN (no_extcommunity_list_standard_all,
19889 no_bgp_extcommunity_list_standard_all_cmd,
19890 "no bgp extcommunity-list <(1-99)|standard WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
19891 NO_STR
19892 BGP_STR
19893 EXTCOMMUNITY_LIST_STR
19894 "Extended Community list number (standard)\n"
19895 "Specify standard extcommunity-list\n"
19896 "Community list name\n"
19897 "Sequence number of an entry\n"
19898 "Sequence number\n"
19899 "Specify community to reject\n"
19900 "Specify community to accept\n"
19901 EXTCOMMUNITY_VAL_STR)
19902 {
19903 int style = EXTCOMMUNITY_LIST_STANDARD;
19904 int direct = 0;
19905 char *cl_number_or_name = NULL;
19906 char *str = NULL;
19907 char *seq = NULL;
19908 int idx = 0;
19909
19910 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19911 seq = argv[idx]->arg;
19912
19913 idx = 0;
19914 argv_find(argv, argc, "permit", &idx);
19915 argv_find(argv, argc, "deny", &idx);
19916 if (idx) {
19917 direct = argv_find(argv, argc, "permit", &idx)
19918 ? COMMUNITY_PERMIT
19919 : COMMUNITY_DENY;
19920
19921 idx = 0;
19922 argv_find(argv, argc, "AA:NN", &idx);
19923 str = argv_concat(argv, argc, idx);
19924 }
19925
19926 idx = 0;
19927 argv_find(argv, argc, "(1-99)", &idx);
19928 argv_find(argv, argc, "WORD", &idx);
19929 cl_number_or_name = argv[idx]->arg;
19930
19931 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
19932 seq, direct, style);
19933
19934 XFREE(MTYPE_TMP, str);
19935
19936 if (ret < 0) {
19937 community_list_perror(vty, ret);
19938 return CMD_WARNING_CONFIG_FAILED;
19939 }
19940
19941 return CMD_SUCCESS;
19942 }
19943
19944 ALIAS(no_extcommunity_list_standard_all,
19945 no_bgp_extcommunity_list_standard_all_list_cmd,
19946 "no bgp extcommunity-list <(1-99)|standard WORD>",
19947 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
19948 "Extended Community list number (standard)\n"
19949 "Specify standard extcommunity-list\n"
19950 "Community list name\n")
19951
19952 DEFUN (no_extcommunity_list_expanded_all,
19953 no_bgp_extcommunity_list_expanded_all_cmd,
19954 "no bgp extcommunity-list <(100-500)|expanded WORD> [seq (0-4294967295)] <deny|permit> LINE...",
19955 NO_STR
19956 BGP_STR
19957 EXTCOMMUNITY_LIST_STR
19958 "Extended Community list number (expanded)\n"
19959 "Specify expanded extcommunity-list\n"
19960 "Extended Community list name\n"
19961 "Sequence number of an entry\n"
19962 "Sequence number\n"
19963 "Specify community to reject\n"
19964 "Specify community to accept\n"
19965 "An ordered list as a regular-expression\n")
19966 {
19967 int style = EXTCOMMUNITY_LIST_EXPANDED;
19968 int direct = 0;
19969 char *cl_number_or_name = NULL;
19970 char *str = NULL;
19971 char *seq = NULL;
19972 int idx = 0;
19973
19974 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19975 seq = argv[idx]->arg;
19976
19977 idx = 0;
19978 argv_find(argv, argc, "permit", &idx);
19979 argv_find(argv, argc, "deny", &idx);
19980
19981 if (idx) {
19982 direct = argv_find(argv, argc, "permit", &idx)
19983 ? COMMUNITY_PERMIT
19984 : COMMUNITY_DENY;
19985
19986 idx = 0;
19987 argv_find(argv, argc, "LINE", &idx);
19988 str = argv_concat(argv, argc, idx);
19989 }
19990
19991 idx = 0;
19992 argv_find(argv, argc, "(100-500)", &idx);
19993 argv_find(argv, argc, "WORD", &idx);
19994 cl_number_or_name = argv[idx]->arg;
19995
19996 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
19997 seq, direct, style);
19998
19999 XFREE(MTYPE_TMP, str);
20000
20001 if (ret < 0) {
20002 community_list_perror(vty, ret);
20003 return CMD_WARNING_CONFIG_FAILED;
20004 }
20005
20006 return CMD_SUCCESS;
20007 }
20008
20009 ALIAS(no_extcommunity_list_expanded_all,
20010 no_bgp_extcommunity_list_expanded_all_list_cmd,
20011 "no bgp extcommunity-list <(100-500)|expanded WORD>",
20012 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
20013 "Extended Community list number (expanded)\n"
20014 "Specify expanded extcommunity-list\n"
20015 "Extended Community list name\n")
20016
20017 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
20018 {
20019 struct community_entry *entry;
20020
20021 for (entry = list->head; entry; entry = entry->next) {
20022 if (entry == list->head) {
20023 if (all_digit(list->name))
20024 vty_out(vty, "Extended community %s list %s\n",
20025 entry->style == EXTCOMMUNITY_LIST_STANDARD
20026 ? "standard"
20027 : "(expanded) access",
20028 list->name);
20029 else
20030 vty_out(vty,
20031 "Named extended community %s list %s\n",
20032 entry->style == EXTCOMMUNITY_LIST_STANDARD
20033 ? "standard"
20034 : "expanded",
20035 list->name);
20036 }
20037 if (entry->any)
20038 vty_out(vty, " %s\n",
20039 community_direct_str(entry->direct));
20040 else
20041 vty_out(vty, " %s %s\n",
20042 community_direct_str(entry->direct),
20043 community_list_config_str(entry));
20044 }
20045 }
20046
20047 DEFUN (show_extcommunity_list,
20048 show_bgp_extcommunity_list_cmd,
20049 "show bgp extcommunity-list",
20050 SHOW_STR
20051 BGP_STR
20052 "List extended-community list\n")
20053 {
20054 struct community_list *list;
20055 struct community_list_master *cm;
20056
20057 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
20058 if (!cm)
20059 return CMD_SUCCESS;
20060
20061 for (list = cm->num.head; list; list = list->next)
20062 extcommunity_list_show(vty, list);
20063
20064 for (list = cm->str.head; list; list = list->next)
20065 extcommunity_list_show(vty, list);
20066
20067 return CMD_SUCCESS;
20068 }
20069
20070 DEFUN (show_extcommunity_list_arg,
20071 show_bgp_extcommunity_list_arg_cmd,
20072 "show bgp extcommunity-list <(1-500)|WORD> detail",
20073 SHOW_STR
20074 BGP_STR
20075 "List extended-community list\n"
20076 "Extcommunity-list number\n"
20077 "Extcommunity-list name\n"
20078 "Detailed information on extcommunity-list\n")
20079 {
20080 int idx_comm_list = 3;
20081 struct community_list *list;
20082
20083 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
20084 EXTCOMMUNITY_LIST_MASTER);
20085 if (!list) {
20086 vty_out(vty, "%% Can't find extcommunity-list\n");
20087 return CMD_WARNING;
20088 }
20089
20090 extcommunity_list_show(vty, list);
20091
20092 return CMD_SUCCESS;
20093 }
20094
20095 /* Display community-list and extcommunity-list configuration. */
20096 static int community_list_config_write(struct vty *vty)
20097 {
20098 struct community_list *list;
20099 struct community_entry *entry;
20100 struct community_list_master *cm;
20101 int write = 0;
20102
20103 /* Community-list. */
20104 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
20105
20106 for (list = cm->num.head; list; list = list->next)
20107 for (entry = list->head; entry; entry = entry->next) {
20108 vty_out(vty,
20109 "bgp community-list %s seq %" PRId64 " %s %s\n",
20110 list->name, entry->seq,
20111 community_direct_str(entry->direct),
20112 community_list_config_str(entry));
20113 write++;
20114 }
20115 for (list = cm->str.head; list; list = list->next)
20116 for (entry = list->head; entry; entry = entry->next) {
20117 vty_out(vty,
20118 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
20119 entry->style == COMMUNITY_LIST_STANDARD
20120 ? "standard"
20121 : "expanded",
20122 list->name, entry->seq,
20123 community_direct_str(entry->direct),
20124 community_list_config_str(entry));
20125 write++;
20126 }
20127
20128 /* Extcommunity-list. */
20129 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
20130
20131 for (list = cm->num.head; list; list = list->next)
20132 for (entry = list->head; entry; entry = entry->next) {
20133 vty_out(vty,
20134 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
20135 list->name, entry->seq,
20136 community_direct_str(entry->direct),
20137 community_list_config_str(entry));
20138 write++;
20139 }
20140 for (list = cm->str.head; list; list = list->next)
20141 for (entry = list->head; entry; entry = entry->next) {
20142 vty_out(vty,
20143 "bgp extcommunity-list %s %s seq %" PRId64" %s %s\n",
20144 entry->style == EXTCOMMUNITY_LIST_STANDARD
20145 ? "standard"
20146 : "expanded",
20147 list->name, entry->seq,
20148 community_direct_str(entry->direct),
20149 community_list_config_str(entry));
20150 write++;
20151 }
20152
20153
20154 /* lcommunity-list. */
20155 cm = community_list_master_lookup(bgp_clist,
20156 LARGE_COMMUNITY_LIST_MASTER);
20157
20158 for (list = cm->num.head; list; list = list->next)
20159 for (entry = list->head; entry; entry = entry->next) {
20160 vty_out(vty,
20161 "bgp large-community-list %s seq %" PRId64" %s %s\n",
20162 list->name, entry->seq,
20163 community_direct_str(entry->direct),
20164 community_list_config_str(entry));
20165 write++;
20166 }
20167 for (list = cm->str.head; list; list = list->next)
20168 for (entry = list->head; entry; entry = entry->next) {
20169 vty_out(vty,
20170 "bgp large-community-list %s %s seq %" PRId64" %s %s\n",
20171
20172 entry->style == LARGE_COMMUNITY_LIST_STANDARD
20173 ? "standard"
20174 : "expanded",
20175 list->name, entry->seq, community_direct_str(entry->direct),
20176 community_list_config_str(entry));
20177 write++;
20178 }
20179
20180 return write;
20181 }
20182
20183 static int community_list_config_write(struct vty *vty);
20184 static struct cmd_node community_list_node = {
20185 .name = "community list",
20186 .node = COMMUNITY_LIST_NODE,
20187 .prompt = "",
20188 .config_write = community_list_config_write,
20189 };
20190
20191 static void community_list_vty(void)
20192 {
20193 install_node(&community_list_node);
20194
20195 /* Community-list. */
20196 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
20197 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
20198 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
20199 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
20200 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
20201 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
20202 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
20203 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
20204
20205 /* Extcommunity-list. */
20206 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
20207 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
20208 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
20209 install_element(CONFIG_NODE,
20210 &no_bgp_extcommunity_list_standard_all_list_cmd);
20211 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
20212 install_element(CONFIG_NODE,
20213 &no_bgp_extcommunity_list_expanded_all_list_cmd);
20214 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
20215 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
20216
20217 /* Large Community List */
20218 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
20219 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
20220 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
20221 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
20222 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
20223 install_element(CONFIG_NODE,
20224 &no_bgp_lcommunity_list_name_standard_all_cmd);
20225 install_element(CONFIG_NODE,
20226 &no_bgp_lcommunity_list_name_expanded_all_cmd);
20227 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
20228 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
20229 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
20230 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
20231 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
20232 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
20233 }