]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
Merge pull request #7652 from adharkar/frr-vni_switch
[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_YANG (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 int idx_peer = 1;
4964 int idx_word = 3;
4965 char base_xpath[XPATH_MAXLEN];
4966
4967 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4968 sizeof(base_xpath), NULL)
4969 < 0)
4970 return CMD_WARNING_CONFIG_FAILED;
4971
4972 nb_cli_enqueue_change(vty, "./peer-group", NB_OP_MODIFY,
4973 argv[idx_word]->arg);
4974
4975 return nb_cli_apply_changes(vty, base_xpath);
4976 }
4977
4978 ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
4979 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
4980 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4981 "Member of the peer-group\n"
4982 "Peer-group name\n")
4983
4984 DEFUN_YANG (no_neighbor_set_peer_group,
4985 no_neighbor_set_peer_group_cmd,
4986 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
4987 NO_STR
4988 NEIGHBOR_STR
4989 NEIGHBOR_ADDR_STR2
4990 "Member of the peer-group\n"
4991 "Peer-group name\n")
4992 {
4993 int idx_peer = 2;
4994 char base_xpath[XPATH_MAXLEN];
4995
4996 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4997 sizeof(base_xpath), NULL)
4998 < 0)
4999 return CMD_WARNING_CONFIG_FAILED;
5000
5001 nb_cli_enqueue_change(vty, "./peer-group", NB_OP_DESTROY, NULL);
5002
5003 return nb_cli_apply_changes(vty, base_xpath);
5004 }
5005
5006 ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
5007 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5008 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5009 "Member of the peer-group\n"
5010 "Peer-group name\n")
5011
5012 static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
5013 uint32_t flag, int set)
5014 {
5015 int ret;
5016 struct peer *peer;
5017
5018 peer = peer_and_group_lookup_vty(vty, ip_str);
5019 if (!peer)
5020 return CMD_WARNING_CONFIG_FAILED;
5021
5022 /*
5023 * If 'neighbor <interface>', then this is for directly connected peers,
5024 * we should not accept disable-connected-check.
5025 */
5026 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
5027 vty_out(vty,
5028 "%s is directly connected peer, cannot accept disable-connected-check\n",
5029 ip_str);
5030 return CMD_WARNING_CONFIG_FAILED;
5031 }
5032
5033 if (!set && flag == PEER_FLAG_SHUTDOWN)
5034 peer_tx_shutdown_message_unset(peer);
5035
5036 if (set)
5037 ret = peer_flag_set(peer, flag);
5038 else
5039 ret = peer_flag_unset(peer, flag);
5040
5041 return bgp_vty_return(vty, ret);
5042 }
5043
5044 static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
5045 {
5046 return peer_flag_modify_vty(vty, ip_str, flag, 1);
5047 }
5048
5049 static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
5050 uint32_t flag)
5051 {
5052 return peer_flag_modify_vty(vty, ip_str, flag, 0);
5053 }
5054
5055 int peer_flag_modify_nb(struct bgp *bgp, const char *ip_str, struct peer *peer,
5056 uint32_t flag, bool set, char *errmsg,
5057 size_t errmsg_len)
5058 {
5059 int ret;
5060
5061 /*
5062 * If 'neighbor <interface>', then this is for directly connected peers,
5063 * we should not accept disable-connected-check.
5064 */
5065 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
5066 snprintf(
5067 errmsg, errmsg_len,
5068 "%s is directly connected peer, cannot accept disable-connected-check\n",
5069 ip_str);
5070 return -1;
5071 }
5072
5073 if (!set && flag == PEER_FLAG_SHUTDOWN)
5074 peer_tx_shutdown_message_unset(peer);
5075
5076 if (set)
5077 ret = peer_flag_set(peer, flag);
5078 else
5079 ret = peer_flag_unset(peer, flag);
5080
5081 return bgp_nb_errmsg_return(errmsg, errmsg_len, ret);
5082 }
5083
5084 /* neighbor passive. */
5085 DEFUN_YANG(neighbor_passive,
5086 neighbor_passive_cmd,
5087 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5088 NEIGHBOR_STR
5089 NEIGHBOR_ADDR_STR2
5090 "Don't send open messages to this neighbor\n")
5091 {
5092 int idx_peer = 1;
5093 char base_xpath[XPATH_MAXLEN];
5094
5095 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5096 sizeof(base_xpath), NULL)
5097 < 0)
5098 return CMD_WARNING_CONFIG_FAILED;
5099
5100 nb_cli_enqueue_change(vty, "./passive-mode", NB_OP_MODIFY, "true");
5101
5102 return nb_cli_apply_changes(vty, base_xpath);
5103 }
5104
5105 DEFUN_YANG(no_neighbor_passive,
5106 no_neighbor_passive_cmd,
5107 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5108 NO_STR NEIGHBOR_STR
5109 NEIGHBOR_ADDR_STR2
5110 "Don't send open messages to this neighbor\n")
5111 {
5112 int idx_peer = 2;
5113 char base_xpath[XPATH_MAXLEN];
5114
5115 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5116 sizeof(base_xpath), NULL)
5117 < 0)
5118 return CMD_WARNING_CONFIG_FAILED;
5119
5120 nb_cli_enqueue_change(vty, "./passive-mode", NB_OP_MODIFY, "false");
5121
5122 return nb_cli_apply_changes(vty, base_xpath);
5123 }
5124
5125 /* neighbor shutdown. */
5126 DEFUN_YANG(neighbor_shutdown_msg,
5127 neighbor_shutdown_msg_cmd,
5128 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5129 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5130 "Administratively shut down this neighbor\n"
5131 "Add a shutdown message (RFC 8203)\n"
5132 "Shutdown message\n")
5133 {
5134 int idx_peer = 1;
5135 char base_xpath[XPATH_MAXLEN];
5136
5137 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5138 sizeof(base_xpath), NULL)
5139 < 0)
5140 return CMD_WARNING_CONFIG_FAILED;
5141
5142 if (argc >= 5) {
5143 char *message;
5144
5145 message = argv_concat(argv, argc, 4);
5146 nb_cli_enqueue_change(vty, "./admin-shutdown/message",
5147 NB_OP_MODIFY, message);
5148 }
5149
5150 nb_cli_enqueue_change(vty, "./admin-shutdown/enable", NB_OP_MODIFY,
5151 "true");
5152
5153 return nb_cli_apply_changes(vty, base_xpath);
5154 }
5155
5156 ALIAS_YANG(neighbor_shutdown_msg, neighbor_shutdown_cmd,
5157 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5158 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5159 "Administratively shut down this neighbor\n")
5160
5161 DEFUN_YANG(no_neighbor_shutdown_msg,
5162 no_neighbor_shutdown_msg_cmd,
5163 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5164 NO_STR NEIGHBOR_STR
5165 NEIGHBOR_ADDR_STR2
5166 "Administratively shut down this neighbor\n"
5167 "Remove a shutdown message (RFC 8203)\n"
5168 "Shutdown message\n")
5169 {
5170 int idx_peer = 2;
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 nb_cli_enqueue_change(vty, "./admin-shutdown/enable", NB_OP_MODIFY,
5179 "false");
5180
5181 return nb_cli_apply_changes(vty, base_xpath);
5182 }
5183
5184 ALIAS_YANG(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
5185 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5186 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5187 "Administratively shut down this neighbor\n")
5188
5189 DEFUN(neighbor_shutdown_rtt,
5190 neighbor_shutdown_rtt_cmd,
5191 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt (1-65535) [count (1-255)]",
5192 NEIGHBOR_STR
5193 NEIGHBOR_ADDR_STR2
5194 "Administratively shut down this neighbor\n"
5195 "Shutdown if round-trip-time is higher than expected\n"
5196 "Round-trip-time in milliseconds\n"
5197 "Specify the number of keepalives before shutdown\n"
5198 "The number of keepalives with higher RTT to shutdown\n")
5199 {
5200 int idx_peer = 1;
5201 int idx_rtt = 4;
5202 int idx_count = 0;
5203 struct peer *peer;
5204
5205 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5206
5207 if (!peer)
5208 return CMD_WARNING_CONFIG_FAILED;
5209
5210 peer->rtt_expected = strtol(argv[idx_rtt]->arg, NULL, 10);
5211
5212 if (argv_find(argv, argc, "count", &idx_count))
5213 peer->rtt_keepalive_conf =
5214 strtol(argv[idx_count + 1]->arg, NULL, 10);
5215
5216 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5217 PEER_FLAG_RTT_SHUTDOWN);
5218 }
5219
5220 DEFUN(no_neighbor_shutdown_rtt,
5221 no_neighbor_shutdown_rtt_cmd,
5222 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt [(1-65535) [count (1-255)]]",
5223 NO_STR
5224 NEIGHBOR_STR
5225 NEIGHBOR_ADDR_STR2
5226 "Administratively shut down this neighbor\n"
5227 "Shutdown if round-trip-time is higher than expected\n"
5228 "Round-trip-time in milliseconds\n"
5229 "Specify the number of keepalives before shutdown\n"
5230 "The number of keepalives with higher RTT to shutdown\n")
5231 {
5232 int idx_peer = 2;
5233 struct peer *peer;
5234
5235 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5236
5237 if (!peer)
5238 return CMD_WARNING_CONFIG_FAILED;
5239
5240 peer->rtt_expected = 0;
5241 peer->rtt_keepalive_conf = 1;
5242
5243 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5244 PEER_FLAG_RTT_SHUTDOWN);
5245 }
5246
5247 /* neighbor capability dynamic. */
5248 DEFUN_YANG (neighbor_capability_dynamic,
5249 neighbor_capability_dynamic_cmd,
5250 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5251 NEIGHBOR_STR
5252 NEIGHBOR_ADDR_STR2
5253 "Advertise capability to the peer\n"
5254 "Advertise dynamic capability to this neighbor\n")
5255 {
5256 int idx_peer = 1;
5257 char base_xpath[XPATH_MAXLEN];
5258
5259 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5260 sizeof(base_xpath), NULL)
5261 < 0)
5262 return CMD_WARNING_CONFIG_FAILED;
5263
5264 nb_cli_enqueue_change(vty, "./capability-options/dynamic-capability",
5265 NB_OP_MODIFY, "true");
5266
5267 return nb_cli_apply_changes(vty, base_xpath);
5268 }
5269
5270 DEFUN_YANG (no_neighbor_capability_dynamic,
5271 no_neighbor_capability_dynamic_cmd,
5272 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5273 NO_STR
5274 NEIGHBOR_STR
5275 NEIGHBOR_ADDR_STR2
5276 "Advertise capability to the peer\n"
5277 "Advertise dynamic capability to this neighbor\n")
5278 {
5279 int idx_peer = 2;
5280 char base_xpath[XPATH_MAXLEN];
5281
5282 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5283 sizeof(base_xpath), NULL)
5284 < 0)
5285 return CMD_WARNING_CONFIG_FAILED;
5286
5287 nb_cli_enqueue_change(vty, "./capability-options/dynamic-capability",
5288 NB_OP_MODIFY, "false");
5289
5290 return nb_cli_apply_changes(vty, base_xpath);
5291 }
5292
5293 /* neighbor dont-capability-negotiate */
5294 DEFUN (neighbor_dont_capability_negotiate,
5295 neighbor_dont_capability_negotiate_cmd,
5296 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
5297 NEIGHBOR_STR
5298 NEIGHBOR_ADDR_STR2
5299 "Do not perform capability negotiation\n")
5300 {
5301 int idx_peer = 1;
5302 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5303 PEER_FLAG_DONT_CAPABILITY);
5304 }
5305
5306 DEFUN (no_neighbor_dont_capability_negotiate,
5307 no_neighbor_dont_capability_negotiate_cmd,
5308 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
5309 NO_STR
5310 NEIGHBOR_STR
5311 NEIGHBOR_ADDR_STR2
5312 "Do not perform capability negotiation\n")
5313 {
5314 int idx_peer = 2;
5315 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5316 PEER_FLAG_DONT_CAPABILITY);
5317 }
5318
5319 /* neighbor capability extended next hop encoding */
5320 DEFUN_YANG (neighbor_capability_enhe,
5321 neighbor_capability_enhe_cmd,
5322 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5323 NEIGHBOR_STR
5324 NEIGHBOR_ADDR_STR2
5325 "Advertise capability to the peer\n"
5326 "Advertise extended next-hop capability to the peer\n")
5327 {
5328 int idx_peer = 1;
5329 char base_xpath[XPATH_MAXLEN];
5330
5331 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5332 sizeof(base_xpath), NULL)
5333 < 0)
5334 return CMD_WARNING_CONFIG_FAILED;
5335
5336 nb_cli_enqueue_change(
5337 vty, "./capability-options/extended-nexthop-capability",
5338 NB_OP_MODIFY, "true");
5339
5340 return nb_cli_apply_changes(vty, base_xpath);
5341 }
5342
5343 DEFUN_YANG (no_neighbor_capability_enhe,
5344 no_neighbor_capability_enhe_cmd,
5345 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5346 NO_STR
5347 NEIGHBOR_STR
5348 NEIGHBOR_ADDR_STR2
5349 "Advertise capability to the peer\n"
5350 "Advertise extended next-hop capability to the peer\n")
5351 {
5352 int idx_peer = 2;
5353 char base_xpath[XPATH_MAXLEN];
5354
5355 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5356 sizeof(base_xpath), NULL)
5357 < 0)
5358 return CMD_WARNING_CONFIG_FAILED;
5359
5360 nb_cli_enqueue_change(
5361 vty, "./capability-options/extended-nexthop-capability",
5362 NB_OP_MODIFY, "false");
5363
5364 return nb_cli_apply_changes(vty, base_xpath);
5365 }
5366
5367 int peer_af_flag_modify_nb(struct peer *peer, afi_t afi, safi_t safi,
5368 uint32_t flag, int set, char *errmsg,
5369 size_t errmsg_len)
5370 {
5371 int ret;
5372
5373 if (set)
5374 ret = peer_af_flag_set(peer, afi, safi, flag);
5375 else
5376 ret = peer_af_flag_unset(peer, afi, safi, flag);
5377
5378 return bgp_nb_errmsg_return(errmsg, errmsg_len, ret);
5379 }
5380
5381 static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
5382 afi_t afi, safi_t safi, uint32_t flag,
5383 int set)
5384 {
5385 int ret;
5386 struct peer *peer;
5387
5388 peer = peer_and_group_lookup_vty(vty, peer_str);
5389 if (!peer)
5390 return CMD_WARNING_CONFIG_FAILED;
5391
5392 if (set)
5393 ret = peer_af_flag_set(peer, afi, safi, flag);
5394 else
5395 ret = peer_af_flag_unset(peer, afi, safi, flag);
5396
5397 return bgp_vty_return(vty, ret);
5398 }
5399
5400 static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
5401 afi_t afi, safi_t safi, uint32_t flag)
5402 {
5403 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
5404 }
5405
5406 static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
5407 afi_t afi, safi_t safi, uint32_t flag)
5408 {
5409 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
5410 }
5411
5412 /* neighbor capability orf prefix-list. */
5413 DEFUN (neighbor_capability_orf_prefix,
5414 neighbor_capability_orf_prefix_cmd,
5415 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5416 NEIGHBOR_STR
5417 NEIGHBOR_ADDR_STR2
5418 "Advertise capability to the peer\n"
5419 "Advertise ORF capability to the peer\n"
5420 "Advertise prefixlist ORF capability to this neighbor\n"
5421 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5422 "Capability to RECEIVE the ORF from this neighbor\n"
5423 "Capability to SEND the ORF to this neighbor\n")
5424 {
5425 int idx_send_recv = 5;
5426 char *peer_str = argv[1]->arg;
5427 struct peer *peer;
5428 afi_t afi = bgp_node_afi(vty);
5429 safi_t safi = bgp_node_safi(vty);
5430
5431 peer = peer_and_group_lookup_vty(vty, peer_str);
5432 if (!peer)
5433 return CMD_WARNING_CONFIG_FAILED;
5434
5435 if (strmatch(argv[idx_send_recv]->text, "send"))
5436 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5437 PEER_FLAG_ORF_PREFIX_SM);
5438
5439 if (strmatch(argv[idx_send_recv]->text, "receive"))
5440 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5441 PEER_FLAG_ORF_PREFIX_RM);
5442
5443 if (strmatch(argv[idx_send_recv]->text, "both"))
5444 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5445 PEER_FLAG_ORF_PREFIX_SM)
5446 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5447 PEER_FLAG_ORF_PREFIX_RM);
5448
5449 return CMD_WARNING_CONFIG_FAILED;
5450 }
5451
5452 ALIAS_HIDDEN(
5453 neighbor_capability_orf_prefix,
5454 neighbor_capability_orf_prefix_hidden_cmd,
5455 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5456 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5457 "Advertise capability to the peer\n"
5458 "Advertise ORF capability to the peer\n"
5459 "Advertise prefixlist ORF capability to this neighbor\n"
5460 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5461 "Capability to RECEIVE the ORF from this neighbor\n"
5462 "Capability to SEND the ORF to this neighbor\n")
5463
5464 DEFUN (no_neighbor_capability_orf_prefix,
5465 no_neighbor_capability_orf_prefix_cmd,
5466 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5467 NO_STR
5468 NEIGHBOR_STR
5469 NEIGHBOR_ADDR_STR2
5470 "Advertise capability to the peer\n"
5471 "Advertise ORF capability to the peer\n"
5472 "Advertise prefixlist ORF capability to this neighbor\n"
5473 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5474 "Capability to RECEIVE the ORF from this neighbor\n"
5475 "Capability to SEND the ORF to this neighbor\n")
5476 {
5477 int idx_send_recv = 6;
5478 char *peer_str = argv[2]->arg;
5479 struct peer *peer;
5480 afi_t afi = bgp_node_afi(vty);
5481 safi_t safi = bgp_node_safi(vty);
5482
5483 peer = peer_and_group_lookup_vty(vty, peer_str);
5484 if (!peer)
5485 return CMD_WARNING_CONFIG_FAILED;
5486
5487 if (strmatch(argv[idx_send_recv]->text, "send"))
5488 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5489 PEER_FLAG_ORF_PREFIX_SM);
5490
5491 if (strmatch(argv[idx_send_recv]->text, "receive"))
5492 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5493 PEER_FLAG_ORF_PREFIX_RM);
5494
5495 if (strmatch(argv[idx_send_recv]->text, "both"))
5496 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5497 PEER_FLAG_ORF_PREFIX_SM)
5498 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5499 PEER_FLAG_ORF_PREFIX_RM);
5500
5501 return CMD_WARNING_CONFIG_FAILED;
5502 }
5503
5504 ALIAS_HIDDEN(
5505 no_neighbor_capability_orf_prefix,
5506 no_neighbor_capability_orf_prefix_hidden_cmd,
5507 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5508 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5509 "Advertise capability to the peer\n"
5510 "Advertise ORF capability to the peer\n"
5511 "Advertise prefixlist ORF capability to this neighbor\n"
5512 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5513 "Capability to RECEIVE the ORF from this neighbor\n"
5514 "Capability to SEND the ORF to this neighbor\n")
5515
5516 /* neighbor next-hop-self. */
5517 DEFUN_YANG (neighbor_nexthop_self,
5518 neighbor_nexthop_self_cmd,
5519 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5520 NEIGHBOR_STR
5521 NEIGHBOR_ADDR_STR2
5522 "Disable the next hop calculation for this neighbor\n")
5523 {
5524 int idx_peer = 1;
5525 char base_xpath[XPATH_MAXLEN];
5526 char af_xpath[XPATH_MAXLEN];
5527 char attr_xpath[XPATH_MAXLEN];
5528 afi_t afi = bgp_node_afi(vty);
5529 safi_t safi = bgp_node_safi(vty);
5530
5531
5532 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5533 yang_afi_safi_value2identity(afi, safi));
5534
5535 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5536 sizeof(base_xpath), af_xpath)
5537 < 0)
5538 return CMD_WARNING_CONFIG_FAILED;
5539
5540 snprintf(attr_xpath, sizeof(attr_xpath),
5541 "./%s/nexthop-self/next-hop-self",
5542 bgp_afi_safi_get_container_str(afi, safi));
5543
5544 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5545
5546 return nb_cli_apply_changes(vty, base_xpath);
5547 }
5548
5549 ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
5550 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5551 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5552 "Disable the next hop calculation for this neighbor\n")
5553
5554 /* neighbor next-hop-self. */
5555 DEFUN_YANG(neighbor_nexthop_self_force,
5556 neighbor_nexthop_self_force_cmd,
5557 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5558 NEIGHBOR_STR
5559 NEIGHBOR_ADDR_STR2
5560 "Disable the next hop calculation for this neighbor\n"
5561 "Set the next hop to self for reflected routes\n")
5562 {
5563 int idx_peer = 1;
5564 char base_xpath[XPATH_MAXLEN];
5565 char af_xpath[XPATH_MAXLEN];
5566 char attr_xpath[XPATH_MAXLEN];
5567 afi_t afi = bgp_node_afi(vty);
5568 safi_t safi = bgp_node_safi(vty);
5569
5570
5571 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5572 yang_afi_safi_value2identity(afi, safi));
5573
5574 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5575 sizeof(base_xpath), af_xpath)
5576 < 0)
5577 return CMD_WARNING_CONFIG_FAILED;
5578
5579 snprintf(attr_xpath, sizeof(attr_xpath),
5580 "./%s/nexthop-self/next-hop-self-force",
5581 bgp_afi_safi_get_container_str(afi, safi));
5582
5583 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5584
5585 return nb_cli_apply_changes(vty, base_xpath);
5586 }
5587
5588 ALIAS_HIDDEN(neighbor_nexthop_self_force,
5589 neighbor_nexthop_self_force_hidden_cmd,
5590 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5591 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5592 "Disable the next hop calculation for this neighbor\n"
5593 "Set the next hop to self for reflected routes\n")
5594
5595 ALIAS_HIDDEN(neighbor_nexthop_self_force,
5596 neighbor_nexthop_self_all_hidden_cmd,
5597 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5598 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5599 "Disable the next hop calculation for this neighbor\n"
5600 "Set the next hop to self for reflected routes\n")
5601
5602 DEFUN_YANG (no_neighbor_nexthop_self,
5603 no_neighbor_nexthop_self_cmd,
5604 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5605 NO_STR
5606 NEIGHBOR_STR
5607 NEIGHBOR_ADDR_STR2
5608 "Disable the next hop calculation for this neighbor\n")
5609 {
5610 int idx_peer = 2;
5611 char base_xpath[XPATH_MAXLEN];
5612 char af_xpath[XPATH_MAXLEN];
5613 char attr_xpath[XPATH_MAXLEN];
5614 afi_t afi = bgp_node_afi(vty);
5615 safi_t safi = bgp_node_safi(vty);
5616
5617 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5618 yang_afi_safi_value2identity(afi, safi));
5619
5620 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5621 sizeof(base_xpath), af_xpath)
5622 < 0)
5623 return CMD_WARNING_CONFIG_FAILED;
5624
5625 snprintf(attr_xpath, sizeof(attr_xpath),
5626 "./%s/nexthop-self/next-hop-self",
5627 bgp_afi_safi_get_container_str(afi, safi));
5628
5629 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5630
5631 return nb_cli_apply_changes(vty, base_xpath);
5632 }
5633
5634 ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
5635 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5636 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5637 "Disable the next hop calculation for this neighbor\n")
5638
5639 DEFUN_YANG (no_neighbor_nexthop_self_force,
5640 no_neighbor_nexthop_self_force_cmd,
5641 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5642 NO_STR
5643 NEIGHBOR_STR
5644 NEIGHBOR_ADDR_STR2
5645 "Disable the next hop calculation for this neighbor\n"
5646 "Set the next hop to self for reflected routes\n")
5647 {
5648 int idx_peer = 2;
5649 char base_xpath[XPATH_MAXLEN];
5650 char af_xpath[XPATH_MAXLEN];
5651 char attr_xpath[XPATH_MAXLEN];
5652 afi_t afi = bgp_node_afi(vty);
5653 safi_t safi = bgp_node_safi(vty);
5654
5655
5656 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5657 yang_afi_safi_value2identity(afi, safi));
5658
5659 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5660 sizeof(base_xpath), af_xpath)
5661 < 0)
5662 return CMD_WARNING_CONFIG_FAILED;
5663
5664 snprintf(attr_xpath, sizeof(attr_xpath),
5665 "./%s/nexthop-self/next-hop-self-force",
5666 bgp_afi_safi_get_container_str(afi, safi));
5667
5668 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5669
5670 return nb_cli_apply_changes(vty, base_xpath);
5671 }
5672
5673 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5674 no_neighbor_nexthop_self_force_hidden_cmd,
5675 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5676 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5677 "Disable the next hop calculation for this neighbor\n"
5678 "Set the next hop to self for reflected routes\n")
5679
5680 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5681 no_neighbor_nexthop_self_all_hidden_cmd,
5682 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5683 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5684 "Disable the next hop calculation for this neighbor\n"
5685 "Set the next hop to self for reflected routes\n")
5686
5687 /* neighbor as-override */
5688 DEFUN_YANG (neighbor_as_override,
5689 neighbor_as_override_cmd,
5690 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5691 NEIGHBOR_STR
5692 NEIGHBOR_ADDR_STR2
5693 "Override ASNs in outbound updates if aspath equals remote-as\n")
5694 {
5695 int idx_peer = 1;
5696 char base_xpath[XPATH_MAXLEN];
5697 char af_xpath[XPATH_MAXLEN];
5698 char attr_xpath[XPATH_MAXLEN];
5699 afi_t afi = bgp_node_afi(vty);
5700 safi_t safi = bgp_node_safi(vty);
5701
5702 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5703 yang_afi_safi_value2identity(afi, safi));
5704
5705 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5706 sizeof(base_xpath), af_xpath)
5707 < 0)
5708 return CMD_WARNING_CONFIG_FAILED;
5709
5710 snprintf(attr_xpath, sizeof(attr_xpath),
5711 "./%s/as-path-options/replace-peer-as",
5712 bgp_afi_safi_get_container_str(afi, safi));
5713
5714 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5715
5716 return nb_cli_apply_changes(vty, base_xpath);
5717 }
5718
5719 ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
5720 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5721 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5722 "Override ASNs in outbound updates if aspath equals remote-as\n")
5723
5724 DEFUN_YANG (no_neighbor_as_override,
5725 no_neighbor_as_override_cmd,
5726 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5727 NO_STR
5728 NEIGHBOR_STR
5729 NEIGHBOR_ADDR_STR2
5730 "Override ASNs in outbound updates if aspath equals remote-as\n")
5731 {
5732 int idx_peer = 2;
5733 char base_xpath[XPATH_MAXLEN];
5734 char af_xpath[XPATH_MAXLEN];
5735 char attr_xpath[XPATH_MAXLEN];
5736 afi_t afi = bgp_node_afi(vty);
5737 safi_t safi = bgp_node_safi(vty);
5738
5739 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5740 yang_afi_safi_value2identity(afi, safi));
5741
5742 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5743 sizeof(base_xpath), af_xpath)
5744 < 0)
5745 return CMD_WARNING_CONFIG_FAILED;
5746
5747 snprintf(attr_xpath, sizeof(attr_xpath),
5748 "./%s/as-path-options/replace-peer-as",
5749 bgp_afi_safi_get_container_str(afi, safi));
5750
5751 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5752
5753 return nb_cli_apply_changes(vty, base_xpath);
5754 }
5755
5756 ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
5757 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5758 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5759 "Override ASNs in outbound updates if aspath equals remote-as\n")
5760
5761 /* neighbor remove-private-AS. */
5762 DEFUN_YANG (neighbor_remove_private_as,
5763 neighbor_remove_private_as_cmd,
5764 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5765 NEIGHBOR_STR
5766 NEIGHBOR_ADDR_STR2
5767 "Remove private ASNs in outbound updates\n")
5768 {
5769 int idx_peer = 1;
5770 char base_xpath[XPATH_MAXLEN];
5771 char af_xpath[XPATH_MAXLEN];
5772 char attr_xpath[XPATH_MAXLEN];
5773 afi_t afi = bgp_node_afi(vty);
5774 safi_t safi = bgp_node_safi(vty);
5775
5776 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5777 yang_afi_safi_value2identity(afi, safi));
5778
5779 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5780 sizeof(base_xpath), af_xpath)
5781 < 0)
5782 return CMD_WARNING_CONFIG_FAILED;
5783
5784 snprintf(attr_xpath, sizeof(attr_xpath),
5785 "./%s/private-as/remove-private-as",
5786 bgp_afi_safi_get_container_str(afi, safi));
5787
5788 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5789
5790 return nb_cli_apply_changes(vty, base_xpath);
5791 }
5792
5793 ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
5794 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5795 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5796 "Remove private ASNs in outbound updates\n")
5797
5798 DEFUN_YANG (neighbor_remove_private_as_all,
5799 neighbor_remove_private_as_all_cmd,
5800 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5801 NEIGHBOR_STR
5802 NEIGHBOR_ADDR_STR2
5803 "Remove private ASNs in outbound updates\n"
5804 "Apply to all AS numbers\n")
5805 {
5806 int idx_peer = 1;
5807 char base_xpath[XPATH_MAXLEN];
5808 char af_xpath[XPATH_MAXLEN];
5809 char attr_xpath[XPATH_MAXLEN];
5810 afi_t afi = bgp_node_afi(vty);
5811 safi_t safi = bgp_node_safi(vty);
5812
5813
5814 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5815 yang_afi_safi_value2identity(afi, safi));
5816
5817 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5818 sizeof(base_xpath), af_xpath)
5819 < 0)
5820 return CMD_WARNING_CONFIG_FAILED;
5821
5822 snprintf(attr_xpath, sizeof(attr_xpath),
5823 "./%s/private-as/remove-private-as-all",
5824 bgp_afi_safi_get_container_str(afi, safi));
5825
5826 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5827
5828 return nb_cli_apply_changes(vty, base_xpath);
5829 }
5830
5831 ALIAS_HIDDEN(neighbor_remove_private_as_all,
5832 neighbor_remove_private_as_all_hidden_cmd,
5833 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5834 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5835 "Remove private ASNs in outbound updates\n"
5836 "Apply to all AS numbers")
5837
5838 DEFUN_YANG (neighbor_remove_private_as_replace_as,
5839 neighbor_remove_private_as_replace_as_cmd,
5840 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5841 NEIGHBOR_STR
5842 NEIGHBOR_ADDR_STR2
5843 "Remove private ASNs in outbound updates\n"
5844 "Replace private ASNs with our ASN in outbound updates\n")
5845 {
5846 int idx_peer = 1;
5847 char base_xpath[XPATH_MAXLEN];
5848 char af_xpath[XPATH_MAXLEN];
5849 char attr_xpath[XPATH_MAXLEN];
5850 afi_t afi = bgp_node_afi(vty);
5851 safi_t safi = bgp_node_safi(vty);
5852
5853
5854 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5855 yang_afi_safi_value2identity(afi, safi));
5856
5857 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5858 sizeof(base_xpath), af_xpath)
5859 < 0)
5860 return CMD_WARNING_CONFIG_FAILED;
5861
5862 snprintf(attr_xpath, sizeof(attr_xpath),
5863 "./%s/private-as/remove-private-as-replace",
5864 bgp_afi_safi_get_container_str(afi, safi));
5865
5866 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5867
5868 return nb_cli_apply_changes(vty, base_xpath);
5869 }
5870
5871 ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
5872 neighbor_remove_private_as_replace_as_hidden_cmd,
5873 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5874 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5875 "Remove private ASNs in outbound updates\n"
5876 "Replace private ASNs with our ASN in outbound updates\n")
5877
5878 DEFUN_YANG (neighbor_remove_private_as_all_replace_as,
5879 neighbor_remove_private_as_all_replace_as_cmd,
5880 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5881 NEIGHBOR_STR
5882 NEIGHBOR_ADDR_STR2
5883 "Remove private ASNs in outbound updates\n"
5884 "Apply to all AS numbers\n"
5885 "Replace private ASNs with our ASN in outbound updates\n")
5886 {
5887 int idx_peer = 1;
5888 char base_xpath[XPATH_MAXLEN];
5889 char af_xpath[XPATH_MAXLEN];
5890 char attr_xpath[XPATH_MAXLEN];
5891 afi_t afi = bgp_node_afi(vty);
5892 safi_t safi = bgp_node_safi(vty);
5893
5894
5895 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5896 yang_afi_safi_value2identity(afi, safi));
5897
5898 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5899 sizeof(base_xpath), af_xpath)
5900 < 0)
5901 return CMD_WARNING_CONFIG_FAILED;
5902
5903 snprintf(attr_xpath, sizeof(attr_xpath),
5904 "./%s/private-as/remove-private-as-all-replace",
5905 bgp_afi_safi_get_container_str(afi, safi));
5906
5907 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5908
5909 return nb_cli_apply_changes(vty, base_xpath);
5910 }
5911
5912 ALIAS_HIDDEN(
5913 neighbor_remove_private_as_all_replace_as,
5914 neighbor_remove_private_as_all_replace_as_hidden_cmd,
5915 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5916 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5917 "Remove private ASNs in outbound updates\n"
5918 "Apply to all AS numbers\n"
5919 "Replace private ASNs with our ASN in outbound updates\n")
5920
5921 DEFUN_YANG (no_neighbor_remove_private_as,
5922 no_neighbor_remove_private_as_cmd,
5923 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5924 NO_STR
5925 NEIGHBOR_STR
5926 NEIGHBOR_ADDR_STR2
5927 "Remove private ASNs in outbound updates\n")
5928 {
5929 int idx_peer = 2;
5930 char base_xpath[XPATH_MAXLEN];
5931 char af_xpath[XPATH_MAXLEN];
5932 char attr_xpath[XPATH_MAXLEN];
5933 afi_t afi = bgp_node_afi(vty);
5934 safi_t safi = bgp_node_safi(vty);
5935
5936 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5937 yang_afi_safi_value2identity(afi, safi));
5938
5939 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5940 sizeof(base_xpath), af_xpath)
5941 < 0)
5942 return CMD_WARNING_CONFIG_FAILED;
5943
5944 snprintf(attr_xpath, sizeof(attr_xpath),
5945 "./%s/private-as/remove-private-as",
5946 bgp_afi_safi_get_container_str(afi, safi));
5947
5948 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5949
5950 return nb_cli_apply_changes(vty, base_xpath);
5951 }
5952
5953 ALIAS_HIDDEN(no_neighbor_remove_private_as,
5954 no_neighbor_remove_private_as_hidden_cmd,
5955 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5956 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5957 "Remove private ASNs in outbound updates\n")
5958
5959 DEFUN_YANG (no_neighbor_remove_private_as_all,
5960 no_neighbor_remove_private_as_all_cmd,
5961 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5962 NO_STR
5963 NEIGHBOR_STR
5964 NEIGHBOR_ADDR_STR2
5965 "Remove private ASNs in outbound updates\n"
5966 "Apply to all AS numbers\n")
5967 {
5968 int idx_peer = 2;
5969 char base_xpath[XPATH_MAXLEN];
5970 char af_xpath[XPATH_MAXLEN];
5971 char attr_xpath[XPATH_MAXLEN];
5972 afi_t afi = bgp_node_afi(vty);
5973 safi_t safi = bgp_node_safi(vty);
5974
5975
5976 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5977 yang_afi_safi_value2identity(afi, safi));
5978
5979 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5980 sizeof(base_xpath), af_xpath)
5981 < 0)
5982 return CMD_WARNING_CONFIG_FAILED;
5983
5984 snprintf(attr_xpath, sizeof(attr_xpath),
5985 "./%s/private-as/remove-private-as-all",
5986 bgp_afi_safi_get_container_str(afi, safi));
5987
5988 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5989
5990 return nb_cli_apply_changes(vty, base_xpath);
5991 }
5992
5993 ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
5994 no_neighbor_remove_private_as_all_hidden_cmd,
5995 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5996 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5997 "Remove private ASNs in outbound updates\n"
5998 "Apply to all AS numbers\n")
5999
6000 DEFUN_YANG (no_neighbor_remove_private_as_replace_as,
6001 no_neighbor_remove_private_as_replace_as_cmd,
6002 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
6003 NO_STR
6004 NEIGHBOR_STR
6005 NEIGHBOR_ADDR_STR2
6006 "Remove private ASNs in outbound updates\n"
6007 "Replace private ASNs with our ASN in outbound updates\n")
6008 {
6009 int idx_peer = 2;
6010 char base_xpath[XPATH_MAXLEN];
6011 char af_xpath[XPATH_MAXLEN];
6012 char attr_xpath[XPATH_MAXLEN];
6013 afi_t afi = bgp_node_afi(vty);
6014 safi_t safi = bgp_node_safi(vty);
6015
6016
6017 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6018 yang_afi_safi_value2identity(afi, safi));
6019
6020 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6021 sizeof(base_xpath), af_xpath)
6022 < 0)
6023 return CMD_WARNING_CONFIG_FAILED;
6024
6025 snprintf(attr_xpath, sizeof(attr_xpath),
6026 "./%s/private-as/remove-private-as-replace",
6027 bgp_afi_safi_get_container_str(afi, safi));
6028
6029 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6030
6031 return nb_cli_apply_changes(vty, base_xpath);
6032 }
6033
6034 ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
6035 no_neighbor_remove_private_as_replace_as_hidden_cmd,
6036 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
6037 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6038 "Remove private ASNs in outbound updates\n"
6039 "Replace private ASNs with our ASN in outbound updates\n")
6040
6041 DEFUN_YANG (no_neighbor_remove_private_as_all_replace_as,
6042 no_neighbor_remove_private_as_all_replace_as_cmd,
6043 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
6044 NO_STR
6045 NEIGHBOR_STR
6046 NEIGHBOR_ADDR_STR2
6047 "Remove private ASNs in outbound updates\n"
6048 "Apply to all AS numbers\n"
6049 "Replace private ASNs with our ASN in outbound updates\n")
6050 {
6051 int idx_peer = 2;
6052 char base_xpath[XPATH_MAXLEN];
6053 char af_xpath[XPATH_MAXLEN];
6054 char attr_xpath[XPATH_MAXLEN];
6055 afi_t afi = bgp_node_afi(vty);
6056 safi_t safi = bgp_node_safi(vty);
6057
6058
6059 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6060 yang_afi_safi_value2identity(afi, safi));
6061
6062 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6063 sizeof(base_xpath), af_xpath)
6064 < 0)
6065 return CMD_WARNING_CONFIG_FAILED;
6066
6067 snprintf(attr_xpath, sizeof(attr_xpath),
6068 "./%s/private-as/remove-private-as-all-replace",
6069 bgp_afi_safi_get_container_str(afi, safi));
6070
6071 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6072
6073 return nb_cli_apply_changes(vty, base_xpath);
6074 }
6075
6076 ALIAS_HIDDEN(
6077 no_neighbor_remove_private_as_all_replace_as,
6078 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
6079 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
6080 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6081 "Remove private ASNs in outbound updates\n"
6082 "Apply to all AS numbers\n"
6083 "Replace private ASNs with our ASN in outbound updates\n")
6084
6085
6086 /* neighbor send-community. */
6087 DEFUN_YANG (neighbor_send_community,
6088 neighbor_send_community_cmd,
6089 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6090 NEIGHBOR_STR
6091 NEIGHBOR_ADDR_STR2
6092 "Send Community attribute to this neighbor\n")
6093 {
6094 int idx_peer = 1;
6095
6096 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6097 bgp_node_safi(vty),
6098 PEER_FLAG_SEND_COMMUNITY);
6099 }
6100
6101 ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
6102 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6103 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6104 "Send Community attribute to this neighbor\n")
6105
6106 DEFUN_YANG (no_neighbor_send_community,
6107 no_neighbor_send_community_cmd,
6108 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6109 NO_STR
6110 NEIGHBOR_STR
6111 NEIGHBOR_ADDR_STR2
6112 "Send Community attribute to this neighbor\n")
6113 {
6114 int idx_peer = 2;
6115
6116 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6117 bgp_node_afi(vty), bgp_node_safi(vty),
6118 PEER_FLAG_SEND_COMMUNITY);
6119 }
6120
6121 ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
6122 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6123 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6124 "Send Community attribute to this neighbor\n")
6125
6126 /* neighbor send-community extended. */
6127 DEFUN_YANG (neighbor_send_community_type,
6128 neighbor_send_community_type_cmd,
6129 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6130 NEIGHBOR_STR
6131 NEIGHBOR_ADDR_STR2
6132 "Send Community attribute to this neighbor\n"
6133 "Send Standard and Extended Community attributes\n"
6134 "Send Standard, Large and Extended Community attributes\n"
6135 "Send Extended Community attributes\n"
6136 "Send Standard Community attributes\n"
6137 "Send Large Community attributes\n")
6138 {
6139 const char *type = argv[argc - 1]->text;
6140 char *peer_str = argv[1]->arg;
6141 char base_xpath[XPATH_MAXLEN];
6142 char af_xpath[XPATH_MAXLEN];
6143 char std_xpath[XPATH_MAXLEN];
6144 char ext_xpath[XPATH_MAXLEN];
6145 char lrg_xpath[XPATH_MAXLEN];
6146 afi_t afi = bgp_node_afi(vty);
6147 safi_t safi = bgp_node_safi(vty);
6148
6149 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6150 yang_afi_safi_value2identity(afi, safi));
6151
6152 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6153 sizeof(base_xpath), af_xpath)
6154 < 0)
6155 return CMD_WARNING_CONFIG_FAILED;
6156
6157 if (strmatch(type, "standard")) {
6158 snprintf(std_xpath, sizeof(std_xpath),
6159 "./%s/send-community/send-community",
6160 bgp_afi_safi_get_container_str(afi, safi));
6161
6162 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "true");
6163 }
6164
6165 if (strmatch(type, "extended")) {
6166 snprintf(ext_xpath, sizeof(ext_xpath),
6167 "./%s/send-community/send-ext-community",
6168 bgp_afi_safi_get_container_str(afi, safi));
6169
6170 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "true");
6171 }
6172
6173 if (strmatch(type, "large")) {
6174 snprintf(lrg_xpath, sizeof(lrg_xpath),
6175 "./%s/send-community/send-large-community",
6176 bgp_afi_safi_get_container_str(afi, safi));
6177
6178 nb_cli_enqueue_change(vty, lrg_xpath, NB_OP_MODIFY, "true");
6179 }
6180
6181 if (strmatch(type, "both")) {
6182 snprintf(std_xpath, sizeof(std_xpath),
6183 "./%s/send-community/send-community",
6184 bgp_afi_safi_get_container_str(afi, safi));
6185
6186 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "true");
6187
6188 snprintf(ext_xpath, sizeof(ext_xpath),
6189 "./%s/send-community/send-ext-community",
6190 bgp_afi_safi_get_container_str(afi, safi));
6191
6192 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "true");
6193 }
6194
6195 if (strmatch(type, "all")) {
6196 snprintf(std_xpath, sizeof(std_xpath),
6197 "./%s/send-community/send-community",
6198 bgp_afi_safi_get_container_str(afi, safi));
6199
6200 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "true");
6201
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 snprintf(lrg_xpath, sizeof(lrg_xpath),
6209 "./%s/send-community/send-large-community",
6210 bgp_afi_safi_get_container_str(afi, safi));
6211
6212 nb_cli_enqueue_change(vty, lrg_xpath, NB_OP_MODIFY, "true");
6213 }
6214
6215 return nb_cli_apply_changes(vty, base_xpath);
6216 }
6217
6218 ALIAS_HIDDEN(
6219 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
6220 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6221 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6222 "Send Community attribute to this neighbor\n"
6223 "Send Standard and Extended Community attributes\n"
6224 "Send Standard, Large and Extended Community attributes\n"
6225 "Send Extended Community attributes\n"
6226 "Send Standard Community attributes\n"
6227 "Send Large Community attributes\n")
6228
6229 DEFUN_YANG (no_neighbor_send_community_type,
6230 no_neighbor_send_community_type_cmd,
6231 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6232 NO_STR
6233 NEIGHBOR_STR
6234 NEIGHBOR_ADDR_STR2
6235 "Send Community attribute to this neighbor\n"
6236 "Send Standard and Extended Community attributes\n"
6237 "Send Standard, Large and Extended Community attributes\n"
6238 "Send Extended Community attributes\n"
6239 "Send Standard Community attributes\n"
6240 "Send Large Community attributes\n")
6241 {
6242 const char *type = argv[argc - 1]->text;
6243 char *peer_str = argv[2]->arg;
6244 char base_xpath[XPATH_MAXLEN];
6245 char af_xpath[XPATH_MAXLEN];
6246 char std_xpath[XPATH_MAXLEN];
6247 char ext_xpath[XPATH_MAXLEN];
6248 char lrg_xpath[XPATH_MAXLEN];
6249 afi_t afi = bgp_node_afi(vty);
6250 safi_t safi = bgp_node_safi(vty);
6251
6252 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6253 yang_afi_safi_value2identity(afi, safi));
6254
6255 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6256 sizeof(base_xpath), af_xpath)
6257 < 0)
6258 return CMD_WARNING_CONFIG_FAILED;
6259
6260 if (strmatch(type, "standard")) {
6261 snprintf(std_xpath, sizeof(std_xpath),
6262 "./%s/send-community/send-community",
6263 bgp_afi_safi_get_container_str(afi, safi));
6264
6265 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "false");
6266 }
6267
6268 if (strmatch(type, "extended")) {
6269 snprintf(ext_xpath, sizeof(ext_xpath),
6270 "./%s/send-community/send-ext-community",
6271 bgp_afi_safi_get_container_str(afi, safi));
6272
6273 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "false");
6274 }
6275
6276 if (strmatch(type, "large")) {
6277 snprintf(lrg_xpath, sizeof(lrg_xpath),
6278 "./%s/send-community/send-large-community",
6279 bgp_afi_safi_get_container_str(afi, safi));
6280
6281 nb_cli_enqueue_change(vty, lrg_xpath, NB_OP_MODIFY, "false");
6282 }
6283
6284 if (strmatch(type, "both")) {
6285 snprintf(std_xpath, sizeof(std_xpath),
6286 "./%s/send-community/send-community",
6287 bgp_afi_safi_get_container_str(afi, safi));
6288
6289 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "false");
6290
6291 snprintf(ext_xpath, sizeof(ext_xpath),
6292 "./%s/send-community/send-ext-community",
6293 bgp_afi_safi_get_container_str(afi, safi));
6294
6295 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "false");
6296 }
6297
6298 if (strmatch(type, "all")) {
6299 snprintf(std_xpath, sizeof(std_xpath),
6300 "./%s/send-community/send-community",
6301 bgp_afi_safi_get_container_str(afi, safi));
6302
6303 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "false");
6304
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 snprintf(lrg_xpath, sizeof(lrg_xpath),
6312 "./%s/send-community/send-large-community",
6313 bgp_afi_safi_get_container_str(afi, safi));
6314
6315 nb_cli_enqueue_change(vty, lrg_xpath, NB_OP_MODIFY, "false");
6316 }
6317
6318 return nb_cli_apply_changes(vty, base_xpath);
6319 }
6320
6321 ALIAS_HIDDEN(
6322 no_neighbor_send_community_type,
6323 no_neighbor_send_community_type_hidden_cmd,
6324 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6325 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6326 "Send Community attribute to this neighbor\n"
6327 "Send Standard and Extended Community attributes\n"
6328 "Send Standard, Large and Extended Community attributes\n"
6329 "Send Extended Community attributes\n"
6330 "Send Standard Community attributes\n"
6331 "Send Large Community attributes\n")
6332
6333 /* neighbor soft-reconfig. */
6334 DEFUN_YANG (neighbor_soft_reconfiguration,
6335 neighbor_soft_reconfiguration_cmd,
6336 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6337 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6338 "Per neighbor soft reconfiguration\n"
6339 "Allow inbound soft reconfiguration for this neighbor\n")
6340 {
6341 int idx_peer = 1;
6342 char base_xpath[XPATH_MAXLEN];
6343 char af_xpath[XPATH_MAXLEN];
6344 char soft_xpath[XPATH_MAXLEN];
6345 afi_t afi = bgp_node_afi(vty);
6346 safi_t safi = bgp_node_safi(vty);
6347
6348
6349 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6350 yang_afi_safi_value2identity(afi, safi));
6351
6352 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6353 sizeof(base_xpath), af_xpath)
6354 < 0)
6355 return CMD_WARNING_CONFIG_FAILED;
6356
6357 snprintf(soft_xpath, sizeof(soft_xpath), "./%s/soft-reconfiguration",
6358 bgp_afi_safi_get_container_str(afi, safi));
6359
6360 nb_cli_enqueue_change(vty, soft_xpath, NB_OP_MODIFY, "true");
6361
6362 return nb_cli_apply_changes(vty, base_xpath);
6363 }
6364
6365 ALIAS_HIDDEN(neighbor_soft_reconfiguration,
6366 neighbor_soft_reconfiguration_hidden_cmd,
6367 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6368 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6369 "Per neighbor soft reconfiguration\n"
6370 "Allow inbound soft reconfiguration for this neighbor\n")
6371
6372 DEFUN_YANG (no_neighbor_soft_reconfiguration,
6373 no_neighbor_soft_reconfiguration_cmd,
6374 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6375 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6376 "Per neighbor soft reconfiguration\n"
6377 "Allow inbound soft reconfiguration for this neighbor\n")
6378 {
6379 int idx_peer = 2;
6380 char base_xpath[XPATH_MAXLEN];
6381 char af_xpath[XPATH_MAXLEN];
6382 char soft_xpath[XPATH_MAXLEN];
6383 afi_t afi = bgp_node_afi(vty);
6384 safi_t safi = bgp_node_safi(vty);
6385
6386 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6387 yang_afi_safi_value2identity(afi, safi));
6388
6389 snprintf(soft_xpath, sizeof(soft_xpath), "./%s/soft-reconfiguration",
6390 bgp_afi_safi_get_container_str(afi, safi));
6391
6392 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6393 sizeof(base_xpath), af_xpath)
6394 < 0)
6395 return CMD_WARNING_CONFIG_FAILED;
6396
6397 nb_cli_enqueue_change(vty, soft_xpath, NB_OP_MODIFY, "false");
6398
6399 return nb_cli_apply_changes(vty, base_xpath);
6400 }
6401
6402 ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
6403 no_neighbor_soft_reconfiguration_hidden_cmd,
6404 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6405 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6406 "Per neighbor soft reconfiguration\n"
6407 "Allow inbound soft reconfiguration for this neighbor\n")
6408
6409 DEFUN_YANG (neighbor_route_reflector_client,
6410 neighbor_route_reflector_client_cmd,
6411 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6412 NEIGHBOR_STR
6413 NEIGHBOR_ADDR_STR2
6414 "Configure a neighbor as Route Reflector client\n")
6415 {
6416 int idx_peer = 1;
6417 char base_xpath[XPATH_MAXLEN];
6418 char af_xpath[XPATH_MAXLEN];
6419 char attr_xpath[XPATH_MAXLEN];
6420 afi_t afi = bgp_node_afi(vty);
6421 safi_t safi = bgp_node_safi(vty);
6422
6423 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6424 yang_afi_safi_value2identity(afi, safi));
6425
6426 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6427 sizeof(base_xpath), af_xpath)
6428 < 0)
6429 return CMD_WARNING_CONFIG_FAILED;
6430
6431 snprintf(attr_xpath, sizeof(attr_xpath),
6432 "./%s/route-reflector/route-reflector-client",
6433 bgp_afi_safi_get_container_str(afi, safi));
6434
6435 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
6436
6437 return nb_cli_apply_changes(vty, base_xpath);
6438 }
6439
6440 ALIAS_HIDDEN(neighbor_route_reflector_client,
6441 neighbor_route_reflector_client_hidden_cmd,
6442 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6443 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6444 "Configure a neighbor as Route Reflector client\n")
6445
6446 DEFUN_YANG (no_neighbor_route_reflector_client,
6447 no_neighbor_route_reflector_client_cmd,
6448 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6449 NO_STR
6450 NEIGHBOR_STR
6451 NEIGHBOR_ADDR_STR2
6452 "Configure a neighbor as Route Reflector client\n")
6453 {
6454 int idx_peer = 2;
6455 char base_xpath[XPATH_MAXLEN];
6456 char af_xpath[XPATH_MAXLEN];
6457 char attr_xpath[XPATH_MAXLEN];
6458 afi_t afi = bgp_node_afi(vty);
6459 safi_t safi = bgp_node_safi(vty);
6460
6461 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6462 yang_afi_safi_value2identity(afi, safi));
6463
6464 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6465 sizeof(base_xpath), af_xpath)
6466 < 0)
6467 return CMD_WARNING_CONFIG_FAILED;
6468
6469 snprintf(attr_xpath, sizeof(attr_xpath),
6470 "./%s/route-reflector/route-reflector-client",
6471 bgp_afi_safi_get_container_str(afi, safi));
6472
6473 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6474
6475 return nb_cli_apply_changes(vty, base_xpath);
6476 }
6477
6478 ALIAS_HIDDEN(no_neighbor_route_reflector_client,
6479 no_neighbor_route_reflector_client_hidden_cmd,
6480 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6481 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6482 "Configure a neighbor as Route Reflector client\n")
6483
6484 /* neighbor route-server-client. */
6485 DEFUN_YANG (neighbor_route_server_client,
6486 neighbor_route_server_client_cmd,
6487 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6488 NEIGHBOR_STR
6489 NEIGHBOR_ADDR_STR2
6490 "Configure a neighbor as Route Server client\n")
6491 {
6492 int idx_peer = 1;
6493 char base_xpath[XPATH_MAXLEN];
6494 char af_xpath[XPATH_MAXLEN];
6495 char attr_xpath[XPATH_MAXLEN];
6496 afi_t afi = bgp_node_afi(vty);
6497 safi_t safi = bgp_node_safi(vty);
6498
6499 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6500 yang_afi_safi_value2identity(afi, safi));
6501
6502 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6503 sizeof(base_xpath), af_xpath)
6504 < 0)
6505 return CMD_WARNING_CONFIG_FAILED;
6506
6507 snprintf(attr_xpath, sizeof(attr_xpath),
6508 "./%s/route-server/route-server-client",
6509 bgp_afi_safi_get_container_str(afi, safi));
6510
6511 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
6512
6513 return nb_cli_apply_changes(vty, base_xpath);
6514 }
6515
6516 ALIAS_HIDDEN(neighbor_route_server_client,
6517 neighbor_route_server_client_hidden_cmd,
6518 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6519 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6520 "Configure a neighbor as Route Server client\n")
6521
6522 DEFUN_YANG (no_neighbor_route_server_client,
6523 no_neighbor_route_server_client_cmd,
6524 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6525 NO_STR
6526 NEIGHBOR_STR
6527 NEIGHBOR_ADDR_STR2
6528 "Configure a neighbor as Route Server client\n")
6529 {
6530 int idx_peer = 2;
6531 char base_xpath[XPATH_MAXLEN];
6532 char af_xpath[XPATH_MAXLEN];
6533 char attr_xpath[XPATH_MAXLEN];
6534 afi_t afi = bgp_node_afi(vty);
6535 safi_t safi = bgp_node_safi(vty);
6536
6537 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6538 yang_afi_safi_value2identity(afi, safi));
6539
6540 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6541 sizeof(base_xpath), af_xpath)
6542 < 0)
6543 return CMD_WARNING_CONFIG_FAILED;
6544
6545 snprintf(attr_xpath, sizeof(attr_xpath),
6546 "./%s/route-server/route-server-client",
6547 bgp_afi_safi_get_container_str(afi, safi));
6548
6549 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6550
6551 return nb_cli_apply_changes(vty, base_xpath);
6552 }
6553
6554 ALIAS_HIDDEN(no_neighbor_route_server_client,
6555 no_neighbor_route_server_client_hidden_cmd,
6556 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6557 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6558 "Configure a neighbor as Route Server client\n")
6559
6560 DEFUN (neighbor_nexthop_local_unchanged,
6561 neighbor_nexthop_local_unchanged_cmd,
6562 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
6563 NEIGHBOR_STR
6564 NEIGHBOR_ADDR_STR2
6565 "Configure treatment of outgoing link-local nexthop attribute\n"
6566 "Leave link-local nexthop unchanged for this peer\n")
6567 {
6568 int idx_peer = 1;
6569 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6570 bgp_node_safi(vty),
6571 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
6572 }
6573
6574 DEFUN (no_neighbor_nexthop_local_unchanged,
6575 no_neighbor_nexthop_local_unchanged_cmd,
6576 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
6577 NO_STR
6578 NEIGHBOR_STR
6579 NEIGHBOR_ADDR_STR2
6580 "Configure treatment of outgoing link-local-nexthop attribute\n"
6581 "Leave link-local nexthop unchanged for this peer\n")
6582 {
6583 int idx_peer = 2;
6584 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6585 bgp_node_afi(vty), bgp_node_safi(vty),
6586 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
6587 }
6588
6589 DEFUN_YANG (neighbor_attr_unchanged,
6590 neighbor_attr_unchanged_cmd,
6591 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6592 NEIGHBOR_STR
6593 NEIGHBOR_ADDR_STR2
6594 "BGP attribute is propagated unchanged to this neighbor\n"
6595 "As-path attribute\n"
6596 "Nexthop attribute\n"
6597 "Med attribute\n")
6598 {
6599 int idx = 0;
6600 char *peer_str = argv[1]->arg;
6601 bool aspath = false;
6602 bool nexthop = false;
6603 bool med = false;
6604 afi_t afi = bgp_node_afi(vty);
6605 safi_t safi = bgp_node_safi(vty);
6606 char base_xpath[XPATH_MAXLEN];
6607 char af_xpath[XPATH_MAXLEN];
6608 char as_xpath[XPATH_MAXLEN];
6609 char nxthop_xpath[XPATH_MAXLEN];
6610 char med_xpath[XPATH_MAXLEN];
6611
6612 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6613 yang_afi_safi_value2identity(afi, safi));
6614
6615 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6616 sizeof(base_xpath), af_xpath)
6617 < 0)
6618 return CMD_WARNING_CONFIG_FAILED;
6619
6620 if (argv_find(argv, argc, "as-path", &idx))
6621 aspath = true;
6622
6623 idx = 0;
6624 if (argv_find(argv, argc, "next-hop", &idx))
6625 nexthop = true;
6626
6627 idx = 0;
6628 if (argv_find(argv, argc, "med", &idx))
6629 med = true;
6630
6631 snprintf(as_xpath, sizeof(as_xpath),
6632 "./%s/attr-unchanged/as-path-unchanged",
6633 bgp_afi_safi_get_container_str(afi, safi));
6634 snprintf(nxthop_xpath, sizeof(nxthop_xpath),
6635 "./%s/attr-unchanged/next-hop-unchanged",
6636 bgp_afi_safi_get_container_str(afi, safi));
6637 snprintf(med_xpath, sizeof(med_xpath),
6638 "./%s/attr-unchanged/med-unchanged",
6639 bgp_afi_safi_get_container_str(afi, safi));
6640
6641 /* no flags means all of them! */
6642 if (!aspath && !nexthop && !med) {
6643 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY, "true");
6644 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY, "true");
6645 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY, "true");
6646 } else {
6647 if (!aspath)
6648 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY,
6649 "false");
6650 else
6651 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY,
6652 "true");
6653
6654 if (!nexthop)
6655 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY,
6656 "false");
6657 else
6658 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY,
6659 "true");
6660
6661 if (!med)
6662 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY,
6663 "false");
6664 else
6665 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY,
6666 "true");
6667 }
6668
6669 return nb_cli_apply_changes(vty, base_xpath);
6670 }
6671
6672 ALIAS_HIDDEN(
6673 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
6674 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6675 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6676 "BGP attribute is propagated unchanged to this neighbor\n"
6677 "As-path attribute\n"
6678 "Nexthop attribute\n"
6679 "Med attribute\n")
6680
6681 DEFUN_YANG (no_neighbor_attr_unchanged,
6682 no_neighbor_attr_unchanged_cmd,
6683 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6684 NO_STR
6685 NEIGHBOR_STR
6686 NEIGHBOR_ADDR_STR2
6687 "BGP attribute is propagated unchanged to this neighbor\n"
6688 "As-path attribute\n"
6689 "Nexthop attribute\n"
6690 "Med attribute\n")
6691 {
6692 int idx = 0;
6693 char *peer_str = argv[2]->arg;
6694 bool aspath = false;
6695 bool nexthop = false;
6696 bool med = false;
6697 afi_t afi = bgp_node_afi(vty);
6698 safi_t safi = bgp_node_safi(vty);
6699 char base_xpath[XPATH_MAXLEN];
6700 char af_xpath[XPATH_MAXLEN];
6701 char as_xpath[XPATH_MAXLEN];
6702 char nxthop_xpath[XPATH_MAXLEN];
6703 char med_xpath[XPATH_MAXLEN];
6704
6705 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6706 yang_afi_safi_value2identity(afi, safi));
6707
6708 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6709 sizeof(base_xpath), af_xpath)
6710 < 0)
6711 return CMD_WARNING_CONFIG_FAILED;
6712
6713 if (argv_find(argv, argc, "as-path", &idx))
6714 aspath = true;
6715
6716 idx = 0;
6717 if (argv_find(argv, argc, "next-hop", &idx))
6718 nexthop = true;
6719
6720 idx = 0;
6721 if (argv_find(argv, argc, "med", &idx))
6722 med = true;
6723
6724 snprintf(as_xpath, sizeof(as_xpath),
6725 "./%s/attr-unchanged/as-path-unchanged",
6726 bgp_afi_safi_get_container_str(afi, safi));
6727 snprintf(nxthop_xpath, sizeof(nxthop_xpath),
6728 "./%s/attr-unchanged/next-hop-unchanged",
6729 bgp_afi_safi_get_container_str(afi, safi));
6730 snprintf(med_xpath, sizeof(med_xpath),
6731 "./%s/attr-unchanged/med-unchanged",
6732 bgp_afi_safi_get_container_str(afi, safi));
6733
6734 /* no flags means all of them! */
6735 if (!aspath && !nexthop && !med) {
6736 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY, "false");
6737 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY, "false");
6738 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY, "false");
6739 }
6740
6741 if (aspath)
6742 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY, "false");
6743
6744 if (nexthop)
6745 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY, "false");
6746
6747 if (med)
6748 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY, "false");
6749
6750 return nb_cli_apply_changes(vty, base_xpath);
6751 }
6752
6753 ALIAS_HIDDEN(
6754 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
6755 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6756 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6757 "BGP attribute is propagated unchanged to this neighbor\n"
6758 "As-path attribute\n"
6759 "Nexthop attribute\n"
6760 "Med attribute\n")
6761
6762 /* neighbor ebgp-multihop. */
6763 DEFUN_YANG (neighbor_ebgp_multihop,
6764 neighbor_ebgp_multihop_cmd,
6765 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
6766 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6767 "Allow EBGP neighbors not on directly connected networks\n")
6768 {
6769 int idx_peer = 1;
6770 char base_xpath[XPATH_MAXLEN];
6771
6772 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6773 sizeof(base_xpath), NULL)
6774 < 0)
6775 return CMD_WARNING_CONFIG_FAILED;
6776
6777 nb_cli_enqueue_change(vty, "./ebgp-multihop/enabled", NB_OP_MODIFY,
6778 "true");
6779
6780 return nb_cli_apply_changes(vty, base_xpath);
6781 }
6782
6783 DEFUN_YANG (neighbor_ebgp_multihop_ttl,
6784 neighbor_ebgp_multihop_ttl_cmd,
6785 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
6786 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6787 "Allow EBGP neighbors not on directly connected networks\n"
6788 "maximum hop count\n")
6789 {
6790 int idx_peer = 1;
6791 int idx_number = 3;
6792 char base_xpath[XPATH_MAXLEN];
6793
6794 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6795 sizeof(base_xpath), NULL)
6796 < 0)
6797 return CMD_WARNING_CONFIG_FAILED;
6798
6799 nb_cli_enqueue_change(vty, "./ebgp-multihop/multihop-ttl", NB_OP_MODIFY,
6800 argv[idx_number]->arg);
6801
6802 return nb_cli_apply_changes(vty, base_xpath);
6803 }
6804
6805 DEFUN_YANG (no_neighbor_ebgp_multihop,
6806 no_neighbor_ebgp_multihop_cmd,
6807 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
6808 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6809 "Allow EBGP neighbors not on directly connected networks\n"
6810 "maximum hop count\n")
6811 {
6812 int idx_peer = 2;
6813 char base_xpath[XPATH_MAXLEN];
6814
6815 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6816 sizeof(base_xpath), NULL)
6817 < 0)
6818 return CMD_WARNING_CONFIG_FAILED;
6819
6820 if (argc > 4)
6821 nb_cli_enqueue_change(vty, "./ebgp-multihop/multihop-ttl",
6822 NB_OP_DESTROY, NULL);
6823 else
6824 nb_cli_enqueue_change(vty, "./ebgp-multihop/enabled",
6825 NB_OP_MODIFY, "false");
6826
6827 return nb_cli_apply_changes(vty, base_xpath);
6828 }
6829
6830
6831 /* disable-connected-check */
6832 DEFUN_YANG (neighbor_disable_connected_check,
6833 neighbor_disable_connected_check_cmd,
6834 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6835 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6836 "one-hop away EBGP peer using loopback address\n"
6837 "Enforce EBGP neighbors perform multihop\n")
6838 {
6839 int idx_peer = 1;
6840 char base_xpath[XPATH_MAXLEN];
6841
6842 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6843 sizeof(base_xpath), NULL)
6844 < 0)
6845 return CMD_WARNING_CONFIG_FAILED;
6846
6847 nb_cli_enqueue_change(vty, "./ebgp-multihop/disable-connected-check",
6848 NB_OP_MODIFY, "true");
6849
6850 return nb_cli_apply_changes(vty, base_xpath);
6851 }
6852
6853 DEFUN_YANG (no_neighbor_disable_connected_check,
6854 no_neighbor_disable_connected_check_cmd,
6855 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6856 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6857 "one-hop away EBGP peer using loopback address\n"
6858 "Enforce EBGP neighbors perform multihop\n")
6859 {
6860 int idx_peer = 2;
6861 char base_xpath[XPATH_MAXLEN];
6862
6863 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6864 sizeof(base_xpath), NULL)
6865 < 0)
6866 return CMD_WARNING_CONFIG_FAILED;
6867
6868 nb_cli_enqueue_change(vty, "./ebgp-multihop/disable-connected-check",
6869 NB_OP_MODIFY, "false");
6870
6871 return nb_cli_apply_changes(vty, base_xpath);
6872 }
6873
6874
6875 /* enforce-first-as */
6876 DEFUN_YANG (neighbor_enforce_first_as,
6877 neighbor_enforce_first_as_cmd,
6878 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6879 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6880 "Enforce the first AS for EBGP routes\n")
6881 {
6882 int idx_peer = 1;
6883 char base_xpath[XPATH_MAXLEN];
6884
6885 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6886 sizeof(base_xpath), NULL)
6887 < 0)
6888 return CMD_WARNING_CONFIG_FAILED;
6889
6890 nb_cli_enqueue_change(vty, "./enforce-first-as", NB_OP_MODIFY, "true");
6891
6892 return nb_cli_apply_changes(vty, base_xpath);
6893 }
6894
6895 DEFUN_YANG (no_neighbor_enforce_first_as,
6896 no_neighbor_enforce_first_as_cmd,
6897 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6898 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6899 "Enforce the first AS for EBGP routes\n")
6900 {
6901 int idx_peer = 2;
6902 char base_xpath[XPATH_MAXLEN];
6903
6904 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6905 sizeof(base_xpath), NULL)
6906 < 0)
6907 return CMD_WARNING_CONFIG_FAILED;
6908
6909 nb_cli_enqueue_change(vty, "./enforce-first-as", NB_OP_MODIFY, "false");
6910
6911 return nb_cli_apply_changes(vty, base_xpath);
6912 }
6913
6914 static int peer_and_group_lookup_nb(struct vty *vty, const char *peer_str,
6915 char *base_xpath, int xpath_len,
6916 char *xpath)
6917 {
6918 union sockunion su;
6919 char num_xpath[XPATH_MAXLEN];
6920 char unnbr_xpath[XPATH_MAXLEN];
6921 char prgrp_xpath[XPATH_MAXLEN];
6922
6923 if (str2sockunion(peer_str, &su) == 0) {
6924 snprintf(num_xpath, sizeof(num_xpath),
6925 "/neighbors/neighbor[remote-address='%s']", peer_str);
6926 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
6927 VTY_CURR_XPATH, num_xpath)) {
6928 snprintf(base_xpath, xpath_len,
6929 FRR_BGP_NEIGHBOR_NUM_XPATH, peer_str,
6930 xpath ? xpath : "");
6931 } else {
6932 vty_out(vty,
6933 "%% Specify remote-as or peer-group commands first\n");
6934 return -1;
6935 }
6936
6937 } else {
6938 snprintf(unnbr_xpath, sizeof(unnbr_xpath),
6939 "/neighbors/unnumbered-neighbor[interface='%s']",
6940 peer_str);
6941
6942 snprintf(prgrp_xpath, sizeof(prgrp_xpath),
6943 "/peer-groups/peer-group[peer-group-name='%s']",
6944 peer_str);
6945
6946 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
6947 VTY_CURR_XPATH, unnbr_xpath)) {
6948 snprintf(base_xpath, xpath_len,
6949 FRR_BGP_NEIGHBOR_UNNUM_XPATH, peer_str,
6950 xpath ? xpath : "");
6951 } else if (yang_dnode_exists(vty->candidate_config->dnode,
6952 "%s%s", VTY_CURR_XPATH,
6953 prgrp_xpath)) {
6954 snprintf(base_xpath, xpath_len,
6955 FRR_BGP_PEER_GROUP_XPATH, peer_str,
6956 xpath ? xpath : "");
6957 } else {
6958 vty_out(vty,
6959 "%% Create the peer-group or interface first\n");
6960 return -1;
6961 }
6962 }
6963
6964 return 0;
6965 }
6966
6967 DEFUN_YANG (neighbor_description,
6968 neighbor_description_cmd,
6969 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6970 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6971 "Neighbor specific description\n"
6972 "Up to 80 characters describing this neighbor\n")
6973 {
6974 int idx_peer = 1;
6975 int idx_line = 3;
6976 int ret;
6977 char base_xpath[XPATH_MAXLEN];
6978 char *str;
6979
6980 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6981 sizeof(base_xpath), NULL)
6982 < 0)
6983 return CMD_WARNING_CONFIG_FAILED;
6984
6985 str = argv_concat(argv, argc, idx_line);
6986
6987 nb_cli_enqueue_change(vty, "./description", NB_OP_MODIFY, str);
6988
6989 ret = nb_cli_apply_changes(vty, base_xpath);
6990
6991 XFREE(MTYPE_TMP, str);
6992
6993 return ret;
6994 }
6995
6996 DEFUN_YANG (no_neighbor_description,
6997 no_neighbor_description_cmd,
6998 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
6999 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7000 "Neighbor specific description\n")
7001 {
7002 int idx_peer = 2;
7003 char base_xpath[XPATH_MAXLEN];
7004
7005 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7006 sizeof(base_xpath), NULL)
7007 < 0)
7008 return CMD_WARNING_CONFIG_FAILED;
7009
7010 nb_cli_enqueue_change(vty, "./description", NB_OP_DESTROY, NULL);
7011
7012 return nb_cli_apply_changes(vty, base_xpath);
7013 }
7014
7015 ALIAS_YANG(no_neighbor_description, no_neighbor_description_comment_cmd,
7016 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
7017 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7018 "Neighbor specific description\n"
7019 "Up to 80 characters describing this neighbor\n")
7020
7021 #define BGP_UPDATE_SOURCE_HELP_STR \
7022 "IPv4 address\n" \
7023 "IPv6 address\n" \
7024 "Interface name (requires zebra to be running)\n"
7025
7026 DEFUN_YANG (neighbor_update_source,
7027 neighbor_update_source_cmd,
7028 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
7029 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7030 "Source of routing updates\n"
7031 BGP_UPDATE_SOURCE_HELP_STR)
7032 {
7033 int idx_peer = 1;
7034 int idx_peer_2 = 3;
7035 union sockunion su;
7036 char base_xpath[XPATH_MAXLEN];
7037
7038 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7039 sizeof(base_xpath), NULL)
7040 < 0)
7041 return CMD_WARNING_CONFIG_FAILED;
7042
7043 if (str2sockunion(argv[idx_peer_2]->arg, &su) == 0)
7044 nb_cli_enqueue_change(vty, "./update-source/ip", NB_OP_MODIFY,
7045 argv[idx_peer_2]->arg);
7046 else
7047 nb_cli_enqueue_change(vty, "./update-source/interface",
7048 NB_OP_MODIFY, argv[idx_peer_2]->arg);
7049
7050 return nb_cli_apply_changes(vty, base_xpath);
7051 }
7052
7053 DEFUN_YANG (no_neighbor_update_source,
7054 no_neighbor_update_source_cmd,
7055 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
7056 NO_STR NEIGHBOR_STR
7057 NEIGHBOR_ADDR_STR2
7058 "Source of routing updates\n"
7059 BGP_UPDATE_SOURCE_HELP_STR)
7060 {
7061 int idx_peer = 2;
7062 char base_xpath[XPATH_MAXLEN];
7063
7064 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7065 sizeof(base_xpath), NULL)
7066 < 0)
7067 return CMD_WARNING_CONFIG_FAILED;
7068
7069 nb_cli_enqueue_change(vty, "./update-source/ip", NB_OP_DESTROY, NULL);
7070 nb_cli_enqueue_change(vty, "./update-source/interface", NB_OP_DESTROY,
7071 NULL);
7072
7073 return nb_cli_apply_changes(vty, base_xpath);
7074 }
7075
7076 static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
7077 afi_t afi, safi_t safi,
7078 const char *rmap, int set)
7079 {
7080 int ret;
7081 struct peer *peer;
7082 struct route_map *route_map = NULL;
7083
7084 peer = peer_and_group_lookup_vty(vty, peer_str);
7085 if (!peer)
7086 return CMD_WARNING_CONFIG_FAILED;
7087
7088 if (set) {
7089 if (rmap)
7090 route_map = route_map_lookup_warn_noexist(vty, rmap);
7091 ret = peer_default_originate_set(peer, afi, safi,
7092 rmap, route_map);
7093 } else
7094 ret = peer_default_originate_unset(peer, afi, safi);
7095
7096 return bgp_vty_return(vty, ret);
7097 }
7098
7099 /* neighbor default-originate. */
7100 DEFUN (neighbor_default_originate,
7101 neighbor_default_originate_cmd,
7102 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
7103 NEIGHBOR_STR
7104 NEIGHBOR_ADDR_STR2
7105 "Originate default route to this neighbor\n")
7106 {
7107 int idx_peer = 1;
7108 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
7109 bgp_node_afi(vty),
7110 bgp_node_safi(vty), NULL, 1);
7111 }
7112
7113 ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
7114 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
7115 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7116 "Originate default route to this neighbor\n")
7117
7118 DEFUN (neighbor_default_originate_rmap,
7119 neighbor_default_originate_rmap_cmd,
7120 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
7121 NEIGHBOR_STR
7122 NEIGHBOR_ADDR_STR2
7123 "Originate default route to this neighbor\n"
7124 "Route-map to specify criteria to originate default\n"
7125 "route-map name\n")
7126 {
7127 int idx_peer = 1;
7128 int idx_word = 4;
7129 return peer_default_originate_set_vty(
7130 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7131 argv[idx_word]->arg, 1);
7132 }
7133
7134 ALIAS_HIDDEN(
7135 neighbor_default_originate_rmap,
7136 neighbor_default_originate_rmap_hidden_cmd,
7137 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
7138 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7139 "Originate default route to this neighbor\n"
7140 "Route-map to specify criteria to originate default\n"
7141 "route-map name\n")
7142
7143 DEFUN (no_neighbor_default_originate,
7144 no_neighbor_default_originate_cmd,
7145 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
7146 NO_STR
7147 NEIGHBOR_STR
7148 NEIGHBOR_ADDR_STR2
7149 "Originate default route to this neighbor\n"
7150 "Route-map to specify criteria to originate default\n"
7151 "route-map name\n")
7152 {
7153 int idx_peer = 2;
7154 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
7155 bgp_node_afi(vty),
7156 bgp_node_safi(vty), NULL, 0);
7157 }
7158
7159 ALIAS_HIDDEN(
7160 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
7161 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
7162 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7163 "Originate default route to this neighbor\n"
7164 "Route-map to specify criteria to originate default\n"
7165 "route-map name\n")
7166
7167
7168 /* Set specified peer's BGP port. */
7169 DEFUN_YANG (neighbor_port,
7170 neighbor_port_cmd,
7171 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
7172 NEIGHBOR_STR
7173 NEIGHBOR_ADDR_STR
7174 "Neighbor's BGP port\n"
7175 "TCP port number\n")
7176 {
7177 int idx_ip = 1;
7178 int idx_number = 3;
7179 char base_xpath[XPATH_MAXLEN];
7180
7181 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_NUM_XPATH,
7182 argv[idx_ip]->arg, "");
7183
7184 nb_cli_enqueue_change(vty, "./local-port", NB_OP_MODIFY,
7185 argv[idx_number]->arg);
7186
7187 return nb_cli_apply_changes(vty, base_xpath);
7188 }
7189
7190 DEFUN_YANG (no_neighbor_port,
7191 no_neighbor_port_cmd,
7192 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
7193 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR
7194 "Neighbor's BGP port\n"
7195 "TCP port number\n")
7196 {
7197 int idx_ip = 2;
7198 char base_xpath[XPATH_MAXLEN];
7199
7200 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_NUM_XPATH,
7201 argv[idx_ip]->arg, "");
7202
7203 nb_cli_enqueue_change(vty, "./local-port", NB_OP_DESTROY, NULL);
7204
7205 return nb_cli_apply_changes(vty, base_xpath);
7206 }
7207
7208 DEFUN_YANG (neighbor_weight,
7209 neighbor_weight_cmd,
7210 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7211 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7212 "Set default weight for routes from this neighbor\n"
7213 "default weight\n")
7214 {
7215 int idx_peer = 1;
7216 int idx_number = 3;
7217 char base_xpath[XPATH_MAXLEN];
7218 char af_xpath[XPATH_MAXLEN];
7219 char attr_xpath[XPATH_MAXLEN];
7220 afi_t afi = bgp_node_afi(vty);
7221 safi_t safi = bgp_node_safi(vty);
7222
7223 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
7224 yang_afi_safi_value2identity(afi, safi));
7225
7226 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7227 sizeof(base_xpath), af_xpath)
7228 < 0)
7229 return CMD_WARNING_CONFIG_FAILED;
7230
7231 snprintf(attr_xpath, sizeof(attr_xpath), "./%s/weight/weight-attribute",
7232 bgp_afi_safi_get_container_str(afi, safi));
7233
7234 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY,
7235 argv[idx_number]->arg);
7236
7237 return nb_cli_apply_changes(vty, base_xpath);
7238 }
7239
7240 ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
7241 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7242 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7243 "Set default weight for routes from this neighbor\n"
7244 "default weight\n")
7245
7246 DEFUN_YANG (no_neighbor_weight,
7247 no_neighbor_weight_cmd,
7248 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7249 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7250 "Set default weight for routes from this neighbor\n"
7251 "default weight\n")
7252 {
7253 int idx_peer = 2;
7254 char base_xpath[XPATH_MAXLEN];
7255 char af_xpath[XPATH_MAXLEN];
7256 char attr_xpath[XPATH_MAXLEN];
7257 afi_t afi = bgp_node_afi(vty);
7258 safi_t safi = bgp_node_safi(vty);
7259
7260 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
7261 yang_afi_safi_value2identity(afi, safi));
7262
7263 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7264 sizeof(base_xpath), af_xpath)
7265 < 0)
7266 return CMD_WARNING_CONFIG_FAILED;
7267
7268 snprintf(attr_xpath, sizeof(attr_xpath), "./%s/weight/weight-attribute",
7269 bgp_afi_safi_get_container_str(afi, safi));
7270
7271 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_DESTROY, NULL);
7272
7273 return nb_cli_apply_changes(vty, base_xpath);
7274 }
7275
7276 ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
7277 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7278 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7279 "Set default weight for routes from this neighbor\n"
7280 "default weight\n")
7281
7282
7283 /* Override capability negotiation. */
7284 DEFUN_YANG (neighbor_override_capability,
7285 neighbor_override_capability_cmd,
7286 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7287 NEIGHBOR_STR
7288 NEIGHBOR_ADDR_STR2
7289 "Override capability negotiation result\n")
7290 {
7291 int idx_peer = 1;
7292 char base_xpath[XPATH_MAXLEN];
7293
7294 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7295 sizeof(base_xpath), NULL)
7296 < 0)
7297 return CMD_WARNING_CONFIG_FAILED;
7298
7299 nb_cli_enqueue_change(
7300 vty, "./capability-options/override-capability",
7301 NB_OP_MODIFY, "true");
7302
7303 return nb_cli_apply_changes(vty, base_xpath);
7304 }
7305
7306 DEFUN_YANG (no_neighbor_override_capability,
7307 no_neighbor_override_capability_cmd,
7308 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7309 NO_STR
7310 NEIGHBOR_STR
7311 NEIGHBOR_ADDR_STR2
7312 "Override capability negotiation result\n")
7313 {
7314 int idx_peer = 2;
7315 char base_xpath[XPATH_MAXLEN];
7316
7317 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7318 sizeof(base_xpath), NULL)
7319 < 0)
7320 return CMD_WARNING_CONFIG_FAILED;
7321
7322 nb_cli_enqueue_change(
7323 vty, "./capability-options/override-capability",
7324 NB_OP_MODIFY, "false");
7325
7326 return nb_cli_apply_changes(vty, base_xpath);
7327 }
7328
7329 DEFUN_YANG (neighbor_strict_capability,
7330 neighbor_strict_capability_cmd,
7331 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7332 NEIGHBOR_STR
7333 NEIGHBOR_ADDR_STR2
7334 "Strict capability negotiation match\n")
7335 {
7336 int idx_peer = 1;
7337 char base_xpath[XPATH_MAXLEN];
7338
7339 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7340 sizeof(base_xpath), NULL)
7341 < 0)
7342 return CMD_WARNING_CONFIG_FAILED;
7343
7344 nb_cli_enqueue_change(
7345 vty, "./capability-options/strict-capability",
7346 NB_OP_MODIFY, "true");
7347
7348 return nb_cli_apply_changes(vty, base_xpath);
7349 }
7350
7351 DEFUN_YANG (no_neighbor_strict_capability,
7352 no_neighbor_strict_capability_cmd,
7353 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7354 NO_STR
7355 NEIGHBOR_STR
7356 NEIGHBOR_ADDR_STR2
7357 "Strict capability negotiation match\n")
7358 {
7359 int idx_peer = 2;
7360 char base_xpath[XPATH_MAXLEN];
7361
7362 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7363 sizeof(base_xpath), NULL)
7364 < 0)
7365 return CMD_WARNING_CONFIG_FAILED;
7366
7367 nb_cli_enqueue_change(
7368 vty, "./capability-options/strict-capability",
7369 NB_OP_MODIFY, "false");
7370
7371 return nb_cli_apply_changes(vty, base_xpath);
7372 }
7373
7374 DEFUN_YANG (neighbor_timers,
7375 neighbor_timers_cmd,
7376 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
7377 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7378 "BGP per neighbor timers\n"
7379 "Keepalive interval\n"
7380 "Holdtime\n")
7381 {
7382 int idx_peer = 1;
7383 int idx_number = 3;
7384 int idx_number_2 = 4;
7385 char base_xpath[XPATH_MAXLEN];
7386
7387 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7388 sizeof(base_xpath), NULL)
7389 < 0)
7390 return CMD_WARNING_CONFIG_FAILED;
7391
7392 nb_cli_enqueue_change(vty, "./timers/keepalive", NB_OP_MODIFY,
7393 argv[idx_number]->arg);
7394
7395 nb_cli_enqueue_change(vty, "./timers/hold-time", NB_OP_MODIFY,
7396 argv[idx_number_2]->arg);
7397
7398 return nb_cli_apply_changes(vty, base_xpath);
7399 }
7400
7401 DEFUN_YANG (no_neighbor_timers,
7402 no_neighbor_timers_cmd,
7403 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
7404 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7405 "BGP per neighbor timers\n"
7406 "Keepalive interval\n"
7407 "Holdtime\n")
7408 {
7409 int idx_peer = 2;
7410 char base_xpath[XPATH_MAXLEN];
7411
7412 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7413 sizeof(base_xpath), NULL)
7414 < 0)
7415 return CMD_WARNING_CONFIG_FAILED;
7416
7417 nb_cli_enqueue_change(vty, "./timers/hold-time", NB_OP_DESTROY, NULL);
7418
7419 nb_cli_enqueue_change(vty, "./timers/keepalive", NB_OP_DESTROY, NULL);
7420
7421 return nb_cli_apply_changes(vty, base_xpath);
7422 }
7423
7424 DEFUN_YANG (neighbor_timers_connect,
7425 neighbor_timers_connect_cmd,
7426 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
7427 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7428 "BGP per neighbor timers\n"
7429 "BGP connect timer\n"
7430 "Connect timer\n")
7431 {
7432 int idx_peer = 1;
7433 int idx_number = 4;
7434 char base_xpath[XPATH_MAXLEN];
7435
7436 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7437 sizeof(base_xpath), NULL)
7438 < 0)
7439 return CMD_WARNING_CONFIG_FAILED;
7440
7441 nb_cli_enqueue_change(vty, "./timers/connect-time", NB_OP_MODIFY,
7442 argv[idx_number]->arg);
7443
7444 return nb_cli_apply_changes(vty, base_xpath);
7445 }
7446
7447 DEFUN_YANG (no_neighbor_timers_connect,
7448 no_neighbor_timers_connect_cmd,
7449 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
7450 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7451 "BGP per neighbor timers\n"
7452 "BGP connect timer\n"
7453 "Connect timer\n")
7454 {
7455 int idx_peer = 2;
7456 char base_xpath[XPATH_MAXLEN];
7457
7458 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7459 sizeof(base_xpath), NULL)
7460 < 0)
7461 return CMD_WARNING_CONFIG_FAILED;
7462
7463 nb_cli_enqueue_change(vty, "./timers/connect-time", NB_OP_DESTROY,
7464 NULL);
7465
7466 return nb_cli_apply_changes(vty, base_xpath);
7467 }
7468
7469 DEFPY (neighbor_timers_delayopen,
7470 neighbor_timers_delayopen_cmd,
7471 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen (1-240)$interval",
7472 NEIGHBOR_STR
7473 NEIGHBOR_ADDR_STR2
7474 "BGP per neighbor timers\n"
7475 "RFC 4271 DelayOpenTimer\n"
7476 "DelayOpenTime timer interval\n")
7477 {
7478 struct peer *peer;
7479
7480 peer = peer_and_group_lookup_vty(vty, neighbor);
7481 if (!peer)
7482 return CMD_WARNING_CONFIG_FAILED;
7483
7484 if (!interval) {
7485 if (peer_timers_delayopen_unset(peer))
7486 return CMD_WARNING_CONFIG_FAILED;
7487 } else {
7488 if (peer_timers_delayopen_set(peer, interval))
7489 return CMD_WARNING_CONFIG_FAILED;
7490 }
7491
7492 return CMD_SUCCESS;
7493 }
7494
7495 DEFPY (no_neighbor_timers_delayopen,
7496 no_neighbor_timers_delayopen_cmd,
7497 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen [(0-65535)]",
7498 NO_STR
7499 NEIGHBOR_STR
7500 NEIGHBOR_ADDR_STR2
7501 "BGP per neighbor timers\n"
7502 "RFC 4271 DelayOpenTimer\n"
7503 "DelayOpenTime timer interval\n")
7504 {
7505 struct peer *peer;
7506
7507 peer = peer_and_group_lookup_vty(vty, neighbor);
7508 if (!peer)
7509 return CMD_WARNING_CONFIG_FAILED;
7510
7511 if (peer_timers_delayopen_unset(peer))
7512 return CMD_WARNING_CONFIG_FAILED;
7513
7514 return CMD_SUCCESS;
7515 }
7516
7517 DEFUN_YANG (neighbor_advertise_interval,
7518 neighbor_advertise_interval_cmd,
7519 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
7520 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7521 "Minimum interval between sending BGP routing updates\n"
7522 "time in seconds\n")
7523 {
7524 int idx_peer = 1;
7525 int idx_number = 3;
7526 char base_xpath[XPATH_MAXLEN];
7527
7528 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7529 sizeof(base_xpath), NULL)
7530 < 0)
7531 return CMD_WARNING_CONFIG_FAILED;
7532
7533 nb_cli_enqueue_change(vty, "./timers/advertise-interval", NB_OP_MODIFY,
7534 argv[idx_number]->arg);
7535
7536 return nb_cli_apply_changes(vty, base_xpath);
7537 }
7538
7539 DEFUN_YANG (no_neighbor_advertise_interval,
7540 no_neighbor_advertise_interval_cmd,
7541 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
7542 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7543 "Minimum interval between sending BGP routing updates\n"
7544 "time in seconds\n")
7545 {
7546 int idx_peer = 2;
7547 char base_xpath[XPATH_MAXLEN];
7548
7549 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7550 sizeof(base_xpath), NULL)
7551 < 0)
7552 return CMD_WARNING_CONFIG_FAILED;
7553
7554 nb_cli_enqueue_change(vty, "./timers/advertise-interval", NB_OP_DESTROY,
7555 NULL);
7556
7557 return nb_cli_apply_changes(vty, base_xpath);
7558 }
7559
7560
7561 /* Time to wait before processing route-map updates */
7562 DEFUN (bgp_set_route_map_delay_timer,
7563 bgp_set_route_map_delay_timer_cmd,
7564 "bgp route-map delay-timer (0-600)",
7565 SET_STR
7566 "BGP route-map delay timer\n"
7567 "Time in secs to wait before processing route-map changes\n"
7568 "0 disables the timer, no route updates happen when route-maps change\n")
7569 {
7570 int idx_number = 3;
7571 uint32_t rmap_delay_timer;
7572
7573 if (argv[idx_number]->arg) {
7574 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
7575 bm->rmap_update_timer = rmap_delay_timer;
7576
7577 /* if the dynamic update handling is being disabled, and a timer
7578 * is
7579 * running, stop the timer and act as if the timer has already
7580 * fired.
7581 */
7582 if (!rmap_delay_timer && bm->t_rmap_update) {
7583 BGP_TIMER_OFF(bm->t_rmap_update);
7584 thread_execute(bm->master, bgp_route_map_update_timer,
7585 NULL, 0);
7586 }
7587 return CMD_SUCCESS;
7588 } else {
7589 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
7590 return CMD_WARNING_CONFIG_FAILED;
7591 }
7592 }
7593
7594 DEFUN (no_bgp_set_route_map_delay_timer,
7595 no_bgp_set_route_map_delay_timer_cmd,
7596 "no bgp route-map delay-timer [(0-600)]",
7597 NO_STR
7598 BGP_STR
7599 "Default BGP route-map delay timer\n"
7600 "Reset to default time to wait for processing route-map changes\n"
7601 "0 disables the timer, no route updates happen when route-maps change\n")
7602 {
7603
7604 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
7605
7606 return CMD_SUCCESS;
7607 }
7608
7609 DEFUN_YANG (neighbor_interface,
7610 neighbor_interface_cmd,
7611 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
7612 NEIGHBOR_STR NEIGHBOR_ADDR_STR
7613 "Interface\n"
7614 "Interface name\n")
7615 {
7616 int idx_ip = 1;
7617 int idx_word = 3;
7618 char base_xpath[XPATH_MAXLEN];
7619
7620 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_NUM_XPATH,
7621 argv[idx_ip]->arg, "");
7622
7623 nb_cli_enqueue_change(vty, "./local-interface", NB_OP_MODIFY,
7624 argv[idx_word]->arg);
7625
7626 return nb_cli_apply_changes(vty, base_xpath);
7627 }
7628
7629 DEFUN_YANG (no_neighbor_interface,
7630 no_neighbor_interface_cmd,
7631 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
7632 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7633 "Interface\n"
7634 "Interface name\n")
7635 {
7636 int idx_peer = 2;
7637 char base_xpath[XPATH_MAXLEN];
7638
7639 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_NUM_XPATH,
7640 argv[idx_peer]->arg, "");
7641
7642 nb_cli_enqueue_change(vty, "./local-interface", NB_OP_DESTROY, NULL);
7643
7644 return nb_cli_apply_changes(vty, base_xpath);
7645 }
7646
7647 DEFUN (neighbor_distribute_list,
7648 neighbor_distribute_list_cmd,
7649 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
7650 NEIGHBOR_STR
7651 NEIGHBOR_ADDR_STR2
7652 "Filter updates to/from this neighbor\n"
7653 "IP access-list number\n"
7654 "IP access-list number (expanded range)\n"
7655 "IP Access-list name\n"
7656 "Filter incoming updates\n"
7657 "Filter outgoing updates\n")
7658 {
7659 int idx_peer = 1;
7660 int idx_acl = 3;
7661 int direct, ret;
7662 struct peer *peer;
7663
7664 const char *pstr = argv[idx_peer]->arg;
7665 const char *acl = argv[idx_acl]->arg;
7666 const char *inout = argv[argc - 1]->text;
7667
7668 peer = peer_and_group_lookup_vty(vty, pstr);
7669 if (!peer)
7670 return CMD_WARNING_CONFIG_FAILED;
7671
7672 /* Check filter direction. */
7673 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7674 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7675 direct, acl);
7676
7677 return bgp_vty_return(vty, ret);
7678 }
7679
7680 ALIAS_HIDDEN(
7681 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
7682 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
7683 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7684 "Filter updates to/from this neighbor\n"
7685 "IP access-list number\n"
7686 "IP access-list number (expanded range)\n"
7687 "IP Access-list name\n"
7688 "Filter incoming updates\n"
7689 "Filter outgoing updates\n")
7690
7691 DEFUN (no_neighbor_distribute_list,
7692 no_neighbor_distribute_list_cmd,
7693 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
7694 NO_STR
7695 NEIGHBOR_STR
7696 NEIGHBOR_ADDR_STR2
7697 "Filter updates to/from this neighbor\n"
7698 "IP access-list number\n"
7699 "IP access-list number (expanded range)\n"
7700 "IP Access-list name\n"
7701 "Filter incoming updates\n"
7702 "Filter outgoing updates\n")
7703 {
7704 int idx_peer = 2;
7705 int direct, ret;
7706 struct peer *peer;
7707
7708 const char *pstr = argv[idx_peer]->arg;
7709 const char *inout = argv[argc - 1]->text;
7710
7711 peer = peer_and_group_lookup_vty(vty, pstr);
7712 if (!peer)
7713 return CMD_WARNING_CONFIG_FAILED;
7714
7715 /* Check filter direction. */
7716 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7717 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7718 direct);
7719
7720 return bgp_vty_return(vty, ret);
7721 }
7722
7723 ALIAS_HIDDEN(
7724 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
7725 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
7726 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7727 "Filter updates to/from this neighbor\n"
7728 "IP access-list number\n"
7729 "IP access-list number (expanded range)\n"
7730 "IP Access-list name\n"
7731 "Filter incoming updates\n"
7732 "Filter outgoing updates\n")
7733
7734 /* Set prefix list to the peer. */
7735 static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
7736 afi_t afi, safi_t safi,
7737 const char *name_str,
7738 const char *direct_str)
7739 {
7740 int ret;
7741 int direct = FILTER_IN;
7742 struct peer *peer;
7743
7744 peer = peer_and_group_lookup_vty(vty, ip_str);
7745 if (!peer)
7746 return CMD_WARNING_CONFIG_FAILED;
7747
7748 /* Check filter direction. */
7749 if (strncmp(direct_str, "i", 1) == 0)
7750 direct = FILTER_IN;
7751 else if (strncmp(direct_str, "o", 1) == 0)
7752 direct = FILTER_OUT;
7753
7754 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
7755
7756 return bgp_vty_return(vty, ret);
7757 }
7758
7759 static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
7760 afi_t afi, safi_t safi,
7761 const char *direct_str)
7762 {
7763 int ret;
7764 struct peer *peer;
7765 int direct = FILTER_IN;
7766
7767 peer = peer_and_group_lookup_vty(vty, ip_str);
7768 if (!peer)
7769 return CMD_WARNING_CONFIG_FAILED;
7770
7771 /* Check filter direction. */
7772 if (strncmp(direct_str, "i", 1) == 0)
7773 direct = FILTER_IN;
7774 else if (strncmp(direct_str, "o", 1) == 0)
7775 direct = FILTER_OUT;
7776
7777 ret = peer_prefix_list_unset(peer, afi, safi, direct);
7778
7779 return bgp_vty_return(vty, ret);
7780 }
7781
7782 DEFUN (neighbor_prefix_list,
7783 neighbor_prefix_list_cmd,
7784 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7785 NEIGHBOR_STR
7786 NEIGHBOR_ADDR_STR2
7787 "Filter updates to/from this neighbor\n"
7788 "Name of a prefix list\n"
7789 "Filter incoming updates\n"
7790 "Filter outgoing updates\n")
7791 {
7792 int idx_peer = 1;
7793 int idx_word = 3;
7794 int idx_in_out = 4;
7795 return peer_prefix_list_set_vty(
7796 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7797 argv[idx_word]->arg, argv[idx_in_out]->arg);
7798 }
7799
7800 ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
7801 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7802 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7803 "Filter updates to/from this neighbor\n"
7804 "Name of a prefix list\n"
7805 "Filter incoming updates\n"
7806 "Filter outgoing updates\n")
7807
7808 DEFUN (no_neighbor_prefix_list,
7809 no_neighbor_prefix_list_cmd,
7810 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7811 NO_STR
7812 NEIGHBOR_STR
7813 NEIGHBOR_ADDR_STR2
7814 "Filter updates to/from this neighbor\n"
7815 "Name of a prefix list\n"
7816 "Filter incoming updates\n"
7817 "Filter outgoing updates\n")
7818 {
7819 int idx_peer = 2;
7820 int idx_in_out = 5;
7821 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
7822 bgp_node_afi(vty), bgp_node_safi(vty),
7823 argv[idx_in_out]->arg);
7824 }
7825
7826 ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
7827 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7828 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7829 "Filter updates to/from this neighbor\n"
7830 "Name of a prefix list\n"
7831 "Filter incoming updates\n"
7832 "Filter outgoing updates\n")
7833
7834 static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7835 safi_t safi, const char *name_str,
7836 const char *direct_str)
7837 {
7838 int ret;
7839 struct peer *peer;
7840 int direct = FILTER_IN;
7841
7842 peer = peer_and_group_lookup_vty(vty, ip_str);
7843 if (!peer)
7844 return CMD_WARNING_CONFIG_FAILED;
7845
7846 /* Check filter direction. */
7847 if (strncmp(direct_str, "i", 1) == 0)
7848 direct = FILTER_IN;
7849 else if (strncmp(direct_str, "o", 1) == 0)
7850 direct = FILTER_OUT;
7851
7852 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
7853
7854 return bgp_vty_return(vty, ret);
7855 }
7856
7857 static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7858 safi_t safi, const char *direct_str)
7859 {
7860 int ret;
7861 struct peer *peer;
7862 int direct = FILTER_IN;
7863
7864 peer = peer_and_group_lookup_vty(vty, ip_str);
7865 if (!peer)
7866 return CMD_WARNING_CONFIG_FAILED;
7867
7868 /* Check filter direction. */
7869 if (strncmp(direct_str, "i", 1) == 0)
7870 direct = FILTER_IN;
7871 else if (strncmp(direct_str, "o", 1) == 0)
7872 direct = FILTER_OUT;
7873
7874 ret = peer_aslist_unset(peer, afi, safi, direct);
7875
7876 return bgp_vty_return(vty, ret);
7877 }
7878
7879 DEFUN (neighbor_filter_list,
7880 neighbor_filter_list_cmd,
7881 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
7882 NEIGHBOR_STR
7883 NEIGHBOR_ADDR_STR2
7884 "Establish BGP filters\n"
7885 "AS path access-list name\n"
7886 "Filter incoming routes\n"
7887 "Filter outgoing routes\n")
7888 {
7889 int idx_peer = 1;
7890 int idx_word = 3;
7891 int idx_in_out = 4;
7892 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7893 bgp_node_safi(vty), argv[idx_word]->arg,
7894 argv[idx_in_out]->arg);
7895 }
7896
7897 ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
7898 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
7899 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7900 "Establish BGP filters\n"
7901 "AS path access-list name\n"
7902 "Filter incoming routes\n"
7903 "Filter outgoing routes\n")
7904
7905 DEFUN (no_neighbor_filter_list,
7906 no_neighbor_filter_list_cmd,
7907 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
7908 NO_STR
7909 NEIGHBOR_STR
7910 NEIGHBOR_ADDR_STR2
7911 "Establish BGP filters\n"
7912 "AS path access-list name\n"
7913 "Filter incoming routes\n"
7914 "Filter outgoing routes\n")
7915 {
7916 int idx_peer = 2;
7917 int idx_in_out = 5;
7918 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
7919 bgp_node_afi(vty), bgp_node_safi(vty),
7920 argv[idx_in_out]->arg);
7921 }
7922
7923 ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
7924 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
7925 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7926 "Establish BGP filters\n"
7927 "AS path access-list name\n"
7928 "Filter incoming routes\n"
7929 "Filter outgoing routes\n")
7930
7931 /* Set advertise-map to the peer. */
7932 static int peer_advertise_map_set_vty(struct vty *vty, const char *ip_str,
7933 afi_t afi, safi_t safi,
7934 const char *advertise_str,
7935 const char *condition_str, bool condition,
7936 bool set)
7937 {
7938 int ret = CMD_WARNING_CONFIG_FAILED;
7939 struct peer *peer;
7940 struct route_map *advertise_map;
7941 struct route_map *condition_map;
7942
7943 peer = peer_and_group_lookup_vty(vty, ip_str);
7944 if (!peer)
7945 return ret;
7946
7947 condition_map = route_map_lookup_warn_noexist(vty, condition_str);
7948 advertise_map = route_map_lookup_warn_noexist(vty, advertise_str);
7949
7950 if (set)
7951 ret = peer_advertise_map_set(peer, afi, safi, advertise_str,
7952 advertise_map, condition_str,
7953 condition_map, condition);
7954 else
7955 ret = peer_advertise_map_unset(peer, afi, safi, advertise_str,
7956 advertise_map, condition_str,
7957 condition_map, condition);
7958
7959 return bgp_vty_return(vty, ret);
7960 }
7961
7962 DEFPY (neighbor_advertise_map,
7963 neighbor_advertise_map_cmd,
7964 "[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",
7965 NO_STR
7966 NEIGHBOR_STR
7967 NEIGHBOR_ADDR_STR2
7968 "Route-map to conditionally advertise routes\n"
7969 "Name of advertise map\n"
7970 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7971 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
7972 "Name of the exist or non exist map\n")
7973 {
7974 bool condition = CONDITION_EXIST;
7975
7976 if (!strcmp(exist, "non-exist-map"))
7977 condition = CONDITION_NON_EXIST;
7978
7979 return peer_advertise_map_set_vty(vty, neighbor, bgp_node_afi(vty),
7980 bgp_node_safi(vty), advertise_str,
7981 condition_str, condition, !no);
7982 }
7983
7984 ALIAS_HIDDEN(neighbor_advertise_map, neighbor_advertise_map_hidden_cmd,
7985 "[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",
7986 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7987 "Route-map to conditionally advertise routes\n"
7988 "Name of advertise map\n"
7989 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7990 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
7991 "Name of the exist or non exist map\n")
7992
7993 /* Set route-map to the peer. */
7994 static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
7995 afi_t afi, safi_t safi, const char *name_str,
7996 const char *direct_str)
7997 {
7998 int ret;
7999 struct peer *peer;
8000 int direct = RMAP_IN;
8001 struct route_map *route_map;
8002
8003 peer = peer_and_group_lookup_vty(vty, ip_str);
8004 if (!peer)
8005 return CMD_WARNING_CONFIG_FAILED;
8006
8007 /* Check filter direction. */
8008 if (strncmp(direct_str, "in", 2) == 0)
8009 direct = RMAP_IN;
8010 else if (strncmp(direct_str, "o", 1) == 0)
8011 direct = RMAP_OUT;
8012
8013 route_map = route_map_lookup_warn_noexist(vty, name_str);
8014 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
8015
8016 return bgp_vty_return(vty, ret);
8017 }
8018
8019 static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
8020 afi_t afi, safi_t safi,
8021 const char *direct_str)
8022 {
8023 int ret;
8024 struct peer *peer;
8025 int direct = RMAP_IN;
8026
8027 peer = peer_and_group_lookup_vty(vty, ip_str);
8028 if (!peer)
8029 return CMD_WARNING_CONFIG_FAILED;
8030
8031 /* Check filter direction. */
8032 if (strncmp(direct_str, "in", 2) == 0)
8033 direct = RMAP_IN;
8034 else if (strncmp(direct_str, "o", 1) == 0)
8035 direct = RMAP_OUT;
8036
8037 ret = peer_route_map_unset(peer, afi, safi, direct);
8038
8039 return bgp_vty_return(vty, ret);
8040 }
8041
8042 DEFUN (neighbor_route_map,
8043 neighbor_route_map_cmd,
8044 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
8045 NEIGHBOR_STR
8046 NEIGHBOR_ADDR_STR2
8047 "Apply route map to neighbor\n"
8048 "Name of route map\n"
8049 "Apply map to incoming routes\n"
8050 "Apply map to outbound routes\n")
8051 {
8052 int idx_peer = 1;
8053 int idx_word = 3;
8054 int idx_in_out = 4;
8055 return peer_route_map_set_vty(
8056 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8057 argv[idx_word]->arg, argv[idx_in_out]->arg);
8058 }
8059
8060 ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
8061 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
8062 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8063 "Apply route map to neighbor\n"
8064 "Name of route map\n"
8065 "Apply map to incoming routes\n"
8066 "Apply map to outbound routes\n")
8067
8068 DEFUN (no_neighbor_route_map,
8069 no_neighbor_route_map_cmd,
8070 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
8071 NO_STR
8072 NEIGHBOR_STR
8073 NEIGHBOR_ADDR_STR2
8074 "Apply route map to neighbor\n"
8075 "Name of route map\n"
8076 "Apply map to incoming routes\n"
8077 "Apply map to outbound routes\n")
8078 {
8079 int idx_peer = 2;
8080 int idx_in_out = 5;
8081 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
8082 bgp_node_afi(vty), bgp_node_safi(vty),
8083 argv[idx_in_out]->arg);
8084 }
8085
8086 ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
8087 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
8088 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8089 "Apply route map to neighbor\n"
8090 "Name of route map\n"
8091 "Apply map to incoming routes\n"
8092 "Apply map to outbound routes\n")
8093
8094 /* Set unsuppress-map to the peer. */
8095 static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
8096 afi_t afi, safi_t safi,
8097 const char *name_str)
8098 {
8099 int ret;
8100 struct peer *peer;
8101 struct route_map *route_map;
8102
8103 peer = peer_and_group_lookup_vty(vty, ip_str);
8104 if (!peer)
8105 return CMD_WARNING_CONFIG_FAILED;
8106
8107 route_map = route_map_lookup_warn_noexist(vty, name_str);
8108 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
8109
8110 return bgp_vty_return(vty, ret);
8111 }
8112
8113 /* Unset route-map from the peer. */
8114 static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
8115 afi_t afi, safi_t safi)
8116 {
8117 int ret;
8118 struct peer *peer;
8119
8120 peer = peer_and_group_lookup_vty(vty, ip_str);
8121 if (!peer)
8122 return CMD_WARNING_CONFIG_FAILED;
8123
8124 ret = peer_unsuppress_map_unset(peer, afi, safi);
8125
8126 return bgp_vty_return(vty, ret);
8127 }
8128
8129 DEFUN (neighbor_unsuppress_map,
8130 neighbor_unsuppress_map_cmd,
8131 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8132 NEIGHBOR_STR
8133 NEIGHBOR_ADDR_STR2
8134 "Route-map to selectively unsuppress suppressed routes\n"
8135 "Name of route map\n")
8136 {
8137 int idx_peer = 1;
8138 int idx_word = 3;
8139 return peer_unsuppress_map_set_vty(
8140 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8141 argv[idx_word]->arg);
8142 }
8143
8144 ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
8145 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8146 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8147 "Route-map to selectively unsuppress suppressed routes\n"
8148 "Name of route map\n")
8149
8150 DEFUN (no_neighbor_unsuppress_map,
8151 no_neighbor_unsuppress_map_cmd,
8152 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8153 NO_STR
8154 NEIGHBOR_STR
8155 NEIGHBOR_ADDR_STR2
8156 "Route-map to selectively unsuppress suppressed routes\n"
8157 "Name of route map\n")
8158 {
8159 int idx_peer = 2;
8160 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
8161 bgp_node_afi(vty),
8162 bgp_node_safi(vty));
8163 }
8164
8165 ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
8166 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8167 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8168 "Route-map to selectively unsuppress suppressed routes\n"
8169 "Name of route map\n")
8170
8171 /* Maximum number of prefix to be sent to the neighbor. */
8172 DEFUN_YANG(neighbor_maximum_prefix_out,
8173 neighbor_maximum_prefix_out_cmd,
8174 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out (1-4294967295)",
8175 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8176 "Maximum number of prefixes to be sent to this peer\n"
8177 "Maximum no. of prefix limit\n")
8178 {
8179 char base_xpath[XPATH_MAXLEN];
8180 char af_xpath[XPATH_MAXLEN];
8181 char attr_xpath[XPATH_MAXLEN];
8182 int idx_peer = 1;
8183 int idx_number = 3;
8184 afi_t afi = bgp_node_afi(vty);
8185 safi_t safi = bgp_node_safi(vty);
8186
8187 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8188 yang_afi_safi_value2identity(afi, safi));
8189 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8190 sizeof(base_xpath), af_xpath)
8191 < 0)
8192 return CMD_WARNING_CONFIG_FAILED;
8193
8194 snprintf(attr_xpath, sizeof(attr_xpath),
8195 "/%s/prefix-limit/direction-list[direction='out']",
8196 bgp_afi_safi_get_container_str(afi, safi));
8197 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8198
8199 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8200
8201 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8202 argv[idx_number]->arg);
8203
8204 return nb_cli_apply_changes(vty, base_xpath);
8205 }
8206
8207 DEFUN_YANG(no_neighbor_maximum_prefix_out,
8208 no_neighbor_maximum_prefix_out_cmd,
8209 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out",
8210 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8211 "Maximum number of prefixes to be sent to this peer\n")
8212 {
8213 char base_xpath[XPATH_MAXLEN];
8214 char af_xpath[XPATH_MAXLEN];
8215 char attr_xpath[XPATH_MAXLEN];
8216 int idx_peer = 2;
8217 afi_t afi = bgp_node_afi(vty);
8218 safi_t safi = bgp_node_safi(vty);
8219
8220 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8221 yang_afi_safi_value2identity(afi, safi));
8222 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8223 sizeof(base_xpath), af_xpath)
8224 < 0)
8225 return CMD_WARNING_CONFIG_FAILED;
8226
8227 snprintf(attr_xpath, sizeof(attr_xpath),
8228 "/%s/prefix-limit/direction-list[direction='out']",
8229 bgp_afi_safi_get_container_str(afi, safi));
8230 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8231
8232 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
8233
8234 return nb_cli_apply_changes(vty, base_xpath);
8235 }
8236
8237 /* Maximum number of prefix configuration. Prefix count is different
8238 for each peer configuration. So this configuration can be set for
8239 each peer configuration. */
8240 DEFUN_YANG(neighbor_maximum_prefix,
8241 neighbor_maximum_prefix_cmd,
8242 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
8243 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8244 "Maximum number of prefix accept from this peer\n"
8245 "maximum no. of prefix limit\n"
8246 "Force checking all received routes not only accepted\n")
8247 {
8248 int idx_peer = 1;
8249 int idx_number = 3;
8250 int idx_force = 0;
8251 char base_xpath[XPATH_MAXLEN];
8252 char af_xpath[XPATH_MAXLEN];
8253 char attr_xpath[XPATH_MAXLEN];
8254 afi_t afi = bgp_node_afi(vty);
8255 safi_t safi = bgp_node_safi(vty);
8256
8257 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8258 yang_afi_safi_value2identity(afi, safi));
8259 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8260 sizeof(base_xpath), af_xpath)
8261 < 0)
8262 return CMD_WARNING_CONFIG_FAILED;
8263
8264 snprintf(attr_xpath, sizeof(attr_xpath),
8265 "/%s/prefix-limit/direction-list[direction='in']",
8266 bgp_afi_safi_get_container_str(afi, safi));
8267 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8268
8269 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8270
8271 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8272 argv[idx_number]->arg);
8273 if (argv_find(argv, argc, "force", &idx_force))
8274 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8275 "true");
8276
8277 return nb_cli_apply_changes(vty, base_xpath);
8278 }
8279
8280 ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
8281 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
8282 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8283 "Maximum number of prefix accept from this peer\n"
8284 "maximum no. of prefix limit\n"
8285 "Force checking all received routes not only accepted\n")
8286
8287 DEFUN_YANG(neighbor_maximum_prefix_threshold,
8288 neighbor_maximum_prefix_threshold_cmd,
8289 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
8290 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8291 "Maximum number of prefix accept from this peer\n"
8292 "maximum no. of prefix limit\n"
8293 "Threshold value (%) at which to generate a warning msg\n"
8294 "Force checking all received routes not only accepted\n")
8295 {
8296 int idx_peer = 1;
8297 int idx_number = 3;
8298 int idx_number_2 = 4;
8299 int idx_force = 0;
8300 char base_xpath[XPATH_MAXLEN];
8301 char af_xpath[XPATH_MAXLEN];
8302 char attr_xpath[XPATH_MAXLEN];
8303 afi_t afi = bgp_node_afi(vty);
8304 safi_t safi = bgp_node_safi(vty);
8305
8306 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8307 yang_afi_safi_value2identity(afi, safi));
8308 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8309 sizeof(base_xpath), af_xpath)
8310 < 0)
8311 return CMD_WARNING_CONFIG_FAILED;
8312
8313 snprintf(attr_xpath, sizeof(attr_xpath),
8314 "/%s/prefix-limit/direction-list[direction='in']",
8315 bgp_afi_safi_get_container_str(afi, safi));
8316 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8317
8318 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8319
8320 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8321 argv[idx_number]->arg);
8322
8323 nb_cli_enqueue_change(vty, "./options/shutdown-threshold-pct",
8324 NB_OP_MODIFY, argv[idx_number_2]->arg);
8325
8326 if (argv_find(argv, argc, "force", &idx_force))
8327 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8328 "true");
8329
8330 return nb_cli_apply_changes(vty, base_xpath);
8331 }
8332
8333 ALIAS_HIDDEN(
8334 neighbor_maximum_prefix_threshold,
8335 neighbor_maximum_prefix_threshold_hidden_cmd,
8336 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
8337 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8338 "Maximum number of prefix accept from this peer\n"
8339 "maximum no. of prefix limit\n"
8340 "Threshold value (%) at which to generate a warning msg\n"
8341 "Force checking all received routes not only accepted\n")
8342
8343 DEFUN_YANG(neighbor_maximum_prefix_warning,
8344 neighbor_maximum_prefix_warning_cmd,
8345 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
8346 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8347 "Maximum number of prefix accept from this peer\n"
8348 "maximum no. of prefix limit\n"
8349 "Only give warning message when limit is exceeded\n"
8350 "Force checking all received routes not only accepted\n")
8351 {
8352 int idx_peer = 1;
8353 int idx_number = 3;
8354 int idx_force = 0;
8355 char base_xpath[XPATH_MAXLEN];
8356 char af_xpath[XPATH_MAXLEN];
8357 char attr_xpath[XPATH_MAXLEN];
8358 afi_t afi = bgp_node_afi(vty);
8359 safi_t safi = bgp_node_safi(vty);
8360
8361 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8362 yang_afi_safi_value2identity(afi, safi));
8363 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8364 sizeof(base_xpath), af_xpath)
8365 < 0)
8366 return CMD_WARNING_CONFIG_FAILED;
8367
8368 snprintf(attr_xpath, sizeof(attr_xpath),
8369 "/%s/prefix-limit/direction-list[direction='in']",
8370 bgp_afi_safi_get_container_str(afi, safi));
8371 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8372
8373 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8374
8375 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8376 argv[idx_number]->arg);
8377
8378 nb_cli_enqueue_change(vty, "./options/warning-only", NB_OP_MODIFY,
8379 "true");
8380 if (argv_find(argv, argc, "force", &idx_force))
8381 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8382 "true");
8383
8384 return nb_cli_apply_changes(vty, base_xpath);
8385 }
8386
8387 ALIAS_HIDDEN(
8388 neighbor_maximum_prefix_warning,
8389 neighbor_maximum_prefix_warning_hidden_cmd,
8390 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
8391 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8392 "Maximum number of prefix accept from this peer\n"
8393 "maximum no. of prefix limit\n"
8394 "Only give warning message when limit is exceeded\n"
8395 "Force checking all received routes not only accepted\n")
8396
8397 DEFUN_YANG(neighbor_maximum_prefix_threshold_warning,
8398 neighbor_maximum_prefix_threshold_warning_cmd,
8399 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
8400 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8401 "Maximum number of prefix accept from this peer\n"
8402 "maximum no. of prefix limit\n"
8403 "Threshold value (%) at which to generate a warning msg\n"
8404 "Only give warning message when limit is exceeded\n"
8405 "Force checking all received routes not only accepted\n")
8406 {
8407 int idx_peer = 1;
8408 int idx_number = 3;
8409 int idx_number_2 = 4;
8410 int idx_force = 0;
8411 char base_xpath[XPATH_MAXLEN];
8412 char af_xpath[XPATH_MAXLEN];
8413 char attr_xpath[XPATH_MAXLEN];
8414 afi_t afi = bgp_node_afi(vty);
8415 safi_t safi = bgp_node_safi(vty);
8416
8417 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8418 yang_afi_safi_value2identity(afi, safi));
8419 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8420 sizeof(base_xpath), af_xpath)
8421 < 0)
8422 return CMD_WARNING_CONFIG_FAILED;
8423
8424 snprintf(attr_xpath, sizeof(attr_xpath),
8425 "/%s/prefix-limit/direction-list[direction='in']",
8426 bgp_afi_safi_get_container_str(afi, safi));
8427 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8428
8429 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8430
8431 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8432 argv[idx_number]->arg);
8433 nb_cli_enqueue_change(vty, "./options/tw-shutdown-threshold-pct",
8434 NB_OP_MODIFY, argv[idx_number_2]->arg);
8435 nb_cli_enqueue_change(vty, "./options/tw-warning-only", NB_OP_MODIFY,
8436 "true");
8437 if (argv_find(argv, argc, "force", &idx_force))
8438 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8439 "true");
8440
8441 return nb_cli_apply_changes(vty, base_xpath);
8442 }
8443
8444 ALIAS_HIDDEN(
8445 neighbor_maximum_prefix_threshold_warning,
8446 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
8447 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
8448 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8449 "Maximum number of prefix accept from this peer\n"
8450 "maximum no. of prefix limit\n"
8451 "Threshold value (%) at which to generate a warning msg\n"
8452 "Only give warning message when limit is exceeded\n"
8453 "Force checking all received routes not only accepted\n")
8454
8455 DEFUN_YANG(neighbor_maximum_prefix_restart,
8456 neighbor_maximum_prefix_restart_cmd,
8457 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8458 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8459 "Maximum number of prefix accept from this peer\n"
8460 "maximum no. of prefix limit\n"
8461 "Restart bgp connection after limit is exceeded\n"
8462 "Restart interval in minutes\n"
8463 "Force checking all received routes not only accepted\n")
8464 {
8465 int idx_peer = 1;
8466 int idx_number = 3;
8467 int idx_number_2 = 5;
8468 int idx_force = 0;
8469 char base_xpath[XPATH_MAXLEN];
8470 char af_xpath[XPATH_MAXLEN];
8471 char attr_xpath[XPATH_MAXLEN];
8472 afi_t afi = bgp_node_afi(vty);
8473 safi_t safi = bgp_node_safi(vty);
8474
8475 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8476 yang_afi_safi_value2identity(afi, safi));
8477 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8478 sizeof(base_xpath), af_xpath)
8479 < 0)
8480 return CMD_WARNING_CONFIG_FAILED;
8481
8482 snprintf(attr_xpath, sizeof(attr_xpath),
8483 "/%s/prefix-limit/direction-list[direction='in']",
8484 bgp_afi_safi_get_container_str(afi, safi));
8485 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8486
8487 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8488
8489 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8490 argv[idx_number]->arg);
8491 nb_cli_enqueue_change(vty, "./options/restart-timer", NB_OP_MODIFY,
8492 argv[idx_number_2]->arg);
8493 if (argv_find(argv, argc, "force", &idx_force))
8494 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8495 "true");
8496
8497 return nb_cli_apply_changes(vty, base_xpath);
8498 }
8499
8500 ALIAS_HIDDEN(
8501 neighbor_maximum_prefix_restart,
8502 neighbor_maximum_prefix_restart_hidden_cmd,
8503 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8504 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8505 "Maximum number of prefix accept from this peer\n"
8506 "maximum no. of prefix limit\n"
8507 "Restart bgp connection after limit is exceeded\n"
8508 "Restart interval in minutes\n"
8509 "Force checking all received routes not only accepted\n")
8510
8511 DEFUN_YANG(neighbor_maximum_prefix_threshold_restart,
8512 neighbor_maximum_prefix_threshold_restart_cmd,
8513 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8514 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8515 "Maximum number of prefixes to accept from this peer\n"
8516 "maximum no. of prefix limit\n"
8517 "Threshold value (%) at which to generate a warning msg\n"
8518 "Restart bgp connection after limit is exceeded\n"
8519 "Restart interval in minutes\n"
8520 "Force checking all received routes not only accepted\n")
8521 {
8522 int idx_peer = 1;
8523 int idx_number = 3;
8524 int idx_number_2 = 4;
8525 int idx_number_3 = 6;
8526 int idx_force = 0;
8527 char base_xpath[XPATH_MAXLEN];
8528 char af_xpath[XPATH_MAXLEN];
8529 char attr_xpath[XPATH_MAXLEN];
8530 afi_t afi = bgp_node_afi(vty);
8531 safi_t safi = bgp_node_safi(vty);
8532
8533 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8534 yang_afi_safi_value2identity(afi, safi));
8535 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8536 sizeof(base_xpath), af_xpath)
8537 < 0)
8538 return CMD_WARNING_CONFIG_FAILED;
8539
8540 snprintf(attr_xpath, sizeof(attr_xpath),
8541 "/%s/prefix-limit/direction-list[direction='in']",
8542 bgp_afi_safi_get_container_str(afi, safi));
8543 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8544
8545 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8546
8547 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8548 argv[idx_number]->arg);
8549 nb_cli_enqueue_change(vty, "./options/tr-shutdown-threshold-pct",
8550 NB_OP_MODIFY, argv[idx_number_2]->arg);
8551 nb_cli_enqueue_change(vty, "./options/tr-restart-timer", NB_OP_MODIFY,
8552 argv[idx_number_3]->arg);
8553 if (argv_find(argv, argc, "force", &idx_force))
8554 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8555 "true");
8556
8557 return nb_cli_apply_changes(vty, base_xpath);
8558 }
8559
8560 ALIAS_HIDDEN(
8561 neighbor_maximum_prefix_threshold_restart,
8562 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
8563 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8564 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8565 "Maximum number of prefixes to accept from this peer\n"
8566 "maximum no. of prefix limit\n"
8567 "Threshold value (%) at which to generate a warning msg\n"
8568 "Restart bgp connection after limit is exceeded\n"
8569 "Restart interval in minutes\n"
8570 "Force checking all received routes not only accepted\n")
8571
8572 DEFUN_YANG(no_neighbor_maximum_prefix,
8573 no_neighbor_maximum_prefix_cmd,
8574 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8575 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8576 "Maximum number of prefixes to accept from this peer\n"
8577 "maximum no. of prefix limit\n"
8578 "Threshold value (%) at which to generate a warning msg\n"
8579 "Restart bgp connection after limit is exceeded\n"
8580 "Restart interval in minutes\n"
8581 "Only give warning message when limit is exceeded\n"
8582 "Force checking all received routes not only accepted\n")
8583 {
8584 int idx_peer = 2;
8585 char base_xpath[XPATH_MAXLEN];
8586 char af_xpath[XPATH_MAXLEN];
8587 char attr_xpath[XPATH_MAXLEN];
8588 afi_t afi = bgp_node_afi(vty);
8589 safi_t safi = bgp_node_safi(vty);
8590
8591 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8592 yang_afi_safi_value2identity(afi, safi));
8593 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8594 sizeof(base_xpath), af_xpath)
8595 < 0)
8596 return CMD_WARNING_CONFIG_FAILED;
8597
8598 snprintf(attr_xpath, sizeof(attr_xpath),
8599 "/%s/prefix-limit/direction-list[direction='in']",
8600 bgp_afi_safi_get_container_str(afi, safi));
8601 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8602
8603 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
8604
8605 return nb_cli_apply_changes(vty, base_xpath);
8606 }
8607
8608 ALIAS_HIDDEN(
8609 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_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
8621 /* "neighbor allowas-in" */
8622 DEFUN (neighbor_allowas_in,
8623 neighbor_allowas_in_cmd,
8624 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8625 NEIGHBOR_STR
8626 NEIGHBOR_ADDR_STR2
8627 "Accept as-path with my AS present in it\n"
8628 "Number of occurrences of AS number\n"
8629 "Only accept my AS in the as-path if the route was originated in my AS\n")
8630 {
8631 int idx_peer = 1;
8632 int idx_number_origin = 3;
8633 int ret;
8634 int origin = 0;
8635 struct peer *peer;
8636 int allow_num = 0;
8637
8638 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8639 if (!peer)
8640 return CMD_WARNING_CONFIG_FAILED;
8641
8642 if (argc <= idx_number_origin)
8643 allow_num = 3;
8644 else {
8645 if (argv[idx_number_origin]->type == WORD_TKN)
8646 origin = 1;
8647 else
8648 allow_num = atoi(argv[idx_number_origin]->arg);
8649 }
8650
8651 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8652 allow_num, origin);
8653
8654 return bgp_vty_return(vty, ret);
8655 }
8656
8657 ALIAS_HIDDEN(
8658 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
8659 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8660 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8661 "Accept as-path with my AS present in it\n"
8662 "Number of occurrences of AS number\n"
8663 "Only accept my AS in the as-path if the route was originated in my AS\n")
8664
8665 DEFUN (no_neighbor_allowas_in,
8666 no_neighbor_allowas_in_cmd,
8667 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8668 NO_STR
8669 NEIGHBOR_STR
8670 NEIGHBOR_ADDR_STR2
8671 "allow local ASN appears in aspath attribute\n"
8672 "Number of occurrences of AS number\n"
8673 "Only accept my AS in the as-path if the route was originated in my AS\n")
8674 {
8675 int idx_peer = 2;
8676 int ret;
8677 struct peer *peer;
8678
8679 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8680 if (!peer)
8681 return CMD_WARNING_CONFIG_FAILED;
8682
8683 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
8684 bgp_node_safi(vty));
8685
8686 return bgp_vty_return(vty, ret);
8687 }
8688
8689 ALIAS_HIDDEN(
8690 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
8691 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8692 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8693 "allow local ASN appears in aspath attribute\n"
8694 "Number of occurrences of AS number\n"
8695 "Only accept my AS in the as-path if the route was originated in my AS\n")
8696
8697 DEFUN_YANG (neighbor_ttl_security,
8698 neighbor_ttl_security_cmd,
8699 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8700 NEIGHBOR_STR
8701 NEIGHBOR_ADDR_STR2
8702 "BGP ttl-security parameters\n"
8703 "Specify the maximum number of hops to the BGP peer\n"
8704 "Number of hops to BGP peer\n")
8705 {
8706 int idx_peer = 1;
8707 int idx_number = 4;
8708 char base_xpath[XPATH_MAXLEN];
8709
8710 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8711 sizeof(base_xpath), NULL)
8712 < 0)
8713 return CMD_WARNING_CONFIG_FAILED;
8714
8715 nb_cli_enqueue_change(vty, "./ttl-security", NB_OP_MODIFY,
8716 argv[idx_number]->arg);
8717
8718 return nb_cli_apply_changes(vty, base_xpath);
8719 }
8720
8721 DEFUN_YANG(no_neighbor_ttl_security,
8722 no_neighbor_ttl_security_cmd,
8723 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8724 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8725 "BGP ttl-security parameters\n"
8726 "Specify the maximum number of hops to the BGP peer\n"
8727 "Number of hops to BGP peer\n")
8728 {
8729 int idx_peer = 2;
8730 char base_xpath[XPATH_MAXLEN];
8731
8732 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8733 sizeof(base_xpath), NULL)
8734 < 0)
8735 return CMD_WARNING_CONFIG_FAILED;
8736
8737 nb_cli_enqueue_change(vty, "./ttl-security", NB_OP_DESTROY, NULL);
8738
8739 return nb_cli_apply_changes(vty, base_xpath);
8740 }
8741
8742 DEFUN (neighbor_addpath_tx_all_paths,
8743 neighbor_addpath_tx_all_paths_cmd,
8744 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8745 NEIGHBOR_STR
8746 NEIGHBOR_ADDR_STR2
8747 "Use addpath to advertise all paths to a neighbor\n")
8748 {
8749 int idx_peer = 1;
8750 struct peer *peer;
8751
8752 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8753 if (!peer)
8754 return CMD_WARNING_CONFIG_FAILED;
8755
8756 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8757 BGP_ADDPATH_ALL);
8758 return CMD_SUCCESS;
8759 }
8760
8761 ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
8762 neighbor_addpath_tx_all_paths_hidden_cmd,
8763 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8764 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8765 "Use addpath to advertise all paths to a neighbor\n")
8766
8767 DEFUN (no_neighbor_addpath_tx_all_paths,
8768 no_neighbor_addpath_tx_all_paths_cmd,
8769 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8770 NO_STR
8771 NEIGHBOR_STR
8772 NEIGHBOR_ADDR_STR2
8773 "Use addpath to advertise all paths to a neighbor\n")
8774 {
8775 int idx_peer = 2;
8776 struct peer *peer;
8777
8778 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8779 if (!peer)
8780 return CMD_WARNING_CONFIG_FAILED;
8781
8782 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8783 != BGP_ADDPATH_ALL) {
8784 vty_out(vty,
8785 "%% Peer not currently configured to transmit all paths.");
8786 return CMD_WARNING_CONFIG_FAILED;
8787 }
8788
8789 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8790 BGP_ADDPATH_NONE);
8791
8792 return CMD_SUCCESS;
8793 }
8794
8795 ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
8796 no_neighbor_addpath_tx_all_paths_hidden_cmd,
8797 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8798 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8799 "Use addpath to advertise all paths to a neighbor\n")
8800
8801 DEFUN (neighbor_addpath_tx_bestpath_per_as,
8802 neighbor_addpath_tx_bestpath_per_as_cmd,
8803 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8804 NEIGHBOR_STR
8805 NEIGHBOR_ADDR_STR2
8806 "Use addpath to advertise the bestpath per each neighboring AS\n")
8807 {
8808 int idx_peer = 1;
8809 struct peer *peer;
8810
8811 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8812 if (!peer)
8813 return CMD_WARNING_CONFIG_FAILED;
8814
8815 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8816 BGP_ADDPATH_BEST_PER_AS);
8817
8818 return CMD_SUCCESS;
8819 }
8820
8821 ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
8822 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8823 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8824 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8825 "Use addpath to advertise the bestpath per each neighboring AS\n")
8826
8827 DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
8828 no_neighbor_addpath_tx_bestpath_per_as_cmd,
8829 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8830 NO_STR
8831 NEIGHBOR_STR
8832 NEIGHBOR_ADDR_STR2
8833 "Use addpath to advertise the bestpath per each neighboring AS\n")
8834 {
8835 int idx_peer = 2;
8836 struct peer *peer;
8837
8838 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8839 if (!peer)
8840 return CMD_WARNING_CONFIG_FAILED;
8841
8842 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8843 != BGP_ADDPATH_BEST_PER_AS) {
8844 vty_out(vty,
8845 "%% Peer not currently configured to transmit all best path per as.");
8846 return CMD_WARNING_CONFIG_FAILED;
8847 }
8848
8849 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8850 BGP_ADDPATH_NONE);
8851
8852 return CMD_SUCCESS;
8853 }
8854
8855 ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
8856 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8857 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8858 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8859 "Use addpath to advertise the bestpath per each neighboring AS\n")
8860
8861 DEFPY(
8862 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
8863 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8864 NEIGHBOR_STR
8865 NEIGHBOR_ADDR_STR2
8866 "Detect AS loops before sending to neighbor\n")
8867 {
8868 struct peer *peer;
8869
8870 peer = peer_and_group_lookup_vty(vty, neighbor);
8871 if (!peer)
8872 return CMD_WARNING_CONFIG_FAILED;
8873
8874 peer->as_path_loop_detection = true;
8875
8876 return CMD_SUCCESS;
8877 }
8878
8879 DEFPY(
8880 no_neighbor_aspath_loop_detection,
8881 no_neighbor_aspath_loop_detection_cmd,
8882 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8883 NO_STR
8884 NEIGHBOR_STR
8885 NEIGHBOR_ADDR_STR2
8886 "Detect AS loops before sending to neighbor\n")
8887 {
8888 struct peer *peer;
8889
8890 peer = peer_and_group_lookup_vty(vty, neighbor);
8891 if (!peer)
8892 return CMD_WARNING_CONFIG_FAILED;
8893
8894 peer->as_path_loop_detection = false;
8895
8896 return CMD_SUCCESS;
8897 }
8898
8899 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
8900 struct ecommunity **list, bool is_rt6)
8901 {
8902 struct ecommunity *ecom = NULL;
8903 struct ecommunity *ecomadd;
8904
8905 for (; argc; --argc, ++argv) {
8906 if (is_rt6)
8907 ecomadd = ecommunity_str2com_ipv6(argv[0]->arg,
8908 ECOMMUNITY_ROUTE_TARGET,
8909 0);
8910 else
8911 ecomadd = ecommunity_str2com(argv[0]->arg,
8912 ECOMMUNITY_ROUTE_TARGET,
8913 0);
8914 if (!ecomadd) {
8915 vty_out(vty, "Malformed community-list value\n");
8916 if (ecom)
8917 ecommunity_free(&ecom);
8918 return CMD_WARNING_CONFIG_FAILED;
8919 }
8920
8921 if (ecom) {
8922 ecommunity_merge(ecom, ecomadd);
8923 ecommunity_free(&ecomadd);
8924 } else {
8925 ecom = ecomadd;
8926 }
8927 }
8928
8929 if (*list) {
8930 ecommunity_free(&*list);
8931 }
8932 *list = ecom;
8933
8934 return CMD_SUCCESS;
8935 }
8936
8937 bool vpn_policy_check_import(struct bgp *bgp, afi_t afi, safi_t safi,
8938 bool v2vimport, char *errmsg, size_t errmsg_len)
8939 {
8940 if (!v2vimport) {
8941 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8942 BGP_CONFIG_VRF_TO_VRF_IMPORT)
8943 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8944 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
8945 snprintf(
8946 errmsg, errmsg_len, "%s",
8947 "%% error: Please unconfigure import vrf commands before using vpn commands");
8948 return false;
8949 }
8950 } else {
8951 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8952 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
8953 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8954 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
8955 snprintf(
8956 errmsg, errmsg_len, "%s",
8957 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands");
8958 return false;
8959 }
8960 }
8961 return true;
8962 }
8963
8964 /*
8965 * v2vimport is true if we are handling a `import vrf ...` command
8966 */
8967 static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
8968 {
8969 afi_t afi;
8970
8971 switch (vty->node) {
8972 case BGP_IPV4_NODE:
8973 afi = AFI_IP;
8974 break;
8975 case BGP_IPV6_NODE:
8976 afi = AFI_IP6;
8977 break;
8978 default:
8979 vty_out(vty,
8980 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
8981 return AFI_MAX;
8982 }
8983
8984 if (!v2vimport) {
8985 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8986 BGP_CONFIG_VRF_TO_VRF_IMPORT)
8987 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8988 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
8989 vty_out(vty,
8990 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
8991 return AFI_MAX;
8992 }
8993 } else {
8994 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8995 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
8996 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8997 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
8998 vty_out(vty,
8999 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
9000 return AFI_MAX;
9001 }
9002 }
9003 return afi;
9004 }
9005
9006 DEFPY_YANG(
9007 af_rd_vpn_export,
9008 af_rd_vpn_export_cmd,
9009 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
9010 NO_STR
9011 "Specify route distinguisher\n"
9012 "Between current address-family and vpn\n"
9013 "For routes leaked from current address-family to vpn\n"
9014 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
9015 {
9016 char base_xpath[XPATH_MAXLEN];
9017 afi_t afi;
9018 safi_t safi;
9019 int idx = 0;
9020
9021 afi = bgp_node_afi(vty);
9022 safi = bgp_node_safi(vty);
9023
9024 snprintf(
9025 base_xpath, sizeof(base_xpath),
9026 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config",
9027 yang_afi_safi_value2identity(afi, safi),
9028 bgp_afi_safi_get_container_str(afi, safi));
9029
9030 if (argv_find(argv, argc, "no", &idx))
9031 nb_cli_enqueue_change(vty, "./rd", NB_OP_DESTROY, NULL);
9032 else
9033 nb_cli_enqueue_change(vty, "./rd", NB_OP_MODIFY, rd_str);
9034
9035 return nb_cli_apply_changes(vty, base_xpath);
9036 }
9037
9038 void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rd(
9039 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9040 {
9041 int indent = 2;
9042
9043 vty_out(vty, "%*srd vpn export %s\n", indent, "",
9044 yang_dnode_get_string(dnode, NULL));
9045 }
9046
9047 ALIAS (af_rd_vpn_export,
9048 af_no_rd_vpn_export_cmd,
9049 "no rd vpn export",
9050 NO_STR
9051 "Specify route distinguisher\n"
9052 "Between current address-family and vpn\n"
9053 "For routes leaked from current address-family to vpn\n")
9054
9055 DEFPY (af_label_vpn_export,
9056 af_label_vpn_export_cmd,
9057 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
9058 NO_STR
9059 "label value for VRF\n"
9060 "Between current address-family and vpn\n"
9061 "For routes leaked from current address-family to vpn\n"
9062 "Label Value <0-1048575>\n"
9063 "Automatically assign a label\n")
9064 {
9065 VTY_DECLVAR_CONTEXT(bgp, bgp);
9066 mpls_label_t label = MPLS_LABEL_NONE;
9067 afi_t afi;
9068 int idx = 0;
9069 bool yes = true;
9070
9071 if (argv_find(argv, argc, "no", &idx))
9072 yes = false;
9073
9074 /* If "no ...", squash trailing parameter */
9075 if (!yes)
9076 label_auto = NULL;
9077
9078 if (yes) {
9079 if (!label_auto)
9080 label = label_val; /* parser should force unsigned */
9081 }
9082
9083 afi = vpn_policy_getafi(vty, bgp, false);
9084 if (afi == AFI_MAX)
9085 return CMD_WARNING_CONFIG_FAILED;
9086
9087
9088 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9089 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
9090 /* no change */
9091 return CMD_SUCCESS;
9092
9093 /*
9094 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
9095 */
9096 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9097 bgp_get_default(), bgp);
9098
9099 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9100 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
9101
9102 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
9103
9104 /*
9105 * label has previously been automatically
9106 * assigned by labelpool: release it
9107 *
9108 * NB if tovpn_label == MPLS_LABEL_NONE it
9109 * means the automatic assignment is in flight
9110 * and therefore the labelpool callback must
9111 * detect that the auto label is not needed.
9112 */
9113
9114 bgp_lp_release(LP_TYPE_VRF,
9115 &bgp->vpn_policy[afi],
9116 bgp->vpn_policy[afi].tovpn_label);
9117 }
9118 UNSET_FLAG(bgp->vpn_policy[afi].flags,
9119 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
9120 }
9121
9122 bgp->vpn_policy[afi].tovpn_label = label;
9123 if (label_auto) {
9124 SET_FLAG(bgp->vpn_policy[afi].flags,
9125 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
9126 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
9127 vpn_leak_label_callback);
9128 }
9129
9130 /* post-change: re-export vpn routes */
9131 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9132 bgp_get_default(), bgp);
9133
9134 return CMD_SUCCESS;
9135 }
9136
9137 ALIAS (af_label_vpn_export,
9138 af_no_label_vpn_export_cmd,
9139 "no label vpn export",
9140 NO_STR
9141 "label value for VRF\n"
9142 "Between current address-family and vpn\n"
9143 "For routes leaked from current address-family to vpn\n")
9144
9145 DEFPY_YANG (af_nexthop_vpn_export,
9146 af_nexthop_vpn_export_cmd,
9147 "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
9148 NO_STR
9149 "Specify next hop to use for VRF advertised prefixes\n"
9150 "Between current address-family and vpn\n"
9151 "For routes leaked from current address-family to vpn\n"
9152 "IPv4 prefix\n"
9153 "IPv6 prefix\n")
9154 {
9155 char base_xpath[XPATH_MAXLEN];
9156 afi_t afi;
9157 safi_t safi;
9158 int idx = 0;
9159 struct prefix p;
9160
9161 if (!no) {
9162 if (!nexthop_su) {
9163 vty_out(vty, "%% Nexthop required\n");
9164 return CMD_WARNING_CONFIG_FAILED;
9165 }
9166 if (!sockunion2hostprefix(nexthop_su, &p))
9167 return CMD_WARNING_CONFIG_FAILED;
9168 }
9169
9170 afi = bgp_node_afi(vty);
9171 safi = bgp_node_safi(vty);
9172
9173 snprintf(
9174 base_xpath, sizeof(base_xpath),
9175 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config",
9176 yang_afi_safi_value2identity(afi, safi),
9177 bgp_afi_safi_get_container_str(afi, safi));
9178
9179 if (argv_find(argv, argc, "no", &idx))
9180 nb_cli_enqueue_change(vty, "./nexthop", NB_OP_DESTROY, NULL);
9181 else
9182 nb_cli_enqueue_change(vty, "./nexthop", NB_OP_MODIFY,
9183 nexthop_su_str);
9184
9185 return nb_cli_apply_changes(vty, base_xpath);
9186 }
9187
9188 void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_nexthop(
9189 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9190 {
9191 int indent = 2;
9192
9193 vty_out(vty, "%*snexthop vpn export %s\n", indent, "",
9194 yang_dnode_get_string(dnode, NULL));
9195 }
9196
9197 static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
9198 {
9199 if (!strcmp(dstr, "import")) {
9200 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9201 } else if (!strcmp(dstr, "export")) {
9202 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9203 } else if (!strcmp(dstr, "both")) {
9204 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9205 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9206 } else {
9207 vty_out(vty, "%% direction parse error\n");
9208 return CMD_WARNING_CONFIG_FAILED;
9209 }
9210 return CMD_SUCCESS;
9211 }
9212
9213 DEFPY (af_rt_vpn_imexport,
9214 af_rt_vpn_imexport_cmd,
9215 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
9216 NO_STR
9217 "Specify route target list\n"
9218 "Specify route target list\n"
9219 "Between current address-family and vpn\n"
9220 "For routes leaked from vpn to current address-family: match any\n"
9221 "For routes leaked from current address-family to vpn: set\n"
9222 "both import: match any and export: set\n"
9223 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
9224 {
9225 VTY_DECLVAR_CONTEXT(bgp, bgp);
9226 int ret;
9227 struct ecommunity *ecom = NULL;
9228 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
9229 vpn_policy_direction_t dir;
9230 afi_t afi;
9231 int idx = 0;
9232 bool yes = true;
9233
9234 if (argv_find(argv, argc, "no", &idx))
9235 yes = false;
9236
9237 afi = vpn_policy_getafi(vty, bgp, false);
9238 if (afi == AFI_MAX)
9239 return CMD_WARNING_CONFIG_FAILED;
9240
9241 ret = vpn_policy_getdirs(vty, direction_str, dodir);
9242 if (ret != CMD_SUCCESS)
9243 return ret;
9244
9245 if (yes) {
9246 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9247 vty_out(vty, "%% Missing RTLIST\n");
9248 return CMD_WARNING_CONFIG_FAILED;
9249 }
9250 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, false);
9251 if (ret != CMD_SUCCESS) {
9252 return ret;
9253 }
9254 }
9255
9256 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9257 if (!dodir[dir])
9258 continue;
9259
9260 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9261
9262 if (yes) {
9263 if (bgp->vpn_policy[afi].rtlist[dir])
9264 ecommunity_free(
9265 &bgp->vpn_policy[afi].rtlist[dir]);
9266 bgp->vpn_policy[afi].rtlist[dir] =
9267 ecommunity_dup(ecom);
9268 } else {
9269 if (bgp->vpn_policy[afi].rtlist[dir])
9270 ecommunity_free(
9271 &bgp->vpn_policy[afi].rtlist[dir]);
9272 bgp->vpn_policy[afi].rtlist[dir] = NULL;
9273 }
9274
9275 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9276 }
9277
9278 if (ecom)
9279 ecommunity_free(&ecom);
9280
9281 return CMD_SUCCESS;
9282 }
9283
9284 ALIAS (af_rt_vpn_imexport,
9285 af_no_rt_vpn_imexport_cmd,
9286 "no <rt|route-target> vpn <import|export|both>$direction_str",
9287 NO_STR
9288 "Specify route target list\n"
9289 "Specify route target list\n"
9290 "Between current address-family and vpn\n"
9291 "For routes leaked from vpn to current address-family\n"
9292 "For routes leaked from current address-family to vpn\n"
9293 "both import and export\n")
9294
9295 DEFPY_YANG (af_route_map_vpn_imexport,
9296 af_route_map_vpn_imexport_cmd,
9297 /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
9298 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
9299 NO_STR
9300 "Specify route map\n"
9301 "Between current address-family and vpn\n"
9302 "For routes leaked from vpn to current address-family\n"
9303 "For routes leaked from current address-family to vpn\n"
9304 "name of route-map\n")
9305 {
9306 char base_xpath[XPATH_MAXLEN];
9307 afi_t afi;
9308 safi_t safi;
9309 int idx = 0;
9310
9311 afi = bgp_node_afi(vty);
9312 safi = bgp_node_safi(vty);
9313
9314 snprintf(
9315 base_xpath, sizeof(base_xpath),
9316 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config",
9317 yang_afi_safi_value2identity(afi, safi),
9318 bgp_afi_safi_get_container_str(afi, safi));
9319
9320 if (argv_find(argv, argc, "no", &idx)) {
9321 if (!strcmp(direction_str, "import"))
9322 nb_cli_enqueue_change(vty, "./rmap-import",
9323 NB_OP_DESTROY, NULL);
9324 else if (!strcmp(direction_str, "export"))
9325 nb_cli_enqueue_change(vty, "./rmap-export",
9326 NB_OP_DESTROY, NULL);
9327 } else {
9328 if (!strcmp(direction_str, "import"))
9329 nb_cli_enqueue_change(vty, "./rmap-import",
9330 NB_OP_MODIFY, rmap_str);
9331 if (!strcmp(direction_str, "export"))
9332 nb_cli_enqueue_change(vty, "./rmap-export",
9333 NB_OP_MODIFY, rmap_str);
9334 }
9335 return nb_cli_apply_changes(vty, base_xpath);
9336 }
9337
9338 void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rmap_import(
9339 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9340 {
9341 int indent = 2;
9342
9343 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
9344 yang_dnode_get_string(dnode, NULL));
9345 }
9346
9347 void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rmap_export(
9348 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9349 {
9350 int indent = 2;
9351
9352 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
9353 yang_dnode_get_string(dnode, NULL));
9354 }
9355
9356 ALIAS (af_route_map_vpn_imexport,
9357 af_no_route_map_vpn_imexport_cmd,
9358 "no route-map vpn <import|export>$direction_str",
9359 NO_STR
9360 "Specify route map\n"
9361 "Between current address-family and vpn\n"
9362 "For routes leaked from vpn to current address-family\n"
9363 "For routes leaked from current address-family to vpn\n")
9364
9365 DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
9366 "import vrf route-map RMAP$rmap_str",
9367 "Import routes from another VRF\n"
9368 "Vrf routes being filtered\n"
9369 "Specify route map\n"
9370 "name of route-map\n")
9371 {
9372 VTY_DECLVAR_CONTEXT(bgp, bgp);
9373 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
9374 afi_t afi;
9375 struct bgp *bgp_default;
9376
9377 afi = vpn_policy_getafi(vty, bgp, true);
9378 if (afi == AFI_MAX)
9379 return CMD_WARNING_CONFIG_FAILED;
9380
9381 bgp_default = bgp_get_default();
9382 if (!bgp_default) {
9383 int32_t ret;
9384 as_t as = bgp->as;
9385
9386 /* Auto-create assuming the same AS */
9387 ret = bgp_get_vty(&bgp_default, &as, NULL,
9388 BGP_INSTANCE_TYPE_DEFAULT);
9389
9390 if (ret) {
9391 vty_out(vty,
9392 "VRF default is not configured as a bgp instance\n");
9393 return CMD_WARNING;
9394 }
9395 }
9396
9397 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9398
9399 if (bgp->vpn_policy[afi].rmap_name[dir])
9400 XFREE(MTYPE_ROUTE_MAP_NAME,
9401 bgp->vpn_policy[afi].rmap_name[dir]);
9402 bgp->vpn_policy[afi].rmap_name[dir] =
9403 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
9404 bgp->vpn_policy[afi].rmap[dir] =
9405 route_map_lookup_warn_noexist(vty, rmap_str);
9406 if (!bgp->vpn_policy[afi].rmap[dir])
9407 return CMD_SUCCESS;
9408
9409 SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9410 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9411
9412 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9413
9414 return CMD_SUCCESS;
9415 }
9416
9417 DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
9418 "no import vrf route-map [RMAP$rmap_str]",
9419 NO_STR
9420 "Import routes from another VRF\n"
9421 "Vrf routes being filtered\n"
9422 "Specify route map\n"
9423 "name of route-map\n")
9424 {
9425 VTY_DECLVAR_CONTEXT(bgp, bgp);
9426 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
9427 afi_t afi;
9428
9429 afi = vpn_policy_getafi(vty, bgp, true);
9430 if (afi == AFI_MAX)
9431 return CMD_WARNING_CONFIG_FAILED;
9432
9433 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9434
9435 if (bgp->vpn_policy[afi].rmap_name[dir])
9436 XFREE(MTYPE_ROUTE_MAP_NAME,
9437 bgp->vpn_policy[afi].rmap_name[dir]);
9438 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9439 bgp->vpn_policy[afi].rmap[dir] = NULL;
9440
9441 if (bgp->vpn_policy[afi].import_vrf->count == 0)
9442 UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9443 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9444
9445 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9446
9447 return CMD_SUCCESS;
9448 }
9449
9450 DEFPY_YANG(bgp_imexport_vrf,
9451 bgp_imexport_vrf_cmd,
9452 "[no] import vrf VIEWVRFNAME$import_name",
9453 NO_STR
9454 "Import routes from another VRF\n"
9455 "VRF to import from\n"
9456 "The name of the VRF\n")
9457 {
9458 char base_xpath[XPATH_MAXLEN];
9459 safi_t safi;
9460 afi_t afi;
9461 int32_t idx = 0;
9462
9463 if (import_name == NULL) {
9464 vty_out(vty, "%% Missing import name\n");
9465 return CMD_WARNING;
9466 }
9467
9468 if (strcmp(import_name, "route-map") == 0) {
9469 vty_out(vty, "%% Must include route-map name\n");
9470 return CMD_WARNING;
9471 }
9472
9473 afi = bgp_node_afi(vty);
9474 safi = bgp_node_safi(vty);
9475
9476 snprintf(
9477 base_xpath, sizeof(base_xpath),
9478 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config/import-vrf-list[vrf='%s']",
9479 yang_afi_safi_value2identity(afi, safi),
9480 bgp_afi_safi_get_container_str(afi, safi), import_name);
9481
9482 if (argv_find(argv, argc, "no", &idx))
9483 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
9484 else
9485 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
9486
9487 return nb_cli_apply_changes(vty, base_xpath);
9488 }
9489
9490 void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_import_vrfs(
9491 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9492 {
9493 vty_out(vty, " import vrf %s\n",
9494 yang_dnode_get_string(dnode, "./vrf"));
9495 }
9496
9497 /* This command is valid only in a bgp vrf instance or the default instance */
9498 DEFPY_YANG (bgp_imexport_vpn,
9499 bgp_imexport_vpn_cmd,
9500 "[no] <import|export>$direction_str vpn",
9501 NO_STR
9502 "Import routes to this address-family\n"
9503 "Export routes from this address-family\n"
9504 "to/from default instance VPN RIB\n")
9505 {
9506 char base_xpath[XPATH_MAXLEN];
9507 safi_t safi;
9508 afi_t afi;
9509 int32_t idx = 0;
9510
9511 afi = bgp_node_afi(vty);
9512 safi = bgp_node_safi(vty);
9513
9514 if (!strcmp(direction_str, "import")) {
9515 snprintf(
9516 base_xpath, sizeof(base_xpath),
9517 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config/import-vpn",
9518 yang_afi_safi_value2identity(afi, safi),
9519 bgp_afi_safi_get_container_str(afi, safi));
9520 } else if (!strcmp(direction_str, "export")) {
9521 snprintf(
9522 base_xpath, sizeof(base_xpath),
9523 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config/export-vpn",
9524 yang_afi_safi_value2identity(afi, safi),
9525 bgp_afi_safi_get_container_str(afi, safi));
9526 } else {
9527 vty_out(vty, "%% unknown direction %s\n", direction_str);
9528 return CMD_WARNING_CONFIG_FAILED;
9529 }
9530
9531 if (argv_find(argv, argc, "no", &idx))
9532 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
9533 else
9534 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, "true");
9535
9536 return nb_cli_apply_changes(vty, base_xpath);
9537 }
9538
9539 void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_import_vpn(
9540 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9541 {
9542 if (yang_dnode_get_bool(dnode, NULL))
9543 vty_out(vty, " import vpn\n");
9544 }
9545
9546 void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_export_vpn(
9547 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9548 {
9549 if (yang_dnode_get_bool(dnode, NULL))
9550 vty_out(vty, " export vpn\n");
9551 }
9552
9553 DEFPY (af_routetarget_import,
9554 af_routetarget_import_cmd,
9555 "[no] <rt|route-target|route-target6|rt6> redirect import RTLIST...",
9556 NO_STR
9557 "Specify route target list\n"
9558 "Specify route target list\n"
9559 "Specify route target list\n"
9560 "Specify route target list\n"
9561 "Flow-spec redirect type route target\n"
9562 "Import routes to this address-family\n"
9563 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN|IPV6:MN)\n")
9564 {
9565 VTY_DECLVAR_CONTEXT(bgp, bgp);
9566 int ret;
9567 struct ecommunity *ecom = NULL;
9568 afi_t afi;
9569 int idx = 0, idx_unused = 0;
9570 bool yes = true;
9571 bool rt6 = false;
9572
9573 if (argv_find(argv, argc, "no", &idx))
9574 yes = false;
9575
9576 if (argv_find(argv, argc, "rt6", &idx_unused) ||
9577 argv_find(argv, argc, "route-target6", &idx_unused))
9578 rt6 = true;
9579
9580 afi = vpn_policy_getafi(vty, bgp, false);
9581 if (afi == AFI_MAX)
9582 return CMD_WARNING_CONFIG_FAILED;
9583
9584 if (rt6 && afi != AFI_IP6)
9585 return CMD_WARNING_CONFIG_FAILED;
9586
9587 if (yes) {
9588 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9589 vty_out(vty, "%% Missing RTLIST\n");
9590 return CMD_WARNING_CONFIG_FAILED;
9591 }
9592 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, rt6);
9593 if (ret != CMD_SUCCESS)
9594 return ret;
9595 }
9596
9597 if (yes) {
9598 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9599 ecommunity_free(&bgp->vpn_policy[afi]
9600 .import_redirect_rtlist);
9601 bgp->vpn_policy[afi].import_redirect_rtlist =
9602 ecommunity_dup(ecom);
9603 } else {
9604 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9605 ecommunity_free(&bgp->vpn_policy[afi]
9606 .import_redirect_rtlist);
9607 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
9608 }
9609
9610 if (ecom)
9611 ecommunity_free(&ecom);
9612
9613 return CMD_SUCCESS;
9614 }
9615
9616 void cli_show_bgp_global_afi_safi_header(struct vty *vty,
9617 struct lyd_node *dnode,
9618 bool show_defaults)
9619 {
9620 const char *af_name;
9621 afi_t afi;
9622 safi_t safi;
9623
9624 af_name = yang_dnode_get_string(dnode, "./afi-safi-name");
9625 yang_afi_safi_identity2value(af_name, &afi, &safi);
9626
9627 vty_out(vty, " !\n address-family ");
9628 if (afi == AFI_IP) {
9629 if (safi == SAFI_UNICAST)
9630 vty_out(vty, "ipv4 unicast");
9631 else if (safi == SAFI_LABELED_UNICAST)
9632 vty_out(vty, "ipv4 labeled-unicast");
9633 else if (safi == SAFI_MULTICAST)
9634 vty_out(vty, "ipv4 multicast");
9635 else if (safi == SAFI_MPLS_VPN)
9636 vty_out(vty, "ipv4 vpn");
9637 else if (safi == SAFI_ENCAP)
9638 vty_out(vty, "ipv4 encap");
9639 else if (safi == SAFI_FLOWSPEC)
9640 vty_out(vty, "ipv4 flowspec");
9641 } else if (afi == AFI_IP6) {
9642 if (safi == SAFI_UNICAST)
9643 vty_out(vty, "ipv6 unicast");
9644 else if (safi == SAFI_LABELED_UNICAST)
9645 vty_out(vty, "ipv6 labeled-unicast");
9646 else if (safi == SAFI_MULTICAST)
9647 vty_out(vty, "ipv6 multicast");
9648 else if (safi == SAFI_MPLS_VPN)
9649 vty_out(vty, "ipv6 vpn");
9650 else if (safi == SAFI_ENCAP)
9651 vty_out(vty, "ipv6 encap");
9652 else if (safi == SAFI_FLOWSPEC)
9653 vty_out(vty, "ipv6 flowspec");
9654 } else if (afi == AFI_L2VPN) {
9655 if (safi == SAFI_EVPN)
9656 vty_out(vty, "l2vpn evpn");
9657 }
9658 vty_out(vty, "\n");
9659 }
9660
9661 DEFUN_NOSH (address_family_ipv4_safi,
9662 address_family_ipv4_safi_cmd,
9663 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9664 "Enter Address Family command mode\n"
9665 "Address Family\n"
9666 BGP_SAFI_WITH_LABEL_HELP_STR)
9667 {
9668
9669 safi_t safi = SAFI_UNICAST;
9670 const struct lyd_node *vrf_dnode, *bgp_glb_dnode;
9671 const char *vrf_name = NULL;
9672
9673 if (argc == 3) {
9674 safi = bgp_vty_safi_from_str(argv[2]->text);
9675
9676 bgp_glb_dnode = yang_dnode_get(vty->candidate_config->dnode,
9677 VTY_CURR_XPATH);
9678 vrf_dnode = yang_dnode_get_parent(bgp_glb_dnode,
9679 "control-plane-protocol");
9680 vrf_name = yang_dnode_get_string(vrf_dnode, "./vrf");
9681
9682 if (!strmatch(vrf_name, VRF_DEFAULT_NAME)
9683 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9684 && safi != SAFI_EVPN) {
9685 vty_out(vty,
9686 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9687 return CMD_WARNING_CONFIG_FAILED;
9688 }
9689 }
9690 vty->node = bgp_node_type(AFI_IP, safi);
9691
9692 return CMD_SUCCESS;
9693 }
9694
9695 DEFUN_NOSH (address_family_ipv6_safi,
9696 address_family_ipv6_safi_cmd,
9697 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9698 "Enter Address Family command mode\n"
9699 "Address Family\n"
9700 BGP_SAFI_WITH_LABEL_HELP_STR)
9701 {
9702 safi_t safi = SAFI_UNICAST;
9703 const struct lyd_node *vrf_dnode, *bgp_glb_dnode;
9704 const char *vrf_name = NULL;
9705
9706 if (argc == 3) {
9707 safi = bgp_vty_safi_from_str(argv[2]->text);
9708 bgp_glb_dnode = yang_dnode_get(vty->candidate_config->dnode,
9709 VTY_CURR_XPATH);
9710 vrf_dnode = yang_dnode_get_parent(bgp_glb_dnode,
9711 "control-plane-protocol");
9712 vrf_name = yang_dnode_get_string(vrf_dnode, "./vrf");
9713
9714 if (!strmatch(vrf_name, VRF_DEFAULT_NAME)
9715 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9716 && safi != SAFI_EVPN) {
9717 vty_out(vty,
9718 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9719 return CMD_WARNING_CONFIG_FAILED;
9720 }
9721 }
9722 vty->node = bgp_node_type(AFI_IP6, safi);
9723
9724 return CMD_SUCCESS;
9725 }
9726
9727 #ifdef KEEP_OLD_VPN_COMMANDS
9728 DEFUN_NOSH (address_family_vpnv4,
9729 address_family_vpnv4_cmd,
9730 "address-family vpnv4 [unicast]",
9731 "Enter Address Family command mode\n"
9732 "Address Family\n"
9733 "Address Family modifier\n")
9734 {
9735 vty->node = BGP_VPNV4_NODE;
9736 return CMD_SUCCESS;
9737 }
9738
9739 DEFUN_NOSH (address_family_vpnv6,
9740 address_family_vpnv6_cmd,
9741 "address-family vpnv6 [unicast]",
9742 "Enter Address Family command mode\n"
9743 "Address Family\n"
9744 "Address Family modifier\n")
9745 {
9746 vty->node = BGP_VPNV6_NODE;
9747 return CMD_SUCCESS;
9748 }
9749 #endif /* KEEP_OLD_VPN_COMMANDS */
9750
9751 DEFUN_NOSH (address_family_evpn,
9752 address_family_evpn_cmd,
9753 "address-family l2vpn evpn",
9754 "Enter Address Family command mode\n"
9755 "Address Family\n"
9756 "Address Family modifier\n")
9757 {
9758 VTY_DECLVAR_CONTEXT(bgp, bgp);
9759 vty->node = BGP_EVPN_NODE;
9760 return CMD_SUCCESS;
9761 }
9762
9763 DEFUN_NOSH (exit_address_family,
9764 exit_address_family_cmd,
9765 "exit-address-family",
9766 "Exit from Address Family configuration mode\n")
9767 {
9768 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
9769 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
9770 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
9771 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
9772 || vty->node == BGP_EVPN_NODE
9773 || vty->node == BGP_FLOWSPECV4_NODE
9774 || vty->node == BGP_FLOWSPECV6_NODE)
9775 vty->node = BGP_NODE;
9776 return CMD_SUCCESS;
9777 }
9778
9779 void cli_show_bgp_global_afi_safi_header_end(struct vty *vty,
9780 struct lyd_node *dnode
9781 __attribute__((__unused__)))
9782 {
9783 vty_out(vty, " exit-address-family\n");
9784 }
9785
9786 /* Recalculate bestpath and re-advertise a prefix */
9787 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
9788 const char *ip_str, afi_t afi, safi_t safi,
9789 struct prefix_rd *prd)
9790 {
9791 int ret;
9792 struct prefix match;
9793 struct bgp_dest *dest;
9794 struct bgp_dest *rm;
9795 struct bgp *bgp;
9796 struct bgp_table *table;
9797 struct bgp_table *rib;
9798
9799 /* BGP structure lookup. */
9800 if (view_name) {
9801 bgp = bgp_lookup_by_name(view_name);
9802 if (bgp == NULL) {
9803 vty_out(vty, "%% Can't find BGP instance %s\n",
9804 view_name);
9805 return CMD_WARNING;
9806 }
9807 } else {
9808 bgp = bgp_get_default();
9809 if (bgp == NULL) {
9810 vty_out(vty, "%% No BGP process is configured\n");
9811 return CMD_WARNING;
9812 }
9813 }
9814
9815 /* Check IP address argument. */
9816 ret = str2prefix(ip_str, &match);
9817 if (!ret) {
9818 vty_out(vty, "%% address is malformed\n");
9819 return CMD_WARNING;
9820 }
9821
9822 match.family = afi2family(afi);
9823 rib = bgp->rib[afi][safi];
9824
9825 if (safi == SAFI_MPLS_VPN) {
9826 for (dest = bgp_table_top(rib); dest;
9827 dest = bgp_route_next(dest)) {
9828 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
9829
9830 if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
9831 continue;
9832
9833 table = bgp_dest_get_bgp_table_info(dest);
9834 if (table == NULL)
9835 continue;
9836
9837 if ((rm = bgp_node_match(table, &match)) != NULL) {
9838 const struct prefix *rm_p =
9839 bgp_dest_get_prefix(rm);
9840
9841 if (rm_p->prefixlen == match.prefixlen) {
9842 SET_FLAG(rm->flags,
9843 BGP_NODE_USER_CLEAR);
9844 bgp_process(bgp, rm, afi, safi);
9845 }
9846 bgp_dest_unlock_node(rm);
9847 }
9848 }
9849 } else {
9850 if ((dest = bgp_node_match(rib, &match)) != NULL) {
9851 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
9852
9853 if (dest_p->prefixlen == match.prefixlen) {
9854 SET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
9855 bgp_process(bgp, dest, afi, safi);
9856 }
9857 bgp_dest_unlock_node(dest);
9858 }
9859 }
9860
9861 return CMD_SUCCESS;
9862 }
9863
9864 /* one clear bgp command to rule them all */
9865 DEFUN (clear_ip_bgp_all,
9866 clear_ip_bgp_all_cmd,
9867 "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>]",
9868 CLEAR_STR
9869 IP_STR
9870 BGP_STR
9871 BGP_INSTANCE_HELP_STR
9872 BGP_AFI_HELP_STR
9873 "Address Family\n"
9874 BGP_SAFI_WITH_LABEL_HELP_STR
9875 "Address Family modifier\n"
9876 "Clear all peers\n"
9877 "BGP IPv4 neighbor to clear\n"
9878 "BGP IPv6 neighbor to clear\n"
9879 "BGP neighbor on interface to clear\n"
9880 "Clear peers with the AS number\n"
9881 "Clear all external peers\n"
9882 "Clear all members of peer-group\n"
9883 "BGP peer-group name\n"
9884 BGP_SOFT_STR
9885 BGP_SOFT_IN_STR
9886 BGP_SOFT_OUT_STR
9887 BGP_SOFT_IN_STR
9888 "Push out prefix-list ORF and do inbound soft reconfig\n"
9889 BGP_SOFT_OUT_STR)
9890 {
9891 char *vrf = NULL;
9892
9893 afi_t afi = AFI_UNSPEC;
9894 safi_t safi = SAFI_UNSPEC;
9895 enum clear_sort clr_sort = clear_peer;
9896 enum bgp_clear_type clr_type;
9897 char *clr_arg = NULL;
9898
9899 int idx = 0;
9900 char errmsg[BUFSIZ] = {'\0'};
9901 int ret;
9902
9903 /* clear [ip] bgp */
9904 if (argv_find(argv, argc, "ip", &idx))
9905 afi = AFI_IP;
9906
9907 /* [<vrf> VIEWVRFNAME] */
9908 if (argv_find(argv, argc, "vrf", &idx)) {
9909 vrf = argv[idx + 1]->arg;
9910 idx += 2;
9911 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9912 vrf = NULL;
9913 } else if (argv_find(argv, argc, "view", &idx)) {
9914 /* [<view> VIEWVRFNAME] */
9915 vrf = argv[idx + 1]->arg;
9916 idx += 2;
9917 }
9918 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
9919 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
9920 argv_find_and_parse_safi(argv, argc, &idx, &safi);
9921
9922 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
9923 if (argv_find(argv, argc, "*", &idx)) {
9924 clr_sort = clear_all;
9925 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
9926 clr_sort = clear_peer;
9927 clr_arg = argv[idx]->arg;
9928 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
9929 clr_sort = clear_peer;
9930 clr_arg = argv[idx]->arg;
9931 } else if (argv_find(argv, argc, "peer-group", &idx)) {
9932 clr_sort = clear_group;
9933 idx++;
9934 clr_arg = argv[idx]->arg;
9935 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
9936 clr_sort = clear_peer;
9937 clr_arg = argv[idx]->arg;
9938 } else if (argv_find(argv, argc, "WORD", &idx)) {
9939 clr_sort = clear_peer;
9940 clr_arg = argv[idx]->arg;
9941 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
9942 clr_sort = clear_as;
9943 clr_arg = argv[idx]->arg;
9944 } else if (argv_find(argv, argc, "external", &idx)) {
9945 clr_sort = clear_external;
9946 }
9947
9948 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
9949 if (argv_find(argv, argc, "soft", &idx)) {
9950 if (argv_find(argv, argc, "in", &idx)
9951 || argv_find(argv, argc, "out", &idx))
9952 clr_type = strmatch(argv[idx]->text, "in")
9953 ? BGP_CLEAR_SOFT_IN
9954 : BGP_CLEAR_SOFT_OUT;
9955 else
9956 clr_type = BGP_CLEAR_SOFT_BOTH;
9957 } else if (argv_find(argv, argc, "in", &idx)) {
9958 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
9959 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
9960 : BGP_CLEAR_SOFT_IN;
9961 } else if (argv_find(argv, argc, "out", &idx)) {
9962 clr_type = BGP_CLEAR_SOFT_OUT;
9963 } else
9964 clr_type = BGP_CLEAR_SOFT_NONE;
9965
9966 ret = bgp_clear_vty(vrf, afi, safi, clr_sort, clr_type, clr_arg, errmsg,
9967 sizeof(errmsg));
9968 if (ret != NB_OK)
9969 vty_out(vty, "Error description: %s\n", errmsg);
9970
9971 return ret;
9972 }
9973
9974 DEFUN (clear_ip_bgp_prefix,
9975 clear_ip_bgp_prefix_cmd,
9976 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
9977 CLEAR_STR
9978 IP_STR
9979 BGP_STR
9980 BGP_INSTANCE_HELP_STR
9981 "Clear bestpath and re-advertise\n"
9982 "IPv4 prefix\n")
9983 {
9984 char *vrf = NULL;
9985 char *prefix = NULL;
9986
9987 int idx = 0;
9988
9989 /* [<view|vrf> VIEWVRFNAME] */
9990 if (argv_find(argv, argc, "vrf", &idx)) {
9991 vrf = argv[idx + 1]->arg;
9992 idx += 2;
9993 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9994 vrf = NULL;
9995 } else if (argv_find(argv, argc, "view", &idx)) {
9996 /* [<view> VIEWVRFNAME] */
9997 vrf = argv[idx + 1]->arg;
9998 idx += 2;
9999 }
10000
10001 prefix = argv[argc - 1]->arg;
10002
10003 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
10004 }
10005
10006 DEFUN (clear_bgp_ipv6_safi_prefix,
10007 clear_bgp_ipv6_safi_prefix_cmd,
10008 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
10009 CLEAR_STR
10010 IP_STR
10011 BGP_STR
10012 "Address Family\n"
10013 BGP_SAFI_HELP_STR
10014 "Clear bestpath and re-advertise\n"
10015 "IPv6 prefix\n")
10016 {
10017 int idx_safi = 0;
10018 int idx_ipv6_prefix = 0;
10019 safi_t safi = SAFI_UNICAST;
10020 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
10021 argv[idx_ipv6_prefix]->arg : NULL;
10022
10023 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
10024 return bgp_clear_prefix(
10025 vty, NULL, prefix, AFI_IP6,
10026 safi, NULL);
10027 }
10028
10029 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
10030 clear_bgp_instance_ipv6_safi_prefix_cmd,
10031 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
10032 CLEAR_STR
10033 IP_STR
10034 BGP_STR
10035 BGP_INSTANCE_HELP_STR
10036 "Address Family\n"
10037 BGP_SAFI_HELP_STR
10038 "Clear bestpath and re-advertise\n"
10039 "IPv6 prefix\n")
10040 {
10041 int idx_safi = 0;
10042 int idx_vrfview = 0;
10043 int idx_ipv6_prefix = 0;
10044 safi_t safi = SAFI_UNICAST;
10045 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
10046 argv[idx_ipv6_prefix]->arg : NULL;
10047 char *vrfview = NULL;
10048
10049 /* [<view|vrf> VIEWVRFNAME] */
10050 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
10051 vrfview = argv[idx_vrfview + 1]->arg;
10052 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
10053 vrfview = NULL;
10054 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
10055 /* [<view> VIEWVRFNAME] */
10056 vrfview = argv[idx_vrfview + 1]->arg;
10057 }
10058 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
10059
10060 return bgp_clear_prefix(
10061 vty, vrfview, prefix,
10062 AFI_IP6, safi, NULL);
10063 }
10064
10065 DEFUN (show_bgp_views,
10066 show_bgp_views_cmd,
10067 "show [ip] bgp views",
10068 SHOW_STR
10069 IP_STR
10070 BGP_STR
10071 "Show the defined BGP views\n")
10072 {
10073 struct list *inst = bm->bgp;
10074 struct listnode *node;
10075 struct bgp *bgp;
10076
10077 vty_out(vty, "Defined BGP views:\n");
10078 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10079 /* Skip VRFs. */
10080 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
10081 continue;
10082 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
10083 bgp->as);
10084 }
10085
10086 return CMD_SUCCESS;
10087 }
10088
10089 DEFUN (show_bgp_vrfs,
10090 show_bgp_vrfs_cmd,
10091 "show [ip] bgp vrfs [json]",
10092 SHOW_STR
10093 IP_STR
10094 BGP_STR
10095 "Show BGP VRFs\n"
10096 JSON_STR)
10097 {
10098 char buf[ETHER_ADDR_STRLEN];
10099 struct list *inst = bm->bgp;
10100 struct listnode *node;
10101 struct bgp *bgp;
10102 bool uj = use_json(argc, argv);
10103 json_object *json = NULL;
10104 json_object *json_vrfs = NULL;
10105 int count = 0;
10106
10107 if (uj) {
10108 json = json_object_new_object();
10109 json_vrfs = json_object_new_object();
10110 }
10111
10112 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10113 const char *name, *type;
10114 struct peer *peer;
10115 struct listnode *node2, *nnode2;
10116 int peers_cfg, peers_estb;
10117 json_object *json_vrf = NULL;
10118
10119 /* Skip Views. */
10120 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
10121 continue;
10122
10123 count++;
10124 if (!uj && count == 1) {
10125 vty_out(vty,
10126 "%4s %-5s %-16s %9s %10s %-37s\n",
10127 "Type", "Id", "routerId", "#PeersCfg",
10128 "#PeersEstb", "Name");
10129 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
10130 "L3-VNI", "RouterMAC", "Interface");
10131 }
10132
10133 peers_cfg = peers_estb = 0;
10134 if (uj)
10135 json_vrf = json_object_new_object();
10136
10137
10138 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
10139 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10140 continue;
10141 peers_cfg++;
10142 if (peer->status == Established)
10143 peers_estb++;
10144 }
10145
10146 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
10147 name = VRF_DEFAULT_NAME;
10148 type = "DFLT";
10149 } else {
10150 name = bgp->name;
10151 type = "VRF";
10152 }
10153
10154
10155 if (uj) {
10156 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10157 ? -1
10158 : (int64_t)bgp->vrf_id;
10159 char buf[BUFSIZ] = {0};
10160
10161 json_object_string_add(json_vrf, "type", type);
10162 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
10163 json_object_string_add(json_vrf, "routerId",
10164 inet_ntop(AF_INET,
10165 &bgp->router_id, buf,
10166 sizeof(buf)));
10167 json_object_int_add(json_vrf, "numConfiguredPeers",
10168 peers_cfg);
10169 json_object_int_add(json_vrf, "numEstablishedPeers",
10170 peers_estb);
10171
10172 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
10173 json_object_string_add(
10174 json_vrf, "rmac",
10175 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
10176 json_object_string_add(json_vrf, "interface",
10177 ifindex2ifname(bgp->l3vni_svi_ifindex,
10178 bgp->vrf_id));
10179 json_object_object_add(json_vrfs, name, json_vrf);
10180 } else {
10181 vty_out(vty, "%4s %-5d %-16pI4 %-9u %-10u %-37s\n",
10182 type,
10183 bgp->vrf_id == VRF_UNKNOWN ? -1
10184 : (int)bgp->vrf_id,
10185 &bgp->router_id, peers_cfg, peers_estb, name);
10186 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
10187 bgp->l3vni,
10188 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
10189 ifindex2ifname(bgp->l3vni_svi_ifindex,
10190 bgp->vrf_id));
10191 }
10192 }
10193
10194 if (uj) {
10195 json_object_object_add(json, "vrfs", json_vrfs);
10196
10197 json_object_int_add(json, "totalVrfs", count);
10198
10199 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10200 json, JSON_C_TO_STRING_PRETTY));
10201 json_object_free(json);
10202 } else {
10203 if (count)
10204 vty_out(vty,
10205 "\nTotal number of VRFs (including default): %d\n",
10206 count);
10207 }
10208
10209 return CMD_SUCCESS;
10210 }
10211
10212 DEFUN (show_bgp_mac_hash,
10213 show_bgp_mac_hash_cmd,
10214 "show bgp mac hash",
10215 SHOW_STR
10216 BGP_STR
10217 "Mac Address\n"
10218 "Mac Address database\n")
10219 {
10220 bgp_mac_dump_table(vty);
10221
10222 return CMD_SUCCESS;
10223 }
10224
10225 static void show_tip_entry(struct hash_bucket *bucket, void *args)
10226 {
10227 struct vty *vty = (struct vty *)args;
10228 struct tip_addr *tip = (struct tip_addr *)bucket->data;
10229
10230 vty_out(vty, "addr: %pI4, count: %d\n", &tip->addr, tip->refcnt);
10231 }
10232
10233 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
10234 {
10235 vty_out(vty, "self nexthop database:\n");
10236 bgp_nexthop_show_address_hash(vty, bgp);
10237
10238 vty_out(vty, "Tunnel-ip database:\n");
10239 hash_iterate(bgp->tip_hash,
10240 (void (*)(struct hash_bucket *, void *))show_tip_entry,
10241 vty);
10242 }
10243
10244 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
10245 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
10246 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
10247 "martian next-hops\n"
10248 "martian next-hop database\n")
10249 {
10250 struct bgp *bgp = NULL;
10251 int idx = 0;
10252 char *name = NULL;
10253
10254 /* [<vrf> VIEWVRFNAME] */
10255 if (argv_find(argv, argc, "vrf", &idx)) {
10256 name = argv[idx + 1]->arg;
10257 if (name && strmatch(name, VRF_DEFAULT_NAME))
10258 name = NULL;
10259 } else if (argv_find(argv, argc, "view", &idx))
10260 /* [<view> VIEWVRFNAME] */
10261 name = argv[idx + 1]->arg;
10262 if (name)
10263 bgp = bgp_lookup_by_name(name);
10264 else
10265 bgp = bgp_get_default();
10266
10267 if (!bgp) {
10268 vty_out(vty, "%% No BGP process is configured\n");
10269 return CMD_WARNING;
10270 }
10271 bgp_show_martian_nexthops(vty, bgp);
10272
10273 return CMD_SUCCESS;
10274 }
10275
10276 DEFUN (show_bgp_memory,
10277 show_bgp_memory_cmd,
10278 "show [ip] bgp memory",
10279 SHOW_STR
10280 IP_STR
10281 BGP_STR
10282 "Global BGP memory statistics\n")
10283 {
10284 char memstrbuf[MTYPE_MEMSTR_LEN];
10285 unsigned long count;
10286
10287 /* RIB related usage stats */
10288 count = mtype_stats_alloc(MTYPE_BGP_NODE);
10289 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
10290 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10291 count * sizeof(struct bgp_dest)));
10292
10293 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
10294 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
10295 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10296 count * sizeof(struct bgp_path_info)));
10297 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
10298 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
10299 count,
10300 mtype_memstr(
10301 memstrbuf, sizeof(memstrbuf),
10302 count * sizeof(struct bgp_path_info_extra)));
10303
10304 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
10305 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
10306 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10307 count * sizeof(struct bgp_static)));
10308
10309 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
10310 vty_out(vty, "%ld Packets, using %s of memory\n", count,
10311 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10312 count * sizeof(struct bpacket)));
10313
10314 /* Adj-In/Out */
10315 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
10316 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
10317 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10318 count * sizeof(struct bgp_adj_in)));
10319 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
10320 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
10321 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10322 count * sizeof(struct bgp_adj_out)));
10323
10324 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
10325 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
10326 count,
10327 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10328 count * sizeof(struct bgp_nexthop_cache)));
10329
10330 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
10331 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
10332 count,
10333 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10334 count * sizeof(struct bgp_damp_info)));
10335
10336 /* Attributes */
10337 count = attr_count();
10338 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
10339 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10340 count * sizeof(struct attr)));
10341
10342 if ((count = attr_unknown_count()))
10343 vty_out(vty, "%ld unknown attributes\n", count);
10344
10345 /* AS_PATH attributes */
10346 count = aspath_count();
10347 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
10348 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10349 count * sizeof(struct aspath)));
10350
10351 count = mtype_stats_alloc(MTYPE_AS_SEG);
10352 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
10353 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10354 count * sizeof(struct assegment)));
10355
10356 /* Other attributes */
10357 if ((count = community_count()))
10358 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
10359 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10360 count * sizeof(struct community)));
10361 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
10362 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
10363 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10364 count * sizeof(struct ecommunity)));
10365 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
10366 vty_out(vty,
10367 "%ld BGP large-community entries, using %s of memory\n",
10368 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10369 count * sizeof(struct lcommunity)));
10370
10371 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
10372 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
10373 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10374 count * sizeof(struct cluster_list)));
10375
10376 /* Peer related usage */
10377 count = mtype_stats_alloc(MTYPE_BGP_PEER);
10378 vty_out(vty, "%ld peers, using %s of memory\n", count,
10379 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10380 count * sizeof(struct peer)));
10381
10382 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
10383 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
10384 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10385 count * sizeof(struct peer_group)));
10386
10387 /* Other */
10388 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
10389 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
10390 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10391 count * sizeof(regex_t)));
10392 return CMD_SUCCESS;
10393 }
10394
10395 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
10396 {
10397 json_object *bestpath = json_object_new_object();
10398
10399 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
10400 json_object_string_add(bestpath, "asPath", "ignore");
10401
10402 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
10403 json_object_string_add(bestpath, "asPath", "confed");
10404
10405 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
10406 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
10407 json_object_string_add(bestpath, "multiPathRelax",
10408 "as-set");
10409 else
10410 json_object_string_add(bestpath, "multiPathRelax",
10411 "true");
10412 } else
10413 json_object_string_add(bestpath, "multiPathRelax", "false");
10414
10415 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
10416 json_object_string_add(bestpath, "compareRouterId", "true");
10417 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
10418 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
10419 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
10420 json_object_string_add(bestpath, "med", "confed");
10421 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
10422 json_object_string_add(bestpath, "med",
10423 "missing-as-worst");
10424 else
10425 json_object_string_add(bestpath, "med", "true");
10426 }
10427
10428 json_object_object_add(json, "bestPath", bestpath);
10429 }
10430
10431 /* Print the error code/subcode for why the peer is down */
10432 static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
10433 json_object *json_peer, bool use_json)
10434 {
10435 const char *code_str;
10436 const char *subcode_str;
10437
10438 if (use_json) {
10439 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10440 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10441 char errorcodesubcode_hexstr[5];
10442 char errorcodesubcode_str[256];
10443
10444 code_str = bgp_notify_code_str(peer->notify.code);
10445 subcode_str = bgp_notify_subcode_str(
10446 peer->notify.code,
10447 peer->notify.subcode);
10448
10449 snprintf(errorcodesubcode_hexstr,
10450 sizeof(errorcodesubcode_hexstr), "%02X%02X",
10451 peer->notify.code, peer->notify.subcode);
10452 json_object_string_add(json_peer,
10453 "lastErrorCodeSubcode",
10454 errorcodesubcode_hexstr);
10455 snprintf(errorcodesubcode_str, 255, "%s%s",
10456 code_str, subcode_str);
10457 json_object_string_add(json_peer,
10458 "lastNotificationReason",
10459 errorcodesubcode_str);
10460 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10461 && peer->notify.code == BGP_NOTIFY_CEASE
10462 && (peer->notify.subcode
10463 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10464 || peer->notify.subcode
10465 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10466 && peer->notify.length) {
10467 char msgbuf[1024];
10468 const char *msg_str;
10469
10470 msg_str = bgp_notify_admin_message(
10471 msgbuf, sizeof(msgbuf),
10472 (uint8_t *)peer->notify.data,
10473 peer->notify.length);
10474 if (msg_str)
10475 json_object_string_add(
10476 json_peer,
10477 "lastShutdownDescription",
10478 msg_str);
10479 }
10480
10481 }
10482 json_object_string_add(json_peer, "lastResetDueTo",
10483 peer_down_str[(int)peer->last_reset]);
10484 json_object_int_add(json_peer, "lastResetCode",
10485 peer->last_reset);
10486 } else {
10487 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10488 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10489 code_str = bgp_notify_code_str(peer->notify.code);
10490 subcode_str =
10491 bgp_notify_subcode_str(peer->notify.code,
10492 peer->notify.subcode);
10493 vty_out(vty, " Notification %s (%s%s)\n",
10494 peer->last_reset == PEER_DOWN_NOTIFY_SEND
10495 ? "sent"
10496 : "received",
10497 code_str, subcode_str);
10498 } else {
10499 vty_out(vty, " %s\n",
10500 peer_down_str[(int)peer->last_reset]);
10501 }
10502 }
10503 }
10504
10505 static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
10506 safi_t safi)
10507 {
10508 return ((peer->status != Established) ||
10509 !peer->afc_recv[afi][safi]);
10510 }
10511
10512 static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
10513 struct peer *peer, json_object *json_peer,
10514 int max_neighbor_width, bool use_json)
10515 {
10516 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10517 int len;
10518
10519 if (use_json) {
10520 if (peer_dynamic_neighbor(peer))
10521 json_object_boolean_true_add(json_peer,
10522 "dynamicPeer");
10523 if (peer->hostname)
10524 json_object_string_add(json_peer, "hostname",
10525 peer->hostname);
10526
10527 if (peer->domainname)
10528 json_object_string_add(json_peer, "domainname",
10529 peer->domainname);
10530 json_object_int_add(json_peer, "connectionsEstablished",
10531 peer->established);
10532 json_object_int_add(json_peer, "connectionsDropped",
10533 peer->dropped);
10534 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10535 use_json, json_peer);
10536 if (peer->status == Established)
10537 json_object_string_add(json_peer, "lastResetDueTo",
10538 "AFI/SAFI Not Negotiated");
10539 else
10540 bgp_show_peer_reset(NULL, peer, json_peer, true);
10541 } else {
10542 dn_flag[1] = '\0';
10543 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
10544 if (peer->hostname
10545 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
10546 len = vty_out(vty, "%s%s(%s)", dn_flag,
10547 peer->hostname, peer->host);
10548 else
10549 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10550
10551 /* pad the neighbor column with spaces */
10552 if (len < max_neighbor_width)
10553 vty_out(vty, "%*s", max_neighbor_width - len,
10554 " ");
10555 vty_out(vty, "%7d %7d %9s", peer->established,
10556 peer->dropped,
10557 peer_uptime(peer->uptime, timebuf,
10558 BGP_UPTIME_LEN, 0, NULL));
10559 if (peer->status == Established)
10560 vty_out(vty, " AFI/SAFI Not Negotiated\n");
10561 else
10562 bgp_show_peer_reset(vty, peer, NULL,
10563 false);
10564 }
10565 }
10566
10567
10568 /* Show BGP peer's summary information. */
10569 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
10570 bool show_failed, bool show_established,
10571 bool use_json)
10572 {
10573 struct peer *peer;
10574 struct listnode *node, *nnode;
10575 unsigned int count = 0, dn_count = 0;
10576 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10577 char neighbor_buf[VTY_BUFSIZ];
10578 int neighbor_col_default_width = 16;
10579 int len, failed_count = 0;
10580 int max_neighbor_width = 0;
10581 int pfx_rcd_safi;
10582 json_object *json = NULL;
10583 json_object *json_peer = NULL;
10584 json_object *json_peers = NULL;
10585 struct peer_af *paf;
10586 struct bgp_filter *filter;
10587
10588 /* labeled-unicast routes are installed in the unicast table so in order
10589 * to
10590 * display the correct PfxRcd value we must look at SAFI_UNICAST
10591 */
10592
10593 if (safi == SAFI_LABELED_UNICAST)
10594 pfx_rcd_safi = SAFI_UNICAST;
10595 else
10596 pfx_rcd_safi = safi;
10597
10598 if (use_json) {
10599 json = json_object_new_object();
10600 json_peers = json_object_new_object();
10601 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10602 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10603 continue;
10604
10605 if (peer->afc[afi][safi]) {
10606 /* See if we have at least a single failed peer */
10607 if (bgp_has_peer_failed(peer, afi, safi))
10608 failed_count++;
10609 count++;
10610 }
10611 if (peer_dynamic_neighbor(peer))
10612 dn_count++;
10613 }
10614
10615 } else {
10616 /* Loop over all neighbors that will be displayed to determine
10617 * how many
10618 * characters are needed for the Neighbor column
10619 */
10620 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10621 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10622 continue;
10623
10624 if (peer->afc[afi][safi]) {
10625 memset(dn_flag, '\0', sizeof(dn_flag));
10626 if (peer_dynamic_neighbor(peer))
10627 dn_flag[0] = '*';
10628
10629 if (peer->hostname
10630 && CHECK_FLAG(bgp->flags,
10631 BGP_FLAG_SHOW_HOSTNAME))
10632 snprintf(neighbor_buf,
10633 sizeof(neighbor_buf),
10634 "%s%s(%s) ", dn_flag,
10635 peer->hostname, peer->host);
10636 else
10637 snprintf(neighbor_buf,
10638 sizeof(neighbor_buf), "%s%s ",
10639 dn_flag, peer->host);
10640
10641 len = strlen(neighbor_buf);
10642
10643 if (len > max_neighbor_width)
10644 max_neighbor_width = len;
10645
10646 /* See if we have at least a single failed peer */
10647 if (bgp_has_peer_failed(peer, afi, safi))
10648 failed_count++;
10649 count++;
10650 }
10651 }
10652
10653 /* Originally we displayed the Neighbor column as 16
10654 * characters wide so make that the default
10655 */
10656 if (max_neighbor_width < neighbor_col_default_width)
10657 max_neighbor_width = neighbor_col_default_width;
10658 }
10659
10660 if (show_failed && !failed_count) {
10661 if (use_json) {
10662 json_object_int_add(json, "failedPeersCount", 0);
10663 json_object_int_add(json, "dynamicPeers", dn_count);
10664 json_object_int_add(json, "totalPeers", count);
10665
10666 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10667 json, JSON_C_TO_STRING_PRETTY));
10668 json_object_free(json);
10669 } else {
10670 vty_out(vty, "%% No failed BGP neighbors found\n");
10671 vty_out(vty, "\nTotal number of neighbors %d\n", count);
10672 }
10673 return CMD_SUCCESS;
10674 }
10675
10676 count = 0; /* Reset the value as its used again */
10677 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10678 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10679 continue;
10680
10681 if (!peer->afc[afi][safi])
10682 continue;
10683
10684 if (!count) {
10685 unsigned long ents;
10686 char memstrbuf[MTYPE_MEMSTR_LEN];
10687 int64_t vrf_id_ui;
10688
10689 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10690 ? -1
10691 : (int64_t)bgp->vrf_id;
10692
10693 /* Usage summary and header */
10694 if (use_json) {
10695 char buf[BUFSIZ] = {0};
10696
10697 json_object_string_add(
10698 json, "routerId",
10699 inet_ntop(AF_INET, &bgp->router_id, buf,
10700 sizeof(buf)));
10701 json_object_int_add(json, "as", bgp->as);
10702 json_object_int_add(json, "vrfId", vrf_id_ui);
10703 json_object_string_add(
10704 json, "vrfName",
10705 (bgp->inst_type
10706 == BGP_INSTANCE_TYPE_DEFAULT)
10707 ? VRF_DEFAULT_NAME
10708 : bgp->name);
10709 } else {
10710 vty_out(vty,
10711 "BGP router identifier %pI4, local AS number %u vrf-id %d",
10712 &bgp->router_id, bgp->as,
10713 bgp->vrf_id == VRF_UNKNOWN
10714 ? -1
10715 : (int)bgp->vrf_id);
10716 vty_out(vty, "\n");
10717 }
10718
10719 if (bgp_update_delay_configured(bgp)) {
10720 if (use_json) {
10721 json_object_int_add(
10722 json, "updateDelayLimit",
10723 bgp->v_update_delay);
10724
10725 if (bgp->v_update_delay
10726 != bgp->v_establish_wait)
10727 json_object_int_add(
10728 json,
10729 "updateDelayEstablishWait",
10730 bgp->v_establish_wait);
10731
10732 if (bgp_update_delay_active(bgp)) {
10733 json_object_string_add(
10734 json,
10735 "updateDelayFirstNeighbor",
10736 bgp->update_delay_begin_time);
10737 json_object_boolean_true_add(
10738 json,
10739 "updateDelayInProgress");
10740 } else {
10741 if (bgp->update_delay_over) {
10742 json_object_string_add(
10743 json,
10744 "updateDelayFirstNeighbor",
10745 bgp->update_delay_begin_time);
10746 json_object_string_add(
10747 json,
10748 "updateDelayBestpathResumed",
10749 bgp->update_delay_end_time);
10750 json_object_string_add(
10751 json,
10752 "updateDelayZebraUpdateResume",
10753 bgp->update_delay_zebra_resume_time);
10754 json_object_string_add(
10755 json,
10756 "updateDelayPeerUpdateResume",
10757 bgp->update_delay_peers_resume_time);
10758 }
10759 }
10760 } else {
10761 vty_out(vty,
10762 "Read-only mode update-delay limit: %d seconds\n",
10763 bgp->v_update_delay);
10764 if (bgp->v_update_delay
10765 != bgp->v_establish_wait)
10766 vty_out(vty,
10767 " Establish wait: %d seconds\n",
10768 bgp->v_establish_wait);
10769
10770 if (bgp_update_delay_active(bgp)) {
10771 vty_out(vty,
10772 " First neighbor established: %s\n",
10773 bgp->update_delay_begin_time);
10774 vty_out(vty,
10775 " Delay in progress\n");
10776 } else {
10777 if (bgp->update_delay_over) {
10778 vty_out(vty,
10779 " First neighbor established: %s\n",
10780 bgp->update_delay_begin_time);
10781 vty_out(vty,
10782 " Best-paths resumed: %s\n",
10783 bgp->update_delay_end_time);
10784 vty_out(vty,
10785 " zebra update resumed: %s\n",
10786 bgp->update_delay_zebra_resume_time);
10787 vty_out(vty,
10788 " peers update resumed: %s\n",
10789 bgp->update_delay_peers_resume_time);
10790 }
10791 }
10792 }
10793 }
10794
10795 if (use_json) {
10796 if (bgp_maxmed_onstartup_configured(bgp)
10797 && bgp->maxmed_active)
10798 json_object_boolean_true_add(
10799 json, "maxMedOnStartup");
10800 if (bgp->v_maxmed_admin)
10801 json_object_boolean_true_add(
10802 json, "maxMedAdministrative");
10803
10804 json_object_int_add(
10805 json, "tableVersion",
10806 bgp_table_version(bgp->rib[afi][safi]));
10807
10808 ents = bgp_table_count(bgp->rib[afi][safi]);
10809 json_object_int_add(json, "ribCount", ents);
10810 json_object_int_add(
10811 json, "ribMemory",
10812 ents * sizeof(struct bgp_dest));
10813
10814 ents = bgp->af_peer_count[afi][safi];
10815 json_object_int_add(json, "peerCount", ents);
10816 json_object_int_add(json, "peerMemory",
10817 ents * sizeof(struct peer));
10818
10819 if ((ents = listcount(bgp->group))) {
10820 json_object_int_add(
10821 json, "peerGroupCount", ents);
10822 json_object_int_add(
10823 json, "peerGroupMemory",
10824 ents * sizeof(struct
10825 peer_group));
10826 }
10827
10828 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10829 BGP_CONFIG_DAMPENING))
10830 json_object_boolean_true_add(
10831 json, "dampeningEnabled");
10832 } else {
10833 if (bgp_maxmed_onstartup_configured(bgp)
10834 && bgp->maxmed_active)
10835 vty_out(vty,
10836 "Max-med on-startup active\n");
10837 if (bgp->v_maxmed_admin)
10838 vty_out(vty,
10839 "Max-med administrative active\n");
10840
10841 vty_out(vty, "BGP table version %" PRIu64 "\n",
10842 bgp_table_version(bgp->rib[afi][safi]));
10843
10844 ents = bgp_table_count(bgp->rib[afi][safi]);
10845 vty_out(vty,
10846 "RIB entries %ld, using %s of memory\n",
10847 ents,
10848 mtype_memstr(
10849 memstrbuf, sizeof(memstrbuf),
10850 ents
10851 * sizeof(struct
10852 bgp_dest)));
10853
10854 /* Peer related usage */
10855 ents = bgp->af_peer_count[afi][safi];
10856 vty_out(vty, "Peers %ld, using %s of memory\n",
10857 ents,
10858 mtype_memstr(
10859 memstrbuf, sizeof(memstrbuf),
10860 ents * sizeof(struct peer)));
10861
10862 if ((ents = listcount(bgp->group)))
10863 vty_out(vty,
10864 "Peer groups %ld, using %s of memory\n",
10865 ents,
10866 mtype_memstr(
10867 memstrbuf,
10868 sizeof(memstrbuf),
10869 ents * sizeof(struct
10870 peer_group)));
10871
10872 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10873 BGP_CONFIG_DAMPENING))
10874 vty_out(vty, "Dampening enabled.\n");
10875 vty_out(vty, "\n");
10876
10877 /* Subtract 8 here because 'Neighbor' is
10878 * 8 characters */
10879 vty_out(vty, "Neighbor");
10880 vty_out(vty, "%*s", max_neighbor_width - 8,
10881 " ");
10882 if (show_failed)
10883 vty_out(vty, "EstdCnt DropCnt ResetTime Reason\n");
10884 else
10885 vty_out(vty,
10886 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd PfxSnt Desc\n");
10887 }
10888 }
10889
10890 paf = peer_af_find(peer, afi, safi);
10891 filter = &peer->filter[afi][safi];
10892
10893 count++;
10894 /* Works for both failed & successful cases */
10895 if (peer_dynamic_neighbor(peer))
10896 dn_count++;
10897
10898 if (use_json) {
10899 json_peer = NULL;
10900
10901 if (show_failed &&
10902 bgp_has_peer_failed(peer, afi, safi)) {
10903 json_peer = json_object_new_object();
10904 bgp_show_failed_summary(vty, bgp, peer,
10905 json_peer, 0, use_json);
10906 } else if (!show_failed) {
10907 if (show_established
10908 && bgp_has_peer_failed(peer, afi, safi))
10909 continue;
10910
10911 json_peer = json_object_new_object();
10912 if (peer_dynamic_neighbor(peer)) {
10913 json_object_boolean_true_add(json_peer,
10914 "dynamicPeer");
10915 }
10916
10917 if (peer->hostname)
10918 json_object_string_add(json_peer, "hostname",
10919 peer->hostname);
10920
10921 if (peer->domainname)
10922 json_object_string_add(json_peer, "domainname",
10923 peer->domainname);
10924
10925 json_object_int_add(json_peer, "remoteAs", peer->as);
10926 json_object_int_add(json_peer, "version", 4);
10927 json_object_int_add(json_peer, "msgRcvd",
10928 PEER_TOTAL_RX(peer));
10929 json_object_int_add(json_peer, "msgSent",
10930 PEER_TOTAL_TX(peer));
10931
10932 atomic_size_t outq_count, inq_count;
10933 outq_count = atomic_load_explicit(
10934 &peer->obuf->count,
10935 memory_order_relaxed);
10936 inq_count = atomic_load_explicit(
10937 &peer->ibuf->count,
10938 memory_order_relaxed);
10939
10940 json_object_int_add(json_peer, "tableVersion",
10941 peer->version[afi][safi]);
10942 json_object_int_add(json_peer, "outq",
10943 outq_count);
10944 json_object_int_add(json_peer, "inq",
10945 inq_count);
10946 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10947 use_json, json_peer);
10948
10949 json_object_int_add(json_peer, "pfxRcd",
10950 peer->pcount[afi][pfx_rcd_safi]);
10951
10952 if (paf && PAF_SUBGRP(paf))
10953 json_object_int_add(
10954 json_peer, "pfxSnt",
10955 (PAF_SUBGRP(paf))->scount);
10956 else
10957 json_object_int_add(json_peer, "pfxSnt",
10958 0);
10959
10960 /* BGP FSM state */
10961 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
10962 || CHECK_FLAG(peer->bgp->flags,
10963 BGP_FLAG_SHUTDOWN))
10964 json_object_string_add(json_peer,
10965 "state",
10966 "Idle (Admin)");
10967 else if (peer->afc_recv[afi][safi])
10968 json_object_string_add(
10969 json_peer, "state",
10970 lookup_msg(bgp_status_msg,
10971 peer->status, NULL));
10972 else if (CHECK_FLAG(
10973 peer->sflags,
10974 PEER_STATUS_PREFIX_OVERFLOW))
10975 json_object_string_add(json_peer,
10976 "state",
10977 "Idle (PfxCt)");
10978 else
10979 json_object_string_add(
10980 json_peer, "state",
10981 lookup_msg(bgp_status_msg,
10982 peer->status, NULL));
10983
10984 /* BGP peer state */
10985 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
10986 || CHECK_FLAG(peer->bgp->flags,
10987 BGP_FLAG_SHUTDOWN))
10988 json_object_string_add(json_peer,
10989 "peerState",
10990 "Admin");
10991 else if (CHECK_FLAG(
10992 peer->sflags,
10993 PEER_STATUS_PREFIX_OVERFLOW))
10994 json_object_string_add(json_peer,
10995 "peerState",
10996 "PfxCt");
10997 else if (CHECK_FLAG(peer->flags,
10998 PEER_FLAG_PASSIVE))
10999 json_object_string_add(json_peer,
11000 "peerState",
11001 "Passive");
11002 else if (CHECK_FLAG(peer->sflags,
11003 PEER_STATUS_NSF_WAIT))
11004 json_object_string_add(json_peer,
11005 "peerState",
11006 "NSF passive");
11007 else if (CHECK_FLAG(
11008 peer->bgp->flags,
11009 BGP_FLAG_EBGP_REQUIRES_POLICY)
11010 && (!bgp_inbound_policy_exists(peer,
11011 filter)
11012 || !bgp_outbound_policy_exists(
11013 peer, filter)))
11014 json_object_string_add(json_peer,
11015 "peerState",
11016 "Policy");
11017 else
11018 json_object_string_add(
11019 json_peer, "peerState", "OK");
11020
11021 json_object_int_add(json_peer, "connectionsEstablished",
11022 peer->established);
11023 json_object_int_add(json_peer, "connectionsDropped",
11024 peer->dropped);
11025 if (peer->desc)
11026 json_object_string_add(
11027 json_peer, "desc", peer->desc);
11028 }
11029 /* Avoid creating empty peer dicts in JSON */
11030 if (json_peer == NULL)
11031 continue;
11032
11033 if (peer->conf_if)
11034 json_object_string_add(json_peer, "idType",
11035 "interface");
11036 else if (peer->su.sa.sa_family == AF_INET)
11037 json_object_string_add(json_peer, "idType",
11038 "ipv4");
11039 else if (peer->su.sa.sa_family == AF_INET6)
11040 json_object_string_add(json_peer, "idType",
11041 "ipv6");
11042 json_object_object_add(json_peers, peer->host,
11043 json_peer);
11044 } else {
11045 if (show_failed &&
11046 bgp_has_peer_failed(peer, afi, safi)) {
11047 bgp_show_failed_summary(vty, bgp, peer, NULL,
11048 max_neighbor_width,
11049 use_json);
11050 } else if (!show_failed) {
11051 if (show_established
11052 && bgp_has_peer_failed(peer, afi, safi))
11053 continue;
11054
11055 memset(dn_flag, '\0', sizeof(dn_flag));
11056 if (peer_dynamic_neighbor(peer)) {
11057 dn_flag[0] = '*';
11058 }
11059
11060 if (peer->hostname
11061 && CHECK_FLAG(bgp->flags,
11062 BGP_FLAG_SHOW_HOSTNAME))
11063 len = vty_out(vty, "%s%s(%s)", dn_flag,
11064 peer->hostname,
11065 peer->host);
11066 else
11067 len = vty_out(vty, "%s%s", dn_flag, peer->host);
11068
11069 /* pad the neighbor column with spaces */
11070 if (len < max_neighbor_width)
11071 vty_out(vty, "%*s", max_neighbor_width - len,
11072 " ");
11073
11074 atomic_size_t outq_count, inq_count;
11075 outq_count = atomic_load_explicit(
11076 &peer->obuf->count,
11077 memory_order_relaxed);
11078 inq_count = atomic_load_explicit(
11079 &peer->ibuf->count,
11080 memory_order_relaxed);
11081
11082 vty_out(vty,
11083 "4 %10u %9u %9u %8" PRIu64" %4zu %4zu %8s",
11084 peer->as, PEER_TOTAL_RX(peer),
11085 PEER_TOTAL_TX(peer),
11086 peer->version[afi][safi], inq_count,
11087 outq_count,
11088 peer_uptime(peer->uptime, timebuf,
11089 BGP_UPTIME_LEN, 0, NULL));
11090
11091 if (peer->status == Established) {
11092 if (peer->afc_recv[afi][safi]) {
11093 if (CHECK_FLAG(
11094 bgp->flags,
11095 BGP_FLAG_EBGP_REQUIRES_POLICY)
11096 && !bgp_inbound_policy_exists(
11097 peer, filter))
11098 vty_out(vty, " %12s",
11099 "(Policy)");
11100 else
11101 vty_out(vty,
11102 " %12u",
11103 peer->pcount
11104 [afi]
11105 [pfx_rcd_safi]);
11106 } else {
11107 vty_out(vty, " NoNeg");
11108 }
11109
11110 if (paf && PAF_SUBGRP(paf)) {
11111 if (CHECK_FLAG(
11112 bgp->flags,
11113 BGP_FLAG_EBGP_REQUIRES_POLICY)
11114 && !bgp_outbound_policy_exists(
11115 peer, filter))
11116 vty_out(vty, " %8s",
11117 "(Policy)");
11118 else
11119 vty_out(vty,
11120 " %8u",
11121 (PAF_SUBGRP(
11122 paf))
11123 ->scount);
11124 }
11125 } else {
11126 if (CHECK_FLAG(peer->flags,
11127 PEER_FLAG_SHUTDOWN)
11128 || CHECK_FLAG(peer->bgp->flags,
11129 BGP_FLAG_SHUTDOWN))
11130 vty_out(vty, " Idle (Admin)");
11131 else if (CHECK_FLAG(
11132 peer->sflags,
11133 PEER_STATUS_PREFIX_OVERFLOW))
11134 vty_out(vty, " Idle (PfxCt)");
11135 else
11136 vty_out(vty, " %12s",
11137 lookup_msg(bgp_status_msg,
11138 peer->status, NULL));
11139
11140 vty_out(vty, " %8u", 0);
11141 }
11142 if (peer->desc)
11143 vty_out(vty, " %s", peer->desc);
11144 else
11145 vty_out(vty, " N/A");
11146 vty_out(vty, "\n");
11147 }
11148
11149 }
11150 }
11151
11152 if (use_json) {
11153 json_object_object_add(json, "peers", json_peers);
11154 json_object_int_add(json, "failedPeers", failed_count);
11155 json_object_int_add(json, "totalPeers", count);
11156 json_object_int_add(json, "dynamicPeers", dn_count);
11157
11158 if (!show_failed)
11159 bgp_show_bestpath_json(bgp, json);
11160
11161 vty_out(vty, "%s\n", json_object_to_json_string_ext(
11162 json, JSON_C_TO_STRING_PRETTY));
11163 json_object_free(json);
11164 } else {
11165 if (count)
11166 vty_out(vty, "\nTotal number of neighbors %d\n", count);
11167 else {
11168 vty_out(vty, "No %s neighbor is configured\n",
11169 get_afi_safi_str(afi, safi, false));
11170 }
11171
11172 if (dn_count) {
11173 vty_out(vty, "* - dynamic neighbor\n");
11174 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
11175 dn_count, bgp->dynamic_neighbors_limit);
11176 }
11177 }
11178
11179 return CMD_SUCCESS;
11180 }
11181
11182 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
11183 int safi, bool show_failed,
11184 bool show_established, bool use_json)
11185 {
11186 int is_first = 1;
11187 int afi_wildcard = (afi == AFI_MAX);
11188 int safi_wildcard = (safi == SAFI_MAX);
11189 int is_wildcard = (afi_wildcard || safi_wildcard);
11190 bool nbr_output = false;
11191
11192 if (use_json && is_wildcard)
11193 vty_out(vty, "{\n");
11194 if (afi_wildcard)
11195 afi = 1; /* AFI_IP */
11196 while (afi < AFI_MAX) {
11197 if (safi_wildcard)
11198 safi = 1; /* SAFI_UNICAST */
11199 while (safi < SAFI_MAX) {
11200 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
11201 nbr_output = true;
11202
11203 if (is_wildcard) {
11204 /*
11205 * So limit output to those afi/safi
11206 * pairs that
11207 * actualy have something interesting in
11208 * them
11209 */
11210 if (use_json) {
11211 if (!is_first)
11212 vty_out(vty, ",\n");
11213 else
11214 is_first = 0;
11215
11216 vty_out(vty, "\"%s\":",
11217 get_afi_safi_str(afi,
11218 safi,
11219 true));
11220 } else {
11221 vty_out(vty, "\n%s Summary:\n",
11222 get_afi_safi_str(afi,
11223 safi,
11224 false));
11225 }
11226 }
11227 bgp_show_summary(vty, bgp, afi, safi,
11228 show_failed, show_established,
11229 use_json);
11230 }
11231 safi++;
11232 if (!safi_wildcard)
11233 safi = SAFI_MAX;
11234 }
11235 afi++;
11236 if (!afi_wildcard)
11237 afi = AFI_MAX;
11238 }
11239
11240 if (use_json && is_wildcard)
11241 vty_out(vty, "}\n");
11242 else if (!nbr_output) {
11243 if (use_json)
11244 vty_out(vty, "{}\n");
11245 else
11246 vty_out(vty, "%% No BGP neighbors found\n");
11247 }
11248 }
11249
11250 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
11251 safi_t safi, bool show_failed,
11252 bool show_established,
11253 bool use_json)
11254 {
11255 struct listnode *node, *nnode;
11256 struct bgp *bgp;
11257 int is_first = 1;
11258 bool nbr_output = false;
11259
11260 if (use_json)
11261 vty_out(vty, "{\n");
11262
11263 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11264 nbr_output = true;
11265 if (use_json) {
11266 if (!is_first)
11267 vty_out(vty, ",\n");
11268 else
11269 is_first = 0;
11270
11271 vty_out(vty, "\"%s\":",
11272 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11273 ? VRF_DEFAULT_NAME
11274 : bgp->name);
11275 } else {
11276 vty_out(vty, "\nInstance %s:\n",
11277 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11278 ? VRF_DEFAULT_NAME
11279 : bgp->name);
11280 }
11281 bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_failed,
11282 show_established, use_json);
11283 }
11284
11285 if (use_json)
11286 vty_out(vty, "}\n");
11287 else if (!nbr_output)
11288 vty_out(vty, "%% BGP instance not found\n");
11289 }
11290
11291 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
11292 safi_t safi, bool show_failed, bool show_established,
11293 bool use_json)
11294 {
11295 struct bgp *bgp;
11296
11297 if (name) {
11298 if (strmatch(name, "all")) {
11299 bgp_show_all_instances_summary_vty(
11300 vty, afi, safi, show_failed, show_established,
11301 use_json);
11302 return CMD_SUCCESS;
11303 } else {
11304 bgp = bgp_lookup_by_name(name);
11305
11306 if (!bgp) {
11307 if (use_json)
11308 vty_out(vty, "{}\n");
11309 else
11310 vty_out(vty,
11311 "%% BGP instance not found\n");
11312 return CMD_WARNING;
11313 }
11314
11315 bgp_show_summary_afi_safi(vty, bgp, afi, safi,
11316 show_failed, show_established,
11317 use_json);
11318 return CMD_SUCCESS;
11319 }
11320 }
11321
11322 bgp = bgp_get_default();
11323
11324 if (bgp)
11325 bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_failed,
11326 show_established, use_json);
11327 else {
11328 if (use_json)
11329 vty_out(vty, "{}\n");
11330 else
11331 vty_out(vty, "%% BGP instance not found\n");
11332 return CMD_WARNING;
11333 }
11334
11335 return CMD_SUCCESS;
11336 }
11337
11338 /* `show [ip] bgp summary' commands. */
11339 DEFPY (show_ip_bgp_summary,
11340 show_ip_bgp_summary_cmd,
11341 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] [all$all] summary [established|failed] [json$uj]",
11342 SHOW_STR
11343 IP_STR
11344 BGP_STR
11345 BGP_INSTANCE_HELP_STR
11346 BGP_AFI_HELP_STR
11347 BGP_SAFI_WITH_LABEL_HELP_STR
11348 "Display the entries for all address families\n"
11349 "Summary of BGP neighbor status\n"
11350 "Show only sessions in Established state\n"
11351 "Show only sessions not in Established state\n"
11352 JSON_STR)
11353 {
11354 char *vrf = NULL;
11355 afi_t afi = AFI_MAX;
11356 safi_t safi = SAFI_MAX;
11357 bool show_failed = false;
11358 bool show_established = false;
11359
11360 int idx = 0;
11361
11362 /* show [ip] bgp */
11363 if (!all && argv_find(argv, argc, "ip", &idx))
11364 afi = AFI_IP;
11365 /* [<vrf> VIEWVRFNAME] */
11366 if (argv_find(argv, argc, "vrf", &idx)) {
11367 vrf = argv[idx + 1]->arg;
11368 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11369 vrf = NULL;
11370 } else if (argv_find(argv, argc, "view", &idx))
11371 /* [<view> VIEWVRFNAME] */
11372 vrf = argv[idx + 1]->arg;
11373 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11374 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11375 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11376 }
11377
11378 if (argv_find(argv, argc, "failed", &idx))
11379 show_failed = true;
11380 if (argv_find(argv, argc, "established", &idx))
11381 show_established = true;
11382
11383 return bgp_show_summary_vty(vty, vrf, afi, safi, show_failed,
11384 show_established, uj);
11385 }
11386
11387 const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
11388 {
11389 if (for_json)
11390 return get_afi_safi_json_str(afi, safi);
11391 else
11392 return get_afi_safi_vty_str(afi, safi);
11393 }
11394
11395
11396 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
11397 afi_t afi, safi_t safi,
11398 uint16_t adv_smcap, uint16_t adv_rmcap,
11399 uint16_t rcv_smcap, uint16_t rcv_rmcap,
11400 bool use_json, json_object *json_pref)
11401 {
11402 /* Send-Mode */
11403 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11404 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
11405 if (use_json) {
11406 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11407 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11408 json_object_string_add(json_pref, "sendMode",
11409 "advertisedAndReceived");
11410 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11411 json_object_string_add(json_pref, "sendMode",
11412 "advertised");
11413 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11414 json_object_string_add(json_pref, "sendMode",
11415 "received");
11416 } else {
11417 vty_out(vty, " Send-mode: ");
11418 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11419 vty_out(vty, "advertised");
11420 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11421 vty_out(vty, "%sreceived",
11422 CHECK_FLAG(p->af_cap[afi][safi],
11423 adv_smcap)
11424 ? ", "
11425 : "");
11426 vty_out(vty, "\n");
11427 }
11428 }
11429
11430 /* Receive-Mode */
11431 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11432 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
11433 if (use_json) {
11434 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11435 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11436 json_object_string_add(json_pref, "recvMode",
11437 "advertisedAndReceived");
11438 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11439 json_object_string_add(json_pref, "recvMode",
11440 "advertised");
11441 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11442 json_object_string_add(json_pref, "recvMode",
11443 "received");
11444 } else {
11445 vty_out(vty, " Receive-mode: ");
11446 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11447 vty_out(vty, "advertised");
11448 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11449 vty_out(vty, "%sreceived",
11450 CHECK_FLAG(p->af_cap[afi][safi],
11451 adv_rmcap)
11452 ? ", "
11453 : "");
11454 vty_out(vty, "\n");
11455 }
11456 }
11457 }
11458
11459 static void bgp_show_neighnor_graceful_restart_rbit(struct vty *vty,
11460 struct peer *p,
11461 bool use_json,
11462 json_object *json)
11463 {
11464 bool rbit_status = false;
11465
11466 if (!use_json)
11467 vty_out(vty, "\n R bit: ");
11468
11469 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
11470 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
11471 && (p->status == Established)) {
11472
11473 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_BIT_RCV))
11474 rbit_status = true;
11475 else
11476 rbit_status = false;
11477 }
11478
11479 if (rbit_status) {
11480 if (use_json)
11481 json_object_boolean_true_add(json, "rBit");
11482 else
11483 vty_out(vty, "True\n");
11484 } else {
11485 if (use_json)
11486 json_object_boolean_false_add(json, "rBit");
11487 else
11488 vty_out(vty, "False\n");
11489 }
11490 }
11491
11492 static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
11493 struct peer *peer,
11494 bool use_json,
11495 json_object *json)
11496 {
11497 const char *mode = "NotApplicable";
11498
11499 if (!use_json)
11500 vty_out(vty, "\n Remote GR Mode: ");
11501
11502 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
11503 && (peer->status == Established)) {
11504
11505 if ((peer->nsf_af_count == 0)
11506 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11507
11508 mode = "Disable";
11509
11510 } else if (peer->nsf_af_count == 0
11511 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11512
11513 mode = "Helper";
11514
11515 } else if (peer->nsf_af_count != 0
11516 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11517
11518 mode = "Restart";
11519 }
11520 }
11521
11522 if (use_json) {
11523 json_object_string_add(json, "remoteGrMode", mode);
11524 } else
11525 vty_out(vty, mode, "\n");
11526 }
11527
11528 static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
11529 struct peer *p,
11530 bool use_json,
11531 json_object *json)
11532 {
11533 const char *mode = "Invalid";
11534
11535 if (!use_json)
11536 vty_out(vty, " Local GR Mode: ");
11537
11538 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
11539 mode = "Helper";
11540 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
11541 mode = "Restart";
11542 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
11543 mode = "Disable";
11544 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
11545 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
11546 mode = "Helper*";
11547 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
11548 mode = "Restart*";
11549 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
11550 mode = "Disable*";
11551 else
11552 mode = "Invalid*";
11553 }
11554
11555 if (use_json) {
11556 json_object_string_add(json, "localGrMode", mode);
11557 } else {
11558 vty_out(vty, mode, "\n");
11559 }
11560 }
11561
11562 static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
11563 struct vty *vty, struct peer *peer, bool use_json, json_object *json)
11564 {
11565 afi_t afi;
11566 safi_t safi;
11567 json_object *json_afi_safi = NULL;
11568 json_object *json_timer = NULL;
11569 json_object *json_endofrib_status = NULL;
11570 bool eor_flag = false;
11571
11572 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
11573 for (safi = SAFI_UNICAST; safi <= SAFI_MPLS_VPN; safi++) {
11574 if (!peer->afc[afi][safi])
11575 continue;
11576
11577 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
11578 || !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
11579 continue;
11580
11581 if (use_json) {
11582 json_afi_safi = json_object_new_object();
11583 json_endofrib_status = json_object_new_object();
11584 json_timer = json_object_new_object();
11585 }
11586
11587 if (peer->eor_stime[afi][safi]
11588 >= peer->pkt_stime[afi][safi])
11589 eor_flag = true;
11590 else
11591 eor_flag = false;
11592
11593 if (!use_json) {
11594 vty_out(vty, " %s:\n",
11595 get_afi_safi_str(afi, safi, false));
11596
11597 vty_out(vty, " F bit: ");
11598 }
11599
11600 if (peer->nsf[afi][safi]
11601 && CHECK_FLAG(peer->af_cap[afi][safi],
11602 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
11603
11604 if (use_json) {
11605 json_object_boolean_true_add(
11606 json_afi_safi, "fBit");
11607 } else
11608 vty_out(vty, "True\n");
11609 } else {
11610 if (use_json)
11611 json_object_boolean_false_add(
11612 json_afi_safi, "fBit");
11613 else
11614 vty_out(vty, "False\n");
11615 }
11616
11617 if (!use_json)
11618 vty_out(vty, " End-of-RIB sent: ");
11619
11620 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11621 PEER_STATUS_EOR_SEND)) {
11622 if (use_json) {
11623 json_object_boolean_true_add(
11624 json_endofrib_status,
11625 "endOfRibSend");
11626
11627 PRINT_EOR_JSON(eor_flag);
11628 } else {
11629 vty_out(vty, "Yes\n");
11630 vty_out(vty,
11631 " End-of-RIB sent after update: ");
11632
11633 PRINT_EOR(eor_flag);
11634 }
11635 } else {
11636 if (use_json) {
11637 json_object_boolean_false_add(
11638 json_endofrib_status,
11639 "endOfRibSend");
11640 json_object_boolean_false_add(
11641 json_endofrib_status,
11642 "endOfRibSentAfterUpdate");
11643 } else {
11644 vty_out(vty, "No\n");
11645 vty_out(vty,
11646 " End-of-RIB sent after update: ");
11647 vty_out(vty, "No\n");
11648 }
11649 }
11650
11651 if (!use_json)
11652 vty_out(vty, " End-of-RIB received: ");
11653
11654 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11655 PEER_STATUS_EOR_RECEIVED)) {
11656 if (use_json)
11657 json_object_boolean_true_add(
11658 json_endofrib_status,
11659 "endOfRibRecv");
11660 else
11661 vty_out(vty, "Yes\n");
11662 } else {
11663 if (use_json)
11664 json_object_boolean_false_add(
11665 json_endofrib_status,
11666 "endOfRibRecv");
11667 else
11668 vty_out(vty, "No\n");
11669 }
11670
11671 if (use_json) {
11672 json_object_int_add(json_timer,
11673 "stalePathTimer",
11674 peer->bgp->stalepath_time);
11675
11676 if (peer->t_gr_stale != NULL) {
11677 json_object_int_add(
11678 json_timer,
11679 "stalePathTimerRemaining",
11680 thread_timer_remain_second(
11681 peer->t_gr_stale));
11682 }
11683
11684 /* Display Configured Selection
11685 * Deferral only when when
11686 * Gr mode is enabled.
11687 */
11688 if (CHECK_FLAG(peer->flags,
11689 PEER_FLAG_GRACEFUL_RESTART)) {
11690 json_object_int_add(
11691 json_timer,
11692 "selectionDeferralTimer",
11693 peer->bgp->stalepath_time);
11694 }
11695
11696 if (peer->bgp->gr_info[afi][safi]
11697 .t_select_deferral
11698 != NULL) {
11699
11700 json_object_int_add(
11701 json_timer,
11702 "selectionDeferralTimerRemaining",
11703 thread_timer_remain_second(
11704 peer->bgp
11705 ->gr_info[afi]
11706 [safi]
11707 .t_select_deferral));
11708 }
11709 } else {
11710 vty_out(vty, " Timers:\n");
11711 vty_out(vty,
11712 " Configured Stale Path Time(sec): %u\n",
11713 peer->bgp->stalepath_time);
11714
11715 if (peer->t_gr_stale != NULL)
11716 vty_out(vty,
11717 " Stale Path Remaining(sec): %ld\n",
11718 thread_timer_remain_second(
11719 peer->t_gr_stale));
11720 /* Display Configured Selection
11721 * Deferral only when when
11722 * Gr mode is enabled.
11723 */
11724 if (CHECK_FLAG(peer->flags,
11725 PEER_FLAG_GRACEFUL_RESTART))
11726 vty_out(vty,
11727 " Configured Selection Deferral Time(sec): %u\n",
11728 peer->bgp->select_defer_time);
11729
11730 if (peer->bgp->gr_info[afi][safi]
11731 .t_select_deferral
11732 != NULL)
11733 vty_out(vty,
11734 " Selection Deferral Time Remaining(sec): %ld\n",
11735 thread_timer_remain_second(
11736 peer->bgp
11737 ->gr_info[afi]
11738 [safi]
11739 .t_select_deferral));
11740 }
11741 if (use_json) {
11742 json_object_object_add(json_afi_safi,
11743 "endOfRibStatus",
11744 json_endofrib_status);
11745 json_object_object_add(json_afi_safi, "timers",
11746 json_timer);
11747 json_object_object_add(
11748 json, get_afi_safi_str(afi, safi, true),
11749 json_afi_safi);
11750 }
11751 }
11752 }
11753 }
11754
11755 static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
11756 struct peer *p,
11757 bool use_json,
11758 json_object *json)
11759 {
11760 if (use_json) {
11761 json_object *json_timer = NULL;
11762
11763 json_timer = json_object_new_object();
11764
11765 json_object_int_add(json_timer, "configuredRestartTimer",
11766 p->bgp->restart_time);
11767
11768 json_object_int_add(json_timer, "receivedRestartTimer",
11769 p->v_gr_restart);
11770
11771 if (p->t_gr_restart != NULL)
11772 json_object_int_add(
11773 json_timer, "restartTimerRemaining",
11774 thread_timer_remain_second(p->t_gr_restart));
11775
11776 json_object_object_add(json, "timers", json_timer);
11777 } else {
11778
11779 vty_out(vty, " Timers:\n");
11780 vty_out(vty, " Configured Restart Time(sec): %u\n",
11781 p->bgp->restart_time);
11782
11783 vty_out(vty, " Received Restart Time(sec): %u\n",
11784 p->v_gr_restart);
11785 if (p->t_gr_restart != NULL)
11786 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
11787 thread_timer_remain_second(p->t_gr_restart));
11788 if (p->t_gr_restart != NULL) {
11789 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
11790 thread_timer_remain_second(p->t_gr_restart));
11791 }
11792 }
11793 }
11794
11795 static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
11796 bool use_json, json_object *json)
11797 {
11798 char buf[SU_ADDRSTRLEN] = {0};
11799 char dn_flag[2] = {0};
11800 /* '*' + v6 address of neighbor */
11801 char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
11802
11803 if (!p->conf_if && peer_dynamic_neighbor(p))
11804 dn_flag[0] = '*';
11805
11806 if (p->conf_if) {
11807 if (use_json)
11808 json_object_string_add(
11809 json, "neighborAddr",
11810 BGP_PEER_SU_UNSPEC(p)
11811 ? "none"
11812 : sockunion2str(&p->su, buf,
11813 SU_ADDRSTRLEN));
11814 else
11815 vty_out(vty, "BGP neighbor on %s: %s\n", p->conf_if,
11816 BGP_PEER_SU_UNSPEC(p)
11817 ? "none"
11818 : sockunion2str(&p->su, buf,
11819 SU_ADDRSTRLEN));
11820 } else {
11821 snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
11822 p->host);
11823
11824 if (use_json)
11825 json_object_string_add(json, "neighborAddr",
11826 neighborAddr);
11827 else
11828 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
11829 }
11830
11831 /* more gr info in new format */
11832 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json);
11833 }
11834
11835 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
11836 safi_t safi, bool use_json,
11837 json_object *json_neigh)
11838 {
11839 struct bgp_filter *filter;
11840 struct peer_af *paf;
11841 char orf_pfx_name[BUFSIZ];
11842 int orf_pfx_count;
11843 json_object *json_af = NULL;
11844 json_object *json_prefA = NULL;
11845 json_object *json_prefB = NULL;
11846 json_object *json_addr = NULL;
11847 json_object *json_advmap = NULL;
11848
11849 if (use_json) {
11850 json_addr = json_object_new_object();
11851 json_af = json_object_new_object();
11852 filter = &p->filter[afi][safi];
11853
11854 if (peer_group_active(p))
11855 json_object_string_add(json_addr, "peerGroupMember",
11856 p->group->name);
11857
11858 paf = peer_af_find(p, afi, safi);
11859 if (paf && PAF_SUBGRP(paf)) {
11860 json_object_int_add(json_addr, "updateGroupId",
11861 PAF_UPDGRP(paf)->id);
11862 json_object_int_add(json_addr, "subGroupId",
11863 PAF_SUBGRP(paf)->id);
11864 json_object_int_add(json_addr, "packetQueueLength",
11865 bpacket_queue_virtual_length(paf));
11866 }
11867
11868 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11869 || CHECK_FLAG(p->af_cap[afi][safi],
11870 PEER_CAP_ORF_PREFIX_SM_RCV)
11871 || CHECK_FLAG(p->af_cap[afi][safi],
11872 PEER_CAP_ORF_PREFIX_RM_ADV)
11873 || CHECK_FLAG(p->af_cap[afi][safi],
11874 PEER_CAP_ORF_PREFIX_RM_RCV)) {
11875 json_object_int_add(json_af, "orfType",
11876 ORF_TYPE_PREFIX);
11877 json_prefA = json_object_new_object();
11878 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
11879 PEER_CAP_ORF_PREFIX_SM_ADV,
11880 PEER_CAP_ORF_PREFIX_RM_ADV,
11881 PEER_CAP_ORF_PREFIX_SM_RCV,
11882 PEER_CAP_ORF_PREFIX_RM_RCV,
11883 use_json, json_prefA);
11884 json_object_object_add(json_af, "orfPrefixList",
11885 json_prefA);
11886 }
11887
11888 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11889 || CHECK_FLAG(p->af_cap[afi][safi],
11890 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11891 || CHECK_FLAG(p->af_cap[afi][safi],
11892 PEER_CAP_ORF_PREFIX_RM_ADV)
11893 || CHECK_FLAG(p->af_cap[afi][safi],
11894 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
11895 json_object_int_add(json_af, "orfOldType",
11896 ORF_TYPE_PREFIX_OLD);
11897 json_prefB = json_object_new_object();
11898 bgp_show_peer_afi_orf_cap(
11899 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
11900 PEER_CAP_ORF_PREFIX_RM_ADV,
11901 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
11902 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
11903 json_prefB);
11904 json_object_object_add(json_af, "orfOldPrefixList",
11905 json_prefB);
11906 }
11907
11908 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11909 || CHECK_FLAG(p->af_cap[afi][safi],
11910 PEER_CAP_ORF_PREFIX_SM_RCV)
11911 || CHECK_FLAG(p->af_cap[afi][safi],
11912 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11913 || CHECK_FLAG(p->af_cap[afi][safi],
11914 PEER_CAP_ORF_PREFIX_RM_ADV)
11915 || CHECK_FLAG(p->af_cap[afi][safi],
11916 PEER_CAP_ORF_PREFIX_RM_RCV)
11917 || CHECK_FLAG(p->af_cap[afi][safi],
11918 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
11919 json_object_object_add(json_addr, "afDependentCap",
11920 json_af);
11921 else
11922 json_object_free(json_af);
11923
11924 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
11925 p->host, afi, safi);
11926 orf_pfx_count = prefix_bgp_show_prefix_list(
11927 NULL, afi, orf_pfx_name, use_json);
11928
11929 if (CHECK_FLAG(p->af_sflags[afi][safi],
11930 PEER_STATUS_ORF_PREFIX_SEND)
11931 || orf_pfx_count) {
11932 if (CHECK_FLAG(p->af_sflags[afi][safi],
11933 PEER_STATUS_ORF_PREFIX_SEND))
11934 json_object_boolean_true_add(json_neigh,
11935 "orfSent");
11936 if (orf_pfx_count)
11937 json_object_int_add(json_addr, "orfRecvCounter",
11938 orf_pfx_count);
11939 }
11940 if (CHECK_FLAG(p->af_sflags[afi][safi],
11941 PEER_STATUS_ORF_WAIT_REFRESH))
11942 json_object_string_add(
11943 json_addr, "orfFirstUpdate",
11944 "deferredUntilORFOrRouteRefreshRecvd");
11945
11946 if (CHECK_FLAG(p->af_flags[afi][safi],
11947 PEER_FLAG_REFLECTOR_CLIENT))
11948 json_object_boolean_true_add(json_addr,
11949 "routeReflectorClient");
11950 if (CHECK_FLAG(p->af_flags[afi][safi],
11951 PEER_FLAG_RSERVER_CLIENT))
11952 json_object_boolean_true_add(json_addr,
11953 "routeServerClient");
11954 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
11955 json_object_boolean_true_add(json_addr,
11956 "inboundSoftConfigPermit");
11957
11958 if (CHECK_FLAG(p->af_flags[afi][safi],
11959 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
11960 json_object_boolean_true_add(
11961 json_addr,
11962 "privateAsNumsAllReplacedInUpdatesToNbr");
11963 else if (CHECK_FLAG(p->af_flags[afi][safi],
11964 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
11965 json_object_boolean_true_add(
11966 json_addr,
11967 "privateAsNumsReplacedInUpdatesToNbr");
11968 else if (CHECK_FLAG(p->af_flags[afi][safi],
11969 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
11970 json_object_boolean_true_add(
11971 json_addr,
11972 "privateAsNumsAllRemovedInUpdatesToNbr");
11973 else if (CHECK_FLAG(p->af_flags[afi][safi],
11974 PEER_FLAG_REMOVE_PRIVATE_AS))
11975 json_object_boolean_true_add(
11976 json_addr,
11977 "privateAsNumsRemovedInUpdatesToNbr");
11978
11979 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
11980 json_object_boolean_true_add(
11981 json_addr,
11982 bgp_addpath_names(p->addpath_type[afi][safi])
11983 ->type_json_name);
11984
11985 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
11986 json_object_string_add(json_addr,
11987 "overrideASNsInOutboundUpdates",
11988 "ifAspathEqualRemoteAs");
11989
11990 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
11991 || CHECK_FLAG(p->af_flags[afi][safi],
11992 PEER_FLAG_FORCE_NEXTHOP_SELF))
11993 json_object_boolean_true_add(json_addr,
11994 "routerAlwaysNextHop");
11995 if (CHECK_FLAG(p->af_flags[afi][safi],
11996 PEER_FLAG_AS_PATH_UNCHANGED))
11997 json_object_boolean_true_add(
11998 json_addr, "unchangedAsPathPropogatedToNbr");
11999 if (CHECK_FLAG(p->af_flags[afi][safi],
12000 PEER_FLAG_NEXTHOP_UNCHANGED))
12001 json_object_boolean_true_add(
12002 json_addr, "unchangedNextHopPropogatedToNbr");
12003 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12004 json_object_boolean_true_add(
12005 json_addr, "unchangedMedPropogatedToNbr");
12006 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12007 || CHECK_FLAG(p->af_flags[afi][safi],
12008 PEER_FLAG_SEND_EXT_COMMUNITY)) {
12009 if (CHECK_FLAG(p->af_flags[afi][safi],
12010 PEER_FLAG_SEND_COMMUNITY)
12011 && CHECK_FLAG(p->af_flags[afi][safi],
12012 PEER_FLAG_SEND_EXT_COMMUNITY))
12013 json_object_string_add(json_addr,
12014 "commAttriSentToNbr",
12015 "extendedAndStandard");
12016 else if (CHECK_FLAG(p->af_flags[afi][safi],
12017 PEER_FLAG_SEND_EXT_COMMUNITY))
12018 json_object_string_add(json_addr,
12019 "commAttriSentToNbr",
12020 "extended");
12021 else
12022 json_object_string_add(json_addr,
12023 "commAttriSentToNbr",
12024 "standard");
12025 }
12026 if (CHECK_FLAG(p->af_flags[afi][safi],
12027 PEER_FLAG_DEFAULT_ORIGINATE)) {
12028 if (p->default_rmap[afi][safi].name)
12029 json_object_string_add(
12030 json_addr, "defaultRouteMap",
12031 p->default_rmap[afi][safi].name);
12032
12033 if (paf && PAF_SUBGRP(paf)
12034 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12035 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12036 json_object_boolean_true_add(json_addr,
12037 "defaultSent");
12038 else
12039 json_object_boolean_true_add(json_addr,
12040 "defaultNotSent");
12041 }
12042
12043 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
12044 if (is_evpn_enabled())
12045 json_object_boolean_true_add(
12046 json_addr, "advertiseAllVnis");
12047 }
12048
12049 if (filter->plist[FILTER_IN].name
12050 || filter->dlist[FILTER_IN].name
12051 || filter->aslist[FILTER_IN].name
12052 || filter->map[RMAP_IN].name)
12053 json_object_boolean_true_add(json_addr,
12054 "inboundPathPolicyConfig");
12055 if (filter->plist[FILTER_OUT].name
12056 || filter->dlist[FILTER_OUT].name
12057 || filter->aslist[FILTER_OUT].name
12058 || filter->map[RMAP_OUT].name || filter->usmap.name)
12059 json_object_boolean_true_add(
12060 json_addr, "outboundPathPolicyConfig");
12061
12062 /* prefix-list */
12063 if (filter->plist[FILTER_IN].name)
12064 json_object_string_add(json_addr,
12065 "incomingUpdatePrefixFilterList",
12066 filter->plist[FILTER_IN].name);
12067 if (filter->plist[FILTER_OUT].name)
12068 json_object_string_add(json_addr,
12069 "outgoingUpdatePrefixFilterList",
12070 filter->plist[FILTER_OUT].name);
12071
12072 /* distribute-list */
12073 if (filter->dlist[FILTER_IN].name)
12074 json_object_string_add(
12075 json_addr, "incomingUpdateNetworkFilterList",
12076 filter->dlist[FILTER_IN].name);
12077 if (filter->dlist[FILTER_OUT].name)
12078 json_object_string_add(
12079 json_addr, "outgoingUpdateNetworkFilterList",
12080 filter->dlist[FILTER_OUT].name);
12081
12082 /* filter-list. */
12083 if (filter->aslist[FILTER_IN].name)
12084 json_object_string_add(json_addr,
12085 "incomingUpdateAsPathFilterList",
12086 filter->aslist[FILTER_IN].name);
12087 if (filter->aslist[FILTER_OUT].name)
12088 json_object_string_add(json_addr,
12089 "outgoingUpdateAsPathFilterList",
12090 filter->aslist[FILTER_OUT].name);
12091
12092 /* route-map. */
12093 if (filter->map[RMAP_IN].name)
12094 json_object_string_add(
12095 json_addr, "routeMapForIncomingAdvertisements",
12096 filter->map[RMAP_IN].name);
12097 if (filter->map[RMAP_OUT].name)
12098 json_object_string_add(
12099 json_addr, "routeMapForOutgoingAdvertisements",
12100 filter->map[RMAP_OUT].name);
12101
12102 /* ebgp-requires-policy (inbound) */
12103 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12104 && !bgp_inbound_policy_exists(p, filter))
12105 json_object_string_add(
12106 json_addr, "inboundEbgpRequiresPolicy",
12107 "Inbound updates discarded due to missing policy");
12108
12109 /* ebgp-requires-policy (outbound) */
12110 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12111 && (!bgp_outbound_policy_exists(p, filter)))
12112 json_object_string_add(
12113 json_addr, "outboundEbgpRequiresPolicy",
12114 "Outbound updates discarded due to missing policy");
12115
12116 /* unsuppress-map */
12117 if (filter->usmap.name)
12118 json_object_string_add(json_addr,
12119 "selectiveUnsuppressRouteMap",
12120 filter->usmap.name);
12121
12122 /* advertise-map */
12123 if (filter->advmap.aname) {
12124 json_advmap = json_object_new_object();
12125 json_object_string_add(json_advmap, "condition",
12126 filter->advmap.condition
12127 ? "EXIST"
12128 : "NON_EXIST");
12129 json_object_string_add(json_advmap, "conditionMap",
12130 filter->advmap.cname);
12131 json_object_string_add(json_advmap, "advertiseMap",
12132 filter->advmap.aname);
12133 json_object_string_add(json_advmap, "advertiseStatus",
12134 filter->advmap.update_type
12135 == ADVERTISE
12136 ? "Advertise"
12137 : "Withdraw");
12138 json_object_object_add(json_addr, "advertiseMap",
12139 json_advmap);
12140 }
12141
12142 /* Receive prefix count */
12143 json_object_int_add(json_addr, "acceptedPrefixCounter",
12144 p->pcount[afi][safi]);
12145 if (paf && PAF_SUBGRP(paf))
12146 json_object_int_add(json_addr, "sentPrefixCounter",
12147 (PAF_SUBGRP(paf))->scount);
12148
12149 /* Maximum prefix */
12150 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
12151 json_object_int_add(json_addr, "prefixOutAllowedMax",
12152 p->pmax_out[afi][safi]);
12153
12154 /* Maximum prefix */
12155 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12156 json_object_int_add(json_addr, "prefixAllowedMax",
12157 p->pmax[afi][safi]);
12158 if (CHECK_FLAG(p->af_flags[afi][safi],
12159 PEER_FLAG_MAX_PREFIX_WARNING))
12160 json_object_boolean_true_add(
12161 json_addr, "prefixAllowedMaxWarning");
12162 json_object_int_add(json_addr,
12163 "prefixAllowedWarningThresh",
12164 p->pmax_threshold[afi][safi]);
12165 if (p->pmax_restart[afi][safi])
12166 json_object_int_add(
12167 json_addr,
12168 "prefixAllowedRestartIntervalMsecs",
12169 p->pmax_restart[afi][safi] * 60000);
12170 }
12171 json_object_object_add(json_neigh,
12172 get_afi_safi_str(afi, safi, true),
12173 json_addr);
12174
12175 } else {
12176 filter = &p->filter[afi][safi];
12177
12178 vty_out(vty, " For address family: %s\n",
12179 get_afi_safi_str(afi, safi, false));
12180
12181 if (peer_group_active(p))
12182 vty_out(vty, " %s peer-group member\n",
12183 p->group->name);
12184
12185 paf = peer_af_find(p, afi, safi);
12186 if (paf && PAF_SUBGRP(paf)) {
12187 vty_out(vty, " Update group %" PRIu64", subgroup %" PRIu64 "\n",
12188 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
12189 vty_out(vty, " Packet Queue length %d\n",
12190 bpacket_queue_virtual_length(paf));
12191 } else {
12192 vty_out(vty, " Not part of any update group\n");
12193 }
12194 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12195 || CHECK_FLAG(p->af_cap[afi][safi],
12196 PEER_CAP_ORF_PREFIX_SM_RCV)
12197 || CHECK_FLAG(p->af_cap[afi][safi],
12198 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12199 || CHECK_FLAG(p->af_cap[afi][safi],
12200 PEER_CAP_ORF_PREFIX_RM_ADV)
12201 || CHECK_FLAG(p->af_cap[afi][safi],
12202 PEER_CAP_ORF_PREFIX_RM_RCV)
12203 || CHECK_FLAG(p->af_cap[afi][safi],
12204 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12205 vty_out(vty, " AF-dependant capabilities:\n");
12206
12207 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12208 || CHECK_FLAG(p->af_cap[afi][safi],
12209 PEER_CAP_ORF_PREFIX_SM_RCV)
12210 || CHECK_FLAG(p->af_cap[afi][safi],
12211 PEER_CAP_ORF_PREFIX_RM_ADV)
12212 || CHECK_FLAG(p->af_cap[afi][safi],
12213 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12214 vty_out(vty,
12215 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12216 ORF_TYPE_PREFIX);
12217 bgp_show_peer_afi_orf_cap(
12218 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12219 PEER_CAP_ORF_PREFIX_RM_ADV,
12220 PEER_CAP_ORF_PREFIX_SM_RCV,
12221 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
12222 }
12223 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12224 || CHECK_FLAG(p->af_cap[afi][safi],
12225 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12226 || CHECK_FLAG(p->af_cap[afi][safi],
12227 PEER_CAP_ORF_PREFIX_RM_ADV)
12228 || CHECK_FLAG(p->af_cap[afi][safi],
12229 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12230 vty_out(vty,
12231 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12232 ORF_TYPE_PREFIX_OLD);
12233 bgp_show_peer_afi_orf_cap(
12234 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12235 PEER_CAP_ORF_PREFIX_RM_ADV,
12236 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12237 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
12238 }
12239
12240 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12241 p->host, afi, safi);
12242 orf_pfx_count = prefix_bgp_show_prefix_list(
12243 NULL, afi, orf_pfx_name, use_json);
12244
12245 if (CHECK_FLAG(p->af_sflags[afi][safi],
12246 PEER_STATUS_ORF_PREFIX_SEND)
12247 || orf_pfx_count) {
12248 vty_out(vty, " Outbound Route Filter (ORF):");
12249 if (CHECK_FLAG(p->af_sflags[afi][safi],
12250 PEER_STATUS_ORF_PREFIX_SEND))
12251 vty_out(vty, " sent;");
12252 if (orf_pfx_count)
12253 vty_out(vty, " received (%d entries)",
12254 orf_pfx_count);
12255 vty_out(vty, "\n");
12256 }
12257 if (CHECK_FLAG(p->af_sflags[afi][safi],
12258 PEER_STATUS_ORF_WAIT_REFRESH))
12259 vty_out(vty,
12260 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
12261
12262 if (CHECK_FLAG(p->af_flags[afi][safi],
12263 PEER_FLAG_REFLECTOR_CLIENT))
12264 vty_out(vty, " Route-Reflector Client\n");
12265 if (CHECK_FLAG(p->af_flags[afi][safi],
12266 PEER_FLAG_RSERVER_CLIENT))
12267 vty_out(vty, " Route-Server Client\n");
12268 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12269 vty_out(vty,
12270 " Inbound soft reconfiguration allowed\n");
12271
12272 if (CHECK_FLAG(p->af_flags[afi][safi],
12273 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12274 vty_out(vty,
12275 " Private AS numbers (all) replaced in updates to this neighbor\n");
12276 else if (CHECK_FLAG(p->af_flags[afi][safi],
12277 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12278 vty_out(vty,
12279 " Private AS numbers replaced in updates to this neighbor\n");
12280 else if (CHECK_FLAG(p->af_flags[afi][safi],
12281 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12282 vty_out(vty,
12283 " Private AS numbers (all) removed in updates to this neighbor\n");
12284 else if (CHECK_FLAG(p->af_flags[afi][safi],
12285 PEER_FLAG_REMOVE_PRIVATE_AS))
12286 vty_out(vty,
12287 " Private AS numbers removed in updates to this neighbor\n");
12288
12289 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12290 vty_out(vty, " %s\n",
12291 bgp_addpath_names(p->addpath_type[afi][safi])
12292 ->human_description);
12293
12294 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12295 vty_out(vty,
12296 " Override ASNs in outbound updates if aspath equals remote-as\n");
12297
12298 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12299 || CHECK_FLAG(p->af_flags[afi][safi],
12300 PEER_FLAG_FORCE_NEXTHOP_SELF))
12301 vty_out(vty, " NEXT_HOP is always this router\n");
12302 if (CHECK_FLAG(p->af_flags[afi][safi],
12303 PEER_FLAG_AS_PATH_UNCHANGED))
12304 vty_out(vty,
12305 " AS_PATH is propagated unchanged to this neighbor\n");
12306 if (CHECK_FLAG(p->af_flags[afi][safi],
12307 PEER_FLAG_NEXTHOP_UNCHANGED))
12308 vty_out(vty,
12309 " NEXT_HOP is propagated unchanged to this neighbor\n");
12310 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12311 vty_out(vty,
12312 " MED is propagated unchanged to this neighbor\n");
12313 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12314 || CHECK_FLAG(p->af_flags[afi][safi],
12315 PEER_FLAG_SEND_EXT_COMMUNITY)
12316 || CHECK_FLAG(p->af_flags[afi][safi],
12317 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
12318 vty_out(vty,
12319 " Community attribute sent to this neighbor");
12320 if (CHECK_FLAG(p->af_flags[afi][safi],
12321 PEER_FLAG_SEND_COMMUNITY)
12322 && CHECK_FLAG(p->af_flags[afi][safi],
12323 PEER_FLAG_SEND_EXT_COMMUNITY)
12324 && CHECK_FLAG(p->af_flags[afi][safi],
12325 PEER_FLAG_SEND_LARGE_COMMUNITY))
12326 vty_out(vty, "(all)\n");
12327 else if (CHECK_FLAG(p->af_flags[afi][safi],
12328 PEER_FLAG_SEND_LARGE_COMMUNITY))
12329 vty_out(vty, "(large)\n");
12330 else if (CHECK_FLAG(p->af_flags[afi][safi],
12331 PEER_FLAG_SEND_EXT_COMMUNITY))
12332 vty_out(vty, "(extended)\n");
12333 else
12334 vty_out(vty, "(standard)\n");
12335 }
12336 if (CHECK_FLAG(p->af_flags[afi][safi],
12337 PEER_FLAG_DEFAULT_ORIGINATE)) {
12338 vty_out(vty, " Default information originate,");
12339
12340 if (p->default_rmap[afi][safi].name)
12341 vty_out(vty, " default route-map %s%s,",
12342 p->default_rmap[afi][safi].map ? "*"
12343 : "",
12344 p->default_rmap[afi][safi].name);
12345 if (paf && PAF_SUBGRP(paf)
12346 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12347 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12348 vty_out(vty, " default sent\n");
12349 else
12350 vty_out(vty, " default not sent\n");
12351 }
12352
12353 /* advertise-vni-all */
12354 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
12355 if (is_evpn_enabled())
12356 vty_out(vty, " advertise-all-vni\n");
12357 }
12358
12359 if (filter->plist[FILTER_IN].name
12360 || filter->dlist[FILTER_IN].name
12361 || filter->aslist[FILTER_IN].name
12362 || filter->map[RMAP_IN].name)
12363 vty_out(vty, " Inbound path policy configured\n");
12364 if (filter->plist[FILTER_OUT].name
12365 || filter->dlist[FILTER_OUT].name
12366 || filter->aslist[FILTER_OUT].name
12367 || filter->map[RMAP_OUT].name || filter->usmap.name)
12368 vty_out(vty, " Outbound path policy configured\n");
12369
12370 /* prefix-list */
12371 if (filter->plist[FILTER_IN].name)
12372 vty_out(vty,
12373 " Incoming update prefix filter list is %s%s\n",
12374 filter->plist[FILTER_IN].plist ? "*" : "",
12375 filter->plist[FILTER_IN].name);
12376 if (filter->plist[FILTER_OUT].name)
12377 vty_out(vty,
12378 " Outgoing update prefix filter list is %s%s\n",
12379 filter->plist[FILTER_OUT].plist ? "*" : "",
12380 filter->plist[FILTER_OUT].name);
12381
12382 /* distribute-list */
12383 if (filter->dlist[FILTER_IN].name)
12384 vty_out(vty,
12385 " Incoming update network filter list is %s%s\n",
12386 filter->dlist[FILTER_IN].alist ? "*" : "",
12387 filter->dlist[FILTER_IN].name);
12388 if (filter->dlist[FILTER_OUT].name)
12389 vty_out(vty,
12390 " Outgoing update network filter list is %s%s\n",
12391 filter->dlist[FILTER_OUT].alist ? "*" : "",
12392 filter->dlist[FILTER_OUT].name);
12393
12394 /* filter-list. */
12395 if (filter->aslist[FILTER_IN].name)
12396 vty_out(vty,
12397 " Incoming update AS path filter list is %s%s\n",
12398 filter->aslist[FILTER_IN].aslist ? "*" : "",
12399 filter->aslist[FILTER_IN].name);
12400 if (filter->aslist[FILTER_OUT].name)
12401 vty_out(vty,
12402 " Outgoing update AS path filter list is %s%s\n",
12403 filter->aslist[FILTER_OUT].aslist ? "*" : "",
12404 filter->aslist[FILTER_OUT].name);
12405
12406 /* route-map. */
12407 if (filter->map[RMAP_IN].name)
12408 vty_out(vty,
12409 " Route map for incoming advertisements is %s%s\n",
12410 filter->map[RMAP_IN].map ? "*" : "",
12411 filter->map[RMAP_IN].name);
12412 if (filter->map[RMAP_OUT].name)
12413 vty_out(vty,
12414 " Route map for outgoing advertisements is %s%s\n",
12415 filter->map[RMAP_OUT].map ? "*" : "",
12416 filter->map[RMAP_OUT].name);
12417
12418 /* ebgp-requires-policy (inbound) */
12419 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12420 && !bgp_inbound_policy_exists(p, filter))
12421 vty_out(vty,
12422 " Inbound updates discarded due to missing policy\n");
12423
12424 /* ebgp-requires-policy (outbound) */
12425 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12426 && !bgp_outbound_policy_exists(p, filter))
12427 vty_out(vty,
12428 " Outbound updates discarded due to missing policy\n");
12429
12430 /* unsuppress-map */
12431 if (filter->usmap.name)
12432 vty_out(vty,
12433 " Route map for selective unsuppress is %s%s\n",
12434 filter->usmap.map ? "*" : "",
12435 filter->usmap.name);
12436
12437 /* advertise-map */
12438 if (filter->advmap.aname && filter->advmap.cname)
12439 vty_out(vty,
12440 " Condition %s, Condition-map %s%s, Advertise-map %s%s, status: %s\n",
12441 filter->advmap.condition ? "EXIST"
12442 : "NON_EXIST",
12443 filter->advmap.cmap ? "*" : "",
12444 filter->advmap.cname,
12445 filter->advmap.amap ? "*" : "",
12446 filter->advmap.aname,
12447 filter->advmap.update_type == ADVERTISE
12448 ? "Advertise"
12449 : "Withdraw");
12450
12451 /* Receive prefix count */
12452 vty_out(vty, " %u accepted prefixes\n",
12453 p->pcount[afi][safi]);
12454
12455 /* maximum-prefix-out */
12456 if (CHECK_FLAG(p->af_flags[afi][safi],
12457 PEER_FLAG_MAX_PREFIX_OUT))
12458 vty_out(vty,
12459 " Maximum allowed prefixes sent %u\n",
12460 p->pmax_out[afi][safi]);
12461
12462 /* Maximum prefix */
12463 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12464 vty_out(vty,
12465 " Maximum prefixes allowed %u%s\n",
12466 p->pmax[afi][safi],
12467 CHECK_FLAG(p->af_flags[afi][safi],
12468 PEER_FLAG_MAX_PREFIX_WARNING)
12469 ? " (warning-only)"
12470 : "");
12471 vty_out(vty, " Threshold for warning message %d%%",
12472 p->pmax_threshold[afi][safi]);
12473 if (p->pmax_restart[afi][safi])
12474 vty_out(vty, ", restart interval %d min",
12475 p->pmax_restart[afi][safi]);
12476 vty_out(vty, "\n");
12477 }
12478
12479 vty_out(vty, "\n");
12480 }
12481 }
12482
12483 static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
12484 json_object *json)
12485 {
12486 struct bgp *bgp;
12487 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
12488 char timebuf[BGP_UPTIME_LEN];
12489 char dn_flag[2];
12490 afi_t afi;
12491 safi_t safi;
12492 uint16_t i;
12493 uint8_t *msg;
12494 json_object *json_neigh = NULL;
12495 time_t epoch_tbuf;
12496
12497 bgp = p->bgp;
12498
12499 if (use_json)
12500 json_neigh = json_object_new_object();
12501
12502 memset(dn_flag, '\0', sizeof(dn_flag));
12503 if (!p->conf_if && peer_dynamic_neighbor(p))
12504 dn_flag[0] = '*';
12505
12506 if (!use_json) {
12507 if (p->conf_if) /* Configured interface name. */
12508 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
12509 BGP_PEER_SU_UNSPEC(p)
12510 ? "None"
12511 : sockunion2str(&p->su, buf,
12512 SU_ADDRSTRLEN));
12513 else /* Configured IP address. */
12514 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
12515 p->host);
12516 }
12517
12518 if (use_json) {
12519 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
12520 json_object_string_add(json_neigh, "bgpNeighborAddr",
12521 "none");
12522 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
12523 json_object_string_add(
12524 json_neigh, "bgpNeighborAddr",
12525 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
12526
12527 json_object_int_add(json_neigh, "remoteAs", p->as);
12528
12529 if (p->change_local_as)
12530 json_object_int_add(json_neigh, "localAs",
12531 p->change_local_as);
12532 else
12533 json_object_int_add(json_neigh, "localAs", p->local_as);
12534
12535 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
12536 json_object_boolean_true_add(json_neigh,
12537 "localAsNoPrepend");
12538
12539 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
12540 json_object_boolean_true_add(json_neigh,
12541 "localAsReplaceAs");
12542 } else {
12543 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
12544 || (p->as_type == AS_INTERNAL))
12545 vty_out(vty, "remote AS %u, ", p->as);
12546 else
12547 vty_out(vty, "remote AS Unspecified, ");
12548 vty_out(vty, "local AS %u%s%s, ",
12549 p->change_local_as ? p->change_local_as : p->local_as,
12550 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
12551 ? " no-prepend"
12552 : "",
12553 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
12554 ? " replace-as"
12555 : "");
12556 }
12557 /* peer type internal or confed-internal */
12558 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
12559 if (use_json) {
12560 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12561 json_object_boolean_true_add(
12562 json_neigh, "nbrConfedInternalLink");
12563 else
12564 json_object_boolean_true_add(json_neigh,
12565 "nbrInternalLink");
12566 } else {
12567 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12568 vty_out(vty, "confed-internal link\n");
12569 else
12570 vty_out(vty, "internal link\n");
12571 }
12572 /* peer type external or confed-external */
12573 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
12574 if (use_json) {
12575 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12576 json_object_boolean_true_add(
12577 json_neigh, "nbrConfedExternalLink");
12578 else
12579 json_object_boolean_true_add(json_neigh,
12580 "nbrExternalLink");
12581 } else {
12582 if (bgp_confederation_peers_check(bgp, p->as))
12583 vty_out(vty, "confed-external link\n");
12584 else
12585 vty_out(vty, "external link\n");
12586 }
12587 } else {
12588 if (use_json)
12589 json_object_boolean_true_add(json_neigh,
12590 "nbrUnspecifiedLink");
12591 else
12592 vty_out(vty, "unspecified link\n");
12593 }
12594
12595 /* Description. */
12596 if (p->desc) {
12597 if (use_json)
12598 json_object_string_add(json_neigh, "nbrDesc", p->desc);
12599 else
12600 vty_out(vty, " Description: %s\n", p->desc);
12601 }
12602
12603 if (p->hostname) {
12604 if (use_json) {
12605 if (p->hostname)
12606 json_object_string_add(json_neigh, "hostname",
12607 p->hostname);
12608
12609 if (p->domainname)
12610 json_object_string_add(json_neigh, "domainname",
12611 p->domainname);
12612 } else {
12613 if (p->domainname && (p->domainname[0] != '\0'))
12614 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
12615 p->domainname);
12616 else
12617 vty_out(vty, "Hostname: %s\n", p->hostname);
12618 }
12619 }
12620
12621 /* Peer-group */
12622 if (p->group) {
12623 if (use_json) {
12624 json_object_string_add(json_neigh, "peerGroup",
12625 p->group->name);
12626
12627 if (dn_flag[0]) {
12628 struct prefix prefix, *range = NULL;
12629
12630 if (sockunion2hostprefix(&(p->su), &prefix))
12631 range = peer_group_lookup_dynamic_neighbor_range(
12632 p->group, &prefix);
12633
12634 if (range) {
12635 prefix2str(range, buf1, sizeof(buf1));
12636 json_object_string_add(
12637 json_neigh,
12638 "peerSubnetRangeGroup", buf1);
12639 }
12640 }
12641 } else {
12642 vty_out(vty,
12643 " Member of peer-group %s for session parameters\n",
12644 p->group->name);
12645
12646 if (dn_flag[0]) {
12647 struct prefix prefix, *range = NULL;
12648
12649 if (sockunion2hostprefix(&(p->su), &prefix))
12650 range = peer_group_lookup_dynamic_neighbor_range(
12651 p->group, &prefix);
12652
12653 if (range) {
12654 vty_out(vty,
12655 " Belongs to the subnet range group: %pFX\n",
12656 range);
12657 }
12658 }
12659 }
12660 }
12661
12662 if (use_json) {
12663 /* Administrative shutdown. */
12664 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12665 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
12666 json_object_boolean_true_add(json_neigh,
12667 "adminShutDown");
12668
12669 /* BGP Version. */
12670 json_object_int_add(json_neigh, "bgpVersion", 4);
12671 json_object_string_add(
12672 json_neigh, "remoteRouterId",
12673 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
12674 json_object_string_add(
12675 json_neigh, "localRouterId",
12676 inet_ntop(AF_INET, &bgp->router_id, buf1,
12677 sizeof(buf1)));
12678
12679 /* Confederation */
12680 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12681 && bgp_confederation_peers_check(bgp, p->as))
12682 json_object_boolean_true_add(json_neigh,
12683 "nbrCommonAdmin");
12684
12685 /* Status. */
12686 json_object_string_add(
12687 json_neigh, "bgpState",
12688 lookup_msg(bgp_status_msg, p->status, NULL));
12689
12690 if (p->status == Established) {
12691 time_t uptime;
12692
12693 uptime = bgp_clock();
12694 uptime -= p->uptime;
12695 epoch_tbuf = time(NULL) - uptime;
12696
12697 json_object_int_add(json_neigh, "bgpTimerUpMsec",
12698 uptime * 1000);
12699 json_object_string_add(json_neigh, "bgpTimerUpString",
12700 peer_uptime(p->uptime, timebuf,
12701 BGP_UPTIME_LEN, 0,
12702 NULL));
12703 json_object_int_add(json_neigh,
12704 "bgpTimerUpEstablishedEpoch",
12705 epoch_tbuf);
12706 }
12707
12708 else if (p->status == Active) {
12709 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12710 json_object_string_add(json_neigh, "bgpStateIs",
12711 "passive");
12712 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12713 json_object_string_add(json_neigh, "bgpStateIs",
12714 "passiveNSF");
12715 }
12716
12717 /* read timer */
12718 time_t uptime;
12719 struct tm tm;
12720
12721 uptime = bgp_clock();
12722 uptime -= p->readtime;
12723 gmtime_r(&uptime, &tm);
12724
12725 json_object_int_add(json_neigh, "bgpTimerLastRead",
12726 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12727 + (tm.tm_hour * 3600000));
12728
12729 uptime = bgp_clock();
12730 uptime -= p->last_write;
12731 gmtime_r(&uptime, &tm);
12732
12733 json_object_int_add(json_neigh, "bgpTimerLastWrite",
12734 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12735 + (tm.tm_hour * 3600000));
12736
12737 uptime = bgp_clock();
12738 uptime -= p->update_time;
12739 gmtime_r(&uptime, &tm);
12740
12741 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
12742 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12743 + (tm.tm_hour * 3600000));
12744
12745 /* Configured timer values. */
12746 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
12747 p->v_holdtime * 1000);
12748 json_object_int_add(json_neigh,
12749 "bgpTimerKeepAliveIntervalMsecs",
12750 p->v_keepalive * 1000);
12751 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN)) {
12752 json_object_int_add(json_neigh,
12753 "bgpTimerDelayOpenTimeMsecs",
12754 p->v_delayopen * 1000);
12755 }
12756
12757 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
12758 json_object_int_add(json_neigh,
12759 "bgpTimerConfiguredHoldTimeMsecs",
12760 p->holdtime * 1000);
12761 json_object_int_add(
12762 json_neigh,
12763 "bgpTimerConfiguredKeepAliveIntervalMsecs",
12764 p->keepalive * 1000);
12765 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
12766 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
12767 json_object_int_add(json_neigh,
12768 "bgpTimerConfiguredHoldTimeMsecs",
12769 bgp->default_holdtime);
12770 json_object_int_add(
12771 json_neigh,
12772 "bgpTimerConfiguredKeepAliveIntervalMsecs",
12773 bgp->default_keepalive);
12774 }
12775 } else {
12776 /* Administrative shutdown. */
12777 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12778 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
12779 vty_out(vty, " Administratively shut down\n");
12780
12781 /* BGP Version. */
12782 vty_out(vty, " BGP version 4");
12783 vty_out(vty, ", remote router ID %s",
12784 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
12785 vty_out(vty, ", local router ID %s\n",
12786 inet_ntop(AF_INET, &bgp->router_id, buf1,
12787 sizeof(buf1)));
12788
12789 /* Confederation */
12790 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12791 && bgp_confederation_peers_check(bgp, p->as))
12792 vty_out(vty,
12793 " Neighbor under common administration\n");
12794
12795 /* Status. */
12796 vty_out(vty, " BGP state = %s",
12797 lookup_msg(bgp_status_msg, p->status, NULL));
12798
12799 if (p->status == Established)
12800 vty_out(vty, ", up for %8s",
12801 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
12802 0, NULL));
12803
12804 else if (p->status == Active) {
12805 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12806 vty_out(vty, " (passive)");
12807 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12808 vty_out(vty, " (NSF passive)");
12809 }
12810 vty_out(vty, "\n");
12811
12812 /* read timer */
12813 vty_out(vty, " Last read %s",
12814 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
12815 NULL));
12816 vty_out(vty, ", Last write %s\n",
12817 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
12818 NULL));
12819
12820 /* Configured timer values. */
12821 vty_out(vty,
12822 " Hold time is %d, keepalive interval is %d seconds\n",
12823 p->v_holdtime, p->v_keepalive);
12824 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
12825 vty_out(vty, " Configured hold time is %d",
12826 p->holdtime);
12827 vty_out(vty, ", keepalive interval is %d seconds\n",
12828 p->keepalive);
12829 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
12830 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
12831 vty_out(vty, " Configured hold time is %d",
12832 bgp->default_holdtime);
12833 vty_out(vty, ", keepalive interval is %d seconds\n",
12834 bgp->default_keepalive);
12835 }
12836 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN))
12837 vty_out(vty,
12838 " Configured DelayOpenTime is %d seconds\n",
12839 p->delayopen);
12840 }
12841 /* Capability. */
12842 if (p->status == Established) {
12843 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
12844 || p->afc_recv[AFI_IP][SAFI_UNICAST]
12845 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
12846 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
12847 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
12848 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
12849 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
12850 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
12851 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
12852 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
12853 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
12854 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
12855 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
12856 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
12857 || p->afc_adv[AFI_IP][SAFI_ENCAP]
12858 || p->afc_recv[AFI_IP][SAFI_ENCAP]
12859 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
12860 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
12861 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
12862 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
12863 if (use_json) {
12864 json_object *json_cap = NULL;
12865
12866 json_cap = json_object_new_object();
12867
12868 /* AS4 */
12869 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
12870 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
12871 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
12872 && CHECK_FLAG(p->cap,
12873 PEER_CAP_AS4_RCV))
12874 json_object_string_add(
12875 json_cap, "4byteAs",
12876 "advertisedAndReceived");
12877 else if (CHECK_FLAG(p->cap,
12878 PEER_CAP_AS4_ADV))
12879 json_object_string_add(
12880 json_cap, "4byteAs",
12881 "advertised");
12882 else if (CHECK_FLAG(p->cap,
12883 PEER_CAP_AS4_RCV))
12884 json_object_string_add(
12885 json_cap, "4byteAs",
12886 "received");
12887 }
12888
12889 /* AddPath */
12890 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
12891 || CHECK_FLAG(p->cap,
12892 PEER_CAP_ADDPATH_ADV)) {
12893 json_object *json_add = NULL;
12894 const char *print_store;
12895
12896 json_add = json_object_new_object();
12897
12898 FOREACH_AFI_SAFI (afi, safi) {
12899 json_object *json_sub = NULL;
12900 json_sub =
12901 json_object_new_object();
12902 print_store = get_afi_safi_str(
12903 afi, safi, true);
12904
12905 if (CHECK_FLAG(
12906 p->af_cap[afi]
12907 [safi],
12908 PEER_CAP_ADDPATH_AF_TX_ADV)
12909 || CHECK_FLAG(
12910 p->af_cap[afi]
12911 [safi],
12912 PEER_CAP_ADDPATH_AF_TX_RCV)) {
12913 if (CHECK_FLAG(
12914 p->af_cap
12915 [afi]
12916 [safi],
12917 PEER_CAP_ADDPATH_AF_TX_ADV)
12918 && CHECK_FLAG(
12919 p->af_cap
12920 [afi]
12921 [safi],
12922 PEER_CAP_ADDPATH_AF_TX_RCV))
12923 json_object_boolean_true_add(
12924 json_sub,
12925 "txAdvertisedAndReceived");
12926 else if (
12927 CHECK_FLAG(
12928 p->af_cap
12929 [afi]
12930 [safi],
12931 PEER_CAP_ADDPATH_AF_TX_ADV))
12932 json_object_boolean_true_add(
12933 json_sub,
12934 "txAdvertised");
12935 else if (
12936 CHECK_FLAG(
12937 p->af_cap
12938 [afi]
12939 [safi],
12940 PEER_CAP_ADDPATH_AF_TX_RCV))
12941 json_object_boolean_true_add(
12942 json_sub,
12943 "txReceived");
12944 }
12945
12946 if (CHECK_FLAG(
12947 p->af_cap[afi]
12948 [safi],
12949 PEER_CAP_ADDPATH_AF_RX_ADV)
12950 || CHECK_FLAG(
12951 p->af_cap[afi]
12952 [safi],
12953 PEER_CAP_ADDPATH_AF_RX_RCV)) {
12954 if (CHECK_FLAG(
12955 p->af_cap
12956 [afi]
12957 [safi],
12958 PEER_CAP_ADDPATH_AF_RX_ADV)
12959 && CHECK_FLAG(
12960 p->af_cap
12961 [afi]
12962 [safi],
12963 PEER_CAP_ADDPATH_AF_RX_RCV))
12964 json_object_boolean_true_add(
12965 json_sub,
12966 "rxAdvertisedAndReceived");
12967 else if (
12968 CHECK_FLAG(
12969 p->af_cap
12970 [afi]
12971 [safi],
12972 PEER_CAP_ADDPATH_AF_RX_ADV))
12973 json_object_boolean_true_add(
12974 json_sub,
12975 "rxAdvertised");
12976 else if (
12977 CHECK_FLAG(
12978 p->af_cap
12979 [afi]
12980 [safi],
12981 PEER_CAP_ADDPATH_AF_RX_RCV))
12982 json_object_boolean_true_add(
12983 json_sub,
12984 "rxReceived");
12985 }
12986
12987 if (CHECK_FLAG(
12988 p->af_cap[afi]
12989 [safi],
12990 PEER_CAP_ADDPATH_AF_TX_ADV)
12991 || CHECK_FLAG(
12992 p->af_cap[afi]
12993 [safi],
12994 PEER_CAP_ADDPATH_AF_TX_RCV)
12995 || CHECK_FLAG(
12996 p->af_cap[afi]
12997 [safi],
12998 PEER_CAP_ADDPATH_AF_RX_ADV)
12999 || CHECK_FLAG(
13000 p->af_cap[afi]
13001 [safi],
13002 PEER_CAP_ADDPATH_AF_RX_RCV))
13003 json_object_object_add(
13004 json_add,
13005 print_store,
13006 json_sub);
13007 else
13008 json_object_free(
13009 json_sub);
13010 }
13011
13012 json_object_object_add(
13013 json_cap, "addPath", json_add);
13014 }
13015
13016 /* Dynamic */
13017 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
13018 || CHECK_FLAG(p->cap,
13019 PEER_CAP_DYNAMIC_ADV)) {
13020 if (CHECK_FLAG(p->cap,
13021 PEER_CAP_DYNAMIC_ADV)
13022 && CHECK_FLAG(p->cap,
13023 PEER_CAP_DYNAMIC_RCV))
13024 json_object_string_add(
13025 json_cap, "dynamic",
13026 "advertisedAndReceived");
13027 else if (CHECK_FLAG(
13028 p->cap,
13029 PEER_CAP_DYNAMIC_ADV))
13030 json_object_string_add(
13031 json_cap, "dynamic",
13032 "advertised");
13033 else if (CHECK_FLAG(
13034 p->cap,
13035 PEER_CAP_DYNAMIC_RCV))
13036 json_object_string_add(
13037 json_cap, "dynamic",
13038 "received");
13039 }
13040
13041 /* Extended nexthop */
13042 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
13043 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13044 json_object *json_nxt = NULL;
13045 const char *print_store;
13046
13047
13048 if (CHECK_FLAG(p->cap,
13049 PEER_CAP_ENHE_ADV)
13050 && CHECK_FLAG(p->cap,
13051 PEER_CAP_ENHE_RCV))
13052 json_object_string_add(
13053 json_cap,
13054 "extendedNexthop",
13055 "advertisedAndReceived");
13056 else if (CHECK_FLAG(p->cap,
13057 PEER_CAP_ENHE_ADV))
13058 json_object_string_add(
13059 json_cap,
13060 "extendedNexthop",
13061 "advertised");
13062 else if (CHECK_FLAG(p->cap,
13063 PEER_CAP_ENHE_RCV))
13064 json_object_string_add(
13065 json_cap,
13066 "extendedNexthop",
13067 "received");
13068
13069 if (CHECK_FLAG(p->cap,
13070 PEER_CAP_ENHE_RCV)) {
13071 json_nxt =
13072 json_object_new_object();
13073
13074 for (safi = SAFI_UNICAST;
13075 safi < SAFI_MAX; safi++) {
13076 if (CHECK_FLAG(
13077 p->af_cap
13078 [AFI_IP]
13079 [safi],
13080 PEER_CAP_ENHE_AF_RCV)) {
13081 print_store = get_afi_safi_str(
13082 AFI_IP,
13083 safi, true);
13084 json_object_string_add(
13085 json_nxt,
13086 print_store,
13087 "recieved"); /* misspelled for compatibility */
13088 }
13089 }
13090 json_object_object_add(
13091 json_cap,
13092 "extendedNexthopFamililesByPeer",
13093 json_nxt);
13094 }
13095 }
13096
13097 /* Route Refresh */
13098 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
13099 || CHECK_FLAG(p->cap,
13100 PEER_CAP_REFRESH_NEW_RCV)
13101 || CHECK_FLAG(p->cap,
13102 PEER_CAP_REFRESH_OLD_RCV)) {
13103 if (CHECK_FLAG(p->cap,
13104 PEER_CAP_REFRESH_ADV)
13105 && (CHECK_FLAG(
13106 p->cap,
13107 PEER_CAP_REFRESH_NEW_RCV)
13108 || CHECK_FLAG(
13109 p->cap,
13110 PEER_CAP_REFRESH_OLD_RCV))) {
13111 if (CHECK_FLAG(
13112 p->cap,
13113 PEER_CAP_REFRESH_OLD_RCV)
13114 && CHECK_FLAG(
13115 p->cap,
13116 PEER_CAP_REFRESH_NEW_RCV))
13117 json_object_string_add(
13118 json_cap,
13119 "routeRefresh",
13120 "advertisedAndReceivedOldNew");
13121 else {
13122 if (CHECK_FLAG(
13123 p->cap,
13124 PEER_CAP_REFRESH_OLD_RCV))
13125 json_object_string_add(
13126 json_cap,
13127 "routeRefresh",
13128 "advertisedAndReceivedOld");
13129 else
13130 json_object_string_add(
13131 json_cap,
13132 "routeRefresh",
13133 "advertisedAndReceivedNew");
13134 }
13135 } else if (
13136 CHECK_FLAG(
13137 p->cap,
13138 PEER_CAP_REFRESH_ADV))
13139 json_object_string_add(
13140 json_cap,
13141 "routeRefresh",
13142 "advertised");
13143 else if (
13144 CHECK_FLAG(
13145 p->cap,
13146 PEER_CAP_REFRESH_NEW_RCV)
13147 || CHECK_FLAG(
13148 p->cap,
13149 PEER_CAP_REFRESH_OLD_RCV))
13150 json_object_string_add(
13151 json_cap,
13152 "routeRefresh",
13153 "received");
13154 }
13155
13156 /* Multiprotocol Extensions */
13157 json_object *json_multi = NULL;
13158 json_multi = json_object_new_object();
13159
13160 FOREACH_AFI_SAFI (afi, safi) {
13161 if (p->afc_adv[afi][safi]
13162 || p->afc_recv[afi][safi]) {
13163 json_object *json_exten = NULL;
13164 json_exten =
13165 json_object_new_object();
13166
13167 if (p->afc_adv[afi][safi]
13168 && p->afc_recv[afi][safi])
13169 json_object_boolean_true_add(
13170 json_exten,
13171 "advertisedAndReceived");
13172 else if (p->afc_adv[afi][safi])
13173 json_object_boolean_true_add(
13174 json_exten,
13175 "advertised");
13176 else if (p->afc_recv[afi][safi])
13177 json_object_boolean_true_add(
13178 json_exten,
13179 "received");
13180
13181 json_object_object_add(
13182 json_multi,
13183 get_afi_safi_str(afi,
13184 safi,
13185 true),
13186 json_exten);
13187 }
13188 }
13189 json_object_object_add(
13190 json_cap, "multiprotocolExtensions",
13191 json_multi);
13192
13193 /* Hostname capabilities */
13194 json_object *json_hname = NULL;
13195
13196 json_hname = json_object_new_object();
13197
13198 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13199 json_object_string_add(
13200 json_hname, "advHostName",
13201 bgp->peer_self->hostname
13202 ? bgp->peer_self
13203 ->hostname
13204 : "n/a");
13205 json_object_string_add(
13206 json_hname, "advDomainName",
13207 bgp->peer_self->domainname
13208 ? bgp->peer_self
13209 ->domainname
13210 : "n/a");
13211 }
13212
13213
13214 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13215 json_object_string_add(
13216 json_hname, "rcvHostName",
13217 p->hostname ? p->hostname
13218 : "n/a");
13219 json_object_string_add(
13220 json_hname, "rcvDomainName",
13221 p->domainname ? p->domainname
13222 : "n/a");
13223 }
13224
13225 json_object_object_add(json_cap, "hostName",
13226 json_hname);
13227
13228 /* Gracefull Restart */
13229 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
13230 || CHECK_FLAG(p->cap,
13231 PEER_CAP_RESTART_ADV)) {
13232 if (CHECK_FLAG(p->cap,
13233 PEER_CAP_RESTART_ADV)
13234 && CHECK_FLAG(p->cap,
13235 PEER_CAP_RESTART_RCV))
13236 json_object_string_add(
13237 json_cap,
13238 "gracefulRestart",
13239 "advertisedAndReceived");
13240 else if (CHECK_FLAG(
13241 p->cap,
13242 PEER_CAP_RESTART_ADV))
13243 json_object_string_add(
13244 json_cap,
13245 "gracefulRestartCapability",
13246 "advertised");
13247 else if (CHECK_FLAG(
13248 p->cap,
13249 PEER_CAP_RESTART_RCV))
13250 json_object_string_add(
13251 json_cap,
13252 "gracefulRestartCapability",
13253 "received");
13254
13255 if (CHECK_FLAG(p->cap,
13256 PEER_CAP_RESTART_RCV)) {
13257 int restart_af_count = 0;
13258 json_object *json_restart =
13259 NULL;
13260 json_restart =
13261 json_object_new_object();
13262
13263 json_object_int_add(
13264 json_cap,
13265 "gracefulRestartRemoteTimerMsecs",
13266 p->v_gr_restart * 1000);
13267
13268 FOREACH_AFI_SAFI (afi, safi) {
13269 if (CHECK_FLAG(
13270 p->af_cap
13271 [afi]
13272 [safi],
13273 PEER_CAP_RESTART_AF_RCV)) {
13274 json_object *
13275 json_sub =
13276 NULL;
13277 json_sub =
13278 json_object_new_object();
13279
13280 if (CHECK_FLAG(
13281 p->af_cap
13282 [afi]
13283 [safi],
13284 PEER_CAP_RESTART_AF_PRESERVE_RCV))
13285 json_object_boolean_true_add(
13286 json_sub,
13287 "preserved");
13288 restart_af_count++;
13289 json_object_object_add(
13290 json_restart,
13291 get_afi_safi_str(
13292 afi,
13293 safi,
13294 true),
13295 json_sub);
13296 }
13297 }
13298 if (!restart_af_count) {
13299 json_object_string_add(
13300 json_cap,
13301 "addressFamiliesByPeer",
13302 "none");
13303 json_object_free(
13304 json_restart);
13305 } else
13306 json_object_object_add(
13307 json_cap,
13308 "addressFamiliesByPeer",
13309 json_restart);
13310 }
13311 }
13312 json_object_object_add(json_neigh,
13313 "neighborCapabilities",
13314 json_cap);
13315 } else {
13316 vty_out(vty, " Neighbor capabilities:\n");
13317
13318 /* AS4 */
13319 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
13320 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13321 vty_out(vty, " 4 Byte AS:");
13322 if (CHECK_FLAG(p->cap,
13323 PEER_CAP_AS4_ADV))
13324 vty_out(vty, " advertised");
13325 if (CHECK_FLAG(p->cap,
13326 PEER_CAP_AS4_RCV))
13327 vty_out(vty, " %sreceived",
13328 CHECK_FLAG(
13329 p->cap,
13330 PEER_CAP_AS4_ADV)
13331 ? "and "
13332 : "");
13333 vty_out(vty, "\n");
13334 }
13335
13336 /* AddPath */
13337 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
13338 || CHECK_FLAG(p->cap,
13339 PEER_CAP_ADDPATH_ADV)) {
13340 vty_out(vty, " AddPath:\n");
13341
13342 FOREACH_AFI_SAFI (afi, safi) {
13343 if (CHECK_FLAG(
13344 p->af_cap[afi]
13345 [safi],
13346 PEER_CAP_ADDPATH_AF_TX_ADV)
13347 || CHECK_FLAG(
13348 p->af_cap[afi]
13349 [safi],
13350 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13351 vty_out(vty,
13352 " %s: TX ",
13353 get_afi_safi_str(
13354 afi,
13355 safi,
13356 false));
13357
13358 if (CHECK_FLAG(
13359 p->af_cap
13360 [afi]
13361 [safi],
13362 PEER_CAP_ADDPATH_AF_TX_ADV))
13363 vty_out(vty,
13364 "advertised %s",
13365 get_afi_safi_str(
13366 afi,
13367 safi,
13368 false));
13369
13370 if (CHECK_FLAG(
13371 p->af_cap
13372 [afi]
13373 [safi],
13374 PEER_CAP_ADDPATH_AF_TX_RCV))
13375 vty_out(vty,
13376 "%sreceived",
13377 CHECK_FLAG(
13378 p->af_cap
13379 [afi]
13380 [safi],
13381 PEER_CAP_ADDPATH_AF_TX_ADV)
13382 ? " and "
13383 : "");
13384
13385 vty_out(vty, "\n");
13386 }
13387
13388 if (CHECK_FLAG(
13389 p->af_cap[afi]
13390 [safi],
13391 PEER_CAP_ADDPATH_AF_RX_ADV)
13392 || CHECK_FLAG(
13393 p->af_cap[afi]
13394 [safi],
13395 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13396 vty_out(vty,
13397 " %s: RX ",
13398 get_afi_safi_str(
13399 afi,
13400 safi,
13401 false));
13402
13403 if (CHECK_FLAG(
13404 p->af_cap
13405 [afi]
13406 [safi],
13407 PEER_CAP_ADDPATH_AF_RX_ADV))
13408 vty_out(vty,
13409 "advertised %s",
13410 get_afi_safi_str(
13411 afi,
13412 safi,
13413 false));
13414
13415 if (CHECK_FLAG(
13416 p->af_cap
13417 [afi]
13418 [safi],
13419 PEER_CAP_ADDPATH_AF_RX_RCV))
13420 vty_out(vty,
13421 "%sreceived",
13422 CHECK_FLAG(
13423 p->af_cap
13424 [afi]
13425 [safi],
13426 PEER_CAP_ADDPATH_AF_RX_ADV)
13427 ? " and "
13428 : "");
13429
13430 vty_out(vty, "\n");
13431 }
13432 }
13433 }
13434
13435 /* Dynamic */
13436 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
13437 || CHECK_FLAG(p->cap,
13438 PEER_CAP_DYNAMIC_ADV)) {
13439 vty_out(vty, " Dynamic:");
13440 if (CHECK_FLAG(p->cap,
13441 PEER_CAP_DYNAMIC_ADV))
13442 vty_out(vty, " advertised");
13443 if (CHECK_FLAG(p->cap,
13444 PEER_CAP_DYNAMIC_RCV))
13445 vty_out(vty, " %sreceived",
13446 CHECK_FLAG(
13447 p->cap,
13448 PEER_CAP_DYNAMIC_ADV)
13449 ? "and "
13450 : "");
13451 vty_out(vty, "\n");
13452 }
13453
13454 /* Extended nexthop */
13455 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
13456 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13457 vty_out(vty, " Extended nexthop:");
13458 if (CHECK_FLAG(p->cap,
13459 PEER_CAP_ENHE_ADV))
13460 vty_out(vty, " advertised");
13461 if (CHECK_FLAG(p->cap,
13462 PEER_CAP_ENHE_RCV))
13463 vty_out(vty, " %sreceived",
13464 CHECK_FLAG(
13465 p->cap,
13466 PEER_CAP_ENHE_ADV)
13467 ? "and "
13468 : "");
13469 vty_out(vty, "\n");
13470
13471 if (CHECK_FLAG(p->cap,
13472 PEER_CAP_ENHE_RCV)) {
13473 vty_out(vty,
13474 " Address families by peer:\n ");
13475 for (safi = SAFI_UNICAST;
13476 safi < SAFI_MAX; safi++)
13477 if (CHECK_FLAG(
13478 p->af_cap
13479 [AFI_IP]
13480 [safi],
13481 PEER_CAP_ENHE_AF_RCV))
13482 vty_out(vty,
13483 " %s\n",
13484 get_afi_safi_str(
13485 AFI_IP,
13486 safi,
13487 false));
13488 }
13489 }
13490
13491 /* Route Refresh */
13492 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
13493 || CHECK_FLAG(p->cap,
13494 PEER_CAP_REFRESH_NEW_RCV)
13495 || CHECK_FLAG(p->cap,
13496 PEER_CAP_REFRESH_OLD_RCV)) {
13497 vty_out(vty, " Route refresh:");
13498 if (CHECK_FLAG(p->cap,
13499 PEER_CAP_REFRESH_ADV))
13500 vty_out(vty, " advertised");
13501 if (CHECK_FLAG(p->cap,
13502 PEER_CAP_REFRESH_NEW_RCV)
13503 || CHECK_FLAG(
13504 p->cap,
13505 PEER_CAP_REFRESH_OLD_RCV))
13506 vty_out(vty, " %sreceived(%s)",
13507 CHECK_FLAG(
13508 p->cap,
13509 PEER_CAP_REFRESH_ADV)
13510 ? "and "
13511 : "",
13512 (CHECK_FLAG(
13513 p->cap,
13514 PEER_CAP_REFRESH_OLD_RCV)
13515 && CHECK_FLAG(
13516 p->cap,
13517 PEER_CAP_REFRESH_NEW_RCV))
13518 ? "old & new"
13519 : CHECK_FLAG(
13520 p->cap,
13521 PEER_CAP_REFRESH_OLD_RCV)
13522 ? "old"
13523 : "new");
13524
13525 vty_out(vty, "\n");
13526 }
13527
13528 /* Multiprotocol Extensions */
13529 FOREACH_AFI_SAFI (afi, safi)
13530 if (p->afc_adv[afi][safi]
13531 || p->afc_recv[afi][safi]) {
13532 vty_out(vty,
13533 " Address Family %s:",
13534 get_afi_safi_str(
13535 afi,
13536 safi,
13537 false));
13538 if (p->afc_adv[afi][safi])
13539 vty_out(vty,
13540 " advertised");
13541 if (p->afc_recv[afi][safi])
13542 vty_out(vty,
13543 " %sreceived",
13544 p->afc_adv[afi]
13545 [safi]
13546 ? "and "
13547 : "");
13548 vty_out(vty, "\n");
13549 }
13550
13551 /* Hostname capability */
13552 vty_out(vty, " Hostname Capability:");
13553
13554 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13555 vty_out(vty,
13556 " advertised (name: %s,domain name: %s)",
13557 bgp->peer_self->hostname
13558 ? bgp->peer_self
13559 ->hostname
13560 : "n/a",
13561 bgp->peer_self->domainname
13562 ? bgp->peer_self
13563 ->domainname
13564 : "n/a");
13565 } else {
13566 vty_out(vty, " not advertised");
13567 }
13568
13569 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13570 vty_out(vty,
13571 " received (name: %s,domain name: %s)",
13572 p->hostname ? p->hostname
13573 : "n/a",
13574 p->domainname ? p->domainname
13575 : "n/a");
13576 } else {
13577 vty_out(vty, " not received");
13578 }
13579
13580 vty_out(vty, "\n");
13581
13582 /* Graceful Restart */
13583 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
13584 || CHECK_FLAG(p->cap,
13585 PEER_CAP_RESTART_ADV)) {
13586 vty_out(vty,
13587 " Graceful Restart Capability:");
13588 if (CHECK_FLAG(p->cap,
13589 PEER_CAP_RESTART_ADV))
13590 vty_out(vty, " advertised");
13591 if (CHECK_FLAG(p->cap,
13592 PEER_CAP_RESTART_RCV))
13593 vty_out(vty, " %sreceived",
13594 CHECK_FLAG(
13595 p->cap,
13596 PEER_CAP_RESTART_ADV)
13597 ? "and "
13598 : "");
13599 vty_out(vty, "\n");
13600
13601 if (CHECK_FLAG(p->cap,
13602 PEER_CAP_RESTART_RCV)) {
13603 int restart_af_count = 0;
13604
13605 vty_out(vty,
13606 " Remote Restart timer is %d seconds\n",
13607 p->v_gr_restart);
13608 vty_out(vty,
13609 " Address families by peer:\n ");
13610
13611 FOREACH_AFI_SAFI (afi, safi)
13612 if (CHECK_FLAG(
13613 p->af_cap
13614 [afi]
13615 [safi],
13616 PEER_CAP_RESTART_AF_RCV)) {
13617 vty_out(vty,
13618 "%s%s(%s)",
13619 restart_af_count
13620 ? ", "
13621 : "",
13622 get_afi_safi_str(
13623 afi,
13624 safi,
13625 false),
13626 CHECK_FLAG(
13627 p->af_cap
13628 [afi]
13629 [safi],
13630 PEER_CAP_RESTART_AF_PRESERVE_RCV)
13631 ? "preserved"
13632 : "not preserved");
13633 restart_af_count++;
13634 }
13635 if (!restart_af_count)
13636 vty_out(vty, "none");
13637 vty_out(vty, "\n");
13638 }
13639 } /* Gracefull Restart */
13640 }
13641 }
13642 }
13643
13644 /* graceful restart information */
13645 json_object *json_grace = NULL;
13646 json_object *json_grace_send = NULL;
13647 json_object *json_grace_recv = NULL;
13648 int eor_send_af_count = 0;
13649 int eor_receive_af_count = 0;
13650
13651 if (use_json) {
13652 json_grace = json_object_new_object();
13653 json_grace_send = json_object_new_object();
13654 json_grace_recv = json_object_new_object();
13655
13656 if ((p->status == Established)
13657 && CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13658 FOREACH_AFI_SAFI (afi, safi) {
13659 if (CHECK_FLAG(p->af_sflags[afi][safi],
13660 PEER_STATUS_EOR_SEND)) {
13661 json_object_boolean_true_add(
13662 json_grace_send,
13663 get_afi_safi_str(afi,
13664 safi,
13665 true));
13666 eor_send_af_count++;
13667 }
13668 }
13669 FOREACH_AFI_SAFI (afi, safi) {
13670 if (CHECK_FLAG(
13671 p->af_sflags[afi][safi],
13672 PEER_STATUS_EOR_RECEIVED)) {
13673 json_object_boolean_true_add(
13674 json_grace_recv,
13675 get_afi_safi_str(afi,
13676 safi,
13677 true));
13678 eor_receive_af_count++;
13679 }
13680 }
13681 }
13682 json_object_object_add(json_grace, "endOfRibSend",
13683 json_grace_send);
13684 json_object_object_add(json_grace, "endOfRibRecv",
13685 json_grace_recv);
13686
13687
13688 if (p->t_gr_restart)
13689 json_object_int_add(json_grace,
13690 "gracefulRestartTimerMsecs",
13691 thread_timer_remain_second(
13692 p->t_gr_restart)
13693 * 1000);
13694
13695 if (p->t_gr_stale)
13696 json_object_int_add(
13697 json_grace,
13698 "gracefulStalepathTimerMsecs",
13699 thread_timer_remain_second(
13700 p->t_gr_stale)
13701 * 1000);
13702 /* more gr info in new format */
13703 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json,
13704 json_grace);
13705 json_object_object_add(
13706 json_neigh, "gracefulRestartInfo", json_grace);
13707 } else {
13708 vty_out(vty, " Graceful restart information:\n");
13709 if ((p->status == Established)
13710 && CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13711
13712 vty_out(vty, " End-of-RIB send: ");
13713 FOREACH_AFI_SAFI (afi, safi) {
13714 if (CHECK_FLAG(p->af_sflags[afi][safi],
13715 PEER_STATUS_EOR_SEND)) {
13716 vty_out(vty, "%s%s",
13717 eor_send_af_count ? ", "
13718 : "",
13719 get_afi_safi_str(
13720 afi, safi,
13721 false));
13722 eor_send_af_count++;
13723 }
13724 }
13725 vty_out(vty, "\n");
13726 vty_out(vty, " End-of-RIB received: ");
13727 FOREACH_AFI_SAFI (afi, safi) {
13728 if (CHECK_FLAG(
13729 p->af_sflags[afi][safi],
13730 PEER_STATUS_EOR_RECEIVED)) {
13731 vty_out(vty, "%s%s",
13732 eor_receive_af_count
13733 ? ", "
13734 : "",
13735 get_afi_safi_str(afi,
13736 safi,
13737 false));
13738 eor_receive_af_count++;
13739 }
13740 }
13741 vty_out(vty, "\n");
13742 }
13743
13744 if (p->t_gr_restart)
13745 vty_out(vty,
13746 " The remaining time of restart timer is %ld\n",
13747 thread_timer_remain_second(
13748 p->t_gr_restart));
13749
13750 if (p->t_gr_stale)
13751 vty_out(vty,
13752 " The remaining time of stalepath timer is %ld\n",
13753 thread_timer_remain_second(
13754 p->t_gr_stale));
13755
13756 /* more gr info in new format */
13757 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, NULL);
13758 }
13759
13760 if (use_json) {
13761 json_object *json_stat = NULL;
13762 json_stat = json_object_new_object();
13763 /* Packet counts. */
13764
13765 atomic_size_t outq_count, inq_count;
13766 outq_count = atomic_load_explicit(&p->obuf->count,
13767 memory_order_relaxed);
13768 inq_count = atomic_load_explicit(&p->ibuf->count,
13769 memory_order_relaxed);
13770
13771 json_object_int_add(json_stat, "depthInq",
13772 (unsigned long)inq_count);
13773 json_object_int_add(json_stat, "depthOutq",
13774 (unsigned long)outq_count);
13775 json_object_int_add(json_stat, "opensSent",
13776 atomic_load_explicit(&p->open_out,
13777 memory_order_relaxed));
13778 json_object_int_add(json_stat, "opensRecv",
13779 atomic_load_explicit(&p->open_in,
13780 memory_order_relaxed));
13781 json_object_int_add(json_stat, "notificationsSent",
13782 atomic_load_explicit(&p->notify_out,
13783 memory_order_relaxed));
13784 json_object_int_add(json_stat, "notificationsRecv",
13785 atomic_load_explicit(&p->notify_in,
13786 memory_order_relaxed));
13787 json_object_int_add(json_stat, "updatesSent",
13788 atomic_load_explicit(&p->update_out,
13789 memory_order_relaxed));
13790 json_object_int_add(json_stat, "updatesRecv",
13791 atomic_load_explicit(&p->update_in,
13792 memory_order_relaxed));
13793 json_object_int_add(json_stat, "keepalivesSent",
13794 atomic_load_explicit(&p->keepalive_out,
13795 memory_order_relaxed));
13796 json_object_int_add(json_stat, "keepalivesRecv",
13797 atomic_load_explicit(&p->keepalive_in,
13798 memory_order_relaxed));
13799 json_object_int_add(json_stat, "routeRefreshSent",
13800 atomic_load_explicit(&p->refresh_out,
13801 memory_order_relaxed));
13802 json_object_int_add(json_stat, "routeRefreshRecv",
13803 atomic_load_explicit(&p->refresh_in,
13804 memory_order_relaxed));
13805 json_object_int_add(json_stat, "capabilitySent",
13806 atomic_load_explicit(&p->dynamic_cap_out,
13807 memory_order_relaxed));
13808 json_object_int_add(json_stat, "capabilityRecv",
13809 atomic_load_explicit(&p->dynamic_cap_in,
13810 memory_order_relaxed));
13811 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
13812 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
13813 json_object_object_add(json_neigh, "messageStats", json_stat);
13814 } else {
13815 atomic_size_t outq_count, inq_count;
13816 outq_count = atomic_load_explicit(&p->obuf->count,
13817 memory_order_relaxed);
13818 inq_count = atomic_load_explicit(&p->ibuf->count,
13819 memory_order_relaxed);
13820
13821 /* Packet counts. */
13822 vty_out(vty, " Message statistics:\n");
13823 vty_out(vty, " Inq depth is %zu\n", inq_count);
13824 vty_out(vty, " Outq depth is %zu\n", outq_count);
13825 vty_out(vty, " Sent Rcvd\n");
13826 vty_out(vty, " Opens: %10d %10d\n",
13827 atomic_load_explicit(&p->open_out,
13828 memory_order_relaxed),
13829 atomic_load_explicit(&p->open_in,
13830 memory_order_relaxed));
13831 vty_out(vty, " Notifications: %10d %10d\n",
13832 atomic_load_explicit(&p->notify_out,
13833 memory_order_relaxed),
13834 atomic_load_explicit(&p->notify_in,
13835 memory_order_relaxed));
13836 vty_out(vty, " Updates: %10d %10d\n",
13837 atomic_load_explicit(&p->update_out,
13838 memory_order_relaxed),
13839 atomic_load_explicit(&p->update_in,
13840 memory_order_relaxed));
13841 vty_out(vty, " Keepalives: %10d %10d\n",
13842 atomic_load_explicit(&p->keepalive_out,
13843 memory_order_relaxed),
13844 atomic_load_explicit(&p->keepalive_in,
13845 memory_order_relaxed));
13846 vty_out(vty, " Route Refresh: %10d %10d\n",
13847 atomic_load_explicit(&p->refresh_out,
13848 memory_order_relaxed),
13849 atomic_load_explicit(&p->refresh_in,
13850 memory_order_relaxed));
13851 vty_out(vty, " Capability: %10d %10d\n",
13852 atomic_load_explicit(&p->dynamic_cap_out,
13853 memory_order_relaxed),
13854 atomic_load_explicit(&p->dynamic_cap_in,
13855 memory_order_relaxed));
13856 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
13857 PEER_TOTAL_RX(p));
13858 }
13859
13860 if (use_json) {
13861 /* advertisement-interval */
13862 json_object_int_add(json_neigh,
13863 "minBtwnAdvertisementRunsTimerMsecs",
13864 p->v_routeadv * 1000);
13865
13866 /* Update-source. */
13867 if (p->update_if || p->update_source) {
13868 if (p->update_if)
13869 json_object_string_add(json_neigh,
13870 "updateSource",
13871 p->update_if);
13872 else if (p->update_source)
13873 json_object_string_add(
13874 json_neigh, "updateSource",
13875 sockunion2str(p->update_source, buf1,
13876 SU_ADDRSTRLEN));
13877 }
13878 } else {
13879 /* advertisement-interval */
13880 vty_out(vty,
13881 " Minimum time between advertisement runs is %d seconds\n",
13882 p->v_routeadv);
13883
13884 /* Update-source. */
13885 if (p->update_if || p->update_source) {
13886 vty_out(vty, " Update source is ");
13887 if (p->update_if)
13888 vty_out(vty, "%s", p->update_if);
13889 else if (p->update_source)
13890 vty_out(vty, "%s",
13891 sockunion2str(p->update_source, buf1,
13892 SU_ADDRSTRLEN));
13893 vty_out(vty, "\n");
13894 }
13895
13896 vty_out(vty, "\n");
13897 }
13898
13899 /* Address Family Information */
13900 json_object *json_hold = NULL;
13901
13902 if (use_json)
13903 json_hold = json_object_new_object();
13904
13905 FOREACH_AFI_SAFI (afi, safi)
13906 if (p->afc[afi][safi])
13907 bgp_show_peer_afi(vty, p, afi, safi, use_json,
13908 json_hold);
13909
13910 if (use_json) {
13911 json_object_object_add(json_neigh, "addressFamilyInfo",
13912 json_hold);
13913 json_object_int_add(json_neigh, "connectionsEstablished",
13914 p->established);
13915 json_object_int_add(json_neigh, "connectionsDropped",
13916 p->dropped);
13917 } else
13918 vty_out(vty, " Connections established %d; dropped %d\n",
13919 p->established, p->dropped);
13920
13921 if (!p->last_reset) {
13922 if (use_json)
13923 json_object_string_add(json_neigh, "lastReset",
13924 "never");
13925 else
13926 vty_out(vty, " Last reset never\n");
13927 } else {
13928 if (use_json) {
13929 time_t uptime;
13930 struct tm tm;
13931
13932 uptime = bgp_clock();
13933 uptime -= p->resettime;
13934 gmtime_r(&uptime, &tm);
13935
13936 json_object_int_add(json_neigh, "lastResetTimerMsecs",
13937 (tm.tm_sec * 1000)
13938 + (tm.tm_min * 60000)
13939 + (tm.tm_hour * 3600000));
13940 bgp_show_peer_reset(NULL, p, json_neigh, true);
13941 } else {
13942 vty_out(vty, " Last reset %s, ",
13943 peer_uptime(p->resettime, timebuf,
13944 BGP_UPTIME_LEN, 0, NULL));
13945
13946 bgp_show_peer_reset(vty, p, NULL, false);
13947 if (p->last_reset_cause_size) {
13948 msg = p->last_reset_cause;
13949 vty_out(vty,
13950 " Message received that caused BGP to send a NOTIFICATION:\n ");
13951 for (i = 1; i <= p->last_reset_cause_size;
13952 i++) {
13953 vty_out(vty, "%02X", *msg++);
13954
13955 if (i != p->last_reset_cause_size) {
13956 if (i % 16 == 0) {
13957 vty_out(vty, "\n ");
13958 } else if (i % 4 == 0) {
13959 vty_out(vty, " ");
13960 }
13961 }
13962 }
13963 vty_out(vty, "\n");
13964 }
13965 }
13966 }
13967
13968 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
13969 if (use_json)
13970 json_object_boolean_true_add(json_neigh,
13971 "prefixesConfigExceedMax");
13972 else
13973 vty_out(vty,
13974 " Peer had exceeded the max. no. of prefixes configured.\n");
13975
13976 if (p->t_pmax_restart) {
13977 if (use_json) {
13978 json_object_boolean_true_add(
13979 json_neigh, "reducePrefixNumFrom");
13980 json_object_int_add(json_neigh,
13981 "restartInTimerMsec",
13982 thread_timer_remain_second(
13983 p->t_pmax_restart)
13984 * 1000);
13985 } else
13986 vty_out(vty,
13987 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
13988 p->host, thread_timer_remain_second(
13989 p->t_pmax_restart));
13990 } else {
13991 if (use_json)
13992 json_object_boolean_true_add(
13993 json_neigh,
13994 "reducePrefixNumAndClearIpBgp");
13995 else
13996 vty_out(vty,
13997 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
13998 p->host);
13999 }
14000 }
14001
14002 /* EBGP Multihop and GTSM */
14003 if (p->sort != BGP_PEER_IBGP) {
14004 if (use_json) {
14005 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14006 json_object_int_add(json_neigh,
14007 "externalBgpNbrMaxHopsAway",
14008 p->gtsm_hops);
14009 else if (p->ttl > BGP_DEFAULT_TTL)
14010 json_object_int_add(json_neigh,
14011 "externalBgpNbrMaxHopsAway",
14012 p->ttl);
14013 } else {
14014 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14015 vty_out(vty,
14016 " External BGP neighbor may be up to %d hops away.\n",
14017 p->gtsm_hops);
14018 else if (p->ttl > BGP_DEFAULT_TTL)
14019 vty_out(vty,
14020 " External BGP neighbor may be up to %d hops away.\n",
14021 p->ttl);
14022 }
14023 } else {
14024 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED) {
14025 if (use_json)
14026 json_object_int_add(json_neigh,
14027 "internalBgpNbrMaxHopsAway",
14028 p->gtsm_hops);
14029 else
14030 vty_out(vty,
14031 " Internal BGP neighbor may be up to %d hops away.\n",
14032 p->gtsm_hops);
14033 }
14034 }
14035
14036 /* Local address. */
14037 if (p->su_local) {
14038 if (use_json) {
14039 json_object_string_add(json_neigh, "hostLocal",
14040 sockunion2str(p->su_local, buf1,
14041 SU_ADDRSTRLEN));
14042 json_object_int_add(json_neigh, "portLocal",
14043 ntohs(p->su_local->sin.sin_port));
14044 } else
14045 vty_out(vty, "Local host: %s, Local port: %d\n",
14046 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
14047 ntohs(p->su_local->sin.sin_port));
14048 }
14049
14050 /* Remote address. */
14051 if (p->su_remote) {
14052 if (use_json) {
14053 json_object_string_add(json_neigh, "hostForeign",
14054 sockunion2str(p->su_remote, buf1,
14055 SU_ADDRSTRLEN));
14056 json_object_int_add(json_neigh, "portForeign",
14057 ntohs(p->su_remote->sin.sin_port));
14058 } else
14059 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
14060 sockunion2str(p->su_remote, buf1,
14061 SU_ADDRSTRLEN),
14062 ntohs(p->su_remote->sin.sin_port));
14063 }
14064
14065 /* Nexthop display. */
14066 if (p->su_local) {
14067 if (use_json) {
14068 json_object_string_add(json_neigh, "nexthop",
14069 inet_ntop(AF_INET,
14070 &p->nexthop.v4, buf1,
14071 sizeof(buf1)));
14072 json_object_string_add(json_neigh, "nexthopGlobal",
14073 inet_ntop(AF_INET6,
14074 &p->nexthop.v6_global,
14075 buf1, sizeof(buf1)));
14076 json_object_string_add(json_neigh, "nexthopLocal",
14077 inet_ntop(AF_INET6,
14078 &p->nexthop.v6_local,
14079 buf1, sizeof(buf1)));
14080 if (p->shared_network)
14081 json_object_string_add(json_neigh,
14082 "bgpConnection",
14083 "sharedNetwork");
14084 else
14085 json_object_string_add(json_neigh,
14086 "bgpConnection",
14087 "nonSharedNetwork");
14088 } else {
14089 vty_out(vty, "Nexthop: %s\n",
14090 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
14091 sizeof(buf1)));
14092 vty_out(vty, "Nexthop global: %s\n",
14093 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
14094 sizeof(buf1)));
14095 vty_out(vty, "Nexthop local: %s\n",
14096 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
14097 sizeof(buf1)));
14098 vty_out(vty, "BGP connection: %s\n",
14099 p->shared_network ? "shared network"
14100 : "non shared network");
14101 }
14102 }
14103
14104 /* Timer information. */
14105 if (use_json) {
14106 json_object_int_add(json_neigh, "connectRetryTimer",
14107 p->v_connect);
14108 if (p->status == Established && p->rtt)
14109 json_object_int_add(json_neigh, "estimatedRttInMsecs",
14110 p->rtt);
14111 if (p->t_start)
14112 json_object_int_add(
14113 json_neigh, "nextStartTimerDueInMsecs",
14114 thread_timer_remain_second(p->t_start) * 1000);
14115 if (p->t_connect)
14116 json_object_int_add(
14117 json_neigh, "nextConnectTimerDueInMsecs",
14118 thread_timer_remain_second(p->t_connect)
14119 * 1000);
14120 if (p->t_routeadv) {
14121 json_object_int_add(json_neigh, "mraiInterval",
14122 p->v_routeadv);
14123 json_object_int_add(
14124 json_neigh, "mraiTimerExpireInMsecs",
14125 thread_timer_remain_second(p->t_routeadv)
14126 * 1000);
14127 }
14128 if (p->password)
14129 json_object_int_add(json_neigh, "authenticationEnabled",
14130 1);
14131
14132 if (p->t_read)
14133 json_object_string_add(json_neigh, "readThread", "on");
14134 else
14135 json_object_string_add(json_neigh, "readThread", "off");
14136
14137 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
14138 json_object_string_add(json_neigh, "writeThread", "on");
14139 else
14140 json_object_string_add(json_neigh, "writeThread",
14141 "off");
14142 } else {
14143 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
14144 p->v_connect);
14145 if (p->status == Established && p->rtt)
14146 vty_out(vty, "Estimated round trip time: %d ms\n",
14147 p->rtt);
14148 if (p->t_start)
14149 vty_out(vty, "Next start timer due in %ld seconds\n",
14150 thread_timer_remain_second(p->t_start));
14151 if (p->t_connect)
14152 vty_out(vty, "Next connect timer due in %ld seconds\n",
14153 thread_timer_remain_second(p->t_connect));
14154 if (p->t_routeadv)
14155 vty_out(vty,
14156 "MRAI (interval %u) timer expires in %ld seconds\n",
14157 p->v_routeadv,
14158 thread_timer_remain_second(p->t_routeadv));
14159 if (p->password)
14160 vty_out(vty, "Peer Authentication Enabled\n");
14161
14162 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
14163 p->t_read ? "on" : "off",
14164 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
14165 ? "on"
14166 : "off", p->fd);
14167 }
14168
14169 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
14170 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
14171 bgp_capability_vty_out(vty, p, use_json, json_neigh);
14172
14173 if (!use_json)
14174 vty_out(vty, "\n");
14175
14176 /* BFD information. */
14177 bgp_bfd_show_info(vty, p, use_json, json_neigh);
14178
14179 if (use_json) {
14180 if (p->conf_if) /* Configured interface name. */
14181 json_object_object_add(json, p->conf_if, json_neigh);
14182 else /* Configured IP address. */
14183 json_object_object_add(json, p->host, json_neigh);
14184 }
14185 }
14186
14187 static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
14188 enum show_type type,
14189 union sockunion *su,
14190 const char *conf_if, afi_t afi,
14191 bool use_json)
14192 {
14193 struct listnode *node, *nnode;
14194 struct peer *peer;
14195 int find = 0;
14196 safi_t safi = SAFI_UNICAST;
14197 json_object *json = NULL;
14198 json_object *json_neighbor = NULL;
14199
14200 if (use_json) {
14201 json = json_object_new_object();
14202 json_neighbor = json_object_new_object();
14203 }
14204
14205 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14206
14207 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14208 continue;
14209
14210 if ((peer->afc[afi][safi]) == 0)
14211 continue;
14212
14213 if (type == show_all) {
14214 bgp_show_peer_gr_status(vty, peer, use_json,
14215 json_neighbor);
14216
14217 if (use_json) {
14218 json_object_object_add(json, peer->host,
14219 json_neighbor);
14220 json_neighbor = NULL;
14221 }
14222
14223 } else if (type == show_peer) {
14224 if (conf_if) {
14225 if ((peer->conf_if
14226 && !strcmp(peer->conf_if, conf_if))
14227 || (peer->hostname
14228 && !strcmp(peer->hostname, conf_if))) {
14229 find = 1;
14230 bgp_show_peer_gr_status(vty, peer,
14231 use_json,
14232 json_neighbor);
14233 }
14234 } else {
14235 if (sockunion_same(&peer->su, su)) {
14236 find = 1;
14237 bgp_show_peer_gr_status(vty, peer,
14238 use_json,
14239 json_neighbor);
14240 }
14241 }
14242 if (use_json && find)
14243 json_object_object_add(json, peer->host,
14244 json_neighbor);
14245 }
14246
14247 if (find) {
14248 json_neighbor = NULL;
14249 break;
14250 }
14251 }
14252
14253 if (type == show_peer && !find) {
14254 if (use_json)
14255 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14256 else
14257 vty_out(vty, "%% No such neighbor\n");
14258 }
14259 if (use_json) {
14260 vty_out(vty, "%s\n",
14261 json_object_to_json_string_ext(
14262 json, JSON_C_TO_STRING_PRETTY));
14263
14264 if (json_neighbor)
14265 json_object_free(json_neighbor);
14266 json_object_free(json);
14267 } else {
14268 vty_out(vty, "\n");
14269 }
14270
14271 return CMD_SUCCESS;
14272 }
14273
14274 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
14275 enum show_type type, union sockunion *su,
14276 const char *conf_if, bool use_json,
14277 json_object *json)
14278 {
14279 struct listnode *node, *nnode;
14280 struct peer *peer;
14281 int find = 0;
14282 bool nbr_output = false;
14283 afi_t afi = AFI_MAX;
14284 safi_t safi = SAFI_MAX;
14285
14286 if (type == show_ipv4_peer || type == show_ipv4_all) {
14287 afi = AFI_IP;
14288 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
14289 afi = AFI_IP6;
14290 }
14291
14292 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14293 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14294 continue;
14295
14296 switch (type) {
14297 case show_all:
14298 bgp_show_peer(vty, peer, use_json, json);
14299 nbr_output = true;
14300 break;
14301 case show_peer:
14302 if (conf_if) {
14303 if ((peer->conf_if
14304 && !strcmp(peer->conf_if, conf_if))
14305 || (peer->hostname
14306 && !strcmp(peer->hostname, conf_if))) {
14307 find = 1;
14308 bgp_show_peer(vty, peer, use_json,
14309 json);
14310 }
14311 } else {
14312 if (sockunion_same(&peer->su, su)) {
14313 find = 1;
14314 bgp_show_peer(vty, peer, use_json,
14315 json);
14316 }
14317 }
14318 break;
14319 case show_ipv4_peer:
14320 case show_ipv6_peer:
14321 FOREACH_SAFI (safi) {
14322 if (peer->afc[afi][safi]) {
14323 if (conf_if) {
14324 if ((peer->conf_if
14325 && !strcmp(peer->conf_if, conf_if))
14326 || (peer->hostname
14327 && !strcmp(peer->hostname, conf_if))) {
14328 find = 1;
14329 bgp_show_peer(vty, peer, use_json,
14330 json);
14331 break;
14332 }
14333 } else {
14334 if (sockunion_same(&peer->su, su)) {
14335 find = 1;
14336 bgp_show_peer(vty, peer, use_json,
14337 json);
14338 break;
14339 }
14340 }
14341 }
14342 }
14343 break;
14344 case show_ipv4_all:
14345 case show_ipv6_all:
14346 FOREACH_SAFI (safi) {
14347 if (peer->afc[afi][safi]) {
14348 bgp_show_peer(vty, peer, use_json, json);
14349 nbr_output = true;
14350 break;
14351 }
14352 }
14353 break;
14354 }
14355 }
14356
14357 if ((type == show_peer || type == show_ipv4_peer ||
14358 type == show_ipv6_peer) && !find) {
14359 if (use_json)
14360 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14361 else
14362 vty_out(vty, "%% No such neighbor in this view/vrf\n");
14363 }
14364
14365 if (type != show_peer && type != show_ipv4_peer &&
14366 type != show_ipv6_peer && !nbr_output && !use_json)
14367 vty_out(vty, "%% No BGP neighbors found\n");
14368
14369 if (use_json) {
14370 vty_out(vty, "%s\n", json_object_to_json_string_ext(
14371 json, JSON_C_TO_STRING_PRETTY));
14372 } else {
14373 vty_out(vty, "\n");
14374 }
14375
14376 return CMD_SUCCESS;
14377 }
14378
14379 static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
14380 enum show_type type,
14381 const char *ip_str,
14382 afi_t afi, bool use_json)
14383 {
14384
14385 int ret;
14386 struct bgp *bgp;
14387 union sockunion su;
14388
14389 bgp = bgp_get_default();
14390
14391 if (!bgp)
14392 return;
14393
14394 if (!use_json)
14395 bgp_show_global_graceful_restart_mode_vty(vty, bgp, use_json,
14396 NULL);
14397
14398 if (ip_str) {
14399 ret = str2sockunion(ip_str, &su);
14400 if (ret < 0)
14401 bgp_show_neighbor_graceful_restart(
14402 vty, bgp, type, NULL, ip_str, afi, use_json);
14403 else
14404 bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
14405 NULL, afi, use_json);
14406 } else
14407 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
14408 afi, use_json);
14409 }
14410
14411 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
14412 enum show_type type,
14413 const char *ip_str,
14414 bool use_json)
14415 {
14416 struct listnode *node, *nnode;
14417 struct bgp *bgp;
14418 union sockunion su;
14419 json_object *json = NULL;
14420 int ret, is_first = 1;
14421 bool nbr_output = false;
14422
14423 if (use_json)
14424 vty_out(vty, "{\n");
14425
14426 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
14427 nbr_output = true;
14428 if (use_json) {
14429 if (!(json = json_object_new_object())) {
14430 flog_err(
14431 EC_BGP_JSON_MEM_ERROR,
14432 "Unable to allocate memory for JSON object");
14433 vty_out(vty,
14434 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
14435 return;
14436 }
14437
14438 json_object_int_add(json, "vrfId",
14439 (bgp->vrf_id == VRF_UNKNOWN)
14440 ? -1
14441 : (int64_t)bgp->vrf_id);
14442 json_object_string_add(
14443 json, "vrfName",
14444 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14445 ? VRF_DEFAULT_NAME
14446 : bgp->name);
14447
14448 if (!is_first)
14449 vty_out(vty, ",\n");
14450 else
14451 is_first = 0;
14452
14453 vty_out(vty, "\"%s\":",
14454 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14455 ? VRF_DEFAULT_NAME
14456 : bgp->name);
14457 } else {
14458 vty_out(vty, "\nInstance %s:\n",
14459 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14460 ? VRF_DEFAULT_NAME
14461 : bgp->name);
14462 }
14463
14464 if (type == show_peer || type == show_ipv4_peer ||
14465 type == show_ipv6_peer) {
14466 ret = str2sockunion(ip_str, &su);
14467 if (ret < 0)
14468 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14469 use_json, json);
14470 else
14471 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14472 use_json, json);
14473 } else {
14474 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
14475 use_json, json);
14476 }
14477 json_object_free(json);
14478 json = NULL;
14479 }
14480
14481 if (use_json)
14482 vty_out(vty, "}\n");
14483 else if (!nbr_output)
14484 vty_out(vty, "%% BGP instance not found\n");
14485 }
14486
14487 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
14488 enum show_type type, const char *ip_str,
14489 bool use_json)
14490 {
14491 int ret;
14492 struct bgp *bgp;
14493 union sockunion su;
14494 json_object *json = NULL;
14495
14496 if (name) {
14497 if (strmatch(name, "all")) {
14498 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
14499 use_json);
14500 return CMD_SUCCESS;
14501 } else {
14502 bgp = bgp_lookup_by_name(name);
14503 if (!bgp) {
14504 if (use_json) {
14505 json = json_object_new_object();
14506 vty_out(vty, "%s\n",
14507 json_object_to_json_string_ext(
14508 json,
14509 JSON_C_TO_STRING_PRETTY));
14510 json_object_free(json);
14511 } else
14512 vty_out(vty,
14513 "%% BGP instance not found\n");
14514
14515 return CMD_WARNING;
14516 }
14517 }
14518 } else {
14519 bgp = bgp_get_default();
14520 }
14521
14522 if (bgp) {
14523 json = json_object_new_object();
14524 if (ip_str) {
14525 ret = str2sockunion(ip_str, &su);
14526 if (ret < 0)
14527 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14528 use_json, json);
14529 else
14530 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14531 use_json, json);
14532 } else {
14533 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
14534 json);
14535 }
14536 json_object_free(json);
14537 } else {
14538 if (use_json)
14539 vty_out(vty, "{}\n");
14540 else
14541 vty_out(vty, "%% BGP instance not found\n");
14542 }
14543
14544 return CMD_SUCCESS;
14545 }
14546
14547
14548
14549 /* "show [ip] bgp neighbors graceful-restart" commands. */
14550 DEFUN (show_ip_bgp_neighbors_gracrful_restart,
14551 show_ip_bgp_neighbors_graceful_restart_cmd,
14552 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
14553 SHOW_STR
14554 BGP_STR
14555 IP_STR
14556 IPV6_STR
14557 NEIGHBOR_STR
14558 "Neighbor to display information about\n"
14559 "Neighbor to display information about\n"
14560 "Neighbor on BGP configured interface\n"
14561 GR_SHOW
14562 JSON_STR)
14563 {
14564 char *sh_arg = NULL;
14565 enum show_type sh_type;
14566 int idx = 0;
14567 afi_t afi = AFI_MAX;
14568 bool uj = use_json(argc, argv);
14569
14570 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
14571 afi = AFI_MAX;
14572
14573 idx++;
14574
14575 if (argv_find(argv, argc, "A.B.C.D", &idx)
14576 || argv_find(argv, argc, "X:X::X:X", &idx)
14577 || argv_find(argv, argc, "WORD", &idx)) {
14578 sh_type = show_peer;
14579 sh_arg = argv[idx]->arg;
14580 } else
14581 sh_type = show_all;
14582
14583 if (!argv_find(argv, argc, "graceful-restart", &idx))
14584 return CMD_SUCCESS;
14585
14586
14587 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
14588 afi, uj);
14589 }
14590
14591 /* "show [ip] bgp neighbors" commands. */
14592 DEFUN (show_ip_bgp_neighbors,
14593 show_ip_bgp_neighbors_cmd,
14594 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
14595 SHOW_STR
14596 IP_STR
14597 BGP_STR
14598 BGP_INSTANCE_HELP_STR
14599 "Address Family\n"
14600 "Address Family\n"
14601 "Detailed information on TCP and BGP neighbor connections\n"
14602 "Neighbor to display information about\n"
14603 "Neighbor to display information about\n"
14604 "Neighbor on BGP configured interface\n"
14605 JSON_STR)
14606 {
14607 char *vrf = NULL;
14608 char *sh_arg = NULL;
14609 enum show_type sh_type;
14610 afi_t afi = AFI_MAX;
14611
14612 bool uj = use_json(argc, argv);
14613
14614 int idx = 0;
14615
14616 /* [<vrf> VIEWVRFNAME] */
14617 if (argv_find(argv, argc, "vrf", &idx)) {
14618 vrf = argv[idx + 1]->arg;
14619 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
14620 vrf = NULL;
14621 } else if (argv_find(argv, argc, "view", &idx))
14622 /* [<view> VIEWVRFNAME] */
14623 vrf = argv[idx + 1]->arg;
14624
14625 idx++;
14626
14627 if (argv_find(argv, argc, "ipv4", &idx)) {
14628 sh_type = show_ipv4_all;
14629 afi = AFI_IP;
14630 } else if (argv_find(argv, argc, "ipv6", &idx)) {
14631 sh_type = show_ipv6_all;
14632 afi = AFI_IP6;
14633 } else {
14634 sh_type = show_all;
14635 }
14636
14637 if (argv_find(argv, argc, "A.B.C.D", &idx)
14638 || argv_find(argv, argc, "X:X::X:X", &idx)
14639 || argv_find(argv, argc, "WORD", &idx)) {
14640 sh_type = show_peer;
14641 sh_arg = argv[idx]->arg;
14642 }
14643
14644 if (sh_type == show_peer && afi == AFI_IP) {
14645 sh_type = show_ipv4_peer;
14646 } else if (sh_type == show_peer && afi == AFI_IP6) {
14647 sh_type = show_ipv6_peer;
14648 }
14649
14650 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
14651 }
14652
14653 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
14654 paths' and `show ip mbgp paths'. Those functions results are the
14655 same.*/
14656 DEFUN (show_ip_bgp_paths,
14657 show_ip_bgp_paths_cmd,
14658 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
14659 SHOW_STR
14660 IP_STR
14661 BGP_STR
14662 BGP_SAFI_HELP_STR
14663 "Path information\n")
14664 {
14665 vty_out(vty, "Address Refcnt Path\n");
14666 aspath_print_all_vty(vty);
14667 return CMD_SUCCESS;
14668 }
14669
14670 #include "hash.h"
14671
14672 static void community_show_all_iterator(struct hash_bucket *bucket,
14673 struct vty *vty)
14674 {
14675 struct community *com;
14676
14677 com = (struct community *)bucket->data;
14678 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
14679 community_str(com, false));
14680 }
14681
14682 /* Show BGP's community internal data. */
14683 DEFUN (show_ip_bgp_community_info,
14684 show_ip_bgp_community_info_cmd,
14685 "show [ip] bgp community-info",
14686 SHOW_STR
14687 IP_STR
14688 BGP_STR
14689 "List all bgp community information\n")
14690 {
14691 vty_out(vty, "Address Refcnt Community\n");
14692
14693 hash_iterate(community_hash(),
14694 (void (*)(struct hash_bucket *,
14695 void *))community_show_all_iterator,
14696 vty);
14697
14698 return CMD_SUCCESS;
14699 }
14700
14701 static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
14702 struct vty *vty)
14703 {
14704 struct lcommunity *lcom;
14705
14706 lcom = (struct lcommunity *)bucket->data;
14707 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
14708 lcommunity_str(lcom, false));
14709 }
14710
14711 /* Show BGP's community internal data. */
14712 DEFUN (show_ip_bgp_lcommunity_info,
14713 show_ip_bgp_lcommunity_info_cmd,
14714 "show ip bgp large-community-info",
14715 SHOW_STR
14716 IP_STR
14717 BGP_STR
14718 "List all bgp large-community information\n")
14719 {
14720 vty_out(vty, "Address Refcnt Large-community\n");
14721
14722 hash_iterate(lcommunity_hash(),
14723 (void (*)(struct hash_bucket *,
14724 void *))lcommunity_show_all_iterator,
14725 vty);
14726
14727 return CMD_SUCCESS;
14728 }
14729 /* Graceful Restart */
14730
14731 static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
14732 struct bgp *bgp,
14733 bool use_json,
14734 json_object *json)
14735 {
14736
14737
14738 vty_out(vty, "\n%s", SHOW_GR_HEADER);
14739
14740 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
14741
14742 switch (bgp_global_gr_mode) {
14743
14744 case GLOBAL_HELPER:
14745 vty_out(vty, "Global BGP GR Mode : Helper\n");
14746 break;
14747
14748 case GLOBAL_GR:
14749 vty_out(vty, "Global BGP GR Mode : Restart\n");
14750 break;
14751
14752 case GLOBAL_DISABLE:
14753 vty_out(vty, "Global BGP GR Mode : Disable\n");
14754 break;
14755
14756 case GLOBAL_INVALID:
14757 vty_out(vty,
14758 "Global BGP GR Mode Invalid\n");
14759 break;
14760 }
14761 vty_out(vty, "\n");
14762 }
14763
14764 static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
14765 enum show_type type,
14766 const char *ip_str,
14767 afi_t afi, bool use_json)
14768 {
14769 if ((afi == AFI_MAX) && (ip_str == NULL)) {
14770 afi = AFI_IP;
14771
14772 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
14773
14774 bgp_show_neighbor_graceful_restart_vty(
14775 vty, type, ip_str, afi, use_json);
14776 afi++;
14777 }
14778 } else if (afi != AFI_MAX) {
14779 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
14780 use_json);
14781 } else {
14782 return CMD_ERR_INCOMPLETE;
14783 }
14784
14785 return CMD_SUCCESS;
14786 }
14787 /* Graceful Restart */
14788
14789 DEFUN (show_ip_bgp_attr_info,
14790 show_ip_bgp_attr_info_cmd,
14791 "show [ip] bgp attribute-info",
14792 SHOW_STR
14793 IP_STR
14794 BGP_STR
14795 "List all bgp attribute information\n")
14796 {
14797 attr_show_all(vty);
14798 return CMD_SUCCESS;
14799 }
14800
14801 static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
14802 afi_t afi, safi_t safi,
14803 bool use_json, json_object *json)
14804 {
14805 struct bgp *bgp;
14806 struct listnode *node;
14807 char *vname;
14808 char buf1[INET6_ADDRSTRLEN];
14809 char *ecom_str;
14810 vpn_policy_direction_t dir;
14811
14812 if (json) {
14813 json_object *json_import_vrfs = NULL;
14814 json_object *json_export_vrfs = NULL;
14815
14816 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
14817
14818 if (!bgp) {
14819 vty_out(vty, "%s\n",
14820 json_object_to_json_string_ext(
14821 json,
14822 JSON_C_TO_STRING_PRETTY));
14823 json_object_free(json);
14824
14825 return CMD_WARNING;
14826 }
14827
14828 /* Provide context for the block */
14829 json_object_string_add(json, "vrf", name ? name : "default");
14830 json_object_string_add(json, "afiSafi",
14831 get_afi_safi_str(afi, safi, true));
14832
14833 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14834 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
14835 json_object_string_add(json, "importFromVrfs", "none");
14836 json_object_string_add(json, "importRts", "none");
14837 } else {
14838 json_import_vrfs = json_object_new_array();
14839
14840 for (ALL_LIST_ELEMENTS_RO(
14841 bgp->vpn_policy[afi].import_vrf,
14842 node, vname))
14843 json_object_array_add(json_import_vrfs,
14844 json_object_new_string(vname));
14845
14846 json_object_object_add(json, "importFromVrfs",
14847 json_import_vrfs);
14848 dir = BGP_VPN_POLICY_DIR_FROMVPN;
14849 if (bgp->vpn_policy[afi].rtlist[dir]) {
14850 ecom_str = ecommunity_ecom2str(
14851 bgp->vpn_policy[afi].rtlist[dir],
14852 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
14853 json_object_string_add(json, "importRts",
14854 ecom_str);
14855 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14856 } else
14857 json_object_string_add(json, "importRts",
14858 "none");
14859 }
14860
14861 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14862 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
14863 json_object_string_add(json, "exportToVrfs", "none");
14864 json_object_string_add(json, "routeDistinguisher",
14865 "none");
14866 json_object_string_add(json, "exportRts", "none");
14867 } else {
14868 json_export_vrfs = json_object_new_array();
14869
14870 for (ALL_LIST_ELEMENTS_RO(
14871 bgp->vpn_policy[afi].export_vrf,
14872 node, vname))
14873 json_object_array_add(json_export_vrfs,
14874 json_object_new_string(vname));
14875 json_object_object_add(json, "exportToVrfs",
14876 json_export_vrfs);
14877 json_object_string_add(json, "routeDistinguisher",
14878 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
14879 buf1, RD_ADDRSTRLEN));
14880
14881 dir = BGP_VPN_POLICY_DIR_TOVPN;
14882 if (bgp->vpn_policy[afi].rtlist[dir]) {
14883 ecom_str = ecommunity_ecom2str(
14884 bgp->vpn_policy[afi].rtlist[dir],
14885 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
14886 json_object_string_add(json, "exportRts",
14887 ecom_str);
14888 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14889 } else
14890 json_object_string_add(json, "exportRts",
14891 "none");
14892 }
14893
14894 if (use_json) {
14895 vty_out(vty, "%s\n",
14896 json_object_to_json_string_ext(json,
14897 JSON_C_TO_STRING_PRETTY));
14898 json_object_free(json);
14899 }
14900 } else {
14901 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
14902
14903 if (!bgp) {
14904 vty_out(vty, "%% No such BGP instance exist\n");
14905 return CMD_WARNING;
14906 }
14907
14908 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14909 BGP_CONFIG_VRF_TO_VRF_IMPORT))
14910 vty_out(vty,
14911 "This VRF is not importing %s routes from any other VRF\n",
14912 get_afi_safi_str(afi, safi, false));
14913 else {
14914 vty_out(vty,
14915 "This VRF is importing %s routes from the following VRFs:\n",
14916 get_afi_safi_str(afi, safi, false));
14917
14918 for (ALL_LIST_ELEMENTS_RO(
14919 bgp->vpn_policy[afi].import_vrf,
14920 node, vname))
14921 vty_out(vty, " %s\n", vname);
14922
14923 dir = BGP_VPN_POLICY_DIR_FROMVPN;
14924 ecom_str = NULL;
14925 if (bgp->vpn_policy[afi].rtlist[dir]) {
14926 ecom_str = ecommunity_ecom2str(
14927 bgp->vpn_policy[afi].rtlist[dir],
14928 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
14929 vty_out(vty, "Import RT(s): %s\n", ecom_str);
14930
14931 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14932 } else
14933 vty_out(vty, "Import RT(s):\n");
14934 }
14935
14936 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14937 BGP_CONFIG_VRF_TO_VRF_EXPORT))
14938 vty_out(vty,
14939 "This VRF is not exporting %s routes to any other VRF\n",
14940 get_afi_safi_str(afi, safi, false));
14941 else {
14942 vty_out(vty,
14943 "This VRF is exporting %s routes to the following VRFs:\n",
14944 get_afi_safi_str(afi, safi, false));
14945
14946 for (ALL_LIST_ELEMENTS_RO(
14947 bgp->vpn_policy[afi].export_vrf,
14948 node, vname))
14949 vty_out(vty, " %s\n", vname);
14950
14951 vty_out(vty, "RD: %s\n",
14952 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
14953 buf1, RD_ADDRSTRLEN));
14954
14955 dir = BGP_VPN_POLICY_DIR_TOVPN;
14956 if (bgp->vpn_policy[afi].rtlist[dir]) {
14957 ecom_str = ecommunity_ecom2str(
14958 bgp->vpn_policy[afi].rtlist[dir],
14959 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
14960 vty_out(vty, "Export RT: %s\n", ecom_str);
14961 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14962 } else
14963 vty_out(vty, "Import RT(s):\n");
14964 }
14965 }
14966
14967 return CMD_SUCCESS;
14968 }
14969
14970 static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
14971 safi_t safi, bool use_json)
14972 {
14973 struct listnode *node, *nnode;
14974 struct bgp *bgp;
14975 char *vrf_name = NULL;
14976 json_object *json = NULL;
14977 json_object *json_vrf = NULL;
14978 json_object *json_vrfs = NULL;
14979
14980 if (use_json) {
14981 json = json_object_new_object();
14982 json_vrfs = json_object_new_object();
14983 }
14984
14985 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
14986
14987 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
14988 vrf_name = bgp->name;
14989
14990 if (use_json) {
14991 json_vrf = json_object_new_object();
14992 } else {
14993 vty_out(vty, "\nInstance %s:\n",
14994 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14995 ? VRF_DEFAULT_NAME : bgp->name);
14996 }
14997 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
14998 if (use_json) {
14999 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15000 json_object_object_add(json_vrfs,
15001 VRF_DEFAULT_NAME, json_vrf);
15002 else
15003 json_object_object_add(json_vrfs, vrf_name,
15004 json_vrf);
15005 }
15006 }
15007
15008 if (use_json) {
15009 json_object_object_add(json, "vrfs", json_vrfs);
15010 vty_out(vty, "%s\n", json_object_to_json_string_ext(json,
15011 JSON_C_TO_STRING_PRETTY));
15012 json_object_free(json);
15013 }
15014
15015 return CMD_SUCCESS;
15016 }
15017
15018 /* "show [ip] bgp route-leak" command. */
15019 DEFUN (show_ip_bgp_route_leak,
15020 show_ip_bgp_route_leak_cmd,
15021 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
15022 SHOW_STR
15023 IP_STR
15024 BGP_STR
15025 BGP_INSTANCE_HELP_STR
15026 BGP_AFI_HELP_STR
15027 BGP_SAFI_HELP_STR
15028 "Route leaking information\n"
15029 JSON_STR)
15030 {
15031 char *vrf = NULL;
15032 afi_t afi = AFI_MAX;
15033 safi_t safi = SAFI_MAX;
15034
15035 bool uj = use_json(argc, argv);
15036 int idx = 0;
15037 json_object *json = NULL;
15038
15039 /* show [ip] bgp */
15040 if (argv_find(argv, argc, "ip", &idx)) {
15041 afi = AFI_IP;
15042 safi = SAFI_UNICAST;
15043 }
15044 /* [vrf VIEWVRFNAME] */
15045 if (argv_find(argv, argc, "view", &idx)) {
15046 vty_out(vty,
15047 "%% This command is not applicable to BGP views\n");
15048 return CMD_WARNING;
15049 }
15050
15051 if (argv_find(argv, argc, "vrf", &idx)) {
15052 vrf = argv[idx + 1]->arg;
15053 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15054 vrf = NULL;
15055 }
15056 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15057 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
15058 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15059 }
15060
15061 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
15062 vty_out(vty,
15063 "%% This command is applicable only for unicast ipv4|ipv6\n");
15064 return CMD_WARNING;
15065 }
15066
15067 if (vrf && strmatch(vrf, "all"))
15068 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
15069
15070 if (uj)
15071 json = json_object_new_object();
15072
15073 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
15074 }
15075
15076 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
15077 safi_t safi)
15078 {
15079 struct listnode *node, *nnode;
15080 struct bgp *bgp;
15081
15082 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15083 vty_out(vty, "\nInstance %s:\n",
15084 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15085 ? VRF_DEFAULT_NAME
15086 : bgp->name);
15087 update_group_show(bgp, afi, safi, vty, 0);
15088 }
15089 }
15090
15091 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
15092 int safi, uint64_t subgrp_id)
15093 {
15094 struct bgp *bgp;
15095
15096 if (name) {
15097 if (strmatch(name, "all")) {
15098 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
15099 return CMD_SUCCESS;
15100 } else {
15101 bgp = bgp_lookup_by_name(name);
15102 }
15103 } else {
15104 bgp = bgp_get_default();
15105 }
15106
15107 if (bgp)
15108 update_group_show(bgp, afi, safi, vty, subgrp_id);
15109 return CMD_SUCCESS;
15110 }
15111
15112 DEFUN (show_ip_bgp_updgrps,
15113 show_ip_bgp_updgrps_cmd,
15114 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
15115 SHOW_STR
15116 IP_STR
15117 BGP_STR
15118 BGP_INSTANCE_HELP_STR
15119 BGP_AFI_HELP_STR
15120 BGP_SAFI_WITH_LABEL_HELP_STR
15121 "Detailed info about dynamic update groups\n"
15122 "Specific subgroup to display detailed info for\n")
15123 {
15124 char *vrf = NULL;
15125 afi_t afi = AFI_IP6;
15126 safi_t safi = SAFI_UNICAST;
15127 uint64_t subgrp_id = 0;
15128
15129 int idx = 0;
15130
15131 /* show [ip] bgp */
15132 if (argv_find(argv, argc, "ip", &idx))
15133 afi = AFI_IP;
15134 /* [<vrf> VIEWVRFNAME] */
15135 if (argv_find(argv, argc, "vrf", &idx)) {
15136 vrf = argv[idx + 1]->arg;
15137 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15138 vrf = NULL;
15139 } else if (argv_find(argv, argc, "view", &idx))
15140 /* [<view> VIEWVRFNAME] */
15141 vrf = argv[idx + 1]->arg;
15142 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15143 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
15144 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15145 }
15146
15147 /* get subgroup id, if provided */
15148 idx = argc - 1;
15149 if (argv[idx]->type == VARIABLE_TKN)
15150 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
15151
15152 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
15153 }
15154
15155 DEFUN (show_bgp_instance_all_ipv6_updgrps,
15156 show_bgp_instance_all_ipv6_updgrps_cmd,
15157 "show [ip] bgp <view|vrf> all update-groups",
15158 SHOW_STR
15159 IP_STR
15160 BGP_STR
15161 BGP_INSTANCE_ALL_HELP_STR
15162 "Detailed info about dynamic update groups\n")
15163 {
15164 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
15165 return CMD_SUCCESS;
15166 }
15167
15168 DEFUN (show_bgp_l2vpn_evpn_updgrps,
15169 show_bgp_l2vpn_evpn_updgrps_cmd,
15170 "show [ip] bgp l2vpn evpn update-groups",
15171 SHOW_STR
15172 IP_STR
15173 BGP_STR
15174 "l2vpn address family\n"
15175 "evpn sub-address family\n"
15176 "Detailed info about dynamic update groups\n")
15177 {
15178 char *vrf = NULL;
15179 uint64_t subgrp_id = 0;
15180
15181 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
15182 return CMD_SUCCESS;
15183 }
15184
15185 DEFUN (show_bgp_updgrps_stats,
15186 show_bgp_updgrps_stats_cmd,
15187 "show [ip] bgp update-groups statistics",
15188 SHOW_STR
15189 IP_STR
15190 BGP_STR
15191 "Detailed info about dynamic update groups\n"
15192 "Statistics\n")
15193 {
15194 struct bgp *bgp;
15195
15196 bgp = bgp_get_default();
15197 if (bgp)
15198 update_group_show_stats(bgp, vty);
15199
15200 return CMD_SUCCESS;
15201 }
15202
15203 DEFUN (show_bgp_instance_updgrps_stats,
15204 show_bgp_instance_updgrps_stats_cmd,
15205 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
15206 SHOW_STR
15207 IP_STR
15208 BGP_STR
15209 BGP_INSTANCE_HELP_STR
15210 "Detailed info about dynamic update groups\n"
15211 "Statistics\n")
15212 {
15213 int idx_word = 3;
15214 struct bgp *bgp;
15215
15216 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
15217 if (bgp)
15218 update_group_show_stats(bgp, vty);
15219
15220 return CMD_SUCCESS;
15221 }
15222
15223 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
15224 afi_t afi, safi_t safi,
15225 const char *what, uint64_t subgrp_id)
15226 {
15227 struct bgp *bgp;
15228
15229 if (name)
15230 bgp = bgp_lookup_by_name(name);
15231 else
15232 bgp = bgp_get_default();
15233
15234 if (bgp) {
15235 if (!strcmp(what, "advertise-queue"))
15236 update_group_show_adj_queue(bgp, afi, safi, vty,
15237 subgrp_id);
15238 else if (!strcmp(what, "advertised-routes"))
15239 update_group_show_advertised(bgp, afi, safi, vty,
15240 subgrp_id);
15241 else if (!strcmp(what, "packet-queue"))
15242 update_group_show_packet_queue(bgp, afi, safi, vty,
15243 subgrp_id);
15244 }
15245 }
15246
15247 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
15248 show_ip_bgp_instance_updgrps_adj_s_cmd,
15249 "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",
15250 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
15251 BGP_SAFI_HELP_STR
15252 "Detailed info about dynamic update groups\n"
15253 "Specific subgroup to display info for\n"
15254 "Advertisement queue\n"
15255 "Announced routes\n"
15256 "Packet queue\n")
15257 {
15258 uint64_t subgrp_id = 0;
15259 afi_t afiz;
15260 safi_t safiz;
15261 if (sgid)
15262 subgrp_id = strtoull(sgid, NULL, 10);
15263
15264 if (!ip && !afi)
15265 afiz = AFI_IP6;
15266 if (!ip && afi)
15267 afiz = bgp_vty_afi_from_str(afi);
15268 if (ip && !afi)
15269 afiz = AFI_IP;
15270 if (ip && afi) {
15271 afiz = bgp_vty_afi_from_str(afi);
15272 if (afiz != AFI_IP)
15273 vty_out(vty,
15274 "%% Cannot specify both 'ip' and 'ipv6'\n");
15275 return CMD_WARNING;
15276 }
15277
15278 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
15279
15280 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
15281 return CMD_SUCCESS;
15282 }
15283
15284 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
15285 {
15286 struct listnode *node, *nnode;
15287 struct prefix *range;
15288 struct peer *conf;
15289 struct peer *peer;
15290 afi_t afi;
15291 safi_t safi;
15292 const char *peer_status;
15293 const char *af_str;
15294 int lr_count;
15295 int dynamic;
15296 int af_cfgd;
15297
15298 conf = group->conf;
15299
15300 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
15301 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15302 group->name, conf->as);
15303 } else if (conf->as_type == AS_INTERNAL) {
15304 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15305 group->name, group->bgp->as);
15306 } else {
15307 vty_out(vty, "\nBGP peer-group %s\n", group->name);
15308 }
15309
15310 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
15311 vty_out(vty, " Peer-group type is internal\n");
15312 else
15313 vty_out(vty, " Peer-group type is external\n");
15314
15315 /* Display AFs configured. */
15316 vty_out(vty, " Configured address-families:");
15317 FOREACH_AFI_SAFI (afi, safi) {
15318 if (conf->afc[afi][safi]) {
15319 af_cfgd = 1;
15320 vty_out(vty, " %s;", get_afi_safi_str(afi, safi, false));
15321 }
15322 }
15323 if (!af_cfgd)
15324 vty_out(vty, " none\n");
15325 else
15326 vty_out(vty, "\n");
15327
15328 /* Display listen ranges (for dynamic neighbors), if any */
15329 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
15330 if (afi == AFI_IP)
15331 af_str = "IPv4";
15332 else if (afi == AFI_IP6)
15333 af_str = "IPv6";
15334 else
15335 af_str = "???";
15336 lr_count = listcount(group->listen_range[afi]);
15337 if (lr_count) {
15338 vty_out(vty, " %d %s listen range(s)\n", lr_count,
15339 af_str);
15340
15341
15342 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
15343 nnode, range))
15344 vty_out(vty, " %pFX\n", range);
15345 }
15346 }
15347
15348 /* Display group members and their status */
15349 if (listcount(group->peer)) {
15350 vty_out(vty, " Peer-group members:\n");
15351 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
15352 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
15353 || CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHUTDOWN))
15354 peer_status = "Idle (Admin)";
15355 else if (CHECK_FLAG(peer->sflags,
15356 PEER_STATUS_PREFIX_OVERFLOW))
15357 peer_status = "Idle (PfxCt)";
15358 else
15359 peer_status = lookup_msg(bgp_status_msg,
15360 peer->status, NULL);
15361
15362 dynamic = peer_dynamic_neighbor(peer);
15363 vty_out(vty, " %s %s %s \n", peer->host,
15364 dynamic ? "(dynamic)" : "", peer_status);
15365 }
15366 }
15367
15368 return CMD_SUCCESS;
15369 }
15370
15371 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
15372 const char *group_name)
15373 {
15374 struct bgp *bgp;
15375 struct listnode *node, *nnode;
15376 struct peer_group *group;
15377 bool found = false;
15378
15379 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15380
15381 if (!bgp) {
15382 vty_out(vty, "%% BGP instance not found\n");
15383 return CMD_WARNING;
15384 }
15385
15386 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
15387 if (group_name) {
15388 if (strmatch(group->name, group_name)) {
15389 bgp_show_one_peer_group(vty, group);
15390 found = true;
15391 break;
15392 }
15393 } else {
15394 bgp_show_one_peer_group(vty, group);
15395 }
15396 }
15397
15398 if (group_name && !found)
15399 vty_out(vty, "%% No such peer-group\n");
15400
15401 return CMD_SUCCESS;
15402 }
15403
15404 DEFUN (show_ip_bgp_peer_groups,
15405 show_ip_bgp_peer_groups_cmd,
15406 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
15407 SHOW_STR
15408 IP_STR
15409 BGP_STR
15410 BGP_INSTANCE_HELP_STR
15411 "Detailed information on BGP peer groups\n"
15412 "Peer group name\n")
15413 {
15414 char *vrf, *pg;
15415 int idx = 0;
15416
15417 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
15418 : NULL;
15419 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
15420
15421 return bgp_show_peer_group_vty(vty, vrf, pg);
15422 }
15423
15424
15425 /* Redistribute VTY commands. */
15426
15427 DEFUN_YANG (bgp_redistribute_ipv4,
15428 bgp_redistribute_ipv4_cmd,
15429 "redistribute " FRR_IP_REDIST_STR_BGPD,
15430 "Redistribute information from another routing protocol\n"
15431 FRR_IP_REDIST_HELP_STR_BGPD)
15432 {
15433 int idx_protocol = 1;
15434 char base_xpath[XPATH_MAXLEN];
15435
15436 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15437 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15438 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15439 argv[idx_protocol]->text, "0");
15440
15441 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15442
15443 return nb_cli_apply_changes(vty, base_xpath);
15444 }
15445
15446 ALIAS_HIDDEN(
15447 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
15448 "redistribute " FRR_IP_REDIST_STR_BGPD,
15449 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
15450
15451 DEFUN_YANG (bgp_redistribute_ipv4_rmap,
15452 bgp_redistribute_ipv4_rmap_cmd,
15453 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
15454 "Redistribute information from another routing protocol\n"
15455 FRR_IP_REDIST_HELP_STR_BGPD
15456 "Route map reference\n"
15457 "Pointer to route-map entries\n")
15458 {
15459 int idx_protocol = 1;
15460 int idx_word = 3;
15461 char base_xpath[XPATH_MAXLEN];
15462
15463 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15464 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15465 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15466 argv[idx_protocol]->text, "0");
15467
15468 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15469 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15470 argv[idx_word]->arg);
15471
15472 return nb_cli_apply_changes(vty, base_xpath);
15473 }
15474
15475 ALIAS_HIDDEN(
15476 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
15477 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
15478 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15479 "Route map reference\n"
15480 "Pointer to route-map entries\n")
15481
15482 DEFUN_YANG (bgp_redistribute_ipv4_metric,
15483 bgp_redistribute_ipv4_metric_cmd,
15484 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15485 "Redistribute information from another routing protocol\n"
15486 FRR_IP_REDIST_HELP_STR_BGPD
15487 "Metric for redistributed routes\n"
15488 "Default metric\n")
15489 {
15490 int idx_protocol = 1;
15491 int idx_number = 3;
15492 char base_xpath[XPATH_MAXLEN];
15493
15494 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15495 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15496 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15497 argv[idx_protocol]->text, "0");
15498
15499 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15500 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15501 argv[idx_number]->arg);
15502
15503 return nb_cli_apply_changes(vty, base_xpath);
15504 }
15505
15506 ALIAS_HIDDEN(
15507 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
15508 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15509 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15510 "Metric for redistributed routes\n"
15511 "Default metric\n")
15512
15513 DEFUN_YANG(
15514 bgp_redistribute_ipv4_rmap_metric,
15515 bgp_redistribute_ipv4_rmap_metric_cmd,
15516 "redistribute " FRR_IP_REDIST_STR_BGPD
15517 " route-map WORD metric (0-4294967295)",
15518 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15519 "Route map reference\n"
15520 "Pointer to route-map entries\n"
15521 "Metric for redistributed routes\n"
15522 "Default metric\n")
15523 {
15524 int idx_protocol = 1;
15525 int idx_word = 3;
15526 int idx_number = 5;
15527 char base_xpath[XPATH_MAXLEN];
15528
15529 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15530 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15531 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15532 argv[idx_protocol]->text, "0");
15533
15534 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15535 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15536 argv[idx_word]->arg);
15537 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15538 argv[idx_number]->arg);
15539
15540 return nb_cli_apply_changes(vty, base_xpath);
15541 }
15542
15543 ALIAS_HIDDEN(
15544 bgp_redistribute_ipv4_rmap_metric,
15545 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
15546 "redistribute " FRR_IP_REDIST_STR_BGPD
15547 " route-map WORD metric (0-4294967295)",
15548 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15549 "Route map reference\n"
15550 "Pointer to route-map entries\n"
15551 "Metric for redistributed routes\n"
15552 "Default metric\n")
15553
15554 DEFUN_YANG(
15555 bgp_redistribute_ipv4_metric_rmap,
15556 bgp_redistribute_ipv4_metric_rmap_cmd,
15557 "redistribute " FRR_IP_REDIST_STR_BGPD
15558 " metric (0-4294967295) route-map WORD",
15559 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15560 "Metric for redistributed routes\n"
15561 "Default metric\n"
15562 "Route map reference\n"
15563 "Pointer to route-map entries\n")
15564 {
15565 int idx_protocol = 1;
15566 int idx_word = 5;
15567 int idx_number = 3;
15568 char base_xpath[XPATH_MAXLEN];
15569
15570 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15571 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15572 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15573 argv[idx_protocol]->text, "0");
15574
15575 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15576 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15577 argv[idx_number]->arg);
15578 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15579 argv[idx_word]->arg);
15580
15581 return nb_cli_apply_changes(vty, base_xpath);
15582 }
15583
15584 ALIAS_HIDDEN(
15585 bgp_redistribute_ipv4_metric_rmap,
15586 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
15587 "redistribute " FRR_IP_REDIST_STR_BGPD
15588 " metric (0-4294967295) route-map WORD",
15589 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15590 "Metric for redistributed routes\n"
15591 "Default metric\n"
15592 "Route map reference\n"
15593 "Pointer to route-map entries\n")
15594
15595 DEFUN_YANG (bgp_redistribute_ipv4_ospf,
15596 bgp_redistribute_ipv4_ospf_cmd,
15597 "redistribute <ospf|table> (1-65535)",
15598 "Redistribute information from another routing protocol\n"
15599 "Open Shortest Path First (OSPFv2)\n"
15600 "Non-main Kernel Routing Table\n"
15601 "Instance ID/Table ID\n")
15602 {
15603 int idx_protocol = 1;
15604 int idx_number = 2;
15605 char base_xpath[XPATH_MAXLEN];
15606
15607 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15608 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15609 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15610 argv[idx_protocol]->text, argv[idx_number]->arg);
15611
15612 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15613
15614 return nb_cli_apply_changes(vty, base_xpath);
15615 }
15616
15617 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
15618 "redistribute <ospf|table> (1-65535)",
15619 "Redistribute information from another routing protocol\n"
15620 "Open Shortest Path First (OSPFv2)\n"
15621 "Non-main Kernel Routing Table\n"
15622 "Instance ID/Table ID\n")
15623
15624 DEFUN_YANG (bgp_redistribute_ipv4_ospf_rmap,
15625 bgp_redistribute_ipv4_ospf_rmap_cmd,
15626 "redistribute <ospf|table> (1-65535) route-map WORD",
15627 "Redistribute information from another routing protocol\n"
15628 "Open Shortest Path First (OSPFv2)\n"
15629 "Non-main Kernel Routing Table\n"
15630 "Instance ID/Table ID\n"
15631 "Route map reference\n"
15632 "Pointer to route-map entries\n")
15633 {
15634 int idx_protocol = 1;
15635 int idx_number = 2;
15636 int idx_word = 4;
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, argv[idx_number]->arg);
15643
15644 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15645
15646 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15647 argv[idx_word]->arg);
15648
15649 return nb_cli_apply_changes(vty, base_xpath);
15650 }
15651
15652 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
15653 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
15654 "redistribute <ospf|table> (1-65535) route-map WORD",
15655 "Redistribute information from another routing protocol\n"
15656 "Open Shortest Path First (OSPFv2)\n"
15657 "Non-main Kernel Routing Table\n"
15658 "Instance ID/Table ID\n"
15659 "Route map reference\n"
15660 "Pointer to route-map entries\n")
15661
15662 DEFUN_YANG(bgp_redistribute_ipv4_ospf_metric,
15663 bgp_redistribute_ipv4_ospf_metric_cmd,
15664 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
15665 "Redistribute information from another routing protocol\n"
15666 "Open Shortest Path First (OSPFv2)\n"
15667 "Non-main Kernel Routing Table\n"
15668 "Instance ID/Table ID\n"
15669 "Metric for redistributed routes\n"
15670 "Default metric\n")
15671 {
15672 int idx_protocol = 1;
15673 int idx_number = 2;
15674 int idx_number_2 = 4;
15675 char base_xpath[XPATH_MAXLEN];
15676
15677 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15678 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15679 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15680 argv[idx_protocol]->text, argv[idx_number]->arg);
15681
15682 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15683
15684 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15685 argv[idx_number_2]->arg);
15686
15687 return nb_cli_apply_changes(vty, base_xpath);
15688 }
15689
15690 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
15691 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
15692 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
15693 "Redistribute information from another routing protocol\n"
15694 "Open Shortest Path First (OSPFv2)\n"
15695 "Non-main Kernel Routing Table\n"
15696 "Instance ID/Table ID\n"
15697 "Metric for redistributed routes\n"
15698 "Default metric\n")
15699
15700 DEFUN_YANG(
15701 bgp_redistribute_ipv4_ospf_rmap_metric,
15702 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
15703 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
15704 "Redistribute information from another routing protocol\n"
15705 "Open Shortest Path First (OSPFv2)\n"
15706 "Non-main Kernel Routing Table\n"
15707 "Instance ID/Table ID\n"
15708 "Route map reference\n"
15709 "Pointer to route-map entries\n"
15710 "Metric for redistributed routes\n"
15711 "Default metric\n")
15712 {
15713 int idx_protocol = 1;
15714 int idx_number = 2;
15715 int idx_word = 4;
15716 int idx_number_2 = 6;
15717 char base_xpath[XPATH_MAXLEN];
15718
15719 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15720 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15721 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15722 argv[idx_protocol]->text, argv[idx_number]->arg);
15723
15724 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15725
15726 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15727 argv[idx_word]->arg);
15728 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15729 argv[idx_number_2]->arg);
15730
15731 return nb_cli_apply_changes(vty, base_xpath);
15732 }
15733
15734 ALIAS_HIDDEN(
15735 bgp_redistribute_ipv4_ospf_rmap_metric,
15736 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
15737 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
15738 "Redistribute information from another routing protocol\n"
15739 "Open Shortest Path First (OSPFv2)\n"
15740 "Non-main Kernel Routing Table\n"
15741 "Instance ID/Table ID\n"
15742 "Route map reference\n"
15743 "Pointer to route-map entries\n"
15744 "Metric for redistributed routes\n"
15745 "Default metric\n")
15746
15747 DEFUN_YANG(
15748 bgp_redistribute_ipv4_ospf_metric_rmap,
15749 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
15750 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
15751 "Redistribute information from another routing protocol\n"
15752 "Open Shortest Path First (OSPFv2)\n"
15753 "Non-main Kernel Routing Table\n"
15754 "Instance ID/Table ID\n"
15755 "Metric for redistributed routes\n"
15756 "Default metric\n"
15757 "Route map reference\n"
15758 "Pointer to route-map entries\n")
15759 {
15760 int idx_protocol = 1;
15761 int idx_number = 2;
15762 int idx_number_2 = 4;
15763 int idx_word = 6;
15764 char base_xpath[XPATH_MAXLEN];
15765
15766 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15767 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15768 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15769 argv[idx_protocol]->text, argv[idx_number]->arg);
15770
15771 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15772
15773 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15774 argv[idx_number_2]->arg);
15775 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15776 argv[idx_word]->arg);
15777
15778 return nb_cli_apply_changes(vty, base_xpath);
15779 }
15780
15781 ALIAS_HIDDEN(
15782 bgp_redistribute_ipv4_ospf_metric_rmap,
15783 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
15784 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
15785 "Redistribute information from another routing protocol\n"
15786 "Open Shortest Path First (OSPFv2)\n"
15787 "Non-main Kernel Routing Table\n"
15788 "Instance ID/Table ID\n"
15789 "Metric for redistributed routes\n"
15790 "Default metric\n"
15791 "Route map reference\n"
15792 "Pointer to route-map entries\n")
15793
15794 DEFUN_YANG (no_bgp_redistribute_ipv4_ospf,
15795 no_bgp_redistribute_ipv4_ospf_cmd,
15796 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
15797 NO_STR
15798 "Redistribute information from another routing protocol\n"
15799 "Open Shortest Path First (OSPFv2)\n"
15800 "Non-main Kernel Routing Table\n"
15801 "Instance ID/Table ID\n"
15802 "Metric for redistributed routes\n"
15803 "Default metric\n"
15804 "Route map reference\n"
15805 "Pointer to route-map entries\n")
15806 {
15807 int idx_protocol = 2;
15808 int idx_number = 3;
15809 char base_xpath[XPATH_MAXLEN];
15810
15811 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15812 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15813 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15814 argv[idx_protocol]->text, argv[idx_number]->arg);
15815
15816 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
15817
15818 return nb_cli_apply_changes(vty, base_xpath);
15819 }
15820
15821 ALIAS_HIDDEN(
15822 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
15823 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
15824 NO_STR
15825 "Redistribute information from another routing protocol\n"
15826 "Open Shortest Path First (OSPFv2)\n"
15827 "Non-main Kernel Routing Table\n"
15828 "Instance ID/Table ID\n"
15829 "Metric for redistributed routes\n"
15830 "Default metric\n"
15831 "Route map reference\n"
15832 "Pointer to route-map entries\n")
15833
15834 DEFUN_YANG (no_bgp_redistribute_ipv4,
15835 no_bgp_redistribute_ipv4_cmd,
15836 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
15837 NO_STR
15838 "Redistribute information from another routing protocol\n"
15839 FRR_IP_REDIST_HELP_STR_BGPD
15840 "Metric for redistributed routes\n"
15841 "Default metric\n"
15842 "Route map reference\n"
15843 "Pointer to route-map entries\n")
15844 {
15845 int idx_protocol = 2;
15846 char base_xpath[XPATH_MAXLEN];
15847
15848 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15849 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15850 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15851 argv[idx_protocol]->text, "0");
15852
15853 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
15854
15855 return nb_cli_apply_changes(vty, base_xpath);
15856 }
15857
15858 ALIAS_HIDDEN(
15859 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
15860 "no redistribute " FRR_IP_REDIST_STR_BGPD
15861 " [{metric (0-4294967295)|route-map WORD}]",
15862 NO_STR
15863 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15864 "Metric for redistributed routes\n"
15865 "Default metric\n"
15866 "Route map reference\n"
15867 "Pointer to route-map entries\n")
15868
15869 DEFUN_YANG (bgp_redistribute_ipv6,
15870 bgp_redistribute_ipv6_cmd,
15871 "redistribute " FRR_IP6_REDIST_STR_BGPD,
15872 "Redistribute information from another routing protocol\n"
15873 FRR_IP6_REDIST_HELP_STR_BGPD)
15874 {
15875 int idx_protocol = 1;
15876 char base_xpath[XPATH_MAXLEN];
15877
15878 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15879 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
15880 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
15881 argv[idx_protocol]->text, "0");
15882
15883 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15884
15885 return nb_cli_apply_changes(vty, base_xpath);
15886 }
15887
15888 DEFUN_YANG (bgp_redistribute_ipv6_rmap,
15889 bgp_redistribute_ipv6_rmap_cmd,
15890 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
15891 "Redistribute information from another routing protocol\n"
15892 FRR_IP6_REDIST_HELP_STR_BGPD
15893 "Route map reference\n"
15894 "Pointer to route-map entries\n")
15895 {
15896 int idx_protocol = 1;
15897 int idx_word = 3;
15898 char base_xpath[XPATH_MAXLEN];
15899
15900 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15901 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
15902 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
15903 argv[idx_protocol]->text, "0");
15904
15905 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15906 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15907 argv[idx_word]->arg);
15908
15909 return nb_cli_apply_changes(vty, base_xpath);
15910 }
15911
15912 DEFUN_YANG (bgp_redistribute_ipv6_metric,
15913 bgp_redistribute_ipv6_metric_cmd,
15914 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
15915 "Redistribute information from another routing protocol\n"
15916 FRR_IP6_REDIST_HELP_STR_BGPD
15917 "Metric for redistributed routes\n"
15918 "Default metric\n")
15919 {
15920 int idx_protocol = 1;
15921 int idx_number = 3;
15922 char base_xpath[XPATH_MAXLEN];
15923
15924 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15925 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
15926 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
15927 argv[idx_protocol]->text, "0");
15928
15929 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15930 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15931 argv[idx_number]->arg);
15932
15933 return nb_cli_apply_changes(vty, base_xpath);
15934 }
15935
15936 DEFUN_YANG(
15937 bgp_redistribute_ipv6_rmap_metric,
15938 bgp_redistribute_ipv6_rmap_metric_cmd,
15939 "redistribute " FRR_IP6_REDIST_STR_BGPD
15940 " route-map WORD metric (0-4294967295)",
15941 "Redistribute information from another routing protocol\n" FRR_IP6_REDIST_HELP_STR_BGPD
15942 "Route map reference\n"
15943 "Pointer to route-map entries\n"
15944 "Metric for redistributed routes\n"
15945 "Default metric\n")
15946 {
15947 int idx_protocol = 1;
15948 int idx_word = 3;
15949 int idx_number = 5;
15950 char base_xpath[XPATH_MAXLEN];
15951
15952 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15953 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
15954 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
15955 argv[idx_protocol]->text, "0");
15956
15957 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15958 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15959 argv[idx_word]->arg);
15960 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15961 argv[idx_number]->arg);
15962
15963 return nb_cli_apply_changes(vty, base_xpath);
15964 }
15965
15966 DEFUN_YANG(
15967 bgp_redistribute_ipv6_metric_rmap,
15968 bgp_redistribute_ipv6_metric_rmap_cmd,
15969 "redistribute " FRR_IP6_REDIST_STR_BGPD
15970 " metric (0-4294967295) route-map WORD",
15971 "Redistribute information from another routing protocol\n" FRR_IP6_REDIST_HELP_STR_BGPD
15972 "Metric for redistributed routes\n"
15973 "Default metric\n"
15974 "Route map reference\n"
15975 "Pointer to route-map entries\n")
15976 {
15977 int idx_protocol = 1;
15978 int idx_word = 5;
15979 int idx_number = 3;
15980 char base_xpath[XPATH_MAXLEN];
15981
15982 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15983 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
15984 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
15985 argv[idx_protocol]->text, "0");
15986
15987 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15988 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15989 argv[idx_number]->arg);
15990 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15991 argv[idx_word]->arg);
15992
15993 return nb_cli_apply_changes(vty, base_xpath);
15994 }
15995
15996 DEFUN_YANG(
15997 no_bgp_redistribute_ipv6,
15998 no_bgp_redistribute_ipv6_cmd,
15999 "no redistribute " FRR_IP6_REDIST_STR_BGPD
16000 " [{metric (0-4294967295)|route-map WORD}]",
16001 NO_STR
16002 "Redistribute information from another routing protocol\n" FRR_IP6_REDIST_HELP_STR_BGPD
16003 "Metric for redistributed routes\n"
16004 "Default metric\n"
16005 "Route map reference\n"
16006 "Pointer to route-map entries\n")
16007 {
16008 int idx_protocol = 2;
16009 char base_xpath[XPATH_MAXLEN];
16010
16011 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16012 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16013 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16014 argv[idx_protocol]->text, "0");
16015
16016 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
16017
16018 return nb_cli_apply_changes(vty, base_xpath);
16019 }
16020
16021 void cli_show_bgp_global_afi_safi_ip_unicast_redistribution_list(
16022 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
16023 {
16024 uint32_t instance = 0;
16025
16026 vty_out(vty, " redistribute %s",
16027 yang_dnode_get_string(dnode, "./route-type"));
16028 if ((instance = yang_dnode_get_uint16(dnode, "./route-instance")))
16029 vty_out(vty, " %d", instance);
16030 if (yang_dnode_exists(dnode, "./metric"))
16031 vty_out(vty, " metric %u",
16032 yang_dnode_get_uint32(dnode, "./metric"));
16033 if (yang_dnode_exists(dnode, "./rmap-policy-import"))
16034 vty_out(vty, " route-map %s",
16035 yang_dnode_get_string(dnode, "./rmap-policy-import"));
16036 vty_out(vty, "\n");
16037 }
16038
16039 static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
16040 afi_t afi, safi_t safi)
16041 {
16042 int i;
16043
16044 /* Unicast redistribution only. */
16045 if (safi != SAFI_UNICAST)
16046 return;
16047
16048 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
16049 /* Redistribute BGP does not make sense. */
16050 if (i != ZEBRA_ROUTE_BGP) {
16051 struct list *red_list;
16052 struct listnode *node;
16053 struct bgp_redist *red;
16054
16055 red_list = bgp->redist[afi][i];
16056 if (!red_list)
16057 continue;
16058
16059 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
16060 /* "redistribute" configuration. */
16061 vty_out(vty, " redistribute %s",
16062 zebra_route_string(i));
16063 if (red->instance)
16064 vty_out(vty, " %d", red->instance);
16065 if (red->redist_metric_flag)
16066 vty_out(vty, " metric %u",
16067 red->redist_metric);
16068 if (red->rmap.name)
16069 vty_out(vty, " route-map %s",
16070 red->rmap.name);
16071 vty_out(vty, "\n");
16072 }
16073 }
16074 }
16075 }
16076
16077 /* peer-group helpers for config-write */
16078
16079 static bool peergroup_flag_check(struct peer *peer, uint32_t flag)
16080 {
16081 if (!peer_group_active(peer)) {
16082 if (CHECK_FLAG(peer->flags_invert, flag))
16083 return !CHECK_FLAG(peer->flags, flag);
16084 else
16085 return !!CHECK_FLAG(peer->flags, flag);
16086 }
16087
16088 return !!CHECK_FLAG(peer->flags_override, flag);
16089 }
16090
16091 static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
16092 uint32_t flag)
16093 {
16094 if (!peer_group_active(peer)) {
16095 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
16096 return !peer_af_flag_check(peer, afi, safi, flag);
16097 else
16098 return !!peer_af_flag_check(peer, afi, safi, flag);
16099 }
16100
16101 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
16102 }
16103
16104 static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
16105 uint8_t type, int direct)
16106 {
16107 struct bgp_filter *filter;
16108
16109 if (peer_group_active(peer))
16110 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
16111 type);
16112
16113 filter = &peer->filter[afi][safi];
16114 switch (type) {
16115 case PEER_FT_DISTRIBUTE_LIST:
16116 return !!(filter->dlist[direct].name);
16117 case PEER_FT_FILTER_LIST:
16118 return !!(filter->aslist[direct].name);
16119 case PEER_FT_PREFIX_LIST:
16120 return !!(filter->plist[direct].name);
16121 case PEER_FT_ROUTE_MAP:
16122 return !!(filter->map[direct].name);
16123 case PEER_FT_UNSUPPRESS_MAP:
16124 return !!(filter->usmap.name);
16125 case PEER_FT_ADVERTISE_MAP:
16126 return !!(filter->advmap.aname
16127 && ((filter->advmap.condition == direct)
16128 && filter->advmap.cname));
16129 default:
16130 return false;
16131 }
16132 }
16133
16134 /* Return true if the addpath type is set for peer and different from
16135 * peer-group.
16136 */
16137 static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi,
16138 safi_t safi)
16139 {
16140 enum bgp_addpath_strat type, g_type;
16141
16142 type = peer->addpath_type[afi][safi];
16143
16144 if (type != BGP_ADDPATH_NONE) {
16145 if (peer_group_active(peer)) {
16146 g_type = peer->group->conf->addpath_type[afi][safi];
16147
16148 if (type != g_type)
16149 return true;
16150 else
16151 return false;
16152 }
16153
16154 return true;
16155 }
16156
16157 return false;
16158 }
16159
16160 /* This is part of the address-family block (unicast only) */
16161 static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
16162 afi_t afi)
16163 {
16164 int indent = 2;
16165
16166 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
16167 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16168 BGP_CONFIG_VRF_TO_VRF_IMPORT))
16169 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
16170 bgp->vpn_policy[afi]
16171 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16172 else
16173 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
16174 bgp->vpn_policy[afi]
16175 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16176 }
16177 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16178 BGP_CONFIG_VRF_TO_VRF_IMPORT)
16179 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16180 BGP_CONFIG_VRF_TO_VRF_EXPORT))
16181 return;
16182
16183 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16184 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
16185
16186 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
16187
16188 } else {
16189 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
16190 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
16191 bgp->vpn_policy[afi].tovpn_label);
16192 }
16193 }
16194 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16195 BGP_VPN_POLICY_TOVPN_RD_SET)) {
16196 char buf[RD_ADDRSTRLEN];
16197 vty_out(vty, "%*srd vpn export %s\n", indent, "",
16198 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
16199 sizeof(buf)));
16200 }
16201 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16202 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
16203
16204 char buf[PREFIX_STRLEN];
16205 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
16206 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
16207 sizeof(buf))) {
16208
16209 vty_out(vty, "%*snexthop vpn export %s\n",
16210 indent, "", buf);
16211 }
16212 }
16213 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
16214 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
16215 && ecommunity_cmp(
16216 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16217 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
16218
16219 char *b = ecommunity_ecom2str(
16220 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16221 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
16222 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
16223 XFREE(MTYPE_ECOMMUNITY_STR, b);
16224 } else {
16225 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
16226 char *b = ecommunity_ecom2str(
16227 bgp->vpn_policy[afi]
16228 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16229 ECOMMUNITY_FORMAT_ROUTE_MAP,
16230 ECOMMUNITY_ROUTE_TARGET);
16231 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
16232 XFREE(MTYPE_ECOMMUNITY_STR, b);
16233 }
16234 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
16235 char *b = ecommunity_ecom2str(
16236 bgp->vpn_policy[afi]
16237 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16238 ECOMMUNITY_FORMAT_ROUTE_MAP,
16239 ECOMMUNITY_ROUTE_TARGET);
16240 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
16241 XFREE(MTYPE_ECOMMUNITY_STR, b);
16242 }
16243 }
16244
16245 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
16246 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
16247 bgp->vpn_policy[afi]
16248 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
16249
16250 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
16251 char *b = ecommunity_ecom2str(
16252 bgp->vpn_policy[afi]
16253 .import_redirect_rtlist,
16254 ECOMMUNITY_FORMAT_ROUTE_MAP,
16255 ECOMMUNITY_ROUTE_TARGET);
16256
16257 if (bgp->vpn_policy[afi].import_redirect_rtlist->unit_size
16258 != ECOMMUNITY_SIZE)
16259 vty_out(vty, "%*srt6 redirect import %s\n",
16260 indent, "", b);
16261 else
16262 vty_out(vty, "%*srt redirect import %s\n",
16263 indent, "", b);
16264 XFREE(MTYPE_ECOMMUNITY_STR, b);
16265 }
16266 }
16267
16268 static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
16269 afi_t afi, safi_t safi)
16270 {
16271 struct bgp_filter *filter;
16272 char *addr;
16273
16274 addr = peer->host;
16275 filter = &peer->filter[afi][safi];
16276
16277 /* distribute-list. */
16278 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16279 FILTER_IN))
16280 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
16281 filter->dlist[FILTER_IN].name);
16282
16283 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16284 FILTER_OUT))
16285 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
16286 filter->dlist[FILTER_OUT].name);
16287
16288 /* prefix-list. */
16289 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16290 FILTER_IN))
16291 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
16292 filter->plist[FILTER_IN].name);
16293
16294 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16295 FILTER_OUT))
16296 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
16297 filter->plist[FILTER_OUT].name);
16298
16299 /* route-map. */
16300 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
16301 vty_out(vty, " neighbor %s route-map %s in\n", addr,
16302 filter->map[RMAP_IN].name);
16303
16304 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
16305 RMAP_OUT))
16306 vty_out(vty, " neighbor %s route-map %s out\n", addr,
16307 filter->map[RMAP_OUT].name);
16308
16309 /* unsuppress-map */
16310 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
16311 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
16312 filter->usmap.name);
16313
16314 /* advertise-map : always applied in OUT direction*/
16315 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16316 CONDITION_NON_EXIST))
16317 vty_out(vty,
16318 " neighbor %s advertise-map %s non-exist-map %s\n",
16319 addr, filter->advmap.aname, filter->advmap.cname);
16320
16321 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16322 CONDITION_EXIST))
16323 vty_out(vty, " neighbor %s advertise-map %s exist-map %s\n",
16324 addr, filter->advmap.aname, filter->advmap.cname);
16325
16326 /* filter-list. */
16327 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16328 FILTER_IN))
16329 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
16330 filter->aslist[FILTER_IN].name);
16331
16332 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16333 FILTER_OUT))
16334 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
16335 filter->aslist[FILTER_OUT].name);
16336 }
16337
16338 /* BGP peer configuration display function. */
16339 static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
16340 struct peer *peer)
16341 {
16342 struct peer *g_peer = NULL;
16343 char buf[SU_ADDRSTRLEN];
16344 char *addr;
16345 int if_pg_printed = false;
16346 int if_ras_printed = false;
16347
16348 /* Skip dynamic neighbors. */
16349 if (peer_dynamic_neighbor(peer))
16350 return;
16351
16352 if (peer->conf_if)
16353 addr = peer->conf_if;
16354 else
16355 addr = peer->host;
16356
16357 /************************************
16358 ****** Global to the neighbor ******
16359 ************************************/
16360 if (peer->conf_if) {
16361 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
16362 vty_out(vty, " neighbor %s interface v6only", addr);
16363 else
16364 vty_out(vty, " neighbor %s interface", addr);
16365
16366 if (peer_group_active(peer)) {
16367 vty_out(vty, " peer-group %s", peer->group->name);
16368 if_pg_printed = true;
16369 } else if (peer->as_type == AS_SPECIFIED) {
16370 vty_out(vty, " remote-as %u", peer->as);
16371 if_ras_printed = true;
16372 } else if (peer->as_type == AS_INTERNAL) {
16373 vty_out(vty, " remote-as internal");
16374 if_ras_printed = true;
16375 } else if (peer->as_type == AS_EXTERNAL) {
16376 vty_out(vty, " remote-as external");
16377 if_ras_printed = true;
16378 }
16379
16380 vty_out(vty, "\n");
16381 }
16382
16383 /* remote-as and peer-group */
16384 /* peer is a member of a peer-group */
16385 if (peer_group_active(peer)) {
16386 g_peer = peer->group->conf;
16387
16388 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
16389 if (peer->as_type == AS_SPECIFIED) {
16390 vty_out(vty, " neighbor %s remote-as %u\n",
16391 addr, peer->as);
16392 } else if (peer->as_type == AS_INTERNAL) {
16393 vty_out(vty,
16394 " neighbor %s remote-as internal\n",
16395 addr);
16396 } else if (peer->as_type == AS_EXTERNAL) {
16397 vty_out(vty,
16398 " neighbor %s remote-as external\n",
16399 addr);
16400 }
16401 }
16402
16403 /* For swpX peers we displayed the peer-group
16404 * via 'neighbor swpX interface peer-group PGNAME' */
16405 if (!if_pg_printed)
16406 vty_out(vty, " neighbor %s peer-group %s\n", addr,
16407 peer->group->name);
16408 }
16409
16410 /* peer is NOT a member of a peer-group */
16411 else {
16412 /* peer is a peer-group, declare the peer-group */
16413 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
16414 vty_out(vty, " neighbor %s peer-group\n", addr);
16415 }
16416
16417 if (!if_ras_printed) {
16418 if (peer->as_type == AS_SPECIFIED) {
16419 vty_out(vty, " neighbor %s remote-as %u\n",
16420 addr, peer->as);
16421 } else if (peer->as_type == AS_INTERNAL) {
16422 vty_out(vty,
16423 " neighbor %s remote-as internal\n",
16424 addr);
16425 } else if (peer->as_type == AS_EXTERNAL) {
16426 vty_out(vty,
16427 " neighbor %s remote-as external\n",
16428 addr);
16429 }
16430 }
16431 }
16432
16433 /* local-as */
16434 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
16435 vty_out(vty, " neighbor %s local-as %u", addr,
16436 peer->change_local_as);
16437 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
16438 vty_out(vty, " no-prepend");
16439 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
16440 vty_out(vty, " replace-as");
16441 vty_out(vty, "\n");
16442 }
16443
16444 /* description */
16445 if (peer->desc) {
16446 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
16447 }
16448
16449 /* shutdown */
16450 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
16451 if (peer->tx_shutdown_message)
16452 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
16453 peer->tx_shutdown_message);
16454 else
16455 vty_out(vty, " neighbor %s shutdown\n", addr);
16456 }
16457
16458 if (peergroup_flag_check(peer, PEER_FLAG_RTT_SHUTDOWN))
16459 vty_out(vty, " neighbor %s shutdown rtt %u count %u\n", addr,
16460 peer->rtt_expected, peer->rtt_keepalive_conf);
16461
16462 /* bfd */
16463 if (peer->bfd_info) {
16464 if (!peer_group_active(peer) || !g_peer->bfd_info) {
16465 bgp_bfd_peer_config_write(vty, peer, addr);
16466 }
16467 }
16468
16469 /* password */
16470 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
16471 vty_out(vty, " neighbor %s password %s\n", addr,
16472 peer->password);
16473
16474 /* neighbor solo */
16475 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
16476 if (!peer_group_active(peer)) {
16477 vty_out(vty, " neighbor %s solo\n", addr);
16478 }
16479 }
16480
16481 /* BGP port */
16482 if (peer->port != BGP_PORT_DEFAULT) {
16483 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
16484 }
16485
16486 /* Local interface name */
16487 if (peer->ifname) {
16488 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
16489 }
16490
16491 /* passive */
16492 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
16493 vty_out(vty, " neighbor %s passive\n", addr);
16494
16495 /* ebgp-multihop */
16496 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
16497 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
16498 && peer->ttl == MAXTTL)) {
16499 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
16500 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
16501 peer->ttl);
16502 }
16503 }
16504
16505 /* ttl-security hops */
16506 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
16507 if (!peer_group_active(peer)
16508 || g_peer->gtsm_hops != peer->gtsm_hops) {
16509 vty_out(vty, " neighbor %s ttl-security hops %d\n",
16510 addr, peer->gtsm_hops);
16511 }
16512 }
16513
16514 /* disable-connected-check */
16515 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
16516 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
16517
16518 /* enforce-first-as */
16519 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
16520 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
16521
16522 /* update-source */
16523 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
16524 if (peer->update_source)
16525 vty_out(vty, " neighbor %s update-source %s\n", addr,
16526 sockunion2str(peer->update_source, buf,
16527 SU_ADDRSTRLEN));
16528 else if (peer->update_if)
16529 vty_out(vty, " neighbor %s update-source %s\n", addr,
16530 peer->update_if);
16531 }
16532
16533 /* advertisement-interval */
16534 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
16535 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
16536 peer->routeadv);
16537
16538 /* timers */
16539 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
16540 vty_out(vty, " neighbor %s timers %u %u\n", addr,
16541 peer->keepalive, peer->holdtime);
16542
16543 /* timers connect */
16544 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
16545 vty_out(vty, " neighbor %s timers connect %u\n", addr,
16546 peer->connect);
16547 /* need special-case handling for changed default values due to
16548 * config profile / version (because there is no "timers bgp connect"
16549 * command, we need to save this per-peer :/)
16550 */
16551 else if (!peer_group_active(peer) && !peer->connect &&
16552 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
16553 vty_out(vty, " neighbor %s timers connect %u\n", addr,
16554 peer->bgp->default_connect_retry);
16555
16556 /* timers delayopen */
16557 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_DELAYOPEN))
16558 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
16559 peer->delayopen);
16560 /* Save config even though flag is not set if default values have been
16561 * changed
16562 */
16563 else if (!peer_group_active(peer) && !peer->delayopen
16564 && peer->bgp->default_delayopen != BGP_DEFAULT_DELAYOPEN)
16565 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
16566 peer->bgp->default_delayopen);
16567
16568 /* capability dynamic */
16569 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
16570 vty_out(vty, " neighbor %s capability dynamic\n", addr);
16571
16572 /* capability extended-nexthop */
16573 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
16574 if (!peer->conf_if) {
16575 if (CHECK_FLAG(peer->flags_invert,
16576 PEER_FLAG_CAPABILITY_ENHE))
16577 vty_out(vty,
16578 " no neighbor %s capability extended-nexthop\n",
16579 addr);
16580 else
16581 vty_out(vty,
16582 " neighbor %s capability extended-nexthop\n",
16583 addr);
16584 }
16585 }
16586
16587 /* dont-capability-negotiation */
16588 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
16589 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
16590
16591 /* override-capability */
16592 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
16593 vty_out(vty, " neighbor %s override-capability\n", addr);
16594
16595 /* strict-capability-match */
16596 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
16597 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
16598
16599 /* Sender side AS path loop detection. */
16600 if (peer->as_path_loop_detection)
16601 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
16602 addr);
16603
16604 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
16605 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
16606
16607 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
16608 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
16609 vty_out(vty,
16610 " neighbor %s graceful-restart-helper\n", addr);
16611 } else if (CHECK_FLAG(
16612 peer->peer_gr_new_status_flag,
16613 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
16614 vty_out(vty,
16615 " neighbor %s graceful-restart\n", addr);
16616 } else if (
16617 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
16618 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
16619 && !(CHECK_FLAG(
16620 peer->peer_gr_new_status_flag,
16621 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
16622 vty_out(vty, " neighbor %s graceful-restart-disable\n",
16623 addr);
16624 }
16625 }
16626 }
16627
16628 /* BGP peer configuration display function. */
16629 static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
16630 struct peer *peer, afi_t afi, safi_t safi)
16631 {
16632 struct peer *g_peer = NULL;
16633 char *addr;
16634 bool flag_scomm, flag_secomm, flag_slcomm;
16635
16636 /* Skip dynamic neighbors. */
16637 if (peer_dynamic_neighbor(peer))
16638 return;
16639
16640 if (peer->conf_if)
16641 addr = peer->conf_if;
16642 else
16643 addr = peer->host;
16644
16645 /************************************
16646 ****** Per AF to the neighbor ******
16647 ************************************/
16648 if (peer_group_active(peer)) {
16649 g_peer = peer->group->conf;
16650
16651 /* If the peer-group is active but peer is not, print a 'no
16652 * activate' */
16653 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
16654 vty_out(vty, " no neighbor %s activate\n", addr);
16655 }
16656
16657 /* If the peer-group is not active but peer is, print an
16658 'activate' */
16659 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
16660 vty_out(vty, " neighbor %s activate\n", addr);
16661 }
16662 } else {
16663 if (peer->afc[afi][safi]) {
16664 if ((afi == AFI_IP) && (safi == SAFI_UNICAST)) {
16665 if (CHECK_FLAG(bgp->flags,
16666 BGP_FLAG_NO_DEFAULT_IPV4)) {
16667 vty_out(vty, " neighbor %s activate\n",
16668 addr);
16669 }
16670 } else
16671 vty_out(vty, " neighbor %s activate\n", addr);
16672 } else {
16673 if ((afi == AFI_IP) && (safi == SAFI_UNICAST)) {
16674 if (!CHECK_FLAG(bgp->flags,
16675 BGP_FLAG_NO_DEFAULT_IPV4)) {
16676 vty_out(vty,
16677 " no neighbor %s activate\n",
16678 addr);
16679 }
16680 }
16681 }
16682 }
16683
16684 /* addpath TX knobs */
16685 if (peergroup_af_addpath_check(peer, afi, safi)) {
16686 switch (peer->addpath_type[afi][safi]) {
16687 case BGP_ADDPATH_ALL:
16688 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
16689 addr);
16690 break;
16691 case BGP_ADDPATH_BEST_PER_AS:
16692 vty_out(vty,
16693 " neighbor %s addpath-tx-bestpath-per-AS\n",
16694 addr);
16695 break;
16696 case BGP_ADDPATH_MAX:
16697 case BGP_ADDPATH_NONE:
16698 break;
16699 }
16700 }
16701
16702 /* ORF capability. */
16703 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
16704 || peergroup_af_flag_check(peer, afi, safi,
16705 PEER_FLAG_ORF_PREFIX_RM)) {
16706 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
16707
16708 if (peergroup_af_flag_check(peer, afi, safi,
16709 PEER_FLAG_ORF_PREFIX_SM)
16710 && peergroup_af_flag_check(peer, afi, safi,
16711 PEER_FLAG_ORF_PREFIX_RM))
16712 vty_out(vty, " both");
16713 else if (peergroup_af_flag_check(peer, afi, safi,
16714 PEER_FLAG_ORF_PREFIX_SM))
16715 vty_out(vty, " send");
16716 else
16717 vty_out(vty, " receive");
16718 vty_out(vty, "\n");
16719 }
16720
16721 /* Route reflector client. */
16722 if (peergroup_af_flag_check(peer, afi, safi,
16723 PEER_FLAG_REFLECTOR_CLIENT)) {
16724 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
16725 }
16726
16727 /* next-hop-self force */
16728 if (peergroup_af_flag_check(peer, afi, safi,
16729 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
16730 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
16731 }
16732
16733 /* next-hop-self */
16734 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
16735 vty_out(vty, " neighbor %s next-hop-self\n", addr);
16736 }
16737
16738 /* remove-private-AS */
16739 if (peergroup_af_flag_check(peer, afi, safi,
16740 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
16741 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
16742 addr);
16743 }
16744
16745 else if (peergroup_af_flag_check(peer, afi, safi,
16746 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
16747 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
16748 addr);
16749 }
16750
16751 else if (peergroup_af_flag_check(peer, afi, safi,
16752 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
16753 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
16754 }
16755
16756 else if (peergroup_af_flag_check(peer, afi, safi,
16757 PEER_FLAG_REMOVE_PRIVATE_AS)) {
16758 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
16759 }
16760
16761 /* as-override */
16762 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
16763 vty_out(vty, " neighbor %s as-override\n", addr);
16764 }
16765
16766 /* send-community print. */
16767 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
16768 PEER_FLAG_SEND_COMMUNITY);
16769 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
16770 PEER_FLAG_SEND_EXT_COMMUNITY);
16771 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
16772 PEER_FLAG_SEND_LARGE_COMMUNITY);
16773
16774 if (flag_scomm && flag_secomm && flag_slcomm) {
16775 vty_out(vty, " no neighbor %s send-community all\n", addr);
16776 } else {
16777 if (flag_scomm)
16778 vty_out(vty, " no neighbor %s send-community\n", addr);
16779 if (flag_secomm)
16780 vty_out(vty,
16781 " no neighbor %s send-community extended\n",
16782 addr);
16783
16784 if (flag_slcomm)
16785 vty_out(vty, " no neighbor %s send-community large\n",
16786 addr);
16787 }
16788
16789 /* Default information */
16790 if (peergroup_af_flag_check(peer, afi, safi,
16791 PEER_FLAG_DEFAULT_ORIGINATE)) {
16792 vty_out(vty, " neighbor %s default-originate", addr);
16793
16794 if (peer->default_rmap[afi][safi].name)
16795 vty_out(vty, " route-map %s",
16796 peer->default_rmap[afi][safi].name);
16797
16798 vty_out(vty, "\n");
16799 }
16800
16801 /* Soft reconfiguration inbound. */
16802 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
16803 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
16804 addr);
16805 }
16806
16807 /* maximum-prefix. */
16808 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
16809 vty_out(vty, " neighbor %s maximum-prefix %u", addr,
16810 peer->pmax[afi][safi]);
16811
16812 if (peer->pmax_threshold[afi][safi]
16813 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
16814 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
16815 if (peer_af_flag_check(peer, afi, safi,
16816 PEER_FLAG_MAX_PREFIX_WARNING))
16817 vty_out(vty, " warning-only");
16818 if (peer->pmax_restart[afi][safi])
16819 vty_out(vty, " restart %u",
16820 peer->pmax_restart[afi][safi]);
16821 if (peer_af_flag_check(peer, afi, safi,
16822 PEER_FLAG_MAX_PREFIX_FORCE))
16823 vty_out(vty, " force");
16824
16825 vty_out(vty, "\n");
16826 }
16827
16828 /* maximum-prefix-out */
16829 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
16830 vty_out(vty, " neighbor %s maximum-prefix-out %u\n",
16831 addr, peer->pmax_out[afi][safi]);
16832
16833 /* Route server client. */
16834 if (peergroup_af_flag_check(peer, afi, safi,
16835 PEER_FLAG_RSERVER_CLIENT)) {
16836 vty_out(vty, " neighbor %s route-server-client\n", addr);
16837 }
16838
16839 /* Nexthop-local unchanged. */
16840 if (peergroup_af_flag_check(peer, afi, safi,
16841 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
16842 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
16843 }
16844
16845 /* allowas-in <1-10> */
16846 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
16847 if (peer_af_flag_check(peer, afi, safi,
16848 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
16849 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
16850 } else if (peer->allowas_in[afi][safi] == 3) {
16851 vty_out(vty, " neighbor %s allowas-in\n", addr);
16852 } else {
16853 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
16854 peer->allowas_in[afi][safi]);
16855 }
16856 }
16857
16858 /* weight */
16859 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
16860 vty_out(vty, " neighbor %s weight %lu\n", addr,
16861 peer->weight[afi][safi]);
16862
16863 /* Filter. */
16864 bgp_config_write_filter(vty, peer, afi, safi);
16865
16866 /* atribute-unchanged. */
16867 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
16868 || (safi != SAFI_EVPN
16869 && peer_af_flag_check(peer, afi, safi,
16870 PEER_FLAG_NEXTHOP_UNCHANGED))
16871 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
16872
16873 if (!peer_group_active(peer)
16874 || peergroup_af_flag_check(peer, afi, safi,
16875 PEER_FLAG_AS_PATH_UNCHANGED)
16876 || peergroup_af_flag_check(peer, afi, safi,
16877 PEER_FLAG_NEXTHOP_UNCHANGED)
16878 || peergroup_af_flag_check(peer, afi, safi,
16879 PEER_FLAG_MED_UNCHANGED)) {
16880
16881 vty_out(vty,
16882 " neighbor %s attribute-unchanged%s%s%s\n",
16883 addr,
16884 peer_af_flag_check(peer, afi, safi,
16885 PEER_FLAG_AS_PATH_UNCHANGED)
16886 ? " as-path"
16887 : "",
16888 peer_af_flag_check(peer, afi, safi,
16889 PEER_FLAG_NEXTHOP_UNCHANGED)
16890 ? " next-hop"
16891 : "",
16892 peer_af_flag_check(peer, afi, safi,
16893 PEER_FLAG_MED_UNCHANGED)
16894 ? " med"
16895 : "");
16896 }
16897 }
16898 }
16899
16900 /* Address family based peer configuration display. */
16901 static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
16902 safi_t safi)
16903 {
16904 struct peer *peer;
16905 struct peer_group *group;
16906 struct listnode *node, *nnode;
16907
16908
16909 vty_frame(vty, " !\n address-family ");
16910 if (afi == AFI_IP) {
16911 if (safi == SAFI_UNICAST)
16912 vty_frame(vty, "ipv4 unicast");
16913 else if (safi == SAFI_LABELED_UNICAST)
16914 vty_frame(vty, "ipv4 labeled-unicast");
16915 else if (safi == SAFI_MULTICAST)
16916 vty_frame(vty, "ipv4 multicast");
16917 else if (safi == SAFI_MPLS_VPN)
16918 vty_frame(vty, "ipv4 vpn");
16919 else if (safi == SAFI_ENCAP)
16920 vty_frame(vty, "ipv4 encap");
16921 else if (safi == SAFI_FLOWSPEC)
16922 vty_frame(vty, "ipv4 flowspec");
16923 } else if (afi == AFI_IP6) {
16924 if (safi == SAFI_UNICAST)
16925 vty_frame(vty, "ipv6 unicast");
16926 else if (safi == SAFI_LABELED_UNICAST)
16927 vty_frame(vty, "ipv6 labeled-unicast");
16928 else if (safi == SAFI_MULTICAST)
16929 vty_frame(vty, "ipv6 multicast");
16930 else if (safi == SAFI_MPLS_VPN)
16931 vty_frame(vty, "ipv6 vpn");
16932 else if (safi == SAFI_ENCAP)
16933 vty_frame(vty, "ipv6 encap");
16934 else if (safi == SAFI_FLOWSPEC)
16935 vty_frame(vty, "ipv6 flowspec");
16936 } else if (afi == AFI_L2VPN) {
16937 if (safi == SAFI_EVPN)
16938 vty_frame(vty, "l2vpn evpn");
16939 }
16940 vty_frame(vty, "\n");
16941
16942 bgp_config_write_distance(vty, bgp, afi, safi);
16943
16944 bgp_config_write_network(vty, bgp, afi, safi);
16945
16946 bgp_config_write_redistribute(vty, bgp, afi, safi);
16947
16948 /* BGP flag dampening. */
16949 if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
16950 bgp_config_write_damp(vty, afi, safi);
16951
16952 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
16953 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
16954
16955 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
16956 /* Skip dynamic neighbors. */
16957 if (peer_dynamic_neighbor(peer))
16958 continue;
16959
16960 /* Do not display doppelganger peers */
16961 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
16962 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
16963 }
16964
16965 bgp_config_write_maxpaths(vty, bgp, afi, safi);
16966 bgp_config_write_table_map(vty, bgp, afi, safi);
16967
16968 if (safi == SAFI_EVPN)
16969 bgp_config_write_evpn_info(vty, bgp, afi, safi);
16970
16971 if (safi == SAFI_FLOWSPEC)
16972 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
16973
16974 if (safi == SAFI_UNICAST) {
16975 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
16976 if (CHECK_FLAG(bgp->af_flags[afi][safi],
16977 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
16978
16979 vty_out(vty, " export vpn\n");
16980 }
16981 if (CHECK_FLAG(bgp->af_flags[afi][safi],
16982 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
16983
16984 vty_out(vty, " import vpn\n");
16985 }
16986 if (CHECK_FLAG(bgp->af_flags[afi][safi],
16987 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
16988 char *name;
16989
16990 for (ALL_LIST_ELEMENTS_RO(
16991 bgp->vpn_policy[afi].import_vrf, node,
16992 name))
16993 vty_out(vty, " import vrf %s\n", name);
16994 }
16995 }
16996
16997 vty_endframe(vty, " exit-address-family\n");
16998 }
16999
17000 int bgp_config_write(struct vty *vty)
17001 {
17002 struct bgp *bgp;
17003 struct peer_group *group;
17004 struct peer *peer;
17005 struct listnode *node, *nnode;
17006 struct listnode *mnode, *mnnode;
17007
17008 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
17009 vty_out(vty, "bgp route-map delay-timer %u\n",
17010 bm->rmap_update_timer);
17011
17012 if (bm->v_update_delay != BGP_UPDATE_DELAY_DEF) {
17013 vty_out(vty, "bgp update-delay %d", bm->v_update_delay);
17014 if (bm->v_update_delay != bm->v_establish_wait)
17015 vty_out(vty, " %d", bm->v_establish_wait);
17016 vty_out(vty, "\n");
17017 }
17018
17019 if (bm->wait_for_fib)
17020 vty_out(vty, "bgp suppress-fib-pending\n");
17021
17022 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17023 vty_out(vty, "bgp graceful-shutdown\n");
17024
17025 /* No-RIB (Zebra) option flag configuration */
17026 if (bgp_option_check(BGP_OPT_NO_FIB))
17027 vty_out(vty, "bgp no-rib\n");
17028
17029 if (!CHECK_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA))
17030 vty_out(vty, "no bgp send-extra-data zebra\n");
17031
17032 /* BGP configuration. */
17033 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
17034
17035 /* skip all auto created vrf as they dont have user config */
17036 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
17037 continue;
17038
17039 /* Router bgp ASN */
17040 vty_out(vty, "router bgp %u", bgp->as);
17041
17042 if (bgp->name)
17043 vty_out(vty, " %s %s",
17044 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
17045 ? "view" : "vrf", bgp->name);
17046 vty_out(vty, "\n");
17047
17048 /* BGP fast-external-failover. */
17049 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
17050 vty_out(vty, " no bgp fast-external-failover\n");
17051
17052 /* BGP router ID. */
17053 if (bgp->router_id_static.s_addr != INADDR_ANY)
17054 vty_out(vty, " bgp router-id %pI4\n",
17055 &bgp->router_id_static);
17056
17057 /* Suppress fib pending */
17058 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_FIB_PENDING))
17059 vty_out(vty, " bgp suppress-fib-pending\n");
17060
17061 /* BGP log-neighbor-changes. */
17062 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
17063 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
17064 vty_out(vty, " %sbgp log-neighbor-changes\n",
17065 CHECK_FLAG(bgp->flags,
17066 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
17067 ? ""
17068 : "no ");
17069
17070 /* BGP configuration. */
17071 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
17072 vty_out(vty, " bgp always-compare-med\n");
17073
17074 /* RFC8212 default eBGP policy. */
17075 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
17076 != SAVE_BGP_EBGP_REQUIRES_POLICY)
17077 vty_out(vty, " %sbgp ebgp-requires-policy\n",
17078 CHECK_FLAG(bgp->flags,
17079 BGP_FLAG_EBGP_REQUIRES_POLICY)
17080 ? ""
17081 : "no ");
17082
17083 /* draft-ietf-idr-deprecate-as-set-confed-set */
17084 if (bgp->reject_as_sets)
17085 vty_out(vty, " bgp reject-as-sets\n");
17086
17087 /* Suppress duplicate updates if the route actually not changed
17088 */
17089 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES)
17090 != SAVE_BGP_SUPPRESS_DUPLICATES)
17091 vty_out(vty, " %sbgp suppress-duplicates\n",
17092 CHECK_FLAG(bgp->flags,
17093 BGP_FLAG_SUPPRESS_DUPLICATES)
17094 ? ""
17095 : "no ");
17096
17097 /* BGP default ipv4-unicast. */
17098 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4))
17099 vty_out(vty, " no bgp default ipv4-unicast\n");
17100
17101 /* BGP default local-preference. */
17102 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
17103 vty_out(vty, " bgp default local-preference %u\n",
17104 bgp->default_local_pref);
17105
17106 /* BGP default show-hostname */
17107 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
17108 != SAVE_BGP_SHOW_HOSTNAME)
17109 vty_out(vty, " %sbgp default show-hostname\n",
17110 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
17111 ? ""
17112 : "no ");
17113
17114 /* BGP default show-nexthop-hostname */
17115 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17116 != SAVE_BGP_SHOW_HOSTNAME)
17117 vty_out(vty, " %sbgp default show-nexthop-hostname\n",
17118 CHECK_FLAG(bgp->flags,
17119 BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17120 ? ""
17121 : "no ");
17122
17123 /* BGP default subgroup-pkt-queue-max. */
17124 if (bgp->default_subgroup_pkt_queue_max
17125 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
17126 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
17127 bgp->default_subgroup_pkt_queue_max);
17128
17129 /* BGP client-to-client reflection. */
17130 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
17131 vty_out(vty, " no bgp client-to-client reflection\n");
17132
17133 /* BGP cluster ID. */
17134 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
17135 vty_out(vty, " bgp cluster-id %pI4\n",
17136 &bgp->cluster_id);
17137
17138 /* Disable ebgp connected nexthop check */
17139 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
17140 vty_out(vty,
17141 " bgp disable-ebgp-connected-route-check\n");
17142
17143 /* Confederation identifier*/
17144 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
17145 vty_out(vty, " bgp confederation identifier %u\n",
17146 bgp->confed_id);
17147
17148 /* Confederation peer */
17149 if (bgp->confed_peers_cnt > 0) {
17150 int i;
17151
17152 vty_out(vty, " bgp confederation peers");
17153
17154 for (i = 0; i < bgp->confed_peers_cnt; i++)
17155 vty_out(vty, " %u", bgp->confed_peers[i]);
17156
17157 vty_out(vty, "\n");
17158 }
17159
17160 /* BGP deterministic-med. */
17161 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
17162 != SAVE_BGP_DETERMINISTIC_MED)
17163 vty_out(vty, " %sbgp deterministic-med\n",
17164 CHECK_FLAG(bgp->flags,
17165 BGP_FLAG_DETERMINISTIC_MED)
17166 ? ""
17167 : "no ");
17168
17169 /* BGP update-delay. */
17170 bgp_config_write_update_delay(vty, bgp);
17171
17172 if (bgp->v_maxmed_onstartup
17173 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
17174 vty_out(vty, " bgp max-med on-startup %u",
17175 bgp->v_maxmed_onstartup);
17176 if (bgp->maxmed_onstartup_value
17177 != BGP_MAXMED_VALUE_DEFAULT)
17178 vty_out(vty, " %u",
17179 bgp->maxmed_onstartup_value);
17180 vty_out(vty, "\n");
17181 }
17182 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
17183 vty_out(vty, " bgp max-med administrative");
17184 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
17185 vty_out(vty, " %u", bgp->maxmed_admin_value);
17186 vty_out(vty, "\n");
17187 }
17188
17189 /* write quanta */
17190 bgp_config_write_wpkt_quanta(vty, bgp);
17191 /* read quanta */
17192 bgp_config_write_rpkt_quanta(vty, bgp);
17193
17194 /* coalesce time */
17195 bgp_config_write_coalesce_time(vty, bgp);
17196
17197 /* BGP per-instance graceful-shutdown */
17198 /* BGP-wide settings and per-instance settings are mutually
17199 * exclusive.
17200 */
17201 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17202 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
17203 vty_out(vty, " bgp graceful-shutdown\n");
17204
17205 /* BGP graceful-restart. */
17206 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
17207 vty_out(vty,
17208 " bgp graceful-restart stalepath-time %u\n",
17209 bgp->stalepath_time);
17210
17211 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
17212 vty_out(vty, " bgp graceful-restart restart-time %u\n",
17213 bgp->restart_time);
17214
17215 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
17216 vty_out(vty,
17217 " bgp graceful-restart select-defer-time %u\n",
17218 bgp->select_defer_time);
17219
17220 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
17221 vty_out(vty, " bgp graceful-restart\n");
17222
17223 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
17224 vty_out(vty, " bgp graceful-restart-disable\n");
17225
17226 /* BGP graceful-restart Preserve State F bit. */
17227 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
17228 vty_out(vty,
17229 " bgp graceful-restart preserve-fw-state\n");
17230
17231 /* Stale timer for RIB */
17232 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
17233 vty_out(vty,
17234 " bgp graceful-restart rib-stale-time %u\n",
17235 bgp->rib_stale_time);
17236
17237 /* BGP bestpath method. */
17238 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
17239 vty_out(vty, " bgp bestpath as-path ignore\n");
17240 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
17241 vty_out(vty, " bgp bestpath as-path confed\n");
17242
17243 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
17244 if (CHECK_FLAG(bgp->flags,
17245 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
17246 vty_out(vty,
17247 " bgp bestpath as-path multipath-relax as-set\n");
17248 } else {
17249 vty_out(vty,
17250 " bgp bestpath as-path multipath-relax\n");
17251 }
17252 }
17253
17254 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
17255 vty_out(vty,
17256 " bgp route-reflector allow-outbound-policy\n");
17257 }
17258 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
17259 vty_out(vty, " bgp bestpath compare-routerid\n");
17260 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
17261 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
17262 vty_out(vty, " bgp bestpath med");
17263 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
17264 vty_out(vty, " confed");
17265 if (CHECK_FLAG(bgp->flags,
17266 BGP_FLAG_MED_MISSING_AS_WORST))
17267 vty_out(vty, " missing-as-worst");
17268 vty_out(vty, "\n");
17269 }
17270
17271 /* Link bandwidth handling. */
17272 if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW)
17273 vty_out(vty, " bgp bestpath bandwidth ignore\n");
17274 else if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
17275 vty_out(vty, " bgp bestpath bandwidth skip-missing\n");
17276 else if (bgp->lb_handling == BGP_LINK_BW_DEFWT_4_MISSING)
17277 vty_out(vty, " bgp bestpath bandwidth default-weight-for-missing\n");
17278
17279 /* BGP network import check. */
17280 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
17281 != SAVE_BGP_IMPORT_CHECK)
17282 vty_out(vty, " %sbgp network import-check\n",
17283 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
17284 ? ""
17285 : "no ");
17286
17287 /* BGP timers configuration. */
17288 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
17289 && bgp->default_holdtime != SAVE_BGP_HOLDTIME)
17290 vty_out(vty, " timers bgp %u %u\n",
17291 bgp->default_keepalive, bgp->default_holdtime);
17292
17293 /* peer-group */
17294 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
17295 bgp_config_write_peer_global(vty, bgp, group->conf);
17296 }
17297
17298 /* Normal neighbor configuration. */
17299 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17300 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17301 bgp_config_write_peer_global(vty, bgp, peer);
17302 }
17303
17304 /* listen range and limit for dynamic BGP neighbors */
17305 bgp_config_write_listen(vty, bgp);
17306
17307 /*
17308 * BGP default autoshutdown neighbors
17309 *
17310 * This must be placed after any peer and peer-group
17311 * configuration, to avoid setting all peers to shutdown after
17312 * a daemon restart, which is undesired behavior. (see #2286)
17313 */
17314 if (bgp->autoshutdown)
17315 vty_out(vty, " bgp default shutdown\n");
17316
17317 /* BGP instance administrative shutdown */
17318 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN))
17319 vty_out(vty, " bgp shutdown\n");
17320
17321 /* IPv4 unicast configuration. */
17322 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
17323
17324 /* IPv4 multicast configuration. */
17325 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
17326
17327 /* IPv4 labeled-unicast configuration. */
17328 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
17329
17330 /* IPv4 VPN configuration. */
17331 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
17332
17333 /* ENCAPv4 configuration. */
17334 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
17335
17336 /* FLOWSPEC v4 configuration. */
17337 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
17338
17339 /* IPv6 unicast configuration. */
17340 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
17341
17342 /* IPv6 multicast configuration. */
17343 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
17344
17345 /* IPv6 labeled-unicast configuration. */
17346 bgp_config_write_family(vty, bgp, AFI_IP6,
17347 SAFI_LABELED_UNICAST);
17348
17349 /* IPv6 VPN configuration. */
17350 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
17351
17352 /* ENCAPv6 configuration. */
17353 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
17354
17355 /* FLOWSPEC v6 configuration. */
17356 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
17357
17358 /* EVPN configuration. */
17359 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
17360
17361 hook_call(bgp_inst_config_write, bgp, vty);
17362
17363 #ifdef ENABLE_BGP_VNC
17364 bgp_rfapi_cfg_write(vty, bgp);
17365 #endif
17366
17367 vty_out(vty, "!\n");
17368 }
17369 return 0;
17370 }
17371
17372
17373 /* BGP node structure. */
17374 static struct cmd_node bgp_node = {
17375 .name = "bgp",
17376 .node = BGP_NODE,
17377 .parent_node = CONFIG_NODE,
17378 .prompt = "%s(config-router)# ",
17379 .config_write = bgp_config_write,
17380 };
17381
17382 static struct cmd_node bgp_ipv4_unicast_node = {
17383 .name = "bgp ipv4 unicast",
17384 .node = BGP_IPV4_NODE,
17385 .parent_node = BGP_NODE,
17386 .prompt = "%s(config-router-af)# ",
17387 };
17388
17389 static struct cmd_node bgp_ipv4_multicast_node = {
17390 .name = "bgp ipv4 multicast",
17391 .node = BGP_IPV4M_NODE,
17392 .parent_node = BGP_NODE,
17393 .prompt = "%s(config-router-af)# ",
17394 };
17395
17396 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
17397 .name = "bgp ipv4 labeled unicast",
17398 .node = BGP_IPV4L_NODE,
17399 .parent_node = BGP_NODE,
17400 .prompt = "%s(config-router-af)# ",
17401 };
17402
17403 static struct cmd_node bgp_ipv6_unicast_node = {
17404 .name = "bgp ipv6",
17405 .node = BGP_IPV6_NODE,
17406 .parent_node = BGP_NODE,
17407 .prompt = "%s(config-router-af)# ",
17408 };
17409
17410 static struct cmd_node bgp_ipv6_multicast_node = {
17411 .name = "bgp ipv6 multicast",
17412 .node = BGP_IPV6M_NODE,
17413 .parent_node = BGP_NODE,
17414 .prompt = "%s(config-router-af)# ",
17415 };
17416
17417 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
17418 .name = "bgp ipv6 labeled unicast",
17419 .node = BGP_IPV6L_NODE,
17420 .parent_node = BGP_NODE,
17421 .prompt = "%s(config-router-af)# ",
17422 };
17423
17424 static struct cmd_node bgp_vpnv4_node = {
17425 .name = "bgp vpnv4",
17426 .node = BGP_VPNV4_NODE,
17427 .parent_node = BGP_NODE,
17428 .prompt = "%s(config-router-af)# ",
17429 };
17430
17431 static struct cmd_node bgp_vpnv6_node = {
17432 .name = "bgp vpnv6",
17433 .node = BGP_VPNV6_NODE,
17434 .parent_node = BGP_NODE,
17435 .prompt = "%s(config-router-af-vpnv6)# ",
17436 };
17437
17438 static struct cmd_node bgp_evpn_node = {
17439 .name = "bgp evpn",
17440 .node = BGP_EVPN_NODE,
17441 .parent_node = BGP_NODE,
17442 .prompt = "%s(config-router-evpn)# ",
17443 };
17444
17445 static struct cmd_node bgp_evpn_vni_node = {
17446 .name = "bgp evpn vni",
17447 .node = BGP_EVPN_VNI_NODE,
17448 .parent_node = BGP_EVPN_NODE,
17449 .prompt = "%s(config-router-af-vni)# ",
17450 };
17451
17452 static struct cmd_node bgp_flowspecv4_node = {
17453 .name = "bgp ipv4 flowspec",
17454 .node = BGP_FLOWSPECV4_NODE,
17455 .parent_node = BGP_NODE,
17456 .prompt = "%s(config-router-af)# ",
17457 };
17458
17459 static struct cmd_node bgp_flowspecv6_node = {
17460 .name = "bgp ipv6 flowspec",
17461 .node = BGP_FLOWSPECV6_NODE,
17462 .parent_node = BGP_NODE,
17463 .prompt = "%s(config-router-af-vpnv6)# ",
17464 };
17465
17466 static void community_list_vty(void);
17467
17468 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
17469 {
17470 struct bgp *bgp;
17471 struct peer *peer;
17472 struct listnode *lnbgp, *lnpeer;
17473
17474 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
17475 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
17476 /* only provide suggestions on the appropriate input
17477 * token type,
17478 * they'll otherwise show up multiple times */
17479 enum cmd_token_type match_type;
17480 char *name = peer->host;
17481
17482 if (peer->conf_if) {
17483 match_type = VARIABLE_TKN;
17484 name = peer->conf_if;
17485 } else if (strchr(peer->host, ':'))
17486 match_type = IPV6_TKN;
17487 else
17488 match_type = IPV4_TKN;
17489
17490 if (token->type != match_type)
17491 continue;
17492
17493 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
17494 }
17495 }
17496 }
17497
17498 static const struct cmd_variable_handler bgp_var_neighbor[] = {
17499 {.varname = "neighbor", .completions = bgp_ac_neighbor},
17500 {.varname = "neighbors", .completions = bgp_ac_neighbor},
17501 {.varname = "peer", .completions = bgp_ac_neighbor},
17502 {.completions = NULL}};
17503
17504 static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
17505 {
17506 struct bgp *bgp;
17507 struct peer_group *group;
17508 struct listnode *lnbgp, *lnpeer;
17509
17510 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
17511 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
17512 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
17513 group->name));
17514 }
17515 }
17516
17517 static const struct cmd_variable_handler bgp_var_peergroup[] = {
17518 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
17519 {.completions = NULL} };
17520
17521 void bgp_vty_init(void)
17522 {
17523 cmd_variable_handler_register(bgp_var_neighbor);
17524 cmd_variable_handler_register(bgp_var_peergroup);
17525
17526 /* Install bgp top node. */
17527 install_node(&bgp_node);
17528 install_node(&bgp_ipv4_unicast_node);
17529 install_node(&bgp_ipv4_multicast_node);
17530 install_node(&bgp_ipv4_labeled_unicast_node);
17531 install_node(&bgp_ipv6_unicast_node);
17532 install_node(&bgp_ipv6_multicast_node);
17533 install_node(&bgp_ipv6_labeled_unicast_node);
17534 install_node(&bgp_vpnv4_node);
17535 install_node(&bgp_vpnv6_node);
17536 install_node(&bgp_evpn_node);
17537 install_node(&bgp_evpn_vni_node);
17538 install_node(&bgp_flowspecv4_node);
17539 install_node(&bgp_flowspecv6_node);
17540
17541 /* Install default VTY commands to new nodes. */
17542 install_default(BGP_NODE);
17543 install_default(BGP_IPV4_NODE);
17544 install_default(BGP_IPV4M_NODE);
17545 install_default(BGP_IPV4L_NODE);
17546 install_default(BGP_IPV6_NODE);
17547 install_default(BGP_IPV6M_NODE);
17548 install_default(BGP_IPV6L_NODE);
17549 install_default(BGP_VPNV4_NODE);
17550 install_default(BGP_VPNV6_NODE);
17551 install_default(BGP_FLOWSPECV4_NODE);
17552 install_default(BGP_FLOWSPECV6_NODE);
17553 install_default(BGP_EVPN_NODE);
17554 install_default(BGP_EVPN_VNI_NODE);
17555
17556 /* "bgp local-mac" hidden commands. */
17557 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
17558 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
17559
17560 /* "bgp suppress-fib-pending" global */
17561 install_element(CONFIG_NODE, &bgp_global_suppress_fib_pending_cmd);
17562
17563 /* bgp route-map delay-timer commands. */
17564 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
17565 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
17566
17567 /* global bgp update-delay command */
17568 install_element(CONFIG_NODE, &bgp_global_update_delay_cmd);
17569 install_element(CONFIG_NODE, &no_bgp_global_update_delay_cmd);
17570
17571 /* global bgp graceful-shutdown command */
17572 install_element(CONFIG_NODE, &bgp_graceful_shutdown_cmd);
17573 install_element(CONFIG_NODE, &no_bgp_graceful_shutdown_cmd);
17574
17575 /* Dummy commands (Currently not supported) */
17576 install_element(BGP_NODE, &no_synchronization_cmd);
17577 install_element(BGP_NODE, &no_auto_summary_cmd);
17578
17579 /* "router bgp" commands. */
17580 install_element(CONFIG_NODE, &router_bgp_cmd);
17581
17582 /* "no router bgp" commands. */
17583 install_element(CONFIG_NODE, &no_router_bgp_cmd);
17584
17585 /* "bgp router-id" commands. */
17586 install_element(BGP_NODE, &bgp_router_id_cmd);
17587 install_element(BGP_NODE, &no_bgp_router_id_cmd);
17588
17589 /* "bgp suppress-fib-pending" command */
17590 install_element(BGP_NODE, &bgp_suppress_fib_pending_cmd);
17591
17592 /* "bgp cluster-id" commands. */
17593 install_element(BGP_NODE, &bgp_cluster_id_cmd);
17594 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
17595
17596 /* "bgp no-rib" commands. */
17597 install_element(CONFIG_NODE, &bgp_norib_cmd);
17598 install_element(CONFIG_NODE, &no_bgp_norib_cmd);
17599
17600 install_element(CONFIG_NODE, &no_bgp_send_extra_data_cmd);
17601
17602 /* "bgp confederation" commands. */
17603 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
17604 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
17605
17606 /* "bgp confederation peers" commands. */
17607 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
17608 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
17609
17610 /* bgp max-med command */
17611 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
17612 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
17613 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
17614 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
17615 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
17616
17617 /* bgp disable-ebgp-connected-nh-check */
17618 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
17619 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
17620
17621 /* bgp update-delay command */
17622 install_element(BGP_NODE, &bgp_update_delay_cmd);
17623 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
17624
17625 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
17626 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
17627
17628 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
17629 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
17630
17631 /* "maximum-paths" commands. */
17632 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
17633 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
17634 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
17635 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
17636 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
17637 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
17638 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
17639 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
17640 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
17641 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
17642 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17643 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
17644 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
17645 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17646 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
17647
17648 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_cmd);
17649 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_cmd);
17650 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cmd);
17651 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17652 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_ibgp_cmd);
17653 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
17654 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
17655 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
17656 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17657 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
17658
17659 /* "timers bgp" commands. */
17660 install_element(BGP_NODE, &bgp_timers_cmd);
17661 install_element(BGP_NODE, &no_bgp_timers_cmd);
17662
17663 /* route-map delay-timer commands - per instance for backwards compat.
17664 */
17665 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
17666 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
17667
17668 /* "bgp client-to-client reflection" commands */
17669 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
17670 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
17671
17672 /* "bgp always-compare-med" commands */
17673 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
17674 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
17675
17676 /* bgp ebgp-requires-policy */
17677 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
17678 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
17679
17680 /* bgp suppress-duplicates */
17681 install_element(BGP_NODE, &bgp_suppress_duplicates_cmd);
17682 install_element(BGP_NODE, &no_bgp_suppress_duplicates_cmd);
17683
17684 /* bgp reject-as-sets */
17685 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
17686 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
17687
17688 /* "bgp deterministic-med" commands */
17689 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
17690 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
17691
17692 /* "bgp graceful-restart" command */
17693 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
17694 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
17695
17696 /* "bgp graceful-restart-disable" command */
17697 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
17698 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
17699
17700 /* "neighbor a:b:c:d graceful-restart" command */
17701 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
17702 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
17703
17704 /* "neighbor a:b:c:d graceful-restart-disable" command */
17705 install_element(BGP_NODE,
17706 &bgp_neighbor_graceful_restart_disable_set_cmd);
17707 install_element(BGP_NODE,
17708 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
17709
17710 /* "neighbor a:b:c:d graceful-restart-helper" command */
17711 install_element(BGP_NODE,
17712 &bgp_neighbor_graceful_restart_helper_set_cmd);
17713 install_element(BGP_NODE,
17714 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
17715
17716 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
17717 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
17718 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
17719 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
17720 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
17721 install_element(BGP_NODE,
17722 &no_bgp_graceful_restart_select_defer_time_cmd);
17723 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
17724 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
17725
17726 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
17727 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
17728 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
17729 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
17730
17731 /* "bgp graceful-shutdown" commands */
17732 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
17733 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
17734
17735 /* "bgp fast-external-failover" commands */
17736 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
17737 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
17738
17739 /* "bgp bestpath compare-routerid" commands */
17740 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
17741 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
17742
17743 /* "bgp bestpath as-path ignore" commands */
17744 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
17745 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
17746
17747 /* "bgp bestpath as-path confed" commands */
17748 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
17749 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
17750
17751 /* "bgp bestpath as-path multipath-relax" commands */
17752 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
17753 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
17754
17755 /* "bgp log-neighbor-changes" commands */
17756 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
17757 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
17758
17759 /* "bgp bestpath med" commands */
17760 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
17761 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
17762
17763 /* "bgp bestpath bandwidth" commands */
17764 install_element(BGP_NODE, &bgp_bestpath_bw_cmd);
17765 install_element(BGP_NODE, &no_bgp_bestpath_bw_cmd);
17766
17767 /* "no bgp default ipv4-unicast" commands. */
17768 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
17769 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
17770
17771 /* "bgp network import-check" commands. */
17772 install_element(BGP_NODE, &bgp_network_import_check_cmd);
17773 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
17774 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
17775
17776 /* "bgp default local-preference" commands. */
17777 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
17778 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
17779
17780 /* bgp default show-hostname */
17781 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
17782 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
17783
17784 /* bgp default show-nexthop-hostname */
17785 install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
17786 install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
17787
17788 /* "bgp default subgroup-pkt-queue-max" commands. */
17789 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
17790 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
17791
17792 /* bgp ibgp-allow-policy-mods command */
17793 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
17794 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
17795
17796 /* "bgp listen limit" commands. */
17797 install_element(BGP_NODE, &bgp_listen_limit_cmd);
17798 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
17799
17800 /* "bgp listen range" commands. */
17801 install_element(BGP_NODE, &bgp_listen_range_cmd);
17802 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
17803
17804 /* "bgp default shutdown" command */
17805 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
17806
17807 /* "bgp shutdown" commands */
17808 install_element(BGP_NODE, &bgp_shutdown_cmd);
17809 install_element(BGP_NODE, &bgp_shutdown_msg_cmd);
17810 install_element(BGP_NODE, &no_bgp_shutdown_cmd);
17811 install_element(BGP_NODE, &no_bgp_shutdown_msg_cmd);
17812
17813 /* "neighbor remote-as" commands. */
17814 install_element(BGP_NODE, &neighbor_remote_as_cmd);
17815 install_element(BGP_NODE, &neighbor_interface_config_cmd);
17816 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
17817 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
17818 install_element(BGP_NODE,
17819 &neighbor_interface_v6only_config_remote_as_cmd);
17820 install_element(BGP_NODE, &no_neighbor_cmd);
17821 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
17822
17823 /* "neighbor peer-group" commands. */
17824 install_element(BGP_NODE, &neighbor_peer_group_cmd);
17825 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
17826 install_element(BGP_NODE,
17827 &no_neighbor_interface_peer_group_remote_as_cmd);
17828
17829 /* "neighbor local-as" commands. */
17830 install_element(BGP_NODE, &neighbor_local_as_cmd);
17831 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
17832 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
17833 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
17834
17835 /* "neighbor solo" commands. */
17836 install_element(BGP_NODE, &neighbor_solo_cmd);
17837 install_element(BGP_NODE, &no_neighbor_solo_cmd);
17838
17839 /* "neighbor password" commands. */
17840 install_element(BGP_NODE, &neighbor_password_cmd);
17841 install_element(BGP_NODE, &no_neighbor_password_cmd);
17842
17843 /* "neighbor activate" commands. */
17844 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
17845 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
17846 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
17847 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
17848 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
17849 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
17850 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
17851 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
17852 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
17853 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
17854 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
17855 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
17856
17857 /* "no neighbor activate" commands. */
17858 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
17859 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
17860 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
17861 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
17862 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
17863 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
17864 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
17865 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
17866 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
17867 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
17868 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
17869 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
17870
17871 /* "neighbor peer-group" set commands. */
17872 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
17873 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
17874 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
17875 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
17876 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
17877 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
17878 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
17879 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
17880 install_element(BGP_FLOWSPECV4_NODE,
17881 &neighbor_set_peer_group_hidden_cmd);
17882 install_element(BGP_FLOWSPECV6_NODE,
17883 &neighbor_set_peer_group_hidden_cmd);
17884
17885 /* "no neighbor peer-group unset" commands. */
17886 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
17887 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17888 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17889 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17890 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17891 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17892 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17893 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17894 install_element(BGP_FLOWSPECV4_NODE,
17895 &no_neighbor_set_peer_group_hidden_cmd);
17896 install_element(BGP_FLOWSPECV6_NODE,
17897 &no_neighbor_set_peer_group_hidden_cmd);
17898
17899 /* "neighbor softreconfiguration inbound" commands.*/
17900 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
17901 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
17902 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
17903 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
17904 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
17905 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
17906 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
17907 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
17908 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
17909 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
17910 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
17911 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
17912 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
17913 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
17914 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
17915 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
17916 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
17917 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
17918 install_element(BGP_FLOWSPECV4_NODE,
17919 &neighbor_soft_reconfiguration_cmd);
17920 install_element(BGP_FLOWSPECV4_NODE,
17921 &no_neighbor_soft_reconfiguration_cmd);
17922 install_element(BGP_FLOWSPECV6_NODE,
17923 &neighbor_soft_reconfiguration_cmd);
17924 install_element(BGP_FLOWSPECV6_NODE,
17925 &no_neighbor_soft_reconfiguration_cmd);
17926 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
17927 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
17928
17929 /* "neighbor attribute-unchanged" commands. */
17930 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
17931 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
17932 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
17933 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
17934 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
17935 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
17936 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
17937 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
17938 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
17939 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
17940 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
17941 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
17942 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
17943 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
17944 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
17945 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
17946 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
17947 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
17948
17949 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
17950 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
17951
17952 /* "nexthop-local unchanged" commands */
17953 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
17954 install_element(BGP_IPV6_NODE,
17955 &no_neighbor_nexthop_local_unchanged_cmd);
17956
17957 /* "neighbor next-hop-self" commands. */
17958 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
17959 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
17960 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
17961 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
17962 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
17963 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
17964 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
17965 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
17966 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
17967 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
17968 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
17969 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
17970 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
17971 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
17972 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
17973 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
17974 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
17975 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
17976 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
17977 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
17978
17979 /* "neighbor next-hop-self force" commands. */
17980 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
17981 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
17982 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
17983 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
17984 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
17985 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
17986 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
17987 install_element(BGP_IPV4_NODE,
17988 &no_neighbor_nexthop_self_all_hidden_cmd);
17989 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
17990 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
17991 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
17992 install_element(BGP_IPV4M_NODE,
17993 &no_neighbor_nexthop_self_all_hidden_cmd);
17994 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
17995 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
17996 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
17997 install_element(BGP_IPV4L_NODE,
17998 &no_neighbor_nexthop_self_all_hidden_cmd);
17999 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
18000 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
18001 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18002 install_element(BGP_IPV6_NODE,
18003 &no_neighbor_nexthop_self_all_hidden_cmd);
18004 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
18005 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
18006 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18007 install_element(BGP_IPV6M_NODE,
18008 &no_neighbor_nexthop_self_all_hidden_cmd);
18009 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
18010 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
18011 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18012 install_element(BGP_IPV6L_NODE,
18013 &no_neighbor_nexthop_self_all_hidden_cmd);
18014 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
18015 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
18016 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18017 install_element(BGP_VPNV4_NODE,
18018 &no_neighbor_nexthop_self_all_hidden_cmd);
18019 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
18020 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
18021 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18022 install_element(BGP_VPNV6_NODE,
18023 &no_neighbor_nexthop_self_all_hidden_cmd);
18024 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_force_cmd);
18025 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_force_cmd);
18026
18027 /* "neighbor as-override" commands. */
18028 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
18029 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
18030 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
18031 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
18032 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
18033 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
18034 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
18035 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
18036 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
18037 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
18038 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
18039 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
18040 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
18041 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
18042 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
18043 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
18044 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
18045 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
18046
18047 /* "neighbor remove-private-AS" commands. */
18048 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
18049 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
18050 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
18051 install_element(BGP_NODE,
18052 &no_neighbor_remove_private_as_all_hidden_cmd);
18053 install_element(BGP_NODE,
18054 &neighbor_remove_private_as_replace_as_hidden_cmd);
18055 install_element(BGP_NODE,
18056 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
18057 install_element(BGP_NODE,
18058 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
18059 install_element(
18060 BGP_NODE,
18061 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
18062 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
18063 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
18064 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
18065 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18066 install_element(BGP_IPV4_NODE,
18067 &neighbor_remove_private_as_replace_as_cmd);
18068 install_element(BGP_IPV4_NODE,
18069 &no_neighbor_remove_private_as_replace_as_cmd);
18070 install_element(BGP_IPV4_NODE,
18071 &neighbor_remove_private_as_all_replace_as_cmd);
18072 install_element(BGP_IPV4_NODE,
18073 &no_neighbor_remove_private_as_all_replace_as_cmd);
18074 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
18075 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
18076 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
18077 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
18078 install_element(BGP_IPV4M_NODE,
18079 &neighbor_remove_private_as_replace_as_cmd);
18080 install_element(BGP_IPV4M_NODE,
18081 &no_neighbor_remove_private_as_replace_as_cmd);
18082 install_element(BGP_IPV4M_NODE,
18083 &neighbor_remove_private_as_all_replace_as_cmd);
18084 install_element(BGP_IPV4M_NODE,
18085 &no_neighbor_remove_private_as_all_replace_as_cmd);
18086 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
18087 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
18088 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
18089 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
18090 install_element(BGP_IPV4L_NODE,
18091 &neighbor_remove_private_as_replace_as_cmd);
18092 install_element(BGP_IPV4L_NODE,
18093 &no_neighbor_remove_private_as_replace_as_cmd);
18094 install_element(BGP_IPV4L_NODE,
18095 &neighbor_remove_private_as_all_replace_as_cmd);
18096 install_element(BGP_IPV4L_NODE,
18097 &no_neighbor_remove_private_as_all_replace_as_cmd);
18098 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
18099 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
18100 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
18101 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18102 install_element(BGP_IPV6_NODE,
18103 &neighbor_remove_private_as_replace_as_cmd);
18104 install_element(BGP_IPV6_NODE,
18105 &no_neighbor_remove_private_as_replace_as_cmd);
18106 install_element(BGP_IPV6_NODE,
18107 &neighbor_remove_private_as_all_replace_as_cmd);
18108 install_element(BGP_IPV6_NODE,
18109 &no_neighbor_remove_private_as_all_replace_as_cmd);
18110 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
18111 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
18112 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
18113 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
18114 install_element(BGP_IPV6M_NODE,
18115 &neighbor_remove_private_as_replace_as_cmd);
18116 install_element(BGP_IPV6M_NODE,
18117 &no_neighbor_remove_private_as_replace_as_cmd);
18118 install_element(BGP_IPV6M_NODE,
18119 &neighbor_remove_private_as_all_replace_as_cmd);
18120 install_element(BGP_IPV6M_NODE,
18121 &no_neighbor_remove_private_as_all_replace_as_cmd);
18122 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
18123 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
18124 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
18125 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
18126 install_element(BGP_IPV6L_NODE,
18127 &neighbor_remove_private_as_replace_as_cmd);
18128 install_element(BGP_IPV6L_NODE,
18129 &no_neighbor_remove_private_as_replace_as_cmd);
18130 install_element(BGP_IPV6L_NODE,
18131 &neighbor_remove_private_as_all_replace_as_cmd);
18132 install_element(BGP_IPV6L_NODE,
18133 &no_neighbor_remove_private_as_all_replace_as_cmd);
18134 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
18135 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
18136 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
18137 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18138 install_element(BGP_VPNV4_NODE,
18139 &neighbor_remove_private_as_replace_as_cmd);
18140 install_element(BGP_VPNV4_NODE,
18141 &no_neighbor_remove_private_as_replace_as_cmd);
18142 install_element(BGP_VPNV4_NODE,
18143 &neighbor_remove_private_as_all_replace_as_cmd);
18144 install_element(BGP_VPNV4_NODE,
18145 &no_neighbor_remove_private_as_all_replace_as_cmd);
18146 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
18147 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
18148 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
18149 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18150 install_element(BGP_VPNV6_NODE,
18151 &neighbor_remove_private_as_replace_as_cmd);
18152 install_element(BGP_VPNV6_NODE,
18153 &no_neighbor_remove_private_as_replace_as_cmd);
18154 install_element(BGP_VPNV6_NODE,
18155 &neighbor_remove_private_as_all_replace_as_cmd);
18156 install_element(BGP_VPNV6_NODE,
18157 &no_neighbor_remove_private_as_all_replace_as_cmd);
18158
18159 /* "neighbor send-community" commands.*/
18160 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
18161 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
18162 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
18163 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
18164 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
18165 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
18166 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
18167 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
18168 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
18169 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
18170 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
18171 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
18172 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
18173 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
18174 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
18175 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
18176 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
18177 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
18178 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
18179 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
18180 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
18181 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
18182 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
18183 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
18184 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
18185 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
18186 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
18187 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
18188 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
18189 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
18190 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
18191 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
18192 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
18193 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
18194 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
18195 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
18196
18197 /* "neighbor route-reflector" commands.*/
18198 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
18199 install_element(BGP_NODE,
18200 &no_neighbor_route_reflector_client_hidden_cmd);
18201 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
18202 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
18203 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
18204 install_element(BGP_IPV4M_NODE,
18205 &no_neighbor_route_reflector_client_cmd);
18206 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
18207 install_element(BGP_IPV4L_NODE,
18208 &no_neighbor_route_reflector_client_cmd);
18209 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
18210 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
18211 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
18212 install_element(BGP_IPV6M_NODE,
18213 &no_neighbor_route_reflector_client_cmd);
18214 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
18215 install_element(BGP_IPV6L_NODE,
18216 &no_neighbor_route_reflector_client_cmd);
18217 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
18218 install_element(BGP_VPNV4_NODE,
18219 &no_neighbor_route_reflector_client_cmd);
18220 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
18221 install_element(BGP_VPNV6_NODE,
18222 &no_neighbor_route_reflector_client_cmd);
18223 install_element(BGP_FLOWSPECV4_NODE,
18224 &neighbor_route_reflector_client_cmd);
18225 install_element(BGP_FLOWSPECV4_NODE,
18226 &no_neighbor_route_reflector_client_cmd);
18227 install_element(BGP_FLOWSPECV6_NODE,
18228 &neighbor_route_reflector_client_cmd);
18229 install_element(BGP_FLOWSPECV6_NODE,
18230 &no_neighbor_route_reflector_client_cmd);
18231 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
18232 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
18233
18234 /* "neighbor route-server" commands.*/
18235 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
18236 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
18237 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
18238 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
18239 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
18240 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
18241 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
18242 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
18243 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
18244 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
18245 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
18246 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
18247 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
18248 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
18249 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
18250 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
18251 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
18252 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
18253 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
18254 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
18255 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
18256 install_element(BGP_FLOWSPECV4_NODE,
18257 &no_neighbor_route_server_client_cmd);
18258 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
18259 install_element(BGP_FLOWSPECV6_NODE,
18260 &no_neighbor_route_server_client_cmd);
18261
18262 /* "neighbor addpath-tx-all-paths" commands.*/
18263 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
18264 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
18265 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
18266 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18267 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
18268 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18269 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
18270 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18271 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
18272 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18273 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
18274 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18275 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
18276 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18277 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
18278 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18279 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
18280 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18281
18282 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
18283 install_element(BGP_NODE,
18284 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
18285 install_element(BGP_NODE,
18286 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
18287 install_element(BGP_IPV4_NODE,
18288 &neighbor_addpath_tx_bestpath_per_as_cmd);
18289 install_element(BGP_IPV4_NODE,
18290 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18291 install_element(BGP_IPV4M_NODE,
18292 &neighbor_addpath_tx_bestpath_per_as_cmd);
18293 install_element(BGP_IPV4M_NODE,
18294 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18295 install_element(BGP_IPV4L_NODE,
18296 &neighbor_addpath_tx_bestpath_per_as_cmd);
18297 install_element(BGP_IPV4L_NODE,
18298 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18299 install_element(BGP_IPV6_NODE,
18300 &neighbor_addpath_tx_bestpath_per_as_cmd);
18301 install_element(BGP_IPV6_NODE,
18302 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18303 install_element(BGP_IPV6M_NODE,
18304 &neighbor_addpath_tx_bestpath_per_as_cmd);
18305 install_element(BGP_IPV6M_NODE,
18306 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18307 install_element(BGP_IPV6L_NODE,
18308 &neighbor_addpath_tx_bestpath_per_as_cmd);
18309 install_element(BGP_IPV6L_NODE,
18310 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18311 install_element(BGP_VPNV4_NODE,
18312 &neighbor_addpath_tx_bestpath_per_as_cmd);
18313 install_element(BGP_VPNV4_NODE,
18314 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18315 install_element(BGP_VPNV6_NODE,
18316 &neighbor_addpath_tx_bestpath_per_as_cmd);
18317 install_element(BGP_VPNV6_NODE,
18318 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18319
18320 /* "neighbor sender-as-path-loop-detection" commands. */
18321 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
18322 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
18323
18324 /* "neighbor passive" commands. */
18325 install_element(BGP_NODE, &neighbor_passive_cmd);
18326 install_element(BGP_NODE, &no_neighbor_passive_cmd);
18327
18328
18329 /* "neighbor shutdown" commands. */
18330 install_element(BGP_NODE, &neighbor_shutdown_cmd);
18331 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
18332 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
18333 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
18334 install_element(BGP_NODE, &neighbor_shutdown_rtt_cmd);
18335 install_element(BGP_NODE, &no_neighbor_shutdown_rtt_cmd);
18336
18337 /* "neighbor capability extended-nexthop" commands.*/
18338 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
18339 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
18340
18341 /* "neighbor capability orf prefix-list" commands.*/
18342 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
18343 install_element(BGP_NODE,
18344 &no_neighbor_capability_orf_prefix_hidden_cmd);
18345 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
18346 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
18347 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
18348 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
18349 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
18350 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
18351 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
18352 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
18353 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
18354 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
18355 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
18356 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
18357
18358 /* "neighbor capability dynamic" commands.*/
18359 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
18360 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
18361
18362 /* "neighbor dont-capability-negotiate" commands. */
18363 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
18364 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
18365
18366 /* "neighbor ebgp-multihop" commands. */
18367 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
18368 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
18369 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
18370
18371 /* "neighbor disable-connected-check" commands. */
18372 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
18373 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
18374
18375 /* "neighbor enforce-first-as" commands. */
18376 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
18377 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
18378
18379 /* "neighbor description" commands. */
18380 install_element(BGP_NODE, &neighbor_description_cmd);
18381 install_element(BGP_NODE, &no_neighbor_description_cmd);
18382 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
18383
18384 /* "neighbor update-source" commands. "*/
18385 install_element(BGP_NODE, &neighbor_update_source_cmd);
18386 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
18387
18388 /* "neighbor default-originate" commands. */
18389 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
18390 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
18391 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
18392 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
18393 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
18394 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
18395 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
18396 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
18397 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
18398 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
18399 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
18400 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
18401 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
18402 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
18403 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
18404 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
18405 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
18406 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
18407 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
18408 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
18409 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
18410
18411 /* "neighbor port" commands. */
18412 install_element(BGP_NODE, &neighbor_port_cmd);
18413 install_element(BGP_NODE, &no_neighbor_port_cmd);
18414
18415 /* "neighbor weight" commands. */
18416 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
18417 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
18418
18419 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
18420 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
18421 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
18422 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
18423 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
18424 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
18425 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
18426 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
18427 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
18428 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
18429 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
18430 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
18431 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
18432 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
18433 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
18434 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
18435
18436 /* "neighbor override-capability" commands. */
18437 install_element(BGP_NODE, &neighbor_override_capability_cmd);
18438 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
18439
18440 /* "neighbor strict-capability-match" commands. */
18441 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
18442 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
18443
18444 /* "neighbor timers" commands. */
18445 install_element(BGP_NODE, &neighbor_timers_cmd);
18446 install_element(BGP_NODE, &no_neighbor_timers_cmd);
18447
18448 /* "neighbor timers connect" commands. */
18449 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
18450 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
18451
18452 /* "neighbor timers delayopen" commands. */
18453 install_element(BGP_NODE, &neighbor_timers_delayopen_cmd);
18454 install_element(BGP_NODE, &no_neighbor_timers_delayopen_cmd);
18455
18456 /* "neighbor advertisement-interval" commands. */
18457 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
18458 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
18459
18460 /* "neighbor interface" commands. */
18461 install_element(BGP_NODE, &neighbor_interface_cmd);
18462 install_element(BGP_NODE, &no_neighbor_interface_cmd);
18463
18464 /* "neighbor distribute" commands. */
18465 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
18466 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
18467 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
18468 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
18469 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
18470 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
18471 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
18472 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
18473 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
18474 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
18475 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
18476 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
18477 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
18478 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
18479 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
18480 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
18481 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
18482 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
18483
18484 /* "neighbor prefix-list" commands. */
18485 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
18486 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
18487 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
18488 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
18489 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
18490 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
18491 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
18492 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
18493 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
18494 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
18495 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
18496 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
18497 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
18498 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
18499 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
18500 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
18501 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
18502 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
18503 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
18504 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
18505 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
18506 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
18507
18508 /* "neighbor filter-list" commands. */
18509 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
18510 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
18511 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
18512 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
18513 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
18514 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
18515 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
18516 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
18517 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
18518 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
18519 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
18520 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
18521 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
18522 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
18523 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
18524 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
18525 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
18526 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
18527 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
18528 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
18529 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
18530 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
18531
18532 /* "neighbor route-map" commands. */
18533 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
18534 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
18535 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
18536 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
18537 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
18538 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
18539 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
18540 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
18541 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
18542 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
18543 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
18544 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
18545 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
18546 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
18547 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
18548 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
18549 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
18550 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
18551 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
18552 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
18553 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
18554 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
18555 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
18556 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
18557
18558 /* "neighbor unsuppress-map" commands. */
18559 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
18560 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
18561 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
18562 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
18563 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
18564 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
18565 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
18566 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
18567 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
18568 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
18569 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
18570 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
18571 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
18572 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
18573 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
18574 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
18575 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
18576 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
18577
18578 /* "neighbor advertise-map" commands. */
18579 install_element(BGP_NODE, &neighbor_advertise_map_hidden_cmd);
18580 install_element(BGP_IPV4_NODE, &neighbor_advertise_map_cmd);
18581 install_element(BGP_IPV4M_NODE, &neighbor_advertise_map_cmd);
18582 install_element(BGP_IPV4L_NODE, &neighbor_advertise_map_cmd);
18583 install_element(BGP_IPV6_NODE, &neighbor_advertise_map_cmd);
18584 install_element(BGP_IPV6M_NODE, &neighbor_advertise_map_cmd);
18585 install_element(BGP_IPV6L_NODE, &neighbor_advertise_map_cmd);
18586 install_element(BGP_VPNV4_NODE, &neighbor_advertise_map_cmd);
18587 install_element(BGP_VPNV6_NODE, &neighbor_advertise_map_cmd);
18588
18589 /* neighbor maximum-prefix-out commands. */
18590 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
18591 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
18592 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
18593 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
18594 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
18595 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
18596 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
18597 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
18598 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
18599 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
18600 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
18601 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
18602 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
18603 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
18604 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
18605 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
18606 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
18607 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
18608
18609 /* "neighbor maximum-prefix" commands. */
18610 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
18611 install_element(BGP_NODE,
18612 &neighbor_maximum_prefix_threshold_hidden_cmd);
18613 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
18614 install_element(BGP_NODE,
18615 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
18616 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
18617 install_element(BGP_NODE,
18618 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
18619 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
18620 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
18621 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
18622 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
18623 install_element(BGP_IPV4_NODE,
18624 &neighbor_maximum_prefix_threshold_warning_cmd);
18625 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
18626 install_element(BGP_IPV4_NODE,
18627 &neighbor_maximum_prefix_threshold_restart_cmd);
18628 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
18629 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
18630 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
18631 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
18632 install_element(BGP_IPV4M_NODE,
18633 &neighbor_maximum_prefix_threshold_warning_cmd);
18634 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
18635 install_element(BGP_IPV4M_NODE,
18636 &neighbor_maximum_prefix_threshold_restart_cmd);
18637 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
18638 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
18639 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
18640 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
18641 install_element(BGP_IPV4L_NODE,
18642 &neighbor_maximum_prefix_threshold_warning_cmd);
18643 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
18644 install_element(BGP_IPV4L_NODE,
18645 &neighbor_maximum_prefix_threshold_restart_cmd);
18646 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
18647 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
18648 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
18649 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
18650 install_element(BGP_IPV6_NODE,
18651 &neighbor_maximum_prefix_threshold_warning_cmd);
18652 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
18653 install_element(BGP_IPV6_NODE,
18654 &neighbor_maximum_prefix_threshold_restart_cmd);
18655 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
18656 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
18657 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
18658 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
18659 install_element(BGP_IPV6M_NODE,
18660 &neighbor_maximum_prefix_threshold_warning_cmd);
18661 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
18662 install_element(BGP_IPV6M_NODE,
18663 &neighbor_maximum_prefix_threshold_restart_cmd);
18664 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
18665 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
18666 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
18667 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
18668 install_element(BGP_IPV6L_NODE,
18669 &neighbor_maximum_prefix_threshold_warning_cmd);
18670 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
18671 install_element(BGP_IPV6L_NODE,
18672 &neighbor_maximum_prefix_threshold_restart_cmd);
18673 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
18674 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
18675 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
18676 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
18677 install_element(BGP_VPNV4_NODE,
18678 &neighbor_maximum_prefix_threshold_warning_cmd);
18679 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
18680 install_element(BGP_VPNV4_NODE,
18681 &neighbor_maximum_prefix_threshold_restart_cmd);
18682 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
18683 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
18684 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
18685 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
18686 install_element(BGP_VPNV6_NODE,
18687 &neighbor_maximum_prefix_threshold_warning_cmd);
18688 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
18689 install_element(BGP_VPNV6_NODE,
18690 &neighbor_maximum_prefix_threshold_restart_cmd);
18691 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
18692
18693 /* "neighbor allowas-in" */
18694 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
18695 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
18696 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
18697 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
18698 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
18699 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
18700 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
18701 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
18702 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
18703 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
18704 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
18705 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
18706 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
18707 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
18708 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
18709 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
18710 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
18711 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
18712 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
18713 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
18714
18715 /* address-family commands. */
18716 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
18717 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
18718 #ifdef KEEP_OLD_VPN_COMMANDS
18719 install_element(BGP_NODE, &address_family_vpnv4_cmd);
18720 install_element(BGP_NODE, &address_family_vpnv6_cmd);
18721 #endif /* KEEP_OLD_VPN_COMMANDS */
18722
18723 install_element(BGP_NODE, &address_family_evpn_cmd);
18724
18725 /* "exit-address-family" command. */
18726 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
18727 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
18728 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
18729 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
18730 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
18731 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
18732 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
18733 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
18734 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
18735 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
18736 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
18737
18738 /* "clear ip bgp commands" */
18739 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
18740
18741 /* clear ip bgp prefix */
18742 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
18743 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
18744 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
18745
18746 /* "show [ip] bgp summary" commands. */
18747 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
18748 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
18749 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
18750 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
18751 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
18752 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
18753 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
18754
18755 /* "show [ip] bgp neighbors" commands. */
18756 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
18757
18758 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
18759
18760 /* "show [ip] bgp peer-group" commands. */
18761 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
18762
18763 /* "show [ip] bgp paths" commands. */
18764 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
18765
18766 /* "show [ip] bgp community" commands. */
18767 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
18768
18769 /* "show ip bgp large-community" commands. */
18770 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
18771 /* "show [ip] bgp attribute-info" commands. */
18772 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
18773 /* "show [ip] bgp route-leak" command */
18774 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
18775
18776 /* "redistribute" commands. */
18777 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
18778 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
18779 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
18780 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
18781 install_element(BGP_NODE,
18782 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
18783 install_element(BGP_NODE,
18784 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
18785 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
18786 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
18787 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
18788 install_element(BGP_NODE,
18789 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
18790 install_element(BGP_NODE,
18791 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
18792 install_element(BGP_NODE,
18793 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
18794 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
18795 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
18796 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
18797 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
18798 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
18799 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
18800 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
18801 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
18802 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
18803 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
18804 install_element(BGP_IPV4_NODE,
18805 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
18806 install_element(BGP_IPV4_NODE,
18807 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
18808 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
18809 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
18810 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
18811 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
18812 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
18813 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
18814
18815 /* import|export vpn [route-map WORD] */
18816 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
18817 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
18818
18819 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
18820 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
18821
18822 /* ttl_security commands */
18823 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
18824 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
18825
18826 /* "show [ip] bgp memory" commands. */
18827 install_element(VIEW_NODE, &show_bgp_memory_cmd);
18828
18829 /* "show bgp martian next-hop" */
18830 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
18831
18832 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
18833
18834 /* "show [ip] bgp views" commands. */
18835 install_element(VIEW_NODE, &show_bgp_views_cmd);
18836
18837 /* "show [ip] bgp vrfs" commands. */
18838 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
18839
18840 /* Community-list. */
18841 community_list_vty();
18842
18843 /* vpn-policy commands */
18844 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
18845 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
18846 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
18847 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
18848 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
18849 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
18850 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
18851 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
18852 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
18853 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
18854 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
18855 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
18856
18857 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
18858 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
18859
18860 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
18861 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
18862 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
18863 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
18864 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
18865 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
18866 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
18867 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
18868 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
18869 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
18870 }
18871
18872 #include "memory.h"
18873 #include "bgp_regex.h"
18874 #include "bgp_clist.h"
18875 #include "bgp_ecommunity.h"
18876
18877 /* VTY functions. */
18878
18879 /* Direction value to string conversion. */
18880 static const char *community_direct_str(int direct)
18881 {
18882 switch (direct) {
18883 case COMMUNITY_DENY:
18884 return "deny";
18885 case COMMUNITY_PERMIT:
18886 return "permit";
18887 default:
18888 return "unknown";
18889 }
18890 }
18891
18892 /* Display error string. */
18893 static void community_list_perror(struct vty *vty, int ret)
18894 {
18895 switch (ret) {
18896 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
18897 vty_out(vty, "%% Can't find community-list\n");
18898 break;
18899 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
18900 vty_out(vty, "%% Malformed community-list value\n");
18901 break;
18902 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
18903 vty_out(vty,
18904 "%% Community name conflict, previously defined as standard community\n");
18905 break;
18906 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
18907 vty_out(vty,
18908 "%% Community name conflict, previously defined as expanded community\n");
18909 break;
18910 }
18911 }
18912
18913 /* "community-list" keyword help string. */
18914 #define COMMUNITY_LIST_STR "Add a community list entry\n"
18915
18916 /*community-list standard */
18917 DEFUN (community_list_standard,
18918 bgp_community_list_standard_cmd,
18919 "bgp community-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
18920 BGP_STR
18921 COMMUNITY_LIST_STR
18922 "Community list number (standard)\n"
18923 "Add an standard community-list entry\n"
18924 "Community list name\n"
18925 "Sequence number of an entry\n"
18926 "Sequence number\n"
18927 "Specify community to reject\n"
18928 "Specify community to accept\n"
18929 COMMUNITY_VAL_STR)
18930 {
18931 char *cl_name_or_number = NULL;
18932 char *seq = NULL;
18933 int direct = 0;
18934 int style = COMMUNITY_LIST_STANDARD;
18935 int idx = 0;
18936
18937 argv_find(argv, argc, "(1-4294967295)", &idx);
18938 if (idx)
18939 seq = argv[idx]->arg;
18940
18941 idx = 0;
18942 argv_find(argv, argc, "(1-99)", &idx);
18943 argv_find(argv, argc, "WORD", &idx);
18944 cl_name_or_number = argv[idx]->arg;
18945 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
18946 : COMMUNITY_DENY;
18947 argv_find(argv, argc, "AA:NN", &idx);
18948 char *str = argv_concat(argv, argc, idx);
18949
18950 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
18951 direct, style);
18952
18953 XFREE(MTYPE_TMP, str);
18954
18955 if (ret < 0) {
18956 /* Display error string. */
18957 community_list_perror(vty, ret);
18958 return CMD_WARNING_CONFIG_FAILED;
18959 }
18960
18961 return CMD_SUCCESS;
18962 }
18963
18964 DEFUN (no_community_list_standard_all,
18965 no_bgp_community_list_standard_all_cmd,
18966 "no bgp community-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
18967 NO_STR
18968 BGP_STR
18969 COMMUNITY_LIST_STR
18970 "Community list number (standard)\n"
18971 "Add an standard community-list entry\n"
18972 "Community list name\n"
18973 "Sequence number of an entry\n"
18974 "Sequence number\n"
18975 "Specify community to reject\n"
18976 "Specify community to accept\n"
18977 COMMUNITY_VAL_STR)
18978 {
18979 char *cl_name_or_number = NULL;
18980 char *str = NULL;
18981 int direct = 0;
18982 int style = COMMUNITY_LIST_STANDARD;
18983 char *seq = NULL;
18984 int idx = 0;
18985
18986 argv_find(argv, argc, "(1-4294967295)", &idx);
18987 if (idx)
18988 seq = argv[idx]->arg;
18989
18990 idx = 0;
18991 argv_find(argv, argc, "permit", &idx);
18992 argv_find(argv, argc, "deny", &idx);
18993
18994 if (idx) {
18995 direct = argv_find(argv, argc, "permit", &idx)
18996 ? COMMUNITY_PERMIT
18997 : COMMUNITY_DENY;
18998
18999 idx = 0;
19000 argv_find(argv, argc, "AA:NN", &idx);
19001 str = argv_concat(argv, argc, idx);
19002 }
19003
19004 idx = 0;
19005 argv_find(argv, argc, "(1-99)", &idx);
19006 argv_find(argv, argc, "WORD", &idx);
19007 cl_name_or_number = argv[idx]->arg;
19008
19009 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
19010 direct, style);
19011
19012 XFREE(MTYPE_TMP, str);
19013
19014 if (ret < 0) {
19015 community_list_perror(vty, ret);
19016 return CMD_WARNING_CONFIG_FAILED;
19017 }
19018
19019 return CMD_SUCCESS;
19020 }
19021
19022 ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
19023 "no bgp community-list <(1-99)|standard WORD>",
19024 NO_STR BGP_STR COMMUNITY_LIST_STR
19025 "Community list number (standard)\n"
19026 "Add an standard community-list entry\n"
19027 "Community list name\n")
19028
19029 /*community-list expanded */
19030 DEFUN (community_list_expanded_all,
19031 bgp_community_list_expanded_all_cmd,
19032 "bgp community-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
19033 BGP_STR
19034 COMMUNITY_LIST_STR
19035 "Community list number (expanded)\n"
19036 "Add an expanded community-list entry\n"
19037 "Community list name\n"
19038 "Sequence number of an entry\n"
19039 "Sequence number\n"
19040 "Specify community to reject\n"
19041 "Specify community to accept\n"
19042 COMMUNITY_VAL_STR)
19043 {
19044 char *cl_name_or_number = NULL;
19045 char *seq = NULL;
19046 int direct = 0;
19047 int style = COMMUNITY_LIST_EXPANDED;
19048 int idx = 0;
19049
19050 argv_find(argv, argc, "(1-4294967295)", &idx);
19051 if (idx)
19052 seq = argv[idx]->arg;
19053
19054 idx = 0;
19055
19056 argv_find(argv, argc, "(100-500)", &idx);
19057 argv_find(argv, argc, "WORD", &idx);
19058 cl_name_or_number = argv[idx]->arg;
19059 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19060 : COMMUNITY_DENY;
19061 argv_find(argv, argc, "AA:NN", &idx);
19062 char *str = argv_concat(argv, argc, idx);
19063
19064 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19065 direct, style);
19066
19067 XFREE(MTYPE_TMP, str);
19068
19069 if (ret < 0) {
19070 /* Display error string. */
19071 community_list_perror(vty, ret);
19072 return CMD_WARNING_CONFIG_FAILED;
19073 }
19074
19075 return CMD_SUCCESS;
19076 }
19077
19078 DEFUN (no_community_list_expanded_all,
19079 no_bgp_community_list_expanded_all_cmd,
19080 "no bgp community-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
19081 NO_STR
19082 BGP_STR
19083 COMMUNITY_LIST_STR
19084 "Community list number (expanded)\n"
19085 "Add an expanded community-list entry\n"
19086 "Community list name\n"
19087 "Sequence number of an entry\n"
19088 "Sequence number\n"
19089 "Specify community to reject\n"
19090 "Specify community to accept\n"
19091 COMMUNITY_VAL_STR)
19092 {
19093 char *cl_name_or_number = NULL;
19094 char *seq = NULL;
19095 char *str = NULL;
19096 int direct = 0;
19097 int style = COMMUNITY_LIST_EXPANDED;
19098 int idx = 0;
19099
19100 argv_find(argv, argc, "(1-4294967295)", &idx);
19101 if (idx)
19102 seq = argv[idx]->arg;
19103
19104 idx = 0;
19105 argv_find(argv, argc, "permit", &idx);
19106 argv_find(argv, argc, "deny", &idx);
19107
19108 if (idx) {
19109 direct = argv_find(argv, argc, "permit", &idx)
19110 ? COMMUNITY_PERMIT
19111 : COMMUNITY_DENY;
19112
19113 idx = 0;
19114 argv_find(argv, argc, "AA:NN", &idx);
19115 str = argv_concat(argv, argc, idx);
19116 }
19117
19118 idx = 0;
19119 argv_find(argv, argc, "(100-500)", &idx);
19120 argv_find(argv, argc, "WORD", &idx);
19121 cl_name_or_number = argv[idx]->arg;
19122
19123 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
19124 direct, style);
19125
19126 XFREE(MTYPE_TMP, str);
19127
19128 if (ret < 0) {
19129 community_list_perror(vty, ret);
19130 return CMD_WARNING_CONFIG_FAILED;
19131 }
19132
19133 return CMD_SUCCESS;
19134 }
19135
19136 ALIAS(no_community_list_expanded_all,
19137 no_bgp_community_list_expanded_all_list_cmd,
19138 "no bgp community-list <(100-500)|expanded WORD>",
19139 NO_STR BGP_STR COMMUNITY_LIST_STR
19140 "Community list number (expanded)\n"
19141 "Add an expanded community-list entry\n"
19142 "Community list name\n")
19143
19144 /* Return configuration string of community-list entry. */
19145 static const char *community_list_config_str(struct community_entry *entry)
19146 {
19147 const char *str;
19148
19149 if (entry->any)
19150 str = "";
19151 else {
19152 if (entry->style == COMMUNITY_LIST_STANDARD)
19153 str = community_str(entry->u.com, false);
19154 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
19155 str = lcommunity_str(entry->u.lcom, false);
19156 else
19157 str = entry->config;
19158 }
19159 return str;
19160 }
19161
19162 static void community_list_show(struct vty *vty, struct community_list *list)
19163 {
19164 struct community_entry *entry;
19165
19166 for (entry = list->head; entry; entry = entry->next) {
19167 if (entry == list->head) {
19168 if (all_digit(list->name))
19169 vty_out(vty, "Community %s list %s\n",
19170 entry->style == COMMUNITY_LIST_STANDARD
19171 ? "standard"
19172 : "(expanded) access",
19173 list->name);
19174 else
19175 vty_out(vty, "Named Community %s list %s\n",
19176 entry->style == COMMUNITY_LIST_STANDARD
19177 ? "standard"
19178 : "expanded",
19179 list->name);
19180 }
19181 if (entry->any)
19182 vty_out(vty, " %s\n",
19183 community_direct_str(entry->direct));
19184 else
19185 vty_out(vty, " %s %s\n",
19186 community_direct_str(entry->direct),
19187 community_list_config_str(entry));
19188 }
19189 }
19190
19191 DEFUN (show_community_list,
19192 show_bgp_community_list_cmd,
19193 "show bgp community-list",
19194 SHOW_STR
19195 BGP_STR
19196 "List community-list\n")
19197 {
19198 struct community_list *list;
19199 struct community_list_master *cm;
19200
19201 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
19202 if (!cm)
19203 return CMD_SUCCESS;
19204
19205 for (list = cm->num.head; list; list = list->next)
19206 community_list_show(vty, list);
19207
19208 for (list = cm->str.head; list; list = list->next)
19209 community_list_show(vty, list);
19210
19211 return CMD_SUCCESS;
19212 }
19213
19214 DEFUN (show_community_list_arg,
19215 show_bgp_community_list_arg_cmd,
19216 "show bgp community-list <(1-500)|WORD> detail",
19217 SHOW_STR
19218 BGP_STR
19219 "List community-list\n"
19220 "Community-list number\n"
19221 "Community-list name\n"
19222 "Detailed information on community-list\n")
19223 {
19224 int idx_comm_list = 3;
19225 struct community_list *list;
19226
19227 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
19228 COMMUNITY_LIST_MASTER);
19229 if (!list) {
19230 vty_out(vty, "%% Can't find community-list\n");
19231 return CMD_WARNING;
19232 }
19233
19234 community_list_show(vty, list);
19235
19236 return CMD_SUCCESS;
19237 }
19238
19239 /*
19240 * Large Community code.
19241 */
19242 static int lcommunity_list_set_vty(struct vty *vty, int argc,
19243 struct cmd_token **argv, int style,
19244 int reject_all_digit_name)
19245 {
19246 int ret;
19247 int direct;
19248 char *str;
19249 int idx = 0;
19250 char *cl_name;
19251 char *seq = NULL;
19252
19253 if (argv_find(argv, argc, "(1-4294967295)", &idx))
19254 seq = argv[idx]->arg;
19255
19256 idx = 0;
19257 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19258 : COMMUNITY_DENY;
19259
19260 /* All digit name check. */
19261 idx = 0;
19262 argv_find(argv, argc, "WORD", &idx);
19263 argv_find(argv, argc, "(1-99)", &idx);
19264 argv_find(argv, argc, "(100-500)", &idx);
19265 cl_name = argv[idx]->arg;
19266 if (reject_all_digit_name && all_digit(cl_name)) {
19267 vty_out(vty, "%% Community name cannot have all digits\n");
19268 return CMD_WARNING_CONFIG_FAILED;
19269 }
19270
19271 idx = 0;
19272 argv_find(argv, argc, "AA:BB:CC", &idx);
19273 argv_find(argv, argc, "LINE", &idx);
19274 /* Concat community string argument. */
19275 if (idx)
19276 str = argv_concat(argv, argc, idx);
19277 else
19278 str = NULL;
19279
19280 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
19281
19282 /* Free temporary community list string allocated by
19283 argv_concat(). */
19284 XFREE(MTYPE_TMP, str);
19285
19286 if (ret < 0) {
19287 community_list_perror(vty, ret);
19288 return CMD_WARNING_CONFIG_FAILED;
19289 }
19290 return CMD_SUCCESS;
19291 }
19292
19293 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
19294 struct cmd_token **argv, int style)
19295 {
19296 int ret;
19297 int direct = 0;
19298 char *str = NULL;
19299 int idx = 0;
19300 char *seq = NULL;
19301
19302 if (argv_find(argv, argc, "(1-4294967295)", &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 /* Check the list direct. */
19311 if (strncmp(argv[idx]->arg, "p", 1) == 0)
19312 direct = COMMUNITY_PERMIT;
19313 else
19314 direct = COMMUNITY_DENY;
19315
19316 idx = 0;
19317 argv_find(argv, argc, "LINE", &idx);
19318 argv_find(argv, argc, "AA:AA:NN", &idx);
19319 /* Concat community string argument. */
19320 str = argv_concat(argv, argc, idx);
19321 }
19322
19323 idx = 0;
19324 argv_find(argv, argc, "(1-99)", &idx);
19325 argv_find(argv, argc, "(100-500)", &idx);
19326 argv_find(argv, argc, "WORD", &idx);
19327
19328 /* Unset community list. */
19329 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
19330 style);
19331
19332 /* Free temporary community list string allocated by
19333 argv_concat(). */
19334 XFREE(MTYPE_TMP, str);
19335
19336 if (ret < 0) {
19337 community_list_perror(vty, ret);
19338 return CMD_WARNING_CONFIG_FAILED;
19339 }
19340
19341 return CMD_SUCCESS;
19342 }
19343
19344 /* "large-community-list" keyword help string. */
19345 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
19346 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
19347
19348 DEFUN (lcommunity_list_standard,
19349 bgp_lcommunity_list_standard_cmd,
19350 "bgp large-community-list (1-99) [seq (1-4294967295)] <deny|permit> AA:BB:CC...",
19351 BGP_STR
19352 LCOMMUNITY_LIST_STR
19353 "Large Community list number (standard)\n"
19354 "Sequence number of an entry\n"
19355 "Sequence number\n"
19356 "Specify large community to reject\n"
19357 "Specify large community to accept\n"
19358 LCOMMUNITY_VAL_STR)
19359 {
19360 return lcommunity_list_set_vty(vty, argc, argv,
19361 LARGE_COMMUNITY_LIST_STANDARD, 0);
19362 }
19363
19364 DEFUN (lcommunity_list_expanded,
19365 bgp_lcommunity_list_expanded_cmd,
19366 "bgp large-community-list (100-500) [seq (1-4294967295)] <deny|permit> LINE...",
19367 BGP_STR
19368 LCOMMUNITY_LIST_STR
19369 "Large Community list number (expanded)\n"
19370 "Sequence number of an entry\n"
19371 "Sequence number\n"
19372 "Specify large community to reject\n"
19373 "Specify large community to accept\n"
19374 "An ordered list as a regular-expression\n")
19375 {
19376 return lcommunity_list_set_vty(vty, argc, argv,
19377 LARGE_COMMUNITY_LIST_EXPANDED, 0);
19378 }
19379
19380 DEFUN (lcommunity_list_name_standard,
19381 bgp_lcommunity_list_name_standard_cmd,
19382 "bgp large-community-list standard WORD [seq (1-4294967295)] <deny|permit> AA:BB:CC...",
19383 BGP_STR
19384 LCOMMUNITY_LIST_STR
19385 "Specify standard large-community-list\n"
19386 "Large Community list name\n"
19387 "Sequence number of an entry\n"
19388 "Sequence number\n"
19389 "Specify large community to reject\n"
19390 "Specify large community to accept\n"
19391 LCOMMUNITY_VAL_STR)
19392 {
19393 return lcommunity_list_set_vty(vty, argc, argv,
19394 LARGE_COMMUNITY_LIST_STANDARD, 1);
19395 }
19396
19397 DEFUN (lcommunity_list_name_expanded,
19398 bgp_lcommunity_list_name_expanded_cmd,
19399 "bgp large-community-list expanded WORD [seq (1-4294967295)] <deny|permit> LINE...",
19400 BGP_STR
19401 LCOMMUNITY_LIST_STR
19402 "Specify expanded large-community-list\n"
19403 "Large Community list name\n"
19404 "Sequence number of an entry\n"
19405 "Sequence number\n"
19406 "Specify large community to reject\n"
19407 "Specify large community to accept\n"
19408 "An ordered list as a regular-expression\n")
19409 {
19410 return lcommunity_list_set_vty(vty, argc, argv,
19411 LARGE_COMMUNITY_LIST_EXPANDED, 1);
19412 }
19413
19414 DEFUN (no_lcommunity_list_all,
19415 no_bgp_lcommunity_list_all_cmd,
19416 "no bgp large-community-list <(1-99)|(100-500)|WORD>",
19417 NO_STR
19418 BGP_STR
19419 LCOMMUNITY_LIST_STR
19420 "Large Community list number (standard)\n"
19421 "Large Community list number (expanded)\n"
19422 "Large Community list name\n")
19423 {
19424 return lcommunity_list_unset_vty(vty, argc, argv,
19425 LARGE_COMMUNITY_LIST_STANDARD);
19426 }
19427
19428 DEFUN (no_lcommunity_list_name_standard_all,
19429 no_bgp_lcommunity_list_name_standard_all_cmd,
19430 "no bgp large-community-list standard WORD",
19431 NO_STR
19432 BGP_STR
19433 LCOMMUNITY_LIST_STR
19434 "Specify standard large-community-list\n"
19435 "Large Community list name\n")
19436 {
19437 return lcommunity_list_unset_vty(vty, argc, argv,
19438 LARGE_COMMUNITY_LIST_STANDARD);
19439 }
19440
19441 DEFUN (no_lcommunity_list_name_expanded_all,
19442 no_bgp_lcommunity_list_name_expanded_all_cmd,
19443 "no bgp large-community-list expanded WORD",
19444 NO_STR
19445 BGP_STR
19446 LCOMMUNITY_LIST_STR
19447 "Specify expanded large-community-list\n"
19448 "Large Community list name\n")
19449 {
19450 return lcommunity_list_unset_vty(vty, argc, argv,
19451 LARGE_COMMUNITY_LIST_EXPANDED);
19452 }
19453
19454 DEFUN (no_lcommunity_list_standard,
19455 no_bgp_lcommunity_list_standard_cmd,
19456 "no bgp large-community-list (1-99) [seq (1-4294967295)] <deny|permit> AA:AA:NN...",
19457 NO_STR
19458 BGP_STR
19459 LCOMMUNITY_LIST_STR
19460 "Large Community list number (standard)\n"
19461 "Sequence number of an entry\n"
19462 "Sequence number\n"
19463 "Specify large community to reject\n"
19464 "Specify large community to accept\n"
19465 LCOMMUNITY_VAL_STR)
19466 {
19467 return lcommunity_list_unset_vty(vty, argc, argv,
19468 LARGE_COMMUNITY_LIST_STANDARD);
19469 }
19470
19471 DEFUN (no_lcommunity_list_expanded,
19472 no_bgp_lcommunity_list_expanded_cmd,
19473 "no bgp large-community-list (100-500) [seq (1-4294967295)] <deny|permit> LINE...",
19474 NO_STR
19475 BGP_STR
19476 LCOMMUNITY_LIST_STR
19477 "Large Community list number (expanded)\n"
19478 "Sequence number of an entry\n"
19479 "Sequence number\n"
19480 "Specify large community to reject\n"
19481 "Specify large community to accept\n"
19482 "An ordered list as a regular-expression\n")
19483 {
19484 return lcommunity_list_unset_vty(vty, argc, argv,
19485 LARGE_COMMUNITY_LIST_EXPANDED);
19486 }
19487
19488 DEFUN (no_lcommunity_list_name_standard,
19489 no_bgp_lcommunity_list_name_standard_cmd,
19490 "no bgp large-community-list standard WORD [seq (1-4294967295)] <deny|permit> AA:AA:NN...",
19491 NO_STR
19492 BGP_STR
19493 LCOMMUNITY_LIST_STR
19494 "Specify standard large-community-list\n"
19495 "Large Community list name\n"
19496 "Sequence number of an entry\n"
19497 "Sequence number\n"
19498 "Specify large community to reject\n"
19499 "Specify large community to accept\n"
19500 LCOMMUNITY_VAL_STR)
19501 {
19502 return lcommunity_list_unset_vty(vty, argc, argv,
19503 LARGE_COMMUNITY_LIST_STANDARD);
19504 }
19505
19506 DEFUN (no_lcommunity_list_name_expanded,
19507 no_bgp_lcommunity_list_name_expanded_cmd,
19508 "no bgp large-community-list expanded WORD [seq (1-4294967295)] <deny|permit> LINE...",
19509 NO_STR
19510 BGP_STR
19511 LCOMMUNITY_LIST_STR
19512 "Specify expanded large-community-list\n"
19513 "Large community list name\n"
19514 "Sequence number of an entry\n"
19515 "Sequence number\n"
19516 "Specify large community to reject\n"
19517 "Specify large community to accept\n"
19518 "An ordered list as a regular-expression\n")
19519 {
19520 return lcommunity_list_unset_vty(vty, argc, argv,
19521 LARGE_COMMUNITY_LIST_EXPANDED);
19522 }
19523
19524 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
19525 {
19526 struct community_entry *entry;
19527
19528 for (entry = list->head; entry; entry = entry->next) {
19529 if (entry == list->head) {
19530 if (all_digit(list->name))
19531 vty_out(vty, "Large community %s list %s\n",
19532 entry->style ==
19533 LARGE_COMMUNITY_LIST_STANDARD
19534 ? "standard"
19535 : "(expanded) access",
19536 list->name);
19537 else
19538 vty_out(vty,
19539 "Named large community %s list %s\n",
19540 entry->style ==
19541 LARGE_COMMUNITY_LIST_STANDARD
19542 ? "standard"
19543 : "expanded",
19544 list->name);
19545 }
19546 if (entry->any)
19547 vty_out(vty, " %s\n",
19548 community_direct_str(entry->direct));
19549 else
19550 vty_out(vty, " %s %s\n",
19551 community_direct_str(entry->direct),
19552 community_list_config_str(entry));
19553 }
19554 }
19555
19556 DEFUN (show_lcommunity_list,
19557 show_bgp_lcommunity_list_cmd,
19558 "show bgp large-community-list",
19559 SHOW_STR
19560 BGP_STR
19561 "List large-community list\n")
19562 {
19563 struct community_list *list;
19564 struct community_list_master *cm;
19565
19566 cm = community_list_master_lookup(bgp_clist,
19567 LARGE_COMMUNITY_LIST_MASTER);
19568 if (!cm)
19569 return CMD_SUCCESS;
19570
19571 for (list = cm->num.head; list; list = list->next)
19572 lcommunity_list_show(vty, list);
19573
19574 for (list = cm->str.head; list; list = list->next)
19575 lcommunity_list_show(vty, list);
19576
19577 return CMD_SUCCESS;
19578 }
19579
19580 DEFUN (show_lcommunity_list_arg,
19581 show_bgp_lcommunity_list_arg_cmd,
19582 "show bgp large-community-list <(1-500)|WORD> detail",
19583 SHOW_STR
19584 BGP_STR
19585 "List large-community list\n"
19586 "Large-community-list number\n"
19587 "Large-community-list name\n"
19588 "Detailed information on large-community-list\n")
19589 {
19590 struct community_list *list;
19591
19592 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
19593 LARGE_COMMUNITY_LIST_MASTER);
19594 if (!list) {
19595 vty_out(vty, "%% Can't find large-community-list\n");
19596 return CMD_WARNING;
19597 }
19598
19599 lcommunity_list_show(vty, list);
19600
19601 return CMD_SUCCESS;
19602 }
19603
19604 /* "extcommunity-list" keyword help string. */
19605 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
19606 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
19607
19608 DEFUN (extcommunity_list_standard,
19609 bgp_extcommunity_list_standard_cmd,
19610 "bgp extcommunity-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
19611 BGP_STR
19612 EXTCOMMUNITY_LIST_STR
19613 "Extended Community list number (standard)\n"
19614 "Specify standard extcommunity-list\n"
19615 "Community list name\n"
19616 "Sequence number of an entry\n"
19617 "Sequence number\n"
19618 "Specify community to reject\n"
19619 "Specify community to accept\n"
19620 EXTCOMMUNITY_VAL_STR)
19621 {
19622 int style = EXTCOMMUNITY_LIST_STANDARD;
19623 int direct = 0;
19624 char *cl_number_or_name = NULL;
19625 char *seq = NULL;
19626
19627 int idx = 0;
19628
19629 argv_find(argv, argc, "(1-99)", &idx);
19630 argv_find(argv, argc, "WORD", &idx);
19631 cl_number_or_name = argv[idx]->arg;
19632
19633 if (argv_find(argv, argc, "(1-4294967295)", &idx))
19634 seq = argv[idx]->arg;
19635
19636 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19637 : COMMUNITY_DENY;
19638 argv_find(argv, argc, "AA:NN", &idx);
19639 char *str = argv_concat(argv, argc, idx);
19640
19641 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
19642 direct, style);
19643
19644 XFREE(MTYPE_TMP, str);
19645
19646 if (ret < 0) {
19647 community_list_perror(vty, ret);
19648 return CMD_WARNING_CONFIG_FAILED;
19649 }
19650
19651 return CMD_SUCCESS;
19652 }
19653
19654 DEFUN (extcommunity_list_name_expanded,
19655 bgp_extcommunity_list_name_expanded_cmd,
19656 "bgp extcommunity-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> LINE...",
19657 BGP_STR
19658 EXTCOMMUNITY_LIST_STR
19659 "Extended Community list number (expanded)\n"
19660 "Specify expanded extcommunity-list\n"
19661 "Extended Community list name\n"
19662 "Sequence number of an entry\n"
19663 "Sequence number\n"
19664 "Specify community to reject\n"
19665 "Specify community to accept\n"
19666 "An ordered list as a regular-expression\n")
19667 {
19668 int style = EXTCOMMUNITY_LIST_EXPANDED;
19669 int direct = 0;
19670 char *cl_number_or_name = NULL;
19671 char *seq = NULL;
19672 int idx = 0;
19673
19674 argv_find(argv, argc, "(100-500)", &idx);
19675 argv_find(argv, argc, "WORD", &idx);
19676 cl_number_or_name = argv[idx]->arg;
19677
19678 if (argv_find(argv, argc, "(1-4294967295)", &idx))
19679 seq = argv[idx]->arg;
19680
19681 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19682 : COMMUNITY_DENY;
19683 argv_find(argv, argc, "LINE", &idx);
19684 char *str = argv_concat(argv, argc, idx);
19685
19686 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
19687 direct, style);
19688
19689 XFREE(MTYPE_TMP, str);
19690
19691 if (ret < 0) {
19692 community_list_perror(vty, ret);
19693 return CMD_WARNING_CONFIG_FAILED;
19694 }
19695
19696 return CMD_SUCCESS;
19697 }
19698
19699 DEFUN (no_extcommunity_list_standard_all,
19700 no_bgp_extcommunity_list_standard_all_cmd,
19701 "no bgp extcommunity-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
19702 NO_STR
19703 BGP_STR
19704 EXTCOMMUNITY_LIST_STR
19705 "Extended Community list number (standard)\n"
19706 "Specify standard extcommunity-list\n"
19707 "Community list name\n"
19708 "Sequence number of an entry\n"
19709 "Sequence number\n"
19710 "Specify community to reject\n"
19711 "Specify community to accept\n"
19712 EXTCOMMUNITY_VAL_STR)
19713 {
19714 int style = EXTCOMMUNITY_LIST_STANDARD;
19715 int direct = 0;
19716 char *cl_number_or_name = NULL;
19717 char *str = NULL;
19718 char *seq = NULL;
19719 int idx = 0;
19720
19721 if (argv_find(argv, argc, "(1-4294967295)", &idx))
19722 seq = argv[idx]->arg;
19723
19724 idx = 0;
19725 argv_find(argv, argc, "permit", &idx);
19726 argv_find(argv, argc, "deny", &idx);
19727 if (idx) {
19728 direct = argv_find(argv, argc, "permit", &idx)
19729 ? COMMUNITY_PERMIT
19730 : COMMUNITY_DENY;
19731
19732 idx = 0;
19733 argv_find(argv, argc, "AA:NN", &idx);
19734 str = argv_concat(argv, argc, idx);
19735 }
19736
19737 idx = 0;
19738 argv_find(argv, argc, "(1-99)", &idx);
19739 argv_find(argv, argc, "WORD", &idx);
19740 cl_number_or_name = argv[idx]->arg;
19741
19742 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
19743 seq, direct, style);
19744
19745 XFREE(MTYPE_TMP, str);
19746
19747 if (ret < 0) {
19748 community_list_perror(vty, ret);
19749 return CMD_WARNING_CONFIG_FAILED;
19750 }
19751
19752 return CMD_SUCCESS;
19753 }
19754
19755 ALIAS(no_extcommunity_list_standard_all,
19756 no_bgp_extcommunity_list_standard_all_list_cmd,
19757 "no bgp extcommunity-list <(1-99)|standard WORD>",
19758 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
19759 "Extended Community list number (standard)\n"
19760 "Specify standard extcommunity-list\n"
19761 "Community list name\n")
19762
19763 DEFUN (no_extcommunity_list_expanded_all,
19764 no_bgp_extcommunity_list_expanded_all_cmd,
19765 "no bgp extcommunity-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> LINE...",
19766 NO_STR
19767 BGP_STR
19768 EXTCOMMUNITY_LIST_STR
19769 "Extended Community list number (expanded)\n"
19770 "Specify expanded extcommunity-list\n"
19771 "Extended Community list name\n"
19772 "Sequence number of an entry\n"
19773 "Sequence number\n"
19774 "Specify community to reject\n"
19775 "Specify community to accept\n"
19776 "An ordered list as a regular-expression\n")
19777 {
19778 int style = EXTCOMMUNITY_LIST_EXPANDED;
19779 int direct = 0;
19780 char *cl_number_or_name = NULL;
19781 char *str = NULL;
19782 char *seq = NULL;
19783 int idx = 0;
19784
19785 if (argv_find(argv, argc, "(1-4294967295)", &idx))
19786 seq = argv[idx]->arg;
19787
19788 idx = 0;
19789 argv_find(argv, argc, "permit", &idx);
19790 argv_find(argv, argc, "deny", &idx);
19791
19792 if (idx) {
19793 direct = argv_find(argv, argc, "permit", &idx)
19794 ? COMMUNITY_PERMIT
19795 : COMMUNITY_DENY;
19796
19797 idx = 0;
19798 argv_find(argv, argc, "LINE", &idx);
19799 str = argv_concat(argv, argc, idx);
19800 }
19801
19802 idx = 0;
19803 argv_find(argv, argc, "(100-500)", &idx);
19804 argv_find(argv, argc, "WORD", &idx);
19805 cl_number_or_name = argv[idx]->arg;
19806
19807 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
19808 seq, direct, style);
19809
19810 XFREE(MTYPE_TMP, str);
19811
19812 if (ret < 0) {
19813 community_list_perror(vty, ret);
19814 return CMD_WARNING_CONFIG_FAILED;
19815 }
19816
19817 return CMD_SUCCESS;
19818 }
19819
19820 ALIAS(no_extcommunity_list_expanded_all,
19821 no_bgp_extcommunity_list_expanded_all_list_cmd,
19822 "no bgp extcommunity-list <(100-500)|expanded WORD>",
19823 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
19824 "Extended Community list number (expanded)\n"
19825 "Specify expanded extcommunity-list\n"
19826 "Extended Community list name\n")
19827
19828 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
19829 {
19830 struct community_entry *entry;
19831
19832 for (entry = list->head; entry; entry = entry->next) {
19833 if (entry == list->head) {
19834 if (all_digit(list->name))
19835 vty_out(vty, "Extended community %s list %s\n",
19836 entry->style == EXTCOMMUNITY_LIST_STANDARD
19837 ? "standard"
19838 : "(expanded) access",
19839 list->name);
19840 else
19841 vty_out(vty,
19842 "Named extended community %s list %s\n",
19843 entry->style == EXTCOMMUNITY_LIST_STANDARD
19844 ? "standard"
19845 : "expanded",
19846 list->name);
19847 }
19848 if (entry->any)
19849 vty_out(vty, " %s\n",
19850 community_direct_str(entry->direct));
19851 else
19852 vty_out(vty, " %s %s\n",
19853 community_direct_str(entry->direct),
19854 community_list_config_str(entry));
19855 }
19856 }
19857
19858 DEFUN (show_extcommunity_list,
19859 show_bgp_extcommunity_list_cmd,
19860 "show bgp extcommunity-list",
19861 SHOW_STR
19862 BGP_STR
19863 "List extended-community list\n")
19864 {
19865 struct community_list *list;
19866 struct community_list_master *cm;
19867
19868 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
19869 if (!cm)
19870 return CMD_SUCCESS;
19871
19872 for (list = cm->num.head; list; list = list->next)
19873 extcommunity_list_show(vty, list);
19874
19875 for (list = cm->str.head; list; list = list->next)
19876 extcommunity_list_show(vty, list);
19877
19878 return CMD_SUCCESS;
19879 }
19880
19881 DEFUN (show_extcommunity_list_arg,
19882 show_bgp_extcommunity_list_arg_cmd,
19883 "show bgp extcommunity-list <(1-500)|WORD> detail",
19884 SHOW_STR
19885 BGP_STR
19886 "List extended-community list\n"
19887 "Extcommunity-list number\n"
19888 "Extcommunity-list name\n"
19889 "Detailed information on extcommunity-list\n")
19890 {
19891 int idx_comm_list = 3;
19892 struct community_list *list;
19893
19894 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
19895 EXTCOMMUNITY_LIST_MASTER);
19896 if (!list) {
19897 vty_out(vty, "%% Can't find extcommunity-list\n");
19898 return CMD_WARNING;
19899 }
19900
19901 extcommunity_list_show(vty, list);
19902
19903 return CMD_SUCCESS;
19904 }
19905
19906 /* Display community-list and extcommunity-list configuration. */
19907 static int community_list_config_write(struct vty *vty)
19908 {
19909 struct community_list *list;
19910 struct community_entry *entry;
19911 struct community_list_master *cm;
19912 int write = 0;
19913
19914 /* Community-list. */
19915 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
19916
19917 for (list = cm->num.head; list; list = list->next)
19918 for (entry = list->head; entry; entry = entry->next) {
19919 vty_out(vty,
19920 "bgp community-list %s seq %" PRId64 " %s %s\n",
19921 list->name, entry->seq,
19922 community_direct_str(entry->direct),
19923 community_list_config_str(entry));
19924 write++;
19925 }
19926 for (list = cm->str.head; list; list = list->next)
19927 for (entry = list->head; entry; entry = entry->next) {
19928 vty_out(vty,
19929 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
19930 entry->style == COMMUNITY_LIST_STANDARD
19931 ? "standard"
19932 : "expanded",
19933 list->name, entry->seq,
19934 community_direct_str(entry->direct),
19935 community_list_config_str(entry));
19936 write++;
19937 }
19938
19939 /* Extcommunity-list. */
19940 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
19941
19942 for (list = cm->num.head; list; list = list->next)
19943 for (entry = list->head; entry; entry = entry->next) {
19944 vty_out(vty,
19945 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
19946 list->name, entry->seq,
19947 community_direct_str(entry->direct),
19948 community_list_config_str(entry));
19949 write++;
19950 }
19951 for (list = cm->str.head; list; list = list->next)
19952 for (entry = list->head; entry; entry = entry->next) {
19953 vty_out(vty,
19954 "bgp extcommunity-list %s %s seq %" PRId64" %s %s\n",
19955 entry->style == EXTCOMMUNITY_LIST_STANDARD
19956 ? "standard"
19957 : "expanded",
19958 list->name, entry->seq,
19959 community_direct_str(entry->direct),
19960 community_list_config_str(entry));
19961 write++;
19962 }
19963
19964
19965 /* lcommunity-list. */
19966 cm = community_list_master_lookup(bgp_clist,
19967 LARGE_COMMUNITY_LIST_MASTER);
19968
19969 for (list = cm->num.head; list; list = list->next)
19970 for (entry = list->head; entry; entry = entry->next) {
19971 vty_out(vty,
19972 "bgp large-community-list %s seq %" PRId64" %s %s\n",
19973 list->name, entry->seq,
19974 community_direct_str(entry->direct),
19975 community_list_config_str(entry));
19976 write++;
19977 }
19978 for (list = cm->str.head; list; list = list->next)
19979 for (entry = list->head; entry; entry = entry->next) {
19980 vty_out(vty,
19981 "bgp large-community-list %s %s seq %" PRId64" %s %s\n",
19982
19983 entry->style == LARGE_COMMUNITY_LIST_STANDARD
19984 ? "standard"
19985 : "expanded",
19986 list->name, entry->seq, community_direct_str(entry->direct),
19987 community_list_config_str(entry));
19988 write++;
19989 }
19990
19991 return write;
19992 }
19993
19994 static int community_list_config_write(struct vty *vty);
19995 static struct cmd_node community_list_node = {
19996 .name = "community list",
19997 .node = COMMUNITY_LIST_NODE,
19998 .prompt = "",
19999 .config_write = community_list_config_write,
20000 };
20001
20002 static void community_list_vty(void)
20003 {
20004 install_node(&community_list_node);
20005
20006 /* Community-list. */
20007 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
20008 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
20009 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
20010 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
20011 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
20012 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
20013 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
20014 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
20015
20016 /* Extcommunity-list. */
20017 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
20018 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
20019 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
20020 install_element(CONFIG_NODE,
20021 &no_bgp_extcommunity_list_standard_all_list_cmd);
20022 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
20023 install_element(CONFIG_NODE,
20024 &no_bgp_extcommunity_list_expanded_all_list_cmd);
20025 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
20026 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
20027
20028 /* Large Community List */
20029 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
20030 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
20031 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
20032 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
20033 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
20034 install_element(CONFIG_NODE,
20035 &no_bgp_lcommunity_list_name_standard_all_cmd);
20036 install_element(CONFIG_NODE,
20037 &no_bgp_lcommunity_list_name_expanded_all_cmd);
20038 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
20039 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
20040 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
20041 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
20042 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
20043 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
20044 }