]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
Merge pull request #8744 from sworleys/RTADV-Fix-Upstream
[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/sockopt.h"
26 #include "lib_errors.h"
27 #include "lib/zclient.h"
28 #include "lib/printfrr.h"
29 #include "prefix.h"
30 #include "plist.h"
31 #include "buffer.h"
32 #include "linklist.h"
33 #include "stream.h"
34 #include "thread.h"
35 #include "log.h"
36 #include "memory.h"
37 #include "lib_vty.h"
38 #include "hash.h"
39 #include "queue.h"
40 #include "filter.h"
41 #include "frrstr.h"
42
43 #include "bgpd/bgpd.h"
44 #include "bgpd/bgp_attr_evpn.h"
45 #include "bgpd/bgp_advertise.h"
46 #include "bgpd/bgp_attr.h"
47 #include "bgpd/bgp_aspath.h"
48 #include "bgpd/bgp_community.h"
49 #include "bgpd/bgp_community_alias.h"
50 #include "bgpd/bgp_ecommunity.h"
51 #include "bgpd/bgp_lcommunity.h"
52 #include "bgpd/bgp_damp.h"
53 #include "bgpd/bgp_debug.h"
54 #include "bgpd/bgp_errors.h"
55 #include "bgpd/bgp_fsm.h"
56 #include "bgpd/bgp_nexthop.h"
57 #include "bgpd/bgp_open.h"
58 #include "bgpd/bgp_regex.h"
59 #include "bgpd/bgp_route.h"
60 #include "bgpd/bgp_mplsvpn.h"
61 #include "bgpd/bgp_zebra.h"
62 #include "bgpd/bgp_table.h"
63 #include "bgpd/bgp_vty.h"
64 #include "bgpd/bgp_mpath.h"
65 #include "bgpd/bgp_packet.h"
66 #include "bgpd/bgp_updgrp.h"
67 #include "bgpd/bgp_bfd.h"
68 #include "bgpd/bgp_io.h"
69 #include "bgpd/bgp_evpn.h"
70 #include "bgpd/bgp_evpn_vty.h"
71 #include "bgpd/bgp_evpn_mh.h"
72 #include "bgpd/bgp_addpath.h"
73 #include "bgpd/bgp_mac.h"
74 #include "bgpd/bgp_flowspec.h"
75 #ifdef ENABLE_BGP_VNC
76 #include "bgpd/rfapi/bgp_rfapi_cfg.h"
77 #endif
78
79 #include "northbound.h"
80 #include "northbound_cli.h"
81 #include "bgpd/bgp_nb.h"
82
83
84 FRR_CFG_DEFAULT_BOOL(BGP_IMPORT_CHECK,
85 {
86 .val_bool = false,
87 .match_profile = "traditional",
88 .match_version = "< 7.4",
89 },
90 { .val_bool = true },
91 );
92 FRR_CFG_DEFAULT_BOOL(BGP_SHOW_HOSTNAME,
93 { .val_bool = true, .match_profile = "datacenter", },
94 { .val_bool = false },
95 );
96 FRR_CFG_DEFAULT_BOOL(BGP_SHOW_NEXTHOP_HOSTNAME,
97 { .val_bool = true, .match_profile = "datacenter", },
98 { .val_bool = false },
99 );
100 FRR_CFG_DEFAULT_BOOL(BGP_LOG_NEIGHBOR_CHANGES,
101 { .val_bool = true, .match_profile = "datacenter", },
102 { .val_bool = false },
103 );
104 FRR_CFG_DEFAULT_BOOL(BGP_DETERMINISTIC_MED,
105 { .val_bool = true, .match_profile = "datacenter", },
106 { .val_bool = false },
107 );
108 FRR_CFG_DEFAULT_ULONG(BGP_CONNECT_RETRY,
109 { .val_ulong = 10, .match_profile = "datacenter", },
110 { .val_ulong = 120 },
111 );
112 FRR_CFG_DEFAULT_ULONG(BGP_HOLDTIME,
113 { .val_ulong = 9, .match_profile = "datacenter", },
114 { .val_ulong = 180 },
115 );
116 FRR_CFG_DEFAULT_ULONG(BGP_KEEPALIVE,
117 { .val_ulong = 3, .match_profile = "datacenter", },
118 { .val_ulong = 60 },
119 );
120 FRR_CFG_DEFAULT_BOOL(BGP_EBGP_REQUIRES_POLICY,
121 { .val_bool = false, .match_profile = "datacenter", },
122 { .val_bool = false, .match_version = "< 7.4", },
123 { .val_bool = true },
124 );
125 FRR_CFG_DEFAULT_BOOL(BGP_SUPPRESS_DUPLICATES,
126 { .val_bool = false, .match_version = "< 7.6", },
127 { .val_bool = true },
128 );
129
130 DEFINE_HOOK(bgp_inst_config_write,
131 (struct bgp *bgp, struct vty *vty),
132 (bgp, vty));
133 DEFINE_HOOK(bgp_snmp_update_last_changed, (struct bgp *bgp), (bgp));
134
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 /*
474 * Convert an afi_t/safi_t pair to matching BGP_DEFAULT_AF* flag.
475 *
476 * afi
477 * address-family identifier
478 *
479 * safi
480 * subsequent address-family identifier
481 *
482 * Returns:
483 * default_af string corresponding to the supplied afi/safi pair.
484 * If afi/safi is invalid or if flag for afi/safi doesn't exist,
485 * return -1.
486 */
487 static const char *get_bgp_default_af_flag(afi_t afi, safi_t safi)
488 {
489 switch (afi) {
490 case AFI_IP:
491 switch (safi) {
492 case SAFI_UNICAST:
493 return "ipv4-unicast";
494 case SAFI_MULTICAST:
495 return "ipv4-multicast";
496 case SAFI_MPLS_VPN:
497 return "ipv4-vpn";
498 case SAFI_ENCAP:
499 return "ipv4-encap";
500 case SAFI_LABELED_UNICAST:
501 return "ipv4-labeled-unicast";
502 case SAFI_FLOWSPEC:
503 return "ipv4-flowspec";
504 default:
505 return "unknown-afi/safi";
506 }
507 break;
508 case AFI_IP6:
509 switch (safi) {
510 case SAFI_UNICAST:
511 return "ipv6-unicast";
512 case SAFI_MULTICAST:
513 return "ipv6-multicast";
514 case SAFI_MPLS_VPN:
515 return "ipv6-vpn";
516 case SAFI_ENCAP:
517 return "ipv6-encap";
518 case SAFI_LABELED_UNICAST:
519 return "ipv6-labeled-unicast";
520 case SAFI_FLOWSPEC:
521 return "ipv6-flowspec";
522 default:
523 return "unknown-afi/safi";
524 }
525 break;
526 case AFI_L2VPN:
527 switch (safi) {
528 case SAFI_EVPN:
529 return "l2vpn-evpn";
530 default:
531 return "unknown-afi/safi";
532 }
533 case AFI_UNSPEC:
534 case AFI_MAX:
535 return "unknown-afi/safi";
536 }
537 /* all AFIs are accounted for above, so this shouldn't happen */
538 return "unknown-afi/safi";
539 }
540
541 int bgp_get_vty(struct bgp **bgp, as_t *as, const char *name,
542 enum bgp_instance_type inst_type)
543 {
544 int ret = bgp_get(bgp, as, name, inst_type);
545
546 if (ret == BGP_CREATED) {
547 bgp_timers_set(*bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
548 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
549
550 if (DFLT_BGP_IMPORT_CHECK)
551 SET_FLAG((*bgp)->flags, BGP_FLAG_IMPORT_CHECK);
552 if (DFLT_BGP_SHOW_HOSTNAME)
553 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_HOSTNAME);
554 if (DFLT_BGP_SHOW_NEXTHOP_HOSTNAME)
555 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
556 if (DFLT_BGP_LOG_NEIGHBOR_CHANGES)
557 SET_FLAG((*bgp)->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
558 if (DFLT_BGP_DETERMINISTIC_MED)
559 SET_FLAG((*bgp)->flags, BGP_FLAG_DETERMINISTIC_MED);
560 if (DFLT_BGP_EBGP_REQUIRES_POLICY)
561 SET_FLAG((*bgp)->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
562 if (DFLT_BGP_SUPPRESS_DUPLICATES)
563 SET_FLAG((*bgp)->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
564
565 ret = BGP_SUCCESS;
566 }
567 return ret;
568 }
569
570 /*
571 * bgp_vty_find_and_parse_afi_safi_bgp
572 *
573 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
574 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
575 * to appropriate values for the calling function. This is to allow the
576 * calling function to make decisions appropriate for the show command
577 * that is being parsed.
578 *
579 * The show commands are generally of the form:
580 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
581 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
582 *
583 * Since we use argv_find if the show command in particular doesn't have:
584 * [ip]
585 * [<view|vrf> VIEWVRFNAME]
586 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
587 * The command parsing should still be ok.
588 *
589 * vty -> The vty for the command so we can output some useful data in
590 * the event of a parse error in the vrf.
591 * argv -> The command tokens
592 * argc -> How many command tokens we have
593 * idx -> The current place in the command, generally should be 0 for this
594 * function
595 * afi -> The parsed afi if it was included in the show command, returned here
596 * safi -> The parsed safi if it was included in the show command, returned here
597 * bgp -> Pointer to the bgp data structure we need to fill in.
598 * use_json -> json is configured or not
599 *
600 * The function returns the correct location in the parse tree for the
601 * last token found.
602 *
603 * Returns 0 for failure to parse correctly, else the idx position of where
604 * it found the last token.
605 */
606 int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
607 struct cmd_token **argv, int argc,
608 int *idx, afi_t *afi, safi_t *safi,
609 struct bgp **bgp, bool use_json)
610 {
611 char *vrf_name = NULL;
612
613 assert(afi);
614 assert(safi);
615 assert(bgp);
616
617 if (argv_find(argv, argc, "ip", idx))
618 *afi = AFI_IP;
619
620 if (argv_find(argv, argc, "view", idx))
621 vrf_name = argv[*idx + 1]->arg;
622 else if (argv_find(argv, argc, "vrf", idx)) {
623 vrf_name = argv[*idx + 1]->arg;
624 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
625 vrf_name = NULL;
626 }
627 if (vrf_name) {
628 if (strmatch(vrf_name, "all"))
629 *bgp = NULL;
630 else {
631 *bgp = bgp_lookup_by_name(vrf_name);
632 if (!*bgp) {
633 if (use_json) {
634 json_object *json = NULL;
635 json = json_object_new_object();
636 json_object_string_add(
637 json, "warning",
638 "View/Vrf is unknown");
639 vty_out(vty, "%s\n",
640 json_object_to_json_string_ext(json,
641 JSON_C_TO_STRING_PRETTY));
642 json_object_free(json);
643 }
644 else
645 vty_out(vty, "View/Vrf %s is unknown\n",
646 vrf_name);
647 *idx = 0;
648 return 0;
649 }
650 }
651 } else {
652 *bgp = bgp_get_default();
653 if (!*bgp) {
654 if (use_json) {
655 json_object *json = NULL;
656 json = json_object_new_object();
657 json_object_string_add(
658 json, "warning",
659 "Default BGP instance not found");
660 vty_out(vty, "%s\n",
661 json_object_to_json_string_ext(json,
662 JSON_C_TO_STRING_PRETTY));
663 json_object_free(json);
664 }
665 else
666 vty_out(vty,
667 "Default BGP instance not found\n");
668 *idx = 0;
669 return 0;
670 }
671 }
672
673 if (argv_find_and_parse_afi(argv, argc, idx, afi))
674 argv_find_and_parse_safi(argv, argc, idx, safi);
675
676 *idx += 1;
677 return *idx;
678 }
679
680 bool peer_address_self_check(struct bgp *bgp, union sockunion *su)
681 {
682 struct interface *ifp = NULL;
683
684 if (su->sa.sa_family == AF_INET)
685 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
686 else if (su->sa.sa_family == AF_INET6)
687 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
688 su->sin6.sin6_scope_id,
689 bgp->vrf_id);
690
691 if (ifp)
692 return true;
693
694 return false;
695 }
696
697 /* Utility function for looking up peer or peer group. */
698 /* This is used only for configuration, so disallow if attempted on
699 * a dynamic neighbor.
700 */
701 struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
702 {
703 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
704 int ret;
705 union sockunion su;
706 struct peer *peer = NULL;
707 struct peer_group *group = NULL;
708
709 if (!bgp) {
710 return NULL;
711 }
712
713 ret = str2sockunion(peer_str, &su);
714 if (ret == 0) {
715 /* IP address, locate peer. */
716 peer = peer_lookup(bgp, &su);
717 } else {
718 /* Not IP, could match either peer configured on interface or a
719 * group. */
720 peer = peer_lookup_by_conf_if(bgp, peer_str);
721 if (!peer)
722 group = peer_group_lookup(bgp, peer_str);
723 }
724
725 if (peer) {
726 if (peer_dynamic_neighbor(peer)) {
727 vty_out(vty,
728 "%% Operation not allowed on a dynamic neighbor\n");
729 return NULL;
730 }
731
732 return peer;
733 }
734
735 if (group)
736 return group->conf;
737
738 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
739
740 return NULL;
741 }
742
743 int bgp_nb_errmsg_return(char *errmsg, size_t errmsg_len, int ret)
744 {
745 const char *str = NULL;
746
747 switch (ret) {
748 case BGP_ERR_INVALID_VALUE:
749 str = "Invalid value";
750 break;
751 case BGP_ERR_INVALID_FLAG:
752 str = "Invalid flag";
753 break;
754 case BGP_ERR_PEER_GROUP_SHUTDOWN:
755 str = "Peer-group has been shutdown. Activate the peer-group first";
756 break;
757 case BGP_ERR_PEER_FLAG_CONFLICT:
758 str = "Can't set override-capability and strict-capability-match at the same time";
759 break;
760 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
761 str = "Specify remote-as or peer-group remote AS first";
762 break;
763 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
764 str = "Cannot change the peer-group. Deconfigure first";
765 break;
766 case BGP_ERR_PEER_GROUP_MISMATCH:
767 str = "Peer is not a member of this peer-group";
768 break;
769 case BGP_ERR_PEER_FILTER_CONFLICT:
770 str = "Prefix/distribute list can not co-exist";
771 break;
772 case BGP_ERR_NOT_INTERNAL_PEER:
773 str = "Invalid command. Not an internal neighbor";
774 break;
775 case BGP_ERR_REMOVE_PRIVATE_AS:
776 str = "remove-private-AS cannot be configured for IBGP peers";
777 break;
778 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
779 str = "Local-AS allowed only for EBGP peers";
780 break;
781 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
782 str = "Cannot have local-as same as BGP AS number";
783 break;
784 case BGP_ERR_TCPSIG_FAILED:
785 str = "Error while applying TCP-Sig to session(s)";
786 break;
787 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
788 str = "ebgp-multihop and ttl-security cannot be configured together";
789 break;
790 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
791 str = "ttl-security only allowed for EBGP peers";
792 break;
793 case BGP_ERR_AS_OVERRIDE:
794 str = "as-override cannot be configured for IBGP peers";
795 break;
796 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
797 str = "Invalid limit for number of dynamic neighbors";
798 break;
799 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
800 str = "Dynamic neighbor listen range already exists";
801 break;
802 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
803 str = "Operation not allowed on a dynamic neighbor";
804 break;
805 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
806 str = "Operation not allowed on a directly connected neighbor";
807 break;
808 case BGP_ERR_PEER_SAFI_CONFLICT:
809 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
810 break;
811 case BGP_ERR_GR_INVALID_CMD:
812 str = "The Graceful Restart command used is not valid at this moment.";
813 break;
814 case BGP_ERR_GR_OPERATION_FAILED:
815 str = "The Graceful Restart Operation failed due to an err.";
816 break;
817 case BGP_ERR_PEER_GROUP_MEMBER:
818 str = "Peer-group member cannot override remote-as of peer-group";
819 break;
820 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
821 str = "Peer-group members must be all internal or all external";
822 break;
823 }
824 if (str) {
825 snprintf(errmsg, errmsg_len, "%s", str);
826 return -1;
827 }
828
829 return 0;
830 }
831
832 int bgp_vty_return(struct vty *vty, int ret)
833 {
834 const char *str = NULL;
835
836 switch (ret) {
837 case BGP_ERR_INVALID_VALUE:
838 str = "Invalid value";
839 break;
840 case BGP_ERR_INVALID_FLAG:
841 str = "Invalid flag";
842 break;
843 case BGP_ERR_PEER_GROUP_SHUTDOWN:
844 str = "Peer-group has been shutdown. Activate the peer-group first";
845 break;
846 case BGP_ERR_PEER_FLAG_CONFLICT:
847 str = "Can't set override-capability and strict-capability-match at the same time";
848 break;
849 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
850 str = "Specify remote-as or peer-group remote AS first";
851 break;
852 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
853 str = "Cannot change the peer-group. Deconfigure first";
854 break;
855 case BGP_ERR_PEER_GROUP_MISMATCH:
856 str = "Peer is not a member of this peer-group";
857 break;
858 case BGP_ERR_PEER_FILTER_CONFLICT:
859 str = "Prefix/distribute list can not co-exist";
860 break;
861 case BGP_ERR_NOT_INTERNAL_PEER:
862 str = "Invalid command. Not an internal neighbor";
863 break;
864 case BGP_ERR_REMOVE_PRIVATE_AS:
865 str = "remove-private-AS cannot be configured for IBGP peers";
866 break;
867 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
868 str = "Local-AS allowed only for EBGP peers";
869 break;
870 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
871 str = "Cannot have local-as same as BGP AS number";
872 break;
873 case BGP_ERR_TCPSIG_FAILED:
874 str = "Error while applying TCP-Sig to session(s)";
875 break;
876 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
877 str = "ebgp-multihop and ttl-security cannot be configured together";
878 break;
879 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
880 str = "ttl-security only allowed for EBGP peers";
881 break;
882 case BGP_ERR_AS_OVERRIDE:
883 str = "as-override cannot be configured for IBGP peers";
884 break;
885 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
886 str = "Invalid limit for number of dynamic neighbors";
887 break;
888 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
889 str = "Dynamic neighbor listen range already exists";
890 break;
891 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
892 str = "Operation not allowed on a dynamic neighbor";
893 break;
894 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
895 str = "Operation not allowed on a directly connected neighbor";
896 break;
897 case BGP_ERR_PEER_SAFI_CONFLICT:
898 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
899 break;
900 case BGP_ERR_GR_INVALID_CMD:
901 str = "The Graceful Restart command used is not valid at this moment.";
902 break;
903 case BGP_ERR_GR_OPERATION_FAILED:
904 str = "The Graceful Restart Operation failed due to an err.";
905 break;
906 }
907 if (str) {
908 vty_out(vty, "%% %s\n", str);
909 return CMD_WARNING_CONFIG_FAILED;
910 }
911 return CMD_SUCCESS;
912 }
913
914 /* BGP clear sort. */
915 enum clear_sort {
916 clear_all,
917 clear_peer,
918 clear_group,
919 clear_external,
920 clear_as
921 };
922
923 static void bgp_clear_vty_error(struct peer *peer, afi_t afi, safi_t safi,
924 int error, char *errmsg, size_t errmsg_len)
925 {
926 switch (error) {
927 case BGP_ERR_AF_UNCONFIGURED:
928 snprintf(errmsg, errmsg_len,
929 "%%BGP: Enable %s address family for the neighbor %s",
930 get_afi_safi_str(afi, safi, false), peer->host);
931 break;
932 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
933 snprintf(
934 errmsg, errmsg_len,
935 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig",
936 peer->host);
937 break;
938 default:
939 break;
940 }
941 }
942
943 static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi,
944 struct listnode **nnode, enum bgp_clear_type stype)
945 {
946 int ret = 0;
947 struct peer_af *paf;
948
949 /* if afi/.safi not specified, spin thru all of them */
950 if ((afi == AFI_UNSPEC) && (safi == SAFI_UNSPEC)) {
951 afi_t tmp_afi;
952 safi_t tmp_safi;
953
954 FOREACH_AFI_SAFI (tmp_afi, tmp_safi) {
955 paf = peer_af_find(peer, tmp_afi, tmp_safi);
956 if (paf && paf->subgroup)
957 SET_FLAG(paf->subgroup->sflags,
958 SUBGRP_STATUS_FORCE_UPDATES);
959
960 if (!peer->afc[tmp_afi][tmp_safi])
961 continue;
962
963 if (stype == BGP_CLEAR_SOFT_NONE)
964 ret = peer_clear(peer, nnode);
965 else
966 ret = peer_clear_soft(peer, tmp_afi, tmp_safi,
967 stype);
968 }
969 /* if afi specified and safi not, spin thru safis on this afi */
970 } else if (safi == SAFI_UNSPEC) {
971 safi_t tmp_safi;
972
973 for (tmp_safi = SAFI_UNICAST;
974 tmp_safi < SAFI_MAX; tmp_safi++) {
975 if (!peer->afc[afi][tmp_safi])
976 continue;
977
978 paf = peer_af_find(peer, afi, tmp_safi);
979 if (paf && paf->subgroup)
980 SET_FLAG(paf->subgroup->sflags,
981 SUBGRP_STATUS_FORCE_UPDATES);
982
983 if (stype == BGP_CLEAR_SOFT_NONE)
984 ret = peer_clear(peer, nnode);
985 else
986 ret = peer_clear_soft(peer, afi,
987 tmp_safi, stype);
988 }
989 /* both afi/safi specified, let the caller know if not defined */
990 } else {
991 if (!peer->afc[afi][safi])
992 return 1;
993
994 paf = peer_af_find(peer, afi, safi);
995 if (paf && paf->subgroup)
996 SET_FLAG(paf->subgroup->sflags,
997 SUBGRP_STATUS_FORCE_UPDATES);
998
999 if (stype == BGP_CLEAR_SOFT_NONE)
1000 ret = peer_clear(peer, nnode);
1001 else
1002 ret = peer_clear_soft(peer, afi, safi, stype);
1003 }
1004
1005 return ret;
1006 }
1007
1008 /* `clear ip bgp' functions. */
1009 static int bgp_clear(struct bgp *bgp, afi_t afi, safi_t safi,
1010 enum clear_sort sort, enum bgp_clear_type stype,
1011 const char *arg, char *errmsg, size_t errmsg_len)
1012 {
1013 int ret = 0;
1014 bool found = false;
1015 struct peer *peer;
1016
1017 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
1018
1019 /* Clear all neighbors. */
1020 /*
1021 * Pass along pointer to next node to peer_clear() when walking all
1022 * nodes on the BGP instance as that may get freed if it is a
1023 * doppelganger
1024 */
1025 if (sort == clear_all) {
1026 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1027
1028 bgp_peer_gr_flags_update(peer);
1029
1030 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1031 gr_router_detected = true;
1032
1033 ret = bgp_peer_clear(peer, afi, safi, &nnode,
1034 stype);
1035
1036 if (ret < 0)
1037 bgp_clear_vty_error(peer, afi, safi, ret,
1038 errmsg, errmsg_len);
1039 }
1040
1041 if (gr_router_detected
1042 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1043 bgp_zebra_send_capabilities(bgp, false);
1044 } else if (!gr_router_detected
1045 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1046 bgp_zebra_send_capabilities(bgp, true);
1047 }
1048
1049 /* This is to apply read-only mode on this clear. */
1050 if (stype == BGP_CLEAR_SOFT_NONE)
1051 bgp->update_delay_over = 0;
1052
1053 return CMD_SUCCESS;
1054 }
1055
1056 /* Clear specified neighbor. */
1057 if (sort == clear_peer) {
1058 union sockunion su;
1059
1060 /* Make sockunion for lookup. */
1061 ret = str2sockunion(arg, &su);
1062 if (ret < 0) {
1063 peer = peer_lookup_by_conf_if(bgp, arg);
1064 if (!peer) {
1065 peer = peer_lookup_by_hostname(bgp, arg);
1066 if (!peer) {
1067 snprintf(
1068 errmsg, errmsg_len,
1069 "Malformed address or name: %s",
1070 arg);
1071 return CMD_WARNING;
1072 }
1073 }
1074 } else {
1075 peer = peer_lookup(bgp, &su);
1076 if (!peer) {
1077 snprintf(errmsg, errmsg_len,
1078 "%%BGP: Unknown neighbor - \"%s\"",
1079 arg);
1080 return CMD_WARNING;
1081 }
1082 }
1083
1084 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
1085 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
1086
1087 ret = bgp_peer_clear(peer, afi, safi, NULL, stype);
1088
1089 /* if afi/safi not defined for this peer, let caller know */
1090 if (ret == 1)
1091 ret = BGP_ERR_AF_UNCONFIGURED;
1092
1093 if (ret < 0)
1094 bgp_clear_vty_error(peer, afi, safi, ret, errmsg,
1095 errmsg_len);
1096
1097 return CMD_SUCCESS;
1098 }
1099
1100 /* Clear all neighbors belonging to a specific peer-group. */
1101 if (sort == clear_group) {
1102 struct peer_group *group;
1103
1104 group = peer_group_lookup(bgp, arg);
1105 if (!group) {
1106 snprintf(errmsg, errmsg_len,
1107 "%%BGP: No such peer-group %s", arg);
1108 return CMD_WARNING;
1109 }
1110
1111 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
1112 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1113
1114 if (ret < 0)
1115 bgp_clear_vty_error(peer, afi, safi, ret,
1116 errmsg, errmsg_len);
1117 else
1118 found = true;
1119 }
1120
1121 if (!found)
1122 snprintf(
1123 errmsg, errmsg_len,
1124 "%%BGP: No %s peer belonging to peer-group %s is configured",
1125 get_afi_safi_str(afi, safi, false), arg);
1126
1127 return CMD_SUCCESS;
1128 }
1129
1130 /* Clear all external (eBGP) neighbors. */
1131 if (sort == clear_external) {
1132 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1133 if (peer->sort == BGP_PEER_IBGP)
1134 continue;
1135
1136 bgp_peer_gr_flags_update(peer);
1137
1138 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1139 gr_router_detected = true;
1140
1141 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1142
1143 if (ret < 0)
1144 bgp_clear_vty_error(peer, afi, safi, ret,
1145 errmsg, errmsg_len);
1146 else
1147 found = true;
1148 }
1149
1150 if (gr_router_detected
1151 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1152 bgp_zebra_send_capabilities(bgp, false);
1153 } else if (!gr_router_detected
1154 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1155 bgp_zebra_send_capabilities(bgp, true);
1156 }
1157
1158 if (!found)
1159 snprintf(errmsg, errmsg_len,
1160 "%%BGP: No external %s peer is configured",
1161 get_afi_safi_str(afi, safi, false));
1162
1163 return CMD_SUCCESS;
1164 }
1165
1166 /* Clear all neighbors belonging to a specific AS. */
1167 if (sort == clear_as) {
1168 as_t as = strtoul(arg, NULL, 10);
1169
1170 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1171 if (peer->as != as)
1172 continue;
1173
1174 bgp_peer_gr_flags_update(peer);
1175
1176 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1177 gr_router_detected = true;
1178
1179 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1180
1181 if (ret < 0)
1182 bgp_clear_vty_error(peer, afi, safi, ret,
1183 errmsg, errmsg_len);
1184 else
1185 found = true;
1186 }
1187
1188 if (gr_router_detected
1189 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1190 bgp_zebra_send_capabilities(bgp, false);
1191 } else if (!gr_router_detected
1192 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1193 bgp_zebra_send_capabilities(bgp, true);
1194 }
1195
1196 if (!found)
1197 snprintf(errmsg, errmsg_len,
1198 "%%BGP: No %s peer is configured with AS %s",
1199 get_afi_safi_str(afi, safi, false), arg);
1200
1201 return CMD_SUCCESS;
1202 }
1203
1204 return CMD_SUCCESS;
1205 }
1206
1207 static int bgp_clear_vty(const char *name, afi_t afi, safi_t safi,
1208 enum clear_sort sort, enum bgp_clear_type stype,
1209 const char *arg, char *errmsg, size_t errmsg_len)
1210 {
1211 struct bgp *bgp;
1212
1213 /* BGP structure lookup. */
1214 if (name) {
1215 bgp = bgp_lookup_by_name(name);
1216 if (bgp == NULL) {
1217 snprintf(errmsg, errmsg_len,
1218 "Can't find BGP instance %s", name);
1219 return CMD_WARNING;
1220 }
1221 } else {
1222 bgp = bgp_get_default();
1223 if (bgp == NULL) {
1224 snprintf(errmsg, errmsg_len,
1225 "No BGP process is configured");
1226 return CMD_WARNING;
1227 }
1228 }
1229
1230 return bgp_clear(bgp, afi, safi, sort, stype, arg, errmsg, errmsg_len);
1231 }
1232
1233 /* clear soft inbound */
1234 int bgp_clear_star_soft_in(const char *name, char *errmsg, size_t errmsg_len)
1235 {
1236 afi_t afi;
1237 safi_t safi;
1238 int ret;
1239
1240 FOREACH_AFI_SAFI (afi, safi) {
1241 ret = bgp_clear_vty(name, afi, safi, clear_all,
1242 BGP_CLEAR_SOFT_IN, NULL, errmsg,
1243 errmsg_len);
1244 if (ret != CMD_SUCCESS)
1245 return -1;
1246 }
1247
1248 return 0;
1249 }
1250
1251 /* clear soft outbound */
1252 int bgp_clear_star_soft_out(const char *name, char *errmsg, size_t errmsg_len)
1253 {
1254 afi_t afi;
1255 safi_t safi;
1256 int ret;
1257
1258 FOREACH_AFI_SAFI (afi, safi) {
1259 ret = bgp_clear_vty(name, afi, safi, clear_all,
1260 BGP_CLEAR_SOFT_OUT, NULL, errmsg,
1261 errmsg_len);
1262 if (ret != CMD_SUCCESS)
1263 return -1;
1264 }
1265
1266 return 0;
1267 }
1268
1269
1270 #ifndef VTYSH_EXTRACT_PL
1271 #include "bgpd/bgp_vty_clippy.c"
1272 #endif
1273
1274 DEFUN_HIDDEN (bgp_local_mac,
1275 bgp_local_mac_cmd,
1276 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
1277 BGP_STR
1278 "Local MAC config\n"
1279 "VxLAN Network Identifier\n"
1280 "VNI number\n"
1281 "local mac\n"
1282 "mac address\n"
1283 "mac-mobility sequence\n"
1284 "seq number\n")
1285 {
1286 int rv;
1287 vni_t vni;
1288 struct ethaddr mac;
1289 struct ipaddr ip;
1290 uint32_t seq;
1291 struct bgp *bgp;
1292
1293 vni = strtoul(argv[3]->arg, NULL, 10);
1294 if (!prefix_str2mac(argv[5]->arg, &mac)) {
1295 vty_out(vty, "%% Malformed MAC address\n");
1296 return CMD_WARNING;
1297 }
1298 memset(&ip, 0, sizeof(ip));
1299 seq = strtoul(argv[7]->arg, NULL, 10);
1300
1301 bgp = bgp_get_default();
1302 if (!bgp) {
1303 vty_out(vty, "Default BGP instance is not there\n");
1304 return CMD_WARNING;
1305 }
1306
1307 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq,
1308 zero_esi);
1309 if (rv < 0) {
1310 vty_out(vty, "Internal error\n");
1311 return CMD_WARNING;
1312 }
1313
1314 return CMD_SUCCESS;
1315 }
1316
1317 DEFUN_HIDDEN (no_bgp_local_mac,
1318 no_bgp_local_mac_cmd,
1319 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
1320 NO_STR
1321 BGP_STR
1322 "Local MAC config\n"
1323 "VxLAN Network Identifier\n"
1324 "VNI number\n"
1325 "local mac\n"
1326 "mac address\n")
1327 {
1328 int rv;
1329 vni_t vni;
1330 struct ethaddr mac;
1331 struct ipaddr ip;
1332 struct bgp *bgp;
1333
1334 vni = strtoul(argv[4]->arg, NULL, 10);
1335 if (!prefix_str2mac(argv[6]->arg, &mac)) {
1336 vty_out(vty, "%% Malformed MAC address\n");
1337 return CMD_WARNING;
1338 }
1339 memset(&ip, 0, sizeof(ip));
1340
1341 bgp = bgp_get_default();
1342 if (!bgp) {
1343 vty_out(vty, "Default BGP instance is not there\n");
1344 return CMD_WARNING;
1345 }
1346
1347 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
1348 if (rv < 0) {
1349 vty_out(vty, "Internal error\n");
1350 return CMD_WARNING;
1351 }
1352
1353 return CMD_SUCCESS;
1354 }
1355
1356 DEFUN (no_synchronization,
1357 no_synchronization_cmd,
1358 "no synchronization",
1359 NO_STR
1360 "Perform IGP synchronization\n")
1361 {
1362 return CMD_SUCCESS;
1363 }
1364
1365 DEFUN (no_auto_summary,
1366 no_auto_summary_cmd,
1367 "no auto-summary",
1368 NO_STR
1369 "Enable automatic network number summarization\n")
1370 {
1371 return CMD_SUCCESS;
1372 }
1373
1374 /* "router bgp" commands. */
1375 DEFUN_YANG_NOSH(router_bgp,
1376 router_bgp_cmd,
1377 "router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1378 ROUTER_STR BGP_STR AS_STR BGP_INSTANCE_HELP_STR)
1379 {
1380 int idx_asn = 2;
1381 int idx_view_vrf = 3;
1382 int idx_vrf = 4;
1383 int ret = CMD_SUCCESS;
1384 as_t as;
1385 struct bgp *bgp;
1386 const char *name = NULL;
1387 enum bgp_instance_type inst_type;
1388 char base_xpath[XPATH_MAXLEN];
1389 const struct lyd_node *bgp_glb_dnode;
1390
1391 // "router bgp" without an ASN
1392 if (argc == 2) {
1393 // Pending: Make VRF option available for ASN less config
1394 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_GLOBAL_XPATH,
1395 "frr-bgp:bgp", "bgp", VRF_DEFAULT_NAME);
1396
1397 bgp_glb_dnode = yang_dnode_get(vty->candidate_config->dnode,
1398 base_xpath);
1399 if (!bgp_glb_dnode) {
1400 vty_out(vty, "%% No BGP process is configured\n");
1401 return CMD_WARNING_CONFIG_FAILED;
1402 }
1403
1404 if (listcount(bm->bgp) > 1) {
1405 vty_out(vty, "%% Please specify ASN and VRF\n");
1406 return CMD_WARNING_CONFIG_FAILED;
1407 }
1408
1409 as = yang_dnode_get_uint32(bgp_glb_dnode, "./global/local-as");
1410
1411 VTY_PUSH_XPATH(BGP_NODE, base_xpath);
1412
1413 /*
1414 * For backward compatibility with old commands we still
1415 * need to use the qobj infrastructure.
1416 */
1417 bgp = bgp_lookup(as, NULL);
1418 if (bgp)
1419 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1420
1421 return CMD_SUCCESS;
1422 }
1423
1424 // "router bgp X"
1425 else {
1426
1427 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1428 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1429 if (argc > 3) {
1430 name = argv[idx_vrf]->arg;
1431
1432 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1433 if (strmatch(name, VRF_DEFAULT_NAME))
1434 name = NULL;
1435 else
1436 inst_type = BGP_INSTANCE_TYPE_VRF;
1437 } else if (!strcmp(argv[idx_view_vrf]->text, "view")) {
1438 inst_type = BGP_INSTANCE_TYPE_VIEW;
1439 }
1440 }
1441 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_GLOBAL_XPATH,
1442 "frr-bgp:bgp", "bgp", name ? name : VRF_DEFAULT_NAME);
1443
1444 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
1445 nb_cli_enqueue_change(vty, "./global/local-as", NB_OP_MODIFY,
1446 argv[idx_asn]->arg);
1447 if (inst_type == BGP_INSTANCE_TYPE_VIEW) {
1448 nb_cli_enqueue_change(vty,
1449 "./global/instance-type-view",
1450 NB_OP_MODIFY, "true");
1451 } else {
1452 nb_cli_enqueue_change(vty,
1453 "./global/instance-type-view",
1454 NB_OP_MODIFY, "false");
1455 }
1456
1457 ret = nb_cli_apply_changes_clear_pending(vty, base_xpath);
1458 if (ret == CMD_SUCCESS) {
1459 VTY_PUSH_XPATH(BGP_NODE, base_xpath);
1460
1461 /*
1462 * For backward compatibility with old commands we still
1463 * need to use the qobj infrastructure.
1464 */
1465 bgp = bgp_lookup(as, name);
1466 if (bgp)
1467 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1468 }
1469 }
1470
1471 return ret;
1472 }
1473
1474 /* "no router bgp" commands. */
1475 DEFUN_YANG(no_router_bgp,
1476 no_router_bgp_cmd,
1477 "no router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1478 NO_STR ROUTER_STR BGP_STR AS_STR BGP_INSTANCE_HELP_STR)
1479 {
1480 int idx_vrf = 5;
1481 const char *name = NULL;
1482 char base_xpath[XPATH_MAXLEN];
1483 const struct lyd_node *bgp_glb_dnode;
1484
1485 // "no router bgp" without an ASN
1486 if (argc == 3) {
1487 // Pending: Make VRF option available for ASN less config
1488 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_GLOBAL_XPATH,
1489 "frr-bgp:bgp", "bgp", VRF_DEFAULT_NAME);
1490
1491 bgp_glb_dnode = yang_dnode_get(vty->candidate_config->dnode,
1492 base_xpath);
1493 if (!bgp_glb_dnode) {
1494 vty_out(vty, "%% No BGP process is configured\n");
1495 return CMD_WARNING_CONFIG_FAILED;
1496 }
1497
1498 if (listcount(bm->bgp) > 1) {
1499 vty_out(vty, "%% Please specify ASN and VRF\n");
1500 return CMD_WARNING_CONFIG_FAILED;
1501 }
1502 } else {
1503 if (argc > 4)
1504 name = argv[idx_vrf]->arg;
1505 else
1506 name = VRF_DEFAULT_NAME;
1507
1508 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_GLOBAL_XPATH,
1509 "frr-bgp:bgp", "bgp", name);
1510 }
1511
1512 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
1513
1514 /* We want to finish any classic config after a no router */
1515 return nb_cli_apply_changes_clear_pending(vty, base_xpath);
1516 }
1517
1518 void cli_show_router_bgp(struct vty *vty, struct lyd_node *dnode,
1519 bool show_defaults)
1520 {
1521 const struct lyd_node *vrf_dnode;
1522 const char *vrf_name;
1523 as_t as;
1524
1525 vrf_dnode = yang_dnode_get_parent(dnode, "control-plane-protocol");
1526 vrf_name = yang_dnode_get_string(vrf_dnode, "./vrf");
1527 as = yang_dnode_get_uint32(dnode, "./global/local-as");
1528
1529 vty_out(vty, "!\n");
1530 vty_out(vty, "router bgp %u", as);
1531 if (!strmatch(vrf_name, VRF_DEFAULT_NAME))
1532 vty_out(vty, " vrf %s", vrf_name);
1533 vty_out(vty, "\n");
1534 }
1535
1536 /* BGP router-id. */
1537
1538 DEFPY_YANG(bgp_router_id, bgp_router_id_cmd, "bgp router-id A.B.C.D",
1539 BGP_STR
1540 "Override configured router identifier\n"
1541 "Manually configured router identifier\n")
1542 {
1543 nb_cli_enqueue_change(vty, "./global/router-id", NB_OP_MODIFY,
1544 router_id_str);
1545
1546 return nb_cli_apply_changes(vty, NULL);
1547 }
1548
1549 DEFPY_YANG(no_bgp_router_id, no_bgp_router_id_cmd, "no bgp router-id [A.B.C.D]",
1550 NO_STR BGP_STR
1551 "Override configured router identifier\n"
1552 "Manually configured router identifier\n")
1553 {
1554 nb_cli_enqueue_change(vty, "./global/router-id", NB_OP_DESTROY,
1555 router_id_str ? router_id_str : NULL);
1556
1557 return nb_cli_apply_changes(vty, NULL);
1558 }
1559
1560 void cli_show_router_bgp_router_id(struct vty *vty, struct lyd_node *dnode,
1561 bool show_defaults)
1562 {
1563 vty_out(vty, " bgp router-id %s\n", yang_dnode_get_string(dnode, NULL));
1564 }
1565
1566 DEFPY(bgp_community_alias, bgp_community_alias_cmd,
1567 "[no$no] bgp community alias WORD$community WORD$alias",
1568 NO_STR BGP_STR
1569 "Add community specific parameters\n"
1570 "Create an alias for a community\n"
1571 "Community (AA:BB or AA:BB:CC)\n"
1572 "Alias name\n")
1573 {
1574 struct community_alias ca1;
1575 struct community_alias ca2;
1576 struct community_alias *lookup_community;
1577 struct community_alias *lookup_alias;
1578
1579 if (!community_str2com(community) && !lcommunity_str2com(community)) {
1580 vty_out(vty, "Invalid community format\n");
1581 return CMD_WARNING;
1582 }
1583
1584 memset(&ca1, 0, sizeof(ca1));
1585 memset(&ca2, 0, sizeof(ca2));
1586 strlcpy(ca1.community, community, sizeof(ca1.community));
1587 strlcpy(ca1.alias, alias, sizeof(ca1.alias));
1588
1589 lookup_community = bgp_ca_community_lookup(&ca1);
1590 lookup_alias = bgp_ca_alias_lookup(&ca1);
1591
1592 if (no) {
1593 bgp_ca_alias_delete(&ca1);
1594 bgp_ca_community_delete(&ca1);
1595 } else {
1596 if (lookup_alias) {
1597 /* Lookup if community hash table has an item
1598 * with the same alias name.
1599 */
1600 strlcpy(ca2.community, lookup_alias->community,
1601 sizeof(ca2.community));
1602 if (bgp_ca_community_lookup(&ca2)) {
1603 vty_out(vty,
1604 "community (%s) already has this alias (%s)\n",
1605 lookup_alias->community,
1606 lookup_alias->alias);
1607 return CMD_WARNING;
1608 }
1609 bgp_ca_alias_delete(&ca1);
1610 }
1611
1612 if (lookup_community)
1613 bgp_ca_community_delete(&ca1);
1614
1615 bgp_ca_alias_insert(&ca1);
1616 bgp_ca_community_insert(&ca1);
1617 }
1618
1619 return CMD_SUCCESS;
1620 }
1621
1622 DEFPY (bgp_global_suppress_fib_pending,
1623 bgp_global_suppress_fib_pending_cmd,
1624 "[no] bgp suppress-fib-pending",
1625 NO_STR
1626 BGP_STR
1627 "Advertise only routes that are programmed in kernel to peers globally\n")
1628 {
1629 bm_wait_for_fib_set(!no);
1630
1631 return CMD_SUCCESS;
1632 }
1633
1634 DEFPY (bgp_suppress_fib_pending,
1635 bgp_suppress_fib_pending_cmd,
1636 "[no] bgp suppress-fib-pending",
1637 NO_STR
1638 BGP_STR
1639 "Advertise only routes that are programmed in kernel to peers\n")
1640 {
1641 VTY_DECLVAR_CONTEXT(bgp, bgp);
1642
1643 bgp_suppress_fib_pending_set(bgp, !no);
1644 return CMD_SUCCESS;
1645 }
1646
1647
1648 /* BGP Cluster ID. */
1649 DEFUN_YANG(bgp_cluster_id,
1650 bgp_cluster_id_cmd,
1651 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1652 BGP_STR
1653 "Configure Route-Reflector Cluster-id\n"
1654 "Route-Reflector Cluster-id in IP address format\n"
1655 "Route-Reflector Cluster-id as 32 bit quantity\n")
1656 {
1657 int idx_ipv4 = 2;
1658
1659 nb_cli_enqueue_change(
1660 vty, "./global/route-reflector/route-reflector-cluster-id",
1661 NB_OP_MODIFY, argv[idx_ipv4]->arg);
1662
1663 return nb_cli_apply_changes(vty, NULL);
1664 }
1665
1666 DEFUN_YANG(no_bgp_cluster_id,
1667 no_bgp_cluster_id_cmd,
1668 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1669 NO_STR BGP_STR
1670 "Configure Route-Reflector Cluster-id\n"
1671 "Route-Reflector Cluster-id in IP address format\n"
1672 "Route-Reflector Cluster-id as 32 bit quantity\n")
1673 {
1674 nb_cli_enqueue_change(
1675 vty, "./global/route-reflector/route-reflector-cluster-id",
1676 NB_OP_DESTROY, NULL);
1677
1678 return nb_cli_apply_changes(vty, NULL);
1679 }
1680
1681 DEFPY (bgp_norib,
1682 bgp_norib_cmd,
1683 "bgp no-rib",
1684 BGP_STR
1685 "Disable BGP route installation to RIB (Zebra)\n")
1686 {
1687 if (bgp_option_check(BGP_OPT_NO_FIB)) {
1688 vty_out(vty,
1689 "%% No-RIB option is already set, nothing to do here.\n");
1690 return CMD_SUCCESS;
1691 }
1692
1693 bgp_option_norib_set_runtime();
1694
1695 return CMD_SUCCESS;
1696 }
1697
1698 DEFPY (no_bgp_norib,
1699 no_bgp_norib_cmd,
1700 "no bgp no-rib",
1701 NO_STR
1702 BGP_STR
1703 "Disable BGP route installation to RIB (Zebra)\n")
1704 {
1705 if (!bgp_option_check(BGP_OPT_NO_FIB)) {
1706 vty_out(vty,
1707 "%% No-RIB option is not set, nothing to do here.\n");
1708 return CMD_SUCCESS;
1709 }
1710
1711 bgp_option_norib_unset_runtime();
1712
1713 return CMD_SUCCESS;
1714 }
1715
1716 DEFPY (no_bgp_send_extra_data,
1717 no_bgp_send_extra_data_cmd,
1718 "[no] bgp send-extra-data zebra",
1719 NO_STR
1720 BGP_STR
1721 "Extra data to Zebra for display/use\n"
1722 "To zebra\n")
1723 {
1724 if (no)
1725 UNSET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1726 else
1727 SET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1728
1729 return CMD_SUCCESS;
1730 }
1731
1732 DEFUN_YANG(bgp_confederation_identifier,
1733 bgp_confederation_identifier_cmd,
1734 "bgp confederation identifier (1-4294967295)",
1735 "BGP specific commands\n"
1736 "AS confederation parameters\n"
1737 "AS number\n"
1738 "Set routing domain confederation AS\n")
1739 {
1740 int idx_number = 3;
1741
1742 nb_cli_enqueue_change(vty, "./global/confederation/identifier",
1743 NB_OP_MODIFY, argv[idx_number]->arg);
1744
1745 return nb_cli_apply_changes(vty, NULL);
1746 }
1747
1748 DEFUN_YANG(no_bgp_confederation_identifier,
1749 no_bgp_confederation_identifier_cmd,
1750 "no bgp confederation identifier [(1-4294967295)]",
1751 NO_STR
1752 "BGP specific commands\n"
1753 "AS confederation parameters\n"
1754 "AS number\n"
1755 "Set routing domain confederation AS\n")
1756 {
1757 nb_cli_enqueue_change(vty, "./global/confederation/identifier",
1758 NB_OP_DESTROY, NULL);
1759
1760 return nb_cli_apply_changes(vty, NULL);
1761 }
1762
1763 void cli_show_router_bgp_confederation_identifier(struct vty *vty,
1764 struct lyd_node *dnode,
1765 bool show_defaults)
1766 {
1767 vty_out(vty, " bgp confederation identifier %u\n",
1768 yang_dnode_get_uint32(dnode, NULL));
1769 }
1770
1771 DEFUN_YANG(bgp_confederation_peers,
1772 bgp_confederation_peers_cmd,
1773 "bgp confederation peers (1-4294967295)...",
1774 "BGP specific commands\n"
1775 "AS confederation parameters\n"
1776 "Peer ASs in BGP confederation\n" AS_STR)
1777 {
1778 int idx_asn = 3;
1779 int i;
1780
1781 for (i = idx_asn; i < argc; i++)
1782 nb_cli_enqueue_change(vty, "./global/confederation/member-as",
1783 NB_OP_CREATE, argv[i]->arg);
1784
1785 return nb_cli_apply_changes(vty, NULL);
1786 }
1787
1788 DEFUN_YANG(no_bgp_confederation_peers,
1789 no_bgp_confederation_peers_cmd,
1790 "no bgp confederation peers (1-4294967295)...",
1791 NO_STR
1792 "BGP specific commands\n"
1793 "AS confederation parameters\n"
1794 "Peer ASs in BGP confederation\n" AS_STR)
1795 {
1796 int idx_asn = 4;
1797 int i;
1798
1799 for (i = idx_asn; i < argc; i++)
1800 nb_cli_enqueue_change(vty, "./global/confederation/member-as",
1801 NB_OP_DESTROY, argv[i]->arg);
1802
1803 return nb_cli_apply_changes(vty, NULL);
1804 }
1805
1806 void cli_show_router_bgp_confederation_member_as(struct vty *vty,
1807 struct lyd_node *dnode,
1808 bool show_defaults)
1809 {
1810 vty_out(vty, " bgp confederation peers %u \n",
1811 yang_dnode_get_uint32(dnode, NULL));
1812 }
1813
1814 /**
1815 * Central routine for maximum-paths configuration.
1816 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1817 * @set: 1 for setting values, 0 for removing the max-paths config.
1818 */
1819 int bgp_maxpaths_config_vty(struct bgp *bgp, afi_t afi, safi_t safi,
1820 int peer_type, uint16_t maxpaths, uint16_t options,
1821 int set, char *errmsg, size_t errmsg_len)
1822 {
1823 int ret;
1824
1825 if (set) {
1826 if (maxpaths > multipath_num) {
1827 snprintf(
1828 errmsg, errmsg_len,
1829 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1830 maxpaths, multipath_num);
1831 return CMD_WARNING_CONFIG_FAILED;
1832 }
1833 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1834 options);
1835 } else
1836 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1837
1838 if (ret < 0) {
1839 snprintf(
1840 errmsg, errmsg_len,
1841 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1842 (set == 1) ? "" : "un",
1843 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1844 maxpaths, afi, safi);
1845 return CMD_WARNING_CONFIG_FAILED;
1846 }
1847
1848 bgp_recalculate_all_bestpaths(bgp);
1849
1850 return CMD_SUCCESS;
1851 }
1852
1853 void cli_show_router_bgp_med_config(struct vty *vty, struct lyd_node *dnode,
1854 bool show_defaults)
1855 {
1856 if (yang_dnode_get_bool(dnode, "./enable-med-admin")) {
1857 uint32_t med_admin_val;
1858
1859 vty_out(vty, " bgp max-med administrative");
1860 if ((med_admin_val =
1861 yang_dnode_get_uint32(dnode, "./max-med-admin"))
1862 != BGP_MAXMED_VALUE_DEFAULT)
1863 vty_out(vty, " %u", med_admin_val);
1864 vty_out(vty, "\n");
1865 }
1866
1867 if (yang_dnode_exists(dnode, "./max-med-onstart-up-time")) {
1868 uint32_t onstartup_val;
1869
1870 vty_out(vty, " bgp max-med on-startup %u",
1871 yang_dnode_get_uint32(dnode,
1872 "./max-med-onstart-up-time"));
1873 onstartup_val = yang_dnode_get_uint32(
1874 dnode, "./max-med-onstart-up-value");
1875 if (onstartup_val != BGP_MAXMED_VALUE_DEFAULT)
1876 vty_out(vty, " %u", onstartup_val);
1877
1878 vty_out(vty, "\n");
1879 }
1880 }
1881
1882 DEFUN_YANG(bgp_maxmed_admin,
1883 bgp_maxmed_admin_cmd,
1884 "bgp max-med administrative ",
1885 BGP_STR
1886 "Advertise routes with max-med\n"
1887 "Administratively applied, for an indefinite period\n")
1888 {
1889 nb_cli_enqueue_change(vty, "./global/med-config/enable-med-admin",
1890 NB_OP_MODIFY, "true");
1891
1892 return nb_cli_apply_changes(vty, NULL);
1893 }
1894
1895 DEFUN_YANG(bgp_maxmed_admin_medv,
1896 bgp_maxmed_admin_medv_cmd,
1897 "bgp max-med administrative (0-4294967295)",
1898 BGP_STR
1899 "Advertise routes with max-med\n"
1900 "Administratively applied, for an indefinite period\n"
1901 "Max MED value to be used\n")
1902 {
1903 int idx_number = 3;
1904
1905 nb_cli_enqueue_change(vty, "./global/med-config/enable-med-admin",
1906 NB_OP_MODIFY, "true");
1907
1908 nb_cli_enqueue_change(vty, "./global/med-config/max-med-admin",
1909 NB_OP_MODIFY, argv[idx_number]->arg);
1910
1911 return nb_cli_apply_changes(vty, NULL);
1912 }
1913
1914 DEFUN_YANG(no_bgp_maxmed_admin,
1915 no_bgp_maxmed_admin_cmd,
1916 "no bgp max-med administrative [(0-4294967295)]",
1917 NO_STR BGP_STR
1918 "Advertise routes with max-med\n"
1919 "Administratively applied, for an indefinite period\n"
1920 "Max MED value to be used\n")
1921 {
1922 nb_cli_enqueue_change(vty, "./global/med-config/enable-med-admin",
1923 NB_OP_MODIFY, "false");
1924
1925 nb_cli_enqueue_change(vty, "./global/med-config/max-med-admin",
1926 NB_OP_MODIFY, NULL);
1927
1928 return nb_cli_apply_changes(vty, NULL);
1929 }
1930
1931 DEFUN_YANG (bgp_maxmed_onstartup,
1932 bgp_maxmed_onstartup_cmd,
1933 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
1934 BGP_STR
1935 "Advertise routes with max-med\n"
1936 "Effective on a startup\n"
1937 "Time (seconds) period for max-med\n"
1938 "Max MED value to be used\n")
1939 {
1940 int idx = 0;
1941
1942 argv_find(argv, argc, "(5-86400)", &idx);
1943 nb_cli_enqueue_change(vty,
1944 "./global/med-config/max-med-onstart-up-time",
1945 NB_OP_MODIFY, argv[idx]->arg);
1946
1947 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1948 nb_cli_enqueue_change(
1949 vty, "./global/med-config/max-med-onstart-up-value",
1950 NB_OP_MODIFY, argv[idx]->arg);
1951 else
1952 nb_cli_enqueue_change(
1953 vty, "./global/med-config/max-med-onstart-up-value",
1954 NB_OP_MODIFY, NULL);
1955
1956 return nb_cli_apply_changes(vty, NULL);
1957 }
1958
1959 DEFUN_YANG (no_bgp_maxmed_onstartup,
1960 no_bgp_maxmed_onstartup_cmd,
1961 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
1962 NO_STR BGP_STR
1963 "Advertise routes with max-med\n"
1964 "Effective on a startup\n"
1965 "Time (seconds) period for max-med\n"
1966 "Max MED value to be used\n")
1967 {
1968 nb_cli_enqueue_change(vty,
1969 "./global/med-config/max-med-onstart-up-time",
1970 NB_OP_DESTROY, NULL);
1971
1972 nb_cli_enqueue_change(vty,
1973 "./global/med-config/max-med-onstart-up-value",
1974 NB_OP_MODIFY, NULL);
1975
1976 return nb_cli_apply_changes(vty, NULL);
1977 }
1978
1979 static int bgp_global_update_delay_config_vty(struct vty *vty,
1980 uint16_t update_delay,
1981 uint16_t establish_wait)
1982 {
1983 struct listnode *node, *nnode;
1984 struct bgp *bgp;
1985 bool vrf_cfg = false;
1986
1987 /*
1988 * See if update-delay is set per-vrf and warn user to delete it
1989 * Note that we only need to check this if this is the first time
1990 * setting the global config.
1991 */
1992 if (bm->v_update_delay == BGP_UPDATE_DELAY_DEF) {
1993 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
1994 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1995 vty_out(vty,
1996 "%% update-delay configuration found in vrf %s\n",
1997 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT
1998 ? VRF_DEFAULT_NAME
1999 : bgp->name);
2000 vrf_cfg = true;
2001 }
2002 }
2003 }
2004
2005 if (vrf_cfg) {
2006 vty_out(vty,
2007 "%%Failed: global update-delay config not permitted\n");
2008 return CMD_WARNING;
2009 }
2010
2011 if (!establish_wait) { /* update-delay <delay> */
2012 bm->v_update_delay = update_delay;
2013 bm->v_establish_wait = bm->v_update_delay;
2014 } else {
2015 /* update-delay <delay> <establish-wait> */
2016 if (update_delay < establish_wait) {
2017 vty_out(vty,
2018 "%%Failed: update-delay less than the establish-wait!\n");
2019 return CMD_WARNING_CONFIG_FAILED;
2020 }
2021
2022 bm->v_update_delay = update_delay;
2023 bm->v_establish_wait = establish_wait;
2024 }
2025
2026 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2027 bgp->v_update_delay = bm->v_update_delay;
2028 bgp->v_establish_wait = bm->v_establish_wait;
2029 }
2030
2031 return CMD_SUCCESS;
2032 }
2033
2034 static int bgp_global_update_delay_deconfig_vty(struct vty *vty)
2035 {
2036 struct listnode *node, *nnode;
2037 struct bgp *bgp;
2038
2039 bm->v_update_delay = BGP_UPDATE_DELAY_DEF;
2040 bm->v_establish_wait = bm->v_update_delay;
2041
2042 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2043 bgp->v_update_delay = bm->v_update_delay;
2044 bgp->v_establish_wait = bm->v_establish_wait;
2045 }
2046
2047 return CMD_SUCCESS;
2048 }
2049
2050 static int bgp_update_delay_config_vty(struct vty *vty, uint16_t update_delay,
2051 uint16_t establish_wait)
2052 {
2053 VTY_DECLVAR_CONTEXT(bgp, bgp);
2054
2055 /* if configured globally, per-instance config is not allowed */
2056 if (bm->v_update_delay) {
2057 vty_out(vty,
2058 "%%Failed: per-vrf update-delay config not permitted with global update-delay\n");
2059 return CMD_WARNING_CONFIG_FAILED;
2060 }
2061
2062
2063 if (!establish_wait) /* update-delay <delay> */
2064 {
2065 bgp->v_update_delay = update_delay;
2066 bgp->v_establish_wait = bgp->v_update_delay;
2067 return CMD_SUCCESS;
2068 }
2069
2070 /* update-delay <delay> <establish-wait> */
2071 if (update_delay < establish_wait) {
2072 vty_out(vty,
2073 "%%Failed: update-delay less than the establish-wait!\n");
2074 return CMD_WARNING_CONFIG_FAILED;
2075 }
2076
2077 bgp->v_update_delay = update_delay;
2078 bgp->v_establish_wait = establish_wait;
2079
2080 return CMD_SUCCESS;
2081 }
2082
2083 static int bgp_update_delay_deconfig_vty(struct vty *vty)
2084 {
2085 VTY_DECLVAR_CONTEXT(bgp, bgp);
2086
2087 /* If configured globally, cannot remove from one bgp instance */
2088 if (bm->v_update_delay) {
2089 vty_out(vty,
2090 "%%Failed: bgp update-delay configured globally. Delete per-vrf not permitted\n");
2091 return CMD_WARNING_CONFIG_FAILED;
2092 }
2093 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
2094 bgp->v_establish_wait = bgp->v_update_delay;
2095
2096 return CMD_SUCCESS;
2097 }
2098
2099 void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
2100 {
2101 /* If configured globally, no need to display per-instance value */
2102 if (bgp->v_update_delay != bm->v_update_delay) {
2103 vty_out(vty, " update-delay %d", bgp->v_update_delay);
2104 if (bgp->v_update_delay != bgp->v_establish_wait)
2105 vty_out(vty, " %d", bgp->v_establish_wait);
2106 vty_out(vty, "\n");
2107 }
2108 }
2109
2110 /* Global update-delay configuration */
2111 DEFPY (bgp_global_update_delay,
2112 bgp_global_update_delay_cmd,
2113 "bgp update-delay (0-3600)$delay [(1-3600)$wait]",
2114 BGP_STR
2115 "Force initial delay for best-path and updates for all bgp instances\n"
2116 "Max delay in seconds\n"
2117 "Establish wait in seconds\n")
2118 {
2119 return bgp_global_update_delay_config_vty(vty, delay, wait);
2120 }
2121
2122 /* Global update-delay deconfiguration */
2123 DEFPY (no_bgp_global_update_delay,
2124 no_bgp_global_update_delay_cmd,
2125 "no bgp update-delay [(0-3600) [(1-3600)]]",
2126 NO_STR
2127 BGP_STR
2128 "Force initial delay for best-path and updates\n"
2129 "Max delay in seconds\n"
2130 "Establish wait in seconds\n")
2131 {
2132 return bgp_global_update_delay_deconfig_vty(vty);
2133 }
2134
2135 /* Update-delay configuration */
2136
2137 DEFPY (bgp_update_delay,
2138 bgp_update_delay_cmd,
2139 "update-delay (0-3600)$delay [(1-3600)$wait]",
2140 "Force initial delay for best-path and updates\n"
2141 "Max delay in seconds\n"
2142 "Establish wait in seconds\n")
2143 {
2144 return bgp_update_delay_config_vty(vty, delay, wait);
2145 }
2146
2147 /* Update-delay deconfiguration */
2148 DEFPY (no_bgp_update_delay,
2149 no_bgp_update_delay_cmd,
2150 "no update-delay [(0-3600) [(1-3600)]]",
2151 NO_STR
2152 "Force initial delay for best-path and updates\n"
2153 "Max delay in seconds\n"
2154 "Establish wait in seconds\n")
2155 {
2156 return bgp_update_delay_deconfig_vty(vty);
2157 }
2158
2159
2160 int bgp_wpkt_quanta_config_vty(struct bgp *bgp, uint32_t quanta, bool set)
2161 {
2162 quanta = set ? quanta : BGP_WRITE_PACKET_MAX;
2163 atomic_store_explicit(&bgp->wpkt_quanta, quanta, memory_order_relaxed);
2164
2165 return CMD_SUCCESS;
2166 }
2167
2168 int bgp_rpkt_quanta_config_vty(struct bgp *bgp, uint32_t quanta, bool set)
2169 {
2170 quanta = set ? quanta : BGP_READ_PACKET_MAX;
2171 atomic_store_explicit(&bgp->rpkt_quanta, quanta, memory_order_relaxed);
2172
2173 return CMD_SUCCESS;
2174 }
2175
2176 void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
2177 {
2178 uint32_t quanta =
2179 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
2180 if (quanta != BGP_WRITE_PACKET_MAX)
2181 vty_out(vty, " write-quanta %d\n", quanta);
2182 }
2183
2184 void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
2185 {
2186 uint32_t quanta =
2187 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
2188 if (quanta != BGP_READ_PACKET_MAX)
2189 vty_out(vty, " read-quanta %d\n", quanta);
2190 }
2191
2192 /* Packet quanta configuration
2193 *
2194 * XXX: The value set here controls the size of a stack buffer in the IO
2195 * thread. When changing these limits be careful to prevent stack overflow.
2196 *
2197 * Furthermore, the maximums used here should correspond to
2198 * BGP_WRITE_PACKET_MAX and BGP_READ_PACKET_MAX.
2199 */
2200 DEFPY_YANG (bgp_wpkt_quanta,
2201 bgp_wpkt_quanta_cmd,
2202 "[no] write-quanta (1-64)$quanta",
2203 NO_STR
2204 "How many packets to write to peer socket per run\n"
2205 "Number of packets\n")
2206 {
2207 if (!no)
2208 nb_cli_enqueue_change(
2209 vty,
2210 "./global/global-neighbor-config/packet-quanta-config/wpkt-quanta",
2211 NB_OP_MODIFY, quanta_str);
2212 else
2213 nb_cli_enqueue_change(
2214 vty,
2215 "./global/global-neighbor-config/packet-quanta-config/wpkt-quanta",
2216 NB_OP_MODIFY, NULL);
2217
2218 return nb_cli_apply_changes(vty, NULL);
2219 }
2220
2221 DEFPY_YANG (bgp_rpkt_quanta,
2222 bgp_rpkt_quanta_cmd,
2223 "[no] read-quanta (1-10)$quanta",
2224 NO_STR
2225 "How many packets to read from peer socket per I/O cycle\n"
2226 "Number of packets\n")
2227 {
2228 if (!no)
2229 nb_cli_enqueue_change(
2230 vty,
2231 "./global/global-neighbor-config/packet-quanta-config/rpkt-quanta",
2232 NB_OP_MODIFY, quanta_str);
2233 else
2234 nb_cli_enqueue_change(
2235 vty,
2236 "./global/global-neighbor-config/packet-quanta-config/rpkt-quanta",
2237 NB_OP_MODIFY, NULL);
2238
2239 return nb_cli_apply_changes(vty, NULL);
2240 }
2241
2242 void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
2243 {
2244 if (!bgp->heuristic_coalesce)
2245 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
2246 }
2247
2248 void cli_show_router_global_update_group_config_coalesce_time(
2249 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
2250 {
2251 vty_out(vty, " coalesce-time %u\n", yang_dnode_get_uint32(dnode, NULL));
2252 }
2253
2254
2255 DEFUN_YANG (bgp_coalesce_time,
2256 bgp_coalesce_time_cmd,
2257 "coalesce-time (0-4294967295)",
2258 "Subgroup coalesce timer\n"
2259 "Subgroup coalesce timer value (in ms)\n")
2260 {
2261 int idx = 0;
2262
2263 argv_find(argv, argc, "(0-4294967295)", &idx);
2264 nb_cli_enqueue_change(
2265 vty, "./global/global-update-group-config/coalesce-time",
2266 NB_OP_MODIFY, argv[idx]->arg);
2267
2268 return nb_cli_apply_changes(vty, NULL);
2269 }
2270
2271 DEFUN_YANG(no_bgp_coalesce_time,
2272 no_bgp_coalesce_time_cmd,
2273 "no coalesce-time (0-4294967295)",
2274 NO_STR
2275 "Subgroup coalesce timer\n"
2276 "Subgroup coalesce timer value (in ms)\n")
2277 {
2278 nb_cli_enqueue_change(
2279 vty, "./global/global-update-group-config/coalesce-time",
2280 NB_OP_MODIFY, NULL);
2281
2282 return nb_cli_apply_changes(vty, NULL);
2283 }
2284
2285 /* Maximum-paths configuration */
2286 DEFUN_YANG (bgp_maxpaths,
2287 bgp_maxpaths_cmd,
2288 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2289 "Forward packets over multiple paths\n"
2290 "Number of paths\n")
2291 {
2292 int idx_number = 1;
2293 char base_xpath[XPATH_MAXLEN];
2294 afi_t afi;
2295 safi_t safi;
2296
2297 afi = bgp_node_afi(vty);
2298 safi = bgp_node_safi(vty);
2299
2300 snprintf(
2301 base_xpath, sizeof(base_xpath),
2302 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ebgp/maximum-paths",
2303 yang_afi_safi_value2identity(afi, safi),
2304 bgp_afi_safi_get_container_str(afi, safi));
2305
2306 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY,
2307 argv[idx_number]->arg);
2308
2309 return nb_cli_apply_changes(vty, NULL);
2310 }
2311
2312 void cli_show_bgp_global_afi_safi_unicast_use_multiple_paths_ebgp_maximum_paths(
2313 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
2314 {
2315 vty_out(vty, " maximum-paths %d\n",
2316 yang_dnode_get_uint16(dnode, NULL));
2317 }
2318
2319 ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
2320 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2321 "Forward packets over multiple paths\n"
2322 "Number of paths\n")
2323
2324 DEFUN_YANG (bgp_maxpaths_ibgp,
2325 bgp_maxpaths_ibgp_cmd,
2326 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2327 "Forward packets over multiple paths\n"
2328 "iBGP-multipath\n"
2329 "Number of paths\n")
2330 {
2331 int idx_number = 2;
2332 char base_xpath[XPATH_MAXLEN];
2333 afi_t afi;
2334 safi_t safi;
2335
2336 afi = bgp_node_afi(vty);
2337 safi = bgp_node_safi(vty);
2338
2339 snprintf(
2340 base_xpath, sizeof(base_xpath),
2341 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/maximum-paths",
2342 yang_afi_safi_value2identity(afi, safi),
2343 bgp_afi_safi_get_container_str(afi, safi));
2344
2345 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY,
2346 argv[idx_number]->arg);
2347
2348 return nb_cli_apply_changes(vty, NULL);
2349 }
2350
2351 ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
2352 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2353 "Forward packets over multiple paths\n"
2354 "iBGP-multipath\n"
2355 "Number of paths\n")
2356
2357 DEFUN_YANG (bgp_maxpaths_ibgp_cluster,
2358 bgp_maxpaths_ibgp_cluster_cmd,
2359 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
2360 "Forward packets over multiple paths\n"
2361 "iBGP-multipath\n"
2362 "Number of paths\n"
2363 "Match the cluster length\n")
2364 {
2365 int idx_number = 2;
2366 char base_xpath[XPATH_MAXLEN];
2367 afi_t afi;
2368 safi_t safi;
2369
2370 afi = bgp_node_afi(vty);
2371 safi = bgp_node_safi(vty);
2372
2373 snprintf(
2374 base_xpath, sizeof(base_xpath),
2375 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/maximum-paths",
2376 yang_afi_safi_value2identity(afi, safi),
2377 bgp_afi_safi_get_container_str(afi, safi));
2378
2379 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY,
2380 argv[idx_number]->arg);
2381
2382 snprintf(
2383 base_xpath, sizeof(base_xpath),
2384 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/cluster-length-list",
2385 yang_afi_safi_value2identity(afi, safi),
2386 bgp_afi_safi_get_container_str(afi, safi));
2387
2388 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, "true");
2389
2390 return nb_cli_apply_changes(vty, NULL);
2391 }
2392
2393 void cli_show_bgp_global_afi_safi_ip_unicast_use_multiple_paths_ibgp_maximum_paths(
2394 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
2395 {
2396 vty_out(vty, " maximum-paths ibgp %d",
2397 yang_dnode_get_uint16(dnode, "./maximum-paths"));
2398 if (yang_dnode_get_bool(dnode, "./cluster-length-list"))
2399 vty_out(vty, " equal-cluster-length");
2400 vty_out(vty, "\n");
2401 }
2402
2403 ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
2404 "maximum-paths ibgp " CMD_RANGE_STR(
2405 1, MULTIPATH_NUM) " equal-cluster-length",
2406 "Forward packets over multiple paths\n"
2407 "iBGP-multipath\n"
2408 "Number of paths\n"
2409 "Match the cluster length\n")
2410
2411 DEFUN_YANG (no_bgp_maxpaths,
2412 no_bgp_maxpaths_cmd,
2413 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
2414 NO_STR
2415 "Forward packets over multiple paths\n"
2416 "Number of paths\n")
2417 {
2418 char base_xpath[XPATH_MAXLEN];
2419 afi_t afi;
2420 safi_t safi;
2421
2422 afi = bgp_node_afi(vty);
2423 safi = bgp_node_safi(vty);
2424
2425 snprintf(
2426 base_xpath, sizeof(base_xpath),
2427 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ebgp/maximum-paths",
2428 yang_afi_safi_value2identity(afi, safi),
2429 bgp_afi_safi_get_container_str(afi, safi));
2430
2431 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, NULL);
2432
2433 return nb_cli_apply_changes(vty, NULL);
2434 }
2435
2436 ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
2437 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
2438 "Forward packets over multiple paths\n"
2439 "Number of paths\n")
2440
2441 DEFUN_YANG (no_bgp_maxpaths_ibgp,
2442 no_bgp_maxpaths_ibgp_cmd,
2443 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
2444 NO_STR
2445 "Forward packets over multiple paths\n"
2446 "iBGP-multipath\n"
2447 "Number of paths\n"
2448 "Match the cluster length\n")
2449 {
2450 char base_xpath[XPATH_MAXLEN];
2451 afi_t afi;
2452 safi_t safi;
2453
2454 afi = bgp_node_afi(vty);
2455 safi = bgp_node_safi(vty);
2456
2457 snprintf(
2458 base_xpath, sizeof(base_xpath),
2459 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/maximum-paths",
2460 yang_afi_safi_value2identity(afi, safi),
2461 bgp_afi_safi_get_container_str(afi, safi));
2462
2463 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, NULL);
2464
2465 snprintf(
2466 base_xpath, sizeof(base_xpath),
2467 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/cluster-length-list",
2468 yang_afi_safi_value2identity(afi, safi),
2469 bgp_afi_safi_get_container_str(afi, safi));
2470
2471 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, "false");
2472
2473 return nb_cli_apply_changes(vty, NULL);
2474 }
2475
2476 ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
2477 "no maximum-paths ibgp [" CMD_RANGE_STR(
2478 1, MULTIPATH_NUM) " [equal-cluster-length]]",
2479 NO_STR
2480 "Forward packets over multiple paths\n"
2481 "iBGP-multipath\n"
2482 "Number of paths\n"
2483 "Match the cluster length\n")
2484
2485 static void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp,
2486 afi_t afi, safi_t safi)
2487 {
2488 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != multipath_num) {
2489 vty_out(vty, " maximum-paths %d\n",
2490 bgp->maxpaths[afi][safi].maxpaths_ebgp);
2491 }
2492
2493 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != multipath_num) {
2494 vty_out(vty, " maximum-paths ibgp %d",
2495 bgp->maxpaths[afi][safi].maxpaths_ibgp);
2496 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
2497 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
2498 vty_out(vty, " equal-cluster-length");
2499 vty_out(vty, "\n");
2500 }
2501 }
2502
2503 /* BGP timers. */
2504
2505 DEFUN_YANG (bgp_timers,
2506 bgp_timers_cmd,
2507 "timers bgp (0-65535) (0-65535)",
2508 "Adjust routing timers\n"
2509 "BGP timers\n"
2510 "Keepalive interval\n"
2511 "Holdtime\n")
2512 {
2513 int idx_number = 2;
2514 int idx_number_2 = 3;
2515
2516 nb_cli_enqueue_change(vty, "./global/global-config-timers/keepalive",
2517 NB_OP_MODIFY, argv[idx_number]->arg);
2518 nb_cli_enqueue_change(vty, "./global/global-config-timers/hold-time",
2519 NB_OP_MODIFY, argv[idx_number_2]->arg);
2520
2521 return nb_cli_apply_changes(vty, NULL);
2522 }
2523
2524 DEFUN_YANG (no_bgp_timers,
2525 no_bgp_timers_cmd,
2526 "no timers bgp [(0-65535) (0-65535)]",
2527 NO_STR
2528 "Adjust routing timers\n"
2529 "BGP timers\n"
2530 "Keepalive interval\n"
2531 "Holdtime\n")
2532 {
2533 nb_cli_enqueue_change(vty, "./global/global-config-timers/keepalive",
2534 NB_OP_DESTROY, NULL);
2535 nb_cli_enqueue_change(vty, "./global/global-config-timers/hold-time",
2536 NB_OP_DESTROY, NULL);
2537
2538 return nb_cli_apply_changes(vty, NULL);
2539 }
2540
2541 void cli_show_router_bgp_route_reflector(struct vty *vty,
2542 struct lyd_node *dnode,
2543 bool show_defaults)
2544 {
2545 if (yang_dnode_get_bool(dnode, "./no-client-reflect"))
2546 vty_out(vty, " no bgp client-to-client reflection\n");
2547
2548 if (yang_dnode_get_bool(dnode, "./allow-outbound-policy"))
2549 vty_out(vty, " bgp route-reflector allow-outbound-policy\n");
2550
2551 if (yang_dnode_exists(dnode, "./route-reflector-cluster-id"))
2552 vty_out(vty, " bgp cluster-id %s\n",
2553 yang_dnode_get_string(dnode,
2554 "./route-reflector-cluster-id"));
2555 }
2556
2557 DEFUN_YANG(bgp_client_to_client_reflection,
2558 bgp_client_to_client_reflection_cmd,
2559 "bgp client-to-client reflection",
2560 "BGP specific commands\n"
2561 "Configure client to client route reflection\n"
2562 "reflection of routes allowed\n")
2563 {
2564 nb_cli_enqueue_change(vty, "./global/route-reflector/no-client-reflect",
2565 NB_OP_MODIFY, "false");
2566
2567 return nb_cli_apply_changes(vty, NULL);
2568 }
2569
2570 DEFUN_YANG(no_bgp_client_to_client_reflection,
2571 no_bgp_client_to_client_reflection_cmd,
2572 "no bgp client-to-client reflection",
2573 NO_STR
2574 "BGP specific commands\n"
2575 "Configure client to client route reflection\n"
2576 "reflection of routes allowed\n")
2577 {
2578 nb_cli_enqueue_change(vty, "./global/route-reflector/no-client-reflect",
2579 NB_OP_MODIFY, "true");
2580
2581 return nb_cli_apply_changes(vty, NULL);
2582 }
2583
2584 void cli_show_router_bgp_route_selection(struct vty *vty,
2585 struct lyd_node *dnode,
2586 bool show_defaults)
2587 {
2588
2589 if (yang_dnode_get_bool(dnode, "./always-compare-med"))
2590 vty_out(vty, " bgp always-compare-med\n");
2591
2592 if (yang_dnode_get_bool(dnode, "./ignore-as-path-length"))
2593 vty_out(vty, " bgp bestpath as-path ignore\n");
2594
2595 if (yang_dnode_get_bool(dnode, "./aspath-confed"))
2596 vty_out(vty, " bgp bestpath as-path confed\n");
2597
2598 if (yang_dnode_get_bool(dnode, "./external-compare-router-id"))
2599 vty_out(vty, " bgp bestpath compare-routerid\n");
2600
2601 if (yang_dnode_get_bool(dnode, "./allow-multiple-as")) {
2602 if (yang_dnode_get_bool(dnode, "./multi-path-as-set"))
2603 vty_out(vty,
2604 " bgp bestpath as-path multipath-relax as-set\n");
2605 else
2606 vty_out(vty, " bgp bestpath as-path multipath-relax\n");
2607 }
2608
2609 if (yang_dnode_get_bool(dnode, "./deterministic-med"))
2610 vty_out(vty, " bgp deterministic-med\n");
2611
2612 if (yang_dnode_get_bool(dnode, "./confed-med")
2613 || yang_dnode_get_bool(dnode, "./missing-as-worst-med")) {
2614 vty_out(vty, " bgp bestpath med");
2615 if (yang_dnode_get_bool(dnode, "./confed-med"))
2616 vty_out(vty, " confed");
2617 if (yang_dnode_get_bool(dnode, "./missing-as-worst-med"))
2618 vty_out(vty, " missing-as-worst");
2619 vty_out(vty, "\n");
2620 }
2621 }
2622
2623 /* "bgp always-compare-med" configuration. */
2624 DEFUN_YANG(bgp_always_compare_med,
2625 bgp_always_compare_med_cmd,
2626 "bgp always-compare-med",
2627 "BGP specific commands\n"
2628 "Allow comparing MED from different neighbors\n")
2629 {
2630 nb_cli_enqueue_change(
2631 vty, "./global/route-selection-options/always-compare-med",
2632 NB_OP_MODIFY, "true");
2633
2634 return nb_cli_apply_changes(vty, NULL);
2635 }
2636
2637 DEFUN_YANG(no_bgp_always_compare_med,
2638 no_bgp_always_compare_med_cmd,
2639 "no bgp always-compare-med",
2640 NO_STR
2641 "BGP specific commands\n"
2642 "Allow comparing MED from different neighbors\n")
2643 {
2644 nb_cli_enqueue_change(
2645 vty, "./global/route-selection-options/always-compare-med",
2646 NB_OP_MODIFY, "false");
2647
2648 return nb_cli_apply_changes(vty, NULL);
2649 }
2650
2651 DEFUN_YANG(bgp_suppress_duplicates,
2652 bgp_suppress_duplicates_cmd,
2653 "bgp suppress-duplicates",
2654 "BGP specific commands\n"
2655 "Suppress duplicate updates if the route actually not changed\n")
2656 {
2657 nb_cli_enqueue_change(vty, "./global/suppress-duplicates",
2658 NB_OP_MODIFY, "true");
2659 return nb_cli_apply_changes(vty, NULL);
2660 }
2661
2662 DEFUN_YANG(no_bgp_suppress_duplicates,
2663 no_bgp_suppress_duplicates_cmd,
2664 "no bgp suppress-duplicates",
2665 NO_STR
2666 "BGP specific commands\n"
2667 "Suppress duplicate updates if the route actually not changed\n")
2668 {
2669 nb_cli_enqueue_change(vty, "./global/suppress-duplicates",
2670 NB_OP_MODIFY, "false");
2671 return nb_cli_apply_changes(vty, NULL);
2672 }
2673
2674 void cli_show_router_bgp_suppress_duplicates(struct vty *vty,
2675 struct lyd_node *dnode,
2676 bool show_defaults)
2677 {
2678 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_SUPPRESS_DUPLICATES)
2679 vty_out(vty, " bgp suppress-duplicates\n");
2680 }
2681
2682 DEFUN_YANG(bgp_ebgp_requires_policy,
2683 bgp_ebgp_requires_policy_cmd,
2684 "bgp ebgp-requires-policy",
2685 "BGP specific commands\n"
2686 "Require in and out policy for eBGP peers (RFC8212)\n")
2687 {
2688 nb_cli_enqueue_change(vty, "./global/ebgp-requires-policy",
2689 NB_OP_MODIFY, "true");
2690 return nb_cli_apply_changes(vty, NULL);
2691 }
2692
2693 DEFUN_YANG(no_bgp_ebgp_requires_policy,
2694 no_bgp_ebgp_requires_policy_cmd,
2695 "no bgp ebgp-requires-policy",
2696 NO_STR
2697 "BGP specific commands\n"
2698 "Require in and out policy for eBGP peers (RFC8212)\n")
2699 {
2700 nb_cli_enqueue_change(vty, "./global/ebgp-requires-policy",
2701 NB_OP_MODIFY, "false");
2702 return nb_cli_apply_changes(vty, NULL);
2703 }
2704
2705 void cli_show_router_bgp_ebgp_requires_policy(struct vty *vty,
2706 struct lyd_node *dnode,
2707 bool show_defaults)
2708 {
2709 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_EBGP_REQUIRES_POLICY)
2710 vty_out(vty, " bgp ebgp-requires-policy\n");
2711 }
2712
2713 DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd,
2714 "bgp reject-as-sets",
2715 "BGP specific commands\n"
2716 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2717 {
2718 VTY_DECLVAR_CONTEXT(bgp, bgp);
2719 struct listnode *node, *nnode;
2720 struct peer *peer;
2721
2722 bgp->reject_as_sets = true;
2723
2724 /* Reset existing BGP sessions to reject routes
2725 * with aspath containing AS_SET or AS_CONFED_SET.
2726 */
2727 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2728 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2729 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2730 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2731 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2732 }
2733 }
2734
2735 return CMD_SUCCESS;
2736 }
2737
2738 DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd,
2739 "no bgp reject-as-sets",
2740 NO_STR
2741 "BGP specific commands\n"
2742 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2743 {
2744 VTY_DECLVAR_CONTEXT(bgp, bgp);
2745 struct listnode *node, *nnode;
2746 struct peer *peer;
2747
2748 bgp->reject_as_sets = false;
2749
2750 /* Reset existing BGP sessions to reject routes
2751 * with aspath containing AS_SET or AS_CONFED_SET.
2752 */
2753 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2754 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2755 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2756 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2757 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2758 }
2759 }
2760
2761 return CMD_SUCCESS;
2762 }
2763
2764 /* "bgp deterministic-med" configuration. */
2765 DEFUN_YANG (bgp_deterministic_med,
2766 bgp_deterministic_med_cmd,
2767 "bgp deterministic-med",
2768 "BGP specific commands\n"
2769 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2770 {
2771 nb_cli_enqueue_change(
2772 vty, "./global/route-selection-options/deterministic-med",
2773 NB_OP_MODIFY, "true");
2774
2775 return nb_cli_apply_changes(vty, NULL);
2776 }
2777
2778 DEFUN_YANG (no_bgp_deterministic_med,
2779 no_bgp_deterministic_med_cmd,
2780 "no bgp deterministic-med",
2781 NO_STR
2782 "BGP specific commands\n"
2783 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2784 {
2785 nb_cli_enqueue_change(
2786 vty, "./global/route-selection-options/deterministic-med",
2787 NB_OP_MODIFY, "false");
2788
2789 return nb_cli_apply_changes(vty, NULL);
2790 }
2791
2792 /* "bgp graceful-restart mode" configuration. */
2793 DEFUN (bgp_graceful_restart,
2794 bgp_graceful_restart_cmd,
2795 "bgp graceful-restart",
2796 "BGP specific commands\n"
2797 GR_CMD
2798 )
2799 {
2800 int ret = BGP_GR_FAILURE;
2801
2802 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2803 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : START ");
2804
2805 VTY_DECLVAR_CONTEXT(bgp, bgp);
2806
2807 ret = bgp_gr_update_all(bgp, GLOBAL_GR_CMD);
2808
2809 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2810 ret);
2811
2812 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2813 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : END ");
2814 vty_out(vty,
2815 "Graceful restart configuration changed, reset all peers to take effect\n");
2816 return bgp_vty_return(vty, ret);
2817 }
2818
2819 DEFUN (no_bgp_graceful_restart,
2820 no_bgp_graceful_restart_cmd,
2821 "no bgp graceful-restart",
2822 NO_STR
2823 "BGP specific commands\n"
2824 NO_GR_CMD
2825 )
2826 {
2827 VTY_DECLVAR_CONTEXT(bgp, bgp);
2828
2829 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2830 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : START ");
2831
2832 int ret = BGP_GR_FAILURE;
2833
2834 ret = bgp_gr_update_all(bgp, NO_GLOBAL_GR_CMD);
2835
2836 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2837 ret);
2838
2839 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2840 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : END ");
2841 vty_out(vty,
2842 "Graceful restart configuration changed, reset all peers to take effect\n");
2843
2844 return bgp_vty_return(vty, ret);
2845 }
2846
2847 DEFUN (bgp_graceful_restart_stalepath_time,
2848 bgp_graceful_restart_stalepath_time_cmd,
2849 "bgp graceful-restart stalepath-time (1-4095)",
2850 "BGP specific commands\n"
2851 "Graceful restart capability parameters\n"
2852 "Set the max time to hold onto restarting peer's stale paths\n"
2853 "Delay value (seconds)\n")
2854 {
2855 VTY_DECLVAR_CONTEXT(bgp, bgp);
2856 int idx_number = 3;
2857 uint32_t stalepath;
2858
2859 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2860 bgp->stalepath_time = stalepath;
2861 return CMD_SUCCESS;
2862 }
2863
2864 DEFUN (bgp_graceful_restart_restart_time,
2865 bgp_graceful_restart_restart_time_cmd,
2866 "bgp graceful-restart restart-time (1-4095)",
2867 "BGP specific commands\n"
2868 "Graceful restart capability parameters\n"
2869 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2870 "Delay value (seconds)\n")
2871 {
2872 VTY_DECLVAR_CONTEXT(bgp, bgp);
2873 int idx_number = 3;
2874 uint32_t restart;
2875
2876 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2877 bgp->restart_time = restart;
2878 return CMD_SUCCESS;
2879 }
2880
2881 DEFUN (bgp_graceful_restart_select_defer_time,
2882 bgp_graceful_restart_select_defer_time_cmd,
2883 "bgp graceful-restart select-defer-time (0-3600)",
2884 "BGP specific commands\n"
2885 "Graceful restart capability parameters\n"
2886 "Set the time to defer the BGP route selection after restart\n"
2887 "Delay value (seconds, 0 - disable)\n")
2888 {
2889 VTY_DECLVAR_CONTEXT(bgp, bgp);
2890 int idx_number = 3;
2891 uint32_t defer_time;
2892
2893 defer_time = strtoul(argv[idx_number]->arg, NULL, 10);
2894 bgp->select_defer_time = defer_time;
2895 if (defer_time == 0)
2896 SET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2897 else
2898 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2899
2900 return CMD_SUCCESS;
2901 }
2902
2903 DEFUN (no_bgp_graceful_restart_stalepath_time,
2904 no_bgp_graceful_restart_stalepath_time_cmd,
2905 "no bgp graceful-restart stalepath-time [(1-4095)]",
2906 NO_STR
2907 "BGP specific commands\n"
2908 "Graceful restart capability parameters\n"
2909 "Set the max time to hold onto restarting peer's stale paths\n"
2910 "Delay value (seconds)\n")
2911 {
2912 VTY_DECLVAR_CONTEXT(bgp, bgp);
2913
2914 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2915 return CMD_SUCCESS;
2916 }
2917
2918 DEFUN (no_bgp_graceful_restart_restart_time,
2919 no_bgp_graceful_restart_restart_time_cmd,
2920 "no bgp graceful-restart restart-time [(1-4095)]",
2921 NO_STR
2922 "BGP specific commands\n"
2923 "Graceful restart capability parameters\n"
2924 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2925 "Delay value (seconds)\n")
2926 {
2927 VTY_DECLVAR_CONTEXT(bgp, bgp);
2928
2929 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2930 return CMD_SUCCESS;
2931 }
2932
2933 DEFUN (no_bgp_graceful_restart_select_defer_time,
2934 no_bgp_graceful_restart_select_defer_time_cmd,
2935 "no bgp graceful-restart select-defer-time [(0-3600)]",
2936 NO_STR
2937 "BGP specific commands\n"
2938 "Graceful restart capability parameters\n"
2939 "Set the time to defer the BGP route selection after restart\n"
2940 "Delay value (seconds)\n")
2941 {
2942 VTY_DECLVAR_CONTEXT(bgp, bgp);
2943
2944 bgp->select_defer_time = BGP_DEFAULT_SELECT_DEFERRAL_TIME;
2945 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2946
2947 return CMD_SUCCESS;
2948 }
2949
2950 DEFUN (bgp_graceful_restart_preserve_fw,
2951 bgp_graceful_restart_preserve_fw_cmd,
2952 "bgp graceful-restart preserve-fw-state",
2953 "BGP specific commands\n"
2954 "Graceful restart capability parameters\n"
2955 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
2956 {
2957 VTY_DECLVAR_CONTEXT(bgp, bgp);
2958 SET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
2959 return CMD_SUCCESS;
2960 }
2961
2962 DEFUN (no_bgp_graceful_restart_preserve_fw,
2963 no_bgp_graceful_restart_preserve_fw_cmd,
2964 "no bgp graceful-restart preserve-fw-state",
2965 NO_STR
2966 "BGP specific commands\n"
2967 "Graceful restart capability parameters\n"
2968 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
2969 {
2970 VTY_DECLVAR_CONTEXT(bgp, bgp);
2971 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
2972 return CMD_SUCCESS;
2973 }
2974
2975 DEFUN (bgp_graceful_restart_disable,
2976 bgp_graceful_restart_disable_cmd,
2977 "bgp graceful-restart-disable",
2978 "BGP specific commands\n"
2979 GR_DISABLE)
2980 {
2981 int ret = BGP_GR_FAILURE;
2982
2983 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2984 zlog_debug(
2985 "[BGP_GR] bgp_graceful_restart_disable_cmd : START ");
2986
2987 VTY_DECLVAR_CONTEXT(bgp, bgp);
2988
2989 ret = bgp_gr_update_all(bgp, GLOBAL_DISABLE_CMD);
2990
2991 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
2992 bgp->peer, ret);
2993
2994 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2995 zlog_debug(
2996 "[BGP_GR] bgp_graceful_restart_disable_cmd : END ");
2997 vty_out(vty,
2998 "Graceful restart configuration changed, reset all peers to take effect\n");
2999
3000 return bgp_vty_return(vty, ret);
3001 }
3002
3003 DEFUN (no_bgp_graceful_restart_disable,
3004 no_bgp_graceful_restart_disable_cmd,
3005 "no bgp graceful-restart-disable",
3006 NO_STR
3007 "BGP specific commands\n"
3008 NO_GR_DISABLE
3009 )
3010 {
3011 VTY_DECLVAR_CONTEXT(bgp, bgp);
3012
3013 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3014 zlog_debug(
3015 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : START ");
3016
3017 int ret = BGP_GR_FAILURE;
3018
3019 ret = bgp_gr_update_all(bgp, NO_GLOBAL_DISABLE_CMD);
3020
3021 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
3022 ret);
3023
3024 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3025 zlog_debug(
3026 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : END ");
3027 vty_out(vty,
3028 "Graceful restart configuration changed, reset all peers to take effect\n");
3029
3030 return bgp_vty_return(vty, ret);
3031 }
3032
3033 DEFUN (bgp_neighbor_graceful_restart_set,
3034 bgp_neighbor_graceful_restart_set_cmd,
3035 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3036 NEIGHBOR_STR
3037 NEIGHBOR_ADDR_STR2
3038 GR_NEIGHBOR_CMD
3039 )
3040 {
3041 int idx_peer = 1;
3042 struct peer *peer;
3043 int ret = BGP_GR_FAILURE;
3044
3045 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3046
3047 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3048 zlog_debug(
3049 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : START ");
3050
3051 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3052 if (!peer)
3053 return CMD_WARNING_CONFIG_FAILED;
3054
3055 ret = bgp_neighbor_graceful_restart(peer, PEER_GR_CMD);
3056
3057 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3058 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3059
3060 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3061 zlog_debug(
3062 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : END ");
3063 vty_out(vty,
3064 "Graceful restart configuration changed, reset this peer to take effect\n");
3065
3066 return bgp_vty_return(vty, ret);
3067 }
3068
3069 DEFUN (no_bgp_neighbor_graceful_restart,
3070 no_bgp_neighbor_graceful_restart_set_cmd,
3071 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3072 NO_STR
3073 NEIGHBOR_STR
3074 NEIGHBOR_ADDR_STR2
3075 NO_GR_NEIGHBOR_CMD
3076 )
3077 {
3078 int idx_peer = 2;
3079 int ret = BGP_GR_FAILURE;
3080 struct peer *peer;
3081
3082 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3083
3084 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3085 if (!peer)
3086 return CMD_WARNING_CONFIG_FAILED;
3087
3088 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3089 zlog_debug(
3090 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : START ");
3091
3092 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_GR_CMD);
3093
3094 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3095 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3096
3097 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3098 zlog_debug(
3099 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : END ");
3100 vty_out(vty,
3101 "Graceful restart configuration changed, reset this peer to take effect\n");
3102
3103 return bgp_vty_return(vty, ret);
3104 }
3105
3106 DEFUN (bgp_neighbor_graceful_restart_helper_set,
3107 bgp_neighbor_graceful_restart_helper_set_cmd,
3108 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3109 NEIGHBOR_STR
3110 NEIGHBOR_ADDR_STR2
3111 GR_NEIGHBOR_HELPER_CMD
3112 )
3113 {
3114 int idx_peer = 1;
3115 struct peer *peer;
3116 int ret = BGP_GR_FAILURE;
3117
3118 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3119
3120 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3121 zlog_debug(
3122 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : START ");
3123
3124 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3125
3126 if (!peer)
3127 return CMD_WARNING_CONFIG_FAILED;
3128
3129
3130 ret = bgp_neighbor_graceful_restart(peer, PEER_HELPER_CMD);
3131
3132 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3133 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3134
3135 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3136 zlog_debug(
3137 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : END ");
3138 vty_out(vty,
3139 "Graceful restart configuration changed, reset this peer to take effect\n");
3140
3141 return bgp_vty_return(vty, ret);
3142 }
3143
3144 DEFUN (no_bgp_neighbor_graceful_restart_helper,
3145 no_bgp_neighbor_graceful_restart_helper_set_cmd,
3146 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3147 NO_STR
3148 NEIGHBOR_STR
3149 NEIGHBOR_ADDR_STR2
3150 NO_GR_NEIGHBOR_HELPER_CMD
3151 )
3152 {
3153 int idx_peer = 2;
3154 int ret = BGP_GR_FAILURE;
3155 struct peer *peer;
3156
3157 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3158
3159 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3160 if (!peer)
3161 return CMD_WARNING_CONFIG_FAILED;
3162
3163 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3164 zlog_debug(
3165 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : START ");
3166
3167 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_HELPER_CMD);
3168
3169 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3170 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3171
3172 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3173 zlog_debug(
3174 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : END ");
3175 vty_out(vty,
3176 "Graceful restart configuration changed, reset this peer to take effect\n");
3177
3178 return bgp_vty_return(vty, ret);
3179 }
3180
3181 DEFUN (bgp_neighbor_graceful_restart_disable_set,
3182 bgp_neighbor_graceful_restart_disable_set_cmd,
3183 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3184 NEIGHBOR_STR
3185 NEIGHBOR_ADDR_STR2
3186 GR_NEIGHBOR_DISABLE_CMD
3187 )
3188 {
3189 int idx_peer = 1;
3190 struct peer *peer;
3191 int ret = BGP_GR_FAILURE;
3192
3193 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3194
3195 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3196 zlog_debug(
3197 "[BGP_GR] bgp_neighbor_graceful_restart_disable_set_cmd : START ");
3198
3199 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3200 if (!peer)
3201 return CMD_WARNING_CONFIG_FAILED;
3202
3203 ret = bgp_neighbor_graceful_restart(peer, PEER_DISABLE_CMD);
3204
3205 if (peer->bgp->t_startup)
3206 bgp_peer_gr_flags_update(peer);
3207
3208 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3209 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3210
3211 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3212 zlog_debug(
3213 "[BGP_GR]bgp_neighbor_graceful_restart_disable_set_cmd : END ");
3214 vty_out(vty,
3215 "Graceful restart configuration changed, reset this peer to take effect\n");
3216
3217 return bgp_vty_return(vty, ret);
3218 }
3219
3220 DEFUN (no_bgp_neighbor_graceful_restart_disable,
3221 no_bgp_neighbor_graceful_restart_disable_set_cmd,
3222 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3223 NO_STR
3224 NEIGHBOR_STR
3225 NEIGHBOR_ADDR_STR2
3226 NO_GR_NEIGHBOR_DISABLE_CMD
3227 )
3228 {
3229 int idx_peer = 2;
3230 int ret = BGP_GR_FAILURE;
3231 struct peer *peer;
3232
3233 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3234
3235 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3236 if (!peer)
3237 return CMD_WARNING_CONFIG_FAILED;
3238
3239 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3240 zlog_debug(
3241 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : START ");
3242
3243 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_DISABLE_CMD);
3244
3245 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3246 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3247
3248 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3249 zlog_debug(
3250 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : END ");
3251 vty_out(vty,
3252 "Graceful restart configuration changed, reset this peer to take effect\n");
3253
3254 return bgp_vty_return(vty, ret);
3255 }
3256
3257 DEFUN_HIDDEN (bgp_graceful_restart_disable_eor,
3258 bgp_graceful_restart_disable_eor_cmd,
3259 "bgp graceful-restart disable-eor",
3260 "BGP specific commands\n"
3261 "Graceful restart configuration parameters\n"
3262 "Disable EOR Check\n")
3263 {
3264 VTY_DECLVAR_CONTEXT(bgp, bgp);
3265 SET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
3266
3267 return CMD_SUCCESS;
3268 }
3269
3270 DEFUN_HIDDEN (no_bgp_graceful_restart_disable_eor,
3271 no_bgp_graceful_restart_disable_eor_cmd,
3272 "no bgp graceful-restart disable-eor",
3273 NO_STR
3274 "BGP specific commands\n"
3275 "Graceful restart configuration parameters\n"
3276 "Disable EOR Check\n")
3277 {
3278 VTY_DECLVAR_CONTEXT(bgp, bgp);
3279 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
3280
3281 return CMD_SUCCESS;
3282 }
3283
3284 DEFUN (bgp_graceful_restart_rib_stale_time,
3285 bgp_graceful_restart_rib_stale_time_cmd,
3286 "bgp graceful-restart rib-stale-time (1-3600)",
3287 "BGP specific commands\n"
3288 "Graceful restart configuration parameters\n"
3289 "Specify the stale route removal timer in rib\n"
3290 "Delay value (seconds)\n")
3291 {
3292 VTY_DECLVAR_CONTEXT(bgp, bgp);
3293 int idx_number = 3;
3294 uint32_t stale_time;
3295
3296 stale_time = strtoul(argv[idx_number]->arg, NULL, 10);
3297 bgp->rib_stale_time = stale_time;
3298 /* Send the stale timer update message to RIB */
3299 if (bgp_zebra_stale_timer_update(bgp))
3300 return CMD_WARNING;
3301
3302 return CMD_SUCCESS;
3303 }
3304
3305 DEFUN (no_bgp_graceful_restart_rib_stale_time,
3306 no_bgp_graceful_restart_rib_stale_time_cmd,
3307 "no bgp graceful-restart rib-stale-time [(1-3600)]",
3308 NO_STR
3309 "BGP specific commands\n"
3310 "Graceful restart configuration parameters\n"
3311 "Specify the stale route removal timer in rib\n"
3312 "Delay value (seconds)\n")
3313 {
3314 VTY_DECLVAR_CONTEXT(bgp, bgp);
3315
3316 bgp->rib_stale_time = BGP_DEFAULT_RIB_STALE_TIME;
3317 /* Send the stale timer update message to RIB */
3318 if (bgp_zebra_stale_timer_update(bgp))
3319 return CMD_WARNING;
3320
3321 return CMD_SUCCESS;
3322 }
3323
3324 static inline int bgp_initiate_graceful_shut_unshut(struct bgp *bgp,
3325 char *errmsg,
3326 size_t errmsg_len)
3327 {
3328 bgp_static_redo_import_check(bgp);
3329 bgp_redistribute_redo(bgp);
3330 if (bgp_clear_star_soft_out(bgp->name, errmsg, errmsg_len) < 0)
3331 return -1;
3332 if (bgp_clear_star_soft_in(bgp->name, errmsg, errmsg_len) < 0)
3333 return -1;
3334
3335 return 0;
3336 }
3337
3338 static int bgp_global_graceful_shutdown_config_vty(struct vty *vty)
3339 {
3340 struct listnode *node, *nnode;
3341 struct bgp *bgp;
3342 bool vrf_cfg = false;
3343 char errmsg[BUFSIZ] = {'\0'};
3344
3345 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3346 return CMD_SUCCESS;
3347
3348 /* See if graceful-shutdown is set per-vrf and warn user to delete */
3349 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3350 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3351 vty_out(vty,
3352 "%% graceful-shutdown configuration found in vrf %s\n",
3353 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT ?
3354 VRF_DEFAULT_NAME : bgp->name);
3355 vrf_cfg = true;
3356 }
3357 }
3358
3359 if (vrf_cfg) {
3360 vty_out(vty,
3361 "%%Failed: global graceful-shutdown not permitted\n");
3362 return CMD_WARNING;
3363 }
3364
3365 /* Set flag globally */
3366 SET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3367
3368 /* Initiate processing for all BGP instances. */
3369 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3370 if (bgp_initiate_graceful_shut_unshut(bgp, errmsg,
3371 sizeof(errmsg))
3372 < 0)
3373 if (strlen(errmsg))
3374 vty_out(vty, "%s\n", errmsg);
3375 }
3376
3377 return CMD_SUCCESS;
3378 }
3379
3380 static int bgp_global_graceful_shutdown_deconfig_vty(struct vty *vty)
3381 {
3382 struct listnode *node, *nnode;
3383 struct bgp *bgp;
3384 char errmsg[BUFSIZ] = {'\0'};
3385
3386 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3387 return CMD_SUCCESS;
3388
3389 /* Unset flag globally */
3390 UNSET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3391
3392 /* Initiate processing for all BGP instances. */
3393 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3394 if (bgp_initiate_graceful_shut_unshut(bgp, errmsg,
3395 sizeof(errmsg))
3396 < 0)
3397 if (strlen(errmsg))
3398 vty_out(vty, "%s\n", errmsg);
3399 }
3400
3401 return CMD_SUCCESS;
3402 }
3403
3404 /* "bgp graceful-shutdown" configuration */
3405 DEFUN (bgp_graceful_shutdown,
3406 bgp_graceful_shutdown_cmd,
3407 "bgp graceful-shutdown",
3408 BGP_STR
3409 "Graceful shutdown parameters\n")
3410 {
3411 if (vty->node == CONFIG_NODE)
3412 return bgp_global_graceful_shutdown_config_vty(vty);
3413
3414 nb_cli_enqueue_change(vty, "./global/graceful-shutdown/enable",
3415 NB_OP_MODIFY, "true");
3416
3417 return nb_cli_apply_changes(vty, NULL);
3418 }
3419
3420 DEFUN_YANG (no_bgp_graceful_shutdown,
3421 no_bgp_graceful_shutdown_cmd,
3422 "no bgp graceful-shutdown",
3423 NO_STR
3424 BGP_STR
3425 "Graceful shutdown parameters\n")
3426 {
3427 if (vty->node == CONFIG_NODE)
3428 return bgp_global_graceful_shutdown_deconfig_vty(vty);
3429
3430 nb_cli_enqueue_change(vty, "./global/graceful-shutdown/enable",
3431 NB_OP_MODIFY, "false");
3432
3433 return nb_cli_apply_changes(vty, NULL);
3434 }
3435
3436 void cli_show_router_bgp_graceful_shutdown(struct vty *vty,
3437 struct lyd_node *dnode,
3438 bool show_defaults)
3439 {
3440 if (yang_dnode_get_bool(dnode, NULL))
3441 vty_out(vty, " bgp graceful-shutdown\n");
3442 }
3443
3444 /* "bgp fast-external-failover" configuration. */
3445 DEFUN_YANG (bgp_fast_external_failover,
3446 bgp_fast_external_failover_cmd,
3447 "bgp fast-external-failover",
3448 BGP_STR
3449 "Immediately reset session if a link to a directly connected external peer goes down\n")
3450 {
3451 nb_cli_enqueue_change(vty, "./global/fast-external-failover",
3452 NB_OP_MODIFY, "false");
3453
3454 return nb_cli_apply_changes(vty, NULL);
3455 }
3456
3457 DEFUN_YANG (no_bgp_fast_external_failover,
3458 no_bgp_fast_external_failover_cmd,
3459 "no bgp fast-external-failover",
3460 NO_STR
3461 BGP_STR
3462 "Immediately reset session if a link to a directly connected external peer goes down\n")
3463 {
3464 nb_cli_enqueue_change(vty, "./global/fast-external-failover",
3465 NB_OP_MODIFY, "true");
3466
3467 return nb_cli_apply_changes(vty, NULL);
3468 }
3469
3470 void cli_show_router_bgp_fast_external_failover(struct vty *vty,
3471 struct lyd_node *dnode,
3472 bool show_defaults)
3473 {
3474 if (!yang_dnode_get_bool(dnode, NULL))
3475 vty_out(vty, " no bgp fast-external-failover\n");
3476 }
3477
3478 /* "bgp bestpath compare-routerid" configuration. */
3479 DEFUN_YANG(bgp_bestpath_compare_router_id,
3480 bgp_bestpath_compare_router_id_cmd,
3481 "bgp bestpath compare-routerid",
3482 "BGP specific commands\n"
3483 "Change the default bestpath selection\n"
3484 "Compare router-id for identical EBGP paths\n")
3485 {
3486 nb_cli_enqueue_change(
3487 vty,
3488 "./global/route-selection-options/external-compare-router-id",
3489 NB_OP_MODIFY, "true");
3490
3491 return nb_cli_apply_changes(vty, NULL);
3492 }
3493
3494 DEFUN_YANG(no_bgp_bestpath_compare_router_id,
3495 no_bgp_bestpath_compare_router_id_cmd,
3496 "no bgp bestpath compare-routerid",
3497 NO_STR
3498 "BGP specific commands\n"
3499 "Change the default bestpath selection\n"
3500 "Compare router-id for identical EBGP paths\n")
3501 {
3502 nb_cli_enqueue_change(
3503 vty,
3504 "./global/route-selection-options/external-compare-router-id",
3505 NB_OP_MODIFY, "false");
3506
3507 return nb_cli_apply_changes(vty, NULL);
3508 }
3509
3510 /* "bgp bestpath as-path ignore" configuration. */
3511 DEFUN_YANG(bgp_bestpath_aspath_ignore,
3512 bgp_bestpath_aspath_ignore_cmd,
3513 "bgp bestpath as-path ignore",
3514 "BGP specific commands\n"
3515 "Change the default bestpath selection\n"
3516 "AS-path attribute\n"
3517 "Ignore as-path length in selecting a route\n")
3518 {
3519 nb_cli_enqueue_change(
3520 vty, "./global/route-selection-options/ignore-as-path-length",
3521 NB_OP_MODIFY, "true");
3522
3523 return nb_cli_apply_changes(vty, NULL);
3524 }
3525
3526 DEFUN_YANG(no_bgp_bestpath_aspath_ignore,
3527 no_bgp_bestpath_aspath_ignore_cmd,
3528 "no bgp bestpath as-path ignore",
3529 NO_STR
3530 "BGP specific commands\n"
3531 "Change the default bestpath selection\n"
3532 "AS-path attribute\n"
3533 "Ignore as-path length in selecting a route\n")
3534 {
3535 nb_cli_enqueue_change(
3536 vty, "./global/route-selection-options/ignore-as-path-length",
3537 NB_OP_MODIFY, "false");
3538
3539 return nb_cli_apply_changes(vty, NULL);
3540 }
3541
3542 /* "bgp bestpath as-path confed" configuration. */
3543 DEFUN_YANG (bgp_bestpath_aspath_confed,
3544 bgp_bestpath_aspath_confed_cmd,
3545 "bgp bestpath as-path confed",
3546 "BGP specific commands\n"
3547 "Change the default bestpath selection\n"
3548 "AS-path attribute\n"
3549 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3550 {
3551 nb_cli_enqueue_change(vty,
3552 "./global/route-selection-options/aspath-confed",
3553 NB_OP_MODIFY, "true");
3554
3555 return nb_cli_apply_changes(vty, NULL);
3556 }
3557
3558 DEFUN_YANG (no_bgp_bestpath_aspath_confed,
3559 no_bgp_bestpath_aspath_confed_cmd,
3560 "no bgp bestpath as-path confed",
3561 NO_STR
3562 "BGP specific commands\n"
3563 "Change the default bestpath selection\n"
3564 "AS-path attribute\n"
3565 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3566 {
3567 nb_cli_enqueue_change(vty,
3568 "./global/route-selection-options/aspath-confed",
3569 NB_OP_MODIFY, "false");
3570
3571 return nb_cli_apply_changes(vty, NULL);
3572 }
3573
3574 /* "bgp bestpath as-path multipath-relax" configuration. */
3575 DEFUN_YANG (bgp_bestpath_aspath_multipath_relax,
3576 bgp_bestpath_aspath_multipath_relax_cmd,
3577 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
3578 "BGP specific commands\n"
3579 "Change the default bestpath selection\n"
3580 "AS-path attribute\n"
3581 "Allow load sharing across routes that have different AS paths (but same length)\n"
3582 "Generate an AS_SET\n"
3583 "Do not generate an AS_SET\n")
3584 {
3585 int idx = 0;
3586
3587 nb_cli_enqueue_change(
3588 vty, "./global/route-selection-options/allow-multiple-as",
3589 NB_OP_MODIFY, "true");
3590 if (argv_find(argv, argc, "as-set", &idx))
3591 nb_cli_enqueue_change(
3592 vty,
3593 "./global/route-selection-options/multi-path-as-set",
3594 NB_OP_MODIFY, "true");
3595 else
3596 nb_cli_enqueue_change(
3597 vty,
3598 "./global/route-selection-options/multi-path-as-set",
3599 NB_OP_MODIFY, "false");
3600
3601 return nb_cli_apply_changes(vty, NULL);
3602 }
3603
3604 DEFUN_YANG (no_bgp_bestpath_aspath_multipath_relax,
3605 no_bgp_bestpath_aspath_multipath_relax_cmd,
3606 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
3607 NO_STR
3608 "BGP specific commands\n"
3609 "Change the default bestpath selection\n"
3610 "AS-path attribute\n"
3611 "Allow load sharing across routes that have different AS paths (but same length)\n"
3612 "Generate an AS_SET\n"
3613 "Do not generate an AS_SET\n")
3614 {
3615 nb_cli_enqueue_change(
3616 vty, "./global/route-selection-options/allow-multiple-as",
3617 NB_OP_MODIFY, "false");
3618 nb_cli_enqueue_change(
3619 vty, "./global/route-selection-options/multi-path-as-set",
3620 NB_OP_MODIFY, "false");
3621
3622 return nb_cli_apply_changes(vty, NULL);
3623 }
3624
3625 /* "bgp bestpath peer-type multipath-relax" configuration. */
3626 DEFUN(bgp_bestpath_peer_type_multipath_relax,
3627 bgp_bestpath_peer_type_multipath_relax_cmd,
3628 "bgp bestpath peer-type multipath-relax",
3629 BGP_STR
3630 "Change the default bestpath selection\n"
3631 "Peer type\n"
3632 "Allow load sharing across routes learned from different peer types\n")
3633 {
3634 VTY_DECLVAR_CONTEXT(bgp, bgp);
3635 SET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3636 bgp_recalculate_all_bestpaths(bgp);
3637
3638 return CMD_SUCCESS;
3639 }
3640
3641 DEFUN(no_bgp_bestpath_peer_type_multipath_relax,
3642 no_bgp_bestpath_peer_type_multipath_relax_cmd,
3643 "no bgp bestpath peer-type multipath-relax",
3644 NO_STR BGP_STR
3645 "Change the default bestpath selection\n"
3646 "Peer type\n"
3647 "Allow load sharing across routes learned from different peer types\n")
3648 {
3649 VTY_DECLVAR_CONTEXT(bgp, bgp);
3650 UNSET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3651 bgp_recalculate_all_bestpaths(bgp);
3652
3653 return CMD_SUCCESS;
3654 }
3655
3656 /* "bgp log-neighbor-changes" configuration. */
3657 DEFUN_YANG(bgp_log_neighbor_changes,
3658 bgp_log_neighbor_changes_cmd,
3659 "bgp log-neighbor-changes",
3660 "BGP specific commands\n"
3661 "Log neighbor up/down and reset reason\n")
3662 {
3663 nb_cli_enqueue_change(
3664 vty, "./global/global-neighbor-config/log-neighbor-changes",
3665 NB_OP_MODIFY, "true");
3666
3667 return nb_cli_apply_changes(vty, NULL);
3668 }
3669
3670 DEFUN_YANG(no_bgp_log_neighbor_changes,
3671 no_bgp_log_neighbor_changes_cmd,
3672 "no bgp log-neighbor-changes",
3673 NO_STR
3674 "BGP specific commands\n"
3675 "Log neighbor up/down and reset reason\n")
3676 {
3677 nb_cli_enqueue_change(
3678 vty, "./global/global-neighbor-config/log-neighbor-changes",
3679 NB_OP_MODIFY, "false");
3680
3681 return nb_cli_apply_changes(vty, NULL);
3682 }
3683
3684 /* "bgp bestpath med" configuration. */
3685 DEFUN_YANG (bgp_bestpath_med,
3686 bgp_bestpath_med_cmd,
3687 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
3688 "BGP specific commands\n"
3689 "Change the default bestpath selection\n"
3690 "MED attribute\n"
3691 "Compare MED among confederation paths\n"
3692 "Treat missing MED as the least preferred one\n"
3693 "Treat missing MED as the least preferred one\n"
3694 "Compare MED among confederation paths\n")
3695 {
3696 int idx = 0;
3697 bool confed = false;
3698 bool worst_med = false;
3699
3700
3701 if (argv_find(argv, argc, "confed", &idx))
3702 confed = true;
3703
3704 nb_cli_enqueue_change(vty,
3705 "./global/route-selection-options/confed-med",
3706 NB_OP_MODIFY, confed ? "true" : "false");
3707
3708 idx = 0;
3709 if (argv_find(argv, argc, "missing-as-worst", &idx))
3710 worst_med = true;
3711
3712 nb_cli_enqueue_change(
3713 vty, "./global/route-selection-options/missing-as-worst-med",
3714 NB_OP_MODIFY, worst_med ? "true" : "false");
3715
3716 return nb_cli_apply_changes(vty, NULL);
3717 }
3718
3719 DEFUN_YANG (no_bgp_bestpath_med,
3720 no_bgp_bestpath_med_cmd,
3721 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
3722 NO_STR
3723 "BGP specific commands\n"
3724 "Change the default bestpath selection\n"
3725 "MED attribute\n"
3726 "Compare MED among confederation paths\n"
3727 "Treat missing MED as the least preferred one\n"
3728 "Treat missing MED as the least preferred one\n"
3729 "Compare MED among confederation paths\n")
3730 {
3731 int idx = 0;
3732
3733 if (argv_find(argv, argc, "confed", &idx))
3734 nb_cli_enqueue_change(
3735 vty, "./global/route-selection-options/confed-med",
3736 NB_OP_MODIFY, "false");
3737
3738 idx = 0;
3739 if (argv_find(argv, argc, "missing-as-worst", &idx))
3740 nb_cli_enqueue_change(
3741 vty,
3742 "./global/route-selection-options/missing-as-worst-med",
3743 NB_OP_MODIFY, "false");
3744
3745 return nb_cli_apply_changes(vty, NULL);
3746 }
3747
3748 /* "bgp bestpath bandwidth" configuration. */
3749 DEFPY (bgp_bestpath_bw,
3750 bgp_bestpath_bw_cmd,
3751 "bgp bestpath bandwidth <ignore|skip-missing|default-weight-for-missing>$bw_cfg",
3752 "BGP specific commands\n"
3753 "Change the default bestpath selection\n"
3754 "Link Bandwidth attribute\n"
3755 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3756 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3757 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3758 {
3759 VTY_DECLVAR_CONTEXT(bgp, bgp);
3760 afi_t afi;
3761 safi_t safi;
3762
3763 if (!bw_cfg) {
3764 vty_out(vty, "%% Bandwidth configuration must be specified\n");
3765 return CMD_ERR_INCOMPLETE;
3766 }
3767 if (!strcmp(bw_cfg, "ignore"))
3768 bgp->lb_handling = BGP_LINK_BW_IGNORE_BW;
3769 else if (!strcmp(bw_cfg, "skip-missing"))
3770 bgp->lb_handling = BGP_LINK_BW_SKIP_MISSING;
3771 else if (!strcmp(bw_cfg, "default-weight-for-missing"))
3772 bgp->lb_handling = BGP_LINK_BW_DEFWT_4_MISSING;
3773 else
3774 return CMD_ERR_NO_MATCH;
3775
3776 /* This config is used in route install, so redo that. */
3777 FOREACH_AFI_SAFI (afi, safi) {
3778 if (!bgp_fibupd_safi(safi))
3779 continue;
3780 bgp_zebra_announce_table(bgp, afi, safi);
3781 }
3782
3783 return CMD_SUCCESS;
3784 }
3785
3786 DEFPY (no_bgp_bestpath_bw,
3787 no_bgp_bestpath_bw_cmd,
3788 "no bgp bestpath bandwidth [<ignore|skip-missing|default-weight-for-missing>$bw_cfg]",
3789 NO_STR
3790 "BGP specific commands\n"
3791 "Change the default bestpath selection\n"
3792 "Link Bandwidth attribute\n"
3793 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3794 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3795 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3796 {
3797 VTY_DECLVAR_CONTEXT(bgp, bgp);
3798 afi_t afi;
3799 safi_t safi;
3800
3801 bgp->lb_handling = BGP_LINK_BW_ECMP;
3802
3803 /* This config is used in route install, so redo that. */
3804 FOREACH_AFI_SAFI (afi, safi) {
3805 if (!bgp_fibupd_safi(safi))
3806 continue;
3807 bgp_zebra_announce_table(bgp, afi, safi);
3808 }
3809 return CMD_SUCCESS;
3810 }
3811
3812 DEFPY(bgp_default_afi_safi, bgp_default_afi_safi_cmd,
3813 "[no] bgp default <ipv4-unicast|"
3814 "ipv4-multicast|"
3815 "ipv4-vpn|"
3816 "ipv4-labeled-unicast|"
3817 "ipv4-flowspec|"
3818 "ipv6-unicast|"
3819 "ipv6-multicast|"
3820 "ipv6-vpn|"
3821 "ipv6-labeled-unicast|"
3822 "ipv6-flowspec|"
3823 "l2vpn-evpn>$afi_safi",
3824 NO_STR
3825 "BGP specific commands\n"
3826 "Configure BGP defaults\n"
3827 "Activate ipv4-unicast for a peer by default\n"
3828 "Activate ipv4-multicast for a peer by default\n"
3829 "Activate ipv4-vpn for a peer by default\n"
3830 "Activate ipv4-labeled-unicast for a peer by default\n"
3831 "Activate ipv4-flowspec for a peer by default\n"
3832 "Activate ipv6-unicast for a peer by default\n"
3833 "Activate ipv6-multicast for a peer by default\n"
3834 "Activate ipv6-vpn for a peer by default\n"
3835 "Activate ipv6-labeled-unicast for a peer by default\n"
3836 "Activate ipv6-flowspec for a peer by default\n"
3837 "Activate l2vpn-evpn for a peer by default\n")
3838 {
3839 VTY_DECLVAR_CONTEXT(bgp, bgp);
3840 char afi_safi_str[strlen(afi_safi) + 1];
3841 char *afi_safi_str_tok;
3842
3843 strlcpy(afi_safi_str, afi_safi, sizeof(afi_safi_str));
3844 char *afi_str = strtok_r(afi_safi_str, "-", &afi_safi_str_tok);
3845 char *safi_str = strtok_r(NULL, "-", &afi_safi_str_tok);
3846 afi_t afi = bgp_vty_afi_from_str(afi_str);
3847 safi_t safi;
3848
3849 if (strmatch(safi_str, "labeled"))
3850 safi = bgp_vty_safi_from_str("labeled-unicast");
3851 else
3852 safi = bgp_vty_safi_from_str(safi_str);
3853
3854 if (no)
3855 bgp->default_af[afi][safi] = false;
3856 else {
3857 if ((safi == SAFI_LABELED_UNICAST
3858 && bgp->default_af[afi][SAFI_UNICAST])
3859 || (safi == SAFI_UNICAST
3860 && bgp->default_af[afi][SAFI_LABELED_UNICAST]))
3861 bgp_vty_return(vty, BGP_ERR_PEER_SAFI_CONFLICT);
3862 else
3863 bgp->default_af[afi][safi] = true;
3864 }
3865
3866 return CMD_SUCCESS;
3867 }
3868
3869 /* Display hostname in certain command outputs */
3870 DEFUN_YANG (bgp_default_show_hostname,
3871 bgp_default_show_hostname_cmd,
3872 "bgp default show-hostname",
3873 "BGP specific commands\n"
3874 "Configure BGP defaults\n"
3875 "Show hostname in certain command outputs\n")
3876 {
3877 nb_cli_enqueue_change(vty, "./global/show-hostname", NB_OP_MODIFY,
3878 "true");
3879
3880 return nb_cli_apply_changes(vty, NULL);
3881 }
3882
3883 DEFUN_YANG(no_bgp_default_show_hostname,
3884 no_bgp_default_show_hostname_cmd,
3885 "no bgp default show-hostname",
3886 NO_STR
3887 "BGP specific commands\n"
3888 "Configure BGP defaults\n"
3889 "Show hostname in certain command outputs\n")
3890 {
3891 nb_cli_enqueue_change(vty, "./global/show-hostname", NB_OP_MODIFY,
3892 "false");
3893
3894 return nb_cli_apply_changes(vty, NULL);
3895 }
3896
3897 void cli_show_router_bgp_show_hostname(struct vty *vty, struct lyd_node *dnode,
3898 bool show_defaults)
3899 {
3900 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_SHOW_HOSTNAME)
3901 vty_out(vty, " bgp default show-hostname\n");
3902 }
3903
3904 /* Display hostname in certain command outputs */
3905 DEFUN_YANG(bgp_default_show_nexthop_hostname,
3906 bgp_default_show_nexthop_hostname_cmd,
3907 "bgp default show-nexthop-hostname",
3908 "BGP specific commands\n"
3909 "Configure BGP defaults\n"
3910 "Show hostname for nexthop in certain command outputs\n")
3911 {
3912 nb_cli_enqueue_change(vty, "./global/show-nexthop-hostname",
3913 NB_OP_MODIFY, "true");
3914
3915 return nb_cli_apply_changes(vty, NULL);
3916 }
3917
3918 DEFUN (no_bgp_default_show_nexthop_hostname,
3919 no_bgp_default_show_nexthop_hostname_cmd,
3920 "no bgp default show-nexthop-hostname",
3921 NO_STR
3922 "BGP specific commands\n"
3923 "Configure BGP defaults\n"
3924 "Show hostname for nexthop in certain command outputs\n")
3925 {
3926 nb_cli_enqueue_change(vty, "./global/show-nexthop-hostname",
3927 NB_OP_MODIFY, "false");
3928
3929 return nb_cli_apply_changes(vty, NULL);
3930 }
3931
3932 void cli_show_router_bgp_show_nexthop_hostname(struct vty *vty,
3933 struct lyd_node *dnode,
3934 bool show_defaults)
3935 {
3936 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_SHOW_HOSTNAME)
3937 vty_out(vty, " bgp default show-nexthop-hostname\n");
3938 }
3939
3940 /* "bgp network import-check" configuration. */
3941 DEFUN_YANG(bgp_network_import_check,
3942 bgp_network_import_check_cmd,
3943 "bgp network import-check",
3944 "BGP specific commands\n"
3945 "BGP network command\n"
3946 "Check BGP network route exists in IGP\n")
3947 {
3948 nb_cli_enqueue_change(vty, "./global/import-check", NB_OP_MODIFY,
3949 "true");
3950
3951 return nb_cli_apply_changes(vty, NULL);
3952 }
3953
3954 ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
3955 "bgp network import-check exact",
3956 "BGP specific commands\n"
3957 "BGP network command\n"
3958 "Check BGP network route exists in IGP\n"
3959 "Match route precisely\n")
3960
3961 DEFUN_YANG(no_bgp_network_import_check,
3962 no_bgp_network_import_check_cmd,
3963 "no bgp network import-check",
3964 NO_STR
3965 "BGP specific commands\n"
3966 "BGP network command\n"
3967 "Check BGP network route exists in IGP\n")
3968 {
3969 nb_cli_enqueue_change(vty, "./global/import-check", NB_OP_MODIFY,
3970 "false");
3971
3972 return nb_cli_apply_changes(vty, NULL);
3973 }
3974
3975 void cli_show_router_bgp_import_check(struct vty *vty, struct lyd_node *dnode,
3976 bool show_defaults)
3977 {
3978 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_IMPORT_CHECK)
3979 vty_out(vty, " bgp network import-check\n");
3980 }
3981
3982 DEFUN_YANG(bgp_default_local_preference,
3983 bgp_default_local_preference_cmd,
3984 "bgp default local-preference (0-4294967295)",
3985 "BGP specific commands\n"
3986 "Configure BGP defaults\n"
3987 "local preference (higher=more preferred)\n"
3988 "Configure default local preference value\n")
3989 {
3990 int idx_number = 3;
3991
3992 nb_cli_enqueue_change(vty, "./global/local-pref", NB_OP_MODIFY,
3993 argv[idx_number]->arg);
3994
3995 return nb_cli_apply_changes(vty, NULL);
3996 }
3997
3998 DEFUN_YANG(no_bgp_default_local_preference,
3999 no_bgp_default_local_preference_cmd,
4000 "no bgp default local-preference [(0-4294967295)]",
4001 NO_STR
4002 "BGP specific commands\n"
4003 "Configure BGP defaults\n"
4004 "local preference (higher=more preferred)\n"
4005 "Configure default local preference value\n")
4006 {
4007 nb_cli_enqueue_change(vty, "./global/local-pref", NB_OP_MODIFY, NULL);
4008
4009 return nb_cli_apply_changes(vty, NULL);
4010 }
4011
4012 void cli_show_router_bgp_local_pref(struct vty *vty, struct lyd_node *dnode,
4013 bool show_defaults)
4014 {
4015 vty_out(vty, " bgp default local-preference %u\n",
4016 yang_dnode_get_uint32(dnode, NULL));
4017 }
4018
4019
4020 DEFUN_YANG(bgp_default_subgroup_pkt_queue_max,
4021 bgp_default_subgroup_pkt_queue_max_cmd,
4022 "bgp default subgroup-pkt-queue-max (20-100)",
4023 "BGP specific commands\n"
4024 "Configure BGP defaults\n"
4025 "subgroup-pkt-queue-max\n"
4026 "Configure subgroup packet queue max\n")
4027 {
4028 int idx_number = 3;
4029
4030 nb_cli_enqueue_change(
4031 vty,
4032 "./global/global-update-group-config/subgroup-pkt-queue-size",
4033 NB_OP_MODIFY, argv[idx_number]->arg);
4034
4035 return nb_cli_apply_changes(vty, NULL);
4036 }
4037
4038 DEFUN_YANG(no_bgp_default_subgroup_pkt_queue_max,
4039 no_bgp_default_subgroup_pkt_queue_max_cmd,
4040 "no bgp default subgroup-pkt-queue-max [(20-100)]",
4041 NO_STR
4042 "BGP specific commands\n"
4043 "Configure BGP defaults\n"
4044 "subgroup-pkt-queue-max\n"
4045 "Configure subgroup packet queue max\n")
4046 {
4047 nb_cli_enqueue_change(
4048 vty,
4049 "./global/global-update-group-config/subgroup-pkt-queue-size",
4050 NB_OP_MODIFY, NULL);
4051
4052 return nb_cli_apply_changes(vty, NULL);
4053 }
4054
4055 void cli_show_router_global_update_group_config_subgroup_pkt_queue_size(
4056 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
4057 {
4058 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
4059 yang_dnode_get_uint32(dnode, NULL));
4060 }
4061
4062 DEFUN_YANG(bgp_rr_allow_outbound_policy,
4063 bgp_rr_allow_outbound_policy_cmd,
4064 "bgp route-reflector allow-outbound-policy",
4065 "BGP specific commands\n"
4066 "Allow modifications made by out route-map\n"
4067 "on ibgp neighbors\n")
4068 {
4069 nb_cli_enqueue_change(vty,
4070 "./global/route-reflector/allow-outbound-policy",
4071 NB_OP_MODIFY, "true");
4072
4073 return nb_cli_apply_changes(vty, NULL);
4074 }
4075
4076 DEFUN_YANG(no_bgp_rr_allow_outbound_policy,
4077 no_bgp_rr_allow_outbound_policy_cmd,
4078 "no bgp route-reflector allow-outbound-policy",
4079 NO_STR
4080 "BGP specific commands\n"
4081 "Allow modifications made by out route-map\n"
4082 "on ibgp neighbors\n")
4083 {
4084 nb_cli_enqueue_change(vty,
4085 "./global/route-reflector/allow-outbound-policy",
4086 NB_OP_MODIFY, "false");
4087
4088 return nb_cli_apply_changes(vty, NULL);
4089 }
4090
4091
4092 void cli_show_router_global_neighbor_config(struct vty *vty,
4093 struct lyd_node *dnode,
4094 bool show_defaults)
4095 {
4096 uint32_t write_quanta, read_quanta;
4097
4098 if (yang_dnode_get_bool(dnode, "./log-neighbor-changes"))
4099 vty_out(vty, " bgp log-neighbor-changes\n");
4100
4101 if (yang_dnode_exists(dnode, "./dynamic-neighbors-limit")) {
4102 uint32_t listen_limit = yang_dnode_get_uint32(
4103 dnode, "./dynamic-neighbors-limit");
4104 vty_out(vty, " bgp listen limit %u\n", listen_limit);
4105 }
4106
4107 write_quanta = yang_dnode_get_uint32(
4108 dnode, "./packet-quanta-config/wpkt-quanta");
4109 if (write_quanta != BGP_WRITE_PACKET_MAX)
4110 vty_out(vty, " write-quanta %d\n", write_quanta);
4111
4112 read_quanta = yang_dnode_get_uint32(
4113 dnode, "./packet-quanta-config/rpkt-quanta");
4114
4115 if (read_quanta != BGP_READ_PACKET_MAX)
4116 vty_out(vty, " read-quanta %d\n", read_quanta);
4117 }
4118
4119 DEFUN_YANG(bgp_listen_limit,
4120 bgp_listen_limit_cmd,
4121 "bgp listen limit (1-65535)",
4122 "BGP specific commands\n"
4123 "BGP Dynamic Neighbors listen commands\n"
4124 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4125 "Configure Dynamic Neighbors listen limit value\n")
4126 {
4127 int idx_number = 3;
4128
4129 nb_cli_enqueue_change(
4130 vty, "./global/global-neighbor-config/dynamic-neighbors-limit",
4131 NB_OP_MODIFY, argv[idx_number]->arg);
4132
4133 return nb_cli_apply_changes(vty, NULL);
4134 }
4135
4136 DEFUN_YANG(no_bgp_listen_limit,
4137 no_bgp_listen_limit_cmd,
4138 "no bgp listen limit [(1-65535)]",
4139 NO_STR
4140 "BGP specific commands\n"
4141 "BGP Dynamic Neighbors listen commands\n"
4142 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4143 "Configure Dynamic Neighbors listen limit value\n")
4144 {
4145 nb_cli_enqueue_change(
4146 vty, "./global/global-neighbor-config/dynamic-neighbors-limit",
4147 NB_OP_DESTROY, NULL);
4148
4149 return nb_cli_apply_changes(vty, NULL);
4150 }
4151
4152
4153 /*
4154 * Check if this listen range is already configured. Check for exact
4155 * match or overlap based on input.
4156 */
4157 static struct peer_group *listen_range_exists(struct bgp *bgp,
4158 struct prefix *range, int exact)
4159 {
4160 struct listnode *node, *nnode;
4161 struct listnode *node1, *nnode1;
4162 struct peer_group *group;
4163 struct prefix *lr;
4164 afi_t afi;
4165 int match;
4166
4167 afi = family2afi(range->family);
4168 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4169 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
4170 lr)) {
4171 if (exact)
4172 match = prefix_same(range, lr);
4173 else
4174 match = (prefix_match(range, lr)
4175 || prefix_match(lr, range));
4176 if (match)
4177 return group;
4178 }
4179 }
4180
4181 return NULL;
4182 }
4183
4184 DEFUN (bgp_listen_range,
4185 bgp_listen_range_cmd,
4186 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
4187 "BGP specific commands\n"
4188 "Configure BGP dynamic neighbors listen range\n"
4189 "Configure BGP dynamic neighbors listen range\n"
4190 NEIGHBOR_ADDR_STR
4191 "Member of the peer-group\n"
4192 "Peer-group name\n")
4193 {
4194 VTY_DECLVAR_CONTEXT(bgp, bgp);
4195 struct prefix range;
4196 struct peer_group *group, *existing_group;
4197 afi_t afi;
4198 int ret;
4199 int idx = 0;
4200
4201 argv_find(argv, argc, "A.B.C.D/M", &idx);
4202 argv_find(argv, argc, "X:X::X:X/M", &idx);
4203 char *prefix = argv[idx]->arg;
4204 argv_find(argv, argc, "PGNAME", &idx);
4205 char *peergroup = argv[idx]->arg;
4206
4207 /* Convert IP prefix string to struct prefix. */
4208 ret = str2prefix(prefix, &range);
4209 if (!ret) {
4210 vty_out(vty, "%% Malformed listen range\n");
4211 return CMD_WARNING_CONFIG_FAILED;
4212 }
4213
4214 afi = family2afi(range.family);
4215
4216 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4217 vty_out(vty,
4218 "%% Malformed listen range (link-local address)\n");
4219 return CMD_WARNING_CONFIG_FAILED;
4220 }
4221
4222 apply_mask(&range);
4223
4224 /* Check if same listen range is already configured. */
4225 existing_group = listen_range_exists(bgp, &range, 1);
4226 if (existing_group) {
4227 if (strcmp(existing_group->name, peergroup) == 0)
4228 return CMD_SUCCESS;
4229 else {
4230 vty_out(vty,
4231 "%% Same listen range is attached to peer-group %s\n",
4232 existing_group->name);
4233 return CMD_WARNING_CONFIG_FAILED;
4234 }
4235 }
4236
4237 /* Check if an overlapping listen range exists. */
4238 if (listen_range_exists(bgp, &range, 0)) {
4239 vty_out(vty,
4240 "%% Listen range overlaps with existing listen range\n");
4241 return CMD_WARNING_CONFIG_FAILED;
4242 }
4243
4244 group = peer_group_lookup(bgp, peergroup);
4245 if (!group) {
4246 vty_out(vty, "%% Configure the peer-group first\n");
4247 return CMD_WARNING_CONFIG_FAILED;
4248 }
4249
4250 ret = peer_group_listen_range_add(group, &range);
4251 return bgp_vty_return(vty, ret);
4252 }
4253
4254 DEFUN (no_bgp_listen_range,
4255 no_bgp_listen_range_cmd,
4256 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
4257 NO_STR
4258 "BGP specific commands\n"
4259 "Unconfigure BGP dynamic neighbors listen range\n"
4260 "Unconfigure BGP dynamic neighbors listen range\n"
4261 NEIGHBOR_ADDR_STR
4262 "Member of the peer-group\n"
4263 "Peer-group name\n")
4264 {
4265 VTY_DECLVAR_CONTEXT(bgp, bgp);
4266 struct prefix range;
4267 struct peer_group *group;
4268 afi_t afi;
4269 int ret;
4270 int idx = 0;
4271
4272 argv_find(argv, argc, "A.B.C.D/M", &idx);
4273 argv_find(argv, argc, "X:X::X:X/M", &idx);
4274 char *prefix = argv[idx]->arg;
4275 argv_find(argv, argc, "PGNAME", &idx);
4276 char *peergroup = argv[idx]->arg;
4277
4278 /* Convert IP prefix string to struct prefix. */
4279 ret = str2prefix(prefix, &range);
4280 if (!ret) {
4281 vty_out(vty, "%% Malformed listen range\n");
4282 return CMD_WARNING_CONFIG_FAILED;
4283 }
4284
4285 afi = family2afi(range.family);
4286
4287 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4288 vty_out(vty,
4289 "%% Malformed listen range (link-local address)\n");
4290 return CMD_WARNING_CONFIG_FAILED;
4291 }
4292
4293 apply_mask(&range);
4294
4295 group = peer_group_lookup(bgp, peergroup);
4296 if (!group) {
4297 vty_out(vty, "%% Peer-group does not exist\n");
4298 return CMD_WARNING_CONFIG_FAILED;
4299 }
4300
4301 ret = peer_group_listen_range_del(group, &range);
4302 return bgp_vty_return(vty, ret);
4303 }
4304
4305 void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
4306 {
4307 struct peer_group *group;
4308 struct listnode *node, *nnode, *rnode, *nrnode;
4309 struct prefix *range;
4310 afi_t afi;
4311
4312 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
4313 vty_out(vty, " bgp listen limit %d\n",
4314 bgp->dynamic_neighbors_limit);
4315
4316 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4317 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
4318 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
4319 nrnode, range)) {
4320 vty_out(vty,
4321 " bgp listen range %pFX peer-group %s\n",
4322 range, group->name);
4323 }
4324 }
4325 }
4326 }
4327
4328
4329 DEFUN_YANG(bgp_disable_connected_route_check,
4330 bgp_disable_connected_route_check_cmd,
4331 "bgp disable-ebgp-connected-route-check",
4332 "BGP specific commands\n"
4333 "Disable checking if nexthop is connected on ebgp sessions\n")
4334 {
4335 nb_cli_enqueue_change(vty,
4336 "./global/ebgp-multihop-connected-route-check",
4337 NB_OP_MODIFY, "true");
4338
4339 return nb_cli_apply_changes(vty, NULL);
4340 }
4341
4342 DEFUN_YANG(no_bgp_disable_connected_route_check,
4343 no_bgp_disable_connected_route_check_cmd,
4344 "no bgp disable-ebgp-connected-route-check",
4345 NO_STR
4346 "BGP specific commands\n"
4347 "Disable checking if nexthop is connected on ebgp sessions\n")
4348 {
4349 nb_cli_enqueue_change(vty,
4350 "./global/ebgp-multihop-connected-route-check",
4351 NB_OP_MODIFY, "false");
4352
4353 return nb_cli_apply_changes(vty, NULL);
4354 }
4355
4356 void cli_show_router_global_ebgp_multihop_connected_route_check(
4357 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
4358 {
4359 if (yang_dnode_get_bool(dnode, NULL))
4360 vty_out(vty, " bgp disable-ebgp-connected-route-check\n");
4361 }
4362
4363 DEFUN_YANG(bgp_default_shutdown,
4364 bgp_default_shutdown_cmd,
4365 "[no] bgp default shutdown",
4366 NO_STR BGP_STR
4367 "Configure BGP defaults\n"
4368 "Apply administrative shutdown to newly configured peers\n")
4369 {
4370 nb_cli_enqueue_change(vty, "./global/default-shutdown", NB_OP_MODIFY,
4371 strmatch(argv[0]->text, "no") ? "false" : "true");
4372
4373 return nb_cli_apply_changes(vty, NULL);
4374 }
4375
4376 void cli_show_router_bgp_default_shutdown(struct vty *vty,
4377 struct lyd_node *dnode,
4378 bool show_defaults)
4379 {
4380 if (yang_dnode_get_bool(dnode, NULL))
4381 vty_out(vty, " bgp default shutdown\n");
4382 }
4383
4384 DEFPY(bgp_shutdown_msg, bgp_shutdown_msg_cmd, "bgp shutdown message MSG...",
4385 BGP_STR
4386 "Administrative shutdown of the BGP instance\n"
4387 "Add a shutdown message (RFC 8203)\n"
4388 "Shutdown message\n")
4389 {
4390 char *msgstr = NULL;
4391
4392 VTY_DECLVAR_CONTEXT(bgp, bgp);
4393
4394 if (argc > 3)
4395 msgstr = argv_concat(argv, argc, 3);
4396
4397 bgp_shutdown_enable(bgp, msgstr);
4398 XFREE(MTYPE_TMP, msgstr);
4399
4400 return CMD_SUCCESS;
4401 }
4402
4403 DEFPY(bgp_shutdown, bgp_shutdown_cmd, "bgp shutdown",
4404 BGP_STR "Administrative shutdown of the BGP instance\n")
4405 {
4406 VTY_DECLVAR_CONTEXT(bgp, bgp);
4407
4408 bgp_shutdown_enable(bgp, NULL);
4409
4410 return CMD_SUCCESS;
4411 }
4412
4413 DEFPY(no_bgp_shutdown, no_bgp_shutdown_cmd, "no bgp shutdown",
4414 NO_STR BGP_STR "Administrative shutdown of the BGP instance\n")
4415 {
4416 VTY_DECLVAR_CONTEXT(bgp, bgp);
4417
4418 bgp_shutdown_disable(bgp);
4419
4420 return CMD_SUCCESS;
4421 }
4422
4423 ALIAS(no_bgp_shutdown, no_bgp_shutdown_msg_cmd,
4424 "no bgp shutdown message MSG...", NO_STR BGP_STR
4425 "Administrative shutdown of the BGP instance\n"
4426 "Add a shutdown message (RFC 8203)\n" "Shutdown message\n")
4427
4428 DEFUN_YANG(neighbor_remote_as,
4429 neighbor_remote_as_cmd,
4430 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
4431 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4432 "Specify a BGP neighbor\n" AS_STR
4433 "Internal BGP peer\n"
4434 "External BGP peer\n")
4435 {
4436 int idx_peer = 1;
4437 int idx_remote_as = 3;
4438 char base_xpath[XPATH_MAXLEN];
4439 char unnbr_xpath[XPATH_MAXLEN];
4440 char prgrp_xpath[XPATH_MAXLEN];
4441 union sockunion su;
4442 const char *as_type_str = "as-specified";
4443
4444 if (str2sockunion(argv[idx_peer]->arg, &su) < 0) {
4445 snprintf(unnbr_xpath, sizeof(unnbr_xpath),
4446 FRR_BGP_NEIGHBOR_UNNUM_XPATH, argv[idx_peer]->arg, "");
4447
4448 snprintf(prgrp_xpath, sizeof(prgrp_xpath),
4449 FRR_BGP_PEER_GROUP_XPATH, argv[idx_peer]->arg, "");
4450
4451 if (yang_dnode_existsf(vty->candidate_config->dnode, "%s%s",
4452 VTY_CURR_XPATH, unnbr_xpath + 1)) {
4453 strlcpy(base_xpath, unnbr_xpath, sizeof(base_xpath));
4454 } else if (yang_dnode_existsf(vty->candidate_config->dnode,
4455 "%s%s", VTY_CURR_XPATH,
4456 prgrp_xpath + 1)) {
4457 snprintf(base_xpath, sizeof(base_xpath),
4458 FRR_BGP_PEER_GROUP_XPATH, argv[idx_peer]->arg,
4459 "");
4460 } else {
4461 vty_out(vty,
4462 "%% Create the peer-group or interface first\n");
4463 return CMD_WARNING_CONFIG_FAILED;
4464 }
4465 } else {
4466 snprintf(base_xpath, sizeof(base_xpath),
4467 FRR_BGP_NEIGHBOR_NUM_XPATH, argv[idx_peer]->arg, "");
4468 }
4469
4470 if (argv[idx_remote_as]->arg[0] == 'i') {
4471 as_type_str = "internal";
4472 } else if (argv[idx_remote_as]->arg[0] == 'e') {
4473 as_type_str = "external";
4474 } else {
4475 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as",
4476 NB_OP_MODIFY, argv[idx_remote_as]->arg);
4477 }
4478 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as-type",
4479 NB_OP_MODIFY, as_type_str);
4480
4481 return nb_cli_apply_changes(vty, base_xpath);
4482 }
4483
4484 int peer_conf_interface_create(struct bgp *bgp, const char *conf_if,
4485 bool v6only, const char *peer_group_name,
4486 int as_type, as_t as, char *errmsg,
4487 size_t errmsg_len)
4488 {
4489 struct peer *peer;
4490 struct peer_group *group;
4491 int ret = 0;
4492
4493 group = peer_group_lookup(bgp, conf_if);
4494
4495 if (group) {
4496 snprintf(errmsg, errmsg_len,
4497 "Name conflict with peer-group \n");
4498 return -1;
4499 }
4500
4501 peer = peer_lookup_by_conf_if(bgp, conf_if);
4502 if (peer) {
4503 if (as_type != AS_UNSPECIFIED)
4504 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type);
4505 } else {
4506 peer = peer_create(NULL, conf_if, bgp, bgp->as, as, as_type,
4507 NULL);
4508
4509 if (!peer) {
4510 snprintf(errmsg, errmsg_len,
4511 "BGP failed to create peer\n");
4512 return -1;
4513 }
4514
4515 if (v6only)
4516 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
4517
4518 /* Request zebra to initiate IPv6 RAs on this interface. We do
4519 * this
4520 * any unnumbered peer in order to not worry about run-time
4521 * transitions
4522 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
4523 * address
4524 * gets deleted later etc.)
4525 */
4526 if (peer->ifp)
4527 bgp_zebra_initiate_radv(bgp, peer);
4528 }
4529
4530 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
4531 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
4532 if (v6only)
4533 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
4534 else
4535 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
4536
4537 /* v6only flag changed. Reset bgp seesion */
4538 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
4539 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
4540 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
4541 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
4542 } else
4543 bgp_session_reset(peer);
4544 }
4545
4546 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
4547 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
4548 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
4549 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
4550 }
4551
4552 if (peer_group_name) {
4553 group = peer_group_lookup(bgp, peer_group_name);
4554 if (!group) {
4555 snprintf(errmsg, errmsg_len,
4556 "Configure the peer-group first\n");
4557 return -1;
4558 }
4559
4560 ret = peer_group_bind(bgp, NULL, peer, group, &as);
4561 }
4562
4563 return bgp_nb_errmsg_return(errmsg, errmsg_len, ret);
4564 }
4565
4566 DEFUN_YANG(neighbor_interface_config,
4567 neighbor_interface_config_cmd,
4568 "neighbor WORD interface [peer-group PGNAME]",
4569 NEIGHBOR_STR
4570 "Interface name or neighbor tag\n"
4571 "Enable BGP on interface\n"
4572 "Member of the peer-group\n"
4573 "Peer-group name\n")
4574 {
4575 int idx_word = 1;
4576 int idx_peer_group_word = 4;
4577 char base_xpath[XPATH_MAXLEN];
4578
4579 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4580 argv[idx_word]->arg, "");
4581
4582 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
4583 if (argc > idx_peer_group_word)
4584 nb_cli_enqueue_change(vty, "./peer-group", NB_OP_MODIFY,
4585 argv[idx_peer_group_word]->arg);
4586
4587 return nb_cli_apply_changes(vty, base_xpath);
4588 }
4589
4590 DEFUN_YANG(neighbor_interface_config_v6only,
4591 neighbor_interface_config_v6only_cmd,
4592 "neighbor WORD interface v6only [peer-group PGNAME]",
4593 NEIGHBOR_STR
4594 "Interface name or neighbor tag\n"
4595 "Enable BGP on interface\n"
4596 "Enable BGP with v6 link-local only\n"
4597 "Member of the peer-group\n"
4598 "Peer-group name\n")
4599 {
4600 int idx_word = 1;
4601 int idx_peer_group_word = 5;
4602 char base_xpath[XPATH_MAXLEN];
4603
4604 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4605 argv[idx_word]->arg, "");
4606
4607 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
4608 if (argc > idx_peer_group_word)
4609 nb_cli_enqueue_change(vty, "./peer-group", NB_OP_MODIFY,
4610 argv[idx_peer_group_word]->arg);
4611
4612 nb_cli_enqueue_change(vty, "./v6only", NB_OP_MODIFY, "true");
4613
4614 return nb_cli_apply_changes(vty, base_xpath);
4615 }
4616
4617
4618 DEFUN_YANG(
4619 neighbor_interface_config_remote_as,
4620 neighbor_interface_config_remote_as_cmd,
4621 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
4622 NEIGHBOR_STR
4623 "Interface name or neighbor tag\n"
4624 "Enable BGP on interface\n"
4625 "Specify a BGP neighbor\n" AS_STR
4626 "Internal BGP peer\n"
4627 "External BGP peer\n")
4628 {
4629 int idx_word = 1;
4630 int idx_remote_as = 4;
4631 char base_xpath[XPATH_MAXLEN];
4632 const char *as_type_str = "as-specified";
4633
4634 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4635 argv[idx_word]->arg, "");
4636
4637 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
4638
4639 if (argv[idx_remote_as]->arg[0] == 'i') {
4640 as_type_str = "internal";
4641 } else if (argv[idx_remote_as]->arg[0] == 'e') {
4642 as_type_str = "external";
4643 } else {
4644 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as",
4645 NB_OP_MODIFY, argv[idx_remote_as]->arg);
4646 }
4647 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as-type",
4648 NB_OP_MODIFY, as_type_str);
4649
4650 return nb_cli_apply_changes(vty, base_xpath);
4651 }
4652
4653 DEFUN_YANG(
4654 neighbor_interface_v6only_config_remote_as,
4655 neighbor_interface_v6only_config_remote_as_cmd,
4656 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
4657 NEIGHBOR_STR
4658 "Interface name or neighbor tag\n"
4659 "Enable BGP with v6 link-local only\n"
4660 "Enable BGP on interface\n"
4661 "Specify a BGP neighbor\n" AS_STR
4662 "Internal BGP peer\n"
4663 "External BGP peer\n")
4664 {
4665 int idx_word = 1;
4666 int idx_remote_as = 5;
4667 char base_xpath[XPATH_MAXLEN];
4668 const char *as_type_str = "as-specified";
4669
4670 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4671 argv[idx_word]->arg, "");
4672
4673 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
4674
4675 nb_cli_enqueue_change(vty, "./v6only", NB_OP_MODIFY, "true");
4676
4677 if (argv[idx_remote_as]->arg[0] == 'i') {
4678 as_type_str = "internal";
4679 } else if (argv[idx_remote_as]->arg[0] == 'e') {
4680 as_type_str = "external";
4681 } else {
4682 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as",
4683 NB_OP_MODIFY, argv[idx_remote_as]->arg);
4684 }
4685 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as-type",
4686 NB_OP_MODIFY, as_type_str);
4687
4688 return nb_cli_apply_changes(vty, base_xpath);
4689 }
4690
4691 DEFUN_YANG(neighbor_peer_group, neighbor_peer_group_cmd,
4692 "neighbor WORD peer-group",
4693 NEIGHBOR_STR
4694 "Interface name or neighbor tag\n"
4695 "Configure peer-group\n")
4696 {
4697 char base_xpath[XPATH_MAXLEN];
4698 int idx_word = 1;
4699
4700 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_PEER_GROUP_XPATH,
4701 argv[idx_word]->arg, "");
4702
4703 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
4704
4705 return nb_cli_apply_changes(vty, base_xpath);
4706 }
4707
4708 DEFUN_YANG(no_neighbor,
4709 no_neighbor_cmd,
4710 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
4711 NO_STR NEIGHBOR_STR
4712 NEIGHBOR_ADDR_STR2
4713 "Specify a BGP neighbor\n" AS_STR
4714 "Internal BGP peer\n"
4715 "External BGP peer\n")
4716 {
4717 int idx_peer = 2;
4718 char base_xpath[XPATH_MAXLEN];
4719 char num_xpath[XPATH_MAXLEN];
4720 char unnbr_xpath[XPATH_MAXLEN];
4721 char prgrp_xpath[XPATH_MAXLEN];
4722 union sockunion su;
4723
4724 if (str2sockunion(argv[idx_peer]->arg, &su) == 0) {
4725 snprintf(num_xpath, sizeof(num_xpath),
4726 FRR_BGP_NEIGHBOR_NUM_XPATH, argv[idx_peer]->arg, "");
4727 if (yang_dnode_existsf(vty->candidate_config->dnode, "%s%s",
4728 VTY_CURR_XPATH, num_xpath + 1)) {
4729 strlcpy(base_xpath, num_xpath, sizeof(base_xpath));
4730 }
4731 } else {
4732 snprintf(unnbr_xpath, sizeof(unnbr_xpath),
4733 FRR_BGP_NEIGHBOR_UNNUM_XPATH, argv[idx_peer]->arg, "");
4734
4735 snprintf(prgrp_xpath, sizeof(prgrp_xpath),
4736 FRR_BGP_PEER_GROUP_XPATH, argv[idx_peer]->arg, "");
4737
4738 if (yang_dnode_existsf(vty->candidate_config->dnode, "%s%s",
4739 VTY_CURR_XPATH, unnbr_xpath + 1)) {
4740 strlcpy(base_xpath, unnbr_xpath, sizeof(base_xpath));
4741 } else if (yang_dnode_existsf(vty->candidate_config->dnode,
4742 "%s%s", VTY_CURR_XPATH,
4743 prgrp_xpath + 1)) {
4744 strlcpy(base_xpath, prgrp_xpath, sizeof(base_xpath));
4745 } else {
4746 vty_out(vty,
4747 "%% Create the peer-group or interface first\n");
4748 return CMD_WARNING_CONFIG_FAILED;
4749 }
4750 }
4751
4752 nb_cli_enqueue_change(vty, base_xpath, NB_OP_DESTROY, NULL);
4753
4754 /*
4755 * Need to commit any pending so this command doesn't merge with a
4756 * create into a modify, which BGP can't handle
4757 */
4758 return nb_cli_apply_changes_clear_pending(vty, NULL);
4759 }
4760
4761 DEFUN_YANG(no_neighbor_interface_config,
4762 no_neighbor_interface_config_cmd,
4763 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
4764 NO_STR NEIGHBOR_STR
4765 "Interface name\n"
4766 "Configure BGP on interface\n"
4767 "Enable BGP with v6 link-local only\n"
4768 "Member of the peer-group\n"
4769 "Peer-group name\n"
4770 "Specify a BGP neighbor\n" AS_STR
4771 "Internal BGP peer\n"
4772 "External BGP peer\n")
4773 {
4774 int idx_word = 2;
4775 char base_xpath[XPATH_MAXLEN];
4776
4777 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4778 argv[idx_word]->arg, "");
4779
4780 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
4781
4782 /*
4783 * Need to commit any pending so this command doesn't merge with a
4784 * create into a modify, which BGP can't handle
4785 */
4786 return nb_cli_apply_changes_clear_pending(vty, base_xpath);
4787 }
4788
4789 DEFUN_YANG(no_neighbor_peer_group,
4790 no_neighbor_peer_group_cmd,
4791 "no neighbor WORD peer-group",
4792 NO_STR NEIGHBOR_STR
4793 "Neighbor tag\n"
4794 "Configure peer-group\n")
4795 {
4796 char base_xpath[XPATH_MAXLEN];
4797 int idx_word = 2;
4798
4799 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_PEER_GROUP_XPATH,
4800 argv[idx_word]->arg, "");
4801
4802 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
4803
4804 /*
4805 * Need to commit any pending so this command doesn't merge with a
4806 * create into a modify, which BGP can't handle
4807 */
4808 return nb_cli_apply_changes_clear_pending(vty, base_xpath);
4809 }
4810
4811 DEFUN_YANG(no_neighbor_interface_peer_group_remote_as,
4812 no_neighbor_interface_peer_group_remote_as_cmd,
4813 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
4814 NO_STR NEIGHBOR_STR
4815 "Interface name or neighbor tag\n"
4816 "Specify a BGP neighbor\n" AS_STR
4817 "Internal BGP peer\n"
4818 "External BGP peer\n")
4819 {
4820 int idx_peer = 2;
4821 char base_xpath[XPATH_MAXLEN];
4822 char unnbr_xpath[XPATH_MAXLEN];
4823 char prgrp_xpath[XPATH_MAXLEN];
4824
4825 snprintf(unnbr_xpath, sizeof(unnbr_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4826 argv[idx_peer]->arg, "");
4827
4828 snprintf(prgrp_xpath, sizeof(prgrp_xpath), FRR_BGP_PEER_GROUP_XPATH,
4829 argv[idx_peer]->arg, "");
4830
4831 if (yang_dnode_existsf(vty->candidate_config->dnode, "%s%s",
4832 VTY_CURR_XPATH, unnbr_xpath + 1)) {
4833 strlcpy(base_xpath, unnbr_xpath, sizeof(base_xpath));
4834 } else if (yang_dnode_existsf(vty->candidate_config->dnode, "%s%s",
4835 VTY_CURR_XPATH, prgrp_xpath + 1)) {
4836 strlcpy(base_xpath, prgrp_xpath, sizeof(base_xpath));
4837 } else {
4838 vty_out(vty, "%% Create the peer-group or interface first\n");
4839 return CMD_WARNING_CONFIG_FAILED;
4840 }
4841
4842 strlcat(base_xpath, "/neighbor-remote-as/remote-as-type",
4843 sizeof(base_xpath));
4844
4845 nb_cli_enqueue_change(vty, base_xpath, NB_OP_DESTROY, NULL);
4846
4847 /*
4848 * Need to commit any pending so this command doesn't merge with a
4849 * create into a modify, which BGP can't handle
4850 */
4851 return nb_cli_apply_changes_clear_pending(vty, NULL);
4852 }
4853
4854 DEFUN_YANG(neighbor_local_as,
4855 neighbor_local_as_cmd,
4856 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
4857 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4858 "Specify a local-as number\n"
4859 "AS number used as local AS\n")
4860 {
4861 int idx_peer = 1;
4862 int idx_number = 3;
4863 char base_xpath[XPATH_MAXLEN];
4864
4865 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4866 sizeof(base_xpath), NULL)
4867 < 0)
4868 return CMD_WARNING_CONFIG_FAILED;
4869
4870 nb_cli_enqueue_change(vty, "./local-as/local-as", NB_OP_MODIFY,
4871 argv[idx_number]->arg);
4872
4873 return nb_cli_apply_changes(vty, base_xpath);
4874 }
4875
4876 DEFUN_YANG(
4877 neighbor_local_as_no_prepend, neighbor_local_as_no_prepend_cmd,
4878 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
4879 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4880 "Specify a local-as number\n"
4881 "AS number used as local AS\n"
4882 "Do not prepend local-as to updates from ebgp peers\n")
4883 {
4884 int idx_peer = 1;
4885 int idx_number = 3;
4886 char base_xpath[XPATH_MAXLEN];
4887
4888 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4889 sizeof(base_xpath), NULL)
4890 < 0)
4891 return CMD_WARNING_CONFIG_FAILED;
4892
4893 nb_cli_enqueue_change(vty, "./local-as/local-as", NB_OP_MODIFY,
4894 argv[idx_number]->arg);
4895 nb_cli_enqueue_change(vty, "./local-as/no-prepend", NB_OP_MODIFY,
4896 "true");
4897
4898 return nb_cli_apply_changes(vty, base_xpath);
4899 }
4900
4901 DEFUN_YANG(
4902 neighbor_local_as_no_prepend_replace_as,
4903 neighbor_local_as_no_prepend_replace_as_cmd,
4904 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
4905 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4906 "Specify a local-as number\n"
4907 "AS number used as local AS\n"
4908 "Do not prepend local-as to updates from ebgp peers\n"
4909 "Do not prepend local-as to updates from ibgp peers\n")
4910 {
4911 int idx_peer = 1;
4912 int idx_number = 3;
4913 char base_xpath[XPATH_MAXLEN];
4914
4915 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4916 sizeof(base_xpath), NULL)
4917 < 0)
4918 return CMD_WARNING_CONFIG_FAILED;
4919
4920 nb_cli_enqueue_change(vty, "./local-as/local-as", NB_OP_MODIFY,
4921 argv[idx_number]->arg);
4922 nb_cli_enqueue_change(vty, "./local-as/no-prepend", NB_OP_MODIFY,
4923 "true");
4924 nb_cli_enqueue_change(vty, "./local-as/replace-as", NB_OP_MODIFY,
4925 "true");
4926
4927 return nb_cli_apply_changes(vty, base_xpath);
4928 }
4929
4930 DEFUN_YANG(no_neighbor_local_as,
4931 no_neighbor_local_as_cmd,
4932 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
4933 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4934 "Specify a local-as number\n"
4935 "AS number used as local AS\n"
4936 "Do not prepend local-as to updates from ebgp peers\n"
4937 "Do not prepend local-as to updates from ibgp peers\n")
4938 {
4939 int idx_peer = 2;
4940 char base_xpath[XPATH_MAXLEN];
4941
4942 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4943 sizeof(base_xpath), NULL)
4944 < 0)
4945 return CMD_WARNING_CONFIG_FAILED;
4946
4947 nb_cli_enqueue_change(vty, "./local-as/local-as", NB_OP_DESTROY, NULL);
4948 nb_cli_enqueue_change(vty, "./local-as/no-prepend", NB_OP_MODIFY,
4949 "false");
4950 nb_cli_enqueue_change(vty, "./local-as/replace-as", NB_OP_MODIFY,
4951 "false");
4952
4953 return nb_cli_apply_changes(vty, base_xpath);
4954 }
4955
4956
4957 DEFUN (neighbor_solo,
4958 neighbor_solo_cmd,
4959 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
4960 NEIGHBOR_STR
4961 NEIGHBOR_ADDR_STR2
4962 "Solo peer - part of its own update group\n")
4963 {
4964 int idx_peer = 1;
4965 struct peer *peer;
4966 int ret;
4967
4968 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4969 if (!peer)
4970 return CMD_WARNING_CONFIG_FAILED;
4971
4972 ret = update_group_adjust_soloness(peer, 1);
4973 return bgp_vty_return(vty, ret);
4974 }
4975
4976 DEFUN (no_neighbor_solo,
4977 no_neighbor_solo_cmd,
4978 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
4979 NO_STR
4980 NEIGHBOR_STR
4981 NEIGHBOR_ADDR_STR2
4982 "Solo peer - part of its own update group\n")
4983 {
4984 int idx_peer = 2;
4985 struct peer *peer;
4986 int ret;
4987
4988 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4989 if (!peer)
4990 return CMD_WARNING_CONFIG_FAILED;
4991
4992 ret = update_group_adjust_soloness(peer, 0);
4993 return bgp_vty_return(vty, ret);
4994 }
4995
4996 DEFUN_YANG(neighbor_password,
4997 neighbor_password_cmd,
4998 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
4999 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5000 "Set a password\n"
5001 "The password\n")
5002 {
5003 int idx_peer = 1;
5004 int idx_line = 3;
5005 char base_xpath[XPATH_MAXLEN];
5006
5007 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5008 sizeof(base_xpath), NULL)
5009 < 0)
5010 return CMD_WARNING_CONFIG_FAILED;
5011
5012 nb_cli_enqueue_change(vty, "./password", NB_OP_MODIFY,
5013 argv[idx_line]->arg);
5014
5015 return nb_cli_apply_changes(vty, base_xpath);
5016 }
5017
5018 DEFUN_YANG(no_neighbor_password,
5019 no_neighbor_password_cmd,
5020 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
5021 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5022 "Set a password\n"
5023 "The password\n")
5024 {
5025 int idx_peer = 2;
5026 char base_xpath[XPATH_MAXLEN];
5027
5028 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5029 sizeof(base_xpath), NULL)
5030 < 0)
5031 return CMD_WARNING_CONFIG_FAILED;
5032
5033 nb_cli_enqueue_change(vty, "./password", NB_OP_DESTROY, NULL);
5034
5035 return nb_cli_apply_changes(vty, base_xpath);
5036 }
5037
5038 DEFUN_YANG(neighbor_activate,
5039 neighbor_activate_cmd,
5040 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5041 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5042 "Enable the Address Family for this Neighbor\n")
5043 {
5044 int idx_peer = 1;
5045 char base_xpath[XPATH_MAXLEN];
5046 char af_xpath[XPATH_MAXLEN];
5047 afi_t afi = bgp_node_afi(vty);
5048 safi_t safi = bgp_node_safi(vty);
5049
5050 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5051 yang_afi_safi_value2identity(afi, safi));
5052 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5053 sizeof(base_xpath), af_xpath)
5054 < 0)
5055 return CMD_WARNING_CONFIG_FAILED;
5056
5057 nb_cli_enqueue_change(vty, "./enabled", NB_OP_MODIFY, "true");
5058
5059 return nb_cli_apply_changes(vty, base_xpath);
5060 }
5061
5062 ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
5063 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5064 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5065 "Enable the Address Family for this Neighbor\n")
5066
5067 DEFUN_YANG(no_neighbor_activate,
5068 no_neighbor_activate_cmd,
5069 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5070 NO_STR NEIGHBOR_STR
5071 NEIGHBOR_ADDR_STR2
5072 "Enable the Address Family for this Neighbor\n")
5073 {
5074 int idx_peer = 2;
5075 char base_xpath[XPATH_MAXLEN];
5076 char af_xpath[XPATH_MAXLEN];
5077 afi_t afi = bgp_node_afi(vty);
5078 safi_t safi = bgp_node_safi(vty);
5079
5080 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5081 yang_afi_safi_value2identity(afi, safi));
5082
5083 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5084 sizeof(base_xpath), af_xpath)
5085 < 0)
5086 return CMD_WARNING_CONFIG_FAILED;
5087
5088 nb_cli_enqueue_change(vty, "./enabled", NB_OP_MODIFY, "false");
5089
5090 return nb_cli_apply_changes(vty, base_xpath);
5091 }
5092
5093 ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
5094 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5095 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5096 "Enable the Address Family for this Neighbor\n")
5097
5098 DEFUN (neighbor_set_peer_group,
5099 neighbor_set_peer_group_cmd,
5100 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5101 NEIGHBOR_STR
5102 NEIGHBOR_ADDR_STR2
5103 "Member of the peer-group\n"
5104 "Peer-group name\n")
5105 {
5106 VTY_DECLVAR_CONTEXT(bgp, bgp);
5107 int idx_peer = 1;
5108 int idx_word = 3;
5109 int ret;
5110 as_t as;
5111 union sockunion su;
5112 struct peer *peer;
5113 struct peer_group *group;
5114
5115 ret = str2sockunion(argv[idx_peer]->arg, &su);
5116 if (ret < 0) {
5117 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
5118 if (!peer) {
5119 vty_out(vty, "%% Malformed address or name: %s\n",
5120 argv[idx_peer]->arg);
5121 return CMD_WARNING_CONFIG_FAILED;
5122 }
5123 } else {
5124 if (peer_address_self_check(bgp, &su)) {
5125 vty_out(vty,
5126 "%% Can not configure the local system as neighbor\n");
5127 return CMD_WARNING_CONFIG_FAILED;
5128 }
5129
5130 /* Disallow for dynamic neighbor. */
5131 peer = peer_lookup(bgp, &su);
5132 if (peer && peer_dynamic_neighbor(peer)) {
5133 vty_out(vty,
5134 "%% Operation not allowed on a dynamic neighbor\n");
5135 return CMD_WARNING_CONFIG_FAILED;
5136 }
5137 }
5138
5139 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5140 if (!group) {
5141 vty_out(vty, "%% Configure the peer-group first\n");
5142 return CMD_WARNING_CONFIG_FAILED;
5143 }
5144
5145 ret = peer_group_bind(bgp, &su, peer, group, &as);
5146
5147 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
5148 vty_out(vty,
5149 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
5150 as);
5151 return CMD_WARNING_CONFIG_FAILED;
5152 }
5153
5154 return bgp_vty_return(vty, ret);
5155 }
5156
5157 ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
5158 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5159 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5160 "Member of the peer-group\n"
5161 "Peer-group name\n")
5162
5163 DEFUN_YANG (no_neighbor_set_peer_group,
5164 no_neighbor_set_peer_group_cmd,
5165 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5166 NO_STR
5167 NEIGHBOR_STR
5168 NEIGHBOR_ADDR_STR2
5169 "Member of the peer-group\n"
5170 "Peer-group name\n")
5171 {
5172 int idx_peer = 2;
5173 char base_xpath[XPATH_MAXLEN];
5174
5175 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5176 sizeof(base_xpath), NULL)
5177 < 0)
5178 return CMD_WARNING_CONFIG_FAILED;
5179
5180 nb_cli_enqueue_change(vty, "./peer-group", NB_OP_DESTROY, NULL);
5181
5182 /*
5183 * Need to commit any pending so this command doesn't merge with a
5184 * create into a modify, which BGP can't handle
5185 */
5186 return nb_cli_apply_changes_clear_pending(vty, base_xpath);
5187 }
5188
5189 ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
5190 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5191 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5192 "Member of the peer-group\n"
5193 "Peer-group name\n")
5194
5195 static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
5196 uint32_t flag, int set)
5197 {
5198 int ret;
5199 struct peer *peer;
5200
5201 peer = peer_and_group_lookup_vty(vty, ip_str);
5202 if (!peer)
5203 return CMD_WARNING_CONFIG_FAILED;
5204
5205 /*
5206 * If 'neighbor <interface>', then this is for directly connected peers,
5207 * we should not accept disable-connected-check.
5208 */
5209 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
5210 vty_out(vty,
5211 "%s is directly connected peer, cannot accept disable-connected-check\n",
5212 ip_str);
5213 return CMD_WARNING_CONFIG_FAILED;
5214 }
5215
5216 if (!set && flag == PEER_FLAG_SHUTDOWN)
5217 peer_tx_shutdown_message_unset(peer);
5218
5219 if (set)
5220 ret = peer_flag_set(peer, flag);
5221 else
5222 ret = peer_flag_unset(peer, flag);
5223
5224 return bgp_vty_return(vty, ret);
5225 }
5226
5227 static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
5228 {
5229 return peer_flag_modify_vty(vty, ip_str, flag, 1);
5230 }
5231
5232 static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
5233 uint32_t flag)
5234 {
5235 return peer_flag_modify_vty(vty, ip_str, flag, 0);
5236 }
5237
5238 int peer_flag_modify_nb(struct bgp *bgp, const char *ip_str, struct peer *peer,
5239 uint32_t flag, bool set, char *errmsg,
5240 size_t errmsg_len)
5241 {
5242 int ret;
5243
5244 /*
5245 * If 'neighbor <interface>', then this is for directly connected peers,
5246 * we should not accept disable-connected-check.
5247 */
5248 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
5249 snprintf(
5250 errmsg, errmsg_len,
5251 "%s is directly connected peer, cannot accept disable-connected-check\n",
5252 ip_str);
5253 return -1;
5254 }
5255
5256 if (!set && flag == PEER_FLAG_SHUTDOWN)
5257 peer_tx_shutdown_message_unset(peer);
5258
5259 if (set)
5260 ret = peer_flag_set(peer, flag);
5261 else
5262 ret = peer_flag_unset(peer, flag);
5263
5264 return bgp_nb_errmsg_return(errmsg, errmsg_len, ret);
5265 }
5266
5267 /* neighbor passive. */
5268 DEFUN_YANG(neighbor_passive,
5269 neighbor_passive_cmd,
5270 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5271 NEIGHBOR_STR
5272 NEIGHBOR_ADDR_STR2
5273 "Don't send open messages to this neighbor\n")
5274 {
5275 int idx_peer = 1;
5276 char base_xpath[XPATH_MAXLEN];
5277
5278 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5279 sizeof(base_xpath), NULL)
5280 < 0)
5281 return CMD_WARNING_CONFIG_FAILED;
5282
5283 nb_cli_enqueue_change(vty, "./passive-mode", NB_OP_MODIFY, "true");
5284
5285 return nb_cli_apply_changes(vty, base_xpath);
5286 }
5287
5288 DEFUN_YANG(no_neighbor_passive,
5289 no_neighbor_passive_cmd,
5290 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5291 NO_STR NEIGHBOR_STR
5292 NEIGHBOR_ADDR_STR2
5293 "Don't send open messages to this neighbor\n")
5294 {
5295 int idx_peer = 2;
5296 char base_xpath[XPATH_MAXLEN];
5297
5298 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5299 sizeof(base_xpath), NULL)
5300 < 0)
5301 return CMD_WARNING_CONFIG_FAILED;
5302
5303 nb_cli_enqueue_change(vty, "./passive-mode", NB_OP_MODIFY, "false");
5304
5305 return nb_cli_apply_changes(vty, base_xpath);
5306 }
5307
5308 /* neighbor shutdown. */
5309 DEFUN_YANG(neighbor_shutdown_msg,
5310 neighbor_shutdown_msg_cmd,
5311 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5312 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5313 "Administratively shut down this neighbor\n"
5314 "Add a shutdown message (RFC 8203)\n"
5315 "Shutdown message\n")
5316 {
5317 int idx_peer = 1;
5318 char base_xpath[XPATH_MAXLEN];
5319
5320 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5321 sizeof(base_xpath), NULL)
5322 < 0)
5323 return CMD_WARNING_CONFIG_FAILED;
5324
5325 if (argc >= 5) {
5326 char *message;
5327
5328 message = argv_concat(argv, argc, 4);
5329 nb_cli_enqueue_change(vty, "./admin-shutdown/message",
5330 NB_OP_MODIFY, message);
5331 }
5332
5333 nb_cli_enqueue_change(vty, "./admin-shutdown/enable", NB_OP_MODIFY,
5334 "true");
5335
5336 return nb_cli_apply_changes(vty, base_xpath);
5337 }
5338
5339 ALIAS_YANG(neighbor_shutdown_msg, neighbor_shutdown_cmd,
5340 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5341 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5342 "Administratively shut down this neighbor\n")
5343
5344 DEFUN_YANG(no_neighbor_shutdown_msg,
5345 no_neighbor_shutdown_msg_cmd,
5346 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5347 NO_STR NEIGHBOR_STR
5348 NEIGHBOR_ADDR_STR2
5349 "Administratively shut down this neighbor\n"
5350 "Remove a shutdown message (RFC 8203)\n"
5351 "Shutdown message\n")
5352 {
5353 int idx_peer = 2;
5354 char base_xpath[XPATH_MAXLEN];
5355
5356 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5357 sizeof(base_xpath), NULL)
5358 < 0)
5359 return CMD_WARNING_CONFIG_FAILED;
5360
5361 nb_cli_enqueue_change(vty, "./admin-shutdown/enable", NB_OP_MODIFY,
5362 "false");
5363
5364 return nb_cli_apply_changes(vty, base_xpath);
5365 }
5366
5367 ALIAS_YANG(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
5368 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5369 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5370 "Administratively shut down this neighbor\n")
5371
5372 DEFUN(neighbor_shutdown_rtt,
5373 neighbor_shutdown_rtt_cmd,
5374 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt (1-65535) [count (1-255)]",
5375 NEIGHBOR_STR
5376 NEIGHBOR_ADDR_STR2
5377 "Administratively shut down this neighbor\n"
5378 "Shutdown if round-trip-time is higher than expected\n"
5379 "Round-trip-time in milliseconds\n"
5380 "Specify the number of keepalives before shutdown\n"
5381 "The number of keepalives with higher RTT to shutdown\n")
5382 {
5383 int idx_peer = 1;
5384 int idx_rtt = 4;
5385 int idx_count = 0;
5386 struct peer *peer;
5387
5388 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5389
5390 if (!peer)
5391 return CMD_WARNING_CONFIG_FAILED;
5392
5393 peer->rtt_expected = strtol(argv[idx_rtt]->arg, NULL, 10);
5394
5395 if (argv_find(argv, argc, "count", &idx_count))
5396 peer->rtt_keepalive_conf =
5397 strtol(argv[idx_count + 1]->arg, NULL, 10);
5398
5399 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5400 PEER_FLAG_RTT_SHUTDOWN);
5401 }
5402
5403 DEFUN(no_neighbor_shutdown_rtt,
5404 no_neighbor_shutdown_rtt_cmd,
5405 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt [(1-65535) [count (1-255)]]",
5406 NO_STR
5407 NEIGHBOR_STR
5408 NEIGHBOR_ADDR_STR2
5409 "Administratively shut down this neighbor\n"
5410 "Shutdown if round-trip-time is higher than expected\n"
5411 "Round-trip-time in milliseconds\n"
5412 "Specify the number of keepalives before shutdown\n"
5413 "The number of keepalives with higher RTT to shutdown\n")
5414 {
5415 int idx_peer = 2;
5416 struct peer *peer;
5417
5418 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5419
5420 if (!peer)
5421 return CMD_WARNING_CONFIG_FAILED;
5422
5423 peer->rtt_expected = 0;
5424 peer->rtt_keepalive_conf = 1;
5425
5426 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5427 PEER_FLAG_RTT_SHUTDOWN);
5428 }
5429
5430 /* neighbor capability dynamic. */
5431 DEFUN_YANG (neighbor_capability_dynamic,
5432 neighbor_capability_dynamic_cmd,
5433 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5434 NEIGHBOR_STR
5435 NEIGHBOR_ADDR_STR2
5436 "Advertise capability to the peer\n"
5437 "Advertise dynamic capability to this neighbor\n")
5438 {
5439 int idx_peer = 1;
5440 char base_xpath[XPATH_MAXLEN];
5441
5442 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5443 sizeof(base_xpath), NULL)
5444 < 0)
5445 return CMD_WARNING_CONFIG_FAILED;
5446
5447 nb_cli_enqueue_change(vty, "./capability-options/dynamic-capability",
5448 NB_OP_MODIFY, "true");
5449
5450 return nb_cli_apply_changes(vty, base_xpath);
5451 }
5452
5453 DEFUN_YANG (no_neighbor_capability_dynamic,
5454 no_neighbor_capability_dynamic_cmd,
5455 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5456 NO_STR
5457 NEIGHBOR_STR
5458 NEIGHBOR_ADDR_STR2
5459 "Advertise capability to the peer\n"
5460 "Advertise dynamic capability to this neighbor\n")
5461 {
5462 int idx_peer = 2;
5463 char base_xpath[XPATH_MAXLEN];
5464
5465 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5466 sizeof(base_xpath), NULL)
5467 < 0)
5468 return CMD_WARNING_CONFIG_FAILED;
5469
5470 nb_cli_enqueue_change(vty, "./capability-options/dynamic-capability",
5471 NB_OP_MODIFY, "false");
5472
5473 return nb_cli_apply_changes(vty, base_xpath);
5474 }
5475
5476 /* neighbor dont-capability-negotiate */
5477 DEFUN (neighbor_dont_capability_negotiate,
5478 neighbor_dont_capability_negotiate_cmd,
5479 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
5480 NEIGHBOR_STR
5481 NEIGHBOR_ADDR_STR2
5482 "Do not perform capability negotiation\n")
5483 {
5484 int idx_peer = 1;
5485 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5486 PEER_FLAG_DONT_CAPABILITY);
5487 }
5488
5489 DEFUN (no_neighbor_dont_capability_negotiate,
5490 no_neighbor_dont_capability_negotiate_cmd,
5491 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
5492 NO_STR
5493 NEIGHBOR_STR
5494 NEIGHBOR_ADDR_STR2
5495 "Do not perform capability negotiation\n")
5496 {
5497 int idx_peer = 2;
5498 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5499 PEER_FLAG_DONT_CAPABILITY);
5500 }
5501
5502 /* neighbor capability extended next hop encoding */
5503 DEFUN_YANG (neighbor_capability_enhe,
5504 neighbor_capability_enhe_cmd,
5505 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5506 NEIGHBOR_STR
5507 NEIGHBOR_ADDR_STR2
5508 "Advertise capability to the peer\n"
5509 "Advertise extended next-hop capability to the peer\n")
5510 {
5511 int idx_peer = 1;
5512 char base_xpath[XPATH_MAXLEN];
5513
5514 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5515 sizeof(base_xpath), NULL)
5516 < 0)
5517 return CMD_WARNING_CONFIG_FAILED;
5518
5519 nb_cli_enqueue_change(
5520 vty, "./capability-options/extended-nexthop-capability",
5521 NB_OP_MODIFY, "true");
5522
5523 return nb_cli_apply_changes(vty, base_xpath);
5524 }
5525
5526 DEFUN_YANG (no_neighbor_capability_enhe,
5527 no_neighbor_capability_enhe_cmd,
5528 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5529 NO_STR
5530 NEIGHBOR_STR
5531 NEIGHBOR_ADDR_STR2
5532 "Advertise capability to the peer\n"
5533 "Advertise extended next-hop capability to the peer\n")
5534 {
5535 int idx_peer = 2;
5536 char base_xpath[XPATH_MAXLEN];
5537
5538 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5539 sizeof(base_xpath), NULL)
5540 < 0)
5541 return CMD_WARNING_CONFIG_FAILED;
5542
5543 nb_cli_enqueue_change(
5544 vty, "./capability-options/extended-nexthop-capability",
5545 NB_OP_MODIFY, "false");
5546
5547 return nb_cli_apply_changes(vty, base_xpath);
5548 }
5549
5550 int peer_af_flag_modify_nb(struct peer *peer, afi_t afi, safi_t safi,
5551 uint32_t flag, int set, char *errmsg,
5552 size_t errmsg_len)
5553 {
5554 int ret;
5555
5556 if (set)
5557 ret = peer_af_flag_set(peer, afi, safi, flag);
5558 else
5559 ret = peer_af_flag_unset(peer, afi, safi, flag);
5560
5561 return bgp_nb_errmsg_return(errmsg, errmsg_len, ret);
5562 }
5563
5564 static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
5565 afi_t afi, safi_t safi, uint32_t flag,
5566 int set)
5567 {
5568 int ret;
5569 struct peer *peer;
5570
5571 peer = peer_and_group_lookup_vty(vty, peer_str);
5572 if (!peer)
5573 return CMD_WARNING_CONFIG_FAILED;
5574
5575 if (set)
5576 ret = peer_af_flag_set(peer, afi, safi, flag);
5577 else
5578 ret = peer_af_flag_unset(peer, afi, safi, flag);
5579
5580 return bgp_vty_return(vty, ret);
5581 }
5582
5583 static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
5584 afi_t afi, safi_t safi, uint32_t flag)
5585 {
5586 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
5587 }
5588
5589 static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
5590 afi_t afi, safi_t safi, uint32_t flag)
5591 {
5592 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
5593 }
5594
5595 /* neighbor capability orf prefix-list. */
5596 DEFUN (neighbor_capability_orf_prefix,
5597 neighbor_capability_orf_prefix_cmd,
5598 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5599 NEIGHBOR_STR
5600 NEIGHBOR_ADDR_STR2
5601 "Advertise capability to the peer\n"
5602 "Advertise ORF capability to the peer\n"
5603 "Advertise prefixlist ORF capability to this neighbor\n"
5604 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5605 "Capability to RECEIVE the ORF from this neighbor\n"
5606 "Capability to SEND the ORF to this neighbor\n")
5607 {
5608 int idx_send_recv = 5;
5609 char *peer_str = argv[1]->arg;
5610 struct peer *peer;
5611 afi_t afi = bgp_node_afi(vty);
5612 safi_t safi = bgp_node_safi(vty);
5613
5614 peer = peer_and_group_lookup_vty(vty, peer_str);
5615 if (!peer)
5616 return CMD_WARNING_CONFIG_FAILED;
5617
5618 if (strmatch(argv[idx_send_recv]->text, "send"))
5619 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5620 PEER_FLAG_ORF_PREFIX_SM);
5621
5622 if (strmatch(argv[idx_send_recv]->text, "receive"))
5623 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5624 PEER_FLAG_ORF_PREFIX_RM);
5625
5626 if (strmatch(argv[idx_send_recv]->text, "both"))
5627 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5628 PEER_FLAG_ORF_PREFIX_SM)
5629 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5630 PEER_FLAG_ORF_PREFIX_RM);
5631
5632 return CMD_WARNING_CONFIG_FAILED;
5633 }
5634
5635 ALIAS_HIDDEN(
5636 neighbor_capability_orf_prefix,
5637 neighbor_capability_orf_prefix_hidden_cmd,
5638 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5639 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5640 "Advertise capability to the peer\n"
5641 "Advertise ORF capability to the peer\n"
5642 "Advertise prefixlist ORF capability to this neighbor\n"
5643 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5644 "Capability to RECEIVE the ORF from this neighbor\n"
5645 "Capability to SEND the ORF to this neighbor\n")
5646
5647 DEFUN (no_neighbor_capability_orf_prefix,
5648 no_neighbor_capability_orf_prefix_cmd,
5649 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5650 NO_STR
5651 NEIGHBOR_STR
5652 NEIGHBOR_ADDR_STR2
5653 "Advertise capability to the peer\n"
5654 "Advertise ORF capability to the peer\n"
5655 "Advertise prefixlist ORF capability to this neighbor\n"
5656 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5657 "Capability to RECEIVE the ORF from this neighbor\n"
5658 "Capability to SEND the ORF to this neighbor\n")
5659 {
5660 int idx_send_recv = 6;
5661 char *peer_str = argv[2]->arg;
5662 struct peer *peer;
5663 afi_t afi = bgp_node_afi(vty);
5664 safi_t safi = bgp_node_safi(vty);
5665
5666 peer = peer_and_group_lookup_vty(vty, peer_str);
5667 if (!peer)
5668 return CMD_WARNING_CONFIG_FAILED;
5669
5670 if (strmatch(argv[idx_send_recv]->text, "send"))
5671 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5672 PEER_FLAG_ORF_PREFIX_SM);
5673
5674 if (strmatch(argv[idx_send_recv]->text, "receive"))
5675 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5676 PEER_FLAG_ORF_PREFIX_RM);
5677
5678 if (strmatch(argv[idx_send_recv]->text, "both"))
5679 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5680 PEER_FLAG_ORF_PREFIX_SM)
5681 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5682 PEER_FLAG_ORF_PREFIX_RM);
5683
5684 return CMD_WARNING_CONFIG_FAILED;
5685 }
5686
5687 ALIAS_HIDDEN(
5688 no_neighbor_capability_orf_prefix,
5689 no_neighbor_capability_orf_prefix_hidden_cmd,
5690 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5691 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5692 "Advertise capability to the peer\n"
5693 "Advertise ORF capability to the peer\n"
5694 "Advertise prefixlist ORF capability to this neighbor\n"
5695 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5696 "Capability to RECEIVE the ORF from this neighbor\n"
5697 "Capability to SEND the ORF to this neighbor\n")
5698
5699 /* neighbor next-hop-self. */
5700 DEFUN_YANG (neighbor_nexthop_self,
5701 neighbor_nexthop_self_cmd,
5702 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5703 NEIGHBOR_STR
5704 NEIGHBOR_ADDR_STR2
5705 "Disable the next hop calculation for this neighbor\n")
5706 {
5707 int idx_peer = 1;
5708 char base_xpath[XPATH_MAXLEN];
5709 char af_xpath[XPATH_MAXLEN];
5710 char attr_xpath[XPATH_MAXLEN];
5711 afi_t afi = bgp_node_afi(vty);
5712 safi_t safi = bgp_node_safi(vty);
5713
5714 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5715 yang_afi_safi_value2identity(afi, safi));
5716
5717 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5718 sizeof(base_xpath), af_xpath)
5719 < 0)
5720 return CMD_WARNING_CONFIG_FAILED;
5721
5722 snprintf(attr_xpath, sizeof(attr_xpath),
5723 "./%s/nexthop-self/next-hop-self",
5724 bgp_afi_safi_get_container_str(afi, safi));
5725
5726 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5727
5728 return nb_cli_apply_changes(vty, base_xpath);
5729 }
5730
5731 ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
5732 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5733 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5734 "Disable the next hop calculation for this neighbor\n")
5735
5736 /* neighbor next-hop-self. */
5737 DEFUN_YANG(neighbor_nexthop_self_force,
5738 neighbor_nexthop_self_force_cmd,
5739 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5740 NEIGHBOR_STR
5741 NEIGHBOR_ADDR_STR2
5742 "Disable the next hop calculation for this neighbor\n"
5743 "Set the next hop to self for reflected routes\n")
5744 {
5745 int idx_peer = 1;
5746 char base_xpath[XPATH_MAXLEN];
5747 char af_xpath[XPATH_MAXLEN];
5748 char attr_xpath[XPATH_MAXLEN];
5749 afi_t afi = bgp_node_afi(vty);
5750 safi_t safi = bgp_node_safi(vty);
5751
5752 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5753 yang_afi_safi_value2identity(afi, safi));
5754
5755 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5756 sizeof(base_xpath), af_xpath)
5757 < 0)
5758 return CMD_WARNING_CONFIG_FAILED;
5759
5760 snprintf(attr_xpath, sizeof(attr_xpath),
5761 "./%s/nexthop-self/next-hop-self-force",
5762 bgp_afi_safi_get_container_str(afi, safi));
5763
5764 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5765
5766 return nb_cli_apply_changes(vty, base_xpath);
5767 }
5768
5769 ALIAS_HIDDEN(neighbor_nexthop_self_force,
5770 neighbor_nexthop_self_force_hidden_cmd,
5771 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5772 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5773 "Disable the next hop calculation for this neighbor\n"
5774 "Set the next hop to self for reflected routes\n")
5775
5776 ALIAS_HIDDEN(neighbor_nexthop_self_force,
5777 neighbor_nexthop_self_all_hidden_cmd,
5778 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5779 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5780 "Disable the next hop calculation for this neighbor\n"
5781 "Set the next hop to self for reflected routes\n")
5782
5783 DEFUN_YANG (no_neighbor_nexthop_self,
5784 no_neighbor_nexthop_self_cmd,
5785 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5786 NO_STR
5787 NEIGHBOR_STR
5788 NEIGHBOR_ADDR_STR2
5789 "Disable the next hop calculation for this neighbor\n")
5790 {
5791 int idx_peer = 2;
5792 char base_xpath[XPATH_MAXLEN];
5793 char af_xpath[XPATH_MAXLEN];
5794 char attr_xpath[XPATH_MAXLEN];
5795 afi_t afi = bgp_node_afi(vty);
5796 safi_t safi = bgp_node_safi(vty);
5797
5798 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5799 yang_afi_safi_value2identity(afi, safi));
5800
5801 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5802 sizeof(base_xpath), af_xpath)
5803 < 0)
5804 return CMD_WARNING_CONFIG_FAILED;
5805
5806 snprintf(attr_xpath, sizeof(attr_xpath),
5807 "./%s/nexthop-self/next-hop-self",
5808 bgp_afi_safi_get_container_str(afi, safi));
5809
5810 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5811
5812 return nb_cli_apply_changes(vty, base_xpath);
5813 }
5814
5815 ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
5816 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5817 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5818 "Disable the next hop calculation for this neighbor\n")
5819
5820 DEFUN_YANG (no_neighbor_nexthop_self_force,
5821 no_neighbor_nexthop_self_force_cmd,
5822 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5823 NO_STR
5824 NEIGHBOR_STR
5825 NEIGHBOR_ADDR_STR2
5826 "Disable the next hop calculation for this neighbor\n"
5827 "Set the next hop to self for reflected routes\n")
5828 {
5829 int idx_peer = 2;
5830 char base_xpath[XPATH_MAXLEN];
5831 char af_xpath[XPATH_MAXLEN];
5832 char attr_xpath[XPATH_MAXLEN];
5833 afi_t afi = bgp_node_afi(vty);
5834 safi_t safi = bgp_node_safi(vty);
5835
5836 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5837 yang_afi_safi_value2identity(afi, safi));
5838
5839 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5840 sizeof(base_xpath), af_xpath)
5841 < 0)
5842 return CMD_WARNING_CONFIG_FAILED;
5843
5844 snprintf(attr_xpath, sizeof(attr_xpath),
5845 "./%s/nexthop-self/next-hop-self-force",
5846 bgp_afi_safi_get_container_str(afi, safi));
5847
5848 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5849
5850 return nb_cli_apply_changes(vty, base_xpath);
5851 }
5852
5853 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5854 no_neighbor_nexthop_self_force_hidden_cmd,
5855 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5856 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5857 "Disable the next hop calculation for this neighbor\n"
5858 "Set the next hop to self for reflected routes\n")
5859
5860 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5861 no_neighbor_nexthop_self_all_hidden_cmd,
5862 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5863 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5864 "Disable the next hop calculation for this neighbor\n"
5865 "Set the next hop to self for reflected routes\n")
5866
5867 /* neighbor as-override */
5868 DEFUN_YANG (neighbor_as_override,
5869 neighbor_as_override_cmd,
5870 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5871 NEIGHBOR_STR
5872 NEIGHBOR_ADDR_STR2
5873 "Override ASNs in outbound updates if aspath equals remote-as\n")
5874 {
5875 int idx_peer = 1;
5876 char base_xpath[XPATH_MAXLEN];
5877 char af_xpath[XPATH_MAXLEN];
5878 char attr_xpath[XPATH_MAXLEN];
5879 afi_t afi = bgp_node_afi(vty);
5880 safi_t safi = bgp_node_safi(vty);
5881
5882 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5883 yang_afi_safi_value2identity(afi, safi));
5884
5885 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5886 sizeof(base_xpath), af_xpath)
5887 < 0)
5888 return CMD_WARNING_CONFIG_FAILED;
5889
5890 snprintf(attr_xpath, sizeof(attr_xpath),
5891 "./%s/as-path-options/replace-peer-as",
5892 bgp_afi_safi_get_container_str(afi, safi));
5893
5894 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5895
5896 return nb_cli_apply_changes(vty, base_xpath);
5897 }
5898
5899 ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
5900 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5901 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5902 "Override ASNs in outbound updates if aspath equals remote-as\n")
5903
5904 DEFUN_YANG (no_neighbor_as_override,
5905 no_neighbor_as_override_cmd,
5906 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5907 NO_STR
5908 NEIGHBOR_STR
5909 NEIGHBOR_ADDR_STR2
5910 "Override ASNs in outbound updates if aspath equals remote-as\n")
5911 {
5912 int idx_peer = 2;
5913 char base_xpath[XPATH_MAXLEN];
5914 char af_xpath[XPATH_MAXLEN];
5915 char attr_xpath[XPATH_MAXLEN];
5916 afi_t afi = bgp_node_afi(vty);
5917 safi_t safi = bgp_node_safi(vty);
5918
5919 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5920 yang_afi_safi_value2identity(afi, safi));
5921
5922 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5923 sizeof(base_xpath), af_xpath)
5924 < 0)
5925 return CMD_WARNING_CONFIG_FAILED;
5926
5927 snprintf(attr_xpath, sizeof(attr_xpath),
5928 "./%s/as-path-options/replace-peer-as",
5929 bgp_afi_safi_get_container_str(afi, safi));
5930
5931 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5932
5933 return nb_cli_apply_changes(vty, base_xpath);
5934 }
5935
5936 ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
5937 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5938 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5939 "Override ASNs in outbound updates if aspath equals remote-as\n")
5940
5941 /* neighbor remove-private-AS. */
5942 DEFUN_YANG (neighbor_remove_private_as,
5943 neighbor_remove_private_as_cmd,
5944 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5945 NEIGHBOR_STR
5946 NEIGHBOR_ADDR_STR2
5947 "Remove private ASNs in outbound updates\n")
5948 {
5949 int idx_peer = 1;
5950 char base_xpath[XPATH_MAXLEN];
5951 char af_xpath[XPATH_MAXLEN];
5952 char attr_xpath[XPATH_MAXLEN];
5953 afi_t afi = bgp_node_afi(vty);
5954 safi_t safi = bgp_node_safi(vty);
5955
5956 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5957 yang_afi_safi_value2identity(afi, safi));
5958
5959 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5960 sizeof(base_xpath), af_xpath)
5961 < 0)
5962 return CMD_WARNING_CONFIG_FAILED;
5963
5964 snprintf(attr_xpath, sizeof(attr_xpath),
5965 "./%s/private-as/remove-private-as",
5966 bgp_afi_safi_get_container_str(afi, safi));
5967
5968 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5969
5970 return nb_cli_apply_changes(vty, base_xpath);
5971 }
5972
5973 ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
5974 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5975 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5976 "Remove private ASNs in outbound updates\n")
5977
5978 DEFUN_YANG (neighbor_remove_private_as_all,
5979 neighbor_remove_private_as_all_cmd,
5980 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5981 NEIGHBOR_STR
5982 NEIGHBOR_ADDR_STR2
5983 "Remove private ASNs in outbound updates\n"
5984 "Apply to all AS numbers\n")
5985 {
5986 int idx_peer = 1;
5987 char base_xpath[XPATH_MAXLEN];
5988 char af_xpath[XPATH_MAXLEN];
5989 char attr_xpath[XPATH_MAXLEN];
5990 afi_t afi = bgp_node_afi(vty);
5991 safi_t safi = bgp_node_safi(vty);
5992
5993 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5994 yang_afi_safi_value2identity(afi, safi));
5995
5996 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5997 sizeof(base_xpath), af_xpath)
5998 < 0)
5999 return CMD_WARNING_CONFIG_FAILED;
6000
6001 snprintf(attr_xpath, sizeof(attr_xpath),
6002 "./%s/private-as/remove-private-as-all",
6003 bgp_afi_safi_get_container_str(afi, safi));
6004
6005 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
6006
6007 return nb_cli_apply_changes(vty, base_xpath);
6008 }
6009
6010 ALIAS_HIDDEN(neighbor_remove_private_as_all,
6011 neighbor_remove_private_as_all_hidden_cmd,
6012 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
6013 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6014 "Remove private ASNs in outbound updates\n"
6015 "Apply to all AS numbers")
6016
6017 DEFUN_YANG (neighbor_remove_private_as_replace_as,
6018 neighbor_remove_private_as_replace_as_cmd,
6019 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
6020 NEIGHBOR_STR
6021 NEIGHBOR_ADDR_STR2
6022 "Remove private ASNs in outbound updates\n"
6023 "Replace private ASNs with our ASN in outbound updates\n")
6024 {
6025 int idx_peer = 1;
6026 char base_xpath[XPATH_MAXLEN];
6027 char af_xpath[XPATH_MAXLEN];
6028 char attr_xpath[XPATH_MAXLEN];
6029 afi_t afi = bgp_node_afi(vty);
6030 safi_t safi = bgp_node_safi(vty);
6031
6032 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6033 yang_afi_safi_value2identity(afi, safi));
6034
6035 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6036 sizeof(base_xpath), af_xpath)
6037 < 0)
6038 return CMD_WARNING_CONFIG_FAILED;
6039
6040 snprintf(attr_xpath, sizeof(attr_xpath),
6041 "./%s/private-as/remove-private-as-replace",
6042 bgp_afi_safi_get_container_str(afi, safi));
6043
6044 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
6045
6046 return nb_cli_apply_changes(vty, base_xpath);
6047 }
6048
6049 ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
6050 neighbor_remove_private_as_replace_as_hidden_cmd,
6051 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
6052 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6053 "Remove private ASNs in outbound updates\n"
6054 "Replace private ASNs with our ASN in outbound updates\n")
6055
6056 DEFUN_YANG (neighbor_remove_private_as_all_replace_as,
6057 neighbor_remove_private_as_all_replace_as_cmd,
6058 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
6059 NEIGHBOR_STR
6060 NEIGHBOR_ADDR_STR2
6061 "Remove private ASNs in outbound updates\n"
6062 "Apply to all AS numbers\n"
6063 "Replace private ASNs with our ASN in outbound updates\n")
6064 {
6065 int idx_peer = 1;
6066 char base_xpath[XPATH_MAXLEN];
6067 char af_xpath[XPATH_MAXLEN];
6068 char attr_xpath[XPATH_MAXLEN];
6069 afi_t afi = bgp_node_afi(vty);
6070 safi_t safi = bgp_node_safi(vty);
6071
6072 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6073 yang_afi_safi_value2identity(afi, safi));
6074
6075 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6076 sizeof(base_xpath), af_xpath)
6077 < 0)
6078 return CMD_WARNING_CONFIG_FAILED;
6079
6080 snprintf(attr_xpath, sizeof(attr_xpath),
6081 "./%s/private-as/remove-private-as-all-replace",
6082 bgp_afi_safi_get_container_str(afi, safi));
6083
6084 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
6085
6086 return nb_cli_apply_changes(vty, base_xpath);
6087 }
6088
6089 ALIAS_HIDDEN(
6090 neighbor_remove_private_as_all_replace_as,
6091 neighbor_remove_private_as_all_replace_as_hidden_cmd,
6092 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
6093 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6094 "Remove private ASNs in outbound updates\n"
6095 "Apply to all AS numbers\n"
6096 "Replace private ASNs with our ASN in outbound updates\n")
6097
6098 DEFUN_YANG (no_neighbor_remove_private_as,
6099 no_neighbor_remove_private_as_cmd,
6100 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
6101 NO_STR
6102 NEIGHBOR_STR
6103 NEIGHBOR_ADDR_STR2
6104 "Remove private ASNs in outbound updates\n")
6105 {
6106 int idx_peer = 2;
6107 char base_xpath[XPATH_MAXLEN];
6108 char af_xpath[XPATH_MAXLEN];
6109 char attr_xpath[XPATH_MAXLEN];
6110 afi_t afi = bgp_node_afi(vty);
6111 safi_t safi = bgp_node_safi(vty);
6112
6113 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6114 yang_afi_safi_value2identity(afi, safi));
6115
6116 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6117 sizeof(base_xpath), af_xpath)
6118 < 0)
6119 return CMD_WARNING_CONFIG_FAILED;
6120
6121 snprintf(attr_xpath, sizeof(attr_xpath),
6122 "./%s/private-as/remove-private-as",
6123 bgp_afi_safi_get_container_str(afi, safi));
6124
6125 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6126
6127 return nb_cli_apply_changes(vty, base_xpath);
6128 }
6129
6130 ALIAS_HIDDEN(no_neighbor_remove_private_as,
6131 no_neighbor_remove_private_as_hidden_cmd,
6132 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
6133 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6134 "Remove private ASNs in outbound updates\n")
6135
6136 DEFUN_YANG (no_neighbor_remove_private_as_all,
6137 no_neighbor_remove_private_as_all_cmd,
6138 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
6139 NO_STR
6140 NEIGHBOR_STR
6141 NEIGHBOR_ADDR_STR2
6142 "Remove private ASNs in outbound updates\n"
6143 "Apply to all AS numbers\n")
6144 {
6145 int idx_peer = 2;
6146 char base_xpath[XPATH_MAXLEN];
6147 char af_xpath[XPATH_MAXLEN];
6148 char attr_xpath[XPATH_MAXLEN];
6149 afi_t afi = bgp_node_afi(vty);
6150 safi_t safi = bgp_node_safi(vty);
6151
6152 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6153 yang_afi_safi_value2identity(afi, safi));
6154
6155 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6156 sizeof(base_xpath), af_xpath)
6157 < 0)
6158 return CMD_WARNING_CONFIG_FAILED;
6159
6160 snprintf(attr_xpath, sizeof(attr_xpath),
6161 "./%s/private-as/remove-private-as-all",
6162 bgp_afi_safi_get_container_str(afi, safi));
6163
6164 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6165
6166 return nb_cli_apply_changes(vty, base_xpath);
6167 }
6168
6169 ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
6170 no_neighbor_remove_private_as_all_hidden_cmd,
6171 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
6172 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6173 "Remove private ASNs in outbound updates\n"
6174 "Apply to all AS numbers\n")
6175
6176 DEFUN_YANG (no_neighbor_remove_private_as_replace_as,
6177 no_neighbor_remove_private_as_replace_as_cmd,
6178 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
6179 NO_STR
6180 NEIGHBOR_STR
6181 NEIGHBOR_ADDR_STR2
6182 "Remove private ASNs in outbound updates\n"
6183 "Replace private ASNs with our ASN in outbound updates\n")
6184 {
6185 int idx_peer = 2;
6186 char base_xpath[XPATH_MAXLEN];
6187 char af_xpath[XPATH_MAXLEN];
6188 char attr_xpath[XPATH_MAXLEN];
6189 afi_t afi = bgp_node_afi(vty);
6190 safi_t safi = bgp_node_safi(vty);
6191
6192 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6193 yang_afi_safi_value2identity(afi, safi));
6194
6195 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6196 sizeof(base_xpath), af_xpath)
6197 < 0)
6198 return CMD_WARNING_CONFIG_FAILED;
6199
6200 snprintf(attr_xpath, sizeof(attr_xpath),
6201 "./%s/private-as/remove-private-as-replace",
6202 bgp_afi_safi_get_container_str(afi, safi));
6203
6204 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6205
6206 return nb_cli_apply_changes(vty, base_xpath);
6207 }
6208
6209 ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
6210 no_neighbor_remove_private_as_replace_as_hidden_cmd,
6211 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
6212 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6213 "Remove private ASNs in outbound updates\n"
6214 "Replace private ASNs with our ASN in outbound updates\n")
6215
6216 DEFUN_YANG (no_neighbor_remove_private_as_all_replace_as,
6217 no_neighbor_remove_private_as_all_replace_as_cmd,
6218 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
6219 NO_STR
6220 NEIGHBOR_STR
6221 NEIGHBOR_ADDR_STR2
6222 "Remove private ASNs in outbound updates\n"
6223 "Apply to all AS numbers\n"
6224 "Replace private ASNs with our ASN in outbound updates\n")
6225 {
6226 int idx_peer = 2;
6227 char base_xpath[XPATH_MAXLEN];
6228 char af_xpath[XPATH_MAXLEN];
6229 char attr_xpath[XPATH_MAXLEN];
6230 afi_t afi = bgp_node_afi(vty);
6231 safi_t safi = bgp_node_safi(vty);
6232
6233 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6234 yang_afi_safi_value2identity(afi, safi));
6235
6236 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6237 sizeof(base_xpath), af_xpath)
6238 < 0)
6239 return CMD_WARNING_CONFIG_FAILED;
6240
6241 snprintf(attr_xpath, sizeof(attr_xpath),
6242 "./%s/private-as/remove-private-as-all-replace",
6243 bgp_afi_safi_get_container_str(afi, safi));
6244
6245 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6246
6247 return nb_cli_apply_changes(vty, base_xpath);
6248 }
6249
6250 ALIAS_HIDDEN(
6251 no_neighbor_remove_private_as_all_replace_as,
6252 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
6253 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
6254 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6255 "Remove private ASNs in outbound updates\n"
6256 "Apply to all AS numbers\n"
6257 "Replace private ASNs with our ASN in outbound updates\n")
6258
6259
6260 /* neighbor send-community. */
6261 DEFUN_YANG (neighbor_send_community,
6262 neighbor_send_community_cmd,
6263 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6264 NEIGHBOR_STR
6265 NEIGHBOR_ADDR_STR2
6266 "Send Community attribute to this neighbor\n")
6267 {
6268 int idx_peer = 1;
6269 char *peer_str = argv[idx_peer]->arg;
6270 char base_xpath[XPATH_MAXLEN];
6271 char af_xpath[XPATH_MAXLEN];
6272 char std_xpath[XPATH_MAXLEN];
6273 afi_t afi = bgp_node_afi(vty);
6274 safi_t safi = bgp_node_safi(vty);
6275
6276 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6277 yang_afi_safi_value2identity(afi, safi));
6278
6279 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6280 sizeof(base_xpath), af_xpath)
6281 < 0)
6282 return CMD_WARNING_CONFIG_FAILED;
6283
6284 snprintf(std_xpath, sizeof(std_xpath),
6285 "./%s/send-community/send-community",
6286 bgp_afi_safi_get_container_str(afi, safi));
6287
6288 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "true");
6289
6290 return nb_cli_apply_changes(vty, base_xpath);
6291 }
6292
6293 ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
6294 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6295 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6296 "Send Community attribute to this neighbor\n")
6297
6298 DEFUN_YANG (no_neighbor_send_community,
6299 no_neighbor_send_community_cmd,
6300 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6301 NO_STR
6302 NEIGHBOR_STR
6303 NEIGHBOR_ADDR_STR2
6304 "Send Community attribute to this neighbor\n")
6305 {
6306 int idx_peer = 2;
6307 char *peer_str = argv[idx_peer]->arg;
6308 char base_xpath[XPATH_MAXLEN];
6309 char af_xpath[XPATH_MAXLEN];
6310 char std_xpath[XPATH_MAXLEN];
6311 afi_t afi = bgp_node_afi(vty);
6312 safi_t safi = bgp_node_safi(vty);
6313
6314 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6315 yang_afi_safi_value2identity(afi, safi));
6316
6317 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6318 sizeof(base_xpath), af_xpath)
6319 < 0)
6320 return CMD_WARNING_CONFIG_FAILED;
6321
6322 snprintf(std_xpath, sizeof(std_xpath),
6323 "./%s/send-community/send-community",
6324 bgp_afi_safi_get_container_str(afi, safi));
6325
6326 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "false");
6327
6328 return nb_cli_apply_changes(vty, base_xpath);
6329 }
6330
6331 ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
6332 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6333 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6334 "Send Community attribute to this neighbor\n")
6335
6336 /* neighbor send-community extended. */
6337 DEFUN_YANG (neighbor_send_community_type,
6338 neighbor_send_community_type_cmd,
6339 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6340 NEIGHBOR_STR
6341 NEIGHBOR_ADDR_STR2
6342 "Send Community attribute to this neighbor\n"
6343 "Send Standard and Extended Community attributes\n"
6344 "Send Standard, Large and Extended Community attributes\n"
6345 "Send Extended Community attributes\n"
6346 "Send Standard Community attributes\n"
6347 "Send Large Community attributes\n")
6348 {
6349 const char *type = argv[argc - 1]->text;
6350 char *peer_str = argv[1]->arg;
6351 char base_xpath[XPATH_MAXLEN];
6352 char af_xpath[XPATH_MAXLEN];
6353 char std_xpath[XPATH_MAXLEN];
6354 char ext_xpath[XPATH_MAXLEN];
6355 char lrg_xpath[XPATH_MAXLEN];
6356 afi_t afi = bgp_node_afi(vty);
6357 safi_t safi = bgp_node_safi(vty);
6358
6359 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6360 yang_afi_safi_value2identity(afi, safi));
6361
6362 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6363 sizeof(base_xpath), af_xpath)
6364 < 0)
6365 return CMD_WARNING_CONFIG_FAILED;
6366
6367 if (strmatch(type, "standard")) {
6368 snprintf(std_xpath, sizeof(std_xpath),
6369 "./%s/send-community/send-community",
6370 bgp_afi_safi_get_container_str(afi, safi));
6371
6372 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "true");
6373 }
6374
6375 if (strmatch(type, "extended")) {
6376 snprintf(ext_xpath, sizeof(ext_xpath),
6377 "./%s/send-community/send-ext-community",
6378 bgp_afi_safi_get_container_str(afi, safi));
6379
6380 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "true");
6381 }
6382
6383 if (strmatch(type, "large")) {
6384 snprintf(lrg_xpath, sizeof(lrg_xpath),
6385 "./%s/send-community/send-large-community",
6386 bgp_afi_safi_get_container_str(afi, safi));
6387
6388 nb_cli_enqueue_change(vty, lrg_xpath, NB_OP_MODIFY, "true");
6389 }
6390
6391 if (strmatch(type, "both")) {
6392 snprintf(std_xpath, sizeof(std_xpath),
6393 "./%s/send-community/send-community",
6394 bgp_afi_safi_get_container_str(afi, safi));
6395
6396 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "true");
6397
6398 snprintf(ext_xpath, sizeof(ext_xpath),
6399 "./%s/send-community/send-ext-community",
6400 bgp_afi_safi_get_container_str(afi, safi));
6401
6402 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "true");
6403 }
6404
6405 if (strmatch(type, "all")) {
6406 snprintf(std_xpath, sizeof(std_xpath),
6407 "./%s/send-community/send-community",
6408 bgp_afi_safi_get_container_str(afi, safi));
6409
6410 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "true");
6411
6412 snprintf(ext_xpath, sizeof(ext_xpath),
6413 "./%s/send-community/send-ext-community",
6414 bgp_afi_safi_get_container_str(afi, safi));
6415
6416 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "true");
6417
6418 snprintf(lrg_xpath, sizeof(lrg_xpath),
6419 "./%s/send-community/send-large-community",
6420 bgp_afi_safi_get_container_str(afi, safi));
6421
6422 nb_cli_enqueue_change(vty, lrg_xpath, NB_OP_MODIFY, "true");
6423 }
6424
6425 return nb_cli_apply_changes(vty, base_xpath);
6426 }
6427
6428 ALIAS_HIDDEN(
6429 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
6430 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6431 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6432 "Send Community attribute to this neighbor\n"
6433 "Send Standard and Extended Community attributes\n"
6434 "Send Standard, Large and Extended Community attributes\n"
6435 "Send Extended Community attributes\n"
6436 "Send Standard Community attributes\n"
6437 "Send Large Community attributes\n")
6438
6439 DEFUN_YANG (no_neighbor_send_community_type,
6440 no_neighbor_send_community_type_cmd,
6441 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6442 NO_STR
6443 NEIGHBOR_STR
6444 NEIGHBOR_ADDR_STR2
6445 "Send Community attribute to this neighbor\n"
6446 "Send Standard and Extended Community attributes\n"
6447 "Send Standard, Large and Extended Community attributes\n"
6448 "Send Extended Community attributes\n"
6449 "Send Standard Community attributes\n"
6450 "Send Large Community attributes\n")
6451 {
6452 const char *type = argv[argc - 1]->text;
6453 char *peer_str = argv[2]->arg;
6454 char base_xpath[XPATH_MAXLEN];
6455 char af_xpath[XPATH_MAXLEN];
6456 char std_xpath[XPATH_MAXLEN];
6457 char ext_xpath[XPATH_MAXLEN];
6458 char lrg_xpath[XPATH_MAXLEN];
6459 afi_t afi = bgp_node_afi(vty);
6460 safi_t safi = bgp_node_safi(vty);
6461
6462 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6463 yang_afi_safi_value2identity(afi, safi));
6464
6465 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6466 sizeof(base_xpath), af_xpath)
6467 < 0)
6468 return CMD_WARNING_CONFIG_FAILED;
6469
6470 if (strmatch(type, "standard")) {
6471 snprintf(std_xpath, sizeof(std_xpath),
6472 "./%s/send-community/send-community",
6473 bgp_afi_safi_get_container_str(afi, safi));
6474
6475 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "false");
6476 }
6477
6478 if (strmatch(type, "extended")) {
6479 snprintf(ext_xpath, sizeof(ext_xpath),
6480 "./%s/send-community/send-ext-community",
6481 bgp_afi_safi_get_container_str(afi, safi));
6482
6483 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "false");
6484 }
6485
6486 if (strmatch(type, "large")) {
6487 snprintf(lrg_xpath, sizeof(lrg_xpath),
6488 "./%s/send-community/send-large-community",
6489 bgp_afi_safi_get_container_str(afi, safi));
6490
6491 nb_cli_enqueue_change(vty, lrg_xpath, NB_OP_MODIFY, "false");
6492 }
6493
6494 if (strmatch(type, "both")) {
6495 snprintf(std_xpath, sizeof(std_xpath),
6496 "./%s/send-community/send-community",
6497 bgp_afi_safi_get_container_str(afi, safi));
6498
6499 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "false");
6500
6501 snprintf(ext_xpath, sizeof(ext_xpath),
6502 "./%s/send-community/send-ext-community",
6503 bgp_afi_safi_get_container_str(afi, safi));
6504
6505 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "false");
6506 }
6507
6508 if (strmatch(type, "all")) {
6509 snprintf(std_xpath, sizeof(std_xpath),
6510 "./%s/send-community/send-community",
6511 bgp_afi_safi_get_container_str(afi, safi));
6512
6513 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "false");
6514
6515 snprintf(ext_xpath, sizeof(ext_xpath),
6516 "./%s/send-community/send-ext-community",
6517 bgp_afi_safi_get_container_str(afi, safi));
6518
6519 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "false");
6520
6521 snprintf(lrg_xpath, sizeof(lrg_xpath),
6522 "./%s/send-community/send-large-community",
6523 bgp_afi_safi_get_container_str(afi, safi));
6524
6525 nb_cli_enqueue_change(vty, lrg_xpath, NB_OP_MODIFY, "false");
6526 }
6527
6528 return nb_cli_apply_changes(vty, base_xpath);
6529 }
6530
6531 ALIAS_HIDDEN(
6532 no_neighbor_send_community_type,
6533 no_neighbor_send_community_type_hidden_cmd,
6534 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6535 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6536 "Send Community attribute to this neighbor\n"
6537 "Send Standard and Extended Community attributes\n"
6538 "Send Standard, Large and Extended Community attributes\n"
6539 "Send Extended Community attributes\n"
6540 "Send Standard Community attributes\n"
6541 "Send Large Community attributes\n")
6542
6543 /* neighbor soft-reconfig. */
6544 DEFUN_YANG (neighbor_soft_reconfiguration,
6545 neighbor_soft_reconfiguration_cmd,
6546 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6547 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6548 "Per neighbor soft reconfiguration\n"
6549 "Allow inbound soft reconfiguration for this neighbor\n")
6550 {
6551 int idx_peer = 1;
6552 char base_xpath[XPATH_MAXLEN];
6553 char af_xpath[XPATH_MAXLEN];
6554 char soft_xpath[XPATH_MAXLEN];
6555 afi_t afi = bgp_node_afi(vty);
6556 safi_t safi = bgp_node_safi(vty);
6557
6558 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6559 yang_afi_safi_value2identity(afi, safi));
6560
6561 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6562 sizeof(base_xpath), af_xpath)
6563 < 0)
6564 return CMD_WARNING_CONFIG_FAILED;
6565
6566 snprintf(soft_xpath, sizeof(soft_xpath), "./%s/soft-reconfiguration",
6567 bgp_afi_safi_get_container_str(afi, safi));
6568
6569 nb_cli_enqueue_change(vty, soft_xpath, NB_OP_MODIFY, "true");
6570
6571 return nb_cli_apply_changes(vty, base_xpath);
6572 }
6573
6574 ALIAS_HIDDEN(neighbor_soft_reconfiguration,
6575 neighbor_soft_reconfiguration_hidden_cmd,
6576 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6577 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6578 "Per neighbor soft reconfiguration\n"
6579 "Allow inbound soft reconfiguration for this neighbor\n")
6580
6581 DEFUN_YANG (no_neighbor_soft_reconfiguration,
6582 no_neighbor_soft_reconfiguration_cmd,
6583 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6584 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6585 "Per neighbor soft reconfiguration\n"
6586 "Allow inbound soft reconfiguration for this neighbor\n")
6587 {
6588 int idx_peer = 2;
6589 char base_xpath[XPATH_MAXLEN];
6590 char af_xpath[XPATH_MAXLEN];
6591 char soft_xpath[XPATH_MAXLEN];
6592 afi_t afi = bgp_node_afi(vty);
6593 safi_t safi = bgp_node_safi(vty);
6594
6595 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6596 yang_afi_safi_value2identity(afi, safi));
6597
6598 snprintf(soft_xpath, sizeof(soft_xpath), "./%s/soft-reconfiguration",
6599 bgp_afi_safi_get_container_str(afi, safi));
6600
6601 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6602 sizeof(base_xpath), af_xpath)
6603 < 0)
6604 return CMD_WARNING_CONFIG_FAILED;
6605
6606 nb_cli_enqueue_change(vty, soft_xpath, NB_OP_MODIFY, "false");
6607
6608 return nb_cli_apply_changes(vty, base_xpath);
6609 }
6610
6611 ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
6612 no_neighbor_soft_reconfiguration_hidden_cmd,
6613 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6614 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6615 "Per neighbor soft reconfiguration\n"
6616 "Allow inbound soft reconfiguration for this neighbor\n")
6617
6618 DEFUN_YANG (neighbor_route_reflector_client,
6619 neighbor_route_reflector_client_cmd,
6620 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6621 NEIGHBOR_STR
6622 NEIGHBOR_ADDR_STR2
6623 "Configure a neighbor as Route Reflector client\n")
6624 {
6625 int idx_peer = 1;
6626 char base_xpath[XPATH_MAXLEN];
6627 char af_xpath[XPATH_MAXLEN];
6628 char attr_xpath[XPATH_MAXLEN];
6629 afi_t afi = bgp_node_afi(vty);
6630 safi_t safi = bgp_node_safi(vty);
6631
6632 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6633 yang_afi_safi_value2identity(afi, safi));
6634
6635 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6636 sizeof(base_xpath), af_xpath)
6637 < 0)
6638 return CMD_WARNING_CONFIG_FAILED;
6639
6640 snprintf(attr_xpath, sizeof(attr_xpath),
6641 "./%s/route-reflector/route-reflector-client",
6642 bgp_afi_safi_get_container_str(afi, safi));
6643
6644 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
6645
6646 return nb_cli_apply_changes(vty, base_xpath);
6647 }
6648
6649 ALIAS_HIDDEN(neighbor_route_reflector_client,
6650 neighbor_route_reflector_client_hidden_cmd,
6651 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6652 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6653 "Configure a neighbor as Route Reflector client\n")
6654
6655 DEFUN_YANG (no_neighbor_route_reflector_client,
6656 no_neighbor_route_reflector_client_cmd,
6657 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6658 NO_STR
6659 NEIGHBOR_STR
6660 NEIGHBOR_ADDR_STR2
6661 "Configure a neighbor as Route Reflector client\n")
6662 {
6663 int idx_peer = 2;
6664 char base_xpath[XPATH_MAXLEN];
6665 char af_xpath[XPATH_MAXLEN];
6666 char attr_xpath[XPATH_MAXLEN];
6667 afi_t afi = bgp_node_afi(vty);
6668 safi_t safi = bgp_node_safi(vty);
6669
6670 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6671 yang_afi_safi_value2identity(afi, safi));
6672
6673 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6674 sizeof(base_xpath), af_xpath)
6675 < 0)
6676 return CMD_WARNING_CONFIG_FAILED;
6677
6678 snprintf(attr_xpath, sizeof(attr_xpath),
6679 "./%s/route-reflector/route-reflector-client",
6680 bgp_afi_safi_get_container_str(afi, safi));
6681
6682 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6683
6684 return nb_cli_apply_changes(vty, base_xpath);
6685 }
6686
6687 ALIAS_HIDDEN(no_neighbor_route_reflector_client,
6688 no_neighbor_route_reflector_client_hidden_cmd,
6689 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6690 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6691 "Configure a neighbor as Route Reflector client\n")
6692
6693 /* neighbor route-server-client. */
6694 DEFUN_YANG (neighbor_route_server_client,
6695 neighbor_route_server_client_cmd,
6696 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6697 NEIGHBOR_STR
6698 NEIGHBOR_ADDR_STR2
6699 "Configure a neighbor as Route Server client\n")
6700 {
6701 int idx_peer = 1;
6702 char base_xpath[XPATH_MAXLEN];
6703 char af_xpath[XPATH_MAXLEN];
6704 char attr_xpath[XPATH_MAXLEN];
6705 afi_t afi = bgp_node_afi(vty);
6706 safi_t safi = bgp_node_safi(vty);
6707
6708 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6709 yang_afi_safi_value2identity(afi, safi));
6710
6711 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6712 sizeof(base_xpath), af_xpath)
6713 < 0)
6714 return CMD_WARNING_CONFIG_FAILED;
6715
6716 snprintf(attr_xpath, sizeof(attr_xpath),
6717 "./%s/route-server/route-server-client",
6718 bgp_afi_safi_get_container_str(afi, safi));
6719
6720 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
6721
6722 return nb_cli_apply_changes(vty, base_xpath);
6723 }
6724
6725 ALIAS_HIDDEN(neighbor_route_server_client,
6726 neighbor_route_server_client_hidden_cmd,
6727 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6728 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6729 "Configure a neighbor as Route Server client\n")
6730
6731 DEFUN_YANG (no_neighbor_route_server_client,
6732 no_neighbor_route_server_client_cmd,
6733 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6734 NO_STR
6735 NEIGHBOR_STR
6736 NEIGHBOR_ADDR_STR2
6737 "Configure a neighbor as Route Server client\n")
6738 {
6739 int idx_peer = 2;
6740 char base_xpath[XPATH_MAXLEN];
6741 char af_xpath[XPATH_MAXLEN];
6742 char attr_xpath[XPATH_MAXLEN];
6743 afi_t afi = bgp_node_afi(vty);
6744 safi_t safi = bgp_node_safi(vty);
6745
6746 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6747 yang_afi_safi_value2identity(afi, safi));
6748
6749 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6750 sizeof(base_xpath), af_xpath)
6751 < 0)
6752 return CMD_WARNING_CONFIG_FAILED;
6753
6754 snprintf(attr_xpath, sizeof(attr_xpath),
6755 "./%s/route-server/route-server-client",
6756 bgp_afi_safi_get_container_str(afi, safi));
6757
6758 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6759
6760 return nb_cli_apply_changes(vty, base_xpath);
6761 }
6762
6763 ALIAS_HIDDEN(no_neighbor_route_server_client,
6764 no_neighbor_route_server_client_hidden_cmd,
6765 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6766 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6767 "Configure a neighbor as Route Server client\n")
6768
6769 DEFUN (neighbor_nexthop_local_unchanged,
6770 neighbor_nexthop_local_unchanged_cmd,
6771 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
6772 NEIGHBOR_STR
6773 NEIGHBOR_ADDR_STR2
6774 "Configure treatment of outgoing link-local nexthop attribute\n"
6775 "Leave link-local nexthop unchanged for this peer\n")
6776 {
6777 int idx_peer = 1;
6778 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6779 bgp_node_safi(vty),
6780 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
6781 }
6782
6783 DEFUN (no_neighbor_nexthop_local_unchanged,
6784 no_neighbor_nexthop_local_unchanged_cmd,
6785 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
6786 NO_STR
6787 NEIGHBOR_STR
6788 NEIGHBOR_ADDR_STR2
6789 "Configure treatment of outgoing link-local-nexthop attribute\n"
6790 "Leave link-local nexthop unchanged for this peer\n")
6791 {
6792 int idx_peer = 2;
6793 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6794 bgp_node_afi(vty), bgp_node_safi(vty),
6795 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
6796 }
6797
6798 DEFUN_YANG (neighbor_attr_unchanged,
6799 neighbor_attr_unchanged_cmd,
6800 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6801 NEIGHBOR_STR
6802 NEIGHBOR_ADDR_STR2
6803 "BGP attribute is propagated unchanged to this neighbor\n"
6804 "As-path attribute\n"
6805 "Nexthop attribute\n"
6806 "Med attribute\n")
6807 {
6808 int idx = 0;
6809 char *peer_str = argv[1]->arg;
6810 bool aspath = false;
6811 bool nexthop = false;
6812 bool med = false;
6813 afi_t afi = bgp_node_afi(vty);
6814 safi_t safi = bgp_node_safi(vty);
6815 char base_xpath[XPATH_MAXLEN];
6816 char af_xpath[XPATH_MAXLEN];
6817 char as_xpath[XPATH_MAXLEN];
6818 char nxthop_xpath[XPATH_MAXLEN];
6819 char med_xpath[XPATH_MAXLEN];
6820
6821 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6822 yang_afi_safi_value2identity(afi, safi));
6823
6824 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6825 sizeof(base_xpath), af_xpath)
6826 < 0)
6827 return CMD_WARNING_CONFIG_FAILED;
6828
6829 if (argv_find(argv, argc, "as-path", &idx))
6830 aspath = true;
6831
6832 idx = 0;
6833 if (argv_find(argv, argc, "next-hop", &idx))
6834 nexthop = true;
6835
6836 idx = 0;
6837 if (argv_find(argv, argc, "med", &idx))
6838 med = true;
6839
6840 snprintf(as_xpath, sizeof(as_xpath),
6841 "./%s/attr-unchanged/as-path-unchanged",
6842 bgp_afi_safi_get_container_str(afi, safi));
6843 snprintf(nxthop_xpath, sizeof(nxthop_xpath),
6844 "./%s/attr-unchanged/next-hop-unchanged",
6845 bgp_afi_safi_get_container_str(afi, safi));
6846 snprintf(med_xpath, sizeof(med_xpath),
6847 "./%s/attr-unchanged/med-unchanged",
6848 bgp_afi_safi_get_container_str(afi, safi));
6849
6850 /* no flags means all of them! */
6851 if (!aspath && !nexthop && !med) {
6852 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY, "true");
6853 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY, "true");
6854 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY, "true");
6855 } else {
6856 if (!aspath)
6857 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY,
6858 "false");
6859 else
6860 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY,
6861 "true");
6862
6863 if (!nexthop)
6864 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY,
6865 "false");
6866 else
6867 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY,
6868 "true");
6869
6870 if (!med)
6871 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY,
6872 "false");
6873 else
6874 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY,
6875 "true");
6876 }
6877
6878 return nb_cli_apply_changes(vty, base_xpath);
6879 }
6880
6881 ALIAS_HIDDEN(
6882 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
6883 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6884 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6885 "BGP attribute is propagated unchanged to this neighbor\n"
6886 "As-path attribute\n"
6887 "Nexthop attribute\n"
6888 "Med attribute\n")
6889
6890 DEFUN_YANG (no_neighbor_attr_unchanged,
6891 no_neighbor_attr_unchanged_cmd,
6892 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6893 NO_STR
6894 NEIGHBOR_STR
6895 NEIGHBOR_ADDR_STR2
6896 "BGP attribute is propagated unchanged to this neighbor\n"
6897 "As-path attribute\n"
6898 "Nexthop attribute\n"
6899 "Med attribute\n")
6900 {
6901 int idx = 0;
6902 char *peer_str = argv[2]->arg;
6903 bool aspath = false;
6904 bool nexthop = false;
6905 bool med = false;
6906 afi_t afi = bgp_node_afi(vty);
6907 safi_t safi = bgp_node_safi(vty);
6908 char base_xpath[XPATH_MAXLEN];
6909 char af_xpath[XPATH_MAXLEN];
6910 char as_xpath[XPATH_MAXLEN];
6911 char nxthop_xpath[XPATH_MAXLEN];
6912 char med_xpath[XPATH_MAXLEN];
6913
6914 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6915 yang_afi_safi_value2identity(afi, safi));
6916
6917 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6918 sizeof(base_xpath), af_xpath)
6919 < 0)
6920 return CMD_WARNING_CONFIG_FAILED;
6921
6922 if (argv_find(argv, argc, "as-path", &idx))
6923 aspath = true;
6924
6925 idx = 0;
6926 if (argv_find(argv, argc, "next-hop", &idx))
6927 nexthop = true;
6928
6929 idx = 0;
6930 if (argv_find(argv, argc, "med", &idx))
6931 med = true;
6932
6933 snprintf(as_xpath, sizeof(as_xpath),
6934 "./%s/attr-unchanged/as-path-unchanged",
6935 bgp_afi_safi_get_container_str(afi, safi));
6936 snprintf(nxthop_xpath, sizeof(nxthop_xpath),
6937 "./%s/attr-unchanged/next-hop-unchanged",
6938 bgp_afi_safi_get_container_str(afi, safi));
6939 snprintf(med_xpath, sizeof(med_xpath),
6940 "./%s/attr-unchanged/med-unchanged",
6941 bgp_afi_safi_get_container_str(afi, safi));
6942
6943 /* no flags means all of them! */
6944 if (!aspath && !nexthop && !med) {
6945 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY, "false");
6946 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY, "false");
6947 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY, "false");
6948 }
6949
6950 if (aspath)
6951 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY, "false");
6952
6953 if (nexthop)
6954 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY, "false");
6955
6956 if (med)
6957 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY, "false");
6958
6959 return nb_cli_apply_changes(vty, base_xpath);
6960 }
6961
6962 ALIAS_HIDDEN(
6963 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
6964 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6965 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6966 "BGP attribute is propagated unchanged to this neighbor\n"
6967 "As-path attribute\n"
6968 "Nexthop attribute\n"
6969 "Med attribute\n")
6970
6971 /* neighbor ebgp-multihop. */
6972 DEFUN_YANG (neighbor_ebgp_multihop,
6973 neighbor_ebgp_multihop_cmd,
6974 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
6975 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6976 "Allow EBGP neighbors not on directly connected networks\n")
6977 {
6978 int idx_peer = 1;
6979 char base_xpath[XPATH_MAXLEN];
6980
6981 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6982 sizeof(base_xpath), NULL)
6983 < 0)
6984 return CMD_WARNING_CONFIG_FAILED;
6985
6986 nb_cli_enqueue_change(vty, "./ebgp-multihop/enabled", NB_OP_MODIFY,
6987 "true");
6988
6989 return nb_cli_apply_changes(vty, base_xpath);
6990 }
6991
6992 DEFUN_YANG (neighbor_ebgp_multihop_ttl,
6993 neighbor_ebgp_multihop_ttl_cmd,
6994 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
6995 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6996 "Allow EBGP neighbors not on directly connected networks\n"
6997 "maximum hop count\n")
6998 {
6999 int idx_peer = 1;
7000 int idx_number = 3;
7001 char base_xpath[XPATH_MAXLEN];
7002
7003 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7004 sizeof(base_xpath), NULL)
7005 < 0)
7006 return CMD_WARNING_CONFIG_FAILED;
7007
7008 nb_cli_enqueue_change(vty, "./ebgp-multihop/multihop-ttl", NB_OP_MODIFY,
7009 argv[idx_number]->arg);
7010
7011 return nb_cli_apply_changes(vty, base_xpath);
7012 }
7013
7014 DEFUN_YANG (no_neighbor_ebgp_multihop,
7015 no_neighbor_ebgp_multihop_cmd,
7016 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
7017 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7018 "Allow EBGP neighbors not on directly connected networks\n"
7019 "maximum hop count\n")
7020 {
7021 int idx_peer = 2;
7022 char base_xpath[XPATH_MAXLEN];
7023
7024 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7025 sizeof(base_xpath), NULL)
7026 < 0)
7027 return CMD_WARNING_CONFIG_FAILED;
7028
7029 if (argc > 4)
7030 nb_cli_enqueue_change(vty, "./ebgp-multihop/multihop-ttl",
7031 NB_OP_DESTROY, NULL);
7032 else
7033 nb_cli_enqueue_change(vty, "./ebgp-multihop/enabled",
7034 NB_OP_MODIFY, "false");
7035
7036 return nb_cli_apply_changes(vty, base_xpath);
7037 }
7038
7039
7040 /* disable-connected-check */
7041 DEFUN_YANG (neighbor_disable_connected_check,
7042 neighbor_disable_connected_check_cmd,
7043 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
7044 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7045 "one-hop away EBGP peer using loopback address\n"
7046 "Enforce EBGP neighbors perform multihop\n")
7047 {
7048 int idx_peer = 1;
7049 char base_xpath[XPATH_MAXLEN];
7050
7051 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7052 sizeof(base_xpath), NULL)
7053 < 0)
7054 return CMD_WARNING_CONFIG_FAILED;
7055
7056 nb_cli_enqueue_change(vty, "./ebgp-multihop/disable-connected-check",
7057 NB_OP_MODIFY, "true");
7058
7059 return nb_cli_apply_changes(vty, base_xpath);
7060 }
7061
7062 DEFUN_YANG (no_neighbor_disable_connected_check,
7063 no_neighbor_disable_connected_check_cmd,
7064 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
7065 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7066 "one-hop away EBGP peer using loopback address\n"
7067 "Enforce EBGP neighbors perform multihop\n")
7068 {
7069 int idx_peer = 2;
7070 char base_xpath[XPATH_MAXLEN];
7071
7072 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7073 sizeof(base_xpath), NULL)
7074 < 0)
7075 return CMD_WARNING_CONFIG_FAILED;
7076
7077 nb_cli_enqueue_change(vty, "./ebgp-multihop/disable-connected-check",
7078 NB_OP_MODIFY, "false");
7079
7080 return nb_cli_apply_changes(vty, base_xpath);
7081 }
7082
7083
7084 /* enforce-first-as */
7085 DEFUN_YANG (neighbor_enforce_first_as,
7086 neighbor_enforce_first_as_cmd,
7087 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
7088 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7089 "Enforce the first AS for EBGP routes\n")
7090 {
7091 int idx_peer = 1;
7092 char base_xpath[XPATH_MAXLEN];
7093
7094 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7095 sizeof(base_xpath), NULL)
7096 < 0)
7097 return CMD_WARNING_CONFIG_FAILED;
7098
7099 nb_cli_enqueue_change(vty, "./enforce-first-as", NB_OP_MODIFY, "true");
7100
7101 return nb_cli_apply_changes(vty, base_xpath);
7102 }
7103
7104 DEFUN_YANG (no_neighbor_enforce_first_as,
7105 no_neighbor_enforce_first_as_cmd,
7106 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
7107 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7108 "Enforce the first AS for EBGP routes\n")
7109 {
7110 int idx_peer = 2;
7111 char base_xpath[XPATH_MAXLEN];
7112
7113 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7114 sizeof(base_xpath), NULL)
7115 < 0)
7116 return CMD_WARNING_CONFIG_FAILED;
7117
7118 nb_cli_enqueue_change(vty, "./enforce-first-as", NB_OP_MODIFY, "false");
7119
7120 return nb_cli_apply_changes(vty, base_xpath);
7121 }
7122
7123 static int peer_and_group_lookup_nb(struct vty *vty, const char *peer_str,
7124 char *base_xpath, int xpath_len,
7125 char *xpath)
7126 {
7127 union sockunion su;
7128 char num_xpath[XPATH_MAXLEN];
7129 char unnbr_xpath[XPATH_MAXLEN];
7130 char prgrp_xpath[XPATH_MAXLEN];
7131
7132 if (str2sockunion(peer_str, &su) == 0) {
7133 snprintf(num_xpath, sizeof(num_xpath),
7134 "/neighbors/neighbor[remote-address='%s']", peer_str);
7135 if (yang_dnode_existsf(vty->candidate_config->dnode, "%s%s",
7136 VTY_CURR_XPATH, num_xpath)) {
7137 snprintf(base_xpath, xpath_len,
7138 FRR_BGP_NEIGHBOR_NUM_XPATH, peer_str,
7139 xpath ? xpath : "");
7140 } else {
7141 vty_out(vty,
7142 "%% Specify remote-as or peer-group commands first\n");
7143 return -1;
7144 }
7145
7146 } else {
7147 snprintf(unnbr_xpath, sizeof(unnbr_xpath),
7148 "/neighbors/unnumbered-neighbor[interface='%s']",
7149 peer_str);
7150
7151 snprintf(prgrp_xpath, sizeof(prgrp_xpath),
7152 "/peer-groups/peer-group[peer-group-name='%s']",
7153 peer_str);
7154
7155 if (yang_dnode_existsf(vty->candidate_config->dnode, "%s%s",
7156 VTY_CURR_XPATH, unnbr_xpath)) {
7157 snprintf(base_xpath, xpath_len,
7158 FRR_BGP_NEIGHBOR_UNNUM_XPATH, peer_str,
7159 xpath ? xpath : "");
7160 } else if (yang_dnode_existsf(vty->candidate_config->dnode,
7161 "%s%s", VTY_CURR_XPATH,
7162 prgrp_xpath)) {
7163 snprintf(base_xpath, xpath_len,
7164 FRR_BGP_PEER_GROUP_XPATH, peer_str,
7165 xpath ? xpath : "");
7166 } else {
7167 vty_out(vty,
7168 "%% Create the peer-group or interface first\n");
7169 return -1;
7170 }
7171 }
7172
7173 return 0;
7174 }
7175
7176 DEFUN_YANG (neighbor_description,
7177 neighbor_description_cmd,
7178 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
7179 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7180 "Neighbor specific description\n"
7181 "Up to 80 characters describing this neighbor\n")
7182 {
7183 int idx_peer = 1;
7184 int idx_line = 3;
7185 int ret;
7186 char base_xpath[XPATH_MAXLEN];
7187 char *str;
7188
7189 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7190 sizeof(base_xpath), NULL)
7191 < 0)
7192 return CMD_WARNING_CONFIG_FAILED;
7193
7194 str = argv_concat(argv, argc, idx_line);
7195
7196 nb_cli_enqueue_change(vty, "./description", NB_OP_MODIFY, str);
7197
7198 ret = nb_cli_apply_changes(vty, base_xpath);
7199
7200 XFREE(MTYPE_TMP, str);
7201
7202 return ret;
7203 }
7204
7205 DEFUN_YANG (no_neighbor_description,
7206 no_neighbor_description_cmd,
7207 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
7208 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7209 "Neighbor specific description\n")
7210 {
7211 int idx_peer = 2;
7212 char base_xpath[XPATH_MAXLEN];
7213
7214 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7215 sizeof(base_xpath), NULL)
7216 < 0)
7217 return CMD_WARNING_CONFIG_FAILED;
7218
7219 nb_cli_enqueue_change(vty, "./description", NB_OP_DESTROY, NULL);
7220
7221 return nb_cli_apply_changes(vty, base_xpath);
7222 }
7223
7224 ALIAS_YANG(no_neighbor_description, no_neighbor_description_comment_cmd,
7225 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
7226 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7227 "Neighbor specific description\n"
7228 "Up to 80 characters describing this neighbor\n")
7229
7230 #define BGP_UPDATE_SOURCE_HELP_STR \
7231 "IPv4 address\n" \
7232 "IPv6 address\n" \
7233 "Interface name (requires zebra to be running)\n"
7234
7235 DEFUN_YANG (neighbor_update_source,
7236 neighbor_update_source_cmd,
7237 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
7238 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7239 "Source of routing updates\n"
7240 BGP_UPDATE_SOURCE_HELP_STR)
7241 {
7242 int idx_peer = 1;
7243 int idx_peer_2 = 3;
7244 union sockunion su;
7245 char base_xpath[XPATH_MAXLEN];
7246
7247 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7248 sizeof(base_xpath), NULL)
7249 < 0)
7250 return CMD_WARNING_CONFIG_FAILED;
7251
7252 if (str2sockunion(argv[idx_peer_2]->arg, &su) == 0)
7253 nb_cli_enqueue_change(vty, "./update-source/ip", NB_OP_MODIFY,
7254 argv[idx_peer_2]->arg);
7255 else
7256 nb_cli_enqueue_change(vty, "./update-source/interface",
7257 NB_OP_MODIFY, argv[idx_peer_2]->arg);
7258
7259 return nb_cli_apply_changes(vty, base_xpath);
7260 }
7261
7262 DEFUN_YANG (no_neighbor_update_source,
7263 no_neighbor_update_source_cmd,
7264 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
7265 NO_STR NEIGHBOR_STR
7266 NEIGHBOR_ADDR_STR2
7267 "Source of routing updates\n"
7268 BGP_UPDATE_SOURCE_HELP_STR)
7269 {
7270 int idx_peer = 2;
7271 char base_xpath[XPATH_MAXLEN];
7272
7273 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7274 sizeof(base_xpath), NULL)
7275 < 0)
7276 return CMD_WARNING_CONFIG_FAILED;
7277
7278 nb_cli_enqueue_change(vty, "./update-source/ip", NB_OP_DESTROY, NULL);
7279 nb_cli_enqueue_change(vty, "./update-source/interface", NB_OP_DESTROY,
7280 NULL);
7281
7282 return nb_cli_apply_changes(vty, base_xpath);
7283 }
7284
7285 static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
7286 afi_t afi, safi_t safi,
7287 const char *rmap, int set)
7288 {
7289 int ret;
7290 struct peer *peer;
7291 struct route_map *route_map = NULL;
7292
7293 peer = peer_and_group_lookup_vty(vty, peer_str);
7294 if (!peer)
7295 return CMD_WARNING_CONFIG_FAILED;
7296
7297 if (set) {
7298 if (rmap)
7299 route_map = route_map_lookup_warn_noexist(vty, rmap);
7300 ret = peer_default_originate_set(peer, afi, safi,
7301 rmap, route_map);
7302 } else
7303 ret = peer_default_originate_unset(peer, afi, safi);
7304
7305 return bgp_vty_return(vty, ret);
7306 }
7307
7308 /* neighbor default-originate. */
7309 DEFUN (neighbor_default_originate,
7310 neighbor_default_originate_cmd,
7311 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
7312 NEIGHBOR_STR
7313 NEIGHBOR_ADDR_STR2
7314 "Originate default route to this neighbor\n")
7315 {
7316 int idx_peer = 1;
7317 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
7318 bgp_node_afi(vty),
7319 bgp_node_safi(vty), NULL, 1);
7320 }
7321
7322 ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
7323 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
7324 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7325 "Originate default route to this neighbor\n")
7326
7327 DEFUN (neighbor_default_originate_rmap,
7328 neighbor_default_originate_rmap_cmd,
7329 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
7330 NEIGHBOR_STR
7331 NEIGHBOR_ADDR_STR2
7332 "Originate default route to this neighbor\n"
7333 "Route-map to specify criteria to originate default\n"
7334 "route-map name\n")
7335 {
7336 int idx_peer = 1;
7337 int idx_word = 4;
7338 return peer_default_originate_set_vty(
7339 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7340 argv[idx_word]->arg, 1);
7341 }
7342
7343 ALIAS_HIDDEN(
7344 neighbor_default_originate_rmap,
7345 neighbor_default_originate_rmap_hidden_cmd,
7346 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
7347 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7348 "Originate default route to this neighbor\n"
7349 "Route-map to specify criteria to originate default\n"
7350 "route-map name\n")
7351
7352 DEFUN (no_neighbor_default_originate,
7353 no_neighbor_default_originate_cmd,
7354 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
7355 NO_STR
7356 NEIGHBOR_STR
7357 NEIGHBOR_ADDR_STR2
7358 "Originate default route to this neighbor\n"
7359 "Route-map to specify criteria to originate default\n"
7360 "route-map name\n")
7361 {
7362 int idx_peer = 2;
7363 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
7364 bgp_node_afi(vty),
7365 bgp_node_safi(vty), NULL, 0);
7366 }
7367
7368 ALIAS_HIDDEN(
7369 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
7370 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
7371 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7372 "Originate default route to this neighbor\n"
7373 "Route-map to specify criteria to originate default\n"
7374 "route-map name\n")
7375
7376
7377 /* Set specified peer's BGP port. */
7378 DEFUN_YANG (neighbor_port,
7379 neighbor_port_cmd,
7380 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
7381 NEIGHBOR_STR
7382 NEIGHBOR_ADDR_STR
7383 "Neighbor's BGP port\n"
7384 "TCP port number\n")
7385 {
7386 int idx_ip = 1;
7387 int idx_number = 3;
7388 char base_xpath[XPATH_MAXLEN];
7389
7390 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_NUM_XPATH,
7391 argv[idx_ip]->arg, "");
7392
7393 nb_cli_enqueue_change(vty, "./local-port", NB_OP_MODIFY,
7394 argv[idx_number]->arg);
7395
7396 return nb_cli_apply_changes(vty, base_xpath);
7397 }
7398
7399 DEFUN_YANG (no_neighbor_port,
7400 no_neighbor_port_cmd,
7401 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
7402 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR
7403 "Neighbor's BGP port\n"
7404 "TCP port number\n")
7405 {
7406 int idx_ip = 2;
7407 char base_xpath[XPATH_MAXLEN];
7408
7409 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_NUM_XPATH,
7410 argv[idx_ip]->arg, "");
7411
7412 nb_cli_enqueue_change(vty, "./local-port", NB_OP_DESTROY, NULL);
7413
7414 return nb_cli_apply_changes(vty, base_xpath);
7415 }
7416
7417 DEFUN_YANG (neighbor_weight,
7418 neighbor_weight_cmd,
7419 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7420 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7421 "Set default weight for routes from this neighbor\n"
7422 "default weight\n")
7423 {
7424 int idx_peer = 1;
7425 int idx_number = 3;
7426 char base_xpath[XPATH_MAXLEN];
7427 char af_xpath[XPATH_MAXLEN];
7428 char attr_xpath[XPATH_MAXLEN];
7429 afi_t afi = bgp_node_afi(vty);
7430 safi_t safi = bgp_node_safi(vty);
7431
7432 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
7433 yang_afi_safi_value2identity(afi, safi));
7434
7435 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7436 sizeof(base_xpath), af_xpath)
7437 < 0)
7438 return CMD_WARNING_CONFIG_FAILED;
7439
7440 snprintf(attr_xpath, sizeof(attr_xpath), "./%s/weight/weight-attribute",
7441 bgp_afi_safi_get_container_str(afi, safi));
7442
7443 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY,
7444 argv[idx_number]->arg);
7445
7446 return nb_cli_apply_changes(vty, base_xpath);
7447 }
7448
7449 ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
7450 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7451 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7452 "Set default weight for routes from this neighbor\n"
7453 "default weight\n")
7454
7455 DEFUN_YANG (no_neighbor_weight,
7456 no_neighbor_weight_cmd,
7457 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7458 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7459 "Set default weight for routes from this neighbor\n"
7460 "default weight\n")
7461 {
7462 int idx_peer = 2;
7463 char base_xpath[XPATH_MAXLEN];
7464 char af_xpath[XPATH_MAXLEN];
7465 char attr_xpath[XPATH_MAXLEN];
7466 afi_t afi = bgp_node_afi(vty);
7467 safi_t safi = bgp_node_safi(vty);
7468
7469 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
7470 yang_afi_safi_value2identity(afi, safi));
7471
7472 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7473 sizeof(base_xpath), af_xpath)
7474 < 0)
7475 return CMD_WARNING_CONFIG_FAILED;
7476
7477 snprintf(attr_xpath, sizeof(attr_xpath), "./%s/weight/weight-attribute",
7478 bgp_afi_safi_get_container_str(afi, safi));
7479
7480 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_DESTROY, NULL);
7481
7482 return nb_cli_apply_changes(vty, base_xpath);
7483 }
7484
7485 ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
7486 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7487 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7488 "Set default weight for routes from this neighbor\n"
7489 "default weight\n")
7490
7491
7492 /* Override capability negotiation. */
7493 DEFUN_YANG (neighbor_override_capability,
7494 neighbor_override_capability_cmd,
7495 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7496 NEIGHBOR_STR
7497 NEIGHBOR_ADDR_STR2
7498 "Override capability negotiation result\n")
7499 {
7500 int idx_peer = 1;
7501 char base_xpath[XPATH_MAXLEN];
7502
7503 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7504 sizeof(base_xpath), NULL)
7505 < 0)
7506 return CMD_WARNING_CONFIG_FAILED;
7507
7508 nb_cli_enqueue_change(
7509 vty, "./capability-options/override-capability",
7510 NB_OP_MODIFY, "true");
7511
7512 return nb_cli_apply_changes(vty, base_xpath);
7513 }
7514
7515 DEFUN_YANG (no_neighbor_override_capability,
7516 no_neighbor_override_capability_cmd,
7517 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7518 NO_STR
7519 NEIGHBOR_STR
7520 NEIGHBOR_ADDR_STR2
7521 "Override capability negotiation result\n")
7522 {
7523 int idx_peer = 2;
7524 char base_xpath[XPATH_MAXLEN];
7525
7526 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7527 sizeof(base_xpath), NULL)
7528 < 0)
7529 return CMD_WARNING_CONFIG_FAILED;
7530
7531 nb_cli_enqueue_change(
7532 vty, "./capability-options/override-capability",
7533 NB_OP_MODIFY, "false");
7534
7535 return nb_cli_apply_changes(vty, base_xpath);
7536 }
7537
7538 DEFUN_YANG (neighbor_strict_capability,
7539 neighbor_strict_capability_cmd,
7540 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7541 NEIGHBOR_STR
7542 NEIGHBOR_ADDR_STR2
7543 "Strict capability negotiation match\n")
7544 {
7545 int idx_peer = 1;
7546 char base_xpath[XPATH_MAXLEN];
7547
7548 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7549 sizeof(base_xpath), NULL)
7550 < 0)
7551 return CMD_WARNING_CONFIG_FAILED;
7552
7553 nb_cli_enqueue_change(
7554 vty, "./capability-options/strict-capability",
7555 NB_OP_MODIFY, "true");
7556
7557 return nb_cli_apply_changes(vty, base_xpath);
7558 }
7559
7560 DEFUN_YANG (no_neighbor_strict_capability,
7561 no_neighbor_strict_capability_cmd,
7562 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7563 NO_STR
7564 NEIGHBOR_STR
7565 NEIGHBOR_ADDR_STR2
7566 "Strict capability negotiation match\n")
7567 {
7568 int idx_peer = 2;
7569 char base_xpath[XPATH_MAXLEN];
7570
7571 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7572 sizeof(base_xpath), NULL)
7573 < 0)
7574 return CMD_WARNING_CONFIG_FAILED;
7575
7576 nb_cli_enqueue_change(
7577 vty, "./capability-options/strict-capability",
7578 NB_OP_MODIFY, "false");
7579
7580 return nb_cli_apply_changes(vty, base_xpath);
7581 }
7582
7583 DEFUN_YANG (neighbor_timers,
7584 neighbor_timers_cmd,
7585 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
7586 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7587 "BGP per neighbor timers\n"
7588 "Keepalive interval\n"
7589 "Holdtime\n")
7590 {
7591 int idx_peer = 1;
7592 int idx_number = 3;
7593 int idx_number_2 = 4;
7594 char base_xpath[XPATH_MAXLEN];
7595
7596 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7597 sizeof(base_xpath), NULL)
7598 < 0)
7599 return CMD_WARNING_CONFIG_FAILED;
7600
7601 nb_cli_enqueue_change(vty, "./timers/keepalive", NB_OP_MODIFY,
7602 argv[idx_number]->arg);
7603
7604 nb_cli_enqueue_change(vty, "./timers/hold-time", NB_OP_MODIFY,
7605 argv[idx_number_2]->arg);
7606
7607 return nb_cli_apply_changes(vty, base_xpath);
7608 }
7609
7610 DEFUN_YANG (no_neighbor_timers,
7611 no_neighbor_timers_cmd,
7612 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
7613 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7614 "BGP per neighbor timers\n"
7615 "Keepalive interval\n"
7616 "Holdtime\n")
7617 {
7618 int idx_peer = 2;
7619 char base_xpath[XPATH_MAXLEN];
7620
7621 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7622 sizeof(base_xpath), NULL)
7623 < 0)
7624 return CMD_WARNING_CONFIG_FAILED;
7625
7626 nb_cli_enqueue_change(vty, "./timers/hold-time", NB_OP_DESTROY, NULL);
7627
7628 nb_cli_enqueue_change(vty, "./timers/keepalive", NB_OP_DESTROY, NULL);
7629
7630 return nb_cli_apply_changes(vty, base_xpath);
7631 }
7632
7633 DEFUN_YANG (neighbor_timers_connect,
7634 neighbor_timers_connect_cmd,
7635 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
7636 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7637 "BGP per neighbor timers\n"
7638 "BGP connect timer\n"
7639 "Connect timer\n")
7640 {
7641 int idx_peer = 1;
7642 int idx_number = 4;
7643 char base_xpath[XPATH_MAXLEN];
7644
7645 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7646 sizeof(base_xpath), NULL)
7647 < 0)
7648 return CMD_WARNING_CONFIG_FAILED;
7649
7650 nb_cli_enqueue_change(vty, "./timers/connect-time", NB_OP_MODIFY,
7651 argv[idx_number]->arg);
7652
7653 return nb_cli_apply_changes(vty, base_xpath);
7654 }
7655
7656 DEFUN_YANG (no_neighbor_timers_connect,
7657 no_neighbor_timers_connect_cmd,
7658 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
7659 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7660 "BGP per neighbor timers\n"
7661 "BGP connect timer\n"
7662 "Connect timer\n")
7663 {
7664 int idx_peer = 2;
7665 char base_xpath[XPATH_MAXLEN];
7666
7667 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7668 sizeof(base_xpath), NULL)
7669 < 0)
7670 return CMD_WARNING_CONFIG_FAILED;
7671
7672 nb_cli_enqueue_change(vty, "./timers/connect-time", NB_OP_DESTROY,
7673 NULL);
7674
7675 return nb_cli_apply_changes(vty, base_xpath);
7676 }
7677
7678 DEFPY (neighbor_timers_delayopen,
7679 neighbor_timers_delayopen_cmd,
7680 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen (1-240)$interval",
7681 NEIGHBOR_STR
7682 NEIGHBOR_ADDR_STR2
7683 "BGP per neighbor timers\n"
7684 "RFC 4271 DelayOpenTimer\n"
7685 "DelayOpenTime timer interval\n")
7686 {
7687 struct peer *peer;
7688
7689 peer = peer_and_group_lookup_vty(vty, neighbor);
7690 if (!peer)
7691 return CMD_WARNING_CONFIG_FAILED;
7692
7693 if (!interval) {
7694 if (peer_timers_delayopen_unset(peer))
7695 return CMD_WARNING_CONFIG_FAILED;
7696 } else {
7697 if (peer_timers_delayopen_set(peer, interval))
7698 return CMD_WARNING_CONFIG_FAILED;
7699 }
7700
7701 return CMD_SUCCESS;
7702 }
7703
7704 DEFPY (no_neighbor_timers_delayopen,
7705 no_neighbor_timers_delayopen_cmd,
7706 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen [(0-65535)]",
7707 NO_STR
7708 NEIGHBOR_STR
7709 NEIGHBOR_ADDR_STR2
7710 "BGP per neighbor timers\n"
7711 "RFC 4271 DelayOpenTimer\n"
7712 "DelayOpenTime timer interval\n")
7713 {
7714 struct peer *peer;
7715
7716 peer = peer_and_group_lookup_vty(vty, neighbor);
7717 if (!peer)
7718 return CMD_WARNING_CONFIG_FAILED;
7719
7720 if (peer_timers_delayopen_unset(peer))
7721 return CMD_WARNING_CONFIG_FAILED;
7722
7723 return CMD_SUCCESS;
7724 }
7725
7726 DEFUN_YANG (neighbor_advertise_interval,
7727 neighbor_advertise_interval_cmd,
7728 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
7729 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7730 "Minimum interval between sending BGP routing updates\n"
7731 "time in seconds\n")
7732 {
7733 int idx_peer = 1;
7734 int idx_number = 3;
7735 char base_xpath[XPATH_MAXLEN];
7736
7737 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7738 sizeof(base_xpath), NULL)
7739 < 0)
7740 return CMD_WARNING_CONFIG_FAILED;
7741
7742 nb_cli_enqueue_change(vty, "./timers/advertise-interval", NB_OP_MODIFY,
7743 argv[idx_number]->arg);
7744
7745 return nb_cli_apply_changes(vty, base_xpath);
7746 }
7747
7748 DEFUN_YANG (no_neighbor_advertise_interval,
7749 no_neighbor_advertise_interval_cmd,
7750 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
7751 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7752 "Minimum interval between sending BGP routing updates\n"
7753 "time in seconds\n")
7754 {
7755 int idx_peer = 2;
7756 char base_xpath[XPATH_MAXLEN];
7757
7758 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7759 sizeof(base_xpath), NULL)
7760 < 0)
7761 return CMD_WARNING_CONFIG_FAILED;
7762
7763 nb_cli_enqueue_change(vty, "./timers/advertise-interval", NB_OP_DESTROY,
7764 NULL);
7765
7766 return nb_cli_apply_changes(vty, base_xpath);
7767 }
7768
7769
7770 /* Time to wait before processing route-map updates */
7771 DEFUN (bgp_set_route_map_delay_timer,
7772 bgp_set_route_map_delay_timer_cmd,
7773 "bgp route-map delay-timer (0-600)",
7774 SET_STR
7775 "BGP route-map delay timer\n"
7776 "Time in secs to wait before processing route-map changes\n"
7777 "0 disables the timer, no route updates happen when route-maps change\n")
7778 {
7779 int idx_number = 3;
7780 uint32_t rmap_delay_timer;
7781
7782 if (argv[idx_number]->arg) {
7783 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
7784 bm->rmap_update_timer = rmap_delay_timer;
7785
7786 /* if the dynamic update handling is being disabled, and a timer
7787 * is
7788 * running, stop the timer and act as if the timer has already
7789 * fired.
7790 */
7791 if (!rmap_delay_timer && bm->t_rmap_update) {
7792 BGP_TIMER_OFF(bm->t_rmap_update);
7793 thread_execute(bm->master, bgp_route_map_update_timer,
7794 NULL, 0);
7795 }
7796 return CMD_SUCCESS;
7797 } else {
7798 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
7799 return CMD_WARNING_CONFIG_FAILED;
7800 }
7801 }
7802
7803 DEFUN (no_bgp_set_route_map_delay_timer,
7804 no_bgp_set_route_map_delay_timer_cmd,
7805 "no bgp route-map delay-timer [(0-600)]",
7806 NO_STR
7807 BGP_STR
7808 "Default BGP route-map delay timer\n"
7809 "Reset to default time to wait for processing route-map changes\n"
7810 "0 disables the timer, no route updates happen when route-maps change\n")
7811 {
7812
7813 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
7814
7815 return CMD_SUCCESS;
7816 }
7817
7818 DEFUN_YANG (neighbor_interface,
7819 neighbor_interface_cmd,
7820 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
7821 NEIGHBOR_STR NEIGHBOR_ADDR_STR
7822 "Interface\n"
7823 "Interface name\n")
7824 {
7825 int idx_ip = 1;
7826 int idx_word = 3;
7827 char base_xpath[XPATH_MAXLEN];
7828
7829 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_NUM_XPATH,
7830 argv[idx_ip]->arg, "");
7831
7832 nb_cli_enqueue_change(vty, "./local-interface", NB_OP_MODIFY,
7833 argv[idx_word]->arg);
7834
7835 return nb_cli_apply_changes(vty, base_xpath);
7836 }
7837
7838 DEFUN_YANG (no_neighbor_interface,
7839 no_neighbor_interface_cmd,
7840 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
7841 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7842 "Interface\n"
7843 "Interface name\n")
7844 {
7845 int idx_peer = 2;
7846 char base_xpath[XPATH_MAXLEN];
7847
7848 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_NUM_XPATH,
7849 argv[idx_peer]->arg, "");
7850
7851 nb_cli_enqueue_change(vty, "./local-interface", NB_OP_DESTROY, NULL);
7852
7853 return nb_cli_apply_changes(vty, base_xpath);
7854 }
7855
7856 DEFUN (neighbor_distribute_list,
7857 neighbor_distribute_list_cmd,
7858 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
7859 NEIGHBOR_STR
7860 NEIGHBOR_ADDR_STR2
7861 "Filter updates to/from this neighbor\n"
7862 "IP access-list number\n"
7863 "IP access-list number (expanded range)\n"
7864 "IP Access-list name\n"
7865 "Filter incoming updates\n"
7866 "Filter outgoing updates\n")
7867 {
7868 int idx_peer = 1;
7869 int idx_acl = 3;
7870 int direct, ret;
7871 struct peer *peer;
7872
7873 const char *pstr = argv[idx_peer]->arg;
7874 const char *acl = argv[idx_acl]->arg;
7875 const char *inout = argv[argc - 1]->text;
7876
7877 peer = peer_and_group_lookup_vty(vty, pstr);
7878 if (!peer)
7879 return CMD_WARNING_CONFIG_FAILED;
7880
7881 /* Check filter direction. */
7882 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7883 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7884 direct, acl);
7885
7886 return bgp_vty_return(vty, ret);
7887 }
7888
7889 ALIAS_HIDDEN(
7890 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
7891 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
7892 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7893 "Filter updates to/from this neighbor\n"
7894 "IP access-list number\n"
7895 "IP access-list number (expanded range)\n"
7896 "IP Access-list name\n"
7897 "Filter incoming updates\n"
7898 "Filter outgoing updates\n")
7899
7900 DEFUN (no_neighbor_distribute_list,
7901 no_neighbor_distribute_list_cmd,
7902 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
7903 NO_STR
7904 NEIGHBOR_STR
7905 NEIGHBOR_ADDR_STR2
7906 "Filter updates to/from this neighbor\n"
7907 "IP access-list number\n"
7908 "IP access-list number (expanded range)\n"
7909 "IP Access-list name\n"
7910 "Filter incoming updates\n"
7911 "Filter outgoing updates\n")
7912 {
7913 int idx_peer = 2;
7914 int direct, ret;
7915 struct peer *peer;
7916
7917 const char *pstr = argv[idx_peer]->arg;
7918 const char *inout = argv[argc - 1]->text;
7919
7920 peer = peer_and_group_lookup_vty(vty, pstr);
7921 if (!peer)
7922 return CMD_WARNING_CONFIG_FAILED;
7923
7924 /* Check filter direction. */
7925 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7926 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7927 direct);
7928
7929 return bgp_vty_return(vty, ret);
7930 }
7931
7932 ALIAS_HIDDEN(
7933 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
7934 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
7935 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7936 "Filter updates to/from this neighbor\n"
7937 "IP access-list number\n"
7938 "IP access-list number (expanded range)\n"
7939 "IP Access-list name\n"
7940 "Filter incoming updates\n"
7941 "Filter outgoing updates\n")
7942
7943 /* Set prefix list to the peer. */
7944 DEFPY_YANG(
7945 neighbor_prefix_list, neighbor_prefix_list_cmd,
7946 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor_str prefix-list WORD$prefix_str <in|out>$direction",
7947 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7948 "Filter updates to/from this neighbor\n"
7949 "Name of a prefix list\n"
7950 "Filter incoming updates\n"
7951 "Filter outgoing updates\n")
7952 {
7953 char base_xpath[XPATH_MAXLEN];
7954 char af_xpath[XPATH_MAXLEN];
7955 char plist_xpath[XPATH_MAXLEN];
7956 afi_t afi = bgp_node_afi(vty);
7957 safi_t safi = bgp_node_safi(vty);
7958
7959 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
7960 yang_afi_safi_value2identity(afi, safi));
7961 if (peer_and_group_lookup_nb(vty, neighbor_str, base_xpath,
7962 sizeof(base_xpath), af_xpath)
7963 < 0)
7964 return CMD_WARNING_CONFIG_FAILED;
7965
7966 if (strmatch(direction, "in"))
7967 snprintf(plist_xpath, sizeof(plist_xpath),
7968 "./%s/filter-config/plist-import",
7969 bgp_afi_safi_get_container_str(afi, safi));
7970 else if (strmatch(direction, "out"))
7971 snprintf(plist_xpath, sizeof(plist_xpath),
7972 "./%s/filter-config/plist-export",
7973 bgp_afi_safi_get_container_str(afi, safi));
7974
7975 if (!no)
7976 nb_cli_enqueue_change(vty, plist_xpath, NB_OP_MODIFY,
7977 prefix_str);
7978 else
7979 nb_cli_enqueue_change(vty, plist_xpath, NB_OP_DESTROY, NULL);
7980
7981 return nb_cli_apply_changes(vty, base_xpath);
7982 }
7983
7984 ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
7985 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7986 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7987 "Filter updates to/from this neighbor\n"
7988 "Name of a prefix list\n"
7989 "Filter incoming updates\n"
7990 "Filter outgoing updates\n")
7991
7992 static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7993 safi_t safi, const char *name_str,
7994 const char *direct_str)
7995 {
7996 int ret;
7997 struct peer *peer;
7998 int direct = FILTER_IN;
7999
8000 peer = peer_and_group_lookup_vty(vty, ip_str);
8001 if (!peer)
8002 return CMD_WARNING_CONFIG_FAILED;
8003
8004 /* Check filter direction. */
8005 if (strncmp(direct_str, "i", 1) == 0)
8006 direct = FILTER_IN;
8007 else if (strncmp(direct_str, "o", 1) == 0)
8008 direct = FILTER_OUT;
8009
8010 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
8011
8012 return bgp_vty_return(vty, ret);
8013 }
8014
8015 static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
8016 safi_t safi, const char *direct_str)
8017 {
8018 int ret;
8019 struct peer *peer;
8020 int direct = FILTER_IN;
8021
8022 peer = peer_and_group_lookup_vty(vty, ip_str);
8023 if (!peer)
8024 return CMD_WARNING_CONFIG_FAILED;
8025
8026 /* Check filter direction. */
8027 if (strncmp(direct_str, "i", 1) == 0)
8028 direct = FILTER_IN;
8029 else if (strncmp(direct_str, "o", 1) == 0)
8030 direct = FILTER_OUT;
8031
8032 ret = peer_aslist_unset(peer, afi, safi, direct);
8033
8034 return bgp_vty_return(vty, ret);
8035 }
8036
8037 DEFUN (neighbor_filter_list,
8038 neighbor_filter_list_cmd,
8039 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
8040 NEIGHBOR_STR
8041 NEIGHBOR_ADDR_STR2
8042 "Establish BGP filters\n"
8043 "AS path access-list name\n"
8044 "Filter incoming routes\n"
8045 "Filter outgoing routes\n")
8046 {
8047 int idx_peer = 1;
8048 int idx_word = 3;
8049 int idx_in_out = 4;
8050 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
8051 bgp_node_safi(vty), argv[idx_word]->arg,
8052 argv[idx_in_out]->arg);
8053 }
8054
8055 ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
8056 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
8057 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8058 "Establish BGP filters\n"
8059 "AS path access-list name\n"
8060 "Filter incoming routes\n"
8061 "Filter outgoing routes\n")
8062
8063 DEFUN (no_neighbor_filter_list,
8064 no_neighbor_filter_list_cmd,
8065 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
8066 NO_STR
8067 NEIGHBOR_STR
8068 NEIGHBOR_ADDR_STR2
8069 "Establish BGP filters\n"
8070 "AS path access-list name\n"
8071 "Filter incoming routes\n"
8072 "Filter outgoing routes\n")
8073 {
8074 int idx_peer = 2;
8075 int idx_in_out = 5;
8076 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
8077 bgp_node_afi(vty), bgp_node_safi(vty),
8078 argv[idx_in_out]->arg);
8079 }
8080
8081 ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
8082 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
8083 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8084 "Establish BGP filters\n"
8085 "AS path access-list name\n"
8086 "Filter incoming routes\n"
8087 "Filter outgoing routes\n")
8088
8089 /* Set advertise-map to the peer. */
8090 static int peer_advertise_map_set_vty(struct vty *vty, const char *ip_str,
8091 afi_t afi, safi_t safi,
8092 const char *advertise_str,
8093 const char *condition_str, bool condition,
8094 bool set)
8095 {
8096 int ret = CMD_WARNING_CONFIG_FAILED;
8097 struct peer *peer;
8098 struct route_map *advertise_map;
8099 struct route_map *condition_map;
8100
8101 peer = peer_and_group_lookup_vty(vty, ip_str);
8102 if (!peer)
8103 return ret;
8104
8105 condition_map = route_map_lookup_warn_noexist(vty, condition_str);
8106 advertise_map = route_map_lookup_warn_noexist(vty, advertise_str);
8107
8108 if (set)
8109 ret = peer_advertise_map_set(peer, afi, safi, advertise_str,
8110 advertise_map, condition_str,
8111 condition_map, condition);
8112 else
8113 ret = peer_advertise_map_unset(peer, afi, safi, advertise_str,
8114 advertise_map, condition_str,
8115 condition_map, condition);
8116
8117 return bgp_vty_return(vty, ret);
8118 }
8119
8120 DEFPY (neighbor_advertise_map,
8121 neighbor_advertise_map_cmd,
8122 "[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",
8123 NO_STR
8124 NEIGHBOR_STR
8125 NEIGHBOR_ADDR_STR2
8126 "Route-map to conditionally advertise routes\n"
8127 "Name of advertise map\n"
8128 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
8129 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
8130 "Name of the exist or non exist map\n")
8131 {
8132 bool condition = CONDITION_EXIST;
8133
8134 if (!strcmp(exist, "non-exist-map"))
8135 condition = CONDITION_NON_EXIST;
8136
8137 return peer_advertise_map_set_vty(vty, neighbor, bgp_node_afi(vty),
8138 bgp_node_safi(vty), advertise_str,
8139 condition_str, condition, !no);
8140 }
8141
8142 ALIAS_HIDDEN(neighbor_advertise_map, neighbor_advertise_map_hidden_cmd,
8143 "[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",
8144 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8145 "Route-map to conditionally advertise routes\n"
8146 "Name of advertise map\n"
8147 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
8148 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
8149 "Name of the exist or non exist map\n")
8150
8151 /* Set route-map to the peer. */
8152 DEFPY_YANG(
8153 neighbor_route_map, neighbor_route_map_cmd,
8154 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor_str route-map WORD$rmap_str <in|out>$direction",
8155 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8156 "Apply route map to neighbor\n"
8157 "Name of route map\n"
8158 "Apply map to incoming routes\n"
8159 "Apply map to outbound routes\n")
8160 {
8161 char base_xpath[XPATH_MAXLEN];
8162 char af_xpath[XPATH_MAXLEN];
8163 char rmap_xpath[XPATH_MAXLEN];
8164 afi_t afi = bgp_node_afi(vty);
8165 safi_t safi = bgp_node_safi(vty);
8166
8167 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8168 yang_afi_safi_value2identity(afi, safi));
8169 if (peer_and_group_lookup_nb(vty, neighbor_str, base_xpath,
8170 sizeof(base_xpath), af_xpath)
8171 < 0)
8172 return CMD_WARNING_CONFIG_FAILED;
8173
8174 if (strmatch(direction, "in"))
8175 snprintf(rmap_xpath, sizeof(rmap_xpath),
8176 "./%s/filter-config/rmap-import",
8177 bgp_afi_safi_get_container_str(afi, safi));
8178 else if (strmatch(direction, "out"))
8179 snprintf(rmap_xpath, sizeof(rmap_xpath),
8180 "./%s/filter-config/rmap-export",
8181 bgp_afi_safi_get_container_str(afi, safi));
8182
8183 if (!no) {
8184 if (!yang_dnode_existsf(
8185 vty->candidate_config->dnode,
8186 "/frr-route-map:lib/route-map[name='%s']",
8187 rmap_str)) {
8188 if (vty_shell_serv(vty))
8189 vty_out(vty,
8190 "The route-map '%s' does not exist.\n",
8191 rmap_str);
8192 }
8193 nb_cli_enqueue_change(vty, rmap_xpath, NB_OP_MODIFY, rmap_str);
8194 } else
8195 nb_cli_enqueue_change(vty, rmap_xpath, NB_OP_DESTROY, NULL);
8196
8197 return nb_cli_apply_changes(vty, base_xpath);
8198 }
8199
8200 /* Set unsuppress-map to the peer. */
8201 static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
8202 afi_t afi, safi_t safi,
8203 const char *name_str)
8204 {
8205 int ret;
8206 struct peer *peer;
8207 struct route_map *route_map;
8208
8209 peer = peer_and_group_lookup_vty(vty, ip_str);
8210 if (!peer)
8211 return CMD_WARNING_CONFIG_FAILED;
8212
8213 route_map = route_map_lookup_warn_noexist(vty, name_str);
8214 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
8215
8216 return bgp_vty_return(vty, ret);
8217 }
8218
8219 /* Unset route-map from the peer. */
8220 static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
8221 afi_t afi, safi_t safi)
8222 {
8223 int ret;
8224 struct peer *peer;
8225
8226 peer = peer_and_group_lookup_vty(vty, ip_str);
8227 if (!peer)
8228 return CMD_WARNING_CONFIG_FAILED;
8229
8230 ret = peer_unsuppress_map_unset(peer, afi, safi);
8231
8232 return bgp_vty_return(vty, ret);
8233 }
8234
8235 DEFUN (neighbor_unsuppress_map,
8236 neighbor_unsuppress_map_cmd,
8237 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8238 NEIGHBOR_STR
8239 NEIGHBOR_ADDR_STR2
8240 "Route-map to selectively unsuppress suppressed routes\n"
8241 "Name of route map\n")
8242 {
8243 int idx_peer = 1;
8244 int idx_word = 3;
8245 return peer_unsuppress_map_set_vty(
8246 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8247 argv[idx_word]->arg);
8248 }
8249
8250 ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
8251 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8252 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8253 "Route-map to selectively unsuppress suppressed routes\n"
8254 "Name of route map\n")
8255
8256 DEFUN (no_neighbor_unsuppress_map,
8257 no_neighbor_unsuppress_map_cmd,
8258 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8259 NO_STR
8260 NEIGHBOR_STR
8261 NEIGHBOR_ADDR_STR2
8262 "Route-map to selectively unsuppress suppressed routes\n"
8263 "Name of route map\n")
8264 {
8265 int idx_peer = 2;
8266 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
8267 bgp_node_afi(vty),
8268 bgp_node_safi(vty));
8269 }
8270
8271 ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
8272 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8273 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8274 "Route-map to selectively unsuppress suppressed routes\n"
8275 "Name of route map\n")
8276
8277 /* Maximum number of prefix to be sent to the neighbor. */
8278 DEFUN_YANG(neighbor_maximum_prefix_out,
8279 neighbor_maximum_prefix_out_cmd,
8280 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out (1-4294967295)",
8281 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8282 "Maximum number of prefixes to be sent to this peer\n"
8283 "Maximum no. of prefix limit\n")
8284 {
8285 char base_xpath[XPATH_MAXLEN];
8286 char af_xpath[XPATH_MAXLEN];
8287 char attr_xpath[XPATH_MAXLEN];
8288 int idx_peer = 1;
8289 int idx_number = 3;
8290 afi_t afi = bgp_node_afi(vty);
8291 safi_t safi = bgp_node_safi(vty);
8292
8293 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8294 yang_afi_safi_value2identity(afi, safi));
8295 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8296 sizeof(base_xpath), af_xpath)
8297 < 0)
8298 return CMD_WARNING_CONFIG_FAILED;
8299
8300 snprintf(attr_xpath, sizeof(attr_xpath),
8301 "/%s/prefix-limit/direction-list[direction='out']",
8302 bgp_afi_safi_get_container_str(afi, safi));
8303 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8304
8305 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8306
8307 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8308 argv[idx_number]->arg);
8309
8310 return nb_cli_apply_changes(vty, base_xpath);
8311 }
8312
8313 DEFUN_YANG(no_neighbor_maximum_prefix_out,
8314 no_neighbor_maximum_prefix_out_cmd,
8315 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out",
8316 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8317 "Maximum number of prefixes to be sent to this peer\n")
8318 {
8319 char base_xpath[XPATH_MAXLEN];
8320 char af_xpath[XPATH_MAXLEN];
8321 char attr_xpath[XPATH_MAXLEN];
8322 int idx_peer = 2;
8323 afi_t afi = bgp_node_afi(vty);
8324 safi_t safi = bgp_node_safi(vty);
8325
8326 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8327 yang_afi_safi_value2identity(afi, safi));
8328 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8329 sizeof(base_xpath), af_xpath)
8330 < 0)
8331 return CMD_WARNING_CONFIG_FAILED;
8332
8333 snprintf(attr_xpath, sizeof(attr_xpath),
8334 "/%s/prefix-limit/direction-list[direction='out']",
8335 bgp_afi_safi_get_container_str(afi, safi));
8336 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8337
8338 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
8339
8340 return nb_cli_apply_changes(vty, base_xpath);
8341 }
8342
8343 /* Maximum number of prefix configuration. Prefix count is different
8344 for each peer configuration. So this configuration can be set for
8345 each peer configuration. */
8346 DEFUN_YANG(neighbor_maximum_prefix,
8347 neighbor_maximum_prefix_cmd,
8348 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
8349 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8350 "Maximum number of prefix accept from this peer\n"
8351 "maximum no. of prefix limit\n"
8352 "Force checking all received routes not only accepted\n")
8353 {
8354 int idx_peer = 1;
8355 int idx_number = 3;
8356 int idx_force = 0;
8357 char base_xpath[XPATH_MAXLEN];
8358 char af_xpath[XPATH_MAXLEN];
8359 char attr_xpath[XPATH_MAXLEN];
8360 afi_t afi = bgp_node_afi(vty);
8361 safi_t safi = bgp_node_safi(vty);
8362
8363 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8364 yang_afi_safi_value2identity(afi, safi));
8365 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8366 sizeof(base_xpath), af_xpath)
8367 < 0)
8368 return CMD_WARNING_CONFIG_FAILED;
8369
8370 snprintf(attr_xpath, sizeof(attr_xpath),
8371 "/%s/prefix-limit/direction-list[direction='in']",
8372 bgp_afi_safi_get_container_str(afi, safi));
8373 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8374
8375 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8376
8377 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8378 argv[idx_number]->arg);
8379 if (argv_find(argv, argc, "force", &idx_force))
8380 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8381 "true");
8382
8383 return nb_cli_apply_changes(vty, base_xpath);
8384 }
8385
8386 ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
8387 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
8388 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8389 "Maximum number of prefix accept from this peer\n"
8390 "maximum no. of prefix limit\n"
8391 "Force checking all received routes not only accepted\n")
8392
8393 DEFUN_YANG(neighbor_maximum_prefix_threshold,
8394 neighbor_maximum_prefix_threshold_cmd,
8395 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
8396 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8397 "Maximum number of prefix accept from this peer\n"
8398 "maximum no. of prefix limit\n"
8399 "Threshold value (%) at which to generate a warning msg\n"
8400 "Force checking all received routes not only accepted\n")
8401 {
8402 int idx_peer = 1;
8403 int idx_number = 3;
8404 int idx_number_2 = 4;
8405 int idx_force = 0;
8406 char base_xpath[XPATH_MAXLEN];
8407 char af_xpath[XPATH_MAXLEN];
8408 char attr_xpath[XPATH_MAXLEN];
8409 afi_t afi = bgp_node_afi(vty);
8410 safi_t safi = bgp_node_safi(vty);
8411
8412 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8413 yang_afi_safi_value2identity(afi, safi));
8414 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8415 sizeof(base_xpath), af_xpath)
8416 < 0)
8417 return CMD_WARNING_CONFIG_FAILED;
8418
8419 snprintf(attr_xpath, sizeof(attr_xpath),
8420 "/%s/prefix-limit/direction-list[direction='in']",
8421 bgp_afi_safi_get_container_str(afi, safi));
8422 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8423
8424 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8425
8426 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8427 argv[idx_number]->arg);
8428
8429 nb_cli_enqueue_change(vty, "./options/shutdown-threshold-pct",
8430 NB_OP_MODIFY, argv[idx_number_2]->arg);
8431
8432 if (argv_find(argv, argc, "force", &idx_force))
8433 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8434 "true");
8435
8436 return nb_cli_apply_changes(vty, base_xpath);
8437 }
8438
8439 ALIAS_HIDDEN(
8440 neighbor_maximum_prefix_threshold,
8441 neighbor_maximum_prefix_threshold_hidden_cmd,
8442 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
8443 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8444 "Maximum number of prefix accept from this peer\n"
8445 "maximum no. of prefix limit\n"
8446 "Threshold value (%) at which to generate a warning msg\n"
8447 "Force checking all received routes not only accepted\n")
8448
8449 DEFUN_YANG(neighbor_maximum_prefix_warning,
8450 neighbor_maximum_prefix_warning_cmd,
8451 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
8452 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8453 "Maximum number of prefix accept from this peer\n"
8454 "maximum no. of prefix limit\n"
8455 "Only give warning message when limit is exceeded\n"
8456 "Force checking all received routes not only accepted\n")
8457 {
8458 int idx_peer = 1;
8459 int idx_number = 3;
8460 int idx_force = 0;
8461 char base_xpath[XPATH_MAXLEN];
8462 char af_xpath[XPATH_MAXLEN];
8463 char attr_xpath[XPATH_MAXLEN];
8464 afi_t afi = bgp_node_afi(vty);
8465 safi_t safi = bgp_node_safi(vty);
8466
8467 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8468 yang_afi_safi_value2identity(afi, safi));
8469 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8470 sizeof(base_xpath), af_xpath)
8471 < 0)
8472 return CMD_WARNING_CONFIG_FAILED;
8473
8474 snprintf(attr_xpath, sizeof(attr_xpath),
8475 "/%s/prefix-limit/direction-list[direction='in']",
8476 bgp_afi_safi_get_container_str(afi, safi));
8477 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8478
8479 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8480
8481 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8482 argv[idx_number]->arg);
8483
8484 nb_cli_enqueue_change(vty, "./options/warning-only", NB_OP_MODIFY,
8485 "true");
8486 if (argv_find(argv, argc, "force", &idx_force))
8487 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8488 "true");
8489
8490 return nb_cli_apply_changes(vty, base_xpath);
8491 }
8492
8493 ALIAS_HIDDEN(
8494 neighbor_maximum_prefix_warning,
8495 neighbor_maximum_prefix_warning_hidden_cmd,
8496 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
8497 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8498 "Maximum number of prefix accept from this peer\n"
8499 "maximum no. of prefix limit\n"
8500 "Only give warning message when limit is exceeded\n"
8501 "Force checking all received routes not only accepted\n")
8502
8503 DEFUN_YANG(neighbor_maximum_prefix_threshold_warning,
8504 neighbor_maximum_prefix_threshold_warning_cmd,
8505 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
8506 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8507 "Maximum number of prefix accept from this peer\n"
8508 "maximum no. of prefix limit\n"
8509 "Threshold value (%) at which to generate a warning msg\n"
8510 "Only give warning message when limit is exceeded\n"
8511 "Force checking all received routes not only accepted\n")
8512 {
8513 int idx_peer = 1;
8514 int idx_number = 3;
8515 int idx_number_2 = 4;
8516 int idx_force = 0;
8517 char base_xpath[XPATH_MAXLEN];
8518 char af_xpath[XPATH_MAXLEN];
8519 char attr_xpath[XPATH_MAXLEN];
8520 afi_t afi = bgp_node_afi(vty);
8521 safi_t safi = bgp_node_safi(vty);
8522
8523 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8524 yang_afi_safi_value2identity(afi, safi));
8525 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8526 sizeof(base_xpath), af_xpath)
8527 < 0)
8528 return CMD_WARNING_CONFIG_FAILED;
8529
8530 snprintf(attr_xpath, sizeof(attr_xpath),
8531 "/%s/prefix-limit/direction-list[direction='in']",
8532 bgp_afi_safi_get_container_str(afi, safi));
8533 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8534
8535 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8536
8537 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8538 argv[idx_number]->arg);
8539 nb_cli_enqueue_change(vty, "./options/tw-shutdown-threshold-pct",
8540 NB_OP_MODIFY, argv[idx_number_2]->arg);
8541 nb_cli_enqueue_change(vty, "./options/tw-warning-only", NB_OP_MODIFY,
8542 "true");
8543 if (argv_find(argv, argc, "force", &idx_force))
8544 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8545 "true");
8546
8547 return nb_cli_apply_changes(vty, base_xpath);
8548 }
8549
8550 ALIAS_HIDDEN(
8551 neighbor_maximum_prefix_threshold_warning,
8552 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
8553 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
8554 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8555 "Maximum number of prefix accept from this peer\n"
8556 "maximum no. of prefix limit\n"
8557 "Threshold value (%) at which to generate a warning msg\n"
8558 "Only give warning message when limit is exceeded\n"
8559 "Force checking all received routes not only accepted\n")
8560
8561 DEFUN_YANG(neighbor_maximum_prefix_restart,
8562 neighbor_maximum_prefix_restart_cmd,
8563 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8564 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8565 "Maximum number of prefix accept from this peer\n"
8566 "maximum no. of prefix limit\n"
8567 "Restart bgp connection after limit is exceeded\n"
8568 "Restart interval in minutes\n"
8569 "Force checking all received routes not only accepted\n")
8570 {
8571 int idx_peer = 1;
8572 int idx_number = 3;
8573 int idx_number_2 = 5;
8574 int idx_force = 0;
8575 char base_xpath[XPATH_MAXLEN];
8576 char af_xpath[XPATH_MAXLEN];
8577 char attr_xpath[XPATH_MAXLEN];
8578 afi_t afi = bgp_node_afi(vty);
8579 safi_t safi = bgp_node_safi(vty);
8580
8581 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8582 yang_afi_safi_value2identity(afi, safi));
8583 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8584 sizeof(base_xpath), af_xpath)
8585 < 0)
8586 return CMD_WARNING_CONFIG_FAILED;
8587
8588 snprintf(attr_xpath, sizeof(attr_xpath),
8589 "/%s/prefix-limit/direction-list[direction='in']",
8590 bgp_afi_safi_get_container_str(afi, safi));
8591 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8592
8593 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8594
8595 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8596 argv[idx_number]->arg);
8597 nb_cli_enqueue_change(vty, "./options/restart-timer", NB_OP_MODIFY,
8598 argv[idx_number_2]->arg);
8599 if (argv_find(argv, argc, "force", &idx_force))
8600 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8601 "true");
8602
8603 return nb_cli_apply_changes(vty, base_xpath);
8604 }
8605
8606 ALIAS_HIDDEN(
8607 neighbor_maximum_prefix_restart,
8608 neighbor_maximum_prefix_restart_hidden_cmd,
8609 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8610 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8611 "Maximum number of prefix accept from this peer\n"
8612 "maximum no. of prefix limit\n"
8613 "Restart bgp connection after limit is exceeded\n"
8614 "Restart interval in minutes\n"
8615 "Force checking all received routes not only accepted\n")
8616
8617 DEFUN_YANG(neighbor_maximum_prefix_threshold_restart,
8618 neighbor_maximum_prefix_threshold_restart_cmd,
8619 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8620 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8621 "Maximum number of prefixes to accept from this peer\n"
8622 "maximum no. of prefix limit\n"
8623 "Threshold value (%) at which to generate a warning msg\n"
8624 "Restart bgp connection after limit is exceeded\n"
8625 "Restart interval in minutes\n"
8626 "Force checking all received routes not only accepted\n")
8627 {
8628 int idx_peer = 1;
8629 int idx_number = 3;
8630 int idx_number_2 = 4;
8631 int idx_number_3 = 6;
8632 int idx_force = 0;
8633 char base_xpath[XPATH_MAXLEN];
8634 char af_xpath[XPATH_MAXLEN];
8635 char attr_xpath[XPATH_MAXLEN];
8636 afi_t afi = bgp_node_afi(vty);
8637 safi_t safi = bgp_node_safi(vty);
8638
8639 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8640 yang_afi_safi_value2identity(afi, safi));
8641 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8642 sizeof(base_xpath), af_xpath)
8643 < 0)
8644 return CMD_WARNING_CONFIG_FAILED;
8645
8646 snprintf(attr_xpath, sizeof(attr_xpath),
8647 "/%s/prefix-limit/direction-list[direction='in']",
8648 bgp_afi_safi_get_container_str(afi, safi));
8649 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8650
8651 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8652
8653 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8654 argv[idx_number]->arg);
8655 nb_cli_enqueue_change(vty, "./options/tr-shutdown-threshold-pct",
8656 NB_OP_MODIFY, argv[idx_number_2]->arg);
8657 nb_cli_enqueue_change(vty, "./options/tr-restart-timer", NB_OP_MODIFY,
8658 argv[idx_number_3]->arg);
8659 if (argv_find(argv, argc, "force", &idx_force))
8660 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8661 "true");
8662
8663 return nb_cli_apply_changes(vty, base_xpath);
8664 }
8665
8666 ALIAS_HIDDEN(
8667 neighbor_maximum_prefix_threshold_restart,
8668 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
8669 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8670 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8671 "Maximum number of prefixes to accept from this peer\n"
8672 "maximum no. of prefix limit\n"
8673 "Threshold value (%) at which to generate a warning msg\n"
8674 "Restart bgp connection after limit is exceeded\n"
8675 "Restart interval in minutes\n"
8676 "Force checking all received routes not only accepted\n")
8677
8678 DEFUN_YANG(no_neighbor_maximum_prefix,
8679 no_neighbor_maximum_prefix_cmd,
8680 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8681 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8682 "Maximum number of prefixes to accept from this peer\n"
8683 "maximum no. of prefix limit\n"
8684 "Threshold value (%) at which to generate a warning msg\n"
8685 "Restart bgp connection after limit is exceeded\n"
8686 "Restart interval in minutes\n"
8687 "Only give warning message when limit is exceeded\n"
8688 "Force checking all received routes not only accepted\n")
8689 {
8690 int idx_peer = 2;
8691 char base_xpath[XPATH_MAXLEN];
8692 char af_xpath[XPATH_MAXLEN];
8693 char attr_xpath[XPATH_MAXLEN];
8694 afi_t afi = bgp_node_afi(vty);
8695 safi_t safi = bgp_node_safi(vty);
8696
8697 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8698 yang_afi_safi_value2identity(afi, safi));
8699 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8700 sizeof(base_xpath), af_xpath)
8701 < 0)
8702 return CMD_WARNING_CONFIG_FAILED;
8703
8704 snprintf(attr_xpath, sizeof(attr_xpath),
8705 "/%s/prefix-limit/direction-list[direction='in']",
8706 bgp_afi_safi_get_container_str(afi, safi));
8707 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8708
8709 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
8710
8711 return nb_cli_apply_changes(vty, base_xpath);
8712 }
8713
8714 ALIAS_HIDDEN(
8715 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
8716 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8717 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8718 "Maximum number of prefixes to accept from this peer\n"
8719 "maximum no. of prefix limit\n"
8720 "Threshold value (%) at which to generate a warning msg\n"
8721 "Restart bgp connection after limit is exceeded\n"
8722 "Restart interval in minutes\n"
8723 "Only give warning message when limit is exceeded\n"
8724 "Force checking all received routes not only accepted\n")
8725
8726
8727 /* "neighbor allowas-in" */
8728 DEFUN (neighbor_allowas_in,
8729 neighbor_allowas_in_cmd,
8730 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8731 NEIGHBOR_STR
8732 NEIGHBOR_ADDR_STR2
8733 "Accept as-path with my AS present in it\n"
8734 "Number of occurrences of AS number\n"
8735 "Only accept my AS in the as-path if the route was originated in my AS\n")
8736 {
8737 int idx_peer = 1;
8738 int idx_number_origin = 3;
8739 int ret;
8740 int origin = 0;
8741 struct peer *peer;
8742 int allow_num = 0;
8743
8744 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8745 if (!peer)
8746 return CMD_WARNING_CONFIG_FAILED;
8747
8748 if (argc <= idx_number_origin)
8749 allow_num = 3;
8750 else {
8751 if (argv[idx_number_origin]->type == WORD_TKN)
8752 origin = 1;
8753 else
8754 allow_num = atoi(argv[idx_number_origin]->arg);
8755 }
8756
8757 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8758 allow_num, origin);
8759
8760 return bgp_vty_return(vty, ret);
8761 }
8762
8763 ALIAS_HIDDEN(
8764 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
8765 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8766 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8767 "Accept as-path with my AS present in it\n"
8768 "Number of occurrences of AS number\n"
8769 "Only accept my AS in the as-path if the route was originated in my AS\n")
8770
8771 DEFUN (no_neighbor_allowas_in,
8772 no_neighbor_allowas_in_cmd,
8773 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8774 NO_STR
8775 NEIGHBOR_STR
8776 NEIGHBOR_ADDR_STR2
8777 "allow local ASN appears in aspath attribute\n"
8778 "Number of occurrences of AS number\n"
8779 "Only accept my AS in the as-path if the route was originated in my AS\n")
8780 {
8781 int idx_peer = 2;
8782 int ret;
8783 struct peer *peer;
8784
8785 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8786 if (!peer)
8787 return CMD_WARNING_CONFIG_FAILED;
8788
8789 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
8790 bgp_node_safi(vty));
8791
8792 return bgp_vty_return(vty, ret);
8793 }
8794
8795 ALIAS_HIDDEN(
8796 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
8797 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8798 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8799 "allow local ASN appears in aspath attribute\n"
8800 "Number of occurrences of AS number\n"
8801 "Only accept my AS in the as-path if the route was originated in my AS\n")
8802
8803 DEFUN_YANG (neighbor_ttl_security,
8804 neighbor_ttl_security_cmd,
8805 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8806 NEIGHBOR_STR
8807 NEIGHBOR_ADDR_STR2
8808 "BGP ttl-security parameters\n"
8809 "Specify the maximum number of hops to the BGP peer\n"
8810 "Number of hops to BGP peer\n")
8811 {
8812 int idx_peer = 1;
8813 int idx_number = 4;
8814 char base_xpath[XPATH_MAXLEN];
8815
8816 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8817 sizeof(base_xpath), NULL)
8818 < 0)
8819 return CMD_WARNING_CONFIG_FAILED;
8820
8821 nb_cli_enqueue_change(vty, "./ttl-security", NB_OP_MODIFY,
8822 argv[idx_number]->arg);
8823
8824 return nb_cli_apply_changes(vty, base_xpath);
8825 }
8826
8827 DEFUN_YANG(no_neighbor_ttl_security,
8828 no_neighbor_ttl_security_cmd,
8829 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8830 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8831 "BGP ttl-security parameters\n"
8832 "Specify the maximum number of hops to the BGP peer\n"
8833 "Number of hops to BGP peer\n")
8834 {
8835 int idx_peer = 2;
8836 char base_xpath[XPATH_MAXLEN];
8837
8838 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8839 sizeof(base_xpath), NULL)
8840 < 0)
8841 return CMD_WARNING_CONFIG_FAILED;
8842
8843 nb_cli_enqueue_change(vty, "./ttl-security", NB_OP_DESTROY, NULL);
8844
8845 return nb_cli_apply_changes(vty, base_xpath);
8846 }
8847
8848 DEFUN (neighbor_addpath_tx_all_paths,
8849 neighbor_addpath_tx_all_paths_cmd,
8850 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8851 NEIGHBOR_STR
8852 NEIGHBOR_ADDR_STR2
8853 "Use addpath to advertise all paths to a neighbor\n")
8854 {
8855 int idx_peer = 1;
8856 struct peer *peer;
8857
8858 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8859 if (!peer)
8860 return CMD_WARNING_CONFIG_FAILED;
8861
8862 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8863 BGP_ADDPATH_ALL);
8864 return CMD_SUCCESS;
8865 }
8866
8867 ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
8868 neighbor_addpath_tx_all_paths_hidden_cmd,
8869 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8870 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8871 "Use addpath to advertise all paths to a neighbor\n")
8872
8873 DEFUN (no_neighbor_addpath_tx_all_paths,
8874 no_neighbor_addpath_tx_all_paths_cmd,
8875 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8876 NO_STR
8877 NEIGHBOR_STR
8878 NEIGHBOR_ADDR_STR2
8879 "Use addpath to advertise all paths to a neighbor\n")
8880 {
8881 int idx_peer = 2;
8882 struct peer *peer;
8883
8884 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8885 if (!peer)
8886 return CMD_WARNING_CONFIG_FAILED;
8887
8888 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8889 != BGP_ADDPATH_ALL) {
8890 vty_out(vty,
8891 "%% Peer not currently configured to transmit all paths.");
8892 return CMD_WARNING_CONFIG_FAILED;
8893 }
8894
8895 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8896 BGP_ADDPATH_NONE);
8897
8898 return CMD_SUCCESS;
8899 }
8900
8901 ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
8902 no_neighbor_addpath_tx_all_paths_hidden_cmd,
8903 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8904 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8905 "Use addpath to advertise all paths to a neighbor\n")
8906
8907 DEFUN (neighbor_addpath_tx_bestpath_per_as,
8908 neighbor_addpath_tx_bestpath_per_as_cmd,
8909 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8910 NEIGHBOR_STR
8911 NEIGHBOR_ADDR_STR2
8912 "Use addpath to advertise the bestpath per each neighboring AS\n")
8913 {
8914 int idx_peer = 1;
8915 struct peer *peer;
8916
8917 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8918 if (!peer)
8919 return CMD_WARNING_CONFIG_FAILED;
8920
8921 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8922 BGP_ADDPATH_BEST_PER_AS);
8923
8924 return CMD_SUCCESS;
8925 }
8926
8927 ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
8928 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8929 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8930 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8931 "Use addpath to advertise the bestpath per each neighboring AS\n")
8932
8933 DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
8934 no_neighbor_addpath_tx_bestpath_per_as_cmd,
8935 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8936 NO_STR
8937 NEIGHBOR_STR
8938 NEIGHBOR_ADDR_STR2
8939 "Use addpath to advertise the bestpath per each neighboring AS\n")
8940 {
8941 int idx_peer = 2;
8942 struct peer *peer;
8943
8944 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8945 if (!peer)
8946 return CMD_WARNING_CONFIG_FAILED;
8947
8948 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8949 != BGP_ADDPATH_BEST_PER_AS) {
8950 vty_out(vty,
8951 "%% Peer not currently configured to transmit all best path per as.");
8952 return CMD_WARNING_CONFIG_FAILED;
8953 }
8954
8955 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8956 BGP_ADDPATH_NONE);
8957
8958 return CMD_SUCCESS;
8959 }
8960
8961 ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
8962 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8963 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8964 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8965 "Use addpath to advertise the bestpath per each neighboring AS\n")
8966
8967 DEFPY(
8968 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
8969 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8970 NEIGHBOR_STR
8971 NEIGHBOR_ADDR_STR2
8972 "Detect AS loops before sending to neighbor\n")
8973 {
8974 struct peer *peer;
8975
8976 peer = peer_and_group_lookup_vty(vty, neighbor);
8977 if (!peer)
8978 return CMD_WARNING_CONFIG_FAILED;
8979
8980 peer->as_path_loop_detection = true;
8981
8982 return CMD_SUCCESS;
8983 }
8984
8985 DEFPY(
8986 no_neighbor_aspath_loop_detection,
8987 no_neighbor_aspath_loop_detection_cmd,
8988 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8989 NO_STR
8990 NEIGHBOR_STR
8991 NEIGHBOR_ADDR_STR2
8992 "Detect AS loops before sending to neighbor\n")
8993 {
8994 struct peer *peer;
8995
8996 peer = peer_and_group_lookup_vty(vty, neighbor);
8997 if (!peer)
8998 return CMD_WARNING_CONFIG_FAILED;
8999
9000 peer->as_path_loop_detection = false;
9001
9002 return CMD_SUCCESS;
9003 }
9004
9005 DEFPY(neighbor_damp,
9006 neighbor_damp_cmd,
9007 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor dampening [(1-45)$half [(1-20000)$reuse (1-20000)$suppress (1-255)$max]]",
9008 NEIGHBOR_STR
9009 NEIGHBOR_ADDR_STR2
9010 "Enable neighbor route-flap dampening\n"
9011 "Half-life time for the penalty\n"
9012 "Value to start reusing a route\n"
9013 "Value to start suppressing a route\n"
9014 "Maximum duration to suppress a stable route\n")
9015 {
9016 struct peer *peer = peer_and_group_lookup_vty(vty, neighbor);
9017
9018 if (!peer)
9019 return CMD_WARNING_CONFIG_FAILED;
9020 if (!half)
9021 half = DEFAULT_HALF_LIFE;
9022 if (!reuse) {
9023 reuse = DEFAULT_REUSE;
9024 suppress = DEFAULT_SUPPRESS;
9025 max = half * 4;
9026 }
9027 if (suppress < reuse) {
9028 vty_out(vty,
9029 "Suppress value cannot be less than reuse value\n");
9030 return CMD_WARNING_CONFIG_FAILED;
9031 }
9032 bgp_peer_damp_enable(peer, bgp_node_afi(vty), bgp_node_safi(vty),
9033 half * 60, reuse, suppress, max * 60);
9034 return CMD_SUCCESS;
9035 }
9036
9037 DEFPY(no_neighbor_damp,
9038 no_neighbor_damp_cmd,
9039 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor dampening [HALF [REUSE SUPPRESS MAX]]",
9040 NO_STR
9041 NEIGHBOR_STR
9042 NEIGHBOR_ADDR_STR2
9043 "Enable neighbor route-flap dampening\n"
9044 "Half-life time for the penalty\n"
9045 "Value to start reusing a route\n"
9046 "Value to start suppressing a route\n"
9047 "Maximum duration to suppress a stable route\n")
9048 {
9049 struct peer *peer = peer_and_group_lookup_vty(vty, neighbor);
9050
9051 if (!peer)
9052 return CMD_WARNING_CONFIG_FAILED;
9053 bgp_peer_damp_disable(peer, bgp_node_afi(vty), bgp_node_safi(vty));
9054 return CMD_SUCCESS;
9055 }
9056
9057 DEFPY (show_ip_bgp_neighbor_damp_param,
9058 show_ip_bgp_neighbor_damp_param_cmd,
9059 "show [ip] bgp [<ipv4|ipv6> [unicast]] neighbors <A.B.C.D|X:X::X:X|WORD>$neighbor dampening parameters [json]$json",
9060 SHOW_STR
9061 IP_STR
9062 BGP_STR
9063 BGP_AFI_HELP_STR
9064 "Address Family modifier\n"
9065 NEIGHBOR_STR
9066 NEIGHBOR_ADDR_STR2
9067 "Neighbor route-flap dampening information\n"
9068 "Display detail of configured dampening parameters\n"
9069 JSON_STR)
9070 {
9071 bool use_json = false;
9072 int idx = 0;
9073 afi_t afi = AFI_IP;
9074 safi_t safi = SAFI_UNICAST;
9075 struct peer *peer;
9076
9077 if (argv_find(argv, argc, "ip", &idx))
9078 afi = AFI_IP;
9079 if (argv_find(argv, argc, "ipv4", &idx))
9080 afi = AFI_IP;
9081 if (argv_find(argv, argc, "ipv6", &idx))
9082 afi = AFI_IP6;
9083 peer = peer_and_group_lookup_vty(vty, neighbor);
9084 if (!peer)
9085 return CMD_WARNING;
9086 if (json)
9087 use_json = true;
9088 bgp_show_peer_dampening_parameters(vty, peer, afi, safi, use_json);
9089 return CMD_SUCCESS;
9090 }
9091
9092 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
9093 struct ecommunity **list, bool is_rt6)
9094 {
9095 struct ecommunity *ecom = NULL;
9096 struct ecommunity *ecomadd;
9097
9098 for (; argc; --argc, ++argv) {
9099 if (is_rt6)
9100 ecomadd = ecommunity_str2com_ipv6(argv[0]->arg,
9101 ECOMMUNITY_ROUTE_TARGET,
9102 0);
9103 else
9104 ecomadd = ecommunity_str2com(argv[0]->arg,
9105 ECOMMUNITY_ROUTE_TARGET,
9106 0);
9107 if (!ecomadd) {
9108 vty_out(vty, "Malformed community-list value\n");
9109 if (ecom)
9110 ecommunity_free(&ecom);
9111 return CMD_WARNING_CONFIG_FAILED;
9112 }
9113
9114 if (ecom) {
9115 ecommunity_merge(ecom, ecomadd);
9116 ecommunity_free(&ecomadd);
9117 } else {
9118 ecom = ecomadd;
9119 }
9120 }
9121
9122 if (*list) {
9123 ecommunity_free(&*list);
9124 }
9125 *list = ecom;
9126
9127 return CMD_SUCCESS;
9128 }
9129
9130 bool vpn_policy_check_import(struct bgp *bgp, afi_t afi, safi_t safi,
9131 bool v2vimport, char *errmsg, size_t errmsg_len)
9132 {
9133 if (!v2vimport) {
9134 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9135 BGP_CONFIG_VRF_TO_VRF_IMPORT)
9136 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9137 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
9138 snprintf(
9139 errmsg, errmsg_len, "%s",
9140 "%% error: Please unconfigure import vrf commands before using vpn commands");
9141 return false;
9142 }
9143 } else {
9144 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9145 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
9146 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9147 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
9148 snprintf(
9149 errmsg, errmsg_len, "%s",
9150 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands");
9151 return false;
9152 }
9153 }
9154 return true;
9155 }
9156
9157 /*
9158 * v2vimport is true if we are handling a `import vrf ...` command
9159 */
9160 static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
9161 {
9162 afi_t afi;
9163
9164 switch (vty->node) {
9165 case BGP_IPV4_NODE:
9166 afi = AFI_IP;
9167 break;
9168 case BGP_IPV6_NODE:
9169 afi = AFI_IP6;
9170 break;
9171 default:
9172 vty_out(vty,
9173 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
9174 return AFI_MAX;
9175 }
9176
9177 if (!v2vimport) {
9178 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9179 BGP_CONFIG_VRF_TO_VRF_IMPORT)
9180 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9181 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
9182 vty_out(vty,
9183 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
9184 return AFI_MAX;
9185 }
9186 } else {
9187 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9188 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
9189 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9190 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
9191 vty_out(vty,
9192 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
9193 return AFI_MAX;
9194 }
9195 }
9196 return afi;
9197 }
9198
9199 DEFPY_YANG(
9200 af_rd_vpn_export,
9201 af_rd_vpn_export_cmd,
9202 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
9203 NO_STR
9204 "Specify route distinguisher\n"
9205 "Between current address-family and vpn\n"
9206 "For routes leaked from current address-family to vpn\n"
9207 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
9208 {
9209 char base_xpath[XPATH_MAXLEN];
9210 afi_t afi;
9211 safi_t safi;
9212 int idx = 0;
9213
9214 afi = bgp_node_afi(vty);
9215 safi = bgp_node_safi(vty);
9216
9217 snprintf(
9218 base_xpath, sizeof(base_xpath),
9219 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config",
9220 yang_afi_safi_value2identity(afi, safi),
9221 bgp_afi_safi_get_container_str(afi, safi));
9222
9223 if (argv_find(argv, argc, "no", &idx))
9224 nb_cli_enqueue_change(vty, "./rd", NB_OP_DESTROY, NULL);
9225 else
9226 nb_cli_enqueue_change(vty, "./rd", NB_OP_MODIFY, rd_str);
9227
9228 return nb_cli_apply_changes(vty, base_xpath);
9229 }
9230
9231 void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rd(
9232 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9233 {
9234 int indent = 2;
9235
9236 vty_out(vty, "%*srd vpn export %s\n", indent, "",
9237 yang_dnode_get_string(dnode, NULL));
9238 }
9239
9240 ALIAS (af_rd_vpn_export,
9241 af_no_rd_vpn_export_cmd,
9242 "no rd vpn export",
9243 NO_STR
9244 "Specify route distinguisher\n"
9245 "Between current address-family and vpn\n"
9246 "For routes leaked from current address-family to vpn\n")
9247
9248 DEFPY (af_label_vpn_export,
9249 af_label_vpn_export_cmd,
9250 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
9251 NO_STR
9252 "label value for VRF\n"
9253 "Between current address-family and vpn\n"
9254 "For routes leaked from current address-family to vpn\n"
9255 "Label Value <0-1048575>\n"
9256 "Automatically assign a label\n")
9257 {
9258 VTY_DECLVAR_CONTEXT(bgp, bgp);
9259 mpls_label_t label = MPLS_LABEL_NONE;
9260 afi_t afi;
9261 int idx = 0;
9262 bool yes = true;
9263
9264 if (argv_find(argv, argc, "no", &idx))
9265 yes = false;
9266
9267 /* If "no ...", squash trailing parameter */
9268 if (!yes)
9269 label_auto = NULL;
9270
9271 if (yes) {
9272 if (!label_auto)
9273 label = label_val; /* parser should force unsigned */
9274 }
9275
9276 afi = vpn_policy_getafi(vty, bgp, false);
9277 if (afi == AFI_MAX)
9278 return CMD_WARNING_CONFIG_FAILED;
9279
9280
9281 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9282 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
9283 /* no change */
9284 return CMD_SUCCESS;
9285
9286 /*
9287 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
9288 */
9289 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9290 bgp_get_default(), bgp);
9291
9292 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9293 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
9294
9295 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
9296
9297 /*
9298 * label has previously been automatically
9299 * assigned by labelpool: release it
9300 *
9301 * NB if tovpn_label == MPLS_LABEL_NONE it
9302 * means the automatic assignment is in flight
9303 * and therefore the labelpool callback must
9304 * detect that the auto label is not needed.
9305 */
9306
9307 bgp_lp_release(LP_TYPE_VRF,
9308 &bgp->vpn_policy[afi],
9309 bgp->vpn_policy[afi].tovpn_label);
9310 }
9311 UNSET_FLAG(bgp->vpn_policy[afi].flags,
9312 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
9313 }
9314
9315 bgp->vpn_policy[afi].tovpn_label = label;
9316 if (label_auto) {
9317 SET_FLAG(bgp->vpn_policy[afi].flags,
9318 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
9319 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
9320 vpn_leak_label_callback);
9321 }
9322
9323 /* post-change: re-export vpn routes */
9324 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9325 bgp_get_default(), bgp);
9326
9327 hook_call(bgp_snmp_update_last_changed, bgp);
9328 return CMD_SUCCESS;
9329 }
9330
9331 DEFPY (af_sid_vpn_export,
9332 af_sid_vpn_export_cmd,
9333 "[no] sid vpn export <(1-255)$sid_idx|auto$sid_auto>",
9334 NO_STR
9335 "sid value for VRF\n"
9336 "Between current address-family and vpn\n"
9337 "For routes leaked from current address-family to vpn\n"
9338 "Sid allocation index\n"
9339 "Automatically assign a label\n")
9340 {
9341 VTY_DECLVAR_CONTEXT(bgp, bgp);
9342 afi_t afi;
9343 int debug = 0;
9344 int idx = 0;
9345 bool yes = true;
9346
9347 if (argv_find(argv, argc, "no", &idx))
9348 yes = false;
9349 debug = (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF) |
9350 BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF));
9351
9352 afi = vpn_policy_getafi(vty, bgp, false);
9353 if (afi == AFI_MAX)
9354 return CMD_WARNING_CONFIG_FAILED;
9355
9356 if (!yes) {
9357 /* implement me */
9358 vty_out(vty, "It's not implemented");
9359 return CMD_WARNING_CONFIG_FAILED;
9360 }
9361
9362 /* skip when it's already configured */
9363 if ((sid_idx != 0 && bgp->vpn_policy[afi].tovpn_sid_index != 0)
9364 || (sid_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9365 BGP_VPN_POLICY_TOVPN_SID_AUTO)))
9366 return CMD_SUCCESS;
9367
9368 /*
9369 * mode change between sid_idx and sid_auto isn't supported.
9370 * user must negate sid vpn export when they want to change the mode
9371 */
9372 if ((sid_auto && bgp->vpn_policy[afi].tovpn_sid_index != 0)
9373 || (sid_idx != 0 && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9374 BGP_VPN_POLICY_TOVPN_SID_AUTO))) {
9375 vty_out(vty, "it's already configured as %s.\n",
9376 sid_auto ? "auto-mode" : "idx-mode");
9377 return CMD_WARNING_CONFIG_FAILED;
9378 }
9379
9380 /* pre-change */
9381 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9382 bgp_get_default(), bgp);
9383
9384 if (sid_auto) {
9385 /* SID allocation auto-mode */
9386 if (debug)
9387 zlog_debug("%s: auto sid alloc.", __func__);
9388 SET_FLAG(bgp->vpn_policy[afi].flags,
9389 BGP_VPN_POLICY_TOVPN_SID_AUTO);
9390 } else {
9391 /* SID allocation index-mode */
9392 if (debug)
9393 zlog_debug("%s: idx %ld sid alloc.", __func__, sid_idx);
9394 bgp->vpn_policy[afi].tovpn_sid_index = sid_idx;
9395 }
9396
9397 /* post-change */
9398 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9399 bgp_get_default(), bgp);
9400 return CMD_SUCCESS;
9401 }
9402
9403 ALIAS (af_label_vpn_export,
9404 af_no_label_vpn_export_cmd,
9405 "no label vpn export",
9406 NO_STR
9407 "label value for VRF\n"
9408 "Between current address-family and vpn\n"
9409 "For routes leaked from current address-family to vpn\n")
9410
9411 DEFPY_YANG (af_nexthop_vpn_export,
9412 af_nexthop_vpn_export_cmd,
9413 "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
9414 NO_STR
9415 "Specify next hop to use for VRF advertised prefixes\n"
9416 "Between current address-family and vpn\n"
9417 "For routes leaked from current address-family to vpn\n"
9418 "IPv4 prefix\n"
9419 "IPv6 prefix\n")
9420 {
9421 char base_xpath[XPATH_MAXLEN];
9422 afi_t afi;
9423 safi_t safi;
9424 int idx = 0;
9425 struct prefix p;
9426
9427 if (!no) {
9428 if (!nexthop_su) {
9429 vty_out(vty, "%% Nexthop required\n");
9430 return CMD_WARNING_CONFIG_FAILED;
9431 }
9432 if (!sockunion2hostprefix(nexthop_su, &p))
9433 return CMD_WARNING_CONFIG_FAILED;
9434 }
9435
9436 afi = bgp_node_afi(vty);
9437 safi = bgp_node_safi(vty);
9438
9439 snprintf(
9440 base_xpath, sizeof(base_xpath),
9441 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config",
9442 yang_afi_safi_value2identity(afi, safi),
9443 bgp_afi_safi_get_container_str(afi, safi));
9444
9445 if (argv_find(argv, argc, "no", &idx))
9446 nb_cli_enqueue_change(vty, "./nexthop", NB_OP_DESTROY, NULL);
9447 else
9448 nb_cli_enqueue_change(vty, "./nexthop", NB_OP_MODIFY,
9449 nexthop_su_str);
9450
9451 return nb_cli_apply_changes(vty, base_xpath);
9452 }
9453
9454 void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_nexthop(
9455 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9456 {
9457 int indent = 2;
9458
9459 vty_out(vty, "%*snexthop vpn export %s\n", indent, "",
9460 yang_dnode_get_string(dnode, NULL));
9461 }
9462
9463 static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
9464 {
9465 if (!strcmp(dstr, "import")) {
9466 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9467 } else if (!strcmp(dstr, "export")) {
9468 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9469 } else if (!strcmp(dstr, "both")) {
9470 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9471 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9472 } else {
9473 vty_out(vty, "%% direction parse error\n");
9474 return CMD_WARNING_CONFIG_FAILED;
9475 }
9476 return CMD_SUCCESS;
9477 }
9478
9479 DEFPY (af_rt_vpn_imexport,
9480 af_rt_vpn_imexport_cmd,
9481 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
9482 NO_STR
9483 "Specify route target list\n"
9484 "Specify route target list\n"
9485 "Between current address-family and vpn\n"
9486 "For routes leaked from vpn to current address-family: match any\n"
9487 "For routes leaked from current address-family to vpn: set\n"
9488 "both import: match any and export: set\n"
9489 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
9490 {
9491 VTY_DECLVAR_CONTEXT(bgp, bgp);
9492 int ret;
9493 struct ecommunity *ecom = NULL;
9494 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
9495 vpn_policy_direction_t dir;
9496 afi_t afi;
9497 int idx = 0;
9498 bool yes = true;
9499
9500 if (argv_find(argv, argc, "no", &idx))
9501 yes = false;
9502
9503 afi = vpn_policy_getafi(vty, bgp, false);
9504 if (afi == AFI_MAX)
9505 return CMD_WARNING_CONFIG_FAILED;
9506
9507 ret = vpn_policy_getdirs(vty, direction_str, dodir);
9508 if (ret != CMD_SUCCESS)
9509 return ret;
9510
9511 if (yes) {
9512 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9513 vty_out(vty, "%% Missing RTLIST\n");
9514 return CMD_WARNING_CONFIG_FAILED;
9515 }
9516 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, false);
9517 if (ret != CMD_SUCCESS) {
9518 return ret;
9519 }
9520 }
9521
9522 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9523 if (!dodir[dir])
9524 continue;
9525
9526 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9527
9528 if (yes) {
9529 if (bgp->vpn_policy[afi].rtlist[dir])
9530 ecommunity_free(
9531 &bgp->vpn_policy[afi].rtlist[dir]);
9532 bgp->vpn_policy[afi].rtlist[dir] =
9533 ecommunity_dup(ecom);
9534 } else {
9535 if (bgp->vpn_policy[afi].rtlist[dir])
9536 ecommunity_free(
9537 &bgp->vpn_policy[afi].rtlist[dir]);
9538 bgp->vpn_policy[afi].rtlist[dir] = NULL;
9539 }
9540
9541 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9542 }
9543
9544 if (ecom)
9545 ecommunity_free(&ecom);
9546
9547 return CMD_SUCCESS;
9548 }
9549
9550 ALIAS (af_rt_vpn_imexport,
9551 af_no_rt_vpn_imexport_cmd,
9552 "no <rt|route-target> vpn <import|export|both>$direction_str",
9553 NO_STR
9554 "Specify route target list\n"
9555 "Specify route target list\n"
9556 "Between current address-family and vpn\n"
9557 "For routes leaked from vpn to current address-family\n"
9558 "For routes leaked from current address-family to vpn\n"
9559 "both import and export\n")
9560
9561 DEFPY_YANG (af_route_map_vpn_imexport,
9562 af_route_map_vpn_imexport_cmd,
9563 /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
9564 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
9565 NO_STR
9566 "Specify route map\n"
9567 "Between current address-family and vpn\n"
9568 "For routes leaked from vpn to current address-family\n"
9569 "For routes leaked from current address-family to vpn\n"
9570 "name of route-map\n")
9571 {
9572 char base_xpath[XPATH_MAXLEN];
9573 afi_t afi;
9574 safi_t safi;
9575 int idx = 0;
9576
9577 afi = bgp_node_afi(vty);
9578 safi = bgp_node_safi(vty);
9579
9580 snprintf(
9581 base_xpath, sizeof(base_xpath),
9582 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config",
9583 yang_afi_safi_value2identity(afi, safi),
9584 bgp_afi_safi_get_container_str(afi, safi));
9585
9586 if (argv_find(argv, argc, "no", &idx)) {
9587 if (!strcmp(direction_str, "import"))
9588 nb_cli_enqueue_change(vty, "./rmap-import",
9589 NB_OP_DESTROY, NULL);
9590 else if (!strcmp(direction_str, "export"))
9591 nb_cli_enqueue_change(vty, "./rmap-export",
9592 NB_OP_DESTROY, NULL);
9593 } else {
9594 if (!strcmp(direction_str, "import"))
9595 nb_cli_enqueue_change(vty, "./rmap-import",
9596 NB_OP_MODIFY, rmap_str);
9597 if (!strcmp(direction_str, "export"))
9598 nb_cli_enqueue_change(vty, "./rmap-export",
9599 NB_OP_MODIFY, rmap_str);
9600 }
9601 return nb_cli_apply_changes(vty, base_xpath);
9602 }
9603
9604 void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rmap_import(
9605 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9606 {
9607 int indent = 2;
9608
9609 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
9610 yang_dnode_get_string(dnode, NULL));
9611 }
9612
9613 void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rmap_export(
9614 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9615 {
9616 int indent = 2;
9617
9618 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
9619 yang_dnode_get_string(dnode, NULL));
9620 }
9621
9622 ALIAS (af_route_map_vpn_imexport,
9623 af_no_route_map_vpn_imexport_cmd,
9624 "no route-map vpn <import|export>$direction_str",
9625 NO_STR
9626 "Specify route map\n"
9627 "Between current address-family and vpn\n"
9628 "For routes leaked from vpn to current address-family\n"
9629 "For routes leaked from current address-family to vpn\n")
9630
9631 DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
9632 "import vrf route-map RMAP$rmap_str",
9633 "Import routes from another VRF\n"
9634 "Vrf routes being filtered\n"
9635 "Specify route map\n"
9636 "name of route-map\n")
9637 {
9638 VTY_DECLVAR_CONTEXT(bgp, bgp);
9639 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
9640 afi_t afi;
9641 struct bgp *bgp_default;
9642
9643 afi = vpn_policy_getafi(vty, bgp, true);
9644 if (afi == AFI_MAX)
9645 return CMD_WARNING_CONFIG_FAILED;
9646
9647 bgp_default = bgp_get_default();
9648 if (!bgp_default) {
9649 int32_t ret;
9650 as_t as = bgp->as;
9651
9652 /* Auto-create assuming the same AS */
9653 ret = bgp_get_vty(&bgp_default, &as, NULL,
9654 BGP_INSTANCE_TYPE_DEFAULT);
9655
9656 if (ret) {
9657 vty_out(vty,
9658 "VRF default is not configured as a bgp instance\n");
9659 return CMD_WARNING;
9660 }
9661 }
9662
9663 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9664
9665 if (bgp->vpn_policy[afi].rmap_name[dir])
9666 XFREE(MTYPE_ROUTE_MAP_NAME,
9667 bgp->vpn_policy[afi].rmap_name[dir]);
9668 bgp->vpn_policy[afi].rmap_name[dir] =
9669 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
9670 bgp->vpn_policy[afi].rmap[dir] =
9671 route_map_lookup_warn_noexist(vty, rmap_str);
9672 if (!bgp->vpn_policy[afi].rmap[dir])
9673 return CMD_SUCCESS;
9674
9675 SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9676 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9677
9678 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9679
9680 return CMD_SUCCESS;
9681 }
9682
9683 DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
9684 "no import vrf route-map [RMAP$rmap_str]",
9685 NO_STR
9686 "Import routes from another VRF\n"
9687 "Vrf routes being filtered\n"
9688 "Specify route map\n"
9689 "name of route-map\n")
9690 {
9691 VTY_DECLVAR_CONTEXT(bgp, bgp);
9692 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
9693 afi_t afi;
9694
9695 afi = vpn_policy_getafi(vty, bgp, true);
9696 if (afi == AFI_MAX)
9697 return CMD_WARNING_CONFIG_FAILED;
9698
9699 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9700
9701 if (bgp->vpn_policy[afi].rmap_name[dir])
9702 XFREE(MTYPE_ROUTE_MAP_NAME,
9703 bgp->vpn_policy[afi].rmap_name[dir]);
9704 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9705 bgp->vpn_policy[afi].rmap[dir] = NULL;
9706
9707 if (bgp->vpn_policy[afi].import_vrf->count == 0)
9708 UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9709 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9710
9711 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9712
9713 return CMD_SUCCESS;
9714 }
9715
9716 DEFPY_YANG(bgp_imexport_vrf,
9717 bgp_imexport_vrf_cmd,
9718 "[no] import vrf VIEWVRFNAME$import_name",
9719 NO_STR
9720 "Import routes from another VRF\n"
9721 "VRF to import from\n"
9722 "The name of the VRF\n")
9723 {
9724 char base_xpath[XPATH_MAXLEN];
9725 safi_t safi;
9726 afi_t afi;
9727 int32_t idx = 0;
9728
9729 if (import_name == NULL) {
9730 vty_out(vty, "%% Missing import name\n");
9731 return CMD_WARNING;
9732 }
9733
9734 if (strcmp(import_name, "route-map") == 0) {
9735 vty_out(vty, "%% Must include route-map name\n");
9736 return CMD_WARNING;
9737 }
9738
9739 afi = bgp_node_afi(vty);
9740 safi = bgp_node_safi(vty);
9741
9742 snprintf(
9743 base_xpath, sizeof(base_xpath),
9744 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config/import-vrf-list[vrf='%s']",
9745 yang_afi_safi_value2identity(afi, safi),
9746 bgp_afi_safi_get_container_str(afi, safi), import_name);
9747
9748 if (argv_find(argv, argc, "no", &idx))
9749 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
9750 else
9751 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
9752
9753 return nb_cli_apply_changes(vty, base_xpath);
9754 }
9755
9756 void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_import_vrfs(
9757 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9758 {
9759 vty_out(vty, " import vrf %s\n",
9760 yang_dnode_get_string(dnode, "./vrf"));
9761 }
9762
9763 /* This command is valid only in a bgp vrf instance or the default instance */
9764 DEFPY_YANG (bgp_imexport_vpn,
9765 bgp_imexport_vpn_cmd,
9766 "[no] <import|export>$direction_str vpn",
9767 NO_STR
9768 "Import routes to this address-family\n"
9769 "Export routes from this address-family\n"
9770 "to/from default instance VPN RIB\n")
9771 {
9772 char base_xpath[XPATH_MAXLEN];
9773 safi_t safi;
9774 afi_t afi;
9775 int32_t idx = 0;
9776
9777 afi = bgp_node_afi(vty);
9778 safi = bgp_node_safi(vty);
9779
9780 if (!strcmp(direction_str, "import")) {
9781 snprintf(
9782 base_xpath, sizeof(base_xpath),
9783 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config/import-vpn",
9784 yang_afi_safi_value2identity(afi, safi),
9785 bgp_afi_safi_get_container_str(afi, safi));
9786 } else if (!strcmp(direction_str, "export")) {
9787 snprintf(
9788 base_xpath, sizeof(base_xpath),
9789 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config/export-vpn",
9790 yang_afi_safi_value2identity(afi, safi),
9791 bgp_afi_safi_get_container_str(afi, safi));
9792 } else {
9793 vty_out(vty, "%% unknown direction %s\n", direction_str);
9794 return CMD_WARNING_CONFIG_FAILED;
9795 }
9796
9797 if (argv_find(argv, argc, "no", &idx))
9798 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
9799 else
9800 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, "true");
9801
9802 return nb_cli_apply_changes(vty, base_xpath);
9803 }
9804
9805 void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_import_vpn(
9806 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9807 {
9808 if (yang_dnode_get_bool(dnode, NULL))
9809 vty_out(vty, " import vpn\n");
9810 }
9811
9812 void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_export_vpn(
9813 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9814 {
9815 if (yang_dnode_get_bool(dnode, NULL))
9816 vty_out(vty, " export vpn\n");
9817 }
9818
9819 DEFPY (af_routetarget_import,
9820 af_routetarget_import_cmd,
9821 "[no] <rt|route-target|route-target6|rt6> redirect import RTLIST...",
9822 NO_STR
9823 "Specify route target list\n"
9824 "Specify route target list\n"
9825 "Specify route target list\n"
9826 "Specify route target list\n"
9827 "Flow-spec redirect type route target\n"
9828 "Import routes to this address-family\n"
9829 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN|IPV6:MN)\n")
9830 {
9831 VTY_DECLVAR_CONTEXT(bgp, bgp);
9832 int ret;
9833 struct ecommunity *ecom = NULL;
9834 afi_t afi;
9835 int idx = 0, idx_unused = 0;
9836 bool yes = true;
9837 bool rt6 = false;
9838
9839 if (argv_find(argv, argc, "no", &idx))
9840 yes = false;
9841
9842 if (argv_find(argv, argc, "rt6", &idx_unused) ||
9843 argv_find(argv, argc, "route-target6", &idx_unused))
9844 rt6 = true;
9845
9846 afi = vpn_policy_getafi(vty, bgp, false);
9847 if (afi == AFI_MAX)
9848 return CMD_WARNING_CONFIG_FAILED;
9849
9850 if (rt6 && afi != AFI_IP6)
9851 return CMD_WARNING_CONFIG_FAILED;
9852
9853 if (yes) {
9854 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9855 vty_out(vty, "%% Missing RTLIST\n");
9856 return CMD_WARNING_CONFIG_FAILED;
9857 }
9858 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, rt6);
9859 if (ret != CMD_SUCCESS)
9860 return ret;
9861 }
9862
9863 if (yes) {
9864 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9865 ecommunity_free(&bgp->vpn_policy[afi]
9866 .import_redirect_rtlist);
9867 bgp->vpn_policy[afi].import_redirect_rtlist =
9868 ecommunity_dup(ecom);
9869 } else {
9870 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9871 ecommunity_free(&bgp->vpn_policy[afi]
9872 .import_redirect_rtlist);
9873 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
9874 }
9875
9876 if (ecom)
9877 ecommunity_free(&ecom);
9878
9879 return CMD_SUCCESS;
9880 }
9881
9882 void cli_show_bgp_global_afi_safi_header(struct vty *vty,
9883 struct lyd_node *dnode,
9884 bool show_defaults)
9885 {
9886 const char *af_name;
9887 afi_t afi;
9888 safi_t safi;
9889
9890 af_name = yang_dnode_get_string(dnode, "./afi-safi-name");
9891 yang_afi_safi_identity2value(af_name, &afi, &safi);
9892
9893 vty_out(vty, " !\n address-family ");
9894 if (afi == AFI_IP) {
9895 if (safi == SAFI_UNICAST)
9896 vty_out(vty, "ipv4 unicast");
9897 else if (safi == SAFI_LABELED_UNICAST)
9898 vty_out(vty, "ipv4 labeled-unicast");
9899 else if (safi == SAFI_MULTICAST)
9900 vty_out(vty, "ipv4 multicast");
9901 else if (safi == SAFI_MPLS_VPN)
9902 vty_out(vty, "ipv4 vpn");
9903 else if (safi == SAFI_ENCAP)
9904 vty_out(vty, "ipv4 encap");
9905 else if (safi == SAFI_FLOWSPEC)
9906 vty_out(vty, "ipv4 flowspec");
9907 } else if (afi == AFI_IP6) {
9908 if (safi == SAFI_UNICAST)
9909 vty_out(vty, "ipv6 unicast");
9910 else if (safi == SAFI_LABELED_UNICAST)
9911 vty_out(vty, "ipv6 labeled-unicast");
9912 else if (safi == SAFI_MULTICAST)
9913 vty_out(vty, "ipv6 multicast");
9914 else if (safi == SAFI_MPLS_VPN)
9915 vty_out(vty, "ipv6 vpn");
9916 else if (safi == SAFI_ENCAP)
9917 vty_out(vty, "ipv6 encap");
9918 else if (safi == SAFI_FLOWSPEC)
9919 vty_out(vty, "ipv6 flowspec");
9920 } else if (afi == AFI_L2VPN) {
9921 if (safi == SAFI_EVPN)
9922 vty_out(vty, "l2vpn evpn");
9923 }
9924 vty_out(vty, "\n");
9925 }
9926
9927 DEFUN_NOSH (address_family_ipv4_safi,
9928 address_family_ipv4_safi_cmd,
9929 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9930 "Enter Address Family command mode\n"
9931 "Address Family\n"
9932 BGP_SAFI_WITH_LABEL_HELP_STR)
9933 {
9934
9935 safi_t safi = SAFI_UNICAST;
9936 const struct lyd_node *vrf_dnode, *bgp_glb_dnode;
9937 const char *vrf_name = NULL;
9938
9939 if (argc == 3) {
9940 safi = bgp_vty_safi_from_str(argv[2]->text);
9941
9942 bgp_glb_dnode = yang_dnode_get(vty->candidate_config->dnode,
9943 VTY_CURR_XPATH);
9944 vrf_dnode = yang_dnode_get_parent(bgp_glb_dnode,
9945 "control-plane-protocol");
9946 vrf_name = yang_dnode_get_string(vrf_dnode, "./vrf");
9947
9948 if (!strmatch(vrf_name, VRF_DEFAULT_NAME)
9949 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9950 && safi != SAFI_EVPN) {
9951 vty_out(vty,
9952 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9953 return CMD_WARNING_CONFIG_FAILED;
9954 }
9955 }
9956 vty->node = bgp_node_type(AFI_IP, safi);
9957
9958 return CMD_SUCCESS;
9959 }
9960
9961 DEFUN_NOSH (address_family_ipv6_safi,
9962 address_family_ipv6_safi_cmd,
9963 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9964 "Enter Address Family command mode\n"
9965 "Address Family\n"
9966 BGP_SAFI_WITH_LABEL_HELP_STR)
9967 {
9968 safi_t safi = SAFI_UNICAST;
9969 const struct lyd_node *vrf_dnode, *bgp_glb_dnode;
9970 const char *vrf_name = NULL;
9971
9972 if (argc == 3) {
9973 safi = bgp_vty_safi_from_str(argv[2]->text);
9974 bgp_glb_dnode = yang_dnode_get(vty->candidate_config->dnode,
9975 VTY_CURR_XPATH);
9976 vrf_dnode = yang_dnode_get_parent(bgp_glb_dnode,
9977 "control-plane-protocol");
9978 vrf_name = yang_dnode_get_string(vrf_dnode, "./vrf");
9979
9980 if (!strmatch(vrf_name, VRF_DEFAULT_NAME)
9981 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9982 && safi != SAFI_EVPN) {
9983 vty_out(vty,
9984 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9985 return CMD_WARNING_CONFIG_FAILED;
9986 }
9987 }
9988 vty->node = bgp_node_type(AFI_IP6, safi);
9989
9990 return CMD_SUCCESS;
9991 }
9992
9993 #ifdef KEEP_OLD_VPN_COMMANDS
9994 DEFUN_NOSH (address_family_vpnv4,
9995 address_family_vpnv4_cmd,
9996 "address-family vpnv4 [unicast]",
9997 "Enter Address Family command mode\n"
9998 "Address Family\n"
9999 "Address Family modifier\n")
10000 {
10001 vty->node = BGP_VPNV4_NODE;
10002 return CMD_SUCCESS;
10003 }
10004
10005 DEFUN_NOSH (address_family_vpnv6,
10006 address_family_vpnv6_cmd,
10007 "address-family vpnv6 [unicast]",
10008 "Enter Address Family command mode\n"
10009 "Address Family\n"
10010 "Address Family modifier\n")
10011 {
10012 vty->node = BGP_VPNV6_NODE;
10013 return CMD_SUCCESS;
10014 }
10015 #endif /* KEEP_OLD_VPN_COMMANDS */
10016
10017 DEFUN_NOSH (address_family_evpn,
10018 address_family_evpn_cmd,
10019 "address-family l2vpn evpn",
10020 "Enter Address Family command mode\n"
10021 "Address Family\n"
10022 "Address Family modifier\n")
10023 {
10024 VTY_DECLVAR_CONTEXT(bgp, bgp);
10025 vty->node = BGP_EVPN_NODE;
10026 return CMD_SUCCESS;
10027 }
10028
10029 DEFUN_NOSH (bgp_segment_routing_srv6,
10030 bgp_segment_routing_srv6_cmd,
10031 "segment-routing srv6",
10032 "Segment-Routing configuration\n"
10033 "Segment-Routing SRv6 configuration\n")
10034 {
10035 VTY_DECLVAR_CONTEXT(bgp, bgp);
10036 bgp->srv6_enabled = true;
10037 vty->node = BGP_SRV6_NODE;
10038 return CMD_SUCCESS;
10039 }
10040
10041 DEFPY (bgp_srv6_locator,
10042 bgp_srv6_locator_cmd,
10043 "locator NAME$name",
10044 "Specify SRv6 locator\n"
10045 "Specify SRv6 locator\n")
10046 {
10047 VTY_DECLVAR_CONTEXT(bgp, bgp);
10048 int ret;
10049
10050 if (strlen(bgp->srv6_locator_name) > 0
10051 && strcmp(name, bgp->srv6_locator_name) != 0) {
10052 vty_out(vty, "srv6 locator is already configured\n");
10053 return CMD_WARNING_CONFIG_FAILED;
10054 }
10055
10056 snprintf(bgp->srv6_locator_name,
10057 sizeof(bgp->srv6_locator_name), "%s", name);
10058
10059 ret = bgp_zebra_srv6_manager_get_locator_chunk(name);
10060 if (ret < 0)
10061 return CMD_WARNING_CONFIG_FAILED;
10062
10063 return CMD_SUCCESS;
10064 }
10065
10066 DEFPY (show_bgp_srv6,
10067 show_bgp_srv6_cmd,
10068 "show bgp segment-routing srv6",
10069 SHOW_STR
10070 BGP_STR
10071 "BGP Segment Routing\n"
10072 "BGP Segment Routing SRv6\n")
10073 {
10074 struct bgp *bgp;
10075 struct listnode *node;
10076 struct prefix_ipv6 *chunk;
10077 struct bgp_srv6_function *func;
10078 struct in6_addr *tovpn4_sid;
10079 struct in6_addr *tovpn6_sid;
10080 char buf[256];
10081 char buf_tovpn4_sid[256];
10082 char buf_tovpn6_sid[256];
10083
10084 bgp = bgp_get_default();
10085 if (!bgp)
10086 return CMD_SUCCESS;
10087
10088 vty_out(vty, "locator_name: %s\n", bgp->srv6_locator_name);
10089 vty_out(vty, "locator_chunks:\n");
10090 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_locator_chunks, node, chunk)) {
10091 prefix2str(chunk, buf, sizeof(buf));
10092 vty_out(vty, "- %s\n", buf);
10093 }
10094
10095 vty_out(vty, "functions:\n");
10096 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_functions, node, func)) {
10097 inet_ntop(AF_INET6, &func->sid, buf, sizeof(buf));
10098 vty_out(vty, "- sid: %s\n", buf);
10099 vty_out(vty, " locator: %s\n", func->locator_name);
10100 }
10101
10102 vty_out(vty, "bgps:\n");
10103 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp)) {
10104 vty_out(vty, "- name: %s\n",
10105 bgp->name ? bgp->name : "default");
10106
10107 tovpn4_sid = bgp->vpn_policy[AFI_IP].tovpn_sid;
10108 tovpn6_sid = bgp->vpn_policy[AFI_IP6].tovpn_sid;
10109 if (tovpn4_sid)
10110 inet_ntop(AF_INET6, tovpn4_sid, buf_tovpn4_sid,
10111 sizeof(buf_tovpn4_sid));
10112 if (tovpn6_sid)
10113 inet_ntop(AF_INET6, tovpn6_sid, buf_tovpn6_sid,
10114 sizeof(buf_tovpn6_sid));
10115
10116 vty_out(vty, " vpn_policy[AFI_IP].tovpn_sid: %s\n",
10117 tovpn4_sid ? buf_tovpn4_sid : "none");
10118 vty_out(vty, " vpn_policy[AFI_IP6].tovpn_sid: %s\n",
10119 tovpn6_sid ? buf_tovpn6_sid : "none");
10120 }
10121
10122 return CMD_SUCCESS;
10123 }
10124
10125 DEFUN_NOSH (exit_address_family,
10126 exit_address_family_cmd,
10127 "exit-address-family",
10128 "Exit from Address Family configuration mode\n")
10129 {
10130 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
10131 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
10132 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
10133 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
10134 || vty->node == BGP_EVPN_NODE
10135 || vty->node == BGP_FLOWSPECV4_NODE
10136 || vty->node == BGP_FLOWSPECV6_NODE)
10137 vty->node = BGP_NODE;
10138 return CMD_SUCCESS;
10139 }
10140
10141 void cli_show_bgp_global_afi_safi_header_end(struct vty *vty,
10142 struct lyd_node *dnode
10143 __attribute__((__unused__)))
10144 {
10145 vty_out(vty, " exit-address-family\n");
10146 }
10147
10148 /* Recalculate bestpath and re-advertise a prefix */
10149 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
10150 const char *ip_str, afi_t afi, safi_t safi,
10151 struct prefix_rd *prd)
10152 {
10153 int ret;
10154 struct prefix match;
10155 struct bgp_dest *dest;
10156 struct bgp_dest *rm;
10157 struct bgp *bgp;
10158 struct bgp_table *table;
10159 struct bgp_table *rib;
10160
10161 /* BGP structure lookup. */
10162 if (view_name) {
10163 bgp = bgp_lookup_by_name(view_name);
10164 if (bgp == NULL) {
10165 vty_out(vty, "%% Can't find BGP instance %s\n",
10166 view_name);
10167 return CMD_WARNING;
10168 }
10169 } else {
10170 bgp = bgp_get_default();
10171 if (bgp == NULL) {
10172 vty_out(vty, "%% No BGP process is configured\n");
10173 return CMD_WARNING;
10174 }
10175 }
10176
10177 /* Check IP address argument. */
10178 ret = str2prefix(ip_str, &match);
10179 if (!ret) {
10180 vty_out(vty, "%% address is malformed\n");
10181 return CMD_WARNING;
10182 }
10183
10184 match.family = afi2family(afi);
10185 rib = bgp->rib[afi][safi];
10186
10187 if (safi == SAFI_MPLS_VPN) {
10188 for (dest = bgp_table_top(rib); dest;
10189 dest = bgp_route_next(dest)) {
10190 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
10191
10192 if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
10193 continue;
10194
10195 table = bgp_dest_get_bgp_table_info(dest);
10196 if (table == NULL)
10197 continue;
10198
10199 if ((rm = bgp_node_match(table, &match)) != NULL) {
10200 const struct prefix *rm_p =
10201 bgp_dest_get_prefix(rm);
10202
10203 if (rm_p->prefixlen == match.prefixlen) {
10204 SET_FLAG(rm->flags,
10205 BGP_NODE_USER_CLEAR);
10206 bgp_process(bgp, rm, afi, safi);
10207 }
10208 bgp_dest_unlock_node(rm);
10209 }
10210 }
10211 } else {
10212 if ((dest = bgp_node_match(rib, &match)) != NULL) {
10213 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
10214
10215 if (dest_p->prefixlen == match.prefixlen) {
10216 SET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
10217 bgp_process(bgp, dest, afi, safi);
10218 }
10219 bgp_dest_unlock_node(dest);
10220 }
10221 }
10222
10223 return CMD_SUCCESS;
10224 }
10225
10226 /* one clear bgp command to rule them all */
10227 DEFUN (clear_ip_bgp_all,
10228 clear_ip_bgp_all_cmd,
10229 "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>]",
10230 CLEAR_STR
10231 IP_STR
10232 BGP_STR
10233 BGP_INSTANCE_HELP_STR
10234 BGP_AFI_HELP_STR
10235 "Address Family\n"
10236 BGP_SAFI_WITH_LABEL_HELP_STR
10237 "Address Family modifier\n"
10238 "Clear all peers\n"
10239 "BGP IPv4 neighbor to clear\n"
10240 "BGP IPv6 neighbor to clear\n"
10241 "BGP neighbor on interface to clear\n"
10242 "Clear peers with the AS number\n"
10243 "Clear all external peers\n"
10244 "Clear all members of peer-group\n"
10245 "BGP peer-group name\n"
10246 BGP_SOFT_STR
10247 BGP_SOFT_IN_STR
10248 BGP_SOFT_OUT_STR
10249 BGP_SOFT_IN_STR
10250 "Push out prefix-list ORF and do inbound soft reconfig\n"
10251 BGP_SOFT_OUT_STR)
10252 {
10253 char *vrf = NULL;
10254
10255 afi_t afi = AFI_UNSPEC;
10256 safi_t safi = SAFI_UNSPEC;
10257 enum clear_sort clr_sort = clear_peer;
10258 enum bgp_clear_type clr_type;
10259 char *clr_arg = NULL;
10260
10261 int idx = 0;
10262 char errmsg[BUFSIZ] = {'\0'};
10263 int ret;
10264
10265 /* clear [ip] bgp */
10266 if (argv_find(argv, argc, "ip", &idx))
10267 afi = AFI_IP;
10268
10269 /* [<vrf> VIEWVRFNAME] */
10270 if (argv_find(argv, argc, "vrf", &idx)) {
10271 vrf = argv[idx + 1]->arg;
10272 idx += 2;
10273 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
10274 vrf = NULL;
10275 } else if (argv_find(argv, argc, "view", &idx)) {
10276 /* [<view> VIEWVRFNAME] */
10277 vrf = argv[idx + 1]->arg;
10278 idx += 2;
10279 }
10280 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
10281 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
10282 argv_find_and_parse_safi(argv, argc, &idx, &safi);
10283
10284 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
10285 if (argv_find(argv, argc, "*", &idx)) {
10286 clr_sort = clear_all;
10287 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
10288 clr_sort = clear_peer;
10289 clr_arg = argv[idx]->arg;
10290 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
10291 clr_sort = clear_peer;
10292 clr_arg = argv[idx]->arg;
10293 } else if (argv_find(argv, argc, "peer-group", &idx)) {
10294 clr_sort = clear_group;
10295 idx++;
10296 clr_arg = argv[idx]->arg;
10297 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
10298 clr_sort = clear_peer;
10299 clr_arg = argv[idx]->arg;
10300 } else if (argv_find(argv, argc, "WORD", &idx)) {
10301 clr_sort = clear_peer;
10302 clr_arg = argv[idx]->arg;
10303 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
10304 clr_sort = clear_as;
10305 clr_arg = argv[idx]->arg;
10306 } else if (argv_find(argv, argc, "external", &idx)) {
10307 clr_sort = clear_external;
10308 }
10309
10310 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
10311 if (argv_find(argv, argc, "soft", &idx)) {
10312 if (argv_find(argv, argc, "in", &idx)
10313 || argv_find(argv, argc, "out", &idx))
10314 clr_type = strmatch(argv[idx]->text, "in")
10315 ? BGP_CLEAR_SOFT_IN
10316 : BGP_CLEAR_SOFT_OUT;
10317 else
10318 clr_type = BGP_CLEAR_SOFT_BOTH;
10319 } else if (argv_find(argv, argc, "in", &idx)) {
10320 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
10321 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
10322 : BGP_CLEAR_SOFT_IN;
10323 } else if (argv_find(argv, argc, "out", &idx)) {
10324 clr_type = BGP_CLEAR_SOFT_OUT;
10325 } else
10326 clr_type = BGP_CLEAR_SOFT_NONE;
10327
10328 ret = bgp_clear_vty(vrf, afi, safi, clr_sort, clr_type, clr_arg, errmsg,
10329 sizeof(errmsg));
10330 if (ret != NB_OK)
10331 vty_out(vty, "Error description: %s\n", errmsg);
10332
10333 return ret;
10334 }
10335
10336 DEFUN (clear_ip_bgp_prefix,
10337 clear_ip_bgp_prefix_cmd,
10338 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
10339 CLEAR_STR
10340 IP_STR
10341 BGP_STR
10342 BGP_INSTANCE_HELP_STR
10343 "Clear bestpath and re-advertise\n"
10344 "IPv4 prefix\n")
10345 {
10346 char *vrf = NULL;
10347 char *prefix = NULL;
10348
10349 int idx = 0;
10350
10351 /* [<view|vrf> VIEWVRFNAME] */
10352 if (argv_find(argv, argc, "vrf", &idx)) {
10353 vrf = argv[idx + 1]->arg;
10354 idx += 2;
10355 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
10356 vrf = NULL;
10357 } else if (argv_find(argv, argc, "view", &idx)) {
10358 /* [<view> VIEWVRFNAME] */
10359 vrf = argv[idx + 1]->arg;
10360 idx += 2;
10361 }
10362
10363 prefix = argv[argc - 1]->arg;
10364
10365 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
10366 }
10367
10368 DEFUN (clear_bgp_ipv6_safi_prefix,
10369 clear_bgp_ipv6_safi_prefix_cmd,
10370 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
10371 CLEAR_STR
10372 IP_STR
10373 BGP_STR
10374 "Address Family\n"
10375 BGP_SAFI_HELP_STR
10376 "Clear bestpath and re-advertise\n"
10377 "IPv6 prefix\n")
10378 {
10379 int idx_safi = 0;
10380 int idx_ipv6_prefix = 0;
10381 safi_t safi = SAFI_UNICAST;
10382 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
10383 argv[idx_ipv6_prefix]->arg : NULL;
10384
10385 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
10386 return bgp_clear_prefix(
10387 vty, NULL, prefix, AFI_IP6,
10388 safi, NULL);
10389 }
10390
10391 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
10392 clear_bgp_instance_ipv6_safi_prefix_cmd,
10393 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
10394 CLEAR_STR
10395 IP_STR
10396 BGP_STR
10397 BGP_INSTANCE_HELP_STR
10398 "Address Family\n"
10399 BGP_SAFI_HELP_STR
10400 "Clear bestpath and re-advertise\n"
10401 "IPv6 prefix\n")
10402 {
10403 int idx_safi = 0;
10404 int idx_vrfview = 0;
10405 int idx_ipv6_prefix = 0;
10406 safi_t safi = SAFI_UNICAST;
10407 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
10408 argv[idx_ipv6_prefix]->arg : NULL;
10409 char *vrfview = NULL;
10410
10411 /* [<view|vrf> VIEWVRFNAME] */
10412 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
10413 vrfview = argv[idx_vrfview + 1]->arg;
10414 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
10415 vrfview = NULL;
10416 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
10417 /* [<view> VIEWVRFNAME] */
10418 vrfview = argv[idx_vrfview + 1]->arg;
10419 }
10420 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
10421
10422 return bgp_clear_prefix(
10423 vty, vrfview, prefix,
10424 AFI_IP6, safi, NULL);
10425 }
10426
10427 DEFUN (show_bgp_views,
10428 show_bgp_views_cmd,
10429 "show [ip] bgp views",
10430 SHOW_STR
10431 IP_STR
10432 BGP_STR
10433 "Show the defined BGP views\n")
10434 {
10435 struct list *inst = bm->bgp;
10436 struct listnode *node;
10437 struct bgp *bgp;
10438
10439 vty_out(vty, "Defined BGP views:\n");
10440 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10441 /* Skip VRFs. */
10442 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
10443 continue;
10444 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
10445 bgp->as);
10446 }
10447
10448 return CMD_SUCCESS;
10449 }
10450
10451 DEFUN (show_bgp_vrfs,
10452 show_bgp_vrfs_cmd,
10453 "show [ip] bgp vrfs [json]",
10454 SHOW_STR
10455 IP_STR
10456 BGP_STR
10457 "Show BGP VRFs\n"
10458 JSON_STR)
10459 {
10460 char buf[ETHER_ADDR_STRLEN];
10461 struct list *inst = bm->bgp;
10462 struct listnode *node;
10463 struct bgp *bgp;
10464 bool uj = use_json(argc, argv);
10465 json_object *json = NULL;
10466 json_object *json_vrfs = NULL;
10467 int count = 0;
10468
10469 if (uj) {
10470 json = json_object_new_object();
10471 json_vrfs = json_object_new_object();
10472 }
10473
10474 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10475 const char *name, *type;
10476 struct peer *peer;
10477 struct listnode *node2, *nnode2;
10478 int peers_cfg, peers_estb;
10479 json_object *json_vrf = NULL;
10480
10481 /* Skip Views. */
10482 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
10483 continue;
10484
10485 count++;
10486 if (!uj && count == 1) {
10487 vty_out(vty,
10488 "%4s %-5s %-16s %9s %10s %-37s\n",
10489 "Type", "Id", "routerId", "#PeersCfg",
10490 "#PeersEstb", "Name");
10491 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
10492 "L3-VNI", "RouterMAC", "Interface");
10493 }
10494
10495 peers_cfg = peers_estb = 0;
10496 if (uj)
10497 json_vrf = json_object_new_object();
10498
10499
10500 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
10501 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10502 continue;
10503 peers_cfg++;
10504 if (peer_established(peer))
10505 peers_estb++;
10506 }
10507
10508 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
10509 name = VRF_DEFAULT_NAME;
10510 type = "DFLT";
10511 } else {
10512 name = bgp->name;
10513 type = "VRF";
10514 }
10515
10516
10517 if (uj) {
10518 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10519 ? -1
10520 : (int64_t)bgp->vrf_id;
10521 char buf[BUFSIZ] = {0};
10522
10523 json_object_string_add(json_vrf, "type", type);
10524 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
10525 json_object_string_add(json_vrf, "routerId",
10526 inet_ntop(AF_INET,
10527 &bgp->router_id, buf,
10528 sizeof(buf)));
10529 json_object_int_add(json_vrf, "numConfiguredPeers",
10530 peers_cfg);
10531 json_object_int_add(json_vrf, "numEstablishedPeers",
10532 peers_estb);
10533
10534 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
10535 json_object_string_add(
10536 json_vrf, "rmac",
10537 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
10538 json_object_string_add(json_vrf, "interface",
10539 ifindex2ifname(bgp->l3vni_svi_ifindex,
10540 bgp->vrf_id));
10541 json_object_object_add(json_vrfs, name, json_vrf);
10542 } else {
10543 vty_out(vty, "%4s %-5d %-16pI4 %-9u %-10u %-37s\n",
10544 type,
10545 bgp->vrf_id == VRF_UNKNOWN ? -1
10546 : (int)bgp->vrf_id,
10547 &bgp->router_id, peers_cfg, peers_estb, name);
10548 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
10549 bgp->l3vni,
10550 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
10551 ifindex2ifname(bgp->l3vni_svi_ifindex,
10552 bgp->vrf_id));
10553 }
10554 }
10555
10556 if (uj) {
10557 json_object_object_add(json, "vrfs", json_vrfs);
10558
10559 json_object_int_add(json, "totalVrfs", count);
10560
10561 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10562 json, JSON_C_TO_STRING_PRETTY));
10563 json_object_free(json);
10564 } else {
10565 if (count)
10566 vty_out(vty,
10567 "\nTotal number of VRFs (including default): %d\n",
10568 count);
10569 }
10570
10571 return CMD_SUCCESS;
10572 }
10573
10574 DEFUN (show_bgp_mac_hash,
10575 show_bgp_mac_hash_cmd,
10576 "show bgp mac hash",
10577 SHOW_STR
10578 BGP_STR
10579 "Mac Address\n"
10580 "Mac Address database\n")
10581 {
10582 bgp_mac_dump_table(vty);
10583
10584 return CMD_SUCCESS;
10585 }
10586
10587 static void show_tip_entry(struct hash_bucket *bucket, void *args)
10588 {
10589 struct vty *vty = (struct vty *)args;
10590 struct tip_addr *tip = (struct tip_addr *)bucket->data;
10591
10592 vty_out(vty, "addr: %pI4, count: %d\n", &tip->addr, tip->refcnt);
10593 }
10594
10595 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
10596 {
10597 vty_out(vty, "self nexthop database:\n");
10598 bgp_nexthop_show_address_hash(vty, bgp);
10599
10600 vty_out(vty, "Tunnel-ip database:\n");
10601 hash_iterate(bgp->tip_hash,
10602 (void (*)(struct hash_bucket *, void *))show_tip_entry,
10603 vty);
10604 }
10605
10606 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
10607 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
10608 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
10609 "martian next-hops\n"
10610 "martian next-hop database\n")
10611 {
10612 struct bgp *bgp = NULL;
10613 int idx = 0;
10614 char *name = NULL;
10615
10616 /* [<vrf> VIEWVRFNAME] */
10617 if (argv_find(argv, argc, "vrf", &idx)) {
10618 name = argv[idx + 1]->arg;
10619 if (name && strmatch(name, VRF_DEFAULT_NAME))
10620 name = NULL;
10621 } else if (argv_find(argv, argc, "view", &idx))
10622 /* [<view> VIEWVRFNAME] */
10623 name = argv[idx + 1]->arg;
10624 if (name)
10625 bgp = bgp_lookup_by_name(name);
10626 else
10627 bgp = bgp_get_default();
10628
10629 if (!bgp) {
10630 vty_out(vty, "%% No BGP process is configured\n");
10631 return CMD_WARNING;
10632 }
10633 bgp_show_martian_nexthops(vty, bgp);
10634
10635 return CMD_SUCCESS;
10636 }
10637
10638 DEFUN (show_bgp_memory,
10639 show_bgp_memory_cmd,
10640 "show [ip] bgp memory",
10641 SHOW_STR
10642 IP_STR
10643 BGP_STR
10644 "Global BGP memory statistics\n")
10645 {
10646 char memstrbuf[MTYPE_MEMSTR_LEN];
10647 unsigned long count;
10648
10649 /* RIB related usage stats */
10650 count = mtype_stats_alloc(MTYPE_BGP_NODE);
10651 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
10652 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10653 count * sizeof(struct bgp_dest)));
10654
10655 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
10656 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
10657 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10658 count * sizeof(struct bgp_path_info)));
10659 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
10660 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
10661 count,
10662 mtype_memstr(
10663 memstrbuf, sizeof(memstrbuf),
10664 count * sizeof(struct bgp_path_info_extra)));
10665
10666 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
10667 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
10668 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10669 count * sizeof(struct bgp_static)));
10670
10671 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
10672 vty_out(vty, "%ld Packets, using %s of memory\n", count,
10673 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10674 count * sizeof(struct bpacket)));
10675
10676 /* Adj-In/Out */
10677 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
10678 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
10679 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10680 count * sizeof(struct bgp_adj_in)));
10681 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
10682 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
10683 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10684 count * sizeof(struct bgp_adj_out)));
10685
10686 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
10687 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
10688 count,
10689 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10690 count * sizeof(struct bgp_nexthop_cache)));
10691
10692 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
10693 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
10694 count,
10695 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10696 count * sizeof(struct bgp_damp_info)));
10697
10698 /* Attributes */
10699 count = attr_count();
10700 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
10701 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10702 count * sizeof(struct attr)));
10703
10704 if ((count = attr_unknown_count()))
10705 vty_out(vty, "%ld unknown attributes\n", count);
10706
10707 /* AS_PATH attributes */
10708 count = aspath_count();
10709 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
10710 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10711 count * sizeof(struct aspath)));
10712
10713 count = mtype_stats_alloc(MTYPE_AS_SEG);
10714 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
10715 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10716 count * sizeof(struct assegment)));
10717
10718 /* Other attributes */
10719 if ((count = community_count()))
10720 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
10721 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10722 count * sizeof(struct community)));
10723 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
10724 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
10725 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10726 count * sizeof(struct ecommunity)));
10727 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
10728 vty_out(vty,
10729 "%ld BGP large-community entries, using %s of memory\n",
10730 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10731 count * sizeof(struct lcommunity)));
10732
10733 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
10734 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
10735 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10736 count * sizeof(struct cluster_list)));
10737
10738 /* Peer related usage */
10739 count = mtype_stats_alloc(MTYPE_BGP_PEER);
10740 vty_out(vty, "%ld peers, using %s of memory\n", count,
10741 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10742 count * sizeof(struct peer)));
10743
10744 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
10745 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
10746 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10747 count * sizeof(struct peer_group)));
10748
10749 /* Other */
10750 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
10751 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
10752 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10753 count * sizeof(regex_t)));
10754 return CMD_SUCCESS;
10755 }
10756
10757 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
10758 {
10759 json_object *bestpath = json_object_new_object();
10760
10761 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
10762 json_object_string_add(bestpath, "asPath", "ignore");
10763
10764 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
10765 json_object_string_add(bestpath, "asPath", "confed");
10766
10767 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
10768 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
10769 json_object_string_add(bestpath, "multiPathRelax",
10770 "as-set");
10771 else
10772 json_object_string_add(bestpath, "multiPathRelax",
10773 "true");
10774 } else
10775 json_object_string_add(bestpath, "multiPathRelax", "false");
10776
10777 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
10778 json_object_boolean_true_add(bestpath, "peerTypeRelax");
10779
10780 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
10781 json_object_string_add(bestpath, "compareRouterId", "true");
10782 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
10783 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
10784 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
10785 json_object_string_add(bestpath, "med", "confed");
10786 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
10787 json_object_string_add(bestpath, "med",
10788 "missing-as-worst");
10789 else
10790 json_object_string_add(bestpath, "med", "true");
10791 }
10792
10793 json_object_object_add(json, "bestPath", bestpath);
10794 }
10795
10796 /* Print the error code/subcode for why the peer is down */
10797 static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
10798 json_object *json_peer, bool use_json)
10799 {
10800 const char *code_str;
10801 const char *subcode_str;
10802
10803 if (use_json) {
10804 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10805 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10806 char errorcodesubcode_hexstr[5];
10807 char errorcodesubcode_str[256];
10808
10809 code_str = bgp_notify_code_str(peer->notify.code);
10810 subcode_str = bgp_notify_subcode_str(
10811 peer->notify.code,
10812 peer->notify.subcode);
10813
10814 snprintf(errorcodesubcode_hexstr,
10815 sizeof(errorcodesubcode_hexstr), "%02X%02X",
10816 peer->notify.code, peer->notify.subcode);
10817 json_object_string_add(json_peer,
10818 "lastErrorCodeSubcode",
10819 errorcodesubcode_hexstr);
10820 snprintf(errorcodesubcode_str, 255, "%s%s",
10821 code_str, subcode_str);
10822 json_object_string_add(json_peer,
10823 "lastNotificationReason",
10824 errorcodesubcode_str);
10825 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10826 && peer->notify.code == BGP_NOTIFY_CEASE
10827 && (peer->notify.subcode
10828 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10829 || peer->notify.subcode
10830 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10831 && peer->notify.length) {
10832 char msgbuf[1024];
10833 const char *msg_str;
10834
10835 msg_str = bgp_notify_admin_message(
10836 msgbuf, sizeof(msgbuf),
10837 (uint8_t *)peer->notify.data,
10838 peer->notify.length);
10839 if (msg_str)
10840 json_object_string_add(
10841 json_peer,
10842 "lastShutdownDescription",
10843 msg_str);
10844 }
10845
10846 }
10847 json_object_string_add(json_peer, "lastResetDueTo",
10848 peer_down_str[(int)peer->last_reset]);
10849 json_object_int_add(json_peer, "lastResetCode",
10850 peer->last_reset);
10851 } else {
10852 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10853 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10854 code_str = bgp_notify_code_str(peer->notify.code);
10855 subcode_str =
10856 bgp_notify_subcode_str(peer->notify.code,
10857 peer->notify.subcode);
10858 vty_out(vty, " Notification %s (%s%s)\n",
10859 peer->last_reset == PEER_DOWN_NOTIFY_SEND
10860 ? "sent"
10861 : "received",
10862 code_str, subcode_str);
10863 } else {
10864 vty_out(vty, " %s\n",
10865 peer_down_str[(int)peer->last_reset]);
10866 }
10867 }
10868 }
10869
10870 static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
10871 safi_t safi)
10872 {
10873 return ((!peer_established(peer)) || !peer->afc_recv[afi][safi]);
10874 }
10875
10876 static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
10877 struct peer *peer, json_object *json_peer,
10878 int max_neighbor_width, bool use_json)
10879 {
10880 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10881 int len;
10882
10883 if (use_json) {
10884 if (peer_dynamic_neighbor(peer))
10885 json_object_boolean_true_add(json_peer,
10886 "dynamicPeer");
10887 if (peer->hostname)
10888 json_object_string_add(json_peer, "hostname",
10889 peer->hostname);
10890
10891 if (peer->domainname)
10892 json_object_string_add(json_peer, "domainname",
10893 peer->domainname);
10894 json_object_int_add(json_peer, "connectionsEstablished",
10895 peer->established);
10896 json_object_int_add(json_peer, "connectionsDropped",
10897 peer->dropped);
10898 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10899 use_json, json_peer);
10900 if (peer_established(peer))
10901 json_object_string_add(json_peer, "lastResetDueTo",
10902 "AFI/SAFI Not Negotiated");
10903 else
10904 bgp_show_peer_reset(NULL, peer, json_peer, true);
10905 } else {
10906 dn_flag[1] = '\0';
10907 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
10908 if (peer->hostname
10909 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
10910 len = vty_out(vty, "%s%s(%s)", dn_flag,
10911 peer->hostname, peer->host);
10912 else
10913 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10914
10915 /* pad the neighbor column with spaces */
10916 if (len < max_neighbor_width)
10917 vty_out(vty, "%*s", max_neighbor_width - len,
10918 " ");
10919 vty_out(vty, "%7d %7d %9s", peer->established,
10920 peer->dropped,
10921 peer_uptime(peer->uptime, timebuf,
10922 BGP_UPTIME_LEN, 0, NULL));
10923 if (peer_established(peer))
10924 vty_out(vty, " AFI/SAFI Not Negotiated\n");
10925 else
10926 bgp_show_peer_reset(vty, peer, NULL,
10927 false);
10928 }
10929 }
10930
10931 /* If the peer's description includes whitespaces
10932 * then return the first occurrence. Also strip description
10933 * to the given size if needed.
10934 */
10935 static char *bgp_peer_description_stripped(char *desc, uint32_t size)
10936 {
10937 static char stripped[BUFSIZ];
10938 char *pnt;
10939 uint32_t len = size > strlen(desc) ? strlen(desc) : size;
10940
10941 pnt = strchr(desc, ' ');
10942 if (pnt)
10943 len = size > (uint32_t)(pnt - desc) ? (uint32_t)(pnt - desc)
10944 : size;
10945
10946 strlcpy(stripped, desc, len + 1);
10947
10948 return stripped;
10949 }
10950
10951 /* Determine whether var peer should be filtered out of the summary. */
10952 static bool bgp_show_summary_is_peer_filtered(struct peer *peer,
10953 struct peer *fpeer, int as_type,
10954 as_t as)
10955 {
10956
10957 /* filter neighbor XXXX */
10958 if (fpeer && fpeer != peer)
10959 return true;
10960
10961 /* filter remote-as (internal|external) */
10962 if (as_type != AS_UNSPECIFIED) {
10963 if (peer->as_type == AS_SPECIFIED) {
10964 if (as_type == AS_INTERNAL) {
10965 if (peer->as != peer->local_as)
10966 return true;
10967 } else if (peer->as == peer->local_as)
10968 return true;
10969 } else if (as_type != peer->as_type)
10970 return true;
10971 } else if (as && as != peer->as) /* filter remote-as XXX */
10972 return true;
10973
10974 return false;
10975 }
10976
10977 /* Show BGP peer's summary information. */
10978 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
10979 struct peer *fpeer, int as_type, as_t as,
10980 uint16_t show_flags)
10981 {
10982 struct peer *peer;
10983 struct listnode *node, *nnode;
10984 unsigned int count = 0, dn_count = 0;
10985 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10986 char neighbor_buf[VTY_BUFSIZ];
10987 int neighbor_col_default_width = 16;
10988 int len, failed_count = 0;
10989 unsigned int filtered_count = 0;
10990 int max_neighbor_width = 0;
10991 int pfx_rcd_safi;
10992 json_object *json = NULL;
10993 json_object *json_peer = NULL;
10994 json_object *json_peers = NULL;
10995 struct peer_af *paf;
10996 struct bgp_filter *filter;
10997 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
10998 bool show_failed = CHECK_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
10999 bool show_established =
11000 CHECK_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
11001 bool show_wide = CHECK_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
11002 bool show_terse = CHECK_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
11003
11004 /* labeled-unicast routes are installed in the unicast table so in order
11005 * to
11006 * display the correct PfxRcd value we must look at SAFI_UNICAST
11007 */
11008
11009 if (safi == SAFI_LABELED_UNICAST)
11010 pfx_rcd_safi = SAFI_UNICAST;
11011 else
11012 pfx_rcd_safi = safi;
11013
11014 if (use_json) {
11015 json = json_object_new_object();
11016 json_peers = json_object_new_object();
11017 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
11018 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
11019 as_type, as)) {
11020 filtered_count++;
11021 count++;
11022 continue;
11023 }
11024
11025 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
11026 continue;
11027
11028 if (peer->afc[afi][safi]) {
11029 /* See if we have at least a single failed peer */
11030 if (bgp_has_peer_failed(peer, afi, safi))
11031 failed_count++;
11032 count++;
11033 }
11034 if (peer_dynamic_neighbor(peer))
11035 dn_count++;
11036 }
11037
11038 } else {
11039 /* Loop over all neighbors that will be displayed to determine
11040 * how many
11041 * characters are needed for the Neighbor column
11042 */
11043 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
11044 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
11045 as_type, as)) {
11046 filtered_count++;
11047 count++;
11048 continue;
11049 }
11050
11051 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
11052 continue;
11053
11054 if (peer->afc[afi][safi]) {
11055 memset(dn_flag, '\0', sizeof(dn_flag));
11056 if (peer_dynamic_neighbor(peer))
11057 dn_flag[0] = '*';
11058
11059 if (peer->hostname
11060 && CHECK_FLAG(bgp->flags,
11061 BGP_FLAG_SHOW_HOSTNAME))
11062 snprintf(neighbor_buf,
11063 sizeof(neighbor_buf),
11064 "%s%s(%s) ", dn_flag,
11065 peer->hostname, peer->host);
11066 else
11067 snprintf(neighbor_buf,
11068 sizeof(neighbor_buf), "%s%s ",
11069 dn_flag, peer->host);
11070
11071 len = strlen(neighbor_buf);
11072
11073 if (len > max_neighbor_width)
11074 max_neighbor_width = len;
11075
11076 /* See if we have at least a single failed peer */
11077 if (bgp_has_peer_failed(peer, afi, safi))
11078 failed_count++;
11079 count++;
11080 }
11081 }
11082
11083 /* Originally we displayed the Neighbor column as 16
11084 * characters wide so make that the default
11085 */
11086 if (max_neighbor_width < neighbor_col_default_width)
11087 max_neighbor_width = neighbor_col_default_width;
11088 }
11089
11090 if (show_failed && !failed_count) {
11091 if (use_json) {
11092 json_object_int_add(json, "failedPeersCount", 0);
11093 json_object_int_add(json, "dynamicPeers", dn_count);
11094 json_object_int_add(json, "totalPeers", count);
11095
11096 vty_out(vty, "%s\n", json_object_to_json_string_ext(
11097 json, JSON_C_TO_STRING_PRETTY));
11098 json_object_free(json);
11099 } else {
11100 vty_out(vty, "%% No failed BGP neighbors found\n");
11101 }
11102 return CMD_SUCCESS;
11103 }
11104
11105 count = 0; /* Reset the value as its used again */
11106 filtered_count = 0;
11107 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
11108 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
11109 continue;
11110
11111 if (!peer->afc[afi][safi])
11112 continue;
11113
11114 if (!count) {
11115 unsigned long ents;
11116 char memstrbuf[MTYPE_MEMSTR_LEN];
11117 int64_t vrf_id_ui;
11118
11119 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
11120 ? -1
11121 : (int64_t)bgp->vrf_id;
11122
11123 /* Usage summary and header */
11124 if (use_json) {
11125 char buf[BUFSIZ] = {0};
11126
11127 json_object_string_add(
11128 json, "routerId",
11129 inet_ntop(AF_INET, &bgp->router_id, buf,
11130 sizeof(buf)));
11131 json_object_int_add(json, "as", bgp->as);
11132 json_object_int_add(json, "vrfId", vrf_id_ui);
11133 json_object_string_add(
11134 json, "vrfName",
11135 (bgp->inst_type
11136 == BGP_INSTANCE_TYPE_DEFAULT)
11137 ? VRF_DEFAULT_NAME
11138 : bgp->name);
11139 } else {
11140 vty_out(vty,
11141 "BGP router identifier %pI4, local AS number %u vrf-id %d",
11142 &bgp->router_id, bgp->as,
11143 bgp->vrf_id == VRF_UNKNOWN
11144 ? -1
11145 : (int)bgp->vrf_id);
11146 vty_out(vty, "\n");
11147 }
11148
11149 if (bgp_update_delay_configured(bgp)) {
11150 if (use_json) {
11151 json_object_int_add(
11152 json, "updateDelayLimit",
11153 bgp->v_update_delay);
11154
11155 if (bgp->v_update_delay
11156 != bgp->v_establish_wait)
11157 json_object_int_add(
11158 json,
11159 "updateDelayEstablishWait",
11160 bgp->v_establish_wait);
11161
11162 if (bgp_update_delay_active(bgp)) {
11163 json_object_string_add(
11164 json,
11165 "updateDelayFirstNeighbor",
11166 bgp->update_delay_begin_time);
11167 json_object_boolean_true_add(
11168 json,
11169 "updateDelayInProgress");
11170 } else {
11171 if (bgp->update_delay_over) {
11172 json_object_string_add(
11173 json,
11174 "updateDelayFirstNeighbor",
11175 bgp->update_delay_begin_time);
11176 json_object_string_add(
11177 json,
11178 "updateDelayBestpathResumed",
11179 bgp->update_delay_end_time);
11180 json_object_string_add(
11181 json,
11182 "updateDelayZebraUpdateResume",
11183 bgp->update_delay_zebra_resume_time);
11184 json_object_string_add(
11185 json,
11186 "updateDelayPeerUpdateResume",
11187 bgp->update_delay_peers_resume_time);
11188 }
11189 }
11190 } else {
11191 vty_out(vty,
11192 "Read-only mode update-delay limit: %d seconds\n",
11193 bgp->v_update_delay);
11194 if (bgp->v_update_delay
11195 != bgp->v_establish_wait)
11196 vty_out(vty,
11197 " Establish wait: %d seconds\n",
11198 bgp->v_establish_wait);
11199
11200 if (bgp_update_delay_active(bgp)) {
11201 vty_out(vty,
11202 " First neighbor established: %s\n",
11203 bgp->update_delay_begin_time);
11204 vty_out(vty,
11205 " Delay in progress\n");
11206 } else {
11207 if (bgp->update_delay_over) {
11208 vty_out(vty,
11209 " First neighbor established: %s\n",
11210 bgp->update_delay_begin_time);
11211 vty_out(vty,
11212 " Best-paths resumed: %s\n",
11213 bgp->update_delay_end_time);
11214 vty_out(vty,
11215 " zebra update resumed: %s\n",
11216 bgp->update_delay_zebra_resume_time);
11217 vty_out(vty,
11218 " peers update resumed: %s\n",
11219 bgp->update_delay_peers_resume_time);
11220 }
11221 }
11222 }
11223 }
11224
11225 if (use_json) {
11226 if (bgp_maxmed_onstartup_configured(bgp)
11227 && bgp->maxmed_active)
11228 json_object_boolean_true_add(
11229 json, "maxMedOnStartup");
11230 if (bgp->v_maxmed_admin)
11231 json_object_boolean_true_add(
11232 json, "maxMedAdministrative");
11233
11234 json_object_int_add(
11235 json, "tableVersion",
11236 bgp_table_version(bgp->rib[afi][safi]));
11237
11238 ents = bgp_table_count(bgp->rib[afi][safi]);
11239 json_object_int_add(json, "ribCount", ents);
11240 json_object_int_add(
11241 json, "ribMemory",
11242 ents * sizeof(struct bgp_dest));
11243
11244 ents = bgp->af_peer_count[afi][safi];
11245 json_object_int_add(json, "peerCount", ents);
11246 json_object_int_add(json, "peerMemory",
11247 ents * sizeof(struct peer));
11248
11249 if ((ents = listcount(bgp->group))) {
11250 json_object_int_add(
11251 json, "peerGroupCount", ents);
11252 json_object_int_add(
11253 json, "peerGroupMemory",
11254 ents * sizeof(struct
11255 peer_group));
11256 }
11257
11258 if (CHECK_FLAG(bgp->af_flags[afi][safi],
11259 BGP_CONFIG_DAMPENING))
11260 json_object_boolean_true_add(
11261 json, "dampeningEnabled");
11262 } else {
11263 if (!show_terse) {
11264 if (bgp_maxmed_onstartup_configured(bgp)
11265 && bgp->maxmed_active)
11266 vty_out(vty,
11267 "Max-med on-startup active\n");
11268 if (bgp->v_maxmed_admin)
11269 vty_out(vty,
11270 "Max-med administrative active\n");
11271
11272 vty_out(vty,
11273 "BGP table version %" PRIu64
11274 "\n",
11275 bgp_table_version(
11276 bgp->rib[afi][safi]));
11277
11278 ents = bgp_table_count(
11279 bgp->rib[afi][safi]);
11280 vty_out(vty,
11281 "RIB entries %ld, using %s of memory\n",
11282 ents,
11283 mtype_memstr(
11284 memstrbuf,
11285 sizeof(memstrbuf),
11286 ents
11287 * sizeof(
11288 struct
11289 bgp_dest)));
11290
11291 /* Peer related usage */
11292 ents = bgp->af_peer_count[afi][safi];
11293 vty_out(vty,
11294 "Peers %ld, using %s of memory\n",
11295 ents,
11296 mtype_memstr(
11297 memstrbuf,
11298 sizeof(memstrbuf),
11299 ents
11300 * sizeof(
11301 struct
11302 peer)));
11303
11304 if ((ents = listcount(bgp->group)))
11305 vty_out(vty,
11306 "Peer groups %ld, using %s of memory\n",
11307 ents,
11308 mtype_memstr(
11309 memstrbuf,
11310 sizeof(memstrbuf),
11311 ents
11312 * sizeof(
11313 struct
11314 peer_group)));
11315
11316 if (CHECK_FLAG(bgp->af_flags[afi][safi],
11317 BGP_CONFIG_DAMPENING))
11318 vty_out(vty,
11319 "Dampening enabled.\n");
11320 }
11321 if (show_failed) {
11322 vty_out(vty, "\n");
11323
11324 /* Subtract 8 here because 'Neighbor' is
11325 * 8 characters */
11326 vty_out(vty, "Neighbor");
11327 vty_out(vty, "%*s",
11328 max_neighbor_width - 8, " ");
11329 vty_out(vty,
11330 BGP_SHOW_SUMMARY_HEADER_FAILED);
11331 }
11332 }
11333 }
11334
11335 paf = peer_af_find(peer, afi, safi);
11336 filter = &peer->filter[afi][safi];
11337
11338 count++;
11339 /* Works for both failed & successful cases */
11340 if (peer_dynamic_neighbor(peer))
11341 dn_count++;
11342
11343 if (use_json) {
11344 json_peer = NULL;
11345 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
11346 as_type, as)) {
11347 filtered_count++;
11348 continue;
11349 }
11350 if (show_failed &&
11351 bgp_has_peer_failed(peer, afi, safi)) {
11352 json_peer = json_object_new_object();
11353 bgp_show_failed_summary(vty, bgp, peer,
11354 json_peer, 0, use_json);
11355 } else if (!show_failed) {
11356 if (show_established
11357 && bgp_has_peer_failed(peer, afi, safi)) {
11358 filtered_count++;
11359 continue;
11360 }
11361
11362 json_peer = json_object_new_object();
11363 if (peer_dynamic_neighbor(peer)) {
11364 json_object_boolean_true_add(json_peer,
11365 "dynamicPeer");
11366 }
11367
11368 if (peer->hostname)
11369 json_object_string_add(json_peer, "hostname",
11370 peer->hostname);
11371
11372 if (peer->domainname)
11373 json_object_string_add(json_peer, "domainname",
11374 peer->domainname);
11375
11376 json_object_int_add(json_peer, "remoteAs", peer->as);
11377 json_object_int_add(
11378 json_peer, "localAs",
11379 peer->change_local_as
11380 ? peer->change_local_as
11381 : peer->local_as);
11382 json_object_int_add(json_peer, "version", 4);
11383 json_object_int_add(json_peer, "msgRcvd",
11384 PEER_TOTAL_RX(peer));
11385 json_object_int_add(json_peer, "msgSent",
11386 PEER_TOTAL_TX(peer));
11387
11388 atomic_size_t outq_count, inq_count;
11389 outq_count = atomic_load_explicit(
11390 &peer->obuf->count,
11391 memory_order_relaxed);
11392 inq_count = atomic_load_explicit(
11393 &peer->ibuf->count,
11394 memory_order_relaxed);
11395
11396 json_object_int_add(json_peer, "tableVersion",
11397 peer->version[afi][safi]);
11398 json_object_int_add(json_peer, "outq",
11399 outq_count);
11400 json_object_int_add(json_peer, "inq",
11401 inq_count);
11402 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
11403 use_json, json_peer);
11404
11405 json_object_int_add(json_peer, "pfxRcd",
11406 peer->pcount[afi][pfx_rcd_safi]);
11407
11408 if (paf && PAF_SUBGRP(paf))
11409 json_object_int_add(
11410 json_peer, "pfxSnt",
11411 (PAF_SUBGRP(paf))->scount);
11412 else
11413 json_object_int_add(json_peer, "pfxSnt",
11414 0);
11415
11416 /* BGP FSM state */
11417 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
11418 || CHECK_FLAG(peer->bgp->flags,
11419 BGP_FLAG_SHUTDOWN))
11420 json_object_string_add(json_peer,
11421 "state",
11422 "Idle (Admin)");
11423 else if (peer->afc_recv[afi][safi])
11424 json_object_string_add(
11425 json_peer, "state",
11426 lookup_msg(bgp_status_msg,
11427 peer->status, NULL));
11428 else if (CHECK_FLAG(
11429 peer->sflags,
11430 PEER_STATUS_PREFIX_OVERFLOW))
11431 json_object_string_add(json_peer,
11432 "state",
11433 "Idle (PfxCt)");
11434 else
11435 json_object_string_add(
11436 json_peer, "state",
11437 lookup_msg(bgp_status_msg,
11438 peer->status, NULL));
11439
11440 /* BGP peer state */
11441 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
11442 || CHECK_FLAG(peer->bgp->flags,
11443 BGP_FLAG_SHUTDOWN))
11444 json_object_string_add(json_peer,
11445 "peerState",
11446 "Admin");
11447 else if (CHECK_FLAG(
11448 peer->sflags,
11449 PEER_STATUS_PREFIX_OVERFLOW))
11450 json_object_string_add(json_peer,
11451 "peerState",
11452 "PfxCt");
11453 else if (CHECK_FLAG(peer->flags,
11454 PEER_FLAG_PASSIVE))
11455 json_object_string_add(json_peer,
11456 "peerState",
11457 "Passive");
11458 else if (CHECK_FLAG(peer->sflags,
11459 PEER_STATUS_NSF_WAIT))
11460 json_object_string_add(json_peer,
11461 "peerState",
11462 "NSF passive");
11463 else if (CHECK_FLAG(
11464 peer->bgp->flags,
11465 BGP_FLAG_EBGP_REQUIRES_POLICY)
11466 && (!bgp_inbound_policy_exists(peer,
11467 filter)
11468 || !bgp_outbound_policy_exists(
11469 peer, filter)))
11470 json_object_string_add(json_peer,
11471 "peerState",
11472 "Policy");
11473 else
11474 json_object_string_add(
11475 json_peer, "peerState", "OK");
11476
11477 json_object_int_add(json_peer, "connectionsEstablished",
11478 peer->established);
11479 json_object_int_add(json_peer, "connectionsDropped",
11480 peer->dropped);
11481 if (peer->desc)
11482 json_object_string_add(
11483 json_peer, "desc", peer->desc);
11484 }
11485 /* Avoid creating empty peer dicts in JSON */
11486 if (json_peer == NULL)
11487 continue;
11488
11489 if (peer->conf_if)
11490 json_object_string_add(json_peer, "idType",
11491 "interface");
11492 else if (peer->su.sa.sa_family == AF_INET)
11493 json_object_string_add(json_peer, "idType",
11494 "ipv4");
11495 else if (peer->su.sa.sa_family == AF_INET6)
11496 json_object_string_add(json_peer, "idType",
11497 "ipv6");
11498 json_object_object_add(json_peers, peer->host,
11499 json_peer);
11500 } else {
11501 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
11502 as_type, as)) {
11503 filtered_count++;
11504 continue;
11505 }
11506 if (show_failed &&
11507 bgp_has_peer_failed(peer, afi, safi)) {
11508 bgp_show_failed_summary(vty, bgp, peer, NULL,
11509 max_neighbor_width,
11510 use_json);
11511 } else if (!show_failed) {
11512 if (show_established
11513 && bgp_has_peer_failed(peer, afi, safi)) {
11514 filtered_count++;
11515 continue;
11516 }
11517
11518 if ((count - filtered_count) == 1) {
11519 /* display headline before the first
11520 * neighbor line */
11521 vty_out(vty, "\n");
11522
11523 /* Subtract 8 here because 'Neighbor' is
11524 * 8 characters */
11525 vty_out(vty, "Neighbor");
11526 vty_out(vty, "%*s",
11527 max_neighbor_width - 8, " ");
11528 vty_out(vty,
11529 show_wide
11530 ? BGP_SHOW_SUMMARY_HEADER_ALL_WIDE
11531 : BGP_SHOW_SUMMARY_HEADER_ALL);
11532 }
11533
11534 memset(dn_flag, '\0', sizeof(dn_flag));
11535 if (peer_dynamic_neighbor(peer)) {
11536 dn_flag[0] = '*';
11537 }
11538
11539 if (peer->hostname
11540 && CHECK_FLAG(bgp->flags,
11541 BGP_FLAG_SHOW_HOSTNAME))
11542 len = vty_out(vty, "%s%s(%s)", dn_flag,
11543 peer->hostname,
11544 peer->host);
11545 else
11546 len = vty_out(vty, "%s%s", dn_flag, peer->host);
11547
11548 /* pad the neighbor column with spaces */
11549 if (len < max_neighbor_width)
11550 vty_out(vty, "%*s", max_neighbor_width - len,
11551 " ");
11552
11553 atomic_size_t outq_count, inq_count;
11554 outq_count = atomic_load_explicit(
11555 &peer->obuf->count,
11556 memory_order_relaxed);
11557 inq_count = atomic_load_explicit(
11558 &peer->ibuf->count,
11559 memory_order_relaxed);
11560
11561 if (show_wide)
11562 vty_out(vty,
11563 "4 %10u %10u %9u %9u %8" PRIu64
11564 " %4zu %4zu %8s",
11565 peer->as,
11566 peer->change_local_as
11567 ? peer->change_local_as
11568 : peer->local_as,
11569 PEER_TOTAL_RX(peer),
11570 PEER_TOTAL_TX(peer),
11571 peer->version[afi][safi],
11572 inq_count, outq_count,
11573 peer_uptime(peer->uptime,
11574 timebuf,
11575 BGP_UPTIME_LEN, 0,
11576 NULL));
11577 else
11578 vty_out(vty, "4 %10u %9u %9u %8" PRIu64
11579 " %4zu %4zu %8s",
11580 peer->as, PEER_TOTAL_RX(peer),
11581 PEER_TOTAL_TX(peer),
11582 peer->version[afi][safi],
11583 inq_count, outq_count,
11584 peer_uptime(peer->uptime,
11585 timebuf,
11586 BGP_UPTIME_LEN, 0,
11587 NULL));
11588
11589 if (peer_established(peer)) {
11590 if (peer->afc_recv[afi][safi]) {
11591 if (CHECK_FLAG(
11592 bgp->flags,
11593 BGP_FLAG_EBGP_REQUIRES_POLICY)
11594 && !bgp_inbound_policy_exists(
11595 peer, filter))
11596 vty_out(vty, " %12s",
11597 "(Policy)");
11598 else
11599 vty_out(vty,
11600 " %12u",
11601 peer->pcount
11602 [afi]
11603 [pfx_rcd_safi]);
11604 } else {
11605 vty_out(vty, " NoNeg");
11606 }
11607
11608 if (paf && PAF_SUBGRP(paf)) {
11609 if (CHECK_FLAG(
11610 bgp->flags,
11611 BGP_FLAG_EBGP_REQUIRES_POLICY)
11612 && !bgp_outbound_policy_exists(
11613 peer, filter))
11614 vty_out(vty, " %8s",
11615 "(Policy)");
11616 else
11617 vty_out(vty,
11618 " %8u",
11619 (PAF_SUBGRP(
11620 paf))
11621 ->scount);
11622 } else {
11623 vty_out(vty, " NoNeg");
11624 }
11625 } else {
11626 if (CHECK_FLAG(peer->flags,
11627 PEER_FLAG_SHUTDOWN)
11628 || CHECK_FLAG(peer->bgp->flags,
11629 BGP_FLAG_SHUTDOWN))
11630 vty_out(vty, " Idle (Admin)");
11631 else if (CHECK_FLAG(
11632 peer->sflags,
11633 PEER_STATUS_PREFIX_OVERFLOW))
11634 vty_out(vty, " Idle (PfxCt)");
11635 else
11636 vty_out(vty, " %12s",
11637 lookup_msg(bgp_status_msg,
11638 peer->status, NULL));
11639
11640 vty_out(vty, " %8u", 0);
11641 }
11642 if (peer->desc)
11643 vty_out(vty, " %s",
11644 bgp_peer_description_stripped(
11645 peer->desc,
11646 show_wide ? 64 : 20));
11647 else
11648 vty_out(vty, " N/A");
11649 vty_out(vty, "\n");
11650 }
11651
11652 }
11653 }
11654
11655 if (use_json) {
11656 json_object_object_add(json, "peers", json_peers);
11657 json_object_int_add(json, "failedPeers", failed_count);
11658 json_object_int_add(json, "displayedPeers",
11659 count - filtered_count);
11660 json_object_int_add(json, "totalPeers", count);
11661 json_object_int_add(json, "dynamicPeers", dn_count);
11662
11663 if (!show_failed)
11664 bgp_show_bestpath_json(bgp, json);
11665
11666 vty_out(vty, "%s\n", json_object_to_json_string_ext(
11667 json, JSON_C_TO_STRING_PRETTY));
11668 json_object_free(json);
11669 } else {
11670 if (count) {
11671 if (filtered_count == count)
11672 vty_out(vty, "\n%% No matching neighbor\n");
11673 else {
11674 if (show_failed)
11675 vty_out(vty, "\nDisplayed neighbors %d",
11676 failed_count);
11677 else if (as_type != AS_UNSPECIFIED || as
11678 || fpeer || show_established)
11679 vty_out(vty, "\nDisplayed neighbors %d",
11680 count - filtered_count);
11681
11682 vty_out(vty, "\nTotal number of neighbors %d\n",
11683 count);
11684 }
11685 } else {
11686 vty_out(vty, "No %s neighbor is configured\n",
11687 get_afi_safi_str(afi, safi, false));
11688 }
11689
11690 if (dn_count) {
11691 vty_out(vty, "* - dynamic neighbor\n");
11692 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
11693 dn_count, bgp->dynamic_neighbors_limit);
11694 }
11695 }
11696
11697 return CMD_SUCCESS;
11698 }
11699
11700 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
11701 int safi, struct peer *fpeer, int as_type,
11702 as_t as, uint16_t show_flags)
11703 {
11704 int is_first = 1;
11705 int afi_wildcard = (afi == AFI_MAX);
11706 int safi_wildcard = (safi == SAFI_MAX);
11707 int is_wildcard = (afi_wildcard || safi_wildcard);
11708 bool nbr_output = false;
11709 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11710
11711 if (use_json && is_wildcard)
11712 vty_out(vty, "{\n");
11713 if (afi_wildcard)
11714 afi = 1; /* AFI_IP */
11715 while (afi < AFI_MAX) {
11716 if (safi_wildcard)
11717 safi = 1; /* SAFI_UNICAST */
11718 while (safi < SAFI_MAX) {
11719 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
11720 nbr_output = true;
11721
11722 if (is_wildcard) {
11723 /*
11724 * So limit output to those afi/safi
11725 * pairs that
11726 * actualy have something interesting in
11727 * them
11728 */
11729 if (use_json) {
11730 if (!is_first)
11731 vty_out(vty, ",\n");
11732 else
11733 is_first = 0;
11734
11735 vty_out(vty, "\"%s\":",
11736 get_afi_safi_str(afi,
11737 safi,
11738 true));
11739 } else {
11740 vty_out(vty,
11741 "\n%s Summary (%s):\n",
11742 get_afi_safi_str(afi,
11743 safi,
11744 false),
11745 bgp->name_pretty);
11746 }
11747 }
11748 bgp_show_summary(vty, bgp, afi, safi, fpeer,
11749 as_type, as, show_flags);
11750 }
11751 safi++;
11752 if (!safi_wildcard)
11753 safi = SAFI_MAX;
11754 }
11755 afi++;
11756 if (!afi_wildcard)
11757 afi = AFI_MAX;
11758 }
11759
11760 if (use_json && is_wildcard)
11761 vty_out(vty, "}\n");
11762 else if (!nbr_output) {
11763 if (use_json)
11764 vty_out(vty, "{}\n");
11765 else
11766 vty_out(vty, "%% No BGP neighbors found in %s\n",
11767 bgp->name_pretty);
11768 }
11769 }
11770
11771 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
11772 safi_t safi,
11773 const char *neighbor,
11774 int as_type, as_t as,
11775 uint16_t show_flags)
11776 {
11777 struct listnode *node, *nnode;
11778 struct bgp *bgp;
11779 struct peer *fpeer = NULL;
11780 int is_first = 1;
11781 bool nbr_output = false;
11782 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11783
11784 if (use_json)
11785 vty_out(vty, "{\n");
11786
11787 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11788 nbr_output = true;
11789 if (use_json) {
11790 if (!is_first)
11791 vty_out(vty, ",\n");
11792 else
11793 is_first = 0;
11794
11795 vty_out(vty, "\"%s\":",
11796 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11797 ? VRF_DEFAULT_NAME
11798 : bgp->name);
11799 }
11800 if (neighbor) {
11801 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11802 use_json);
11803 if (!fpeer)
11804 continue;
11805 }
11806 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11807 as, show_flags);
11808 }
11809
11810 if (use_json)
11811 vty_out(vty, "}\n");
11812 else if (!nbr_output)
11813 vty_out(vty, "%% BGP instance not found\n");
11814 }
11815
11816 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
11817 safi_t safi, const char *neighbor, int as_type,
11818 as_t as, uint16_t show_flags)
11819 {
11820 struct bgp *bgp;
11821 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11822 struct peer *fpeer = NULL;
11823
11824 if (name) {
11825 if (strmatch(name, "all")) {
11826 bgp_show_all_instances_summary_vty(vty, afi, safi,
11827 neighbor, as_type,
11828 as, show_flags);
11829 return CMD_SUCCESS;
11830 } else {
11831 bgp = bgp_lookup_by_name(name);
11832
11833 if (!bgp) {
11834 if (use_json)
11835 vty_out(vty, "{}\n");
11836 else
11837 vty_out(vty,
11838 "%% BGP instance not found\n");
11839 return CMD_WARNING;
11840 }
11841
11842 if (neighbor) {
11843 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11844 use_json);
11845 if (!fpeer)
11846 return CMD_WARNING;
11847 }
11848 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer,
11849 as_type, as, show_flags);
11850 return CMD_SUCCESS;
11851 }
11852 }
11853
11854 bgp = bgp_get_default();
11855
11856 if (bgp) {
11857 if (neighbor) {
11858 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11859 use_json);
11860 if (!fpeer)
11861 return CMD_WARNING;
11862 }
11863 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11864 as, show_flags);
11865 } else {
11866 if (use_json)
11867 vty_out(vty, "{}\n");
11868 else
11869 vty_out(vty, "%% BGP instance not found\n");
11870 return CMD_WARNING;
11871 }
11872
11873 return CMD_SUCCESS;
11874 }
11875
11876 /* `show [ip] bgp summary' commands. */
11877 DEFPY(show_ip_bgp_summary, show_ip_bgp_summary_cmd,
11878 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [" BGP_AFI_CMD_STR
11879 " [" BGP_SAFI_WITH_LABEL_CMD_STR
11880 "]] [all$all] summary [established|failed] [<neighbor <A.B.C.D|X:X::X:X|WORD>|remote-as <(1-4294967295)|internal|external>>] [terse] [wide] [json$uj]",
11881 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11882 BGP_SAFI_WITH_LABEL_HELP_STR
11883 "Display the entries for all address families\n"
11884 "Summary of BGP neighbor status\n"
11885 "Show only sessions in Established state\n"
11886 "Show only sessions not in Established state\n"
11887 "Show only the specified neighbor session\n"
11888 "Neighbor to display information about\n"
11889 "Neighbor to display information about\n"
11890 "Neighbor on BGP configured interface\n"
11891 "Show only the specified remote AS sessions\n"
11892 "AS number\n"
11893 "Internal (iBGP) AS sessions\n"
11894 "External (eBGP) AS sessions\n"
11895 "Shorten the information on BGP instances\n"
11896 "Increase table width for longer output\n" JSON_STR)
11897 {
11898 char *vrf = NULL;
11899 afi_t afi = AFI_MAX;
11900 safi_t safi = SAFI_MAX;
11901 as_t as = 0; /* 0 means AS filter not set */
11902 int as_type = AS_UNSPECIFIED;
11903 uint16_t show_flags = 0;
11904
11905 int idx = 0;
11906
11907 /* show [ip] bgp */
11908 if (!all && argv_find(argv, argc, "ip", &idx))
11909 afi = AFI_IP;
11910 /* [<vrf> VIEWVRFNAME] */
11911 if (argv_find(argv, argc, "vrf", &idx)) {
11912 vrf = argv[idx + 1]->arg;
11913 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11914 vrf = NULL;
11915 } else if (argv_find(argv, argc, "view", &idx))
11916 /* [<view> VIEWVRFNAME] */
11917 vrf = argv[idx + 1]->arg;
11918 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11919 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11920 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11921 }
11922
11923 if (argv_find(argv, argc, "failed", &idx))
11924 SET_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
11925
11926 if (argv_find(argv, argc, "established", &idx))
11927 SET_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
11928
11929 if (argv_find(argv, argc, "remote-as", &idx)) {
11930 if (argv[idx + 1]->arg[0] == 'i')
11931 as_type = AS_INTERNAL;
11932 else if (argv[idx + 1]->arg[0] == 'e')
11933 as_type = AS_EXTERNAL;
11934 else
11935 as = (as_t)atoi(argv[idx + 1]->arg);
11936 }
11937
11938 if (argv_find(argv, argc, "terse", &idx))
11939 SET_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
11940
11941 if (argv_find(argv, argc, "wide", &idx))
11942 SET_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
11943
11944 if (argv_find(argv, argc, "json", &idx))
11945 SET_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11946
11947 return bgp_show_summary_vty(vty, vrf, afi, safi, neighbor, as_type, as,
11948 show_flags);
11949 }
11950
11951 const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
11952 {
11953 if (for_json)
11954 return get_afi_safi_json_str(afi, safi);
11955 else
11956 return get_afi_safi_vty_str(afi, safi);
11957 }
11958
11959
11960 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
11961 afi_t afi, safi_t safi,
11962 uint16_t adv_smcap, uint16_t adv_rmcap,
11963 uint16_t rcv_smcap, uint16_t rcv_rmcap,
11964 bool use_json, json_object *json_pref)
11965 {
11966 /* Send-Mode */
11967 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11968 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
11969 if (use_json) {
11970 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11971 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11972 json_object_string_add(json_pref, "sendMode",
11973 "advertisedAndReceived");
11974 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11975 json_object_string_add(json_pref, "sendMode",
11976 "advertised");
11977 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11978 json_object_string_add(json_pref, "sendMode",
11979 "received");
11980 } else {
11981 vty_out(vty, " Send-mode: ");
11982 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11983 vty_out(vty, "advertised");
11984 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11985 vty_out(vty, "%sreceived",
11986 CHECK_FLAG(p->af_cap[afi][safi],
11987 adv_smcap)
11988 ? ", "
11989 : "");
11990 vty_out(vty, "\n");
11991 }
11992 }
11993
11994 /* Receive-Mode */
11995 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11996 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
11997 if (use_json) {
11998 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11999 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
12000 json_object_string_add(json_pref, "recvMode",
12001 "advertisedAndReceived");
12002 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
12003 json_object_string_add(json_pref, "recvMode",
12004 "advertised");
12005 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
12006 json_object_string_add(json_pref, "recvMode",
12007 "received");
12008 } else {
12009 vty_out(vty, " Receive-mode: ");
12010 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
12011 vty_out(vty, "advertised");
12012 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
12013 vty_out(vty, "%sreceived",
12014 CHECK_FLAG(p->af_cap[afi][safi],
12015 adv_rmcap)
12016 ? ", "
12017 : "");
12018 vty_out(vty, "\n");
12019 }
12020 }
12021 }
12022
12023 static void bgp_show_neighnor_graceful_restart_rbit(struct vty *vty,
12024 struct peer *p,
12025 bool use_json,
12026 json_object *json)
12027 {
12028 bool rbit_status = false;
12029
12030 if (!use_json)
12031 vty_out(vty, "\n R bit: ");
12032
12033 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
12034 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
12035 && (peer_established(p))) {
12036
12037 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_BIT_RCV))
12038 rbit_status = true;
12039 else
12040 rbit_status = false;
12041 }
12042
12043 if (rbit_status) {
12044 if (use_json)
12045 json_object_boolean_true_add(json, "rBit");
12046 else
12047 vty_out(vty, "True\n");
12048 } else {
12049 if (use_json)
12050 json_object_boolean_false_add(json, "rBit");
12051 else
12052 vty_out(vty, "False\n");
12053 }
12054 }
12055
12056 static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
12057 struct peer *peer,
12058 bool use_json,
12059 json_object *json)
12060 {
12061 const char *mode = "NotApplicable";
12062
12063 if (!use_json)
12064 vty_out(vty, "\n Remote GR Mode: ");
12065
12066 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
12067 && (peer_established(peer))) {
12068
12069 if ((peer->nsf_af_count == 0)
12070 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
12071
12072 mode = "Disable";
12073
12074 } else if (peer->nsf_af_count == 0
12075 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
12076
12077 mode = "Helper";
12078
12079 } else if (peer->nsf_af_count != 0
12080 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
12081
12082 mode = "Restart";
12083 }
12084 }
12085
12086 if (use_json) {
12087 json_object_string_add(json, "remoteGrMode", mode);
12088 } else
12089 vty_out(vty, mode, "\n");
12090 }
12091
12092 static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
12093 struct peer *p,
12094 bool use_json,
12095 json_object *json)
12096 {
12097 const char *mode = "Invalid";
12098
12099 if (!use_json)
12100 vty_out(vty, " Local GR Mode: ");
12101
12102 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
12103 mode = "Helper";
12104 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
12105 mode = "Restart";
12106 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
12107 mode = "Disable";
12108 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
12109 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
12110 mode = "Helper*";
12111 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
12112 mode = "Restart*";
12113 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
12114 mode = "Disable*";
12115 else
12116 mode = "Invalid*";
12117 }
12118
12119 if (use_json) {
12120 json_object_string_add(json, "localGrMode", mode);
12121 } else {
12122 vty_out(vty, mode, "\n");
12123 }
12124 }
12125
12126 static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
12127 struct vty *vty, struct peer *peer, bool use_json, json_object *json)
12128 {
12129 afi_t afi;
12130 safi_t safi;
12131 json_object *json_afi_safi = NULL;
12132 json_object *json_timer = NULL;
12133 json_object *json_endofrib_status = NULL;
12134 bool eor_flag = false;
12135
12136 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
12137 for (safi = SAFI_UNICAST; safi <= SAFI_MPLS_VPN; safi++) {
12138 if (!peer->afc[afi][safi])
12139 continue;
12140
12141 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
12142 || !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
12143 continue;
12144
12145 if (use_json) {
12146 json_afi_safi = json_object_new_object();
12147 json_endofrib_status = json_object_new_object();
12148 json_timer = json_object_new_object();
12149 }
12150
12151 if (peer->eor_stime[afi][safi]
12152 >= peer->pkt_stime[afi][safi])
12153 eor_flag = true;
12154 else
12155 eor_flag = false;
12156
12157 if (!use_json) {
12158 vty_out(vty, " %s:\n",
12159 get_afi_safi_str(afi, safi, false));
12160
12161 vty_out(vty, " F bit: ");
12162 }
12163
12164 if (peer->nsf[afi][safi]
12165 && CHECK_FLAG(peer->af_cap[afi][safi],
12166 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
12167
12168 if (use_json) {
12169 json_object_boolean_true_add(
12170 json_afi_safi, "fBit");
12171 } else
12172 vty_out(vty, "True\n");
12173 } else {
12174 if (use_json)
12175 json_object_boolean_false_add(
12176 json_afi_safi, "fBit");
12177 else
12178 vty_out(vty, "False\n");
12179 }
12180
12181 if (!use_json)
12182 vty_out(vty, " End-of-RIB sent: ");
12183
12184 if (CHECK_FLAG(peer->af_sflags[afi][safi],
12185 PEER_STATUS_EOR_SEND)) {
12186 if (use_json) {
12187 json_object_boolean_true_add(
12188 json_endofrib_status,
12189 "endOfRibSend");
12190
12191 PRINT_EOR_JSON(eor_flag);
12192 } else {
12193 vty_out(vty, "Yes\n");
12194 vty_out(vty,
12195 " End-of-RIB sent after update: ");
12196
12197 PRINT_EOR(eor_flag);
12198 }
12199 } else {
12200 if (use_json) {
12201 json_object_boolean_false_add(
12202 json_endofrib_status,
12203 "endOfRibSend");
12204 json_object_boolean_false_add(
12205 json_endofrib_status,
12206 "endOfRibSentAfterUpdate");
12207 } else {
12208 vty_out(vty, "No\n");
12209 vty_out(vty,
12210 " End-of-RIB sent after update: ");
12211 vty_out(vty, "No\n");
12212 }
12213 }
12214
12215 if (!use_json)
12216 vty_out(vty, " End-of-RIB received: ");
12217
12218 if (CHECK_FLAG(peer->af_sflags[afi][safi],
12219 PEER_STATUS_EOR_RECEIVED)) {
12220 if (use_json)
12221 json_object_boolean_true_add(
12222 json_endofrib_status,
12223 "endOfRibRecv");
12224 else
12225 vty_out(vty, "Yes\n");
12226 } else {
12227 if (use_json)
12228 json_object_boolean_false_add(
12229 json_endofrib_status,
12230 "endOfRibRecv");
12231 else
12232 vty_out(vty, "No\n");
12233 }
12234
12235 if (use_json) {
12236 json_object_int_add(json_timer,
12237 "stalePathTimer",
12238 peer->bgp->stalepath_time);
12239
12240 if (peer->t_gr_stale != NULL) {
12241 json_object_int_add(
12242 json_timer,
12243 "stalePathTimerRemaining",
12244 thread_timer_remain_second(
12245 peer->t_gr_stale));
12246 }
12247
12248 /* Display Configured Selection
12249 * Deferral only when when
12250 * Gr mode is enabled.
12251 */
12252 if (CHECK_FLAG(peer->flags,
12253 PEER_FLAG_GRACEFUL_RESTART)) {
12254 json_object_int_add(
12255 json_timer,
12256 "selectionDeferralTimer",
12257 peer->bgp->stalepath_time);
12258 }
12259
12260 if (peer->bgp->gr_info[afi][safi]
12261 .t_select_deferral
12262 != NULL) {
12263
12264 json_object_int_add(
12265 json_timer,
12266 "selectionDeferralTimerRemaining",
12267 thread_timer_remain_second(
12268 peer->bgp
12269 ->gr_info[afi]
12270 [safi]
12271 .t_select_deferral));
12272 }
12273 } else {
12274 vty_out(vty, " Timers:\n");
12275 vty_out(vty,
12276 " Configured Stale Path Time(sec): %u\n",
12277 peer->bgp->stalepath_time);
12278
12279 if (peer->t_gr_stale != NULL)
12280 vty_out(vty,
12281 " Stale Path Remaining(sec): %ld\n",
12282 thread_timer_remain_second(
12283 peer->t_gr_stale));
12284 /* Display Configured Selection
12285 * Deferral only when when
12286 * Gr mode is enabled.
12287 */
12288 if (CHECK_FLAG(peer->flags,
12289 PEER_FLAG_GRACEFUL_RESTART))
12290 vty_out(vty,
12291 " Configured Selection Deferral Time(sec): %u\n",
12292 peer->bgp->select_defer_time);
12293
12294 if (peer->bgp->gr_info[afi][safi]
12295 .t_select_deferral
12296 != NULL)
12297 vty_out(vty,
12298 " Selection Deferral Time Remaining(sec): %ld\n",
12299 thread_timer_remain_second(
12300 peer->bgp
12301 ->gr_info[afi]
12302 [safi]
12303 .t_select_deferral));
12304 }
12305 if (use_json) {
12306 json_object_object_add(json_afi_safi,
12307 "endOfRibStatus",
12308 json_endofrib_status);
12309 json_object_object_add(json_afi_safi, "timers",
12310 json_timer);
12311 json_object_object_add(
12312 json, get_afi_safi_str(afi, safi, true),
12313 json_afi_safi);
12314 }
12315 }
12316 }
12317 }
12318
12319 static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
12320 struct peer *p,
12321 bool use_json,
12322 json_object *json)
12323 {
12324 if (use_json) {
12325 json_object *json_timer = NULL;
12326
12327 json_timer = json_object_new_object();
12328
12329 json_object_int_add(json_timer, "configuredRestartTimer",
12330 p->bgp->restart_time);
12331
12332 json_object_int_add(json_timer, "receivedRestartTimer",
12333 p->v_gr_restart);
12334
12335 if (p->t_gr_restart != NULL)
12336 json_object_int_add(
12337 json_timer, "restartTimerRemaining",
12338 thread_timer_remain_second(p->t_gr_restart));
12339
12340 json_object_object_add(json, "timers", json_timer);
12341 } else {
12342
12343 vty_out(vty, " Timers:\n");
12344 vty_out(vty, " Configured Restart Time(sec): %u\n",
12345 p->bgp->restart_time);
12346
12347 vty_out(vty, " Received Restart Time(sec): %u\n",
12348 p->v_gr_restart);
12349 if (p->t_gr_restart != NULL)
12350 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
12351 thread_timer_remain_second(p->t_gr_restart));
12352 if (p->t_gr_restart != NULL) {
12353 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
12354 thread_timer_remain_second(p->t_gr_restart));
12355 }
12356 }
12357 }
12358
12359 static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
12360 bool use_json, json_object *json)
12361 {
12362 char buf[SU_ADDRSTRLEN] = {0};
12363 char dn_flag[2] = {0};
12364 /* '*' + v6 address of neighbor */
12365 char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
12366
12367 if (!p->conf_if && peer_dynamic_neighbor(p))
12368 dn_flag[0] = '*';
12369
12370 if (p->conf_if) {
12371 if (use_json)
12372 json_object_string_add(
12373 json, "neighborAddr",
12374 BGP_PEER_SU_UNSPEC(p)
12375 ? "none"
12376 : sockunion2str(&p->su, buf,
12377 SU_ADDRSTRLEN));
12378 else
12379 vty_out(vty, "BGP neighbor on %s: %s\n", p->conf_if,
12380 BGP_PEER_SU_UNSPEC(p)
12381 ? "none"
12382 : sockunion2str(&p->su, buf,
12383 SU_ADDRSTRLEN));
12384 } else {
12385 snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
12386 p->host);
12387
12388 if (use_json)
12389 json_object_string_add(json, "neighborAddr",
12390 neighborAddr);
12391 else
12392 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
12393 }
12394
12395 /* more gr info in new format */
12396 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json);
12397 }
12398
12399 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
12400 safi_t safi, bool use_json,
12401 json_object *json_neigh)
12402 {
12403 struct bgp_filter *filter;
12404 struct peer_af *paf;
12405 char orf_pfx_name[BUFSIZ];
12406 int orf_pfx_count;
12407 json_object *json_af = NULL;
12408 json_object *json_prefA = NULL;
12409 json_object *json_prefB = NULL;
12410 json_object *json_addr = NULL;
12411 json_object *json_advmap = NULL;
12412
12413 if (use_json) {
12414 json_addr = json_object_new_object();
12415 json_af = json_object_new_object();
12416 filter = &p->filter[afi][safi];
12417
12418 if (peer_group_active(p))
12419 json_object_string_add(json_addr, "peerGroupMember",
12420 p->group->name);
12421
12422 paf = peer_af_find(p, afi, safi);
12423 if (paf && PAF_SUBGRP(paf)) {
12424 json_object_int_add(json_addr, "updateGroupId",
12425 PAF_UPDGRP(paf)->id);
12426 json_object_int_add(json_addr, "subGroupId",
12427 PAF_SUBGRP(paf)->id);
12428 json_object_int_add(json_addr, "packetQueueLength",
12429 bpacket_queue_virtual_length(paf));
12430 }
12431
12432 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12433 || CHECK_FLAG(p->af_cap[afi][safi],
12434 PEER_CAP_ORF_PREFIX_SM_RCV)
12435 || CHECK_FLAG(p->af_cap[afi][safi],
12436 PEER_CAP_ORF_PREFIX_RM_ADV)
12437 || CHECK_FLAG(p->af_cap[afi][safi],
12438 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12439 json_object_int_add(json_af, "orfType",
12440 ORF_TYPE_PREFIX);
12441 json_prefA = json_object_new_object();
12442 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
12443 PEER_CAP_ORF_PREFIX_SM_ADV,
12444 PEER_CAP_ORF_PREFIX_RM_ADV,
12445 PEER_CAP_ORF_PREFIX_SM_RCV,
12446 PEER_CAP_ORF_PREFIX_RM_RCV,
12447 use_json, json_prefA);
12448 json_object_object_add(json_af, "orfPrefixList",
12449 json_prefA);
12450 }
12451
12452 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12453 || CHECK_FLAG(p->af_cap[afi][safi],
12454 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12455 || CHECK_FLAG(p->af_cap[afi][safi],
12456 PEER_CAP_ORF_PREFIX_RM_ADV)
12457 || CHECK_FLAG(p->af_cap[afi][safi],
12458 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12459 json_object_int_add(json_af, "orfOldType",
12460 ORF_TYPE_PREFIX_OLD);
12461 json_prefB = json_object_new_object();
12462 bgp_show_peer_afi_orf_cap(
12463 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12464 PEER_CAP_ORF_PREFIX_RM_ADV,
12465 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12466 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
12467 json_prefB);
12468 json_object_object_add(json_af, "orfOldPrefixList",
12469 json_prefB);
12470 }
12471
12472 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12473 || CHECK_FLAG(p->af_cap[afi][safi],
12474 PEER_CAP_ORF_PREFIX_SM_RCV)
12475 || CHECK_FLAG(p->af_cap[afi][safi],
12476 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12477 || CHECK_FLAG(p->af_cap[afi][safi],
12478 PEER_CAP_ORF_PREFIX_RM_ADV)
12479 || CHECK_FLAG(p->af_cap[afi][safi],
12480 PEER_CAP_ORF_PREFIX_RM_RCV)
12481 || CHECK_FLAG(p->af_cap[afi][safi],
12482 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12483 json_object_object_add(json_addr, "afDependentCap",
12484 json_af);
12485 else
12486 json_object_free(json_af);
12487
12488 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12489 p->host, afi, safi);
12490 orf_pfx_count = prefix_bgp_show_prefix_list(
12491 NULL, afi, orf_pfx_name, use_json);
12492
12493 if (CHECK_FLAG(p->af_sflags[afi][safi],
12494 PEER_STATUS_ORF_PREFIX_SEND)
12495 || orf_pfx_count) {
12496 if (CHECK_FLAG(p->af_sflags[afi][safi],
12497 PEER_STATUS_ORF_PREFIX_SEND))
12498 json_object_boolean_true_add(json_neigh,
12499 "orfSent");
12500 if (orf_pfx_count)
12501 json_object_int_add(json_addr, "orfRecvCounter",
12502 orf_pfx_count);
12503 }
12504 if (CHECK_FLAG(p->af_sflags[afi][safi],
12505 PEER_STATUS_ORF_WAIT_REFRESH))
12506 json_object_string_add(
12507 json_addr, "orfFirstUpdate",
12508 "deferredUntilORFOrRouteRefreshRecvd");
12509
12510 if (CHECK_FLAG(p->af_flags[afi][safi],
12511 PEER_FLAG_REFLECTOR_CLIENT))
12512 json_object_boolean_true_add(json_addr,
12513 "routeReflectorClient");
12514 if (CHECK_FLAG(p->af_flags[afi][safi],
12515 PEER_FLAG_RSERVER_CLIENT))
12516 json_object_boolean_true_add(json_addr,
12517 "routeServerClient");
12518 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12519 json_object_boolean_true_add(json_addr,
12520 "inboundSoftConfigPermit");
12521
12522 if (CHECK_FLAG(p->af_flags[afi][safi],
12523 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12524 json_object_boolean_true_add(
12525 json_addr,
12526 "privateAsNumsAllReplacedInUpdatesToNbr");
12527 else if (CHECK_FLAG(p->af_flags[afi][safi],
12528 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12529 json_object_boolean_true_add(
12530 json_addr,
12531 "privateAsNumsReplacedInUpdatesToNbr");
12532 else if (CHECK_FLAG(p->af_flags[afi][safi],
12533 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12534 json_object_boolean_true_add(
12535 json_addr,
12536 "privateAsNumsAllRemovedInUpdatesToNbr");
12537 else if (CHECK_FLAG(p->af_flags[afi][safi],
12538 PEER_FLAG_REMOVE_PRIVATE_AS))
12539 json_object_boolean_true_add(
12540 json_addr,
12541 "privateAsNumsRemovedInUpdatesToNbr");
12542
12543 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12544 json_object_boolean_true_add(
12545 json_addr,
12546 bgp_addpath_names(p->addpath_type[afi][safi])
12547 ->type_json_name);
12548
12549 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12550 json_object_string_add(json_addr,
12551 "overrideASNsInOutboundUpdates",
12552 "ifAspathEqualRemoteAs");
12553
12554 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12555 || CHECK_FLAG(p->af_flags[afi][safi],
12556 PEER_FLAG_FORCE_NEXTHOP_SELF))
12557 json_object_boolean_true_add(json_addr,
12558 "routerAlwaysNextHop");
12559 if (CHECK_FLAG(p->af_flags[afi][safi],
12560 PEER_FLAG_AS_PATH_UNCHANGED))
12561 json_object_boolean_true_add(
12562 json_addr, "unchangedAsPathPropogatedToNbr");
12563 if (CHECK_FLAG(p->af_flags[afi][safi],
12564 PEER_FLAG_NEXTHOP_UNCHANGED))
12565 json_object_boolean_true_add(
12566 json_addr, "unchangedNextHopPropogatedToNbr");
12567 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12568 json_object_boolean_true_add(
12569 json_addr, "unchangedMedPropogatedToNbr");
12570 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12571 || CHECK_FLAG(p->af_flags[afi][safi],
12572 PEER_FLAG_SEND_EXT_COMMUNITY)) {
12573 if (CHECK_FLAG(p->af_flags[afi][safi],
12574 PEER_FLAG_SEND_COMMUNITY)
12575 && CHECK_FLAG(p->af_flags[afi][safi],
12576 PEER_FLAG_SEND_EXT_COMMUNITY))
12577 json_object_string_add(json_addr,
12578 "commAttriSentToNbr",
12579 "extendedAndStandard");
12580 else if (CHECK_FLAG(p->af_flags[afi][safi],
12581 PEER_FLAG_SEND_EXT_COMMUNITY))
12582 json_object_string_add(json_addr,
12583 "commAttriSentToNbr",
12584 "extended");
12585 else
12586 json_object_string_add(json_addr,
12587 "commAttriSentToNbr",
12588 "standard");
12589 }
12590 if (CHECK_FLAG(p->af_flags[afi][safi],
12591 PEER_FLAG_DEFAULT_ORIGINATE)) {
12592 if (p->default_rmap[afi][safi].name)
12593 json_object_string_add(
12594 json_addr, "defaultRouteMap",
12595 p->default_rmap[afi][safi].name);
12596
12597 if (paf && PAF_SUBGRP(paf)
12598 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12599 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12600 json_object_boolean_true_add(json_addr,
12601 "defaultSent");
12602 else
12603 json_object_boolean_true_add(json_addr,
12604 "defaultNotSent");
12605 }
12606
12607 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
12608 if (is_evpn_enabled())
12609 json_object_boolean_true_add(
12610 json_addr, "advertiseAllVnis");
12611 }
12612
12613 if (filter->plist[FILTER_IN].name
12614 || filter->dlist[FILTER_IN].name
12615 || filter->aslist[FILTER_IN].name
12616 || filter->map[RMAP_IN].name)
12617 json_object_boolean_true_add(json_addr,
12618 "inboundPathPolicyConfig");
12619 if (filter->plist[FILTER_OUT].name
12620 || filter->dlist[FILTER_OUT].name
12621 || filter->aslist[FILTER_OUT].name
12622 || filter->map[RMAP_OUT].name || filter->usmap.name)
12623 json_object_boolean_true_add(
12624 json_addr, "outboundPathPolicyConfig");
12625
12626 /* prefix-list */
12627 if (filter->plist[FILTER_IN].name)
12628 json_object_string_add(json_addr,
12629 "incomingUpdatePrefixFilterList",
12630 filter->plist[FILTER_IN].name);
12631 if (filter->plist[FILTER_OUT].name)
12632 json_object_string_add(json_addr,
12633 "outgoingUpdatePrefixFilterList",
12634 filter->plist[FILTER_OUT].name);
12635
12636 /* distribute-list */
12637 if (filter->dlist[FILTER_IN].name)
12638 json_object_string_add(
12639 json_addr, "incomingUpdateNetworkFilterList",
12640 filter->dlist[FILTER_IN].name);
12641 if (filter->dlist[FILTER_OUT].name)
12642 json_object_string_add(
12643 json_addr, "outgoingUpdateNetworkFilterList",
12644 filter->dlist[FILTER_OUT].name);
12645
12646 /* filter-list. */
12647 if (filter->aslist[FILTER_IN].name)
12648 json_object_string_add(json_addr,
12649 "incomingUpdateAsPathFilterList",
12650 filter->aslist[FILTER_IN].name);
12651 if (filter->aslist[FILTER_OUT].name)
12652 json_object_string_add(json_addr,
12653 "outgoingUpdateAsPathFilterList",
12654 filter->aslist[FILTER_OUT].name);
12655
12656 /* route-map. */
12657 if (filter->map[RMAP_IN].name)
12658 json_object_string_add(
12659 json_addr, "routeMapForIncomingAdvertisements",
12660 filter->map[RMAP_IN].name);
12661 if (filter->map[RMAP_OUT].name)
12662 json_object_string_add(
12663 json_addr, "routeMapForOutgoingAdvertisements",
12664 filter->map[RMAP_OUT].name);
12665
12666 /* ebgp-requires-policy (inbound) */
12667 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12668 && !bgp_inbound_policy_exists(p, filter))
12669 json_object_string_add(
12670 json_addr, "inboundEbgpRequiresPolicy",
12671 "Inbound updates discarded due to missing policy");
12672
12673 /* ebgp-requires-policy (outbound) */
12674 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12675 && (!bgp_outbound_policy_exists(p, filter)))
12676 json_object_string_add(
12677 json_addr, "outboundEbgpRequiresPolicy",
12678 "Outbound updates discarded due to missing policy");
12679
12680 /* unsuppress-map */
12681 if (filter->usmap.name)
12682 json_object_string_add(json_addr,
12683 "selectiveUnsuppressRouteMap",
12684 filter->usmap.name);
12685
12686 /* advertise-map */
12687 if (filter->advmap.aname) {
12688 json_advmap = json_object_new_object();
12689 json_object_string_add(json_advmap, "condition",
12690 filter->advmap.condition
12691 ? "EXIST"
12692 : "NON_EXIST");
12693 json_object_string_add(json_advmap, "conditionMap",
12694 filter->advmap.cname);
12695 json_object_string_add(json_advmap, "advertiseMap",
12696 filter->advmap.aname);
12697 json_object_string_add(json_advmap, "advertiseStatus",
12698 filter->advmap.update_type
12699 == ADVERTISE
12700 ? "Advertise"
12701 : "Withdraw");
12702 json_object_object_add(json_addr, "advertiseMap",
12703 json_advmap);
12704 }
12705
12706 /* Receive prefix count */
12707 json_object_int_add(json_addr, "acceptedPrefixCounter",
12708 p->pcount[afi][safi]);
12709 if (paf && PAF_SUBGRP(paf))
12710 json_object_int_add(json_addr, "sentPrefixCounter",
12711 (PAF_SUBGRP(paf))->scount);
12712
12713 /* Maximum prefix */
12714 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
12715 json_object_int_add(json_addr, "prefixOutAllowedMax",
12716 p->pmax_out[afi][safi]);
12717
12718 /* Maximum prefix */
12719 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12720 json_object_int_add(json_addr, "prefixAllowedMax",
12721 p->pmax[afi][safi]);
12722 if (CHECK_FLAG(p->af_flags[afi][safi],
12723 PEER_FLAG_MAX_PREFIX_WARNING))
12724 json_object_boolean_true_add(
12725 json_addr, "prefixAllowedMaxWarning");
12726 json_object_int_add(json_addr,
12727 "prefixAllowedWarningThresh",
12728 p->pmax_threshold[afi][safi]);
12729 if (p->pmax_restart[afi][safi])
12730 json_object_int_add(
12731 json_addr,
12732 "prefixAllowedRestartIntervalMsecs",
12733 p->pmax_restart[afi][safi] * 60000);
12734 }
12735 json_object_object_add(json_neigh,
12736 get_afi_safi_str(afi, safi, true),
12737 json_addr);
12738
12739 } else {
12740 filter = &p->filter[afi][safi];
12741
12742 vty_out(vty, " For address family: %s\n",
12743 get_afi_safi_str(afi, safi, false));
12744
12745 if (peer_group_active(p))
12746 vty_out(vty, " %s peer-group member\n",
12747 p->group->name);
12748
12749 paf = peer_af_find(p, afi, safi);
12750 if (paf && PAF_SUBGRP(paf)) {
12751 vty_out(vty, " Update group %" PRIu64", subgroup %" PRIu64 "\n",
12752 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
12753 vty_out(vty, " Packet Queue length %d\n",
12754 bpacket_queue_virtual_length(paf));
12755 } else {
12756 vty_out(vty, " Not part of any update group\n");
12757 }
12758 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12759 || CHECK_FLAG(p->af_cap[afi][safi],
12760 PEER_CAP_ORF_PREFIX_SM_RCV)
12761 || CHECK_FLAG(p->af_cap[afi][safi],
12762 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12763 || CHECK_FLAG(p->af_cap[afi][safi],
12764 PEER_CAP_ORF_PREFIX_RM_ADV)
12765 || CHECK_FLAG(p->af_cap[afi][safi],
12766 PEER_CAP_ORF_PREFIX_RM_RCV)
12767 || CHECK_FLAG(p->af_cap[afi][safi],
12768 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12769 vty_out(vty, " AF-dependant capabilities:\n");
12770
12771 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12772 || CHECK_FLAG(p->af_cap[afi][safi],
12773 PEER_CAP_ORF_PREFIX_SM_RCV)
12774 || CHECK_FLAG(p->af_cap[afi][safi],
12775 PEER_CAP_ORF_PREFIX_RM_ADV)
12776 || CHECK_FLAG(p->af_cap[afi][safi],
12777 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12778 vty_out(vty,
12779 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12780 ORF_TYPE_PREFIX);
12781 bgp_show_peer_afi_orf_cap(
12782 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12783 PEER_CAP_ORF_PREFIX_RM_ADV,
12784 PEER_CAP_ORF_PREFIX_SM_RCV,
12785 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
12786 }
12787 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12788 || CHECK_FLAG(p->af_cap[afi][safi],
12789 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12790 || CHECK_FLAG(p->af_cap[afi][safi],
12791 PEER_CAP_ORF_PREFIX_RM_ADV)
12792 || CHECK_FLAG(p->af_cap[afi][safi],
12793 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12794 vty_out(vty,
12795 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12796 ORF_TYPE_PREFIX_OLD);
12797 bgp_show_peer_afi_orf_cap(
12798 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12799 PEER_CAP_ORF_PREFIX_RM_ADV,
12800 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12801 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
12802 }
12803
12804 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12805 p->host, afi, safi);
12806 orf_pfx_count = prefix_bgp_show_prefix_list(
12807 NULL, afi, orf_pfx_name, use_json);
12808
12809 if (CHECK_FLAG(p->af_sflags[afi][safi],
12810 PEER_STATUS_ORF_PREFIX_SEND)
12811 || orf_pfx_count) {
12812 vty_out(vty, " Outbound Route Filter (ORF):");
12813 if (CHECK_FLAG(p->af_sflags[afi][safi],
12814 PEER_STATUS_ORF_PREFIX_SEND))
12815 vty_out(vty, " sent;");
12816 if (orf_pfx_count)
12817 vty_out(vty, " received (%d entries)",
12818 orf_pfx_count);
12819 vty_out(vty, "\n");
12820 }
12821 if (CHECK_FLAG(p->af_sflags[afi][safi],
12822 PEER_STATUS_ORF_WAIT_REFRESH))
12823 vty_out(vty,
12824 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
12825
12826 if (CHECK_FLAG(p->af_flags[afi][safi],
12827 PEER_FLAG_REFLECTOR_CLIENT))
12828 vty_out(vty, " Route-Reflector Client\n");
12829 if (CHECK_FLAG(p->af_flags[afi][safi],
12830 PEER_FLAG_RSERVER_CLIENT))
12831 vty_out(vty, " Route-Server Client\n");
12832 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12833 vty_out(vty,
12834 " Inbound soft reconfiguration allowed\n");
12835
12836 if (CHECK_FLAG(p->af_flags[afi][safi],
12837 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12838 vty_out(vty,
12839 " Private AS numbers (all) replaced in updates to this neighbor\n");
12840 else if (CHECK_FLAG(p->af_flags[afi][safi],
12841 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12842 vty_out(vty,
12843 " Private AS numbers replaced in updates to this neighbor\n");
12844 else if (CHECK_FLAG(p->af_flags[afi][safi],
12845 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12846 vty_out(vty,
12847 " Private AS numbers (all) removed in updates to this neighbor\n");
12848 else if (CHECK_FLAG(p->af_flags[afi][safi],
12849 PEER_FLAG_REMOVE_PRIVATE_AS))
12850 vty_out(vty,
12851 " Private AS numbers removed in updates to this neighbor\n");
12852
12853 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12854 vty_out(vty, " %s\n",
12855 bgp_addpath_names(p->addpath_type[afi][safi])
12856 ->human_description);
12857
12858 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12859 vty_out(vty,
12860 " Override ASNs in outbound updates if aspath equals remote-as\n");
12861
12862 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12863 || CHECK_FLAG(p->af_flags[afi][safi],
12864 PEER_FLAG_FORCE_NEXTHOP_SELF))
12865 vty_out(vty, " NEXT_HOP is always this router\n");
12866 if (CHECK_FLAG(p->af_flags[afi][safi],
12867 PEER_FLAG_AS_PATH_UNCHANGED))
12868 vty_out(vty,
12869 " AS_PATH is propagated unchanged to this neighbor\n");
12870 if (CHECK_FLAG(p->af_flags[afi][safi],
12871 PEER_FLAG_NEXTHOP_UNCHANGED))
12872 vty_out(vty,
12873 " NEXT_HOP is propagated unchanged to this neighbor\n");
12874 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12875 vty_out(vty,
12876 " MED is propagated unchanged to this neighbor\n");
12877 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12878 || CHECK_FLAG(p->af_flags[afi][safi],
12879 PEER_FLAG_SEND_EXT_COMMUNITY)
12880 || CHECK_FLAG(p->af_flags[afi][safi],
12881 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
12882 vty_out(vty,
12883 " Community attribute sent to this neighbor");
12884 if (CHECK_FLAG(p->af_flags[afi][safi],
12885 PEER_FLAG_SEND_COMMUNITY)
12886 && CHECK_FLAG(p->af_flags[afi][safi],
12887 PEER_FLAG_SEND_EXT_COMMUNITY)
12888 && CHECK_FLAG(p->af_flags[afi][safi],
12889 PEER_FLAG_SEND_LARGE_COMMUNITY))
12890 vty_out(vty, "(all)\n");
12891 else if (CHECK_FLAG(p->af_flags[afi][safi],
12892 PEER_FLAG_SEND_LARGE_COMMUNITY))
12893 vty_out(vty, "(large)\n");
12894 else if (CHECK_FLAG(p->af_flags[afi][safi],
12895 PEER_FLAG_SEND_EXT_COMMUNITY))
12896 vty_out(vty, "(extended)\n");
12897 else
12898 vty_out(vty, "(standard)\n");
12899 }
12900 if (CHECK_FLAG(p->af_flags[afi][safi],
12901 PEER_FLAG_DEFAULT_ORIGINATE)) {
12902 vty_out(vty, " Default information originate,");
12903
12904 if (p->default_rmap[afi][safi].name)
12905 vty_out(vty, " default route-map %s%s,",
12906 p->default_rmap[afi][safi].map ? "*"
12907 : "",
12908 p->default_rmap[afi][safi].name);
12909 if (paf && PAF_SUBGRP(paf)
12910 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12911 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12912 vty_out(vty, " default sent\n");
12913 else
12914 vty_out(vty, " default not sent\n");
12915 }
12916
12917 /* advertise-vni-all */
12918 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
12919 if (is_evpn_enabled())
12920 vty_out(vty, " advertise-all-vni\n");
12921 }
12922
12923 if (filter->plist[FILTER_IN].name
12924 || filter->dlist[FILTER_IN].name
12925 || filter->aslist[FILTER_IN].name
12926 || filter->map[RMAP_IN].name)
12927 vty_out(vty, " Inbound path policy configured\n");
12928 if (filter->plist[FILTER_OUT].name
12929 || filter->dlist[FILTER_OUT].name
12930 || filter->aslist[FILTER_OUT].name
12931 || filter->map[RMAP_OUT].name || filter->usmap.name)
12932 vty_out(vty, " Outbound path policy configured\n");
12933
12934 /* prefix-list */
12935 if (filter->plist[FILTER_IN].name)
12936 vty_out(vty,
12937 " Incoming update prefix filter list is %s%s\n",
12938 filter->plist[FILTER_IN].plist ? "*" : "",
12939 filter->plist[FILTER_IN].name);
12940 if (filter->plist[FILTER_OUT].name)
12941 vty_out(vty,
12942 " Outgoing update prefix filter list is %s%s\n",
12943 filter->plist[FILTER_OUT].plist ? "*" : "",
12944 filter->plist[FILTER_OUT].name);
12945
12946 /* distribute-list */
12947 if (filter->dlist[FILTER_IN].name)
12948 vty_out(vty,
12949 " Incoming update network filter list is %s%s\n",
12950 filter->dlist[FILTER_IN].alist ? "*" : "",
12951 filter->dlist[FILTER_IN].name);
12952 if (filter->dlist[FILTER_OUT].name)
12953 vty_out(vty,
12954 " Outgoing update network filter list is %s%s\n",
12955 filter->dlist[FILTER_OUT].alist ? "*" : "",
12956 filter->dlist[FILTER_OUT].name);
12957
12958 /* filter-list. */
12959 if (filter->aslist[FILTER_IN].name)
12960 vty_out(vty,
12961 " Incoming update AS path filter list is %s%s\n",
12962 filter->aslist[FILTER_IN].aslist ? "*" : "",
12963 filter->aslist[FILTER_IN].name);
12964 if (filter->aslist[FILTER_OUT].name)
12965 vty_out(vty,
12966 " Outgoing update AS path filter list is %s%s\n",
12967 filter->aslist[FILTER_OUT].aslist ? "*" : "",
12968 filter->aslist[FILTER_OUT].name);
12969
12970 /* route-map. */
12971 if (filter->map[RMAP_IN].name)
12972 vty_out(vty,
12973 " Route map for incoming advertisements is %s%s\n",
12974 filter->map[RMAP_IN].map ? "*" : "",
12975 filter->map[RMAP_IN].name);
12976 if (filter->map[RMAP_OUT].name)
12977 vty_out(vty,
12978 " Route map for outgoing advertisements is %s%s\n",
12979 filter->map[RMAP_OUT].map ? "*" : "",
12980 filter->map[RMAP_OUT].name);
12981
12982 /* ebgp-requires-policy (inbound) */
12983 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12984 && !bgp_inbound_policy_exists(p, filter))
12985 vty_out(vty,
12986 " Inbound updates discarded due to missing policy\n");
12987
12988 /* ebgp-requires-policy (outbound) */
12989 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12990 && !bgp_outbound_policy_exists(p, filter))
12991 vty_out(vty,
12992 " Outbound updates discarded due to missing policy\n");
12993
12994 /* unsuppress-map */
12995 if (filter->usmap.name)
12996 vty_out(vty,
12997 " Route map for selective unsuppress is %s%s\n",
12998 filter->usmap.map ? "*" : "",
12999 filter->usmap.name);
13000
13001 /* advertise-map */
13002 if (filter->advmap.aname && filter->advmap.cname)
13003 vty_out(vty,
13004 " Condition %s, Condition-map %s%s, Advertise-map %s%s, status: %s\n",
13005 filter->advmap.condition ? "EXIST"
13006 : "NON_EXIST",
13007 filter->advmap.cmap ? "*" : "",
13008 filter->advmap.cname,
13009 filter->advmap.amap ? "*" : "",
13010 filter->advmap.aname,
13011 filter->advmap.update_type == ADVERTISE
13012 ? "Advertise"
13013 : "Withdraw");
13014
13015 /* Receive prefix count */
13016 vty_out(vty, " %u accepted prefixes\n",
13017 p->pcount[afi][safi]);
13018
13019 /* maximum-prefix-out */
13020 if (CHECK_FLAG(p->af_flags[afi][safi],
13021 PEER_FLAG_MAX_PREFIX_OUT))
13022 vty_out(vty,
13023 " Maximum allowed prefixes sent %u\n",
13024 p->pmax_out[afi][safi]);
13025
13026 /* Maximum prefix */
13027 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
13028 vty_out(vty,
13029 " Maximum prefixes allowed %u%s\n",
13030 p->pmax[afi][safi],
13031 CHECK_FLAG(p->af_flags[afi][safi],
13032 PEER_FLAG_MAX_PREFIX_WARNING)
13033 ? " (warning-only)"
13034 : "");
13035 vty_out(vty, " Threshold for warning message %d%%",
13036 p->pmax_threshold[afi][safi]);
13037 if (p->pmax_restart[afi][safi])
13038 vty_out(vty, ", restart interval %d min",
13039 p->pmax_restart[afi][safi]);
13040 vty_out(vty, "\n");
13041 }
13042
13043 vty_out(vty, "\n");
13044 }
13045 }
13046
13047 static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
13048 json_object *json)
13049 {
13050 struct bgp *bgp;
13051 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
13052 char timebuf[BGP_UPTIME_LEN];
13053 char dn_flag[2];
13054 afi_t afi;
13055 safi_t safi;
13056 uint16_t i;
13057 uint8_t *msg;
13058 json_object *json_neigh = NULL;
13059 time_t epoch_tbuf;
13060 uint32_t sync_tcp_mss;
13061
13062 bgp = p->bgp;
13063
13064 if (use_json)
13065 json_neigh = json_object_new_object();
13066
13067 memset(dn_flag, '\0', sizeof(dn_flag));
13068 if (!p->conf_if && peer_dynamic_neighbor(p))
13069 dn_flag[0] = '*';
13070
13071 if (!use_json) {
13072 if (p->conf_if) /* Configured interface name. */
13073 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
13074 BGP_PEER_SU_UNSPEC(p)
13075 ? "None"
13076 : sockunion2str(&p->su, buf,
13077 SU_ADDRSTRLEN));
13078 else /* Configured IP address. */
13079 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
13080 p->host);
13081 }
13082
13083 if (use_json) {
13084 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
13085 json_object_string_add(json_neigh, "bgpNeighborAddr",
13086 "none");
13087 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
13088 json_object_string_add(
13089 json_neigh, "bgpNeighborAddr",
13090 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
13091
13092 json_object_int_add(json_neigh, "remoteAs", p->as);
13093
13094 if (p->change_local_as)
13095 json_object_int_add(json_neigh, "localAs",
13096 p->change_local_as);
13097 else
13098 json_object_int_add(json_neigh, "localAs", p->local_as);
13099
13100 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
13101 json_object_boolean_true_add(json_neigh,
13102 "localAsNoPrepend");
13103
13104 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
13105 json_object_boolean_true_add(json_neigh,
13106 "localAsReplaceAs");
13107 } else {
13108 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
13109 || (p->as_type == AS_INTERNAL))
13110 vty_out(vty, "remote AS %u, ", p->as);
13111 else
13112 vty_out(vty, "remote AS Unspecified, ");
13113 vty_out(vty, "local AS %u%s%s, ",
13114 p->change_local_as ? p->change_local_as : p->local_as,
13115 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
13116 ? " no-prepend"
13117 : "",
13118 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
13119 ? " replace-as"
13120 : "");
13121 }
13122 /* peer type internal or confed-internal */
13123 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
13124 if (use_json) {
13125 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
13126 json_object_boolean_true_add(
13127 json_neigh, "nbrConfedInternalLink");
13128 else
13129 json_object_boolean_true_add(json_neigh,
13130 "nbrInternalLink");
13131 } else {
13132 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
13133 vty_out(vty, "confed-internal link\n");
13134 else
13135 vty_out(vty, "internal link\n");
13136 }
13137 /* peer type external or confed-external */
13138 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
13139 if (use_json) {
13140 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
13141 json_object_boolean_true_add(
13142 json_neigh, "nbrConfedExternalLink");
13143 else
13144 json_object_boolean_true_add(json_neigh,
13145 "nbrExternalLink");
13146 } else {
13147 if (bgp_confederation_peers_check(bgp, p->as))
13148 vty_out(vty, "confed-external link\n");
13149 else
13150 vty_out(vty, "external link\n");
13151 }
13152 } else {
13153 if (use_json)
13154 json_object_boolean_true_add(json_neigh,
13155 "nbrUnspecifiedLink");
13156 else
13157 vty_out(vty, "unspecified link\n");
13158 }
13159
13160 /* Description. */
13161 if (p->desc) {
13162 if (use_json)
13163 json_object_string_add(json_neigh, "nbrDesc", p->desc);
13164 else
13165 vty_out(vty, " Description: %s\n", p->desc);
13166 }
13167
13168 if (p->hostname) {
13169 if (use_json) {
13170 if (p->hostname)
13171 json_object_string_add(json_neigh, "hostname",
13172 p->hostname);
13173
13174 if (p->domainname)
13175 json_object_string_add(json_neigh, "domainname",
13176 p->domainname);
13177 } else {
13178 if (p->domainname && (p->domainname[0] != '\0'))
13179 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
13180 p->domainname);
13181 else
13182 vty_out(vty, "Hostname: %s\n", p->hostname);
13183 }
13184 }
13185
13186 /* Peer-group */
13187 if (p->group) {
13188 if (use_json) {
13189 json_object_string_add(json_neigh, "peerGroup",
13190 p->group->name);
13191
13192 if (dn_flag[0]) {
13193 struct prefix prefix, *range = NULL;
13194
13195 if (sockunion2hostprefix(&(p->su), &prefix))
13196 range = peer_group_lookup_dynamic_neighbor_range(
13197 p->group, &prefix);
13198
13199 if (range) {
13200 prefix2str(range, buf1, sizeof(buf1));
13201 json_object_string_add(
13202 json_neigh,
13203 "peerSubnetRangeGroup", buf1);
13204 }
13205 }
13206 } else {
13207 vty_out(vty,
13208 " Member of peer-group %s for session parameters\n",
13209 p->group->name);
13210
13211 if (dn_flag[0]) {
13212 struct prefix prefix, *range = NULL;
13213
13214 if (sockunion2hostprefix(&(p->su), &prefix))
13215 range = peer_group_lookup_dynamic_neighbor_range(
13216 p->group, &prefix);
13217
13218 if (range) {
13219 vty_out(vty,
13220 " Belongs to the subnet range group: %pFX\n",
13221 range);
13222 }
13223 }
13224 }
13225 }
13226
13227 if (use_json) {
13228 /* Administrative shutdown. */
13229 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
13230 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
13231 json_object_boolean_true_add(json_neigh,
13232 "adminShutDown");
13233
13234 /* BGP Version. */
13235 json_object_int_add(json_neigh, "bgpVersion", 4);
13236 json_object_string_add(
13237 json_neigh, "remoteRouterId",
13238 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
13239 json_object_string_add(
13240 json_neigh, "localRouterId",
13241 inet_ntop(AF_INET, &bgp->router_id, buf1,
13242 sizeof(buf1)));
13243
13244 /* Confederation */
13245 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
13246 && bgp_confederation_peers_check(bgp, p->as))
13247 json_object_boolean_true_add(json_neigh,
13248 "nbrCommonAdmin");
13249
13250 /* Status. */
13251 json_object_string_add(
13252 json_neigh, "bgpState",
13253 lookup_msg(bgp_status_msg, p->status, NULL));
13254
13255 if (peer_established(p)) {
13256 time_t uptime;
13257
13258 uptime = bgp_clock();
13259 uptime -= p->uptime;
13260 epoch_tbuf = time(NULL) - uptime;
13261
13262 json_object_int_add(json_neigh, "bgpTimerUpMsec",
13263 uptime * 1000);
13264 json_object_string_add(json_neigh, "bgpTimerUpString",
13265 peer_uptime(p->uptime, timebuf,
13266 BGP_UPTIME_LEN, 0,
13267 NULL));
13268 json_object_int_add(json_neigh,
13269 "bgpTimerUpEstablishedEpoch",
13270 epoch_tbuf);
13271 }
13272
13273 else if (p->status == Active) {
13274 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
13275 json_object_string_add(json_neigh, "bgpStateIs",
13276 "passive");
13277 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
13278 json_object_string_add(json_neigh, "bgpStateIs",
13279 "passiveNSF");
13280 }
13281
13282 /* read timer */
13283 time_t uptime;
13284 struct tm tm;
13285
13286 uptime = bgp_clock();
13287 uptime -= p->readtime;
13288 gmtime_r(&uptime, &tm);
13289
13290 json_object_int_add(json_neigh, "bgpTimerLastRead",
13291 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
13292 + (tm.tm_hour * 3600000));
13293
13294 uptime = bgp_clock();
13295 uptime -= p->last_write;
13296 gmtime_r(&uptime, &tm);
13297
13298 json_object_int_add(json_neigh, "bgpTimerLastWrite",
13299 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
13300 + (tm.tm_hour * 3600000));
13301
13302 uptime = bgp_clock();
13303 uptime -= p->update_time;
13304 gmtime_r(&uptime, &tm);
13305
13306 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
13307 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
13308 + (tm.tm_hour * 3600000));
13309
13310 /* Configured timer values. */
13311 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
13312 p->v_holdtime * 1000);
13313 json_object_int_add(json_neigh,
13314 "bgpTimerKeepAliveIntervalMsecs",
13315 p->v_keepalive * 1000);
13316 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN)) {
13317 json_object_int_add(json_neigh,
13318 "bgpTimerDelayOpenTimeMsecs",
13319 p->v_delayopen * 1000);
13320 }
13321
13322 /* Configured and Synced tcp-mss value for peer */
13323 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
13324 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
13325 json_object_int_add(json_neigh, "bgpTcpMssConfigured",
13326 p->tcp_mss);
13327 json_object_int_add(json_neigh, "bgpTcpMssSynced",
13328 sync_tcp_mss);
13329 }
13330
13331 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
13332 json_object_int_add(json_neigh,
13333 "bgpTimerConfiguredHoldTimeMsecs",
13334 p->holdtime * 1000);
13335 json_object_int_add(
13336 json_neigh,
13337 "bgpTimerConfiguredKeepAliveIntervalMsecs",
13338 p->keepalive * 1000);
13339 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
13340 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
13341 json_object_int_add(json_neigh,
13342 "bgpTimerConfiguredHoldTimeMsecs",
13343 bgp->default_holdtime);
13344 json_object_int_add(
13345 json_neigh,
13346 "bgpTimerConfiguredKeepAliveIntervalMsecs",
13347 bgp->default_keepalive);
13348 }
13349 } else {
13350 /* Administrative shutdown. */
13351 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
13352 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
13353 vty_out(vty, " Administratively shut down\n");
13354
13355 /* BGP Version. */
13356 vty_out(vty, " BGP version 4");
13357 vty_out(vty, ", remote router ID %s",
13358 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
13359 vty_out(vty, ", local router ID %s\n",
13360 inet_ntop(AF_INET, &bgp->router_id, buf1,
13361 sizeof(buf1)));
13362
13363 /* Confederation */
13364 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
13365 && bgp_confederation_peers_check(bgp, p->as))
13366 vty_out(vty,
13367 " Neighbor under common administration\n");
13368
13369 /* Status. */
13370 vty_out(vty, " BGP state = %s",
13371 lookup_msg(bgp_status_msg, p->status, NULL));
13372
13373 if (peer_established(p))
13374 vty_out(vty, ", up for %8s",
13375 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
13376 0, NULL));
13377
13378 else if (p->status == Active) {
13379 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
13380 vty_out(vty, " (passive)");
13381 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
13382 vty_out(vty, " (NSF passive)");
13383 }
13384 vty_out(vty, "\n");
13385
13386 /* read timer */
13387 vty_out(vty, " Last read %s",
13388 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
13389 NULL));
13390 vty_out(vty, ", Last write %s\n",
13391 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
13392 NULL));
13393
13394 /* Configured timer values. */
13395 vty_out(vty,
13396 " Hold time is %d, keepalive interval is %d seconds\n",
13397 p->v_holdtime, p->v_keepalive);
13398 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
13399 vty_out(vty, " Configured hold time is %d",
13400 p->holdtime);
13401 vty_out(vty, ", keepalive interval is %d seconds\n",
13402 p->keepalive);
13403 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
13404 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
13405 vty_out(vty, " Configured hold time is %d",
13406 bgp->default_holdtime);
13407 vty_out(vty, ", keepalive interval is %d seconds\n",
13408 bgp->default_keepalive);
13409 }
13410 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN))
13411 vty_out(vty,
13412 " Configured DelayOpenTime is %d seconds\n",
13413 p->delayopen);
13414
13415 /* Configured and synced tcp-mss value for peer */
13416 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
13417 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
13418 vty_out(vty, " Configured tcp-mss is %d", p->tcp_mss);
13419 vty_out(vty, ", synced tcp-mss is %d\n", sync_tcp_mss);
13420 }
13421 }
13422 /* Capability. */
13423 if (peer_established(p)) {
13424 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
13425 || p->afc_recv[AFI_IP][SAFI_UNICAST]
13426 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
13427 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
13428 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
13429 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
13430 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
13431 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
13432 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
13433 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
13434 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
13435 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
13436 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
13437 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
13438 || p->afc_adv[AFI_IP][SAFI_ENCAP]
13439 || p->afc_recv[AFI_IP][SAFI_ENCAP]
13440 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
13441 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
13442 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
13443 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
13444 if (use_json) {
13445 json_object *json_cap = NULL;
13446
13447 json_cap = json_object_new_object();
13448
13449 /* AS4 */
13450 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
13451 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13452 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
13453 && CHECK_FLAG(p->cap,
13454 PEER_CAP_AS4_RCV))
13455 json_object_string_add(
13456 json_cap, "4byteAs",
13457 "advertisedAndReceived");
13458 else if (CHECK_FLAG(p->cap,
13459 PEER_CAP_AS4_ADV))
13460 json_object_string_add(
13461 json_cap, "4byteAs",
13462 "advertised");
13463 else if (CHECK_FLAG(p->cap,
13464 PEER_CAP_AS4_RCV))
13465 json_object_string_add(
13466 json_cap, "4byteAs",
13467 "received");
13468 }
13469
13470 /* Extended Message Support */
13471 if (CHECK_FLAG(p->cap,
13472 PEER_CAP_EXTENDED_MESSAGE_ADV)
13473 && CHECK_FLAG(
13474 p->cap,
13475 PEER_CAP_EXTENDED_MESSAGE_RCV))
13476 json_object_string_add(
13477 json_cap, "extendedMessage",
13478 "advertisedAndReceived");
13479 else if (CHECK_FLAG(
13480 p->cap,
13481 PEER_CAP_EXTENDED_MESSAGE_ADV))
13482 json_object_string_add(
13483 json_cap, "extendedMessage",
13484 "advertised");
13485 else if (CHECK_FLAG(
13486 p->cap,
13487 PEER_CAP_EXTENDED_MESSAGE_RCV))
13488 json_object_string_add(
13489 json_cap, "extendedMessage",
13490 "received");
13491
13492 /* AddPath */
13493 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
13494 || CHECK_FLAG(p->cap,
13495 PEER_CAP_ADDPATH_ADV)) {
13496 json_object *json_add = NULL;
13497 const char *print_store;
13498
13499 json_add = json_object_new_object();
13500
13501 FOREACH_AFI_SAFI (afi, safi) {
13502 json_object *json_sub = NULL;
13503 json_sub =
13504 json_object_new_object();
13505 print_store = get_afi_safi_str(
13506 afi, safi, true);
13507
13508 if (CHECK_FLAG(
13509 p->af_cap[afi]
13510 [safi],
13511 PEER_CAP_ADDPATH_AF_TX_ADV)
13512 || CHECK_FLAG(
13513 p->af_cap[afi]
13514 [safi],
13515 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13516 if (CHECK_FLAG(
13517 p->af_cap
13518 [afi]
13519 [safi],
13520 PEER_CAP_ADDPATH_AF_TX_ADV)
13521 && CHECK_FLAG(
13522 p->af_cap
13523 [afi]
13524 [safi],
13525 PEER_CAP_ADDPATH_AF_TX_RCV))
13526 json_object_boolean_true_add(
13527 json_sub,
13528 "txAdvertisedAndReceived");
13529 else if (
13530 CHECK_FLAG(
13531 p->af_cap
13532 [afi]
13533 [safi],
13534 PEER_CAP_ADDPATH_AF_TX_ADV))
13535 json_object_boolean_true_add(
13536 json_sub,
13537 "txAdvertised");
13538 else if (
13539 CHECK_FLAG(
13540 p->af_cap
13541 [afi]
13542 [safi],
13543 PEER_CAP_ADDPATH_AF_TX_RCV))
13544 json_object_boolean_true_add(
13545 json_sub,
13546 "txReceived");
13547 }
13548
13549 if (CHECK_FLAG(
13550 p->af_cap[afi]
13551 [safi],
13552 PEER_CAP_ADDPATH_AF_RX_ADV)
13553 || CHECK_FLAG(
13554 p->af_cap[afi]
13555 [safi],
13556 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13557 if (CHECK_FLAG(
13558 p->af_cap
13559 [afi]
13560 [safi],
13561 PEER_CAP_ADDPATH_AF_RX_ADV)
13562 && CHECK_FLAG(
13563 p->af_cap
13564 [afi]
13565 [safi],
13566 PEER_CAP_ADDPATH_AF_RX_RCV))
13567 json_object_boolean_true_add(
13568 json_sub,
13569 "rxAdvertisedAndReceived");
13570 else if (
13571 CHECK_FLAG(
13572 p->af_cap
13573 [afi]
13574 [safi],
13575 PEER_CAP_ADDPATH_AF_RX_ADV))
13576 json_object_boolean_true_add(
13577 json_sub,
13578 "rxAdvertised");
13579 else if (
13580 CHECK_FLAG(
13581 p->af_cap
13582 [afi]
13583 [safi],
13584 PEER_CAP_ADDPATH_AF_RX_RCV))
13585 json_object_boolean_true_add(
13586 json_sub,
13587 "rxReceived");
13588 }
13589
13590 if (CHECK_FLAG(
13591 p->af_cap[afi]
13592 [safi],
13593 PEER_CAP_ADDPATH_AF_TX_ADV)
13594 || CHECK_FLAG(
13595 p->af_cap[afi]
13596 [safi],
13597 PEER_CAP_ADDPATH_AF_TX_RCV)
13598 || CHECK_FLAG(
13599 p->af_cap[afi]
13600 [safi],
13601 PEER_CAP_ADDPATH_AF_RX_ADV)
13602 || CHECK_FLAG(
13603 p->af_cap[afi]
13604 [safi],
13605 PEER_CAP_ADDPATH_AF_RX_RCV))
13606 json_object_object_add(
13607 json_add,
13608 print_store,
13609 json_sub);
13610 else
13611 json_object_free(
13612 json_sub);
13613 }
13614
13615 json_object_object_add(
13616 json_cap, "addPath", json_add);
13617 }
13618
13619 /* Dynamic */
13620 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
13621 || CHECK_FLAG(p->cap,
13622 PEER_CAP_DYNAMIC_ADV)) {
13623 if (CHECK_FLAG(p->cap,
13624 PEER_CAP_DYNAMIC_ADV)
13625 && CHECK_FLAG(p->cap,
13626 PEER_CAP_DYNAMIC_RCV))
13627 json_object_string_add(
13628 json_cap, "dynamic",
13629 "advertisedAndReceived");
13630 else if (CHECK_FLAG(
13631 p->cap,
13632 PEER_CAP_DYNAMIC_ADV))
13633 json_object_string_add(
13634 json_cap, "dynamic",
13635 "advertised");
13636 else if (CHECK_FLAG(
13637 p->cap,
13638 PEER_CAP_DYNAMIC_RCV))
13639 json_object_string_add(
13640 json_cap, "dynamic",
13641 "received");
13642 }
13643
13644 /* Extended nexthop */
13645 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
13646 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13647 json_object *json_nxt = NULL;
13648 const char *print_store;
13649
13650
13651 if (CHECK_FLAG(p->cap,
13652 PEER_CAP_ENHE_ADV)
13653 && CHECK_FLAG(p->cap,
13654 PEER_CAP_ENHE_RCV))
13655 json_object_string_add(
13656 json_cap,
13657 "extendedNexthop",
13658 "advertisedAndReceived");
13659 else if (CHECK_FLAG(p->cap,
13660 PEER_CAP_ENHE_ADV))
13661 json_object_string_add(
13662 json_cap,
13663 "extendedNexthop",
13664 "advertised");
13665 else if (CHECK_FLAG(p->cap,
13666 PEER_CAP_ENHE_RCV))
13667 json_object_string_add(
13668 json_cap,
13669 "extendedNexthop",
13670 "received");
13671
13672 if (CHECK_FLAG(p->cap,
13673 PEER_CAP_ENHE_RCV)) {
13674 json_nxt =
13675 json_object_new_object();
13676
13677 for (safi = SAFI_UNICAST;
13678 safi < SAFI_MAX; safi++) {
13679 if (CHECK_FLAG(
13680 p->af_cap
13681 [AFI_IP]
13682 [safi],
13683 PEER_CAP_ENHE_AF_RCV)) {
13684 print_store = get_afi_safi_str(
13685 AFI_IP,
13686 safi, true);
13687 json_object_string_add(
13688 json_nxt,
13689 print_store,
13690 "recieved"); /* misspelled for compatibility */
13691 }
13692 }
13693 json_object_object_add(
13694 json_cap,
13695 "extendedNexthopFamililesByPeer",
13696 json_nxt);
13697 }
13698 }
13699
13700 /* Route Refresh */
13701 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
13702 || CHECK_FLAG(p->cap,
13703 PEER_CAP_REFRESH_NEW_RCV)
13704 || CHECK_FLAG(p->cap,
13705 PEER_CAP_REFRESH_OLD_RCV)) {
13706 if (CHECK_FLAG(p->cap,
13707 PEER_CAP_REFRESH_ADV)
13708 && (CHECK_FLAG(
13709 p->cap,
13710 PEER_CAP_REFRESH_NEW_RCV)
13711 || CHECK_FLAG(
13712 p->cap,
13713 PEER_CAP_REFRESH_OLD_RCV))) {
13714 if (CHECK_FLAG(
13715 p->cap,
13716 PEER_CAP_REFRESH_OLD_RCV)
13717 && CHECK_FLAG(
13718 p->cap,
13719 PEER_CAP_REFRESH_NEW_RCV))
13720 json_object_string_add(
13721 json_cap,
13722 "routeRefresh",
13723 "advertisedAndReceivedOldNew");
13724 else {
13725 if (CHECK_FLAG(
13726 p->cap,
13727 PEER_CAP_REFRESH_OLD_RCV))
13728 json_object_string_add(
13729 json_cap,
13730 "routeRefresh",
13731 "advertisedAndReceivedOld");
13732 else
13733 json_object_string_add(
13734 json_cap,
13735 "routeRefresh",
13736 "advertisedAndReceivedNew");
13737 }
13738 } else if (
13739 CHECK_FLAG(
13740 p->cap,
13741 PEER_CAP_REFRESH_ADV))
13742 json_object_string_add(
13743 json_cap,
13744 "routeRefresh",
13745 "advertised");
13746 else if (
13747 CHECK_FLAG(
13748 p->cap,
13749 PEER_CAP_REFRESH_NEW_RCV)
13750 || CHECK_FLAG(
13751 p->cap,
13752 PEER_CAP_REFRESH_OLD_RCV))
13753 json_object_string_add(
13754 json_cap,
13755 "routeRefresh",
13756 "received");
13757 }
13758
13759 /* Enhanced Route Refresh */
13760 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV)
13761 || CHECK_FLAG(p->cap,
13762 PEER_CAP_ENHANCED_RR_RCV)) {
13763 if (CHECK_FLAG(p->cap,
13764 PEER_CAP_ENHANCED_RR_ADV)
13765 && CHECK_FLAG(
13766 p->cap,
13767 PEER_CAP_ENHANCED_RR_RCV))
13768 json_object_string_add(
13769 json_cap,
13770 "enhancedRouteRefresh",
13771 "advertisedAndReceived");
13772 else if (
13773 CHECK_FLAG(
13774 p->cap,
13775 PEER_CAP_ENHANCED_RR_ADV))
13776 json_object_string_add(
13777 json_cap,
13778 "enhancedRouteRefresh",
13779 "advertised");
13780 else if (
13781 CHECK_FLAG(
13782 p->cap,
13783 PEER_CAP_ENHANCED_RR_RCV))
13784 json_object_string_add(
13785 json_cap,
13786 "enhancedRouteRefresh",
13787 "received");
13788 }
13789
13790 /* Multiprotocol Extensions */
13791 json_object *json_multi = NULL;
13792 json_multi = json_object_new_object();
13793
13794 FOREACH_AFI_SAFI (afi, safi) {
13795 if (p->afc_adv[afi][safi]
13796 || p->afc_recv[afi][safi]) {
13797 json_object *json_exten = NULL;
13798 json_exten =
13799 json_object_new_object();
13800
13801 if (p->afc_adv[afi][safi]
13802 && p->afc_recv[afi][safi])
13803 json_object_boolean_true_add(
13804 json_exten,
13805 "advertisedAndReceived");
13806 else if (p->afc_adv[afi][safi])
13807 json_object_boolean_true_add(
13808 json_exten,
13809 "advertised");
13810 else if (p->afc_recv[afi][safi])
13811 json_object_boolean_true_add(
13812 json_exten,
13813 "received");
13814
13815 json_object_object_add(
13816 json_multi,
13817 get_afi_safi_str(afi,
13818 safi,
13819 true),
13820 json_exten);
13821 }
13822 }
13823 json_object_object_add(
13824 json_cap, "multiprotocolExtensions",
13825 json_multi);
13826
13827 /* Hostname capabilities */
13828 json_object *json_hname = NULL;
13829
13830 json_hname = json_object_new_object();
13831
13832 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13833 json_object_string_add(
13834 json_hname, "advHostName",
13835 bgp->peer_self->hostname
13836 ? bgp->peer_self
13837 ->hostname
13838 : "n/a");
13839 json_object_string_add(
13840 json_hname, "advDomainName",
13841 bgp->peer_self->domainname
13842 ? bgp->peer_self
13843 ->domainname
13844 : "n/a");
13845 }
13846
13847
13848 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13849 json_object_string_add(
13850 json_hname, "rcvHostName",
13851 p->hostname ? p->hostname
13852 : "n/a");
13853 json_object_string_add(
13854 json_hname, "rcvDomainName",
13855 p->domainname ? p->domainname
13856 : "n/a");
13857 }
13858
13859 json_object_object_add(json_cap, "hostName",
13860 json_hname);
13861
13862 /* Gracefull Restart */
13863 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
13864 || CHECK_FLAG(p->cap,
13865 PEER_CAP_RESTART_ADV)) {
13866 if (CHECK_FLAG(p->cap,
13867 PEER_CAP_RESTART_ADV)
13868 && CHECK_FLAG(p->cap,
13869 PEER_CAP_RESTART_RCV))
13870 json_object_string_add(
13871 json_cap,
13872 "gracefulRestart",
13873 "advertisedAndReceived");
13874 else if (CHECK_FLAG(
13875 p->cap,
13876 PEER_CAP_RESTART_ADV))
13877 json_object_string_add(
13878 json_cap,
13879 "gracefulRestartCapability",
13880 "advertised");
13881 else if (CHECK_FLAG(
13882 p->cap,
13883 PEER_CAP_RESTART_RCV))
13884 json_object_string_add(
13885 json_cap,
13886 "gracefulRestartCapability",
13887 "received");
13888
13889 if (CHECK_FLAG(p->cap,
13890 PEER_CAP_RESTART_RCV)) {
13891 int restart_af_count = 0;
13892 json_object *json_restart =
13893 NULL;
13894 json_restart =
13895 json_object_new_object();
13896
13897 json_object_int_add(
13898 json_cap,
13899 "gracefulRestartRemoteTimerMsecs",
13900 p->v_gr_restart * 1000);
13901
13902 FOREACH_AFI_SAFI (afi, safi) {
13903 if (CHECK_FLAG(
13904 p->af_cap
13905 [afi]
13906 [safi],
13907 PEER_CAP_RESTART_AF_RCV)) {
13908 json_object *
13909 json_sub =
13910 NULL;
13911 json_sub =
13912 json_object_new_object();
13913
13914 if (CHECK_FLAG(
13915 p->af_cap
13916 [afi]
13917 [safi],
13918 PEER_CAP_RESTART_AF_PRESERVE_RCV))
13919 json_object_boolean_true_add(
13920 json_sub,
13921 "preserved");
13922 restart_af_count++;
13923 json_object_object_add(
13924 json_restart,
13925 get_afi_safi_str(
13926 afi,
13927 safi,
13928 true),
13929 json_sub);
13930 }
13931 }
13932 if (!restart_af_count) {
13933 json_object_string_add(
13934 json_cap,
13935 "addressFamiliesByPeer",
13936 "none");
13937 json_object_free(
13938 json_restart);
13939 } else
13940 json_object_object_add(
13941 json_cap,
13942 "addressFamiliesByPeer",
13943 json_restart);
13944 }
13945 }
13946 json_object_object_add(json_neigh,
13947 "neighborCapabilities",
13948 json_cap);
13949 } else {
13950 vty_out(vty, " Neighbor capabilities:\n");
13951
13952 /* AS4 */
13953 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
13954 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13955 vty_out(vty, " 4 Byte AS:");
13956 if (CHECK_FLAG(p->cap,
13957 PEER_CAP_AS4_ADV))
13958 vty_out(vty, " advertised");
13959 if (CHECK_FLAG(p->cap,
13960 PEER_CAP_AS4_RCV))
13961 vty_out(vty, " %sreceived",
13962 CHECK_FLAG(
13963 p->cap,
13964 PEER_CAP_AS4_ADV)
13965 ? "and "
13966 : "");
13967 vty_out(vty, "\n");
13968 }
13969
13970 /* Extended Message Support */
13971 if (CHECK_FLAG(p->cap,
13972 PEER_CAP_EXTENDED_MESSAGE_RCV)
13973 || CHECK_FLAG(
13974 p->cap,
13975 PEER_CAP_EXTENDED_MESSAGE_ADV)) {
13976 vty_out(vty, " Extended Message:");
13977 if (CHECK_FLAG(
13978 p->cap,
13979 PEER_CAP_EXTENDED_MESSAGE_ADV))
13980 vty_out(vty, " advertised");
13981 if (CHECK_FLAG(
13982 p->cap,
13983 PEER_CAP_EXTENDED_MESSAGE_RCV))
13984 vty_out(vty, " %sreceived",
13985 CHECK_FLAG(
13986 p->cap,
13987 PEER_CAP_EXTENDED_MESSAGE_ADV)
13988 ? "and "
13989 : "");
13990 vty_out(vty, "\n");
13991 }
13992
13993 /* AddPath */
13994 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
13995 || CHECK_FLAG(p->cap,
13996 PEER_CAP_ADDPATH_ADV)) {
13997 vty_out(vty, " AddPath:\n");
13998
13999 FOREACH_AFI_SAFI (afi, safi) {
14000 if (CHECK_FLAG(
14001 p->af_cap[afi]
14002 [safi],
14003 PEER_CAP_ADDPATH_AF_TX_ADV)
14004 || CHECK_FLAG(
14005 p->af_cap[afi]
14006 [safi],
14007 PEER_CAP_ADDPATH_AF_TX_RCV)) {
14008 vty_out(vty,
14009 " %s: TX ",
14010 get_afi_safi_str(
14011 afi,
14012 safi,
14013 false));
14014
14015 if (CHECK_FLAG(
14016 p->af_cap
14017 [afi]
14018 [safi],
14019 PEER_CAP_ADDPATH_AF_TX_ADV))
14020 vty_out(vty,
14021 "advertised %s",
14022 get_afi_safi_str(
14023 afi,
14024 safi,
14025 false));
14026
14027 if (CHECK_FLAG(
14028 p->af_cap
14029 [afi]
14030 [safi],
14031 PEER_CAP_ADDPATH_AF_TX_RCV))
14032 vty_out(vty,
14033 "%sreceived",
14034 CHECK_FLAG(
14035 p->af_cap
14036 [afi]
14037 [safi],
14038 PEER_CAP_ADDPATH_AF_TX_ADV)
14039 ? " and "
14040 : "");
14041
14042 vty_out(vty, "\n");
14043 }
14044
14045 if (CHECK_FLAG(
14046 p->af_cap[afi]
14047 [safi],
14048 PEER_CAP_ADDPATH_AF_RX_ADV)
14049 || CHECK_FLAG(
14050 p->af_cap[afi]
14051 [safi],
14052 PEER_CAP_ADDPATH_AF_RX_RCV)) {
14053 vty_out(vty,
14054 " %s: RX ",
14055 get_afi_safi_str(
14056 afi,
14057 safi,
14058 false));
14059
14060 if (CHECK_FLAG(
14061 p->af_cap
14062 [afi]
14063 [safi],
14064 PEER_CAP_ADDPATH_AF_RX_ADV))
14065 vty_out(vty,
14066 "advertised %s",
14067 get_afi_safi_str(
14068 afi,
14069 safi,
14070 false));
14071
14072 if (CHECK_FLAG(
14073 p->af_cap
14074 [afi]
14075 [safi],
14076 PEER_CAP_ADDPATH_AF_RX_RCV))
14077 vty_out(vty,
14078 "%sreceived",
14079 CHECK_FLAG(
14080 p->af_cap
14081 [afi]
14082 [safi],
14083 PEER_CAP_ADDPATH_AF_RX_ADV)
14084 ? " and "
14085 : "");
14086
14087 vty_out(vty, "\n");
14088 }
14089 }
14090 }
14091
14092 /* Dynamic */
14093 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
14094 || CHECK_FLAG(p->cap,
14095 PEER_CAP_DYNAMIC_ADV)) {
14096 vty_out(vty, " Dynamic:");
14097 if (CHECK_FLAG(p->cap,
14098 PEER_CAP_DYNAMIC_ADV))
14099 vty_out(vty, " advertised");
14100 if (CHECK_FLAG(p->cap,
14101 PEER_CAP_DYNAMIC_RCV))
14102 vty_out(vty, " %sreceived",
14103 CHECK_FLAG(
14104 p->cap,
14105 PEER_CAP_DYNAMIC_ADV)
14106 ? "and "
14107 : "");
14108 vty_out(vty, "\n");
14109 }
14110
14111 /* Extended nexthop */
14112 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
14113 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
14114 vty_out(vty, " Extended nexthop:");
14115 if (CHECK_FLAG(p->cap,
14116 PEER_CAP_ENHE_ADV))
14117 vty_out(vty, " advertised");
14118 if (CHECK_FLAG(p->cap,
14119 PEER_CAP_ENHE_RCV))
14120 vty_out(vty, " %sreceived",
14121 CHECK_FLAG(
14122 p->cap,
14123 PEER_CAP_ENHE_ADV)
14124 ? "and "
14125 : "");
14126 vty_out(vty, "\n");
14127
14128 if (CHECK_FLAG(p->cap,
14129 PEER_CAP_ENHE_RCV)) {
14130 vty_out(vty,
14131 " Address families by peer:\n ");
14132 for (safi = SAFI_UNICAST;
14133 safi < SAFI_MAX; safi++)
14134 if (CHECK_FLAG(
14135 p->af_cap
14136 [AFI_IP]
14137 [safi],
14138 PEER_CAP_ENHE_AF_RCV))
14139 vty_out(vty,
14140 " %s\n",
14141 get_afi_safi_str(
14142 AFI_IP,
14143 safi,
14144 false));
14145 }
14146 }
14147
14148 /* Route Refresh */
14149 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
14150 || CHECK_FLAG(p->cap,
14151 PEER_CAP_REFRESH_NEW_RCV)
14152 || CHECK_FLAG(p->cap,
14153 PEER_CAP_REFRESH_OLD_RCV)) {
14154 vty_out(vty, " Route refresh:");
14155 if (CHECK_FLAG(p->cap,
14156 PEER_CAP_REFRESH_ADV))
14157 vty_out(vty, " advertised");
14158 if (CHECK_FLAG(p->cap,
14159 PEER_CAP_REFRESH_NEW_RCV)
14160 || CHECK_FLAG(
14161 p->cap,
14162 PEER_CAP_REFRESH_OLD_RCV))
14163 vty_out(vty, " %sreceived(%s)",
14164 CHECK_FLAG(
14165 p->cap,
14166 PEER_CAP_REFRESH_ADV)
14167 ? "and "
14168 : "",
14169 (CHECK_FLAG(
14170 p->cap,
14171 PEER_CAP_REFRESH_OLD_RCV)
14172 && CHECK_FLAG(
14173 p->cap,
14174 PEER_CAP_REFRESH_NEW_RCV))
14175 ? "old & new"
14176 : CHECK_FLAG(
14177 p->cap,
14178 PEER_CAP_REFRESH_OLD_RCV)
14179 ? "old"
14180 : "new");
14181
14182 vty_out(vty, "\n");
14183 }
14184
14185 /* Enhanced Route Refresh */
14186 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV)
14187 || CHECK_FLAG(p->cap,
14188 PEER_CAP_ENHANCED_RR_RCV)) {
14189 vty_out(vty,
14190 " Enhanced Route Refresh:");
14191 if (CHECK_FLAG(
14192 p->cap,
14193 PEER_CAP_ENHANCED_RR_ADV))
14194 vty_out(vty, " advertised");
14195 if (CHECK_FLAG(
14196 p->cap,
14197 PEER_CAP_ENHANCED_RR_RCV))
14198 vty_out(vty, " %sreceived",
14199 CHECK_FLAG(
14200 p->cap,
14201 PEER_CAP_REFRESH_ADV)
14202 ? "and "
14203 : "");
14204 vty_out(vty, "\n");
14205 }
14206
14207 /* Multiprotocol Extensions */
14208 FOREACH_AFI_SAFI (afi, safi)
14209 if (p->afc_adv[afi][safi]
14210 || p->afc_recv[afi][safi]) {
14211 vty_out(vty,
14212 " Address Family %s:",
14213 get_afi_safi_str(
14214 afi,
14215 safi,
14216 false));
14217 if (p->afc_adv[afi][safi])
14218 vty_out(vty,
14219 " advertised");
14220 if (p->afc_recv[afi][safi])
14221 vty_out(vty,
14222 " %sreceived",
14223 p->afc_adv[afi]
14224 [safi]
14225 ? "and "
14226 : "");
14227 vty_out(vty, "\n");
14228 }
14229
14230 /* Hostname capability */
14231 vty_out(vty, " Hostname Capability:");
14232
14233 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
14234 vty_out(vty,
14235 " advertised (name: %s,domain name: %s)",
14236 bgp->peer_self->hostname
14237 ? bgp->peer_self
14238 ->hostname
14239 : "n/a",
14240 bgp->peer_self->domainname
14241 ? bgp->peer_self
14242 ->domainname
14243 : "n/a");
14244 } else {
14245 vty_out(vty, " not advertised");
14246 }
14247
14248 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
14249 vty_out(vty,
14250 " received (name: %s,domain name: %s)",
14251 p->hostname ? p->hostname
14252 : "n/a",
14253 p->domainname ? p->domainname
14254 : "n/a");
14255 } else {
14256 vty_out(vty, " not received");
14257 }
14258
14259 vty_out(vty, "\n");
14260
14261 /* Graceful Restart */
14262 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
14263 || CHECK_FLAG(p->cap,
14264 PEER_CAP_RESTART_ADV)) {
14265 vty_out(vty,
14266 " Graceful Restart Capability:");
14267 if (CHECK_FLAG(p->cap,
14268 PEER_CAP_RESTART_ADV))
14269 vty_out(vty, " advertised");
14270 if (CHECK_FLAG(p->cap,
14271 PEER_CAP_RESTART_RCV))
14272 vty_out(vty, " %sreceived",
14273 CHECK_FLAG(
14274 p->cap,
14275 PEER_CAP_RESTART_ADV)
14276 ? "and "
14277 : "");
14278 vty_out(vty, "\n");
14279
14280 if (CHECK_FLAG(p->cap,
14281 PEER_CAP_RESTART_RCV)) {
14282 int restart_af_count = 0;
14283
14284 vty_out(vty,
14285 " Remote Restart timer is %d seconds\n",
14286 p->v_gr_restart);
14287 vty_out(vty,
14288 " Address families by peer:\n ");
14289
14290 FOREACH_AFI_SAFI (afi, safi)
14291 if (CHECK_FLAG(
14292 p->af_cap
14293 [afi]
14294 [safi],
14295 PEER_CAP_RESTART_AF_RCV)) {
14296 vty_out(vty,
14297 "%s%s(%s)",
14298 restart_af_count
14299 ? ", "
14300 : "",
14301 get_afi_safi_str(
14302 afi,
14303 safi,
14304 false),
14305 CHECK_FLAG(
14306 p->af_cap
14307 [afi]
14308 [safi],
14309 PEER_CAP_RESTART_AF_PRESERVE_RCV)
14310 ? "preserved"
14311 : "not preserved");
14312 restart_af_count++;
14313 }
14314 if (!restart_af_count)
14315 vty_out(vty, "none");
14316 vty_out(vty, "\n");
14317 }
14318 } /* Gracefull Restart */
14319 }
14320 }
14321 }
14322
14323 /* graceful restart information */
14324 json_object *json_grace = NULL;
14325 json_object *json_grace_send = NULL;
14326 json_object *json_grace_recv = NULL;
14327 int eor_send_af_count = 0;
14328 int eor_receive_af_count = 0;
14329
14330 if (use_json) {
14331 json_grace = json_object_new_object();
14332 json_grace_send = json_object_new_object();
14333 json_grace_recv = json_object_new_object();
14334
14335 if ((peer_established(p))
14336 && CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
14337 FOREACH_AFI_SAFI (afi, safi) {
14338 if (CHECK_FLAG(p->af_sflags[afi][safi],
14339 PEER_STATUS_EOR_SEND)) {
14340 json_object_boolean_true_add(
14341 json_grace_send,
14342 get_afi_safi_str(afi,
14343 safi,
14344 true));
14345 eor_send_af_count++;
14346 }
14347 }
14348 FOREACH_AFI_SAFI (afi, safi) {
14349 if (CHECK_FLAG(
14350 p->af_sflags[afi][safi],
14351 PEER_STATUS_EOR_RECEIVED)) {
14352 json_object_boolean_true_add(
14353 json_grace_recv,
14354 get_afi_safi_str(afi,
14355 safi,
14356 true));
14357 eor_receive_af_count++;
14358 }
14359 }
14360 }
14361 json_object_object_add(json_grace, "endOfRibSend",
14362 json_grace_send);
14363 json_object_object_add(json_grace, "endOfRibRecv",
14364 json_grace_recv);
14365
14366
14367 if (p->t_gr_restart)
14368 json_object_int_add(json_grace,
14369 "gracefulRestartTimerMsecs",
14370 thread_timer_remain_second(
14371 p->t_gr_restart)
14372 * 1000);
14373
14374 if (p->t_gr_stale)
14375 json_object_int_add(
14376 json_grace,
14377 "gracefulStalepathTimerMsecs",
14378 thread_timer_remain_second(
14379 p->t_gr_stale)
14380 * 1000);
14381 /* more gr info in new format */
14382 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json,
14383 json_grace);
14384 json_object_object_add(
14385 json_neigh, "gracefulRestartInfo", json_grace);
14386 } else {
14387 vty_out(vty, " Graceful restart information:\n");
14388 if ((peer_established(p))
14389 && CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
14390
14391 vty_out(vty, " End-of-RIB send: ");
14392 FOREACH_AFI_SAFI (afi, safi) {
14393 if (CHECK_FLAG(p->af_sflags[afi][safi],
14394 PEER_STATUS_EOR_SEND)) {
14395 vty_out(vty, "%s%s",
14396 eor_send_af_count ? ", "
14397 : "",
14398 get_afi_safi_str(
14399 afi, safi,
14400 false));
14401 eor_send_af_count++;
14402 }
14403 }
14404 vty_out(vty, "\n");
14405 vty_out(vty, " End-of-RIB received: ");
14406 FOREACH_AFI_SAFI (afi, safi) {
14407 if (CHECK_FLAG(
14408 p->af_sflags[afi][safi],
14409 PEER_STATUS_EOR_RECEIVED)) {
14410 vty_out(vty, "%s%s",
14411 eor_receive_af_count
14412 ? ", "
14413 : "",
14414 get_afi_safi_str(afi,
14415 safi,
14416 false));
14417 eor_receive_af_count++;
14418 }
14419 }
14420 vty_out(vty, "\n");
14421 }
14422
14423 if (p->t_gr_restart)
14424 vty_out(vty,
14425 " The remaining time of restart timer is %ld\n",
14426 thread_timer_remain_second(
14427 p->t_gr_restart));
14428
14429 if (p->t_gr_stale)
14430 vty_out(vty,
14431 " The remaining time of stalepath timer is %ld\n",
14432 thread_timer_remain_second(
14433 p->t_gr_stale));
14434
14435 /* more gr info in new format */
14436 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, NULL);
14437 }
14438
14439 if (use_json) {
14440 json_object *json_stat = NULL;
14441 json_stat = json_object_new_object();
14442 /* Packet counts. */
14443
14444 atomic_size_t outq_count, inq_count;
14445 outq_count = atomic_load_explicit(&p->obuf->count,
14446 memory_order_relaxed);
14447 inq_count = atomic_load_explicit(&p->ibuf->count,
14448 memory_order_relaxed);
14449
14450 json_object_int_add(json_stat, "depthInq",
14451 (unsigned long)inq_count);
14452 json_object_int_add(json_stat, "depthOutq",
14453 (unsigned long)outq_count);
14454 json_object_int_add(json_stat, "opensSent",
14455 atomic_load_explicit(&p->open_out,
14456 memory_order_relaxed));
14457 json_object_int_add(json_stat, "opensRecv",
14458 atomic_load_explicit(&p->open_in,
14459 memory_order_relaxed));
14460 json_object_int_add(json_stat, "notificationsSent",
14461 atomic_load_explicit(&p->notify_out,
14462 memory_order_relaxed));
14463 json_object_int_add(json_stat, "notificationsRecv",
14464 atomic_load_explicit(&p->notify_in,
14465 memory_order_relaxed));
14466 json_object_int_add(json_stat, "updatesSent",
14467 atomic_load_explicit(&p->update_out,
14468 memory_order_relaxed));
14469 json_object_int_add(json_stat, "updatesRecv",
14470 atomic_load_explicit(&p->update_in,
14471 memory_order_relaxed));
14472 json_object_int_add(json_stat, "keepalivesSent",
14473 atomic_load_explicit(&p->keepalive_out,
14474 memory_order_relaxed));
14475 json_object_int_add(json_stat, "keepalivesRecv",
14476 atomic_load_explicit(&p->keepalive_in,
14477 memory_order_relaxed));
14478 json_object_int_add(json_stat, "routeRefreshSent",
14479 atomic_load_explicit(&p->refresh_out,
14480 memory_order_relaxed));
14481 json_object_int_add(json_stat, "routeRefreshRecv",
14482 atomic_load_explicit(&p->refresh_in,
14483 memory_order_relaxed));
14484 json_object_int_add(json_stat, "capabilitySent",
14485 atomic_load_explicit(&p->dynamic_cap_out,
14486 memory_order_relaxed));
14487 json_object_int_add(json_stat, "capabilityRecv",
14488 atomic_load_explicit(&p->dynamic_cap_in,
14489 memory_order_relaxed));
14490 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
14491 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
14492 json_object_object_add(json_neigh, "messageStats", json_stat);
14493 } else {
14494 atomic_size_t outq_count, inq_count;
14495 outq_count = atomic_load_explicit(&p->obuf->count,
14496 memory_order_relaxed);
14497 inq_count = atomic_load_explicit(&p->ibuf->count,
14498 memory_order_relaxed);
14499
14500 /* Packet counts. */
14501 vty_out(vty, " Message statistics:\n");
14502 vty_out(vty, " Inq depth is %zu\n", inq_count);
14503 vty_out(vty, " Outq depth is %zu\n", outq_count);
14504 vty_out(vty, " Sent Rcvd\n");
14505 vty_out(vty, " Opens: %10d %10d\n",
14506 atomic_load_explicit(&p->open_out,
14507 memory_order_relaxed),
14508 atomic_load_explicit(&p->open_in,
14509 memory_order_relaxed));
14510 vty_out(vty, " Notifications: %10d %10d\n",
14511 atomic_load_explicit(&p->notify_out,
14512 memory_order_relaxed),
14513 atomic_load_explicit(&p->notify_in,
14514 memory_order_relaxed));
14515 vty_out(vty, " Updates: %10d %10d\n",
14516 atomic_load_explicit(&p->update_out,
14517 memory_order_relaxed),
14518 atomic_load_explicit(&p->update_in,
14519 memory_order_relaxed));
14520 vty_out(vty, " Keepalives: %10d %10d\n",
14521 atomic_load_explicit(&p->keepalive_out,
14522 memory_order_relaxed),
14523 atomic_load_explicit(&p->keepalive_in,
14524 memory_order_relaxed));
14525 vty_out(vty, " Route Refresh: %10d %10d\n",
14526 atomic_load_explicit(&p->refresh_out,
14527 memory_order_relaxed),
14528 atomic_load_explicit(&p->refresh_in,
14529 memory_order_relaxed));
14530 vty_out(vty, " Capability: %10d %10d\n",
14531 atomic_load_explicit(&p->dynamic_cap_out,
14532 memory_order_relaxed),
14533 atomic_load_explicit(&p->dynamic_cap_in,
14534 memory_order_relaxed));
14535 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
14536 PEER_TOTAL_RX(p));
14537 }
14538
14539 if (use_json) {
14540 /* advertisement-interval */
14541 json_object_int_add(json_neigh,
14542 "minBtwnAdvertisementRunsTimerMsecs",
14543 p->v_routeadv * 1000);
14544
14545 /* Update-source. */
14546 if (p->update_if || p->update_source) {
14547 if (p->update_if)
14548 json_object_string_add(json_neigh,
14549 "updateSource",
14550 p->update_if);
14551 else if (p->update_source)
14552 json_object_string_add(
14553 json_neigh, "updateSource",
14554 sockunion2str(p->update_source, buf1,
14555 SU_ADDRSTRLEN));
14556 }
14557 } else {
14558 /* advertisement-interval */
14559 vty_out(vty,
14560 " Minimum time between advertisement runs is %d seconds\n",
14561 p->v_routeadv);
14562
14563 /* Update-source. */
14564 if (p->update_if || p->update_source) {
14565 vty_out(vty, " Update source is ");
14566 if (p->update_if)
14567 vty_out(vty, "%s", p->update_if);
14568 else if (p->update_source)
14569 vty_out(vty, "%s",
14570 sockunion2str(p->update_source, buf1,
14571 SU_ADDRSTRLEN));
14572 vty_out(vty, "\n");
14573 }
14574
14575 vty_out(vty, "\n");
14576 }
14577
14578 /* Address Family Information */
14579 json_object *json_hold = NULL;
14580
14581 if (use_json)
14582 json_hold = json_object_new_object();
14583
14584 FOREACH_AFI_SAFI (afi, safi)
14585 if (p->afc[afi][safi])
14586 bgp_show_peer_afi(vty, p, afi, safi, use_json,
14587 json_hold);
14588
14589 if (use_json) {
14590 json_object_object_add(json_neigh, "addressFamilyInfo",
14591 json_hold);
14592 json_object_int_add(json_neigh, "connectionsEstablished",
14593 p->established);
14594 json_object_int_add(json_neigh, "connectionsDropped",
14595 p->dropped);
14596 } else
14597 vty_out(vty, " Connections established %d; dropped %d\n",
14598 p->established, p->dropped);
14599
14600 if (!p->last_reset) {
14601 if (use_json)
14602 json_object_string_add(json_neigh, "lastReset",
14603 "never");
14604 else
14605 vty_out(vty, " Last reset never\n");
14606 } else {
14607 if (use_json) {
14608 time_t uptime;
14609 struct tm tm;
14610
14611 uptime = bgp_clock();
14612 uptime -= p->resettime;
14613 gmtime_r(&uptime, &tm);
14614
14615 json_object_int_add(json_neigh, "lastResetTimerMsecs",
14616 (tm.tm_sec * 1000)
14617 + (tm.tm_min * 60000)
14618 + (tm.tm_hour * 3600000));
14619 bgp_show_peer_reset(NULL, p, json_neigh, true);
14620 } else {
14621 vty_out(vty, " Last reset %s, ",
14622 peer_uptime(p->resettime, timebuf,
14623 BGP_UPTIME_LEN, 0, NULL));
14624
14625 bgp_show_peer_reset(vty, p, NULL, false);
14626 if (p->last_reset_cause_size) {
14627 msg = p->last_reset_cause;
14628 vty_out(vty,
14629 " Message received that caused BGP to send a NOTIFICATION:\n ");
14630 for (i = 1; i <= p->last_reset_cause_size;
14631 i++) {
14632 vty_out(vty, "%02X", *msg++);
14633
14634 if (i != p->last_reset_cause_size) {
14635 if (i % 16 == 0) {
14636 vty_out(vty, "\n ");
14637 } else if (i % 4 == 0) {
14638 vty_out(vty, " ");
14639 }
14640 }
14641 }
14642 vty_out(vty, "\n");
14643 }
14644 }
14645 }
14646
14647 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
14648 if (use_json)
14649 json_object_boolean_true_add(json_neigh,
14650 "prefixesConfigExceedMax");
14651 else
14652 vty_out(vty,
14653 " Peer had exceeded the max. no. of prefixes configured.\n");
14654
14655 if (p->t_pmax_restart) {
14656 if (use_json) {
14657 json_object_boolean_true_add(
14658 json_neigh, "reducePrefixNumFrom");
14659 json_object_int_add(json_neigh,
14660 "restartInTimerMsec",
14661 thread_timer_remain_second(
14662 p->t_pmax_restart)
14663 * 1000);
14664 } else
14665 vty_out(vty,
14666 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
14667 p->host, thread_timer_remain_second(
14668 p->t_pmax_restart));
14669 } else {
14670 if (use_json)
14671 json_object_boolean_true_add(
14672 json_neigh,
14673 "reducePrefixNumAndClearIpBgp");
14674 else
14675 vty_out(vty,
14676 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
14677 p->host);
14678 }
14679 }
14680
14681 /* EBGP Multihop and GTSM */
14682 if (p->sort != BGP_PEER_IBGP) {
14683 if (use_json) {
14684 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14685 json_object_int_add(json_neigh,
14686 "externalBgpNbrMaxHopsAway",
14687 p->gtsm_hops);
14688 else if (p->ttl > BGP_DEFAULT_TTL)
14689 json_object_int_add(json_neigh,
14690 "externalBgpNbrMaxHopsAway",
14691 p->ttl);
14692 } else {
14693 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14694 vty_out(vty,
14695 " External BGP neighbor may be up to %d hops away.\n",
14696 p->gtsm_hops);
14697 else if (p->ttl > BGP_DEFAULT_TTL)
14698 vty_out(vty,
14699 " External BGP neighbor may be up to %d hops away.\n",
14700 p->ttl);
14701 }
14702 } else {
14703 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED) {
14704 if (use_json)
14705 json_object_int_add(json_neigh,
14706 "internalBgpNbrMaxHopsAway",
14707 p->gtsm_hops);
14708 else
14709 vty_out(vty,
14710 " Internal BGP neighbor may be up to %d hops away.\n",
14711 p->gtsm_hops);
14712 }
14713 }
14714
14715 /* Local address. */
14716 if (p->su_local) {
14717 if (use_json) {
14718 json_object_string_add(json_neigh, "hostLocal",
14719 sockunion2str(p->su_local, buf1,
14720 SU_ADDRSTRLEN));
14721 json_object_int_add(json_neigh, "portLocal",
14722 ntohs(p->su_local->sin.sin_port));
14723 } else
14724 vty_out(vty, "Local host: %s, Local port: %d\n",
14725 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
14726 ntohs(p->su_local->sin.sin_port));
14727 }
14728
14729 /* Remote address. */
14730 if (p->su_remote) {
14731 if (use_json) {
14732 json_object_string_add(json_neigh, "hostForeign",
14733 sockunion2str(p->su_remote, buf1,
14734 SU_ADDRSTRLEN));
14735 json_object_int_add(json_neigh, "portForeign",
14736 ntohs(p->su_remote->sin.sin_port));
14737 } else
14738 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
14739 sockunion2str(p->su_remote, buf1,
14740 SU_ADDRSTRLEN),
14741 ntohs(p->su_remote->sin.sin_port));
14742 }
14743
14744 /* Nexthop display. */
14745 if (p->su_local) {
14746 if (use_json) {
14747 json_object_string_add(json_neigh, "nexthop",
14748 inet_ntop(AF_INET,
14749 &p->nexthop.v4, buf1,
14750 sizeof(buf1)));
14751 json_object_string_add(json_neigh, "nexthopGlobal",
14752 inet_ntop(AF_INET6,
14753 &p->nexthop.v6_global,
14754 buf1, sizeof(buf1)));
14755 json_object_string_add(json_neigh, "nexthopLocal",
14756 inet_ntop(AF_INET6,
14757 &p->nexthop.v6_local,
14758 buf1, sizeof(buf1)));
14759 if (p->shared_network)
14760 json_object_string_add(json_neigh,
14761 "bgpConnection",
14762 "sharedNetwork");
14763 else
14764 json_object_string_add(json_neigh,
14765 "bgpConnection",
14766 "nonSharedNetwork");
14767 } else {
14768 vty_out(vty, "Nexthop: %s\n",
14769 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
14770 sizeof(buf1)));
14771 vty_out(vty, "Nexthop global: %s\n",
14772 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
14773 sizeof(buf1)));
14774 vty_out(vty, "Nexthop local: %s\n",
14775 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
14776 sizeof(buf1)));
14777 vty_out(vty, "BGP connection: %s\n",
14778 p->shared_network ? "shared network"
14779 : "non shared network");
14780 }
14781 }
14782
14783 /* Timer information. */
14784 if (use_json) {
14785 json_object_int_add(json_neigh, "connectRetryTimer",
14786 p->v_connect);
14787 if (peer_established(p) && p->rtt)
14788 json_object_int_add(json_neigh, "estimatedRttInMsecs",
14789 p->rtt);
14790 if (p->t_start)
14791 json_object_int_add(
14792 json_neigh, "nextStartTimerDueInMsecs",
14793 thread_timer_remain_second(p->t_start) * 1000);
14794 if (p->t_connect)
14795 json_object_int_add(
14796 json_neigh, "nextConnectTimerDueInMsecs",
14797 thread_timer_remain_second(p->t_connect)
14798 * 1000);
14799 if (p->t_routeadv) {
14800 json_object_int_add(json_neigh, "mraiInterval",
14801 p->v_routeadv);
14802 json_object_int_add(
14803 json_neigh, "mraiTimerExpireInMsecs",
14804 thread_timer_remain_second(p->t_routeadv)
14805 * 1000);
14806 }
14807 if (p->password)
14808 json_object_int_add(json_neigh, "authenticationEnabled",
14809 1);
14810
14811 if (p->t_read)
14812 json_object_string_add(json_neigh, "readThread", "on");
14813 else
14814 json_object_string_add(json_neigh, "readThread", "off");
14815
14816 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
14817 json_object_string_add(json_neigh, "writeThread", "on");
14818 else
14819 json_object_string_add(json_neigh, "writeThread",
14820 "off");
14821 } else {
14822 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
14823 p->v_connect);
14824 if (peer_established(p) && p->rtt)
14825 vty_out(vty, "Estimated round trip time: %d ms\n",
14826 p->rtt);
14827 if (p->t_start)
14828 vty_out(vty, "Next start timer due in %ld seconds\n",
14829 thread_timer_remain_second(p->t_start));
14830 if (p->t_connect)
14831 vty_out(vty, "Next connect timer due in %ld seconds\n",
14832 thread_timer_remain_second(p->t_connect));
14833 if (p->t_routeadv)
14834 vty_out(vty,
14835 "MRAI (interval %u) timer expires in %ld seconds\n",
14836 p->v_routeadv,
14837 thread_timer_remain_second(p->t_routeadv));
14838 if (p->password)
14839 vty_out(vty, "Peer Authentication Enabled\n");
14840
14841 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
14842 p->t_read ? "on" : "off",
14843 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
14844 ? "on"
14845 : "off", p->fd);
14846 }
14847
14848 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
14849 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
14850 bgp_capability_vty_out(vty, p, use_json, json_neigh);
14851
14852 if (!use_json)
14853 vty_out(vty, "\n");
14854
14855 /* BFD information. */
14856 if (p->bfd_config)
14857 bgp_bfd_show_info(vty, p, json_neigh);
14858
14859 if (use_json) {
14860 if (p->conf_if) /* Configured interface name. */
14861 json_object_object_add(json, p->conf_if, json_neigh);
14862 else /* Configured IP address. */
14863 json_object_object_add(json, p->host, json_neigh);
14864 }
14865 }
14866
14867 static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
14868 enum show_type type,
14869 union sockunion *su,
14870 const char *conf_if, afi_t afi,
14871 bool use_json)
14872 {
14873 struct listnode *node, *nnode;
14874 struct peer *peer;
14875 int find = 0;
14876 safi_t safi = SAFI_UNICAST;
14877 json_object *json = NULL;
14878 json_object *json_neighbor = NULL;
14879
14880 if (use_json) {
14881 json = json_object_new_object();
14882 json_neighbor = json_object_new_object();
14883 }
14884
14885 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14886
14887 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14888 continue;
14889
14890 if ((peer->afc[afi][safi]) == 0)
14891 continue;
14892
14893 if (type == show_all) {
14894 bgp_show_peer_gr_status(vty, peer, use_json,
14895 json_neighbor);
14896
14897 if (use_json) {
14898 json_object_object_add(json, peer->host,
14899 json_neighbor);
14900 json_neighbor = NULL;
14901 }
14902
14903 } else if (type == show_peer) {
14904 if (conf_if) {
14905 if ((peer->conf_if
14906 && !strcmp(peer->conf_if, conf_if))
14907 || (peer->hostname
14908 && !strcmp(peer->hostname, conf_if))) {
14909 find = 1;
14910 bgp_show_peer_gr_status(vty, peer,
14911 use_json,
14912 json_neighbor);
14913 }
14914 } else {
14915 if (sockunion_same(&peer->su, su)) {
14916 find = 1;
14917 bgp_show_peer_gr_status(vty, peer,
14918 use_json,
14919 json_neighbor);
14920 }
14921 }
14922 if (use_json && find)
14923 json_object_object_add(json, peer->host,
14924 json_neighbor);
14925 }
14926
14927 if (find) {
14928 json_neighbor = NULL;
14929 break;
14930 }
14931 }
14932
14933 if (type == show_peer && !find) {
14934 if (use_json)
14935 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14936 else
14937 vty_out(vty, "%% No such neighbor\n");
14938 }
14939 if (use_json) {
14940 vty_out(vty, "%s\n",
14941 json_object_to_json_string_ext(
14942 json, JSON_C_TO_STRING_PRETTY));
14943
14944 if (json_neighbor)
14945 json_object_free(json_neighbor);
14946 json_object_free(json);
14947 } else {
14948 vty_out(vty, "\n");
14949 }
14950
14951 return CMD_SUCCESS;
14952 }
14953
14954 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
14955 enum show_type type, union sockunion *su,
14956 const char *conf_if, bool use_json,
14957 json_object *json)
14958 {
14959 struct listnode *node, *nnode;
14960 struct peer *peer;
14961 int find = 0;
14962 bool nbr_output = false;
14963 afi_t afi = AFI_MAX;
14964 safi_t safi = SAFI_MAX;
14965
14966 if (type == show_ipv4_peer || type == show_ipv4_all) {
14967 afi = AFI_IP;
14968 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
14969 afi = AFI_IP6;
14970 }
14971
14972 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14973 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14974 continue;
14975
14976 switch (type) {
14977 case show_all:
14978 bgp_show_peer(vty, peer, use_json, json);
14979 nbr_output = true;
14980 break;
14981 case show_peer:
14982 if (conf_if) {
14983 if ((peer->conf_if
14984 && !strcmp(peer->conf_if, conf_if))
14985 || (peer->hostname
14986 && !strcmp(peer->hostname, conf_if))) {
14987 find = 1;
14988 bgp_show_peer(vty, peer, use_json,
14989 json);
14990 }
14991 } else {
14992 if (sockunion_same(&peer->su, su)) {
14993 find = 1;
14994 bgp_show_peer(vty, peer, use_json,
14995 json);
14996 }
14997 }
14998 break;
14999 case show_ipv4_peer:
15000 case show_ipv6_peer:
15001 FOREACH_SAFI (safi) {
15002 if (peer->afc[afi][safi]) {
15003 if (conf_if) {
15004 if ((peer->conf_if
15005 && !strcmp(peer->conf_if, conf_if))
15006 || (peer->hostname
15007 && !strcmp(peer->hostname, conf_if))) {
15008 find = 1;
15009 bgp_show_peer(vty, peer, use_json,
15010 json);
15011 break;
15012 }
15013 } else {
15014 if (sockunion_same(&peer->su, su)) {
15015 find = 1;
15016 bgp_show_peer(vty, peer, use_json,
15017 json);
15018 break;
15019 }
15020 }
15021 }
15022 }
15023 break;
15024 case show_ipv4_all:
15025 case show_ipv6_all:
15026 FOREACH_SAFI (safi) {
15027 if (peer->afc[afi][safi]) {
15028 bgp_show_peer(vty, peer, use_json, json);
15029 nbr_output = true;
15030 break;
15031 }
15032 }
15033 break;
15034 }
15035 }
15036
15037 if ((type == show_peer || type == show_ipv4_peer ||
15038 type == show_ipv6_peer) && !find) {
15039 if (use_json)
15040 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
15041 else
15042 vty_out(vty, "%% No such neighbor in this view/vrf\n");
15043 }
15044
15045 if (type != show_peer && type != show_ipv4_peer &&
15046 type != show_ipv6_peer && !nbr_output && !use_json)
15047 vty_out(vty, "%% No BGP neighbors found\n");
15048
15049 if (use_json) {
15050 vty_out(vty, "%s\n", json_object_to_json_string_ext(
15051 json, JSON_C_TO_STRING_PRETTY));
15052 } else {
15053 vty_out(vty, "\n");
15054 }
15055
15056 return CMD_SUCCESS;
15057 }
15058
15059 static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
15060 enum show_type type,
15061 const char *ip_str,
15062 afi_t afi, bool use_json)
15063 {
15064
15065 int ret;
15066 struct bgp *bgp;
15067 union sockunion su;
15068
15069 bgp = bgp_get_default();
15070
15071 if (!bgp)
15072 return;
15073
15074 if (!use_json)
15075 bgp_show_global_graceful_restart_mode_vty(vty, bgp, use_json,
15076 NULL);
15077
15078 if (ip_str) {
15079 ret = str2sockunion(ip_str, &su);
15080 if (ret < 0)
15081 bgp_show_neighbor_graceful_restart(
15082 vty, bgp, type, NULL, ip_str, afi, use_json);
15083 else
15084 bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
15085 NULL, afi, use_json);
15086 } else
15087 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
15088 afi, use_json);
15089 }
15090
15091 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
15092 enum show_type type,
15093 const char *ip_str,
15094 bool use_json)
15095 {
15096 struct listnode *node, *nnode;
15097 struct bgp *bgp;
15098 union sockunion su;
15099 json_object *json = NULL;
15100 int ret, is_first = 1;
15101 bool nbr_output = false;
15102
15103 if (use_json)
15104 vty_out(vty, "{\n");
15105
15106 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15107 nbr_output = true;
15108 if (use_json) {
15109 if (!(json = json_object_new_object())) {
15110 flog_err(
15111 EC_BGP_JSON_MEM_ERROR,
15112 "Unable to allocate memory for JSON object");
15113 vty_out(vty,
15114 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
15115 return;
15116 }
15117
15118 json_object_int_add(json, "vrfId",
15119 (bgp->vrf_id == VRF_UNKNOWN)
15120 ? -1
15121 : (int64_t)bgp->vrf_id);
15122 json_object_string_add(
15123 json, "vrfName",
15124 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15125 ? VRF_DEFAULT_NAME
15126 : bgp->name);
15127
15128 if (!is_first)
15129 vty_out(vty, ",\n");
15130 else
15131 is_first = 0;
15132
15133 vty_out(vty, "\"%s\":",
15134 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15135 ? VRF_DEFAULT_NAME
15136 : bgp->name);
15137 } else {
15138 vty_out(vty, "\nInstance %s:\n",
15139 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15140 ? VRF_DEFAULT_NAME
15141 : bgp->name);
15142 }
15143
15144 if (type == show_peer || type == show_ipv4_peer ||
15145 type == show_ipv6_peer) {
15146 ret = str2sockunion(ip_str, &su);
15147 if (ret < 0)
15148 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
15149 use_json, json);
15150 else
15151 bgp_show_neighbor(vty, bgp, type, &su, NULL,
15152 use_json, json);
15153 } else {
15154 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
15155 use_json, json);
15156 }
15157 json_object_free(json);
15158 json = NULL;
15159 }
15160
15161 if (use_json)
15162 vty_out(vty, "}\n");
15163 else if (!nbr_output)
15164 vty_out(vty, "%% BGP instance not found\n");
15165 }
15166
15167 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
15168 enum show_type type, const char *ip_str,
15169 bool use_json)
15170 {
15171 int ret;
15172 struct bgp *bgp;
15173 union sockunion su;
15174 json_object *json = NULL;
15175
15176 if (name) {
15177 if (strmatch(name, "all")) {
15178 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
15179 use_json);
15180 return CMD_SUCCESS;
15181 } else {
15182 bgp = bgp_lookup_by_name(name);
15183 if (!bgp) {
15184 if (use_json) {
15185 json = json_object_new_object();
15186 vty_out(vty, "%s\n",
15187 json_object_to_json_string_ext(
15188 json,
15189 JSON_C_TO_STRING_PRETTY));
15190 json_object_free(json);
15191 } else
15192 vty_out(vty,
15193 "%% BGP instance not found\n");
15194
15195 return CMD_WARNING;
15196 }
15197 }
15198 } else {
15199 bgp = bgp_get_default();
15200 }
15201
15202 if (bgp) {
15203 json = json_object_new_object();
15204 if (ip_str) {
15205 ret = str2sockunion(ip_str, &su);
15206 if (ret < 0)
15207 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
15208 use_json, json);
15209 else
15210 bgp_show_neighbor(vty, bgp, type, &su, NULL,
15211 use_json, json);
15212 } else {
15213 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
15214 json);
15215 }
15216 json_object_free(json);
15217 } else {
15218 if (use_json)
15219 vty_out(vty, "{}\n");
15220 else
15221 vty_out(vty, "%% BGP instance not found\n");
15222 }
15223
15224 return CMD_SUCCESS;
15225 }
15226
15227
15228
15229 /* "show [ip] bgp neighbors graceful-restart" commands. */
15230 DEFUN (show_ip_bgp_neighbors_gracrful_restart,
15231 show_ip_bgp_neighbors_graceful_restart_cmd,
15232 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
15233 SHOW_STR
15234 BGP_STR
15235 IP_STR
15236 IPV6_STR
15237 NEIGHBOR_STR
15238 "Neighbor to display information about\n"
15239 "Neighbor to display information about\n"
15240 "Neighbor on BGP configured interface\n"
15241 GR_SHOW
15242 JSON_STR)
15243 {
15244 char *sh_arg = NULL;
15245 enum show_type sh_type;
15246 int idx = 0;
15247 afi_t afi = AFI_MAX;
15248 bool uj = use_json(argc, argv);
15249
15250 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
15251 afi = AFI_MAX;
15252
15253 idx++;
15254
15255 if (argv_find(argv, argc, "A.B.C.D", &idx)
15256 || argv_find(argv, argc, "X:X::X:X", &idx)
15257 || argv_find(argv, argc, "WORD", &idx)) {
15258 sh_type = show_peer;
15259 sh_arg = argv[idx]->arg;
15260 } else
15261 sh_type = show_all;
15262
15263 if (!argv_find(argv, argc, "graceful-restart", &idx))
15264 return CMD_SUCCESS;
15265
15266
15267 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
15268 afi, uj);
15269 }
15270
15271 /* "show [ip] bgp neighbors" commands. */
15272 DEFUN (show_ip_bgp_neighbors,
15273 show_ip_bgp_neighbors_cmd,
15274 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
15275 SHOW_STR
15276 IP_STR
15277 BGP_STR
15278 BGP_INSTANCE_HELP_STR
15279 "Address Family\n"
15280 "Address Family\n"
15281 "Detailed information on TCP and BGP neighbor connections\n"
15282 "Neighbor to display information about\n"
15283 "Neighbor to display information about\n"
15284 "Neighbor on BGP configured interface\n"
15285 JSON_STR)
15286 {
15287 char *vrf = NULL;
15288 char *sh_arg = NULL;
15289 enum show_type sh_type;
15290 afi_t afi = AFI_MAX;
15291
15292 bool uj = use_json(argc, argv);
15293
15294 int idx = 0;
15295
15296 /* [<vrf> VIEWVRFNAME] */
15297 if (argv_find(argv, argc, "vrf", &idx)) {
15298 vrf = argv[idx + 1]->arg;
15299 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15300 vrf = NULL;
15301 } else if (argv_find(argv, argc, "view", &idx))
15302 /* [<view> VIEWVRFNAME] */
15303 vrf = argv[idx + 1]->arg;
15304
15305 idx++;
15306
15307 if (argv_find(argv, argc, "ipv4", &idx)) {
15308 sh_type = show_ipv4_all;
15309 afi = AFI_IP;
15310 } else if (argv_find(argv, argc, "ipv6", &idx)) {
15311 sh_type = show_ipv6_all;
15312 afi = AFI_IP6;
15313 } else {
15314 sh_type = show_all;
15315 }
15316
15317 if (argv_find(argv, argc, "A.B.C.D", &idx)
15318 || argv_find(argv, argc, "X:X::X:X", &idx)
15319 || argv_find(argv, argc, "WORD", &idx)) {
15320 sh_type = show_peer;
15321 sh_arg = argv[idx]->arg;
15322 }
15323
15324 if (sh_type == show_peer && afi == AFI_IP) {
15325 sh_type = show_ipv4_peer;
15326 } else if (sh_type == show_peer && afi == AFI_IP6) {
15327 sh_type = show_ipv6_peer;
15328 }
15329
15330 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
15331 }
15332
15333 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
15334 paths' and `show ip mbgp paths'. Those functions results are the
15335 same.*/
15336 DEFUN (show_ip_bgp_paths,
15337 show_ip_bgp_paths_cmd,
15338 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
15339 SHOW_STR
15340 IP_STR
15341 BGP_STR
15342 BGP_SAFI_HELP_STR
15343 "Path information\n")
15344 {
15345 vty_out(vty, "Address Refcnt Path\n");
15346 aspath_print_all_vty(vty);
15347 return CMD_SUCCESS;
15348 }
15349
15350 #include "hash.h"
15351
15352 static void community_show_all_iterator(struct hash_bucket *bucket,
15353 struct vty *vty)
15354 {
15355 struct community *com;
15356
15357 com = (struct community *)bucket->data;
15358 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
15359 community_str(com, false));
15360 }
15361
15362 /* Show BGP's community internal data. */
15363 DEFUN (show_ip_bgp_community_info,
15364 show_ip_bgp_community_info_cmd,
15365 "show [ip] bgp community-info",
15366 SHOW_STR
15367 IP_STR
15368 BGP_STR
15369 "List all bgp community information\n")
15370 {
15371 vty_out(vty, "Address Refcnt Community\n");
15372
15373 hash_iterate(community_hash(),
15374 (void (*)(struct hash_bucket *,
15375 void *))community_show_all_iterator,
15376 vty);
15377
15378 return CMD_SUCCESS;
15379 }
15380
15381 static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
15382 struct vty *vty)
15383 {
15384 struct lcommunity *lcom;
15385
15386 lcom = (struct lcommunity *)bucket->data;
15387 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
15388 lcommunity_str(lcom, false));
15389 }
15390
15391 /* Show BGP's community internal data. */
15392 DEFUN (show_ip_bgp_lcommunity_info,
15393 show_ip_bgp_lcommunity_info_cmd,
15394 "show ip bgp large-community-info",
15395 SHOW_STR
15396 IP_STR
15397 BGP_STR
15398 "List all bgp large-community information\n")
15399 {
15400 vty_out(vty, "Address Refcnt Large-community\n");
15401
15402 hash_iterate(lcommunity_hash(),
15403 (void (*)(struct hash_bucket *,
15404 void *))lcommunity_show_all_iterator,
15405 vty);
15406
15407 return CMD_SUCCESS;
15408 }
15409 /* Graceful Restart */
15410
15411 static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
15412 struct bgp *bgp,
15413 bool use_json,
15414 json_object *json)
15415 {
15416
15417
15418 vty_out(vty, "\n%s", SHOW_GR_HEADER);
15419
15420 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
15421
15422 switch (bgp_global_gr_mode) {
15423
15424 case GLOBAL_HELPER:
15425 vty_out(vty, "Global BGP GR Mode : Helper\n");
15426 break;
15427
15428 case GLOBAL_GR:
15429 vty_out(vty, "Global BGP GR Mode : Restart\n");
15430 break;
15431
15432 case GLOBAL_DISABLE:
15433 vty_out(vty, "Global BGP GR Mode : Disable\n");
15434 break;
15435
15436 case GLOBAL_INVALID:
15437 vty_out(vty,
15438 "Global BGP GR Mode Invalid\n");
15439 break;
15440 }
15441 vty_out(vty, "\n");
15442 }
15443
15444 static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
15445 enum show_type type,
15446 const char *ip_str,
15447 afi_t afi, bool use_json)
15448 {
15449 if ((afi == AFI_MAX) && (ip_str == NULL)) {
15450 afi = AFI_IP;
15451
15452 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
15453
15454 bgp_show_neighbor_graceful_restart_vty(
15455 vty, type, ip_str, afi, use_json);
15456 afi++;
15457 }
15458 } else if (afi != AFI_MAX) {
15459 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
15460 use_json);
15461 } else {
15462 return CMD_ERR_INCOMPLETE;
15463 }
15464
15465 return CMD_SUCCESS;
15466 }
15467 /* Graceful Restart */
15468
15469 DEFUN (show_ip_bgp_attr_info,
15470 show_ip_bgp_attr_info_cmd,
15471 "show [ip] bgp attribute-info",
15472 SHOW_STR
15473 IP_STR
15474 BGP_STR
15475 "List all bgp attribute information\n")
15476 {
15477 attr_show_all(vty);
15478 return CMD_SUCCESS;
15479 }
15480
15481 static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
15482 afi_t afi, safi_t safi,
15483 bool use_json, json_object *json)
15484 {
15485 struct bgp *bgp;
15486 struct listnode *node;
15487 char *vname;
15488 char buf1[INET6_ADDRSTRLEN];
15489 char *ecom_str;
15490 vpn_policy_direction_t dir;
15491
15492 if (json) {
15493 json_object *json_import_vrfs = NULL;
15494 json_object *json_export_vrfs = NULL;
15495
15496 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15497
15498 if (!bgp) {
15499 vty_out(vty, "%s\n",
15500 json_object_to_json_string_ext(
15501 json,
15502 JSON_C_TO_STRING_PRETTY));
15503 json_object_free(json);
15504
15505 return CMD_WARNING;
15506 }
15507
15508 /* Provide context for the block */
15509 json_object_string_add(json, "vrf", name ? name : "default");
15510 json_object_string_add(json, "afiSafi",
15511 get_afi_safi_str(afi, safi, true));
15512
15513 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15514 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
15515 json_object_string_add(json, "importFromVrfs", "none");
15516 json_object_string_add(json, "importRts", "none");
15517 } else {
15518 json_import_vrfs = json_object_new_array();
15519
15520 for (ALL_LIST_ELEMENTS_RO(
15521 bgp->vpn_policy[afi].import_vrf,
15522 node, vname))
15523 json_object_array_add(json_import_vrfs,
15524 json_object_new_string(vname));
15525
15526 json_object_object_add(json, "importFromVrfs",
15527 json_import_vrfs);
15528 dir = BGP_VPN_POLICY_DIR_FROMVPN;
15529 if (bgp->vpn_policy[afi].rtlist[dir]) {
15530 ecom_str = ecommunity_ecom2str(
15531 bgp->vpn_policy[afi].rtlist[dir],
15532 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15533 json_object_string_add(json, "importRts",
15534 ecom_str);
15535 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15536 } else
15537 json_object_string_add(json, "importRts",
15538 "none");
15539 }
15540
15541 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15542 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
15543 json_object_string_add(json, "exportToVrfs", "none");
15544 json_object_string_add(json, "routeDistinguisher",
15545 "none");
15546 json_object_string_add(json, "exportRts", "none");
15547 } else {
15548 json_export_vrfs = json_object_new_array();
15549
15550 for (ALL_LIST_ELEMENTS_RO(
15551 bgp->vpn_policy[afi].export_vrf,
15552 node, vname))
15553 json_object_array_add(json_export_vrfs,
15554 json_object_new_string(vname));
15555 json_object_object_add(json, "exportToVrfs",
15556 json_export_vrfs);
15557 json_object_string_add(json, "routeDistinguisher",
15558 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
15559 buf1, RD_ADDRSTRLEN));
15560
15561 dir = BGP_VPN_POLICY_DIR_TOVPN;
15562 if (bgp->vpn_policy[afi].rtlist[dir]) {
15563 ecom_str = ecommunity_ecom2str(
15564 bgp->vpn_policy[afi].rtlist[dir],
15565 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15566 json_object_string_add(json, "exportRts",
15567 ecom_str);
15568 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15569 } else
15570 json_object_string_add(json, "exportRts",
15571 "none");
15572 }
15573
15574 if (use_json) {
15575 vty_out(vty, "%s\n",
15576 json_object_to_json_string_ext(json,
15577 JSON_C_TO_STRING_PRETTY));
15578 json_object_free(json);
15579 }
15580 } else {
15581 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15582
15583 if (!bgp) {
15584 vty_out(vty, "%% No such BGP instance exist\n");
15585 return CMD_WARNING;
15586 }
15587
15588 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15589 BGP_CONFIG_VRF_TO_VRF_IMPORT))
15590 vty_out(vty,
15591 "This VRF is not importing %s routes from any other VRF\n",
15592 get_afi_safi_str(afi, safi, false));
15593 else {
15594 vty_out(vty,
15595 "This VRF is importing %s routes from the following VRFs:\n",
15596 get_afi_safi_str(afi, safi, false));
15597
15598 for (ALL_LIST_ELEMENTS_RO(
15599 bgp->vpn_policy[afi].import_vrf,
15600 node, vname))
15601 vty_out(vty, " %s\n", vname);
15602
15603 dir = BGP_VPN_POLICY_DIR_FROMVPN;
15604 ecom_str = NULL;
15605 if (bgp->vpn_policy[afi].rtlist[dir]) {
15606 ecom_str = ecommunity_ecom2str(
15607 bgp->vpn_policy[afi].rtlist[dir],
15608 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15609 vty_out(vty, "Import RT(s): %s\n", ecom_str);
15610
15611 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15612 } else
15613 vty_out(vty, "Import RT(s):\n");
15614 }
15615
15616 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15617 BGP_CONFIG_VRF_TO_VRF_EXPORT))
15618 vty_out(vty,
15619 "This VRF is not exporting %s routes to any other VRF\n",
15620 get_afi_safi_str(afi, safi, false));
15621 else {
15622 vty_out(vty,
15623 "This VRF is exporting %s routes to the following VRFs:\n",
15624 get_afi_safi_str(afi, safi, false));
15625
15626 for (ALL_LIST_ELEMENTS_RO(
15627 bgp->vpn_policy[afi].export_vrf,
15628 node, vname))
15629 vty_out(vty, " %s\n", vname);
15630
15631 vty_out(vty, "RD: %s\n",
15632 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
15633 buf1, RD_ADDRSTRLEN));
15634
15635 dir = BGP_VPN_POLICY_DIR_TOVPN;
15636 if (bgp->vpn_policy[afi].rtlist[dir]) {
15637 ecom_str = ecommunity_ecom2str(
15638 bgp->vpn_policy[afi].rtlist[dir],
15639 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15640 vty_out(vty, "Export RT: %s\n", ecom_str);
15641 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15642 } else
15643 vty_out(vty, "Import RT(s):\n");
15644 }
15645 }
15646
15647 return CMD_SUCCESS;
15648 }
15649
15650 static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
15651 safi_t safi, bool use_json)
15652 {
15653 struct listnode *node, *nnode;
15654 struct bgp *bgp;
15655 char *vrf_name = NULL;
15656 json_object *json = NULL;
15657 json_object *json_vrf = NULL;
15658 json_object *json_vrfs = NULL;
15659
15660 if (use_json) {
15661 json = json_object_new_object();
15662 json_vrfs = json_object_new_object();
15663 }
15664
15665 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15666
15667 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
15668 vrf_name = bgp->name;
15669
15670 if (use_json) {
15671 json_vrf = json_object_new_object();
15672 } else {
15673 vty_out(vty, "\nInstance %s:\n",
15674 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15675 ? VRF_DEFAULT_NAME : bgp->name);
15676 }
15677 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
15678 if (use_json) {
15679 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15680 json_object_object_add(json_vrfs,
15681 VRF_DEFAULT_NAME, json_vrf);
15682 else
15683 json_object_object_add(json_vrfs, vrf_name,
15684 json_vrf);
15685 }
15686 }
15687
15688 if (use_json) {
15689 json_object_object_add(json, "vrfs", json_vrfs);
15690 vty_out(vty, "%s\n", json_object_to_json_string_ext(json,
15691 JSON_C_TO_STRING_PRETTY));
15692 json_object_free(json);
15693 }
15694
15695 return CMD_SUCCESS;
15696 }
15697
15698 /* "show [ip] bgp route-leak" command. */
15699 DEFUN (show_ip_bgp_route_leak,
15700 show_ip_bgp_route_leak_cmd,
15701 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
15702 SHOW_STR
15703 IP_STR
15704 BGP_STR
15705 BGP_INSTANCE_HELP_STR
15706 BGP_AFI_HELP_STR
15707 BGP_SAFI_HELP_STR
15708 "Route leaking information\n"
15709 JSON_STR)
15710 {
15711 char *vrf = NULL;
15712 afi_t afi = AFI_MAX;
15713 safi_t safi = SAFI_MAX;
15714
15715 bool uj = use_json(argc, argv);
15716 int idx = 0;
15717 json_object *json = NULL;
15718
15719 /* show [ip] bgp */
15720 if (argv_find(argv, argc, "ip", &idx)) {
15721 afi = AFI_IP;
15722 safi = SAFI_UNICAST;
15723 }
15724 /* [vrf VIEWVRFNAME] */
15725 if (argv_find(argv, argc, "view", &idx)) {
15726 vty_out(vty,
15727 "%% This command is not applicable to BGP views\n");
15728 return CMD_WARNING;
15729 }
15730
15731 if (argv_find(argv, argc, "vrf", &idx)) {
15732 vrf = argv[idx + 1]->arg;
15733 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15734 vrf = NULL;
15735 }
15736 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15737 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
15738 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15739 }
15740
15741 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
15742 vty_out(vty,
15743 "%% This command is applicable only for unicast ipv4|ipv6\n");
15744 return CMD_WARNING;
15745 }
15746
15747 if (vrf && strmatch(vrf, "all"))
15748 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
15749
15750 if (uj)
15751 json = json_object_new_object();
15752
15753 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
15754 }
15755
15756 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
15757 safi_t safi)
15758 {
15759 struct listnode *node, *nnode;
15760 struct bgp *bgp;
15761
15762 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15763 vty_out(vty, "\nInstance %s:\n",
15764 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15765 ? VRF_DEFAULT_NAME
15766 : bgp->name);
15767 update_group_show(bgp, afi, safi, vty, 0);
15768 }
15769 }
15770
15771 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
15772 int safi, uint64_t subgrp_id)
15773 {
15774 struct bgp *bgp;
15775
15776 if (name) {
15777 if (strmatch(name, "all")) {
15778 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
15779 return CMD_SUCCESS;
15780 } else {
15781 bgp = bgp_lookup_by_name(name);
15782 }
15783 } else {
15784 bgp = bgp_get_default();
15785 }
15786
15787 if (bgp)
15788 update_group_show(bgp, afi, safi, vty, subgrp_id);
15789 return CMD_SUCCESS;
15790 }
15791
15792 DEFUN (show_ip_bgp_updgrps,
15793 show_ip_bgp_updgrps_cmd,
15794 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
15795 SHOW_STR
15796 IP_STR
15797 BGP_STR
15798 BGP_INSTANCE_HELP_STR
15799 BGP_AFI_HELP_STR
15800 BGP_SAFI_WITH_LABEL_HELP_STR
15801 "Detailed info about dynamic update groups\n"
15802 "Specific subgroup to display detailed info for\n")
15803 {
15804 char *vrf = NULL;
15805 afi_t afi = AFI_IP6;
15806 safi_t safi = SAFI_UNICAST;
15807 uint64_t subgrp_id = 0;
15808
15809 int idx = 0;
15810
15811 /* show [ip] bgp */
15812 if (argv_find(argv, argc, "ip", &idx))
15813 afi = AFI_IP;
15814 /* [<vrf> VIEWVRFNAME] */
15815 if (argv_find(argv, argc, "vrf", &idx)) {
15816 vrf = argv[idx + 1]->arg;
15817 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15818 vrf = NULL;
15819 } else if (argv_find(argv, argc, "view", &idx))
15820 /* [<view> VIEWVRFNAME] */
15821 vrf = argv[idx + 1]->arg;
15822 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15823 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
15824 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15825 }
15826
15827 /* get subgroup id, if provided */
15828 idx = argc - 1;
15829 if (argv[idx]->type == VARIABLE_TKN)
15830 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
15831
15832 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
15833 }
15834
15835 DEFUN (show_bgp_instance_all_ipv6_updgrps,
15836 show_bgp_instance_all_ipv6_updgrps_cmd,
15837 "show [ip] bgp <view|vrf> all update-groups",
15838 SHOW_STR
15839 IP_STR
15840 BGP_STR
15841 BGP_INSTANCE_ALL_HELP_STR
15842 "Detailed info about dynamic update groups\n")
15843 {
15844 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
15845 return CMD_SUCCESS;
15846 }
15847
15848 DEFUN (show_bgp_l2vpn_evpn_updgrps,
15849 show_bgp_l2vpn_evpn_updgrps_cmd,
15850 "show [ip] bgp l2vpn evpn update-groups",
15851 SHOW_STR
15852 IP_STR
15853 BGP_STR
15854 "l2vpn address family\n"
15855 "evpn sub-address family\n"
15856 "Detailed info about dynamic update groups\n")
15857 {
15858 char *vrf = NULL;
15859 uint64_t subgrp_id = 0;
15860
15861 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
15862 return CMD_SUCCESS;
15863 }
15864
15865 DEFUN (show_bgp_updgrps_stats,
15866 show_bgp_updgrps_stats_cmd,
15867 "show [ip] bgp update-groups statistics",
15868 SHOW_STR
15869 IP_STR
15870 BGP_STR
15871 "Detailed info about dynamic update groups\n"
15872 "Statistics\n")
15873 {
15874 struct bgp *bgp;
15875
15876 bgp = bgp_get_default();
15877 if (bgp)
15878 update_group_show_stats(bgp, vty);
15879
15880 return CMD_SUCCESS;
15881 }
15882
15883 DEFUN (show_bgp_instance_updgrps_stats,
15884 show_bgp_instance_updgrps_stats_cmd,
15885 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
15886 SHOW_STR
15887 IP_STR
15888 BGP_STR
15889 BGP_INSTANCE_HELP_STR
15890 "Detailed info about dynamic update groups\n"
15891 "Statistics\n")
15892 {
15893 int idx_word = 3;
15894 struct bgp *bgp;
15895
15896 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
15897 if (bgp)
15898 update_group_show_stats(bgp, vty);
15899
15900 return CMD_SUCCESS;
15901 }
15902
15903 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
15904 afi_t afi, safi_t safi,
15905 const char *what, uint64_t subgrp_id)
15906 {
15907 struct bgp *bgp;
15908
15909 if (name)
15910 bgp = bgp_lookup_by_name(name);
15911 else
15912 bgp = bgp_get_default();
15913
15914 if (bgp) {
15915 if (!strcmp(what, "advertise-queue"))
15916 update_group_show_adj_queue(bgp, afi, safi, vty,
15917 subgrp_id);
15918 else if (!strcmp(what, "advertised-routes"))
15919 update_group_show_advertised(bgp, afi, safi, vty,
15920 subgrp_id);
15921 else if (!strcmp(what, "packet-queue"))
15922 update_group_show_packet_queue(bgp, afi, safi, vty,
15923 subgrp_id);
15924 }
15925 }
15926
15927 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
15928 show_ip_bgp_instance_updgrps_adj_s_cmd,
15929 "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",
15930 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
15931 BGP_SAFI_HELP_STR
15932 "Detailed info about dynamic update groups\n"
15933 "Specific subgroup to display info for\n"
15934 "Advertisement queue\n"
15935 "Announced routes\n"
15936 "Packet queue\n")
15937 {
15938 uint64_t subgrp_id = 0;
15939 afi_t afiz;
15940 safi_t safiz;
15941 if (sgid)
15942 subgrp_id = strtoull(sgid, NULL, 10);
15943
15944 if (!ip && !afi)
15945 afiz = AFI_IP6;
15946 if (!ip && afi)
15947 afiz = bgp_vty_afi_from_str(afi);
15948 if (ip && !afi)
15949 afiz = AFI_IP;
15950 if (ip && afi) {
15951 afiz = bgp_vty_afi_from_str(afi);
15952 if (afiz != AFI_IP)
15953 vty_out(vty,
15954 "%% Cannot specify both 'ip' and 'ipv6'\n");
15955 return CMD_WARNING;
15956 }
15957
15958 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
15959
15960 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
15961 return CMD_SUCCESS;
15962 }
15963
15964 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group,
15965 json_object *json)
15966 {
15967 struct listnode *node, *nnode;
15968 struct prefix *range;
15969 struct peer *conf;
15970 struct peer *peer;
15971 afi_t afi;
15972 safi_t safi;
15973 const char *peer_status;
15974 int lr_count;
15975 int dynamic;
15976 bool af_cfgd;
15977 json_object *json_peer_group = NULL;
15978 json_object *json_peer_group_afc = NULL;
15979 json_object *json_peer_group_members = NULL;
15980 json_object *json_peer_group_dynamic = NULL;
15981 json_object *json_peer_group_dynamic_af = NULL;
15982 json_object *json_peer_group_ranges = NULL;
15983
15984 conf = group->conf;
15985
15986 if (json) {
15987 json_peer_group = json_object_new_object();
15988 json_peer_group_afc = json_object_new_array();
15989 }
15990
15991 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
15992 if (json)
15993 json_object_int_add(json_peer_group, "remoteAs",
15994 conf->as);
15995 else
15996 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15997 group->name, conf->as);
15998 } else if (conf->as_type == AS_INTERNAL) {
15999 if (json)
16000 json_object_int_add(json_peer_group, "remoteAs",
16001 group->bgp->as);
16002 else
16003 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
16004 group->name, group->bgp->as);
16005 } else {
16006 if (!json)
16007 vty_out(vty, "\nBGP peer-group %s\n", group->name);
16008 }
16009
16010 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL)) {
16011 if (json)
16012 json_object_string_add(json_peer_group, "type",
16013 "internal");
16014 else
16015 vty_out(vty, " Peer-group type is internal\n");
16016 } else {
16017 if (json)
16018 json_object_string_add(json_peer_group, "type",
16019 "external");
16020 else
16021 vty_out(vty, " Peer-group type is external\n");
16022 }
16023
16024 /* Display AFs configured. */
16025 if (!json)
16026 vty_out(vty, " Configured address-families:");
16027
16028 FOREACH_AFI_SAFI (afi, safi) {
16029 if (conf->afc[afi][safi]) {
16030 af_cfgd = true;
16031 if (json)
16032 json_object_array_add(
16033 json_peer_group_afc,
16034 json_object_new_string(get_afi_safi_str(
16035 afi, safi, false)));
16036 else
16037 vty_out(vty, " %s;",
16038 get_afi_safi_str(afi, safi, false));
16039 }
16040 }
16041
16042 if (json) {
16043 json_object_object_add(json_peer_group,
16044 "addressFamiliesConfigured",
16045 json_peer_group_afc);
16046 } else {
16047 if (!af_cfgd)
16048 vty_out(vty, " none\n");
16049 else
16050 vty_out(vty, "\n");
16051 }
16052
16053 /* Display listen ranges (for dynamic neighbors), if any */
16054 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
16055 lr_count = listcount(group->listen_range[afi]);
16056 if (lr_count) {
16057 if (json) {
16058 if (!json_peer_group_dynamic)
16059 json_peer_group_dynamic =
16060 json_object_new_object();
16061
16062 json_peer_group_dynamic_af =
16063 json_object_new_object();
16064 json_peer_group_ranges =
16065 json_object_new_array();
16066 json_object_int_add(json_peer_group_dynamic_af,
16067 "count", lr_count);
16068 } else {
16069 vty_out(vty, " %d %s listen range(s)\n",
16070 lr_count, afi2str(afi));
16071 }
16072
16073 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
16074 nnode, range)) {
16075 if (json) {
16076 char buf[BUFSIZ];
16077
16078 snprintfrr(buf, sizeof(buf), "%pFX",
16079 range);
16080
16081 json_object_array_add(
16082 json_peer_group_ranges,
16083 json_object_new_string(buf));
16084 } else {
16085 vty_out(vty, " %pFX\n", range);
16086 }
16087 }
16088
16089 if (json) {
16090 json_object_object_add(
16091 json_peer_group_dynamic_af, "ranges",
16092 json_peer_group_ranges);
16093
16094 json_object_object_add(
16095 json_peer_group_dynamic, afi2str(afi),
16096 json_peer_group_dynamic_af);
16097 }
16098 }
16099 }
16100
16101 if (json_peer_group_dynamic)
16102 json_object_object_add(json_peer_group, "dynamicRanges",
16103 json_peer_group_dynamic);
16104
16105 /* Display group members and their status */
16106 if (listcount(group->peer)) {
16107 if (json)
16108 json_peer_group_members = json_object_new_object();
16109 else
16110 vty_out(vty, " Peer-group members:\n");
16111 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
16112 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
16113 || CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHUTDOWN))
16114 peer_status = "Idle (Admin)";
16115 else if (CHECK_FLAG(peer->sflags,
16116 PEER_STATUS_PREFIX_OVERFLOW))
16117 peer_status = "Idle (PfxCt)";
16118 else
16119 peer_status = lookup_msg(bgp_status_msg,
16120 peer->status, NULL);
16121
16122 dynamic = peer_dynamic_neighbor(peer);
16123
16124 if (json) {
16125 json_object *json_peer_group_member =
16126 json_object_new_object();
16127
16128 json_object_string_add(json_peer_group_member,
16129 "status", peer_status);
16130
16131 if (dynamic)
16132 json_object_boolean_true_add(
16133 json_peer_group_member,
16134 "dynamic");
16135
16136 json_object_object_add(json_peer_group_members,
16137 peer->host,
16138 json_peer_group_member);
16139 } else {
16140 vty_out(vty, " %s %s %s \n", peer->host,
16141 dynamic ? "(dynamic)" : "",
16142 peer_status);
16143 }
16144 }
16145 if (json)
16146 json_object_object_add(json_peer_group, "members",
16147 json_peer_group_members);
16148 }
16149
16150 if (json)
16151 json_object_object_add(json, group->name, json_peer_group);
16152
16153 return CMD_SUCCESS;
16154 }
16155
16156 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
16157 const char *group_name, bool uj)
16158 {
16159 struct bgp *bgp;
16160 struct listnode *node, *nnode;
16161 struct peer_group *group;
16162 bool found = false;
16163 json_object *json = NULL;
16164
16165 if (uj)
16166 json = json_object_new_object();
16167
16168 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
16169
16170 if (!bgp) {
16171 if (uj) {
16172 vty_out(vty, "%s\n",
16173 json_object_to_json_string_ext(
16174 json, JSON_C_TO_STRING_PRETTY));
16175 json_object_free(json);
16176 } else {
16177 vty_out(vty, "%% BGP instance not found\n");
16178 }
16179
16180 return CMD_WARNING;
16181 }
16182
16183 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
16184 if (group_name) {
16185 if (strmatch(group->name, group_name)) {
16186 bgp_show_one_peer_group(vty, group, json);
16187 found = true;
16188 break;
16189 }
16190 } else {
16191 bgp_show_one_peer_group(vty, group, json);
16192 }
16193 }
16194
16195 if (group_name && !found && !uj)
16196 vty_out(vty, "%% No such peer-group\n");
16197
16198 if (uj) {
16199 vty_out(vty, "%s\n",
16200 json_object_to_json_string_ext(
16201 json, JSON_C_TO_STRING_PRETTY));
16202 json_object_free(json);
16203 }
16204
16205 return CMD_SUCCESS;
16206 }
16207
16208 DEFUN(show_ip_bgp_peer_groups, show_ip_bgp_peer_groups_cmd,
16209 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME] [json]",
16210 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR
16211 "Detailed information on BGP peer groups\n"
16212 "Peer group name\n" JSON_STR)
16213 {
16214 char *vrf, *pg;
16215 int idx = 0;
16216 bool uj = use_json(argc, argv);
16217
16218 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
16219 : NULL;
16220 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
16221
16222 return bgp_show_peer_group_vty(vty, vrf, pg, uj);
16223 }
16224
16225
16226 /* Redistribute VTY commands. */
16227
16228 DEFUN_YANG (bgp_redistribute_ipv4,
16229 bgp_redistribute_ipv4_cmd,
16230 "redistribute " FRR_IP_REDIST_STR_BGPD,
16231 "Redistribute information from another routing protocol\n"
16232 FRR_IP_REDIST_HELP_STR_BGPD)
16233 {
16234 int idx_protocol = 1;
16235 char base_xpath[XPATH_MAXLEN];
16236
16237 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16238 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16239 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16240 argv[idx_protocol]->text, "0");
16241
16242 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16243
16244 return nb_cli_apply_changes(vty, base_xpath);
16245 }
16246
16247 ALIAS_HIDDEN(
16248 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
16249 "redistribute " FRR_IP_REDIST_STR_BGPD,
16250 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
16251
16252 DEFUN_YANG (bgp_redistribute_ipv4_rmap,
16253 bgp_redistribute_ipv4_rmap_cmd,
16254 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
16255 "Redistribute information from another routing protocol\n"
16256 FRR_IP_REDIST_HELP_STR_BGPD
16257 "Route map reference\n"
16258 "Pointer to route-map entries\n")
16259 {
16260 int idx_protocol = 1;
16261 int idx_word = 3;
16262 char base_xpath[XPATH_MAXLEN];
16263
16264 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16265 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16266 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16267 argv[idx_protocol]->text, "0");
16268
16269 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16270 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16271 argv[idx_word]->arg);
16272
16273 return nb_cli_apply_changes(vty, base_xpath);
16274 }
16275
16276 ALIAS_HIDDEN(
16277 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
16278 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
16279 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16280 "Route map reference\n"
16281 "Pointer to route-map entries\n")
16282
16283 DEFUN_YANG (bgp_redistribute_ipv4_metric,
16284 bgp_redistribute_ipv4_metric_cmd,
16285 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
16286 "Redistribute information from another routing protocol\n"
16287 FRR_IP_REDIST_HELP_STR_BGPD
16288 "Metric for redistributed routes\n"
16289 "Default metric\n")
16290 {
16291 int idx_protocol = 1;
16292 int idx_number = 3;
16293 char base_xpath[XPATH_MAXLEN];
16294
16295 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16296 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16297 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16298 argv[idx_protocol]->text, "0");
16299
16300 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16301 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16302 argv[idx_number]->arg);
16303
16304 return nb_cli_apply_changes(vty, base_xpath);
16305 }
16306
16307 ALIAS_HIDDEN(
16308 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
16309 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
16310 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16311 "Metric for redistributed routes\n"
16312 "Default metric\n")
16313
16314 DEFUN_YANG(
16315 bgp_redistribute_ipv4_rmap_metric,
16316 bgp_redistribute_ipv4_rmap_metric_cmd,
16317 "redistribute " FRR_IP_REDIST_STR_BGPD
16318 " route-map WORD metric (0-4294967295)",
16319 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16320 "Route map reference\n"
16321 "Pointer to route-map entries\n"
16322 "Metric for redistributed routes\n"
16323 "Default metric\n")
16324 {
16325 int idx_protocol = 1;
16326 int idx_word = 3;
16327 int idx_number = 5;
16328 char base_xpath[XPATH_MAXLEN];
16329
16330 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16331 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16332 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16333 argv[idx_protocol]->text, "0");
16334
16335 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16336 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16337 argv[idx_word]->arg);
16338 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16339 argv[idx_number]->arg);
16340
16341 return nb_cli_apply_changes(vty, base_xpath);
16342 }
16343
16344 ALIAS_HIDDEN(
16345 bgp_redistribute_ipv4_rmap_metric,
16346 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
16347 "redistribute " FRR_IP_REDIST_STR_BGPD
16348 " route-map WORD metric (0-4294967295)",
16349 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16350 "Route map reference\n"
16351 "Pointer to route-map entries\n"
16352 "Metric for redistributed routes\n"
16353 "Default metric\n")
16354
16355 DEFUN_YANG(
16356 bgp_redistribute_ipv4_metric_rmap,
16357 bgp_redistribute_ipv4_metric_rmap_cmd,
16358 "redistribute " FRR_IP_REDIST_STR_BGPD
16359 " metric (0-4294967295) route-map WORD",
16360 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16361 "Metric for redistributed routes\n"
16362 "Default metric\n"
16363 "Route map reference\n"
16364 "Pointer to route-map entries\n")
16365 {
16366 int idx_protocol = 1;
16367 int idx_word = 5;
16368 int idx_number = 3;
16369 char base_xpath[XPATH_MAXLEN];
16370
16371 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16372 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16373 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16374 argv[idx_protocol]->text, "0");
16375
16376 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16377 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16378 argv[idx_number]->arg);
16379 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16380 argv[idx_word]->arg);
16381
16382 return nb_cli_apply_changes(vty, base_xpath);
16383 }
16384
16385 ALIAS_HIDDEN(
16386 bgp_redistribute_ipv4_metric_rmap,
16387 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
16388 "redistribute " FRR_IP_REDIST_STR_BGPD
16389 " metric (0-4294967295) route-map WORD",
16390 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16391 "Metric for redistributed routes\n"
16392 "Default metric\n"
16393 "Route map reference\n"
16394 "Pointer to route-map entries\n")
16395
16396 DEFUN_YANG (bgp_redistribute_ipv4_ospf,
16397 bgp_redistribute_ipv4_ospf_cmd,
16398 "redistribute <ospf|table> (1-65535)",
16399 "Redistribute information from another routing protocol\n"
16400 "Open Shortest Path First (OSPFv2)\n"
16401 "Non-main Kernel Routing Table\n"
16402 "Instance ID/Table ID\n")
16403 {
16404 int idx_protocol = 1;
16405 int idx_number = 2;
16406 char base_xpath[XPATH_MAXLEN];
16407
16408 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16409 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16410 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16411 argv[idx_protocol]->text, argv[idx_number]->arg);
16412
16413 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16414
16415 return nb_cli_apply_changes(vty, base_xpath);
16416 }
16417
16418 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
16419 "redistribute <ospf|table> (1-65535)",
16420 "Redistribute information from another routing protocol\n"
16421 "Open Shortest Path First (OSPFv2)\n"
16422 "Non-main Kernel Routing Table\n"
16423 "Instance ID/Table ID\n")
16424
16425 DEFUN_YANG (bgp_redistribute_ipv4_ospf_rmap,
16426 bgp_redistribute_ipv4_ospf_rmap_cmd,
16427 "redistribute <ospf|table> (1-65535) route-map WORD",
16428 "Redistribute information from another routing protocol\n"
16429 "Open Shortest Path First (OSPFv2)\n"
16430 "Non-main Kernel Routing Table\n"
16431 "Instance ID/Table ID\n"
16432 "Route map reference\n"
16433 "Pointer to route-map entries\n")
16434 {
16435 int idx_protocol = 1;
16436 int idx_number = 2;
16437 int idx_word = 4;
16438 char base_xpath[XPATH_MAXLEN];
16439
16440 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16441 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16442 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16443 argv[idx_protocol]->text, argv[idx_number]->arg);
16444
16445 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16446
16447 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16448 argv[idx_word]->arg);
16449
16450 return nb_cli_apply_changes(vty, base_xpath);
16451 }
16452
16453 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
16454 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
16455 "redistribute <ospf|table> (1-65535) route-map WORD",
16456 "Redistribute information from another routing protocol\n"
16457 "Open Shortest Path First (OSPFv2)\n"
16458 "Non-main Kernel Routing Table\n"
16459 "Instance ID/Table ID\n"
16460 "Route map reference\n"
16461 "Pointer to route-map entries\n")
16462
16463 DEFUN_YANG(bgp_redistribute_ipv4_ospf_metric,
16464 bgp_redistribute_ipv4_ospf_metric_cmd,
16465 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
16466 "Redistribute information from another routing protocol\n"
16467 "Open Shortest Path First (OSPFv2)\n"
16468 "Non-main Kernel Routing Table\n"
16469 "Instance ID/Table ID\n"
16470 "Metric for redistributed routes\n"
16471 "Default metric\n")
16472 {
16473 int idx_protocol = 1;
16474 int idx_number = 2;
16475 int idx_number_2 = 4;
16476 char base_xpath[XPATH_MAXLEN];
16477
16478 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16479 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16480 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16481 argv[idx_protocol]->text, argv[idx_number]->arg);
16482
16483 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16484
16485 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16486 argv[idx_number_2]->arg);
16487
16488 return nb_cli_apply_changes(vty, base_xpath);
16489 }
16490
16491 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
16492 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
16493 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
16494 "Redistribute information from another routing protocol\n"
16495 "Open Shortest Path First (OSPFv2)\n"
16496 "Non-main Kernel Routing Table\n"
16497 "Instance ID/Table ID\n"
16498 "Metric for redistributed routes\n"
16499 "Default metric\n")
16500
16501 DEFUN_YANG(
16502 bgp_redistribute_ipv4_ospf_rmap_metric,
16503 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
16504 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
16505 "Redistribute information from another routing protocol\n"
16506 "Open Shortest Path First (OSPFv2)\n"
16507 "Non-main Kernel Routing Table\n"
16508 "Instance ID/Table ID\n"
16509 "Route map reference\n"
16510 "Pointer to route-map entries\n"
16511 "Metric for redistributed routes\n"
16512 "Default metric\n")
16513 {
16514 int idx_protocol = 1;
16515 int idx_number = 2;
16516 int idx_word = 4;
16517 int idx_number_2 = 6;
16518 char base_xpath[XPATH_MAXLEN];
16519
16520 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16521 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16522 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16523 argv[idx_protocol]->text, argv[idx_number]->arg);
16524
16525 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16526
16527 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16528 argv[idx_word]->arg);
16529 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16530 argv[idx_number_2]->arg);
16531
16532 return nb_cli_apply_changes(vty, base_xpath);
16533 }
16534
16535 ALIAS_HIDDEN(
16536 bgp_redistribute_ipv4_ospf_rmap_metric,
16537 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
16538 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
16539 "Redistribute information from another routing protocol\n"
16540 "Open Shortest Path First (OSPFv2)\n"
16541 "Non-main Kernel Routing Table\n"
16542 "Instance ID/Table ID\n"
16543 "Route map reference\n"
16544 "Pointer to route-map entries\n"
16545 "Metric for redistributed routes\n"
16546 "Default metric\n")
16547
16548 DEFUN_YANG(
16549 bgp_redistribute_ipv4_ospf_metric_rmap,
16550 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
16551 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
16552 "Redistribute information from another routing protocol\n"
16553 "Open Shortest Path First (OSPFv2)\n"
16554 "Non-main Kernel Routing Table\n"
16555 "Instance ID/Table ID\n"
16556 "Metric for redistributed routes\n"
16557 "Default metric\n"
16558 "Route map reference\n"
16559 "Pointer to route-map entries\n")
16560 {
16561 int idx_protocol = 1;
16562 int idx_number = 2;
16563 int idx_number_2 = 4;
16564 int idx_word = 6;
16565 char base_xpath[XPATH_MAXLEN];
16566
16567 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16568 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16569 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16570 argv[idx_protocol]->text, argv[idx_number]->arg);
16571
16572 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16573
16574 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16575 argv[idx_number_2]->arg);
16576 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16577 argv[idx_word]->arg);
16578
16579 return nb_cli_apply_changes(vty, base_xpath);
16580 }
16581
16582 ALIAS_HIDDEN(
16583 bgp_redistribute_ipv4_ospf_metric_rmap,
16584 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
16585 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
16586 "Redistribute information from another routing protocol\n"
16587 "Open Shortest Path First (OSPFv2)\n"
16588 "Non-main Kernel Routing Table\n"
16589 "Instance ID/Table ID\n"
16590 "Metric for redistributed routes\n"
16591 "Default metric\n"
16592 "Route map reference\n"
16593 "Pointer to route-map entries\n")
16594
16595 DEFUN_YANG (no_bgp_redistribute_ipv4_ospf,
16596 no_bgp_redistribute_ipv4_ospf_cmd,
16597 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
16598 NO_STR
16599 "Redistribute information from another routing protocol\n"
16600 "Open Shortest Path First (OSPFv2)\n"
16601 "Non-main Kernel Routing Table\n"
16602 "Instance ID/Table ID\n"
16603 "Metric for redistributed routes\n"
16604 "Default metric\n"
16605 "Route map reference\n"
16606 "Pointer to route-map entries\n")
16607 {
16608 int idx_protocol = 2;
16609 int idx_number = 3;
16610 char base_xpath[XPATH_MAXLEN];
16611
16612 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16613 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16614 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16615 argv[idx_protocol]->text, argv[idx_number]->arg);
16616
16617 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
16618
16619 return nb_cli_apply_changes(vty, base_xpath);
16620 }
16621
16622 ALIAS_HIDDEN(
16623 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
16624 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
16625 NO_STR
16626 "Redistribute information from another routing protocol\n"
16627 "Open Shortest Path First (OSPFv2)\n"
16628 "Non-main Kernel Routing Table\n"
16629 "Instance ID/Table ID\n"
16630 "Metric for redistributed routes\n"
16631 "Default metric\n"
16632 "Route map reference\n"
16633 "Pointer to route-map entries\n")
16634
16635 DEFUN_YANG (no_bgp_redistribute_ipv4,
16636 no_bgp_redistribute_ipv4_cmd,
16637 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
16638 NO_STR
16639 "Redistribute information from another routing protocol\n"
16640 FRR_IP_REDIST_HELP_STR_BGPD
16641 "Metric for redistributed routes\n"
16642 "Default metric\n"
16643 "Route map reference\n"
16644 "Pointer to route-map entries\n")
16645 {
16646 int idx_protocol = 2;
16647 char base_xpath[XPATH_MAXLEN];
16648
16649 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16650 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16651 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16652 argv[idx_protocol]->text, "0");
16653
16654 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
16655
16656 return nb_cli_apply_changes(vty, base_xpath);
16657 }
16658
16659 ALIAS_HIDDEN(
16660 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
16661 "no redistribute " FRR_IP_REDIST_STR_BGPD
16662 " [{metric (0-4294967295)|route-map WORD}]",
16663 NO_STR
16664 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16665 "Metric for redistributed routes\n"
16666 "Default metric\n"
16667 "Route map reference\n"
16668 "Pointer to route-map entries\n")
16669
16670 DEFUN_YANG (bgp_redistribute_ipv6,
16671 bgp_redistribute_ipv6_cmd,
16672 "redistribute " FRR_IP6_REDIST_STR_BGPD,
16673 "Redistribute information from another routing protocol\n"
16674 FRR_IP6_REDIST_HELP_STR_BGPD)
16675 {
16676 int idx_protocol = 1;
16677 char base_xpath[XPATH_MAXLEN];
16678
16679 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16680 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16681 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16682 argv[idx_protocol]->text, "0");
16683
16684 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16685
16686 return nb_cli_apply_changes(vty, base_xpath);
16687 }
16688
16689 DEFUN_YANG (bgp_redistribute_ipv6_rmap,
16690 bgp_redistribute_ipv6_rmap_cmd,
16691 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
16692 "Redistribute information from another routing protocol\n"
16693 FRR_IP6_REDIST_HELP_STR_BGPD
16694 "Route map reference\n"
16695 "Pointer to route-map entries\n")
16696 {
16697 int idx_protocol = 1;
16698 int idx_word = 3;
16699 char base_xpath[XPATH_MAXLEN];
16700
16701 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16702 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16703 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16704 argv[idx_protocol]->text, "0");
16705
16706 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16707 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16708 argv[idx_word]->arg);
16709
16710 return nb_cli_apply_changes(vty, base_xpath);
16711 }
16712
16713 DEFUN_YANG (bgp_redistribute_ipv6_metric,
16714 bgp_redistribute_ipv6_metric_cmd,
16715 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
16716 "Redistribute information from another routing protocol\n"
16717 FRR_IP6_REDIST_HELP_STR_BGPD
16718 "Metric for redistributed routes\n"
16719 "Default metric\n")
16720 {
16721 int idx_protocol = 1;
16722 int idx_number = 3;
16723 char base_xpath[XPATH_MAXLEN];
16724
16725 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16726 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16727 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16728 argv[idx_protocol]->text, "0");
16729
16730 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16731 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16732 argv[idx_number]->arg);
16733
16734 return nb_cli_apply_changes(vty, base_xpath);
16735 }
16736
16737 DEFUN_YANG(
16738 bgp_redistribute_ipv6_rmap_metric,
16739 bgp_redistribute_ipv6_rmap_metric_cmd,
16740 "redistribute " FRR_IP6_REDIST_STR_BGPD
16741 " route-map WORD metric (0-4294967295)",
16742 "Redistribute information from another routing protocol\n" FRR_IP6_REDIST_HELP_STR_BGPD
16743 "Route map reference\n"
16744 "Pointer to route-map entries\n"
16745 "Metric for redistributed routes\n"
16746 "Default metric\n")
16747 {
16748 int idx_protocol = 1;
16749 int idx_word = 3;
16750 int idx_number = 5;
16751 char base_xpath[XPATH_MAXLEN];
16752
16753 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16754 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16755 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16756 argv[idx_protocol]->text, "0");
16757
16758 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16759 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16760 argv[idx_word]->arg);
16761 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16762 argv[idx_number]->arg);
16763
16764 return nb_cli_apply_changes(vty, base_xpath);
16765 }
16766
16767 DEFUN_YANG(
16768 bgp_redistribute_ipv6_metric_rmap,
16769 bgp_redistribute_ipv6_metric_rmap_cmd,
16770 "redistribute " FRR_IP6_REDIST_STR_BGPD
16771 " metric (0-4294967295) route-map WORD",
16772 "Redistribute information from another routing protocol\n" FRR_IP6_REDIST_HELP_STR_BGPD
16773 "Metric for redistributed routes\n"
16774 "Default metric\n"
16775 "Route map reference\n"
16776 "Pointer to route-map entries\n")
16777 {
16778 int idx_protocol = 1;
16779 int idx_word = 5;
16780 int idx_number = 3;
16781 char base_xpath[XPATH_MAXLEN];
16782
16783 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16784 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16785 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16786 argv[idx_protocol]->text, "0");
16787
16788 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16789 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16790 argv[idx_number]->arg);
16791 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16792 argv[idx_word]->arg);
16793
16794 return nb_cli_apply_changes(vty, base_xpath);
16795 }
16796
16797 DEFUN_YANG(
16798 no_bgp_redistribute_ipv6,
16799 no_bgp_redistribute_ipv6_cmd,
16800 "no redistribute " FRR_IP6_REDIST_STR_BGPD
16801 " [{metric (0-4294967295)|route-map WORD}]",
16802 NO_STR
16803 "Redistribute information from another routing protocol\n" FRR_IP6_REDIST_HELP_STR_BGPD
16804 "Metric for redistributed routes\n"
16805 "Default metric\n"
16806 "Route map reference\n"
16807 "Pointer to route-map entries\n")
16808 {
16809 int idx_protocol = 2;
16810 char base_xpath[XPATH_MAXLEN];
16811
16812 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16813 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16814 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16815 argv[idx_protocol]->text, "0");
16816
16817 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
16818
16819 return nb_cli_apply_changes(vty, base_xpath);
16820 }
16821
16822 void cli_show_bgp_global_afi_safi_ip_unicast_redistribution_list(
16823 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
16824 {
16825 uint32_t instance = 0;
16826
16827 vty_out(vty, " redistribute %s",
16828 yang_dnode_get_string(dnode, "./route-type"));
16829 if ((instance = yang_dnode_get_uint16(dnode, "./route-instance")))
16830 vty_out(vty, " %d", instance);
16831 if (yang_dnode_exists(dnode, "./metric"))
16832 vty_out(vty, " metric %u",
16833 yang_dnode_get_uint32(dnode, "./metric"));
16834 if (yang_dnode_exists(dnode, "./rmap-policy-import"))
16835 vty_out(vty, " route-map %s",
16836 yang_dnode_get_string(dnode, "./rmap-policy-import"));
16837 vty_out(vty, "\n");
16838 }
16839
16840 /* Neighbor update tcp-mss. */
16841 static int peer_tcp_mss_vty(struct vty *vty, const char *peer_str,
16842 const char *tcp_mss_str)
16843 {
16844 struct peer *peer;
16845 uint32_t tcp_mss_val = 0;
16846
16847 peer = peer_and_group_lookup_vty(vty, peer_str);
16848 if (!peer)
16849 return CMD_WARNING_CONFIG_FAILED;
16850
16851 if (tcp_mss_str) {
16852 tcp_mss_val = strtoul(tcp_mss_str, NULL, 10);
16853 peer_tcp_mss_set(peer, tcp_mss_val);
16854 } else {
16855 peer_tcp_mss_unset(peer);
16856 }
16857
16858 return CMD_SUCCESS;
16859 }
16860
16861 DEFUN(neighbor_tcp_mss, neighbor_tcp_mss_cmd,
16862 "neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss (1-65535)",
16863 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16864 "TCP max segment size\n"
16865 "TCP MSS value\n")
16866 {
16867 int peer_index = 1;
16868 int mss_index = 3;
16869
16870 vty_out(vty,
16871 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16872 return peer_tcp_mss_vty(vty, argv[peer_index]->arg,
16873 argv[mss_index]->arg);
16874 }
16875
16876 DEFUN(no_neighbor_tcp_mss, no_neighbor_tcp_mss_cmd,
16877 "no neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss [(1-65535)]",
16878 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16879 "TCP max segment size\n"
16880 "TCP MSS value\n")
16881 {
16882 int peer_index = 2;
16883
16884 vty_out(vty,
16885 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16886 return peer_tcp_mss_vty(vty, argv[peer_index]->arg, NULL);
16887 }
16888
16889 static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
16890 afi_t afi, safi_t safi)
16891 {
16892 int i;
16893
16894 /* Unicast redistribution only. */
16895 if (safi != SAFI_UNICAST)
16896 return;
16897
16898 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
16899 /* Redistribute BGP does not make sense. */
16900 if (i != ZEBRA_ROUTE_BGP) {
16901 struct list *red_list;
16902 struct listnode *node;
16903 struct bgp_redist *red;
16904
16905 red_list = bgp->redist[afi][i];
16906 if (!red_list)
16907 continue;
16908
16909 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
16910 /* "redistribute" configuration. */
16911 vty_out(vty, " redistribute %s",
16912 zebra_route_string(i));
16913 if (red->instance)
16914 vty_out(vty, " %d", red->instance);
16915 if (red->redist_metric_flag)
16916 vty_out(vty, " metric %u",
16917 red->redist_metric);
16918 if (red->rmap.name)
16919 vty_out(vty, " route-map %s",
16920 red->rmap.name);
16921 vty_out(vty, "\n");
16922 }
16923 }
16924 }
16925 }
16926
16927 /* peer-group helpers for config-write */
16928
16929 static bool peergroup_flag_check(struct peer *peer, uint32_t flag)
16930 {
16931 if (!peer_group_active(peer)) {
16932 if (CHECK_FLAG(peer->flags_invert, flag))
16933 return !CHECK_FLAG(peer->flags, flag);
16934 else
16935 return !!CHECK_FLAG(peer->flags, flag);
16936 }
16937
16938 return !!CHECK_FLAG(peer->flags_override, flag);
16939 }
16940
16941 static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
16942 uint32_t flag)
16943 {
16944 if (!peer_group_active(peer)) {
16945 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
16946 return !peer_af_flag_check(peer, afi, safi, flag);
16947 else
16948 return !!peer_af_flag_check(peer, afi, safi, flag);
16949 }
16950
16951 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
16952 }
16953
16954 static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
16955 uint8_t type, int direct)
16956 {
16957 struct bgp_filter *filter;
16958
16959 if (peer_group_active(peer))
16960 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
16961 type);
16962
16963 filter = &peer->filter[afi][safi];
16964 switch (type) {
16965 case PEER_FT_DISTRIBUTE_LIST:
16966 return !!(filter->dlist[direct].name);
16967 case PEER_FT_FILTER_LIST:
16968 return !!(filter->aslist[direct].name);
16969 case PEER_FT_PREFIX_LIST:
16970 return !!(filter->plist[direct].name);
16971 case PEER_FT_ROUTE_MAP:
16972 return !!(filter->map[direct].name);
16973 case PEER_FT_UNSUPPRESS_MAP:
16974 return !!(filter->usmap.name);
16975 case PEER_FT_ADVERTISE_MAP:
16976 return !!(filter->advmap.aname
16977 && ((filter->advmap.condition == direct)
16978 && filter->advmap.cname));
16979 default:
16980 return false;
16981 }
16982 }
16983
16984 /* Return true if the addpath type is set for peer and different from
16985 * peer-group.
16986 */
16987 static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi,
16988 safi_t safi)
16989 {
16990 enum bgp_addpath_strat type, g_type;
16991
16992 type = peer->addpath_type[afi][safi];
16993
16994 if (type != BGP_ADDPATH_NONE) {
16995 if (peer_group_active(peer)) {
16996 g_type = peer->group->conf->addpath_type[afi][safi];
16997
16998 if (type != g_type)
16999 return true;
17000 else
17001 return false;
17002 }
17003
17004 return true;
17005 }
17006
17007 return false;
17008 }
17009
17010 /* This is part of the address-family block (unicast only) */
17011 static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
17012 afi_t afi)
17013 {
17014 int indent = 2;
17015
17016 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
17017 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
17018 BGP_CONFIG_VRF_TO_VRF_IMPORT))
17019 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
17020 bgp->vpn_policy[afi]
17021 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
17022 else
17023 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
17024 bgp->vpn_policy[afi]
17025 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
17026 }
17027 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
17028 BGP_CONFIG_VRF_TO_VRF_IMPORT)
17029 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
17030 BGP_CONFIG_VRF_TO_VRF_EXPORT))
17031 return;
17032
17033 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
17034 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
17035
17036 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
17037
17038 } else {
17039 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
17040 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
17041 bgp->vpn_policy[afi].tovpn_label);
17042 }
17043 }
17044 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
17045 BGP_VPN_POLICY_TOVPN_RD_SET)) {
17046 char buf[RD_ADDRSTRLEN];
17047 vty_out(vty, "%*srd vpn export %s\n", indent, "",
17048 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
17049 sizeof(buf)));
17050 }
17051 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
17052 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
17053
17054 char buf[PREFIX_STRLEN];
17055 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
17056 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
17057 sizeof(buf))) {
17058
17059 vty_out(vty, "%*snexthop vpn export %s\n",
17060 indent, "", buf);
17061 }
17062 }
17063 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
17064 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
17065 && ecommunity_cmp(
17066 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
17067 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
17068
17069 char *b = ecommunity_ecom2str(
17070 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
17071 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
17072 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
17073 XFREE(MTYPE_ECOMMUNITY_STR, b);
17074 } else {
17075 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
17076 char *b = ecommunity_ecom2str(
17077 bgp->vpn_policy[afi]
17078 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
17079 ECOMMUNITY_FORMAT_ROUTE_MAP,
17080 ECOMMUNITY_ROUTE_TARGET);
17081 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
17082 XFREE(MTYPE_ECOMMUNITY_STR, b);
17083 }
17084 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
17085 char *b = ecommunity_ecom2str(
17086 bgp->vpn_policy[afi]
17087 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
17088 ECOMMUNITY_FORMAT_ROUTE_MAP,
17089 ECOMMUNITY_ROUTE_TARGET);
17090 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
17091 XFREE(MTYPE_ECOMMUNITY_STR, b);
17092 }
17093 }
17094
17095 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
17096 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
17097 bgp->vpn_policy[afi]
17098 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
17099
17100 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
17101 char *b = ecommunity_ecom2str(
17102 bgp->vpn_policy[afi]
17103 .import_redirect_rtlist,
17104 ECOMMUNITY_FORMAT_ROUTE_MAP,
17105 ECOMMUNITY_ROUTE_TARGET);
17106
17107 if (bgp->vpn_policy[afi].import_redirect_rtlist->unit_size
17108 != ECOMMUNITY_SIZE)
17109 vty_out(vty, "%*srt6 redirect import %s\n",
17110 indent, "", b);
17111 else
17112 vty_out(vty, "%*srt redirect import %s\n",
17113 indent, "", b);
17114 XFREE(MTYPE_ECOMMUNITY_STR, b);
17115 }
17116 }
17117
17118 static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
17119 afi_t afi, safi_t safi)
17120 {
17121 struct bgp_filter *filter;
17122 char *addr;
17123
17124 addr = peer->host;
17125 filter = &peer->filter[afi][safi];
17126
17127 /* distribute-list. */
17128 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
17129 FILTER_IN))
17130 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
17131 filter->dlist[FILTER_IN].name);
17132
17133 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
17134 FILTER_OUT))
17135 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
17136 filter->dlist[FILTER_OUT].name);
17137
17138 /* prefix-list. */
17139 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
17140 FILTER_IN))
17141 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
17142 filter->plist[FILTER_IN].name);
17143
17144 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
17145 FILTER_OUT))
17146 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
17147 filter->plist[FILTER_OUT].name);
17148
17149 /* route-map. */
17150 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
17151 vty_out(vty, " neighbor %s route-map %s in\n", addr,
17152 filter->map[RMAP_IN].name);
17153
17154 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
17155 RMAP_OUT))
17156 vty_out(vty, " neighbor %s route-map %s out\n", addr,
17157 filter->map[RMAP_OUT].name);
17158
17159 /* unsuppress-map */
17160 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
17161 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
17162 filter->usmap.name);
17163
17164 /* advertise-map : always applied in OUT direction*/
17165 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
17166 CONDITION_NON_EXIST))
17167 vty_out(vty,
17168 " neighbor %s advertise-map %s non-exist-map %s\n",
17169 addr, filter->advmap.aname, filter->advmap.cname);
17170
17171 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
17172 CONDITION_EXIST))
17173 vty_out(vty, " neighbor %s advertise-map %s exist-map %s\n",
17174 addr, filter->advmap.aname, filter->advmap.cname);
17175
17176 /* filter-list. */
17177 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
17178 FILTER_IN))
17179 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
17180 filter->aslist[FILTER_IN].name);
17181
17182 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
17183 FILTER_OUT))
17184 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
17185 filter->aslist[FILTER_OUT].name);
17186 }
17187
17188 /* BGP peer configuration display function. */
17189 static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
17190 struct peer *peer)
17191 {
17192 struct peer *g_peer = NULL;
17193 char buf[SU_ADDRSTRLEN];
17194 char *addr;
17195 int if_pg_printed = false;
17196 int if_ras_printed = false;
17197
17198 /* Skip dynamic neighbors. */
17199 if (peer_dynamic_neighbor(peer))
17200 return;
17201
17202 if (peer->conf_if)
17203 addr = peer->conf_if;
17204 else
17205 addr = peer->host;
17206
17207 /************************************
17208 ****** Global to the neighbor ******
17209 ************************************/
17210 if (peer->conf_if) {
17211 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
17212 vty_out(vty, " neighbor %s interface v6only", addr);
17213 else
17214 vty_out(vty, " neighbor %s interface", addr);
17215
17216 if (peer_group_active(peer)) {
17217 vty_out(vty, " peer-group %s", peer->group->name);
17218 if_pg_printed = true;
17219 } else if (peer->as_type == AS_SPECIFIED) {
17220 vty_out(vty, " remote-as %u", peer->as);
17221 if_ras_printed = true;
17222 } else if (peer->as_type == AS_INTERNAL) {
17223 vty_out(vty, " remote-as internal");
17224 if_ras_printed = true;
17225 } else if (peer->as_type == AS_EXTERNAL) {
17226 vty_out(vty, " remote-as external");
17227 if_ras_printed = true;
17228 }
17229
17230 vty_out(vty, "\n");
17231 }
17232
17233 /* remote-as and peer-group */
17234 /* peer is a member of a peer-group */
17235 if (peer_group_active(peer)) {
17236 g_peer = peer->group->conf;
17237
17238 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
17239 if (peer->as_type == AS_SPECIFIED) {
17240 vty_out(vty, " neighbor %s remote-as %u\n",
17241 addr, peer->as);
17242 } else if (peer->as_type == AS_INTERNAL) {
17243 vty_out(vty,
17244 " neighbor %s remote-as internal\n",
17245 addr);
17246 } else if (peer->as_type == AS_EXTERNAL) {
17247 vty_out(vty,
17248 " neighbor %s remote-as external\n",
17249 addr);
17250 }
17251 }
17252
17253 /* For swpX peers we displayed the peer-group
17254 * via 'neighbor swpX interface peer-group PGNAME' */
17255 if (!if_pg_printed)
17256 vty_out(vty, " neighbor %s peer-group %s\n", addr,
17257 peer->group->name);
17258 }
17259
17260 /* peer is NOT a member of a peer-group */
17261 else {
17262 /* peer is a peer-group, declare the peer-group */
17263 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
17264 vty_out(vty, " neighbor %s peer-group\n", addr);
17265 }
17266
17267 if (!if_ras_printed) {
17268 if (peer->as_type == AS_SPECIFIED) {
17269 vty_out(vty, " neighbor %s remote-as %u\n",
17270 addr, peer->as);
17271 } else if (peer->as_type == AS_INTERNAL) {
17272 vty_out(vty,
17273 " neighbor %s remote-as internal\n",
17274 addr);
17275 } else if (peer->as_type == AS_EXTERNAL) {
17276 vty_out(vty,
17277 " neighbor %s remote-as external\n",
17278 addr);
17279 }
17280 }
17281 }
17282
17283 /* local-as */
17284 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
17285 vty_out(vty, " neighbor %s local-as %u", addr,
17286 peer->change_local_as);
17287 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
17288 vty_out(vty, " no-prepend");
17289 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
17290 vty_out(vty, " replace-as");
17291 vty_out(vty, "\n");
17292 }
17293
17294 /* description */
17295 if (peer->desc) {
17296 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
17297 }
17298
17299 /* shutdown */
17300 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
17301 if (peer->tx_shutdown_message)
17302 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
17303 peer->tx_shutdown_message);
17304 else
17305 vty_out(vty, " neighbor %s shutdown\n", addr);
17306 }
17307
17308 if (peergroup_flag_check(peer, PEER_FLAG_RTT_SHUTDOWN))
17309 vty_out(vty, " neighbor %s shutdown rtt %u count %u\n", addr,
17310 peer->rtt_expected, peer->rtt_keepalive_conf);
17311
17312 /* bfd */
17313 if (peer->bfd_config)
17314 bgp_bfd_peer_config_write(vty, peer, addr);
17315
17316 /* password */
17317 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
17318 vty_out(vty, " neighbor %s password %s\n", addr,
17319 peer->password);
17320
17321 /* neighbor solo */
17322 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
17323 if (!peer_group_active(peer)) {
17324 vty_out(vty, " neighbor %s solo\n", addr);
17325 }
17326 }
17327
17328 /* BGP port */
17329 if (peer->port != BGP_PORT_DEFAULT) {
17330 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
17331 }
17332
17333 /* Local interface name */
17334 if (peer->ifname) {
17335 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
17336 }
17337
17338 /* TCP max segment size */
17339 if (CHECK_FLAG(peer->flags, PEER_FLAG_TCP_MSS))
17340 vty_out(vty, " neighbor %s tcp-mss %d\n", addr, peer->tcp_mss);
17341
17342 /* passive */
17343 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
17344 vty_out(vty, " neighbor %s passive\n", addr);
17345
17346 /* ebgp-multihop */
17347 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
17348 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
17349 && peer->ttl == MAXTTL)) {
17350 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
17351 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
17352 peer->ttl);
17353 }
17354 }
17355
17356 /* ttl-security hops */
17357 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
17358 if (!peer_group_active(peer)
17359 || g_peer->gtsm_hops != peer->gtsm_hops) {
17360 vty_out(vty, " neighbor %s ttl-security hops %d\n",
17361 addr, peer->gtsm_hops);
17362 }
17363 }
17364
17365 /* disable-connected-check */
17366 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
17367 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
17368
17369 /* enforce-first-as */
17370 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
17371 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
17372
17373 /* update-source */
17374 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
17375 if (peer->update_source)
17376 vty_out(vty, " neighbor %s update-source %s\n", addr,
17377 sockunion2str(peer->update_source, buf,
17378 SU_ADDRSTRLEN));
17379 else if (peer->update_if)
17380 vty_out(vty, " neighbor %s update-source %s\n", addr,
17381 peer->update_if);
17382 }
17383
17384 /* advertisement-interval */
17385 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
17386 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
17387 peer->routeadv);
17388
17389 /* timers */
17390 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
17391 vty_out(vty, " neighbor %s timers %u %u\n", addr,
17392 peer->keepalive, peer->holdtime);
17393
17394 /* timers connect */
17395 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
17396 vty_out(vty, " neighbor %s timers connect %u\n", addr,
17397 peer->connect);
17398 /* need special-case handling for changed default values due to
17399 * config profile / version (because there is no "timers bgp connect"
17400 * command, we need to save this per-peer :/)
17401 */
17402 else if (!peer_group_active(peer) && !peer->connect &&
17403 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
17404 vty_out(vty, " neighbor %s timers connect %u\n", addr,
17405 peer->bgp->default_connect_retry);
17406
17407 /* timers delayopen */
17408 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_DELAYOPEN))
17409 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
17410 peer->delayopen);
17411 /* Save config even though flag is not set if default values have been
17412 * changed
17413 */
17414 else if (!peer_group_active(peer) && !peer->delayopen
17415 && peer->bgp->default_delayopen != BGP_DEFAULT_DELAYOPEN)
17416 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
17417 peer->bgp->default_delayopen);
17418
17419 /* capability dynamic */
17420 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
17421 vty_out(vty, " neighbor %s capability dynamic\n", addr);
17422
17423 /* capability extended-nexthop */
17424 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
17425 if (!peer->conf_if) {
17426 if (CHECK_FLAG(peer->flags_invert,
17427 PEER_FLAG_CAPABILITY_ENHE))
17428 vty_out(vty,
17429 " no neighbor %s capability extended-nexthop\n",
17430 addr);
17431 else
17432 vty_out(vty,
17433 " neighbor %s capability extended-nexthop\n",
17434 addr);
17435 }
17436 }
17437
17438 /* dont-capability-negotiation */
17439 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
17440 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
17441
17442 /* override-capability */
17443 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
17444 vty_out(vty, " neighbor %s override-capability\n", addr);
17445
17446 /* strict-capability-match */
17447 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
17448 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
17449
17450 /* Sender side AS path loop detection. */
17451 if (peer->as_path_loop_detection)
17452 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
17453 addr);
17454
17455 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
17456 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
17457
17458 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
17459 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
17460 vty_out(vty,
17461 " neighbor %s graceful-restart-helper\n", addr);
17462 } else if (CHECK_FLAG(
17463 peer->peer_gr_new_status_flag,
17464 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
17465 vty_out(vty,
17466 " neighbor %s graceful-restart\n", addr);
17467 } else if (
17468 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
17469 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
17470 && !(CHECK_FLAG(
17471 peer->peer_gr_new_status_flag,
17472 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
17473 vty_out(vty, " neighbor %s graceful-restart-disable\n",
17474 addr);
17475 }
17476 }
17477 }
17478
17479 /* BGP peer configuration display function. */
17480 static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
17481 struct peer *peer, afi_t afi, safi_t safi)
17482 {
17483 struct peer *g_peer = NULL;
17484 char *addr;
17485 bool flag_scomm, flag_secomm, flag_slcomm;
17486
17487 /* Skip dynamic neighbors. */
17488 if (peer_dynamic_neighbor(peer))
17489 return;
17490
17491 if (peer->conf_if)
17492 addr = peer->conf_if;
17493 else
17494 addr = peer->host;
17495
17496 /************************************
17497 ****** Per AF to the neighbor ******
17498 ************************************/
17499 if (peer_group_active(peer)) {
17500 g_peer = peer->group->conf;
17501
17502 /* If the peer-group is active but peer is not, print a 'no
17503 * activate' */
17504 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
17505 vty_out(vty, " no neighbor %s activate\n", addr);
17506 }
17507
17508 /* If the peer-group is not active but peer is, print an
17509 'activate' */
17510 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
17511 vty_out(vty, " neighbor %s activate\n", addr);
17512 }
17513 } else {
17514 if (peer->afc[afi][safi]) {
17515 if (safi == SAFI_ENCAP)
17516 vty_out(vty, " neighbor %s activate\n", addr);
17517 else if (!bgp->default_af[afi][safi])
17518 vty_out(vty, " neighbor %s activate\n", addr);
17519 } else {
17520 if (bgp->default_af[afi][safi])
17521 vty_out(vty, " no neighbor %s activate\n",
17522 addr);
17523 }
17524 }
17525
17526 /* addpath TX knobs */
17527 if (peergroup_af_addpath_check(peer, afi, safi)) {
17528 switch (peer->addpath_type[afi][safi]) {
17529 case BGP_ADDPATH_ALL:
17530 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
17531 addr);
17532 break;
17533 case BGP_ADDPATH_BEST_PER_AS:
17534 vty_out(vty,
17535 " neighbor %s addpath-tx-bestpath-per-AS\n",
17536 addr);
17537 break;
17538 case BGP_ADDPATH_MAX:
17539 case BGP_ADDPATH_NONE:
17540 break;
17541 }
17542 }
17543
17544 /* ORF capability. */
17545 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
17546 || peergroup_af_flag_check(peer, afi, safi,
17547 PEER_FLAG_ORF_PREFIX_RM)) {
17548 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
17549
17550 if (peergroup_af_flag_check(peer, afi, safi,
17551 PEER_FLAG_ORF_PREFIX_SM)
17552 && peergroup_af_flag_check(peer, afi, safi,
17553 PEER_FLAG_ORF_PREFIX_RM))
17554 vty_out(vty, " both");
17555 else if (peergroup_af_flag_check(peer, afi, safi,
17556 PEER_FLAG_ORF_PREFIX_SM))
17557 vty_out(vty, " send");
17558 else
17559 vty_out(vty, " receive");
17560 vty_out(vty, "\n");
17561 }
17562
17563 /* Route reflector client. */
17564 if (peergroup_af_flag_check(peer, afi, safi,
17565 PEER_FLAG_REFLECTOR_CLIENT)) {
17566 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
17567 }
17568
17569 /* next-hop-self force */
17570 if (peergroup_af_flag_check(peer, afi, safi,
17571 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
17572 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
17573 }
17574
17575 /* next-hop-self */
17576 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
17577 vty_out(vty, " neighbor %s next-hop-self\n", addr);
17578 }
17579
17580 /* remove-private-AS */
17581 if (peergroup_af_flag_check(peer, afi, safi,
17582 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
17583 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
17584 addr);
17585 }
17586
17587 else if (peergroup_af_flag_check(peer, afi, safi,
17588 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
17589 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
17590 addr);
17591 }
17592
17593 else if (peergroup_af_flag_check(peer, afi, safi,
17594 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
17595 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
17596 }
17597
17598 else if (peergroup_af_flag_check(peer, afi, safi,
17599 PEER_FLAG_REMOVE_PRIVATE_AS)) {
17600 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
17601 }
17602
17603 /* as-override */
17604 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
17605 vty_out(vty, " neighbor %s as-override\n", addr);
17606 }
17607
17608 /* send-community print. */
17609 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
17610 PEER_FLAG_SEND_COMMUNITY);
17611 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
17612 PEER_FLAG_SEND_EXT_COMMUNITY);
17613 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
17614 PEER_FLAG_SEND_LARGE_COMMUNITY);
17615
17616 if (flag_scomm && flag_secomm && flag_slcomm) {
17617 vty_out(vty, " no neighbor %s send-community all\n", addr);
17618 } else {
17619 if (flag_scomm)
17620 vty_out(vty, " no neighbor %s send-community\n", addr);
17621 if (flag_secomm)
17622 vty_out(vty,
17623 " no neighbor %s send-community extended\n",
17624 addr);
17625
17626 if (flag_slcomm)
17627 vty_out(vty, " no neighbor %s send-community large\n",
17628 addr);
17629 }
17630
17631 /* Default information */
17632 if (peergroup_af_flag_check(peer, afi, safi,
17633 PEER_FLAG_DEFAULT_ORIGINATE)) {
17634 vty_out(vty, " neighbor %s default-originate", addr);
17635
17636 if (peer->default_rmap[afi][safi].name)
17637 vty_out(vty, " route-map %s",
17638 peer->default_rmap[afi][safi].name);
17639
17640 vty_out(vty, "\n");
17641 }
17642
17643 /* Soft reconfiguration inbound. */
17644 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
17645 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
17646 addr);
17647 }
17648
17649 /* maximum-prefix. */
17650 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
17651 vty_out(vty, " neighbor %s maximum-prefix %u", addr,
17652 peer->pmax[afi][safi]);
17653
17654 if (peer->pmax_threshold[afi][safi]
17655 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
17656 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
17657 if (peer_af_flag_check(peer, afi, safi,
17658 PEER_FLAG_MAX_PREFIX_WARNING))
17659 vty_out(vty, " warning-only");
17660 if (peer->pmax_restart[afi][safi])
17661 vty_out(vty, " restart %u",
17662 peer->pmax_restart[afi][safi]);
17663 if (peer_af_flag_check(peer, afi, safi,
17664 PEER_FLAG_MAX_PREFIX_FORCE))
17665 vty_out(vty, " force");
17666
17667 vty_out(vty, "\n");
17668 }
17669
17670 /* maximum-prefix-out */
17671 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
17672 vty_out(vty, " neighbor %s maximum-prefix-out %u\n",
17673 addr, peer->pmax_out[afi][safi]);
17674
17675 /* Route server client. */
17676 if (peergroup_af_flag_check(peer, afi, safi,
17677 PEER_FLAG_RSERVER_CLIENT)) {
17678 vty_out(vty, " neighbor %s route-server-client\n", addr);
17679 }
17680
17681 /* Nexthop-local unchanged. */
17682 if (peergroup_af_flag_check(peer, afi, safi,
17683 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
17684 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
17685 }
17686
17687 /* allowas-in <1-10> */
17688 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
17689 if (peer_af_flag_check(peer, afi, safi,
17690 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
17691 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
17692 } else if (peer->allowas_in[afi][safi] == 3) {
17693 vty_out(vty, " neighbor %s allowas-in\n", addr);
17694 } else {
17695 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
17696 peer->allowas_in[afi][safi]);
17697 }
17698 }
17699
17700 /* weight */
17701 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
17702 vty_out(vty, " neighbor %s weight %lu\n", addr,
17703 peer->weight[afi][safi]);
17704
17705 /* Filter. */
17706 bgp_config_write_filter(vty, peer, afi, safi);
17707
17708 /* atribute-unchanged. */
17709 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
17710 || (safi != SAFI_EVPN
17711 && peer_af_flag_check(peer, afi, safi,
17712 PEER_FLAG_NEXTHOP_UNCHANGED))
17713 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
17714
17715 if (!peer_group_active(peer)
17716 || peergroup_af_flag_check(peer, afi, safi,
17717 PEER_FLAG_AS_PATH_UNCHANGED)
17718 || peergroup_af_flag_check(peer, afi, safi,
17719 PEER_FLAG_NEXTHOP_UNCHANGED)
17720 || peergroup_af_flag_check(peer, afi, safi,
17721 PEER_FLAG_MED_UNCHANGED)) {
17722
17723 vty_out(vty,
17724 " neighbor %s attribute-unchanged%s%s%s\n",
17725 addr,
17726 peer_af_flag_check(peer, afi, safi,
17727 PEER_FLAG_AS_PATH_UNCHANGED)
17728 ? " as-path"
17729 : "",
17730 peer_af_flag_check(peer, afi, safi,
17731 PEER_FLAG_NEXTHOP_UNCHANGED)
17732 ? " next-hop"
17733 : "",
17734 peer_af_flag_check(peer, afi, safi,
17735 PEER_FLAG_MED_UNCHANGED)
17736 ? " med"
17737 : "");
17738 }
17739 }
17740
17741 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_CONFIG_DAMPENING))
17742 bgp_config_write_peer_damp(vty, peer, afi, safi);
17743 }
17744
17745 /* Address family based peer configuration display. */
17746 static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
17747 safi_t safi)
17748 {
17749 struct peer *peer;
17750 struct peer_group *group;
17751 struct listnode *node, *nnode;
17752
17753
17754 vty_frame(vty, " !\n address-family ");
17755 if (afi == AFI_IP) {
17756 if (safi == SAFI_UNICAST)
17757 vty_frame(vty, "ipv4 unicast");
17758 else if (safi == SAFI_LABELED_UNICAST)
17759 vty_frame(vty, "ipv4 labeled-unicast");
17760 else if (safi == SAFI_MULTICAST)
17761 vty_frame(vty, "ipv4 multicast");
17762 else if (safi == SAFI_MPLS_VPN)
17763 vty_frame(vty, "ipv4 vpn");
17764 else if (safi == SAFI_ENCAP)
17765 vty_frame(vty, "ipv4 encap");
17766 else if (safi == SAFI_FLOWSPEC)
17767 vty_frame(vty, "ipv4 flowspec");
17768 } else if (afi == AFI_IP6) {
17769 if (safi == SAFI_UNICAST)
17770 vty_frame(vty, "ipv6 unicast");
17771 else if (safi == SAFI_LABELED_UNICAST)
17772 vty_frame(vty, "ipv6 labeled-unicast");
17773 else if (safi == SAFI_MULTICAST)
17774 vty_frame(vty, "ipv6 multicast");
17775 else if (safi == SAFI_MPLS_VPN)
17776 vty_frame(vty, "ipv6 vpn");
17777 else if (safi == SAFI_ENCAP)
17778 vty_frame(vty, "ipv6 encap");
17779 else if (safi == SAFI_FLOWSPEC)
17780 vty_frame(vty, "ipv6 flowspec");
17781 } else if (afi == AFI_L2VPN) {
17782 if (safi == SAFI_EVPN)
17783 vty_frame(vty, "l2vpn evpn");
17784 }
17785 vty_frame(vty, "\n");
17786
17787 bgp_config_write_distance(vty, bgp, afi, safi);
17788
17789 bgp_config_write_network(vty, bgp, afi, safi);
17790
17791 bgp_config_write_redistribute(vty, bgp, afi, safi);
17792
17793 /* BGP flag dampening. */
17794 if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
17795 bgp_config_write_damp(vty, bgp, afi, safi);
17796
17797 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
17798 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
17799
17800 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17801 /* Do not display doppelganger peers */
17802 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17803 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
17804 }
17805
17806 bgp_config_write_maxpaths(vty, bgp, afi, safi);
17807 bgp_config_write_table_map(vty, bgp, afi, safi);
17808
17809 if (safi == SAFI_EVPN)
17810 bgp_config_write_evpn_info(vty, bgp, afi, safi);
17811
17812 if (safi == SAFI_FLOWSPEC)
17813 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
17814
17815 if (safi == SAFI_UNICAST) {
17816 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
17817 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17818 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
17819
17820 vty_out(vty, " export vpn\n");
17821 }
17822 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17823 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
17824
17825 vty_out(vty, " import vpn\n");
17826 }
17827 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17828 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
17829 char *name;
17830
17831 for (ALL_LIST_ELEMENTS_RO(
17832 bgp->vpn_policy[afi].import_vrf, node,
17833 name))
17834 vty_out(vty, " import vrf %s\n", name);
17835 }
17836 }
17837
17838 vty_endframe(vty, " exit-address-family\n");
17839 }
17840
17841 int bgp_config_write(struct vty *vty)
17842 {
17843 struct bgp *bgp;
17844 struct peer_group *group;
17845 struct peer *peer;
17846 struct listnode *node, *nnode;
17847 struct listnode *mnode, *mnnode;
17848 afi_t afi;
17849 safi_t safi;
17850
17851 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
17852 vty_out(vty, "bgp route-map delay-timer %u\n",
17853 bm->rmap_update_timer);
17854
17855 if (bm->v_update_delay != BGP_UPDATE_DELAY_DEF) {
17856 vty_out(vty, "bgp update-delay %d", bm->v_update_delay);
17857 if (bm->v_update_delay != bm->v_establish_wait)
17858 vty_out(vty, " %d", bm->v_establish_wait);
17859 vty_out(vty, "\n");
17860 }
17861
17862 if (bm->wait_for_fib)
17863 vty_out(vty, "bgp suppress-fib-pending\n");
17864
17865 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17866 vty_out(vty, "bgp graceful-shutdown\n");
17867
17868 /* No-RIB (Zebra) option flag configuration */
17869 if (bgp_option_check(BGP_OPT_NO_FIB))
17870 vty_out(vty, "bgp no-rib\n");
17871
17872 if (!CHECK_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA))
17873 vty_out(vty, "no bgp send-extra-data zebra\n");
17874
17875 /* BGP configuration. */
17876 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
17877
17878 /* skip all auto created vrf as they dont have user config */
17879 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
17880 continue;
17881
17882 /* Router bgp ASN */
17883 vty_out(vty, "router bgp %u", bgp->as);
17884
17885 if (bgp->name)
17886 vty_out(vty, " %s %s",
17887 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
17888 ? "view" : "vrf", bgp->name);
17889 vty_out(vty, "\n");
17890
17891 /* BGP fast-external-failover. */
17892 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
17893 vty_out(vty, " no bgp fast-external-failover\n");
17894
17895 /* BGP router ID. */
17896 if (bgp->router_id_static.s_addr != INADDR_ANY)
17897 vty_out(vty, " bgp router-id %pI4\n",
17898 &bgp->router_id_static);
17899
17900 /* Suppress fib pending */
17901 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_FIB_PENDING))
17902 vty_out(vty, " bgp suppress-fib-pending\n");
17903
17904 /* BGP log-neighbor-changes. */
17905 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
17906 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
17907 vty_out(vty, " %sbgp log-neighbor-changes\n",
17908 CHECK_FLAG(bgp->flags,
17909 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
17910 ? ""
17911 : "no ");
17912
17913 /* BGP configuration. */
17914 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
17915 vty_out(vty, " bgp always-compare-med\n");
17916
17917 /* RFC8212 default eBGP policy. */
17918 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
17919 != SAVE_BGP_EBGP_REQUIRES_POLICY)
17920 vty_out(vty, " %sbgp ebgp-requires-policy\n",
17921 CHECK_FLAG(bgp->flags,
17922 BGP_FLAG_EBGP_REQUIRES_POLICY)
17923 ? ""
17924 : "no ");
17925
17926 /* draft-ietf-idr-deprecate-as-set-confed-set */
17927 if (bgp->reject_as_sets)
17928 vty_out(vty, " bgp reject-as-sets\n");
17929
17930 /* Suppress duplicate updates if the route actually not changed
17931 */
17932 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES)
17933 != SAVE_BGP_SUPPRESS_DUPLICATES)
17934 vty_out(vty, " %sbgp suppress-duplicates\n",
17935 CHECK_FLAG(bgp->flags,
17936 BGP_FLAG_SUPPRESS_DUPLICATES)
17937 ? ""
17938 : "no ");
17939
17940 /* BGP default <afi>-<safi> */
17941 FOREACH_AFI_SAFI (afi, safi) {
17942 if (afi == AFI_IP && safi == SAFI_UNICAST) {
17943 if (!bgp->default_af[afi][safi])
17944 vty_out(vty, " no bgp default %s\n",
17945 get_bgp_default_af_flag(afi,
17946 safi));
17947 } else if (bgp->default_af[afi][safi])
17948 vty_out(vty, " bgp default %s\n",
17949 get_bgp_default_af_flag(afi, safi));
17950 }
17951
17952 /* BGP default local-preference. */
17953 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
17954 vty_out(vty, " bgp default local-preference %u\n",
17955 bgp->default_local_pref);
17956
17957 /* BGP default show-hostname */
17958 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
17959 != SAVE_BGP_SHOW_HOSTNAME)
17960 vty_out(vty, " %sbgp default show-hostname\n",
17961 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
17962 ? ""
17963 : "no ");
17964
17965 /* BGP default show-nexthop-hostname */
17966 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17967 != SAVE_BGP_SHOW_HOSTNAME)
17968 vty_out(vty, " %sbgp default show-nexthop-hostname\n",
17969 CHECK_FLAG(bgp->flags,
17970 BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17971 ? ""
17972 : "no ");
17973
17974 /* BGP default subgroup-pkt-queue-max. */
17975 if (bgp->default_subgroup_pkt_queue_max
17976 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
17977 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
17978 bgp->default_subgroup_pkt_queue_max);
17979
17980 /* BGP client-to-client reflection. */
17981 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
17982 vty_out(vty, " no bgp client-to-client reflection\n");
17983
17984 /* BGP cluster ID. */
17985 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
17986 vty_out(vty, " bgp cluster-id %pI4\n",
17987 &bgp->cluster_id);
17988
17989 /* Disable ebgp connected nexthop check */
17990 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
17991 vty_out(vty,
17992 " bgp disable-ebgp-connected-route-check\n");
17993
17994 /* Confederation identifier*/
17995 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
17996 vty_out(vty, " bgp confederation identifier %u\n",
17997 bgp->confed_id);
17998
17999 /* Confederation peer */
18000 if (bgp->confed_peers_cnt > 0) {
18001 int i;
18002
18003 vty_out(vty, " bgp confederation peers");
18004
18005 for (i = 0; i < bgp->confed_peers_cnt; i++)
18006 vty_out(vty, " %u", bgp->confed_peers[i]);
18007
18008 vty_out(vty, "\n");
18009 }
18010
18011 /* BGP deterministic-med. */
18012 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
18013 != SAVE_BGP_DETERMINISTIC_MED)
18014 vty_out(vty, " %sbgp deterministic-med\n",
18015 CHECK_FLAG(bgp->flags,
18016 BGP_FLAG_DETERMINISTIC_MED)
18017 ? ""
18018 : "no ");
18019
18020 /* BGP update-delay. */
18021 bgp_config_write_update_delay(vty, bgp);
18022
18023 if (bgp->v_maxmed_onstartup
18024 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
18025 vty_out(vty, " bgp max-med on-startup %u",
18026 bgp->v_maxmed_onstartup);
18027 if (bgp->maxmed_onstartup_value
18028 != BGP_MAXMED_VALUE_DEFAULT)
18029 vty_out(vty, " %u",
18030 bgp->maxmed_onstartup_value);
18031 vty_out(vty, "\n");
18032 }
18033 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
18034 vty_out(vty, " bgp max-med administrative");
18035 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
18036 vty_out(vty, " %u", bgp->maxmed_admin_value);
18037 vty_out(vty, "\n");
18038 }
18039
18040 /* write quanta */
18041 bgp_config_write_wpkt_quanta(vty, bgp);
18042 /* read quanta */
18043 bgp_config_write_rpkt_quanta(vty, bgp);
18044
18045 /* coalesce time */
18046 bgp_config_write_coalesce_time(vty, bgp);
18047
18048 /* BGP per-instance graceful-shutdown */
18049 /* BGP-wide settings and per-instance settings are mutually
18050 * exclusive.
18051 */
18052 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
18053 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
18054 vty_out(vty, " bgp graceful-shutdown\n");
18055
18056 /* BGP graceful-restart. */
18057 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
18058 vty_out(vty,
18059 " bgp graceful-restart stalepath-time %u\n",
18060 bgp->stalepath_time);
18061
18062 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
18063 vty_out(vty, " bgp graceful-restart restart-time %u\n",
18064 bgp->restart_time);
18065
18066 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
18067 vty_out(vty,
18068 " bgp graceful-restart select-defer-time %u\n",
18069 bgp->select_defer_time);
18070
18071 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
18072 vty_out(vty, " bgp graceful-restart\n");
18073
18074 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
18075 vty_out(vty, " bgp graceful-restart-disable\n");
18076
18077 /* BGP graceful-restart Preserve State F bit. */
18078 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
18079 vty_out(vty,
18080 " bgp graceful-restart preserve-fw-state\n");
18081
18082 /* Stale timer for RIB */
18083 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
18084 vty_out(vty,
18085 " bgp graceful-restart rib-stale-time %u\n",
18086 bgp->rib_stale_time);
18087
18088 /* BGP bestpath method. */
18089 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
18090 vty_out(vty, " bgp bestpath as-path ignore\n");
18091 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
18092 vty_out(vty, " bgp bestpath as-path confed\n");
18093
18094 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
18095 if (CHECK_FLAG(bgp->flags,
18096 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
18097 vty_out(vty,
18098 " bgp bestpath as-path multipath-relax as-set\n");
18099 } else {
18100 vty_out(vty,
18101 " bgp bestpath as-path multipath-relax\n");
18102 }
18103 }
18104
18105 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
18106 vty_out(vty,
18107 " bgp route-reflector allow-outbound-policy\n");
18108 }
18109 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
18110 vty_out(vty, " bgp bestpath compare-routerid\n");
18111 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
18112 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
18113 vty_out(vty, " bgp bestpath med");
18114 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
18115 vty_out(vty, " confed");
18116 if (CHECK_FLAG(bgp->flags,
18117 BGP_FLAG_MED_MISSING_AS_WORST))
18118 vty_out(vty, " missing-as-worst");
18119 vty_out(vty, "\n");
18120 }
18121
18122 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
18123 vty_out(vty,
18124 " bgp bestpath peer-type multipath-relax\n");
18125
18126 /* Link bandwidth handling. */
18127 if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW)
18128 vty_out(vty, " bgp bestpath bandwidth ignore\n");
18129 else if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
18130 vty_out(vty, " bgp bestpath bandwidth skip-missing\n");
18131 else if (bgp->lb_handling == BGP_LINK_BW_DEFWT_4_MISSING)
18132 vty_out(vty, " bgp bestpath bandwidth default-weight-for-missing\n");
18133
18134 /* BGP network import check. */
18135 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
18136 != SAVE_BGP_IMPORT_CHECK)
18137 vty_out(vty, " %sbgp network import-check\n",
18138 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
18139 ? ""
18140 : "no ");
18141
18142 /* BGP timers configuration. */
18143 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
18144 || bgp->default_holdtime != SAVE_BGP_HOLDTIME)
18145 vty_out(vty, " timers bgp %u %u\n",
18146 bgp->default_keepalive, bgp->default_holdtime);
18147
18148 /* peer-group */
18149 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
18150 bgp_config_write_peer_global(vty, bgp, group->conf);
18151 }
18152
18153 /* Normal neighbor configuration. */
18154 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
18155 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
18156 bgp_config_write_peer_global(vty, bgp, peer);
18157 }
18158
18159 /* listen range and limit for dynamic BGP neighbors */
18160 bgp_config_write_listen(vty, bgp);
18161
18162 /*
18163 * BGP default autoshutdown neighbors
18164 *
18165 * This must be placed after any peer and peer-group
18166 * configuration, to avoid setting all peers to shutdown after
18167 * a daemon restart, which is undesired behavior. (see #2286)
18168 */
18169 if (bgp->autoshutdown)
18170 vty_out(vty, " bgp default shutdown\n");
18171
18172 /* BGP instance administrative shutdown */
18173 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN))
18174 vty_out(vty, " bgp shutdown\n");
18175
18176 if (bgp->srv6_enabled) {
18177 vty_frame(vty, " !\n segment-routing srv6\n");
18178 if (strlen(bgp->srv6_locator_name))
18179 vty_out(vty, " locator %s\n",
18180 bgp->srv6_locator_name);
18181 }
18182
18183
18184 /* IPv4 unicast configuration. */
18185 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
18186
18187 /* IPv4 multicast configuration. */
18188 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
18189
18190 /* IPv4 labeled-unicast configuration. */
18191 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
18192
18193 /* IPv4 VPN configuration. */
18194 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
18195
18196 /* ENCAPv4 configuration. */
18197 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
18198
18199 /* FLOWSPEC v4 configuration. */
18200 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
18201
18202 /* IPv6 unicast configuration. */
18203 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
18204
18205 /* IPv6 multicast configuration. */
18206 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
18207
18208 /* IPv6 labeled-unicast configuration. */
18209 bgp_config_write_family(vty, bgp, AFI_IP6,
18210 SAFI_LABELED_UNICAST);
18211
18212 /* IPv6 VPN configuration. */
18213 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
18214
18215 /* ENCAPv6 configuration. */
18216 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
18217
18218 /* FLOWSPEC v6 configuration. */
18219 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
18220
18221 /* EVPN configuration. */
18222 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
18223
18224 hook_call(bgp_inst_config_write, bgp, vty);
18225
18226 #ifdef ENABLE_BGP_VNC
18227 bgp_rfapi_cfg_write(vty, bgp);
18228 #endif
18229
18230 vty_out(vty, "!\n");
18231 }
18232 return 0;
18233 }
18234
18235
18236 /* BGP node structure. */
18237 static struct cmd_node bgp_node = {
18238 .name = "bgp",
18239 .node = BGP_NODE,
18240 .parent_node = CONFIG_NODE,
18241 .prompt = "%s(config-router)# ",
18242 .config_write = bgp_config_write,
18243 };
18244
18245 static struct cmd_node bgp_ipv4_unicast_node = {
18246 .name = "bgp ipv4 unicast",
18247 .node = BGP_IPV4_NODE,
18248 .parent_node = BGP_NODE,
18249 .prompt = "%s(config-router-af)# ",
18250 };
18251
18252 static struct cmd_node bgp_ipv4_multicast_node = {
18253 .name = "bgp ipv4 multicast",
18254 .node = BGP_IPV4M_NODE,
18255 .parent_node = BGP_NODE,
18256 .prompt = "%s(config-router-af)# ",
18257 };
18258
18259 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
18260 .name = "bgp ipv4 labeled unicast",
18261 .node = BGP_IPV4L_NODE,
18262 .parent_node = BGP_NODE,
18263 .prompt = "%s(config-router-af)# ",
18264 };
18265
18266 static struct cmd_node bgp_ipv6_unicast_node = {
18267 .name = "bgp ipv6",
18268 .node = BGP_IPV6_NODE,
18269 .parent_node = BGP_NODE,
18270 .prompt = "%s(config-router-af)# ",
18271 };
18272
18273 static struct cmd_node bgp_ipv6_multicast_node = {
18274 .name = "bgp ipv6 multicast",
18275 .node = BGP_IPV6M_NODE,
18276 .parent_node = BGP_NODE,
18277 .prompt = "%s(config-router-af)# ",
18278 };
18279
18280 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
18281 .name = "bgp ipv6 labeled unicast",
18282 .node = BGP_IPV6L_NODE,
18283 .parent_node = BGP_NODE,
18284 .prompt = "%s(config-router-af)# ",
18285 };
18286
18287 static struct cmd_node bgp_vpnv4_node = {
18288 .name = "bgp vpnv4",
18289 .node = BGP_VPNV4_NODE,
18290 .parent_node = BGP_NODE,
18291 .prompt = "%s(config-router-af)# ",
18292 };
18293
18294 static struct cmd_node bgp_vpnv6_node = {
18295 .name = "bgp vpnv6",
18296 .node = BGP_VPNV6_NODE,
18297 .parent_node = BGP_NODE,
18298 .prompt = "%s(config-router-af-vpnv6)# ",
18299 };
18300
18301 static struct cmd_node bgp_evpn_node = {
18302 .name = "bgp evpn",
18303 .node = BGP_EVPN_NODE,
18304 .parent_node = BGP_NODE,
18305 .prompt = "%s(config-router-evpn)# ",
18306 };
18307
18308 static struct cmd_node bgp_evpn_vni_node = {
18309 .name = "bgp evpn vni",
18310 .node = BGP_EVPN_VNI_NODE,
18311 .parent_node = BGP_EVPN_NODE,
18312 .prompt = "%s(config-router-af-vni)# ",
18313 };
18314
18315 static struct cmd_node bgp_flowspecv4_node = {
18316 .name = "bgp ipv4 flowspec",
18317 .node = BGP_FLOWSPECV4_NODE,
18318 .parent_node = BGP_NODE,
18319 .prompt = "%s(config-router-af)# ",
18320 };
18321
18322 static struct cmd_node bgp_flowspecv6_node = {
18323 .name = "bgp ipv6 flowspec",
18324 .node = BGP_FLOWSPECV6_NODE,
18325 .parent_node = BGP_NODE,
18326 .prompt = "%s(config-router-af-vpnv6)# ",
18327 };
18328
18329 static struct cmd_node bgp_srv6_node = {
18330 .name = "bgp srv6",
18331 .node = BGP_SRV6_NODE,
18332 .parent_node = BGP_NODE,
18333 .prompt = "%s(config-router-srv6)# ",
18334 };
18335
18336 static void community_list_vty(void);
18337
18338 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
18339 {
18340 struct bgp *bgp;
18341 struct peer *peer;
18342 struct listnode *lnbgp, *lnpeer;
18343
18344 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
18345 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
18346 /* only provide suggestions on the appropriate input
18347 * token type,
18348 * they'll otherwise show up multiple times */
18349 enum cmd_token_type match_type;
18350 char *name = peer->host;
18351
18352 if (peer->conf_if) {
18353 match_type = VARIABLE_TKN;
18354 name = peer->conf_if;
18355 } else if (strchr(peer->host, ':'))
18356 match_type = IPV6_TKN;
18357 else
18358 match_type = IPV4_TKN;
18359
18360 if (token->type != match_type)
18361 continue;
18362
18363 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
18364 }
18365 }
18366 }
18367
18368 static const struct cmd_variable_handler bgp_var_neighbor[] = {
18369 {.varname = "neighbor", .completions = bgp_ac_neighbor},
18370 {.varname = "neighbors", .completions = bgp_ac_neighbor},
18371 {.varname = "peer", .completions = bgp_ac_neighbor},
18372 {.completions = NULL}};
18373
18374 static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
18375 {
18376 struct bgp *bgp;
18377 struct peer_group *group;
18378 struct listnode *lnbgp, *lnpeer;
18379
18380 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
18381 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
18382 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
18383 group->name));
18384 }
18385 }
18386
18387 static const struct cmd_variable_handler bgp_var_peergroup[] = {
18388 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
18389 {.completions = NULL} };
18390
18391 void bgp_vty_init(void)
18392 {
18393 cmd_variable_handler_register(bgp_var_neighbor);
18394 cmd_variable_handler_register(bgp_var_peergroup);
18395
18396 /* Install bgp top node. */
18397 install_node(&bgp_node);
18398 install_node(&bgp_ipv4_unicast_node);
18399 install_node(&bgp_ipv4_multicast_node);
18400 install_node(&bgp_ipv4_labeled_unicast_node);
18401 install_node(&bgp_ipv6_unicast_node);
18402 install_node(&bgp_ipv6_multicast_node);
18403 install_node(&bgp_ipv6_labeled_unicast_node);
18404 install_node(&bgp_vpnv4_node);
18405 install_node(&bgp_vpnv6_node);
18406 install_node(&bgp_evpn_node);
18407 install_node(&bgp_evpn_vni_node);
18408 install_node(&bgp_flowspecv4_node);
18409 install_node(&bgp_flowspecv6_node);
18410 install_node(&bgp_srv6_node);
18411
18412 /* Install default VTY commands to new nodes. */
18413 install_default(BGP_NODE);
18414 install_default(BGP_IPV4_NODE);
18415 install_default(BGP_IPV4M_NODE);
18416 install_default(BGP_IPV4L_NODE);
18417 install_default(BGP_IPV6_NODE);
18418 install_default(BGP_IPV6M_NODE);
18419 install_default(BGP_IPV6L_NODE);
18420 install_default(BGP_VPNV4_NODE);
18421 install_default(BGP_VPNV6_NODE);
18422 install_default(BGP_FLOWSPECV4_NODE);
18423 install_default(BGP_FLOWSPECV6_NODE);
18424 install_default(BGP_EVPN_NODE);
18425 install_default(BGP_EVPN_VNI_NODE);
18426 install_default(BGP_SRV6_NODE);
18427
18428 /* "bgp local-mac" hidden commands. */
18429 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
18430 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
18431
18432 /* "bgp suppress-fib-pending" global */
18433 install_element(CONFIG_NODE, &bgp_global_suppress_fib_pending_cmd);
18434
18435 /* bgp route-map delay-timer commands. */
18436 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
18437 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
18438
18439 /* global bgp update-delay command */
18440 install_element(CONFIG_NODE, &bgp_global_update_delay_cmd);
18441 install_element(CONFIG_NODE, &no_bgp_global_update_delay_cmd);
18442
18443 /* global bgp graceful-shutdown command */
18444 install_element(CONFIG_NODE, &bgp_graceful_shutdown_cmd);
18445 install_element(CONFIG_NODE, &no_bgp_graceful_shutdown_cmd);
18446
18447 /* Dummy commands (Currently not supported) */
18448 install_element(BGP_NODE, &no_synchronization_cmd);
18449 install_element(BGP_NODE, &no_auto_summary_cmd);
18450
18451 /* "router bgp" commands. */
18452 install_element(CONFIG_NODE, &router_bgp_cmd);
18453
18454 /* "no router bgp" commands. */
18455 install_element(CONFIG_NODE, &no_router_bgp_cmd);
18456
18457 /* "bgp router-id" commands. */
18458 install_element(BGP_NODE, &bgp_router_id_cmd);
18459 install_element(BGP_NODE, &no_bgp_router_id_cmd);
18460
18461 /* "bgp suppress-fib-pending" command */
18462 install_element(BGP_NODE, &bgp_suppress_fib_pending_cmd);
18463
18464 /* "bgp cluster-id" commands. */
18465 install_element(BGP_NODE, &bgp_cluster_id_cmd);
18466 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
18467
18468 /* "bgp no-rib" commands. */
18469 install_element(CONFIG_NODE, &bgp_norib_cmd);
18470 install_element(CONFIG_NODE, &no_bgp_norib_cmd);
18471
18472 install_element(CONFIG_NODE, &no_bgp_send_extra_data_cmd);
18473
18474 /* "bgp confederation" commands. */
18475 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
18476 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
18477
18478 /* "bgp confederation peers" commands. */
18479 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
18480 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
18481
18482 /* bgp max-med command */
18483 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
18484 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
18485 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
18486 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
18487 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
18488
18489 /* bgp disable-ebgp-connected-nh-check */
18490 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
18491 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
18492
18493 /* bgp update-delay command */
18494 install_element(BGP_NODE, &bgp_update_delay_cmd);
18495 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
18496
18497 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
18498 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
18499
18500 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
18501 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
18502
18503 /* "maximum-paths" commands. */
18504 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
18505 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
18506 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
18507 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
18508 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
18509 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
18510 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
18511 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
18512 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
18513 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
18514 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18515 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
18516 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
18517 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18518 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
18519
18520 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_cmd);
18521 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_cmd);
18522 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cmd);
18523 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18524 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_ibgp_cmd);
18525 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
18526 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
18527 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
18528 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18529 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
18530
18531 /* "timers bgp" commands. */
18532 install_element(BGP_NODE, &bgp_timers_cmd);
18533 install_element(BGP_NODE, &no_bgp_timers_cmd);
18534
18535 /* route-map delay-timer commands - per instance for backwards compat.
18536 */
18537 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
18538 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
18539
18540 /* "bgp client-to-client reflection" commands */
18541 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
18542 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
18543
18544 /* "bgp always-compare-med" commands */
18545 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
18546 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
18547
18548 /* bgp ebgp-requires-policy */
18549 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
18550 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
18551
18552 /* bgp suppress-duplicates */
18553 install_element(BGP_NODE, &bgp_suppress_duplicates_cmd);
18554 install_element(BGP_NODE, &no_bgp_suppress_duplicates_cmd);
18555
18556 /* bgp reject-as-sets */
18557 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
18558 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
18559
18560 /* "bgp deterministic-med" commands */
18561 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
18562 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
18563
18564 /* "bgp graceful-restart" command */
18565 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
18566 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
18567
18568 /* "bgp graceful-restart-disable" command */
18569 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
18570 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
18571
18572 /* "neighbor a:b:c:d graceful-restart" command */
18573 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
18574 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
18575
18576 /* "neighbor a:b:c:d graceful-restart-disable" command */
18577 install_element(BGP_NODE,
18578 &bgp_neighbor_graceful_restart_disable_set_cmd);
18579 install_element(BGP_NODE,
18580 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
18581
18582 /* "neighbor a:b:c:d graceful-restart-helper" command */
18583 install_element(BGP_NODE,
18584 &bgp_neighbor_graceful_restart_helper_set_cmd);
18585 install_element(BGP_NODE,
18586 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
18587
18588 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
18589 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
18590 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
18591 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
18592 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
18593 install_element(BGP_NODE,
18594 &no_bgp_graceful_restart_select_defer_time_cmd);
18595 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
18596 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
18597
18598 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
18599 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
18600 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
18601 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
18602
18603 /* "bgp graceful-shutdown" commands */
18604 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
18605 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
18606
18607 /* "bgp fast-external-failover" commands */
18608 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
18609 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
18610
18611 /* "bgp bestpath compare-routerid" commands */
18612 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
18613 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
18614
18615 /* "bgp bestpath as-path ignore" commands */
18616 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
18617 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
18618
18619 /* "bgp bestpath as-path confed" commands */
18620 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
18621 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
18622
18623 /* "bgp bestpath as-path multipath-relax" commands */
18624 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
18625 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
18626
18627 /* "bgp bestpath peer-type multipath-relax" commands */
18628 install_element(BGP_NODE, &bgp_bestpath_peer_type_multipath_relax_cmd);
18629 install_element(BGP_NODE,
18630 &no_bgp_bestpath_peer_type_multipath_relax_cmd);
18631
18632 /* "bgp log-neighbor-changes" commands */
18633 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
18634 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
18635
18636 /* "bgp bestpath med" commands */
18637 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
18638 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
18639
18640 /* "bgp bestpath bandwidth" commands */
18641 install_element(BGP_NODE, &bgp_bestpath_bw_cmd);
18642 install_element(BGP_NODE, &no_bgp_bestpath_bw_cmd);
18643
18644 /* "no bgp default <afi>-<safi>" commands. */
18645 install_element(BGP_NODE, &bgp_default_afi_safi_cmd);
18646
18647 /* "bgp network import-check" commands. */
18648 install_element(BGP_NODE, &bgp_network_import_check_cmd);
18649 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
18650 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
18651
18652 /* "bgp default local-preference" commands. */
18653 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
18654 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
18655
18656 /* bgp default show-hostname */
18657 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
18658 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
18659
18660 /* bgp default show-nexthop-hostname */
18661 install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
18662 install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
18663
18664 /* "bgp default subgroup-pkt-queue-max" commands. */
18665 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
18666 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
18667
18668 /* bgp ibgp-allow-policy-mods command */
18669 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
18670 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
18671
18672 /* "bgp listen limit" commands. */
18673 install_element(BGP_NODE, &bgp_listen_limit_cmd);
18674 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
18675
18676 /* "bgp listen range" commands. */
18677 install_element(BGP_NODE, &bgp_listen_range_cmd);
18678 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
18679
18680 /* "bgp default shutdown" command */
18681 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
18682
18683 /* "bgp shutdown" commands */
18684 install_element(BGP_NODE, &bgp_shutdown_cmd);
18685 install_element(BGP_NODE, &bgp_shutdown_msg_cmd);
18686 install_element(BGP_NODE, &no_bgp_shutdown_cmd);
18687 install_element(BGP_NODE, &no_bgp_shutdown_msg_cmd);
18688
18689 /* "neighbor remote-as" commands. */
18690 install_element(BGP_NODE, &neighbor_remote_as_cmd);
18691 install_element(BGP_NODE, &neighbor_interface_config_cmd);
18692 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
18693 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
18694 install_element(BGP_NODE,
18695 &neighbor_interface_v6only_config_remote_as_cmd);
18696 install_element(BGP_NODE, &no_neighbor_cmd);
18697 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
18698
18699 /* "neighbor peer-group" commands. */
18700 install_element(BGP_NODE, &neighbor_peer_group_cmd);
18701 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
18702 install_element(BGP_NODE,
18703 &no_neighbor_interface_peer_group_remote_as_cmd);
18704
18705 /* "neighbor local-as" commands. */
18706 install_element(BGP_NODE, &neighbor_local_as_cmd);
18707 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
18708 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
18709 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
18710
18711 /* "neighbor solo" commands. */
18712 install_element(BGP_NODE, &neighbor_solo_cmd);
18713 install_element(BGP_NODE, &no_neighbor_solo_cmd);
18714
18715 /* "neighbor password" commands. */
18716 install_element(BGP_NODE, &neighbor_password_cmd);
18717 install_element(BGP_NODE, &no_neighbor_password_cmd);
18718
18719 /* "neighbor activate" commands. */
18720 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
18721 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
18722 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
18723 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
18724 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
18725 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
18726 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
18727 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
18728 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
18729 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
18730 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
18731 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
18732
18733 /* "no neighbor activate" commands. */
18734 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
18735 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
18736 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
18737 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
18738 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
18739 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
18740 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
18741 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
18742 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
18743 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
18744 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
18745 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
18746
18747 /* "neighbor peer-group" set commands. */
18748 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
18749 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
18750 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
18751 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
18752 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
18753 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
18754 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
18755 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
18756 install_element(BGP_FLOWSPECV4_NODE,
18757 &neighbor_set_peer_group_hidden_cmd);
18758 install_element(BGP_FLOWSPECV6_NODE,
18759 &neighbor_set_peer_group_hidden_cmd);
18760
18761 /* "no neighbor peer-group unset" commands. */
18762 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
18763 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18764 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18765 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18766 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18767 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18768 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18769 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18770 install_element(BGP_FLOWSPECV4_NODE,
18771 &no_neighbor_set_peer_group_hidden_cmd);
18772 install_element(BGP_FLOWSPECV6_NODE,
18773 &no_neighbor_set_peer_group_hidden_cmd);
18774
18775 /* "neighbor softreconfiguration inbound" commands.*/
18776 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
18777 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
18778 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
18779 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
18780 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
18781 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
18782 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
18783 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
18784 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
18785 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
18786 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
18787 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
18788 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
18789 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
18790 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
18791 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
18792 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
18793 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
18794 install_element(BGP_FLOWSPECV4_NODE,
18795 &neighbor_soft_reconfiguration_cmd);
18796 install_element(BGP_FLOWSPECV4_NODE,
18797 &no_neighbor_soft_reconfiguration_cmd);
18798 install_element(BGP_FLOWSPECV6_NODE,
18799 &neighbor_soft_reconfiguration_cmd);
18800 install_element(BGP_FLOWSPECV6_NODE,
18801 &no_neighbor_soft_reconfiguration_cmd);
18802 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
18803 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
18804
18805 /* "neighbor attribute-unchanged" commands. */
18806 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
18807 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
18808 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
18809 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
18810 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
18811 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
18812 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
18813 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
18814 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
18815 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
18816 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
18817 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
18818 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
18819 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
18820 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
18821 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
18822 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
18823 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
18824
18825 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
18826 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
18827
18828 install_element(BGP_FLOWSPECV4_NODE, &neighbor_attr_unchanged_cmd);
18829 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_attr_unchanged_cmd);
18830 install_element(BGP_FLOWSPECV6_NODE, &neighbor_attr_unchanged_cmd);
18831 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_attr_unchanged_cmd);
18832
18833 /* "nexthop-local unchanged" commands */
18834 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
18835 install_element(BGP_IPV6_NODE,
18836 &no_neighbor_nexthop_local_unchanged_cmd);
18837
18838 /* "neighbor next-hop-self" commands. */
18839 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
18840 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
18841 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
18842 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
18843 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
18844 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
18845 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
18846 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
18847 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
18848 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
18849 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
18850 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
18851 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
18852 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
18853 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
18854 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
18855 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
18856 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
18857 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
18858 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
18859
18860 /* "neighbor next-hop-self force" commands. */
18861 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
18862 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
18863 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18864 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
18865 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
18866 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
18867 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18868 install_element(BGP_IPV4_NODE,
18869 &no_neighbor_nexthop_self_all_hidden_cmd);
18870 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
18871 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
18872 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18873 install_element(BGP_IPV4M_NODE,
18874 &no_neighbor_nexthop_self_all_hidden_cmd);
18875 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
18876 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
18877 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18878 install_element(BGP_IPV4L_NODE,
18879 &no_neighbor_nexthop_self_all_hidden_cmd);
18880 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
18881 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
18882 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18883 install_element(BGP_IPV6_NODE,
18884 &no_neighbor_nexthop_self_all_hidden_cmd);
18885 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
18886 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
18887 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18888 install_element(BGP_IPV6M_NODE,
18889 &no_neighbor_nexthop_self_all_hidden_cmd);
18890 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
18891 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
18892 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18893 install_element(BGP_IPV6L_NODE,
18894 &no_neighbor_nexthop_self_all_hidden_cmd);
18895 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
18896 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
18897 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18898 install_element(BGP_VPNV4_NODE,
18899 &no_neighbor_nexthop_self_all_hidden_cmd);
18900 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
18901 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
18902 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18903 install_element(BGP_VPNV6_NODE,
18904 &no_neighbor_nexthop_self_all_hidden_cmd);
18905 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_force_cmd);
18906 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_force_cmd);
18907
18908 /* "neighbor as-override" commands. */
18909 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
18910 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
18911 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
18912 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
18913 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
18914 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
18915 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
18916 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
18917 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
18918 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
18919 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
18920 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
18921 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
18922 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
18923 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
18924 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
18925 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
18926 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
18927
18928 /* "neighbor remove-private-AS" commands. */
18929 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
18930 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
18931 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
18932 install_element(BGP_NODE,
18933 &no_neighbor_remove_private_as_all_hidden_cmd);
18934 install_element(BGP_NODE,
18935 &neighbor_remove_private_as_replace_as_hidden_cmd);
18936 install_element(BGP_NODE,
18937 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
18938 install_element(BGP_NODE,
18939 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
18940 install_element(
18941 BGP_NODE,
18942 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
18943 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
18944 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
18945 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
18946 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18947 install_element(BGP_IPV4_NODE,
18948 &neighbor_remove_private_as_replace_as_cmd);
18949 install_element(BGP_IPV4_NODE,
18950 &no_neighbor_remove_private_as_replace_as_cmd);
18951 install_element(BGP_IPV4_NODE,
18952 &neighbor_remove_private_as_all_replace_as_cmd);
18953 install_element(BGP_IPV4_NODE,
18954 &no_neighbor_remove_private_as_all_replace_as_cmd);
18955 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
18956 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
18957 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
18958 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
18959 install_element(BGP_IPV4M_NODE,
18960 &neighbor_remove_private_as_replace_as_cmd);
18961 install_element(BGP_IPV4M_NODE,
18962 &no_neighbor_remove_private_as_replace_as_cmd);
18963 install_element(BGP_IPV4M_NODE,
18964 &neighbor_remove_private_as_all_replace_as_cmd);
18965 install_element(BGP_IPV4M_NODE,
18966 &no_neighbor_remove_private_as_all_replace_as_cmd);
18967 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
18968 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
18969 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
18970 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
18971 install_element(BGP_IPV4L_NODE,
18972 &neighbor_remove_private_as_replace_as_cmd);
18973 install_element(BGP_IPV4L_NODE,
18974 &no_neighbor_remove_private_as_replace_as_cmd);
18975 install_element(BGP_IPV4L_NODE,
18976 &neighbor_remove_private_as_all_replace_as_cmd);
18977 install_element(BGP_IPV4L_NODE,
18978 &no_neighbor_remove_private_as_all_replace_as_cmd);
18979 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
18980 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
18981 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
18982 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18983 install_element(BGP_IPV6_NODE,
18984 &neighbor_remove_private_as_replace_as_cmd);
18985 install_element(BGP_IPV6_NODE,
18986 &no_neighbor_remove_private_as_replace_as_cmd);
18987 install_element(BGP_IPV6_NODE,
18988 &neighbor_remove_private_as_all_replace_as_cmd);
18989 install_element(BGP_IPV6_NODE,
18990 &no_neighbor_remove_private_as_all_replace_as_cmd);
18991 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
18992 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
18993 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
18994 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
18995 install_element(BGP_IPV6M_NODE,
18996 &neighbor_remove_private_as_replace_as_cmd);
18997 install_element(BGP_IPV6M_NODE,
18998 &no_neighbor_remove_private_as_replace_as_cmd);
18999 install_element(BGP_IPV6M_NODE,
19000 &neighbor_remove_private_as_all_replace_as_cmd);
19001 install_element(BGP_IPV6M_NODE,
19002 &no_neighbor_remove_private_as_all_replace_as_cmd);
19003 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
19004 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
19005 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
19006 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
19007 install_element(BGP_IPV6L_NODE,
19008 &neighbor_remove_private_as_replace_as_cmd);
19009 install_element(BGP_IPV6L_NODE,
19010 &no_neighbor_remove_private_as_replace_as_cmd);
19011 install_element(BGP_IPV6L_NODE,
19012 &neighbor_remove_private_as_all_replace_as_cmd);
19013 install_element(BGP_IPV6L_NODE,
19014 &no_neighbor_remove_private_as_all_replace_as_cmd);
19015 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
19016 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
19017 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
19018 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
19019 install_element(BGP_VPNV4_NODE,
19020 &neighbor_remove_private_as_replace_as_cmd);
19021 install_element(BGP_VPNV4_NODE,
19022 &no_neighbor_remove_private_as_replace_as_cmd);
19023 install_element(BGP_VPNV4_NODE,
19024 &neighbor_remove_private_as_all_replace_as_cmd);
19025 install_element(BGP_VPNV4_NODE,
19026 &no_neighbor_remove_private_as_all_replace_as_cmd);
19027 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
19028 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
19029 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
19030 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
19031 install_element(BGP_VPNV6_NODE,
19032 &neighbor_remove_private_as_replace_as_cmd);
19033 install_element(BGP_VPNV6_NODE,
19034 &no_neighbor_remove_private_as_replace_as_cmd);
19035 install_element(BGP_VPNV6_NODE,
19036 &neighbor_remove_private_as_all_replace_as_cmd);
19037 install_element(BGP_VPNV6_NODE,
19038 &no_neighbor_remove_private_as_all_replace_as_cmd);
19039
19040 /* "neighbor send-community" commands.*/
19041 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
19042 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
19043 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
19044 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
19045 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
19046 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
19047 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
19048 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
19049 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
19050 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
19051 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
19052 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
19053 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
19054 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
19055 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
19056 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
19057 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
19058 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
19059 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
19060 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
19061 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
19062 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
19063 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
19064 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
19065 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
19066 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
19067 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
19068 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
19069 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
19070 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
19071 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
19072 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
19073 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
19074 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
19075 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
19076 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
19077
19078 /* "neighbor route-reflector" commands.*/
19079 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
19080 install_element(BGP_NODE,
19081 &no_neighbor_route_reflector_client_hidden_cmd);
19082 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
19083 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
19084 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
19085 install_element(BGP_IPV4M_NODE,
19086 &no_neighbor_route_reflector_client_cmd);
19087 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
19088 install_element(BGP_IPV4L_NODE,
19089 &no_neighbor_route_reflector_client_cmd);
19090 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
19091 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
19092 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
19093 install_element(BGP_IPV6M_NODE,
19094 &no_neighbor_route_reflector_client_cmd);
19095 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
19096 install_element(BGP_IPV6L_NODE,
19097 &no_neighbor_route_reflector_client_cmd);
19098 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
19099 install_element(BGP_VPNV4_NODE,
19100 &no_neighbor_route_reflector_client_cmd);
19101 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
19102 install_element(BGP_VPNV6_NODE,
19103 &no_neighbor_route_reflector_client_cmd);
19104 install_element(BGP_FLOWSPECV4_NODE,
19105 &neighbor_route_reflector_client_cmd);
19106 install_element(BGP_FLOWSPECV4_NODE,
19107 &no_neighbor_route_reflector_client_cmd);
19108 install_element(BGP_FLOWSPECV6_NODE,
19109 &neighbor_route_reflector_client_cmd);
19110 install_element(BGP_FLOWSPECV6_NODE,
19111 &no_neighbor_route_reflector_client_cmd);
19112 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
19113 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
19114
19115 /* "neighbor route-server" commands.*/
19116 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
19117 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
19118 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
19119 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
19120 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
19121 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
19122 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
19123 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
19124 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
19125 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
19126 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
19127 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
19128 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
19129 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
19130 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
19131 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
19132 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
19133 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
19134 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
19135 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
19136 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
19137 install_element(BGP_FLOWSPECV4_NODE,
19138 &no_neighbor_route_server_client_cmd);
19139 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
19140 install_element(BGP_FLOWSPECV6_NODE,
19141 &no_neighbor_route_server_client_cmd);
19142
19143 /* "neighbor addpath-tx-all-paths" commands.*/
19144 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
19145 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
19146 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
19147 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19148 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
19149 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19150 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
19151 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19152 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
19153 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19154 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
19155 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19156 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
19157 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19158 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
19159 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19160 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
19161 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19162
19163 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
19164 install_element(BGP_NODE,
19165 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
19166 install_element(BGP_NODE,
19167 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
19168 install_element(BGP_IPV4_NODE,
19169 &neighbor_addpath_tx_bestpath_per_as_cmd);
19170 install_element(BGP_IPV4_NODE,
19171 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19172 install_element(BGP_IPV4M_NODE,
19173 &neighbor_addpath_tx_bestpath_per_as_cmd);
19174 install_element(BGP_IPV4M_NODE,
19175 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19176 install_element(BGP_IPV4L_NODE,
19177 &neighbor_addpath_tx_bestpath_per_as_cmd);
19178 install_element(BGP_IPV4L_NODE,
19179 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19180 install_element(BGP_IPV6_NODE,
19181 &neighbor_addpath_tx_bestpath_per_as_cmd);
19182 install_element(BGP_IPV6_NODE,
19183 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19184 install_element(BGP_IPV6M_NODE,
19185 &neighbor_addpath_tx_bestpath_per_as_cmd);
19186 install_element(BGP_IPV6M_NODE,
19187 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19188 install_element(BGP_IPV6L_NODE,
19189 &neighbor_addpath_tx_bestpath_per_as_cmd);
19190 install_element(BGP_IPV6L_NODE,
19191 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19192 install_element(BGP_VPNV4_NODE,
19193 &neighbor_addpath_tx_bestpath_per_as_cmd);
19194 install_element(BGP_VPNV4_NODE,
19195 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19196 install_element(BGP_VPNV6_NODE,
19197 &neighbor_addpath_tx_bestpath_per_as_cmd);
19198 install_element(BGP_VPNV6_NODE,
19199 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19200
19201 /* "neighbor sender-as-path-loop-detection" commands. */
19202 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
19203 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
19204
19205 /* "neighbor passive" commands. */
19206 install_element(BGP_NODE, &neighbor_passive_cmd);
19207 install_element(BGP_NODE, &no_neighbor_passive_cmd);
19208
19209
19210 /* "neighbor shutdown" commands. */
19211 install_element(BGP_NODE, &neighbor_shutdown_cmd);
19212 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
19213 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
19214 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
19215 install_element(BGP_NODE, &neighbor_shutdown_rtt_cmd);
19216 install_element(BGP_NODE, &no_neighbor_shutdown_rtt_cmd);
19217
19218 /* "neighbor capability extended-nexthop" commands.*/
19219 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
19220 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
19221
19222 /* "neighbor capability orf prefix-list" commands.*/
19223 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
19224 install_element(BGP_NODE,
19225 &no_neighbor_capability_orf_prefix_hidden_cmd);
19226 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
19227 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
19228 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
19229 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
19230 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
19231 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
19232 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
19233 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
19234 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
19235 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
19236 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
19237 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
19238
19239 /* "neighbor capability dynamic" commands.*/
19240 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
19241 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
19242
19243 /* "neighbor dont-capability-negotiate" commands. */
19244 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
19245 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
19246
19247 /* "neighbor ebgp-multihop" commands. */
19248 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
19249 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
19250 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
19251
19252 /* "neighbor disable-connected-check" commands. */
19253 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
19254 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
19255
19256 /* "neighbor enforce-first-as" commands. */
19257 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
19258 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
19259
19260 /* "neighbor description" commands. */
19261 install_element(BGP_NODE, &neighbor_description_cmd);
19262 install_element(BGP_NODE, &no_neighbor_description_cmd);
19263 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
19264
19265 /* "neighbor update-source" commands. "*/
19266 install_element(BGP_NODE, &neighbor_update_source_cmd);
19267 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
19268
19269 /* "neighbor default-originate" commands. */
19270 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
19271 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
19272 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
19273 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
19274 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
19275 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
19276 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
19277 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
19278 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
19279 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
19280 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
19281 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
19282 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
19283 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
19284 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
19285 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
19286 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
19287 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
19288 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
19289 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
19290 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
19291
19292 /* "neighbor port" commands. */
19293 install_element(BGP_NODE, &neighbor_port_cmd);
19294 install_element(BGP_NODE, &no_neighbor_port_cmd);
19295
19296 /* "neighbor weight" commands. */
19297 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
19298 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
19299
19300 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
19301 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
19302 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
19303 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
19304 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
19305 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
19306 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
19307 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
19308 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
19309 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
19310 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
19311 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
19312 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
19313 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
19314 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
19315 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
19316
19317 /* "neighbor override-capability" commands. */
19318 install_element(BGP_NODE, &neighbor_override_capability_cmd);
19319 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
19320
19321 /* "neighbor strict-capability-match" commands. */
19322 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
19323 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
19324
19325 /* "neighbor timers" commands. */
19326 install_element(BGP_NODE, &neighbor_timers_cmd);
19327 install_element(BGP_NODE, &no_neighbor_timers_cmd);
19328
19329 /* "neighbor timers connect" commands. */
19330 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
19331 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
19332
19333 /* "neighbor timers delayopen" commands. */
19334 install_element(BGP_NODE, &neighbor_timers_delayopen_cmd);
19335 install_element(BGP_NODE, &no_neighbor_timers_delayopen_cmd);
19336
19337 /* "neighbor advertisement-interval" commands. */
19338 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
19339 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
19340
19341 /* "neighbor interface" commands. */
19342 install_element(BGP_NODE, &neighbor_interface_cmd);
19343 install_element(BGP_NODE, &no_neighbor_interface_cmd);
19344
19345 /* "neighbor distribute" commands. */
19346 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
19347 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
19348 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
19349 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
19350 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
19351 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
19352 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
19353 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
19354 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
19355 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
19356 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
19357 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
19358 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
19359 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
19360 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
19361 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
19362 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
19363 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
19364
19365 /* "neighbor prefix-list" commands. */
19366 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
19367 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
19368 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
19369 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
19370 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
19371 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
19372 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
19373 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
19374 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
19375 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
19376 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
19377
19378 /* "neighbor filter-list" commands. */
19379 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
19380 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
19381 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
19382 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
19383 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
19384 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
19385 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
19386 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
19387 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
19388 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
19389 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
19390 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
19391 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
19392 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
19393 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
19394 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
19395 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
19396 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
19397 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
19398 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
19399 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
19400 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
19401
19402 /* "neighbor route-map" commands. */
19403 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
19404 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
19405 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
19406 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
19407 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
19408 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
19409 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
19410 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
19411 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
19412 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
19413 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
19414
19415 /* "neighbor unsuppress-map" commands. */
19416 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
19417 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
19418 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
19419 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
19420 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
19421 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
19422 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
19423 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
19424 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
19425 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
19426 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
19427 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
19428 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
19429 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
19430 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
19431 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
19432 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
19433 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
19434
19435 /* "neighbor advertise-map" commands. */
19436 install_element(BGP_NODE, &neighbor_advertise_map_hidden_cmd);
19437 install_element(BGP_IPV4_NODE, &neighbor_advertise_map_cmd);
19438 install_element(BGP_IPV4M_NODE, &neighbor_advertise_map_cmd);
19439 install_element(BGP_IPV4L_NODE, &neighbor_advertise_map_cmd);
19440 install_element(BGP_IPV6_NODE, &neighbor_advertise_map_cmd);
19441 install_element(BGP_IPV6M_NODE, &neighbor_advertise_map_cmd);
19442 install_element(BGP_IPV6L_NODE, &neighbor_advertise_map_cmd);
19443 install_element(BGP_VPNV4_NODE, &neighbor_advertise_map_cmd);
19444 install_element(BGP_VPNV6_NODE, &neighbor_advertise_map_cmd);
19445
19446 /* neighbor maximum-prefix-out commands. */
19447 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
19448 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
19449 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
19450 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
19451 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
19452 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
19453 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
19454 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
19455 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
19456 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
19457 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
19458 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
19459 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
19460 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
19461 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
19462 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
19463 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
19464 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
19465
19466 /* "neighbor maximum-prefix" commands. */
19467 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
19468 install_element(BGP_NODE,
19469 &neighbor_maximum_prefix_threshold_hidden_cmd);
19470 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
19471 install_element(BGP_NODE,
19472 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
19473 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
19474 install_element(BGP_NODE,
19475 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
19476 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
19477 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
19478 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
19479 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
19480 install_element(BGP_IPV4_NODE,
19481 &neighbor_maximum_prefix_threshold_warning_cmd);
19482 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
19483 install_element(BGP_IPV4_NODE,
19484 &neighbor_maximum_prefix_threshold_restart_cmd);
19485 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
19486 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
19487 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
19488 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
19489 install_element(BGP_IPV4M_NODE,
19490 &neighbor_maximum_prefix_threshold_warning_cmd);
19491 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
19492 install_element(BGP_IPV4M_NODE,
19493 &neighbor_maximum_prefix_threshold_restart_cmd);
19494 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
19495 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
19496 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
19497 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
19498 install_element(BGP_IPV4L_NODE,
19499 &neighbor_maximum_prefix_threshold_warning_cmd);
19500 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
19501 install_element(BGP_IPV4L_NODE,
19502 &neighbor_maximum_prefix_threshold_restart_cmd);
19503 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
19504 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
19505 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
19506 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
19507 install_element(BGP_IPV6_NODE,
19508 &neighbor_maximum_prefix_threshold_warning_cmd);
19509 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
19510 install_element(BGP_IPV6_NODE,
19511 &neighbor_maximum_prefix_threshold_restart_cmd);
19512 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
19513 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
19514 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
19515 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
19516 install_element(BGP_IPV6M_NODE,
19517 &neighbor_maximum_prefix_threshold_warning_cmd);
19518 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
19519 install_element(BGP_IPV6M_NODE,
19520 &neighbor_maximum_prefix_threshold_restart_cmd);
19521 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
19522 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
19523 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
19524 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
19525 install_element(BGP_IPV6L_NODE,
19526 &neighbor_maximum_prefix_threshold_warning_cmd);
19527 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
19528 install_element(BGP_IPV6L_NODE,
19529 &neighbor_maximum_prefix_threshold_restart_cmd);
19530 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
19531 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
19532 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
19533 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
19534 install_element(BGP_VPNV4_NODE,
19535 &neighbor_maximum_prefix_threshold_warning_cmd);
19536 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
19537 install_element(BGP_VPNV4_NODE,
19538 &neighbor_maximum_prefix_threshold_restart_cmd);
19539 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
19540 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
19541 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
19542 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
19543 install_element(BGP_VPNV6_NODE,
19544 &neighbor_maximum_prefix_threshold_warning_cmd);
19545 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
19546 install_element(BGP_VPNV6_NODE,
19547 &neighbor_maximum_prefix_threshold_restart_cmd);
19548 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
19549
19550 /* "neighbor allowas-in" */
19551 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
19552 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
19553 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
19554 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
19555 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
19556 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
19557 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
19558 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
19559 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
19560 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
19561 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
19562 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
19563 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
19564 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
19565 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
19566 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
19567 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
19568 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
19569 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
19570 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
19571
19572 /* "neighbor dampening" commands. */
19573 install_element(BGP_NODE, &neighbor_damp_cmd);
19574 install_element(BGP_NODE, &no_neighbor_damp_cmd);
19575 install_element(BGP_IPV4_NODE, &neighbor_damp_cmd);
19576 install_element(BGP_IPV4_NODE, &no_neighbor_damp_cmd);
19577 install_element(BGP_IPV4M_NODE, &neighbor_damp_cmd);
19578 install_element(BGP_IPV4M_NODE, &no_neighbor_damp_cmd);
19579 install_element(BGP_IPV4L_NODE, &neighbor_damp_cmd);
19580 install_element(BGP_IPV4L_NODE, &no_neighbor_damp_cmd);
19581 install_element(BGP_IPV6_NODE, &neighbor_damp_cmd);
19582 install_element(BGP_IPV6_NODE, &no_neighbor_damp_cmd);
19583 install_element(BGP_IPV6M_NODE, &neighbor_damp_cmd);
19584 install_element(BGP_IPV6M_NODE, &no_neighbor_damp_cmd);
19585 install_element(BGP_IPV6L_NODE, &neighbor_damp_cmd);
19586 install_element(BGP_IPV6L_NODE, &no_neighbor_damp_cmd);
19587 install_element(VIEW_NODE, &show_ip_bgp_neighbor_damp_param_cmd);
19588
19589 /* address-family commands. */
19590 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
19591 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
19592 #ifdef KEEP_OLD_VPN_COMMANDS
19593 install_element(BGP_NODE, &address_family_vpnv4_cmd);
19594 install_element(BGP_NODE, &address_family_vpnv6_cmd);
19595 #endif /* KEEP_OLD_VPN_COMMANDS */
19596
19597 install_element(BGP_NODE, &address_family_evpn_cmd);
19598
19599 /* "exit-address-family" command. */
19600 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
19601 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
19602 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
19603 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
19604 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
19605 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
19606 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
19607 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
19608 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
19609 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
19610 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
19611
19612 /* "clear ip bgp commands" */
19613 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
19614
19615 /* clear ip bgp prefix */
19616 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
19617 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
19618 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
19619
19620 /* "show [ip] bgp summary" commands. */
19621 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
19622 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
19623 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
19624 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
19625 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
19626 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
19627 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
19628
19629 /* "show [ip] bgp neighbors" commands. */
19630 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
19631
19632 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
19633
19634 /* "show [ip] bgp peer-group" commands. */
19635 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
19636
19637 /* "show [ip] bgp paths" commands. */
19638 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
19639
19640 /* "show [ip] bgp community" commands. */
19641 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
19642
19643 /* "show ip bgp large-community" commands. */
19644 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
19645 /* "show [ip] bgp attribute-info" commands. */
19646 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
19647 /* "show [ip] bgp route-leak" command */
19648 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
19649
19650 /* "redistribute" commands. */
19651 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
19652 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
19653 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
19654 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
19655 install_element(BGP_NODE,
19656 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
19657 install_element(BGP_NODE,
19658 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
19659 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
19660 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
19661 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
19662 install_element(BGP_NODE,
19663 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
19664 install_element(BGP_NODE,
19665 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
19666 install_element(BGP_NODE,
19667 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
19668 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
19669 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
19670 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
19671 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
19672 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
19673 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
19674 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
19675 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
19676 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
19677 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
19678 install_element(BGP_IPV4_NODE,
19679 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
19680 install_element(BGP_IPV4_NODE,
19681 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
19682 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
19683 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
19684 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
19685 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
19686 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
19687 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
19688
19689 /* import|export vpn [route-map WORD] */
19690 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
19691 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
19692
19693 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
19694 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
19695
19696 /* ttl_security commands */
19697 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
19698 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
19699
19700 /* "show [ip] bgp memory" commands. */
19701 install_element(VIEW_NODE, &show_bgp_memory_cmd);
19702
19703 /* "show bgp martian next-hop" */
19704 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
19705
19706 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
19707
19708 /* "show [ip] bgp views" commands. */
19709 install_element(VIEW_NODE, &show_bgp_views_cmd);
19710
19711 /* "show [ip] bgp vrfs" commands. */
19712 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
19713
19714 /* Community-list. */
19715 community_list_vty();
19716
19717 community_alias_vty();
19718
19719 /* vpn-policy commands */
19720 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
19721 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
19722 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
19723 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
19724 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
19725 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
19726 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
19727 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
19728 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
19729 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
19730 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
19731 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
19732
19733 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
19734 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
19735
19736 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
19737 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
19738 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
19739 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
19740 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
19741 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
19742 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
19743 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
19744 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
19745 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
19746
19747 /* tcp-mss command */
19748 install_element(BGP_NODE, &neighbor_tcp_mss_cmd);
19749 install_element(BGP_NODE, &no_neighbor_tcp_mss_cmd);
19750
19751 /* srv6 commands */
19752 install_element(VIEW_NODE, &show_bgp_srv6_cmd);
19753 install_element(BGP_NODE, &bgp_segment_routing_srv6_cmd);
19754 install_element(BGP_SRV6_NODE, &bgp_srv6_locator_cmd);
19755 install_element(BGP_IPV4_NODE, &af_sid_vpn_export_cmd);
19756 install_element(BGP_IPV6_NODE, &af_sid_vpn_export_cmd);
19757 }
19758
19759 #include "memory.h"
19760 #include "bgp_regex.h"
19761 #include "bgp_clist.h"
19762 #include "bgp_ecommunity.h"
19763
19764 /* VTY functions. */
19765
19766 /* Direction value to string conversion. */
19767 static const char *community_direct_str(int direct)
19768 {
19769 switch (direct) {
19770 case COMMUNITY_DENY:
19771 return "deny";
19772 case COMMUNITY_PERMIT:
19773 return "permit";
19774 default:
19775 return "unknown";
19776 }
19777 }
19778
19779 /* Display error string. */
19780 static void community_list_perror(struct vty *vty, int ret)
19781 {
19782 switch (ret) {
19783 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
19784 vty_out(vty, "%% Can't find community-list\n");
19785 break;
19786 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
19787 vty_out(vty, "%% Malformed community-list value\n");
19788 break;
19789 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
19790 vty_out(vty,
19791 "%% Community name conflict, previously defined as standard community\n");
19792 break;
19793 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
19794 vty_out(vty,
19795 "%% Community name conflict, previously defined as expanded community\n");
19796 break;
19797 }
19798 }
19799
19800 /* "community-list" keyword help string. */
19801 #define COMMUNITY_LIST_STR "Add a community list entry\n"
19802
19803 /*community-list standard */
19804 DEFUN (community_list_standard,
19805 bgp_community_list_standard_cmd,
19806 "bgp community-list <(1-99)|standard WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
19807 BGP_STR
19808 COMMUNITY_LIST_STR
19809 "Community list number (standard)\n"
19810 "Add an standard community-list entry\n"
19811 "Community list name\n"
19812 "Sequence number of an entry\n"
19813 "Sequence number\n"
19814 "Specify community to reject\n"
19815 "Specify community to accept\n"
19816 COMMUNITY_VAL_STR)
19817 {
19818 char *cl_name_or_number = NULL;
19819 char *seq = NULL;
19820 int direct = 0;
19821 int style = COMMUNITY_LIST_STANDARD;
19822 int idx = 0;
19823
19824 argv_find(argv, argc, "(0-4294967295)", &idx);
19825 if (idx)
19826 seq = argv[idx]->arg;
19827
19828 idx = 0;
19829 argv_find(argv, argc, "(1-99)", &idx);
19830 argv_find(argv, argc, "WORD", &idx);
19831 cl_name_or_number = argv[idx]->arg;
19832 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19833 : COMMUNITY_DENY;
19834 argv_find(argv, argc, "AA:NN", &idx);
19835 char *str = argv_concat(argv, argc, idx);
19836
19837 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19838 direct, style);
19839
19840 XFREE(MTYPE_TMP, str);
19841
19842 if (ret < 0) {
19843 /* Display error string. */
19844 community_list_perror(vty, ret);
19845 return CMD_WARNING_CONFIG_FAILED;
19846 }
19847
19848 return CMD_SUCCESS;
19849 }
19850
19851 DEFUN (no_community_list_standard_all,
19852 no_bgp_community_list_standard_all_cmd,
19853 "no bgp community-list <(1-99)|standard WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
19854 NO_STR
19855 BGP_STR
19856 COMMUNITY_LIST_STR
19857 "Community list number (standard)\n"
19858 "Add an standard community-list entry\n"
19859 "Community list name\n"
19860 "Sequence number of an entry\n"
19861 "Sequence number\n"
19862 "Specify community to reject\n"
19863 "Specify community to accept\n"
19864 COMMUNITY_VAL_STR)
19865 {
19866 char *cl_name_or_number = NULL;
19867 char *str = NULL;
19868 int direct = 0;
19869 int style = COMMUNITY_LIST_STANDARD;
19870 char *seq = NULL;
19871 int idx = 0;
19872
19873 argv_find(argv, argc, "(0-4294967295)", &idx);
19874 if (idx)
19875 seq = argv[idx]->arg;
19876
19877 idx = 0;
19878 argv_find(argv, argc, "permit", &idx);
19879 argv_find(argv, argc, "deny", &idx);
19880
19881 if (idx) {
19882 direct = argv_find(argv, argc, "permit", &idx)
19883 ? COMMUNITY_PERMIT
19884 : COMMUNITY_DENY;
19885
19886 idx = 0;
19887 argv_find(argv, argc, "AA:NN", &idx);
19888 str = argv_concat(argv, argc, idx);
19889 }
19890
19891 idx = 0;
19892 argv_find(argv, argc, "(1-99)", &idx);
19893 argv_find(argv, argc, "WORD", &idx);
19894 cl_name_or_number = argv[idx]->arg;
19895
19896 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
19897 direct, style);
19898
19899 XFREE(MTYPE_TMP, str);
19900
19901 if (ret < 0) {
19902 community_list_perror(vty, ret);
19903 return CMD_WARNING_CONFIG_FAILED;
19904 }
19905
19906 return CMD_SUCCESS;
19907 }
19908
19909 ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
19910 "no bgp community-list <(1-99)|standard WORD>",
19911 NO_STR BGP_STR COMMUNITY_LIST_STR
19912 "Community list number (standard)\n"
19913 "Add an standard community-list entry\n"
19914 "Community list name\n")
19915
19916 /*community-list expanded */
19917 DEFUN (community_list_expanded_all,
19918 bgp_community_list_expanded_all_cmd,
19919 "bgp community-list <(100-500)|expanded WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
19920 BGP_STR
19921 COMMUNITY_LIST_STR
19922 "Community list number (expanded)\n"
19923 "Add an expanded community-list entry\n"
19924 "Community list name\n"
19925 "Sequence number of an entry\n"
19926 "Sequence number\n"
19927 "Specify community to reject\n"
19928 "Specify community to accept\n"
19929 COMMUNITY_VAL_STR)
19930 {
19931 char *cl_name_or_number = NULL;
19932 char *seq = NULL;
19933 int direct = 0;
19934 int style = COMMUNITY_LIST_EXPANDED;
19935 int idx = 0;
19936
19937 argv_find(argv, argc, "(0-4294967295)", &idx);
19938 if (idx)
19939 seq = argv[idx]->arg;
19940
19941 idx = 0;
19942
19943 argv_find(argv, argc, "(100-500)", &idx);
19944 argv_find(argv, argc, "WORD", &idx);
19945 cl_name_or_number = argv[idx]->arg;
19946 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19947 : COMMUNITY_DENY;
19948 argv_find(argv, argc, "AA:NN", &idx);
19949 char *str = argv_concat(argv, argc, idx);
19950
19951 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19952 direct, style);
19953
19954 XFREE(MTYPE_TMP, str);
19955
19956 if (ret < 0) {
19957 /* Display error string. */
19958 community_list_perror(vty, ret);
19959 return CMD_WARNING_CONFIG_FAILED;
19960 }
19961
19962 return CMD_SUCCESS;
19963 }
19964
19965 DEFUN (no_community_list_expanded_all,
19966 no_bgp_community_list_expanded_all_cmd,
19967 "no bgp community-list <(100-500)|expanded WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
19968 NO_STR
19969 BGP_STR
19970 COMMUNITY_LIST_STR
19971 "Community list number (expanded)\n"
19972 "Add an expanded community-list entry\n"
19973 "Community list name\n"
19974 "Sequence number of an entry\n"
19975 "Sequence number\n"
19976 "Specify community to reject\n"
19977 "Specify community to accept\n"
19978 COMMUNITY_VAL_STR)
19979 {
19980 char *cl_name_or_number = NULL;
19981 char *seq = NULL;
19982 char *str = NULL;
19983 int direct = 0;
19984 int style = COMMUNITY_LIST_EXPANDED;
19985 int idx = 0;
19986
19987 argv_find(argv, argc, "(0-4294967295)", &idx);
19988 if (idx)
19989 seq = argv[idx]->arg;
19990
19991 idx = 0;
19992 argv_find(argv, argc, "permit", &idx);
19993 argv_find(argv, argc, "deny", &idx);
19994
19995 if (idx) {
19996 direct = argv_find(argv, argc, "permit", &idx)
19997 ? COMMUNITY_PERMIT
19998 : COMMUNITY_DENY;
19999
20000 idx = 0;
20001 argv_find(argv, argc, "AA:NN", &idx);
20002 str = argv_concat(argv, argc, idx);
20003 }
20004
20005 idx = 0;
20006 argv_find(argv, argc, "(100-500)", &idx);
20007 argv_find(argv, argc, "WORD", &idx);
20008 cl_name_or_number = argv[idx]->arg;
20009
20010 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
20011 direct, style);
20012
20013 XFREE(MTYPE_TMP, str);
20014
20015 if (ret < 0) {
20016 community_list_perror(vty, ret);
20017 return CMD_WARNING_CONFIG_FAILED;
20018 }
20019
20020 return CMD_SUCCESS;
20021 }
20022
20023 ALIAS(no_community_list_expanded_all,
20024 no_bgp_community_list_expanded_all_list_cmd,
20025 "no bgp community-list <(100-500)|expanded WORD>",
20026 NO_STR BGP_STR COMMUNITY_LIST_STR
20027 "Community list number (expanded)\n"
20028 "Add an expanded community-list entry\n"
20029 "Community list name\n")
20030
20031 /* Return configuration string of community-list entry. */
20032 static const char *community_list_config_str(struct community_entry *entry)
20033 {
20034 const char *str;
20035
20036 if (entry->any)
20037 str = "";
20038 else {
20039 if (entry->style == COMMUNITY_LIST_STANDARD)
20040 str = community_str(entry->u.com, false);
20041 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
20042 str = lcommunity_str(entry->u.lcom, false);
20043 else
20044 str = entry->config;
20045 }
20046 return str;
20047 }
20048
20049 static void community_list_show(struct vty *vty, struct community_list *list)
20050 {
20051 struct community_entry *entry;
20052
20053 for (entry = list->head; entry; entry = entry->next) {
20054 if (entry == list->head) {
20055 if (all_digit(list->name))
20056 vty_out(vty, "Community %s list %s\n",
20057 entry->style == COMMUNITY_LIST_STANDARD
20058 ? "standard"
20059 : "(expanded) access",
20060 list->name);
20061 else
20062 vty_out(vty, "Named Community %s list %s\n",
20063 entry->style == COMMUNITY_LIST_STANDARD
20064 ? "standard"
20065 : "expanded",
20066 list->name);
20067 }
20068 if (entry->any)
20069 vty_out(vty, " %s\n",
20070 community_direct_str(entry->direct));
20071 else
20072 vty_out(vty, " %s %s\n",
20073 community_direct_str(entry->direct),
20074 community_list_config_str(entry));
20075 }
20076 }
20077
20078 DEFUN (show_community_list,
20079 show_bgp_community_list_cmd,
20080 "show bgp community-list",
20081 SHOW_STR
20082 BGP_STR
20083 "List community-list\n")
20084 {
20085 struct community_list *list;
20086 struct community_list_master *cm;
20087
20088 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
20089 if (!cm)
20090 return CMD_SUCCESS;
20091
20092 for (list = cm->num.head; list; list = list->next)
20093 community_list_show(vty, list);
20094
20095 for (list = cm->str.head; list; list = list->next)
20096 community_list_show(vty, list);
20097
20098 return CMD_SUCCESS;
20099 }
20100
20101 DEFUN (show_community_list_arg,
20102 show_bgp_community_list_arg_cmd,
20103 "show bgp community-list <(1-500)|WORD> detail",
20104 SHOW_STR
20105 BGP_STR
20106 "List community-list\n"
20107 "Community-list number\n"
20108 "Community-list name\n"
20109 "Detailed information on community-list\n")
20110 {
20111 int idx_comm_list = 3;
20112 struct community_list *list;
20113
20114 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
20115 COMMUNITY_LIST_MASTER);
20116 if (!list) {
20117 vty_out(vty, "%% Can't find community-list\n");
20118 return CMD_WARNING;
20119 }
20120
20121 community_list_show(vty, list);
20122
20123 return CMD_SUCCESS;
20124 }
20125
20126 /*
20127 * Large Community code.
20128 */
20129 static int lcommunity_list_set_vty(struct vty *vty, int argc,
20130 struct cmd_token **argv, int style,
20131 int reject_all_digit_name)
20132 {
20133 int ret;
20134 int direct;
20135 char *str;
20136 int idx = 0;
20137 char *cl_name;
20138 char *seq = NULL;
20139
20140 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20141 seq = argv[idx]->arg;
20142
20143 idx = 0;
20144 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20145 : COMMUNITY_DENY;
20146
20147 /* All digit name check. */
20148 idx = 0;
20149 argv_find(argv, argc, "WORD", &idx);
20150 argv_find(argv, argc, "(1-99)", &idx);
20151 argv_find(argv, argc, "(100-500)", &idx);
20152 cl_name = argv[idx]->arg;
20153 if (reject_all_digit_name && all_digit(cl_name)) {
20154 vty_out(vty, "%% Community name cannot have all digits\n");
20155 return CMD_WARNING_CONFIG_FAILED;
20156 }
20157
20158 idx = 0;
20159 argv_find(argv, argc, "AA:BB:CC", &idx);
20160 argv_find(argv, argc, "LINE", &idx);
20161 /* Concat community string argument. */
20162 if (idx)
20163 str = argv_concat(argv, argc, idx);
20164 else
20165 str = NULL;
20166
20167 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
20168
20169 /* Free temporary community list string allocated by
20170 argv_concat(). */
20171 XFREE(MTYPE_TMP, str);
20172
20173 if (ret < 0) {
20174 community_list_perror(vty, ret);
20175 return CMD_WARNING_CONFIG_FAILED;
20176 }
20177 return CMD_SUCCESS;
20178 }
20179
20180 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
20181 struct cmd_token **argv, int style)
20182 {
20183 int ret;
20184 int direct = 0;
20185 char *str = NULL;
20186 int idx = 0;
20187 char *seq = NULL;
20188
20189 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20190 seq = argv[idx]->arg;
20191
20192 idx = 0;
20193 argv_find(argv, argc, "permit", &idx);
20194 argv_find(argv, argc, "deny", &idx);
20195
20196 if (idx) {
20197 /* Check the list direct. */
20198 if (strncmp(argv[idx]->arg, "p", 1) == 0)
20199 direct = COMMUNITY_PERMIT;
20200 else
20201 direct = COMMUNITY_DENY;
20202
20203 idx = 0;
20204 argv_find(argv, argc, "LINE", &idx);
20205 argv_find(argv, argc, "AA:AA:NN", &idx);
20206 /* Concat community string argument. */
20207 str = argv_concat(argv, argc, idx);
20208 }
20209
20210 idx = 0;
20211 argv_find(argv, argc, "(1-99)", &idx);
20212 argv_find(argv, argc, "(100-500)", &idx);
20213 argv_find(argv, argc, "WORD", &idx);
20214
20215 /* Unset community list. */
20216 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
20217 style);
20218
20219 /* Free temporary community list string allocated by
20220 argv_concat(). */
20221 XFREE(MTYPE_TMP, str);
20222
20223 if (ret < 0) {
20224 community_list_perror(vty, ret);
20225 return CMD_WARNING_CONFIG_FAILED;
20226 }
20227
20228 return CMD_SUCCESS;
20229 }
20230
20231 /* "large-community-list" keyword help string. */
20232 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
20233 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
20234
20235 DEFUN (lcommunity_list_standard,
20236 bgp_lcommunity_list_standard_cmd,
20237 "bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
20238 BGP_STR
20239 LCOMMUNITY_LIST_STR
20240 "Large Community list number (standard)\n"
20241 "Sequence number of an entry\n"
20242 "Sequence number\n"
20243 "Specify large community to reject\n"
20244 "Specify large community to accept\n"
20245 LCOMMUNITY_VAL_STR)
20246 {
20247 return lcommunity_list_set_vty(vty, argc, argv,
20248 LARGE_COMMUNITY_LIST_STANDARD, 0);
20249 }
20250
20251 DEFUN (lcommunity_list_expanded,
20252 bgp_lcommunity_list_expanded_cmd,
20253 "bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
20254 BGP_STR
20255 LCOMMUNITY_LIST_STR
20256 "Large Community list number (expanded)\n"
20257 "Sequence number of an entry\n"
20258 "Sequence number\n"
20259 "Specify large community to reject\n"
20260 "Specify large community to accept\n"
20261 "An ordered list as a regular-expression\n")
20262 {
20263 return lcommunity_list_set_vty(vty, argc, argv,
20264 LARGE_COMMUNITY_LIST_EXPANDED, 0);
20265 }
20266
20267 DEFUN (lcommunity_list_name_standard,
20268 bgp_lcommunity_list_name_standard_cmd,
20269 "bgp large-community-list standard WORD [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
20270 BGP_STR
20271 LCOMMUNITY_LIST_STR
20272 "Specify standard large-community-list\n"
20273 "Large Community list name\n"
20274 "Sequence number of an entry\n"
20275 "Sequence number\n"
20276 "Specify large community to reject\n"
20277 "Specify large community to accept\n"
20278 LCOMMUNITY_VAL_STR)
20279 {
20280 return lcommunity_list_set_vty(vty, argc, argv,
20281 LARGE_COMMUNITY_LIST_STANDARD, 1);
20282 }
20283
20284 DEFUN (lcommunity_list_name_expanded,
20285 bgp_lcommunity_list_name_expanded_cmd,
20286 "bgp large-community-list expanded WORD [seq (0-4294967295)] <deny|permit> LINE...",
20287 BGP_STR
20288 LCOMMUNITY_LIST_STR
20289 "Specify expanded large-community-list\n"
20290 "Large Community list name\n"
20291 "Sequence number of an entry\n"
20292 "Sequence number\n"
20293 "Specify large community to reject\n"
20294 "Specify large community to accept\n"
20295 "An ordered list as a regular-expression\n")
20296 {
20297 return lcommunity_list_set_vty(vty, argc, argv,
20298 LARGE_COMMUNITY_LIST_EXPANDED, 1);
20299 }
20300
20301 DEFUN (no_lcommunity_list_all,
20302 no_bgp_lcommunity_list_all_cmd,
20303 "no bgp large-community-list <(1-99)|(100-500)|WORD>",
20304 NO_STR
20305 BGP_STR
20306 LCOMMUNITY_LIST_STR
20307 "Large Community list number (standard)\n"
20308 "Large Community list number (expanded)\n"
20309 "Large Community list name\n")
20310 {
20311 return lcommunity_list_unset_vty(vty, argc, argv,
20312 LARGE_COMMUNITY_LIST_STANDARD);
20313 }
20314
20315 DEFUN (no_lcommunity_list_name_standard_all,
20316 no_bgp_lcommunity_list_name_standard_all_cmd,
20317 "no bgp large-community-list standard WORD",
20318 NO_STR
20319 BGP_STR
20320 LCOMMUNITY_LIST_STR
20321 "Specify standard large-community-list\n"
20322 "Large Community list name\n")
20323 {
20324 return lcommunity_list_unset_vty(vty, argc, argv,
20325 LARGE_COMMUNITY_LIST_STANDARD);
20326 }
20327
20328 DEFUN (no_lcommunity_list_name_expanded_all,
20329 no_bgp_lcommunity_list_name_expanded_all_cmd,
20330 "no bgp large-community-list expanded WORD",
20331 NO_STR
20332 BGP_STR
20333 LCOMMUNITY_LIST_STR
20334 "Specify expanded large-community-list\n"
20335 "Large Community list name\n")
20336 {
20337 return lcommunity_list_unset_vty(vty, argc, argv,
20338 LARGE_COMMUNITY_LIST_EXPANDED);
20339 }
20340
20341 DEFUN (no_lcommunity_list_standard,
20342 no_bgp_lcommunity_list_standard_cmd,
20343 "no bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
20344 NO_STR
20345 BGP_STR
20346 LCOMMUNITY_LIST_STR
20347 "Large Community list number (standard)\n"
20348 "Sequence number of an entry\n"
20349 "Sequence number\n"
20350 "Specify large community to reject\n"
20351 "Specify large community to accept\n"
20352 LCOMMUNITY_VAL_STR)
20353 {
20354 return lcommunity_list_unset_vty(vty, argc, argv,
20355 LARGE_COMMUNITY_LIST_STANDARD);
20356 }
20357
20358 DEFUN (no_lcommunity_list_expanded,
20359 no_bgp_lcommunity_list_expanded_cmd,
20360 "no bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
20361 NO_STR
20362 BGP_STR
20363 LCOMMUNITY_LIST_STR
20364 "Large Community list number (expanded)\n"
20365 "Sequence number of an entry\n"
20366 "Sequence number\n"
20367 "Specify large community to reject\n"
20368 "Specify large community to accept\n"
20369 "An ordered list as a regular-expression\n")
20370 {
20371 return lcommunity_list_unset_vty(vty, argc, argv,
20372 LARGE_COMMUNITY_LIST_EXPANDED);
20373 }
20374
20375 DEFUN (no_lcommunity_list_name_standard,
20376 no_bgp_lcommunity_list_name_standard_cmd,
20377 "no bgp large-community-list standard WORD [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
20378 NO_STR
20379 BGP_STR
20380 LCOMMUNITY_LIST_STR
20381 "Specify standard large-community-list\n"
20382 "Large Community list name\n"
20383 "Sequence number of an entry\n"
20384 "Sequence number\n"
20385 "Specify large community to reject\n"
20386 "Specify large community to accept\n"
20387 LCOMMUNITY_VAL_STR)
20388 {
20389 return lcommunity_list_unset_vty(vty, argc, argv,
20390 LARGE_COMMUNITY_LIST_STANDARD);
20391 }
20392
20393 DEFUN (no_lcommunity_list_name_expanded,
20394 no_bgp_lcommunity_list_name_expanded_cmd,
20395 "no bgp large-community-list expanded WORD [seq (0-4294967295)] <deny|permit> LINE...",
20396 NO_STR
20397 BGP_STR
20398 LCOMMUNITY_LIST_STR
20399 "Specify expanded large-community-list\n"
20400 "Large community list name\n"
20401 "Sequence number of an entry\n"
20402 "Sequence number\n"
20403 "Specify large community to reject\n"
20404 "Specify large community to accept\n"
20405 "An ordered list as a regular-expression\n")
20406 {
20407 return lcommunity_list_unset_vty(vty, argc, argv,
20408 LARGE_COMMUNITY_LIST_EXPANDED);
20409 }
20410
20411 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
20412 {
20413 struct community_entry *entry;
20414
20415 for (entry = list->head; entry; entry = entry->next) {
20416 if (entry == list->head) {
20417 if (all_digit(list->name))
20418 vty_out(vty, "Large community %s list %s\n",
20419 entry->style ==
20420 LARGE_COMMUNITY_LIST_STANDARD
20421 ? "standard"
20422 : "(expanded) access",
20423 list->name);
20424 else
20425 vty_out(vty,
20426 "Named large community %s list %s\n",
20427 entry->style ==
20428 LARGE_COMMUNITY_LIST_STANDARD
20429 ? "standard"
20430 : "expanded",
20431 list->name);
20432 }
20433 if (entry->any)
20434 vty_out(vty, " %s\n",
20435 community_direct_str(entry->direct));
20436 else
20437 vty_out(vty, " %s %s\n",
20438 community_direct_str(entry->direct),
20439 community_list_config_str(entry));
20440 }
20441 }
20442
20443 DEFUN (show_lcommunity_list,
20444 show_bgp_lcommunity_list_cmd,
20445 "show bgp large-community-list",
20446 SHOW_STR
20447 BGP_STR
20448 "List large-community list\n")
20449 {
20450 struct community_list *list;
20451 struct community_list_master *cm;
20452
20453 cm = community_list_master_lookup(bgp_clist,
20454 LARGE_COMMUNITY_LIST_MASTER);
20455 if (!cm)
20456 return CMD_SUCCESS;
20457
20458 for (list = cm->num.head; list; list = list->next)
20459 lcommunity_list_show(vty, list);
20460
20461 for (list = cm->str.head; list; list = list->next)
20462 lcommunity_list_show(vty, list);
20463
20464 return CMD_SUCCESS;
20465 }
20466
20467 DEFUN (show_lcommunity_list_arg,
20468 show_bgp_lcommunity_list_arg_cmd,
20469 "show bgp large-community-list <(1-500)|WORD> detail",
20470 SHOW_STR
20471 BGP_STR
20472 "List large-community list\n"
20473 "Large-community-list number\n"
20474 "Large-community-list name\n"
20475 "Detailed information on large-community-list\n")
20476 {
20477 struct community_list *list;
20478
20479 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
20480 LARGE_COMMUNITY_LIST_MASTER);
20481 if (!list) {
20482 vty_out(vty, "%% Can't find large-community-list\n");
20483 return CMD_WARNING;
20484 }
20485
20486 lcommunity_list_show(vty, list);
20487
20488 return CMD_SUCCESS;
20489 }
20490
20491 /* "extcommunity-list" keyword help string. */
20492 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
20493 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
20494
20495 DEFUN (extcommunity_list_standard,
20496 bgp_extcommunity_list_standard_cmd,
20497 "bgp extcommunity-list <(1-99)|standard WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
20498 BGP_STR
20499 EXTCOMMUNITY_LIST_STR
20500 "Extended Community list number (standard)\n"
20501 "Specify standard extcommunity-list\n"
20502 "Community list name\n"
20503 "Sequence number of an entry\n"
20504 "Sequence number\n"
20505 "Specify community to reject\n"
20506 "Specify community to accept\n"
20507 EXTCOMMUNITY_VAL_STR)
20508 {
20509 int style = EXTCOMMUNITY_LIST_STANDARD;
20510 int direct = 0;
20511 char *cl_number_or_name = NULL;
20512 char *seq = NULL;
20513
20514 int idx = 0;
20515
20516 argv_find(argv, argc, "(1-99)", &idx);
20517 argv_find(argv, argc, "WORD", &idx);
20518 cl_number_or_name = argv[idx]->arg;
20519
20520 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20521 seq = argv[idx]->arg;
20522
20523 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20524 : COMMUNITY_DENY;
20525 argv_find(argv, argc, "AA:NN", &idx);
20526 char *str = argv_concat(argv, argc, idx);
20527
20528 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
20529 direct, style);
20530
20531 XFREE(MTYPE_TMP, str);
20532
20533 if (ret < 0) {
20534 community_list_perror(vty, ret);
20535 return CMD_WARNING_CONFIG_FAILED;
20536 }
20537
20538 return CMD_SUCCESS;
20539 }
20540
20541 DEFUN (extcommunity_list_name_expanded,
20542 bgp_extcommunity_list_name_expanded_cmd,
20543 "bgp extcommunity-list <(100-500)|expanded WORD> [seq (0-4294967295)] <deny|permit> LINE...",
20544 BGP_STR
20545 EXTCOMMUNITY_LIST_STR
20546 "Extended Community list number (expanded)\n"
20547 "Specify expanded extcommunity-list\n"
20548 "Extended Community list name\n"
20549 "Sequence number of an entry\n"
20550 "Sequence number\n"
20551 "Specify community to reject\n"
20552 "Specify community to accept\n"
20553 "An ordered list as a regular-expression\n")
20554 {
20555 int style = EXTCOMMUNITY_LIST_EXPANDED;
20556 int direct = 0;
20557 char *cl_number_or_name = NULL;
20558 char *seq = NULL;
20559 int idx = 0;
20560
20561 argv_find(argv, argc, "(100-500)", &idx);
20562 argv_find(argv, argc, "WORD", &idx);
20563 cl_number_or_name = argv[idx]->arg;
20564
20565 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20566 seq = argv[idx]->arg;
20567
20568 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20569 : COMMUNITY_DENY;
20570 argv_find(argv, argc, "LINE", &idx);
20571 char *str = argv_concat(argv, argc, idx);
20572
20573 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
20574 direct, style);
20575
20576 XFREE(MTYPE_TMP, str);
20577
20578 if (ret < 0) {
20579 community_list_perror(vty, ret);
20580 return CMD_WARNING_CONFIG_FAILED;
20581 }
20582
20583 return CMD_SUCCESS;
20584 }
20585
20586 DEFUN (no_extcommunity_list_standard_all,
20587 no_bgp_extcommunity_list_standard_all_cmd,
20588 "no bgp extcommunity-list <(1-99)|standard WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
20589 NO_STR
20590 BGP_STR
20591 EXTCOMMUNITY_LIST_STR
20592 "Extended Community list number (standard)\n"
20593 "Specify standard extcommunity-list\n"
20594 "Community list name\n"
20595 "Sequence number of an entry\n"
20596 "Sequence number\n"
20597 "Specify community to reject\n"
20598 "Specify community to accept\n"
20599 EXTCOMMUNITY_VAL_STR)
20600 {
20601 int style = EXTCOMMUNITY_LIST_STANDARD;
20602 int direct = 0;
20603 char *cl_number_or_name = NULL;
20604 char *str = NULL;
20605 char *seq = NULL;
20606 int idx = 0;
20607
20608 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20609 seq = argv[idx]->arg;
20610
20611 idx = 0;
20612 argv_find(argv, argc, "permit", &idx);
20613 argv_find(argv, argc, "deny", &idx);
20614 if (idx) {
20615 direct = argv_find(argv, argc, "permit", &idx)
20616 ? COMMUNITY_PERMIT
20617 : COMMUNITY_DENY;
20618
20619 idx = 0;
20620 argv_find(argv, argc, "AA:NN", &idx);
20621 str = argv_concat(argv, argc, idx);
20622 }
20623
20624 idx = 0;
20625 argv_find(argv, argc, "(1-99)", &idx);
20626 argv_find(argv, argc, "WORD", &idx);
20627 cl_number_or_name = argv[idx]->arg;
20628
20629 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
20630 seq, direct, style);
20631
20632 XFREE(MTYPE_TMP, str);
20633
20634 if (ret < 0) {
20635 community_list_perror(vty, ret);
20636 return CMD_WARNING_CONFIG_FAILED;
20637 }
20638
20639 return CMD_SUCCESS;
20640 }
20641
20642 ALIAS(no_extcommunity_list_standard_all,
20643 no_bgp_extcommunity_list_standard_all_list_cmd,
20644 "no bgp extcommunity-list <(1-99)|standard WORD>",
20645 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
20646 "Extended Community list number (standard)\n"
20647 "Specify standard extcommunity-list\n"
20648 "Community list name\n")
20649
20650 DEFUN (no_extcommunity_list_expanded_all,
20651 no_bgp_extcommunity_list_expanded_all_cmd,
20652 "no bgp extcommunity-list <(100-500)|expanded WORD> [seq (0-4294967295)] <deny|permit> LINE...",
20653 NO_STR
20654 BGP_STR
20655 EXTCOMMUNITY_LIST_STR
20656 "Extended Community list number (expanded)\n"
20657 "Specify expanded extcommunity-list\n"
20658 "Extended Community list name\n"
20659 "Sequence number of an entry\n"
20660 "Sequence number\n"
20661 "Specify community to reject\n"
20662 "Specify community to accept\n"
20663 "An ordered list as a regular-expression\n")
20664 {
20665 int style = EXTCOMMUNITY_LIST_EXPANDED;
20666 int direct = 0;
20667 char *cl_number_or_name = NULL;
20668 char *str = NULL;
20669 char *seq = NULL;
20670 int idx = 0;
20671
20672 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20673 seq = argv[idx]->arg;
20674
20675 idx = 0;
20676 argv_find(argv, argc, "permit", &idx);
20677 argv_find(argv, argc, "deny", &idx);
20678
20679 if (idx) {
20680 direct = argv_find(argv, argc, "permit", &idx)
20681 ? COMMUNITY_PERMIT
20682 : COMMUNITY_DENY;
20683
20684 idx = 0;
20685 argv_find(argv, argc, "LINE", &idx);
20686 str = argv_concat(argv, argc, idx);
20687 }
20688
20689 idx = 0;
20690 argv_find(argv, argc, "(100-500)", &idx);
20691 argv_find(argv, argc, "WORD", &idx);
20692 cl_number_or_name = argv[idx]->arg;
20693
20694 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
20695 seq, direct, style);
20696
20697 XFREE(MTYPE_TMP, str);
20698
20699 if (ret < 0) {
20700 community_list_perror(vty, ret);
20701 return CMD_WARNING_CONFIG_FAILED;
20702 }
20703
20704 return CMD_SUCCESS;
20705 }
20706
20707 ALIAS(no_extcommunity_list_expanded_all,
20708 no_bgp_extcommunity_list_expanded_all_list_cmd,
20709 "no bgp extcommunity-list <(100-500)|expanded WORD>",
20710 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
20711 "Extended Community list number (expanded)\n"
20712 "Specify expanded extcommunity-list\n"
20713 "Extended Community list name\n")
20714
20715 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
20716 {
20717 struct community_entry *entry;
20718
20719 for (entry = list->head; entry; entry = entry->next) {
20720 if (entry == list->head) {
20721 if (all_digit(list->name))
20722 vty_out(vty, "Extended community %s list %s\n",
20723 entry->style == EXTCOMMUNITY_LIST_STANDARD
20724 ? "standard"
20725 : "(expanded) access",
20726 list->name);
20727 else
20728 vty_out(vty,
20729 "Named extended community %s list %s\n",
20730 entry->style == EXTCOMMUNITY_LIST_STANDARD
20731 ? "standard"
20732 : "expanded",
20733 list->name);
20734 }
20735 if (entry->any)
20736 vty_out(vty, " %s\n",
20737 community_direct_str(entry->direct));
20738 else
20739 vty_out(vty, " %s %s\n",
20740 community_direct_str(entry->direct),
20741 community_list_config_str(entry));
20742 }
20743 }
20744
20745 DEFUN (show_extcommunity_list,
20746 show_bgp_extcommunity_list_cmd,
20747 "show bgp extcommunity-list",
20748 SHOW_STR
20749 BGP_STR
20750 "List extended-community list\n")
20751 {
20752 struct community_list *list;
20753 struct community_list_master *cm;
20754
20755 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
20756 if (!cm)
20757 return CMD_SUCCESS;
20758
20759 for (list = cm->num.head; list; list = list->next)
20760 extcommunity_list_show(vty, list);
20761
20762 for (list = cm->str.head; list; list = list->next)
20763 extcommunity_list_show(vty, list);
20764
20765 return CMD_SUCCESS;
20766 }
20767
20768 DEFUN (show_extcommunity_list_arg,
20769 show_bgp_extcommunity_list_arg_cmd,
20770 "show bgp extcommunity-list <(1-500)|WORD> detail",
20771 SHOW_STR
20772 BGP_STR
20773 "List extended-community list\n"
20774 "Extcommunity-list number\n"
20775 "Extcommunity-list name\n"
20776 "Detailed information on extcommunity-list\n")
20777 {
20778 int idx_comm_list = 3;
20779 struct community_list *list;
20780
20781 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
20782 EXTCOMMUNITY_LIST_MASTER);
20783 if (!list) {
20784 vty_out(vty, "%% Can't find extcommunity-list\n");
20785 return CMD_WARNING;
20786 }
20787
20788 extcommunity_list_show(vty, list);
20789
20790 return CMD_SUCCESS;
20791 }
20792
20793 /* Display community-list and extcommunity-list configuration. */
20794 static int community_list_config_write(struct vty *vty)
20795 {
20796 struct community_list *list;
20797 struct community_entry *entry;
20798 struct community_list_master *cm;
20799 int write = 0;
20800
20801 /* Community-list. */
20802 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
20803
20804 for (list = cm->num.head; list; list = list->next)
20805 for (entry = list->head; entry; entry = entry->next) {
20806 vty_out(vty,
20807 "bgp community-list %s seq %" PRId64 " %s %s\n",
20808 list->name, entry->seq,
20809 community_direct_str(entry->direct),
20810 community_list_config_str(entry));
20811 write++;
20812 }
20813 for (list = cm->str.head; list; list = list->next)
20814 for (entry = list->head; entry; entry = entry->next) {
20815 vty_out(vty,
20816 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
20817 entry->style == COMMUNITY_LIST_STANDARD
20818 ? "standard"
20819 : "expanded",
20820 list->name, entry->seq,
20821 community_direct_str(entry->direct),
20822 community_list_config_str(entry));
20823 write++;
20824 }
20825
20826 /* Extcommunity-list. */
20827 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
20828
20829 for (list = cm->num.head; list; list = list->next)
20830 for (entry = list->head; entry; entry = entry->next) {
20831 vty_out(vty,
20832 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
20833 list->name, entry->seq,
20834 community_direct_str(entry->direct),
20835 community_list_config_str(entry));
20836 write++;
20837 }
20838 for (list = cm->str.head; list; list = list->next)
20839 for (entry = list->head; entry; entry = entry->next) {
20840 vty_out(vty,
20841 "bgp extcommunity-list %s %s seq %" PRId64" %s %s\n",
20842 entry->style == EXTCOMMUNITY_LIST_STANDARD
20843 ? "standard"
20844 : "expanded",
20845 list->name, entry->seq,
20846 community_direct_str(entry->direct),
20847 community_list_config_str(entry));
20848 write++;
20849 }
20850
20851
20852 /* lcommunity-list. */
20853 cm = community_list_master_lookup(bgp_clist,
20854 LARGE_COMMUNITY_LIST_MASTER);
20855
20856 for (list = cm->num.head; list; list = list->next)
20857 for (entry = list->head; entry; entry = entry->next) {
20858 vty_out(vty,
20859 "bgp large-community-list %s seq %" PRId64" %s %s\n",
20860 list->name, entry->seq,
20861 community_direct_str(entry->direct),
20862 community_list_config_str(entry));
20863 write++;
20864 }
20865 for (list = cm->str.head; list; list = list->next)
20866 for (entry = list->head; entry; entry = entry->next) {
20867 vty_out(vty,
20868 "bgp large-community-list %s %s seq %" PRId64" %s %s\n",
20869
20870 entry->style == LARGE_COMMUNITY_LIST_STANDARD
20871 ? "standard"
20872 : "expanded",
20873 list->name, entry->seq, community_direct_str(entry->direct),
20874 community_list_config_str(entry));
20875 write++;
20876 }
20877
20878 return write;
20879 }
20880
20881 static int community_list_config_write(struct vty *vty);
20882 static struct cmd_node community_list_node = {
20883 .name = "community list",
20884 .node = COMMUNITY_LIST_NODE,
20885 .prompt = "",
20886 .config_write = community_list_config_write,
20887 };
20888
20889 static void community_list_vty(void)
20890 {
20891 install_node(&community_list_node);
20892
20893 /* Community-list. */
20894 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
20895 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
20896 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
20897 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
20898 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
20899 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
20900 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
20901 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
20902
20903 /* Extcommunity-list. */
20904 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
20905 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
20906 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
20907 install_element(CONFIG_NODE,
20908 &no_bgp_extcommunity_list_standard_all_list_cmd);
20909 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
20910 install_element(CONFIG_NODE,
20911 &no_bgp_extcommunity_list_expanded_all_list_cmd);
20912 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
20913 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
20914
20915 /* Large Community List */
20916 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
20917 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
20918 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
20919 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
20920 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
20921 install_element(CONFIG_NODE,
20922 &no_bgp_lcommunity_list_name_standard_all_cmd);
20923 install_element(CONFIG_NODE,
20924 &no_bgp_lcommunity_list_name_expanded_all_cmd);
20925 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
20926 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
20927 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
20928 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
20929 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
20930 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
20931 }
20932
20933 static struct cmd_node community_alias_node = {
20934 .name = "community alias",
20935 .node = COMMUNITY_ALIAS_NODE,
20936 .prompt = "",
20937 .config_write = bgp_community_alias_write,
20938 };
20939
20940 void community_alias_vty(void)
20941 {
20942 install_node(&community_alias_node);
20943
20944 /* Community-list. */
20945 install_element(CONFIG_NODE, &bgp_community_alias_cmd);
20946 }