]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
Merge pull request #8942 from ton31337/fix/cleanups_2
[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 med_admin_val = yang_dnode_get_uint32(dnode, "./max-med-admin");
1861 if (med_admin_val != BGP_MAXMED_VALUE_DEFAULT)
1862 vty_out(vty, " %u", med_admin_val);
1863 vty_out(vty, "\n");
1864 }
1865
1866 if (yang_dnode_exists(dnode, "./max-med-onstart-up-time")) {
1867 uint32_t onstartup_val;
1868
1869 vty_out(vty, " bgp max-med on-startup %u",
1870 yang_dnode_get_uint32(dnode,
1871 "./max-med-onstart-up-time"));
1872 onstartup_val = yang_dnode_get_uint32(
1873 dnode, "./max-med-onstart-up-value");
1874 if (onstartup_val != BGP_MAXMED_VALUE_DEFAULT)
1875 vty_out(vty, " %u", onstartup_val);
1876
1877 vty_out(vty, "\n");
1878 }
1879 }
1880
1881 DEFUN_YANG(bgp_maxmed_admin,
1882 bgp_maxmed_admin_cmd,
1883 "bgp max-med administrative ",
1884 BGP_STR
1885 "Advertise routes with max-med\n"
1886 "Administratively applied, for an indefinite period\n")
1887 {
1888 nb_cli_enqueue_change(vty, "./global/med-config/enable-med-admin",
1889 NB_OP_MODIFY, "true");
1890
1891 return nb_cli_apply_changes(vty, NULL);
1892 }
1893
1894 DEFUN_YANG(bgp_maxmed_admin_medv,
1895 bgp_maxmed_admin_medv_cmd,
1896 "bgp max-med administrative (0-4294967295)",
1897 BGP_STR
1898 "Advertise routes with max-med\n"
1899 "Administratively applied, for an indefinite period\n"
1900 "Max MED value to be used\n")
1901 {
1902 int idx_number = 3;
1903
1904 nb_cli_enqueue_change(vty, "./global/med-config/enable-med-admin",
1905 NB_OP_MODIFY, "true");
1906
1907 nb_cli_enqueue_change(vty, "./global/med-config/max-med-admin",
1908 NB_OP_MODIFY, argv[idx_number]->arg);
1909
1910 return nb_cli_apply_changes(vty, NULL);
1911 }
1912
1913 DEFUN_YANG(no_bgp_maxmed_admin,
1914 no_bgp_maxmed_admin_cmd,
1915 "no bgp max-med administrative [(0-4294967295)]",
1916 NO_STR BGP_STR
1917 "Advertise routes with max-med\n"
1918 "Administratively applied, for an indefinite period\n"
1919 "Max MED value to be used\n")
1920 {
1921 nb_cli_enqueue_change(vty, "./global/med-config/enable-med-admin",
1922 NB_OP_MODIFY, "false");
1923
1924 nb_cli_enqueue_change(vty, "./global/med-config/max-med-admin",
1925 NB_OP_MODIFY, NULL);
1926
1927 return nb_cli_apply_changes(vty, NULL);
1928 }
1929
1930 DEFUN_YANG (bgp_maxmed_onstartup,
1931 bgp_maxmed_onstartup_cmd,
1932 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
1933 BGP_STR
1934 "Advertise routes with max-med\n"
1935 "Effective on a startup\n"
1936 "Time (seconds) period for max-med\n"
1937 "Max MED value to be used\n")
1938 {
1939 int idx = 0;
1940
1941 argv_find(argv, argc, "(5-86400)", &idx);
1942 nb_cli_enqueue_change(vty,
1943 "./global/med-config/max-med-onstart-up-time",
1944 NB_OP_MODIFY, argv[idx]->arg);
1945
1946 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1947 nb_cli_enqueue_change(
1948 vty, "./global/med-config/max-med-onstart-up-value",
1949 NB_OP_MODIFY, argv[idx]->arg);
1950 else
1951 nb_cli_enqueue_change(
1952 vty, "./global/med-config/max-med-onstart-up-value",
1953 NB_OP_MODIFY, NULL);
1954
1955 return nb_cli_apply_changes(vty, NULL);
1956 }
1957
1958 DEFUN_YANG (no_bgp_maxmed_onstartup,
1959 no_bgp_maxmed_onstartup_cmd,
1960 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
1961 NO_STR BGP_STR
1962 "Advertise routes with max-med\n"
1963 "Effective on a startup\n"
1964 "Time (seconds) period for max-med\n"
1965 "Max MED value to be used\n")
1966 {
1967 nb_cli_enqueue_change(vty,
1968 "./global/med-config/max-med-onstart-up-time",
1969 NB_OP_DESTROY, NULL);
1970
1971 nb_cli_enqueue_change(vty,
1972 "./global/med-config/max-med-onstart-up-value",
1973 NB_OP_MODIFY, NULL);
1974
1975 return nb_cli_apply_changes(vty, NULL);
1976 }
1977
1978 static int bgp_global_update_delay_config_vty(struct vty *vty,
1979 uint16_t update_delay,
1980 uint16_t establish_wait)
1981 {
1982 struct listnode *node, *nnode;
1983 struct bgp *bgp;
1984 bool vrf_cfg = false;
1985
1986 /*
1987 * See if update-delay is set per-vrf and warn user to delete it
1988 * Note that we only need to check this if this is the first time
1989 * setting the global config.
1990 */
1991 if (bm->v_update_delay == BGP_UPDATE_DELAY_DEF) {
1992 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
1993 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1994 vty_out(vty,
1995 "%% update-delay configuration found in vrf %s\n",
1996 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT
1997 ? VRF_DEFAULT_NAME
1998 : bgp->name);
1999 vrf_cfg = true;
2000 }
2001 }
2002 }
2003
2004 if (vrf_cfg) {
2005 vty_out(vty,
2006 "%%Failed: global update-delay config not permitted\n");
2007 return CMD_WARNING;
2008 }
2009
2010 if (!establish_wait) { /* update-delay <delay> */
2011 bm->v_update_delay = update_delay;
2012 bm->v_establish_wait = bm->v_update_delay;
2013 } else {
2014 /* update-delay <delay> <establish-wait> */
2015 if (update_delay < establish_wait) {
2016 vty_out(vty,
2017 "%%Failed: update-delay less than the establish-wait!\n");
2018 return CMD_WARNING_CONFIG_FAILED;
2019 }
2020
2021 bm->v_update_delay = update_delay;
2022 bm->v_establish_wait = establish_wait;
2023 }
2024
2025 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2026 bgp->v_update_delay = bm->v_update_delay;
2027 bgp->v_establish_wait = bm->v_establish_wait;
2028 }
2029
2030 return CMD_SUCCESS;
2031 }
2032
2033 static int bgp_global_update_delay_deconfig_vty(struct vty *vty)
2034 {
2035 struct listnode *node, *nnode;
2036 struct bgp *bgp;
2037
2038 bm->v_update_delay = BGP_UPDATE_DELAY_DEF;
2039 bm->v_establish_wait = bm->v_update_delay;
2040
2041 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2042 bgp->v_update_delay = bm->v_update_delay;
2043 bgp->v_establish_wait = bm->v_establish_wait;
2044 }
2045
2046 return CMD_SUCCESS;
2047 }
2048
2049 static int bgp_update_delay_config_vty(struct vty *vty, uint16_t update_delay,
2050 uint16_t establish_wait)
2051 {
2052 VTY_DECLVAR_CONTEXT(bgp, bgp);
2053
2054 /* if configured globally, per-instance config is not allowed */
2055 if (bm->v_update_delay) {
2056 vty_out(vty,
2057 "%%Failed: per-vrf update-delay config not permitted with global update-delay\n");
2058 return CMD_WARNING_CONFIG_FAILED;
2059 }
2060
2061
2062 if (!establish_wait) /* update-delay <delay> */
2063 {
2064 bgp->v_update_delay = update_delay;
2065 bgp->v_establish_wait = bgp->v_update_delay;
2066 return CMD_SUCCESS;
2067 }
2068
2069 /* update-delay <delay> <establish-wait> */
2070 if (update_delay < establish_wait) {
2071 vty_out(vty,
2072 "%%Failed: update-delay less than the establish-wait!\n");
2073 return CMD_WARNING_CONFIG_FAILED;
2074 }
2075
2076 bgp->v_update_delay = update_delay;
2077 bgp->v_establish_wait = establish_wait;
2078
2079 return CMD_SUCCESS;
2080 }
2081
2082 static int bgp_update_delay_deconfig_vty(struct vty *vty)
2083 {
2084 VTY_DECLVAR_CONTEXT(bgp, bgp);
2085
2086 /* If configured globally, cannot remove from one bgp instance */
2087 if (bm->v_update_delay) {
2088 vty_out(vty,
2089 "%%Failed: bgp update-delay configured globally. Delete per-vrf not permitted\n");
2090 return CMD_WARNING_CONFIG_FAILED;
2091 }
2092 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
2093 bgp->v_establish_wait = bgp->v_update_delay;
2094
2095 return CMD_SUCCESS;
2096 }
2097
2098 void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
2099 {
2100 /* If configured globally, no need to display per-instance value */
2101 if (bgp->v_update_delay != bm->v_update_delay) {
2102 vty_out(vty, " update-delay %d", bgp->v_update_delay);
2103 if (bgp->v_update_delay != bgp->v_establish_wait)
2104 vty_out(vty, " %d", bgp->v_establish_wait);
2105 vty_out(vty, "\n");
2106 }
2107 }
2108
2109 /* Global update-delay configuration */
2110 DEFPY (bgp_global_update_delay,
2111 bgp_global_update_delay_cmd,
2112 "bgp update-delay (0-3600)$delay [(1-3600)$wait]",
2113 BGP_STR
2114 "Force initial delay for best-path and updates for all bgp instances\n"
2115 "Max delay in seconds\n"
2116 "Establish wait in seconds\n")
2117 {
2118 return bgp_global_update_delay_config_vty(vty, delay, wait);
2119 }
2120
2121 /* Global update-delay deconfiguration */
2122 DEFPY (no_bgp_global_update_delay,
2123 no_bgp_global_update_delay_cmd,
2124 "no bgp update-delay [(0-3600) [(1-3600)]]",
2125 NO_STR
2126 BGP_STR
2127 "Force initial delay for best-path and updates\n"
2128 "Max delay in seconds\n"
2129 "Establish wait in seconds\n")
2130 {
2131 return bgp_global_update_delay_deconfig_vty(vty);
2132 }
2133
2134 /* Update-delay configuration */
2135
2136 DEFPY (bgp_update_delay,
2137 bgp_update_delay_cmd,
2138 "update-delay (0-3600)$delay [(1-3600)$wait]",
2139 "Force initial delay for best-path and updates\n"
2140 "Max delay in seconds\n"
2141 "Establish wait in seconds\n")
2142 {
2143 return bgp_update_delay_config_vty(vty, delay, wait);
2144 }
2145
2146 /* Update-delay deconfiguration */
2147 DEFPY (no_bgp_update_delay,
2148 no_bgp_update_delay_cmd,
2149 "no update-delay [(0-3600) [(1-3600)]]",
2150 NO_STR
2151 "Force initial delay for best-path and updates\n"
2152 "Max delay in seconds\n"
2153 "Establish wait in seconds\n")
2154 {
2155 return bgp_update_delay_deconfig_vty(vty);
2156 }
2157
2158
2159 int bgp_wpkt_quanta_config_vty(struct bgp *bgp, uint32_t quanta, bool set)
2160 {
2161 quanta = set ? quanta : BGP_WRITE_PACKET_MAX;
2162 atomic_store_explicit(&bgp->wpkt_quanta, quanta, memory_order_relaxed);
2163
2164 return CMD_SUCCESS;
2165 }
2166
2167 int bgp_rpkt_quanta_config_vty(struct bgp *bgp, uint32_t quanta, bool set)
2168 {
2169 quanta = set ? quanta : BGP_READ_PACKET_MAX;
2170 atomic_store_explicit(&bgp->rpkt_quanta, quanta, memory_order_relaxed);
2171
2172 return CMD_SUCCESS;
2173 }
2174
2175 void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
2176 {
2177 uint32_t quanta =
2178 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
2179 if (quanta != BGP_WRITE_PACKET_MAX)
2180 vty_out(vty, " write-quanta %d\n", quanta);
2181 }
2182
2183 void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
2184 {
2185 uint32_t quanta =
2186 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
2187 if (quanta != BGP_READ_PACKET_MAX)
2188 vty_out(vty, " read-quanta %d\n", quanta);
2189 }
2190
2191 /* Packet quanta configuration
2192 *
2193 * XXX: The value set here controls the size of a stack buffer in the IO
2194 * thread. When changing these limits be careful to prevent stack overflow.
2195 *
2196 * Furthermore, the maximums used here should correspond to
2197 * BGP_WRITE_PACKET_MAX and BGP_READ_PACKET_MAX.
2198 */
2199 DEFPY_YANG (bgp_wpkt_quanta,
2200 bgp_wpkt_quanta_cmd,
2201 "[no] write-quanta (1-64)$quanta",
2202 NO_STR
2203 "How many packets to write to peer socket per run\n"
2204 "Number of packets\n")
2205 {
2206 if (!no)
2207 nb_cli_enqueue_change(
2208 vty,
2209 "./global/global-neighbor-config/packet-quanta-config/wpkt-quanta",
2210 NB_OP_MODIFY, quanta_str);
2211 else
2212 nb_cli_enqueue_change(
2213 vty,
2214 "./global/global-neighbor-config/packet-quanta-config/wpkt-quanta",
2215 NB_OP_MODIFY, NULL);
2216
2217 return nb_cli_apply_changes(vty, NULL);
2218 }
2219
2220 DEFPY_YANG (bgp_rpkt_quanta,
2221 bgp_rpkt_quanta_cmd,
2222 "[no] read-quanta (1-10)$quanta",
2223 NO_STR
2224 "How many packets to read from peer socket per I/O cycle\n"
2225 "Number of packets\n")
2226 {
2227 if (!no)
2228 nb_cli_enqueue_change(
2229 vty,
2230 "./global/global-neighbor-config/packet-quanta-config/rpkt-quanta",
2231 NB_OP_MODIFY, quanta_str);
2232 else
2233 nb_cli_enqueue_change(
2234 vty,
2235 "./global/global-neighbor-config/packet-quanta-config/rpkt-quanta",
2236 NB_OP_MODIFY, NULL);
2237
2238 return nb_cli_apply_changes(vty, NULL);
2239 }
2240
2241 void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
2242 {
2243 if (!bgp->heuristic_coalesce)
2244 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
2245 }
2246
2247 void cli_show_router_global_update_group_config_coalesce_time(
2248 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
2249 {
2250 vty_out(vty, " coalesce-time %u\n", yang_dnode_get_uint32(dnode, NULL));
2251 }
2252
2253
2254 DEFUN_YANG (bgp_coalesce_time,
2255 bgp_coalesce_time_cmd,
2256 "coalesce-time (0-4294967295)",
2257 "Subgroup coalesce timer\n"
2258 "Subgroup coalesce timer value (in ms)\n")
2259 {
2260 int idx = 0;
2261
2262 argv_find(argv, argc, "(0-4294967295)", &idx);
2263 nb_cli_enqueue_change(
2264 vty, "./global/global-update-group-config/coalesce-time",
2265 NB_OP_MODIFY, argv[idx]->arg);
2266
2267 return nb_cli_apply_changes(vty, NULL);
2268 }
2269
2270 DEFUN_YANG(no_bgp_coalesce_time,
2271 no_bgp_coalesce_time_cmd,
2272 "no coalesce-time (0-4294967295)",
2273 NO_STR
2274 "Subgroup coalesce timer\n"
2275 "Subgroup coalesce timer value (in ms)\n")
2276 {
2277 nb_cli_enqueue_change(
2278 vty, "./global/global-update-group-config/coalesce-time",
2279 NB_OP_MODIFY, NULL);
2280
2281 return nb_cli_apply_changes(vty, NULL);
2282 }
2283
2284 /* Maximum-paths configuration */
2285 DEFUN_YANG (bgp_maxpaths,
2286 bgp_maxpaths_cmd,
2287 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2288 "Forward packets over multiple paths\n"
2289 "Number of paths\n")
2290 {
2291 int idx_number = 1;
2292 char base_xpath[XPATH_MAXLEN];
2293 afi_t afi;
2294 safi_t safi;
2295
2296 afi = bgp_node_afi(vty);
2297 safi = bgp_node_safi(vty);
2298
2299 snprintf(
2300 base_xpath, sizeof(base_xpath),
2301 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ebgp/maximum-paths",
2302 yang_afi_safi_value2identity(afi, safi),
2303 bgp_afi_safi_get_container_str(afi, safi));
2304
2305 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY,
2306 argv[idx_number]->arg);
2307
2308 return nb_cli_apply_changes(vty, NULL);
2309 }
2310
2311 void cli_show_bgp_global_afi_safi_unicast_use_multiple_paths_ebgp_maximum_paths(
2312 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
2313 {
2314 vty_out(vty, " maximum-paths %d\n",
2315 yang_dnode_get_uint16(dnode, NULL));
2316 }
2317
2318 ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
2319 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2320 "Forward packets over multiple paths\n"
2321 "Number of paths\n")
2322
2323 DEFUN_YANG (bgp_maxpaths_ibgp,
2324 bgp_maxpaths_ibgp_cmd,
2325 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2326 "Forward packets over multiple paths\n"
2327 "iBGP-multipath\n"
2328 "Number of paths\n")
2329 {
2330 int idx_number = 2;
2331 char base_xpath[XPATH_MAXLEN];
2332 afi_t afi;
2333 safi_t safi;
2334
2335 afi = bgp_node_afi(vty);
2336 safi = bgp_node_safi(vty);
2337
2338 snprintf(
2339 base_xpath, sizeof(base_xpath),
2340 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/maximum-paths",
2341 yang_afi_safi_value2identity(afi, safi),
2342 bgp_afi_safi_get_container_str(afi, safi));
2343
2344 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY,
2345 argv[idx_number]->arg);
2346
2347 return nb_cli_apply_changes(vty, NULL);
2348 }
2349
2350 ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
2351 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2352 "Forward packets over multiple paths\n"
2353 "iBGP-multipath\n"
2354 "Number of paths\n")
2355
2356 DEFUN_YANG (bgp_maxpaths_ibgp_cluster,
2357 bgp_maxpaths_ibgp_cluster_cmd,
2358 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
2359 "Forward packets over multiple paths\n"
2360 "iBGP-multipath\n"
2361 "Number of paths\n"
2362 "Match the cluster length\n")
2363 {
2364 int idx_number = 2;
2365 char base_xpath[XPATH_MAXLEN];
2366 afi_t afi;
2367 safi_t safi;
2368
2369 afi = bgp_node_afi(vty);
2370 safi = bgp_node_safi(vty);
2371
2372 snprintf(
2373 base_xpath, sizeof(base_xpath),
2374 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/maximum-paths",
2375 yang_afi_safi_value2identity(afi, safi),
2376 bgp_afi_safi_get_container_str(afi, safi));
2377
2378 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY,
2379 argv[idx_number]->arg);
2380
2381 snprintf(
2382 base_xpath, sizeof(base_xpath),
2383 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/cluster-length-list",
2384 yang_afi_safi_value2identity(afi, safi),
2385 bgp_afi_safi_get_container_str(afi, safi));
2386
2387 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, "true");
2388
2389 return nb_cli_apply_changes(vty, NULL);
2390 }
2391
2392 void cli_show_bgp_global_afi_safi_ip_unicast_use_multiple_paths_ibgp_maximum_paths(
2393 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
2394 {
2395 vty_out(vty, " maximum-paths ibgp %d",
2396 yang_dnode_get_uint16(dnode, "./maximum-paths"));
2397 if (yang_dnode_get_bool(dnode, "./cluster-length-list"))
2398 vty_out(vty, " equal-cluster-length");
2399 vty_out(vty, "\n");
2400 }
2401
2402 ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
2403 "maximum-paths ibgp " CMD_RANGE_STR(
2404 1, MULTIPATH_NUM) " equal-cluster-length",
2405 "Forward packets over multiple paths\n"
2406 "iBGP-multipath\n"
2407 "Number of paths\n"
2408 "Match the cluster length\n")
2409
2410 DEFUN_YANG (no_bgp_maxpaths,
2411 no_bgp_maxpaths_cmd,
2412 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
2413 NO_STR
2414 "Forward packets over multiple paths\n"
2415 "Number of paths\n")
2416 {
2417 char base_xpath[XPATH_MAXLEN];
2418 afi_t afi;
2419 safi_t safi;
2420
2421 afi = bgp_node_afi(vty);
2422 safi = bgp_node_safi(vty);
2423
2424 snprintf(
2425 base_xpath, sizeof(base_xpath),
2426 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ebgp/maximum-paths",
2427 yang_afi_safi_value2identity(afi, safi),
2428 bgp_afi_safi_get_container_str(afi, safi));
2429
2430 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, NULL);
2431
2432 return nb_cli_apply_changes(vty, NULL);
2433 }
2434
2435 ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
2436 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
2437 "Forward packets over multiple paths\n"
2438 "Number of paths\n")
2439
2440 DEFUN_YANG (no_bgp_maxpaths_ibgp,
2441 no_bgp_maxpaths_ibgp_cmd,
2442 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
2443 NO_STR
2444 "Forward packets over multiple paths\n"
2445 "iBGP-multipath\n"
2446 "Number of paths\n"
2447 "Match the cluster length\n")
2448 {
2449 char base_xpath[XPATH_MAXLEN];
2450 afi_t afi;
2451 safi_t safi;
2452
2453 afi = bgp_node_afi(vty);
2454 safi = bgp_node_safi(vty);
2455
2456 snprintf(
2457 base_xpath, sizeof(base_xpath),
2458 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/maximum-paths",
2459 yang_afi_safi_value2identity(afi, safi),
2460 bgp_afi_safi_get_container_str(afi, safi));
2461
2462 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, NULL);
2463
2464 snprintf(
2465 base_xpath, sizeof(base_xpath),
2466 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/cluster-length-list",
2467 yang_afi_safi_value2identity(afi, safi),
2468 bgp_afi_safi_get_container_str(afi, safi));
2469
2470 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, "false");
2471
2472 return nb_cli_apply_changes(vty, NULL);
2473 }
2474
2475 ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
2476 "no maximum-paths ibgp [" CMD_RANGE_STR(
2477 1, MULTIPATH_NUM) " [equal-cluster-length]]",
2478 NO_STR
2479 "Forward packets over multiple paths\n"
2480 "iBGP-multipath\n"
2481 "Number of paths\n"
2482 "Match the cluster length\n")
2483
2484 static void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp,
2485 afi_t afi, safi_t safi)
2486 {
2487 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != multipath_num) {
2488 vty_out(vty, " maximum-paths %d\n",
2489 bgp->maxpaths[afi][safi].maxpaths_ebgp);
2490 }
2491
2492 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != multipath_num) {
2493 vty_out(vty, " maximum-paths ibgp %d",
2494 bgp->maxpaths[afi][safi].maxpaths_ibgp);
2495 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
2496 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
2497 vty_out(vty, " equal-cluster-length");
2498 vty_out(vty, "\n");
2499 }
2500 }
2501
2502 /* BGP timers. */
2503
2504 DEFUN_YANG (bgp_timers,
2505 bgp_timers_cmd,
2506 "timers bgp (0-65535) (0-65535)",
2507 "Adjust routing timers\n"
2508 "BGP timers\n"
2509 "Keepalive interval\n"
2510 "Holdtime\n")
2511 {
2512 int idx_number = 2;
2513 int idx_number_2 = 3;
2514
2515 nb_cli_enqueue_change(vty, "./global/global-config-timers/keepalive",
2516 NB_OP_MODIFY, argv[idx_number]->arg);
2517 nb_cli_enqueue_change(vty, "./global/global-config-timers/hold-time",
2518 NB_OP_MODIFY, argv[idx_number_2]->arg);
2519
2520 return nb_cli_apply_changes(vty, NULL);
2521 }
2522
2523 DEFUN_YANG (no_bgp_timers,
2524 no_bgp_timers_cmd,
2525 "no timers bgp [(0-65535) (0-65535)]",
2526 NO_STR
2527 "Adjust routing timers\n"
2528 "BGP timers\n"
2529 "Keepalive interval\n"
2530 "Holdtime\n")
2531 {
2532 nb_cli_enqueue_change(vty, "./global/global-config-timers/keepalive",
2533 NB_OP_DESTROY, NULL);
2534 nb_cli_enqueue_change(vty, "./global/global-config-timers/hold-time",
2535 NB_OP_DESTROY, NULL);
2536
2537 return nb_cli_apply_changes(vty, NULL);
2538 }
2539
2540 void cli_show_router_bgp_route_reflector(struct vty *vty,
2541 struct lyd_node *dnode,
2542 bool show_defaults)
2543 {
2544 if (yang_dnode_get_bool(dnode, "./no-client-reflect"))
2545 vty_out(vty, " no bgp client-to-client reflection\n");
2546
2547 if (yang_dnode_get_bool(dnode, "./allow-outbound-policy"))
2548 vty_out(vty, " bgp route-reflector allow-outbound-policy\n");
2549
2550 if (yang_dnode_exists(dnode, "./route-reflector-cluster-id"))
2551 vty_out(vty, " bgp cluster-id %s\n",
2552 yang_dnode_get_string(dnode,
2553 "./route-reflector-cluster-id"));
2554 }
2555
2556 DEFUN_YANG(bgp_client_to_client_reflection,
2557 bgp_client_to_client_reflection_cmd,
2558 "bgp client-to-client reflection",
2559 "BGP specific commands\n"
2560 "Configure client to client route reflection\n"
2561 "reflection of routes allowed\n")
2562 {
2563 nb_cli_enqueue_change(vty, "./global/route-reflector/no-client-reflect",
2564 NB_OP_MODIFY, "false");
2565
2566 return nb_cli_apply_changes(vty, NULL);
2567 }
2568
2569 DEFUN_YANG(no_bgp_client_to_client_reflection,
2570 no_bgp_client_to_client_reflection_cmd,
2571 "no bgp client-to-client reflection",
2572 NO_STR
2573 "BGP specific commands\n"
2574 "Configure client to client route reflection\n"
2575 "reflection of routes allowed\n")
2576 {
2577 nb_cli_enqueue_change(vty, "./global/route-reflector/no-client-reflect",
2578 NB_OP_MODIFY, "true");
2579
2580 return nb_cli_apply_changes(vty, NULL);
2581 }
2582
2583 void cli_show_router_bgp_route_selection(struct vty *vty,
2584 struct lyd_node *dnode,
2585 bool show_defaults)
2586 {
2587
2588 if (yang_dnode_get_bool(dnode, "./always-compare-med"))
2589 vty_out(vty, " bgp always-compare-med\n");
2590
2591 if (yang_dnode_get_bool(dnode, "./ignore-as-path-length"))
2592 vty_out(vty, " bgp bestpath as-path ignore\n");
2593
2594 if (yang_dnode_get_bool(dnode, "./aspath-confed"))
2595 vty_out(vty, " bgp bestpath as-path confed\n");
2596
2597 if (yang_dnode_get_bool(dnode, "./external-compare-router-id"))
2598 vty_out(vty, " bgp bestpath compare-routerid\n");
2599
2600 if (yang_dnode_get_bool(dnode, "./allow-multiple-as")) {
2601 if (yang_dnode_get_bool(dnode, "./multi-path-as-set"))
2602 vty_out(vty,
2603 " bgp bestpath as-path multipath-relax as-set\n");
2604 else
2605 vty_out(vty, " bgp bestpath as-path multipath-relax\n");
2606 }
2607
2608 if (yang_dnode_get_bool(dnode, "./deterministic-med"))
2609 vty_out(vty, " bgp deterministic-med\n");
2610
2611 if (yang_dnode_get_bool(dnode, "./confed-med")
2612 || yang_dnode_get_bool(dnode, "./missing-as-worst-med")) {
2613 vty_out(vty, " bgp bestpath med");
2614 if (yang_dnode_get_bool(dnode, "./confed-med"))
2615 vty_out(vty, " confed");
2616 if (yang_dnode_get_bool(dnode, "./missing-as-worst-med"))
2617 vty_out(vty, " missing-as-worst");
2618 vty_out(vty, "\n");
2619 }
2620 }
2621
2622 /* "bgp always-compare-med" configuration. */
2623 DEFUN_YANG(bgp_always_compare_med,
2624 bgp_always_compare_med_cmd,
2625 "bgp always-compare-med",
2626 "BGP specific commands\n"
2627 "Allow comparing MED from different neighbors\n")
2628 {
2629 nb_cli_enqueue_change(
2630 vty, "./global/route-selection-options/always-compare-med",
2631 NB_OP_MODIFY, "true");
2632
2633 return nb_cli_apply_changes(vty, NULL);
2634 }
2635
2636 DEFUN_YANG(no_bgp_always_compare_med,
2637 no_bgp_always_compare_med_cmd,
2638 "no bgp always-compare-med",
2639 NO_STR
2640 "BGP specific commands\n"
2641 "Allow comparing MED from different neighbors\n")
2642 {
2643 nb_cli_enqueue_change(
2644 vty, "./global/route-selection-options/always-compare-med",
2645 NB_OP_MODIFY, "false");
2646
2647 return nb_cli_apply_changes(vty, NULL);
2648 }
2649
2650 DEFUN_YANG(bgp_suppress_duplicates,
2651 bgp_suppress_duplicates_cmd,
2652 "bgp suppress-duplicates",
2653 "BGP specific commands\n"
2654 "Suppress duplicate updates if the route actually not changed\n")
2655 {
2656 nb_cli_enqueue_change(vty, "./global/suppress-duplicates",
2657 NB_OP_MODIFY, "true");
2658 return nb_cli_apply_changes(vty, NULL);
2659 }
2660
2661 DEFUN_YANG(no_bgp_suppress_duplicates,
2662 no_bgp_suppress_duplicates_cmd,
2663 "no bgp suppress-duplicates",
2664 NO_STR
2665 "BGP specific commands\n"
2666 "Suppress duplicate updates if the route actually not changed\n")
2667 {
2668 nb_cli_enqueue_change(vty, "./global/suppress-duplicates",
2669 NB_OP_MODIFY, "false");
2670 return nb_cli_apply_changes(vty, NULL);
2671 }
2672
2673 void cli_show_router_bgp_suppress_duplicates(struct vty *vty,
2674 struct lyd_node *dnode,
2675 bool show_defaults)
2676 {
2677 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_SUPPRESS_DUPLICATES)
2678 vty_out(vty, " bgp suppress-duplicates\n");
2679 }
2680
2681 DEFUN_YANG(bgp_ebgp_requires_policy,
2682 bgp_ebgp_requires_policy_cmd,
2683 "bgp ebgp-requires-policy",
2684 "BGP specific commands\n"
2685 "Require in and out policy for eBGP peers (RFC8212)\n")
2686 {
2687 nb_cli_enqueue_change(vty, "./global/ebgp-requires-policy",
2688 NB_OP_MODIFY, "true");
2689 return nb_cli_apply_changes(vty, NULL);
2690 }
2691
2692 DEFUN_YANG(no_bgp_ebgp_requires_policy,
2693 no_bgp_ebgp_requires_policy_cmd,
2694 "no bgp ebgp-requires-policy",
2695 NO_STR
2696 "BGP specific commands\n"
2697 "Require in and out policy for eBGP peers (RFC8212)\n")
2698 {
2699 nb_cli_enqueue_change(vty, "./global/ebgp-requires-policy",
2700 NB_OP_MODIFY, "false");
2701 return nb_cli_apply_changes(vty, NULL);
2702 }
2703
2704 void cli_show_router_bgp_ebgp_requires_policy(struct vty *vty,
2705 struct lyd_node *dnode,
2706 bool show_defaults)
2707 {
2708 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_EBGP_REQUIRES_POLICY)
2709 vty_out(vty, " bgp ebgp-requires-policy\n");
2710 }
2711
2712 DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd,
2713 "bgp reject-as-sets",
2714 "BGP specific commands\n"
2715 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2716 {
2717 VTY_DECLVAR_CONTEXT(bgp, bgp);
2718 struct listnode *node, *nnode;
2719 struct peer *peer;
2720
2721 bgp->reject_as_sets = true;
2722
2723 /* Reset existing BGP sessions to reject routes
2724 * with aspath containing AS_SET or AS_CONFED_SET.
2725 */
2726 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2727 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2728 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2729 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2730 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2731 }
2732 }
2733
2734 return CMD_SUCCESS;
2735 }
2736
2737 DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd,
2738 "no bgp reject-as-sets",
2739 NO_STR
2740 "BGP specific commands\n"
2741 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2742 {
2743 VTY_DECLVAR_CONTEXT(bgp, bgp);
2744 struct listnode *node, *nnode;
2745 struct peer *peer;
2746
2747 bgp->reject_as_sets = false;
2748
2749 /* Reset existing BGP sessions to reject routes
2750 * with aspath containing AS_SET or AS_CONFED_SET.
2751 */
2752 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2753 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2754 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2755 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2756 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2757 }
2758 }
2759
2760 return CMD_SUCCESS;
2761 }
2762
2763 /* "bgp deterministic-med" configuration. */
2764 DEFUN_YANG (bgp_deterministic_med,
2765 bgp_deterministic_med_cmd,
2766 "bgp deterministic-med",
2767 "BGP specific commands\n"
2768 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2769 {
2770 nb_cli_enqueue_change(
2771 vty, "./global/route-selection-options/deterministic-med",
2772 NB_OP_MODIFY, "true");
2773
2774 return nb_cli_apply_changes(vty, NULL);
2775 }
2776
2777 DEFUN_YANG (no_bgp_deterministic_med,
2778 no_bgp_deterministic_med_cmd,
2779 "no bgp deterministic-med",
2780 NO_STR
2781 "BGP specific commands\n"
2782 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2783 {
2784 nb_cli_enqueue_change(
2785 vty, "./global/route-selection-options/deterministic-med",
2786 NB_OP_MODIFY, "false");
2787
2788 return nb_cli_apply_changes(vty, NULL);
2789 }
2790
2791 /* "bgp graceful-restart mode" configuration. */
2792 DEFUN (bgp_graceful_restart,
2793 bgp_graceful_restart_cmd,
2794 "bgp graceful-restart",
2795 "BGP specific commands\n"
2796 GR_CMD
2797 )
2798 {
2799 int ret = BGP_GR_FAILURE;
2800
2801 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2802 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : START ");
2803
2804 VTY_DECLVAR_CONTEXT(bgp, bgp);
2805
2806 ret = bgp_gr_update_all(bgp, GLOBAL_GR_CMD);
2807
2808 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2809 ret);
2810
2811 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2812 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : END ");
2813 vty_out(vty,
2814 "Graceful restart configuration changed, reset all peers to take effect\n");
2815 return bgp_vty_return(vty, ret);
2816 }
2817
2818 DEFUN (no_bgp_graceful_restart,
2819 no_bgp_graceful_restart_cmd,
2820 "no bgp graceful-restart",
2821 NO_STR
2822 "BGP specific commands\n"
2823 NO_GR_CMD
2824 )
2825 {
2826 VTY_DECLVAR_CONTEXT(bgp, bgp);
2827
2828 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2829 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : START ");
2830
2831 int ret = BGP_GR_FAILURE;
2832
2833 ret = bgp_gr_update_all(bgp, NO_GLOBAL_GR_CMD);
2834
2835 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2836 ret);
2837
2838 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2839 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : END ");
2840 vty_out(vty,
2841 "Graceful restart configuration changed, reset all peers to take effect\n");
2842
2843 return bgp_vty_return(vty, ret);
2844 }
2845
2846 DEFUN (bgp_graceful_restart_stalepath_time,
2847 bgp_graceful_restart_stalepath_time_cmd,
2848 "bgp graceful-restart stalepath-time (1-4095)",
2849 "BGP specific commands\n"
2850 "Graceful restart capability parameters\n"
2851 "Set the max time to hold onto restarting peer's stale paths\n"
2852 "Delay value (seconds)\n")
2853 {
2854 VTY_DECLVAR_CONTEXT(bgp, bgp);
2855 int idx_number = 3;
2856 uint32_t stalepath;
2857
2858 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2859 bgp->stalepath_time = stalepath;
2860 return CMD_SUCCESS;
2861 }
2862
2863 DEFUN (bgp_graceful_restart_restart_time,
2864 bgp_graceful_restart_restart_time_cmd,
2865 "bgp graceful-restart restart-time (1-4095)",
2866 "BGP specific commands\n"
2867 "Graceful restart capability parameters\n"
2868 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2869 "Delay value (seconds)\n")
2870 {
2871 VTY_DECLVAR_CONTEXT(bgp, bgp);
2872 int idx_number = 3;
2873 uint32_t restart;
2874
2875 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2876 bgp->restart_time = restart;
2877 return CMD_SUCCESS;
2878 }
2879
2880 DEFUN (bgp_graceful_restart_select_defer_time,
2881 bgp_graceful_restart_select_defer_time_cmd,
2882 "bgp graceful-restart select-defer-time (0-3600)",
2883 "BGP specific commands\n"
2884 "Graceful restart capability parameters\n"
2885 "Set the time to defer the BGP route selection after restart\n"
2886 "Delay value (seconds, 0 - disable)\n")
2887 {
2888 VTY_DECLVAR_CONTEXT(bgp, bgp);
2889 int idx_number = 3;
2890 uint32_t defer_time;
2891
2892 defer_time = strtoul(argv[idx_number]->arg, NULL, 10);
2893 bgp->select_defer_time = defer_time;
2894 if (defer_time == 0)
2895 SET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2896 else
2897 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2898
2899 return CMD_SUCCESS;
2900 }
2901
2902 DEFUN (no_bgp_graceful_restart_stalepath_time,
2903 no_bgp_graceful_restart_stalepath_time_cmd,
2904 "no bgp graceful-restart stalepath-time [(1-4095)]",
2905 NO_STR
2906 "BGP specific commands\n"
2907 "Graceful restart capability parameters\n"
2908 "Set the max time to hold onto restarting peer's stale paths\n"
2909 "Delay value (seconds)\n")
2910 {
2911 VTY_DECLVAR_CONTEXT(bgp, bgp);
2912
2913 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2914 return CMD_SUCCESS;
2915 }
2916
2917 DEFUN (no_bgp_graceful_restart_restart_time,
2918 no_bgp_graceful_restart_restart_time_cmd,
2919 "no bgp graceful-restart restart-time [(1-4095)]",
2920 NO_STR
2921 "BGP specific commands\n"
2922 "Graceful restart capability parameters\n"
2923 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2924 "Delay value (seconds)\n")
2925 {
2926 VTY_DECLVAR_CONTEXT(bgp, bgp);
2927
2928 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2929 return CMD_SUCCESS;
2930 }
2931
2932 DEFUN (no_bgp_graceful_restart_select_defer_time,
2933 no_bgp_graceful_restart_select_defer_time_cmd,
2934 "no bgp graceful-restart select-defer-time [(0-3600)]",
2935 NO_STR
2936 "BGP specific commands\n"
2937 "Graceful restart capability parameters\n"
2938 "Set the time to defer the BGP route selection after restart\n"
2939 "Delay value (seconds)\n")
2940 {
2941 VTY_DECLVAR_CONTEXT(bgp, bgp);
2942
2943 bgp->select_defer_time = BGP_DEFAULT_SELECT_DEFERRAL_TIME;
2944 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2945
2946 return CMD_SUCCESS;
2947 }
2948
2949 DEFUN (bgp_graceful_restart_preserve_fw,
2950 bgp_graceful_restart_preserve_fw_cmd,
2951 "bgp graceful-restart preserve-fw-state",
2952 "BGP specific commands\n"
2953 "Graceful restart capability parameters\n"
2954 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
2955 {
2956 VTY_DECLVAR_CONTEXT(bgp, bgp);
2957 SET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
2958 return CMD_SUCCESS;
2959 }
2960
2961 DEFUN (no_bgp_graceful_restart_preserve_fw,
2962 no_bgp_graceful_restart_preserve_fw_cmd,
2963 "no bgp graceful-restart preserve-fw-state",
2964 NO_STR
2965 "BGP specific commands\n"
2966 "Graceful restart capability parameters\n"
2967 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
2968 {
2969 VTY_DECLVAR_CONTEXT(bgp, bgp);
2970 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
2971 return CMD_SUCCESS;
2972 }
2973
2974 DEFUN (bgp_graceful_restart_disable,
2975 bgp_graceful_restart_disable_cmd,
2976 "bgp graceful-restart-disable",
2977 "BGP specific commands\n"
2978 GR_DISABLE)
2979 {
2980 int ret = BGP_GR_FAILURE;
2981
2982 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2983 zlog_debug(
2984 "[BGP_GR] bgp_graceful_restart_disable_cmd : START ");
2985
2986 VTY_DECLVAR_CONTEXT(bgp, bgp);
2987
2988 ret = bgp_gr_update_all(bgp, GLOBAL_DISABLE_CMD);
2989
2990 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
2991 bgp->peer, ret);
2992
2993 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2994 zlog_debug(
2995 "[BGP_GR] bgp_graceful_restart_disable_cmd : END ");
2996 vty_out(vty,
2997 "Graceful restart configuration changed, reset all peers to take effect\n");
2998
2999 return bgp_vty_return(vty, ret);
3000 }
3001
3002 DEFUN (no_bgp_graceful_restart_disable,
3003 no_bgp_graceful_restart_disable_cmd,
3004 "no bgp graceful-restart-disable",
3005 NO_STR
3006 "BGP specific commands\n"
3007 NO_GR_DISABLE
3008 )
3009 {
3010 VTY_DECLVAR_CONTEXT(bgp, bgp);
3011
3012 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3013 zlog_debug(
3014 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : START ");
3015
3016 int ret = BGP_GR_FAILURE;
3017
3018 ret = bgp_gr_update_all(bgp, NO_GLOBAL_DISABLE_CMD);
3019
3020 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
3021 ret);
3022
3023 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3024 zlog_debug(
3025 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : END ");
3026 vty_out(vty,
3027 "Graceful restart configuration changed, reset all peers to take effect\n");
3028
3029 return bgp_vty_return(vty, ret);
3030 }
3031
3032 DEFUN (bgp_neighbor_graceful_restart_set,
3033 bgp_neighbor_graceful_restart_set_cmd,
3034 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3035 NEIGHBOR_STR
3036 NEIGHBOR_ADDR_STR2
3037 GR_NEIGHBOR_CMD
3038 )
3039 {
3040 int idx_peer = 1;
3041 struct peer *peer;
3042 int ret = BGP_GR_FAILURE;
3043
3044 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3045
3046 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3047 zlog_debug(
3048 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : START ");
3049
3050 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3051 if (!peer)
3052 return CMD_WARNING_CONFIG_FAILED;
3053
3054 ret = bgp_neighbor_graceful_restart(peer, PEER_GR_CMD);
3055
3056 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3057 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3058
3059 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3060 zlog_debug(
3061 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : END ");
3062 vty_out(vty,
3063 "Graceful restart configuration changed, reset this peer to take effect\n");
3064
3065 return bgp_vty_return(vty, ret);
3066 }
3067
3068 DEFUN (no_bgp_neighbor_graceful_restart,
3069 no_bgp_neighbor_graceful_restart_set_cmd,
3070 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3071 NO_STR
3072 NEIGHBOR_STR
3073 NEIGHBOR_ADDR_STR2
3074 NO_GR_NEIGHBOR_CMD
3075 )
3076 {
3077 int idx_peer = 2;
3078 int ret = BGP_GR_FAILURE;
3079 struct peer *peer;
3080
3081 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3082
3083 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3084 if (!peer)
3085 return CMD_WARNING_CONFIG_FAILED;
3086
3087 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3088 zlog_debug(
3089 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : START ");
3090
3091 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_GR_CMD);
3092
3093 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3094 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3095
3096 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3097 zlog_debug(
3098 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : END ");
3099 vty_out(vty,
3100 "Graceful restart configuration changed, reset this peer to take effect\n");
3101
3102 return bgp_vty_return(vty, ret);
3103 }
3104
3105 DEFUN (bgp_neighbor_graceful_restart_helper_set,
3106 bgp_neighbor_graceful_restart_helper_set_cmd,
3107 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3108 NEIGHBOR_STR
3109 NEIGHBOR_ADDR_STR2
3110 GR_NEIGHBOR_HELPER_CMD
3111 )
3112 {
3113 int idx_peer = 1;
3114 struct peer *peer;
3115 int ret = BGP_GR_FAILURE;
3116
3117 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3118
3119 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3120 zlog_debug(
3121 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : START ");
3122
3123 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3124
3125 if (!peer)
3126 return CMD_WARNING_CONFIG_FAILED;
3127
3128
3129 ret = bgp_neighbor_graceful_restart(peer, PEER_HELPER_CMD);
3130
3131 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3132 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3133
3134 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3135 zlog_debug(
3136 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : END ");
3137 vty_out(vty,
3138 "Graceful restart configuration changed, reset this peer to take effect\n");
3139
3140 return bgp_vty_return(vty, ret);
3141 }
3142
3143 DEFUN (no_bgp_neighbor_graceful_restart_helper,
3144 no_bgp_neighbor_graceful_restart_helper_set_cmd,
3145 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3146 NO_STR
3147 NEIGHBOR_STR
3148 NEIGHBOR_ADDR_STR2
3149 NO_GR_NEIGHBOR_HELPER_CMD
3150 )
3151 {
3152 int idx_peer = 2;
3153 int ret = BGP_GR_FAILURE;
3154 struct peer *peer;
3155
3156 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3157
3158 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3159 if (!peer)
3160 return CMD_WARNING_CONFIG_FAILED;
3161
3162 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3163 zlog_debug(
3164 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : START ");
3165
3166 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_HELPER_CMD);
3167
3168 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3169 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3170
3171 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3172 zlog_debug(
3173 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : END ");
3174 vty_out(vty,
3175 "Graceful restart configuration changed, reset this peer to take effect\n");
3176
3177 return bgp_vty_return(vty, ret);
3178 }
3179
3180 DEFUN (bgp_neighbor_graceful_restart_disable_set,
3181 bgp_neighbor_graceful_restart_disable_set_cmd,
3182 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3183 NEIGHBOR_STR
3184 NEIGHBOR_ADDR_STR2
3185 GR_NEIGHBOR_DISABLE_CMD
3186 )
3187 {
3188 int idx_peer = 1;
3189 struct peer *peer;
3190 int ret = BGP_GR_FAILURE;
3191
3192 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3193
3194 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3195 zlog_debug(
3196 "[BGP_GR] bgp_neighbor_graceful_restart_disable_set_cmd : START ");
3197
3198 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3199 if (!peer)
3200 return CMD_WARNING_CONFIG_FAILED;
3201
3202 ret = bgp_neighbor_graceful_restart(peer, PEER_DISABLE_CMD);
3203
3204 if (peer->bgp->t_startup)
3205 bgp_peer_gr_flags_update(peer);
3206
3207 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3208 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3209
3210 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3211 zlog_debug(
3212 "[BGP_GR]bgp_neighbor_graceful_restart_disable_set_cmd : END ");
3213 vty_out(vty,
3214 "Graceful restart configuration changed, reset this peer to take effect\n");
3215
3216 return bgp_vty_return(vty, ret);
3217 }
3218
3219 DEFUN (no_bgp_neighbor_graceful_restart_disable,
3220 no_bgp_neighbor_graceful_restart_disable_set_cmd,
3221 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3222 NO_STR
3223 NEIGHBOR_STR
3224 NEIGHBOR_ADDR_STR2
3225 NO_GR_NEIGHBOR_DISABLE_CMD
3226 )
3227 {
3228 int idx_peer = 2;
3229 int ret = BGP_GR_FAILURE;
3230 struct peer *peer;
3231
3232 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3233
3234 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3235 if (!peer)
3236 return CMD_WARNING_CONFIG_FAILED;
3237
3238 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3239 zlog_debug(
3240 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : START ");
3241
3242 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_DISABLE_CMD);
3243
3244 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3245 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3246
3247 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3248 zlog_debug(
3249 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : END ");
3250 vty_out(vty,
3251 "Graceful restart configuration changed, reset this peer to take effect\n");
3252
3253 return bgp_vty_return(vty, ret);
3254 }
3255
3256 DEFUN_HIDDEN (bgp_graceful_restart_disable_eor,
3257 bgp_graceful_restart_disable_eor_cmd,
3258 "bgp graceful-restart disable-eor",
3259 "BGP specific commands\n"
3260 "Graceful restart configuration parameters\n"
3261 "Disable EOR Check\n")
3262 {
3263 VTY_DECLVAR_CONTEXT(bgp, bgp);
3264 SET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
3265
3266 return CMD_SUCCESS;
3267 }
3268
3269 DEFUN_HIDDEN (no_bgp_graceful_restart_disable_eor,
3270 no_bgp_graceful_restart_disable_eor_cmd,
3271 "no bgp graceful-restart disable-eor",
3272 NO_STR
3273 "BGP specific commands\n"
3274 "Graceful restart configuration parameters\n"
3275 "Disable EOR Check\n")
3276 {
3277 VTY_DECLVAR_CONTEXT(bgp, bgp);
3278 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
3279
3280 return CMD_SUCCESS;
3281 }
3282
3283 DEFUN (bgp_graceful_restart_rib_stale_time,
3284 bgp_graceful_restart_rib_stale_time_cmd,
3285 "bgp graceful-restart rib-stale-time (1-3600)",
3286 "BGP specific commands\n"
3287 "Graceful restart configuration parameters\n"
3288 "Specify the stale route removal timer in rib\n"
3289 "Delay value (seconds)\n")
3290 {
3291 VTY_DECLVAR_CONTEXT(bgp, bgp);
3292 int idx_number = 3;
3293 uint32_t stale_time;
3294
3295 stale_time = strtoul(argv[idx_number]->arg, NULL, 10);
3296 bgp->rib_stale_time = stale_time;
3297 /* Send the stale timer update message to RIB */
3298 if (bgp_zebra_stale_timer_update(bgp))
3299 return CMD_WARNING;
3300
3301 return CMD_SUCCESS;
3302 }
3303
3304 DEFUN (no_bgp_graceful_restart_rib_stale_time,
3305 no_bgp_graceful_restart_rib_stale_time_cmd,
3306 "no bgp graceful-restart rib-stale-time [(1-3600)]",
3307 NO_STR
3308 "BGP specific commands\n"
3309 "Graceful restart configuration parameters\n"
3310 "Specify the stale route removal timer in rib\n"
3311 "Delay value (seconds)\n")
3312 {
3313 VTY_DECLVAR_CONTEXT(bgp, bgp);
3314
3315 bgp->rib_stale_time = BGP_DEFAULT_RIB_STALE_TIME;
3316 /* Send the stale timer update message to RIB */
3317 if (bgp_zebra_stale_timer_update(bgp))
3318 return CMD_WARNING;
3319
3320 return CMD_SUCCESS;
3321 }
3322
3323 static inline int bgp_initiate_graceful_shut_unshut(struct bgp *bgp,
3324 char *errmsg,
3325 size_t errmsg_len)
3326 {
3327 bgp_static_redo_import_check(bgp);
3328 bgp_redistribute_redo(bgp);
3329 if (bgp_clear_star_soft_out(bgp->name, errmsg, errmsg_len) < 0)
3330 return -1;
3331 if (bgp_clear_star_soft_in(bgp->name, errmsg, errmsg_len) < 0)
3332 return -1;
3333
3334 return 0;
3335 }
3336
3337 static int bgp_global_graceful_shutdown_config_vty(struct vty *vty)
3338 {
3339 struct listnode *node, *nnode;
3340 struct bgp *bgp;
3341 bool vrf_cfg = false;
3342 char errmsg[BUFSIZ] = {'\0'};
3343
3344 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3345 return CMD_SUCCESS;
3346
3347 /* See if graceful-shutdown is set per-vrf and warn user to delete */
3348 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3349 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3350 vty_out(vty,
3351 "%% graceful-shutdown configuration found in vrf %s\n",
3352 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT ?
3353 VRF_DEFAULT_NAME : bgp->name);
3354 vrf_cfg = true;
3355 }
3356 }
3357
3358 if (vrf_cfg) {
3359 vty_out(vty,
3360 "%%Failed: global graceful-shutdown not permitted\n");
3361 return CMD_WARNING;
3362 }
3363
3364 /* Set flag globally */
3365 SET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3366
3367 /* Initiate processing for all BGP instances. */
3368 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3369 if (bgp_initiate_graceful_shut_unshut(bgp, errmsg,
3370 sizeof(errmsg))
3371 < 0)
3372 if (strlen(errmsg))
3373 vty_out(vty, "%s\n", errmsg);
3374 }
3375
3376 return CMD_SUCCESS;
3377 }
3378
3379 static int bgp_global_graceful_shutdown_deconfig_vty(struct vty *vty)
3380 {
3381 struct listnode *node, *nnode;
3382 struct bgp *bgp;
3383 char errmsg[BUFSIZ] = {'\0'};
3384
3385 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3386 return CMD_SUCCESS;
3387
3388 /* Unset flag globally */
3389 UNSET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3390
3391 /* Initiate processing for all BGP instances. */
3392 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3393 if (bgp_initiate_graceful_shut_unshut(bgp, errmsg,
3394 sizeof(errmsg))
3395 < 0)
3396 if (strlen(errmsg))
3397 vty_out(vty, "%s\n", errmsg);
3398 }
3399
3400 return CMD_SUCCESS;
3401 }
3402
3403 /* "bgp graceful-shutdown" configuration */
3404 DEFUN (bgp_graceful_shutdown,
3405 bgp_graceful_shutdown_cmd,
3406 "bgp graceful-shutdown",
3407 BGP_STR
3408 "Graceful shutdown parameters\n")
3409 {
3410 if (vty->node == CONFIG_NODE)
3411 return bgp_global_graceful_shutdown_config_vty(vty);
3412
3413 nb_cli_enqueue_change(vty, "./global/graceful-shutdown/enable",
3414 NB_OP_MODIFY, "true");
3415
3416 return nb_cli_apply_changes(vty, NULL);
3417 }
3418
3419 DEFUN_YANG (no_bgp_graceful_shutdown,
3420 no_bgp_graceful_shutdown_cmd,
3421 "no bgp graceful-shutdown",
3422 NO_STR
3423 BGP_STR
3424 "Graceful shutdown parameters\n")
3425 {
3426 if (vty->node == CONFIG_NODE)
3427 return bgp_global_graceful_shutdown_deconfig_vty(vty);
3428
3429 nb_cli_enqueue_change(vty, "./global/graceful-shutdown/enable",
3430 NB_OP_MODIFY, "false");
3431
3432 return nb_cli_apply_changes(vty, NULL);
3433 }
3434
3435 void cli_show_router_bgp_graceful_shutdown(struct vty *vty,
3436 struct lyd_node *dnode,
3437 bool show_defaults)
3438 {
3439 if (yang_dnode_get_bool(dnode, NULL))
3440 vty_out(vty, " bgp graceful-shutdown\n");
3441 }
3442
3443 /* "bgp fast-external-failover" configuration. */
3444 DEFUN_YANG (bgp_fast_external_failover,
3445 bgp_fast_external_failover_cmd,
3446 "bgp fast-external-failover",
3447 BGP_STR
3448 "Immediately reset session if a link to a directly connected external peer goes down\n")
3449 {
3450 nb_cli_enqueue_change(vty, "./global/fast-external-failover",
3451 NB_OP_MODIFY, "false");
3452
3453 return nb_cli_apply_changes(vty, NULL);
3454 }
3455
3456 DEFUN_YANG (no_bgp_fast_external_failover,
3457 no_bgp_fast_external_failover_cmd,
3458 "no bgp fast-external-failover",
3459 NO_STR
3460 BGP_STR
3461 "Immediately reset session if a link to a directly connected external peer goes down\n")
3462 {
3463 nb_cli_enqueue_change(vty, "./global/fast-external-failover",
3464 NB_OP_MODIFY, "true");
3465
3466 return nb_cli_apply_changes(vty, NULL);
3467 }
3468
3469 void cli_show_router_bgp_fast_external_failover(struct vty *vty,
3470 struct lyd_node *dnode,
3471 bool show_defaults)
3472 {
3473 if (!yang_dnode_get_bool(dnode, NULL))
3474 vty_out(vty, " no bgp fast-external-failover\n");
3475 }
3476
3477 /* "bgp bestpath compare-routerid" configuration. */
3478 DEFUN_YANG(bgp_bestpath_compare_router_id,
3479 bgp_bestpath_compare_router_id_cmd,
3480 "bgp bestpath compare-routerid",
3481 "BGP specific commands\n"
3482 "Change the default bestpath selection\n"
3483 "Compare router-id for identical EBGP paths\n")
3484 {
3485 nb_cli_enqueue_change(
3486 vty,
3487 "./global/route-selection-options/external-compare-router-id",
3488 NB_OP_MODIFY, "true");
3489
3490 return nb_cli_apply_changes(vty, NULL);
3491 }
3492
3493 DEFUN_YANG(no_bgp_bestpath_compare_router_id,
3494 no_bgp_bestpath_compare_router_id_cmd,
3495 "no bgp bestpath compare-routerid",
3496 NO_STR
3497 "BGP specific commands\n"
3498 "Change the default bestpath selection\n"
3499 "Compare router-id for identical EBGP paths\n")
3500 {
3501 nb_cli_enqueue_change(
3502 vty,
3503 "./global/route-selection-options/external-compare-router-id",
3504 NB_OP_MODIFY, "false");
3505
3506 return nb_cli_apply_changes(vty, NULL);
3507 }
3508
3509 /* "bgp bestpath as-path ignore" configuration. */
3510 DEFUN_YANG(bgp_bestpath_aspath_ignore,
3511 bgp_bestpath_aspath_ignore_cmd,
3512 "bgp bestpath as-path ignore",
3513 "BGP specific commands\n"
3514 "Change the default bestpath selection\n"
3515 "AS-path attribute\n"
3516 "Ignore as-path length in selecting a route\n")
3517 {
3518 nb_cli_enqueue_change(
3519 vty, "./global/route-selection-options/ignore-as-path-length",
3520 NB_OP_MODIFY, "true");
3521
3522 return nb_cli_apply_changes(vty, NULL);
3523 }
3524
3525 DEFUN_YANG(no_bgp_bestpath_aspath_ignore,
3526 no_bgp_bestpath_aspath_ignore_cmd,
3527 "no bgp bestpath as-path ignore",
3528 NO_STR
3529 "BGP specific commands\n"
3530 "Change the default bestpath selection\n"
3531 "AS-path attribute\n"
3532 "Ignore as-path length in selecting a route\n")
3533 {
3534 nb_cli_enqueue_change(
3535 vty, "./global/route-selection-options/ignore-as-path-length",
3536 NB_OP_MODIFY, "false");
3537
3538 return nb_cli_apply_changes(vty, NULL);
3539 }
3540
3541 /* "bgp bestpath as-path confed" configuration. */
3542 DEFUN_YANG (bgp_bestpath_aspath_confed,
3543 bgp_bestpath_aspath_confed_cmd,
3544 "bgp bestpath as-path confed",
3545 "BGP specific commands\n"
3546 "Change the default bestpath selection\n"
3547 "AS-path attribute\n"
3548 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3549 {
3550 nb_cli_enqueue_change(vty,
3551 "./global/route-selection-options/aspath-confed",
3552 NB_OP_MODIFY, "true");
3553
3554 return nb_cli_apply_changes(vty, NULL);
3555 }
3556
3557 DEFUN_YANG (no_bgp_bestpath_aspath_confed,
3558 no_bgp_bestpath_aspath_confed_cmd,
3559 "no bgp bestpath as-path confed",
3560 NO_STR
3561 "BGP specific commands\n"
3562 "Change the default bestpath selection\n"
3563 "AS-path attribute\n"
3564 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3565 {
3566 nb_cli_enqueue_change(vty,
3567 "./global/route-selection-options/aspath-confed",
3568 NB_OP_MODIFY, "false");
3569
3570 return nb_cli_apply_changes(vty, NULL);
3571 }
3572
3573 /* "bgp bestpath as-path multipath-relax" configuration. */
3574 DEFUN_YANG (bgp_bestpath_aspath_multipath_relax,
3575 bgp_bestpath_aspath_multipath_relax_cmd,
3576 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
3577 "BGP specific commands\n"
3578 "Change the default bestpath selection\n"
3579 "AS-path attribute\n"
3580 "Allow load sharing across routes that have different AS paths (but same length)\n"
3581 "Generate an AS_SET\n"
3582 "Do not generate an AS_SET\n")
3583 {
3584 int idx = 0;
3585
3586 nb_cli_enqueue_change(
3587 vty, "./global/route-selection-options/allow-multiple-as",
3588 NB_OP_MODIFY, "true");
3589 if (argv_find(argv, argc, "as-set", &idx))
3590 nb_cli_enqueue_change(
3591 vty,
3592 "./global/route-selection-options/multi-path-as-set",
3593 NB_OP_MODIFY, "true");
3594 else
3595 nb_cli_enqueue_change(
3596 vty,
3597 "./global/route-selection-options/multi-path-as-set",
3598 NB_OP_MODIFY, "false");
3599
3600 return nb_cli_apply_changes(vty, NULL);
3601 }
3602
3603 DEFUN_YANG (no_bgp_bestpath_aspath_multipath_relax,
3604 no_bgp_bestpath_aspath_multipath_relax_cmd,
3605 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
3606 NO_STR
3607 "BGP specific commands\n"
3608 "Change the default bestpath selection\n"
3609 "AS-path attribute\n"
3610 "Allow load sharing across routes that have different AS paths (but same length)\n"
3611 "Generate an AS_SET\n"
3612 "Do not generate an AS_SET\n")
3613 {
3614 nb_cli_enqueue_change(
3615 vty, "./global/route-selection-options/allow-multiple-as",
3616 NB_OP_MODIFY, "false");
3617 nb_cli_enqueue_change(
3618 vty, "./global/route-selection-options/multi-path-as-set",
3619 NB_OP_MODIFY, "false");
3620
3621 return nb_cli_apply_changes(vty, NULL);
3622 }
3623
3624 /* "bgp bestpath peer-type multipath-relax" configuration. */
3625 DEFUN(bgp_bestpath_peer_type_multipath_relax,
3626 bgp_bestpath_peer_type_multipath_relax_cmd,
3627 "bgp bestpath peer-type multipath-relax",
3628 BGP_STR
3629 "Change the default bestpath selection\n"
3630 "Peer type\n"
3631 "Allow load sharing across routes learned from different peer types\n")
3632 {
3633 VTY_DECLVAR_CONTEXT(bgp, bgp);
3634 SET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3635 bgp_recalculate_all_bestpaths(bgp);
3636
3637 return CMD_SUCCESS;
3638 }
3639
3640 DEFUN(no_bgp_bestpath_peer_type_multipath_relax,
3641 no_bgp_bestpath_peer_type_multipath_relax_cmd,
3642 "no bgp bestpath peer-type multipath-relax",
3643 NO_STR BGP_STR
3644 "Change the default bestpath selection\n"
3645 "Peer type\n"
3646 "Allow load sharing across routes learned from different peer types\n")
3647 {
3648 VTY_DECLVAR_CONTEXT(bgp, bgp);
3649 UNSET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3650 bgp_recalculate_all_bestpaths(bgp);
3651
3652 return CMD_SUCCESS;
3653 }
3654
3655 /* "bgp log-neighbor-changes" configuration. */
3656 DEFUN_YANG(bgp_log_neighbor_changes,
3657 bgp_log_neighbor_changes_cmd,
3658 "bgp log-neighbor-changes",
3659 "BGP specific commands\n"
3660 "Log neighbor up/down and reset reason\n")
3661 {
3662 nb_cli_enqueue_change(
3663 vty, "./global/global-neighbor-config/log-neighbor-changes",
3664 NB_OP_MODIFY, "true");
3665
3666 return nb_cli_apply_changes(vty, NULL);
3667 }
3668
3669 DEFUN_YANG(no_bgp_log_neighbor_changes,
3670 no_bgp_log_neighbor_changes_cmd,
3671 "no bgp log-neighbor-changes",
3672 NO_STR
3673 "BGP specific commands\n"
3674 "Log neighbor up/down and reset reason\n")
3675 {
3676 nb_cli_enqueue_change(
3677 vty, "./global/global-neighbor-config/log-neighbor-changes",
3678 NB_OP_MODIFY, "false");
3679
3680 return nb_cli_apply_changes(vty, NULL);
3681 }
3682
3683 /* "bgp bestpath med" configuration. */
3684 DEFUN_YANG (bgp_bestpath_med,
3685 bgp_bestpath_med_cmd,
3686 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
3687 "BGP specific commands\n"
3688 "Change the default bestpath selection\n"
3689 "MED attribute\n"
3690 "Compare MED among confederation paths\n"
3691 "Treat missing MED as the least preferred one\n"
3692 "Treat missing MED as the least preferred one\n"
3693 "Compare MED among confederation paths\n")
3694 {
3695 int idx = 0;
3696 bool confed = false;
3697 bool worst_med = false;
3698
3699
3700 if (argv_find(argv, argc, "confed", &idx))
3701 confed = true;
3702
3703 nb_cli_enqueue_change(vty,
3704 "./global/route-selection-options/confed-med",
3705 NB_OP_MODIFY, confed ? "true" : "false");
3706
3707 idx = 0;
3708 if (argv_find(argv, argc, "missing-as-worst", &idx))
3709 worst_med = true;
3710
3711 nb_cli_enqueue_change(
3712 vty, "./global/route-selection-options/missing-as-worst-med",
3713 NB_OP_MODIFY, worst_med ? "true" : "false");
3714
3715 return nb_cli_apply_changes(vty, NULL);
3716 }
3717
3718 DEFUN_YANG (no_bgp_bestpath_med,
3719 no_bgp_bestpath_med_cmd,
3720 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
3721 NO_STR
3722 "BGP specific commands\n"
3723 "Change the default bestpath selection\n"
3724 "MED attribute\n"
3725 "Compare MED among confederation paths\n"
3726 "Treat missing MED as the least preferred one\n"
3727 "Treat missing MED as the least preferred one\n"
3728 "Compare MED among confederation paths\n")
3729 {
3730 int idx = 0;
3731
3732 if (argv_find(argv, argc, "confed", &idx))
3733 nb_cli_enqueue_change(
3734 vty, "./global/route-selection-options/confed-med",
3735 NB_OP_MODIFY, "false");
3736
3737 idx = 0;
3738 if (argv_find(argv, argc, "missing-as-worst", &idx))
3739 nb_cli_enqueue_change(
3740 vty,
3741 "./global/route-selection-options/missing-as-worst-med",
3742 NB_OP_MODIFY, "false");
3743
3744 return nb_cli_apply_changes(vty, NULL);
3745 }
3746
3747 /* "bgp bestpath bandwidth" configuration. */
3748 DEFPY (bgp_bestpath_bw,
3749 bgp_bestpath_bw_cmd,
3750 "bgp bestpath bandwidth <ignore|skip-missing|default-weight-for-missing>$bw_cfg",
3751 "BGP specific commands\n"
3752 "Change the default bestpath selection\n"
3753 "Link Bandwidth attribute\n"
3754 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3755 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3756 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3757 {
3758 VTY_DECLVAR_CONTEXT(bgp, bgp);
3759 afi_t afi;
3760 safi_t safi;
3761
3762 if (!bw_cfg) {
3763 vty_out(vty, "%% Bandwidth configuration must be specified\n");
3764 return CMD_ERR_INCOMPLETE;
3765 }
3766 if (!strcmp(bw_cfg, "ignore"))
3767 bgp->lb_handling = BGP_LINK_BW_IGNORE_BW;
3768 else if (!strcmp(bw_cfg, "skip-missing"))
3769 bgp->lb_handling = BGP_LINK_BW_SKIP_MISSING;
3770 else if (!strcmp(bw_cfg, "default-weight-for-missing"))
3771 bgp->lb_handling = BGP_LINK_BW_DEFWT_4_MISSING;
3772 else
3773 return CMD_ERR_NO_MATCH;
3774
3775 /* This config is used in route install, so redo that. */
3776 FOREACH_AFI_SAFI (afi, safi) {
3777 if (!bgp_fibupd_safi(safi))
3778 continue;
3779 bgp_zebra_announce_table(bgp, afi, safi);
3780 }
3781
3782 return CMD_SUCCESS;
3783 }
3784
3785 DEFPY (no_bgp_bestpath_bw,
3786 no_bgp_bestpath_bw_cmd,
3787 "no bgp bestpath bandwidth [<ignore|skip-missing|default-weight-for-missing>$bw_cfg]",
3788 NO_STR
3789 "BGP specific commands\n"
3790 "Change the default bestpath selection\n"
3791 "Link Bandwidth attribute\n"
3792 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3793 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3794 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3795 {
3796 VTY_DECLVAR_CONTEXT(bgp, bgp);
3797 afi_t afi;
3798 safi_t safi;
3799
3800 bgp->lb_handling = BGP_LINK_BW_ECMP;
3801
3802 /* This config is used in route install, so redo that. */
3803 FOREACH_AFI_SAFI (afi, safi) {
3804 if (!bgp_fibupd_safi(safi))
3805 continue;
3806 bgp_zebra_announce_table(bgp, afi, safi);
3807 }
3808 return CMD_SUCCESS;
3809 }
3810
3811 DEFPY(bgp_default_afi_safi, bgp_default_afi_safi_cmd,
3812 "[no] bgp default <ipv4-unicast|"
3813 "ipv4-multicast|"
3814 "ipv4-vpn|"
3815 "ipv4-labeled-unicast|"
3816 "ipv4-flowspec|"
3817 "ipv6-unicast|"
3818 "ipv6-multicast|"
3819 "ipv6-vpn|"
3820 "ipv6-labeled-unicast|"
3821 "ipv6-flowspec|"
3822 "l2vpn-evpn>$afi_safi",
3823 NO_STR
3824 "BGP specific commands\n"
3825 "Configure BGP defaults\n"
3826 "Activate ipv4-unicast for a peer by default\n"
3827 "Activate ipv4-multicast for a peer by default\n"
3828 "Activate ipv4-vpn for a peer by default\n"
3829 "Activate ipv4-labeled-unicast for a peer by default\n"
3830 "Activate ipv4-flowspec for a peer by default\n"
3831 "Activate ipv6-unicast for a peer by default\n"
3832 "Activate ipv6-multicast for a peer by default\n"
3833 "Activate ipv6-vpn for a peer by default\n"
3834 "Activate ipv6-labeled-unicast for a peer by default\n"
3835 "Activate ipv6-flowspec for a peer by default\n"
3836 "Activate l2vpn-evpn for a peer by default\n")
3837 {
3838 VTY_DECLVAR_CONTEXT(bgp, bgp);
3839 char afi_safi_str[strlen(afi_safi) + 1];
3840 char *afi_safi_str_tok;
3841
3842 strlcpy(afi_safi_str, afi_safi, sizeof(afi_safi_str));
3843 char *afi_str = strtok_r(afi_safi_str, "-", &afi_safi_str_tok);
3844 char *safi_str = strtok_r(NULL, "-", &afi_safi_str_tok);
3845 afi_t afi = bgp_vty_afi_from_str(afi_str);
3846 safi_t safi;
3847
3848 if (strmatch(safi_str, "labeled"))
3849 safi = bgp_vty_safi_from_str("labeled-unicast");
3850 else
3851 safi = bgp_vty_safi_from_str(safi_str);
3852
3853 if (no)
3854 bgp->default_af[afi][safi] = false;
3855 else {
3856 if ((safi == SAFI_LABELED_UNICAST
3857 && bgp->default_af[afi][SAFI_UNICAST])
3858 || (safi == SAFI_UNICAST
3859 && bgp->default_af[afi][SAFI_LABELED_UNICAST]))
3860 bgp_vty_return(vty, BGP_ERR_PEER_SAFI_CONFLICT);
3861 else
3862 bgp->default_af[afi][safi] = true;
3863 }
3864
3865 return CMD_SUCCESS;
3866 }
3867
3868 /* Display hostname in certain command outputs */
3869 DEFUN_YANG (bgp_default_show_hostname,
3870 bgp_default_show_hostname_cmd,
3871 "bgp default show-hostname",
3872 "BGP specific commands\n"
3873 "Configure BGP defaults\n"
3874 "Show hostname in certain command outputs\n")
3875 {
3876 nb_cli_enqueue_change(vty, "./global/show-hostname", NB_OP_MODIFY,
3877 "true");
3878
3879 return nb_cli_apply_changes(vty, NULL);
3880 }
3881
3882 DEFUN_YANG(no_bgp_default_show_hostname,
3883 no_bgp_default_show_hostname_cmd,
3884 "no bgp default show-hostname",
3885 NO_STR
3886 "BGP specific commands\n"
3887 "Configure BGP defaults\n"
3888 "Show hostname in certain command outputs\n")
3889 {
3890 nb_cli_enqueue_change(vty, "./global/show-hostname", NB_OP_MODIFY,
3891 "false");
3892
3893 return nb_cli_apply_changes(vty, NULL);
3894 }
3895
3896 void cli_show_router_bgp_show_hostname(struct vty *vty, struct lyd_node *dnode,
3897 bool show_defaults)
3898 {
3899 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_SHOW_HOSTNAME)
3900 vty_out(vty, " bgp default show-hostname\n");
3901 }
3902
3903 /* Display hostname in certain command outputs */
3904 DEFUN_YANG(bgp_default_show_nexthop_hostname,
3905 bgp_default_show_nexthop_hostname_cmd,
3906 "bgp default show-nexthop-hostname",
3907 "BGP specific commands\n"
3908 "Configure BGP defaults\n"
3909 "Show hostname for nexthop in certain command outputs\n")
3910 {
3911 nb_cli_enqueue_change(vty, "./global/show-nexthop-hostname",
3912 NB_OP_MODIFY, "true");
3913
3914 return nb_cli_apply_changes(vty, NULL);
3915 }
3916
3917 DEFUN (no_bgp_default_show_nexthop_hostname,
3918 no_bgp_default_show_nexthop_hostname_cmd,
3919 "no bgp default show-nexthop-hostname",
3920 NO_STR
3921 "BGP specific commands\n"
3922 "Configure BGP defaults\n"
3923 "Show hostname for nexthop in certain command outputs\n")
3924 {
3925 nb_cli_enqueue_change(vty, "./global/show-nexthop-hostname",
3926 NB_OP_MODIFY, "false");
3927
3928 return nb_cli_apply_changes(vty, NULL);
3929 }
3930
3931 void cli_show_router_bgp_show_nexthop_hostname(struct vty *vty,
3932 struct lyd_node *dnode,
3933 bool show_defaults)
3934 {
3935 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_SHOW_HOSTNAME)
3936 vty_out(vty, " bgp default show-nexthop-hostname\n");
3937 }
3938
3939 /* "bgp network import-check" configuration. */
3940 DEFUN_YANG(bgp_network_import_check,
3941 bgp_network_import_check_cmd,
3942 "bgp network import-check",
3943 "BGP specific commands\n"
3944 "BGP network command\n"
3945 "Check BGP network route exists in IGP\n")
3946 {
3947 nb_cli_enqueue_change(vty, "./global/import-check", NB_OP_MODIFY,
3948 "true");
3949
3950 return nb_cli_apply_changes(vty, NULL);
3951 }
3952
3953 ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
3954 "bgp network import-check exact",
3955 "BGP specific commands\n"
3956 "BGP network command\n"
3957 "Check BGP network route exists in IGP\n"
3958 "Match route precisely\n")
3959
3960 DEFUN_YANG(no_bgp_network_import_check,
3961 no_bgp_network_import_check_cmd,
3962 "no bgp network import-check",
3963 NO_STR
3964 "BGP specific commands\n"
3965 "BGP network command\n"
3966 "Check BGP network route exists in IGP\n")
3967 {
3968 nb_cli_enqueue_change(vty, "./global/import-check", NB_OP_MODIFY,
3969 "false");
3970
3971 return nb_cli_apply_changes(vty, NULL);
3972 }
3973
3974 void cli_show_router_bgp_import_check(struct vty *vty, struct lyd_node *dnode,
3975 bool show_defaults)
3976 {
3977 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_IMPORT_CHECK)
3978 vty_out(vty, " bgp network import-check\n");
3979 }
3980
3981 DEFUN_YANG(bgp_default_local_preference,
3982 bgp_default_local_preference_cmd,
3983 "bgp default local-preference (0-4294967295)",
3984 "BGP specific commands\n"
3985 "Configure BGP defaults\n"
3986 "local preference (higher=more preferred)\n"
3987 "Configure default local preference value\n")
3988 {
3989 int idx_number = 3;
3990
3991 nb_cli_enqueue_change(vty, "./global/local-pref", NB_OP_MODIFY,
3992 argv[idx_number]->arg);
3993
3994 return nb_cli_apply_changes(vty, NULL);
3995 }
3996
3997 DEFUN_YANG(no_bgp_default_local_preference,
3998 no_bgp_default_local_preference_cmd,
3999 "no bgp default local-preference [(0-4294967295)]",
4000 NO_STR
4001 "BGP specific commands\n"
4002 "Configure BGP defaults\n"
4003 "local preference (higher=more preferred)\n"
4004 "Configure default local preference value\n")
4005 {
4006 nb_cli_enqueue_change(vty, "./global/local-pref", NB_OP_MODIFY, NULL);
4007
4008 return nb_cli_apply_changes(vty, NULL);
4009 }
4010
4011 void cli_show_router_bgp_local_pref(struct vty *vty, struct lyd_node *dnode,
4012 bool show_defaults)
4013 {
4014 vty_out(vty, " bgp default local-preference %u\n",
4015 yang_dnode_get_uint32(dnode, NULL));
4016 }
4017
4018
4019 DEFUN_YANG(bgp_default_subgroup_pkt_queue_max,
4020 bgp_default_subgroup_pkt_queue_max_cmd,
4021 "bgp default subgroup-pkt-queue-max (20-100)",
4022 "BGP specific commands\n"
4023 "Configure BGP defaults\n"
4024 "subgroup-pkt-queue-max\n"
4025 "Configure subgroup packet queue max\n")
4026 {
4027 int idx_number = 3;
4028
4029 nb_cli_enqueue_change(
4030 vty,
4031 "./global/global-update-group-config/subgroup-pkt-queue-size",
4032 NB_OP_MODIFY, argv[idx_number]->arg);
4033
4034 return nb_cli_apply_changes(vty, NULL);
4035 }
4036
4037 DEFUN_YANG(no_bgp_default_subgroup_pkt_queue_max,
4038 no_bgp_default_subgroup_pkt_queue_max_cmd,
4039 "no bgp default subgroup-pkt-queue-max [(20-100)]",
4040 NO_STR
4041 "BGP specific commands\n"
4042 "Configure BGP defaults\n"
4043 "subgroup-pkt-queue-max\n"
4044 "Configure subgroup packet queue max\n")
4045 {
4046 nb_cli_enqueue_change(
4047 vty,
4048 "./global/global-update-group-config/subgroup-pkt-queue-size",
4049 NB_OP_MODIFY, NULL);
4050
4051 return nb_cli_apply_changes(vty, NULL);
4052 }
4053
4054 void cli_show_router_global_update_group_config_subgroup_pkt_queue_size(
4055 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
4056 {
4057 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
4058 yang_dnode_get_uint32(dnode, NULL));
4059 }
4060
4061 DEFUN_YANG(bgp_rr_allow_outbound_policy,
4062 bgp_rr_allow_outbound_policy_cmd,
4063 "bgp route-reflector allow-outbound-policy",
4064 "BGP specific commands\n"
4065 "Allow modifications made by out route-map\n"
4066 "on ibgp neighbors\n")
4067 {
4068 nb_cli_enqueue_change(vty,
4069 "./global/route-reflector/allow-outbound-policy",
4070 NB_OP_MODIFY, "true");
4071
4072 return nb_cli_apply_changes(vty, NULL);
4073 }
4074
4075 DEFUN_YANG(no_bgp_rr_allow_outbound_policy,
4076 no_bgp_rr_allow_outbound_policy_cmd,
4077 "no bgp route-reflector allow-outbound-policy",
4078 NO_STR
4079 "BGP specific commands\n"
4080 "Allow modifications made by out route-map\n"
4081 "on ibgp neighbors\n")
4082 {
4083 nb_cli_enqueue_change(vty,
4084 "./global/route-reflector/allow-outbound-policy",
4085 NB_OP_MODIFY, "false");
4086
4087 return nb_cli_apply_changes(vty, NULL);
4088 }
4089
4090
4091 void cli_show_router_global_neighbor_config(struct vty *vty,
4092 struct lyd_node *dnode,
4093 bool show_defaults)
4094 {
4095 uint32_t write_quanta, read_quanta;
4096
4097 if (yang_dnode_get_bool(dnode, "./log-neighbor-changes"))
4098 vty_out(vty, " bgp log-neighbor-changes\n");
4099
4100 if (yang_dnode_exists(dnode, "./dynamic-neighbors-limit")) {
4101 uint32_t listen_limit = yang_dnode_get_uint32(
4102 dnode, "./dynamic-neighbors-limit");
4103 vty_out(vty, " bgp listen limit %u\n", listen_limit);
4104 }
4105
4106 write_quanta = yang_dnode_get_uint32(
4107 dnode, "./packet-quanta-config/wpkt-quanta");
4108 if (write_quanta != BGP_WRITE_PACKET_MAX)
4109 vty_out(vty, " write-quanta %d\n", write_quanta);
4110
4111 read_quanta = yang_dnode_get_uint32(
4112 dnode, "./packet-quanta-config/rpkt-quanta");
4113
4114 if (read_quanta != BGP_READ_PACKET_MAX)
4115 vty_out(vty, " read-quanta %d\n", read_quanta);
4116 }
4117
4118 DEFUN_YANG(bgp_listen_limit,
4119 bgp_listen_limit_cmd,
4120 "bgp listen limit (1-65535)",
4121 "BGP specific commands\n"
4122 "BGP Dynamic Neighbors listen commands\n"
4123 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4124 "Configure Dynamic Neighbors listen limit value\n")
4125 {
4126 int idx_number = 3;
4127
4128 nb_cli_enqueue_change(
4129 vty, "./global/global-neighbor-config/dynamic-neighbors-limit",
4130 NB_OP_MODIFY, argv[idx_number]->arg);
4131
4132 return nb_cli_apply_changes(vty, NULL);
4133 }
4134
4135 DEFUN_YANG(no_bgp_listen_limit,
4136 no_bgp_listen_limit_cmd,
4137 "no bgp listen limit [(1-65535)]",
4138 NO_STR
4139 "BGP specific commands\n"
4140 "BGP Dynamic Neighbors listen commands\n"
4141 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4142 "Configure Dynamic Neighbors listen limit value\n")
4143 {
4144 nb_cli_enqueue_change(
4145 vty, "./global/global-neighbor-config/dynamic-neighbors-limit",
4146 NB_OP_DESTROY, NULL);
4147
4148 return nb_cli_apply_changes(vty, NULL);
4149 }
4150
4151
4152 /*
4153 * Check if this listen range is already configured. Check for exact
4154 * match or overlap based on input.
4155 */
4156 static struct peer_group *listen_range_exists(struct bgp *bgp,
4157 struct prefix *range, int exact)
4158 {
4159 struct listnode *node, *nnode;
4160 struct listnode *node1, *nnode1;
4161 struct peer_group *group;
4162 struct prefix *lr;
4163 afi_t afi;
4164 int match;
4165
4166 afi = family2afi(range->family);
4167 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4168 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
4169 lr)) {
4170 if (exact)
4171 match = prefix_same(range, lr);
4172 else
4173 match = (prefix_match(range, lr)
4174 || prefix_match(lr, range));
4175 if (match)
4176 return group;
4177 }
4178 }
4179
4180 return NULL;
4181 }
4182
4183 DEFUN (bgp_listen_range,
4184 bgp_listen_range_cmd,
4185 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
4186 "BGP specific commands\n"
4187 "Configure BGP dynamic neighbors listen range\n"
4188 "Configure BGP dynamic neighbors listen range\n"
4189 NEIGHBOR_ADDR_STR
4190 "Member of the peer-group\n"
4191 "Peer-group name\n")
4192 {
4193 VTY_DECLVAR_CONTEXT(bgp, bgp);
4194 struct prefix range;
4195 struct peer_group *group, *existing_group;
4196 afi_t afi;
4197 int ret;
4198 int idx = 0;
4199
4200 argv_find(argv, argc, "A.B.C.D/M", &idx);
4201 argv_find(argv, argc, "X:X::X:X/M", &idx);
4202 char *prefix = argv[idx]->arg;
4203 argv_find(argv, argc, "PGNAME", &idx);
4204 char *peergroup = argv[idx]->arg;
4205
4206 /* Convert IP prefix string to struct prefix. */
4207 ret = str2prefix(prefix, &range);
4208 if (!ret) {
4209 vty_out(vty, "%% Malformed listen range\n");
4210 return CMD_WARNING_CONFIG_FAILED;
4211 }
4212
4213 afi = family2afi(range.family);
4214
4215 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4216 vty_out(vty,
4217 "%% Malformed listen range (link-local address)\n");
4218 return CMD_WARNING_CONFIG_FAILED;
4219 }
4220
4221 apply_mask(&range);
4222
4223 /* Check if same listen range is already configured. */
4224 existing_group = listen_range_exists(bgp, &range, 1);
4225 if (existing_group) {
4226 if (strcmp(existing_group->name, peergroup) == 0)
4227 return CMD_SUCCESS;
4228 else {
4229 vty_out(vty,
4230 "%% Same listen range is attached to peer-group %s\n",
4231 existing_group->name);
4232 return CMD_WARNING_CONFIG_FAILED;
4233 }
4234 }
4235
4236 /* Check if an overlapping listen range exists. */
4237 if (listen_range_exists(bgp, &range, 0)) {
4238 vty_out(vty,
4239 "%% Listen range overlaps with existing listen range\n");
4240 return CMD_WARNING_CONFIG_FAILED;
4241 }
4242
4243 group = peer_group_lookup(bgp, peergroup);
4244 if (!group) {
4245 vty_out(vty, "%% Configure the peer-group first\n");
4246 return CMD_WARNING_CONFIG_FAILED;
4247 }
4248
4249 ret = peer_group_listen_range_add(group, &range);
4250 return bgp_vty_return(vty, ret);
4251 }
4252
4253 DEFUN (no_bgp_listen_range,
4254 no_bgp_listen_range_cmd,
4255 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
4256 NO_STR
4257 "BGP specific commands\n"
4258 "Unconfigure BGP dynamic neighbors listen range\n"
4259 "Unconfigure BGP dynamic neighbors listen range\n"
4260 NEIGHBOR_ADDR_STR
4261 "Member of the peer-group\n"
4262 "Peer-group name\n")
4263 {
4264 VTY_DECLVAR_CONTEXT(bgp, bgp);
4265 struct prefix range;
4266 struct peer_group *group;
4267 afi_t afi;
4268 int ret;
4269 int idx = 0;
4270
4271 argv_find(argv, argc, "A.B.C.D/M", &idx);
4272 argv_find(argv, argc, "X:X::X:X/M", &idx);
4273 char *prefix = argv[idx]->arg;
4274 argv_find(argv, argc, "PGNAME", &idx);
4275 char *peergroup = argv[idx]->arg;
4276
4277 /* Convert IP prefix string to struct prefix. */
4278 ret = str2prefix(prefix, &range);
4279 if (!ret) {
4280 vty_out(vty, "%% Malformed listen range\n");
4281 return CMD_WARNING_CONFIG_FAILED;
4282 }
4283
4284 afi = family2afi(range.family);
4285
4286 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4287 vty_out(vty,
4288 "%% Malformed listen range (link-local address)\n");
4289 return CMD_WARNING_CONFIG_FAILED;
4290 }
4291
4292 apply_mask(&range);
4293
4294 group = peer_group_lookup(bgp, peergroup);
4295 if (!group) {
4296 vty_out(vty, "%% Peer-group does not exist\n");
4297 return CMD_WARNING_CONFIG_FAILED;
4298 }
4299
4300 ret = peer_group_listen_range_del(group, &range);
4301 return bgp_vty_return(vty, ret);
4302 }
4303
4304 void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
4305 {
4306 struct peer_group *group;
4307 struct listnode *node, *nnode, *rnode, *nrnode;
4308 struct prefix *range;
4309 afi_t afi;
4310
4311 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
4312 vty_out(vty, " bgp listen limit %d\n",
4313 bgp->dynamic_neighbors_limit);
4314
4315 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4316 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
4317 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
4318 nrnode, range)) {
4319 vty_out(vty,
4320 " bgp listen range %pFX peer-group %s\n",
4321 range, group->name);
4322 }
4323 }
4324 }
4325 }
4326
4327
4328 DEFUN_YANG(bgp_disable_connected_route_check,
4329 bgp_disable_connected_route_check_cmd,
4330 "bgp disable-ebgp-connected-route-check",
4331 "BGP specific commands\n"
4332 "Disable checking if nexthop is connected on ebgp sessions\n")
4333 {
4334 nb_cli_enqueue_change(vty,
4335 "./global/ebgp-multihop-connected-route-check",
4336 NB_OP_MODIFY, "true");
4337
4338 return nb_cli_apply_changes(vty, NULL);
4339 }
4340
4341 DEFUN_YANG(no_bgp_disable_connected_route_check,
4342 no_bgp_disable_connected_route_check_cmd,
4343 "no bgp disable-ebgp-connected-route-check",
4344 NO_STR
4345 "BGP specific commands\n"
4346 "Disable checking if nexthop is connected on ebgp sessions\n")
4347 {
4348 nb_cli_enqueue_change(vty,
4349 "./global/ebgp-multihop-connected-route-check",
4350 NB_OP_MODIFY, "false");
4351
4352 return nb_cli_apply_changes(vty, NULL);
4353 }
4354
4355 void cli_show_router_global_ebgp_multihop_connected_route_check(
4356 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
4357 {
4358 if (yang_dnode_get_bool(dnode, NULL))
4359 vty_out(vty, " bgp disable-ebgp-connected-route-check\n");
4360 }
4361
4362 DEFUN_YANG(bgp_default_shutdown,
4363 bgp_default_shutdown_cmd,
4364 "[no] bgp default shutdown",
4365 NO_STR BGP_STR
4366 "Configure BGP defaults\n"
4367 "Apply administrative shutdown to newly configured peers\n")
4368 {
4369 nb_cli_enqueue_change(vty, "./global/default-shutdown", NB_OP_MODIFY,
4370 strmatch(argv[0]->text, "no") ? "false" : "true");
4371
4372 return nb_cli_apply_changes(vty, NULL);
4373 }
4374
4375 void cli_show_router_bgp_default_shutdown(struct vty *vty,
4376 struct lyd_node *dnode,
4377 bool show_defaults)
4378 {
4379 if (yang_dnode_get_bool(dnode, NULL))
4380 vty_out(vty, " bgp default shutdown\n");
4381 }
4382
4383 DEFPY(bgp_shutdown_msg, bgp_shutdown_msg_cmd, "bgp shutdown message MSG...",
4384 BGP_STR
4385 "Administrative shutdown of the BGP instance\n"
4386 "Add a shutdown message (RFC 8203)\n"
4387 "Shutdown message\n")
4388 {
4389 char *msgstr = NULL;
4390
4391 VTY_DECLVAR_CONTEXT(bgp, bgp);
4392
4393 if (argc > 3)
4394 msgstr = argv_concat(argv, argc, 3);
4395
4396 bgp_shutdown_enable(bgp, msgstr);
4397 XFREE(MTYPE_TMP, msgstr);
4398
4399 return CMD_SUCCESS;
4400 }
4401
4402 DEFPY(bgp_shutdown, bgp_shutdown_cmd, "bgp shutdown",
4403 BGP_STR "Administrative shutdown of the BGP instance\n")
4404 {
4405 VTY_DECLVAR_CONTEXT(bgp, bgp);
4406
4407 bgp_shutdown_enable(bgp, NULL);
4408
4409 return CMD_SUCCESS;
4410 }
4411
4412 DEFPY(no_bgp_shutdown, no_bgp_shutdown_cmd, "no bgp shutdown",
4413 NO_STR BGP_STR "Administrative shutdown of the BGP instance\n")
4414 {
4415 VTY_DECLVAR_CONTEXT(bgp, bgp);
4416
4417 bgp_shutdown_disable(bgp);
4418
4419 return CMD_SUCCESS;
4420 }
4421
4422 ALIAS(no_bgp_shutdown, no_bgp_shutdown_msg_cmd,
4423 "no bgp shutdown message MSG...", NO_STR BGP_STR
4424 "Administrative shutdown of the BGP instance\n"
4425 "Add a shutdown message (RFC 8203)\n" "Shutdown message\n")
4426
4427 DEFUN_YANG(neighbor_remote_as,
4428 neighbor_remote_as_cmd,
4429 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
4430 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4431 "Specify a BGP neighbor\n" AS_STR
4432 "Internal BGP peer\n"
4433 "External BGP peer\n")
4434 {
4435 int idx_peer = 1;
4436 int idx_remote_as = 3;
4437 char base_xpath[XPATH_MAXLEN];
4438 char unnbr_xpath[XPATH_MAXLEN];
4439 char prgrp_xpath[XPATH_MAXLEN];
4440 union sockunion su;
4441 const char *as_type_str = "as-specified";
4442
4443 if (str2sockunion(argv[idx_peer]->arg, &su) < 0) {
4444 snprintf(unnbr_xpath, sizeof(unnbr_xpath),
4445 FRR_BGP_NEIGHBOR_UNNUM_XPATH, argv[idx_peer]->arg, "");
4446
4447 snprintf(prgrp_xpath, sizeof(prgrp_xpath),
4448 FRR_BGP_PEER_GROUP_XPATH, argv[idx_peer]->arg, "");
4449
4450 if (yang_dnode_existsf(vty->candidate_config->dnode, "%s%s",
4451 VTY_CURR_XPATH, unnbr_xpath + 1)) {
4452 strlcpy(base_xpath, unnbr_xpath, sizeof(base_xpath));
4453 } else if (yang_dnode_existsf(vty->candidate_config->dnode,
4454 "%s%s", VTY_CURR_XPATH,
4455 prgrp_xpath + 1)) {
4456 snprintf(base_xpath, sizeof(base_xpath),
4457 FRR_BGP_PEER_GROUP_XPATH, argv[idx_peer]->arg,
4458 "");
4459 } else {
4460 vty_out(vty,
4461 "%% Create the peer-group or interface first\n");
4462 return CMD_WARNING_CONFIG_FAILED;
4463 }
4464 } else {
4465 snprintf(base_xpath, sizeof(base_xpath),
4466 FRR_BGP_NEIGHBOR_NUM_XPATH, argv[idx_peer]->arg, "");
4467 }
4468
4469 if (argv[idx_remote_as]->arg[0] == 'i') {
4470 as_type_str = "internal";
4471 } else if (argv[idx_remote_as]->arg[0] == 'e') {
4472 as_type_str = "external";
4473 } else {
4474 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as",
4475 NB_OP_MODIFY, argv[idx_remote_as]->arg);
4476 }
4477 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as-type",
4478 NB_OP_MODIFY, as_type_str);
4479
4480 return nb_cli_apply_changes(vty, base_xpath);
4481 }
4482
4483 int peer_conf_interface_create(struct bgp *bgp, const char *conf_if,
4484 bool v6only, const char *peer_group_name,
4485 int as_type, as_t as, char *errmsg,
4486 size_t errmsg_len)
4487 {
4488 struct peer *peer;
4489 struct peer_group *group;
4490 int ret = 0;
4491
4492 group = peer_group_lookup(bgp, conf_if);
4493
4494 if (group) {
4495 snprintf(errmsg, errmsg_len,
4496 "Name conflict with peer-group \n");
4497 return -1;
4498 }
4499
4500 peer = peer_lookup_by_conf_if(bgp, conf_if);
4501 if (peer) {
4502 if (as_type != AS_UNSPECIFIED)
4503 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type);
4504 } else {
4505 peer = peer_create(NULL, conf_if, bgp, bgp->as, as, as_type,
4506 NULL);
4507
4508 if (!peer) {
4509 snprintf(errmsg, errmsg_len,
4510 "BGP failed to create peer\n");
4511 return -1;
4512 }
4513
4514 if (v6only)
4515 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
4516
4517 /* Request zebra to initiate IPv6 RAs on this interface. We do
4518 * this
4519 * any unnumbered peer in order to not worry about run-time
4520 * transitions
4521 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
4522 * address
4523 * gets deleted later etc.)
4524 */
4525 if (peer->ifp)
4526 bgp_zebra_initiate_radv(bgp, peer);
4527 }
4528
4529 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
4530 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
4531 if (v6only)
4532 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
4533 else
4534 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
4535
4536 /* v6only flag changed. Reset bgp seesion */
4537 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
4538 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
4539 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
4540 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
4541 } else
4542 bgp_session_reset(peer);
4543 }
4544
4545 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
4546 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
4547 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
4548 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
4549 }
4550
4551 if (peer_group_name) {
4552 group = peer_group_lookup(bgp, peer_group_name);
4553 if (!group) {
4554 snprintf(errmsg, errmsg_len,
4555 "Configure the peer-group first\n");
4556 return -1;
4557 }
4558
4559 ret = peer_group_bind(bgp, NULL, peer, group, &as);
4560 }
4561
4562 return bgp_nb_errmsg_return(errmsg, errmsg_len, ret);
4563 }
4564
4565 DEFUN_YANG(neighbor_interface_config,
4566 neighbor_interface_config_cmd,
4567 "neighbor WORD interface [peer-group PGNAME]",
4568 NEIGHBOR_STR
4569 "Interface name or neighbor tag\n"
4570 "Enable BGP on interface\n"
4571 "Member of the peer-group\n"
4572 "Peer-group name\n")
4573 {
4574 int idx_word = 1;
4575 int idx_peer_group_word = 4;
4576 char base_xpath[XPATH_MAXLEN];
4577
4578 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4579 argv[idx_word]->arg, "");
4580
4581 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
4582 if (argc > idx_peer_group_word)
4583 nb_cli_enqueue_change(vty, "./peer-group", NB_OP_MODIFY,
4584 argv[idx_peer_group_word]->arg);
4585
4586 return nb_cli_apply_changes(vty, base_xpath);
4587 }
4588
4589 DEFUN_YANG(neighbor_interface_config_v6only,
4590 neighbor_interface_config_v6only_cmd,
4591 "neighbor WORD interface v6only [peer-group PGNAME]",
4592 NEIGHBOR_STR
4593 "Interface name or neighbor tag\n"
4594 "Enable BGP on interface\n"
4595 "Enable BGP with v6 link-local only\n"
4596 "Member of the peer-group\n"
4597 "Peer-group name\n")
4598 {
4599 int idx_word = 1;
4600 int idx_peer_group_word = 5;
4601 char base_xpath[XPATH_MAXLEN];
4602
4603 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4604 argv[idx_word]->arg, "");
4605
4606 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
4607 if (argc > idx_peer_group_word)
4608 nb_cli_enqueue_change(vty, "./peer-group", NB_OP_MODIFY,
4609 argv[idx_peer_group_word]->arg);
4610
4611 nb_cli_enqueue_change(vty, "./v6only", NB_OP_MODIFY, "true");
4612
4613 return nb_cli_apply_changes(vty, base_xpath);
4614 }
4615
4616
4617 DEFUN_YANG(
4618 neighbor_interface_config_remote_as,
4619 neighbor_interface_config_remote_as_cmd,
4620 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
4621 NEIGHBOR_STR
4622 "Interface name or neighbor tag\n"
4623 "Enable BGP on interface\n"
4624 "Specify a BGP neighbor\n" AS_STR
4625 "Internal BGP peer\n"
4626 "External BGP peer\n")
4627 {
4628 int idx_word = 1;
4629 int idx_remote_as = 4;
4630 char base_xpath[XPATH_MAXLEN];
4631 const char *as_type_str = "as-specified";
4632
4633 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4634 argv[idx_word]->arg, "");
4635
4636 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
4637
4638 if (argv[idx_remote_as]->arg[0] == 'i') {
4639 as_type_str = "internal";
4640 } else if (argv[idx_remote_as]->arg[0] == 'e') {
4641 as_type_str = "external";
4642 } else {
4643 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as",
4644 NB_OP_MODIFY, argv[idx_remote_as]->arg);
4645 }
4646 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as-type",
4647 NB_OP_MODIFY, as_type_str);
4648
4649 return nb_cli_apply_changes(vty, base_xpath);
4650 }
4651
4652 DEFUN_YANG(
4653 neighbor_interface_v6only_config_remote_as,
4654 neighbor_interface_v6only_config_remote_as_cmd,
4655 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
4656 NEIGHBOR_STR
4657 "Interface name or neighbor tag\n"
4658 "Enable BGP with v6 link-local only\n"
4659 "Enable BGP on interface\n"
4660 "Specify a BGP neighbor\n" AS_STR
4661 "Internal BGP peer\n"
4662 "External BGP peer\n")
4663 {
4664 int idx_word = 1;
4665 int idx_remote_as = 5;
4666 char base_xpath[XPATH_MAXLEN];
4667 const char *as_type_str = "as-specified";
4668
4669 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4670 argv[idx_word]->arg, "");
4671
4672 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
4673
4674 nb_cli_enqueue_change(vty, "./v6only", NB_OP_MODIFY, "true");
4675
4676 if (argv[idx_remote_as]->arg[0] == 'i') {
4677 as_type_str = "internal";
4678 } else if (argv[idx_remote_as]->arg[0] == 'e') {
4679 as_type_str = "external";
4680 } else {
4681 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as",
4682 NB_OP_MODIFY, argv[idx_remote_as]->arg);
4683 }
4684 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as-type",
4685 NB_OP_MODIFY, as_type_str);
4686
4687 return nb_cli_apply_changes(vty, base_xpath);
4688 }
4689
4690 DEFUN_YANG(neighbor_peer_group, neighbor_peer_group_cmd,
4691 "neighbor WORD peer-group",
4692 NEIGHBOR_STR
4693 "Interface name or neighbor tag\n"
4694 "Configure peer-group\n")
4695 {
4696 char base_xpath[XPATH_MAXLEN];
4697 int idx_word = 1;
4698
4699 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_PEER_GROUP_XPATH,
4700 argv[idx_word]->arg, "");
4701
4702 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
4703
4704 return nb_cli_apply_changes(vty, base_xpath);
4705 }
4706
4707 DEFUN_YANG(no_neighbor,
4708 no_neighbor_cmd,
4709 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
4710 NO_STR NEIGHBOR_STR
4711 NEIGHBOR_ADDR_STR2
4712 "Specify a BGP neighbor\n" AS_STR
4713 "Internal BGP peer\n"
4714 "External BGP peer\n")
4715 {
4716 int idx_peer = 2;
4717 char base_xpath[XPATH_MAXLEN];
4718 char num_xpath[XPATH_MAXLEN];
4719 char unnbr_xpath[XPATH_MAXLEN];
4720 char prgrp_xpath[XPATH_MAXLEN];
4721 union sockunion su;
4722
4723 if (str2sockunion(argv[idx_peer]->arg, &su) == 0) {
4724 snprintf(num_xpath, sizeof(num_xpath),
4725 FRR_BGP_NEIGHBOR_NUM_XPATH, argv[idx_peer]->arg, "");
4726 if (yang_dnode_existsf(vty->candidate_config->dnode, "%s%s",
4727 VTY_CURR_XPATH, num_xpath + 1)) {
4728 strlcpy(base_xpath, num_xpath, sizeof(base_xpath));
4729 }
4730 } else {
4731 snprintf(unnbr_xpath, sizeof(unnbr_xpath),
4732 FRR_BGP_NEIGHBOR_UNNUM_XPATH, argv[idx_peer]->arg, "");
4733
4734 snprintf(prgrp_xpath, sizeof(prgrp_xpath),
4735 FRR_BGP_PEER_GROUP_XPATH, argv[idx_peer]->arg, "");
4736
4737 if (yang_dnode_existsf(vty->candidate_config->dnode, "%s%s",
4738 VTY_CURR_XPATH, unnbr_xpath + 1)) {
4739 strlcpy(base_xpath, unnbr_xpath, sizeof(base_xpath));
4740 } else if (yang_dnode_existsf(vty->candidate_config->dnode,
4741 "%s%s", VTY_CURR_XPATH,
4742 prgrp_xpath + 1)) {
4743 strlcpy(base_xpath, prgrp_xpath, sizeof(base_xpath));
4744 } else {
4745 vty_out(vty,
4746 "%% Create the peer-group or interface first\n");
4747 return CMD_WARNING_CONFIG_FAILED;
4748 }
4749 }
4750
4751 nb_cli_enqueue_change(vty, base_xpath, NB_OP_DESTROY, NULL);
4752
4753 /*
4754 * Need to commit any pending so this command doesn't merge with a
4755 * create into a modify, which BGP can't handle
4756 */
4757 return nb_cli_apply_changes_clear_pending(vty, NULL);
4758 }
4759
4760 DEFUN_YANG(no_neighbor_interface_config,
4761 no_neighbor_interface_config_cmd,
4762 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
4763 NO_STR NEIGHBOR_STR
4764 "Interface name\n"
4765 "Configure BGP on interface\n"
4766 "Enable BGP with v6 link-local only\n"
4767 "Member of the peer-group\n"
4768 "Peer-group name\n"
4769 "Specify a BGP neighbor\n" AS_STR
4770 "Internal BGP peer\n"
4771 "External BGP peer\n")
4772 {
4773 int idx_word = 2;
4774 char base_xpath[XPATH_MAXLEN];
4775
4776 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4777 argv[idx_word]->arg, "");
4778
4779 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
4780
4781 /*
4782 * Need to commit any pending so this command doesn't merge with a
4783 * create into a modify, which BGP can't handle
4784 */
4785 return nb_cli_apply_changes_clear_pending(vty, base_xpath);
4786 }
4787
4788 DEFUN_YANG(no_neighbor_peer_group,
4789 no_neighbor_peer_group_cmd,
4790 "no neighbor WORD peer-group",
4791 NO_STR NEIGHBOR_STR
4792 "Neighbor tag\n"
4793 "Configure peer-group\n")
4794 {
4795 char base_xpath[XPATH_MAXLEN];
4796 int idx_word = 2;
4797
4798 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_PEER_GROUP_XPATH,
4799 argv[idx_word]->arg, "");
4800
4801 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
4802
4803 /*
4804 * Need to commit any pending so this command doesn't merge with a
4805 * create into a modify, which BGP can't handle
4806 */
4807 return nb_cli_apply_changes_clear_pending(vty, base_xpath);
4808 }
4809
4810 DEFUN_YANG(no_neighbor_interface_peer_group_remote_as,
4811 no_neighbor_interface_peer_group_remote_as_cmd,
4812 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
4813 NO_STR NEIGHBOR_STR
4814 "Interface name or neighbor tag\n"
4815 "Specify a BGP neighbor\n" AS_STR
4816 "Internal BGP peer\n"
4817 "External BGP peer\n")
4818 {
4819 int idx_peer = 2;
4820 char base_xpath[XPATH_MAXLEN];
4821 char unnbr_xpath[XPATH_MAXLEN];
4822 char prgrp_xpath[XPATH_MAXLEN];
4823
4824 snprintf(unnbr_xpath, sizeof(unnbr_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4825 argv[idx_peer]->arg, "");
4826
4827 snprintf(prgrp_xpath, sizeof(prgrp_xpath), FRR_BGP_PEER_GROUP_XPATH,
4828 argv[idx_peer]->arg, "");
4829
4830 if (yang_dnode_existsf(vty->candidate_config->dnode, "%s%s",
4831 VTY_CURR_XPATH, unnbr_xpath + 1)) {
4832 strlcpy(base_xpath, unnbr_xpath, sizeof(base_xpath));
4833 } else if (yang_dnode_existsf(vty->candidate_config->dnode, "%s%s",
4834 VTY_CURR_XPATH, prgrp_xpath + 1)) {
4835 strlcpy(base_xpath, prgrp_xpath, sizeof(base_xpath));
4836 } else {
4837 vty_out(vty, "%% Create the peer-group or interface first\n");
4838 return CMD_WARNING_CONFIG_FAILED;
4839 }
4840
4841 strlcat(base_xpath, "/neighbor-remote-as/remote-as-type",
4842 sizeof(base_xpath));
4843
4844 nb_cli_enqueue_change(vty, base_xpath, NB_OP_DESTROY, NULL);
4845
4846 /*
4847 * Need to commit any pending so this command doesn't merge with a
4848 * create into a modify, which BGP can't handle
4849 */
4850 return nb_cli_apply_changes_clear_pending(vty, NULL);
4851 }
4852
4853 DEFUN_YANG(neighbor_local_as,
4854 neighbor_local_as_cmd,
4855 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
4856 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4857 "Specify a local-as number\n"
4858 "AS number used as local AS\n")
4859 {
4860 int idx_peer = 1;
4861 int idx_number = 3;
4862 char base_xpath[XPATH_MAXLEN];
4863
4864 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4865 sizeof(base_xpath), NULL)
4866 < 0)
4867 return CMD_WARNING_CONFIG_FAILED;
4868
4869 nb_cli_enqueue_change(vty, "./local-as/local-as", NB_OP_MODIFY,
4870 argv[idx_number]->arg);
4871
4872 return nb_cli_apply_changes(vty, base_xpath);
4873 }
4874
4875 DEFUN_YANG(
4876 neighbor_local_as_no_prepend, neighbor_local_as_no_prepend_cmd,
4877 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
4878 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4879 "Specify a local-as number\n"
4880 "AS number used as local AS\n"
4881 "Do not prepend local-as to updates from ebgp peers\n")
4882 {
4883 int idx_peer = 1;
4884 int idx_number = 3;
4885 char base_xpath[XPATH_MAXLEN];
4886
4887 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4888 sizeof(base_xpath), NULL)
4889 < 0)
4890 return CMD_WARNING_CONFIG_FAILED;
4891
4892 nb_cli_enqueue_change(vty, "./local-as/local-as", NB_OP_MODIFY,
4893 argv[idx_number]->arg);
4894 nb_cli_enqueue_change(vty, "./local-as/no-prepend", NB_OP_MODIFY,
4895 "true");
4896
4897 return nb_cli_apply_changes(vty, base_xpath);
4898 }
4899
4900 DEFUN_YANG(
4901 neighbor_local_as_no_prepend_replace_as,
4902 neighbor_local_as_no_prepend_replace_as_cmd,
4903 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
4904 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4905 "Specify a local-as number\n"
4906 "AS number used as local AS\n"
4907 "Do not prepend local-as to updates from ebgp peers\n"
4908 "Do not prepend local-as to updates from ibgp peers\n")
4909 {
4910 int idx_peer = 1;
4911 int idx_number = 3;
4912 char base_xpath[XPATH_MAXLEN];
4913
4914 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4915 sizeof(base_xpath), NULL)
4916 < 0)
4917 return CMD_WARNING_CONFIG_FAILED;
4918
4919 nb_cli_enqueue_change(vty, "./local-as/local-as", NB_OP_MODIFY,
4920 argv[idx_number]->arg);
4921 nb_cli_enqueue_change(vty, "./local-as/no-prepend", NB_OP_MODIFY,
4922 "true");
4923 nb_cli_enqueue_change(vty, "./local-as/replace-as", NB_OP_MODIFY,
4924 "true");
4925
4926 return nb_cli_apply_changes(vty, base_xpath);
4927 }
4928
4929 DEFUN_YANG(no_neighbor_local_as,
4930 no_neighbor_local_as_cmd,
4931 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
4932 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4933 "Specify a local-as number\n"
4934 "AS number used as local AS\n"
4935 "Do not prepend local-as to updates from ebgp peers\n"
4936 "Do not prepend local-as to updates from ibgp peers\n")
4937 {
4938 int idx_peer = 2;
4939 char base_xpath[XPATH_MAXLEN];
4940
4941 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4942 sizeof(base_xpath), NULL)
4943 < 0)
4944 return CMD_WARNING_CONFIG_FAILED;
4945
4946 nb_cli_enqueue_change(vty, "./local-as/local-as", NB_OP_DESTROY, NULL);
4947 nb_cli_enqueue_change(vty, "./local-as/no-prepend", NB_OP_MODIFY,
4948 "false");
4949 nb_cli_enqueue_change(vty, "./local-as/replace-as", NB_OP_MODIFY,
4950 "false");
4951
4952 return nb_cli_apply_changes(vty, base_xpath);
4953 }
4954
4955
4956 DEFUN (neighbor_solo,
4957 neighbor_solo_cmd,
4958 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
4959 NEIGHBOR_STR
4960 NEIGHBOR_ADDR_STR2
4961 "Solo peer - part of its own update group\n")
4962 {
4963 int idx_peer = 1;
4964 struct peer *peer;
4965 int ret;
4966
4967 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4968 if (!peer)
4969 return CMD_WARNING_CONFIG_FAILED;
4970
4971 ret = update_group_adjust_soloness(peer, 1);
4972 return bgp_vty_return(vty, ret);
4973 }
4974
4975 DEFUN (no_neighbor_solo,
4976 no_neighbor_solo_cmd,
4977 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
4978 NO_STR
4979 NEIGHBOR_STR
4980 NEIGHBOR_ADDR_STR2
4981 "Solo peer - part of its own update group\n")
4982 {
4983 int idx_peer = 2;
4984 struct peer *peer;
4985 int ret;
4986
4987 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4988 if (!peer)
4989 return CMD_WARNING_CONFIG_FAILED;
4990
4991 ret = update_group_adjust_soloness(peer, 0);
4992 return bgp_vty_return(vty, ret);
4993 }
4994
4995 DEFUN_YANG(neighbor_password,
4996 neighbor_password_cmd,
4997 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
4998 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4999 "Set a password\n"
5000 "The password\n")
5001 {
5002 int idx_peer = 1;
5003 int idx_line = 3;
5004 char base_xpath[XPATH_MAXLEN];
5005
5006 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5007 sizeof(base_xpath), NULL)
5008 < 0)
5009 return CMD_WARNING_CONFIG_FAILED;
5010
5011 nb_cli_enqueue_change(vty, "./password", NB_OP_MODIFY,
5012 argv[idx_line]->arg);
5013
5014 return nb_cli_apply_changes(vty, base_xpath);
5015 }
5016
5017 DEFUN_YANG(no_neighbor_password,
5018 no_neighbor_password_cmd,
5019 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
5020 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5021 "Set a password\n"
5022 "The password\n")
5023 {
5024 int idx_peer = 2;
5025 char base_xpath[XPATH_MAXLEN];
5026
5027 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5028 sizeof(base_xpath), NULL)
5029 < 0)
5030 return CMD_WARNING_CONFIG_FAILED;
5031
5032 nb_cli_enqueue_change(vty, "./password", NB_OP_DESTROY, NULL);
5033
5034 return nb_cli_apply_changes(vty, base_xpath);
5035 }
5036
5037 DEFUN_YANG(neighbor_activate,
5038 neighbor_activate_cmd,
5039 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5040 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5041 "Enable the Address Family for this Neighbor\n")
5042 {
5043 int idx_peer = 1;
5044 char base_xpath[XPATH_MAXLEN];
5045 char af_xpath[XPATH_MAXLEN];
5046 afi_t afi = bgp_node_afi(vty);
5047 safi_t safi = bgp_node_safi(vty);
5048
5049 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5050 yang_afi_safi_value2identity(afi, safi));
5051 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5052 sizeof(base_xpath), af_xpath)
5053 < 0)
5054 return CMD_WARNING_CONFIG_FAILED;
5055
5056 nb_cli_enqueue_change(vty, "./enabled", NB_OP_MODIFY, "true");
5057
5058 return nb_cli_apply_changes(vty, base_xpath);
5059 }
5060
5061 ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
5062 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5063 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5064 "Enable the Address Family for this Neighbor\n")
5065
5066 DEFUN_YANG(no_neighbor_activate,
5067 no_neighbor_activate_cmd,
5068 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5069 NO_STR NEIGHBOR_STR
5070 NEIGHBOR_ADDR_STR2
5071 "Enable the Address Family for this Neighbor\n")
5072 {
5073 int idx_peer = 2;
5074 char base_xpath[XPATH_MAXLEN];
5075 char af_xpath[XPATH_MAXLEN];
5076 afi_t afi = bgp_node_afi(vty);
5077 safi_t safi = bgp_node_safi(vty);
5078
5079 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5080 yang_afi_safi_value2identity(afi, safi));
5081
5082 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5083 sizeof(base_xpath), af_xpath)
5084 < 0)
5085 return CMD_WARNING_CONFIG_FAILED;
5086
5087 nb_cli_enqueue_change(vty, "./enabled", NB_OP_MODIFY, "false");
5088
5089 return nb_cli_apply_changes(vty, base_xpath);
5090 }
5091
5092 ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
5093 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5094 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5095 "Enable the Address Family for this Neighbor\n")
5096
5097 DEFUN (neighbor_set_peer_group,
5098 neighbor_set_peer_group_cmd,
5099 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5100 NEIGHBOR_STR
5101 NEIGHBOR_ADDR_STR2
5102 "Member of the peer-group\n"
5103 "Peer-group name\n")
5104 {
5105 VTY_DECLVAR_CONTEXT(bgp, bgp);
5106 int idx_peer = 1;
5107 int idx_word = 3;
5108 int ret;
5109 as_t as;
5110 union sockunion su;
5111 struct peer *peer;
5112 struct peer_group *group;
5113
5114 ret = str2sockunion(argv[idx_peer]->arg, &su);
5115 if (ret < 0) {
5116 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
5117 if (!peer) {
5118 vty_out(vty, "%% Malformed address or name: %s\n",
5119 argv[idx_peer]->arg);
5120 return CMD_WARNING_CONFIG_FAILED;
5121 }
5122 } else {
5123 if (peer_address_self_check(bgp, &su)) {
5124 vty_out(vty,
5125 "%% Can not configure the local system as neighbor\n");
5126 return CMD_WARNING_CONFIG_FAILED;
5127 }
5128
5129 /* Disallow for dynamic neighbor. */
5130 peer = peer_lookup(bgp, &su);
5131 if (peer && peer_dynamic_neighbor(peer)) {
5132 vty_out(vty,
5133 "%% Operation not allowed on a dynamic neighbor\n");
5134 return CMD_WARNING_CONFIG_FAILED;
5135 }
5136 }
5137
5138 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5139 if (!group) {
5140 vty_out(vty, "%% Configure the peer-group first\n");
5141 return CMD_WARNING_CONFIG_FAILED;
5142 }
5143
5144 ret = peer_group_bind(bgp, &su, peer, group, &as);
5145
5146 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
5147 vty_out(vty,
5148 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
5149 as);
5150 return CMD_WARNING_CONFIG_FAILED;
5151 }
5152
5153 return bgp_vty_return(vty, ret);
5154 }
5155
5156 ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
5157 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5158 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5159 "Member of the peer-group\n"
5160 "Peer-group name\n")
5161
5162 DEFUN_YANG (no_neighbor_set_peer_group,
5163 no_neighbor_set_peer_group_cmd,
5164 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5165 NO_STR
5166 NEIGHBOR_STR
5167 NEIGHBOR_ADDR_STR2
5168 "Member of the peer-group\n"
5169 "Peer-group name\n")
5170 {
5171 int idx_peer = 2;
5172 char base_xpath[XPATH_MAXLEN];
5173
5174 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5175 sizeof(base_xpath), NULL)
5176 < 0)
5177 return CMD_WARNING_CONFIG_FAILED;
5178
5179 nb_cli_enqueue_change(vty, "./peer-group", NB_OP_DESTROY, NULL);
5180
5181 /*
5182 * Need to commit any pending so this command doesn't merge with a
5183 * create into a modify, which BGP can't handle
5184 */
5185 return nb_cli_apply_changes_clear_pending(vty, base_xpath);
5186 }
5187
5188 ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
5189 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5190 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5191 "Member of the peer-group\n"
5192 "Peer-group name\n")
5193
5194 static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
5195 uint32_t flag, int set)
5196 {
5197 int ret;
5198 struct peer *peer;
5199
5200 peer = peer_and_group_lookup_vty(vty, ip_str);
5201 if (!peer)
5202 return CMD_WARNING_CONFIG_FAILED;
5203
5204 /*
5205 * If 'neighbor <interface>', then this is for directly connected peers,
5206 * we should not accept disable-connected-check.
5207 */
5208 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
5209 vty_out(vty,
5210 "%s is directly connected peer, cannot accept disable-connected-check\n",
5211 ip_str);
5212 return CMD_WARNING_CONFIG_FAILED;
5213 }
5214
5215 if (!set && flag == PEER_FLAG_SHUTDOWN)
5216 peer_tx_shutdown_message_unset(peer);
5217
5218 if (set)
5219 ret = peer_flag_set(peer, flag);
5220 else
5221 ret = peer_flag_unset(peer, flag);
5222
5223 return bgp_vty_return(vty, ret);
5224 }
5225
5226 static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
5227 {
5228 return peer_flag_modify_vty(vty, ip_str, flag, 1);
5229 }
5230
5231 static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
5232 uint32_t flag)
5233 {
5234 return peer_flag_modify_vty(vty, ip_str, flag, 0);
5235 }
5236
5237 int peer_flag_modify_nb(struct bgp *bgp, const char *ip_str, struct peer *peer,
5238 uint32_t flag, bool set, char *errmsg,
5239 size_t errmsg_len)
5240 {
5241 int ret;
5242
5243 /*
5244 * If 'neighbor <interface>', then this is for directly connected peers,
5245 * we should not accept disable-connected-check.
5246 */
5247 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
5248 snprintf(
5249 errmsg, errmsg_len,
5250 "%s is directly connected peer, cannot accept disable-connected-check\n",
5251 ip_str);
5252 return -1;
5253 }
5254
5255 if (!set && flag == PEER_FLAG_SHUTDOWN)
5256 peer_tx_shutdown_message_unset(peer);
5257
5258 if (set)
5259 ret = peer_flag_set(peer, flag);
5260 else
5261 ret = peer_flag_unset(peer, flag);
5262
5263 return bgp_nb_errmsg_return(errmsg, errmsg_len, ret);
5264 }
5265
5266 /* neighbor passive. */
5267 DEFUN_YANG(neighbor_passive,
5268 neighbor_passive_cmd,
5269 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5270 NEIGHBOR_STR
5271 NEIGHBOR_ADDR_STR2
5272 "Don't send open messages to this neighbor\n")
5273 {
5274 int idx_peer = 1;
5275 char base_xpath[XPATH_MAXLEN];
5276
5277 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5278 sizeof(base_xpath), NULL)
5279 < 0)
5280 return CMD_WARNING_CONFIG_FAILED;
5281
5282 nb_cli_enqueue_change(vty, "./passive-mode", NB_OP_MODIFY, "true");
5283
5284 return nb_cli_apply_changes(vty, base_xpath);
5285 }
5286
5287 DEFUN_YANG(no_neighbor_passive,
5288 no_neighbor_passive_cmd,
5289 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5290 NO_STR NEIGHBOR_STR
5291 NEIGHBOR_ADDR_STR2
5292 "Don't send open messages to this neighbor\n")
5293 {
5294 int idx_peer = 2;
5295 char base_xpath[XPATH_MAXLEN];
5296
5297 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5298 sizeof(base_xpath), NULL)
5299 < 0)
5300 return CMD_WARNING_CONFIG_FAILED;
5301
5302 nb_cli_enqueue_change(vty, "./passive-mode", NB_OP_MODIFY, "false");
5303
5304 return nb_cli_apply_changes(vty, base_xpath);
5305 }
5306
5307 /* neighbor shutdown. */
5308 DEFUN_YANG(neighbor_shutdown_msg,
5309 neighbor_shutdown_msg_cmd,
5310 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5311 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5312 "Administratively shut down this neighbor\n"
5313 "Add a shutdown message (RFC 8203)\n"
5314 "Shutdown message\n")
5315 {
5316 int idx_peer = 1;
5317 char base_xpath[XPATH_MAXLEN];
5318
5319 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5320 sizeof(base_xpath), NULL)
5321 < 0)
5322 return CMD_WARNING_CONFIG_FAILED;
5323
5324 if (argc >= 5) {
5325 char *message;
5326
5327 message = argv_concat(argv, argc, 4);
5328 nb_cli_enqueue_change(vty, "./admin-shutdown/message",
5329 NB_OP_MODIFY, message);
5330 }
5331
5332 nb_cli_enqueue_change(vty, "./admin-shutdown/enable", NB_OP_MODIFY,
5333 "true");
5334
5335 return nb_cli_apply_changes(vty, base_xpath);
5336 }
5337
5338 ALIAS_YANG(neighbor_shutdown_msg, neighbor_shutdown_cmd,
5339 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5340 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5341 "Administratively shut down this neighbor\n")
5342
5343 DEFUN_YANG(no_neighbor_shutdown_msg,
5344 no_neighbor_shutdown_msg_cmd,
5345 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5346 NO_STR NEIGHBOR_STR
5347 NEIGHBOR_ADDR_STR2
5348 "Administratively shut down this neighbor\n"
5349 "Remove a shutdown message (RFC 8203)\n"
5350 "Shutdown message\n")
5351 {
5352 int idx_peer = 2;
5353 char base_xpath[XPATH_MAXLEN];
5354
5355 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5356 sizeof(base_xpath), NULL)
5357 < 0)
5358 return CMD_WARNING_CONFIG_FAILED;
5359
5360 nb_cli_enqueue_change(vty, "./admin-shutdown/enable", NB_OP_MODIFY,
5361 "false");
5362
5363 return nb_cli_apply_changes(vty, base_xpath);
5364 }
5365
5366 ALIAS_YANG(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
5367 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5368 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5369 "Administratively shut down this neighbor\n")
5370
5371 DEFUN(neighbor_shutdown_rtt,
5372 neighbor_shutdown_rtt_cmd,
5373 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt (1-65535) [count (1-255)]",
5374 NEIGHBOR_STR
5375 NEIGHBOR_ADDR_STR2
5376 "Administratively shut down this neighbor\n"
5377 "Shutdown if round-trip-time is higher than expected\n"
5378 "Round-trip-time in milliseconds\n"
5379 "Specify the number of keepalives before shutdown\n"
5380 "The number of keepalives with higher RTT to shutdown\n")
5381 {
5382 int idx_peer = 1;
5383 int idx_rtt = 4;
5384 int idx_count = 0;
5385 struct peer *peer;
5386
5387 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5388
5389 if (!peer)
5390 return CMD_WARNING_CONFIG_FAILED;
5391
5392 peer->rtt_expected = strtol(argv[idx_rtt]->arg, NULL, 10);
5393
5394 if (argv_find(argv, argc, "count", &idx_count))
5395 peer->rtt_keepalive_conf =
5396 strtol(argv[idx_count + 1]->arg, NULL, 10);
5397
5398 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5399 PEER_FLAG_RTT_SHUTDOWN);
5400 }
5401
5402 DEFUN(no_neighbor_shutdown_rtt,
5403 no_neighbor_shutdown_rtt_cmd,
5404 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt [(1-65535) [count (1-255)]]",
5405 NO_STR
5406 NEIGHBOR_STR
5407 NEIGHBOR_ADDR_STR2
5408 "Administratively shut down this neighbor\n"
5409 "Shutdown if round-trip-time is higher than expected\n"
5410 "Round-trip-time in milliseconds\n"
5411 "Specify the number of keepalives before shutdown\n"
5412 "The number of keepalives with higher RTT to shutdown\n")
5413 {
5414 int idx_peer = 2;
5415 struct peer *peer;
5416
5417 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5418
5419 if (!peer)
5420 return CMD_WARNING_CONFIG_FAILED;
5421
5422 peer->rtt_expected = 0;
5423 peer->rtt_keepalive_conf = 1;
5424
5425 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5426 PEER_FLAG_RTT_SHUTDOWN);
5427 }
5428
5429 /* neighbor capability dynamic. */
5430 DEFUN_YANG (neighbor_capability_dynamic,
5431 neighbor_capability_dynamic_cmd,
5432 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5433 NEIGHBOR_STR
5434 NEIGHBOR_ADDR_STR2
5435 "Advertise capability to the peer\n"
5436 "Advertise dynamic capability to this neighbor\n")
5437 {
5438 int idx_peer = 1;
5439 char base_xpath[XPATH_MAXLEN];
5440
5441 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5442 sizeof(base_xpath), NULL)
5443 < 0)
5444 return CMD_WARNING_CONFIG_FAILED;
5445
5446 nb_cli_enqueue_change(vty, "./capability-options/dynamic-capability",
5447 NB_OP_MODIFY, "true");
5448
5449 return nb_cli_apply_changes(vty, base_xpath);
5450 }
5451
5452 DEFUN_YANG (no_neighbor_capability_dynamic,
5453 no_neighbor_capability_dynamic_cmd,
5454 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5455 NO_STR
5456 NEIGHBOR_STR
5457 NEIGHBOR_ADDR_STR2
5458 "Advertise capability to the peer\n"
5459 "Advertise dynamic capability to this neighbor\n")
5460 {
5461 int idx_peer = 2;
5462 char base_xpath[XPATH_MAXLEN];
5463
5464 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5465 sizeof(base_xpath), NULL)
5466 < 0)
5467 return CMD_WARNING_CONFIG_FAILED;
5468
5469 nb_cli_enqueue_change(vty, "./capability-options/dynamic-capability",
5470 NB_OP_MODIFY, "false");
5471
5472 return nb_cli_apply_changes(vty, base_xpath);
5473 }
5474
5475 /* neighbor dont-capability-negotiate */
5476 DEFUN (neighbor_dont_capability_negotiate,
5477 neighbor_dont_capability_negotiate_cmd,
5478 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
5479 NEIGHBOR_STR
5480 NEIGHBOR_ADDR_STR2
5481 "Do not perform capability negotiation\n")
5482 {
5483 int idx_peer = 1;
5484 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5485 PEER_FLAG_DONT_CAPABILITY);
5486 }
5487
5488 DEFUN (no_neighbor_dont_capability_negotiate,
5489 no_neighbor_dont_capability_negotiate_cmd,
5490 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
5491 NO_STR
5492 NEIGHBOR_STR
5493 NEIGHBOR_ADDR_STR2
5494 "Do not perform capability negotiation\n")
5495 {
5496 int idx_peer = 2;
5497 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5498 PEER_FLAG_DONT_CAPABILITY);
5499 }
5500
5501 /* neighbor capability extended next hop encoding */
5502 DEFUN_YANG (neighbor_capability_enhe,
5503 neighbor_capability_enhe_cmd,
5504 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5505 NEIGHBOR_STR
5506 NEIGHBOR_ADDR_STR2
5507 "Advertise capability to the peer\n"
5508 "Advertise extended next-hop capability to the peer\n")
5509 {
5510 int idx_peer = 1;
5511 char base_xpath[XPATH_MAXLEN];
5512
5513 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5514 sizeof(base_xpath), NULL)
5515 < 0)
5516 return CMD_WARNING_CONFIG_FAILED;
5517
5518 nb_cli_enqueue_change(
5519 vty, "./capability-options/extended-nexthop-capability",
5520 NB_OP_MODIFY, "true");
5521
5522 return nb_cli_apply_changes(vty, base_xpath);
5523 }
5524
5525 DEFUN_YANG (no_neighbor_capability_enhe,
5526 no_neighbor_capability_enhe_cmd,
5527 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5528 NO_STR
5529 NEIGHBOR_STR
5530 NEIGHBOR_ADDR_STR2
5531 "Advertise capability to the peer\n"
5532 "Advertise extended next-hop capability to the peer\n")
5533 {
5534 int idx_peer = 2;
5535 char base_xpath[XPATH_MAXLEN];
5536
5537 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5538 sizeof(base_xpath), NULL)
5539 < 0)
5540 return CMD_WARNING_CONFIG_FAILED;
5541
5542 nb_cli_enqueue_change(
5543 vty, "./capability-options/extended-nexthop-capability",
5544 NB_OP_MODIFY, "false");
5545
5546 return nb_cli_apply_changes(vty, base_xpath);
5547 }
5548
5549 int peer_af_flag_modify_nb(struct peer *peer, afi_t afi, safi_t safi,
5550 uint32_t flag, int set, char *errmsg,
5551 size_t errmsg_len)
5552 {
5553 int ret;
5554
5555 if (set)
5556 ret = peer_af_flag_set(peer, afi, safi, flag);
5557 else
5558 ret = peer_af_flag_unset(peer, afi, safi, flag);
5559
5560 return bgp_nb_errmsg_return(errmsg, errmsg_len, ret);
5561 }
5562
5563 static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
5564 afi_t afi, safi_t safi, uint32_t flag,
5565 int set)
5566 {
5567 int ret;
5568 struct peer *peer;
5569
5570 peer = peer_and_group_lookup_vty(vty, peer_str);
5571 if (!peer)
5572 return CMD_WARNING_CONFIG_FAILED;
5573
5574 if (set)
5575 ret = peer_af_flag_set(peer, afi, safi, flag);
5576 else
5577 ret = peer_af_flag_unset(peer, afi, safi, flag);
5578
5579 return bgp_vty_return(vty, ret);
5580 }
5581
5582 static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
5583 afi_t afi, safi_t safi, uint32_t flag)
5584 {
5585 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
5586 }
5587
5588 static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
5589 afi_t afi, safi_t safi, uint32_t flag)
5590 {
5591 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
5592 }
5593
5594 /* neighbor capability orf prefix-list. */
5595 DEFUN (neighbor_capability_orf_prefix,
5596 neighbor_capability_orf_prefix_cmd,
5597 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5598 NEIGHBOR_STR
5599 NEIGHBOR_ADDR_STR2
5600 "Advertise capability to the peer\n"
5601 "Advertise ORF capability to the peer\n"
5602 "Advertise prefixlist ORF capability to this neighbor\n"
5603 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5604 "Capability to RECEIVE the ORF from this neighbor\n"
5605 "Capability to SEND the ORF to this neighbor\n")
5606 {
5607 int idx_send_recv = 5;
5608 char *peer_str = argv[1]->arg;
5609 struct peer *peer;
5610 afi_t afi = bgp_node_afi(vty);
5611 safi_t safi = bgp_node_safi(vty);
5612
5613 peer = peer_and_group_lookup_vty(vty, peer_str);
5614 if (!peer)
5615 return CMD_WARNING_CONFIG_FAILED;
5616
5617 if (strmatch(argv[idx_send_recv]->text, "send"))
5618 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5619 PEER_FLAG_ORF_PREFIX_SM);
5620
5621 if (strmatch(argv[idx_send_recv]->text, "receive"))
5622 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5623 PEER_FLAG_ORF_PREFIX_RM);
5624
5625 if (strmatch(argv[idx_send_recv]->text, "both"))
5626 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5627 PEER_FLAG_ORF_PREFIX_SM)
5628 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5629 PEER_FLAG_ORF_PREFIX_RM);
5630
5631 return CMD_WARNING_CONFIG_FAILED;
5632 }
5633
5634 ALIAS_HIDDEN(
5635 neighbor_capability_orf_prefix,
5636 neighbor_capability_orf_prefix_hidden_cmd,
5637 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5638 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5639 "Advertise capability to the peer\n"
5640 "Advertise ORF capability to the peer\n"
5641 "Advertise prefixlist ORF capability to this neighbor\n"
5642 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5643 "Capability to RECEIVE the ORF from this neighbor\n"
5644 "Capability to SEND the ORF to this neighbor\n")
5645
5646 DEFUN (no_neighbor_capability_orf_prefix,
5647 no_neighbor_capability_orf_prefix_cmd,
5648 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5649 NO_STR
5650 NEIGHBOR_STR
5651 NEIGHBOR_ADDR_STR2
5652 "Advertise capability to the peer\n"
5653 "Advertise ORF capability to the peer\n"
5654 "Advertise prefixlist ORF capability to this neighbor\n"
5655 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5656 "Capability to RECEIVE the ORF from this neighbor\n"
5657 "Capability to SEND the ORF to this neighbor\n")
5658 {
5659 int idx_send_recv = 6;
5660 char *peer_str = argv[2]->arg;
5661 struct peer *peer;
5662 afi_t afi = bgp_node_afi(vty);
5663 safi_t safi = bgp_node_safi(vty);
5664
5665 peer = peer_and_group_lookup_vty(vty, peer_str);
5666 if (!peer)
5667 return CMD_WARNING_CONFIG_FAILED;
5668
5669 if (strmatch(argv[idx_send_recv]->text, "send"))
5670 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5671 PEER_FLAG_ORF_PREFIX_SM);
5672
5673 if (strmatch(argv[idx_send_recv]->text, "receive"))
5674 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5675 PEER_FLAG_ORF_PREFIX_RM);
5676
5677 if (strmatch(argv[idx_send_recv]->text, "both"))
5678 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5679 PEER_FLAG_ORF_PREFIX_SM)
5680 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5681 PEER_FLAG_ORF_PREFIX_RM);
5682
5683 return CMD_WARNING_CONFIG_FAILED;
5684 }
5685
5686 ALIAS_HIDDEN(
5687 no_neighbor_capability_orf_prefix,
5688 no_neighbor_capability_orf_prefix_hidden_cmd,
5689 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5690 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5691 "Advertise capability to the peer\n"
5692 "Advertise ORF capability to the peer\n"
5693 "Advertise prefixlist ORF capability to this neighbor\n"
5694 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5695 "Capability to RECEIVE the ORF from this neighbor\n"
5696 "Capability to SEND the ORF to this neighbor\n")
5697
5698 /* neighbor next-hop-self. */
5699 DEFUN_YANG (neighbor_nexthop_self,
5700 neighbor_nexthop_self_cmd,
5701 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5702 NEIGHBOR_STR
5703 NEIGHBOR_ADDR_STR2
5704 "Disable the next hop calculation for this neighbor\n")
5705 {
5706 int idx_peer = 1;
5707 char base_xpath[XPATH_MAXLEN];
5708 char af_xpath[XPATH_MAXLEN];
5709 char attr_xpath[XPATH_MAXLEN];
5710 afi_t afi = bgp_node_afi(vty);
5711 safi_t safi = bgp_node_safi(vty);
5712
5713 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5714 yang_afi_safi_value2identity(afi, safi));
5715
5716 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5717 sizeof(base_xpath), af_xpath)
5718 < 0)
5719 return CMD_WARNING_CONFIG_FAILED;
5720
5721 snprintf(attr_xpath, sizeof(attr_xpath),
5722 "./%s/nexthop-self/next-hop-self",
5723 bgp_afi_safi_get_container_str(afi, safi));
5724
5725 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5726
5727 return nb_cli_apply_changes(vty, base_xpath);
5728 }
5729
5730 ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
5731 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5732 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5733 "Disable the next hop calculation for this neighbor\n")
5734
5735 /* neighbor next-hop-self. */
5736 DEFUN_YANG(neighbor_nexthop_self_force,
5737 neighbor_nexthop_self_force_cmd,
5738 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5739 NEIGHBOR_STR
5740 NEIGHBOR_ADDR_STR2
5741 "Disable the next hop calculation for this neighbor\n"
5742 "Set the next hop to self for reflected routes\n")
5743 {
5744 int idx_peer = 1;
5745 char base_xpath[XPATH_MAXLEN];
5746 char af_xpath[XPATH_MAXLEN];
5747 char attr_xpath[XPATH_MAXLEN];
5748 afi_t afi = bgp_node_afi(vty);
5749 safi_t safi = bgp_node_safi(vty);
5750
5751 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5752 yang_afi_safi_value2identity(afi, safi));
5753
5754 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5755 sizeof(base_xpath), af_xpath)
5756 < 0)
5757 return CMD_WARNING_CONFIG_FAILED;
5758
5759 snprintf(attr_xpath, sizeof(attr_xpath),
5760 "./%s/nexthop-self/next-hop-self-force",
5761 bgp_afi_safi_get_container_str(afi, safi));
5762
5763 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5764
5765 return nb_cli_apply_changes(vty, base_xpath);
5766 }
5767
5768 ALIAS_HIDDEN(neighbor_nexthop_self_force,
5769 neighbor_nexthop_self_force_hidden_cmd,
5770 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5771 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5772 "Disable the next hop calculation for this neighbor\n"
5773 "Set the next hop to self for reflected routes\n")
5774
5775 ALIAS_HIDDEN(neighbor_nexthop_self_force,
5776 neighbor_nexthop_self_all_hidden_cmd,
5777 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5778 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5779 "Disable the next hop calculation for this neighbor\n"
5780 "Set the next hop to self for reflected routes\n")
5781
5782 DEFUN_YANG (no_neighbor_nexthop_self,
5783 no_neighbor_nexthop_self_cmd,
5784 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5785 NO_STR
5786 NEIGHBOR_STR
5787 NEIGHBOR_ADDR_STR2
5788 "Disable the next hop calculation for this neighbor\n")
5789 {
5790 int idx_peer = 2;
5791 char base_xpath[XPATH_MAXLEN];
5792 char af_xpath[XPATH_MAXLEN];
5793 char attr_xpath[XPATH_MAXLEN];
5794 afi_t afi = bgp_node_afi(vty);
5795 safi_t safi = bgp_node_safi(vty);
5796
5797 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5798 yang_afi_safi_value2identity(afi, safi));
5799
5800 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5801 sizeof(base_xpath), af_xpath)
5802 < 0)
5803 return CMD_WARNING_CONFIG_FAILED;
5804
5805 snprintf(attr_xpath, sizeof(attr_xpath),
5806 "./%s/nexthop-self/next-hop-self",
5807 bgp_afi_safi_get_container_str(afi, safi));
5808
5809 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5810
5811 return nb_cli_apply_changes(vty, base_xpath);
5812 }
5813
5814 ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
5815 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5816 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5817 "Disable the next hop calculation for this neighbor\n")
5818
5819 DEFUN_YANG (no_neighbor_nexthop_self_force,
5820 no_neighbor_nexthop_self_force_cmd,
5821 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5822 NO_STR
5823 NEIGHBOR_STR
5824 NEIGHBOR_ADDR_STR2
5825 "Disable the next hop calculation for this neighbor\n"
5826 "Set the next hop to self for reflected routes\n")
5827 {
5828 int idx_peer = 2;
5829 char base_xpath[XPATH_MAXLEN];
5830 char af_xpath[XPATH_MAXLEN];
5831 char attr_xpath[XPATH_MAXLEN];
5832 afi_t afi = bgp_node_afi(vty);
5833 safi_t safi = bgp_node_safi(vty);
5834
5835 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5836 yang_afi_safi_value2identity(afi, safi));
5837
5838 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5839 sizeof(base_xpath), af_xpath)
5840 < 0)
5841 return CMD_WARNING_CONFIG_FAILED;
5842
5843 snprintf(attr_xpath, sizeof(attr_xpath),
5844 "./%s/nexthop-self/next-hop-self-force",
5845 bgp_afi_safi_get_container_str(afi, safi));
5846
5847 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5848
5849 return nb_cli_apply_changes(vty, base_xpath);
5850 }
5851
5852 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5853 no_neighbor_nexthop_self_force_hidden_cmd,
5854 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5855 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5856 "Disable the next hop calculation for this neighbor\n"
5857 "Set the next hop to self for reflected routes\n")
5858
5859 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5860 no_neighbor_nexthop_self_all_hidden_cmd,
5861 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5862 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5863 "Disable the next hop calculation for this neighbor\n"
5864 "Set the next hop to self for reflected routes\n")
5865
5866 /* neighbor as-override */
5867 DEFUN_YANG (neighbor_as_override,
5868 neighbor_as_override_cmd,
5869 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5870 NEIGHBOR_STR
5871 NEIGHBOR_ADDR_STR2
5872 "Override ASNs in outbound updates if aspath equals remote-as\n")
5873 {
5874 int idx_peer = 1;
5875 char base_xpath[XPATH_MAXLEN];
5876 char af_xpath[XPATH_MAXLEN];
5877 char attr_xpath[XPATH_MAXLEN];
5878 afi_t afi = bgp_node_afi(vty);
5879 safi_t safi = bgp_node_safi(vty);
5880
5881 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5882 yang_afi_safi_value2identity(afi, safi));
5883
5884 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5885 sizeof(base_xpath), af_xpath)
5886 < 0)
5887 return CMD_WARNING_CONFIG_FAILED;
5888
5889 snprintf(attr_xpath, sizeof(attr_xpath),
5890 "./%s/as-path-options/replace-peer-as",
5891 bgp_afi_safi_get_container_str(afi, safi));
5892
5893 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5894
5895 return nb_cli_apply_changes(vty, base_xpath);
5896 }
5897
5898 ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
5899 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5900 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5901 "Override ASNs in outbound updates if aspath equals remote-as\n")
5902
5903 DEFUN_YANG (no_neighbor_as_override,
5904 no_neighbor_as_override_cmd,
5905 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5906 NO_STR
5907 NEIGHBOR_STR
5908 NEIGHBOR_ADDR_STR2
5909 "Override ASNs in outbound updates if aspath equals remote-as\n")
5910 {
5911 int idx_peer = 2;
5912 char base_xpath[XPATH_MAXLEN];
5913 char af_xpath[XPATH_MAXLEN];
5914 char attr_xpath[XPATH_MAXLEN];
5915 afi_t afi = bgp_node_afi(vty);
5916 safi_t safi = bgp_node_safi(vty);
5917
5918 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5919 yang_afi_safi_value2identity(afi, safi));
5920
5921 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5922 sizeof(base_xpath), af_xpath)
5923 < 0)
5924 return CMD_WARNING_CONFIG_FAILED;
5925
5926 snprintf(attr_xpath, sizeof(attr_xpath),
5927 "./%s/as-path-options/replace-peer-as",
5928 bgp_afi_safi_get_container_str(afi, safi));
5929
5930 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5931
5932 return nb_cli_apply_changes(vty, base_xpath);
5933 }
5934
5935 ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
5936 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5937 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5938 "Override ASNs in outbound updates if aspath equals remote-as\n")
5939
5940 /* neighbor remove-private-AS. */
5941 DEFUN_YANG (neighbor_remove_private_as,
5942 neighbor_remove_private_as_cmd,
5943 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5944 NEIGHBOR_STR
5945 NEIGHBOR_ADDR_STR2
5946 "Remove private ASNs in outbound updates\n")
5947 {
5948 int idx_peer = 1;
5949 char base_xpath[XPATH_MAXLEN];
5950 char af_xpath[XPATH_MAXLEN];
5951 char attr_xpath[XPATH_MAXLEN];
5952 afi_t afi = bgp_node_afi(vty);
5953 safi_t safi = bgp_node_safi(vty);
5954
5955 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5956 yang_afi_safi_value2identity(afi, safi));
5957
5958 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5959 sizeof(base_xpath), af_xpath)
5960 < 0)
5961 return CMD_WARNING_CONFIG_FAILED;
5962
5963 snprintf(attr_xpath, sizeof(attr_xpath),
5964 "./%s/private-as/remove-private-as",
5965 bgp_afi_safi_get_container_str(afi, safi));
5966
5967 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5968
5969 return nb_cli_apply_changes(vty, base_xpath);
5970 }
5971
5972 ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
5973 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5974 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5975 "Remove private ASNs in outbound updates\n")
5976
5977 DEFUN_YANG (neighbor_remove_private_as_all,
5978 neighbor_remove_private_as_all_cmd,
5979 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5980 NEIGHBOR_STR
5981 NEIGHBOR_ADDR_STR2
5982 "Remove private ASNs in outbound updates\n"
5983 "Apply to all AS numbers\n")
5984 {
5985 int idx_peer = 1;
5986 char base_xpath[XPATH_MAXLEN];
5987 char af_xpath[XPATH_MAXLEN];
5988 char attr_xpath[XPATH_MAXLEN];
5989 afi_t afi = bgp_node_afi(vty);
5990 safi_t safi = bgp_node_safi(vty);
5991
5992 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5993 yang_afi_safi_value2identity(afi, safi));
5994
5995 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5996 sizeof(base_xpath), af_xpath)
5997 < 0)
5998 return CMD_WARNING_CONFIG_FAILED;
5999
6000 snprintf(attr_xpath, sizeof(attr_xpath),
6001 "./%s/private-as/remove-private-as-all",
6002 bgp_afi_safi_get_container_str(afi, safi));
6003
6004 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
6005
6006 return nb_cli_apply_changes(vty, base_xpath);
6007 }
6008
6009 ALIAS_HIDDEN(neighbor_remove_private_as_all,
6010 neighbor_remove_private_as_all_hidden_cmd,
6011 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
6012 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6013 "Remove private ASNs in outbound updates\n"
6014 "Apply to all AS numbers")
6015
6016 DEFUN_YANG (neighbor_remove_private_as_replace_as,
6017 neighbor_remove_private_as_replace_as_cmd,
6018 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
6019 NEIGHBOR_STR
6020 NEIGHBOR_ADDR_STR2
6021 "Remove private ASNs in outbound updates\n"
6022 "Replace private ASNs with our ASN in outbound updates\n")
6023 {
6024 int idx_peer = 1;
6025 char base_xpath[XPATH_MAXLEN];
6026 char af_xpath[XPATH_MAXLEN];
6027 char attr_xpath[XPATH_MAXLEN];
6028 afi_t afi = bgp_node_afi(vty);
6029 safi_t safi = bgp_node_safi(vty);
6030
6031 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6032 yang_afi_safi_value2identity(afi, safi));
6033
6034 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6035 sizeof(base_xpath), af_xpath)
6036 < 0)
6037 return CMD_WARNING_CONFIG_FAILED;
6038
6039 snprintf(attr_xpath, sizeof(attr_xpath),
6040 "./%s/private-as/remove-private-as-replace",
6041 bgp_afi_safi_get_container_str(afi, safi));
6042
6043 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
6044
6045 return nb_cli_apply_changes(vty, base_xpath);
6046 }
6047
6048 ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
6049 neighbor_remove_private_as_replace_as_hidden_cmd,
6050 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
6051 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6052 "Remove private ASNs in outbound updates\n"
6053 "Replace private ASNs with our ASN in outbound updates\n")
6054
6055 DEFUN_YANG (neighbor_remove_private_as_all_replace_as,
6056 neighbor_remove_private_as_all_replace_as_cmd,
6057 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
6058 NEIGHBOR_STR
6059 NEIGHBOR_ADDR_STR2
6060 "Remove private ASNs in outbound updates\n"
6061 "Apply to all AS numbers\n"
6062 "Replace private ASNs with our ASN in outbound updates\n")
6063 {
6064 int idx_peer = 1;
6065 char base_xpath[XPATH_MAXLEN];
6066 char af_xpath[XPATH_MAXLEN];
6067 char attr_xpath[XPATH_MAXLEN];
6068 afi_t afi = bgp_node_afi(vty);
6069 safi_t safi = bgp_node_safi(vty);
6070
6071 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6072 yang_afi_safi_value2identity(afi, safi));
6073
6074 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6075 sizeof(base_xpath), af_xpath)
6076 < 0)
6077 return CMD_WARNING_CONFIG_FAILED;
6078
6079 snprintf(attr_xpath, sizeof(attr_xpath),
6080 "./%s/private-as/remove-private-as-all-replace",
6081 bgp_afi_safi_get_container_str(afi, safi));
6082
6083 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
6084
6085 return nb_cli_apply_changes(vty, base_xpath);
6086 }
6087
6088 ALIAS_HIDDEN(
6089 neighbor_remove_private_as_all_replace_as,
6090 neighbor_remove_private_as_all_replace_as_hidden_cmd,
6091 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
6092 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6093 "Remove private ASNs in outbound updates\n"
6094 "Apply to all AS numbers\n"
6095 "Replace private ASNs with our ASN in outbound updates\n")
6096
6097 DEFUN_YANG (no_neighbor_remove_private_as,
6098 no_neighbor_remove_private_as_cmd,
6099 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
6100 NO_STR
6101 NEIGHBOR_STR
6102 NEIGHBOR_ADDR_STR2
6103 "Remove private ASNs in outbound updates\n")
6104 {
6105 int idx_peer = 2;
6106 char base_xpath[XPATH_MAXLEN];
6107 char af_xpath[XPATH_MAXLEN];
6108 char attr_xpath[XPATH_MAXLEN];
6109 afi_t afi = bgp_node_afi(vty);
6110 safi_t safi = bgp_node_safi(vty);
6111
6112 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6113 yang_afi_safi_value2identity(afi, safi));
6114
6115 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6116 sizeof(base_xpath), af_xpath)
6117 < 0)
6118 return CMD_WARNING_CONFIG_FAILED;
6119
6120 snprintf(attr_xpath, sizeof(attr_xpath),
6121 "./%s/private-as/remove-private-as",
6122 bgp_afi_safi_get_container_str(afi, safi));
6123
6124 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6125
6126 return nb_cli_apply_changes(vty, base_xpath);
6127 }
6128
6129 ALIAS_HIDDEN(no_neighbor_remove_private_as,
6130 no_neighbor_remove_private_as_hidden_cmd,
6131 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
6132 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6133 "Remove private ASNs in outbound updates\n")
6134
6135 DEFUN_YANG (no_neighbor_remove_private_as_all,
6136 no_neighbor_remove_private_as_all_cmd,
6137 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
6138 NO_STR
6139 NEIGHBOR_STR
6140 NEIGHBOR_ADDR_STR2
6141 "Remove private ASNs in outbound updates\n"
6142 "Apply to all AS numbers\n")
6143 {
6144 int idx_peer = 2;
6145 char base_xpath[XPATH_MAXLEN];
6146 char af_xpath[XPATH_MAXLEN];
6147 char attr_xpath[XPATH_MAXLEN];
6148 afi_t afi = bgp_node_afi(vty);
6149 safi_t safi = bgp_node_safi(vty);
6150
6151 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6152 yang_afi_safi_value2identity(afi, safi));
6153
6154 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6155 sizeof(base_xpath), af_xpath)
6156 < 0)
6157 return CMD_WARNING_CONFIG_FAILED;
6158
6159 snprintf(attr_xpath, sizeof(attr_xpath),
6160 "./%s/private-as/remove-private-as-all",
6161 bgp_afi_safi_get_container_str(afi, safi));
6162
6163 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6164
6165 return nb_cli_apply_changes(vty, base_xpath);
6166 }
6167
6168 ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
6169 no_neighbor_remove_private_as_all_hidden_cmd,
6170 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
6171 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6172 "Remove private ASNs in outbound updates\n"
6173 "Apply to all AS numbers\n")
6174
6175 DEFUN_YANG (no_neighbor_remove_private_as_replace_as,
6176 no_neighbor_remove_private_as_replace_as_cmd,
6177 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
6178 NO_STR
6179 NEIGHBOR_STR
6180 NEIGHBOR_ADDR_STR2
6181 "Remove private ASNs in outbound updates\n"
6182 "Replace private ASNs with our ASN in outbound updates\n")
6183 {
6184 int idx_peer = 2;
6185 char base_xpath[XPATH_MAXLEN];
6186 char af_xpath[XPATH_MAXLEN];
6187 char attr_xpath[XPATH_MAXLEN];
6188 afi_t afi = bgp_node_afi(vty);
6189 safi_t safi = bgp_node_safi(vty);
6190
6191 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6192 yang_afi_safi_value2identity(afi, safi));
6193
6194 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6195 sizeof(base_xpath), af_xpath)
6196 < 0)
6197 return CMD_WARNING_CONFIG_FAILED;
6198
6199 snprintf(attr_xpath, sizeof(attr_xpath),
6200 "./%s/private-as/remove-private-as-replace",
6201 bgp_afi_safi_get_container_str(afi, safi));
6202
6203 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6204
6205 return nb_cli_apply_changes(vty, base_xpath);
6206 }
6207
6208 ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
6209 no_neighbor_remove_private_as_replace_as_hidden_cmd,
6210 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
6211 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6212 "Remove private ASNs in outbound updates\n"
6213 "Replace private ASNs with our ASN in outbound updates\n")
6214
6215 DEFUN_YANG (no_neighbor_remove_private_as_all_replace_as,
6216 no_neighbor_remove_private_as_all_replace_as_cmd,
6217 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
6218 NO_STR
6219 NEIGHBOR_STR
6220 NEIGHBOR_ADDR_STR2
6221 "Remove private ASNs in outbound updates\n"
6222 "Apply to all AS numbers\n"
6223 "Replace private ASNs with our ASN in outbound updates\n")
6224 {
6225 int idx_peer = 2;
6226 char base_xpath[XPATH_MAXLEN];
6227 char af_xpath[XPATH_MAXLEN];
6228 char attr_xpath[XPATH_MAXLEN];
6229 afi_t afi = bgp_node_afi(vty);
6230 safi_t safi = bgp_node_safi(vty);
6231
6232 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6233 yang_afi_safi_value2identity(afi, safi));
6234
6235 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6236 sizeof(base_xpath), af_xpath)
6237 < 0)
6238 return CMD_WARNING_CONFIG_FAILED;
6239
6240 snprintf(attr_xpath, sizeof(attr_xpath),
6241 "./%s/private-as/remove-private-as-all-replace",
6242 bgp_afi_safi_get_container_str(afi, safi));
6243
6244 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6245
6246 return nb_cli_apply_changes(vty, base_xpath);
6247 }
6248
6249 ALIAS_HIDDEN(
6250 no_neighbor_remove_private_as_all_replace_as,
6251 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
6252 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
6253 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6254 "Remove private ASNs in outbound updates\n"
6255 "Apply to all AS numbers\n"
6256 "Replace private ASNs with our ASN in outbound updates\n")
6257
6258
6259 /* neighbor send-community. */
6260 DEFUN_YANG (neighbor_send_community,
6261 neighbor_send_community_cmd,
6262 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6263 NEIGHBOR_STR
6264 NEIGHBOR_ADDR_STR2
6265 "Send Community attribute to this neighbor\n")
6266 {
6267 int idx_peer = 1;
6268 char *peer_str = argv[idx_peer]->arg;
6269 char base_xpath[XPATH_MAXLEN];
6270 char af_xpath[XPATH_MAXLEN];
6271 char std_xpath[XPATH_MAXLEN];
6272 afi_t afi = bgp_node_afi(vty);
6273 safi_t safi = bgp_node_safi(vty);
6274
6275 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6276 yang_afi_safi_value2identity(afi, safi));
6277
6278 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6279 sizeof(base_xpath), af_xpath)
6280 < 0)
6281 return CMD_WARNING_CONFIG_FAILED;
6282
6283 snprintf(std_xpath, sizeof(std_xpath),
6284 "./%s/send-community/send-community",
6285 bgp_afi_safi_get_container_str(afi, safi));
6286
6287 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "true");
6288
6289 return nb_cli_apply_changes(vty, base_xpath);
6290 }
6291
6292 ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
6293 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6294 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6295 "Send Community attribute to this neighbor\n")
6296
6297 DEFUN_YANG (no_neighbor_send_community,
6298 no_neighbor_send_community_cmd,
6299 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6300 NO_STR
6301 NEIGHBOR_STR
6302 NEIGHBOR_ADDR_STR2
6303 "Send Community attribute to this neighbor\n")
6304 {
6305 int idx_peer = 2;
6306 char *peer_str = argv[idx_peer]->arg;
6307 char base_xpath[XPATH_MAXLEN];
6308 char af_xpath[XPATH_MAXLEN];
6309 char std_xpath[XPATH_MAXLEN];
6310 afi_t afi = bgp_node_afi(vty);
6311 safi_t safi = bgp_node_safi(vty);
6312
6313 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6314 yang_afi_safi_value2identity(afi, safi));
6315
6316 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6317 sizeof(base_xpath), af_xpath)
6318 < 0)
6319 return CMD_WARNING_CONFIG_FAILED;
6320
6321 snprintf(std_xpath, sizeof(std_xpath),
6322 "./%s/send-community/send-community",
6323 bgp_afi_safi_get_container_str(afi, safi));
6324
6325 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "false");
6326
6327 return nb_cli_apply_changes(vty, base_xpath);
6328 }
6329
6330 ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
6331 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6332 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6333 "Send Community attribute to this neighbor\n")
6334
6335 /* neighbor send-community extended. */
6336 DEFUN_YANG (neighbor_send_community_type,
6337 neighbor_send_community_type_cmd,
6338 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6339 NEIGHBOR_STR
6340 NEIGHBOR_ADDR_STR2
6341 "Send Community attribute to this neighbor\n"
6342 "Send Standard and Extended Community attributes\n"
6343 "Send Standard, Large and Extended Community attributes\n"
6344 "Send Extended Community attributes\n"
6345 "Send Standard Community attributes\n"
6346 "Send Large Community attributes\n")
6347 {
6348 const char *type = argv[argc - 1]->text;
6349 char *peer_str = argv[1]->arg;
6350 char base_xpath[XPATH_MAXLEN];
6351 char af_xpath[XPATH_MAXLEN];
6352 char std_xpath[XPATH_MAXLEN];
6353 char ext_xpath[XPATH_MAXLEN];
6354 char lrg_xpath[XPATH_MAXLEN];
6355 afi_t afi = bgp_node_afi(vty);
6356 safi_t safi = bgp_node_safi(vty);
6357
6358 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6359 yang_afi_safi_value2identity(afi, safi));
6360
6361 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6362 sizeof(base_xpath), af_xpath)
6363 < 0)
6364 return CMD_WARNING_CONFIG_FAILED;
6365
6366 if (strmatch(type, "standard")) {
6367 snprintf(std_xpath, sizeof(std_xpath),
6368 "./%s/send-community/send-community",
6369 bgp_afi_safi_get_container_str(afi, safi));
6370
6371 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "true");
6372 }
6373
6374 if (strmatch(type, "extended")) {
6375 snprintf(ext_xpath, sizeof(ext_xpath),
6376 "./%s/send-community/send-ext-community",
6377 bgp_afi_safi_get_container_str(afi, safi));
6378
6379 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "true");
6380 }
6381
6382 if (strmatch(type, "large")) {
6383 snprintf(lrg_xpath, sizeof(lrg_xpath),
6384 "./%s/send-community/send-large-community",
6385 bgp_afi_safi_get_container_str(afi, safi));
6386
6387 nb_cli_enqueue_change(vty, lrg_xpath, NB_OP_MODIFY, "true");
6388 }
6389
6390 if (strmatch(type, "both")) {
6391 snprintf(std_xpath, sizeof(std_xpath),
6392 "./%s/send-community/send-community",
6393 bgp_afi_safi_get_container_str(afi, safi));
6394
6395 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "true");
6396
6397 snprintf(ext_xpath, sizeof(ext_xpath),
6398 "./%s/send-community/send-ext-community",
6399 bgp_afi_safi_get_container_str(afi, safi));
6400
6401 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "true");
6402 }
6403
6404 if (strmatch(type, "all")) {
6405 snprintf(std_xpath, sizeof(std_xpath),
6406 "./%s/send-community/send-community",
6407 bgp_afi_safi_get_container_str(afi, safi));
6408
6409 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "true");
6410
6411 snprintf(ext_xpath, sizeof(ext_xpath),
6412 "./%s/send-community/send-ext-community",
6413 bgp_afi_safi_get_container_str(afi, safi));
6414
6415 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "true");
6416
6417 snprintf(lrg_xpath, sizeof(lrg_xpath),
6418 "./%s/send-community/send-large-community",
6419 bgp_afi_safi_get_container_str(afi, safi));
6420
6421 nb_cli_enqueue_change(vty, lrg_xpath, NB_OP_MODIFY, "true");
6422 }
6423
6424 return nb_cli_apply_changes(vty, base_xpath);
6425 }
6426
6427 ALIAS_HIDDEN(
6428 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
6429 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6430 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6431 "Send Community attribute to this neighbor\n"
6432 "Send Standard and Extended Community attributes\n"
6433 "Send Standard, Large and Extended Community attributes\n"
6434 "Send Extended Community attributes\n"
6435 "Send Standard Community attributes\n"
6436 "Send Large Community attributes\n")
6437
6438 DEFUN_YANG (no_neighbor_send_community_type,
6439 no_neighbor_send_community_type_cmd,
6440 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6441 NO_STR
6442 NEIGHBOR_STR
6443 NEIGHBOR_ADDR_STR2
6444 "Send Community attribute to this neighbor\n"
6445 "Send Standard and Extended Community attributes\n"
6446 "Send Standard, Large and Extended Community attributes\n"
6447 "Send Extended Community attributes\n"
6448 "Send Standard Community attributes\n"
6449 "Send Large Community attributes\n")
6450 {
6451 const char *type = argv[argc - 1]->text;
6452 char *peer_str = argv[2]->arg;
6453 char base_xpath[XPATH_MAXLEN];
6454 char af_xpath[XPATH_MAXLEN];
6455 char std_xpath[XPATH_MAXLEN];
6456 char ext_xpath[XPATH_MAXLEN];
6457 char lrg_xpath[XPATH_MAXLEN];
6458 afi_t afi = bgp_node_afi(vty);
6459 safi_t safi = bgp_node_safi(vty);
6460
6461 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6462 yang_afi_safi_value2identity(afi, safi));
6463
6464 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6465 sizeof(base_xpath), af_xpath)
6466 < 0)
6467 return CMD_WARNING_CONFIG_FAILED;
6468
6469 if (strmatch(type, "standard")) {
6470 snprintf(std_xpath, sizeof(std_xpath),
6471 "./%s/send-community/send-community",
6472 bgp_afi_safi_get_container_str(afi, safi));
6473
6474 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "false");
6475 }
6476
6477 if (strmatch(type, "extended")) {
6478 snprintf(ext_xpath, sizeof(ext_xpath),
6479 "./%s/send-community/send-ext-community",
6480 bgp_afi_safi_get_container_str(afi, safi));
6481
6482 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "false");
6483 }
6484
6485 if (strmatch(type, "large")) {
6486 snprintf(lrg_xpath, sizeof(lrg_xpath),
6487 "./%s/send-community/send-large-community",
6488 bgp_afi_safi_get_container_str(afi, safi));
6489
6490 nb_cli_enqueue_change(vty, lrg_xpath, NB_OP_MODIFY, "false");
6491 }
6492
6493 if (strmatch(type, "both")) {
6494 snprintf(std_xpath, sizeof(std_xpath),
6495 "./%s/send-community/send-community",
6496 bgp_afi_safi_get_container_str(afi, safi));
6497
6498 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "false");
6499
6500 snprintf(ext_xpath, sizeof(ext_xpath),
6501 "./%s/send-community/send-ext-community",
6502 bgp_afi_safi_get_container_str(afi, safi));
6503
6504 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "false");
6505 }
6506
6507 if (strmatch(type, "all")) {
6508 snprintf(std_xpath, sizeof(std_xpath),
6509 "./%s/send-community/send-community",
6510 bgp_afi_safi_get_container_str(afi, safi));
6511
6512 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "false");
6513
6514 snprintf(ext_xpath, sizeof(ext_xpath),
6515 "./%s/send-community/send-ext-community",
6516 bgp_afi_safi_get_container_str(afi, safi));
6517
6518 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "false");
6519
6520 snprintf(lrg_xpath, sizeof(lrg_xpath),
6521 "./%s/send-community/send-large-community",
6522 bgp_afi_safi_get_container_str(afi, safi));
6523
6524 nb_cli_enqueue_change(vty, lrg_xpath, NB_OP_MODIFY, "false");
6525 }
6526
6527 return nb_cli_apply_changes(vty, base_xpath);
6528 }
6529
6530 ALIAS_HIDDEN(
6531 no_neighbor_send_community_type,
6532 no_neighbor_send_community_type_hidden_cmd,
6533 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6534 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6535 "Send Community attribute to this neighbor\n"
6536 "Send Standard and Extended Community attributes\n"
6537 "Send Standard, Large and Extended Community attributes\n"
6538 "Send Extended Community attributes\n"
6539 "Send Standard Community attributes\n"
6540 "Send Large Community attributes\n")
6541
6542 /* neighbor soft-reconfig. */
6543 DEFUN_YANG (neighbor_soft_reconfiguration,
6544 neighbor_soft_reconfiguration_cmd,
6545 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6546 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6547 "Per neighbor soft reconfiguration\n"
6548 "Allow inbound soft reconfiguration for this neighbor\n")
6549 {
6550 int idx_peer = 1;
6551 char base_xpath[XPATH_MAXLEN];
6552 char af_xpath[XPATH_MAXLEN];
6553 char soft_xpath[XPATH_MAXLEN];
6554 afi_t afi = bgp_node_afi(vty);
6555 safi_t safi = bgp_node_safi(vty);
6556
6557 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6558 yang_afi_safi_value2identity(afi, safi));
6559
6560 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6561 sizeof(base_xpath), af_xpath)
6562 < 0)
6563 return CMD_WARNING_CONFIG_FAILED;
6564
6565 snprintf(soft_xpath, sizeof(soft_xpath), "./%s/soft-reconfiguration",
6566 bgp_afi_safi_get_container_str(afi, safi));
6567
6568 nb_cli_enqueue_change(vty, soft_xpath, NB_OP_MODIFY, "true");
6569
6570 return nb_cli_apply_changes(vty, base_xpath);
6571 }
6572
6573 ALIAS_HIDDEN(neighbor_soft_reconfiguration,
6574 neighbor_soft_reconfiguration_hidden_cmd,
6575 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6576 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6577 "Per neighbor soft reconfiguration\n"
6578 "Allow inbound soft reconfiguration for this neighbor\n")
6579
6580 DEFUN_YANG (no_neighbor_soft_reconfiguration,
6581 no_neighbor_soft_reconfiguration_cmd,
6582 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6583 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6584 "Per neighbor soft reconfiguration\n"
6585 "Allow inbound soft reconfiguration for this neighbor\n")
6586 {
6587 int idx_peer = 2;
6588 char base_xpath[XPATH_MAXLEN];
6589 char af_xpath[XPATH_MAXLEN];
6590 char soft_xpath[XPATH_MAXLEN];
6591 afi_t afi = bgp_node_afi(vty);
6592 safi_t safi = bgp_node_safi(vty);
6593
6594 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6595 yang_afi_safi_value2identity(afi, safi));
6596
6597 snprintf(soft_xpath, sizeof(soft_xpath), "./%s/soft-reconfiguration",
6598 bgp_afi_safi_get_container_str(afi, safi));
6599
6600 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6601 sizeof(base_xpath), af_xpath)
6602 < 0)
6603 return CMD_WARNING_CONFIG_FAILED;
6604
6605 nb_cli_enqueue_change(vty, soft_xpath, NB_OP_MODIFY, "false");
6606
6607 return nb_cli_apply_changes(vty, base_xpath);
6608 }
6609
6610 ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
6611 no_neighbor_soft_reconfiguration_hidden_cmd,
6612 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6613 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6614 "Per neighbor soft reconfiguration\n"
6615 "Allow inbound soft reconfiguration for this neighbor\n")
6616
6617 DEFUN_YANG (neighbor_route_reflector_client,
6618 neighbor_route_reflector_client_cmd,
6619 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6620 NEIGHBOR_STR
6621 NEIGHBOR_ADDR_STR2
6622 "Configure a neighbor as Route Reflector client\n")
6623 {
6624 int idx_peer = 1;
6625 char base_xpath[XPATH_MAXLEN];
6626 char af_xpath[XPATH_MAXLEN];
6627 char attr_xpath[XPATH_MAXLEN];
6628 afi_t afi = bgp_node_afi(vty);
6629 safi_t safi = bgp_node_safi(vty);
6630
6631 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6632 yang_afi_safi_value2identity(afi, safi));
6633
6634 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6635 sizeof(base_xpath), af_xpath)
6636 < 0)
6637 return CMD_WARNING_CONFIG_FAILED;
6638
6639 snprintf(attr_xpath, sizeof(attr_xpath),
6640 "./%s/route-reflector/route-reflector-client",
6641 bgp_afi_safi_get_container_str(afi, safi));
6642
6643 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
6644
6645 return nb_cli_apply_changes(vty, base_xpath);
6646 }
6647
6648 ALIAS_HIDDEN(neighbor_route_reflector_client,
6649 neighbor_route_reflector_client_hidden_cmd,
6650 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6651 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6652 "Configure a neighbor as Route Reflector client\n")
6653
6654 DEFUN_YANG (no_neighbor_route_reflector_client,
6655 no_neighbor_route_reflector_client_cmd,
6656 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6657 NO_STR
6658 NEIGHBOR_STR
6659 NEIGHBOR_ADDR_STR2
6660 "Configure a neighbor as Route Reflector client\n")
6661 {
6662 int idx_peer = 2;
6663 char base_xpath[XPATH_MAXLEN];
6664 char af_xpath[XPATH_MAXLEN];
6665 char attr_xpath[XPATH_MAXLEN];
6666 afi_t afi = bgp_node_afi(vty);
6667 safi_t safi = bgp_node_safi(vty);
6668
6669 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6670 yang_afi_safi_value2identity(afi, safi));
6671
6672 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6673 sizeof(base_xpath), af_xpath)
6674 < 0)
6675 return CMD_WARNING_CONFIG_FAILED;
6676
6677 snprintf(attr_xpath, sizeof(attr_xpath),
6678 "./%s/route-reflector/route-reflector-client",
6679 bgp_afi_safi_get_container_str(afi, safi));
6680
6681 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6682
6683 return nb_cli_apply_changes(vty, base_xpath);
6684 }
6685
6686 ALIAS_HIDDEN(no_neighbor_route_reflector_client,
6687 no_neighbor_route_reflector_client_hidden_cmd,
6688 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6689 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6690 "Configure a neighbor as Route Reflector client\n")
6691
6692 /* neighbor route-server-client. */
6693 DEFUN_YANG (neighbor_route_server_client,
6694 neighbor_route_server_client_cmd,
6695 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6696 NEIGHBOR_STR
6697 NEIGHBOR_ADDR_STR2
6698 "Configure a neighbor as Route Server client\n")
6699 {
6700 int idx_peer = 1;
6701 char base_xpath[XPATH_MAXLEN];
6702 char af_xpath[XPATH_MAXLEN];
6703 char attr_xpath[XPATH_MAXLEN];
6704 afi_t afi = bgp_node_afi(vty);
6705 safi_t safi = bgp_node_safi(vty);
6706
6707 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6708 yang_afi_safi_value2identity(afi, safi));
6709
6710 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6711 sizeof(base_xpath), af_xpath)
6712 < 0)
6713 return CMD_WARNING_CONFIG_FAILED;
6714
6715 snprintf(attr_xpath, sizeof(attr_xpath),
6716 "./%s/route-server/route-server-client",
6717 bgp_afi_safi_get_container_str(afi, safi));
6718
6719 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
6720
6721 return nb_cli_apply_changes(vty, base_xpath);
6722 }
6723
6724 ALIAS_HIDDEN(neighbor_route_server_client,
6725 neighbor_route_server_client_hidden_cmd,
6726 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6727 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6728 "Configure a neighbor as Route Server client\n")
6729
6730 DEFUN_YANG (no_neighbor_route_server_client,
6731 no_neighbor_route_server_client_cmd,
6732 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6733 NO_STR
6734 NEIGHBOR_STR
6735 NEIGHBOR_ADDR_STR2
6736 "Configure a neighbor as Route Server client\n")
6737 {
6738 int idx_peer = 2;
6739 char base_xpath[XPATH_MAXLEN];
6740 char af_xpath[XPATH_MAXLEN];
6741 char attr_xpath[XPATH_MAXLEN];
6742 afi_t afi = bgp_node_afi(vty);
6743 safi_t safi = bgp_node_safi(vty);
6744
6745 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6746 yang_afi_safi_value2identity(afi, safi));
6747
6748 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6749 sizeof(base_xpath), af_xpath)
6750 < 0)
6751 return CMD_WARNING_CONFIG_FAILED;
6752
6753 snprintf(attr_xpath, sizeof(attr_xpath),
6754 "./%s/route-server/route-server-client",
6755 bgp_afi_safi_get_container_str(afi, safi));
6756
6757 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6758
6759 return nb_cli_apply_changes(vty, base_xpath);
6760 }
6761
6762 ALIAS_HIDDEN(no_neighbor_route_server_client,
6763 no_neighbor_route_server_client_hidden_cmd,
6764 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6765 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6766 "Configure a neighbor as Route Server client\n")
6767
6768 DEFUN (neighbor_nexthop_local_unchanged,
6769 neighbor_nexthop_local_unchanged_cmd,
6770 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
6771 NEIGHBOR_STR
6772 NEIGHBOR_ADDR_STR2
6773 "Configure treatment of outgoing link-local nexthop attribute\n"
6774 "Leave link-local nexthop unchanged for this peer\n")
6775 {
6776 int idx_peer = 1;
6777 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6778 bgp_node_safi(vty),
6779 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
6780 }
6781
6782 DEFUN (no_neighbor_nexthop_local_unchanged,
6783 no_neighbor_nexthop_local_unchanged_cmd,
6784 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
6785 NO_STR
6786 NEIGHBOR_STR
6787 NEIGHBOR_ADDR_STR2
6788 "Configure treatment of outgoing link-local-nexthop attribute\n"
6789 "Leave link-local nexthop unchanged for this peer\n")
6790 {
6791 int idx_peer = 2;
6792 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6793 bgp_node_afi(vty), bgp_node_safi(vty),
6794 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
6795 }
6796
6797 DEFUN_YANG (neighbor_attr_unchanged,
6798 neighbor_attr_unchanged_cmd,
6799 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6800 NEIGHBOR_STR
6801 NEIGHBOR_ADDR_STR2
6802 "BGP attribute is propagated unchanged to this neighbor\n"
6803 "As-path attribute\n"
6804 "Nexthop attribute\n"
6805 "Med attribute\n")
6806 {
6807 int idx = 0;
6808 char *peer_str = argv[1]->arg;
6809 bool aspath = false;
6810 bool nexthop = false;
6811 bool med = false;
6812 afi_t afi = bgp_node_afi(vty);
6813 safi_t safi = bgp_node_safi(vty);
6814 char base_xpath[XPATH_MAXLEN];
6815 char af_xpath[XPATH_MAXLEN];
6816 char as_xpath[XPATH_MAXLEN];
6817 char nxthop_xpath[XPATH_MAXLEN];
6818 char med_xpath[XPATH_MAXLEN];
6819
6820 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6821 yang_afi_safi_value2identity(afi, safi));
6822
6823 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6824 sizeof(base_xpath), af_xpath)
6825 < 0)
6826 return CMD_WARNING_CONFIG_FAILED;
6827
6828 if (argv_find(argv, argc, "as-path", &idx))
6829 aspath = true;
6830
6831 idx = 0;
6832 if (argv_find(argv, argc, "next-hop", &idx))
6833 nexthop = true;
6834
6835 idx = 0;
6836 if (argv_find(argv, argc, "med", &idx))
6837 med = true;
6838
6839 snprintf(as_xpath, sizeof(as_xpath),
6840 "./%s/attr-unchanged/as-path-unchanged",
6841 bgp_afi_safi_get_container_str(afi, safi));
6842 snprintf(nxthop_xpath, sizeof(nxthop_xpath),
6843 "./%s/attr-unchanged/next-hop-unchanged",
6844 bgp_afi_safi_get_container_str(afi, safi));
6845 snprintf(med_xpath, sizeof(med_xpath),
6846 "./%s/attr-unchanged/med-unchanged",
6847 bgp_afi_safi_get_container_str(afi, safi));
6848
6849 /* no flags means all of them! */
6850 if (!aspath && !nexthop && !med) {
6851 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY, "true");
6852 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY, "true");
6853 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY, "true");
6854 } else {
6855 if (!aspath)
6856 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY,
6857 "false");
6858 else
6859 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY,
6860 "true");
6861
6862 if (!nexthop)
6863 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY,
6864 "false");
6865 else
6866 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY,
6867 "true");
6868
6869 if (!med)
6870 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY,
6871 "false");
6872 else
6873 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY,
6874 "true");
6875 }
6876
6877 return nb_cli_apply_changes(vty, base_xpath);
6878 }
6879
6880 ALIAS_HIDDEN(
6881 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
6882 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6883 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6884 "BGP attribute is propagated unchanged to this neighbor\n"
6885 "As-path attribute\n"
6886 "Nexthop attribute\n"
6887 "Med attribute\n")
6888
6889 DEFUN_YANG (no_neighbor_attr_unchanged,
6890 no_neighbor_attr_unchanged_cmd,
6891 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6892 NO_STR
6893 NEIGHBOR_STR
6894 NEIGHBOR_ADDR_STR2
6895 "BGP attribute is propagated unchanged to this neighbor\n"
6896 "As-path attribute\n"
6897 "Nexthop attribute\n"
6898 "Med attribute\n")
6899 {
6900 int idx = 0;
6901 char *peer_str = argv[2]->arg;
6902 bool aspath = false;
6903 bool nexthop = false;
6904 bool med = false;
6905 afi_t afi = bgp_node_afi(vty);
6906 safi_t safi = bgp_node_safi(vty);
6907 char base_xpath[XPATH_MAXLEN];
6908 char af_xpath[XPATH_MAXLEN];
6909 char as_xpath[XPATH_MAXLEN];
6910 char nxthop_xpath[XPATH_MAXLEN];
6911 char med_xpath[XPATH_MAXLEN];
6912
6913 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6914 yang_afi_safi_value2identity(afi, safi));
6915
6916 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6917 sizeof(base_xpath), af_xpath)
6918 < 0)
6919 return CMD_WARNING_CONFIG_FAILED;
6920
6921 if (argv_find(argv, argc, "as-path", &idx))
6922 aspath = true;
6923
6924 idx = 0;
6925 if (argv_find(argv, argc, "next-hop", &idx))
6926 nexthop = true;
6927
6928 idx = 0;
6929 if (argv_find(argv, argc, "med", &idx))
6930 med = true;
6931
6932 snprintf(as_xpath, sizeof(as_xpath),
6933 "./%s/attr-unchanged/as-path-unchanged",
6934 bgp_afi_safi_get_container_str(afi, safi));
6935 snprintf(nxthop_xpath, sizeof(nxthop_xpath),
6936 "./%s/attr-unchanged/next-hop-unchanged",
6937 bgp_afi_safi_get_container_str(afi, safi));
6938 snprintf(med_xpath, sizeof(med_xpath),
6939 "./%s/attr-unchanged/med-unchanged",
6940 bgp_afi_safi_get_container_str(afi, safi));
6941
6942 /* no flags means all of them! */
6943 if (!aspath && !nexthop && !med) {
6944 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY, "false");
6945 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY, "false");
6946 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY, "false");
6947 }
6948
6949 if (aspath)
6950 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY, "false");
6951
6952 if (nexthop)
6953 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY, "false");
6954
6955 if (med)
6956 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY, "false");
6957
6958 return nb_cli_apply_changes(vty, base_xpath);
6959 }
6960
6961 ALIAS_HIDDEN(
6962 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
6963 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6964 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6965 "BGP attribute is propagated unchanged to this neighbor\n"
6966 "As-path attribute\n"
6967 "Nexthop attribute\n"
6968 "Med attribute\n")
6969
6970 /* neighbor ebgp-multihop. */
6971 DEFUN_YANG (neighbor_ebgp_multihop,
6972 neighbor_ebgp_multihop_cmd,
6973 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
6974 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6975 "Allow EBGP neighbors not on directly connected networks\n")
6976 {
6977 int idx_peer = 1;
6978 char base_xpath[XPATH_MAXLEN];
6979
6980 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6981 sizeof(base_xpath), NULL)
6982 < 0)
6983 return CMD_WARNING_CONFIG_FAILED;
6984
6985 nb_cli_enqueue_change(vty, "./ebgp-multihop/enabled", NB_OP_MODIFY,
6986 "true");
6987
6988 return nb_cli_apply_changes(vty, base_xpath);
6989 }
6990
6991 DEFUN_YANG (neighbor_ebgp_multihop_ttl,
6992 neighbor_ebgp_multihop_ttl_cmd,
6993 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
6994 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6995 "Allow EBGP neighbors not on directly connected networks\n"
6996 "maximum hop count\n")
6997 {
6998 int idx_peer = 1;
6999 int idx_number = 3;
7000 char base_xpath[XPATH_MAXLEN];
7001
7002 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7003 sizeof(base_xpath), NULL)
7004 < 0)
7005 return CMD_WARNING_CONFIG_FAILED;
7006
7007 nb_cli_enqueue_change(vty, "./ebgp-multihop/multihop-ttl", NB_OP_MODIFY,
7008 argv[idx_number]->arg);
7009
7010 return nb_cli_apply_changes(vty, base_xpath);
7011 }
7012
7013 DEFUN_YANG (no_neighbor_ebgp_multihop,
7014 no_neighbor_ebgp_multihop_cmd,
7015 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
7016 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7017 "Allow EBGP neighbors not on directly connected networks\n"
7018 "maximum hop count\n")
7019 {
7020 int idx_peer = 2;
7021 char base_xpath[XPATH_MAXLEN];
7022
7023 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7024 sizeof(base_xpath), NULL)
7025 < 0)
7026 return CMD_WARNING_CONFIG_FAILED;
7027
7028 if (argc > 4)
7029 nb_cli_enqueue_change(vty, "./ebgp-multihop/multihop-ttl",
7030 NB_OP_DESTROY, NULL);
7031 else
7032 nb_cli_enqueue_change(vty, "./ebgp-multihop/enabled",
7033 NB_OP_MODIFY, "false");
7034
7035 return nb_cli_apply_changes(vty, base_xpath);
7036 }
7037
7038
7039 /* disable-connected-check */
7040 DEFUN_YANG (neighbor_disable_connected_check,
7041 neighbor_disable_connected_check_cmd,
7042 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
7043 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7044 "one-hop away EBGP peer using loopback address\n"
7045 "Enforce EBGP neighbors perform multihop\n")
7046 {
7047 int idx_peer = 1;
7048 char base_xpath[XPATH_MAXLEN];
7049
7050 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7051 sizeof(base_xpath), NULL)
7052 < 0)
7053 return CMD_WARNING_CONFIG_FAILED;
7054
7055 nb_cli_enqueue_change(vty, "./ebgp-multihop/disable-connected-check",
7056 NB_OP_MODIFY, "true");
7057
7058 return nb_cli_apply_changes(vty, base_xpath);
7059 }
7060
7061 DEFUN_YANG (no_neighbor_disable_connected_check,
7062 no_neighbor_disable_connected_check_cmd,
7063 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
7064 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7065 "one-hop away EBGP peer using loopback address\n"
7066 "Enforce EBGP neighbors perform multihop\n")
7067 {
7068 int idx_peer = 2;
7069 char base_xpath[XPATH_MAXLEN];
7070
7071 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7072 sizeof(base_xpath), NULL)
7073 < 0)
7074 return CMD_WARNING_CONFIG_FAILED;
7075
7076 nb_cli_enqueue_change(vty, "./ebgp-multihop/disable-connected-check",
7077 NB_OP_MODIFY, "false");
7078
7079 return nb_cli_apply_changes(vty, base_xpath);
7080 }
7081
7082
7083 /* enforce-first-as */
7084 DEFUN_YANG (neighbor_enforce_first_as,
7085 neighbor_enforce_first_as_cmd,
7086 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
7087 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7088 "Enforce the first AS for EBGP routes\n")
7089 {
7090 int idx_peer = 1;
7091 char base_xpath[XPATH_MAXLEN];
7092
7093 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7094 sizeof(base_xpath), NULL)
7095 < 0)
7096 return CMD_WARNING_CONFIG_FAILED;
7097
7098 nb_cli_enqueue_change(vty, "./enforce-first-as", NB_OP_MODIFY, "true");
7099
7100 return nb_cli_apply_changes(vty, base_xpath);
7101 }
7102
7103 DEFUN_YANG (no_neighbor_enforce_first_as,
7104 no_neighbor_enforce_first_as_cmd,
7105 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
7106 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7107 "Enforce the first AS for EBGP routes\n")
7108 {
7109 int idx_peer = 2;
7110 char base_xpath[XPATH_MAXLEN];
7111
7112 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7113 sizeof(base_xpath), NULL)
7114 < 0)
7115 return CMD_WARNING_CONFIG_FAILED;
7116
7117 nb_cli_enqueue_change(vty, "./enforce-first-as", NB_OP_MODIFY, "false");
7118
7119 return nb_cli_apply_changes(vty, base_xpath);
7120 }
7121
7122 static int peer_and_group_lookup_nb(struct vty *vty, const char *peer_str,
7123 char *base_xpath, int xpath_len,
7124 char *xpath)
7125 {
7126 union sockunion su;
7127 char num_xpath[XPATH_MAXLEN];
7128 char unnbr_xpath[XPATH_MAXLEN];
7129 char prgrp_xpath[XPATH_MAXLEN];
7130
7131 if (str2sockunion(peer_str, &su) == 0) {
7132 snprintf(num_xpath, sizeof(num_xpath),
7133 "/neighbors/neighbor[remote-address='%s']", peer_str);
7134 if (yang_dnode_existsf(vty->candidate_config->dnode, "%s%s",
7135 VTY_CURR_XPATH, num_xpath)) {
7136 snprintf(base_xpath, xpath_len,
7137 FRR_BGP_NEIGHBOR_NUM_XPATH, peer_str,
7138 xpath ? xpath : "");
7139 } else {
7140 vty_out(vty,
7141 "%% Specify remote-as or peer-group commands first\n");
7142 return -1;
7143 }
7144
7145 } else {
7146 snprintf(unnbr_xpath, sizeof(unnbr_xpath),
7147 "/neighbors/unnumbered-neighbor[interface='%s']",
7148 peer_str);
7149
7150 snprintf(prgrp_xpath, sizeof(prgrp_xpath),
7151 "/peer-groups/peer-group[peer-group-name='%s']",
7152 peer_str);
7153
7154 if (yang_dnode_existsf(vty->candidate_config->dnode, "%s%s",
7155 VTY_CURR_XPATH, unnbr_xpath)) {
7156 snprintf(base_xpath, xpath_len,
7157 FRR_BGP_NEIGHBOR_UNNUM_XPATH, peer_str,
7158 xpath ? xpath : "");
7159 } else if (yang_dnode_existsf(vty->candidate_config->dnode,
7160 "%s%s", VTY_CURR_XPATH,
7161 prgrp_xpath)) {
7162 snprintf(base_xpath, xpath_len,
7163 FRR_BGP_PEER_GROUP_XPATH, peer_str,
7164 xpath ? xpath : "");
7165 } else {
7166 vty_out(vty,
7167 "%% Create the peer-group or interface first\n");
7168 return -1;
7169 }
7170 }
7171
7172 return 0;
7173 }
7174
7175 DEFUN_YANG (neighbor_description,
7176 neighbor_description_cmd,
7177 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
7178 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7179 "Neighbor specific description\n"
7180 "Up to 80 characters describing this neighbor\n")
7181 {
7182 int idx_peer = 1;
7183 int idx_line = 3;
7184 int ret;
7185 char base_xpath[XPATH_MAXLEN];
7186 char *str;
7187
7188 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7189 sizeof(base_xpath), NULL)
7190 < 0)
7191 return CMD_WARNING_CONFIG_FAILED;
7192
7193 str = argv_concat(argv, argc, idx_line);
7194
7195 nb_cli_enqueue_change(vty, "./description", NB_OP_MODIFY, str);
7196
7197 ret = nb_cli_apply_changes(vty, base_xpath);
7198
7199 XFREE(MTYPE_TMP, str);
7200
7201 return ret;
7202 }
7203
7204 DEFUN_YANG (no_neighbor_description,
7205 no_neighbor_description_cmd,
7206 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
7207 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7208 "Neighbor specific description\n")
7209 {
7210 int idx_peer = 2;
7211 char base_xpath[XPATH_MAXLEN];
7212
7213 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7214 sizeof(base_xpath), NULL)
7215 < 0)
7216 return CMD_WARNING_CONFIG_FAILED;
7217
7218 nb_cli_enqueue_change(vty, "./description", NB_OP_DESTROY, NULL);
7219
7220 return nb_cli_apply_changes(vty, base_xpath);
7221 }
7222
7223 ALIAS_YANG(no_neighbor_description, no_neighbor_description_comment_cmd,
7224 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
7225 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7226 "Neighbor specific description\n"
7227 "Up to 80 characters describing this neighbor\n")
7228
7229 #define BGP_UPDATE_SOURCE_HELP_STR \
7230 "IPv4 address\n" \
7231 "IPv6 address\n" \
7232 "Interface name (requires zebra to be running)\n"
7233
7234 DEFUN_YANG (neighbor_update_source,
7235 neighbor_update_source_cmd,
7236 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
7237 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7238 "Source of routing updates\n"
7239 BGP_UPDATE_SOURCE_HELP_STR)
7240 {
7241 int idx_peer = 1;
7242 int idx_peer_2 = 3;
7243 union sockunion su;
7244 char base_xpath[XPATH_MAXLEN];
7245
7246 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7247 sizeof(base_xpath), NULL)
7248 < 0)
7249 return CMD_WARNING_CONFIG_FAILED;
7250
7251 if (str2sockunion(argv[idx_peer_2]->arg, &su) == 0)
7252 nb_cli_enqueue_change(vty, "./update-source/ip", NB_OP_MODIFY,
7253 argv[idx_peer_2]->arg);
7254 else
7255 nb_cli_enqueue_change(vty, "./update-source/interface",
7256 NB_OP_MODIFY, argv[idx_peer_2]->arg);
7257
7258 return nb_cli_apply_changes(vty, base_xpath);
7259 }
7260
7261 DEFUN_YANG (no_neighbor_update_source,
7262 no_neighbor_update_source_cmd,
7263 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
7264 NO_STR NEIGHBOR_STR
7265 NEIGHBOR_ADDR_STR2
7266 "Source of routing updates\n"
7267 BGP_UPDATE_SOURCE_HELP_STR)
7268 {
7269 int idx_peer = 2;
7270 char base_xpath[XPATH_MAXLEN];
7271
7272 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7273 sizeof(base_xpath), NULL)
7274 < 0)
7275 return CMD_WARNING_CONFIG_FAILED;
7276
7277 nb_cli_enqueue_change(vty, "./update-source/ip", NB_OP_DESTROY, NULL);
7278 nb_cli_enqueue_change(vty, "./update-source/interface", NB_OP_DESTROY,
7279 NULL);
7280
7281 return nb_cli_apply_changes(vty, base_xpath);
7282 }
7283
7284 static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
7285 afi_t afi, safi_t safi,
7286 const char *rmap, int set)
7287 {
7288 int ret;
7289 struct peer *peer;
7290 struct route_map *route_map = NULL;
7291
7292 peer = peer_and_group_lookup_vty(vty, peer_str);
7293 if (!peer)
7294 return CMD_WARNING_CONFIG_FAILED;
7295
7296 if (set) {
7297 if (rmap)
7298 route_map = route_map_lookup_warn_noexist(vty, rmap);
7299 ret = peer_default_originate_set(peer, afi, safi,
7300 rmap, route_map);
7301 } else
7302 ret = peer_default_originate_unset(peer, afi, safi);
7303
7304 return bgp_vty_return(vty, ret);
7305 }
7306
7307 /* neighbor default-originate. */
7308 DEFUN (neighbor_default_originate,
7309 neighbor_default_originate_cmd,
7310 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
7311 NEIGHBOR_STR
7312 NEIGHBOR_ADDR_STR2
7313 "Originate default route to this neighbor\n")
7314 {
7315 int idx_peer = 1;
7316 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
7317 bgp_node_afi(vty),
7318 bgp_node_safi(vty), NULL, 1);
7319 }
7320
7321 ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
7322 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
7323 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7324 "Originate default route to this neighbor\n")
7325
7326 DEFUN (neighbor_default_originate_rmap,
7327 neighbor_default_originate_rmap_cmd,
7328 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
7329 NEIGHBOR_STR
7330 NEIGHBOR_ADDR_STR2
7331 "Originate default route to this neighbor\n"
7332 "Route-map to specify criteria to originate default\n"
7333 "route-map name\n")
7334 {
7335 int idx_peer = 1;
7336 int idx_word = 4;
7337 return peer_default_originate_set_vty(
7338 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7339 argv[idx_word]->arg, 1);
7340 }
7341
7342 ALIAS_HIDDEN(
7343 neighbor_default_originate_rmap,
7344 neighbor_default_originate_rmap_hidden_cmd,
7345 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
7346 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7347 "Originate default route to this neighbor\n"
7348 "Route-map to specify criteria to originate default\n"
7349 "route-map name\n")
7350
7351 DEFUN (no_neighbor_default_originate,
7352 no_neighbor_default_originate_cmd,
7353 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
7354 NO_STR
7355 NEIGHBOR_STR
7356 NEIGHBOR_ADDR_STR2
7357 "Originate default route to this neighbor\n"
7358 "Route-map to specify criteria to originate default\n"
7359 "route-map name\n")
7360 {
7361 int idx_peer = 2;
7362 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
7363 bgp_node_afi(vty),
7364 bgp_node_safi(vty), NULL, 0);
7365 }
7366
7367 ALIAS_HIDDEN(
7368 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
7369 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
7370 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7371 "Originate default route to this neighbor\n"
7372 "Route-map to specify criteria to originate default\n"
7373 "route-map name\n")
7374
7375
7376 /* Set specified peer's BGP port. */
7377 DEFUN_YANG (neighbor_port,
7378 neighbor_port_cmd,
7379 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
7380 NEIGHBOR_STR
7381 NEIGHBOR_ADDR_STR
7382 "Neighbor's BGP port\n"
7383 "TCP port number\n")
7384 {
7385 int idx_ip = 1;
7386 int idx_number = 3;
7387 char base_xpath[XPATH_MAXLEN];
7388
7389 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_NUM_XPATH,
7390 argv[idx_ip]->arg, "");
7391
7392 nb_cli_enqueue_change(vty, "./local-port", NB_OP_MODIFY,
7393 argv[idx_number]->arg);
7394
7395 return nb_cli_apply_changes(vty, base_xpath);
7396 }
7397
7398 DEFUN_YANG (no_neighbor_port,
7399 no_neighbor_port_cmd,
7400 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
7401 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR
7402 "Neighbor's BGP port\n"
7403 "TCP port number\n")
7404 {
7405 int idx_ip = 2;
7406 char base_xpath[XPATH_MAXLEN];
7407
7408 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_NUM_XPATH,
7409 argv[idx_ip]->arg, "");
7410
7411 nb_cli_enqueue_change(vty, "./local-port", NB_OP_DESTROY, NULL);
7412
7413 return nb_cli_apply_changes(vty, base_xpath);
7414 }
7415
7416 DEFUN_YANG (neighbor_weight,
7417 neighbor_weight_cmd,
7418 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7419 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7420 "Set default weight for routes from this neighbor\n"
7421 "default weight\n")
7422 {
7423 int idx_peer = 1;
7424 int idx_number = 3;
7425 char base_xpath[XPATH_MAXLEN];
7426 char af_xpath[XPATH_MAXLEN];
7427 char attr_xpath[XPATH_MAXLEN];
7428 afi_t afi = bgp_node_afi(vty);
7429 safi_t safi = bgp_node_safi(vty);
7430
7431 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
7432 yang_afi_safi_value2identity(afi, safi));
7433
7434 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7435 sizeof(base_xpath), af_xpath)
7436 < 0)
7437 return CMD_WARNING_CONFIG_FAILED;
7438
7439 snprintf(attr_xpath, sizeof(attr_xpath), "./%s/weight/weight-attribute",
7440 bgp_afi_safi_get_container_str(afi, safi));
7441
7442 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY,
7443 argv[idx_number]->arg);
7444
7445 return nb_cli_apply_changes(vty, base_xpath);
7446 }
7447
7448 ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
7449 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7450 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7451 "Set default weight for routes from this neighbor\n"
7452 "default weight\n")
7453
7454 DEFUN_YANG (no_neighbor_weight,
7455 no_neighbor_weight_cmd,
7456 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7457 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7458 "Set default weight for routes from this neighbor\n"
7459 "default weight\n")
7460 {
7461 int idx_peer = 2;
7462 char base_xpath[XPATH_MAXLEN];
7463 char af_xpath[XPATH_MAXLEN];
7464 char attr_xpath[XPATH_MAXLEN];
7465 afi_t afi = bgp_node_afi(vty);
7466 safi_t safi = bgp_node_safi(vty);
7467
7468 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
7469 yang_afi_safi_value2identity(afi, safi));
7470
7471 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7472 sizeof(base_xpath), af_xpath)
7473 < 0)
7474 return CMD_WARNING_CONFIG_FAILED;
7475
7476 snprintf(attr_xpath, sizeof(attr_xpath), "./%s/weight/weight-attribute",
7477 bgp_afi_safi_get_container_str(afi, safi));
7478
7479 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_DESTROY, NULL);
7480
7481 return nb_cli_apply_changes(vty, base_xpath);
7482 }
7483
7484 ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
7485 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7486 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7487 "Set default weight for routes from this neighbor\n"
7488 "default weight\n")
7489
7490
7491 /* Override capability negotiation. */
7492 DEFUN_YANG (neighbor_override_capability,
7493 neighbor_override_capability_cmd,
7494 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7495 NEIGHBOR_STR
7496 NEIGHBOR_ADDR_STR2
7497 "Override capability negotiation result\n")
7498 {
7499 int idx_peer = 1;
7500 char base_xpath[XPATH_MAXLEN];
7501
7502 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7503 sizeof(base_xpath), NULL)
7504 < 0)
7505 return CMD_WARNING_CONFIG_FAILED;
7506
7507 nb_cli_enqueue_change(
7508 vty, "./capability-options/override-capability",
7509 NB_OP_MODIFY, "true");
7510
7511 return nb_cli_apply_changes(vty, base_xpath);
7512 }
7513
7514 DEFUN_YANG (no_neighbor_override_capability,
7515 no_neighbor_override_capability_cmd,
7516 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7517 NO_STR
7518 NEIGHBOR_STR
7519 NEIGHBOR_ADDR_STR2
7520 "Override capability negotiation result\n")
7521 {
7522 int idx_peer = 2;
7523 char base_xpath[XPATH_MAXLEN];
7524
7525 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7526 sizeof(base_xpath), NULL)
7527 < 0)
7528 return CMD_WARNING_CONFIG_FAILED;
7529
7530 nb_cli_enqueue_change(
7531 vty, "./capability-options/override-capability",
7532 NB_OP_MODIFY, "false");
7533
7534 return nb_cli_apply_changes(vty, base_xpath);
7535 }
7536
7537 DEFUN_YANG (neighbor_strict_capability,
7538 neighbor_strict_capability_cmd,
7539 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7540 NEIGHBOR_STR
7541 NEIGHBOR_ADDR_STR2
7542 "Strict capability negotiation match\n")
7543 {
7544 int idx_peer = 1;
7545 char base_xpath[XPATH_MAXLEN];
7546
7547 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7548 sizeof(base_xpath), NULL)
7549 < 0)
7550 return CMD_WARNING_CONFIG_FAILED;
7551
7552 nb_cli_enqueue_change(
7553 vty, "./capability-options/strict-capability",
7554 NB_OP_MODIFY, "true");
7555
7556 return nb_cli_apply_changes(vty, base_xpath);
7557 }
7558
7559 DEFUN_YANG (no_neighbor_strict_capability,
7560 no_neighbor_strict_capability_cmd,
7561 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7562 NO_STR
7563 NEIGHBOR_STR
7564 NEIGHBOR_ADDR_STR2
7565 "Strict capability negotiation match\n")
7566 {
7567 int idx_peer = 2;
7568 char base_xpath[XPATH_MAXLEN];
7569
7570 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7571 sizeof(base_xpath), NULL)
7572 < 0)
7573 return CMD_WARNING_CONFIG_FAILED;
7574
7575 nb_cli_enqueue_change(
7576 vty, "./capability-options/strict-capability",
7577 NB_OP_MODIFY, "false");
7578
7579 return nb_cli_apply_changes(vty, base_xpath);
7580 }
7581
7582 DEFUN_YANG (neighbor_timers,
7583 neighbor_timers_cmd,
7584 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
7585 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7586 "BGP per neighbor timers\n"
7587 "Keepalive interval\n"
7588 "Holdtime\n")
7589 {
7590 int idx_peer = 1;
7591 int idx_number = 3;
7592 int idx_number_2 = 4;
7593 char base_xpath[XPATH_MAXLEN];
7594
7595 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7596 sizeof(base_xpath), NULL)
7597 < 0)
7598 return CMD_WARNING_CONFIG_FAILED;
7599
7600 nb_cli_enqueue_change(vty, "./timers/keepalive", NB_OP_MODIFY,
7601 argv[idx_number]->arg);
7602
7603 nb_cli_enqueue_change(vty, "./timers/hold-time", NB_OP_MODIFY,
7604 argv[idx_number_2]->arg);
7605
7606 return nb_cli_apply_changes(vty, base_xpath);
7607 }
7608
7609 DEFUN_YANG (no_neighbor_timers,
7610 no_neighbor_timers_cmd,
7611 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
7612 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7613 "BGP per neighbor timers\n"
7614 "Keepalive interval\n"
7615 "Holdtime\n")
7616 {
7617 int idx_peer = 2;
7618 char base_xpath[XPATH_MAXLEN];
7619
7620 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7621 sizeof(base_xpath), NULL)
7622 < 0)
7623 return CMD_WARNING_CONFIG_FAILED;
7624
7625 nb_cli_enqueue_change(vty, "./timers/hold-time", NB_OP_DESTROY, NULL);
7626
7627 nb_cli_enqueue_change(vty, "./timers/keepalive", NB_OP_DESTROY, NULL);
7628
7629 return nb_cli_apply_changes(vty, base_xpath);
7630 }
7631
7632 DEFUN_YANG (neighbor_timers_connect,
7633 neighbor_timers_connect_cmd,
7634 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
7635 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7636 "BGP per neighbor timers\n"
7637 "BGP connect timer\n"
7638 "Connect timer\n")
7639 {
7640 int idx_peer = 1;
7641 int idx_number = 4;
7642 char base_xpath[XPATH_MAXLEN];
7643
7644 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7645 sizeof(base_xpath), NULL)
7646 < 0)
7647 return CMD_WARNING_CONFIG_FAILED;
7648
7649 nb_cli_enqueue_change(vty, "./timers/connect-time", NB_OP_MODIFY,
7650 argv[idx_number]->arg);
7651
7652 return nb_cli_apply_changes(vty, base_xpath);
7653 }
7654
7655 DEFUN_YANG (no_neighbor_timers_connect,
7656 no_neighbor_timers_connect_cmd,
7657 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
7658 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7659 "BGP per neighbor timers\n"
7660 "BGP connect timer\n"
7661 "Connect timer\n")
7662 {
7663 int idx_peer = 2;
7664 char base_xpath[XPATH_MAXLEN];
7665
7666 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7667 sizeof(base_xpath), NULL)
7668 < 0)
7669 return CMD_WARNING_CONFIG_FAILED;
7670
7671 nb_cli_enqueue_change(vty, "./timers/connect-time", NB_OP_DESTROY,
7672 NULL);
7673
7674 return nb_cli_apply_changes(vty, base_xpath);
7675 }
7676
7677 DEFPY (neighbor_timers_delayopen,
7678 neighbor_timers_delayopen_cmd,
7679 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen (1-240)$interval",
7680 NEIGHBOR_STR
7681 NEIGHBOR_ADDR_STR2
7682 "BGP per neighbor timers\n"
7683 "RFC 4271 DelayOpenTimer\n"
7684 "DelayOpenTime timer interval\n")
7685 {
7686 struct peer *peer;
7687
7688 peer = peer_and_group_lookup_vty(vty, neighbor);
7689 if (!peer)
7690 return CMD_WARNING_CONFIG_FAILED;
7691
7692 if (!interval) {
7693 if (peer_timers_delayopen_unset(peer))
7694 return CMD_WARNING_CONFIG_FAILED;
7695 } else {
7696 if (peer_timers_delayopen_set(peer, interval))
7697 return CMD_WARNING_CONFIG_FAILED;
7698 }
7699
7700 return CMD_SUCCESS;
7701 }
7702
7703 DEFPY (no_neighbor_timers_delayopen,
7704 no_neighbor_timers_delayopen_cmd,
7705 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen [(0-65535)]",
7706 NO_STR
7707 NEIGHBOR_STR
7708 NEIGHBOR_ADDR_STR2
7709 "BGP per neighbor timers\n"
7710 "RFC 4271 DelayOpenTimer\n"
7711 "DelayOpenTime timer interval\n")
7712 {
7713 struct peer *peer;
7714
7715 peer = peer_and_group_lookup_vty(vty, neighbor);
7716 if (!peer)
7717 return CMD_WARNING_CONFIG_FAILED;
7718
7719 if (peer_timers_delayopen_unset(peer))
7720 return CMD_WARNING_CONFIG_FAILED;
7721
7722 return CMD_SUCCESS;
7723 }
7724
7725 DEFUN_YANG (neighbor_advertise_interval,
7726 neighbor_advertise_interval_cmd,
7727 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
7728 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7729 "Minimum interval between sending BGP routing updates\n"
7730 "time in seconds\n")
7731 {
7732 int idx_peer = 1;
7733 int idx_number = 3;
7734 char base_xpath[XPATH_MAXLEN];
7735
7736 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7737 sizeof(base_xpath), NULL)
7738 < 0)
7739 return CMD_WARNING_CONFIG_FAILED;
7740
7741 nb_cli_enqueue_change(vty, "./timers/advertise-interval", NB_OP_MODIFY,
7742 argv[idx_number]->arg);
7743
7744 return nb_cli_apply_changes(vty, base_xpath);
7745 }
7746
7747 DEFUN_YANG (no_neighbor_advertise_interval,
7748 no_neighbor_advertise_interval_cmd,
7749 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
7750 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7751 "Minimum interval between sending BGP routing updates\n"
7752 "time in seconds\n")
7753 {
7754 int idx_peer = 2;
7755 char base_xpath[XPATH_MAXLEN];
7756
7757 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7758 sizeof(base_xpath), NULL)
7759 < 0)
7760 return CMD_WARNING_CONFIG_FAILED;
7761
7762 nb_cli_enqueue_change(vty, "./timers/advertise-interval", NB_OP_DESTROY,
7763 NULL);
7764
7765 return nb_cli_apply_changes(vty, base_xpath);
7766 }
7767
7768
7769 /* Time to wait before processing route-map updates */
7770 DEFUN (bgp_set_route_map_delay_timer,
7771 bgp_set_route_map_delay_timer_cmd,
7772 "bgp route-map delay-timer (0-600)",
7773 SET_STR
7774 "BGP route-map delay timer\n"
7775 "Time in secs to wait before processing route-map changes\n"
7776 "0 disables the timer, no route updates happen when route-maps change\n")
7777 {
7778 int idx_number = 3;
7779 uint32_t rmap_delay_timer;
7780
7781 if (argv[idx_number]->arg) {
7782 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
7783 bm->rmap_update_timer = rmap_delay_timer;
7784
7785 /* if the dynamic update handling is being disabled, and a timer
7786 * is
7787 * running, stop the timer and act as if the timer has already
7788 * fired.
7789 */
7790 if (!rmap_delay_timer && bm->t_rmap_update) {
7791 BGP_TIMER_OFF(bm->t_rmap_update);
7792 thread_execute(bm->master, bgp_route_map_update_timer,
7793 NULL, 0);
7794 }
7795 return CMD_SUCCESS;
7796 } else {
7797 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
7798 return CMD_WARNING_CONFIG_FAILED;
7799 }
7800 }
7801
7802 DEFUN (no_bgp_set_route_map_delay_timer,
7803 no_bgp_set_route_map_delay_timer_cmd,
7804 "no bgp route-map delay-timer [(0-600)]",
7805 NO_STR
7806 BGP_STR
7807 "Default BGP route-map delay timer\n"
7808 "Reset to default time to wait for processing route-map changes\n"
7809 "0 disables the timer, no route updates happen when route-maps change\n")
7810 {
7811
7812 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
7813
7814 return CMD_SUCCESS;
7815 }
7816
7817 DEFUN_YANG (neighbor_interface,
7818 neighbor_interface_cmd,
7819 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
7820 NEIGHBOR_STR NEIGHBOR_ADDR_STR
7821 "Interface\n"
7822 "Interface name\n")
7823 {
7824 int idx_ip = 1;
7825 int idx_word = 3;
7826 char base_xpath[XPATH_MAXLEN];
7827
7828 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_NUM_XPATH,
7829 argv[idx_ip]->arg, "");
7830
7831 nb_cli_enqueue_change(vty, "./local-interface", NB_OP_MODIFY,
7832 argv[idx_word]->arg);
7833
7834 return nb_cli_apply_changes(vty, base_xpath);
7835 }
7836
7837 DEFUN_YANG (no_neighbor_interface,
7838 no_neighbor_interface_cmd,
7839 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
7840 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7841 "Interface\n"
7842 "Interface name\n")
7843 {
7844 int idx_peer = 2;
7845 char base_xpath[XPATH_MAXLEN];
7846
7847 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_NUM_XPATH,
7848 argv[idx_peer]->arg, "");
7849
7850 nb_cli_enqueue_change(vty, "./local-interface", NB_OP_DESTROY, NULL);
7851
7852 return nb_cli_apply_changes(vty, base_xpath);
7853 }
7854
7855 DEFUN (neighbor_distribute_list,
7856 neighbor_distribute_list_cmd,
7857 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
7858 NEIGHBOR_STR
7859 NEIGHBOR_ADDR_STR2
7860 "Filter updates to/from this neighbor\n"
7861 "IP access-list number\n"
7862 "IP access-list number (expanded range)\n"
7863 "IP Access-list name\n"
7864 "Filter incoming updates\n"
7865 "Filter outgoing updates\n")
7866 {
7867 int idx_peer = 1;
7868 int idx_acl = 3;
7869 int direct, ret;
7870 struct peer *peer;
7871
7872 const char *pstr = argv[idx_peer]->arg;
7873 const char *acl = argv[idx_acl]->arg;
7874 const char *inout = argv[argc - 1]->text;
7875
7876 peer = peer_and_group_lookup_vty(vty, pstr);
7877 if (!peer)
7878 return CMD_WARNING_CONFIG_FAILED;
7879
7880 /* Check filter direction. */
7881 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7882 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7883 direct, acl);
7884
7885 return bgp_vty_return(vty, ret);
7886 }
7887
7888 ALIAS_HIDDEN(
7889 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
7890 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
7891 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7892 "Filter updates to/from this neighbor\n"
7893 "IP access-list number\n"
7894 "IP access-list number (expanded range)\n"
7895 "IP Access-list name\n"
7896 "Filter incoming updates\n"
7897 "Filter outgoing updates\n")
7898
7899 DEFUN (no_neighbor_distribute_list,
7900 no_neighbor_distribute_list_cmd,
7901 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
7902 NO_STR
7903 NEIGHBOR_STR
7904 NEIGHBOR_ADDR_STR2
7905 "Filter updates to/from this neighbor\n"
7906 "IP access-list number\n"
7907 "IP access-list number (expanded range)\n"
7908 "IP Access-list name\n"
7909 "Filter incoming updates\n"
7910 "Filter outgoing updates\n")
7911 {
7912 int idx_peer = 2;
7913 int direct, ret;
7914 struct peer *peer;
7915
7916 const char *pstr = argv[idx_peer]->arg;
7917 const char *inout = argv[argc - 1]->text;
7918
7919 peer = peer_and_group_lookup_vty(vty, pstr);
7920 if (!peer)
7921 return CMD_WARNING_CONFIG_FAILED;
7922
7923 /* Check filter direction. */
7924 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7925 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7926 direct);
7927
7928 return bgp_vty_return(vty, ret);
7929 }
7930
7931 ALIAS_HIDDEN(
7932 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
7933 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
7934 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7935 "Filter updates to/from this neighbor\n"
7936 "IP access-list number\n"
7937 "IP access-list number (expanded range)\n"
7938 "IP Access-list name\n"
7939 "Filter incoming updates\n"
7940 "Filter outgoing updates\n")
7941
7942 /* Set prefix list to the peer. */
7943 DEFPY_YANG(
7944 neighbor_prefix_list, neighbor_prefix_list_cmd,
7945 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor_str prefix-list WORD$prefix_str <in|out>$direction",
7946 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7947 "Filter updates to/from this neighbor\n"
7948 "Name of a prefix list\n"
7949 "Filter incoming updates\n"
7950 "Filter outgoing updates\n")
7951 {
7952 char base_xpath[XPATH_MAXLEN];
7953 char af_xpath[XPATH_MAXLEN];
7954 char plist_xpath[XPATH_MAXLEN];
7955 afi_t afi = bgp_node_afi(vty);
7956 safi_t safi = bgp_node_safi(vty);
7957
7958 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
7959 yang_afi_safi_value2identity(afi, safi));
7960 if (peer_and_group_lookup_nb(vty, neighbor_str, base_xpath,
7961 sizeof(base_xpath), af_xpath)
7962 < 0)
7963 return CMD_WARNING_CONFIG_FAILED;
7964
7965 if (strmatch(direction, "in"))
7966 snprintf(plist_xpath, sizeof(plist_xpath),
7967 "./%s/filter-config/plist-import",
7968 bgp_afi_safi_get_container_str(afi, safi));
7969 else if (strmatch(direction, "out"))
7970 snprintf(plist_xpath, sizeof(plist_xpath),
7971 "./%s/filter-config/plist-export",
7972 bgp_afi_safi_get_container_str(afi, safi));
7973
7974 if (!no)
7975 nb_cli_enqueue_change(vty, plist_xpath, NB_OP_MODIFY,
7976 prefix_str);
7977 else
7978 nb_cli_enqueue_change(vty, plist_xpath, NB_OP_DESTROY, NULL);
7979
7980 return nb_cli_apply_changes(vty, base_xpath);
7981 }
7982
7983 ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
7984 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7985 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7986 "Filter updates to/from this neighbor\n"
7987 "Name of a prefix list\n"
7988 "Filter incoming updates\n"
7989 "Filter outgoing updates\n")
7990
7991 static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7992 safi_t safi, const char *name_str,
7993 const char *direct_str)
7994 {
7995 int ret;
7996 struct peer *peer;
7997 int direct = FILTER_IN;
7998
7999 peer = peer_and_group_lookup_vty(vty, ip_str);
8000 if (!peer)
8001 return CMD_WARNING_CONFIG_FAILED;
8002
8003 /* Check filter direction. */
8004 if (strncmp(direct_str, "i", 1) == 0)
8005 direct = FILTER_IN;
8006 else if (strncmp(direct_str, "o", 1) == 0)
8007 direct = FILTER_OUT;
8008
8009 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
8010
8011 return bgp_vty_return(vty, ret);
8012 }
8013
8014 static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
8015 safi_t safi, const char *direct_str)
8016 {
8017 int ret;
8018 struct peer *peer;
8019 int direct = FILTER_IN;
8020
8021 peer = peer_and_group_lookup_vty(vty, ip_str);
8022 if (!peer)
8023 return CMD_WARNING_CONFIG_FAILED;
8024
8025 /* Check filter direction. */
8026 if (strncmp(direct_str, "i", 1) == 0)
8027 direct = FILTER_IN;
8028 else if (strncmp(direct_str, "o", 1) == 0)
8029 direct = FILTER_OUT;
8030
8031 ret = peer_aslist_unset(peer, afi, safi, direct);
8032
8033 return bgp_vty_return(vty, ret);
8034 }
8035
8036 DEFUN (neighbor_filter_list,
8037 neighbor_filter_list_cmd,
8038 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
8039 NEIGHBOR_STR
8040 NEIGHBOR_ADDR_STR2
8041 "Establish BGP filters\n"
8042 "AS path access-list name\n"
8043 "Filter incoming routes\n"
8044 "Filter outgoing routes\n")
8045 {
8046 int idx_peer = 1;
8047 int idx_word = 3;
8048 int idx_in_out = 4;
8049 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
8050 bgp_node_safi(vty), argv[idx_word]->arg,
8051 argv[idx_in_out]->arg);
8052 }
8053
8054 ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
8055 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
8056 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8057 "Establish BGP filters\n"
8058 "AS path access-list name\n"
8059 "Filter incoming routes\n"
8060 "Filter outgoing routes\n")
8061
8062 DEFUN (no_neighbor_filter_list,
8063 no_neighbor_filter_list_cmd,
8064 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
8065 NO_STR
8066 NEIGHBOR_STR
8067 NEIGHBOR_ADDR_STR2
8068 "Establish BGP filters\n"
8069 "AS path access-list name\n"
8070 "Filter incoming routes\n"
8071 "Filter outgoing routes\n")
8072 {
8073 int idx_peer = 2;
8074 int idx_in_out = 5;
8075 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
8076 bgp_node_afi(vty), bgp_node_safi(vty),
8077 argv[idx_in_out]->arg);
8078 }
8079
8080 ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
8081 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
8082 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8083 "Establish BGP filters\n"
8084 "AS path access-list name\n"
8085 "Filter incoming routes\n"
8086 "Filter outgoing routes\n")
8087
8088 /* Set advertise-map to the peer. */
8089 static int peer_advertise_map_set_vty(struct vty *vty, const char *ip_str,
8090 afi_t afi, safi_t safi,
8091 const char *advertise_str,
8092 const char *condition_str, bool condition,
8093 bool set)
8094 {
8095 int ret = CMD_WARNING_CONFIG_FAILED;
8096 struct peer *peer;
8097 struct route_map *advertise_map;
8098 struct route_map *condition_map;
8099
8100 peer = peer_and_group_lookup_vty(vty, ip_str);
8101 if (!peer)
8102 return ret;
8103
8104 condition_map = route_map_lookup_warn_noexist(vty, condition_str);
8105 advertise_map = route_map_lookup_warn_noexist(vty, advertise_str);
8106
8107 if (set)
8108 ret = peer_advertise_map_set(peer, afi, safi, advertise_str,
8109 advertise_map, condition_str,
8110 condition_map, condition);
8111 else
8112 ret = peer_advertise_map_unset(peer, afi, safi, advertise_str,
8113 advertise_map, condition_str,
8114 condition_map, condition);
8115
8116 return bgp_vty_return(vty, ret);
8117 }
8118
8119 DEFPY (neighbor_advertise_map,
8120 neighbor_advertise_map_cmd,
8121 "[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",
8122 NO_STR
8123 NEIGHBOR_STR
8124 NEIGHBOR_ADDR_STR2
8125 "Route-map to conditionally advertise routes\n"
8126 "Name of advertise map\n"
8127 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
8128 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
8129 "Name of the exist or non exist map\n")
8130 {
8131 bool condition = CONDITION_EXIST;
8132
8133 if (!strcmp(exist, "non-exist-map"))
8134 condition = CONDITION_NON_EXIST;
8135
8136 return peer_advertise_map_set_vty(vty, neighbor, bgp_node_afi(vty),
8137 bgp_node_safi(vty), advertise_str,
8138 condition_str, condition, !no);
8139 }
8140
8141 ALIAS_HIDDEN(neighbor_advertise_map, neighbor_advertise_map_hidden_cmd,
8142 "[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",
8143 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8144 "Route-map to conditionally advertise routes\n"
8145 "Name of advertise map\n"
8146 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
8147 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
8148 "Name of the exist or non exist map\n")
8149
8150 /* Set route-map to the peer. */
8151 DEFPY_YANG(
8152 neighbor_route_map, neighbor_route_map_cmd,
8153 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor_str route-map WORD$rmap_str <in|out>$direction",
8154 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8155 "Apply route map to neighbor\n"
8156 "Name of route map\n"
8157 "Apply map to incoming routes\n"
8158 "Apply map to outbound routes\n")
8159 {
8160 char base_xpath[XPATH_MAXLEN];
8161 char af_xpath[XPATH_MAXLEN];
8162 char rmap_xpath[XPATH_MAXLEN];
8163 afi_t afi = bgp_node_afi(vty);
8164 safi_t safi = bgp_node_safi(vty);
8165
8166 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8167 yang_afi_safi_value2identity(afi, safi));
8168 if (peer_and_group_lookup_nb(vty, neighbor_str, base_xpath,
8169 sizeof(base_xpath), af_xpath)
8170 < 0)
8171 return CMD_WARNING_CONFIG_FAILED;
8172
8173 if (strmatch(direction, "in"))
8174 snprintf(rmap_xpath, sizeof(rmap_xpath),
8175 "./%s/filter-config/rmap-import",
8176 bgp_afi_safi_get_container_str(afi, safi));
8177 else if (strmatch(direction, "out"))
8178 snprintf(rmap_xpath, sizeof(rmap_xpath),
8179 "./%s/filter-config/rmap-export",
8180 bgp_afi_safi_get_container_str(afi, safi));
8181
8182 if (!no) {
8183 if (!yang_dnode_existsf(
8184 vty->candidate_config->dnode,
8185 "/frr-route-map:lib/route-map[name='%s']",
8186 rmap_str)) {
8187 if (vty_shell_serv(vty))
8188 vty_out(vty,
8189 "The route-map '%s' does not exist.\n",
8190 rmap_str);
8191 }
8192 nb_cli_enqueue_change(vty, rmap_xpath, NB_OP_MODIFY, rmap_str);
8193 } else
8194 nb_cli_enqueue_change(vty, rmap_xpath, NB_OP_DESTROY, NULL);
8195
8196 return nb_cli_apply_changes(vty, base_xpath);
8197 }
8198
8199 /* Set unsuppress-map to the peer. */
8200 static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
8201 afi_t afi, safi_t safi,
8202 const char *name_str)
8203 {
8204 int ret;
8205 struct peer *peer;
8206 struct route_map *route_map;
8207
8208 peer = peer_and_group_lookup_vty(vty, ip_str);
8209 if (!peer)
8210 return CMD_WARNING_CONFIG_FAILED;
8211
8212 route_map = route_map_lookup_warn_noexist(vty, name_str);
8213 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
8214
8215 return bgp_vty_return(vty, ret);
8216 }
8217
8218 /* Unset route-map from the peer. */
8219 static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
8220 afi_t afi, safi_t safi)
8221 {
8222 int ret;
8223 struct peer *peer;
8224
8225 peer = peer_and_group_lookup_vty(vty, ip_str);
8226 if (!peer)
8227 return CMD_WARNING_CONFIG_FAILED;
8228
8229 ret = peer_unsuppress_map_unset(peer, afi, safi);
8230
8231 return bgp_vty_return(vty, ret);
8232 }
8233
8234 DEFUN (neighbor_unsuppress_map,
8235 neighbor_unsuppress_map_cmd,
8236 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8237 NEIGHBOR_STR
8238 NEIGHBOR_ADDR_STR2
8239 "Route-map to selectively unsuppress suppressed routes\n"
8240 "Name of route map\n")
8241 {
8242 int idx_peer = 1;
8243 int idx_word = 3;
8244 return peer_unsuppress_map_set_vty(
8245 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8246 argv[idx_word]->arg);
8247 }
8248
8249 ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
8250 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8251 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8252 "Route-map to selectively unsuppress suppressed routes\n"
8253 "Name of route map\n")
8254
8255 DEFUN (no_neighbor_unsuppress_map,
8256 no_neighbor_unsuppress_map_cmd,
8257 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8258 NO_STR
8259 NEIGHBOR_STR
8260 NEIGHBOR_ADDR_STR2
8261 "Route-map to selectively unsuppress suppressed routes\n"
8262 "Name of route map\n")
8263 {
8264 int idx_peer = 2;
8265 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
8266 bgp_node_afi(vty),
8267 bgp_node_safi(vty));
8268 }
8269
8270 ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
8271 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8272 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8273 "Route-map to selectively unsuppress suppressed routes\n"
8274 "Name of route map\n")
8275
8276 /* Maximum number of prefix to be sent to the neighbor. */
8277 DEFUN_YANG(neighbor_maximum_prefix_out,
8278 neighbor_maximum_prefix_out_cmd,
8279 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out (1-4294967295)",
8280 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8281 "Maximum number of prefixes to be sent to this peer\n"
8282 "Maximum no. of prefix limit\n")
8283 {
8284 char base_xpath[XPATH_MAXLEN];
8285 char af_xpath[XPATH_MAXLEN];
8286 char attr_xpath[XPATH_MAXLEN];
8287 int idx_peer = 1;
8288 int idx_number = 3;
8289 afi_t afi = bgp_node_afi(vty);
8290 safi_t safi = bgp_node_safi(vty);
8291
8292 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8293 yang_afi_safi_value2identity(afi, safi));
8294 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8295 sizeof(base_xpath), af_xpath)
8296 < 0)
8297 return CMD_WARNING_CONFIG_FAILED;
8298
8299 snprintf(attr_xpath, sizeof(attr_xpath),
8300 "/%s/prefix-limit/direction-list[direction='out']",
8301 bgp_afi_safi_get_container_str(afi, safi));
8302 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8303
8304 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8305
8306 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8307 argv[idx_number]->arg);
8308
8309 return nb_cli_apply_changes(vty, base_xpath);
8310 }
8311
8312 DEFUN_YANG(no_neighbor_maximum_prefix_out,
8313 no_neighbor_maximum_prefix_out_cmd,
8314 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out",
8315 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8316 "Maximum number of prefixes to be sent to this peer\n")
8317 {
8318 char base_xpath[XPATH_MAXLEN];
8319 char af_xpath[XPATH_MAXLEN];
8320 char attr_xpath[XPATH_MAXLEN];
8321 int idx_peer = 2;
8322 afi_t afi = bgp_node_afi(vty);
8323 safi_t safi = bgp_node_safi(vty);
8324
8325 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8326 yang_afi_safi_value2identity(afi, safi));
8327 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8328 sizeof(base_xpath), af_xpath)
8329 < 0)
8330 return CMD_WARNING_CONFIG_FAILED;
8331
8332 snprintf(attr_xpath, sizeof(attr_xpath),
8333 "/%s/prefix-limit/direction-list[direction='out']",
8334 bgp_afi_safi_get_container_str(afi, safi));
8335 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8336
8337 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
8338
8339 return nb_cli_apply_changes(vty, base_xpath);
8340 }
8341
8342 /* Maximum number of prefix configuration. Prefix count is different
8343 for each peer configuration. So this configuration can be set for
8344 each peer configuration. */
8345 DEFUN_YANG(neighbor_maximum_prefix,
8346 neighbor_maximum_prefix_cmd,
8347 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
8348 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8349 "Maximum number of prefix accept from this peer\n"
8350 "maximum no. of prefix limit\n"
8351 "Force checking all received routes not only accepted\n")
8352 {
8353 int idx_peer = 1;
8354 int idx_number = 3;
8355 int idx_force = 0;
8356 char base_xpath[XPATH_MAXLEN];
8357 char af_xpath[XPATH_MAXLEN];
8358 char attr_xpath[XPATH_MAXLEN];
8359 afi_t afi = bgp_node_afi(vty);
8360 safi_t safi = bgp_node_safi(vty);
8361
8362 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8363 yang_afi_safi_value2identity(afi, safi));
8364 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8365 sizeof(base_xpath), af_xpath)
8366 < 0)
8367 return CMD_WARNING_CONFIG_FAILED;
8368
8369 snprintf(attr_xpath, sizeof(attr_xpath),
8370 "/%s/prefix-limit/direction-list[direction='in']",
8371 bgp_afi_safi_get_container_str(afi, safi));
8372 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8373
8374 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8375
8376 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8377 argv[idx_number]->arg);
8378 if (argv_find(argv, argc, "force", &idx_force))
8379 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8380 "true");
8381
8382 return nb_cli_apply_changes(vty, base_xpath);
8383 }
8384
8385 ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
8386 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
8387 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8388 "Maximum number of prefix accept from this peer\n"
8389 "maximum no. of prefix limit\n"
8390 "Force checking all received routes not only accepted\n")
8391
8392 DEFUN_YANG(neighbor_maximum_prefix_threshold,
8393 neighbor_maximum_prefix_threshold_cmd,
8394 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
8395 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8396 "Maximum number of prefix accept from this peer\n"
8397 "maximum no. of prefix limit\n"
8398 "Threshold value (%) at which to generate a warning msg\n"
8399 "Force checking all received routes not only accepted\n")
8400 {
8401 int idx_peer = 1;
8402 int idx_number = 3;
8403 int idx_number_2 = 4;
8404 int idx_force = 0;
8405 char base_xpath[XPATH_MAXLEN];
8406 char af_xpath[XPATH_MAXLEN];
8407 char attr_xpath[XPATH_MAXLEN];
8408 afi_t afi = bgp_node_afi(vty);
8409 safi_t safi = bgp_node_safi(vty);
8410
8411 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8412 yang_afi_safi_value2identity(afi, safi));
8413 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8414 sizeof(base_xpath), af_xpath)
8415 < 0)
8416 return CMD_WARNING_CONFIG_FAILED;
8417
8418 snprintf(attr_xpath, sizeof(attr_xpath),
8419 "/%s/prefix-limit/direction-list[direction='in']",
8420 bgp_afi_safi_get_container_str(afi, safi));
8421 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8422
8423 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8424
8425 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8426 argv[idx_number]->arg);
8427
8428 nb_cli_enqueue_change(vty, "./options/shutdown-threshold-pct",
8429 NB_OP_MODIFY, argv[idx_number_2]->arg);
8430
8431 if (argv_find(argv, argc, "force", &idx_force))
8432 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8433 "true");
8434
8435 return nb_cli_apply_changes(vty, base_xpath);
8436 }
8437
8438 ALIAS_HIDDEN(
8439 neighbor_maximum_prefix_threshold,
8440 neighbor_maximum_prefix_threshold_hidden_cmd,
8441 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
8442 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8443 "Maximum number of prefix accept from this peer\n"
8444 "maximum no. of prefix limit\n"
8445 "Threshold value (%) at which to generate a warning msg\n"
8446 "Force checking all received routes not only accepted\n")
8447
8448 DEFUN_YANG(neighbor_maximum_prefix_warning,
8449 neighbor_maximum_prefix_warning_cmd,
8450 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
8451 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8452 "Maximum number of prefix accept from this peer\n"
8453 "maximum no. of prefix limit\n"
8454 "Only give warning message when limit is exceeded\n"
8455 "Force checking all received routes not only accepted\n")
8456 {
8457 int idx_peer = 1;
8458 int idx_number = 3;
8459 int idx_force = 0;
8460 char base_xpath[XPATH_MAXLEN];
8461 char af_xpath[XPATH_MAXLEN];
8462 char attr_xpath[XPATH_MAXLEN];
8463 afi_t afi = bgp_node_afi(vty);
8464 safi_t safi = bgp_node_safi(vty);
8465
8466 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8467 yang_afi_safi_value2identity(afi, safi));
8468 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8469 sizeof(base_xpath), af_xpath)
8470 < 0)
8471 return CMD_WARNING_CONFIG_FAILED;
8472
8473 snprintf(attr_xpath, sizeof(attr_xpath),
8474 "/%s/prefix-limit/direction-list[direction='in']",
8475 bgp_afi_safi_get_container_str(afi, safi));
8476 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8477
8478 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8479
8480 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8481 argv[idx_number]->arg);
8482
8483 nb_cli_enqueue_change(vty, "./options/warning-only", NB_OP_MODIFY,
8484 "true");
8485 if (argv_find(argv, argc, "force", &idx_force))
8486 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8487 "true");
8488
8489 return nb_cli_apply_changes(vty, base_xpath);
8490 }
8491
8492 ALIAS_HIDDEN(
8493 neighbor_maximum_prefix_warning,
8494 neighbor_maximum_prefix_warning_hidden_cmd,
8495 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
8496 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8497 "Maximum number of prefix accept from this peer\n"
8498 "maximum no. of prefix limit\n"
8499 "Only give warning message when limit is exceeded\n"
8500 "Force checking all received routes not only accepted\n")
8501
8502 DEFUN_YANG(neighbor_maximum_prefix_threshold_warning,
8503 neighbor_maximum_prefix_threshold_warning_cmd,
8504 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
8505 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8506 "Maximum number of prefix accept from this peer\n"
8507 "maximum no. of prefix limit\n"
8508 "Threshold value (%) at which to generate a warning msg\n"
8509 "Only give warning message when limit is exceeded\n"
8510 "Force checking all received routes not only accepted\n")
8511 {
8512 int idx_peer = 1;
8513 int idx_number = 3;
8514 int idx_number_2 = 4;
8515 int idx_force = 0;
8516 char base_xpath[XPATH_MAXLEN];
8517 char af_xpath[XPATH_MAXLEN];
8518 char attr_xpath[XPATH_MAXLEN];
8519 afi_t afi = bgp_node_afi(vty);
8520 safi_t safi = bgp_node_safi(vty);
8521
8522 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8523 yang_afi_safi_value2identity(afi, safi));
8524 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8525 sizeof(base_xpath), af_xpath)
8526 < 0)
8527 return CMD_WARNING_CONFIG_FAILED;
8528
8529 snprintf(attr_xpath, sizeof(attr_xpath),
8530 "/%s/prefix-limit/direction-list[direction='in']",
8531 bgp_afi_safi_get_container_str(afi, safi));
8532 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8533
8534 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8535
8536 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8537 argv[idx_number]->arg);
8538 nb_cli_enqueue_change(vty, "./options/tw-shutdown-threshold-pct",
8539 NB_OP_MODIFY, argv[idx_number_2]->arg);
8540 nb_cli_enqueue_change(vty, "./options/tw-warning-only", NB_OP_MODIFY,
8541 "true");
8542 if (argv_find(argv, argc, "force", &idx_force))
8543 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8544 "true");
8545
8546 return nb_cli_apply_changes(vty, base_xpath);
8547 }
8548
8549 ALIAS_HIDDEN(
8550 neighbor_maximum_prefix_threshold_warning,
8551 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
8552 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
8553 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8554 "Maximum number of prefix accept from this peer\n"
8555 "maximum no. of prefix limit\n"
8556 "Threshold value (%) at which to generate a warning msg\n"
8557 "Only give warning message when limit is exceeded\n"
8558 "Force checking all received routes not only accepted\n")
8559
8560 DEFUN_YANG(neighbor_maximum_prefix_restart,
8561 neighbor_maximum_prefix_restart_cmd,
8562 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8563 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8564 "Maximum number of prefix accept from this peer\n"
8565 "maximum no. of prefix limit\n"
8566 "Restart bgp connection after limit is exceeded\n"
8567 "Restart interval in minutes\n"
8568 "Force checking all received routes not only accepted\n")
8569 {
8570 int idx_peer = 1;
8571 int idx_number = 3;
8572 int idx_number_2 = 5;
8573 int idx_force = 0;
8574 char base_xpath[XPATH_MAXLEN];
8575 char af_xpath[XPATH_MAXLEN];
8576 char attr_xpath[XPATH_MAXLEN];
8577 afi_t afi = bgp_node_afi(vty);
8578 safi_t safi = bgp_node_safi(vty);
8579
8580 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8581 yang_afi_safi_value2identity(afi, safi));
8582 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8583 sizeof(base_xpath), af_xpath)
8584 < 0)
8585 return CMD_WARNING_CONFIG_FAILED;
8586
8587 snprintf(attr_xpath, sizeof(attr_xpath),
8588 "/%s/prefix-limit/direction-list[direction='in']",
8589 bgp_afi_safi_get_container_str(afi, safi));
8590 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8591
8592 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8593
8594 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8595 argv[idx_number]->arg);
8596 nb_cli_enqueue_change(vty, "./options/restart-timer", NB_OP_MODIFY,
8597 argv[idx_number_2]->arg);
8598 if (argv_find(argv, argc, "force", &idx_force))
8599 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8600 "true");
8601
8602 return nb_cli_apply_changes(vty, base_xpath);
8603 }
8604
8605 ALIAS_HIDDEN(
8606 neighbor_maximum_prefix_restart,
8607 neighbor_maximum_prefix_restart_hidden_cmd,
8608 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8609 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8610 "Maximum number of prefix accept from this peer\n"
8611 "maximum no. of prefix limit\n"
8612 "Restart bgp connection after limit is exceeded\n"
8613 "Restart interval in minutes\n"
8614 "Force checking all received routes not only accepted\n")
8615
8616 DEFUN_YANG(neighbor_maximum_prefix_threshold_restart,
8617 neighbor_maximum_prefix_threshold_restart_cmd,
8618 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8619 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8620 "Maximum number of prefixes to accept from this peer\n"
8621 "maximum no. of prefix limit\n"
8622 "Threshold value (%) at which to generate a warning msg\n"
8623 "Restart bgp connection after limit is exceeded\n"
8624 "Restart interval in minutes\n"
8625 "Force checking all received routes not only accepted\n")
8626 {
8627 int idx_peer = 1;
8628 int idx_number = 3;
8629 int idx_number_2 = 4;
8630 int idx_number_3 = 6;
8631 int idx_force = 0;
8632 char base_xpath[XPATH_MAXLEN];
8633 char af_xpath[XPATH_MAXLEN];
8634 char attr_xpath[XPATH_MAXLEN];
8635 afi_t afi = bgp_node_afi(vty);
8636 safi_t safi = bgp_node_safi(vty);
8637
8638 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8639 yang_afi_safi_value2identity(afi, safi));
8640 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8641 sizeof(base_xpath), af_xpath)
8642 < 0)
8643 return CMD_WARNING_CONFIG_FAILED;
8644
8645 snprintf(attr_xpath, sizeof(attr_xpath),
8646 "/%s/prefix-limit/direction-list[direction='in']",
8647 bgp_afi_safi_get_container_str(afi, safi));
8648 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8649
8650 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8651
8652 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8653 argv[idx_number]->arg);
8654 nb_cli_enqueue_change(vty, "./options/tr-shutdown-threshold-pct",
8655 NB_OP_MODIFY, argv[idx_number_2]->arg);
8656 nb_cli_enqueue_change(vty, "./options/tr-restart-timer", NB_OP_MODIFY,
8657 argv[idx_number_3]->arg);
8658 if (argv_find(argv, argc, "force", &idx_force))
8659 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8660 "true");
8661
8662 return nb_cli_apply_changes(vty, base_xpath);
8663 }
8664
8665 ALIAS_HIDDEN(
8666 neighbor_maximum_prefix_threshold_restart,
8667 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
8668 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8669 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8670 "Maximum number of prefixes to accept from this peer\n"
8671 "maximum no. of prefix limit\n"
8672 "Threshold value (%) at which to generate a warning msg\n"
8673 "Restart bgp connection after limit is exceeded\n"
8674 "Restart interval in minutes\n"
8675 "Force checking all received routes not only accepted\n")
8676
8677 DEFUN_YANG(no_neighbor_maximum_prefix,
8678 no_neighbor_maximum_prefix_cmd,
8679 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8680 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8681 "Maximum number of prefixes to accept from this peer\n"
8682 "maximum no. of prefix limit\n"
8683 "Threshold value (%) at which to generate a warning msg\n"
8684 "Restart bgp connection after limit is exceeded\n"
8685 "Restart interval in minutes\n"
8686 "Only give warning message when limit is exceeded\n"
8687 "Force checking all received routes not only accepted\n")
8688 {
8689 int idx_peer = 2;
8690 char base_xpath[XPATH_MAXLEN];
8691 char af_xpath[XPATH_MAXLEN];
8692 char attr_xpath[XPATH_MAXLEN];
8693 afi_t afi = bgp_node_afi(vty);
8694 safi_t safi = bgp_node_safi(vty);
8695
8696 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8697 yang_afi_safi_value2identity(afi, safi));
8698 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8699 sizeof(base_xpath), af_xpath)
8700 < 0)
8701 return CMD_WARNING_CONFIG_FAILED;
8702
8703 snprintf(attr_xpath, sizeof(attr_xpath),
8704 "/%s/prefix-limit/direction-list[direction='in']",
8705 bgp_afi_safi_get_container_str(afi, safi));
8706 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8707
8708 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
8709
8710 return nb_cli_apply_changes(vty, base_xpath);
8711 }
8712
8713 ALIAS_HIDDEN(
8714 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
8715 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8716 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8717 "Maximum number of prefixes to accept from this peer\n"
8718 "maximum no. of prefix limit\n"
8719 "Threshold value (%) at which to generate a warning msg\n"
8720 "Restart bgp connection after limit is exceeded\n"
8721 "Restart interval in minutes\n"
8722 "Only give warning message when limit is exceeded\n"
8723 "Force checking all received routes not only accepted\n")
8724
8725
8726 /* "neighbor allowas-in" */
8727 DEFUN (neighbor_allowas_in,
8728 neighbor_allowas_in_cmd,
8729 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8730 NEIGHBOR_STR
8731 NEIGHBOR_ADDR_STR2
8732 "Accept as-path with my AS present in it\n"
8733 "Number of occurrences of AS number\n"
8734 "Only accept my AS in the as-path if the route was originated in my AS\n")
8735 {
8736 int idx_peer = 1;
8737 int idx_number_origin = 3;
8738 int ret;
8739 int origin = 0;
8740 struct peer *peer;
8741 int allow_num = 0;
8742
8743 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8744 if (!peer)
8745 return CMD_WARNING_CONFIG_FAILED;
8746
8747 if (argc <= idx_number_origin)
8748 allow_num = 3;
8749 else {
8750 if (argv[idx_number_origin]->type == WORD_TKN)
8751 origin = 1;
8752 else
8753 allow_num = atoi(argv[idx_number_origin]->arg);
8754 }
8755
8756 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8757 allow_num, origin);
8758
8759 return bgp_vty_return(vty, ret);
8760 }
8761
8762 ALIAS_HIDDEN(
8763 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
8764 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8765 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8766 "Accept as-path with my AS present in it\n"
8767 "Number of occurrences of AS number\n"
8768 "Only accept my AS in the as-path if the route was originated in my AS\n")
8769
8770 DEFUN (no_neighbor_allowas_in,
8771 no_neighbor_allowas_in_cmd,
8772 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8773 NO_STR
8774 NEIGHBOR_STR
8775 NEIGHBOR_ADDR_STR2
8776 "allow local ASN appears in aspath attribute\n"
8777 "Number of occurrences of AS number\n"
8778 "Only accept my AS in the as-path if the route was originated in my AS\n")
8779 {
8780 int idx_peer = 2;
8781 int ret;
8782 struct peer *peer;
8783
8784 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8785 if (!peer)
8786 return CMD_WARNING_CONFIG_FAILED;
8787
8788 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
8789 bgp_node_safi(vty));
8790
8791 return bgp_vty_return(vty, ret);
8792 }
8793
8794 ALIAS_HIDDEN(
8795 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
8796 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8797 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8798 "allow local ASN appears in aspath attribute\n"
8799 "Number of occurrences of AS number\n"
8800 "Only accept my AS in the as-path if the route was originated in my AS\n")
8801
8802 DEFUN_YANG (neighbor_ttl_security,
8803 neighbor_ttl_security_cmd,
8804 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8805 NEIGHBOR_STR
8806 NEIGHBOR_ADDR_STR2
8807 "BGP ttl-security parameters\n"
8808 "Specify the maximum number of hops to the BGP peer\n"
8809 "Number of hops to BGP peer\n")
8810 {
8811 int idx_peer = 1;
8812 int idx_number = 4;
8813 char base_xpath[XPATH_MAXLEN];
8814
8815 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8816 sizeof(base_xpath), NULL)
8817 < 0)
8818 return CMD_WARNING_CONFIG_FAILED;
8819
8820 nb_cli_enqueue_change(vty, "./ttl-security", NB_OP_MODIFY,
8821 argv[idx_number]->arg);
8822
8823 return nb_cli_apply_changes(vty, base_xpath);
8824 }
8825
8826 DEFUN_YANG(no_neighbor_ttl_security,
8827 no_neighbor_ttl_security_cmd,
8828 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8829 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8830 "BGP ttl-security parameters\n"
8831 "Specify the maximum number of hops to the BGP peer\n"
8832 "Number of hops to BGP peer\n")
8833 {
8834 int idx_peer = 2;
8835 char base_xpath[XPATH_MAXLEN];
8836
8837 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8838 sizeof(base_xpath), NULL)
8839 < 0)
8840 return CMD_WARNING_CONFIG_FAILED;
8841
8842 nb_cli_enqueue_change(vty, "./ttl-security", NB_OP_DESTROY, NULL);
8843
8844 return nb_cli_apply_changes(vty, base_xpath);
8845 }
8846
8847 DEFUN (neighbor_addpath_tx_all_paths,
8848 neighbor_addpath_tx_all_paths_cmd,
8849 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8850 NEIGHBOR_STR
8851 NEIGHBOR_ADDR_STR2
8852 "Use addpath to advertise all paths to a neighbor\n")
8853 {
8854 int idx_peer = 1;
8855 struct peer *peer;
8856
8857 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8858 if (!peer)
8859 return CMD_WARNING_CONFIG_FAILED;
8860
8861 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8862 BGP_ADDPATH_ALL);
8863 return CMD_SUCCESS;
8864 }
8865
8866 ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
8867 neighbor_addpath_tx_all_paths_hidden_cmd,
8868 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8869 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8870 "Use addpath to advertise all paths to a neighbor\n")
8871
8872 DEFUN (no_neighbor_addpath_tx_all_paths,
8873 no_neighbor_addpath_tx_all_paths_cmd,
8874 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8875 NO_STR
8876 NEIGHBOR_STR
8877 NEIGHBOR_ADDR_STR2
8878 "Use addpath to advertise all paths to a neighbor\n")
8879 {
8880 int idx_peer = 2;
8881 struct peer *peer;
8882
8883 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8884 if (!peer)
8885 return CMD_WARNING_CONFIG_FAILED;
8886
8887 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8888 != BGP_ADDPATH_ALL) {
8889 vty_out(vty,
8890 "%% Peer not currently configured to transmit all paths.");
8891 return CMD_WARNING_CONFIG_FAILED;
8892 }
8893
8894 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8895 BGP_ADDPATH_NONE);
8896
8897 return CMD_SUCCESS;
8898 }
8899
8900 ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
8901 no_neighbor_addpath_tx_all_paths_hidden_cmd,
8902 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8903 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8904 "Use addpath to advertise all paths to a neighbor\n")
8905
8906 DEFUN (neighbor_addpath_tx_bestpath_per_as,
8907 neighbor_addpath_tx_bestpath_per_as_cmd,
8908 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8909 NEIGHBOR_STR
8910 NEIGHBOR_ADDR_STR2
8911 "Use addpath to advertise the bestpath per each neighboring AS\n")
8912 {
8913 int idx_peer = 1;
8914 struct peer *peer;
8915
8916 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8917 if (!peer)
8918 return CMD_WARNING_CONFIG_FAILED;
8919
8920 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8921 BGP_ADDPATH_BEST_PER_AS);
8922
8923 return CMD_SUCCESS;
8924 }
8925
8926 ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
8927 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8928 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8929 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8930 "Use addpath to advertise the bestpath per each neighboring AS\n")
8931
8932 DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
8933 no_neighbor_addpath_tx_bestpath_per_as_cmd,
8934 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8935 NO_STR
8936 NEIGHBOR_STR
8937 NEIGHBOR_ADDR_STR2
8938 "Use addpath to advertise the bestpath per each neighboring AS\n")
8939 {
8940 int idx_peer = 2;
8941 struct peer *peer;
8942
8943 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8944 if (!peer)
8945 return CMD_WARNING_CONFIG_FAILED;
8946
8947 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8948 != BGP_ADDPATH_BEST_PER_AS) {
8949 vty_out(vty,
8950 "%% Peer not currently configured to transmit all best path per as.");
8951 return CMD_WARNING_CONFIG_FAILED;
8952 }
8953
8954 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8955 BGP_ADDPATH_NONE);
8956
8957 return CMD_SUCCESS;
8958 }
8959
8960 ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
8961 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8962 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8963 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8964 "Use addpath to advertise the bestpath per each neighboring AS\n")
8965
8966 DEFPY(
8967 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
8968 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8969 NEIGHBOR_STR
8970 NEIGHBOR_ADDR_STR2
8971 "Detect AS loops before sending to neighbor\n")
8972 {
8973 struct peer *peer;
8974
8975 peer = peer_and_group_lookup_vty(vty, neighbor);
8976 if (!peer)
8977 return CMD_WARNING_CONFIG_FAILED;
8978
8979 peer->as_path_loop_detection = true;
8980
8981 return CMD_SUCCESS;
8982 }
8983
8984 DEFPY(
8985 no_neighbor_aspath_loop_detection,
8986 no_neighbor_aspath_loop_detection_cmd,
8987 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8988 NO_STR
8989 NEIGHBOR_STR
8990 NEIGHBOR_ADDR_STR2
8991 "Detect AS loops before sending to neighbor\n")
8992 {
8993 struct peer *peer;
8994
8995 peer = peer_and_group_lookup_vty(vty, neighbor);
8996 if (!peer)
8997 return CMD_WARNING_CONFIG_FAILED;
8998
8999 peer->as_path_loop_detection = false;
9000
9001 return CMD_SUCCESS;
9002 }
9003
9004 DEFPY(neighbor_damp,
9005 neighbor_damp_cmd,
9006 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor dampening [(1-45)$half [(1-20000)$reuse (1-20000)$suppress (1-255)$max]]",
9007 NEIGHBOR_STR
9008 NEIGHBOR_ADDR_STR2
9009 "Enable neighbor route-flap dampening\n"
9010 "Half-life time for the penalty\n"
9011 "Value to start reusing a route\n"
9012 "Value to start suppressing a route\n"
9013 "Maximum duration to suppress a stable route\n")
9014 {
9015 struct peer *peer = peer_and_group_lookup_vty(vty, neighbor);
9016
9017 if (!peer)
9018 return CMD_WARNING_CONFIG_FAILED;
9019 if (!half)
9020 half = DEFAULT_HALF_LIFE;
9021 if (!reuse) {
9022 reuse = DEFAULT_REUSE;
9023 suppress = DEFAULT_SUPPRESS;
9024 max = half * 4;
9025 }
9026 if (suppress < reuse) {
9027 vty_out(vty,
9028 "Suppress value cannot be less than reuse value\n");
9029 return CMD_WARNING_CONFIG_FAILED;
9030 }
9031 bgp_peer_damp_enable(peer, bgp_node_afi(vty), bgp_node_safi(vty),
9032 half * 60, reuse, suppress, max * 60);
9033 return CMD_SUCCESS;
9034 }
9035
9036 DEFPY(no_neighbor_damp,
9037 no_neighbor_damp_cmd,
9038 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor dampening [HALF [REUSE SUPPRESS MAX]]",
9039 NO_STR
9040 NEIGHBOR_STR
9041 NEIGHBOR_ADDR_STR2
9042 "Enable neighbor route-flap dampening\n"
9043 "Half-life time for the penalty\n"
9044 "Value to start reusing a route\n"
9045 "Value to start suppressing a route\n"
9046 "Maximum duration to suppress a stable route\n")
9047 {
9048 struct peer *peer = peer_and_group_lookup_vty(vty, neighbor);
9049
9050 if (!peer)
9051 return CMD_WARNING_CONFIG_FAILED;
9052 bgp_peer_damp_disable(peer, bgp_node_afi(vty), bgp_node_safi(vty));
9053 return CMD_SUCCESS;
9054 }
9055
9056 DEFPY (show_ip_bgp_neighbor_damp_param,
9057 show_ip_bgp_neighbor_damp_param_cmd,
9058 "show [ip] bgp [<ipv4|ipv6> [unicast]] neighbors <A.B.C.D|X:X::X:X|WORD>$neighbor dampening parameters [json]$json",
9059 SHOW_STR
9060 IP_STR
9061 BGP_STR
9062 BGP_AFI_HELP_STR
9063 "Address Family modifier\n"
9064 NEIGHBOR_STR
9065 NEIGHBOR_ADDR_STR2
9066 "Neighbor route-flap dampening information\n"
9067 "Display detail of configured dampening parameters\n"
9068 JSON_STR)
9069 {
9070 bool use_json = false;
9071 int idx = 0;
9072 afi_t afi = AFI_IP;
9073 safi_t safi = SAFI_UNICAST;
9074 struct peer *peer;
9075
9076 if (argv_find(argv, argc, "ip", &idx))
9077 afi = AFI_IP;
9078 if (argv_find(argv, argc, "ipv4", &idx))
9079 afi = AFI_IP;
9080 if (argv_find(argv, argc, "ipv6", &idx))
9081 afi = AFI_IP6;
9082 peer = peer_and_group_lookup_vty(vty, neighbor);
9083 if (!peer)
9084 return CMD_WARNING;
9085 if (json)
9086 use_json = true;
9087 bgp_show_peer_dampening_parameters(vty, peer, afi, safi, use_json);
9088 return CMD_SUCCESS;
9089 }
9090
9091 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
9092 struct ecommunity **list, bool is_rt6)
9093 {
9094 struct ecommunity *ecom = NULL;
9095 struct ecommunity *ecomadd;
9096
9097 for (; argc; --argc, ++argv) {
9098 if (is_rt6)
9099 ecomadd = ecommunity_str2com_ipv6(argv[0]->arg,
9100 ECOMMUNITY_ROUTE_TARGET,
9101 0);
9102 else
9103 ecomadd = ecommunity_str2com(argv[0]->arg,
9104 ECOMMUNITY_ROUTE_TARGET,
9105 0);
9106 if (!ecomadd) {
9107 vty_out(vty, "Malformed community-list value\n");
9108 if (ecom)
9109 ecommunity_free(&ecom);
9110 return CMD_WARNING_CONFIG_FAILED;
9111 }
9112
9113 if (ecom) {
9114 ecommunity_merge(ecom, ecomadd);
9115 ecommunity_free(&ecomadd);
9116 } else {
9117 ecom = ecomadd;
9118 }
9119 }
9120
9121 if (*list) {
9122 ecommunity_free(&*list);
9123 }
9124 *list = ecom;
9125
9126 return CMD_SUCCESS;
9127 }
9128
9129 bool vpn_policy_check_import(struct bgp *bgp, afi_t afi, safi_t safi,
9130 bool v2vimport, char *errmsg, size_t errmsg_len)
9131 {
9132 if (!v2vimport) {
9133 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9134 BGP_CONFIG_VRF_TO_VRF_IMPORT)
9135 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9136 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
9137 snprintf(
9138 errmsg, errmsg_len, "%s",
9139 "%% error: Please unconfigure import vrf commands before using vpn commands");
9140 return false;
9141 }
9142 } else {
9143 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9144 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
9145 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9146 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
9147 snprintf(
9148 errmsg, errmsg_len, "%s",
9149 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands");
9150 return false;
9151 }
9152 }
9153 return true;
9154 }
9155
9156 /*
9157 * v2vimport is true if we are handling a `import vrf ...` command
9158 */
9159 static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
9160 {
9161 afi_t afi;
9162
9163 switch (vty->node) {
9164 case BGP_IPV4_NODE:
9165 afi = AFI_IP;
9166 break;
9167 case BGP_IPV6_NODE:
9168 afi = AFI_IP6;
9169 break;
9170 default:
9171 vty_out(vty,
9172 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
9173 return AFI_MAX;
9174 }
9175
9176 if (!v2vimport) {
9177 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9178 BGP_CONFIG_VRF_TO_VRF_IMPORT)
9179 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9180 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
9181 vty_out(vty,
9182 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
9183 return AFI_MAX;
9184 }
9185 } else {
9186 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9187 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
9188 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9189 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
9190 vty_out(vty,
9191 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
9192 return AFI_MAX;
9193 }
9194 }
9195 return afi;
9196 }
9197
9198 DEFPY_YANG(
9199 af_rd_vpn_export,
9200 af_rd_vpn_export_cmd,
9201 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
9202 NO_STR
9203 "Specify route distinguisher\n"
9204 "Between current address-family and vpn\n"
9205 "For routes leaked from current address-family to vpn\n"
9206 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
9207 {
9208 char base_xpath[XPATH_MAXLEN];
9209 afi_t afi;
9210 safi_t safi;
9211 int idx = 0;
9212
9213 afi = bgp_node_afi(vty);
9214 safi = bgp_node_safi(vty);
9215
9216 snprintf(
9217 base_xpath, sizeof(base_xpath),
9218 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config",
9219 yang_afi_safi_value2identity(afi, safi),
9220 bgp_afi_safi_get_container_str(afi, safi));
9221
9222 if (argv_find(argv, argc, "no", &idx))
9223 nb_cli_enqueue_change(vty, "./rd", NB_OP_DESTROY, NULL);
9224 else
9225 nb_cli_enqueue_change(vty, "./rd", NB_OP_MODIFY, rd_str);
9226
9227 return nb_cli_apply_changes(vty, base_xpath);
9228 }
9229
9230 void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rd(
9231 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9232 {
9233 int indent = 2;
9234
9235 vty_out(vty, "%*srd vpn export %s\n", indent, "",
9236 yang_dnode_get_string(dnode, NULL));
9237 }
9238
9239 ALIAS (af_rd_vpn_export,
9240 af_no_rd_vpn_export_cmd,
9241 "no rd vpn export",
9242 NO_STR
9243 "Specify route distinguisher\n"
9244 "Between current address-family and vpn\n"
9245 "For routes leaked from current address-family to vpn\n")
9246
9247 DEFPY (af_label_vpn_export,
9248 af_label_vpn_export_cmd,
9249 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
9250 NO_STR
9251 "label value for VRF\n"
9252 "Between current address-family and vpn\n"
9253 "For routes leaked from current address-family to vpn\n"
9254 "Label Value <0-1048575>\n"
9255 "Automatically assign a label\n")
9256 {
9257 VTY_DECLVAR_CONTEXT(bgp, bgp);
9258 mpls_label_t label = MPLS_LABEL_NONE;
9259 afi_t afi;
9260 int idx = 0;
9261 bool yes = true;
9262
9263 if (argv_find(argv, argc, "no", &idx))
9264 yes = false;
9265
9266 /* If "no ...", squash trailing parameter */
9267 if (!yes)
9268 label_auto = NULL;
9269
9270 if (yes) {
9271 if (!label_auto)
9272 label = label_val; /* parser should force unsigned */
9273 }
9274
9275 afi = vpn_policy_getafi(vty, bgp, false);
9276 if (afi == AFI_MAX)
9277 return CMD_WARNING_CONFIG_FAILED;
9278
9279
9280 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9281 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
9282 /* no change */
9283 return CMD_SUCCESS;
9284
9285 /*
9286 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
9287 */
9288 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9289 bgp_get_default(), bgp);
9290
9291 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9292 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
9293
9294 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
9295
9296 /*
9297 * label has previously been automatically
9298 * assigned by labelpool: release it
9299 *
9300 * NB if tovpn_label == MPLS_LABEL_NONE it
9301 * means the automatic assignment is in flight
9302 * and therefore the labelpool callback must
9303 * detect that the auto label is not needed.
9304 */
9305
9306 bgp_lp_release(LP_TYPE_VRF,
9307 &bgp->vpn_policy[afi],
9308 bgp->vpn_policy[afi].tovpn_label);
9309 }
9310 UNSET_FLAG(bgp->vpn_policy[afi].flags,
9311 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
9312 }
9313
9314 bgp->vpn_policy[afi].tovpn_label = label;
9315 if (label_auto) {
9316 SET_FLAG(bgp->vpn_policy[afi].flags,
9317 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
9318 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
9319 vpn_leak_label_callback);
9320 }
9321
9322 /* post-change: re-export vpn routes */
9323 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9324 bgp_get_default(), bgp);
9325
9326 hook_call(bgp_snmp_update_last_changed, bgp);
9327 return CMD_SUCCESS;
9328 }
9329
9330 DEFPY (af_sid_vpn_export,
9331 af_sid_vpn_export_cmd,
9332 "[no] sid vpn export <(1-255)$sid_idx|auto$sid_auto>",
9333 NO_STR
9334 "sid value for VRF\n"
9335 "Between current address-family and vpn\n"
9336 "For routes leaked from current address-family to vpn\n"
9337 "Sid allocation index\n"
9338 "Automatically assign a label\n")
9339 {
9340 VTY_DECLVAR_CONTEXT(bgp, bgp);
9341 afi_t afi;
9342 int debug = 0;
9343 int idx = 0;
9344 bool yes = true;
9345
9346 if (argv_find(argv, argc, "no", &idx))
9347 yes = false;
9348 debug = (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF) |
9349 BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF));
9350
9351 afi = vpn_policy_getafi(vty, bgp, false);
9352 if (afi == AFI_MAX)
9353 return CMD_WARNING_CONFIG_FAILED;
9354
9355 if (!yes) {
9356 /* implement me */
9357 vty_out(vty, "It's not implemented");
9358 return CMD_WARNING_CONFIG_FAILED;
9359 }
9360
9361 /* skip when it's already configured */
9362 if ((sid_idx != 0 && bgp->vpn_policy[afi].tovpn_sid_index != 0)
9363 || (sid_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9364 BGP_VPN_POLICY_TOVPN_SID_AUTO)))
9365 return CMD_SUCCESS;
9366
9367 /*
9368 * mode change between sid_idx and sid_auto isn't supported.
9369 * user must negate sid vpn export when they want to change the mode
9370 */
9371 if ((sid_auto && bgp->vpn_policy[afi].tovpn_sid_index != 0)
9372 || (sid_idx != 0 && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9373 BGP_VPN_POLICY_TOVPN_SID_AUTO))) {
9374 vty_out(vty, "it's already configured as %s.\n",
9375 sid_auto ? "auto-mode" : "idx-mode");
9376 return CMD_WARNING_CONFIG_FAILED;
9377 }
9378
9379 /* pre-change */
9380 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9381 bgp_get_default(), bgp);
9382
9383 if (sid_auto) {
9384 /* SID allocation auto-mode */
9385 if (debug)
9386 zlog_debug("%s: auto sid alloc.", __func__);
9387 SET_FLAG(bgp->vpn_policy[afi].flags,
9388 BGP_VPN_POLICY_TOVPN_SID_AUTO);
9389 } else {
9390 /* SID allocation index-mode */
9391 if (debug)
9392 zlog_debug("%s: idx %ld sid alloc.", __func__, sid_idx);
9393 bgp->vpn_policy[afi].tovpn_sid_index = sid_idx;
9394 }
9395
9396 /* post-change */
9397 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9398 bgp_get_default(), bgp);
9399 return CMD_SUCCESS;
9400 }
9401
9402 ALIAS (af_label_vpn_export,
9403 af_no_label_vpn_export_cmd,
9404 "no label vpn export",
9405 NO_STR
9406 "label value for VRF\n"
9407 "Between current address-family and vpn\n"
9408 "For routes leaked from current address-family to vpn\n")
9409
9410 DEFPY_YANG (af_nexthop_vpn_export,
9411 af_nexthop_vpn_export_cmd,
9412 "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
9413 NO_STR
9414 "Specify next hop to use for VRF advertised prefixes\n"
9415 "Between current address-family and vpn\n"
9416 "For routes leaked from current address-family to vpn\n"
9417 "IPv4 prefix\n"
9418 "IPv6 prefix\n")
9419 {
9420 char base_xpath[XPATH_MAXLEN];
9421 afi_t afi;
9422 safi_t safi;
9423 int idx = 0;
9424 struct prefix p;
9425
9426 if (!no) {
9427 if (!nexthop_su) {
9428 vty_out(vty, "%% Nexthop required\n");
9429 return CMD_WARNING_CONFIG_FAILED;
9430 }
9431 if (!sockunion2hostprefix(nexthop_su, &p))
9432 return CMD_WARNING_CONFIG_FAILED;
9433 }
9434
9435 afi = bgp_node_afi(vty);
9436 safi = bgp_node_safi(vty);
9437
9438 snprintf(
9439 base_xpath, sizeof(base_xpath),
9440 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config",
9441 yang_afi_safi_value2identity(afi, safi),
9442 bgp_afi_safi_get_container_str(afi, safi));
9443
9444 if (argv_find(argv, argc, "no", &idx))
9445 nb_cli_enqueue_change(vty, "./nexthop", NB_OP_DESTROY, NULL);
9446 else
9447 nb_cli_enqueue_change(vty, "./nexthop", NB_OP_MODIFY,
9448 nexthop_su_str);
9449
9450 return nb_cli_apply_changes(vty, base_xpath);
9451 }
9452
9453 void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_nexthop(
9454 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9455 {
9456 int indent = 2;
9457
9458 vty_out(vty, "%*snexthop vpn export %s\n", indent, "",
9459 yang_dnode_get_string(dnode, NULL));
9460 }
9461
9462 static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
9463 {
9464 if (!strcmp(dstr, "import")) {
9465 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9466 } else if (!strcmp(dstr, "export")) {
9467 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9468 } else if (!strcmp(dstr, "both")) {
9469 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9470 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9471 } else {
9472 vty_out(vty, "%% direction parse error\n");
9473 return CMD_WARNING_CONFIG_FAILED;
9474 }
9475 return CMD_SUCCESS;
9476 }
9477
9478 DEFPY (af_rt_vpn_imexport,
9479 af_rt_vpn_imexport_cmd,
9480 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
9481 NO_STR
9482 "Specify route target list\n"
9483 "Specify route target list\n"
9484 "Between current address-family and vpn\n"
9485 "For routes leaked from vpn to current address-family: match any\n"
9486 "For routes leaked from current address-family to vpn: set\n"
9487 "both import: match any and export: set\n"
9488 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
9489 {
9490 VTY_DECLVAR_CONTEXT(bgp, bgp);
9491 int ret;
9492 struct ecommunity *ecom = NULL;
9493 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
9494 vpn_policy_direction_t dir;
9495 afi_t afi;
9496 int idx = 0;
9497 bool yes = true;
9498
9499 if (argv_find(argv, argc, "no", &idx))
9500 yes = false;
9501
9502 afi = vpn_policy_getafi(vty, bgp, false);
9503 if (afi == AFI_MAX)
9504 return CMD_WARNING_CONFIG_FAILED;
9505
9506 ret = vpn_policy_getdirs(vty, direction_str, dodir);
9507 if (ret != CMD_SUCCESS)
9508 return ret;
9509
9510 if (yes) {
9511 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9512 vty_out(vty, "%% Missing RTLIST\n");
9513 return CMD_WARNING_CONFIG_FAILED;
9514 }
9515 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, false);
9516 if (ret != CMD_SUCCESS) {
9517 return ret;
9518 }
9519 }
9520
9521 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9522 if (!dodir[dir])
9523 continue;
9524
9525 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9526
9527 if (yes) {
9528 if (bgp->vpn_policy[afi].rtlist[dir])
9529 ecommunity_free(
9530 &bgp->vpn_policy[afi].rtlist[dir]);
9531 bgp->vpn_policy[afi].rtlist[dir] =
9532 ecommunity_dup(ecom);
9533 } else {
9534 if (bgp->vpn_policy[afi].rtlist[dir])
9535 ecommunity_free(
9536 &bgp->vpn_policy[afi].rtlist[dir]);
9537 bgp->vpn_policy[afi].rtlist[dir] = NULL;
9538 }
9539
9540 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9541 }
9542
9543 if (ecom)
9544 ecommunity_free(&ecom);
9545
9546 return CMD_SUCCESS;
9547 }
9548
9549 ALIAS (af_rt_vpn_imexport,
9550 af_no_rt_vpn_imexport_cmd,
9551 "no <rt|route-target> vpn <import|export|both>$direction_str",
9552 NO_STR
9553 "Specify route target list\n"
9554 "Specify route target list\n"
9555 "Between current address-family and vpn\n"
9556 "For routes leaked from vpn to current address-family\n"
9557 "For routes leaked from current address-family to vpn\n"
9558 "both import and export\n")
9559
9560 DEFPY_YANG (af_route_map_vpn_imexport,
9561 af_route_map_vpn_imexport_cmd,
9562 /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
9563 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
9564 NO_STR
9565 "Specify route map\n"
9566 "Between current address-family and vpn\n"
9567 "For routes leaked from vpn to current address-family\n"
9568 "For routes leaked from current address-family to vpn\n"
9569 "name of route-map\n")
9570 {
9571 char base_xpath[XPATH_MAXLEN];
9572 afi_t afi;
9573 safi_t safi;
9574 int idx = 0;
9575
9576 afi = bgp_node_afi(vty);
9577 safi = bgp_node_safi(vty);
9578
9579 snprintf(
9580 base_xpath, sizeof(base_xpath),
9581 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config",
9582 yang_afi_safi_value2identity(afi, safi),
9583 bgp_afi_safi_get_container_str(afi, safi));
9584
9585 if (argv_find(argv, argc, "no", &idx)) {
9586 if (!strcmp(direction_str, "import"))
9587 nb_cli_enqueue_change(vty, "./rmap-import",
9588 NB_OP_DESTROY, NULL);
9589 else if (!strcmp(direction_str, "export"))
9590 nb_cli_enqueue_change(vty, "./rmap-export",
9591 NB_OP_DESTROY, NULL);
9592 } else {
9593 if (!strcmp(direction_str, "import"))
9594 nb_cli_enqueue_change(vty, "./rmap-import",
9595 NB_OP_MODIFY, rmap_str);
9596 if (!strcmp(direction_str, "export"))
9597 nb_cli_enqueue_change(vty, "./rmap-export",
9598 NB_OP_MODIFY, rmap_str);
9599 }
9600 return nb_cli_apply_changes(vty, base_xpath);
9601 }
9602
9603 void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rmap_import(
9604 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9605 {
9606 int indent = 2;
9607
9608 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
9609 yang_dnode_get_string(dnode, NULL));
9610 }
9611
9612 void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rmap_export(
9613 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9614 {
9615 int indent = 2;
9616
9617 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
9618 yang_dnode_get_string(dnode, NULL));
9619 }
9620
9621 ALIAS (af_route_map_vpn_imexport,
9622 af_no_route_map_vpn_imexport_cmd,
9623 "no route-map vpn <import|export>$direction_str",
9624 NO_STR
9625 "Specify route map\n"
9626 "Between current address-family and vpn\n"
9627 "For routes leaked from vpn to current address-family\n"
9628 "For routes leaked from current address-family to vpn\n")
9629
9630 DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
9631 "import vrf route-map RMAP$rmap_str",
9632 "Import routes from another VRF\n"
9633 "Vrf routes being filtered\n"
9634 "Specify route map\n"
9635 "name of route-map\n")
9636 {
9637 VTY_DECLVAR_CONTEXT(bgp, bgp);
9638 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
9639 afi_t afi;
9640 struct bgp *bgp_default;
9641
9642 afi = vpn_policy_getafi(vty, bgp, true);
9643 if (afi == AFI_MAX)
9644 return CMD_WARNING_CONFIG_FAILED;
9645
9646 bgp_default = bgp_get_default();
9647 if (!bgp_default) {
9648 int32_t ret;
9649 as_t as = bgp->as;
9650
9651 /* Auto-create assuming the same AS */
9652 ret = bgp_get_vty(&bgp_default, &as, NULL,
9653 BGP_INSTANCE_TYPE_DEFAULT);
9654
9655 if (ret) {
9656 vty_out(vty,
9657 "VRF default is not configured as a bgp instance\n");
9658 return CMD_WARNING;
9659 }
9660 }
9661
9662 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9663
9664 if (bgp->vpn_policy[afi].rmap_name[dir])
9665 XFREE(MTYPE_ROUTE_MAP_NAME,
9666 bgp->vpn_policy[afi].rmap_name[dir]);
9667 bgp->vpn_policy[afi].rmap_name[dir] =
9668 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
9669 bgp->vpn_policy[afi].rmap[dir] =
9670 route_map_lookup_warn_noexist(vty, rmap_str);
9671 if (!bgp->vpn_policy[afi].rmap[dir])
9672 return CMD_SUCCESS;
9673
9674 SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9675 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9676
9677 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9678
9679 return CMD_SUCCESS;
9680 }
9681
9682 DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
9683 "no import vrf route-map [RMAP$rmap_str]",
9684 NO_STR
9685 "Import routes from another VRF\n"
9686 "Vrf routes being filtered\n"
9687 "Specify route map\n"
9688 "name of route-map\n")
9689 {
9690 VTY_DECLVAR_CONTEXT(bgp, bgp);
9691 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
9692 afi_t afi;
9693
9694 afi = vpn_policy_getafi(vty, bgp, true);
9695 if (afi == AFI_MAX)
9696 return CMD_WARNING_CONFIG_FAILED;
9697
9698 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9699
9700 if (bgp->vpn_policy[afi].rmap_name[dir])
9701 XFREE(MTYPE_ROUTE_MAP_NAME,
9702 bgp->vpn_policy[afi].rmap_name[dir]);
9703 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9704 bgp->vpn_policy[afi].rmap[dir] = NULL;
9705
9706 if (bgp->vpn_policy[afi].import_vrf->count == 0)
9707 UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9708 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9709
9710 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9711
9712 return CMD_SUCCESS;
9713 }
9714
9715 DEFPY_YANG(bgp_imexport_vrf,
9716 bgp_imexport_vrf_cmd,
9717 "[no] import vrf VIEWVRFNAME$import_name",
9718 NO_STR
9719 "Import routes from another VRF\n"
9720 "VRF to import from\n"
9721 "The name of the VRF\n")
9722 {
9723 char base_xpath[XPATH_MAXLEN];
9724 safi_t safi;
9725 afi_t afi;
9726 int32_t idx = 0;
9727
9728 if (import_name == NULL) {
9729 vty_out(vty, "%% Missing import name\n");
9730 return CMD_WARNING;
9731 }
9732
9733 if (strcmp(import_name, "route-map") == 0) {
9734 vty_out(vty, "%% Must include route-map name\n");
9735 return CMD_WARNING;
9736 }
9737
9738 afi = bgp_node_afi(vty);
9739 safi = bgp_node_safi(vty);
9740
9741 snprintf(
9742 base_xpath, sizeof(base_xpath),
9743 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config/import-vrf-list[vrf='%s']",
9744 yang_afi_safi_value2identity(afi, safi),
9745 bgp_afi_safi_get_container_str(afi, safi), import_name);
9746
9747 if (argv_find(argv, argc, "no", &idx))
9748 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
9749 else
9750 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
9751
9752 return nb_cli_apply_changes(vty, base_xpath);
9753 }
9754
9755 void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_import_vrfs(
9756 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9757 {
9758 vty_out(vty, " import vrf %s\n",
9759 yang_dnode_get_string(dnode, "./vrf"));
9760 }
9761
9762 /* This command is valid only in a bgp vrf instance or the default instance */
9763 DEFPY_YANG (bgp_imexport_vpn,
9764 bgp_imexport_vpn_cmd,
9765 "[no] <import|export>$direction_str vpn",
9766 NO_STR
9767 "Import routes to this address-family\n"
9768 "Export routes from this address-family\n"
9769 "to/from default instance VPN RIB\n")
9770 {
9771 char base_xpath[XPATH_MAXLEN];
9772 safi_t safi;
9773 afi_t afi;
9774 int32_t idx = 0;
9775
9776 afi = bgp_node_afi(vty);
9777 safi = bgp_node_safi(vty);
9778
9779 if (!strcmp(direction_str, "import")) {
9780 snprintf(
9781 base_xpath, sizeof(base_xpath),
9782 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config/import-vpn",
9783 yang_afi_safi_value2identity(afi, safi),
9784 bgp_afi_safi_get_container_str(afi, safi));
9785 } else if (!strcmp(direction_str, "export")) {
9786 snprintf(
9787 base_xpath, sizeof(base_xpath),
9788 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config/export-vpn",
9789 yang_afi_safi_value2identity(afi, safi),
9790 bgp_afi_safi_get_container_str(afi, safi));
9791 } else {
9792 vty_out(vty, "%% unknown direction %s\n", direction_str);
9793 return CMD_WARNING_CONFIG_FAILED;
9794 }
9795
9796 if (argv_find(argv, argc, "no", &idx))
9797 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
9798 else
9799 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, "true");
9800
9801 return nb_cli_apply_changes(vty, base_xpath);
9802 }
9803
9804 void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_import_vpn(
9805 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9806 {
9807 if (yang_dnode_get_bool(dnode, NULL))
9808 vty_out(vty, " import vpn\n");
9809 }
9810
9811 void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_export_vpn(
9812 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9813 {
9814 if (yang_dnode_get_bool(dnode, NULL))
9815 vty_out(vty, " export vpn\n");
9816 }
9817
9818 DEFPY (af_routetarget_import,
9819 af_routetarget_import_cmd,
9820 "[no] <rt|route-target|route-target6|rt6> redirect import RTLIST...",
9821 NO_STR
9822 "Specify route target list\n"
9823 "Specify route target list\n"
9824 "Specify route target list\n"
9825 "Specify route target list\n"
9826 "Flow-spec redirect type route target\n"
9827 "Import routes to this address-family\n"
9828 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN|IPV6:MN)\n")
9829 {
9830 VTY_DECLVAR_CONTEXT(bgp, bgp);
9831 int ret;
9832 struct ecommunity *ecom = NULL;
9833 afi_t afi;
9834 int idx = 0, idx_unused = 0;
9835 bool yes = true;
9836 bool rt6 = false;
9837
9838 if (argv_find(argv, argc, "no", &idx))
9839 yes = false;
9840
9841 if (argv_find(argv, argc, "rt6", &idx_unused) ||
9842 argv_find(argv, argc, "route-target6", &idx_unused))
9843 rt6 = true;
9844
9845 afi = vpn_policy_getafi(vty, bgp, false);
9846 if (afi == AFI_MAX)
9847 return CMD_WARNING_CONFIG_FAILED;
9848
9849 if (rt6 && afi != AFI_IP6)
9850 return CMD_WARNING_CONFIG_FAILED;
9851
9852 if (yes) {
9853 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9854 vty_out(vty, "%% Missing RTLIST\n");
9855 return CMD_WARNING_CONFIG_FAILED;
9856 }
9857 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, rt6);
9858 if (ret != CMD_SUCCESS)
9859 return ret;
9860 }
9861
9862 if (yes) {
9863 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9864 ecommunity_free(&bgp->vpn_policy[afi]
9865 .import_redirect_rtlist);
9866 bgp->vpn_policy[afi].import_redirect_rtlist =
9867 ecommunity_dup(ecom);
9868 } else {
9869 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9870 ecommunity_free(&bgp->vpn_policy[afi]
9871 .import_redirect_rtlist);
9872 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
9873 }
9874
9875 if (ecom)
9876 ecommunity_free(&ecom);
9877
9878 return CMD_SUCCESS;
9879 }
9880
9881 void cli_show_bgp_global_afi_safi_header(struct vty *vty,
9882 struct lyd_node *dnode,
9883 bool show_defaults)
9884 {
9885 const char *af_name;
9886 afi_t afi;
9887 safi_t safi;
9888
9889 af_name = yang_dnode_get_string(dnode, "./afi-safi-name");
9890 yang_afi_safi_identity2value(af_name, &afi, &safi);
9891
9892 vty_out(vty, " !\n address-family ");
9893 if (afi == AFI_IP) {
9894 if (safi == SAFI_UNICAST)
9895 vty_out(vty, "ipv4 unicast");
9896 else if (safi == SAFI_LABELED_UNICAST)
9897 vty_out(vty, "ipv4 labeled-unicast");
9898 else if (safi == SAFI_MULTICAST)
9899 vty_out(vty, "ipv4 multicast");
9900 else if (safi == SAFI_MPLS_VPN)
9901 vty_out(vty, "ipv4 vpn");
9902 else if (safi == SAFI_ENCAP)
9903 vty_out(vty, "ipv4 encap");
9904 else if (safi == SAFI_FLOWSPEC)
9905 vty_out(vty, "ipv4 flowspec");
9906 } else if (afi == AFI_IP6) {
9907 if (safi == SAFI_UNICAST)
9908 vty_out(vty, "ipv6 unicast");
9909 else if (safi == SAFI_LABELED_UNICAST)
9910 vty_out(vty, "ipv6 labeled-unicast");
9911 else if (safi == SAFI_MULTICAST)
9912 vty_out(vty, "ipv6 multicast");
9913 else if (safi == SAFI_MPLS_VPN)
9914 vty_out(vty, "ipv6 vpn");
9915 else if (safi == SAFI_ENCAP)
9916 vty_out(vty, "ipv6 encap");
9917 else if (safi == SAFI_FLOWSPEC)
9918 vty_out(vty, "ipv6 flowspec");
9919 } else if (afi == AFI_L2VPN) {
9920 if (safi == SAFI_EVPN)
9921 vty_out(vty, "l2vpn evpn");
9922 }
9923 vty_out(vty, "\n");
9924 }
9925
9926 DEFUN_NOSH (address_family_ipv4_safi,
9927 address_family_ipv4_safi_cmd,
9928 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9929 "Enter Address Family command mode\n"
9930 "Address Family\n"
9931 BGP_SAFI_WITH_LABEL_HELP_STR)
9932 {
9933
9934 safi_t safi = SAFI_UNICAST;
9935 const struct lyd_node *vrf_dnode, *bgp_glb_dnode;
9936 const char *vrf_name = NULL;
9937
9938 if (argc == 3) {
9939 safi = bgp_vty_safi_from_str(argv[2]->text);
9940
9941 bgp_glb_dnode = yang_dnode_get(vty->candidate_config->dnode,
9942 VTY_CURR_XPATH);
9943 vrf_dnode = yang_dnode_get_parent(bgp_glb_dnode,
9944 "control-plane-protocol");
9945 vrf_name = yang_dnode_get_string(vrf_dnode, "./vrf");
9946
9947 if (!strmatch(vrf_name, VRF_DEFAULT_NAME)
9948 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9949 && safi != SAFI_EVPN) {
9950 vty_out(vty,
9951 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9952 return CMD_WARNING_CONFIG_FAILED;
9953 }
9954 }
9955 vty->node = bgp_node_type(AFI_IP, safi);
9956
9957 return CMD_SUCCESS;
9958 }
9959
9960 DEFUN_NOSH (address_family_ipv6_safi,
9961 address_family_ipv6_safi_cmd,
9962 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9963 "Enter Address Family command mode\n"
9964 "Address Family\n"
9965 BGP_SAFI_WITH_LABEL_HELP_STR)
9966 {
9967 safi_t safi = SAFI_UNICAST;
9968 const struct lyd_node *vrf_dnode, *bgp_glb_dnode;
9969 const char *vrf_name = NULL;
9970
9971 if (argc == 3) {
9972 safi = bgp_vty_safi_from_str(argv[2]->text);
9973 bgp_glb_dnode = yang_dnode_get(vty->candidate_config->dnode,
9974 VTY_CURR_XPATH);
9975 vrf_dnode = yang_dnode_get_parent(bgp_glb_dnode,
9976 "control-plane-protocol");
9977 vrf_name = yang_dnode_get_string(vrf_dnode, "./vrf");
9978
9979 if (!strmatch(vrf_name, VRF_DEFAULT_NAME)
9980 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9981 && safi != SAFI_EVPN) {
9982 vty_out(vty,
9983 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9984 return CMD_WARNING_CONFIG_FAILED;
9985 }
9986 }
9987 vty->node = bgp_node_type(AFI_IP6, safi);
9988
9989 return CMD_SUCCESS;
9990 }
9991
9992 #ifdef KEEP_OLD_VPN_COMMANDS
9993 DEFUN_NOSH (address_family_vpnv4,
9994 address_family_vpnv4_cmd,
9995 "address-family vpnv4 [unicast]",
9996 "Enter Address Family command mode\n"
9997 "Address Family\n"
9998 "Address Family modifier\n")
9999 {
10000 vty->node = BGP_VPNV4_NODE;
10001 return CMD_SUCCESS;
10002 }
10003
10004 DEFUN_NOSH (address_family_vpnv6,
10005 address_family_vpnv6_cmd,
10006 "address-family vpnv6 [unicast]",
10007 "Enter Address Family command mode\n"
10008 "Address Family\n"
10009 "Address Family modifier\n")
10010 {
10011 vty->node = BGP_VPNV6_NODE;
10012 return CMD_SUCCESS;
10013 }
10014 #endif /* KEEP_OLD_VPN_COMMANDS */
10015
10016 DEFUN_NOSH (address_family_evpn,
10017 address_family_evpn_cmd,
10018 "address-family l2vpn evpn",
10019 "Enter Address Family command mode\n"
10020 "Address Family\n"
10021 "Address Family modifier\n")
10022 {
10023 VTY_DECLVAR_CONTEXT(bgp, bgp);
10024 vty->node = BGP_EVPN_NODE;
10025 return CMD_SUCCESS;
10026 }
10027
10028 DEFUN_NOSH (bgp_segment_routing_srv6,
10029 bgp_segment_routing_srv6_cmd,
10030 "segment-routing srv6",
10031 "Segment-Routing configuration\n"
10032 "Segment-Routing SRv6 configuration\n")
10033 {
10034 VTY_DECLVAR_CONTEXT(bgp, bgp);
10035 bgp->srv6_enabled = true;
10036 vty->node = BGP_SRV6_NODE;
10037 return CMD_SUCCESS;
10038 }
10039
10040 DEFPY (bgp_srv6_locator,
10041 bgp_srv6_locator_cmd,
10042 "locator NAME$name",
10043 "Specify SRv6 locator\n"
10044 "Specify SRv6 locator\n")
10045 {
10046 VTY_DECLVAR_CONTEXT(bgp, bgp);
10047 int ret;
10048
10049 if (strlen(bgp->srv6_locator_name) > 0
10050 && strcmp(name, bgp->srv6_locator_name) != 0) {
10051 vty_out(vty, "srv6 locator is already configured\n");
10052 return CMD_WARNING_CONFIG_FAILED;
10053 }
10054
10055 snprintf(bgp->srv6_locator_name,
10056 sizeof(bgp->srv6_locator_name), "%s", name);
10057
10058 ret = bgp_zebra_srv6_manager_get_locator_chunk(name);
10059 if (ret < 0)
10060 return CMD_WARNING_CONFIG_FAILED;
10061
10062 return CMD_SUCCESS;
10063 }
10064
10065 DEFPY (show_bgp_srv6,
10066 show_bgp_srv6_cmd,
10067 "show bgp segment-routing srv6",
10068 SHOW_STR
10069 BGP_STR
10070 "BGP Segment Routing\n"
10071 "BGP Segment Routing SRv6\n")
10072 {
10073 struct bgp *bgp;
10074 struct listnode *node;
10075 struct prefix_ipv6 *chunk;
10076 struct bgp_srv6_function *func;
10077 struct in6_addr *tovpn4_sid;
10078 struct in6_addr *tovpn6_sid;
10079 char buf[256];
10080 char buf_tovpn4_sid[256];
10081 char buf_tovpn6_sid[256];
10082
10083 bgp = bgp_get_default();
10084 if (!bgp)
10085 return CMD_SUCCESS;
10086
10087 vty_out(vty, "locator_name: %s\n", bgp->srv6_locator_name);
10088 vty_out(vty, "locator_chunks:\n");
10089 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_locator_chunks, node, chunk)) {
10090 prefix2str(chunk, buf, sizeof(buf));
10091 vty_out(vty, "- %s\n", buf);
10092 }
10093
10094 vty_out(vty, "functions:\n");
10095 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_functions, node, func)) {
10096 inet_ntop(AF_INET6, &func->sid, buf, sizeof(buf));
10097 vty_out(vty, "- sid: %s\n", buf);
10098 vty_out(vty, " locator: %s\n", func->locator_name);
10099 }
10100
10101 vty_out(vty, "bgps:\n");
10102 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp)) {
10103 vty_out(vty, "- name: %s\n",
10104 bgp->name ? bgp->name : "default");
10105
10106 tovpn4_sid = bgp->vpn_policy[AFI_IP].tovpn_sid;
10107 tovpn6_sid = bgp->vpn_policy[AFI_IP6].tovpn_sid;
10108 if (tovpn4_sid)
10109 inet_ntop(AF_INET6, tovpn4_sid, buf_tovpn4_sid,
10110 sizeof(buf_tovpn4_sid));
10111 if (tovpn6_sid)
10112 inet_ntop(AF_INET6, tovpn6_sid, buf_tovpn6_sid,
10113 sizeof(buf_tovpn6_sid));
10114
10115 vty_out(vty, " vpn_policy[AFI_IP].tovpn_sid: %s\n",
10116 tovpn4_sid ? buf_tovpn4_sid : "none");
10117 vty_out(vty, " vpn_policy[AFI_IP6].tovpn_sid: %s\n",
10118 tovpn6_sid ? buf_tovpn6_sid : "none");
10119 }
10120
10121 return CMD_SUCCESS;
10122 }
10123
10124 DEFUN_NOSH (exit_address_family,
10125 exit_address_family_cmd,
10126 "exit-address-family",
10127 "Exit from Address Family configuration mode\n")
10128 {
10129 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
10130 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
10131 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
10132 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
10133 || vty->node == BGP_EVPN_NODE
10134 || vty->node == BGP_FLOWSPECV4_NODE
10135 || vty->node == BGP_FLOWSPECV6_NODE)
10136 vty->node = BGP_NODE;
10137 return CMD_SUCCESS;
10138 }
10139
10140 void cli_show_bgp_global_afi_safi_header_end(struct vty *vty,
10141 struct lyd_node *dnode
10142 __attribute__((__unused__)))
10143 {
10144 vty_out(vty, " exit-address-family\n");
10145 }
10146
10147 /* Recalculate bestpath and re-advertise a prefix */
10148 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
10149 const char *ip_str, afi_t afi, safi_t safi,
10150 struct prefix_rd *prd)
10151 {
10152 int ret;
10153 struct prefix match;
10154 struct bgp_dest *dest;
10155 struct bgp_dest *rm;
10156 struct bgp *bgp;
10157 struct bgp_table *table;
10158 struct bgp_table *rib;
10159
10160 /* BGP structure lookup. */
10161 if (view_name) {
10162 bgp = bgp_lookup_by_name(view_name);
10163 if (bgp == NULL) {
10164 vty_out(vty, "%% Can't find BGP instance %s\n",
10165 view_name);
10166 return CMD_WARNING;
10167 }
10168 } else {
10169 bgp = bgp_get_default();
10170 if (bgp == NULL) {
10171 vty_out(vty, "%% No BGP process is configured\n");
10172 return CMD_WARNING;
10173 }
10174 }
10175
10176 /* Check IP address argument. */
10177 ret = str2prefix(ip_str, &match);
10178 if (!ret) {
10179 vty_out(vty, "%% address is malformed\n");
10180 return CMD_WARNING;
10181 }
10182
10183 match.family = afi2family(afi);
10184 rib = bgp->rib[afi][safi];
10185
10186 if (safi == SAFI_MPLS_VPN) {
10187 for (dest = bgp_table_top(rib); dest;
10188 dest = bgp_route_next(dest)) {
10189 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
10190
10191 if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
10192 continue;
10193
10194 table = bgp_dest_get_bgp_table_info(dest);
10195 if (table == NULL)
10196 continue;
10197
10198 rm = bgp_node_match(table, &match);
10199 if (rm != 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 dest = bgp_node_match(rib, &match);
10213 if (dest != NULL) {
10214 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
10215
10216 if (dest_p->prefixlen == match.prefixlen) {
10217 SET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
10218 bgp_process(bgp, dest, afi, safi);
10219 }
10220 bgp_dest_unlock_node(dest);
10221 }
10222 }
10223
10224 return CMD_SUCCESS;
10225 }
10226
10227 /* one clear bgp command to rule them all */
10228 DEFUN (clear_ip_bgp_all,
10229 clear_ip_bgp_all_cmd,
10230 "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>]",
10231 CLEAR_STR
10232 IP_STR
10233 BGP_STR
10234 BGP_INSTANCE_HELP_STR
10235 BGP_AFI_HELP_STR
10236 "Address Family\n"
10237 BGP_SAFI_WITH_LABEL_HELP_STR
10238 "Address Family modifier\n"
10239 "Clear all peers\n"
10240 "BGP IPv4 neighbor to clear\n"
10241 "BGP IPv6 neighbor to clear\n"
10242 "BGP neighbor on interface to clear\n"
10243 "Clear peers with the AS number\n"
10244 "Clear all external peers\n"
10245 "Clear all members of peer-group\n"
10246 "BGP peer-group name\n"
10247 BGP_SOFT_STR
10248 BGP_SOFT_IN_STR
10249 BGP_SOFT_OUT_STR
10250 BGP_SOFT_IN_STR
10251 "Push out prefix-list ORF and do inbound soft reconfig\n"
10252 BGP_SOFT_OUT_STR)
10253 {
10254 char *vrf = NULL;
10255
10256 afi_t afi = AFI_UNSPEC;
10257 safi_t safi = SAFI_UNSPEC;
10258 enum clear_sort clr_sort = clear_peer;
10259 enum bgp_clear_type clr_type;
10260 char *clr_arg = NULL;
10261
10262 int idx = 0;
10263 char errmsg[BUFSIZ] = {'\0'};
10264 int ret;
10265
10266 /* clear [ip] bgp */
10267 if (argv_find(argv, argc, "ip", &idx))
10268 afi = AFI_IP;
10269
10270 /* [<vrf> VIEWVRFNAME] */
10271 if (argv_find(argv, argc, "vrf", &idx)) {
10272 vrf = argv[idx + 1]->arg;
10273 idx += 2;
10274 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
10275 vrf = NULL;
10276 } else if (argv_find(argv, argc, "view", &idx)) {
10277 /* [<view> VIEWVRFNAME] */
10278 vrf = argv[idx + 1]->arg;
10279 idx += 2;
10280 }
10281 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
10282 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
10283 argv_find_and_parse_safi(argv, argc, &idx, &safi);
10284
10285 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
10286 if (argv_find(argv, argc, "*", &idx)) {
10287 clr_sort = clear_all;
10288 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
10289 clr_sort = clear_peer;
10290 clr_arg = argv[idx]->arg;
10291 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
10292 clr_sort = clear_peer;
10293 clr_arg = argv[idx]->arg;
10294 } else if (argv_find(argv, argc, "peer-group", &idx)) {
10295 clr_sort = clear_group;
10296 idx++;
10297 clr_arg = argv[idx]->arg;
10298 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
10299 clr_sort = clear_peer;
10300 clr_arg = argv[idx]->arg;
10301 } else if (argv_find(argv, argc, "WORD", &idx)) {
10302 clr_sort = clear_peer;
10303 clr_arg = argv[idx]->arg;
10304 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
10305 clr_sort = clear_as;
10306 clr_arg = argv[idx]->arg;
10307 } else if (argv_find(argv, argc, "external", &idx)) {
10308 clr_sort = clear_external;
10309 }
10310
10311 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
10312 if (argv_find(argv, argc, "soft", &idx)) {
10313 if (argv_find(argv, argc, "in", &idx)
10314 || argv_find(argv, argc, "out", &idx))
10315 clr_type = strmatch(argv[idx]->text, "in")
10316 ? BGP_CLEAR_SOFT_IN
10317 : BGP_CLEAR_SOFT_OUT;
10318 else
10319 clr_type = BGP_CLEAR_SOFT_BOTH;
10320 } else if (argv_find(argv, argc, "in", &idx)) {
10321 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
10322 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
10323 : BGP_CLEAR_SOFT_IN;
10324 } else if (argv_find(argv, argc, "out", &idx)) {
10325 clr_type = BGP_CLEAR_SOFT_OUT;
10326 } else
10327 clr_type = BGP_CLEAR_SOFT_NONE;
10328
10329 ret = bgp_clear_vty(vrf, afi, safi, clr_sort, clr_type, clr_arg, errmsg,
10330 sizeof(errmsg));
10331 if (ret != NB_OK)
10332 vty_out(vty, "Error description: %s\n", errmsg);
10333
10334 return ret;
10335 }
10336
10337 DEFUN (clear_ip_bgp_prefix,
10338 clear_ip_bgp_prefix_cmd,
10339 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
10340 CLEAR_STR
10341 IP_STR
10342 BGP_STR
10343 BGP_INSTANCE_HELP_STR
10344 "Clear bestpath and re-advertise\n"
10345 "IPv4 prefix\n")
10346 {
10347 char *vrf = NULL;
10348 char *prefix = NULL;
10349
10350 int idx = 0;
10351
10352 /* [<view|vrf> VIEWVRFNAME] */
10353 if (argv_find(argv, argc, "vrf", &idx)) {
10354 vrf = argv[idx + 1]->arg;
10355 idx += 2;
10356 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
10357 vrf = NULL;
10358 } else if (argv_find(argv, argc, "view", &idx)) {
10359 /* [<view> VIEWVRFNAME] */
10360 vrf = argv[idx + 1]->arg;
10361 idx += 2;
10362 }
10363
10364 prefix = argv[argc - 1]->arg;
10365
10366 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
10367 }
10368
10369 DEFUN (clear_bgp_ipv6_safi_prefix,
10370 clear_bgp_ipv6_safi_prefix_cmd,
10371 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
10372 CLEAR_STR
10373 IP_STR
10374 BGP_STR
10375 "Address Family\n"
10376 BGP_SAFI_HELP_STR
10377 "Clear bestpath and re-advertise\n"
10378 "IPv6 prefix\n")
10379 {
10380 int idx_safi = 0;
10381 int idx_ipv6_prefix = 0;
10382 safi_t safi = SAFI_UNICAST;
10383 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
10384 argv[idx_ipv6_prefix]->arg : NULL;
10385
10386 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
10387 return bgp_clear_prefix(
10388 vty, NULL, prefix, AFI_IP6,
10389 safi, NULL);
10390 }
10391
10392 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
10393 clear_bgp_instance_ipv6_safi_prefix_cmd,
10394 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
10395 CLEAR_STR
10396 IP_STR
10397 BGP_STR
10398 BGP_INSTANCE_HELP_STR
10399 "Address Family\n"
10400 BGP_SAFI_HELP_STR
10401 "Clear bestpath and re-advertise\n"
10402 "IPv6 prefix\n")
10403 {
10404 int idx_safi = 0;
10405 int idx_vrfview = 0;
10406 int idx_ipv6_prefix = 0;
10407 safi_t safi = SAFI_UNICAST;
10408 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
10409 argv[idx_ipv6_prefix]->arg : NULL;
10410 char *vrfview = NULL;
10411
10412 /* [<view|vrf> VIEWVRFNAME] */
10413 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
10414 vrfview = argv[idx_vrfview + 1]->arg;
10415 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
10416 vrfview = NULL;
10417 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
10418 /* [<view> VIEWVRFNAME] */
10419 vrfview = argv[idx_vrfview + 1]->arg;
10420 }
10421 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
10422
10423 return bgp_clear_prefix(
10424 vty, vrfview, prefix,
10425 AFI_IP6, safi, NULL);
10426 }
10427
10428 DEFUN (show_bgp_views,
10429 show_bgp_views_cmd,
10430 "show [ip] bgp views",
10431 SHOW_STR
10432 IP_STR
10433 BGP_STR
10434 "Show the defined BGP views\n")
10435 {
10436 struct list *inst = bm->bgp;
10437 struct listnode *node;
10438 struct bgp *bgp;
10439
10440 vty_out(vty, "Defined BGP views:\n");
10441 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10442 /* Skip VRFs. */
10443 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
10444 continue;
10445 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
10446 bgp->as);
10447 }
10448
10449 return CMD_SUCCESS;
10450 }
10451
10452 DEFUN (show_bgp_vrfs,
10453 show_bgp_vrfs_cmd,
10454 "show [ip] bgp vrfs [json]",
10455 SHOW_STR
10456 IP_STR
10457 BGP_STR
10458 "Show BGP VRFs\n"
10459 JSON_STR)
10460 {
10461 char buf[ETHER_ADDR_STRLEN];
10462 struct list *inst = bm->bgp;
10463 struct listnode *node;
10464 struct bgp *bgp;
10465 bool uj = use_json(argc, argv);
10466 json_object *json = NULL;
10467 json_object *json_vrfs = NULL;
10468 int count = 0;
10469
10470 if (uj) {
10471 json = json_object_new_object();
10472 json_vrfs = json_object_new_object();
10473 }
10474
10475 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10476 const char *name, *type;
10477 struct peer *peer;
10478 struct listnode *node2, *nnode2;
10479 int peers_cfg, peers_estb;
10480 json_object *json_vrf = NULL;
10481
10482 /* Skip Views. */
10483 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
10484 continue;
10485
10486 count++;
10487 if (!uj && count == 1) {
10488 vty_out(vty,
10489 "%4s %-5s %-16s %9s %10s %-37s\n",
10490 "Type", "Id", "routerId", "#PeersCfg",
10491 "#PeersEstb", "Name");
10492 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
10493 "L3-VNI", "RouterMAC", "Interface");
10494 }
10495
10496 peers_cfg = peers_estb = 0;
10497 if (uj)
10498 json_vrf = json_object_new_object();
10499
10500
10501 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
10502 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10503 continue;
10504 peers_cfg++;
10505 if (peer_established(peer))
10506 peers_estb++;
10507 }
10508
10509 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
10510 name = VRF_DEFAULT_NAME;
10511 type = "DFLT";
10512 } else {
10513 name = bgp->name;
10514 type = "VRF";
10515 }
10516
10517
10518 if (uj) {
10519 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10520 ? -1
10521 : (int64_t)bgp->vrf_id;
10522 char buf[BUFSIZ] = {0};
10523
10524 json_object_string_add(json_vrf, "type", type);
10525 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
10526 json_object_string_add(json_vrf, "routerId",
10527 inet_ntop(AF_INET,
10528 &bgp->router_id, buf,
10529 sizeof(buf)));
10530 json_object_int_add(json_vrf, "numConfiguredPeers",
10531 peers_cfg);
10532 json_object_int_add(json_vrf, "numEstablishedPeers",
10533 peers_estb);
10534
10535 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
10536 json_object_string_add(
10537 json_vrf, "rmac",
10538 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
10539 json_object_string_add(json_vrf, "interface",
10540 ifindex2ifname(bgp->l3vni_svi_ifindex,
10541 bgp->vrf_id));
10542 json_object_object_add(json_vrfs, name, json_vrf);
10543 } else {
10544 vty_out(vty, "%4s %-5d %-16pI4 %-9u %-10u %-37s\n",
10545 type,
10546 bgp->vrf_id == VRF_UNKNOWN ? -1
10547 : (int)bgp->vrf_id,
10548 &bgp->router_id, peers_cfg, peers_estb, name);
10549 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
10550 bgp->l3vni,
10551 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
10552 ifindex2ifname(bgp->l3vni_svi_ifindex,
10553 bgp->vrf_id));
10554 }
10555 }
10556
10557 if (uj) {
10558 json_object_object_add(json, "vrfs", json_vrfs);
10559
10560 json_object_int_add(json, "totalVrfs", count);
10561
10562 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10563 json, JSON_C_TO_STRING_PRETTY));
10564 json_object_free(json);
10565 } else {
10566 if (count)
10567 vty_out(vty,
10568 "\nTotal number of VRFs (including default): %d\n",
10569 count);
10570 }
10571
10572 return CMD_SUCCESS;
10573 }
10574
10575 DEFUN (show_bgp_mac_hash,
10576 show_bgp_mac_hash_cmd,
10577 "show bgp mac hash",
10578 SHOW_STR
10579 BGP_STR
10580 "Mac Address\n"
10581 "Mac Address database\n")
10582 {
10583 bgp_mac_dump_table(vty);
10584
10585 return CMD_SUCCESS;
10586 }
10587
10588 static void show_tip_entry(struct hash_bucket *bucket, void *args)
10589 {
10590 struct vty *vty = (struct vty *)args;
10591 struct tip_addr *tip = (struct tip_addr *)bucket->data;
10592
10593 vty_out(vty, "addr: %pI4, count: %d\n", &tip->addr, tip->refcnt);
10594 }
10595
10596 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
10597 {
10598 vty_out(vty, "self nexthop database:\n");
10599 bgp_nexthop_show_address_hash(vty, bgp);
10600
10601 vty_out(vty, "Tunnel-ip database:\n");
10602 hash_iterate(bgp->tip_hash,
10603 (void (*)(struct hash_bucket *, void *))show_tip_entry,
10604 vty);
10605 }
10606
10607 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
10608 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
10609 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
10610 "martian next-hops\n"
10611 "martian next-hop database\n")
10612 {
10613 struct bgp *bgp = NULL;
10614 int idx = 0;
10615 char *name = NULL;
10616
10617 /* [<vrf> VIEWVRFNAME] */
10618 if (argv_find(argv, argc, "vrf", &idx)) {
10619 name = argv[idx + 1]->arg;
10620 if (name && strmatch(name, VRF_DEFAULT_NAME))
10621 name = NULL;
10622 } else if (argv_find(argv, argc, "view", &idx))
10623 /* [<view> VIEWVRFNAME] */
10624 name = argv[idx + 1]->arg;
10625 if (name)
10626 bgp = bgp_lookup_by_name(name);
10627 else
10628 bgp = bgp_get_default();
10629
10630 if (!bgp) {
10631 vty_out(vty, "%% No BGP process is configured\n");
10632 return CMD_WARNING;
10633 }
10634 bgp_show_martian_nexthops(vty, bgp);
10635
10636 return CMD_SUCCESS;
10637 }
10638
10639 DEFUN (show_bgp_memory,
10640 show_bgp_memory_cmd,
10641 "show [ip] bgp memory",
10642 SHOW_STR
10643 IP_STR
10644 BGP_STR
10645 "Global BGP memory statistics\n")
10646 {
10647 char memstrbuf[MTYPE_MEMSTR_LEN];
10648 unsigned long count;
10649
10650 /* RIB related usage stats */
10651 count = mtype_stats_alloc(MTYPE_BGP_NODE);
10652 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
10653 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10654 count * sizeof(struct bgp_dest)));
10655
10656 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
10657 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
10658 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10659 count * sizeof(struct bgp_path_info)));
10660 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
10661 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
10662 count,
10663 mtype_memstr(
10664 memstrbuf, sizeof(memstrbuf),
10665 count * sizeof(struct bgp_path_info_extra)));
10666
10667 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
10668 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
10669 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10670 count * sizeof(struct bgp_static)));
10671
10672 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
10673 vty_out(vty, "%ld Packets, using %s of memory\n", count,
10674 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10675 count * sizeof(struct bpacket)));
10676
10677 /* Adj-In/Out */
10678 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
10679 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
10680 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10681 count * sizeof(struct bgp_adj_in)));
10682 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
10683 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
10684 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10685 count * sizeof(struct bgp_adj_out)));
10686
10687 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
10688 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
10689 count,
10690 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10691 count * sizeof(struct bgp_nexthop_cache)));
10692
10693 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
10694 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
10695 count,
10696 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10697 count * sizeof(struct bgp_damp_info)));
10698
10699 /* Attributes */
10700 count = attr_count();
10701 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
10702 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10703 count * sizeof(struct attr)));
10704
10705 if ((count = attr_unknown_count()))
10706 vty_out(vty, "%ld unknown attributes\n", count);
10707
10708 /* AS_PATH attributes */
10709 count = aspath_count();
10710 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
10711 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10712 count * sizeof(struct aspath)));
10713
10714 count = mtype_stats_alloc(MTYPE_AS_SEG);
10715 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
10716 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10717 count * sizeof(struct assegment)));
10718
10719 /* Other attributes */
10720 if ((count = community_count()))
10721 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
10722 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10723 count * sizeof(struct community)));
10724 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
10725 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
10726 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10727 count * sizeof(struct ecommunity)));
10728 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
10729 vty_out(vty,
10730 "%ld BGP large-community entries, using %s of memory\n",
10731 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10732 count * sizeof(struct lcommunity)));
10733
10734 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
10735 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
10736 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10737 count * sizeof(struct cluster_list)));
10738
10739 /* Peer related usage */
10740 count = mtype_stats_alloc(MTYPE_BGP_PEER);
10741 vty_out(vty, "%ld peers, using %s of memory\n", count,
10742 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10743 count * sizeof(struct peer)));
10744
10745 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
10746 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
10747 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10748 count * sizeof(struct peer_group)));
10749
10750 /* Other */
10751 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
10752 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
10753 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10754 count * sizeof(regex_t)));
10755 return CMD_SUCCESS;
10756 }
10757
10758 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
10759 {
10760 json_object *bestpath = json_object_new_object();
10761
10762 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
10763 json_object_string_add(bestpath, "asPath", "ignore");
10764
10765 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
10766 json_object_string_add(bestpath, "asPath", "confed");
10767
10768 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
10769 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
10770 json_object_string_add(bestpath, "multiPathRelax",
10771 "as-set");
10772 else
10773 json_object_string_add(bestpath, "multiPathRelax",
10774 "true");
10775 } else
10776 json_object_string_add(bestpath, "multiPathRelax", "false");
10777
10778 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
10779 json_object_boolean_true_add(bestpath, "peerTypeRelax");
10780
10781 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
10782 json_object_string_add(bestpath, "compareRouterId", "true");
10783 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
10784 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
10785 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
10786 json_object_string_add(bestpath, "med", "confed");
10787 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
10788 json_object_string_add(bestpath, "med",
10789 "missing-as-worst");
10790 else
10791 json_object_string_add(bestpath, "med", "true");
10792 }
10793
10794 json_object_object_add(json, "bestPath", bestpath);
10795 }
10796
10797 /* Print the error code/subcode for why the peer is down */
10798 static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
10799 json_object *json_peer, bool use_json)
10800 {
10801 const char *code_str;
10802 const char *subcode_str;
10803
10804 if (use_json) {
10805 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10806 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10807 char errorcodesubcode_hexstr[5];
10808 char errorcodesubcode_str[256];
10809
10810 code_str = bgp_notify_code_str(peer->notify.code);
10811 subcode_str = bgp_notify_subcode_str(
10812 peer->notify.code,
10813 peer->notify.subcode);
10814
10815 snprintf(errorcodesubcode_hexstr,
10816 sizeof(errorcodesubcode_hexstr), "%02X%02X",
10817 peer->notify.code, peer->notify.subcode);
10818 json_object_string_add(json_peer,
10819 "lastErrorCodeSubcode",
10820 errorcodesubcode_hexstr);
10821 snprintf(errorcodesubcode_str, 255, "%s%s",
10822 code_str, subcode_str);
10823 json_object_string_add(json_peer,
10824 "lastNotificationReason",
10825 errorcodesubcode_str);
10826 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10827 && peer->notify.code == BGP_NOTIFY_CEASE
10828 && (peer->notify.subcode
10829 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10830 || peer->notify.subcode
10831 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10832 && peer->notify.length) {
10833 char msgbuf[1024];
10834 const char *msg_str;
10835
10836 msg_str = bgp_notify_admin_message(
10837 msgbuf, sizeof(msgbuf),
10838 (uint8_t *)peer->notify.data,
10839 peer->notify.length);
10840 if (msg_str)
10841 json_object_string_add(
10842 json_peer,
10843 "lastShutdownDescription",
10844 msg_str);
10845 }
10846
10847 }
10848 json_object_string_add(json_peer, "lastResetDueTo",
10849 peer_down_str[(int)peer->last_reset]);
10850 json_object_int_add(json_peer, "lastResetCode",
10851 peer->last_reset);
10852 } else {
10853 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10854 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10855 code_str = bgp_notify_code_str(peer->notify.code);
10856 subcode_str =
10857 bgp_notify_subcode_str(peer->notify.code,
10858 peer->notify.subcode);
10859 vty_out(vty, " Notification %s (%s%s)\n",
10860 peer->last_reset == PEER_DOWN_NOTIFY_SEND
10861 ? "sent"
10862 : "received",
10863 code_str, subcode_str);
10864 } else {
10865 vty_out(vty, " %s\n",
10866 peer_down_str[(int)peer->last_reset]);
10867 }
10868 }
10869 }
10870
10871 static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
10872 safi_t safi)
10873 {
10874 return ((!peer_established(peer)) || !peer->afc_recv[afi][safi]);
10875 }
10876
10877 static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
10878 struct peer *peer, json_object *json_peer,
10879 int max_neighbor_width, bool use_json)
10880 {
10881 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10882 int len;
10883
10884 if (use_json) {
10885 if (peer_dynamic_neighbor(peer))
10886 json_object_boolean_true_add(json_peer,
10887 "dynamicPeer");
10888 if (peer->hostname)
10889 json_object_string_add(json_peer, "hostname",
10890 peer->hostname);
10891
10892 if (peer->domainname)
10893 json_object_string_add(json_peer, "domainname",
10894 peer->domainname);
10895 json_object_int_add(json_peer, "connectionsEstablished",
10896 peer->established);
10897 json_object_int_add(json_peer, "connectionsDropped",
10898 peer->dropped);
10899 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10900 use_json, json_peer);
10901 if (peer_established(peer))
10902 json_object_string_add(json_peer, "lastResetDueTo",
10903 "AFI/SAFI Not Negotiated");
10904 else
10905 bgp_show_peer_reset(NULL, peer, json_peer, true);
10906 } else {
10907 dn_flag[1] = '\0';
10908 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
10909 if (peer->hostname
10910 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
10911 len = vty_out(vty, "%s%s(%s)", dn_flag,
10912 peer->hostname, peer->host);
10913 else
10914 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10915
10916 /* pad the neighbor column with spaces */
10917 if (len < max_neighbor_width)
10918 vty_out(vty, "%*s", max_neighbor_width - len,
10919 " ");
10920 vty_out(vty, "%7d %7d %9s", peer->established,
10921 peer->dropped,
10922 peer_uptime(peer->uptime, timebuf,
10923 BGP_UPTIME_LEN, 0, NULL));
10924 if (peer_established(peer))
10925 vty_out(vty, " AFI/SAFI Not Negotiated\n");
10926 else
10927 bgp_show_peer_reset(vty, peer, NULL,
10928 false);
10929 }
10930 }
10931
10932 /* If the peer's description includes whitespaces
10933 * then return the first occurrence. Also strip description
10934 * to the given size if needed.
10935 */
10936 static char *bgp_peer_description_stripped(char *desc, uint32_t size)
10937 {
10938 static char stripped[BUFSIZ];
10939 char *pnt;
10940 uint32_t len = size > strlen(desc) ? strlen(desc) : size;
10941
10942 pnt = strchr(desc, ' ');
10943 if (pnt)
10944 len = size > (uint32_t)(pnt - desc) ? (uint32_t)(pnt - desc)
10945 : size;
10946
10947 strlcpy(stripped, desc, len + 1);
10948
10949 return stripped;
10950 }
10951
10952 /* Determine whether var peer should be filtered out of the summary. */
10953 static bool bgp_show_summary_is_peer_filtered(struct peer *peer,
10954 struct peer *fpeer, int as_type,
10955 as_t as)
10956 {
10957
10958 /* filter neighbor XXXX */
10959 if (fpeer && fpeer != peer)
10960 return true;
10961
10962 /* filter remote-as (internal|external) */
10963 if (as_type != AS_UNSPECIFIED) {
10964 if (peer->as_type == AS_SPECIFIED) {
10965 if (as_type == AS_INTERNAL) {
10966 if (peer->as != peer->local_as)
10967 return true;
10968 } else if (peer->as == peer->local_as)
10969 return true;
10970 } else if (as_type != peer->as_type)
10971 return true;
10972 } else if (as && as != peer->as) /* filter remote-as XXX */
10973 return true;
10974
10975 return false;
10976 }
10977
10978 /* Show BGP peer's summary information. */
10979 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
10980 struct peer *fpeer, int as_type, as_t as,
10981 uint16_t show_flags)
10982 {
10983 struct peer *peer;
10984 struct listnode *node, *nnode;
10985 unsigned int count = 0, dn_count = 0;
10986 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10987 char neighbor_buf[VTY_BUFSIZ];
10988 int neighbor_col_default_width = 16;
10989 int len, failed_count = 0;
10990 unsigned int filtered_count = 0;
10991 int max_neighbor_width = 0;
10992 int pfx_rcd_safi;
10993 json_object *json = NULL;
10994 json_object *json_peer = NULL;
10995 json_object *json_peers = NULL;
10996 struct peer_af *paf;
10997 struct bgp_filter *filter;
10998 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
10999 bool show_failed = CHECK_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
11000 bool show_established =
11001 CHECK_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
11002 bool show_wide = CHECK_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
11003 bool show_terse = CHECK_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
11004
11005 /* labeled-unicast routes are installed in the unicast table so in order
11006 * to
11007 * display the correct PfxRcd value we must look at SAFI_UNICAST
11008 */
11009
11010 if (safi == SAFI_LABELED_UNICAST)
11011 pfx_rcd_safi = SAFI_UNICAST;
11012 else
11013 pfx_rcd_safi = safi;
11014
11015 if (use_json) {
11016 json = json_object_new_object();
11017 json_peers = json_object_new_object();
11018 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
11019 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
11020 as_type, as)) {
11021 filtered_count++;
11022 count++;
11023 continue;
11024 }
11025
11026 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
11027 continue;
11028
11029 if (peer->afc[afi][safi]) {
11030 /* See if we have at least a single failed peer */
11031 if (bgp_has_peer_failed(peer, afi, safi))
11032 failed_count++;
11033 count++;
11034 }
11035 if (peer_dynamic_neighbor(peer))
11036 dn_count++;
11037 }
11038
11039 } else {
11040 /* Loop over all neighbors that will be displayed to determine
11041 * how many
11042 * characters are needed for the Neighbor column
11043 */
11044 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
11045 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
11046 as_type, as)) {
11047 filtered_count++;
11048 count++;
11049 continue;
11050 }
11051
11052 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
11053 continue;
11054
11055 if (peer->afc[afi][safi]) {
11056 memset(dn_flag, '\0', sizeof(dn_flag));
11057 if (peer_dynamic_neighbor(peer))
11058 dn_flag[0] = '*';
11059
11060 if (peer->hostname
11061 && CHECK_FLAG(bgp->flags,
11062 BGP_FLAG_SHOW_HOSTNAME))
11063 snprintf(neighbor_buf,
11064 sizeof(neighbor_buf),
11065 "%s%s(%s) ", dn_flag,
11066 peer->hostname, peer->host);
11067 else
11068 snprintf(neighbor_buf,
11069 sizeof(neighbor_buf), "%s%s ",
11070 dn_flag, peer->host);
11071
11072 len = strlen(neighbor_buf);
11073
11074 if (len > max_neighbor_width)
11075 max_neighbor_width = len;
11076
11077 /* See if we have at least a single failed peer */
11078 if (bgp_has_peer_failed(peer, afi, safi))
11079 failed_count++;
11080 count++;
11081 }
11082 }
11083
11084 /* Originally we displayed the Neighbor column as 16
11085 * characters wide so make that the default
11086 */
11087 if (max_neighbor_width < neighbor_col_default_width)
11088 max_neighbor_width = neighbor_col_default_width;
11089 }
11090
11091 if (show_failed && !failed_count) {
11092 if (use_json) {
11093 json_object_int_add(json, "failedPeersCount", 0);
11094 json_object_int_add(json, "dynamicPeers", dn_count);
11095 json_object_int_add(json, "totalPeers", count);
11096
11097 vty_out(vty, "%s\n", json_object_to_json_string_ext(
11098 json, JSON_C_TO_STRING_PRETTY));
11099 json_object_free(json);
11100 } else {
11101 vty_out(vty, "%% No failed BGP neighbors found\n");
11102 }
11103 return CMD_SUCCESS;
11104 }
11105
11106 count = 0; /* Reset the value as its used again */
11107 filtered_count = 0;
11108 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
11109 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
11110 continue;
11111
11112 if (!peer->afc[afi][safi])
11113 continue;
11114
11115 if (!count) {
11116 unsigned long ents;
11117 char memstrbuf[MTYPE_MEMSTR_LEN];
11118 int64_t vrf_id_ui;
11119
11120 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
11121 ? -1
11122 : (int64_t)bgp->vrf_id;
11123
11124 /* Usage summary and header */
11125 if (use_json) {
11126 char buf[BUFSIZ] = {0};
11127
11128 json_object_string_add(
11129 json, "routerId",
11130 inet_ntop(AF_INET, &bgp->router_id, buf,
11131 sizeof(buf)));
11132 json_object_int_add(json, "as", bgp->as);
11133 json_object_int_add(json, "vrfId", vrf_id_ui);
11134 json_object_string_add(
11135 json, "vrfName",
11136 (bgp->inst_type
11137 == BGP_INSTANCE_TYPE_DEFAULT)
11138 ? VRF_DEFAULT_NAME
11139 : bgp->name);
11140 } else {
11141 vty_out(vty,
11142 "BGP router identifier %pI4, local AS number %u vrf-id %d",
11143 &bgp->router_id, bgp->as,
11144 bgp->vrf_id == VRF_UNKNOWN
11145 ? -1
11146 : (int)bgp->vrf_id);
11147 vty_out(vty, "\n");
11148 }
11149
11150 if (bgp_update_delay_configured(bgp)) {
11151 if (use_json) {
11152 json_object_int_add(
11153 json, "updateDelayLimit",
11154 bgp->v_update_delay);
11155
11156 if (bgp->v_update_delay
11157 != bgp->v_establish_wait)
11158 json_object_int_add(
11159 json,
11160 "updateDelayEstablishWait",
11161 bgp->v_establish_wait);
11162
11163 if (bgp_update_delay_active(bgp)) {
11164 json_object_string_add(
11165 json,
11166 "updateDelayFirstNeighbor",
11167 bgp->update_delay_begin_time);
11168 json_object_boolean_true_add(
11169 json,
11170 "updateDelayInProgress");
11171 } else {
11172 if (bgp->update_delay_over) {
11173 json_object_string_add(
11174 json,
11175 "updateDelayFirstNeighbor",
11176 bgp->update_delay_begin_time);
11177 json_object_string_add(
11178 json,
11179 "updateDelayBestpathResumed",
11180 bgp->update_delay_end_time);
11181 json_object_string_add(
11182 json,
11183 "updateDelayZebraUpdateResume",
11184 bgp->update_delay_zebra_resume_time);
11185 json_object_string_add(
11186 json,
11187 "updateDelayPeerUpdateResume",
11188 bgp->update_delay_peers_resume_time);
11189 }
11190 }
11191 } else {
11192 vty_out(vty,
11193 "Read-only mode update-delay limit: %d seconds\n",
11194 bgp->v_update_delay);
11195 if (bgp->v_update_delay
11196 != bgp->v_establish_wait)
11197 vty_out(vty,
11198 " Establish wait: %d seconds\n",
11199 bgp->v_establish_wait);
11200
11201 if (bgp_update_delay_active(bgp)) {
11202 vty_out(vty,
11203 " First neighbor established: %s\n",
11204 bgp->update_delay_begin_time);
11205 vty_out(vty,
11206 " Delay in progress\n");
11207 } else {
11208 if (bgp->update_delay_over) {
11209 vty_out(vty,
11210 " First neighbor established: %s\n",
11211 bgp->update_delay_begin_time);
11212 vty_out(vty,
11213 " Best-paths resumed: %s\n",
11214 bgp->update_delay_end_time);
11215 vty_out(vty,
11216 " zebra update resumed: %s\n",
11217 bgp->update_delay_zebra_resume_time);
11218 vty_out(vty,
11219 " peers update resumed: %s\n",
11220 bgp->update_delay_peers_resume_time);
11221 }
11222 }
11223 }
11224 }
11225
11226 if (use_json) {
11227 if (bgp_maxmed_onstartup_configured(bgp)
11228 && bgp->maxmed_active)
11229 json_object_boolean_true_add(
11230 json, "maxMedOnStartup");
11231 if (bgp->v_maxmed_admin)
11232 json_object_boolean_true_add(
11233 json, "maxMedAdministrative");
11234
11235 json_object_int_add(
11236 json, "tableVersion",
11237 bgp_table_version(bgp->rib[afi][safi]));
11238
11239 ents = bgp_table_count(bgp->rib[afi][safi]);
11240 json_object_int_add(json, "ribCount", ents);
11241 json_object_int_add(
11242 json, "ribMemory",
11243 ents * sizeof(struct bgp_dest));
11244
11245 ents = bgp->af_peer_count[afi][safi];
11246 json_object_int_add(json, "peerCount", ents);
11247 json_object_int_add(json, "peerMemory",
11248 ents * sizeof(struct peer));
11249
11250 if ((ents = listcount(bgp->group))) {
11251 json_object_int_add(
11252 json, "peerGroupCount", ents);
11253 json_object_int_add(
11254 json, "peerGroupMemory",
11255 ents * sizeof(struct
11256 peer_group));
11257 }
11258
11259 if (CHECK_FLAG(bgp->af_flags[afi][safi],
11260 BGP_CONFIG_DAMPENING))
11261 json_object_boolean_true_add(
11262 json, "dampeningEnabled");
11263 } else {
11264 if (!show_terse) {
11265 if (bgp_maxmed_onstartup_configured(bgp)
11266 && bgp->maxmed_active)
11267 vty_out(vty,
11268 "Max-med on-startup active\n");
11269 if (bgp->v_maxmed_admin)
11270 vty_out(vty,
11271 "Max-med administrative active\n");
11272
11273 vty_out(vty,
11274 "BGP table version %" PRIu64
11275 "\n",
11276 bgp_table_version(
11277 bgp->rib[afi][safi]));
11278
11279 ents = bgp_table_count(
11280 bgp->rib[afi][safi]);
11281 vty_out(vty,
11282 "RIB entries %ld, using %s of memory\n",
11283 ents,
11284 mtype_memstr(
11285 memstrbuf,
11286 sizeof(memstrbuf),
11287 ents
11288 * sizeof(
11289 struct
11290 bgp_dest)));
11291
11292 /* Peer related usage */
11293 ents = bgp->af_peer_count[afi][safi];
11294 vty_out(vty,
11295 "Peers %ld, using %s of memory\n",
11296 ents,
11297 mtype_memstr(
11298 memstrbuf,
11299 sizeof(memstrbuf),
11300 ents
11301 * sizeof(
11302 struct
11303 peer)));
11304
11305 if ((ents = listcount(bgp->group)))
11306 vty_out(vty,
11307 "Peer groups %ld, using %s of memory\n",
11308 ents,
11309 mtype_memstr(
11310 memstrbuf,
11311 sizeof(memstrbuf),
11312 ents
11313 * sizeof(
11314 struct
11315 peer_group)));
11316
11317 if (CHECK_FLAG(bgp->af_flags[afi][safi],
11318 BGP_CONFIG_DAMPENING))
11319 vty_out(vty,
11320 "Dampening enabled.\n");
11321 }
11322 if (show_failed) {
11323 vty_out(vty, "\n");
11324
11325 /* Subtract 8 here because 'Neighbor' is
11326 * 8 characters */
11327 vty_out(vty, "Neighbor");
11328 vty_out(vty, "%*s",
11329 max_neighbor_width - 8, " ");
11330 vty_out(vty,
11331 BGP_SHOW_SUMMARY_HEADER_FAILED);
11332 }
11333 }
11334 }
11335
11336 paf = peer_af_find(peer, afi, safi);
11337 filter = &peer->filter[afi][safi];
11338
11339 count++;
11340 /* Works for both failed & successful cases */
11341 if (peer_dynamic_neighbor(peer))
11342 dn_count++;
11343
11344 if (use_json) {
11345 json_peer = NULL;
11346 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
11347 as_type, as)) {
11348 filtered_count++;
11349 continue;
11350 }
11351 if (show_failed &&
11352 bgp_has_peer_failed(peer, afi, safi)) {
11353 json_peer = json_object_new_object();
11354 bgp_show_failed_summary(vty, bgp, peer,
11355 json_peer, 0, use_json);
11356 } else if (!show_failed) {
11357 if (show_established
11358 && bgp_has_peer_failed(peer, afi, safi)) {
11359 filtered_count++;
11360 continue;
11361 }
11362
11363 json_peer = json_object_new_object();
11364 if (peer_dynamic_neighbor(peer)) {
11365 json_object_boolean_true_add(json_peer,
11366 "dynamicPeer");
11367 }
11368
11369 if (peer->hostname)
11370 json_object_string_add(json_peer, "hostname",
11371 peer->hostname);
11372
11373 if (peer->domainname)
11374 json_object_string_add(json_peer, "domainname",
11375 peer->domainname);
11376
11377 json_object_int_add(json_peer, "remoteAs", peer->as);
11378 json_object_int_add(
11379 json_peer, "localAs",
11380 peer->change_local_as
11381 ? peer->change_local_as
11382 : peer->local_as);
11383 json_object_int_add(json_peer, "version", 4);
11384 json_object_int_add(json_peer, "msgRcvd",
11385 PEER_TOTAL_RX(peer));
11386 json_object_int_add(json_peer, "msgSent",
11387 PEER_TOTAL_TX(peer));
11388
11389 atomic_size_t outq_count, inq_count;
11390 outq_count = atomic_load_explicit(
11391 &peer->obuf->count,
11392 memory_order_relaxed);
11393 inq_count = atomic_load_explicit(
11394 &peer->ibuf->count,
11395 memory_order_relaxed);
11396
11397 json_object_int_add(json_peer, "tableVersion",
11398 peer->version[afi][safi]);
11399 json_object_int_add(json_peer, "outq",
11400 outq_count);
11401 json_object_int_add(json_peer, "inq",
11402 inq_count);
11403 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
11404 use_json, json_peer);
11405
11406 json_object_int_add(json_peer, "pfxRcd",
11407 peer->pcount[afi][pfx_rcd_safi]);
11408
11409 if (paf && PAF_SUBGRP(paf))
11410 json_object_int_add(
11411 json_peer, "pfxSnt",
11412 (PAF_SUBGRP(paf))->scount);
11413 else
11414 json_object_int_add(json_peer, "pfxSnt",
11415 0);
11416
11417 /* BGP FSM state */
11418 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
11419 || CHECK_FLAG(peer->bgp->flags,
11420 BGP_FLAG_SHUTDOWN))
11421 json_object_string_add(json_peer,
11422 "state",
11423 "Idle (Admin)");
11424 else if (peer->afc_recv[afi][safi])
11425 json_object_string_add(
11426 json_peer, "state",
11427 lookup_msg(bgp_status_msg,
11428 peer->status, NULL));
11429 else if (CHECK_FLAG(
11430 peer->sflags,
11431 PEER_STATUS_PREFIX_OVERFLOW))
11432 json_object_string_add(json_peer,
11433 "state",
11434 "Idle (PfxCt)");
11435 else
11436 json_object_string_add(
11437 json_peer, "state",
11438 lookup_msg(bgp_status_msg,
11439 peer->status, NULL));
11440
11441 /* BGP peer state */
11442 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
11443 || CHECK_FLAG(peer->bgp->flags,
11444 BGP_FLAG_SHUTDOWN))
11445 json_object_string_add(json_peer,
11446 "peerState",
11447 "Admin");
11448 else if (CHECK_FLAG(
11449 peer->sflags,
11450 PEER_STATUS_PREFIX_OVERFLOW))
11451 json_object_string_add(json_peer,
11452 "peerState",
11453 "PfxCt");
11454 else if (CHECK_FLAG(peer->flags,
11455 PEER_FLAG_PASSIVE))
11456 json_object_string_add(json_peer,
11457 "peerState",
11458 "Passive");
11459 else if (CHECK_FLAG(peer->sflags,
11460 PEER_STATUS_NSF_WAIT))
11461 json_object_string_add(json_peer,
11462 "peerState",
11463 "NSF passive");
11464 else if (CHECK_FLAG(
11465 peer->bgp->flags,
11466 BGP_FLAG_EBGP_REQUIRES_POLICY)
11467 && (!bgp_inbound_policy_exists(peer,
11468 filter)
11469 || !bgp_outbound_policy_exists(
11470 peer, filter)))
11471 json_object_string_add(json_peer,
11472 "peerState",
11473 "Policy");
11474 else
11475 json_object_string_add(
11476 json_peer, "peerState", "OK");
11477
11478 json_object_int_add(json_peer, "connectionsEstablished",
11479 peer->established);
11480 json_object_int_add(json_peer, "connectionsDropped",
11481 peer->dropped);
11482 if (peer->desc)
11483 json_object_string_add(
11484 json_peer, "desc", peer->desc);
11485 }
11486 /* Avoid creating empty peer dicts in JSON */
11487 if (json_peer == NULL)
11488 continue;
11489
11490 if (peer->conf_if)
11491 json_object_string_add(json_peer, "idType",
11492 "interface");
11493 else if (peer->su.sa.sa_family == AF_INET)
11494 json_object_string_add(json_peer, "idType",
11495 "ipv4");
11496 else if (peer->su.sa.sa_family == AF_INET6)
11497 json_object_string_add(json_peer, "idType",
11498 "ipv6");
11499 json_object_object_add(json_peers, peer->host,
11500 json_peer);
11501 } else {
11502 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
11503 as_type, as)) {
11504 filtered_count++;
11505 continue;
11506 }
11507 if (show_failed &&
11508 bgp_has_peer_failed(peer, afi, safi)) {
11509 bgp_show_failed_summary(vty, bgp, peer, NULL,
11510 max_neighbor_width,
11511 use_json);
11512 } else if (!show_failed) {
11513 if (show_established
11514 && bgp_has_peer_failed(peer, afi, safi)) {
11515 filtered_count++;
11516 continue;
11517 }
11518
11519 if ((count - filtered_count) == 1) {
11520 /* display headline before the first
11521 * neighbor line */
11522 vty_out(vty, "\n");
11523
11524 /* Subtract 8 here because 'Neighbor' is
11525 * 8 characters */
11526 vty_out(vty, "Neighbor");
11527 vty_out(vty, "%*s",
11528 max_neighbor_width - 8, " ");
11529 vty_out(vty,
11530 show_wide
11531 ? BGP_SHOW_SUMMARY_HEADER_ALL_WIDE
11532 : BGP_SHOW_SUMMARY_HEADER_ALL);
11533 }
11534
11535 memset(dn_flag, '\0', sizeof(dn_flag));
11536 if (peer_dynamic_neighbor(peer)) {
11537 dn_flag[0] = '*';
11538 }
11539
11540 if (peer->hostname
11541 && CHECK_FLAG(bgp->flags,
11542 BGP_FLAG_SHOW_HOSTNAME))
11543 len = vty_out(vty, "%s%s(%s)", dn_flag,
11544 peer->hostname,
11545 peer->host);
11546 else
11547 len = vty_out(vty, "%s%s", dn_flag, peer->host);
11548
11549 /* pad the neighbor column with spaces */
11550 if (len < max_neighbor_width)
11551 vty_out(vty, "%*s", max_neighbor_width - len,
11552 " ");
11553
11554 atomic_size_t outq_count, inq_count;
11555 outq_count = atomic_load_explicit(
11556 &peer->obuf->count,
11557 memory_order_relaxed);
11558 inq_count = atomic_load_explicit(
11559 &peer->ibuf->count,
11560 memory_order_relaxed);
11561
11562 if (show_wide)
11563 vty_out(vty,
11564 "4 %10u %10u %9u %9u %8" PRIu64
11565 " %4zu %4zu %8s",
11566 peer->as,
11567 peer->change_local_as
11568 ? peer->change_local_as
11569 : peer->local_as,
11570 PEER_TOTAL_RX(peer),
11571 PEER_TOTAL_TX(peer),
11572 peer->version[afi][safi],
11573 inq_count, outq_count,
11574 peer_uptime(peer->uptime,
11575 timebuf,
11576 BGP_UPTIME_LEN, 0,
11577 NULL));
11578 else
11579 vty_out(vty, "4 %10u %9u %9u %8" PRIu64
11580 " %4zu %4zu %8s",
11581 peer->as, PEER_TOTAL_RX(peer),
11582 PEER_TOTAL_TX(peer),
11583 peer->version[afi][safi],
11584 inq_count, outq_count,
11585 peer_uptime(peer->uptime,
11586 timebuf,
11587 BGP_UPTIME_LEN, 0,
11588 NULL));
11589
11590 if (peer_established(peer)) {
11591 if (peer->afc_recv[afi][safi]) {
11592 if (CHECK_FLAG(
11593 bgp->flags,
11594 BGP_FLAG_EBGP_REQUIRES_POLICY)
11595 && !bgp_inbound_policy_exists(
11596 peer, filter))
11597 vty_out(vty, " %12s",
11598 "(Policy)");
11599 else
11600 vty_out(vty,
11601 " %12u",
11602 peer->pcount
11603 [afi]
11604 [pfx_rcd_safi]);
11605 } else {
11606 vty_out(vty, " NoNeg");
11607 }
11608
11609 if (paf && PAF_SUBGRP(paf)) {
11610 if (CHECK_FLAG(
11611 bgp->flags,
11612 BGP_FLAG_EBGP_REQUIRES_POLICY)
11613 && !bgp_outbound_policy_exists(
11614 peer, filter))
11615 vty_out(vty, " %8s",
11616 "(Policy)");
11617 else
11618 vty_out(vty,
11619 " %8u",
11620 (PAF_SUBGRP(
11621 paf))
11622 ->scount);
11623 } else {
11624 vty_out(vty, " NoNeg");
11625 }
11626 } else {
11627 if (CHECK_FLAG(peer->flags,
11628 PEER_FLAG_SHUTDOWN)
11629 || CHECK_FLAG(peer->bgp->flags,
11630 BGP_FLAG_SHUTDOWN))
11631 vty_out(vty, " Idle (Admin)");
11632 else if (CHECK_FLAG(
11633 peer->sflags,
11634 PEER_STATUS_PREFIX_OVERFLOW))
11635 vty_out(vty, " Idle (PfxCt)");
11636 else
11637 vty_out(vty, " %12s",
11638 lookup_msg(bgp_status_msg,
11639 peer->status, NULL));
11640
11641 vty_out(vty, " %8u", 0);
11642 }
11643 if (peer->desc)
11644 vty_out(vty, " %s",
11645 bgp_peer_description_stripped(
11646 peer->desc,
11647 show_wide ? 64 : 20));
11648 else
11649 vty_out(vty, " N/A");
11650 vty_out(vty, "\n");
11651 }
11652
11653 }
11654 }
11655
11656 if (use_json) {
11657 json_object_object_add(json, "peers", json_peers);
11658 json_object_int_add(json, "failedPeers", failed_count);
11659 json_object_int_add(json, "displayedPeers",
11660 count - filtered_count);
11661 json_object_int_add(json, "totalPeers", count);
11662 json_object_int_add(json, "dynamicPeers", dn_count);
11663
11664 if (!show_failed)
11665 bgp_show_bestpath_json(bgp, json);
11666
11667 vty_out(vty, "%s\n", json_object_to_json_string_ext(
11668 json, JSON_C_TO_STRING_PRETTY));
11669 json_object_free(json);
11670 } else {
11671 if (count) {
11672 if (filtered_count == count)
11673 vty_out(vty, "\n%% No matching neighbor\n");
11674 else {
11675 if (show_failed)
11676 vty_out(vty, "\nDisplayed neighbors %d",
11677 failed_count);
11678 else if (as_type != AS_UNSPECIFIED || as
11679 || fpeer || show_established)
11680 vty_out(vty, "\nDisplayed neighbors %d",
11681 count - filtered_count);
11682
11683 vty_out(vty, "\nTotal number of neighbors %d\n",
11684 count);
11685 }
11686 } else {
11687 vty_out(vty, "No %s neighbor is configured\n",
11688 get_afi_safi_str(afi, safi, false));
11689 }
11690
11691 if (dn_count) {
11692 vty_out(vty, "* - dynamic neighbor\n");
11693 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
11694 dn_count, bgp->dynamic_neighbors_limit);
11695 }
11696 }
11697
11698 return CMD_SUCCESS;
11699 }
11700
11701 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
11702 int safi, struct peer *fpeer, int as_type,
11703 as_t as, uint16_t show_flags)
11704 {
11705 int is_first = 1;
11706 int afi_wildcard = (afi == AFI_MAX);
11707 int safi_wildcard = (safi == SAFI_MAX);
11708 int is_wildcard = (afi_wildcard || safi_wildcard);
11709 bool nbr_output = false;
11710 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11711
11712 if (use_json && is_wildcard)
11713 vty_out(vty, "{\n");
11714 if (afi_wildcard)
11715 afi = 1; /* AFI_IP */
11716 while (afi < AFI_MAX) {
11717 if (safi_wildcard)
11718 safi = 1; /* SAFI_UNICAST */
11719 while (safi < SAFI_MAX) {
11720 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
11721 nbr_output = true;
11722
11723 if (is_wildcard) {
11724 /*
11725 * So limit output to those afi/safi
11726 * pairs that
11727 * actualy have something interesting in
11728 * them
11729 */
11730 if (use_json) {
11731 if (!is_first)
11732 vty_out(vty, ",\n");
11733 else
11734 is_first = 0;
11735
11736 vty_out(vty, "\"%s\":",
11737 get_afi_safi_str(afi,
11738 safi,
11739 true));
11740 } else {
11741 vty_out(vty,
11742 "\n%s Summary (%s):\n",
11743 get_afi_safi_str(afi,
11744 safi,
11745 false),
11746 bgp->name_pretty);
11747 }
11748 }
11749 bgp_show_summary(vty, bgp, afi, safi, fpeer,
11750 as_type, as, show_flags);
11751 }
11752 safi++;
11753 if (!safi_wildcard)
11754 safi = SAFI_MAX;
11755 }
11756 afi++;
11757 if (!afi_wildcard)
11758 afi = AFI_MAX;
11759 }
11760
11761 if (use_json && is_wildcard)
11762 vty_out(vty, "}\n");
11763 else if (!nbr_output) {
11764 if (use_json)
11765 vty_out(vty, "{}\n");
11766 else
11767 vty_out(vty, "%% No BGP neighbors found in %s\n",
11768 bgp->name_pretty);
11769 }
11770 }
11771
11772 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
11773 safi_t safi,
11774 const char *neighbor,
11775 int as_type, as_t as,
11776 uint16_t show_flags)
11777 {
11778 struct listnode *node, *nnode;
11779 struct bgp *bgp;
11780 struct peer *fpeer = NULL;
11781 int is_first = 1;
11782 bool nbr_output = false;
11783 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11784
11785 if (use_json)
11786 vty_out(vty, "{\n");
11787
11788 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11789 nbr_output = true;
11790 if (use_json) {
11791 if (!is_first)
11792 vty_out(vty, ",\n");
11793 else
11794 is_first = 0;
11795
11796 vty_out(vty, "\"%s\":",
11797 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11798 ? VRF_DEFAULT_NAME
11799 : bgp->name);
11800 }
11801 if (neighbor) {
11802 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11803 use_json);
11804 if (!fpeer)
11805 continue;
11806 }
11807 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11808 as, show_flags);
11809 }
11810
11811 if (use_json)
11812 vty_out(vty, "}\n");
11813 else if (!nbr_output)
11814 vty_out(vty, "%% BGP instance not found\n");
11815 }
11816
11817 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
11818 safi_t safi, const char *neighbor, int as_type,
11819 as_t as, uint16_t show_flags)
11820 {
11821 struct bgp *bgp;
11822 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11823 struct peer *fpeer = NULL;
11824
11825 if (name) {
11826 if (strmatch(name, "all")) {
11827 bgp_show_all_instances_summary_vty(vty, afi, safi,
11828 neighbor, as_type,
11829 as, show_flags);
11830 return CMD_SUCCESS;
11831 } else {
11832 bgp = bgp_lookup_by_name(name);
11833
11834 if (!bgp) {
11835 if (use_json)
11836 vty_out(vty, "{}\n");
11837 else
11838 vty_out(vty,
11839 "%% BGP instance not found\n");
11840 return CMD_WARNING;
11841 }
11842
11843 if (neighbor) {
11844 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11845 use_json);
11846 if (!fpeer)
11847 return CMD_WARNING;
11848 }
11849 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer,
11850 as_type, as, show_flags);
11851 return CMD_SUCCESS;
11852 }
11853 }
11854
11855 bgp = bgp_get_default();
11856
11857 if (bgp) {
11858 if (neighbor) {
11859 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11860 use_json);
11861 if (!fpeer)
11862 return CMD_WARNING;
11863 }
11864 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11865 as, show_flags);
11866 } else {
11867 if (use_json)
11868 vty_out(vty, "{}\n");
11869 else
11870 vty_out(vty, "%% BGP instance not found\n");
11871 return CMD_WARNING;
11872 }
11873
11874 return CMD_SUCCESS;
11875 }
11876
11877 /* `show [ip] bgp summary' commands. */
11878 DEFPY(show_ip_bgp_summary, show_ip_bgp_summary_cmd,
11879 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [" BGP_AFI_CMD_STR
11880 " [" BGP_SAFI_WITH_LABEL_CMD_STR
11881 "]] [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]",
11882 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11883 BGP_SAFI_WITH_LABEL_HELP_STR
11884 "Display the entries for all address families\n"
11885 "Summary of BGP neighbor status\n"
11886 "Show only sessions in Established state\n"
11887 "Show only sessions not in Established state\n"
11888 "Show only the specified neighbor session\n"
11889 "Neighbor to display information about\n"
11890 "Neighbor to display information about\n"
11891 "Neighbor on BGP configured interface\n"
11892 "Show only the specified remote AS sessions\n"
11893 "AS number\n"
11894 "Internal (iBGP) AS sessions\n"
11895 "External (eBGP) AS sessions\n"
11896 "Shorten the information on BGP instances\n"
11897 "Increase table width for longer output\n" JSON_STR)
11898 {
11899 char *vrf = NULL;
11900 afi_t afi = AFI_MAX;
11901 safi_t safi = SAFI_MAX;
11902 as_t as = 0; /* 0 means AS filter not set */
11903 int as_type = AS_UNSPECIFIED;
11904 uint16_t show_flags = 0;
11905
11906 int idx = 0;
11907
11908 /* show [ip] bgp */
11909 if (!all && argv_find(argv, argc, "ip", &idx))
11910 afi = AFI_IP;
11911 /* [<vrf> VIEWVRFNAME] */
11912 if (argv_find(argv, argc, "vrf", &idx)) {
11913 vrf = argv[idx + 1]->arg;
11914 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11915 vrf = NULL;
11916 } else if (argv_find(argv, argc, "view", &idx))
11917 /* [<view> VIEWVRFNAME] */
11918 vrf = argv[idx + 1]->arg;
11919 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11920 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11921 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11922 }
11923
11924 if (argv_find(argv, argc, "failed", &idx))
11925 SET_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
11926
11927 if (argv_find(argv, argc, "established", &idx))
11928 SET_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
11929
11930 if (argv_find(argv, argc, "remote-as", &idx)) {
11931 if (argv[idx + 1]->arg[0] == 'i')
11932 as_type = AS_INTERNAL;
11933 else if (argv[idx + 1]->arg[0] == 'e')
11934 as_type = AS_EXTERNAL;
11935 else
11936 as = (as_t)atoi(argv[idx + 1]->arg);
11937 }
11938
11939 if (argv_find(argv, argc, "terse", &idx))
11940 SET_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
11941
11942 if (argv_find(argv, argc, "wide", &idx))
11943 SET_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
11944
11945 if (argv_find(argv, argc, "json", &idx))
11946 SET_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11947
11948 return bgp_show_summary_vty(vty, vrf, afi, safi, neighbor, as_type, as,
11949 show_flags);
11950 }
11951
11952 const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
11953 {
11954 if (for_json)
11955 return get_afi_safi_json_str(afi, safi);
11956 else
11957 return get_afi_safi_vty_str(afi, safi);
11958 }
11959
11960
11961 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
11962 afi_t afi, safi_t safi,
11963 uint16_t adv_smcap, uint16_t adv_rmcap,
11964 uint16_t rcv_smcap, uint16_t rcv_rmcap,
11965 bool use_json, json_object *json_pref)
11966 {
11967 /* Send-Mode */
11968 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11969 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
11970 if (use_json) {
11971 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11972 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11973 json_object_string_add(json_pref, "sendMode",
11974 "advertisedAndReceived");
11975 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11976 json_object_string_add(json_pref, "sendMode",
11977 "advertised");
11978 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11979 json_object_string_add(json_pref, "sendMode",
11980 "received");
11981 } else {
11982 vty_out(vty, " Send-mode: ");
11983 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11984 vty_out(vty, "advertised");
11985 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11986 vty_out(vty, "%sreceived",
11987 CHECK_FLAG(p->af_cap[afi][safi],
11988 adv_smcap)
11989 ? ", "
11990 : "");
11991 vty_out(vty, "\n");
11992 }
11993 }
11994
11995 /* Receive-Mode */
11996 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11997 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
11998 if (use_json) {
11999 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
12000 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
12001 json_object_string_add(json_pref, "recvMode",
12002 "advertisedAndReceived");
12003 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
12004 json_object_string_add(json_pref, "recvMode",
12005 "advertised");
12006 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
12007 json_object_string_add(json_pref, "recvMode",
12008 "received");
12009 } else {
12010 vty_out(vty, " Receive-mode: ");
12011 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
12012 vty_out(vty, "advertised");
12013 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
12014 vty_out(vty, "%sreceived",
12015 CHECK_FLAG(p->af_cap[afi][safi],
12016 adv_rmcap)
12017 ? ", "
12018 : "");
12019 vty_out(vty, "\n");
12020 }
12021 }
12022 }
12023
12024 static void bgp_show_neighnor_graceful_restart_rbit(struct vty *vty,
12025 struct peer *p,
12026 bool use_json,
12027 json_object *json)
12028 {
12029 bool rbit_status = false;
12030
12031 if (!use_json)
12032 vty_out(vty, "\n R bit: ");
12033
12034 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
12035 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
12036 && (peer_established(p))) {
12037
12038 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_BIT_RCV))
12039 rbit_status = true;
12040 else
12041 rbit_status = false;
12042 }
12043
12044 if (rbit_status) {
12045 if (use_json)
12046 json_object_boolean_true_add(json, "rBit");
12047 else
12048 vty_out(vty, "True\n");
12049 } else {
12050 if (use_json)
12051 json_object_boolean_false_add(json, "rBit");
12052 else
12053 vty_out(vty, "False\n");
12054 }
12055 }
12056
12057 static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
12058 struct peer *peer,
12059 bool use_json,
12060 json_object *json)
12061 {
12062 const char *mode = "NotApplicable";
12063
12064 if (!use_json)
12065 vty_out(vty, "\n Remote GR Mode: ");
12066
12067 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
12068 && (peer_established(peer))) {
12069
12070 if ((peer->nsf_af_count == 0)
12071 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
12072
12073 mode = "Disable";
12074
12075 } else if (peer->nsf_af_count == 0
12076 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
12077
12078 mode = "Helper";
12079
12080 } else if (peer->nsf_af_count != 0
12081 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
12082
12083 mode = "Restart";
12084 }
12085 }
12086
12087 if (use_json) {
12088 json_object_string_add(json, "remoteGrMode", mode);
12089 } else
12090 vty_out(vty, mode, "\n");
12091 }
12092
12093 static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
12094 struct peer *p,
12095 bool use_json,
12096 json_object *json)
12097 {
12098 const char *mode = "Invalid";
12099
12100 if (!use_json)
12101 vty_out(vty, " Local GR Mode: ");
12102
12103 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
12104 mode = "Helper";
12105 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
12106 mode = "Restart";
12107 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
12108 mode = "Disable";
12109 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
12110 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
12111 mode = "Helper*";
12112 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
12113 mode = "Restart*";
12114 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
12115 mode = "Disable*";
12116 else
12117 mode = "Invalid*";
12118 }
12119
12120 if (use_json) {
12121 json_object_string_add(json, "localGrMode", mode);
12122 } else {
12123 vty_out(vty, mode, "\n");
12124 }
12125 }
12126
12127 static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
12128 struct vty *vty, struct peer *peer, bool use_json, json_object *json)
12129 {
12130 afi_t afi;
12131 safi_t safi;
12132 json_object *json_afi_safi = NULL;
12133 json_object *json_timer = NULL;
12134 json_object *json_endofrib_status = NULL;
12135 bool eor_flag = false;
12136
12137 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
12138 for (safi = SAFI_UNICAST; safi <= SAFI_MPLS_VPN; safi++) {
12139 if (!peer->afc[afi][safi])
12140 continue;
12141
12142 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
12143 || !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
12144 continue;
12145
12146 if (use_json) {
12147 json_afi_safi = json_object_new_object();
12148 json_endofrib_status = json_object_new_object();
12149 json_timer = json_object_new_object();
12150 }
12151
12152 if (peer->eor_stime[afi][safi]
12153 >= peer->pkt_stime[afi][safi])
12154 eor_flag = true;
12155 else
12156 eor_flag = false;
12157
12158 if (!use_json) {
12159 vty_out(vty, " %s:\n",
12160 get_afi_safi_str(afi, safi, false));
12161
12162 vty_out(vty, " F bit: ");
12163 }
12164
12165 if (peer->nsf[afi][safi]
12166 && CHECK_FLAG(peer->af_cap[afi][safi],
12167 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
12168
12169 if (use_json) {
12170 json_object_boolean_true_add(
12171 json_afi_safi, "fBit");
12172 } else
12173 vty_out(vty, "True\n");
12174 } else {
12175 if (use_json)
12176 json_object_boolean_false_add(
12177 json_afi_safi, "fBit");
12178 else
12179 vty_out(vty, "False\n");
12180 }
12181
12182 if (!use_json)
12183 vty_out(vty, " End-of-RIB sent: ");
12184
12185 if (CHECK_FLAG(peer->af_sflags[afi][safi],
12186 PEER_STATUS_EOR_SEND)) {
12187 if (use_json) {
12188 json_object_boolean_true_add(
12189 json_endofrib_status,
12190 "endOfRibSend");
12191
12192 PRINT_EOR_JSON(eor_flag);
12193 } else {
12194 vty_out(vty, "Yes\n");
12195 vty_out(vty,
12196 " End-of-RIB sent after update: ");
12197
12198 PRINT_EOR(eor_flag);
12199 }
12200 } else {
12201 if (use_json) {
12202 json_object_boolean_false_add(
12203 json_endofrib_status,
12204 "endOfRibSend");
12205 json_object_boolean_false_add(
12206 json_endofrib_status,
12207 "endOfRibSentAfterUpdate");
12208 } else {
12209 vty_out(vty, "No\n");
12210 vty_out(vty,
12211 " End-of-RIB sent after update: ");
12212 vty_out(vty, "No\n");
12213 }
12214 }
12215
12216 if (!use_json)
12217 vty_out(vty, " End-of-RIB received: ");
12218
12219 if (CHECK_FLAG(peer->af_sflags[afi][safi],
12220 PEER_STATUS_EOR_RECEIVED)) {
12221 if (use_json)
12222 json_object_boolean_true_add(
12223 json_endofrib_status,
12224 "endOfRibRecv");
12225 else
12226 vty_out(vty, "Yes\n");
12227 } else {
12228 if (use_json)
12229 json_object_boolean_false_add(
12230 json_endofrib_status,
12231 "endOfRibRecv");
12232 else
12233 vty_out(vty, "No\n");
12234 }
12235
12236 if (use_json) {
12237 json_object_int_add(json_timer,
12238 "stalePathTimer",
12239 peer->bgp->stalepath_time);
12240
12241 if (peer->t_gr_stale != NULL) {
12242 json_object_int_add(
12243 json_timer,
12244 "stalePathTimerRemaining",
12245 thread_timer_remain_second(
12246 peer->t_gr_stale));
12247 }
12248
12249 /* Display Configured Selection
12250 * Deferral only when when
12251 * Gr mode is enabled.
12252 */
12253 if (CHECK_FLAG(peer->flags,
12254 PEER_FLAG_GRACEFUL_RESTART)) {
12255 json_object_int_add(
12256 json_timer,
12257 "selectionDeferralTimer",
12258 peer->bgp->stalepath_time);
12259 }
12260
12261 if (peer->bgp->gr_info[afi][safi]
12262 .t_select_deferral
12263 != NULL) {
12264
12265 json_object_int_add(
12266 json_timer,
12267 "selectionDeferralTimerRemaining",
12268 thread_timer_remain_second(
12269 peer->bgp
12270 ->gr_info[afi]
12271 [safi]
12272 .t_select_deferral));
12273 }
12274 } else {
12275 vty_out(vty, " Timers:\n");
12276 vty_out(vty,
12277 " Configured Stale Path Time(sec): %u\n",
12278 peer->bgp->stalepath_time);
12279
12280 if (peer->t_gr_stale != NULL)
12281 vty_out(vty,
12282 " Stale Path Remaining(sec): %ld\n",
12283 thread_timer_remain_second(
12284 peer->t_gr_stale));
12285 /* Display Configured Selection
12286 * Deferral only when when
12287 * Gr mode is enabled.
12288 */
12289 if (CHECK_FLAG(peer->flags,
12290 PEER_FLAG_GRACEFUL_RESTART))
12291 vty_out(vty,
12292 " Configured Selection Deferral Time(sec): %u\n",
12293 peer->bgp->select_defer_time);
12294
12295 if (peer->bgp->gr_info[afi][safi]
12296 .t_select_deferral
12297 != NULL)
12298 vty_out(vty,
12299 " Selection Deferral Time Remaining(sec): %ld\n",
12300 thread_timer_remain_second(
12301 peer->bgp
12302 ->gr_info[afi]
12303 [safi]
12304 .t_select_deferral));
12305 }
12306 if (use_json) {
12307 json_object_object_add(json_afi_safi,
12308 "endOfRibStatus",
12309 json_endofrib_status);
12310 json_object_object_add(json_afi_safi, "timers",
12311 json_timer);
12312 json_object_object_add(
12313 json, get_afi_safi_str(afi, safi, true),
12314 json_afi_safi);
12315 }
12316 }
12317 }
12318 }
12319
12320 static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
12321 struct peer *p,
12322 bool use_json,
12323 json_object *json)
12324 {
12325 if (use_json) {
12326 json_object *json_timer = NULL;
12327
12328 json_timer = json_object_new_object();
12329
12330 json_object_int_add(json_timer, "configuredRestartTimer",
12331 p->bgp->restart_time);
12332
12333 json_object_int_add(json_timer, "receivedRestartTimer",
12334 p->v_gr_restart);
12335
12336 if (p->t_gr_restart != NULL)
12337 json_object_int_add(
12338 json_timer, "restartTimerRemaining",
12339 thread_timer_remain_second(p->t_gr_restart));
12340
12341 json_object_object_add(json, "timers", json_timer);
12342 } else {
12343
12344 vty_out(vty, " Timers:\n");
12345 vty_out(vty, " Configured Restart Time(sec): %u\n",
12346 p->bgp->restart_time);
12347
12348 vty_out(vty, " Received Restart Time(sec): %u\n",
12349 p->v_gr_restart);
12350 if (p->t_gr_restart != NULL)
12351 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
12352 thread_timer_remain_second(p->t_gr_restart));
12353 if (p->t_gr_restart != NULL) {
12354 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
12355 thread_timer_remain_second(p->t_gr_restart));
12356 }
12357 }
12358 }
12359
12360 static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
12361 bool use_json, json_object *json)
12362 {
12363 char buf[SU_ADDRSTRLEN] = {0};
12364 char dn_flag[2] = {0};
12365 /* '*' + v6 address of neighbor */
12366 char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
12367
12368 if (!p->conf_if && peer_dynamic_neighbor(p))
12369 dn_flag[0] = '*';
12370
12371 if (p->conf_if) {
12372 if (use_json)
12373 json_object_string_add(
12374 json, "neighborAddr",
12375 BGP_PEER_SU_UNSPEC(p)
12376 ? "none"
12377 : sockunion2str(&p->su, buf,
12378 SU_ADDRSTRLEN));
12379 else
12380 vty_out(vty, "BGP neighbor on %s: %s\n", p->conf_if,
12381 BGP_PEER_SU_UNSPEC(p)
12382 ? "none"
12383 : sockunion2str(&p->su, buf,
12384 SU_ADDRSTRLEN));
12385 } else {
12386 snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
12387 p->host);
12388
12389 if (use_json)
12390 json_object_string_add(json, "neighborAddr",
12391 neighborAddr);
12392 else
12393 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
12394 }
12395
12396 /* more gr info in new format */
12397 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json);
12398 }
12399
12400 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
12401 safi_t safi, bool use_json,
12402 json_object *json_neigh)
12403 {
12404 struct bgp_filter *filter;
12405 struct peer_af *paf;
12406 char orf_pfx_name[BUFSIZ];
12407 int orf_pfx_count;
12408 json_object *json_af = NULL;
12409 json_object *json_prefA = NULL;
12410 json_object *json_prefB = NULL;
12411 json_object *json_addr = NULL;
12412 json_object *json_advmap = NULL;
12413
12414 if (use_json) {
12415 json_addr = json_object_new_object();
12416 json_af = json_object_new_object();
12417 filter = &p->filter[afi][safi];
12418
12419 if (peer_group_active(p))
12420 json_object_string_add(json_addr, "peerGroupMember",
12421 p->group->name);
12422
12423 paf = peer_af_find(p, afi, safi);
12424 if (paf && PAF_SUBGRP(paf)) {
12425 json_object_int_add(json_addr, "updateGroupId",
12426 PAF_UPDGRP(paf)->id);
12427 json_object_int_add(json_addr, "subGroupId",
12428 PAF_SUBGRP(paf)->id);
12429 json_object_int_add(json_addr, "packetQueueLength",
12430 bpacket_queue_virtual_length(paf));
12431 }
12432
12433 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12434 || CHECK_FLAG(p->af_cap[afi][safi],
12435 PEER_CAP_ORF_PREFIX_SM_RCV)
12436 || CHECK_FLAG(p->af_cap[afi][safi],
12437 PEER_CAP_ORF_PREFIX_RM_ADV)
12438 || CHECK_FLAG(p->af_cap[afi][safi],
12439 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12440 json_object_int_add(json_af, "orfType",
12441 ORF_TYPE_PREFIX);
12442 json_prefA = json_object_new_object();
12443 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
12444 PEER_CAP_ORF_PREFIX_SM_ADV,
12445 PEER_CAP_ORF_PREFIX_RM_ADV,
12446 PEER_CAP_ORF_PREFIX_SM_RCV,
12447 PEER_CAP_ORF_PREFIX_RM_RCV,
12448 use_json, json_prefA);
12449 json_object_object_add(json_af, "orfPrefixList",
12450 json_prefA);
12451 }
12452
12453 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12454 || CHECK_FLAG(p->af_cap[afi][safi],
12455 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12456 || CHECK_FLAG(p->af_cap[afi][safi],
12457 PEER_CAP_ORF_PREFIX_RM_ADV)
12458 || CHECK_FLAG(p->af_cap[afi][safi],
12459 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12460 json_object_int_add(json_af, "orfOldType",
12461 ORF_TYPE_PREFIX_OLD);
12462 json_prefB = json_object_new_object();
12463 bgp_show_peer_afi_orf_cap(
12464 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12465 PEER_CAP_ORF_PREFIX_RM_ADV,
12466 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12467 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
12468 json_prefB);
12469 json_object_object_add(json_af, "orfOldPrefixList",
12470 json_prefB);
12471 }
12472
12473 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12474 || CHECK_FLAG(p->af_cap[afi][safi],
12475 PEER_CAP_ORF_PREFIX_SM_RCV)
12476 || CHECK_FLAG(p->af_cap[afi][safi],
12477 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12478 || CHECK_FLAG(p->af_cap[afi][safi],
12479 PEER_CAP_ORF_PREFIX_RM_ADV)
12480 || CHECK_FLAG(p->af_cap[afi][safi],
12481 PEER_CAP_ORF_PREFIX_RM_RCV)
12482 || CHECK_FLAG(p->af_cap[afi][safi],
12483 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12484 json_object_object_add(json_addr, "afDependentCap",
12485 json_af);
12486 else
12487 json_object_free(json_af);
12488
12489 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12490 p->host, afi, safi);
12491 orf_pfx_count = prefix_bgp_show_prefix_list(
12492 NULL, afi, orf_pfx_name, use_json);
12493
12494 if (CHECK_FLAG(p->af_sflags[afi][safi],
12495 PEER_STATUS_ORF_PREFIX_SEND)
12496 || orf_pfx_count) {
12497 if (CHECK_FLAG(p->af_sflags[afi][safi],
12498 PEER_STATUS_ORF_PREFIX_SEND))
12499 json_object_boolean_true_add(json_neigh,
12500 "orfSent");
12501 if (orf_pfx_count)
12502 json_object_int_add(json_addr, "orfRecvCounter",
12503 orf_pfx_count);
12504 }
12505 if (CHECK_FLAG(p->af_sflags[afi][safi],
12506 PEER_STATUS_ORF_WAIT_REFRESH))
12507 json_object_string_add(
12508 json_addr, "orfFirstUpdate",
12509 "deferredUntilORFOrRouteRefreshRecvd");
12510
12511 if (CHECK_FLAG(p->af_flags[afi][safi],
12512 PEER_FLAG_REFLECTOR_CLIENT))
12513 json_object_boolean_true_add(json_addr,
12514 "routeReflectorClient");
12515 if (CHECK_FLAG(p->af_flags[afi][safi],
12516 PEER_FLAG_RSERVER_CLIENT))
12517 json_object_boolean_true_add(json_addr,
12518 "routeServerClient");
12519 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12520 json_object_boolean_true_add(json_addr,
12521 "inboundSoftConfigPermit");
12522
12523 if (CHECK_FLAG(p->af_flags[afi][safi],
12524 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12525 json_object_boolean_true_add(
12526 json_addr,
12527 "privateAsNumsAllReplacedInUpdatesToNbr");
12528 else if (CHECK_FLAG(p->af_flags[afi][safi],
12529 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12530 json_object_boolean_true_add(
12531 json_addr,
12532 "privateAsNumsReplacedInUpdatesToNbr");
12533 else if (CHECK_FLAG(p->af_flags[afi][safi],
12534 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12535 json_object_boolean_true_add(
12536 json_addr,
12537 "privateAsNumsAllRemovedInUpdatesToNbr");
12538 else if (CHECK_FLAG(p->af_flags[afi][safi],
12539 PEER_FLAG_REMOVE_PRIVATE_AS))
12540 json_object_boolean_true_add(
12541 json_addr,
12542 "privateAsNumsRemovedInUpdatesToNbr");
12543
12544 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12545 json_object_boolean_true_add(
12546 json_addr,
12547 bgp_addpath_names(p->addpath_type[afi][safi])
12548 ->type_json_name);
12549
12550 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12551 json_object_string_add(json_addr,
12552 "overrideASNsInOutboundUpdates",
12553 "ifAspathEqualRemoteAs");
12554
12555 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12556 || CHECK_FLAG(p->af_flags[afi][safi],
12557 PEER_FLAG_FORCE_NEXTHOP_SELF))
12558 json_object_boolean_true_add(json_addr,
12559 "routerAlwaysNextHop");
12560 if (CHECK_FLAG(p->af_flags[afi][safi],
12561 PEER_FLAG_AS_PATH_UNCHANGED))
12562 json_object_boolean_true_add(
12563 json_addr, "unchangedAsPathPropogatedToNbr");
12564 if (CHECK_FLAG(p->af_flags[afi][safi],
12565 PEER_FLAG_NEXTHOP_UNCHANGED))
12566 json_object_boolean_true_add(
12567 json_addr, "unchangedNextHopPropogatedToNbr");
12568 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12569 json_object_boolean_true_add(
12570 json_addr, "unchangedMedPropogatedToNbr");
12571 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12572 || CHECK_FLAG(p->af_flags[afi][safi],
12573 PEER_FLAG_SEND_EXT_COMMUNITY)) {
12574 if (CHECK_FLAG(p->af_flags[afi][safi],
12575 PEER_FLAG_SEND_COMMUNITY)
12576 && CHECK_FLAG(p->af_flags[afi][safi],
12577 PEER_FLAG_SEND_EXT_COMMUNITY))
12578 json_object_string_add(json_addr,
12579 "commAttriSentToNbr",
12580 "extendedAndStandard");
12581 else if (CHECK_FLAG(p->af_flags[afi][safi],
12582 PEER_FLAG_SEND_EXT_COMMUNITY))
12583 json_object_string_add(json_addr,
12584 "commAttriSentToNbr",
12585 "extended");
12586 else
12587 json_object_string_add(json_addr,
12588 "commAttriSentToNbr",
12589 "standard");
12590 }
12591 if (CHECK_FLAG(p->af_flags[afi][safi],
12592 PEER_FLAG_DEFAULT_ORIGINATE)) {
12593 if (p->default_rmap[afi][safi].name)
12594 json_object_string_add(
12595 json_addr, "defaultRouteMap",
12596 p->default_rmap[afi][safi].name);
12597
12598 if (paf && PAF_SUBGRP(paf)
12599 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12600 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12601 json_object_boolean_true_add(json_addr,
12602 "defaultSent");
12603 else
12604 json_object_boolean_true_add(json_addr,
12605 "defaultNotSent");
12606 }
12607
12608 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
12609 if (is_evpn_enabled())
12610 json_object_boolean_true_add(
12611 json_addr, "advertiseAllVnis");
12612 }
12613
12614 if (filter->plist[FILTER_IN].name
12615 || filter->dlist[FILTER_IN].name
12616 || filter->aslist[FILTER_IN].name
12617 || filter->map[RMAP_IN].name)
12618 json_object_boolean_true_add(json_addr,
12619 "inboundPathPolicyConfig");
12620 if (filter->plist[FILTER_OUT].name
12621 || filter->dlist[FILTER_OUT].name
12622 || filter->aslist[FILTER_OUT].name
12623 || filter->map[RMAP_OUT].name || filter->usmap.name)
12624 json_object_boolean_true_add(
12625 json_addr, "outboundPathPolicyConfig");
12626
12627 /* prefix-list */
12628 if (filter->plist[FILTER_IN].name)
12629 json_object_string_add(json_addr,
12630 "incomingUpdatePrefixFilterList",
12631 filter->plist[FILTER_IN].name);
12632 if (filter->plist[FILTER_OUT].name)
12633 json_object_string_add(json_addr,
12634 "outgoingUpdatePrefixFilterList",
12635 filter->plist[FILTER_OUT].name);
12636
12637 /* distribute-list */
12638 if (filter->dlist[FILTER_IN].name)
12639 json_object_string_add(
12640 json_addr, "incomingUpdateNetworkFilterList",
12641 filter->dlist[FILTER_IN].name);
12642 if (filter->dlist[FILTER_OUT].name)
12643 json_object_string_add(
12644 json_addr, "outgoingUpdateNetworkFilterList",
12645 filter->dlist[FILTER_OUT].name);
12646
12647 /* filter-list. */
12648 if (filter->aslist[FILTER_IN].name)
12649 json_object_string_add(json_addr,
12650 "incomingUpdateAsPathFilterList",
12651 filter->aslist[FILTER_IN].name);
12652 if (filter->aslist[FILTER_OUT].name)
12653 json_object_string_add(json_addr,
12654 "outgoingUpdateAsPathFilterList",
12655 filter->aslist[FILTER_OUT].name);
12656
12657 /* route-map. */
12658 if (filter->map[RMAP_IN].name)
12659 json_object_string_add(
12660 json_addr, "routeMapForIncomingAdvertisements",
12661 filter->map[RMAP_IN].name);
12662 if (filter->map[RMAP_OUT].name)
12663 json_object_string_add(
12664 json_addr, "routeMapForOutgoingAdvertisements",
12665 filter->map[RMAP_OUT].name);
12666
12667 /* ebgp-requires-policy (inbound) */
12668 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12669 && !bgp_inbound_policy_exists(p, filter))
12670 json_object_string_add(
12671 json_addr, "inboundEbgpRequiresPolicy",
12672 "Inbound updates discarded due to missing policy");
12673
12674 /* ebgp-requires-policy (outbound) */
12675 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12676 && (!bgp_outbound_policy_exists(p, filter)))
12677 json_object_string_add(
12678 json_addr, "outboundEbgpRequiresPolicy",
12679 "Outbound updates discarded due to missing policy");
12680
12681 /* unsuppress-map */
12682 if (filter->usmap.name)
12683 json_object_string_add(json_addr,
12684 "selectiveUnsuppressRouteMap",
12685 filter->usmap.name);
12686
12687 /* advertise-map */
12688 if (filter->advmap.aname) {
12689 json_advmap = json_object_new_object();
12690 json_object_string_add(json_advmap, "condition",
12691 filter->advmap.condition
12692 ? "EXIST"
12693 : "NON_EXIST");
12694 json_object_string_add(json_advmap, "conditionMap",
12695 filter->advmap.cname);
12696 json_object_string_add(json_advmap, "advertiseMap",
12697 filter->advmap.aname);
12698 json_object_string_add(json_advmap, "advertiseStatus",
12699 filter->advmap.update_type
12700 == ADVERTISE
12701 ? "Advertise"
12702 : "Withdraw");
12703 json_object_object_add(json_addr, "advertiseMap",
12704 json_advmap);
12705 }
12706
12707 /* Receive prefix count */
12708 json_object_int_add(json_addr, "acceptedPrefixCounter",
12709 p->pcount[afi][safi]);
12710 if (paf && PAF_SUBGRP(paf))
12711 json_object_int_add(json_addr, "sentPrefixCounter",
12712 (PAF_SUBGRP(paf))->scount);
12713
12714 /* Maximum prefix */
12715 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
12716 json_object_int_add(json_addr, "prefixOutAllowedMax",
12717 p->pmax_out[afi][safi]);
12718
12719 /* Maximum prefix */
12720 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12721 json_object_int_add(json_addr, "prefixAllowedMax",
12722 p->pmax[afi][safi]);
12723 if (CHECK_FLAG(p->af_flags[afi][safi],
12724 PEER_FLAG_MAX_PREFIX_WARNING))
12725 json_object_boolean_true_add(
12726 json_addr, "prefixAllowedMaxWarning");
12727 json_object_int_add(json_addr,
12728 "prefixAllowedWarningThresh",
12729 p->pmax_threshold[afi][safi]);
12730 if (p->pmax_restart[afi][safi])
12731 json_object_int_add(
12732 json_addr,
12733 "prefixAllowedRestartIntervalMsecs",
12734 p->pmax_restart[afi][safi] * 60000);
12735 }
12736 json_object_object_add(json_neigh,
12737 get_afi_safi_str(afi, safi, true),
12738 json_addr);
12739
12740 } else {
12741 filter = &p->filter[afi][safi];
12742
12743 vty_out(vty, " For address family: %s\n",
12744 get_afi_safi_str(afi, safi, false));
12745
12746 if (peer_group_active(p))
12747 vty_out(vty, " %s peer-group member\n",
12748 p->group->name);
12749
12750 paf = peer_af_find(p, afi, safi);
12751 if (paf && PAF_SUBGRP(paf)) {
12752 vty_out(vty, " Update group %" PRIu64", subgroup %" PRIu64 "\n",
12753 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
12754 vty_out(vty, " Packet Queue length %d\n",
12755 bpacket_queue_virtual_length(paf));
12756 } else {
12757 vty_out(vty, " Not part of any update group\n");
12758 }
12759 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12760 || CHECK_FLAG(p->af_cap[afi][safi],
12761 PEER_CAP_ORF_PREFIX_SM_RCV)
12762 || CHECK_FLAG(p->af_cap[afi][safi],
12763 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12764 || CHECK_FLAG(p->af_cap[afi][safi],
12765 PEER_CAP_ORF_PREFIX_RM_ADV)
12766 || CHECK_FLAG(p->af_cap[afi][safi],
12767 PEER_CAP_ORF_PREFIX_RM_RCV)
12768 || CHECK_FLAG(p->af_cap[afi][safi],
12769 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12770 vty_out(vty, " AF-dependant capabilities:\n");
12771
12772 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12773 || CHECK_FLAG(p->af_cap[afi][safi],
12774 PEER_CAP_ORF_PREFIX_SM_RCV)
12775 || CHECK_FLAG(p->af_cap[afi][safi],
12776 PEER_CAP_ORF_PREFIX_RM_ADV)
12777 || CHECK_FLAG(p->af_cap[afi][safi],
12778 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12779 vty_out(vty,
12780 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12781 ORF_TYPE_PREFIX);
12782 bgp_show_peer_afi_orf_cap(
12783 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12784 PEER_CAP_ORF_PREFIX_RM_ADV,
12785 PEER_CAP_ORF_PREFIX_SM_RCV,
12786 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
12787 }
12788 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12789 || CHECK_FLAG(p->af_cap[afi][safi],
12790 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12791 || CHECK_FLAG(p->af_cap[afi][safi],
12792 PEER_CAP_ORF_PREFIX_RM_ADV)
12793 || CHECK_FLAG(p->af_cap[afi][safi],
12794 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12795 vty_out(vty,
12796 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12797 ORF_TYPE_PREFIX_OLD);
12798 bgp_show_peer_afi_orf_cap(
12799 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12800 PEER_CAP_ORF_PREFIX_RM_ADV,
12801 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12802 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
12803 }
12804
12805 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12806 p->host, afi, safi);
12807 orf_pfx_count = prefix_bgp_show_prefix_list(
12808 NULL, afi, orf_pfx_name, use_json);
12809
12810 if (CHECK_FLAG(p->af_sflags[afi][safi],
12811 PEER_STATUS_ORF_PREFIX_SEND)
12812 || orf_pfx_count) {
12813 vty_out(vty, " Outbound Route Filter (ORF):");
12814 if (CHECK_FLAG(p->af_sflags[afi][safi],
12815 PEER_STATUS_ORF_PREFIX_SEND))
12816 vty_out(vty, " sent;");
12817 if (orf_pfx_count)
12818 vty_out(vty, " received (%d entries)",
12819 orf_pfx_count);
12820 vty_out(vty, "\n");
12821 }
12822 if (CHECK_FLAG(p->af_sflags[afi][safi],
12823 PEER_STATUS_ORF_WAIT_REFRESH))
12824 vty_out(vty,
12825 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
12826
12827 if (CHECK_FLAG(p->af_flags[afi][safi],
12828 PEER_FLAG_REFLECTOR_CLIENT))
12829 vty_out(vty, " Route-Reflector Client\n");
12830 if (CHECK_FLAG(p->af_flags[afi][safi],
12831 PEER_FLAG_RSERVER_CLIENT))
12832 vty_out(vty, " Route-Server Client\n");
12833 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12834 vty_out(vty,
12835 " Inbound soft reconfiguration allowed\n");
12836
12837 if (CHECK_FLAG(p->af_flags[afi][safi],
12838 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12839 vty_out(vty,
12840 " Private AS numbers (all) replaced in updates to this neighbor\n");
12841 else if (CHECK_FLAG(p->af_flags[afi][safi],
12842 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12843 vty_out(vty,
12844 " Private AS numbers replaced in updates to this neighbor\n");
12845 else if (CHECK_FLAG(p->af_flags[afi][safi],
12846 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12847 vty_out(vty,
12848 " Private AS numbers (all) removed in updates to this neighbor\n");
12849 else if (CHECK_FLAG(p->af_flags[afi][safi],
12850 PEER_FLAG_REMOVE_PRIVATE_AS))
12851 vty_out(vty,
12852 " Private AS numbers removed in updates to this neighbor\n");
12853
12854 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12855 vty_out(vty, " %s\n",
12856 bgp_addpath_names(p->addpath_type[afi][safi])
12857 ->human_description);
12858
12859 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12860 vty_out(vty,
12861 " Override ASNs in outbound updates if aspath equals remote-as\n");
12862
12863 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12864 || CHECK_FLAG(p->af_flags[afi][safi],
12865 PEER_FLAG_FORCE_NEXTHOP_SELF))
12866 vty_out(vty, " NEXT_HOP is always this router\n");
12867 if (CHECK_FLAG(p->af_flags[afi][safi],
12868 PEER_FLAG_AS_PATH_UNCHANGED))
12869 vty_out(vty,
12870 " AS_PATH is propagated unchanged to this neighbor\n");
12871 if (CHECK_FLAG(p->af_flags[afi][safi],
12872 PEER_FLAG_NEXTHOP_UNCHANGED))
12873 vty_out(vty,
12874 " NEXT_HOP is propagated unchanged to this neighbor\n");
12875 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12876 vty_out(vty,
12877 " MED is propagated unchanged to this neighbor\n");
12878 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12879 || CHECK_FLAG(p->af_flags[afi][safi],
12880 PEER_FLAG_SEND_EXT_COMMUNITY)
12881 || CHECK_FLAG(p->af_flags[afi][safi],
12882 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
12883 vty_out(vty,
12884 " Community attribute sent to this neighbor");
12885 if (CHECK_FLAG(p->af_flags[afi][safi],
12886 PEER_FLAG_SEND_COMMUNITY)
12887 && CHECK_FLAG(p->af_flags[afi][safi],
12888 PEER_FLAG_SEND_EXT_COMMUNITY)
12889 && CHECK_FLAG(p->af_flags[afi][safi],
12890 PEER_FLAG_SEND_LARGE_COMMUNITY))
12891 vty_out(vty, "(all)\n");
12892 else if (CHECK_FLAG(p->af_flags[afi][safi],
12893 PEER_FLAG_SEND_LARGE_COMMUNITY))
12894 vty_out(vty, "(large)\n");
12895 else if (CHECK_FLAG(p->af_flags[afi][safi],
12896 PEER_FLAG_SEND_EXT_COMMUNITY))
12897 vty_out(vty, "(extended)\n");
12898 else
12899 vty_out(vty, "(standard)\n");
12900 }
12901 if (CHECK_FLAG(p->af_flags[afi][safi],
12902 PEER_FLAG_DEFAULT_ORIGINATE)) {
12903 vty_out(vty, " Default information originate,");
12904
12905 if (p->default_rmap[afi][safi].name)
12906 vty_out(vty, " default route-map %s%s,",
12907 p->default_rmap[afi][safi].map ? "*"
12908 : "",
12909 p->default_rmap[afi][safi].name);
12910 if (paf && PAF_SUBGRP(paf)
12911 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12912 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12913 vty_out(vty, " default sent\n");
12914 else
12915 vty_out(vty, " default not sent\n");
12916 }
12917
12918 /* advertise-vni-all */
12919 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
12920 if (is_evpn_enabled())
12921 vty_out(vty, " advertise-all-vni\n");
12922 }
12923
12924 if (filter->plist[FILTER_IN].name
12925 || filter->dlist[FILTER_IN].name
12926 || filter->aslist[FILTER_IN].name
12927 || filter->map[RMAP_IN].name)
12928 vty_out(vty, " Inbound path policy configured\n");
12929 if (filter->plist[FILTER_OUT].name
12930 || filter->dlist[FILTER_OUT].name
12931 || filter->aslist[FILTER_OUT].name
12932 || filter->map[RMAP_OUT].name || filter->usmap.name)
12933 vty_out(vty, " Outbound path policy configured\n");
12934
12935 /* prefix-list */
12936 if (filter->plist[FILTER_IN].name)
12937 vty_out(vty,
12938 " Incoming update prefix filter list is %s%s\n",
12939 filter->plist[FILTER_IN].plist ? "*" : "",
12940 filter->plist[FILTER_IN].name);
12941 if (filter->plist[FILTER_OUT].name)
12942 vty_out(vty,
12943 " Outgoing update prefix filter list is %s%s\n",
12944 filter->plist[FILTER_OUT].plist ? "*" : "",
12945 filter->plist[FILTER_OUT].name);
12946
12947 /* distribute-list */
12948 if (filter->dlist[FILTER_IN].name)
12949 vty_out(vty,
12950 " Incoming update network filter list is %s%s\n",
12951 filter->dlist[FILTER_IN].alist ? "*" : "",
12952 filter->dlist[FILTER_IN].name);
12953 if (filter->dlist[FILTER_OUT].name)
12954 vty_out(vty,
12955 " Outgoing update network filter list is %s%s\n",
12956 filter->dlist[FILTER_OUT].alist ? "*" : "",
12957 filter->dlist[FILTER_OUT].name);
12958
12959 /* filter-list. */
12960 if (filter->aslist[FILTER_IN].name)
12961 vty_out(vty,
12962 " Incoming update AS path filter list is %s%s\n",
12963 filter->aslist[FILTER_IN].aslist ? "*" : "",
12964 filter->aslist[FILTER_IN].name);
12965 if (filter->aslist[FILTER_OUT].name)
12966 vty_out(vty,
12967 " Outgoing update AS path filter list is %s%s\n",
12968 filter->aslist[FILTER_OUT].aslist ? "*" : "",
12969 filter->aslist[FILTER_OUT].name);
12970
12971 /* route-map. */
12972 if (filter->map[RMAP_IN].name)
12973 vty_out(vty,
12974 " Route map for incoming advertisements is %s%s\n",
12975 filter->map[RMAP_IN].map ? "*" : "",
12976 filter->map[RMAP_IN].name);
12977 if (filter->map[RMAP_OUT].name)
12978 vty_out(vty,
12979 " Route map for outgoing advertisements is %s%s\n",
12980 filter->map[RMAP_OUT].map ? "*" : "",
12981 filter->map[RMAP_OUT].name);
12982
12983 /* ebgp-requires-policy (inbound) */
12984 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12985 && !bgp_inbound_policy_exists(p, filter))
12986 vty_out(vty,
12987 " Inbound updates discarded due to missing policy\n");
12988
12989 /* ebgp-requires-policy (outbound) */
12990 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12991 && !bgp_outbound_policy_exists(p, filter))
12992 vty_out(vty,
12993 " Outbound updates discarded due to missing policy\n");
12994
12995 /* unsuppress-map */
12996 if (filter->usmap.name)
12997 vty_out(vty,
12998 " Route map for selective unsuppress is %s%s\n",
12999 filter->usmap.map ? "*" : "",
13000 filter->usmap.name);
13001
13002 /* advertise-map */
13003 if (filter->advmap.aname && filter->advmap.cname)
13004 vty_out(vty,
13005 " Condition %s, Condition-map %s%s, Advertise-map %s%s, status: %s\n",
13006 filter->advmap.condition ? "EXIST"
13007 : "NON_EXIST",
13008 filter->advmap.cmap ? "*" : "",
13009 filter->advmap.cname,
13010 filter->advmap.amap ? "*" : "",
13011 filter->advmap.aname,
13012 filter->advmap.update_type == ADVERTISE
13013 ? "Advertise"
13014 : "Withdraw");
13015
13016 /* Receive prefix count */
13017 vty_out(vty, " %u accepted prefixes\n",
13018 p->pcount[afi][safi]);
13019
13020 /* maximum-prefix-out */
13021 if (CHECK_FLAG(p->af_flags[afi][safi],
13022 PEER_FLAG_MAX_PREFIX_OUT))
13023 vty_out(vty,
13024 " Maximum allowed prefixes sent %u\n",
13025 p->pmax_out[afi][safi]);
13026
13027 /* Maximum prefix */
13028 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
13029 vty_out(vty,
13030 " Maximum prefixes allowed %u%s\n",
13031 p->pmax[afi][safi],
13032 CHECK_FLAG(p->af_flags[afi][safi],
13033 PEER_FLAG_MAX_PREFIX_WARNING)
13034 ? " (warning-only)"
13035 : "");
13036 vty_out(vty, " Threshold for warning message %d%%",
13037 p->pmax_threshold[afi][safi]);
13038 if (p->pmax_restart[afi][safi])
13039 vty_out(vty, ", restart interval %d min",
13040 p->pmax_restart[afi][safi]);
13041 vty_out(vty, "\n");
13042 }
13043
13044 vty_out(vty, "\n");
13045 }
13046 }
13047
13048 static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
13049 json_object *json)
13050 {
13051 struct bgp *bgp;
13052 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
13053 char timebuf[BGP_UPTIME_LEN];
13054 char dn_flag[2];
13055 afi_t afi;
13056 safi_t safi;
13057 uint16_t i;
13058 uint8_t *msg;
13059 json_object *json_neigh = NULL;
13060 time_t epoch_tbuf;
13061 uint32_t sync_tcp_mss;
13062
13063 bgp = p->bgp;
13064
13065 if (use_json)
13066 json_neigh = json_object_new_object();
13067
13068 memset(dn_flag, '\0', sizeof(dn_flag));
13069 if (!p->conf_if && peer_dynamic_neighbor(p))
13070 dn_flag[0] = '*';
13071
13072 if (!use_json) {
13073 if (p->conf_if) /* Configured interface name. */
13074 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
13075 BGP_PEER_SU_UNSPEC(p)
13076 ? "None"
13077 : sockunion2str(&p->su, buf,
13078 SU_ADDRSTRLEN));
13079 else /* Configured IP address. */
13080 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
13081 p->host);
13082 }
13083
13084 if (use_json) {
13085 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
13086 json_object_string_add(json_neigh, "bgpNeighborAddr",
13087 "none");
13088 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
13089 json_object_string_add(
13090 json_neigh, "bgpNeighborAddr",
13091 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
13092
13093 json_object_int_add(json_neigh, "remoteAs", p->as);
13094
13095 if (p->change_local_as)
13096 json_object_int_add(json_neigh, "localAs",
13097 p->change_local_as);
13098 else
13099 json_object_int_add(json_neigh, "localAs", p->local_as);
13100
13101 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
13102 json_object_boolean_true_add(json_neigh,
13103 "localAsNoPrepend");
13104
13105 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
13106 json_object_boolean_true_add(json_neigh,
13107 "localAsReplaceAs");
13108 } else {
13109 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
13110 || (p->as_type == AS_INTERNAL))
13111 vty_out(vty, "remote AS %u, ", p->as);
13112 else
13113 vty_out(vty, "remote AS Unspecified, ");
13114 vty_out(vty, "local AS %u%s%s, ",
13115 p->change_local_as ? p->change_local_as : p->local_as,
13116 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
13117 ? " no-prepend"
13118 : "",
13119 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
13120 ? " replace-as"
13121 : "");
13122 }
13123 /* peer type internal or confed-internal */
13124 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
13125 if (use_json) {
13126 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
13127 json_object_boolean_true_add(
13128 json_neigh, "nbrConfedInternalLink");
13129 else
13130 json_object_boolean_true_add(json_neigh,
13131 "nbrInternalLink");
13132 } else {
13133 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
13134 vty_out(vty, "confed-internal link\n");
13135 else
13136 vty_out(vty, "internal link\n");
13137 }
13138 /* peer type external or confed-external */
13139 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
13140 if (use_json) {
13141 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
13142 json_object_boolean_true_add(
13143 json_neigh, "nbrConfedExternalLink");
13144 else
13145 json_object_boolean_true_add(json_neigh,
13146 "nbrExternalLink");
13147 } else {
13148 if (bgp_confederation_peers_check(bgp, p->as))
13149 vty_out(vty, "confed-external link\n");
13150 else
13151 vty_out(vty, "external link\n");
13152 }
13153 } else {
13154 if (use_json)
13155 json_object_boolean_true_add(json_neigh,
13156 "nbrUnspecifiedLink");
13157 else
13158 vty_out(vty, "unspecified link\n");
13159 }
13160
13161 /* Description. */
13162 if (p->desc) {
13163 if (use_json)
13164 json_object_string_add(json_neigh, "nbrDesc", p->desc);
13165 else
13166 vty_out(vty, " Description: %s\n", p->desc);
13167 }
13168
13169 if (p->hostname) {
13170 if (use_json) {
13171 if (p->hostname)
13172 json_object_string_add(json_neigh, "hostname",
13173 p->hostname);
13174
13175 if (p->domainname)
13176 json_object_string_add(json_neigh, "domainname",
13177 p->domainname);
13178 } else {
13179 if (p->domainname && (p->domainname[0] != '\0'))
13180 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
13181 p->domainname);
13182 else
13183 vty_out(vty, "Hostname: %s\n", p->hostname);
13184 }
13185 }
13186
13187 /* Peer-group */
13188 if (p->group) {
13189 if (use_json) {
13190 json_object_string_add(json_neigh, "peerGroup",
13191 p->group->name);
13192
13193 if (dn_flag[0]) {
13194 struct prefix prefix, *range = NULL;
13195
13196 if (sockunion2hostprefix(&(p->su), &prefix))
13197 range = peer_group_lookup_dynamic_neighbor_range(
13198 p->group, &prefix);
13199
13200 if (range) {
13201 prefix2str(range, buf1, sizeof(buf1));
13202 json_object_string_add(
13203 json_neigh,
13204 "peerSubnetRangeGroup", buf1);
13205 }
13206 }
13207 } else {
13208 vty_out(vty,
13209 " Member of peer-group %s for session parameters\n",
13210 p->group->name);
13211
13212 if (dn_flag[0]) {
13213 struct prefix prefix, *range = NULL;
13214
13215 if (sockunion2hostprefix(&(p->su), &prefix))
13216 range = peer_group_lookup_dynamic_neighbor_range(
13217 p->group, &prefix);
13218
13219 if (range) {
13220 vty_out(vty,
13221 " Belongs to the subnet range group: %pFX\n",
13222 range);
13223 }
13224 }
13225 }
13226 }
13227
13228 if (use_json) {
13229 /* Administrative shutdown. */
13230 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
13231 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
13232 json_object_boolean_true_add(json_neigh,
13233 "adminShutDown");
13234
13235 /* BGP Version. */
13236 json_object_int_add(json_neigh, "bgpVersion", 4);
13237 json_object_string_add(
13238 json_neigh, "remoteRouterId",
13239 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
13240 json_object_string_add(
13241 json_neigh, "localRouterId",
13242 inet_ntop(AF_INET, &bgp->router_id, buf1,
13243 sizeof(buf1)));
13244
13245 /* Confederation */
13246 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
13247 && bgp_confederation_peers_check(bgp, p->as))
13248 json_object_boolean_true_add(json_neigh,
13249 "nbrCommonAdmin");
13250
13251 /* Status. */
13252 json_object_string_add(
13253 json_neigh, "bgpState",
13254 lookup_msg(bgp_status_msg, p->status, NULL));
13255
13256 if (peer_established(p)) {
13257 time_t uptime;
13258
13259 uptime = bgp_clock();
13260 uptime -= p->uptime;
13261 epoch_tbuf = time(NULL) - uptime;
13262
13263 json_object_int_add(json_neigh, "bgpTimerUpMsec",
13264 uptime * 1000);
13265 json_object_string_add(json_neigh, "bgpTimerUpString",
13266 peer_uptime(p->uptime, timebuf,
13267 BGP_UPTIME_LEN, 0,
13268 NULL));
13269 json_object_int_add(json_neigh,
13270 "bgpTimerUpEstablishedEpoch",
13271 epoch_tbuf);
13272 }
13273
13274 else if (p->status == Active) {
13275 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
13276 json_object_string_add(json_neigh, "bgpStateIs",
13277 "passive");
13278 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
13279 json_object_string_add(json_neigh, "bgpStateIs",
13280 "passiveNSF");
13281 }
13282
13283 /* read timer */
13284 time_t uptime;
13285 struct tm tm;
13286
13287 uptime = bgp_clock();
13288 uptime -= p->readtime;
13289 gmtime_r(&uptime, &tm);
13290
13291 json_object_int_add(json_neigh, "bgpTimerLastRead",
13292 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
13293 + (tm.tm_hour * 3600000));
13294
13295 uptime = bgp_clock();
13296 uptime -= p->last_write;
13297 gmtime_r(&uptime, &tm);
13298
13299 json_object_int_add(json_neigh, "bgpTimerLastWrite",
13300 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
13301 + (tm.tm_hour * 3600000));
13302
13303 uptime = bgp_clock();
13304 uptime -= p->update_time;
13305 gmtime_r(&uptime, &tm);
13306
13307 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
13308 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
13309 + (tm.tm_hour * 3600000));
13310
13311 /* Configured timer values. */
13312 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
13313 p->v_holdtime * 1000);
13314 json_object_int_add(json_neigh,
13315 "bgpTimerKeepAliveIntervalMsecs",
13316 p->v_keepalive * 1000);
13317 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN)) {
13318 json_object_int_add(json_neigh,
13319 "bgpTimerDelayOpenTimeMsecs",
13320 p->v_delayopen * 1000);
13321 }
13322
13323 /* Configured and Synced tcp-mss value for peer */
13324 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
13325 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
13326 json_object_int_add(json_neigh, "bgpTcpMssConfigured",
13327 p->tcp_mss);
13328 json_object_int_add(json_neigh, "bgpTcpMssSynced",
13329 sync_tcp_mss);
13330 }
13331
13332 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
13333 json_object_int_add(json_neigh,
13334 "bgpTimerConfiguredHoldTimeMsecs",
13335 p->holdtime * 1000);
13336 json_object_int_add(
13337 json_neigh,
13338 "bgpTimerConfiguredKeepAliveIntervalMsecs",
13339 p->keepalive * 1000);
13340 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
13341 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
13342 json_object_int_add(json_neigh,
13343 "bgpTimerConfiguredHoldTimeMsecs",
13344 bgp->default_holdtime);
13345 json_object_int_add(
13346 json_neigh,
13347 "bgpTimerConfiguredKeepAliveIntervalMsecs",
13348 bgp->default_keepalive);
13349 }
13350 } else {
13351 /* Administrative shutdown. */
13352 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
13353 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
13354 vty_out(vty, " Administratively shut down\n");
13355
13356 /* BGP Version. */
13357 vty_out(vty, " BGP version 4");
13358 vty_out(vty, ", remote router ID %s",
13359 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
13360 vty_out(vty, ", local router ID %s\n",
13361 inet_ntop(AF_INET, &bgp->router_id, buf1,
13362 sizeof(buf1)));
13363
13364 /* Confederation */
13365 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
13366 && bgp_confederation_peers_check(bgp, p->as))
13367 vty_out(vty,
13368 " Neighbor under common administration\n");
13369
13370 /* Status. */
13371 vty_out(vty, " BGP state = %s",
13372 lookup_msg(bgp_status_msg, p->status, NULL));
13373
13374 if (peer_established(p))
13375 vty_out(vty, ", up for %8s",
13376 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
13377 0, NULL));
13378
13379 else if (p->status == Active) {
13380 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
13381 vty_out(vty, " (passive)");
13382 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
13383 vty_out(vty, " (NSF passive)");
13384 }
13385 vty_out(vty, "\n");
13386
13387 /* read timer */
13388 vty_out(vty, " Last read %s",
13389 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
13390 NULL));
13391 vty_out(vty, ", Last write %s\n",
13392 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
13393 NULL));
13394
13395 /* Configured timer values. */
13396 vty_out(vty,
13397 " Hold time is %d, keepalive interval is %d seconds\n",
13398 p->v_holdtime, p->v_keepalive);
13399 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
13400 vty_out(vty, " Configured hold time is %d",
13401 p->holdtime);
13402 vty_out(vty, ", keepalive interval is %d seconds\n",
13403 p->keepalive);
13404 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
13405 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
13406 vty_out(vty, " Configured hold time is %d",
13407 bgp->default_holdtime);
13408 vty_out(vty, ", keepalive interval is %d seconds\n",
13409 bgp->default_keepalive);
13410 }
13411 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN))
13412 vty_out(vty,
13413 " Configured DelayOpenTime is %d seconds\n",
13414 p->delayopen);
13415
13416 /* Configured and synced tcp-mss value for peer */
13417 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
13418 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
13419 vty_out(vty, " Configured tcp-mss is %d", p->tcp_mss);
13420 vty_out(vty, ", synced tcp-mss is %d\n", sync_tcp_mss);
13421 }
13422 }
13423 /* Capability. */
13424 if (peer_established(p)) {
13425 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
13426 || p->afc_recv[AFI_IP][SAFI_UNICAST]
13427 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
13428 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
13429 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
13430 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
13431 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
13432 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
13433 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
13434 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
13435 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
13436 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
13437 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
13438 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
13439 || p->afc_adv[AFI_IP][SAFI_ENCAP]
13440 || p->afc_recv[AFI_IP][SAFI_ENCAP]
13441 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
13442 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
13443 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
13444 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
13445 if (use_json) {
13446 json_object *json_cap = NULL;
13447
13448 json_cap = json_object_new_object();
13449
13450 /* AS4 */
13451 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
13452 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13453 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
13454 && CHECK_FLAG(p->cap,
13455 PEER_CAP_AS4_RCV))
13456 json_object_string_add(
13457 json_cap, "4byteAs",
13458 "advertisedAndReceived");
13459 else if (CHECK_FLAG(p->cap,
13460 PEER_CAP_AS4_ADV))
13461 json_object_string_add(
13462 json_cap, "4byteAs",
13463 "advertised");
13464 else if (CHECK_FLAG(p->cap,
13465 PEER_CAP_AS4_RCV))
13466 json_object_string_add(
13467 json_cap, "4byteAs",
13468 "received");
13469 }
13470
13471 /* Extended Message Support */
13472 if (CHECK_FLAG(p->cap,
13473 PEER_CAP_EXTENDED_MESSAGE_ADV)
13474 && CHECK_FLAG(
13475 p->cap,
13476 PEER_CAP_EXTENDED_MESSAGE_RCV))
13477 json_object_string_add(
13478 json_cap, "extendedMessage",
13479 "advertisedAndReceived");
13480 else if (CHECK_FLAG(
13481 p->cap,
13482 PEER_CAP_EXTENDED_MESSAGE_ADV))
13483 json_object_string_add(
13484 json_cap, "extendedMessage",
13485 "advertised");
13486 else if (CHECK_FLAG(
13487 p->cap,
13488 PEER_CAP_EXTENDED_MESSAGE_RCV))
13489 json_object_string_add(
13490 json_cap, "extendedMessage",
13491 "received");
13492
13493 /* AddPath */
13494 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
13495 || CHECK_FLAG(p->cap,
13496 PEER_CAP_ADDPATH_ADV)) {
13497 json_object *json_add = NULL;
13498 const char *print_store;
13499
13500 json_add = json_object_new_object();
13501
13502 FOREACH_AFI_SAFI (afi, safi) {
13503 json_object *json_sub = NULL;
13504 json_sub =
13505 json_object_new_object();
13506 print_store = get_afi_safi_str(
13507 afi, safi, true);
13508
13509 if (CHECK_FLAG(
13510 p->af_cap[afi]
13511 [safi],
13512 PEER_CAP_ADDPATH_AF_TX_ADV)
13513 || CHECK_FLAG(
13514 p->af_cap[afi]
13515 [safi],
13516 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13517 if (CHECK_FLAG(
13518 p->af_cap
13519 [afi]
13520 [safi],
13521 PEER_CAP_ADDPATH_AF_TX_ADV)
13522 && CHECK_FLAG(
13523 p->af_cap
13524 [afi]
13525 [safi],
13526 PEER_CAP_ADDPATH_AF_TX_RCV))
13527 json_object_boolean_true_add(
13528 json_sub,
13529 "txAdvertisedAndReceived");
13530 else if (
13531 CHECK_FLAG(
13532 p->af_cap
13533 [afi]
13534 [safi],
13535 PEER_CAP_ADDPATH_AF_TX_ADV))
13536 json_object_boolean_true_add(
13537 json_sub,
13538 "txAdvertised");
13539 else if (
13540 CHECK_FLAG(
13541 p->af_cap
13542 [afi]
13543 [safi],
13544 PEER_CAP_ADDPATH_AF_TX_RCV))
13545 json_object_boolean_true_add(
13546 json_sub,
13547 "txReceived");
13548 }
13549
13550 if (CHECK_FLAG(
13551 p->af_cap[afi]
13552 [safi],
13553 PEER_CAP_ADDPATH_AF_RX_ADV)
13554 || CHECK_FLAG(
13555 p->af_cap[afi]
13556 [safi],
13557 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13558 if (CHECK_FLAG(
13559 p->af_cap
13560 [afi]
13561 [safi],
13562 PEER_CAP_ADDPATH_AF_RX_ADV)
13563 && CHECK_FLAG(
13564 p->af_cap
13565 [afi]
13566 [safi],
13567 PEER_CAP_ADDPATH_AF_RX_RCV))
13568 json_object_boolean_true_add(
13569 json_sub,
13570 "rxAdvertisedAndReceived");
13571 else if (
13572 CHECK_FLAG(
13573 p->af_cap
13574 [afi]
13575 [safi],
13576 PEER_CAP_ADDPATH_AF_RX_ADV))
13577 json_object_boolean_true_add(
13578 json_sub,
13579 "rxAdvertised");
13580 else if (
13581 CHECK_FLAG(
13582 p->af_cap
13583 [afi]
13584 [safi],
13585 PEER_CAP_ADDPATH_AF_RX_RCV))
13586 json_object_boolean_true_add(
13587 json_sub,
13588 "rxReceived");
13589 }
13590
13591 if (CHECK_FLAG(
13592 p->af_cap[afi]
13593 [safi],
13594 PEER_CAP_ADDPATH_AF_TX_ADV)
13595 || CHECK_FLAG(
13596 p->af_cap[afi]
13597 [safi],
13598 PEER_CAP_ADDPATH_AF_TX_RCV)
13599 || CHECK_FLAG(
13600 p->af_cap[afi]
13601 [safi],
13602 PEER_CAP_ADDPATH_AF_RX_ADV)
13603 || CHECK_FLAG(
13604 p->af_cap[afi]
13605 [safi],
13606 PEER_CAP_ADDPATH_AF_RX_RCV))
13607 json_object_object_add(
13608 json_add,
13609 print_store,
13610 json_sub);
13611 else
13612 json_object_free(
13613 json_sub);
13614 }
13615
13616 json_object_object_add(
13617 json_cap, "addPath", json_add);
13618 }
13619
13620 /* Dynamic */
13621 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
13622 || CHECK_FLAG(p->cap,
13623 PEER_CAP_DYNAMIC_ADV)) {
13624 if (CHECK_FLAG(p->cap,
13625 PEER_CAP_DYNAMIC_ADV)
13626 && CHECK_FLAG(p->cap,
13627 PEER_CAP_DYNAMIC_RCV))
13628 json_object_string_add(
13629 json_cap, "dynamic",
13630 "advertisedAndReceived");
13631 else if (CHECK_FLAG(
13632 p->cap,
13633 PEER_CAP_DYNAMIC_ADV))
13634 json_object_string_add(
13635 json_cap, "dynamic",
13636 "advertised");
13637 else if (CHECK_FLAG(
13638 p->cap,
13639 PEER_CAP_DYNAMIC_RCV))
13640 json_object_string_add(
13641 json_cap, "dynamic",
13642 "received");
13643 }
13644
13645 /* Extended nexthop */
13646 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
13647 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13648 json_object *json_nxt = NULL;
13649 const char *print_store;
13650
13651
13652 if (CHECK_FLAG(p->cap,
13653 PEER_CAP_ENHE_ADV)
13654 && CHECK_FLAG(p->cap,
13655 PEER_CAP_ENHE_RCV))
13656 json_object_string_add(
13657 json_cap,
13658 "extendedNexthop",
13659 "advertisedAndReceived");
13660 else if (CHECK_FLAG(p->cap,
13661 PEER_CAP_ENHE_ADV))
13662 json_object_string_add(
13663 json_cap,
13664 "extendedNexthop",
13665 "advertised");
13666 else if (CHECK_FLAG(p->cap,
13667 PEER_CAP_ENHE_RCV))
13668 json_object_string_add(
13669 json_cap,
13670 "extendedNexthop",
13671 "received");
13672
13673 if (CHECK_FLAG(p->cap,
13674 PEER_CAP_ENHE_RCV)) {
13675 json_nxt =
13676 json_object_new_object();
13677
13678 for (safi = SAFI_UNICAST;
13679 safi < SAFI_MAX; safi++) {
13680 if (CHECK_FLAG(
13681 p->af_cap
13682 [AFI_IP]
13683 [safi],
13684 PEER_CAP_ENHE_AF_RCV)) {
13685 print_store = get_afi_safi_str(
13686 AFI_IP,
13687 safi, true);
13688 json_object_string_add(
13689 json_nxt,
13690 print_store,
13691 "recieved"); /* misspelled for compatibility */
13692 }
13693 }
13694 json_object_object_add(
13695 json_cap,
13696 "extendedNexthopFamililesByPeer",
13697 json_nxt);
13698 }
13699 }
13700
13701 /* Route Refresh */
13702 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
13703 || CHECK_FLAG(p->cap,
13704 PEER_CAP_REFRESH_NEW_RCV)
13705 || CHECK_FLAG(p->cap,
13706 PEER_CAP_REFRESH_OLD_RCV)) {
13707 if (CHECK_FLAG(p->cap,
13708 PEER_CAP_REFRESH_ADV)
13709 && (CHECK_FLAG(
13710 p->cap,
13711 PEER_CAP_REFRESH_NEW_RCV)
13712 || CHECK_FLAG(
13713 p->cap,
13714 PEER_CAP_REFRESH_OLD_RCV))) {
13715 if (CHECK_FLAG(
13716 p->cap,
13717 PEER_CAP_REFRESH_OLD_RCV)
13718 && CHECK_FLAG(
13719 p->cap,
13720 PEER_CAP_REFRESH_NEW_RCV))
13721 json_object_string_add(
13722 json_cap,
13723 "routeRefresh",
13724 "advertisedAndReceivedOldNew");
13725 else {
13726 if (CHECK_FLAG(
13727 p->cap,
13728 PEER_CAP_REFRESH_OLD_RCV))
13729 json_object_string_add(
13730 json_cap,
13731 "routeRefresh",
13732 "advertisedAndReceivedOld");
13733 else
13734 json_object_string_add(
13735 json_cap,
13736 "routeRefresh",
13737 "advertisedAndReceivedNew");
13738 }
13739 } else if (
13740 CHECK_FLAG(
13741 p->cap,
13742 PEER_CAP_REFRESH_ADV))
13743 json_object_string_add(
13744 json_cap,
13745 "routeRefresh",
13746 "advertised");
13747 else if (
13748 CHECK_FLAG(
13749 p->cap,
13750 PEER_CAP_REFRESH_NEW_RCV)
13751 || CHECK_FLAG(
13752 p->cap,
13753 PEER_CAP_REFRESH_OLD_RCV))
13754 json_object_string_add(
13755 json_cap,
13756 "routeRefresh",
13757 "received");
13758 }
13759
13760 /* Enhanced Route Refresh */
13761 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV)
13762 || CHECK_FLAG(p->cap,
13763 PEER_CAP_ENHANCED_RR_RCV)) {
13764 if (CHECK_FLAG(p->cap,
13765 PEER_CAP_ENHANCED_RR_ADV)
13766 && CHECK_FLAG(
13767 p->cap,
13768 PEER_CAP_ENHANCED_RR_RCV))
13769 json_object_string_add(
13770 json_cap,
13771 "enhancedRouteRefresh",
13772 "advertisedAndReceived");
13773 else if (
13774 CHECK_FLAG(
13775 p->cap,
13776 PEER_CAP_ENHANCED_RR_ADV))
13777 json_object_string_add(
13778 json_cap,
13779 "enhancedRouteRefresh",
13780 "advertised");
13781 else if (
13782 CHECK_FLAG(
13783 p->cap,
13784 PEER_CAP_ENHANCED_RR_RCV))
13785 json_object_string_add(
13786 json_cap,
13787 "enhancedRouteRefresh",
13788 "received");
13789 }
13790
13791 /* Multiprotocol Extensions */
13792 json_object *json_multi = NULL;
13793 json_multi = json_object_new_object();
13794
13795 FOREACH_AFI_SAFI (afi, safi) {
13796 if (p->afc_adv[afi][safi]
13797 || p->afc_recv[afi][safi]) {
13798 json_object *json_exten = NULL;
13799 json_exten =
13800 json_object_new_object();
13801
13802 if (p->afc_adv[afi][safi]
13803 && p->afc_recv[afi][safi])
13804 json_object_boolean_true_add(
13805 json_exten,
13806 "advertisedAndReceived");
13807 else if (p->afc_adv[afi][safi])
13808 json_object_boolean_true_add(
13809 json_exten,
13810 "advertised");
13811 else if (p->afc_recv[afi][safi])
13812 json_object_boolean_true_add(
13813 json_exten,
13814 "received");
13815
13816 json_object_object_add(
13817 json_multi,
13818 get_afi_safi_str(afi,
13819 safi,
13820 true),
13821 json_exten);
13822 }
13823 }
13824 json_object_object_add(
13825 json_cap, "multiprotocolExtensions",
13826 json_multi);
13827
13828 /* Hostname capabilities */
13829 json_object *json_hname = NULL;
13830
13831 json_hname = json_object_new_object();
13832
13833 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13834 json_object_string_add(
13835 json_hname, "advHostName",
13836 bgp->peer_self->hostname
13837 ? bgp->peer_self
13838 ->hostname
13839 : "n/a");
13840 json_object_string_add(
13841 json_hname, "advDomainName",
13842 bgp->peer_self->domainname
13843 ? bgp->peer_self
13844 ->domainname
13845 : "n/a");
13846 }
13847
13848
13849 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13850 json_object_string_add(
13851 json_hname, "rcvHostName",
13852 p->hostname ? p->hostname
13853 : "n/a");
13854 json_object_string_add(
13855 json_hname, "rcvDomainName",
13856 p->domainname ? p->domainname
13857 : "n/a");
13858 }
13859
13860 json_object_object_add(json_cap, "hostName",
13861 json_hname);
13862
13863 /* Gracefull Restart */
13864 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
13865 || CHECK_FLAG(p->cap,
13866 PEER_CAP_RESTART_ADV)) {
13867 if (CHECK_FLAG(p->cap,
13868 PEER_CAP_RESTART_ADV)
13869 && CHECK_FLAG(p->cap,
13870 PEER_CAP_RESTART_RCV))
13871 json_object_string_add(
13872 json_cap,
13873 "gracefulRestart",
13874 "advertisedAndReceived");
13875 else if (CHECK_FLAG(
13876 p->cap,
13877 PEER_CAP_RESTART_ADV))
13878 json_object_string_add(
13879 json_cap,
13880 "gracefulRestartCapability",
13881 "advertised");
13882 else if (CHECK_FLAG(
13883 p->cap,
13884 PEER_CAP_RESTART_RCV))
13885 json_object_string_add(
13886 json_cap,
13887 "gracefulRestartCapability",
13888 "received");
13889
13890 if (CHECK_FLAG(p->cap,
13891 PEER_CAP_RESTART_RCV)) {
13892 int restart_af_count = 0;
13893 json_object *json_restart =
13894 NULL;
13895 json_restart =
13896 json_object_new_object();
13897
13898 json_object_int_add(
13899 json_cap,
13900 "gracefulRestartRemoteTimerMsecs",
13901 p->v_gr_restart * 1000);
13902
13903 FOREACH_AFI_SAFI (afi, safi) {
13904 if (CHECK_FLAG(
13905 p->af_cap
13906 [afi]
13907 [safi],
13908 PEER_CAP_RESTART_AF_RCV)) {
13909 json_object *
13910 json_sub =
13911 NULL;
13912 json_sub =
13913 json_object_new_object();
13914
13915 if (CHECK_FLAG(
13916 p->af_cap
13917 [afi]
13918 [safi],
13919 PEER_CAP_RESTART_AF_PRESERVE_RCV))
13920 json_object_boolean_true_add(
13921 json_sub,
13922 "preserved");
13923 restart_af_count++;
13924 json_object_object_add(
13925 json_restart,
13926 get_afi_safi_str(
13927 afi,
13928 safi,
13929 true),
13930 json_sub);
13931 }
13932 }
13933 if (!restart_af_count) {
13934 json_object_string_add(
13935 json_cap,
13936 "addressFamiliesByPeer",
13937 "none");
13938 json_object_free(
13939 json_restart);
13940 } else
13941 json_object_object_add(
13942 json_cap,
13943 "addressFamiliesByPeer",
13944 json_restart);
13945 }
13946 }
13947 json_object_object_add(json_neigh,
13948 "neighborCapabilities",
13949 json_cap);
13950 } else {
13951 vty_out(vty, " Neighbor capabilities:\n");
13952
13953 /* AS4 */
13954 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
13955 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13956 vty_out(vty, " 4 Byte AS:");
13957 if (CHECK_FLAG(p->cap,
13958 PEER_CAP_AS4_ADV))
13959 vty_out(vty, " advertised");
13960 if (CHECK_FLAG(p->cap,
13961 PEER_CAP_AS4_RCV))
13962 vty_out(vty, " %sreceived",
13963 CHECK_FLAG(
13964 p->cap,
13965 PEER_CAP_AS4_ADV)
13966 ? "and "
13967 : "");
13968 vty_out(vty, "\n");
13969 }
13970
13971 /* Extended Message Support */
13972 if (CHECK_FLAG(p->cap,
13973 PEER_CAP_EXTENDED_MESSAGE_RCV)
13974 || CHECK_FLAG(
13975 p->cap,
13976 PEER_CAP_EXTENDED_MESSAGE_ADV)) {
13977 vty_out(vty, " Extended Message:");
13978 if (CHECK_FLAG(
13979 p->cap,
13980 PEER_CAP_EXTENDED_MESSAGE_ADV))
13981 vty_out(vty, " advertised");
13982 if (CHECK_FLAG(
13983 p->cap,
13984 PEER_CAP_EXTENDED_MESSAGE_RCV))
13985 vty_out(vty, " %sreceived",
13986 CHECK_FLAG(
13987 p->cap,
13988 PEER_CAP_EXTENDED_MESSAGE_ADV)
13989 ? "and "
13990 : "");
13991 vty_out(vty, "\n");
13992 }
13993
13994 /* AddPath */
13995 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
13996 || CHECK_FLAG(p->cap,
13997 PEER_CAP_ADDPATH_ADV)) {
13998 vty_out(vty, " AddPath:\n");
13999
14000 FOREACH_AFI_SAFI (afi, safi) {
14001 if (CHECK_FLAG(
14002 p->af_cap[afi]
14003 [safi],
14004 PEER_CAP_ADDPATH_AF_TX_ADV)
14005 || CHECK_FLAG(
14006 p->af_cap[afi]
14007 [safi],
14008 PEER_CAP_ADDPATH_AF_TX_RCV)) {
14009 vty_out(vty,
14010 " %s: TX ",
14011 get_afi_safi_str(
14012 afi,
14013 safi,
14014 false));
14015
14016 if (CHECK_FLAG(
14017 p->af_cap
14018 [afi]
14019 [safi],
14020 PEER_CAP_ADDPATH_AF_TX_ADV))
14021 vty_out(vty,
14022 "advertised %s",
14023 get_afi_safi_str(
14024 afi,
14025 safi,
14026 false));
14027
14028 if (CHECK_FLAG(
14029 p->af_cap
14030 [afi]
14031 [safi],
14032 PEER_CAP_ADDPATH_AF_TX_RCV))
14033 vty_out(vty,
14034 "%sreceived",
14035 CHECK_FLAG(
14036 p->af_cap
14037 [afi]
14038 [safi],
14039 PEER_CAP_ADDPATH_AF_TX_ADV)
14040 ? " and "
14041 : "");
14042
14043 vty_out(vty, "\n");
14044 }
14045
14046 if (CHECK_FLAG(
14047 p->af_cap[afi]
14048 [safi],
14049 PEER_CAP_ADDPATH_AF_RX_ADV)
14050 || CHECK_FLAG(
14051 p->af_cap[afi]
14052 [safi],
14053 PEER_CAP_ADDPATH_AF_RX_RCV)) {
14054 vty_out(vty,
14055 " %s: RX ",
14056 get_afi_safi_str(
14057 afi,
14058 safi,
14059 false));
14060
14061 if (CHECK_FLAG(
14062 p->af_cap
14063 [afi]
14064 [safi],
14065 PEER_CAP_ADDPATH_AF_RX_ADV))
14066 vty_out(vty,
14067 "advertised %s",
14068 get_afi_safi_str(
14069 afi,
14070 safi,
14071 false));
14072
14073 if (CHECK_FLAG(
14074 p->af_cap
14075 [afi]
14076 [safi],
14077 PEER_CAP_ADDPATH_AF_RX_RCV))
14078 vty_out(vty,
14079 "%sreceived",
14080 CHECK_FLAG(
14081 p->af_cap
14082 [afi]
14083 [safi],
14084 PEER_CAP_ADDPATH_AF_RX_ADV)
14085 ? " and "
14086 : "");
14087
14088 vty_out(vty, "\n");
14089 }
14090 }
14091 }
14092
14093 /* Dynamic */
14094 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
14095 || CHECK_FLAG(p->cap,
14096 PEER_CAP_DYNAMIC_ADV)) {
14097 vty_out(vty, " Dynamic:");
14098 if (CHECK_FLAG(p->cap,
14099 PEER_CAP_DYNAMIC_ADV))
14100 vty_out(vty, " advertised");
14101 if (CHECK_FLAG(p->cap,
14102 PEER_CAP_DYNAMIC_RCV))
14103 vty_out(vty, " %sreceived",
14104 CHECK_FLAG(
14105 p->cap,
14106 PEER_CAP_DYNAMIC_ADV)
14107 ? "and "
14108 : "");
14109 vty_out(vty, "\n");
14110 }
14111
14112 /* Extended nexthop */
14113 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
14114 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
14115 vty_out(vty, " Extended nexthop:");
14116 if (CHECK_FLAG(p->cap,
14117 PEER_CAP_ENHE_ADV))
14118 vty_out(vty, " advertised");
14119 if (CHECK_FLAG(p->cap,
14120 PEER_CAP_ENHE_RCV))
14121 vty_out(vty, " %sreceived",
14122 CHECK_FLAG(
14123 p->cap,
14124 PEER_CAP_ENHE_ADV)
14125 ? "and "
14126 : "");
14127 vty_out(vty, "\n");
14128
14129 if (CHECK_FLAG(p->cap,
14130 PEER_CAP_ENHE_RCV)) {
14131 vty_out(vty,
14132 " Address families by peer:\n ");
14133 for (safi = SAFI_UNICAST;
14134 safi < SAFI_MAX; safi++)
14135 if (CHECK_FLAG(
14136 p->af_cap
14137 [AFI_IP]
14138 [safi],
14139 PEER_CAP_ENHE_AF_RCV))
14140 vty_out(vty,
14141 " %s\n",
14142 get_afi_safi_str(
14143 AFI_IP,
14144 safi,
14145 false));
14146 }
14147 }
14148
14149 /* Route Refresh */
14150 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
14151 || CHECK_FLAG(p->cap,
14152 PEER_CAP_REFRESH_NEW_RCV)
14153 || CHECK_FLAG(p->cap,
14154 PEER_CAP_REFRESH_OLD_RCV)) {
14155 vty_out(vty, " Route refresh:");
14156 if (CHECK_FLAG(p->cap,
14157 PEER_CAP_REFRESH_ADV))
14158 vty_out(vty, " advertised");
14159 if (CHECK_FLAG(p->cap,
14160 PEER_CAP_REFRESH_NEW_RCV)
14161 || CHECK_FLAG(
14162 p->cap,
14163 PEER_CAP_REFRESH_OLD_RCV))
14164 vty_out(vty, " %sreceived(%s)",
14165 CHECK_FLAG(
14166 p->cap,
14167 PEER_CAP_REFRESH_ADV)
14168 ? "and "
14169 : "",
14170 (CHECK_FLAG(
14171 p->cap,
14172 PEER_CAP_REFRESH_OLD_RCV)
14173 && CHECK_FLAG(
14174 p->cap,
14175 PEER_CAP_REFRESH_NEW_RCV))
14176 ? "old & new"
14177 : CHECK_FLAG(
14178 p->cap,
14179 PEER_CAP_REFRESH_OLD_RCV)
14180 ? "old"
14181 : "new");
14182
14183 vty_out(vty, "\n");
14184 }
14185
14186 /* Enhanced Route Refresh */
14187 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV)
14188 || CHECK_FLAG(p->cap,
14189 PEER_CAP_ENHANCED_RR_RCV)) {
14190 vty_out(vty,
14191 " Enhanced Route Refresh:");
14192 if (CHECK_FLAG(
14193 p->cap,
14194 PEER_CAP_ENHANCED_RR_ADV))
14195 vty_out(vty, " advertised");
14196 if (CHECK_FLAG(
14197 p->cap,
14198 PEER_CAP_ENHANCED_RR_RCV))
14199 vty_out(vty, " %sreceived",
14200 CHECK_FLAG(
14201 p->cap,
14202 PEER_CAP_REFRESH_ADV)
14203 ? "and "
14204 : "");
14205 vty_out(vty, "\n");
14206 }
14207
14208 /* Multiprotocol Extensions */
14209 FOREACH_AFI_SAFI (afi, safi)
14210 if (p->afc_adv[afi][safi]
14211 || p->afc_recv[afi][safi]) {
14212 vty_out(vty,
14213 " Address Family %s:",
14214 get_afi_safi_str(
14215 afi,
14216 safi,
14217 false));
14218 if (p->afc_adv[afi][safi])
14219 vty_out(vty,
14220 " advertised");
14221 if (p->afc_recv[afi][safi])
14222 vty_out(vty,
14223 " %sreceived",
14224 p->afc_adv[afi]
14225 [safi]
14226 ? "and "
14227 : "");
14228 vty_out(vty, "\n");
14229 }
14230
14231 /* Hostname capability */
14232 vty_out(vty, " Hostname Capability:");
14233
14234 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
14235 vty_out(vty,
14236 " advertised (name: %s,domain name: %s)",
14237 bgp->peer_self->hostname
14238 ? bgp->peer_self
14239 ->hostname
14240 : "n/a",
14241 bgp->peer_self->domainname
14242 ? bgp->peer_self
14243 ->domainname
14244 : "n/a");
14245 } else {
14246 vty_out(vty, " not advertised");
14247 }
14248
14249 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
14250 vty_out(vty,
14251 " received (name: %s,domain name: %s)",
14252 p->hostname ? p->hostname
14253 : "n/a",
14254 p->domainname ? p->domainname
14255 : "n/a");
14256 } else {
14257 vty_out(vty, " not received");
14258 }
14259
14260 vty_out(vty, "\n");
14261
14262 /* Graceful Restart */
14263 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
14264 || CHECK_FLAG(p->cap,
14265 PEER_CAP_RESTART_ADV)) {
14266 vty_out(vty,
14267 " Graceful Restart Capability:");
14268 if (CHECK_FLAG(p->cap,
14269 PEER_CAP_RESTART_ADV))
14270 vty_out(vty, " advertised");
14271 if (CHECK_FLAG(p->cap,
14272 PEER_CAP_RESTART_RCV))
14273 vty_out(vty, " %sreceived",
14274 CHECK_FLAG(
14275 p->cap,
14276 PEER_CAP_RESTART_ADV)
14277 ? "and "
14278 : "");
14279 vty_out(vty, "\n");
14280
14281 if (CHECK_FLAG(p->cap,
14282 PEER_CAP_RESTART_RCV)) {
14283 int restart_af_count = 0;
14284
14285 vty_out(vty,
14286 " Remote Restart timer is %d seconds\n",
14287 p->v_gr_restart);
14288 vty_out(vty,
14289 " Address families by peer:\n ");
14290
14291 FOREACH_AFI_SAFI (afi, safi)
14292 if (CHECK_FLAG(
14293 p->af_cap
14294 [afi]
14295 [safi],
14296 PEER_CAP_RESTART_AF_RCV)) {
14297 vty_out(vty,
14298 "%s%s(%s)",
14299 restart_af_count
14300 ? ", "
14301 : "",
14302 get_afi_safi_str(
14303 afi,
14304 safi,
14305 false),
14306 CHECK_FLAG(
14307 p->af_cap
14308 [afi]
14309 [safi],
14310 PEER_CAP_RESTART_AF_PRESERVE_RCV)
14311 ? "preserved"
14312 : "not preserved");
14313 restart_af_count++;
14314 }
14315 if (!restart_af_count)
14316 vty_out(vty, "none");
14317 vty_out(vty, "\n");
14318 }
14319 } /* Gracefull Restart */
14320 }
14321 }
14322 }
14323
14324 /* graceful restart information */
14325 json_object *json_grace = NULL;
14326 json_object *json_grace_send = NULL;
14327 json_object *json_grace_recv = NULL;
14328 int eor_send_af_count = 0;
14329 int eor_receive_af_count = 0;
14330
14331 if (use_json) {
14332 json_grace = json_object_new_object();
14333 json_grace_send = json_object_new_object();
14334 json_grace_recv = json_object_new_object();
14335
14336 if ((peer_established(p))
14337 && CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
14338 FOREACH_AFI_SAFI (afi, safi) {
14339 if (CHECK_FLAG(p->af_sflags[afi][safi],
14340 PEER_STATUS_EOR_SEND)) {
14341 json_object_boolean_true_add(
14342 json_grace_send,
14343 get_afi_safi_str(afi,
14344 safi,
14345 true));
14346 eor_send_af_count++;
14347 }
14348 }
14349 FOREACH_AFI_SAFI (afi, safi) {
14350 if (CHECK_FLAG(
14351 p->af_sflags[afi][safi],
14352 PEER_STATUS_EOR_RECEIVED)) {
14353 json_object_boolean_true_add(
14354 json_grace_recv,
14355 get_afi_safi_str(afi,
14356 safi,
14357 true));
14358 eor_receive_af_count++;
14359 }
14360 }
14361 }
14362 json_object_object_add(json_grace, "endOfRibSend",
14363 json_grace_send);
14364 json_object_object_add(json_grace, "endOfRibRecv",
14365 json_grace_recv);
14366
14367
14368 if (p->t_gr_restart)
14369 json_object_int_add(json_grace,
14370 "gracefulRestartTimerMsecs",
14371 thread_timer_remain_second(
14372 p->t_gr_restart)
14373 * 1000);
14374
14375 if (p->t_gr_stale)
14376 json_object_int_add(
14377 json_grace,
14378 "gracefulStalepathTimerMsecs",
14379 thread_timer_remain_second(
14380 p->t_gr_stale)
14381 * 1000);
14382 /* more gr info in new format */
14383 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json,
14384 json_grace);
14385 json_object_object_add(
14386 json_neigh, "gracefulRestartInfo", json_grace);
14387 } else {
14388 vty_out(vty, " Graceful restart information:\n");
14389 if ((peer_established(p))
14390 && CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
14391
14392 vty_out(vty, " End-of-RIB send: ");
14393 FOREACH_AFI_SAFI (afi, safi) {
14394 if (CHECK_FLAG(p->af_sflags[afi][safi],
14395 PEER_STATUS_EOR_SEND)) {
14396 vty_out(vty, "%s%s",
14397 eor_send_af_count ? ", "
14398 : "",
14399 get_afi_safi_str(
14400 afi, safi,
14401 false));
14402 eor_send_af_count++;
14403 }
14404 }
14405 vty_out(vty, "\n");
14406 vty_out(vty, " End-of-RIB received: ");
14407 FOREACH_AFI_SAFI (afi, safi) {
14408 if (CHECK_FLAG(
14409 p->af_sflags[afi][safi],
14410 PEER_STATUS_EOR_RECEIVED)) {
14411 vty_out(vty, "%s%s",
14412 eor_receive_af_count
14413 ? ", "
14414 : "",
14415 get_afi_safi_str(afi,
14416 safi,
14417 false));
14418 eor_receive_af_count++;
14419 }
14420 }
14421 vty_out(vty, "\n");
14422 }
14423
14424 if (p->t_gr_restart)
14425 vty_out(vty,
14426 " The remaining time of restart timer is %ld\n",
14427 thread_timer_remain_second(
14428 p->t_gr_restart));
14429
14430 if (p->t_gr_stale)
14431 vty_out(vty,
14432 " The remaining time of stalepath timer is %ld\n",
14433 thread_timer_remain_second(
14434 p->t_gr_stale));
14435
14436 /* more gr info in new format */
14437 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, NULL);
14438 }
14439
14440 if (use_json) {
14441 json_object *json_stat = NULL;
14442 json_stat = json_object_new_object();
14443 /* Packet counts. */
14444
14445 atomic_size_t outq_count, inq_count;
14446 outq_count = atomic_load_explicit(&p->obuf->count,
14447 memory_order_relaxed);
14448 inq_count = atomic_load_explicit(&p->ibuf->count,
14449 memory_order_relaxed);
14450
14451 json_object_int_add(json_stat, "depthInq",
14452 (unsigned long)inq_count);
14453 json_object_int_add(json_stat, "depthOutq",
14454 (unsigned long)outq_count);
14455 json_object_int_add(json_stat, "opensSent",
14456 atomic_load_explicit(&p->open_out,
14457 memory_order_relaxed));
14458 json_object_int_add(json_stat, "opensRecv",
14459 atomic_load_explicit(&p->open_in,
14460 memory_order_relaxed));
14461 json_object_int_add(json_stat, "notificationsSent",
14462 atomic_load_explicit(&p->notify_out,
14463 memory_order_relaxed));
14464 json_object_int_add(json_stat, "notificationsRecv",
14465 atomic_load_explicit(&p->notify_in,
14466 memory_order_relaxed));
14467 json_object_int_add(json_stat, "updatesSent",
14468 atomic_load_explicit(&p->update_out,
14469 memory_order_relaxed));
14470 json_object_int_add(json_stat, "updatesRecv",
14471 atomic_load_explicit(&p->update_in,
14472 memory_order_relaxed));
14473 json_object_int_add(json_stat, "keepalivesSent",
14474 atomic_load_explicit(&p->keepalive_out,
14475 memory_order_relaxed));
14476 json_object_int_add(json_stat, "keepalivesRecv",
14477 atomic_load_explicit(&p->keepalive_in,
14478 memory_order_relaxed));
14479 json_object_int_add(json_stat, "routeRefreshSent",
14480 atomic_load_explicit(&p->refresh_out,
14481 memory_order_relaxed));
14482 json_object_int_add(json_stat, "routeRefreshRecv",
14483 atomic_load_explicit(&p->refresh_in,
14484 memory_order_relaxed));
14485 json_object_int_add(json_stat, "capabilitySent",
14486 atomic_load_explicit(&p->dynamic_cap_out,
14487 memory_order_relaxed));
14488 json_object_int_add(json_stat, "capabilityRecv",
14489 atomic_load_explicit(&p->dynamic_cap_in,
14490 memory_order_relaxed));
14491 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
14492 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
14493 json_object_object_add(json_neigh, "messageStats", json_stat);
14494 } else {
14495 atomic_size_t outq_count, inq_count;
14496 outq_count = atomic_load_explicit(&p->obuf->count,
14497 memory_order_relaxed);
14498 inq_count = atomic_load_explicit(&p->ibuf->count,
14499 memory_order_relaxed);
14500
14501 /* Packet counts. */
14502 vty_out(vty, " Message statistics:\n");
14503 vty_out(vty, " Inq depth is %zu\n", inq_count);
14504 vty_out(vty, " Outq depth is %zu\n", outq_count);
14505 vty_out(vty, " Sent Rcvd\n");
14506 vty_out(vty, " Opens: %10d %10d\n",
14507 atomic_load_explicit(&p->open_out,
14508 memory_order_relaxed),
14509 atomic_load_explicit(&p->open_in,
14510 memory_order_relaxed));
14511 vty_out(vty, " Notifications: %10d %10d\n",
14512 atomic_load_explicit(&p->notify_out,
14513 memory_order_relaxed),
14514 atomic_load_explicit(&p->notify_in,
14515 memory_order_relaxed));
14516 vty_out(vty, " Updates: %10d %10d\n",
14517 atomic_load_explicit(&p->update_out,
14518 memory_order_relaxed),
14519 atomic_load_explicit(&p->update_in,
14520 memory_order_relaxed));
14521 vty_out(vty, " Keepalives: %10d %10d\n",
14522 atomic_load_explicit(&p->keepalive_out,
14523 memory_order_relaxed),
14524 atomic_load_explicit(&p->keepalive_in,
14525 memory_order_relaxed));
14526 vty_out(vty, " Route Refresh: %10d %10d\n",
14527 atomic_load_explicit(&p->refresh_out,
14528 memory_order_relaxed),
14529 atomic_load_explicit(&p->refresh_in,
14530 memory_order_relaxed));
14531 vty_out(vty, " Capability: %10d %10d\n",
14532 atomic_load_explicit(&p->dynamic_cap_out,
14533 memory_order_relaxed),
14534 atomic_load_explicit(&p->dynamic_cap_in,
14535 memory_order_relaxed));
14536 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
14537 PEER_TOTAL_RX(p));
14538 }
14539
14540 if (use_json) {
14541 /* advertisement-interval */
14542 json_object_int_add(json_neigh,
14543 "minBtwnAdvertisementRunsTimerMsecs",
14544 p->v_routeadv * 1000);
14545
14546 /* Update-source. */
14547 if (p->update_if || p->update_source) {
14548 if (p->update_if)
14549 json_object_string_add(json_neigh,
14550 "updateSource",
14551 p->update_if);
14552 else if (p->update_source)
14553 json_object_string_add(
14554 json_neigh, "updateSource",
14555 sockunion2str(p->update_source, buf1,
14556 SU_ADDRSTRLEN));
14557 }
14558 } else {
14559 /* advertisement-interval */
14560 vty_out(vty,
14561 " Minimum time between advertisement runs is %d seconds\n",
14562 p->v_routeadv);
14563
14564 /* Update-source. */
14565 if (p->update_if || p->update_source) {
14566 vty_out(vty, " Update source is ");
14567 if (p->update_if)
14568 vty_out(vty, "%s", p->update_if);
14569 else if (p->update_source)
14570 vty_out(vty, "%s",
14571 sockunion2str(p->update_source, buf1,
14572 SU_ADDRSTRLEN));
14573 vty_out(vty, "\n");
14574 }
14575
14576 vty_out(vty, "\n");
14577 }
14578
14579 /* Address Family Information */
14580 json_object *json_hold = NULL;
14581
14582 if (use_json)
14583 json_hold = json_object_new_object();
14584
14585 FOREACH_AFI_SAFI (afi, safi)
14586 if (p->afc[afi][safi])
14587 bgp_show_peer_afi(vty, p, afi, safi, use_json,
14588 json_hold);
14589
14590 if (use_json) {
14591 json_object_object_add(json_neigh, "addressFamilyInfo",
14592 json_hold);
14593 json_object_int_add(json_neigh, "connectionsEstablished",
14594 p->established);
14595 json_object_int_add(json_neigh, "connectionsDropped",
14596 p->dropped);
14597 } else
14598 vty_out(vty, " Connections established %d; dropped %d\n",
14599 p->established, p->dropped);
14600
14601 if (!p->last_reset) {
14602 if (use_json)
14603 json_object_string_add(json_neigh, "lastReset",
14604 "never");
14605 else
14606 vty_out(vty, " Last reset never\n");
14607 } else {
14608 if (use_json) {
14609 time_t uptime;
14610 struct tm tm;
14611
14612 uptime = bgp_clock();
14613 uptime -= p->resettime;
14614 gmtime_r(&uptime, &tm);
14615
14616 json_object_int_add(json_neigh, "lastResetTimerMsecs",
14617 (tm.tm_sec * 1000)
14618 + (tm.tm_min * 60000)
14619 + (tm.tm_hour * 3600000));
14620 bgp_show_peer_reset(NULL, p, json_neigh, true);
14621 } else {
14622 vty_out(vty, " Last reset %s, ",
14623 peer_uptime(p->resettime, timebuf,
14624 BGP_UPTIME_LEN, 0, NULL));
14625
14626 bgp_show_peer_reset(vty, p, NULL, false);
14627 if (p->last_reset_cause_size) {
14628 msg = p->last_reset_cause;
14629 vty_out(vty,
14630 " Message received that caused BGP to send a NOTIFICATION:\n ");
14631 for (i = 1; i <= p->last_reset_cause_size;
14632 i++) {
14633 vty_out(vty, "%02X", *msg++);
14634
14635 if (i != p->last_reset_cause_size) {
14636 if (i % 16 == 0) {
14637 vty_out(vty, "\n ");
14638 } else if (i % 4 == 0) {
14639 vty_out(vty, " ");
14640 }
14641 }
14642 }
14643 vty_out(vty, "\n");
14644 }
14645 }
14646 }
14647
14648 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
14649 if (use_json)
14650 json_object_boolean_true_add(json_neigh,
14651 "prefixesConfigExceedMax");
14652 else
14653 vty_out(vty,
14654 " Peer had exceeded the max. no. of prefixes configured.\n");
14655
14656 if (p->t_pmax_restart) {
14657 if (use_json) {
14658 json_object_boolean_true_add(
14659 json_neigh, "reducePrefixNumFrom");
14660 json_object_int_add(json_neigh,
14661 "restartInTimerMsec",
14662 thread_timer_remain_second(
14663 p->t_pmax_restart)
14664 * 1000);
14665 } else
14666 vty_out(vty,
14667 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
14668 p->host, thread_timer_remain_second(
14669 p->t_pmax_restart));
14670 } else {
14671 if (use_json)
14672 json_object_boolean_true_add(
14673 json_neigh,
14674 "reducePrefixNumAndClearIpBgp");
14675 else
14676 vty_out(vty,
14677 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
14678 p->host);
14679 }
14680 }
14681
14682 /* EBGP Multihop and GTSM */
14683 if (p->sort != BGP_PEER_IBGP) {
14684 if (use_json) {
14685 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14686 json_object_int_add(json_neigh,
14687 "externalBgpNbrMaxHopsAway",
14688 p->gtsm_hops);
14689 else if (p->ttl > BGP_DEFAULT_TTL)
14690 json_object_int_add(json_neigh,
14691 "externalBgpNbrMaxHopsAway",
14692 p->ttl);
14693 } else {
14694 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14695 vty_out(vty,
14696 " External BGP neighbor may be up to %d hops away.\n",
14697 p->gtsm_hops);
14698 else if (p->ttl > BGP_DEFAULT_TTL)
14699 vty_out(vty,
14700 " External BGP neighbor may be up to %d hops away.\n",
14701 p->ttl);
14702 }
14703 } else {
14704 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED) {
14705 if (use_json)
14706 json_object_int_add(json_neigh,
14707 "internalBgpNbrMaxHopsAway",
14708 p->gtsm_hops);
14709 else
14710 vty_out(vty,
14711 " Internal BGP neighbor may be up to %d hops away.\n",
14712 p->gtsm_hops);
14713 }
14714 }
14715
14716 /* Local address. */
14717 if (p->su_local) {
14718 if (use_json) {
14719 json_object_string_add(json_neigh, "hostLocal",
14720 sockunion2str(p->su_local, buf1,
14721 SU_ADDRSTRLEN));
14722 json_object_int_add(json_neigh, "portLocal",
14723 ntohs(p->su_local->sin.sin_port));
14724 } else
14725 vty_out(vty, "Local host: %s, Local port: %d\n",
14726 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
14727 ntohs(p->su_local->sin.sin_port));
14728 }
14729
14730 /* Remote address. */
14731 if (p->su_remote) {
14732 if (use_json) {
14733 json_object_string_add(json_neigh, "hostForeign",
14734 sockunion2str(p->su_remote, buf1,
14735 SU_ADDRSTRLEN));
14736 json_object_int_add(json_neigh, "portForeign",
14737 ntohs(p->su_remote->sin.sin_port));
14738 } else
14739 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
14740 sockunion2str(p->su_remote, buf1,
14741 SU_ADDRSTRLEN),
14742 ntohs(p->su_remote->sin.sin_port));
14743 }
14744
14745 /* Nexthop display. */
14746 if (p->su_local) {
14747 if (use_json) {
14748 json_object_string_add(json_neigh, "nexthop",
14749 inet_ntop(AF_INET,
14750 &p->nexthop.v4, buf1,
14751 sizeof(buf1)));
14752 json_object_string_add(json_neigh, "nexthopGlobal",
14753 inet_ntop(AF_INET6,
14754 &p->nexthop.v6_global,
14755 buf1, sizeof(buf1)));
14756 json_object_string_add(json_neigh, "nexthopLocal",
14757 inet_ntop(AF_INET6,
14758 &p->nexthop.v6_local,
14759 buf1, sizeof(buf1)));
14760 if (p->shared_network)
14761 json_object_string_add(json_neigh,
14762 "bgpConnection",
14763 "sharedNetwork");
14764 else
14765 json_object_string_add(json_neigh,
14766 "bgpConnection",
14767 "nonSharedNetwork");
14768 } else {
14769 vty_out(vty, "Nexthop: %s\n",
14770 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
14771 sizeof(buf1)));
14772 vty_out(vty, "Nexthop global: %s\n",
14773 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
14774 sizeof(buf1)));
14775 vty_out(vty, "Nexthop local: %s\n",
14776 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
14777 sizeof(buf1)));
14778 vty_out(vty, "BGP connection: %s\n",
14779 p->shared_network ? "shared network"
14780 : "non shared network");
14781 }
14782 }
14783
14784 /* Timer information. */
14785 if (use_json) {
14786 json_object_int_add(json_neigh, "connectRetryTimer",
14787 p->v_connect);
14788 if (peer_established(p) && p->rtt)
14789 json_object_int_add(json_neigh, "estimatedRttInMsecs",
14790 p->rtt);
14791 if (p->t_start)
14792 json_object_int_add(
14793 json_neigh, "nextStartTimerDueInMsecs",
14794 thread_timer_remain_second(p->t_start) * 1000);
14795 if (p->t_connect)
14796 json_object_int_add(
14797 json_neigh, "nextConnectTimerDueInMsecs",
14798 thread_timer_remain_second(p->t_connect)
14799 * 1000);
14800 if (p->t_routeadv) {
14801 json_object_int_add(json_neigh, "mraiInterval",
14802 p->v_routeadv);
14803 json_object_int_add(
14804 json_neigh, "mraiTimerExpireInMsecs",
14805 thread_timer_remain_second(p->t_routeadv)
14806 * 1000);
14807 }
14808 if (p->password)
14809 json_object_int_add(json_neigh, "authenticationEnabled",
14810 1);
14811
14812 if (p->t_read)
14813 json_object_string_add(json_neigh, "readThread", "on");
14814 else
14815 json_object_string_add(json_neigh, "readThread", "off");
14816
14817 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
14818 json_object_string_add(json_neigh, "writeThread", "on");
14819 else
14820 json_object_string_add(json_neigh, "writeThread",
14821 "off");
14822 } else {
14823 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
14824 p->v_connect);
14825 if (peer_established(p) && p->rtt)
14826 vty_out(vty, "Estimated round trip time: %d ms\n",
14827 p->rtt);
14828 if (p->t_start)
14829 vty_out(vty, "Next start timer due in %ld seconds\n",
14830 thread_timer_remain_second(p->t_start));
14831 if (p->t_connect)
14832 vty_out(vty, "Next connect timer due in %ld seconds\n",
14833 thread_timer_remain_second(p->t_connect));
14834 if (p->t_routeadv)
14835 vty_out(vty,
14836 "MRAI (interval %u) timer expires in %ld seconds\n",
14837 p->v_routeadv,
14838 thread_timer_remain_second(p->t_routeadv));
14839 if (p->password)
14840 vty_out(vty, "Peer Authentication Enabled\n");
14841
14842 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
14843 p->t_read ? "on" : "off",
14844 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
14845 ? "on"
14846 : "off", p->fd);
14847 }
14848
14849 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
14850 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
14851 bgp_capability_vty_out(vty, p, use_json, json_neigh);
14852
14853 if (!use_json)
14854 vty_out(vty, "\n");
14855
14856 /* BFD information. */
14857 if (p->bfd_config)
14858 bgp_bfd_show_info(vty, p, json_neigh);
14859
14860 if (use_json) {
14861 if (p->conf_if) /* Configured interface name. */
14862 json_object_object_add(json, p->conf_if, json_neigh);
14863 else /* Configured IP address. */
14864 json_object_object_add(json, p->host, json_neigh);
14865 }
14866 }
14867
14868 static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
14869 enum show_type type,
14870 union sockunion *su,
14871 const char *conf_if, afi_t afi,
14872 bool use_json)
14873 {
14874 struct listnode *node, *nnode;
14875 struct peer *peer;
14876 int find = 0;
14877 safi_t safi = SAFI_UNICAST;
14878 json_object *json = NULL;
14879 json_object *json_neighbor = NULL;
14880
14881 if (use_json) {
14882 json = json_object_new_object();
14883 json_neighbor = json_object_new_object();
14884 }
14885
14886 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14887
14888 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14889 continue;
14890
14891 if ((peer->afc[afi][safi]) == 0)
14892 continue;
14893
14894 if (type == show_all) {
14895 bgp_show_peer_gr_status(vty, peer, use_json,
14896 json_neighbor);
14897
14898 if (use_json) {
14899 json_object_object_add(json, peer->host,
14900 json_neighbor);
14901 json_neighbor = NULL;
14902 }
14903
14904 } else if (type == show_peer) {
14905 if (conf_if) {
14906 if ((peer->conf_if
14907 && !strcmp(peer->conf_if, conf_if))
14908 || (peer->hostname
14909 && !strcmp(peer->hostname, conf_if))) {
14910 find = 1;
14911 bgp_show_peer_gr_status(vty, peer,
14912 use_json,
14913 json_neighbor);
14914 }
14915 } else {
14916 if (sockunion_same(&peer->su, su)) {
14917 find = 1;
14918 bgp_show_peer_gr_status(vty, peer,
14919 use_json,
14920 json_neighbor);
14921 }
14922 }
14923 if (use_json && find)
14924 json_object_object_add(json, peer->host,
14925 json_neighbor);
14926 }
14927
14928 if (find) {
14929 json_neighbor = NULL;
14930 break;
14931 }
14932 }
14933
14934 if (type == show_peer && !find) {
14935 if (use_json)
14936 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14937 else
14938 vty_out(vty, "%% No such neighbor\n");
14939 }
14940 if (use_json) {
14941 vty_out(vty, "%s\n",
14942 json_object_to_json_string_ext(
14943 json, JSON_C_TO_STRING_PRETTY));
14944
14945 if (json_neighbor)
14946 json_object_free(json_neighbor);
14947 json_object_free(json);
14948 } else {
14949 vty_out(vty, "\n");
14950 }
14951
14952 return CMD_SUCCESS;
14953 }
14954
14955 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
14956 enum show_type type, union sockunion *su,
14957 const char *conf_if, bool use_json,
14958 json_object *json)
14959 {
14960 struct listnode *node, *nnode;
14961 struct peer *peer;
14962 int find = 0;
14963 bool nbr_output = false;
14964 afi_t afi = AFI_MAX;
14965 safi_t safi = SAFI_MAX;
14966
14967 if (type == show_ipv4_peer || type == show_ipv4_all) {
14968 afi = AFI_IP;
14969 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
14970 afi = AFI_IP6;
14971 }
14972
14973 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14974 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14975 continue;
14976
14977 switch (type) {
14978 case show_all:
14979 bgp_show_peer(vty, peer, use_json, json);
14980 nbr_output = true;
14981 break;
14982 case show_peer:
14983 if (conf_if) {
14984 if ((peer->conf_if
14985 && !strcmp(peer->conf_if, conf_if))
14986 || (peer->hostname
14987 && !strcmp(peer->hostname, conf_if))) {
14988 find = 1;
14989 bgp_show_peer(vty, peer, use_json,
14990 json);
14991 }
14992 } else {
14993 if (sockunion_same(&peer->su, su)) {
14994 find = 1;
14995 bgp_show_peer(vty, peer, use_json,
14996 json);
14997 }
14998 }
14999 break;
15000 case show_ipv4_peer:
15001 case show_ipv6_peer:
15002 FOREACH_SAFI (safi) {
15003 if (peer->afc[afi][safi]) {
15004 if (conf_if) {
15005 if ((peer->conf_if
15006 && !strcmp(peer->conf_if, conf_if))
15007 || (peer->hostname
15008 && !strcmp(peer->hostname, conf_if))) {
15009 find = 1;
15010 bgp_show_peer(vty, peer, use_json,
15011 json);
15012 break;
15013 }
15014 } else {
15015 if (sockunion_same(&peer->su, su)) {
15016 find = 1;
15017 bgp_show_peer(vty, peer, use_json,
15018 json);
15019 break;
15020 }
15021 }
15022 }
15023 }
15024 break;
15025 case show_ipv4_all:
15026 case show_ipv6_all:
15027 FOREACH_SAFI (safi) {
15028 if (peer->afc[afi][safi]) {
15029 bgp_show_peer(vty, peer, use_json, json);
15030 nbr_output = true;
15031 break;
15032 }
15033 }
15034 break;
15035 }
15036 }
15037
15038 if ((type == show_peer || type == show_ipv4_peer ||
15039 type == show_ipv6_peer) && !find) {
15040 if (use_json)
15041 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
15042 else
15043 vty_out(vty, "%% No such neighbor in this view/vrf\n");
15044 }
15045
15046 if (type != show_peer && type != show_ipv4_peer &&
15047 type != show_ipv6_peer && !nbr_output && !use_json)
15048 vty_out(vty, "%% No BGP neighbors found\n");
15049
15050 if (use_json) {
15051 vty_out(vty, "%s\n", json_object_to_json_string_ext(
15052 json, JSON_C_TO_STRING_PRETTY));
15053 } else {
15054 vty_out(vty, "\n");
15055 }
15056
15057 return CMD_SUCCESS;
15058 }
15059
15060 static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
15061 enum show_type type,
15062 const char *ip_str,
15063 afi_t afi, bool use_json)
15064 {
15065
15066 int ret;
15067 struct bgp *bgp;
15068 union sockunion su;
15069
15070 bgp = bgp_get_default();
15071
15072 if (!bgp)
15073 return;
15074
15075 if (!use_json)
15076 bgp_show_global_graceful_restart_mode_vty(vty, bgp, use_json,
15077 NULL);
15078
15079 if (ip_str) {
15080 ret = str2sockunion(ip_str, &su);
15081 if (ret < 0)
15082 bgp_show_neighbor_graceful_restart(
15083 vty, bgp, type, NULL, ip_str, afi, use_json);
15084 else
15085 bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
15086 NULL, afi, use_json);
15087 } else
15088 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
15089 afi, use_json);
15090 }
15091
15092 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
15093 enum show_type type,
15094 const char *ip_str,
15095 bool use_json)
15096 {
15097 struct listnode *node, *nnode;
15098 struct bgp *bgp;
15099 union sockunion su;
15100 json_object *json = NULL;
15101 int ret, is_first = 1;
15102 bool nbr_output = false;
15103
15104 if (use_json)
15105 vty_out(vty, "{\n");
15106
15107 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15108 nbr_output = true;
15109 if (use_json) {
15110 if (!(json = json_object_new_object())) {
15111 flog_err(
15112 EC_BGP_JSON_MEM_ERROR,
15113 "Unable to allocate memory for JSON object");
15114 vty_out(vty,
15115 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
15116 return;
15117 }
15118
15119 json_object_int_add(json, "vrfId",
15120 (bgp->vrf_id == VRF_UNKNOWN)
15121 ? -1
15122 : (int64_t)bgp->vrf_id);
15123 json_object_string_add(
15124 json, "vrfName",
15125 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15126 ? VRF_DEFAULT_NAME
15127 : bgp->name);
15128
15129 if (!is_first)
15130 vty_out(vty, ",\n");
15131 else
15132 is_first = 0;
15133
15134 vty_out(vty, "\"%s\":",
15135 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15136 ? VRF_DEFAULT_NAME
15137 : bgp->name);
15138 } else {
15139 vty_out(vty, "\nInstance %s:\n",
15140 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15141 ? VRF_DEFAULT_NAME
15142 : bgp->name);
15143 }
15144
15145 if (type == show_peer || type == show_ipv4_peer ||
15146 type == show_ipv6_peer) {
15147 ret = str2sockunion(ip_str, &su);
15148 if (ret < 0)
15149 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
15150 use_json, json);
15151 else
15152 bgp_show_neighbor(vty, bgp, type, &su, NULL,
15153 use_json, json);
15154 } else {
15155 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
15156 use_json, json);
15157 }
15158 json_object_free(json);
15159 json = NULL;
15160 }
15161
15162 if (use_json)
15163 vty_out(vty, "}\n");
15164 else if (!nbr_output)
15165 vty_out(vty, "%% BGP instance not found\n");
15166 }
15167
15168 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
15169 enum show_type type, const char *ip_str,
15170 bool use_json)
15171 {
15172 int ret;
15173 struct bgp *bgp;
15174 union sockunion su;
15175 json_object *json = NULL;
15176
15177 if (name) {
15178 if (strmatch(name, "all")) {
15179 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
15180 use_json);
15181 return CMD_SUCCESS;
15182 } else {
15183 bgp = bgp_lookup_by_name(name);
15184 if (!bgp) {
15185 if (use_json) {
15186 json = json_object_new_object();
15187 vty_out(vty, "%s\n",
15188 json_object_to_json_string_ext(
15189 json,
15190 JSON_C_TO_STRING_PRETTY));
15191 json_object_free(json);
15192 } else
15193 vty_out(vty,
15194 "%% BGP instance not found\n");
15195
15196 return CMD_WARNING;
15197 }
15198 }
15199 } else {
15200 bgp = bgp_get_default();
15201 }
15202
15203 if (bgp) {
15204 json = json_object_new_object();
15205 if (ip_str) {
15206 ret = str2sockunion(ip_str, &su);
15207 if (ret < 0)
15208 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
15209 use_json, json);
15210 else
15211 bgp_show_neighbor(vty, bgp, type, &su, NULL,
15212 use_json, json);
15213 } else {
15214 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
15215 json);
15216 }
15217 json_object_free(json);
15218 } else {
15219 if (use_json)
15220 vty_out(vty, "{}\n");
15221 else
15222 vty_out(vty, "%% BGP instance not found\n");
15223 }
15224
15225 return CMD_SUCCESS;
15226 }
15227
15228
15229
15230 /* "show [ip] bgp neighbors graceful-restart" commands. */
15231 DEFUN (show_ip_bgp_neighbors_gracrful_restart,
15232 show_ip_bgp_neighbors_graceful_restart_cmd,
15233 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
15234 SHOW_STR
15235 BGP_STR
15236 IP_STR
15237 IPV6_STR
15238 NEIGHBOR_STR
15239 "Neighbor to display information about\n"
15240 "Neighbor to display information about\n"
15241 "Neighbor on BGP configured interface\n"
15242 GR_SHOW
15243 JSON_STR)
15244 {
15245 char *sh_arg = NULL;
15246 enum show_type sh_type;
15247 int idx = 0;
15248 afi_t afi = AFI_MAX;
15249 bool uj = use_json(argc, argv);
15250
15251 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
15252 afi = AFI_MAX;
15253
15254 idx++;
15255
15256 if (argv_find(argv, argc, "A.B.C.D", &idx)
15257 || argv_find(argv, argc, "X:X::X:X", &idx)
15258 || argv_find(argv, argc, "WORD", &idx)) {
15259 sh_type = show_peer;
15260 sh_arg = argv[idx]->arg;
15261 } else
15262 sh_type = show_all;
15263
15264 if (!argv_find(argv, argc, "graceful-restart", &idx))
15265 return CMD_SUCCESS;
15266
15267
15268 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
15269 afi, uj);
15270 }
15271
15272 /* "show [ip] bgp neighbors" commands. */
15273 DEFUN (show_ip_bgp_neighbors,
15274 show_ip_bgp_neighbors_cmd,
15275 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
15276 SHOW_STR
15277 IP_STR
15278 BGP_STR
15279 BGP_INSTANCE_HELP_STR
15280 "Address Family\n"
15281 "Address Family\n"
15282 "Detailed information on TCP and BGP neighbor connections\n"
15283 "Neighbor to display information about\n"
15284 "Neighbor to display information about\n"
15285 "Neighbor on BGP configured interface\n"
15286 JSON_STR)
15287 {
15288 char *vrf = NULL;
15289 char *sh_arg = NULL;
15290 enum show_type sh_type;
15291 afi_t afi = AFI_MAX;
15292
15293 bool uj = use_json(argc, argv);
15294
15295 int idx = 0;
15296
15297 /* [<vrf> VIEWVRFNAME] */
15298 if (argv_find(argv, argc, "vrf", &idx)) {
15299 vrf = argv[idx + 1]->arg;
15300 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15301 vrf = NULL;
15302 } else if (argv_find(argv, argc, "view", &idx))
15303 /* [<view> VIEWVRFNAME] */
15304 vrf = argv[idx + 1]->arg;
15305
15306 idx++;
15307
15308 if (argv_find(argv, argc, "ipv4", &idx)) {
15309 sh_type = show_ipv4_all;
15310 afi = AFI_IP;
15311 } else if (argv_find(argv, argc, "ipv6", &idx)) {
15312 sh_type = show_ipv6_all;
15313 afi = AFI_IP6;
15314 } else {
15315 sh_type = show_all;
15316 }
15317
15318 if (argv_find(argv, argc, "A.B.C.D", &idx)
15319 || argv_find(argv, argc, "X:X::X:X", &idx)
15320 || argv_find(argv, argc, "WORD", &idx)) {
15321 sh_type = show_peer;
15322 sh_arg = argv[idx]->arg;
15323 }
15324
15325 if (sh_type == show_peer && afi == AFI_IP) {
15326 sh_type = show_ipv4_peer;
15327 } else if (sh_type == show_peer && afi == AFI_IP6) {
15328 sh_type = show_ipv6_peer;
15329 }
15330
15331 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
15332 }
15333
15334 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
15335 paths' and `show ip mbgp paths'. Those functions results are the
15336 same.*/
15337 DEFUN (show_ip_bgp_paths,
15338 show_ip_bgp_paths_cmd,
15339 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
15340 SHOW_STR
15341 IP_STR
15342 BGP_STR
15343 BGP_SAFI_HELP_STR
15344 "Path information\n")
15345 {
15346 vty_out(vty, "Address Refcnt Path\n");
15347 aspath_print_all_vty(vty);
15348 return CMD_SUCCESS;
15349 }
15350
15351 #include "hash.h"
15352
15353 static void community_show_all_iterator(struct hash_bucket *bucket,
15354 struct vty *vty)
15355 {
15356 struct community *com;
15357
15358 com = (struct community *)bucket->data;
15359 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
15360 community_str(com, false));
15361 }
15362
15363 /* Show BGP's community internal data. */
15364 DEFUN (show_ip_bgp_community_info,
15365 show_ip_bgp_community_info_cmd,
15366 "show [ip] bgp community-info",
15367 SHOW_STR
15368 IP_STR
15369 BGP_STR
15370 "List all bgp community information\n")
15371 {
15372 vty_out(vty, "Address Refcnt Community\n");
15373
15374 hash_iterate(community_hash(),
15375 (void (*)(struct hash_bucket *,
15376 void *))community_show_all_iterator,
15377 vty);
15378
15379 return CMD_SUCCESS;
15380 }
15381
15382 static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
15383 struct vty *vty)
15384 {
15385 struct lcommunity *lcom;
15386
15387 lcom = (struct lcommunity *)bucket->data;
15388 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
15389 lcommunity_str(lcom, false));
15390 }
15391
15392 /* Show BGP's community internal data. */
15393 DEFUN (show_ip_bgp_lcommunity_info,
15394 show_ip_bgp_lcommunity_info_cmd,
15395 "show ip bgp large-community-info",
15396 SHOW_STR
15397 IP_STR
15398 BGP_STR
15399 "List all bgp large-community information\n")
15400 {
15401 vty_out(vty, "Address Refcnt Large-community\n");
15402
15403 hash_iterate(lcommunity_hash(),
15404 (void (*)(struct hash_bucket *,
15405 void *))lcommunity_show_all_iterator,
15406 vty);
15407
15408 return CMD_SUCCESS;
15409 }
15410 /* Graceful Restart */
15411
15412 static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
15413 struct bgp *bgp,
15414 bool use_json,
15415 json_object *json)
15416 {
15417
15418
15419 vty_out(vty, "\n%s", SHOW_GR_HEADER);
15420
15421 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
15422
15423 switch (bgp_global_gr_mode) {
15424
15425 case GLOBAL_HELPER:
15426 vty_out(vty, "Global BGP GR Mode : Helper\n");
15427 break;
15428
15429 case GLOBAL_GR:
15430 vty_out(vty, "Global BGP GR Mode : Restart\n");
15431 break;
15432
15433 case GLOBAL_DISABLE:
15434 vty_out(vty, "Global BGP GR Mode : Disable\n");
15435 break;
15436
15437 case GLOBAL_INVALID:
15438 vty_out(vty,
15439 "Global BGP GR Mode Invalid\n");
15440 break;
15441 }
15442 vty_out(vty, "\n");
15443 }
15444
15445 static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
15446 enum show_type type,
15447 const char *ip_str,
15448 afi_t afi, bool use_json)
15449 {
15450 if ((afi == AFI_MAX) && (ip_str == NULL)) {
15451 afi = AFI_IP;
15452
15453 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
15454
15455 bgp_show_neighbor_graceful_restart_vty(
15456 vty, type, ip_str, afi, use_json);
15457 afi++;
15458 }
15459 } else if (afi != AFI_MAX) {
15460 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
15461 use_json);
15462 } else {
15463 return CMD_ERR_INCOMPLETE;
15464 }
15465
15466 return CMD_SUCCESS;
15467 }
15468 /* Graceful Restart */
15469
15470 DEFUN (show_ip_bgp_attr_info,
15471 show_ip_bgp_attr_info_cmd,
15472 "show [ip] bgp attribute-info",
15473 SHOW_STR
15474 IP_STR
15475 BGP_STR
15476 "List all bgp attribute information\n")
15477 {
15478 attr_show_all(vty);
15479 return CMD_SUCCESS;
15480 }
15481
15482 static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
15483 afi_t afi, safi_t safi,
15484 bool use_json, json_object *json)
15485 {
15486 struct bgp *bgp;
15487 struct listnode *node;
15488 char *vname;
15489 char buf1[INET6_ADDRSTRLEN];
15490 char *ecom_str;
15491 vpn_policy_direction_t dir;
15492
15493 if (json) {
15494 json_object *json_import_vrfs = NULL;
15495 json_object *json_export_vrfs = NULL;
15496
15497 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15498
15499 if (!bgp) {
15500 vty_out(vty, "%s\n",
15501 json_object_to_json_string_ext(
15502 json,
15503 JSON_C_TO_STRING_PRETTY));
15504 json_object_free(json);
15505
15506 return CMD_WARNING;
15507 }
15508
15509 /* Provide context for the block */
15510 json_object_string_add(json, "vrf", name ? name : "default");
15511 json_object_string_add(json, "afiSafi",
15512 get_afi_safi_str(afi, safi, true));
15513
15514 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15515 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
15516 json_object_string_add(json, "importFromVrfs", "none");
15517 json_object_string_add(json, "importRts", "none");
15518 } else {
15519 json_import_vrfs = json_object_new_array();
15520
15521 for (ALL_LIST_ELEMENTS_RO(
15522 bgp->vpn_policy[afi].import_vrf,
15523 node, vname))
15524 json_object_array_add(json_import_vrfs,
15525 json_object_new_string(vname));
15526
15527 json_object_object_add(json, "importFromVrfs",
15528 json_import_vrfs);
15529 dir = BGP_VPN_POLICY_DIR_FROMVPN;
15530 if (bgp->vpn_policy[afi].rtlist[dir]) {
15531 ecom_str = ecommunity_ecom2str(
15532 bgp->vpn_policy[afi].rtlist[dir],
15533 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15534 json_object_string_add(json, "importRts",
15535 ecom_str);
15536 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15537 } else
15538 json_object_string_add(json, "importRts",
15539 "none");
15540 }
15541
15542 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15543 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
15544 json_object_string_add(json, "exportToVrfs", "none");
15545 json_object_string_add(json, "routeDistinguisher",
15546 "none");
15547 json_object_string_add(json, "exportRts", "none");
15548 } else {
15549 json_export_vrfs = json_object_new_array();
15550
15551 for (ALL_LIST_ELEMENTS_RO(
15552 bgp->vpn_policy[afi].export_vrf,
15553 node, vname))
15554 json_object_array_add(json_export_vrfs,
15555 json_object_new_string(vname));
15556 json_object_object_add(json, "exportToVrfs",
15557 json_export_vrfs);
15558 json_object_string_add(json, "routeDistinguisher",
15559 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
15560 buf1, RD_ADDRSTRLEN));
15561
15562 dir = BGP_VPN_POLICY_DIR_TOVPN;
15563 if (bgp->vpn_policy[afi].rtlist[dir]) {
15564 ecom_str = ecommunity_ecom2str(
15565 bgp->vpn_policy[afi].rtlist[dir],
15566 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15567 json_object_string_add(json, "exportRts",
15568 ecom_str);
15569 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15570 } else
15571 json_object_string_add(json, "exportRts",
15572 "none");
15573 }
15574
15575 if (use_json) {
15576 vty_out(vty, "%s\n",
15577 json_object_to_json_string_ext(json,
15578 JSON_C_TO_STRING_PRETTY));
15579 json_object_free(json);
15580 }
15581 } else {
15582 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15583
15584 if (!bgp) {
15585 vty_out(vty, "%% No such BGP instance exist\n");
15586 return CMD_WARNING;
15587 }
15588
15589 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15590 BGP_CONFIG_VRF_TO_VRF_IMPORT))
15591 vty_out(vty,
15592 "This VRF is not importing %s routes from any other VRF\n",
15593 get_afi_safi_str(afi, safi, false));
15594 else {
15595 vty_out(vty,
15596 "This VRF is importing %s routes from the following VRFs:\n",
15597 get_afi_safi_str(afi, safi, false));
15598
15599 for (ALL_LIST_ELEMENTS_RO(
15600 bgp->vpn_policy[afi].import_vrf,
15601 node, vname))
15602 vty_out(vty, " %s\n", vname);
15603
15604 dir = BGP_VPN_POLICY_DIR_FROMVPN;
15605 ecom_str = NULL;
15606 if (bgp->vpn_policy[afi].rtlist[dir]) {
15607 ecom_str = ecommunity_ecom2str(
15608 bgp->vpn_policy[afi].rtlist[dir],
15609 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15610 vty_out(vty, "Import RT(s): %s\n", ecom_str);
15611
15612 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15613 } else
15614 vty_out(vty, "Import RT(s):\n");
15615 }
15616
15617 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15618 BGP_CONFIG_VRF_TO_VRF_EXPORT))
15619 vty_out(vty,
15620 "This VRF is not exporting %s routes to any other VRF\n",
15621 get_afi_safi_str(afi, safi, false));
15622 else {
15623 vty_out(vty,
15624 "This VRF is exporting %s routes to the following VRFs:\n",
15625 get_afi_safi_str(afi, safi, false));
15626
15627 for (ALL_LIST_ELEMENTS_RO(
15628 bgp->vpn_policy[afi].export_vrf,
15629 node, vname))
15630 vty_out(vty, " %s\n", vname);
15631
15632 vty_out(vty, "RD: %s\n",
15633 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
15634 buf1, RD_ADDRSTRLEN));
15635
15636 dir = BGP_VPN_POLICY_DIR_TOVPN;
15637 if (bgp->vpn_policy[afi].rtlist[dir]) {
15638 ecom_str = ecommunity_ecom2str(
15639 bgp->vpn_policy[afi].rtlist[dir],
15640 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15641 vty_out(vty, "Export RT: %s\n", ecom_str);
15642 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15643 } else
15644 vty_out(vty, "Import RT(s):\n");
15645 }
15646 }
15647
15648 return CMD_SUCCESS;
15649 }
15650
15651 static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
15652 safi_t safi, bool use_json)
15653 {
15654 struct listnode *node, *nnode;
15655 struct bgp *bgp;
15656 char *vrf_name = NULL;
15657 json_object *json = NULL;
15658 json_object *json_vrf = NULL;
15659 json_object *json_vrfs = NULL;
15660
15661 if (use_json) {
15662 json = json_object_new_object();
15663 json_vrfs = json_object_new_object();
15664 }
15665
15666 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15667
15668 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
15669 vrf_name = bgp->name;
15670
15671 if (use_json) {
15672 json_vrf = json_object_new_object();
15673 } else {
15674 vty_out(vty, "\nInstance %s:\n",
15675 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15676 ? VRF_DEFAULT_NAME : bgp->name);
15677 }
15678 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
15679 if (use_json) {
15680 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15681 json_object_object_add(json_vrfs,
15682 VRF_DEFAULT_NAME, json_vrf);
15683 else
15684 json_object_object_add(json_vrfs, vrf_name,
15685 json_vrf);
15686 }
15687 }
15688
15689 if (use_json) {
15690 json_object_object_add(json, "vrfs", json_vrfs);
15691 vty_out(vty, "%s\n", json_object_to_json_string_ext(json,
15692 JSON_C_TO_STRING_PRETTY));
15693 json_object_free(json);
15694 }
15695
15696 return CMD_SUCCESS;
15697 }
15698
15699 /* "show [ip] bgp route-leak" command. */
15700 DEFUN (show_ip_bgp_route_leak,
15701 show_ip_bgp_route_leak_cmd,
15702 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
15703 SHOW_STR
15704 IP_STR
15705 BGP_STR
15706 BGP_INSTANCE_HELP_STR
15707 BGP_AFI_HELP_STR
15708 BGP_SAFI_HELP_STR
15709 "Route leaking information\n"
15710 JSON_STR)
15711 {
15712 char *vrf = NULL;
15713 afi_t afi = AFI_MAX;
15714 safi_t safi = SAFI_MAX;
15715
15716 bool uj = use_json(argc, argv);
15717 int idx = 0;
15718 json_object *json = NULL;
15719
15720 /* show [ip] bgp */
15721 if (argv_find(argv, argc, "ip", &idx)) {
15722 afi = AFI_IP;
15723 safi = SAFI_UNICAST;
15724 }
15725 /* [vrf VIEWVRFNAME] */
15726 if (argv_find(argv, argc, "view", &idx)) {
15727 vty_out(vty,
15728 "%% This command is not applicable to BGP views\n");
15729 return CMD_WARNING;
15730 }
15731
15732 if (argv_find(argv, argc, "vrf", &idx)) {
15733 vrf = argv[idx + 1]->arg;
15734 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15735 vrf = NULL;
15736 }
15737 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15738 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
15739 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15740 }
15741
15742 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
15743 vty_out(vty,
15744 "%% This command is applicable only for unicast ipv4|ipv6\n");
15745 return CMD_WARNING;
15746 }
15747
15748 if (vrf && strmatch(vrf, "all"))
15749 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
15750
15751 if (uj)
15752 json = json_object_new_object();
15753
15754 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
15755 }
15756
15757 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
15758 safi_t safi)
15759 {
15760 struct listnode *node, *nnode;
15761 struct bgp *bgp;
15762
15763 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15764 vty_out(vty, "\nInstance %s:\n",
15765 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15766 ? VRF_DEFAULT_NAME
15767 : bgp->name);
15768 update_group_show(bgp, afi, safi, vty, 0);
15769 }
15770 }
15771
15772 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
15773 int safi, uint64_t subgrp_id)
15774 {
15775 struct bgp *bgp;
15776
15777 if (name) {
15778 if (strmatch(name, "all")) {
15779 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
15780 return CMD_SUCCESS;
15781 } else {
15782 bgp = bgp_lookup_by_name(name);
15783 }
15784 } else {
15785 bgp = bgp_get_default();
15786 }
15787
15788 if (bgp)
15789 update_group_show(bgp, afi, safi, vty, subgrp_id);
15790 return CMD_SUCCESS;
15791 }
15792
15793 DEFUN (show_ip_bgp_updgrps,
15794 show_ip_bgp_updgrps_cmd,
15795 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
15796 SHOW_STR
15797 IP_STR
15798 BGP_STR
15799 BGP_INSTANCE_HELP_STR
15800 BGP_AFI_HELP_STR
15801 BGP_SAFI_WITH_LABEL_HELP_STR
15802 "Detailed info about dynamic update groups\n"
15803 "Specific subgroup to display detailed info for\n")
15804 {
15805 char *vrf = NULL;
15806 afi_t afi = AFI_IP6;
15807 safi_t safi = SAFI_UNICAST;
15808 uint64_t subgrp_id = 0;
15809
15810 int idx = 0;
15811
15812 /* show [ip] bgp */
15813 if (argv_find(argv, argc, "ip", &idx))
15814 afi = AFI_IP;
15815 /* [<vrf> VIEWVRFNAME] */
15816 if (argv_find(argv, argc, "vrf", &idx)) {
15817 vrf = argv[idx + 1]->arg;
15818 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15819 vrf = NULL;
15820 } else if (argv_find(argv, argc, "view", &idx))
15821 /* [<view> VIEWVRFNAME] */
15822 vrf = argv[idx + 1]->arg;
15823 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15824 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
15825 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15826 }
15827
15828 /* get subgroup id, if provided */
15829 idx = argc - 1;
15830 if (argv[idx]->type == VARIABLE_TKN)
15831 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
15832
15833 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
15834 }
15835
15836 DEFUN (show_bgp_instance_all_ipv6_updgrps,
15837 show_bgp_instance_all_ipv6_updgrps_cmd,
15838 "show [ip] bgp <view|vrf> all update-groups",
15839 SHOW_STR
15840 IP_STR
15841 BGP_STR
15842 BGP_INSTANCE_ALL_HELP_STR
15843 "Detailed info about dynamic update groups\n")
15844 {
15845 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
15846 return CMD_SUCCESS;
15847 }
15848
15849 DEFUN (show_bgp_l2vpn_evpn_updgrps,
15850 show_bgp_l2vpn_evpn_updgrps_cmd,
15851 "show [ip] bgp l2vpn evpn update-groups",
15852 SHOW_STR
15853 IP_STR
15854 BGP_STR
15855 "l2vpn address family\n"
15856 "evpn sub-address family\n"
15857 "Detailed info about dynamic update groups\n")
15858 {
15859 char *vrf = NULL;
15860 uint64_t subgrp_id = 0;
15861
15862 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
15863 return CMD_SUCCESS;
15864 }
15865
15866 DEFUN (show_bgp_updgrps_stats,
15867 show_bgp_updgrps_stats_cmd,
15868 "show [ip] bgp update-groups statistics",
15869 SHOW_STR
15870 IP_STR
15871 BGP_STR
15872 "Detailed info about dynamic update groups\n"
15873 "Statistics\n")
15874 {
15875 struct bgp *bgp;
15876
15877 bgp = bgp_get_default();
15878 if (bgp)
15879 update_group_show_stats(bgp, vty);
15880
15881 return CMD_SUCCESS;
15882 }
15883
15884 DEFUN (show_bgp_instance_updgrps_stats,
15885 show_bgp_instance_updgrps_stats_cmd,
15886 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
15887 SHOW_STR
15888 IP_STR
15889 BGP_STR
15890 BGP_INSTANCE_HELP_STR
15891 "Detailed info about dynamic update groups\n"
15892 "Statistics\n")
15893 {
15894 int idx_word = 3;
15895 struct bgp *bgp;
15896
15897 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
15898 if (bgp)
15899 update_group_show_stats(bgp, vty);
15900
15901 return CMD_SUCCESS;
15902 }
15903
15904 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
15905 afi_t afi, safi_t safi,
15906 const char *what, uint64_t subgrp_id)
15907 {
15908 struct bgp *bgp;
15909
15910 if (name)
15911 bgp = bgp_lookup_by_name(name);
15912 else
15913 bgp = bgp_get_default();
15914
15915 if (bgp) {
15916 if (!strcmp(what, "advertise-queue"))
15917 update_group_show_adj_queue(bgp, afi, safi, vty,
15918 subgrp_id);
15919 else if (!strcmp(what, "advertised-routes"))
15920 update_group_show_advertised(bgp, afi, safi, vty,
15921 subgrp_id);
15922 else if (!strcmp(what, "packet-queue"))
15923 update_group_show_packet_queue(bgp, afi, safi, vty,
15924 subgrp_id);
15925 }
15926 }
15927
15928 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
15929 show_ip_bgp_instance_updgrps_adj_s_cmd,
15930 "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",
15931 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
15932 BGP_SAFI_HELP_STR
15933 "Detailed info about dynamic update groups\n"
15934 "Specific subgroup to display info for\n"
15935 "Advertisement queue\n"
15936 "Announced routes\n"
15937 "Packet queue\n")
15938 {
15939 uint64_t subgrp_id = 0;
15940 afi_t afiz;
15941 safi_t safiz;
15942 if (sgid)
15943 subgrp_id = strtoull(sgid, NULL, 10);
15944
15945 if (!ip && !afi)
15946 afiz = AFI_IP6;
15947 if (!ip && afi)
15948 afiz = bgp_vty_afi_from_str(afi);
15949 if (ip && !afi)
15950 afiz = AFI_IP;
15951 if (ip && afi) {
15952 afiz = bgp_vty_afi_from_str(afi);
15953 if (afiz != AFI_IP)
15954 vty_out(vty,
15955 "%% Cannot specify both 'ip' and 'ipv6'\n");
15956 return CMD_WARNING;
15957 }
15958
15959 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
15960
15961 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
15962 return CMD_SUCCESS;
15963 }
15964
15965 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group,
15966 json_object *json)
15967 {
15968 struct listnode *node, *nnode;
15969 struct prefix *range;
15970 struct peer *conf;
15971 struct peer *peer;
15972 afi_t afi;
15973 safi_t safi;
15974 const char *peer_status;
15975 int lr_count;
15976 int dynamic;
15977 bool af_cfgd;
15978 json_object *json_peer_group = NULL;
15979 json_object *json_peer_group_afc = NULL;
15980 json_object *json_peer_group_members = NULL;
15981 json_object *json_peer_group_dynamic = NULL;
15982 json_object *json_peer_group_dynamic_af = NULL;
15983 json_object *json_peer_group_ranges = NULL;
15984
15985 conf = group->conf;
15986
15987 if (json) {
15988 json_peer_group = json_object_new_object();
15989 json_peer_group_afc = json_object_new_array();
15990 }
15991
15992 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
15993 if (json)
15994 json_object_int_add(json_peer_group, "remoteAs",
15995 conf->as);
15996 else
15997 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15998 group->name, conf->as);
15999 } else if (conf->as_type == AS_INTERNAL) {
16000 if (json)
16001 json_object_int_add(json_peer_group, "remoteAs",
16002 group->bgp->as);
16003 else
16004 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
16005 group->name, group->bgp->as);
16006 } else {
16007 if (!json)
16008 vty_out(vty, "\nBGP peer-group %s\n", group->name);
16009 }
16010
16011 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL)) {
16012 if (json)
16013 json_object_string_add(json_peer_group, "type",
16014 "internal");
16015 else
16016 vty_out(vty, " Peer-group type is internal\n");
16017 } else {
16018 if (json)
16019 json_object_string_add(json_peer_group, "type",
16020 "external");
16021 else
16022 vty_out(vty, " Peer-group type is external\n");
16023 }
16024
16025 /* Display AFs configured. */
16026 if (!json)
16027 vty_out(vty, " Configured address-families:");
16028
16029 FOREACH_AFI_SAFI (afi, safi) {
16030 if (conf->afc[afi][safi]) {
16031 af_cfgd = true;
16032 if (json)
16033 json_object_array_add(
16034 json_peer_group_afc,
16035 json_object_new_string(get_afi_safi_str(
16036 afi, safi, false)));
16037 else
16038 vty_out(vty, " %s;",
16039 get_afi_safi_str(afi, safi, false));
16040 }
16041 }
16042
16043 if (json) {
16044 json_object_object_add(json_peer_group,
16045 "addressFamiliesConfigured",
16046 json_peer_group_afc);
16047 } else {
16048 if (!af_cfgd)
16049 vty_out(vty, " none\n");
16050 else
16051 vty_out(vty, "\n");
16052 }
16053
16054 /* Display listen ranges (for dynamic neighbors), if any */
16055 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
16056 lr_count = listcount(group->listen_range[afi]);
16057 if (lr_count) {
16058 if (json) {
16059 if (!json_peer_group_dynamic)
16060 json_peer_group_dynamic =
16061 json_object_new_object();
16062
16063 json_peer_group_dynamic_af =
16064 json_object_new_object();
16065 json_peer_group_ranges =
16066 json_object_new_array();
16067 json_object_int_add(json_peer_group_dynamic_af,
16068 "count", lr_count);
16069 } else {
16070 vty_out(vty, " %d %s listen range(s)\n",
16071 lr_count, afi2str(afi));
16072 }
16073
16074 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
16075 nnode, range)) {
16076 if (json) {
16077 char buf[BUFSIZ];
16078
16079 snprintfrr(buf, sizeof(buf), "%pFX",
16080 range);
16081
16082 json_object_array_add(
16083 json_peer_group_ranges,
16084 json_object_new_string(buf));
16085 } else {
16086 vty_out(vty, " %pFX\n", range);
16087 }
16088 }
16089
16090 if (json) {
16091 json_object_object_add(
16092 json_peer_group_dynamic_af, "ranges",
16093 json_peer_group_ranges);
16094
16095 json_object_object_add(
16096 json_peer_group_dynamic, afi2str(afi),
16097 json_peer_group_dynamic_af);
16098 }
16099 }
16100 }
16101
16102 if (json_peer_group_dynamic)
16103 json_object_object_add(json_peer_group, "dynamicRanges",
16104 json_peer_group_dynamic);
16105
16106 /* Display group members and their status */
16107 if (listcount(group->peer)) {
16108 if (json)
16109 json_peer_group_members = json_object_new_object();
16110 else
16111 vty_out(vty, " Peer-group members:\n");
16112 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
16113 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
16114 || CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHUTDOWN))
16115 peer_status = "Idle (Admin)";
16116 else if (CHECK_FLAG(peer->sflags,
16117 PEER_STATUS_PREFIX_OVERFLOW))
16118 peer_status = "Idle (PfxCt)";
16119 else
16120 peer_status = lookup_msg(bgp_status_msg,
16121 peer->status, NULL);
16122
16123 dynamic = peer_dynamic_neighbor(peer);
16124
16125 if (json) {
16126 json_object *json_peer_group_member =
16127 json_object_new_object();
16128
16129 json_object_string_add(json_peer_group_member,
16130 "status", peer_status);
16131
16132 if (dynamic)
16133 json_object_boolean_true_add(
16134 json_peer_group_member,
16135 "dynamic");
16136
16137 json_object_object_add(json_peer_group_members,
16138 peer->host,
16139 json_peer_group_member);
16140 } else {
16141 vty_out(vty, " %s %s %s \n", peer->host,
16142 dynamic ? "(dynamic)" : "",
16143 peer_status);
16144 }
16145 }
16146 if (json)
16147 json_object_object_add(json_peer_group, "members",
16148 json_peer_group_members);
16149 }
16150
16151 if (json)
16152 json_object_object_add(json, group->name, json_peer_group);
16153
16154 return CMD_SUCCESS;
16155 }
16156
16157 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
16158 const char *group_name, bool uj)
16159 {
16160 struct bgp *bgp;
16161 struct listnode *node, *nnode;
16162 struct peer_group *group;
16163 bool found = false;
16164 json_object *json = NULL;
16165
16166 if (uj)
16167 json = json_object_new_object();
16168
16169 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
16170
16171 if (!bgp) {
16172 if (uj) {
16173 vty_out(vty, "%s\n",
16174 json_object_to_json_string_ext(
16175 json, JSON_C_TO_STRING_PRETTY));
16176 json_object_free(json);
16177 } else {
16178 vty_out(vty, "%% BGP instance not found\n");
16179 }
16180
16181 return CMD_WARNING;
16182 }
16183
16184 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
16185 if (group_name) {
16186 if (strmatch(group->name, group_name)) {
16187 bgp_show_one_peer_group(vty, group, json);
16188 found = true;
16189 break;
16190 }
16191 } else {
16192 bgp_show_one_peer_group(vty, group, json);
16193 }
16194 }
16195
16196 if (group_name && !found && !uj)
16197 vty_out(vty, "%% No such peer-group\n");
16198
16199 if (uj) {
16200 vty_out(vty, "%s\n",
16201 json_object_to_json_string_ext(
16202 json, JSON_C_TO_STRING_PRETTY));
16203 json_object_free(json);
16204 }
16205
16206 return CMD_SUCCESS;
16207 }
16208
16209 DEFUN(show_ip_bgp_peer_groups, show_ip_bgp_peer_groups_cmd,
16210 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME] [json]",
16211 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR
16212 "Detailed information on BGP peer groups\n"
16213 "Peer group name\n" JSON_STR)
16214 {
16215 char *vrf, *pg;
16216 int idx = 0;
16217 bool uj = use_json(argc, argv);
16218
16219 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
16220 : NULL;
16221 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
16222
16223 return bgp_show_peer_group_vty(vty, vrf, pg, uj);
16224 }
16225
16226
16227 /* Redistribute VTY commands. */
16228
16229 DEFUN_YANG (bgp_redistribute_ipv4,
16230 bgp_redistribute_ipv4_cmd,
16231 "redistribute " FRR_IP_REDIST_STR_BGPD,
16232 "Redistribute information from another routing protocol\n"
16233 FRR_IP_REDIST_HELP_STR_BGPD)
16234 {
16235 int idx_protocol = 1;
16236 char base_xpath[XPATH_MAXLEN];
16237
16238 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16239 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16240 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16241 argv[idx_protocol]->text, "0");
16242
16243 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16244
16245 return nb_cli_apply_changes(vty, base_xpath);
16246 }
16247
16248 ALIAS_HIDDEN(
16249 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
16250 "redistribute " FRR_IP_REDIST_STR_BGPD,
16251 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
16252
16253 DEFUN_YANG (bgp_redistribute_ipv4_rmap,
16254 bgp_redistribute_ipv4_rmap_cmd,
16255 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
16256 "Redistribute information from another routing protocol\n"
16257 FRR_IP_REDIST_HELP_STR_BGPD
16258 "Route map reference\n"
16259 "Pointer to route-map entries\n")
16260 {
16261 int idx_protocol = 1;
16262 int idx_word = 3;
16263 char base_xpath[XPATH_MAXLEN];
16264
16265 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16266 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16267 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16268 argv[idx_protocol]->text, "0");
16269
16270 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16271 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16272 argv[idx_word]->arg);
16273
16274 return nb_cli_apply_changes(vty, base_xpath);
16275 }
16276
16277 ALIAS_HIDDEN(
16278 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
16279 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
16280 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16281 "Route map reference\n"
16282 "Pointer to route-map entries\n")
16283
16284 DEFUN_YANG (bgp_redistribute_ipv4_metric,
16285 bgp_redistribute_ipv4_metric_cmd,
16286 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
16287 "Redistribute information from another routing protocol\n"
16288 FRR_IP_REDIST_HELP_STR_BGPD
16289 "Metric for redistributed routes\n"
16290 "Default metric\n")
16291 {
16292 int idx_protocol = 1;
16293 int idx_number = 3;
16294 char base_xpath[XPATH_MAXLEN];
16295
16296 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16297 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16298 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16299 argv[idx_protocol]->text, "0");
16300
16301 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16302 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16303 argv[idx_number]->arg);
16304
16305 return nb_cli_apply_changes(vty, base_xpath);
16306 }
16307
16308 ALIAS_HIDDEN(
16309 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
16310 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
16311 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16312 "Metric for redistributed routes\n"
16313 "Default metric\n")
16314
16315 DEFUN_YANG(
16316 bgp_redistribute_ipv4_rmap_metric,
16317 bgp_redistribute_ipv4_rmap_metric_cmd,
16318 "redistribute " FRR_IP_REDIST_STR_BGPD
16319 " route-map WORD metric (0-4294967295)",
16320 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16321 "Route map reference\n"
16322 "Pointer to route-map entries\n"
16323 "Metric for redistributed routes\n"
16324 "Default metric\n")
16325 {
16326 int idx_protocol = 1;
16327 int idx_word = 3;
16328 int idx_number = 5;
16329 char base_xpath[XPATH_MAXLEN];
16330
16331 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16332 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16333 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16334 argv[idx_protocol]->text, "0");
16335
16336 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16337 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16338 argv[idx_word]->arg);
16339 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16340 argv[idx_number]->arg);
16341
16342 return nb_cli_apply_changes(vty, base_xpath);
16343 }
16344
16345 ALIAS_HIDDEN(
16346 bgp_redistribute_ipv4_rmap_metric,
16347 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
16348 "redistribute " FRR_IP_REDIST_STR_BGPD
16349 " route-map WORD metric (0-4294967295)",
16350 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16351 "Route map reference\n"
16352 "Pointer to route-map entries\n"
16353 "Metric for redistributed routes\n"
16354 "Default metric\n")
16355
16356 DEFUN_YANG(
16357 bgp_redistribute_ipv4_metric_rmap,
16358 bgp_redistribute_ipv4_metric_rmap_cmd,
16359 "redistribute " FRR_IP_REDIST_STR_BGPD
16360 " metric (0-4294967295) route-map WORD",
16361 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16362 "Metric for redistributed routes\n"
16363 "Default metric\n"
16364 "Route map reference\n"
16365 "Pointer to route-map entries\n")
16366 {
16367 int idx_protocol = 1;
16368 int idx_word = 5;
16369 int idx_number = 3;
16370 char base_xpath[XPATH_MAXLEN];
16371
16372 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16373 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16374 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16375 argv[idx_protocol]->text, "0");
16376
16377 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16378 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16379 argv[idx_number]->arg);
16380 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16381 argv[idx_word]->arg);
16382
16383 return nb_cli_apply_changes(vty, base_xpath);
16384 }
16385
16386 ALIAS_HIDDEN(
16387 bgp_redistribute_ipv4_metric_rmap,
16388 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
16389 "redistribute " FRR_IP_REDIST_STR_BGPD
16390 " metric (0-4294967295) route-map WORD",
16391 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16392 "Metric for redistributed routes\n"
16393 "Default metric\n"
16394 "Route map reference\n"
16395 "Pointer to route-map entries\n")
16396
16397 DEFUN_YANG (bgp_redistribute_ipv4_ospf,
16398 bgp_redistribute_ipv4_ospf_cmd,
16399 "redistribute <ospf|table> (1-65535)",
16400 "Redistribute information from another routing protocol\n"
16401 "Open Shortest Path First (OSPFv2)\n"
16402 "Non-main Kernel Routing Table\n"
16403 "Instance ID/Table ID\n")
16404 {
16405 int idx_protocol = 1;
16406 int idx_number = 2;
16407 char base_xpath[XPATH_MAXLEN];
16408
16409 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16410 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16411 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16412 argv[idx_protocol]->text, argv[idx_number]->arg);
16413
16414 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16415
16416 return nb_cli_apply_changes(vty, base_xpath);
16417 }
16418
16419 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
16420 "redistribute <ospf|table> (1-65535)",
16421 "Redistribute information from another routing protocol\n"
16422 "Open Shortest Path First (OSPFv2)\n"
16423 "Non-main Kernel Routing Table\n"
16424 "Instance ID/Table ID\n")
16425
16426 DEFUN_YANG (bgp_redistribute_ipv4_ospf_rmap,
16427 bgp_redistribute_ipv4_ospf_rmap_cmd,
16428 "redistribute <ospf|table> (1-65535) route-map WORD",
16429 "Redistribute information from another routing protocol\n"
16430 "Open Shortest Path First (OSPFv2)\n"
16431 "Non-main Kernel Routing Table\n"
16432 "Instance ID/Table ID\n"
16433 "Route map reference\n"
16434 "Pointer to route-map entries\n")
16435 {
16436 int idx_protocol = 1;
16437 int idx_number = 2;
16438 int idx_word = 4;
16439 char base_xpath[XPATH_MAXLEN];
16440
16441 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16442 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16443 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16444 argv[idx_protocol]->text, argv[idx_number]->arg);
16445
16446 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16447
16448 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16449 argv[idx_word]->arg);
16450
16451 return nb_cli_apply_changes(vty, base_xpath);
16452 }
16453
16454 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
16455 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
16456 "redistribute <ospf|table> (1-65535) route-map WORD",
16457 "Redistribute information from another routing protocol\n"
16458 "Open Shortest Path First (OSPFv2)\n"
16459 "Non-main Kernel Routing Table\n"
16460 "Instance ID/Table ID\n"
16461 "Route map reference\n"
16462 "Pointer to route-map entries\n")
16463
16464 DEFUN_YANG(bgp_redistribute_ipv4_ospf_metric,
16465 bgp_redistribute_ipv4_ospf_metric_cmd,
16466 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
16467 "Redistribute information from another routing protocol\n"
16468 "Open Shortest Path First (OSPFv2)\n"
16469 "Non-main Kernel Routing Table\n"
16470 "Instance ID/Table ID\n"
16471 "Metric for redistributed routes\n"
16472 "Default metric\n")
16473 {
16474 int idx_protocol = 1;
16475 int idx_number = 2;
16476 int idx_number_2 = 4;
16477 char base_xpath[XPATH_MAXLEN];
16478
16479 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16480 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16481 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16482 argv[idx_protocol]->text, argv[idx_number]->arg);
16483
16484 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16485
16486 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16487 argv[idx_number_2]->arg);
16488
16489 return nb_cli_apply_changes(vty, base_xpath);
16490 }
16491
16492 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
16493 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
16494 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
16495 "Redistribute information from another routing protocol\n"
16496 "Open Shortest Path First (OSPFv2)\n"
16497 "Non-main Kernel Routing Table\n"
16498 "Instance ID/Table ID\n"
16499 "Metric for redistributed routes\n"
16500 "Default metric\n")
16501
16502 DEFUN_YANG(
16503 bgp_redistribute_ipv4_ospf_rmap_metric,
16504 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
16505 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
16506 "Redistribute information from another routing protocol\n"
16507 "Open Shortest Path First (OSPFv2)\n"
16508 "Non-main Kernel Routing Table\n"
16509 "Instance ID/Table ID\n"
16510 "Route map reference\n"
16511 "Pointer to route-map entries\n"
16512 "Metric for redistributed routes\n"
16513 "Default metric\n")
16514 {
16515 int idx_protocol = 1;
16516 int idx_number = 2;
16517 int idx_word = 4;
16518 int idx_number_2 = 6;
16519 char base_xpath[XPATH_MAXLEN];
16520
16521 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16522 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16523 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16524 argv[idx_protocol]->text, argv[idx_number]->arg);
16525
16526 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16527
16528 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16529 argv[idx_word]->arg);
16530 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16531 argv[idx_number_2]->arg);
16532
16533 return nb_cli_apply_changes(vty, base_xpath);
16534 }
16535
16536 ALIAS_HIDDEN(
16537 bgp_redistribute_ipv4_ospf_rmap_metric,
16538 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
16539 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
16540 "Redistribute information from another routing protocol\n"
16541 "Open Shortest Path First (OSPFv2)\n"
16542 "Non-main Kernel Routing Table\n"
16543 "Instance ID/Table ID\n"
16544 "Route map reference\n"
16545 "Pointer to route-map entries\n"
16546 "Metric for redistributed routes\n"
16547 "Default metric\n")
16548
16549 DEFUN_YANG(
16550 bgp_redistribute_ipv4_ospf_metric_rmap,
16551 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
16552 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
16553 "Redistribute information from another routing protocol\n"
16554 "Open Shortest Path First (OSPFv2)\n"
16555 "Non-main Kernel Routing Table\n"
16556 "Instance ID/Table ID\n"
16557 "Metric for redistributed routes\n"
16558 "Default metric\n"
16559 "Route map reference\n"
16560 "Pointer to route-map entries\n")
16561 {
16562 int idx_protocol = 1;
16563 int idx_number = 2;
16564 int idx_number_2 = 4;
16565 int idx_word = 6;
16566 char base_xpath[XPATH_MAXLEN];
16567
16568 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16569 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16570 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16571 argv[idx_protocol]->text, argv[idx_number]->arg);
16572
16573 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16574
16575 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16576 argv[idx_number_2]->arg);
16577 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16578 argv[idx_word]->arg);
16579
16580 return nb_cli_apply_changes(vty, base_xpath);
16581 }
16582
16583 ALIAS_HIDDEN(
16584 bgp_redistribute_ipv4_ospf_metric_rmap,
16585 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
16586 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
16587 "Redistribute information from another routing protocol\n"
16588 "Open Shortest Path First (OSPFv2)\n"
16589 "Non-main Kernel Routing Table\n"
16590 "Instance ID/Table ID\n"
16591 "Metric for redistributed routes\n"
16592 "Default metric\n"
16593 "Route map reference\n"
16594 "Pointer to route-map entries\n")
16595
16596 DEFUN_YANG (no_bgp_redistribute_ipv4_ospf,
16597 no_bgp_redistribute_ipv4_ospf_cmd,
16598 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
16599 NO_STR
16600 "Redistribute information from another routing protocol\n"
16601 "Open Shortest Path First (OSPFv2)\n"
16602 "Non-main Kernel Routing Table\n"
16603 "Instance ID/Table ID\n"
16604 "Metric for redistributed routes\n"
16605 "Default metric\n"
16606 "Route map reference\n"
16607 "Pointer to route-map entries\n")
16608 {
16609 int idx_protocol = 2;
16610 int idx_number = 3;
16611 char base_xpath[XPATH_MAXLEN];
16612
16613 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16614 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16615 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16616 argv[idx_protocol]->text, argv[idx_number]->arg);
16617
16618 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
16619
16620 return nb_cli_apply_changes(vty, base_xpath);
16621 }
16622
16623 ALIAS_HIDDEN(
16624 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
16625 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
16626 NO_STR
16627 "Redistribute information from another routing protocol\n"
16628 "Open Shortest Path First (OSPFv2)\n"
16629 "Non-main Kernel Routing Table\n"
16630 "Instance ID/Table ID\n"
16631 "Metric for redistributed routes\n"
16632 "Default metric\n"
16633 "Route map reference\n"
16634 "Pointer to route-map entries\n")
16635
16636 DEFUN_YANG (no_bgp_redistribute_ipv4,
16637 no_bgp_redistribute_ipv4_cmd,
16638 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
16639 NO_STR
16640 "Redistribute information from another routing protocol\n"
16641 FRR_IP_REDIST_HELP_STR_BGPD
16642 "Metric for redistributed routes\n"
16643 "Default metric\n"
16644 "Route map reference\n"
16645 "Pointer to route-map entries\n")
16646 {
16647 int idx_protocol = 2;
16648 char base_xpath[XPATH_MAXLEN];
16649
16650 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16651 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16652 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16653 argv[idx_protocol]->text, "0");
16654
16655 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
16656
16657 return nb_cli_apply_changes(vty, base_xpath);
16658 }
16659
16660 ALIAS_HIDDEN(
16661 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
16662 "no redistribute " FRR_IP_REDIST_STR_BGPD
16663 " [{metric (0-4294967295)|route-map WORD}]",
16664 NO_STR
16665 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16666 "Metric for redistributed routes\n"
16667 "Default metric\n"
16668 "Route map reference\n"
16669 "Pointer to route-map entries\n")
16670
16671 DEFUN_YANG (bgp_redistribute_ipv6,
16672 bgp_redistribute_ipv6_cmd,
16673 "redistribute " FRR_IP6_REDIST_STR_BGPD,
16674 "Redistribute information from another routing protocol\n"
16675 FRR_IP6_REDIST_HELP_STR_BGPD)
16676 {
16677 int idx_protocol = 1;
16678 char base_xpath[XPATH_MAXLEN];
16679
16680 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16681 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16682 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16683 argv[idx_protocol]->text, "0");
16684
16685 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16686
16687 return nb_cli_apply_changes(vty, base_xpath);
16688 }
16689
16690 DEFUN_YANG (bgp_redistribute_ipv6_rmap,
16691 bgp_redistribute_ipv6_rmap_cmd,
16692 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
16693 "Redistribute information from another routing protocol\n"
16694 FRR_IP6_REDIST_HELP_STR_BGPD
16695 "Route map reference\n"
16696 "Pointer to route-map entries\n")
16697 {
16698 int idx_protocol = 1;
16699 int idx_word = 3;
16700 char base_xpath[XPATH_MAXLEN];
16701
16702 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16703 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16704 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16705 argv[idx_protocol]->text, "0");
16706
16707 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16708 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16709 argv[idx_word]->arg);
16710
16711 return nb_cli_apply_changes(vty, base_xpath);
16712 }
16713
16714 DEFUN_YANG (bgp_redistribute_ipv6_metric,
16715 bgp_redistribute_ipv6_metric_cmd,
16716 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
16717 "Redistribute information from another routing protocol\n"
16718 FRR_IP6_REDIST_HELP_STR_BGPD
16719 "Metric for redistributed routes\n"
16720 "Default metric\n")
16721 {
16722 int idx_protocol = 1;
16723 int idx_number = 3;
16724 char base_xpath[XPATH_MAXLEN];
16725
16726 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16727 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16728 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16729 argv[idx_protocol]->text, "0");
16730
16731 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16732 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16733 argv[idx_number]->arg);
16734
16735 return nb_cli_apply_changes(vty, base_xpath);
16736 }
16737
16738 DEFUN_YANG(
16739 bgp_redistribute_ipv6_rmap_metric,
16740 bgp_redistribute_ipv6_rmap_metric_cmd,
16741 "redistribute " FRR_IP6_REDIST_STR_BGPD
16742 " route-map WORD metric (0-4294967295)",
16743 "Redistribute information from another routing protocol\n" FRR_IP6_REDIST_HELP_STR_BGPD
16744 "Route map reference\n"
16745 "Pointer to route-map entries\n"
16746 "Metric for redistributed routes\n"
16747 "Default metric\n")
16748 {
16749 int idx_protocol = 1;
16750 int idx_word = 3;
16751 int idx_number = 5;
16752 char base_xpath[XPATH_MAXLEN];
16753
16754 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16755 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16756 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16757 argv[idx_protocol]->text, "0");
16758
16759 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16760 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16761 argv[idx_word]->arg);
16762 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16763 argv[idx_number]->arg);
16764
16765 return nb_cli_apply_changes(vty, base_xpath);
16766 }
16767
16768 DEFUN_YANG(
16769 bgp_redistribute_ipv6_metric_rmap,
16770 bgp_redistribute_ipv6_metric_rmap_cmd,
16771 "redistribute " FRR_IP6_REDIST_STR_BGPD
16772 " metric (0-4294967295) route-map WORD",
16773 "Redistribute information from another routing protocol\n" FRR_IP6_REDIST_HELP_STR_BGPD
16774 "Metric for redistributed routes\n"
16775 "Default metric\n"
16776 "Route map reference\n"
16777 "Pointer to route-map entries\n")
16778 {
16779 int idx_protocol = 1;
16780 int idx_word = 5;
16781 int idx_number = 3;
16782 char base_xpath[XPATH_MAXLEN];
16783
16784 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16785 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16786 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16787 argv[idx_protocol]->text, "0");
16788
16789 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16790 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16791 argv[idx_number]->arg);
16792 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16793 argv[idx_word]->arg);
16794
16795 return nb_cli_apply_changes(vty, base_xpath);
16796 }
16797
16798 DEFUN_YANG(
16799 no_bgp_redistribute_ipv6,
16800 no_bgp_redistribute_ipv6_cmd,
16801 "no redistribute " FRR_IP6_REDIST_STR_BGPD
16802 " [{metric (0-4294967295)|route-map WORD}]",
16803 NO_STR
16804 "Redistribute information from another routing protocol\n" FRR_IP6_REDIST_HELP_STR_BGPD
16805 "Metric for redistributed routes\n"
16806 "Default metric\n"
16807 "Route map reference\n"
16808 "Pointer to route-map entries\n")
16809 {
16810 int idx_protocol = 2;
16811 char base_xpath[XPATH_MAXLEN];
16812
16813 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16814 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16815 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16816 argv[idx_protocol]->text, "0");
16817
16818 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
16819
16820 return nb_cli_apply_changes(vty, base_xpath);
16821 }
16822
16823 void cli_show_bgp_global_afi_safi_ip_unicast_redistribution_list(
16824 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
16825 {
16826 uint32_t instance = 0;
16827
16828 vty_out(vty, " redistribute %s",
16829 yang_dnode_get_string(dnode, "./route-type"));
16830 if ((instance = yang_dnode_get_uint16(dnode, "./route-instance")))
16831 vty_out(vty, " %d", instance);
16832 if (yang_dnode_exists(dnode, "./metric"))
16833 vty_out(vty, " metric %u",
16834 yang_dnode_get_uint32(dnode, "./metric"));
16835 if (yang_dnode_exists(dnode, "./rmap-policy-import"))
16836 vty_out(vty, " route-map %s",
16837 yang_dnode_get_string(dnode, "./rmap-policy-import"));
16838 vty_out(vty, "\n");
16839 }
16840
16841 /* Neighbor update tcp-mss. */
16842 static int peer_tcp_mss_vty(struct vty *vty, const char *peer_str,
16843 const char *tcp_mss_str)
16844 {
16845 struct peer *peer;
16846 uint32_t tcp_mss_val = 0;
16847
16848 peer = peer_and_group_lookup_vty(vty, peer_str);
16849 if (!peer)
16850 return CMD_WARNING_CONFIG_FAILED;
16851
16852 if (tcp_mss_str) {
16853 tcp_mss_val = strtoul(tcp_mss_str, NULL, 10);
16854 peer_tcp_mss_set(peer, tcp_mss_val);
16855 } else {
16856 peer_tcp_mss_unset(peer);
16857 }
16858
16859 return CMD_SUCCESS;
16860 }
16861
16862 DEFUN(neighbor_tcp_mss, neighbor_tcp_mss_cmd,
16863 "neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss (1-65535)",
16864 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16865 "TCP max segment size\n"
16866 "TCP MSS value\n")
16867 {
16868 int peer_index = 1;
16869 int mss_index = 3;
16870
16871 vty_out(vty,
16872 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16873 return peer_tcp_mss_vty(vty, argv[peer_index]->arg,
16874 argv[mss_index]->arg);
16875 }
16876
16877 DEFUN(no_neighbor_tcp_mss, no_neighbor_tcp_mss_cmd,
16878 "no neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss [(1-65535)]",
16879 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16880 "TCP max segment size\n"
16881 "TCP MSS value\n")
16882 {
16883 int peer_index = 2;
16884
16885 vty_out(vty,
16886 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16887 return peer_tcp_mss_vty(vty, argv[peer_index]->arg, NULL);
16888 }
16889
16890 static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
16891 afi_t afi, safi_t safi)
16892 {
16893 int i;
16894
16895 /* Unicast redistribution only. */
16896 if (safi != SAFI_UNICAST)
16897 return;
16898
16899 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
16900 /* Redistribute BGP does not make sense. */
16901 if (i != ZEBRA_ROUTE_BGP) {
16902 struct list *red_list;
16903 struct listnode *node;
16904 struct bgp_redist *red;
16905
16906 red_list = bgp->redist[afi][i];
16907 if (!red_list)
16908 continue;
16909
16910 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
16911 /* "redistribute" configuration. */
16912 vty_out(vty, " redistribute %s",
16913 zebra_route_string(i));
16914 if (red->instance)
16915 vty_out(vty, " %d", red->instance);
16916 if (red->redist_metric_flag)
16917 vty_out(vty, " metric %u",
16918 red->redist_metric);
16919 if (red->rmap.name)
16920 vty_out(vty, " route-map %s",
16921 red->rmap.name);
16922 vty_out(vty, "\n");
16923 }
16924 }
16925 }
16926 }
16927
16928 /* peer-group helpers for config-write */
16929
16930 static bool peergroup_flag_check(struct peer *peer, uint32_t flag)
16931 {
16932 if (!peer_group_active(peer)) {
16933 if (CHECK_FLAG(peer->flags_invert, flag))
16934 return !CHECK_FLAG(peer->flags, flag);
16935 else
16936 return !!CHECK_FLAG(peer->flags, flag);
16937 }
16938
16939 return !!CHECK_FLAG(peer->flags_override, flag);
16940 }
16941
16942 static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
16943 uint32_t flag)
16944 {
16945 if (!peer_group_active(peer)) {
16946 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
16947 return !peer_af_flag_check(peer, afi, safi, flag);
16948 else
16949 return !!peer_af_flag_check(peer, afi, safi, flag);
16950 }
16951
16952 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
16953 }
16954
16955 static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
16956 uint8_t type, int direct)
16957 {
16958 struct bgp_filter *filter;
16959
16960 if (peer_group_active(peer))
16961 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
16962 type);
16963
16964 filter = &peer->filter[afi][safi];
16965 switch (type) {
16966 case PEER_FT_DISTRIBUTE_LIST:
16967 return !!(filter->dlist[direct].name);
16968 case PEER_FT_FILTER_LIST:
16969 return !!(filter->aslist[direct].name);
16970 case PEER_FT_PREFIX_LIST:
16971 return !!(filter->plist[direct].name);
16972 case PEER_FT_ROUTE_MAP:
16973 return !!(filter->map[direct].name);
16974 case PEER_FT_UNSUPPRESS_MAP:
16975 return !!(filter->usmap.name);
16976 case PEER_FT_ADVERTISE_MAP:
16977 return !!(filter->advmap.aname
16978 && ((filter->advmap.condition == direct)
16979 && filter->advmap.cname));
16980 default:
16981 return false;
16982 }
16983 }
16984
16985 /* Return true if the addpath type is set for peer and different from
16986 * peer-group.
16987 */
16988 static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi,
16989 safi_t safi)
16990 {
16991 enum bgp_addpath_strat type, g_type;
16992
16993 type = peer->addpath_type[afi][safi];
16994
16995 if (type != BGP_ADDPATH_NONE) {
16996 if (peer_group_active(peer)) {
16997 g_type = peer->group->conf->addpath_type[afi][safi];
16998
16999 if (type != g_type)
17000 return true;
17001 else
17002 return false;
17003 }
17004
17005 return true;
17006 }
17007
17008 return false;
17009 }
17010
17011 /* This is part of the address-family block (unicast only) */
17012 static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
17013 afi_t afi)
17014 {
17015 int indent = 2;
17016
17017 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
17018 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
17019 BGP_CONFIG_VRF_TO_VRF_IMPORT))
17020 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
17021 bgp->vpn_policy[afi]
17022 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
17023 else
17024 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
17025 bgp->vpn_policy[afi]
17026 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
17027 }
17028 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
17029 BGP_CONFIG_VRF_TO_VRF_IMPORT)
17030 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
17031 BGP_CONFIG_VRF_TO_VRF_EXPORT))
17032 return;
17033
17034 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
17035 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
17036
17037 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
17038
17039 } else {
17040 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
17041 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
17042 bgp->vpn_policy[afi].tovpn_label);
17043 }
17044 }
17045 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
17046 BGP_VPN_POLICY_TOVPN_RD_SET)) {
17047 char buf[RD_ADDRSTRLEN];
17048 vty_out(vty, "%*srd vpn export %s\n", indent, "",
17049 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
17050 sizeof(buf)));
17051 }
17052 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
17053 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
17054
17055 char buf[PREFIX_STRLEN];
17056 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
17057 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
17058 sizeof(buf))) {
17059
17060 vty_out(vty, "%*snexthop vpn export %s\n",
17061 indent, "", buf);
17062 }
17063 }
17064 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
17065 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
17066 && ecommunity_cmp(
17067 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
17068 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
17069
17070 char *b = ecommunity_ecom2str(
17071 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
17072 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
17073 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
17074 XFREE(MTYPE_ECOMMUNITY_STR, b);
17075 } else {
17076 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
17077 char *b = ecommunity_ecom2str(
17078 bgp->vpn_policy[afi]
17079 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
17080 ECOMMUNITY_FORMAT_ROUTE_MAP,
17081 ECOMMUNITY_ROUTE_TARGET);
17082 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
17083 XFREE(MTYPE_ECOMMUNITY_STR, b);
17084 }
17085 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
17086 char *b = ecommunity_ecom2str(
17087 bgp->vpn_policy[afi]
17088 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
17089 ECOMMUNITY_FORMAT_ROUTE_MAP,
17090 ECOMMUNITY_ROUTE_TARGET);
17091 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
17092 XFREE(MTYPE_ECOMMUNITY_STR, b);
17093 }
17094 }
17095
17096 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
17097 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
17098 bgp->vpn_policy[afi]
17099 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
17100
17101 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
17102 char *b = ecommunity_ecom2str(
17103 bgp->vpn_policy[afi]
17104 .import_redirect_rtlist,
17105 ECOMMUNITY_FORMAT_ROUTE_MAP,
17106 ECOMMUNITY_ROUTE_TARGET);
17107
17108 if (bgp->vpn_policy[afi].import_redirect_rtlist->unit_size
17109 != ECOMMUNITY_SIZE)
17110 vty_out(vty, "%*srt6 redirect import %s\n",
17111 indent, "", b);
17112 else
17113 vty_out(vty, "%*srt redirect import %s\n",
17114 indent, "", b);
17115 XFREE(MTYPE_ECOMMUNITY_STR, b);
17116 }
17117 }
17118
17119 static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
17120 afi_t afi, safi_t safi)
17121 {
17122 struct bgp_filter *filter;
17123 char *addr;
17124
17125 addr = peer->host;
17126 filter = &peer->filter[afi][safi];
17127
17128 /* distribute-list. */
17129 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
17130 FILTER_IN))
17131 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
17132 filter->dlist[FILTER_IN].name);
17133
17134 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
17135 FILTER_OUT))
17136 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
17137 filter->dlist[FILTER_OUT].name);
17138
17139 /* prefix-list. */
17140 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
17141 FILTER_IN))
17142 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
17143 filter->plist[FILTER_IN].name);
17144
17145 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
17146 FILTER_OUT))
17147 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
17148 filter->plist[FILTER_OUT].name);
17149
17150 /* route-map. */
17151 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
17152 vty_out(vty, " neighbor %s route-map %s in\n", addr,
17153 filter->map[RMAP_IN].name);
17154
17155 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
17156 RMAP_OUT))
17157 vty_out(vty, " neighbor %s route-map %s out\n", addr,
17158 filter->map[RMAP_OUT].name);
17159
17160 /* unsuppress-map */
17161 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
17162 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
17163 filter->usmap.name);
17164
17165 /* advertise-map : always applied in OUT direction*/
17166 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
17167 CONDITION_NON_EXIST))
17168 vty_out(vty,
17169 " neighbor %s advertise-map %s non-exist-map %s\n",
17170 addr, filter->advmap.aname, filter->advmap.cname);
17171
17172 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
17173 CONDITION_EXIST))
17174 vty_out(vty, " neighbor %s advertise-map %s exist-map %s\n",
17175 addr, filter->advmap.aname, filter->advmap.cname);
17176
17177 /* filter-list. */
17178 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
17179 FILTER_IN))
17180 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
17181 filter->aslist[FILTER_IN].name);
17182
17183 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
17184 FILTER_OUT))
17185 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
17186 filter->aslist[FILTER_OUT].name);
17187 }
17188
17189 /* BGP peer configuration display function. */
17190 static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
17191 struct peer *peer)
17192 {
17193 struct peer *g_peer = NULL;
17194 char buf[SU_ADDRSTRLEN];
17195 char *addr;
17196 int if_pg_printed = false;
17197 int if_ras_printed = false;
17198
17199 /* Skip dynamic neighbors. */
17200 if (peer_dynamic_neighbor(peer))
17201 return;
17202
17203 if (peer->conf_if)
17204 addr = peer->conf_if;
17205 else
17206 addr = peer->host;
17207
17208 /************************************
17209 ****** Global to the neighbor ******
17210 ************************************/
17211 if (peer->conf_if) {
17212 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
17213 vty_out(vty, " neighbor %s interface v6only", addr);
17214 else
17215 vty_out(vty, " neighbor %s interface", addr);
17216
17217 if (peer_group_active(peer)) {
17218 vty_out(vty, " peer-group %s", peer->group->name);
17219 if_pg_printed = true;
17220 } else if (peer->as_type == AS_SPECIFIED) {
17221 vty_out(vty, " remote-as %u", peer->as);
17222 if_ras_printed = true;
17223 } else if (peer->as_type == AS_INTERNAL) {
17224 vty_out(vty, " remote-as internal");
17225 if_ras_printed = true;
17226 } else if (peer->as_type == AS_EXTERNAL) {
17227 vty_out(vty, " remote-as external");
17228 if_ras_printed = true;
17229 }
17230
17231 vty_out(vty, "\n");
17232 }
17233
17234 /* remote-as and peer-group */
17235 /* peer is a member of a peer-group */
17236 if (peer_group_active(peer)) {
17237 g_peer = peer->group->conf;
17238
17239 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
17240 if (peer->as_type == AS_SPECIFIED) {
17241 vty_out(vty, " neighbor %s remote-as %u\n",
17242 addr, peer->as);
17243 } else if (peer->as_type == AS_INTERNAL) {
17244 vty_out(vty,
17245 " neighbor %s remote-as internal\n",
17246 addr);
17247 } else if (peer->as_type == AS_EXTERNAL) {
17248 vty_out(vty,
17249 " neighbor %s remote-as external\n",
17250 addr);
17251 }
17252 }
17253
17254 /* For swpX peers we displayed the peer-group
17255 * via 'neighbor swpX interface peer-group PGNAME' */
17256 if (!if_pg_printed)
17257 vty_out(vty, " neighbor %s peer-group %s\n", addr,
17258 peer->group->name);
17259 }
17260
17261 /* peer is NOT a member of a peer-group */
17262 else {
17263 /* peer is a peer-group, declare the peer-group */
17264 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
17265 vty_out(vty, " neighbor %s peer-group\n", addr);
17266 }
17267
17268 if (!if_ras_printed) {
17269 if (peer->as_type == AS_SPECIFIED) {
17270 vty_out(vty, " neighbor %s remote-as %u\n",
17271 addr, peer->as);
17272 } else if (peer->as_type == AS_INTERNAL) {
17273 vty_out(vty,
17274 " neighbor %s remote-as internal\n",
17275 addr);
17276 } else if (peer->as_type == AS_EXTERNAL) {
17277 vty_out(vty,
17278 " neighbor %s remote-as external\n",
17279 addr);
17280 }
17281 }
17282 }
17283
17284 /* local-as */
17285 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
17286 vty_out(vty, " neighbor %s local-as %u", addr,
17287 peer->change_local_as);
17288 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
17289 vty_out(vty, " no-prepend");
17290 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
17291 vty_out(vty, " replace-as");
17292 vty_out(vty, "\n");
17293 }
17294
17295 /* description */
17296 if (peer->desc) {
17297 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
17298 }
17299
17300 /* shutdown */
17301 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
17302 if (peer->tx_shutdown_message)
17303 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
17304 peer->tx_shutdown_message);
17305 else
17306 vty_out(vty, " neighbor %s shutdown\n", addr);
17307 }
17308
17309 if (peergroup_flag_check(peer, PEER_FLAG_RTT_SHUTDOWN))
17310 vty_out(vty, " neighbor %s shutdown rtt %u count %u\n", addr,
17311 peer->rtt_expected, peer->rtt_keepalive_conf);
17312
17313 /* bfd */
17314 if (peer->bfd_config)
17315 bgp_bfd_peer_config_write(vty, peer, addr);
17316
17317 /* password */
17318 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
17319 vty_out(vty, " neighbor %s password %s\n", addr,
17320 peer->password);
17321
17322 /* neighbor solo */
17323 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
17324 if (!peer_group_active(peer)) {
17325 vty_out(vty, " neighbor %s solo\n", addr);
17326 }
17327 }
17328
17329 /* BGP port */
17330 if (peer->port != BGP_PORT_DEFAULT) {
17331 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
17332 }
17333
17334 /* Local interface name */
17335 if (peer->ifname) {
17336 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
17337 }
17338
17339 /* TCP max segment size */
17340 if (CHECK_FLAG(peer->flags, PEER_FLAG_TCP_MSS))
17341 vty_out(vty, " neighbor %s tcp-mss %d\n", addr, peer->tcp_mss);
17342
17343 /* passive */
17344 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
17345 vty_out(vty, " neighbor %s passive\n", addr);
17346
17347 /* ebgp-multihop */
17348 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
17349 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
17350 && peer->ttl == MAXTTL)) {
17351 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
17352 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
17353 peer->ttl);
17354 }
17355 }
17356
17357 /* ttl-security hops */
17358 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
17359 if (!peer_group_active(peer)
17360 || g_peer->gtsm_hops != peer->gtsm_hops) {
17361 vty_out(vty, " neighbor %s ttl-security hops %d\n",
17362 addr, peer->gtsm_hops);
17363 }
17364 }
17365
17366 /* disable-connected-check */
17367 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
17368 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
17369
17370 /* enforce-first-as */
17371 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
17372 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
17373
17374 /* update-source */
17375 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
17376 if (peer->update_source)
17377 vty_out(vty, " neighbor %s update-source %s\n", addr,
17378 sockunion2str(peer->update_source, buf,
17379 SU_ADDRSTRLEN));
17380 else if (peer->update_if)
17381 vty_out(vty, " neighbor %s update-source %s\n", addr,
17382 peer->update_if);
17383 }
17384
17385 /* advertisement-interval */
17386 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
17387 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
17388 peer->routeadv);
17389
17390 /* timers */
17391 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
17392 vty_out(vty, " neighbor %s timers %u %u\n", addr,
17393 peer->keepalive, peer->holdtime);
17394
17395 /* timers connect */
17396 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
17397 vty_out(vty, " neighbor %s timers connect %u\n", addr,
17398 peer->connect);
17399 /* need special-case handling for changed default values due to
17400 * config profile / version (because there is no "timers bgp connect"
17401 * command, we need to save this per-peer :/)
17402 */
17403 else if (!peer_group_active(peer) && !peer->connect &&
17404 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
17405 vty_out(vty, " neighbor %s timers connect %u\n", addr,
17406 peer->bgp->default_connect_retry);
17407
17408 /* timers delayopen */
17409 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_DELAYOPEN))
17410 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
17411 peer->delayopen);
17412 /* Save config even though flag is not set if default values have been
17413 * changed
17414 */
17415 else if (!peer_group_active(peer) && !peer->delayopen
17416 && peer->bgp->default_delayopen != BGP_DEFAULT_DELAYOPEN)
17417 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
17418 peer->bgp->default_delayopen);
17419
17420 /* capability dynamic */
17421 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
17422 vty_out(vty, " neighbor %s capability dynamic\n", addr);
17423
17424 /* capability extended-nexthop */
17425 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
17426 if (!peer->conf_if) {
17427 if (CHECK_FLAG(peer->flags_invert,
17428 PEER_FLAG_CAPABILITY_ENHE))
17429 vty_out(vty,
17430 " no neighbor %s capability extended-nexthop\n",
17431 addr);
17432 else
17433 vty_out(vty,
17434 " neighbor %s capability extended-nexthop\n",
17435 addr);
17436 }
17437 }
17438
17439 /* dont-capability-negotiation */
17440 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
17441 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
17442
17443 /* override-capability */
17444 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
17445 vty_out(vty, " neighbor %s override-capability\n", addr);
17446
17447 /* strict-capability-match */
17448 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
17449 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
17450
17451 /* Sender side AS path loop detection. */
17452 if (peer->as_path_loop_detection)
17453 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
17454 addr);
17455
17456 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
17457 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
17458
17459 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
17460 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
17461 vty_out(vty,
17462 " neighbor %s graceful-restart-helper\n", addr);
17463 } else if (CHECK_FLAG(
17464 peer->peer_gr_new_status_flag,
17465 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
17466 vty_out(vty,
17467 " neighbor %s graceful-restart\n", addr);
17468 } else if (
17469 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
17470 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
17471 && !(CHECK_FLAG(
17472 peer->peer_gr_new_status_flag,
17473 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
17474 vty_out(vty, " neighbor %s graceful-restart-disable\n",
17475 addr);
17476 }
17477 }
17478 }
17479
17480 /* BGP peer configuration display function. */
17481 static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
17482 struct peer *peer, afi_t afi, safi_t safi)
17483 {
17484 struct peer *g_peer = NULL;
17485 char *addr;
17486 bool flag_scomm, flag_secomm, flag_slcomm;
17487
17488 /* Skip dynamic neighbors. */
17489 if (peer_dynamic_neighbor(peer))
17490 return;
17491
17492 if (peer->conf_if)
17493 addr = peer->conf_if;
17494 else
17495 addr = peer->host;
17496
17497 /************************************
17498 ****** Per AF to the neighbor ******
17499 ************************************/
17500 if (peer_group_active(peer)) {
17501 g_peer = peer->group->conf;
17502
17503 /* If the peer-group is active but peer is not, print a 'no
17504 * activate' */
17505 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
17506 vty_out(vty, " no neighbor %s activate\n", addr);
17507 }
17508
17509 /* If the peer-group is not active but peer is, print an
17510 'activate' */
17511 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
17512 vty_out(vty, " neighbor %s activate\n", addr);
17513 }
17514 } else {
17515 if (peer->afc[afi][safi]) {
17516 if (safi == SAFI_ENCAP)
17517 vty_out(vty, " neighbor %s activate\n", addr);
17518 else if (!bgp->default_af[afi][safi])
17519 vty_out(vty, " neighbor %s activate\n", addr);
17520 } else {
17521 if (bgp->default_af[afi][safi])
17522 vty_out(vty, " no neighbor %s activate\n",
17523 addr);
17524 }
17525 }
17526
17527 /* addpath TX knobs */
17528 if (peergroup_af_addpath_check(peer, afi, safi)) {
17529 switch (peer->addpath_type[afi][safi]) {
17530 case BGP_ADDPATH_ALL:
17531 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
17532 addr);
17533 break;
17534 case BGP_ADDPATH_BEST_PER_AS:
17535 vty_out(vty,
17536 " neighbor %s addpath-tx-bestpath-per-AS\n",
17537 addr);
17538 break;
17539 case BGP_ADDPATH_MAX:
17540 case BGP_ADDPATH_NONE:
17541 break;
17542 }
17543 }
17544
17545 /* ORF capability. */
17546 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
17547 || peergroup_af_flag_check(peer, afi, safi,
17548 PEER_FLAG_ORF_PREFIX_RM)) {
17549 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
17550
17551 if (peergroup_af_flag_check(peer, afi, safi,
17552 PEER_FLAG_ORF_PREFIX_SM)
17553 && peergroup_af_flag_check(peer, afi, safi,
17554 PEER_FLAG_ORF_PREFIX_RM))
17555 vty_out(vty, " both");
17556 else if (peergroup_af_flag_check(peer, afi, safi,
17557 PEER_FLAG_ORF_PREFIX_SM))
17558 vty_out(vty, " send");
17559 else
17560 vty_out(vty, " receive");
17561 vty_out(vty, "\n");
17562 }
17563
17564 /* Route reflector client. */
17565 if (peergroup_af_flag_check(peer, afi, safi,
17566 PEER_FLAG_REFLECTOR_CLIENT)) {
17567 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
17568 }
17569
17570 /* next-hop-self force */
17571 if (peergroup_af_flag_check(peer, afi, safi,
17572 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
17573 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
17574 }
17575
17576 /* next-hop-self */
17577 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
17578 vty_out(vty, " neighbor %s next-hop-self\n", addr);
17579 }
17580
17581 /* remove-private-AS */
17582 if (peergroup_af_flag_check(peer, afi, safi,
17583 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
17584 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
17585 addr);
17586 }
17587
17588 else if (peergroup_af_flag_check(peer, afi, safi,
17589 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
17590 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
17591 addr);
17592 }
17593
17594 else if (peergroup_af_flag_check(peer, afi, safi,
17595 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
17596 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
17597 }
17598
17599 else if (peergroup_af_flag_check(peer, afi, safi,
17600 PEER_FLAG_REMOVE_PRIVATE_AS)) {
17601 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
17602 }
17603
17604 /* as-override */
17605 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
17606 vty_out(vty, " neighbor %s as-override\n", addr);
17607 }
17608
17609 /* send-community print. */
17610 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
17611 PEER_FLAG_SEND_COMMUNITY);
17612 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
17613 PEER_FLAG_SEND_EXT_COMMUNITY);
17614 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
17615 PEER_FLAG_SEND_LARGE_COMMUNITY);
17616
17617 if (flag_scomm && flag_secomm && flag_slcomm) {
17618 vty_out(vty, " no neighbor %s send-community all\n", addr);
17619 } else {
17620 if (flag_scomm)
17621 vty_out(vty, " no neighbor %s send-community\n", addr);
17622 if (flag_secomm)
17623 vty_out(vty,
17624 " no neighbor %s send-community extended\n",
17625 addr);
17626
17627 if (flag_slcomm)
17628 vty_out(vty, " no neighbor %s send-community large\n",
17629 addr);
17630 }
17631
17632 /* Default information */
17633 if (peergroup_af_flag_check(peer, afi, safi,
17634 PEER_FLAG_DEFAULT_ORIGINATE)) {
17635 vty_out(vty, " neighbor %s default-originate", addr);
17636
17637 if (peer->default_rmap[afi][safi].name)
17638 vty_out(vty, " route-map %s",
17639 peer->default_rmap[afi][safi].name);
17640
17641 vty_out(vty, "\n");
17642 }
17643
17644 /* Soft reconfiguration inbound. */
17645 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
17646 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
17647 addr);
17648 }
17649
17650 /* maximum-prefix. */
17651 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
17652 vty_out(vty, " neighbor %s maximum-prefix %u", addr,
17653 peer->pmax[afi][safi]);
17654
17655 if (peer->pmax_threshold[afi][safi]
17656 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
17657 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
17658 if (peer_af_flag_check(peer, afi, safi,
17659 PEER_FLAG_MAX_PREFIX_WARNING))
17660 vty_out(vty, " warning-only");
17661 if (peer->pmax_restart[afi][safi])
17662 vty_out(vty, " restart %u",
17663 peer->pmax_restart[afi][safi]);
17664 if (peer_af_flag_check(peer, afi, safi,
17665 PEER_FLAG_MAX_PREFIX_FORCE))
17666 vty_out(vty, " force");
17667
17668 vty_out(vty, "\n");
17669 }
17670
17671 /* maximum-prefix-out */
17672 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
17673 vty_out(vty, " neighbor %s maximum-prefix-out %u\n",
17674 addr, peer->pmax_out[afi][safi]);
17675
17676 /* Route server client. */
17677 if (peergroup_af_flag_check(peer, afi, safi,
17678 PEER_FLAG_RSERVER_CLIENT)) {
17679 vty_out(vty, " neighbor %s route-server-client\n", addr);
17680 }
17681
17682 /* Nexthop-local unchanged. */
17683 if (peergroup_af_flag_check(peer, afi, safi,
17684 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
17685 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
17686 }
17687
17688 /* allowas-in <1-10> */
17689 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
17690 if (peer_af_flag_check(peer, afi, safi,
17691 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
17692 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
17693 } else if (peer->allowas_in[afi][safi] == 3) {
17694 vty_out(vty, " neighbor %s allowas-in\n", addr);
17695 } else {
17696 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
17697 peer->allowas_in[afi][safi]);
17698 }
17699 }
17700
17701 /* weight */
17702 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
17703 vty_out(vty, " neighbor %s weight %lu\n", addr,
17704 peer->weight[afi][safi]);
17705
17706 /* Filter. */
17707 bgp_config_write_filter(vty, peer, afi, safi);
17708
17709 /* atribute-unchanged. */
17710 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
17711 || (safi != SAFI_EVPN
17712 && peer_af_flag_check(peer, afi, safi,
17713 PEER_FLAG_NEXTHOP_UNCHANGED))
17714 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
17715
17716 if (!peer_group_active(peer)
17717 || peergroup_af_flag_check(peer, afi, safi,
17718 PEER_FLAG_AS_PATH_UNCHANGED)
17719 || peergroup_af_flag_check(peer, afi, safi,
17720 PEER_FLAG_NEXTHOP_UNCHANGED)
17721 || peergroup_af_flag_check(peer, afi, safi,
17722 PEER_FLAG_MED_UNCHANGED)) {
17723
17724 vty_out(vty,
17725 " neighbor %s attribute-unchanged%s%s%s\n",
17726 addr,
17727 peer_af_flag_check(peer, afi, safi,
17728 PEER_FLAG_AS_PATH_UNCHANGED)
17729 ? " as-path"
17730 : "",
17731 peer_af_flag_check(peer, afi, safi,
17732 PEER_FLAG_NEXTHOP_UNCHANGED)
17733 ? " next-hop"
17734 : "",
17735 peer_af_flag_check(peer, afi, safi,
17736 PEER_FLAG_MED_UNCHANGED)
17737 ? " med"
17738 : "");
17739 }
17740 }
17741
17742 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_CONFIG_DAMPENING))
17743 bgp_config_write_peer_damp(vty, peer, afi, safi);
17744 }
17745
17746 /* Address family based peer configuration display. */
17747 static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
17748 safi_t safi)
17749 {
17750 struct peer *peer;
17751 struct peer_group *group;
17752 struct listnode *node, *nnode;
17753
17754
17755 vty_frame(vty, " !\n address-family ");
17756 if (afi == AFI_IP) {
17757 if (safi == SAFI_UNICAST)
17758 vty_frame(vty, "ipv4 unicast");
17759 else if (safi == SAFI_LABELED_UNICAST)
17760 vty_frame(vty, "ipv4 labeled-unicast");
17761 else if (safi == SAFI_MULTICAST)
17762 vty_frame(vty, "ipv4 multicast");
17763 else if (safi == SAFI_MPLS_VPN)
17764 vty_frame(vty, "ipv4 vpn");
17765 else if (safi == SAFI_ENCAP)
17766 vty_frame(vty, "ipv4 encap");
17767 else if (safi == SAFI_FLOWSPEC)
17768 vty_frame(vty, "ipv4 flowspec");
17769 } else if (afi == AFI_IP6) {
17770 if (safi == SAFI_UNICAST)
17771 vty_frame(vty, "ipv6 unicast");
17772 else if (safi == SAFI_LABELED_UNICAST)
17773 vty_frame(vty, "ipv6 labeled-unicast");
17774 else if (safi == SAFI_MULTICAST)
17775 vty_frame(vty, "ipv6 multicast");
17776 else if (safi == SAFI_MPLS_VPN)
17777 vty_frame(vty, "ipv6 vpn");
17778 else if (safi == SAFI_ENCAP)
17779 vty_frame(vty, "ipv6 encap");
17780 else if (safi == SAFI_FLOWSPEC)
17781 vty_frame(vty, "ipv6 flowspec");
17782 } else if (afi == AFI_L2VPN) {
17783 if (safi == SAFI_EVPN)
17784 vty_frame(vty, "l2vpn evpn");
17785 }
17786 vty_frame(vty, "\n");
17787
17788 bgp_config_write_distance(vty, bgp, afi, safi);
17789
17790 bgp_config_write_network(vty, bgp, afi, safi);
17791
17792 bgp_config_write_redistribute(vty, bgp, afi, safi);
17793
17794 /* BGP flag dampening. */
17795 if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
17796 bgp_config_write_damp(vty, bgp, afi, safi);
17797
17798 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
17799 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
17800
17801 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17802 /* Do not display doppelganger peers */
17803 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17804 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
17805 }
17806
17807 bgp_config_write_maxpaths(vty, bgp, afi, safi);
17808 bgp_config_write_table_map(vty, bgp, afi, safi);
17809
17810 if (safi == SAFI_EVPN)
17811 bgp_config_write_evpn_info(vty, bgp, afi, safi);
17812
17813 if (safi == SAFI_FLOWSPEC)
17814 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
17815
17816 if (safi == SAFI_UNICAST) {
17817 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
17818 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17819 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
17820
17821 vty_out(vty, " export vpn\n");
17822 }
17823 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17824 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
17825
17826 vty_out(vty, " import vpn\n");
17827 }
17828 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17829 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
17830 char *name;
17831
17832 for (ALL_LIST_ELEMENTS_RO(
17833 bgp->vpn_policy[afi].import_vrf, node,
17834 name))
17835 vty_out(vty, " import vrf %s\n", name);
17836 }
17837 }
17838
17839 vty_endframe(vty, " exit-address-family\n");
17840 }
17841
17842 int bgp_config_write(struct vty *vty)
17843 {
17844 struct bgp *bgp;
17845 struct peer_group *group;
17846 struct peer *peer;
17847 struct listnode *node, *nnode;
17848 struct listnode *mnode, *mnnode;
17849 afi_t afi;
17850 safi_t safi;
17851
17852 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
17853 vty_out(vty, "bgp route-map delay-timer %u\n",
17854 bm->rmap_update_timer);
17855
17856 if (bm->v_update_delay != BGP_UPDATE_DELAY_DEF) {
17857 vty_out(vty, "bgp update-delay %d", bm->v_update_delay);
17858 if (bm->v_update_delay != bm->v_establish_wait)
17859 vty_out(vty, " %d", bm->v_establish_wait);
17860 vty_out(vty, "\n");
17861 }
17862
17863 if (bm->wait_for_fib)
17864 vty_out(vty, "bgp suppress-fib-pending\n");
17865
17866 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17867 vty_out(vty, "bgp graceful-shutdown\n");
17868
17869 /* No-RIB (Zebra) option flag configuration */
17870 if (bgp_option_check(BGP_OPT_NO_FIB))
17871 vty_out(vty, "bgp no-rib\n");
17872
17873 if (!CHECK_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA))
17874 vty_out(vty, "no bgp send-extra-data zebra\n");
17875
17876 /* BGP configuration. */
17877 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
17878
17879 /* skip all auto created vrf as they dont have user config */
17880 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
17881 continue;
17882
17883 /* Router bgp ASN */
17884 vty_out(vty, "router bgp %u", bgp->as);
17885
17886 if (bgp->name)
17887 vty_out(vty, " %s %s",
17888 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
17889 ? "view" : "vrf", bgp->name);
17890 vty_out(vty, "\n");
17891
17892 /* BGP fast-external-failover. */
17893 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
17894 vty_out(vty, " no bgp fast-external-failover\n");
17895
17896 /* BGP router ID. */
17897 if (bgp->router_id_static.s_addr != INADDR_ANY)
17898 vty_out(vty, " bgp router-id %pI4\n",
17899 &bgp->router_id_static);
17900
17901 /* Suppress fib pending */
17902 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_FIB_PENDING))
17903 vty_out(vty, " bgp suppress-fib-pending\n");
17904
17905 /* BGP log-neighbor-changes. */
17906 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
17907 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
17908 vty_out(vty, " %sbgp log-neighbor-changes\n",
17909 CHECK_FLAG(bgp->flags,
17910 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
17911 ? ""
17912 : "no ");
17913
17914 /* BGP configuration. */
17915 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
17916 vty_out(vty, " bgp always-compare-med\n");
17917
17918 /* RFC8212 default eBGP policy. */
17919 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
17920 != SAVE_BGP_EBGP_REQUIRES_POLICY)
17921 vty_out(vty, " %sbgp ebgp-requires-policy\n",
17922 CHECK_FLAG(bgp->flags,
17923 BGP_FLAG_EBGP_REQUIRES_POLICY)
17924 ? ""
17925 : "no ");
17926
17927 /* draft-ietf-idr-deprecate-as-set-confed-set */
17928 if (bgp->reject_as_sets)
17929 vty_out(vty, " bgp reject-as-sets\n");
17930
17931 /* Suppress duplicate updates if the route actually not changed
17932 */
17933 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES)
17934 != SAVE_BGP_SUPPRESS_DUPLICATES)
17935 vty_out(vty, " %sbgp suppress-duplicates\n",
17936 CHECK_FLAG(bgp->flags,
17937 BGP_FLAG_SUPPRESS_DUPLICATES)
17938 ? ""
17939 : "no ");
17940
17941 /* BGP default <afi>-<safi> */
17942 FOREACH_AFI_SAFI (afi, safi) {
17943 if (afi == AFI_IP && safi == SAFI_UNICAST) {
17944 if (!bgp->default_af[afi][safi])
17945 vty_out(vty, " no bgp default %s\n",
17946 get_bgp_default_af_flag(afi,
17947 safi));
17948 } else if (bgp->default_af[afi][safi])
17949 vty_out(vty, " bgp default %s\n",
17950 get_bgp_default_af_flag(afi, safi));
17951 }
17952
17953 /* BGP default local-preference. */
17954 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
17955 vty_out(vty, " bgp default local-preference %u\n",
17956 bgp->default_local_pref);
17957
17958 /* BGP default show-hostname */
17959 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
17960 != SAVE_BGP_SHOW_HOSTNAME)
17961 vty_out(vty, " %sbgp default show-hostname\n",
17962 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
17963 ? ""
17964 : "no ");
17965
17966 /* BGP default show-nexthop-hostname */
17967 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17968 != SAVE_BGP_SHOW_HOSTNAME)
17969 vty_out(vty, " %sbgp default show-nexthop-hostname\n",
17970 CHECK_FLAG(bgp->flags,
17971 BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17972 ? ""
17973 : "no ");
17974
17975 /* BGP default subgroup-pkt-queue-max. */
17976 if (bgp->default_subgroup_pkt_queue_max
17977 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
17978 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
17979 bgp->default_subgroup_pkt_queue_max);
17980
17981 /* BGP client-to-client reflection. */
17982 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
17983 vty_out(vty, " no bgp client-to-client reflection\n");
17984
17985 /* BGP cluster ID. */
17986 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
17987 vty_out(vty, " bgp cluster-id %pI4\n",
17988 &bgp->cluster_id);
17989
17990 /* Disable ebgp connected nexthop check */
17991 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
17992 vty_out(vty,
17993 " bgp disable-ebgp-connected-route-check\n");
17994
17995 /* Confederation identifier*/
17996 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
17997 vty_out(vty, " bgp confederation identifier %u\n",
17998 bgp->confed_id);
17999
18000 /* Confederation peer */
18001 if (bgp->confed_peers_cnt > 0) {
18002 int i;
18003
18004 vty_out(vty, " bgp confederation peers");
18005
18006 for (i = 0; i < bgp->confed_peers_cnt; i++)
18007 vty_out(vty, " %u", bgp->confed_peers[i]);
18008
18009 vty_out(vty, "\n");
18010 }
18011
18012 /* BGP deterministic-med. */
18013 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
18014 != SAVE_BGP_DETERMINISTIC_MED)
18015 vty_out(vty, " %sbgp deterministic-med\n",
18016 CHECK_FLAG(bgp->flags,
18017 BGP_FLAG_DETERMINISTIC_MED)
18018 ? ""
18019 : "no ");
18020
18021 /* BGP update-delay. */
18022 bgp_config_write_update_delay(vty, bgp);
18023
18024 if (bgp->v_maxmed_onstartup
18025 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
18026 vty_out(vty, " bgp max-med on-startup %u",
18027 bgp->v_maxmed_onstartup);
18028 if (bgp->maxmed_onstartup_value
18029 != BGP_MAXMED_VALUE_DEFAULT)
18030 vty_out(vty, " %u",
18031 bgp->maxmed_onstartup_value);
18032 vty_out(vty, "\n");
18033 }
18034 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
18035 vty_out(vty, " bgp max-med administrative");
18036 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
18037 vty_out(vty, " %u", bgp->maxmed_admin_value);
18038 vty_out(vty, "\n");
18039 }
18040
18041 /* write quanta */
18042 bgp_config_write_wpkt_quanta(vty, bgp);
18043 /* read quanta */
18044 bgp_config_write_rpkt_quanta(vty, bgp);
18045
18046 /* coalesce time */
18047 bgp_config_write_coalesce_time(vty, bgp);
18048
18049 /* BGP per-instance graceful-shutdown */
18050 /* BGP-wide settings and per-instance settings are mutually
18051 * exclusive.
18052 */
18053 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
18054 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
18055 vty_out(vty, " bgp graceful-shutdown\n");
18056
18057 /* BGP graceful-restart. */
18058 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
18059 vty_out(vty,
18060 " bgp graceful-restart stalepath-time %u\n",
18061 bgp->stalepath_time);
18062
18063 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
18064 vty_out(vty, " bgp graceful-restart restart-time %u\n",
18065 bgp->restart_time);
18066
18067 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
18068 vty_out(vty,
18069 " bgp graceful-restart select-defer-time %u\n",
18070 bgp->select_defer_time);
18071
18072 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
18073 vty_out(vty, " bgp graceful-restart\n");
18074
18075 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
18076 vty_out(vty, " bgp graceful-restart-disable\n");
18077
18078 /* BGP graceful-restart Preserve State F bit. */
18079 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
18080 vty_out(vty,
18081 " bgp graceful-restart preserve-fw-state\n");
18082
18083 /* Stale timer for RIB */
18084 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
18085 vty_out(vty,
18086 " bgp graceful-restart rib-stale-time %u\n",
18087 bgp->rib_stale_time);
18088
18089 /* BGP bestpath method. */
18090 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
18091 vty_out(vty, " bgp bestpath as-path ignore\n");
18092 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
18093 vty_out(vty, " bgp bestpath as-path confed\n");
18094
18095 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
18096 if (CHECK_FLAG(bgp->flags,
18097 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
18098 vty_out(vty,
18099 " bgp bestpath as-path multipath-relax as-set\n");
18100 } else {
18101 vty_out(vty,
18102 " bgp bestpath as-path multipath-relax\n");
18103 }
18104 }
18105
18106 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
18107 vty_out(vty,
18108 " bgp route-reflector allow-outbound-policy\n");
18109 }
18110 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
18111 vty_out(vty, " bgp bestpath compare-routerid\n");
18112 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
18113 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
18114 vty_out(vty, " bgp bestpath med");
18115 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
18116 vty_out(vty, " confed");
18117 if (CHECK_FLAG(bgp->flags,
18118 BGP_FLAG_MED_MISSING_AS_WORST))
18119 vty_out(vty, " missing-as-worst");
18120 vty_out(vty, "\n");
18121 }
18122
18123 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
18124 vty_out(vty,
18125 " bgp bestpath peer-type multipath-relax\n");
18126
18127 /* Link bandwidth handling. */
18128 if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW)
18129 vty_out(vty, " bgp bestpath bandwidth ignore\n");
18130 else if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
18131 vty_out(vty, " bgp bestpath bandwidth skip-missing\n");
18132 else if (bgp->lb_handling == BGP_LINK_BW_DEFWT_4_MISSING)
18133 vty_out(vty, " bgp bestpath bandwidth default-weight-for-missing\n");
18134
18135 /* BGP network import check. */
18136 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
18137 != SAVE_BGP_IMPORT_CHECK)
18138 vty_out(vty, " %sbgp network import-check\n",
18139 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
18140 ? ""
18141 : "no ");
18142
18143 /* BGP timers configuration. */
18144 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
18145 || bgp->default_holdtime != SAVE_BGP_HOLDTIME)
18146 vty_out(vty, " timers bgp %u %u\n",
18147 bgp->default_keepalive, bgp->default_holdtime);
18148
18149 /* peer-group */
18150 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
18151 bgp_config_write_peer_global(vty, bgp, group->conf);
18152 }
18153
18154 /* Normal neighbor configuration. */
18155 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
18156 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
18157 bgp_config_write_peer_global(vty, bgp, peer);
18158 }
18159
18160 /* listen range and limit for dynamic BGP neighbors */
18161 bgp_config_write_listen(vty, bgp);
18162
18163 /*
18164 * BGP default autoshutdown neighbors
18165 *
18166 * This must be placed after any peer and peer-group
18167 * configuration, to avoid setting all peers to shutdown after
18168 * a daemon restart, which is undesired behavior. (see #2286)
18169 */
18170 if (bgp->autoshutdown)
18171 vty_out(vty, " bgp default shutdown\n");
18172
18173 /* BGP instance administrative shutdown */
18174 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN))
18175 vty_out(vty, " bgp shutdown\n");
18176
18177 if (bgp->srv6_enabled) {
18178 vty_frame(vty, " !\n segment-routing srv6\n");
18179 if (strlen(bgp->srv6_locator_name))
18180 vty_out(vty, " locator %s\n",
18181 bgp->srv6_locator_name);
18182 }
18183
18184
18185 /* IPv4 unicast configuration. */
18186 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
18187
18188 /* IPv4 multicast configuration. */
18189 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
18190
18191 /* IPv4 labeled-unicast configuration. */
18192 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
18193
18194 /* IPv4 VPN configuration. */
18195 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
18196
18197 /* ENCAPv4 configuration. */
18198 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
18199
18200 /* FLOWSPEC v4 configuration. */
18201 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
18202
18203 /* IPv6 unicast configuration. */
18204 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
18205
18206 /* IPv6 multicast configuration. */
18207 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
18208
18209 /* IPv6 labeled-unicast configuration. */
18210 bgp_config_write_family(vty, bgp, AFI_IP6,
18211 SAFI_LABELED_UNICAST);
18212
18213 /* IPv6 VPN configuration. */
18214 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
18215
18216 /* ENCAPv6 configuration. */
18217 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
18218
18219 /* FLOWSPEC v6 configuration. */
18220 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
18221
18222 /* EVPN configuration. */
18223 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
18224
18225 hook_call(bgp_inst_config_write, bgp, vty);
18226
18227 #ifdef ENABLE_BGP_VNC
18228 bgp_rfapi_cfg_write(vty, bgp);
18229 #endif
18230
18231 vty_out(vty, "!\n");
18232 }
18233 return 0;
18234 }
18235
18236
18237 /* BGP node structure. */
18238 static struct cmd_node bgp_node = {
18239 .name = "bgp",
18240 .node = BGP_NODE,
18241 .parent_node = CONFIG_NODE,
18242 .prompt = "%s(config-router)# ",
18243 .config_write = bgp_config_write,
18244 };
18245
18246 static struct cmd_node bgp_ipv4_unicast_node = {
18247 .name = "bgp ipv4 unicast",
18248 .node = BGP_IPV4_NODE,
18249 .parent_node = BGP_NODE,
18250 .prompt = "%s(config-router-af)# ",
18251 };
18252
18253 static struct cmd_node bgp_ipv4_multicast_node = {
18254 .name = "bgp ipv4 multicast",
18255 .node = BGP_IPV4M_NODE,
18256 .parent_node = BGP_NODE,
18257 .prompt = "%s(config-router-af)# ",
18258 };
18259
18260 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
18261 .name = "bgp ipv4 labeled unicast",
18262 .node = BGP_IPV4L_NODE,
18263 .parent_node = BGP_NODE,
18264 .prompt = "%s(config-router-af)# ",
18265 };
18266
18267 static struct cmd_node bgp_ipv6_unicast_node = {
18268 .name = "bgp ipv6",
18269 .node = BGP_IPV6_NODE,
18270 .parent_node = BGP_NODE,
18271 .prompt = "%s(config-router-af)# ",
18272 };
18273
18274 static struct cmd_node bgp_ipv6_multicast_node = {
18275 .name = "bgp ipv6 multicast",
18276 .node = BGP_IPV6M_NODE,
18277 .parent_node = BGP_NODE,
18278 .prompt = "%s(config-router-af)# ",
18279 };
18280
18281 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
18282 .name = "bgp ipv6 labeled unicast",
18283 .node = BGP_IPV6L_NODE,
18284 .parent_node = BGP_NODE,
18285 .prompt = "%s(config-router-af)# ",
18286 };
18287
18288 static struct cmd_node bgp_vpnv4_node = {
18289 .name = "bgp vpnv4",
18290 .node = BGP_VPNV4_NODE,
18291 .parent_node = BGP_NODE,
18292 .prompt = "%s(config-router-af)# ",
18293 };
18294
18295 static struct cmd_node bgp_vpnv6_node = {
18296 .name = "bgp vpnv6",
18297 .node = BGP_VPNV6_NODE,
18298 .parent_node = BGP_NODE,
18299 .prompt = "%s(config-router-af-vpnv6)# ",
18300 };
18301
18302 static struct cmd_node bgp_evpn_node = {
18303 .name = "bgp evpn",
18304 .node = BGP_EVPN_NODE,
18305 .parent_node = BGP_NODE,
18306 .prompt = "%s(config-router-evpn)# ",
18307 };
18308
18309 static struct cmd_node bgp_evpn_vni_node = {
18310 .name = "bgp evpn vni",
18311 .node = BGP_EVPN_VNI_NODE,
18312 .parent_node = BGP_EVPN_NODE,
18313 .prompt = "%s(config-router-af-vni)# ",
18314 };
18315
18316 static struct cmd_node bgp_flowspecv4_node = {
18317 .name = "bgp ipv4 flowspec",
18318 .node = BGP_FLOWSPECV4_NODE,
18319 .parent_node = BGP_NODE,
18320 .prompt = "%s(config-router-af)# ",
18321 };
18322
18323 static struct cmd_node bgp_flowspecv6_node = {
18324 .name = "bgp ipv6 flowspec",
18325 .node = BGP_FLOWSPECV6_NODE,
18326 .parent_node = BGP_NODE,
18327 .prompt = "%s(config-router-af-vpnv6)# ",
18328 };
18329
18330 static struct cmd_node bgp_srv6_node = {
18331 .name = "bgp srv6",
18332 .node = BGP_SRV6_NODE,
18333 .parent_node = BGP_NODE,
18334 .prompt = "%s(config-router-srv6)# ",
18335 };
18336
18337 static void community_list_vty(void);
18338
18339 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
18340 {
18341 struct bgp *bgp;
18342 struct peer *peer;
18343 struct listnode *lnbgp, *lnpeer;
18344
18345 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
18346 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
18347 /* only provide suggestions on the appropriate input
18348 * token type,
18349 * they'll otherwise show up multiple times */
18350 enum cmd_token_type match_type;
18351 char *name = peer->host;
18352
18353 if (peer->conf_if) {
18354 match_type = VARIABLE_TKN;
18355 name = peer->conf_if;
18356 } else if (strchr(peer->host, ':'))
18357 match_type = IPV6_TKN;
18358 else
18359 match_type = IPV4_TKN;
18360
18361 if (token->type != match_type)
18362 continue;
18363
18364 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
18365 }
18366 }
18367 }
18368
18369 static const struct cmd_variable_handler bgp_var_neighbor[] = {
18370 {.varname = "neighbor", .completions = bgp_ac_neighbor},
18371 {.varname = "neighbors", .completions = bgp_ac_neighbor},
18372 {.varname = "peer", .completions = bgp_ac_neighbor},
18373 {.completions = NULL}};
18374
18375 static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
18376 {
18377 struct bgp *bgp;
18378 struct peer_group *group;
18379 struct listnode *lnbgp, *lnpeer;
18380
18381 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
18382 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
18383 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
18384 group->name));
18385 }
18386 }
18387
18388 static const struct cmd_variable_handler bgp_var_peergroup[] = {
18389 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
18390 {.completions = NULL} };
18391
18392 void bgp_vty_init(void)
18393 {
18394 cmd_variable_handler_register(bgp_var_neighbor);
18395 cmd_variable_handler_register(bgp_var_peergroup);
18396
18397 /* Install bgp top node. */
18398 install_node(&bgp_node);
18399 install_node(&bgp_ipv4_unicast_node);
18400 install_node(&bgp_ipv4_multicast_node);
18401 install_node(&bgp_ipv4_labeled_unicast_node);
18402 install_node(&bgp_ipv6_unicast_node);
18403 install_node(&bgp_ipv6_multicast_node);
18404 install_node(&bgp_ipv6_labeled_unicast_node);
18405 install_node(&bgp_vpnv4_node);
18406 install_node(&bgp_vpnv6_node);
18407 install_node(&bgp_evpn_node);
18408 install_node(&bgp_evpn_vni_node);
18409 install_node(&bgp_flowspecv4_node);
18410 install_node(&bgp_flowspecv6_node);
18411 install_node(&bgp_srv6_node);
18412
18413 /* Install default VTY commands to new nodes. */
18414 install_default(BGP_NODE);
18415 install_default(BGP_IPV4_NODE);
18416 install_default(BGP_IPV4M_NODE);
18417 install_default(BGP_IPV4L_NODE);
18418 install_default(BGP_IPV6_NODE);
18419 install_default(BGP_IPV6M_NODE);
18420 install_default(BGP_IPV6L_NODE);
18421 install_default(BGP_VPNV4_NODE);
18422 install_default(BGP_VPNV6_NODE);
18423 install_default(BGP_FLOWSPECV4_NODE);
18424 install_default(BGP_FLOWSPECV6_NODE);
18425 install_default(BGP_EVPN_NODE);
18426 install_default(BGP_EVPN_VNI_NODE);
18427 install_default(BGP_SRV6_NODE);
18428
18429 /* "bgp local-mac" hidden commands. */
18430 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
18431 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
18432
18433 /* "bgp suppress-fib-pending" global */
18434 install_element(CONFIG_NODE, &bgp_global_suppress_fib_pending_cmd);
18435
18436 /* bgp route-map delay-timer commands. */
18437 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
18438 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
18439
18440 /* global bgp update-delay command */
18441 install_element(CONFIG_NODE, &bgp_global_update_delay_cmd);
18442 install_element(CONFIG_NODE, &no_bgp_global_update_delay_cmd);
18443
18444 /* global bgp graceful-shutdown command */
18445 install_element(CONFIG_NODE, &bgp_graceful_shutdown_cmd);
18446 install_element(CONFIG_NODE, &no_bgp_graceful_shutdown_cmd);
18447
18448 /* Dummy commands (Currently not supported) */
18449 install_element(BGP_NODE, &no_synchronization_cmd);
18450 install_element(BGP_NODE, &no_auto_summary_cmd);
18451
18452 /* "router bgp" commands. */
18453 install_element(CONFIG_NODE, &router_bgp_cmd);
18454
18455 /* "no router bgp" commands. */
18456 install_element(CONFIG_NODE, &no_router_bgp_cmd);
18457
18458 /* "bgp router-id" commands. */
18459 install_element(BGP_NODE, &bgp_router_id_cmd);
18460 install_element(BGP_NODE, &no_bgp_router_id_cmd);
18461
18462 /* "bgp suppress-fib-pending" command */
18463 install_element(BGP_NODE, &bgp_suppress_fib_pending_cmd);
18464
18465 /* "bgp cluster-id" commands. */
18466 install_element(BGP_NODE, &bgp_cluster_id_cmd);
18467 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
18468
18469 /* "bgp no-rib" commands. */
18470 install_element(CONFIG_NODE, &bgp_norib_cmd);
18471 install_element(CONFIG_NODE, &no_bgp_norib_cmd);
18472
18473 install_element(CONFIG_NODE, &no_bgp_send_extra_data_cmd);
18474
18475 /* "bgp confederation" commands. */
18476 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
18477 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
18478
18479 /* "bgp confederation peers" commands. */
18480 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
18481 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
18482
18483 /* bgp max-med command */
18484 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
18485 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
18486 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
18487 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
18488 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
18489
18490 /* bgp disable-ebgp-connected-nh-check */
18491 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
18492 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
18493
18494 /* bgp update-delay command */
18495 install_element(BGP_NODE, &bgp_update_delay_cmd);
18496 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
18497
18498 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
18499 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
18500
18501 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
18502 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
18503
18504 /* "maximum-paths" commands. */
18505 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
18506 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
18507 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
18508 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
18509 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
18510 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
18511 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
18512 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
18513 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
18514 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
18515 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18516 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
18517 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
18518 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18519 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
18520
18521 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_cmd);
18522 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_cmd);
18523 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cmd);
18524 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18525 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_ibgp_cmd);
18526 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
18527 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
18528 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
18529 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18530 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
18531
18532 /* "timers bgp" commands. */
18533 install_element(BGP_NODE, &bgp_timers_cmd);
18534 install_element(BGP_NODE, &no_bgp_timers_cmd);
18535
18536 /* route-map delay-timer commands - per instance for backwards compat.
18537 */
18538 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
18539 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
18540
18541 /* "bgp client-to-client reflection" commands */
18542 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
18543 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
18544
18545 /* "bgp always-compare-med" commands */
18546 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
18547 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
18548
18549 /* bgp ebgp-requires-policy */
18550 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
18551 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
18552
18553 /* bgp suppress-duplicates */
18554 install_element(BGP_NODE, &bgp_suppress_duplicates_cmd);
18555 install_element(BGP_NODE, &no_bgp_suppress_duplicates_cmd);
18556
18557 /* bgp reject-as-sets */
18558 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
18559 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
18560
18561 /* "bgp deterministic-med" commands */
18562 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
18563 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
18564
18565 /* "bgp graceful-restart" command */
18566 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
18567 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
18568
18569 /* "bgp graceful-restart-disable" command */
18570 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
18571 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
18572
18573 /* "neighbor a:b:c:d graceful-restart" command */
18574 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
18575 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
18576
18577 /* "neighbor a:b:c:d graceful-restart-disable" command */
18578 install_element(BGP_NODE,
18579 &bgp_neighbor_graceful_restart_disable_set_cmd);
18580 install_element(BGP_NODE,
18581 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
18582
18583 /* "neighbor a:b:c:d graceful-restart-helper" command */
18584 install_element(BGP_NODE,
18585 &bgp_neighbor_graceful_restart_helper_set_cmd);
18586 install_element(BGP_NODE,
18587 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
18588
18589 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
18590 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
18591 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
18592 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
18593 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
18594 install_element(BGP_NODE,
18595 &no_bgp_graceful_restart_select_defer_time_cmd);
18596 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
18597 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
18598
18599 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
18600 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
18601 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
18602 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
18603
18604 /* "bgp graceful-shutdown" commands */
18605 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
18606 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
18607
18608 /* "bgp fast-external-failover" commands */
18609 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
18610 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
18611
18612 /* "bgp bestpath compare-routerid" commands */
18613 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
18614 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
18615
18616 /* "bgp bestpath as-path ignore" commands */
18617 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
18618 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
18619
18620 /* "bgp bestpath as-path confed" commands */
18621 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
18622 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
18623
18624 /* "bgp bestpath as-path multipath-relax" commands */
18625 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
18626 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
18627
18628 /* "bgp bestpath peer-type multipath-relax" commands */
18629 install_element(BGP_NODE, &bgp_bestpath_peer_type_multipath_relax_cmd);
18630 install_element(BGP_NODE,
18631 &no_bgp_bestpath_peer_type_multipath_relax_cmd);
18632
18633 /* "bgp log-neighbor-changes" commands */
18634 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
18635 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
18636
18637 /* "bgp bestpath med" commands */
18638 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
18639 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
18640
18641 /* "bgp bestpath bandwidth" commands */
18642 install_element(BGP_NODE, &bgp_bestpath_bw_cmd);
18643 install_element(BGP_NODE, &no_bgp_bestpath_bw_cmd);
18644
18645 /* "no bgp default <afi>-<safi>" commands. */
18646 install_element(BGP_NODE, &bgp_default_afi_safi_cmd);
18647
18648 /* "bgp network import-check" commands. */
18649 install_element(BGP_NODE, &bgp_network_import_check_cmd);
18650 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
18651 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
18652
18653 /* "bgp default local-preference" commands. */
18654 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
18655 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
18656
18657 /* bgp default show-hostname */
18658 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
18659 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
18660
18661 /* bgp default show-nexthop-hostname */
18662 install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
18663 install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
18664
18665 /* "bgp default subgroup-pkt-queue-max" commands. */
18666 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
18667 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
18668
18669 /* bgp ibgp-allow-policy-mods command */
18670 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
18671 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
18672
18673 /* "bgp listen limit" commands. */
18674 install_element(BGP_NODE, &bgp_listen_limit_cmd);
18675 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
18676
18677 /* "bgp listen range" commands. */
18678 install_element(BGP_NODE, &bgp_listen_range_cmd);
18679 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
18680
18681 /* "bgp default shutdown" command */
18682 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
18683
18684 /* "bgp shutdown" commands */
18685 install_element(BGP_NODE, &bgp_shutdown_cmd);
18686 install_element(BGP_NODE, &bgp_shutdown_msg_cmd);
18687 install_element(BGP_NODE, &no_bgp_shutdown_cmd);
18688 install_element(BGP_NODE, &no_bgp_shutdown_msg_cmd);
18689
18690 /* "neighbor remote-as" commands. */
18691 install_element(BGP_NODE, &neighbor_remote_as_cmd);
18692 install_element(BGP_NODE, &neighbor_interface_config_cmd);
18693 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
18694 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
18695 install_element(BGP_NODE,
18696 &neighbor_interface_v6only_config_remote_as_cmd);
18697 install_element(BGP_NODE, &no_neighbor_cmd);
18698 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
18699
18700 /* "neighbor peer-group" commands. */
18701 install_element(BGP_NODE, &neighbor_peer_group_cmd);
18702 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
18703 install_element(BGP_NODE,
18704 &no_neighbor_interface_peer_group_remote_as_cmd);
18705
18706 /* "neighbor local-as" commands. */
18707 install_element(BGP_NODE, &neighbor_local_as_cmd);
18708 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
18709 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
18710 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
18711
18712 /* "neighbor solo" commands. */
18713 install_element(BGP_NODE, &neighbor_solo_cmd);
18714 install_element(BGP_NODE, &no_neighbor_solo_cmd);
18715
18716 /* "neighbor password" commands. */
18717 install_element(BGP_NODE, &neighbor_password_cmd);
18718 install_element(BGP_NODE, &no_neighbor_password_cmd);
18719
18720 /* "neighbor activate" commands. */
18721 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
18722 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
18723 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
18724 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
18725 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
18726 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
18727 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
18728 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
18729 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
18730 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
18731 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
18732 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
18733
18734 /* "no neighbor activate" commands. */
18735 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
18736 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
18737 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
18738 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
18739 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
18740 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
18741 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
18742 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
18743 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
18744 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
18745 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
18746 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
18747
18748 /* "neighbor peer-group" set commands. */
18749 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
18750 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
18751 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
18752 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
18753 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
18754 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
18755 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
18756 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
18757 install_element(BGP_FLOWSPECV4_NODE,
18758 &neighbor_set_peer_group_hidden_cmd);
18759 install_element(BGP_FLOWSPECV6_NODE,
18760 &neighbor_set_peer_group_hidden_cmd);
18761
18762 /* "no neighbor peer-group unset" commands. */
18763 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
18764 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18765 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18766 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18767 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18768 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18769 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18770 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18771 install_element(BGP_FLOWSPECV4_NODE,
18772 &no_neighbor_set_peer_group_hidden_cmd);
18773 install_element(BGP_FLOWSPECV6_NODE,
18774 &no_neighbor_set_peer_group_hidden_cmd);
18775
18776 /* "neighbor softreconfiguration inbound" commands.*/
18777 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
18778 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
18779 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
18780 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
18781 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
18782 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
18783 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
18784 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
18785 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
18786 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
18787 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
18788 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
18789 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
18790 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
18791 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
18792 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
18793 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
18794 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
18795 install_element(BGP_FLOWSPECV4_NODE,
18796 &neighbor_soft_reconfiguration_cmd);
18797 install_element(BGP_FLOWSPECV4_NODE,
18798 &no_neighbor_soft_reconfiguration_cmd);
18799 install_element(BGP_FLOWSPECV6_NODE,
18800 &neighbor_soft_reconfiguration_cmd);
18801 install_element(BGP_FLOWSPECV6_NODE,
18802 &no_neighbor_soft_reconfiguration_cmd);
18803 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
18804 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
18805
18806 /* "neighbor attribute-unchanged" commands. */
18807 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
18808 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
18809 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
18810 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
18811 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
18812 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
18813 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
18814 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
18815 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
18816 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
18817 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
18818 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
18819 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
18820 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
18821 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
18822 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
18823 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
18824 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
18825
18826 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
18827 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
18828
18829 install_element(BGP_FLOWSPECV4_NODE, &neighbor_attr_unchanged_cmd);
18830 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_attr_unchanged_cmd);
18831 install_element(BGP_FLOWSPECV6_NODE, &neighbor_attr_unchanged_cmd);
18832 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_attr_unchanged_cmd);
18833
18834 /* "nexthop-local unchanged" commands */
18835 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
18836 install_element(BGP_IPV6_NODE,
18837 &no_neighbor_nexthop_local_unchanged_cmd);
18838
18839 /* "neighbor next-hop-self" commands. */
18840 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
18841 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
18842 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
18843 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
18844 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
18845 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
18846 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
18847 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
18848 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
18849 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
18850 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
18851 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
18852 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
18853 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
18854 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
18855 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
18856 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
18857 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
18858 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
18859 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
18860
18861 /* "neighbor next-hop-self force" commands. */
18862 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
18863 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
18864 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18865 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
18866 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
18867 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
18868 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18869 install_element(BGP_IPV4_NODE,
18870 &no_neighbor_nexthop_self_all_hidden_cmd);
18871 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
18872 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
18873 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18874 install_element(BGP_IPV4M_NODE,
18875 &no_neighbor_nexthop_self_all_hidden_cmd);
18876 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
18877 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
18878 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18879 install_element(BGP_IPV4L_NODE,
18880 &no_neighbor_nexthop_self_all_hidden_cmd);
18881 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
18882 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
18883 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18884 install_element(BGP_IPV6_NODE,
18885 &no_neighbor_nexthop_self_all_hidden_cmd);
18886 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
18887 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
18888 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18889 install_element(BGP_IPV6M_NODE,
18890 &no_neighbor_nexthop_self_all_hidden_cmd);
18891 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
18892 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
18893 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18894 install_element(BGP_IPV6L_NODE,
18895 &no_neighbor_nexthop_self_all_hidden_cmd);
18896 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
18897 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
18898 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18899 install_element(BGP_VPNV4_NODE,
18900 &no_neighbor_nexthop_self_all_hidden_cmd);
18901 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
18902 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
18903 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18904 install_element(BGP_VPNV6_NODE,
18905 &no_neighbor_nexthop_self_all_hidden_cmd);
18906 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_force_cmd);
18907 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_force_cmd);
18908
18909 /* "neighbor as-override" commands. */
18910 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
18911 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
18912 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
18913 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
18914 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
18915 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
18916 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
18917 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
18918 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
18919 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
18920 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
18921 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
18922 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
18923 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
18924 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
18925 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
18926 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
18927 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
18928
18929 /* "neighbor remove-private-AS" commands. */
18930 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
18931 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
18932 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
18933 install_element(BGP_NODE,
18934 &no_neighbor_remove_private_as_all_hidden_cmd);
18935 install_element(BGP_NODE,
18936 &neighbor_remove_private_as_replace_as_hidden_cmd);
18937 install_element(BGP_NODE,
18938 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
18939 install_element(BGP_NODE,
18940 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
18941 install_element(
18942 BGP_NODE,
18943 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
18944 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
18945 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
18946 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
18947 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18948 install_element(BGP_IPV4_NODE,
18949 &neighbor_remove_private_as_replace_as_cmd);
18950 install_element(BGP_IPV4_NODE,
18951 &no_neighbor_remove_private_as_replace_as_cmd);
18952 install_element(BGP_IPV4_NODE,
18953 &neighbor_remove_private_as_all_replace_as_cmd);
18954 install_element(BGP_IPV4_NODE,
18955 &no_neighbor_remove_private_as_all_replace_as_cmd);
18956 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
18957 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
18958 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
18959 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
18960 install_element(BGP_IPV4M_NODE,
18961 &neighbor_remove_private_as_replace_as_cmd);
18962 install_element(BGP_IPV4M_NODE,
18963 &no_neighbor_remove_private_as_replace_as_cmd);
18964 install_element(BGP_IPV4M_NODE,
18965 &neighbor_remove_private_as_all_replace_as_cmd);
18966 install_element(BGP_IPV4M_NODE,
18967 &no_neighbor_remove_private_as_all_replace_as_cmd);
18968 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
18969 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
18970 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
18971 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
18972 install_element(BGP_IPV4L_NODE,
18973 &neighbor_remove_private_as_replace_as_cmd);
18974 install_element(BGP_IPV4L_NODE,
18975 &no_neighbor_remove_private_as_replace_as_cmd);
18976 install_element(BGP_IPV4L_NODE,
18977 &neighbor_remove_private_as_all_replace_as_cmd);
18978 install_element(BGP_IPV4L_NODE,
18979 &no_neighbor_remove_private_as_all_replace_as_cmd);
18980 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
18981 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
18982 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
18983 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18984 install_element(BGP_IPV6_NODE,
18985 &neighbor_remove_private_as_replace_as_cmd);
18986 install_element(BGP_IPV6_NODE,
18987 &no_neighbor_remove_private_as_replace_as_cmd);
18988 install_element(BGP_IPV6_NODE,
18989 &neighbor_remove_private_as_all_replace_as_cmd);
18990 install_element(BGP_IPV6_NODE,
18991 &no_neighbor_remove_private_as_all_replace_as_cmd);
18992 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
18993 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
18994 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
18995 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
18996 install_element(BGP_IPV6M_NODE,
18997 &neighbor_remove_private_as_replace_as_cmd);
18998 install_element(BGP_IPV6M_NODE,
18999 &no_neighbor_remove_private_as_replace_as_cmd);
19000 install_element(BGP_IPV6M_NODE,
19001 &neighbor_remove_private_as_all_replace_as_cmd);
19002 install_element(BGP_IPV6M_NODE,
19003 &no_neighbor_remove_private_as_all_replace_as_cmd);
19004 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
19005 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
19006 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
19007 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
19008 install_element(BGP_IPV6L_NODE,
19009 &neighbor_remove_private_as_replace_as_cmd);
19010 install_element(BGP_IPV6L_NODE,
19011 &no_neighbor_remove_private_as_replace_as_cmd);
19012 install_element(BGP_IPV6L_NODE,
19013 &neighbor_remove_private_as_all_replace_as_cmd);
19014 install_element(BGP_IPV6L_NODE,
19015 &no_neighbor_remove_private_as_all_replace_as_cmd);
19016 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
19017 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
19018 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
19019 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
19020 install_element(BGP_VPNV4_NODE,
19021 &neighbor_remove_private_as_replace_as_cmd);
19022 install_element(BGP_VPNV4_NODE,
19023 &no_neighbor_remove_private_as_replace_as_cmd);
19024 install_element(BGP_VPNV4_NODE,
19025 &neighbor_remove_private_as_all_replace_as_cmd);
19026 install_element(BGP_VPNV4_NODE,
19027 &no_neighbor_remove_private_as_all_replace_as_cmd);
19028 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
19029 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
19030 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
19031 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
19032 install_element(BGP_VPNV6_NODE,
19033 &neighbor_remove_private_as_replace_as_cmd);
19034 install_element(BGP_VPNV6_NODE,
19035 &no_neighbor_remove_private_as_replace_as_cmd);
19036 install_element(BGP_VPNV6_NODE,
19037 &neighbor_remove_private_as_all_replace_as_cmd);
19038 install_element(BGP_VPNV6_NODE,
19039 &no_neighbor_remove_private_as_all_replace_as_cmd);
19040
19041 /* "neighbor send-community" commands.*/
19042 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
19043 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
19044 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
19045 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
19046 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
19047 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
19048 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
19049 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
19050 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
19051 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
19052 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
19053 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
19054 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
19055 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
19056 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
19057 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
19058 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
19059 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
19060 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
19061 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
19062 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
19063 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
19064 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
19065 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
19066 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
19067 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
19068 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
19069 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
19070 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
19071 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
19072 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
19073 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
19074 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
19075 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
19076 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
19077 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
19078
19079 /* "neighbor route-reflector" commands.*/
19080 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
19081 install_element(BGP_NODE,
19082 &no_neighbor_route_reflector_client_hidden_cmd);
19083 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
19084 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
19085 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
19086 install_element(BGP_IPV4M_NODE,
19087 &no_neighbor_route_reflector_client_cmd);
19088 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
19089 install_element(BGP_IPV4L_NODE,
19090 &no_neighbor_route_reflector_client_cmd);
19091 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
19092 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
19093 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
19094 install_element(BGP_IPV6M_NODE,
19095 &no_neighbor_route_reflector_client_cmd);
19096 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
19097 install_element(BGP_IPV6L_NODE,
19098 &no_neighbor_route_reflector_client_cmd);
19099 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
19100 install_element(BGP_VPNV4_NODE,
19101 &no_neighbor_route_reflector_client_cmd);
19102 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
19103 install_element(BGP_VPNV6_NODE,
19104 &no_neighbor_route_reflector_client_cmd);
19105 install_element(BGP_FLOWSPECV4_NODE,
19106 &neighbor_route_reflector_client_cmd);
19107 install_element(BGP_FLOWSPECV4_NODE,
19108 &no_neighbor_route_reflector_client_cmd);
19109 install_element(BGP_FLOWSPECV6_NODE,
19110 &neighbor_route_reflector_client_cmd);
19111 install_element(BGP_FLOWSPECV6_NODE,
19112 &no_neighbor_route_reflector_client_cmd);
19113 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
19114 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
19115
19116 /* "neighbor route-server" commands.*/
19117 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
19118 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
19119 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
19120 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
19121 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
19122 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
19123 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
19124 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
19125 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
19126 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
19127 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
19128 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
19129 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
19130 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
19131 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
19132 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
19133 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
19134 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
19135 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
19136 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
19137 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
19138 install_element(BGP_FLOWSPECV4_NODE,
19139 &no_neighbor_route_server_client_cmd);
19140 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
19141 install_element(BGP_FLOWSPECV6_NODE,
19142 &no_neighbor_route_server_client_cmd);
19143
19144 /* "neighbor addpath-tx-all-paths" commands.*/
19145 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
19146 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
19147 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
19148 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19149 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
19150 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19151 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
19152 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19153 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
19154 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19155 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
19156 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19157 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
19158 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19159 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
19160 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19161 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
19162 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19163
19164 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
19165 install_element(BGP_NODE,
19166 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
19167 install_element(BGP_NODE,
19168 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
19169 install_element(BGP_IPV4_NODE,
19170 &neighbor_addpath_tx_bestpath_per_as_cmd);
19171 install_element(BGP_IPV4_NODE,
19172 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19173 install_element(BGP_IPV4M_NODE,
19174 &neighbor_addpath_tx_bestpath_per_as_cmd);
19175 install_element(BGP_IPV4M_NODE,
19176 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19177 install_element(BGP_IPV4L_NODE,
19178 &neighbor_addpath_tx_bestpath_per_as_cmd);
19179 install_element(BGP_IPV4L_NODE,
19180 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19181 install_element(BGP_IPV6_NODE,
19182 &neighbor_addpath_tx_bestpath_per_as_cmd);
19183 install_element(BGP_IPV6_NODE,
19184 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19185 install_element(BGP_IPV6M_NODE,
19186 &neighbor_addpath_tx_bestpath_per_as_cmd);
19187 install_element(BGP_IPV6M_NODE,
19188 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19189 install_element(BGP_IPV6L_NODE,
19190 &neighbor_addpath_tx_bestpath_per_as_cmd);
19191 install_element(BGP_IPV6L_NODE,
19192 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19193 install_element(BGP_VPNV4_NODE,
19194 &neighbor_addpath_tx_bestpath_per_as_cmd);
19195 install_element(BGP_VPNV4_NODE,
19196 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19197 install_element(BGP_VPNV6_NODE,
19198 &neighbor_addpath_tx_bestpath_per_as_cmd);
19199 install_element(BGP_VPNV6_NODE,
19200 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19201
19202 /* "neighbor sender-as-path-loop-detection" commands. */
19203 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
19204 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
19205
19206 /* "neighbor passive" commands. */
19207 install_element(BGP_NODE, &neighbor_passive_cmd);
19208 install_element(BGP_NODE, &no_neighbor_passive_cmd);
19209
19210
19211 /* "neighbor shutdown" commands. */
19212 install_element(BGP_NODE, &neighbor_shutdown_cmd);
19213 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
19214 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
19215 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
19216 install_element(BGP_NODE, &neighbor_shutdown_rtt_cmd);
19217 install_element(BGP_NODE, &no_neighbor_shutdown_rtt_cmd);
19218
19219 /* "neighbor capability extended-nexthop" commands.*/
19220 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
19221 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
19222
19223 /* "neighbor capability orf prefix-list" commands.*/
19224 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
19225 install_element(BGP_NODE,
19226 &no_neighbor_capability_orf_prefix_hidden_cmd);
19227 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
19228 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
19229 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
19230 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
19231 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
19232 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
19233 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
19234 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
19235 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
19236 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
19237 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
19238 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
19239
19240 /* "neighbor capability dynamic" commands.*/
19241 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
19242 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
19243
19244 /* "neighbor dont-capability-negotiate" commands. */
19245 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
19246 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
19247
19248 /* "neighbor ebgp-multihop" commands. */
19249 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
19250 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
19251 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
19252
19253 /* "neighbor disable-connected-check" commands. */
19254 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
19255 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
19256
19257 /* "neighbor enforce-first-as" commands. */
19258 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
19259 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
19260
19261 /* "neighbor description" commands. */
19262 install_element(BGP_NODE, &neighbor_description_cmd);
19263 install_element(BGP_NODE, &no_neighbor_description_cmd);
19264 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
19265
19266 /* "neighbor update-source" commands. "*/
19267 install_element(BGP_NODE, &neighbor_update_source_cmd);
19268 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
19269
19270 /* "neighbor default-originate" commands. */
19271 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
19272 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
19273 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
19274 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
19275 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
19276 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
19277 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
19278 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
19279 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
19280 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
19281 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
19282 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
19283 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
19284 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
19285 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
19286 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
19287 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
19288 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
19289 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
19290 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
19291 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
19292
19293 /* "neighbor port" commands. */
19294 install_element(BGP_NODE, &neighbor_port_cmd);
19295 install_element(BGP_NODE, &no_neighbor_port_cmd);
19296
19297 /* "neighbor weight" commands. */
19298 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
19299 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
19300
19301 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
19302 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
19303 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
19304 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
19305 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
19306 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
19307 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
19308 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
19309 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
19310 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
19311 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
19312 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
19313 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
19314 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
19315 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
19316 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
19317
19318 /* "neighbor override-capability" commands. */
19319 install_element(BGP_NODE, &neighbor_override_capability_cmd);
19320 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
19321
19322 /* "neighbor strict-capability-match" commands. */
19323 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
19324 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
19325
19326 /* "neighbor timers" commands. */
19327 install_element(BGP_NODE, &neighbor_timers_cmd);
19328 install_element(BGP_NODE, &no_neighbor_timers_cmd);
19329
19330 /* "neighbor timers connect" commands. */
19331 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
19332 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
19333
19334 /* "neighbor timers delayopen" commands. */
19335 install_element(BGP_NODE, &neighbor_timers_delayopen_cmd);
19336 install_element(BGP_NODE, &no_neighbor_timers_delayopen_cmd);
19337
19338 /* "neighbor advertisement-interval" commands. */
19339 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
19340 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
19341
19342 /* "neighbor interface" commands. */
19343 install_element(BGP_NODE, &neighbor_interface_cmd);
19344 install_element(BGP_NODE, &no_neighbor_interface_cmd);
19345
19346 /* "neighbor distribute" commands. */
19347 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
19348 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
19349 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
19350 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
19351 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
19352 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
19353 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
19354 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
19355 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
19356 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
19357 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
19358 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
19359 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
19360 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
19361 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
19362 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
19363 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
19364 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
19365
19366 /* "neighbor prefix-list" commands. */
19367 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
19368 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
19369 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
19370 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
19371 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
19372 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
19373 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
19374 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
19375 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
19376 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
19377 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
19378
19379 /* "neighbor filter-list" commands. */
19380 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
19381 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
19382 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
19383 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
19384 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
19385 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
19386 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
19387 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
19388 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
19389 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
19390 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
19391 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
19392 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
19393 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
19394 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
19395 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
19396 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
19397 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
19398 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
19399 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
19400 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
19401 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
19402
19403 /* "neighbor route-map" commands. */
19404 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
19405 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
19406 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
19407 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
19408 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
19409 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
19410 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
19411 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
19412 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
19413 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
19414 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
19415
19416 /* "neighbor unsuppress-map" commands. */
19417 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
19418 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
19419 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
19420 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
19421 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
19422 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
19423 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
19424 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
19425 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
19426 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
19427 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
19428 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
19429 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
19430 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
19431 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
19432 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
19433 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
19434 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
19435
19436 /* "neighbor advertise-map" commands. */
19437 install_element(BGP_NODE, &neighbor_advertise_map_hidden_cmd);
19438 install_element(BGP_IPV4_NODE, &neighbor_advertise_map_cmd);
19439 install_element(BGP_IPV4M_NODE, &neighbor_advertise_map_cmd);
19440 install_element(BGP_IPV4L_NODE, &neighbor_advertise_map_cmd);
19441 install_element(BGP_IPV6_NODE, &neighbor_advertise_map_cmd);
19442 install_element(BGP_IPV6M_NODE, &neighbor_advertise_map_cmd);
19443 install_element(BGP_IPV6L_NODE, &neighbor_advertise_map_cmd);
19444 install_element(BGP_VPNV4_NODE, &neighbor_advertise_map_cmd);
19445 install_element(BGP_VPNV6_NODE, &neighbor_advertise_map_cmd);
19446
19447 /* neighbor maximum-prefix-out commands. */
19448 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
19449 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
19450 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
19451 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
19452 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
19453 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
19454 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
19455 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
19456 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
19457 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
19458 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
19459 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
19460 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
19461 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
19462 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
19463 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
19464 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
19465 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
19466
19467 /* "neighbor maximum-prefix" commands. */
19468 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
19469 install_element(BGP_NODE,
19470 &neighbor_maximum_prefix_threshold_hidden_cmd);
19471 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
19472 install_element(BGP_NODE,
19473 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
19474 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
19475 install_element(BGP_NODE,
19476 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
19477 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
19478 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
19479 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
19480 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
19481 install_element(BGP_IPV4_NODE,
19482 &neighbor_maximum_prefix_threshold_warning_cmd);
19483 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
19484 install_element(BGP_IPV4_NODE,
19485 &neighbor_maximum_prefix_threshold_restart_cmd);
19486 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
19487 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
19488 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
19489 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
19490 install_element(BGP_IPV4M_NODE,
19491 &neighbor_maximum_prefix_threshold_warning_cmd);
19492 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
19493 install_element(BGP_IPV4M_NODE,
19494 &neighbor_maximum_prefix_threshold_restart_cmd);
19495 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
19496 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
19497 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
19498 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
19499 install_element(BGP_IPV4L_NODE,
19500 &neighbor_maximum_prefix_threshold_warning_cmd);
19501 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
19502 install_element(BGP_IPV4L_NODE,
19503 &neighbor_maximum_prefix_threshold_restart_cmd);
19504 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
19505 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
19506 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
19507 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
19508 install_element(BGP_IPV6_NODE,
19509 &neighbor_maximum_prefix_threshold_warning_cmd);
19510 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
19511 install_element(BGP_IPV6_NODE,
19512 &neighbor_maximum_prefix_threshold_restart_cmd);
19513 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
19514 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
19515 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
19516 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
19517 install_element(BGP_IPV6M_NODE,
19518 &neighbor_maximum_prefix_threshold_warning_cmd);
19519 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
19520 install_element(BGP_IPV6M_NODE,
19521 &neighbor_maximum_prefix_threshold_restart_cmd);
19522 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
19523 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
19524 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
19525 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
19526 install_element(BGP_IPV6L_NODE,
19527 &neighbor_maximum_prefix_threshold_warning_cmd);
19528 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
19529 install_element(BGP_IPV6L_NODE,
19530 &neighbor_maximum_prefix_threshold_restart_cmd);
19531 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
19532 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
19533 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
19534 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
19535 install_element(BGP_VPNV4_NODE,
19536 &neighbor_maximum_prefix_threshold_warning_cmd);
19537 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
19538 install_element(BGP_VPNV4_NODE,
19539 &neighbor_maximum_prefix_threshold_restart_cmd);
19540 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
19541 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
19542 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
19543 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
19544 install_element(BGP_VPNV6_NODE,
19545 &neighbor_maximum_prefix_threshold_warning_cmd);
19546 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
19547 install_element(BGP_VPNV6_NODE,
19548 &neighbor_maximum_prefix_threshold_restart_cmd);
19549 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
19550
19551 /* "neighbor allowas-in" */
19552 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
19553 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
19554 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
19555 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
19556 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
19557 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
19558 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
19559 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
19560 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
19561 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
19562 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
19563 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
19564 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
19565 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
19566 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
19567 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
19568 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
19569 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
19570 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
19571 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
19572
19573 /* "neighbor dampening" commands. */
19574 install_element(BGP_NODE, &neighbor_damp_cmd);
19575 install_element(BGP_NODE, &no_neighbor_damp_cmd);
19576 install_element(BGP_IPV4_NODE, &neighbor_damp_cmd);
19577 install_element(BGP_IPV4_NODE, &no_neighbor_damp_cmd);
19578 install_element(BGP_IPV4M_NODE, &neighbor_damp_cmd);
19579 install_element(BGP_IPV4M_NODE, &no_neighbor_damp_cmd);
19580 install_element(BGP_IPV4L_NODE, &neighbor_damp_cmd);
19581 install_element(BGP_IPV4L_NODE, &no_neighbor_damp_cmd);
19582 install_element(BGP_IPV6_NODE, &neighbor_damp_cmd);
19583 install_element(BGP_IPV6_NODE, &no_neighbor_damp_cmd);
19584 install_element(BGP_IPV6M_NODE, &neighbor_damp_cmd);
19585 install_element(BGP_IPV6M_NODE, &no_neighbor_damp_cmd);
19586 install_element(BGP_IPV6L_NODE, &neighbor_damp_cmd);
19587 install_element(BGP_IPV6L_NODE, &no_neighbor_damp_cmd);
19588 install_element(VIEW_NODE, &show_ip_bgp_neighbor_damp_param_cmd);
19589
19590 /* address-family commands. */
19591 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
19592 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
19593 #ifdef KEEP_OLD_VPN_COMMANDS
19594 install_element(BGP_NODE, &address_family_vpnv4_cmd);
19595 install_element(BGP_NODE, &address_family_vpnv6_cmd);
19596 #endif /* KEEP_OLD_VPN_COMMANDS */
19597
19598 install_element(BGP_NODE, &address_family_evpn_cmd);
19599
19600 /* "exit-address-family" command. */
19601 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
19602 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
19603 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
19604 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
19605 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
19606 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
19607 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
19608 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
19609 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
19610 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
19611 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
19612
19613 /* "clear ip bgp commands" */
19614 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
19615
19616 /* clear ip bgp prefix */
19617 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
19618 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
19619 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
19620
19621 /* "show [ip] bgp summary" commands. */
19622 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
19623 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
19624 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
19625 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
19626 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
19627 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
19628 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
19629
19630 /* "show [ip] bgp neighbors" commands. */
19631 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
19632
19633 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
19634
19635 /* "show [ip] bgp peer-group" commands. */
19636 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
19637
19638 /* "show [ip] bgp paths" commands. */
19639 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
19640
19641 /* "show [ip] bgp community" commands. */
19642 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
19643
19644 /* "show ip bgp large-community" commands. */
19645 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
19646 /* "show [ip] bgp attribute-info" commands. */
19647 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
19648 /* "show [ip] bgp route-leak" command */
19649 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
19650
19651 /* "redistribute" commands. */
19652 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
19653 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
19654 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
19655 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
19656 install_element(BGP_NODE,
19657 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
19658 install_element(BGP_NODE,
19659 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
19660 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
19661 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
19662 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
19663 install_element(BGP_NODE,
19664 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
19665 install_element(BGP_NODE,
19666 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
19667 install_element(BGP_NODE,
19668 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
19669 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
19670 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
19671 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
19672 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
19673 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
19674 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
19675 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
19676 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
19677 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
19678 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
19679 install_element(BGP_IPV4_NODE,
19680 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
19681 install_element(BGP_IPV4_NODE,
19682 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
19683 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
19684 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
19685 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
19686 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
19687 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
19688 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
19689
19690 /* import|export vpn [route-map WORD] */
19691 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
19692 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
19693
19694 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
19695 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
19696
19697 /* ttl_security commands */
19698 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
19699 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
19700
19701 /* "show [ip] bgp memory" commands. */
19702 install_element(VIEW_NODE, &show_bgp_memory_cmd);
19703
19704 /* "show bgp martian next-hop" */
19705 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
19706
19707 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
19708
19709 /* "show [ip] bgp views" commands. */
19710 install_element(VIEW_NODE, &show_bgp_views_cmd);
19711
19712 /* "show [ip] bgp vrfs" commands. */
19713 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
19714
19715 /* Community-list. */
19716 community_list_vty();
19717
19718 community_alias_vty();
19719
19720 /* vpn-policy commands */
19721 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
19722 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
19723 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
19724 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
19725 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
19726 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
19727 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
19728 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
19729 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
19730 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
19731 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
19732 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
19733
19734 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
19735 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
19736
19737 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
19738 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
19739 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
19740 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
19741 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
19742 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
19743 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
19744 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
19745 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
19746 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
19747
19748 /* tcp-mss command */
19749 install_element(BGP_NODE, &neighbor_tcp_mss_cmd);
19750 install_element(BGP_NODE, &no_neighbor_tcp_mss_cmd);
19751
19752 /* srv6 commands */
19753 install_element(VIEW_NODE, &show_bgp_srv6_cmd);
19754 install_element(BGP_NODE, &bgp_segment_routing_srv6_cmd);
19755 install_element(BGP_SRV6_NODE, &bgp_srv6_locator_cmd);
19756 install_element(BGP_IPV4_NODE, &af_sid_vpn_export_cmd);
19757 install_element(BGP_IPV6_NODE, &af_sid_vpn_export_cmd);
19758 }
19759
19760 #include "memory.h"
19761 #include "bgp_regex.h"
19762 #include "bgp_clist.h"
19763 #include "bgp_ecommunity.h"
19764
19765 /* VTY functions. */
19766
19767 /* Direction value to string conversion. */
19768 static const char *community_direct_str(int direct)
19769 {
19770 switch (direct) {
19771 case COMMUNITY_DENY:
19772 return "deny";
19773 case COMMUNITY_PERMIT:
19774 return "permit";
19775 default:
19776 return "unknown";
19777 }
19778 }
19779
19780 /* Display error string. */
19781 static void community_list_perror(struct vty *vty, int ret)
19782 {
19783 switch (ret) {
19784 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
19785 vty_out(vty, "%% Can't find community-list\n");
19786 break;
19787 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
19788 vty_out(vty, "%% Malformed community-list value\n");
19789 break;
19790 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
19791 vty_out(vty,
19792 "%% Community name conflict, previously defined as standard community\n");
19793 break;
19794 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
19795 vty_out(vty,
19796 "%% Community name conflict, previously defined as expanded community\n");
19797 break;
19798 }
19799 }
19800
19801 /* "community-list" keyword help string. */
19802 #define COMMUNITY_LIST_STR "Add a community list entry\n"
19803
19804 /*community-list standard */
19805 DEFUN (community_list_standard,
19806 bgp_community_list_standard_cmd,
19807 "bgp community-list <(1-99)|standard WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
19808 BGP_STR
19809 COMMUNITY_LIST_STR
19810 "Community list number (standard)\n"
19811 "Add an standard community-list entry\n"
19812 "Community list name\n"
19813 "Sequence number of an entry\n"
19814 "Sequence number\n"
19815 "Specify community to reject\n"
19816 "Specify community to accept\n"
19817 COMMUNITY_VAL_STR)
19818 {
19819 char *cl_name_or_number = NULL;
19820 char *seq = NULL;
19821 int direct = 0;
19822 int style = COMMUNITY_LIST_STANDARD;
19823 int idx = 0;
19824
19825 argv_find(argv, argc, "(0-4294967295)", &idx);
19826 if (idx)
19827 seq = argv[idx]->arg;
19828
19829 idx = 0;
19830 argv_find(argv, argc, "(1-99)", &idx);
19831 argv_find(argv, argc, "WORD", &idx);
19832 cl_name_or_number = argv[idx]->arg;
19833 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19834 : COMMUNITY_DENY;
19835 argv_find(argv, argc, "AA:NN", &idx);
19836 char *str = argv_concat(argv, argc, idx);
19837
19838 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19839 direct, style);
19840
19841 XFREE(MTYPE_TMP, str);
19842
19843 if (ret < 0) {
19844 /* Display error string. */
19845 community_list_perror(vty, ret);
19846 return CMD_WARNING_CONFIG_FAILED;
19847 }
19848
19849 return CMD_SUCCESS;
19850 }
19851
19852 DEFUN (no_community_list_standard_all,
19853 no_bgp_community_list_standard_all_cmd,
19854 "no bgp community-list <(1-99)|standard WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
19855 NO_STR
19856 BGP_STR
19857 COMMUNITY_LIST_STR
19858 "Community list number (standard)\n"
19859 "Add an standard community-list entry\n"
19860 "Community list name\n"
19861 "Sequence number of an entry\n"
19862 "Sequence number\n"
19863 "Specify community to reject\n"
19864 "Specify community to accept\n"
19865 COMMUNITY_VAL_STR)
19866 {
19867 char *cl_name_or_number = NULL;
19868 char *str = NULL;
19869 int direct = 0;
19870 int style = COMMUNITY_LIST_STANDARD;
19871 char *seq = NULL;
19872 int idx = 0;
19873
19874 argv_find(argv, argc, "(0-4294967295)", &idx);
19875 if (idx)
19876 seq = argv[idx]->arg;
19877
19878 idx = 0;
19879 argv_find(argv, argc, "permit", &idx);
19880 argv_find(argv, argc, "deny", &idx);
19881
19882 if (idx) {
19883 direct = argv_find(argv, argc, "permit", &idx)
19884 ? COMMUNITY_PERMIT
19885 : COMMUNITY_DENY;
19886
19887 idx = 0;
19888 argv_find(argv, argc, "AA:NN", &idx);
19889 str = argv_concat(argv, argc, idx);
19890 }
19891
19892 idx = 0;
19893 argv_find(argv, argc, "(1-99)", &idx);
19894 argv_find(argv, argc, "WORD", &idx);
19895 cl_name_or_number = argv[idx]->arg;
19896
19897 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
19898 direct, style);
19899
19900 XFREE(MTYPE_TMP, str);
19901
19902 if (ret < 0) {
19903 community_list_perror(vty, ret);
19904 return CMD_WARNING_CONFIG_FAILED;
19905 }
19906
19907 return CMD_SUCCESS;
19908 }
19909
19910 ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
19911 "no bgp community-list <(1-99)|standard WORD>",
19912 NO_STR BGP_STR COMMUNITY_LIST_STR
19913 "Community list number (standard)\n"
19914 "Add an standard community-list entry\n"
19915 "Community list name\n")
19916
19917 /*community-list expanded */
19918 DEFUN (community_list_expanded_all,
19919 bgp_community_list_expanded_all_cmd,
19920 "bgp community-list <(100-500)|expanded WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
19921 BGP_STR
19922 COMMUNITY_LIST_STR
19923 "Community list number (expanded)\n"
19924 "Add an expanded community-list entry\n"
19925 "Community list name\n"
19926 "Sequence number of an entry\n"
19927 "Sequence number\n"
19928 "Specify community to reject\n"
19929 "Specify community to accept\n"
19930 COMMUNITY_VAL_STR)
19931 {
19932 char *cl_name_or_number = NULL;
19933 char *seq = NULL;
19934 int direct = 0;
19935 int style = COMMUNITY_LIST_EXPANDED;
19936 int idx = 0;
19937
19938 argv_find(argv, argc, "(0-4294967295)", &idx);
19939 if (idx)
19940 seq = argv[idx]->arg;
19941
19942 idx = 0;
19943
19944 argv_find(argv, argc, "(100-500)", &idx);
19945 argv_find(argv, argc, "WORD", &idx);
19946 cl_name_or_number = argv[idx]->arg;
19947 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19948 : COMMUNITY_DENY;
19949 argv_find(argv, argc, "AA:NN", &idx);
19950 char *str = argv_concat(argv, argc, idx);
19951
19952 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19953 direct, style);
19954
19955 XFREE(MTYPE_TMP, str);
19956
19957 if (ret < 0) {
19958 /* Display error string. */
19959 community_list_perror(vty, ret);
19960 return CMD_WARNING_CONFIG_FAILED;
19961 }
19962
19963 return CMD_SUCCESS;
19964 }
19965
19966 DEFUN (no_community_list_expanded_all,
19967 no_bgp_community_list_expanded_all_cmd,
19968 "no bgp community-list <(100-500)|expanded WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
19969 NO_STR
19970 BGP_STR
19971 COMMUNITY_LIST_STR
19972 "Community list number (expanded)\n"
19973 "Add an expanded community-list entry\n"
19974 "Community list name\n"
19975 "Sequence number of an entry\n"
19976 "Sequence number\n"
19977 "Specify community to reject\n"
19978 "Specify community to accept\n"
19979 COMMUNITY_VAL_STR)
19980 {
19981 char *cl_name_or_number = NULL;
19982 char *seq = NULL;
19983 char *str = NULL;
19984 int direct = 0;
19985 int style = COMMUNITY_LIST_EXPANDED;
19986 int idx = 0;
19987
19988 argv_find(argv, argc, "(0-4294967295)", &idx);
19989 if (idx)
19990 seq = argv[idx]->arg;
19991
19992 idx = 0;
19993 argv_find(argv, argc, "permit", &idx);
19994 argv_find(argv, argc, "deny", &idx);
19995
19996 if (idx) {
19997 direct = argv_find(argv, argc, "permit", &idx)
19998 ? COMMUNITY_PERMIT
19999 : COMMUNITY_DENY;
20000
20001 idx = 0;
20002 argv_find(argv, argc, "AA:NN", &idx);
20003 str = argv_concat(argv, argc, idx);
20004 }
20005
20006 idx = 0;
20007 argv_find(argv, argc, "(100-500)", &idx);
20008 argv_find(argv, argc, "WORD", &idx);
20009 cl_name_or_number = argv[idx]->arg;
20010
20011 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
20012 direct, style);
20013
20014 XFREE(MTYPE_TMP, str);
20015
20016 if (ret < 0) {
20017 community_list_perror(vty, ret);
20018 return CMD_WARNING_CONFIG_FAILED;
20019 }
20020
20021 return CMD_SUCCESS;
20022 }
20023
20024 ALIAS(no_community_list_expanded_all,
20025 no_bgp_community_list_expanded_all_list_cmd,
20026 "no bgp community-list <(100-500)|expanded WORD>",
20027 NO_STR BGP_STR COMMUNITY_LIST_STR
20028 "Community list number (expanded)\n"
20029 "Add an expanded community-list entry\n"
20030 "Community list name\n")
20031
20032 /* Return configuration string of community-list entry. */
20033 static const char *community_list_config_str(struct community_entry *entry)
20034 {
20035 const char *str;
20036
20037 if (entry->any)
20038 str = "";
20039 else {
20040 if (entry->style == COMMUNITY_LIST_STANDARD)
20041 str = community_str(entry->u.com, false);
20042 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
20043 str = lcommunity_str(entry->u.lcom, false);
20044 else
20045 str = entry->config;
20046 }
20047 return str;
20048 }
20049
20050 static void community_list_show(struct vty *vty, struct community_list *list)
20051 {
20052 struct community_entry *entry;
20053
20054 for (entry = list->head; entry; entry = entry->next) {
20055 if (entry == list->head) {
20056 if (all_digit(list->name))
20057 vty_out(vty, "Community %s list %s\n",
20058 entry->style == COMMUNITY_LIST_STANDARD
20059 ? "standard"
20060 : "(expanded) access",
20061 list->name);
20062 else
20063 vty_out(vty, "Named Community %s list %s\n",
20064 entry->style == COMMUNITY_LIST_STANDARD
20065 ? "standard"
20066 : "expanded",
20067 list->name);
20068 }
20069 if (entry->any)
20070 vty_out(vty, " %s\n",
20071 community_direct_str(entry->direct));
20072 else
20073 vty_out(vty, " %s %s\n",
20074 community_direct_str(entry->direct),
20075 community_list_config_str(entry));
20076 }
20077 }
20078
20079 DEFUN (show_community_list,
20080 show_bgp_community_list_cmd,
20081 "show bgp community-list",
20082 SHOW_STR
20083 BGP_STR
20084 "List community-list\n")
20085 {
20086 struct community_list *list;
20087 struct community_list_master *cm;
20088
20089 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
20090 if (!cm)
20091 return CMD_SUCCESS;
20092
20093 for (list = cm->num.head; list; list = list->next)
20094 community_list_show(vty, list);
20095
20096 for (list = cm->str.head; list; list = list->next)
20097 community_list_show(vty, list);
20098
20099 return CMD_SUCCESS;
20100 }
20101
20102 DEFUN (show_community_list_arg,
20103 show_bgp_community_list_arg_cmd,
20104 "show bgp community-list <(1-500)|WORD> detail",
20105 SHOW_STR
20106 BGP_STR
20107 "List community-list\n"
20108 "Community-list number\n"
20109 "Community-list name\n"
20110 "Detailed information on community-list\n")
20111 {
20112 int idx_comm_list = 3;
20113 struct community_list *list;
20114
20115 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
20116 COMMUNITY_LIST_MASTER);
20117 if (!list) {
20118 vty_out(vty, "%% Can't find community-list\n");
20119 return CMD_WARNING;
20120 }
20121
20122 community_list_show(vty, list);
20123
20124 return CMD_SUCCESS;
20125 }
20126
20127 /*
20128 * Large Community code.
20129 */
20130 static int lcommunity_list_set_vty(struct vty *vty, int argc,
20131 struct cmd_token **argv, int style,
20132 int reject_all_digit_name)
20133 {
20134 int ret;
20135 int direct;
20136 char *str;
20137 int idx = 0;
20138 char *cl_name;
20139 char *seq = NULL;
20140
20141 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20142 seq = argv[idx]->arg;
20143
20144 idx = 0;
20145 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20146 : COMMUNITY_DENY;
20147
20148 /* All digit name check. */
20149 idx = 0;
20150 argv_find(argv, argc, "WORD", &idx);
20151 argv_find(argv, argc, "(1-99)", &idx);
20152 argv_find(argv, argc, "(100-500)", &idx);
20153 cl_name = argv[idx]->arg;
20154 if (reject_all_digit_name && all_digit(cl_name)) {
20155 vty_out(vty, "%% Community name cannot have all digits\n");
20156 return CMD_WARNING_CONFIG_FAILED;
20157 }
20158
20159 idx = 0;
20160 argv_find(argv, argc, "AA:BB:CC", &idx);
20161 argv_find(argv, argc, "LINE", &idx);
20162 /* Concat community string argument. */
20163 if (idx)
20164 str = argv_concat(argv, argc, idx);
20165 else
20166 str = NULL;
20167
20168 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
20169
20170 /* Free temporary community list string allocated by
20171 argv_concat(). */
20172 XFREE(MTYPE_TMP, str);
20173
20174 if (ret < 0) {
20175 community_list_perror(vty, ret);
20176 return CMD_WARNING_CONFIG_FAILED;
20177 }
20178 return CMD_SUCCESS;
20179 }
20180
20181 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
20182 struct cmd_token **argv, int style)
20183 {
20184 int ret;
20185 int direct = 0;
20186 char *str = NULL;
20187 int idx = 0;
20188 char *seq = NULL;
20189
20190 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20191 seq = argv[idx]->arg;
20192
20193 idx = 0;
20194 argv_find(argv, argc, "permit", &idx);
20195 argv_find(argv, argc, "deny", &idx);
20196
20197 if (idx) {
20198 /* Check the list direct. */
20199 if (strncmp(argv[idx]->arg, "p", 1) == 0)
20200 direct = COMMUNITY_PERMIT;
20201 else
20202 direct = COMMUNITY_DENY;
20203
20204 idx = 0;
20205 argv_find(argv, argc, "LINE", &idx);
20206 argv_find(argv, argc, "AA:AA:NN", &idx);
20207 /* Concat community string argument. */
20208 str = argv_concat(argv, argc, idx);
20209 }
20210
20211 idx = 0;
20212 argv_find(argv, argc, "(1-99)", &idx);
20213 argv_find(argv, argc, "(100-500)", &idx);
20214 argv_find(argv, argc, "WORD", &idx);
20215
20216 /* Unset community list. */
20217 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
20218 style);
20219
20220 /* Free temporary community list string allocated by
20221 argv_concat(). */
20222 XFREE(MTYPE_TMP, str);
20223
20224 if (ret < 0) {
20225 community_list_perror(vty, ret);
20226 return CMD_WARNING_CONFIG_FAILED;
20227 }
20228
20229 return CMD_SUCCESS;
20230 }
20231
20232 /* "large-community-list" keyword help string. */
20233 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
20234 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
20235
20236 DEFUN (lcommunity_list_standard,
20237 bgp_lcommunity_list_standard_cmd,
20238 "bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
20239 BGP_STR
20240 LCOMMUNITY_LIST_STR
20241 "Large Community list number (standard)\n"
20242 "Sequence number of an entry\n"
20243 "Sequence number\n"
20244 "Specify large community to reject\n"
20245 "Specify large community to accept\n"
20246 LCOMMUNITY_VAL_STR)
20247 {
20248 return lcommunity_list_set_vty(vty, argc, argv,
20249 LARGE_COMMUNITY_LIST_STANDARD, 0);
20250 }
20251
20252 DEFUN (lcommunity_list_expanded,
20253 bgp_lcommunity_list_expanded_cmd,
20254 "bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
20255 BGP_STR
20256 LCOMMUNITY_LIST_STR
20257 "Large Community list number (expanded)\n"
20258 "Sequence number of an entry\n"
20259 "Sequence number\n"
20260 "Specify large community to reject\n"
20261 "Specify large community to accept\n"
20262 "An ordered list as a regular-expression\n")
20263 {
20264 return lcommunity_list_set_vty(vty, argc, argv,
20265 LARGE_COMMUNITY_LIST_EXPANDED, 0);
20266 }
20267
20268 DEFUN (lcommunity_list_name_standard,
20269 bgp_lcommunity_list_name_standard_cmd,
20270 "bgp large-community-list standard WORD [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
20271 BGP_STR
20272 LCOMMUNITY_LIST_STR
20273 "Specify standard large-community-list\n"
20274 "Large Community list name\n"
20275 "Sequence number of an entry\n"
20276 "Sequence number\n"
20277 "Specify large community to reject\n"
20278 "Specify large community to accept\n"
20279 LCOMMUNITY_VAL_STR)
20280 {
20281 return lcommunity_list_set_vty(vty, argc, argv,
20282 LARGE_COMMUNITY_LIST_STANDARD, 1);
20283 }
20284
20285 DEFUN (lcommunity_list_name_expanded,
20286 bgp_lcommunity_list_name_expanded_cmd,
20287 "bgp large-community-list expanded WORD [seq (0-4294967295)] <deny|permit> LINE...",
20288 BGP_STR
20289 LCOMMUNITY_LIST_STR
20290 "Specify expanded large-community-list\n"
20291 "Large Community list name\n"
20292 "Sequence number of an entry\n"
20293 "Sequence number\n"
20294 "Specify large community to reject\n"
20295 "Specify large community to accept\n"
20296 "An ordered list as a regular-expression\n")
20297 {
20298 return lcommunity_list_set_vty(vty, argc, argv,
20299 LARGE_COMMUNITY_LIST_EXPANDED, 1);
20300 }
20301
20302 DEFUN (no_lcommunity_list_all,
20303 no_bgp_lcommunity_list_all_cmd,
20304 "no bgp large-community-list <(1-99)|(100-500)|WORD>",
20305 NO_STR
20306 BGP_STR
20307 LCOMMUNITY_LIST_STR
20308 "Large Community list number (standard)\n"
20309 "Large Community list number (expanded)\n"
20310 "Large Community list name\n")
20311 {
20312 return lcommunity_list_unset_vty(vty, argc, argv,
20313 LARGE_COMMUNITY_LIST_STANDARD);
20314 }
20315
20316 DEFUN (no_lcommunity_list_name_standard_all,
20317 no_bgp_lcommunity_list_name_standard_all_cmd,
20318 "no bgp large-community-list standard WORD",
20319 NO_STR
20320 BGP_STR
20321 LCOMMUNITY_LIST_STR
20322 "Specify standard large-community-list\n"
20323 "Large Community list name\n")
20324 {
20325 return lcommunity_list_unset_vty(vty, argc, argv,
20326 LARGE_COMMUNITY_LIST_STANDARD);
20327 }
20328
20329 DEFUN (no_lcommunity_list_name_expanded_all,
20330 no_bgp_lcommunity_list_name_expanded_all_cmd,
20331 "no bgp large-community-list expanded WORD",
20332 NO_STR
20333 BGP_STR
20334 LCOMMUNITY_LIST_STR
20335 "Specify expanded large-community-list\n"
20336 "Large Community list name\n")
20337 {
20338 return lcommunity_list_unset_vty(vty, argc, argv,
20339 LARGE_COMMUNITY_LIST_EXPANDED);
20340 }
20341
20342 DEFUN (no_lcommunity_list_standard,
20343 no_bgp_lcommunity_list_standard_cmd,
20344 "no bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
20345 NO_STR
20346 BGP_STR
20347 LCOMMUNITY_LIST_STR
20348 "Large Community list number (standard)\n"
20349 "Sequence number of an entry\n"
20350 "Sequence number\n"
20351 "Specify large community to reject\n"
20352 "Specify large community to accept\n"
20353 LCOMMUNITY_VAL_STR)
20354 {
20355 return lcommunity_list_unset_vty(vty, argc, argv,
20356 LARGE_COMMUNITY_LIST_STANDARD);
20357 }
20358
20359 DEFUN (no_lcommunity_list_expanded,
20360 no_bgp_lcommunity_list_expanded_cmd,
20361 "no bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
20362 NO_STR
20363 BGP_STR
20364 LCOMMUNITY_LIST_STR
20365 "Large Community list number (expanded)\n"
20366 "Sequence number of an entry\n"
20367 "Sequence number\n"
20368 "Specify large community to reject\n"
20369 "Specify large community to accept\n"
20370 "An ordered list as a regular-expression\n")
20371 {
20372 return lcommunity_list_unset_vty(vty, argc, argv,
20373 LARGE_COMMUNITY_LIST_EXPANDED);
20374 }
20375
20376 DEFUN (no_lcommunity_list_name_standard,
20377 no_bgp_lcommunity_list_name_standard_cmd,
20378 "no bgp large-community-list standard WORD [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
20379 NO_STR
20380 BGP_STR
20381 LCOMMUNITY_LIST_STR
20382 "Specify standard large-community-list\n"
20383 "Large Community list name\n"
20384 "Sequence number of an entry\n"
20385 "Sequence number\n"
20386 "Specify large community to reject\n"
20387 "Specify large community to accept\n"
20388 LCOMMUNITY_VAL_STR)
20389 {
20390 return lcommunity_list_unset_vty(vty, argc, argv,
20391 LARGE_COMMUNITY_LIST_STANDARD);
20392 }
20393
20394 DEFUN (no_lcommunity_list_name_expanded,
20395 no_bgp_lcommunity_list_name_expanded_cmd,
20396 "no bgp large-community-list expanded WORD [seq (0-4294967295)] <deny|permit> LINE...",
20397 NO_STR
20398 BGP_STR
20399 LCOMMUNITY_LIST_STR
20400 "Specify expanded large-community-list\n"
20401 "Large community list name\n"
20402 "Sequence number of an entry\n"
20403 "Sequence number\n"
20404 "Specify large community to reject\n"
20405 "Specify large community to accept\n"
20406 "An ordered list as a regular-expression\n")
20407 {
20408 return lcommunity_list_unset_vty(vty, argc, argv,
20409 LARGE_COMMUNITY_LIST_EXPANDED);
20410 }
20411
20412 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
20413 {
20414 struct community_entry *entry;
20415
20416 for (entry = list->head; entry; entry = entry->next) {
20417 if (entry == list->head) {
20418 if (all_digit(list->name))
20419 vty_out(vty, "Large community %s list %s\n",
20420 entry->style ==
20421 LARGE_COMMUNITY_LIST_STANDARD
20422 ? "standard"
20423 : "(expanded) access",
20424 list->name);
20425 else
20426 vty_out(vty,
20427 "Named large community %s list %s\n",
20428 entry->style ==
20429 LARGE_COMMUNITY_LIST_STANDARD
20430 ? "standard"
20431 : "expanded",
20432 list->name);
20433 }
20434 if (entry->any)
20435 vty_out(vty, " %s\n",
20436 community_direct_str(entry->direct));
20437 else
20438 vty_out(vty, " %s %s\n",
20439 community_direct_str(entry->direct),
20440 community_list_config_str(entry));
20441 }
20442 }
20443
20444 DEFUN (show_lcommunity_list,
20445 show_bgp_lcommunity_list_cmd,
20446 "show bgp large-community-list",
20447 SHOW_STR
20448 BGP_STR
20449 "List large-community list\n")
20450 {
20451 struct community_list *list;
20452 struct community_list_master *cm;
20453
20454 cm = community_list_master_lookup(bgp_clist,
20455 LARGE_COMMUNITY_LIST_MASTER);
20456 if (!cm)
20457 return CMD_SUCCESS;
20458
20459 for (list = cm->num.head; list; list = list->next)
20460 lcommunity_list_show(vty, list);
20461
20462 for (list = cm->str.head; list; list = list->next)
20463 lcommunity_list_show(vty, list);
20464
20465 return CMD_SUCCESS;
20466 }
20467
20468 DEFUN (show_lcommunity_list_arg,
20469 show_bgp_lcommunity_list_arg_cmd,
20470 "show bgp large-community-list <(1-500)|WORD> detail",
20471 SHOW_STR
20472 BGP_STR
20473 "List large-community list\n"
20474 "Large-community-list number\n"
20475 "Large-community-list name\n"
20476 "Detailed information on large-community-list\n")
20477 {
20478 struct community_list *list;
20479
20480 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
20481 LARGE_COMMUNITY_LIST_MASTER);
20482 if (!list) {
20483 vty_out(vty, "%% Can't find large-community-list\n");
20484 return CMD_WARNING;
20485 }
20486
20487 lcommunity_list_show(vty, list);
20488
20489 return CMD_SUCCESS;
20490 }
20491
20492 /* "extcommunity-list" keyword help string. */
20493 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
20494 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
20495
20496 DEFUN (extcommunity_list_standard,
20497 bgp_extcommunity_list_standard_cmd,
20498 "bgp extcommunity-list <(1-99)|standard WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
20499 BGP_STR
20500 EXTCOMMUNITY_LIST_STR
20501 "Extended Community list number (standard)\n"
20502 "Specify standard extcommunity-list\n"
20503 "Community list name\n"
20504 "Sequence number of an entry\n"
20505 "Sequence number\n"
20506 "Specify community to reject\n"
20507 "Specify community to accept\n"
20508 EXTCOMMUNITY_VAL_STR)
20509 {
20510 int style = EXTCOMMUNITY_LIST_STANDARD;
20511 int direct = 0;
20512 char *cl_number_or_name = NULL;
20513 char *seq = NULL;
20514
20515 int idx = 0;
20516
20517 argv_find(argv, argc, "(1-99)", &idx);
20518 argv_find(argv, argc, "WORD", &idx);
20519 cl_number_or_name = argv[idx]->arg;
20520
20521 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20522 seq = argv[idx]->arg;
20523
20524 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20525 : COMMUNITY_DENY;
20526 argv_find(argv, argc, "AA:NN", &idx);
20527 char *str = argv_concat(argv, argc, idx);
20528
20529 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
20530 direct, style);
20531
20532 XFREE(MTYPE_TMP, str);
20533
20534 if (ret < 0) {
20535 community_list_perror(vty, ret);
20536 return CMD_WARNING_CONFIG_FAILED;
20537 }
20538
20539 return CMD_SUCCESS;
20540 }
20541
20542 DEFUN (extcommunity_list_name_expanded,
20543 bgp_extcommunity_list_name_expanded_cmd,
20544 "bgp extcommunity-list <(100-500)|expanded WORD> [seq (0-4294967295)] <deny|permit> LINE...",
20545 BGP_STR
20546 EXTCOMMUNITY_LIST_STR
20547 "Extended Community list number (expanded)\n"
20548 "Specify expanded extcommunity-list\n"
20549 "Extended Community list name\n"
20550 "Sequence number of an entry\n"
20551 "Sequence number\n"
20552 "Specify community to reject\n"
20553 "Specify community to accept\n"
20554 "An ordered list as a regular-expression\n")
20555 {
20556 int style = EXTCOMMUNITY_LIST_EXPANDED;
20557 int direct = 0;
20558 char *cl_number_or_name = NULL;
20559 char *seq = NULL;
20560 int idx = 0;
20561
20562 argv_find(argv, argc, "(100-500)", &idx);
20563 argv_find(argv, argc, "WORD", &idx);
20564 cl_number_or_name = argv[idx]->arg;
20565
20566 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20567 seq = argv[idx]->arg;
20568
20569 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20570 : COMMUNITY_DENY;
20571 argv_find(argv, argc, "LINE", &idx);
20572 char *str = argv_concat(argv, argc, idx);
20573
20574 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
20575 direct, style);
20576
20577 XFREE(MTYPE_TMP, str);
20578
20579 if (ret < 0) {
20580 community_list_perror(vty, ret);
20581 return CMD_WARNING_CONFIG_FAILED;
20582 }
20583
20584 return CMD_SUCCESS;
20585 }
20586
20587 DEFUN (no_extcommunity_list_standard_all,
20588 no_bgp_extcommunity_list_standard_all_cmd,
20589 "no bgp extcommunity-list <(1-99)|standard WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
20590 NO_STR
20591 BGP_STR
20592 EXTCOMMUNITY_LIST_STR
20593 "Extended Community list number (standard)\n"
20594 "Specify standard extcommunity-list\n"
20595 "Community list name\n"
20596 "Sequence number of an entry\n"
20597 "Sequence number\n"
20598 "Specify community to reject\n"
20599 "Specify community to accept\n"
20600 EXTCOMMUNITY_VAL_STR)
20601 {
20602 int style = EXTCOMMUNITY_LIST_STANDARD;
20603 int direct = 0;
20604 char *cl_number_or_name = NULL;
20605 char *str = NULL;
20606 char *seq = NULL;
20607 int idx = 0;
20608
20609 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20610 seq = argv[idx]->arg;
20611
20612 idx = 0;
20613 argv_find(argv, argc, "permit", &idx);
20614 argv_find(argv, argc, "deny", &idx);
20615 if (idx) {
20616 direct = argv_find(argv, argc, "permit", &idx)
20617 ? COMMUNITY_PERMIT
20618 : COMMUNITY_DENY;
20619
20620 idx = 0;
20621 argv_find(argv, argc, "AA:NN", &idx);
20622 str = argv_concat(argv, argc, idx);
20623 }
20624
20625 idx = 0;
20626 argv_find(argv, argc, "(1-99)", &idx);
20627 argv_find(argv, argc, "WORD", &idx);
20628 cl_number_or_name = argv[idx]->arg;
20629
20630 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
20631 seq, direct, style);
20632
20633 XFREE(MTYPE_TMP, str);
20634
20635 if (ret < 0) {
20636 community_list_perror(vty, ret);
20637 return CMD_WARNING_CONFIG_FAILED;
20638 }
20639
20640 return CMD_SUCCESS;
20641 }
20642
20643 ALIAS(no_extcommunity_list_standard_all,
20644 no_bgp_extcommunity_list_standard_all_list_cmd,
20645 "no bgp extcommunity-list <(1-99)|standard WORD>",
20646 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
20647 "Extended Community list number (standard)\n"
20648 "Specify standard extcommunity-list\n"
20649 "Community list name\n")
20650
20651 DEFUN (no_extcommunity_list_expanded_all,
20652 no_bgp_extcommunity_list_expanded_all_cmd,
20653 "no bgp extcommunity-list <(100-500)|expanded WORD> [seq (0-4294967295)] <deny|permit> LINE...",
20654 NO_STR
20655 BGP_STR
20656 EXTCOMMUNITY_LIST_STR
20657 "Extended Community list number (expanded)\n"
20658 "Specify expanded extcommunity-list\n"
20659 "Extended Community list name\n"
20660 "Sequence number of an entry\n"
20661 "Sequence number\n"
20662 "Specify community to reject\n"
20663 "Specify community to accept\n"
20664 "An ordered list as a regular-expression\n")
20665 {
20666 int style = EXTCOMMUNITY_LIST_EXPANDED;
20667 int direct = 0;
20668 char *cl_number_or_name = NULL;
20669 char *str = NULL;
20670 char *seq = NULL;
20671 int idx = 0;
20672
20673 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20674 seq = argv[idx]->arg;
20675
20676 idx = 0;
20677 argv_find(argv, argc, "permit", &idx);
20678 argv_find(argv, argc, "deny", &idx);
20679
20680 if (idx) {
20681 direct = argv_find(argv, argc, "permit", &idx)
20682 ? COMMUNITY_PERMIT
20683 : COMMUNITY_DENY;
20684
20685 idx = 0;
20686 argv_find(argv, argc, "LINE", &idx);
20687 str = argv_concat(argv, argc, idx);
20688 }
20689
20690 idx = 0;
20691 argv_find(argv, argc, "(100-500)", &idx);
20692 argv_find(argv, argc, "WORD", &idx);
20693 cl_number_or_name = argv[idx]->arg;
20694
20695 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
20696 seq, direct, style);
20697
20698 XFREE(MTYPE_TMP, str);
20699
20700 if (ret < 0) {
20701 community_list_perror(vty, ret);
20702 return CMD_WARNING_CONFIG_FAILED;
20703 }
20704
20705 return CMD_SUCCESS;
20706 }
20707
20708 ALIAS(no_extcommunity_list_expanded_all,
20709 no_bgp_extcommunity_list_expanded_all_list_cmd,
20710 "no bgp extcommunity-list <(100-500)|expanded WORD>",
20711 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
20712 "Extended Community list number (expanded)\n"
20713 "Specify expanded extcommunity-list\n"
20714 "Extended Community list name\n")
20715
20716 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
20717 {
20718 struct community_entry *entry;
20719
20720 for (entry = list->head; entry; entry = entry->next) {
20721 if (entry == list->head) {
20722 if (all_digit(list->name))
20723 vty_out(vty, "Extended community %s list %s\n",
20724 entry->style == EXTCOMMUNITY_LIST_STANDARD
20725 ? "standard"
20726 : "(expanded) access",
20727 list->name);
20728 else
20729 vty_out(vty,
20730 "Named extended community %s list %s\n",
20731 entry->style == EXTCOMMUNITY_LIST_STANDARD
20732 ? "standard"
20733 : "expanded",
20734 list->name);
20735 }
20736 if (entry->any)
20737 vty_out(vty, " %s\n",
20738 community_direct_str(entry->direct));
20739 else
20740 vty_out(vty, " %s %s\n",
20741 community_direct_str(entry->direct),
20742 community_list_config_str(entry));
20743 }
20744 }
20745
20746 DEFUN (show_extcommunity_list,
20747 show_bgp_extcommunity_list_cmd,
20748 "show bgp extcommunity-list",
20749 SHOW_STR
20750 BGP_STR
20751 "List extended-community list\n")
20752 {
20753 struct community_list *list;
20754 struct community_list_master *cm;
20755
20756 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
20757 if (!cm)
20758 return CMD_SUCCESS;
20759
20760 for (list = cm->num.head; list; list = list->next)
20761 extcommunity_list_show(vty, list);
20762
20763 for (list = cm->str.head; list; list = list->next)
20764 extcommunity_list_show(vty, list);
20765
20766 return CMD_SUCCESS;
20767 }
20768
20769 DEFUN (show_extcommunity_list_arg,
20770 show_bgp_extcommunity_list_arg_cmd,
20771 "show bgp extcommunity-list <(1-500)|WORD> detail",
20772 SHOW_STR
20773 BGP_STR
20774 "List extended-community list\n"
20775 "Extcommunity-list number\n"
20776 "Extcommunity-list name\n"
20777 "Detailed information on extcommunity-list\n")
20778 {
20779 int idx_comm_list = 3;
20780 struct community_list *list;
20781
20782 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
20783 EXTCOMMUNITY_LIST_MASTER);
20784 if (!list) {
20785 vty_out(vty, "%% Can't find extcommunity-list\n");
20786 return CMD_WARNING;
20787 }
20788
20789 extcommunity_list_show(vty, list);
20790
20791 return CMD_SUCCESS;
20792 }
20793
20794 /* Display community-list and extcommunity-list configuration. */
20795 static int community_list_config_write(struct vty *vty)
20796 {
20797 struct community_list *list;
20798 struct community_entry *entry;
20799 struct community_list_master *cm;
20800 int write = 0;
20801
20802 /* Community-list. */
20803 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
20804
20805 for (list = cm->num.head; list; list = list->next)
20806 for (entry = list->head; entry; entry = entry->next) {
20807 vty_out(vty,
20808 "bgp community-list %s seq %" PRId64 " %s %s\n",
20809 list->name, entry->seq,
20810 community_direct_str(entry->direct),
20811 community_list_config_str(entry));
20812 write++;
20813 }
20814 for (list = cm->str.head; list; list = list->next)
20815 for (entry = list->head; entry; entry = entry->next) {
20816 vty_out(vty,
20817 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
20818 entry->style == COMMUNITY_LIST_STANDARD
20819 ? "standard"
20820 : "expanded",
20821 list->name, entry->seq,
20822 community_direct_str(entry->direct),
20823 community_list_config_str(entry));
20824 write++;
20825 }
20826
20827 /* Extcommunity-list. */
20828 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
20829
20830 for (list = cm->num.head; list; list = list->next)
20831 for (entry = list->head; entry; entry = entry->next) {
20832 vty_out(vty,
20833 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
20834 list->name, entry->seq,
20835 community_direct_str(entry->direct),
20836 community_list_config_str(entry));
20837 write++;
20838 }
20839 for (list = cm->str.head; list; list = list->next)
20840 for (entry = list->head; entry; entry = entry->next) {
20841 vty_out(vty,
20842 "bgp extcommunity-list %s %s seq %" PRId64" %s %s\n",
20843 entry->style == EXTCOMMUNITY_LIST_STANDARD
20844 ? "standard"
20845 : "expanded",
20846 list->name, entry->seq,
20847 community_direct_str(entry->direct),
20848 community_list_config_str(entry));
20849 write++;
20850 }
20851
20852
20853 /* lcommunity-list. */
20854 cm = community_list_master_lookup(bgp_clist,
20855 LARGE_COMMUNITY_LIST_MASTER);
20856
20857 for (list = cm->num.head; list; list = list->next)
20858 for (entry = list->head; entry; entry = entry->next) {
20859 vty_out(vty,
20860 "bgp large-community-list %s seq %" PRId64" %s %s\n",
20861 list->name, entry->seq,
20862 community_direct_str(entry->direct),
20863 community_list_config_str(entry));
20864 write++;
20865 }
20866 for (list = cm->str.head; list; list = list->next)
20867 for (entry = list->head; entry; entry = entry->next) {
20868 vty_out(vty,
20869 "bgp large-community-list %s %s seq %" PRId64" %s %s\n",
20870
20871 entry->style == LARGE_COMMUNITY_LIST_STANDARD
20872 ? "standard"
20873 : "expanded",
20874 list->name, entry->seq, community_direct_str(entry->direct),
20875 community_list_config_str(entry));
20876 write++;
20877 }
20878
20879 return write;
20880 }
20881
20882 static int community_list_config_write(struct vty *vty);
20883 static struct cmd_node community_list_node = {
20884 .name = "community list",
20885 .node = COMMUNITY_LIST_NODE,
20886 .prompt = "",
20887 .config_write = community_list_config_write,
20888 };
20889
20890 static void community_list_vty(void)
20891 {
20892 install_node(&community_list_node);
20893
20894 /* Community-list. */
20895 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
20896 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
20897 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
20898 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
20899 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
20900 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
20901 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
20902 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
20903
20904 /* Extcommunity-list. */
20905 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
20906 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
20907 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
20908 install_element(CONFIG_NODE,
20909 &no_bgp_extcommunity_list_standard_all_list_cmd);
20910 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
20911 install_element(CONFIG_NODE,
20912 &no_bgp_extcommunity_list_expanded_all_list_cmd);
20913 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
20914 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
20915
20916 /* Large Community List */
20917 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
20918 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
20919 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
20920 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
20921 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
20922 install_element(CONFIG_NODE,
20923 &no_bgp_lcommunity_list_name_standard_all_cmd);
20924 install_element(CONFIG_NODE,
20925 &no_bgp_lcommunity_list_name_expanded_all_cmd);
20926 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
20927 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
20928 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
20929 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
20930 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
20931 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
20932 }
20933
20934 static struct cmd_node community_alias_node = {
20935 .name = "community alias",
20936 .node = COMMUNITY_ALIAS_NODE,
20937 .prompt = "",
20938 .config_write = bgp_community_alias_write,
20939 };
20940
20941 void community_alias_vty(void)
20942 {
20943 install_node(&community_alias_node);
20944
20945 /* Community-list. */
20946 install_element(CONFIG_NODE, &bgp_community_alias_cmd);
20947 }