]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
Merge pull request #7868 from mjstapp/fix_fpm_conn_up
[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
131 #define GR_NO_OPER \
132 "The Graceful Restart No Operation was executed as cmd same as previous one."
133 #define GR_INVALID \
134 "The Graceful Restart command used is not valid at this moment."
135 static struct peer_group *listen_range_exists(struct bgp *bgp,
136 struct prefix *range, int exact);
137
138 /* Show BGP peer's information. */
139 enum show_type {
140 show_all,
141 show_peer,
142 show_ipv4_all,
143 show_ipv6_all,
144 show_ipv4_peer,
145 show_ipv6_peer
146 };
147
148 static struct peer_group *listen_range_exists(struct bgp *bgp,
149 struct prefix *range, int exact);
150
151 static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
152 struct bgp *bgp,
153 bool use_json,
154 json_object *json);
155
156 static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
157 enum show_type type,
158 const char *ip_str,
159 afi_t afi, bool use_json);
160
161 static int peer_and_group_lookup_nb(struct vty *vty, const char *peer_str,
162 char *base_xpath, int xpath_len,
163 char *abs_xpath);
164
165 static enum node_type bgp_node_type(afi_t afi, safi_t safi)
166 {
167 switch (afi) {
168 case AFI_IP:
169 switch (safi) {
170 case SAFI_UNICAST:
171 return BGP_IPV4_NODE;
172 case SAFI_MULTICAST:
173 return BGP_IPV4M_NODE;
174 case SAFI_LABELED_UNICAST:
175 return BGP_IPV4L_NODE;
176 case SAFI_MPLS_VPN:
177 return BGP_VPNV4_NODE;
178 case SAFI_FLOWSPEC:
179 return BGP_FLOWSPECV4_NODE;
180 default:
181 /* not expected */
182 return BGP_IPV4_NODE;
183 }
184 break;
185 case AFI_IP6:
186 switch (safi) {
187 case SAFI_UNICAST:
188 return BGP_IPV6_NODE;
189 case SAFI_MULTICAST:
190 return BGP_IPV6M_NODE;
191 case SAFI_LABELED_UNICAST:
192 return BGP_IPV6L_NODE;
193 case SAFI_MPLS_VPN:
194 return BGP_VPNV6_NODE;
195 case SAFI_FLOWSPEC:
196 return BGP_FLOWSPECV6_NODE;
197 default:
198 /* not expected */
199 return BGP_IPV4_NODE;
200 }
201 break;
202 case AFI_L2VPN:
203 return BGP_EVPN_NODE;
204 case AFI_UNSPEC:
205 case AFI_MAX:
206 // We should never be here but to clarify the switch statement..
207 return BGP_IPV4_NODE;
208 }
209
210 // Impossible to happen
211 return BGP_IPV4_NODE;
212 }
213
214 static const char *get_afi_safi_vty_str(afi_t afi, safi_t safi)
215 {
216 if (afi == AFI_IP) {
217 if (safi == SAFI_UNICAST)
218 return "IPv4 Unicast";
219 if (safi == SAFI_MULTICAST)
220 return "IPv4 Multicast";
221 if (safi == SAFI_LABELED_UNICAST)
222 return "IPv4 Labeled Unicast";
223 if (safi == SAFI_MPLS_VPN)
224 return "IPv4 VPN";
225 if (safi == SAFI_ENCAP)
226 return "IPv4 Encap";
227 if (safi == SAFI_FLOWSPEC)
228 return "IPv4 Flowspec";
229 } else if (afi == AFI_IP6) {
230 if (safi == SAFI_UNICAST)
231 return "IPv6 Unicast";
232 if (safi == SAFI_MULTICAST)
233 return "IPv6 Multicast";
234 if (safi == SAFI_LABELED_UNICAST)
235 return "IPv6 Labeled Unicast";
236 if (safi == SAFI_MPLS_VPN)
237 return "IPv6 VPN";
238 if (safi == SAFI_ENCAP)
239 return "IPv6 Encap";
240 if (safi == SAFI_FLOWSPEC)
241 return "IPv6 Flowspec";
242 } else if (afi == AFI_L2VPN) {
243 if (safi == SAFI_EVPN)
244 return "L2VPN EVPN";
245 }
246
247 return "Unknown";
248 }
249
250 /*
251 * Please note that we have intentionally camelCased
252 * the return strings here. So if you want
253 * to use this function, please ensure you
254 * are doing this within json output
255 */
256 static const char *get_afi_safi_json_str(afi_t afi, safi_t safi)
257 {
258 if (afi == AFI_IP) {
259 if (safi == SAFI_UNICAST)
260 return "ipv4Unicast";
261 if (safi == SAFI_MULTICAST)
262 return "ipv4Multicast";
263 if (safi == SAFI_LABELED_UNICAST)
264 return "ipv4LabeledUnicast";
265 if (safi == SAFI_MPLS_VPN)
266 return "ipv4Vpn";
267 if (safi == SAFI_ENCAP)
268 return "ipv4Encap";
269 if (safi == SAFI_FLOWSPEC)
270 return "ipv4Flowspec";
271 } else if (afi == AFI_IP6) {
272 if (safi == SAFI_UNICAST)
273 return "ipv6Unicast";
274 if (safi == SAFI_MULTICAST)
275 return "ipv6Multicast";
276 if (safi == SAFI_LABELED_UNICAST)
277 return "ipv6LabeledUnicast";
278 if (safi == SAFI_MPLS_VPN)
279 return "ipv6Vpn";
280 if (safi == SAFI_ENCAP)
281 return "ipv6Encap";
282 if (safi == SAFI_FLOWSPEC)
283 return "ipv6Flowspec";
284 } else if (afi == AFI_L2VPN) {
285 if (safi == SAFI_EVPN)
286 return "l2VpnEvpn";
287 }
288
289 return "Unknown";
290 }
291
292 /* return string maps to afi-safi specific container names
293 * defined in bgp yang file.
294 */
295 const char *bgp_afi_safi_get_container_str(afi_t afi, safi_t safi)
296 {
297 if (afi == AFI_IP) {
298 if (safi == SAFI_UNICAST)
299 return "ipv4-unicast";
300 if (safi == SAFI_MULTICAST)
301 return "ipv4-multicast";
302 if (safi == SAFI_LABELED_UNICAST)
303 return "ipv4-labeled-unicast";
304 if (safi == SAFI_MPLS_VPN)
305 return "l3vpn-ipv4-unicast";
306 if (safi == SAFI_FLOWSPEC)
307 return "ipv4-flowspec";
308 } else if (afi == AFI_IP6) {
309 if (safi == SAFI_UNICAST)
310 return "ipv6-unicast";
311 if (safi == SAFI_MULTICAST)
312 return "ipv6-multicast";
313 if (safi == SAFI_LABELED_UNICAST)
314 return "ipv6-labeled-unicast";
315 if (safi == SAFI_MPLS_VPN)
316 return "l3vpn-ipv6-unicast";
317 if (safi == SAFI_FLOWSPEC)
318 return "ipv6-flowspec";
319 } else if (afi == AFI_L2VPN) {
320 if (safi == SAFI_EVPN)
321 return "l2vpn-evpn";
322 }
323
324 return "Unknown";
325 }
326
327 /* Utility function to get address family from current node. */
328 afi_t bgp_node_afi(struct vty *vty)
329 {
330 afi_t afi;
331 switch (vty->node) {
332 case BGP_IPV6_NODE:
333 case BGP_IPV6M_NODE:
334 case BGP_IPV6L_NODE:
335 case BGP_VPNV6_NODE:
336 case BGP_FLOWSPECV6_NODE:
337 afi = AFI_IP6;
338 break;
339 case BGP_EVPN_NODE:
340 afi = AFI_L2VPN;
341 break;
342 default:
343 afi = AFI_IP;
344 break;
345 }
346 return afi;
347 }
348
349 /* Utility function to get subsequent address family from current
350 node. */
351 safi_t bgp_node_safi(struct vty *vty)
352 {
353 safi_t safi;
354 switch (vty->node) {
355 case BGP_VPNV4_NODE:
356 case BGP_VPNV6_NODE:
357 safi = SAFI_MPLS_VPN;
358 break;
359 case BGP_IPV4M_NODE:
360 case BGP_IPV6M_NODE:
361 safi = SAFI_MULTICAST;
362 break;
363 case BGP_EVPN_NODE:
364 safi = SAFI_EVPN;
365 break;
366 case BGP_IPV4L_NODE:
367 case BGP_IPV6L_NODE:
368 safi = SAFI_LABELED_UNICAST;
369 break;
370 case BGP_FLOWSPECV4_NODE:
371 case BGP_FLOWSPECV6_NODE:
372 safi = SAFI_FLOWSPEC;
373 break;
374 default:
375 safi = SAFI_UNICAST;
376 break;
377 }
378 return safi;
379 }
380
381 /**
382 * Converts an AFI in string form to afi_t
383 *
384 * @param afi string, one of
385 * - "ipv4"
386 * - "ipv6"
387 * - "l2vpn"
388 * @return the corresponding afi_t
389 */
390 afi_t bgp_vty_afi_from_str(const char *afi_str)
391 {
392 afi_t afi = AFI_MAX; /* unknown */
393 if (strmatch(afi_str, "ipv4"))
394 afi = AFI_IP;
395 else if (strmatch(afi_str, "ipv6"))
396 afi = AFI_IP6;
397 else if (strmatch(afi_str, "l2vpn"))
398 afi = AFI_L2VPN;
399 return afi;
400 }
401
402 int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
403 afi_t *afi)
404 {
405 int ret = 0;
406 if (argv_find(argv, argc, "ipv4", index)) {
407 ret = 1;
408 if (afi)
409 *afi = AFI_IP;
410 } else if (argv_find(argv, argc, "ipv6", index)) {
411 ret = 1;
412 if (afi)
413 *afi = AFI_IP6;
414 } else if (argv_find(argv, argc, "l2vpn", index)) {
415 ret = 1;
416 if (afi)
417 *afi = AFI_L2VPN;
418 }
419 return ret;
420 }
421
422 /* supports <unicast|multicast|vpn|labeled-unicast> */
423 safi_t bgp_vty_safi_from_str(const char *safi_str)
424 {
425 safi_t safi = SAFI_MAX; /* unknown */
426 if (strmatch(safi_str, "multicast"))
427 safi = SAFI_MULTICAST;
428 else if (strmatch(safi_str, "unicast"))
429 safi = SAFI_UNICAST;
430 else if (strmatch(safi_str, "vpn"))
431 safi = SAFI_MPLS_VPN;
432 else if (strmatch(safi_str, "evpn"))
433 safi = SAFI_EVPN;
434 else if (strmatch(safi_str, "labeled-unicast"))
435 safi = SAFI_LABELED_UNICAST;
436 else if (strmatch(safi_str, "flowspec"))
437 safi = SAFI_FLOWSPEC;
438 return safi;
439 }
440
441 int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
442 safi_t *safi)
443 {
444 int ret = 0;
445 if (argv_find(argv, argc, "unicast", index)) {
446 ret = 1;
447 if (safi)
448 *safi = SAFI_UNICAST;
449 } else if (argv_find(argv, argc, "multicast", index)) {
450 ret = 1;
451 if (safi)
452 *safi = SAFI_MULTICAST;
453 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
454 ret = 1;
455 if (safi)
456 *safi = SAFI_LABELED_UNICAST;
457 } else if (argv_find(argv, argc, "vpn", index)) {
458 ret = 1;
459 if (safi)
460 *safi = SAFI_MPLS_VPN;
461 } else if (argv_find(argv, argc, "evpn", index)) {
462 ret = 1;
463 if (safi)
464 *safi = SAFI_EVPN;
465 } else if (argv_find(argv, argc, "flowspec", index)) {
466 ret = 1;
467 if (safi)
468 *safi = SAFI_FLOWSPEC;
469 }
470 return ret;
471 }
472
473 int bgp_get_vty(struct bgp **bgp, as_t *as, const char *name,
474 enum bgp_instance_type inst_type)
475 {
476 int ret = bgp_get(bgp, as, name, inst_type);
477
478 if (ret == BGP_CREATED) {
479 bgp_timers_set(*bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
480 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
481
482 if (DFLT_BGP_IMPORT_CHECK)
483 SET_FLAG((*bgp)->flags, BGP_FLAG_IMPORT_CHECK);
484 if (DFLT_BGP_SHOW_HOSTNAME)
485 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_HOSTNAME);
486 if (DFLT_BGP_SHOW_NEXTHOP_HOSTNAME)
487 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
488 if (DFLT_BGP_LOG_NEIGHBOR_CHANGES)
489 SET_FLAG((*bgp)->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
490 if (DFLT_BGP_DETERMINISTIC_MED)
491 SET_FLAG((*bgp)->flags, BGP_FLAG_DETERMINISTIC_MED);
492 if (DFLT_BGP_EBGP_REQUIRES_POLICY)
493 SET_FLAG((*bgp)->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
494 if (DFLT_BGP_SUPPRESS_DUPLICATES)
495 SET_FLAG((*bgp)->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
496
497 ret = BGP_SUCCESS;
498 }
499 return ret;
500 }
501
502 /*
503 * bgp_vty_find_and_parse_afi_safi_bgp
504 *
505 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
506 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
507 * to appropriate values for the calling function. This is to allow the
508 * calling function to make decisions appropriate for the show command
509 * that is being parsed.
510 *
511 * The show commands are generally of the form:
512 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
513 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
514 *
515 * Since we use argv_find if the show command in particular doesn't have:
516 * [ip]
517 * [<view|vrf> VIEWVRFNAME]
518 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
519 * The command parsing should still be ok.
520 *
521 * vty -> The vty for the command so we can output some useful data in
522 * the event of a parse error in the vrf.
523 * argv -> The command tokens
524 * argc -> How many command tokens we have
525 * idx -> The current place in the command, generally should be 0 for this
526 * function
527 * afi -> The parsed afi if it was included in the show command, returned here
528 * safi -> The parsed safi if it was included in the show command, returned here
529 * bgp -> Pointer to the bgp data structure we need to fill in.
530 * use_json -> json is configured or not
531 *
532 * The function returns the correct location in the parse tree for the
533 * last token found.
534 *
535 * Returns 0 for failure to parse correctly, else the idx position of where
536 * it found the last token.
537 */
538 int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
539 struct cmd_token **argv, int argc,
540 int *idx, afi_t *afi, safi_t *safi,
541 struct bgp **bgp, bool use_json)
542 {
543 char *vrf_name = NULL;
544
545 assert(afi);
546 assert(safi);
547 assert(bgp);
548
549 if (argv_find(argv, argc, "ip", idx))
550 *afi = AFI_IP;
551
552 if (argv_find(argv, argc, "view", idx))
553 vrf_name = argv[*idx + 1]->arg;
554 else if (argv_find(argv, argc, "vrf", idx)) {
555 vrf_name = argv[*idx + 1]->arg;
556 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
557 vrf_name = NULL;
558 }
559 if (vrf_name) {
560 if (strmatch(vrf_name, "all"))
561 *bgp = NULL;
562 else {
563 *bgp = bgp_lookup_by_name(vrf_name);
564 if (!*bgp) {
565 if (use_json) {
566 json_object *json = NULL;
567 json = json_object_new_object();
568 json_object_string_add(
569 json, "warning",
570 "View/Vrf is unknown");
571 vty_out(vty, "%s\n",
572 json_object_to_json_string_ext(json,
573 JSON_C_TO_STRING_PRETTY));
574 json_object_free(json);
575 }
576 else
577 vty_out(vty, "View/Vrf %s is unknown\n",
578 vrf_name);
579 *idx = 0;
580 return 0;
581 }
582 }
583 } else {
584 *bgp = bgp_get_default();
585 if (!*bgp) {
586 if (use_json) {
587 json_object *json = NULL;
588 json = json_object_new_object();
589 json_object_string_add(
590 json, "warning",
591 "Default BGP instance not found");
592 vty_out(vty, "%s\n",
593 json_object_to_json_string_ext(json,
594 JSON_C_TO_STRING_PRETTY));
595 json_object_free(json);
596 }
597 else
598 vty_out(vty,
599 "Default BGP instance not found\n");
600 *idx = 0;
601 return 0;
602 }
603 }
604
605 if (argv_find_and_parse_afi(argv, argc, idx, afi))
606 argv_find_and_parse_safi(argv, argc, idx, safi);
607
608 *idx += 1;
609 return *idx;
610 }
611
612 bool peer_address_self_check(struct bgp *bgp, union sockunion *su)
613 {
614 struct interface *ifp = NULL;
615
616 if (su->sa.sa_family == AF_INET)
617 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
618 else if (su->sa.sa_family == AF_INET6)
619 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
620 su->sin6.sin6_scope_id,
621 bgp->vrf_id);
622
623 if (ifp)
624 return true;
625
626 return false;
627 }
628
629 /* Utility function for looking up peer or peer group. */
630 /* This is used only for configuration, so disallow if attempted on
631 * a dynamic neighbor.
632 */
633 struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
634 {
635 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
636 int ret;
637 union sockunion su;
638 struct peer *peer = NULL;
639 struct peer_group *group = NULL;
640
641 if (!bgp) {
642 return NULL;
643 }
644
645 ret = str2sockunion(peer_str, &su);
646 if (ret == 0) {
647 /* IP address, locate peer. */
648 peer = peer_lookup(bgp, &su);
649 } else {
650 /* Not IP, could match either peer configured on interface or a
651 * group. */
652 peer = peer_lookup_by_conf_if(bgp, peer_str);
653 if (!peer)
654 group = peer_group_lookup(bgp, peer_str);
655 }
656
657 if (peer) {
658 if (peer_dynamic_neighbor(peer)) {
659 vty_out(vty,
660 "%% Operation not allowed on a dynamic neighbor\n");
661 return NULL;
662 }
663
664 return peer;
665 }
666
667 if (group)
668 return group->conf;
669
670 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
671
672 return NULL;
673 }
674
675 int bgp_nb_errmsg_return(char *errmsg, size_t errmsg_len, int ret)
676 {
677 const char *str = NULL;
678
679 switch (ret) {
680 case BGP_ERR_INVALID_VALUE:
681 str = "Invalid value";
682 break;
683 case BGP_ERR_INVALID_FLAG:
684 str = "Invalid flag";
685 break;
686 case BGP_ERR_PEER_GROUP_SHUTDOWN:
687 str = "Peer-group has been shutdown. Activate the peer-group first";
688 break;
689 case BGP_ERR_PEER_FLAG_CONFLICT:
690 str = "Can't set override-capability and strict-capability-match at the same time";
691 break;
692 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
693 str = "Specify remote-as or peer-group remote AS first";
694 break;
695 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
696 str = "Cannot change the peer-group. Deconfigure first";
697 break;
698 case BGP_ERR_PEER_GROUP_MISMATCH:
699 str = "Peer is not a member of this peer-group";
700 break;
701 case BGP_ERR_PEER_FILTER_CONFLICT:
702 str = "Prefix/distribute list can not co-exist";
703 break;
704 case BGP_ERR_NOT_INTERNAL_PEER:
705 str = "Invalid command. Not an internal neighbor";
706 break;
707 case BGP_ERR_REMOVE_PRIVATE_AS:
708 str = "remove-private-AS cannot be configured for IBGP peers";
709 break;
710 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
711 str = "Local-AS allowed only for EBGP peers";
712 break;
713 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
714 str = "Cannot have local-as same as BGP AS number";
715 break;
716 case BGP_ERR_TCPSIG_FAILED:
717 str = "Error while applying TCP-Sig to session(s)";
718 break;
719 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
720 str = "ebgp-multihop and ttl-security cannot be configured together";
721 break;
722 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
723 str = "ttl-security only allowed for EBGP peers";
724 break;
725 case BGP_ERR_AS_OVERRIDE:
726 str = "as-override cannot be configured for IBGP peers";
727 break;
728 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
729 str = "Invalid limit for number of dynamic neighbors";
730 break;
731 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
732 str = "Dynamic neighbor listen range already exists";
733 break;
734 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
735 str = "Operation not allowed on a dynamic neighbor";
736 break;
737 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
738 str = "Operation not allowed on a directly connected neighbor";
739 break;
740 case BGP_ERR_PEER_SAFI_CONFLICT:
741 str = GR_INVALID;
742 break;
743 case BGP_ERR_GR_INVALID_CMD:
744 str = "The Graceful Restart command used is not valid at this moment.";
745 break;
746 case BGP_ERR_GR_OPERATION_FAILED:
747 str = "The Graceful Restart Operation failed due to an err.";
748 break;
749 case BGP_GR_NO_OPERATION:
750 str = GR_NO_OPER;
751 break;
752 case BGP_ERR_PEER_GROUP_MEMBER:
753 str = "Peer-group member cannot override remote-as of peer-group";
754 break;
755 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
756 str = "Peer-group members must be all internal or all external";
757 break;
758 }
759 if (str) {
760 snprintf(errmsg, errmsg_len, "%s", str);
761 return -1;
762 }
763
764 return 0;
765 }
766
767 int bgp_vty_return(struct vty *vty, int ret)
768 {
769 const char *str = NULL;
770
771 switch (ret) {
772 case BGP_ERR_INVALID_VALUE:
773 str = "Invalid value";
774 break;
775 case BGP_ERR_INVALID_FLAG:
776 str = "Invalid flag";
777 break;
778 case BGP_ERR_PEER_GROUP_SHUTDOWN:
779 str = "Peer-group has been shutdown. Activate the peer-group first";
780 break;
781 case BGP_ERR_PEER_FLAG_CONFLICT:
782 str = "Can't set override-capability and strict-capability-match at the same time";
783 break;
784 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
785 str = "Specify remote-as or peer-group remote AS first";
786 break;
787 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
788 str = "Cannot change the peer-group. Deconfigure first";
789 break;
790 case BGP_ERR_PEER_GROUP_MISMATCH:
791 str = "Peer is not a member of this peer-group";
792 break;
793 case BGP_ERR_PEER_FILTER_CONFLICT:
794 str = "Prefix/distribute list can not co-exist";
795 break;
796 case BGP_ERR_NOT_INTERNAL_PEER:
797 str = "Invalid command. Not an internal neighbor";
798 break;
799 case BGP_ERR_REMOVE_PRIVATE_AS:
800 str = "remove-private-AS cannot be configured for IBGP peers";
801 break;
802 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
803 str = "Local-AS allowed only for EBGP peers";
804 break;
805 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
806 str = "Cannot have local-as same as BGP AS number";
807 break;
808 case BGP_ERR_TCPSIG_FAILED:
809 str = "Error while applying TCP-Sig to session(s)";
810 break;
811 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
812 str = "ebgp-multihop and ttl-security cannot be configured together";
813 break;
814 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
815 str = "ttl-security only allowed for EBGP peers";
816 break;
817 case BGP_ERR_AS_OVERRIDE:
818 str = "as-override cannot be configured for IBGP peers";
819 break;
820 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
821 str = "Invalid limit for number of dynamic neighbors";
822 break;
823 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
824 str = "Dynamic neighbor listen range already exists";
825 break;
826 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
827 str = "Operation not allowed on a dynamic neighbor";
828 break;
829 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
830 str = "Operation not allowed on a directly connected neighbor";
831 break;
832 case BGP_ERR_PEER_SAFI_CONFLICT:
833 str = GR_INVALID;
834 break;
835 case BGP_ERR_GR_INVALID_CMD:
836 str = "The Graceful Restart command used is not valid at this moment.";
837 break;
838 case BGP_ERR_GR_OPERATION_FAILED:
839 str = "The Graceful Restart Operation failed due to an err.";
840 break;
841 case BGP_GR_NO_OPERATION:
842 str = GR_NO_OPER;
843 break;
844 }
845 if (str) {
846 vty_out(vty, "%% %s\n", str);
847 return CMD_WARNING_CONFIG_FAILED;
848 }
849 return CMD_SUCCESS;
850 }
851
852 /* BGP clear sort. */
853 enum clear_sort {
854 clear_all,
855 clear_peer,
856 clear_group,
857 clear_external,
858 clear_as
859 };
860
861 static void bgp_clear_vty_error(struct peer *peer, afi_t afi, safi_t safi,
862 int error, char *errmsg, size_t errmsg_len)
863 {
864 switch (error) {
865 case BGP_ERR_AF_UNCONFIGURED:
866 snprintf(errmsg, errmsg_len,
867 "%%BGP: Enable %s address family for the neighbor %s",
868 get_afi_safi_str(afi, safi, false), peer->host);
869 break;
870 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
871 snprintf(
872 errmsg, errmsg_len,
873 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig",
874 peer->host);
875 break;
876 default:
877 break;
878 }
879 }
880
881 static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi,
882 struct listnode **nnode, enum bgp_clear_type stype)
883 {
884 int ret = 0;
885 struct peer_af *paf;
886
887 /* if afi/.safi not specified, spin thru all of them */
888 if ((afi == AFI_UNSPEC) && (safi == SAFI_UNSPEC)) {
889 afi_t tmp_afi;
890 safi_t tmp_safi;
891
892 FOREACH_AFI_SAFI (tmp_afi, tmp_safi) {
893 paf = peer_af_find(peer, tmp_afi, tmp_safi);
894 if (paf && paf->subgroup)
895 SET_FLAG(paf->subgroup->sflags,
896 SUBGRP_STATUS_FORCE_UPDATES);
897
898 if (!peer->afc[tmp_afi][tmp_safi])
899 continue;
900
901 if (stype == BGP_CLEAR_SOFT_NONE)
902 ret = peer_clear(peer, nnode);
903 else
904 ret = peer_clear_soft(peer, tmp_afi, tmp_safi,
905 stype);
906 }
907 /* if afi specified and safi not, spin thru safis on this afi */
908 } else if (safi == SAFI_UNSPEC) {
909 safi_t tmp_safi;
910
911 for (tmp_safi = SAFI_UNICAST;
912 tmp_safi < SAFI_MAX; tmp_safi++) {
913 if (!peer->afc[afi][tmp_safi])
914 continue;
915
916 paf = peer_af_find(peer, afi, tmp_safi);
917 if (paf && paf->subgroup)
918 SET_FLAG(paf->subgroup->sflags,
919 SUBGRP_STATUS_FORCE_UPDATES);
920
921 if (stype == BGP_CLEAR_SOFT_NONE)
922 ret = peer_clear(peer, nnode);
923 else
924 ret = peer_clear_soft(peer, afi,
925 tmp_safi, stype);
926 }
927 /* both afi/safi specified, let the caller know if not defined */
928 } else {
929 if (!peer->afc[afi][safi])
930 return 1;
931
932 paf = peer_af_find(peer, afi, safi);
933 if (paf && paf->subgroup)
934 SET_FLAG(paf->subgroup->sflags,
935 SUBGRP_STATUS_FORCE_UPDATES);
936
937 if (stype == BGP_CLEAR_SOFT_NONE)
938 ret = peer_clear(peer, nnode);
939 else
940 ret = peer_clear_soft(peer, afi, safi, stype);
941 }
942
943 return ret;
944 }
945
946 /* `clear ip bgp' functions. */
947 static int bgp_clear(struct bgp *bgp, afi_t afi, safi_t safi,
948 enum clear_sort sort, enum bgp_clear_type stype,
949 const char *arg, char *errmsg, size_t errmsg_len)
950 {
951 int ret = 0;
952 bool found = false;
953 struct peer *peer;
954
955 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
956
957 /* Clear all neighbors. */
958 /*
959 * Pass along pointer to next node to peer_clear() when walking all
960 * nodes on the BGP instance as that may get freed if it is a
961 * doppelganger
962 */
963 if (sort == clear_all) {
964 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
965
966 bgp_peer_gr_flags_update(peer);
967
968 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
969 gr_router_detected = true;
970
971 ret = bgp_peer_clear(peer, afi, safi, &nnode,
972 stype);
973
974 if (ret < 0)
975 bgp_clear_vty_error(peer, afi, safi, ret,
976 errmsg, errmsg_len);
977 }
978
979 if (gr_router_detected
980 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
981 bgp_zebra_send_capabilities(bgp, false);
982 } else if (!gr_router_detected
983 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
984 bgp_zebra_send_capabilities(bgp, true);
985 }
986
987 /* This is to apply read-only mode on this clear. */
988 if (stype == BGP_CLEAR_SOFT_NONE)
989 bgp->update_delay_over = 0;
990
991 return CMD_SUCCESS;
992 }
993
994 /* Clear specified neighbor. */
995 if (sort == clear_peer) {
996 union sockunion su;
997
998 /* Make sockunion for lookup. */
999 ret = str2sockunion(arg, &su);
1000 if (ret < 0) {
1001 peer = peer_lookup_by_conf_if(bgp, arg);
1002 if (!peer) {
1003 peer = peer_lookup_by_hostname(bgp, arg);
1004 if (!peer) {
1005 snprintf(
1006 errmsg, errmsg_len,
1007 "Malformed address or name: %s",
1008 arg);
1009 return CMD_WARNING;
1010 }
1011 }
1012 } else {
1013 peer = peer_lookup(bgp, &su);
1014 if (!peer) {
1015 snprintf(errmsg, errmsg_len,
1016 "%%BGP: Unknown neighbor - \"%s\"",
1017 arg);
1018 return CMD_WARNING;
1019 }
1020 }
1021
1022 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
1023 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
1024
1025 ret = bgp_peer_clear(peer, afi, safi, NULL, stype);
1026
1027 /* if afi/safi not defined for this peer, let caller know */
1028 if (ret == 1)
1029 ret = BGP_ERR_AF_UNCONFIGURED;
1030
1031 if (ret < 0)
1032 bgp_clear_vty_error(peer, afi, safi, ret, errmsg,
1033 errmsg_len);
1034
1035 return CMD_SUCCESS;
1036 }
1037
1038 /* Clear all neighbors belonging to a specific peer-group. */
1039 if (sort == clear_group) {
1040 struct peer_group *group;
1041
1042 group = peer_group_lookup(bgp, arg);
1043 if (!group) {
1044 snprintf(errmsg, errmsg_len,
1045 "%%BGP: No such peer-group %s", arg);
1046 return CMD_WARNING;
1047 }
1048
1049 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
1050 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1051
1052 if (ret < 0)
1053 bgp_clear_vty_error(peer, afi, safi, ret,
1054 errmsg, errmsg_len);
1055 else
1056 found = true;
1057 }
1058
1059 if (!found)
1060 snprintf(
1061 errmsg, errmsg_len,
1062 "%%BGP: No %s peer belonging to peer-group %s is configured",
1063 get_afi_safi_str(afi, safi, false), arg);
1064
1065 return CMD_SUCCESS;
1066 }
1067
1068 /* Clear all external (eBGP) neighbors. */
1069 if (sort == clear_external) {
1070 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1071 if (peer->sort == BGP_PEER_IBGP)
1072 continue;
1073
1074 bgp_peer_gr_flags_update(peer);
1075
1076 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1077 gr_router_detected = true;
1078
1079 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1080
1081 if (ret < 0)
1082 bgp_clear_vty_error(peer, afi, safi, ret,
1083 errmsg, errmsg_len);
1084 else
1085 found = true;
1086 }
1087
1088 if (gr_router_detected
1089 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1090 bgp_zebra_send_capabilities(bgp, false);
1091 } else if (!gr_router_detected
1092 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1093 bgp_zebra_send_capabilities(bgp, true);
1094 }
1095
1096 if (!found)
1097 snprintf(errmsg, errmsg_len,
1098 "%%BGP: No external %s peer is configured",
1099 get_afi_safi_str(afi, safi, false));
1100
1101 return CMD_SUCCESS;
1102 }
1103
1104 /* Clear all neighbors belonging to a specific AS. */
1105 if (sort == clear_as) {
1106 as_t as = strtoul(arg, NULL, 10);
1107
1108 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1109 if (peer->as != as)
1110 continue;
1111
1112 bgp_peer_gr_flags_update(peer);
1113
1114 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1115 gr_router_detected = true;
1116
1117 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1118
1119 if (ret < 0)
1120 bgp_clear_vty_error(peer, afi, safi, ret,
1121 errmsg, errmsg_len);
1122 else
1123 found = true;
1124 }
1125
1126 if (gr_router_detected
1127 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1128 bgp_zebra_send_capabilities(bgp, false);
1129 } else if (!gr_router_detected
1130 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1131 bgp_zebra_send_capabilities(bgp, true);
1132 }
1133
1134 if (!found)
1135 snprintf(errmsg, errmsg_len,
1136 "%%BGP: No %s peer is configured with AS %s",
1137 get_afi_safi_str(afi, safi, false), arg);
1138
1139 return CMD_SUCCESS;
1140 }
1141
1142 return CMD_SUCCESS;
1143 }
1144
1145 static int bgp_clear_vty(const char *name, afi_t afi, safi_t safi,
1146 enum clear_sort sort, enum bgp_clear_type stype,
1147 const char *arg, char *errmsg, size_t errmsg_len)
1148 {
1149 struct bgp *bgp;
1150
1151 /* BGP structure lookup. */
1152 if (name) {
1153 bgp = bgp_lookup_by_name(name);
1154 if (bgp == NULL) {
1155 snprintf(errmsg, errmsg_len,
1156 "Can't find BGP instance %s", name);
1157 return CMD_WARNING;
1158 }
1159 } else {
1160 bgp = bgp_get_default();
1161 if (bgp == NULL) {
1162 snprintf(errmsg, errmsg_len,
1163 "No BGP process is configured");
1164 return CMD_WARNING;
1165 }
1166 }
1167
1168 return bgp_clear(bgp, afi, safi, sort, stype, arg, errmsg, errmsg_len);
1169 }
1170
1171 /* clear soft inbound */
1172 int bgp_clear_star_soft_in(const char *name, char *errmsg, size_t errmsg_len)
1173 {
1174 afi_t afi;
1175 safi_t safi;
1176 int ret;
1177
1178 FOREACH_AFI_SAFI (afi, safi) {
1179 ret = bgp_clear_vty(name, afi, safi, clear_all,
1180 BGP_CLEAR_SOFT_IN, NULL, errmsg,
1181 errmsg_len);
1182 if (ret != CMD_SUCCESS)
1183 return -1;
1184 }
1185
1186 return 0;
1187 }
1188
1189 /* clear soft outbound */
1190 int bgp_clear_star_soft_out(const char *name, char *errmsg, size_t errmsg_len)
1191 {
1192 afi_t afi;
1193 safi_t safi;
1194 int ret;
1195
1196 FOREACH_AFI_SAFI (afi, safi) {
1197 ret = bgp_clear_vty(name, afi, safi, clear_all,
1198 BGP_CLEAR_SOFT_OUT, NULL, errmsg,
1199 errmsg_len);
1200 if (ret != CMD_SUCCESS)
1201 return -1;
1202 }
1203
1204 return 0;
1205 }
1206
1207
1208 #ifndef VTYSH_EXTRACT_PL
1209 #include "bgpd/bgp_vty_clippy.c"
1210 #endif
1211
1212 DEFUN_HIDDEN (bgp_local_mac,
1213 bgp_local_mac_cmd,
1214 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
1215 BGP_STR
1216 "Local MAC config\n"
1217 "VxLAN Network Identifier\n"
1218 "VNI number\n"
1219 "local mac\n"
1220 "mac address\n"
1221 "mac-mobility sequence\n"
1222 "seq number\n")
1223 {
1224 int rv;
1225 vni_t vni;
1226 struct ethaddr mac;
1227 struct ipaddr ip;
1228 uint32_t seq;
1229 struct bgp *bgp;
1230
1231 vni = strtoul(argv[3]->arg, NULL, 10);
1232 if (!prefix_str2mac(argv[5]->arg, &mac)) {
1233 vty_out(vty, "%% Malformed MAC address\n");
1234 return CMD_WARNING;
1235 }
1236 memset(&ip, 0, sizeof(ip));
1237 seq = strtoul(argv[7]->arg, NULL, 10);
1238
1239 bgp = bgp_get_default();
1240 if (!bgp) {
1241 vty_out(vty, "Default BGP instance is not there\n");
1242 return CMD_WARNING;
1243 }
1244
1245 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq,
1246 zero_esi);
1247 if (rv < 0) {
1248 vty_out(vty, "Internal error\n");
1249 return CMD_WARNING;
1250 }
1251
1252 return CMD_SUCCESS;
1253 }
1254
1255 DEFUN_HIDDEN (no_bgp_local_mac,
1256 no_bgp_local_mac_cmd,
1257 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
1258 NO_STR
1259 BGP_STR
1260 "Local MAC config\n"
1261 "VxLAN Network Identifier\n"
1262 "VNI number\n"
1263 "local mac\n"
1264 "mac address\n")
1265 {
1266 int rv;
1267 vni_t vni;
1268 struct ethaddr mac;
1269 struct ipaddr ip;
1270 struct bgp *bgp;
1271
1272 vni = strtoul(argv[4]->arg, NULL, 10);
1273 if (!prefix_str2mac(argv[6]->arg, &mac)) {
1274 vty_out(vty, "%% Malformed MAC address\n");
1275 return CMD_WARNING;
1276 }
1277 memset(&ip, 0, sizeof(ip));
1278
1279 bgp = bgp_get_default();
1280 if (!bgp) {
1281 vty_out(vty, "Default BGP instance is not there\n");
1282 return CMD_WARNING;
1283 }
1284
1285 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
1286 if (rv < 0) {
1287 vty_out(vty, "Internal error\n");
1288 return CMD_WARNING;
1289 }
1290
1291 return CMD_SUCCESS;
1292 }
1293
1294 DEFUN (no_synchronization,
1295 no_synchronization_cmd,
1296 "no synchronization",
1297 NO_STR
1298 "Perform IGP synchronization\n")
1299 {
1300 return CMD_SUCCESS;
1301 }
1302
1303 DEFUN (no_auto_summary,
1304 no_auto_summary_cmd,
1305 "no auto-summary",
1306 NO_STR
1307 "Enable automatic network number summarization\n")
1308 {
1309 return CMD_SUCCESS;
1310 }
1311
1312 /* "router bgp" commands. */
1313 DEFUN_YANG_NOSH(router_bgp,
1314 router_bgp_cmd,
1315 "router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1316 ROUTER_STR BGP_STR AS_STR BGP_INSTANCE_HELP_STR)
1317 {
1318 int idx_asn = 2;
1319 int idx_view_vrf = 3;
1320 int idx_vrf = 4;
1321 int ret = CMD_SUCCESS;
1322 as_t as;
1323 struct bgp *bgp;
1324 const char *name = NULL;
1325 char as_str[12] = {'\0'};
1326 enum bgp_instance_type inst_type;
1327 char base_xpath[XPATH_MAXLEN];
1328
1329 // "router bgp" without an ASN
1330 if (argc == 2) {
1331 // Pending: Make VRF option available for ASN less config
1332 bgp = bgp_get_default();
1333
1334 if (bgp == NULL) {
1335 vty_out(vty, "%% No BGP process is configured\n");
1336 return CMD_WARNING_CONFIG_FAILED;
1337 }
1338
1339 if (listcount(bm->bgp) > 1) {
1340 vty_out(vty, "%% Please specify ASN and VRF\n");
1341 return CMD_WARNING_CONFIG_FAILED;
1342 }
1343
1344 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_GLOBAL_XPATH,
1345 "frr-bgp:bgp", "bgp", VRF_DEFAULT_NAME);
1346
1347 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
1348 snprintf(as_str, 12, "%d", bgp->as);
1349 nb_cli_enqueue_change(vty, "./global/local-as", NB_OP_MODIFY,
1350 as_str);
1351 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW) {
1352 nb_cli_enqueue_change(vty,
1353 "./global/instance-type-view",
1354 NB_OP_MODIFY, "true");
1355 }
1356
1357 nb_cli_pending_commit_check(vty);
1358 ret = nb_cli_apply_changes(vty, base_xpath);
1359 if (ret == CMD_SUCCESS) {
1360 VTY_PUSH_XPATH(BGP_NODE, base_xpath);
1361
1362 /*
1363 * For backward compatibility with old commands we still
1364 * need to use the qobj infrastructure.
1365 */
1366 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1367 }
1368 return ret;
1369 }
1370
1371 // "router bgp X"
1372 else {
1373
1374 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1375 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1376 if (argc > 3) {
1377 name = argv[idx_vrf]->arg;
1378
1379 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1380 if (strmatch(name, VRF_DEFAULT_NAME))
1381 name = NULL;
1382 else
1383 inst_type = BGP_INSTANCE_TYPE_VRF;
1384 } else if (!strcmp(argv[idx_view_vrf]->text, "view")) {
1385 inst_type = BGP_INSTANCE_TYPE_VIEW;
1386 }
1387 }
1388 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_GLOBAL_XPATH,
1389 "frr-bgp:bgp", "bgp", name ? name : VRF_DEFAULT_NAME);
1390
1391 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
1392 nb_cli_enqueue_change(vty, "./global/local-as", NB_OP_MODIFY,
1393 argv[idx_asn]->arg);
1394 if (inst_type == BGP_INSTANCE_TYPE_VIEW) {
1395 nb_cli_enqueue_change(vty,
1396 "./global/instance-type-view",
1397 NB_OP_MODIFY, "true");
1398 }
1399
1400 nb_cli_pending_commit_check(vty);
1401 ret = nb_cli_apply_changes(vty, base_xpath);
1402 if (ret == CMD_SUCCESS) {
1403 VTY_PUSH_XPATH(BGP_NODE, base_xpath);
1404
1405 /*
1406 * For backward compatibility with old commands we still
1407 * need to use the qobj infrastructure.
1408 */
1409 bgp = bgp_lookup(as, name);
1410 if (bgp)
1411 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1412 }
1413 }
1414
1415 return ret;
1416 }
1417
1418 /* "no router bgp" commands. */
1419 DEFUN_YANG(no_router_bgp,
1420 no_router_bgp_cmd,
1421 "no router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1422 NO_STR ROUTER_STR BGP_STR AS_STR BGP_INSTANCE_HELP_STR)
1423 {
1424 int idx_asn = 3;
1425 int idx_vrf = 5;
1426 as_t as = 0;
1427 struct bgp *bgp;
1428 const char *name = NULL;
1429 char base_xpath[XPATH_MAXLEN];
1430 const struct lyd_node *bgp_glb_dnode;
1431
1432 // "no router bgp" without an ASN
1433 if (argc == 3) {
1434 // Pending: Make VRF option available for ASN less config
1435 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_GLOBAL_XPATH,
1436 "frr-bgp:bgp", "bgp", VRF_DEFAULT_NAME);
1437
1438 bgp_glb_dnode = yang_dnode_get(vty->candidate_config->dnode,
1439 base_xpath);
1440 if (!bgp_glb_dnode) {
1441 vty_out(vty, "%% No BGP process is configured\n");
1442 return CMD_WARNING_CONFIG_FAILED;
1443 }
1444
1445 if (listcount(bm->bgp) > 1) {
1446 vty_out(vty, "%% Please specify ASN and VRF\n");
1447 return CMD_WARNING_CONFIG_FAILED;
1448 }
1449
1450 /* tcli mode bgp would not be set until apply stage. */
1451 bgp = nb_running_get_entry(bgp_glb_dnode, NULL, false);
1452 if (!bgp)
1453 return CMD_SUCCESS;
1454
1455 if (bgp->l3vni) {
1456 vty_out(vty, "%% Please unconfigure l3vni %u",
1457 bgp->l3vni);
1458 return CMD_WARNING_CONFIG_FAILED;
1459 }
1460 } else {
1461 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1462
1463 if (argc > 4)
1464 name = argv[idx_vrf]->arg;
1465
1466 /* Lookup bgp structure. */
1467 bgp = bgp_lookup(as, name);
1468 if (!bgp) {
1469 vty_out(vty, "%% Can't find BGP instance\n");
1470 return CMD_WARNING_CONFIG_FAILED;
1471 }
1472
1473 if (bgp->l3vni) {
1474 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1475 bgp->l3vni);
1476 return CMD_WARNING_CONFIG_FAILED;
1477 }
1478
1479 /* Cannot delete default instance if vrf instances exist */
1480 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
1481 struct listnode *node;
1482 struct bgp *tmp_bgp;
1483
1484 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, tmp_bgp)) {
1485 if (tmp_bgp->inst_type
1486 == BGP_INSTANCE_TYPE_VRF) {
1487 vty_out(vty,
1488 "%% Cannot delete default BGP instance. Dependent VRF instances exist\n");
1489 return CMD_WARNING_CONFIG_FAILED;
1490 }
1491 }
1492 }
1493 }
1494 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_GLOBAL_XPATH,
1495 "frr-bgp:bgp", "bgp",
1496 bgp->name ? bgp->name : VRF_DEFAULT_NAME);
1497
1498 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
1499
1500 return nb_cli_apply_changes(vty, base_xpath);
1501 }
1502
1503 void cli_show_router_bgp(struct vty *vty, struct lyd_node *dnode,
1504 bool show_defaults)
1505 {
1506 const struct lyd_node *vrf_dnode;
1507 const char *vrf_name;
1508 as_t as;
1509
1510 vrf_dnode = yang_dnode_get_parent(dnode, "control-plane-protocol");
1511 vrf_name = yang_dnode_get_string(vrf_dnode, "./vrf");
1512 as = yang_dnode_get_uint32(dnode, "./global/local-as");
1513
1514 vty_out(vty, "!\n");
1515 vty_out(vty, "router bgp %u", as);
1516 if (!strmatch(vrf_name, VRF_DEFAULT_NAME))
1517 vty_out(vty, " vrf %s", vrf_name);
1518 vty_out(vty, "\n");
1519 }
1520
1521 /* BGP router-id. */
1522
1523 DEFPY_YANG(bgp_router_id, bgp_router_id_cmd, "bgp router-id A.B.C.D",
1524 BGP_STR
1525 "Override configured router identifier\n"
1526 "Manually configured router identifier\n")
1527 {
1528 nb_cli_enqueue_change(vty, "./global/router-id", NB_OP_MODIFY,
1529 router_id_str);
1530
1531 return nb_cli_apply_changes(vty, NULL);
1532 }
1533
1534 DEFPY_YANG(no_bgp_router_id, no_bgp_router_id_cmd, "no bgp router-id [A.B.C.D]",
1535 NO_STR BGP_STR
1536 "Override configured router identifier\n"
1537 "Manually configured router identifier\n")
1538 {
1539 nb_cli_enqueue_change(vty, "./global/router-id", NB_OP_DESTROY,
1540 router_id_str ? router_id_str : NULL);
1541
1542 return nb_cli_apply_changes(vty, NULL);
1543 }
1544
1545 void cli_show_router_bgp_router_id(struct vty *vty, struct lyd_node *dnode,
1546 bool show_defaults)
1547 {
1548 vty_out(vty, " bgp router-id %s\n", yang_dnode_get_string(dnode, NULL));
1549 }
1550
1551 DEFPY (bgp_global_suppress_fib_pending,
1552 bgp_global_suppress_fib_pending_cmd,
1553 "[no] bgp suppress-fib-pending",
1554 NO_STR
1555 BGP_STR
1556 "Advertise only routes that are programmed in kernel to peers globally\n")
1557 {
1558 bm_wait_for_fib_set(!no);
1559
1560 return CMD_SUCCESS;
1561 }
1562
1563 DEFPY (bgp_suppress_fib_pending,
1564 bgp_suppress_fib_pending_cmd,
1565 "[no] bgp suppress-fib-pending",
1566 NO_STR
1567 BGP_STR
1568 "Advertise only routes that are programmed in kernel to peers\n")
1569 {
1570 VTY_DECLVAR_CONTEXT(bgp, bgp);
1571
1572 bgp_suppress_fib_pending_set(bgp, !no);
1573 return CMD_SUCCESS;
1574 }
1575
1576
1577 /* BGP Cluster ID. */
1578 DEFUN_YANG(bgp_cluster_id,
1579 bgp_cluster_id_cmd,
1580 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1581 BGP_STR
1582 "Configure Route-Reflector Cluster-id\n"
1583 "Route-Reflector Cluster-id in IP address format\n"
1584 "Route-Reflector Cluster-id as 32 bit quantity\n")
1585 {
1586 int idx_ipv4 = 2;
1587
1588 nb_cli_enqueue_change(
1589 vty, "./global/route-reflector/route-reflector-cluster-id",
1590 NB_OP_MODIFY, argv[idx_ipv4]->arg);
1591
1592 return nb_cli_apply_changes(vty, NULL);
1593 }
1594
1595 DEFUN_YANG(no_bgp_cluster_id,
1596 no_bgp_cluster_id_cmd,
1597 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1598 NO_STR BGP_STR
1599 "Configure Route-Reflector Cluster-id\n"
1600 "Route-Reflector Cluster-id in IP address format\n"
1601 "Route-Reflector Cluster-id as 32 bit quantity\n")
1602 {
1603 nb_cli_enqueue_change(
1604 vty, "./global/route-reflector/route-reflector-cluster-id",
1605 NB_OP_DESTROY, NULL);
1606
1607 return nb_cli_apply_changes(vty, NULL);
1608 }
1609
1610 DEFPY (bgp_norib,
1611 bgp_norib_cmd,
1612 "bgp no-rib",
1613 BGP_STR
1614 "Disable BGP route installation to RIB (Zebra)\n")
1615 {
1616 if (bgp_option_check(BGP_OPT_NO_FIB)) {
1617 vty_out(vty,
1618 "%% No-RIB option is already set, nothing to do here.\n");
1619 return CMD_SUCCESS;
1620 }
1621
1622 bgp_option_norib_set_runtime();
1623
1624 return CMD_SUCCESS;
1625 }
1626
1627 DEFPY (no_bgp_norib,
1628 no_bgp_norib_cmd,
1629 "no bgp no-rib",
1630 NO_STR
1631 BGP_STR
1632 "Disable BGP route installation to RIB (Zebra)\n")
1633 {
1634 if (!bgp_option_check(BGP_OPT_NO_FIB)) {
1635 vty_out(vty,
1636 "%% No-RIB option is not set, nothing to do here.\n");
1637 return CMD_SUCCESS;
1638 }
1639
1640 bgp_option_norib_unset_runtime();
1641
1642 return CMD_SUCCESS;
1643 }
1644
1645 DEFPY (no_bgp_send_extra_data,
1646 no_bgp_send_extra_data_cmd,
1647 "[no] bgp send-extra-data zebra",
1648 NO_STR
1649 BGP_STR
1650 "Extra data to Zebra for display/use\n"
1651 "To zebra\n")
1652 {
1653 if (no)
1654 UNSET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1655 else
1656 SET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1657
1658 return CMD_SUCCESS;
1659 }
1660
1661 DEFUN_YANG(bgp_confederation_identifier,
1662 bgp_confederation_identifier_cmd,
1663 "bgp confederation identifier (1-4294967295)",
1664 "BGP specific commands\n"
1665 "AS confederation parameters\n"
1666 "AS number\n"
1667 "Set routing domain confederation AS\n")
1668 {
1669 int idx_number = 3;
1670
1671 nb_cli_enqueue_change(vty, "./global/confederation/identifier",
1672 NB_OP_MODIFY, argv[idx_number]->arg);
1673
1674 return nb_cli_apply_changes(vty, NULL);
1675 }
1676
1677 DEFUN_YANG(no_bgp_confederation_identifier,
1678 no_bgp_confederation_identifier_cmd,
1679 "no bgp confederation identifier [(1-4294967295)]",
1680 NO_STR
1681 "BGP specific commands\n"
1682 "AS confederation parameters\n"
1683 "AS number\n"
1684 "Set routing domain confederation AS\n")
1685 {
1686 nb_cli_enqueue_change(vty, "./global/confederation/identifier",
1687 NB_OP_DESTROY, NULL);
1688
1689 return nb_cli_apply_changes(vty, NULL);
1690 }
1691
1692 void cli_show_router_bgp_confederation_identifier(struct vty *vty,
1693 struct lyd_node *dnode,
1694 bool show_defaults)
1695 {
1696 vty_out(vty, " bgp confederation identifier %u\n",
1697 yang_dnode_get_uint32(dnode, NULL));
1698 }
1699
1700 DEFUN_YANG(bgp_confederation_peers,
1701 bgp_confederation_peers_cmd,
1702 "bgp confederation peers (1-4294967295)...",
1703 "BGP specific commands\n"
1704 "AS confederation parameters\n"
1705 "Peer ASs in BGP confederation\n" AS_STR)
1706 {
1707 int idx_asn = 3;
1708 int i;
1709
1710 for (i = idx_asn; i < argc; i++)
1711 nb_cli_enqueue_change(vty, "./global/confederation/member-as",
1712 NB_OP_CREATE, argv[i]->arg);
1713
1714 return nb_cli_apply_changes(vty, NULL);
1715 }
1716
1717 DEFUN_YANG(no_bgp_confederation_peers,
1718 no_bgp_confederation_peers_cmd,
1719 "no bgp confederation peers (1-4294967295)...",
1720 NO_STR
1721 "BGP specific commands\n"
1722 "AS confederation parameters\n"
1723 "Peer ASs in BGP confederation\n" AS_STR)
1724 {
1725 int idx_asn = 4;
1726 int i;
1727
1728 for (i = idx_asn; i < argc; i++)
1729 nb_cli_enqueue_change(vty, "./global/confederation/member-as",
1730 NB_OP_DESTROY, argv[i]->arg);
1731
1732 return nb_cli_apply_changes(vty, NULL);
1733 }
1734
1735 void cli_show_router_bgp_confederation_member_as(struct vty *vty,
1736 struct lyd_node *dnode,
1737 bool show_defaults)
1738 {
1739 vty_out(vty, " bgp confederation peers %u \n",
1740 yang_dnode_get_uint32(dnode, NULL));
1741 }
1742
1743 /**
1744 * Central routine for maximum-paths configuration.
1745 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1746 * @set: 1 for setting values, 0 for removing the max-paths config.
1747 */
1748 int bgp_maxpaths_config_vty(struct bgp *bgp, afi_t afi, safi_t safi,
1749 int peer_type, uint16_t maxpaths, uint16_t options,
1750 int set, char *errmsg, size_t errmsg_len)
1751 {
1752 int ret;
1753
1754 if (set) {
1755 if (maxpaths > multipath_num) {
1756 snprintf(
1757 errmsg, errmsg_len,
1758 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1759 maxpaths, multipath_num);
1760 return CMD_WARNING_CONFIG_FAILED;
1761 }
1762 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1763 options);
1764 } else
1765 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1766
1767 if (ret < 0) {
1768 snprintf(
1769 errmsg, errmsg_len,
1770 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1771 (set == 1) ? "" : "un",
1772 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1773 maxpaths, afi, safi);
1774 return CMD_WARNING_CONFIG_FAILED;
1775 }
1776
1777 bgp_recalculate_all_bestpaths(bgp);
1778
1779 return CMD_SUCCESS;
1780 }
1781
1782 void cli_show_router_bgp_med_config(struct vty *vty, struct lyd_node *dnode,
1783 bool show_defaults)
1784 {
1785 if (yang_dnode_get_bool(dnode, "./enable-med-admin")) {
1786 uint32_t med_admin_val;
1787
1788 vty_out(vty, " bgp max-med administrative");
1789 if ((med_admin_val =
1790 yang_dnode_get_uint32(dnode, "./max-med-admin"))
1791 != BGP_MAXMED_VALUE_DEFAULT)
1792 vty_out(vty, " %u", med_admin_val);
1793 vty_out(vty, "\n");
1794 }
1795
1796 if (yang_dnode_exists(dnode, "./max-med-onstart-up-time")) {
1797 uint32_t onstartup_val;
1798
1799 vty_out(vty, " bgp max-med on-startup %u",
1800 yang_dnode_get_uint32(dnode,
1801 "./max-med-onstart-up-time"));
1802 onstartup_val = yang_dnode_get_uint32(
1803 dnode, "./max-med-onstart-up-value");
1804 if (onstartup_val != BGP_MAXMED_VALUE_DEFAULT)
1805 vty_out(vty, " %u", onstartup_val);
1806
1807 vty_out(vty, "\n");
1808 }
1809 }
1810
1811 DEFUN_YANG(bgp_maxmed_admin,
1812 bgp_maxmed_admin_cmd,
1813 "bgp max-med administrative ",
1814 BGP_STR
1815 "Advertise routes with max-med\n"
1816 "Administratively applied, for an indefinite period\n")
1817 {
1818 nb_cli_enqueue_change(vty, "./global/med-config/enable-med-admin",
1819 NB_OP_MODIFY, "true");
1820
1821 return nb_cli_apply_changes(vty, NULL);
1822 }
1823
1824 DEFUN_YANG(bgp_maxmed_admin_medv,
1825 bgp_maxmed_admin_medv_cmd,
1826 "bgp max-med administrative (0-4294967295)",
1827 BGP_STR
1828 "Advertise routes with max-med\n"
1829 "Administratively applied, for an indefinite period\n"
1830 "Max MED value to be used\n")
1831 {
1832 int idx_number = 3;
1833
1834 nb_cli_enqueue_change(vty, "./global/med-config/enable-med-admin",
1835 NB_OP_MODIFY, "true");
1836
1837 nb_cli_enqueue_change(vty, "./global/med-config/max-med-admin",
1838 NB_OP_MODIFY, argv[idx_number]->arg);
1839
1840 return nb_cli_apply_changes(vty, NULL);
1841 }
1842
1843 DEFUN_YANG(no_bgp_maxmed_admin,
1844 no_bgp_maxmed_admin_cmd,
1845 "no bgp max-med administrative [(0-4294967295)]",
1846 NO_STR 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 nb_cli_enqueue_change(vty, "./global/med-config/enable-med-admin",
1852 NB_OP_MODIFY, "false");
1853
1854 nb_cli_enqueue_change(vty, "./global/med-config/max-med-admin",
1855 NB_OP_MODIFY, NULL);
1856
1857 return nb_cli_apply_changes(vty, NULL);
1858 }
1859
1860 DEFUN_YANG (bgp_maxmed_onstartup,
1861 bgp_maxmed_onstartup_cmd,
1862 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
1863 BGP_STR
1864 "Advertise routes with max-med\n"
1865 "Effective on a startup\n"
1866 "Time (seconds) period for max-med\n"
1867 "Max MED value to be used\n")
1868 {
1869 int idx = 0;
1870
1871 argv_find(argv, argc, "(5-86400)", &idx);
1872 nb_cli_enqueue_change(vty,
1873 "./global/med-config/max-med-onstart-up-time",
1874 NB_OP_MODIFY, argv[idx]->arg);
1875
1876 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1877 nb_cli_enqueue_change(
1878 vty, "./global/med-config/max-med-onstart-up-value",
1879 NB_OP_MODIFY, argv[idx]->arg);
1880 else
1881 nb_cli_enqueue_change(
1882 vty, "./global/med-config/max-med-onstart-up-value",
1883 NB_OP_MODIFY, NULL);
1884
1885 return nb_cli_apply_changes(vty, NULL);
1886 }
1887
1888 DEFUN_YANG (no_bgp_maxmed_onstartup,
1889 no_bgp_maxmed_onstartup_cmd,
1890 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
1891 NO_STR BGP_STR
1892 "Advertise routes with max-med\n"
1893 "Effective on a startup\n"
1894 "Time (seconds) period for max-med\n"
1895 "Max MED value to be used\n")
1896 {
1897 nb_cli_enqueue_change(vty,
1898 "./global/med-config/max-med-onstart-up-time",
1899 NB_OP_DESTROY, NULL);
1900
1901 nb_cli_enqueue_change(vty,
1902 "./global/med-config/max-med-onstart-up-value",
1903 NB_OP_MODIFY, NULL);
1904
1905 return nb_cli_apply_changes(vty, NULL);
1906 }
1907
1908 static int bgp_global_update_delay_config_vty(struct vty *vty,
1909 uint16_t update_delay,
1910 uint16_t establish_wait)
1911 {
1912 struct listnode *node, *nnode;
1913 struct bgp *bgp;
1914 bool vrf_cfg = false;
1915
1916 /*
1917 * See if update-delay is set per-vrf and warn user to delete it
1918 * Note that we only need to check this if this is the first time
1919 * setting the global config.
1920 */
1921 if (bm->v_update_delay == BGP_UPDATE_DELAY_DEF) {
1922 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
1923 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1924 vty_out(vty,
1925 "%% update-delay configuration found in vrf %s\n",
1926 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT
1927 ? VRF_DEFAULT_NAME
1928 : bgp->name);
1929 vrf_cfg = true;
1930 }
1931 }
1932 }
1933
1934 if (vrf_cfg) {
1935 vty_out(vty,
1936 "%%Failed: global update-delay config not permitted\n");
1937 return CMD_WARNING;
1938 }
1939
1940 if (!establish_wait) { /* update-delay <delay> */
1941 bm->v_update_delay = update_delay;
1942 bm->v_establish_wait = bm->v_update_delay;
1943 } else {
1944 /* update-delay <delay> <establish-wait> */
1945 if (update_delay < establish_wait) {
1946 vty_out(vty,
1947 "%%Failed: update-delay less than the establish-wait!\n");
1948 return CMD_WARNING_CONFIG_FAILED;
1949 }
1950
1951 bm->v_update_delay = update_delay;
1952 bm->v_establish_wait = establish_wait;
1953 }
1954
1955 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
1956 bgp->v_update_delay = bm->v_update_delay;
1957 bgp->v_establish_wait = bm->v_establish_wait;
1958 }
1959
1960 return CMD_SUCCESS;
1961 }
1962
1963 static int bgp_global_update_delay_deconfig_vty(struct vty *vty)
1964 {
1965 struct listnode *node, *nnode;
1966 struct bgp *bgp;
1967
1968 bm->v_update_delay = BGP_UPDATE_DELAY_DEF;
1969 bm->v_establish_wait = bm->v_update_delay;
1970
1971 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
1972 bgp->v_update_delay = bm->v_update_delay;
1973 bgp->v_establish_wait = bm->v_establish_wait;
1974 }
1975
1976 return CMD_SUCCESS;
1977 }
1978
1979 static int bgp_update_delay_config_vty(struct vty *vty, uint16_t update_delay,
1980 uint16_t establish_wait)
1981 {
1982 VTY_DECLVAR_CONTEXT(bgp, bgp);
1983
1984 /* if configured globally, per-instance config is not allowed */
1985 if (bm->v_update_delay) {
1986 vty_out(vty,
1987 "%%Failed: per-vrf update-delay config not permitted with global update-delay\n");
1988 return CMD_WARNING_CONFIG_FAILED;
1989 }
1990
1991
1992 if (!establish_wait) /* update-delay <delay> */
1993 {
1994 bgp->v_update_delay = update_delay;
1995 bgp->v_establish_wait = bgp->v_update_delay;
1996 return CMD_SUCCESS;
1997 }
1998
1999 /* update-delay <delay> <establish-wait> */
2000 if (update_delay < establish_wait) {
2001 vty_out(vty,
2002 "%%Failed: update-delay less than the establish-wait!\n");
2003 return CMD_WARNING_CONFIG_FAILED;
2004 }
2005
2006 bgp->v_update_delay = update_delay;
2007 bgp->v_establish_wait = establish_wait;
2008
2009 return CMD_SUCCESS;
2010 }
2011
2012 static int bgp_update_delay_deconfig_vty(struct vty *vty)
2013 {
2014 VTY_DECLVAR_CONTEXT(bgp, bgp);
2015
2016 /* If configured globally, cannot remove from one bgp instance */
2017 if (bm->v_update_delay) {
2018 vty_out(vty,
2019 "%%Failed: bgp update-delay configured globally. Delete per-vrf not permitted\n");
2020 return CMD_WARNING_CONFIG_FAILED;
2021 }
2022 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
2023 bgp->v_establish_wait = bgp->v_update_delay;
2024
2025 return CMD_SUCCESS;
2026 }
2027
2028 void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
2029 {
2030 /* If configured globally, no need to display per-instance value */
2031 if (bgp->v_update_delay != bm->v_update_delay) {
2032 vty_out(vty, " update-delay %d", bgp->v_update_delay);
2033 if (bgp->v_update_delay != bgp->v_establish_wait)
2034 vty_out(vty, " %d", bgp->v_establish_wait);
2035 vty_out(vty, "\n");
2036 }
2037 }
2038
2039 /* Global update-delay configuration */
2040 DEFPY (bgp_global_update_delay,
2041 bgp_global_update_delay_cmd,
2042 "bgp update-delay (0-3600)$delay [(1-3600)$wait]",
2043 BGP_STR
2044 "Force initial delay for best-path and updates for all bgp instances\n"
2045 "Max delay in seconds\n"
2046 "Establish wait in seconds\n")
2047 {
2048 return bgp_global_update_delay_config_vty(vty, delay, wait);
2049 }
2050
2051 /* Global update-delay deconfiguration */
2052 DEFPY (no_bgp_global_update_delay,
2053 no_bgp_global_update_delay_cmd,
2054 "no bgp update-delay [(0-3600) [(1-3600)]]",
2055 NO_STR
2056 BGP_STR
2057 "Force initial delay for best-path and updates\n"
2058 "Max delay in seconds\n"
2059 "Establish wait in seconds\n")
2060 {
2061 return bgp_global_update_delay_deconfig_vty(vty);
2062 }
2063
2064 /* Update-delay configuration */
2065
2066 DEFPY (bgp_update_delay,
2067 bgp_update_delay_cmd,
2068 "update-delay (0-3600)$delay [(1-3600)$wait]",
2069 "Force initial delay for best-path and updates\n"
2070 "Max delay in seconds\n"
2071 "Establish wait in seconds\n")
2072 {
2073 return bgp_update_delay_config_vty(vty, delay, wait);
2074 }
2075
2076 /* Update-delay deconfiguration */
2077 DEFPY (no_bgp_update_delay,
2078 no_bgp_update_delay_cmd,
2079 "no update-delay [(0-3600) [(1-3600)]]",
2080 NO_STR
2081 "Force initial delay for best-path and updates\n"
2082 "Max delay in seconds\n"
2083 "Establish wait in seconds\n")
2084 {
2085 return bgp_update_delay_deconfig_vty(vty);
2086 }
2087
2088
2089 int bgp_wpkt_quanta_config_vty(struct bgp *bgp, uint32_t quanta, bool set)
2090 {
2091 quanta = set ? quanta : BGP_WRITE_PACKET_MAX;
2092 atomic_store_explicit(&bgp->wpkt_quanta, quanta, memory_order_relaxed);
2093
2094 return CMD_SUCCESS;
2095 }
2096
2097 int bgp_rpkt_quanta_config_vty(struct bgp *bgp, uint32_t quanta, bool set)
2098 {
2099 quanta = set ? quanta : BGP_READ_PACKET_MAX;
2100 atomic_store_explicit(&bgp->rpkt_quanta, quanta, memory_order_relaxed);
2101
2102 return CMD_SUCCESS;
2103 }
2104
2105 void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
2106 {
2107 uint32_t quanta =
2108 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
2109 if (quanta != BGP_WRITE_PACKET_MAX)
2110 vty_out(vty, " write-quanta %d\n", quanta);
2111 }
2112
2113 void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
2114 {
2115 uint32_t quanta =
2116 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
2117 if (quanta != BGP_READ_PACKET_MAX)
2118 vty_out(vty, " read-quanta %d\n", quanta);
2119 }
2120
2121 /* Packet quanta configuration
2122 *
2123 * XXX: The value set here controls the size of a stack buffer in the IO
2124 * thread. When changing these limits be careful to prevent stack overflow.
2125 *
2126 * Furthermore, the maximums used here should correspond to
2127 * BGP_WRITE_PACKET_MAX and BGP_READ_PACKET_MAX.
2128 */
2129 DEFPY_YANG (bgp_wpkt_quanta,
2130 bgp_wpkt_quanta_cmd,
2131 "[no] write-quanta (1-64)$quanta",
2132 NO_STR
2133 "How many packets to write to peer socket per run\n"
2134 "Number of packets\n")
2135 {
2136 if (!no)
2137 nb_cli_enqueue_change(
2138 vty,
2139 "./global/global-neighbor-config/packet-quanta-config/wpkt-quanta",
2140 NB_OP_MODIFY, quanta_str);
2141 else
2142 nb_cli_enqueue_change(
2143 vty,
2144 "./global/global-neighbor-config/packet-quanta-config/wpkt-quanta",
2145 NB_OP_MODIFY, NULL);
2146
2147 return nb_cli_apply_changes(vty, NULL);
2148 }
2149
2150 DEFPY_YANG (bgp_rpkt_quanta,
2151 bgp_rpkt_quanta_cmd,
2152 "[no] read-quanta (1-10)$quanta",
2153 NO_STR
2154 "How many packets to read from peer socket per I/O cycle\n"
2155 "Number of packets\n")
2156 {
2157 if (!no)
2158 nb_cli_enqueue_change(
2159 vty,
2160 "./global/global-neighbor-config/packet-quanta-config/rpkt-quanta",
2161 NB_OP_MODIFY, quanta_str);
2162 else
2163 nb_cli_enqueue_change(
2164 vty,
2165 "./global/global-neighbor-config/packet-quanta-config/rpkt-quanta",
2166 NB_OP_MODIFY, NULL);
2167
2168 return nb_cli_apply_changes(vty, NULL);
2169 }
2170
2171 void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
2172 {
2173 if (!bgp->heuristic_coalesce)
2174 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
2175 }
2176
2177 void cli_show_router_global_update_group_config_coalesce_time(
2178 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
2179 {
2180 vty_out(vty, " coalesce-time %u\n", yang_dnode_get_uint32(dnode, NULL));
2181 }
2182
2183
2184 DEFUN_YANG (bgp_coalesce_time,
2185 bgp_coalesce_time_cmd,
2186 "coalesce-time (0-4294967295)",
2187 "Subgroup coalesce timer\n"
2188 "Subgroup coalesce timer value (in ms)\n")
2189 {
2190 int idx = 0;
2191
2192 argv_find(argv, argc, "(0-4294967295)", &idx);
2193 nb_cli_enqueue_change(
2194 vty, "./global/global-update-group-config/coalesce-time",
2195 NB_OP_MODIFY, argv[idx]->arg);
2196
2197 return nb_cli_apply_changes(vty, NULL);
2198 }
2199
2200 DEFUN_YANG(no_bgp_coalesce_time,
2201 no_bgp_coalesce_time_cmd,
2202 "no coalesce-time (0-4294967295)",
2203 NO_STR
2204 "Subgroup coalesce timer\n"
2205 "Subgroup coalesce timer value (in ms)\n")
2206 {
2207 nb_cli_enqueue_change(
2208 vty, "./global/global-update-group-config/coalesce-time",
2209 NB_OP_MODIFY, NULL);
2210
2211 return nb_cli_apply_changes(vty, NULL);
2212 }
2213
2214 /* Maximum-paths configuration */
2215 DEFUN_YANG (bgp_maxpaths,
2216 bgp_maxpaths_cmd,
2217 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2218 "Forward packets over multiple paths\n"
2219 "Number of paths\n")
2220 {
2221 int idx_number = 1;
2222 char base_xpath[XPATH_MAXLEN];
2223 afi_t afi;
2224 safi_t safi;
2225
2226 afi = bgp_node_afi(vty);
2227 safi = bgp_node_safi(vty);
2228
2229 snprintf(
2230 base_xpath, sizeof(base_xpath),
2231 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ebgp/maximum-paths",
2232 yang_afi_safi_value2identity(afi, safi),
2233 bgp_afi_safi_get_container_str(afi, safi));
2234
2235 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY,
2236 argv[idx_number]->arg);
2237
2238 return nb_cli_apply_changes(vty, NULL);
2239 }
2240
2241 void cli_show_bgp_global_afi_safi_unicast_use_multiple_paths_ebgp_maximum_paths(
2242 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
2243 {
2244 vty_out(vty, " maximum-paths %d\n",
2245 yang_dnode_get_uint16(dnode, NULL));
2246 }
2247
2248 ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
2249 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2250 "Forward packets over multiple paths\n"
2251 "Number of paths\n")
2252
2253 DEFUN_YANG (bgp_maxpaths_ibgp,
2254 bgp_maxpaths_ibgp_cmd,
2255 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2256 "Forward packets over multiple paths\n"
2257 "iBGP-multipath\n"
2258 "Number of paths\n")
2259 {
2260 int idx_number = 2;
2261 char base_xpath[XPATH_MAXLEN];
2262 afi_t afi;
2263 safi_t safi;
2264
2265 afi = bgp_node_afi(vty);
2266 safi = bgp_node_safi(vty);
2267
2268 snprintf(
2269 base_xpath, sizeof(base_xpath),
2270 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/maximum-paths",
2271 yang_afi_safi_value2identity(afi, safi),
2272 bgp_afi_safi_get_container_str(afi, safi));
2273
2274 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY,
2275 argv[idx_number]->arg);
2276
2277 return nb_cli_apply_changes(vty, NULL);
2278 }
2279
2280 ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
2281 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2282 "Forward packets over multiple paths\n"
2283 "iBGP-multipath\n"
2284 "Number of paths\n")
2285
2286 DEFUN_YANG (bgp_maxpaths_ibgp_cluster,
2287 bgp_maxpaths_ibgp_cluster_cmd,
2288 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
2289 "Forward packets over multiple paths\n"
2290 "iBGP-multipath\n"
2291 "Number of paths\n"
2292 "Match the cluster length\n")
2293 {
2294 int idx_number = 2;
2295 char base_xpath[XPATH_MAXLEN];
2296 afi_t afi;
2297 safi_t safi;
2298
2299 afi = bgp_node_afi(vty);
2300 safi = bgp_node_safi(vty);
2301
2302 snprintf(
2303 base_xpath, sizeof(base_xpath),
2304 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/maximum-paths",
2305 yang_afi_safi_value2identity(afi, safi),
2306 bgp_afi_safi_get_container_str(afi, safi));
2307
2308 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY,
2309 argv[idx_number]->arg);
2310
2311 snprintf(
2312 base_xpath, sizeof(base_xpath),
2313 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/cluster-length-list",
2314 yang_afi_safi_value2identity(afi, safi),
2315 bgp_afi_safi_get_container_str(afi, safi));
2316
2317 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, "true");
2318
2319 return nb_cli_apply_changes(vty, NULL);
2320 }
2321
2322 void cli_show_bgp_global_afi_safi_ip_unicast_use_multiple_paths_ibgp_maximum_paths(
2323 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
2324 {
2325 vty_out(vty, " maximum-paths ibgp %d",
2326 yang_dnode_get_uint16(dnode, "./maximum-paths"));
2327 if (yang_dnode_get_bool(dnode, "./cluster-length-list"))
2328 vty_out(vty, " equal-cluster-length");
2329 vty_out(vty, "\n");
2330 }
2331
2332 ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
2333 "maximum-paths ibgp " CMD_RANGE_STR(
2334 1, MULTIPATH_NUM) " equal-cluster-length",
2335 "Forward packets over multiple paths\n"
2336 "iBGP-multipath\n"
2337 "Number of paths\n"
2338 "Match the cluster length\n")
2339
2340 DEFUN_YANG (no_bgp_maxpaths,
2341 no_bgp_maxpaths_cmd,
2342 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
2343 NO_STR
2344 "Forward packets over multiple paths\n"
2345 "Number of paths\n")
2346 {
2347 char base_xpath[XPATH_MAXLEN];
2348 afi_t afi;
2349 safi_t safi;
2350
2351 afi = bgp_node_afi(vty);
2352 safi = bgp_node_safi(vty);
2353
2354 snprintf(
2355 base_xpath, sizeof(base_xpath),
2356 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ebgp/maximum-paths",
2357 yang_afi_safi_value2identity(afi, safi),
2358 bgp_afi_safi_get_container_str(afi, safi));
2359
2360 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, NULL);
2361
2362 return nb_cli_apply_changes(vty, NULL);
2363 }
2364
2365 ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
2366 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
2367 "Forward packets over multiple paths\n"
2368 "Number of paths\n")
2369
2370 DEFUN_YANG (no_bgp_maxpaths_ibgp,
2371 no_bgp_maxpaths_ibgp_cmd,
2372 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
2373 NO_STR
2374 "Forward packets over multiple paths\n"
2375 "iBGP-multipath\n"
2376 "Number of paths\n"
2377 "Match the cluster length\n")
2378 {
2379 char base_xpath[XPATH_MAXLEN];
2380 afi_t afi;
2381 safi_t safi;
2382
2383 afi = bgp_node_afi(vty);
2384 safi = bgp_node_safi(vty);
2385
2386 snprintf(
2387 base_xpath, sizeof(base_xpath),
2388 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/maximum-paths",
2389 yang_afi_safi_value2identity(afi, safi),
2390 bgp_afi_safi_get_container_str(afi, safi));
2391
2392 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, NULL);
2393
2394 snprintf(
2395 base_xpath, sizeof(base_xpath),
2396 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/cluster-length-list",
2397 yang_afi_safi_value2identity(afi, safi),
2398 bgp_afi_safi_get_container_str(afi, safi));
2399
2400 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, "false");
2401
2402 return nb_cli_apply_changes(vty, NULL);
2403 }
2404
2405 ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
2406 "no maximum-paths ibgp [" CMD_RANGE_STR(
2407 1, MULTIPATH_NUM) " [equal-cluster-length]]",
2408 NO_STR
2409 "Forward packets over multiple paths\n"
2410 "iBGP-multipath\n"
2411 "Number of paths\n"
2412 "Match the cluster length\n")
2413
2414 static void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp,
2415 afi_t afi, safi_t safi)
2416 {
2417 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != multipath_num) {
2418 vty_out(vty, " maximum-paths %d\n",
2419 bgp->maxpaths[afi][safi].maxpaths_ebgp);
2420 }
2421
2422 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != multipath_num) {
2423 vty_out(vty, " maximum-paths ibgp %d",
2424 bgp->maxpaths[afi][safi].maxpaths_ibgp);
2425 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
2426 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
2427 vty_out(vty, " equal-cluster-length");
2428 vty_out(vty, "\n");
2429 }
2430 }
2431
2432 /* BGP timers. */
2433
2434 DEFUN_YANG (bgp_timers,
2435 bgp_timers_cmd,
2436 "timers bgp (0-65535) (0-65535)",
2437 "Adjust routing timers\n"
2438 "BGP timers\n"
2439 "Keepalive interval\n"
2440 "Holdtime\n")
2441 {
2442 int idx_number = 2;
2443 int idx_number_2 = 3;
2444
2445 nb_cli_enqueue_change(vty, "./global/global-config-timers/keepalive",
2446 NB_OP_MODIFY, argv[idx_number]->arg);
2447 nb_cli_enqueue_change(vty, "./global/global-config-timers/hold-time",
2448 NB_OP_MODIFY, argv[idx_number_2]->arg);
2449
2450 return nb_cli_apply_changes(vty, NULL);
2451 }
2452
2453 DEFUN_YANG (no_bgp_timers,
2454 no_bgp_timers_cmd,
2455 "no timers bgp [(0-65535) (0-65535)]",
2456 NO_STR
2457 "Adjust routing timers\n"
2458 "BGP timers\n"
2459 "Keepalive interval\n"
2460 "Holdtime\n")
2461 {
2462 nb_cli_enqueue_change(vty, "./global/global-config-timers/keepalive",
2463 NB_OP_DESTROY, NULL);
2464 nb_cli_enqueue_change(vty, "./global/global-config-timers/hold-time",
2465 NB_OP_DESTROY, NULL);
2466
2467 return nb_cli_apply_changes(vty, NULL);
2468 }
2469
2470 void cli_show_router_bgp_route_reflector(struct vty *vty,
2471 struct lyd_node *dnode,
2472 bool show_defaults)
2473 {
2474 if (yang_dnode_get_bool(dnode, "./no-client-reflect"))
2475 vty_out(vty, " no bgp client-to-client reflection\n");
2476
2477 if (yang_dnode_get_bool(dnode, "./allow-outbound-policy"))
2478 vty_out(vty, " bgp route-reflector allow-outbound-policy\n");
2479
2480 if (yang_dnode_exists(dnode, "./route-reflector-cluster-id"))
2481 vty_out(vty, " bgp cluster-id %s\n",
2482 yang_dnode_get_string(dnode,
2483 "./route-reflector-cluster-id"));
2484 }
2485
2486 DEFUN_YANG(bgp_client_to_client_reflection,
2487 bgp_client_to_client_reflection_cmd,
2488 "bgp client-to-client reflection",
2489 "BGP specific commands\n"
2490 "Configure client to client route reflection\n"
2491 "reflection of routes allowed\n")
2492 {
2493 nb_cli_enqueue_change(vty, "./global/route-reflector/no-client-reflect",
2494 NB_OP_MODIFY, "false");
2495
2496 return nb_cli_apply_changes(vty, NULL);
2497 }
2498
2499 DEFUN_YANG(no_bgp_client_to_client_reflection,
2500 no_bgp_client_to_client_reflection_cmd,
2501 "no bgp client-to-client reflection",
2502 NO_STR
2503 "BGP specific commands\n"
2504 "Configure client to client route reflection\n"
2505 "reflection of routes allowed\n")
2506 {
2507 nb_cli_enqueue_change(vty, "./global/route-reflector/no-client-reflect",
2508 NB_OP_MODIFY, "true");
2509
2510 return nb_cli_apply_changes(vty, NULL);
2511 }
2512
2513 void cli_show_router_bgp_route_selection(struct vty *vty,
2514 struct lyd_node *dnode,
2515 bool show_defaults)
2516 {
2517
2518 if (yang_dnode_get_bool(dnode, "./always-compare-med"))
2519 vty_out(vty, " bgp always-compare-med\n");
2520
2521 if (yang_dnode_get_bool(dnode, "./ignore-as-path-length"))
2522 vty_out(vty, " bgp bestpath as-path ignore\n");
2523
2524 if (yang_dnode_get_bool(dnode, "./aspath-confed"))
2525 vty_out(vty, " bgp bestpath as-path confed\n");
2526
2527 if (yang_dnode_get_bool(dnode, "./external-compare-router-id"))
2528 vty_out(vty, " bgp bestpath compare-routerid\n");
2529
2530 if (yang_dnode_get_bool(dnode, "./allow-multiple-as")) {
2531 if (yang_dnode_get_bool(dnode, "./multi-path-as-set"))
2532 vty_out(vty,
2533 " bgp bestpath as-path multipath-relax as-set\n");
2534 else
2535 vty_out(vty, " bgp bestpath as-path multipath-relax\n");
2536 }
2537
2538 if (yang_dnode_get_bool(dnode, "./deterministic-med"))
2539 vty_out(vty, " bgp deterministic-med\n");
2540
2541 if (yang_dnode_get_bool(dnode, "./confed-med")
2542 || yang_dnode_get_bool(dnode, "./missing-as-worst-med")) {
2543 vty_out(vty, " bgp bestpath med");
2544 if (yang_dnode_get_bool(dnode, "./confed-med"))
2545 vty_out(vty, " confed");
2546 if (yang_dnode_get_bool(dnode, "./missing-as-worst-med"))
2547 vty_out(vty, " missing-as-worst");
2548 vty_out(vty, "\n");
2549 }
2550 }
2551
2552 /* "bgp always-compare-med" configuration. */
2553 DEFUN_YANG(bgp_always_compare_med,
2554 bgp_always_compare_med_cmd,
2555 "bgp always-compare-med",
2556 "BGP specific commands\n"
2557 "Allow comparing MED from different neighbors\n")
2558 {
2559 nb_cli_enqueue_change(
2560 vty, "./global/route-selection-options/always-compare-med",
2561 NB_OP_MODIFY, "true");
2562
2563 return nb_cli_apply_changes(vty, NULL);
2564 }
2565
2566 DEFUN_YANG(no_bgp_always_compare_med,
2567 no_bgp_always_compare_med_cmd,
2568 "no bgp always-compare-med",
2569 NO_STR
2570 "BGP specific commands\n"
2571 "Allow comparing MED from different neighbors\n")
2572 {
2573 nb_cli_enqueue_change(
2574 vty, "./global/route-selection-options/always-compare-med",
2575 NB_OP_MODIFY, "false");
2576
2577 return nb_cli_apply_changes(vty, NULL);
2578 }
2579
2580 DEFUN_YANG(bgp_suppress_duplicates,
2581 bgp_suppress_duplicates_cmd,
2582 "bgp suppress-duplicates",
2583 "BGP specific commands\n"
2584 "Suppress duplicate updates if the route actually not changed\n")
2585 {
2586 nb_cli_enqueue_change(vty, "./global/suppress-duplicates",
2587 NB_OP_MODIFY, "true");
2588 return nb_cli_apply_changes(vty, NULL);
2589 }
2590
2591 DEFUN_YANG(no_bgp_suppress_duplicates,
2592 no_bgp_suppress_duplicates_cmd,
2593 "no bgp suppress-duplicates",
2594 NO_STR
2595 "BGP specific commands\n"
2596 "Suppress duplicate updates if the route actually not changed\n")
2597 {
2598 nb_cli_enqueue_change(vty, "./global/suppress-duplicates",
2599 NB_OP_MODIFY, "false");
2600 return nb_cli_apply_changes(vty, NULL);
2601 }
2602
2603 void cli_show_router_bgp_suppress_duplicates(struct vty *vty,
2604 struct lyd_node *dnode,
2605 bool show_defaults)
2606 {
2607 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_SUPPRESS_DUPLICATES)
2608 vty_out(vty, " bgp suppress-duplicates\n");
2609 }
2610
2611 DEFUN_YANG(bgp_ebgp_requires_policy,
2612 bgp_ebgp_requires_policy_cmd,
2613 "bgp ebgp-requires-policy",
2614 "BGP specific commands\n"
2615 "Require in and out policy for eBGP peers (RFC8212)\n")
2616 {
2617 nb_cli_enqueue_change(vty, "./global/ebgp-requires-policy",
2618 NB_OP_MODIFY, "true");
2619 return nb_cli_apply_changes(vty, NULL);
2620 }
2621
2622 DEFUN_YANG(no_bgp_ebgp_requires_policy,
2623 no_bgp_ebgp_requires_policy_cmd,
2624 "no bgp ebgp-requires-policy",
2625 NO_STR
2626 "BGP specific commands\n"
2627 "Require in and out policy for eBGP peers (RFC8212)\n")
2628 {
2629 nb_cli_enqueue_change(vty, "./global/ebgp-requires-policy",
2630 NB_OP_MODIFY, "false");
2631 return nb_cli_apply_changes(vty, NULL);
2632 }
2633
2634 void cli_show_router_bgp_ebgp_requires_policy(struct vty *vty,
2635 struct lyd_node *dnode,
2636 bool show_defaults)
2637 {
2638 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_EBGP_REQUIRES_POLICY)
2639 vty_out(vty, " bgp ebgp-requires-policy\n");
2640 }
2641
2642 DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd,
2643 "bgp reject-as-sets",
2644 "BGP specific commands\n"
2645 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2646 {
2647 VTY_DECLVAR_CONTEXT(bgp, bgp);
2648 struct listnode *node, *nnode;
2649 struct peer *peer;
2650
2651 bgp->reject_as_sets = true;
2652
2653 /* Reset existing BGP sessions to reject routes
2654 * with aspath containing AS_SET or AS_CONFED_SET.
2655 */
2656 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2657 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2658 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2659 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2660 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2661 }
2662 }
2663
2664 return CMD_SUCCESS;
2665 }
2666
2667 DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd,
2668 "no bgp reject-as-sets",
2669 NO_STR
2670 "BGP specific commands\n"
2671 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2672 {
2673 VTY_DECLVAR_CONTEXT(bgp, bgp);
2674 struct listnode *node, *nnode;
2675 struct peer *peer;
2676
2677 bgp->reject_as_sets = false;
2678
2679 /* Reset existing BGP sessions to reject routes
2680 * with aspath containing AS_SET or AS_CONFED_SET.
2681 */
2682 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2683 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2684 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2685 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2686 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2687 }
2688 }
2689
2690 return CMD_SUCCESS;
2691 }
2692
2693 /* "bgp deterministic-med" configuration. */
2694 DEFUN_YANG (bgp_deterministic_med,
2695 bgp_deterministic_med_cmd,
2696 "bgp deterministic-med",
2697 "BGP specific commands\n"
2698 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2699 {
2700 nb_cli_enqueue_change(
2701 vty, "./global/route-selection-options/deterministic-med",
2702 NB_OP_MODIFY, "true");
2703
2704 return nb_cli_apply_changes(vty, NULL);
2705 }
2706
2707 DEFUN_YANG (no_bgp_deterministic_med,
2708 no_bgp_deterministic_med_cmd,
2709 "no bgp deterministic-med",
2710 NO_STR
2711 "BGP specific commands\n"
2712 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2713 {
2714 nb_cli_enqueue_change(
2715 vty, "./global/route-selection-options/deterministic-med",
2716 NB_OP_MODIFY, "false");
2717
2718 return nb_cli_apply_changes(vty, NULL);
2719 }
2720
2721 /* "bgp graceful-restart mode" configuration. */
2722 DEFUN (bgp_graceful_restart,
2723 bgp_graceful_restart_cmd,
2724 "bgp graceful-restart",
2725 "BGP specific commands\n"
2726 GR_CMD
2727 )
2728 {
2729 int ret = BGP_GR_FAILURE;
2730
2731 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2732 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : START ");
2733
2734 VTY_DECLVAR_CONTEXT(bgp, bgp);
2735
2736 ret = bgp_gr_update_all(bgp, GLOBAL_GR_CMD);
2737
2738 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2739 ret);
2740
2741 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2742 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : END ");
2743 vty_out(vty,
2744 "Graceful restart configuration changed, reset all peers to take effect\n");
2745 return bgp_vty_return(vty, ret);
2746 }
2747
2748 DEFUN (no_bgp_graceful_restart,
2749 no_bgp_graceful_restart_cmd,
2750 "no bgp graceful-restart",
2751 NO_STR
2752 "BGP specific commands\n"
2753 NO_GR_CMD
2754 )
2755 {
2756 VTY_DECLVAR_CONTEXT(bgp, bgp);
2757
2758 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2759 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : START ");
2760
2761 int ret = BGP_GR_FAILURE;
2762
2763 ret = bgp_gr_update_all(bgp, NO_GLOBAL_GR_CMD);
2764
2765 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2766 ret);
2767
2768 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2769 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : END ");
2770 vty_out(vty,
2771 "Graceful restart configuration changed, reset all peers to take effect\n");
2772
2773 return bgp_vty_return(vty, ret);
2774 }
2775
2776 DEFUN (bgp_graceful_restart_stalepath_time,
2777 bgp_graceful_restart_stalepath_time_cmd,
2778 "bgp graceful-restart stalepath-time (1-4095)",
2779 "BGP specific commands\n"
2780 "Graceful restart capability parameters\n"
2781 "Set the max time to hold onto restarting peer's stale paths\n"
2782 "Delay value (seconds)\n")
2783 {
2784 VTY_DECLVAR_CONTEXT(bgp, bgp);
2785 int idx_number = 3;
2786 uint32_t stalepath;
2787
2788 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2789 bgp->stalepath_time = stalepath;
2790 return CMD_SUCCESS;
2791 }
2792
2793 DEFUN (bgp_graceful_restart_restart_time,
2794 bgp_graceful_restart_restart_time_cmd,
2795 "bgp graceful-restart restart-time (1-4095)",
2796 "BGP specific commands\n"
2797 "Graceful restart capability parameters\n"
2798 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2799 "Delay value (seconds)\n")
2800 {
2801 VTY_DECLVAR_CONTEXT(bgp, bgp);
2802 int idx_number = 3;
2803 uint32_t restart;
2804
2805 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2806 bgp->restart_time = restart;
2807 return CMD_SUCCESS;
2808 }
2809
2810 DEFUN (bgp_graceful_restart_select_defer_time,
2811 bgp_graceful_restart_select_defer_time_cmd,
2812 "bgp graceful-restart select-defer-time (0-3600)",
2813 "BGP specific commands\n"
2814 "Graceful restart capability parameters\n"
2815 "Set the time to defer the BGP route selection after restart\n"
2816 "Delay value (seconds, 0 - disable)\n")
2817 {
2818 VTY_DECLVAR_CONTEXT(bgp, bgp);
2819 int idx_number = 3;
2820 uint32_t defer_time;
2821
2822 defer_time = strtoul(argv[idx_number]->arg, NULL, 10);
2823 bgp->select_defer_time = defer_time;
2824 if (defer_time == 0)
2825 SET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2826 else
2827 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2828
2829 return CMD_SUCCESS;
2830 }
2831
2832 DEFUN (no_bgp_graceful_restart_stalepath_time,
2833 no_bgp_graceful_restart_stalepath_time_cmd,
2834 "no bgp graceful-restart stalepath-time [(1-4095)]",
2835 NO_STR
2836 "BGP specific commands\n"
2837 "Graceful restart capability parameters\n"
2838 "Set the max time to hold onto restarting peer's stale paths\n"
2839 "Delay value (seconds)\n")
2840 {
2841 VTY_DECLVAR_CONTEXT(bgp, bgp);
2842
2843 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2844 return CMD_SUCCESS;
2845 }
2846
2847 DEFUN (no_bgp_graceful_restart_restart_time,
2848 no_bgp_graceful_restart_restart_time_cmd,
2849 "no bgp graceful-restart restart-time [(1-4095)]",
2850 NO_STR
2851 "BGP specific commands\n"
2852 "Graceful restart capability parameters\n"
2853 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2854 "Delay value (seconds)\n")
2855 {
2856 VTY_DECLVAR_CONTEXT(bgp, bgp);
2857
2858 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2859 return CMD_SUCCESS;
2860 }
2861
2862 DEFUN (no_bgp_graceful_restart_select_defer_time,
2863 no_bgp_graceful_restart_select_defer_time_cmd,
2864 "no bgp graceful-restart select-defer-time [(0-3600)]",
2865 NO_STR
2866 "BGP specific commands\n"
2867 "Graceful restart capability parameters\n"
2868 "Set the time to defer the BGP route selection after restart\n"
2869 "Delay value (seconds)\n")
2870 {
2871 VTY_DECLVAR_CONTEXT(bgp, bgp);
2872
2873 bgp->select_defer_time = BGP_DEFAULT_SELECT_DEFERRAL_TIME;
2874 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2875
2876 return CMD_SUCCESS;
2877 }
2878
2879 DEFUN (bgp_graceful_restart_preserve_fw,
2880 bgp_graceful_restart_preserve_fw_cmd,
2881 "bgp graceful-restart preserve-fw-state",
2882 "BGP specific commands\n"
2883 "Graceful restart capability parameters\n"
2884 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
2885 {
2886 VTY_DECLVAR_CONTEXT(bgp, bgp);
2887 SET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
2888 return CMD_SUCCESS;
2889 }
2890
2891 DEFUN (no_bgp_graceful_restart_preserve_fw,
2892 no_bgp_graceful_restart_preserve_fw_cmd,
2893 "no bgp graceful-restart preserve-fw-state",
2894 NO_STR
2895 "BGP specific commands\n"
2896 "Graceful restart capability parameters\n"
2897 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
2898 {
2899 VTY_DECLVAR_CONTEXT(bgp, bgp);
2900 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
2901 return CMD_SUCCESS;
2902 }
2903
2904 DEFUN (bgp_graceful_restart_disable,
2905 bgp_graceful_restart_disable_cmd,
2906 "bgp graceful-restart-disable",
2907 "BGP specific commands\n"
2908 GR_DISABLE)
2909 {
2910 int ret = BGP_GR_FAILURE;
2911
2912 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2913 zlog_debug(
2914 "[BGP_GR] bgp_graceful_restart_disable_cmd : START ");
2915
2916 VTY_DECLVAR_CONTEXT(bgp, bgp);
2917
2918 ret = bgp_gr_update_all(bgp, GLOBAL_DISABLE_CMD);
2919
2920 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
2921 bgp->peer, ret);
2922
2923 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2924 zlog_debug(
2925 "[BGP_GR] bgp_graceful_restart_disable_cmd : END ");
2926 vty_out(vty,
2927 "Graceful restart configuration changed, reset all peers to take effect\n");
2928
2929 return bgp_vty_return(vty, ret);
2930 }
2931
2932 DEFUN (no_bgp_graceful_restart_disable,
2933 no_bgp_graceful_restart_disable_cmd,
2934 "no bgp graceful-restart-disable",
2935 NO_STR
2936 "BGP specific commands\n"
2937 NO_GR_DISABLE
2938 )
2939 {
2940 VTY_DECLVAR_CONTEXT(bgp, bgp);
2941
2942 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2943 zlog_debug(
2944 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : START ");
2945
2946 int ret = BGP_GR_FAILURE;
2947
2948 ret = bgp_gr_update_all(bgp, NO_GLOBAL_DISABLE_CMD);
2949
2950 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2951 ret);
2952
2953 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2954 zlog_debug(
2955 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : END ");
2956 vty_out(vty,
2957 "Graceful restart configuration changed, reset all peers to take effect\n");
2958
2959 return bgp_vty_return(vty, ret);
2960 }
2961
2962 DEFUN (bgp_neighbor_graceful_restart_set,
2963 bgp_neighbor_graceful_restart_set_cmd,
2964 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
2965 NEIGHBOR_STR
2966 NEIGHBOR_ADDR_STR2
2967 GR_NEIGHBOR_CMD
2968 )
2969 {
2970 int idx_peer = 1;
2971 struct peer *peer;
2972 int ret = BGP_GR_FAILURE;
2973
2974 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2975
2976 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2977 zlog_debug(
2978 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : START ");
2979
2980 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2981 if (!peer)
2982 return CMD_WARNING_CONFIG_FAILED;
2983
2984 ret = bgp_neighbor_graceful_restart(peer, PEER_GR_CMD);
2985
2986 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2987 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
2988
2989 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2990 zlog_debug(
2991 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : END ");
2992 vty_out(vty,
2993 "Graceful restart configuration changed, reset this peer to take effect\n");
2994
2995 return bgp_vty_return(vty, ret);
2996 }
2997
2998 DEFUN (no_bgp_neighbor_graceful_restart,
2999 no_bgp_neighbor_graceful_restart_set_cmd,
3000 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3001 NO_STR
3002 NEIGHBOR_STR
3003 NEIGHBOR_ADDR_STR2
3004 NO_GR_NEIGHBOR_CMD
3005 )
3006 {
3007 int idx_peer = 2;
3008 int ret = BGP_GR_FAILURE;
3009 struct peer *peer;
3010
3011 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3012
3013 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3014 if (!peer)
3015 return CMD_WARNING_CONFIG_FAILED;
3016
3017 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3018 zlog_debug(
3019 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : START ");
3020
3021 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_GR_CMD);
3022
3023 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3024 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3025
3026 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3027 zlog_debug(
3028 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : END ");
3029 vty_out(vty,
3030 "Graceful restart configuration changed, reset this peer to take effect\n");
3031
3032 return bgp_vty_return(vty, ret);
3033 }
3034
3035 DEFUN (bgp_neighbor_graceful_restart_helper_set,
3036 bgp_neighbor_graceful_restart_helper_set_cmd,
3037 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3038 NEIGHBOR_STR
3039 NEIGHBOR_ADDR_STR2
3040 GR_NEIGHBOR_HELPER_CMD
3041 )
3042 {
3043 int idx_peer = 1;
3044 struct peer *peer;
3045 int ret = BGP_GR_FAILURE;
3046
3047 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3048
3049 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3050 zlog_debug(
3051 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : START ");
3052
3053 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3054
3055 if (!peer)
3056 return CMD_WARNING_CONFIG_FAILED;
3057
3058
3059 ret = bgp_neighbor_graceful_restart(peer, PEER_HELPER_CMD);
3060
3061 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3062 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3063
3064 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3065 zlog_debug(
3066 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : END ");
3067 vty_out(vty,
3068 "Graceful restart configuration changed, reset this peer to take effect\n");
3069
3070 return bgp_vty_return(vty, ret);
3071 }
3072
3073 DEFUN (no_bgp_neighbor_graceful_restart_helper,
3074 no_bgp_neighbor_graceful_restart_helper_set_cmd,
3075 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3076 NO_STR
3077 NEIGHBOR_STR
3078 NEIGHBOR_ADDR_STR2
3079 NO_GR_NEIGHBOR_HELPER_CMD
3080 )
3081 {
3082 int idx_peer = 2;
3083 int ret = BGP_GR_FAILURE;
3084 struct peer *peer;
3085
3086 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3087
3088 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3089 if (!peer)
3090 return CMD_WARNING_CONFIG_FAILED;
3091
3092 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3093 zlog_debug(
3094 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : START ");
3095
3096 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_HELPER_CMD);
3097
3098 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3099 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3100
3101 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3102 zlog_debug(
3103 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : END ");
3104 vty_out(vty,
3105 "Graceful restart configuration changed, reset this peer to take effect\n");
3106
3107 return bgp_vty_return(vty, ret);
3108 }
3109
3110 DEFUN (bgp_neighbor_graceful_restart_disable_set,
3111 bgp_neighbor_graceful_restart_disable_set_cmd,
3112 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3113 NEIGHBOR_STR
3114 NEIGHBOR_ADDR_STR2
3115 GR_NEIGHBOR_DISABLE_CMD
3116 )
3117 {
3118 int idx_peer = 1;
3119 struct peer *peer;
3120 int ret = BGP_GR_FAILURE;
3121
3122 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3123
3124 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3125 zlog_debug(
3126 "[BGP_GR] bgp_neighbor_graceful_restart_disable_set_cmd : START ");
3127
3128 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3129 if (!peer)
3130 return CMD_WARNING_CONFIG_FAILED;
3131
3132 ret = bgp_neighbor_graceful_restart(peer, PEER_DISABLE_CMD);
3133
3134 if (peer->bgp->t_startup)
3135 bgp_peer_gr_flags_update(peer);
3136
3137 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3138 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3139
3140 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3141 zlog_debug(
3142 "[BGP_GR]bgp_neighbor_graceful_restart_disable_set_cmd : END ");
3143 vty_out(vty,
3144 "Graceful restart configuration changed, reset this peer to take effect\n");
3145
3146 return bgp_vty_return(vty, ret);
3147 }
3148
3149 DEFUN (no_bgp_neighbor_graceful_restart_disable,
3150 no_bgp_neighbor_graceful_restart_disable_set_cmd,
3151 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3152 NO_STR
3153 NEIGHBOR_STR
3154 NEIGHBOR_ADDR_STR2
3155 NO_GR_NEIGHBOR_DISABLE_CMD
3156 )
3157 {
3158 int idx_peer = 2;
3159 int ret = BGP_GR_FAILURE;
3160 struct peer *peer;
3161
3162 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3163
3164 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3165 if (!peer)
3166 return CMD_WARNING_CONFIG_FAILED;
3167
3168 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3169 zlog_debug(
3170 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : START ");
3171
3172 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_DISABLE_CMD);
3173
3174 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3175 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3176
3177 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3178 zlog_debug(
3179 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : END ");
3180 vty_out(vty,
3181 "Graceful restart configuration changed, reset this peer to take effect\n");
3182
3183 return bgp_vty_return(vty, ret);
3184 }
3185
3186 DEFUN_HIDDEN (bgp_graceful_restart_disable_eor,
3187 bgp_graceful_restart_disable_eor_cmd,
3188 "bgp graceful-restart disable-eor",
3189 "BGP specific commands\n"
3190 "Graceful restart configuration parameters\n"
3191 "Disable EOR Check\n")
3192 {
3193 VTY_DECLVAR_CONTEXT(bgp, bgp);
3194 SET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
3195
3196 return CMD_SUCCESS;
3197 }
3198
3199 DEFUN_HIDDEN (no_bgp_graceful_restart_disable_eor,
3200 no_bgp_graceful_restart_disable_eor_cmd,
3201 "no bgp graceful-restart disable-eor",
3202 NO_STR
3203 "BGP specific commands\n"
3204 "Graceful restart configuration parameters\n"
3205 "Disable EOR Check\n")
3206 {
3207 VTY_DECLVAR_CONTEXT(bgp, bgp);
3208 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
3209
3210 return CMD_SUCCESS;
3211 }
3212
3213 DEFUN (bgp_graceful_restart_rib_stale_time,
3214 bgp_graceful_restart_rib_stale_time_cmd,
3215 "bgp graceful-restart rib-stale-time (1-3600)",
3216 "BGP specific commands\n"
3217 "Graceful restart configuration parameters\n"
3218 "Specify the stale route removal timer in rib\n"
3219 "Delay value (seconds)\n")
3220 {
3221 VTY_DECLVAR_CONTEXT(bgp, bgp);
3222 int idx_number = 3;
3223 uint32_t stale_time;
3224
3225 stale_time = strtoul(argv[idx_number]->arg, NULL, 10);
3226 bgp->rib_stale_time = stale_time;
3227 /* Send the stale timer update message to RIB */
3228 if (bgp_zebra_stale_timer_update(bgp))
3229 return CMD_WARNING;
3230
3231 return CMD_SUCCESS;
3232 }
3233
3234 DEFUN (no_bgp_graceful_restart_rib_stale_time,
3235 no_bgp_graceful_restart_rib_stale_time_cmd,
3236 "no bgp graceful-restart rib-stale-time [(1-3600)]",
3237 NO_STR
3238 "BGP specific commands\n"
3239 "Graceful restart configuration parameters\n"
3240 "Specify the stale route removal timer in rib\n"
3241 "Delay value (seconds)\n")
3242 {
3243 VTY_DECLVAR_CONTEXT(bgp, bgp);
3244
3245 bgp->rib_stale_time = BGP_DEFAULT_RIB_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 static inline int bgp_initiate_graceful_shut_unshut(struct bgp *bgp,
3254 char *errmsg,
3255 size_t errmsg_len)
3256 {
3257 bgp_static_redo_import_check(bgp);
3258 bgp_redistribute_redo(bgp);
3259 if (bgp_clear_star_soft_out(bgp->name, errmsg, errmsg_len) < 0)
3260 return -1;
3261 if (bgp_clear_star_soft_in(bgp->name, errmsg, errmsg_len) < 0)
3262 return -1;
3263
3264 return 0;
3265 }
3266
3267 static int bgp_global_graceful_shutdown_config_vty(struct vty *vty)
3268 {
3269 struct listnode *node, *nnode;
3270 struct bgp *bgp;
3271 bool vrf_cfg = false;
3272 char errmsg[BUFSIZ] = {'\0'};
3273
3274 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3275 return CMD_SUCCESS;
3276
3277 /* See if graceful-shutdown is set per-vrf and warn user to delete */
3278 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3279 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3280 vty_out(vty,
3281 "%% graceful-shutdown configuration found in vrf %s\n",
3282 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT ?
3283 VRF_DEFAULT_NAME : bgp->name);
3284 vrf_cfg = true;
3285 }
3286 }
3287
3288 if (vrf_cfg) {
3289 vty_out(vty,
3290 "%%Failed: global graceful-shutdown not permitted\n");
3291 return CMD_WARNING;
3292 }
3293
3294 /* Set flag globally */
3295 SET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3296
3297 /* Initiate processing for all BGP instances. */
3298 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3299 if (bgp_initiate_graceful_shut_unshut(bgp, errmsg,
3300 sizeof(errmsg))
3301 < 0)
3302 if (strlen(errmsg))
3303 vty_out(vty, "%s\n", errmsg);
3304 }
3305
3306 return CMD_SUCCESS;
3307 }
3308
3309 static int bgp_global_graceful_shutdown_deconfig_vty(struct vty *vty)
3310 {
3311 struct listnode *node, *nnode;
3312 struct bgp *bgp;
3313 char errmsg[BUFSIZ] = {'\0'};
3314
3315 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3316 return CMD_SUCCESS;
3317
3318 /* Unset flag globally */
3319 UNSET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3320
3321 /* Initiate processing for all BGP instances. */
3322 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3323 if (bgp_initiate_graceful_shut_unshut(bgp, errmsg,
3324 sizeof(errmsg))
3325 < 0)
3326 if (strlen(errmsg))
3327 vty_out(vty, "%s\n", errmsg);
3328 }
3329
3330 return CMD_SUCCESS;
3331 }
3332
3333 /* "bgp graceful-shutdown" configuration */
3334 DEFUN (bgp_graceful_shutdown,
3335 bgp_graceful_shutdown_cmd,
3336 "bgp graceful-shutdown",
3337 BGP_STR
3338 "Graceful shutdown parameters\n")
3339 {
3340 if (vty->node == CONFIG_NODE)
3341 return bgp_global_graceful_shutdown_config_vty(vty);
3342
3343 nb_cli_enqueue_change(vty, "./global/graceful-shutdown/enable",
3344 NB_OP_MODIFY, "true");
3345
3346 return nb_cli_apply_changes(vty, NULL);
3347 }
3348
3349 DEFUN_YANG (no_bgp_graceful_shutdown,
3350 no_bgp_graceful_shutdown_cmd,
3351 "no bgp graceful-shutdown",
3352 NO_STR
3353 BGP_STR
3354 "Graceful shutdown parameters\n")
3355 {
3356 if (vty->node == CONFIG_NODE)
3357 return bgp_global_graceful_shutdown_deconfig_vty(vty);
3358
3359 nb_cli_enqueue_change(vty, "./global/graceful-shutdown/enable",
3360 NB_OP_MODIFY, "false");
3361
3362 return nb_cli_apply_changes(vty, NULL);
3363 }
3364
3365 void cli_show_router_bgp_graceful_shutdown(struct vty *vty,
3366 struct lyd_node *dnode,
3367 bool show_defaults)
3368 {
3369 if (yang_dnode_get_bool(dnode, NULL))
3370 vty_out(vty, " bgp graceful-shutdown\n");
3371 }
3372
3373 /* "bgp fast-external-failover" configuration. */
3374 DEFUN_YANG (bgp_fast_external_failover,
3375 bgp_fast_external_failover_cmd,
3376 "bgp fast-external-failover",
3377 BGP_STR
3378 "Immediately reset session if a link to a directly connected external peer goes down\n")
3379 {
3380 nb_cli_enqueue_change(vty, "./global/fast-external-failover",
3381 NB_OP_MODIFY, "false");
3382
3383 return nb_cli_apply_changes(vty, NULL);
3384 }
3385
3386 DEFUN_YANG (no_bgp_fast_external_failover,
3387 no_bgp_fast_external_failover_cmd,
3388 "no bgp fast-external-failover",
3389 NO_STR
3390 BGP_STR
3391 "Immediately reset session if a link to a directly connected external peer goes down\n")
3392 {
3393 nb_cli_enqueue_change(vty, "./global/fast-external-failover",
3394 NB_OP_MODIFY, "true");
3395
3396 return nb_cli_apply_changes(vty, NULL);
3397 }
3398
3399 void cli_show_router_bgp_fast_external_failover(struct vty *vty,
3400 struct lyd_node *dnode,
3401 bool show_defaults)
3402 {
3403 if (!yang_dnode_get_bool(dnode, NULL))
3404 vty_out(vty, " no bgp fast-external-failover\n");
3405 }
3406
3407 /* "bgp bestpath compare-routerid" configuration. */
3408 DEFUN_YANG(bgp_bestpath_compare_router_id,
3409 bgp_bestpath_compare_router_id_cmd,
3410 "bgp bestpath compare-routerid",
3411 "BGP specific commands\n"
3412 "Change the default bestpath selection\n"
3413 "Compare router-id for identical EBGP paths\n")
3414 {
3415 nb_cli_enqueue_change(
3416 vty,
3417 "./global/route-selection-options/external-compare-router-id",
3418 NB_OP_MODIFY, "true");
3419
3420 return nb_cli_apply_changes(vty, NULL);
3421 }
3422
3423 DEFUN_YANG(no_bgp_bestpath_compare_router_id,
3424 no_bgp_bestpath_compare_router_id_cmd,
3425 "no bgp bestpath compare-routerid",
3426 NO_STR
3427 "BGP specific commands\n"
3428 "Change the default bestpath selection\n"
3429 "Compare router-id for identical EBGP paths\n")
3430 {
3431 nb_cli_enqueue_change(
3432 vty,
3433 "./global/route-selection-options/external-compare-router-id",
3434 NB_OP_MODIFY, "false");
3435
3436 return nb_cli_apply_changes(vty, NULL);
3437 }
3438
3439 /* "bgp bestpath as-path ignore" configuration. */
3440 DEFUN_YANG(bgp_bestpath_aspath_ignore,
3441 bgp_bestpath_aspath_ignore_cmd,
3442 "bgp bestpath as-path ignore",
3443 "BGP specific commands\n"
3444 "Change the default bestpath selection\n"
3445 "AS-path attribute\n"
3446 "Ignore as-path length in selecting a route\n")
3447 {
3448 nb_cli_enqueue_change(
3449 vty, "./global/route-selection-options/ignore-as-path-length",
3450 NB_OP_MODIFY, "true");
3451
3452 return nb_cli_apply_changes(vty, NULL);
3453 }
3454
3455 DEFUN_YANG(no_bgp_bestpath_aspath_ignore,
3456 no_bgp_bestpath_aspath_ignore_cmd,
3457 "no bgp bestpath as-path ignore",
3458 NO_STR
3459 "BGP specific commands\n"
3460 "Change the default bestpath selection\n"
3461 "AS-path attribute\n"
3462 "Ignore as-path length in selecting a route\n")
3463 {
3464 nb_cli_enqueue_change(
3465 vty, "./global/route-selection-options/ignore-as-path-length",
3466 NB_OP_MODIFY, "false");
3467
3468 return nb_cli_apply_changes(vty, NULL);
3469 }
3470
3471 /* "bgp bestpath as-path confed" configuration. */
3472 DEFUN_YANG (bgp_bestpath_aspath_confed,
3473 bgp_bestpath_aspath_confed_cmd,
3474 "bgp bestpath as-path confed",
3475 "BGP specific commands\n"
3476 "Change the default bestpath selection\n"
3477 "AS-path attribute\n"
3478 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3479 {
3480 nb_cli_enqueue_change(vty,
3481 "./global/route-selection-options/aspath-confed",
3482 NB_OP_MODIFY, "true");
3483
3484 return nb_cli_apply_changes(vty, NULL);
3485 }
3486
3487 DEFUN_YANG (no_bgp_bestpath_aspath_confed,
3488 no_bgp_bestpath_aspath_confed_cmd,
3489 "no bgp bestpath as-path confed",
3490 NO_STR
3491 "BGP specific commands\n"
3492 "Change the default bestpath selection\n"
3493 "AS-path attribute\n"
3494 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3495 {
3496 nb_cli_enqueue_change(vty,
3497 "./global/route-selection-options/aspath-confed",
3498 NB_OP_MODIFY, "false");
3499
3500 return nb_cli_apply_changes(vty, NULL);
3501 }
3502
3503 /* "bgp bestpath as-path multipath-relax" configuration. */
3504 DEFUN_YANG (bgp_bestpath_aspath_multipath_relax,
3505 bgp_bestpath_aspath_multipath_relax_cmd,
3506 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
3507 "BGP specific commands\n"
3508 "Change the default bestpath selection\n"
3509 "AS-path attribute\n"
3510 "Allow load sharing across routes that have different AS paths (but same length)\n"
3511 "Generate an AS_SET\n"
3512 "Do not generate an AS_SET\n")
3513 {
3514 int idx = 0;
3515
3516 nb_cli_enqueue_change(
3517 vty, "./global/route-selection-options/allow-multiple-as",
3518 NB_OP_MODIFY, "true");
3519 if (argv_find(argv, argc, "as-set", &idx))
3520 nb_cli_enqueue_change(
3521 vty,
3522 "./global/route-selection-options/multi-path-as-set",
3523 NB_OP_MODIFY, "true");
3524 else
3525 nb_cli_enqueue_change(
3526 vty,
3527 "./global/route-selection-options/multi-path-as-set",
3528 NB_OP_MODIFY, "false");
3529
3530 return nb_cli_apply_changes(vty, NULL);
3531 }
3532
3533 DEFUN_YANG (no_bgp_bestpath_aspath_multipath_relax,
3534 no_bgp_bestpath_aspath_multipath_relax_cmd,
3535 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
3536 NO_STR
3537 "BGP specific commands\n"
3538 "Change the default bestpath selection\n"
3539 "AS-path attribute\n"
3540 "Allow load sharing across routes that have different AS paths (but same length)\n"
3541 "Generate an AS_SET\n"
3542 "Do not generate an AS_SET\n")
3543 {
3544 nb_cli_enqueue_change(
3545 vty, "./global/route-selection-options/allow-multiple-as",
3546 NB_OP_MODIFY, "false");
3547 nb_cli_enqueue_change(
3548 vty, "./global/route-selection-options/multi-path-as-set",
3549 NB_OP_MODIFY, "false");
3550
3551 return nb_cli_apply_changes(vty, NULL);
3552 }
3553
3554 /* "bgp log-neighbor-changes" configuration. */
3555 DEFUN_YANG(bgp_log_neighbor_changes,
3556 bgp_log_neighbor_changes_cmd,
3557 "bgp log-neighbor-changes",
3558 "BGP specific commands\n"
3559 "Log neighbor up/down and reset reason\n")
3560 {
3561 nb_cli_enqueue_change(
3562 vty, "./global/global-neighbor-config/log-neighbor-changes",
3563 NB_OP_MODIFY, "true");
3564
3565 return nb_cli_apply_changes(vty, NULL);
3566 }
3567
3568 DEFUN_YANG(no_bgp_log_neighbor_changes,
3569 no_bgp_log_neighbor_changes_cmd,
3570 "no bgp log-neighbor-changes",
3571 NO_STR
3572 "BGP specific commands\n"
3573 "Log neighbor up/down and reset reason\n")
3574 {
3575 nb_cli_enqueue_change(
3576 vty, "./global/global-neighbor-config/log-neighbor-changes",
3577 NB_OP_MODIFY, "false");
3578
3579 return nb_cli_apply_changes(vty, NULL);
3580 }
3581
3582 /* "bgp bestpath med" configuration. */
3583 DEFUN_YANG (bgp_bestpath_med,
3584 bgp_bestpath_med_cmd,
3585 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
3586 "BGP specific commands\n"
3587 "Change the default bestpath selection\n"
3588 "MED attribute\n"
3589 "Compare MED among confederation paths\n"
3590 "Treat missing MED as the least preferred one\n"
3591 "Treat missing MED as the least preferred one\n"
3592 "Compare MED among confederation paths\n")
3593 {
3594 int idx = 0;
3595 bool confed = false;
3596 bool worst_med = false;
3597
3598
3599 if (argv_find(argv, argc, "confed", &idx))
3600 confed = true;
3601
3602 nb_cli_enqueue_change(vty,
3603 "./global/route-selection-options/confed-med",
3604 NB_OP_MODIFY, confed ? "true" : "false");
3605
3606 idx = 0;
3607 if (argv_find(argv, argc, "missing-as-worst", &idx))
3608 worst_med = true;
3609
3610 nb_cli_enqueue_change(
3611 vty, "./global/route-selection-options/missing-as-worst-med",
3612 NB_OP_MODIFY, worst_med ? "true" : "false");
3613
3614 return nb_cli_apply_changes(vty, NULL);
3615 }
3616
3617 DEFUN_YANG (no_bgp_bestpath_med,
3618 no_bgp_bestpath_med_cmd,
3619 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
3620 NO_STR
3621 "BGP specific commands\n"
3622 "Change the default bestpath selection\n"
3623 "MED attribute\n"
3624 "Compare MED among confederation paths\n"
3625 "Treat missing MED as the least preferred one\n"
3626 "Treat missing MED as the least preferred one\n"
3627 "Compare MED among confederation paths\n")
3628 {
3629 int idx = 0;
3630
3631 if (argv_find(argv, argc, "confed", &idx))
3632 nb_cli_enqueue_change(
3633 vty, "./global/route-selection-options/confed-med",
3634 NB_OP_MODIFY, "false");
3635
3636 idx = 0;
3637 if (argv_find(argv, argc, "missing-as-worst", &idx))
3638 nb_cli_enqueue_change(
3639 vty,
3640 "./global/route-selection-options/missing-as-worst-med",
3641 NB_OP_MODIFY, "false");
3642
3643 return nb_cli_apply_changes(vty, NULL);
3644 }
3645
3646 /* "bgp bestpath bandwidth" configuration. */
3647 DEFPY (bgp_bestpath_bw,
3648 bgp_bestpath_bw_cmd,
3649 "bgp bestpath bandwidth <ignore|skip-missing|default-weight-for-missing>$bw_cfg",
3650 "BGP specific commands\n"
3651 "Change the default bestpath selection\n"
3652 "Link Bandwidth attribute\n"
3653 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3654 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3655 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3656 {
3657 VTY_DECLVAR_CONTEXT(bgp, bgp);
3658 afi_t afi;
3659 safi_t safi;
3660
3661 if (!bw_cfg) {
3662 vty_out(vty, "%% Bandwidth configuration must be specified\n");
3663 return CMD_ERR_INCOMPLETE;
3664 }
3665 if (!strcmp(bw_cfg, "ignore"))
3666 bgp->lb_handling = BGP_LINK_BW_IGNORE_BW;
3667 else if (!strcmp(bw_cfg, "skip-missing"))
3668 bgp->lb_handling = BGP_LINK_BW_SKIP_MISSING;
3669 else if (!strcmp(bw_cfg, "default-weight-for-missing"))
3670 bgp->lb_handling = BGP_LINK_BW_DEFWT_4_MISSING;
3671 else
3672 return CMD_ERR_NO_MATCH;
3673
3674 /* This config is used in route install, so redo that. */
3675 FOREACH_AFI_SAFI (afi, safi) {
3676 if (!bgp_fibupd_safi(safi))
3677 continue;
3678 bgp_zebra_announce_table(bgp, afi, safi);
3679 }
3680
3681 return CMD_SUCCESS;
3682 }
3683
3684 DEFPY (no_bgp_bestpath_bw,
3685 no_bgp_bestpath_bw_cmd,
3686 "no bgp bestpath bandwidth [<ignore|skip-missing|default-weight-for-missing>$bw_cfg]",
3687 NO_STR
3688 "BGP specific commands\n"
3689 "Change the default bestpath selection\n"
3690 "Link Bandwidth attribute\n"
3691 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3692 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3693 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3694 {
3695 VTY_DECLVAR_CONTEXT(bgp, bgp);
3696 afi_t afi;
3697 safi_t safi;
3698
3699 bgp->lb_handling = BGP_LINK_BW_ECMP;
3700
3701 /* This config is used in route install, so redo that. */
3702 FOREACH_AFI_SAFI (afi, safi) {
3703 if (!bgp_fibupd_safi(safi))
3704 continue;
3705 bgp_zebra_announce_table(bgp, afi, safi);
3706 }
3707 return CMD_SUCCESS;
3708 }
3709
3710 /* "no bgp default ipv4-unicast". */
3711 DEFUN (no_bgp_default_ipv4_unicast,
3712 no_bgp_default_ipv4_unicast_cmd,
3713 "no bgp default ipv4-unicast",
3714 NO_STR
3715 "BGP specific commands\n"
3716 "Configure BGP defaults\n"
3717 "Activate ipv4-unicast for a peer by default\n")
3718 {
3719 VTY_DECLVAR_CONTEXT(bgp, bgp);
3720 SET_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4);
3721 return CMD_SUCCESS;
3722 }
3723
3724 DEFUN (bgp_default_ipv4_unicast,
3725 bgp_default_ipv4_unicast_cmd,
3726 "bgp default ipv4-unicast",
3727 "BGP specific commands\n"
3728 "Configure BGP defaults\n"
3729 "Activate ipv4-unicast for a peer by default\n")
3730 {
3731 VTY_DECLVAR_CONTEXT(bgp, bgp);
3732 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4);
3733 return CMD_SUCCESS;
3734 }
3735
3736 /* Display hostname in certain command outputs */
3737 DEFUN_YANG (bgp_default_show_hostname,
3738 bgp_default_show_hostname_cmd,
3739 "bgp default show-hostname",
3740 "BGP specific commands\n"
3741 "Configure BGP defaults\n"
3742 "Show hostname in certain command outputs\n")
3743 {
3744 nb_cli_enqueue_change(vty, "./global/show-hostname", NB_OP_MODIFY,
3745 "true");
3746
3747 return nb_cli_apply_changes(vty, NULL);
3748 }
3749
3750 DEFUN_YANG(no_bgp_default_show_hostname,
3751 no_bgp_default_show_hostname_cmd,
3752 "no bgp default show-hostname",
3753 NO_STR
3754 "BGP specific commands\n"
3755 "Configure BGP defaults\n"
3756 "Show hostname in certain command outputs\n")
3757 {
3758 nb_cli_enqueue_change(vty, "./global/show-hostname", NB_OP_MODIFY,
3759 "false");
3760
3761 return nb_cli_apply_changes(vty, NULL);
3762 }
3763
3764 void cli_show_router_bgp_show_hostname(struct vty *vty, struct lyd_node *dnode,
3765 bool show_defaults)
3766 {
3767 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_SHOW_HOSTNAME)
3768 vty_out(vty, " bgp default show-hostname\n");
3769 }
3770
3771 /* Display hostname in certain command outputs */
3772 DEFUN_YANG(bgp_default_show_nexthop_hostname,
3773 bgp_default_show_nexthop_hostname_cmd,
3774 "bgp default show-nexthop-hostname",
3775 "BGP specific commands\n"
3776 "Configure BGP defaults\n"
3777 "Show hostname for nexthop in certain command outputs\n")
3778 {
3779 nb_cli_enqueue_change(vty, "./global/show-nexthop-hostname",
3780 NB_OP_MODIFY, "true");
3781
3782 return nb_cli_apply_changes(vty, NULL);
3783 }
3784
3785 DEFUN (no_bgp_default_show_nexthop_hostname,
3786 no_bgp_default_show_nexthop_hostname_cmd,
3787 "no bgp default show-nexthop-hostname",
3788 NO_STR
3789 "BGP specific commands\n"
3790 "Configure BGP defaults\n"
3791 "Show hostname for nexthop in certain command outputs\n")
3792 {
3793 nb_cli_enqueue_change(vty, "./global/show-nexthop-hostname",
3794 NB_OP_MODIFY, "false");
3795
3796 return nb_cli_apply_changes(vty, NULL);
3797 }
3798
3799 void cli_show_router_bgp_show_nexthop_hostname(struct vty *vty,
3800 struct lyd_node *dnode,
3801 bool show_defaults)
3802 {
3803 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_SHOW_HOSTNAME)
3804 vty_out(vty, " bgp default show-nexthop-hostname\n");
3805 }
3806
3807 /* "bgp network import-check" configuration. */
3808 DEFUN_YANG(bgp_network_import_check,
3809 bgp_network_import_check_cmd,
3810 "bgp network import-check",
3811 "BGP specific commands\n"
3812 "BGP network command\n"
3813 "Check BGP network route exists in IGP\n")
3814 {
3815 nb_cli_enqueue_change(vty, "./global/import-check", NB_OP_MODIFY,
3816 "true");
3817
3818 return nb_cli_apply_changes(vty, NULL);
3819 }
3820
3821 ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
3822 "bgp network import-check exact",
3823 "BGP specific commands\n"
3824 "BGP network command\n"
3825 "Check BGP network route exists in IGP\n"
3826 "Match route precisely\n")
3827
3828 DEFUN_YANG(no_bgp_network_import_check,
3829 no_bgp_network_import_check_cmd,
3830 "no bgp network import-check",
3831 NO_STR
3832 "BGP specific commands\n"
3833 "BGP network command\n"
3834 "Check BGP network route exists in IGP\n")
3835 {
3836 nb_cli_enqueue_change(vty, "./global/import-check", NB_OP_MODIFY,
3837 "false");
3838
3839 return nb_cli_apply_changes(vty, NULL);
3840 }
3841
3842 void cli_show_router_bgp_import_check(struct vty *vty, struct lyd_node *dnode,
3843 bool show_defaults)
3844 {
3845 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_IMPORT_CHECK)
3846 vty_out(vty, " bgp network import-check\n");
3847 }
3848
3849 DEFUN_YANG(bgp_default_local_preference,
3850 bgp_default_local_preference_cmd,
3851 "bgp default local-preference (0-4294967295)",
3852 "BGP specific commands\n"
3853 "Configure BGP defaults\n"
3854 "local preference (higher=more preferred)\n"
3855 "Configure default local preference value\n")
3856 {
3857 int idx_number = 3;
3858
3859 nb_cli_enqueue_change(vty, "./global/local-pref", NB_OP_MODIFY,
3860 argv[idx_number]->arg);
3861
3862 return nb_cli_apply_changes(vty, NULL);
3863 }
3864
3865 DEFUN_YANG(no_bgp_default_local_preference,
3866 no_bgp_default_local_preference_cmd,
3867 "no bgp default local-preference [(0-4294967295)]",
3868 NO_STR
3869 "BGP specific commands\n"
3870 "Configure BGP defaults\n"
3871 "local preference (higher=more preferred)\n"
3872 "Configure default local preference value\n")
3873 {
3874 nb_cli_enqueue_change(vty, "./global/local-pref", NB_OP_MODIFY, NULL);
3875
3876 return nb_cli_apply_changes(vty, NULL);
3877 }
3878
3879 void cli_show_router_bgp_local_pref(struct vty *vty, struct lyd_node *dnode,
3880 bool show_defaults)
3881 {
3882 vty_out(vty, " bgp default local-preference %u\n",
3883 yang_dnode_get_uint32(dnode, NULL));
3884 }
3885
3886
3887 DEFUN_YANG(bgp_default_subgroup_pkt_queue_max,
3888 bgp_default_subgroup_pkt_queue_max_cmd,
3889 "bgp default subgroup-pkt-queue-max (20-100)",
3890 "BGP specific commands\n"
3891 "Configure BGP defaults\n"
3892 "subgroup-pkt-queue-max\n"
3893 "Configure subgroup packet queue max\n")
3894 {
3895 int idx_number = 3;
3896
3897 nb_cli_enqueue_change(
3898 vty,
3899 "./global/global-update-group-config/subgroup-pkt-queue-size",
3900 NB_OP_MODIFY, argv[idx_number]->arg);
3901
3902 return nb_cli_apply_changes(vty, NULL);
3903 }
3904
3905 DEFUN_YANG(no_bgp_default_subgroup_pkt_queue_max,
3906 no_bgp_default_subgroup_pkt_queue_max_cmd,
3907 "no bgp default subgroup-pkt-queue-max [(20-100)]",
3908 NO_STR
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 nb_cli_enqueue_change(
3915 vty,
3916 "./global/global-update-group-config/subgroup-pkt-queue-size",
3917 NB_OP_MODIFY, NULL);
3918
3919 return nb_cli_apply_changes(vty, NULL);
3920 }
3921
3922 void cli_show_router_global_update_group_config_subgroup_pkt_queue_size(
3923 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
3924 {
3925 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
3926 yang_dnode_get_uint32(dnode, NULL));
3927 }
3928
3929 DEFUN_YANG(bgp_rr_allow_outbound_policy,
3930 bgp_rr_allow_outbound_policy_cmd,
3931 "bgp route-reflector allow-outbound-policy",
3932 "BGP specific commands\n"
3933 "Allow modifications made by out route-map\n"
3934 "on ibgp neighbors\n")
3935 {
3936 nb_cli_enqueue_change(vty,
3937 "./global/route-reflector/allow-outbound-policy",
3938 NB_OP_MODIFY, "true");
3939
3940 return nb_cli_apply_changes(vty, NULL);
3941 }
3942
3943 DEFUN_YANG(no_bgp_rr_allow_outbound_policy,
3944 no_bgp_rr_allow_outbound_policy_cmd,
3945 "no bgp route-reflector allow-outbound-policy",
3946 NO_STR
3947 "BGP specific commands\n"
3948 "Allow modifications made by out route-map\n"
3949 "on ibgp neighbors\n")
3950 {
3951 nb_cli_enqueue_change(vty,
3952 "./global/route-reflector/allow-outbound-policy",
3953 NB_OP_MODIFY, "false");
3954
3955 return nb_cli_apply_changes(vty, NULL);
3956 }
3957
3958
3959 void cli_show_router_global_neighbor_config(struct vty *vty,
3960 struct lyd_node *dnode,
3961 bool show_defaults)
3962 {
3963 uint32_t write_quanta, read_quanta;
3964
3965 if (yang_dnode_get_bool(dnode, "./log-neighbor-changes"))
3966 vty_out(vty, " bgp log-neighbor-changes\n");
3967
3968 if (yang_dnode_exists(dnode, "./dynamic-neighbors-limit")) {
3969 uint32_t listen_limit = yang_dnode_get_uint32(
3970 dnode, "./dynamic-neighbors-limit");
3971 vty_out(vty, " bgp listen limit %u\n", listen_limit);
3972 }
3973
3974 write_quanta = yang_dnode_get_uint32(
3975 dnode, "./packet-quanta-config/wpkt-quanta");
3976 if (write_quanta != BGP_WRITE_PACKET_MAX)
3977 vty_out(vty, " write-quanta %d\n", write_quanta);
3978
3979 read_quanta = yang_dnode_get_uint32(
3980 dnode, "./packet-quanta-config/rpkt-quanta");
3981
3982 if (read_quanta != BGP_READ_PACKET_MAX)
3983 vty_out(vty, " read-quanta %d\n", read_quanta);
3984 }
3985
3986 DEFUN_YANG(bgp_listen_limit,
3987 bgp_listen_limit_cmd,
3988 "bgp listen limit (1-5000)",
3989 "BGP specific commands\n"
3990 "BGP Dynamic Neighbors listen commands\n"
3991 "Maximum number of BGP Dynamic Neighbors that can be created\n"
3992 "Configure Dynamic Neighbors listen limit value\n")
3993 {
3994 int idx_number = 3;
3995
3996 nb_cli_enqueue_change(
3997 vty, "./global/global-neighbor-config/dynamic-neighbors-limit",
3998 NB_OP_MODIFY, argv[idx_number]->arg);
3999
4000 return nb_cli_apply_changes(vty, NULL);
4001 }
4002
4003 DEFUN_YANG(no_bgp_listen_limit,
4004 no_bgp_listen_limit_cmd,
4005 "no bgp listen limit [(1-5000)]",
4006 NO_STR
4007 "BGP specific commands\n"
4008 "BGP Dynamic Neighbors listen commands\n"
4009 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4010 "Configure Dynamic Neighbors listen limit value\n")
4011 {
4012 nb_cli_enqueue_change(
4013 vty, "./global/global-neighbor-config/dynamic-neighbors-limit",
4014 NB_OP_DESTROY, NULL);
4015
4016 return nb_cli_apply_changes(vty, NULL);
4017 }
4018
4019
4020 /*
4021 * Check if this listen range is already configured. Check for exact
4022 * match or overlap based on input.
4023 */
4024 static struct peer_group *listen_range_exists(struct bgp *bgp,
4025 struct prefix *range, int exact)
4026 {
4027 struct listnode *node, *nnode;
4028 struct listnode *node1, *nnode1;
4029 struct peer_group *group;
4030 struct prefix *lr;
4031 afi_t afi;
4032 int match;
4033
4034 afi = family2afi(range->family);
4035 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4036 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
4037 lr)) {
4038 if (exact)
4039 match = prefix_same(range, lr);
4040 else
4041 match = (prefix_match(range, lr)
4042 || prefix_match(lr, range));
4043 if (match)
4044 return group;
4045 }
4046 }
4047
4048 return NULL;
4049 }
4050
4051 DEFUN (bgp_listen_range,
4052 bgp_listen_range_cmd,
4053 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
4054 "BGP specific commands\n"
4055 "Configure BGP dynamic neighbors listen range\n"
4056 "Configure BGP dynamic neighbors listen range\n"
4057 NEIGHBOR_ADDR_STR
4058 "Member of the peer-group\n"
4059 "Peer-group name\n")
4060 {
4061 VTY_DECLVAR_CONTEXT(bgp, bgp);
4062 struct prefix range;
4063 struct peer_group *group, *existing_group;
4064 afi_t afi;
4065 int ret;
4066 int idx = 0;
4067
4068 argv_find(argv, argc, "A.B.C.D/M", &idx);
4069 argv_find(argv, argc, "X:X::X:X/M", &idx);
4070 char *prefix = argv[idx]->arg;
4071 argv_find(argv, argc, "PGNAME", &idx);
4072 char *peergroup = argv[idx]->arg;
4073
4074 /* Convert IP prefix string to struct prefix. */
4075 ret = str2prefix(prefix, &range);
4076 if (!ret) {
4077 vty_out(vty, "%% Malformed listen range\n");
4078 return CMD_WARNING_CONFIG_FAILED;
4079 }
4080
4081 afi = family2afi(range.family);
4082
4083 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4084 vty_out(vty,
4085 "%% Malformed listen range (link-local address)\n");
4086 return CMD_WARNING_CONFIG_FAILED;
4087 }
4088
4089 apply_mask(&range);
4090
4091 /* Check if same listen range is already configured. */
4092 existing_group = listen_range_exists(bgp, &range, 1);
4093 if (existing_group) {
4094 if (strcmp(existing_group->name, peergroup) == 0)
4095 return CMD_SUCCESS;
4096 else {
4097 vty_out(vty,
4098 "%% Same listen range is attached to peer-group %s\n",
4099 existing_group->name);
4100 return CMD_WARNING_CONFIG_FAILED;
4101 }
4102 }
4103
4104 /* Check if an overlapping listen range exists. */
4105 if (listen_range_exists(bgp, &range, 0)) {
4106 vty_out(vty,
4107 "%% Listen range overlaps with existing listen range\n");
4108 return CMD_WARNING_CONFIG_FAILED;
4109 }
4110
4111 group = peer_group_lookup(bgp, peergroup);
4112 if (!group) {
4113 vty_out(vty, "%% Configure the peer-group first\n");
4114 return CMD_WARNING_CONFIG_FAILED;
4115 }
4116
4117 ret = peer_group_listen_range_add(group, &range);
4118 return bgp_vty_return(vty, ret);
4119 }
4120
4121 DEFUN (no_bgp_listen_range,
4122 no_bgp_listen_range_cmd,
4123 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
4124 NO_STR
4125 "BGP specific commands\n"
4126 "Unconfigure BGP dynamic neighbors listen range\n"
4127 "Unconfigure BGP dynamic neighbors listen range\n"
4128 NEIGHBOR_ADDR_STR
4129 "Member of the peer-group\n"
4130 "Peer-group name\n")
4131 {
4132 VTY_DECLVAR_CONTEXT(bgp, bgp);
4133 struct prefix range;
4134 struct peer_group *group;
4135 afi_t afi;
4136 int ret;
4137 int idx = 0;
4138
4139 argv_find(argv, argc, "A.B.C.D/M", &idx);
4140 argv_find(argv, argc, "X:X::X:X/M", &idx);
4141 char *prefix = argv[idx]->arg;
4142 argv_find(argv, argc, "PGNAME", &idx);
4143 char *peergroup = argv[idx]->arg;
4144
4145 /* Convert IP prefix string to struct prefix. */
4146 ret = str2prefix(prefix, &range);
4147 if (!ret) {
4148 vty_out(vty, "%% Malformed listen range\n");
4149 return CMD_WARNING_CONFIG_FAILED;
4150 }
4151
4152 afi = family2afi(range.family);
4153
4154 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4155 vty_out(vty,
4156 "%% Malformed listen range (link-local address)\n");
4157 return CMD_WARNING_CONFIG_FAILED;
4158 }
4159
4160 apply_mask(&range);
4161
4162 group = peer_group_lookup(bgp, peergroup);
4163 if (!group) {
4164 vty_out(vty, "%% Peer-group does not exist\n");
4165 return CMD_WARNING_CONFIG_FAILED;
4166 }
4167
4168 ret = peer_group_listen_range_del(group, &range);
4169 return bgp_vty_return(vty, ret);
4170 }
4171
4172 void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
4173 {
4174 struct peer_group *group;
4175 struct listnode *node, *nnode, *rnode, *nrnode;
4176 struct prefix *range;
4177 afi_t afi;
4178
4179 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
4180 vty_out(vty, " bgp listen limit %d\n",
4181 bgp->dynamic_neighbors_limit);
4182
4183 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4184 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
4185 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
4186 nrnode, range)) {
4187 vty_out(vty,
4188 " bgp listen range %pFX peer-group %s\n",
4189 range, group->name);
4190 }
4191 }
4192 }
4193 }
4194
4195
4196 DEFUN_YANG(bgp_disable_connected_route_check,
4197 bgp_disable_connected_route_check_cmd,
4198 "bgp disable-ebgp-connected-route-check",
4199 "BGP specific commands\n"
4200 "Disable checking if nexthop is connected on ebgp sessions\n")
4201 {
4202 nb_cli_enqueue_change(vty,
4203 "./global/ebgp-multihop-connected-route-check",
4204 NB_OP_MODIFY, "true");
4205
4206 return nb_cli_apply_changes(vty, NULL);
4207 }
4208
4209 DEFUN_YANG(no_bgp_disable_connected_route_check,
4210 no_bgp_disable_connected_route_check_cmd,
4211 "no bgp disable-ebgp-connected-route-check",
4212 NO_STR
4213 "BGP specific commands\n"
4214 "Disable checking if nexthop is connected on ebgp sessions\n")
4215 {
4216 nb_cli_enqueue_change(vty,
4217 "./global/ebgp-multihop-connected-route-check",
4218 NB_OP_MODIFY, "false");
4219
4220 return nb_cli_apply_changes(vty, NULL);
4221 }
4222
4223 void cli_show_router_global_ebgp_multihop_connected_route_check(
4224 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
4225 {
4226 if (yang_dnode_get_bool(dnode, NULL))
4227 vty_out(vty, " bgp disable-ebgp-connected-route-check\n");
4228 }
4229
4230 DEFUN_YANG(bgp_default_shutdown,
4231 bgp_default_shutdown_cmd,
4232 "[no] bgp default shutdown",
4233 NO_STR BGP_STR
4234 "Configure BGP defaults\n"
4235 "Apply administrative shutdown to newly configured peers\n")
4236 {
4237 nb_cli_enqueue_change(vty, "./global/default-shutdown", NB_OP_MODIFY,
4238 strmatch(argv[0]->text, "no") ? "false" : "true");
4239
4240 return nb_cli_apply_changes(vty, NULL);
4241 }
4242
4243 void cli_show_router_bgp_default_shutdown(struct vty *vty,
4244 struct lyd_node *dnode,
4245 bool show_defaults)
4246 {
4247 if (yang_dnode_get_bool(dnode, NULL))
4248 vty_out(vty, " bgp default shutdown\n");
4249 }
4250
4251 DEFPY(bgp_shutdown_msg, bgp_shutdown_msg_cmd, "bgp shutdown message MSG...",
4252 BGP_STR
4253 "Administrative shutdown of the BGP instance\n"
4254 "Add a shutdown message (RFC 8203)\n"
4255 "Shutdown message\n")
4256 {
4257 char *msgstr = NULL;
4258
4259 VTY_DECLVAR_CONTEXT(bgp, bgp);
4260
4261 if (argc > 3)
4262 msgstr = argv_concat(argv, argc, 3);
4263
4264 bgp_shutdown_enable(bgp, msgstr);
4265 XFREE(MTYPE_TMP, msgstr);
4266
4267 return CMD_SUCCESS;
4268 }
4269
4270 DEFPY(bgp_shutdown, bgp_shutdown_cmd, "bgp shutdown",
4271 BGP_STR "Administrative shutdown of the BGP instance\n")
4272 {
4273 VTY_DECLVAR_CONTEXT(bgp, bgp);
4274
4275 bgp_shutdown_enable(bgp, NULL);
4276
4277 return CMD_SUCCESS;
4278 }
4279
4280 DEFPY(no_bgp_shutdown, no_bgp_shutdown_cmd, "no bgp shutdown",
4281 NO_STR BGP_STR "Administrative shutdown of the BGP instance\n")
4282 {
4283 VTY_DECLVAR_CONTEXT(bgp, bgp);
4284
4285 bgp_shutdown_disable(bgp);
4286
4287 return CMD_SUCCESS;
4288 }
4289
4290 ALIAS(no_bgp_shutdown, no_bgp_shutdown_msg_cmd,
4291 "no bgp shutdown message MSG...", NO_STR BGP_STR
4292 "Administrative shutdown of the BGP instance\n"
4293 "Add a shutdown message (RFC 8203)\n" "Shutdown message\n")
4294
4295 DEFUN_YANG(neighbor_remote_as,
4296 neighbor_remote_as_cmd,
4297 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
4298 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4299 "Specify a BGP neighbor\n" AS_STR
4300 "Internal BGP peer\n"
4301 "External BGP peer\n")
4302 {
4303 int idx_peer = 1;
4304 int idx_remote_as = 3;
4305 char base_xpath[XPATH_MAXLEN];
4306 char unnbr_xpath[XPATH_MAXLEN];
4307 char prgrp_xpath[XPATH_MAXLEN];
4308 union sockunion su;
4309 const char *as_type_str = "as-specified";
4310
4311 if (str2sockunion(argv[idx_peer]->arg, &su) < 0) {
4312 snprintf(unnbr_xpath, sizeof(unnbr_xpath),
4313 FRR_BGP_NEIGHBOR_UNNUM_XPATH, argv[idx_peer]->arg, "");
4314
4315 snprintf(prgrp_xpath, sizeof(prgrp_xpath),
4316 FRR_BGP_PEER_GROUP_XPATH, argv[idx_peer]->arg, "");
4317
4318 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
4319 VTY_CURR_XPATH, unnbr_xpath + 1)) {
4320 strlcpy(base_xpath, unnbr_xpath, sizeof(base_xpath));
4321 } else if (yang_dnode_exists(vty->candidate_config->dnode,
4322 "%s%s", VTY_CURR_XPATH,
4323 prgrp_xpath + 1)) {
4324 snprintf(base_xpath, sizeof(base_xpath),
4325 FRR_BGP_PEER_GROUP_XPATH, argv[idx_peer]->arg,
4326 "");
4327 } else {
4328 vty_out(vty,
4329 "%% Create the peer-group or interface first\n");
4330 return CMD_WARNING_CONFIG_FAILED;
4331 }
4332 } else {
4333 snprintf(base_xpath, sizeof(base_xpath),
4334 FRR_BGP_NEIGHBOR_NUM_XPATH, argv[idx_peer]->arg, "");
4335 }
4336
4337 if (argv[idx_remote_as]->arg[0] == 'i') {
4338 as_type_str = "internal";
4339 } else if (argv[idx_remote_as]->arg[0] == 'e') {
4340 as_type_str = "external";
4341 } else {
4342 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as",
4343 NB_OP_MODIFY, argv[idx_remote_as]->arg);
4344 }
4345 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as-type",
4346 NB_OP_MODIFY, as_type_str);
4347
4348 return nb_cli_apply_changes(vty, base_xpath);
4349 }
4350
4351 int peer_conf_interface_create(struct bgp *bgp, const char *conf_if, afi_t afi,
4352 safi_t safi, bool v6only,
4353 const char *peer_group_name, int as_type,
4354 as_t as, char *errmsg, size_t errmsg_len)
4355 {
4356 struct peer *peer;
4357 struct peer_group *group;
4358 int ret = 0;
4359
4360 group = peer_group_lookup(bgp, conf_if);
4361
4362 if (group) {
4363 snprintf(errmsg, errmsg_len,
4364 "Name conflict with peer-group \n");
4365 return -1;
4366 }
4367
4368 peer = peer_lookup_by_conf_if(bgp, conf_if);
4369 if (peer) {
4370 if (as_type != AS_UNSPECIFIED)
4371 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type,
4372 afi, safi);
4373 } else {
4374 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4)
4375 && afi == AFI_IP && safi == SAFI_UNICAST)
4376 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
4377 as_type, 0, 0, NULL);
4378 else
4379 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
4380 as_type, afi, safi, NULL);
4381
4382 if (!peer) {
4383 snprintf(errmsg, errmsg_len,
4384 "BGP failed to create peer\n");
4385 return -1;
4386 }
4387
4388 if (v6only)
4389 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
4390
4391 /* Request zebra to initiate IPv6 RAs on this interface. We do
4392 * this
4393 * any unnumbered peer in order to not worry about run-time
4394 * transitions
4395 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
4396 * address
4397 * gets deleted later etc.)
4398 */
4399 if (peer->ifp)
4400 bgp_zebra_initiate_radv(bgp, peer);
4401 }
4402
4403 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
4404 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
4405 if (v6only)
4406 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
4407 else
4408 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
4409
4410 /* v6only flag changed. Reset bgp seesion */
4411 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
4412 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
4413 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
4414 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
4415 } else
4416 bgp_session_reset(peer);
4417 }
4418
4419 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
4420 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
4421 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
4422 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
4423 }
4424
4425 if (peer_group_name) {
4426 group = peer_group_lookup(bgp, peer_group_name);
4427 if (!group) {
4428 snprintf(errmsg, errmsg_len,
4429 "Configure the peer-group first\n");
4430 return -1;
4431 }
4432
4433 ret = peer_group_bind(bgp, NULL, peer, group, &as);
4434 }
4435
4436 return bgp_nb_errmsg_return(errmsg, errmsg_len, ret);
4437 }
4438
4439 DEFUN_YANG(neighbor_interface_config,
4440 neighbor_interface_config_cmd,
4441 "neighbor WORD interface [peer-group PGNAME]",
4442 NEIGHBOR_STR
4443 "Interface name or neighbor tag\n"
4444 "Enable BGP on interface\n"
4445 "Member of the peer-group\n"
4446 "Peer-group name\n")
4447 {
4448 int idx_word = 1;
4449 int idx_peer_group_word = 4;
4450 char base_xpath[XPATH_MAXLEN];
4451
4452 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4453 argv[idx_word]->arg, "");
4454
4455 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
4456 if (argc > idx_peer_group_word)
4457 nb_cli_enqueue_change(vty, "./peer-group", NB_OP_MODIFY,
4458 argv[idx_peer_group_word]->arg);
4459
4460 return nb_cli_apply_changes(vty, base_xpath);
4461 }
4462
4463 DEFUN_YANG(neighbor_interface_config_v6only,
4464 neighbor_interface_config_v6only_cmd,
4465 "neighbor WORD interface v6only [peer-group PGNAME]",
4466 NEIGHBOR_STR
4467 "Interface name or neighbor tag\n"
4468 "Enable BGP on interface\n"
4469 "Enable BGP with v6 link-local only\n"
4470 "Member of the peer-group\n"
4471 "Peer-group name\n")
4472 {
4473 int idx_word = 1;
4474 int idx_peer_group_word = 5;
4475 char base_xpath[XPATH_MAXLEN];
4476
4477 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4478 argv[idx_word]->arg, "");
4479
4480 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
4481 if (argc > idx_peer_group_word)
4482 nb_cli_enqueue_change(vty, "./peer-group", NB_OP_MODIFY,
4483 argv[idx_peer_group_word]->arg);
4484
4485 nb_cli_enqueue_change(vty, "./v6only", NB_OP_MODIFY, "true");
4486
4487 return nb_cli_apply_changes(vty, base_xpath);
4488 }
4489
4490
4491 DEFUN_YANG(
4492 neighbor_interface_config_remote_as,
4493 neighbor_interface_config_remote_as_cmd,
4494 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
4495 NEIGHBOR_STR
4496 "Interface name or neighbor tag\n"
4497 "Enable BGP on interface\n"
4498 "Specify a BGP neighbor\n" AS_STR
4499 "Internal BGP peer\n"
4500 "External BGP peer\n")
4501 {
4502 int idx_word = 1;
4503 int idx_remote_as = 4;
4504 char base_xpath[XPATH_MAXLEN];
4505 const char *as_type_str = "as-specified";
4506
4507 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4508 argv[idx_word]->arg, "");
4509
4510 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
4511
4512 if (argv[idx_remote_as]->arg[0] == 'i') {
4513 as_type_str = "internal";
4514 } else if (argv[idx_remote_as]->arg[0] == 'e') {
4515 as_type_str = "external";
4516 } else {
4517 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as",
4518 NB_OP_MODIFY, argv[idx_remote_as]->arg);
4519 }
4520 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as-type",
4521 NB_OP_MODIFY, as_type_str);
4522
4523 return nb_cli_apply_changes(vty, base_xpath);
4524 }
4525
4526 DEFUN_YANG(
4527 neighbor_interface_v6only_config_remote_as,
4528 neighbor_interface_v6only_config_remote_as_cmd,
4529 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
4530 NEIGHBOR_STR
4531 "Interface name or neighbor tag\n"
4532 "Enable BGP with v6 link-local only\n"
4533 "Enable BGP on interface\n"
4534 "Specify a BGP neighbor\n" AS_STR
4535 "Internal BGP peer\n"
4536 "External BGP peer\n")
4537 {
4538 int idx_word = 1;
4539 int idx_remote_as = 5;
4540 char base_xpath[XPATH_MAXLEN];
4541 const char *as_type_str = "as-specified";
4542
4543 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4544 argv[idx_word]->arg, "");
4545
4546 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
4547
4548 nb_cli_enqueue_change(vty, "./v6only", NB_OP_MODIFY, "true");
4549
4550 if (argv[idx_remote_as]->arg[0] == 'i') {
4551 as_type_str = "internal";
4552 } else if (argv[idx_remote_as]->arg[0] == 'e') {
4553 as_type_str = "external";
4554 } else {
4555 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as",
4556 NB_OP_MODIFY, argv[idx_remote_as]->arg);
4557 }
4558 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as-type",
4559 NB_OP_MODIFY, as_type_str);
4560
4561 return nb_cli_apply_changes(vty, base_xpath);
4562 }
4563
4564 DEFUN_YANG(neighbor_peer_group, neighbor_peer_group_cmd,
4565 "neighbor WORD peer-group",
4566 NEIGHBOR_STR
4567 "Interface name or neighbor tag\n"
4568 "Configure peer-group\n")
4569 {
4570 char base_xpath[XPATH_MAXLEN];
4571 int idx_word = 1;
4572
4573 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_PEER_GROUP_XPATH,
4574 argv[idx_word]->arg, "");
4575
4576 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
4577
4578 return nb_cli_apply_changes(vty, base_xpath);
4579 }
4580
4581 DEFUN_YANG(no_neighbor,
4582 no_neighbor_cmd,
4583 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
4584 NO_STR NEIGHBOR_STR
4585 NEIGHBOR_ADDR_STR2
4586 "Specify a BGP neighbor\n" AS_STR
4587 "Internal BGP peer\n"
4588 "External BGP peer\n")
4589 {
4590 int idx_peer = 2;
4591 char base_xpath[XPATH_MAXLEN];
4592 char num_xpath[XPATH_MAXLEN];
4593 char unnbr_xpath[XPATH_MAXLEN];
4594 char prgrp_xpath[XPATH_MAXLEN];
4595 union sockunion su;
4596
4597 if (str2sockunion(argv[idx_peer]->arg, &su) == 0) {
4598 snprintf(num_xpath, sizeof(num_xpath),
4599 FRR_BGP_NEIGHBOR_NUM_XPATH, argv[idx_peer]->arg, "");
4600 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
4601 VTY_CURR_XPATH, num_xpath + 1)) {
4602 strlcpy(base_xpath, num_xpath, sizeof(base_xpath));
4603 }
4604 } else {
4605 snprintf(unnbr_xpath, sizeof(unnbr_xpath),
4606 FRR_BGP_NEIGHBOR_UNNUM_XPATH, argv[idx_peer]->arg, "");
4607
4608 snprintf(prgrp_xpath, sizeof(prgrp_xpath),
4609 FRR_BGP_PEER_GROUP_XPATH, argv[idx_peer]->arg, "");
4610
4611 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
4612 VTY_CURR_XPATH, unnbr_xpath + 1)) {
4613 strlcpy(base_xpath, unnbr_xpath, sizeof(base_xpath));
4614 } else if (yang_dnode_exists(vty->candidate_config->dnode,
4615 "%s%s", VTY_CURR_XPATH,
4616 prgrp_xpath + 1)) {
4617 strlcpy(base_xpath, prgrp_xpath, sizeof(base_xpath));
4618 } else {
4619 vty_out(vty,
4620 "%% Create the peer-group or interface first\n");
4621 return CMD_WARNING_CONFIG_FAILED;
4622 }
4623 }
4624
4625 nb_cli_enqueue_change(vty, base_xpath, NB_OP_DESTROY, NULL);
4626
4627 return nb_cli_apply_changes(vty, NULL);
4628 }
4629
4630 DEFUN_YANG(no_neighbor_interface_config,
4631 no_neighbor_interface_config_cmd,
4632 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
4633 NO_STR NEIGHBOR_STR
4634 "Interface name\n"
4635 "Configure BGP on interface\n"
4636 "Enable BGP with v6 link-local only\n"
4637 "Member of the peer-group\n"
4638 "Peer-group name\n"
4639 "Specify a BGP neighbor\n" AS_STR
4640 "Internal BGP peer\n"
4641 "External BGP peer\n")
4642 {
4643 int idx_word = 2;
4644 char base_xpath[XPATH_MAXLEN];
4645
4646 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4647 argv[idx_word]->arg, "");
4648
4649 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
4650
4651 return nb_cli_apply_changes(vty, base_xpath);
4652 }
4653
4654 DEFUN_YANG(no_neighbor_peer_group,
4655 no_neighbor_peer_group_cmd,
4656 "no neighbor WORD peer-group",
4657 NO_STR NEIGHBOR_STR
4658 "Neighbor tag\n"
4659 "Configure peer-group\n")
4660 {
4661 char base_xpath[XPATH_MAXLEN];
4662 int idx_word = 2;
4663
4664 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_PEER_GROUP_XPATH,
4665 argv[idx_word]->arg, "");
4666
4667 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
4668
4669 return nb_cli_apply_changes(vty, base_xpath);
4670 }
4671
4672 DEFUN_YANG(no_neighbor_interface_peer_group_remote_as,
4673 no_neighbor_interface_peer_group_remote_as_cmd,
4674 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
4675 NO_STR NEIGHBOR_STR
4676 "Interface name or neighbor tag\n"
4677 "Specify a BGP neighbor\n" AS_STR
4678 "Internal BGP peer\n"
4679 "External BGP peer\n")
4680 {
4681 int idx_peer = 2;
4682 char base_xpath[XPATH_MAXLEN];
4683 char unnbr_xpath[XPATH_MAXLEN];
4684 char prgrp_xpath[XPATH_MAXLEN];
4685
4686 snprintf(unnbr_xpath, sizeof(unnbr_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4687 argv[idx_peer]->arg, "");
4688
4689 snprintf(prgrp_xpath, sizeof(prgrp_xpath), FRR_BGP_PEER_GROUP_XPATH,
4690 argv[idx_peer]->arg, "");
4691
4692 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
4693 VTY_CURR_XPATH, unnbr_xpath + 1)) {
4694 strlcpy(base_xpath, unnbr_xpath, sizeof(base_xpath));
4695 } else if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
4696 VTY_CURR_XPATH, prgrp_xpath + 1)) {
4697 strlcpy(base_xpath, prgrp_xpath, sizeof(base_xpath));
4698 } else {
4699 vty_out(vty, "%% Create the peer-group or interface first\n");
4700 return CMD_WARNING_CONFIG_FAILED;
4701 }
4702
4703 strlcat(base_xpath, "/neighbor-remote-as/remote-as-type",
4704 sizeof(base_xpath));
4705
4706 nb_cli_enqueue_change(vty, base_xpath, NB_OP_DESTROY, NULL);
4707
4708 return nb_cli_apply_changes(vty, NULL);
4709 }
4710
4711 DEFUN_YANG(neighbor_local_as,
4712 neighbor_local_as_cmd,
4713 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
4714 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4715 "Specify a local-as number\n"
4716 "AS number used as local AS\n")
4717 {
4718 int idx_peer = 1;
4719 int idx_number = 3;
4720 char base_xpath[XPATH_MAXLEN];
4721
4722 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4723 sizeof(base_xpath), NULL)
4724 < 0)
4725 return CMD_WARNING_CONFIG_FAILED;
4726
4727 nb_cli_enqueue_change(vty, "./local-as/local-as", NB_OP_MODIFY,
4728 argv[idx_number]->arg);
4729
4730 return nb_cli_apply_changes(vty, base_xpath);
4731 }
4732
4733 DEFUN_YANG(
4734 neighbor_local_as_no_prepend, neighbor_local_as_no_prepend_cmd,
4735 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
4736 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4737 "Specify a local-as number\n"
4738 "AS number used as local AS\n"
4739 "Do not prepend local-as to updates from ebgp peers\n")
4740 {
4741 int idx_peer = 1;
4742 int idx_number = 3;
4743 char base_xpath[XPATH_MAXLEN];
4744
4745 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4746 sizeof(base_xpath), NULL)
4747 < 0)
4748 return CMD_WARNING_CONFIG_FAILED;
4749
4750 nb_cli_enqueue_change(vty, "./local-as/local-as", NB_OP_MODIFY,
4751 argv[idx_number]->arg);
4752 nb_cli_enqueue_change(vty, "./local-as/no-prepend", NB_OP_MODIFY,
4753 "true");
4754
4755 return nb_cli_apply_changes(vty, base_xpath);
4756 }
4757
4758 DEFUN_YANG(
4759 neighbor_local_as_no_prepend_replace_as,
4760 neighbor_local_as_no_prepend_replace_as_cmd,
4761 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
4762 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4763 "Specify a local-as number\n"
4764 "AS number used as local AS\n"
4765 "Do not prepend local-as to updates from ebgp peers\n"
4766 "Do not prepend local-as to updates from ibgp peers\n")
4767 {
4768 int idx_peer = 1;
4769 int idx_number = 3;
4770 char base_xpath[XPATH_MAXLEN];
4771
4772 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4773 sizeof(base_xpath), NULL)
4774 < 0)
4775 return CMD_WARNING_CONFIG_FAILED;
4776
4777 nb_cli_enqueue_change(vty, "./local-as/local-as", NB_OP_MODIFY,
4778 argv[idx_number]->arg);
4779 nb_cli_enqueue_change(vty, "./local-as/no-prepend", NB_OP_MODIFY,
4780 "true");
4781 nb_cli_enqueue_change(vty, "./local-as/no-replace-as", NB_OP_MODIFY,
4782 "true");
4783
4784 return nb_cli_apply_changes(vty, base_xpath);
4785 }
4786
4787 DEFUN_YANG(no_neighbor_local_as,
4788 no_neighbor_local_as_cmd,
4789 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
4790 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4791 "Specify a local-as number\n"
4792 "AS number used as local AS\n"
4793 "Do not prepend local-as to updates from ebgp peers\n"
4794 "Do not prepend local-as to updates from ibgp peers\n")
4795 {
4796 int idx_peer = 2;
4797 char base_xpath[XPATH_MAXLEN];
4798
4799 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4800 sizeof(base_xpath), NULL)
4801 < 0)
4802 return CMD_WARNING_CONFIG_FAILED;
4803
4804 nb_cli_enqueue_change(vty, "./local-as/local-as", NB_OP_DESTROY, NULL);
4805 nb_cli_enqueue_change(vty, "./local-as/no-prepend", NB_OP_MODIFY,
4806 "false");
4807 nb_cli_enqueue_change(vty, "./local-as/no-replace-as", NB_OP_MODIFY,
4808 "false");
4809
4810 return nb_cli_apply_changes(vty, base_xpath);
4811 }
4812
4813
4814 DEFUN (neighbor_solo,
4815 neighbor_solo_cmd,
4816 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
4817 NEIGHBOR_STR
4818 NEIGHBOR_ADDR_STR2
4819 "Solo peer - part of its own update group\n")
4820 {
4821 int idx_peer = 1;
4822 struct peer *peer;
4823 int ret;
4824
4825 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4826 if (!peer)
4827 return CMD_WARNING_CONFIG_FAILED;
4828
4829 ret = update_group_adjust_soloness(peer, 1);
4830 return bgp_vty_return(vty, ret);
4831 }
4832
4833 DEFUN (no_neighbor_solo,
4834 no_neighbor_solo_cmd,
4835 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
4836 NO_STR
4837 NEIGHBOR_STR
4838 NEIGHBOR_ADDR_STR2
4839 "Solo peer - part of its own update group\n")
4840 {
4841 int idx_peer = 2;
4842 struct peer *peer;
4843 int ret;
4844
4845 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4846 if (!peer)
4847 return CMD_WARNING_CONFIG_FAILED;
4848
4849 ret = update_group_adjust_soloness(peer, 0);
4850 return bgp_vty_return(vty, ret);
4851 }
4852
4853 DEFUN_YANG(neighbor_password,
4854 neighbor_password_cmd,
4855 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
4856 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4857 "Set a password\n"
4858 "The password\n")
4859 {
4860 int idx_peer = 1;
4861 int idx_line = 3;
4862 char base_xpath[XPATH_MAXLEN];
4863
4864 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4865 sizeof(base_xpath), NULL)
4866 < 0)
4867 return CMD_WARNING_CONFIG_FAILED;
4868
4869 nb_cli_enqueue_change(vty, "./password", NB_OP_MODIFY,
4870 argv[idx_line]->arg);
4871
4872 return nb_cli_apply_changes(vty, base_xpath);
4873 }
4874
4875 DEFUN_YANG(no_neighbor_password,
4876 no_neighbor_password_cmd,
4877 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
4878 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4879 "Set a password\n"
4880 "The password\n")
4881 {
4882 int idx_peer = 2;
4883 char base_xpath[XPATH_MAXLEN];
4884
4885 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4886 sizeof(base_xpath), NULL)
4887 < 0)
4888 return CMD_WARNING_CONFIG_FAILED;
4889
4890 nb_cli_enqueue_change(vty, "./password", NB_OP_DESTROY, NULL);
4891
4892 return nb_cli_apply_changes(vty, base_xpath);
4893 }
4894
4895 DEFUN_YANG(neighbor_activate,
4896 neighbor_activate_cmd,
4897 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4898 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4899 "Enable the Address Family for this Neighbor\n")
4900 {
4901 int idx_peer = 1;
4902 char base_xpath[XPATH_MAXLEN];
4903 char af_xpath[XPATH_MAXLEN];
4904 afi_t afi = bgp_node_afi(vty);
4905 safi_t safi = bgp_node_safi(vty);
4906
4907 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
4908 yang_afi_safi_value2identity(afi, safi));
4909 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4910 sizeof(base_xpath), af_xpath)
4911 < 0)
4912 return CMD_WARNING_CONFIG_FAILED;
4913
4914 nb_cli_enqueue_change(vty, "./enabled", NB_OP_MODIFY, "true");
4915
4916 return nb_cli_apply_changes(vty, base_xpath);
4917 }
4918
4919 ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
4920 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4921 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4922 "Enable the Address Family for this Neighbor\n")
4923
4924 DEFUN_YANG(no_neighbor_activate,
4925 no_neighbor_activate_cmd,
4926 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4927 NO_STR NEIGHBOR_STR
4928 NEIGHBOR_ADDR_STR2
4929 "Enable the Address Family for this Neighbor\n")
4930 {
4931 int idx_peer = 2;
4932 char base_xpath[XPATH_MAXLEN];
4933 char af_xpath[XPATH_MAXLEN];
4934 afi_t afi = bgp_node_afi(vty);
4935 safi_t safi = bgp_node_safi(vty);
4936
4937 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
4938 yang_afi_safi_value2identity(afi, safi));
4939
4940 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4941 sizeof(base_xpath), af_xpath)
4942 < 0)
4943 return CMD_WARNING_CONFIG_FAILED;
4944
4945 nb_cli_enqueue_change(vty, "./enabled", NB_OP_MODIFY, "false");
4946
4947 return nb_cli_apply_changes(vty, base_xpath);
4948 }
4949
4950 ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
4951 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4952 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4953 "Enable the Address Family for this Neighbor\n")
4954
4955 DEFUN (neighbor_set_peer_group,
4956 neighbor_set_peer_group_cmd,
4957 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
4958 NEIGHBOR_STR
4959 NEIGHBOR_ADDR_STR2
4960 "Member of the peer-group\n"
4961 "Peer-group name\n")
4962 {
4963 VTY_DECLVAR_CONTEXT(bgp, bgp);
4964 int idx_peer = 1;
4965 int idx_word = 3;
4966 int ret;
4967 as_t as;
4968 union sockunion su;
4969 struct peer *peer;
4970 struct peer_group *group;
4971
4972 ret = str2sockunion(argv[idx_peer]->arg, &su);
4973 if (ret < 0) {
4974 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4975 if (!peer) {
4976 vty_out(vty, "%% Malformed address or name: %s\n",
4977 argv[idx_peer]->arg);
4978 return CMD_WARNING_CONFIG_FAILED;
4979 }
4980 } else {
4981 if (peer_address_self_check(bgp, &su)) {
4982 vty_out(vty,
4983 "%% Can not configure the local system as neighbor\n");
4984 return CMD_WARNING_CONFIG_FAILED;
4985 }
4986
4987 /* Disallow for dynamic neighbor. */
4988 peer = peer_lookup(bgp, &su);
4989 if (peer && peer_dynamic_neighbor(peer)) {
4990 vty_out(vty,
4991 "%% Operation not allowed on a dynamic neighbor\n");
4992 return CMD_WARNING_CONFIG_FAILED;
4993 }
4994 }
4995
4996 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4997 if (!group) {
4998 vty_out(vty, "%% Configure the peer-group first\n");
4999 return CMD_WARNING_CONFIG_FAILED;
5000 }
5001
5002 ret = peer_group_bind(bgp, &su, peer, group, &as);
5003
5004 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
5005 vty_out(vty,
5006 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
5007 as);
5008 return CMD_WARNING_CONFIG_FAILED;
5009 }
5010
5011 return bgp_vty_return(vty, ret);
5012 }
5013
5014 ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
5015 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5016 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5017 "Member of the peer-group\n"
5018 "Peer-group name\n")
5019
5020 DEFUN_YANG (no_neighbor_set_peer_group,
5021 no_neighbor_set_peer_group_cmd,
5022 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5023 NO_STR
5024 NEIGHBOR_STR
5025 NEIGHBOR_ADDR_STR2
5026 "Member of the peer-group\n"
5027 "Peer-group name\n")
5028 {
5029 int idx_peer = 2;
5030 char base_xpath[XPATH_MAXLEN];
5031
5032 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5033 sizeof(base_xpath), NULL)
5034 < 0)
5035 return CMD_WARNING_CONFIG_FAILED;
5036
5037 nb_cli_enqueue_change(vty, "./peer-group", NB_OP_DESTROY, NULL);
5038
5039 return nb_cli_apply_changes(vty, base_xpath);
5040 }
5041
5042 ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
5043 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5044 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5045 "Member of the peer-group\n"
5046 "Peer-group name\n")
5047
5048 static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
5049 uint32_t flag, int set)
5050 {
5051 int ret;
5052 struct peer *peer;
5053
5054 peer = peer_and_group_lookup_vty(vty, ip_str);
5055 if (!peer)
5056 return CMD_WARNING_CONFIG_FAILED;
5057
5058 /*
5059 * If 'neighbor <interface>', then this is for directly connected peers,
5060 * we should not accept disable-connected-check.
5061 */
5062 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
5063 vty_out(vty,
5064 "%s is directly connected peer, cannot accept disable-connected-check\n",
5065 ip_str);
5066 return CMD_WARNING_CONFIG_FAILED;
5067 }
5068
5069 if (!set && flag == PEER_FLAG_SHUTDOWN)
5070 peer_tx_shutdown_message_unset(peer);
5071
5072 if (set)
5073 ret = peer_flag_set(peer, flag);
5074 else
5075 ret = peer_flag_unset(peer, flag);
5076
5077 return bgp_vty_return(vty, ret);
5078 }
5079
5080 static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
5081 {
5082 return peer_flag_modify_vty(vty, ip_str, flag, 1);
5083 }
5084
5085 static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
5086 uint32_t flag)
5087 {
5088 return peer_flag_modify_vty(vty, ip_str, flag, 0);
5089 }
5090
5091 int peer_flag_modify_nb(struct bgp *bgp, const char *ip_str, struct peer *peer,
5092 uint32_t flag, bool set, char *errmsg,
5093 size_t errmsg_len)
5094 {
5095 int ret;
5096
5097 /*
5098 * If 'neighbor <interface>', then this is for directly connected peers,
5099 * we should not accept disable-connected-check.
5100 */
5101 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
5102 snprintf(
5103 errmsg, errmsg_len,
5104 "%s is directly connected peer, cannot accept disable-connected-check\n",
5105 ip_str);
5106 return -1;
5107 }
5108
5109 if (!set && flag == PEER_FLAG_SHUTDOWN)
5110 peer_tx_shutdown_message_unset(peer);
5111
5112 if (set)
5113 ret = peer_flag_set(peer, flag);
5114 else
5115 ret = peer_flag_unset(peer, flag);
5116
5117 return bgp_nb_errmsg_return(errmsg, errmsg_len, ret);
5118 }
5119
5120 /* neighbor passive. */
5121 DEFUN_YANG(neighbor_passive,
5122 neighbor_passive_cmd,
5123 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5124 NEIGHBOR_STR
5125 NEIGHBOR_ADDR_STR2
5126 "Don't send open messages to this neighbor\n")
5127 {
5128 int idx_peer = 1;
5129 char base_xpath[XPATH_MAXLEN];
5130
5131 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5132 sizeof(base_xpath), NULL)
5133 < 0)
5134 return CMD_WARNING_CONFIG_FAILED;
5135
5136 nb_cli_enqueue_change(vty, "./passive-mode", NB_OP_MODIFY, "true");
5137
5138 return nb_cli_apply_changes(vty, base_xpath);
5139 }
5140
5141 DEFUN_YANG(no_neighbor_passive,
5142 no_neighbor_passive_cmd,
5143 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5144 NO_STR NEIGHBOR_STR
5145 NEIGHBOR_ADDR_STR2
5146 "Don't send open messages to this neighbor\n")
5147 {
5148 int idx_peer = 2;
5149 char base_xpath[XPATH_MAXLEN];
5150
5151 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5152 sizeof(base_xpath), NULL)
5153 < 0)
5154 return CMD_WARNING_CONFIG_FAILED;
5155
5156 nb_cli_enqueue_change(vty, "./passive-mode", NB_OP_MODIFY, "false");
5157
5158 return nb_cli_apply_changes(vty, base_xpath);
5159 }
5160
5161 /* neighbor shutdown. */
5162 DEFUN_YANG(neighbor_shutdown_msg,
5163 neighbor_shutdown_msg_cmd,
5164 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5165 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5166 "Administratively shut down this neighbor\n"
5167 "Add a shutdown message (RFC 8203)\n"
5168 "Shutdown message\n")
5169 {
5170 int idx_peer = 1;
5171 char base_xpath[XPATH_MAXLEN];
5172
5173 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5174 sizeof(base_xpath), NULL)
5175 < 0)
5176 return CMD_WARNING_CONFIG_FAILED;
5177
5178 if (argc >= 5) {
5179 char *message;
5180
5181 message = argv_concat(argv, argc, 4);
5182 nb_cli_enqueue_change(vty, "./admin-shutdown/message",
5183 NB_OP_MODIFY, message);
5184 }
5185
5186 nb_cli_enqueue_change(vty, "./admin-shutdown/enable", NB_OP_MODIFY,
5187 "true");
5188
5189 return nb_cli_apply_changes(vty, base_xpath);
5190 }
5191
5192 ALIAS_YANG(neighbor_shutdown_msg, neighbor_shutdown_cmd,
5193 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5194 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5195 "Administratively shut down this neighbor\n")
5196
5197 DEFUN_YANG(no_neighbor_shutdown_msg,
5198 no_neighbor_shutdown_msg_cmd,
5199 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5200 NO_STR NEIGHBOR_STR
5201 NEIGHBOR_ADDR_STR2
5202 "Administratively shut down this neighbor\n"
5203 "Remove a shutdown message (RFC 8203)\n"
5204 "Shutdown message\n")
5205 {
5206 int idx_peer = 2;
5207 char base_xpath[XPATH_MAXLEN];
5208
5209 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5210 sizeof(base_xpath), NULL)
5211 < 0)
5212 return CMD_WARNING_CONFIG_FAILED;
5213
5214 nb_cli_enqueue_change(vty, "./admin-shutdown/enable", NB_OP_MODIFY,
5215 "false");
5216
5217 return nb_cli_apply_changes(vty, base_xpath);
5218 }
5219
5220 ALIAS_YANG(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
5221 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5222 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5223 "Administratively shut down this neighbor\n")
5224
5225 DEFUN(neighbor_shutdown_rtt,
5226 neighbor_shutdown_rtt_cmd,
5227 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt (1-65535) [count (1-255)]",
5228 NEIGHBOR_STR
5229 NEIGHBOR_ADDR_STR2
5230 "Administratively shut down this neighbor\n"
5231 "Shutdown if round-trip-time is higher than expected\n"
5232 "Round-trip-time in milliseconds\n"
5233 "Specify the number of keepalives before shutdown\n"
5234 "The number of keepalives with higher RTT to shutdown\n")
5235 {
5236 int idx_peer = 1;
5237 int idx_rtt = 4;
5238 int idx_count = 0;
5239 struct peer *peer;
5240
5241 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5242
5243 if (!peer)
5244 return CMD_WARNING_CONFIG_FAILED;
5245
5246 peer->rtt_expected = strtol(argv[idx_rtt]->arg, NULL, 10);
5247
5248 if (argv_find(argv, argc, "count", &idx_count))
5249 peer->rtt_keepalive_conf =
5250 strtol(argv[idx_count + 1]->arg, NULL, 10);
5251
5252 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5253 PEER_FLAG_RTT_SHUTDOWN);
5254 }
5255
5256 DEFUN(no_neighbor_shutdown_rtt,
5257 no_neighbor_shutdown_rtt_cmd,
5258 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt [(1-65535) [count (1-255)]]",
5259 NO_STR
5260 NEIGHBOR_STR
5261 NEIGHBOR_ADDR_STR2
5262 "Administratively shut down this neighbor\n"
5263 "Shutdown if round-trip-time is higher than expected\n"
5264 "Round-trip-time in milliseconds\n"
5265 "Specify the number of keepalives before shutdown\n"
5266 "The number of keepalives with higher RTT to shutdown\n")
5267 {
5268 int idx_peer = 2;
5269 struct peer *peer;
5270
5271 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5272
5273 if (!peer)
5274 return CMD_WARNING_CONFIG_FAILED;
5275
5276 peer->rtt_expected = 0;
5277 peer->rtt_keepalive_conf = 1;
5278
5279 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5280 PEER_FLAG_RTT_SHUTDOWN);
5281 }
5282
5283 /* neighbor capability dynamic. */
5284 DEFUN_YANG (neighbor_capability_dynamic,
5285 neighbor_capability_dynamic_cmd,
5286 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5287 NEIGHBOR_STR
5288 NEIGHBOR_ADDR_STR2
5289 "Advertise capability to the peer\n"
5290 "Advertise dynamic capability to this neighbor\n")
5291 {
5292 int idx_peer = 1;
5293 char base_xpath[XPATH_MAXLEN];
5294
5295 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5296 sizeof(base_xpath), NULL)
5297 < 0)
5298 return CMD_WARNING_CONFIG_FAILED;
5299
5300 nb_cli_enqueue_change(vty, "./capability-options/dynamic-capability",
5301 NB_OP_MODIFY, "true");
5302
5303 return nb_cli_apply_changes(vty, base_xpath);
5304 }
5305
5306 DEFUN_YANG (no_neighbor_capability_dynamic,
5307 no_neighbor_capability_dynamic_cmd,
5308 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5309 NO_STR
5310 NEIGHBOR_STR
5311 NEIGHBOR_ADDR_STR2
5312 "Advertise capability to the peer\n"
5313 "Advertise dynamic capability to this neighbor\n")
5314 {
5315 int idx_peer = 2;
5316 char base_xpath[XPATH_MAXLEN];
5317
5318 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5319 sizeof(base_xpath), NULL)
5320 < 0)
5321 return CMD_WARNING_CONFIG_FAILED;
5322
5323 nb_cli_enqueue_change(vty, "./capability-options/dynamic-capability",
5324 NB_OP_MODIFY, "false");
5325
5326 return nb_cli_apply_changes(vty, base_xpath);
5327 }
5328
5329 /* neighbor dont-capability-negotiate */
5330 DEFUN (neighbor_dont_capability_negotiate,
5331 neighbor_dont_capability_negotiate_cmd,
5332 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
5333 NEIGHBOR_STR
5334 NEIGHBOR_ADDR_STR2
5335 "Do not perform capability negotiation\n")
5336 {
5337 int idx_peer = 1;
5338 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5339 PEER_FLAG_DONT_CAPABILITY);
5340 }
5341
5342 DEFUN (no_neighbor_dont_capability_negotiate,
5343 no_neighbor_dont_capability_negotiate_cmd,
5344 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
5345 NO_STR
5346 NEIGHBOR_STR
5347 NEIGHBOR_ADDR_STR2
5348 "Do not perform capability negotiation\n")
5349 {
5350 int idx_peer = 2;
5351 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5352 PEER_FLAG_DONT_CAPABILITY);
5353 }
5354
5355 /* neighbor capability extended next hop encoding */
5356 DEFUN_YANG (neighbor_capability_enhe,
5357 neighbor_capability_enhe_cmd,
5358 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5359 NEIGHBOR_STR
5360 NEIGHBOR_ADDR_STR2
5361 "Advertise capability to the peer\n"
5362 "Advertise extended next-hop capability to the peer\n")
5363 {
5364 int idx_peer = 1;
5365 char base_xpath[XPATH_MAXLEN];
5366
5367 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5368 sizeof(base_xpath), NULL)
5369 < 0)
5370 return CMD_WARNING_CONFIG_FAILED;
5371
5372 nb_cli_enqueue_change(
5373 vty, "./capability-options/extended-nexthop-capability",
5374 NB_OP_MODIFY, "true");
5375
5376 return nb_cli_apply_changes(vty, base_xpath);
5377 }
5378
5379 DEFUN_YANG (no_neighbor_capability_enhe,
5380 no_neighbor_capability_enhe_cmd,
5381 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5382 NO_STR
5383 NEIGHBOR_STR
5384 NEIGHBOR_ADDR_STR2
5385 "Advertise capability to the peer\n"
5386 "Advertise extended next-hop capability to the peer\n")
5387 {
5388 int idx_peer = 2;
5389 char base_xpath[XPATH_MAXLEN];
5390
5391 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5392 sizeof(base_xpath), NULL)
5393 < 0)
5394 return CMD_WARNING_CONFIG_FAILED;
5395
5396 nb_cli_enqueue_change(
5397 vty, "./capability-options/extended-nexthop-capability",
5398 NB_OP_MODIFY, "false");
5399
5400 return nb_cli_apply_changes(vty, base_xpath);
5401 }
5402
5403 int peer_af_flag_modify_nb(struct peer *peer, afi_t afi, safi_t safi,
5404 uint32_t flag, int set, char *errmsg,
5405 size_t errmsg_len)
5406 {
5407 int ret;
5408
5409 if (set)
5410 ret = peer_af_flag_set(peer, afi, safi, flag);
5411 else
5412 ret = peer_af_flag_unset(peer, afi, safi, flag);
5413
5414 return bgp_nb_errmsg_return(errmsg, errmsg_len, ret);
5415 }
5416
5417 static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
5418 afi_t afi, safi_t safi, uint32_t flag,
5419 int set)
5420 {
5421 int ret;
5422 struct peer *peer;
5423
5424 peer = peer_and_group_lookup_vty(vty, peer_str);
5425 if (!peer)
5426 return CMD_WARNING_CONFIG_FAILED;
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_vty_return(vty, ret);
5434 }
5435
5436 static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
5437 afi_t afi, safi_t safi, uint32_t flag)
5438 {
5439 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
5440 }
5441
5442 static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
5443 afi_t afi, safi_t safi, uint32_t flag)
5444 {
5445 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
5446 }
5447
5448 /* neighbor capability orf prefix-list. */
5449 DEFUN (neighbor_capability_orf_prefix,
5450 neighbor_capability_orf_prefix_cmd,
5451 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5452 NEIGHBOR_STR
5453 NEIGHBOR_ADDR_STR2
5454 "Advertise capability to the peer\n"
5455 "Advertise ORF capability to the peer\n"
5456 "Advertise prefixlist ORF capability to this neighbor\n"
5457 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5458 "Capability to RECEIVE the ORF from this neighbor\n"
5459 "Capability to SEND the ORF to this neighbor\n")
5460 {
5461 int idx_send_recv = 5;
5462 char *peer_str = argv[1]->arg;
5463 struct peer *peer;
5464 afi_t afi = bgp_node_afi(vty);
5465 safi_t safi = bgp_node_safi(vty);
5466
5467 peer = peer_and_group_lookup_vty(vty, peer_str);
5468 if (!peer)
5469 return CMD_WARNING_CONFIG_FAILED;
5470
5471 if (strmatch(argv[idx_send_recv]->text, "send"))
5472 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5473 PEER_FLAG_ORF_PREFIX_SM);
5474
5475 if (strmatch(argv[idx_send_recv]->text, "receive"))
5476 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5477 PEER_FLAG_ORF_PREFIX_RM);
5478
5479 if (strmatch(argv[idx_send_recv]->text, "both"))
5480 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5481 PEER_FLAG_ORF_PREFIX_SM)
5482 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5483 PEER_FLAG_ORF_PREFIX_RM);
5484
5485 return CMD_WARNING_CONFIG_FAILED;
5486 }
5487
5488 ALIAS_HIDDEN(
5489 neighbor_capability_orf_prefix,
5490 neighbor_capability_orf_prefix_hidden_cmd,
5491 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5492 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5493 "Advertise capability to the peer\n"
5494 "Advertise ORF capability to the peer\n"
5495 "Advertise prefixlist ORF capability to this neighbor\n"
5496 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5497 "Capability to RECEIVE the ORF from this neighbor\n"
5498 "Capability to SEND the ORF to this neighbor\n")
5499
5500 DEFUN (no_neighbor_capability_orf_prefix,
5501 no_neighbor_capability_orf_prefix_cmd,
5502 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5503 NO_STR
5504 NEIGHBOR_STR
5505 NEIGHBOR_ADDR_STR2
5506 "Advertise capability to the peer\n"
5507 "Advertise ORF capability to the peer\n"
5508 "Advertise prefixlist ORF capability to this neighbor\n"
5509 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5510 "Capability to RECEIVE the ORF from this neighbor\n"
5511 "Capability to SEND the ORF to this neighbor\n")
5512 {
5513 int idx_send_recv = 6;
5514 char *peer_str = argv[2]->arg;
5515 struct peer *peer;
5516 afi_t afi = bgp_node_afi(vty);
5517 safi_t safi = bgp_node_safi(vty);
5518
5519 peer = peer_and_group_lookup_vty(vty, peer_str);
5520 if (!peer)
5521 return CMD_WARNING_CONFIG_FAILED;
5522
5523 if (strmatch(argv[idx_send_recv]->text, "send"))
5524 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5525 PEER_FLAG_ORF_PREFIX_SM);
5526
5527 if (strmatch(argv[idx_send_recv]->text, "receive"))
5528 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5529 PEER_FLAG_ORF_PREFIX_RM);
5530
5531 if (strmatch(argv[idx_send_recv]->text, "both"))
5532 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5533 PEER_FLAG_ORF_PREFIX_SM)
5534 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5535 PEER_FLAG_ORF_PREFIX_RM);
5536
5537 return CMD_WARNING_CONFIG_FAILED;
5538 }
5539
5540 ALIAS_HIDDEN(
5541 no_neighbor_capability_orf_prefix,
5542 no_neighbor_capability_orf_prefix_hidden_cmd,
5543 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5544 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5545 "Advertise capability to the peer\n"
5546 "Advertise ORF capability to the peer\n"
5547 "Advertise prefixlist ORF capability to this neighbor\n"
5548 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5549 "Capability to RECEIVE the ORF from this neighbor\n"
5550 "Capability to SEND the ORF to this neighbor\n")
5551
5552 /* neighbor next-hop-self. */
5553 DEFUN_YANG (neighbor_nexthop_self,
5554 neighbor_nexthop_self_cmd,
5555 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5556 NEIGHBOR_STR
5557 NEIGHBOR_ADDR_STR2
5558 "Disable the next hop calculation for this neighbor\n")
5559 {
5560 int idx_peer = 1;
5561 char base_xpath[XPATH_MAXLEN];
5562 char af_xpath[XPATH_MAXLEN];
5563 char attr_xpath[XPATH_MAXLEN];
5564 afi_t afi = bgp_node_afi(vty);
5565 safi_t safi = bgp_node_safi(vty);
5566
5567
5568 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5569 yang_afi_safi_value2identity(afi, safi));
5570
5571 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5572 sizeof(base_xpath), af_xpath)
5573 < 0)
5574 return CMD_WARNING_CONFIG_FAILED;
5575
5576 snprintf(attr_xpath, sizeof(attr_xpath),
5577 "./%s/nexthop-self/next-hop-self",
5578 bgp_afi_safi_get_container_str(afi, safi));
5579
5580 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5581
5582 return nb_cli_apply_changes(vty, base_xpath);
5583 }
5584
5585 ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
5586 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5587 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5588 "Disable the next hop calculation for this neighbor\n")
5589
5590 /* neighbor next-hop-self. */
5591 DEFUN_YANG(neighbor_nexthop_self_force,
5592 neighbor_nexthop_self_force_cmd,
5593 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5594 NEIGHBOR_STR
5595 NEIGHBOR_ADDR_STR2
5596 "Disable the next hop calculation for this neighbor\n"
5597 "Set the next hop to self for reflected routes\n")
5598 {
5599 int idx_peer = 1;
5600 char base_xpath[XPATH_MAXLEN];
5601 char af_xpath[XPATH_MAXLEN];
5602 char attr_xpath[XPATH_MAXLEN];
5603 afi_t afi = bgp_node_afi(vty);
5604 safi_t safi = bgp_node_safi(vty);
5605
5606
5607 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5608 yang_afi_safi_value2identity(afi, safi));
5609
5610 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5611 sizeof(base_xpath), af_xpath)
5612 < 0)
5613 return CMD_WARNING_CONFIG_FAILED;
5614
5615 snprintf(attr_xpath, sizeof(attr_xpath),
5616 "./%s/nexthop-self/next-hop-self-force",
5617 bgp_afi_safi_get_container_str(afi, safi));
5618
5619 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5620
5621 return nb_cli_apply_changes(vty, base_xpath);
5622 }
5623
5624 ALIAS_HIDDEN(neighbor_nexthop_self_force,
5625 neighbor_nexthop_self_force_hidden_cmd,
5626 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5627 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5628 "Disable the next hop calculation for this neighbor\n"
5629 "Set the next hop to self for reflected routes\n")
5630
5631 ALIAS_HIDDEN(neighbor_nexthop_self_force,
5632 neighbor_nexthop_self_all_hidden_cmd,
5633 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5634 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5635 "Disable the next hop calculation for this neighbor\n"
5636 "Set the next hop to self for reflected routes\n")
5637
5638 DEFUN_YANG (no_neighbor_nexthop_self,
5639 no_neighbor_nexthop_self_cmd,
5640 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5641 NO_STR
5642 NEIGHBOR_STR
5643 NEIGHBOR_ADDR_STR2
5644 "Disable the next hop calculation for this neighbor\n")
5645 {
5646 int idx_peer = 2;
5647 char base_xpath[XPATH_MAXLEN];
5648 char af_xpath[XPATH_MAXLEN];
5649 char attr_xpath[XPATH_MAXLEN];
5650 afi_t afi = bgp_node_afi(vty);
5651 safi_t safi = bgp_node_safi(vty);
5652
5653 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5654 yang_afi_safi_value2identity(afi, safi));
5655
5656 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5657 sizeof(base_xpath), af_xpath)
5658 < 0)
5659 return CMD_WARNING_CONFIG_FAILED;
5660
5661 snprintf(attr_xpath, sizeof(attr_xpath),
5662 "./%s/nexthop-self/next-hop-self",
5663 bgp_afi_safi_get_container_str(afi, safi));
5664
5665 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5666
5667 return nb_cli_apply_changes(vty, base_xpath);
5668 }
5669
5670 ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
5671 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5672 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5673 "Disable the next hop calculation for this neighbor\n")
5674
5675 DEFUN_YANG (no_neighbor_nexthop_self_force,
5676 no_neighbor_nexthop_self_force_cmd,
5677 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5678 NO_STR
5679 NEIGHBOR_STR
5680 NEIGHBOR_ADDR_STR2
5681 "Disable the next hop calculation for this neighbor\n"
5682 "Set the next hop to self for reflected routes\n")
5683 {
5684 int idx_peer = 2;
5685 char base_xpath[XPATH_MAXLEN];
5686 char af_xpath[XPATH_MAXLEN];
5687 char attr_xpath[XPATH_MAXLEN];
5688 afi_t afi = bgp_node_afi(vty);
5689 safi_t safi = bgp_node_safi(vty);
5690
5691
5692 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5693 yang_afi_safi_value2identity(afi, safi));
5694
5695 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5696 sizeof(base_xpath), af_xpath)
5697 < 0)
5698 return CMD_WARNING_CONFIG_FAILED;
5699
5700 snprintf(attr_xpath, sizeof(attr_xpath),
5701 "./%s/nexthop-self/next-hop-self-force",
5702 bgp_afi_safi_get_container_str(afi, safi));
5703
5704 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5705
5706 return nb_cli_apply_changes(vty, base_xpath);
5707 }
5708
5709 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5710 no_neighbor_nexthop_self_force_hidden_cmd,
5711 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5712 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5713 "Disable the next hop calculation for this neighbor\n"
5714 "Set the next hop to self for reflected routes\n")
5715
5716 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5717 no_neighbor_nexthop_self_all_hidden_cmd,
5718 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5719 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5720 "Disable the next hop calculation for this neighbor\n"
5721 "Set the next hop to self for reflected routes\n")
5722
5723 /* neighbor as-override */
5724 DEFUN_YANG (neighbor_as_override,
5725 neighbor_as_override_cmd,
5726 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5727 NEIGHBOR_STR
5728 NEIGHBOR_ADDR_STR2
5729 "Override ASNs in outbound updates if aspath equals remote-as\n")
5730 {
5731 int idx_peer = 1;
5732 char base_xpath[XPATH_MAXLEN];
5733 char af_xpath[XPATH_MAXLEN];
5734 char attr_xpath[XPATH_MAXLEN];
5735 afi_t afi = bgp_node_afi(vty);
5736 safi_t safi = bgp_node_safi(vty);
5737
5738 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5739 yang_afi_safi_value2identity(afi, safi));
5740
5741 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5742 sizeof(base_xpath), af_xpath)
5743 < 0)
5744 return CMD_WARNING_CONFIG_FAILED;
5745
5746 snprintf(attr_xpath, sizeof(attr_xpath),
5747 "./%s/as-path-options/replace-peer-as",
5748 bgp_afi_safi_get_container_str(afi, safi));
5749
5750 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5751
5752 return nb_cli_apply_changes(vty, base_xpath);
5753 }
5754
5755 ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
5756 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5757 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5758 "Override ASNs in outbound updates if aspath equals remote-as\n")
5759
5760 DEFUN_YANG (no_neighbor_as_override,
5761 no_neighbor_as_override_cmd,
5762 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5763 NO_STR
5764 NEIGHBOR_STR
5765 NEIGHBOR_ADDR_STR2
5766 "Override ASNs in outbound updates if aspath equals remote-as\n")
5767 {
5768 int idx_peer = 2;
5769 char base_xpath[XPATH_MAXLEN];
5770 char af_xpath[XPATH_MAXLEN];
5771 char attr_xpath[XPATH_MAXLEN];
5772 afi_t afi = bgp_node_afi(vty);
5773 safi_t safi = bgp_node_safi(vty);
5774
5775 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5776 yang_afi_safi_value2identity(afi, safi));
5777
5778 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5779 sizeof(base_xpath), af_xpath)
5780 < 0)
5781 return CMD_WARNING_CONFIG_FAILED;
5782
5783 snprintf(attr_xpath, sizeof(attr_xpath),
5784 "./%s/as-path-options/replace-peer-as",
5785 bgp_afi_safi_get_container_str(afi, safi));
5786
5787 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5788
5789 return nb_cli_apply_changes(vty, base_xpath);
5790 }
5791
5792 ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
5793 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5794 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5795 "Override ASNs in outbound updates if aspath equals remote-as\n")
5796
5797 /* neighbor remove-private-AS. */
5798 DEFUN_YANG (neighbor_remove_private_as,
5799 neighbor_remove_private_as_cmd,
5800 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5801 NEIGHBOR_STR
5802 NEIGHBOR_ADDR_STR2
5803 "Remove private ASNs in outbound updates\n")
5804 {
5805 int idx_peer = 1;
5806 char base_xpath[XPATH_MAXLEN];
5807 char af_xpath[XPATH_MAXLEN];
5808 char attr_xpath[XPATH_MAXLEN];
5809 afi_t afi = bgp_node_afi(vty);
5810 safi_t safi = bgp_node_safi(vty);
5811
5812 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5813 yang_afi_safi_value2identity(afi, safi));
5814
5815 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5816 sizeof(base_xpath), af_xpath)
5817 < 0)
5818 return CMD_WARNING_CONFIG_FAILED;
5819
5820 snprintf(attr_xpath, sizeof(attr_xpath),
5821 "./%s/private-as/remove-private-as",
5822 bgp_afi_safi_get_container_str(afi, safi));
5823
5824 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5825
5826 return nb_cli_apply_changes(vty, base_xpath);
5827 }
5828
5829 ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
5830 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5831 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5832 "Remove private ASNs in outbound updates\n")
5833
5834 DEFUN_YANG (neighbor_remove_private_as_all,
5835 neighbor_remove_private_as_all_cmd,
5836 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5837 NEIGHBOR_STR
5838 NEIGHBOR_ADDR_STR2
5839 "Remove private ASNs in outbound updates\n"
5840 "Apply to all AS numbers\n")
5841 {
5842 int idx_peer = 1;
5843 char base_xpath[XPATH_MAXLEN];
5844 char af_xpath[XPATH_MAXLEN];
5845 char attr_xpath[XPATH_MAXLEN];
5846 afi_t afi = bgp_node_afi(vty);
5847 safi_t safi = bgp_node_safi(vty);
5848
5849
5850 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5851 yang_afi_safi_value2identity(afi, safi));
5852
5853 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5854 sizeof(base_xpath), af_xpath)
5855 < 0)
5856 return CMD_WARNING_CONFIG_FAILED;
5857
5858 snprintf(attr_xpath, sizeof(attr_xpath),
5859 "./%s/private-as/remove-private-as-all",
5860 bgp_afi_safi_get_container_str(afi, safi));
5861
5862 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5863
5864 return nb_cli_apply_changes(vty, base_xpath);
5865 }
5866
5867 ALIAS_HIDDEN(neighbor_remove_private_as_all,
5868 neighbor_remove_private_as_all_hidden_cmd,
5869 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5870 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5871 "Remove private ASNs in outbound updates\n"
5872 "Apply to all AS numbers")
5873
5874 DEFUN_YANG (neighbor_remove_private_as_replace_as,
5875 neighbor_remove_private_as_replace_as_cmd,
5876 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5877 NEIGHBOR_STR
5878 NEIGHBOR_ADDR_STR2
5879 "Remove private ASNs in outbound updates\n"
5880 "Replace private ASNs with our ASN in outbound updates\n")
5881 {
5882 int idx_peer = 1;
5883 char base_xpath[XPATH_MAXLEN];
5884 char af_xpath[XPATH_MAXLEN];
5885 char attr_xpath[XPATH_MAXLEN];
5886 afi_t afi = bgp_node_afi(vty);
5887 safi_t safi = bgp_node_safi(vty);
5888
5889
5890 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5891 yang_afi_safi_value2identity(afi, safi));
5892
5893 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5894 sizeof(base_xpath), af_xpath)
5895 < 0)
5896 return CMD_WARNING_CONFIG_FAILED;
5897
5898 snprintf(attr_xpath, sizeof(attr_xpath),
5899 "./%s/private-as/remove-private-as-replace",
5900 bgp_afi_safi_get_container_str(afi, safi));
5901
5902 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5903
5904 return nb_cli_apply_changes(vty, base_xpath);
5905 }
5906
5907 ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
5908 neighbor_remove_private_as_replace_as_hidden_cmd,
5909 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5910 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5911 "Remove private ASNs in outbound updates\n"
5912 "Replace private ASNs with our ASN in outbound updates\n")
5913
5914 DEFUN_YANG (neighbor_remove_private_as_all_replace_as,
5915 neighbor_remove_private_as_all_replace_as_cmd,
5916 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5917 NEIGHBOR_STR
5918 NEIGHBOR_ADDR_STR2
5919 "Remove private ASNs in outbound updates\n"
5920 "Apply to all AS numbers\n"
5921 "Replace private ASNs with our ASN in outbound updates\n")
5922 {
5923 int idx_peer = 1;
5924 char base_xpath[XPATH_MAXLEN];
5925 char af_xpath[XPATH_MAXLEN];
5926 char attr_xpath[XPATH_MAXLEN];
5927 afi_t afi = bgp_node_afi(vty);
5928 safi_t safi = bgp_node_safi(vty);
5929
5930
5931 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5932 yang_afi_safi_value2identity(afi, safi));
5933
5934 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5935 sizeof(base_xpath), af_xpath)
5936 < 0)
5937 return CMD_WARNING_CONFIG_FAILED;
5938
5939 snprintf(attr_xpath, sizeof(attr_xpath),
5940 "./%s/private-as/remove-private-as-all-replace",
5941 bgp_afi_safi_get_container_str(afi, safi));
5942
5943 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5944
5945 return nb_cli_apply_changes(vty, base_xpath);
5946 }
5947
5948 ALIAS_HIDDEN(
5949 neighbor_remove_private_as_all_replace_as,
5950 neighbor_remove_private_as_all_replace_as_hidden_cmd,
5951 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5952 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5953 "Remove private ASNs in outbound updates\n"
5954 "Apply to all AS numbers\n"
5955 "Replace private ASNs with our ASN in outbound updates\n")
5956
5957 DEFUN_YANG (no_neighbor_remove_private_as,
5958 no_neighbor_remove_private_as_cmd,
5959 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5960 NO_STR
5961 NEIGHBOR_STR
5962 NEIGHBOR_ADDR_STR2
5963 "Remove private ASNs in outbound updates\n")
5964 {
5965 int idx_peer = 2;
5966 char base_xpath[XPATH_MAXLEN];
5967 char af_xpath[XPATH_MAXLEN];
5968 char attr_xpath[XPATH_MAXLEN];
5969 afi_t afi = bgp_node_afi(vty);
5970 safi_t safi = bgp_node_safi(vty);
5971
5972 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5973 yang_afi_safi_value2identity(afi, safi));
5974
5975 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5976 sizeof(base_xpath), af_xpath)
5977 < 0)
5978 return CMD_WARNING_CONFIG_FAILED;
5979
5980 snprintf(attr_xpath, sizeof(attr_xpath),
5981 "./%s/private-as/remove-private-as",
5982 bgp_afi_safi_get_container_str(afi, safi));
5983
5984 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5985
5986 return nb_cli_apply_changes(vty, base_xpath);
5987 }
5988
5989 ALIAS_HIDDEN(no_neighbor_remove_private_as,
5990 no_neighbor_remove_private_as_hidden_cmd,
5991 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5992 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5993 "Remove private ASNs in outbound updates\n")
5994
5995 DEFUN_YANG (no_neighbor_remove_private_as_all,
5996 no_neighbor_remove_private_as_all_cmd,
5997 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5998 NO_STR
5999 NEIGHBOR_STR
6000 NEIGHBOR_ADDR_STR2
6001 "Remove private ASNs in outbound updates\n"
6002 "Apply to all AS numbers\n")
6003 {
6004 int idx_peer = 2;
6005 char base_xpath[XPATH_MAXLEN];
6006 char af_xpath[XPATH_MAXLEN];
6007 char attr_xpath[XPATH_MAXLEN];
6008 afi_t afi = bgp_node_afi(vty);
6009 safi_t safi = bgp_node_safi(vty);
6010
6011
6012 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6013 yang_afi_safi_value2identity(afi, safi));
6014
6015 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6016 sizeof(base_xpath), af_xpath)
6017 < 0)
6018 return CMD_WARNING_CONFIG_FAILED;
6019
6020 snprintf(attr_xpath, sizeof(attr_xpath),
6021 "./%s/private-as/remove-private-as-all",
6022 bgp_afi_safi_get_container_str(afi, safi));
6023
6024 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6025
6026 return nb_cli_apply_changes(vty, base_xpath);
6027 }
6028
6029 ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
6030 no_neighbor_remove_private_as_all_hidden_cmd,
6031 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
6032 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6033 "Remove private ASNs in outbound updates\n"
6034 "Apply to all AS numbers\n")
6035
6036 DEFUN_YANG (no_neighbor_remove_private_as_replace_as,
6037 no_neighbor_remove_private_as_replace_as_cmd,
6038 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
6039 NO_STR
6040 NEIGHBOR_STR
6041 NEIGHBOR_ADDR_STR2
6042 "Remove private ASNs in outbound updates\n"
6043 "Replace private ASNs with our ASN in outbound updates\n")
6044 {
6045 int idx_peer = 2;
6046 char base_xpath[XPATH_MAXLEN];
6047 char af_xpath[XPATH_MAXLEN];
6048 char attr_xpath[XPATH_MAXLEN];
6049 afi_t afi = bgp_node_afi(vty);
6050 safi_t safi = bgp_node_safi(vty);
6051
6052
6053 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6054 yang_afi_safi_value2identity(afi, safi));
6055
6056 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6057 sizeof(base_xpath), af_xpath)
6058 < 0)
6059 return CMD_WARNING_CONFIG_FAILED;
6060
6061 snprintf(attr_xpath, sizeof(attr_xpath),
6062 "./%s/private-as/remove-private-as-replace",
6063 bgp_afi_safi_get_container_str(afi, safi));
6064
6065 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6066
6067 return nb_cli_apply_changes(vty, base_xpath);
6068 }
6069
6070 ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
6071 no_neighbor_remove_private_as_replace_as_hidden_cmd,
6072 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
6073 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6074 "Remove private ASNs in outbound updates\n"
6075 "Replace private ASNs with our ASN in outbound updates\n")
6076
6077 DEFUN_YANG (no_neighbor_remove_private_as_all_replace_as,
6078 no_neighbor_remove_private_as_all_replace_as_cmd,
6079 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
6080 NO_STR
6081 NEIGHBOR_STR
6082 NEIGHBOR_ADDR_STR2
6083 "Remove private ASNs in outbound updates\n"
6084 "Apply to all AS numbers\n"
6085 "Replace private ASNs with our ASN in outbound updates\n")
6086 {
6087 int idx_peer = 2;
6088 char base_xpath[XPATH_MAXLEN];
6089 char af_xpath[XPATH_MAXLEN];
6090 char attr_xpath[XPATH_MAXLEN];
6091 afi_t afi = bgp_node_afi(vty);
6092 safi_t safi = bgp_node_safi(vty);
6093
6094
6095 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6096 yang_afi_safi_value2identity(afi, safi));
6097
6098 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6099 sizeof(base_xpath), af_xpath)
6100 < 0)
6101 return CMD_WARNING_CONFIG_FAILED;
6102
6103 snprintf(attr_xpath, sizeof(attr_xpath),
6104 "./%s/private-as/remove-private-as-all-replace",
6105 bgp_afi_safi_get_container_str(afi, safi));
6106
6107 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6108
6109 return nb_cli_apply_changes(vty, base_xpath);
6110 }
6111
6112 ALIAS_HIDDEN(
6113 no_neighbor_remove_private_as_all_replace_as,
6114 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
6115 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
6116 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6117 "Remove private ASNs in outbound updates\n"
6118 "Apply to all AS numbers\n"
6119 "Replace private ASNs with our ASN in outbound updates\n")
6120
6121
6122 /* neighbor send-community. */
6123 DEFUN_YANG (neighbor_send_community,
6124 neighbor_send_community_cmd,
6125 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6126 NEIGHBOR_STR
6127 NEIGHBOR_ADDR_STR2
6128 "Send Community attribute to this neighbor\n")
6129 {
6130 int idx_peer = 1;
6131
6132 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6133 bgp_node_safi(vty),
6134 PEER_FLAG_SEND_COMMUNITY);
6135 }
6136
6137 ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
6138 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6139 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6140 "Send Community attribute to this neighbor\n")
6141
6142 DEFUN_YANG (no_neighbor_send_community,
6143 no_neighbor_send_community_cmd,
6144 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6145 NO_STR
6146 NEIGHBOR_STR
6147 NEIGHBOR_ADDR_STR2
6148 "Send Community attribute to this neighbor\n")
6149 {
6150 int idx_peer = 2;
6151
6152 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6153 bgp_node_afi(vty), bgp_node_safi(vty),
6154 PEER_FLAG_SEND_COMMUNITY);
6155 }
6156
6157 ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
6158 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6159 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6160 "Send Community attribute to this neighbor\n")
6161
6162 /* neighbor send-community extended. */
6163 DEFUN_YANG (neighbor_send_community_type,
6164 neighbor_send_community_type_cmd,
6165 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6166 NEIGHBOR_STR
6167 NEIGHBOR_ADDR_STR2
6168 "Send Community attribute to this neighbor\n"
6169 "Send Standard and Extended Community attributes\n"
6170 "Send Standard, Large and Extended Community attributes\n"
6171 "Send Extended Community attributes\n"
6172 "Send Standard Community attributes\n"
6173 "Send Large Community attributes\n")
6174 {
6175 const char *type = argv[argc - 1]->text;
6176 char *peer_str = argv[1]->arg;
6177 char base_xpath[XPATH_MAXLEN];
6178 char af_xpath[XPATH_MAXLEN];
6179 char std_xpath[XPATH_MAXLEN];
6180 char ext_xpath[XPATH_MAXLEN];
6181 char lrg_xpath[XPATH_MAXLEN];
6182 afi_t afi = bgp_node_afi(vty);
6183 safi_t safi = bgp_node_safi(vty);
6184
6185 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6186 yang_afi_safi_value2identity(afi, safi));
6187
6188 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6189 sizeof(base_xpath), af_xpath)
6190 < 0)
6191 return CMD_WARNING_CONFIG_FAILED;
6192
6193 if (strmatch(type, "standard")) {
6194 snprintf(std_xpath, sizeof(std_xpath),
6195 "./%s/send-community/send-community",
6196 bgp_afi_safi_get_container_str(afi, safi));
6197
6198 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "true");
6199 }
6200
6201 if (strmatch(type, "extended")) {
6202 snprintf(ext_xpath, sizeof(ext_xpath),
6203 "./%s/send-community/send-ext-community",
6204 bgp_afi_safi_get_container_str(afi, safi));
6205
6206 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "true");
6207 }
6208
6209 if (strmatch(type, "large")) {
6210 snprintf(lrg_xpath, sizeof(lrg_xpath),
6211 "./%s/send-community/send-large-community",
6212 bgp_afi_safi_get_container_str(afi, safi));
6213
6214 nb_cli_enqueue_change(vty, lrg_xpath, NB_OP_MODIFY, "true");
6215 }
6216
6217 if (strmatch(type, "both")) {
6218 snprintf(std_xpath, sizeof(std_xpath),
6219 "./%s/send-community/send-community",
6220 bgp_afi_safi_get_container_str(afi, safi));
6221
6222 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "true");
6223
6224 snprintf(ext_xpath, sizeof(ext_xpath),
6225 "./%s/send-community/send-ext-community",
6226 bgp_afi_safi_get_container_str(afi, safi));
6227
6228 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "true");
6229 }
6230
6231 if (strmatch(type, "all")) {
6232 snprintf(std_xpath, sizeof(std_xpath),
6233 "./%s/send-community/send-community",
6234 bgp_afi_safi_get_container_str(afi, safi));
6235
6236 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "true");
6237
6238 snprintf(ext_xpath, sizeof(ext_xpath),
6239 "./%s/send-community/send-ext-community",
6240 bgp_afi_safi_get_container_str(afi, safi));
6241
6242 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "true");
6243
6244 snprintf(lrg_xpath, sizeof(lrg_xpath),
6245 "./%s/send-community/send-large-community",
6246 bgp_afi_safi_get_container_str(afi, safi));
6247
6248 nb_cli_enqueue_change(vty, lrg_xpath, NB_OP_MODIFY, "true");
6249 }
6250
6251 return nb_cli_apply_changes(vty, base_xpath);
6252 }
6253
6254 ALIAS_HIDDEN(
6255 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
6256 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6257 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6258 "Send Community attribute to this neighbor\n"
6259 "Send Standard and Extended Community attributes\n"
6260 "Send Standard, Large and Extended Community attributes\n"
6261 "Send Extended Community attributes\n"
6262 "Send Standard Community attributes\n"
6263 "Send Large Community attributes\n")
6264
6265 DEFUN_YANG (no_neighbor_send_community_type,
6266 no_neighbor_send_community_type_cmd,
6267 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6268 NO_STR
6269 NEIGHBOR_STR
6270 NEIGHBOR_ADDR_STR2
6271 "Send Community attribute to this neighbor\n"
6272 "Send Standard and Extended Community attributes\n"
6273 "Send Standard, Large and Extended Community attributes\n"
6274 "Send Extended Community attributes\n"
6275 "Send Standard Community attributes\n"
6276 "Send Large Community attributes\n")
6277 {
6278 const char *type = argv[argc - 1]->text;
6279 char *peer_str = argv[2]->arg;
6280 char base_xpath[XPATH_MAXLEN];
6281 char af_xpath[XPATH_MAXLEN];
6282 char std_xpath[XPATH_MAXLEN];
6283 char ext_xpath[XPATH_MAXLEN];
6284 char lrg_xpath[XPATH_MAXLEN];
6285 afi_t afi = bgp_node_afi(vty);
6286 safi_t safi = bgp_node_safi(vty);
6287
6288 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6289 yang_afi_safi_value2identity(afi, safi));
6290
6291 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6292 sizeof(base_xpath), af_xpath)
6293 < 0)
6294 return CMD_WARNING_CONFIG_FAILED;
6295
6296 if (strmatch(type, "standard")) {
6297 snprintf(std_xpath, sizeof(std_xpath),
6298 "./%s/send-community/send-community",
6299 bgp_afi_safi_get_container_str(afi, safi));
6300
6301 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "false");
6302 }
6303
6304 if (strmatch(type, "extended")) {
6305 snprintf(ext_xpath, sizeof(ext_xpath),
6306 "./%s/send-community/send-ext-community",
6307 bgp_afi_safi_get_container_str(afi, safi));
6308
6309 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "false");
6310 }
6311
6312 if (strmatch(type, "large")) {
6313 snprintf(lrg_xpath, sizeof(lrg_xpath),
6314 "./%s/send-community/send-large-community",
6315 bgp_afi_safi_get_container_str(afi, safi));
6316
6317 nb_cli_enqueue_change(vty, lrg_xpath, NB_OP_MODIFY, "false");
6318 }
6319
6320 if (strmatch(type, "both")) {
6321 snprintf(std_xpath, sizeof(std_xpath),
6322 "./%s/send-community/send-community",
6323 bgp_afi_safi_get_container_str(afi, safi));
6324
6325 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "false");
6326
6327 snprintf(ext_xpath, sizeof(ext_xpath),
6328 "./%s/send-community/send-ext-community",
6329 bgp_afi_safi_get_container_str(afi, safi));
6330
6331 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "false");
6332 }
6333
6334 if (strmatch(type, "all")) {
6335 snprintf(std_xpath, sizeof(std_xpath),
6336 "./%s/send-community/send-community",
6337 bgp_afi_safi_get_container_str(afi, safi));
6338
6339 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "false");
6340
6341 snprintf(ext_xpath, sizeof(ext_xpath),
6342 "./%s/send-community/send-ext-community",
6343 bgp_afi_safi_get_container_str(afi, safi));
6344
6345 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "false");
6346
6347 snprintf(lrg_xpath, sizeof(lrg_xpath),
6348 "./%s/send-community/send-large-community",
6349 bgp_afi_safi_get_container_str(afi, safi));
6350
6351 nb_cli_enqueue_change(vty, lrg_xpath, NB_OP_MODIFY, "false");
6352 }
6353
6354 return nb_cli_apply_changes(vty, base_xpath);
6355 }
6356
6357 ALIAS_HIDDEN(
6358 no_neighbor_send_community_type,
6359 no_neighbor_send_community_type_hidden_cmd,
6360 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6361 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6362 "Send Community attribute to this neighbor\n"
6363 "Send Standard and Extended Community attributes\n"
6364 "Send Standard, Large and Extended Community attributes\n"
6365 "Send Extended Community attributes\n"
6366 "Send Standard Community attributes\n"
6367 "Send Large Community attributes\n")
6368
6369 /* neighbor soft-reconfig. */
6370 DEFUN_YANG (neighbor_soft_reconfiguration,
6371 neighbor_soft_reconfiguration_cmd,
6372 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6373 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6374 "Per neighbor soft reconfiguration\n"
6375 "Allow inbound soft reconfiguration for this neighbor\n")
6376 {
6377 int idx_peer = 1;
6378 char base_xpath[XPATH_MAXLEN];
6379 char af_xpath[XPATH_MAXLEN];
6380 char soft_xpath[XPATH_MAXLEN];
6381 afi_t afi = bgp_node_afi(vty);
6382 safi_t safi = bgp_node_safi(vty);
6383
6384
6385 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6386 yang_afi_safi_value2identity(afi, safi));
6387
6388 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6389 sizeof(base_xpath), af_xpath)
6390 < 0)
6391 return CMD_WARNING_CONFIG_FAILED;
6392
6393 snprintf(soft_xpath, sizeof(soft_xpath), "./%s/soft-reconfiguration",
6394 bgp_afi_safi_get_container_str(afi, safi));
6395
6396 nb_cli_enqueue_change(vty, soft_xpath, NB_OP_MODIFY, "true");
6397
6398 return nb_cli_apply_changes(vty, base_xpath);
6399 }
6400
6401 ALIAS_HIDDEN(neighbor_soft_reconfiguration,
6402 neighbor_soft_reconfiguration_hidden_cmd,
6403 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6404 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6405 "Per neighbor soft reconfiguration\n"
6406 "Allow inbound soft reconfiguration for this neighbor\n")
6407
6408 DEFUN_YANG (no_neighbor_soft_reconfiguration,
6409 no_neighbor_soft_reconfiguration_cmd,
6410 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6411 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6412 "Per neighbor soft reconfiguration\n"
6413 "Allow inbound soft reconfiguration for this neighbor\n")
6414 {
6415 int idx_peer = 2;
6416 char base_xpath[XPATH_MAXLEN];
6417 char af_xpath[XPATH_MAXLEN];
6418 char soft_xpath[XPATH_MAXLEN];
6419 afi_t afi = bgp_node_afi(vty);
6420 safi_t safi = bgp_node_safi(vty);
6421
6422 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6423 yang_afi_safi_value2identity(afi, safi));
6424
6425 snprintf(soft_xpath, sizeof(soft_xpath), "./%s/soft-reconfiguration",
6426 bgp_afi_safi_get_container_str(afi, safi));
6427
6428 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6429 sizeof(base_xpath), af_xpath)
6430 < 0)
6431 return CMD_WARNING_CONFIG_FAILED;
6432
6433 nb_cli_enqueue_change(vty, soft_xpath, NB_OP_MODIFY, "false");
6434
6435 return nb_cli_apply_changes(vty, base_xpath);
6436 }
6437
6438 ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
6439 no_neighbor_soft_reconfiguration_hidden_cmd,
6440 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6441 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6442 "Per neighbor soft reconfiguration\n"
6443 "Allow inbound soft reconfiguration for this neighbor\n")
6444
6445 DEFUN_YANG (neighbor_route_reflector_client,
6446 neighbor_route_reflector_client_cmd,
6447 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6448 NEIGHBOR_STR
6449 NEIGHBOR_ADDR_STR2
6450 "Configure a neighbor as Route Reflector client\n")
6451 {
6452 int idx_peer = 1;
6453 char base_xpath[XPATH_MAXLEN];
6454 char af_xpath[XPATH_MAXLEN];
6455 char attr_xpath[XPATH_MAXLEN];
6456 afi_t afi = bgp_node_afi(vty);
6457 safi_t safi = bgp_node_safi(vty);
6458
6459 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6460 yang_afi_safi_value2identity(afi, safi));
6461
6462 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6463 sizeof(base_xpath), af_xpath)
6464 < 0)
6465 return CMD_WARNING_CONFIG_FAILED;
6466
6467 snprintf(attr_xpath, sizeof(attr_xpath),
6468 "./%s/route-reflector/route-reflector-client",
6469 bgp_afi_safi_get_container_str(afi, safi));
6470
6471 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
6472
6473 return nb_cli_apply_changes(vty, base_xpath);
6474 }
6475
6476 ALIAS_HIDDEN(neighbor_route_reflector_client,
6477 neighbor_route_reflector_client_hidden_cmd,
6478 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6479 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6480 "Configure a neighbor as Route Reflector client\n")
6481
6482 DEFUN_YANG (no_neighbor_route_reflector_client,
6483 no_neighbor_route_reflector_client_cmd,
6484 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6485 NO_STR
6486 NEIGHBOR_STR
6487 NEIGHBOR_ADDR_STR2
6488 "Configure a neighbor as Route Reflector client\n")
6489 {
6490 int idx_peer = 2;
6491 char base_xpath[XPATH_MAXLEN];
6492 char af_xpath[XPATH_MAXLEN];
6493 char attr_xpath[XPATH_MAXLEN];
6494 afi_t afi = bgp_node_afi(vty);
6495 safi_t safi = bgp_node_safi(vty);
6496
6497 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6498 yang_afi_safi_value2identity(afi, safi));
6499
6500 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6501 sizeof(base_xpath), af_xpath)
6502 < 0)
6503 return CMD_WARNING_CONFIG_FAILED;
6504
6505 snprintf(attr_xpath, sizeof(attr_xpath),
6506 "./%s/route-reflector/route-reflector-client",
6507 bgp_afi_safi_get_container_str(afi, safi));
6508
6509 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6510
6511 return nb_cli_apply_changes(vty, base_xpath);
6512 }
6513
6514 ALIAS_HIDDEN(no_neighbor_route_reflector_client,
6515 no_neighbor_route_reflector_client_hidden_cmd,
6516 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6517 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6518 "Configure a neighbor as Route Reflector client\n")
6519
6520 /* neighbor route-server-client. */
6521 DEFUN_YANG (neighbor_route_server_client,
6522 neighbor_route_server_client_cmd,
6523 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6524 NEIGHBOR_STR
6525 NEIGHBOR_ADDR_STR2
6526 "Configure a neighbor as Route Server client\n")
6527 {
6528 int idx_peer = 1;
6529 char base_xpath[XPATH_MAXLEN];
6530 char af_xpath[XPATH_MAXLEN];
6531 char attr_xpath[XPATH_MAXLEN];
6532 afi_t afi = bgp_node_afi(vty);
6533 safi_t safi = bgp_node_safi(vty);
6534
6535 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6536 yang_afi_safi_value2identity(afi, safi));
6537
6538 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6539 sizeof(base_xpath), af_xpath)
6540 < 0)
6541 return CMD_WARNING_CONFIG_FAILED;
6542
6543 snprintf(attr_xpath, sizeof(attr_xpath),
6544 "./%s/route-server/route-server-client",
6545 bgp_afi_safi_get_container_str(afi, safi));
6546
6547 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
6548
6549 return nb_cli_apply_changes(vty, base_xpath);
6550 }
6551
6552 ALIAS_HIDDEN(neighbor_route_server_client,
6553 neighbor_route_server_client_hidden_cmd,
6554 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6555 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6556 "Configure a neighbor as Route Server client\n")
6557
6558 DEFUN_YANG (no_neighbor_route_server_client,
6559 no_neighbor_route_server_client_cmd,
6560 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6561 NO_STR
6562 NEIGHBOR_STR
6563 NEIGHBOR_ADDR_STR2
6564 "Configure a neighbor as Route Server client\n")
6565 {
6566 int idx_peer = 2;
6567 char base_xpath[XPATH_MAXLEN];
6568 char af_xpath[XPATH_MAXLEN];
6569 char attr_xpath[XPATH_MAXLEN];
6570 afi_t afi = bgp_node_afi(vty);
6571 safi_t safi = bgp_node_safi(vty);
6572
6573 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6574 yang_afi_safi_value2identity(afi, safi));
6575
6576 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6577 sizeof(base_xpath), af_xpath)
6578 < 0)
6579 return CMD_WARNING_CONFIG_FAILED;
6580
6581 snprintf(attr_xpath, sizeof(attr_xpath),
6582 "./%s/route-server/route-server-client",
6583 bgp_afi_safi_get_container_str(afi, safi));
6584
6585 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6586
6587 return nb_cli_apply_changes(vty, base_xpath);
6588 }
6589
6590 ALIAS_HIDDEN(no_neighbor_route_server_client,
6591 no_neighbor_route_server_client_hidden_cmd,
6592 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6593 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6594 "Configure a neighbor as Route Server client\n")
6595
6596 DEFUN (neighbor_nexthop_local_unchanged,
6597 neighbor_nexthop_local_unchanged_cmd,
6598 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
6599 NEIGHBOR_STR
6600 NEIGHBOR_ADDR_STR2
6601 "Configure treatment of outgoing link-local nexthop attribute\n"
6602 "Leave link-local nexthop unchanged for this peer\n")
6603 {
6604 int idx_peer = 1;
6605 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6606 bgp_node_safi(vty),
6607 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
6608 }
6609
6610 DEFUN (no_neighbor_nexthop_local_unchanged,
6611 no_neighbor_nexthop_local_unchanged_cmd,
6612 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
6613 NO_STR
6614 NEIGHBOR_STR
6615 NEIGHBOR_ADDR_STR2
6616 "Configure treatment of outgoing link-local-nexthop attribute\n"
6617 "Leave link-local nexthop unchanged for this peer\n")
6618 {
6619 int idx_peer = 2;
6620 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6621 bgp_node_afi(vty), bgp_node_safi(vty),
6622 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
6623 }
6624
6625 DEFUN_YANG (neighbor_attr_unchanged,
6626 neighbor_attr_unchanged_cmd,
6627 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6628 NEIGHBOR_STR
6629 NEIGHBOR_ADDR_STR2
6630 "BGP attribute is propagated unchanged to this neighbor\n"
6631 "As-path attribute\n"
6632 "Nexthop attribute\n"
6633 "Med attribute\n")
6634 {
6635 int idx = 0;
6636 char *peer_str = argv[1]->arg;
6637 bool aspath = false;
6638 bool nexthop = false;
6639 bool med = false;
6640 afi_t afi = bgp_node_afi(vty);
6641 safi_t safi = bgp_node_safi(vty);
6642 char base_xpath[XPATH_MAXLEN];
6643 char af_xpath[XPATH_MAXLEN];
6644 char as_xpath[XPATH_MAXLEN];
6645 char nxthop_xpath[XPATH_MAXLEN];
6646 char med_xpath[XPATH_MAXLEN];
6647
6648 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6649 yang_afi_safi_value2identity(afi, safi));
6650
6651 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6652 sizeof(base_xpath), af_xpath)
6653 < 0)
6654 return CMD_WARNING_CONFIG_FAILED;
6655
6656 if (argv_find(argv, argc, "as-path", &idx))
6657 aspath = true;
6658
6659 idx = 0;
6660 if (argv_find(argv, argc, "next-hop", &idx))
6661 nexthop = true;
6662
6663 idx = 0;
6664 if (argv_find(argv, argc, "med", &idx))
6665 med = true;
6666
6667 snprintf(as_xpath, sizeof(as_xpath),
6668 "./%s/attr-unchanged/as-path-unchanged",
6669 bgp_afi_safi_get_container_str(afi, safi));
6670 snprintf(nxthop_xpath, sizeof(nxthop_xpath),
6671 "./%s/attr-unchanged/next-hop-unchanged",
6672 bgp_afi_safi_get_container_str(afi, safi));
6673 snprintf(med_xpath, sizeof(med_xpath),
6674 "./%s/attr-unchanged/med-unchanged",
6675 bgp_afi_safi_get_container_str(afi, safi));
6676
6677 /* no flags means all of them! */
6678 if (!aspath && !nexthop && !med) {
6679 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY, "true");
6680 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY, "true");
6681 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY, "true");
6682 } else {
6683 if (!aspath)
6684 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY,
6685 "false");
6686 else
6687 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY,
6688 "true");
6689
6690 if (!nexthop)
6691 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY,
6692 "false");
6693 else
6694 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY,
6695 "true");
6696
6697 if (!med)
6698 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY,
6699 "false");
6700 else
6701 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY,
6702 "true");
6703 }
6704
6705 return nb_cli_apply_changes(vty, base_xpath);
6706 }
6707
6708 ALIAS_HIDDEN(
6709 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
6710 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6711 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6712 "BGP attribute is propagated unchanged to this neighbor\n"
6713 "As-path attribute\n"
6714 "Nexthop attribute\n"
6715 "Med attribute\n")
6716
6717 DEFUN_YANG (no_neighbor_attr_unchanged,
6718 no_neighbor_attr_unchanged_cmd,
6719 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6720 NO_STR
6721 NEIGHBOR_STR
6722 NEIGHBOR_ADDR_STR2
6723 "BGP attribute is propagated unchanged to this neighbor\n"
6724 "As-path attribute\n"
6725 "Nexthop attribute\n"
6726 "Med attribute\n")
6727 {
6728 int idx = 0;
6729 char *peer_str = argv[2]->arg;
6730 bool aspath = false;
6731 bool nexthop = false;
6732 bool med = false;
6733 afi_t afi = bgp_node_afi(vty);
6734 safi_t safi = bgp_node_safi(vty);
6735 char base_xpath[XPATH_MAXLEN];
6736 char af_xpath[XPATH_MAXLEN];
6737 char as_xpath[XPATH_MAXLEN];
6738 char nxthop_xpath[XPATH_MAXLEN];
6739 char med_xpath[XPATH_MAXLEN];
6740
6741 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6742 yang_afi_safi_value2identity(afi, safi));
6743
6744 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6745 sizeof(base_xpath), af_xpath)
6746 < 0)
6747 return CMD_WARNING_CONFIG_FAILED;
6748
6749 if (argv_find(argv, argc, "as-path", &idx))
6750 aspath = true;
6751
6752 idx = 0;
6753 if (argv_find(argv, argc, "next-hop", &idx))
6754 nexthop = true;
6755
6756 idx = 0;
6757 if (argv_find(argv, argc, "med", &idx))
6758 med = true;
6759
6760 snprintf(as_xpath, sizeof(as_xpath),
6761 "./%s/attr-unchanged/as-path-unchanged",
6762 bgp_afi_safi_get_container_str(afi, safi));
6763 snprintf(nxthop_xpath, sizeof(nxthop_xpath),
6764 "./%s/attr-unchanged/next-hop-unchanged",
6765 bgp_afi_safi_get_container_str(afi, safi));
6766 snprintf(med_xpath, sizeof(med_xpath),
6767 "./%s/attr-unchanged/med-unchanged",
6768 bgp_afi_safi_get_container_str(afi, safi));
6769
6770 /* no flags means all of them! */
6771 if (!aspath && !nexthop && !med) {
6772 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY, "false");
6773 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY, "false");
6774 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY, "false");
6775 }
6776
6777 if (aspath)
6778 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY, "false");
6779
6780 if (nexthop)
6781 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY, "false");
6782
6783 if (med)
6784 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY, "false");
6785
6786 return nb_cli_apply_changes(vty, base_xpath);
6787 }
6788
6789 ALIAS_HIDDEN(
6790 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
6791 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6792 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6793 "BGP attribute is propagated unchanged to this neighbor\n"
6794 "As-path attribute\n"
6795 "Nexthop attribute\n"
6796 "Med attribute\n")
6797
6798 /* neighbor ebgp-multihop. */
6799 DEFUN_YANG (neighbor_ebgp_multihop,
6800 neighbor_ebgp_multihop_cmd,
6801 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
6802 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6803 "Allow EBGP neighbors not on directly connected networks\n")
6804 {
6805 int idx_peer = 1;
6806 char base_xpath[XPATH_MAXLEN];
6807
6808 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6809 sizeof(base_xpath), NULL)
6810 < 0)
6811 return CMD_WARNING_CONFIG_FAILED;
6812
6813 nb_cli_enqueue_change(vty, "./ebgp-multihop/enabled", NB_OP_MODIFY,
6814 "true");
6815
6816 return nb_cli_apply_changes(vty, base_xpath);
6817 }
6818
6819 DEFUN_YANG (neighbor_ebgp_multihop_ttl,
6820 neighbor_ebgp_multihop_ttl_cmd,
6821 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
6822 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6823 "Allow EBGP neighbors not on directly connected networks\n"
6824 "maximum hop count\n")
6825 {
6826 int idx_peer = 1;
6827 int idx_number = 3;
6828 char base_xpath[XPATH_MAXLEN];
6829
6830 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6831 sizeof(base_xpath), NULL)
6832 < 0)
6833 return CMD_WARNING_CONFIG_FAILED;
6834
6835 nb_cli_enqueue_change(vty, "./ebgp-multihop/multihop-ttl", NB_OP_MODIFY,
6836 argv[idx_number]->arg);
6837
6838 return nb_cli_apply_changes(vty, base_xpath);
6839 }
6840
6841 DEFUN_YANG (no_neighbor_ebgp_multihop,
6842 no_neighbor_ebgp_multihop_cmd,
6843 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
6844 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6845 "Allow EBGP neighbors not on directly connected networks\n"
6846 "maximum hop count\n")
6847 {
6848 int idx_peer = 2;
6849 char base_xpath[XPATH_MAXLEN];
6850
6851 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6852 sizeof(base_xpath), NULL)
6853 < 0)
6854 return CMD_WARNING_CONFIG_FAILED;
6855
6856 if (argc > 4)
6857 nb_cli_enqueue_change(vty, "./ebgp-multihop/multihop-ttl",
6858 NB_OP_DESTROY, NULL);
6859 else
6860 nb_cli_enqueue_change(vty, "./ebgp-multihop/enabled",
6861 NB_OP_MODIFY, "false");
6862
6863 return nb_cli_apply_changes(vty, base_xpath);
6864 }
6865
6866
6867 /* disable-connected-check */
6868 DEFUN_YANG (neighbor_disable_connected_check,
6869 neighbor_disable_connected_check_cmd,
6870 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6871 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6872 "one-hop away EBGP peer using loopback address\n"
6873 "Enforce EBGP neighbors perform multihop\n")
6874 {
6875 int idx_peer = 1;
6876 char base_xpath[XPATH_MAXLEN];
6877
6878 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6879 sizeof(base_xpath), NULL)
6880 < 0)
6881 return CMD_WARNING_CONFIG_FAILED;
6882
6883 nb_cli_enqueue_change(vty, "./ebgp-multihop/disable-connected-check",
6884 NB_OP_MODIFY, "true");
6885
6886 return nb_cli_apply_changes(vty, base_xpath);
6887 }
6888
6889 DEFUN_YANG (no_neighbor_disable_connected_check,
6890 no_neighbor_disable_connected_check_cmd,
6891 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6892 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6893 "one-hop away EBGP peer using loopback address\n"
6894 "Enforce EBGP neighbors perform multihop\n")
6895 {
6896 int idx_peer = 2;
6897 char base_xpath[XPATH_MAXLEN];
6898
6899 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6900 sizeof(base_xpath), NULL)
6901 < 0)
6902 return CMD_WARNING_CONFIG_FAILED;
6903
6904 nb_cli_enqueue_change(vty, "./ebgp-multihop/disable-connected-check",
6905 NB_OP_MODIFY, "false");
6906
6907 return nb_cli_apply_changes(vty, base_xpath);
6908 }
6909
6910
6911 /* enforce-first-as */
6912 DEFUN_YANG (neighbor_enforce_first_as,
6913 neighbor_enforce_first_as_cmd,
6914 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6915 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6916 "Enforce the first AS for EBGP routes\n")
6917 {
6918 int idx_peer = 1;
6919 char base_xpath[XPATH_MAXLEN];
6920
6921 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6922 sizeof(base_xpath), NULL)
6923 < 0)
6924 return CMD_WARNING_CONFIG_FAILED;
6925
6926 nb_cli_enqueue_change(vty, "./enforce-first-as", NB_OP_MODIFY, "true");
6927
6928 return nb_cli_apply_changes(vty, base_xpath);
6929 }
6930
6931 DEFUN_YANG (no_neighbor_enforce_first_as,
6932 no_neighbor_enforce_first_as_cmd,
6933 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6934 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6935 "Enforce the first AS for EBGP routes\n")
6936 {
6937 int idx_peer = 2;
6938 char base_xpath[XPATH_MAXLEN];
6939
6940 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6941 sizeof(base_xpath), NULL)
6942 < 0)
6943 return CMD_WARNING_CONFIG_FAILED;
6944
6945 nb_cli_enqueue_change(vty, "./enforce-first-as", NB_OP_MODIFY, "false");
6946
6947 return nb_cli_apply_changes(vty, base_xpath);
6948 }
6949
6950 static int peer_and_group_lookup_nb(struct vty *vty, const char *peer_str,
6951 char *base_xpath, int xpath_len,
6952 char *xpath)
6953 {
6954 union sockunion su;
6955 char num_xpath[XPATH_MAXLEN];
6956 char unnbr_xpath[XPATH_MAXLEN];
6957 char prgrp_xpath[XPATH_MAXLEN];
6958
6959 if (str2sockunion(peer_str, &su) == 0) {
6960 snprintf(num_xpath, sizeof(num_xpath),
6961 "/neighbors/neighbor[remote-address='%s']", peer_str);
6962 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
6963 VTY_CURR_XPATH, num_xpath)) {
6964 snprintf(base_xpath, xpath_len,
6965 FRR_BGP_NEIGHBOR_NUM_XPATH, peer_str,
6966 xpath ? xpath : "");
6967 } else {
6968 vty_out(vty,
6969 "%% Specify remote-as or peer-group commands first\n");
6970 return -1;
6971 }
6972
6973 } else {
6974 snprintf(unnbr_xpath, sizeof(unnbr_xpath),
6975 "/neighbors/unnumbered-neighbor[interface='%s']",
6976 peer_str);
6977
6978 snprintf(prgrp_xpath, sizeof(prgrp_xpath),
6979 "/peer-groups/peer-group[peer-group-name='%s']",
6980 peer_str);
6981
6982 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
6983 VTY_CURR_XPATH, unnbr_xpath)) {
6984 snprintf(base_xpath, xpath_len,
6985 FRR_BGP_NEIGHBOR_UNNUM_XPATH, peer_str,
6986 xpath ? xpath : "");
6987 } else if (yang_dnode_exists(vty->candidate_config->dnode,
6988 "%s%s", VTY_CURR_XPATH,
6989 prgrp_xpath)) {
6990 snprintf(base_xpath, xpath_len,
6991 FRR_BGP_PEER_GROUP_XPATH, peer_str,
6992 xpath ? xpath : "");
6993 } else {
6994 vty_out(vty,
6995 "%% Create the peer-group or interface first\n");
6996 return -1;
6997 }
6998 }
6999
7000 return 0;
7001 }
7002
7003 DEFUN_YANG (neighbor_description,
7004 neighbor_description_cmd,
7005 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
7006 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7007 "Neighbor specific description\n"
7008 "Up to 80 characters describing this neighbor\n")
7009 {
7010 int idx_peer = 1;
7011 int idx_line = 3;
7012 int ret;
7013 char base_xpath[XPATH_MAXLEN];
7014 char *str;
7015
7016 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7017 sizeof(base_xpath), NULL)
7018 < 0)
7019 return CMD_WARNING_CONFIG_FAILED;
7020
7021 str = argv_concat(argv, argc, idx_line);
7022
7023 nb_cli_enqueue_change(vty, "./description", NB_OP_MODIFY, str);
7024
7025 ret = nb_cli_apply_changes(vty, base_xpath);
7026
7027 XFREE(MTYPE_TMP, str);
7028
7029 return ret;
7030 }
7031
7032 DEFUN_YANG (no_neighbor_description,
7033 no_neighbor_description_cmd,
7034 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
7035 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7036 "Neighbor specific description\n")
7037 {
7038 int idx_peer = 2;
7039 char base_xpath[XPATH_MAXLEN];
7040
7041 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7042 sizeof(base_xpath), NULL)
7043 < 0)
7044 return CMD_WARNING_CONFIG_FAILED;
7045
7046 nb_cli_enqueue_change(vty, "./description", NB_OP_DESTROY, NULL);
7047
7048 return nb_cli_apply_changes(vty, base_xpath);
7049 }
7050
7051 ALIAS_YANG(no_neighbor_description, no_neighbor_description_comment_cmd,
7052 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
7053 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7054 "Neighbor specific description\n"
7055 "Up to 80 characters describing this neighbor\n")
7056
7057 #define BGP_UPDATE_SOURCE_HELP_STR \
7058 "IPv4 address\n" \
7059 "IPv6 address\n" \
7060 "Interface name (requires zebra to be running)\n"
7061
7062 DEFUN_YANG (neighbor_update_source,
7063 neighbor_update_source_cmd,
7064 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
7065 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7066 "Source of routing updates\n"
7067 BGP_UPDATE_SOURCE_HELP_STR)
7068 {
7069 int idx_peer = 1;
7070 int idx_peer_2 = 3;
7071 union sockunion su;
7072 char base_xpath[XPATH_MAXLEN];
7073
7074 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7075 sizeof(base_xpath), NULL)
7076 < 0)
7077 return CMD_WARNING_CONFIG_FAILED;
7078
7079 if (str2sockunion(argv[idx_peer_2]->arg, &su) == 0)
7080 nb_cli_enqueue_change(vty, "./update-source/ip", NB_OP_MODIFY,
7081 argv[idx_peer_2]->arg);
7082 else
7083 nb_cli_enqueue_change(vty, "./update-source/interface",
7084 NB_OP_MODIFY, argv[idx_peer_2]->arg);
7085
7086 return nb_cli_apply_changes(vty, base_xpath);
7087 }
7088
7089 DEFUN_YANG (no_neighbor_update_source,
7090 no_neighbor_update_source_cmd,
7091 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
7092 NO_STR NEIGHBOR_STR
7093 NEIGHBOR_ADDR_STR2
7094 "Source of routing updates\n"
7095 BGP_UPDATE_SOURCE_HELP_STR)
7096 {
7097 int idx_peer = 2;
7098 char base_xpath[XPATH_MAXLEN];
7099
7100 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7101 sizeof(base_xpath), NULL)
7102 < 0)
7103 return CMD_WARNING_CONFIG_FAILED;
7104
7105 nb_cli_enqueue_change(vty, "./update-source/ip", NB_OP_DESTROY, NULL);
7106 nb_cli_enqueue_change(vty, "./update-source/interface", NB_OP_DESTROY,
7107 NULL);
7108
7109 return nb_cli_apply_changes(vty, base_xpath);
7110 }
7111
7112 static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
7113 afi_t afi, safi_t safi,
7114 const char *rmap, int set)
7115 {
7116 int ret;
7117 struct peer *peer;
7118 struct route_map *route_map = NULL;
7119
7120 peer = peer_and_group_lookup_vty(vty, peer_str);
7121 if (!peer)
7122 return CMD_WARNING_CONFIG_FAILED;
7123
7124 if (set) {
7125 if (rmap)
7126 route_map = route_map_lookup_warn_noexist(vty, rmap);
7127 ret = peer_default_originate_set(peer, afi, safi,
7128 rmap, route_map);
7129 } else
7130 ret = peer_default_originate_unset(peer, afi, safi);
7131
7132 return bgp_vty_return(vty, ret);
7133 }
7134
7135 /* neighbor default-originate. */
7136 DEFUN (neighbor_default_originate,
7137 neighbor_default_originate_cmd,
7138 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
7139 NEIGHBOR_STR
7140 NEIGHBOR_ADDR_STR2
7141 "Originate default route to this neighbor\n")
7142 {
7143 int idx_peer = 1;
7144 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
7145 bgp_node_afi(vty),
7146 bgp_node_safi(vty), NULL, 1);
7147 }
7148
7149 ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
7150 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
7151 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7152 "Originate default route to this neighbor\n")
7153
7154 DEFUN (neighbor_default_originate_rmap,
7155 neighbor_default_originate_rmap_cmd,
7156 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
7157 NEIGHBOR_STR
7158 NEIGHBOR_ADDR_STR2
7159 "Originate default route to this neighbor\n"
7160 "Route-map to specify criteria to originate default\n"
7161 "route-map name\n")
7162 {
7163 int idx_peer = 1;
7164 int idx_word = 4;
7165 return peer_default_originate_set_vty(
7166 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7167 argv[idx_word]->arg, 1);
7168 }
7169
7170 ALIAS_HIDDEN(
7171 neighbor_default_originate_rmap,
7172 neighbor_default_originate_rmap_hidden_cmd,
7173 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
7174 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7175 "Originate default route to this neighbor\n"
7176 "Route-map to specify criteria to originate default\n"
7177 "route-map name\n")
7178
7179 DEFUN (no_neighbor_default_originate,
7180 no_neighbor_default_originate_cmd,
7181 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
7182 NO_STR
7183 NEIGHBOR_STR
7184 NEIGHBOR_ADDR_STR2
7185 "Originate default route to this neighbor\n"
7186 "Route-map to specify criteria to originate default\n"
7187 "route-map name\n")
7188 {
7189 int idx_peer = 2;
7190 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
7191 bgp_node_afi(vty),
7192 bgp_node_safi(vty), NULL, 0);
7193 }
7194
7195 ALIAS_HIDDEN(
7196 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
7197 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
7198 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7199 "Originate default route to this neighbor\n"
7200 "Route-map to specify criteria to originate default\n"
7201 "route-map name\n")
7202
7203
7204 /* Set specified peer's BGP port. */
7205 DEFUN_YANG (neighbor_port,
7206 neighbor_port_cmd,
7207 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
7208 NEIGHBOR_STR
7209 NEIGHBOR_ADDR_STR
7210 "Neighbor's BGP port\n"
7211 "TCP port number\n")
7212 {
7213 int idx_ip = 1;
7214 int idx_number = 3;
7215 char base_xpath[XPATH_MAXLEN];
7216
7217 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_NUM_XPATH,
7218 argv[idx_ip]->arg, "");
7219
7220 nb_cli_enqueue_change(vty, "./local-port", NB_OP_MODIFY,
7221 argv[idx_number]->arg);
7222
7223 return nb_cli_apply_changes(vty, base_xpath);
7224 }
7225
7226 DEFUN_YANG (no_neighbor_port,
7227 no_neighbor_port_cmd,
7228 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
7229 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR
7230 "Neighbor's BGP port\n"
7231 "TCP port number\n")
7232 {
7233 int idx_ip = 2;
7234 char base_xpath[XPATH_MAXLEN];
7235
7236 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_NUM_XPATH,
7237 argv[idx_ip]->arg, "");
7238
7239 nb_cli_enqueue_change(vty, "./local-port", NB_OP_DESTROY, NULL);
7240
7241 return nb_cli_apply_changes(vty, base_xpath);
7242 }
7243
7244 DEFUN_YANG (neighbor_weight,
7245 neighbor_weight_cmd,
7246 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7247 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7248 "Set default weight for routes from this neighbor\n"
7249 "default weight\n")
7250 {
7251 int idx_peer = 1;
7252 int idx_number = 3;
7253 char base_xpath[XPATH_MAXLEN];
7254 char af_xpath[XPATH_MAXLEN];
7255 char attr_xpath[XPATH_MAXLEN];
7256 afi_t afi = bgp_node_afi(vty);
7257 safi_t safi = bgp_node_safi(vty);
7258
7259 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
7260 yang_afi_safi_value2identity(afi, safi));
7261
7262 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7263 sizeof(base_xpath), af_xpath)
7264 < 0)
7265 return CMD_WARNING_CONFIG_FAILED;
7266
7267 snprintf(attr_xpath, sizeof(attr_xpath), "./%s/weight/weight-attribute",
7268 bgp_afi_safi_get_container_str(afi, safi));
7269
7270 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY,
7271 argv[idx_number]->arg);
7272
7273 return nb_cli_apply_changes(vty, base_xpath);
7274 }
7275
7276 ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
7277 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7278 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7279 "Set default weight for routes from this neighbor\n"
7280 "default weight\n")
7281
7282 DEFUN_YANG (no_neighbor_weight,
7283 no_neighbor_weight_cmd,
7284 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7285 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7286 "Set default weight for routes from this neighbor\n"
7287 "default weight\n")
7288 {
7289 int idx_peer = 2;
7290 char base_xpath[XPATH_MAXLEN];
7291 char af_xpath[XPATH_MAXLEN];
7292 char attr_xpath[XPATH_MAXLEN];
7293 afi_t afi = bgp_node_afi(vty);
7294 safi_t safi = bgp_node_safi(vty);
7295
7296 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
7297 yang_afi_safi_value2identity(afi, safi));
7298
7299 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7300 sizeof(base_xpath), af_xpath)
7301 < 0)
7302 return CMD_WARNING_CONFIG_FAILED;
7303
7304 snprintf(attr_xpath, sizeof(attr_xpath), "./%s/weight/weight-attribute",
7305 bgp_afi_safi_get_container_str(afi, safi));
7306
7307 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_DESTROY, NULL);
7308
7309 return nb_cli_apply_changes(vty, base_xpath);
7310 }
7311
7312 ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
7313 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7314 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7315 "Set default weight for routes from this neighbor\n"
7316 "default weight\n")
7317
7318
7319 /* Override capability negotiation. */
7320 DEFUN_YANG (neighbor_override_capability,
7321 neighbor_override_capability_cmd,
7322 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7323 NEIGHBOR_STR
7324 NEIGHBOR_ADDR_STR2
7325 "Override capability negotiation result\n")
7326 {
7327 int idx_peer = 1;
7328 char base_xpath[XPATH_MAXLEN];
7329
7330 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7331 sizeof(base_xpath), NULL)
7332 < 0)
7333 return CMD_WARNING_CONFIG_FAILED;
7334
7335 nb_cli_enqueue_change(
7336 vty, "./capability-options/override-capability",
7337 NB_OP_MODIFY, "true");
7338
7339 return nb_cli_apply_changes(vty, base_xpath);
7340 }
7341
7342 DEFUN_YANG (no_neighbor_override_capability,
7343 no_neighbor_override_capability_cmd,
7344 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7345 NO_STR
7346 NEIGHBOR_STR
7347 NEIGHBOR_ADDR_STR2
7348 "Override capability negotiation result\n")
7349 {
7350 int idx_peer = 2;
7351 char base_xpath[XPATH_MAXLEN];
7352
7353 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7354 sizeof(base_xpath), NULL)
7355 < 0)
7356 return CMD_WARNING_CONFIG_FAILED;
7357
7358 nb_cli_enqueue_change(
7359 vty, "./capability-options/override-capability",
7360 NB_OP_MODIFY, "false");
7361
7362 return nb_cli_apply_changes(vty, base_xpath);
7363 }
7364
7365 DEFUN_YANG (neighbor_strict_capability,
7366 neighbor_strict_capability_cmd,
7367 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7368 NEIGHBOR_STR
7369 NEIGHBOR_ADDR_STR2
7370 "Strict capability negotiation match\n")
7371 {
7372 int idx_peer = 1;
7373 char base_xpath[XPATH_MAXLEN];
7374
7375 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7376 sizeof(base_xpath), NULL)
7377 < 0)
7378 return CMD_WARNING_CONFIG_FAILED;
7379
7380 nb_cli_enqueue_change(
7381 vty, "./capability-options/strict-capability",
7382 NB_OP_MODIFY, "true");
7383
7384 return nb_cli_apply_changes(vty, base_xpath);
7385 }
7386
7387 DEFUN_YANG (no_neighbor_strict_capability,
7388 no_neighbor_strict_capability_cmd,
7389 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7390 NO_STR
7391 NEIGHBOR_STR
7392 NEIGHBOR_ADDR_STR2
7393 "Strict capability negotiation match\n")
7394 {
7395 int idx_peer = 2;
7396 char base_xpath[XPATH_MAXLEN];
7397
7398 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7399 sizeof(base_xpath), NULL)
7400 < 0)
7401 return CMD_WARNING_CONFIG_FAILED;
7402
7403 nb_cli_enqueue_change(
7404 vty, "./capability-options/strict-capability",
7405 NB_OP_MODIFY, "false");
7406
7407 return nb_cli_apply_changes(vty, base_xpath);
7408 }
7409
7410 DEFUN_YANG (neighbor_timers,
7411 neighbor_timers_cmd,
7412 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
7413 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7414 "BGP per neighbor timers\n"
7415 "Keepalive interval\n"
7416 "Holdtime\n")
7417 {
7418 int idx_peer = 1;
7419 int idx_number = 3;
7420 int idx_number_2 = 4;
7421 char base_xpath[XPATH_MAXLEN];
7422
7423 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7424 sizeof(base_xpath), NULL)
7425 < 0)
7426 return CMD_WARNING_CONFIG_FAILED;
7427
7428 nb_cli_enqueue_change(vty, "./timers/keepalive", NB_OP_MODIFY,
7429 argv[idx_number]->arg);
7430
7431 nb_cli_enqueue_change(vty, "./timers/hold-time", NB_OP_MODIFY,
7432 argv[idx_number_2]->arg);
7433
7434 return nb_cli_apply_changes(vty, base_xpath);
7435 }
7436
7437 DEFUN_YANG (no_neighbor_timers,
7438 no_neighbor_timers_cmd,
7439 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
7440 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7441 "BGP per neighbor timers\n"
7442 "Keepalive interval\n"
7443 "Holdtime\n")
7444 {
7445 int idx_peer = 2;
7446 char base_xpath[XPATH_MAXLEN];
7447
7448 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7449 sizeof(base_xpath), NULL)
7450 < 0)
7451 return CMD_WARNING_CONFIG_FAILED;
7452
7453 nb_cli_enqueue_change(vty, "./timers/hold-time", NB_OP_DESTROY, NULL);
7454
7455 nb_cli_enqueue_change(vty, "./timers/keepalive", NB_OP_DESTROY, NULL);
7456
7457 return nb_cli_apply_changes(vty, base_xpath);
7458 }
7459
7460 DEFUN_YANG (neighbor_timers_connect,
7461 neighbor_timers_connect_cmd,
7462 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
7463 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7464 "BGP per neighbor timers\n"
7465 "BGP connect timer\n"
7466 "Connect timer\n")
7467 {
7468 int idx_peer = 1;
7469 int idx_number = 4;
7470 char base_xpath[XPATH_MAXLEN];
7471
7472 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7473 sizeof(base_xpath), NULL)
7474 < 0)
7475 return CMD_WARNING_CONFIG_FAILED;
7476
7477 nb_cli_enqueue_change(vty, "./timers/connect-time", NB_OP_MODIFY,
7478 argv[idx_number]->arg);
7479
7480 return nb_cli_apply_changes(vty, base_xpath);
7481 }
7482
7483 DEFUN_YANG (no_neighbor_timers_connect,
7484 no_neighbor_timers_connect_cmd,
7485 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
7486 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7487 "BGP per neighbor timers\n"
7488 "BGP connect timer\n"
7489 "Connect timer\n")
7490 {
7491 int idx_peer = 2;
7492 char base_xpath[XPATH_MAXLEN];
7493
7494 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7495 sizeof(base_xpath), NULL)
7496 < 0)
7497 return CMD_WARNING_CONFIG_FAILED;
7498
7499 nb_cli_enqueue_change(vty, "./timers/connect-time", NB_OP_DESTROY,
7500 NULL);
7501
7502 return nb_cli_apply_changes(vty, base_xpath);
7503 }
7504
7505 DEFPY (neighbor_timers_delayopen,
7506 neighbor_timers_delayopen_cmd,
7507 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen (1-240)$interval",
7508 NEIGHBOR_STR
7509 NEIGHBOR_ADDR_STR2
7510 "BGP per neighbor timers\n"
7511 "RFC 4271 DelayOpenTimer\n"
7512 "DelayOpenTime timer interval\n")
7513 {
7514 struct peer *peer;
7515
7516 peer = peer_and_group_lookup_vty(vty, neighbor);
7517 if (!peer)
7518 return CMD_WARNING_CONFIG_FAILED;
7519
7520 if (!interval) {
7521 if (peer_timers_delayopen_unset(peer))
7522 return CMD_WARNING_CONFIG_FAILED;
7523 } else {
7524 if (peer_timers_delayopen_set(peer, interval))
7525 return CMD_WARNING_CONFIG_FAILED;
7526 }
7527
7528 return CMD_SUCCESS;
7529 }
7530
7531 DEFPY (no_neighbor_timers_delayopen,
7532 no_neighbor_timers_delayopen_cmd,
7533 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen [(0-65535)]",
7534 NO_STR
7535 NEIGHBOR_STR
7536 NEIGHBOR_ADDR_STR2
7537 "BGP per neighbor timers\n"
7538 "RFC 4271 DelayOpenTimer\n"
7539 "DelayOpenTime timer interval\n")
7540 {
7541 struct peer *peer;
7542
7543 peer = peer_and_group_lookup_vty(vty, neighbor);
7544 if (!peer)
7545 return CMD_WARNING_CONFIG_FAILED;
7546
7547 if (peer_timers_delayopen_unset(peer))
7548 return CMD_WARNING_CONFIG_FAILED;
7549
7550 return CMD_SUCCESS;
7551 }
7552
7553 DEFUN_YANG (neighbor_advertise_interval,
7554 neighbor_advertise_interval_cmd,
7555 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
7556 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7557 "Minimum interval between sending BGP routing updates\n"
7558 "time in seconds\n")
7559 {
7560 int idx_peer = 1;
7561 int idx_number = 3;
7562 char base_xpath[XPATH_MAXLEN];
7563
7564 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7565 sizeof(base_xpath), NULL)
7566 < 0)
7567 return CMD_WARNING_CONFIG_FAILED;
7568
7569 nb_cli_enqueue_change(vty, "./timers/advertise-interval", NB_OP_MODIFY,
7570 argv[idx_number]->arg);
7571
7572 return nb_cli_apply_changes(vty, base_xpath);
7573 }
7574
7575 DEFUN_YANG (no_neighbor_advertise_interval,
7576 no_neighbor_advertise_interval_cmd,
7577 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
7578 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7579 "Minimum interval between sending BGP routing updates\n"
7580 "time in seconds\n")
7581 {
7582 int idx_peer = 2;
7583 char base_xpath[XPATH_MAXLEN];
7584
7585 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7586 sizeof(base_xpath), NULL)
7587 < 0)
7588 return CMD_WARNING_CONFIG_FAILED;
7589
7590 nb_cli_enqueue_change(vty, "./timers/advertise-interval", NB_OP_DESTROY,
7591 NULL);
7592
7593 return nb_cli_apply_changes(vty, base_xpath);
7594 }
7595
7596
7597 /* Time to wait before processing route-map updates */
7598 DEFUN (bgp_set_route_map_delay_timer,
7599 bgp_set_route_map_delay_timer_cmd,
7600 "bgp route-map delay-timer (0-600)",
7601 SET_STR
7602 "BGP route-map delay timer\n"
7603 "Time in secs to wait before processing route-map changes\n"
7604 "0 disables the timer, no route updates happen when route-maps change\n")
7605 {
7606 int idx_number = 3;
7607 uint32_t rmap_delay_timer;
7608
7609 if (argv[idx_number]->arg) {
7610 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
7611 bm->rmap_update_timer = rmap_delay_timer;
7612
7613 /* if the dynamic update handling is being disabled, and a timer
7614 * is
7615 * running, stop the timer and act as if the timer has already
7616 * fired.
7617 */
7618 if (!rmap_delay_timer && bm->t_rmap_update) {
7619 BGP_TIMER_OFF(bm->t_rmap_update);
7620 thread_execute(bm->master, bgp_route_map_update_timer,
7621 NULL, 0);
7622 }
7623 return CMD_SUCCESS;
7624 } else {
7625 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
7626 return CMD_WARNING_CONFIG_FAILED;
7627 }
7628 }
7629
7630 DEFUN (no_bgp_set_route_map_delay_timer,
7631 no_bgp_set_route_map_delay_timer_cmd,
7632 "no bgp route-map delay-timer [(0-600)]",
7633 NO_STR
7634 BGP_STR
7635 "Default BGP route-map delay timer\n"
7636 "Reset to default time to wait for processing route-map changes\n"
7637 "0 disables the timer, no route updates happen when route-maps change\n")
7638 {
7639
7640 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
7641
7642 return CMD_SUCCESS;
7643 }
7644
7645 DEFUN_YANG (neighbor_interface,
7646 neighbor_interface_cmd,
7647 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
7648 NEIGHBOR_STR NEIGHBOR_ADDR_STR
7649 "Interface\n"
7650 "Interface name\n")
7651 {
7652 int idx_ip = 1;
7653 int idx_word = 3;
7654 char base_xpath[XPATH_MAXLEN];
7655
7656 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_NUM_XPATH,
7657 argv[idx_ip]->arg, "");
7658
7659 nb_cli_enqueue_change(vty, "./local-interface", NB_OP_MODIFY,
7660 argv[idx_word]->arg);
7661
7662 return nb_cli_apply_changes(vty, base_xpath);
7663 }
7664
7665 DEFUN_YANG (no_neighbor_interface,
7666 no_neighbor_interface_cmd,
7667 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
7668 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7669 "Interface\n"
7670 "Interface name\n")
7671 {
7672 int idx_peer = 2;
7673 char base_xpath[XPATH_MAXLEN];
7674
7675 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_NUM_XPATH,
7676 argv[idx_peer]->arg, "");
7677
7678 nb_cli_enqueue_change(vty, "./local-interface", NB_OP_DESTROY, NULL);
7679
7680 return nb_cli_apply_changes(vty, base_xpath);
7681 }
7682
7683 DEFUN (neighbor_distribute_list,
7684 neighbor_distribute_list_cmd,
7685 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
7686 NEIGHBOR_STR
7687 NEIGHBOR_ADDR_STR2
7688 "Filter updates to/from this neighbor\n"
7689 "IP access-list number\n"
7690 "IP access-list number (expanded range)\n"
7691 "IP Access-list name\n"
7692 "Filter incoming updates\n"
7693 "Filter outgoing updates\n")
7694 {
7695 int idx_peer = 1;
7696 int idx_acl = 3;
7697 int direct, ret;
7698 struct peer *peer;
7699
7700 const char *pstr = argv[idx_peer]->arg;
7701 const char *acl = argv[idx_acl]->arg;
7702 const char *inout = argv[argc - 1]->text;
7703
7704 peer = peer_and_group_lookup_vty(vty, pstr);
7705 if (!peer)
7706 return CMD_WARNING_CONFIG_FAILED;
7707
7708 /* Check filter direction. */
7709 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7710 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7711 direct, acl);
7712
7713 return bgp_vty_return(vty, ret);
7714 }
7715
7716 ALIAS_HIDDEN(
7717 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
7718 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
7719 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7720 "Filter updates to/from this neighbor\n"
7721 "IP access-list number\n"
7722 "IP access-list number (expanded range)\n"
7723 "IP Access-list name\n"
7724 "Filter incoming updates\n"
7725 "Filter outgoing updates\n")
7726
7727 DEFUN (no_neighbor_distribute_list,
7728 no_neighbor_distribute_list_cmd,
7729 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
7730 NO_STR
7731 NEIGHBOR_STR
7732 NEIGHBOR_ADDR_STR2
7733 "Filter updates to/from this neighbor\n"
7734 "IP access-list number\n"
7735 "IP access-list number (expanded range)\n"
7736 "IP Access-list name\n"
7737 "Filter incoming updates\n"
7738 "Filter outgoing updates\n")
7739 {
7740 int idx_peer = 2;
7741 int direct, ret;
7742 struct peer *peer;
7743
7744 const char *pstr = argv[idx_peer]->arg;
7745 const char *inout = argv[argc - 1]->text;
7746
7747 peer = peer_and_group_lookup_vty(vty, pstr);
7748 if (!peer)
7749 return CMD_WARNING_CONFIG_FAILED;
7750
7751 /* Check filter direction. */
7752 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7753 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7754 direct);
7755
7756 return bgp_vty_return(vty, ret);
7757 }
7758
7759 ALIAS_HIDDEN(
7760 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
7761 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
7762 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7763 "Filter updates to/from this neighbor\n"
7764 "IP access-list number\n"
7765 "IP access-list number (expanded range)\n"
7766 "IP Access-list name\n"
7767 "Filter incoming updates\n"
7768 "Filter outgoing updates\n")
7769
7770 /* Set prefix list to the peer. */
7771 static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
7772 afi_t afi, safi_t safi,
7773 const char *name_str,
7774 const char *direct_str)
7775 {
7776 int ret;
7777 int direct = FILTER_IN;
7778 struct peer *peer;
7779
7780 peer = peer_and_group_lookup_vty(vty, ip_str);
7781 if (!peer)
7782 return CMD_WARNING_CONFIG_FAILED;
7783
7784 /* Check filter direction. */
7785 if (strncmp(direct_str, "i", 1) == 0)
7786 direct = FILTER_IN;
7787 else if (strncmp(direct_str, "o", 1) == 0)
7788 direct = FILTER_OUT;
7789
7790 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
7791
7792 return bgp_vty_return(vty, ret);
7793 }
7794
7795 static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
7796 afi_t afi, safi_t safi,
7797 const char *direct_str)
7798 {
7799 int ret;
7800 struct peer *peer;
7801 int direct = FILTER_IN;
7802
7803 peer = peer_and_group_lookup_vty(vty, ip_str);
7804 if (!peer)
7805 return CMD_WARNING_CONFIG_FAILED;
7806
7807 /* Check filter direction. */
7808 if (strncmp(direct_str, "i", 1) == 0)
7809 direct = FILTER_IN;
7810 else if (strncmp(direct_str, "o", 1) == 0)
7811 direct = FILTER_OUT;
7812
7813 ret = peer_prefix_list_unset(peer, afi, safi, direct);
7814
7815 return bgp_vty_return(vty, ret);
7816 }
7817
7818 DEFUN (neighbor_prefix_list,
7819 neighbor_prefix_list_cmd,
7820 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7821 NEIGHBOR_STR
7822 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 int idx_peer = 1;
7829 int idx_word = 3;
7830 int idx_in_out = 4;
7831 return peer_prefix_list_set_vty(
7832 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7833 argv[idx_word]->arg, argv[idx_in_out]->arg);
7834 }
7835
7836 ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
7837 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7838 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7839 "Filter updates to/from this neighbor\n"
7840 "Name of a prefix list\n"
7841 "Filter incoming updates\n"
7842 "Filter outgoing updates\n")
7843
7844 DEFUN (no_neighbor_prefix_list,
7845 no_neighbor_prefix_list_cmd,
7846 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7847 NO_STR
7848 NEIGHBOR_STR
7849 NEIGHBOR_ADDR_STR2
7850 "Filter updates to/from this neighbor\n"
7851 "Name of a prefix list\n"
7852 "Filter incoming updates\n"
7853 "Filter outgoing updates\n")
7854 {
7855 int idx_peer = 2;
7856 int idx_in_out = 5;
7857 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
7858 bgp_node_afi(vty), bgp_node_safi(vty),
7859 argv[idx_in_out]->arg);
7860 }
7861
7862 ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
7863 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7864 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7865 "Filter updates to/from this neighbor\n"
7866 "Name of a prefix list\n"
7867 "Filter incoming updates\n"
7868 "Filter outgoing updates\n")
7869
7870 static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7871 safi_t safi, const char *name_str,
7872 const char *direct_str)
7873 {
7874 int ret;
7875 struct peer *peer;
7876 int direct = FILTER_IN;
7877
7878 peer = peer_and_group_lookup_vty(vty, ip_str);
7879 if (!peer)
7880 return CMD_WARNING_CONFIG_FAILED;
7881
7882 /* Check filter direction. */
7883 if (strncmp(direct_str, "i", 1) == 0)
7884 direct = FILTER_IN;
7885 else if (strncmp(direct_str, "o", 1) == 0)
7886 direct = FILTER_OUT;
7887
7888 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
7889
7890 return bgp_vty_return(vty, ret);
7891 }
7892
7893 static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7894 safi_t safi, const char *direct_str)
7895 {
7896 int ret;
7897 struct peer *peer;
7898 int direct = FILTER_IN;
7899
7900 peer = peer_and_group_lookup_vty(vty, ip_str);
7901 if (!peer)
7902 return CMD_WARNING_CONFIG_FAILED;
7903
7904 /* Check filter direction. */
7905 if (strncmp(direct_str, "i", 1) == 0)
7906 direct = FILTER_IN;
7907 else if (strncmp(direct_str, "o", 1) == 0)
7908 direct = FILTER_OUT;
7909
7910 ret = peer_aslist_unset(peer, afi, safi, direct);
7911
7912 return bgp_vty_return(vty, ret);
7913 }
7914
7915 DEFUN (neighbor_filter_list,
7916 neighbor_filter_list_cmd,
7917 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
7918 NEIGHBOR_STR
7919 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 int idx_peer = 1;
7926 int idx_word = 3;
7927 int idx_in_out = 4;
7928 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7929 bgp_node_safi(vty), argv[idx_word]->arg,
7930 argv[idx_in_out]->arg);
7931 }
7932
7933 ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
7934 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
7935 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7936 "Establish BGP filters\n"
7937 "AS path access-list name\n"
7938 "Filter incoming routes\n"
7939 "Filter outgoing routes\n")
7940
7941 DEFUN (no_neighbor_filter_list,
7942 no_neighbor_filter_list_cmd,
7943 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
7944 NO_STR
7945 NEIGHBOR_STR
7946 NEIGHBOR_ADDR_STR2
7947 "Establish BGP filters\n"
7948 "AS path access-list name\n"
7949 "Filter incoming routes\n"
7950 "Filter outgoing routes\n")
7951 {
7952 int idx_peer = 2;
7953 int idx_in_out = 5;
7954 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
7955 bgp_node_afi(vty), bgp_node_safi(vty),
7956 argv[idx_in_out]->arg);
7957 }
7958
7959 ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
7960 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
7961 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7962 "Establish BGP filters\n"
7963 "AS path access-list name\n"
7964 "Filter incoming routes\n"
7965 "Filter outgoing routes\n")
7966
7967 /* Set advertise-map to the peer. */
7968 static int peer_advertise_map_set_vty(struct vty *vty, const char *ip_str,
7969 afi_t afi, safi_t safi,
7970 const char *advertise_str,
7971 const char *condition_str, bool condition,
7972 bool set)
7973 {
7974 int ret = CMD_WARNING_CONFIG_FAILED;
7975 struct peer *peer;
7976 struct route_map *advertise_map;
7977 struct route_map *condition_map;
7978
7979 peer = peer_and_group_lookup_vty(vty, ip_str);
7980 if (!peer)
7981 return ret;
7982
7983 condition_map = route_map_lookup_warn_noexist(vty, condition_str);
7984 advertise_map = route_map_lookup_warn_noexist(vty, advertise_str);
7985
7986 if (set)
7987 ret = peer_advertise_map_set(peer, afi, safi, advertise_str,
7988 advertise_map, condition_str,
7989 condition_map, condition);
7990 else
7991 ret = peer_advertise_map_unset(peer, afi, safi, advertise_str,
7992 advertise_map, condition_str,
7993 condition_map, condition);
7994
7995 return bgp_vty_return(vty, ret);
7996 }
7997
7998 DEFPY (neighbor_advertise_map,
7999 neighbor_advertise_map_cmd,
8000 "[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",
8001 NO_STR
8002 NEIGHBOR_STR
8003 NEIGHBOR_ADDR_STR2
8004 "Route-map to conditionally advertise routes\n"
8005 "Name of advertise map\n"
8006 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
8007 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
8008 "Name of the exist or non exist map\n")
8009 {
8010 bool condition = CONDITION_EXIST;
8011
8012 if (!strcmp(exist, "non-exist-map"))
8013 condition = CONDITION_NON_EXIST;
8014
8015 return peer_advertise_map_set_vty(vty, neighbor, bgp_node_afi(vty),
8016 bgp_node_safi(vty), advertise_str,
8017 condition_str, condition, !no);
8018 }
8019
8020 ALIAS_HIDDEN(neighbor_advertise_map, neighbor_advertise_map_hidden_cmd,
8021 "[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",
8022 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8023 "Route-map to conditionally advertise routes\n"
8024 "Name of advertise map\n"
8025 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
8026 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
8027 "Name of the exist or non exist map\n")
8028
8029 /* Set route-map to the peer. */
8030 static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
8031 afi_t afi, safi_t safi, const char *name_str,
8032 const char *direct_str)
8033 {
8034 int ret;
8035 struct peer *peer;
8036 int direct = RMAP_IN;
8037 struct route_map *route_map;
8038
8039 peer = peer_and_group_lookup_vty(vty, ip_str);
8040 if (!peer)
8041 return CMD_WARNING_CONFIG_FAILED;
8042
8043 /* Check filter direction. */
8044 if (strncmp(direct_str, "in", 2) == 0)
8045 direct = RMAP_IN;
8046 else if (strncmp(direct_str, "o", 1) == 0)
8047 direct = RMAP_OUT;
8048
8049 route_map = route_map_lookup_warn_noexist(vty, name_str);
8050 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
8051
8052 return bgp_vty_return(vty, ret);
8053 }
8054
8055 static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
8056 afi_t afi, safi_t safi,
8057 const char *direct_str)
8058 {
8059 int ret;
8060 struct peer *peer;
8061 int direct = RMAP_IN;
8062
8063 peer = peer_and_group_lookup_vty(vty, ip_str);
8064 if (!peer)
8065 return CMD_WARNING_CONFIG_FAILED;
8066
8067 /* Check filter direction. */
8068 if (strncmp(direct_str, "in", 2) == 0)
8069 direct = RMAP_IN;
8070 else if (strncmp(direct_str, "o", 1) == 0)
8071 direct = RMAP_OUT;
8072
8073 ret = peer_route_map_unset(peer, afi, safi, direct);
8074
8075 return bgp_vty_return(vty, ret);
8076 }
8077
8078 DEFUN (neighbor_route_map,
8079 neighbor_route_map_cmd,
8080 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
8081 NEIGHBOR_STR
8082 NEIGHBOR_ADDR_STR2
8083 "Apply route map to neighbor\n"
8084 "Name of route map\n"
8085 "Apply map to incoming routes\n"
8086 "Apply map to outbound routes\n")
8087 {
8088 int idx_peer = 1;
8089 int idx_word = 3;
8090 int idx_in_out = 4;
8091 return peer_route_map_set_vty(
8092 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8093 argv[idx_word]->arg, argv[idx_in_out]->arg);
8094 }
8095
8096 ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
8097 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
8098 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8099 "Apply route map to neighbor\n"
8100 "Name of route map\n"
8101 "Apply map to incoming routes\n"
8102 "Apply map to outbound routes\n")
8103
8104 DEFUN (no_neighbor_route_map,
8105 no_neighbor_route_map_cmd,
8106 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
8107 NO_STR
8108 NEIGHBOR_STR
8109 NEIGHBOR_ADDR_STR2
8110 "Apply route map to neighbor\n"
8111 "Name of route map\n"
8112 "Apply map to incoming routes\n"
8113 "Apply map to outbound routes\n")
8114 {
8115 int idx_peer = 2;
8116 int idx_in_out = 5;
8117 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
8118 bgp_node_afi(vty), bgp_node_safi(vty),
8119 argv[idx_in_out]->arg);
8120 }
8121
8122 ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
8123 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
8124 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8125 "Apply route map to neighbor\n"
8126 "Name of route map\n"
8127 "Apply map to incoming routes\n"
8128 "Apply map to outbound routes\n")
8129
8130 /* Set unsuppress-map to the peer. */
8131 static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
8132 afi_t afi, safi_t safi,
8133 const char *name_str)
8134 {
8135 int ret;
8136 struct peer *peer;
8137 struct route_map *route_map;
8138
8139 peer = peer_and_group_lookup_vty(vty, ip_str);
8140 if (!peer)
8141 return CMD_WARNING_CONFIG_FAILED;
8142
8143 route_map = route_map_lookup_warn_noexist(vty, name_str);
8144 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
8145
8146 return bgp_vty_return(vty, ret);
8147 }
8148
8149 /* Unset route-map from the peer. */
8150 static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
8151 afi_t afi, safi_t safi)
8152 {
8153 int ret;
8154 struct peer *peer;
8155
8156 peer = peer_and_group_lookup_vty(vty, ip_str);
8157 if (!peer)
8158 return CMD_WARNING_CONFIG_FAILED;
8159
8160 ret = peer_unsuppress_map_unset(peer, afi, safi);
8161
8162 return bgp_vty_return(vty, ret);
8163 }
8164
8165 DEFUN (neighbor_unsuppress_map,
8166 neighbor_unsuppress_map_cmd,
8167 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8168 NEIGHBOR_STR
8169 NEIGHBOR_ADDR_STR2
8170 "Route-map to selectively unsuppress suppressed routes\n"
8171 "Name of route map\n")
8172 {
8173 int idx_peer = 1;
8174 int idx_word = 3;
8175 return peer_unsuppress_map_set_vty(
8176 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8177 argv[idx_word]->arg);
8178 }
8179
8180 ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
8181 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8182 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8183 "Route-map to selectively unsuppress suppressed routes\n"
8184 "Name of route map\n")
8185
8186 DEFUN (no_neighbor_unsuppress_map,
8187 no_neighbor_unsuppress_map_cmd,
8188 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8189 NO_STR
8190 NEIGHBOR_STR
8191 NEIGHBOR_ADDR_STR2
8192 "Route-map to selectively unsuppress suppressed routes\n"
8193 "Name of route map\n")
8194 {
8195 int idx_peer = 2;
8196 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
8197 bgp_node_afi(vty),
8198 bgp_node_safi(vty));
8199 }
8200
8201 ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
8202 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8203 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8204 "Route-map to selectively unsuppress suppressed routes\n"
8205 "Name of route map\n")
8206
8207 /* Maximum number of prefix to be sent to the neighbor. */
8208 DEFUN_YANG(neighbor_maximum_prefix_out,
8209 neighbor_maximum_prefix_out_cmd,
8210 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out (1-4294967295)",
8211 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8212 "Maximum number of prefixes to be sent to this peer\n"
8213 "Maximum no. of prefix limit\n")
8214 {
8215 char base_xpath[XPATH_MAXLEN];
8216 char af_xpath[XPATH_MAXLEN];
8217 char attr_xpath[XPATH_MAXLEN];
8218 int idx_peer = 1;
8219 int idx_number = 3;
8220 afi_t afi = bgp_node_afi(vty);
8221 safi_t safi = bgp_node_safi(vty);
8222
8223 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8224 yang_afi_safi_value2identity(afi, safi));
8225 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8226 sizeof(base_xpath), af_xpath)
8227 < 0)
8228 return CMD_WARNING_CONFIG_FAILED;
8229
8230 snprintf(attr_xpath, sizeof(attr_xpath),
8231 "/%s/prefix-limit/direction-list[direction='out']",
8232 bgp_afi_safi_get_container_str(afi, safi));
8233 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8234
8235 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8236
8237 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8238 argv[idx_number]->arg);
8239
8240 return nb_cli_apply_changes(vty, base_xpath);
8241 }
8242
8243 DEFUN_YANG(no_neighbor_maximum_prefix_out,
8244 no_neighbor_maximum_prefix_out_cmd,
8245 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out",
8246 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8247 "Maximum number of prefixes to be sent to this peer\n")
8248 {
8249 char base_xpath[XPATH_MAXLEN];
8250 char af_xpath[XPATH_MAXLEN];
8251 char attr_xpath[XPATH_MAXLEN];
8252 int idx_peer = 2;
8253 afi_t afi = bgp_node_afi(vty);
8254 safi_t safi = bgp_node_safi(vty);
8255
8256 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8257 yang_afi_safi_value2identity(afi, safi));
8258 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8259 sizeof(base_xpath), af_xpath)
8260 < 0)
8261 return CMD_WARNING_CONFIG_FAILED;
8262
8263 snprintf(attr_xpath, sizeof(attr_xpath),
8264 "/%s/prefix-limit/direction-list[direction='out']",
8265 bgp_afi_safi_get_container_str(afi, safi));
8266 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8267
8268 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
8269
8270 return nb_cli_apply_changes(vty, base_xpath);
8271 }
8272
8273 /* Maximum number of prefix configuration. Prefix count is different
8274 for each peer configuration. So this configuration can be set for
8275 each peer configuration. */
8276 DEFUN_YANG(neighbor_maximum_prefix,
8277 neighbor_maximum_prefix_cmd,
8278 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [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 "Force checking all received routes not only accepted\n")
8283 {
8284 int idx_peer = 1;
8285 int idx_number = 3;
8286 int idx_force = 0;
8287 char base_xpath[XPATH_MAXLEN];
8288 char af_xpath[XPATH_MAXLEN];
8289 char attr_xpath[XPATH_MAXLEN];
8290 afi_t afi = bgp_node_afi(vty);
8291 safi_t safi = bgp_node_safi(vty);
8292
8293 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8294 yang_afi_safi_value2identity(afi, safi));
8295 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8296 sizeof(base_xpath), af_xpath)
8297 < 0)
8298 return CMD_WARNING_CONFIG_FAILED;
8299
8300 snprintf(attr_xpath, sizeof(attr_xpath),
8301 "/%s/prefix-limit/direction-list[direction='in']",
8302 bgp_afi_safi_get_container_str(afi, safi));
8303 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8304
8305 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8306
8307 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8308 argv[idx_number]->arg);
8309 if (argv_find(argv, argc, "force", &idx_force))
8310 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8311 "true");
8312
8313 return nb_cli_apply_changes(vty, base_xpath);
8314 }
8315
8316 ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
8317 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
8318 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8319 "Maximum number of prefix accept from this peer\n"
8320 "maximum no. of prefix limit\n"
8321 "Force checking all received routes not only accepted\n")
8322
8323 DEFUN_YANG(neighbor_maximum_prefix_threshold,
8324 neighbor_maximum_prefix_threshold_cmd,
8325 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
8326 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8327 "Maximum number of prefix accept from this peer\n"
8328 "maximum no. of prefix limit\n"
8329 "Threshold value (%) at which to generate a warning msg\n"
8330 "Force checking all received routes not only accepted\n")
8331 {
8332 int idx_peer = 1;
8333 int idx_number = 3;
8334 int idx_number_2 = 4;
8335 int idx_force = 0;
8336 char base_xpath[XPATH_MAXLEN];
8337 char af_xpath[XPATH_MAXLEN];
8338 char attr_xpath[XPATH_MAXLEN];
8339 afi_t afi = bgp_node_afi(vty);
8340 safi_t safi = bgp_node_safi(vty);
8341
8342 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8343 yang_afi_safi_value2identity(afi, safi));
8344 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8345 sizeof(base_xpath), af_xpath)
8346 < 0)
8347 return CMD_WARNING_CONFIG_FAILED;
8348
8349 snprintf(attr_xpath, sizeof(attr_xpath),
8350 "/%s/prefix-limit/direction-list[direction='in']",
8351 bgp_afi_safi_get_container_str(afi, safi));
8352 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8353
8354 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8355
8356 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8357 argv[idx_number]->arg);
8358
8359 nb_cli_enqueue_change(vty, "./options/shutdown-threshold-pct",
8360 NB_OP_MODIFY, argv[idx_number_2]->arg);
8361
8362 if (argv_find(argv, argc, "force", &idx_force))
8363 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8364 "true");
8365
8366 return nb_cli_apply_changes(vty, base_xpath);
8367 }
8368
8369 ALIAS_HIDDEN(
8370 neighbor_maximum_prefix_threshold,
8371 neighbor_maximum_prefix_threshold_hidden_cmd,
8372 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
8373 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8374 "Maximum number of prefix accept from this peer\n"
8375 "maximum no. of prefix limit\n"
8376 "Threshold value (%) at which to generate a warning msg\n"
8377 "Force checking all received routes not only accepted\n")
8378
8379 DEFUN_YANG(neighbor_maximum_prefix_warning,
8380 neighbor_maximum_prefix_warning_cmd,
8381 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
8382 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8383 "Maximum number of prefix accept from this peer\n"
8384 "maximum no. of prefix limit\n"
8385 "Only give warning message when limit is exceeded\n"
8386 "Force checking all received routes not only accepted\n")
8387 {
8388 int idx_peer = 1;
8389 int idx_number = 3;
8390 int idx_force = 0;
8391 char base_xpath[XPATH_MAXLEN];
8392 char af_xpath[XPATH_MAXLEN];
8393 char attr_xpath[XPATH_MAXLEN];
8394 afi_t afi = bgp_node_afi(vty);
8395 safi_t safi = bgp_node_safi(vty);
8396
8397 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8398 yang_afi_safi_value2identity(afi, safi));
8399 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8400 sizeof(base_xpath), af_xpath)
8401 < 0)
8402 return CMD_WARNING_CONFIG_FAILED;
8403
8404 snprintf(attr_xpath, sizeof(attr_xpath),
8405 "/%s/prefix-limit/direction-list[direction='in']",
8406 bgp_afi_safi_get_container_str(afi, safi));
8407 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8408
8409 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8410
8411 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8412 argv[idx_number]->arg);
8413
8414 nb_cli_enqueue_change(vty, "./options/warning-only", NB_OP_MODIFY,
8415 "true");
8416 if (argv_find(argv, argc, "force", &idx_force))
8417 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8418 "true");
8419
8420 return nb_cli_apply_changes(vty, base_xpath);
8421 }
8422
8423 ALIAS_HIDDEN(
8424 neighbor_maximum_prefix_warning,
8425 neighbor_maximum_prefix_warning_hidden_cmd,
8426 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
8427 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8428 "Maximum number of prefix accept from this peer\n"
8429 "maximum no. of prefix limit\n"
8430 "Only give warning message when limit is exceeded\n"
8431 "Force checking all received routes not only accepted\n")
8432
8433 DEFUN_YANG(neighbor_maximum_prefix_threshold_warning,
8434 neighbor_maximum_prefix_threshold_warning_cmd,
8435 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
8436 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8437 "Maximum number of prefix accept from this peer\n"
8438 "maximum no. of prefix limit\n"
8439 "Threshold value (%) at which to generate a warning msg\n"
8440 "Only give warning message when limit is exceeded\n"
8441 "Force checking all received routes not only accepted\n")
8442 {
8443 int idx_peer = 1;
8444 int idx_number = 3;
8445 int idx_number_2 = 4;
8446 int idx_force = 0;
8447 char base_xpath[XPATH_MAXLEN];
8448 char af_xpath[XPATH_MAXLEN];
8449 char attr_xpath[XPATH_MAXLEN];
8450 afi_t afi = bgp_node_afi(vty);
8451 safi_t safi = bgp_node_safi(vty);
8452
8453 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8454 yang_afi_safi_value2identity(afi, safi));
8455 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8456 sizeof(base_xpath), af_xpath)
8457 < 0)
8458 return CMD_WARNING_CONFIG_FAILED;
8459
8460 snprintf(attr_xpath, sizeof(attr_xpath),
8461 "/%s/prefix-limit/direction-list[direction='in']",
8462 bgp_afi_safi_get_container_str(afi, safi));
8463 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8464
8465 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8466
8467 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8468 argv[idx_number]->arg);
8469 nb_cli_enqueue_change(vty, "./options/tw-shutdown-threshold-pct",
8470 NB_OP_MODIFY, argv[idx_number_2]->arg);
8471 nb_cli_enqueue_change(vty, "./options/tw-warning-only", NB_OP_MODIFY,
8472 "true");
8473 if (argv_find(argv, argc, "force", &idx_force))
8474 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8475 "true");
8476
8477 return nb_cli_apply_changes(vty, base_xpath);
8478 }
8479
8480 ALIAS_HIDDEN(
8481 neighbor_maximum_prefix_threshold_warning,
8482 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
8483 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
8484 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8485 "Maximum number of prefix accept from this peer\n"
8486 "maximum no. of prefix limit\n"
8487 "Threshold value (%) at which to generate a warning msg\n"
8488 "Only give warning message when limit is exceeded\n"
8489 "Force checking all received routes not only accepted\n")
8490
8491 DEFUN_YANG(neighbor_maximum_prefix_restart,
8492 neighbor_maximum_prefix_restart_cmd,
8493 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8494 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8495 "Maximum number of prefix accept from this peer\n"
8496 "maximum no. of prefix limit\n"
8497 "Restart bgp connection after limit is exceeded\n"
8498 "Restart interval in minutes\n"
8499 "Force checking all received routes not only accepted\n")
8500 {
8501 int idx_peer = 1;
8502 int idx_number = 3;
8503 int idx_number_2 = 5;
8504 int idx_force = 0;
8505 char base_xpath[XPATH_MAXLEN];
8506 char af_xpath[XPATH_MAXLEN];
8507 char attr_xpath[XPATH_MAXLEN];
8508 afi_t afi = bgp_node_afi(vty);
8509 safi_t safi = bgp_node_safi(vty);
8510
8511 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8512 yang_afi_safi_value2identity(afi, safi));
8513 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8514 sizeof(base_xpath), af_xpath)
8515 < 0)
8516 return CMD_WARNING_CONFIG_FAILED;
8517
8518 snprintf(attr_xpath, sizeof(attr_xpath),
8519 "/%s/prefix-limit/direction-list[direction='in']",
8520 bgp_afi_safi_get_container_str(afi, safi));
8521 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8522
8523 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8524
8525 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8526 argv[idx_number]->arg);
8527 nb_cli_enqueue_change(vty, "./options/restart-timer", NB_OP_MODIFY,
8528 argv[idx_number_2]->arg);
8529 if (argv_find(argv, argc, "force", &idx_force))
8530 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8531 "true");
8532
8533 return nb_cli_apply_changes(vty, base_xpath);
8534 }
8535
8536 ALIAS_HIDDEN(
8537 neighbor_maximum_prefix_restart,
8538 neighbor_maximum_prefix_restart_hidden_cmd,
8539 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8540 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8541 "Maximum number of prefix accept from this peer\n"
8542 "maximum no. of prefix limit\n"
8543 "Restart bgp connection after limit is exceeded\n"
8544 "Restart interval in minutes\n"
8545 "Force checking all received routes not only accepted\n")
8546
8547 DEFUN_YANG(neighbor_maximum_prefix_threshold_restart,
8548 neighbor_maximum_prefix_threshold_restart_cmd,
8549 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8550 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8551 "Maximum number of prefixes to accept from this peer\n"
8552 "maximum no. of prefix limit\n"
8553 "Threshold value (%) at which to generate a warning msg\n"
8554 "Restart bgp connection after limit is exceeded\n"
8555 "Restart interval in minutes\n"
8556 "Force checking all received routes not only accepted\n")
8557 {
8558 int idx_peer = 1;
8559 int idx_number = 3;
8560 int idx_number_2 = 4;
8561 int idx_number_3 = 6;
8562 int idx_force = 0;
8563 char base_xpath[XPATH_MAXLEN];
8564 char af_xpath[XPATH_MAXLEN];
8565 char attr_xpath[XPATH_MAXLEN];
8566 afi_t afi = bgp_node_afi(vty);
8567 safi_t safi = bgp_node_safi(vty);
8568
8569 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8570 yang_afi_safi_value2identity(afi, safi));
8571 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8572 sizeof(base_xpath), af_xpath)
8573 < 0)
8574 return CMD_WARNING_CONFIG_FAILED;
8575
8576 snprintf(attr_xpath, sizeof(attr_xpath),
8577 "/%s/prefix-limit/direction-list[direction='in']",
8578 bgp_afi_safi_get_container_str(afi, safi));
8579 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8580
8581 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8582
8583 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8584 argv[idx_number]->arg);
8585 nb_cli_enqueue_change(vty, "./options/tr-shutdown-threshold-pct",
8586 NB_OP_MODIFY, argv[idx_number_2]->arg);
8587 nb_cli_enqueue_change(vty, "./options/tr-restart-timer", NB_OP_MODIFY,
8588 argv[idx_number_3]->arg);
8589 if (argv_find(argv, argc, "force", &idx_force))
8590 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8591 "true");
8592
8593 return nb_cli_apply_changes(vty, base_xpath);
8594 }
8595
8596 ALIAS_HIDDEN(
8597 neighbor_maximum_prefix_threshold_restart,
8598 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
8599 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8600 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8601 "Maximum number of prefixes to accept from this peer\n"
8602 "maximum no. of prefix limit\n"
8603 "Threshold value (%) at which to generate a warning msg\n"
8604 "Restart bgp connection after limit is exceeded\n"
8605 "Restart interval in minutes\n"
8606 "Force checking all received routes not only accepted\n")
8607
8608 DEFUN_YANG(no_neighbor_maximum_prefix,
8609 no_neighbor_maximum_prefix_cmd,
8610 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8611 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8612 "Maximum number of prefixes to accept from this peer\n"
8613 "maximum no. of prefix limit\n"
8614 "Threshold value (%) at which to generate a warning msg\n"
8615 "Restart bgp connection after limit is exceeded\n"
8616 "Restart interval in minutes\n"
8617 "Only give warning message when limit is exceeded\n"
8618 "Force checking all received routes not only accepted\n")
8619 {
8620 int idx_peer = 2;
8621 char base_xpath[XPATH_MAXLEN];
8622 char af_xpath[XPATH_MAXLEN];
8623 char attr_xpath[XPATH_MAXLEN];
8624 afi_t afi = bgp_node_afi(vty);
8625 safi_t safi = bgp_node_safi(vty);
8626
8627 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8628 yang_afi_safi_value2identity(afi, safi));
8629 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8630 sizeof(base_xpath), af_xpath)
8631 < 0)
8632 return CMD_WARNING_CONFIG_FAILED;
8633
8634 snprintf(attr_xpath, sizeof(attr_xpath),
8635 "/%s/prefix-limit/direction-list[direction='in']",
8636 bgp_afi_safi_get_container_str(afi, safi));
8637 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8638
8639 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
8640
8641 return nb_cli_apply_changes(vty, base_xpath);
8642 }
8643
8644 ALIAS_HIDDEN(
8645 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
8646 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8647 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8648 "Maximum number of prefixes to accept from this peer\n"
8649 "maximum no. of prefix limit\n"
8650 "Threshold value (%) at which to generate a warning msg\n"
8651 "Restart bgp connection after limit is exceeded\n"
8652 "Restart interval in minutes\n"
8653 "Only give warning message when limit is exceeded\n"
8654 "Force checking all received routes not only accepted\n")
8655
8656
8657 /* "neighbor allowas-in" */
8658 DEFUN (neighbor_allowas_in,
8659 neighbor_allowas_in_cmd,
8660 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8661 NEIGHBOR_STR
8662 NEIGHBOR_ADDR_STR2
8663 "Accept as-path with my AS present in it\n"
8664 "Number of occurrences of AS number\n"
8665 "Only accept my AS in the as-path if the route was originated in my AS\n")
8666 {
8667 int idx_peer = 1;
8668 int idx_number_origin = 3;
8669 int ret;
8670 int origin = 0;
8671 struct peer *peer;
8672 int allow_num = 0;
8673
8674 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8675 if (!peer)
8676 return CMD_WARNING_CONFIG_FAILED;
8677
8678 if (argc <= idx_number_origin)
8679 allow_num = 3;
8680 else {
8681 if (argv[idx_number_origin]->type == WORD_TKN)
8682 origin = 1;
8683 else
8684 allow_num = atoi(argv[idx_number_origin]->arg);
8685 }
8686
8687 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8688 allow_num, origin);
8689
8690 return bgp_vty_return(vty, ret);
8691 }
8692
8693 ALIAS_HIDDEN(
8694 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
8695 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8696 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8697 "Accept as-path with my AS present in it\n"
8698 "Number of occurrences of AS number\n"
8699 "Only accept my AS in the as-path if the route was originated in my AS\n")
8700
8701 DEFUN (no_neighbor_allowas_in,
8702 no_neighbor_allowas_in_cmd,
8703 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8704 NO_STR
8705 NEIGHBOR_STR
8706 NEIGHBOR_ADDR_STR2
8707 "allow local ASN appears in aspath attribute\n"
8708 "Number of occurrences of AS number\n"
8709 "Only accept my AS in the as-path if the route was originated in my AS\n")
8710 {
8711 int idx_peer = 2;
8712 int ret;
8713 struct peer *peer;
8714
8715 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8716 if (!peer)
8717 return CMD_WARNING_CONFIG_FAILED;
8718
8719 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
8720 bgp_node_safi(vty));
8721
8722 return bgp_vty_return(vty, ret);
8723 }
8724
8725 ALIAS_HIDDEN(
8726 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
8727 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8728 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8729 "allow local ASN appears in aspath attribute\n"
8730 "Number of occurrences of AS number\n"
8731 "Only accept my AS in the as-path if the route was originated in my AS\n")
8732
8733 DEFUN_YANG (neighbor_ttl_security,
8734 neighbor_ttl_security_cmd,
8735 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8736 NEIGHBOR_STR
8737 NEIGHBOR_ADDR_STR2
8738 "BGP ttl-security parameters\n"
8739 "Specify the maximum number of hops to the BGP peer\n"
8740 "Number of hops to BGP peer\n")
8741 {
8742 int idx_peer = 1;
8743 int idx_number = 4;
8744 char base_xpath[XPATH_MAXLEN];
8745
8746 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8747 sizeof(base_xpath), NULL)
8748 < 0)
8749 return CMD_WARNING_CONFIG_FAILED;
8750
8751 nb_cli_enqueue_change(vty, "./ttl-security", NB_OP_MODIFY,
8752 argv[idx_number]->arg);
8753
8754 return nb_cli_apply_changes(vty, base_xpath);
8755 }
8756
8757 DEFUN_YANG(no_neighbor_ttl_security,
8758 no_neighbor_ttl_security_cmd,
8759 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8760 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8761 "BGP ttl-security parameters\n"
8762 "Specify the maximum number of hops to the BGP peer\n"
8763 "Number of hops to BGP peer\n")
8764 {
8765 int idx_peer = 2;
8766 char base_xpath[XPATH_MAXLEN];
8767
8768 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8769 sizeof(base_xpath), NULL)
8770 < 0)
8771 return CMD_WARNING_CONFIG_FAILED;
8772
8773 nb_cli_enqueue_change(vty, "./ttl-security", NB_OP_DESTROY, NULL);
8774
8775 return nb_cli_apply_changes(vty, base_xpath);
8776 }
8777
8778 DEFUN (neighbor_addpath_tx_all_paths,
8779 neighbor_addpath_tx_all_paths_cmd,
8780 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8781 NEIGHBOR_STR
8782 NEIGHBOR_ADDR_STR2
8783 "Use addpath to advertise all paths to a neighbor\n")
8784 {
8785 int idx_peer = 1;
8786 struct peer *peer;
8787
8788 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8789 if (!peer)
8790 return CMD_WARNING_CONFIG_FAILED;
8791
8792 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8793 BGP_ADDPATH_ALL);
8794 return CMD_SUCCESS;
8795 }
8796
8797 ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
8798 neighbor_addpath_tx_all_paths_hidden_cmd,
8799 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8800 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8801 "Use addpath to advertise all paths to a neighbor\n")
8802
8803 DEFUN (no_neighbor_addpath_tx_all_paths,
8804 no_neighbor_addpath_tx_all_paths_cmd,
8805 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8806 NO_STR
8807 NEIGHBOR_STR
8808 NEIGHBOR_ADDR_STR2
8809 "Use addpath to advertise all paths to a neighbor\n")
8810 {
8811 int idx_peer = 2;
8812 struct peer *peer;
8813
8814 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8815 if (!peer)
8816 return CMD_WARNING_CONFIG_FAILED;
8817
8818 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8819 != BGP_ADDPATH_ALL) {
8820 vty_out(vty,
8821 "%% Peer not currently configured to transmit all paths.");
8822 return CMD_WARNING_CONFIG_FAILED;
8823 }
8824
8825 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8826 BGP_ADDPATH_NONE);
8827
8828 return CMD_SUCCESS;
8829 }
8830
8831 ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
8832 no_neighbor_addpath_tx_all_paths_hidden_cmd,
8833 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8834 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8835 "Use addpath to advertise all paths to a neighbor\n")
8836
8837 DEFUN (neighbor_addpath_tx_bestpath_per_as,
8838 neighbor_addpath_tx_bestpath_per_as_cmd,
8839 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8840 NEIGHBOR_STR
8841 NEIGHBOR_ADDR_STR2
8842 "Use addpath to advertise the bestpath per each neighboring AS\n")
8843 {
8844 int idx_peer = 1;
8845 struct peer *peer;
8846
8847 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8848 if (!peer)
8849 return CMD_WARNING_CONFIG_FAILED;
8850
8851 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8852 BGP_ADDPATH_BEST_PER_AS);
8853
8854 return CMD_SUCCESS;
8855 }
8856
8857 ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
8858 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8859 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8860 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8861 "Use addpath to advertise the bestpath per each neighboring AS\n")
8862
8863 DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
8864 no_neighbor_addpath_tx_bestpath_per_as_cmd,
8865 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8866 NO_STR
8867 NEIGHBOR_STR
8868 NEIGHBOR_ADDR_STR2
8869 "Use addpath to advertise the bestpath per each neighboring AS\n")
8870 {
8871 int idx_peer = 2;
8872 struct peer *peer;
8873
8874 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8875 if (!peer)
8876 return CMD_WARNING_CONFIG_FAILED;
8877
8878 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8879 != BGP_ADDPATH_BEST_PER_AS) {
8880 vty_out(vty,
8881 "%% Peer not currently configured to transmit all best path per as.");
8882 return CMD_WARNING_CONFIG_FAILED;
8883 }
8884
8885 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8886 BGP_ADDPATH_NONE);
8887
8888 return CMD_SUCCESS;
8889 }
8890
8891 ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
8892 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8893 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8894 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8895 "Use addpath to advertise the bestpath per each neighboring AS\n")
8896
8897 DEFPY(
8898 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
8899 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8900 NEIGHBOR_STR
8901 NEIGHBOR_ADDR_STR2
8902 "Detect AS loops before sending to neighbor\n")
8903 {
8904 struct peer *peer;
8905
8906 peer = peer_and_group_lookup_vty(vty, neighbor);
8907 if (!peer)
8908 return CMD_WARNING_CONFIG_FAILED;
8909
8910 peer->as_path_loop_detection = true;
8911
8912 return CMD_SUCCESS;
8913 }
8914
8915 DEFPY(
8916 no_neighbor_aspath_loop_detection,
8917 no_neighbor_aspath_loop_detection_cmd,
8918 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8919 NO_STR
8920 NEIGHBOR_STR
8921 NEIGHBOR_ADDR_STR2
8922 "Detect AS loops before sending to neighbor\n")
8923 {
8924 struct peer *peer;
8925
8926 peer = peer_and_group_lookup_vty(vty, neighbor);
8927 if (!peer)
8928 return CMD_WARNING_CONFIG_FAILED;
8929
8930 peer->as_path_loop_detection = false;
8931
8932 return CMD_SUCCESS;
8933 }
8934
8935 DEFPY(neighbor_damp,
8936 neighbor_damp_cmd,
8937 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor dampening [(1-45)$half [(1-20000)$reuse (1-20000)$suppress (1-255)$max]]",
8938 NEIGHBOR_STR
8939 NEIGHBOR_ADDR_STR2
8940 "Enable neighbor route-flap dampening\n"
8941 "Half-life time for the penalty\n"
8942 "Value to start reusing a route\n"
8943 "Value to start suppressing a route\n"
8944 "Maximum duration to suppress a stable route\n")
8945 {
8946 struct peer *peer = peer_and_group_lookup_vty(vty, neighbor);
8947
8948 if (!peer)
8949 return CMD_WARNING_CONFIG_FAILED;
8950 if (!half)
8951 half = DEFAULT_HALF_LIFE;
8952 if (!reuse) {
8953 reuse = DEFAULT_REUSE;
8954 suppress = DEFAULT_SUPPRESS;
8955 max = half * 4;
8956 }
8957 if (suppress < reuse) {
8958 vty_out(vty,
8959 "Suppress value cannot be less than reuse value\n");
8960 return CMD_WARNING_CONFIG_FAILED;
8961 }
8962 bgp_peer_damp_enable(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8963 half * 60, reuse, suppress, max * 60);
8964 return CMD_SUCCESS;
8965 }
8966
8967 DEFPY(no_neighbor_damp,
8968 no_neighbor_damp_cmd,
8969 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor dampening [HALF [REUSE SUPPRESS MAX]]",
8970 NO_STR
8971 NEIGHBOR_STR
8972 NEIGHBOR_ADDR_STR2
8973 "Enable neighbor route-flap dampening\n"
8974 "Half-life time for the penalty\n"
8975 "Value to start reusing a route\n"
8976 "Value to start suppressing a route\n"
8977 "Maximum duration to suppress a stable route\n")
8978 {
8979 struct peer *peer = peer_and_group_lookup_vty(vty, neighbor);
8980
8981 if (!peer)
8982 return CMD_WARNING_CONFIG_FAILED;
8983 bgp_peer_damp_disable(peer, bgp_node_afi(vty), bgp_node_safi(vty));
8984 return CMD_SUCCESS;
8985 }
8986
8987 DEFPY (show_ip_bgp_neighbor_damp_param,
8988 show_ip_bgp_neighbor_damp_param_cmd,
8989 "show [ip] bgp [<ipv4|ipv6> [unicast]] neighbors <A.B.C.D|X:X::X:X|WORD>$neighbor dampening parameters [json]$json",
8990 SHOW_STR
8991 IP_STR
8992 BGP_STR
8993 BGP_AFI_HELP_STR
8994 "Address Family modifier\n"
8995 NEIGHBOR_STR
8996 NEIGHBOR_ADDR_STR2
8997 "Neighbor route-flap dampening information\n"
8998 "Display detail of configured dampening parameters\n"
8999 JSON_STR)
9000 {
9001 bool use_json = false;
9002 int idx = 0;
9003 afi_t afi = AFI_IP;
9004 safi_t safi = SAFI_UNICAST;
9005 struct peer *peer;
9006
9007 if (argv_find(argv, argc, "ip", &idx))
9008 afi = AFI_IP;
9009 if (argv_find(argv, argc, "ipv4", &idx))
9010 afi = AFI_IP;
9011 if (argv_find(argv, argc, "ipv6", &idx))
9012 afi = AFI_IP6;
9013 peer = peer_and_group_lookup_vty(vty, neighbor);
9014 if (!peer)
9015 return CMD_WARNING;
9016 if (json)
9017 use_json = true;
9018 bgp_show_peer_dampening_parameters(vty, peer, afi, safi, use_json);
9019 return CMD_SUCCESS;
9020 }
9021
9022 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
9023 struct ecommunity **list, bool is_rt6)
9024 {
9025 struct ecommunity *ecom = NULL;
9026 struct ecommunity *ecomadd;
9027
9028 for (; argc; --argc, ++argv) {
9029 if (is_rt6)
9030 ecomadd = ecommunity_str2com_ipv6(argv[0]->arg,
9031 ECOMMUNITY_ROUTE_TARGET,
9032 0);
9033 else
9034 ecomadd = ecommunity_str2com(argv[0]->arg,
9035 ECOMMUNITY_ROUTE_TARGET,
9036 0);
9037 if (!ecomadd) {
9038 vty_out(vty, "Malformed community-list value\n");
9039 if (ecom)
9040 ecommunity_free(&ecom);
9041 return CMD_WARNING_CONFIG_FAILED;
9042 }
9043
9044 if (ecom) {
9045 ecommunity_merge(ecom, ecomadd);
9046 ecommunity_free(&ecomadd);
9047 } else {
9048 ecom = ecomadd;
9049 }
9050 }
9051
9052 if (*list) {
9053 ecommunity_free(&*list);
9054 }
9055 *list = ecom;
9056
9057 return CMD_SUCCESS;
9058 }
9059
9060 bool vpn_policy_check_import(struct bgp *bgp, afi_t afi, safi_t safi,
9061 bool v2vimport, char *errmsg, size_t errmsg_len)
9062 {
9063 if (!v2vimport) {
9064 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9065 BGP_CONFIG_VRF_TO_VRF_IMPORT)
9066 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9067 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
9068 snprintf(
9069 errmsg, errmsg_len, "%s",
9070 "%% error: Please unconfigure import vrf commands before using vpn commands");
9071 return false;
9072 }
9073 } else {
9074 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9075 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
9076 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9077 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
9078 snprintf(
9079 errmsg, errmsg_len, "%s",
9080 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands");
9081 return false;
9082 }
9083 }
9084 return true;
9085 }
9086
9087 /*
9088 * v2vimport is true if we are handling a `import vrf ...` command
9089 */
9090 static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
9091 {
9092 afi_t afi;
9093
9094 switch (vty->node) {
9095 case BGP_IPV4_NODE:
9096 afi = AFI_IP;
9097 break;
9098 case BGP_IPV6_NODE:
9099 afi = AFI_IP6;
9100 break;
9101 default:
9102 vty_out(vty,
9103 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
9104 return AFI_MAX;
9105 }
9106
9107 if (!v2vimport) {
9108 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9109 BGP_CONFIG_VRF_TO_VRF_IMPORT)
9110 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9111 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
9112 vty_out(vty,
9113 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
9114 return AFI_MAX;
9115 }
9116 } else {
9117 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9118 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
9119 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9120 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
9121 vty_out(vty,
9122 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
9123 return AFI_MAX;
9124 }
9125 }
9126 return afi;
9127 }
9128
9129 DEFPY_YANG(
9130 af_rd_vpn_export,
9131 af_rd_vpn_export_cmd,
9132 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
9133 NO_STR
9134 "Specify route distinguisher\n"
9135 "Between current address-family and vpn\n"
9136 "For routes leaked from current address-family to vpn\n"
9137 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
9138 {
9139 char base_xpath[XPATH_MAXLEN];
9140 afi_t afi;
9141 safi_t safi;
9142 int idx = 0;
9143
9144 afi = bgp_node_afi(vty);
9145 safi = bgp_node_safi(vty);
9146
9147 snprintf(
9148 base_xpath, sizeof(base_xpath),
9149 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config",
9150 yang_afi_safi_value2identity(afi, safi),
9151 bgp_afi_safi_get_container_str(afi, safi));
9152
9153 if (argv_find(argv, argc, "no", &idx))
9154 nb_cli_enqueue_change(vty, "./rd", NB_OP_DESTROY, NULL);
9155 else
9156 nb_cli_enqueue_change(vty, "./rd", NB_OP_MODIFY, rd_str);
9157
9158 return nb_cli_apply_changes(vty, base_xpath);
9159 }
9160
9161 void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rd(
9162 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9163 {
9164 int indent = 2;
9165
9166 vty_out(vty, "%*srd vpn export %s\n", indent, "",
9167 yang_dnode_get_string(dnode, NULL));
9168 }
9169
9170 ALIAS (af_rd_vpn_export,
9171 af_no_rd_vpn_export_cmd,
9172 "no rd vpn export",
9173 NO_STR
9174 "Specify route distinguisher\n"
9175 "Between current address-family and vpn\n"
9176 "For routes leaked from current address-family to vpn\n")
9177
9178 DEFPY (af_label_vpn_export,
9179 af_label_vpn_export_cmd,
9180 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
9181 NO_STR
9182 "label value for VRF\n"
9183 "Between current address-family and vpn\n"
9184 "For routes leaked from current address-family to vpn\n"
9185 "Label Value <0-1048575>\n"
9186 "Automatically assign a label\n")
9187 {
9188 VTY_DECLVAR_CONTEXT(bgp, bgp);
9189 mpls_label_t label = MPLS_LABEL_NONE;
9190 afi_t afi;
9191 int idx = 0;
9192 bool yes = true;
9193
9194 if (argv_find(argv, argc, "no", &idx))
9195 yes = false;
9196
9197 /* If "no ...", squash trailing parameter */
9198 if (!yes)
9199 label_auto = NULL;
9200
9201 if (yes) {
9202 if (!label_auto)
9203 label = label_val; /* parser should force unsigned */
9204 }
9205
9206 afi = vpn_policy_getafi(vty, bgp, false);
9207 if (afi == AFI_MAX)
9208 return CMD_WARNING_CONFIG_FAILED;
9209
9210
9211 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9212 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
9213 /* no change */
9214 return CMD_SUCCESS;
9215
9216 /*
9217 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
9218 */
9219 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9220 bgp_get_default(), bgp);
9221
9222 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9223 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
9224
9225 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
9226
9227 /*
9228 * label has previously been automatically
9229 * assigned by labelpool: release it
9230 *
9231 * NB if tovpn_label == MPLS_LABEL_NONE it
9232 * means the automatic assignment is in flight
9233 * and therefore the labelpool callback must
9234 * detect that the auto label is not needed.
9235 */
9236
9237 bgp_lp_release(LP_TYPE_VRF,
9238 &bgp->vpn_policy[afi],
9239 bgp->vpn_policy[afi].tovpn_label);
9240 }
9241 UNSET_FLAG(bgp->vpn_policy[afi].flags,
9242 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
9243 }
9244
9245 bgp->vpn_policy[afi].tovpn_label = label;
9246 if (label_auto) {
9247 SET_FLAG(bgp->vpn_policy[afi].flags,
9248 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
9249 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
9250 vpn_leak_label_callback);
9251 }
9252
9253 /* post-change: re-export vpn routes */
9254 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9255 bgp_get_default(), bgp);
9256
9257 return CMD_SUCCESS;
9258 }
9259
9260 ALIAS (af_label_vpn_export,
9261 af_no_label_vpn_export_cmd,
9262 "no label vpn export",
9263 NO_STR
9264 "label value for VRF\n"
9265 "Between current address-family and vpn\n"
9266 "For routes leaked from current address-family to vpn\n")
9267
9268 DEFPY_YANG (af_nexthop_vpn_export,
9269 af_nexthop_vpn_export_cmd,
9270 "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
9271 NO_STR
9272 "Specify next hop to use for VRF advertised prefixes\n"
9273 "Between current address-family and vpn\n"
9274 "For routes leaked from current address-family to vpn\n"
9275 "IPv4 prefix\n"
9276 "IPv6 prefix\n")
9277 {
9278 char base_xpath[XPATH_MAXLEN];
9279 afi_t afi;
9280 safi_t safi;
9281 int idx = 0;
9282 struct prefix p;
9283
9284 if (!no) {
9285 if (!nexthop_su) {
9286 vty_out(vty, "%% Nexthop required\n");
9287 return CMD_WARNING_CONFIG_FAILED;
9288 }
9289 if (!sockunion2hostprefix(nexthop_su, &p))
9290 return CMD_WARNING_CONFIG_FAILED;
9291 }
9292
9293 afi = bgp_node_afi(vty);
9294 safi = bgp_node_safi(vty);
9295
9296 snprintf(
9297 base_xpath, sizeof(base_xpath),
9298 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config",
9299 yang_afi_safi_value2identity(afi, safi),
9300 bgp_afi_safi_get_container_str(afi, safi));
9301
9302 if (argv_find(argv, argc, "no", &idx))
9303 nb_cli_enqueue_change(vty, "./nexthop", NB_OP_DESTROY, NULL);
9304 else
9305 nb_cli_enqueue_change(vty, "./nexthop", NB_OP_MODIFY,
9306 nexthop_su_str);
9307
9308 return nb_cli_apply_changes(vty, base_xpath);
9309 }
9310
9311 void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_nexthop(
9312 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9313 {
9314 int indent = 2;
9315
9316 vty_out(vty, "%*snexthop vpn export %s\n", indent, "",
9317 yang_dnode_get_string(dnode, NULL));
9318 }
9319
9320 static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
9321 {
9322 if (!strcmp(dstr, "import")) {
9323 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9324 } else if (!strcmp(dstr, "export")) {
9325 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9326 } else if (!strcmp(dstr, "both")) {
9327 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9328 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9329 } else {
9330 vty_out(vty, "%% direction parse error\n");
9331 return CMD_WARNING_CONFIG_FAILED;
9332 }
9333 return CMD_SUCCESS;
9334 }
9335
9336 DEFPY (af_rt_vpn_imexport,
9337 af_rt_vpn_imexport_cmd,
9338 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
9339 NO_STR
9340 "Specify route target list\n"
9341 "Specify route target list\n"
9342 "Between current address-family and vpn\n"
9343 "For routes leaked from vpn to current address-family: match any\n"
9344 "For routes leaked from current address-family to vpn: set\n"
9345 "both import: match any and export: set\n"
9346 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
9347 {
9348 VTY_DECLVAR_CONTEXT(bgp, bgp);
9349 int ret;
9350 struct ecommunity *ecom = NULL;
9351 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
9352 vpn_policy_direction_t dir;
9353 afi_t afi;
9354 int idx = 0;
9355 bool yes = true;
9356
9357 if (argv_find(argv, argc, "no", &idx))
9358 yes = false;
9359
9360 afi = vpn_policy_getafi(vty, bgp, false);
9361 if (afi == AFI_MAX)
9362 return CMD_WARNING_CONFIG_FAILED;
9363
9364 ret = vpn_policy_getdirs(vty, direction_str, dodir);
9365 if (ret != CMD_SUCCESS)
9366 return ret;
9367
9368 if (yes) {
9369 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9370 vty_out(vty, "%% Missing RTLIST\n");
9371 return CMD_WARNING_CONFIG_FAILED;
9372 }
9373 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, false);
9374 if (ret != CMD_SUCCESS) {
9375 return ret;
9376 }
9377 }
9378
9379 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9380 if (!dodir[dir])
9381 continue;
9382
9383 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9384
9385 if (yes) {
9386 if (bgp->vpn_policy[afi].rtlist[dir])
9387 ecommunity_free(
9388 &bgp->vpn_policy[afi].rtlist[dir]);
9389 bgp->vpn_policy[afi].rtlist[dir] =
9390 ecommunity_dup(ecom);
9391 } else {
9392 if (bgp->vpn_policy[afi].rtlist[dir])
9393 ecommunity_free(
9394 &bgp->vpn_policy[afi].rtlist[dir]);
9395 bgp->vpn_policy[afi].rtlist[dir] = NULL;
9396 }
9397
9398 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9399 }
9400
9401 if (ecom)
9402 ecommunity_free(&ecom);
9403
9404 return CMD_SUCCESS;
9405 }
9406
9407 ALIAS (af_rt_vpn_imexport,
9408 af_no_rt_vpn_imexport_cmd,
9409 "no <rt|route-target> vpn <import|export|both>$direction_str",
9410 NO_STR
9411 "Specify route target list\n"
9412 "Specify route target list\n"
9413 "Between current address-family and vpn\n"
9414 "For routes leaked from vpn to current address-family\n"
9415 "For routes leaked from current address-family to vpn\n"
9416 "both import and export\n")
9417
9418 DEFPY_YANG (af_route_map_vpn_imexport,
9419 af_route_map_vpn_imexport_cmd,
9420 /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
9421 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
9422 NO_STR
9423 "Specify route map\n"
9424 "Between current address-family and vpn\n"
9425 "For routes leaked from vpn to current address-family\n"
9426 "For routes leaked from current address-family to vpn\n"
9427 "name of route-map\n")
9428 {
9429 char base_xpath[XPATH_MAXLEN];
9430 afi_t afi;
9431 safi_t safi;
9432 int idx = 0;
9433
9434 afi = bgp_node_afi(vty);
9435 safi = bgp_node_safi(vty);
9436
9437 snprintf(
9438 base_xpath, sizeof(base_xpath),
9439 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config",
9440 yang_afi_safi_value2identity(afi, safi),
9441 bgp_afi_safi_get_container_str(afi, safi));
9442
9443 if (argv_find(argv, argc, "no", &idx)) {
9444 if (!strcmp(direction_str, "import"))
9445 nb_cli_enqueue_change(vty, "./rmap-import",
9446 NB_OP_DESTROY, NULL);
9447 else if (!strcmp(direction_str, "export"))
9448 nb_cli_enqueue_change(vty, "./rmap-export",
9449 NB_OP_DESTROY, NULL);
9450 } else {
9451 if (!strcmp(direction_str, "import"))
9452 nb_cli_enqueue_change(vty, "./rmap-import",
9453 NB_OP_MODIFY, rmap_str);
9454 if (!strcmp(direction_str, "export"))
9455 nb_cli_enqueue_change(vty, "./rmap-export",
9456 NB_OP_MODIFY, rmap_str);
9457 }
9458 return nb_cli_apply_changes(vty, base_xpath);
9459 }
9460
9461 void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rmap_import(
9462 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9463 {
9464 int indent = 2;
9465
9466 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
9467 yang_dnode_get_string(dnode, NULL));
9468 }
9469
9470 void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rmap_export(
9471 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9472 {
9473 int indent = 2;
9474
9475 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
9476 yang_dnode_get_string(dnode, NULL));
9477 }
9478
9479 ALIAS (af_route_map_vpn_imexport,
9480 af_no_route_map_vpn_imexport_cmd,
9481 "no route-map vpn <import|export>$direction_str",
9482 NO_STR
9483 "Specify route map\n"
9484 "Between current address-family and vpn\n"
9485 "For routes leaked from vpn to current address-family\n"
9486 "For routes leaked from current address-family to vpn\n")
9487
9488 DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
9489 "import vrf route-map RMAP$rmap_str",
9490 "Import routes from another VRF\n"
9491 "Vrf routes being filtered\n"
9492 "Specify route map\n"
9493 "name of route-map\n")
9494 {
9495 VTY_DECLVAR_CONTEXT(bgp, bgp);
9496 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
9497 afi_t afi;
9498 struct bgp *bgp_default;
9499
9500 afi = vpn_policy_getafi(vty, bgp, true);
9501 if (afi == AFI_MAX)
9502 return CMD_WARNING_CONFIG_FAILED;
9503
9504 bgp_default = bgp_get_default();
9505 if (!bgp_default) {
9506 int32_t ret;
9507 as_t as = bgp->as;
9508
9509 /* Auto-create assuming the same AS */
9510 ret = bgp_get_vty(&bgp_default, &as, NULL,
9511 BGP_INSTANCE_TYPE_DEFAULT);
9512
9513 if (ret) {
9514 vty_out(vty,
9515 "VRF default is not configured as a bgp instance\n");
9516 return CMD_WARNING;
9517 }
9518 }
9519
9520 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9521
9522 if (bgp->vpn_policy[afi].rmap_name[dir])
9523 XFREE(MTYPE_ROUTE_MAP_NAME,
9524 bgp->vpn_policy[afi].rmap_name[dir]);
9525 bgp->vpn_policy[afi].rmap_name[dir] =
9526 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
9527 bgp->vpn_policy[afi].rmap[dir] =
9528 route_map_lookup_warn_noexist(vty, rmap_str);
9529 if (!bgp->vpn_policy[afi].rmap[dir])
9530 return CMD_SUCCESS;
9531
9532 SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9533 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9534
9535 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9536
9537 return CMD_SUCCESS;
9538 }
9539
9540 DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
9541 "no import vrf route-map [RMAP$rmap_str]",
9542 NO_STR
9543 "Import routes from another VRF\n"
9544 "Vrf routes being filtered\n"
9545 "Specify route map\n"
9546 "name of route-map\n")
9547 {
9548 VTY_DECLVAR_CONTEXT(bgp, bgp);
9549 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
9550 afi_t afi;
9551
9552 afi = vpn_policy_getafi(vty, bgp, true);
9553 if (afi == AFI_MAX)
9554 return CMD_WARNING_CONFIG_FAILED;
9555
9556 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9557
9558 if (bgp->vpn_policy[afi].rmap_name[dir])
9559 XFREE(MTYPE_ROUTE_MAP_NAME,
9560 bgp->vpn_policy[afi].rmap_name[dir]);
9561 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9562 bgp->vpn_policy[afi].rmap[dir] = NULL;
9563
9564 if (bgp->vpn_policy[afi].import_vrf->count == 0)
9565 UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9566 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9567
9568 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9569
9570 return CMD_SUCCESS;
9571 }
9572
9573 DEFPY_YANG(bgp_imexport_vrf,
9574 bgp_imexport_vrf_cmd,
9575 "[no] import vrf VIEWVRFNAME$import_name",
9576 NO_STR
9577 "Import routes from another VRF\n"
9578 "VRF to import from\n"
9579 "The name of the VRF\n")
9580 {
9581 char base_xpath[XPATH_MAXLEN];
9582 safi_t safi;
9583 afi_t afi;
9584 int32_t idx = 0;
9585
9586 if (import_name == NULL) {
9587 vty_out(vty, "%% Missing import name\n");
9588 return CMD_WARNING;
9589 }
9590
9591 if (strcmp(import_name, "route-map") == 0) {
9592 vty_out(vty, "%% Must include route-map name\n");
9593 return CMD_WARNING;
9594 }
9595
9596 afi = bgp_node_afi(vty);
9597 safi = bgp_node_safi(vty);
9598
9599 snprintf(
9600 base_xpath, sizeof(base_xpath),
9601 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config/import-vrf-list[vrf='%s']",
9602 yang_afi_safi_value2identity(afi, safi),
9603 bgp_afi_safi_get_container_str(afi, safi), import_name);
9604
9605 if (argv_find(argv, argc, "no", &idx))
9606 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
9607 else
9608 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
9609
9610 return nb_cli_apply_changes(vty, base_xpath);
9611 }
9612
9613 void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_import_vrfs(
9614 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9615 {
9616 vty_out(vty, " import vrf %s\n",
9617 yang_dnode_get_string(dnode, "./vrf"));
9618 }
9619
9620 /* This command is valid only in a bgp vrf instance or the default instance */
9621 DEFPY_YANG (bgp_imexport_vpn,
9622 bgp_imexport_vpn_cmd,
9623 "[no] <import|export>$direction_str vpn",
9624 NO_STR
9625 "Import routes to this address-family\n"
9626 "Export routes from this address-family\n"
9627 "to/from default instance VPN RIB\n")
9628 {
9629 char base_xpath[XPATH_MAXLEN];
9630 safi_t safi;
9631 afi_t afi;
9632 int32_t idx = 0;
9633
9634 afi = bgp_node_afi(vty);
9635 safi = bgp_node_safi(vty);
9636
9637 if (!strcmp(direction_str, "import")) {
9638 snprintf(
9639 base_xpath, sizeof(base_xpath),
9640 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config/import-vpn",
9641 yang_afi_safi_value2identity(afi, safi),
9642 bgp_afi_safi_get_container_str(afi, safi));
9643 } else if (!strcmp(direction_str, "export")) {
9644 snprintf(
9645 base_xpath, sizeof(base_xpath),
9646 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config/export-vpn",
9647 yang_afi_safi_value2identity(afi, safi),
9648 bgp_afi_safi_get_container_str(afi, safi));
9649 } else {
9650 vty_out(vty, "%% unknown direction %s\n", direction_str);
9651 return CMD_WARNING_CONFIG_FAILED;
9652 }
9653
9654 if (argv_find(argv, argc, "no", &idx))
9655 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
9656 else
9657 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, "true");
9658
9659 return nb_cli_apply_changes(vty, base_xpath);
9660 }
9661
9662 void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_import_vpn(
9663 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9664 {
9665 if (yang_dnode_get_bool(dnode, NULL))
9666 vty_out(vty, " import vpn\n");
9667 }
9668
9669 void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_export_vpn(
9670 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9671 {
9672 if (yang_dnode_get_bool(dnode, NULL))
9673 vty_out(vty, " export vpn\n");
9674 }
9675
9676 DEFPY (af_routetarget_import,
9677 af_routetarget_import_cmd,
9678 "[no] <rt|route-target|route-target6|rt6> redirect import RTLIST...",
9679 NO_STR
9680 "Specify route target list\n"
9681 "Specify route target list\n"
9682 "Specify route target list\n"
9683 "Specify route target list\n"
9684 "Flow-spec redirect type route target\n"
9685 "Import routes to this address-family\n"
9686 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN|IPV6:MN)\n")
9687 {
9688 VTY_DECLVAR_CONTEXT(bgp, bgp);
9689 int ret;
9690 struct ecommunity *ecom = NULL;
9691 afi_t afi;
9692 int idx = 0, idx_unused = 0;
9693 bool yes = true;
9694 bool rt6 = false;
9695
9696 if (argv_find(argv, argc, "no", &idx))
9697 yes = false;
9698
9699 if (argv_find(argv, argc, "rt6", &idx_unused) ||
9700 argv_find(argv, argc, "route-target6", &idx_unused))
9701 rt6 = true;
9702
9703 afi = vpn_policy_getafi(vty, bgp, false);
9704 if (afi == AFI_MAX)
9705 return CMD_WARNING_CONFIG_FAILED;
9706
9707 if (rt6 && afi != AFI_IP6)
9708 return CMD_WARNING_CONFIG_FAILED;
9709
9710 if (yes) {
9711 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9712 vty_out(vty, "%% Missing RTLIST\n");
9713 return CMD_WARNING_CONFIG_FAILED;
9714 }
9715 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, rt6);
9716 if (ret != CMD_SUCCESS)
9717 return ret;
9718 }
9719
9720 if (yes) {
9721 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9722 ecommunity_free(&bgp->vpn_policy[afi]
9723 .import_redirect_rtlist);
9724 bgp->vpn_policy[afi].import_redirect_rtlist =
9725 ecommunity_dup(ecom);
9726 } else {
9727 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9728 ecommunity_free(&bgp->vpn_policy[afi]
9729 .import_redirect_rtlist);
9730 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
9731 }
9732
9733 if (ecom)
9734 ecommunity_free(&ecom);
9735
9736 return CMD_SUCCESS;
9737 }
9738
9739 void cli_show_bgp_global_afi_safi_header(struct vty *vty,
9740 struct lyd_node *dnode,
9741 bool show_defaults)
9742 {
9743 const char *af_name;
9744 afi_t afi;
9745 safi_t safi;
9746
9747 af_name = yang_dnode_get_string(dnode, "./afi-safi-name");
9748 yang_afi_safi_identity2value(af_name, &afi, &safi);
9749
9750 vty_out(vty, " !\n address-family ");
9751 if (afi == AFI_IP) {
9752 if (safi == SAFI_UNICAST)
9753 vty_out(vty, "ipv4 unicast");
9754 else if (safi == SAFI_LABELED_UNICAST)
9755 vty_out(vty, "ipv4 labeled-unicast");
9756 else if (safi == SAFI_MULTICAST)
9757 vty_out(vty, "ipv4 multicast");
9758 else if (safi == SAFI_MPLS_VPN)
9759 vty_out(vty, "ipv4 vpn");
9760 else if (safi == SAFI_ENCAP)
9761 vty_out(vty, "ipv4 encap");
9762 else if (safi == SAFI_FLOWSPEC)
9763 vty_out(vty, "ipv4 flowspec");
9764 } else if (afi == AFI_IP6) {
9765 if (safi == SAFI_UNICAST)
9766 vty_out(vty, "ipv6 unicast");
9767 else if (safi == SAFI_LABELED_UNICAST)
9768 vty_out(vty, "ipv6 labeled-unicast");
9769 else if (safi == SAFI_MULTICAST)
9770 vty_out(vty, "ipv6 multicast");
9771 else if (safi == SAFI_MPLS_VPN)
9772 vty_out(vty, "ipv6 vpn");
9773 else if (safi == SAFI_ENCAP)
9774 vty_out(vty, "ipv6 encap");
9775 else if (safi == SAFI_FLOWSPEC)
9776 vty_out(vty, "ipv6 flowspec");
9777 } else if (afi == AFI_L2VPN) {
9778 if (safi == SAFI_EVPN)
9779 vty_out(vty, "l2vpn evpn");
9780 }
9781 vty_out(vty, "\n");
9782 }
9783
9784 DEFUN_NOSH (address_family_ipv4_safi,
9785 address_family_ipv4_safi_cmd,
9786 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9787 "Enter Address Family command mode\n"
9788 "Address Family\n"
9789 BGP_SAFI_WITH_LABEL_HELP_STR)
9790 {
9791
9792 safi_t safi = SAFI_UNICAST;
9793 const struct lyd_node *vrf_dnode, *bgp_glb_dnode;
9794 const char *vrf_name = NULL;
9795
9796 if (argc == 3) {
9797 safi = bgp_vty_safi_from_str(argv[2]->text);
9798
9799 bgp_glb_dnode = yang_dnode_get(vty->candidate_config->dnode,
9800 VTY_CURR_XPATH);
9801 vrf_dnode = yang_dnode_get_parent(bgp_glb_dnode,
9802 "control-plane-protocol");
9803 vrf_name = yang_dnode_get_string(vrf_dnode, "./vrf");
9804
9805 if (!strmatch(vrf_name, VRF_DEFAULT_NAME)
9806 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9807 && safi != SAFI_EVPN) {
9808 vty_out(vty,
9809 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9810 return CMD_WARNING_CONFIG_FAILED;
9811 }
9812 }
9813 vty->node = bgp_node_type(AFI_IP, safi);
9814
9815 return CMD_SUCCESS;
9816 }
9817
9818 DEFUN_NOSH (address_family_ipv6_safi,
9819 address_family_ipv6_safi_cmd,
9820 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9821 "Enter Address Family command mode\n"
9822 "Address Family\n"
9823 BGP_SAFI_WITH_LABEL_HELP_STR)
9824 {
9825 safi_t safi = SAFI_UNICAST;
9826 const struct lyd_node *vrf_dnode, *bgp_glb_dnode;
9827 const char *vrf_name = NULL;
9828
9829 if (argc == 3) {
9830 safi = bgp_vty_safi_from_str(argv[2]->text);
9831 bgp_glb_dnode = yang_dnode_get(vty->candidate_config->dnode,
9832 VTY_CURR_XPATH);
9833 vrf_dnode = yang_dnode_get_parent(bgp_glb_dnode,
9834 "control-plane-protocol");
9835 vrf_name = yang_dnode_get_string(vrf_dnode, "./vrf");
9836
9837 if (!strmatch(vrf_name, VRF_DEFAULT_NAME)
9838 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9839 && safi != SAFI_EVPN) {
9840 vty_out(vty,
9841 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9842 return CMD_WARNING_CONFIG_FAILED;
9843 }
9844 }
9845 vty->node = bgp_node_type(AFI_IP6, safi);
9846
9847 return CMD_SUCCESS;
9848 }
9849
9850 #ifdef KEEP_OLD_VPN_COMMANDS
9851 DEFUN_NOSH (address_family_vpnv4,
9852 address_family_vpnv4_cmd,
9853 "address-family vpnv4 [unicast]",
9854 "Enter Address Family command mode\n"
9855 "Address Family\n"
9856 "Address Family modifier\n")
9857 {
9858 vty->node = BGP_VPNV4_NODE;
9859 return CMD_SUCCESS;
9860 }
9861
9862 DEFUN_NOSH (address_family_vpnv6,
9863 address_family_vpnv6_cmd,
9864 "address-family vpnv6 [unicast]",
9865 "Enter Address Family command mode\n"
9866 "Address Family\n"
9867 "Address Family modifier\n")
9868 {
9869 vty->node = BGP_VPNV6_NODE;
9870 return CMD_SUCCESS;
9871 }
9872 #endif /* KEEP_OLD_VPN_COMMANDS */
9873
9874 DEFUN_NOSH (address_family_evpn,
9875 address_family_evpn_cmd,
9876 "address-family l2vpn evpn",
9877 "Enter Address Family command mode\n"
9878 "Address Family\n"
9879 "Address Family modifier\n")
9880 {
9881 VTY_DECLVAR_CONTEXT(bgp, bgp);
9882 vty->node = BGP_EVPN_NODE;
9883 return CMD_SUCCESS;
9884 }
9885
9886 DEFUN_NOSH (exit_address_family,
9887 exit_address_family_cmd,
9888 "exit-address-family",
9889 "Exit from Address Family configuration mode\n")
9890 {
9891 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
9892 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
9893 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
9894 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
9895 || vty->node == BGP_EVPN_NODE
9896 || vty->node == BGP_FLOWSPECV4_NODE
9897 || vty->node == BGP_FLOWSPECV6_NODE)
9898 vty->node = BGP_NODE;
9899 return CMD_SUCCESS;
9900 }
9901
9902 void cli_show_bgp_global_afi_safi_header_end(struct vty *vty,
9903 struct lyd_node *dnode
9904 __attribute__((__unused__)))
9905 {
9906 vty_out(vty, " exit-address-family\n");
9907 }
9908
9909 /* Recalculate bestpath and re-advertise a prefix */
9910 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
9911 const char *ip_str, afi_t afi, safi_t safi,
9912 struct prefix_rd *prd)
9913 {
9914 int ret;
9915 struct prefix match;
9916 struct bgp_dest *dest;
9917 struct bgp_dest *rm;
9918 struct bgp *bgp;
9919 struct bgp_table *table;
9920 struct bgp_table *rib;
9921
9922 /* BGP structure lookup. */
9923 if (view_name) {
9924 bgp = bgp_lookup_by_name(view_name);
9925 if (bgp == NULL) {
9926 vty_out(vty, "%% Can't find BGP instance %s\n",
9927 view_name);
9928 return CMD_WARNING;
9929 }
9930 } else {
9931 bgp = bgp_get_default();
9932 if (bgp == NULL) {
9933 vty_out(vty, "%% No BGP process is configured\n");
9934 return CMD_WARNING;
9935 }
9936 }
9937
9938 /* Check IP address argument. */
9939 ret = str2prefix(ip_str, &match);
9940 if (!ret) {
9941 vty_out(vty, "%% address is malformed\n");
9942 return CMD_WARNING;
9943 }
9944
9945 match.family = afi2family(afi);
9946 rib = bgp->rib[afi][safi];
9947
9948 if (safi == SAFI_MPLS_VPN) {
9949 for (dest = bgp_table_top(rib); dest;
9950 dest = bgp_route_next(dest)) {
9951 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
9952
9953 if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
9954 continue;
9955
9956 table = bgp_dest_get_bgp_table_info(dest);
9957 if (table == NULL)
9958 continue;
9959
9960 if ((rm = bgp_node_match(table, &match)) != NULL) {
9961 const struct prefix *rm_p =
9962 bgp_dest_get_prefix(rm);
9963
9964 if (rm_p->prefixlen == match.prefixlen) {
9965 SET_FLAG(rm->flags,
9966 BGP_NODE_USER_CLEAR);
9967 bgp_process(bgp, rm, afi, safi);
9968 }
9969 bgp_dest_unlock_node(rm);
9970 }
9971 }
9972 } else {
9973 if ((dest = bgp_node_match(rib, &match)) != NULL) {
9974 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
9975
9976 if (dest_p->prefixlen == match.prefixlen) {
9977 SET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
9978 bgp_process(bgp, dest, afi, safi);
9979 }
9980 bgp_dest_unlock_node(dest);
9981 }
9982 }
9983
9984 return CMD_SUCCESS;
9985 }
9986
9987 /* one clear bgp command to rule them all */
9988 DEFUN (clear_ip_bgp_all,
9989 clear_ip_bgp_all_cmd,
9990 "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>]",
9991 CLEAR_STR
9992 IP_STR
9993 BGP_STR
9994 BGP_INSTANCE_HELP_STR
9995 BGP_AFI_HELP_STR
9996 "Address Family\n"
9997 BGP_SAFI_WITH_LABEL_HELP_STR
9998 "Address Family modifier\n"
9999 "Clear all peers\n"
10000 "BGP IPv4 neighbor to clear\n"
10001 "BGP IPv6 neighbor to clear\n"
10002 "BGP neighbor on interface to clear\n"
10003 "Clear peers with the AS number\n"
10004 "Clear all external peers\n"
10005 "Clear all members of peer-group\n"
10006 "BGP peer-group name\n"
10007 BGP_SOFT_STR
10008 BGP_SOFT_IN_STR
10009 BGP_SOFT_OUT_STR
10010 BGP_SOFT_IN_STR
10011 "Push out prefix-list ORF and do inbound soft reconfig\n"
10012 BGP_SOFT_OUT_STR)
10013 {
10014 char *vrf = NULL;
10015
10016 afi_t afi = AFI_UNSPEC;
10017 safi_t safi = SAFI_UNSPEC;
10018 enum clear_sort clr_sort = clear_peer;
10019 enum bgp_clear_type clr_type;
10020 char *clr_arg = NULL;
10021
10022 int idx = 0;
10023 char errmsg[BUFSIZ] = {'\0'};
10024 int ret;
10025
10026 /* clear [ip] bgp */
10027 if (argv_find(argv, argc, "ip", &idx))
10028 afi = AFI_IP;
10029
10030 /* [<vrf> VIEWVRFNAME] */
10031 if (argv_find(argv, argc, "vrf", &idx)) {
10032 vrf = argv[idx + 1]->arg;
10033 idx += 2;
10034 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
10035 vrf = NULL;
10036 } else if (argv_find(argv, argc, "view", &idx)) {
10037 /* [<view> VIEWVRFNAME] */
10038 vrf = argv[idx + 1]->arg;
10039 idx += 2;
10040 }
10041 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
10042 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
10043 argv_find_and_parse_safi(argv, argc, &idx, &safi);
10044
10045 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
10046 if (argv_find(argv, argc, "*", &idx)) {
10047 clr_sort = clear_all;
10048 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
10049 clr_sort = clear_peer;
10050 clr_arg = argv[idx]->arg;
10051 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
10052 clr_sort = clear_peer;
10053 clr_arg = argv[idx]->arg;
10054 } else if (argv_find(argv, argc, "peer-group", &idx)) {
10055 clr_sort = clear_group;
10056 idx++;
10057 clr_arg = argv[idx]->arg;
10058 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
10059 clr_sort = clear_peer;
10060 clr_arg = argv[idx]->arg;
10061 } else if (argv_find(argv, argc, "WORD", &idx)) {
10062 clr_sort = clear_peer;
10063 clr_arg = argv[idx]->arg;
10064 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
10065 clr_sort = clear_as;
10066 clr_arg = argv[idx]->arg;
10067 } else if (argv_find(argv, argc, "external", &idx)) {
10068 clr_sort = clear_external;
10069 }
10070
10071 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
10072 if (argv_find(argv, argc, "soft", &idx)) {
10073 if (argv_find(argv, argc, "in", &idx)
10074 || argv_find(argv, argc, "out", &idx))
10075 clr_type = strmatch(argv[idx]->text, "in")
10076 ? BGP_CLEAR_SOFT_IN
10077 : BGP_CLEAR_SOFT_OUT;
10078 else
10079 clr_type = BGP_CLEAR_SOFT_BOTH;
10080 } else if (argv_find(argv, argc, "in", &idx)) {
10081 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
10082 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
10083 : BGP_CLEAR_SOFT_IN;
10084 } else if (argv_find(argv, argc, "out", &idx)) {
10085 clr_type = BGP_CLEAR_SOFT_OUT;
10086 } else
10087 clr_type = BGP_CLEAR_SOFT_NONE;
10088
10089 ret = bgp_clear_vty(vrf, afi, safi, clr_sort, clr_type, clr_arg, errmsg,
10090 sizeof(errmsg));
10091 if (ret != NB_OK)
10092 vty_out(vty, "Error description: %s\n", errmsg);
10093
10094 return ret;
10095 }
10096
10097 DEFUN (clear_ip_bgp_prefix,
10098 clear_ip_bgp_prefix_cmd,
10099 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
10100 CLEAR_STR
10101 IP_STR
10102 BGP_STR
10103 BGP_INSTANCE_HELP_STR
10104 "Clear bestpath and re-advertise\n"
10105 "IPv4 prefix\n")
10106 {
10107 char *vrf = NULL;
10108 char *prefix = NULL;
10109
10110 int idx = 0;
10111
10112 /* [<view|vrf> VIEWVRFNAME] */
10113 if (argv_find(argv, argc, "vrf", &idx)) {
10114 vrf = argv[idx + 1]->arg;
10115 idx += 2;
10116 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
10117 vrf = NULL;
10118 } else if (argv_find(argv, argc, "view", &idx)) {
10119 /* [<view> VIEWVRFNAME] */
10120 vrf = argv[idx + 1]->arg;
10121 idx += 2;
10122 }
10123
10124 prefix = argv[argc - 1]->arg;
10125
10126 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
10127 }
10128
10129 DEFUN (clear_bgp_ipv6_safi_prefix,
10130 clear_bgp_ipv6_safi_prefix_cmd,
10131 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
10132 CLEAR_STR
10133 IP_STR
10134 BGP_STR
10135 "Address Family\n"
10136 BGP_SAFI_HELP_STR
10137 "Clear bestpath and re-advertise\n"
10138 "IPv6 prefix\n")
10139 {
10140 int idx_safi = 0;
10141 int idx_ipv6_prefix = 0;
10142 safi_t safi = SAFI_UNICAST;
10143 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
10144 argv[idx_ipv6_prefix]->arg : NULL;
10145
10146 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
10147 return bgp_clear_prefix(
10148 vty, NULL, prefix, AFI_IP6,
10149 safi, NULL);
10150 }
10151
10152 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
10153 clear_bgp_instance_ipv6_safi_prefix_cmd,
10154 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
10155 CLEAR_STR
10156 IP_STR
10157 BGP_STR
10158 BGP_INSTANCE_HELP_STR
10159 "Address Family\n"
10160 BGP_SAFI_HELP_STR
10161 "Clear bestpath and re-advertise\n"
10162 "IPv6 prefix\n")
10163 {
10164 int idx_safi = 0;
10165 int idx_vrfview = 0;
10166 int idx_ipv6_prefix = 0;
10167 safi_t safi = SAFI_UNICAST;
10168 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
10169 argv[idx_ipv6_prefix]->arg : NULL;
10170 char *vrfview = NULL;
10171
10172 /* [<view|vrf> VIEWVRFNAME] */
10173 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
10174 vrfview = argv[idx_vrfview + 1]->arg;
10175 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
10176 vrfview = NULL;
10177 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
10178 /* [<view> VIEWVRFNAME] */
10179 vrfview = argv[idx_vrfview + 1]->arg;
10180 }
10181 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
10182
10183 return bgp_clear_prefix(
10184 vty, vrfview, prefix,
10185 AFI_IP6, safi, NULL);
10186 }
10187
10188 DEFUN (show_bgp_views,
10189 show_bgp_views_cmd,
10190 "show [ip] bgp views",
10191 SHOW_STR
10192 IP_STR
10193 BGP_STR
10194 "Show the defined BGP views\n")
10195 {
10196 struct list *inst = bm->bgp;
10197 struct listnode *node;
10198 struct bgp *bgp;
10199
10200 vty_out(vty, "Defined BGP views:\n");
10201 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10202 /* Skip VRFs. */
10203 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
10204 continue;
10205 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
10206 bgp->as);
10207 }
10208
10209 return CMD_SUCCESS;
10210 }
10211
10212 DEFUN (show_bgp_vrfs,
10213 show_bgp_vrfs_cmd,
10214 "show [ip] bgp vrfs [json]",
10215 SHOW_STR
10216 IP_STR
10217 BGP_STR
10218 "Show BGP VRFs\n"
10219 JSON_STR)
10220 {
10221 char buf[ETHER_ADDR_STRLEN];
10222 struct list *inst = bm->bgp;
10223 struct listnode *node;
10224 struct bgp *bgp;
10225 bool uj = use_json(argc, argv);
10226 json_object *json = NULL;
10227 json_object *json_vrfs = NULL;
10228 int count = 0;
10229
10230 if (uj) {
10231 json = json_object_new_object();
10232 json_vrfs = json_object_new_object();
10233 }
10234
10235 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10236 const char *name, *type;
10237 struct peer *peer;
10238 struct listnode *node2, *nnode2;
10239 int peers_cfg, peers_estb;
10240 json_object *json_vrf = NULL;
10241
10242 /* Skip Views. */
10243 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
10244 continue;
10245
10246 count++;
10247 if (!uj && count == 1) {
10248 vty_out(vty,
10249 "%4s %-5s %-16s %9s %10s %-37s\n",
10250 "Type", "Id", "routerId", "#PeersCfg",
10251 "#PeersEstb", "Name");
10252 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
10253 "L3-VNI", "RouterMAC", "Interface");
10254 }
10255
10256 peers_cfg = peers_estb = 0;
10257 if (uj)
10258 json_vrf = json_object_new_object();
10259
10260
10261 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
10262 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10263 continue;
10264 peers_cfg++;
10265 if (peer->status == Established)
10266 peers_estb++;
10267 }
10268
10269 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
10270 name = VRF_DEFAULT_NAME;
10271 type = "DFLT";
10272 } else {
10273 name = bgp->name;
10274 type = "VRF";
10275 }
10276
10277
10278 if (uj) {
10279 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10280 ? -1
10281 : (int64_t)bgp->vrf_id;
10282 char buf[BUFSIZ] = {0};
10283
10284 json_object_string_add(json_vrf, "type", type);
10285 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
10286 json_object_string_add(json_vrf, "routerId",
10287 inet_ntop(AF_INET,
10288 &bgp->router_id, buf,
10289 sizeof(buf)));
10290 json_object_int_add(json_vrf, "numConfiguredPeers",
10291 peers_cfg);
10292 json_object_int_add(json_vrf, "numEstablishedPeers",
10293 peers_estb);
10294
10295 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
10296 json_object_string_add(
10297 json_vrf, "rmac",
10298 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
10299 json_object_string_add(json_vrf, "interface",
10300 ifindex2ifname(bgp->l3vni_svi_ifindex,
10301 bgp->vrf_id));
10302 json_object_object_add(json_vrfs, name, json_vrf);
10303 } else {
10304 vty_out(vty, "%4s %-5d %-16pI4 %-9u %-10u %-37s\n",
10305 type,
10306 bgp->vrf_id == VRF_UNKNOWN ? -1
10307 : (int)bgp->vrf_id,
10308 &bgp->router_id, peers_cfg, peers_estb, name);
10309 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
10310 bgp->l3vni,
10311 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
10312 ifindex2ifname(bgp->l3vni_svi_ifindex,
10313 bgp->vrf_id));
10314 }
10315 }
10316
10317 if (uj) {
10318 json_object_object_add(json, "vrfs", json_vrfs);
10319
10320 json_object_int_add(json, "totalVrfs", count);
10321
10322 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10323 json, JSON_C_TO_STRING_PRETTY));
10324 json_object_free(json);
10325 } else {
10326 if (count)
10327 vty_out(vty,
10328 "\nTotal number of VRFs (including default): %d\n",
10329 count);
10330 }
10331
10332 return CMD_SUCCESS;
10333 }
10334
10335 DEFUN (show_bgp_mac_hash,
10336 show_bgp_mac_hash_cmd,
10337 "show bgp mac hash",
10338 SHOW_STR
10339 BGP_STR
10340 "Mac Address\n"
10341 "Mac Address database\n")
10342 {
10343 bgp_mac_dump_table(vty);
10344
10345 return CMD_SUCCESS;
10346 }
10347
10348 static void show_tip_entry(struct hash_bucket *bucket, void *args)
10349 {
10350 struct vty *vty = (struct vty *)args;
10351 struct tip_addr *tip = (struct tip_addr *)bucket->data;
10352
10353 vty_out(vty, "addr: %pI4, count: %d\n", &tip->addr, tip->refcnt);
10354 }
10355
10356 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
10357 {
10358 vty_out(vty, "self nexthop database:\n");
10359 bgp_nexthop_show_address_hash(vty, bgp);
10360
10361 vty_out(vty, "Tunnel-ip database:\n");
10362 hash_iterate(bgp->tip_hash,
10363 (void (*)(struct hash_bucket *, void *))show_tip_entry,
10364 vty);
10365 }
10366
10367 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
10368 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
10369 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
10370 "martian next-hops\n"
10371 "martian next-hop database\n")
10372 {
10373 struct bgp *bgp = NULL;
10374 int idx = 0;
10375 char *name = NULL;
10376
10377 /* [<vrf> VIEWVRFNAME] */
10378 if (argv_find(argv, argc, "vrf", &idx)) {
10379 name = argv[idx + 1]->arg;
10380 if (name && strmatch(name, VRF_DEFAULT_NAME))
10381 name = NULL;
10382 } else if (argv_find(argv, argc, "view", &idx))
10383 /* [<view> VIEWVRFNAME] */
10384 name = argv[idx + 1]->arg;
10385 if (name)
10386 bgp = bgp_lookup_by_name(name);
10387 else
10388 bgp = bgp_get_default();
10389
10390 if (!bgp) {
10391 vty_out(vty, "%% No BGP process is configured\n");
10392 return CMD_WARNING;
10393 }
10394 bgp_show_martian_nexthops(vty, bgp);
10395
10396 return CMD_SUCCESS;
10397 }
10398
10399 DEFUN (show_bgp_memory,
10400 show_bgp_memory_cmd,
10401 "show [ip] bgp memory",
10402 SHOW_STR
10403 IP_STR
10404 BGP_STR
10405 "Global BGP memory statistics\n")
10406 {
10407 char memstrbuf[MTYPE_MEMSTR_LEN];
10408 unsigned long count;
10409
10410 /* RIB related usage stats */
10411 count = mtype_stats_alloc(MTYPE_BGP_NODE);
10412 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
10413 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10414 count * sizeof(struct bgp_dest)));
10415
10416 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
10417 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
10418 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10419 count * sizeof(struct bgp_path_info)));
10420 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
10421 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
10422 count,
10423 mtype_memstr(
10424 memstrbuf, sizeof(memstrbuf),
10425 count * sizeof(struct bgp_path_info_extra)));
10426
10427 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
10428 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
10429 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10430 count * sizeof(struct bgp_static)));
10431
10432 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
10433 vty_out(vty, "%ld Packets, using %s of memory\n", count,
10434 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10435 count * sizeof(struct bpacket)));
10436
10437 /* Adj-In/Out */
10438 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
10439 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
10440 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10441 count * sizeof(struct bgp_adj_in)));
10442 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
10443 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
10444 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10445 count * sizeof(struct bgp_adj_out)));
10446
10447 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
10448 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
10449 count,
10450 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10451 count * sizeof(struct bgp_nexthop_cache)));
10452
10453 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
10454 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
10455 count,
10456 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10457 count * sizeof(struct bgp_damp_info)));
10458
10459 /* Attributes */
10460 count = attr_count();
10461 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
10462 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10463 count * sizeof(struct attr)));
10464
10465 if ((count = attr_unknown_count()))
10466 vty_out(vty, "%ld unknown attributes\n", count);
10467
10468 /* AS_PATH attributes */
10469 count = aspath_count();
10470 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
10471 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10472 count * sizeof(struct aspath)));
10473
10474 count = mtype_stats_alloc(MTYPE_AS_SEG);
10475 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
10476 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10477 count * sizeof(struct assegment)));
10478
10479 /* Other attributes */
10480 if ((count = community_count()))
10481 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
10482 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10483 count * sizeof(struct community)));
10484 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
10485 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
10486 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10487 count * sizeof(struct ecommunity)));
10488 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
10489 vty_out(vty,
10490 "%ld BGP large-community entries, using %s of memory\n",
10491 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10492 count * sizeof(struct lcommunity)));
10493
10494 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
10495 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
10496 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10497 count * sizeof(struct cluster_list)));
10498
10499 /* Peer related usage */
10500 count = mtype_stats_alloc(MTYPE_BGP_PEER);
10501 vty_out(vty, "%ld peers, using %s of memory\n", count,
10502 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10503 count * sizeof(struct peer)));
10504
10505 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
10506 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
10507 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10508 count * sizeof(struct peer_group)));
10509
10510 /* Other */
10511 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
10512 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
10513 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10514 count * sizeof(regex_t)));
10515 return CMD_SUCCESS;
10516 }
10517
10518 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
10519 {
10520 json_object *bestpath = json_object_new_object();
10521
10522 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
10523 json_object_string_add(bestpath, "asPath", "ignore");
10524
10525 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
10526 json_object_string_add(bestpath, "asPath", "confed");
10527
10528 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
10529 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
10530 json_object_string_add(bestpath, "multiPathRelax",
10531 "as-set");
10532 else
10533 json_object_string_add(bestpath, "multiPathRelax",
10534 "true");
10535 } else
10536 json_object_string_add(bestpath, "multiPathRelax", "false");
10537
10538 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
10539 json_object_string_add(bestpath, "compareRouterId", "true");
10540 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
10541 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
10542 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
10543 json_object_string_add(bestpath, "med", "confed");
10544 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
10545 json_object_string_add(bestpath, "med",
10546 "missing-as-worst");
10547 else
10548 json_object_string_add(bestpath, "med", "true");
10549 }
10550
10551 json_object_object_add(json, "bestPath", bestpath);
10552 }
10553
10554 /* Print the error code/subcode for why the peer is down */
10555 static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
10556 json_object *json_peer, bool use_json)
10557 {
10558 const char *code_str;
10559 const char *subcode_str;
10560
10561 if (use_json) {
10562 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10563 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10564 char errorcodesubcode_hexstr[5];
10565 char errorcodesubcode_str[256];
10566
10567 code_str = bgp_notify_code_str(peer->notify.code);
10568 subcode_str = bgp_notify_subcode_str(
10569 peer->notify.code,
10570 peer->notify.subcode);
10571
10572 snprintf(errorcodesubcode_hexstr,
10573 sizeof(errorcodesubcode_hexstr), "%02X%02X",
10574 peer->notify.code, peer->notify.subcode);
10575 json_object_string_add(json_peer,
10576 "lastErrorCodeSubcode",
10577 errorcodesubcode_hexstr);
10578 snprintf(errorcodesubcode_str, 255, "%s%s",
10579 code_str, subcode_str);
10580 json_object_string_add(json_peer,
10581 "lastNotificationReason",
10582 errorcodesubcode_str);
10583 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10584 && peer->notify.code == BGP_NOTIFY_CEASE
10585 && (peer->notify.subcode
10586 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10587 || peer->notify.subcode
10588 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10589 && peer->notify.length) {
10590 char msgbuf[1024];
10591 const char *msg_str;
10592
10593 msg_str = bgp_notify_admin_message(
10594 msgbuf, sizeof(msgbuf),
10595 (uint8_t *)peer->notify.data,
10596 peer->notify.length);
10597 if (msg_str)
10598 json_object_string_add(
10599 json_peer,
10600 "lastShutdownDescription",
10601 msg_str);
10602 }
10603
10604 }
10605 json_object_string_add(json_peer, "lastResetDueTo",
10606 peer_down_str[(int)peer->last_reset]);
10607 json_object_int_add(json_peer, "lastResetCode",
10608 peer->last_reset);
10609 } else {
10610 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10611 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10612 code_str = bgp_notify_code_str(peer->notify.code);
10613 subcode_str =
10614 bgp_notify_subcode_str(peer->notify.code,
10615 peer->notify.subcode);
10616 vty_out(vty, " Notification %s (%s%s)\n",
10617 peer->last_reset == PEER_DOWN_NOTIFY_SEND
10618 ? "sent"
10619 : "received",
10620 code_str, subcode_str);
10621 } else {
10622 vty_out(vty, " %s\n",
10623 peer_down_str[(int)peer->last_reset]);
10624 }
10625 }
10626 }
10627
10628 static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
10629 safi_t safi)
10630 {
10631 return ((peer->status != Established) ||
10632 !peer->afc_recv[afi][safi]);
10633 }
10634
10635 static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
10636 struct peer *peer, json_object *json_peer,
10637 int max_neighbor_width, bool use_json)
10638 {
10639 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10640 int len;
10641
10642 if (use_json) {
10643 if (peer_dynamic_neighbor(peer))
10644 json_object_boolean_true_add(json_peer,
10645 "dynamicPeer");
10646 if (peer->hostname)
10647 json_object_string_add(json_peer, "hostname",
10648 peer->hostname);
10649
10650 if (peer->domainname)
10651 json_object_string_add(json_peer, "domainname",
10652 peer->domainname);
10653 json_object_int_add(json_peer, "connectionsEstablished",
10654 peer->established);
10655 json_object_int_add(json_peer, "connectionsDropped",
10656 peer->dropped);
10657 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10658 use_json, json_peer);
10659 if (peer->status == Established)
10660 json_object_string_add(json_peer, "lastResetDueTo",
10661 "AFI/SAFI Not Negotiated");
10662 else
10663 bgp_show_peer_reset(NULL, peer, json_peer, true);
10664 } else {
10665 dn_flag[1] = '\0';
10666 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
10667 if (peer->hostname
10668 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
10669 len = vty_out(vty, "%s%s(%s)", dn_flag,
10670 peer->hostname, peer->host);
10671 else
10672 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10673
10674 /* pad the neighbor column with spaces */
10675 if (len < max_neighbor_width)
10676 vty_out(vty, "%*s", max_neighbor_width - len,
10677 " ");
10678 vty_out(vty, "%7d %7d %9s", peer->established,
10679 peer->dropped,
10680 peer_uptime(peer->uptime, timebuf,
10681 BGP_UPTIME_LEN, 0, NULL));
10682 if (peer->status == Established)
10683 vty_out(vty, " AFI/SAFI Not Negotiated\n");
10684 else
10685 bgp_show_peer_reset(vty, peer, NULL,
10686 false);
10687 }
10688 }
10689
10690
10691 /* Show BGP peer's summary information. */
10692 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
10693 bool show_failed, bool show_established,
10694 bool use_json)
10695 {
10696 struct peer *peer;
10697 struct listnode *node, *nnode;
10698 unsigned int count = 0, dn_count = 0;
10699 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10700 char neighbor_buf[VTY_BUFSIZ];
10701 int neighbor_col_default_width = 16;
10702 int len, failed_count = 0;
10703 int max_neighbor_width = 0;
10704 int pfx_rcd_safi;
10705 json_object *json = NULL;
10706 json_object *json_peer = NULL;
10707 json_object *json_peers = NULL;
10708 struct peer_af *paf;
10709 struct bgp_filter *filter;
10710
10711 /* labeled-unicast routes are installed in the unicast table so in order
10712 * to
10713 * display the correct PfxRcd value we must look at SAFI_UNICAST
10714 */
10715
10716 if (safi == SAFI_LABELED_UNICAST)
10717 pfx_rcd_safi = SAFI_UNICAST;
10718 else
10719 pfx_rcd_safi = safi;
10720
10721 if (use_json) {
10722 json = json_object_new_object();
10723 json_peers = json_object_new_object();
10724 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10725 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10726 continue;
10727
10728 if (peer->afc[afi][safi]) {
10729 /* See if we have at least a single failed peer */
10730 if (bgp_has_peer_failed(peer, afi, safi))
10731 failed_count++;
10732 count++;
10733 }
10734 if (peer_dynamic_neighbor(peer))
10735 dn_count++;
10736 }
10737
10738 } else {
10739 /* Loop over all neighbors that will be displayed to determine
10740 * how many
10741 * characters are needed for the Neighbor column
10742 */
10743 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10744 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10745 continue;
10746
10747 if (peer->afc[afi][safi]) {
10748 memset(dn_flag, '\0', sizeof(dn_flag));
10749 if (peer_dynamic_neighbor(peer))
10750 dn_flag[0] = '*';
10751
10752 if (peer->hostname
10753 && CHECK_FLAG(bgp->flags,
10754 BGP_FLAG_SHOW_HOSTNAME))
10755 snprintf(neighbor_buf,
10756 sizeof(neighbor_buf),
10757 "%s%s(%s) ", dn_flag,
10758 peer->hostname, peer->host);
10759 else
10760 snprintf(neighbor_buf,
10761 sizeof(neighbor_buf), "%s%s ",
10762 dn_flag, peer->host);
10763
10764 len = strlen(neighbor_buf);
10765
10766 if (len > max_neighbor_width)
10767 max_neighbor_width = len;
10768
10769 /* See if we have at least a single failed peer */
10770 if (bgp_has_peer_failed(peer, afi, safi))
10771 failed_count++;
10772 count++;
10773 }
10774 }
10775
10776 /* Originally we displayed the Neighbor column as 16
10777 * characters wide so make that the default
10778 */
10779 if (max_neighbor_width < neighbor_col_default_width)
10780 max_neighbor_width = neighbor_col_default_width;
10781 }
10782
10783 if (show_failed && !failed_count) {
10784 if (use_json) {
10785 json_object_int_add(json, "failedPeersCount", 0);
10786 json_object_int_add(json, "dynamicPeers", dn_count);
10787 json_object_int_add(json, "totalPeers", count);
10788
10789 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10790 json, JSON_C_TO_STRING_PRETTY));
10791 json_object_free(json);
10792 } else {
10793 vty_out(vty, "%% No failed BGP neighbors found\n");
10794 vty_out(vty, "\nTotal number of neighbors %d\n", count);
10795 }
10796 return CMD_SUCCESS;
10797 }
10798
10799 count = 0; /* Reset the value as its used again */
10800 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10801 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10802 continue;
10803
10804 if (!peer->afc[afi][safi])
10805 continue;
10806
10807 if (!count) {
10808 unsigned long ents;
10809 char memstrbuf[MTYPE_MEMSTR_LEN];
10810 int64_t vrf_id_ui;
10811
10812 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10813 ? -1
10814 : (int64_t)bgp->vrf_id;
10815
10816 /* Usage summary and header */
10817 if (use_json) {
10818 char buf[BUFSIZ] = {0};
10819
10820 json_object_string_add(
10821 json, "routerId",
10822 inet_ntop(AF_INET, &bgp->router_id, buf,
10823 sizeof(buf)));
10824 json_object_int_add(json, "as", bgp->as);
10825 json_object_int_add(json, "vrfId", vrf_id_ui);
10826 json_object_string_add(
10827 json, "vrfName",
10828 (bgp->inst_type
10829 == BGP_INSTANCE_TYPE_DEFAULT)
10830 ? VRF_DEFAULT_NAME
10831 : bgp->name);
10832 } else {
10833 vty_out(vty,
10834 "BGP router identifier %pI4, local AS number %u vrf-id %d",
10835 &bgp->router_id, bgp->as,
10836 bgp->vrf_id == VRF_UNKNOWN
10837 ? -1
10838 : (int)bgp->vrf_id);
10839 vty_out(vty, "\n");
10840 }
10841
10842 if (bgp_update_delay_configured(bgp)) {
10843 if (use_json) {
10844 json_object_int_add(
10845 json, "updateDelayLimit",
10846 bgp->v_update_delay);
10847
10848 if (bgp->v_update_delay
10849 != bgp->v_establish_wait)
10850 json_object_int_add(
10851 json,
10852 "updateDelayEstablishWait",
10853 bgp->v_establish_wait);
10854
10855 if (bgp_update_delay_active(bgp)) {
10856 json_object_string_add(
10857 json,
10858 "updateDelayFirstNeighbor",
10859 bgp->update_delay_begin_time);
10860 json_object_boolean_true_add(
10861 json,
10862 "updateDelayInProgress");
10863 } else {
10864 if (bgp->update_delay_over) {
10865 json_object_string_add(
10866 json,
10867 "updateDelayFirstNeighbor",
10868 bgp->update_delay_begin_time);
10869 json_object_string_add(
10870 json,
10871 "updateDelayBestpathResumed",
10872 bgp->update_delay_end_time);
10873 json_object_string_add(
10874 json,
10875 "updateDelayZebraUpdateResume",
10876 bgp->update_delay_zebra_resume_time);
10877 json_object_string_add(
10878 json,
10879 "updateDelayPeerUpdateResume",
10880 bgp->update_delay_peers_resume_time);
10881 }
10882 }
10883 } else {
10884 vty_out(vty,
10885 "Read-only mode update-delay limit: %d seconds\n",
10886 bgp->v_update_delay);
10887 if (bgp->v_update_delay
10888 != bgp->v_establish_wait)
10889 vty_out(vty,
10890 " Establish wait: %d seconds\n",
10891 bgp->v_establish_wait);
10892
10893 if (bgp_update_delay_active(bgp)) {
10894 vty_out(vty,
10895 " First neighbor established: %s\n",
10896 bgp->update_delay_begin_time);
10897 vty_out(vty,
10898 " Delay in progress\n");
10899 } else {
10900 if (bgp->update_delay_over) {
10901 vty_out(vty,
10902 " First neighbor established: %s\n",
10903 bgp->update_delay_begin_time);
10904 vty_out(vty,
10905 " Best-paths resumed: %s\n",
10906 bgp->update_delay_end_time);
10907 vty_out(vty,
10908 " zebra update resumed: %s\n",
10909 bgp->update_delay_zebra_resume_time);
10910 vty_out(vty,
10911 " peers update resumed: %s\n",
10912 bgp->update_delay_peers_resume_time);
10913 }
10914 }
10915 }
10916 }
10917
10918 if (use_json) {
10919 if (bgp_maxmed_onstartup_configured(bgp)
10920 && bgp->maxmed_active)
10921 json_object_boolean_true_add(
10922 json, "maxMedOnStartup");
10923 if (bgp->v_maxmed_admin)
10924 json_object_boolean_true_add(
10925 json, "maxMedAdministrative");
10926
10927 json_object_int_add(
10928 json, "tableVersion",
10929 bgp_table_version(bgp->rib[afi][safi]));
10930
10931 ents = bgp_table_count(bgp->rib[afi][safi]);
10932 json_object_int_add(json, "ribCount", ents);
10933 json_object_int_add(
10934 json, "ribMemory",
10935 ents * sizeof(struct bgp_dest));
10936
10937 ents = bgp->af_peer_count[afi][safi];
10938 json_object_int_add(json, "peerCount", ents);
10939 json_object_int_add(json, "peerMemory",
10940 ents * sizeof(struct peer));
10941
10942 if ((ents = listcount(bgp->group))) {
10943 json_object_int_add(
10944 json, "peerGroupCount", ents);
10945 json_object_int_add(
10946 json, "peerGroupMemory",
10947 ents * sizeof(struct
10948 peer_group));
10949 }
10950
10951 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10952 BGP_CONFIG_DAMPENING))
10953 json_object_boolean_true_add(
10954 json, "dampeningEnabled");
10955 } else {
10956 if (bgp_maxmed_onstartup_configured(bgp)
10957 && bgp->maxmed_active)
10958 vty_out(vty,
10959 "Max-med on-startup active\n");
10960 if (bgp->v_maxmed_admin)
10961 vty_out(vty,
10962 "Max-med administrative active\n");
10963
10964 vty_out(vty, "BGP table version %" PRIu64 "\n",
10965 bgp_table_version(bgp->rib[afi][safi]));
10966
10967 ents = bgp_table_count(bgp->rib[afi][safi]);
10968 vty_out(vty,
10969 "RIB entries %ld, using %s of memory\n",
10970 ents,
10971 mtype_memstr(
10972 memstrbuf, sizeof(memstrbuf),
10973 ents
10974 * sizeof(struct
10975 bgp_dest)));
10976
10977 /* Peer related usage */
10978 ents = bgp->af_peer_count[afi][safi];
10979 vty_out(vty, "Peers %ld, using %s of memory\n",
10980 ents,
10981 mtype_memstr(
10982 memstrbuf, sizeof(memstrbuf),
10983 ents * sizeof(struct peer)));
10984
10985 if ((ents = listcount(bgp->group)))
10986 vty_out(vty,
10987 "Peer groups %ld, using %s of memory\n",
10988 ents,
10989 mtype_memstr(
10990 memstrbuf,
10991 sizeof(memstrbuf),
10992 ents * sizeof(struct
10993 peer_group)));
10994
10995 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10996 BGP_CONFIG_DAMPENING))
10997 vty_out(vty, "Dampening enabled.\n");
10998 vty_out(vty, "\n");
10999
11000 /* Subtract 8 here because 'Neighbor' is
11001 * 8 characters */
11002 vty_out(vty, "Neighbor");
11003 vty_out(vty, "%*s", max_neighbor_width - 8,
11004 " ");
11005 if (show_failed)
11006 vty_out(vty, "EstdCnt DropCnt ResetTime Reason\n");
11007 else
11008 vty_out(vty,
11009 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd PfxSnt Desc\n");
11010 }
11011 }
11012
11013 paf = peer_af_find(peer, afi, safi);
11014 filter = &peer->filter[afi][safi];
11015
11016 count++;
11017 /* Works for both failed & successful cases */
11018 if (peer_dynamic_neighbor(peer))
11019 dn_count++;
11020
11021 if (use_json) {
11022 json_peer = NULL;
11023
11024 if (show_failed &&
11025 bgp_has_peer_failed(peer, afi, safi)) {
11026 json_peer = json_object_new_object();
11027 bgp_show_failed_summary(vty, bgp, peer,
11028 json_peer, 0, use_json);
11029 } else if (!show_failed) {
11030 if (show_established
11031 && bgp_has_peer_failed(peer, afi, safi))
11032 continue;
11033
11034 json_peer = json_object_new_object();
11035 if (peer_dynamic_neighbor(peer)) {
11036 json_object_boolean_true_add(json_peer,
11037 "dynamicPeer");
11038 }
11039
11040 if (peer->hostname)
11041 json_object_string_add(json_peer, "hostname",
11042 peer->hostname);
11043
11044 if (peer->domainname)
11045 json_object_string_add(json_peer, "domainname",
11046 peer->domainname);
11047
11048 json_object_int_add(json_peer, "remoteAs", peer->as);
11049 json_object_int_add(json_peer, "version", 4);
11050 json_object_int_add(json_peer, "msgRcvd",
11051 PEER_TOTAL_RX(peer));
11052 json_object_int_add(json_peer, "msgSent",
11053 PEER_TOTAL_TX(peer));
11054
11055 atomic_size_t outq_count, inq_count;
11056 outq_count = atomic_load_explicit(
11057 &peer->obuf->count,
11058 memory_order_relaxed);
11059 inq_count = atomic_load_explicit(
11060 &peer->ibuf->count,
11061 memory_order_relaxed);
11062
11063 json_object_int_add(json_peer, "tableVersion",
11064 peer->version[afi][safi]);
11065 json_object_int_add(json_peer, "outq",
11066 outq_count);
11067 json_object_int_add(json_peer, "inq",
11068 inq_count);
11069 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
11070 use_json, json_peer);
11071
11072 json_object_int_add(json_peer, "pfxRcd",
11073 peer->pcount[afi][pfx_rcd_safi]);
11074
11075 if (paf && PAF_SUBGRP(paf))
11076 json_object_int_add(
11077 json_peer, "pfxSnt",
11078 (PAF_SUBGRP(paf))->scount);
11079 else
11080 json_object_int_add(json_peer, "pfxSnt",
11081 0);
11082
11083 /* BGP FSM state */
11084 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
11085 || CHECK_FLAG(peer->bgp->flags,
11086 BGP_FLAG_SHUTDOWN))
11087 json_object_string_add(json_peer,
11088 "state",
11089 "Idle (Admin)");
11090 else if (peer->afc_recv[afi][safi])
11091 json_object_string_add(
11092 json_peer, "state",
11093 lookup_msg(bgp_status_msg,
11094 peer->status, NULL));
11095 else if (CHECK_FLAG(
11096 peer->sflags,
11097 PEER_STATUS_PREFIX_OVERFLOW))
11098 json_object_string_add(json_peer,
11099 "state",
11100 "Idle (PfxCt)");
11101 else
11102 json_object_string_add(
11103 json_peer, "state",
11104 lookup_msg(bgp_status_msg,
11105 peer->status, NULL));
11106
11107 /* BGP peer state */
11108 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
11109 || CHECK_FLAG(peer->bgp->flags,
11110 BGP_FLAG_SHUTDOWN))
11111 json_object_string_add(json_peer,
11112 "peerState",
11113 "Admin");
11114 else if (CHECK_FLAG(
11115 peer->sflags,
11116 PEER_STATUS_PREFIX_OVERFLOW))
11117 json_object_string_add(json_peer,
11118 "peerState",
11119 "PfxCt");
11120 else if (CHECK_FLAG(peer->flags,
11121 PEER_FLAG_PASSIVE))
11122 json_object_string_add(json_peer,
11123 "peerState",
11124 "Passive");
11125 else if (CHECK_FLAG(peer->sflags,
11126 PEER_STATUS_NSF_WAIT))
11127 json_object_string_add(json_peer,
11128 "peerState",
11129 "NSF passive");
11130 else if (CHECK_FLAG(
11131 peer->bgp->flags,
11132 BGP_FLAG_EBGP_REQUIRES_POLICY)
11133 && (!bgp_inbound_policy_exists(peer,
11134 filter)
11135 || !bgp_outbound_policy_exists(
11136 peer, filter)))
11137 json_object_string_add(json_peer,
11138 "peerState",
11139 "Policy");
11140 else
11141 json_object_string_add(
11142 json_peer, "peerState", "OK");
11143
11144 json_object_int_add(json_peer, "connectionsEstablished",
11145 peer->established);
11146 json_object_int_add(json_peer, "connectionsDropped",
11147 peer->dropped);
11148 if (peer->desc)
11149 json_object_string_add(
11150 json_peer, "desc", peer->desc);
11151 }
11152 /* Avoid creating empty peer dicts in JSON */
11153 if (json_peer == NULL)
11154 continue;
11155
11156 if (peer->conf_if)
11157 json_object_string_add(json_peer, "idType",
11158 "interface");
11159 else if (peer->su.sa.sa_family == AF_INET)
11160 json_object_string_add(json_peer, "idType",
11161 "ipv4");
11162 else if (peer->su.sa.sa_family == AF_INET6)
11163 json_object_string_add(json_peer, "idType",
11164 "ipv6");
11165 json_object_object_add(json_peers, peer->host,
11166 json_peer);
11167 } else {
11168 if (show_failed &&
11169 bgp_has_peer_failed(peer, afi, safi)) {
11170 bgp_show_failed_summary(vty, bgp, peer, NULL,
11171 max_neighbor_width,
11172 use_json);
11173 } else if (!show_failed) {
11174 if (show_established
11175 && bgp_has_peer_failed(peer, afi, safi))
11176 continue;
11177
11178 memset(dn_flag, '\0', sizeof(dn_flag));
11179 if (peer_dynamic_neighbor(peer)) {
11180 dn_flag[0] = '*';
11181 }
11182
11183 if (peer->hostname
11184 && CHECK_FLAG(bgp->flags,
11185 BGP_FLAG_SHOW_HOSTNAME))
11186 len = vty_out(vty, "%s%s(%s)", dn_flag,
11187 peer->hostname,
11188 peer->host);
11189 else
11190 len = vty_out(vty, "%s%s", dn_flag, peer->host);
11191
11192 /* pad the neighbor column with spaces */
11193 if (len < max_neighbor_width)
11194 vty_out(vty, "%*s", max_neighbor_width - len,
11195 " ");
11196
11197 atomic_size_t outq_count, inq_count;
11198 outq_count = atomic_load_explicit(
11199 &peer->obuf->count,
11200 memory_order_relaxed);
11201 inq_count = atomic_load_explicit(
11202 &peer->ibuf->count,
11203 memory_order_relaxed);
11204
11205 vty_out(vty,
11206 "4 %10u %9u %9u %8" PRIu64" %4zu %4zu %8s",
11207 peer->as, PEER_TOTAL_RX(peer),
11208 PEER_TOTAL_TX(peer),
11209 peer->version[afi][safi], inq_count,
11210 outq_count,
11211 peer_uptime(peer->uptime, timebuf,
11212 BGP_UPTIME_LEN, 0, NULL));
11213
11214 if (peer->status == Established) {
11215 if (peer->afc_recv[afi][safi]) {
11216 if (CHECK_FLAG(
11217 bgp->flags,
11218 BGP_FLAG_EBGP_REQUIRES_POLICY)
11219 && !bgp_inbound_policy_exists(
11220 peer, filter))
11221 vty_out(vty, " %12s",
11222 "(Policy)");
11223 else
11224 vty_out(vty,
11225 " %12u",
11226 peer->pcount
11227 [afi]
11228 [pfx_rcd_safi]);
11229 } else {
11230 vty_out(vty, " NoNeg");
11231 }
11232
11233 if (paf && PAF_SUBGRP(paf)) {
11234 if (CHECK_FLAG(
11235 bgp->flags,
11236 BGP_FLAG_EBGP_REQUIRES_POLICY)
11237 && !bgp_outbound_policy_exists(
11238 peer, filter))
11239 vty_out(vty, " %8s",
11240 "(Policy)");
11241 else
11242 vty_out(vty,
11243 " %8u",
11244 (PAF_SUBGRP(
11245 paf))
11246 ->scount);
11247 }
11248 } else {
11249 if (CHECK_FLAG(peer->flags,
11250 PEER_FLAG_SHUTDOWN)
11251 || CHECK_FLAG(peer->bgp->flags,
11252 BGP_FLAG_SHUTDOWN))
11253 vty_out(vty, " Idle (Admin)");
11254 else if (CHECK_FLAG(
11255 peer->sflags,
11256 PEER_STATUS_PREFIX_OVERFLOW))
11257 vty_out(vty, " Idle (PfxCt)");
11258 else
11259 vty_out(vty, " %12s",
11260 lookup_msg(bgp_status_msg,
11261 peer->status, NULL));
11262
11263 vty_out(vty, " %8u", 0);
11264 }
11265 if (peer->desc)
11266 vty_out(vty, " %s", peer->desc);
11267 else
11268 vty_out(vty, " N/A");
11269 vty_out(vty, "\n");
11270 }
11271
11272 }
11273 }
11274
11275 if (use_json) {
11276 json_object_object_add(json, "peers", json_peers);
11277 json_object_int_add(json, "failedPeers", failed_count);
11278 json_object_int_add(json, "totalPeers", count);
11279 json_object_int_add(json, "dynamicPeers", dn_count);
11280
11281 if (!show_failed)
11282 bgp_show_bestpath_json(bgp, json);
11283
11284 vty_out(vty, "%s\n", json_object_to_json_string_ext(
11285 json, JSON_C_TO_STRING_PRETTY));
11286 json_object_free(json);
11287 } else {
11288 if (count)
11289 vty_out(vty, "\nTotal number of neighbors %d\n", count);
11290 else {
11291 vty_out(vty, "No %s neighbor is configured\n",
11292 get_afi_safi_str(afi, safi, false));
11293 }
11294
11295 if (dn_count) {
11296 vty_out(vty, "* - dynamic neighbor\n");
11297 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
11298 dn_count, bgp->dynamic_neighbors_limit);
11299 }
11300 }
11301
11302 return CMD_SUCCESS;
11303 }
11304
11305 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
11306 int safi, bool show_failed,
11307 bool show_established, bool use_json)
11308 {
11309 int is_first = 1;
11310 int afi_wildcard = (afi == AFI_MAX);
11311 int safi_wildcard = (safi == SAFI_MAX);
11312 int is_wildcard = (afi_wildcard || safi_wildcard);
11313 bool nbr_output = false;
11314
11315 if (use_json && is_wildcard)
11316 vty_out(vty, "{\n");
11317 if (afi_wildcard)
11318 afi = 1; /* AFI_IP */
11319 while (afi < AFI_MAX) {
11320 if (safi_wildcard)
11321 safi = 1; /* SAFI_UNICAST */
11322 while (safi < SAFI_MAX) {
11323 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
11324 nbr_output = true;
11325
11326 if (is_wildcard) {
11327 /*
11328 * So limit output to those afi/safi
11329 * pairs that
11330 * actualy have something interesting in
11331 * them
11332 */
11333 if (use_json) {
11334 if (!is_first)
11335 vty_out(vty, ",\n");
11336 else
11337 is_first = 0;
11338
11339 vty_out(vty, "\"%s\":",
11340 get_afi_safi_str(afi,
11341 safi,
11342 true));
11343 } else {
11344 vty_out(vty, "\n%s Summary:\n",
11345 get_afi_safi_str(afi,
11346 safi,
11347 false));
11348 }
11349 }
11350 bgp_show_summary(vty, bgp, afi, safi,
11351 show_failed, show_established,
11352 use_json);
11353 }
11354 safi++;
11355 if (!safi_wildcard)
11356 safi = SAFI_MAX;
11357 }
11358 afi++;
11359 if (!afi_wildcard)
11360 afi = AFI_MAX;
11361 }
11362
11363 if (use_json && is_wildcard)
11364 vty_out(vty, "}\n");
11365 else if (!nbr_output) {
11366 if (use_json)
11367 vty_out(vty, "{}\n");
11368 else
11369 vty_out(vty, "%% No BGP neighbors found\n");
11370 }
11371 }
11372
11373 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
11374 safi_t safi, bool show_failed,
11375 bool show_established,
11376 bool use_json)
11377 {
11378 struct listnode *node, *nnode;
11379 struct bgp *bgp;
11380 int is_first = 1;
11381 bool nbr_output = false;
11382
11383 if (use_json)
11384 vty_out(vty, "{\n");
11385
11386 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11387 nbr_output = true;
11388 if (use_json) {
11389 if (!is_first)
11390 vty_out(vty, ",\n");
11391 else
11392 is_first = 0;
11393
11394 vty_out(vty, "\"%s\":",
11395 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11396 ? VRF_DEFAULT_NAME
11397 : bgp->name);
11398 } else {
11399 vty_out(vty, "\nInstance %s:\n",
11400 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11401 ? VRF_DEFAULT_NAME
11402 : bgp->name);
11403 }
11404 bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_failed,
11405 show_established, use_json);
11406 }
11407
11408 if (use_json)
11409 vty_out(vty, "}\n");
11410 else if (!nbr_output)
11411 vty_out(vty, "%% BGP instance not found\n");
11412 }
11413
11414 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
11415 safi_t safi, bool show_failed, bool show_established,
11416 bool use_json)
11417 {
11418 struct bgp *bgp;
11419
11420 if (name) {
11421 if (strmatch(name, "all")) {
11422 bgp_show_all_instances_summary_vty(
11423 vty, afi, safi, show_failed, show_established,
11424 use_json);
11425 return CMD_SUCCESS;
11426 } else {
11427 bgp = bgp_lookup_by_name(name);
11428
11429 if (!bgp) {
11430 if (use_json)
11431 vty_out(vty, "{}\n");
11432 else
11433 vty_out(vty,
11434 "%% BGP instance not found\n");
11435 return CMD_WARNING;
11436 }
11437
11438 bgp_show_summary_afi_safi(vty, bgp, afi, safi,
11439 show_failed, show_established,
11440 use_json);
11441 return CMD_SUCCESS;
11442 }
11443 }
11444
11445 bgp = bgp_get_default();
11446
11447 if (bgp)
11448 bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_failed,
11449 show_established, use_json);
11450 else {
11451 if (use_json)
11452 vty_out(vty, "{}\n");
11453 else
11454 vty_out(vty, "%% BGP instance not found\n");
11455 return CMD_WARNING;
11456 }
11457
11458 return CMD_SUCCESS;
11459 }
11460
11461 /* `show [ip] bgp summary' commands. */
11462 DEFPY (show_ip_bgp_summary,
11463 show_ip_bgp_summary_cmd,
11464 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] [all$all] summary [established|failed] [json$uj]",
11465 SHOW_STR
11466 IP_STR
11467 BGP_STR
11468 BGP_INSTANCE_HELP_STR
11469 BGP_AFI_HELP_STR
11470 BGP_SAFI_WITH_LABEL_HELP_STR
11471 "Display the entries for all address families\n"
11472 "Summary of BGP neighbor status\n"
11473 "Show only sessions in Established state\n"
11474 "Show only sessions not in Established state\n"
11475 JSON_STR)
11476 {
11477 char *vrf = NULL;
11478 afi_t afi = AFI_MAX;
11479 safi_t safi = SAFI_MAX;
11480 bool show_failed = false;
11481 bool show_established = false;
11482
11483 int idx = 0;
11484
11485 /* show [ip] bgp */
11486 if (!all && argv_find(argv, argc, "ip", &idx))
11487 afi = AFI_IP;
11488 /* [<vrf> VIEWVRFNAME] */
11489 if (argv_find(argv, argc, "vrf", &idx)) {
11490 vrf = argv[idx + 1]->arg;
11491 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11492 vrf = NULL;
11493 } else if (argv_find(argv, argc, "view", &idx))
11494 /* [<view> VIEWVRFNAME] */
11495 vrf = argv[idx + 1]->arg;
11496 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11497 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11498 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11499 }
11500
11501 if (argv_find(argv, argc, "failed", &idx))
11502 show_failed = true;
11503 if (argv_find(argv, argc, "established", &idx))
11504 show_established = true;
11505
11506 return bgp_show_summary_vty(vty, vrf, afi, safi, show_failed,
11507 show_established, uj);
11508 }
11509
11510 const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
11511 {
11512 if (for_json)
11513 return get_afi_safi_json_str(afi, safi);
11514 else
11515 return get_afi_safi_vty_str(afi, safi);
11516 }
11517
11518
11519 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
11520 afi_t afi, safi_t safi,
11521 uint16_t adv_smcap, uint16_t adv_rmcap,
11522 uint16_t rcv_smcap, uint16_t rcv_rmcap,
11523 bool use_json, json_object *json_pref)
11524 {
11525 /* Send-Mode */
11526 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11527 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
11528 if (use_json) {
11529 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11530 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11531 json_object_string_add(json_pref, "sendMode",
11532 "advertisedAndReceived");
11533 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11534 json_object_string_add(json_pref, "sendMode",
11535 "advertised");
11536 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11537 json_object_string_add(json_pref, "sendMode",
11538 "received");
11539 } else {
11540 vty_out(vty, " Send-mode: ");
11541 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11542 vty_out(vty, "advertised");
11543 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11544 vty_out(vty, "%sreceived",
11545 CHECK_FLAG(p->af_cap[afi][safi],
11546 adv_smcap)
11547 ? ", "
11548 : "");
11549 vty_out(vty, "\n");
11550 }
11551 }
11552
11553 /* Receive-Mode */
11554 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11555 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
11556 if (use_json) {
11557 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11558 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11559 json_object_string_add(json_pref, "recvMode",
11560 "advertisedAndReceived");
11561 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11562 json_object_string_add(json_pref, "recvMode",
11563 "advertised");
11564 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11565 json_object_string_add(json_pref, "recvMode",
11566 "received");
11567 } else {
11568 vty_out(vty, " Receive-mode: ");
11569 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11570 vty_out(vty, "advertised");
11571 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11572 vty_out(vty, "%sreceived",
11573 CHECK_FLAG(p->af_cap[afi][safi],
11574 adv_rmcap)
11575 ? ", "
11576 : "");
11577 vty_out(vty, "\n");
11578 }
11579 }
11580 }
11581
11582 static void bgp_show_neighnor_graceful_restart_rbit(struct vty *vty,
11583 struct peer *p,
11584 bool use_json,
11585 json_object *json)
11586 {
11587 bool rbit_status = false;
11588
11589 if (!use_json)
11590 vty_out(vty, "\n R bit: ");
11591
11592 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
11593 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
11594 && (p->status == Established)) {
11595
11596 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_BIT_RCV))
11597 rbit_status = true;
11598 else
11599 rbit_status = false;
11600 }
11601
11602 if (rbit_status) {
11603 if (use_json)
11604 json_object_boolean_true_add(json, "rBit");
11605 else
11606 vty_out(vty, "True\n");
11607 } else {
11608 if (use_json)
11609 json_object_boolean_false_add(json, "rBit");
11610 else
11611 vty_out(vty, "False\n");
11612 }
11613 }
11614
11615 static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
11616 struct peer *peer,
11617 bool use_json,
11618 json_object *json)
11619 {
11620 const char *mode = "NotApplicable";
11621
11622 if (!use_json)
11623 vty_out(vty, "\n Remote GR Mode: ");
11624
11625 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
11626 && (peer->status == Established)) {
11627
11628 if ((peer->nsf_af_count == 0)
11629 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11630
11631 mode = "Disable";
11632
11633 } else if (peer->nsf_af_count == 0
11634 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11635
11636 mode = "Helper";
11637
11638 } else if (peer->nsf_af_count != 0
11639 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11640
11641 mode = "Restart";
11642 }
11643 }
11644
11645 if (use_json) {
11646 json_object_string_add(json, "remoteGrMode", mode);
11647 } else
11648 vty_out(vty, mode, "\n");
11649 }
11650
11651 static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
11652 struct peer *p,
11653 bool use_json,
11654 json_object *json)
11655 {
11656 const char *mode = "Invalid";
11657
11658 if (!use_json)
11659 vty_out(vty, " Local GR Mode: ");
11660
11661 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
11662 mode = "Helper";
11663 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
11664 mode = "Restart";
11665 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
11666 mode = "Disable";
11667 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
11668 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
11669 mode = "Helper*";
11670 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
11671 mode = "Restart*";
11672 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
11673 mode = "Disable*";
11674 else
11675 mode = "Invalid*";
11676 }
11677
11678 if (use_json) {
11679 json_object_string_add(json, "localGrMode", mode);
11680 } else {
11681 vty_out(vty, mode, "\n");
11682 }
11683 }
11684
11685 static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
11686 struct vty *vty, struct peer *peer, bool use_json, json_object *json)
11687 {
11688 afi_t afi;
11689 safi_t safi;
11690 json_object *json_afi_safi = NULL;
11691 json_object *json_timer = NULL;
11692 json_object *json_endofrib_status = NULL;
11693 bool eor_flag = false;
11694
11695 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
11696 for (safi = SAFI_UNICAST; safi <= SAFI_MPLS_VPN; safi++) {
11697 if (!peer->afc[afi][safi])
11698 continue;
11699
11700 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
11701 || !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
11702 continue;
11703
11704 if (use_json) {
11705 json_afi_safi = json_object_new_object();
11706 json_endofrib_status = json_object_new_object();
11707 json_timer = json_object_new_object();
11708 }
11709
11710 if (peer->eor_stime[afi][safi]
11711 >= peer->pkt_stime[afi][safi])
11712 eor_flag = true;
11713 else
11714 eor_flag = false;
11715
11716 if (!use_json) {
11717 vty_out(vty, " %s:\n",
11718 get_afi_safi_str(afi, safi, false));
11719
11720 vty_out(vty, " F bit: ");
11721 }
11722
11723 if (peer->nsf[afi][safi]
11724 && CHECK_FLAG(peer->af_cap[afi][safi],
11725 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
11726
11727 if (use_json) {
11728 json_object_boolean_true_add(
11729 json_afi_safi, "fBit");
11730 } else
11731 vty_out(vty, "True\n");
11732 } else {
11733 if (use_json)
11734 json_object_boolean_false_add(
11735 json_afi_safi, "fBit");
11736 else
11737 vty_out(vty, "False\n");
11738 }
11739
11740 if (!use_json)
11741 vty_out(vty, " End-of-RIB sent: ");
11742
11743 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11744 PEER_STATUS_EOR_SEND)) {
11745 if (use_json) {
11746 json_object_boolean_true_add(
11747 json_endofrib_status,
11748 "endOfRibSend");
11749
11750 PRINT_EOR_JSON(eor_flag);
11751 } else {
11752 vty_out(vty, "Yes\n");
11753 vty_out(vty,
11754 " End-of-RIB sent after update: ");
11755
11756 PRINT_EOR(eor_flag);
11757 }
11758 } else {
11759 if (use_json) {
11760 json_object_boolean_false_add(
11761 json_endofrib_status,
11762 "endOfRibSend");
11763 json_object_boolean_false_add(
11764 json_endofrib_status,
11765 "endOfRibSentAfterUpdate");
11766 } else {
11767 vty_out(vty, "No\n");
11768 vty_out(vty,
11769 " End-of-RIB sent after update: ");
11770 vty_out(vty, "No\n");
11771 }
11772 }
11773
11774 if (!use_json)
11775 vty_out(vty, " End-of-RIB received: ");
11776
11777 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11778 PEER_STATUS_EOR_RECEIVED)) {
11779 if (use_json)
11780 json_object_boolean_true_add(
11781 json_endofrib_status,
11782 "endOfRibRecv");
11783 else
11784 vty_out(vty, "Yes\n");
11785 } else {
11786 if (use_json)
11787 json_object_boolean_false_add(
11788 json_endofrib_status,
11789 "endOfRibRecv");
11790 else
11791 vty_out(vty, "No\n");
11792 }
11793
11794 if (use_json) {
11795 json_object_int_add(json_timer,
11796 "stalePathTimer",
11797 peer->bgp->stalepath_time);
11798
11799 if (peer->t_gr_stale != NULL) {
11800 json_object_int_add(
11801 json_timer,
11802 "stalePathTimerRemaining",
11803 thread_timer_remain_second(
11804 peer->t_gr_stale));
11805 }
11806
11807 /* Display Configured Selection
11808 * Deferral only when when
11809 * Gr mode is enabled.
11810 */
11811 if (CHECK_FLAG(peer->flags,
11812 PEER_FLAG_GRACEFUL_RESTART)) {
11813 json_object_int_add(
11814 json_timer,
11815 "selectionDeferralTimer",
11816 peer->bgp->stalepath_time);
11817 }
11818
11819 if (peer->bgp->gr_info[afi][safi]
11820 .t_select_deferral
11821 != NULL) {
11822
11823 json_object_int_add(
11824 json_timer,
11825 "selectionDeferralTimerRemaining",
11826 thread_timer_remain_second(
11827 peer->bgp
11828 ->gr_info[afi]
11829 [safi]
11830 .t_select_deferral));
11831 }
11832 } else {
11833 vty_out(vty, " Timers:\n");
11834 vty_out(vty,
11835 " Configured Stale Path Time(sec): %u\n",
11836 peer->bgp->stalepath_time);
11837
11838 if (peer->t_gr_stale != NULL)
11839 vty_out(vty,
11840 " Stale Path Remaining(sec): %ld\n",
11841 thread_timer_remain_second(
11842 peer->t_gr_stale));
11843 /* Display Configured Selection
11844 * Deferral only when when
11845 * Gr mode is enabled.
11846 */
11847 if (CHECK_FLAG(peer->flags,
11848 PEER_FLAG_GRACEFUL_RESTART))
11849 vty_out(vty,
11850 " Configured Selection Deferral Time(sec): %u\n",
11851 peer->bgp->select_defer_time);
11852
11853 if (peer->bgp->gr_info[afi][safi]
11854 .t_select_deferral
11855 != NULL)
11856 vty_out(vty,
11857 " Selection Deferral Time Remaining(sec): %ld\n",
11858 thread_timer_remain_second(
11859 peer->bgp
11860 ->gr_info[afi]
11861 [safi]
11862 .t_select_deferral));
11863 }
11864 if (use_json) {
11865 json_object_object_add(json_afi_safi,
11866 "endOfRibStatus",
11867 json_endofrib_status);
11868 json_object_object_add(json_afi_safi, "timers",
11869 json_timer);
11870 json_object_object_add(
11871 json, get_afi_safi_str(afi, safi, true),
11872 json_afi_safi);
11873 }
11874 }
11875 }
11876 }
11877
11878 static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
11879 struct peer *p,
11880 bool use_json,
11881 json_object *json)
11882 {
11883 if (use_json) {
11884 json_object *json_timer = NULL;
11885
11886 json_timer = json_object_new_object();
11887
11888 json_object_int_add(json_timer, "configuredRestartTimer",
11889 p->bgp->restart_time);
11890
11891 json_object_int_add(json_timer, "receivedRestartTimer",
11892 p->v_gr_restart);
11893
11894 if (p->t_gr_restart != NULL)
11895 json_object_int_add(
11896 json_timer, "restartTimerRemaining",
11897 thread_timer_remain_second(p->t_gr_restart));
11898
11899 json_object_object_add(json, "timers", json_timer);
11900 } else {
11901
11902 vty_out(vty, " Timers:\n");
11903 vty_out(vty, " Configured Restart Time(sec): %u\n",
11904 p->bgp->restart_time);
11905
11906 vty_out(vty, " Received Restart Time(sec): %u\n",
11907 p->v_gr_restart);
11908 if (p->t_gr_restart != NULL)
11909 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
11910 thread_timer_remain_second(p->t_gr_restart));
11911 if (p->t_gr_restart != NULL) {
11912 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
11913 thread_timer_remain_second(p->t_gr_restart));
11914 }
11915 }
11916 }
11917
11918 static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
11919 bool use_json, json_object *json)
11920 {
11921 char buf[SU_ADDRSTRLEN] = {0};
11922 char dn_flag[2] = {0};
11923 /* '*' + v6 address of neighbor */
11924 char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
11925
11926 if (!p->conf_if && peer_dynamic_neighbor(p))
11927 dn_flag[0] = '*';
11928
11929 if (p->conf_if) {
11930 if (use_json)
11931 json_object_string_add(
11932 json, "neighborAddr",
11933 BGP_PEER_SU_UNSPEC(p)
11934 ? "none"
11935 : sockunion2str(&p->su, buf,
11936 SU_ADDRSTRLEN));
11937 else
11938 vty_out(vty, "BGP neighbor on %s: %s\n", p->conf_if,
11939 BGP_PEER_SU_UNSPEC(p)
11940 ? "none"
11941 : sockunion2str(&p->su, buf,
11942 SU_ADDRSTRLEN));
11943 } else {
11944 snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
11945 p->host);
11946
11947 if (use_json)
11948 json_object_string_add(json, "neighborAddr",
11949 neighborAddr);
11950 else
11951 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
11952 }
11953
11954 /* more gr info in new format */
11955 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json);
11956 }
11957
11958 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
11959 safi_t safi, bool use_json,
11960 json_object *json_neigh)
11961 {
11962 struct bgp_filter *filter;
11963 struct peer_af *paf;
11964 char orf_pfx_name[BUFSIZ];
11965 int orf_pfx_count;
11966 json_object *json_af = NULL;
11967 json_object *json_prefA = NULL;
11968 json_object *json_prefB = NULL;
11969 json_object *json_addr = NULL;
11970 json_object *json_advmap = NULL;
11971
11972 if (use_json) {
11973 json_addr = json_object_new_object();
11974 json_af = json_object_new_object();
11975 filter = &p->filter[afi][safi];
11976
11977 if (peer_group_active(p))
11978 json_object_string_add(json_addr, "peerGroupMember",
11979 p->group->name);
11980
11981 paf = peer_af_find(p, afi, safi);
11982 if (paf && PAF_SUBGRP(paf)) {
11983 json_object_int_add(json_addr, "updateGroupId",
11984 PAF_UPDGRP(paf)->id);
11985 json_object_int_add(json_addr, "subGroupId",
11986 PAF_SUBGRP(paf)->id);
11987 json_object_int_add(json_addr, "packetQueueLength",
11988 bpacket_queue_virtual_length(paf));
11989 }
11990
11991 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11992 || CHECK_FLAG(p->af_cap[afi][safi],
11993 PEER_CAP_ORF_PREFIX_SM_RCV)
11994 || CHECK_FLAG(p->af_cap[afi][safi],
11995 PEER_CAP_ORF_PREFIX_RM_ADV)
11996 || CHECK_FLAG(p->af_cap[afi][safi],
11997 PEER_CAP_ORF_PREFIX_RM_RCV)) {
11998 json_object_int_add(json_af, "orfType",
11999 ORF_TYPE_PREFIX);
12000 json_prefA = json_object_new_object();
12001 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
12002 PEER_CAP_ORF_PREFIX_SM_ADV,
12003 PEER_CAP_ORF_PREFIX_RM_ADV,
12004 PEER_CAP_ORF_PREFIX_SM_RCV,
12005 PEER_CAP_ORF_PREFIX_RM_RCV,
12006 use_json, json_prefA);
12007 json_object_object_add(json_af, "orfPrefixList",
12008 json_prefA);
12009 }
12010
12011 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12012 || CHECK_FLAG(p->af_cap[afi][safi],
12013 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12014 || CHECK_FLAG(p->af_cap[afi][safi],
12015 PEER_CAP_ORF_PREFIX_RM_ADV)
12016 || CHECK_FLAG(p->af_cap[afi][safi],
12017 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12018 json_object_int_add(json_af, "orfOldType",
12019 ORF_TYPE_PREFIX_OLD);
12020 json_prefB = json_object_new_object();
12021 bgp_show_peer_afi_orf_cap(
12022 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12023 PEER_CAP_ORF_PREFIX_RM_ADV,
12024 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12025 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
12026 json_prefB);
12027 json_object_object_add(json_af, "orfOldPrefixList",
12028 json_prefB);
12029 }
12030
12031 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12032 || CHECK_FLAG(p->af_cap[afi][safi],
12033 PEER_CAP_ORF_PREFIX_SM_RCV)
12034 || CHECK_FLAG(p->af_cap[afi][safi],
12035 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12036 || CHECK_FLAG(p->af_cap[afi][safi],
12037 PEER_CAP_ORF_PREFIX_RM_ADV)
12038 || CHECK_FLAG(p->af_cap[afi][safi],
12039 PEER_CAP_ORF_PREFIX_RM_RCV)
12040 || CHECK_FLAG(p->af_cap[afi][safi],
12041 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12042 json_object_object_add(json_addr, "afDependentCap",
12043 json_af);
12044 else
12045 json_object_free(json_af);
12046
12047 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12048 p->host, afi, safi);
12049 orf_pfx_count = prefix_bgp_show_prefix_list(
12050 NULL, afi, orf_pfx_name, use_json);
12051
12052 if (CHECK_FLAG(p->af_sflags[afi][safi],
12053 PEER_STATUS_ORF_PREFIX_SEND)
12054 || orf_pfx_count) {
12055 if (CHECK_FLAG(p->af_sflags[afi][safi],
12056 PEER_STATUS_ORF_PREFIX_SEND))
12057 json_object_boolean_true_add(json_neigh,
12058 "orfSent");
12059 if (orf_pfx_count)
12060 json_object_int_add(json_addr, "orfRecvCounter",
12061 orf_pfx_count);
12062 }
12063 if (CHECK_FLAG(p->af_sflags[afi][safi],
12064 PEER_STATUS_ORF_WAIT_REFRESH))
12065 json_object_string_add(
12066 json_addr, "orfFirstUpdate",
12067 "deferredUntilORFOrRouteRefreshRecvd");
12068
12069 if (CHECK_FLAG(p->af_flags[afi][safi],
12070 PEER_FLAG_REFLECTOR_CLIENT))
12071 json_object_boolean_true_add(json_addr,
12072 "routeReflectorClient");
12073 if (CHECK_FLAG(p->af_flags[afi][safi],
12074 PEER_FLAG_RSERVER_CLIENT))
12075 json_object_boolean_true_add(json_addr,
12076 "routeServerClient");
12077 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12078 json_object_boolean_true_add(json_addr,
12079 "inboundSoftConfigPermit");
12080
12081 if (CHECK_FLAG(p->af_flags[afi][safi],
12082 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12083 json_object_boolean_true_add(
12084 json_addr,
12085 "privateAsNumsAllReplacedInUpdatesToNbr");
12086 else if (CHECK_FLAG(p->af_flags[afi][safi],
12087 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12088 json_object_boolean_true_add(
12089 json_addr,
12090 "privateAsNumsReplacedInUpdatesToNbr");
12091 else if (CHECK_FLAG(p->af_flags[afi][safi],
12092 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12093 json_object_boolean_true_add(
12094 json_addr,
12095 "privateAsNumsAllRemovedInUpdatesToNbr");
12096 else if (CHECK_FLAG(p->af_flags[afi][safi],
12097 PEER_FLAG_REMOVE_PRIVATE_AS))
12098 json_object_boolean_true_add(
12099 json_addr,
12100 "privateAsNumsRemovedInUpdatesToNbr");
12101
12102 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12103 json_object_boolean_true_add(
12104 json_addr,
12105 bgp_addpath_names(p->addpath_type[afi][safi])
12106 ->type_json_name);
12107
12108 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12109 json_object_string_add(json_addr,
12110 "overrideASNsInOutboundUpdates",
12111 "ifAspathEqualRemoteAs");
12112
12113 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12114 || CHECK_FLAG(p->af_flags[afi][safi],
12115 PEER_FLAG_FORCE_NEXTHOP_SELF))
12116 json_object_boolean_true_add(json_addr,
12117 "routerAlwaysNextHop");
12118 if (CHECK_FLAG(p->af_flags[afi][safi],
12119 PEER_FLAG_AS_PATH_UNCHANGED))
12120 json_object_boolean_true_add(
12121 json_addr, "unchangedAsPathPropogatedToNbr");
12122 if (CHECK_FLAG(p->af_flags[afi][safi],
12123 PEER_FLAG_NEXTHOP_UNCHANGED))
12124 json_object_boolean_true_add(
12125 json_addr, "unchangedNextHopPropogatedToNbr");
12126 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12127 json_object_boolean_true_add(
12128 json_addr, "unchangedMedPropogatedToNbr");
12129 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12130 || CHECK_FLAG(p->af_flags[afi][safi],
12131 PEER_FLAG_SEND_EXT_COMMUNITY)) {
12132 if (CHECK_FLAG(p->af_flags[afi][safi],
12133 PEER_FLAG_SEND_COMMUNITY)
12134 && CHECK_FLAG(p->af_flags[afi][safi],
12135 PEER_FLAG_SEND_EXT_COMMUNITY))
12136 json_object_string_add(json_addr,
12137 "commAttriSentToNbr",
12138 "extendedAndStandard");
12139 else if (CHECK_FLAG(p->af_flags[afi][safi],
12140 PEER_FLAG_SEND_EXT_COMMUNITY))
12141 json_object_string_add(json_addr,
12142 "commAttriSentToNbr",
12143 "extended");
12144 else
12145 json_object_string_add(json_addr,
12146 "commAttriSentToNbr",
12147 "standard");
12148 }
12149 if (CHECK_FLAG(p->af_flags[afi][safi],
12150 PEER_FLAG_DEFAULT_ORIGINATE)) {
12151 if (p->default_rmap[afi][safi].name)
12152 json_object_string_add(
12153 json_addr, "defaultRouteMap",
12154 p->default_rmap[afi][safi].name);
12155
12156 if (paf && PAF_SUBGRP(paf)
12157 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12158 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12159 json_object_boolean_true_add(json_addr,
12160 "defaultSent");
12161 else
12162 json_object_boolean_true_add(json_addr,
12163 "defaultNotSent");
12164 }
12165
12166 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
12167 if (is_evpn_enabled())
12168 json_object_boolean_true_add(
12169 json_addr, "advertiseAllVnis");
12170 }
12171
12172 if (filter->plist[FILTER_IN].name
12173 || filter->dlist[FILTER_IN].name
12174 || filter->aslist[FILTER_IN].name
12175 || filter->map[RMAP_IN].name)
12176 json_object_boolean_true_add(json_addr,
12177 "inboundPathPolicyConfig");
12178 if (filter->plist[FILTER_OUT].name
12179 || filter->dlist[FILTER_OUT].name
12180 || filter->aslist[FILTER_OUT].name
12181 || filter->map[RMAP_OUT].name || filter->usmap.name)
12182 json_object_boolean_true_add(
12183 json_addr, "outboundPathPolicyConfig");
12184
12185 /* prefix-list */
12186 if (filter->plist[FILTER_IN].name)
12187 json_object_string_add(json_addr,
12188 "incomingUpdatePrefixFilterList",
12189 filter->plist[FILTER_IN].name);
12190 if (filter->plist[FILTER_OUT].name)
12191 json_object_string_add(json_addr,
12192 "outgoingUpdatePrefixFilterList",
12193 filter->plist[FILTER_OUT].name);
12194
12195 /* distribute-list */
12196 if (filter->dlist[FILTER_IN].name)
12197 json_object_string_add(
12198 json_addr, "incomingUpdateNetworkFilterList",
12199 filter->dlist[FILTER_IN].name);
12200 if (filter->dlist[FILTER_OUT].name)
12201 json_object_string_add(
12202 json_addr, "outgoingUpdateNetworkFilterList",
12203 filter->dlist[FILTER_OUT].name);
12204
12205 /* filter-list. */
12206 if (filter->aslist[FILTER_IN].name)
12207 json_object_string_add(json_addr,
12208 "incomingUpdateAsPathFilterList",
12209 filter->aslist[FILTER_IN].name);
12210 if (filter->aslist[FILTER_OUT].name)
12211 json_object_string_add(json_addr,
12212 "outgoingUpdateAsPathFilterList",
12213 filter->aslist[FILTER_OUT].name);
12214
12215 /* route-map. */
12216 if (filter->map[RMAP_IN].name)
12217 json_object_string_add(
12218 json_addr, "routeMapForIncomingAdvertisements",
12219 filter->map[RMAP_IN].name);
12220 if (filter->map[RMAP_OUT].name)
12221 json_object_string_add(
12222 json_addr, "routeMapForOutgoingAdvertisements",
12223 filter->map[RMAP_OUT].name);
12224
12225 /* ebgp-requires-policy (inbound) */
12226 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12227 && !bgp_inbound_policy_exists(p, filter))
12228 json_object_string_add(
12229 json_addr, "inboundEbgpRequiresPolicy",
12230 "Inbound updates discarded due to missing policy");
12231
12232 /* ebgp-requires-policy (outbound) */
12233 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12234 && (!bgp_outbound_policy_exists(p, filter)))
12235 json_object_string_add(
12236 json_addr, "outboundEbgpRequiresPolicy",
12237 "Outbound updates discarded due to missing policy");
12238
12239 /* unsuppress-map */
12240 if (filter->usmap.name)
12241 json_object_string_add(json_addr,
12242 "selectiveUnsuppressRouteMap",
12243 filter->usmap.name);
12244
12245 /* advertise-map */
12246 if (filter->advmap.aname) {
12247 json_advmap = json_object_new_object();
12248 json_object_string_add(json_advmap, "condition",
12249 filter->advmap.condition
12250 ? "EXIST"
12251 : "NON_EXIST");
12252 json_object_string_add(json_advmap, "conditionMap",
12253 filter->advmap.cname);
12254 json_object_string_add(json_advmap, "advertiseMap",
12255 filter->advmap.aname);
12256 json_object_string_add(json_advmap, "advertiseStatus",
12257 filter->advmap.update_type
12258 == ADVERTISE
12259 ? "Advertise"
12260 : "Withdraw");
12261 json_object_object_add(json_addr, "advertiseMap",
12262 json_advmap);
12263 }
12264
12265 /* Receive prefix count */
12266 json_object_int_add(json_addr, "acceptedPrefixCounter",
12267 p->pcount[afi][safi]);
12268 if (paf && PAF_SUBGRP(paf))
12269 json_object_int_add(json_addr, "sentPrefixCounter",
12270 (PAF_SUBGRP(paf))->scount);
12271
12272 /* Maximum prefix */
12273 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
12274 json_object_int_add(json_addr, "prefixOutAllowedMax",
12275 p->pmax_out[afi][safi]);
12276
12277 /* Maximum prefix */
12278 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12279 json_object_int_add(json_addr, "prefixAllowedMax",
12280 p->pmax[afi][safi]);
12281 if (CHECK_FLAG(p->af_flags[afi][safi],
12282 PEER_FLAG_MAX_PREFIX_WARNING))
12283 json_object_boolean_true_add(
12284 json_addr, "prefixAllowedMaxWarning");
12285 json_object_int_add(json_addr,
12286 "prefixAllowedWarningThresh",
12287 p->pmax_threshold[afi][safi]);
12288 if (p->pmax_restart[afi][safi])
12289 json_object_int_add(
12290 json_addr,
12291 "prefixAllowedRestartIntervalMsecs",
12292 p->pmax_restart[afi][safi] * 60000);
12293 }
12294 json_object_object_add(json_neigh,
12295 get_afi_safi_str(afi, safi, true),
12296 json_addr);
12297
12298 } else {
12299 filter = &p->filter[afi][safi];
12300
12301 vty_out(vty, " For address family: %s\n",
12302 get_afi_safi_str(afi, safi, false));
12303
12304 if (peer_group_active(p))
12305 vty_out(vty, " %s peer-group member\n",
12306 p->group->name);
12307
12308 paf = peer_af_find(p, afi, safi);
12309 if (paf && PAF_SUBGRP(paf)) {
12310 vty_out(vty, " Update group %" PRIu64", subgroup %" PRIu64 "\n",
12311 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
12312 vty_out(vty, " Packet Queue length %d\n",
12313 bpacket_queue_virtual_length(paf));
12314 } else {
12315 vty_out(vty, " Not part of any update group\n");
12316 }
12317 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12318 || CHECK_FLAG(p->af_cap[afi][safi],
12319 PEER_CAP_ORF_PREFIX_SM_RCV)
12320 || CHECK_FLAG(p->af_cap[afi][safi],
12321 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12322 || CHECK_FLAG(p->af_cap[afi][safi],
12323 PEER_CAP_ORF_PREFIX_RM_ADV)
12324 || CHECK_FLAG(p->af_cap[afi][safi],
12325 PEER_CAP_ORF_PREFIX_RM_RCV)
12326 || CHECK_FLAG(p->af_cap[afi][safi],
12327 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12328 vty_out(vty, " AF-dependant capabilities:\n");
12329
12330 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12331 || CHECK_FLAG(p->af_cap[afi][safi],
12332 PEER_CAP_ORF_PREFIX_SM_RCV)
12333 || CHECK_FLAG(p->af_cap[afi][safi],
12334 PEER_CAP_ORF_PREFIX_RM_ADV)
12335 || CHECK_FLAG(p->af_cap[afi][safi],
12336 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12337 vty_out(vty,
12338 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12339 ORF_TYPE_PREFIX);
12340 bgp_show_peer_afi_orf_cap(
12341 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12342 PEER_CAP_ORF_PREFIX_RM_ADV,
12343 PEER_CAP_ORF_PREFIX_SM_RCV,
12344 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
12345 }
12346 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12347 || CHECK_FLAG(p->af_cap[afi][safi],
12348 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12349 || CHECK_FLAG(p->af_cap[afi][safi],
12350 PEER_CAP_ORF_PREFIX_RM_ADV)
12351 || CHECK_FLAG(p->af_cap[afi][safi],
12352 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12353 vty_out(vty,
12354 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12355 ORF_TYPE_PREFIX_OLD);
12356 bgp_show_peer_afi_orf_cap(
12357 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12358 PEER_CAP_ORF_PREFIX_RM_ADV,
12359 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12360 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
12361 }
12362
12363 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12364 p->host, afi, safi);
12365 orf_pfx_count = prefix_bgp_show_prefix_list(
12366 NULL, afi, orf_pfx_name, use_json);
12367
12368 if (CHECK_FLAG(p->af_sflags[afi][safi],
12369 PEER_STATUS_ORF_PREFIX_SEND)
12370 || orf_pfx_count) {
12371 vty_out(vty, " Outbound Route Filter (ORF):");
12372 if (CHECK_FLAG(p->af_sflags[afi][safi],
12373 PEER_STATUS_ORF_PREFIX_SEND))
12374 vty_out(vty, " sent;");
12375 if (orf_pfx_count)
12376 vty_out(vty, " received (%d entries)",
12377 orf_pfx_count);
12378 vty_out(vty, "\n");
12379 }
12380 if (CHECK_FLAG(p->af_sflags[afi][safi],
12381 PEER_STATUS_ORF_WAIT_REFRESH))
12382 vty_out(vty,
12383 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
12384
12385 if (CHECK_FLAG(p->af_flags[afi][safi],
12386 PEER_FLAG_REFLECTOR_CLIENT))
12387 vty_out(vty, " Route-Reflector Client\n");
12388 if (CHECK_FLAG(p->af_flags[afi][safi],
12389 PEER_FLAG_RSERVER_CLIENT))
12390 vty_out(vty, " Route-Server Client\n");
12391 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12392 vty_out(vty,
12393 " Inbound soft reconfiguration allowed\n");
12394
12395 if (CHECK_FLAG(p->af_flags[afi][safi],
12396 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12397 vty_out(vty,
12398 " Private AS numbers (all) replaced in updates to this neighbor\n");
12399 else if (CHECK_FLAG(p->af_flags[afi][safi],
12400 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12401 vty_out(vty,
12402 " Private AS numbers replaced in updates to this neighbor\n");
12403 else if (CHECK_FLAG(p->af_flags[afi][safi],
12404 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12405 vty_out(vty,
12406 " Private AS numbers (all) removed in updates to this neighbor\n");
12407 else if (CHECK_FLAG(p->af_flags[afi][safi],
12408 PEER_FLAG_REMOVE_PRIVATE_AS))
12409 vty_out(vty,
12410 " Private AS numbers removed in updates to this neighbor\n");
12411
12412 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12413 vty_out(vty, " %s\n",
12414 bgp_addpath_names(p->addpath_type[afi][safi])
12415 ->human_description);
12416
12417 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12418 vty_out(vty,
12419 " Override ASNs in outbound updates if aspath equals remote-as\n");
12420
12421 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12422 || CHECK_FLAG(p->af_flags[afi][safi],
12423 PEER_FLAG_FORCE_NEXTHOP_SELF))
12424 vty_out(vty, " NEXT_HOP is always this router\n");
12425 if (CHECK_FLAG(p->af_flags[afi][safi],
12426 PEER_FLAG_AS_PATH_UNCHANGED))
12427 vty_out(vty,
12428 " AS_PATH is propagated unchanged to this neighbor\n");
12429 if (CHECK_FLAG(p->af_flags[afi][safi],
12430 PEER_FLAG_NEXTHOP_UNCHANGED))
12431 vty_out(vty,
12432 " NEXT_HOP is propagated unchanged to this neighbor\n");
12433 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12434 vty_out(vty,
12435 " MED is propagated unchanged to this neighbor\n");
12436 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12437 || CHECK_FLAG(p->af_flags[afi][safi],
12438 PEER_FLAG_SEND_EXT_COMMUNITY)
12439 || CHECK_FLAG(p->af_flags[afi][safi],
12440 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
12441 vty_out(vty,
12442 " Community attribute sent to this neighbor");
12443 if (CHECK_FLAG(p->af_flags[afi][safi],
12444 PEER_FLAG_SEND_COMMUNITY)
12445 && CHECK_FLAG(p->af_flags[afi][safi],
12446 PEER_FLAG_SEND_EXT_COMMUNITY)
12447 && CHECK_FLAG(p->af_flags[afi][safi],
12448 PEER_FLAG_SEND_LARGE_COMMUNITY))
12449 vty_out(vty, "(all)\n");
12450 else if (CHECK_FLAG(p->af_flags[afi][safi],
12451 PEER_FLAG_SEND_LARGE_COMMUNITY))
12452 vty_out(vty, "(large)\n");
12453 else if (CHECK_FLAG(p->af_flags[afi][safi],
12454 PEER_FLAG_SEND_EXT_COMMUNITY))
12455 vty_out(vty, "(extended)\n");
12456 else
12457 vty_out(vty, "(standard)\n");
12458 }
12459 if (CHECK_FLAG(p->af_flags[afi][safi],
12460 PEER_FLAG_DEFAULT_ORIGINATE)) {
12461 vty_out(vty, " Default information originate,");
12462
12463 if (p->default_rmap[afi][safi].name)
12464 vty_out(vty, " default route-map %s%s,",
12465 p->default_rmap[afi][safi].map ? "*"
12466 : "",
12467 p->default_rmap[afi][safi].name);
12468 if (paf && PAF_SUBGRP(paf)
12469 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12470 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12471 vty_out(vty, " default sent\n");
12472 else
12473 vty_out(vty, " default not sent\n");
12474 }
12475
12476 /* advertise-vni-all */
12477 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
12478 if (is_evpn_enabled())
12479 vty_out(vty, " advertise-all-vni\n");
12480 }
12481
12482 if (filter->plist[FILTER_IN].name
12483 || filter->dlist[FILTER_IN].name
12484 || filter->aslist[FILTER_IN].name
12485 || filter->map[RMAP_IN].name)
12486 vty_out(vty, " Inbound path policy configured\n");
12487 if (filter->plist[FILTER_OUT].name
12488 || filter->dlist[FILTER_OUT].name
12489 || filter->aslist[FILTER_OUT].name
12490 || filter->map[RMAP_OUT].name || filter->usmap.name)
12491 vty_out(vty, " Outbound path policy configured\n");
12492
12493 /* prefix-list */
12494 if (filter->plist[FILTER_IN].name)
12495 vty_out(vty,
12496 " Incoming update prefix filter list is %s%s\n",
12497 filter->plist[FILTER_IN].plist ? "*" : "",
12498 filter->plist[FILTER_IN].name);
12499 if (filter->plist[FILTER_OUT].name)
12500 vty_out(vty,
12501 " Outgoing update prefix filter list is %s%s\n",
12502 filter->plist[FILTER_OUT].plist ? "*" : "",
12503 filter->plist[FILTER_OUT].name);
12504
12505 /* distribute-list */
12506 if (filter->dlist[FILTER_IN].name)
12507 vty_out(vty,
12508 " Incoming update network filter list is %s%s\n",
12509 filter->dlist[FILTER_IN].alist ? "*" : "",
12510 filter->dlist[FILTER_IN].name);
12511 if (filter->dlist[FILTER_OUT].name)
12512 vty_out(vty,
12513 " Outgoing update network filter list is %s%s\n",
12514 filter->dlist[FILTER_OUT].alist ? "*" : "",
12515 filter->dlist[FILTER_OUT].name);
12516
12517 /* filter-list. */
12518 if (filter->aslist[FILTER_IN].name)
12519 vty_out(vty,
12520 " Incoming update AS path filter list is %s%s\n",
12521 filter->aslist[FILTER_IN].aslist ? "*" : "",
12522 filter->aslist[FILTER_IN].name);
12523 if (filter->aslist[FILTER_OUT].name)
12524 vty_out(vty,
12525 " Outgoing update AS path filter list is %s%s\n",
12526 filter->aslist[FILTER_OUT].aslist ? "*" : "",
12527 filter->aslist[FILTER_OUT].name);
12528
12529 /* route-map. */
12530 if (filter->map[RMAP_IN].name)
12531 vty_out(vty,
12532 " Route map for incoming advertisements is %s%s\n",
12533 filter->map[RMAP_IN].map ? "*" : "",
12534 filter->map[RMAP_IN].name);
12535 if (filter->map[RMAP_OUT].name)
12536 vty_out(vty,
12537 " Route map for outgoing advertisements is %s%s\n",
12538 filter->map[RMAP_OUT].map ? "*" : "",
12539 filter->map[RMAP_OUT].name);
12540
12541 /* ebgp-requires-policy (inbound) */
12542 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12543 && !bgp_inbound_policy_exists(p, filter))
12544 vty_out(vty,
12545 " Inbound updates discarded due to missing policy\n");
12546
12547 /* ebgp-requires-policy (outbound) */
12548 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12549 && !bgp_outbound_policy_exists(p, filter))
12550 vty_out(vty,
12551 " Outbound updates discarded due to missing policy\n");
12552
12553 /* unsuppress-map */
12554 if (filter->usmap.name)
12555 vty_out(vty,
12556 " Route map for selective unsuppress is %s%s\n",
12557 filter->usmap.map ? "*" : "",
12558 filter->usmap.name);
12559
12560 /* advertise-map */
12561 if (filter->advmap.aname && filter->advmap.cname)
12562 vty_out(vty,
12563 " Condition %s, Condition-map %s%s, Advertise-map %s%s, status: %s\n",
12564 filter->advmap.condition ? "EXIST"
12565 : "NON_EXIST",
12566 filter->advmap.cmap ? "*" : "",
12567 filter->advmap.cname,
12568 filter->advmap.amap ? "*" : "",
12569 filter->advmap.aname,
12570 filter->advmap.update_type == ADVERTISE
12571 ? "Advertise"
12572 : "Withdraw");
12573
12574 /* Receive prefix count */
12575 vty_out(vty, " %u accepted prefixes\n",
12576 p->pcount[afi][safi]);
12577
12578 /* maximum-prefix-out */
12579 if (CHECK_FLAG(p->af_flags[afi][safi],
12580 PEER_FLAG_MAX_PREFIX_OUT))
12581 vty_out(vty,
12582 " Maximum allowed prefixes sent %u\n",
12583 p->pmax_out[afi][safi]);
12584
12585 /* Maximum prefix */
12586 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12587 vty_out(vty,
12588 " Maximum prefixes allowed %u%s\n",
12589 p->pmax[afi][safi],
12590 CHECK_FLAG(p->af_flags[afi][safi],
12591 PEER_FLAG_MAX_PREFIX_WARNING)
12592 ? " (warning-only)"
12593 : "");
12594 vty_out(vty, " Threshold for warning message %d%%",
12595 p->pmax_threshold[afi][safi]);
12596 if (p->pmax_restart[afi][safi])
12597 vty_out(vty, ", restart interval %d min",
12598 p->pmax_restart[afi][safi]);
12599 vty_out(vty, "\n");
12600 }
12601
12602 vty_out(vty, "\n");
12603 }
12604 }
12605
12606 static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
12607 json_object *json)
12608 {
12609 struct bgp *bgp;
12610 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
12611 char timebuf[BGP_UPTIME_LEN];
12612 char dn_flag[2];
12613 afi_t afi;
12614 safi_t safi;
12615 uint16_t i;
12616 uint8_t *msg;
12617 json_object *json_neigh = NULL;
12618 time_t epoch_tbuf;
12619
12620 bgp = p->bgp;
12621
12622 if (use_json)
12623 json_neigh = json_object_new_object();
12624
12625 memset(dn_flag, '\0', sizeof(dn_flag));
12626 if (!p->conf_if && peer_dynamic_neighbor(p))
12627 dn_flag[0] = '*';
12628
12629 if (!use_json) {
12630 if (p->conf_if) /* Configured interface name. */
12631 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
12632 BGP_PEER_SU_UNSPEC(p)
12633 ? "None"
12634 : sockunion2str(&p->su, buf,
12635 SU_ADDRSTRLEN));
12636 else /* Configured IP address. */
12637 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
12638 p->host);
12639 }
12640
12641 if (use_json) {
12642 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
12643 json_object_string_add(json_neigh, "bgpNeighborAddr",
12644 "none");
12645 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
12646 json_object_string_add(
12647 json_neigh, "bgpNeighborAddr",
12648 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
12649
12650 json_object_int_add(json_neigh, "remoteAs", p->as);
12651
12652 if (p->change_local_as)
12653 json_object_int_add(json_neigh, "localAs",
12654 p->change_local_as);
12655 else
12656 json_object_int_add(json_neigh, "localAs", p->local_as);
12657
12658 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
12659 json_object_boolean_true_add(json_neigh,
12660 "localAsNoPrepend");
12661
12662 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
12663 json_object_boolean_true_add(json_neigh,
12664 "localAsReplaceAs");
12665 } else {
12666 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
12667 || (p->as_type == AS_INTERNAL))
12668 vty_out(vty, "remote AS %u, ", p->as);
12669 else
12670 vty_out(vty, "remote AS Unspecified, ");
12671 vty_out(vty, "local AS %u%s%s, ",
12672 p->change_local_as ? p->change_local_as : p->local_as,
12673 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
12674 ? " no-prepend"
12675 : "",
12676 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
12677 ? " replace-as"
12678 : "");
12679 }
12680 /* peer type internal or confed-internal */
12681 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
12682 if (use_json) {
12683 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12684 json_object_boolean_true_add(
12685 json_neigh, "nbrConfedInternalLink");
12686 else
12687 json_object_boolean_true_add(json_neigh,
12688 "nbrInternalLink");
12689 } else {
12690 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12691 vty_out(vty, "confed-internal link\n");
12692 else
12693 vty_out(vty, "internal link\n");
12694 }
12695 /* peer type external or confed-external */
12696 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
12697 if (use_json) {
12698 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12699 json_object_boolean_true_add(
12700 json_neigh, "nbrConfedExternalLink");
12701 else
12702 json_object_boolean_true_add(json_neigh,
12703 "nbrExternalLink");
12704 } else {
12705 if (bgp_confederation_peers_check(bgp, p->as))
12706 vty_out(vty, "confed-external link\n");
12707 else
12708 vty_out(vty, "external link\n");
12709 }
12710 } else {
12711 if (use_json)
12712 json_object_boolean_true_add(json_neigh,
12713 "nbrUnspecifiedLink");
12714 else
12715 vty_out(vty, "unspecified link\n");
12716 }
12717
12718 /* Description. */
12719 if (p->desc) {
12720 if (use_json)
12721 json_object_string_add(json_neigh, "nbrDesc", p->desc);
12722 else
12723 vty_out(vty, " Description: %s\n", p->desc);
12724 }
12725
12726 if (p->hostname) {
12727 if (use_json) {
12728 if (p->hostname)
12729 json_object_string_add(json_neigh, "hostname",
12730 p->hostname);
12731
12732 if (p->domainname)
12733 json_object_string_add(json_neigh, "domainname",
12734 p->domainname);
12735 } else {
12736 if (p->domainname && (p->domainname[0] != '\0'))
12737 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
12738 p->domainname);
12739 else
12740 vty_out(vty, "Hostname: %s\n", p->hostname);
12741 }
12742 }
12743
12744 /* Peer-group */
12745 if (p->group) {
12746 if (use_json) {
12747 json_object_string_add(json_neigh, "peerGroup",
12748 p->group->name);
12749
12750 if (dn_flag[0]) {
12751 struct prefix prefix, *range = NULL;
12752
12753 if (sockunion2hostprefix(&(p->su), &prefix))
12754 range = peer_group_lookup_dynamic_neighbor_range(
12755 p->group, &prefix);
12756
12757 if (range) {
12758 prefix2str(range, buf1, sizeof(buf1));
12759 json_object_string_add(
12760 json_neigh,
12761 "peerSubnetRangeGroup", buf1);
12762 }
12763 }
12764 } else {
12765 vty_out(vty,
12766 " Member of peer-group %s for session parameters\n",
12767 p->group->name);
12768
12769 if (dn_flag[0]) {
12770 struct prefix prefix, *range = NULL;
12771
12772 if (sockunion2hostprefix(&(p->su), &prefix))
12773 range = peer_group_lookup_dynamic_neighbor_range(
12774 p->group, &prefix);
12775
12776 if (range) {
12777 vty_out(vty,
12778 " Belongs to the subnet range group: %pFX\n",
12779 range);
12780 }
12781 }
12782 }
12783 }
12784
12785 if (use_json) {
12786 /* Administrative shutdown. */
12787 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12788 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
12789 json_object_boolean_true_add(json_neigh,
12790 "adminShutDown");
12791
12792 /* BGP Version. */
12793 json_object_int_add(json_neigh, "bgpVersion", 4);
12794 json_object_string_add(
12795 json_neigh, "remoteRouterId",
12796 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
12797 json_object_string_add(
12798 json_neigh, "localRouterId",
12799 inet_ntop(AF_INET, &bgp->router_id, buf1,
12800 sizeof(buf1)));
12801
12802 /* Confederation */
12803 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12804 && bgp_confederation_peers_check(bgp, p->as))
12805 json_object_boolean_true_add(json_neigh,
12806 "nbrCommonAdmin");
12807
12808 /* Status. */
12809 json_object_string_add(
12810 json_neigh, "bgpState",
12811 lookup_msg(bgp_status_msg, p->status, NULL));
12812
12813 if (p->status == Established) {
12814 time_t uptime;
12815
12816 uptime = bgp_clock();
12817 uptime -= p->uptime;
12818 epoch_tbuf = time(NULL) - uptime;
12819
12820 json_object_int_add(json_neigh, "bgpTimerUpMsec",
12821 uptime * 1000);
12822 json_object_string_add(json_neigh, "bgpTimerUpString",
12823 peer_uptime(p->uptime, timebuf,
12824 BGP_UPTIME_LEN, 0,
12825 NULL));
12826 json_object_int_add(json_neigh,
12827 "bgpTimerUpEstablishedEpoch",
12828 epoch_tbuf);
12829 }
12830
12831 else if (p->status == Active) {
12832 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12833 json_object_string_add(json_neigh, "bgpStateIs",
12834 "passive");
12835 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12836 json_object_string_add(json_neigh, "bgpStateIs",
12837 "passiveNSF");
12838 }
12839
12840 /* read timer */
12841 time_t uptime;
12842 struct tm tm;
12843
12844 uptime = bgp_clock();
12845 uptime -= p->readtime;
12846 gmtime_r(&uptime, &tm);
12847
12848 json_object_int_add(json_neigh, "bgpTimerLastRead",
12849 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12850 + (tm.tm_hour * 3600000));
12851
12852 uptime = bgp_clock();
12853 uptime -= p->last_write;
12854 gmtime_r(&uptime, &tm);
12855
12856 json_object_int_add(json_neigh, "bgpTimerLastWrite",
12857 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12858 + (tm.tm_hour * 3600000));
12859
12860 uptime = bgp_clock();
12861 uptime -= p->update_time;
12862 gmtime_r(&uptime, &tm);
12863
12864 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
12865 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12866 + (tm.tm_hour * 3600000));
12867
12868 /* Configured timer values. */
12869 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
12870 p->v_holdtime * 1000);
12871 json_object_int_add(json_neigh,
12872 "bgpTimerKeepAliveIntervalMsecs",
12873 p->v_keepalive * 1000);
12874 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN)) {
12875 json_object_int_add(json_neigh,
12876 "bgpTimerDelayOpenTimeMsecs",
12877 p->v_delayopen * 1000);
12878 }
12879
12880 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
12881 json_object_int_add(json_neigh,
12882 "bgpTimerConfiguredHoldTimeMsecs",
12883 p->holdtime * 1000);
12884 json_object_int_add(
12885 json_neigh,
12886 "bgpTimerConfiguredKeepAliveIntervalMsecs",
12887 p->keepalive * 1000);
12888 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
12889 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
12890 json_object_int_add(json_neigh,
12891 "bgpTimerConfiguredHoldTimeMsecs",
12892 bgp->default_holdtime);
12893 json_object_int_add(
12894 json_neigh,
12895 "bgpTimerConfiguredKeepAliveIntervalMsecs",
12896 bgp->default_keepalive);
12897 }
12898 } else {
12899 /* Administrative shutdown. */
12900 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12901 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
12902 vty_out(vty, " Administratively shut down\n");
12903
12904 /* BGP Version. */
12905 vty_out(vty, " BGP version 4");
12906 vty_out(vty, ", remote router ID %s",
12907 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
12908 vty_out(vty, ", local router ID %s\n",
12909 inet_ntop(AF_INET, &bgp->router_id, buf1,
12910 sizeof(buf1)));
12911
12912 /* Confederation */
12913 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12914 && bgp_confederation_peers_check(bgp, p->as))
12915 vty_out(vty,
12916 " Neighbor under common administration\n");
12917
12918 /* Status. */
12919 vty_out(vty, " BGP state = %s",
12920 lookup_msg(bgp_status_msg, p->status, NULL));
12921
12922 if (p->status == Established)
12923 vty_out(vty, ", up for %8s",
12924 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
12925 0, NULL));
12926
12927 else if (p->status == Active) {
12928 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12929 vty_out(vty, " (passive)");
12930 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12931 vty_out(vty, " (NSF passive)");
12932 }
12933 vty_out(vty, "\n");
12934
12935 /* read timer */
12936 vty_out(vty, " Last read %s",
12937 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
12938 NULL));
12939 vty_out(vty, ", Last write %s\n",
12940 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
12941 NULL));
12942
12943 /* Configured timer values. */
12944 vty_out(vty,
12945 " Hold time is %d, keepalive interval is %d seconds\n",
12946 p->v_holdtime, p->v_keepalive);
12947 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
12948 vty_out(vty, " Configured hold time is %d",
12949 p->holdtime);
12950 vty_out(vty, ", keepalive interval is %d seconds\n",
12951 p->keepalive);
12952 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
12953 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
12954 vty_out(vty, " Configured hold time is %d",
12955 bgp->default_holdtime);
12956 vty_out(vty, ", keepalive interval is %d seconds\n",
12957 bgp->default_keepalive);
12958 }
12959 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN))
12960 vty_out(vty,
12961 " Configured DelayOpenTime is %d seconds\n",
12962 p->delayopen);
12963 }
12964 /* Capability. */
12965 if (p->status == Established) {
12966 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
12967 || p->afc_recv[AFI_IP][SAFI_UNICAST]
12968 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
12969 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
12970 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
12971 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
12972 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
12973 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
12974 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
12975 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
12976 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
12977 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
12978 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
12979 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
12980 || p->afc_adv[AFI_IP][SAFI_ENCAP]
12981 || p->afc_recv[AFI_IP][SAFI_ENCAP]
12982 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
12983 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
12984 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
12985 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
12986 if (use_json) {
12987 json_object *json_cap = NULL;
12988
12989 json_cap = json_object_new_object();
12990
12991 /* AS4 */
12992 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
12993 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
12994 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
12995 && CHECK_FLAG(p->cap,
12996 PEER_CAP_AS4_RCV))
12997 json_object_string_add(
12998 json_cap, "4byteAs",
12999 "advertisedAndReceived");
13000 else if (CHECK_FLAG(p->cap,
13001 PEER_CAP_AS4_ADV))
13002 json_object_string_add(
13003 json_cap, "4byteAs",
13004 "advertised");
13005 else if (CHECK_FLAG(p->cap,
13006 PEER_CAP_AS4_RCV))
13007 json_object_string_add(
13008 json_cap, "4byteAs",
13009 "received");
13010 }
13011
13012 /* AddPath */
13013 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
13014 || CHECK_FLAG(p->cap,
13015 PEER_CAP_ADDPATH_ADV)) {
13016 json_object *json_add = NULL;
13017 const char *print_store;
13018
13019 json_add = json_object_new_object();
13020
13021 FOREACH_AFI_SAFI (afi, safi) {
13022 json_object *json_sub = NULL;
13023 json_sub =
13024 json_object_new_object();
13025 print_store = get_afi_safi_str(
13026 afi, safi, true);
13027
13028 if (CHECK_FLAG(
13029 p->af_cap[afi]
13030 [safi],
13031 PEER_CAP_ADDPATH_AF_TX_ADV)
13032 || CHECK_FLAG(
13033 p->af_cap[afi]
13034 [safi],
13035 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13036 if (CHECK_FLAG(
13037 p->af_cap
13038 [afi]
13039 [safi],
13040 PEER_CAP_ADDPATH_AF_TX_ADV)
13041 && CHECK_FLAG(
13042 p->af_cap
13043 [afi]
13044 [safi],
13045 PEER_CAP_ADDPATH_AF_TX_RCV))
13046 json_object_boolean_true_add(
13047 json_sub,
13048 "txAdvertisedAndReceived");
13049 else if (
13050 CHECK_FLAG(
13051 p->af_cap
13052 [afi]
13053 [safi],
13054 PEER_CAP_ADDPATH_AF_TX_ADV))
13055 json_object_boolean_true_add(
13056 json_sub,
13057 "txAdvertised");
13058 else if (
13059 CHECK_FLAG(
13060 p->af_cap
13061 [afi]
13062 [safi],
13063 PEER_CAP_ADDPATH_AF_TX_RCV))
13064 json_object_boolean_true_add(
13065 json_sub,
13066 "txReceived");
13067 }
13068
13069 if (CHECK_FLAG(
13070 p->af_cap[afi]
13071 [safi],
13072 PEER_CAP_ADDPATH_AF_RX_ADV)
13073 || CHECK_FLAG(
13074 p->af_cap[afi]
13075 [safi],
13076 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13077 if (CHECK_FLAG(
13078 p->af_cap
13079 [afi]
13080 [safi],
13081 PEER_CAP_ADDPATH_AF_RX_ADV)
13082 && CHECK_FLAG(
13083 p->af_cap
13084 [afi]
13085 [safi],
13086 PEER_CAP_ADDPATH_AF_RX_RCV))
13087 json_object_boolean_true_add(
13088 json_sub,
13089 "rxAdvertisedAndReceived");
13090 else if (
13091 CHECK_FLAG(
13092 p->af_cap
13093 [afi]
13094 [safi],
13095 PEER_CAP_ADDPATH_AF_RX_ADV))
13096 json_object_boolean_true_add(
13097 json_sub,
13098 "rxAdvertised");
13099 else if (
13100 CHECK_FLAG(
13101 p->af_cap
13102 [afi]
13103 [safi],
13104 PEER_CAP_ADDPATH_AF_RX_RCV))
13105 json_object_boolean_true_add(
13106 json_sub,
13107 "rxReceived");
13108 }
13109
13110 if (CHECK_FLAG(
13111 p->af_cap[afi]
13112 [safi],
13113 PEER_CAP_ADDPATH_AF_TX_ADV)
13114 || CHECK_FLAG(
13115 p->af_cap[afi]
13116 [safi],
13117 PEER_CAP_ADDPATH_AF_TX_RCV)
13118 || CHECK_FLAG(
13119 p->af_cap[afi]
13120 [safi],
13121 PEER_CAP_ADDPATH_AF_RX_ADV)
13122 || CHECK_FLAG(
13123 p->af_cap[afi]
13124 [safi],
13125 PEER_CAP_ADDPATH_AF_RX_RCV))
13126 json_object_object_add(
13127 json_add,
13128 print_store,
13129 json_sub);
13130 else
13131 json_object_free(
13132 json_sub);
13133 }
13134
13135 json_object_object_add(
13136 json_cap, "addPath", json_add);
13137 }
13138
13139 /* Dynamic */
13140 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
13141 || CHECK_FLAG(p->cap,
13142 PEER_CAP_DYNAMIC_ADV)) {
13143 if (CHECK_FLAG(p->cap,
13144 PEER_CAP_DYNAMIC_ADV)
13145 && CHECK_FLAG(p->cap,
13146 PEER_CAP_DYNAMIC_RCV))
13147 json_object_string_add(
13148 json_cap, "dynamic",
13149 "advertisedAndReceived");
13150 else if (CHECK_FLAG(
13151 p->cap,
13152 PEER_CAP_DYNAMIC_ADV))
13153 json_object_string_add(
13154 json_cap, "dynamic",
13155 "advertised");
13156 else if (CHECK_FLAG(
13157 p->cap,
13158 PEER_CAP_DYNAMIC_RCV))
13159 json_object_string_add(
13160 json_cap, "dynamic",
13161 "received");
13162 }
13163
13164 /* Extended nexthop */
13165 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
13166 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13167 json_object *json_nxt = NULL;
13168 const char *print_store;
13169
13170
13171 if (CHECK_FLAG(p->cap,
13172 PEER_CAP_ENHE_ADV)
13173 && CHECK_FLAG(p->cap,
13174 PEER_CAP_ENHE_RCV))
13175 json_object_string_add(
13176 json_cap,
13177 "extendedNexthop",
13178 "advertisedAndReceived");
13179 else if (CHECK_FLAG(p->cap,
13180 PEER_CAP_ENHE_ADV))
13181 json_object_string_add(
13182 json_cap,
13183 "extendedNexthop",
13184 "advertised");
13185 else if (CHECK_FLAG(p->cap,
13186 PEER_CAP_ENHE_RCV))
13187 json_object_string_add(
13188 json_cap,
13189 "extendedNexthop",
13190 "received");
13191
13192 if (CHECK_FLAG(p->cap,
13193 PEER_CAP_ENHE_RCV)) {
13194 json_nxt =
13195 json_object_new_object();
13196
13197 for (safi = SAFI_UNICAST;
13198 safi < SAFI_MAX; safi++) {
13199 if (CHECK_FLAG(
13200 p->af_cap
13201 [AFI_IP]
13202 [safi],
13203 PEER_CAP_ENHE_AF_RCV)) {
13204 print_store = get_afi_safi_str(
13205 AFI_IP,
13206 safi, true);
13207 json_object_string_add(
13208 json_nxt,
13209 print_store,
13210 "recieved"); /* misspelled for compatibility */
13211 }
13212 }
13213 json_object_object_add(
13214 json_cap,
13215 "extendedNexthopFamililesByPeer",
13216 json_nxt);
13217 }
13218 }
13219
13220 /* Route Refresh */
13221 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
13222 || CHECK_FLAG(p->cap,
13223 PEER_CAP_REFRESH_NEW_RCV)
13224 || CHECK_FLAG(p->cap,
13225 PEER_CAP_REFRESH_OLD_RCV)) {
13226 if (CHECK_FLAG(p->cap,
13227 PEER_CAP_REFRESH_ADV)
13228 && (CHECK_FLAG(
13229 p->cap,
13230 PEER_CAP_REFRESH_NEW_RCV)
13231 || CHECK_FLAG(
13232 p->cap,
13233 PEER_CAP_REFRESH_OLD_RCV))) {
13234 if (CHECK_FLAG(
13235 p->cap,
13236 PEER_CAP_REFRESH_OLD_RCV)
13237 && CHECK_FLAG(
13238 p->cap,
13239 PEER_CAP_REFRESH_NEW_RCV))
13240 json_object_string_add(
13241 json_cap,
13242 "routeRefresh",
13243 "advertisedAndReceivedOldNew");
13244 else {
13245 if (CHECK_FLAG(
13246 p->cap,
13247 PEER_CAP_REFRESH_OLD_RCV))
13248 json_object_string_add(
13249 json_cap,
13250 "routeRefresh",
13251 "advertisedAndReceivedOld");
13252 else
13253 json_object_string_add(
13254 json_cap,
13255 "routeRefresh",
13256 "advertisedAndReceivedNew");
13257 }
13258 } else if (
13259 CHECK_FLAG(
13260 p->cap,
13261 PEER_CAP_REFRESH_ADV))
13262 json_object_string_add(
13263 json_cap,
13264 "routeRefresh",
13265 "advertised");
13266 else if (
13267 CHECK_FLAG(
13268 p->cap,
13269 PEER_CAP_REFRESH_NEW_RCV)
13270 || CHECK_FLAG(
13271 p->cap,
13272 PEER_CAP_REFRESH_OLD_RCV))
13273 json_object_string_add(
13274 json_cap,
13275 "routeRefresh",
13276 "received");
13277 }
13278
13279 /* Enhanced Route Refresh */
13280 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV)
13281 || CHECK_FLAG(p->cap,
13282 PEER_CAP_ENHANCED_RR_RCV)) {
13283 if (CHECK_FLAG(p->cap,
13284 PEER_CAP_ENHANCED_RR_ADV)
13285 && CHECK_FLAG(
13286 p->cap,
13287 PEER_CAP_ENHANCED_RR_RCV))
13288 json_object_string_add(
13289 json_cap,
13290 "enhancedRouteRefresh",
13291 "advertisedAndReceived");
13292 else if (
13293 CHECK_FLAG(
13294 p->cap,
13295 PEER_CAP_ENHANCED_RR_ADV))
13296 json_object_string_add(
13297 json_cap,
13298 "enhancedRouteRefresh",
13299 "advertised");
13300 else if (
13301 CHECK_FLAG(
13302 p->cap,
13303 PEER_CAP_ENHANCED_RR_RCV))
13304 json_object_string_add(
13305 json_cap,
13306 "enhancedRouteRefresh",
13307 "received");
13308 }
13309
13310 /* Multiprotocol Extensions */
13311 json_object *json_multi = NULL;
13312 json_multi = json_object_new_object();
13313
13314 FOREACH_AFI_SAFI (afi, safi) {
13315 if (p->afc_adv[afi][safi]
13316 || p->afc_recv[afi][safi]) {
13317 json_object *json_exten = NULL;
13318 json_exten =
13319 json_object_new_object();
13320
13321 if (p->afc_adv[afi][safi]
13322 && p->afc_recv[afi][safi])
13323 json_object_boolean_true_add(
13324 json_exten,
13325 "advertisedAndReceived");
13326 else if (p->afc_adv[afi][safi])
13327 json_object_boolean_true_add(
13328 json_exten,
13329 "advertised");
13330 else if (p->afc_recv[afi][safi])
13331 json_object_boolean_true_add(
13332 json_exten,
13333 "received");
13334
13335 json_object_object_add(
13336 json_multi,
13337 get_afi_safi_str(afi,
13338 safi,
13339 true),
13340 json_exten);
13341 }
13342 }
13343 json_object_object_add(
13344 json_cap, "multiprotocolExtensions",
13345 json_multi);
13346
13347 /* Hostname capabilities */
13348 json_object *json_hname = NULL;
13349
13350 json_hname = json_object_new_object();
13351
13352 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13353 json_object_string_add(
13354 json_hname, "advHostName",
13355 bgp->peer_self->hostname
13356 ? bgp->peer_self
13357 ->hostname
13358 : "n/a");
13359 json_object_string_add(
13360 json_hname, "advDomainName",
13361 bgp->peer_self->domainname
13362 ? bgp->peer_self
13363 ->domainname
13364 : "n/a");
13365 }
13366
13367
13368 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13369 json_object_string_add(
13370 json_hname, "rcvHostName",
13371 p->hostname ? p->hostname
13372 : "n/a");
13373 json_object_string_add(
13374 json_hname, "rcvDomainName",
13375 p->domainname ? p->domainname
13376 : "n/a");
13377 }
13378
13379 json_object_object_add(json_cap, "hostName",
13380 json_hname);
13381
13382 /* Gracefull Restart */
13383 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
13384 || CHECK_FLAG(p->cap,
13385 PEER_CAP_RESTART_ADV)) {
13386 if (CHECK_FLAG(p->cap,
13387 PEER_CAP_RESTART_ADV)
13388 && CHECK_FLAG(p->cap,
13389 PEER_CAP_RESTART_RCV))
13390 json_object_string_add(
13391 json_cap,
13392 "gracefulRestart",
13393 "advertisedAndReceived");
13394 else if (CHECK_FLAG(
13395 p->cap,
13396 PEER_CAP_RESTART_ADV))
13397 json_object_string_add(
13398 json_cap,
13399 "gracefulRestartCapability",
13400 "advertised");
13401 else if (CHECK_FLAG(
13402 p->cap,
13403 PEER_CAP_RESTART_RCV))
13404 json_object_string_add(
13405 json_cap,
13406 "gracefulRestartCapability",
13407 "received");
13408
13409 if (CHECK_FLAG(p->cap,
13410 PEER_CAP_RESTART_RCV)) {
13411 int restart_af_count = 0;
13412 json_object *json_restart =
13413 NULL;
13414 json_restart =
13415 json_object_new_object();
13416
13417 json_object_int_add(
13418 json_cap,
13419 "gracefulRestartRemoteTimerMsecs",
13420 p->v_gr_restart * 1000);
13421
13422 FOREACH_AFI_SAFI (afi, safi) {
13423 if (CHECK_FLAG(
13424 p->af_cap
13425 [afi]
13426 [safi],
13427 PEER_CAP_RESTART_AF_RCV)) {
13428 json_object *
13429 json_sub =
13430 NULL;
13431 json_sub =
13432 json_object_new_object();
13433
13434 if (CHECK_FLAG(
13435 p->af_cap
13436 [afi]
13437 [safi],
13438 PEER_CAP_RESTART_AF_PRESERVE_RCV))
13439 json_object_boolean_true_add(
13440 json_sub,
13441 "preserved");
13442 restart_af_count++;
13443 json_object_object_add(
13444 json_restart,
13445 get_afi_safi_str(
13446 afi,
13447 safi,
13448 true),
13449 json_sub);
13450 }
13451 }
13452 if (!restart_af_count) {
13453 json_object_string_add(
13454 json_cap,
13455 "addressFamiliesByPeer",
13456 "none");
13457 json_object_free(
13458 json_restart);
13459 } else
13460 json_object_object_add(
13461 json_cap,
13462 "addressFamiliesByPeer",
13463 json_restart);
13464 }
13465 }
13466 json_object_object_add(json_neigh,
13467 "neighborCapabilities",
13468 json_cap);
13469 } else {
13470 vty_out(vty, " Neighbor capabilities:\n");
13471
13472 /* AS4 */
13473 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
13474 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13475 vty_out(vty, " 4 Byte AS:");
13476 if (CHECK_FLAG(p->cap,
13477 PEER_CAP_AS4_ADV))
13478 vty_out(vty, " advertised");
13479 if (CHECK_FLAG(p->cap,
13480 PEER_CAP_AS4_RCV))
13481 vty_out(vty, " %sreceived",
13482 CHECK_FLAG(
13483 p->cap,
13484 PEER_CAP_AS4_ADV)
13485 ? "and "
13486 : "");
13487 vty_out(vty, "\n");
13488 }
13489
13490 /* AddPath */
13491 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
13492 || CHECK_FLAG(p->cap,
13493 PEER_CAP_ADDPATH_ADV)) {
13494 vty_out(vty, " AddPath:\n");
13495
13496 FOREACH_AFI_SAFI (afi, safi) {
13497 if (CHECK_FLAG(
13498 p->af_cap[afi]
13499 [safi],
13500 PEER_CAP_ADDPATH_AF_TX_ADV)
13501 || CHECK_FLAG(
13502 p->af_cap[afi]
13503 [safi],
13504 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13505 vty_out(vty,
13506 " %s: TX ",
13507 get_afi_safi_str(
13508 afi,
13509 safi,
13510 false));
13511
13512 if (CHECK_FLAG(
13513 p->af_cap
13514 [afi]
13515 [safi],
13516 PEER_CAP_ADDPATH_AF_TX_ADV))
13517 vty_out(vty,
13518 "advertised %s",
13519 get_afi_safi_str(
13520 afi,
13521 safi,
13522 false));
13523
13524 if (CHECK_FLAG(
13525 p->af_cap
13526 [afi]
13527 [safi],
13528 PEER_CAP_ADDPATH_AF_TX_RCV))
13529 vty_out(vty,
13530 "%sreceived",
13531 CHECK_FLAG(
13532 p->af_cap
13533 [afi]
13534 [safi],
13535 PEER_CAP_ADDPATH_AF_TX_ADV)
13536 ? " and "
13537 : "");
13538
13539 vty_out(vty, "\n");
13540 }
13541
13542 if (CHECK_FLAG(
13543 p->af_cap[afi]
13544 [safi],
13545 PEER_CAP_ADDPATH_AF_RX_ADV)
13546 || CHECK_FLAG(
13547 p->af_cap[afi]
13548 [safi],
13549 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13550 vty_out(vty,
13551 " %s: RX ",
13552 get_afi_safi_str(
13553 afi,
13554 safi,
13555 false));
13556
13557 if (CHECK_FLAG(
13558 p->af_cap
13559 [afi]
13560 [safi],
13561 PEER_CAP_ADDPATH_AF_RX_ADV))
13562 vty_out(vty,
13563 "advertised %s",
13564 get_afi_safi_str(
13565 afi,
13566 safi,
13567 false));
13568
13569 if (CHECK_FLAG(
13570 p->af_cap
13571 [afi]
13572 [safi],
13573 PEER_CAP_ADDPATH_AF_RX_RCV))
13574 vty_out(vty,
13575 "%sreceived",
13576 CHECK_FLAG(
13577 p->af_cap
13578 [afi]
13579 [safi],
13580 PEER_CAP_ADDPATH_AF_RX_ADV)
13581 ? " and "
13582 : "");
13583
13584 vty_out(vty, "\n");
13585 }
13586 }
13587 }
13588
13589 /* Dynamic */
13590 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
13591 || CHECK_FLAG(p->cap,
13592 PEER_CAP_DYNAMIC_ADV)) {
13593 vty_out(vty, " Dynamic:");
13594 if (CHECK_FLAG(p->cap,
13595 PEER_CAP_DYNAMIC_ADV))
13596 vty_out(vty, " advertised");
13597 if (CHECK_FLAG(p->cap,
13598 PEER_CAP_DYNAMIC_RCV))
13599 vty_out(vty, " %sreceived",
13600 CHECK_FLAG(
13601 p->cap,
13602 PEER_CAP_DYNAMIC_ADV)
13603 ? "and "
13604 : "");
13605 vty_out(vty, "\n");
13606 }
13607
13608 /* Extended nexthop */
13609 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
13610 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13611 vty_out(vty, " Extended nexthop:");
13612 if (CHECK_FLAG(p->cap,
13613 PEER_CAP_ENHE_ADV))
13614 vty_out(vty, " advertised");
13615 if (CHECK_FLAG(p->cap,
13616 PEER_CAP_ENHE_RCV))
13617 vty_out(vty, " %sreceived",
13618 CHECK_FLAG(
13619 p->cap,
13620 PEER_CAP_ENHE_ADV)
13621 ? "and "
13622 : "");
13623 vty_out(vty, "\n");
13624
13625 if (CHECK_FLAG(p->cap,
13626 PEER_CAP_ENHE_RCV)) {
13627 vty_out(vty,
13628 " Address families by peer:\n ");
13629 for (safi = SAFI_UNICAST;
13630 safi < SAFI_MAX; safi++)
13631 if (CHECK_FLAG(
13632 p->af_cap
13633 [AFI_IP]
13634 [safi],
13635 PEER_CAP_ENHE_AF_RCV))
13636 vty_out(vty,
13637 " %s\n",
13638 get_afi_safi_str(
13639 AFI_IP,
13640 safi,
13641 false));
13642 }
13643 }
13644
13645 /* Route Refresh */
13646 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
13647 || CHECK_FLAG(p->cap,
13648 PEER_CAP_REFRESH_NEW_RCV)
13649 || CHECK_FLAG(p->cap,
13650 PEER_CAP_REFRESH_OLD_RCV)) {
13651 vty_out(vty, " Route refresh:");
13652 if (CHECK_FLAG(p->cap,
13653 PEER_CAP_REFRESH_ADV))
13654 vty_out(vty, " advertised");
13655 if (CHECK_FLAG(p->cap,
13656 PEER_CAP_REFRESH_NEW_RCV)
13657 || CHECK_FLAG(
13658 p->cap,
13659 PEER_CAP_REFRESH_OLD_RCV))
13660 vty_out(vty, " %sreceived(%s)",
13661 CHECK_FLAG(
13662 p->cap,
13663 PEER_CAP_REFRESH_ADV)
13664 ? "and "
13665 : "",
13666 (CHECK_FLAG(
13667 p->cap,
13668 PEER_CAP_REFRESH_OLD_RCV)
13669 && CHECK_FLAG(
13670 p->cap,
13671 PEER_CAP_REFRESH_NEW_RCV))
13672 ? "old & new"
13673 : CHECK_FLAG(
13674 p->cap,
13675 PEER_CAP_REFRESH_OLD_RCV)
13676 ? "old"
13677 : "new");
13678
13679 vty_out(vty, "\n");
13680 }
13681
13682 /* Enhanced Route Refresh */
13683 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV)
13684 || CHECK_FLAG(p->cap,
13685 PEER_CAP_ENHANCED_RR_RCV)) {
13686 vty_out(vty,
13687 " Enhanced Route Refresh:");
13688 if (CHECK_FLAG(
13689 p->cap,
13690 PEER_CAP_ENHANCED_RR_ADV))
13691 vty_out(vty, " advertised");
13692 if (CHECK_FLAG(
13693 p->cap,
13694 PEER_CAP_ENHANCED_RR_RCV))
13695 vty_out(vty, " %sreceived",
13696 CHECK_FLAG(
13697 p->cap,
13698 PEER_CAP_REFRESH_ADV)
13699 ? "and "
13700 : "");
13701 vty_out(vty, "\n");
13702 }
13703
13704 /* Multiprotocol Extensions */
13705 FOREACH_AFI_SAFI (afi, safi)
13706 if (p->afc_adv[afi][safi]
13707 || p->afc_recv[afi][safi]) {
13708 vty_out(vty,
13709 " Address Family %s:",
13710 get_afi_safi_str(
13711 afi,
13712 safi,
13713 false));
13714 if (p->afc_adv[afi][safi])
13715 vty_out(vty,
13716 " advertised");
13717 if (p->afc_recv[afi][safi])
13718 vty_out(vty,
13719 " %sreceived",
13720 p->afc_adv[afi]
13721 [safi]
13722 ? "and "
13723 : "");
13724 vty_out(vty, "\n");
13725 }
13726
13727 /* Hostname capability */
13728 vty_out(vty, " Hostname Capability:");
13729
13730 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13731 vty_out(vty,
13732 " advertised (name: %s,domain name: %s)",
13733 bgp->peer_self->hostname
13734 ? bgp->peer_self
13735 ->hostname
13736 : "n/a",
13737 bgp->peer_self->domainname
13738 ? bgp->peer_self
13739 ->domainname
13740 : "n/a");
13741 } else {
13742 vty_out(vty, " not advertised");
13743 }
13744
13745 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13746 vty_out(vty,
13747 " received (name: %s,domain name: %s)",
13748 p->hostname ? p->hostname
13749 : "n/a",
13750 p->domainname ? p->domainname
13751 : "n/a");
13752 } else {
13753 vty_out(vty, " not received");
13754 }
13755
13756 vty_out(vty, "\n");
13757
13758 /* Graceful Restart */
13759 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
13760 || CHECK_FLAG(p->cap,
13761 PEER_CAP_RESTART_ADV)) {
13762 vty_out(vty,
13763 " Graceful Restart Capability:");
13764 if (CHECK_FLAG(p->cap,
13765 PEER_CAP_RESTART_ADV))
13766 vty_out(vty, " advertised");
13767 if (CHECK_FLAG(p->cap,
13768 PEER_CAP_RESTART_RCV))
13769 vty_out(vty, " %sreceived",
13770 CHECK_FLAG(
13771 p->cap,
13772 PEER_CAP_RESTART_ADV)
13773 ? "and "
13774 : "");
13775 vty_out(vty, "\n");
13776
13777 if (CHECK_FLAG(p->cap,
13778 PEER_CAP_RESTART_RCV)) {
13779 int restart_af_count = 0;
13780
13781 vty_out(vty,
13782 " Remote Restart timer is %d seconds\n",
13783 p->v_gr_restart);
13784 vty_out(vty,
13785 " Address families by peer:\n ");
13786
13787 FOREACH_AFI_SAFI (afi, safi)
13788 if (CHECK_FLAG(
13789 p->af_cap
13790 [afi]
13791 [safi],
13792 PEER_CAP_RESTART_AF_RCV)) {
13793 vty_out(vty,
13794 "%s%s(%s)",
13795 restart_af_count
13796 ? ", "
13797 : "",
13798 get_afi_safi_str(
13799 afi,
13800 safi,
13801 false),
13802 CHECK_FLAG(
13803 p->af_cap
13804 [afi]
13805 [safi],
13806 PEER_CAP_RESTART_AF_PRESERVE_RCV)
13807 ? "preserved"
13808 : "not preserved");
13809 restart_af_count++;
13810 }
13811 if (!restart_af_count)
13812 vty_out(vty, "none");
13813 vty_out(vty, "\n");
13814 }
13815 } /* Gracefull Restart */
13816 }
13817 }
13818 }
13819
13820 /* graceful restart information */
13821 json_object *json_grace = NULL;
13822 json_object *json_grace_send = NULL;
13823 json_object *json_grace_recv = NULL;
13824 int eor_send_af_count = 0;
13825 int eor_receive_af_count = 0;
13826
13827 if (use_json) {
13828 json_grace = json_object_new_object();
13829 json_grace_send = json_object_new_object();
13830 json_grace_recv = json_object_new_object();
13831
13832 if ((p->status == Established)
13833 && CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13834 FOREACH_AFI_SAFI (afi, safi) {
13835 if (CHECK_FLAG(p->af_sflags[afi][safi],
13836 PEER_STATUS_EOR_SEND)) {
13837 json_object_boolean_true_add(
13838 json_grace_send,
13839 get_afi_safi_str(afi,
13840 safi,
13841 true));
13842 eor_send_af_count++;
13843 }
13844 }
13845 FOREACH_AFI_SAFI (afi, safi) {
13846 if (CHECK_FLAG(
13847 p->af_sflags[afi][safi],
13848 PEER_STATUS_EOR_RECEIVED)) {
13849 json_object_boolean_true_add(
13850 json_grace_recv,
13851 get_afi_safi_str(afi,
13852 safi,
13853 true));
13854 eor_receive_af_count++;
13855 }
13856 }
13857 }
13858 json_object_object_add(json_grace, "endOfRibSend",
13859 json_grace_send);
13860 json_object_object_add(json_grace, "endOfRibRecv",
13861 json_grace_recv);
13862
13863
13864 if (p->t_gr_restart)
13865 json_object_int_add(json_grace,
13866 "gracefulRestartTimerMsecs",
13867 thread_timer_remain_second(
13868 p->t_gr_restart)
13869 * 1000);
13870
13871 if (p->t_gr_stale)
13872 json_object_int_add(
13873 json_grace,
13874 "gracefulStalepathTimerMsecs",
13875 thread_timer_remain_second(
13876 p->t_gr_stale)
13877 * 1000);
13878 /* more gr info in new format */
13879 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json,
13880 json_grace);
13881 json_object_object_add(
13882 json_neigh, "gracefulRestartInfo", json_grace);
13883 } else {
13884 vty_out(vty, " Graceful restart information:\n");
13885 if ((p->status == Established)
13886 && CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13887
13888 vty_out(vty, " End-of-RIB send: ");
13889 FOREACH_AFI_SAFI (afi, safi) {
13890 if (CHECK_FLAG(p->af_sflags[afi][safi],
13891 PEER_STATUS_EOR_SEND)) {
13892 vty_out(vty, "%s%s",
13893 eor_send_af_count ? ", "
13894 : "",
13895 get_afi_safi_str(
13896 afi, safi,
13897 false));
13898 eor_send_af_count++;
13899 }
13900 }
13901 vty_out(vty, "\n");
13902 vty_out(vty, " End-of-RIB received: ");
13903 FOREACH_AFI_SAFI (afi, safi) {
13904 if (CHECK_FLAG(
13905 p->af_sflags[afi][safi],
13906 PEER_STATUS_EOR_RECEIVED)) {
13907 vty_out(vty, "%s%s",
13908 eor_receive_af_count
13909 ? ", "
13910 : "",
13911 get_afi_safi_str(afi,
13912 safi,
13913 false));
13914 eor_receive_af_count++;
13915 }
13916 }
13917 vty_out(vty, "\n");
13918 }
13919
13920 if (p->t_gr_restart)
13921 vty_out(vty,
13922 " The remaining time of restart timer is %ld\n",
13923 thread_timer_remain_second(
13924 p->t_gr_restart));
13925
13926 if (p->t_gr_stale)
13927 vty_out(vty,
13928 " The remaining time of stalepath timer is %ld\n",
13929 thread_timer_remain_second(
13930 p->t_gr_stale));
13931
13932 /* more gr info in new format */
13933 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, NULL);
13934 }
13935
13936 if (use_json) {
13937 json_object *json_stat = NULL;
13938 json_stat = json_object_new_object();
13939 /* Packet counts. */
13940
13941 atomic_size_t outq_count, inq_count;
13942 outq_count = atomic_load_explicit(&p->obuf->count,
13943 memory_order_relaxed);
13944 inq_count = atomic_load_explicit(&p->ibuf->count,
13945 memory_order_relaxed);
13946
13947 json_object_int_add(json_stat, "depthInq",
13948 (unsigned long)inq_count);
13949 json_object_int_add(json_stat, "depthOutq",
13950 (unsigned long)outq_count);
13951 json_object_int_add(json_stat, "opensSent",
13952 atomic_load_explicit(&p->open_out,
13953 memory_order_relaxed));
13954 json_object_int_add(json_stat, "opensRecv",
13955 atomic_load_explicit(&p->open_in,
13956 memory_order_relaxed));
13957 json_object_int_add(json_stat, "notificationsSent",
13958 atomic_load_explicit(&p->notify_out,
13959 memory_order_relaxed));
13960 json_object_int_add(json_stat, "notificationsRecv",
13961 atomic_load_explicit(&p->notify_in,
13962 memory_order_relaxed));
13963 json_object_int_add(json_stat, "updatesSent",
13964 atomic_load_explicit(&p->update_out,
13965 memory_order_relaxed));
13966 json_object_int_add(json_stat, "updatesRecv",
13967 atomic_load_explicit(&p->update_in,
13968 memory_order_relaxed));
13969 json_object_int_add(json_stat, "keepalivesSent",
13970 atomic_load_explicit(&p->keepalive_out,
13971 memory_order_relaxed));
13972 json_object_int_add(json_stat, "keepalivesRecv",
13973 atomic_load_explicit(&p->keepalive_in,
13974 memory_order_relaxed));
13975 json_object_int_add(json_stat, "routeRefreshSent",
13976 atomic_load_explicit(&p->refresh_out,
13977 memory_order_relaxed));
13978 json_object_int_add(json_stat, "routeRefreshRecv",
13979 atomic_load_explicit(&p->refresh_in,
13980 memory_order_relaxed));
13981 json_object_int_add(json_stat, "capabilitySent",
13982 atomic_load_explicit(&p->dynamic_cap_out,
13983 memory_order_relaxed));
13984 json_object_int_add(json_stat, "capabilityRecv",
13985 atomic_load_explicit(&p->dynamic_cap_in,
13986 memory_order_relaxed));
13987 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
13988 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
13989 json_object_object_add(json_neigh, "messageStats", json_stat);
13990 } else {
13991 atomic_size_t outq_count, inq_count;
13992 outq_count = atomic_load_explicit(&p->obuf->count,
13993 memory_order_relaxed);
13994 inq_count = atomic_load_explicit(&p->ibuf->count,
13995 memory_order_relaxed);
13996
13997 /* Packet counts. */
13998 vty_out(vty, " Message statistics:\n");
13999 vty_out(vty, " Inq depth is %zu\n", inq_count);
14000 vty_out(vty, " Outq depth is %zu\n", outq_count);
14001 vty_out(vty, " Sent Rcvd\n");
14002 vty_out(vty, " Opens: %10d %10d\n",
14003 atomic_load_explicit(&p->open_out,
14004 memory_order_relaxed),
14005 atomic_load_explicit(&p->open_in,
14006 memory_order_relaxed));
14007 vty_out(vty, " Notifications: %10d %10d\n",
14008 atomic_load_explicit(&p->notify_out,
14009 memory_order_relaxed),
14010 atomic_load_explicit(&p->notify_in,
14011 memory_order_relaxed));
14012 vty_out(vty, " Updates: %10d %10d\n",
14013 atomic_load_explicit(&p->update_out,
14014 memory_order_relaxed),
14015 atomic_load_explicit(&p->update_in,
14016 memory_order_relaxed));
14017 vty_out(vty, " Keepalives: %10d %10d\n",
14018 atomic_load_explicit(&p->keepalive_out,
14019 memory_order_relaxed),
14020 atomic_load_explicit(&p->keepalive_in,
14021 memory_order_relaxed));
14022 vty_out(vty, " Route Refresh: %10d %10d\n",
14023 atomic_load_explicit(&p->refresh_out,
14024 memory_order_relaxed),
14025 atomic_load_explicit(&p->refresh_in,
14026 memory_order_relaxed));
14027 vty_out(vty, " Capability: %10d %10d\n",
14028 atomic_load_explicit(&p->dynamic_cap_out,
14029 memory_order_relaxed),
14030 atomic_load_explicit(&p->dynamic_cap_in,
14031 memory_order_relaxed));
14032 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
14033 PEER_TOTAL_RX(p));
14034 }
14035
14036 if (use_json) {
14037 /* advertisement-interval */
14038 json_object_int_add(json_neigh,
14039 "minBtwnAdvertisementRunsTimerMsecs",
14040 p->v_routeadv * 1000);
14041
14042 /* Update-source. */
14043 if (p->update_if || p->update_source) {
14044 if (p->update_if)
14045 json_object_string_add(json_neigh,
14046 "updateSource",
14047 p->update_if);
14048 else if (p->update_source)
14049 json_object_string_add(
14050 json_neigh, "updateSource",
14051 sockunion2str(p->update_source, buf1,
14052 SU_ADDRSTRLEN));
14053 }
14054 } else {
14055 /* advertisement-interval */
14056 vty_out(vty,
14057 " Minimum time between advertisement runs is %d seconds\n",
14058 p->v_routeadv);
14059
14060 /* Update-source. */
14061 if (p->update_if || p->update_source) {
14062 vty_out(vty, " Update source is ");
14063 if (p->update_if)
14064 vty_out(vty, "%s", p->update_if);
14065 else if (p->update_source)
14066 vty_out(vty, "%s",
14067 sockunion2str(p->update_source, buf1,
14068 SU_ADDRSTRLEN));
14069 vty_out(vty, "\n");
14070 }
14071
14072 vty_out(vty, "\n");
14073 }
14074
14075 /* Address Family Information */
14076 json_object *json_hold = NULL;
14077
14078 if (use_json)
14079 json_hold = json_object_new_object();
14080
14081 FOREACH_AFI_SAFI (afi, safi)
14082 if (p->afc[afi][safi])
14083 bgp_show_peer_afi(vty, p, afi, safi, use_json,
14084 json_hold);
14085
14086 if (use_json) {
14087 json_object_object_add(json_neigh, "addressFamilyInfo",
14088 json_hold);
14089 json_object_int_add(json_neigh, "connectionsEstablished",
14090 p->established);
14091 json_object_int_add(json_neigh, "connectionsDropped",
14092 p->dropped);
14093 } else
14094 vty_out(vty, " Connections established %d; dropped %d\n",
14095 p->established, p->dropped);
14096
14097 if (!p->last_reset) {
14098 if (use_json)
14099 json_object_string_add(json_neigh, "lastReset",
14100 "never");
14101 else
14102 vty_out(vty, " Last reset never\n");
14103 } else {
14104 if (use_json) {
14105 time_t uptime;
14106 struct tm tm;
14107
14108 uptime = bgp_clock();
14109 uptime -= p->resettime;
14110 gmtime_r(&uptime, &tm);
14111
14112 json_object_int_add(json_neigh, "lastResetTimerMsecs",
14113 (tm.tm_sec * 1000)
14114 + (tm.tm_min * 60000)
14115 + (tm.tm_hour * 3600000));
14116 bgp_show_peer_reset(NULL, p, json_neigh, true);
14117 } else {
14118 vty_out(vty, " Last reset %s, ",
14119 peer_uptime(p->resettime, timebuf,
14120 BGP_UPTIME_LEN, 0, NULL));
14121
14122 bgp_show_peer_reset(vty, p, NULL, false);
14123 if (p->last_reset_cause_size) {
14124 msg = p->last_reset_cause;
14125 vty_out(vty,
14126 " Message received that caused BGP to send a NOTIFICATION:\n ");
14127 for (i = 1; i <= p->last_reset_cause_size;
14128 i++) {
14129 vty_out(vty, "%02X", *msg++);
14130
14131 if (i != p->last_reset_cause_size) {
14132 if (i % 16 == 0) {
14133 vty_out(vty, "\n ");
14134 } else if (i % 4 == 0) {
14135 vty_out(vty, " ");
14136 }
14137 }
14138 }
14139 vty_out(vty, "\n");
14140 }
14141 }
14142 }
14143
14144 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
14145 if (use_json)
14146 json_object_boolean_true_add(json_neigh,
14147 "prefixesConfigExceedMax");
14148 else
14149 vty_out(vty,
14150 " Peer had exceeded the max. no. of prefixes configured.\n");
14151
14152 if (p->t_pmax_restart) {
14153 if (use_json) {
14154 json_object_boolean_true_add(
14155 json_neigh, "reducePrefixNumFrom");
14156 json_object_int_add(json_neigh,
14157 "restartInTimerMsec",
14158 thread_timer_remain_second(
14159 p->t_pmax_restart)
14160 * 1000);
14161 } else
14162 vty_out(vty,
14163 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
14164 p->host, thread_timer_remain_second(
14165 p->t_pmax_restart));
14166 } else {
14167 if (use_json)
14168 json_object_boolean_true_add(
14169 json_neigh,
14170 "reducePrefixNumAndClearIpBgp");
14171 else
14172 vty_out(vty,
14173 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
14174 p->host);
14175 }
14176 }
14177
14178 /* EBGP Multihop and GTSM */
14179 if (p->sort != BGP_PEER_IBGP) {
14180 if (use_json) {
14181 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14182 json_object_int_add(json_neigh,
14183 "externalBgpNbrMaxHopsAway",
14184 p->gtsm_hops);
14185 else if (p->ttl > BGP_DEFAULT_TTL)
14186 json_object_int_add(json_neigh,
14187 "externalBgpNbrMaxHopsAway",
14188 p->ttl);
14189 } else {
14190 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14191 vty_out(vty,
14192 " External BGP neighbor may be up to %d hops away.\n",
14193 p->gtsm_hops);
14194 else if (p->ttl > BGP_DEFAULT_TTL)
14195 vty_out(vty,
14196 " External BGP neighbor may be up to %d hops away.\n",
14197 p->ttl);
14198 }
14199 } else {
14200 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED) {
14201 if (use_json)
14202 json_object_int_add(json_neigh,
14203 "internalBgpNbrMaxHopsAway",
14204 p->gtsm_hops);
14205 else
14206 vty_out(vty,
14207 " Internal BGP neighbor may be up to %d hops away.\n",
14208 p->gtsm_hops);
14209 }
14210 }
14211
14212 /* Local address. */
14213 if (p->su_local) {
14214 if (use_json) {
14215 json_object_string_add(json_neigh, "hostLocal",
14216 sockunion2str(p->su_local, buf1,
14217 SU_ADDRSTRLEN));
14218 json_object_int_add(json_neigh, "portLocal",
14219 ntohs(p->su_local->sin.sin_port));
14220 } else
14221 vty_out(vty, "Local host: %s, Local port: %d\n",
14222 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
14223 ntohs(p->su_local->sin.sin_port));
14224 }
14225
14226 /* Remote address. */
14227 if (p->su_remote) {
14228 if (use_json) {
14229 json_object_string_add(json_neigh, "hostForeign",
14230 sockunion2str(p->su_remote, buf1,
14231 SU_ADDRSTRLEN));
14232 json_object_int_add(json_neigh, "portForeign",
14233 ntohs(p->su_remote->sin.sin_port));
14234 } else
14235 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
14236 sockunion2str(p->su_remote, buf1,
14237 SU_ADDRSTRLEN),
14238 ntohs(p->su_remote->sin.sin_port));
14239 }
14240
14241 /* Nexthop display. */
14242 if (p->su_local) {
14243 if (use_json) {
14244 json_object_string_add(json_neigh, "nexthop",
14245 inet_ntop(AF_INET,
14246 &p->nexthop.v4, buf1,
14247 sizeof(buf1)));
14248 json_object_string_add(json_neigh, "nexthopGlobal",
14249 inet_ntop(AF_INET6,
14250 &p->nexthop.v6_global,
14251 buf1, sizeof(buf1)));
14252 json_object_string_add(json_neigh, "nexthopLocal",
14253 inet_ntop(AF_INET6,
14254 &p->nexthop.v6_local,
14255 buf1, sizeof(buf1)));
14256 if (p->shared_network)
14257 json_object_string_add(json_neigh,
14258 "bgpConnection",
14259 "sharedNetwork");
14260 else
14261 json_object_string_add(json_neigh,
14262 "bgpConnection",
14263 "nonSharedNetwork");
14264 } else {
14265 vty_out(vty, "Nexthop: %s\n",
14266 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
14267 sizeof(buf1)));
14268 vty_out(vty, "Nexthop global: %s\n",
14269 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
14270 sizeof(buf1)));
14271 vty_out(vty, "Nexthop local: %s\n",
14272 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
14273 sizeof(buf1)));
14274 vty_out(vty, "BGP connection: %s\n",
14275 p->shared_network ? "shared network"
14276 : "non shared network");
14277 }
14278 }
14279
14280 /* Timer information. */
14281 if (use_json) {
14282 json_object_int_add(json_neigh, "connectRetryTimer",
14283 p->v_connect);
14284 if (p->status == Established && p->rtt)
14285 json_object_int_add(json_neigh, "estimatedRttInMsecs",
14286 p->rtt);
14287 if (p->t_start)
14288 json_object_int_add(
14289 json_neigh, "nextStartTimerDueInMsecs",
14290 thread_timer_remain_second(p->t_start) * 1000);
14291 if (p->t_connect)
14292 json_object_int_add(
14293 json_neigh, "nextConnectTimerDueInMsecs",
14294 thread_timer_remain_second(p->t_connect)
14295 * 1000);
14296 if (p->t_routeadv) {
14297 json_object_int_add(json_neigh, "mraiInterval",
14298 p->v_routeadv);
14299 json_object_int_add(
14300 json_neigh, "mraiTimerExpireInMsecs",
14301 thread_timer_remain_second(p->t_routeadv)
14302 * 1000);
14303 }
14304 if (p->password)
14305 json_object_int_add(json_neigh, "authenticationEnabled",
14306 1);
14307
14308 if (p->t_read)
14309 json_object_string_add(json_neigh, "readThread", "on");
14310 else
14311 json_object_string_add(json_neigh, "readThread", "off");
14312
14313 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
14314 json_object_string_add(json_neigh, "writeThread", "on");
14315 else
14316 json_object_string_add(json_neigh, "writeThread",
14317 "off");
14318 } else {
14319 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
14320 p->v_connect);
14321 if (p->status == Established && p->rtt)
14322 vty_out(vty, "Estimated round trip time: %d ms\n",
14323 p->rtt);
14324 if (p->t_start)
14325 vty_out(vty, "Next start timer due in %ld seconds\n",
14326 thread_timer_remain_second(p->t_start));
14327 if (p->t_connect)
14328 vty_out(vty, "Next connect timer due in %ld seconds\n",
14329 thread_timer_remain_second(p->t_connect));
14330 if (p->t_routeadv)
14331 vty_out(vty,
14332 "MRAI (interval %u) timer expires in %ld seconds\n",
14333 p->v_routeadv,
14334 thread_timer_remain_second(p->t_routeadv));
14335 if (p->password)
14336 vty_out(vty, "Peer Authentication Enabled\n");
14337
14338 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
14339 p->t_read ? "on" : "off",
14340 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
14341 ? "on"
14342 : "off", p->fd);
14343 }
14344
14345 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
14346 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
14347 bgp_capability_vty_out(vty, p, use_json, json_neigh);
14348
14349 if (!use_json)
14350 vty_out(vty, "\n");
14351
14352 /* BFD information. */
14353 bgp_bfd_show_info(vty, p, use_json, json_neigh);
14354
14355 if (use_json) {
14356 if (p->conf_if) /* Configured interface name. */
14357 json_object_object_add(json, p->conf_if, json_neigh);
14358 else /* Configured IP address. */
14359 json_object_object_add(json, p->host, json_neigh);
14360 }
14361 }
14362
14363 static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
14364 enum show_type type,
14365 union sockunion *su,
14366 const char *conf_if, afi_t afi,
14367 bool use_json)
14368 {
14369 struct listnode *node, *nnode;
14370 struct peer *peer;
14371 int find = 0;
14372 safi_t safi = SAFI_UNICAST;
14373 json_object *json = NULL;
14374 json_object *json_neighbor = NULL;
14375
14376 if (use_json) {
14377 json = json_object_new_object();
14378 json_neighbor = json_object_new_object();
14379 }
14380
14381 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14382
14383 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14384 continue;
14385
14386 if ((peer->afc[afi][safi]) == 0)
14387 continue;
14388
14389 if (type == show_all) {
14390 bgp_show_peer_gr_status(vty, peer, use_json,
14391 json_neighbor);
14392
14393 if (use_json) {
14394 json_object_object_add(json, peer->host,
14395 json_neighbor);
14396 json_neighbor = NULL;
14397 }
14398
14399 } else if (type == show_peer) {
14400 if (conf_if) {
14401 if ((peer->conf_if
14402 && !strcmp(peer->conf_if, conf_if))
14403 || (peer->hostname
14404 && !strcmp(peer->hostname, conf_if))) {
14405 find = 1;
14406 bgp_show_peer_gr_status(vty, peer,
14407 use_json,
14408 json_neighbor);
14409 }
14410 } else {
14411 if (sockunion_same(&peer->su, su)) {
14412 find = 1;
14413 bgp_show_peer_gr_status(vty, peer,
14414 use_json,
14415 json_neighbor);
14416 }
14417 }
14418 if (use_json && find)
14419 json_object_object_add(json, peer->host,
14420 json_neighbor);
14421 }
14422
14423 if (find) {
14424 json_neighbor = NULL;
14425 break;
14426 }
14427 }
14428
14429 if (type == show_peer && !find) {
14430 if (use_json)
14431 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14432 else
14433 vty_out(vty, "%% No such neighbor\n");
14434 }
14435 if (use_json) {
14436 vty_out(vty, "%s\n",
14437 json_object_to_json_string_ext(
14438 json, JSON_C_TO_STRING_PRETTY));
14439
14440 if (json_neighbor)
14441 json_object_free(json_neighbor);
14442 json_object_free(json);
14443 } else {
14444 vty_out(vty, "\n");
14445 }
14446
14447 return CMD_SUCCESS;
14448 }
14449
14450 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
14451 enum show_type type, union sockunion *su,
14452 const char *conf_if, bool use_json,
14453 json_object *json)
14454 {
14455 struct listnode *node, *nnode;
14456 struct peer *peer;
14457 int find = 0;
14458 bool nbr_output = false;
14459 afi_t afi = AFI_MAX;
14460 safi_t safi = SAFI_MAX;
14461
14462 if (type == show_ipv4_peer || type == show_ipv4_all) {
14463 afi = AFI_IP;
14464 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
14465 afi = AFI_IP6;
14466 }
14467
14468 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14469 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14470 continue;
14471
14472 switch (type) {
14473 case show_all:
14474 bgp_show_peer(vty, peer, use_json, json);
14475 nbr_output = true;
14476 break;
14477 case show_peer:
14478 if (conf_if) {
14479 if ((peer->conf_if
14480 && !strcmp(peer->conf_if, conf_if))
14481 || (peer->hostname
14482 && !strcmp(peer->hostname, conf_if))) {
14483 find = 1;
14484 bgp_show_peer(vty, peer, use_json,
14485 json);
14486 }
14487 } else {
14488 if (sockunion_same(&peer->su, su)) {
14489 find = 1;
14490 bgp_show_peer(vty, peer, use_json,
14491 json);
14492 }
14493 }
14494 break;
14495 case show_ipv4_peer:
14496 case show_ipv6_peer:
14497 FOREACH_SAFI (safi) {
14498 if (peer->afc[afi][safi]) {
14499 if (conf_if) {
14500 if ((peer->conf_if
14501 && !strcmp(peer->conf_if, conf_if))
14502 || (peer->hostname
14503 && !strcmp(peer->hostname, conf_if))) {
14504 find = 1;
14505 bgp_show_peer(vty, peer, use_json,
14506 json);
14507 break;
14508 }
14509 } else {
14510 if (sockunion_same(&peer->su, su)) {
14511 find = 1;
14512 bgp_show_peer(vty, peer, use_json,
14513 json);
14514 break;
14515 }
14516 }
14517 }
14518 }
14519 break;
14520 case show_ipv4_all:
14521 case show_ipv6_all:
14522 FOREACH_SAFI (safi) {
14523 if (peer->afc[afi][safi]) {
14524 bgp_show_peer(vty, peer, use_json, json);
14525 nbr_output = true;
14526 break;
14527 }
14528 }
14529 break;
14530 }
14531 }
14532
14533 if ((type == show_peer || type == show_ipv4_peer ||
14534 type == show_ipv6_peer) && !find) {
14535 if (use_json)
14536 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14537 else
14538 vty_out(vty, "%% No such neighbor in this view/vrf\n");
14539 }
14540
14541 if (type != show_peer && type != show_ipv4_peer &&
14542 type != show_ipv6_peer && !nbr_output && !use_json)
14543 vty_out(vty, "%% No BGP neighbors found\n");
14544
14545 if (use_json) {
14546 vty_out(vty, "%s\n", json_object_to_json_string_ext(
14547 json, JSON_C_TO_STRING_PRETTY));
14548 } else {
14549 vty_out(vty, "\n");
14550 }
14551
14552 return CMD_SUCCESS;
14553 }
14554
14555 static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
14556 enum show_type type,
14557 const char *ip_str,
14558 afi_t afi, bool use_json)
14559 {
14560
14561 int ret;
14562 struct bgp *bgp;
14563 union sockunion su;
14564
14565 bgp = bgp_get_default();
14566
14567 if (!bgp)
14568 return;
14569
14570 if (!use_json)
14571 bgp_show_global_graceful_restart_mode_vty(vty, bgp, use_json,
14572 NULL);
14573
14574 if (ip_str) {
14575 ret = str2sockunion(ip_str, &su);
14576 if (ret < 0)
14577 bgp_show_neighbor_graceful_restart(
14578 vty, bgp, type, NULL, ip_str, afi, use_json);
14579 else
14580 bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
14581 NULL, afi, use_json);
14582 } else
14583 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
14584 afi, use_json);
14585 }
14586
14587 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
14588 enum show_type type,
14589 const char *ip_str,
14590 bool use_json)
14591 {
14592 struct listnode *node, *nnode;
14593 struct bgp *bgp;
14594 union sockunion su;
14595 json_object *json = NULL;
14596 int ret, is_first = 1;
14597 bool nbr_output = false;
14598
14599 if (use_json)
14600 vty_out(vty, "{\n");
14601
14602 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
14603 nbr_output = true;
14604 if (use_json) {
14605 if (!(json = json_object_new_object())) {
14606 flog_err(
14607 EC_BGP_JSON_MEM_ERROR,
14608 "Unable to allocate memory for JSON object");
14609 vty_out(vty,
14610 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
14611 return;
14612 }
14613
14614 json_object_int_add(json, "vrfId",
14615 (bgp->vrf_id == VRF_UNKNOWN)
14616 ? -1
14617 : (int64_t)bgp->vrf_id);
14618 json_object_string_add(
14619 json, "vrfName",
14620 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14621 ? VRF_DEFAULT_NAME
14622 : bgp->name);
14623
14624 if (!is_first)
14625 vty_out(vty, ",\n");
14626 else
14627 is_first = 0;
14628
14629 vty_out(vty, "\"%s\":",
14630 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14631 ? VRF_DEFAULT_NAME
14632 : bgp->name);
14633 } else {
14634 vty_out(vty, "\nInstance %s:\n",
14635 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14636 ? VRF_DEFAULT_NAME
14637 : bgp->name);
14638 }
14639
14640 if (type == show_peer || type == show_ipv4_peer ||
14641 type == show_ipv6_peer) {
14642 ret = str2sockunion(ip_str, &su);
14643 if (ret < 0)
14644 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14645 use_json, json);
14646 else
14647 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14648 use_json, json);
14649 } else {
14650 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
14651 use_json, json);
14652 }
14653 json_object_free(json);
14654 json = NULL;
14655 }
14656
14657 if (use_json)
14658 vty_out(vty, "}\n");
14659 else if (!nbr_output)
14660 vty_out(vty, "%% BGP instance not found\n");
14661 }
14662
14663 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
14664 enum show_type type, const char *ip_str,
14665 bool use_json)
14666 {
14667 int ret;
14668 struct bgp *bgp;
14669 union sockunion su;
14670 json_object *json = NULL;
14671
14672 if (name) {
14673 if (strmatch(name, "all")) {
14674 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
14675 use_json);
14676 return CMD_SUCCESS;
14677 } else {
14678 bgp = bgp_lookup_by_name(name);
14679 if (!bgp) {
14680 if (use_json) {
14681 json = json_object_new_object();
14682 vty_out(vty, "%s\n",
14683 json_object_to_json_string_ext(
14684 json,
14685 JSON_C_TO_STRING_PRETTY));
14686 json_object_free(json);
14687 } else
14688 vty_out(vty,
14689 "%% BGP instance not found\n");
14690
14691 return CMD_WARNING;
14692 }
14693 }
14694 } else {
14695 bgp = bgp_get_default();
14696 }
14697
14698 if (bgp) {
14699 json = json_object_new_object();
14700 if (ip_str) {
14701 ret = str2sockunion(ip_str, &su);
14702 if (ret < 0)
14703 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14704 use_json, json);
14705 else
14706 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14707 use_json, json);
14708 } else {
14709 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
14710 json);
14711 }
14712 json_object_free(json);
14713 } else {
14714 if (use_json)
14715 vty_out(vty, "{}\n");
14716 else
14717 vty_out(vty, "%% BGP instance not found\n");
14718 }
14719
14720 return CMD_SUCCESS;
14721 }
14722
14723
14724
14725 /* "show [ip] bgp neighbors graceful-restart" commands. */
14726 DEFUN (show_ip_bgp_neighbors_gracrful_restart,
14727 show_ip_bgp_neighbors_graceful_restart_cmd,
14728 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
14729 SHOW_STR
14730 BGP_STR
14731 IP_STR
14732 IPV6_STR
14733 NEIGHBOR_STR
14734 "Neighbor to display information about\n"
14735 "Neighbor to display information about\n"
14736 "Neighbor on BGP configured interface\n"
14737 GR_SHOW
14738 JSON_STR)
14739 {
14740 char *sh_arg = NULL;
14741 enum show_type sh_type;
14742 int idx = 0;
14743 afi_t afi = AFI_MAX;
14744 bool uj = use_json(argc, argv);
14745
14746 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
14747 afi = AFI_MAX;
14748
14749 idx++;
14750
14751 if (argv_find(argv, argc, "A.B.C.D", &idx)
14752 || argv_find(argv, argc, "X:X::X:X", &idx)
14753 || argv_find(argv, argc, "WORD", &idx)) {
14754 sh_type = show_peer;
14755 sh_arg = argv[idx]->arg;
14756 } else
14757 sh_type = show_all;
14758
14759 if (!argv_find(argv, argc, "graceful-restart", &idx))
14760 return CMD_SUCCESS;
14761
14762
14763 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
14764 afi, uj);
14765 }
14766
14767 /* "show [ip] bgp neighbors" commands. */
14768 DEFUN (show_ip_bgp_neighbors,
14769 show_ip_bgp_neighbors_cmd,
14770 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
14771 SHOW_STR
14772 IP_STR
14773 BGP_STR
14774 BGP_INSTANCE_HELP_STR
14775 "Address Family\n"
14776 "Address Family\n"
14777 "Detailed information on TCP and BGP neighbor connections\n"
14778 "Neighbor to display information about\n"
14779 "Neighbor to display information about\n"
14780 "Neighbor on BGP configured interface\n"
14781 JSON_STR)
14782 {
14783 char *vrf = NULL;
14784 char *sh_arg = NULL;
14785 enum show_type sh_type;
14786 afi_t afi = AFI_MAX;
14787
14788 bool uj = use_json(argc, argv);
14789
14790 int idx = 0;
14791
14792 /* [<vrf> VIEWVRFNAME] */
14793 if (argv_find(argv, argc, "vrf", &idx)) {
14794 vrf = argv[idx + 1]->arg;
14795 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
14796 vrf = NULL;
14797 } else if (argv_find(argv, argc, "view", &idx))
14798 /* [<view> VIEWVRFNAME] */
14799 vrf = argv[idx + 1]->arg;
14800
14801 idx++;
14802
14803 if (argv_find(argv, argc, "ipv4", &idx)) {
14804 sh_type = show_ipv4_all;
14805 afi = AFI_IP;
14806 } else if (argv_find(argv, argc, "ipv6", &idx)) {
14807 sh_type = show_ipv6_all;
14808 afi = AFI_IP6;
14809 } else {
14810 sh_type = show_all;
14811 }
14812
14813 if (argv_find(argv, argc, "A.B.C.D", &idx)
14814 || argv_find(argv, argc, "X:X::X:X", &idx)
14815 || argv_find(argv, argc, "WORD", &idx)) {
14816 sh_type = show_peer;
14817 sh_arg = argv[idx]->arg;
14818 }
14819
14820 if (sh_type == show_peer && afi == AFI_IP) {
14821 sh_type = show_ipv4_peer;
14822 } else if (sh_type == show_peer && afi == AFI_IP6) {
14823 sh_type = show_ipv6_peer;
14824 }
14825
14826 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
14827 }
14828
14829 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
14830 paths' and `show ip mbgp paths'. Those functions results are the
14831 same.*/
14832 DEFUN (show_ip_bgp_paths,
14833 show_ip_bgp_paths_cmd,
14834 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
14835 SHOW_STR
14836 IP_STR
14837 BGP_STR
14838 BGP_SAFI_HELP_STR
14839 "Path information\n")
14840 {
14841 vty_out(vty, "Address Refcnt Path\n");
14842 aspath_print_all_vty(vty);
14843 return CMD_SUCCESS;
14844 }
14845
14846 #include "hash.h"
14847
14848 static void community_show_all_iterator(struct hash_bucket *bucket,
14849 struct vty *vty)
14850 {
14851 struct community *com;
14852
14853 com = (struct community *)bucket->data;
14854 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
14855 community_str(com, false));
14856 }
14857
14858 /* Show BGP's community internal data. */
14859 DEFUN (show_ip_bgp_community_info,
14860 show_ip_bgp_community_info_cmd,
14861 "show [ip] bgp community-info",
14862 SHOW_STR
14863 IP_STR
14864 BGP_STR
14865 "List all bgp community information\n")
14866 {
14867 vty_out(vty, "Address Refcnt Community\n");
14868
14869 hash_iterate(community_hash(),
14870 (void (*)(struct hash_bucket *,
14871 void *))community_show_all_iterator,
14872 vty);
14873
14874 return CMD_SUCCESS;
14875 }
14876
14877 static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
14878 struct vty *vty)
14879 {
14880 struct lcommunity *lcom;
14881
14882 lcom = (struct lcommunity *)bucket->data;
14883 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
14884 lcommunity_str(lcom, false));
14885 }
14886
14887 /* Show BGP's community internal data. */
14888 DEFUN (show_ip_bgp_lcommunity_info,
14889 show_ip_bgp_lcommunity_info_cmd,
14890 "show ip bgp large-community-info",
14891 SHOW_STR
14892 IP_STR
14893 BGP_STR
14894 "List all bgp large-community information\n")
14895 {
14896 vty_out(vty, "Address Refcnt Large-community\n");
14897
14898 hash_iterate(lcommunity_hash(),
14899 (void (*)(struct hash_bucket *,
14900 void *))lcommunity_show_all_iterator,
14901 vty);
14902
14903 return CMD_SUCCESS;
14904 }
14905 /* Graceful Restart */
14906
14907 static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
14908 struct bgp *bgp,
14909 bool use_json,
14910 json_object *json)
14911 {
14912
14913
14914 vty_out(vty, "\n%s", SHOW_GR_HEADER);
14915
14916 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
14917
14918 switch (bgp_global_gr_mode) {
14919
14920 case GLOBAL_HELPER:
14921 vty_out(vty, "Global BGP GR Mode : Helper\n");
14922 break;
14923
14924 case GLOBAL_GR:
14925 vty_out(vty, "Global BGP GR Mode : Restart\n");
14926 break;
14927
14928 case GLOBAL_DISABLE:
14929 vty_out(vty, "Global BGP GR Mode : Disable\n");
14930 break;
14931
14932 case GLOBAL_INVALID:
14933 vty_out(vty,
14934 "Global BGP GR Mode Invalid\n");
14935 break;
14936 }
14937 vty_out(vty, "\n");
14938 }
14939
14940 static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
14941 enum show_type type,
14942 const char *ip_str,
14943 afi_t afi, bool use_json)
14944 {
14945 if ((afi == AFI_MAX) && (ip_str == NULL)) {
14946 afi = AFI_IP;
14947
14948 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
14949
14950 bgp_show_neighbor_graceful_restart_vty(
14951 vty, type, ip_str, afi, use_json);
14952 afi++;
14953 }
14954 } else if (afi != AFI_MAX) {
14955 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
14956 use_json);
14957 } else {
14958 return CMD_ERR_INCOMPLETE;
14959 }
14960
14961 return CMD_SUCCESS;
14962 }
14963 /* Graceful Restart */
14964
14965 DEFUN (show_ip_bgp_attr_info,
14966 show_ip_bgp_attr_info_cmd,
14967 "show [ip] bgp attribute-info",
14968 SHOW_STR
14969 IP_STR
14970 BGP_STR
14971 "List all bgp attribute information\n")
14972 {
14973 attr_show_all(vty);
14974 return CMD_SUCCESS;
14975 }
14976
14977 static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
14978 afi_t afi, safi_t safi,
14979 bool use_json, json_object *json)
14980 {
14981 struct bgp *bgp;
14982 struct listnode *node;
14983 char *vname;
14984 char buf1[INET6_ADDRSTRLEN];
14985 char *ecom_str;
14986 vpn_policy_direction_t dir;
14987
14988 if (json) {
14989 json_object *json_import_vrfs = NULL;
14990 json_object *json_export_vrfs = NULL;
14991
14992 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
14993
14994 if (!bgp) {
14995 vty_out(vty, "%s\n",
14996 json_object_to_json_string_ext(
14997 json,
14998 JSON_C_TO_STRING_PRETTY));
14999 json_object_free(json);
15000
15001 return CMD_WARNING;
15002 }
15003
15004 /* Provide context for the block */
15005 json_object_string_add(json, "vrf", name ? name : "default");
15006 json_object_string_add(json, "afiSafi",
15007 get_afi_safi_str(afi, safi, true));
15008
15009 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15010 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
15011 json_object_string_add(json, "importFromVrfs", "none");
15012 json_object_string_add(json, "importRts", "none");
15013 } else {
15014 json_import_vrfs = json_object_new_array();
15015
15016 for (ALL_LIST_ELEMENTS_RO(
15017 bgp->vpn_policy[afi].import_vrf,
15018 node, vname))
15019 json_object_array_add(json_import_vrfs,
15020 json_object_new_string(vname));
15021
15022 json_object_object_add(json, "importFromVrfs",
15023 json_import_vrfs);
15024 dir = BGP_VPN_POLICY_DIR_FROMVPN;
15025 if (bgp->vpn_policy[afi].rtlist[dir]) {
15026 ecom_str = ecommunity_ecom2str(
15027 bgp->vpn_policy[afi].rtlist[dir],
15028 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15029 json_object_string_add(json, "importRts",
15030 ecom_str);
15031 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15032 } else
15033 json_object_string_add(json, "importRts",
15034 "none");
15035 }
15036
15037 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15038 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
15039 json_object_string_add(json, "exportToVrfs", "none");
15040 json_object_string_add(json, "routeDistinguisher",
15041 "none");
15042 json_object_string_add(json, "exportRts", "none");
15043 } else {
15044 json_export_vrfs = json_object_new_array();
15045
15046 for (ALL_LIST_ELEMENTS_RO(
15047 bgp->vpn_policy[afi].export_vrf,
15048 node, vname))
15049 json_object_array_add(json_export_vrfs,
15050 json_object_new_string(vname));
15051 json_object_object_add(json, "exportToVrfs",
15052 json_export_vrfs);
15053 json_object_string_add(json, "routeDistinguisher",
15054 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
15055 buf1, RD_ADDRSTRLEN));
15056
15057 dir = BGP_VPN_POLICY_DIR_TOVPN;
15058 if (bgp->vpn_policy[afi].rtlist[dir]) {
15059 ecom_str = ecommunity_ecom2str(
15060 bgp->vpn_policy[afi].rtlist[dir],
15061 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15062 json_object_string_add(json, "exportRts",
15063 ecom_str);
15064 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15065 } else
15066 json_object_string_add(json, "exportRts",
15067 "none");
15068 }
15069
15070 if (use_json) {
15071 vty_out(vty, "%s\n",
15072 json_object_to_json_string_ext(json,
15073 JSON_C_TO_STRING_PRETTY));
15074 json_object_free(json);
15075 }
15076 } else {
15077 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15078
15079 if (!bgp) {
15080 vty_out(vty, "%% No such BGP instance exist\n");
15081 return CMD_WARNING;
15082 }
15083
15084 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15085 BGP_CONFIG_VRF_TO_VRF_IMPORT))
15086 vty_out(vty,
15087 "This VRF is not importing %s routes from any other VRF\n",
15088 get_afi_safi_str(afi, safi, false));
15089 else {
15090 vty_out(vty,
15091 "This VRF is importing %s routes from the following VRFs:\n",
15092 get_afi_safi_str(afi, safi, false));
15093
15094 for (ALL_LIST_ELEMENTS_RO(
15095 bgp->vpn_policy[afi].import_vrf,
15096 node, vname))
15097 vty_out(vty, " %s\n", vname);
15098
15099 dir = BGP_VPN_POLICY_DIR_FROMVPN;
15100 ecom_str = NULL;
15101 if (bgp->vpn_policy[afi].rtlist[dir]) {
15102 ecom_str = ecommunity_ecom2str(
15103 bgp->vpn_policy[afi].rtlist[dir],
15104 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15105 vty_out(vty, "Import RT(s): %s\n", ecom_str);
15106
15107 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15108 } else
15109 vty_out(vty, "Import RT(s):\n");
15110 }
15111
15112 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15113 BGP_CONFIG_VRF_TO_VRF_EXPORT))
15114 vty_out(vty,
15115 "This VRF is not exporting %s routes to any other VRF\n",
15116 get_afi_safi_str(afi, safi, false));
15117 else {
15118 vty_out(vty,
15119 "This VRF is exporting %s routes to the following VRFs:\n",
15120 get_afi_safi_str(afi, safi, false));
15121
15122 for (ALL_LIST_ELEMENTS_RO(
15123 bgp->vpn_policy[afi].export_vrf,
15124 node, vname))
15125 vty_out(vty, " %s\n", vname);
15126
15127 vty_out(vty, "RD: %s\n",
15128 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
15129 buf1, RD_ADDRSTRLEN));
15130
15131 dir = BGP_VPN_POLICY_DIR_TOVPN;
15132 if (bgp->vpn_policy[afi].rtlist[dir]) {
15133 ecom_str = ecommunity_ecom2str(
15134 bgp->vpn_policy[afi].rtlist[dir],
15135 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15136 vty_out(vty, "Export RT: %s\n", ecom_str);
15137 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15138 } else
15139 vty_out(vty, "Import RT(s):\n");
15140 }
15141 }
15142
15143 return CMD_SUCCESS;
15144 }
15145
15146 static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
15147 safi_t safi, bool use_json)
15148 {
15149 struct listnode *node, *nnode;
15150 struct bgp *bgp;
15151 char *vrf_name = NULL;
15152 json_object *json = NULL;
15153 json_object *json_vrf = NULL;
15154 json_object *json_vrfs = NULL;
15155
15156 if (use_json) {
15157 json = json_object_new_object();
15158 json_vrfs = json_object_new_object();
15159 }
15160
15161 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15162
15163 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
15164 vrf_name = bgp->name;
15165
15166 if (use_json) {
15167 json_vrf = json_object_new_object();
15168 } else {
15169 vty_out(vty, "\nInstance %s:\n",
15170 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15171 ? VRF_DEFAULT_NAME : bgp->name);
15172 }
15173 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
15174 if (use_json) {
15175 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15176 json_object_object_add(json_vrfs,
15177 VRF_DEFAULT_NAME, json_vrf);
15178 else
15179 json_object_object_add(json_vrfs, vrf_name,
15180 json_vrf);
15181 }
15182 }
15183
15184 if (use_json) {
15185 json_object_object_add(json, "vrfs", json_vrfs);
15186 vty_out(vty, "%s\n", json_object_to_json_string_ext(json,
15187 JSON_C_TO_STRING_PRETTY));
15188 json_object_free(json);
15189 }
15190
15191 return CMD_SUCCESS;
15192 }
15193
15194 /* "show [ip] bgp route-leak" command. */
15195 DEFUN (show_ip_bgp_route_leak,
15196 show_ip_bgp_route_leak_cmd,
15197 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
15198 SHOW_STR
15199 IP_STR
15200 BGP_STR
15201 BGP_INSTANCE_HELP_STR
15202 BGP_AFI_HELP_STR
15203 BGP_SAFI_HELP_STR
15204 "Route leaking information\n"
15205 JSON_STR)
15206 {
15207 char *vrf = NULL;
15208 afi_t afi = AFI_MAX;
15209 safi_t safi = SAFI_MAX;
15210
15211 bool uj = use_json(argc, argv);
15212 int idx = 0;
15213 json_object *json = NULL;
15214
15215 /* show [ip] bgp */
15216 if (argv_find(argv, argc, "ip", &idx)) {
15217 afi = AFI_IP;
15218 safi = SAFI_UNICAST;
15219 }
15220 /* [vrf VIEWVRFNAME] */
15221 if (argv_find(argv, argc, "view", &idx)) {
15222 vty_out(vty,
15223 "%% This command is not applicable to BGP views\n");
15224 return CMD_WARNING;
15225 }
15226
15227 if (argv_find(argv, argc, "vrf", &idx)) {
15228 vrf = argv[idx + 1]->arg;
15229 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15230 vrf = NULL;
15231 }
15232 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15233 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
15234 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15235 }
15236
15237 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
15238 vty_out(vty,
15239 "%% This command is applicable only for unicast ipv4|ipv6\n");
15240 return CMD_WARNING;
15241 }
15242
15243 if (vrf && strmatch(vrf, "all"))
15244 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
15245
15246 if (uj)
15247 json = json_object_new_object();
15248
15249 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
15250 }
15251
15252 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
15253 safi_t safi)
15254 {
15255 struct listnode *node, *nnode;
15256 struct bgp *bgp;
15257
15258 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15259 vty_out(vty, "\nInstance %s:\n",
15260 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15261 ? VRF_DEFAULT_NAME
15262 : bgp->name);
15263 update_group_show(bgp, afi, safi, vty, 0);
15264 }
15265 }
15266
15267 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
15268 int safi, uint64_t subgrp_id)
15269 {
15270 struct bgp *bgp;
15271
15272 if (name) {
15273 if (strmatch(name, "all")) {
15274 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
15275 return CMD_SUCCESS;
15276 } else {
15277 bgp = bgp_lookup_by_name(name);
15278 }
15279 } else {
15280 bgp = bgp_get_default();
15281 }
15282
15283 if (bgp)
15284 update_group_show(bgp, afi, safi, vty, subgrp_id);
15285 return CMD_SUCCESS;
15286 }
15287
15288 DEFUN (show_ip_bgp_updgrps,
15289 show_ip_bgp_updgrps_cmd,
15290 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
15291 SHOW_STR
15292 IP_STR
15293 BGP_STR
15294 BGP_INSTANCE_HELP_STR
15295 BGP_AFI_HELP_STR
15296 BGP_SAFI_WITH_LABEL_HELP_STR
15297 "Detailed info about dynamic update groups\n"
15298 "Specific subgroup to display detailed info for\n")
15299 {
15300 char *vrf = NULL;
15301 afi_t afi = AFI_IP6;
15302 safi_t safi = SAFI_UNICAST;
15303 uint64_t subgrp_id = 0;
15304
15305 int idx = 0;
15306
15307 /* show [ip] bgp */
15308 if (argv_find(argv, argc, "ip", &idx))
15309 afi = AFI_IP;
15310 /* [<vrf> VIEWVRFNAME] */
15311 if (argv_find(argv, argc, "vrf", &idx)) {
15312 vrf = argv[idx + 1]->arg;
15313 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15314 vrf = NULL;
15315 } else if (argv_find(argv, argc, "view", &idx))
15316 /* [<view> VIEWVRFNAME] */
15317 vrf = argv[idx + 1]->arg;
15318 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15319 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
15320 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15321 }
15322
15323 /* get subgroup id, if provided */
15324 idx = argc - 1;
15325 if (argv[idx]->type == VARIABLE_TKN)
15326 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
15327
15328 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
15329 }
15330
15331 DEFUN (show_bgp_instance_all_ipv6_updgrps,
15332 show_bgp_instance_all_ipv6_updgrps_cmd,
15333 "show [ip] bgp <view|vrf> all update-groups",
15334 SHOW_STR
15335 IP_STR
15336 BGP_STR
15337 BGP_INSTANCE_ALL_HELP_STR
15338 "Detailed info about dynamic update groups\n")
15339 {
15340 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
15341 return CMD_SUCCESS;
15342 }
15343
15344 DEFUN (show_bgp_l2vpn_evpn_updgrps,
15345 show_bgp_l2vpn_evpn_updgrps_cmd,
15346 "show [ip] bgp l2vpn evpn update-groups",
15347 SHOW_STR
15348 IP_STR
15349 BGP_STR
15350 "l2vpn address family\n"
15351 "evpn sub-address family\n"
15352 "Detailed info about dynamic update groups\n")
15353 {
15354 char *vrf = NULL;
15355 uint64_t subgrp_id = 0;
15356
15357 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
15358 return CMD_SUCCESS;
15359 }
15360
15361 DEFUN (show_bgp_updgrps_stats,
15362 show_bgp_updgrps_stats_cmd,
15363 "show [ip] bgp update-groups statistics",
15364 SHOW_STR
15365 IP_STR
15366 BGP_STR
15367 "Detailed info about dynamic update groups\n"
15368 "Statistics\n")
15369 {
15370 struct bgp *bgp;
15371
15372 bgp = bgp_get_default();
15373 if (bgp)
15374 update_group_show_stats(bgp, vty);
15375
15376 return CMD_SUCCESS;
15377 }
15378
15379 DEFUN (show_bgp_instance_updgrps_stats,
15380 show_bgp_instance_updgrps_stats_cmd,
15381 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
15382 SHOW_STR
15383 IP_STR
15384 BGP_STR
15385 BGP_INSTANCE_HELP_STR
15386 "Detailed info about dynamic update groups\n"
15387 "Statistics\n")
15388 {
15389 int idx_word = 3;
15390 struct bgp *bgp;
15391
15392 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
15393 if (bgp)
15394 update_group_show_stats(bgp, vty);
15395
15396 return CMD_SUCCESS;
15397 }
15398
15399 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
15400 afi_t afi, safi_t safi,
15401 const char *what, uint64_t subgrp_id)
15402 {
15403 struct bgp *bgp;
15404
15405 if (name)
15406 bgp = bgp_lookup_by_name(name);
15407 else
15408 bgp = bgp_get_default();
15409
15410 if (bgp) {
15411 if (!strcmp(what, "advertise-queue"))
15412 update_group_show_adj_queue(bgp, afi, safi, vty,
15413 subgrp_id);
15414 else if (!strcmp(what, "advertised-routes"))
15415 update_group_show_advertised(bgp, afi, safi, vty,
15416 subgrp_id);
15417 else if (!strcmp(what, "packet-queue"))
15418 update_group_show_packet_queue(bgp, afi, safi, vty,
15419 subgrp_id);
15420 }
15421 }
15422
15423 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
15424 show_ip_bgp_instance_updgrps_adj_s_cmd,
15425 "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",
15426 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
15427 BGP_SAFI_HELP_STR
15428 "Detailed info about dynamic update groups\n"
15429 "Specific subgroup to display info for\n"
15430 "Advertisement queue\n"
15431 "Announced routes\n"
15432 "Packet queue\n")
15433 {
15434 uint64_t subgrp_id = 0;
15435 afi_t afiz;
15436 safi_t safiz;
15437 if (sgid)
15438 subgrp_id = strtoull(sgid, NULL, 10);
15439
15440 if (!ip && !afi)
15441 afiz = AFI_IP6;
15442 if (!ip && afi)
15443 afiz = bgp_vty_afi_from_str(afi);
15444 if (ip && !afi)
15445 afiz = AFI_IP;
15446 if (ip && afi) {
15447 afiz = bgp_vty_afi_from_str(afi);
15448 if (afiz != AFI_IP)
15449 vty_out(vty,
15450 "%% Cannot specify both 'ip' and 'ipv6'\n");
15451 return CMD_WARNING;
15452 }
15453
15454 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
15455
15456 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
15457 return CMD_SUCCESS;
15458 }
15459
15460 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
15461 {
15462 struct listnode *node, *nnode;
15463 struct prefix *range;
15464 struct peer *conf;
15465 struct peer *peer;
15466 afi_t afi;
15467 safi_t safi;
15468 const char *peer_status;
15469 const char *af_str;
15470 int lr_count;
15471 int dynamic;
15472 int af_cfgd;
15473
15474 conf = group->conf;
15475
15476 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
15477 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15478 group->name, conf->as);
15479 } else if (conf->as_type == AS_INTERNAL) {
15480 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15481 group->name, group->bgp->as);
15482 } else {
15483 vty_out(vty, "\nBGP peer-group %s\n", group->name);
15484 }
15485
15486 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
15487 vty_out(vty, " Peer-group type is internal\n");
15488 else
15489 vty_out(vty, " Peer-group type is external\n");
15490
15491 /* Display AFs configured. */
15492 vty_out(vty, " Configured address-families:");
15493 FOREACH_AFI_SAFI (afi, safi) {
15494 if (conf->afc[afi][safi]) {
15495 af_cfgd = 1;
15496 vty_out(vty, " %s;", get_afi_safi_str(afi, safi, false));
15497 }
15498 }
15499 if (!af_cfgd)
15500 vty_out(vty, " none\n");
15501 else
15502 vty_out(vty, "\n");
15503
15504 /* Display listen ranges (for dynamic neighbors), if any */
15505 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
15506 if (afi == AFI_IP)
15507 af_str = "IPv4";
15508 else if (afi == AFI_IP6)
15509 af_str = "IPv6";
15510 else
15511 af_str = "???";
15512 lr_count = listcount(group->listen_range[afi]);
15513 if (lr_count) {
15514 vty_out(vty, " %d %s listen range(s)\n", lr_count,
15515 af_str);
15516
15517
15518 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
15519 nnode, range))
15520 vty_out(vty, " %pFX\n", range);
15521 }
15522 }
15523
15524 /* Display group members and their status */
15525 if (listcount(group->peer)) {
15526 vty_out(vty, " Peer-group members:\n");
15527 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
15528 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
15529 || CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHUTDOWN))
15530 peer_status = "Idle (Admin)";
15531 else if (CHECK_FLAG(peer->sflags,
15532 PEER_STATUS_PREFIX_OVERFLOW))
15533 peer_status = "Idle (PfxCt)";
15534 else
15535 peer_status = lookup_msg(bgp_status_msg,
15536 peer->status, NULL);
15537
15538 dynamic = peer_dynamic_neighbor(peer);
15539 vty_out(vty, " %s %s %s \n", peer->host,
15540 dynamic ? "(dynamic)" : "", peer_status);
15541 }
15542 }
15543
15544 return CMD_SUCCESS;
15545 }
15546
15547 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
15548 const char *group_name)
15549 {
15550 struct bgp *bgp;
15551 struct listnode *node, *nnode;
15552 struct peer_group *group;
15553 bool found = false;
15554
15555 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15556
15557 if (!bgp) {
15558 vty_out(vty, "%% BGP instance not found\n");
15559 return CMD_WARNING;
15560 }
15561
15562 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
15563 if (group_name) {
15564 if (strmatch(group->name, group_name)) {
15565 bgp_show_one_peer_group(vty, group);
15566 found = true;
15567 break;
15568 }
15569 } else {
15570 bgp_show_one_peer_group(vty, group);
15571 }
15572 }
15573
15574 if (group_name && !found)
15575 vty_out(vty, "%% No such peer-group\n");
15576
15577 return CMD_SUCCESS;
15578 }
15579
15580 DEFUN (show_ip_bgp_peer_groups,
15581 show_ip_bgp_peer_groups_cmd,
15582 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
15583 SHOW_STR
15584 IP_STR
15585 BGP_STR
15586 BGP_INSTANCE_HELP_STR
15587 "Detailed information on BGP peer groups\n"
15588 "Peer group name\n")
15589 {
15590 char *vrf, *pg;
15591 int idx = 0;
15592
15593 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
15594 : NULL;
15595 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
15596
15597 return bgp_show_peer_group_vty(vty, vrf, pg);
15598 }
15599
15600
15601 /* Redistribute VTY commands. */
15602
15603 DEFUN_YANG (bgp_redistribute_ipv4,
15604 bgp_redistribute_ipv4_cmd,
15605 "redistribute " FRR_IP_REDIST_STR_BGPD,
15606 "Redistribute information from another routing protocol\n"
15607 FRR_IP_REDIST_HELP_STR_BGPD)
15608 {
15609 int idx_protocol = 1;
15610 char base_xpath[XPATH_MAXLEN];
15611
15612 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15613 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15614 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15615 argv[idx_protocol]->text, "0");
15616
15617 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15618
15619 return nb_cli_apply_changes(vty, base_xpath);
15620 }
15621
15622 ALIAS_HIDDEN(
15623 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
15624 "redistribute " FRR_IP_REDIST_STR_BGPD,
15625 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
15626
15627 DEFUN_YANG (bgp_redistribute_ipv4_rmap,
15628 bgp_redistribute_ipv4_rmap_cmd,
15629 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
15630 "Redistribute information from another routing protocol\n"
15631 FRR_IP_REDIST_HELP_STR_BGPD
15632 "Route map reference\n"
15633 "Pointer to route-map entries\n")
15634 {
15635 int idx_protocol = 1;
15636 int idx_word = 3;
15637 char base_xpath[XPATH_MAXLEN];
15638
15639 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15640 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15641 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15642 argv[idx_protocol]->text, "0");
15643
15644 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15645 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15646 argv[idx_word]->arg);
15647
15648 return nb_cli_apply_changes(vty, base_xpath);
15649 }
15650
15651 ALIAS_HIDDEN(
15652 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
15653 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
15654 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15655 "Route map reference\n"
15656 "Pointer to route-map entries\n")
15657
15658 DEFUN_YANG (bgp_redistribute_ipv4_metric,
15659 bgp_redistribute_ipv4_metric_cmd,
15660 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15661 "Redistribute information from another routing protocol\n"
15662 FRR_IP_REDIST_HELP_STR_BGPD
15663 "Metric for redistributed routes\n"
15664 "Default metric\n")
15665 {
15666 int idx_protocol = 1;
15667 int idx_number = 3;
15668 char base_xpath[XPATH_MAXLEN];
15669
15670 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15671 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15672 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15673 argv[idx_protocol]->text, "0");
15674
15675 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15676 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15677 argv[idx_number]->arg);
15678
15679 return nb_cli_apply_changes(vty, base_xpath);
15680 }
15681
15682 ALIAS_HIDDEN(
15683 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
15684 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15685 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15686 "Metric for redistributed routes\n"
15687 "Default metric\n")
15688
15689 DEFUN_YANG(
15690 bgp_redistribute_ipv4_rmap_metric,
15691 bgp_redistribute_ipv4_rmap_metric_cmd,
15692 "redistribute " FRR_IP_REDIST_STR_BGPD
15693 " route-map WORD metric (0-4294967295)",
15694 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15695 "Route map reference\n"
15696 "Pointer to route-map entries\n"
15697 "Metric for redistributed routes\n"
15698 "Default metric\n")
15699 {
15700 int idx_protocol = 1;
15701 int idx_word = 3;
15702 int idx_number = 5;
15703 char base_xpath[XPATH_MAXLEN];
15704
15705 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15706 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15707 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15708 argv[idx_protocol]->text, "0");
15709
15710 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15711 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15712 argv[idx_word]->arg);
15713 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15714 argv[idx_number]->arg);
15715
15716 return nb_cli_apply_changes(vty, base_xpath);
15717 }
15718
15719 ALIAS_HIDDEN(
15720 bgp_redistribute_ipv4_rmap_metric,
15721 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
15722 "redistribute " FRR_IP_REDIST_STR_BGPD
15723 " route-map WORD metric (0-4294967295)",
15724 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15725 "Route map reference\n"
15726 "Pointer to route-map entries\n"
15727 "Metric for redistributed routes\n"
15728 "Default metric\n")
15729
15730 DEFUN_YANG(
15731 bgp_redistribute_ipv4_metric_rmap,
15732 bgp_redistribute_ipv4_metric_rmap_cmd,
15733 "redistribute " FRR_IP_REDIST_STR_BGPD
15734 " metric (0-4294967295) route-map WORD",
15735 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15736 "Metric for redistributed routes\n"
15737 "Default metric\n"
15738 "Route map reference\n"
15739 "Pointer to route-map entries\n")
15740 {
15741 int idx_protocol = 1;
15742 int idx_word = 5;
15743 int idx_number = 3;
15744 char base_xpath[XPATH_MAXLEN];
15745
15746 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15747 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15748 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15749 argv[idx_protocol]->text, "0");
15750
15751 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15752 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15753 argv[idx_number]->arg);
15754 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15755 argv[idx_word]->arg);
15756
15757 return nb_cli_apply_changes(vty, base_xpath);
15758 }
15759
15760 ALIAS_HIDDEN(
15761 bgp_redistribute_ipv4_metric_rmap,
15762 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
15763 "redistribute " FRR_IP_REDIST_STR_BGPD
15764 " metric (0-4294967295) route-map WORD",
15765 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15766 "Metric for redistributed routes\n"
15767 "Default metric\n"
15768 "Route map reference\n"
15769 "Pointer to route-map entries\n")
15770
15771 DEFUN_YANG (bgp_redistribute_ipv4_ospf,
15772 bgp_redistribute_ipv4_ospf_cmd,
15773 "redistribute <ospf|table> (1-65535)",
15774 "Redistribute information from another routing protocol\n"
15775 "Open Shortest Path First (OSPFv2)\n"
15776 "Non-main Kernel Routing Table\n"
15777 "Instance ID/Table ID\n")
15778 {
15779 int idx_protocol = 1;
15780 int idx_number = 2;
15781 char base_xpath[XPATH_MAXLEN];
15782
15783 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15784 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15785 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15786 argv[idx_protocol]->text, argv[idx_number]->arg);
15787
15788 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15789
15790 return nb_cli_apply_changes(vty, base_xpath);
15791 }
15792
15793 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
15794 "redistribute <ospf|table> (1-65535)",
15795 "Redistribute information from another routing protocol\n"
15796 "Open Shortest Path First (OSPFv2)\n"
15797 "Non-main Kernel Routing Table\n"
15798 "Instance ID/Table ID\n")
15799
15800 DEFUN_YANG (bgp_redistribute_ipv4_ospf_rmap,
15801 bgp_redistribute_ipv4_ospf_rmap_cmd,
15802 "redistribute <ospf|table> (1-65535) route-map WORD",
15803 "Redistribute information from another routing protocol\n"
15804 "Open Shortest Path First (OSPFv2)\n"
15805 "Non-main Kernel Routing Table\n"
15806 "Instance ID/Table ID\n"
15807 "Route map reference\n"
15808 "Pointer to route-map entries\n")
15809 {
15810 int idx_protocol = 1;
15811 int idx_number = 2;
15812 int idx_word = 4;
15813 char base_xpath[XPATH_MAXLEN];
15814
15815 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15816 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15817 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15818 argv[idx_protocol]->text, argv[idx_number]->arg);
15819
15820 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15821
15822 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15823 argv[idx_word]->arg);
15824
15825 return nb_cli_apply_changes(vty, base_xpath);
15826 }
15827
15828 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
15829 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
15830 "redistribute <ospf|table> (1-65535) route-map WORD",
15831 "Redistribute information from another routing protocol\n"
15832 "Open Shortest Path First (OSPFv2)\n"
15833 "Non-main Kernel Routing Table\n"
15834 "Instance ID/Table ID\n"
15835 "Route map reference\n"
15836 "Pointer to route-map entries\n")
15837
15838 DEFUN_YANG(bgp_redistribute_ipv4_ospf_metric,
15839 bgp_redistribute_ipv4_ospf_metric_cmd,
15840 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
15841 "Redistribute information from another routing protocol\n"
15842 "Open Shortest Path First (OSPFv2)\n"
15843 "Non-main Kernel Routing Table\n"
15844 "Instance ID/Table ID\n"
15845 "Metric for redistributed routes\n"
15846 "Default metric\n")
15847 {
15848 int idx_protocol = 1;
15849 int idx_number = 2;
15850 int idx_number_2 = 4;
15851 char base_xpath[XPATH_MAXLEN];
15852
15853 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15854 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15855 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15856 argv[idx_protocol]->text, argv[idx_number]->arg);
15857
15858 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15859
15860 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15861 argv[idx_number_2]->arg);
15862
15863 return nb_cli_apply_changes(vty, base_xpath);
15864 }
15865
15866 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
15867 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
15868 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
15869 "Redistribute information from another routing protocol\n"
15870 "Open Shortest Path First (OSPFv2)\n"
15871 "Non-main Kernel Routing Table\n"
15872 "Instance ID/Table ID\n"
15873 "Metric for redistributed routes\n"
15874 "Default metric\n")
15875
15876 DEFUN_YANG(
15877 bgp_redistribute_ipv4_ospf_rmap_metric,
15878 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
15879 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
15880 "Redistribute information from another routing protocol\n"
15881 "Open Shortest Path First (OSPFv2)\n"
15882 "Non-main Kernel Routing Table\n"
15883 "Instance ID/Table ID\n"
15884 "Route map reference\n"
15885 "Pointer to route-map entries\n"
15886 "Metric for redistributed routes\n"
15887 "Default metric\n")
15888 {
15889 int idx_protocol = 1;
15890 int idx_number = 2;
15891 int idx_word = 4;
15892 int idx_number_2 = 6;
15893 char base_xpath[XPATH_MAXLEN];
15894
15895 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15896 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15897 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15898 argv[idx_protocol]->text, argv[idx_number]->arg);
15899
15900 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15901
15902 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15903 argv[idx_word]->arg);
15904 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15905 argv[idx_number_2]->arg);
15906
15907 return nb_cli_apply_changes(vty, base_xpath);
15908 }
15909
15910 ALIAS_HIDDEN(
15911 bgp_redistribute_ipv4_ospf_rmap_metric,
15912 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
15913 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
15914 "Redistribute information from another routing protocol\n"
15915 "Open Shortest Path First (OSPFv2)\n"
15916 "Non-main Kernel Routing Table\n"
15917 "Instance ID/Table ID\n"
15918 "Route map reference\n"
15919 "Pointer to route-map entries\n"
15920 "Metric for redistributed routes\n"
15921 "Default metric\n")
15922
15923 DEFUN_YANG(
15924 bgp_redistribute_ipv4_ospf_metric_rmap,
15925 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
15926 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
15927 "Redistribute information from another routing protocol\n"
15928 "Open Shortest Path First (OSPFv2)\n"
15929 "Non-main Kernel Routing Table\n"
15930 "Instance ID/Table ID\n"
15931 "Metric for redistributed routes\n"
15932 "Default metric\n"
15933 "Route map reference\n"
15934 "Pointer to route-map entries\n")
15935 {
15936 int idx_protocol = 1;
15937 int idx_number = 2;
15938 int idx_number_2 = 4;
15939 int idx_word = 6;
15940 char base_xpath[XPATH_MAXLEN];
15941
15942 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15943 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15944 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15945 argv[idx_protocol]->text, argv[idx_number]->arg);
15946
15947 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15948
15949 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15950 argv[idx_number_2]->arg);
15951 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15952 argv[idx_word]->arg);
15953
15954 return nb_cli_apply_changes(vty, base_xpath);
15955 }
15956
15957 ALIAS_HIDDEN(
15958 bgp_redistribute_ipv4_ospf_metric_rmap,
15959 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
15960 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
15961 "Redistribute information from another routing protocol\n"
15962 "Open Shortest Path First (OSPFv2)\n"
15963 "Non-main Kernel Routing Table\n"
15964 "Instance ID/Table ID\n"
15965 "Metric for redistributed routes\n"
15966 "Default metric\n"
15967 "Route map reference\n"
15968 "Pointer to route-map entries\n")
15969
15970 DEFUN_YANG (no_bgp_redistribute_ipv4_ospf,
15971 no_bgp_redistribute_ipv4_ospf_cmd,
15972 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
15973 NO_STR
15974 "Redistribute information from another routing protocol\n"
15975 "Open Shortest Path First (OSPFv2)\n"
15976 "Non-main Kernel Routing Table\n"
15977 "Instance ID/Table ID\n"
15978 "Metric for redistributed routes\n"
15979 "Default metric\n"
15980 "Route map reference\n"
15981 "Pointer to route-map entries\n")
15982 {
15983 int idx_protocol = 2;
15984 int idx_number = 3;
15985 char base_xpath[XPATH_MAXLEN];
15986
15987 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15988 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15989 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15990 argv[idx_protocol]->text, argv[idx_number]->arg);
15991
15992 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
15993
15994 return nb_cli_apply_changes(vty, base_xpath);
15995 }
15996
15997 ALIAS_HIDDEN(
15998 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
15999 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
16000 NO_STR
16001 "Redistribute information from another routing protocol\n"
16002 "Open Shortest Path First (OSPFv2)\n"
16003 "Non-main Kernel Routing Table\n"
16004 "Instance ID/Table ID\n"
16005 "Metric for redistributed routes\n"
16006 "Default metric\n"
16007 "Route map reference\n"
16008 "Pointer to route-map entries\n")
16009
16010 DEFUN_YANG (no_bgp_redistribute_ipv4,
16011 no_bgp_redistribute_ipv4_cmd,
16012 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
16013 NO_STR
16014 "Redistribute information from another routing protocol\n"
16015 FRR_IP_REDIST_HELP_STR_BGPD
16016 "Metric for redistributed routes\n"
16017 "Default metric\n"
16018 "Route map reference\n"
16019 "Pointer to route-map entries\n")
16020 {
16021 int idx_protocol = 2;
16022 char base_xpath[XPATH_MAXLEN];
16023
16024 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16025 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16026 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16027 argv[idx_protocol]->text, "0");
16028
16029 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
16030
16031 return nb_cli_apply_changes(vty, base_xpath);
16032 }
16033
16034 ALIAS_HIDDEN(
16035 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
16036 "no redistribute " FRR_IP_REDIST_STR_BGPD
16037 " [{metric (0-4294967295)|route-map WORD}]",
16038 NO_STR
16039 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16040 "Metric for redistributed routes\n"
16041 "Default metric\n"
16042 "Route map reference\n"
16043 "Pointer to route-map entries\n")
16044
16045 DEFUN_YANG (bgp_redistribute_ipv6,
16046 bgp_redistribute_ipv6_cmd,
16047 "redistribute " FRR_IP6_REDIST_STR_BGPD,
16048 "Redistribute information from another routing protocol\n"
16049 FRR_IP6_REDIST_HELP_STR_BGPD)
16050 {
16051 int idx_protocol = 1;
16052 char base_xpath[XPATH_MAXLEN];
16053
16054 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16055 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16056 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16057 argv[idx_protocol]->text, "0");
16058
16059 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16060
16061 return nb_cli_apply_changes(vty, base_xpath);
16062 }
16063
16064 DEFUN_YANG (bgp_redistribute_ipv6_rmap,
16065 bgp_redistribute_ipv6_rmap_cmd,
16066 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
16067 "Redistribute information from another routing protocol\n"
16068 FRR_IP6_REDIST_HELP_STR_BGPD
16069 "Route map reference\n"
16070 "Pointer to route-map entries\n")
16071 {
16072 int idx_protocol = 1;
16073 int idx_word = 3;
16074 char base_xpath[XPATH_MAXLEN];
16075
16076 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16077 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16078 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16079 argv[idx_protocol]->text, "0");
16080
16081 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16082 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16083 argv[idx_word]->arg);
16084
16085 return nb_cli_apply_changes(vty, base_xpath);
16086 }
16087
16088 DEFUN_YANG (bgp_redistribute_ipv6_metric,
16089 bgp_redistribute_ipv6_metric_cmd,
16090 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
16091 "Redistribute information from another routing protocol\n"
16092 FRR_IP6_REDIST_HELP_STR_BGPD
16093 "Metric for redistributed routes\n"
16094 "Default metric\n")
16095 {
16096 int idx_protocol = 1;
16097 int idx_number = 3;
16098 char base_xpath[XPATH_MAXLEN];
16099
16100 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16101 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16102 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16103 argv[idx_protocol]->text, "0");
16104
16105 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16106 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16107 argv[idx_number]->arg);
16108
16109 return nb_cli_apply_changes(vty, base_xpath);
16110 }
16111
16112 DEFUN_YANG(
16113 bgp_redistribute_ipv6_rmap_metric,
16114 bgp_redistribute_ipv6_rmap_metric_cmd,
16115 "redistribute " FRR_IP6_REDIST_STR_BGPD
16116 " route-map WORD metric (0-4294967295)",
16117 "Redistribute information from another routing protocol\n" FRR_IP6_REDIST_HELP_STR_BGPD
16118 "Route map reference\n"
16119 "Pointer to route-map entries\n"
16120 "Metric for redistributed routes\n"
16121 "Default metric\n")
16122 {
16123 int idx_protocol = 1;
16124 int idx_word = 3;
16125 int idx_number = 5;
16126 char base_xpath[XPATH_MAXLEN];
16127
16128 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16129 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16130 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16131 argv[idx_protocol]->text, "0");
16132
16133 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16134 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16135 argv[idx_word]->arg);
16136 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16137 argv[idx_number]->arg);
16138
16139 return nb_cli_apply_changes(vty, base_xpath);
16140 }
16141
16142 DEFUN_YANG(
16143 bgp_redistribute_ipv6_metric_rmap,
16144 bgp_redistribute_ipv6_metric_rmap_cmd,
16145 "redistribute " FRR_IP6_REDIST_STR_BGPD
16146 " metric (0-4294967295) route-map WORD",
16147 "Redistribute information from another routing protocol\n" FRR_IP6_REDIST_HELP_STR_BGPD
16148 "Metric for redistributed routes\n"
16149 "Default metric\n"
16150 "Route map reference\n"
16151 "Pointer to route-map entries\n")
16152 {
16153 int idx_protocol = 1;
16154 int idx_word = 5;
16155 int idx_number = 3;
16156 char base_xpath[XPATH_MAXLEN];
16157
16158 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16159 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16160 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16161 argv[idx_protocol]->text, "0");
16162
16163 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16164 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16165 argv[idx_number]->arg);
16166 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16167 argv[idx_word]->arg);
16168
16169 return nb_cli_apply_changes(vty, base_xpath);
16170 }
16171
16172 DEFUN_YANG(
16173 no_bgp_redistribute_ipv6,
16174 no_bgp_redistribute_ipv6_cmd,
16175 "no redistribute " FRR_IP6_REDIST_STR_BGPD
16176 " [{metric (0-4294967295)|route-map WORD}]",
16177 NO_STR
16178 "Redistribute information from another routing protocol\n" FRR_IP6_REDIST_HELP_STR_BGPD
16179 "Metric for redistributed routes\n"
16180 "Default metric\n"
16181 "Route map reference\n"
16182 "Pointer to route-map entries\n")
16183 {
16184 int idx_protocol = 2;
16185 char base_xpath[XPATH_MAXLEN];
16186
16187 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16188 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16189 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16190 argv[idx_protocol]->text, "0");
16191
16192 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
16193
16194 return nb_cli_apply_changes(vty, base_xpath);
16195 }
16196
16197 void cli_show_bgp_global_afi_safi_ip_unicast_redistribution_list(
16198 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
16199 {
16200 uint32_t instance = 0;
16201
16202 vty_out(vty, " redistribute %s",
16203 yang_dnode_get_string(dnode, "./route-type"));
16204 if ((instance = yang_dnode_get_uint16(dnode, "./route-instance")))
16205 vty_out(vty, " %d", instance);
16206 if (yang_dnode_exists(dnode, "./metric"))
16207 vty_out(vty, " metric %u",
16208 yang_dnode_get_uint32(dnode, "./metric"));
16209 if (yang_dnode_exists(dnode, "./rmap-policy-import"))
16210 vty_out(vty, " route-map %s",
16211 yang_dnode_get_string(dnode, "./rmap-policy-import"));
16212 vty_out(vty, "\n");
16213 }
16214
16215 static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
16216 afi_t afi, safi_t safi)
16217 {
16218 int i;
16219
16220 /* Unicast redistribution only. */
16221 if (safi != SAFI_UNICAST)
16222 return;
16223
16224 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
16225 /* Redistribute BGP does not make sense. */
16226 if (i != ZEBRA_ROUTE_BGP) {
16227 struct list *red_list;
16228 struct listnode *node;
16229 struct bgp_redist *red;
16230
16231 red_list = bgp->redist[afi][i];
16232 if (!red_list)
16233 continue;
16234
16235 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
16236 /* "redistribute" configuration. */
16237 vty_out(vty, " redistribute %s",
16238 zebra_route_string(i));
16239 if (red->instance)
16240 vty_out(vty, " %d", red->instance);
16241 if (red->redist_metric_flag)
16242 vty_out(vty, " metric %u",
16243 red->redist_metric);
16244 if (red->rmap.name)
16245 vty_out(vty, " route-map %s",
16246 red->rmap.name);
16247 vty_out(vty, "\n");
16248 }
16249 }
16250 }
16251 }
16252
16253 /* peer-group helpers for config-write */
16254
16255 static bool peergroup_flag_check(struct peer *peer, uint32_t flag)
16256 {
16257 if (!peer_group_active(peer)) {
16258 if (CHECK_FLAG(peer->flags_invert, flag))
16259 return !CHECK_FLAG(peer->flags, flag);
16260 else
16261 return !!CHECK_FLAG(peer->flags, flag);
16262 }
16263
16264 return !!CHECK_FLAG(peer->flags_override, flag);
16265 }
16266
16267 static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
16268 uint32_t flag)
16269 {
16270 if (!peer_group_active(peer)) {
16271 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
16272 return !peer_af_flag_check(peer, afi, safi, flag);
16273 else
16274 return !!peer_af_flag_check(peer, afi, safi, flag);
16275 }
16276
16277 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
16278 }
16279
16280 static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
16281 uint8_t type, int direct)
16282 {
16283 struct bgp_filter *filter;
16284
16285 if (peer_group_active(peer))
16286 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
16287 type);
16288
16289 filter = &peer->filter[afi][safi];
16290 switch (type) {
16291 case PEER_FT_DISTRIBUTE_LIST:
16292 return !!(filter->dlist[direct].name);
16293 case PEER_FT_FILTER_LIST:
16294 return !!(filter->aslist[direct].name);
16295 case PEER_FT_PREFIX_LIST:
16296 return !!(filter->plist[direct].name);
16297 case PEER_FT_ROUTE_MAP:
16298 return !!(filter->map[direct].name);
16299 case PEER_FT_UNSUPPRESS_MAP:
16300 return !!(filter->usmap.name);
16301 case PEER_FT_ADVERTISE_MAP:
16302 return !!(filter->advmap.aname
16303 && ((filter->advmap.condition == direct)
16304 && filter->advmap.cname));
16305 default:
16306 return false;
16307 }
16308 }
16309
16310 /* Return true if the addpath type is set for peer and different from
16311 * peer-group.
16312 */
16313 static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi,
16314 safi_t safi)
16315 {
16316 enum bgp_addpath_strat type, g_type;
16317
16318 type = peer->addpath_type[afi][safi];
16319
16320 if (type != BGP_ADDPATH_NONE) {
16321 if (peer_group_active(peer)) {
16322 g_type = peer->group->conf->addpath_type[afi][safi];
16323
16324 if (type != g_type)
16325 return true;
16326 else
16327 return false;
16328 }
16329
16330 return true;
16331 }
16332
16333 return false;
16334 }
16335
16336 /* This is part of the address-family block (unicast only) */
16337 static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
16338 afi_t afi)
16339 {
16340 int indent = 2;
16341
16342 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
16343 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16344 BGP_CONFIG_VRF_TO_VRF_IMPORT))
16345 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
16346 bgp->vpn_policy[afi]
16347 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16348 else
16349 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
16350 bgp->vpn_policy[afi]
16351 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16352 }
16353 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16354 BGP_CONFIG_VRF_TO_VRF_IMPORT)
16355 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16356 BGP_CONFIG_VRF_TO_VRF_EXPORT))
16357 return;
16358
16359 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16360 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
16361
16362 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
16363
16364 } else {
16365 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
16366 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
16367 bgp->vpn_policy[afi].tovpn_label);
16368 }
16369 }
16370 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16371 BGP_VPN_POLICY_TOVPN_RD_SET)) {
16372 char buf[RD_ADDRSTRLEN];
16373 vty_out(vty, "%*srd vpn export %s\n", indent, "",
16374 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
16375 sizeof(buf)));
16376 }
16377 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16378 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
16379
16380 char buf[PREFIX_STRLEN];
16381 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
16382 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
16383 sizeof(buf))) {
16384
16385 vty_out(vty, "%*snexthop vpn export %s\n",
16386 indent, "", buf);
16387 }
16388 }
16389 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
16390 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
16391 && ecommunity_cmp(
16392 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16393 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
16394
16395 char *b = ecommunity_ecom2str(
16396 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16397 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
16398 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
16399 XFREE(MTYPE_ECOMMUNITY_STR, b);
16400 } else {
16401 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
16402 char *b = ecommunity_ecom2str(
16403 bgp->vpn_policy[afi]
16404 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16405 ECOMMUNITY_FORMAT_ROUTE_MAP,
16406 ECOMMUNITY_ROUTE_TARGET);
16407 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
16408 XFREE(MTYPE_ECOMMUNITY_STR, b);
16409 }
16410 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
16411 char *b = ecommunity_ecom2str(
16412 bgp->vpn_policy[afi]
16413 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16414 ECOMMUNITY_FORMAT_ROUTE_MAP,
16415 ECOMMUNITY_ROUTE_TARGET);
16416 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
16417 XFREE(MTYPE_ECOMMUNITY_STR, b);
16418 }
16419 }
16420
16421 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
16422 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
16423 bgp->vpn_policy[afi]
16424 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
16425
16426 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
16427 char *b = ecommunity_ecom2str(
16428 bgp->vpn_policy[afi]
16429 .import_redirect_rtlist,
16430 ECOMMUNITY_FORMAT_ROUTE_MAP,
16431 ECOMMUNITY_ROUTE_TARGET);
16432
16433 if (bgp->vpn_policy[afi].import_redirect_rtlist->unit_size
16434 != ECOMMUNITY_SIZE)
16435 vty_out(vty, "%*srt6 redirect import %s\n",
16436 indent, "", b);
16437 else
16438 vty_out(vty, "%*srt redirect import %s\n",
16439 indent, "", b);
16440 XFREE(MTYPE_ECOMMUNITY_STR, b);
16441 }
16442 }
16443
16444 static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
16445 afi_t afi, safi_t safi)
16446 {
16447 struct bgp_filter *filter;
16448 char *addr;
16449
16450 addr = peer->host;
16451 filter = &peer->filter[afi][safi];
16452
16453 /* distribute-list. */
16454 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16455 FILTER_IN))
16456 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
16457 filter->dlist[FILTER_IN].name);
16458
16459 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16460 FILTER_OUT))
16461 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
16462 filter->dlist[FILTER_OUT].name);
16463
16464 /* prefix-list. */
16465 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16466 FILTER_IN))
16467 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
16468 filter->plist[FILTER_IN].name);
16469
16470 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16471 FILTER_OUT))
16472 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
16473 filter->plist[FILTER_OUT].name);
16474
16475 /* route-map. */
16476 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
16477 vty_out(vty, " neighbor %s route-map %s in\n", addr,
16478 filter->map[RMAP_IN].name);
16479
16480 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
16481 RMAP_OUT))
16482 vty_out(vty, " neighbor %s route-map %s out\n", addr,
16483 filter->map[RMAP_OUT].name);
16484
16485 /* unsuppress-map */
16486 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
16487 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
16488 filter->usmap.name);
16489
16490 /* advertise-map : always applied in OUT direction*/
16491 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16492 CONDITION_NON_EXIST))
16493 vty_out(vty,
16494 " neighbor %s advertise-map %s non-exist-map %s\n",
16495 addr, filter->advmap.aname, filter->advmap.cname);
16496
16497 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16498 CONDITION_EXIST))
16499 vty_out(vty, " neighbor %s advertise-map %s exist-map %s\n",
16500 addr, filter->advmap.aname, filter->advmap.cname);
16501
16502 /* filter-list. */
16503 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16504 FILTER_IN))
16505 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
16506 filter->aslist[FILTER_IN].name);
16507
16508 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16509 FILTER_OUT))
16510 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
16511 filter->aslist[FILTER_OUT].name);
16512 }
16513
16514 /* BGP peer configuration display function. */
16515 static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
16516 struct peer *peer)
16517 {
16518 struct peer *g_peer = NULL;
16519 char buf[SU_ADDRSTRLEN];
16520 char *addr;
16521 int if_pg_printed = false;
16522 int if_ras_printed = false;
16523
16524 /* Skip dynamic neighbors. */
16525 if (peer_dynamic_neighbor(peer))
16526 return;
16527
16528 if (peer->conf_if)
16529 addr = peer->conf_if;
16530 else
16531 addr = peer->host;
16532
16533 /************************************
16534 ****** Global to the neighbor ******
16535 ************************************/
16536 if (peer->conf_if) {
16537 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
16538 vty_out(vty, " neighbor %s interface v6only", addr);
16539 else
16540 vty_out(vty, " neighbor %s interface", addr);
16541
16542 if (peer_group_active(peer)) {
16543 vty_out(vty, " peer-group %s", peer->group->name);
16544 if_pg_printed = true;
16545 } else if (peer->as_type == AS_SPECIFIED) {
16546 vty_out(vty, " remote-as %u", peer->as);
16547 if_ras_printed = true;
16548 } else if (peer->as_type == AS_INTERNAL) {
16549 vty_out(vty, " remote-as internal");
16550 if_ras_printed = true;
16551 } else if (peer->as_type == AS_EXTERNAL) {
16552 vty_out(vty, " remote-as external");
16553 if_ras_printed = true;
16554 }
16555
16556 vty_out(vty, "\n");
16557 }
16558
16559 /* remote-as and peer-group */
16560 /* peer is a member of a peer-group */
16561 if (peer_group_active(peer)) {
16562 g_peer = peer->group->conf;
16563
16564 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
16565 if (peer->as_type == AS_SPECIFIED) {
16566 vty_out(vty, " neighbor %s remote-as %u\n",
16567 addr, peer->as);
16568 } else if (peer->as_type == AS_INTERNAL) {
16569 vty_out(vty,
16570 " neighbor %s remote-as internal\n",
16571 addr);
16572 } else if (peer->as_type == AS_EXTERNAL) {
16573 vty_out(vty,
16574 " neighbor %s remote-as external\n",
16575 addr);
16576 }
16577 }
16578
16579 /* For swpX peers we displayed the peer-group
16580 * via 'neighbor swpX interface peer-group PGNAME' */
16581 if (!if_pg_printed)
16582 vty_out(vty, " neighbor %s peer-group %s\n", addr,
16583 peer->group->name);
16584 }
16585
16586 /* peer is NOT a member of a peer-group */
16587 else {
16588 /* peer is a peer-group, declare the peer-group */
16589 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
16590 vty_out(vty, " neighbor %s peer-group\n", addr);
16591 }
16592
16593 if (!if_ras_printed) {
16594 if (peer->as_type == AS_SPECIFIED) {
16595 vty_out(vty, " neighbor %s remote-as %u\n",
16596 addr, peer->as);
16597 } else if (peer->as_type == AS_INTERNAL) {
16598 vty_out(vty,
16599 " neighbor %s remote-as internal\n",
16600 addr);
16601 } else if (peer->as_type == AS_EXTERNAL) {
16602 vty_out(vty,
16603 " neighbor %s remote-as external\n",
16604 addr);
16605 }
16606 }
16607 }
16608
16609 /* local-as */
16610 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
16611 vty_out(vty, " neighbor %s local-as %u", addr,
16612 peer->change_local_as);
16613 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
16614 vty_out(vty, " no-prepend");
16615 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
16616 vty_out(vty, " replace-as");
16617 vty_out(vty, "\n");
16618 }
16619
16620 /* description */
16621 if (peer->desc) {
16622 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
16623 }
16624
16625 /* shutdown */
16626 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
16627 if (peer->tx_shutdown_message)
16628 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
16629 peer->tx_shutdown_message);
16630 else
16631 vty_out(vty, " neighbor %s shutdown\n", addr);
16632 }
16633
16634 if (peergroup_flag_check(peer, PEER_FLAG_RTT_SHUTDOWN))
16635 vty_out(vty, " neighbor %s shutdown rtt %u count %u\n", addr,
16636 peer->rtt_expected, peer->rtt_keepalive_conf);
16637
16638 /* bfd */
16639 if (peer->bfd_info) {
16640 if (!peer_group_active(peer) || !g_peer->bfd_info) {
16641 bgp_bfd_peer_config_write(vty, peer, addr);
16642 }
16643 }
16644
16645 /* password */
16646 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
16647 vty_out(vty, " neighbor %s password %s\n", addr,
16648 peer->password);
16649
16650 /* neighbor solo */
16651 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
16652 if (!peer_group_active(peer)) {
16653 vty_out(vty, " neighbor %s solo\n", addr);
16654 }
16655 }
16656
16657 /* BGP port */
16658 if (peer->port != BGP_PORT_DEFAULT) {
16659 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
16660 }
16661
16662 /* Local interface name */
16663 if (peer->ifname) {
16664 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
16665 }
16666
16667 /* passive */
16668 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
16669 vty_out(vty, " neighbor %s passive\n", addr);
16670
16671 /* ebgp-multihop */
16672 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
16673 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
16674 && peer->ttl == MAXTTL)) {
16675 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
16676 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
16677 peer->ttl);
16678 }
16679 }
16680
16681 /* ttl-security hops */
16682 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
16683 if (!peer_group_active(peer)
16684 || g_peer->gtsm_hops != peer->gtsm_hops) {
16685 vty_out(vty, " neighbor %s ttl-security hops %d\n",
16686 addr, peer->gtsm_hops);
16687 }
16688 }
16689
16690 /* disable-connected-check */
16691 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
16692 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
16693
16694 /* enforce-first-as */
16695 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
16696 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
16697
16698 /* update-source */
16699 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
16700 if (peer->update_source)
16701 vty_out(vty, " neighbor %s update-source %s\n", addr,
16702 sockunion2str(peer->update_source, buf,
16703 SU_ADDRSTRLEN));
16704 else if (peer->update_if)
16705 vty_out(vty, " neighbor %s update-source %s\n", addr,
16706 peer->update_if);
16707 }
16708
16709 /* advertisement-interval */
16710 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
16711 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
16712 peer->routeadv);
16713
16714 /* timers */
16715 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
16716 vty_out(vty, " neighbor %s timers %u %u\n", addr,
16717 peer->keepalive, peer->holdtime);
16718
16719 /* timers connect */
16720 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
16721 vty_out(vty, " neighbor %s timers connect %u\n", addr,
16722 peer->connect);
16723 /* need special-case handling for changed default values due to
16724 * config profile / version (because there is no "timers bgp connect"
16725 * command, we need to save this per-peer :/)
16726 */
16727 else if (!peer_group_active(peer) && !peer->connect &&
16728 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
16729 vty_out(vty, " neighbor %s timers connect %u\n", addr,
16730 peer->bgp->default_connect_retry);
16731
16732 /* timers delayopen */
16733 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_DELAYOPEN))
16734 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
16735 peer->delayopen);
16736 /* Save config even though flag is not set if default values have been
16737 * changed
16738 */
16739 else if (!peer_group_active(peer) && !peer->delayopen
16740 && peer->bgp->default_delayopen != BGP_DEFAULT_DELAYOPEN)
16741 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
16742 peer->bgp->default_delayopen);
16743
16744 /* capability dynamic */
16745 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
16746 vty_out(vty, " neighbor %s capability dynamic\n", addr);
16747
16748 /* capability extended-nexthop */
16749 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
16750 if (!peer->conf_if) {
16751 if (CHECK_FLAG(peer->flags_invert,
16752 PEER_FLAG_CAPABILITY_ENHE))
16753 vty_out(vty,
16754 " no neighbor %s capability extended-nexthop\n",
16755 addr);
16756 else
16757 vty_out(vty,
16758 " neighbor %s capability extended-nexthop\n",
16759 addr);
16760 }
16761 }
16762
16763 /* dont-capability-negotiation */
16764 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
16765 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
16766
16767 /* override-capability */
16768 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
16769 vty_out(vty, " neighbor %s override-capability\n", addr);
16770
16771 /* strict-capability-match */
16772 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
16773 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
16774
16775 /* Sender side AS path loop detection. */
16776 if (peer->as_path_loop_detection)
16777 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
16778 addr);
16779
16780 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
16781 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
16782
16783 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
16784 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
16785 vty_out(vty,
16786 " neighbor %s graceful-restart-helper\n", addr);
16787 } else if (CHECK_FLAG(
16788 peer->peer_gr_new_status_flag,
16789 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
16790 vty_out(vty,
16791 " neighbor %s graceful-restart\n", addr);
16792 } else if (
16793 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
16794 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
16795 && !(CHECK_FLAG(
16796 peer->peer_gr_new_status_flag,
16797 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
16798 vty_out(vty, " neighbor %s graceful-restart-disable\n",
16799 addr);
16800 }
16801 }
16802 }
16803
16804 /* BGP peer configuration display function. */
16805 static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
16806 struct peer *peer, afi_t afi, safi_t safi)
16807 {
16808 struct peer *g_peer = NULL;
16809 char *addr;
16810 bool flag_scomm, flag_secomm, flag_slcomm;
16811
16812 /* Skip dynamic neighbors. */
16813 if (peer_dynamic_neighbor(peer))
16814 return;
16815
16816 if (peer->conf_if)
16817 addr = peer->conf_if;
16818 else
16819 addr = peer->host;
16820
16821 /************************************
16822 ****** Per AF to the neighbor ******
16823 ************************************/
16824 if (peer_group_active(peer)) {
16825 g_peer = peer->group->conf;
16826
16827 /* If the peer-group is active but peer is not, print a 'no
16828 * activate' */
16829 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
16830 vty_out(vty, " no neighbor %s activate\n", addr);
16831 }
16832
16833 /* If the peer-group is not active but peer is, print an
16834 'activate' */
16835 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
16836 vty_out(vty, " neighbor %s activate\n", addr);
16837 }
16838 } else {
16839 if (peer->afc[afi][safi]) {
16840 if ((afi == AFI_IP) && (safi == SAFI_UNICAST)) {
16841 if (CHECK_FLAG(bgp->flags,
16842 BGP_FLAG_NO_DEFAULT_IPV4)) {
16843 vty_out(vty, " neighbor %s activate\n",
16844 addr);
16845 }
16846 } else
16847 vty_out(vty, " neighbor %s activate\n", addr);
16848 } else {
16849 if ((afi == AFI_IP) && (safi == SAFI_UNICAST)) {
16850 if (!CHECK_FLAG(bgp->flags,
16851 BGP_FLAG_NO_DEFAULT_IPV4)) {
16852 vty_out(vty,
16853 " no neighbor %s activate\n",
16854 addr);
16855 }
16856 }
16857 }
16858 }
16859
16860 /* addpath TX knobs */
16861 if (peergroup_af_addpath_check(peer, afi, safi)) {
16862 switch (peer->addpath_type[afi][safi]) {
16863 case BGP_ADDPATH_ALL:
16864 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
16865 addr);
16866 break;
16867 case BGP_ADDPATH_BEST_PER_AS:
16868 vty_out(vty,
16869 " neighbor %s addpath-tx-bestpath-per-AS\n",
16870 addr);
16871 break;
16872 case BGP_ADDPATH_MAX:
16873 case BGP_ADDPATH_NONE:
16874 break;
16875 }
16876 }
16877
16878 /* ORF capability. */
16879 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
16880 || peergroup_af_flag_check(peer, afi, safi,
16881 PEER_FLAG_ORF_PREFIX_RM)) {
16882 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
16883
16884 if (peergroup_af_flag_check(peer, afi, safi,
16885 PEER_FLAG_ORF_PREFIX_SM)
16886 && peergroup_af_flag_check(peer, afi, safi,
16887 PEER_FLAG_ORF_PREFIX_RM))
16888 vty_out(vty, " both");
16889 else if (peergroup_af_flag_check(peer, afi, safi,
16890 PEER_FLAG_ORF_PREFIX_SM))
16891 vty_out(vty, " send");
16892 else
16893 vty_out(vty, " receive");
16894 vty_out(vty, "\n");
16895 }
16896
16897 /* Route reflector client. */
16898 if (peergroup_af_flag_check(peer, afi, safi,
16899 PEER_FLAG_REFLECTOR_CLIENT)) {
16900 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
16901 }
16902
16903 /* next-hop-self force */
16904 if (peergroup_af_flag_check(peer, afi, safi,
16905 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
16906 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
16907 }
16908
16909 /* next-hop-self */
16910 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
16911 vty_out(vty, " neighbor %s next-hop-self\n", addr);
16912 }
16913
16914 /* remove-private-AS */
16915 if (peergroup_af_flag_check(peer, afi, safi,
16916 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
16917 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
16918 addr);
16919 }
16920
16921 else if (peergroup_af_flag_check(peer, afi, safi,
16922 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
16923 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
16924 addr);
16925 }
16926
16927 else if (peergroup_af_flag_check(peer, afi, safi,
16928 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
16929 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
16930 }
16931
16932 else if (peergroup_af_flag_check(peer, afi, safi,
16933 PEER_FLAG_REMOVE_PRIVATE_AS)) {
16934 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
16935 }
16936
16937 /* as-override */
16938 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
16939 vty_out(vty, " neighbor %s as-override\n", addr);
16940 }
16941
16942 /* send-community print. */
16943 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
16944 PEER_FLAG_SEND_COMMUNITY);
16945 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
16946 PEER_FLAG_SEND_EXT_COMMUNITY);
16947 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
16948 PEER_FLAG_SEND_LARGE_COMMUNITY);
16949
16950 if (flag_scomm && flag_secomm && flag_slcomm) {
16951 vty_out(vty, " no neighbor %s send-community all\n", addr);
16952 } else {
16953 if (flag_scomm)
16954 vty_out(vty, " no neighbor %s send-community\n", addr);
16955 if (flag_secomm)
16956 vty_out(vty,
16957 " no neighbor %s send-community extended\n",
16958 addr);
16959
16960 if (flag_slcomm)
16961 vty_out(vty, " no neighbor %s send-community large\n",
16962 addr);
16963 }
16964
16965 /* Default information */
16966 if (peergroup_af_flag_check(peer, afi, safi,
16967 PEER_FLAG_DEFAULT_ORIGINATE)) {
16968 vty_out(vty, " neighbor %s default-originate", addr);
16969
16970 if (peer->default_rmap[afi][safi].name)
16971 vty_out(vty, " route-map %s",
16972 peer->default_rmap[afi][safi].name);
16973
16974 vty_out(vty, "\n");
16975 }
16976
16977 /* Soft reconfiguration inbound. */
16978 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
16979 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
16980 addr);
16981 }
16982
16983 /* maximum-prefix. */
16984 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
16985 vty_out(vty, " neighbor %s maximum-prefix %u", addr,
16986 peer->pmax[afi][safi]);
16987
16988 if (peer->pmax_threshold[afi][safi]
16989 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
16990 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
16991 if (peer_af_flag_check(peer, afi, safi,
16992 PEER_FLAG_MAX_PREFIX_WARNING))
16993 vty_out(vty, " warning-only");
16994 if (peer->pmax_restart[afi][safi])
16995 vty_out(vty, " restart %u",
16996 peer->pmax_restart[afi][safi]);
16997 if (peer_af_flag_check(peer, afi, safi,
16998 PEER_FLAG_MAX_PREFIX_FORCE))
16999 vty_out(vty, " force");
17000
17001 vty_out(vty, "\n");
17002 }
17003
17004 /* maximum-prefix-out */
17005 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
17006 vty_out(vty, " neighbor %s maximum-prefix-out %u\n",
17007 addr, peer->pmax_out[afi][safi]);
17008
17009 /* Route server client. */
17010 if (peergroup_af_flag_check(peer, afi, safi,
17011 PEER_FLAG_RSERVER_CLIENT)) {
17012 vty_out(vty, " neighbor %s route-server-client\n", addr);
17013 }
17014
17015 /* Nexthop-local unchanged. */
17016 if (peergroup_af_flag_check(peer, afi, safi,
17017 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
17018 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
17019 }
17020
17021 /* allowas-in <1-10> */
17022 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
17023 if (peer_af_flag_check(peer, afi, safi,
17024 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
17025 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
17026 } else if (peer->allowas_in[afi][safi] == 3) {
17027 vty_out(vty, " neighbor %s allowas-in\n", addr);
17028 } else {
17029 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
17030 peer->allowas_in[afi][safi]);
17031 }
17032 }
17033
17034 /* weight */
17035 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
17036 vty_out(vty, " neighbor %s weight %lu\n", addr,
17037 peer->weight[afi][safi]);
17038
17039 /* Filter. */
17040 bgp_config_write_filter(vty, peer, afi, safi);
17041
17042 /* atribute-unchanged. */
17043 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
17044 || (safi != SAFI_EVPN
17045 && peer_af_flag_check(peer, afi, safi,
17046 PEER_FLAG_NEXTHOP_UNCHANGED))
17047 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
17048
17049 if (!peer_group_active(peer)
17050 || peergroup_af_flag_check(peer, afi, safi,
17051 PEER_FLAG_AS_PATH_UNCHANGED)
17052 || peergroup_af_flag_check(peer, afi, safi,
17053 PEER_FLAG_NEXTHOP_UNCHANGED)
17054 || peergroup_af_flag_check(peer, afi, safi,
17055 PEER_FLAG_MED_UNCHANGED)) {
17056
17057 vty_out(vty,
17058 " neighbor %s attribute-unchanged%s%s%s\n",
17059 addr,
17060 peer_af_flag_check(peer, afi, safi,
17061 PEER_FLAG_AS_PATH_UNCHANGED)
17062 ? " as-path"
17063 : "",
17064 peer_af_flag_check(peer, afi, safi,
17065 PEER_FLAG_NEXTHOP_UNCHANGED)
17066 ? " next-hop"
17067 : "",
17068 peer_af_flag_check(peer, afi, safi,
17069 PEER_FLAG_MED_UNCHANGED)
17070 ? " med"
17071 : "");
17072 }
17073 }
17074 }
17075
17076 /* Address family based peer configuration display. */
17077 static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
17078 safi_t safi)
17079 {
17080 struct peer *peer;
17081 struct peer_group *group;
17082 struct listnode *node, *nnode;
17083
17084
17085 vty_frame(vty, " !\n address-family ");
17086 if (afi == AFI_IP) {
17087 if (safi == SAFI_UNICAST)
17088 vty_frame(vty, "ipv4 unicast");
17089 else if (safi == SAFI_LABELED_UNICAST)
17090 vty_frame(vty, "ipv4 labeled-unicast");
17091 else if (safi == SAFI_MULTICAST)
17092 vty_frame(vty, "ipv4 multicast");
17093 else if (safi == SAFI_MPLS_VPN)
17094 vty_frame(vty, "ipv4 vpn");
17095 else if (safi == SAFI_ENCAP)
17096 vty_frame(vty, "ipv4 encap");
17097 else if (safi == SAFI_FLOWSPEC)
17098 vty_frame(vty, "ipv4 flowspec");
17099 } else if (afi == AFI_IP6) {
17100 if (safi == SAFI_UNICAST)
17101 vty_frame(vty, "ipv6 unicast");
17102 else if (safi == SAFI_LABELED_UNICAST)
17103 vty_frame(vty, "ipv6 labeled-unicast");
17104 else if (safi == SAFI_MULTICAST)
17105 vty_frame(vty, "ipv6 multicast");
17106 else if (safi == SAFI_MPLS_VPN)
17107 vty_frame(vty, "ipv6 vpn");
17108 else if (safi == SAFI_ENCAP)
17109 vty_frame(vty, "ipv6 encap");
17110 else if (safi == SAFI_FLOWSPEC)
17111 vty_frame(vty, "ipv6 flowspec");
17112 } else if (afi == AFI_L2VPN) {
17113 if (safi == SAFI_EVPN)
17114 vty_frame(vty, "l2vpn evpn");
17115 }
17116 vty_frame(vty, "\n");
17117
17118 bgp_config_write_distance(vty, bgp, afi, safi);
17119
17120 bgp_config_write_network(vty, bgp, afi, safi);
17121
17122 bgp_config_write_redistribute(vty, bgp, afi, safi);
17123
17124 /* BGP flag dampening. */
17125 if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
17126 bgp_config_write_damp(vty, bgp, afi, safi);
17127 for (ALL_LIST_ELEMENTS_RO(bgp->group, node, group))
17128 if (peer_af_flag_check(group->conf, afi, safi,
17129 PEER_FLAG_CONFIG_DAMPENING))
17130 bgp_config_write_peer_damp(vty, group->conf, afi, safi);
17131 for (ALL_LIST_ELEMENTS_RO(bgp->peer, node, peer))
17132 if (peer_af_flag_check(peer, afi, safi,
17133 PEER_FLAG_CONFIG_DAMPENING))
17134 bgp_config_write_peer_damp(vty, peer, afi, safi);
17135
17136 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
17137 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
17138
17139 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17140 /* Skip dynamic neighbors. */
17141 if (peer_dynamic_neighbor(peer))
17142 continue;
17143
17144 /* Do not display doppelganger peers */
17145 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17146 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
17147 }
17148
17149 bgp_config_write_maxpaths(vty, bgp, afi, safi);
17150 bgp_config_write_table_map(vty, bgp, afi, safi);
17151
17152 if (safi == SAFI_EVPN)
17153 bgp_config_write_evpn_info(vty, bgp, afi, safi);
17154
17155 if (safi == SAFI_FLOWSPEC)
17156 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
17157
17158 if (safi == SAFI_UNICAST) {
17159 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
17160 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17161 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
17162
17163 vty_out(vty, " export vpn\n");
17164 }
17165 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17166 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
17167
17168 vty_out(vty, " import vpn\n");
17169 }
17170 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17171 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
17172 char *name;
17173
17174 for (ALL_LIST_ELEMENTS_RO(
17175 bgp->vpn_policy[afi].import_vrf, node,
17176 name))
17177 vty_out(vty, " import vrf %s\n", name);
17178 }
17179 }
17180
17181 vty_endframe(vty, " exit-address-family\n");
17182 }
17183
17184 int bgp_config_write(struct vty *vty)
17185 {
17186 struct bgp *bgp;
17187 struct peer_group *group;
17188 struct peer *peer;
17189 struct listnode *node, *nnode;
17190 struct listnode *mnode, *mnnode;
17191
17192 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
17193 vty_out(vty, "bgp route-map delay-timer %u\n",
17194 bm->rmap_update_timer);
17195
17196 if (bm->v_update_delay != BGP_UPDATE_DELAY_DEF) {
17197 vty_out(vty, "bgp update-delay %d", bm->v_update_delay);
17198 if (bm->v_update_delay != bm->v_establish_wait)
17199 vty_out(vty, " %d", bm->v_establish_wait);
17200 vty_out(vty, "\n");
17201 }
17202
17203 if (bm->wait_for_fib)
17204 vty_out(vty, "bgp suppress-fib-pending\n");
17205
17206 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17207 vty_out(vty, "bgp graceful-shutdown\n");
17208
17209 /* No-RIB (Zebra) option flag configuration */
17210 if (bgp_option_check(BGP_OPT_NO_FIB))
17211 vty_out(vty, "bgp no-rib\n");
17212
17213 if (!CHECK_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA))
17214 vty_out(vty, "no bgp send-extra-data zebra\n");
17215
17216 /* BGP configuration. */
17217 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
17218
17219 /* skip all auto created vrf as they dont have user config */
17220 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
17221 continue;
17222
17223 /* Router bgp ASN */
17224 vty_out(vty, "router bgp %u", bgp->as);
17225
17226 if (bgp->name)
17227 vty_out(vty, " %s %s",
17228 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
17229 ? "view" : "vrf", bgp->name);
17230 vty_out(vty, "\n");
17231
17232 /* BGP fast-external-failover. */
17233 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
17234 vty_out(vty, " no bgp fast-external-failover\n");
17235
17236 /* BGP router ID. */
17237 if (bgp->router_id_static.s_addr != INADDR_ANY)
17238 vty_out(vty, " bgp router-id %pI4\n",
17239 &bgp->router_id_static);
17240
17241 /* Suppress fib pending */
17242 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_FIB_PENDING))
17243 vty_out(vty, " bgp suppress-fib-pending\n");
17244
17245 /* BGP log-neighbor-changes. */
17246 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
17247 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
17248 vty_out(vty, " %sbgp log-neighbor-changes\n",
17249 CHECK_FLAG(bgp->flags,
17250 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
17251 ? ""
17252 : "no ");
17253
17254 /* BGP configuration. */
17255 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
17256 vty_out(vty, " bgp always-compare-med\n");
17257
17258 /* RFC8212 default eBGP policy. */
17259 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
17260 != SAVE_BGP_EBGP_REQUIRES_POLICY)
17261 vty_out(vty, " %sbgp ebgp-requires-policy\n",
17262 CHECK_FLAG(bgp->flags,
17263 BGP_FLAG_EBGP_REQUIRES_POLICY)
17264 ? ""
17265 : "no ");
17266
17267 /* draft-ietf-idr-deprecate-as-set-confed-set */
17268 if (bgp->reject_as_sets)
17269 vty_out(vty, " bgp reject-as-sets\n");
17270
17271 /* Suppress duplicate updates if the route actually not changed
17272 */
17273 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES)
17274 != SAVE_BGP_SUPPRESS_DUPLICATES)
17275 vty_out(vty, " %sbgp suppress-duplicates\n",
17276 CHECK_FLAG(bgp->flags,
17277 BGP_FLAG_SUPPRESS_DUPLICATES)
17278 ? ""
17279 : "no ");
17280
17281 /* BGP default ipv4-unicast. */
17282 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4))
17283 vty_out(vty, " no bgp default ipv4-unicast\n");
17284
17285 /* BGP default local-preference. */
17286 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
17287 vty_out(vty, " bgp default local-preference %u\n",
17288 bgp->default_local_pref);
17289
17290 /* BGP default show-hostname */
17291 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
17292 != SAVE_BGP_SHOW_HOSTNAME)
17293 vty_out(vty, " %sbgp default show-hostname\n",
17294 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
17295 ? ""
17296 : "no ");
17297
17298 /* BGP default show-nexthop-hostname */
17299 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17300 != SAVE_BGP_SHOW_HOSTNAME)
17301 vty_out(vty, " %sbgp default show-nexthop-hostname\n",
17302 CHECK_FLAG(bgp->flags,
17303 BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17304 ? ""
17305 : "no ");
17306
17307 /* BGP default subgroup-pkt-queue-max. */
17308 if (bgp->default_subgroup_pkt_queue_max
17309 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
17310 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
17311 bgp->default_subgroup_pkt_queue_max);
17312
17313 /* BGP client-to-client reflection. */
17314 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
17315 vty_out(vty, " no bgp client-to-client reflection\n");
17316
17317 /* BGP cluster ID. */
17318 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
17319 vty_out(vty, " bgp cluster-id %pI4\n",
17320 &bgp->cluster_id);
17321
17322 /* Disable ebgp connected nexthop check */
17323 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
17324 vty_out(vty,
17325 " bgp disable-ebgp-connected-route-check\n");
17326
17327 /* Confederation identifier*/
17328 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
17329 vty_out(vty, " bgp confederation identifier %u\n",
17330 bgp->confed_id);
17331
17332 /* Confederation peer */
17333 if (bgp->confed_peers_cnt > 0) {
17334 int i;
17335
17336 vty_out(vty, " bgp confederation peers");
17337
17338 for (i = 0; i < bgp->confed_peers_cnt; i++)
17339 vty_out(vty, " %u", bgp->confed_peers[i]);
17340
17341 vty_out(vty, "\n");
17342 }
17343
17344 /* BGP deterministic-med. */
17345 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
17346 != SAVE_BGP_DETERMINISTIC_MED)
17347 vty_out(vty, " %sbgp deterministic-med\n",
17348 CHECK_FLAG(bgp->flags,
17349 BGP_FLAG_DETERMINISTIC_MED)
17350 ? ""
17351 : "no ");
17352
17353 /* BGP update-delay. */
17354 bgp_config_write_update_delay(vty, bgp);
17355
17356 if (bgp->v_maxmed_onstartup
17357 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
17358 vty_out(vty, " bgp max-med on-startup %u",
17359 bgp->v_maxmed_onstartup);
17360 if (bgp->maxmed_onstartup_value
17361 != BGP_MAXMED_VALUE_DEFAULT)
17362 vty_out(vty, " %u",
17363 bgp->maxmed_onstartup_value);
17364 vty_out(vty, "\n");
17365 }
17366 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
17367 vty_out(vty, " bgp max-med administrative");
17368 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
17369 vty_out(vty, " %u", bgp->maxmed_admin_value);
17370 vty_out(vty, "\n");
17371 }
17372
17373 /* write quanta */
17374 bgp_config_write_wpkt_quanta(vty, bgp);
17375 /* read quanta */
17376 bgp_config_write_rpkt_quanta(vty, bgp);
17377
17378 /* coalesce time */
17379 bgp_config_write_coalesce_time(vty, bgp);
17380
17381 /* BGP per-instance graceful-shutdown */
17382 /* BGP-wide settings and per-instance settings are mutually
17383 * exclusive.
17384 */
17385 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17386 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
17387 vty_out(vty, " bgp graceful-shutdown\n");
17388
17389 /* BGP graceful-restart. */
17390 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
17391 vty_out(vty,
17392 " bgp graceful-restart stalepath-time %u\n",
17393 bgp->stalepath_time);
17394
17395 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
17396 vty_out(vty, " bgp graceful-restart restart-time %u\n",
17397 bgp->restart_time);
17398
17399 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
17400 vty_out(vty,
17401 " bgp graceful-restart select-defer-time %u\n",
17402 bgp->select_defer_time);
17403
17404 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
17405 vty_out(vty, " bgp graceful-restart\n");
17406
17407 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
17408 vty_out(vty, " bgp graceful-restart-disable\n");
17409
17410 /* BGP graceful-restart Preserve State F bit. */
17411 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
17412 vty_out(vty,
17413 " bgp graceful-restart preserve-fw-state\n");
17414
17415 /* Stale timer for RIB */
17416 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
17417 vty_out(vty,
17418 " bgp graceful-restart rib-stale-time %u\n",
17419 bgp->rib_stale_time);
17420
17421 /* BGP bestpath method. */
17422 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
17423 vty_out(vty, " bgp bestpath as-path ignore\n");
17424 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
17425 vty_out(vty, " bgp bestpath as-path confed\n");
17426
17427 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
17428 if (CHECK_FLAG(bgp->flags,
17429 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
17430 vty_out(vty,
17431 " bgp bestpath as-path multipath-relax as-set\n");
17432 } else {
17433 vty_out(vty,
17434 " bgp bestpath as-path multipath-relax\n");
17435 }
17436 }
17437
17438 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
17439 vty_out(vty,
17440 " bgp route-reflector allow-outbound-policy\n");
17441 }
17442 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
17443 vty_out(vty, " bgp bestpath compare-routerid\n");
17444 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
17445 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
17446 vty_out(vty, " bgp bestpath med");
17447 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
17448 vty_out(vty, " confed");
17449 if (CHECK_FLAG(bgp->flags,
17450 BGP_FLAG_MED_MISSING_AS_WORST))
17451 vty_out(vty, " missing-as-worst");
17452 vty_out(vty, "\n");
17453 }
17454
17455 /* Link bandwidth handling. */
17456 if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW)
17457 vty_out(vty, " bgp bestpath bandwidth ignore\n");
17458 else if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
17459 vty_out(vty, " bgp bestpath bandwidth skip-missing\n");
17460 else if (bgp->lb_handling == BGP_LINK_BW_DEFWT_4_MISSING)
17461 vty_out(vty, " bgp bestpath bandwidth default-weight-for-missing\n");
17462
17463 /* BGP network import check. */
17464 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
17465 != SAVE_BGP_IMPORT_CHECK)
17466 vty_out(vty, " %sbgp network import-check\n",
17467 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
17468 ? ""
17469 : "no ");
17470
17471 /* BGP timers configuration. */
17472 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
17473 && bgp->default_holdtime != SAVE_BGP_HOLDTIME)
17474 vty_out(vty, " timers bgp %u %u\n",
17475 bgp->default_keepalive, bgp->default_holdtime);
17476
17477 /* peer-group */
17478 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
17479 bgp_config_write_peer_global(vty, bgp, group->conf);
17480 }
17481
17482 /* Normal neighbor configuration. */
17483 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17484 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17485 bgp_config_write_peer_global(vty, bgp, peer);
17486 }
17487
17488 /* listen range and limit for dynamic BGP neighbors */
17489 bgp_config_write_listen(vty, bgp);
17490
17491 /*
17492 * BGP default autoshutdown neighbors
17493 *
17494 * This must be placed after any peer and peer-group
17495 * configuration, to avoid setting all peers to shutdown after
17496 * a daemon restart, which is undesired behavior. (see #2286)
17497 */
17498 if (bgp->autoshutdown)
17499 vty_out(vty, " bgp default shutdown\n");
17500
17501 /* BGP instance administrative shutdown */
17502 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN))
17503 vty_out(vty, " bgp shutdown\n");
17504
17505 /* IPv4 unicast configuration. */
17506 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
17507
17508 /* IPv4 multicast configuration. */
17509 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
17510
17511 /* IPv4 labeled-unicast configuration. */
17512 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
17513
17514 /* IPv4 VPN configuration. */
17515 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
17516
17517 /* ENCAPv4 configuration. */
17518 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
17519
17520 /* FLOWSPEC v4 configuration. */
17521 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
17522
17523 /* IPv6 unicast configuration. */
17524 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
17525
17526 /* IPv6 multicast configuration. */
17527 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
17528
17529 /* IPv6 labeled-unicast configuration. */
17530 bgp_config_write_family(vty, bgp, AFI_IP6,
17531 SAFI_LABELED_UNICAST);
17532
17533 /* IPv6 VPN configuration. */
17534 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
17535
17536 /* ENCAPv6 configuration. */
17537 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
17538
17539 /* FLOWSPEC v6 configuration. */
17540 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
17541
17542 /* EVPN configuration. */
17543 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
17544
17545 hook_call(bgp_inst_config_write, bgp, vty);
17546
17547 #ifdef ENABLE_BGP_VNC
17548 bgp_rfapi_cfg_write(vty, bgp);
17549 #endif
17550
17551 vty_out(vty, "!\n");
17552 }
17553 return 0;
17554 }
17555
17556
17557 /* BGP node structure. */
17558 static struct cmd_node bgp_node = {
17559 .name = "bgp",
17560 .node = BGP_NODE,
17561 .parent_node = CONFIG_NODE,
17562 .prompt = "%s(config-router)# ",
17563 .config_write = bgp_config_write,
17564 };
17565
17566 static struct cmd_node bgp_ipv4_unicast_node = {
17567 .name = "bgp ipv4 unicast",
17568 .node = BGP_IPV4_NODE,
17569 .parent_node = BGP_NODE,
17570 .prompt = "%s(config-router-af)# ",
17571 };
17572
17573 static struct cmd_node bgp_ipv4_multicast_node = {
17574 .name = "bgp ipv4 multicast",
17575 .node = BGP_IPV4M_NODE,
17576 .parent_node = BGP_NODE,
17577 .prompt = "%s(config-router-af)# ",
17578 };
17579
17580 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
17581 .name = "bgp ipv4 labeled unicast",
17582 .node = BGP_IPV4L_NODE,
17583 .parent_node = BGP_NODE,
17584 .prompt = "%s(config-router-af)# ",
17585 };
17586
17587 static struct cmd_node bgp_ipv6_unicast_node = {
17588 .name = "bgp ipv6",
17589 .node = BGP_IPV6_NODE,
17590 .parent_node = BGP_NODE,
17591 .prompt = "%s(config-router-af)# ",
17592 };
17593
17594 static struct cmd_node bgp_ipv6_multicast_node = {
17595 .name = "bgp ipv6 multicast",
17596 .node = BGP_IPV6M_NODE,
17597 .parent_node = BGP_NODE,
17598 .prompt = "%s(config-router-af)# ",
17599 };
17600
17601 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
17602 .name = "bgp ipv6 labeled unicast",
17603 .node = BGP_IPV6L_NODE,
17604 .parent_node = BGP_NODE,
17605 .prompt = "%s(config-router-af)# ",
17606 };
17607
17608 static struct cmd_node bgp_vpnv4_node = {
17609 .name = "bgp vpnv4",
17610 .node = BGP_VPNV4_NODE,
17611 .parent_node = BGP_NODE,
17612 .prompt = "%s(config-router-af)# ",
17613 };
17614
17615 static struct cmd_node bgp_vpnv6_node = {
17616 .name = "bgp vpnv6",
17617 .node = BGP_VPNV6_NODE,
17618 .parent_node = BGP_NODE,
17619 .prompt = "%s(config-router-af-vpnv6)# ",
17620 };
17621
17622 static struct cmd_node bgp_evpn_node = {
17623 .name = "bgp evpn",
17624 .node = BGP_EVPN_NODE,
17625 .parent_node = BGP_NODE,
17626 .prompt = "%s(config-router-evpn)# ",
17627 };
17628
17629 static struct cmd_node bgp_evpn_vni_node = {
17630 .name = "bgp evpn vni",
17631 .node = BGP_EVPN_VNI_NODE,
17632 .parent_node = BGP_EVPN_NODE,
17633 .prompt = "%s(config-router-af-vni)# ",
17634 };
17635
17636 static struct cmd_node bgp_flowspecv4_node = {
17637 .name = "bgp ipv4 flowspec",
17638 .node = BGP_FLOWSPECV4_NODE,
17639 .parent_node = BGP_NODE,
17640 .prompt = "%s(config-router-af)# ",
17641 };
17642
17643 static struct cmd_node bgp_flowspecv6_node = {
17644 .name = "bgp ipv6 flowspec",
17645 .node = BGP_FLOWSPECV6_NODE,
17646 .parent_node = BGP_NODE,
17647 .prompt = "%s(config-router-af-vpnv6)# ",
17648 };
17649
17650 static void community_list_vty(void);
17651
17652 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
17653 {
17654 struct bgp *bgp;
17655 struct peer *peer;
17656 struct listnode *lnbgp, *lnpeer;
17657
17658 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
17659 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
17660 /* only provide suggestions on the appropriate input
17661 * token type,
17662 * they'll otherwise show up multiple times */
17663 enum cmd_token_type match_type;
17664 char *name = peer->host;
17665
17666 if (peer->conf_if) {
17667 match_type = VARIABLE_TKN;
17668 name = peer->conf_if;
17669 } else if (strchr(peer->host, ':'))
17670 match_type = IPV6_TKN;
17671 else
17672 match_type = IPV4_TKN;
17673
17674 if (token->type != match_type)
17675 continue;
17676
17677 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
17678 }
17679 }
17680 }
17681
17682 static const struct cmd_variable_handler bgp_var_neighbor[] = {
17683 {.varname = "neighbor", .completions = bgp_ac_neighbor},
17684 {.varname = "neighbors", .completions = bgp_ac_neighbor},
17685 {.varname = "peer", .completions = bgp_ac_neighbor},
17686 {.completions = NULL}};
17687
17688 static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
17689 {
17690 struct bgp *bgp;
17691 struct peer_group *group;
17692 struct listnode *lnbgp, *lnpeer;
17693
17694 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
17695 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
17696 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
17697 group->name));
17698 }
17699 }
17700
17701 static const struct cmd_variable_handler bgp_var_peergroup[] = {
17702 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
17703 {.completions = NULL} };
17704
17705 void bgp_vty_init(void)
17706 {
17707 cmd_variable_handler_register(bgp_var_neighbor);
17708 cmd_variable_handler_register(bgp_var_peergroup);
17709
17710 /* Install bgp top node. */
17711 install_node(&bgp_node);
17712 install_node(&bgp_ipv4_unicast_node);
17713 install_node(&bgp_ipv4_multicast_node);
17714 install_node(&bgp_ipv4_labeled_unicast_node);
17715 install_node(&bgp_ipv6_unicast_node);
17716 install_node(&bgp_ipv6_multicast_node);
17717 install_node(&bgp_ipv6_labeled_unicast_node);
17718 install_node(&bgp_vpnv4_node);
17719 install_node(&bgp_vpnv6_node);
17720 install_node(&bgp_evpn_node);
17721 install_node(&bgp_evpn_vni_node);
17722 install_node(&bgp_flowspecv4_node);
17723 install_node(&bgp_flowspecv6_node);
17724
17725 /* Install default VTY commands to new nodes. */
17726 install_default(BGP_NODE);
17727 install_default(BGP_IPV4_NODE);
17728 install_default(BGP_IPV4M_NODE);
17729 install_default(BGP_IPV4L_NODE);
17730 install_default(BGP_IPV6_NODE);
17731 install_default(BGP_IPV6M_NODE);
17732 install_default(BGP_IPV6L_NODE);
17733 install_default(BGP_VPNV4_NODE);
17734 install_default(BGP_VPNV6_NODE);
17735 install_default(BGP_FLOWSPECV4_NODE);
17736 install_default(BGP_FLOWSPECV6_NODE);
17737 install_default(BGP_EVPN_NODE);
17738 install_default(BGP_EVPN_VNI_NODE);
17739
17740 /* "bgp local-mac" hidden commands. */
17741 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
17742 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
17743
17744 /* "bgp suppress-fib-pending" global */
17745 install_element(CONFIG_NODE, &bgp_global_suppress_fib_pending_cmd);
17746
17747 /* bgp route-map delay-timer commands. */
17748 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
17749 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
17750
17751 /* global bgp update-delay command */
17752 install_element(CONFIG_NODE, &bgp_global_update_delay_cmd);
17753 install_element(CONFIG_NODE, &no_bgp_global_update_delay_cmd);
17754
17755 /* global bgp graceful-shutdown command */
17756 install_element(CONFIG_NODE, &bgp_graceful_shutdown_cmd);
17757 install_element(CONFIG_NODE, &no_bgp_graceful_shutdown_cmd);
17758
17759 /* Dummy commands (Currently not supported) */
17760 install_element(BGP_NODE, &no_synchronization_cmd);
17761 install_element(BGP_NODE, &no_auto_summary_cmd);
17762
17763 /* "router bgp" commands. */
17764 install_element(CONFIG_NODE, &router_bgp_cmd);
17765
17766 /* "no router bgp" commands. */
17767 install_element(CONFIG_NODE, &no_router_bgp_cmd);
17768
17769 /* "bgp router-id" commands. */
17770 install_element(BGP_NODE, &bgp_router_id_cmd);
17771 install_element(BGP_NODE, &no_bgp_router_id_cmd);
17772
17773 /* "bgp suppress-fib-pending" command */
17774 install_element(BGP_NODE, &bgp_suppress_fib_pending_cmd);
17775
17776 /* "bgp cluster-id" commands. */
17777 install_element(BGP_NODE, &bgp_cluster_id_cmd);
17778 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
17779
17780 /* "bgp no-rib" commands. */
17781 install_element(CONFIG_NODE, &bgp_norib_cmd);
17782 install_element(CONFIG_NODE, &no_bgp_norib_cmd);
17783
17784 install_element(CONFIG_NODE, &no_bgp_send_extra_data_cmd);
17785
17786 /* "bgp confederation" commands. */
17787 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
17788 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
17789
17790 /* "bgp confederation peers" commands. */
17791 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
17792 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
17793
17794 /* bgp max-med command */
17795 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
17796 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
17797 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
17798 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
17799 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
17800
17801 /* bgp disable-ebgp-connected-nh-check */
17802 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
17803 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
17804
17805 /* bgp update-delay command */
17806 install_element(BGP_NODE, &bgp_update_delay_cmd);
17807 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
17808
17809 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
17810 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
17811
17812 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
17813 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
17814
17815 /* "maximum-paths" commands. */
17816 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
17817 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
17818 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
17819 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
17820 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
17821 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
17822 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
17823 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
17824 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
17825 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
17826 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17827 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
17828 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
17829 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17830 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
17831
17832 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_cmd);
17833 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_cmd);
17834 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cmd);
17835 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17836 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_ibgp_cmd);
17837 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
17838 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
17839 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
17840 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17841 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
17842
17843 /* "timers bgp" commands. */
17844 install_element(BGP_NODE, &bgp_timers_cmd);
17845 install_element(BGP_NODE, &no_bgp_timers_cmd);
17846
17847 /* route-map delay-timer commands - per instance for backwards compat.
17848 */
17849 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
17850 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
17851
17852 /* "bgp client-to-client reflection" commands */
17853 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
17854 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
17855
17856 /* "bgp always-compare-med" commands */
17857 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
17858 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
17859
17860 /* bgp ebgp-requires-policy */
17861 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
17862 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
17863
17864 /* bgp suppress-duplicates */
17865 install_element(BGP_NODE, &bgp_suppress_duplicates_cmd);
17866 install_element(BGP_NODE, &no_bgp_suppress_duplicates_cmd);
17867
17868 /* bgp reject-as-sets */
17869 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
17870 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
17871
17872 /* "bgp deterministic-med" commands */
17873 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
17874 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
17875
17876 /* "bgp graceful-restart" command */
17877 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
17878 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
17879
17880 /* "bgp graceful-restart-disable" command */
17881 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
17882 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
17883
17884 /* "neighbor a:b:c:d graceful-restart" command */
17885 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
17886 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
17887
17888 /* "neighbor a:b:c:d graceful-restart-disable" command */
17889 install_element(BGP_NODE,
17890 &bgp_neighbor_graceful_restart_disable_set_cmd);
17891 install_element(BGP_NODE,
17892 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
17893
17894 /* "neighbor a:b:c:d graceful-restart-helper" command */
17895 install_element(BGP_NODE,
17896 &bgp_neighbor_graceful_restart_helper_set_cmd);
17897 install_element(BGP_NODE,
17898 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
17899
17900 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
17901 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
17902 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
17903 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
17904 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
17905 install_element(BGP_NODE,
17906 &no_bgp_graceful_restart_select_defer_time_cmd);
17907 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
17908 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
17909
17910 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
17911 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
17912 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
17913 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
17914
17915 /* "bgp graceful-shutdown" commands */
17916 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
17917 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
17918
17919 /* "bgp fast-external-failover" commands */
17920 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
17921 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
17922
17923 /* "bgp bestpath compare-routerid" commands */
17924 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
17925 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
17926
17927 /* "bgp bestpath as-path ignore" commands */
17928 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
17929 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
17930
17931 /* "bgp bestpath as-path confed" commands */
17932 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
17933 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
17934
17935 /* "bgp bestpath as-path multipath-relax" commands */
17936 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
17937 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
17938
17939 /* "bgp log-neighbor-changes" commands */
17940 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
17941 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
17942
17943 /* "bgp bestpath med" commands */
17944 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
17945 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
17946
17947 /* "bgp bestpath bandwidth" commands */
17948 install_element(BGP_NODE, &bgp_bestpath_bw_cmd);
17949 install_element(BGP_NODE, &no_bgp_bestpath_bw_cmd);
17950
17951 /* "no bgp default ipv4-unicast" commands. */
17952 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
17953 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
17954
17955 /* "bgp network import-check" commands. */
17956 install_element(BGP_NODE, &bgp_network_import_check_cmd);
17957 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
17958 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
17959
17960 /* "bgp default local-preference" commands. */
17961 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
17962 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
17963
17964 /* bgp default show-hostname */
17965 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
17966 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
17967
17968 /* bgp default show-nexthop-hostname */
17969 install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
17970 install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
17971
17972 /* "bgp default subgroup-pkt-queue-max" commands. */
17973 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
17974 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
17975
17976 /* bgp ibgp-allow-policy-mods command */
17977 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
17978 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
17979
17980 /* "bgp listen limit" commands. */
17981 install_element(BGP_NODE, &bgp_listen_limit_cmd);
17982 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
17983
17984 /* "bgp listen range" commands. */
17985 install_element(BGP_NODE, &bgp_listen_range_cmd);
17986 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
17987
17988 /* "bgp default shutdown" command */
17989 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
17990
17991 /* "bgp shutdown" commands */
17992 install_element(BGP_NODE, &bgp_shutdown_cmd);
17993 install_element(BGP_NODE, &bgp_shutdown_msg_cmd);
17994 install_element(BGP_NODE, &no_bgp_shutdown_cmd);
17995 install_element(BGP_NODE, &no_bgp_shutdown_msg_cmd);
17996
17997 /* "neighbor remote-as" commands. */
17998 install_element(BGP_NODE, &neighbor_remote_as_cmd);
17999 install_element(BGP_NODE, &neighbor_interface_config_cmd);
18000 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
18001 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
18002 install_element(BGP_NODE,
18003 &neighbor_interface_v6only_config_remote_as_cmd);
18004 install_element(BGP_NODE, &no_neighbor_cmd);
18005 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
18006
18007 /* "neighbor peer-group" commands. */
18008 install_element(BGP_NODE, &neighbor_peer_group_cmd);
18009 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
18010 install_element(BGP_NODE,
18011 &no_neighbor_interface_peer_group_remote_as_cmd);
18012
18013 /* "neighbor local-as" commands. */
18014 install_element(BGP_NODE, &neighbor_local_as_cmd);
18015 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
18016 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
18017 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
18018
18019 /* "neighbor solo" commands. */
18020 install_element(BGP_NODE, &neighbor_solo_cmd);
18021 install_element(BGP_NODE, &no_neighbor_solo_cmd);
18022
18023 /* "neighbor password" commands. */
18024 install_element(BGP_NODE, &neighbor_password_cmd);
18025 install_element(BGP_NODE, &no_neighbor_password_cmd);
18026
18027 /* "neighbor activate" commands. */
18028 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
18029 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
18030 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
18031 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
18032 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
18033 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
18034 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
18035 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
18036 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
18037 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
18038 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
18039 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
18040
18041 /* "no neighbor activate" commands. */
18042 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
18043 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
18044 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
18045 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
18046 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
18047 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
18048 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
18049 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
18050 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
18051 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
18052 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
18053 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
18054
18055 /* "neighbor peer-group" set commands. */
18056 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
18057 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
18058 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
18059 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
18060 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
18061 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
18062 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
18063 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
18064 install_element(BGP_FLOWSPECV4_NODE,
18065 &neighbor_set_peer_group_hidden_cmd);
18066 install_element(BGP_FLOWSPECV6_NODE,
18067 &neighbor_set_peer_group_hidden_cmd);
18068
18069 /* "no neighbor peer-group unset" commands. */
18070 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
18071 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18072 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18073 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18074 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18075 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18076 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18077 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18078 install_element(BGP_FLOWSPECV4_NODE,
18079 &no_neighbor_set_peer_group_hidden_cmd);
18080 install_element(BGP_FLOWSPECV6_NODE,
18081 &no_neighbor_set_peer_group_hidden_cmd);
18082
18083 /* "neighbor softreconfiguration inbound" commands.*/
18084 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
18085 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
18086 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
18087 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
18088 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
18089 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
18090 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
18091 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
18092 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
18093 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
18094 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
18095 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
18096 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
18097 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
18098 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
18099 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
18100 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
18101 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
18102 install_element(BGP_FLOWSPECV4_NODE,
18103 &neighbor_soft_reconfiguration_cmd);
18104 install_element(BGP_FLOWSPECV4_NODE,
18105 &no_neighbor_soft_reconfiguration_cmd);
18106 install_element(BGP_FLOWSPECV6_NODE,
18107 &neighbor_soft_reconfiguration_cmd);
18108 install_element(BGP_FLOWSPECV6_NODE,
18109 &no_neighbor_soft_reconfiguration_cmd);
18110 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
18111 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
18112
18113 /* "neighbor attribute-unchanged" commands. */
18114 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
18115 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
18116 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
18117 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
18118 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
18119 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
18120 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
18121 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
18122 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
18123 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
18124 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
18125 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
18126 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
18127 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
18128 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
18129 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
18130 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
18131 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
18132
18133 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
18134 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
18135
18136 /* "nexthop-local unchanged" commands */
18137 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
18138 install_element(BGP_IPV6_NODE,
18139 &no_neighbor_nexthop_local_unchanged_cmd);
18140
18141 /* "neighbor next-hop-self" commands. */
18142 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
18143 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
18144 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
18145 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
18146 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
18147 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
18148 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
18149 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
18150 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
18151 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
18152 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
18153 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
18154 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
18155 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
18156 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
18157 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
18158 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
18159 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
18160 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
18161 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
18162
18163 /* "neighbor next-hop-self force" commands. */
18164 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
18165 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
18166 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18167 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
18168 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
18169 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
18170 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18171 install_element(BGP_IPV4_NODE,
18172 &no_neighbor_nexthop_self_all_hidden_cmd);
18173 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
18174 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
18175 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18176 install_element(BGP_IPV4M_NODE,
18177 &no_neighbor_nexthop_self_all_hidden_cmd);
18178 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
18179 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
18180 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18181 install_element(BGP_IPV4L_NODE,
18182 &no_neighbor_nexthop_self_all_hidden_cmd);
18183 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
18184 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
18185 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18186 install_element(BGP_IPV6_NODE,
18187 &no_neighbor_nexthop_self_all_hidden_cmd);
18188 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
18189 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
18190 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18191 install_element(BGP_IPV6M_NODE,
18192 &no_neighbor_nexthop_self_all_hidden_cmd);
18193 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
18194 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
18195 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18196 install_element(BGP_IPV6L_NODE,
18197 &no_neighbor_nexthop_self_all_hidden_cmd);
18198 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
18199 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
18200 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18201 install_element(BGP_VPNV4_NODE,
18202 &no_neighbor_nexthop_self_all_hidden_cmd);
18203 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
18204 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
18205 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18206 install_element(BGP_VPNV6_NODE,
18207 &no_neighbor_nexthop_self_all_hidden_cmd);
18208 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_force_cmd);
18209 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_force_cmd);
18210
18211 /* "neighbor as-override" commands. */
18212 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
18213 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
18214 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
18215 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
18216 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
18217 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
18218 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
18219 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
18220 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
18221 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
18222 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
18223 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
18224 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
18225 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
18226 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
18227 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
18228 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
18229 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
18230
18231 /* "neighbor remove-private-AS" commands. */
18232 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
18233 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
18234 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
18235 install_element(BGP_NODE,
18236 &no_neighbor_remove_private_as_all_hidden_cmd);
18237 install_element(BGP_NODE,
18238 &neighbor_remove_private_as_replace_as_hidden_cmd);
18239 install_element(BGP_NODE,
18240 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
18241 install_element(BGP_NODE,
18242 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
18243 install_element(
18244 BGP_NODE,
18245 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
18246 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
18247 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
18248 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
18249 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18250 install_element(BGP_IPV4_NODE,
18251 &neighbor_remove_private_as_replace_as_cmd);
18252 install_element(BGP_IPV4_NODE,
18253 &no_neighbor_remove_private_as_replace_as_cmd);
18254 install_element(BGP_IPV4_NODE,
18255 &neighbor_remove_private_as_all_replace_as_cmd);
18256 install_element(BGP_IPV4_NODE,
18257 &no_neighbor_remove_private_as_all_replace_as_cmd);
18258 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
18259 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
18260 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
18261 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
18262 install_element(BGP_IPV4M_NODE,
18263 &neighbor_remove_private_as_replace_as_cmd);
18264 install_element(BGP_IPV4M_NODE,
18265 &no_neighbor_remove_private_as_replace_as_cmd);
18266 install_element(BGP_IPV4M_NODE,
18267 &neighbor_remove_private_as_all_replace_as_cmd);
18268 install_element(BGP_IPV4M_NODE,
18269 &no_neighbor_remove_private_as_all_replace_as_cmd);
18270 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
18271 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
18272 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
18273 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
18274 install_element(BGP_IPV4L_NODE,
18275 &neighbor_remove_private_as_replace_as_cmd);
18276 install_element(BGP_IPV4L_NODE,
18277 &no_neighbor_remove_private_as_replace_as_cmd);
18278 install_element(BGP_IPV4L_NODE,
18279 &neighbor_remove_private_as_all_replace_as_cmd);
18280 install_element(BGP_IPV4L_NODE,
18281 &no_neighbor_remove_private_as_all_replace_as_cmd);
18282 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
18283 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
18284 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
18285 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18286 install_element(BGP_IPV6_NODE,
18287 &neighbor_remove_private_as_replace_as_cmd);
18288 install_element(BGP_IPV6_NODE,
18289 &no_neighbor_remove_private_as_replace_as_cmd);
18290 install_element(BGP_IPV6_NODE,
18291 &neighbor_remove_private_as_all_replace_as_cmd);
18292 install_element(BGP_IPV6_NODE,
18293 &no_neighbor_remove_private_as_all_replace_as_cmd);
18294 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
18295 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
18296 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
18297 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
18298 install_element(BGP_IPV6M_NODE,
18299 &neighbor_remove_private_as_replace_as_cmd);
18300 install_element(BGP_IPV6M_NODE,
18301 &no_neighbor_remove_private_as_replace_as_cmd);
18302 install_element(BGP_IPV6M_NODE,
18303 &neighbor_remove_private_as_all_replace_as_cmd);
18304 install_element(BGP_IPV6M_NODE,
18305 &no_neighbor_remove_private_as_all_replace_as_cmd);
18306 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
18307 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
18308 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
18309 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
18310 install_element(BGP_IPV6L_NODE,
18311 &neighbor_remove_private_as_replace_as_cmd);
18312 install_element(BGP_IPV6L_NODE,
18313 &no_neighbor_remove_private_as_replace_as_cmd);
18314 install_element(BGP_IPV6L_NODE,
18315 &neighbor_remove_private_as_all_replace_as_cmd);
18316 install_element(BGP_IPV6L_NODE,
18317 &no_neighbor_remove_private_as_all_replace_as_cmd);
18318 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
18319 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
18320 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
18321 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18322 install_element(BGP_VPNV4_NODE,
18323 &neighbor_remove_private_as_replace_as_cmd);
18324 install_element(BGP_VPNV4_NODE,
18325 &no_neighbor_remove_private_as_replace_as_cmd);
18326 install_element(BGP_VPNV4_NODE,
18327 &neighbor_remove_private_as_all_replace_as_cmd);
18328 install_element(BGP_VPNV4_NODE,
18329 &no_neighbor_remove_private_as_all_replace_as_cmd);
18330 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
18331 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
18332 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
18333 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18334 install_element(BGP_VPNV6_NODE,
18335 &neighbor_remove_private_as_replace_as_cmd);
18336 install_element(BGP_VPNV6_NODE,
18337 &no_neighbor_remove_private_as_replace_as_cmd);
18338 install_element(BGP_VPNV6_NODE,
18339 &neighbor_remove_private_as_all_replace_as_cmd);
18340 install_element(BGP_VPNV6_NODE,
18341 &no_neighbor_remove_private_as_all_replace_as_cmd);
18342
18343 /* "neighbor send-community" commands.*/
18344 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
18345 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
18346 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
18347 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
18348 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
18349 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
18350 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
18351 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
18352 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
18353 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
18354 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
18355 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
18356 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
18357 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
18358 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
18359 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
18360 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
18361 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
18362 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
18363 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
18364 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
18365 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
18366 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
18367 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
18368 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
18369 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
18370 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
18371 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
18372 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
18373 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
18374 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
18375 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
18376 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
18377 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
18378 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
18379 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
18380
18381 /* "neighbor route-reflector" commands.*/
18382 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
18383 install_element(BGP_NODE,
18384 &no_neighbor_route_reflector_client_hidden_cmd);
18385 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
18386 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
18387 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
18388 install_element(BGP_IPV4M_NODE,
18389 &no_neighbor_route_reflector_client_cmd);
18390 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
18391 install_element(BGP_IPV4L_NODE,
18392 &no_neighbor_route_reflector_client_cmd);
18393 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
18394 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
18395 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
18396 install_element(BGP_IPV6M_NODE,
18397 &no_neighbor_route_reflector_client_cmd);
18398 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
18399 install_element(BGP_IPV6L_NODE,
18400 &no_neighbor_route_reflector_client_cmd);
18401 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
18402 install_element(BGP_VPNV4_NODE,
18403 &no_neighbor_route_reflector_client_cmd);
18404 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
18405 install_element(BGP_VPNV6_NODE,
18406 &no_neighbor_route_reflector_client_cmd);
18407 install_element(BGP_FLOWSPECV4_NODE,
18408 &neighbor_route_reflector_client_cmd);
18409 install_element(BGP_FLOWSPECV4_NODE,
18410 &no_neighbor_route_reflector_client_cmd);
18411 install_element(BGP_FLOWSPECV6_NODE,
18412 &neighbor_route_reflector_client_cmd);
18413 install_element(BGP_FLOWSPECV6_NODE,
18414 &no_neighbor_route_reflector_client_cmd);
18415 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
18416 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
18417
18418 /* "neighbor route-server" commands.*/
18419 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
18420 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
18421 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
18422 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
18423 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
18424 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
18425 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
18426 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
18427 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
18428 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
18429 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
18430 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
18431 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
18432 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
18433 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
18434 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
18435 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
18436 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
18437 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
18438 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
18439 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
18440 install_element(BGP_FLOWSPECV4_NODE,
18441 &no_neighbor_route_server_client_cmd);
18442 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
18443 install_element(BGP_FLOWSPECV6_NODE,
18444 &no_neighbor_route_server_client_cmd);
18445
18446 /* "neighbor addpath-tx-all-paths" commands.*/
18447 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
18448 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
18449 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
18450 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18451 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
18452 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18453 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
18454 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18455 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
18456 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18457 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
18458 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18459 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
18460 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18461 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
18462 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18463 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
18464 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18465
18466 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
18467 install_element(BGP_NODE,
18468 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
18469 install_element(BGP_NODE,
18470 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
18471 install_element(BGP_IPV4_NODE,
18472 &neighbor_addpath_tx_bestpath_per_as_cmd);
18473 install_element(BGP_IPV4_NODE,
18474 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18475 install_element(BGP_IPV4M_NODE,
18476 &neighbor_addpath_tx_bestpath_per_as_cmd);
18477 install_element(BGP_IPV4M_NODE,
18478 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18479 install_element(BGP_IPV4L_NODE,
18480 &neighbor_addpath_tx_bestpath_per_as_cmd);
18481 install_element(BGP_IPV4L_NODE,
18482 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18483 install_element(BGP_IPV6_NODE,
18484 &neighbor_addpath_tx_bestpath_per_as_cmd);
18485 install_element(BGP_IPV6_NODE,
18486 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18487 install_element(BGP_IPV6M_NODE,
18488 &neighbor_addpath_tx_bestpath_per_as_cmd);
18489 install_element(BGP_IPV6M_NODE,
18490 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18491 install_element(BGP_IPV6L_NODE,
18492 &neighbor_addpath_tx_bestpath_per_as_cmd);
18493 install_element(BGP_IPV6L_NODE,
18494 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18495 install_element(BGP_VPNV4_NODE,
18496 &neighbor_addpath_tx_bestpath_per_as_cmd);
18497 install_element(BGP_VPNV4_NODE,
18498 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18499 install_element(BGP_VPNV6_NODE,
18500 &neighbor_addpath_tx_bestpath_per_as_cmd);
18501 install_element(BGP_VPNV6_NODE,
18502 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18503
18504 /* "neighbor sender-as-path-loop-detection" commands. */
18505 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
18506 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
18507
18508 /* "neighbor passive" commands. */
18509 install_element(BGP_NODE, &neighbor_passive_cmd);
18510 install_element(BGP_NODE, &no_neighbor_passive_cmd);
18511
18512
18513 /* "neighbor shutdown" commands. */
18514 install_element(BGP_NODE, &neighbor_shutdown_cmd);
18515 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
18516 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
18517 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
18518 install_element(BGP_NODE, &neighbor_shutdown_rtt_cmd);
18519 install_element(BGP_NODE, &no_neighbor_shutdown_rtt_cmd);
18520
18521 /* "neighbor capability extended-nexthop" commands.*/
18522 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
18523 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
18524
18525 /* "neighbor capability orf prefix-list" commands.*/
18526 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
18527 install_element(BGP_NODE,
18528 &no_neighbor_capability_orf_prefix_hidden_cmd);
18529 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
18530 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
18531 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
18532 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
18533 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
18534 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
18535 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
18536 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
18537 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
18538 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
18539 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
18540 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
18541
18542 /* "neighbor capability dynamic" commands.*/
18543 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
18544 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
18545
18546 /* "neighbor dont-capability-negotiate" commands. */
18547 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
18548 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
18549
18550 /* "neighbor ebgp-multihop" commands. */
18551 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
18552 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
18553 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
18554
18555 /* "neighbor disable-connected-check" commands. */
18556 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
18557 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
18558
18559 /* "neighbor enforce-first-as" commands. */
18560 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
18561 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
18562
18563 /* "neighbor description" commands. */
18564 install_element(BGP_NODE, &neighbor_description_cmd);
18565 install_element(BGP_NODE, &no_neighbor_description_cmd);
18566 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
18567
18568 /* "neighbor update-source" commands. "*/
18569 install_element(BGP_NODE, &neighbor_update_source_cmd);
18570 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
18571
18572 /* "neighbor default-originate" commands. */
18573 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
18574 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
18575 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
18576 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
18577 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
18578 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
18579 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
18580 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
18581 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
18582 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
18583 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
18584 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
18585 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
18586 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
18587 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
18588 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
18589 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
18590 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
18591 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
18592 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
18593 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
18594
18595 /* "neighbor port" commands. */
18596 install_element(BGP_NODE, &neighbor_port_cmd);
18597 install_element(BGP_NODE, &no_neighbor_port_cmd);
18598
18599 /* "neighbor weight" commands. */
18600 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
18601 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
18602
18603 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
18604 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
18605 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
18606 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
18607 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
18608 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
18609 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
18610 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
18611 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
18612 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
18613 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
18614 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
18615 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
18616 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
18617 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
18618 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
18619
18620 /* "neighbor override-capability" commands. */
18621 install_element(BGP_NODE, &neighbor_override_capability_cmd);
18622 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
18623
18624 /* "neighbor strict-capability-match" commands. */
18625 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
18626 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
18627
18628 /* "neighbor timers" commands. */
18629 install_element(BGP_NODE, &neighbor_timers_cmd);
18630 install_element(BGP_NODE, &no_neighbor_timers_cmd);
18631
18632 /* "neighbor timers connect" commands. */
18633 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
18634 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
18635
18636 /* "neighbor timers delayopen" commands. */
18637 install_element(BGP_NODE, &neighbor_timers_delayopen_cmd);
18638 install_element(BGP_NODE, &no_neighbor_timers_delayopen_cmd);
18639
18640 /* "neighbor advertisement-interval" commands. */
18641 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
18642 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
18643
18644 /* "neighbor interface" commands. */
18645 install_element(BGP_NODE, &neighbor_interface_cmd);
18646 install_element(BGP_NODE, &no_neighbor_interface_cmd);
18647
18648 /* "neighbor distribute" commands. */
18649 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
18650 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
18651 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
18652 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
18653 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
18654 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
18655 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
18656 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
18657 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
18658 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
18659 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
18660 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
18661 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
18662 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
18663 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
18664 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
18665 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
18666 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
18667
18668 /* "neighbor prefix-list" commands. */
18669 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
18670 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
18671 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
18672 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
18673 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
18674 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
18675 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
18676 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
18677 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
18678 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
18679 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
18680 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
18681 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
18682 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
18683 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
18684 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
18685 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
18686 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
18687 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
18688 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
18689 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
18690 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
18691
18692 /* "neighbor filter-list" commands. */
18693 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
18694 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
18695 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
18696 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
18697 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
18698 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
18699 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
18700 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
18701 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
18702 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
18703 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
18704 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
18705 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
18706 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
18707 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
18708 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
18709 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
18710 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
18711 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
18712 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
18713 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
18714 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
18715
18716 /* "neighbor route-map" commands. */
18717 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
18718 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
18719 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
18720 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
18721 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
18722 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
18723 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
18724 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
18725 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
18726 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
18727 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
18728 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
18729 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
18730 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
18731 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
18732 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
18733 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
18734 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
18735 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
18736 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
18737 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
18738 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
18739 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
18740 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
18741
18742 /* "neighbor unsuppress-map" commands. */
18743 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
18744 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
18745 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
18746 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
18747 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
18748 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
18749 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
18750 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
18751 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
18752 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
18753 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
18754 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
18755 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
18756 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
18757 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
18758 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
18759 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
18760 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
18761
18762 /* "neighbor advertise-map" commands. */
18763 install_element(BGP_NODE, &neighbor_advertise_map_hidden_cmd);
18764 install_element(BGP_IPV4_NODE, &neighbor_advertise_map_cmd);
18765 install_element(BGP_IPV4M_NODE, &neighbor_advertise_map_cmd);
18766 install_element(BGP_IPV4L_NODE, &neighbor_advertise_map_cmd);
18767 install_element(BGP_IPV6_NODE, &neighbor_advertise_map_cmd);
18768 install_element(BGP_IPV6M_NODE, &neighbor_advertise_map_cmd);
18769 install_element(BGP_IPV6L_NODE, &neighbor_advertise_map_cmd);
18770 install_element(BGP_VPNV4_NODE, &neighbor_advertise_map_cmd);
18771 install_element(BGP_VPNV6_NODE, &neighbor_advertise_map_cmd);
18772
18773 /* neighbor maximum-prefix-out commands. */
18774 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
18775 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
18776 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
18777 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
18778 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
18779 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
18780 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
18781 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
18782 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
18783 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
18784 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
18785 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
18786 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
18787 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
18788 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
18789 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
18790 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
18791 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
18792
18793 /* "neighbor maximum-prefix" commands. */
18794 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
18795 install_element(BGP_NODE,
18796 &neighbor_maximum_prefix_threshold_hidden_cmd);
18797 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
18798 install_element(BGP_NODE,
18799 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
18800 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
18801 install_element(BGP_NODE,
18802 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
18803 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
18804 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
18805 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
18806 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
18807 install_element(BGP_IPV4_NODE,
18808 &neighbor_maximum_prefix_threshold_warning_cmd);
18809 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
18810 install_element(BGP_IPV4_NODE,
18811 &neighbor_maximum_prefix_threshold_restart_cmd);
18812 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
18813 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
18814 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
18815 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
18816 install_element(BGP_IPV4M_NODE,
18817 &neighbor_maximum_prefix_threshold_warning_cmd);
18818 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
18819 install_element(BGP_IPV4M_NODE,
18820 &neighbor_maximum_prefix_threshold_restart_cmd);
18821 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
18822 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
18823 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
18824 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
18825 install_element(BGP_IPV4L_NODE,
18826 &neighbor_maximum_prefix_threshold_warning_cmd);
18827 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
18828 install_element(BGP_IPV4L_NODE,
18829 &neighbor_maximum_prefix_threshold_restart_cmd);
18830 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
18831 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
18832 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
18833 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
18834 install_element(BGP_IPV6_NODE,
18835 &neighbor_maximum_prefix_threshold_warning_cmd);
18836 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
18837 install_element(BGP_IPV6_NODE,
18838 &neighbor_maximum_prefix_threshold_restart_cmd);
18839 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
18840 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
18841 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
18842 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
18843 install_element(BGP_IPV6M_NODE,
18844 &neighbor_maximum_prefix_threshold_warning_cmd);
18845 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
18846 install_element(BGP_IPV6M_NODE,
18847 &neighbor_maximum_prefix_threshold_restart_cmd);
18848 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
18849 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
18850 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
18851 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
18852 install_element(BGP_IPV6L_NODE,
18853 &neighbor_maximum_prefix_threshold_warning_cmd);
18854 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
18855 install_element(BGP_IPV6L_NODE,
18856 &neighbor_maximum_prefix_threshold_restart_cmd);
18857 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
18858 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
18859 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
18860 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
18861 install_element(BGP_VPNV4_NODE,
18862 &neighbor_maximum_prefix_threshold_warning_cmd);
18863 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
18864 install_element(BGP_VPNV4_NODE,
18865 &neighbor_maximum_prefix_threshold_restart_cmd);
18866 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
18867 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
18868 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
18869 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
18870 install_element(BGP_VPNV6_NODE,
18871 &neighbor_maximum_prefix_threshold_warning_cmd);
18872 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
18873 install_element(BGP_VPNV6_NODE,
18874 &neighbor_maximum_prefix_threshold_restart_cmd);
18875 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
18876
18877 /* "neighbor allowas-in" */
18878 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
18879 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
18880 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
18881 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
18882 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
18883 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
18884 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
18885 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
18886 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
18887 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
18888 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
18889 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
18890 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
18891 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
18892 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
18893 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
18894 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
18895 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
18896 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
18897 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
18898
18899 /* "neighbor dampening" commands. */
18900 install_element(BGP_NODE, &neighbor_damp_cmd);
18901 install_element(BGP_NODE, &no_neighbor_damp_cmd);
18902 install_element(BGP_IPV4_NODE, &neighbor_damp_cmd);
18903 install_element(BGP_IPV4_NODE, &no_neighbor_damp_cmd);
18904 install_element(BGP_IPV4M_NODE, &neighbor_damp_cmd);
18905 install_element(BGP_IPV4M_NODE, &no_neighbor_damp_cmd);
18906 install_element(BGP_IPV4L_NODE, &neighbor_damp_cmd);
18907 install_element(BGP_IPV4L_NODE, &no_neighbor_damp_cmd);
18908 install_element(BGP_IPV6_NODE, &neighbor_damp_cmd);
18909 install_element(BGP_IPV6_NODE, &no_neighbor_damp_cmd);
18910 install_element(BGP_IPV6M_NODE, &neighbor_damp_cmd);
18911 install_element(BGP_IPV6M_NODE, &no_neighbor_damp_cmd);
18912 install_element(BGP_IPV6L_NODE, &neighbor_damp_cmd);
18913 install_element(BGP_IPV6L_NODE, &no_neighbor_damp_cmd);
18914 install_element(VIEW_NODE, &show_ip_bgp_neighbor_damp_param_cmd);
18915
18916 /* address-family commands. */
18917 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
18918 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
18919 #ifdef KEEP_OLD_VPN_COMMANDS
18920 install_element(BGP_NODE, &address_family_vpnv4_cmd);
18921 install_element(BGP_NODE, &address_family_vpnv6_cmd);
18922 #endif /* KEEP_OLD_VPN_COMMANDS */
18923
18924 install_element(BGP_NODE, &address_family_evpn_cmd);
18925
18926 /* "exit-address-family" command. */
18927 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
18928 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
18929 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
18930 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
18931 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
18932 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
18933 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
18934 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
18935 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
18936 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
18937 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
18938
18939 /* "clear ip bgp commands" */
18940 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
18941
18942 /* clear ip bgp prefix */
18943 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
18944 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
18945 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
18946
18947 /* "show [ip] bgp summary" commands. */
18948 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
18949 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
18950 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
18951 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
18952 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
18953 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
18954 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
18955
18956 /* "show [ip] bgp neighbors" commands. */
18957 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
18958
18959 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
18960
18961 /* "show [ip] bgp peer-group" commands. */
18962 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
18963
18964 /* "show [ip] bgp paths" commands. */
18965 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
18966
18967 /* "show [ip] bgp community" commands. */
18968 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
18969
18970 /* "show ip bgp large-community" commands. */
18971 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
18972 /* "show [ip] bgp attribute-info" commands. */
18973 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
18974 /* "show [ip] bgp route-leak" command */
18975 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
18976
18977 /* "redistribute" commands. */
18978 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
18979 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
18980 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
18981 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
18982 install_element(BGP_NODE,
18983 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
18984 install_element(BGP_NODE,
18985 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
18986 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
18987 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
18988 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
18989 install_element(BGP_NODE,
18990 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
18991 install_element(BGP_NODE,
18992 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
18993 install_element(BGP_NODE,
18994 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
18995 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
18996 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
18997 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
18998 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
18999 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
19000 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
19001 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
19002 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
19003 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
19004 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
19005 install_element(BGP_IPV4_NODE,
19006 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
19007 install_element(BGP_IPV4_NODE,
19008 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
19009 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
19010 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
19011 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
19012 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
19013 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
19014 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
19015
19016 /* import|export vpn [route-map WORD] */
19017 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
19018 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
19019
19020 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
19021 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
19022
19023 /* ttl_security commands */
19024 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
19025 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
19026
19027 /* "show [ip] bgp memory" commands. */
19028 install_element(VIEW_NODE, &show_bgp_memory_cmd);
19029
19030 /* "show bgp martian next-hop" */
19031 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
19032
19033 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
19034
19035 /* "show [ip] bgp views" commands. */
19036 install_element(VIEW_NODE, &show_bgp_views_cmd);
19037
19038 /* "show [ip] bgp vrfs" commands. */
19039 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
19040
19041 /* Community-list. */
19042 community_list_vty();
19043
19044 /* vpn-policy commands */
19045 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
19046 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
19047 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
19048 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
19049 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
19050 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
19051 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
19052 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
19053 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
19054 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
19055 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
19056 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
19057
19058 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
19059 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
19060
19061 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
19062 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
19063 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
19064 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
19065 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
19066 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
19067 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
19068 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
19069 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
19070 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
19071 }
19072
19073 #include "memory.h"
19074 #include "bgp_regex.h"
19075 #include "bgp_clist.h"
19076 #include "bgp_ecommunity.h"
19077
19078 /* VTY functions. */
19079
19080 /* Direction value to string conversion. */
19081 static const char *community_direct_str(int direct)
19082 {
19083 switch (direct) {
19084 case COMMUNITY_DENY:
19085 return "deny";
19086 case COMMUNITY_PERMIT:
19087 return "permit";
19088 default:
19089 return "unknown";
19090 }
19091 }
19092
19093 /* Display error string. */
19094 static void community_list_perror(struct vty *vty, int ret)
19095 {
19096 switch (ret) {
19097 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
19098 vty_out(vty, "%% Can't find community-list\n");
19099 break;
19100 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
19101 vty_out(vty, "%% Malformed community-list value\n");
19102 break;
19103 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
19104 vty_out(vty,
19105 "%% Community name conflict, previously defined as standard community\n");
19106 break;
19107 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
19108 vty_out(vty,
19109 "%% Community name conflict, previously defined as expanded community\n");
19110 break;
19111 }
19112 }
19113
19114 /* "community-list" keyword help string. */
19115 #define COMMUNITY_LIST_STR "Add a community list entry\n"
19116
19117 /*community-list standard */
19118 DEFUN (community_list_standard,
19119 bgp_community_list_standard_cmd,
19120 "bgp community-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
19121 BGP_STR
19122 COMMUNITY_LIST_STR
19123 "Community list number (standard)\n"
19124 "Add an standard community-list entry\n"
19125 "Community list name\n"
19126 "Sequence number of an entry\n"
19127 "Sequence number\n"
19128 "Specify community to reject\n"
19129 "Specify community to accept\n"
19130 COMMUNITY_VAL_STR)
19131 {
19132 char *cl_name_or_number = NULL;
19133 char *seq = NULL;
19134 int direct = 0;
19135 int style = COMMUNITY_LIST_STANDARD;
19136 int idx = 0;
19137
19138 argv_find(argv, argc, "(1-4294967295)", &idx);
19139 if (idx)
19140 seq = argv[idx]->arg;
19141
19142 idx = 0;
19143 argv_find(argv, argc, "(1-99)", &idx);
19144 argv_find(argv, argc, "WORD", &idx);
19145 cl_name_or_number = argv[idx]->arg;
19146 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19147 : COMMUNITY_DENY;
19148 argv_find(argv, argc, "AA:NN", &idx);
19149 char *str = argv_concat(argv, argc, idx);
19150
19151 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19152 direct, style);
19153
19154 XFREE(MTYPE_TMP, str);
19155
19156 if (ret < 0) {
19157 /* Display error string. */
19158 community_list_perror(vty, ret);
19159 return CMD_WARNING_CONFIG_FAILED;
19160 }
19161
19162 return CMD_SUCCESS;
19163 }
19164
19165 DEFUN (no_community_list_standard_all,
19166 no_bgp_community_list_standard_all_cmd,
19167 "no bgp community-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
19168 NO_STR
19169 BGP_STR
19170 COMMUNITY_LIST_STR
19171 "Community list number (standard)\n"
19172 "Add an standard community-list entry\n"
19173 "Community list name\n"
19174 "Sequence number of an entry\n"
19175 "Sequence number\n"
19176 "Specify community to reject\n"
19177 "Specify community to accept\n"
19178 COMMUNITY_VAL_STR)
19179 {
19180 char *cl_name_or_number = NULL;
19181 char *str = NULL;
19182 int direct = 0;
19183 int style = COMMUNITY_LIST_STANDARD;
19184 char *seq = NULL;
19185 int idx = 0;
19186
19187 argv_find(argv, argc, "(1-4294967295)", &idx);
19188 if (idx)
19189 seq = argv[idx]->arg;
19190
19191 idx = 0;
19192 argv_find(argv, argc, "permit", &idx);
19193 argv_find(argv, argc, "deny", &idx);
19194
19195 if (idx) {
19196 direct = argv_find(argv, argc, "permit", &idx)
19197 ? COMMUNITY_PERMIT
19198 : COMMUNITY_DENY;
19199
19200 idx = 0;
19201 argv_find(argv, argc, "AA:NN", &idx);
19202 str = argv_concat(argv, argc, idx);
19203 }
19204
19205 idx = 0;
19206 argv_find(argv, argc, "(1-99)", &idx);
19207 argv_find(argv, argc, "WORD", &idx);
19208 cl_name_or_number = argv[idx]->arg;
19209
19210 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
19211 direct, style);
19212
19213 XFREE(MTYPE_TMP, str);
19214
19215 if (ret < 0) {
19216 community_list_perror(vty, ret);
19217 return CMD_WARNING_CONFIG_FAILED;
19218 }
19219
19220 return CMD_SUCCESS;
19221 }
19222
19223 ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
19224 "no bgp community-list <(1-99)|standard WORD>",
19225 NO_STR BGP_STR COMMUNITY_LIST_STR
19226 "Community list number (standard)\n"
19227 "Add an standard community-list entry\n"
19228 "Community list name\n")
19229
19230 /*community-list expanded */
19231 DEFUN (community_list_expanded_all,
19232 bgp_community_list_expanded_all_cmd,
19233 "bgp community-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
19234 BGP_STR
19235 COMMUNITY_LIST_STR
19236 "Community list number (expanded)\n"
19237 "Add an expanded community-list entry\n"
19238 "Community list name\n"
19239 "Sequence number of an entry\n"
19240 "Sequence number\n"
19241 "Specify community to reject\n"
19242 "Specify community to accept\n"
19243 COMMUNITY_VAL_STR)
19244 {
19245 char *cl_name_or_number = NULL;
19246 char *seq = NULL;
19247 int direct = 0;
19248 int style = COMMUNITY_LIST_EXPANDED;
19249 int idx = 0;
19250
19251 argv_find(argv, argc, "(1-4294967295)", &idx);
19252 if (idx)
19253 seq = argv[idx]->arg;
19254
19255 idx = 0;
19256
19257 argv_find(argv, argc, "(100-500)", &idx);
19258 argv_find(argv, argc, "WORD", &idx);
19259 cl_name_or_number = argv[idx]->arg;
19260 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19261 : COMMUNITY_DENY;
19262 argv_find(argv, argc, "AA:NN", &idx);
19263 char *str = argv_concat(argv, argc, idx);
19264
19265 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19266 direct, style);
19267
19268 XFREE(MTYPE_TMP, str);
19269
19270 if (ret < 0) {
19271 /* Display error string. */
19272 community_list_perror(vty, ret);
19273 return CMD_WARNING_CONFIG_FAILED;
19274 }
19275
19276 return CMD_SUCCESS;
19277 }
19278
19279 DEFUN (no_community_list_expanded_all,
19280 no_bgp_community_list_expanded_all_cmd,
19281 "no bgp community-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
19282 NO_STR
19283 BGP_STR
19284 COMMUNITY_LIST_STR
19285 "Community list number (expanded)\n"
19286 "Add an expanded community-list entry\n"
19287 "Community list name\n"
19288 "Sequence number of an entry\n"
19289 "Sequence number\n"
19290 "Specify community to reject\n"
19291 "Specify community to accept\n"
19292 COMMUNITY_VAL_STR)
19293 {
19294 char *cl_name_or_number = NULL;
19295 char *seq = NULL;
19296 char *str = NULL;
19297 int direct = 0;
19298 int style = COMMUNITY_LIST_EXPANDED;
19299 int idx = 0;
19300
19301 argv_find(argv, argc, "(1-4294967295)", &idx);
19302 if (idx)
19303 seq = argv[idx]->arg;
19304
19305 idx = 0;
19306 argv_find(argv, argc, "permit", &idx);
19307 argv_find(argv, argc, "deny", &idx);
19308
19309 if (idx) {
19310 direct = argv_find(argv, argc, "permit", &idx)
19311 ? COMMUNITY_PERMIT
19312 : COMMUNITY_DENY;
19313
19314 idx = 0;
19315 argv_find(argv, argc, "AA:NN", &idx);
19316 str = argv_concat(argv, argc, idx);
19317 }
19318
19319 idx = 0;
19320 argv_find(argv, argc, "(100-500)", &idx);
19321 argv_find(argv, argc, "WORD", &idx);
19322 cl_name_or_number = argv[idx]->arg;
19323
19324 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
19325 direct, style);
19326
19327 XFREE(MTYPE_TMP, str);
19328
19329 if (ret < 0) {
19330 community_list_perror(vty, ret);
19331 return CMD_WARNING_CONFIG_FAILED;
19332 }
19333
19334 return CMD_SUCCESS;
19335 }
19336
19337 ALIAS(no_community_list_expanded_all,
19338 no_bgp_community_list_expanded_all_list_cmd,
19339 "no bgp community-list <(100-500)|expanded WORD>",
19340 NO_STR BGP_STR COMMUNITY_LIST_STR
19341 "Community list number (expanded)\n"
19342 "Add an expanded community-list entry\n"
19343 "Community list name\n")
19344
19345 /* Return configuration string of community-list entry. */
19346 static const char *community_list_config_str(struct community_entry *entry)
19347 {
19348 const char *str;
19349
19350 if (entry->any)
19351 str = "";
19352 else {
19353 if (entry->style == COMMUNITY_LIST_STANDARD)
19354 str = community_str(entry->u.com, false);
19355 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
19356 str = lcommunity_str(entry->u.lcom, false);
19357 else
19358 str = entry->config;
19359 }
19360 return str;
19361 }
19362
19363 static void community_list_show(struct vty *vty, struct community_list *list)
19364 {
19365 struct community_entry *entry;
19366
19367 for (entry = list->head; entry; entry = entry->next) {
19368 if (entry == list->head) {
19369 if (all_digit(list->name))
19370 vty_out(vty, "Community %s list %s\n",
19371 entry->style == COMMUNITY_LIST_STANDARD
19372 ? "standard"
19373 : "(expanded) access",
19374 list->name);
19375 else
19376 vty_out(vty, "Named Community %s list %s\n",
19377 entry->style == COMMUNITY_LIST_STANDARD
19378 ? "standard"
19379 : "expanded",
19380 list->name);
19381 }
19382 if (entry->any)
19383 vty_out(vty, " %s\n",
19384 community_direct_str(entry->direct));
19385 else
19386 vty_out(vty, " %s %s\n",
19387 community_direct_str(entry->direct),
19388 community_list_config_str(entry));
19389 }
19390 }
19391
19392 DEFUN (show_community_list,
19393 show_bgp_community_list_cmd,
19394 "show bgp community-list",
19395 SHOW_STR
19396 BGP_STR
19397 "List community-list\n")
19398 {
19399 struct community_list *list;
19400 struct community_list_master *cm;
19401
19402 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
19403 if (!cm)
19404 return CMD_SUCCESS;
19405
19406 for (list = cm->num.head; list; list = list->next)
19407 community_list_show(vty, list);
19408
19409 for (list = cm->str.head; list; list = list->next)
19410 community_list_show(vty, list);
19411
19412 return CMD_SUCCESS;
19413 }
19414
19415 DEFUN (show_community_list_arg,
19416 show_bgp_community_list_arg_cmd,
19417 "show bgp community-list <(1-500)|WORD> detail",
19418 SHOW_STR
19419 BGP_STR
19420 "List community-list\n"
19421 "Community-list number\n"
19422 "Community-list name\n"
19423 "Detailed information on community-list\n")
19424 {
19425 int idx_comm_list = 3;
19426 struct community_list *list;
19427
19428 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
19429 COMMUNITY_LIST_MASTER);
19430 if (!list) {
19431 vty_out(vty, "%% Can't find community-list\n");
19432 return CMD_WARNING;
19433 }
19434
19435 community_list_show(vty, list);
19436
19437 return CMD_SUCCESS;
19438 }
19439
19440 /*
19441 * Large Community code.
19442 */
19443 static int lcommunity_list_set_vty(struct vty *vty, int argc,
19444 struct cmd_token **argv, int style,
19445 int reject_all_digit_name)
19446 {
19447 int ret;
19448 int direct;
19449 char *str;
19450 int idx = 0;
19451 char *cl_name;
19452 char *seq = NULL;
19453
19454 if (argv_find(argv, argc, "(1-4294967295)", &idx))
19455 seq = argv[idx]->arg;
19456
19457 idx = 0;
19458 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19459 : COMMUNITY_DENY;
19460
19461 /* All digit name check. */
19462 idx = 0;
19463 argv_find(argv, argc, "WORD", &idx);
19464 argv_find(argv, argc, "(1-99)", &idx);
19465 argv_find(argv, argc, "(100-500)", &idx);
19466 cl_name = argv[idx]->arg;
19467 if (reject_all_digit_name && all_digit(cl_name)) {
19468 vty_out(vty, "%% Community name cannot have all digits\n");
19469 return CMD_WARNING_CONFIG_FAILED;
19470 }
19471
19472 idx = 0;
19473 argv_find(argv, argc, "AA:BB:CC", &idx);
19474 argv_find(argv, argc, "LINE", &idx);
19475 /* Concat community string argument. */
19476 if (idx)
19477 str = argv_concat(argv, argc, idx);
19478 else
19479 str = NULL;
19480
19481 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
19482
19483 /* Free temporary community list string allocated by
19484 argv_concat(). */
19485 XFREE(MTYPE_TMP, str);
19486
19487 if (ret < 0) {
19488 community_list_perror(vty, ret);
19489 return CMD_WARNING_CONFIG_FAILED;
19490 }
19491 return CMD_SUCCESS;
19492 }
19493
19494 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
19495 struct cmd_token **argv, int style)
19496 {
19497 int ret;
19498 int direct = 0;
19499 char *str = NULL;
19500 int idx = 0;
19501 char *seq = NULL;
19502
19503 if (argv_find(argv, argc, "(1-4294967295)", &idx))
19504 seq = argv[idx]->arg;
19505
19506 idx = 0;
19507 argv_find(argv, argc, "permit", &idx);
19508 argv_find(argv, argc, "deny", &idx);
19509
19510 if (idx) {
19511 /* Check the list direct. */
19512 if (strncmp(argv[idx]->arg, "p", 1) == 0)
19513 direct = COMMUNITY_PERMIT;
19514 else
19515 direct = COMMUNITY_DENY;
19516
19517 idx = 0;
19518 argv_find(argv, argc, "LINE", &idx);
19519 argv_find(argv, argc, "AA:AA:NN", &idx);
19520 /* Concat community string argument. */
19521 str = argv_concat(argv, argc, idx);
19522 }
19523
19524 idx = 0;
19525 argv_find(argv, argc, "(1-99)", &idx);
19526 argv_find(argv, argc, "(100-500)", &idx);
19527 argv_find(argv, argc, "WORD", &idx);
19528
19529 /* Unset community list. */
19530 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
19531 style);
19532
19533 /* Free temporary community list string allocated by
19534 argv_concat(). */
19535 XFREE(MTYPE_TMP, str);
19536
19537 if (ret < 0) {
19538 community_list_perror(vty, ret);
19539 return CMD_WARNING_CONFIG_FAILED;
19540 }
19541
19542 return CMD_SUCCESS;
19543 }
19544
19545 /* "large-community-list" keyword help string. */
19546 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
19547 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
19548
19549 DEFUN (lcommunity_list_standard,
19550 bgp_lcommunity_list_standard_cmd,
19551 "bgp large-community-list (1-99) [seq (1-4294967295)] <deny|permit> AA:BB:CC...",
19552 BGP_STR
19553 LCOMMUNITY_LIST_STR
19554 "Large Community list number (standard)\n"
19555 "Sequence number of an entry\n"
19556 "Sequence number\n"
19557 "Specify large community to reject\n"
19558 "Specify large community to accept\n"
19559 LCOMMUNITY_VAL_STR)
19560 {
19561 return lcommunity_list_set_vty(vty, argc, argv,
19562 LARGE_COMMUNITY_LIST_STANDARD, 0);
19563 }
19564
19565 DEFUN (lcommunity_list_expanded,
19566 bgp_lcommunity_list_expanded_cmd,
19567 "bgp large-community-list (100-500) [seq (1-4294967295)] <deny|permit> LINE...",
19568 BGP_STR
19569 LCOMMUNITY_LIST_STR
19570 "Large Community list number (expanded)\n"
19571 "Sequence number of an entry\n"
19572 "Sequence number\n"
19573 "Specify large community to reject\n"
19574 "Specify large community to accept\n"
19575 "An ordered list as a regular-expression\n")
19576 {
19577 return lcommunity_list_set_vty(vty, argc, argv,
19578 LARGE_COMMUNITY_LIST_EXPANDED, 0);
19579 }
19580
19581 DEFUN (lcommunity_list_name_standard,
19582 bgp_lcommunity_list_name_standard_cmd,
19583 "bgp large-community-list standard WORD [seq (1-4294967295)] <deny|permit> AA:BB:CC...",
19584 BGP_STR
19585 LCOMMUNITY_LIST_STR
19586 "Specify standard large-community-list\n"
19587 "Large Community list name\n"
19588 "Sequence number of an entry\n"
19589 "Sequence number\n"
19590 "Specify large community to reject\n"
19591 "Specify large community to accept\n"
19592 LCOMMUNITY_VAL_STR)
19593 {
19594 return lcommunity_list_set_vty(vty, argc, argv,
19595 LARGE_COMMUNITY_LIST_STANDARD, 1);
19596 }
19597
19598 DEFUN (lcommunity_list_name_expanded,
19599 bgp_lcommunity_list_name_expanded_cmd,
19600 "bgp large-community-list expanded WORD [seq (1-4294967295)] <deny|permit> LINE...",
19601 BGP_STR
19602 LCOMMUNITY_LIST_STR
19603 "Specify expanded large-community-list\n"
19604 "Large Community list name\n"
19605 "Sequence number of an entry\n"
19606 "Sequence number\n"
19607 "Specify large community to reject\n"
19608 "Specify large community to accept\n"
19609 "An ordered list as a regular-expression\n")
19610 {
19611 return lcommunity_list_set_vty(vty, argc, argv,
19612 LARGE_COMMUNITY_LIST_EXPANDED, 1);
19613 }
19614
19615 DEFUN (no_lcommunity_list_all,
19616 no_bgp_lcommunity_list_all_cmd,
19617 "no bgp large-community-list <(1-99)|(100-500)|WORD>",
19618 NO_STR
19619 BGP_STR
19620 LCOMMUNITY_LIST_STR
19621 "Large Community list number (standard)\n"
19622 "Large Community list number (expanded)\n"
19623 "Large Community list name\n")
19624 {
19625 return lcommunity_list_unset_vty(vty, argc, argv,
19626 LARGE_COMMUNITY_LIST_STANDARD);
19627 }
19628
19629 DEFUN (no_lcommunity_list_name_standard_all,
19630 no_bgp_lcommunity_list_name_standard_all_cmd,
19631 "no bgp large-community-list standard WORD",
19632 NO_STR
19633 BGP_STR
19634 LCOMMUNITY_LIST_STR
19635 "Specify standard large-community-list\n"
19636 "Large Community list name\n")
19637 {
19638 return lcommunity_list_unset_vty(vty, argc, argv,
19639 LARGE_COMMUNITY_LIST_STANDARD);
19640 }
19641
19642 DEFUN (no_lcommunity_list_name_expanded_all,
19643 no_bgp_lcommunity_list_name_expanded_all_cmd,
19644 "no bgp large-community-list expanded WORD",
19645 NO_STR
19646 BGP_STR
19647 LCOMMUNITY_LIST_STR
19648 "Specify expanded large-community-list\n"
19649 "Large Community list name\n")
19650 {
19651 return lcommunity_list_unset_vty(vty, argc, argv,
19652 LARGE_COMMUNITY_LIST_EXPANDED);
19653 }
19654
19655 DEFUN (no_lcommunity_list_standard,
19656 no_bgp_lcommunity_list_standard_cmd,
19657 "no bgp large-community-list (1-99) [seq (1-4294967295)] <deny|permit> AA:AA:NN...",
19658 NO_STR
19659 BGP_STR
19660 LCOMMUNITY_LIST_STR
19661 "Large Community list number (standard)\n"
19662 "Sequence number of an entry\n"
19663 "Sequence number\n"
19664 "Specify large community to reject\n"
19665 "Specify large community to accept\n"
19666 LCOMMUNITY_VAL_STR)
19667 {
19668 return lcommunity_list_unset_vty(vty, argc, argv,
19669 LARGE_COMMUNITY_LIST_STANDARD);
19670 }
19671
19672 DEFUN (no_lcommunity_list_expanded,
19673 no_bgp_lcommunity_list_expanded_cmd,
19674 "no bgp large-community-list (100-500) [seq (1-4294967295)] <deny|permit> LINE...",
19675 NO_STR
19676 BGP_STR
19677 LCOMMUNITY_LIST_STR
19678 "Large Community list number (expanded)\n"
19679 "Sequence number of an entry\n"
19680 "Sequence number\n"
19681 "Specify large community to reject\n"
19682 "Specify large community to accept\n"
19683 "An ordered list as a regular-expression\n")
19684 {
19685 return lcommunity_list_unset_vty(vty, argc, argv,
19686 LARGE_COMMUNITY_LIST_EXPANDED);
19687 }
19688
19689 DEFUN (no_lcommunity_list_name_standard,
19690 no_bgp_lcommunity_list_name_standard_cmd,
19691 "no bgp large-community-list standard WORD [seq (1-4294967295)] <deny|permit> AA:AA:NN...",
19692 NO_STR
19693 BGP_STR
19694 LCOMMUNITY_LIST_STR
19695 "Specify standard large-community-list\n"
19696 "Large Community list name\n"
19697 "Sequence number of an entry\n"
19698 "Sequence number\n"
19699 "Specify large community to reject\n"
19700 "Specify large community to accept\n"
19701 LCOMMUNITY_VAL_STR)
19702 {
19703 return lcommunity_list_unset_vty(vty, argc, argv,
19704 LARGE_COMMUNITY_LIST_STANDARD);
19705 }
19706
19707 DEFUN (no_lcommunity_list_name_expanded,
19708 no_bgp_lcommunity_list_name_expanded_cmd,
19709 "no bgp large-community-list expanded WORD [seq (1-4294967295)] <deny|permit> LINE...",
19710 NO_STR
19711 BGP_STR
19712 LCOMMUNITY_LIST_STR
19713 "Specify expanded large-community-list\n"
19714 "Large community list name\n"
19715 "Sequence number of an entry\n"
19716 "Sequence number\n"
19717 "Specify large community to reject\n"
19718 "Specify large community to accept\n"
19719 "An ordered list as a regular-expression\n")
19720 {
19721 return lcommunity_list_unset_vty(vty, argc, argv,
19722 LARGE_COMMUNITY_LIST_EXPANDED);
19723 }
19724
19725 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
19726 {
19727 struct community_entry *entry;
19728
19729 for (entry = list->head; entry; entry = entry->next) {
19730 if (entry == list->head) {
19731 if (all_digit(list->name))
19732 vty_out(vty, "Large community %s list %s\n",
19733 entry->style ==
19734 LARGE_COMMUNITY_LIST_STANDARD
19735 ? "standard"
19736 : "(expanded) access",
19737 list->name);
19738 else
19739 vty_out(vty,
19740 "Named large community %s list %s\n",
19741 entry->style ==
19742 LARGE_COMMUNITY_LIST_STANDARD
19743 ? "standard"
19744 : "expanded",
19745 list->name);
19746 }
19747 if (entry->any)
19748 vty_out(vty, " %s\n",
19749 community_direct_str(entry->direct));
19750 else
19751 vty_out(vty, " %s %s\n",
19752 community_direct_str(entry->direct),
19753 community_list_config_str(entry));
19754 }
19755 }
19756
19757 DEFUN (show_lcommunity_list,
19758 show_bgp_lcommunity_list_cmd,
19759 "show bgp large-community-list",
19760 SHOW_STR
19761 BGP_STR
19762 "List large-community list\n")
19763 {
19764 struct community_list *list;
19765 struct community_list_master *cm;
19766
19767 cm = community_list_master_lookup(bgp_clist,
19768 LARGE_COMMUNITY_LIST_MASTER);
19769 if (!cm)
19770 return CMD_SUCCESS;
19771
19772 for (list = cm->num.head; list; list = list->next)
19773 lcommunity_list_show(vty, list);
19774
19775 for (list = cm->str.head; list; list = list->next)
19776 lcommunity_list_show(vty, list);
19777
19778 return CMD_SUCCESS;
19779 }
19780
19781 DEFUN (show_lcommunity_list_arg,
19782 show_bgp_lcommunity_list_arg_cmd,
19783 "show bgp large-community-list <(1-500)|WORD> detail",
19784 SHOW_STR
19785 BGP_STR
19786 "List large-community list\n"
19787 "Large-community-list number\n"
19788 "Large-community-list name\n"
19789 "Detailed information on large-community-list\n")
19790 {
19791 struct community_list *list;
19792
19793 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
19794 LARGE_COMMUNITY_LIST_MASTER);
19795 if (!list) {
19796 vty_out(vty, "%% Can't find large-community-list\n");
19797 return CMD_WARNING;
19798 }
19799
19800 lcommunity_list_show(vty, list);
19801
19802 return CMD_SUCCESS;
19803 }
19804
19805 /* "extcommunity-list" keyword help string. */
19806 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
19807 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
19808
19809 DEFUN (extcommunity_list_standard,
19810 bgp_extcommunity_list_standard_cmd,
19811 "bgp extcommunity-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
19812 BGP_STR
19813 EXTCOMMUNITY_LIST_STR
19814 "Extended Community list number (standard)\n"
19815 "Specify standard extcommunity-list\n"
19816 "Community list name\n"
19817 "Sequence number of an entry\n"
19818 "Sequence number\n"
19819 "Specify community to reject\n"
19820 "Specify community to accept\n"
19821 EXTCOMMUNITY_VAL_STR)
19822 {
19823 int style = EXTCOMMUNITY_LIST_STANDARD;
19824 int direct = 0;
19825 char *cl_number_or_name = NULL;
19826 char *seq = NULL;
19827
19828 int idx = 0;
19829
19830 argv_find(argv, argc, "(1-99)", &idx);
19831 argv_find(argv, argc, "WORD", &idx);
19832 cl_number_or_name = argv[idx]->arg;
19833
19834 if (argv_find(argv, argc, "(1-4294967295)", &idx))
19835 seq = argv[idx]->arg;
19836
19837 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19838 : COMMUNITY_DENY;
19839 argv_find(argv, argc, "AA:NN", &idx);
19840 char *str = argv_concat(argv, argc, idx);
19841
19842 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
19843 direct, style);
19844
19845 XFREE(MTYPE_TMP, str);
19846
19847 if (ret < 0) {
19848 community_list_perror(vty, ret);
19849 return CMD_WARNING_CONFIG_FAILED;
19850 }
19851
19852 return CMD_SUCCESS;
19853 }
19854
19855 DEFUN (extcommunity_list_name_expanded,
19856 bgp_extcommunity_list_name_expanded_cmd,
19857 "bgp extcommunity-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> LINE...",
19858 BGP_STR
19859 EXTCOMMUNITY_LIST_STR
19860 "Extended Community list number (expanded)\n"
19861 "Specify expanded extcommunity-list\n"
19862 "Extended Community list name\n"
19863 "Sequence number of an entry\n"
19864 "Sequence number\n"
19865 "Specify community to reject\n"
19866 "Specify community to accept\n"
19867 "An ordered list as a regular-expression\n")
19868 {
19869 int style = EXTCOMMUNITY_LIST_EXPANDED;
19870 int direct = 0;
19871 char *cl_number_or_name = NULL;
19872 char *seq = NULL;
19873 int idx = 0;
19874
19875 argv_find(argv, argc, "(100-500)", &idx);
19876 argv_find(argv, argc, "WORD", &idx);
19877 cl_number_or_name = argv[idx]->arg;
19878
19879 if (argv_find(argv, argc, "(1-4294967295)", &idx))
19880 seq = argv[idx]->arg;
19881
19882 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19883 : COMMUNITY_DENY;
19884 argv_find(argv, argc, "LINE", &idx);
19885 char *str = argv_concat(argv, argc, idx);
19886
19887 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
19888 direct, style);
19889
19890 XFREE(MTYPE_TMP, str);
19891
19892 if (ret < 0) {
19893 community_list_perror(vty, ret);
19894 return CMD_WARNING_CONFIG_FAILED;
19895 }
19896
19897 return CMD_SUCCESS;
19898 }
19899
19900 DEFUN (no_extcommunity_list_standard_all,
19901 no_bgp_extcommunity_list_standard_all_cmd,
19902 "no bgp extcommunity-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
19903 NO_STR
19904 BGP_STR
19905 EXTCOMMUNITY_LIST_STR
19906 "Extended Community list number (standard)\n"
19907 "Specify standard extcommunity-list\n"
19908 "Community list name\n"
19909 "Sequence number of an entry\n"
19910 "Sequence number\n"
19911 "Specify community to reject\n"
19912 "Specify community to accept\n"
19913 EXTCOMMUNITY_VAL_STR)
19914 {
19915 int style = EXTCOMMUNITY_LIST_STANDARD;
19916 int direct = 0;
19917 char *cl_number_or_name = NULL;
19918 char *str = NULL;
19919 char *seq = NULL;
19920 int idx = 0;
19921
19922 if (argv_find(argv, argc, "(1-4294967295)", &idx))
19923 seq = argv[idx]->arg;
19924
19925 idx = 0;
19926 argv_find(argv, argc, "permit", &idx);
19927 argv_find(argv, argc, "deny", &idx);
19928 if (idx) {
19929 direct = argv_find(argv, argc, "permit", &idx)
19930 ? COMMUNITY_PERMIT
19931 : COMMUNITY_DENY;
19932
19933 idx = 0;
19934 argv_find(argv, argc, "AA:NN", &idx);
19935 str = argv_concat(argv, argc, idx);
19936 }
19937
19938 idx = 0;
19939 argv_find(argv, argc, "(1-99)", &idx);
19940 argv_find(argv, argc, "WORD", &idx);
19941 cl_number_or_name = argv[idx]->arg;
19942
19943 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
19944 seq, direct, style);
19945
19946 XFREE(MTYPE_TMP, str);
19947
19948 if (ret < 0) {
19949 community_list_perror(vty, ret);
19950 return CMD_WARNING_CONFIG_FAILED;
19951 }
19952
19953 return CMD_SUCCESS;
19954 }
19955
19956 ALIAS(no_extcommunity_list_standard_all,
19957 no_bgp_extcommunity_list_standard_all_list_cmd,
19958 "no bgp extcommunity-list <(1-99)|standard WORD>",
19959 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
19960 "Extended Community list number (standard)\n"
19961 "Specify standard extcommunity-list\n"
19962 "Community list name\n")
19963
19964 DEFUN (no_extcommunity_list_expanded_all,
19965 no_bgp_extcommunity_list_expanded_all_cmd,
19966 "no bgp extcommunity-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> LINE...",
19967 NO_STR
19968 BGP_STR
19969 EXTCOMMUNITY_LIST_STR
19970 "Extended Community list number (expanded)\n"
19971 "Specify expanded extcommunity-list\n"
19972 "Extended Community list name\n"
19973 "Sequence number of an entry\n"
19974 "Sequence number\n"
19975 "Specify community to reject\n"
19976 "Specify community to accept\n"
19977 "An ordered list as a regular-expression\n")
19978 {
19979 int style = EXTCOMMUNITY_LIST_EXPANDED;
19980 int direct = 0;
19981 char *cl_number_or_name = NULL;
19982 char *str = NULL;
19983 char *seq = NULL;
19984 int idx = 0;
19985
19986 if (argv_find(argv, argc, "(1-4294967295)", &idx))
19987 seq = argv[idx]->arg;
19988
19989 idx = 0;
19990 argv_find(argv, argc, "permit", &idx);
19991 argv_find(argv, argc, "deny", &idx);
19992
19993 if (idx) {
19994 direct = argv_find(argv, argc, "permit", &idx)
19995 ? COMMUNITY_PERMIT
19996 : COMMUNITY_DENY;
19997
19998 idx = 0;
19999 argv_find(argv, argc, "LINE", &idx);
20000 str = argv_concat(argv, argc, idx);
20001 }
20002
20003 idx = 0;
20004 argv_find(argv, argc, "(100-500)", &idx);
20005 argv_find(argv, argc, "WORD", &idx);
20006 cl_number_or_name = argv[idx]->arg;
20007
20008 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
20009 seq, direct, style);
20010
20011 XFREE(MTYPE_TMP, str);
20012
20013 if (ret < 0) {
20014 community_list_perror(vty, ret);
20015 return CMD_WARNING_CONFIG_FAILED;
20016 }
20017
20018 return CMD_SUCCESS;
20019 }
20020
20021 ALIAS(no_extcommunity_list_expanded_all,
20022 no_bgp_extcommunity_list_expanded_all_list_cmd,
20023 "no bgp extcommunity-list <(100-500)|expanded WORD>",
20024 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
20025 "Extended Community list number (expanded)\n"
20026 "Specify expanded extcommunity-list\n"
20027 "Extended Community list name\n")
20028
20029 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
20030 {
20031 struct community_entry *entry;
20032
20033 for (entry = list->head; entry; entry = entry->next) {
20034 if (entry == list->head) {
20035 if (all_digit(list->name))
20036 vty_out(vty, "Extended community %s list %s\n",
20037 entry->style == EXTCOMMUNITY_LIST_STANDARD
20038 ? "standard"
20039 : "(expanded) access",
20040 list->name);
20041 else
20042 vty_out(vty,
20043 "Named extended community %s list %s\n",
20044 entry->style == EXTCOMMUNITY_LIST_STANDARD
20045 ? "standard"
20046 : "expanded",
20047 list->name);
20048 }
20049 if (entry->any)
20050 vty_out(vty, " %s\n",
20051 community_direct_str(entry->direct));
20052 else
20053 vty_out(vty, " %s %s\n",
20054 community_direct_str(entry->direct),
20055 community_list_config_str(entry));
20056 }
20057 }
20058
20059 DEFUN (show_extcommunity_list,
20060 show_bgp_extcommunity_list_cmd,
20061 "show bgp extcommunity-list",
20062 SHOW_STR
20063 BGP_STR
20064 "List extended-community list\n")
20065 {
20066 struct community_list *list;
20067 struct community_list_master *cm;
20068
20069 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
20070 if (!cm)
20071 return CMD_SUCCESS;
20072
20073 for (list = cm->num.head; list; list = list->next)
20074 extcommunity_list_show(vty, list);
20075
20076 for (list = cm->str.head; list; list = list->next)
20077 extcommunity_list_show(vty, list);
20078
20079 return CMD_SUCCESS;
20080 }
20081
20082 DEFUN (show_extcommunity_list_arg,
20083 show_bgp_extcommunity_list_arg_cmd,
20084 "show bgp extcommunity-list <(1-500)|WORD> detail",
20085 SHOW_STR
20086 BGP_STR
20087 "List extended-community list\n"
20088 "Extcommunity-list number\n"
20089 "Extcommunity-list name\n"
20090 "Detailed information on extcommunity-list\n")
20091 {
20092 int idx_comm_list = 3;
20093 struct community_list *list;
20094
20095 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
20096 EXTCOMMUNITY_LIST_MASTER);
20097 if (!list) {
20098 vty_out(vty, "%% Can't find extcommunity-list\n");
20099 return CMD_WARNING;
20100 }
20101
20102 extcommunity_list_show(vty, list);
20103
20104 return CMD_SUCCESS;
20105 }
20106
20107 /* Display community-list and extcommunity-list configuration. */
20108 static int community_list_config_write(struct vty *vty)
20109 {
20110 struct community_list *list;
20111 struct community_entry *entry;
20112 struct community_list_master *cm;
20113 int write = 0;
20114
20115 /* Community-list. */
20116 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
20117
20118 for (list = cm->num.head; list; list = list->next)
20119 for (entry = list->head; entry; entry = entry->next) {
20120 vty_out(vty,
20121 "bgp community-list %s seq %" PRId64 " %s %s\n",
20122 list->name, entry->seq,
20123 community_direct_str(entry->direct),
20124 community_list_config_str(entry));
20125 write++;
20126 }
20127 for (list = cm->str.head; list; list = list->next)
20128 for (entry = list->head; entry; entry = entry->next) {
20129 vty_out(vty,
20130 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
20131 entry->style == COMMUNITY_LIST_STANDARD
20132 ? "standard"
20133 : "expanded",
20134 list->name, entry->seq,
20135 community_direct_str(entry->direct),
20136 community_list_config_str(entry));
20137 write++;
20138 }
20139
20140 /* Extcommunity-list. */
20141 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
20142
20143 for (list = cm->num.head; list; list = list->next)
20144 for (entry = list->head; entry; entry = entry->next) {
20145 vty_out(vty,
20146 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
20147 list->name, entry->seq,
20148 community_direct_str(entry->direct),
20149 community_list_config_str(entry));
20150 write++;
20151 }
20152 for (list = cm->str.head; list; list = list->next)
20153 for (entry = list->head; entry; entry = entry->next) {
20154 vty_out(vty,
20155 "bgp extcommunity-list %s %s seq %" PRId64" %s %s\n",
20156 entry->style == EXTCOMMUNITY_LIST_STANDARD
20157 ? "standard"
20158 : "expanded",
20159 list->name, entry->seq,
20160 community_direct_str(entry->direct),
20161 community_list_config_str(entry));
20162 write++;
20163 }
20164
20165
20166 /* lcommunity-list. */
20167 cm = community_list_master_lookup(bgp_clist,
20168 LARGE_COMMUNITY_LIST_MASTER);
20169
20170 for (list = cm->num.head; list; list = list->next)
20171 for (entry = list->head; entry; entry = entry->next) {
20172 vty_out(vty,
20173 "bgp large-community-list %s seq %" PRId64" %s %s\n",
20174 list->name, entry->seq,
20175 community_direct_str(entry->direct),
20176 community_list_config_str(entry));
20177 write++;
20178 }
20179 for (list = cm->str.head; list; list = list->next)
20180 for (entry = list->head; entry; entry = entry->next) {
20181 vty_out(vty,
20182 "bgp large-community-list %s %s seq %" PRId64" %s %s\n",
20183
20184 entry->style == LARGE_COMMUNITY_LIST_STANDARD
20185 ? "standard"
20186 : "expanded",
20187 list->name, entry->seq, community_direct_str(entry->direct),
20188 community_list_config_str(entry));
20189 write++;
20190 }
20191
20192 return write;
20193 }
20194
20195 static int community_list_config_write(struct vty *vty);
20196 static struct cmd_node community_list_node = {
20197 .name = "community list",
20198 .node = COMMUNITY_LIST_NODE,
20199 .prompt = "",
20200 .config_write = community_list_config_write,
20201 };
20202
20203 static void community_list_vty(void)
20204 {
20205 install_node(&community_list_node);
20206
20207 /* Community-list. */
20208 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
20209 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
20210 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
20211 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
20212 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
20213 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
20214 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
20215 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
20216
20217 /* Extcommunity-list. */
20218 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
20219 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
20220 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
20221 install_element(CONFIG_NODE,
20222 &no_bgp_extcommunity_list_standard_all_list_cmd);
20223 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
20224 install_element(CONFIG_NODE,
20225 &no_bgp_extcommunity_list_expanded_all_list_cmd);
20226 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
20227 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
20228
20229 /* Large Community List */
20230 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
20231 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
20232 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
20233 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
20234 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
20235 install_element(CONFIG_NODE,
20236 &no_bgp_lcommunity_list_name_standard_all_cmd);
20237 install_element(CONFIG_NODE,
20238 &no_bgp_lcommunity_list_name_expanded_all_cmd);
20239 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
20240 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
20241 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
20242 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
20243 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
20244 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
20245 }