]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
Merge pull request #7439 from opensourcerouting/bgp-damp-profile2
[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 DEFPY(neighbor_damp,
8900 neighbor_damp_cmd,
8901 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor dampening [(1-45)$half [(1-20000)$reuse (1-20000)$suppress (1-255)$max]]",
8902 NEIGHBOR_STR
8903 NEIGHBOR_ADDR_STR2
8904 "Enable neighbor route-flap dampening\n"
8905 "Half-life time for the penalty\n"
8906 "Value to start reusing a route\n"
8907 "Value to start suppressing a route\n"
8908 "Maximum duration to suppress a stable route\n")
8909 {
8910 struct peer *peer = peer_and_group_lookup_vty(vty, neighbor);
8911
8912 if (!peer)
8913 return CMD_WARNING_CONFIG_FAILED;
8914 if (!half)
8915 half = DEFAULT_HALF_LIFE;
8916 if (!reuse) {
8917 reuse = DEFAULT_REUSE;
8918 suppress = DEFAULT_SUPPRESS;
8919 max = half * 4;
8920 }
8921 if (suppress < reuse) {
8922 vty_out(vty,
8923 "Suppress value cannot be less than reuse value\n");
8924 return CMD_WARNING_CONFIG_FAILED;
8925 }
8926 bgp_peer_damp_enable(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8927 half * 60, reuse, suppress, max * 60);
8928 return CMD_SUCCESS;
8929 }
8930
8931 DEFPY(no_neighbor_damp,
8932 no_neighbor_damp_cmd,
8933 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor dampening [HALF [REUSE SUPPRESS MAX]]",
8934 NO_STR
8935 NEIGHBOR_STR
8936 NEIGHBOR_ADDR_STR2
8937 "Enable neighbor route-flap dampening\n"
8938 "Half-life time for the penalty\n"
8939 "Value to start reusing a route\n"
8940 "Value to start suppressing a route\n"
8941 "Maximum duration to suppress a stable route\n")
8942 {
8943 struct peer *peer = peer_and_group_lookup_vty(vty, neighbor);
8944
8945 if (!peer)
8946 return CMD_WARNING_CONFIG_FAILED;
8947 bgp_peer_damp_disable(peer, bgp_node_afi(vty), bgp_node_safi(vty));
8948 return CMD_SUCCESS;
8949 }
8950
8951 DEFPY (show_ip_bgp_neighbor_damp_param,
8952 show_ip_bgp_neighbor_damp_param_cmd,
8953 "show [ip] bgp [<ipv4|ipv6> [unicast]] neighbors <A.B.C.D|X:X::X:X|WORD>$neighbor dampening parameters [json]$json",
8954 SHOW_STR
8955 IP_STR
8956 BGP_STR
8957 BGP_AFI_HELP_STR
8958 "Address Family modifier\n"
8959 NEIGHBOR_STR
8960 NEIGHBOR_ADDR_STR2
8961 "Neighbor route-flap dampening information\n"
8962 "Display detail of configured dampening parameters\n"
8963 JSON_STR)
8964 {
8965 bool use_json = false;
8966 int idx = 0;
8967 afi_t afi = AFI_IP;
8968 safi_t safi = SAFI_UNICAST;
8969 struct peer *peer;
8970
8971 if (argv_find(argv, argc, "ip", &idx))
8972 afi = AFI_IP;
8973 if (argv_find(argv, argc, "ipv4", &idx))
8974 afi = AFI_IP;
8975 if (argv_find(argv, argc, "ipv6", &idx))
8976 afi = AFI_IP6;
8977 peer = peer_and_group_lookup_vty(vty, neighbor);
8978 if (!peer)
8979 return CMD_WARNING;
8980 if (json)
8981 use_json = true;
8982 bgp_show_peer_dampening_parameters(vty, peer, afi, safi, use_json);
8983 return CMD_SUCCESS;
8984 }
8985
8986 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
8987 struct ecommunity **list, bool is_rt6)
8988 {
8989 struct ecommunity *ecom = NULL;
8990 struct ecommunity *ecomadd;
8991
8992 for (; argc; --argc, ++argv) {
8993 if (is_rt6)
8994 ecomadd = ecommunity_str2com_ipv6(argv[0]->arg,
8995 ECOMMUNITY_ROUTE_TARGET,
8996 0);
8997 else
8998 ecomadd = ecommunity_str2com(argv[0]->arg,
8999 ECOMMUNITY_ROUTE_TARGET,
9000 0);
9001 if (!ecomadd) {
9002 vty_out(vty, "Malformed community-list value\n");
9003 if (ecom)
9004 ecommunity_free(&ecom);
9005 return CMD_WARNING_CONFIG_FAILED;
9006 }
9007
9008 if (ecom) {
9009 ecommunity_merge(ecom, ecomadd);
9010 ecommunity_free(&ecomadd);
9011 } else {
9012 ecom = ecomadd;
9013 }
9014 }
9015
9016 if (*list) {
9017 ecommunity_free(&*list);
9018 }
9019 *list = ecom;
9020
9021 return CMD_SUCCESS;
9022 }
9023
9024 bool vpn_policy_check_import(struct bgp *bgp, afi_t afi, safi_t safi,
9025 bool v2vimport, char *errmsg, size_t errmsg_len)
9026 {
9027 if (!v2vimport) {
9028 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9029 BGP_CONFIG_VRF_TO_VRF_IMPORT)
9030 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9031 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
9032 snprintf(
9033 errmsg, errmsg_len, "%s",
9034 "%% error: Please unconfigure import vrf commands before using vpn commands");
9035 return false;
9036 }
9037 } else {
9038 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9039 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
9040 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9041 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
9042 snprintf(
9043 errmsg, errmsg_len, "%s",
9044 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands");
9045 return false;
9046 }
9047 }
9048 return true;
9049 }
9050
9051 /*
9052 * v2vimport is true if we are handling a `import vrf ...` command
9053 */
9054 static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
9055 {
9056 afi_t afi;
9057
9058 switch (vty->node) {
9059 case BGP_IPV4_NODE:
9060 afi = AFI_IP;
9061 break;
9062 case BGP_IPV6_NODE:
9063 afi = AFI_IP6;
9064 break;
9065 default:
9066 vty_out(vty,
9067 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
9068 return AFI_MAX;
9069 }
9070
9071 if (!v2vimport) {
9072 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9073 BGP_CONFIG_VRF_TO_VRF_IMPORT)
9074 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9075 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
9076 vty_out(vty,
9077 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
9078 return AFI_MAX;
9079 }
9080 } else {
9081 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9082 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
9083 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9084 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
9085 vty_out(vty,
9086 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
9087 return AFI_MAX;
9088 }
9089 }
9090 return afi;
9091 }
9092
9093 DEFPY_YANG(
9094 af_rd_vpn_export,
9095 af_rd_vpn_export_cmd,
9096 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
9097 NO_STR
9098 "Specify route distinguisher\n"
9099 "Between current address-family and vpn\n"
9100 "For routes leaked from current address-family to vpn\n"
9101 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
9102 {
9103 char base_xpath[XPATH_MAXLEN];
9104 afi_t afi;
9105 safi_t safi;
9106 int idx = 0;
9107
9108 afi = bgp_node_afi(vty);
9109 safi = bgp_node_safi(vty);
9110
9111 snprintf(
9112 base_xpath, sizeof(base_xpath),
9113 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config",
9114 yang_afi_safi_value2identity(afi, safi),
9115 bgp_afi_safi_get_container_str(afi, safi));
9116
9117 if (argv_find(argv, argc, "no", &idx))
9118 nb_cli_enqueue_change(vty, "./rd", NB_OP_DESTROY, NULL);
9119 else
9120 nb_cli_enqueue_change(vty, "./rd", NB_OP_MODIFY, rd_str);
9121
9122 return nb_cli_apply_changes(vty, base_xpath);
9123 }
9124
9125 void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rd(
9126 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9127 {
9128 int indent = 2;
9129
9130 vty_out(vty, "%*srd vpn export %s\n", indent, "",
9131 yang_dnode_get_string(dnode, NULL));
9132 }
9133
9134 ALIAS (af_rd_vpn_export,
9135 af_no_rd_vpn_export_cmd,
9136 "no rd vpn export",
9137 NO_STR
9138 "Specify route distinguisher\n"
9139 "Between current address-family and vpn\n"
9140 "For routes leaked from current address-family to vpn\n")
9141
9142 DEFPY (af_label_vpn_export,
9143 af_label_vpn_export_cmd,
9144 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
9145 NO_STR
9146 "label value for VRF\n"
9147 "Between current address-family and vpn\n"
9148 "For routes leaked from current address-family to vpn\n"
9149 "Label Value <0-1048575>\n"
9150 "Automatically assign a label\n")
9151 {
9152 VTY_DECLVAR_CONTEXT(bgp, bgp);
9153 mpls_label_t label = MPLS_LABEL_NONE;
9154 afi_t afi;
9155 int idx = 0;
9156 bool yes = true;
9157
9158 if (argv_find(argv, argc, "no", &idx))
9159 yes = false;
9160
9161 /* If "no ...", squash trailing parameter */
9162 if (!yes)
9163 label_auto = NULL;
9164
9165 if (yes) {
9166 if (!label_auto)
9167 label = label_val; /* parser should force unsigned */
9168 }
9169
9170 afi = vpn_policy_getafi(vty, bgp, false);
9171 if (afi == AFI_MAX)
9172 return CMD_WARNING_CONFIG_FAILED;
9173
9174
9175 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9176 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
9177 /* no change */
9178 return CMD_SUCCESS;
9179
9180 /*
9181 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
9182 */
9183 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9184 bgp_get_default(), bgp);
9185
9186 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9187 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
9188
9189 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
9190
9191 /*
9192 * label has previously been automatically
9193 * assigned by labelpool: release it
9194 *
9195 * NB if tovpn_label == MPLS_LABEL_NONE it
9196 * means the automatic assignment is in flight
9197 * and therefore the labelpool callback must
9198 * detect that the auto label is not needed.
9199 */
9200
9201 bgp_lp_release(LP_TYPE_VRF,
9202 &bgp->vpn_policy[afi],
9203 bgp->vpn_policy[afi].tovpn_label);
9204 }
9205 UNSET_FLAG(bgp->vpn_policy[afi].flags,
9206 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
9207 }
9208
9209 bgp->vpn_policy[afi].tovpn_label = label;
9210 if (label_auto) {
9211 SET_FLAG(bgp->vpn_policy[afi].flags,
9212 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
9213 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
9214 vpn_leak_label_callback);
9215 }
9216
9217 /* post-change: re-export vpn routes */
9218 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9219 bgp_get_default(), bgp);
9220
9221 return CMD_SUCCESS;
9222 }
9223
9224 ALIAS (af_label_vpn_export,
9225 af_no_label_vpn_export_cmd,
9226 "no label vpn export",
9227 NO_STR
9228 "label value for VRF\n"
9229 "Between current address-family and vpn\n"
9230 "For routes leaked from current address-family to vpn\n")
9231
9232 DEFPY_YANG (af_nexthop_vpn_export,
9233 af_nexthop_vpn_export_cmd,
9234 "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
9235 NO_STR
9236 "Specify next hop to use for VRF advertised prefixes\n"
9237 "Between current address-family and vpn\n"
9238 "For routes leaked from current address-family to vpn\n"
9239 "IPv4 prefix\n"
9240 "IPv6 prefix\n")
9241 {
9242 char base_xpath[XPATH_MAXLEN];
9243 afi_t afi;
9244 safi_t safi;
9245 int idx = 0;
9246 struct prefix p;
9247
9248 if (!no) {
9249 if (!nexthop_su) {
9250 vty_out(vty, "%% Nexthop required\n");
9251 return CMD_WARNING_CONFIG_FAILED;
9252 }
9253 if (!sockunion2hostprefix(nexthop_su, &p))
9254 return CMD_WARNING_CONFIG_FAILED;
9255 }
9256
9257 afi = bgp_node_afi(vty);
9258 safi = bgp_node_safi(vty);
9259
9260 snprintf(
9261 base_xpath, sizeof(base_xpath),
9262 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config",
9263 yang_afi_safi_value2identity(afi, safi),
9264 bgp_afi_safi_get_container_str(afi, safi));
9265
9266 if (argv_find(argv, argc, "no", &idx))
9267 nb_cli_enqueue_change(vty, "./nexthop", NB_OP_DESTROY, NULL);
9268 else
9269 nb_cli_enqueue_change(vty, "./nexthop", NB_OP_MODIFY,
9270 nexthop_su_str);
9271
9272 return nb_cli_apply_changes(vty, base_xpath);
9273 }
9274
9275 void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_nexthop(
9276 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9277 {
9278 int indent = 2;
9279
9280 vty_out(vty, "%*snexthop vpn export %s\n", indent, "",
9281 yang_dnode_get_string(dnode, NULL));
9282 }
9283
9284 static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
9285 {
9286 if (!strcmp(dstr, "import")) {
9287 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9288 } else if (!strcmp(dstr, "export")) {
9289 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9290 } else if (!strcmp(dstr, "both")) {
9291 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9292 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9293 } else {
9294 vty_out(vty, "%% direction parse error\n");
9295 return CMD_WARNING_CONFIG_FAILED;
9296 }
9297 return CMD_SUCCESS;
9298 }
9299
9300 DEFPY (af_rt_vpn_imexport,
9301 af_rt_vpn_imexport_cmd,
9302 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
9303 NO_STR
9304 "Specify route target list\n"
9305 "Specify route target list\n"
9306 "Between current address-family and vpn\n"
9307 "For routes leaked from vpn to current address-family: match any\n"
9308 "For routes leaked from current address-family to vpn: set\n"
9309 "both import: match any and export: set\n"
9310 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
9311 {
9312 VTY_DECLVAR_CONTEXT(bgp, bgp);
9313 int ret;
9314 struct ecommunity *ecom = NULL;
9315 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
9316 vpn_policy_direction_t dir;
9317 afi_t afi;
9318 int idx = 0;
9319 bool yes = true;
9320
9321 if (argv_find(argv, argc, "no", &idx))
9322 yes = false;
9323
9324 afi = vpn_policy_getafi(vty, bgp, false);
9325 if (afi == AFI_MAX)
9326 return CMD_WARNING_CONFIG_FAILED;
9327
9328 ret = vpn_policy_getdirs(vty, direction_str, dodir);
9329 if (ret != CMD_SUCCESS)
9330 return ret;
9331
9332 if (yes) {
9333 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9334 vty_out(vty, "%% Missing RTLIST\n");
9335 return CMD_WARNING_CONFIG_FAILED;
9336 }
9337 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, false);
9338 if (ret != CMD_SUCCESS) {
9339 return ret;
9340 }
9341 }
9342
9343 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9344 if (!dodir[dir])
9345 continue;
9346
9347 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9348
9349 if (yes) {
9350 if (bgp->vpn_policy[afi].rtlist[dir])
9351 ecommunity_free(
9352 &bgp->vpn_policy[afi].rtlist[dir]);
9353 bgp->vpn_policy[afi].rtlist[dir] =
9354 ecommunity_dup(ecom);
9355 } else {
9356 if (bgp->vpn_policy[afi].rtlist[dir])
9357 ecommunity_free(
9358 &bgp->vpn_policy[afi].rtlist[dir]);
9359 bgp->vpn_policy[afi].rtlist[dir] = NULL;
9360 }
9361
9362 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9363 }
9364
9365 if (ecom)
9366 ecommunity_free(&ecom);
9367
9368 return CMD_SUCCESS;
9369 }
9370
9371 ALIAS (af_rt_vpn_imexport,
9372 af_no_rt_vpn_imexport_cmd,
9373 "no <rt|route-target> vpn <import|export|both>$direction_str",
9374 NO_STR
9375 "Specify route target list\n"
9376 "Specify route target list\n"
9377 "Between current address-family and vpn\n"
9378 "For routes leaked from vpn to current address-family\n"
9379 "For routes leaked from current address-family to vpn\n"
9380 "both import and export\n")
9381
9382 DEFPY_YANG (af_route_map_vpn_imexport,
9383 af_route_map_vpn_imexport_cmd,
9384 /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
9385 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
9386 NO_STR
9387 "Specify route map\n"
9388 "Between current address-family and vpn\n"
9389 "For routes leaked from vpn to current address-family\n"
9390 "For routes leaked from current address-family to vpn\n"
9391 "name of route-map\n")
9392 {
9393 char base_xpath[XPATH_MAXLEN];
9394 afi_t afi;
9395 safi_t safi;
9396 int idx = 0;
9397
9398 afi = bgp_node_afi(vty);
9399 safi = bgp_node_safi(vty);
9400
9401 snprintf(
9402 base_xpath, sizeof(base_xpath),
9403 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config",
9404 yang_afi_safi_value2identity(afi, safi),
9405 bgp_afi_safi_get_container_str(afi, safi));
9406
9407 if (argv_find(argv, argc, "no", &idx)) {
9408 if (!strcmp(direction_str, "import"))
9409 nb_cli_enqueue_change(vty, "./rmap-import",
9410 NB_OP_DESTROY, NULL);
9411 else if (!strcmp(direction_str, "export"))
9412 nb_cli_enqueue_change(vty, "./rmap-export",
9413 NB_OP_DESTROY, NULL);
9414 } else {
9415 if (!strcmp(direction_str, "import"))
9416 nb_cli_enqueue_change(vty, "./rmap-import",
9417 NB_OP_MODIFY, rmap_str);
9418 if (!strcmp(direction_str, "export"))
9419 nb_cli_enqueue_change(vty, "./rmap-export",
9420 NB_OP_MODIFY, rmap_str);
9421 }
9422 return nb_cli_apply_changes(vty, base_xpath);
9423 }
9424
9425 void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rmap_import(
9426 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9427 {
9428 int indent = 2;
9429
9430 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
9431 yang_dnode_get_string(dnode, NULL));
9432 }
9433
9434 void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rmap_export(
9435 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9436 {
9437 int indent = 2;
9438
9439 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
9440 yang_dnode_get_string(dnode, NULL));
9441 }
9442
9443 ALIAS (af_route_map_vpn_imexport,
9444 af_no_route_map_vpn_imexport_cmd,
9445 "no route-map vpn <import|export>$direction_str",
9446 NO_STR
9447 "Specify route map\n"
9448 "Between current address-family and vpn\n"
9449 "For routes leaked from vpn to current address-family\n"
9450 "For routes leaked from current address-family to vpn\n")
9451
9452 DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
9453 "import vrf route-map RMAP$rmap_str",
9454 "Import routes from another VRF\n"
9455 "Vrf routes being filtered\n"
9456 "Specify route map\n"
9457 "name of route-map\n")
9458 {
9459 VTY_DECLVAR_CONTEXT(bgp, bgp);
9460 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
9461 afi_t afi;
9462 struct bgp *bgp_default;
9463
9464 afi = vpn_policy_getafi(vty, bgp, true);
9465 if (afi == AFI_MAX)
9466 return CMD_WARNING_CONFIG_FAILED;
9467
9468 bgp_default = bgp_get_default();
9469 if (!bgp_default) {
9470 int32_t ret;
9471 as_t as = bgp->as;
9472
9473 /* Auto-create assuming the same AS */
9474 ret = bgp_get_vty(&bgp_default, &as, NULL,
9475 BGP_INSTANCE_TYPE_DEFAULT);
9476
9477 if (ret) {
9478 vty_out(vty,
9479 "VRF default is not configured as a bgp instance\n");
9480 return CMD_WARNING;
9481 }
9482 }
9483
9484 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9485
9486 if (bgp->vpn_policy[afi].rmap_name[dir])
9487 XFREE(MTYPE_ROUTE_MAP_NAME,
9488 bgp->vpn_policy[afi].rmap_name[dir]);
9489 bgp->vpn_policy[afi].rmap_name[dir] =
9490 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
9491 bgp->vpn_policy[afi].rmap[dir] =
9492 route_map_lookup_warn_noexist(vty, rmap_str);
9493 if (!bgp->vpn_policy[afi].rmap[dir])
9494 return CMD_SUCCESS;
9495
9496 SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9497 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9498
9499 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9500
9501 return CMD_SUCCESS;
9502 }
9503
9504 DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
9505 "no import vrf route-map [RMAP$rmap_str]",
9506 NO_STR
9507 "Import routes from another VRF\n"
9508 "Vrf routes being filtered\n"
9509 "Specify route map\n"
9510 "name of route-map\n")
9511 {
9512 VTY_DECLVAR_CONTEXT(bgp, bgp);
9513 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
9514 afi_t afi;
9515
9516 afi = vpn_policy_getafi(vty, bgp, true);
9517 if (afi == AFI_MAX)
9518 return CMD_WARNING_CONFIG_FAILED;
9519
9520 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9521
9522 if (bgp->vpn_policy[afi].rmap_name[dir])
9523 XFREE(MTYPE_ROUTE_MAP_NAME,
9524 bgp->vpn_policy[afi].rmap_name[dir]);
9525 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9526 bgp->vpn_policy[afi].rmap[dir] = NULL;
9527
9528 if (bgp->vpn_policy[afi].import_vrf->count == 0)
9529 UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9530 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9531
9532 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9533
9534 return CMD_SUCCESS;
9535 }
9536
9537 DEFPY_YANG(bgp_imexport_vrf,
9538 bgp_imexport_vrf_cmd,
9539 "[no] import vrf VIEWVRFNAME$import_name",
9540 NO_STR
9541 "Import routes from another VRF\n"
9542 "VRF to import from\n"
9543 "The name of the VRF\n")
9544 {
9545 char base_xpath[XPATH_MAXLEN];
9546 safi_t safi;
9547 afi_t afi;
9548 int32_t idx = 0;
9549
9550 if (import_name == NULL) {
9551 vty_out(vty, "%% Missing import name\n");
9552 return CMD_WARNING;
9553 }
9554
9555 if (strcmp(import_name, "route-map") == 0) {
9556 vty_out(vty, "%% Must include route-map name\n");
9557 return CMD_WARNING;
9558 }
9559
9560 afi = bgp_node_afi(vty);
9561 safi = bgp_node_safi(vty);
9562
9563 snprintf(
9564 base_xpath, sizeof(base_xpath),
9565 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config/import-vrf-list[vrf='%s']",
9566 yang_afi_safi_value2identity(afi, safi),
9567 bgp_afi_safi_get_container_str(afi, safi), import_name);
9568
9569 if (argv_find(argv, argc, "no", &idx))
9570 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
9571 else
9572 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
9573
9574 return nb_cli_apply_changes(vty, base_xpath);
9575 }
9576
9577 void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_import_vrfs(
9578 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9579 {
9580 vty_out(vty, " import vrf %s\n",
9581 yang_dnode_get_string(dnode, "./vrf"));
9582 }
9583
9584 /* This command is valid only in a bgp vrf instance or the default instance */
9585 DEFPY_YANG (bgp_imexport_vpn,
9586 bgp_imexport_vpn_cmd,
9587 "[no] <import|export>$direction_str vpn",
9588 NO_STR
9589 "Import routes to this address-family\n"
9590 "Export routes from this address-family\n"
9591 "to/from default instance VPN RIB\n")
9592 {
9593 char base_xpath[XPATH_MAXLEN];
9594 safi_t safi;
9595 afi_t afi;
9596 int32_t idx = 0;
9597
9598 afi = bgp_node_afi(vty);
9599 safi = bgp_node_safi(vty);
9600
9601 if (!strcmp(direction_str, "import")) {
9602 snprintf(
9603 base_xpath, sizeof(base_xpath),
9604 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config/import-vpn",
9605 yang_afi_safi_value2identity(afi, safi),
9606 bgp_afi_safi_get_container_str(afi, safi));
9607 } else if (!strcmp(direction_str, "export")) {
9608 snprintf(
9609 base_xpath, sizeof(base_xpath),
9610 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config/export-vpn",
9611 yang_afi_safi_value2identity(afi, safi),
9612 bgp_afi_safi_get_container_str(afi, safi));
9613 } else {
9614 vty_out(vty, "%% unknown direction %s\n", direction_str);
9615 return CMD_WARNING_CONFIG_FAILED;
9616 }
9617
9618 if (argv_find(argv, argc, "no", &idx))
9619 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
9620 else
9621 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, "true");
9622
9623 return nb_cli_apply_changes(vty, base_xpath);
9624 }
9625
9626 void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_import_vpn(
9627 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9628 {
9629 if (yang_dnode_get_bool(dnode, NULL))
9630 vty_out(vty, " import vpn\n");
9631 }
9632
9633 void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_export_vpn(
9634 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9635 {
9636 if (yang_dnode_get_bool(dnode, NULL))
9637 vty_out(vty, " export vpn\n");
9638 }
9639
9640 DEFPY (af_routetarget_import,
9641 af_routetarget_import_cmd,
9642 "[no] <rt|route-target|route-target6|rt6> redirect import RTLIST...",
9643 NO_STR
9644 "Specify route target list\n"
9645 "Specify route target list\n"
9646 "Specify route target list\n"
9647 "Specify route target list\n"
9648 "Flow-spec redirect type route target\n"
9649 "Import routes to this address-family\n"
9650 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN|IPV6:MN)\n")
9651 {
9652 VTY_DECLVAR_CONTEXT(bgp, bgp);
9653 int ret;
9654 struct ecommunity *ecom = NULL;
9655 afi_t afi;
9656 int idx = 0, idx_unused = 0;
9657 bool yes = true;
9658 bool rt6 = false;
9659
9660 if (argv_find(argv, argc, "no", &idx))
9661 yes = false;
9662
9663 if (argv_find(argv, argc, "rt6", &idx_unused) ||
9664 argv_find(argv, argc, "route-target6", &idx_unused))
9665 rt6 = true;
9666
9667 afi = vpn_policy_getafi(vty, bgp, false);
9668 if (afi == AFI_MAX)
9669 return CMD_WARNING_CONFIG_FAILED;
9670
9671 if (rt6 && afi != AFI_IP6)
9672 return CMD_WARNING_CONFIG_FAILED;
9673
9674 if (yes) {
9675 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9676 vty_out(vty, "%% Missing RTLIST\n");
9677 return CMD_WARNING_CONFIG_FAILED;
9678 }
9679 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, rt6);
9680 if (ret != CMD_SUCCESS)
9681 return ret;
9682 }
9683
9684 if (yes) {
9685 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9686 ecommunity_free(&bgp->vpn_policy[afi]
9687 .import_redirect_rtlist);
9688 bgp->vpn_policy[afi].import_redirect_rtlist =
9689 ecommunity_dup(ecom);
9690 } else {
9691 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9692 ecommunity_free(&bgp->vpn_policy[afi]
9693 .import_redirect_rtlist);
9694 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
9695 }
9696
9697 if (ecom)
9698 ecommunity_free(&ecom);
9699
9700 return CMD_SUCCESS;
9701 }
9702
9703 void cli_show_bgp_global_afi_safi_header(struct vty *vty,
9704 struct lyd_node *dnode,
9705 bool show_defaults)
9706 {
9707 const char *af_name;
9708 afi_t afi;
9709 safi_t safi;
9710
9711 af_name = yang_dnode_get_string(dnode, "./afi-safi-name");
9712 yang_afi_safi_identity2value(af_name, &afi, &safi);
9713
9714 vty_out(vty, " !\n address-family ");
9715 if (afi == AFI_IP) {
9716 if (safi == SAFI_UNICAST)
9717 vty_out(vty, "ipv4 unicast");
9718 else if (safi == SAFI_LABELED_UNICAST)
9719 vty_out(vty, "ipv4 labeled-unicast");
9720 else if (safi == SAFI_MULTICAST)
9721 vty_out(vty, "ipv4 multicast");
9722 else if (safi == SAFI_MPLS_VPN)
9723 vty_out(vty, "ipv4 vpn");
9724 else if (safi == SAFI_ENCAP)
9725 vty_out(vty, "ipv4 encap");
9726 else if (safi == SAFI_FLOWSPEC)
9727 vty_out(vty, "ipv4 flowspec");
9728 } else if (afi == AFI_IP6) {
9729 if (safi == SAFI_UNICAST)
9730 vty_out(vty, "ipv6 unicast");
9731 else if (safi == SAFI_LABELED_UNICAST)
9732 vty_out(vty, "ipv6 labeled-unicast");
9733 else if (safi == SAFI_MULTICAST)
9734 vty_out(vty, "ipv6 multicast");
9735 else if (safi == SAFI_MPLS_VPN)
9736 vty_out(vty, "ipv6 vpn");
9737 else if (safi == SAFI_ENCAP)
9738 vty_out(vty, "ipv6 encap");
9739 else if (safi == SAFI_FLOWSPEC)
9740 vty_out(vty, "ipv6 flowspec");
9741 } else if (afi == AFI_L2VPN) {
9742 if (safi == SAFI_EVPN)
9743 vty_out(vty, "l2vpn evpn");
9744 }
9745 vty_out(vty, "\n");
9746 }
9747
9748 DEFUN_NOSH (address_family_ipv4_safi,
9749 address_family_ipv4_safi_cmd,
9750 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9751 "Enter Address Family command mode\n"
9752 "Address Family\n"
9753 BGP_SAFI_WITH_LABEL_HELP_STR)
9754 {
9755
9756 safi_t safi = SAFI_UNICAST;
9757 const struct lyd_node *vrf_dnode, *bgp_glb_dnode;
9758 const char *vrf_name = NULL;
9759
9760 if (argc == 3) {
9761 safi = bgp_vty_safi_from_str(argv[2]->text);
9762
9763 bgp_glb_dnode = yang_dnode_get(vty->candidate_config->dnode,
9764 VTY_CURR_XPATH);
9765 vrf_dnode = yang_dnode_get_parent(bgp_glb_dnode,
9766 "control-plane-protocol");
9767 vrf_name = yang_dnode_get_string(vrf_dnode, "./vrf");
9768
9769 if (!strmatch(vrf_name, VRF_DEFAULT_NAME)
9770 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9771 && safi != SAFI_EVPN) {
9772 vty_out(vty,
9773 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9774 return CMD_WARNING_CONFIG_FAILED;
9775 }
9776 }
9777 vty->node = bgp_node_type(AFI_IP, safi);
9778
9779 return CMD_SUCCESS;
9780 }
9781
9782 DEFUN_NOSH (address_family_ipv6_safi,
9783 address_family_ipv6_safi_cmd,
9784 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9785 "Enter Address Family command mode\n"
9786 "Address Family\n"
9787 BGP_SAFI_WITH_LABEL_HELP_STR)
9788 {
9789 safi_t safi = SAFI_UNICAST;
9790 const struct lyd_node *vrf_dnode, *bgp_glb_dnode;
9791 const char *vrf_name = NULL;
9792
9793 if (argc == 3) {
9794 safi = bgp_vty_safi_from_str(argv[2]->text);
9795 bgp_glb_dnode = yang_dnode_get(vty->candidate_config->dnode,
9796 VTY_CURR_XPATH);
9797 vrf_dnode = yang_dnode_get_parent(bgp_glb_dnode,
9798 "control-plane-protocol");
9799 vrf_name = yang_dnode_get_string(vrf_dnode, "./vrf");
9800
9801 if (!strmatch(vrf_name, VRF_DEFAULT_NAME)
9802 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9803 && safi != SAFI_EVPN) {
9804 vty_out(vty,
9805 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9806 return CMD_WARNING_CONFIG_FAILED;
9807 }
9808 }
9809 vty->node = bgp_node_type(AFI_IP6, safi);
9810
9811 return CMD_SUCCESS;
9812 }
9813
9814 #ifdef KEEP_OLD_VPN_COMMANDS
9815 DEFUN_NOSH (address_family_vpnv4,
9816 address_family_vpnv4_cmd,
9817 "address-family vpnv4 [unicast]",
9818 "Enter Address Family command mode\n"
9819 "Address Family\n"
9820 "Address Family modifier\n")
9821 {
9822 vty->node = BGP_VPNV4_NODE;
9823 return CMD_SUCCESS;
9824 }
9825
9826 DEFUN_NOSH (address_family_vpnv6,
9827 address_family_vpnv6_cmd,
9828 "address-family vpnv6 [unicast]",
9829 "Enter Address Family command mode\n"
9830 "Address Family\n"
9831 "Address Family modifier\n")
9832 {
9833 vty->node = BGP_VPNV6_NODE;
9834 return CMD_SUCCESS;
9835 }
9836 #endif /* KEEP_OLD_VPN_COMMANDS */
9837
9838 DEFUN_NOSH (address_family_evpn,
9839 address_family_evpn_cmd,
9840 "address-family l2vpn evpn",
9841 "Enter Address Family command mode\n"
9842 "Address Family\n"
9843 "Address Family modifier\n")
9844 {
9845 VTY_DECLVAR_CONTEXT(bgp, bgp);
9846 vty->node = BGP_EVPN_NODE;
9847 return CMD_SUCCESS;
9848 }
9849
9850 DEFUN_NOSH (exit_address_family,
9851 exit_address_family_cmd,
9852 "exit-address-family",
9853 "Exit from Address Family configuration mode\n")
9854 {
9855 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
9856 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
9857 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
9858 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
9859 || vty->node == BGP_EVPN_NODE
9860 || vty->node == BGP_FLOWSPECV4_NODE
9861 || vty->node == BGP_FLOWSPECV6_NODE)
9862 vty->node = BGP_NODE;
9863 return CMD_SUCCESS;
9864 }
9865
9866 void cli_show_bgp_global_afi_safi_header_end(struct vty *vty,
9867 struct lyd_node *dnode
9868 __attribute__((__unused__)))
9869 {
9870 vty_out(vty, " exit-address-family\n");
9871 }
9872
9873 /* Recalculate bestpath and re-advertise a prefix */
9874 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
9875 const char *ip_str, afi_t afi, safi_t safi,
9876 struct prefix_rd *prd)
9877 {
9878 int ret;
9879 struct prefix match;
9880 struct bgp_dest *dest;
9881 struct bgp_dest *rm;
9882 struct bgp *bgp;
9883 struct bgp_table *table;
9884 struct bgp_table *rib;
9885
9886 /* BGP structure lookup. */
9887 if (view_name) {
9888 bgp = bgp_lookup_by_name(view_name);
9889 if (bgp == NULL) {
9890 vty_out(vty, "%% Can't find BGP instance %s\n",
9891 view_name);
9892 return CMD_WARNING;
9893 }
9894 } else {
9895 bgp = bgp_get_default();
9896 if (bgp == NULL) {
9897 vty_out(vty, "%% No BGP process is configured\n");
9898 return CMD_WARNING;
9899 }
9900 }
9901
9902 /* Check IP address argument. */
9903 ret = str2prefix(ip_str, &match);
9904 if (!ret) {
9905 vty_out(vty, "%% address is malformed\n");
9906 return CMD_WARNING;
9907 }
9908
9909 match.family = afi2family(afi);
9910 rib = bgp->rib[afi][safi];
9911
9912 if (safi == SAFI_MPLS_VPN) {
9913 for (dest = bgp_table_top(rib); dest;
9914 dest = bgp_route_next(dest)) {
9915 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
9916
9917 if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
9918 continue;
9919
9920 table = bgp_dest_get_bgp_table_info(dest);
9921 if (table == NULL)
9922 continue;
9923
9924 if ((rm = bgp_node_match(table, &match)) != NULL) {
9925 const struct prefix *rm_p =
9926 bgp_dest_get_prefix(rm);
9927
9928 if (rm_p->prefixlen == match.prefixlen) {
9929 SET_FLAG(rm->flags,
9930 BGP_NODE_USER_CLEAR);
9931 bgp_process(bgp, rm, afi, safi);
9932 }
9933 bgp_dest_unlock_node(rm);
9934 }
9935 }
9936 } else {
9937 if ((dest = bgp_node_match(rib, &match)) != NULL) {
9938 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
9939
9940 if (dest_p->prefixlen == match.prefixlen) {
9941 SET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
9942 bgp_process(bgp, dest, afi, safi);
9943 }
9944 bgp_dest_unlock_node(dest);
9945 }
9946 }
9947
9948 return CMD_SUCCESS;
9949 }
9950
9951 /* one clear bgp command to rule them all */
9952 DEFUN (clear_ip_bgp_all,
9953 clear_ip_bgp_all_cmd,
9954 "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>]",
9955 CLEAR_STR
9956 IP_STR
9957 BGP_STR
9958 BGP_INSTANCE_HELP_STR
9959 BGP_AFI_HELP_STR
9960 "Address Family\n"
9961 BGP_SAFI_WITH_LABEL_HELP_STR
9962 "Address Family modifier\n"
9963 "Clear all peers\n"
9964 "BGP IPv4 neighbor to clear\n"
9965 "BGP IPv6 neighbor to clear\n"
9966 "BGP neighbor on interface to clear\n"
9967 "Clear peers with the AS number\n"
9968 "Clear all external peers\n"
9969 "Clear all members of peer-group\n"
9970 "BGP peer-group name\n"
9971 BGP_SOFT_STR
9972 BGP_SOFT_IN_STR
9973 BGP_SOFT_OUT_STR
9974 BGP_SOFT_IN_STR
9975 "Push out prefix-list ORF and do inbound soft reconfig\n"
9976 BGP_SOFT_OUT_STR)
9977 {
9978 char *vrf = NULL;
9979
9980 afi_t afi = AFI_UNSPEC;
9981 safi_t safi = SAFI_UNSPEC;
9982 enum clear_sort clr_sort = clear_peer;
9983 enum bgp_clear_type clr_type;
9984 char *clr_arg = NULL;
9985
9986 int idx = 0;
9987 char errmsg[BUFSIZ] = {'\0'};
9988 int ret;
9989
9990 /* clear [ip] bgp */
9991 if (argv_find(argv, argc, "ip", &idx))
9992 afi = AFI_IP;
9993
9994 /* [<vrf> VIEWVRFNAME] */
9995 if (argv_find(argv, argc, "vrf", &idx)) {
9996 vrf = argv[idx + 1]->arg;
9997 idx += 2;
9998 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9999 vrf = NULL;
10000 } else if (argv_find(argv, argc, "view", &idx)) {
10001 /* [<view> VIEWVRFNAME] */
10002 vrf = argv[idx + 1]->arg;
10003 idx += 2;
10004 }
10005 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
10006 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
10007 argv_find_and_parse_safi(argv, argc, &idx, &safi);
10008
10009 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
10010 if (argv_find(argv, argc, "*", &idx)) {
10011 clr_sort = clear_all;
10012 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
10013 clr_sort = clear_peer;
10014 clr_arg = argv[idx]->arg;
10015 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
10016 clr_sort = clear_peer;
10017 clr_arg = argv[idx]->arg;
10018 } else if (argv_find(argv, argc, "peer-group", &idx)) {
10019 clr_sort = clear_group;
10020 idx++;
10021 clr_arg = argv[idx]->arg;
10022 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
10023 clr_sort = clear_peer;
10024 clr_arg = argv[idx]->arg;
10025 } else if (argv_find(argv, argc, "WORD", &idx)) {
10026 clr_sort = clear_peer;
10027 clr_arg = argv[idx]->arg;
10028 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
10029 clr_sort = clear_as;
10030 clr_arg = argv[idx]->arg;
10031 } else if (argv_find(argv, argc, "external", &idx)) {
10032 clr_sort = clear_external;
10033 }
10034
10035 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
10036 if (argv_find(argv, argc, "soft", &idx)) {
10037 if (argv_find(argv, argc, "in", &idx)
10038 || argv_find(argv, argc, "out", &idx))
10039 clr_type = strmatch(argv[idx]->text, "in")
10040 ? BGP_CLEAR_SOFT_IN
10041 : BGP_CLEAR_SOFT_OUT;
10042 else
10043 clr_type = BGP_CLEAR_SOFT_BOTH;
10044 } else if (argv_find(argv, argc, "in", &idx)) {
10045 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
10046 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
10047 : BGP_CLEAR_SOFT_IN;
10048 } else if (argv_find(argv, argc, "out", &idx)) {
10049 clr_type = BGP_CLEAR_SOFT_OUT;
10050 } else
10051 clr_type = BGP_CLEAR_SOFT_NONE;
10052
10053 ret = bgp_clear_vty(vrf, afi, safi, clr_sort, clr_type, clr_arg, errmsg,
10054 sizeof(errmsg));
10055 if (ret != NB_OK)
10056 vty_out(vty, "Error description: %s\n", errmsg);
10057
10058 return ret;
10059 }
10060
10061 DEFUN (clear_ip_bgp_prefix,
10062 clear_ip_bgp_prefix_cmd,
10063 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
10064 CLEAR_STR
10065 IP_STR
10066 BGP_STR
10067 BGP_INSTANCE_HELP_STR
10068 "Clear bestpath and re-advertise\n"
10069 "IPv4 prefix\n")
10070 {
10071 char *vrf = NULL;
10072 char *prefix = NULL;
10073
10074 int idx = 0;
10075
10076 /* [<view|vrf> VIEWVRFNAME] */
10077 if (argv_find(argv, argc, "vrf", &idx)) {
10078 vrf = argv[idx + 1]->arg;
10079 idx += 2;
10080 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
10081 vrf = NULL;
10082 } else if (argv_find(argv, argc, "view", &idx)) {
10083 /* [<view> VIEWVRFNAME] */
10084 vrf = argv[idx + 1]->arg;
10085 idx += 2;
10086 }
10087
10088 prefix = argv[argc - 1]->arg;
10089
10090 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
10091 }
10092
10093 DEFUN (clear_bgp_ipv6_safi_prefix,
10094 clear_bgp_ipv6_safi_prefix_cmd,
10095 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
10096 CLEAR_STR
10097 IP_STR
10098 BGP_STR
10099 "Address Family\n"
10100 BGP_SAFI_HELP_STR
10101 "Clear bestpath and re-advertise\n"
10102 "IPv6 prefix\n")
10103 {
10104 int idx_safi = 0;
10105 int idx_ipv6_prefix = 0;
10106 safi_t safi = SAFI_UNICAST;
10107 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
10108 argv[idx_ipv6_prefix]->arg : NULL;
10109
10110 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
10111 return bgp_clear_prefix(
10112 vty, NULL, prefix, AFI_IP6,
10113 safi, NULL);
10114 }
10115
10116 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
10117 clear_bgp_instance_ipv6_safi_prefix_cmd,
10118 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
10119 CLEAR_STR
10120 IP_STR
10121 BGP_STR
10122 BGP_INSTANCE_HELP_STR
10123 "Address Family\n"
10124 BGP_SAFI_HELP_STR
10125 "Clear bestpath and re-advertise\n"
10126 "IPv6 prefix\n")
10127 {
10128 int idx_safi = 0;
10129 int idx_vrfview = 0;
10130 int idx_ipv6_prefix = 0;
10131 safi_t safi = SAFI_UNICAST;
10132 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
10133 argv[idx_ipv6_prefix]->arg : NULL;
10134 char *vrfview = NULL;
10135
10136 /* [<view|vrf> VIEWVRFNAME] */
10137 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
10138 vrfview = argv[idx_vrfview + 1]->arg;
10139 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
10140 vrfview = NULL;
10141 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
10142 /* [<view> VIEWVRFNAME] */
10143 vrfview = argv[idx_vrfview + 1]->arg;
10144 }
10145 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
10146
10147 return bgp_clear_prefix(
10148 vty, vrfview, prefix,
10149 AFI_IP6, safi, NULL);
10150 }
10151
10152 DEFUN (show_bgp_views,
10153 show_bgp_views_cmd,
10154 "show [ip] bgp views",
10155 SHOW_STR
10156 IP_STR
10157 BGP_STR
10158 "Show the defined BGP views\n")
10159 {
10160 struct list *inst = bm->bgp;
10161 struct listnode *node;
10162 struct bgp *bgp;
10163
10164 vty_out(vty, "Defined BGP views:\n");
10165 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10166 /* Skip VRFs. */
10167 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
10168 continue;
10169 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
10170 bgp->as);
10171 }
10172
10173 return CMD_SUCCESS;
10174 }
10175
10176 DEFUN (show_bgp_vrfs,
10177 show_bgp_vrfs_cmd,
10178 "show [ip] bgp vrfs [json]",
10179 SHOW_STR
10180 IP_STR
10181 BGP_STR
10182 "Show BGP VRFs\n"
10183 JSON_STR)
10184 {
10185 char buf[ETHER_ADDR_STRLEN];
10186 struct list *inst = bm->bgp;
10187 struct listnode *node;
10188 struct bgp *bgp;
10189 bool uj = use_json(argc, argv);
10190 json_object *json = NULL;
10191 json_object *json_vrfs = NULL;
10192 int count = 0;
10193
10194 if (uj) {
10195 json = json_object_new_object();
10196 json_vrfs = json_object_new_object();
10197 }
10198
10199 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10200 const char *name, *type;
10201 struct peer *peer;
10202 struct listnode *node2, *nnode2;
10203 int peers_cfg, peers_estb;
10204 json_object *json_vrf = NULL;
10205
10206 /* Skip Views. */
10207 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
10208 continue;
10209
10210 count++;
10211 if (!uj && count == 1) {
10212 vty_out(vty,
10213 "%4s %-5s %-16s %9s %10s %-37s\n",
10214 "Type", "Id", "routerId", "#PeersCfg",
10215 "#PeersEstb", "Name");
10216 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
10217 "L3-VNI", "RouterMAC", "Interface");
10218 }
10219
10220 peers_cfg = peers_estb = 0;
10221 if (uj)
10222 json_vrf = json_object_new_object();
10223
10224
10225 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
10226 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10227 continue;
10228 peers_cfg++;
10229 if (peer->status == Established)
10230 peers_estb++;
10231 }
10232
10233 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
10234 name = VRF_DEFAULT_NAME;
10235 type = "DFLT";
10236 } else {
10237 name = bgp->name;
10238 type = "VRF";
10239 }
10240
10241
10242 if (uj) {
10243 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10244 ? -1
10245 : (int64_t)bgp->vrf_id;
10246 char buf[BUFSIZ] = {0};
10247
10248 json_object_string_add(json_vrf, "type", type);
10249 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
10250 json_object_string_add(json_vrf, "routerId",
10251 inet_ntop(AF_INET,
10252 &bgp->router_id, buf,
10253 sizeof(buf)));
10254 json_object_int_add(json_vrf, "numConfiguredPeers",
10255 peers_cfg);
10256 json_object_int_add(json_vrf, "numEstablishedPeers",
10257 peers_estb);
10258
10259 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
10260 json_object_string_add(
10261 json_vrf, "rmac",
10262 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
10263 json_object_string_add(json_vrf, "interface",
10264 ifindex2ifname(bgp->l3vni_svi_ifindex,
10265 bgp->vrf_id));
10266 json_object_object_add(json_vrfs, name, json_vrf);
10267 } else {
10268 vty_out(vty, "%4s %-5d %-16pI4 %-9u %-10u %-37s\n",
10269 type,
10270 bgp->vrf_id == VRF_UNKNOWN ? -1
10271 : (int)bgp->vrf_id,
10272 &bgp->router_id, peers_cfg, peers_estb, name);
10273 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
10274 bgp->l3vni,
10275 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
10276 ifindex2ifname(bgp->l3vni_svi_ifindex,
10277 bgp->vrf_id));
10278 }
10279 }
10280
10281 if (uj) {
10282 json_object_object_add(json, "vrfs", json_vrfs);
10283
10284 json_object_int_add(json, "totalVrfs", count);
10285
10286 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10287 json, JSON_C_TO_STRING_PRETTY));
10288 json_object_free(json);
10289 } else {
10290 if (count)
10291 vty_out(vty,
10292 "\nTotal number of VRFs (including default): %d\n",
10293 count);
10294 }
10295
10296 return CMD_SUCCESS;
10297 }
10298
10299 DEFUN (show_bgp_mac_hash,
10300 show_bgp_mac_hash_cmd,
10301 "show bgp mac hash",
10302 SHOW_STR
10303 BGP_STR
10304 "Mac Address\n"
10305 "Mac Address database\n")
10306 {
10307 bgp_mac_dump_table(vty);
10308
10309 return CMD_SUCCESS;
10310 }
10311
10312 static void show_tip_entry(struct hash_bucket *bucket, void *args)
10313 {
10314 struct vty *vty = (struct vty *)args;
10315 struct tip_addr *tip = (struct tip_addr *)bucket->data;
10316
10317 vty_out(vty, "addr: %pI4, count: %d\n", &tip->addr, tip->refcnt);
10318 }
10319
10320 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
10321 {
10322 vty_out(vty, "self nexthop database:\n");
10323 bgp_nexthop_show_address_hash(vty, bgp);
10324
10325 vty_out(vty, "Tunnel-ip database:\n");
10326 hash_iterate(bgp->tip_hash,
10327 (void (*)(struct hash_bucket *, void *))show_tip_entry,
10328 vty);
10329 }
10330
10331 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
10332 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
10333 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
10334 "martian next-hops\n"
10335 "martian next-hop database\n")
10336 {
10337 struct bgp *bgp = NULL;
10338 int idx = 0;
10339 char *name = NULL;
10340
10341 /* [<vrf> VIEWVRFNAME] */
10342 if (argv_find(argv, argc, "vrf", &idx)) {
10343 name = argv[idx + 1]->arg;
10344 if (name && strmatch(name, VRF_DEFAULT_NAME))
10345 name = NULL;
10346 } else if (argv_find(argv, argc, "view", &idx))
10347 /* [<view> VIEWVRFNAME] */
10348 name = argv[idx + 1]->arg;
10349 if (name)
10350 bgp = bgp_lookup_by_name(name);
10351 else
10352 bgp = bgp_get_default();
10353
10354 if (!bgp) {
10355 vty_out(vty, "%% No BGP process is configured\n");
10356 return CMD_WARNING;
10357 }
10358 bgp_show_martian_nexthops(vty, bgp);
10359
10360 return CMD_SUCCESS;
10361 }
10362
10363 DEFUN (show_bgp_memory,
10364 show_bgp_memory_cmd,
10365 "show [ip] bgp memory",
10366 SHOW_STR
10367 IP_STR
10368 BGP_STR
10369 "Global BGP memory statistics\n")
10370 {
10371 char memstrbuf[MTYPE_MEMSTR_LEN];
10372 unsigned long count;
10373
10374 /* RIB related usage stats */
10375 count = mtype_stats_alloc(MTYPE_BGP_NODE);
10376 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
10377 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10378 count * sizeof(struct bgp_dest)));
10379
10380 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
10381 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
10382 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10383 count * sizeof(struct bgp_path_info)));
10384 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
10385 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
10386 count,
10387 mtype_memstr(
10388 memstrbuf, sizeof(memstrbuf),
10389 count * sizeof(struct bgp_path_info_extra)));
10390
10391 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
10392 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
10393 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10394 count * sizeof(struct bgp_static)));
10395
10396 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
10397 vty_out(vty, "%ld Packets, using %s of memory\n", count,
10398 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10399 count * sizeof(struct bpacket)));
10400
10401 /* Adj-In/Out */
10402 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
10403 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
10404 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10405 count * sizeof(struct bgp_adj_in)));
10406 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
10407 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
10408 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10409 count * sizeof(struct bgp_adj_out)));
10410
10411 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
10412 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
10413 count,
10414 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10415 count * sizeof(struct bgp_nexthop_cache)));
10416
10417 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
10418 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
10419 count,
10420 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10421 count * sizeof(struct bgp_damp_info)));
10422
10423 /* Attributes */
10424 count = attr_count();
10425 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
10426 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10427 count * sizeof(struct attr)));
10428
10429 if ((count = attr_unknown_count()))
10430 vty_out(vty, "%ld unknown attributes\n", count);
10431
10432 /* AS_PATH attributes */
10433 count = aspath_count();
10434 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
10435 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10436 count * sizeof(struct aspath)));
10437
10438 count = mtype_stats_alloc(MTYPE_AS_SEG);
10439 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
10440 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10441 count * sizeof(struct assegment)));
10442
10443 /* Other attributes */
10444 if ((count = community_count()))
10445 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
10446 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10447 count * sizeof(struct community)));
10448 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
10449 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
10450 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10451 count * sizeof(struct ecommunity)));
10452 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
10453 vty_out(vty,
10454 "%ld BGP large-community entries, using %s of memory\n",
10455 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10456 count * sizeof(struct lcommunity)));
10457
10458 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
10459 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
10460 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10461 count * sizeof(struct cluster_list)));
10462
10463 /* Peer related usage */
10464 count = mtype_stats_alloc(MTYPE_BGP_PEER);
10465 vty_out(vty, "%ld peers, using %s of memory\n", count,
10466 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10467 count * sizeof(struct peer)));
10468
10469 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
10470 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
10471 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10472 count * sizeof(struct peer_group)));
10473
10474 /* Other */
10475 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
10476 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
10477 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10478 count * sizeof(regex_t)));
10479 return CMD_SUCCESS;
10480 }
10481
10482 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
10483 {
10484 json_object *bestpath = json_object_new_object();
10485
10486 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
10487 json_object_string_add(bestpath, "asPath", "ignore");
10488
10489 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
10490 json_object_string_add(bestpath, "asPath", "confed");
10491
10492 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
10493 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
10494 json_object_string_add(bestpath, "multiPathRelax",
10495 "as-set");
10496 else
10497 json_object_string_add(bestpath, "multiPathRelax",
10498 "true");
10499 } else
10500 json_object_string_add(bestpath, "multiPathRelax", "false");
10501
10502 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
10503 json_object_string_add(bestpath, "compareRouterId", "true");
10504 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
10505 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
10506 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
10507 json_object_string_add(bestpath, "med", "confed");
10508 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
10509 json_object_string_add(bestpath, "med",
10510 "missing-as-worst");
10511 else
10512 json_object_string_add(bestpath, "med", "true");
10513 }
10514
10515 json_object_object_add(json, "bestPath", bestpath);
10516 }
10517
10518 /* Print the error code/subcode for why the peer is down */
10519 static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
10520 json_object *json_peer, bool use_json)
10521 {
10522 const char *code_str;
10523 const char *subcode_str;
10524
10525 if (use_json) {
10526 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10527 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10528 char errorcodesubcode_hexstr[5];
10529 char errorcodesubcode_str[256];
10530
10531 code_str = bgp_notify_code_str(peer->notify.code);
10532 subcode_str = bgp_notify_subcode_str(
10533 peer->notify.code,
10534 peer->notify.subcode);
10535
10536 snprintf(errorcodesubcode_hexstr,
10537 sizeof(errorcodesubcode_hexstr), "%02X%02X",
10538 peer->notify.code, peer->notify.subcode);
10539 json_object_string_add(json_peer,
10540 "lastErrorCodeSubcode",
10541 errorcodesubcode_hexstr);
10542 snprintf(errorcodesubcode_str, 255, "%s%s",
10543 code_str, subcode_str);
10544 json_object_string_add(json_peer,
10545 "lastNotificationReason",
10546 errorcodesubcode_str);
10547 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10548 && peer->notify.code == BGP_NOTIFY_CEASE
10549 && (peer->notify.subcode
10550 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10551 || peer->notify.subcode
10552 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10553 && peer->notify.length) {
10554 char msgbuf[1024];
10555 const char *msg_str;
10556
10557 msg_str = bgp_notify_admin_message(
10558 msgbuf, sizeof(msgbuf),
10559 (uint8_t *)peer->notify.data,
10560 peer->notify.length);
10561 if (msg_str)
10562 json_object_string_add(
10563 json_peer,
10564 "lastShutdownDescription",
10565 msg_str);
10566 }
10567
10568 }
10569 json_object_string_add(json_peer, "lastResetDueTo",
10570 peer_down_str[(int)peer->last_reset]);
10571 json_object_int_add(json_peer, "lastResetCode",
10572 peer->last_reset);
10573 } else {
10574 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10575 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10576 code_str = bgp_notify_code_str(peer->notify.code);
10577 subcode_str =
10578 bgp_notify_subcode_str(peer->notify.code,
10579 peer->notify.subcode);
10580 vty_out(vty, " Notification %s (%s%s)\n",
10581 peer->last_reset == PEER_DOWN_NOTIFY_SEND
10582 ? "sent"
10583 : "received",
10584 code_str, subcode_str);
10585 } else {
10586 vty_out(vty, " %s\n",
10587 peer_down_str[(int)peer->last_reset]);
10588 }
10589 }
10590 }
10591
10592 static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
10593 safi_t safi)
10594 {
10595 return ((peer->status != Established) ||
10596 !peer->afc_recv[afi][safi]);
10597 }
10598
10599 static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
10600 struct peer *peer, json_object *json_peer,
10601 int max_neighbor_width, bool use_json)
10602 {
10603 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10604 int len;
10605
10606 if (use_json) {
10607 if (peer_dynamic_neighbor(peer))
10608 json_object_boolean_true_add(json_peer,
10609 "dynamicPeer");
10610 if (peer->hostname)
10611 json_object_string_add(json_peer, "hostname",
10612 peer->hostname);
10613
10614 if (peer->domainname)
10615 json_object_string_add(json_peer, "domainname",
10616 peer->domainname);
10617 json_object_int_add(json_peer, "connectionsEstablished",
10618 peer->established);
10619 json_object_int_add(json_peer, "connectionsDropped",
10620 peer->dropped);
10621 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10622 use_json, json_peer);
10623 if (peer->status == Established)
10624 json_object_string_add(json_peer, "lastResetDueTo",
10625 "AFI/SAFI Not Negotiated");
10626 else
10627 bgp_show_peer_reset(NULL, peer, json_peer, true);
10628 } else {
10629 dn_flag[1] = '\0';
10630 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
10631 if (peer->hostname
10632 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
10633 len = vty_out(vty, "%s%s(%s)", dn_flag,
10634 peer->hostname, peer->host);
10635 else
10636 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10637
10638 /* pad the neighbor column with spaces */
10639 if (len < max_neighbor_width)
10640 vty_out(vty, "%*s", max_neighbor_width - len,
10641 " ");
10642 vty_out(vty, "%7d %7d %9s", peer->established,
10643 peer->dropped,
10644 peer_uptime(peer->uptime, timebuf,
10645 BGP_UPTIME_LEN, 0, NULL));
10646 if (peer->status == Established)
10647 vty_out(vty, " AFI/SAFI Not Negotiated\n");
10648 else
10649 bgp_show_peer_reset(vty, peer, NULL,
10650 false);
10651 }
10652 }
10653
10654
10655 /* Show BGP peer's summary information. */
10656 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
10657 bool show_failed, bool show_established,
10658 bool use_json)
10659 {
10660 struct peer *peer;
10661 struct listnode *node, *nnode;
10662 unsigned int count = 0, dn_count = 0;
10663 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10664 char neighbor_buf[VTY_BUFSIZ];
10665 int neighbor_col_default_width = 16;
10666 int len, failed_count = 0;
10667 int max_neighbor_width = 0;
10668 int pfx_rcd_safi;
10669 json_object *json = NULL;
10670 json_object *json_peer = NULL;
10671 json_object *json_peers = NULL;
10672 struct peer_af *paf;
10673 struct bgp_filter *filter;
10674
10675 /* labeled-unicast routes are installed in the unicast table so in order
10676 * to
10677 * display the correct PfxRcd value we must look at SAFI_UNICAST
10678 */
10679
10680 if (safi == SAFI_LABELED_UNICAST)
10681 pfx_rcd_safi = SAFI_UNICAST;
10682 else
10683 pfx_rcd_safi = safi;
10684
10685 if (use_json) {
10686 json = json_object_new_object();
10687 json_peers = json_object_new_object();
10688 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10689 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10690 continue;
10691
10692 if (peer->afc[afi][safi]) {
10693 /* See if we have at least a single failed peer */
10694 if (bgp_has_peer_failed(peer, afi, safi))
10695 failed_count++;
10696 count++;
10697 }
10698 if (peer_dynamic_neighbor(peer))
10699 dn_count++;
10700 }
10701
10702 } else {
10703 /* Loop over all neighbors that will be displayed to determine
10704 * how many
10705 * characters are needed for the Neighbor column
10706 */
10707 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10708 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10709 continue;
10710
10711 if (peer->afc[afi][safi]) {
10712 memset(dn_flag, '\0', sizeof(dn_flag));
10713 if (peer_dynamic_neighbor(peer))
10714 dn_flag[0] = '*';
10715
10716 if (peer->hostname
10717 && CHECK_FLAG(bgp->flags,
10718 BGP_FLAG_SHOW_HOSTNAME))
10719 snprintf(neighbor_buf,
10720 sizeof(neighbor_buf),
10721 "%s%s(%s) ", dn_flag,
10722 peer->hostname, peer->host);
10723 else
10724 snprintf(neighbor_buf,
10725 sizeof(neighbor_buf), "%s%s ",
10726 dn_flag, peer->host);
10727
10728 len = strlen(neighbor_buf);
10729
10730 if (len > max_neighbor_width)
10731 max_neighbor_width = len;
10732
10733 /* See if we have at least a single failed peer */
10734 if (bgp_has_peer_failed(peer, afi, safi))
10735 failed_count++;
10736 count++;
10737 }
10738 }
10739
10740 /* Originally we displayed the Neighbor column as 16
10741 * characters wide so make that the default
10742 */
10743 if (max_neighbor_width < neighbor_col_default_width)
10744 max_neighbor_width = neighbor_col_default_width;
10745 }
10746
10747 if (show_failed && !failed_count) {
10748 if (use_json) {
10749 json_object_int_add(json, "failedPeersCount", 0);
10750 json_object_int_add(json, "dynamicPeers", dn_count);
10751 json_object_int_add(json, "totalPeers", count);
10752
10753 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10754 json, JSON_C_TO_STRING_PRETTY));
10755 json_object_free(json);
10756 } else {
10757 vty_out(vty, "%% No failed BGP neighbors found\n");
10758 vty_out(vty, "\nTotal number of neighbors %d\n", count);
10759 }
10760 return CMD_SUCCESS;
10761 }
10762
10763 count = 0; /* Reset the value as its used again */
10764 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10765 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10766 continue;
10767
10768 if (!peer->afc[afi][safi])
10769 continue;
10770
10771 if (!count) {
10772 unsigned long ents;
10773 char memstrbuf[MTYPE_MEMSTR_LEN];
10774 int64_t vrf_id_ui;
10775
10776 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10777 ? -1
10778 : (int64_t)bgp->vrf_id;
10779
10780 /* Usage summary and header */
10781 if (use_json) {
10782 char buf[BUFSIZ] = {0};
10783
10784 json_object_string_add(
10785 json, "routerId",
10786 inet_ntop(AF_INET, &bgp->router_id, buf,
10787 sizeof(buf)));
10788 json_object_int_add(json, "as", bgp->as);
10789 json_object_int_add(json, "vrfId", vrf_id_ui);
10790 json_object_string_add(
10791 json, "vrfName",
10792 (bgp->inst_type
10793 == BGP_INSTANCE_TYPE_DEFAULT)
10794 ? VRF_DEFAULT_NAME
10795 : bgp->name);
10796 } else {
10797 vty_out(vty,
10798 "BGP router identifier %pI4, local AS number %u vrf-id %d",
10799 &bgp->router_id, bgp->as,
10800 bgp->vrf_id == VRF_UNKNOWN
10801 ? -1
10802 : (int)bgp->vrf_id);
10803 vty_out(vty, "\n");
10804 }
10805
10806 if (bgp_update_delay_configured(bgp)) {
10807 if (use_json) {
10808 json_object_int_add(
10809 json, "updateDelayLimit",
10810 bgp->v_update_delay);
10811
10812 if (bgp->v_update_delay
10813 != bgp->v_establish_wait)
10814 json_object_int_add(
10815 json,
10816 "updateDelayEstablishWait",
10817 bgp->v_establish_wait);
10818
10819 if (bgp_update_delay_active(bgp)) {
10820 json_object_string_add(
10821 json,
10822 "updateDelayFirstNeighbor",
10823 bgp->update_delay_begin_time);
10824 json_object_boolean_true_add(
10825 json,
10826 "updateDelayInProgress");
10827 } else {
10828 if (bgp->update_delay_over) {
10829 json_object_string_add(
10830 json,
10831 "updateDelayFirstNeighbor",
10832 bgp->update_delay_begin_time);
10833 json_object_string_add(
10834 json,
10835 "updateDelayBestpathResumed",
10836 bgp->update_delay_end_time);
10837 json_object_string_add(
10838 json,
10839 "updateDelayZebraUpdateResume",
10840 bgp->update_delay_zebra_resume_time);
10841 json_object_string_add(
10842 json,
10843 "updateDelayPeerUpdateResume",
10844 bgp->update_delay_peers_resume_time);
10845 }
10846 }
10847 } else {
10848 vty_out(vty,
10849 "Read-only mode update-delay limit: %d seconds\n",
10850 bgp->v_update_delay);
10851 if (bgp->v_update_delay
10852 != bgp->v_establish_wait)
10853 vty_out(vty,
10854 " Establish wait: %d seconds\n",
10855 bgp->v_establish_wait);
10856
10857 if (bgp_update_delay_active(bgp)) {
10858 vty_out(vty,
10859 " First neighbor established: %s\n",
10860 bgp->update_delay_begin_time);
10861 vty_out(vty,
10862 " Delay in progress\n");
10863 } else {
10864 if (bgp->update_delay_over) {
10865 vty_out(vty,
10866 " First neighbor established: %s\n",
10867 bgp->update_delay_begin_time);
10868 vty_out(vty,
10869 " Best-paths resumed: %s\n",
10870 bgp->update_delay_end_time);
10871 vty_out(vty,
10872 " zebra update resumed: %s\n",
10873 bgp->update_delay_zebra_resume_time);
10874 vty_out(vty,
10875 " peers update resumed: %s\n",
10876 bgp->update_delay_peers_resume_time);
10877 }
10878 }
10879 }
10880 }
10881
10882 if (use_json) {
10883 if (bgp_maxmed_onstartup_configured(bgp)
10884 && bgp->maxmed_active)
10885 json_object_boolean_true_add(
10886 json, "maxMedOnStartup");
10887 if (bgp->v_maxmed_admin)
10888 json_object_boolean_true_add(
10889 json, "maxMedAdministrative");
10890
10891 json_object_int_add(
10892 json, "tableVersion",
10893 bgp_table_version(bgp->rib[afi][safi]));
10894
10895 ents = bgp_table_count(bgp->rib[afi][safi]);
10896 json_object_int_add(json, "ribCount", ents);
10897 json_object_int_add(
10898 json, "ribMemory",
10899 ents * sizeof(struct bgp_dest));
10900
10901 ents = bgp->af_peer_count[afi][safi];
10902 json_object_int_add(json, "peerCount", ents);
10903 json_object_int_add(json, "peerMemory",
10904 ents * sizeof(struct peer));
10905
10906 if ((ents = listcount(bgp->group))) {
10907 json_object_int_add(
10908 json, "peerGroupCount", ents);
10909 json_object_int_add(
10910 json, "peerGroupMemory",
10911 ents * sizeof(struct
10912 peer_group));
10913 }
10914
10915 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10916 BGP_CONFIG_DAMPENING))
10917 json_object_boolean_true_add(
10918 json, "dampeningEnabled");
10919 } else {
10920 if (bgp_maxmed_onstartup_configured(bgp)
10921 && bgp->maxmed_active)
10922 vty_out(vty,
10923 "Max-med on-startup active\n");
10924 if (bgp->v_maxmed_admin)
10925 vty_out(vty,
10926 "Max-med administrative active\n");
10927
10928 vty_out(vty, "BGP table version %" PRIu64 "\n",
10929 bgp_table_version(bgp->rib[afi][safi]));
10930
10931 ents = bgp_table_count(bgp->rib[afi][safi]);
10932 vty_out(vty,
10933 "RIB entries %ld, using %s of memory\n",
10934 ents,
10935 mtype_memstr(
10936 memstrbuf, sizeof(memstrbuf),
10937 ents
10938 * sizeof(struct
10939 bgp_dest)));
10940
10941 /* Peer related usage */
10942 ents = bgp->af_peer_count[afi][safi];
10943 vty_out(vty, "Peers %ld, using %s of memory\n",
10944 ents,
10945 mtype_memstr(
10946 memstrbuf, sizeof(memstrbuf),
10947 ents * sizeof(struct peer)));
10948
10949 if ((ents = listcount(bgp->group)))
10950 vty_out(vty,
10951 "Peer groups %ld, using %s of memory\n",
10952 ents,
10953 mtype_memstr(
10954 memstrbuf,
10955 sizeof(memstrbuf),
10956 ents * sizeof(struct
10957 peer_group)));
10958
10959 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10960 BGP_CONFIG_DAMPENING))
10961 vty_out(vty, "Dampening enabled.\n");
10962 vty_out(vty, "\n");
10963
10964 /* Subtract 8 here because 'Neighbor' is
10965 * 8 characters */
10966 vty_out(vty, "Neighbor");
10967 vty_out(vty, "%*s", max_neighbor_width - 8,
10968 " ");
10969 if (show_failed)
10970 vty_out(vty, "EstdCnt DropCnt ResetTime Reason\n");
10971 else
10972 vty_out(vty,
10973 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd PfxSnt Desc\n");
10974 }
10975 }
10976
10977 paf = peer_af_find(peer, afi, safi);
10978 filter = &peer->filter[afi][safi];
10979
10980 count++;
10981 /* Works for both failed & successful cases */
10982 if (peer_dynamic_neighbor(peer))
10983 dn_count++;
10984
10985 if (use_json) {
10986 json_peer = NULL;
10987
10988 if (show_failed &&
10989 bgp_has_peer_failed(peer, afi, safi)) {
10990 json_peer = json_object_new_object();
10991 bgp_show_failed_summary(vty, bgp, peer,
10992 json_peer, 0, use_json);
10993 } else if (!show_failed) {
10994 if (show_established
10995 && bgp_has_peer_failed(peer, afi, safi))
10996 continue;
10997
10998 json_peer = json_object_new_object();
10999 if (peer_dynamic_neighbor(peer)) {
11000 json_object_boolean_true_add(json_peer,
11001 "dynamicPeer");
11002 }
11003
11004 if (peer->hostname)
11005 json_object_string_add(json_peer, "hostname",
11006 peer->hostname);
11007
11008 if (peer->domainname)
11009 json_object_string_add(json_peer, "domainname",
11010 peer->domainname);
11011
11012 json_object_int_add(json_peer, "remoteAs", peer->as);
11013 json_object_int_add(json_peer, "version", 4);
11014 json_object_int_add(json_peer, "msgRcvd",
11015 PEER_TOTAL_RX(peer));
11016 json_object_int_add(json_peer, "msgSent",
11017 PEER_TOTAL_TX(peer));
11018
11019 atomic_size_t outq_count, inq_count;
11020 outq_count = atomic_load_explicit(
11021 &peer->obuf->count,
11022 memory_order_relaxed);
11023 inq_count = atomic_load_explicit(
11024 &peer->ibuf->count,
11025 memory_order_relaxed);
11026
11027 json_object_int_add(json_peer, "tableVersion",
11028 peer->version[afi][safi]);
11029 json_object_int_add(json_peer, "outq",
11030 outq_count);
11031 json_object_int_add(json_peer, "inq",
11032 inq_count);
11033 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
11034 use_json, json_peer);
11035
11036 json_object_int_add(json_peer, "pfxRcd",
11037 peer->pcount[afi][pfx_rcd_safi]);
11038
11039 if (paf && PAF_SUBGRP(paf))
11040 json_object_int_add(
11041 json_peer, "pfxSnt",
11042 (PAF_SUBGRP(paf))->scount);
11043 else
11044 json_object_int_add(json_peer, "pfxSnt",
11045 0);
11046
11047 /* BGP FSM state */
11048 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
11049 || CHECK_FLAG(peer->bgp->flags,
11050 BGP_FLAG_SHUTDOWN))
11051 json_object_string_add(json_peer,
11052 "state",
11053 "Idle (Admin)");
11054 else if (peer->afc_recv[afi][safi])
11055 json_object_string_add(
11056 json_peer, "state",
11057 lookup_msg(bgp_status_msg,
11058 peer->status, NULL));
11059 else if (CHECK_FLAG(
11060 peer->sflags,
11061 PEER_STATUS_PREFIX_OVERFLOW))
11062 json_object_string_add(json_peer,
11063 "state",
11064 "Idle (PfxCt)");
11065 else
11066 json_object_string_add(
11067 json_peer, "state",
11068 lookup_msg(bgp_status_msg,
11069 peer->status, NULL));
11070
11071 /* BGP peer state */
11072 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
11073 || CHECK_FLAG(peer->bgp->flags,
11074 BGP_FLAG_SHUTDOWN))
11075 json_object_string_add(json_peer,
11076 "peerState",
11077 "Admin");
11078 else if (CHECK_FLAG(
11079 peer->sflags,
11080 PEER_STATUS_PREFIX_OVERFLOW))
11081 json_object_string_add(json_peer,
11082 "peerState",
11083 "PfxCt");
11084 else if (CHECK_FLAG(peer->flags,
11085 PEER_FLAG_PASSIVE))
11086 json_object_string_add(json_peer,
11087 "peerState",
11088 "Passive");
11089 else if (CHECK_FLAG(peer->sflags,
11090 PEER_STATUS_NSF_WAIT))
11091 json_object_string_add(json_peer,
11092 "peerState",
11093 "NSF passive");
11094 else if (CHECK_FLAG(
11095 peer->bgp->flags,
11096 BGP_FLAG_EBGP_REQUIRES_POLICY)
11097 && (!bgp_inbound_policy_exists(peer,
11098 filter)
11099 || !bgp_outbound_policy_exists(
11100 peer, filter)))
11101 json_object_string_add(json_peer,
11102 "peerState",
11103 "Policy");
11104 else
11105 json_object_string_add(
11106 json_peer, "peerState", "OK");
11107
11108 json_object_int_add(json_peer, "connectionsEstablished",
11109 peer->established);
11110 json_object_int_add(json_peer, "connectionsDropped",
11111 peer->dropped);
11112 if (peer->desc)
11113 json_object_string_add(
11114 json_peer, "desc", peer->desc);
11115 }
11116 /* Avoid creating empty peer dicts in JSON */
11117 if (json_peer == NULL)
11118 continue;
11119
11120 if (peer->conf_if)
11121 json_object_string_add(json_peer, "idType",
11122 "interface");
11123 else if (peer->su.sa.sa_family == AF_INET)
11124 json_object_string_add(json_peer, "idType",
11125 "ipv4");
11126 else if (peer->su.sa.sa_family == AF_INET6)
11127 json_object_string_add(json_peer, "idType",
11128 "ipv6");
11129 json_object_object_add(json_peers, peer->host,
11130 json_peer);
11131 } else {
11132 if (show_failed &&
11133 bgp_has_peer_failed(peer, afi, safi)) {
11134 bgp_show_failed_summary(vty, bgp, peer, NULL,
11135 max_neighbor_width,
11136 use_json);
11137 } else if (!show_failed) {
11138 if (show_established
11139 && bgp_has_peer_failed(peer, afi, safi))
11140 continue;
11141
11142 memset(dn_flag, '\0', sizeof(dn_flag));
11143 if (peer_dynamic_neighbor(peer)) {
11144 dn_flag[0] = '*';
11145 }
11146
11147 if (peer->hostname
11148 && CHECK_FLAG(bgp->flags,
11149 BGP_FLAG_SHOW_HOSTNAME))
11150 len = vty_out(vty, "%s%s(%s)", dn_flag,
11151 peer->hostname,
11152 peer->host);
11153 else
11154 len = vty_out(vty, "%s%s", dn_flag, peer->host);
11155
11156 /* pad the neighbor column with spaces */
11157 if (len < max_neighbor_width)
11158 vty_out(vty, "%*s", max_neighbor_width - len,
11159 " ");
11160
11161 atomic_size_t outq_count, inq_count;
11162 outq_count = atomic_load_explicit(
11163 &peer->obuf->count,
11164 memory_order_relaxed);
11165 inq_count = atomic_load_explicit(
11166 &peer->ibuf->count,
11167 memory_order_relaxed);
11168
11169 vty_out(vty,
11170 "4 %10u %9u %9u %8" PRIu64" %4zu %4zu %8s",
11171 peer->as, PEER_TOTAL_RX(peer),
11172 PEER_TOTAL_TX(peer),
11173 peer->version[afi][safi], inq_count,
11174 outq_count,
11175 peer_uptime(peer->uptime, timebuf,
11176 BGP_UPTIME_LEN, 0, NULL));
11177
11178 if (peer->status == Established) {
11179 if (peer->afc_recv[afi][safi]) {
11180 if (CHECK_FLAG(
11181 bgp->flags,
11182 BGP_FLAG_EBGP_REQUIRES_POLICY)
11183 && !bgp_inbound_policy_exists(
11184 peer, filter))
11185 vty_out(vty, " %12s",
11186 "(Policy)");
11187 else
11188 vty_out(vty,
11189 " %12u",
11190 peer->pcount
11191 [afi]
11192 [pfx_rcd_safi]);
11193 } else {
11194 vty_out(vty, " NoNeg");
11195 }
11196
11197 if (paf && PAF_SUBGRP(paf)) {
11198 if (CHECK_FLAG(
11199 bgp->flags,
11200 BGP_FLAG_EBGP_REQUIRES_POLICY)
11201 && !bgp_outbound_policy_exists(
11202 peer, filter))
11203 vty_out(vty, " %8s",
11204 "(Policy)");
11205 else
11206 vty_out(vty,
11207 " %8u",
11208 (PAF_SUBGRP(
11209 paf))
11210 ->scount);
11211 }
11212 } else {
11213 if (CHECK_FLAG(peer->flags,
11214 PEER_FLAG_SHUTDOWN)
11215 || CHECK_FLAG(peer->bgp->flags,
11216 BGP_FLAG_SHUTDOWN))
11217 vty_out(vty, " Idle (Admin)");
11218 else if (CHECK_FLAG(
11219 peer->sflags,
11220 PEER_STATUS_PREFIX_OVERFLOW))
11221 vty_out(vty, " Idle (PfxCt)");
11222 else
11223 vty_out(vty, " %12s",
11224 lookup_msg(bgp_status_msg,
11225 peer->status, NULL));
11226
11227 vty_out(vty, " %8u", 0);
11228 }
11229 if (peer->desc)
11230 vty_out(vty, " %s", peer->desc);
11231 else
11232 vty_out(vty, " N/A");
11233 vty_out(vty, "\n");
11234 }
11235
11236 }
11237 }
11238
11239 if (use_json) {
11240 json_object_object_add(json, "peers", json_peers);
11241 json_object_int_add(json, "failedPeers", failed_count);
11242 json_object_int_add(json, "totalPeers", count);
11243 json_object_int_add(json, "dynamicPeers", dn_count);
11244
11245 if (!show_failed)
11246 bgp_show_bestpath_json(bgp, json);
11247
11248 vty_out(vty, "%s\n", json_object_to_json_string_ext(
11249 json, JSON_C_TO_STRING_PRETTY));
11250 json_object_free(json);
11251 } else {
11252 if (count)
11253 vty_out(vty, "\nTotal number of neighbors %d\n", count);
11254 else {
11255 vty_out(vty, "No %s neighbor is configured\n",
11256 get_afi_safi_str(afi, safi, false));
11257 }
11258
11259 if (dn_count) {
11260 vty_out(vty, "* - dynamic neighbor\n");
11261 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
11262 dn_count, bgp->dynamic_neighbors_limit);
11263 }
11264 }
11265
11266 return CMD_SUCCESS;
11267 }
11268
11269 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
11270 int safi, bool show_failed,
11271 bool show_established, bool use_json)
11272 {
11273 int is_first = 1;
11274 int afi_wildcard = (afi == AFI_MAX);
11275 int safi_wildcard = (safi == SAFI_MAX);
11276 int is_wildcard = (afi_wildcard || safi_wildcard);
11277 bool nbr_output = false;
11278
11279 if (use_json && is_wildcard)
11280 vty_out(vty, "{\n");
11281 if (afi_wildcard)
11282 afi = 1; /* AFI_IP */
11283 while (afi < AFI_MAX) {
11284 if (safi_wildcard)
11285 safi = 1; /* SAFI_UNICAST */
11286 while (safi < SAFI_MAX) {
11287 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
11288 nbr_output = true;
11289
11290 if (is_wildcard) {
11291 /*
11292 * So limit output to those afi/safi
11293 * pairs that
11294 * actualy have something interesting in
11295 * them
11296 */
11297 if (use_json) {
11298 if (!is_first)
11299 vty_out(vty, ",\n");
11300 else
11301 is_first = 0;
11302
11303 vty_out(vty, "\"%s\":",
11304 get_afi_safi_str(afi,
11305 safi,
11306 true));
11307 } else {
11308 vty_out(vty, "\n%s Summary:\n",
11309 get_afi_safi_str(afi,
11310 safi,
11311 false));
11312 }
11313 }
11314 bgp_show_summary(vty, bgp, afi, safi,
11315 show_failed, show_established,
11316 use_json);
11317 }
11318 safi++;
11319 if (!safi_wildcard)
11320 safi = SAFI_MAX;
11321 }
11322 afi++;
11323 if (!afi_wildcard)
11324 afi = AFI_MAX;
11325 }
11326
11327 if (use_json && is_wildcard)
11328 vty_out(vty, "}\n");
11329 else if (!nbr_output) {
11330 if (use_json)
11331 vty_out(vty, "{}\n");
11332 else
11333 vty_out(vty, "%% No BGP neighbors found\n");
11334 }
11335 }
11336
11337 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
11338 safi_t safi, bool show_failed,
11339 bool show_established,
11340 bool use_json)
11341 {
11342 struct listnode *node, *nnode;
11343 struct bgp *bgp;
11344 int is_first = 1;
11345 bool nbr_output = false;
11346
11347 if (use_json)
11348 vty_out(vty, "{\n");
11349
11350 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11351 nbr_output = true;
11352 if (use_json) {
11353 if (!is_first)
11354 vty_out(vty, ",\n");
11355 else
11356 is_first = 0;
11357
11358 vty_out(vty, "\"%s\":",
11359 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11360 ? VRF_DEFAULT_NAME
11361 : bgp->name);
11362 } else {
11363 vty_out(vty, "\nInstance %s:\n",
11364 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11365 ? VRF_DEFAULT_NAME
11366 : bgp->name);
11367 }
11368 bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_failed,
11369 show_established, use_json);
11370 }
11371
11372 if (use_json)
11373 vty_out(vty, "}\n");
11374 else if (!nbr_output)
11375 vty_out(vty, "%% BGP instance not found\n");
11376 }
11377
11378 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
11379 safi_t safi, bool show_failed, bool show_established,
11380 bool use_json)
11381 {
11382 struct bgp *bgp;
11383
11384 if (name) {
11385 if (strmatch(name, "all")) {
11386 bgp_show_all_instances_summary_vty(
11387 vty, afi, safi, show_failed, show_established,
11388 use_json);
11389 return CMD_SUCCESS;
11390 } else {
11391 bgp = bgp_lookup_by_name(name);
11392
11393 if (!bgp) {
11394 if (use_json)
11395 vty_out(vty, "{}\n");
11396 else
11397 vty_out(vty,
11398 "%% BGP instance not found\n");
11399 return CMD_WARNING;
11400 }
11401
11402 bgp_show_summary_afi_safi(vty, bgp, afi, safi,
11403 show_failed, show_established,
11404 use_json);
11405 return CMD_SUCCESS;
11406 }
11407 }
11408
11409 bgp = bgp_get_default();
11410
11411 if (bgp)
11412 bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_failed,
11413 show_established, use_json);
11414 else {
11415 if (use_json)
11416 vty_out(vty, "{}\n");
11417 else
11418 vty_out(vty, "%% BGP instance not found\n");
11419 return CMD_WARNING;
11420 }
11421
11422 return CMD_SUCCESS;
11423 }
11424
11425 /* `show [ip] bgp summary' commands. */
11426 DEFPY (show_ip_bgp_summary,
11427 show_ip_bgp_summary_cmd,
11428 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] [all$all] summary [established|failed] [json$uj]",
11429 SHOW_STR
11430 IP_STR
11431 BGP_STR
11432 BGP_INSTANCE_HELP_STR
11433 BGP_AFI_HELP_STR
11434 BGP_SAFI_WITH_LABEL_HELP_STR
11435 "Display the entries for all address families\n"
11436 "Summary of BGP neighbor status\n"
11437 "Show only sessions in Established state\n"
11438 "Show only sessions not in Established state\n"
11439 JSON_STR)
11440 {
11441 char *vrf = NULL;
11442 afi_t afi = AFI_MAX;
11443 safi_t safi = SAFI_MAX;
11444 bool show_failed = false;
11445 bool show_established = false;
11446
11447 int idx = 0;
11448
11449 /* show [ip] bgp */
11450 if (!all && argv_find(argv, argc, "ip", &idx))
11451 afi = AFI_IP;
11452 /* [<vrf> VIEWVRFNAME] */
11453 if (argv_find(argv, argc, "vrf", &idx)) {
11454 vrf = argv[idx + 1]->arg;
11455 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11456 vrf = NULL;
11457 } else if (argv_find(argv, argc, "view", &idx))
11458 /* [<view> VIEWVRFNAME] */
11459 vrf = argv[idx + 1]->arg;
11460 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11461 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11462 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11463 }
11464
11465 if (argv_find(argv, argc, "failed", &idx))
11466 show_failed = true;
11467 if (argv_find(argv, argc, "established", &idx))
11468 show_established = true;
11469
11470 return bgp_show_summary_vty(vty, vrf, afi, safi, show_failed,
11471 show_established, uj);
11472 }
11473
11474 const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
11475 {
11476 if (for_json)
11477 return get_afi_safi_json_str(afi, safi);
11478 else
11479 return get_afi_safi_vty_str(afi, safi);
11480 }
11481
11482
11483 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
11484 afi_t afi, safi_t safi,
11485 uint16_t adv_smcap, uint16_t adv_rmcap,
11486 uint16_t rcv_smcap, uint16_t rcv_rmcap,
11487 bool use_json, json_object *json_pref)
11488 {
11489 /* Send-Mode */
11490 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11491 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
11492 if (use_json) {
11493 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11494 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11495 json_object_string_add(json_pref, "sendMode",
11496 "advertisedAndReceived");
11497 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11498 json_object_string_add(json_pref, "sendMode",
11499 "advertised");
11500 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11501 json_object_string_add(json_pref, "sendMode",
11502 "received");
11503 } else {
11504 vty_out(vty, " Send-mode: ");
11505 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11506 vty_out(vty, "advertised");
11507 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11508 vty_out(vty, "%sreceived",
11509 CHECK_FLAG(p->af_cap[afi][safi],
11510 adv_smcap)
11511 ? ", "
11512 : "");
11513 vty_out(vty, "\n");
11514 }
11515 }
11516
11517 /* Receive-Mode */
11518 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11519 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
11520 if (use_json) {
11521 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11522 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11523 json_object_string_add(json_pref, "recvMode",
11524 "advertisedAndReceived");
11525 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11526 json_object_string_add(json_pref, "recvMode",
11527 "advertised");
11528 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11529 json_object_string_add(json_pref, "recvMode",
11530 "received");
11531 } else {
11532 vty_out(vty, " Receive-mode: ");
11533 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11534 vty_out(vty, "advertised");
11535 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11536 vty_out(vty, "%sreceived",
11537 CHECK_FLAG(p->af_cap[afi][safi],
11538 adv_rmcap)
11539 ? ", "
11540 : "");
11541 vty_out(vty, "\n");
11542 }
11543 }
11544 }
11545
11546 static void bgp_show_neighnor_graceful_restart_rbit(struct vty *vty,
11547 struct peer *p,
11548 bool use_json,
11549 json_object *json)
11550 {
11551 bool rbit_status = false;
11552
11553 if (!use_json)
11554 vty_out(vty, "\n R bit: ");
11555
11556 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
11557 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
11558 && (p->status == Established)) {
11559
11560 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_BIT_RCV))
11561 rbit_status = true;
11562 else
11563 rbit_status = false;
11564 }
11565
11566 if (rbit_status) {
11567 if (use_json)
11568 json_object_boolean_true_add(json, "rBit");
11569 else
11570 vty_out(vty, "True\n");
11571 } else {
11572 if (use_json)
11573 json_object_boolean_false_add(json, "rBit");
11574 else
11575 vty_out(vty, "False\n");
11576 }
11577 }
11578
11579 static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
11580 struct peer *peer,
11581 bool use_json,
11582 json_object *json)
11583 {
11584 const char *mode = "NotApplicable";
11585
11586 if (!use_json)
11587 vty_out(vty, "\n Remote GR Mode: ");
11588
11589 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
11590 && (peer->status == Established)) {
11591
11592 if ((peer->nsf_af_count == 0)
11593 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11594
11595 mode = "Disable";
11596
11597 } else if (peer->nsf_af_count == 0
11598 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11599
11600 mode = "Helper";
11601
11602 } else if (peer->nsf_af_count != 0
11603 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11604
11605 mode = "Restart";
11606 }
11607 }
11608
11609 if (use_json) {
11610 json_object_string_add(json, "remoteGrMode", mode);
11611 } else
11612 vty_out(vty, mode, "\n");
11613 }
11614
11615 static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
11616 struct peer *p,
11617 bool use_json,
11618 json_object *json)
11619 {
11620 const char *mode = "Invalid";
11621
11622 if (!use_json)
11623 vty_out(vty, " Local GR Mode: ");
11624
11625 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
11626 mode = "Helper";
11627 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
11628 mode = "Restart";
11629 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
11630 mode = "Disable";
11631 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
11632 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
11633 mode = "Helper*";
11634 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
11635 mode = "Restart*";
11636 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
11637 mode = "Disable*";
11638 else
11639 mode = "Invalid*";
11640 }
11641
11642 if (use_json) {
11643 json_object_string_add(json, "localGrMode", mode);
11644 } else {
11645 vty_out(vty, mode, "\n");
11646 }
11647 }
11648
11649 static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
11650 struct vty *vty, struct peer *peer, bool use_json, json_object *json)
11651 {
11652 afi_t afi;
11653 safi_t safi;
11654 json_object *json_afi_safi = NULL;
11655 json_object *json_timer = NULL;
11656 json_object *json_endofrib_status = NULL;
11657 bool eor_flag = false;
11658
11659 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
11660 for (safi = SAFI_UNICAST; safi <= SAFI_MPLS_VPN; safi++) {
11661 if (!peer->afc[afi][safi])
11662 continue;
11663
11664 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
11665 || !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
11666 continue;
11667
11668 if (use_json) {
11669 json_afi_safi = json_object_new_object();
11670 json_endofrib_status = json_object_new_object();
11671 json_timer = json_object_new_object();
11672 }
11673
11674 if (peer->eor_stime[afi][safi]
11675 >= peer->pkt_stime[afi][safi])
11676 eor_flag = true;
11677 else
11678 eor_flag = false;
11679
11680 if (!use_json) {
11681 vty_out(vty, " %s:\n",
11682 get_afi_safi_str(afi, safi, false));
11683
11684 vty_out(vty, " F bit: ");
11685 }
11686
11687 if (peer->nsf[afi][safi]
11688 && CHECK_FLAG(peer->af_cap[afi][safi],
11689 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
11690
11691 if (use_json) {
11692 json_object_boolean_true_add(
11693 json_afi_safi, "fBit");
11694 } else
11695 vty_out(vty, "True\n");
11696 } else {
11697 if (use_json)
11698 json_object_boolean_false_add(
11699 json_afi_safi, "fBit");
11700 else
11701 vty_out(vty, "False\n");
11702 }
11703
11704 if (!use_json)
11705 vty_out(vty, " End-of-RIB sent: ");
11706
11707 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11708 PEER_STATUS_EOR_SEND)) {
11709 if (use_json) {
11710 json_object_boolean_true_add(
11711 json_endofrib_status,
11712 "endOfRibSend");
11713
11714 PRINT_EOR_JSON(eor_flag);
11715 } else {
11716 vty_out(vty, "Yes\n");
11717 vty_out(vty,
11718 " End-of-RIB sent after update: ");
11719
11720 PRINT_EOR(eor_flag);
11721 }
11722 } else {
11723 if (use_json) {
11724 json_object_boolean_false_add(
11725 json_endofrib_status,
11726 "endOfRibSend");
11727 json_object_boolean_false_add(
11728 json_endofrib_status,
11729 "endOfRibSentAfterUpdate");
11730 } else {
11731 vty_out(vty, "No\n");
11732 vty_out(vty,
11733 " End-of-RIB sent after update: ");
11734 vty_out(vty, "No\n");
11735 }
11736 }
11737
11738 if (!use_json)
11739 vty_out(vty, " End-of-RIB received: ");
11740
11741 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11742 PEER_STATUS_EOR_RECEIVED)) {
11743 if (use_json)
11744 json_object_boolean_true_add(
11745 json_endofrib_status,
11746 "endOfRibRecv");
11747 else
11748 vty_out(vty, "Yes\n");
11749 } else {
11750 if (use_json)
11751 json_object_boolean_false_add(
11752 json_endofrib_status,
11753 "endOfRibRecv");
11754 else
11755 vty_out(vty, "No\n");
11756 }
11757
11758 if (use_json) {
11759 json_object_int_add(json_timer,
11760 "stalePathTimer",
11761 peer->bgp->stalepath_time);
11762
11763 if (peer->t_gr_stale != NULL) {
11764 json_object_int_add(
11765 json_timer,
11766 "stalePathTimerRemaining",
11767 thread_timer_remain_second(
11768 peer->t_gr_stale));
11769 }
11770
11771 /* Display Configured Selection
11772 * Deferral only when when
11773 * Gr mode is enabled.
11774 */
11775 if (CHECK_FLAG(peer->flags,
11776 PEER_FLAG_GRACEFUL_RESTART)) {
11777 json_object_int_add(
11778 json_timer,
11779 "selectionDeferralTimer",
11780 peer->bgp->stalepath_time);
11781 }
11782
11783 if (peer->bgp->gr_info[afi][safi]
11784 .t_select_deferral
11785 != NULL) {
11786
11787 json_object_int_add(
11788 json_timer,
11789 "selectionDeferralTimerRemaining",
11790 thread_timer_remain_second(
11791 peer->bgp
11792 ->gr_info[afi]
11793 [safi]
11794 .t_select_deferral));
11795 }
11796 } else {
11797 vty_out(vty, " Timers:\n");
11798 vty_out(vty,
11799 " Configured Stale Path Time(sec): %u\n",
11800 peer->bgp->stalepath_time);
11801
11802 if (peer->t_gr_stale != NULL)
11803 vty_out(vty,
11804 " Stale Path Remaining(sec): %ld\n",
11805 thread_timer_remain_second(
11806 peer->t_gr_stale));
11807 /* Display Configured Selection
11808 * Deferral only when when
11809 * Gr mode is enabled.
11810 */
11811 if (CHECK_FLAG(peer->flags,
11812 PEER_FLAG_GRACEFUL_RESTART))
11813 vty_out(vty,
11814 " Configured Selection Deferral Time(sec): %u\n",
11815 peer->bgp->select_defer_time);
11816
11817 if (peer->bgp->gr_info[afi][safi]
11818 .t_select_deferral
11819 != NULL)
11820 vty_out(vty,
11821 " Selection Deferral Time Remaining(sec): %ld\n",
11822 thread_timer_remain_second(
11823 peer->bgp
11824 ->gr_info[afi]
11825 [safi]
11826 .t_select_deferral));
11827 }
11828 if (use_json) {
11829 json_object_object_add(json_afi_safi,
11830 "endOfRibStatus",
11831 json_endofrib_status);
11832 json_object_object_add(json_afi_safi, "timers",
11833 json_timer);
11834 json_object_object_add(
11835 json, get_afi_safi_str(afi, safi, true),
11836 json_afi_safi);
11837 }
11838 }
11839 }
11840 }
11841
11842 static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
11843 struct peer *p,
11844 bool use_json,
11845 json_object *json)
11846 {
11847 if (use_json) {
11848 json_object *json_timer = NULL;
11849
11850 json_timer = json_object_new_object();
11851
11852 json_object_int_add(json_timer, "configuredRestartTimer",
11853 p->bgp->restart_time);
11854
11855 json_object_int_add(json_timer, "receivedRestartTimer",
11856 p->v_gr_restart);
11857
11858 if (p->t_gr_restart != NULL)
11859 json_object_int_add(
11860 json_timer, "restartTimerRemaining",
11861 thread_timer_remain_second(p->t_gr_restart));
11862
11863 json_object_object_add(json, "timers", json_timer);
11864 } else {
11865
11866 vty_out(vty, " Timers:\n");
11867 vty_out(vty, " Configured Restart Time(sec): %u\n",
11868 p->bgp->restart_time);
11869
11870 vty_out(vty, " Received Restart Time(sec): %u\n",
11871 p->v_gr_restart);
11872 if (p->t_gr_restart != NULL)
11873 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
11874 thread_timer_remain_second(p->t_gr_restart));
11875 if (p->t_gr_restart != NULL) {
11876 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
11877 thread_timer_remain_second(p->t_gr_restart));
11878 }
11879 }
11880 }
11881
11882 static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
11883 bool use_json, json_object *json)
11884 {
11885 char buf[SU_ADDRSTRLEN] = {0};
11886 char dn_flag[2] = {0};
11887 /* '*' + v6 address of neighbor */
11888 char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
11889
11890 if (!p->conf_if && peer_dynamic_neighbor(p))
11891 dn_flag[0] = '*';
11892
11893 if (p->conf_if) {
11894 if (use_json)
11895 json_object_string_add(
11896 json, "neighborAddr",
11897 BGP_PEER_SU_UNSPEC(p)
11898 ? "none"
11899 : sockunion2str(&p->su, buf,
11900 SU_ADDRSTRLEN));
11901 else
11902 vty_out(vty, "BGP neighbor on %s: %s\n", p->conf_if,
11903 BGP_PEER_SU_UNSPEC(p)
11904 ? "none"
11905 : sockunion2str(&p->su, buf,
11906 SU_ADDRSTRLEN));
11907 } else {
11908 snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
11909 p->host);
11910
11911 if (use_json)
11912 json_object_string_add(json, "neighborAddr",
11913 neighborAddr);
11914 else
11915 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
11916 }
11917
11918 /* more gr info in new format */
11919 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json);
11920 }
11921
11922 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
11923 safi_t safi, bool use_json,
11924 json_object *json_neigh)
11925 {
11926 struct bgp_filter *filter;
11927 struct peer_af *paf;
11928 char orf_pfx_name[BUFSIZ];
11929 int orf_pfx_count;
11930 json_object *json_af = NULL;
11931 json_object *json_prefA = NULL;
11932 json_object *json_prefB = NULL;
11933 json_object *json_addr = NULL;
11934 json_object *json_advmap = NULL;
11935
11936 if (use_json) {
11937 json_addr = json_object_new_object();
11938 json_af = json_object_new_object();
11939 filter = &p->filter[afi][safi];
11940
11941 if (peer_group_active(p))
11942 json_object_string_add(json_addr, "peerGroupMember",
11943 p->group->name);
11944
11945 paf = peer_af_find(p, afi, safi);
11946 if (paf && PAF_SUBGRP(paf)) {
11947 json_object_int_add(json_addr, "updateGroupId",
11948 PAF_UPDGRP(paf)->id);
11949 json_object_int_add(json_addr, "subGroupId",
11950 PAF_SUBGRP(paf)->id);
11951 json_object_int_add(json_addr, "packetQueueLength",
11952 bpacket_queue_virtual_length(paf));
11953 }
11954
11955 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11956 || CHECK_FLAG(p->af_cap[afi][safi],
11957 PEER_CAP_ORF_PREFIX_SM_RCV)
11958 || CHECK_FLAG(p->af_cap[afi][safi],
11959 PEER_CAP_ORF_PREFIX_RM_ADV)
11960 || CHECK_FLAG(p->af_cap[afi][safi],
11961 PEER_CAP_ORF_PREFIX_RM_RCV)) {
11962 json_object_int_add(json_af, "orfType",
11963 ORF_TYPE_PREFIX);
11964 json_prefA = json_object_new_object();
11965 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
11966 PEER_CAP_ORF_PREFIX_SM_ADV,
11967 PEER_CAP_ORF_PREFIX_RM_ADV,
11968 PEER_CAP_ORF_PREFIX_SM_RCV,
11969 PEER_CAP_ORF_PREFIX_RM_RCV,
11970 use_json, json_prefA);
11971 json_object_object_add(json_af, "orfPrefixList",
11972 json_prefA);
11973 }
11974
11975 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11976 || CHECK_FLAG(p->af_cap[afi][safi],
11977 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11978 || CHECK_FLAG(p->af_cap[afi][safi],
11979 PEER_CAP_ORF_PREFIX_RM_ADV)
11980 || CHECK_FLAG(p->af_cap[afi][safi],
11981 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
11982 json_object_int_add(json_af, "orfOldType",
11983 ORF_TYPE_PREFIX_OLD);
11984 json_prefB = json_object_new_object();
11985 bgp_show_peer_afi_orf_cap(
11986 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
11987 PEER_CAP_ORF_PREFIX_RM_ADV,
11988 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
11989 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
11990 json_prefB);
11991 json_object_object_add(json_af, "orfOldPrefixList",
11992 json_prefB);
11993 }
11994
11995 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11996 || CHECK_FLAG(p->af_cap[afi][safi],
11997 PEER_CAP_ORF_PREFIX_SM_RCV)
11998 || CHECK_FLAG(p->af_cap[afi][safi],
11999 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12000 || CHECK_FLAG(p->af_cap[afi][safi],
12001 PEER_CAP_ORF_PREFIX_RM_ADV)
12002 || CHECK_FLAG(p->af_cap[afi][safi],
12003 PEER_CAP_ORF_PREFIX_RM_RCV)
12004 || CHECK_FLAG(p->af_cap[afi][safi],
12005 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12006 json_object_object_add(json_addr, "afDependentCap",
12007 json_af);
12008 else
12009 json_object_free(json_af);
12010
12011 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12012 p->host, afi, safi);
12013 orf_pfx_count = prefix_bgp_show_prefix_list(
12014 NULL, afi, orf_pfx_name, use_json);
12015
12016 if (CHECK_FLAG(p->af_sflags[afi][safi],
12017 PEER_STATUS_ORF_PREFIX_SEND)
12018 || orf_pfx_count) {
12019 if (CHECK_FLAG(p->af_sflags[afi][safi],
12020 PEER_STATUS_ORF_PREFIX_SEND))
12021 json_object_boolean_true_add(json_neigh,
12022 "orfSent");
12023 if (orf_pfx_count)
12024 json_object_int_add(json_addr, "orfRecvCounter",
12025 orf_pfx_count);
12026 }
12027 if (CHECK_FLAG(p->af_sflags[afi][safi],
12028 PEER_STATUS_ORF_WAIT_REFRESH))
12029 json_object_string_add(
12030 json_addr, "orfFirstUpdate",
12031 "deferredUntilORFOrRouteRefreshRecvd");
12032
12033 if (CHECK_FLAG(p->af_flags[afi][safi],
12034 PEER_FLAG_REFLECTOR_CLIENT))
12035 json_object_boolean_true_add(json_addr,
12036 "routeReflectorClient");
12037 if (CHECK_FLAG(p->af_flags[afi][safi],
12038 PEER_FLAG_RSERVER_CLIENT))
12039 json_object_boolean_true_add(json_addr,
12040 "routeServerClient");
12041 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12042 json_object_boolean_true_add(json_addr,
12043 "inboundSoftConfigPermit");
12044
12045 if (CHECK_FLAG(p->af_flags[afi][safi],
12046 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12047 json_object_boolean_true_add(
12048 json_addr,
12049 "privateAsNumsAllReplacedInUpdatesToNbr");
12050 else if (CHECK_FLAG(p->af_flags[afi][safi],
12051 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12052 json_object_boolean_true_add(
12053 json_addr,
12054 "privateAsNumsReplacedInUpdatesToNbr");
12055 else if (CHECK_FLAG(p->af_flags[afi][safi],
12056 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12057 json_object_boolean_true_add(
12058 json_addr,
12059 "privateAsNumsAllRemovedInUpdatesToNbr");
12060 else if (CHECK_FLAG(p->af_flags[afi][safi],
12061 PEER_FLAG_REMOVE_PRIVATE_AS))
12062 json_object_boolean_true_add(
12063 json_addr,
12064 "privateAsNumsRemovedInUpdatesToNbr");
12065
12066 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12067 json_object_boolean_true_add(
12068 json_addr,
12069 bgp_addpath_names(p->addpath_type[afi][safi])
12070 ->type_json_name);
12071
12072 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12073 json_object_string_add(json_addr,
12074 "overrideASNsInOutboundUpdates",
12075 "ifAspathEqualRemoteAs");
12076
12077 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12078 || CHECK_FLAG(p->af_flags[afi][safi],
12079 PEER_FLAG_FORCE_NEXTHOP_SELF))
12080 json_object_boolean_true_add(json_addr,
12081 "routerAlwaysNextHop");
12082 if (CHECK_FLAG(p->af_flags[afi][safi],
12083 PEER_FLAG_AS_PATH_UNCHANGED))
12084 json_object_boolean_true_add(
12085 json_addr, "unchangedAsPathPropogatedToNbr");
12086 if (CHECK_FLAG(p->af_flags[afi][safi],
12087 PEER_FLAG_NEXTHOP_UNCHANGED))
12088 json_object_boolean_true_add(
12089 json_addr, "unchangedNextHopPropogatedToNbr");
12090 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12091 json_object_boolean_true_add(
12092 json_addr, "unchangedMedPropogatedToNbr");
12093 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12094 || CHECK_FLAG(p->af_flags[afi][safi],
12095 PEER_FLAG_SEND_EXT_COMMUNITY)) {
12096 if (CHECK_FLAG(p->af_flags[afi][safi],
12097 PEER_FLAG_SEND_COMMUNITY)
12098 && CHECK_FLAG(p->af_flags[afi][safi],
12099 PEER_FLAG_SEND_EXT_COMMUNITY))
12100 json_object_string_add(json_addr,
12101 "commAttriSentToNbr",
12102 "extendedAndStandard");
12103 else if (CHECK_FLAG(p->af_flags[afi][safi],
12104 PEER_FLAG_SEND_EXT_COMMUNITY))
12105 json_object_string_add(json_addr,
12106 "commAttriSentToNbr",
12107 "extended");
12108 else
12109 json_object_string_add(json_addr,
12110 "commAttriSentToNbr",
12111 "standard");
12112 }
12113 if (CHECK_FLAG(p->af_flags[afi][safi],
12114 PEER_FLAG_DEFAULT_ORIGINATE)) {
12115 if (p->default_rmap[afi][safi].name)
12116 json_object_string_add(
12117 json_addr, "defaultRouteMap",
12118 p->default_rmap[afi][safi].name);
12119
12120 if (paf && PAF_SUBGRP(paf)
12121 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12122 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12123 json_object_boolean_true_add(json_addr,
12124 "defaultSent");
12125 else
12126 json_object_boolean_true_add(json_addr,
12127 "defaultNotSent");
12128 }
12129
12130 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
12131 if (is_evpn_enabled())
12132 json_object_boolean_true_add(
12133 json_addr, "advertiseAllVnis");
12134 }
12135
12136 if (filter->plist[FILTER_IN].name
12137 || filter->dlist[FILTER_IN].name
12138 || filter->aslist[FILTER_IN].name
12139 || filter->map[RMAP_IN].name)
12140 json_object_boolean_true_add(json_addr,
12141 "inboundPathPolicyConfig");
12142 if (filter->plist[FILTER_OUT].name
12143 || filter->dlist[FILTER_OUT].name
12144 || filter->aslist[FILTER_OUT].name
12145 || filter->map[RMAP_OUT].name || filter->usmap.name)
12146 json_object_boolean_true_add(
12147 json_addr, "outboundPathPolicyConfig");
12148
12149 /* prefix-list */
12150 if (filter->plist[FILTER_IN].name)
12151 json_object_string_add(json_addr,
12152 "incomingUpdatePrefixFilterList",
12153 filter->plist[FILTER_IN].name);
12154 if (filter->plist[FILTER_OUT].name)
12155 json_object_string_add(json_addr,
12156 "outgoingUpdatePrefixFilterList",
12157 filter->plist[FILTER_OUT].name);
12158
12159 /* distribute-list */
12160 if (filter->dlist[FILTER_IN].name)
12161 json_object_string_add(
12162 json_addr, "incomingUpdateNetworkFilterList",
12163 filter->dlist[FILTER_IN].name);
12164 if (filter->dlist[FILTER_OUT].name)
12165 json_object_string_add(
12166 json_addr, "outgoingUpdateNetworkFilterList",
12167 filter->dlist[FILTER_OUT].name);
12168
12169 /* filter-list. */
12170 if (filter->aslist[FILTER_IN].name)
12171 json_object_string_add(json_addr,
12172 "incomingUpdateAsPathFilterList",
12173 filter->aslist[FILTER_IN].name);
12174 if (filter->aslist[FILTER_OUT].name)
12175 json_object_string_add(json_addr,
12176 "outgoingUpdateAsPathFilterList",
12177 filter->aslist[FILTER_OUT].name);
12178
12179 /* route-map. */
12180 if (filter->map[RMAP_IN].name)
12181 json_object_string_add(
12182 json_addr, "routeMapForIncomingAdvertisements",
12183 filter->map[RMAP_IN].name);
12184 if (filter->map[RMAP_OUT].name)
12185 json_object_string_add(
12186 json_addr, "routeMapForOutgoingAdvertisements",
12187 filter->map[RMAP_OUT].name);
12188
12189 /* ebgp-requires-policy (inbound) */
12190 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12191 && !bgp_inbound_policy_exists(p, filter))
12192 json_object_string_add(
12193 json_addr, "inboundEbgpRequiresPolicy",
12194 "Inbound updates discarded due to missing policy");
12195
12196 /* ebgp-requires-policy (outbound) */
12197 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12198 && (!bgp_outbound_policy_exists(p, filter)))
12199 json_object_string_add(
12200 json_addr, "outboundEbgpRequiresPolicy",
12201 "Outbound updates discarded due to missing policy");
12202
12203 /* unsuppress-map */
12204 if (filter->usmap.name)
12205 json_object_string_add(json_addr,
12206 "selectiveUnsuppressRouteMap",
12207 filter->usmap.name);
12208
12209 /* advertise-map */
12210 if (filter->advmap.aname) {
12211 json_advmap = json_object_new_object();
12212 json_object_string_add(json_advmap, "condition",
12213 filter->advmap.condition
12214 ? "EXIST"
12215 : "NON_EXIST");
12216 json_object_string_add(json_advmap, "conditionMap",
12217 filter->advmap.cname);
12218 json_object_string_add(json_advmap, "advertiseMap",
12219 filter->advmap.aname);
12220 json_object_string_add(json_advmap, "advertiseStatus",
12221 filter->advmap.update_type
12222 == ADVERTISE
12223 ? "Advertise"
12224 : "Withdraw");
12225 json_object_object_add(json_addr, "advertiseMap",
12226 json_advmap);
12227 }
12228
12229 /* Receive prefix count */
12230 json_object_int_add(json_addr, "acceptedPrefixCounter",
12231 p->pcount[afi][safi]);
12232 if (paf && PAF_SUBGRP(paf))
12233 json_object_int_add(json_addr, "sentPrefixCounter",
12234 (PAF_SUBGRP(paf))->scount);
12235
12236 /* Maximum prefix */
12237 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
12238 json_object_int_add(json_addr, "prefixOutAllowedMax",
12239 p->pmax_out[afi][safi]);
12240
12241 /* Maximum prefix */
12242 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12243 json_object_int_add(json_addr, "prefixAllowedMax",
12244 p->pmax[afi][safi]);
12245 if (CHECK_FLAG(p->af_flags[afi][safi],
12246 PEER_FLAG_MAX_PREFIX_WARNING))
12247 json_object_boolean_true_add(
12248 json_addr, "prefixAllowedMaxWarning");
12249 json_object_int_add(json_addr,
12250 "prefixAllowedWarningThresh",
12251 p->pmax_threshold[afi][safi]);
12252 if (p->pmax_restart[afi][safi])
12253 json_object_int_add(
12254 json_addr,
12255 "prefixAllowedRestartIntervalMsecs",
12256 p->pmax_restart[afi][safi] * 60000);
12257 }
12258 json_object_object_add(json_neigh,
12259 get_afi_safi_str(afi, safi, true),
12260 json_addr);
12261
12262 } else {
12263 filter = &p->filter[afi][safi];
12264
12265 vty_out(vty, " For address family: %s\n",
12266 get_afi_safi_str(afi, safi, false));
12267
12268 if (peer_group_active(p))
12269 vty_out(vty, " %s peer-group member\n",
12270 p->group->name);
12271
12272 paf = peer_af_find(p, afi, safi);
12273 if (paf && PAF_SUBGRP(paf)) {
12274 vty_out(vty, " Update group %" PRIu64", subgroup %" PRIu64 "\n",
12275 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
12276 vty_out(vty, " Packet Queue length %d\n",
12277 bpacket_queue_virtual_length(paf));
12278 } else {
12279 vty_out(vty, " Not part of any update group\n");
12280 }
12281 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12282 || CHECK_FLAG(p->af_cap[afi][safi],
12283 PEER_CAP_ORF_PREFIX_SM_RCV)
12284 || CHECK_FLAG(p->af_cap[afi][safi],
12285 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12286 || CHECK_FLAG(p->af_cap[afi][safi],
12287 PEER_CAP_ORF_PREFIX_RM_ADV)
12288 || CHECK_FLAG(p->af_cap[afi][safi],
12289 PEER_CAP_ORF_PREFIX_RM_RCV)
12290 || CHECK_FLAG(p->af_cap[afi][safi],
12291 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12292 vty_out(vty, " AF-dependant capabilities:\n");
12293
12294 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12295 || CHECK_FLAG(p->af_cap[afi][safi],
12296 PEER_CAP_ORF_PREFIX_SM_RCV)
12297 || CHECK_FLAG(p->af_cap[afi][safi],
12298 PEER_CAP_ORF_PREFIX_RM_ADV)
12299 || CHECK_FLAG(p->af_cap[afi][safi],
12300 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12301 vty_out(vty,
12302 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12303 ORF_TYPE_PREFIX);
12304 bgp_show_peer_afi_orf_cap(
12305 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12306 PEER_CAP_ORF_PREFIX_RM_ADV,
12307 PEER_CAP_ORF_PREFIX_SM_RCV,
12308 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
12309 }
12310 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12311 || CHECK_FLAG(p->af_cap[afi][safi],
12312 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12313 || CHECK_FLAG(p->af_cap[afi][safi],
12314 PEER_CAP_ORF_PREFIX_RM_ADV)
12315 || CHECK_FLAG(p->af_cap[afi][safi],
12316 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12317 vty_out(vty,
12318 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12319 ORF_TYPE_PREFIX_OLD);
12320 bgp_show_peer_afi_orf_cap(
12321 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12322 PEER_CAP_ORF_PREFIX_RM_ADV,
12323 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12324 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
12325 }
12326
12327 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12328 p->host, afi, safi);
12329 orf_pfx_count = prefix_bgp_show_prefix_list(
12330 NULL, afi, orf_pfx_name, use_json);
12331
12332 if (CHECK_FLAG(p->af_sflags[afi][safi],
12333 PEER_STATUS_ORF_PREFIX_SEND)
12334 || orf_pfx_count) {
12335 vty_out(vty, " Outbound Route Filter (ORF):");
12336 if (CHECK_FLAG(p->af_sflags[afi][safi],
12337 PEER_STATUS_ORF_PREFIX_SEND))
12338 vty_out(vty, " sent;");
12339 if (orf_pfx_count)
12340 vty_out(vty, " received (%d entries)",
12341 orf_pfx_count);
12342 vty_out(vty, "\n");
12343 }
12344 if (CHECK_FLAG(p->af_sflags[afi][safi],
12345 PEER_STATUS_ORF_WAIT_REFRESH))
12346 vty_out(vty,
12347 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
12348
12349 if (CHECK_FLAG(p->af_flags[afi][safi],
12350 PEER_FLAG_REFLECTOR_CLIENT))
12351 vty_out(vty, " Route-Reflector Client\n");
12352 if (CHECK_FLAG(p->af_flags[afi][safi],
12353 PEER_FLAG_RSERVER_CLIENT))
12354 vty_out(vty, " Route-Server Client\n");
12355 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12356 vty_out(vty,
12357 " Inbound soft reconfiguration allowed\n");
12358
12359 if (CHECK_FLAG(p->af_flags[afi][safi],
12360 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12361 vty_out(vty,
12362 " Private AS numbers (all) replaced in updates to this neighbor\n");
12363 else if (CHECK_FLAG(p->af_flags[afi][safi],
12364 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12365 vty_out(vty,
12366 " Private AS numbers replaced in updates to this neighbor\n");
12367 else if (CHECK_FLAG(p->af_flags[afi][safi],
12368 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12369 vty_out(vty,
12370 " Private AS numbers (all) removed in updates to this neighbor\n");
12371 else if (CHECK_FLAG(p->af_flags[afi][safi],
12372 PEER_FLAG_REMOVE_PRIVATE_AS))
12373 vty_out(vty,
12374 " Private AS numbers removed in updates to this neighbor\n");
12375
12376 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12377 vty_out(vty, " %s\n",
12378 bgp_addpath_names(p->addpath_type[afi][safi])
12379 ->human_description);
12380
12381 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12382 vty_out(vty,
12383 " Override ASNs in outbound updates if aspath equals remote-as\n");
12384
12385 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12386 || CHECK_FLAG(p->af_flags[afi][safi],
12387 PEER_FLAG_FORCE_NEXTHOP_SELF))
12388 vty_out(vty, " NEXT_HOP is always this router\n");
12389 if (CHECK_FLAG(p->af_flags[afi][safi],
12390 PEER_FLAG_AS_PATH_UNCHANGED))
12391 vty_out(vty,
12392 " AS_PATH is propagated unchanged to this neighbor\n");
12393 if (CHECK_FLAG(p->af_flags[afi][safi],
12394 PEER_FLAG_NEXTHOP_UNCHANGED))
12395 vty_out(vty,
12396 " NEXT_HOP is propagated unchanged to this neighbor\n");
12397 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12398 vty_out(vty,
12399 " MED is propagated unchanged to this neighbor\n");
12400 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12401 || CHECK_FLAG(p->af_flags[afi][safi],
12402 PEER_FLAG_SEND_EXT_COMMUNITY)
12403 || CHECK_FLAG(p->af_flags[afi][safi],
12404 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
12405 vty_out(vty,
12406 " Community attribute sent to this neighbor");
12407 if (CHECK_FLAG(p->af_flags[afi][safi],
12408 PEER_FLAG_SEND_COMMUNITY)
12409 && CHECK_FLAG(p->af_flags[afi][safi],
12410 PEER_FLAG_SEND_EXT_COMMUNITY)
12411 && CHECK_FLAG(p->af_flags[afi][safi],
12412 PEER_FLAG_SEND_LARGE_COMMUNITY))
12413 vty_out(vty, "(all)\n");
12414 else if (CHECK_FLAG(p->af_flags[afi][safi],
12415 PEER_FLAG_SEND_LARGE_COMMUNITY))
12416 vty_out(vty, "(large)\n");
12417 else if (CHECK_FLAG(p->af_flags[afi][safi],
12418 PEER_FLAG_SEND_EXT_COMMUNITY))
12419 vty_out(vty, "(extended)\n");
12420 else
12421 vty_out(vty, "(standard)\n");
12422 }
12423 if (CHECK_FLAG(p->af_flags[afi][safi],
12424 PEER_FLAG_DEFAULT_ORIGINATE)) {
12425 vty_out(vty, " Default information originate,");
12426
12427 if (p->default_rmap[afi][safi].name)
12428 vty_out(vty, " default route-map %s%s,",
12429 p->default_rmap[afi][safi].map ? "*"
12430 : "",
12431 p->default_rmap[afi][safi].name);
12432 if (paf && PAF_SUBGRP(paf)
12433 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12434 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12435 vty_out(vty, " default sent\n");
12436 else
12437 vty_out(vty, " default not sent\n");
12438 }
12439
12440 /* advertise-vni-all */
12441 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
12442 if (is_evpn_enabled())
12443 vty_out(vty, " advertise-all-vni\n");
12444 }
12445
12446 if (filter->plist[FILTER_IN].name
12447 || filter->dlist[FILTER_IN].name
12448 || filter->aslist[FILTER_IN].name
12449 || filter->map[RMAP_IN].name)
12450 vty_out(vty, " Inbound path policy configured\n");
12451 if (filter->plist[FILTER_OUT].name
12452 || filter->dlist[FILTER_OUT].name
12453 || filter->aslist[FILTER_OUT].name
12454 || filter->map[RMAP_OUT].name || filter->usmap.name)
12455 vty_out(vty, " Outbound path policy configured\n");
12456
12457 /* prefix-list */
12458 if (filter->plist[FILTER_IN].name)
12459 vty_out(vty,
12460 " Incoming update prefix filter list is %s%s\n",
12461 filter->plist[FILTER_IN].plist ? "*" : "",
12462 filter->plist[FILTER_IN].name);
12463 if (filter->plist[FILTER_OUT].name)
12464 vty_out(vty,
12465 " Outgoing update prefix filter list is %s%s\n",
12466 filter->plist[FILTER_OUT].plist ? "*" : "",
12467 filter->plist[FILTER_OUT].name);
12468
12469 /* distribute-list */
12470 if (filter->dlist[FILTER_IN].name)
12471 vty_out(vty,
12472 " Incoming update network filter list is %s%s\n",
12473 filter->dlist[FILTER_IN].alist ? "*" : "",
12474 filter->dlist[FILTER_IN].name);
12475 if (filter->dlist[FILTER_OUT].name)
12476 vty_out(vty,
12477 " Outgoing update network filter list is %s%s\n",
12478 filter->dlist[FILTER_OUT].alist ? "*" : "",
12479 filter->dlist[FILTER_OUT].name);
12480
12481 /* filter-list. */
12482 if (filter->aslist[FILTER_IN].name)
12483 vty_out(vty,
12484 " Incoming update AS path filter list is %s%s\n",
12485 filter->aslist[FILTER_IN].aslist ? "*" : "",
12486 filter->aslist[FILTER_IN].name);
12487 if (filter->aslist[FILTER_OUT].name)
12488 vty_out(vty,
12489 " Outgoing update AS path filter list is %s%s\n",
12490 filter->aslist[FILTER_OUT].aslist ? "*" : "",
12491 filter->aslist[FILTER_OUT].name);
12492
12493 /* route-map. */
12494 if (filter->map[RMAP_IN].name)
12495 vty_out(vty,
12496 " Route map for incoming advertisements is %s%s\n",
12497 filter->map[RMAP_IN].map ? "*" : "",
12498 filter->map[RMAP_IN].name);
12499 if (filter->map[RMAP_OUT].name)
12500 vty_out(vty,
12501 " Route map for outgoing advertisements is %s%s\n",
12502 filter->map[RMAP_OUT].map ? "*" : "",
12503 filter->map[RMAP_OUT].name);
12504
12505 /* ebgp-requires-policy (inbound) */
12506 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12507 && !bgp_inbound_policy_exists(p, filter))
12508 vty_out(vty,
12509 " Inbound updates discarded due to missing policy\n");
12510
12511 /* ebgp-requires-policy (outbound) */
12512 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12513 && !bgp_outbound_policy_exists(p, filter))
12514 vty_out(vty,
12515 " Outbound updates discarded due to missing policy\n");
12516
12517 /* unsuppress-map */
12518 if (filter->usmap.name)
12519 vty_out(vty,
12520 " Route map for selective unsuppress is %s%s\n",
12521 filter->usmap.map ? "*" : "",
12522 filter->usmap.name);
12523
12524 /* advertise-map */
12525 if (filter->advmap.aname && filter->advmap.cname)
12526 vty_out(vty,
12527 " Condition %s, Condition-map %s%s, Advertise-map %s%s, status: %s\n",
12528 filter->advmap.condition ? "EXIST"
12529 : "NON_EXIST",
12530 filter->advmap.cmap ? "*" : "",
12531 filter->advmap.cname,
12532 filter->advmap.amap ? "*" : "",
12533 filter->advmap.aname,
12534 filter->advmap.update_type == ADVERTISE
12535 ? "Advertise"
12536 : "Withdraw");
12537
12538 /* Receive prefix count */
12539 vty_out(vty, " %u accepted prefixes\n",
12540 p->pcount[afi][safi]);
12541
12542 /* maximum-prefix-out */
12543 if (CHECK_FLAG(p->af_flags[afi][safi],
12544 PEER_FLAG_MAX_PREFIX_OUT))
12545 vty_out(vty,
12546 " Maximum allowed prefixes sent %u\n",
12547 p->pmax_out[afi][safi]);
12548
12549 /* Maximum prefix */
12550 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12551 vty_out(vty,
12552 " Maximum prefixes allowed %u%s\n",
12553 p->pmax[afi][safi],
12554 CHECK_FLAG(p->af_flags[afi][safi],
12555 PEER_FLAG_MAX_PREFIX_WARNING)
12556 ? " (warning-only)"
12557 : "");
12558 vty_out(vty, " Threshold for warning message %d%%",
12559 p->pmax_threshold[afi][safi]);
12560 if (p->pmax_restart[afi][safi])
12561 vty_out(vty, ", restart interval %d min",
12562 p->pmax_restart[afi][safi]);
12563 vty_out(vty, "\n");
12564 }
12565
12566 vty_out(vty, "\n");
12567 }
12568 }
12569
12570 static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
12571 json_object *json)
12572 {
12573 struct bgp *bgp;
12574 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
12575 char timebuf[BGP_UPTIME_LEN];
12576 char dn_flag[2];
12577 afi_t afi;
12578 safi_t safi;
12579 uint16_t i;
12580 uint8_t *msg;
12581 json_object *json_neigh = NULL;
12582 time_t epoch_tbuf;
12583
12584 bgp = p->bgp;
12585
12586 if (use_json)
12587 json_neigh = json_object_new_object();
12588
12589 memset(dn_flag, '\0', sizeof(dn_flag));
12590 if (!p->conf_if && peer_dynamic_neighbor(p))
12591 dn_flag[0] = '*';
12592
12593 if (!use_json) {
12594 if (p->conf_if) /* Configured interface name. */
12595 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
12596 BGP_PEER_SU_UNSPEC(p)
12597 ? "None"
12598 : sockunion2str(&p->su, buf,
12599 SU_ADDRSTRLEN));
12600 else /* Configured IP address. */
12601 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
12602 p->host);
12603 }
12604
12605 if (use_json) {
12606 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
12607 json_object_string_add(json_neigh, "bgpNeighborAddr",
12608 "none");
12609 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
12610 json_object_string_add(
12611 json_neigh, "bgpNeighborAddr",
12612 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
12613
12614 json_object_int_add(json_neigh, "remoteAs", p->as);
12615
12616 if (p->change_local_as)
12617 json_object_int_add(json_neigh, "localAs",
12618 p->change_local_as);
12619 else
12620 json_object_int_add(json_neigh, "localAs", p->local_as);
12621
12622 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
12623 json_object_boolean_true_add(json_neigh,
12624 "localAsNoPrepend");
12625
12626 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
12627 json_object_boolean_true_add(json_neigh,
12628 "localAsReplaceAs");
12629 } else {
12630 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
12631 || (p->as_type == AS_INTERNAL))
12632 vty_out(vty, "remote AS %u, ", p->as);
12633 else
12634 vty_out(vty, "remote AS Unspecified, ");
12635 vty_out(vty, "local AS %u%s%s, ",
12636 p->change_local_as ? p->change_local_as : p->local_as,
12637 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
12638 ? " no-prepend"
12639 : "",
12640 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
12641 ? " replace-as"
12642 : "");
12643 }
12644 /* peer type internal or confed-internal */
12645 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
12646 if (use_json) {
12647 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12648 json_object_boolean_true_add(
12649 json_neigh, "nbrConfedInternalLink");
12650 else
12651 json_object_boolean_true_add(json_neigh,
12652 "nbrInternalLink");
12653 } else {
12654 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12655 vty_out(vty, "confed-internal link\n");
12656 else
12657 vty_out(vty, "internal link\n");
12658 }
12659 /* peer type external or confed-external */
12660 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
12661 if (use_json) {
12662 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12663 json_object_boolean_true_add(
12664 json_neigh, "nbrConfedExternalLink");
12665 else
12666 json_object_boolean_true_add(json_neigh,
12667 "nbrExternalLink");
12668 } else {
12669 if (bgp_confederation_peers_check(bgp, p->as))
12670 vty_out(vty, "confed-external link\n");
12671 else
12672 vty_out(vty, "external link\n");
12673 }
12674 } else {
12675 if (use_json)
12676 json_object_boolean_true_add(json_neigh,
12677 "nbrUnspecifiedLink");
12678 else
12679 vty_out(vty, "unspecified link\n");
12680 }
12681
12682 /* Description. */
12683 if (p->desc) {
12684 if (use_json)
12685 json_object_string_add(json_neigh, "nbrDesc", p->desc);
12686 else
12687 vty_out(vty, " Description: %s\n", p->desc);
12688 }
12689
12690 if (p->hostname) {
12691 if (use_json) {
12692 if (p->hostname)
12693 json_object_string_add(json_neigh, "hostname",
12694 p->hostname);
12695
12696 if (p->domainname)
12697 json_object_string_add(json_neigh, "domainname",
12698 p->domainname);
12699 } else {
12700 if (p->domainname && (p->domainname[0] != '\0'))
12701 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
12702 p->domainname);
12703 else
12704 vty_out(vty, "Hostname: %s\n", p->hostname);
12705 }
12706 }
12707
12708 /* Peer-group */
12709 if (p->group) {
12710 if (use_json) {
12711 json_object_string_add(json_neigh, "peerGroup",
12712 p->group->name);
12713
12714 if (dn_flag[0]) {
12715 struct prefix prefix, *range = NULL;
12716
12717 if (sockunion2hostprefix(&(p->su), &prefix))
12718 range = peer_group_lookup_dynamic_neighbor_range(
12719 p->group, &prefix);
12720
12721 if (range) {
12722 prefix2str(range, buf1, sizeof(buf1));
12723 json_object_string_add(
12724 json_neigh,
12725 "peerSubnetRangeGroup", buf1);
12726 }
12727 }
12728 } else {
12729 vty_out(vty,
12730 " Member of peer-group %s for session parameters\n",
12731 p->group->name);
12732
12733 if (dn_flag[0]) {
12734 struct prefix prefix, *range = NULL;
12735
12736 if (sockunion2hostprefix(&(p->su), &prefix))
12737 range = peer_group_lookup_dynamic_neighbor_range(
12738 p->group, &prefix);
12739
12740 if (range) {
12741 vty_out(vty,
12742 " Belongs to the subnet range group: %pFX\n",
12743 range);
12744 }
12745 }
12746 }
12747 }
12748
12749 if (use_json) {
12750 /* Administrative shutdown. */
12751 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12752 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
12753 json_object_boolean_true_add(json_neigh,
12754 "adminShutDown");
12755
12756 /* BGP Version. */
12757 json_object_int_add(json_neigh, "bgpVersion", 4);
12758 json_object_string_add(
12759 json_neigh, "remoteRouterId",
12760 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
12761 json_object_string_add(
12762 json_neigh, "localRouterId",
12763 inet_ntop(AF_INET, &bgp->router_id, buf1,
12764 sizeof(buf1)));
12765
12766 /* Confederation */
12767 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12768 && bgp_confederation_peers_check(bgp, p->as))
12769 json_object_boolean_true_add(json_neigh,
12770 "nbrCommonAdmin");
12771
12772 /* Status. */
12773 json_object_string_add(
12774 json_neigh, "bgpState",
12775 lookup_msg(bgp_status_msg, p->status, NULL));
12776
12777 if (p->status == Established) {
12778 time_t uptime;
12779
12780 uptime = bgp_clock();
12781 uptime -= p->uptime;
12782 epoch_tbuf = time(NULL) - uptime;
12783
12784 json_object_int_add(json_neigh, "bgpTimerUpMsec",
12785 uptime * 1000);
12786 json_object_string_add(json_neigh, "bgpTimerUpString",
12787 peer_uptime(p->uptime, timebuf,
12788 BGP_UPTIME_LEN, 0,
12789 NULL));
12790 json_object_int_add(json_neigh,
12791 "bgpTimerUpEstablishedEpoch",
12792 epoch_tbuf);
12793 }
12794
12795 else if (p->status == Active) {
12796 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12797 json_object_string_add(json_neigh, "bgpStateIs",
12798 "passive");
12799 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12800 json_object_string_add(json_neigh, "bgpStateIs",
12801 "passiveNSF");
12802 }
12803
12804 /* read timer */
12805 time_t uptime;
12806 struct tm tm;
12807
12808 uptime = bgp_clock();
12809 uptime -= p->readtime;
12810 gmtime_r(&uptime, &tm);
12811
12812 json_object_int_add(json_neigh, "bgpTimerLastRead",
12813 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12814 + (tm.tm_hour * 3600000));
12815
12816 uptime = bgp_clock();
12817 uptime -= p->last_write;
12818 gmtime_r(&uptime, &tm);
12819
12820 json_object_int_add(json_neigh, "bgpTimerLastWrite",
12821 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12822 + (tm.tm_hour * 3600000));
12823
12824 uptime = bgp_clock();
12825 uptime -= p->update_time;
12826 gmtime_r(&uptime, &tm);
12827
12828 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
12829 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12830 + (tm.tm_hour * 3600000));
12831
12832 /* Configured timer values. */
12833 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
12834 p->v_holdtime * 1000);
12835 json_object_int_add(json_neigh,
12836 "bgpTimerKeepAliveIntervalMsecs",
12837 p->v_keepalive * 1000);
12838 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN)) {
12839 json_object_int_add(json_neigh,
12840 "bgpTimerDelayOpenTimeMsecs",
12841 p->v_delayopen * 1000);
12842 }
12843
12844 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
12845 json_object_int_add(json_neigh,
12846 "bgpTimerConfiguredHoldTimeMsecs",
12847 p->holdtime * 1000);
12848 json_object_int_add(
12849 json_neigh,
12850 "bgpTimerConfiguredKeepAliveIntervalMsecs",
12851 p->keepalive * 1000);
12852 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
12853 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
12854 json_object_int_add(json_neigh,
12855 "bgpTimerConfiguredHoldTimeMsecs",
12856 bgp->default_holdtime);
12857 json_object_int_add(
12858 json_neigh,
12859 "bgpTimerConfiguredKeepAliveIntervalMsecs",
12860 bgp->default_keepalive);
12861 }
12862 } else {
12863 /* Administrative shutdown. */
12864 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12865 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
12866 vty_out(vty, " Administratively shut down\n");
12867
12868 /* BGP Version. */
12869 vty_out(vty, " BGP version 4");
12870 vty_out(vty, ", remote router ID %s",
12871 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
12872 vty_out(vty, ", local router ID %s\n",
12873 inet_ntop(AF_INET, &bgp->router_id, buf1,
12874 sizeof(buf1)));
12875
12876 /* Confederation */
12877 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12878 && bgp_confederation_peers_check(bgp, p->as))
12879 vty_out(vty,
12880 " Neighbor under common administration\n");
12881
12882 /* Status. */
12883 vty_out(vty, " BGP state = %s",
12884 lookup_msg(bgp_status_msg, p->status, NULL));
12885
12886 if (p->status == Established)
12887 vty_out(vty, ", up for %8s",
12888 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
12889 0, NULL));
12890
12891 else if (p->status == Active) {
12892 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12893 vty_out(vty, " (passive)");
12894 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12895 vty_out(vty, " (NSF passive)");
12896 }
12897 vty_out(vty, "\n");
12898
12899 /* read timer */
12900 vty_out(vty, " Last read %s",
12901 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
12902 NULL));
12903 vty_out(vty, ", Last write %s\n",
12904 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
12905 NULL));
12906
12907 /* Configured timer values. */
12908 vty_out(vty,
12909 " Hold time is %d, keepalive interval is %d seconds\n",
12910 p->v_holdtime, p->v_keepalive);
12911 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
12912 vty_out(vty, " Configured hold time is %d",
12913 p->holdtime);
12914 vty_out(vty, ", keepalive interval is %d seconds\n",
12915 p->keepalive);
12916 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
12917 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
12918 vty_out(vty, " Configured hold time is %d",
12919 bgp->default_holdtime);
12920 vty_out(vty, ", keepalive interval is %d seconds\n",
12921 bgp->default_keepalive);
12922 }
12923 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN))
12924 vty_out(vty,
12925 " Configured DelayOpenTime is %d seconds\n",
12926 p->delayopen);
12927 }
12928 /* Capability. */
12929 if (p->status == Established) {
12930 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
12931 || p->afc_recv[AFI_IP][SAFI_UNICAST]
12932 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
12933 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
12934 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
12935 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
12936 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
12937 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
12938 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
12939 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
12940 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
12941 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
12942 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
12943 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
12944 || p->afc_adv[AFI_IP][SAFI_ENCAP]
12945 || p->afc_recv[AFI_IP][SAFI_ENCAP]
12946 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
12947 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
12948 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
12949 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
12950 if (use_json) {
12951 json_object *json_cap = NULL;
12952
12953 json_cap = json_object_new_object();
12954
12955 /* AS4 */
12956 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
12957 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
12958 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
12959 && CHECK_FLAG(p->cap,
12960 PEER_CAP_AS4_RCV))
12961 json_object_string_add(
12962 json_cap, "4byteAs",
12963 "advertisedAndReceived");
12964 else if (CHECK_FLAG(p->cap,
12965 PEER_CAP_AS4_ADV))
12966 json_object_string_add(
12967 json_cap, "4byteAs",
12968 "advertised");
12969 else if (CHECK_FLAG(p->cap,
12970 PEER_CAP_AS4_RCV))
12971 json_object_string_add(
12972 json_cap, "4byteAs",
12973 "received");
12974 }
12975
12976 /* AddPath */
12977 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
12978 || CHECK_FLAG(p->cap,
12979 PEER_CAP_ADDPATH_ADV)) {
12980 json_object *json_add = NULL;
12981 const char *print_store;
12982
12983 json_add = json_object_new_object();
12984
12985 FOREACH_AFI_SAFI (afi, safi) {
12986 json_object *json_sub = NULL;
12987 json_sub =
12988 json_object_new_object();
12989 print_store = get_afi_safi_str(
12990 afi, safi, true);
12991
12992 if (CHECK_FLAG(
12993 p->af_cap[afi]
12994 [safi],
12995 PEER_CAP_ADDPATH_AF_TX_ADV)
12996 || CHECK_FLAG(
12997 p->af_cap[afi]
12998 [safi],
12999 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13000 if (CHECK_FLAG(
13001 p->af_cap
13002 [afi]
13003 [safi],
13004 PEER_CAP_ADDPATH_AF_TX_ADV)
13005 && CHECK_FLAG(
13006 p->af_cap
13007 [afi]
13008 [safi],
13009 PEER_CAP_ADDPATH_AF_TX_RCV))
13010 json_object_boolean_true_add(
13011 json_sub,
13012 "txAdvertisedAndReceived");
13013 else if (
13014 CHECK_FLAG(
13015 p->af_cap
13016 [afi]
13017 [safi],
13018 PEER_CAP_ADDPATH_AF_TX_ADV))
13019 json_object_boolean_true_add(
13020 json_sub,
13021 "txAdvertised");
13022 else if (
13023 CHECK_FLAG(
13024 p->af_cap
13025 [afi]
13026 [safi],
13027 PEER_CAP_ADDPATH_AF_TX_RCV))
13028 json_object_boolean_true_add(
13029 json_sub,
13030 "txReceived");
13031 }
13032
13033 if (CHECK_FLAG(
13034 p->af_cap[afi]
13035 [safi],
13036 PEER_CAP_ADDPATH_AF_RX_ADV)
13037 || CHECK_FLAG(
13038 p->af_cap[afi]
13039 [safi],
13040 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13041 if (CHECK_FLAG(
13042 p->af_cap
13043 [afi]
13044 [safi],
13045 PEER_CAP_ADDPATH_AF_RX_ADV)
13046 && CHECK_FLAG(
13047 p->af_cap
13048 [afi]
13049 [safi],
13050 PEER_CAP_ADDPATH_AF_RX_RCV))
13051 json_object_boolean_true_add(
13052 json_sub,
13053 "rxAdvertisedAndReceived");
13054 else if (
13055 CHECK_FLAG(
13056 p->af_cap
13057 [afi]
13058 [safi],
13059 PEER_CAP_ADDPATH_AF_RX_ADV))
13060 json_object_boolean_true_add(
13061 json_sub,
13062 "rxAdvertised");
13063 else if (
13064 CHECK_FLAG(
13065 p->af_cap
13066 [afi]
13067 [safi],
13068 PEER_CAP_ADDPATH_AF_RX_RCV))
13069 json_object_boolean_true_add(
13070 json_sub,
13071 "rxReceived");
13072 }
13073
13074 if (CHECK_FLAG(
13075 p->af_cap[afi]
13076 [safi],
13077 PEER_CAP_ADDPATH_AF_TX_ADV)
13078 || CHECK_FLAG(
13079 p->af_cap[afi]
13080 [safi],
13081 PEER_CAP_ADDPATH_AF_TX_RCV)
13082 || CHECK_FLAG(
13083 p->af_cap[afi]
13084 [safi],
13085 PEER_CAP_ADDPATH_AF_RX_ADV)
13086 || CHECK_FLAG(
13087 p->af_cap[afi]
13088 [safi],
13089 PEER_CAP_ADDPATH_AF_RX_RCV))
13090 json_object_object_add(
13091 json_add,
13092 print_store,
13093 json_sub);
13094 else
13095 json_object_free(
13096 json_sub);
13097 }
13098
13099 json_object_object_add(
13100 json_cap, "addPath", json_add);
13101 }
13102
13103 /* Dynamic */
13104 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
13105 || CHECK_FLAG(p->cap,
13106 PEER_CAP_DYNAMIC_ADV)) {
13107 if (CHECK_FLAG(p->cap,
13108 PEER_CAP_DYNAMIC_ADV)
13109 && CHECK_FLAG(p->cap,
13110 PEER_CAP_DYNAMIC_RCV))
13111 json_object_string_add(
13112 json_cap, "dynamic",
13113 "advertisedAndReceived");
13114 else if (CHECK_FLAG(
13115 p->cap,
13116 PEER_CAP_DYNAMIC_ADV))
13117 json_object_string_add(
13118 json_cap, "dynamic",
13119 "advertised");
13120 else if (CHECK_FLAG(
13121 p->cap,
13122 PEER_CAP_DYNAMIC_RCV))
13123 json_object_string_add(
13124 json_cap, "dynamic",
13125 "received");
13126 }
13127
13128 /* Extended nexthop */
13129 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
13130 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13131 json_object *json_nxt = NULL;
13132 const char *print_store;
13133
13134
13135 if (CHECK_FLAG(p->cap,
13136 PEER_CAP_ENHE_ADV)
13137 && CHECK_FLAG(p->cap,
13138 PEER_CAP_ENHE_RCV))
13139 json_object_string_add(
13140 json_cap,
13141 "extendedNexthop",
13142 "advertisedAndReceived");
13143 else if (CHECK_FLAG(p->cap,
13144 PEER_CAP_ENHE_ADV))
13145 json_object_string_add(
13146 json_cap,
13147 "extendedNexthop",
13148 "advertised");
13149 else if (CHECK_FLAG(p->cap,
13150 PEER_CAP_ENHE_RCV))
13151 json_object_string_add(
13152 json_cap,
13153 "extendedNexthop",
13154 "received");
13155
13156 if (CHECK_FLAG(p->cap,
13157 PEER_CAP_ENHE_RCV)) {
13158 json_nxt =
13159 json_object_new_object();
13160
13161 for (safi = SAFI_UNICAST;
13162 safi < SAFI_MAX; safi++) {
13163 if (CHECK_FLAG(
13164 p->af_cap
13165 [AFI_IP]
13166 [safi],
13167 PEER_CAP_ENHE_AF_RCV)) {
13168 print_store = get_afi_safi_str(
13169 AFI_IP,
13170 safi, true);
13171 json_object_string_add(
13172 json_nxt,
13173 print_store,
13174 "recieved"); /* misspelled for compatibility */
13175 }
13176 }
13177 json_object_object_add(
13178 json_cap,
13179 "extendedNexthopFamililesByPeer",
13180 json_nxt);
13181 }
13182 }
13183
13184 /* Route Refresh */
13185 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
13186 || CHECK_FLAG(p->cap,
13187 PEER_CAP_REFRESH_NEW_RCV)
13188 || CHECK_FLAG(p->cap,
13189 PEER_CAP_REFRESH_OLD_RCV)) {
13190 if (CHECK_FLAG(p->cap,
13191 PEER_CAP_REFRESH_ADV)
13192 && (CHECK_FLAG(
13193 p->cap,
13194 PEER_CAP_REFRESH_NEW_RCV)
13195 || CHECK_FLAG(
13196 p->cap,
13197 PEER_CAP_REFRESH_OLD_RCV))) {
13198 if (CHECK_FLAG(
13199 p->cap,
13200 PEER_CAP_REFRESH_OLD_RCV)
13201 && CHECK_FLAG(
13202 p->cap,
13203 PEER_CAP_REFRESH_NEW_RCV))
13204 json_object_string_add(
13205 json_cap,
13206 "routeRefresh",
13207 "advertisedAndReceivedOldNew");
13208 else {
13209 if (CHECK_FLAG(
13210 p->cap,
13211 PEER_CAP_REFRESH_OLD_RCV))
13212 json_object_string_add(
13213 json_cap,
13214 "routeRefresh",
13215 "advertisedAndReceivedOld");
13216 else
13217 json_object_string_add(
13218 json_cap,
13219 "routeRefresh",
13220 "advertisedAndReceivedNew");
13221 }
13222 } else if (
13223 CHECK_FLAG(
13224 p->cap,
13225 PEER_CAP_REFRESH_ADV))
13226 json_object_string_add(
13227 json_cap,
13228 "routeRefresh",
13229 "advertised");
13230 else if (
13231 CHECK_FLAG(
13232 p->cap,
13233 PEER_CAP_REFRESH_NEW_RCV)
13234 || CHECK_FLAG(
13235 p->cap,
13236 PEER_CAP_REFRESH_OLD_RCV))
13237 json_object_string_add(
13238 json_cap,
13239 "routeRefresh",
13240 "received");
13241 }
13242
13243 /* Enhanced Route Refresh */
13244 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV)
13245 || CHECK_FLAG(p->cap,
13246 PEER_CAP_ENHANCED_RR_RCV)) {
13247 if (CHECK_FLAG(p->cap,
13248 PEER_CAP_ENHANCED_RR_ADV)
13249 && CHECK_FLAG(
13250 p->cap,
13251 PEER_CAP_ENHANCED_RR_RCV))
13252 json_object_string_add(
13253 json_cap,
13254 "enhancedRouteRefresh",
13255 "advertisedAndReceived");
13256 else if (
13257 CHECK_FLAG(
13258 p->cap,
13259 PEER_CAP_ENHANCED_RR_ADV))
13260 json_object_string_add(
13261 json_cap,
13262 "enhancedRouteRefresh",
13263 "advertised");
13264 else if (
13265 CHECK_FLAG(
13266 p->cap,
13267 PEER_CAP_ENHANCED_RR_RCV))
13268 json_object_string_add(
13269 json_cap,
13270 "enhancedRouteRefresh",
13271 "received");
13272 }
13273
13274 /* Multiprotocol Extensions */
13275 json_object *json_multi = NULL;
13276 json_multi = json_object_new_object();
13277
13278 FOREACH_AFI_SAFI (afi, safi) {
13279 if (p->afc_adv[afi][safi]
13280 || p->afc_recv[afi][safi]) {
13281 json_object *json_exten = NULL;
13282 json_exten =
13283 json_object_new_object();
13284
13285 if (p->afc_adv[afi][safi]
13286 && p->afc_recv[afi][safi])
13287 json_object_boolean_true_add(
13288 json_exten,
13289 "advertisedAndReceived");
13290 else if (p->afc_adv[afi][safi])
13291 json_object_boolean_true_add(
13292 json_exten,
13293 "advertised");
13294 else if (p->afc_recv[afi][safi])
13295 json_object_boolean_true_add(
13296 json_exten,
13297 "received");
13298
13299 json_object_object_add(
13300 json_multi,
13301 get_afi_safi_str(afi,
13302 safi,
13303 true),
13304 json_exten);
13305 }
13306 }
13307 json_object_object_add(
13308 json_cap, "multiprotocolExtensions",
13309 json_multi);
13310
13311 /* Hostname capabilities */
13312 json_object *json_hname = NULL;
13313
13314 json_hname = json_object_new_object();
13315
13316 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13317 json_object_string_add(
13318 json_hname, "advHostName",
13319 bgp->peer_self->hostname
13320 ? bgp->peer_self
13321 ->hostname
13322 : "n/a");
13323 json_object_string_add(
13324 json_hname, "advDomainName",
13325 bgp->peer_self->domainname
13326 ? bgp->peer_self
13327 ->domainname
13328 : "n/a");
13329 }
13330
13331
13332 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13333 json_object_string_add(
13334 json_hname, "rcvHostName",
13335 p->hostname ? p->hostname
13336 : "n/a");
13337 json_object_string_add(
13338 json_hname, "rcvDomainName",
13339 p->domainname ? p->domainname
13340 : "n/a");
13341 }
13342
13343 json_object_object_add(json_cap, "hostName",
13344 json_hname);
13345
13346 /* Gracefull Restart */
13347 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
13348 || CHECK_FLAG(p->cap,
13349 PEER_CAP_RESTART_ADV)) {
13350 if (CHECK_FLAG(p->cap,
13351 PEER_CAP_RESTART_ADV)
13352 && CHECK_FLAG(p->cap,
13353 PEER_CAP_RESTART_RCV))
13354 json_object_string_add(
13355 json_cap,
13356 "gracefulRestart",
13357 "advertisedAndReceived");
13358 else if (CHECK_FLAG(
13359 p->cap,
13360 PEER_CAP_RESTART_ADV))
13361 json_object_string_add(
13362 json_cap,
13363 "gracefulRestartCapability",
13364 "advertised");
13365 else if (CHECK_FLAG(
13366 p->cap,
13367 PEER_CAP_RESTART_RCV))
13368 json_object_string_add(
13369 json_cap,
13370 "gracefulRestartCapability",
13371 "received");
13372
13373 if (CHECK_FLAG(p->cap,
13374 PEER_CAP_RESTART_RCV)) {
13375 int restart_af_count = 0;
13376 json_object *json_restart =
13377 NULL;
13378 json_restart =
13379 json_object_new_object();
13380
13381 json_object_int_add(
13382 json_cap,
13383 "gracefulRestartRemoteTimerMsecs",
13384 p->v_gr_restart * 1000);
13385
13386 FOREACH_AFI_SAFI (afi, safi) {
13387 if (CHECK_FLAG(
13388 p->af_cap
13389 [afi]
13390 [safi],
13391 PEER_CAP_RESTART_AF_RCV)) {
13392 json_object *
13393 json_sub =
13394 NULL;
13395 json_sub =
13396 json_object_new_object();
13397
13398 if (CHECK_FLAG(
13399 p->af_cap
13400 [afi]
13401 [safi],
13402 PEER_CAP_RESTART_AF_PRESERVE_RCV))
13403 json_object_boolean_true_add(
13404 json_sub,
13405 "preserved");
13406 restart_af_count++;
13407 json_object_object_add(
13408 json_restart,
13409 get_afi_safi_str(
13410 afi,
13411 safi,
13412 true),
13413 json_sub);
13414 }
13415 }
13416 if (!restart_af_count) {
13417 json_object_string_add(
13418 json_cap,
13419 "addressFamiliesByPeer",
13420 "none");
13421 json_object_free(
13422 json_restart);
13423 } else
13424 json_object_object_add(
13425 json_cap,
13426 "addressFamiliesByPeer",
13427 json_restart);
13428 }
13429 }
13430 json_object_object_add(json_neigh,
13431 "neighborCapabilities",
13432 json_cap);
13433 } else {
13434 vty_out(vty, " Neighbor capabilities:\n");
13435
13436 /* AS4 */
13437 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
13438 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13439 vty_out(vty, " 4 Byte AS:");
13440 if (CHECK_FLAG(p->cap,
13441 PEER_CAP_AS4_ADV))
13442 vty_out(vty, " advertised");
13443 if (CHECK_FLAG(p->cap,
13444 PEER_CAP_AS4_RCV))
13445 vty_out(vty, " %sreceived",
13446 CHECK_FLAG(
13447 p->cap,
13448 PEER_CAP_AS4_ADV)
13449 ? "and "
13450 : "");
13451 vty_out(vty, "\n");
13452 }
13453
13454 /* AddPath */
13455 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
13456 || CHECK_FLAG(p->cap,
13457 PEER_CAP_ADDPATH_ADV)) {
13458 vty_out(vty, " AddPath:\n");
13459
13460 FOREACH_AFI_SAFI (afi, safi) {
13461 if (CHECK_FLAG(
13462 p->af_cap[afi]
13463 [safi],
13464 PEER_CAP_ADDPATH_AF_TX_ADV)
13465 || CHECK_FLAG(
13466 p->af_cap[afi]
13467 [safi],
13468 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13469 vty_out(vty,
13470 " %s: TX ",
13471 get_afi_safi_str(
13472 afi,
13473 safi,
13474 false));
13475
13476 if (CHECK_FLAG(
13477 p->af_cap
13478 [afi]
13479 [safi],
13480 PEER_CAP_ADDPATH_AF_TX_ADV))
13481 vty_out(vty,
13482 "advertised %s",
13483 get_afi_safi_str(
13484 afi,
13485 safi,
13486 false));
13487
13488 if (CHECK_FLAG(
13489 p->af_cap
13490 [afi]
13491 [safi],
13492 PEER_CAP_ADDPATH_AF_TX_RCV))
13493 vty_out(vty,
13494 "%sreceived",
13495 CHECK_FLAG(
13496 p->af_cap
13497 [afi]
13498 [safi],
13499 PEER_CAP_ADDPATH_AF_TX_ADV)
13500 ? " and "
13501 : "");
13502
13503 vty_out(vty, "\n");
13504 }
13505
13506 if (CHECK_FLAG(
13507 p->af_cap[afi]
13508 [safi],
13509 PEER_CAP_ADDPATH_AF_RX_ADV)
13510 || CHECK_FLAG(
13511 p->af_cap[afi]
13512 [safi],
13513 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13514 vty_out(vty,
13515 " %s: RX ",
13516 get_afi_safi_str(
13517 afi,
13518 safi,
13519 false));
13520
13521 if (CHECK_FLAG(
13522 p->af_cap
13523 [afi]
13524 [safi],
13525 PEER_CAP_ADDPATH_AF_RX_ADV))
13526 vty_out(vty,
13527 "advertised %s",
13528 get_afi_safi_str(
13529 afi,
13530 safi,
13531 false));
13532
13533 if (CHECK_FLAG(
13534 p->af_cap
13535 [afi]
13536 [safi],
13537 PEER_CAP_ADDPATH_AF_RX_RCV))
13538 vty_out(vty,
13539 "%sreceived",
13540 CHECK_FLAG(
13541 p->af_cap
13542 [afi]
13543 [safi],
13544 PEER_CAP_ADDPATH_AF_RX_ADV)
13545 ? " and "
13546 : "");
13547
13548 vty_out(vty, "\n");
13549 }
13550 }
13551 }
13552
13553 /* Dynamic */
13554 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
13555 || CHECK_FLAG(p->cap,
13556 PEER_CAP_DYNAMIC_ADV)) {
13557 vty_out(vty, " Dynamic:");
13558 if (CHECK_FLAG(p->cap,
13559 PEER_CAP_DYNAMIC_ADV))
13560 vty_out(vty, " advertised");
13561 if (CHECK_FLAG(p->cap,
13562 PEER_CAP_DYNAMIC_RCV))
13563 vty_out(vty, " %sreceived",
13564 CHECK_FLAG(
13565 p->cap,
13566 PEER_CAP_DYNAMIC_ADV)
13567 ? "and "
13568 : "");
13569 vty_out(vty, "\n");
13570 }
13571
13572 /* Extended nexthop */
13573 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
13574 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13575 vty_out(vty, " Extended nexthop:");
13576 if (CHECK_FLAG(p->cap,
13577 PEER_CAP_ENHE_ADV))
13578 vty_out(vty, " advertised");
13579 if (CHECK_FLAG(p->cap,
13580 PEER_CAP_ENHE_RCV))
13581 vty_out(vty, " %sreceived",
13582 CHECK_FLAG(
13583 p->cap,
13584 PEER_CAP_ENHE_ADV)
13585 ? "and "
13586 : "");
13587 vty_out(vty, "\n");
13588
13589 if (CHECK_FLAG(p->cap,
13590 PEER_CAP_ENHE_RCV)) {
13591 vty_out(vty,
13592 " Address families by peer:\n ");
13593 for (safi = SAFI_UNICAST;
13594 safi < SAFI_MAX; safi++)
13595 if (CHECK_FLAG(
13596 p->af_cap
13597 [AFI_IP]
13598 [safi],
13599 PEER_CAP_ENHE_AF_RCV))
13600 vty_out(vty,
13601 " %s\n",
13602 get_afi_safi_str(
13603 AFI_IP,
13604 safi,
13605 false));
13606 }
13607 }
13608
13609 /* Route Refresh */
13610 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
13611 || CHECK_FLAG(p->cap,
13612 PEER_CAP_REFRESH_NEW_RCV)
13613 || CHECK_FLAG(p->cap,
13614 PEER_CAP_REFRESH_OLD_RCV)) {
13615 vty_out(vty, " Route refresh:");
13616 if (CHECK_FLAG(p->cap,
13617 PEER_CAP_REFRESH_ADV))
13618 vty_out(vty, " advertised");
13619 if (CHECK_FLAG(p->cap,
13620 PEER_CAP_REFRESH_NEW_RCV)
13621 || CHECK_FLAG(
13622 p->cap,
13623 PEER_CAP_REFRESH_OLD_RCV))
13624 vty_out(vty, " %sreceived(%s)",
13625 CHECK_FLAG(
13626 p->cap,
13627 PEER_CAP_REFRESH_ADV)
13628 ? "and "
13629 : "",
13630 (CHECK_FLAG(
13631 p->cap,
13632 PEER_CAP_REFRESH_OLD_RCV)
13633 && CHECK_FLAG(
13634 p->cap,
13635 PEER_CAP_REFRESH_NEW_RCV))
13636 ? "old & new"
13637 : CHECK_FLAG(
13638 p->cap,
13639 PEER_CAP_REFRESH_OLD_RCV)
13640 ? "old"
13641 : "new");
13642
13643 vty_out(vty, "\n");
13644 }
13645
13646 /* Enhanced Route Refresh */
13647 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV)
13648 || CHECK_FLAG(p->cap,
13649 PEER_CAP_ENHANCED_RR_RCV)) {
13650 vty_out(vty,
13651 " Enhanced Route Refresh:");
13652 if (CHECK_FLAG(
13653 p->cap,
13654 PEER_CAP_ENHANCED_RR_ADV))
13655 vty_out(vty, " advertised");
13656 if (CHECK_FLAG(
13657 p->cap,
13658 PEER_CAP_ENHANCED_RR_RCV))
13659 vty_out(vty, " %sreceived",
13660 CHECK_FLAG(
13661 p->cap,
13662 PEER_CAP_REFRESH_ADV)
13663 ? "and "
13664 : "");
13665 vty_out(vty, "\n");
13666 }
13667
13668 /* Multiprotocol Extensions */
13669 FOREACH_AFI_SAFI (afi, safi)
13670 if (p->afc_adv[afi][safi]
13671 || p->afc_recv[afi][safi]) {
13672 vty_out(vty,
13673 " Address Family %s:",
13674 get_afi_safi_str(
13675 afi,
13676 safi,
13677 false));
13678 if (p->afc_adv[afi][safi])
13679 vty_out(vty,
13680 " advertised");
13681 if (p->afc_recv[afi][safi])
13682 vty_out(vty,
13683 " %sreceived",
13684 p->afc_adv[afi]
13685 [safi]
13686 ? "and "
13687 : "");
13688 vty_out(vty, "\n");
13689 }
13690
13691 /* Hostname capability */
13692 vty_out(vty, " Hostname Capability:");
13693
13694 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13695 vty_out(vty,
13696 " advertised (name: %s,domain name: %s)",
13697 bgp->peer_self->hostname
13698 ? bgp->peer_self
13699 ->hostname
13700 : "n/a",
13701 bgp->peer_self->domainname
13702 ? bgp->peer_self
13703 ->domainname
13704 : "n/a");
13705 } else {
13706 vty_out(vty, " not advertised");
13707 }
13708
13709 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13710 vty_out(vty,
13711 " received (name: %s,domain name: %s)",
13712 p->hostname ? p->hostname
13713 : "n/a",
13714 p->domainname ? p->domainname
13715 : "n/a");
13716 } else {
13717 vty_out(vty, " not received");
13718 }
13719
13720 vty_out(vty, "\n");
13721
13722 /* Graceful Restart */
13723 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
13724 || CHECK_FLAG(p->cap,
13725 PEER_CAP_RESTART_ADV)) {
13726 vty_out(vty,
13727 " Graceful Restart Capability:");
13728 if (CHECK_FLAG(p->cap,
13729 PEER_CAP_RESTART_ADV))
13730 vty_out(vty, " advertised");
13731 if (CHECK_FLAG(p->cap,
13732 PEER_CAP_RESTART_RCV))
13733 vty_out(vty, " %sreceived",
13734 CHECK_FLAG(
13735 p->cap,
13736 PEER_CAP_RESTART_ADV)
13737 ? "and "
13738 : "");
13739 vty_out(vty, "\n");
13740
13741 if (CHECK_FLAG(p->cap,
13742 PEER_CAP_RESTART_RCV)) {
13743 int restart_af_count = 0;
13744
13745 vty_out(vty,
13746 " Remote Restart timer is %d seconds\n",
13747 p->v_gr_restart);
13748 vty_out(vty,
13749 " Address families by peer:\n ");
13750
13751 FOREACH_AFI_SAFI (afi, safi)
13752 if (CHECK_FLAG(
13753 p->af_cap
13754 [afi]
13755 [safi],
13756 PEER_CAP_RESTART_AF_RCV)) {
13757 vty_out(vty,
13758 "%s%s(%s)",
13759 restart_af_count
13760 ? ", "
13761 : "",
13762 get_afi_safi_str(
13763 afi,
13764 safi,
13765 false),
13766 CHECK_FLAG(
13767 p->af_cap
13768 [afi]
13769 [safi],
13770 PEER_CAP_RESTART_AF_PRESERVE_RCV)
13771 ? "preserved"
13772 : "not preserved");
13773 restart_af_count++;
13774 }
13775 if (!restart_af_count)
13776 vty_out(vty, "none");
13777 vty_out(vty, "\n");
13778 }
13779 } /* Gracefull Restart */
13780 }
13781 }
13782 }
13783
13784 /* graceful restart information */
13785 json_object *json_grace = NULL;
13786 json_object *json_grace_send = NULL;
13787 json_object *json_grace_recv = NULL;
13788 int eor_send_af_count = 0;
13789 int eor_receive_af_count = 0;
13790
13791 if (use_json) {
13792 json_grace = json_object_new_object();
13793 json_grace_send = json_object_new_object();
13794 json_grace_recv = json_object_new_object();
13795
13796 if ((p->status == Established)
13797 && CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13798 FOREACH_AFI_SAFI (afi, safi) {
13799 if (CHECK_FLAG(p->af_sflags[afi][safi],
13800 PEER_STATUS_EOR_SEND)) {
13801 json_object_boolean_true_add(
13802 json_grace_send,
13803 get_afi_safi_str(afi,
13804 safi,
13805 true));
13806 eor_send_af_count++;
13807 }
13808 }
13809 FOREACH_AFI_SAFI (afi, safi) {
13810 if (CHECK_FLAG(
13811 p->af_sflags[afi][safi],
13812 PEER_STATUS_EOR_RECEIVED)) {
13813 json_object_boolean_true_add(
13814 json_grace_recv,
13815 get_afi_safi_str(afi,
13816 safi,
13817 true));
13818 eor_receive_af_count++;
13819 }
13820 }
13821 }
13822 json_object_object_add(json_grace, "endOfRibSend",
13823 json_grace_send);
13824 json_object_object_add(json_grace, "endOfRibRecv",
13825 json_grace_recv);
13826
13827
13828 if (p->t_gr_restart)
13829 json_object_int_add(json_grace,
13830 "gracefulRestartTimerMsecs",
13831 thread_timer_remain_second(
13832 p->t_gr_restart)
13833 * 1000);
13834
13835 if (p->t_gr_stale)
13836 json_object_int_add(
13837 json_grace,
13838 "gracefulStalepathTimerMsecs",
13839 thread_timer_remain_second(
13840 p->t_gr_stale)
13841 * 1000);
13842 /* more gr info in new format */
13843 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json,
13844 json_grace);
13845 json_object_object_add(
13846 json_neigh, "gracefulRestartInfo", json_grace);
13847 } else {
13848 vty_out(vty, " Graceful restart information:\n");
13849 if ((p->status == Established)
13850 && CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13851
13852 vty_out(vty, " End-of-RIB send: ");
13853 FOREACH_AFI_SAFI (afi, safi) {
13854 if (CHECK_FLAG(p->af_sflags[afi][safi],
13855 PEER_STATUS_EOR_SEND)) {
13856 vty_out(vty, "%s%s",
13857 eor_send_af_count ? ", "
13858 : "",
13859 get_afi_safi_str(
13860 afi, safi,
13861 false));
13862 eor_send_af_count++;
13863 }
13864 }
13865 vty_out(vty, "\n");
13866 vty_out(vty, " End-of-RIB received: ");
13867 FOREACH_AFI_SAFI (afi, safi) {
13868 if (CHECK_FLAG(
13869 p->af_sflags[afi][safi],
13870 PEER_STATUS_EOR_RECEIVED)) {
13871 vty_out(vty, "%s%s",
13872 eor_receive_af_count
13873 ? ", "
13874 : "",
13875 get_afi_safi_str(afi,
13876 safi,
13877 false));
13878 eor_receive_af_count++;
13879 }
13880 }
13881 vty_out(vty, "\n");
13882 }
13883
13884 if (p->t_gr_restart)
13885 vty_out(vty,
13886 " The remaining time of restart timer is %ld\n",
13887 thread_timer_remain_second(
13888 p->t_gr_restart));
13889
13890 if (p->t_gr_stale)
13891 vty_out(vty,
13892 " The remaining time of stalepath timer is %ld\n",
13893 thread_timer_remain_second(
13894 p->t_gr_stale));
13895
13896 /* more gr info in new format */
13897 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, NULL);
13898 }
13899
13900 if (use_json) {
13901 json_object *json_stat = NULL;
13902 json_stat = json_object_new_object();
13903 /* Packet counts. */
13904
13905 atomic_size_t outq_count, inq_count;
13906 outq_count = atomic_load_explicit(&p->obuf->count,
13907 memory_order_relaxed);
13908 inq_count = atomic_load_explicit(&p->ibuf->count,
13909 memory_order_relaxed);
13910
13911 json_object_int_add(json_stat, "depthInq",
13912 (unsigned long)inq_count);
13913 json_object_int_add(json_stat, "depthOutq",
13914 (unsigned long)outq_count);
13915 json_object_int_add(json_stat, "opensSent",
13916 atomic_load_explicit(&p->open_out,
13917 memory_order_relaxed));
13918 json_object_int_add(json_stat, "opensRecv",
13919 atomic_load_explicit(&p->open_in,
13920 memory_order_relaxed));
13921 json_object_int_add(json_stat, "notificationsSent",
13922 atomic_load_explicit(&p->notify_out,
13923 memory_order_relaxed));
13924 json_object_int_add(json_stat, "notificationsRecv",
13925 atomic_load_explicit(&p->notify_in,
13926 memory_order_relaxed));
13927 json_object_int_add(json_stat, "updatesSent",
13928 atomic_load_explicit(&p->update_out,
13929 memory_order_relaxed));
13930 json_object_int_add(json_stat, "updatesRecv",
13931 atomic_load_explicit(&p->update_in,
13932 memory_order_relaxed));
13933 json_object_int_add(json_stat, "keepalivesSent",
13934 atomic_load_explicit(&p->keepalive_out,
13935 memory_order_relaxed));
13936 json_object_int_add(json_stat, "keepalivesRecv",
13937 atomic_load_explicit(&p->keepalive_in,
13938 memory_order_relaxed));
13939 json_object_int_add(json_stat, "routeRefreshSent",
13940 atomic_load_explicit(&p->refresh_out,
13941 memory_order_relaxed));
13942 json_object_int_add(json_stat, "routeRefreshRecv",
13943 atomic_load_explicit(&p->refresh_in,
13944 memory_order_relaxed));
13945 json_object_int_add(json_stat, "capabilitySent",
13946 atomic_load_explicit(&p->dynamic_cap_out,
13947 memory_order_relaxed));
13948 json_object_int_add(json_stat, "capabilityRecv",
13949 atomic_load_explicit(&p->dynamic_cap_in,
13950 memory_order_relaxed));
13951 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
13952 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
13953 json_object_object_add(json_neigh, "messageStats", json_stat);
13954 } else {
13955 atomic_size_t outq_count, inq_count;
13956 outq_count = atomic_load_explicit(&p->obuf->count,
13957 memory_order_relaxed);
13958 inq_count = atomic_load_explicit(&p->ibuf->count,
13959 memory_order_relaxed);
13960
13961 /* Packet counts. */
13962 vty_out(vty, " Message statistics:\n");
13963 vty_out(vty, " Inq depth is %zu\n", inq_count);
13964 vty_out(vty, " Outq depth is %zu\n", outq_count);
13965 vty_out(vty, " Sent Rcvd\n");
13966 vty_out(vty, " Opens: %10d %10d\n",
13967 atomic_load_explicit(&p->open_out,
13968 memory_order_relaxed),
13969 atomic_load_explicit(&p->open_in,
13970 memory_order_relaxed));
13971 vty_out(vty, " Notifications: %10d %10d\n",
13972 atomic_load_explicit(&p->notify_out,
13973 memory_order_relaxed),
13974 atomic_load_explicit(&p->notify_in,
13975 memory_order_relaxed));
13976 vty_out(vty, " Updates: %10d %10d\n",
13977 atomic_load_explicit(&p->update_out,
13978 memory_order_relaxed),
13979 atomic_load_explicit(&p->update_in,
13980 memory_order_relaxed));
13981 vty_out(vty, " Keepalives: %10d %10d\n",
13982 atomic_load_explicit(&p->keepalive_out,
13983 memory_order_relaxed),
13984 atomic_load_explicit(&p->keepalive_in,
13985 memory_order_relaxed));
13986 vty_out(vty, " Route Refresh: %10d %10d\n",
13987 atomic_load_explicit(&p->refresh_out,
13988 memory_order_relaxed),
13989 atomic_load_explicit(&p->refresh_in,
13990 memory_order_relaxed));
13991 vty_out(vty, " Capability: %10d %10d\n",
13992 atomic_load_explicit(&p->dynamic_cap_out,
13993 memory_order_relaxed),
13994 atomic_load_explicit(&p->dynamic_cap_in,
13995 memory_order_relaxed));
13996 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
13997 PEER_TOTAL_RX(p));
13998 }
13999
14000 if (use_json) {
14001 /* advertisement-interval */
14002 json_object_int_add(json_neigh,
14003 "minBtwnAdvertisementRunsTimerMsecs",
14004 p->v_routeadv * 1000);
14005
14006 /* Update-source. */
14007 if (p->update_if || p->update_source) {
14008 if (p->update_if)
14009 json_object_string_add(json_neigh,
14010 "updateSource",
14011 p->update_if);
14012 else if (p->update_source)
14013 json_object_string_add(
14014 json_neigh, "updateSource",
14015 sockunion2str(p->update_source, buf1,
14016 SU_ADDRSTRLEN));
14017 }
14018 } else {
14019 /* advertisement-interval */
14020 vty_out(vty,
14021 " Minimum time between advertisement runs is %d seconds\n",
14022 p->v_routeadv);
14023
14024 /* Update-source. */
14025 if (p->update_if || p->update_source) {
14026 vty_out(vty, " Update source is ");
14027 if (p->update_if)
14028 vty_out(vty, "%s", p->update_if);
14029 else if (p->update_source)
14030 vty_out(vty, "%s",
14031 sockunion2str(p->update_source, buf1,
14032 SU_ADDRSTRLEN));
14033 vty_out(vty, "\n");
14034 }
14035
14036 vty_out(vty, "\n");
14037 }
14038
14039 /* Address Family Information */
14040 json_object *json_hold = NULL;
14041
14042 if (use_json)
14043 json_hold = json_object_new_object();
14044
14045 FOREACH_AFI_SAFI (afi, safi)
14046 if (p->afc[afi][safi])
14047 bgp_show_peer_afi(vty, p, afi, safi, use_json,
14048 json_hold);
14049
14050 if (use_json) {
14051 json_object_object_add(json_neigh, "addressFamilyInfo",
14052 json_hold);
14053 json_object_int_add(json_neigh, "connectionsEstablished",
14054 p->established);
14055 json_object_int_add(json_neigh, "connectionsDropped",
14056 p->dropped);
14057 } else
14058 vty_out(vty, " Connections established %d; dropped %d\n",
14059 p->established, p->dropped);
14060
14061 if (!p->last_reset) {
14062 if (use_json)
14063 json_object_string_add(json_neigh, "lastReset",
14064 "never");
14065 else
14066 vty_out(vty, " Last reset never\n");
14067 } else {
14068 if (use_json) {
14069 time_t uptime;
14070 struct tm tm;
14071
14072 uptime = bgp_clock();
14073 uptime -= p->resettime;
14074 gmtime_r(&uptime, &tm);
14075
14076 json_object_int_add(json_neigh, "lastResetTimerMsecs",
14077 (tm.tm_sec * 1000)
14078 + (tm.tm_min * 60000)
14079 + (tm.tm_hour * 3600000));
14080 bgp_show_peer_reset(NULL, p, json_neigh, true);
14081 } else {
14082 vty_out(vty, " Last reset %s, ",
14083 peer_uptime(p->resettime, timebuf,
14084 BGP_UPTIME_LEN, 0, NULL));
14085
14086 bgp_show_peer_reset(vty, p, NULL, false);
14087 if (p->last_reset_cause_size) {
14088 msg = p->last_reset_cause;
14089 vty_out(vty,
14090 " Message received that caused BGP to send a NOTIFICATION:\n ");
14091 for (i = 1; i <= p->last_reset_cause_size;
14092 i++) {
14093 vty_out(vty, "%02X", *msg++);
14094
14095 if (i != p->last_reset_cause_size) {
14096 if (i % 16 == 0) {
14097 vty_out(vty, "\n ");
14098 } else if (i % 4 == 0) {
14099 vty_out(vty, " ");
14100 }
14101 }
14102 }
14103 vty_out(vty, "\n");
14104 }
14105 }
14106 }
14107
14108 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
14109 if (use_json)
14110 json_object_boolean_true_add(json_neigh,
14111 "prefixesConfigExceedMax");
14112 else
14113 vty_out(vty,
14114 " Peer had exceeded the max. no. of prefixes configured.\n");
14115
14116 if (p->t_pmax_restart) {
14117 if (use_json) {
14118 json_object_boolean_true_add(
14119 json_neigh, "reducePrefixNumFrom");
14120 json_object_int_add(json_neigh,
14121 "restartInTimerMsec",
14122 thread_timer_remain_second(
14123 p->t_pmax_restart)
14124 * 1000);
14125 } else
14126 vty_out(vty,
14127 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
14128 p->host, thread_timer_remain_second(
14129 p->t_pmax_restart));
14130 } else {
14131 if (use_json)
14132 json_object_boolean_true_add(
14133 json_neigh,
14134 "reducePrefixNumAndClearIpBgp");
14135 else
14136 vty_out(vty,
14137 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
14138 p->host);
14139 }
14140 }
14141
14142 /* EBGP Multihop and GTSM */
14143 if (p->sort != BGP_PEER_IBGP) {
14144 if (use_json) {
14145 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14146 json_object_int_add(json_neigh,
14147 "externalBgpNbrMaxHopsAway",
14148 p->gtsm_hops);
14149 else if (p->ttl > BGP_DEFAULT_TTL)
14150 json_object_int_add(json_neigh,
14151 "externalBgpNbrMaxHopsAway",
14152 p->ttl);
14153 } else {
14154 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14155 vty_out(vty,
14156 " External BGP neighbor may be up to %d hops away.\n",
14157 p->gtsm_hops);
14158 else if (p->ttl > BGP_DEFAULT_TTL)
14159 vty_out(vty,
14160 " External BGP neighbor may be up to %d hops away.\n",
14161 p->ttl);
14162 }
14163 } else {
14164 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED) {
14165 if (use_json)
14166 json_object_int_add(json_neigh,
14167 "internalBgpNbrMaxHopsAway",
14168 p->gtsm_hops);
14169 else
14170 vty_out(vty,
14171 " Internal BGP neighbor may be up to %d hops away.\n",
14172 p->gtsm_hops);
14173 }
14174 }
14175
14176 /* Local address. */
14177 if (p->su_local) {
14178 if (use_json) {
14179 json_object_string_add(json_neigh, "hostLocal",
14180 sockunion2str(p->su_local, buf1,
14181 SU_ADDRSTRLEN));
14182 json_object_int_add(json_neigh, "portLocal",
14183 ntohs(p->su_local->sin.sin_port));
14184 } else
14185 vty_out(vty, "Local host: %s, Local port: %d\n",
14186 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
14187 ntohs(p->su_local->sin.sin_port));
14188 }
14189
14190 /* Remote address. */
14191 if (p->su_remote) {
14192 if (use_json) {
14193 json_object_string_add(json_neigh, "hostForeign",
14194 sockunion2str(p->su_remote, buf1,
14195 SU_ADDRSTRLEN));
14196 json_object_int_add(json_neigh, "portForeign",
14197 ntohs(p->su_remote->sin.sin_port));
14198 } else
14199 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
14200 sockunion2str(p->su_remote, buf1,
14201 SU_ADDRSTRLEN),
14202 ntohs(p->su_remote->sin.sin_port));
14203 }
14204
14205 /* Nexthop display. */
14206 if (p->su_local) {
14207 if (use_json) {
14208 json_object_string_add(json_neigh, "nexthop",
14209 inet_ntop(AF_INET,
14210 &p->nexthop.v4, buf1,
14211 sizeof(buf1)));
14212 json_object_string_add(json_neigh, "nexthopGlobal",
14213 inet_ntop(AF_INET6,
14214 &p->nexthop.v6_global,
14215 buf1, sizeof(buf1)));
14216 json_object_string_add(json_neigh, "nexthopLocal",
14217 inet_ntop(AF_INET6,
14218 &p->nexthop.v6_local,
14219 buf1, sizeof(buf1)));
14220 if (p->shared_network)
14221 json_object_string_add(json_neigh,
14222 "bgpConnection",
14223 "sharedNetwork");
14224 else
14225 json_object_string_add(json_neigh,
14226 "bgpConnection",
14227 "nonSharedNetwork");
14228 } else {
14229 vty_out(vty, "Nexthop: %s\n",
14230 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
14231 sizeof(buf1)));
14232 vty_out(vty, "Nexthop global: %s\n",
14233 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
14234 sizeof(buf1)));
14235 vty_out(vty, "Nexthop local: %s\n",
14236 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
14237 sizeof(buf1)));
14238 vty_out(vty, "BGP connection: %s\n",
14239 p->shared_network ? "shared network"
14240 : "non shared network");
14241 }
14242 }
14243
14244 /* Timer information. */
14245 if (use_json) {
14246 json_object_int_add(json_neigh, "connectRetryTimer",
14247 p->v_connect);
14248 if (p->status == Established && p->rtt)
14249 json_object_int_add(json_neigh, "estimatedRttInMsecs",
14250 p->rtt);
14251 if (p->t_start)
14252 json_object_int_add(
14253 json_neigh, "nextStartTimerDueInMsecs",
14254 thread_timer_remain_second(p->t_start) * 1000);
14255 if (p->t_connect)
14256 json_object_int_add(
14257 json_neigh, "nextConnectTimerDueInMsecs",
14258 thread_timer_remain_second(p->t_connect)
14259 * 1000);
14260 if (p->t_routeadv) {
14261 json_object_int_add(json_neigh, "mraiInterval",
14262 p->v_routeadv);
14263 json_object_int_add(
14264 json_neigh, "mraiTimerExpireInMsecs",
14265 thread_timer_remain_second(p->t_routeadv)
14266 * 1000);
14267 }
14268 if (p->password)
14269 json_object_int_add(json_neigh, "authenticationEnabled",
14270 1);
14271
14272 if (p->t_read)
14273 json_object_string_add(json_neigh, "readThread", "on");
14274 else
14275 json_object_string_add(json_neigh, "readThread", "off");
14276
14277 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
14278 json_object_string_add(json_neigh, "writeThread", "on");
14279 else
14280 json_object_string_add(json_neigh, "writeThread",
14281 "off");
14282 } else {
14283 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
14284 p->v_connect);
14285 if (p->status == Established && p->rtt)
14286 vty_out(vty, "Estimated round trip time: %d ms\n",
14287 p->rtt);
14288 if (p->t_start)
14289 vty_out(vty, "Next start timer due in %ld seconds\n",
14290 thread_timer_remain_second(p->t_start));
14291 if (p->t_connect)
14292 vty_out(vty, "Next connect timer due in %ld seconds\n",
14293 thread_timer_remain_second(p->t_connect));
14294 if (p->t_routeadv)
14295 vty_out(vty,
14296 "MRAI (interval %u) timer expires in %ld seconds\n",
14297 p->v_routeadv,
14298 thread_timer_remain_second(p->t_routeadv));
14299 if (p->password)
14300 vty_out(vty, "Peer Authentication Enabled\n");
14301
14302 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
14303 p->t_read ? "on" : "off",
14304 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
14305 ? "on"
14306 : "off", p->fd);
14307 }
14308
14309 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
14310 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
14311 bgp_capability_vty_out(vty, p, use_json, json_neigh);
14312
14313 if (!use_json)
14314 vty_out(vty, "\n");
14315
14316 /* BFD information. */
14317 bgp_bfd_show_info(vty, p, use_json, json_neigh);
14318
14319 if (use_json) {
14320 if (p->conf_if) /* Configured interface name. */
14321 json_object_object_add(json, p->conf_if, json_neigh);
14322 else /* Configured IP address. */
14323 json_object_object_add(json, p->host, json_neigh);
14324 }
14325 }
14326
14327 static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
14328 enum show_type type,
14329 union sockunion *su,
14330 const char *conf_if, afi_t afi,
14331 bool use_json)
14332 {
14333 struct listnode *node, *nnode;
14334 struct peer *peer;
14335 int find = 0;
14336 safi_t safi = SAFI_UNICAST;
14337 json_object *json = NULL;
14338 json_object *json_neighbor = NULL;
14339
14340 if (use_json) {
14341 json = json_object_new_object();
14342 json_neighbor = json_object_new_object();
14343 }
14344
14345 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14346
14347 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14348 continue;
14349
14350 if ((peer->afc[afi][safi]) == 0)
14351 continue;
14352
14353 if (type == show_all) {
14354 bgp_show_peer_gr_status(vty, peer, use_json,
14355 json_neighbor);
14356
14357 if (use_json) {
14358 json_object_object_add(json, peer->host,
14359 json_neighbor);
14360 json_neighbor = NULL;
14361 }
14362
14363 } else if (type == show_peer) {
14364 if (conf_if) {
14365 if ((peer->conf_if
14366 && !strcmp(peer->conf_if, conf_if))
14367 || (peer->hostname
14368 && !strcmp(peer->hostname, conf_if))) {
14369 find = 1;
14370 bgp_show_peer_gr_status(vty, peer,
14371 use_json,
14372 json_neighbor);
14373 }
14374 } else {
14375 if (sockunion_same(&peer->su, su)) {
14376 find = 1;
14377 bgp_show_peer_gr_status(vty, peer,
14378 use_json,
14379 json_neighbor);
14380 }
14381 }
14382 if (use_json && find)
14383 json_object_object_add(json, peer->host,
14384 json_neighbor);
14385 }
14386
14387 if (find) {
14388 json_neighbor = NULL;
14389 break;
14390 }
14391 }
14392
14393 if (type == show_peer && !find) {
14394 if (use_json)
14395 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14396 else
14397 vty_out(vty, "%% No such neighbor\n");
14398 }
14399 if (use_json) {
14400 vty_out(vty, "%s\n",
14401 json_object_to_json_string_ext(
14402 json, JSON_C_TO_STRING_PRETTY));
14403
14404 if (json_neighbor)
14405 json_object_free(json_neighbor);
14406 json_object_free(json);
14407 } else {
14408 vty_out(vty, "\n");
14409 }
14410
14411 return CMD_SUCCESS;
14412 }
14413
14414 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
14415 enum show_type type, union sockunion *su,
14416 const char *conf_if, bool use_json,
14417 json_object *json)
14418 {
14419 struct listnode *node, *nnode;
14420 struct peer *peer;
14421 int find = 0;
14422 bool nbr_output = false;
14423 afi_t afi = AFI_MAX;
14424 safi_t safi = SAFI_MAX;
14425
14426 if (type == show_ipv4_peer || type == show_ipv4_all) {
14427 afi = AFI_IP;
14428 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
14429 afi = AFI_IP6;
14430 }
14431
14432 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14433 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14434 continue;
14435
14436 switch (type) {
14437 case show_all:
14438 bgp_show_peer(vty, peer, use_json, json);
14439 nbr_output = true;
14440 break;
14441 case show_peer:
14442 if (conf_if) {
14443 if ((peer->conf_if
14444 && !strcmp(peer->conf_if, conf_if))
14445 || (peer->hostname
14446 && !strcmp(peer->hostname, conf_if))) {
14447 find = 1;
14448 bgp_show_peer(vty, peer, use_json,
14449 json);
14450 }
14451 } else {
14452 if (sockunion_same(&peer->su, su)) {
14453 find = 1;
14454 bgp_show_peer(vty, peer, use_json,
14455 json);
14456 }
14457 }
14458 break;
14459 case show_ipv4_peer:
14460 case show_ipv6_peer:
14461 FOREACH_SAFI (safi) {
14462 if (peer->afc[afi][safi]) {
14463 if (conf_if) {
14464 if ((peer->conf_if
14465 && !strcmp(peer->conf_if, conf_if))
14466 || (peer->hostname
14467 && !strcmp(peer->hostname, conf_if))) {
14468 find = 1;
14469 bgp_show_peer(vty, peer, use_json,
14470 json);
14471 break;
14472 }
14473 } else {
14474 if (sockunion_same(&peer->su, su)) {
14475 find = 1;
14476 bgp_show_peer(vty, peer, use_json,
14477 json);
14478 break;
14479 }
14480 }
14481 }
14482 }
14483 break;
14484 case show_ipv4_all:
14485 case show_ipv6_all:
14486 FOREACH_SAFI (safi) {
14487 if (peer->afc[afi][safi]) {
14488 bgp_show_peer(vty, peer, use_json, json);
14489 nbr_output = true;
14490 break;
14491 }
14492 }
14493 break;
14494 }
14495 }
14496
14497 if ((type == show_peer || type == show_ipv4_peer ||
14498 type == show_ipv6_peer) && !find) {
14499 if (use_json)
14500 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14501 else
14502 vty_out(vty, "%% No such neighbor in this view/vrf\n");
14503 }
14504
14505 if (type != show_peer && type != show_ipv4_peer &&
14506 type != show_ipv6_peer && !nbr_output && !use_json)
14507 vty_out(vty, "%% No BGP neighbors found\n");
14508
14509 if (use_json) {
14510 vty_out(vty, "%s\n", json_object_to_json_string_ext(
14511 json, JSON_C_TO_STRING_PRETTY));
14512 } else {
14513 vty_out(vty, "\n");
14514 }
14515
14516 return CMD_SUCCESS;
14517 }
14518
14519 static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
14520 enum show_type type,
14521 const char *ip_str,
14522 afi_t afi, bool use_json)
14523 {
14524
14525 int ret;
14526 struct bgp *bgp;
14527 union sockunion su;
14528
14529 bgp = bgp_get_default();
14530
14531 if (!bgp)
14532 return;
14533
14534 if (!use_json)
14535 bgp_show_global_graceful_restart_mode_vty(vty, bgp, use_json,
14536 NULL);
14537
14538 if (ip_str) {
14539 ret = str2sockunion(ip_str, &su);
14540 if (ret < 0)
14541 bgp_show_neighbor_graceful_restart(
14542 vty, bgp, type, NULL, ip_str, afi, use_json);
14543 else
14544 bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
14545 NULL, afi, use_json);
14546 } else
14547 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
14548 afi, use_json);
14549 }
14550
14551 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
14552 enum show_type type,
14553 const char *ip_str,
14554 bool use_json)
14555 {
14556 struct listnode *node, *nnode;
14557 struct bgp *bgp;
14558 union sockunion su;
14559 json_object *json = NULL;
14560 int ret, is_first = 1;
14561 bool nbr_output = false;
14562
14563 if (use_json)
14564 vty_out(vty, "{\n");
14565
14566 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
14567 nbr_output = true;
14568 if (use_json) {
14569 if (!(json = json_object_new_object())) {
14570 flog_err(
14571 EC_BGP_JSON_MEM_ERROR,
14572 "Unable to allocate memory for JSON object");
14573 vty_out(vty,
14574 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
14575 return;
14576 }
14577
14578 json_object_int_add(json, "vrfId",
14579 (bgp->vrf_id == VRF_UNKNOWN)
14580 ? -1
14581 : (int64_t)bgp->vrf_id);
14582 json_object_string_add(
14583 json, "vrfName",
14584 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14585 ? VRF_DEFAULT_NAME
14586 : bgp->name);
14587
14588 if (!is_first)
14589 vty_out(vty, ",\n");
14590 else
14591 is_first = 0;
14592
14593 vty_out(vty, "\"%s\":",
14594 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14595 ? VRF_DEFAULT_NAME
14596 : bgp->name);
14597 } else {
14598 vty_out(vty, "\nInstance %s:\n",
14599 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14600 ? VRF_DEFAULT_NAME
14601 : bgp->name);
14602 }
14603
14604 if (type == show_peer || type == show_ipv4_peer ||
14605 type == show_ipv6_peer) {
14606 ret = str2sockunion(ip_str, &su);
14607 if (ret < 0)
14608 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14609 use_json, json);
14610 else
14611 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14612 use_json, json);
14613 } else {
14614 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
14615 use_json, json);
14616 }
14617 json_object_free(json);
14618 json = NULL;
14619 }
14620
14621 if (use_json)
14622 vty_out(vty, "}\n");
14623 else if (!nbr_output)
14624 vty_out(vty, "%% BGP instance not found\n");
14625 }
14626
14627 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
14628 enum show_type type, const char *ip_str,
14629 bool use_json)
14630 {
14631 int ret;
14632 struct bgp *bgp;
14633 union sockunion su;
14634 json_object *json = NULL;
14635
14636 if (name) {
14637 if (strmatch(name, "all")) {
14638 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
14639 use_json);
14640 return CMD_SUCCESS;
14641 } else {
14642 bgp = bgp_lookup_by_name(name);
14643 if (!bgp) {
14644 if (use_json) {
14645 json = json_object_new_object();
14646 vty_out(vty, "%s\n",
14647 json_object_to_json_string_ext(
14648 json,
14649 JSON_C_TO_STRING_PRETTY));
14650 json_object_free(json);
14651 } else
14652 vty_out(vty,
14653 "%% BGP instance not found\n");
14654
14655 return CMD_WARNING;
14656 }
14657 }
14658 } else {
14659 bgp = bgp_get_default();
14660 }
14661
14662 if (bgp) {
14663 json = json_object_new_object();
14664 if (ip_str) {
14665 ret = str2sockunion(ip_str, &su);
14666 if (ret < 0)
14667 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14668 use_json, json);
14669 else
14670 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14671 use_json, json);
14672 } else {
14673 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
14674 json);
14675 }
14676 json_object_free(json);
14677 } else {
14678 if (use_json)
14679 vty_out(vty, "{}\n");
14680 else
14681 vty_out(vty, "%% BGP instance not found\n");
14682 }
14683
14684 return CMD_SUCCESS;
14685 }
14686
14687
14688
14689 /* "show [ip] bgp neighbors graceful-restart" commands. */
14690 DEFUN (show_ip_bgp_neighbors_gracrful_restart,
14691 show_ip_bgp_neighbors_graceful_restart_cmd,
14692 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
14693 SHOW_STR
14694 BGP_STR
14695 IP_STR
14696 IPV6_STR
14697 NEIGHBOR_STR
14698 "Neighbor to display information about\n"
14699 "Neighbor to display information about\n"
14700 "Neighbor on BGP configured interface\n"
14701 GR_SHOW
14702 JSON_STR)
14703 {
14704 char *sh_arg = NULL;
14705 enum show_type sh_type;
14706 int idx = 0;
14707 afi_t afi = AFI_MAX;
14708 bool uj = use_json(argc, argv);
14709
14710 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
14711 afi = AFI_MAX;
14712
14713 idx++;
14714
14715 if (argv_find(argv, argc, "A.B.C.D", &idx)
14716 || argv_find(argv, argc, "X:X::X:X", &idx)
14717 || argv_find(argv, argc, "WORD", &idx)) {
14718 sh_type = show_peer;
14719 sh_arg = argv[idx]->arg;
14720 } else
14721 sh_type = show_all;
14722
14723 if (!argv_find(argv, argc, "graceful-restart", &idx))
14724 return CMD_SUCCESS;
14725
14726
14727 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
14728 afi, uj);
14729 }
14730
14731 /* "show [ip] bgp neighbors" commands. */
14732 DEFUN (show_ip_bgp_neighbors,
14733 show_ip_bgp_neighbors_cmd,
14734 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
14735 SHOW_STR
14736 IP_STR
14737 BGP_STR
14738 BGP_INSTANCE_HELP_STR
14739 "Address Family\n"
14740 "Address Family\n"
14741 "Detailed information on TCP and BGP neighbor connections\n"
14742 "Neighbor to display information about\n"
14743 "Neighbor to display information about\n"
14744 "Neighbor on BGP configured interface\n"
14745 JSON_STR)
14746 {
14747 char *vrf = NULL;
14748 char *sh_arg = NULL;
14749 enum show_type sh_type;
14750 afi_t afi = AFI_MAX;
14751
14752 bool uj = use_json(argc, argv);
14753
14754 int idx = 0;
14755
14756 /* [<vrf> VIEWVRFNAME] */
14757 if (argv_find(argv, argc, "vrf", &idx)) {
14758 vrf = argv[idx + 1]->arg;
14759 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
14760 vrf = NULL;
14761 } else if (argv_find(argv, argc, "view", &idx))
14762 /* [<view> VIEWVRFNAME] */
14763 vrf = argv[idx + 1]->arg;
14764
14765 idx++;
14766
14767 if (argv_find(argv, argc, "ipv4", &idx)) {
14768 sh_type = show_ipv4_all;
14769 afi = AFI_IP;
14770 } else if (argv_find(argv, argc, "ipv6", &idx)) {
14771 sh_type = show_ipv6_all;
14772 afi = AFI_IP6;
14773 } else {
14774 sh_type = show_all;
14775 }
14776
14777 if (argv_find(argv, argc, "A.B.C.D", &idx)
14778 || argv_find(argv, argc, "X:X::X:X", &idx)
14779 || argv_find(argv, argc, "WORD", &idx)) {
14780 sh_type = show_peer;
14781 sh_arg = argv[idx]->arg;
14782 }
14783
14784 if (sh_type == show_peer && afi == AFI_IP) {
14785 sh_type = show_ipv4_peer;
14786 } else if (sh_type == show_peer && afi == AFI_IP6) {
14787 sh_type = show_ipv6_peer;
14788 }
14789
14790 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
14791 }
14792
14793 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
14794 paths' and `show ip mbgp paths'. Those functions results are the
14795 same.*/
14796 DEFUN (show_ip_bgp_paths,
14797 show_ip_bgp_paths_cmd,
14798 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
14799 SHOW_STR
14800 IP_STR
14801 BGP_STR
14802 BGP_SAFI_HELP_STR
14803 "Path information\n")
14804 {
14805 vty_out(vty, "Address Refcnt Path\n");
14806 aspath_print_all_vty(vty);
14807 return CMD_SUCCESS;
14808 }
14809
14810 #include "hash.h"
14811
14812 static void community_show_all_iterator(struct hash_bucket *bucket,
14813 struct vty *vty)
14814 {
14815 struct community *com;
14816
14817 com = (struct community *)bucket->data;
14818 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
14819 community_str(com, false));
14820 }
14821
14822 /* Show BGP's community internal data. */
14823 DEFUN (show_ip_bgp_community_info,
14824 show_ip_bgp_community_info_cmd,
14825 "show [ip] bgp community-info",
14826 SHOW_STR
14827 IP_STR
14828 BGP_STR
14829 "List all bgp community information\n")
14830 {
14831 vty_out(vty, "Address Refcnt Community\n");
14832
14833 hash_iterate(community_hash(),
14834 (void (*)(struct hash_bucket *,
14835 void *))community_show_all_iterator,
14836 vty);
14837
14838 return CMD_SUCCESS;
14839 }
14840
14841 static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
14842 struct vty *vty)
14843 {
14844 struct lcommunity *lcom;
14845
14846 lcom = (struct lcommunity *)bucket->data;
14847 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
14848 lcommunity_str(lcom, false));
14849 }
14850
14851 /* Show BGP's community internal data. */
14852 DEFUN (show_ip_bgp_lcommunity_info,
14853 show_ip_bgp_lcommunity_info_cmd,
14854 "show ip bgp large-community-info",
14855 SHOW_STR
14856 IP_STR
14857 BGP_STR
14858 "List all bgp large-community information\n")
14859 {
14860 vty_out(vty, "Address Refcnt Large-community\n");
14861
14862 hash_iterate(lcommunity_hash(),
14863 (void (*)(struct hash_bucket *,
14864 void *))lcommunity_show_all_iterator,
14865 vty);
14866
14867 return CMD_SUCCESS;
14868 }
14869 /* Graceful Restart */
14870
14871 static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
14872 struct bgp *bgp,
14873 bool use_json,
14874 json_object *json)
14875 {
14876
14877
14878 vty_out(vty, "\n%s", SHOW_GR_HEADER);
14879
14880 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
14881
14882 switch (bgp_global_gr_mode) {
14883
14884 case GLOBAL_HELPER:
14885 vty_out(vty, "Global BGP GR Mode : Helper\n");
14886 break;
14887
14888 case GLOBAL_GR:
14889 vty_out(vty, "Global BGP GR Mode : Restart\n");
14890 break;
14891
14892 case GLOBAL_DISABLE:
14893 vty_out(vty, "Global BGP GR Mode : Disable\n");
14894 break;
14895
14896 case GLOBAL_INVALID:
14897 vty_out(vty,
14898 "Global BGP GR Mode Invalid\n");
14899 break;
14900 }
14901 vty_out(vty, "\n");
14902 }
14903
14904 static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
14905 enum show_type type,
14906 const char *ip_str,
14907 afi_t afi, bool use_json)
14908 {
14909 if ((afi == AFI_MAX) && (ip_str == NULL)) {
14910 afi = AFI_IP;
14911
14912 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
14913
14914 bgp_show_neighbor_graceful_restart_vty(
14915 vty, type, ip_str, afi, use_json);
14916 afi++;
14917 }
14918 } else if (afi != AFI_MAX) {
14919 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
14920 use_json);
14921 } else {
14922 return CMD_ERR_INCOMPLETE;
14923 }
14924
14925 return CMD_SUCCESS;
14926 }
14927 /* Graceful Restart */
14928
14929 DEFUN (show_ip_bgp_attr_info,
14930 show_ip_bgp_attr_info_cmd,
14931 "show [ip] bgp attribute-info",
14932 SHOW_STR
14933 IP_STR
14934 BGP_STR
14935 "List all bgp attribute information\n")
14936 {
14937 attr_show_all(vty);
14938 return CMD_SUCCESS;
14939 }
14940
14941 static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
14942 afi_t afi, safi_t safi,
14943 bool use_json, json_object *json)
14944 {
14945 struct bgp *bgp;
14946 struct listnode *node;
14947 char *vname;
14948 char buf1[INET6_ADDRSTRLEN];
14949 char *ecom_str;
14950 vpn_policy_direction_t dir;
14951
14952 if (json) {
14953 json_object *json_import_vrfs = NULL;
14954 json_object *json_export_vrfs = NULL;
14955
14956 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
14957
14958 if (!bgp) {
14959 vty_out(vty, "%s\n",
14960 json_object_to_json_string_ext(
14961 json,
14962 JSON_C_TO_STRING_PRETTY));
14963 json_object_free(json);
14964
14965 return CMD_WARNING;
14966 }
14967
14968 /* Provide context for the block */
14969 json_object_string_add(json, "vrf", name ? name : "default");
14970 json_object_string_add(json, "afiSafi",
14971 get_afi_safi_str(afi, safi, true));
14972
14973 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14974 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
14975 json_object_string_add(json, "importFromVrfs", "none");
14976 json_object_string_add(json, "importRts", "none");
14977 } else {
14978 json_import_vrfs = json_object_new_array();
14979
14980 for (ALL_LIST_ELEMENTS_RO(
14981 bgp->vpn_policy[afi].import_vrf,
14982 node, vname))
14983 json_object_array_add(json_import_vrfs,
14984 json_object_new_string(vname));
14985
14986 json_object_object_add(json, "importFromVrfs",
14987 json_import_vrfs);
14988 dir = BGP_VPN_POLICY_DIR_FROMVPN;
14989 if (bgp->vpn_policy[afi].rtlist[dir]) {
14990 ecom_str = ecommunity_ecom2str(
14991 bgp->vpn_policy[afi].rtlist[dir],
14992 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
14993 json_object_string_add(json, "importRts",
14994 ecom_str);
14995 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14996 } else
14997 json_object_string_add(json, "importRts",
14998 "none");
14999 }
15000
15001 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15002 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
15003 json_object_string_add(json, "exportToVrfs", "none");
15004 json_object_string_add(json, "routeDistinguisher",
15005 "none");
15006 json_object_string_add(json, "exportRts", "none");
15007 } else {
15008 json_export_vrfs = json_object_new_array();
15009
15010 for (ALL_LIST_ELEMENTS_RO(
15011 bgp->vpn_policy[afi].export_vrf,
15012 node, vname))
15013 json_object_array_add(json_export_vrfs,
15014 json_object_new_string(vname));
15015 json_object_object_add(json, "exportToVrfs",
15016 json_export_vrfs);
15017 json_object_string_add(json, "routeDistinguisher",
15018 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
15019 buf1, RD_ADDRSTRLEN));
15020
15021 dir = BGP_VPN_POLICY_DIR_TOVPN;
15022 if (bgp->vpn_policy[afi].rtlist[dir]) {
15023 ecom_str = ecommunity_ecom2str(
15024 bgp->vpn_policy[afi].rtlist[dir],
15025 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15026 json_object_string_add(json, "exportRts",
15027 ecom_str);
15028 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15029 } else
15030 json_object_string_add(json, "exportRts",
15031 "none");
15032 }
15033
15034 if (use_json) {
15035 vty_out(vty, "%s\n",
15036 json_object_to_json_string_ext(json,
15037 JSON_C_TO_STRING_PRETTY));
15038 json_object_free(json);
15039 }
15040 } else {
15041 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15042
15043 if (!bgp) {
15044 vty_out(vty, "%% No such BGP instance exist\n");
15045 return CMD_WARNING;
15046 }
15047
15048 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15049 BGP_CONFIG_VRF_TO_VRF_IMPORT))
15050 vty_out(vty,
15051 "This VRF is not importing %s routes from any other VRF\n",
15052 get_afi_safi_str(afi, safi, false));
15053 else {
15054 vty_out(vty,
15055 "This VRF is importing %s routes from the following VRFs:\n",
15056 get_afi_safi_str(afi, safi, false));
15057
15058 for (ALL_LIST_ELEMENTS_RO(
15059 bgp->vpn_policy[afi].import_vrf,
15060 node, vname))
15061 vty_out(vty, " %s\n", vname);
15062
15063 dir = BGP_VPN_POLICY_DIR_FROMVPN;
15064 ecom_str = NULL;
15065 if (bgp->vpn_policy[afi].rtlist[dir]) {
15066 ecom_str = ecommunity_ecom2str(
15067 bgp->vpn_policy[afi].rtlist[dir],
15068 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15069 vty_out(vty, "Import RT(s): %s\n", ecom_str);
15070
15071 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15072 } else
15073 vty_out(vty, "Import RT(s):\n");
15074 }
15075
15076 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15077 BGP_CONFIG_VRF_TO_VRF_EXPORT))
15078 vty_out(vty,
15079 "This VRF is not exporting %s routes to any other VRF\n",
15080 get_afi_safi_str(afi, safi, false));
15081 else {
15082 vty_out(vty,
15083 "This VRF is exporting %s routes to the following VRFs:\n",
15084 get_afi_safi_str(afi, safi, false));
15085
15086 for (ALL_LIST_ELEMENTS_RO(
15087 bgp->vpn_policy[afi].export_vrf,
15088 node, vname))
15089 vty_out(vty, " %s\n", vname);
15090
15091 vty_out(vty, "RD: %s\n",
15092 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
15093 buf1, RD_ADDRSTRLEN));
15094
15095 dir = BGP_VPN_POLICY_DIR_TOVPN;
15096 if (bgp->vpn_policy[afi].rtlist[dir]) {
15097 ecom_str = ecommunity_ecom2str(
15098 bgp->vpn_policy[afi].rtlist[dir],
15099 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15100 vty_out(vty, "Export RT: %s\n", ecom_str);
15101 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15102 } else
15103 vty_out(vty, "Import RT(s):\n");
15104 }
15105 }
15106
15107 return CMD_SUCCESS;
15108 }
15109
15110 static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
15111 safi_t safi, bool use_json)
15112 {
15113 struct listnode *node, *nnode;
15114 struct bgp *bgp;
15115 char *vrf_name = NULL;
15116 json_object *json = NULL;
15117 json_object *json_vrf = NULL;
15118 json_object *json_vrfs = NULL;
15119
15120 if (use_json) {
15121 json = json_object_new_object();
15122 json_vrfs = json_object_new_object();
15123 }
15124
15125 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15126
15127 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
15128 vrf_name = bgp->name;
15129
15130 if (use_json) {
15131 json_vrf = json_object_new_object();
15132 } else {
15133 vty_out(vty, "\nInstance %s:\n",
15134 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15135 ? VRF_DEFAULT_NAME : bgp->name);
15136 }
15137 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
15138 if (use_json) {
15139 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15140 json_object_object_add(json_vrfs,
15141 VRF_DEFAULT_NAME, json_vrf);
15142 else
15143 json_object_object_add(json_vrfs, vrf_name,
15144 json_vrf);
15145 }
15146 }
15147
15148 if (use_json) {
15149 json_object_object_add(json, "vrfs", json_vrfs);
15150 vty_out(vty, "%s\n", json_object_to_json_string_ext(json,
15151 JSON_C_TO_STRING_PRETTY));
15152 json_object_free(json);
15153 }
15154
15155 return CMD_SUCCESS;
15156 }
15157
15158 /* "show [ip] bgp route-leak" command. */
15159 DEFUN (show_ip_bgp_route_leak,
15160 show_ip_bgp_route_leak_cmd,
15161 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
15162 SHOW_STR
15163 IP_STR
15164 BGP_STR
15165 BGP_INSTANCE_HELP_STR
15166 BGP_AFI_HELP_STR
15167 BGP_SAFI_HELP_STR
15168 "Route leaking information\n"
15169 JSON_STR)
15170 {
15171 char *vrf = NULL;
15172 afi_t afi = AFI_MAX;
15173 safi_t safi = SAFI_MAX;
15174
15175 bool uj = use_json(argc, argv);
15176 int idx = 0;
15177 json_object *json = NULL;
15178
15179 /* show [ip] bgp */
15180 if (argv_find(argv, argc, "ip", &idx)) {
15181 afi = AFI_IP;
15182 safi = SAFI_UNICAST;
15183 }
15184 /* [vrf VIEWVRFNAME] */
15185 if (argv_find(argv, argc, "view", &idx)) {
15186 vty_out(vty,
15187 "%% This command is not applicable to BGP views\n");
15188 return CMD_WARNING;
15189 }
15190
15191 if (argv_find(argv, argc, "vrf", &idx)) {
15192 vrf = argv[idx + 1]->arg;
15193 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15194 vrf = NULL;
15195 }
15196 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15197 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
15198 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15199 }
15200
15201 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
15202 vty_out(vty,
15203 "%% This command is applicable only for unicast ipv4|ipv6\n");
15204 return CMD_WARNING;
15205 }
15206
15207 if (vrf && strmatch(vrf, "all"))
15208 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
15209
15210 if (uj)
15211 json = json_object_new_object();
15212
15213 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
15214 }
15215
15216 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
15217 safi_t safi)
15218 {
15219 struct listnode *node, *nnode;
15220 struct bgp *bgp;
15221
15222 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15223 vty_out(vty, "\nInstance %s:\n",
15224 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15225 ? VRF_DEFAULT_NAME
15226 : bgp->name);
15227 update_group_show(bgp, afi, safi, vty, 0);
15228 }
15229 }
15230
15231 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
15232 int safi, uint64_t subgrp_id)
15233 {
15234 struct bgp *bgp;
15235
15236 if (name) {
15237 if (strmatch(name, "all")) {
15238 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
15239 return CMD_SUCCESS;
15240 } else {
15241 bgp = bgp_lookup_by_name(name);
15242 }
15243 } else {
15244 bgp = bgp_get_default();
15245 }
15246
15247 if (bgp)
15248 update_group_show(bgp, afi, safi, vty, subgrp_id);
15249 return CMD_SUCCESS;
15250 }
15251
15252 DEFUN (show_ip_bgp_updgrps,
15253 show_ip_bgp_updgrps_cmd,
15254 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
15255 SHOW_STR
15256 IP_STR
15257 BGP_STR
15258 BGP_INSTANCE_HELP_STR
15259 BGP_AFI_HELP_STR
15260 BGP_SAFI_WITH_LABEL_HELP_STR
15261 "Detailed info about dynamic update groups\n"
15262 "Specific subgroup to display detailed info for\n")
15263 {
15264 char *vrf = NULL;
15265 afi_t afi = AFI_IP6;
15266 safi_t safi = SAFI_UNICAST;
15267 uint64_t subgrp_id = 0;
15268
15269 int idx = 0;
15270
15271 /* show [ip] bgp */
15272 if (argv_find(argv, argc, "ip", &idx))
15273 afi = AFI_IP;
15274 /* [<vrf> VIEWVRFNAME] */
15275 if (argv_find(argv, argc, "vrf", &idx)) {
15276 vrf = argv[idx + 1]->arg;
15277 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15278 vrf = NULL;
15279 } else if (argv_find(argv, argc, "view", &idx))
15280 /* [<view> VIEWVRFNAME] */
15281 vrf = argv[idx + 1]->arg;
15282 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15283 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
15284 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15285 }
15286
15287 /* get subgroup id, if provided */
15288 idx = argc - 1;
15289 if (argv[idx]->type == VARIABLE_TKN)
15290 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
15291
15292 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
15293 }
15294
15295 DEFUN (show_bgp_instance_all_ipv6_updgrps,
15296 show_bgp_instance_all_ipv6_updgrps_cmd,
15297 "show [ip] bgp <view|vrf> all update-groups",
15298 SHOW_STR
15299 IP_STR
15300 BGP_STR
15301 BGP_INSTANCE_ALL_HELP_STR
15302 "Detailed info about dynamic update groups\n")
15303 {
15304 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
15305 return CMD_SUCCESS;
15306 }
15307
15308 DEFUN (show_bgp_l2vpn_evpn_updgrps,
15309 show_bgp_l2vpn_evpn_updgrps_cmd,
15310 "show [ip] bgp l2vpn evpn update-groups",
15311 SHOW_STR
15312 IP_STR
15313 BGP_STR
15314 "l2vpn address family\n"
15315 "evpn sub-address family\n"
15316 "Detailed info about dynamic update groups\n")
15317 {
15318 char *vrf = NULL;
15319 uint64_t subgrp_id = 0;
15320
15321 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
15322 return CMD_SUCCESS;
15323 }
15324
15325 DEFUN (show_bgp_updgrps_stats,
15326 show_bgp_updgrps_stats_cmd,
15327 "show [ip] bgp update-groups statistics",
15328 SHOW_STR
15329 IP_STR
15330 BGP_STR
15331 "Detailed info about dynamic update groups\n"
15332 "Statistics\n")
15333 {
15334 struct bgp *bgp;
15335
15336 bgp = bgp_get_default();
15337 if (bgp)
15338 update_group_show_stats(bgp, vty);
15339
15340 return CMD_SUCCESS;
15341 }
15342
15343 DEFUN (show_bgp_instance_updgrps_stats,
15344 show_bgp_instance_updgrps_stats_cmd,
15345 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
15346 SHOW_STR
15347 IP_STR
15348 BGP_STR
15349 BGP_INSTANCE_HELP_STR
15350 "Detailed info about dynamic update groups\n"
15351 "Statistics\n")
15352 {
15353 int idx_word = 3;
15354 struct bgp *bgp;
15355
15356 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
15357 if (bgp)
15358 update_group_show_stats(bgp, vty);
15359
15360 return CMD_SUCCESS;
15361 }
15362
15363 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
15364 afi_t afi, safi_t safi,
15365 const char *what, uint64_t subgrp_id)
15366 {
15367 struct bgp *bgp;
15368
15369 if (name)
15370 bgp = bgp_lookup_by_name(name);
15371 else
15372 bgp = bgp_get_default();
15373
15374 if (bgp) {
15375 if (!strcmp(what, "advertise-queue"))
15376 update_group_show_adj_queue(bgp, afi, safi, vty,
15377 subgrp_id);
15378 else if (!strcmp(what, "advertised-routes"))
15379 update_group_show_advertised(bgp, afi, safi, vty,
15380 subgrp_id);
15381 else if (!strcmp(what, "packet-queue"))
15382 update_group_show_packet_queue(bgp, afi, safi, vty,
15383 subgrp_id);
15384 }
15385 }
15386
15387 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
15388 show_ip_bgp_instance_updgrps_adj_s_cmd,
15389 "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",
15390 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
15391 BGP_SAFI_HELP_STR
15392 "Detailed info about dynamic update groups\n"
15393 "Specific subgroup to display info for\n"
15394 "Advertisement queue\n"
15395 "Announced routes\n"
15396 "Packet queue\n")
15397 {
15398 uint64_t subgrp_id = 0;
15399 afi_t afiz;
15400 safi_t safiz;
15401 if (sgid)
15402 subgrp_id = strtoull(sgid, NULL, 10);
15403
15404 if (!ip && !afi)
15405 afiz = AFI_IP6;
15406 if (!ip && afi)
15407 afiz = bgp_vty_afi_from_str(afi);
15408 if (ip && !afi)
15409 afiz = AFI_IP;
15410 if (ip && afi) {
15411 afiz = bgp_vty_afi_from_str(afi);
15412 if (afiz != AFI_IP)
15413 vty_out(vty,
15414 "%% Cannot specify both 'ip' and 'ipv6'\n");
15415 return CMD_WARNING;
15416 }
15417
15418 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
15419
15420 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
15421 return CMD_SUCCESS;
15422 }
15423
15424 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
15425 {
15426 struct listnode *node, *nnode;
15427 struct prefix *range;
15428 struct peer *conf;
15429 struct peer *peer;
15430 afi_t afi;
15431 safi_t safi;
15432 const char *peer_status;
15433 const char *af_str;
15434 int lr_count;
15435 int dynamic;
15436 int af_cfgd;
15437
15438 conf = group->conf;
15439
15440 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
15441 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15442 group->name, conf->as);
15443 } else if (conf->as_type == AS_INTERNAL) {
15444 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15445 group->name, group->bgp->as);
15446 } else {
15447 vty_out(vty, "\nBGP peer-group %s\n", group->name);
15448 }
15449
15450 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
15451 vty_out(vty, " Peer-group type is internal\n");
15452 else
15453 vty_out(vty, " Peer-group type is external\n");
15454
15455 /* Display AFs configured. */
15456 vty_out(vty, " Configured address-families:");
15457 FOREACH_AFI_SAFI (afi, safi) {
15458 if (conf->afc[afi][safi]) {
15459 af_cfgd = 1;
15460 vty_out(vty, " %s;", get_afi_safi_str(afi, safi, false));
15461 }
15462 }
15463 if (!af_cfgd)
15464 vty_out(vty, " none\n");
15465 else
15466 vty_out(vty, "\n");
15467
15468 /* Display listen ranges (for dynamic neighbors), if any */
15469 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
15470 if (afi == AFI_IP)
15471 af_str = "IPv4";
15472 else if (afi == AFI_IP6)
15473 af_str = "IPv6";
15474 else
15475 af_str = "???";
15476 lr_count = listcount(group->listen_range[afi]);
15477 if (lr_count) {
15478 vty_out(vty, " %d %s listen range(s)\n", lr_count,
15479 af_str);
15480
15481
15482 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
15483 nnode, range))
15484 vty_out(vty, " %pFX\n", range);
15485 }
15486 }
15487
15488 /* Display group members and their status */
15489 if (listcount(group->peer)) {
15490 vty_out(vty, " Peer-group members:\n");
15491 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
15492 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
15493 || CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHUTDOWN))
15494 peer_status = "Idle (Admin)";
15495 else if (CHECK_FLAG(peer->sflags,
15496 PEER_STATUS_PREFIX_OVERFLOW))
15497 peer_status = "Idle (PfxCt)";
15498 else
15499 peer_status = lookup_msg(bgp_status_msg,
15500 peer->status, NULL);
15501
15502 dynamic = peer_dynamic_neighbor(peer);
15503 vty_out(vty, " %s %s %s \n", peer->host,
15504 dynamic ? "(dynamic)" : "", peer_status);
15505 }
15506 }
15507
15508 return CMD_SUCCESS;
15509 }
15510
15511 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
15512 const char *group_name)
15513 {
15514 struct bgp *bgp;
15515 struct listnode *node, *nnode;
15516 struct peer_group *group;
15517 bool found = false;
15518
15519 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15520
15521 if (!bgp) {
15522 vty_out(vty, "%% BGP instance not found\n");
15523 return CMD_WARNING;
15524 }
15525
15526 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
15527 if (group_name) {
15528 if (strmatch(group->name, group_name)) {
15529 bgp_show_one_peer_group(vty, group);
15530 found = true;
15531 break;
15532 }
15533 } else {
15534 bgp_show_one_peer_group(vty, group);
15535 }
15536 }
15537
15538 if (group_name && !found)
15539 vty_out(vty, "%% No such peer-group\n");
15540
15541 return CMD_SUCCESS;
15542 }
15543
15544 DEFUN (show_ip_bgp_peer_groups,
15545 show_ip_bgp_peer_groups_cmd,
15546 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
15547 SHOW_STR
15548 IP_STR
15549 BGP_STR
15550 BGP_INSTANCE_HELP_STR
15551 "Detailed information on BGP peer groups\n"
15552 "Peer group name\n")
15553 {
15554 char *vrf, *pg;
15555 int idx = 0;
15556
15557 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
15558 : NULL;
15559 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
15560
15561 return bgp_show_peer_group_vty(vty, vrf, pg);
15562 }
15563
15564
15565 /* Redistribute VTY commands. */
15566
15567 DEFUN_YANG (bgp_redistribute_ipv4,
15568 bgp_redistribute_ipv4_cmd,
15569 "redistribute " FRR_IP_REDIST_STR_BGPD,
15570 "Redistribute information from another routing protocol\n"
15571 FRR_IP_REDIST_HELP_STR_BGPD)
15572 {
15573 int idx_protocol = 1;
15574 char base_xpath[XPATH_MAXLEN];
15575
15576 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15577 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15578 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15579 argv[idx_protocol]->text, "0");
15580
15581 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15582
15583 return nb_cli_apply_changes(vty, base_xpath);
15584 }
15585
15586 ALIAS_HIDDEN(
15587 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
15588 "redistribute " FRR_IP_REDIST_STR_BGPD,
15589 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
15590
15591 DEFUN_YANG (bgp_redistribute_ipv4_rmap,
15592 bgp_redistribute_ipv4_rmap_cmd,
15593 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
15594 "Redistribute information from another routing protocol\n"
15595 FRR_IP_REDIST_HELP_STR_BGPD
15596 "Route map reference\n"
15597 "Pointer to route-map entries\n")
15598 {
15599 int idx_protocol = 1;
15600 int idx_word = 3;
15601 char base_xpath[XPATH_MAXLEN];
15602
15603 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15604 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15605 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15606 argv[idx_protocol]->text, "0");
15607
15608 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15609 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15610 argv[idx_word]->arg);
15611
15612 return nb_cli_apply_changes(vty, base_xpath);
15613 }
15614
15615 ALIAS_HIDDEN(
15616 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
15617 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
15618 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15619 "Route map reference\n"
15620 "Pointer to route-map entries\n")
15621
15622 DEFUN_YANG (bgp_redistribute_ipv4_metric,
15623 bgp_redistribute_ipv4_metric_cmd,
15624 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15625 "Redistribute information from another routing protocol\n"
15626 FRR_IP_REDIST_HELP_STR_BGPD
15627 "Metric for redistributed routes\n"
15628 "Default metric\n")
15629 {
15630 int idx_protocol = 1;
15631 int idx_number = 3;
15632 char base_xpath[XPATH_MAXLEN];
15633
15634 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15635 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15636 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15637 argv[idx_protocol]->text, "0");
15638
15639 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15640 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15641 argv[idx_number]->arg);
15642
15643 return nb_cli_apply_changes(vty, base_xpath);
15644 }
15645
15646 ALIAS_HIDDEN(
15647 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
15648 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15649 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15650 "Metric for redistributed routes\n"
15651 "Default metric\n")
15652
15653 DEFUN_YANG(
15654 bgp_redistribute_ipv4_rmap_metric,
15655 bgp_redistribute_ipv4_rmap_metric_cmd,
15656 "redistribute " FRR_IP_REDIST_STR_BGPD
15657 " route-map WORD metric (0-4294967295)",
15658 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15659 "Route map reference\n"
15660 "Pointer to route-map entries\n"
15661 "Metric for redistributed routes\n"
15662 "Default metric\n")
15663 {
15664 int idx_protocol = 1;
15665 int idx_word = 3;
15666 int idx_number = 5;
15667 char base_xpath[XPATH_MAXLEN];
15668
15669 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15670 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15671 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15672 argv[idx_protocol]->text, "0");
15673
15674 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15675 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15676 argv[idx_word]->arg);
15677 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15678 argv[idx_number]->arg);
15679
15680 return nb_cli_apply_changes(vty, base_xpath);
15681 }
15682
15683 ALIAS_HIDDEN(
15684 bgp_redistribute_ipv4_rmap_metric,
15685 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
15686 "redistribute " FRR_IP_REDIST_STR_BGPD
15687 " route-map WORD metric (0-4294967295)",
15688 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15689 "Route map reference\n"
15690 "Pointer to route-map entries\n"
15691 "Metric for redistributed routes\n"
15692 "Default metric\n")
15693
15694 DEFUN_YANG(
15695 bgp_redistribute_ipv4_metric_rmap,
15696 bgp_redistribute_ipv4_metric_rmap_cmd,
15697 "redistribute " FRR_IP_REDIST_STR_BGPD
15698 " metric (0-4294967295) route-map WORD",
15699 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15700 "Metric for redistributed routes\n"
15701 "Default metric\n"
15702 "Route map reference\n"
15703 "Pointer to route-map entries\n")
15704 {
15705 int idx_protocol = 1;
15706 int idx_word = 5;
15707 int idx_number = 3;
15708 char base_xpath[XPATH_MAXLEN];
15709
15710 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15711 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15712 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15713 argv[idx_protocol]->text, "0");
15714
15715 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15716 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15717 argv[idx_number]->arg);
15718 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15719 argv[idx_word]->arg);
15720
15721 return nb_cli_apply_changes(vty, base_xpath);
15722 }
15723
15724 ALIAS_HIDDEN(
15725 bgp_redistribute_ipv4_metric_rmap,
15726 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
15727 "redistribute " FRR_IP_REDIST_STR_BGPD
15728 " metric (0-4294967295) route-map WORD",
15729 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15730 "Metric for redistributed routes\n"
15731 "Default metric\n"
15732 "Route map reference\n"
15733 "Pointer to route-map entries\n")
15734
15735 DEFUN_YANG (bgp_redistribute_ipv4_ospf,
15736 bgp_redistribute_ipv4_ospf_cmd,
15737 "redistribute <ospf|table> (1-65535)",
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 {
15743 int idx_protocol = 1;
15744 int idx_number = 2;
15745 char base_xpath[XPATH_MAXLEN];
15746
15747 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15748 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15749 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15750 argv[idx_protocol]->text, argv[idx_number]->arg);
15751
15752 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15753
15754 return nb_cli_apply_changes(vty, base_xpath);
15755 }
15756
15757 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
15758 "redistribute <ospf|table> (1-65535)",
15759 "Redistribute information from another routing protocol\n"
15760 "Open Shortest Path First (OSPFv2)\n"
15761 "Non-main Kernel Routing Table\n"
15762 "Instance ID/Table ID\n")
15763
15764 DEFUN_YANG (bgp_redistribute_ipv4_ospf_rmap,
15765 bgp_redistribute_ipv4_ospf_rmap_cmd,
15766 "redistribute <ospf|table> (1-65535) route-map WORD",
15767 "Redistribute information from another routing protocol\n"
15768 "Open Shortest Path First (OSPFv2)\n"
15769 "Non-main Kernel Routing Table\n"
15770 "Instance ID/Table ID\n"
15771 "Route map reference\n"
15772 "Pointer to route-map entries\n")
15773 {
15774 int idx_protocol = 1;
15775 int idx_number = 2;
15776 int idx_word = 4;
15777 char base_xpath[XPATH_MAXLEN];
15778
15779 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15780 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15781 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15782 argv[idx_protocol]->text, argv[idx_number]->arg);
15783
15784 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15785
15786 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15787 argv[idx_word]->arg);
15788
15789 return nb_cli_apply_changes(vty, base_xpath);
15790 }
15791
15792 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
15793 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
15794 "redistribute <ospf|table> (1-65535) route-map WORD",
15795 "Redistribute information from another routing protocol\n"
15796 "Open Shortest Path First (OSPFv2)\n"
15797 "Non-main Kernel Routing Table\n"
15798 "Instance ID/Table ID\n"
15799 "Route map reference\n"
15800 "Pointer to route-map entries\n")
15801
15802 DEFUN_YANG(bgp_redistribute_ipv4_ospf_metric,
15803 bgp_redistribute_ipv4_ospf_metric_cmd,
15804 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
15805 "Redistribute information from another routing protocol\n"
15806 "Open Shortest Path First (OSPFv2)\n"
15807 "Non-main Kernel Routing Table\n"
15808 "Instance ID/Table ID\n"
15809 "Metric for redistributed routes\n"
15810 "Default metric\n")
15811 {
15812 int idx_protocol = 1;
15813 int idx_number = 2;
15814 int idx_number_2 = 4;
15815 char base_xpath[XPATH_MAXLEN];
15816
15817 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15818 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15819 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15820 argv[idx_protocol]->text, argv[idx_number]->arg);
15821
15822 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15823
15824 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15825 argv[idx_number_2]->arg);
15826
15827 return nb_cli_apply_changes(vty, base_xpath);
15828 }
15829
15830 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
15831 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
15832 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
15833 "Redistribute information from another routing protocol\n"
15834 "Open Shortest Path First (OSPFv2)\n"
15835 "Non-main Kernel Routing Table\n"
15836 "Instance ID/Table ID\n"
15837 "Metric for redistributed routes\n"
15838 "Default metric\n")
15839
15840 DEFUN_YANG(
15841 bgp_redistribute_ipv4_ospf_rmap_metric,
15842 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
15843 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
15844 "Redistribute information from another routing protocol\n"
15845 "Open Shortest Path First (OSPFv2)\n"
15846 "Non-main Kernel Routing Table\n"
15847 "Instance ID/Table ID\n"
15848 "Route map reference\n"
15849 "Pointer to route-map entries\n"
15850 "Metric for redistributed routes\n"
15851 "Default metric\n")
15852 {
15853 int idx_protocol = 1;
15854 int idx_number = 2;
15855 int idx_word = 4;
15856 int idx_number_2 = 6;
15857 char base_xpath[XPATH_MAXLEN];
15858
15859 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15860 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15861 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15862 argv[idx_protocol]->text, argv[idx_number]->arg);
15863
15864 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15865
15866 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15867 argv[idx_word]->arg);
15868 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15869 argv[idx_number_2]->arg);
15870
15871 return nb_cli_apply_changes(vty, base_xpath);
15872 }
15873
15874 ALIAS_HIDDEN(
15875 bgp_redistribute_ipv4_ospf_rmap_metric,
15876 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
15877 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
15878 "Redistribute information from another routing protocol\n"
15879 "Open Shortest Path First (OSPFv2)\n"
15880 "Non-main Kernel Routing Table\n"
15881 "Instance ID/Table ID\n"
15882 "Route map reference\n"
15883 "Pointer to route-map entries\n"
15884 "Metric for redistributed routes\n"
15885 "Default metric\n")
15886
15887 DEFUN_YANG(
15888 bgp_redistribute_ipv4_ospf_metric_rmap,
15889 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
15890 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
15891 "Redistribute information from another routing protocol\n"
15892 "Open Shortest Path First (OSPFv2)\n"
15893 "Non-main Kernel Routing Table\n"
15894 "Instance ID/Table ID\n"
15895 "Metric for redistributed routes\n"
15896 "Default metric\n"
15897 "Route map reference\n"
15898 "Pointer to route-map entries\n")
15899 {
15900 int idx_protocol = 1;
15901 int idx_number = 2;
15902 int idx_number_2 = 4;
15903 int idx_word = 6;
15904 char base_xpath[XPATH_MAXLEN];
15905
15906 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15907 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15908 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15909 argv[idx_protocol]->text, argv[idx_number]->arg);
15910
15911 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15912
15913 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15914 argv[idx_number_2]->arg);
15915 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15916 argv[idx_word]->arg);
15917
15918 return nb_cli_apply_changes(vty, base_xpath);
15919 }
15920
15921 ALIAS_HIDDEN(
15922 bgp_redistribute_ipv4_ospf_metric_rmap,
15923 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
15924 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
15925 "Redistribute information from another routing protocol\n"
15926 "Open Shortest Path First (OSPFv2)\n"
15927 "Non-main Kernel Routing Table\n"
15928 "Instance ID/Table ID\n"
15929 "Metric for redistributed routes\n"
15930 "Default metric\n"
15931 "Route map reference\n"
15932 "Pointer to route-map entries\n")
15933
15934 DEFUN_YANG (no_bgp_redistribute_ipv4_ospf,
15935 no_bgp_redistribute_ipv4_ospf_cmd,
15936 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
15937 NO_STR
15938 "Redistribute information from another routing protocol\n"
15939 "Open Shortest Path First (OSPFv2)\n"
15940 "Non-main Kernel Routing Table\n"
15941 "Instance ID/Table ID\n"
15942 "Metric for redistributed routes\n"
15943 "Default metric\n"
15944 "Route map reference\n"
15945 "Pointer to route-map entries\n")
15946 {
15947 int idx_protocol = 2;
15948 int idx_number = 3;
15949 char base_xpath[XPATH_MAXLEN];
15950
15951 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15952 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15953 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15954 argv[idx_protocol]->text, argv[idx_number]->arg);
15955
15956 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
15957
15958 return nb_cli_apply_changes(vty, base_xpath);
15959 }
15960
15961 ALIAS_HIDDEN(
15962 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
15963 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
15964 NO_STR
15965 "Redistribute information from another routing protocol\n"
15966 "Open Shortest Path First (OSPFv2)\n"
15967 "Non-main Kernel Routing Table\n"
15968 "Instance ID/Table ID\n"
15969 "Metric for redistributed routes\n"
15970 "Default metric\n"
15971 "Route map reference\n"
15972 "Pointer to route-map entries\n")
15973
15974 DEFUN_YANG (no_bgp_redistribute_ipv4,
15975 no_bgp_redistribute_ipv4_cmd,
15976 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
15977 NO_STR
15978 "Redistribute information from another routing protocol\n"
15979 FRR_IP_REDIST_HELP_STR_BGPD
15980 "Metric for redistributed routes\n"
15981 "Default metric\n"
15982 "Route map reference\n"
15983 "Pointer to route-map entries\n")
15984 {
15985 int idx_protocol = 2;
15986 char base_xpath[XPATH_MAXLEN];
15987
15988 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15989 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15990 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15991 argv[idx_protocol]->text, "0");
15992
15993 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
15994
15995 return nb_cli_apply_changes(vty, base_xpath);
15996 }
15997
15998 ALIAS_HIDDEN(
15999 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
16000 "no redistribute " FRR_IP_REDIST_STR_BGPD
16001 " [{metric (0-4294967295)|route-map WORD}]",
16002 NO_STR
16003 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16004 "Metric for redistributed routes\n"
16005 "Default metric\n"
16006 "Route map reference\n"
16007 "Pointer to route-map entries\n")
16008
16009 DEFUN_YANG (bgp_redistribute_ipv6,
16010 bgp_redistribute_ipv6_cmd,
16011 "redistribute " FRR_IP6_REDIST_STR_BGPD,
16012 "Redistribute information from another routing protocol\n"
16013 FRR_IP6_REDIST_HELP_STR_BGPD)
16014 {
16015 int idx_protocol = 1;
16016 char base_xpath[XPATH_MAXLEN];
16017
16018 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16019 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16020 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16021 argv[idx_protocol]->text, "0");
16022
16023 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16024
16025 return nb_cli_apply_changes(vty, base_xpath);
16026 }
16027
16028 DEFUN_YANG (bgp_redistribute_ipv6_rmap,
16029 bgp_redistribute_ipv6_rmap_cmd,
16030 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
16031 "Redistribute information from another routing protocol\n"
16032 FRR_IP6_REDIST_HELP_STR_BGPD
16033 "Route map reference\n"
16034 "Pointer to route-map entries\n")
16035 {
16036 int idx_protocol = 1;
16037 int idx_word = 3;
16038 char base_xpath[XPATH_MAXLEN];
16039
16040 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16041 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16042 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16043 argv[idx_protocol]->text, "0");
16044
16045 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16046 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16047 argv[idx_word]->arg);
16048
16049 return nb_cli_apply_changes(vty, base_xpath);
16050 }
16051
16052 DEFUN_YANG (bgp_redistribute_ipv6_metric,
16053 bgp_redistribute_ipv6_metric_cmd,
16054 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
16055 "Redistribute information from another routing protocol\n"
16056 FRR_IP6_REDIST_HELP_STR_BGPD
16057 "Metric for redistributed routes\n"
16058 "Default metric\n")
16059 {
16060 int idx_protocol = 1;
16061 int idx_number = 3;
16062 char base_xpath[XPATH_MAXLEN];
16063
16064 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16065 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16066 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16067 argv[idx_protocol]->text, "0");
16068
16069 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16070 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16071 argv[idx_number]->arg);
16072
16073 return nb_cli_apply_changes(vty, base_xpath);
16074 }
16075
16076 DEFUN_YANG(
16077 bgp_redistribute_ipv6_rmap_metric,
16078 bgp_redistribute_ipv6_rmap_metric_cmd,
16079 "redistribute " FRR_IP6_REDIST_STR_BGPD
16080 " route-map WORD metric (0-4294967295)",
16081 "Redistribute information from another routing protocol\n" FRR_IP6_REDIST_HELP_STR_BGPD
16082 "Route map reference\n"
16083 "Pointer to route-map entries\n"
16084 "Metric for redistributed routes\n"
16085 "Default metric\n")
16086 {
16087 int idx_protocol = 1;
16088 int idx_word = 3;
16089 int idx_number = 5;
16090 char base_xpath[XPATH_MAXLEN];
16091
16092 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16093 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16094 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16095 argv[idx_protocol]->text, "0");
16096
16097 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16098 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16099 argv[idx_word]->arg);
16100 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16101 argv[idx_number]->arg);
16102
16103 return nb_cli_apply_changes(vty, base_xpath);
16104 }
16105
16106 DEFUN_YANG(
16107 bgp_redistribute_ipv6_metric_rmap,
16108 bgp_redistribute_ipv6_metric_rmap_cmd,
16109 "redistribute " FRR_IP6_REDIST_STR_BGPD
16110 " metric (0-4294967295) route-map WORD",
16111 "Redistribute information from another routing protocol\n" FRR_IP6_REDIST_HELP_STR_BGPD
16112 "Metric for redistributed routes\n"
16113 "Default metric\n"
16114 "Route map reference\n"
16115 "Pointer to route-map entries\n")
16116 {
16117 int idx_protocol = 1;
16118 int idx_word = 5;
16119 int idx_number = 3;
16120 char base_xpath[XPATH_MAXLEN];
16121
16122 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16123 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16124 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16125 argv[idx_protocol]->text, "0");
16126
16127 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16128 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16129 argv[idx_number]->arg);
16130 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16131 argv[idx_word]->arg);
16132
16133 return nb_cli_apply_changes(vty, base_xpath);
16134 }
16135
16136 DEFUN_YANG(
16137 no_bgp_redistribute_ipv6,
16138 no_bgp_redistribute_ipv6_cmd,
16139 "no redistribute " FRR_IP6_REDIST_STR_BGPD
16140 " [{metric (0-4294967295)|route-map WORD}]",
16141 NO_STR
16142 "Redistribute information from another routing protocol\n" FRR_IP6_REDIST_HELP_STR_BGPD
16143 "Metric for redistributed routes\n"
16144 "Default metric\n"
16145 "Route map reference\n"
16146 "Pointer to route-map entries\n")
16147 {
16148 int idx_protocol = 2;
16149 char base_xpath[XPATH_MAXLEN];
16150
16151 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16152 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16153 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16154 argv[idx_protocol]->text, "0");
16155
16156 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
16157
16158 return nb_cli_apply_changes(vty, base_xpath);
16159 }
16160
16161 void cli_show_bgp_global_afi_safi_ip_unicast_redistribution_list(
16162 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
16163 {
16164 uint32_t instance = 0;
16165
16166 vty_out(vty, " redistribute %s",
16167 yang_dnode_get_string(dnode, "./route-type"));
16168 if ((instance = yang_dnode_get_uint16(dnode, "./route-instance")))
16169 vty_out(vty, " %d", instance);
16170 if (yang_dnode_exists(dnode, "./metric"))
16171 vty_out(vty, " metric %u",
16172 yang_dnode_get_uint32(dnode, "./metric"));
16173 if (yang_dnode_exists(dnode, "./rmap-policy-import"))
16174 vty_out(vty, " route-map %s",
16175 yang_dnode_get_string(dnode, "./rmap-policy-import"));
16176 vty_out(vty, "\n");
16177 }
16178
16179 static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
16180 afi_t afi, safi_t safi)
16181 {
16182 int i;
16183
16184 /* Unicast redistribution only. */
16185 if (safi != SAFI_UNICAST)
16186 return;
16187
16188 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
16189 /* Redistribute BGP does not make sense. */
16190 if (i != ZEBRA_ROUTE_BGP) {
16191 struct list *red_list;
16192 struct listnode *node;
16193 struct bgp_redist *red;
16194
16195 red_list = bgp->redist[afi][i];
16196 if (!red_list)
16197 continue;
16198
16199 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
16200 /* "redistribute" configuration. */
16201 vty_out(vty, " redistribute %s",
16202 zebra_route_string(i));
16203 if (red->instance)
16204 vty_out(vty, " %d", red->instance);
16205 if (red->redist_metric_flag)
16206 vty_out(vty, " metric %u",
16207 red->redist_metric);
16208 if (red->rmap.name)
16209 vty_out(vty, " route-map %s",
16210 red->rmap.name);
16211 vty_out(vty, "\n");
16212 }
16213 }
16214 }
16215 }
16216
16217 /* peer-group helpers for config-write */
16218
16219 static bool peergroup_flag_check(struct peer *peer, uint32_t flag)
16220 {
16221 if (!peer_group_active(peer)) {
16222 if (CHECK_FLAG(peer->flags_invert, flag))
16223 return !CHECK_FLAG(peer->flags, flag);
16224 else
16225 return !!CHECK_FLAG(peer->flags, flag);
16226 }
16227
16228 return !!CHECK_FLAG(peer->flags_override, flag);
16229 }
16230
16231 static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
16232 uint32_t flag)
16233 {
16234 if (!peer_group_active(peer)) {
16235 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
16236 return !peer_af_flag_check(peer, afi, safi, flag);
16237 else
16238 return !!peer_af_flag_check(peer, afi, safi, flag);
16239 }
16240
16241 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
16242 }
16243
16244 static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
16245 uint8_t type, int direct)
16246 {
16247 struct bgp_filter *filter;
16248
16249 if (peer_group_active(peer))
16250 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
16251 type);
16252
16253 filter = &peer->filter[afi][safi];
16254 switch (type) {
16255 case PEER_FT_DISTRIBUTE_LIST:
16256 return !!(filter->dlist[direct].name);
16257 case PEER_FT_FILTER_LIST:
16258 return !!(filter->aslist[direct].name);
16259 case PEER_FT_PREFIX_LIST:
16260 return !!(filter->plist[direct].name);
16261 case PEER_FT_ROUTE_MAP:
16262 return !!(filter->map[direct].name);
16263 case PEER_FT_UNSUPPRESS_MAP:
16264 return !!(filter->usmap.name);
16265 case PEER_FT_ADVERTISE_MAP:
16266 return !!(filter->advmap.aname
16267 && ((filter->advmap.condition == direct)
16268 && filter->advmap.cname));
16269 default:
16270 return false;
16271 }
16272 }
16273
16274 /* Return true if the addpath type is set for peer and different from
16275 * peer-group.
16276 */
16277 static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi,
16278 safi_t safi)
16279 {
16280 enum bgp_addpath_strat type, g_type;
16281
16282 type = peer->addpath_type[afi][safi];
16283
16284 if (type != BGP_ADDPATH_NONE) {
16285 if (peer_group_active(peer)) {
16286 g_type = peer->group->conf->addpath_type[afi][safi];
16287
16288 if (type != g_type)
16289 return true;
16290 else
16291 return false;
16292 }
16293
16294 return true;
16295 }
16296
16297 return false;
16298 }
16299
16300 /* This is part of the address-family block (unicast only) */
16301 static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
16302 afi_t afi)
16303 {
16304 int indent = 2;
16305
16306 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
16307 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16308 BGP_CONFIG_VRF_TO_VRF_IMPORT))
16309 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
16310 bgp->vpn_policy[afi]
16311 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16312 else
16313 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
16314 bgp->vpn_policy[afi]
16315 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16316 }
16317 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16318 BGP_CONFIG_VRF_TO_VRF_IMPORT)
16319 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16320 BGP_CONFIG_VRF_TO_VRF_EXPORT))
16321 return;
16322
16323 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16324 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
16325
16326 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
16327
16328 } else {
16329 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
16330 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
16331 bgp->vpn_policy[afi].tovpn_label);
16332 }
16333 }
16334 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16335 BGP_VPN_POLICY_TOVPN_RD_SET)) {
16336 char buf[RD_ADDRSTRLEN];
16337 vty_out(vty, "%*srd vpn export %s\n", indent, "",
16338 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
16339 sizeof(buf)));
16340 }
16341 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16342 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
16343
16344 char buf[PREFIX_STRLEN];
16345 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
16346 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
16347 sizeof(buf))) {
16348
16349 vty_out(vty, "%*snexthop vpn export %s\n",
16350 indent, "", buf);
16351 }
16352 }
16353 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
16354 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
16355 && ecommunity_cmp(
16356 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16357 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
16358
16359 char *b = ecommunity_ecom2str(
16360 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16361 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
16362 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
16363 XFREE(MTYPE_ECOMMUNITY_STR, b);
16364 } else {
16365 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
16366 char *b = ecommunity_ecom2str(
16367 bgp->vpn_policy[afi]
16368 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16369 ECOMMUNITY_FORMAT_ROUTE_MAP,
16370 ECOMMUNITY_ROUTE_TARGET);
16371 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
16372 XFREE(MTYPE_ECOMMUNITY_STR, b);
16373 }
16374 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
16375 char *b = ecommunity_ecom2str(
16376 bgp->vpn_policy[afi]
16377 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16378 ECOMMUNITY_FORMAT_ROUTE_MAP,
16379 ECOMMUNITY_ROUTE_TARGET);
16380 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
16381 XFREE(MTYPE_ECOMMUNITY_STR, b);
16382 }
16383 }
16384
16385 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
16386 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
16387 bgp->vpn_policy[afi]
16388 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
16389
16390 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
16391 char *b = ecommunity_ecom2str(
16392 bgp->vpn_policy[afi]
16393 .import_redirect_rtlist,
16394 ECOMMUNITY_FORMAT_ROUTE_MAP,
16395 ECOMMUNITY_ROUTE_TARGET);
16396
16397 if (bgp->vpn_policy[afi].import_redirect_rtlist->unit_size
16398 != ECOMMUNITY_SIZE)
16399 vty_out(vty, "%*srt6 redirect import %s\n",
16400 indent, "", b);
16401 else
16402 vty_out(vty, "%*srt redirect import %s\n",
16403 indent, "", b);
16404 XFREE(MTYPE_ECOMMUNITY_STR, b);
16405 }
16406 }
16407
16408 static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
16409 afi_t afi, safi_t safi)
16410 {
16411 struct bgp_filter *filter;
16412 char *addr;
16413
16414 addr = peer->host;
16415 filter = &peer->filter[afi][safi];
16416
16417 /* distribute-list. */
16418 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16419 FILTER_IN))
16420 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
16421 filter->dlist[FILTER_IN].name);
16422
16423 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16424 FILTER_OUT))
16425 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
16426 filter->dlist[FILTER_OUT].name);
16427
16428 /* prefix-list. */
16429 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16430 FILTER_IN))
16431 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
16432 filter->plist[FILTER_IN].name);
16433
16434 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16435 FILTER_OUT))
16436 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
16437 filter->plist[FILTER_OUT].name);
16438
16439 /* route-map. */
16440 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
16441 vty_out(vty, " neighbor %s route-map %s in\n", addr,
16442 filter->map[RMAP_IN].name);
16443
16444 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
16445 RMAP_OUT))
16446 vty_out(vty, " neighbor %s route-map %s out\n", addr,
16447 filter->map[RMAP_OUT].name);
16448
16449 /* unsuppress-map */
16450 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
16451 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
16452 filter->usmap.name);
16453
16454 /* advertise-map : always applied in OUT direction*/
16455 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16456 CONDITION_NON_EXIST))
16457 vty_out(vty,
16458 " neighbor %s advertise-map %s non-exist-map %s\n",
16459 addr, filter->advmap.aname, filter->advmap.cname);
16460
16461 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16462 CONDITION_EXIST))
16463 vty_out(vty, " neighbor %s advertise-map %s exist-map %s\n",
16464 addr, filter->advmap.aname, filter->advmap.cname);
16465
16466 /* filter-list. */
16467 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16468 FILTER_IN))
16469 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
16470 filter->aslist[FILTER_IN].name);
16471
16472 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16473 FILTER_OUT))
16474 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
16475 filter->aslist[FILTER_OUT].name);
16476 }
16477
16478 /* BGP peer configuration display function. */
16479 static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
16480 struct peer *peer)
16481 {
16482 struct peer *g_peer = NULL;
16483 char buf[SU_ADDRSTRLEN];
16484 char *addr;
16485 int if_pg_printed = false;
16486 int if_ras_printed = false;
16487
16488 /* Skip dynamic neighbors. */
16489 if (peer_dynamic_neighbor(peer))
16490 return;
16491
16492 if (peer->conf_if)
16493 addr = peer->conf_if;
16494 else
16495 addr = peer->host;
16496
16497 /************************************
16498 ****** Global to the neighbor ******
16499 ************************************/
16500 if (peer->conf_if) {
16501 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
16502 vty_out(vty, " neighbor %s interface v6only", addr);
16503 else
16504 vty_out(vty, " neighbor %s interface", addr);
16505
16506 if (peer_group_active(peer)) {
16507 vty_out(vty, " peer-group %s", peer->group->name);
16508 if_pg_printed = true;
16509 } else if (peer->as_type == AS_SPECIFIED) {
16510 vty_out(vty, " remote-as %u", peer->as);
16511 if_ras_printed = true;
16512 } else if (peer->as_type == AS_INTERNAL) {
16513 vty_out(vty, " remote-as internal");
16514 if_ras_printed = true;
16515 } else if (peer->as_type == AS_EXTERNAL) {
16516 vty_out(vty, " remote-as external");
16517 if_ras_printed = true;
16518 }
16519
16520 vty_out(vty, "\n");
16521 }
16522
16523 /* remote-as and peer-group */
16524 /* peer is a member of a peer-group */
16525 if (peer_group_active(peer)) {
16526 g_peer = peer->group->conf;
16527
16528 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
16529 if (peer->as_type == AS_SPECIFIED) {
16530 vty_out(vty, " neighbor %s remote-as %u\n",
16531 addr, peer->as);
16532 } else if (peer->as_type == AS_INTERNAL) {
16533 vty_out(vty,
16534 " neighbor %s remote-as internal\n",
16535 addr);
16536 } else if (peer->as_type == AS_EXTERNAL) {
16537 vty_out(vty,
16538 " neighbor %s remote-as external\n",
16539 addr);
16540 }
16541 }
16542
16543 /* For swpX peers we displayed the peer-group
16544 * via 'neighbor swpX interface peer-group PGNAME' */
16545 if (!if_pg_printed)
16546 vty_out(vty, " neighbor %s peer-group %s\n", addr,
16547 peer->group->name);
16548 }
16549
16550 /* peer is NOT a member of a peer-group */
16551 else {
16552 /* peer is a peer-group, declare the peer-group */
16553 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
16554 vty_out(vty, " neighbor %s peer-group\n", addr);
16555 }
16556
16557 if (!if_ras_printed) {
16558 if (peer->as_type == AS_SPECIFIED) {
16559 vty_out(vty, " neighbor %s remote-as %u\n",
16560 addr, peer->as);
16561 } else if (peer->as_type == AS_INTERNAL) {
16562 vty_out(vty,
16563 " neighbor %s remote-as internal\n",
16564 addr);
16565 } else if (peer->as_type == AS_EXTERNAL) {
16566 vty_out(vty,
16567 " neighbor %s remote-as external\n",
16568 addr);
16569 }
16570 }
16571 }
16572
16573 /* local-as */
16574 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
16575 vty_out(vty, " neighbor %s local-as %u", addr,
16576 peer->change_local_as);
16577 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
16578 vty_out(vty, " no-prepend");
16579 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
16580 vty_out(vty, " replace-as");
16581 vty_out(vty, "\n");
16582 }
16583
16584 /* description */
16585 if (peer->desc) {
16586 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
16587 }
16588
16589 /* shutdown */
16590 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
16591 if (peer->tx_shutdown_message)
16592 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
16593 peer->tx_shutdown_message);
16594 else
16595 vty_out(vty, " neighbor %s shutdown\n", addr);
16596 }
16597
16598 if (peergroup_flag_check(peer, PEER_FLAG_RTT_SHUTDOWN))
16599 vty_out(vty, " neighbor %s shutdown rtt %u count %u\n", addr,
16600 peer->rtt_expected, peer->rtt_keepalive_conf);
16601
16602 /* bfd */
16603 if (peer->bfd_info) {
16604 if (!peer_group_active(peer) || !g_peer->bfd_info) {
16605 bgp_bfd_peer_config_write(vty, peer, addr);
16606 }
16607 }
16608
16609 /* password */
16610 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
16611 vty_out(vty, " neighbor %s password %s\n", addr,
16612 peer->password);
16613
16614 /* neighbor solo */
16615 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
16616 if (!peer_group_active(peer)) {
16617 vty_out(vty, " neighbor %s solo\n", addr);
16618 }
16619 }
16620
16621 /* BGP port */
16622 if (peer->port != BGP_PORT_DEFAULT) {
16623 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
16624 }
16625
16626 /* Local interface name */
16627 if (peer->ifname) {
16628 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
16629 }
16630
16631 /* passive */
16632 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
16633 vty_out(vty, " neighbor %s passive\n", addr);
16634
16635 /* ebgp-multihop */
16636 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
16637 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
16638 && peer->ttl == MAXTTL)) {
16639 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
16640 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
16641 peer->ttl);
16642 }
16643 }
16644
16645 /* ttl-security hops */
16646 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
16647 if (!peer_group_active(peer)
16648 || g_peer->gtsm_hops != peer->gtsm_hops) {
16649 vty_out(vty, " neighbor %s ttl-security hops %d\n",
16650 addr, peer->gtsm_hops);
16651 }
16652 }
16653
16654 /* disable-connected-check */
16655 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
16656 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
16657
16658 /* enforce-first-as */
16659 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
16660 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
16661
16662 /* update-source */
16663 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
16664 if (peer->update_source)
16665 vty_out(vty, " neighbor %s update-source %s\n", addr,
16666 sockunion2str(peer->update_source, buf,
16667 SU_ADDRSTRLEN));
16668 else if (peer->update_if)
16669 vty_out(vty, " neighbor %s update-source %s\n", addr,
16670 peer->update_if);
16671 }
16672
16673 /* advertisement-interval */
16674 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
16675 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
16676 peer->routeadv);
16677
16678 /* timers */
16679 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
16680 vty_out(vty, " neighbor %s timers %u %u\n", addr,
16681 peer->keepalive, peer->holdtime);
16682
16683 /* timers connect */
16684 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
16685 vty_out(vty, " neighbor %s timers connect %u\n", addr,
16686 peer->connect);
16687 /* need special-case handling for changed default values due to
16688 * config profile / version (because there is no "timers bgp connect"
16689 * command, we need to save this per-peer :/)
16690 */
16691 else if (!peer_group_active(peer) && !peer->connect &&
16692 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
16693 vty_out(vty, " neighbor %s timers connect %u\n", addr,
16694 peer->bgp->default_connect_retry);
16695
16696 /* timers delayopen */
16697 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_DELAYOPEN))
16698 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
16699 peer->delayopen);
16700 /* Save config even though flag is not set if default values have been
16701 * changed
16702 */
16703 else if (!peer_group_active(peer) && !peer->delayopen
16704 && peer->bgp->default_delayopen != BGP_DEFAULT_DELAYOPEN)
16705 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
16706 peer->bgp->default_delayopen);
16707
16708 /* capability dynamic */
16709 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
16710 vty_out(vty, " neighbor %s capability dynamic\n", addr);
16711
16712 /* capability extended-nexthop */
16713 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
16714 if (!peer->conf_if) {
16715 if (CHECK_FLAG(peer->flags_invert,
16716 PEER_FLAG_CAPABILITY_ENHE))
16717 vty_out(vty,
16718 " no neighbor %s capability extended-nexthop\n",
16719 addr);
16720 else
16721 vty_out(vty,
16722 " neighbor %s capability extended-nexthop\n",
16723 addr);
16724 }
16725 }
16726
16727 /* dont-capability-negotiation */
16728 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
16729 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
16730
16731 /* override-capability */
16732 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
16733 vty_out(vty, " neighbor %s override-capability\n", addr);
16734
16735 /* strict-capability-match */
16736 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
16737 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
16738
16739 /* Sender side AS path loop detection. */
16740 if (peer->as_path_loop_detection)
16741 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
16742 addr);
16743
16744 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
16745 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
16746
16747 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
16748 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
16749 vty_out(vty,
16750 " neighbor %s graceful-restart-helper\n", addr);
16751 } else if (CHECK_FLAG(
16752 peer->peer_gr_new_status_flag,
16753 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
16754 vty_out(vty,
16755 " neighbor %s graceful-restart\n", addr);
16756 } else if (
16757 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
16758 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
16759 && !(CHECK_FLAG(
16760 peer->peer_gr_new_status_flag,
16761 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
16762 vty_out(vty, " neighbor %s graceful-restart-disable\n",
16763 addr);
16764 }
16765 }
16766 }
16767
16768 /* BGP peer configuration display function. */
16769 static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
16770 struct peer *peer, afi_t afi, safi_t safi)
16771 {
16772 struct peer *g_peer = NULL;
16773 char *addr;
16774 bool flag_scomm, flag_secomm, flag_slcomm;
16775
16776 /* Skip dynamic neighbors. */
16777 if (peer_dynamic_neighbor(peer))
16778 return;
16779
16780 if (peer->conf_if)
16781 addr = peer->conf_if;
16782 else
16783 addr = peer->host;
16784
16785 /************************************
16786 ****** Per AF to the neighbor ******
16787 ************************************/
16788 if (peer_group_active(peer)) {
16789 g_peer = peer->group->conf;
16790
16791 /* If the peer-group is active but peer is not, print a 'no
16792 * activate' */
16793 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
16794 vty_out(vty, " no neighbor %s activate\n", addr);
16795 }
16796
16797 /* If the peer-group is not active but peer is, print an
16798 'activate' */
16799 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
16800 vty_out(vty, " neighbor %s activate\n", addr);
16801 }
16802 } else {
16803 if (peer->afc[afi][safi]) {
16804 if ((afi == AFI_IP) && (safi == SAFI_UNICAST)) {
16805 if (CHECK_FLAG(bgp->flags,
16806 BGP_FLAG_NO_DEFAULT_IPV4)) {
16807 vty_out(vty, " neighbor %s activate\n",
16808 addr);
16809 }
16810 } else
16811 vty_out(vty, " neighbor %s activate\n", addr);
16812 } else {
16813 if ((afi == AFI_IP) && (safi == SAFI_UNICAST)) {
16814 if (!CHECK_FLAG(bgp->flags,
16815 BGP_FLAG_NO_DEFAULT_IPV4)) {
16816 vty_out(vty,
16817 " no neighbor %s activate\n",
16818 addr);
16819 }
16820 }
16821 }
16822 }
16823
16824 /* addpath TX knobs */
16825 if (peergroup_af_addpath_check(peer, afi, safi)) {
16826 switch (peer->addpath_type[afi][safi]) {
16827 case BGP_ADDPATH_ALL:
16828 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
16829 addr);
16830 break;
16831 case BGP_ADDPATH_BEST_PER_AS:
16832 vty_out(vty,
16833 " neighbor %s addpath-tx-bestpath-per-AS\n",
16834 addr);
16835 break;
16836 case BGP_ADDPATH_MAX:
16837 case BGP_ADDPATH_NONE:
16838 break;
16839 }
16840 }
16841
16842 /* ORF capability. */
16843 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
16844 || peergroup_af_flag_check(peer, afi, safi,
16845 PEER_FLAG_ORF_PREFIX_RM)) {
16846 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
16847
16848 if (peergroup_af_flag_check(peer, afi, safi,
16849 PEER_FLAG_ORF_PREFIX_SM)
16850 && peergroup_af_flag_check(peer, afi, safi,
16851 PEER_FLAG_ORF_PREFIX_RM))
16852 vty_out(vty, " both");
16853 else if (peergroup_af_flag_check(peer, afi, safi,
16854 PEER_FLAG_ORF_PREFIX_SM))
16855 vty_out(vty, " send");
16856 else
16857 vty_out(vty, " receive");
16858 vty_out(vty, "\n");
16859 }
16860
16861 /* Route reflector client. */
16862 if (peergroup_af_flag_check(peer, afi, safi,
16863 PEER_FLAG_REFLECTOR_CLIENT)) {
16864 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
16865 }
16866
16867 /* next-hop-self force */
16868 if (peergroup_af_flag_check(peer, afi, safi,
16869 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
16870 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
16871 }
16872
16873 /* next-hop-self */
16874 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
16875 vty_out(vty, " neighbor %s next-hop-self\n", addr);
16876 }
16877
16878 /* remove-private-AS */
16879 if (peergroup_af_flag_check(peer, afi, safi,
16880 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
16881 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
16882 addr);
16883 }
16884
16885 else if (peergroup_af_flag_check(peer, afi, safi,
16886 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
16887 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
16888 addr);
16889 }
16890
16891 else if (peergroup_af_flag_check(peer, afi, safi,
16892 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
16893 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
16894 }
16895
16896 else if (peergroup_af_flag_check(peer, afi, safi,
16897 PEER_FLAG_REMOVE_PRIVATE_AS)) {
16898 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
16899 }
16900
16901 /* as-override */
16902 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
16903 vty_out(vty, " neighbor %s as-override\n", addr);
16904 }
16905
16906 /* send-community print. */
16907 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
16908 PEER_FLAG_SEND_COMMUNITY);
16909 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
16910 PEER_FLAG_SEND_EXT_COMMUNITY);
16911 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
16912 PEER_FLAG_SEND_LARGE_COMMUNITY);
16913
16914 if (flag_scomm && flag_secomm && flag_slcomm) {
16915 vty_out(vty, " no neighbor %s send-community all\n", addr);
16916 } else {
16917 if (flag_scomm)
16918 vty_out(vty, " no neighbor %s send-community\n", addr);
16919 if (flag_secomm)
16920 vty_out(vty,
16921 " no neighbor %s send-community extended\n",
16922 addr);
16923
16924 if (flag_slcomm)
16925 vty_out(vty, " no neighbor %s send-community large\n",
16926 addr);
16927 }
16928
16929 /* Default information */
16930 if (peergroup_af_flag_check(peer, afi, safi,
16931 PEER_FLAG_DEFAULT_ORIGINATE)) {
16932 vty_out(vty, " neighbor %s default-originate", addr);
16933
16934 if (peer->default_rmap[afi][safi].name)
16935 vty_out(vty, " route-map %s",
16936 peer->default_rmap[afi][safi].name);
16937
16938 vty_out(vty, "\n");
16939 }
16940
16941 /* Soft reconfiguration inbound. */
16942 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
16943 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
16944 addr);
16945 }
16946
16947 /* maximum-prefix. */
16948 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
16949 vty_out(vty, " neighbor %s maximum-prefix %u", addr,
16950 peer->pmax[afi][safi]);
16951
16952 if (peer->pmax_threshold[afi][safi]
16953 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
16954 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
16955 if (peer_af_flag_check(peer, afi, safi,
16956 PEER_FLAG_MAX_PREFIX_WARNING))
16957 vty_out(vty, " warning-only");
16958 if (peer->pmax_restart[afi][safi])
16959 vty_out(vty, " restart %u",
16960 peer->pmax_restart[afi][safi]);
16961 if (peer_af_flag_check(peer, afi, safi,
16962 PEER_FLAG_MAX_PREFIX_FORCE))
16963 vty_out(vty, " force");
16964
16965 vty_out(vty, "\n");
16966 }
16967
16968 /* maximum-prefix-out */
16969 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
16970 vty_out(vty, " neighbor %s maximum-prefix-out %u\n",
16971 addr, peer->pmax_out[afi][safi]);
16972
16973 /* Route server client. */
16974 if (peergroup_af_flag_check(peer, afi, safi,
16975 PEER_FLAG_RSERVER_CLIENT)) {
16976 vty_out(vty, " neighbor %s route-server-client\n", addr);
16977 }
16978
16979 /* Nexthop-local unchanged. */
16980 if (peergroup_af_flag_check(peer, afi, safi,
16981 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
16982 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
16983 }
16984
16985 /* allowas-in <1-10> */
16986 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
16987 if (peer_af_flag_check(peer, afi, safi,
16988 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
16989 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
16990 } else if (peer->allowas_in[afi][safi] == 3) {
16991 vty_out(vty, " neighbor %s allowas-in\n", addr);
16992 } else {
16993 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
16994 peer->allowas_in[afi][safi]);
16995 }
16996 }
16997
16998 /* weight */
16999 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
17000 vty_out(vty, " neighbor %s weight %lu\n", addr,
17001 peer->weight[afi][safi]);
17002
17003 /* Filter. */
17004 bgp_config_write_filter(vty, peer, afi, safi);
17005
17006 /* atribute-unchanged. */
17007 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
17008 || (safi != SAFI_EVPN
17009 && peer_af_flag_check(peer, afi, safi,
17010 PEER_FLAG_NEXTHOP_UNCHANGED))
17011 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
17012
17013 if (!peer_group_active(peer)
17014 || peergroup_af_flag_check(peer, afi, safi,
17015 PEER_FLAG_AS_PATH_UNCHANGED)
17016 || peergroup_af_flag_check(peer, afi, safi,
17017 PEER_FLAG_NEXTHOP_UNCHANGED)
17018 || peergroup_af_flag_check(peer, afi, safi,
17019 PEER_FLAG_MED_UNCHANGED)) {
17020
17021 vty_out(vty,
17022 " neighbor %s attribute-unchanged%s%s%s\n",
17023 addr,
17024 peer_af_flag_check(peer, afi, safi,
17025 PEER_FLAG_AS_PATH_UNCHANGED)
17026 ? " as-path"
17027 : "",
17028 peer_af_flag_check(peer, afi, safi,
17029 PEER_FLAG_NEXTHOP_UNCHANGED)
17030 ? " next-hop"
17031 : "",
17032 peer_af_flag_check(peer, afi, safi,
17033 PEER_FLAG_MED_UNCHANGED)
17034 ? " med"
17035 : "");
17036 }
17037 }
17038 }
17039
17040 /* Address family based peer configuration display. */
17041 static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
17042 safi_t safi)
17043 {
17044 struct peer *peer;
17045 struct peer_group *group;
17046 struct listnode *node, *nnode;
17047
17048
17049 vty_frame(vty, " !\n address-family ");
17050 if (afi == AFI_IP) {
17051 if (safi == SAFI_UNICAST)
17052 vty_frame(vty, "ipv4 unicast");
17053 else if (safi == SAFI_LABELED_UNICAST)
17054 vty_frame(vty, "ipv4 labeled-unicast");
17055 else if (safi == SAFI_MULTICAST)
17056 vty_frame(vty, "ipv4 multicast");
17057 else if (safi == SAFI_MPLS_VPN)
17058 vty_frame(vty, "ipv4 vpn");
17059 else if (safi == SAFI_ENCAP)
17060 vty_frame(vty, "ipv4 encap");
17061 else if (safi == SAFI_FLOWSPEC)
17062 vty_frame(vty, "ipv4 flowspec");
17063 } else if (afi == AFI_IP6) {
17064 if (safi == SAFI_UNICAST)
17065 vty_frame(vty, "ipv6 unicast");
17066 else if (safi == SAFI_LABELED_UNICAST)
17067 vty_frame(vty, "ipv6 labeled-unicast");
17068 else if (safi == SAFI_MULTICAST)
17069 vty_frame(vty, "ipv6 multicast");
17070 else if (safi == SAFI_MPLS_VPN)
17071 vty_frame(vty, "ipv6 vpn");
17072 else if (safi == SAFI_ENCAP)
17073 vty_frame(vty, "ipv6 encap");
17074 else if (safi == SAFI_FLOWSPEC)
17075 vty_frame(vty, "ipv6 flowspec");
17076 } else if (afi == AFI_L2VPN) {
17077 if (safi == SAFI_EVPN)
17078 vty_frame(vty, "l2vpn evpn");
17079 }
17080 vty_frame(vty, "\n");
17081
17082 bgp_config_write_distance(vty, bgp, afi, safi);
17083
17084 bgp_config_write_network(vty, bgp, afi, safi);
17085
17086 bgp_config_write_redistribute(vty, bgp, afi, safi);
17087
17088 /* BGP flag dampening. */
17089 if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
17090 bgp_config_write_damp(vty, bgp, afi, safi);
17091 for (ALL_LIST_ELEMENTS_RO(bgp->group, node, group))
17092 if (peer_af_flag_check(group->conf, afi, safi,
17093 PEER_FLAG_CONFIG_DAMPENING))
17094 bgp_config_write_peer_damp(vty, group->conf, afi, safi);
17095 for (ALL_LIST_ELEMENTS_RO(bgp->peer, node, peer))
17096 if (peer_af_flag_check(peer, afi, safi,
17097 PEER_FLAG_CONFIG_DAMPENING))
17098 bgp_config_write_peer_damp(vty, peer, afi, safi);
17099
17100 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
17101 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
17102
17103 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17104 /* Skip dynamic neighbors. */
17105 if (peer_dynamic_neighbor(peer))
17106 continue;
17107
17108 /* Do not display doppelganger peers */
17109 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17110 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
17111 }
17112
17113 bgp_config_write_maxpaths(vty, bgp, afi, safi);
17114 bgp_config_write_table_map(vty, bgp, afi, safi);
17115
17116 if (safi == SAFI_EVPN)
17117 bgp_config_write_evpn_info(vty, bgp, afi, safi);
17118
17119 if (safi == SAFI_FLOWSPEC)
17120 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
17121
17122 if (safi == SAFI_UNICAST) {
17123 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
17124 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17125 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
17126
17127 vty_out(vty, " export vpn\n");
17128 }
17129 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17130 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
17131
17132 vty_out(vty, " import vpn\n");
17133 }
17134 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17135 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
17136 char *name;
17137
17138 for (ALL_LIST_ELEMENTS_RO(
17139 bgp->vpn_policy[afi].import_vrf, node,
17140 name))
17141 vty_out(vty, " import vrf %s\n", name);
17142 }
17143 }
17144
17145 vty_endframe(vty, " exit-address-family\n");
17146 }
17147
17148 int bgp_config_write(struct vty *vty)
17149 {
17150 struct bgp *bgp;
17151 struct peer_group *group;
17152 struct peer *peer;
17153 struct listnode *node, *nnode;
17154 struct listnode *mnode, *mnnode;
17155
17156 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
17157 vty_out(vty, "bgp route-map delay-timer %u\n",
17158 bm->rmap_update_timer);
17159
17160 if (bm->v_update_delay != BGP_UPDATE_DELAY_DEF) {
17161 vty_out(vty, "bgp update-delay %d", bm->v_update_delay);
17162 if (bm->v_update_delay != bm->v_establish_wait)
17163 vty_out(vty, " %d", bm->v_establish_wait);
17164 vty_out(vty, "\n");
17165 }
17166
17167 if (bm->wait_for_fib)
17168 vty_out(vty, "bgp suppress-fib-pending\n");
17169
17170 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17171 vty_out(vty, "bgp graceful-shutdown\n");
17172
17173 /* No-RIB (Zebra) option flag configuration */
17174 if (bgp_option_check(BGP_OPT_NO_FIB))
17175 vty_out(vty, "bgp no-rib\n");
17176
17177 if (!CHECK_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA))
17178 vty_out(vty, "no bgp send-extra-data zebra\n");
17179
17180 /* BGP configuration. */
17181 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
17182
17183 /* skip all auto created vrf as they dont have user config */
17184 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
17185 continue;
17186
17187 /* Router bgp ASN */
17188 vty_out(vty, "router bgp %u", bgp->as);
17189
17190 if (bgp->name)
17191 vty_out(vty, " %s %s",
17192 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
17193 ? "view" : "vrf", bgp->name);
17194 vty_out(vty, "\n");
17195
17196 /* BGP fast-external-failover. */
17197 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
17198 vty_out(vty, " no bgp fast-external-failover\n");
17199
17200 /* BGP router ID. */
17201 if (bgp->router_id_static.s_addr != INADDR_ANY)
17202 vty_out(vty, " bgp router-id %pI4\n",
17203 &bgp->router_id_static);
17204
17205 /* Suppress fib pending */
17206 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_FIB_PENDING))
17207 vty_out(vty, " bgp suppress-fib-pending\n");
17208
17209 /* BGP log-neighbor-changes. */
17210 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
17211 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
17212 vty_out(vty, " %sbgp log-neighbor-changes\n",
17213 CHECK_FLAG(bgp->flags,
17214 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
17215 ? ""
17216 : "no ");
17217
17218 /* BGP configuration. */
17219 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
17220 vty_out(vty, " bgp always-compare-med\n");
17221
17222 /* RFC8212 default eBGP policy. */
17223 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
17224 != SAVE_BGP_EBGP_REQUIRES_POLICY)
17225 vty_out(vty, " %sbgp ebgp-requires-policy\n",
17226 CHECK_FLAG(bgp->flags,
17227 BGP_FLAG_EBGP_REQUIRES_POLICY)
17228 ? ""
17229 : "no ");
17230
17231 /* draft-ietf-idr-deprecate-as-set-confed-set */
17232 if (bgp->reject_as_sets)
17233 vty_out(vty, " bgp reject-as-sets\n");
17234
17235 /* Suppress duplicate updates if the route actually not changed
17236 */
17237 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES)
17238 != SAVE_BGP_SUPPRESS_DUPLICATES)
17239 vty_out(vty, " %sbgp suppress-duplicates\n",
17240 CHECK_FLAG(bgp->flags,
17241 BGP_FLAG_SUPPRESS_DUPLICATES)
17242 ? ""
17243 : "no ");
17244
17245 /* BGP default ipv4-unicast. */
17246 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4))
17247 vty_out(vty, " no bgp default ipv4-unicast\n");
17248
17249 /* BGP default local-preference. */
17250 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
17251 vty_out(vty, " bgp default local-preference %u\n",
17252 bgp->default_local_pref);
17253
17254 /* BGP default show-hostname */
17255 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
17256 != SAVE_BGP_SHOW_HOSTNAME)
17257 vty_out(vty, " %sbgp default show-hostname\n",
17258 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
17259 ? ""
17260 : "no ");
17261
17262 /* BGP default show-nexthop-hostname */
17263 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17264 != SAVE_BGP_SHOW_HOSTNAME)
17265 vty_out(vty, " %sbgp default show-nexthop-hostname\n",
17266 CHECK_FLAG(bgp->flags,
17267 BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17268 ? ""
17269 : "no ");
17270
17271 /* BGP default subgroup-pkt-queue-max. */
17272 if (bgp->default_subgroup_pkt_queue_max
17273 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
17274 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
17275 bgp->default_subgroup_pkt_queue_max);
17276
17277 /* BGP client-to-client reflection. */
17278 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
17279 vty_out(vty, " no bgp client-to-client reflection\n");
17280
17281 /* BGP cluster ID. */
17282 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
17283 vty_out(vty, " bgp cluster-id %pI4\n",
17284 &bgp->cluster_id);
17285
17286 /* Disable ebgp connected nexthop check */
17287 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
17288 vty_out(vty,
17289 " bgp disable-ebgp-connected-route-check\n");
17290
17291 /* Confederation identifier*/
17292 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
17293 vty_out(vty, " bgp confederation identifier %u\n",
17294 bgp->confed_id);
17295
17296 /* Confederation peer */
17297 if (bgp->confed_peers_cnt > 0) {
17298 int i;
17299
17300 vty_out(vty, " bgp confederation peers");
17301
17302 for (i = 0; i < bgp->confed_peers_cnt; i++)
17303 vty_out(vty, " %u", bgp->confed_peers[i]);
17304
17305 vty_out(vty, "\n");
17306 }
17307
17308 /* BGP deterministic-med. */
17309 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
17310 != SAVE_BGP_DETERMINISTIC_MED)
17311 vty_out(vty, " %sbgp deterministic-med\n",
17312 CHECK_FLAG(bgp->flags,
17313 BGP_FLAG_DETERMINISTIC_MED)
17314 ? ""
17315 : "no ");
17316
17317 /* BGP update-delay. */
17318 bgp_config_write_update_delay(vty, bgp);
17319
17320 if (bgp->v_maxmed_onstartup
17321 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
17322 vty_out(vty, " bgp max-med on-startup %u",
17323 bgp->v_maxmed_onstartup);
17324 if (bgp->maxmed_onstartup_value
17325 != BGP_MAXMED_VALUE_DEFAULT)
17326 vty_out(vty, " %u",
17327 bgp->maxmed_onstartup_value);
17328 vty_out(vty, "\n");
17329 }
17330 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
17331 vty_out(vty, " bgp max-med administrative");
17332 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
17333 vty_out(vty, " %u", bgp->maxmed_admin_value);
17334 vty_out(vty, "\n");
17335 }
17336
17337 /* write quanta */
17338 bgp_config_write_wpkt_quanta(vty, bgp);
17339 /* read quanta */
17340 bgp_config_write_rpkt_quanta(vty, bgp);
17341
17342 /* coalesce time */
17343 bgp_config_write_coalesce_time(vty, bgp);
17344
17345 /* BGP per-instance graceful-shutdown */
17346 /* BGP-wide settings and per-instance settings are mutually
17347 * exclusive.
17348 */
17349 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17350 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
17351 vty_out(vty, " bgp graceful-shutdown\n");
17352
17353 /* BGP graceful-restart. */
17354 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
17355 vty_out(vty,
17356 " bgp graceful-restart stalepath-time %u\n",
17357 bgp->stalepath_time);
17358
17359 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
17360 vty_out(vty, " bgp graceful-restart restart-time %u\n",
17361 bgp->restart_time);
17362
17363 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
17364 vty_out(vty,
17365 " bgp graceful-restart select-defer-time %u\n",
17366 bgp->select_defer_time);
17367
17368 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
17369 vty_out(vty, " bgp graceful-restart\n");
17370
17371 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
17372 vty_out(vty, " bgp graceful-restart-disable\n");
17373
17374 /* BGP graceful-restart Preserve State F bit. */
17375 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
17376 vty_out(vty,
17377 " bgp graceful-restart preserve-fw-state\n");
17378
17379 /* Stale timer for RIB */
17380 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
17381 vty_out(vty,
17382 " bgp graceful-restart rib-stale-time %u\n",
17383 bgp->rib_stale_time);
17384
17385 /* BGP bestpath method. */
17386 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
17387 vty_out(vty, " bgp bestpath as-path ignore\n");
17388 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
17389 vty_out(vty, " bgp bestpath as-path confed\n");
17390
17391 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
17392 if (CHECK_FLAG(bgp->flags,
17393 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
17394 vty_out(vty,
17395 " bgp bestpath as-path multipath-relax as-set\n");
17396 } else {
17397 vty_out(vty,
17398 " bgp bestpath as-path multipath-relax\n");
17399 }
17400 }
17401
17402 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
17403 vty_out(vty,
17404 " bgp route-reflector allow-outbound-policy\n");
17405 }
17406 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
17407 vty_out(vty, " bgp bestpath compare-routerid\n");
17408 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
17409 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
17410 vty_out(vty, " bgp bestpath med");
17411 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
17412 vty_out(vty, " confed");
17413 if (CHECK_FLAG(bgp->flags,
17414 BGP_FLAG_MED_MISSING_AS_WORST))
17415 vty_out(vty, " missing-as-worst");
17416 vty_out(vty, "\n");
17417 }
17418
17419 /* Link bandwidth handling. */
17420 if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW)
17421 vty_out(vty, " bgp bestpath bandwidth ignore\n");
17422 else if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
17423 vty_out(vty, " bgp bestpath bandwidth skip-missing\n");
17424 else if (bgp->lb_handling == BGP_LINK_BW_DEFWT_4_MISSING)
17425 vty_out(vty, " bgp bestpath bandwidth default-weight-for-missing\n");
17426
17427 /* BGP network import check. */
17428 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
17429 != SAVE_BGP_IMPORT_CHECK)
17430 vty_out(vty, " %sbgp network import-check\n",
17431 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
17432 ? ""
17433 : "no ");
17434
17435 /* BGP timers configuration. */
17436 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
17437 && bgp->default_holdtime != SAVE_BGP_HOLDTIME)
17438 vty_out(vty, " timers bgp %u %u\n",
17439 bgp->default_keepalive, bgp->default_holdtime);
17440
17441 /* peer-group */
17442 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
17443 bgp_config_write_peer_global(vty, bgp, group->conf);
17444 }
17445
17446 /* Normal neighbor configuration. */
17447 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17448 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17449 bgp_config_write_peer_global(vty, bgp, peer);
17450 }
17451
17452 /* listen range and limit for dynamic BGP neighbors */
17453 bgp_config_write_listen(vty, bgp);
17454
17455 /*
17456 * BGP default autoshutdown neighbors
17457 *
17458 * This must be placed after any peer and peer-group
17459 * configuration, to avoid setting all peers to shutdown after
17460 * a daemon restart, which is undesired behavior. (see #2286)
17461 */
17462 if (bgp->autoshutdown)
17463 vty_out(vty, " bgp default shutdown\n");
17464
17465 /* BGP instance administrative shutdown */
17466 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN))
17467 vty_out(vty, " bgp shutdown\n");
17468
17469 /* IPv4 unicast configuration. */
17470 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
17471
17472 /* IPv4 multicast configuration. */
17473 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
17474
17475 /* IPv4 labeled-unicast configuration. */
17476 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
17477
17478 /* IPv4 VPN configuration. */
17479 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
17480
17481 /* ENCAPv4 configuration. */
17482 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
17483
17484 /* FLOWSPEC v4 configuration. */
17485 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
17486
17487 /* IPv6 unicast configuration. */
17488 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
17489
17490 /* IPv6 multicast configuration. */
17491 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
17492
17493 /* IPv6 labeled-unicast configuration. */
17494 bgp_config_write_family(vty, bgp, AFI_IP6,
17495 SAFI_LABELED_UNICAST);
17496
17497 /* IPv6 VPN configuration. */
17498 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
17499
17500 /* ENCAPv6 configuration. */
17501 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
17502
17503 /* FLOWSPEC v6 configuration. */
17504 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
17505
17506 /* EVPN configuration. */
17507 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
17508
17509 hook_call(bgp_inst_config_write, bgp, vty);
17510
17511 #ifdef ENABLE_BGP_VNC
17512 bgp_rfapi_cfg_write(vty, bgp);
17513 #endif
17514
17515 vty_out(vty, "!\n");
17516 }
17517 return 0;
17518 }
17519
17520
17521 /* BGP node structure. */
17522 static struct cmd_node bgp_node = {
17523 .name = "bgp",
17524 .node = BGP_NODE,
17525 .parent_node = CONFIG_NODE,
17526 .prompt = "%s(config-router)# ",
17527 .config_write = bgp_config_write,
17528 };
17529
17530 static struct cmd_node bgp_ipv4_unicast_node = {
17531 .name = "bgp ipv4 unicast",
17532 .node = BGP_IPV4_NODE,
17533 .parent_node = BGP_NODE,
17534 .prompt = "%s(config-router-af)# ",
17535 };
17536
17537 static struct cmd_node bgp_ipv4_multicast_node = {
17538 .name = "bgp ipv4 multicast",
17539 .node = BGP_IPV4M_NODE,
17540 .parent_node = BGP_NODE,
17541 .prompt = "%s(config-router-af)# ",
17542 };
17543
17544 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
17545 .name = "bgp ipv4 labeled unicast",
17546 .node = BGP_IPV4L_NODE,
17547 .parent_node = BGP_NODE,
17548 .prompt = "%s(config-router-af)# ",
17549 };
17550
17551 static struct cmd_node bgp_ipv6_unicast_node = {
17552 .name = "bgp ipv6",
17553 .node = BGP_IPV6_NODE,
17554 .parent_node = BGP_NODE,
17555 .prompt = "%s(config-router-af)# ",
17556 };
17557
17558 static struct cmd_node bgp_ipv6_multicast_node = {
17559 .name = "bgp ipv6 multicast",
17560 .node = BGP_IPV6M_NODE,
17561 .parent_node = BGP_NODE,
17562 .prompt = "%s(config-router-af)# ",
17563 };
17564
17565 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
17566 .name = "bgp ipv6 labeled unicast",
17567 .node = BGP_IPV6L_NODE,
17568 .parent_node = BGP_NODE,
17569 .prompt = "%s(config-router-af)# ",
17570 };
17571
17572 static struct cmd_node bgp_vpnv4_node = {
17573 .name = "bgp vpnv4",
17574 .node = BGP_VPNV4_NODE,
17575 .parent_node = BGP_NODE,
17576 .prompt = "%s(config-router-af)# ",
17577 };
17578
17579 static struct cmd_node bgp_vpnv6_node = {
17580 .name = "bgp vpnv6",
17581 .node = BGP_VPNV6_NODE,
17582 .parent_node = BGP_NODE,
17583 .prompt = "%s(config-router-af-vpnv6)# ",
17584 };
17585
17586 static struct cmd_node bgp_evpn_node = {
17587 .name = "bgp evpn",
17588 .node = BGP_EVPN_NODE,
17589 .parent_node = BGP_NODE,
17590 .prompt = "%s(config-router-evpn)# ",
17591 };
17592
17593 static struct cmd_node bgp_evpn_vni_node = {
17594 .name = "bgp evpn vni",
17595 .node = BGP_EVPN_VNI_NODE,
17596 .parent_node = BGP_EVPN_NODE,
17597 .prompt = "%s(config-router-af-vni)# ",
17598 };
17599
17600 static struct cmd_node bgp_flowspecv4_node = {
17601 .name = "bgp ipv4 flowspec",
17602 .node = BGP_FLOWSPECV4_NODE,
17603 .parent_node = BGP_NODE,
17604 .prompt = "%s(config-router-af)# ",
17605 };
17606
17607 static struct cmd_node bgp_flowspecv6_node = {
17608 .name = "bgp ipv6 flowspec",
17609 .node = BGP_FLOWSPECV6_NODE,
17610 .parent_node = BGP_NODE,
17611 .prompt = "%s(config-router-af-vpnv6)# ",
17612 };
17613
17614 static void community_list_vty(void);
17615
17616 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
17617 {
17618 struct bgp *bgp;
17619 struct peer *peer;
17620 struct listnode *lnbgp, *lnpeer;
17621
17622 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
17623 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
17624 /* only provide suggestions on the appropriate input
17625 * token type,
17626 * they'll otherwise show up multiple times */
17627 enum cmd_token_type match_type;
17628 char *name = peer->host;
17629
17630 if (peer->conf_if) {
17631 match_type = VARIABLE_TKN;
17632 name = peer->conf_if;
17633 } else if (strchr(peer->host, ':'))
17634 match_type = IPV6_TKN;
17635 else
17636 match_type = IPV4_TKN;
17637
17638 if (token->type != match_type)
17639 continue;
17640
17641 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
17642 }
17643 }
17644 }
17645
17646 static const struct cmd_variable_handler bgp_var_neighbor[] = {
17647 {.varname = "neighbor", .completions = bgp_ac_neighbor},
17648 {.varname = "neighbors", .completions = bgp_ac_neighbor},
17649 {.varname = "peer", .completions = bgp_ac_neighbor},
17650 {.completions = NULL}};
17651
17652 static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
17653 {
17654 struct bgp *bgp;
17655 struct peer_group *group;
17656 struct listnode *lnbgp, *lnpeer;
17657
17658 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
17659 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
17660 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
17661 group->name));
17662 }
17663 }
17664
17665 static const struct cmd_variable_handler bgp_var_peergroup[] = {
17666 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
17667 {.completions = NULL} };
17668
17669 void bgp_vty_init(void)
17670 {
17671 cmd_variable_handler_register(bgp_var_neighbor);
17672 cmd_variable_handler_register(bgp_var_peergroup);
17673
17674 /* Install bgp top node. */
17675 install_node(&bgp_node);
17676 install_node(&bgp_ipv4_unicast_node);
17677 install_node(&bgp_ipv4_multicast_node);
17678 install_node(&bgp_ipv4_labeled_unicast_node);
17679 install_node(&bgp_ipv6_unicast_node);
17680 install_node(&bgp_ipv6_multicast_node);
17681 install_node(&bgp_ipv6_labeled_unicast_node);
17682 install_node(&bgp_vpnv4_node);
17683 install_node(&bgp_vpnv6_node);
17684 install_node(&bgp_evpn_node);
17685 install_node(&bgp_evpn_vni_node);
17686 install_node(&bgp_flowspecv4_node);
17687 install_node(&bgp_flowspecv6_node);
17688
17689 /* Install default VTY commands to new nodes. */
17690 install_default(BGP_NODE);
17691 install_default(BGP_IPV4_NODE);
17692 install_default(BGP_IPV4M_NODE);
17693 install_default(BGP_IPV4L_NODE);
17694 install_default(BGP_IPV6_NODE);
17695 install_default(BGP_IPV6M_NODE);
17696 install_default(BGP_IPV6L_NODE);
17697 install_default(BGP_VPNV4_NODE);
17698 install_default(BGP_VPNV6_NODE);
17699 install_default(BGP_FLOWSPECV4_NODE);
17700 install_default(BGP_FLOWSPECV6_NODE);
17701 install_default(BGP_EVPN_NODE);
17702 install_default(BGP_EVPN_VNI_NODE);
17703
17704 /* "bgp local-mac" hidden commands. */
17705 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
17706 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
17707
17708 /* "bgp suppress-fib-pending" global */
17709 install_element(CONFIG_NODE, &bgp_global_suppress_fib_pending_cmd);
17710
17711 /* bgp route-map delay-timer commands. */
17712 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
17713 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
17714
17715 /* global bgp update-delay command */
17716 install_element(CONFIG_NODE, &bgp_global_update_delay_cmd);
17717 install_element(CONFIG_NODE, &no_bgp_global_update_delay_cmd);
17718
17719 /* global bgp graceful-shutdown command */
17720 install_element(CONFIG_NODE, &bgp_graceful_shutdown_cmd);
17721 install_element(CONFIG_NODE, &no_bgp_graceful_shutdown_cmd);
17722
17723 /* Dummy commands (Currently not supported) */
17724 install_element(BGP_NODE, &no_synchronization_cmd);
17725 install_element(BGP_NODE, &no_auto_summary_cmd);
17726
17727 /* "router bgp" commands. */
17728 install_element(CONFIG_NODE, &router_bgp_cmd);
17729
17730 /* "no router bgp" commands. */
17731 install_element(CONFIG_NODE, &no_router_bgp_cmd);
17732
17733 /* "bgp router-id" commands. */
17734 install_element(BGP_NODE, &bgp_router_id_cmd);
17735 install_element(BGP_NODE, &no_bgp_router_id_cmd);
17736
17737 /* "bgp suppress-fib-pending" command */
17738 install_element(BGP_NODE, &bgp_suppress_fib_pending_cmd);
17739
17740 /* "bgp cluster-id" commands. */
17741 install_element(BGP_NODE, &bgp_cluster_id_cmd);
17742 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
17743
17744 /* "bgp no-rib" commands. */
17745 install_element(CONFIG_NODE, &bgp_norib_cmd);
17746 install_element(CONFIG_NODE, &no_bgp_norib_cmd);
17747
17748 install_element(CONFIG_NODE, &no_bgp_send_extra_data_cmd);
17749
17750 /* "bgp confederation" commands. */
17751 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
17752 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
17753
17754 /* "bgp confederation peers" commands. */
17755 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
17756 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
17757
17758 /* bgp max-med command */
17759 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
17760 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
17761 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
17762 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
17763 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
17764
17765 /* bgp disable-ebgp-connected-nh-check */
17766 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
17767 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
17768
17769 /* bgp update-delay command */
17770 install_element(BGP_NODE, &bgp_update_delay_cmd);
17771 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
17772
17773 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
17774 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
17775
17776 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
17777 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
17778
17779 /* "maximum-paths" commands. */
17780 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
17781 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
17782 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
17783 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
17784 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
17785 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
17786 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
17787 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
17788 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
17789 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
17790 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17791 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
17792 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
17793 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17794 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
17795
17796 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_cmd);
17797 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_cmd);
17798 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cmd);
17799 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17800 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_ibgp_cmd);
17801 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
17802 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
17803 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
17804 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17805 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
17806
17807 /* "timers bgp" commands. */
17808 install_element(BGP_NODE, &bgp_timers_cmd);
17809 install_element(BGP_NODE, &no_bgp_timers_cmd);
17810
17811 /* route-map delay-timer commands - per instance for backwards compat.
17812 */
17813 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
17814 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
17815
17816 /* "bgp client-to-client reflection" commands */
17817 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
17818 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
17819
17820 /* "bgp always-compare-med" commands */
17821 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
17822 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
17823
17824 /* bgp ebgp-requires-policy */
17825 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
17826 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
17827
17828 /* bgp suppress-duplicates */
17829 install_element(BGP_NODE, &bgp_suppress_duplicates_cmd);
17830 install_element(BGP_NODE, &no_bgp_suppress_duplicates_cmd);
17831
17832 /* bgp reject-as-sets */
17833 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
17834 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
17835
17836 /* "bgp deterministic-med" commands */
17837 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
17838 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
17839
17840 /* "bgp graceful-restart" command */
17841 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
17842 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
17843
17844 /* "bgp graceful-restart-disable" command */
17845 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
17846 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
17847
17848 /* "neighbor a:b:c:d graceful-restart" command */
17849 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
17850 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
17851
17852 /* "neighbor a:b:c:d graceful-restart-disable" command */
17853 install_element(BGP_NODE,
17854 &bgp_neighbor_graceful_restart_disable_set_cmd);
17855 install_element(BGP_NODE,
17856 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
17857
17858 /* "neighbor a:b:c:d graceful-restart-helper" command */
17859 install_element(BGP_NODE,
17860 &bgp_neighbor_graceful_restart_helper_set_cmd);
17861 install_element(BGP_NODE,
17862 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
17863
17864 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
17865 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
17866 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
17867 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
17868 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
17869 install_element(BGP_NODE,
17870 &no_bgp_graceful_restart_select_defer_time_cmd);
17871 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
17872 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
17873
17874 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
17875 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
17876 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
17877 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
17878
17879 /* "bgp graceful-shutdown" commands */
17880 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
17881 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
17882
17883 /* "bgp fast-external-failover" commands */
17884 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
17885 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
17886
17887 /* "bgp bestpath compare-routerid" commands */
17888 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
17889 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
17890
17891 /* "bgp bestpath as-path ignore" commands */
17892 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
17893 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
17894
17895 /* "bgp bestpath as-path confed" commands */
17896 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
17897 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
17898
17899 /* "bgp bestpath as-path multipath-relax" commands */
17900 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
17901 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
17902
17903 /* "bgp log-neighbor-changes" commands */
17904 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
17905 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
17906
17907 /* "bgp bestpath med" commands */
17908 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
17909 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
17910
17911 /* "bgp bestpath bandwidth" commands */
17912 install_element(BGP_NODE, &bgp_bestpath_bw_cmd);
17913 install_element(BGP_NODE, &no_bgp_bestpath_bw_cmd);
17914
17915 /* "no bgp default ipv4-unicast" commands. */
17916 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
17917 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
17918
17919 /* "bgp network import-check" commands. */
17920 install_element(BGP_NODE, &bgp_network_import_check_cmd);
17921 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
17922 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
17923
17924 /* "bgp default local-preference" commands. */
17925 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
17926 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
17927
17928 /* bgp default show-hostname */
17929 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
17930 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
17931
17932 /* bgp default show-nexthop-hostname */
17933 install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
17934 install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
17935
17936 /* "bgp default subgroup-pkt-queue-max" commands. */
17937 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
17938 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
17939
17940 /* bgp ibgp-allow-policy-mods command */
17941 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
17942 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
17943
17944 /* "bgp listen limit" commands. */
17945 install_element(BGP_NODE, &bgp_listen_limit_cmd);
17946 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
17947
17948 /* "bgp listen range" commands. */
17949 install_element(BGP_NODE, &bgp_listen_range_cmd);
17950 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
17951
17952 /* "bgp default shutdown" command */
17953 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
17954
17955 /* "bgp shutdown" commands */
17956 install_element(BGP_NODE, &bgp_shutdown_cmd);
17957 install_element(BGP_NODE, &bgp_shutdown_msg_cmd);
17958 install_element(BGP_NODE, &no_bgp_shutdown_cmd);
17959 install_element(BGP_NODE, &no_bgp_shutdown_msg_cmd);
17960
17961 /* "neighbor remote-as" commands. */
17962 install_element(BGP_NODE, &neighbor_remote_as_cmd);
17963 install_element(BGP_NODE, &neighbor_interface_config_cmd);
17964 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
17965 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
17966 install_element(BGP_NODE,
17967 &neighbor_interface_v6only_config_remote_as_cmd);
17968 install_element(BGP_NODE, &no_neighbor_cmd);
17969 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
17970
17971 /* "neighbor peer-group" commands. */
17972 install_element(BGP_NODE, &neighbor_peer_group_cmd);
17973 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
17974 install_element(BGP_NODE,
17975 &no_neighbor_interface_peer_group_remote_as_cmd);
17976
17977 /* "neighbor local-as" commands. */
17978 install_element(BGP_NODE, &neighbor_local_as_cmd);
17979 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
17980 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
17981 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
17982
17983 /* "neighbor solo" commands. */
17984 install_element(BGP_NODE, &neighbor_solo_cmd);
17985 install_element(BGP_NODE, &no_neighbor_solo_cmd);
17986
17987 /* "neighbor password" commands. */
17988 install_element(BGP_NODE, &neighbor_password_cmd);
17989 install_element(BGP_NODE, &no_neighbor_password_cmd);
17990
17991 /* "neighbor activate" commands. */
17992 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
17993 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
17994 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
17995 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
17996 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
17997 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
17998 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
17999 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
18000 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
18001 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
18002 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
18003 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
18004
18005 /* "no neighbor activate" commands. */
18006 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
18007 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
18008 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
18009 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
18010 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
18011 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
18012 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
18013 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
18014 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
18015 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
18016 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
18017 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
18018
18019 /* "neighbor peer-group" set commands. */
18020 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
18021 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
18022 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
18023 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
18024 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
18025 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
18026 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
18027 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
18028 install_element(BGP_FLOWSPECV4_NODE,
18029 &neighbor_set_peer_group_hidden_cmd);
18030 install_element(BGP_FLOWSPECV6_NODE,
18031 &neighbor_set_peer_group_hidden_cmd);
18032
18033 /* "no neighbor peer-group unset" commands. */
18034 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
18035 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18036 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18037 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18038 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18039 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18040 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18041 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18042 install_element(BGP_FLOWSPECV4_NODE,
18043 &no_neighbor_set_peer_group_hidden_cmd);
18044 install_element(BGP_FLOWSPECV6_NODE,
18045 &no_neighbor_set_peer_group_hidden_cmd);
18046
18047 /* "neighbor softreconfiguration inbound" commands.*/
18048 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
18049 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
18050 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
18051 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
18052 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
18053 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
18054 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
18055 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
18056 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
18057 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
18058 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
18059 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
18060 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
18061 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
18062 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
18063 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
18064 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
18065 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
18066 install_element(BGP_FLOWSPECV4_NODE,
18067 &neighbor_soft_reconfiguration_cmd);
18068 install_element(BGP_FLOWSPECV4_NODE,
18069 &no_neighbor_soft_reconfiguration_cmd);
18070 install_element(BGP_FLOWSPECV6_NODE,
18071 &neighbor_soft_reconfiguration_cmd);
18072 install_element(BGP_FLOWSPECV6_NODE,
18073 &no_neighbor_soft_reconfiguration_cmd);
18074 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
18075 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
18076
18077 /* "neighbor attribute-unchanged" commands. */
18078 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
18079 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
18080 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
18081 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
18082 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
18083 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
18084 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
18085 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
18086 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
18087 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
18088 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
18089 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
18090 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
18091 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
18092 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
18093 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
18094 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
18095 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
18096
18097 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
18098 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
18099
18100 /* "nexthop-local unchanged" commands */
18101 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
18102 install_element(BGP_IPV6_NODE,
18103 &no_neighbor_nexthop_local_unchanged_cmd);
18104
18105 /* "neighbor next-hop-self" commands. */
18106 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
18107 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
18108 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
18109 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
18110 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
18111 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
18112 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
18113 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
18114 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
18115 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
18116 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
18117 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
18118 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
18119 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
18120 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
18121 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
18122 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
18123 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
18124 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
18125 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
18126
18127 /* "neighbor next-hop-self force" commands. */
18128 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
18129 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
18130 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18131 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
18132 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
18133 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
18134 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18135 install_element(BGP_IPV4_NODE,
18136 &no_neighbor_nexthop_self_all_hidden_cmd);
18137 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
18138 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
18139 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18140 install_element(BGP_IPV4M_NODE,
18141 &no_neighbor_nexthop_self_all_hidden_cmd);
18142 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
18143 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
18144 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18145 install_element(BGP_IPV4L_NODE,
18146 &no_neighbor_nexthop_self_all_hidden_cmd);
18147 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
18148 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
18149 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18150 install_element(BGP_IPV6_NODE,
18151 &no_neighbor_nexthop_self_all_hidden_cmd);
18152 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
18153 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
18154 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18155 install_element(BGP_IPV6M_NODE,
18156 &no_neighbor_nexthop_self_all_hidden_cmd);
18157 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
18158 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
18159 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18160 install_element(BGP_IPV6L_NODE,
18161 &no_neighbor_nexthop_self_all_hidden_cmd);
18162 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
18163 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
18164 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18165 install_element(BGP_VPNV4_NODE,
18166 &no_neighbor_nexthop_self_all_hidden_cmd);
18167 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
18168 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
18169 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18170 install_element(BGP_VPNV6_NODE,
18171 &no_neighbor_nexthop_self_all_hidden_cmd);
18172 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_force_cmd);
18173 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_force_cmd);
18174
18175 /* "neighbor as-override" commands. */
18176 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
18177 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
18178 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
18179 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
18180 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
18181 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
18182 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
18183 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
18184 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
18185 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
18186 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
18187 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
18188 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
18189 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
18190 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
18191 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
18192 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
18193 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
18194
18195 /* "neighbor remove-private-AS" commands. */
18196 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
18197 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
18198 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
18199 install_element(BGP_NODE,
18200 &no_neighbor_remove_private_as_all_hidden_cmd);
18201 install_element(BGP_NODE,
18202 &neighbor_remove_private_as_replace_as_hidden_cmd);
18203 install_element(BGP_NODE,
18204 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
18205 install_element(BGP_NODE,
18206 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
18207 install_element(
18208 BGP_NODE,
18209 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
18210 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
18211 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
18212 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
18213 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18214 install_element(BGP_IPV4_NODE,
18215 &neighbor_remove_private_as_replace_as_cmd);
18216 install_element(BGP_IPV4_NODE,
18217 &no_neighbor_remove_private_as_replace_as_cmd);
18218 install_element(BGP_IPV4_NODE,
18219 &neighbor_remove_private_as_all_replace_as_cmd);
18220 install_element(BGP_IPV4_NODE,
18221 &no_neighbor_remove_private_as_all_replace_as_cmd);
18222 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
18223 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
18224 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
18225 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
18226 install_element(BGP_IPV4M_NODE,
18227 &neighbor_remove_private_as_replace_as_cmd);
18228 install_element(BGP_IPV4M_NODE,
18229 &no_neighbor_remove_private_as_replace_as_cmd);
18230 install_element(BGP_IPV4M_NODE,
18231 &neighbor_remove_private_as_all_replace_as_cmd);
18232 install_element(BGP_IPV4M_NODE,
18233 &no_neighbor_remove_private_as_all_replace_as_cmd);
18234 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
18235 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
18236 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
18237 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
18238 install_element(BGP_IPV4L_NODE,
18239 &neighbor_remove_private_as_replace_as_cmd);
18240 install_element(BGP_IPV4L_NODE,
18241 &no_neighbor_remove_private_as_replace_as_cmd);
18242 install_element(BGP_IPV4L_NODE,
18243 &neighbor_remove_private_as_all_replace_as_cmd);
18244 install_element(BGP_IPV4L_NODE,
18245 &no_neighbor_remove_private_as_all_replace_as_cmd);
18246 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
18247 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
18248 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
18249 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18250 install_element(BGP_IPV6_NODE,
18251 &neighbor_remove_private_as_replace_as_cmd);
18252 install_element(BGP_IPV6_NODE,
18253 &no_neighbor_remove_private_as_replace_as_cmd);
18254 install_element(BGP_IPV6_NODE,
18255 &neighbor_remove_private_as_all_replace_as_cmd);
18256 install_element(BGP_IPV6_NODE,
18257 &no_neighbor_remove_private_as_all_replace_as_cmd);
18258 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
18259 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
18260 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
18261 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
18262 install_element(BGP_IPV6M_NODE,
18263 &neighbor_remove_private_as_replace_as_cmd);
18264 install_element(BGP_IPV6M_NODE,
18265 &no_neighbor_remove_private_as_replace_as_cmd);
18266 install_element(BGP_IPV6M_NODE,
18267 &neighbor_remove_private_as_all_replace_as_cmd);
18268 install_element(BGP_IPV6M_NODE,
18269 &no_neighbor_remove_private_as_all_replace_as_cmd);
18270 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
18271 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
18272 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
18273 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
18274 install_element(BGP_IPV6L_NODE,
18275 &neighbor_remove_private_as_replace_as_cmd);
18276 install_element(BGP_IPV6L_NODE,
18277 &no_neighbor_remove_private_as_replace_as_cmd);
18278 install_element(BGP_IPV6L_NODE,
18279 &neighbor_remove_private_as_all_replace_as_cmd);
18280 install_element(BGP_IPV6L_NODE,
18281 &no_neighbor_remove_private_as_all_replace_as_cmd);
18282 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
18283 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
18284 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
18285 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18286 install_element(BGP_VPNV4_NODE,
18287 &neighbor_remove_private_as_replace_as_cmd);
18288 install_element(BGP_VPNV4_NODE,
18289 &no_neighbor_remove_private_as_replace_as_cmd);
18290 install_element(BGP_VPNV4_NODE,
18291 &neighbor_remove_private_as_all_replace_as_cmd);
18292 install_element(BGP_VPNV4_NODE,
18293 &no_neighbor_remove_private_as_all_replace_as_cmd);
18294 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
18295 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
18296 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
18297 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18298 install_element(BGP_VPNV6_NODE,
18299 &neighbor_remove_private_as_replace_as_cmd);
18300 install_element(BGP_VPNV6_NODE,
18301 &no_neighbor_remove_private_as_replace_as_cmd);
18302 install_element(BGP_VPNV6_NODE,
18303 &neighbor_remove_private_as_all_replace_as_cmd);
18304 install_element(BGP_VPNV6_NODE,
18305 &no_neighbor_remove_private_as_all_replace_as_cmd);
18306
18307 /* "neighbor send-community" commands.*/
18308 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
18309 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
18310 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
18311 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
18312 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
18313 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
18314 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
18315 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
18316 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
18317 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
18318 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
18319 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
18320 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
18321 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
18322 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
18323 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
18324 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
18325 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
18326 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
18327 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
18328 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
18329 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
18330 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
18331 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
18332 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
18333 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
18334 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
18335 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
18336 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
18337 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
18338 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
18339 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
18340 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
18341 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
18342 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
18343 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
18344
18345 /* "neighbor route-reflector" commands.*/
18346 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
18347 install_element(BGP_NODE,
18348 &no_neighbor_route_reflector_client_hidden_cmd);
18349 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
18350 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
18351 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
18352 install_element(BGP_IPV4M_NODE,
18353 &no_neighbor_route_reflector_client_cmd);
18354 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
18355 install_element(BGP_IPV4L_NODE,
18356 &no_neighbor_route_reflector_client_cmd);
18357 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
18358 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
18359 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
18360 install_element(BGP_IPV6M_NODE,
18361 &no_neighbor_route_reflector_client_cmd);
18362 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
18363 install_element(BGP_IPV6L_NODE,
18364 &no_neighbor_route_reflector_client_cmd);
18365 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
18366 install_element(BGP_VPNV4_NODE,
18367 &no_neighbor_route_reflector_client_cmd);
18368 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
18369 install_element(BGP_VPNV6_NODE,
18370 &no_neighbor_route_reflector_client_cmd);
18371 install_element(BGP_FLOWSPECV4_NODE,
18372 &neighbor_route_reflector_client_cmd);
18373 install_element(BGP_FLOWSPECV4_NODE,
18374 &no_neighbor_route_reflector_client_cmd);
18375 install_element(BGP_FLOWSPECV6_NODE,
18376 &neighbor_route_reflector_client_cmd);
18377 install_element(BGP_FLOWSPECV6_NODE,
18378 &no_neighbor_route_reflector_client_cmd);
18379 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
18380 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
18381
18382 /* "neighbor route-server" commands.*/
18383 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
18384 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
18385 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
18386 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
18387 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
18388 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
18389 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
18390 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
18391 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
18392 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
18393 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
18394 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
18395 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
18396 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
18397 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
18398 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
18399 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
18400 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
18401 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
18402 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
18403 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
18404 install_element(BGP_FLOWSPECV4_NODE,
18405 &no_neighbor_route_server_client_cmd);
18406 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
18407 install_element(BGP_FLOWSPECV6_NODE,
18408 &no_neighbor_route_server_client_cmd);
18409
18410 /* "neighbor addpath-tx-all-paths" commands.*/
18411 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
18412 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
18413 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
18414 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18415 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
18416 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18417 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
18418 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18419 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
18420 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18421 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
18422 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18423 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
18424 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18425 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
18426 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18427 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
18428 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18429
18430 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
18431 install_element(BGP_NODE,
18432 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
18433 install_element(BGP_NODE,
18434 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
18435 install_element(BGP_IPV4_NODE,
18436 &neighbor_addpath_tx_bestpath_per_as_cmd);
18437 install_element(BGP_IPV4_NODE,
18438 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18439 install_element(BGP_IPV4M_NODE,
18440 &neighbor_addpath_tx_bestpath_per_as_cmd);
18441 install_element(BGP_IPV4M_NODE,
18442 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18443 install_element(BGP_IPV4L_NODE,
18444 &neighbor_addpath_tx_bestpath_per_as_cmd);
18445 install_element(BGP_IPV4L_NODE,
18446 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18447 install_element(BGP_IPV6_NODE,
18448 &neighbor_addpath_tx_bestpath_per_as_cmd);
18449 install_element(BGP_IPV6_NODE,
18450 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18451 install_element(BGP_IPV6M_NODE,
18452 &neighbor_addpath_tx_bestpath_per_as_cmd);
18453 install_element(BGP_IPV6M_NODE,
18454 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18455 install_element(BGP_IPV6L_NODE,
18456 &neighbor_addpath_tx_bestpath_per_as_cmd);
18457 install_element(BGP_IPV6L_NODE,
18458 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18459 install_element(BGP_VPNV4_NODE,
18460 &neighbor_addpath_tx_bestpath_per_as_cmd);
18461 install_element(BGP_VPNV4_NODE,
18462 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18463 install_element(BGP_VPNV6_NODE,
18464 &neighbor_addpath_tx_bestpath_per_as_cmd);
18465 install_element(BGP_VPNV6_NODE,
18466 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18467
18468 /* "neighbor sender-as-path-loop-detection" commands. */
18469 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
18470 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
18471
18472 /* "neighbor passive" commands. */
18473 install_element(BGP_NODE, &neighbor_passive_cmd);
18474 install_element(BGP_NODE, &no_neighbor_passive_cmd);
18475
18476
18477 /* "neighbor shutdown" commands. */
18478 install_element(BGP_NODE, &neighbor_shutdown_cmd);
18479 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
18480 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
18481 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
18482 install_element(BGP_NODE, &neighbor_shutdown_rtt_cmd);
18483 install_element(BGP_NODE, &no_neighbor_shutdown_rtt_cmd);
18484
18485 /* "neighbor capability extended-nexthop" commands.*/
18486 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
18487 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
18488
18489 /* "neighbor capability orf prefix-list" commands.*/
18490 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
18491 install_element(BGP_NODE,
18492 &no_neighbor_capability_orf_prefix_hidden_cmd);
18493 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
18494 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
18495 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
18496 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
18497 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
18498 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
18499 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
18500 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
18501 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
18502 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
18503 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
18504 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
18505
18506 /* "neighbor capability dynamic" commands.*/
18507 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
18508 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
18509
18510 /* "neighbor dont-capability-negotiate" commands. */
18511 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
18512 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
18513
18514 /* "neighbor ebgp-multihop" commands. */
18515 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
18516 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
18517 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
18518
18519 /* "neighbor disable-connected-check" commands. */
18520 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
18521 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
18522
18523 /* "neighbor enforce-first-as" commands. */
18524 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
18525 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
18526
18527 /* "neighbor description" commands. */
18528 install_element(BGP_NODE, &neighbor_description_cmd);
18529 install_element(BGP_NODE, &no_neighbor_description_cmd);
18530 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
18531
18532 /* "neighbor update-source" commands. "*/
18533 install_element(BGP_NODE, &neighbor_update_source_cmd);
18534 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
18535
18536 /* "neighbor default-originate" commands. */
18537 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
18538 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
18539 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
18540 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
18541 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
18542 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
18543 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
18544 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
18545 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
18546 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
18547 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
18548 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
18549 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
18550 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
18551 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
18552 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
18553 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
18554 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
18555 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
18556 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
18557 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
18558
18559 /* "neighbor port" commands. */
18560 install_element(BGP_NODE, &neighbor_port_cmd);
18561 install_element(BGP_NODE, &no_neighbor_port_cmd);
18562
18563 /* "neighbor weight" commands. */
18564 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
18565 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
18566
18567 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
18568 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
18569 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
18570 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
18571 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
18572 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
18573 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
18574 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
18575 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
18576 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
18577 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
18578 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
18579 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
18580 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
18581 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
18582 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
18583
18584 /* "neighbor override-capability" commands. */
18585 install_element(BGP_NODE, &neighbor_override_capability_cmd);
18586 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
18587
18588 /* "neighbor strict-capability-match" commands. */
18589 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
18590 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
18591
18592 /* "neighbor timers" commands. */
18593 install_element(BGP_NODE, &neighbor_timers_cmd);
18594 install_element(BGP_NODE, &no_neighbor_timers_cmd);
18595
18596 /* "neighbor timers connect" commands. */
18597 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
18598 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
18599
18600 /* "neighbor timers delayopen" commands. */
18601 install_element(BGP_NODE, &neighbor_timers_delayopen_cmd);
18602 install_element(BGP_NODE, &no_neighbor_timers_delayopen_cmd);
18603
18604 /* "neighbor advertisement-interval" commands. */
18605 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
18606 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
18607
18608 /* "neighbor interface" commands. */
18609 install_element(BGP_NODE, &neighbor_interface_cmd);
18610 install_element(BGP_NODE, &no_neighbor_interface_cmd);
18611
18612 /* "neighbor distribute" commands. */
18613 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
18614 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
18615 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
18616 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
18617 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
18618 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
18619 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
18620 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
18621 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
18622 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
18623 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
18624 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
18625 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
18626 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
18627 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
18628 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
18629 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
18630 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
18631
18632 /* "neighbor prefix-list" commands. */
18633 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
18634 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
18635 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
18636 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
18637 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
18638 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
18639 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
18640 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
18641 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
18642 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
18643 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
18644 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
18645 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
18646 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
18647 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
18648 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
18649 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
18650 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
18651 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
18652 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
18653 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
18654 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
18655
18656 /* "neighbor filter-list" commands. */
18657 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
18658 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
18659 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
18660 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
18661 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
18662 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
18663 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
18664 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
18665 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
18666 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
18667 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
18668 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
18669 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
18670 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
18671 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
18672 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
18673 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
18674 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
18675 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
18676 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
18677 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
18678 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
18679
18680 /* "neighbor route-map" commands. */
18681 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
18682 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
18683 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
18684 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
18685 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
18686 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
18687 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
18688 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
18689 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
18690 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
18691 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
18692 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
18693 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
18694 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
18695 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
18696 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
18697 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
18698 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
18699 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
18700 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
18701 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
18702 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
18703 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
18704 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
18705
18706 /* "neighbor unsuppress-map" commands. */
18707 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
18708 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
18709 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
18710 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
18711 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
18712 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
18713 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
18714 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
18715 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
18716 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
18717 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
18718 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
18719 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
18720 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
18721 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
18722 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
18723 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
18724 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
18725
18726 /* "neighbor advertise-map" commands. */
18727 install_element(BGP_NODE, &neighbor_advertise_map_hidden_cmd);
18728 install_element(BGP_IPV4_NODE, &neighbor_advertise_map_cmd);
18729 install_element(BGP_IPV4M_NODE, &neighbor_advertise_map_cmd);
18730 install_element(BGP_IPV4L_NODE, &neighbor_advertise_map_cmd);
18731 install_element(BGP_IPV6_NODE, &neighbor_advertise_map_cmd);
18732 install_element(BGP_IPV6M_NODE, &neighbor_advertise_map_cmd);
18733 install_element(BGP_IPV6L_NODE, &neighbor_advertise_map_cmd);
18734 install_element(BGP_VPNV4_NODE, &neighbor_advertise_map_cmd);
18735 install_element(BGP_VPNV6_NODE, &neighbor_advertise_map_cmd);
18736
18737 /* neighbor maximum-prefix-out commands. */
18738 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
18739 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
18740 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
18741 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
18742 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
18743 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
18744 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
18745 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
18746 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
18747 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
18748 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
18749 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
18750 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
18751 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
18752 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
18753 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
18754 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
18755 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
18756
18757 /* "neighbor maximum-prefix" commands. */
18758 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
18759 install_element(BGP_NODE,
18760 &neighbor_maximum_prefix_threshold_hidden_cmd);
18761 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
18762 install_element(BGP_NODE,
18763 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
18764 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
18765 install_element(BGP_NODE,
18766 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
18767 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
18768 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
18769 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
18770 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
18771 install_element(BGP_IPV4_NODE,
18772 &neighbor_maximum_prefix_threshold_warning_cmd);
18773 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
18774 install_element(BGP_IPV4_NODE,
18775 &neighbor_maximum_prefix_threshold_restart_cmd);
18776 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
18777 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
18778 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
18779 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
18780 install_element(BGP_IPV4M_NODE,
18781 &neighbor_maximum_prefix_threshold_warning_cmd);
18782 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
18783 install_element(BGP_IPV4M_NODE,
18784 &neighbor_maximum_prefix_threshold_restart_cmd);
18785 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
18786 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
18787 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
18788 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
18789 install_element(BGP_IPV4L_NODE,
18790 &neighbor_maximum_prefix_threshold_warning_cmd);
18791 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
18792 install_element(BGP_IPV4L_NODE,
18793 &neighbor_maximum_prefix_threshold_restart_cmd);
18794 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
18795 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
18796 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
18797 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
18798 install_element(BGP_IPV6_NODE,
18799 &neighbor_maximum_prefix_threshold_warning_cmd);
18800 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
18801 install_element(BGP_IPV6_NODE,
18802 &neighbor_maximum_prefix_threshold_restart_cmd);
18803 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
18804 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
18805 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
18806 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
18807 install_element(BGP_IPV6M_NODE,
18808 &neighbor_maximum_prefix_threshold_warning_cmd);
18809 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
18810 install_element(BGP_IPV6M_NODE,
18811 &neighbor_maximum_prefix_threshold_restart_cmd);
18812 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
18813 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
18814 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
18815 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
18816 install_element(BGP_IPV6L_NODE,
18817 &neighbor_maximum_prefix_threshold_warning_cmd);
18818 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
18819 install_element(BGP_IPV6L_NODE,
18820 &neighbor_maximum_prefix_threshold_restart_cmd);
18821 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
18822 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
18823 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
18824 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
18825 install_element(BGP_VPNV4_NODE,
18826 &neighbor_maximum_prefix_threshold_warning_cmd);
18827 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
18828 install_element(BGP_VPNV4_NODE,
18829 &neighbor_maximum_prefix_threshold_restart_cmd);
18830 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
18831 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
18832 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
18833 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
18834 install_element(BGP_VPNV6_NODE,
18835 &neighbor_maximum_prefix_threshold_warning_cmd);
18836 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
18837 install_element(BGP_VPNV6_NODE,
18838 &neighbor_maximum_prefix_threshold_restart_cmd);
18839 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
18840
18841 /* "neighbor allowas-in" */
18842 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
18843 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
18844 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
18845 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
18846 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
18847 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
18848 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
18849 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
18850 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
18851 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
18852 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
18853 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
18854 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
18855 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
18856 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
18857 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
18858 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
18859 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
18860 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
18861 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
18862
18863 /* "neighbor dampening" commands. */
18864 install_element(BGP_NODE, &neighbor_damp_cmd);
18865 install_element(BGP_NODE, &no_neighbor_damp_cmd);
18866 install_element(BGP_IPV4_NODE, &neighbor_damp_cmd);
18867 install_element(BGP_IPV4_NODE, &no_neighbor_damp_cmd);
18868 install_element(BGP_IPV4M_NODE, &neighbor_damp_cmd);
18869 install_element(BGP_IPV4M_NODE, &no_neighbor_damp_cmd);
18870 install_element(BGP_IPV4L_NODE, &neighbor_damp_cmd);
18871 install_element(BGP_IPV4L_NODE, &no_neighbor_damp_cmd);
18872 install_element(BGP_IPV6_NODE, &neighbor_damp_cmd);
18873 install_element(BGP_IPV6_NODE, &no_neighbor_damp_cmd);
18874 install_element(BGP_IPV6M_NODE, &neighbor_damp_cmd);
18875 install_element(BGP_IPV6M_NODE, &no_neighbor_damp_cmd);
18876 install_element(BGP_IPV6L_NODE, &neighbor_damp_cmd);
18877 install_element(BGP_IPV6L_NODE, &no_neighbor_damp_cmd);
18878 install_element(VIEW_NODE, &show_ip_bgp_neighbor_damp_param_cmd);
18879
18880 /* address-family commands. */
18881 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
18882 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
18883 #ifdef KEEP_OLD_VPN_COMMANDS
18884 install_element(BGP_NODE, &address_family_vpnv4_cmd);
18885 install_element(BGP_NODE, &address_family_vpnv6_cmd);
18886 #endif /* KEEP_OLD_VPN_COMMANDS */
18887
18888 install_element(BGP_NODE, &address_family_evpn_cmd);
18889
18890 /* "exit-address-family" command. */
18891 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
18892 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
18893 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
18894 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
18895 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
18896 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
18897 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
18898 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
18899 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
18900 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
18901 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
18902
18903 /* "clear ip bgp commands" */
18904 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
18905
18906 /* clear ip bgp prefix */
18907 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
18908 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
18909 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
18910
18911 /* "show [ip] bgp summary" commands. */
18912 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
18913 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
18914 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
18915 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
18916 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
18917 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
18918 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
18919
18920 /* "show [ip] bgp neighbors" commands. */
18921 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
18922
18923 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
18924
18925 /* "show [ip] bgp peer-group" commands. */
18926 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
18927
18928 /* "show [ip] bgp paths" commands. */
18929 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
18930
18931 /* "show [ip] bgp community" commands. */
18932 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
18933
18934 /* "show ip bgp large-community" commands. */
18935 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
18936 /* "show [ip] bgp attribute-info" commands. */
18937 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
18938 /* "show [ip] bgp route-leak" command */
18939 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
18940
18941 /* "redistribute" commands. */
18942 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
18943 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
18944 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
18945 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
18946 install_element(BGP_NODE,
18947 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
18948 install_element(BGP_NODE,
18949 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
18950 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
18951 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
18952 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
18953 install_element(BGP_NODE,
18954 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
18955 install_element(BGP_NODE,
18956 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
18957 install_element(BGP_NODE,
18958 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
18959 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
18960 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
18961 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
18962 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
18963 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
18964 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
18965 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
18966 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
18967 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
18968 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
18969 install_element(BGP_IPV4_NODE,
18970 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
18971 install_element(BGP_IPV4_NODE,
18972 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
18973 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
18974 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
18975 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
18976 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
18977 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
18978 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
18979
18980 /* import|export vpn [route-map WORD] */
18981 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
18982 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
18983
18984 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
18985 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
18986
18987 /* ttl_security commands */
18988 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
18989 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
18990
18991 /* "show [ip] bgp memory" commands. */
18992 install_element(VIEW_NODE, &show_bgp_memory_cmd);
18993
18994 /* "show bgp martian next-hop" */
18995 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
18996
18997 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
18998
18999 /* "show [ip] bgp views" commands. */
19000 install_element(VIEW_NODE, &show_bgp_views_cmd);
19001
19002 /* "show [ip] bgp vrfs" commands. */
19003 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
19004
19005 /* Community-list. */
19006 community_list_vty();
19007
19008 /* vpn-policy commands */
19009 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
19010 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
19011 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
19012 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
19013 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
19014 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
19015 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
19016 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
19017 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
19018 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
19019 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
19020 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
19021
19022 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
19023 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
19024
19025 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
19026 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
19027 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
19028 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
19029 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
19030 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
19031 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
19032 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
19033 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
19034 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
19035 }
19036
19037 #include "memory.h"
19038 #include "bgp_regex.h"
19039 #include "bgp_clist.h"
19040 #include "bgp_ecommunity.h"
19041
19042 /* VTY functions. */
19043
19044 /* Direction value to string conversion. */
19045 static const char *community_direct_str(int direct)
19046 {
19047 switch (direct) {
19048 case COMMUNITY_DENY:
19049 return "deny";
19050 case COMMUNITY_PERMIT:
19051 return "permit";
19052 default:
19053 return "unknown";
19054 }
19055 }
19056
19057 /* Display error string. */
19058 static void community_list_perror(struct vty *vty, int ret)
19059 {
19060 switch (ret) {
19061 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
19062 vty_out(vty, "%% Can't find community-list\n");
19063 break;
19064 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
19065 vty_out(vty, "%% Malformed community-list value\n");
19066 break;
19067 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
19068 vty_out(vty,
19069 "%% Community name conflict, previously defined as standard community\n");
19070 break;
19071 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
19072 vty_out(vty,
19073 "%% Community name conflict, previously defined as expanded community\n");
19074 break;
19075 }
19076 }
19077
19078 /* "community-list" keyword help string. */
19079 #define COMMUNITY_LIST_STR "Add a community list entry\n"
19080
19081 /*community-list standard */
19082 DEFUN (community_list_standard,
19083 bgp_community_list_standard_cmd,
19084 "bgp community-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
19085 BGP_STR
19086 COMMUNITY_LIST_STR
19087 "Community list number (standard)\n"
19088 "Add an standard community-list entry\n"
19089 "Community list name\n"
19090 "Sequence number of an entry\n"
19091 "Sequence number\n"
19092 "Specify community to reject\n"
19093 "Specify community to accept\n"
19094 COMMUNITY_VAL_STR)
19095 {
19096 char *cl_name_or_number = NULL;
19097 char *seq = NULL;
19098 int direct = 0;
19099 int style = COMMUNITY_LIST_STANDARD;
19100 int idx = 0;
19101
19102 argv_find(argv, argc, "(1-4294967295)", &idx);
19103 if (idx)
19104 seq = argv[idx]->arg;
19105
19106 idx = 0;
19107 argv_find(argv, argc, "(1-99)", &idx);
19108 argv_find(argv, argc, "WORD", &idx);
19109 cl_name_or_number = argv[idx]->arg;
19110 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19111 : COMMUNITY_DENY;
19112 argv_find(argv, argc, "AA:NN", &idx);
19113 char *str = argv_concat(argv, argc, idx);
19114
19115 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19116 direct, style);
19117
19118 XFREE(MTYPE_TMP, str);
19119
19120 if (ret < 0) {
19121 /* Display error string. */
19122 community_list_perror(vty, ret);
19123 return CMD_WARNING_CONFIG_FAILED;
19124 }
19125
19126 return CMD_SUCCESS;
19127 }
19128
19129 DEFUN (no_community_list_standard_all,
19130 no_bgp_community_list_standard_all_cmd,
19131 "no bgp community-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
19132 NO_STR
19133 BGP_STR
19134 COMMUNITY_LIST_STR
19135 "Community list number (standard)\n"
19136 "Add an standard community-list entry\n"
19137 "Community list name\n"
19138 "Sequence number of an entry\n"
19139 "Sequence number\n"
19140 "Specify community to reject\n"
19141 "Specify community to accept\n"
19142 COMMUNITY_VAL_STR)
19143 {
19144 char *cl_name_or_number = NULL;
19145 char *str = NULL;
19146 int direct = 0;
19147 int style = COMMUNITY_LIST_STANDARD;
19148 char *seq = NULL;
19149 int idx = 0;
19150
19151 argv_find(argv, argc, "(1-4294967295)", &idx);
19152 if (idx)
19153 seq = argv[idx]->arg;
19154
19155 idx = 0;
19156 argv_find(argv, argc, "permit", &idx);
19157 argv_find(argv, argc, "deny", &idx);
19158
19159 if (idx) {
19160 direct = argv_find(argv, argc, "permit", &idx)
19161 ? COMMUNITY_PERMIT
19162 : COMMUNITY_DENY;
19163
19164 idx = 0;
19165 argv_find(argv, argc, "AA:NN", &idx);
19166 str = argv_concat(argv, argc, idx);
19167 }
19168
19169 idx = 0;
19170 argv_find(argv, argc, "(1-99)", &idx);
19171 argv_find(argv, argc, "WORD", &idx);
19172 cl_name_or_number = argv[idx]->arg;
19173
19174 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
19175 direct, style);
19176
19177 XFREE(MTYPE_TMP, str);
19178
19179 if (ret < 0) {
19180 community_list_perror(vty, ret);
19181 return CMD_WARNING_CONFIG_FAILED;
19182 }
19183
19184 return CMD_SUCCESS;
19185 }
19186
19187 ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
19188 "no bgp community-list <(1-99)|standard WORD>",
19189 NO_STR BGP_STR COMMUNITY_LIST_STR
19190 "Community list number (standard)\n"
19191 "Add an standard community-list entry\n"
19192 "Community list name\n")
19193
19194 /*community-list expanded */
19195 DEFUN (community_list_expanded_all,
19196 bgp_community_list_expanded_all_cmd,
19197 "bgp community-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
19198 BGP_STR
19199 COMMUNITY_LIST_STR
19200 "Community list number (expanded)\n"
19201 "Add an expanded community-list entry\n"
19202 "Community list name\n"
19203 "Sequence number of an entry\n"
19204 "Sequence number\n"
19205 "Specify community to reject\n"
19206 "Specify community to accept\n"
19207 COMMUNITY_VAL_STR)
19208 {
19209 char *cl_name_or_number = NULL;
19210 char *seq = NULL;
19211 int direct = 0;
19212 int style = COMMUNITY_LIST_EXPANDED;
19213 int idx = 0;
19214
19215 argv_find(argv, argc, "(1-4294967295)", &idx);
19216 if (idx)
19217 seq = argv[idx]->arg;
19218
19219 idx = 0;
19220
19221 argv_find(argv, argc, "(100-500)", &idx);
19222 argv_find(argv, argc, "WORD", &idx);
19223 cl_name_or_number = argv[idx]->arg;
19224 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19225 : COMMUNITY_DENY;
19226 argv_find(argv, argc, "AA:NN", &idx);
19227 char *str = argv_concat(argv, argc, idx);
19228
19229 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19230 direct, style);
19231
19232 XFREE(MTYPE_TMP, str);
19233
19234 if (ret < 0) {
19235 /* Display error string. */
19236 community_list_perror(vty, ret);
19237 return CMD_WARNING_CONFIG_FAILED;
19238 }
19239
19240 return CMD_SUCCESS;
19241 }
19242
19243 DEFUN (no_community_list_expanded_all,
19244 no_bgp_community_list_expanded_all_cmd,
19245 "no bgp community-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
19246 NO_STR
19247 BGP_STR
19248 COMMUNITY_LIST_STR
19249 "Community list number (expanded)\n"
19250 "Add an expanded community-list entry\n"
19251 "Community list name\n"
19252 "Sequence number of an entry\n"
19253 "Sequence number\n"
19254 "Specify community to reject\n"
19255 "Specify community to accept\n"
19256 COMMUNITY_VAL_STR)
19257 {
19258 char *cl_name_or_number = NULL;
19259 char *seq = NULL;
19260 char *str = NULL;
19261 int direct = 0;
19262 int style = COMMUNITY_LIST_EXPANDED;
19263 int idx = 0;
19264
19265 argv_find(argv, argc, "(1-4294967295)", &idx);
19266 if (idx)
19267 seq = argv[idx]->arg;
19268
19269 idx = 0;
19270 argv_find(argv, argc, "permit", &idx);
19271 argv_find(argv, argc, "deny", &idx);
19272
19273 if (idx) {
19274 direct = argv_find(argv, argc, "permit", &idx)
19275 ? COMMUNITY_PERMIT
19276 : COMMUNITY_DENY;
19277
19278 idx = 0;
19279 argv_find(argv, argc, "AA:NN", &idx);
19280 str = argv_concat(argv, argc, idx);
19281 }
19282
19283 idx = 0;
19284 argv_find(argv, argc, "(100-500)", &idx);
19285 argv_find(argv, argc, "WORD", &idx);
19286 cl_name_or_number = argv[idx]->arg;
19287
19288 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
19289 direct, style);
19290
19291 XFREE(MTYPE_TMP, str);
19292
19293 if (ret < 0) {
19294 community_list_perror(vty, ret);
19295 return CMD_WARNING_CONFIG_FAILED;
19296 }
19297
19298 return CMD_SUCCESS;
19299 }
19300
19301 ALIAS(no_community_list_expanded_all,
19302 no_bgp_community_list_expanded_all_list_cmd,
19303 "no bgp community-list <(100-500)|expanded WORD>",
19304 NO_STR BGP_STR COMMUNITY_LIST_STR
19305 "Community list number (expanded)\n"
19306 "Add an expanded community-list entry\n"
19307 "Community list name\n")
19308
19309 /* Return configuration string of community-list entry. */
19310 static const char *community_list_config_str(struct community_entry *entry)
19311 {
19312 const char *str;
19313
19314 if (entry->any)
19315 str = "";
19316 else {
19317 if (entry->style == COMMUNITY_LIST_STANDARD)
19318 str = community_str(entry->u.com, false);
19319 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
19320 str = lcommunity_str(entry->u.lcom, false);
19321 else
19322 str = entry->config;
19323 }
19324 return str;
19325 }
19326
19327 static void community_list_show(struct vty *vty, struct community_list *list)
19328 {
19329 struct community_entry *entry;
19330
19331 for (entry = list->head; entry; entry = entry->next) {
19332 if (entry == list->head) {
19333 if (all_digit(list->name))
19334 vty_out(vty, "Community %s list %s\n",
19335 entry->style == COMMUNITY_LIST_STANDARD
19336 ? "standard"
19337 : "(expanded) access",
19338 list->name);
19339 else
19340 vty_out(vty, "Named Community %s list %s\n",
19341 entry->style == COMMUNITY_LIST_STANDARD
19342 ? "standard"
19343 : "expanded",
19344 list->name);
19345 }
19346 if (entry->any)
19347 vty_out(vty, " %s\n",
19348 community_direct_str(entry->direct));
19349 else
19350 vty_out(vty, " %s %s\n",
19351 community_direct_str(entry->direct),
19352 community_list_config_str(entry));
19353 }
19354 }
19355
19356 DEFUN (show_community_list,
19357 show_bgp_community_list_cmd,
19358 "show bgp community-list",
19359 SHOW_STR
19360 BGP_STR
19361 "List community-list\n")
19362 {
19363 struct community_list *list;
19364 struct community_list_master *cm;
19365
19366 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
19367 if (!cm)
19368 return CMD_SUCCESS;
19369
19370 for (list = cm->num.head; list; list = list->next)
19371 community_list_show(vty, list);
19372
19373 for (list = cm->str.head; list; list = list->next)
19374 community_list_show(vty, list);
19375
19376 return CMD_SUCCESS;
19377 }
19378
19379 DEFUN (show_community_list_arg,
19380 show_bgp_community_list_arg_cmd,
19381 "show bgp community-list <(1-500)|WORD> detail",
19382 SHOW_STR
19383 BGP_STR
19384 "List community-list\n"
19385 "Community-list number\n"
19386 "Community-list name\n"
19387 "Detailed information on community-list\n")
19388 {
19389 int idx_comm_list = 3;
19390 struct community_list *list;
19391
19392 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
19393 COMMUNITY_LIST_MASTER);
19394 if (!list) {
19395 vty_out(vty, "%% Can't find community-list\n");
19396 return CMD_WARNING;
19397 }
19398
19399 community_list_show(vty, list);
19400
19401 return CMD_SUCCESS;
19402 }
19403
19404 /*
19405 * Large Community code.
19406 */
19407 static int lcommunity_list_set_vty(struct vty *vty, int argc,
19408 struct cmd_token **argv, int style,
19409 int reject_all_digit_name)
19410 {
19411 int ret;
19412 int direct;
19413 char *str;
19414 int idx = 0;
19415 char *cl_name;
19416 char *seq = NULL;
19417
19418 if (argv_find(argv, argc, "(1-4294967295)", &idx))
19419 seq = argv[idx]->arg;
19420
19421 idx = 0;
19422 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19423 : COMMUNITY_DENY;
19424
19425 /* All digit name check. */
19426 idx = 0;
19427 argv_find(argv, argc, "WORD", &idx);
19428 argv_find(argv, argc, "(1-99)", &idx);
19429 argv_find(argv, argc, "(100-500)", &idx);
19430 cl_name = argv[idx]->arg;
19431 if (reject_all_digit_name && all_digit(cl_name)) {
19432 vty_out(vty, "%% Community name cannot have all digits\n");
19433 return CMD_WARNING_CONFIG_FAILED;
19434 }
19435
19436 idx = 0;
19437 argv_find(argv, argc, "AA:BB:CC", &idx);
19438 argv_find(argv, argc, "LINE", &idx);
19439 /* Concat community string argument. */
19440 if (idx)
19441 str = argv_concat(argv, argc, idx);
19442 else
19443 str = NULL;
19444
19445 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
19446
19447 /* Free temporary community list string allocated by
19448 argv_concat(). */
19449 XFREE(MTYPE_TMP, str);
19450
19451 if (ret < 0) {
19452 community_list_perror(vty, ret);
19453 return CMD_WARNING_CONFIG_FAILED;
19454 }
19455 return CMD_SUCCESS;
19456 }
19457
19458 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
19459 struct cmd_token **argv, int style)
19460 {
19461 int ret;
19462 int direct = 0;
19463 char *str = NULL;
19464 int idx = 0;
19465 char *seq = NULL;
19466
19467 if (argv_find(argv, argc, "(1-4294967295)", &idx))
19468 seq = argv[idx]->arg;
19469
19470 idx = 0;
19471 argv_find(argv, argc, "permit", &idx);
19472 argv_find(argv, argc, "deny", &idx);
19473
19474 if (idx) {
19475 /* Check the list direct. */
19476 if (strncmp(argv[idx]->arg, "p", 1) == 0)
19477 direct = COMMUNITY_PERMIT;
19478 else
19479 direct = COMMUNITY_DENY;
19480
19481 idx = 0;
19482 argv_find(argv, argc, "LINE", &idx);
19483 argv_find(argv, argc, "AA:AA:NN", &idx);
19484 /* Concat community string argument. */
19485 str = argv_concat(argv, argc, idx);
19486 }
19487
19488 idx = 0;
19489 argv_find(argv, argc, "(1-99)", &idx);
19490 argv_find(argv, argc, "(100-500)", &idx);
19491 argv_find(argv, argc, "WORD", &idx);
19492
19493 /* Unset community list. */
19494 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
19495 style);
19496
19497 /* Free temporary community list string allocated by
19498 argv_concat(). */
19499 XFREE(MTYPE_TMP, str);
19500
19501 if (ret < 0) {
19502 community_list_perror(vty, ret);
19503 return CMD_WARNING_CONFIG_FAILED;
19504 }
19505
19506 return CMD_SUCCESS;
19507 }
19508
19509 /* "large-community-list" keyword help string. */
19510 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
19511 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
19512
19513 DEFUN (lcommunity_list_standard,
19514 bgp_lcommunity_list_standard_cmd,
19515 "bgp large-community-list (1-99) [seq (1-4294967295)] <deny|permit> AA:BB:CC...",
19516 BGP_STR
19517 LCOMMUNITY_LIST_STR
19518 "Large Community list number (standard)\n"
19519 "Sequence number of an entry\n"
19520 "Sequence number\n"
19521 "Specify large community to reject\n"
19522 "Specify large community to accept\n"
19523 LCOMMUNITY_VAL_STR)
19524 {
19525 return lcommunity_list_set_vty(vty, argc, argv,
19526 LARGE_COMMUNITY_LIST_STANDARD, 0);
19527 }
19528
19529 DEFUN (lcommunity_list_expanded,
19530 bgp_lcommunity_list_expanded_cmd,
19531 "bgp large-community-list (100-500) [seq (1-4294967295)] <deny|permit> LINE...",
19532 BGP_STR
19533 LCOMMUNITY_LIST_STR
19534 "Large Community list number (expanded)\n"
19535 "Sequence number of an entry\n"
19536 "Sequence number\n"
19537 "Specify large community to reject\n"
19538 "Specify large community to accept\n"
19539 "An ordered list as a regular-expression\n")
19540 {
19541 return lcommunity_list_set_vty(vty, argc, argv,
19542 LARGE_COMMUNITY_LIST_EXPANDED, 0);
19543 }
19544
19545 DEFUN (lcommunity_list_name_standard,
19546 bgp_lcommunity_list_name_standard_cmd,
19547 "bgp large-community-list standard WORD [seq (1-4294967295)] <deny|permit> AA:BB:CC...",
19548 BGP_STR
19549 LCOMMUNITY_LIST_STR
19550 "Specify standard large-community-list\n"
19551 "Large Community list name\n"
19552 "Sequence number of an entry\n"
19553 "Sequence number\n"
19554 "Specify large community to reject\n"
19555 "Specify large community to accept\n"
19556 LCOMMUNITY_VAL_STR)
19557 {
19558 return lcommunity_list_set_vty(vty, argc, argv,
19559 LARGE_COMMUNITY_LIST_STANDARD, 1);
19560 }
19561
19562 DEFUN (lcommunity_list_name_expanded,
19563 bgp_lcommunity_list_name_expanded_cmd,
19564 "bgp large-community-list expanded WORD [seq (1-4294967295)] <deny|permit> LINE...",
19565 BGP_STR
19566 LCOMMUNITY_LIST_STR
19567 "Specify expanded large-community-list\n"
19568 "Large Community list name\n"
19569 "Sequence number of an entry\n"
19570 "Sequence number\n"
19571 "Specify large community to reject\n"
19572 "Specify large community to accept\n"
19573 "An ordered list as a regular-expression\n")
19574 {
19575 return lcommunity_list_set_vty(vty, argc, argv,
19576 LARGE_COMMUNITY_LIST_EXPANDED, 1);
19577 }
19578
19579 DEFUN (no_lcommunity_list_all,
19580 no_bgp_lcommunity_list_all_cmd,
19581 "no bgp large-community-list <(1-99)|(100-500)|WORD>",
19582 NO_STR
19583 BGP_STR
19584 LCOMMUNITY_LIST_STR
19585 "Large Community list number (standard)\n"
19586 "Large Community list number (expanded)\n"
19587 "Large Community list name\n")
19588 {
19589 return lcommunity_list_unset_vty(vty, argc, argv,
19590 LARGE_COMMUNITY_LIST_STANDARD);
19591 }
19592
19593 DEFUN (no_lcommunity_list_name_standard_all,
19594 no_bgp_lcommunity_list_name_standard_all_cmd,
19595 "no bgp large-community-list standard WORD",
19596 NO_STR
19597 BGP_STR
19598 LCOMMUNITY_LIST_STR
19599 "Specify standard large-community-list\n"
19600 "Large Community list name\n")
19601 {
19602 return lcommunity_list_unset_vty(vty, argc, argv,
19603 LARGE_COMMUNITY_LIST_STANDARD);
19604 }
19605
19606 DEFUN (no_lcommunity_list_name_expanded_all,
19607 no_bgp_lcommunity_list_name_expanded_all_cmd,
19608 "no bgp large-community-list expanded WORD",
19609 NO_STR
19610 BGP_STR
19611 LCOMMUNITY_LIST_STR
19612 "Specify expanded large-community-list\n"
19613 "Large Community list name\n")
19614 {
19615 return lcommunity_list_unset_vty(vty, argc, argv,
19616 LARGE_COMMUNITY_LIST_EXPANDED);
19617 }
19618
19619 DEFUN (no_lcommunity_list_standard,
19620 no_bgp_lcommunity_list_standard_cmd,
19621 "no bgp large-community-list (1-99) [seq (1-4294967295)] <deny|permit> AA:AA:NN...",
19622 NO_STR
19623 BGP_STR
19624 LCOMMUNITY_LIST_STR
19625 "Large Community list number (standard)\n"
19626 "Sequence number of an entry\n"
19627 "Sequence number\n"
19628 "Specify large community to reject\n"
19629 "Specify large community to accept\n"
19630 LCOMMUNITY_VAL_STR)
19631 {
19632 return lcommunity_list_unset_vty(vty, argc, argv,
19633 LARGE_COMMUNITY_LIST_STANDARD);
19634 }
19635
19636 DEFUN (no_lcommunity_list_expanded,
19637 no_bgp_lcommunity_list_expanded_cmd,
19638 "no bgp large-community-list (100-500) [seq (1-4294967295)] <deny|permit> LINE...",
19639 NO_STR
19640 BGP_STR
19641 LCOMMUNITY_LIST_STR
19642 "Large Community list number (expanded)\n"
19643 "Sequence number of an entry\n"
19644 "Sequence number\n"
19645 "Specify large community to reject\n"
19646 "Specify large community to accept\n"
19647 "An ordered list as a regular-expression\n")
19648 {
19649 return lcommunity_list_unset_vty(vty, argc, argv,
19650 LARGE_COMMUNITY_LIST_EXPANDED);
19651 }
19652
19653 DEFUN (no_lcommunity_list_name_standard,
19654 no_bgp_lcommunity_list_name_standard_cmd,
19655 "no bgp large-community-list standard WORD [seq (1-4294967295)] <deny|permit> AA:AA:NN...",
19656 NO_STR
19657 BGP_STR
19658 LCOMMUNITY_LIST_STR
19659 "Specify standard large-community-list\n"
19660 "Large Community list name\n"
19661 "Sequence number of an entry\n"
19662 "Sequence number\n"
19663 "Specify large community to reject\n"
19664 "Specify large community to accept\n"
19665 LCOMMUNITY_VAL_STR)
19666 {
19667 return lcommunity_list_unset_vty(vty, argc, argv,
19668 LARGE_COMMUNITY_LIST_STANDARD);
19669 }
19670
19671 DEFUN (no_lcommunity_list_name_expanded,
19672 no_bgp_lcommunity_list_name_expanded_cmd,
19673 "no bgp large-community-list expanded WORD [seq (1-4294967295)] <deny|permit> LINE...",
19674 NO_STR
19675 BGP_STR
19676 LCOMMUNITY_LIST_STR
19677 "Specify expanded large-community-list\n"
19678 "Large community list name\n"
19679 "Sequence number of an entry\n"
19680 "Sequence number\n"
19681 "Specify large community to reject\n"
19682 "Specify large community to accept\n"
19683 "An ordered list as a regular-expression\n")
19684 {
19685 return lcommunity_list_unset_vty(vty, argc, argv,
19686 LARGE_COMMUNITY_LIST_EXPANDED);
19687 }
19688
19689 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
19690 {
19691 struct community_entry *entry;
19692
19693 for (entry = list->head; entry; entry = entry->next) {
19694 if (entry == list->head) {
19695 if (all_digit(list->name))
19696 vty_out(vty, "Large community %s list %s\n",
19697 entry->style ==
19698 LARGE_COMMUNITY_LIST_STANDARD
19699 ? "standard"
19700 : "(expanded) access",
19701 list->name);
19702 else
19703 vty_out(vty,
19704 "Named large community %s list %s\n",
19705 entry->style ==
19706 LARGE_COMMUNITY_LIST_STANDARD
19707 ? "standard"
19708 : "expanded",
19709 list->name);
19710 }
19711 if (entry->any)
19712 vty_out(vty, " %s\n",
19713 community_direct_str(entry->direct));
19714 else
19715 vty_out(vty, " %s %s\n",
19716 community_direct_str(entry->direct),
19717 community_list_config_str(entry));
19718 }
19719 }
19720
19721 DEFUN (show_lcommunity_list,
19722 show_bgp_lcommunity_list_cmd,
19723 "show bgp large-community-list",
19724 SHOW_STR
19725 BGP_STR
19726 "List large-community list\n")
19727 {
19728 struct community_list *list;
19729 struct community_list_master *cm;
19730
19731 cm = community_list_master_lookup(bgp_clist,
19732 LARGE_COMMUNITY_LIST_MASTER);
19733 if (!cm)
19734 return CMD_SUCCESS;
19735
19736 for (list = cm->num.head; list; list = list->next)
19737 lcommunity_list_show(vty, list);
19738
19739 for (list = cm->str.head; list; list = list->next)
19740 lcommunity_list_show(vty, list);
19741
19742 return CMD_SUCCESS;
19743 }
19744
19745 DEFUN (show_lcommunity_list_arg,
19746 show_bgp_lcommunity_list_arg_cmd,
19747 "show bgp large-community-list <(1-500)|WORD> detail",
19748 SHOW_STR
19749 BGP_STR
19750 "List large-community list\n"
19751 "Large-community-list number\n"
19752 "Large-community-list name\n"
19753 "Detailed information on large-community-list\n")
19754 {
19755 struct community_list *list;
19756
19757 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
19758 LARGE_COMMUNITY_LIST_MASTER);
19759 if (!list) {
19760 vty_out(vty, "%% Can't find large-community-list\n");
19761 return CMD_WARNING;
19762 }
19763
19764 lcommunity_list_show(vty, list);
19765
19766 return CMD_SUCCESS;
19767 }
19768
19769 /* "extcommunity-list" keyword help string. */
19770 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
19771 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
19772
19773 DEFUN (extcommunity_list_standard,
19774 bgp_extcommunity_list_standard_cmd,
19775 "bgp extcommunity-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
19776 BGP_STR
19777 EXTCOMMUNITY_LIST_STR
19778 "Extended Community list number (standard)\n"
19779 "Specify standard extcommunity-list\n"
19780 "Community list name\n"
19781 "Sequence number of an entry\n"
19782 "Sequence number\n"
19783 "Specify community to reject\n"
19784 "Specify community to accept\n"
19785 EXTCOMMUNITY_VAL_STR)
19786 {
19787 int style = EXTCOMMUNITY_LIST_STANDARD;
19788 int direct = 0;
19789 char *cl_number_or_name = NULL;
19790 char *seq = NULL;
19791
19792 int idx = 0;
19793
19794 argv_find(argv, argc, "(1-99)", &idx);
19795 argv_find(argv, argc, "WORD", &idx);
19796 cl_number_or_name = argv[idx]->arg;
19797
19798 if (argv_find(argv, argc, "(1-4294967295)", &idx))
19799 seq = argv[idx]->arg;
19800
19801 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19802 : COMMUNITY_DENY;
19803 argv_find(argv, argc, "AA:NN", &idx);
19804 char *str = argv_concat(argv, argc, idx);
19805
19806 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
19807 direct, style);
19808
19809 XFREE(MTYPE_TMP, str);
19810
19811 if (ret < 0) {
19812 community_list_perror(vty, ret);
19813 return CMD_WARNING_CONFIG_FAILED;
19814 }
19815
19816 return CMD_SUCCESS;
19817 }
19818
19819 DEFUN (extcommunity_list_name_expanded,
19820 bgp_extcommunity_list_name_expanded_cmd,
19821 "bgp extcommunity-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> LINE...",
19822 BGP_STR
19823 EXTCOMMUNITY_LIST_STR
19824 "Extended Community list number (expanded)\n"
19825 "Specify expanded extcommunity-list\n"
19826 "Extended Community list name\n"
19827 "Sequence number of an entry\n"
19828 "Sequence number\n"
19829 "Specify community to reject\n"
19830 "Specify community to accept\n"
19831 "An ordered list as a regular-expression\n")
19832 {
19833 int style = EXTCOMMUNITY_LIST_EXPANDED;
19834 int direct = 0;
19835 char *cl_number_or_name = NULL;
19836 char *seq = NULL;
19837 int idx = 0;
19838
19839 argv_find(argv, argc, "(100-500)", &idx);
19840 argv_find(argv, argc, "WORD", &idx);
19841 cl_number_or_name = argv[idx]->arg;
19842
19843 if (argv_find(argv, argc, "(1-4294967295)", &idx))
19844 seq = argv[idx]->arg;
19845
19846 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19847 : COMMUNITY_DENY;
19848 argv_find(argv, argc, "LINE", &idx);
19849 char *str = argv_concat(argv, argc, idx);
19850
19851 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
19852 direct, style);
19853
19854 XFREE(MTYPE_TMP, str);
19855
19856 if (ret < 0) {
19857 community_list_perror(vty, ret);
19858 return CMD_WARNING_CONFIG_FAILED;
19859 }
19860
19861 return CMD_SUCCESS;
19862 }
19863
19864 DEFUN (no_extcommunity_list_standard_all,
19865 no_bgp_extcommunity_list_standard_all_cmd,
19866 "no bgp extcommunity-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
19867 NO_STR
19868 BGP_STR
19869 EXTCOMMUNITY_LIST_STR
19870 "Extended Community list number (standard)\n"
19871 "Specify standard extcommunity-list\n"
19872 "Community list name\n"
19873 "Sequence number of an entry\n"
19874 "Sequence number\n"
19875 "Specify community to reject\n"
19876 "Specify community to accept\n"
19877 EXTCOMMUNITY_VAL_STR)
19878 {
19879 int style = EXTCOMMUNITY_LIST_STANDARD;
19880 int direct = 0;
19881 char *cl_number_or_name = NULL;
19882 char *str = NULL;
19883 char *seq = NULL;
19884 int idx = 0;
19885
19886 if (argv_find(argv, argc, "(1-4294967295)", &idx))
19887 seq = argv[idx]->arg;
19888
19889 idx = 0;
19890 argv_find(argv, argc, "permit", &idx);
19891 argv_find(argv, argc, "deny", &idx);
19892 if (idx) {
19893 direct = argv_find(argv, argc, "permit", &idx)
19894 ? COMMUNITY_PERMIT
19895 : COMMUNITY_DENY;
19896
19897 idx = 0;
19898 argv_find(argv, argc, "AA:NN", &idx);
19899 str = argv_concat(argv, argc, idx);
19900 }
19901
19902 idx = 0;
19903 argv_find(argv, argc, "(1-99)", &idx);
19904 argv_find(argv, argc, "WORD", &idx);
19905 cl_number_or_name = argv[idx]->arg;
19906
19907 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
19908 seq, direct, style);
19909
19910 XFREE(MTYPE_TMP, str);
19911
19912 if (ret < 0) {
19913 community_list_perror(vty, ret);
19914 return CMD_WARNING_CONFIG_FAILED;
19915 }
19916
19917 return CMD_SUCCESS;
19918 }
19919
19920 ALIAS(no_extcommunity_list_standard_all,
19921 no_bgp_extcommunity_list_standard_all_list_cmd,
19922 "no bgp extcommunity-list <(1-99)|standard WORD>",
19923 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
19924 "Extended Community list number (standard)\n"
19925 "Specify standard extcommunity-list\n"
19926 "Community list name\n")
19927
19928 DEFUN (no_extcommunity_list_expanded_all,
19929 no_bgp_extcommunity_list_expanded_all_cmd,
19930 "no bgp extcommunity-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> LINE...",
19931 NO_STR
19932 BGP_STR
19933 EXTCOMMUNITY_LIST_STR
19934 "Extended Community list number (expanded)\n"
19935 "Specify expanded extcommunity-list\n"
19936 "Extended Community list name\n"
19937 "Sequence number of an entry\n"
19938 "Sequence number\n"
19939 "Specify community to reject\n"
19940 "Specify community to accept\n"
19941 "An ordered list as a regular-expression\n")
19942 {
19943 int style = EXTCOMMUNITY_LIST_EXPANDED;
19944 int direct = 0;
19945 char *cl_number_or_name = NULL;
19946 char *str = NULL;
19947 char *seq = NULL;
19948 int idx = 0;
19949
19950 if (argv_find(argv, argc, "(1-4294967295)", &idx))
19951 seq = argv[idx]->arg;
19952
19953 idx = 0;
19954 argv_find(argv, argc, "permit", &idx);
19955 argv_find(argv, argc, "deny", &idx);
19956
19957 if (idx) {
19958 direct = argv_find(argv, argc, "permit", &idx)
19959 ? COMMUNITY_PERMIT
19960 : COMMUNITY_DENY;
19961
19962 idx = 0;
19963 argv_find(argv, argc, "LINE", &idx);
19964 str = argv_concat(argv, argc, idx);
19965 }
19966
19967 idx = 0;
19968 argv_find(argv, argc, "(100-500)", &idx);
19969 argv_find(argv, argc, "WORD", &idx);
19970 cl_number_or_name = argv[idx]->arg;
19971
19972 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
19973 seq, direct, style);
19974
19975 XFREE(MTYPE_TMP, str);
19976
19977 if (ret < 0) {
19978 community_list_perror(vty, ret);
19979 return CMD_WARNING_CONFIG_FAILED;
19980 }
19981
19982 return CMD_SUCCESS;
19983 }
19984
19985 ALIAS(no_extcommunity_list_expanded_all,
19986 no_bgp_extcommunity_list_expanded_all_list_cmd,
19987 "no bgp extcommunity-list <(100-500)|expanded WORD>",
19988 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
19989 "Extended Community list number (expanded)\n"
19990 "Specify expanded extcommunity-list\n"
19991 "Extended Community list name\n")
19992
19993 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
19994 {
19995 struct community_entry *entry;
19996
19997 for (entry = list->head; entry; entry = entry->next) {
19998 if (entry == list->head) {
19999 if (all_digit(list->name))
20000 vty_out(vty, "Extended community %s list %s\n",
20001 entry->style == EXTCOMMUNITY_LIST_STANDARD
20002 ? "standard"
20003 : "(expanded) access",
20004 list->name);
20005 else
20006 vty_out(vty,
20007 "Named extended community %s list %s\n",
20008 entry->style == EXTCOMMUNITY_LIST_STANDARD
20009 ? "standard"
20010 : "expanded",
20011 list->name);
20012 }
20013 if (entry->any)
20014 vty_out(vty, " %s\n",
20015 community_direct_str(entry->direct));
20016 else
20017 vty_out(vty, " %s %s\n",
20018 community_direct_str(entry->direct),
20019 community_list_config_str(entry));
20020 }
20021 }
20022
20023 DEFUN (show_extcommunity_list,
20024 show_bgp_extcommunity_list_cmd,
20025 "show bgp extcommunity-list",
20026 SHOW_STR
20027 BGP_STR
20028 "List extended-community list\n")
20029 {
20030 struct community_list *list;
20031 struct community_list_master *cm;
20032
20033 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
20034 if (!cm)
20035 return CMD_SUCCESS;
20036
20037 for (list = cm->num.head; list; list = list->next)
20038 extcommunity_list_show(vty, list);
20039
20040 for (list = cm->str.head; list; list = list->next)
20041 extcommunity_list_show(vty, list);
20042
20043 return CMD_SUCCESS;
20044 }
20045
20046 DEFUN (show_extcommunity_list_arg,
20047 show_bgp_extcommunity_list_arg_cmd,
20048 "show bgp extcommunity-list <(1-500)|WORD> detail",
20049 SHOW_STR
20050 BGP_STR
20051 "List extended-community list\n"
20052 "Extcommunity-list number\n"
20053 "Extcommunity-list name\n"
20054 "Detailed information on extcommunity-list\n")
20055 {
20056 int idx_comm_list = 3;
20057 struct community_list *list;
20058
20059 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
20060 EXTCOMMUNITY_LIST_MASTER);
20061 if (!list) {
20062 vty_out(vty, "%% Can't find extcommunity-list\n");
20063 return CMD_WARNING;
20064 }
20065
20066 extcommunity_list_show(vty, list);
20067
20068 return CMD_SUCCESS;
20069 }
20070
20071 /* Display community-list and extcommunity-list configuration. */
20072 static int community_list_config_write(struct vty *vty)
20073 {
20074 struct community_list *list;
20075 struct community_entry *entry;
20076 struct community_list_master *cm;
20077 int write = 0;
20078
20079 /* Community-list. */
20080 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
20081
20082 for (list = cm->num.head; list; list = list->next)
20083 for (entry = list->head; entry; entry = entry->next) {
20084 vty_out(vty,
20085 "bgp community-list %s seq %" PRId64 " %s %s\n",
20086 list->name, entry->seq,
20087 community_direct_str(entry->direct),
20088 community_list_config_str(entry));
20089 write++;
20090 }
20091 for (list = cm->str.head; list; list = list->next)
20092 for (entry = list->head; entry; entry = entry->next) {
20093 vty_out(vty,
20094 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
20095 entry->style == COMMUNITY_LIST_STANDARD
20096 ? "standard"
20097 : "expanded",
20098 list->name, entry->seq,
20099 community_direct_str(entry->direct),
20100 community_list_config_str(entry));
20101 write++;
20102 }
20103
20104 /* Extcommunity-list. */
20105 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
20106
20107 for (list = cm->num.head; list; list = list->next)
20108 for (entry = list->head; entry; entry = entry->next) {
20109 vty_out(vty,
20110 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
20111 list->name, entry->seq,
20112 community_direct_str(entry->direct),
20113 community_list_config_str(entry));
20114 write++;
20115 }
20116 for (list = cm->str.head; list; list = list->next)
20117 for (entry = list->head; entry; entry = entry->next) {
20118 vty_out(vty,
20119 "bgp extcommunity-list %s %s seq %" PRId64" %s %s\n",
20120 entry->style == EXTCOMMUNITY_LIST_STANDARD
20121 ? "standard"
20122 : "expanded",
20123 list->name, entry->seq,
20124 community_direct_str(entry->direct),
20125 community_list_config_str(entry));
20126 write++;
20127 }
20128
20129
20130 /* lcommunity-list. */
20131 cm = community_list_master_lookup(bgp_clist,
20132 LARGE_COMMUNITY_LIST_MASTER);
20133
20134 for (list = cm->num.head; list; list = list->next)
20135 for (entry = list->head; entry; entry = entry->next) {
20136 vty_out(vty,
20137 "bgp large-community-list %s seq %" PRId64" %s %s\n",
20138 list->name, entry->seq,
20139 community_direct_str(entry->direct),
20140 community_list_config_str(entry));
20141 write++;
20142 }
20143 for (list = cm->str.head; list; list = list->next)
20144 for (entry = list->head; entry; entry = entry->next) {
20145 vty_out(vty,
20146 "bgp large-community-list %s %s seq %" PRId64" %s %s\n",
20147
20148 entry->style == LARGE_COMMUNITY_LIST_STANDARD
20149 ? "standard"
20150 : "expanded",
20151 list->name, entry->seq, community_direct_str(entry->direct),
20152 community_list_config_str(entry));
20153 write++;
20154 }
20155
20156 return write;
20157 }
20158
20159 static int community_list_config_write(struct vty *vty);
20160 static struct cmd_node community_list_node = {
20161 .name = "community list",
20162 .node = COMMUNITY_LIST_NODE,
20163 .prompt = "",
20164 .config_write = community_list_config_write,
20165 };
20166
20167 static void community_list_vty(void)
20168 {
20169 install_node(&community_list_node);
20170
20171 /* Community-list. */
20172 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
20173 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
20174 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
20175 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
20176 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
20177 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
20178 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
20179 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
20180
20181 /* Extcommunity-list. */
20182 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
20183 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
20184 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
20185 install_element(CONFIG_NODE,
20186 &no_bgp_extcommunity_list_standard_all_list_cmd);
20187 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
20188 install_element(CONFIG_NODE,
20189 &no_bgp_extcommunity_list_expanded_all_list_cmd);
20190 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
20191 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
20192
20193 /* Large Community List */
20194 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
20195 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
20196 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
20197 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
20198 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
20199 install_element(CONFIG_NODE,
20200 &no_bgp_lcommunity_list_name_standard_all_cmd);
20201 install_element(CONFIG_NODE,
20202 &no_bgp_lcommunity_list_name_expanded_all_cmd);
20203 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
20204 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
20205 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
20206 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
20207 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
20208 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
20209 }