]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
Merge pull request #7809 from donaldsharp/m_coverity
[mirror_frr.git] / bgpd / bgp_vty.c
1 /* BGP VTY interface.
2 * Copyright (C) 1996, 97, 98, 99, 2000 Kunihiro Ishiguro
3 *
4 * This file is part of GNU Zebra.
5 *
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
10 *
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include <zebra.h>
22
23 #include "command.h"
24 #include "lib/json.h"
25 #include "lib_errors.h"
26 #include "lib/zclient.h"
27 #include "prefix.h"
28 #include "plist.h"
29 #include "buffer.h"
30 #include "linklist.h"
31 #include "stream.h"
32 #include "thread.h"
33 #include "log.h"
34 #include "memory.h"
35 #include "lib_vty.h"
36 #include "hash.h"
37 #include "queue.h"
38 #include "filter.h"
39 #include "frrstr.h"
40
41 #include "bgpd/bgpd.h"
42 #include "bgpd/bgp_attr_evpn.h"
43 #include "bgpd/bgp_advertise.h"
44 #include "bgpd/bgp_attr.h"
45 #include "bgpd/bgp_aspath.h"
46 #include "bgpd/bgp_community.h"
47 #include "bgpd/bgp_ecommunity.h"
48 #include "bgpd/bgp_lcommunity.h"
49 #include "bgpd/bgp_damp.h"
50 #include "bgpd/bgp_debug.h"
51 #include "bgpd/bgp_errors.h"
52 #include "bgpd/bgp_fsm.h"
53 #include "bgpd/bgp_nexthop.h"
54 #include "bgpd/bgp_open.h"
55 #include "bgpd/bgp_regex.h"
56 #include "bgpd/bgp_route.h"
57 #include "bgpd/bgp_mplsvpn.h"
58 #include "bgpd/bgp_zebra.h"
59 #include "bgpd/bgp_table.h"
60 #include "bgpd/bgp_vty.h"
61 #include "bgpd/bgp_mpath.h"
62 #include "bgpd/bgp_packet.h"
63 #include "bgpd/bgp_updgrp.h"
64 #include "bgpd/bgp_bfd.h"
65 #include "bgpd/bgp_io.h"
66 #include "bgpd/bgp_evpn.h"
67 #include "bgpd/bgp_evpn_vty.h"
68 #include "bgpd/bgp_evpn_mh.h"
69 #include "bgpd/bgp_addpath.h"
70 #include "bgpd/bgp_mac.h"
71 #include "bgpd/bgp_flowspec.h"
72 #ifdef ENABLE_BGP_VNC
73 #include "bgpd/rfapi/bgp_rfapi_cfg.h"
74 #endif
75
76 #include "northbound.h"
77 #include "northbound_cli.h"
78 #include "bgpd/bgp_nb.h"
79
80
81 FRR_CFG_DEFAULT_BOOL(BGP_IMPORT_CHECK,
82 {
83 .val_bool = false,
84 .match_profile = "traditional",
85 .match_version = "< 7.4",
86 },
87 { .val_bool = true },
88 )
89 FRR_CFG_DEFAULT_BOOL(BGP_SHOW_HOSTNAME,
90 { .val_bool = true, .match_profile = "datacenter", },
91 { .val_bool = false },
92 )
93 FRR_CFG_DEFAULT_BOOL(BGP_SHOW_NEXTHOP_HOSTNAME,
94 { .val_bool = true, .match_profile = "datacenter", },
95 { .val_bool = false },
96 )
97 FRR_CFG_DEFAULT_BOOL(BGP_LOG_NEIGHBOR_CHANGES,
98 { .val_bool = true, .match_profile = "datacenter", },
99 { .val_bool = false },
100 )
101 FRR_CFG_DEFAULT_BOOL(BGP_DETERMINISTIC_MED,
102 { .val_bool = true, .match_profile = "datacenter", },
103 { .val_bool = false },
104 )
105 FRR_CFG_DEFAULT_ULONG(BGP_CONNECT_RETRY,
106 { .val_ulong = 10, .match_profile = "datacenter", },
107 { .val_ulong = 120 },
108 )
109 FRR_CFG_DEFAULT_ULONG(BGP_HOLDTIME,
110 { .val_ulong = 9, .match_profile = "datacenter", },
111 { .val_ulong = 180 },
112 )
113 FRR_CFG_DEFAULT_ULONG(BGP_KEEPALIVE,
114 { .val_ulong = 3, .match_profile = "datacenter", },
115 { .val_ulong = 60 },
116 )
117 FRR_CFG_DEFAULT_BOOL(BGP_EBGP_REQUIRES_POLICY,
118 { .val_bool = false, .match_profile = "datacenter", },
119 { .val_bool = false, .match_version = "< 7.4", },
120 { .val_bool = true },
121 )
122
123 DEFINE_HOOK(bgp_inst_config_write,
124 (struct bgp *bgp, struct vty *vty),
125 (bgp, vty))
126
127 #define GR_NO_OPER \
128 "The Graceful Restart No Operation was executed as cmd same as previous one."
129 #define GR_INVALID \
130 "The Graceful Restart command used is not valid at this moment."
131 static struct peer_group *listen_range_exists(struct bgp *bgp,
132 struct prefix *range, int exact);
133
134 /* Show BGP peer's information. */
135 enum show_type {
136 show_all,
137 show_peer,
138 show_ipv4_all,
139 show_ipv6_all,
140 show_ipv4_peer,
141 show_ipv6_peer
142 };
143
144 static struct peer_group *listen_range_exists(struct bgp *bgp,
145 struct prefix *range, int exact);
146
147 static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
148 struct bgp *bgp,
149 bool use_json,
150 json_object *json);
151
152 static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
153 enum show_type type,
154 const char *ip_str,
155 afi_t afi, bool use_json);
156
157 static int peer_and_group_lookup_nb(struct vty *vty, const char *peer_str,
158 char *base_xpath, int xpath_len,
159 char *abs_xpath);
160
161 static enum node_type bgp_node_type(afi_t afi, safi_t safi)
162 {
163 switch (afi) {
164 case AFI_IP:
165 switch (safi) {
166 case SAFI_UNICAST:
167 return BGP_IPV4_NODE;
168 case SAFI_MULTICAST:
169 return BGP_IPV4M_NODE;
170 case SAFI_LABELED_UNICAST:
171 return BGP_IPV4L_NODE;
172 case SAFI_MPLS_VPN:
173 return BGP_VPNV4_NODE;
174 case SAFI_FLOWSPEC:
175 return BGP_FLOWSPECV4_NODE;
176 default:
177 /* not expected */
178 return BGP_IPV4_NODE;
179 }
180 break;
181 case AFI_IP6:
182 switch (safi) {
183 case SAFI_UNICAST:
184 return BGP_IPV6_NODE;
185 case SAFI_MULTICAST:
186 return BGP_IPV6M_NODE;
187 case SAFI_LABELED_UNICAST:
188 return BGP_IPV6L_NODE;
189 case SAFI_MPLS_VPN:
190 return BGP_VPNV6_NODE;
191 case SAFI_FLOWSPEC:
192 return BGP_FLOWSPECV6_NODE;
193 default:
194 /* not expected */
195 return BGP_IPV4_NODE;
196 }
197 break;
198 case AFI_L2VPN:
199 return BGP_EVPN_NODE;
200 case AFI_UNSPEC:
201 case AFI_MAX:
202 // We should never be here but to clarify the switch statement..
203 return BGP_IPV4_NODE;
204 }
205
206 // Impossible to happen
207 return BGP_IPV4_NODE;
208 }
209
210 static const char *get_afi_safi_vty_str(afi_t afi, safi_t safi)
211 {
212 if (afi == AFI_IP) {
213 if (safi == SAFI_UNICAST)
214 return "IPv4 Unicast";
215 if (safi == SAFI_MULTICAST)
216 return "IPv4 Multicast";
217 if (safi == SAFI_LABELED_UNICAST)
218 return "IPv4 Labeled Unicast";
219 if (safi == SAFI_MPLS_VPN)
220 return "IPv4 VPN";
221 if (safi == SAFI_ENCAP)
222 return "IPv4 Encap";
223 if (safi == SAFI_FLOWSPEC)
224 return "IPv4 Flowspec";
225 } else if (afi == AFI_IP6) {
226 if (safi == SAFI_UNICAST)
227 return "IPv6 Unicast";
228 if (safi == SAFI_MULTICAST)
229 return "IPv6 Multicast";
230 if (safi == SAFI_LABELED_UNICAST)
231 return "IPv6 Labeled Unicast";
232 if (safi == SAFI_MPLS_VPN)
233 return "IPv6 VPN";
234 if (safi == SAFI_ENCAP)
235 return "IPv6 Encap";
236 if (safi == SAFI_FLOWSPEC)
237 return "IPv6 Flowspec";
238 } else if (afi == AFI_L2VPN) {
239 if (safi == SAFI_EVPN)
240 return "L2VPN EVPN";
241 }
242
243 return "Unknown";
244 }
245
246 /*
247 * Please note that we have intentionally camelCased
248 * the return strings here. So if you want
249 * to use this function, please ensure you
250 * are doing this within json output
251 */
252 static const char *get_afi_safi_json_str(afi_t afi, safi_t safi)
253 {
254 if (afi == AFI_IP) {
255 if (safi == SAFI_UNICAST)
256 return "ipv4Unicast";
257 if (safi == SAFI_MULTICAST)
258 return "ipv4Multicast";
259 if (safi == SAFI_LABELED_UNICAST)
260 return "ipv4LabeledUnicast";
261 if (safi == SAFI_MPLS_VPN)
262 return "ipv4Vpn";
263 if (safi == SAFI_ENCAP)
264 return "ipv4Encap";
265 if (safi == SAFI_FLOWSPEC)
266 return "ipv4Flowspec";
267 } else if (afi == AFI_IP6) {
268 if (safi == SAFI_UNICAST)
269 return "ipv6Unicast";
270 if (safi == SAFI_MULTICAST)
271 return "ipv6Multicast";
272 if (safi == SAFI_LABELED_UNICAST)
273 return "ipv6LabeledUnicast";
274 if (safi == SAFI_MPLS_VPN)
275 return "ipv6Vpn";
276 if (safi == SAFI_ENCAP)
277 return "ipv6Encap";
278 if (safi == SAFI_FLOWSPEC)
279 return "ipv6Flowspec";
280 } else if (afi == AFI_L2VPN) {
281 if (safi == SAFI_EVPN)
282 return "l2VpnEvpn";
283 }
284
285 return "Unknown";
286 }
287
288 /* return string maps to afi-safi specific container names
289 * defined in bgp yang file.
290 */
291 const char *bgp_afi_safi_get_container_str(afi_t afi, safi_t safi)
292 {
293 if (afi == AFI_IP) {
294 if (safi == SAFI_UNICAST)
295 return "ipv4-unicast";
296 if (safi == SAFI_MULTICAST)
297 return "ipv4-multicast";
298 if (safi == SAFI_LABELED_UNICAST)
299 return "ipv4-labeled-unicast";
300 if (safi == SAFI_MPLS_VPN)
301 return "l3vpn-ipv4-unicast";
302 if (safi == SAFI_FLOWSPEC)
303 return "ipv4-flowspec";
304 } else if (afi == AFI_IP6) {
305 if (safi == SAFI_UNICAST)
306 return "ipv6-unicast";
307 if (safi == SAFI_MULTICAST)
308 return "ipv6-multicast";
309 if (safi == SAFI_LABELED_UNICAST)
310 return "ipv6-labeled-unicast";
311 if (safi == SAFI_MPLS_VPN)
312 return "l3vpn-ipv6-unicast";
313 if (safi == SAFI_FLOWSPEC)
314 return "ipv6-flowspec";
315 } else if (afi == AFI_L2VPN) {
316 if (safi == SAFI_EVPN)
317 return "l2vpn-evpn";
318 }
319
320 return "Unknown";
321 }
322
323 /* Utility function to get address family from current node. */
324 afi_t bgp_node_afi(struct vty *vty)
325 {
326 afi_t afi;
327 switch (vty->node) {
328 case BGP_IPV6_NODE:
329 case BGP_IPV6M_NODE:
330 case BGP_IPV6L_NODE:
331 case BGP_VPNV6_NODE:
332 case BGP_FLOWSPECV6_NODE:
333 afi = AFI_IP6;
334 break;
335 case BGP_EVPN_NODE:
336 afi = AFI_L2VPN;
337 break;
338 default:
339 afi = AFI_IP;
340 break;
341 }
342 return afi;
343 }
344
345 /* Utility function to get subsequent address family from current
346 node. */
347 safi_t bgp_node_safi(struct vty *vty)
348 {
349 safi_t safi;
350 switch (vty->node) {
351 case BGP_VPNV4_NODE:
352 case BGP_VPNV6_NODE:
353 safi = SAFI_MPLS_VPN;
354 break;
355 case BGP_IPV4M_NODE:
356 case BGP_IPV6M_NODE:
357 safi = SAFI_MULTICAST;
358 break;
359 case BGP_EVPN_NODE:
360 safi = SAFI_EVPN;
361 break;
362 case BGP_IPV4L_NODE:
363 case BGP_IPV6L_NODE:
364 safi = SAFI_LABELED_UNICAST;
365 break;
366 case BGP_FLOWSPECV4_NODE:
367 case BGP_FLOWSPECV6_NODE:
368 safi = SAFI_FLOWSPEC;
369 break;
370 default:
371 safi = SAFI_UNICAST;
372 break;
373 }
374 return safi;
375 }
376
377 /**
378 * Converts an AFI in string form to afi_t
379 *
380 * @param afi string, one of
381 * - "ipv4"
382 * - "ipv6"
383 * - "l2vpn"
384 * @return the corresponding afi_t
385 */
386 afi_t bgp_vty_afi_from_str(const char *afi_str)
387 {
388 afi_t afi = AFI_MAX; /* unknown */
389 if (strmatch(afi_str, "ipv4"))
390 afi = AFI_IP;
391 else if (strmatch(afi_str, "ipv6"))
392 afi = AFI_IP6;
393 else if (strmatch(afi_str, "l2vpn"))
394 afi = AFI_L2VPN;
395 return afi;
396 }
397
398 int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
399 afi_t *afi)
400 {
401 int ret = 0;
402 if (argv_find(argv, argc, "ipv4", index)) {
403 ret = 1;
404 if (afi)
405 *afi = AFI_IP;
406 } else if (argv_find(argv, argc, "ipv6", index)) {
407 ret = 1;
408 if (afi)
409 *afi = AFI_IP6;
410 } else if (argv_find(argv, argc, "l2vpn", index)) {
411 ret = 1;
412 if (afi)
413 *afi = AFI_L2VPN;
414 }
415 return ret;
416 }
417
418 /* supports <unicast|multicast|vpn|labeled-unicast> */
419 safi_t bgp_vty_safi_from_str(const char *safi_str)
420 {
421 safi_t safi = SAFI_MAX; /* unknown */
422 if (strmatch(safi_str, "multicast"))
423 safi = SAFI_MULTICAST;
424 else if (strmatch(safi_str, "unicast"))
425 safi = SAFI_UNICAST;
426 else if (strmatch(safi_str, "vpn"))
427 safi = SAFI_MPLS_VPN;
428 else if (strmatch(safi_str, "evpn"))
429 safi = SAFI_EVPN;
430 else if (strmatch(safi_str, "labeled-unicast"))
431 safi = SAFI_LABELED_UNICAST;
432 else if (strmatch(safi_str, "flowspec"))
433 safi = SAFI_FLOWSPEC;
434 return safi;
435 }
436
437 int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
438 safi_t *safi)
439 {
440 int ret = 0;
441 if (argv_find(argv, argc, "unicast", index)) {
442 ret = 1;
443 if (safi)
444 *safi = SAFI_UNICAST;
445 } else if (argv_find(argv, argc, "multicast", index)) {
446 ret = 1;
447 if (safi)
448 *safi = SAFI_MULTICAST;
449 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
450 ret = 1;
451 if (safi)
452 *safi = SAFI_LABELED_UNICAST;
453 } else if (argv_find(argv, argc, "vpn", index)) {
454 ret = 1;
455 if (safi)
456 *safi = SAFI_MPLS_VPN;
457 } else if (argv_find(argv, argc, "evpn", index)) {
458 ret = 1;
459 if (safi)
460 *safi = SAFI_EVPN;
461 } else if (argv_find(argv, argc, "flowspec", index)) {
462 ret = 1;
463 if (safi)
464 *safi = SAFI_FLOWSPEC;
465 }
466 return ret;
467 }
468
469 int bgp_get_vty(struct bgp **bgp, as_t *as, const char *name,
470 enum bgp_instance_type inst_type)
471 {
472 int ret = bgp_get(bgp, as, name, inst_type);
473
474 if (ret == BGP_CREATED) {
475 bgp_timers_set(*bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
476 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
477
478 if (DFLT_BGP_IMPORT_CHECK)
479 SET_FLAG((*bgp)->flags, BGP_FLAG_IMPORT_CHECK);
480 if (DFLT_BGP_SHOW_HOSTNAME)
481 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_HOSTNAME);
482 if (DFLT_BGP_SHOW_NEXTHOP_HOSTNAME)
483 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
484 if (DFLT_BGP_LOG_NEIGHBOR_CHANGES)
485 SET_FLAG((*bgp)->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
486 if (DFLT_BGP_DETERMINISTIC_MED)
487 SET_FLAG((*bgp)->flags, BGP_FLAG_DETERMINISTIC_MED);
488 if (DFLT_BGP_EBGP_REQUIRES_POLICY)
489 SET_FLAG((*bgp)->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
490
491 ret = BGP_SUCCESS;
492 }
493 return ret;
494 }
495
496 /*
497 * bgp_vty_find_and_parse_afi_safi_bgp
498 *
499 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
500 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
501 * to appropriate values for the calling function. This is to allow the
502 * calling function to make decisions appropriate for the show command
503 * that is being parsed.
504 *
505 * The show commands are generally of the form:
506 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
507 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
508 *
509 * Since we use argv_find if the show command in particular doesn't have:
510 * [ip]
511 * [<view|vrf> VIEWVRFNAME]
512 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
513 * The command parsing should still be ok.
514 *
515 * vty -> The vty for the command so we can output some useful data in
516 * the event of a parse error in the vrf.
517 * argv -> The command tokens
518 * argc -> How many command tokens we have
519 * idx -> The current place in the command, generally should be 0 for this
520 * function
521 * afi -> The parsed afi if it was included in the show command, returned here
522 * safi -> The parsed safi if it was included in the show command, returned here
523 * bgp -> Pointer to the bgp data structure we need to fill in.
524 * use_json -> json is configured or not
525 *
526 * The function returns the correct location in the parse tree for the
527 * last token found.
528 *
529 * Returns 0 for failure to parse correctly, else the idx position of where
530 * it found the last token.
531 */
532 int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
533 struct cmd_token **argv, int argc,
534 int *idx, afi_t *afi, safi_t *safi,
535 struct bgp **bgp, bool use_json)
536 {
537 char *vrf_name = NULL;
538
539 assert(afi);
540 assert(safi);
541 assert(bgp);
542
543 if (argv_find(argv, argc, "ip", idx))
544 *afi = AFI_IP;
545
546 if (argv_find(argv, argc, "view", idx))
547 vrf_name = argv[*idx + 1]->arg;
548 else if (argv_find(argv, argc, "vrf", idx)) {
549 vrf_name = argv[*idx + 1]->arg;
550 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
551 vrf_name = NULL;
552 }
553 if (vrf_name) {
554 if (strmatch(vrf_name, "all"))
555 *bgp = NULL;
556 else {
557 *bgp = bgp_lookup_by_name(vrf_name);
558 if (!*bgp) {
559 if (use_json) {
560 json_object *json = NULL;
561 json = json_object_new_object();
562 json_object_string_add(
563 json, "warning",
564 "View/Vrf is unknown");
565 vty_out(vty, "%s\n",
566 json_object_to_json_string_ext(json,
567 JSON_C_TO_STRING_PRETTY));
568 json_object_free(json);
569 }
570 else
571 vty_out(vty, "View/Vrf %s is unknown\n",
572 vrf_name);
573 *idx = 0;
574 return 0;
575 }
576 }
577 } else {
578 *bgp = bgp_get_default();
579 if (!*bgp) {
580 if (use_json) {
581 json_object *json = NULL;
582 json = json_object_new_object();
583 json_object_string_add(
584 json, "warning",
585 "Default BGP instance not found");
586 vty_out(vty, "%s\n",
587 json_object_to_json_string_ext(json,
588 JSON_C_TO_STRING_PRETTY));
589 json_object_free(json);
590 }
591 else
592 vty_out(vty,
593 "Default BGP instance not found\n");
594 *idx = 0;
595 return 0;
596 }
597 }
598
599 if (argv_find_and_parse_afi(argv, argc, idx, afi))
600 argv_find_and_parse_safi(argv, argc, idx, safi);
601
602 *idx += 1;
603 return *idx;
604 }
605
606 bool peer_address_self_check(struct bgp *bgp, union sockunion *su)
607 {
608 struct interface *ifp = NULL;
609
610 if (su->sa.sa_family == AF_INET)
611 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
612 else if (su->sa.sa_family == AF_INET6)
613 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
614 su->sin6.sin6_scope_id,
615 bgp->vrf_id);
616
617 if (ifp)
618 return true;
619
620 return false;
621 }
622
623 /* Utility function for looking up peer or peer group. */
624 /* This is used only for configuration, so disallow if attempted on
625 * a dynamic neighbor.
626 */
627 struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
628 {
629 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
630 int ret;
631 union sockunion su;
632 struct peer *peer = NULL;
633 struct peer_group *group = NULL;
634
635 if (!bgp) {
636 return NULL;
637 }
638
639 ret = str2sockunion(peer_str, &su);
640 if (ret == 0) {
641 /* IP address, locate peer. */
642 peer = peer_lookup(bgp, &su);
643 } else {
644 /* Not IP, could match either peer configured on interface or a
645 * group. */
646 peer = peer_lookup_by_conf_if(bgp, peer_str);
647 if (!peer)
648 group = peer_group_lookup(bgp, peer_str);
649 }
650
651 if (peer) {
652 if (peer_dynamic_neighbor(peer)) {
653 vty_out(vty,
654 "%% Operation not allowed on a dynamic neighbor\n");
655 return NULL;
656 }
657
658 return peer;
659 }
660
661 if (group)
662 return group->conf;
663
664 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
665
666 return NULL;
667 }
668
669 int bgp_nb_errmsg_return(char *errmsg, size_t errmsg_len, int ret)
670 {
671 const char *str = NULL;
672
673 switch (ret) {
674 case BGP_ERR_INVALID_VALUE:
675 str = "Invalid value";
676 break;
677 case BGP_ERR_INVALID_FLAG:
678 str = "Invalid flag";
679 break;
680 case BGP_ERR_PEER_GROUP_SHUTDOWN:
681 str = "Peer-group has been shutdown. Activate the peer-group first";
682 break;
683 case BGP_ERR_PEER_FLAG_CONFLICT:
684 str = "Can't set override-capability and strict-capability-match at the same time";
685 break;
686 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
687 str = "Specify remote-as or peer-group remote AS first";
688 break;
689 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
690 str = "Cannot change the peer-group. Deconfigure first";
691 break;
692 case BGP_ERR_PEER_GROUP_MISMATCH:
693 str = "Peer is not a member of this peer-group";
694 break;
695 case BGP_ERR_PEER_FILTER_CONFLICT:
696 str = "Prefix/distribute list can not co-exist";
697 break;
698 case BGP_ERR_NOT_INTERNAL_PEER:
699 str = "Invalid command. Not an internal neighbor";
700 break;
701 case BGP_ERR_REMOVE_PRIVATE_AS:
702 str = "remove-private-AS cannot be configured for IBGP peers";
703 break;
704 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
705 str = "Local-AS allowed only for EBGP peers";
706 break;
707 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
708 str = "Cannot have local-as same as BGP AS number";
709 break;
710 case BGP_ERR_TCPSIG_FAILED:
711 str = "Error while applying TCP-Sig to session(s)";
712 break;
713 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
714 str = "ebgp-multihop and ttl-security cannot be configured together";
715 break;
716 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
717 str = "ttl-security only allowed for EBGP peers";
718 break;
719 case BGP_ERR_AS_OVERRIDE:
720 str = "as-override cannot be configured for IBGP peers";
721 break;
722 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
723 str = "Invalid limit for number of dynamic neighbors";
724 break;
725 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
726 str = "Dynamic neighbor listen range already exists";
727 break;
728 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
729 str = "Operation not allowed on a dynamic neighbor";
730 break;
731 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
732 str = "Operation not allowed on a directly connected neighbor";
733 break;
734 case BGP_ERR_PEER_SAFI_CONFLICT:
735 str = GR_INVALID;
736 break;
737 case BGP_ERR_GR_INVALID_CMD:
738 str = "The Graceful Restart command used is not valid at this moment.";
739 break;
740 case BGP_ERR_GR_OPERATION_FAILED:
741 str = "The Graceful Restart Operation failed due to an err.";
742 break;
743 case BGP_GR_NO_OPERATION:
744 str = GR_NO_OPER;
745 break;
746 case BGP_ERR_PEER_GROUP_MEMBER:
747 str = "Peer-group member cannot override remote-as of peer-group";
748 break;
749 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
750 str = "Peer-group members must be all internal or all external";
751 break;
752 }
753 if (str) {
754 snprintf(errmsg, errmsg_len, "%s", str);
755 return -1;
756 }
757
758 return 0;
759 }
760
761 int bgp_vty_return(struct vty *vty, int ret)
762 {
763 const char *str = NULL;
764
765 switch (ret) {
766 case BGP_ERR_INVALID_VALUE:
767 str = "Invalid value";
768 break;
769 case BGP_ERR_INVALID_FLAG:
770 str = "Invalid flag";
771 break;
772 case BGP_ERR_PEER_GROUP_SHUTDOWN:
773 str = "Peer-group has been shutdown. Activate the peer-group first";
774 break;
775 case BGP_ERR_PEER_FLAG_CONFLICT:
776 str = "Can't set override-capability and strict-capability-match at the same time";
777 break;
778 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
779 str = "Specify remote-as or peer-group remote AS first";
780 break;
781 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
782 str = "Cannot change the peer-group. Deconfigure first";
783 break;
784 case BGP_ERR_PEER_GROUP_MISMATCH:
785 str = "Peer is not a member of this peer-group";
786 break;
787 case BGP_ERR_PEER_FILTER_CONFLICT:
788 str = "Prefix/distribute list can not co-exist";
789 break;
790 case BGP_ERR_NOT_INTERNAL_PEER:
791 str = "Invalid command. Not an internal neighbor";
792 break;
793 case BGP_ERR_REMOVE_PRIVATE_AS:
794 str = "remove-private-AS cannot be configured for IBGP peers";
795 break;
796 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
797 str = "Local-AS allowed only for EBGP peers";
798 break;
799 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
800 str = "Cannot have local-as same as BGP AS number";
801 break;
802 case BGP_ERR_TCPSIG_FAILED:
803 str = "Error while applying TCP-Sig to session(s)";
804 break;
805 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
806 str = "ebgp-multihop and ttl-security cannot be configured together";
807 break;
808 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
809 str = "ttl-security only allowed for EBGP peers";
810 break;
811 case BGP_ERR_AS_OVERRIDE:
812 str = "as-override cannot be configured for IBGP peers";
813 break;
814 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
815 str = "Invalid limit for number of dynamic neighbors";
816 break;
817 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
818 str = "Dynamic neighbor listen range already exists";
819 break;
820 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
821 str = "Operation not allowed on a dynamic neighbor";
822 break;
823 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
824 str = "Operation not allowed on a directly connected neighbor";
825 break;
826 case BGP_ERR_PEER_SAFI_CONFLICT:
827 str = GR_INVALID;
828 break;
829 case BGP_ERR_GR_INVALID_CMD:
830 str = "The Graceful Restart command used is not valid at this moment.";
831 break;
832 case BGP_ERR_GR_OPERATION_FAILED:
833 str = "The Graceful Restart Operation failed due to an err.";
834 break;
835 case BGP_GR_NO_OPERATION:
836 str = GR_NO_OPER;
837 break;
838 }
839 if (str) {
840 vty_out(vty, "%% %s\n", str);
841 return CMD_WARNING_CONFIG_FAILED;
842 }
843 return CMD_SUCCESS;
844 }
845
846 /* BGP clear sort. */
847 enum clear_sort {
848 clear_all,
849 clear_peer,
850 clear_group,
851 clear_external,
852 clear_as
853 };
854
855 static void bgp_clear_vty_error(struct peer *peer, afi_t afi, safi_t safi,
856 int error, char *errmsg, size_t errmsg_len)
857 {
858 switch (error) {
859 case BGP_ERR_AF_UNCONFIGURED:
860 snprintf(errmsg, errmsg_len,
861 "%%BGP: Enable %s address family for the neighbor %s",
862 get_afi_safi_str(afi, safi, false), peer->host);
863 break;
864 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
865 snprintf(
866 errmsg, errmsg_len,
867 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig",
868 peer->host);
869 break;
870 default:
871 break;
872 }
873 }
874
875 static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi,
876 struct listnode **nnode, enum bgp_clear_type stype)
877 {
878 int ret = 0;
879
880 /* if afi/.safi not specified, spin thru all of them */
881 if ((afi == AFI_UNSPEC) && (safi == SAFI_UNSPEC)) {
882 afi_t tmp_afi;
883 safi_t tmp_safi;
884
885 FOREACH_AFI_SAFI (tmp_afi, tmp_safi) {
886 if (!peer->afc[tmp_afi][tmp_safi])
887 continue;
888
889 if (stype == BGP_CLEAR_SOFT_NONE)
890 ret = peer_clear(peer, nnode);
891 else
892 ret = peer_clear_soft(peer, tmp_afi, tmp_safi,
893 stype);
894 }
895 /* if afi specified and safi not, spin thru safis on this afi */
896 } else if (safi == SAFI_UNSPEC) {
897 safi_t tmp_safi;
898
899 for (tmp_safi = SAFI_UNICAST;
900 tmp_safi < SAFI_MAX; tmp_safi++) {
901 if (!peer->afc[afi][tmp_safi])
902 continue;
903
904 if (stype == BGP_CLEAR_SOFT_NONE)
905 ret = peer_clear(peer, nnode);
906 else
907 ret = peer_clear_soft(peer, afi,
908 tmp_safi, stype);
909 }
910 /* both afi/safi specified, let the caller know if not defined */
911 } else {
912 if (!peer->afc[afi][safi])
913 return 1;
914
915 if (stype == BGP_CLEAR_SOFT_NONE)
916 ret = peer_clear(peer, nnode);
917 else
918 ret = peer_clear_soft(peer, afi, safi, stype);
919 }
920
921 return ret;
922 }
923
924 /* `clear ip bgp' functions. */
925 static int bgp_clear(struct bgp *bgp, afi_t afi, safi_t safi,
926 enum clear_sort sort, enum bgp_clear_type stype,
927 const char *arg, char *errmsg, size_t errmsg_len)
928 {
929 int ret = 0;
930 bool found = false;
931 struct peer *peer;
932
933 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
934
935 /* Clear all neighbors. */
936 /*
937 * Pass along pointer to next node to peer_clear() when walking all
938 * nodes on the BGP instance as that may get freed if it is a
939 * doppelganger
940 */
941 if (sort == clear_all) {
942 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
943
944 bgp_peer_gr_flags_update(peer);
945
946 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
947 gr_router_detected = true;
948
949 ret = bgp_peer_clear(peer, afi, safi, &nnode,
950 stype);
951
952 if (ret < 0)
953 bgp_clear_vty_error(peer, afi, safi, ret,
954 errmsg, errmsg_len);
955 }
956
957 if (gr_router_detected
958 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
959 bgp_zebra_send_capabilities(bgp, false);
960 } else if (!gr_router_detected
961 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
962 bgp_zebra_send_capabilities(bgp, true);
963 }
964
965 /* This is to apply read-only mode on this clear. */
966 if (stype == BGP_CLEAR_SOFT_NONE)
967 bgp->update_delay_over = 0;
968
969 return CMD_SUCCESS;
970 }
971
972 /* Clear specified neighbor. */
973 if (sort == clear_peer) {
974 union sockunion su;
975
976 /* Make sockunion for lookup. */
977 ret = str2sockunion(arg, &su);
978 if (ret < 0) {
979 peer = peer_lookup_by_conf_if(bgp, arg);
980 if (!peer) {
981 peer = peer_lookup_by_hostname(bgp, arg);
982 if (!peer) {
983 snprintf(
984 errmsg, errmsg_len,
985 "Malformed address or name: %s",
986 arg);
987 return CMD_WARNING;
988 }
989 }
990 } else {
991 peer = peer_lookup(bgp, &su);
992 if (!peer) {
993 snprintf(errmsg, errmsg_len,
994 "%%BGP: Unknown neighbor - \"%s\"",
995 arg);
996 return CMD_WARNING;
997 }
998 }
999
1000 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
1001 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
1002
1003 ret = bgp_peer_clear(peer, afi, safi, NULL, stype);
1004
1005 /* if afi/safi not defined for this peer, let caller know */
1006 if (ret == 1)
1007 ret = BGP_ERR_AF_UNCONFIGURED;
1008
1009 if (ret < 0)
1010 bgp_clear_vty_error(peer, afi, safi, ret, errmsg,
1011 errmsg_len);
1012
1013 return CMD_SUCCESS;
1014 }
1015
1016 /* Clear all neighbors belonging to a specific peer-group. */
1017 if (sort == clear_group) {
1018 struct peer_group *group;
1019
1020 group = peer_group_lookup(bgp, arg);
1021 if (!group) {
1022 snprintf(errmsg, errmsg_len,
1023 "%%BGP: No such peer-group %s", arg);
1024 return CMD_WARNING;
1025 }
1026
1027 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
1028 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1029
1030 if (ret < 0)
1031 bgp_clear_vty_error(peer, afi, safi, ret,
1032 errmsg, errmsg_len);
1033 else
1034 found = true;
1035 }
1036
1037 if (!found)
1038 snprintf(
1039 errmsg, errmsg_len,
1040 "%%BGP: No %s peer belonging to peer-group %s is configured",
1041 get_afi_safi_str(afi, safi, false), arg);
1042
1043 return CMD_SUCCESS;
1044 }
1045
1046 /* Clear all external (eBGP) neighbors. */
1047 if (sort == clear_external) {
1048 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1049 if (peer->sort == BGP_PEER_IBGP)
1050 continue;
1051
1052 bgp_peer_gr_flags_update(peer);
1053
1054 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1055 gr_router_detected = true;
1056
1057 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1058
1059 if (ret < 0)
1060 bgp_clear_vty_error(peer, afi, safi, ret,
1061 errmsg, errmsg_len);
1062 else
1063 found = true;
1064 }
1065
1066 if (gr_router_detected
1067 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1068 bgp_zebra_send_capabilities(bgp, false);
1069 } else if (!gr_router_detected
1070 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1071 bgp_zebra_send_capabilities(bgp, true);
1072 }
1073
1074 if (!found)
1075 snprintf(errmsg, errmsg_len,
1076 "%%BGP: No external %s peer is configured",
1077 get_afi_safi_str(afi, safi, false));
1078
1079 return CMD_SUCCESS;
1080 }
1081
1082 /* Clear all neighbors belonging to a specific AS. */
1083 if (sort == clear_as) {
1084 as_t as = strtoul(arg, NULL, 10);
1085
1086 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1087 if (peer->as != as)
1088 continue;
1089
1090 bgp_peer_gr_flags_update(peer);
1091
1092 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1093 gr_router_detected = true;
1094
1095 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1096
1097 if (ret < 0)
1098 bgp_clear_vty_error(peer, afi, safi, ret,
1099 errmsg, errmsg_len);
1100 else
1101 found = true;
1102 }
1103
1104 if (gr_router_detected
1105 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1106 bgp_zebra_send_capabilities(bgp, false);
1107 } else if (!gr_router_detected
1108 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1109 bgp_zebra_send_capabilities(bgp, true);
1110 }
1111
1112 if (!found)
1113 snprintf(errmsg, errmsg_len,
1114 "%%BGP: No %s peer is configured with AS %s",
1115 get_afi_safi_str(afi, safi, false), arg);
1116
1117 return CMD_SUCCESS;
1118 }
1119
1120 return CMD_SUCCESS;
1121 }
1122
1123 static int bgp_clear_vty(const char *name, afi_t afi, safi_t safi,
1124 enum clear_sort sort, enum bgp_clear_type stype,
1125 const char *arg, char *errmsg, size_t errmsg_len)
1126 {
1127 struct bgp *bgp;
1128
1129 /* BGP structure lookup. */
1130 if (name) {
1131 bgp = bgp_lookup_by_name(name);
1132 if (bgp == NULL) {
1133 snprintf(errmsg, errmsg_len,
1134 "Can't find BGP instance %s", name);
1135 return CMD_WARNING;
1136 }
1137 } else {
1138 bgp = bgp_get_default();
1139 if (bgp == NULL) {
1140 snprintf(errmsg, errmsg_len,
1141 "No BGP process is configured");
1142 return CMD_WARNING;
1143 }
1144 }
1145
1146 return bgp_clear(bgp, afi, safi, sort, stype, arg, errmsg, errmsg_len);
1147 }
1148
1149 /* clear soft inbound */
1150 int bgp_clear_star_soft_in(const char *name, char *errmsg, size_t errmsg_len)
1151 {
1152 afi_t afi;
1153 safi_t safi;
1154 int ret;
1155
1156 FOREACH_AFI_SAFI (afi, safi) {
1157 ret = bgp_clear_vty(name, afi, safi, clear_all,
1158 BGP_CLEAR_SOFT_IN, NULL, errmsg,
1159 errmsg_len);
1160 if (ret != CMD_SUCCESS)
1161 return -1;
1162 }
1163
1164 return 0;
1165 }
1166
1167 /* clear soft outbound */
1168 int bgp_clear_star_soft_out(const char *name, char *errmsg, size_t errmsg_len)
1169 {
1170 afi_t afi;
1171 safi_t safi;
1172 int ret;
1173
1174 FOREACH_AFI_SAFI (afi, safi) {
1175 ret = bgp_clear_vty(name, afi, safi, clear_all,
1176 BGP_CLEAR_SOFT_OUT, NULL, errmsg,
1177 errmsg_len);
1178 if (ret != CMD_SUCCESS)
1179 return -1;
1180 }
1181
1182 return 0;
1183 }
1184
1185
1186 #ifndef VTYSH_EXTRACT_PL
1187 #include "bgpd/bgp_vty_clippy.c"
1188 #endif
1189
1190 DEFUN_HIDDEN (bgp_local_mac,
1191 bgp_local_mac_cmd,
1192 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
1193 BGP_STR
1194 "Local MAC config\n"
1195 "VxLAN Network Identifier\n"
1196 "VNI number\n"
1197 "local mac\n"
1198 "mac address\n"
1199 "mac-mobility sequence\n"
1200 "seq number\n")
1201 {
1202 int rv;
1203 vni_t vni;
1204 struct ethaddr mac;
1205 struct ipaddr ip;
1206 uint32_t seq;
1207 struct bgp *bgp;
1208
1209 vni = strtoul(argv[3]->arg, NULL, 10);
1210 if (!prefix_str2mac(argv[5]->arg, &mac)) {
1211 vty_out(vty, "%% Malformed MAC address\n");
1212 return CMD_WARNING;
1213 }
1214 memset(&ip, 0, sizeof(ip));
1215 seq = strtoul(argv[7]->arg, NULL, 10);
1216
1217 bgp = bgp_get_default();
1218 if (!bgp) {
1219 vty_out(vty, "Default BGP instance is not there\n");
1220 return CMD_WARNING;
1221 }
1222
1223 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq,
1224 zero_esi);
1225 if (rv < 0) {
1226 vty_out(vty, "Internal error\n");
1227 return CMD_WARNING;
1228 }
1229
1230 return CMD_SUCCESS;
1231 }
1232
1233 DEFUN_HIDDEN (no_bgp_local_mac,
1234 no_bgp_local_mac_cmd,
1235 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
1236 NO_STR
1237 BGP_STR
1238 "Local MAC config\n"
1239 "VxLAN Network Identifier\n"
1240 "VNI number\n"
1241 "local mac\n"
1242 "mac address\n")
1243 {
1244 int rv;
1245 vni_t vni;
1246 struct ethaddr mac;
1247 struct ipaddr ip;
1248 struct bgp *bgp;
1249
1250 vni = strtoul(argv[4]->arg, NULL, 10);
1251 if (!prefix_str2mac(argv[6]->arg, &mac)) {
1252 vty_out(vty, "%% Malformed MAC address\n");
1253 return CMD_WARNING;
1254 }
1255 memset(&ip, 0, sizeof(ip));
1256
1257 bgp = bgp_get_default();
1258 if (!bgp) {
1259 vty_out(vty, "Default BGP instance is not there\n");
1260 return CMD_WARNING;
1261 }
1262
1263 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
1264 if (rv < 0) {
1265 vty_out(vty, "Internal error\n");
1266 return CMD_WARNING;
1267 }
1268
1269 return CMD_SUCCESS;
1270 }
1271
1272 DEFUN (no_synchronization,
1273 no_synchronization_cmd,
1274 "no synchronization",
1275 NO_STR
1276 "Perform IGP synchronization\n")
1277 {
1278 return CMD_SUCCESS;
1279 }
1280
1281 DEFUN (no_auto_summary,
1282 no_auto_summary_cmd,
1283 "no auto-summary",
1284 NO_STR
1285 "Enable automatic network number summarization\n")
1286 {
1287 return CMD_SUCCESS;
1288 }
1289
1290 /* "router bgp" commands. */
1291 DEFUN_YANG_NOSH(router_bgp,
1292 router_bgp_cmd,
1293 "router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1294 ROUTER_STR BGP_STR AS_STR BGP_INSTANCE_HELP_STR)
1295 {
1296 int idx_asn = 2;
1297 int idx_view_vrf = 3;
1298 int idx_vrf = 4;
1299 int ret = CMD_SUCCESS;
1300 as_t as;
1301 struct bgp *bgp;
1302 const char *name = NULL;
1303 char as_str[12] = {'\0'};
1304 enum bgp_instance_type inst_type;
1305 char base_xpath[XPATH_MAXLEN];
1306
1307 // "router bgp" without an ASN
1308 if (argc == 2) {
1309 // Pending: Make VRF option available for ASN less config
1310 bgp = bgp_get_default();
1311
1312 if (bgp == NULL) {
1313 vty_out(vty, "%% No BGP process is configured\n");
1314 return CMD_WARNING_CONFIG_FAILED;
1315 }
1316
1317 if (listcount(bm->bgp) > 1) {
1318 vty_out(vty, "%% Please specify ASN and VRF\n");
1319 return CMD_WARNING_CONFIG_FAILED;
1320 }
1321
1322 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_GLOBAL_XPATH,
1323 "frr-bgp:bgp", "bgp", VRF_DEFAULT_NAME);
1324
1325 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
1326 snprintf(as_str, 12, "%d", bgp->as);
1327 nb_cli_enqueue_change(vty, "./global/local-as", NB_OP_MODIFY,
1328 as_str);
1329 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW) {
1330 nb_cli_enqueue_change(vty,
1331 "./global/instance-type-view",
1332 NB_OP_MODIFY, "true");
1333 }
1334
1335 nb_cli_pending_commit_check(vty);
1336 ret = nb_cli_apply_changes(vty, base_xpath);
1337 if (ret == CMD_SUCCESS) {
1338 VTY_PUSH_XPATH(BGP_NODE, base_xpath);
1339
1340 /*
1341 * For backward compatibility with old commands we still
1342 * need to use the qobj infrastructure.
1343 */
1344 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1345 }
1346 return ret;
1347 }
1348
1349 // "router bgp X"
1350 else {
1351
1352 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1353 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1354 if (argc > 3) {
1355 name = argv[idx_vrf]->arg;
1356
1357 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1358 if (strmatch(name, VRF_DEFAULT_NAME))
1359 name = NULL;
1360 else
1361 inst_type = BGP_INSTANCE_TYPE_VRF;
1362 } else if (!strcmp(argv[idx_view_vrf]->text, "view")) {
1363 inst_type = BGP_INSTANCE_TYPE_VIEW;
1364 }
1365 }
1366 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_GLOBAL_XPATH,
1367 "frr-bgp:bgp", "bgp", name ? name : VRF_DEFAULT_NAME);
1368
1369 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
1370 nb_cli_enqueue_change(vty, "./global/local-as", NB_OP_MODIFY,
1371 argv[idx_asn]->arg);
1372 if (inst_type == BGP_INSTANCE_TYPE_VIEW) {
1373 nb_cli_enqueue_change(vty,
1374 "./global/instance-type-view",
1375 NB_OP_MODIFY, "true");
1376 }
1377
1378 nb_cli_pending_commit_check(vty);
1379 ret = nb_cli_apply_changes(vty, base_xpath);
1380 if (ret == CMD_SUCCESS) {
1381 VTY_PUSH_XPATH(BGP_NODE, base_xpath);
1382
1383 /*
1384 * For backward compatibility with old commands we still
1385 * need to use the qobj infrastructure.
1386 */
1387 bgp = bgp_lookup(as, name);
1388 if (bgp)
1389 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1390 }
1391 }
1392
1393 return ret;
1394 }
1395
1396 /* "no router bgp" commands. */
1397 DEFUN_YANG(no_router_bgp,
1398 no_router_bgp_cmd,
1399 "no router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1400 NO_STR ROUTER_STR BGP_STR AS_STR BGP_INSTANCE_HELP_STR)
1401 {
1402 int idx_asn = 3;
1403 int idx_vrf = 5;
1404 as_t as = 0;
1405 struct bgp *bgp;
1406 const char *name = NULL;
1407 char base_xpath[XPATH_MAXLEN];
1408 const struct lyd_node *bgp_glb_dnode;
1409
1410 // "no router bgp" without an ASN
1411 if (argc == 3) {
1412 // Pending: Make VRF option available for ASN less config
1413 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_GLOBAL_XPATH,
1414 "frr-bgp:bgp", "bgp", VRF_DEFAULT_NAME);
1415
1416 bgp_glb_dnode = yang_dnode_get(vty->candidate_config->dnode,
1417 base_xpath);
1418 if (!bgp_glb_dnode) {
1419 vty_out(vty, "%% No BGP process is configured\n");
1420 return CMD_WARNING_CONFIG_FAILED;
1421 }
1422
1423 if (listcount(bm->bgp) > 1) {
1424 vty_out(vty, "%% Please specify ASN and VRF\n");
1425 return CMD_WARNING_CONFIG_FAILED;
1426 }
1427
1428 /* tcli mode bgp would not be set until apply stage. */
1429 bgp = nb_running_get_entry(bgp_glb_dnode, NULL, false);
1430 if (!bgp)
1431 return CMD_SUCCESS;
1432
1433 if (bgp->l3vni) {
1434 vty_out(vty, "%% Please unconfigure l3vni %u",
1435 bgp->l3vni);
1436 return CMD_WARNING_CONFIG_FAILED;
1437 }
1438 } else {
1439 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1440
1441 if (argc > 4)
1442 name = argv[idx_vrf]->arg;
1443
1444 /* Lookup bgp structure. */
1445 bgp = bgp_lookup(as, name);
1446 if (!bgp) {
1447 vty_out(vty, "%% Can't find BGP instance\n");
1448 return CMD_WARNING_CONFIG_FAILED;
1449 }
1450
1451 if (bgp->l3vni) {
1452 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1453 bgp->l3vni);
1454 return CMD_WARNING_CONFIG_FAILED;
1455 }
1456
1457 /* Cannot delete default instance if vrf instances exist */
1458 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
1459 struct listnode *node;
1460 struct bgp *tmp_bgp;
1461
1462 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, tmp_bgp)) {
1463 if (tmp_bgp->inst_type
1464 == BGP_INSTANCE_TYPE_VRF) {
1465 vty_out(vty,
1466 "%% Cannot delete default BGP instance. Dependent VRF instances exist\n");
1467 return CMD_WARNING_CONFIG_FAILED;
1468 }
1469 }
1470 }
1471 }
1472 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_GLOBAL_XPATH,
1473 "frr-bgp:bgp", "bgp",
1474 bgp->name ? bgp->name : VRF_DEFAULT_NAME);
1475
1476 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
1477
1478 return nb_cli_apply_changes(vty, base_xpath);
1479 }
1480
1481 void cli_show_router_bgp(struct vty *vty, struct lyd_node *dnode,
1482 bool show_defaults)
1483 {
1484 const struct lyd_node *vrf_dnode;
1485 const char *vrf_name;
1486 as_t as;
1487
1488 vrf_dnode = yang_dnode_get_parent(dnode, "control-plane-protocol");
1489 vrf_name = yang_dnode_get_string(vrf_dnode, "./vrf");
1490 as = yang_dnode_get_uint32(dnode, "./global/local-as");
1491
1492 vty_out(vty, "!\n");
1493 vty_out(vty, "router bgp %u", as);
1494 if (!strmatch(vrf_name, VRF_DEFAULT_NAME))
1495 vty_out(vty, " vrf %s", vrf_name);
1496 vty_out(vty, "\n");
1497 }
1498
1499 /* BGP router-id. */
1500
1501 DEFPY_YANG(bgp_router_id, bgp_router_id_cmd, "bgp router-id A.B.C.D",
1502 BGP_STR
1503 "Override configured router identifier\n"
1504 "Manually configured router identifier\n")
1505 {
1506 nb_cli_enqueue_change(vty, "./global/router-id", NB_OP_MODIFY,
1507 router_id_str);
1508
1509 return nb_cli_apply_changes(vty, NULL);
1510 }
1511
1512 DEFPY_YANG(no_bgp_router_id, no_bgp_router_id_cmd, "no bgp router-id [A.B.C.D]",
1513 NO_STR BGP_STR
1514 "Override configured router identifier\n"
1515 "Manually configured router identifier\n")
1516 {
1517 nb_cli_enqueue_change(vty, "./global/router-id", NB_OP_DESTROY,
1518 router_id_str ? router_id_str : NULL);
1519
1520 return nb_cli_apply_changes(vty, NULL);
1521 }
1522
1523 void cli_show_router_bgp_router_id(struct vty *vty, struct lyd_node *dnode,
1524 bool show_defaults)
1525 {
1526 vty_out(vty, " bgp router-id %s\n", yang_dnode_get_string(dnode, NULL));
1527 }
1528
1529 DEFPY (bgp_global_suppress_fib_pending,
1530 bgp_global_suppress_fib_pending_cmd,
1531 "[no] bgp suppress-fib-pending",
1532 NO_STR
1533 BGP_STR
1534 "Advertise only routes that are programmed in kernel to peers globally\n")
1535 {
1536 bm_wait_for_fib_set(!no);
1537
1538 return CMD_SUCCESS;
1539 }
1540
1541 DEFPY (bgp_suppress_fib_pending,
1542 bgp_suppress_fib_pending_cmd,
1543 "[no] bgp suppress-fib-pending",
1544 NO_STR
1545 BGP_STR
1546 "Advertise only routes that are programmed in kernel to peers\n")
1547 {
1548 VTY_DECLVAR_CONTEXT(bgp, bgp);
1549
1550 bgp_suppress_fib_pending_set(bgp, !no);
1551 return CMD_SUCCESS;
1552 }
1553
1554
1555 /* BGP Cluster ID. */
1556 DEFUN_YANG(bgp_cluster_id,
1557 bgp_cluster_id_cmd,
1558 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1559 BGP_STR
1560 "Configure Route-Reflector Cluster-id\n"
1561 "Route-Reflector Cluster-id in IP address format\n"
1562 "Route-Reflector Cluster-id as 32 bit quantity\n")
1563 {
1564 int idx_ipv4 = 2;
1565
1566 nb_cli_enqueue_change(
1567 vty, "./global/route-reflector/route-reflector-cluster-id",
1568 NB_OP_MODIFY, argv[idx_ipv4]->arg);
1569
1570 return nb_cli_apply_changes(vty, NULL);
1571 }
1572
1573 DEFUN_YANG(no_bgp_cluster_id,
1574 no_bgp_cluster_id_cmd,
1575 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1576 NO_STR BGP_STR
1577 "Configure Route-Reflector Cluster-id\n"
1578 "Route-Reflector Cluster-id in IP address format\n"
1579 "Route-Reflector Cluster-id as 32 bit quantity\n")
1580 {
1581 nb_cli_enqueue_change(
1582 vty, "./global/route-reflector/route-reflector-cluster-id",
1583 NB_OP_DESTROY, NULL);
1584
1585 return nb_cli_apply_changes(vty, NULL);
1586 }
1587
1588 DEFPY (bgp_norib,
1589 bgp_norib_cmd,
1590 "bgp no-rib",
1591 BGP_STR
1592 "Disable BGP route installation to RIB (Zebra)\n")
1593 {
1594 if (bgp_option_check(BGP_OPT_NO_FIB)) {
1595 vty_out(vty,
1596 "%% No-RIB option is already set, nothing to do here.\n");
1597 return CMD_SUCCESS;
1598 }
1599
1600 bgp_option_norib_set_runtime();
1601
1602 return CMD_SUCCESS;
1603 }
1604
1605 DEFPY (no_bgp_norib,
1606 no_bgp_norib_cmd,
1607 "no bgp no-rib",
1608 NO_STR
1609 BGP_STR
1610 "Disable BGP route installation to RIB (Zebra)\n")
1611 {
1612 if (!bgp_option_check(BGP_OPT_NO_FIB)) {
1613 vty_out(vty,
1614 "%% No-RIB option is not set, nothing to do here.\n");
1615 return CMD_SUCCESS;
1616 }
1617
1618 bgp_option_norib_unset_runtime();
1619
1620 return CMD_SUCCESS;
1621 }
1622
1623 DEFPY (no_bgp_send_extra_data,
1624 no_bgp_send_extra_data_cmd,
1625 "[no] bgp send-extra-data zebra",
1626 NO_STR
1627 BGP_STR
1628 "Extra data to Zebra for display/use\n"
1629 "To zebra\n")
1630 {
1631 if (no)
1632 UNSET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1633 else
1634 SET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1635
1636 return CMD_SUCCESS;
1637 }
1638
1639 DEFUN_YANG(bgp_confederation_identifier,
1640 bgp_confederation_identifier_cmd,
1641 "bgp confederation identifier (1-4294967295)",
1642 "BGP specific commands\n"
1643 "AS confederation parameters\n"
1644 "AS number\n"
1645 "Set routing domain confederation AS\n")
1646 {
1647 int idx_number = 3;
1648
1649 nb_cli_enqueue_change(vty, "./global/confederation/identifier",
1650 NB_OP_MODIFY, argv[idx_number]->arg);
1651
1652 return nb_cli_apply_changes(vty, NULL);
1653 }
1654
1655 DEFUN_YANG(no_bgp_confederation_identifier,
1656 no_bgp_confederation_identifier_cmd,
1657 "no bgp confederation identifier [(1-4294967295)]",
1658 NO_STR
1659 "BGP specific commands\n"
1660 "AS confederation parameters\n"
1661 "AS number\n"
1662 "Set routing domain confederation AS\n")
1663 {
1664 nb_cli_enqueue_change(vty, "./global/confederation/identifier",
1665 NB_OP_DESTROY, NULL);
1666
1667 return nb_cli_apply_changes(vty, NULL);
1668 }
1669
1670 void cli_show_router_bgp_confederation_identifier(struct vty *vty,
1671 struct lyd_node *dnode,
1672 bool show_defaults)
1673 {
1674 vty_out(vty, " bgp confederation identifier %u\n",
1675 yang_dnode_get_uint32(dnode, NULL));
1676 }
1677
1678 DEFUN_YANG(bgp_confederation_peers,
1679 bgp_confederation_peers_cmd,
1680 "bgp confederation peers (1-4294967295)...",
1681 "BGP specific commands\n"
1682 "AS confederation parameters\n"
1683 "Peer ASs in BGP confederation\n" AS_STR)
1684 {
1685 int idx_asn = 3;
1686 int i;
1687
1688 for (i = idx_asn; i < argc; i++)
1689 nb_cli_enqueue_change(vty, "./global/confederation/member-as",
1690 NB_OP_CREATE, argv[i]->arg);
1691
1692 return nb_cli_apply_changes(vty, NULL);
1693 }
1694
1695 DEFUN_YANG(no_bgp_confederation_peers,
1696 no_bgp_confederation_peers_cmd,
1697 "no bgp confederation peers (1-4294967295)...",
1698 NO_STR
1699 "BGP specific commands\n"
1700 "AS confederation parameters\n"
1701 "Peer ASs in BGP confederation\n" AS_STR)
1702 {
1703 int idx_asn = 4;
1704 int i;
1705
1706 for (i = idx_asn; i < argc; i++)
1707 nb_cli_enqueue_change(vty, "./global/confederation/member-as",
1708 NB_OP_DESTROY, argv[i]->arg);
1709
1710 return nb_cli_apply_changes(vty, NULL);
1711 }
1712
1713 void cli_show_router_bgp_confederation_member_as(struct vty *vty,
1714 struct lyd_node *dnode,
1715 bool show_defaults)
1716 {
1717 vty_out(vty, " bgp confederation peers %u \n",
1718 yang_dnode_get_uint32(dnode, NULL));
1719 }
1720
1721 /**
1722 * Central routine for maximum-paths configuration.
1723 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1724 * @set: 1 for setting values, 0 for removing the max-paths config.
1725 */
1726 int bgp_maxpaths_config_vty(struct bgp *bgp, afi_t afi, safi_t safi,
1727 int peer_type, uint16_t maxpaths, uint16_t options,
1728 int set, char *errmsg, size_t errmsg_len)
1729 {
1730 int ret;
1731
1732 if (set) {
1733 if (maxpaths > multipath_num) {
1734 snprintf(
1735 errmsg, errmsg_len,
1736 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1737 maxpaths, multipath_num);
1738 return CMD_WARNING_CONFIG_FAILED;
1739 }
1740 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1741 options);
1742 } else
1743 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1744
1745 if (ret < 0) {
1746 snprintf(
1747 errmsg, errmsg_len,
1748 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1749 (set == 1) ? "" : "un",
1750 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1751 maxpaths, afi, safi);
1752 return CMD_WARNING_CONFIG_FAILED;
1753 }
1754
1755 bgp_recalculate_all_bestpaths(bgp);
1756
1757 return CMD_SUCCESS;
1758 }
1759
1760 void cli_show_router_bgp_med_config(struct vty *vty, struct lyd_node *dnode,
1761 bool show_defaults)
1762 {
1763 if (yang_dnode_get_bool(dnode, "./enable-med-admin")) {
1764 uint32_t med_admin_val;
1765
1766 vty_out(vty, " bgp max-med administrative");
1767 if ((med_admin_val =
1768 yang_dnode_get_uint32(dnode, "./max-med-admin"))
1769 != BGP_MAXMED_VALUE_DEFAULT)
1770 vty_out(vty, " %u", med_admin_val);
1771 vty_out(vty, "\n");
1772 }
1773
1774 if (yang_dnode_exists(dnode, "./max-med-onstart-up-time")) {
1775 uint32_t onstartup_val;
1776
1777 vty_out(vty, " bgp max-med on-startup %u",
1778 yang_dnode_get_uint32(dnode,
1779 "./max-med-onstart-up-time"));
1780 onstartup_val = yang_dnode_get_uint32(
1781 dnode, "./max-med-onstart-up-value");
1782 if (onstartup_val != BGP_MAXMED_VALUE_DEFAULT)
1783 vty_out(vty, " %u", onstartup_val);
1784
1785 vty_out(vty, "\n");
1786 }
1787 }
1788
1789 DEFUN_YANG(bgp_maxmed_admin,
1790 bgp_maxmed_admin_cmd,
1791 "bgp max-med administrative ",
1792 BGP_STR
1793 "Advertise routes with max-med\n"
1794 "Administratively applied, for an indefinite period\n")
1795 {
1796 nb_cli_enqueue_change(vty, "./global/med-config/enable-med-admin",
1797 NB_OP_MODIFY, "true");
1798
1799 return nb_cli_apply_changes(vty, NULL);
1800 }
1801
1802 DEFUN_YANG(bgp_maxmed_admin_medv,
1803 bgp_maxmed_admin_medv_cmd,
1804 "bgp max-med administrative (0-4294967295)",
1805 BGP_STR
1806 "Advertise routes with max-med\n"
1807 "Administratively applied, for an indefinite period\n"
1808 "Max MED value to be used\n")
1809 {
1810 int idx_number = 3;
1811
1812 nb_cli_enqueue_change(vty, "./global/med-config/enable-med-admin",
1813 NB_OP_MODIFY, "true");
1814
1815 nb_cli_enqueue_change(vty, "./global/med-config/max-med-admin",
1816 NB_OP_MODIFY, argv[idx_number]->arg);
1817
1818 return nb_cli_apply_changes(vty, NULL);
1819 }
1820
1821 DEFUN_YANG(no_bgp_maxmed_admin,
1822 no_bgp_maxmed_admin_cmd,
1823 "no bgp max-med administrative [(0-4294967295)]",
1824 NO_STR BGP_STR
1825 "Advertise routes with max-med\n"
1826 "Administratively applied, for an indefinite period\n"
1827 "Max MED value to be used\n")
1828 {
1829 nb_cli_enqueue_change(vty, "./global/med-config/enable-med-admin",
1830 NB_OP_MODIFY, "false");
1831
1832 nb_cli_enqueue_change(vty, "./global/med-config/max-med-admin",
1833 NB_OP_MODIFY, NULL);
1834
1835 return nb_cli_apply_changes(vty, NULL);
1836 }
1837
1838 DEFUN_YANG (bgp_maxmed_onstartup,
1839 bgp_maxmed_onstartup_cmd,
1840 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
1841 BGP_STR
1842 "Advertise routes with max-med\n"
1843 "Effective on a startup\n"
1844 "Time (seconds) period for max-med\n"
1845 "Max MED value to be used\n")
1846 {
1847 int idx = 0;
1848
1849 argv_find(argv, argc, "(5-86400)", &idx);
1850 nb_cli_enqueue_change(vty,
1851 "./global/med-config/max-med-onstart-up-time",
1852 NB_OP_MODIFY, argv[idx]->arg);
1853
1854 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1855 nb_cli_enqueue_change(
1856 vty, "./global/med-config/max-med-onstart-up-value",
1857 NB_OP_MODIFY, argv[idx]->arg);
1858 else
1859 nb_cli_enqueue_change(
1860 vty, "./global/med-config/max-med-onstart-up-value",
1861 NB_OP_MODIFY, NULL);
1862
1863 return nb_cli_apply_changes(vty, NULL);
1864 }
1865
1866 DEFUN_YANG (no_bgp_maxmed_onstartup,
1867 no_bgp_maxmed_onstartup_cmd,
1868 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
1869 NO_STR BGP_STR
1870 "Advertise routes with max-med\n"
1871 "Effective on a startup\n"
1872 "Time (seconds) period for max-med\n"
1873 "Max MED value to be used\n")
1874 {
1875 nb_cli_enqueue_change(vty,
1876 "./global/med-config/max-med-onstart-up-time",
1877 NB_OP_DESTROY, NULL);
1878
1879 nb_cli_enqueue_change(vty,
1880 "./global/med-config/max-med-onstart-up-value",
1881 NB_OP_MODIFY, NULL);
1882
1883 return nb_cli_apply_changes(vty, NULL);
1884 }
1885
1886 static int bgp_global_update_delay_config_vty(struct vty *vty,
1887 uint16_t update_delay,
1888 uint16_t establish_wait)
1889 {
1890 struct listnode *node, *nnode;
1891 struct bgp *bgp;
1892 bool vrf_cfg = false;
1893
1894 /*
1895 * See if update-delay is set per-vrf and warn user to delete it
1896 * Note that we only need to check this if this is the first time
1897 * setting the global config.
1898 */
1899 if (bm->v_update_delay == BGP_UPDATE_DELAY_DEF) {
1900 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
1901 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1902 vty_out(vty,
1903 "%% update-delay configuration found in vrf %s\n",
1904 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT
1905 ? VRF_DEFAULT_NAME
1906 : bgp->name);
1907 vrf_cfg = true;
1908 }
1909 }
1910 }
1911
1912 if (vrf_cfg) {
1913 vty_out(vty,
1914 "%%Failed: global update-delay config not permitted\n");
1915 return CMD_WARNING;
1916 }
1917
1918 if (!establish_wait) { /* update-delay <delay> */
1919 bm->v_update_delay = update_delay;
1920 bm->v_establish_wait = bm->v_update_delay;
1921 } else {
1922 /* update-delay <delay> <establish-wait> */
1923 if (update_delay < establish_wait) {
1924 vty_out(vty,
1925 "%%Failed: update-delay less than the establish-wait!\n");
1926 return CMD_WARNING_CONFIG_FAILED;
1927 }
1928
1929 bm->v_update_delay = update_delay;
1930 bm->v_establish_wait = establish_wait;
1931 }
1932
1933 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
1934 bgp->v_update_delay = bm->v_update_delay;
1935 bgp->v_establish_wait = bm->v_establish_wait;
1936 }
1937
1938 return CMD_SUCCESS;
1939 }
1940
1941 static int bgp_global_update_delay_deconfig_vty(struct vty *vty)
1942 {
1943 struct listnode *node, *nnode;
1944 struct bgp *bgp;
1945
1946 bm->v_update_delay = BGP_UPDATE_DELAY_DEF;
1947 bm->v_establish_wait = bm->v_update_delay;
1948
1949 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
1950 bgp->v_update_delay = bm->v_update_delay;
1951 bgp->v_establish_wait = bm->v_establish_wait;
1952 }
1953
1954 return CMD_SUCCESS;
1955 }
1956
1957 static int bgp_update_delay_config_vty(struct vty *vty, uint16_t update_delay,
1958 uint16_t establish_wait)
1959 {
1960 VTY_DECLVAR_CONTEXT(bgp, bgp);
1961
1962 /* if configured globally, per-instance config is not allowed */
1963 if (bm->v_update_delay) {
1964 vty_out(vty,
1965 "%%Failed: per-vrf update-delay config not permitted with global update-delay\n");
1966 return CMD_WARNING_CONFIG_FAILED;
1967 }
1968
1969
1970 if (!establish_wait) /* update-delay <delay> */
1971 {
1972 bgp->v_update_delay = update_delay;
1973 bgp->v_establish_wait = bgp->v_update_delay;
1974 return CMD_SUCCESS;
1975 }
1976
1977 /* update-delay <delay> <establish-wait> */
1978 if (update_delay < establish_wait) {
1979 vty_out(vty,
1980 "%%Failed: update-delay less than the establish-wait!\n");
1981 return CMD_WARNING_CONFIG_FAILED;
1982 }
1983
1984 bgp->v_update_delay = update_delay;
1985 bgp->v_establish_wait = establish_wait;
1986
1987 return CMD_SUCCESS;
1988 }
1989
1990 static int bgp_update_delay_deconfig_vty(struct vty *vty)
1991 {
1992 VTY_DECLVAR_CONTEXT(bgp, bgp);
1993
1994 /* If configured globally, cannot remove from one bgp instance */
1995 if (bm->v_update_delay) {
1996 vty_out(vty,
1997 "%%Failed: bgp update-delay configured globally. Delete per-vrf not permitted\n");
1998 return CMD_WARNING_CONFIG_FAILED;
1999 }
2000 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
2001 bgp->v_establish_wait = bgp->v_update_delay;
2002
2003 return CMD_SUCCESS;
2004 }
2005
2006 void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
2007 {
2008 /* If configured globally, no need to display per-instance value */
2009 if (bgp->v_update_delay != bm->v_update_delay) {
2010 vty_out(vty, " update-delay %d", bgp->v_update_delay);
2011 if (bgp->v_update_delay != bgp->v_establish_wait)
2012 vty_out(vty, " %d", bgp->v_establish_wait);
2013 vty_out(vty, "\n");
2014 }
2015 }
2016
2017 /* Global update-delay configuration */
2018 DEFPY (bgp_global_update_delay,
2019 bgp_global_update_delay_cmd,
2020 "bgp update-delay (0-3600)$delay [(1-3600)$wait]",
2021 BGP_STR
2022 "Force initial delay for best-path and updates for all bgp instances\n"
2023 "Max delay in seconds\n"
2024 "Establish wait in seconds\n")
2025 {
2026 return bgp_global_update_delay_config_vty(vty, delay, wait);
2027 }
2028
2029 /* Global update-delay deconfiguration */
2030 DEFPY (no_bgp_global_update_delay,
2031 no_bgp_global_update_delay_cmd,
2032 "no bgp update-delay [(0-3600) [(1-3600)]]",
2033 NO_STR
2034 BGP_STR
2035 "Force initial delay for best-path and updates\n"
2036 "Max delay in seconds\n"
2037 "Establish wait in seconds\n")
2038 {
2039 return bgp_global_update_delay_deconfig_vty(vty);
2040 }
2041
2042 /* Update-delay configuration */
2043
2044 DEFPY (bgp_update_delay,
2045 bgp_update_delay_cmd,
2046 "update-delay (0-3600)$delay [(1-3600)$wait]",
2047 "Force initial delay for best-path and updates\n"
2048 "Max delay in seconds\n"
2049 "Establish wait in seconds\n")
2050 {
2051 return bgp_update_delay_config_vty(vty, delay, wait);
2052 }
2053
2054 /* Update-delay deconfiguration */
2055 DEFPY (no_bgp_update_delay,
2056 no_bgp_update_delay_cmd,
2057 "no update-delay [(0-3600) [(1-3600)]]",
2058 NO_STR
2059 "Force initial delay for best-path and updates\n"
2060 "Max delay in seconds\n"
2061 "Establish wait in seconds\n")
2062 {
2063 return bgp_update_delay_deconfig_vty(vty);
2064 }
2065
2066
2067 int bgp_wpkt_quanta_config_vty(struct bgp *bgp, uint32_t quanta, bool set)
2068 {
2069 quanta = set ? quanta : BGP_WRITE_PACKET_MAX;
2070 atomic_store_explicit(&bgp->wpkt_quanta, quanta, memory_order_relaxed);
2071
2072 return CMD_SUCCESS;
2073 }
2074
2075 int bgp_rpkt_quanta_config_vty(struct bgp *bgp, uint32_t quanta, bool set)
2076 {
2077 quanta = set ? quanta : BGP_READ_PACKET_MAX;
2078 atomic_store_explicit(&bgp->rpkt_quanta, quanta, memory_order_relaxed);
2079
2080 return CMD_SUCCESS;
2081 }
2082
2083 void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
2084 {
2085 uint32_t quanta =
2086 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
2087 if (quanta != BGP_WRITE_PACKET_MAX)
2088 vty_out(vty, " write-quanta %d\n", quanta);
2089 }
2090
2091 void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
2092 {
2093 uint32_t quanta =
2094 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
2095 if (quanta != BGP_READ_PACKET_MAX)
2096 vty_out(vty, " read-quanta %d\n", quanta);
2097 }
2098
2099 /* Packet quanta configuration
2100 *
2101 * XXX: The value set here controls the size of a stack buffer in the IO
2102 * thread. When changing these limits be careful to prevent stack overflow.
2103 *
2104 * Furthermore, the maximums used here should correspond to
2105 * BGP_WRITE_PACKET_MAX and BGP_READ_PACKET_MAX.
2106 */
2107 DEFPY_YANG (bgp_wpkt_quanta,
2108 bgp_wpkt_quanta_cmd,
2109 "[no] write-quanta (1-64)$quanta",
2110 NO_STR
2111 "How many packets to write to peer socket per run\n"
2112 "Number of packets\n")
2113 {
2114 if (!no)
2115 nb_cli_enqueue_change(
2116 vty,
2117 "./global/global-neighbor-config/packet-quanta-config/wpkt-quanta",
2118 NB_OP_MODIFY, quanta_str);
2119 else
2120 nb_cli_enqueue_change(
2121 vty,
2122 "./global/global-neighbor-config/packet-quanta-config/wpkt-quanta",
2123 NB_OP_MODIFY, NULL);
2124
2125 return nb_cli_apply_changes(vty, NULL);
2126 }
2127
2128 DEFPY_YANG (bgp_rpkt_quanta,
2129 bgp_rpkt_quanta_cmd,
2130 "[no] read-quanta (1-10)$quanta",
2131 NO_STR
2132 "How many packets to read from peer socket per I/O cycle\n"
2133 "Number of packets\n")
2134 {
2135 if (!no)
2136 nb_cli_enqueue_change(
2137 vty,
2138 "./global/global-neighbor-config/packet-quanta-config/rpkt-quanta",
2139 NB_OP_MODIFY, quanta_str);
2140 else
2141 nb_cli_enqueue_change(
2142 vty,
2143 "./global/global-neighbor-config/packet-quanta-config/rpkt-quanta",
2144 NB_OP_MODIFY, NULL);
2145
2146 return nb_cli_apply_changes(vty, NULL);
2147 }
2148
2149 void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
2150 {
2151 if (!bgp->heuristic_coalesce)
2152 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
2153 }
2154
2155 void cli_show_router_global_update_group_config_coalesce_time(
2156 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
2157 {
2158 vty_out(vty, " coalesce-time %u\n", yang_dnode_get_uint32(dnode, NULL));
2159 }
2160
2161
2162 DEFUN_YANG (bgp_coalesce_time,
2163 bgp_coalesce_time_cmd,
2164 "coalesce-time (0-4294967295)",
2165 "Subgroup coalesce timer\n"
2166 "Subgroup coalesce timer value (in ms)\n")
2167 {
2168 int idx = 0;
2169
2170 argv_find(argv, argc, "(0-4294967295)", &idx);
2171 nb_cli_enqueue_change(
2172 vty, "./global/global-update-group-config/coalesce-time",
2173 NB_OP_MODIFY, argv[idx]->arg);
2174
2175 return nb_cli_apply_changes(vty, NULL);
2176 }
2177
2178 DEFUN_YANG(no_bgp_coalesce_time,
2179 no_bgp_coalesce_time_cmd,
2180 "no coalesce-time (0-4294967295)",
2181 NO_STR
2182 "Subgroup coalesce timer\n"
2183 "Subgroup coalesce timer value (in ms)\n")
2184 {
2185 nb_cli_enqueue_change(
2186 vty, "./global/global-update-group-config/coalesce-time",
2187 NB_OP_MODIFY, NULL);
2188
2189 return nb_cli_apply_changes(vty, NULL);
2190 }
2191
2192 /* Maximum-paths configuration */
2193 DEFUN_YANG (bgp_maxpaths,
2194 bgp_maxpaths_cmd,
2195 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2196 "Forward packets over multiple paths\n"
2197 "Number of paths\n")
2198 {
2199 int idx_number = 1;
2200 char base_xpath[XPATH_MAXLEN];
2201 afi_t afi;
2202 safi_t safi;
2203
2204 afi = bgp_node_afi(vty);
2205 safi = bgp_node_safi(vty);
2206
2207 snprintf(
2208 base_xpath, sizeof(base_xpath),
2209 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ebgp/maximum-paths",
2210 yang_afi_safi_value2identity(afi, safi),
2211 bgp_afi_safi_get_container_str(afi, safi));
2212
2213 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY,
2214 argv[idx_number]->arg);
2215
2216 return nb_cli_apply_changes(vty, NULL);
2217 }
2218
2219 void cli_show_bgp_global_afi_safi_unicast_use_multiple_paths_ebgp_maximum_paths(
2220 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
2221 {
2222 vty_out(vty, " maximum-paths %d\n",
2223 yang_dnode_get_uint16(dnode, NULL));
2224 }
2225
2226 ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
2227 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2228 "Forward packets over multiple paths\n"
2229 "Number of paths\n")
2230
2231 DEFUN_YANG (bgp_maxpaths_ibgp,
2232 bgp_maxpaths_ibgp_cmd,
2233 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2234 "Forward packets over multiple paths\n"
2235 "iBGP-multipath\n"
2236 "Number of paths\n")
2237 {
2238 int idx_number = 2;
2239 char base_xpath[XPATH_MAXLEN];
2240 afi_t afi;
2241 safi_t safi;
2242
2243 afi = bgp_node_afi(vty);
2244 safi = bgp_node_safi(vty);
2245
2246 snprintf(
2247 base_xpath, sizeof(base_xpath),
2248 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/maximum-paths",
2249 yang_afi_safi_value2identity(afi, safi),
2250 bgp_afi_safi_get_container_str(afi, safi));
2251
2252 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY,
2253 argv[idx_number]->arg);
2254
2255 return nb_cli_apply_changes(vty, NULL);
2256 }
2257
2258 ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
2259 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2260 "Forward packets over multiple paths\n"
2261 "iBGP-multipath\n"
2262 "Number of paths\n")
2263
2264 DEFUN_YANG (bgp_maxpaths_ibgp_cluster,
2265 bgp_maxpaths_ibgp_cluster_cmd,
2266 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
2267 "Forward packets over multiple paths\n"
2268 "iBGP-multipath\n"
2269 "Number of paths\n"
2270 "Match the cluster length\n")
2271 {
2272 int idx_number = 2;
2273 char base_xpath[XPATH_MAXLEN];
2274 afi_t afi;
2275 safi_t safi;
2276
2277 afi = bgp_node_afi(vty);
2278 safi = bgp_node_safi(vty);
2279
2280 snprintf(
2281 base_xpath, sizeof(base_xpath),
2282 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/maximum-paths",
2283 yang_afi_safi_value2identity(afi, safi),
2284 bgp_afi_safi_get_container_str(afi, safi));
2285
2286 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY,
2287 argv[idx_number]->arg);
2288
2289 snprintf(
2290 base_xpath, sizeof(base_xpath),
2291 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/cluster-length-list",
2292 yang_afi_safi_value2identity(afi, safi),
2293 bgp_afi_safi_get_container_str(afi, safi));
2294
2295 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, "true");
2296
2297 return nb_cli_apply_changes(vty, NULL);
2298 }
2299
2300 void cli_show_bgp_global_afi_safi_ip_unicast_use_multiple_paths_ibgp_maximum_paths(
2301 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
2302 {
2303 vty_out(vty, " maximum-paths ibgp %d",
2304 yang_dnode_get_uint16(dnode, "./maximum-paths"));
2305 if (yang_dnode_get_bool(dnode, "./cluster-length-list"))
2306 vty_out(vty, " equal-cluster-length");
2307 vty_out(vty, "\n");
2308 }
2309
2310 ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
2311 "maximum-paths ibgp " CMD_RANGE_STR(
2312 1, MULTIPATH_NUM) " equal-cluster-length",
2313 "Forward packets over multiple paths\n"
2314 "iBGP-multipath\n"
2315 "Number of paths\n"
2316 "Match the cluster length\n")
2317
2318 DEFUN_YANG (no_bgp_maxpaths,
2319 no_bgp_maxpaths_cmd,
2320 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
2321 NO_STR
2322 "Forward packets over multiple paths\n"
2323 "Number of paths\n")
2324 {
2325 char base_xpath[XPATH_MAXLEN];
2326 afi_t afi;
2327 safi_t safi;
2328
2329 afi = bgp_node_afi(vty);
2330 safi = bgp_node_safi(vty);
2331
2332 snprintf(
2333 base_xpath, sizeof(base_xpath),
2334 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ebgp/maximum-paths",
2335 yang_afi_safi_value2identity(afi, safi),
2336 bgp_afi_safi_get_container_str(afi, safi));
2337
2338 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, NULL);
2339
2340 return nb_cli_apply_changes(vty, NULL);
2341 }
2342
2343 ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
2344 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
2345 "Forward packets over multiple paths\n"
2346 "Number of paths\n")
2347
2348 DEFUN_YANG (no_bgp_maxpaths_ibgp,
2349 no_bgp_maxpaths_ibgp_cmd,
2350 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
2351 NO_STR
2352 "Forward packets over multiple paths\n"
2353 "iBGP-multipath\n"
2354 "Number of paths\n"
2355 "Match the cluster length\n")
2356 {
2357 char base_xpath[XPATH_MAXLEN];
2358 afi_t afi;
2359 safi_t safi;
2360
2361 afi = bgp_node_afi(vty);
2362 safi = bgp_node_safi(vty);
2363
2364 snprintf(
2365 base_xpath, sizeof(base_xpath),
2366 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/maximum-paths",
2367 yang_afi_safi_value2identity(afi, safi),
2368 bgp_afi_safi_get_container_str(afi, safi));
2369
2370 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, NULL);
2371
2372 snprintf(
2373 base_xpath, sizeof(base_xpath),
2374 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/cluster-length-list",
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, "false");
2379
2380 return nb_cli_apply_changes(vty, NULL);
2381 }
2382
2383 ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
2384 "no maximum-paths ibgp [" CMD_RANGE_STR(
2385 1, MULTIPATH_NUM) " [equal-cluster-length]]",
2386 NO_STR
2387 "Forward packets over multiple paths\n"
2388 "iBGP-multipath\n"
2389 "Number of paths\n"
2390 "Match the cluster length\n")
2391
2392 static void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp,
2393 afi_t afi, safi_t safi)
2394 {
2395 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != multipath_num) {
2396 vty_out(vty, " maximum-paths %d\n",
2397 bgp->maxpaths[afi][safi].maxpaths_ebgp);
2398 }
2399
2400 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != multipath_num) {
2401 vty_out(vty, " maximum-paths ibgp %d",
2402 bgp->maxpaths[afi][safi].maxpaths_ibgp);
2403 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
2404 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
2405 vty_out(vty, " equal-cluster-length");
2406 vty_out(vty, "\n");
2407 }
2408 }
2409
2410 /* BGP timers. */
2411
2412 DEFUN_YANG (bgp_timers,
2413 bgp_timers_cmd,
2414 "timers bgp (0-65535) (0-65535)",
2415 "Adjust routing timers\n"
2416 "BGP timers\n"
2417 "Keepalive interval\n"
2418 "Holdtime\n")
2419 {
2420 int idx_number = 2;
2421 int idx_number_2 = 3;
2422
2423 nb_cli_enqueue_change(vty, "./global/global-config-timers/keepalive",
2424 NB_OP_MODIFY, argv[idx_number]->arg);
2425 nb_cli_enqueue_change(vty, "./global/global-config-timers/hold-time",
2426 NB_OP_MODIFY, argv[idx_number_2]->arg);
2427
2428 return nb_cli_apply_changes(vty, NULL);
2429 }
2430
2431 DEFUN_YANG (no_bgp_timers,
2432 no_bgp_timers_cmd,
2433 "no timers bgp [(0-65535) (0-65535)]",
2434 NO_STR
2435 "Adjust routing timers\n"
2436 "BGP timers\n"
2437 "Keepalive interval\n"
2438 "Holdtime\n")
2439 {
2440 nb_cli_enqueue_change(vty, "./global/global-config-timers/keepalive",
2441 NB_OP_DESTROY, NULL);
2442 nb_cli_enqueue_change(vty, "./global/global-config-timers/hold-time",
2443 NB_OP_DESTROY, NULL);
2444
2445 return nb_cli_apply_changes(vty, NULL);
2446 }
2447
2448 void cli_show_router_bgp_route_reflector(struct vty *vty,
2449 struct lyd_node *dnode,
2450 bool show_defaults)
2451 {
2452 if (yang_dnode_get_bool(dnode, "./no-client-reflect"))
2453 vty_out(vty, " no bgp client-to-client reflection\n");
2454
2455 if (yang_dnode_get_bool(dnode, "./allow-outbound-policy"))
2456 vty_out(vty, " bgp route-reflector allow-outbound-policy\n");
2457
2458 if (yang_dnode_exists(dnode, "./route-reflector-cluster-id"))
2459 vty_out(vty, " bgp cluster-id %s\n",
2460 yang_dnode_get_string(dnode,
2461 "./route-reflector-cluster-id"));
2462 }
2463
2464 DEFUN_YANG(bgp_client_to_client_reflection,
2465 bgp_client_to_client_reflection_cmd,
2466 "bgp client-to-client reflection",
2467 "BGP specific commands\n"
2468 "Configure client to client route reflection\n"
2469 "reflection of routes allowed\n")
2470 {
2471 nb_cli_enqueue_change(vty, "./global/route-reflector/no-client-reflect",
2472 NB_OP_MODIFY, "false");
2473
2474 return nb_cli_apply_changes(vty, NULL);
2475 }
2476
2477 DEFUN_YANG(no_bgp_client_to_client_reflection,
2478 no_bgp_client_to_client_reflection_cmd,
2479 "no bgp client-to-client reflection",
2480 NO_STR
2481 "BGP specific commands\n"
2482 "Configure client to client route reflection\n"
2483 "reflection of routes allowed\n")
2484 {
2485 nb_cli_enqueue_change(vty, "./global/route-reflector/no-client-reflect",
2486 NB_OP_MODIFY, "true");
2487
2488 return nb_cli_apply_changes(vty, NULL);
2489 }
2490
2491 void cli_show_router_bgp_route_selection(struct vty *vty,
2492 struct lyd_node *dnode,
2493 bool show_defaults)
2494 {
2495
2496 if (yang_dnode_get_bool(dnode, "./always-compare-med"))
2497 vty_out(vty, " bgp always-compare-med\n");
2498
2499 if (yang_dnode_get_bool(dnode, "./ignore-as-path-length"))
2500 vty_out(vty, " bgp bestpath as-path ignore\n");
2501
2502 if (yang_dnode_get_bool(dnode, "./aspath-confed"))
2503 vty_out(vty, " bgp bestpath as-path confed\n");
2504
2505 if (yang_dnode_get_bool(dnode, "./external-compare-router-id"))
2506 vty_out(vty, " bgp bestpath compare-routerid\n");
2507
2508 if (yang_dnode_get_bool(dnode, "./allow-multiple-as")) {
2509 if (yang_dnode_get_bool(dnode, "./multi-path-as-set"))
2510 vty_out(vty,
2511 " bgp bestpath as-path multipath-relax as-set\n");
2512 else
2513 vty_out(vty, " bgp bestpath as-path multipath-relax\n");
2514 }
2515
2516 if (yang_dnode_get_bool(dnode, "./deterministic-med"))
2517 vty_out(vty, " bgp deterministic-med\n");
2518
2519 if (yang_dnode_get_bool(dnode, "./confed-med")
2520 || yang_dnode_get_bool(dnode, "./missing-as-worst-med")) {
2521 vty_out(vty, " bgp bestpath med");
2522 if (yang_dnode_get_bool(dnode, "./confed-med"))
2523 vty_out(vty, " confed");
2524 if (yang_dnode_get_bool(dnode, "./missing-as-worst-med"))
2525 vty_out(vty, " missing-as-worst");
2526 vty_out(vty, "\n");
2527 }
2528 }
2529
2530 /* "bgp always-compare-med" configuration. */
2531 DEFUN_YANG(bgp_always_compare_med,
2532 bgp_always_compare_med_cmd,
2533 "bgp always-compare-med",
2534 "BGP specific commands\n"
2535 "Allow comparing MED from different neighbors\n")
2536 {
2537 nb_cli_enqueue_change(
2538 vty, "./global/route-selection-options/always-compare-med",
2539 NB_OP_MODIFY, "true");
2540
2541 return nb_cli_apply_changes(vty, NULL);
2542 }
2543
2544 DEFUN_YANG(no_bgp_always_compare_med,
2545 no_bgp_always_compare_med_cmd,
2546 "no bgp always-compare-med",
2547 NO_STR
2548 "BGP specific commands\n"
2549 "Allow comparing MED from different neighbors\n")
2550 {
2551 nb_cli_enqueue_change(
2552 vty, "./global/route-selection-options/always-compare-med",
2553 NB_OP_MODIFY, "false");
2554
2555 return nb_cli_apply_changes(vty, NULL);
2556 }
2557
2558 DEFUN_YANG(bgp_ebgp_requires_policy,
2559 bgp_ebgp_requires_policy_cmd,
2560 "bgp ebgp-requires-policy",
2561 "BGP specific commands\n"
2562 "Require in and out policy for eBGP peers (RFC8212)\n")
2563 {
2564 nb_cli_enqueue_change(vty, "./global/ebgp-requires-policy",
2565 NB_OP_MODIFY, "true");
2566 return nb_cli_apply_changes(vty, NULL);
2567 }
2568
2569 DEFUN_YANG(no_bgp_ebgp_requires_policy,
2570 no_bgp_ebgp_requires_policy_cmd,
2571 "no bgp ebgp-requires-policy",
2572 NO_STR
2573 "BGP specific commands\n"
2574 "Require in and out policy for eBGP peers (RFC8212)\n")
2575 {
2576 nb_cli_enqueue_change(vty, "./global/ebgp-requires-policy",
2577 NB_OP_MODIFY, "false");
2578 return nb_cli_apply_changes(vty, NULL);
2579 }
2580
2581 void cli_show_router_bgp_ebgp_requires_policy(struct vty *vty,
2582 struct lyd_node *dnode,
2583 bool show_defaults)
2584 {
2585 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_EBGP_REQUIRES_POLICY)
2586 vty_out(vty, " bgp ebgp-requires-policy\n");
2587 }
2588
2589 DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd,
2590 "bgp reject-as-sets",
2591 "BGP specific commands\n"
2592 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2593 {
2594 VTY_DECLVAR_CONTEXT(bgp, bgp);
2595 struct listnode *node, *nnode;
2596 struct peer *peer;
2597
2598 bgp->reject_as_sets = true;
2599
2600 /* Reset existing BGP sessions to reject routes
2601 * with aspath containing AS_SET or AS_CONFED_SET.
2602 */
2603 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2604 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2605 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2606 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2607 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2608 }
2609 }
2610
2611 return CMD_SUCCESS;
2612 }
2613
2614 DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd,
2615 "no bgp reject-as-sets",
2616 NO_STR
2617 "BGP specific commands\n"
2618 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2619 {
2620 VTY_DECLVAR_CONTEXT(bgp, bgp);
2621 struct listnode *node, *nnode;
2622 struct peer *peer;
2623
2624 bgp->reject_as_sets = false;
2625
2626 /* Reset existing BGP sessions to reject routes
2627 * with aspath containing AS_SET or AS_CONFED_SET.
2628 */
2629 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2630 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2631 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2632 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2633 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2634 }
2635 }
2636
2637 return CMD_SUCCESS;
2638 }
2639
2640 /* "bgp deterministic-med" configuration. */
2641 DEFUN_YANG (bgp_deterministic_med,
2642 bgp_deterministic_med_cmd,
2643 "bgp deterministic-med",
2644 "BGP specific commands\n"
2645 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2646 {
2647 nb_cli_enqueue_change(
2648 vty, "./global/route-selection-options/deterministic-med",
2649 NB_OP_MODIFY, "true");
2650
2651 return nb_cli_apply_changes(vty, NULL);
2652 }
2653
2654 DEFUN_YANG (no_bgp_deterministic_med,
2655 no_bgp_deterministic_med_cmd,
2656 "no bgp deterministic-med",
2657 NO_STR
2658 "BGP specific commands\n"
2659 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2660 {
2661 nb_cli_enqueue_change(
2662 vty, "./global/route-selection-options/deterministic-med",
2663 NB_OP_MODIFY, "false");
2664
2665 return nb_cli_apply_changes(vty, NULL);
2666 }
2667
2668 /* "bgp graceful-restart mode" configuration. */
2669 DEFUN (bgp_graceful_restart,
2670 bgp_graceful_restart_cmd,
2671 "bgp graceful-restart",
2672 "BGP specific commands\n"
2673 GR_CMD
2674 )
2675 {
2676 int ret = BGP_GR_FAILURE;
2677
2678 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2679 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : START ");
2680
2681 VTY_DECLVAR_CONTEXT(bgp, bgp);
2682
2683 ret = bgp_gr_update_all(bgp, GLOBAL_GR_CMD);
2684
2685 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2686 ret);
2687
2688 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2689 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : END ");
2690 vty_out(vty,
2691 "Graceful restart configuration changed, reset all peers to take effect\n");
2692 return bgp_vty_return(vty, ret);
2693 }
2694
2695 DEFUN (no_bgp_graceful_restart,
2696 no_bgp_graceful_restart_cmd,
2697 "no bgp graceful-restart",
2698 NO_STR
2699 "BGP specific commands\n"
2700 NO_GR_CMD
2701 )
2702 {
2703 VTY_DECLVAR_CONTEXT(bgp, bgp);
2704
2705 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2706 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : START ");
2707
2708 int ret = BGP_GR_FAILURE;
2709
2710 ret = bgp_gr_update_all(bgp, NO_GLOBAL_GR_CMD);
2711
2712 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2713 ret);
2714
2715 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2716 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : END ");
2717 vty_out(vty,
2718 "Graceful restart configuration changed, reset all peers to take effect\n");
2719
2720 return bgp_vty_return(vty, ret);
2721 }
2722
2723 DEFUN (bgp_graceful_restart_stalepath_time,
2724 bgp_graceful_restart_stalepath_time_cmd,
2725 "bgp graceful-restart stalepath-time (1-4095)",
2726 "BGP specific commands\n"
2727 "Graceful restart capability parameters\n"
2728 "Set the max time to hold onto restarting peer's stale paths\n"
2729 "Delay value (seconds)\n")
2730 {
2731 VTY_DECLVAR_CONTEXT(bgp, bgp);
2732 int idx_number = 3;
2733 uint32_t stalepath;
2734
2735 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2736 bgp->stalepath_time = stalepath;
2737 return CMD_SUCCESS;
2738 }
2739
2740 DEFUN (bgp_graceful_restart_restart_time,
2741 bgp_graceful_restart_restart_time_cmd,
2742 "bgp graceful-restart restart-time (1-4095)",
2743 "BGP specific commands\n"
2744 "Graceful restart capability parameters\n"
2745 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2746 "Delay value (seconds)\n")
2747 {
2748 VTY_DECLVAR_CONTEXT(bgp, bgp);
2749 int idx_number = 3;
2750 uint32_t restart;
2751
2752 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2753 bgp->restart_time = restart;
2754 return CMD_SUCCESS;
2755 }
2756
2757 DEFUN (bgp_graceful_restart_select_defer_time,
2758 bgp_graceful_restart_select_defer_time_cmd,
2759 "bgp graceful-restart select-defer-time (0-3600)",
2760 "BGP specific commands\n"
2761 "Graceful restart capability parameters\n"
2762 "Set the time to defer the BGP route selection after restart\n"
2763 "Delay value (seconds, 0 - disable)\n")
2764 {
2765 VTY_DECLVAR_CONTEXT(bgp, bgp);
2766 int idx_number = 3;
2767 uint32_t defer_time;
2768
2769 defer_time = strtoul(argv[idx_number]->arg, NULL, 10);
2770 bgp->select_defer_time = defer_time;
2771 if (defer_time == 0)
2772 SET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2773 else
2774 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2775
2776 return CMD_SUCCESS;
2777 }
2778
2779 DEFUN (no_bgp_graceful_restart_stalepath_time,
2780 no_bgp_graceful_restart_stalepath_time_cmd,
2781 "no bgp graceful-restart stalepath-time [(1-4095)]",
2782 NO_STR
2783 "BGP specific commands\n"
2784 "Graceful restart capability parameters\n"
2785 "Set the max time to hold onto restarting peer's stale paths\n"
2786 "Delay value (seconds)\n")
2787 {
2788 VTY_DECLVAR_CONTEXT(bgp, bgp);
2789
2790 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2791 return CMD_SUCCESS;
2792 }
2793
2794 DEFUN (no_bgp_graceful_restart_restart_time,
2795 no_bgp_graceful_restart_restart_time_cmd,
2796 "no bgp graceful-restart restart-time [(1-4095)]",
2797 NO_STR
2798 "BGP specific commands\n"
2799 "Graceful restart capability parameters\n"
2800 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2801 "Delay value (seconds)\n")
2802 {
2803 VTY_DECLVAR_CONTEXT(bgp, bgp);
2804
2805 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2806 return CMD_SUCCESS;
2807 }
2808
2809 DEFUN (no_bgp_graceful_restart_select_defer_time,
2810 no_bgp_graceful_restart_select_defer_time_cmd,
2811 "no bgp graceful-restart select-defer-time [(0-3600)]",
2812 NO_STR
2813 "BGP specific commands\n"
2814 "Graceful restart capability parameters\n"
2815 "Set the time to defer the BGP route selection after restart\n"
2816 "Delay value (seconds)\n")
2817 {
2818 VTY_DECLVAR_CONTEXT(bgp, bgp);
2819
2820 bgp->select_defer_time = BGP_DEFAULT_SELECT_DEFERRAL_TIME;
2821 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2822
2823 return CMD_SUCCESS;
2824 }
2825
2826 DEFUN (bgp_graceful_restart_preserve_fw,
2827 bgp_graceful_restart_preserve_fw_cmd,
2828 "bgp graceful-restart preserve-fw-state",
2829 "BGP specific commands\n"
2830 "Graceful restart capability parameters\n"
2831 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
2832 {
2833 VTY_DECLVAR_CONTEXT(bgp, bgp);
2834 SET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
2835 return CMD_SUCCESS;
2836 }
2837
2838 DEFUN (no_bgp_graceful_restart_preserve_fw,
2839 no_bgp_graceful_restart_preserve_fw_cmd,
2840 "no bgp graceful-restart preserve-fw-state",
2841 NO_STR
2842 "BGP specific commands\n"
2843 "Graceful restart capability parameters\n"
2844 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
2845 {
2846 VTY_DECLVAR_CONTEXT(bgp, bgp);
2847 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
2848 return CMD_SUCCESS;
2849 }
2850
2851 DEFUN (bgp_graceful_restart_disable,
2852 bgp_graceful_restart_disable_cmd,
2853 "bgp graceful-restart-disable",
2854 "BGP specific commands\n"
2855 GR_DISABLE)
2856 {
2857 int ret = BGP_GR_FAILURE;
2858
2859 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2860 zlog_debug(
2861 "[BGP_GR] bgp_graceful_restart_disable_cmd : START ");
2862
2863 VTY_DECLVAR_CONTEXT(bgp, bgp);
2864
2865 ret = bgp_gr_update_all(bgp, GLOBAL_DISABLE_CMD);
2866
2867 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
2868 bgp->peer, ret);
2869
2870 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2871 zlog_debug(
2872 "[BGP_GR] bgp_graceful_restart_disable_cmd : END ");
2873 vty_out(vty,
2874 "Graceful restart configuration changed, reset all peers to take effect\n");
2875
2876 return bgp_vty_return(vty, ret);
2877 }
2878
2879 DEFUN (no_bgp_graceful_restart_disable,
2880 no_bgp_graceful_restart_disable_cmd,
2881 "no bgp graceful-restart-disable",
2882 NO_STR
2883 "BGP specific commands\n"
2884 NO_GR_DISABLE
2885 )
2886 {
2887 VTY_DECLVAR_CONTEXT(bgp, bgp);
2888
2889 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2890 zlog_debug(
2891 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : START ");
2892
2893 int ret = BGP_GR_FAILURE;
2894
2895 ret = bgp_gr_update_all(bgp, NO_GLOBAL_DISABLE_CMD);
2896
2897 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2898 ret);
2899
2900 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2901 zlog_debug(
2902 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : END ");
2903 vty_out(vty,
2904 "Graceful restart configuration changed, reset all peers to take effect\n");
2905
2906 return bgp_vty_return(vty, ret);
2907 }
2908
2909 DEFUN (bgp_neighbor_graceful_restart_set,
2910 bgp_neighbor_graceful_restart_set_cmd,
2911 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
2912 NEIGHBOR_STR
2913 NEIGHBOR_ADDR_STR2
2914 GR_NEIGHBOR_CMD
2915 )
2916 {
2917 int idx_peer = 1;
2918 struct peer *peer;
2919 int ret = BGP_GR_FAILURE;
2920
2921 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2922
2923 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2924 zlog_debug(
2925 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : START ");
2926
2927 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2928 if (!peer)
2929 return CMD_WARNING_CONFIG_FAILED;
2930
2931 ret = bgp_neighbor_graceful_restart(peer, PEER_GR_CMD);
2932
2933 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2934 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
2935
2936 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2937 zlog_debug(
2938 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : END ");
2939 vty_out(vty,
2940 "Graceful restart configuration changed, reset this peer to take effect\n");
2941
2942 return bgp_vty_return(vty, ret);
2943 }
2944
2945 DEFUN (no_bgp_neighbor_graceful_restart,
2946 no_bgp_neighbor_graceful_restart_set_cmd,
2947 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
2948 NO_STR
2949 NEIGHBOR_STR
2950 NEIGHBOR_ADDR_STR2
2951 NO_GR_NEIGHBOR_CMD
2952 )
2953 {
2954 int idx_peer = 2;
2955 int ret = BGP_GR_FAILURE;
2956 struct peer *peer;
2957
2958 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2959
2960 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2961 if (!peer)
2962 return CMD_WARNING_CONFIG_FAILED;
2963
2964 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2965 zlog_debug(
2966 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : START ");
2967
2968 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_GR_CMD);
2969
2970 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2971 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
2972
2973 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2974 zlog_debug(
2975 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : END ");
2976 vty_out(vty,
2977 "Graceful restart configuration changed, reset this peer to take effect\n");
2978
2979 return bgp_vty_return(vty, ret);
2980 }
2981
2982 DEFUN (bgp_neighbor_graceful_restart_helper_set,
2983 bgp_neighbor_graceful_restart_helper_set_cmd,
2984 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
2985 NEIGHBOR_STR
2986 NEIGHBOR_ADDR_STR2
2987 GR_NEIGHBOR_HELPER_CMD
2988 )
2989 {
2990 int idx_peer = 1;
2991 struct peer *peer;
2992 int ret = BGP_GR_FAILURE;
2993
2994 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2995
2996 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2997 zlog_debug(
2998 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : START ");
2999
3000 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3001
3002 if (!peer)
3003 return CMD_WARNING_CONFIG_FAILED;
3004
3005
3006 ret = bgp_neighbor_graceful_restart(peer, PEER_HELPER_CMD);
3007
3008 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3009 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3010
3011 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3012 zlog_debug(
3013 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : END ");
3014 vty_out(vty,
3015 "Graceful restart configuration changed, reset this peer to take effect\n");
3016
3017 return bgp_vty_return(vty, ret);
3018 }
3019
3020 DEFUN (no_bgp_neighbor_graceful_restart_helper,
3021 no_bgp_neighbor_graceful_restart_helper_set_cmd,
3022 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3023 NO_STR
3024 NEIGHBOR_STR
3025 NEIGHBOR_ADDR_STR2
3026 NO_GR_NEIGHBOR_HELPER_CMD
3027 )
3028 {
3029 int idx_peer = 2;
3030 int ret = BGP_GR_FAILURE;
3031 struct peer *peer;
3032
3033 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3034
3035 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3036 if (!peer)
3037 return CMD_WARNING_CONFIG_FAILED;
3038
3039 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3040 zlog_debug(
3041 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : START ");
3042
3043 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_HELPER_CMD);
3044
3045 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3046 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3047
3048 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3049 zlog_debug(
3050 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : END ");
3051 vty_out(vty,
3052 "Graceful restart configuration changed, reset this peer to take effect\n");
3053
3054 return bgp_vty_return(vty, ret);
3055 }
3056
3057 DEFUN (bgp_neighbor_graceful_restart_disable_set,
3058 bgp_neighbor_graceful_restart_disable_set_cmd,
3059 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3060 NEIGHBOR_STR
3061 NEIGHBOR_ADDR_STR2
3062 GR_NEIGHBOR_DISABLE_CMD
3063 )
3064 {
3065 int idx_peer = 1;
3066 struct peer *peer;
3067 int ret = BGP_GR_FAILURE;
3068
3069 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3070
3071 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3072 zlog_debug(
3073 "[BGP_GR] bgp_neighbor_graceful_restart_disable_set_cmd : START ");
3074
3075 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3076 if (!peer)
3077 return CMD_WARNING_CONFIG_FAILED;
3078
3079 ret = bgp_neighbor_graceful_restart(peer, PEER_DISABLE_CMD);
3080
3081 if (peer->bgp->t_startup)
3082 bgp_peer_gr_flags_update(peer);
3083
3084 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3085 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3086
3087 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3088 zlog_debug(
3089 "[BGP_GR]bgp_neighbor_graceful_restart_disable_set_cmd : END ");
3090 vty_out(vty,
3091 "Graceful restart configuration changed, reset this peer to take effect\n");
3092
3093 return bgp_vty_return(vty, ret);
3094 }
3095
3096 DEFUN (no_bgp_neighbor_graceful_restart_disable,
3097 no_bgp_neighbor_graceful_restart_disable_set_cmd,
3098 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3099 NO_STR
3100 NEIGHBOR_STR
3101 NEIGHBOR_ADDR_STR2
3102 NO_GR_NEIGHBOR_DISABLE_CMD
3103 )
3104 {
3105 int idx_peer = 2;
3106 int ret = BGP_GR_FAILURE;
3107 struct peer *peer;
3108
3109 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3110
3111 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3112 if (!peer)
3113 return CMD_WARNING_CONFIG_FAILED;
3114
3115 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3116 zlog_debug(
3117 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : START ");
3118
3119 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_DISABLE_CMD);
3120
3121 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3122 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3123
3124 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3125 zlog_debug(
3126 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : END ");
3127 vty_out(vty,
3128 "Graceful restart configuration changed, reset this peer to take effect\n");
3129
3130 return bgp_vty_return(vty, ret);
3131 }
3132
3133 DEFUN_HIDDEN (bgp_graceful_restart_disable_eor,
3134 bgp_graceful_restart_disable_eor_cmd,
3135 "bgp graceful-restart disable-eor",
3136 "BGP specific commands\n"
3137 "Graceful restart configuration parameters\n"
3138 "Disable EOR Check\n")
3139 {
3140 VTY_DECLVAR_CONTEXT(bgp, bgp);
3141 SET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
3142
3143 return CMD_SUCCESS;
3144 }
3145
3146 DEFUN_HIDDEN (no_bgp_graceful_restart_disable_eor,
3147 no_bgp_graceful_restart_disable_eor_cmd,
3148 "no bgp graceful-restart disable-eor",
3149 NO_STR
3150 "BGP specific commands\n"
3151 "Graceful restart configuration parameters\n"
3152 "Disable EOR Check\n")
3153 {
3154 VTY_DECLVAR_CONTEXT(bgp, bgp);
3155 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
3156
3157 return CMD_SUCCESS;
3158 }
3159
3160 DEFUN (bgp_graceful_restart_rib_stale_time,
3161 bgp_graceful_restart_rib_stale_time_cmd,
3162 "bgp graceful-restart rib-stale-time (1-3600)",
3163 "BGP specific commands\n"
3164 "Graceful restart configuration parameters\n"
3165 "Specify the stale route removal timer in rib\n"
3166 "Delay value (seconds)\n")
3167 {
3168 VTY_DECLVAR_CONTEXT(bgp, bgp);
3169 int idx_number = 3;
3170 uint32_t stale_time;
3171
3172 stale_time = strtoul(argv[idx_number]->arg, NULL, 10);
3173 bgp->rib_stale_time = stale_time;
3174 /* Send the stale timer update message to RIB */
3175 if (bgp_zebra_stale_timer_update(bgp))
3176 return CMD_WARNING;
3177
3178 return CMD_SUCCESS;
3179 }
3180
3181 DEFUN (no_bgp_graceful_restart_rib_stale_time,
3182 no_bgp_graceful_restart_rib_stale_time_cmd,
3183 "no bgp graceful-restart rib-stale-time [(1-3600)]",
3184 NO_STR
3185 "BGP specific commands\n"
3186 "Graceful restart configuration parameters\n"
3187 "Specify the stale route removal timer in rib\n"
3188 "Delay value (seconds)\n")
3189 {
3190 VTY_DECLVAR_CONTEXT(bgp, bgp);
3191
3192 bgp->rib_stale_time = BGP_DEFAULT_RIB_STALE_TIME;
3193 /* Send the stale timer update message to RIB */
3194 if (bgp_zebra_stale_timer_update(bgp))
3195 return CMD_WARNING;
3196
3197 return CMD_SUCCESS;
3198 }
3199
3200 static inline int bgp_initiate_graceful_shut_unshut(struct bgp *bgp,
3201 char *errmsg,
3202 size_t errmsg_len)
3203 {
3204 bgp_static_redo_import_check(bgp);
3205 bgp_redistribute_redo(bgp);
3206 if (bgp_clear_star_soft_out(bgp->name, errmsg, errmsg_len) < 0)
3207 return -1;
3208 if (bgp_clear_star_soft_in(bgp->name, errmsg, errmsg_len) < 0)
3209 return -1;
3210
3211 return 0;
3212 }
3213
3214 static int bgp_global_graceful_shutdown_config_vty(struct vty *vty)
3215 {
3216 struct listnode *node, *nnode;
3217 struct bgp *bgp;
3218 bool vrf_cfg = false;
3219 char errmsg[BUFSIZ] = {'\0'};
3220
3221 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3222 return CMD_SUCCESS;
3223
3224 /* See if graceful-shutdown is set per-vrf and warn user to delete */
3225 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3226 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3227 vty_out(vty,
3228 "%% graceful-shutdown configuration found in vrf %s\n",
3229 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT ?
3230 VRF_DEFAULT_NAME : bgp->name);
3231 vrf_cfg = true;
3232 }
3233 }
3234
3235 if (vrf_cfg) {
3236 vty_out(vty,
3237 "%%Failed: global graceful-shutdown not permitted\n");
3238 return CMD_WARNING;
3239 }
3240
3241 /* Set flag globally */
3242 SET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3243
3244 /* Initiate processing for all BGP instances. */
3245 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3246 if (bgp_initiate_graceful_shut_unshut(bgp, errmsg,
3247 sizeof(errmsg))
3248 < 0)
3249 if (strlen(errmsg))
3250 vty_out(vty, "%s\n", errmsg);
3251 }
3252
3253 return CMD_SUCCESS;
3254 }
3255
3256 static int bgp_global_graceful_shutdown_deconfig_vty(struct vty *vty)
3257 {
3258 struct listnode *node, *nnode;
3259 struct bgp *bgp;
3260 char errmsg[BUFSIZ] = {'\0'};
3261
3262 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3263 return CMD_SUCCESS;
3264
3265 /* Unset flag globally */
3266 UNSET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3267
3268 /* Initiate processing for all BGP instances. */
3269 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3270 if (bgp_initiate_graceful_shut_unshut(bgp, errmsg,
3271 sizeof(errmsg))
3272 < 0)
3273 if (strlen(errmsg))
3274 vty_out(vty, "%s\n", errmsg);
3275 }
3276
3277 return CMD_SUCCESS;
3278 }
3279
3280 /* "bgp graceful-shutdown" configuration */
3281 DEFUN (bgp_graceful_shutdown,
3282 bgp_graceful_shutdown_cmd,
3283 "bgp graceful-shutdown",
3284 BGP_STR
3285 "Graceful shutdown parameters\n")
3286 {
3287 if (vty->node == CONFIG_NODE)
3288 return bgp_global_graceful_shutdown_config_vty(vty);
3289
3290 nb_cli_enqueue_change(vty, "./global/graceful-shutdown/enable",
3291 NB_OP_MODIFY, "true");
3292
3293 return nb_cli_apply_changes(vty, NULL);
3294 }
3295
3296 DEFUN_YANG (no_bgp_graceful_shutdown,
3297 no_bgp_graceful_shutdown_cmd,
3298 "no bgp graceful-shutdown",
3299 NO_STR
3300 BGP_STR
3301 "Graceful shutdown parameters\n")
3302 {
3303 if (vty->node == CONFIG_NODE)
3304 return bgp_global_graceful_shutdown_deconfig_vty(vty);
3305
3306 nb_cli_enqueue_change(vty, "./global/graceful-shutdown/enable",
3307 NB_OP_MODIFY, "false");
3308
3309 return nb_cli_apply_changes(vty, NULL);
3310 }
3311
3312 void cli_show_router_bgp_graceful_shutdown(struct vty *vty,
3313 struct lyd_node *dnode,
3314 bool show_defaults)
3315 {
3316 if (yang_dnode_get_bool(dnode, NULL))
3317 vty_out(vty, " bgp graceful-shutdown\n");
3318 }
3319
3320 /* "bgp fast-external-failover" configuration. */
3321 DEFUN_YANG (bgp_fast_external_failover,
3322 bgp_fast_external_failover_cmd,
3323 "bgp fast-external-failover",
3324 BGP_STR
3325 "Immediately reset session if a link to a directly connected external peer goes down\n")
3326 {
3327 nb_cli_enqueue_change(vty, "./global/fast-external-failover",
3328 NB_OP_MODIFY, "false");
3329
3330 return nb_cli_apply_changes(vty, NULL);
3331 }
3332
3333 DEFUN_YANG (no_bgp_fast_external_failover,
3334 no_bgp_fast_external_failover_cmd,
3335 "no bgp fast-external-failover",
3336 NO_STR
3337 BGP_STR
3338 "Immediately reset session if a link to a directly connected external peer goes down\n")
3339 {
3340 nb_cli_enqueue_change(vty, "./global/fast-external-failover",
3341 NB_OP_MODIFY, "true");
3342
3343 return nb_cli_apply_changes(vty, NULL);
3344 }
3345
3346 void cli_show_router_bgp_fast_external_failover(struct vty *vty,
3347 struct lyd_node *dnode,
3348 bool show_defaults)
3349 {
3350 if (!yang_dnode_get_bool(dnode, NULL))
3351 vty_out(vty, " no bgp fast-external-failover\n");
3352 }
3353
3354 /* "bgp bestpath compare-routerid" configuration. */
3355 DEFUN_YANG(bgp_bestpath_compare_router_id,
3356 bgp_bestpath_compare_router_id_cmd,
3357 "bgp bestpath compare-routerid",
3358 "BGP specific commands\n"
3359 "Change the default bestpath selection\n"
3360 "Compare router-id for identical EBGP paths\n")
3361 {
3362 nb_cli_enqueue_change(
3363 vty,
3364 "./global/route-selection-options/external-compare-router-id",
3365 NB_OP_MODIFY, "true");
3366
3367 return nb_cli_apply_changes(vty, NULL);
3368 }
3369
3370 DEFUN_YANG(no_bgp_bestpath_compare_router_id,
3371 no_bgp_bestpath_compare_router_id_cmd,
3372 "no bgp bestpath compare-routerid",
3373 NO_STR
3374 "BGP specific commands\n"
3375 "Change the default bestpath selection\n"
3376 "Compare router-id for identical EBGP paths\n")
3377 {
3378 nb_cli_enqueue_change(
3379 vty,
3380 "./global/route-selection-options/external-compare-router-id",
3381 NB_OP_MODIFY, "false");
3382
3383 return nb_cli_apply_changes(vty, NULL);
3384 }
3385
3386 /* "bgp bestpath as-path ignore" configuration. */
3387 DEFUN_YANG(bgp_bestpath_aspath_ignore,
3388 bgp_bestpath_aspath_ignore_cmd,
3389 "bgp bestpath as-path ignore",
3390 "BGP specific commands\n"
3391 "Change the default bestpath selection\n"
3392 "AS-path attribute\n"
3393 "Ignore as-path length in selecting a route\n")
3394 {
3395 nb_cli_enqueue_change(
3396 vty, "./global/route-selection-options/ignore-as-path-length",
3397 NB_OP_MODIFY, "true");
3398
3399 return nb_cli_apply_changes(vty, NULL);
3400 }
3401
3402 DEFUN_YANG(no_bgp_bestpath_aspath_ignore,
3403 no_bgp_bestpath_aspath_ignore_cmd,
3404 "no bgp bestpath as-path ignore",
3405 NO_STR
3406 "BGP specific commands\n"
3407 "Change the default bestpath selection\n"
3408 "AS-path attribute\n"
3409 "Ignore as-path length in selecting a route\n")
3410 {
3411 nb_cli_enqueue_change(
3412 vty, "./global/route-selection-options/ignore-as-path-length",
3413 NB_OP_MODIFY, "false");
3414
3415 return nb_cli_apply_changes(vty, NULL);
3416 }
3417
3418 /* "bgp bestpath as-path confed" configuration. */
3419 DEFUN_YANG (bgp_bestpath_aspath_confed,
3420 bgp_bestpath_aspath_confed_cmd,
3421 "bgp bestpath as-path confed",
3422 "BGP specific commands\n"
3423 "Change the default bestpath selection\n"
3424 "AS-path attribute\n"
3425 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3426 {
3427 nb_cli_enqueue_change(vty,
3428 "./global/route-selection-options/aspath-confed",
3429 NB_OP_MODIFY, "true");
3430
3431 return nb_cli_apply_changes(vty, NULL);
3432 }
3433
3434 DEFUN_YANG (no_bgp_bestpath_aspath_confed,
3435 no_bgp_bestpath_aspath_confed_cmd,
3436 "no bgp bestpath as-path confed",
3437 NO_STR
3438 "BGP specific commands\n"
3439 "Change the default bestpath selection\n"
3440 "AS-path attribute\n"
3441 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3442 {
3443 nb_cli_enqueue_change(vty,
3444 "./global/route-selection-options/aspath-confed",
3445 NB_OP_MODIFY, "false");
3446
3447 return nb_cli_apply_changes(vty, NULL);
3448 }
3449
3450 /* "bgp bestpath as-path multipath-relax" configuration. */
3451 DEFUN_YANG (bgp_bestpath_aspath_multipath_relax,
3452 bgp_bestpath_aspath_multipath_relax_cmd,
3453 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
3454 "BGP specific commands\n"
3455 "Change the default bestpath selection\n"
3456 "AS-path attribute\n"
3457 "Allow load sharing across routes that have different AS paths (but same length)\n"
3458 "Generate an AS_SET\n"
3459 "Do not generate an AS_SET\n")
3460 {
3461 int idx = 0;
3462
3463 nb_cli_enqueue_change(
3464 vty, "./global/route-selection-options/allow-multiple-as",
3465 NB_OP_MODIFY, "true");
3466 if (argv_find(argv, argc, "as-set", &idx))
3467 nb_cli_enqueue_change(
3468 vty,
3469 "./global/route-selection-options/multi-path-as-set",
3470 NB_OP_MODIFY, "true");
3471 else
3472 nb_cli_enqueue_change(
3473 vty,
3474 "./global/route-selection-options/multi-path-as-set",
3475 NB_OP_MODIFY, "false");
3476
3477 return nb_cli_apply_changes(vty, NULL);
3478 }
3479
3480 DEFUN_YANG (no_bgp_bestpath_aspath_multipath_relax,
3481 no_bgp_bestpath_aspath_multipath_relax_cmd,
3482 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
3483 NO_STR
3484 "BGP specific commands\n"
3485 "Change the default bestpath selection\n"
3486 "AS-path attribute\n"
3487 "Allow load sharing across routes that have different AS paths (but same length)\n"
3488 "Generate an AS_SET\n"
3489 "Do not generate an AS_SET\n")
3490 {
3491 nb_cli_enqueue_change(
3492 vty, "./global/route-selection-options/allow-multiple-as",
3493 NB_OP_MODIFY, "false");
3494 nb_cli_enqueue_change(
3495 vty, "./global/route-selection-options/multi-path-as-set",
3496 NB_OP_MODIFY, "false");
3497
3498 return nb_cli_apply_changes(vty, NULL);
3499 }
3500
3501 /* "bgp log-neighbor-changes" configuration. */
3502 DEFUN_YANG(bgp_log_neighbor_changes,
3503 bgp_log_neighbor_changes_cmd,
3504 "bgp log-neighbor-changes",
3505 "BGP specific commands\n"
3506 "Log neighbor up/down and reset reason\n")
3507 {
3508 nb_cli_enqueue_change(
3509 vty, "./global/global-neighbor-config/log-neighbor-changes",
3510 NB_OP_MODIFY, "true");
3511
3512 return nb_cli_apply_changes(vty, NULL);
3513 }
3514
3515 DEFUN_YANG(no_bgp_log_neighbor_changes,
3516 no_bgp_log_neighbor_changes_cmd,
3517 "no bgp log-neighbor-changes",
3518 NO_STR
3519 "BGP specific commands\n"
3520 "Log neighbor up/down and reset reason\n")
3521 {
3522 nb_cli_enqueue_change(
3523 vty, "./global/global-neighbor-config/log-neighbor-changes",
3524 NB_OP_MODIFY, "false");
3525
3526 return nb_cli_apply_changes(vty, NULL);
3527 }
3528
3529 /* "bgp bestpath med" configuration. */
3530 DEFUN_YANG (bgp_bestpath_med,
3531 bgp_bestpath_med_cmd,
3532 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
3533 "BGP specific commands\n"
3534 "Change the default bestpath selection\n"
3535 "MED attribute\n"
3536 "Compare MED among confederation paths\n"
3537 "Treat missing MED as the least preferred one\n"
3538 "Treat missing MED as the least preferred one\n"
3539 "Compare MED among confederation paths\n")
3540 {
3541 int idx = 0;
3542 bool confed = false;
3543 bool worst_med = false;
3544
3545
3546 if (argv_find(argv, argc, "confed", &idx))
3547 confed = true;
3548
3549 nb_cli_enqueue_change(vty,
3550 "./global/route-selection-options/confed-med",
3551 NB_OP_MODIFY, confed ? "true" : "false");
3552
3553 idx = 0;
3554 if (argv_find(argv, argc, "missing-as-worst", &idx))
3555 worst_med = true;
3556
3557 nb_cli_enqueue_change(
3558 vty, "./global/route-selection-options/missing-as-worst-med",
3559 NB_OP_MODIFY, worst_med ? "true" : "false");
3560
3561 return nb_cli_apply_changes(vty, NULL);
3562 }
3563
3564 DEFUN_YANG (no_bgp_bestpath_med,
3565 no_bgp_bestpath_med_cmd,
3566 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
3567 NO_STR
3568 "BGP specific commands\n"
3569 "Change the default bestpath selection\n"
3570 "MED attribute\n"
3571 "Compare MED among confederation paths\n"
3572 "Treat missing MED as the least preferred one\n"
3573 "Treat missing MED as the least preferred one\n"
3574 "Compare MED among confederation paths\n")
3575 {
3576 int idx = 0;
3577
3578 if (argv_find(argv, argc, "confed", &idx))
3579 nb_cli_enqueue_change(
3580 vty, "./global/route-selection-options/confed-med",
3581 NB_OP_MODIFY, "false");
3582
3583 idx = 0;
3584 if (argv_find(argv, argc, "missing-as-worst", &idx))
3585 nb_cli_enqueue_change(
3586 vty,
3587 "./global/route-selection-options/missing-as-worst-med",
3588 NB_OP_MODIFY, "false");
3589
3590 return nb_cli_apply_changes(vty, NULL);
3591 }
3592
3593 /* "bgp bestpath bandwidth" configuration. */
3594 DEFPY (bgp_bestpath_bw,
3595 bgp_bestpath_bw_cmd,
3596 "bgp bestpath bandwidth <ignore|skip-missing|default-weight-for-missing>$bw_cfg",
3597 "BGP specific commands\n"
3598 "Change the default bestpath selection\n"
3599 "Link Bandwidth attribute\n"
3600 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3601 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3602 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3603 {
3604 VTY_DECLVAR_CONTEXT(bgp, bgp);
3605 afi_t afi;
3606 safi_t safi;
3607
3608 if (!bw_cfg) {
3609 vty_out(vty, "%% Bandwidth configuration must be specified\n");
3610 return CMD_ERR_INCOMPLETE;
3611 }
3612 if (!strcmp(bw_cfg, "ignore"))
3613 bgp->lb_handling = BGP_LINK_BW_IGNORE_BW;
3614 else if (!strcmp(bw_cfg, "skip-missing"))
3615 bgp->lb_handling = BGP_LINK_BW_SKIP_MISSING;
3616 else if (!strcmp(bw_cfg, "default-weight-for-missing"))
3617 bgp->lb_handling = BGP_LINK_BW_DEFWT_4_MISSING;
3618 else
3619 return CMD_ERR_NO_MATCH;
3620
3621 /* This config is used in route install, so redo that. */
3622 FOREACH_AFI_SAFI (afi, safi) {
3623 if (!bgp_fibupd_safi(safi))
3624 continue;
3625 bgp_zebra_announce_table(bgp, afi, safi);
3626 }
3627
3628 return CMD_SUCCESS;
3629 }
3630
3631 DEFPY (no_bgp_bestpath_bw,
3632 no_bgp_bestpath_bw_cmd,
3633 "no bgp bestpath bandwidth [<ignore|skip-missing|default-weight-for-missing>$bw_cfg]",
3634 NO_STR
3635 "BGP specific commands\n"
3636 "Change the default bestpath selection\n"
3637 "Link Bandwidth attribute\n"
3638 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3639 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3640 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3641 {
3642 VTY_DECLVAR_CONTEXT(bgp, bgp);
3643 afi_t afi;
3644 safi_t safi;
3645
3646 bgp->lb_handling = BGP_LINK_BW_ECMP;
3647
3648 /* This config is used in route install, so redo that. */
3649 FOREACH_AFI_SAFI (afi, safi) {
3650 if (!bgp_fibupd_safi(safi))
3651 continue;
3652 bgp_zebra_announce_table(bgp, afi, safi);
3653 }
3654 return CMD_SUCCESS;
3655 }
3656
3657 /* "no bgp default ipv4-unicast". */
3658 DEFUN (no_bgp_default_ipv4_unicast,
3659 no_bgp_default_ipv4_unicast_cmd,
3660 "no bgp default ipv4-unicast",
3661 NO_STR
3662 "BGP specific commands\n"
3663 "Configure BGP defaults\n"
3664 "Activate ipv4-unicast for a peer by default\n")
3665 {
3666 VTY_DECLVAR_CONTEXT(bgp, bgp);
3667 SET_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4);
3668 return CMD_SUCCESS;
3669 }
3670
3671 DEFUN (bgp_default_ipv4_unicast,
3672 bgp_default_ipv4_unicast_cmd,
3673 "bgp default ipv4-unicast",
3674 "BGP specific commands\n"
3675 "Configure BGP defaults\n"
3676 "Activate ipv4-unicast for a peer by default\n")
3677 {
3678 VTY_DECLVAR_CONTEXT(bgp, bgp);
3679 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4);
3680 return CMD_SUCCESS;
3681 }
3682
3683 /* Display hostname in certain command outputs */
3684 DEFUN_YANG (bgp_default_show_hostname,
3685 bgp_default_show_hostname_cmd,
3686 "bgp default show-hostname",
3687 "BGP specific commands\n"
3688 "Configure BGP defaults\n"
3689 "Show hostname in certain command outputs\n")
3690 {
3691 nb_cli_enqueue_change(vty, "./global/show-hostname", NB_OP_MODIFY,
3692 "true");
3693
3694 return nb_cli_apply_changes(vty, NULL);
3695 }
3696
3697 DEFUN_YANG(no_bgp_default_show_hostname,
3698 no_bgp_default_show_hostname_cmd,
3699 "no bgp default show-hostname",
3700 NO_STR
3701 "BGP specific commands\n"
3702 "Configure BGP defaults\n"
3703 "Show hostname in certain command outputs\n")
3704 {
3705 nb_cli_enqueue_change(vty, "./global/show-hostname", NB_OP_MODIFY,
3706 "false");
3707
3708 return nb_cli_apply_changes(vty, NULL);
3709 }
3710
3711 void cli_show_router_bgp_show_hostname(struct vty *vty, struct lyd_node *dnode,
3712 bool show_defaults)
3713 {
3714 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_SHOW_HOSTNAME)
3715 vty_out(vty, " bgp default show-hostname\n");
3716 }
3717
3718 /* Display hostname in certain command outputs */
3719 DEFUN_YANG(bgp_default_show_nexthop_hostname,
3720 bgp_default_show_nexthop_hostname_cmd,
3721 "bgp default show-nexthop-hostname",
3722 "BGP specific commands\n"
3723 "Configure BGP defaults\n"
3724 "Show hostname for nexthop in certain command outputs\n")
3725 {
3726 nb_cli_enqueue_change(vty, "./global/show-nexthop-hostname",
3727 NB_OP_MODIFY, "true");
3728
3729 return nb_cli_apply_changes(vty, NULL);
3730 }
3731
3732 DEFUN (no_bgp_default_show_nexthop_hostname,
3733 no_bgp_default_show_nexthop_hostname_cmd,
3734 "no bgp default show-nexthop-hostname",
3735 NO_STR
3736 "BGP specific commands\n"
3737 "Configure BGP defaults\n"
3738 "Show hostname for nexthop in certain command outputs\n")
3739 {
3740 nb_cli_enqueue_change(vty, "./global/show-nexthop-hostname",
3741 NB_OP_MODIFY, "false");
3742
3743 return nb_cli_apply_changes(vty, NULL);
3744 }
3745
3746 void cli_show_router_bgp_show_nexthop_hostname(struct vty *vty,
3747 struct lyd_node *dnode,
3748 bool show_defaults)
3749 {
3750 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_SHOW_HOSTNAME)
3751 vty_out(vty, " bgp default show-nexthop-hostname\n");
3752 }
3753
3754 /* "bgp network import-check" configuration. */
3755 DEFUN_YANG(bgp_network_import_check,
3756 bgp_network_import_check_cmd,
3757 "bgp network import-check",
3758 "BGP specific commands\n"
3759 "BGP network command\n"
3760 "Check BGP network route exists in IGP\n")
3761 {
3762 nb_cli_enqueue_change(vty, "./global/import-check", NB_OP_MODIFY,
3763 "true");
3764
3765 return nb_cli_apply_changes(vty, NULL);
3766 }
3767
3768 ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
3769 "bgp network import-check exact",
3770 "BGP specific commands\n"
3771 "BGP network command\n"
3772 "Check BGP network route exists in IGP\n"
3773 "Match route precisely\n")
3774
3775 DEFUN_YANG(no_bgp_network_import_check,
3776 no_bgp_network_import_check_cmd,
3777 "no bgp network import-check",
3778 NO_STR
3779 "BGP specific commands\n"
3780 "BGP network command\n"
3781 "Check BGP network route exists in IGP\n")
3782 {
3783 nb_cli_enqueue_change(vty, "./global/import-check", NB_OP_MODIFY,
3784 "false");
3785
3786 return nb_cli_apply_changes(vty, NULL);
3787 }
3788
3789 void cli_show_router_bgp_import_check(struct vty *vty, struct lyd_node *dnode,
3790 bool show_defaults)
3791 {
3792 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_IMPORT_CHECK)
3793 vty_out(vty, " bgp network import-check\n");
3794 }
3795
3796 DEFUN_YANG(bgp_default_local_preference,
3797 bgp_default_local_preference_cmd,
3798 "bgp default local-preference (0-4294967295)",
3799 "BGP specific commands\n"
3800 "Configure BGP defaults\n"
3801 "local preference (higher=more preferred)\n"
3802 "Configure default local preference value\n")
3803 {
3804 int idx_number = 3;
3805
3806 nb_cli_enqueue_change(vty, "./global/local-pref", NB_OP_MODIFY,
3807 argv[idx_number]->arg);
3808
3809 return nb_cli_apply_changes(vty, NULL);
3810 }
3811
3812 DEFUN_YANG(no_bgp_default_local_preference,
3813 no_bgp_default_local_preference_cmd,
3814 "no bgp default local-preference [(0-4294967295)]",
3815 NO_STR
3816 "BGP specific commands\n"
3817 "Configure BGP defaults\n"
3818 "local preference (higher=more preferred)\n"
3819 "Configure default local preference value\n")
3820 {
3821 nb_cli_enqueue_change(vty, "./global/local-pref", NB_OP_MODIFY, NULL);
3822
3823 return nb_cli_apply_changes(vty, NULL);
3824 }
3825
3826 void cli_show_router_bgp_local_pref(struct vty *vty, struct lyd_node *dnode,
3827 bool show_defaults)
3828 {
3829 vty_out(vty, " bgp default local-preference %u\n",
3830 yang_dnode_get_uint32(dnode, NULL));
3831 }
3832
3833
3834 DEFUN_YANG(bgp_default_subgroup_pkt_queue_max,
3835 bgp_default_subgroup_pkt_queue_max_cmd,
3836 "bgp default subgroup-pkt-queue-max (20-100)",
3837 "BGP specific commands\n"
3838 "Configure BGP defaults\n"
3839 "subgroup-pkt-queue-max\n"
3840 "Configure subgroup packet queue max\n")
3841 {
3842 int idx_number = 3;
3843
3844 nb_cli_enqueue_change(
3845 vty,
3846 "./global/global-update-group-config/subgroup-pkt-queue-size",
3847 NB_OP_MODIFY, argv[idx_number]->arg);
3848
3849 return nb_cli_apply_changes(vty, NULL);
3850 }
3851
3852 DEFUN_YANG(no_bgp_default_subgroup_pkt_queue_max,
3853 no_bgp_default_subgroup_pkt_queue_max_cmd,
3854 "no bgp default subgroup-pkt-queue-max [(20-100)]",
3855 NO_STR
3856 "BGP specific commands\n"
3857 "Configure BGP defaults\n"
3858 "subgroup-pkt-queue-max\n"
3859 "Configure subgroup packet queue max\n")
3860 {
3861 nb_cli_enqueue_change(
3862 vty,
3863 "./global/global-update-group-config/subgroup-pkt-queue-size",
3864 NB_OP_MODIFY, NULL);
3865
3866 return nb_cli_apply_changes(vty, NULL);
3867 }
3868
3869 void cli_show_router_global_update_group_config_subgroup_pkt_queue_size(
3870 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
3871 {
3872 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
3873 yang_dnode_get_uint32(dnode, NULL));
3874 }
3875
3876 DEFUN_YANG(bgp_rr_allow_outbound_policy,
3877 bgp_rr_allow_outbound_policy_cmd,
3878 "bgp route-reflector allow-outbound-policy",
3879 "BGP specific commands\n"
3880 "Allow modifications made by out route-map\n"
3881 "on ibgp neighbors\n")
3882 {
3883 nb_cli_enqueue_change(vty,
3884 "./global/route-reflector/allow-outbound-policy",
3885 NB_OP_MODIFY, "true");
3886
3887 return nb_cli_apply_changes(vty, NULL);
3888 }
3889
3890 DEFUN_YANG(no_bgp_rr_allow_outbound_policy,
3891 no_bgp_rr_allow_outbound_policy_cmd,
3892 "no bgp route-reflector allow-outbound-policy",
3893 NO_STR
3894 "BGP specific commands\n"
3895 "Allow modifications made by out route-map\n"
3896 "on ibgp neighbors\n")
3897 {
3898 nb_cli_enqueue_change(vty,
3899 "./global/route-reflector/allow-outbound-policy",
3900 NB_OP_MODIFY, "false");
3901
3902 return nb_cli_apply_changes(vty, NULL);
3903 }
3904
3905
3906 void cli_show_router_global_neighbor_config(struct vty *vty,
3907 struct lyd_node *dnode,
3908 bool show_defaults)
3909 {
3910 uint32_t write_quanta, read_quanta;
3911
3912 if (yang_dnode_get_bool(dnode, "./log-neighbor-changes"))
3913 vty_out(vty, " bgp log-neighbor-changes\n");
3914
3915 if (yang_dnode_exists(dnode, "./dynamic-neighbors-limit")) {
3916 uint32_t listen_limit = yang_dnode_get_uint32(
3917 dnode, "./dynamic-neighbors-limit");
3918 vty_out(vty, " bgp listen limit %u\n", listen_limit);
3919 }
3920
3921 write_quanta = yang_dnode_get_uint32(
3922 dnode, "./packet-quanta-config/wpkt-quanta");
3923 if (write_quanta != BGP_WRITE_PACKET_MAX)
3924 vty_out(vty, " write-quanta %d\n", write_quanta);
3925
3926 read_quanta = yang_dnode_get_uint32(
3927 dnode, "./packet-quanta-config/rpkt-quanta");
3928
3929 if (read_quanta != BGP_READ_PACKET_MAX)
3930 vty_out(vty, " read-quanta %d\n", read_quanta);
3931 }
3932
3933 DEFUN_YANG(bgp_listen_limit,
3934 bgp_listen_limit_cmd,
3935 "bgp listen limit (1-5000)",
3936 "BGP specific commands\n"
3937 "BGP Dynamic Neighbors listen commands\n"
3938 "Maximum number of BGP Dynamic Neighbors that can be created\n"
3939 "Configure Dynamic Neighbors listen limit value\n")
3940 {
3941 int idx_number = 3;
3942
3943 nb_cli_enqueue_change(
3944 vty, "./global/global-neighbor-config/dynamic-neighbors-limit",
3945 NB_OP_MODIFY, argv[idx_number]->arg);
3946
3947 return nb_cli_apply_changes(vty, NULL);
3948 }
3949
3950 DEFUN_YANG(no_bgp_listen_limit,
3951 no_bgp_listen_limit_cmd,
3952 "no bgp listen limit [(1-5000)]",
3953 NO_STR
3954 "BGP specific commands\n"
3955 "BGP Dynamic Neighbors listen commands\n"
3956 "Maximum number of BGP Dynamic Neighbors that can be created\n"
3957 "Configure Dynamic Neighbors listen limit value\n")
3958 {
3959 nb_cli_enqueue_change(
3960 vty, "./global/global-neighbor-config/dynamic-neighbors-limit",
3961 NB_OP_DESTROY, NULL);
3962
3963 return nb_cli_apply_changes(vty, NULL);
3964 }
3965
3966
3967 /*
3968 * Check if this listen range is already configured. Check for exact
3969 * match or overlap based on input.
3970 */
3971 static struct peer_group *listen_range_exists(struct bgp *bgp,
3972 struct prefix *range, int exact)
3973 {
3974 struct listnode *node, *nnode;
3975 struct listnode *node1, *nnode1;
3976 struct peer_group *group;
3977 struct prefix *lr;
3978 afi_t afi;
3979 int match;
3980
3981 afi = family2afi(range->family);
3982 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
3983 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
3984 lr)) {
3985 if (exact)
3986 match = prefix_same(range, lr);
3987 else
3988 match = (prefix_match(range, lr)
3989 || prefix_match(lr, range));
3990 if (match)
3991 return group;
3992 }
3993 }
3994
3995 return NULL;
3996 }
3997
3998 DEFUN (bgp_listen_range,
3999 bgp_listen_range_cmd,
4000 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
4001 "BGP specific commands\n"
4002 "Configure BGP dynamic neighbors listen range\n"
4003 "Configure BGP dynamic neighbors listen range\n"
4004 NEIGHBOR_ADDR_STR
4005 "Member of the peer-group\n"
4006 "Peer-group name\n")
4007 {
4008 VTY_DECLVAR_CONTEXT(bgp, bgp);
4009 struct prefix range;
4010 struct peer_group *group, *existing_group;
4011 afi_t afi;
4012 int ret;
4013 int idx = 0;
4014
4015 argv_find(argv, argc, "A.B.C.D/M", &idx);
4016 argv_find(argv, argc, "X:X::X:X/M", &idx);
4017 char *prefix = argv[idx]->arg;
4018 argv_find(argv, argc, "PGNAME", &idx);
4019 char *peergroup = argv[idx]->arg;
4020
4021 /* Convert IP prefix string to struct prefix. */
4022 ret = str2prefix(prefix, &range);
4023 if (!ret) {
4024 vty_out(vty, "%% Malformed listen range\n");
4025 return CMD_WARNING_CONFIG_FAILED;
4026 }
4027
4028 afi = family2afi(range.family);
4029
4030 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4031 vty_out(vty,
4032 "%% Malformed listen range (link-local address)\n");
4033 return CMD_WARNING_CONFIG_FAILED;
4034 }
4035
4036 apply_mask(&range);
4037
4038 /* Check if same listen range is already configured. */
4039 existing_group = listen_range_exists(bgp, &range, 1);
4040 if (existing_group) {
4041 if (strcmp(existing_group->name, peergroup) == 0)
4042 return CMD_SUCCESS;
4043 else {
4044 vty_out(vty,
4045 "%% Same listen range is attached to peer-group %s\n",
4046 existing_group->name);
4047 return CMD_WARNING_CONFIG_FAILED;
4048 }
4049 }
4050
4051 /* Check if an overlapping listen range exists. */
4052 if (listen_range_exists(bgp, &range, 0)) {
4053 vty_out(vty,
4054 "%% Listen range overlaps with existing listen range\n");
4055 return CMD_WARNING_CONFIG_FAILED;
4056 }
4057
4058 group = peer_group_lookup(bgp, peergroup);
4059 if (!group) {
4060 vty_out(vty, "%% Configure the peer-group first\n");
4061 return CMD_WARNING_CONFIG_FAILED;
4062 }
4063
4064 ret = peer_group_listen_range_add(group, &range);
4065 return bgp_vty_return(vty, ret);
4066 }
4067
4068 DEFUN (no_bgp_listen_range,
4069 no_bgp_listen_range_cmd,
4070 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
4071 NO_STR
4072 "BGP specific commands\n"
4073 "Unconfigure BGP dynamic neighbors listen range\n"
4074 "Unconfigure BGP dynamic neighbors listen range\n"
4075 NEIGHBOR_ADDR_STR
4076 "Member of the peer-group\n"
4077 "Peer-group name\n")
4078 {
4079 VTY_DECLVAR_CONTEXT(bgp, bgp);
4080 struct prefix range;
4081 struct peer_group *group;
4082 afi_t afi;
4083 int ret;
4084 int idx = 0;
4085
4086 argv_find(argv, argc, "A.B.C.D/M", &idx);
4087 argv_find(argv, argc, "X:X::X:X/M", &idx);
4088 char *prefix = argv[idx]->arg;
4089 argv_find(argv, argc, "PGNAME", &idx);
4090 char *peergroup = argv[idx]->arg;
4091
4092 /* Convert IP prefix string to struct prefix. */
4093 ret = str2prefix(prefix, &range);
4094 if (!ret) {
4095 vty_out(vty, "%% Malformed listen range\n");
4096 return CMD_WARNING_CONFIG_FAILED;
4097 }
4098
4099 afi = family2afi(range.family);
4100
4101 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4102 vty_out(vty,
4103 "%% Malformed listen range (link-local address)\n");
4104 return CMD_WARNING_CONFIG_FAILED;
4105 }
4106
4107 apply_mask(&range);
4108
4109 group = peer_group_lookup(bgp, peergroup);
4110 if (!group) {
4111 vty_out(vty, "%% Peer-group does not exist\n");
4112 return CMD_WARNING_CONFIG_FAILED;
4113 }
4114
4115 ret = peer_group_listen_range_del(group, &range);
4116 return bgp_vty_return(vty, ret);
4117 }
4118
4119 void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
4120 {
4121 struct peer_group *group;
4122 struct listnode *node, *nnode, *rnode, *nrnode;
4123 struct prefix *range;
4124 afi_t afi;
4125
4126 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
4127 vty_out(vty, " bgp listen limit %d\n",
4128 bgp->dynamic_neighbors_limit);
4129
4130 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4131 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
4132 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
4133 nrnode, range)) {
4134 vty_out(vty,
4135 " bgp listen range %pFX peer-group %s\n",
4136 range, group->name);
4137 }
4138 }
4139 }
4140 }
4141
4142
4143 DEFUN_YANG(bgp_disable_connected_route_check,
4144 bgp_disable_connected_route_check_cmd,
4145 "bgp disable-ebgp-connected-route-check",
4146 "BGP specific commands\n"
4147 "Disable checking if nexthop is connected on ebgp sessions\n")
4148 {
4149 nb_cli_enqueue_change(vty,
4150 "./global/ebgp-multihop-connected-route-check",
4151 NB_OP_MODIFY, "true");
4152
4153 return nb_cli_apply_changes(vty, NULL);
4154 }
4155
4156 DEFUN_YANG(no_bgp_disable_connected_route_check,
4157 no_bgp_disable_connected_route_check_cmd,
4158 "no bgp disable-ebgp-connected-route-check",
4159 NO_STR
4160 "BGP specific commands\n"
4161 "Disable checking if nexthop is connected on ebgp sessions\n")
4162 {
4163 nb_cli_enqueue_change(vty,
4164 "./global/ebgp-multihop-connected-route-check",
4165 NB_OP_MODIFY, "false");
4166
4167 return nb_cli_apply_changes(vty, NULL);
4168 }
4169
4170 void cli_show_router_global_ebgp_multihop_connected_route_check(
4171 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
4172 {
4173 if (yang_dnode_get_bool(dnode, NULL))
4174 vty_out(vty, " bgp disable-ebgp-connected-route-check\n");
4175 }
4176
4177 DEFUN_YANG(bgp_default_shutdown,
4178 bgp_default_shutdown_cmd,
4179 "[no] bgp default shutdown",
4180 NO_STR BGP_STR
4181 "Configure BGP defaults\n"
4182 "Apply administrative shutdown to newly configured peers\n")
4183 {
4184 nb_cli_enqueue_change(vty, "./global/default-shutdown", NB_OP_MODIFY,
4185 strmatch(argv[0]->text, "no") ? "false" : "true");
4186
4187 return nb_cli_apply_changes(vty, NULL);
4188 }
4189
4190 void cli_show_router_bgp_default_shutdown(struct vty *vty,
4191 struct lyd_node *dnode,
4192 bool show_defaults)
4193 {
4194 if (yang_dnode_get_bool(dnode, NULL))
4195 vty_out(vty, " bgp default shutdown\n");
4196 }
4197
4198 DEFPY(bgp_shutdown_msg, bgp_shutdown_msg_cmd, "bgp shutdown message MSG...",
4199 BGP_STR
4200 "Administrative shutdown of the BGP instance\n"
4201 "Add a shutdown message (RFC 8203)\n"
4202 "Shutdown message\n")
4203 {
4204 char *msgstr = NULL;
4205
4206 VTY_DECLVAR_CONTEXT(bgp, bgp);
4207
4208 if (argc > 3)
4209 msgstr = argv_concat(argv, argc, 3);
4210
4211 bgp_shutdown_enable(bgp, msgstr);
4212 XFREE(MTYPE_TMP, msgstr);
4213
4214 return CMD_SUCCESS;
4215 }
4216
4217 DEFPY(bgp_shutdown, bgp_shutdown_cmd, "bgp shutdown",
4218 BGP_STR "Administrative shutdown of the BGP instance\n")
4219 {
4220 VTY_DECLVAR_CONTEXT(bgp, bgp);
4221
4222 bgp_shutdown_enable(bgp, NULL);
4223
4224 return CMD_SUCCESS;
4225 }
4226
4227 DEFPY(no_bgp_shutdown, no_bgp_shutdown_cmd, "no bgp shutdown",
4228 NO_STR BGP_STR "Administrative shutdown of the BGP instance\n")
4229 {
4230 VTY_DECLVAR_CONTEXT(bgp, bgp);
4231
4232 bgp_shutdown_disable(bgp);
4233
4234 return CMD_SUCCESS;
4235 }
4236
4237 ALIAS(no_bgp_shutdown, no_bgp_shutdown_msg_cmd,
4238 "no bgp shutdown message MSG...", NO_STR BGP_STR
4239 "Administrative shutdown of the BGP instance\n"
4240 "Add a shutdown message (RFC 8203)\n" "Shutdown message\n")
4241
4242 DEFUN_YANG(neighbor_remote_as,
4243 neighbor_remote_as_cmd,
4244 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
4245 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4246 "Specify a BGP neighbor\n" AS_STR
4247 "Internal BGP peer\n"
4248 "External BGP peer\n")
4249 {
4250 int idx_peer = 1;
4251 int idx_remote_as = 3;
4252 char base_xpath[XPATH_MAXLEN];
4253 char unnbr_xpath[XPATH_MAXLEN];
4254 char prgrp_xpath[XPATH_MAXLEN];
4255 union sockunion su;
4256 const char *as_type_str = "as-specified";
4257
4258 if (str2sockunion(argv[idx_peer]->arg, &su) < 0) {
4259 snprintf(unnbr_xpath, sizeof(unnbr_xpath),
4260 FRR_BGP_NEIGHBOR_UNNUM_XPATH, argv[idx_peer]->arg, "");
4261
4262 snprintf(prgrp_xpath, sizeof(prgrp_xpath),
4263 FRR_BGP_PEER_GROUP_XPATH, argv[idx_peer]->arg, "");
4264
4265 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
4266 VTY_CURR_XPATH, unnbr_xpath + 1)) {
4267 strlcpy(base_xpath, unnbr_xpath, sizeof(base_xpath));
4268 } else if (yang_dnode_exists(vty->candidate_config->dnode,
4269 "%s%s", VTY_CURR_XPATH,
4270 prgrp_xpath + 1)) {
4271 snprintf(base_xpath, sizeof(base_xpath),
4272 FRR_BGP_PEER_GROUP_XPATH, argv[idx_peer]->arg,
4273 "");
4274 } else {
4275 vty_out(vty,
4276 "%% Create the peer-group or interface first\n");
4277 return CMD_WARNING_CONFIG_FAILED;
4278 }
4279 } else {
4280 snprintf(base_xpath, sizeof(base_xpath),
4281 FRR_BGP_NEIGHBOR_NUM_XPATH, argv[idx_peer]->arg, "");
4282 }
4283
4284 if (argv[idx_remote_as]->arg[0] == 'i') {
4285 as_type_str = "internal";
4286 } else if (argv[idx_remote_as]->arg[0] == 'e') {
4287 as_type_str = "external";
4288 } else {
4289 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as",
4290 NB_OP_MODIFY, argv[idx_remote_as]->arg);
4291 }
4292 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as-type",
4293 NB_OP_MODIFY, as_type_str);
4294
4295 return nb_cli_apply_changes(vty, base_xpath);
4296 }
4297
4298 int peer_conf_interface_create(struct bgp *bgp, const char *conf_if, afi_t afi,
4299 safi_t safi, bool v6only,
4300 const char *peer_group_name, int as_type,
4301 as_t as, char *errmsg, size_t errmsg_len)
4302 {
4303 struct peer *peer;
4304 struct peer_group *group;
4305 int ret = 0;
4306
4307 group = peer_group_lookup(bgp, conf_if);
4308
4309 if (group) {
4310 snprintf(errmsg, errmsg_len,
4311 "Name conflict with peer-group \n");
4312 return -1;
4313 }
4314
4315 peer = peer_lookup_by_conf_if(bgp, conf_if);
4316 if (peer) {
4317 if (as_type != AS_UNSPECIFIED)
4318 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type,
4319 afi, safi);
4320 } else {
4321 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4)
4322 && afi == AFI_IP && safi == SAFI_UNICAST)
4323 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
4324 as_type, 0, 0, NULL);
4325 else
4326 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
4327 as_type, afi, safi, NULL);
4328
4329 if (!peer) {
4330 snprintf(errmsg, errmsg_len,
4331 "BGP failed to create peer\n");
4332 return -1;
4333 }
4334
4335 if (v6only)
4336 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
4337
4338 /* Request zebra to initiate IPv6 RAs on this interface. We do
4339 * this
4340 * any unnumbered peer in order to not worry about run-time
4341 * transitions
4342 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
4343 * address
4344 * gets deleted later etc.)
4345 */
4346 if (peer->ifp)
4347 bgp_zebra_initiate_radv(bgp, peer);
4348 }
4349
4350 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
4351 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
4352 if (v6only)
4353 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
4354 else
4355 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
4356
4357 /* v6only flag changed. Reset bgp seesion */
4358 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
4359 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
4360 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
4361 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
4362 } else
4363 bgp_session_reset(peer);
4364 }
4365
4366 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
4367 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
4368 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
4369 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
4370 }
4371
4372 if (peer_group_name) {
4373 group = peer_group_lookup(bgp, peer_group_name);
4374 if (!group) {
4375 snprintf(errmsg, errmsg_len,
4376 "Configure the peer-group first\n");
4377 return -1;
4378 }
4379
4380 ret = peer_group_bind(bgp, NULL, peer, group, &as);
4381 }
4382
4383 return bgp_nb_errmsg_return(errmsg, errmsg_len, ret);
4384 }
4385
4386 DEFUN_YANG(neighbor_interface_config,
4387 neighbor_interface_config_cmd,
4388 "neighbor WORD interface [peer-group PGNAME]",
4389 NEIGHBOR_STR
4390 "Interface name or neighbor tag\n"
4391 "Enable BGP on interface\n"
4392 "Member of the peer-group\n"
4393 "Peer-group name\n")
4394 {
4395 int idx_word = 1;
4396 int idx_peer_group_word = 4;
4397 char base_xpath[XPATH_MAXLEN];
4398
4399 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4400 argv[idx_word]->arg, "");
4401
4402 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
4403 if (argc > idx_peer_group_word)
4404 nb_cli_enqueue_change(vty, "./peer-group", NB_OP_MODIFY,
4405 argv[idx_peer_group_word]->arg);
4406
4407 return nb_cli_apply_changes(vty, base_xpath);
4408 }
4409
4410 DEFUN_YANG(neighbor_interface_config_v6only,
4411 neighbor_interface_config_v6only_cmd,
4412 "neighbor WORD interface v6only [peer-group PGNAME]",
4413 NEIGHBOR_STR
4414 "Interface name or neighbor tag\n"
4415 "Enable BGP on interface\n"
4416 "Enable BGP with v6 link-local only\n"
4417 "Member of the peer-group\n"
4418 "Peer-group name\n")
4419 {
4420 int idx_word = 1;
4421 int idx_peer_group_word = 5;
4422 char base_xpath[XPATH_MAXLEN];
4423
4424 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4425 argv[idx_word]->arg, "");
4426
4427 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
4428 if (argc > idx_peer_group_word)
4429 nb_cli_enqueue_change(vty, "./peer-group", NB_OP_MODIFY,
4430 argv[idx_peer_group_word]->arg);
4431
4432 nb_cli_enqueue_change(vty, "./v6only", NB_OP_MODIFY, "true");
4433
4434 return nb_cli_apply_changes(vty, base_xpath);
4435 }
4436
4437
4438 DEFUN_YANG(
4439 neighbor_interface_config_remote_as,
4440 neighbor_interface_config_remote_as_cmd,
4441 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
4442 NEIGHBOR_STR
4443 "Interface name or neighbor tag\n"
4444 "Enable BGP on interface\n"
4445 "Specify a BGP neighbor\n" AS_STR
4446 "Internal BGP peer\n"
4447 "External BGP peer\n")
4448 {
4449 int idx_word = 1;
4450 int idx_remote_as = 4;
4451 char base_xpath[XPATH_MAXLEN];
4452 const char *as_type_str = "as-specified";
4453
4454 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4455 argv[idx_word]->arg, "");
4456
4457 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
4458
4459 if (argv[idx_remote_as]->arg[0] == 'i') {
4460 as_type_str = "internal";
4461 } else if (argv[idx_remote_as]->arg[0] == 'e') {
4462 as_type_str = "external";
4463 } else {
4464 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as",
4465 NB_OP_MODIFY, argv[idx_remote_as]->arg);
4466 }
4467 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as-type",
4468 NB_OP_MODIFY, as_type_str);
4469
4470 return nb_cli_apply_changes(vty, base_xpath);
4471 }
4472
4473 DEFUN_YANG(
4474 neighbor_interface_v6only_config_remote_as,
4475 neighbor_interface_v6only_config_remote_as_cmd,
4476 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
4477 NEIGHBOR_STR
4478 "Interface name or neighbor tag\n"
4479 "Enable BGP with v6 link-local only\n"
4480 "Enable BGP on interface\n"
4481 "Specify a BGP neighbor\n" AS_STR
4482 "Internal BGP peer\n"
4483 "External BGP peer\n")
4484 {
4485 int idx_word = 1;
4486 int idx_remote_as = 5;
4487 char base_xpath[XPATH_MAXLEN];
4488 const char *as_type_str = "as-specified";
4489
4490 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4491 argv[idx_word]->arg, "");
4492
4493 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
4494
4495 nb_cli_enqueue_change(vty, "./v6only", NB_OP_MODIFY, "true");
4496
4497 if (argv[idx_remote_as]->arg[0] == 'i') {
4498 as_type_str = "internal";
4499 } else if (argv[idx_remote_as]->arg[0] == 'e') {
4500 as_type_str = "external";
4501 } else {
4502 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as",
4503 NB_OP_MODIFY, argv[idx_remote_as]->arg);
4504 }
4505 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as-type",
4506 NB_OP_MODIFY, as_type_str);
4507
4508 return nb_cli_apply_changes(vty, base_xpath);
4509 }
4510
4511 DEFUN_YANG(neighbor_peer_group, neighbor_peer_group_cmd,
4512 "neighbor WORD peer-group",
4513 NEIGHBOR_STR
4514 "Interface name or neighbor tag\n"
4515 "Configure peer-group\n")
4516 {
4517 char base_xpath[XPATH_MAXLEN];
4518 int idx_word = 1;
4519
4520 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_PEER_GROUP_XPATH,
4521 argv[idx_word]->arg, "");
4522
4523 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
4524
4525 return nb_cli_apply_changes(vty, base_xpath);
4526 }
4527
4528 DEFUN_YANG(no_neighbor,
4529 no_neighbor_cmd,
4530 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
4531 NO_STR NEIGHBOR_STR
4532 NEIGHBOR_ADDR_STR2
4533 "Specify a BGP neighbor\n" AS_STR
4534 "Internal BGP peer\n"
4535 "External BGP peer\n")
4536 {
4537 int idx_peer = 2;
4538 char base_xpath[XPATH_MAXLEN];
4539 char num_xpath[XPATH_MAXLEN];
4540 char unnbr_xpath[XPATH_MAXLEN];
4541 char prgrp_xpath[XPATH_MAXLEN];
4542 union sockunion su;
4543
4544 if (str2sockunion(argv[idx_peer]->arg, &su) == 0) {
4545 snprintf(num_xpath, sizeof(num_xpath),
4546 FRR_BGP_NEIGHBOR_NUM_XPATH, argv[idx_peer]->arg, "");
4547 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
4548 VTY_CURR_XPATH, num_xpath + 1)) {
4549 strlcpy(base_xpath, num_xpath, sizeof(base_xpath));
4550 }
4551 } else {
4552 snprintf(unnbr_xpath, sizeof(unnbr_xpath),
4553 FRR_BGP_NEIGHBOR_UNNUM_XPATH, argv[idx_peer]->arg, "");
4554
4555 snprintf(prgrp_xpath, sizeof(prgrp_xpath),
4556 FRR_BGP_PEER_GROUP_XPATH, argv[idx_peer]->arg, "");
4557
4558 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
4559 VTY_CURR_XPATH, unnbr_xpath + 1)) {
4560 strlcpy(base_xpath, unnbr_xpath, sizeof(base_xpath));
4561 } else if (yang_dnode_exists(vty->candidate_config->dnode,
4562 "%s%s", VTY_CURR_XPATH,
4563 prgrp_xpath + 1)) {
4564 strlcpy(base_xpath, prgrp_xpath, sizeof(base_xpath));
4565 } else {
4566 vty_out(vty,
4567 "%% Create the peer-group or interface first\n");
4568 return CMD_WARNING_CONFIG_FAILED;
4569 }
4570 }
4571
4572 nb_cli_enqueue_change(vty, base_xpath, NB_OP_DESTROY, NULL);
4573
4574 return nb_cli_apply_changes(vty, NULL);
4575 }
4576
4577 DEFUN_YANG(no_neighbor_interface_config,
4578 no_neighbor_interface_config_cmd,
4579 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
4580 NO_STR NEIGHBOR_STR
4581 "Interface name\n"
4582 "Configure BGP on interface\n"
4583 "Enable BGP with v6 link-local only\n"
4584 "Member of the peer-group\n"
4585 "Peer-group name\n"
4586 "Specify a BGP neighbor\n" AS_STR
4587 "Internal BGP peer\n"
4588 "External BGP peer\n")
4589 {
4590 int idx_word = 2;
4591 char base_xpath[XPATH_MAXLEN];
4592
4593 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4594 argv[idx_word]->arg, "");
4595
4596 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
4597
4598 return nb_cli_apply_changes(vty, base_xpath);
4599 }
4600
4601 DEFUN_YANG(no_neighbor_peer_group,
4602 no_neighbor_peer_group_cmd,
4603 "no neighbor WORD peer-group",
4604 NO_STR NEIGHBOR_STR
4605 "Neighbor tag\n"
4606 "Configure peer-group\n")
4607 {
4608 char base_xpath[XPATH_MAXLEN];
4609 int idx_word = 2;
4610
4611 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_PEER_GROUP_XPATH,
4612 argv[idx_word]->arg, "");
4613
4614 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
4615
4616 return nb_cli_apply_changes(vty, base_xpath);
4617 }
4618
4619 DEFUN_YANG(no_neighbor_interface_peer_group_remote_as,
4620 no_neighbor_interface_peer_group_remote_as_cmd,
4621 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
4622 NO_STR NEIGHBOR_STR
4623 "Interface name or neighbor tag\n"
4624 "Specify a BGP neighbor\n" AS_STR
4625 "Internal BGP peer\n"
4626 "External BGP peer\n")
4627 {
4628 int idx_peer = 2;
4629 char base_xpath[XPATH_MAXLEN];
4630 char unnbr_xpath[XPATH_MAXLEN];
4631 char prgrp_xpath[XPATH_MAXLEN];
4632
4633 snprintf(unnbr_xpath, sizeof(unnbr_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4634 argv[idx_peer]->arg, "");
4635
4636 snprintf(prgrp_xpath, sizeof(prgrp_xpath), FRR_BGP_PEER_GROUP_XPATH,
4637 argv[idx_peer]->arg, "");
4638
4639 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
4640 VTY_CURR_XPATH, unnbr_xpath + 1)) {
4641 strlcpy(base_xpath, unnbr_xpath, sizeof(base_xpath));
4642 } else if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
4643 VTY_CURR_XPATH, prgrp_xpath + 1)) {
4644 strlcpy(base_xpath, prgrp_xpath, sizeof(base_xpath));
4645 } else {
4646 vty_out(vty, "%% Create the peer-group or interface first\n");
4647 return CMD_WARNING_CONFIG_FAILED;
4648 }
4649
4650 strlcat(base_xpath, "/neighbor-remote-as/remote-as-type",
4651 sizeof(base_xpath));
4652
4653 nb_cli_enqueue_change(vty, base_xpath, NB_OP_DESTROY, NULL);
4654
4655 return nb_cli_apply_changes(vty, NULL);
4656 }
4657
4658 DEFUN_YANG(neighbor_local_as,
4659 neighbor_local_as_cmd,
4660 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
4661 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4662 "Specify a local-as number\n"
4663 "AS number used as local AS\n")
4664 {
4665 int idx_peer = 1;
4666 int idx_number = 3;
4667 char base_xpath[XPATH_MAXLEN];
4668
4669 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4670 sizeof(base_xpath), NULL)
4671 < 0)
4672 return CMD_WARNING_CONFIG_FAILED;
4673
4674 nb_cli_enqueue_change(vty, "./local-as/local-as", NB_OP_MODIFY,
4675 argv[idx_number]->arg);
4676
4677 return nb_cli_apply_changes(vty, base_xpath);
4678 }
4679
4680 DEFUN_YANG(
4681 neighbor_local_as_no_prepend, neighbor_local_as_no_prepend_cmd,
4682 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
4683 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4684 "Specify a local-as number\n"
4685 "AS number used as local AS\n"
4686 "Do not prepend local-as to updates from ebgp peers\n")
4687 {
4688 int idx_peer = 1;
4689 int idx_number = 3;
4690 char base_xpath[XPATH_MAXLEN];
4691
4692 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4693 sizeof(base_xpath), NULL)
4694 < 0)
4695 return CMD_WARNING_CONFIG_FAILED;
4696
4697 nb_cli_enqueue_change(vty, "./local-as/local-as", NB_OP_MODIFY,
4698 argv[idx_number]->arg);
4699 nb_cli_enqueue_change(vty, "./local-as/no-prepend", NB_OP_MODIFY,
4700 "true");
4701
4702 return nb_cli_apply_changes(vty, base_xpath);
4703 }
4704
4705 DEFUN_YANG(
4706 neighbor_local_as_no_prepend_replace_as,
4707 neighbor_local_as_no_prepend_replace_as_cmd,
4708 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
4709 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4710 "Specify a local-as number\n"
4711 "AS number used as local AS\n"
4712 "Do not prepend local-as to updates from ebgp peers\n"
4713 "Do not prepend local-as to updates from ibgp peers\n")
4714 {
4715 int idx_peer = 1;
4716 int idx_number = 3;
4717 char base_xpath[XPATH_MAXLEN];
4718
4719 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4720 sizeof(base_xpath), NULL)
4721 < 0)
4722 return CMD_WARNING_CONFIG_FAILED;
4723
4724 nb_cli_enqueue_change(vty, "./local-as/local-as", NB_OP_MODIFY,
4725 argv[idx_number]->arg);
4726 nb_cli_enqueue_change(vty, "./local-as/no-prepend", NB_OP_MODIFY,
4727 "true");
4728 nb_cli_enqueue_change(vty, "./local-as/no-replace-as", NB_OP_MODIFY,
4729 "true");
4730
4731 return nb_cli_apply_changes(vty, base_xpath);
4732 }
4733
4734 DEFUN_YANG(no_neighbor_local_as,
4735 no_neighbor_local_as_cmd,
4736 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
4737 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4738 "Specify a local-as number\n"
4739 "AS number used as local AS\n"
4740 "Do not prepend local-as to updates from ebgp peers\n"
4741 "Do not prepend local-as to updates from ibgp peers\n")
4742 {
4743 int idx_peer = 2;
4744 char base_xpath[XPATH_MAXLEN];
4745
4746 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4747 sizeof(base_xpath), NULL)
4748 < 0)
4749 return CMD_WARNING_CONFIG_FAILED;
4750
4751 nb_cli_enqueue_change(vty, "./local-as/local-as", NB_OP_DESTROY, NULL);
4752 nb_cli_enqueue_change(vty, "./local-as/no-prepend", NB_OP_MODIFY,
4753 "false");
4754 nb_cli_enqueue_change(vty, "./local-as/no-replace-as", NB_OP_MODIFY,
4755 "false");
4756
4757 return nb_cli_apply_changes(vty, base_xpath);
4758 }
4759
4760
4761 DEFUN (neighbor_solo,
4762 neighbor_solo_cmd,
4763 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
4764 NEIGHBOR_STR
4765 NEIGHBOR_ADDR_STR2
4766 "Solo peer - part of its own update group\n")
4767 {
4768 int idx_peer = 1;
4769 struct peer *peer;
4770 int ret;
4771
4772 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4773 if (!peer)
4774 return CMD_WARNING_CONFIG_FAILED;
4775
4776 ret = update_group_adjust_soloness(peer, 1);
4777 return bgp_vty_return(vty, ret);
4778 }
4779
4780 DEFUN (no_neighbor_solo,
4781 no_neighbor_solo_cmd,
4782 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
4783 NO_STR
4784 NEIGHBOR_STR
4785 NEIGHBOR_ADDR_STR2
4786 "Solo peer - part of its own update group\n")
4787 {
4788 int idx_peer = 2;
4789 struct peer *peer;
4790 int ret;
4791
4792 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4793 if (!peer)
4794 return CMD_WARNING_CONFIG_FAILED;
4795
4796 ret = update_group_adjust_soloness(peer, 0);
4797 return bgp_vty_return(vty, ret);
4798 }
4799
4800 DEFUN_YANG(neighbor_password,
4801 neighbor_password_cmd,
4802 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
4803 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4804 "Set a password\n"
4805 "The password\n")
4806 {
4807 int idx_peer = 1;
4808 int idx_line = 3;
4809 char base_xpath[XPATH_MAXLEN];
4810
4811 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4812 sizeof(base_xpath), NULL)
4813 < 0)
4814 return CMD_WARNING_CONFIG_FAILED;
4815
4816 nb_cli_enqueue_change(vty, "./password", NB_OP_MODIFY,
4817 argv[idx_line]->arg);
4818
4819 return nb_cli_apply_changes(vty, base_xpath);
4820 }
4821
4822 DEFUN_YANG(no_neighbor_password,
4823 no_neighbor_password_cmd,
4824 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
4825 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4826 "Set a password\n"
4827 "The password\n")
4828 {
4829 int idx_peer = 2;
4830 char base_xpath[XPATH_MAXLEN];
4831
4832 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4833 sizeof(base_xpath), NULL)
4834 < 0)
4835 return CMD_WARNING_CONFIG_FAILED;
4836
4837 nb_cli_enqueue_change(vty, "./password", NB_OP_DESTROY, NULL);
4838
4839 return nb_cli_apply_changes(vty, base_xpath);
4840 }
4841
4842 DEFUN_YANG(neighbor_activate,
4843 neighbor_activate_cmd,
4844 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4845 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4846 "Enable the Address Family for this Neighbor\n")
4847 {
4848 int idx_peer = 1;
4849 char base_xpath[XPATH_MAXLEN];
4850 char af_xpath[XPATH_MAXLEN];
4851 afi_t afi = bgp_node_afi(vty);
4852 safi_t safi = bgp_node_safi(vty);
4853
4854 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
4855 yang_afi_safi_value2identity(afi, safi));
4856 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4857 sizeof(base_xpath), af_xpath)
4858 < 0)
4859 return CMD_WARNING_CONFIG_FAILED;
4860
4861 nb_cli_enqueue_change(vty, "./enabled", NB_OP_MODIFY, "true");
4862
4863 return nb_cli_apply_changes(vty, base_xpath);
4864 }
4865
4866 ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
4867 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4868 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4869 "Enable the Address Family for this Neighbor\n")
4870
4871 DEFUN_YANG(no_neighbor_activate,
4872 no_neighbor_activate_cmd,
4873 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4874 NO_STR NEIGHBOR_STR
4875 NEIGHBOR_ADDR_STR2
4876 "Enable the Address Family for this Neighbor\n")
4877 {
4878 int idx_peer = 2;
4879 char base_xpath[XPATH_MAXLEN];
4880 char af_xpath[XPATH_MAXLEN];
4881 afi_t afi = bgp_node_afi(vty);
4882 safi_t safi = bgp_node_safi(vty);
4883
4884 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
4885 yang_afi_safi_value2identity(afi, safi));
4886
4887 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4888 sizeof(base_xpath), af_xpath)
4889 < 0)
4890 return CMD_WARNING_CONFIG_FAILED;
4891
4892 nb_cli_enqueue_change(vty, "./enabled", NB_OP_MODIFY, "false");
4893
4894 return nb_cli_apply_changes(vty, base_xpath);
4895 }
4896
4897 ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
4898 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4899 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4900 "Enable the Address Family for this Neighbor\n")
4901
4902 DEFUN_YANG (neighbor_set_peer_group,
4903 neighbor_set_peer_group_cmd,
4904 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
4905 NEIGHBOR_STR
4906 NEIGHBOR_ADDR_STR2
4907 "Member of the peer-group\n"
4908 "Peer-group name\n")
4909 {
4910 int idx_peer = 1;
4911 int idx_word = 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, "./peer-group", NB_OP_MODIFY,
4920 argv[idx_word]->arg);
4921
4922 return nb_cli_apply_changes(vty, base_xpath);
4923 }
4924
4925 ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
4926 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
4927 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4928 "Member of the peer-group\n"
4929 "Peer-group name\n")
4930
4931 DEFUN_YANG (no_neighbor_set_peer_group,
4932 no_neighbor_set_peer_group_cmd,
4933 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
4934 NO_STR
4935 NEIGHBOR_STR
4936 NEIGHBOR_ADDR_STR2
4937 "Member of the peer-group\n"
4938 "Peer-group name\n")
4939 {
4940 int idx_peer = 2;
4941 char base_xpath[XPATH_MAXLEN];
4942
4943 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4944 sizeof(base_xpath), NULL)
4945 < 0)
4946 return CMD_WARNING_CONFIG_FAILED;
4947
4948 nb_cli_enqueue_change(vty, "./peer-group", NB_OP_DESTROY, NULL);
4949
4950 return nb_cli_apply_changes(vty, base_xpath);
4951 }
4952
4953 ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
4954 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
4955 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4956 "Member of the peer-group\n"
4957 "Peer-group name\n")
4958
4959 static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
4960 uint32_t flag, int set)
4961 {
4962 int ret;
4963 struct peer *peer;
4964
4965 peer = peer_and_group_lookup_vty(vty, ip_str);
4966 if (!peer)
4967 return CMD_WARNING_CONFIG_FAILED;
4968
4969 /*
4970 * If 'neighbor <interface>', then this is for directly connected peers,
4971 * we should not accept disable-connected-check.
4972 */
4973 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
4974 vty_out(vty,
4975 "%s is directly connected peer, cannot accept disable-connected-check\n",
4976 ip_str);
4977 return CMD_WARNING_CONFIG_FAILED;
4978 }
4979
4980 if (!set && flag == PEER_FLAG_SHUTDOWN)
4981 peer_tx_shutdown_message_unset(peer);
4982
4983 if (set)
4984 ret = peer_flag_set(peer, flag);
4985 else
4986 ret = peer_flag_unset(peer, flag);
4987
4988 return bgp_vty_return(vty, ret);
4989 }
4990
4991 static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
4992 {
4993 return peer_flag_modify_vty(vty, ip_str, flag, 1);
4994 }
4995
4996 static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
4997 uint32_t flag)
4998 {
4999 return peer_flag_modify_vty(vty, ip_str, flag, 0);
5000 }
5001
5002 int peer_flag_modify_nb(struct bgp *bgp, const char *ip_str, struct peer *peer,
5003 uint32_t flag, bool set, char *errmsg,
5004 size_t errmsg_len)
5005 {
5006 int ret;
5007
5008 /*
5009 * If 'neighbor <interface>', then this is for directly connected peers,
5010 * we should not accept disable-connected-check.
5011 */
5012 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
5013 snprintf(
5014 errmsg, errmsg_len,
5015 "%s is directly connected peer, cannot accept disable-connected-check\n",
5016 ip_str);
5017 return -1;
5018 }
5019
5020 if (!set && flag == PEER_FLAG_SHUTDOWN)
5021 peer_tx_shutdown_message_unset(peer);
5022
5023 if (set)
5024 ret = peer_flag_set(peer, flag);
5025 else
5026 ret = peer_flag_unset(peer, flag);
5027
5028 return bgp_nb_errmsg_return(errmsg, errmsg_len, ret);
5029 }
5030
5031 /* neighbor passive. */
5032 DEFUN_YANG(neighbor_passive,
5033 neighbor_passive_cmd,
5034 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5035 NEIGHBOR_STR
5036 NEIGHBOR_ADDR_STR2
5037 "Don't send open messages to this neighbor\n")
5038 {
5039 int idx_peer = 1;
5040 char base_xpath[XPATH_MAXLEN];
5041
5042 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5043 sizeof(base_xpath), NULL)
5044 < 0)
5045 return CMD_WARNING_CONFIG_FAILED;
5046
5047 nb_cli_enqueue_change(vty, "./passive-mode", NB_OP_MODIFY, "true");
5048
5049 return nb_cli_apply_changes(vty, base_xpath);
5050 }
5051
5052 DEFUN_YANG(no_neighbor_passive,
5053 no_neighbor_passive_cmd,
5054 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5055 NO_STR NEIGHBOR_STR
5056 NEIGHBOR_ADDR_STR2
5057 "Don't send open messages to this neighbor\n")
5058 {
5059 int idx_peer = 2;
5060 char base_xpath[XPATH_MAXLEN];
5061
5062 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5063 sizeof(base_xpath), NULL)
5064 < 0)
5065 return CMD_WARNING_CONFIG_FAILED;
5066
5067 nb_cli_enqueue_change(vty, "./passive-mode", NB_OP_MODIFY, "false");
5068
5069 return nb_cli_apply_changes(vty, base_xpath);
5070 }
5071
5072 /* neighbor shutdown. */
5073 DEFUN_YANG(neighbor_shutdown_msg,
5074 neighbor_shutdown_msg_cmd,
5075 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5076 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5077 "Administratively shut down this neighbor\n"
5078 "Add a shutdown message (RFC 8203)\n"
5079 "Shutdown message\n")
5080 {
5081 int idx_peer = 1;
5082 char base_xpath[XPATH_MAXLEN];
5083
5084 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5085 sizeof(base_xpath), NULL)
5086 < 0)
5087 return CMD_WARNING_CONFIG_FAILED;
5088
5089 if (argc >= 5) {
5090 char *message;
5091
5092 message = argv_concat(argv, argc, 4);
5093 nb_cli_enqueue_change(vty, "./admin-shutdown/message",
5094 NB_OP_MODIFY, message);
5095 }
5096
5097 nb_cli_enqueue_change(vty, "./admin-shutdown/enable", NB_OP_MODIFY,
5098 "true");
5099
5100 return nb_cli_apply_changes(vty, base_xpath);
5101 }
5102
5103 ALIAS_YANG(neighbor_shutdown_msg, neighbor_shutdown_cmd,
5104 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5105 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5106 "Administratively shut down this neighbor\n")
5107
5108 DEFUN_YANG(no_neighbor_shutdown_msg,
5109 no_neighbor_shutdown_msg_cmd,
5110 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5111 NO_STR NEIGHBOR_STR
5112 NEIGHBOR_ADDR_STR2
5113 "Administratively shut down this neighbor\n"
5114 "Remove a shutdown message (RFC 8203)\n"
5115 "Shutdown message\n")
5116 {
5117 int idx_peer = 2;
5118 char base_xpath[XPATH_MAXLEN];
5119
5120 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5121 sizeof(base_xpath), NULL)
5122 < 0)
5123 return CMD_WARNING_CONFIG_FAILED;
5124
5125 nb_cli_enqueue_change(vty, "./admin-shutdown/enable", NB_OP_MODIFY,
5126 "false");
5127
5128 return nb_cli_apply_changes(vty, base_xpath);
5129 }
5130
5131 ALIAS_YANG(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
5132 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5133 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5134 "Administratively shut down this neighbor\n")
5135
5136 DEFUN(neighbor_shutdown_rtt,
5137 neighbor_shutdown_rtt_cmd,
5138 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt (1-65535) [count (1-255)]",
5139 NEIGHBOR_STR
5140 NEIGHBOR_ADDR_STR2
5141 "Administratively shut down this neighbor\n"
5142 "Shutdown if round-trip-time is higher than expected\n"
5143 "Round-trip-time in milliseconds\n"
5144 "Specify the number of keepalives before shutdown\n"
5145 "The number of keepalives with higher RTT to shutdown\n")
5146 {
5147 int idx_peer = 1;
5148 int idx_rtt = 4;
5149 int idx_count = 0;
5150 struct peer *peer;
5151
5152 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5153
5154 if (!peer)
5155 return CMD_WARNING_CONFIG_FAILED;
5156
5157 peer->rtt_expected = strtol(argv[idx_rtt]->arg, NULL, 10);
5158
5159 if (argv_find(argv, argc, "count", &idx_count))
5160 peer->rtt_keepalive_conf =
5161 strtol(argv[idx_count + 1]->arg, NULL, 10);
5162
5163 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5164 PEER_FLAG_RTT_SHUTDOWN);
5165 }
5166
5167 DEFUN(no_neighbor_shutdown_rtt,
5168 no_neighbor_shutdown_rtt_cmd,
5169 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt [(1-65535) [count (1-255)]]",
5170 NO_STR
5171 NEIGHBOR_STR
5172 NEIGHBOR_ADDR_STR2
5173 "Administratively shut down this neighbor\n"
5174 "Shutdown if round-trip-time is higher than expected\n"
5175 "Round-trip-time in milliseconds\n"
5176 "Specify the number of keepalives before shutdown\n"
5177 "The number of keepalives with higher RTT to shutdown\n")
5178 {
5179 int idx_peer = 2;
5180 struct peer *peer;
5181
5182 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5183
5184 if (!peer)
5185 return CMD_WARNING_CONFIG_FAILED;
5186
5187 peer->rtt_expected = 0;
5188 peer->rtt_keepalive_conf = 1;
5189
5190 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5191 PEER_FLAG_RTT_SHUTDOWN);
5192 }
5193
5194 /* neighbor capability dynamic. */
5195 DEFUN_YANG (neighbor_capability_dynamic,
5196 neighbor_capability_dynamic_cmd,
5197 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5198 NEIGHBOR_STR
5199 NEIGHBOR_ADDR_STR2
5200 "Advertise capability to the peer\n"
5201 "Advertise dynamic capability to this neighbor\n")
5202 {
5203 int idx_peer = 1;
5204 char base_xpath[XPATH_MAXLEN];
5205
5206 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5207 sizeof(base_xpath), NULL)
5208 < 0)
5209 return CMD_WARNING_CONFIG_FAILED;
5210
5211 nb_cli_enqueue_change(vty, "./capability-options/dynamic-capability",
5212 NB_OP_MODIFY, "true");
5213
5214 return nb_cli_apply_changes(vty, base_xpath);
5215 }
5216
5217 DEFUN_YANG (no_neighbor_capability_dynamic,
5218 no_neighbor_capability_dynamic_cmd,
5219 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5220 NO_STR
5221 NEIGHBOR_STR
5222 NEIGHBOR_ADDR_STR2
5223 "Advertise capability to the peer\n"
5224 "Advertise dynamic capability to this neighbor\n")
5225 {
5226 int idx_peer = 2;
5227 char base_xpath[XPATH_MAXLEN];
5228
5229 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5230 sizeof(base_xpath), NULL)
5231 < 0)
5232 return CMD_WARNING_CONFIG_FAILED;
5233
5234 nb_cli_enqueue_change(vty, "./capability-options/dynamic-capability",
5235 NB_OP_MODIFY, "false");
5236
5237 return nb_cli_apply_changes(vty, base_xpath);
5238 }
5239
5240 /* neighbor dont-capability-negotiate */
5241 DEFUN (neighbor_dont_capability_negotiate,
5242 neighbor_dont_capability_negotiate_cmd,
5243 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
5244 NEIGHBOR_STR
5245 NEIGHBOR_ADDR_STR2
5246 "Do not perform capability negotiation\n")
5247 {
5248 int idx_peer = 1;
5249 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5250 PEER_FLAG_DONT_CAPABILITY);
5251 }
5252
5253 DEFUN (no_neighbor_dont_capability_negotiate,
5254 no_neighbor_dont_capability_negotiate_cmd,
5255 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
5256 NO_STR
5257 NEIGHBOR_STR
5258 NEIGHBOR_ADDR_STR2
5259 "Do not perform capability negotiation\n")
5260 {
5261 int idx_peer = 2;
5262 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5263 PEER_FLAG_DONT_CAPABILITY);
5264 }
5265
5266 /* neighbor capability extended next hop encoding */
5267 DEFUN_YANG (neighbor_capability_enhe,
5268 neighbor_capability_enhe_cmd,
5269 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5270 NEIGHBOR_STR
5271 NEIGHBOR_ADDR_STR2
5272 "Advertise capability to the peer\n"
5273 "Advertise extended next-hop capability to the peer\n")
5274 {
5275 int idx_peer = 1;
5276 char base_xpath[XPATH_MAXLEN];
5277
5278 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5279 sizeof(base_xpath), NULL)
5280 < 0)
5281 return CMD_WARNING_CONFIG_FAILED;
5282
5283 nb_cli_enqueue_change(
5284 vty, "./capability-options/extended-nexthop-capability",
5285 NB_OP_MODIFY, "true");
5286
5287 return nb_cli_apply_changes(vty, base_xpath);
5288 }
5289
5290 DEFUN_YANG (no_neighbor_capability_enhe,
5291 no_neighbor_capability_enhe_cmd,
5292 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5293 NO_STR
5294 NEIGHBOR_STR
5295 NEIGHBOR_ADDR_STR2
5296 "Advertise capability to the peer\n"
5297 "Advertise extended next-hop capability to the peer\n")
5298 {
5299 int idx_peer = 2;
5300 char base_xpath[XPATH_MAXLEN];
5301
5302 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5303 sizeof(base_xpath), NULL)
5304 < 0)
5305 return CMD_WARNING_CONFIG_FAILED;
5306
5307 nb_cli_enqueue_change(
5308 vty, "./capability-options/extended-nexthop-capability",
5309 NB_OP_MODIFY, "false");
5310
5311 return nb_cli_apply_changes(vty, base_xpath);
5312 }
5313
5314 int peer_af_flag_modify_nb(struct peer *peer, afi_t afi, safi_t safi,
5315 uint32_t flag, int set, char *errmsg,
5316 size_t errmsg_len)
5317 {
5318 int ret;
5319
5320 if (set)
5321 ret = peer_af_flag_set(peer, afi, safi, flag);
5322 else
5323 ret = peer_af_flag_unset(peer, afi, safi, flag);
5324
5325 return bgp_nb_errmsg_return(errmsg, errmsg_len, ret);
5326 }
5327
5328 static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
5329 afi_t afi, safi_t safi, uint32_t flag,
5330 int set)
5331 {
5332 int ret;
5333 struct peer *peer;
5334
5335 peer = peer_and_group_lookup_vty(vty, peer_str);
5336 if (!peer)
5337 return CMD_WARNING_CONFIG_FAILED;
5338
5339 if (set)
5340 ret = peer_af_flag_set(peer, afi, safi, flag);
5341 else
5342 ret = peer_af_flag_unset(peer, afi, safi, flag);
5343
5344 return bgp_vty_return(vty, ret);
5345 }
5346
5347 static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
5348 afi_t afi, safi_t safi, uint32_t flag)
5349 {
5350 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
5351 }
5352
5353 static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
5354 afi_t afi, safi_t safi, uint32_t flag)
5355 {
5356 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
5357 }
5358
5359 /* neighbor capability orf prefix-list. */
5360 DEFUN (neighbor_capability_orf_prefix,
5361 neighbor_capability_orf_prefix_cmd,
5362 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5363 NEIGHBOR_STR
5364 NEIGHBOR_ADDR_STR2
5365 "Advertise capability to the peer\n"
5366 "Advertise ORF capability to the peer\n"
5367 "Advertise prefixlist ORF capability to this neighbor\n"
5368 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5369 "Capability to RECEIVE the ORF from this neighbor\n"
5370 "Capability to SEND the ORF to this neighbor\n")
5371 {
5372 int idx_send_recv = 5;
5373 char *peer_str = argv[1]->arg;
5374 struct peer *peer;
5375 afi_t afi = bgp_node_afi(vty);
5376 safi_t safi = bgp_node_safi(vty);
5377
5378 peer = peer_and_group_lookup_vty(vty, peer_str);
5379 if (!peer)
5380 return CMD_WARNING_CONFIG_FAILED;
5381
5382 if (strmatch(argv[idx_send_recv]->text, "send"))
5383 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5384 PEER_FLAG_ORF_PREFIX_SM);
5385
5386 if (strmatch(argv[idx_send_recv]->text, "receive"))
5387 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5388 PEER_FLAG_ORF_PREFIX_RM);
5389
5390 if (strmatch(argv[idx_send_recv]->text, "both"))
5391 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5392 PEER_FLAG_ORF_PREFIX_SM)
5393 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5394 PEER_FLAG_ORF_PREFIX_RM);
5395
5396 return CMD_WARNING_CONFIG_FAILED;
5397 }
5398
5399 ALIAS_HIDDEN(
5400 neighbor_capability_orf_prefix,
5401 neighbor_capability_orf_prefix_hidden_cmd,
5402 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5403 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5404 "Advertise capability to the peer\n"
5405 "Advertise ORF capability to the peer\n"
5406 "Advertise prefixlist ORF capability to this neighbor\n"
5407 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5408 "Capability to RECEIVE the ORF from this neighbor\n"
5409 "Capability to SEND the ORF to this neighbor\n")
5410
5411 DEFUN (no_neighbor_capability_orf_prefix,
5412 no_neighbor_capability_orf_prefix_cmd,
5413 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5414 NO_STR
5415 NEIGHBOR_STR
5416 NEIGHBOR_ADDR_STR2
5417 "Advertise capability to the peer\n"
5418 "Advertise ORF capability to the peer\n"
5419 "Advertise prefixlist ORF capability to this neighbor\n"
5420 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5421 "Capability to RECEIVE the ORF from this neighbor\n"
5422 "Capability to SEND the ORF to this neighbor\n")
5423 {
5424 int idx_send_recv = 6;
5425 char *peer_str = argv[2]->arg;
5426 struct peer *peer;
5427 afi_t afi = bgp_node_afi(vty);
5428 safi_t safi = bgp_node_safi(vty);
5429
5430 peer = peer_and_group_lookup_vty(vty, peer_str);
5431 if (!peer)
5432 return CMD_WARNING_CONFIG_FAILED;
5433
5434 if (strmatch(argv[idx_send_recv]->text, "send"))
5435 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5436 PEER_FLAG_ORF_PREFIX_SM);
5437
5438 if (strmatch(argv[idx_send_recv]->text, "receive"))
5439 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5440 PEER_FLAG_ORF_PREFIX_RM);
5441
5442 if (strmatch(argv[idx_send_recv]->text, "both"))
5443 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5444 PEER_FLAG_ORF_PREFIX_SM)
5445 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5446 PEER_FLAG_ORF_PREFIX_RM);
5447
5448 return CMD_WARNING_CONFIG_FAILED;
5449 }
5450
5451 ALIAS_HIDDEN(
5452 no_neighbor_capability_orf_prefix,
5453 no_neighbor_capability_orf_prefix_hidden_cmd,
5454 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5455 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5456 "Advertise capability to the peer\n"
5457 "Advertise ORF capability to the peer\n"
5458 "Advertise prefixlist ORF capability to this neighbor\n"
5459 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5460 "Capability to RECEIVE the ORF from this neighbor\n"
5461 "Capability to SEND the ORF to this neighbor\n")
5462
5463 /* neighbor next-hop-self. */
5464 DEFUN_YANG (neighbor_nexthop_self,
5465 neighbor_nexthop_self_cmd,
5466 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5467 NEIGHBOR_STR
5468 NEIGHBOR_ADDR_STR2
5469 "Disable the next hop calculation for this neighbor\n")
5470 {
5471 int idx_peer = 1;
5472 char base_xpath[XPATH_MAXLEN];
5473 char af_xpath[XPATH_MAXLEN];
5474 char attr_xpath[XPATH_MAXLEN];
5475 afi_t afi = bgp_node_afi(vty);
5476 safi_t safi = bgp_node_safi(vty);
5477
5478
5479 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5480 yang_afi_safi_value2identity(afi, safi));
5481
5482 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5483 sizeof(base_xpath), af_xpath)
5484 < 0)
5485 return CMD_WARNING_CONFIG_FAILED;
5486
5487 snprintf(attr_xpath, sizeof(attr_xpath),
5488 "./%s/nexthop-self/next-hop-self",
5489 bgp_afi_safi_get_container_str(afi, safi));
5490
5491 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5492
5493 return nb_cli_apply_changes(vty, base_xpath);
5494 }
5495
5496 ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
5497 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5498 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5499 "Disable the next hop calculation for this neighbor\n")
5500
5501 /* neighbor next-hop-self. */
5502 DEFUN_YANG(neighbor_nexthop_self_force,
5503 neighbor_nexthop_self_force_cmd,
5504 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5505 NEIGHBOR_STR
5506 NEIGHBOR_ADDR_STR2
5507 "Disable the next hop calculation for this neighbor\n"
5508 "Set the next hop to self for reflected routes\n")
5509 {
5510 int idx_peer = 1;
5511 char base_xpath[XPATH_MAXLEN];
5512 char af_xpath[XPATH_MAXLEN];
5513 char attr_xpath[XPATH_MAXLEN];
5514 afi_t afi = bgp_node_afi(vty);
5515 safi_t safi = bgp_node_safi(vty);
5516
5517
5518 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5519 yang_afi_safi_value2identity(afi, safi));
5520
5521 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5522 sizeof(base_xpath), af_xpath)
5523 < 0)
5524 return CMD_WARNING_CONFIG_FAILED;
5525
5526 snprintf(attr_xpath, sizeof(attr_xpath),
5527 "./%s/nexthop-self/next-hop-self-force",
5528 bgp_afi_safi_get_container_str(afi, safi));
5529
5530 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5531
5532 return nb_cli_apply_changes(vty, base_xpath);
5533 }
5534
5535 ALIAS_HIDDEN(neighbor_nexthop_self_force,
5536 neighbor_nexthop_self_force_hidden_cmd,
5537 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5538 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5539 "Disable the next hop calculation for this neighbor\n"
5540 "Set the next hop to self for reflected routes\n")
5541
5542 ALIAS_HIDDEN(neighbor_nexthop_self_force,
5543 neighbor_nexthop_self_all_hidden_cmd,
5544 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5545 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5546 "Disable the next hop calculation for this neighbor\n"
5547 "Set the next hop to self for reflected routes\n")
5548
5549 DEFUN_YANG (no_neighbor_nexthop_self,
5550 no_neighbor_nexthop_self_cmd,
5551 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5552 NO_STR
5553 NEIGHBOR_STR
5554 NEIGHBOR_ADDR_STR2
5555 "Disable the next hop calculation for this neighbor\n")
5556 {
5557 int idx_peer = 2;
5558 char base_xpath[XPATH_MAXLEN];
5559 char af_xpath[XPATH_MAXLEN];
5560 char attr_xpath[XPATH_MAXLEN];
5561 afi_t afi = bgp_node_afi(vty);
5562 safi_t safi = bgp_node_safi(vty);
5563
5564 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5565 yang_afi_safi_value2identity(afi, safi));
5566
5567 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5568 sizeof(base_xpath), af_xpath)
5569 < 0)
5570 return CMD_WARNING_CONFIG_FAILED;
5571
5572 snprintf(attr_xpath, sizeof(attr_xpath),
5573 "./%s/nexthop-self/next-hop-self",
5574 bgp_afi_safi_get_container_str(afi, safi));
5575
5576 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5577
5578 return nb_cli_apply_changes(vty, base_xpath);
5579 }
5580
5581 ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
5582 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5583 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5584 "Disable the next hop calculation for this neighbor\n")
5585
5586 DEFUN_YANG (no_neighbor_nexthop_self_force,
5587 no_neighbor_nexthop_self_force_cmd,
5588 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5589 NO_STR
5590 NEIGHBOR_STR
5591 NEIGHBOR_ADDR_STR2
5592 "Disable the next hop calculation for this neighbor\n"
5593 "Set the next hop to self for reflected routes\n")
5594 {
5595 int idx_peer = 2;
5596 char base_xpath[XPATH_MAXLEN];
5597 char af_xpath[XPATH_MAXLEN];
5598 char attr_xpath[XPATH_MAXLEN];
5599 afi_t afi = bgp_node_afi(vty);
5600 safi_t safi = bgp_node_safi(vty);
5601
5602
5603 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5604 yang_afi_safi_value2identity(afi, safi));
5605
5606 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5607 sizeof(base_xpath), af_xpath)
5608 < 0)
5609 return CMD_WARNING_CONFIG_FAILED;
5610
5611 snprintf(attr_xpath, sizeof(attr_xpath),
5612 "./%s/nexthop-self/next-hop-self-force",
5613 bgp_afi_safi_get_container_str(afi, safi));
5614
5615 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5616
5617 return nb_cli_apply_changes(vty, base_xpath);
5618 }
5619
5620 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5621 no_neighbor_nexthop_self_force_hidden_cmd,
5622 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5623 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5624 "Disable the next hop calculation for this neighbor\n"
5625 "Set the next hop to self for reflected routes\n")
5626
5627 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5628 no_neighbor_nexthop_self_all_hidden_cmd,
5629 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5630 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5631 "Disable the next hop calculation for this neighbor\n"
5632 "Set the next hop to self for reflected routes\n")
5633
5634 /* neighbor as-override */
5635 DEFUN_YANG (neighbor_as_override,
5636 neighbor_as_override_cmd,
5637 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5638 NEIGHBOR_STR
5639 NEIGHBOR_ADDR_STR2
5640 "Override ASNs in outbound updates if aspath equals remote-as\n")
5641 {
5642 int idx_peer = 1;
5643 char base_xpath[XPATH_MAXLEN];
5644 char af_xpath[XPATH_MAXLEN];
5645 char attr_xpath[XPATH_MAXLEN];
5646 afi_t afi = bgp_node_afi(vty);
5647 safi_t safi = bgp_node_safi(vty);
5648
5649 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5650 yang_afi_safi_value2identity(afi, safi));
5651
5652 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5653 sizeof(base_xpath), af_xpath)
5654 < 0)
5655 return CMD_WARNING_CONFIG_FAILED;
5656
5657 snprintf(attr_xpath, sizeof(attr_xpath),
5658 "./%s/as-path-options/replace-peer-as",
5659 bgp_afi_safi_get_container_str(afi, safi));
5660
5661 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5662
5663 return nb_cli_apply_changes(vty, base_xpath);
5664 }
5665
5666 ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
5667 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5668 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5669 "Override ASNs in outbound updates if aspath equals remote-as\n")
5670
5671 DEFUN_YANG (no_neighbor_as_override,
5672 no_neighbor_as_override_cmd,
5673 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5674 NO_STR
5675 NEIGHBOR_STR
5676 NEIGHBOR_ADDR_STR2
5677 "Override ASNs in outbound updates if aspath equals remote-as\n")
5678 {
5679 int idx_peer = 2;
5680 char base_xpath[XPATH_MAXLEN];
5681 char af_xpath[XPATH_MAXLEN];
5682 char attr_xpath[XPATH_MAXLEN];
5683 afi_t afi = bgp_node_afi(vty);
5684 safi_t safi = bgp_node_safi(vty);
5685
5686 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5687 yang_afi_safi_value2identity(afi, safi));
5688
5689 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5690 sizeof(base_xpath), af_xpath)
5691 < 0)
5692 return CMD_WARNING_CONFIG_FAILED;
5693
5694 snprintf(attr_xpath, sizeof(attr_xpath),
5695 "./%s/as-path-options/replace-peer-as",
5696 bgp_afi_safi_get_container_str(afi, safi));
5697
5698 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5699
5700 return nb_cli_apply_changes(vty, base_xpath);
5701 }
5702
5703 ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
5704 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5705 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5706 "Override ASNs in outbound updates if aspath equals remote-as\n")
5707
5708 /* neighbor remove-private-AS. */
5709 DEFUN_YANG (neighbor_remove_private_as,
5710 neighbor_remove_private_as_cmd,
5711 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5712 NEIGHBOR_STR
5713 NEIGHBOR_ADDR_STR2
5714 "Remove private ASNs in outbound updates\n")
5715 {
5716 int idx_peer = 1;
5717 char base_xpath[XPATH_MAXLEN];
5718 char af_xpath[XPATH_MAXLEN];
5719 char attr_xpath[XPATH_MAXLEN];
5720 afi_t afi = bgp_node_afi(vty);
5721 safi_t safi = bgp_node_safi(vty);
5722
5723 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5724 yang_afi_safi_value2identity(afi, safi));
5725
5726 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5727 sizeof(base_xpath), af_xpath)
5728 < 0)
5729 return CMD_WARNING_CONFIG_FAILED;
5730
5731 snprintf(attr_xpath, sizeof(attr_xpath),
5732 "./%s/private-as/remove-private-as",
5733 bgp_afi_safi_get_container_str(afi, safi));
5734
5735 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5736
5737 return nb_cli_apply_changes(vty, base_xpath);
5738 }
5739
5740 ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
5741 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5742 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5743 "Remove private ASNs in outbound updates\n")
5744
5745 DEFUN_YANG (neighbor_remove_private_as_all,
5746 neighbor_remove_private_as_all_cmd,
5747 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5748 NEIGHBOR_STR
5749 NEIGHBOR_ADDR_STR2
5750 "Remove private ASNs in outbound updates\n"
5751 "Apply to all AS numbers\n")
5752 {
5753 int idx_peer = 1;
5754 char base_xpath[XPATH_MAXLEN];
5755 char af_xpath[XPATH_MAXLEN];
5756 char attr_xpath[XPATH_MAXLEN];
5757 afi_t afi = bgp_node_afi(vty);
5758 safi_t safi = bgp_node_safi(vty);
5759
5760
5761 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5762 yang_afi_safi_value2identity(afi, safi));
5763
5764 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5765 sizeof(base_xpath), af_xpath)
5766 < 0)
5767 return CMD_WARNING_CONFIG_FAILED;
5768
5769 snprintf(attr_xpath, sizeof(attr_xpath),
5770 "./%s/private-as/remove-private-as-all",
5771 bgp_afi_safi_get_container_str(afi, safi));
5772
5773 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5774
5775 return nb_cli_apply_changes(vty, base_xpath);
5776 }
5777
5778 ALIAS_HIDDEN(neighbor_remove_private_as_all,
5779 neighbor_remove_private_as_all_hidden_cmd,
5780 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5781 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5782 "Remove private ASNs in outbound updates\n"
5783 "Apply to all AS numbers")
5784
5785 DEFUN_YANG (neighbor_remove_private_as_replace_as,
5786 neighbor_remove_private_as_replace_as_cmd,
5787 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5788 NEIGHBOR_STR
5789 NEIGHBOR_ADDR_STR2
5790 "Remove private ASNs in outbound updates\n"
5791 "Replace private ASNs with our ASN in outbound updates\n")
5792 {
5793 int idx_peer = 1;
5794 char base_xpath[XPATH_MAXLEN];
5795 char af_xpath[XPATH_MAXLEN];
5796 char attr_xpath[XPATH_MAXLEN];
5797 afi_t afi = bgp_node_afi(vty);
5798 safi_t safi = bgp_node_safi(vty);
5799
5800
5801 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5802 yang_afi_safi_value2identity(afi, safi));
5803
5804 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5805 sizeof(base_xpath), af_xpath)
5806 < 0)
5807 return CMD_WARNING_CONFIG_FAILED;
5808
5809 snprintf(attr_xpath, sizeof(attr_xpath),
5810 "./%s/private-as/remove-private-as-replace",
5811 bgp_afi_safi_get_container_str(afi, safi));
5812
5813 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5814
5815 return nb_cli_apply_changes(vty, base_xpath);
5816 }
5817
5818 ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
5819 neighbor_remove_private_as_replace_as_hidden_cmd,
5820 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5821 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5822 "Remove private ASNs in outbound updates\n"
5823 "Replace private ASNs with our ASN in outbound updates\n")
5824
5825 DEFUN_YANG (neighbor_remove_private_as_all_replace_as,
5826 neighbor_remove_private_as_all_replace_as_cmd,
5827 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5828 NEIGHBOR_STR
5829 NEIGHBOR_ADDR_STR2
5830 "Remove private ASNs in outbound updates\n"
5831 "Apply to all AS numbers\n"
5832 "Replace private ASNs with our ASN in outbound updates\n")
5833 {
5834 int idx_peer = 1;
5835 char base_xpath[XPATH_MAXLEN];
5836 char af_xpath[XPATH_MAXLEN];
5837 char attr_xpath[XPATH_MAXLEN];
5838 afi_t afi = bgp_node_afi(vty);
5839 safi_t safi = bgp_node_safi(vty);
5840
5841
5842 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5843 yang_afi_safi_value2identity(afi, safi));
5844
5845 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5846 sizeof(base_xpath), af_xpath)
5847 < 0)
5848 return CMD_WARNING_CONFIG_FAILED;
5849
5850 snprintf(attr_xpath, sizeof(attr_xpath),
5851 "./%s/private-as/remove-private-as-all-replace",
5852 bgp_afi_safi_get_container_str(afi, safi));
5853
5854 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5855
5856 return nb_cli_apply_changes(vty, base_xpath);
5857 }
5858
5859 ALIAS_HIDDEN(
5860 neighbor_remove_private_as_all_replace_as,
5861 neighbor_remove_private_as_all_replace_as_hidden_cmd,
5862 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5863 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5864 "Remove private ASNs in outbound updates\n"
5865 "Apply to all AS numbers\n"
5866 "Replace private ASNs with our ASN in outbound updates\n")
5867
5868 DEFUN_YANG (no_neighbor_remove_private_as,
5869 no_neighbor_remove_private_as_cmd,
5870 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5871 NO_STR
5872 NEIGHBOR_STR
5873 NEIGHBOR_ADDR_STR2
5874 "Remove private ASNs in outbound updates\n")
5875 {
5876 int idx_peer = 2;
5877 char base_xpath[XPATH_MAXLEN];
5878 char af_xpath[XPATH_MAXLEN];
5879 char attr_xpath[XPATH_MAXLEN];
5880 afi_t afi = bgp_node_afi(vty);
5881 safi_t safi = bgp_node_safi(vty);
5882
5883 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5884 yang_afi_safi_value2identity(afi, safi));
5885
5886 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5887 sizeof(base_xpath), af_xpath)
5888 < 0)
5889 return CMD_WARNING_CONFIG_FAILED;
5890
5891 snprintf(attr_xpath, sizeof(attr_xpath),
5892 "./%s/private-as/remove-private-as",
5893 bgp_afi_safi_get_container_str(afi, safi));
5894
5895 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5896
5897 return nb_cli_apply_changes(vty, base_xpath);
5898 }
5899
5900 ALIAS_HIDDEN(no_neighbor_remove_private_as,
5901 no_neighbor_remove_private_as_hidden_cmd,
5902 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5903 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5904 "Remove private ASNs in outbound updates\n")
5905
5906 DEFUN_YANG (no_neighbor_remove_private_as_all,
5907 no_neighbor_remove_private_as_all_cmd,
5908 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5909 NO_STR
5910 NEIGHBOR_STR
5911 NEIGHBOR_ADDR_STR2
5912 "Remove private ASNs in outbound updates\n"
5913 "Apply to all AS numbers\n")
5914 {
5915 int idx_peer = 2;
5916 char base_xpath[XPATH_MAXLEN];
5917 char af_xpath[XPATH_MAXLEN];
5918 char attr_xpath[XPATH_MAXLEN];
5919 afi_t afi = bgp_node_afi(vty);
5920 safi_t safi = bgp_node_safi(vty);
5921
5922
5923 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5924 yang_afi_safi_value2identity(afi, safi));
5925
5926 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5927 sizeof(base_xpath), af_xpath)
5928 < 0)
5929 return CMD_WARNING_CONFIG_FAILED;
5930
5931 snprintf(attr_xpath, sizeof(attr_xpath),
5932 "./%s/private-as/remove-private-as-all",
5933 bgp_afi_safi_get_container_str(afi, safi));
5934
5935 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5936
5937 return nb_cli_apply_changes(vty, base_xpath);
5938 }
5939
5940 ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
5941 no_neighbor_remove_private_as_all_hidden_cmd,
5942 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5943 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5944 "Remove private ASNs in outbound updates\n"
5945 "Apply to all AS numbers\n")
5946
5947 DEFUN_YANG (no_neighbor_remove_private_as_replace_as,
5948 no_neighbor_remove_private_as_replace_as_cmd,
5949 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5950 NO_STR
5951 NEIGHBOR_STR
5952 NEIGHBOR_ADDR_STR2
5953 "Remove private ASNs in outbound updates\n"
5954 "Replace private ASNs with our ASN in outbound updates\n")
5955 {
5956 int idx_peer = 2;
5957 char base_xpath[XPATH_MAXLEN];
5958 char af_xpath[XPATH_MAXLEN];
5959 char attr_xpath[XPATH_MAXLEN];
5960 afi_t afi = bgp_node_afi(vty);
5961 safi_t safi = bgp_node_safi(vty);
5962
5963
5964 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5965 yang_afi_safi_value2identity(afi, safi));
5966
5967 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5968 sizeof(base_xpath), af_xpath)
5969 < 0)
5970 return CMD_WARNING_CONFIG_FAILED;
5971
5972 snprintf(attr_xpath, sizeof(attr_xpath),
5973 "./%s/private-as/remove-private-as-replace",
5974 bgp_afi_safi_get_container_str(afi, safi));
5975
5976 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5977
5978 return nb_cli_apply_changes(vty, base_xpath);
5979 }
5980
5981 ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
5982 no_neighbor_remove_private_as_replace_as_hidden_cmd,
5983 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5984 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5985 "Remove private ASNs in outbound updates\n"
5986 "Replace private ASNs with our ASN in outbound updates\n")
5987
5988 DEFUN_YANG (no_neighbor_remove_private_as_all_replace_as,
5989 no_neighbor_remove_private_as_all_replace_as_cmd,
5990 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5991 NO_STR
5992 NEIGHBOR_STR
5993 NEIGHBOR_ADDR_STR2
5994 "Remove private ASNs in outbound updates\n"
5995 "Apply to all AS numbers\n"
5996 "Replace private ASNs with our ASN in outbound updates\n")
5997 {
5998 int idx_peer = 2;
5999 char base_xpath[XPATH_MAXLEN];
6000 char af_xpath[XPATH_MAXLEN];
6001 char attr_xpath[XPATH_MAXLEN];
6002 afi_t afi = bgp_node_afi(vty);
6003 safi_t safi = bgp_node_safi(vty);
6004
6005
6006 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6007 yang_afi_safi_value2identity(afi, safi));
6008
6009 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6010 sizeof(base_xpath), af_xpath)
6011 < 0)
6012 return CMD_WARNING_CONFIG_FAILED;
6013
6014 snprintf(attr_xpath, sizeof(attr_xpath),
6015 "./%s/private-as/remove-private-as-all-replace",
6016 bgp_afi_safi_get_container_str(afi, safi));
6017
6018 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6019
6020 return nb_cli_apply_changes(vty, base_xpath);
6021 }
6022
6023 ALIAS_HIDDEN(
6024 no_neighbor_remove_private_as_all_replace_as,
6025 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
6026 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
6027 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6028 "Remove private ASNs in outbound updates\n"
6029 "Apply to all AS numbers\n"
6030 "Replace private ASNs with our ASN in outbound updates\n")
6031
6032
6033 /* neighbor send-community. */
6034 DEFUN_YANG (neighbor_send_community,
6035 neighbor_send_community_cmd,
6036 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6037 NEIGHBOR_STR
6038 NEIGHBOR_ADDR_STR2
6039 "Send Community attribute to this neighbor\n")
6040 {
6041 int idx_peer = 1;
6042
6043 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6044 bgp_node_safi(vty),
6045 PEER_FLAG_SEND_COMMUNITY);
6046 }
6047
6048 ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
6049 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6050 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6051 "Send Community attribute to this neighbor\n")
6052
6053 DEFUN_YANG (no_neighbor_send_community,
6054 no_neighbor_send_community_cmd,
6055 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6056 NO_STR
6057 NEIGHBOR_STR
6058 NEIGHBOR_ADDR_STR2
6059 "Send Community attribute to this neighbor\n")
6060 {
6061 int idx_peer = 2;
6062
6063 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6064 bgp_node_afi(vty), bgp_node_safi(vty),
6065 PEER_FLAG_SEND_COMMUNITY);
6066 }
6067
6068 ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
6069 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6070 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6071 "Send Community attribute to this neighbor\n")
6072
6073 /* neighbor send-community extended. */
6074 DEFUN_YANG (neighbor_send_community_type,
6075 neighbor_send_community_type_cmd,
6076 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6077 NEIGHBOR_STR
6078 NEIGHBOR_ADDR_STR2
6079 "Send Community attribute to this neighbor\n"
6080 "Send Standard and Extended Community attributes\n"
6081 "Send Standard, Large and Extended Community attributes\n"
6082 "Send Extended Community attributes\n"
6083 "Send Standard Community attributes\n"
6084 "Send Large Community attributes\n")
6085 {
6086 const char *type = argv[argc - 1]->text;
6087 char *peer_str = argv[1]->arg;
6088 char base_xpath[XPATH_MAXLEN];
6089 char af_xpath[XPATH_MAXLEN];
6090 char std_xpath[XPATH_MAXLEN];
6091 char ext_xpath[XPATH_MAXLEN];
6092 char lrg_xpath[XPATH_MAXLEN];
6093 afi_t afi = bgp_node_afi(vty);
6094 safi_t safi = bgp_node_safi(vty);
6095
6096 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6097 yang_afi_safi_value2identity(afi, safi));
6098
6099 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6100 sizeof(base_xpath), af_xpath)
6101 < 0)
6102 return CMD_WARNING_CONFIG_FAILED;
6103
6104 if (strmatch(type, "standard")) {
6105 snprintf(std_xpath, sizeof(std_xpath),
6106 "./%s/send-community/send-community",
6107 bgp_afi_safi_get_container_str(afi, safi));
6108
6109 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "true");
6110 }
6111
6112 if (strmatch(type, "extended")) {
6113 snprintf(ext_xpath, sizeof(ext_xpath),
6114 "./%s/send-community/send-ext-community",
6115 bgp_afi_safi_get_container_str(afi, safi));
6116
6117 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "true");
6118 }
6119
6120 if (strmatch(type, "large")) {
6121 snprintf(lrg_xpath, sizeof(lrg_xpath),
6122 "./%s/send-community/send-large-community",
6123 bgp_afi_safi_get_container_str(afi, safi));
6124
6125 nb_cli_enqueue_change(vty, lrg_xpath, NB_OP_MODIFY, "true");
6126 }
6127
6128 if (strmatch(type, "both")) {
6129 snprintf(std_xpath, sizeof(std_xpath),
6130 "./%s/send-community/send-community",
6131 bgp_afi_safi_get_container_str(afi, safi));
6132
6133 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "true");
6134
6135 snprintf(ext_xpath, sizeof(ext_xpath),
6136 "./%s/send-community/send-ext-community",
6137 bgp_afi_safi_get_container_str(afi, safi));
6138
6139 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "true");
6140 }
6141
6142 if (strmatch(type, "all")) {
6143 snprintf(std_xpath, sizeof(std_xpath),
6144 "./%s/send-community/send-community",
6145 bgp_afi_safi_get_container_str(afi, safi));
6146
6147 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "true");
6148
6149 snprintf(ext_xpath, sizeof(ext_xpath),
6150 "./%s/send-community/send-ext-community",
6151 bgp_afi_safi_get_container_str(afi, safi));
6152
6153 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "true");
6154
6155 snprintf(lrg_xpath, sizeof(lrg_xpath),
6156 "./%s/send-community/send-large-community",
6157 bgp_afi_safi_get_container_str(afi, safi));
6158
6159 nb_cli_enqueue_change(vty, lrg_xpath, NB_OP_MODIFY, "true");
6160 }
6161
6162 return nb_cli_apply_changes(vty, base_xpath);
6163 }
6164
6165 ALIAS_HIDDEN(
6166 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
6167 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6168 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6169 "Send Community attribute to this neighbor\n"
6170 "Send Standard and Extended Community attributes\n"
6171 "Send Standard, Large and Extended Community attributes\n"
6172 "Send Extended Community attributes\n"
6173 "Send Standard Community attributes\n"
6174 "Send Large Community attributes\n")
6175
6176 DEFUN_YANG (no_neighbor_send_community_type,
6177 no_neighbor_send_community_type_cmd,
6178 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6179 NO_STR
6180 NEIGHBOR_STR
6181 NEIGHBOR_ADDR_STR2
6182 "Send Community attribute to this neighbor\n"
6183 "Send Standard and Extended Community attributes\n"
6184 "Send Standard, Large and Extended Community attributes\n"
6185 "Send Extended Community attributes\n"
6186 "Send Standard Community attributes\n"
6187 "Send Large Community attributes\n")
6188 {
6189 const char *type = argv[argc - 1]->text;
6190 char *peer_str = argv[2]->arg;
6191 char base_xpath[XPATH_MAXLEN];
6192 char af_xpath[XPATH_MAXLEN];
6193 char std_xpath[XPATH_MAXLEN];
6194 char ext_xpath[XPATH_MAXLEN];
6195 char lrg_xpath[XPATH_MAXLEN];
6196 afi_t afi = bgp_node_afi(vty);
6197 safi_t safi = bgp_node_safi(vty);
6198
6199 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6200 yang_afi_safi_value2identity(afi, safi));
6201
6202 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6203 sizeof(base_xpath), af_xpath)
6204 < 0)
6205 return CMD_WARNING_CONFIG_FAILED;
6206
6207 if (strmatch(type, "standard")) {
6208 snprintf(std_xpath, sizeof(std_xpath),
6209 "./%s/send-community/send-community",
6210 bgp_afi_safi_get_container_str(afi, safi));
6211
6212 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "false");
6213 }
6214
6215 if (strmatch(type, "extended")) {
6216 snprintf(ext_xpath, sizeof(ext_xpath),
6217 "./%s/send-community/send-ext-community",
6218 bgp_afi_safi_get_container_str(afi, safi));
6219
6220 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "false");
6221 }
6222
6223 if (strmatch(type, "large")) {
6224 snprintf(lrg_xpath, sizeof(lrg_xpath),
6225 "./%s/send-community/send-large-community",
6226 bgp_afi_safi_get_container_str(afi, safi));
6227
6228 nb_cli_enqueue_change(vty, lrg_xpath, NB_OP_MODIFY, "false");
6229 }
6230
6231 if (strmatch(type, "both")) {
6232 snprintf(std_xpath, sizeof(std_xpath),
6233 "./%s/send-community/send-community",
6234 bgp_afi_safi_get_container_str(afi, safi));
6235
6236 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "false");
6237
6238 snprintf(ext_xpath, sizeof(ext_xpath),
6239 "./%s/send-community/send-ext-community",
6240 bgp_afi_safi_get_container_str(afi, safi));
6241
6242 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "false");
6243 }
6244
6245 if (strmatch(type, "all")) {
6246 snprintf(std_xpath, sizeof(std_xpath),
6247 "./%s/send-community/send-community",
6248 bgp_afi_safi_get_container_str(afi, safi));
6249
6250 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "false");
6251
6252 snprintf(ext_xpath, sizeof(ext_xpath),
6253 "./%s/send-community/send-ext-community",
6254 bgp_afi_safi_get_container_str(afi, safi));
6255
6256 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "false");
6257
6258 snprintf(lrg_xpath, sizeof(lrg_xpath),
6259 "./%s/send-community/send-large-community",
6260 bgp_afi_safi_get_container_str(afi, safi));
6261
6262 nb_cli_enqueue_change(vty, lrg_xpath, NB_OP_MODIFY, "false");
6263 }
6264
6265 return nb_cli_apply_changes(vty, base_xpath);
6266 }
6267
6268 ALIAS_HIDDEN(
6269 no_neighbor_send_community_type,
6270 no_neighbor_send_community_type_hidden_cmd,
6271 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6272 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6273 "Send Community attribute to this neighbor\n"
6274 "Send Standard and Extended Community attributes\n"
6275 "Send Standard, Large and Extended Community attributes\n"
6276 "Send Extended Community attributes\n"
6277 "Send Standard Community attributes\n"
6278 "Send Large Community attributes\n")
6279
6280 /* neighbor soft-reconfig. */
6281 DEFUN_YANG (neighbor_soft_reconfiguration,
6282 neighbor_soft_reconfiguration_cmd,
6283 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6284 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6285 "Per neighbor soft reconfiguration\n"
6286 "Allow inbound soft reconfiguration for this neighbor\n")
6287 {
6288 int idx_peer = 1;
6289 char base_xpath[XPATH_MAXLEN];
6290 char af_xpath[XPATH_MAXLEN];
6291 char soft_xpath[XPATH_MAXLEN];
6292 afi_t afi = bgp_node_afi(vty);
6293 safi_t safi = bgp_node_safi(vty);
6294
6295
6296 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6297 yang_afi_safi_value2identity(afi, safi));
6298
6299 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6300 sizeof(base_xpath), af_xpath)
6301 < 0)
6302 return CMD_WARNING_CONFIG_FAILED;
6303
6304 snprintf(soft_xpath, sizeof(soft_xpath), "./%s/soft-reconfiguration",
6305 bgp_afi_safi_get_container_str(afi, safi));
6306
6307 nb_cli_enqueue_change(vty, soft_xpath, NB_OP_MODIFY, "true");
6308
6309 return nb_cli_apply_changes(vty, base_xpath);
6310 }
6311
6312 ALIAS_HIDDEN(neighbor_soft_reconfiguration,
6313 neighbor_soft_reconfiguration_hidden_cmd,
6314 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6315 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6316 "Per neighbor soft reconfiguration\n"
6317 "Allow inbound soft reconfiguration for this neighbor\n")
6318
6319 DEFUN_YANG (no_neighbor_soft_reconfiguration,
6320 no_neighbor_soft_reconfiguration_cmd,
6321 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6322 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6323 "Per neighbor soft reconfiguration\n"
6324 "Allow inbound soft reconfiguration for this neighbor\n")
6325 {
6326 int idx_peer = 2;
6327 char base_xpath[XPATH_MAXLEN];
6328 char af_xpath[XPATH_MAXLEN];
6329 char soft_xpath[XPATH_MAXLEN];
6330 afi_t afi = bgp_node_afi(vty);
6331 safi_t safi = bgp_node_safi(vty);
6332
6333 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6334 yang_afi_safi_value2identity(afi, safi));
6335
6336 snprintf(soft_xpath, sizeof(soft_xpath), "./%s/soft-reconfiguration",
6337 bgp_afi_safi_get_container_str(afi, safi));
6338
6339 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6340 sizeof(base_xpath), af_xpath)
6341 < 0)
6342 return CMD_WARNING_CONFIG_FAILED;
6343
6344 nb_cli_enqueue_change(vty, soft_xpath, NB_OP_MODIFY, "false");
6345
6346 return nb_cli_apply_changes(vty, base_xpath);
6347 }
6348
6349 ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
6350 no_neighbor_soft_reconfiguration_hidden_cmd,
6351 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6352 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6353 "Per neighbor soft reconfiguration\n"
6354 "Allow inbound soft reconfiguration for this neighbor\n")
6355
6356 DEFUN_YANG (neighbor_route_reflector_client,
6357 neighbor_route_reflector_client_cmd,
6358 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6359 NEIGHBOR_STR
6360 NEIGHBOR_ADDR_STR2
6361 "Configure a neighbor as Route Reflector client\n")
6362 {
6363 int idx_peer = 1;
6364 char base_xpath[XPATH_MAXLEN];
6365 char af_xpath[XPATH_MAXLEN];
6366 char attr_xpath[XPATH_MAXLEN];
6367 afi_t afi = bgp_node_afi(vty);
6368 safi_t safi = bgp_node_safi(vty);
6369
6370 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6371 yang_afi_safi_value2identity(afi, safi));
6372
6373 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6374 sizeof(base_xpath), af_xpath)
6375 < 0)
6376 return CMD_WARNING_CONFIG_FAILED;
6377
6378 snprintf(attr_xpath, sizeof(attr_xpath),
6379 "./%s/route-reflector/route-reflector-client",
6380 bgp_afi_safi_get_container_str(afi, safi));
6381
6382 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
6383
6384 return nb_cli_apply_changes(vty, base_xpath);
6385 }
6386
6387 ALIAS_HIDDEN(neighbor_route_reflector_client,
6388 neighbor_route_reflector_client_hidden_cmd,
6389 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6390 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6391 "Configure a neighbor as Route Reflector client\n")
6392
6393 DEFUN_YANG (no_neighbor_route_reflector_client,
6394 no_neighbor_route_reflector_client_cmd,
6395 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6396 NO_STR
6397 NEIGHBOR_STR
6398 NEIGHBOR_ADDR_STR2
6399 "Configure a neighbor as Route Reflector client\n")
6400 {
6401 int idx_peer = 2;
6402 char base_xpath[XPATH_MAXLEN];
6403 char af_xpath[XPATH_MAXLEN];
6404 char attr_xpath[XPATH_MAXLEN];
6405 afi_t afi = bgp_node_afi(vty);
6406 safi_t safi = bgp_node_safi(vty);
6407
6408 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6409 yang_afi_safi_value2identity(afi, safi));
6410
6411 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6412 sizeof(base_xpath), af_xpath)
6413 < 0)
6414 return CMD_WARNING_CONFIG_FAILED;
6415
6416 snprintf(attr_xpath, sizeof(attr_xpath),
6417 "./%s/route-reflector/route-reflector-client",
6418 bgp_afi_safi_get_container_str(afi, safi));
6419
6420 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6421
6422 return nb_cli_apply_changes(vty, base_xpath);
6423 }
6424
6425 ALIAS_HIDDEN(no_neighbor_route_reflector_client,
6426 no_neighbor_route_reflector_client_hidden_cmd,
6427 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6428 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6429 "Configure a neighbor as Route Reflector client\n")
6430
6431 /* neighbor route-server-client. */
6432 DEFUN_YANG (neighbor_route_server_client,
6433 neighbor_route_server_client_cmd,
6434 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6435 NEIGHBOR_STR
6436 NEIGHBOR_ADDR_STR2
6437 "Configure a neighbor as Route Server client\n")
6438 {
6439 int idx_peer = 1;
6440 char base_xpath[XPATH_MAXLEN];
6441 char af_xpath[XPATH_MAXLEN];
6442 char attr_xpath[XPATH_MAXLEN];
6443 afi_t afi = bgp_node_afi(vty);
6444 safi_t safi = bgp_node_safi(vty);
6445
6446 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6447 yang_afi_safi_value2identity(afi, safi));
6448
6449 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6450 sizeof(base_xpath), af_xpath)
6451 < 0)
6452 return CMD_WARNING_CONFIG_FAILED;
6453
6454 snprintf(attr_xpath, sizeof(attr_xpath),
6455 "./%s/route-server/route-server-client",
6456 bgp_afi_safi_get_container_str(afi, safi));
6457
6458 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
6459
6460 return nb_cli_apply_changes(vty, base_xpath);
6461 }
6462
6463 ALIAS_HIDDEN(neighbor_route_server_client,
6464 neighbor_route_server_client_hidden_cmd,
6465 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6466 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6467 "Configure a neighbor as Route Server client\n")
6468
6469 DEFUN_YANG (no_neighbor_route_server_client,
6470 no_neighbor_route_server_client_cmd,
6471 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6472 NO_STR
6473 NEIGHBOR_STR
6474 NEIGHBOR_ADDR_STR2
6475 "Configure a neighbor as Route Server client\n")
6476 {
6477 int idx_peer = 2;
6478 char base_xpath[XPATH_MAXLEN];
6479 char af_xpath[XPATH_MAXLEN];
6480 char attr_xpath[XPATH_MAXLEN];
6481 afi_t afi = bgp_node_afi(vty);
6482 safi_t safi = bgp_node_safi(vty);
6483
6484 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6485 yang_afi_safi_value2identity(afi, safi));
6486
6487 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6488 sizeof(base_xpath), af_xpath)
6489 < 0)
6490 return CMD_WARNING_CONFIG_FAILED;
6491
6492 snprintf(attr_xpath, sizeof(attr_xpath),
6493 "./%s/route-server/route-server-client",
6494 bgp_afi_safi_get_container_str(afi, safi));
6495
6496 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6497
6498 return nb_cli_apply_changes(vty, base_xpath);
6499 }
6500
6501 ALIAS_HIDDEN(no_neighbor_route_server_client,
6502 no_neighbor_route_server_client_hidden_cmd,
6503 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6504 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6505 "Configure a neighbor as Route Server client\n")
6506
6507 DEFUN (neighbor_nexthop_local_unchanged,
6508 neighbor_nexthop_local_unchanged_cmd,
6509 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
6510 NEIGHBOR_STR
6511 NEIGHBOR_ADDR_STR2
6512 "Configure treatment of outgoing link-local nexthop attribute\n"
6513 "Leave link-local nexthop unchanged for this peer\n")
6514 {
6515 int idx_peer = 1;
6516 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6517 bgp_node_safi(vty),
6518 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
6519 }
6520
6521 DEFUN (no_neighbor_nexthop_local_unchanged,
6522 no_neighbor_nexthop_local_unchanged_cmd,
6523 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
6524 NO_STR
6525 NEIGHBOR_STR
6526 NEIGHBOR_ADDR_STR2
6527 "Configure treatment of outgoing link-local-nexthop attribute\n"
6528 "Leave link-local nexthop unchanged for this peer\n")
6529 {
6530 int idx_peer = 2;
6531 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6532 bgp_node_afi(vty), bgp_node_safi(vty),
6533 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
6534 }
6535
6536 DEFUN_YANG (neighbor_attr_unchanged,
6537 neighbor_attr_unchanged_cmd,
6538 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6539 NEIGHBOR_STR
6540 NEIGHBOR_ADDR_STR2
6541 "BGP attribute is propagated unchanged to this neighbor\n"
6542 "As-path attribute\n"
6543 "Nexthop attribute\n"
6544 "Med attribute\n")
6545 {
6546 int idx = 0;
6547 char *peer_str = argv[1]->arg;
6548 bool aspath = false;
6549 bool nexthop = false;
6550 bool med = false;
6551 afi_t afi = bgp_node_afi(vty);
6552 safi_t safi = bgp_node_safi(vty);
6553 char base_xpath[XPATH_MAXLEN];
6554 char af_xpath[XPATH_MAXLEN];
6555 char as_xpath[XPATH_MAXLEN];
6556 char nxthop_xpath[XPATH_MAXLEN];
6557 char med_xpath[XPATH_MAXLEN];
6558
6559 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6560 yang_afi_safi_value2identity(afi, safi));
6561
6562 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6563 sizeof(base_xpath), af_xpath)
6564 < 0)
6565 return CMD_WARNING_CONFIG_FAILED;
6566
6567 if (argv_find(argv, argc, "as-path", &idx))
6568 aspath = true;
6569
6570 idx = 0;
6571 if (argv_find(argv, argc, "next-hop", &idx))
6572 nexthop = true;
6573
6574 idx = 0;
6575 if (argv_find(argv, argc, "med", &idx))
6576 med = true;
6577
6578 snprintf(as_xpath, sizeof(as_xpath),
6579 "./%s/attr-unchanged/as-path-unchanged",
6580 bgp_afi_safi_get_container_str(afi, safi));
6581 snprintf(nxthop_xpath, sizeof(nxthop_xpath),
6582 "./%s/attr-unchanged/next-hop-unchanged",
6583 bgp_afi_safi_get_container_str(afi, safi));
6584 snprintf(med_xpath, sizeof(med_xpath),
6585 "./%s/attr-unchanged/med-unchanged",
6586 bgp_afi_safi_get_container_str(afi, safi));
6587
6588 /* no flags means all of them! */
6589 if (!aspath && !nexthop && !med) {
6590 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY, "true");
6591 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY, "true");
6592 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY, "true");
6593 } else {
6594 if (!aspath)
6595 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY,
6596 "false");
6597 else
6598 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY,
6599 "true");
6600
6601 if (!nexthop)
6602 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY,
6603 "false");
6604 else
6605 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY,
6606 "true");
6607
6608 if (!med)
6609 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY,
6610 "false");
6611 else
6612 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY,
6613 "true");
6614 }
6615
6616 return nb_cli_apply_changes(vty, base_xpath);
6617 }
6618
6619 ALIAS_HIDDEN(
6620 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
6621 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6622 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6623 "BGP attribute is propagated unchanged to this neighbor\n"
6624 "As-path attribute\n"
6625 "Nexthop attribute\n"
6626 "Med attribute\n")
6627
6628 DEFUN_YANG (no_neighbor_attr_unchanged,
6629 no_neighbor_attr_unchanged_cmd,
6630 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6631 NO_STR
6632 NEIGHBOR_STR
6633 NEIGHBOR_ADDR_STR2
6634 "BGP attribute is propagated unchanged to this neighbor\n"
6635 "As-path attribute\n"
6636 "Nexthop attribute\n"
6637 "Med attribute\n")
6638 {
6639 int idx = 0;
6640 char *peer_str = argv[2]->arg;
6641 bool aspath = false;
6642 bool nexthop = false;
6643 bool med = false;
6644 afi_t afi = bgp_node_afi(vty);
6645 safi_t safi = bgp_node_safi(vty);
6646 char base_xpath[XPATH_MAXLEN];
6647 char af_xpath[XPATH_MAXLEN];
6648 char as_xpath[XPATH_MAXLEN];
6649 char nxthop_xpath[XPATH_MAXLEN];
6650 char med_xpath[XPATH_MAXLEN];
6651
6652 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6653 yang_afi_safi_value2identity(afi, safi));
6654
6655 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6656 sizeof(base_xpath), af_xpath)
6657 < 0)
6658 return CMD_WARNING_CONFIG_FAILED;
6659
6660 if (argv_find(argv, argc, "as-path", &idx))
6661 aspath = true;
6662
6663 idx = 0;
6664 if (argv_find(argv, argc, "next-hop", &idx))
6665 nexthop = true;
6666
6667 idx = 0;
6668 if (argv_find(argv, argc, "med", &idx))
6669 med = true;
6670
6671 snprintf(as_xpath, sizeof(as_xpath),
6672 "./%s/attr-unchanged/as-path-unchanged",
6673 bgp_afi_safi_get_container_str(afi, safi));
6674 snprintf(nxthop_xpath, sizeof(nxthop_xpath),
6675 "./%s/attr-unchanged/next-hop-unchanged",
6676 bgp_afi_safi_get_container_str(afi, safi));
6677 snprintf(med_xpath, sizeof(med_xpath),
6678 "./%s/attr-unchanged/med-unchanged",
6679 bgp_afi_safi_get_container_str(afi, safi));
6680
6681 /* no flags means all of them! */
6682 if (!aspath && !nexthop && !med) {
6683 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY, "false");
6684 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY, "false");
6685 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY, "false");
6686 }
6687
6688 if (aspath)
6689 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY, "false");
6690
6691 if (nexthop)
6692 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY, "false");
6693
6694 if (med)
6695 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY, "false");
6696
6697 return nb_cli_apply_changes(vty, base_xpath);
6698 }
6699
6700 ALIAS_HIDDEN(
6701 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
6702 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6703 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6704 "BGP attribute is propagated unchanged to this neighbor\n"
6705 "As-path attribute\n"
6706 "Nexthop attribute\n"
6707 "Med attribute\n")
6708
6709 /* neighbor ebgp-multihop. */
6710 DEFUN_YANG (neighbor_ebgp_multihop,
6711 neighbor_ebgp_multihop_cmd,
6712 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
6713 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6714 "Allow EBGP neighbors not on directly connected networks\n")
6715 {
6716 int idx_peer = 1;
6717 char base_xpath[XPATH_MAXLEN];
6718
6719 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6720 sizeof(base_xpath), NULL)
6721 < 0)
6722 return CMD_WARNING_CONFIG_FAILED;
6723
6724 nb_cli_enqueue_change(vty, "./ebgp-multihop/enabled", NB_OP_MODIFY,
6725 "true");
6726
6727 return nb_cli_apply_changes(vty, base_xpath);
6728 }
6729
6730 DEFUN_YANG (neighbor_ebgp_multihop_ttl,
6731 neighbor_ebgp_multihop_ttl_cmd,
6732 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
6733 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6734 "Allow EBGP neighbors not on directly connected networks\n"
6735 "maximum hop count\n")
6736 {
6737 int idx_peer = 1;
6738 int idx_number = 3;
6739 char base_xpath[XPATH_MAXLEN];
6740
6741 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6742 sizeof(base_xpath), NULL)
6743 < 0)
6744 return CMD_WARNING_CONFIG_FAILED;
6745
6746 nb_cli_enqueue_change(vty, "./ebgp-multihop/multihop-ttl", NB_OP_MODIFY,
6747 argv[idx_number]->arg);
6748
6749 return nb_cli_apply_changes(vty, base_xpath);
6750 }
6751
6752 DEFUN_YANG (no_neighbor_ebgp_multihop,
6753 no_neighbor_ebgp_multihop_cmd,
6754 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
6755 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6756 "Allow EBGP neighbors not on directly connected networks\n"
6757 "maximum hop count\n")
6758 {
6759 int idx_peer = 2;
6760 char base_xpath[XPATH_MAXLEN];
6761
6762 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6763 sizeof(base_xpath), NULL)
6764 < 0)
6765 return CMD_WARNING_CONFIG_FAILED;
6766
6767 if (argc > 4)
6768 nb_cli_enqueue_change(vty, "./ebgp-multihop/multihop-ttl",
6769 NB_OP_DESTROY, NULL);
6770 else
6771 nb_cli_enqueue_change(vty, "./ebgp-multihop/enabled",
6772 NB_OP_MODIFY, "false");
6773
6774 return nb_cli_apply_changes(vty, base_xpath);
6775 }
6776
6777
6778 /* disable-connected-check */
6779 DEFUN_YANG (neighbor_disable_connected_check,
6780 neighbor_disable_connected_check_cmd,
6781 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6782 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6783 "one-hop away EBGP peer using loopback address\n"
6784 "Enforce EBGP neighbors perform multihop\n")
6785 {
6786 int idx_peer = 1;
6787 char base_xpath[XPATH_MAXLEN];
6788
6789 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6790 sizeof(base_xpath), NULL)
6791 < 0)
6792 return CMD_WARNING_CONFIG_FAILED;
6793
6794 nb_cli_enqueue_change(vty, "./ebgp-multihop/disable-connected-check",
6795 NB_OP_MODIFY, "true");
6796
6797 return nb_cli_apply_changes(vty, base_xpath);
6798 }
6799
6800 DEFUN_YANG (no_neighbor_disable_connected_check,
6801 no_neighbor_disable_connected_check_cmd,
6802 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6803 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6804 "one-hop away EBGP peer using loopback address\n"
6805 "Enforce EBGP neighbors perform multihop\n")
6806 {
6807 int idx_peer = 2;
6808 char base_xpath[XPATH_MAXLEN];
6809
6810 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6811 sizeof(base_xpath), NULL)
6812 < 0)
6813 return CMD_WARNING_CONFIG_FAILED;
6814
6815 nb_cli_enqueue_change(vty, "./ebgp-multihop/disable-connected-check",
6816 NB_OP_MODIFY, "false");
6817
6818 return nb_cli_apply_changes(vty, base_xpath);
6819 }
6820
6821
6822 /* enforce-first-as */
6823 DEFUN_YANG (neighbor_enforce_first_as,
6824 neighbor_enforce_first_as_cmd,
6825 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6826 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6827 "Enforce the first AS for EBGP routes\n")
6828 {
6829 int idx_peer = 1;
6830 char base_xpath[XPATH_MAXLEN];
6831
6832 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6833 sizeof(base_xpath), NULL)
6834 < 0)
6835 return CMD_WARNING_CONFIG_FAILED;
6836
6837 nb_cli_enqueue_change(vty, "./enforce-first-as", NB_OP_MODIFY, "true");
6838
6839 return nb_cli_apply_changes(vty, base_xpath);
6840 }
6841
6842 DEFUN_YANG (no_neighbor_enforce_first_as,
6843 no_neighbor_enforce_first_as_cmd,
6844 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6845 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6846 "Enforce the first AS for EBGP routes\n")
6847 {
6848 int idx_peer = 2;
6849 char base_xpath[XPATH_MAXLEN];
6850
6851 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6852 sizeof(base_xpath), NULL)
6853 < 0)
6854 return CMD_WARNING_CONFIG_FAILED;
6855
6856 nb_cli_enqueue_change(vty, "./enforce-first-as", NB_OP_MODIFY, "false");
6857
6858 return nb_cli_apply_changes(vty, base_xpath);
6859 }
6860
6861 static int peer_and_group_lookup_nb(struct vty *vty, const char *peer_str,
6862 char *base_xpath, int xpath_len,
6863 char *xpath)
6864 {
6865 union sockunion su;
6866 char num_xpath[XPATH_MAXLEN];
6867 char unnbr_xpath[XPATH_MAXLEN];
6868 char prgrp_xpath[XPATH_MAXLEN];
6869
6870 if (str2sockunion(peer_str, &su) == 0) {
6871 snprintf(num_xpath, sizeof(num_xpath),
6872 "/neighbors/neighbor[remote-address='%s']", peer_str);
6873 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
6874 VTY_CURR_XPATH, num_xpath)) {
6875 snprintf(base_xpath, xpath_len,
6876 FRR_BGP_NEIGHBOR_NUM_XPATH, peer_str,
6877 xpath ? xpath : "");
6878 } else {
6879 vty_out(vty,
6880 "%% Specify remote-as or peer-group commands first\n");
6881 return -1;
6882 }
6883
6884 } else {
6885 snprintf(unnbr_xpath, sizeof(unnbr_xpath),
6886 "/neighbors/unnumbered-neighbor[interface='%s']",
6887 peer_str);
6888
6889 snprintf(prgrp_xpath, sizeof(prgrp_xpath),
6890 "/peer-groups/peer-group[peer-group-name='%s']",
6891 peer_str);
6892
6893 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
6894 VTY_CURR_XPATH, unnbr_xpath)) {
6895 snprintf(base_xpath, xpath_len,
6896 FRR_BGP_NEIGHBOR_UNNUM_XPATH, peer_str,
6897 xpath ? xpath : "");
6898 } else if (yang_dnode_exists(vty->candidate_config->dnode,
6899 "%s%s", VTY_CURR_XPATH,
6900 prgrp_xpath)) {
6901 snprintf(base_xpath, xpath_len,
6902 FRR_BGP_PEER_GROUP_XPATH, peer_str,
6903 xpath ? xpath : "");
6904 } else {
6905 vty_out(vty,
6906 "%% Create the peer-group or interface first\n");
6907 return -1;
6908 }
6909 }
6910
6911 return 0;
6912 }
6913
6914 DEFUN_YANG (neighbor_description,
6915 neighbor_description_cmd,
6916 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6917 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6918 "Neighbor specific description\n"
6919 "Up to 80 characters describing this neighbor\n")
6920 {
6921 int idx_peer = 1;
6922 int idx_line = 3;
6923 int ret;
6924 char base_xpath[XPATH_MAXLEN];
6925 char *str;
6926
6927 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6928 sizeof(base_xpath), NULL)
6929 < 0)
6930 return CMD_WARNING_CONFIG_FAILED;
6931
6932 str = argv_concat(argv, argc, idx_line);
6933
6934 nb_cli_enqueue_change(vty, "./description", NB_OP_MODIFY, str);
6935
6936 ret = nb_cli_apply_changes(vty, base_xpath);
6937
6938 XFREE(MTYPE_TMP, str);
6939
6940 return ret;
6941 }
6942
6943 DEFUN_YANG (no_neighbor_description,
6944 no_neighbor_description_cmd,
6945 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
6946 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6947 "Neighbor specific description\n")
6948 {
6949 int idx_peer = 2;
6950 char base_xpath[XPATH_MAXLEN];
6951
6952 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6953 sizeof(base_xpath), NULL)
6954 < 0)
6955 return CMD_WARNING_CONFIG_FAILED;
6956
6957 nb_cli_enqueue_change(vty, "./description", NB_OP_DESTROY, NULL);
6958
6959 return nb_cli_apply_changes(vty, base_xpath);
6960 }
6961
6962 ALIAS_YANG(no_neighbor_description, no_neighbor_description_comment_cmd,
6963 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6964 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6965 "Neighbor specific description\n"
6966 "Up to 80 characters describing this neighbor\n")
6967
6968 #define BGP_UPDATE_SOURCE_HELP_STR \
6969 "IPv4 address\n" \
6970 "IPv6 address\n" \
6971 "Interface name (requires zebra to be running)\n"
6972
6973 DEFUN_YANG (neighbor_update_source,
6974 neighbor_update_source_cmd,
6975 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
6976 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6977 "Source of routing updates\n"
6978 BGP_UPDATE_SOURCE_HELP_STR)
6979 {
6980 int idx_peer = 1;
6981 int idx_peer_2 = 3;
6982 union sockunion su;
6983 char base_xpath[XPATH_MAXLEN];
6984
6985 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6986 sizeof(base_xpath), NULL)
6987 < 0)
6988 return CMD_WARNING_CONFIG_FAILED;
6989
6990 if (str2sockunion(argv[idx_peer_2]->arg, &su) == 0)
6991 nb_cli_enqueue_change(vty, "./update-source/ip", NB_OP_MODIFY,
6992 argv[idx_peer_2]->arg);
6993 else
6994 nb_cli_enqueue_change(vty, "./update-source/interface",
6995 NB_OP_MODIFY, argv[idx_peer_2]->arg);
6996
6997 return nb_cli_apply_changes(vty, base_xpath);
6998 }
6999
7000 DEFUN_YANG (no_neighbor_update_source,
7001 no_neighbor_update_source_cmd,
7002 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
7003 NO_STR NEIGHBOR_STR
7004 NEIGHBOR_ADDR_STR2
7005 "Source of routing updates\n"
7006 BGP_UPDATE_SOURCE_HELP_STR)
7007 {
7008 int idx_peer = 2;
7009 char base_xpath[XPATH_MAXLEN];
7010
7011 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7012 sizeof(base_xpath), NULL)
7013 < 0)
7014 return CMD_WARNING_CONFIG_FAILED;
7015
7016 nb_cli_enqueue_change(vty, "./update-source/ip", NB_OP_DESTROY, NULL);
7017 nb_cli_enqueue_change(vty, "./update-source/interface", NB_OP_DESTROY,
7018 NULL);
7019
7020 return nb_cli_apply_changes(vty, base_xpath);
7021 }
7022
7023 static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
7024 afi_t afi, safi_t safi,
7025 const char *rmap, int set)
7026 {
7027 int ret;
7028 struct peer *peer;
7029 struct route_map *route_map = NULL;
7030
7031 peer = peer_and_group_lookup_vty(vty, peer_str);
7032 if (!peer)
7033 return CMD_WARNING_CONFIG_FAILED;
7034
7035 if (set) {
7036 if (rmap)
7037 route_map = route_map_lookup_warn_noexist(vty, rmap);
7038 ret = peer_default_originate_set(peer, afi, safi,
7039 rmap, route_map);
7040 } else
7041 ret = peer_default_originate_unset(peer, afi, safi);
7042
7043 return bgp_vty_return(vty, ret);
7044 }
7045
7046 /* neighbor default-originate. */
7047 DEFUN (neighbor_default_originate,
7048 neighbor_default_originate_cmd,
7049 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
7050 NEIGHBOR_STR
7051 NEIGHBOR_ADDR_STR2
7052 "Originate default route to this neighbor\n")
7053 {
7054 int idx_peer = 1;
7055 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
7056 bgp_node_afi(vty),
7057 bgp_node_safi(vty), NULL, 1);
7058 }
7059
7060 ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
7061 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
7062 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7063 "Originate default route to this neighbor\n")
7064
7065 DEFUN (neighbor_default_originate_rmap,
7066 neighbor_default_originate_rmap_cmd,
7067 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
7068 NEIGHBOR_STR
7069 NEIGHBOR_ADDR_STR2
7070 "Originate default route to this neighbor\n"
7071 "Route-map to specify criteria to originate default\n"
7072 "route-map name\n")
7073 {
7074 int idx_peer = 1;
7075 int idx_word = 4;
7076 return peer_default_originate_set_vty(
7077 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7078 argv[idx_word]->arg, 1);
7079 }
7080
7081 ALIAS_HIDDEN(
7082 neighbor_default_originate_rmap,
7083 neighbor_default_originate_rmap_hidden_cmd,
7084 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
7085 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7086 "Originate default route to this neighbor\n"
7087 "Route-map to specify criteria to originate default\n"
7088 "route-map name\n")
7089
7090 DEFUN (no_neighbor_default_originate,
7091 no_neighbor_default_originate_cmd,
7092 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
7093 NO_STR
7094 NEIGHBOR_STR
7095 NEIGHBOR_ADDR_STR2
7096 "Originate default route to this neighbor\n"
7097 "Route-map to specify criteria to originate default\n"
7098 "route-map name\n")
7099 {
7100 int idx_peer = 2;
7101 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
7102 bgp_node_afi(vty),
7103 bgp_node_safi(vty), NULL, 0);
7104 }
7105
7106 ALIAS_HIDDEN(
7107 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
7108 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
7109 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7110 "Originate default route to this neighbor\n"
7111 "Route-map to specify criteria to originate default\n"
7112 "route-map name\n")
7113
7114
7115 /* Set specified peer's BGP port. */
7116 DEFUN_YANG (neighbor_port,
7117 neighbor_port_cmd,
7118 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
7119 NEIGHBOR_STR
7120 NEIGHBOR_ADDR_STR
7121 "Neighbor's BGP port\n"
7122 "TCP port number\n")
7123 {
7124 int idx_ip = 1;
7125 int idx_number = 3;
7126 char base_xpath[XPATH_MAXLEN];
7127
7128 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_NUM_XPATH,
7129 argv[idx_ip]->arg, "");
7130
7131 nb_cli_enqueue_change(vty, "./local-port", NB_OP_MODIFY,
7132 argv[idx_number]->arg);
7133
7134 return nb_cli_apply_changes(vty, base_xpath);
7135 }
7136
7137 DEFUN_YANG (no_neighbor_port,
7138 no_neighbor_port_cmd,
7139 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
7140 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR
7141 "Neighbor's BGP port\n"
7142 "TCP port number\n")
7143 {
7144 int idx_ip = 2;
7145 char base_xpath[XPATH_MAXLEN];
7146
7147 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_NUM_XPATH,
7148 argv[idx_ip]->arg, "");
7149
7150 nb_cli_enqueue_change(vty, "./local-port", NB_OP_DESTROY, NULL);
7151
7152 return nb_cli_apply_changes(vty, base_xpath);
7153 }
7154
7155 DEFUN_YANG (neighbor_weight,
7156 neighbor_weight_cmd,
7157 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7158 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7159 "Set default weight for routes from this neighbor\n"
7160 "default weight\n")
7161 {
7162 int idx_peer = 1;
7163 int idx_number = 3;
7164 char base_xpath[XPATH_MAXLEN];
7165 char af_xpath[XPATH_MAXLEN];
7166 char attr_xpath[XPATH_MAXLEN];
7167 afi_t afi = bgp_node_afi(vty);
7168 safi_t safi = bgp_node_safi(vty);
7169
7170 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
7171 yang_afi_safi_value2identity(afi, safi));
7172
7173 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7174 sizeof(base_xpath), af_xpath)
7175 < 0)
7176 return CMD_WARNING_CONFIG_FAILED;
7177
7178 snprintf(attr_xpath, sizeof(attr_xpath), "./%s/weight/weight-attribute",
7179 bgp_afi_safi_get_container_str(afi, safi));
7180
7181 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY,
7182 argv[idx_number]->arg);
7183
7184 return nb_cli_apply_changes(vty, base_xpath);
7185 }
7186
7187 ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
7188 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7189 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7190 "Set default weight for routes from this neighbor\n"
7191 "default weight\n")
7192
7193 DEFUN_YANG (no_neighbor_weight,
7194 no_neighbor_weight_cmd,
7195 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7196 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7197 "Set default weight for routes from this neighbor\n"
7198 "default weight\n")
7199 {
7200 int idx_peer = 2;
7201 char base_xpath[XPATH_MAXLEN];
7202 char af_xpath[XPATH_MAXLEN];
7203 char attr_xpath[XPATH_MAXLEN];
7204 afi_t afi = bgp_node_afi(vty);
7205 safi_t safi = bgp_node_safi(vty);
7206
7207 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
7208 yang_afi_safi_value2identity(afi, safi));
7209
7210 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7211 sizeof(base_xpath), af_xpath)
7212 < 0)
7213 return CMD_WARNING_CONFIG_FAILED;
7214
7215 snprintf(attr_xpath, sizeof(attr_xpath), "./%s/weight/weight-attribute",
7216 bgp_afi_safi_get_container_str(afi, safi));
7217
7218 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_DESTROY, NULL);
7219
7220 return nb_cli_apply_changes(vty, base_xpath);
7221 }
7222
7223 ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
7224 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7225 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7226 "Set default weight for routes from this neighbor\n"
7227 "default weight\n")
7228
7229
7230 /* Override capability negotiation. */
7231 DEFUN_YANG (neighbor_override_capability,
7232 neighbor_override_capability_cmd,
7233 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7234 NEIGHBOR_STR
7235 NEIGHBOR_ADDR_STR2
7236 "Override capability negotiation result\n")
7237 {
7238 int idx_peer = 1;
7239 char base_xpath[XPATH_MAXLEN];
7240
7241 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7242 sizeof(base_xpath), NULL)
7243 < 0)
7244 return CMD_WARNING_CONFIG_FAILED;
7245
7246 nb_cli_enqueue_change(
7247 vty, "./capability-options/override-capability",
7248 NB_OP_MODIFY, "true");
7249
7250 return nb_cli_apply_changes(vty, base_xpath);
7251 }
7252
7253 DEFUN_YANG (no_neighbor_override_capability,
7254 no_neighbor_override_capability_cmd,
7255 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7256 NO_STR
7257 NEIGHBOR_STR
7258 NEIGHBOR_ADDR_STR2
7259 "Override capability negotiation result\n")
7260 {
7261 int idx_peer = 2;
7262 char base_xpath[XPATH_MAXLEN];
7263
7264 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7265 sizeof(base_xpath), NULL)
7266 < 0)
7267 return CMD_WARNING_CONFIG_FAILED;
7268
7269 nb_cli_enqueue_change(
7270 vty, "./capability-options/override-capability",
7271 NB_OP_MODIFY, "false");
7272
7273 return nb_cli_apply_changes(vty, base_xpath);
7274 }
7275
7276 DEFUN_YANG (neighbor_strict_capability,
7277 neighbor_strict_capability_cmd,
7278 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7279 NEIGHBOR_STR
7280 NEIGHBOR_ADDR_STR2
7281 "Strict capability negotiation match\n")
7282 {
7283 int idx_peer = 1;
7284 char base_xpath[XPATH_MAXLEN];
7285
7286 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7287 sizeof(base_xpath), NULL)
7288 < 0)
7289 return CMD_WARNING_CONFIG_FAILED;
7290
7291 nb_cli_enqueue_change(
7292 vty, "./capability-options/strict-capability",
7293 NB_OP_MODIFY, "true");
7294
7295 return nb_cli_apply_changes(vty, base_xpath);
7296 }
7297
7298 DEFUN_YANG (no_neighbor_strict_capability,
7299 no_neighbor_strict_capability_cmd,
7300 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7301 NO_STR
7302 NEIGHBOR_STR
7303 NEIGHBOR_ADDR_STR2
7304 "Strict capability negotiation match\n")
7305 {
7306 int idx_peer = 2;
7307 char base_xpath[XPATH_MAXLEN];
7308
7309 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7310 sizeof(base_xpath), NULL)
7311 < 0)
7312 return CMD_WARNING_CONFIG_FAILED;
7313
7314 nb_cli_enqueue_change(
7315 vty, "./capability-options/strict-capability",
7316 NB_OP_MODIFY, "false");
7317
7318 return nb_cli_apply_changes(vty, base_xpath);
7319 }
7320
7321 DEFUN_YANG (neighbor_timers,
7322 neighbor_timers_cmd,
7323 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
7324 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7325 "BGP per neighbor timers\n"
7326 "Keepalive interval\n"
7327 "Holdtime\n")
7328 {
7329 int idx_peer = 1;
7330 int idx_number = 3;
7331 int idx_number_2 = 4;
7332 char base_xpath[XPATH_MAXLEN];
7333
7334 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7335 sizeof(base_xpath), NULL)
7336 < 0)
7337 return CMD_WARNING_CONFIG_FAILED;
7338
7339 nb_cli_enqueue_change(vty, "./timers/keepalive", NB_OP_MODIFY,
7340 argv[idx_number]->arg);
7341
7342 nb_cli_enqueue_change(vty, "./timers/hold-time", NB_OP_MODIFY,
7343 argv[idx_number_2]->arg);
7344
7345 return nb_cli_apply_changes(vty, base_xpath);
7346 }
7347
7348 DEFUN_YANG (no_neighbor_timers,
7349 no_neighbor_timers_cmd,
7350 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
7351 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7352 "BGP per neighbor timers\n"
7353 "Keepalive interval\n"
7354 "Holdtime\n")
7355 {
7356 int idx_peer = 2;
7357 char base_xpath[XPATH_MAXLEN];
7358
7359 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7360 sizeof(base_xpath), NULL)
7361 < 0)
7362 return CMD_WARNING_CONFIG_FAILED;
7363
7364 nb_cli_enqueue_change(vty, "./timers/hold-time", NB_OP_DESTROY, NULL);
7365
7366 nb_cli_enqueue_change(vty, "./timers/keepalive", NB_OP_DESTROY, NULL);
7367
7368 return nb_cli_apply_changes(vty, base_xpath);
7369 }
7370
7371 DEFUN_YANG (neighbor_timers_connect,
7372 neighbor_timers_connect_cmd,
7373 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
7374 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7375 "BGP per neighbor timers\n"
7376 "BGP connect timer\n"
7377 "Connect timer\n")
7378 {
7379 int idx_peer = 1;
7380 int idx_number = 4;
7381 char base_xpath[XPATH_MAXLEN];
7382
7383 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7384 sizeof(base_xpath), NULL)
7385 < 0)
7386 return CMD_WARNING_CONFIG_FAILED;
7387
7388 nb_cli_enqueue_change(vty, "./timers/connect-time", NB_OP_MODIFY,
7389 argv[idx_number]->arg);
7390
7391 return nb_cli_apply_changes(vty, base_xpath);
7392 }
7393
7394 DEFUN_YANG (no_neighbor_timers_connect,
7395 no_neighbor_timers_connect_cmd,
7396 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
7397 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7398 "BGP per neighbor timers\n"
7399 "BGP connect timer\n"
7400 "Connect timer\n")
7401 {
7402 int idx_peer = 2;
7403 char base_xpath[XPATH_MAXLEN];
7404
7405 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7406 sizeof(base_xpath), NULL)
7407 < 0)
7408 return CMD_WARNING_CONFIG_FAILED;
7409
7410 nb_cli_enqueue_change(vty, "./timers/connect-time", NB_OP_DESTROY,
7411 NULL);
7412
7413 return nb_cli_apply_changes(vty, base_xpath);
7414 }
7415
7416 DEFPY (neighbor_timers_delayopen,
7417 neighbor_timers_delayopen_cmd,
7418 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen (1-240)$interval",
7419 NEIGHBOR_STR
7420 NEIGHBOR_ADDR_STR2
7421 "BGP per neighbor timers\n"
7422 "RFC 4271 DelayOpenTimer\n"
7423 "DelayOpenTime timer interval\n")
7424 {
7425 struct peer *peer;
7426
7427 peer = peer_and_group_lookup_vty(vty, neighbor);
7428 if (!peer)
7429 return CMD_WARNING_CONFIG_FAILED;
7430
7431 if (!interval) {
7432 if (peer_timers_delayopen_unset(peer))
7433 return CMD_WARNING_CONFIG_FAILED;
7434 } else {
7435 if (peer_timers_delayopen_set(peer, interval))
7436 return CMD_WARNING_CONFIG_FAILED;
7437 }
7438
7439 return CMD_SUCCESS;
7440 }
7441
7442 DEFPY (no_neighbor_timers_delayopen,
7443 no_neighbor_timers_delayopen_cmd,
7444 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen [(0-65535)]",
7445 NO_STR
7446 NEIGHBOR_STR
7447 NEIGHBOR_ADDR_STR2
7448 "BGP per neighbor timers\n"
7449 "RFC 4271 DelayOpenTimer\n"
7450 "DelayOpenTime timer interval\n")
7451 {
7452 struct peer *peer;
7453
7454 peer = peer_and_group_lookup_vty(vty, neighbor);
7455 if (!peer)
7456 return CMD_WARNING_CONFIG_FAILED;
7457
7458 if (peer_timers_delayopen_unset(peer))
7459 return CMD_WARNING_CONFIG_FAILED;
7460
7461 return CMD_SUCCESS;
7462 }
7463
7464 DEFUN_YANG (neighbor_advertise_interval,
7465 neighbor_advertise_interval_cmd,
7466 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
7467 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7468 "Minimum interval between sending BGP routing updates\n"
7469 "time in seconds\n")
7470 {
7471 int idx_peer = 1;
7472 int idx_number = 3;
7473 char base_xpath[XPATH_MAXLEN];
7474
7475 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7476 sizeof(base_xpath), NULL)
7477 < 0)
7478 return CMD_WARNING_CONFIG_FAILED;
7479
7480 nb_cli_enqueue_change(vty, "./timers/advertise-interval", NB_OP_MODIFY,
7481 argv[idx_number]->arg);
7482
7483 return nb_cli_apply_changes(vty, base_xpath);
7484 }
7485
7486 DEFUN_YANG (no_neighbor_advertise_interval,
7487 no_neighbor_advertise_interval_cmd,
7488 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
7489 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7490 "Minimum interval between sending BGP routing updates\n"
7491 "time in seconds\n")
7492 {
7493 int idx_peer = 2;
7494 char base_xpath[XPATH_MAXLEN];
7495
7496 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7497 sizeof(base_xpath), NULL)
7498 < 0)
7499 return CMD_WARNING_CONFIG_FAILED;
7500
7501 nb_cli_enqueue_change(vty, "./timers/advertise-interval", NB_OP_DESTROY,
7502 NULL);
7503
7504 return nb_cli_apply_changes(vty, base_xpath);
7505 }
7506
7507
7508 /* Time to wait before processing route-map updates */
7509 DEFUN (bgp_set_route_map_delay_timer,
7510 bgp_set_route_map_delay_timer_cmd,
7511 "bgp route-map delay-timer (0-600)",
7512 SET_STR
7513 "BGP route-map delay timer\n"
7514 "Time in secs to wait before processing route-map changes\n"
7515 "0 disables the timer, no route updates happen when route-maps change\n")
7516 {
7517 int idx_number = 3;
7518 uint32_t rmap_delay_timer;
7519
7520 if (argv[idx_number]->arg) {
7521 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
7522 bm->rmap_update_timer = rmap_delay_timer;
7523
7524 /* if the dynamic update handling is being disabled, and a timer
7525 * is
7526 * running, stop the timer and act as if the timer has already
7527 * fired.
7528 */
7529 if (!rmap_delay_timer && bm->t_rmap_update) {
7530 BGP_TIMER_OFF(bm->t_rmap_update);
7531 thread_execute(bm->master, bgp_route_map_update_timer,
7532 NULL, 0);
7533 }
7534 return CMD_SUCCESS;
7535 } else {
7536 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
7537 return CMD_WARNING_CONFIG_FAILED;
7538 }
7539 }
7540
7541 DEFUN (no_bgp_set_route_map_delay_timer,
7542 no_bgp_set_route_map_delay_timer_cmd,
7543 "no bgp route-map delay-timer [(0-600)]",
7544 NO_STR
7545 BGP_STR
7546 "Default BGP route-map delay timer\n"
7547 "Reset to default time to wait for processing route-map changes\n"
7548 "0 disables the timer, no route updates happen when route-maps change\n")
7549 {
7550
7551 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
7552
7553 return CMD_SUCCESS;
7554 }
7555
7556 DEFUN_YANG (neighbor_interface,
7557 neighbor_interface_cmd,
7558 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
7559 NEIGHBOR_STR NEIGHBOR_ADDR_STR
7560 "Interface\n"
7561 "Interface name\n")
7562 {
7563 int idx_ip = 1;
7564 int idx_word = 3;
7565 char base_xpath[XPATH_MAXLEN];
7566
7567 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_NUM_XPATH,
7568 argv[idx_ip]->arg, "");
7569
7570 nb_cli_enqueue_change(vty, "./local-interface", NB_OP_MODIFY,
7571 argv[idx_word]->arg);
7572
7573 return nb_cli_apply_changes(vty, base_xpath);
7574 }
7575
7576 DEFUN_YANG (no_neighbor_interface,
7577 no_neighbor_interface_cmd,
7578 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
7579 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7580 "Interface\n"
7581 "Interface name\n")
7582 {
7583 int idx_peer = 2;
7584 char base_xpath[XPATH_MAXLEN];
7585
7586 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_NUM_XPATH,
7587 argv[idx_peer]->arg, "");
7588
7589 nb_cli_enqueue_change(vty, "./local-interface", NB_OP_DESTROY, NULL);
7590
7591 return nb_cli_apply_changes(vty, base_xpath);
7592 }
7593
7594 DEFUN (neighbor_distribute_list,
7595 neighbor_distribute_list_cmd,
7596 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
7597 NEIGHBOR_STR
7598 NEIGHBOR_ADDR_STR2
7599 "Filter updates to/from this neighbor\n"
7600 "IP access-list number\n"
7601 "IP access-list number (expanded range)\n"
7602 "IP Access-list name\n"
7603 "Filter incoming updates\n"
7604 "Filter outgoing updates\n")
7605 {
7606 int idx_peer = 1;
7607 int idx_acl = 3;
7608 int direct, ret;
7609 struct peer *peer;
7610
7611 const char *pstr = argv[idx_peer]->arg;
7612 const char *acl = argv[idx_acl]->arg;
7613 const char *inout = argv[argc - 1]->text;
7614
7615 peer = peer_and_group_lookup_vty(vty, pstr);
7616 if (!peer)
7617 return CMD_WARNING_CONFIG_FAILED;
7618
7619 /* Check filter direction. */
7620 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7621 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7622 direct, acl);
7623
7624 return bgp_vty_return(vty, ret);
7625 }
7626
7627 ALIAS_HIDDEN(
7628 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
7629 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
7630 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7631 "Filter updates to/from this neighbor\n"
7632 "IP access-list number\n"
7633 "IP access-list number (expanded range)\n"
7634 "IP Access-list name\n"
7635 "Filter incoming updates\n"
7636 "Filter outgoing updates\n")
7637
7638 DEFUN (no_neighbor_distribute_list,
7639 no_neighbor_distribute_list_cmd,
7640 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
7641 NO_STR
7642 NEIGHBOR_STR
7643 NEIGHBOR_ADDR_STR2
7644 "Filter updates to/from this neighbor\n"
7645 "IP access-list number\n"
7646 "IP access-list number (expanded range)\n"
7647 "IP Access-list name\n"
7648 "Filter incoming updates\n"
7649 "Filter outgoing updates\n")
7650 {
7651 int idx_peer = 2;
7652 int direct, ret;
7653 struct peer *peer;
7654
7655 const char *pstr = argv[idx_peer]->arg;
7656 const char *inout = argv[argc - 1]->text;
7657
7658 peer = peer_and_group_lookup_vty(vty, pstr);
7659 if (!peer)
7660 return CMD_WARNING_CONFIG_FAILED;
7661
7662 /* Check filter direction. */
7663 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7664 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7665 direct);
7666
7667 return bgp_vty_return(vty, ret);
7668 }
7669
7670 ALIAS_HIDDEN(
7671 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
7672 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
7673 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7674 "Filter updates to/from this neighbor\n"
7675 "IP access-list number\n"
7676 "IP access-list number (expanded range)\n"
7677 "IP Access-list name\n"
7678 "Filter incoming updates\n"
7679 "Filter outgoing updates\n")
7680
7681 /* Set prefix list to the peer. */
7682 static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
7683 afi_t afi, safi_t safi,
7684 const char *name_str,
7685 const char *direct_str)
7686 {
7687 int ret;
7688 int direct = FILTER_IN;
7689 struct peer *peer;
7690
7691 peer = peer_and_group_lookup_vty(vty, ip_str);
7692 if (!peer)
7693 return CMD_WARNING_CONFIG_FAILED;
7694
7695 /* Check filter direction. */
7696 if (strncmp(direct_str, "i", 1) == 0)
7697 direct = FILTER_IN;
7698 else if (strncmp(direct_str, "o", 1) == 0)
7699 direct = FILTER_OUT;
7700
7701 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
7702
7703 return bgp_vty_return(vty, ret);
7704 }
7705
7706 static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
7707 afi_t afi, safi_t safi,
7708 const char *direct_str)
7709 {
7710 int ret;
7711 struct peer *peer;
7712 int direct = FILTER_IN;
7713
7714 peer = peer_and_group_lookup_vty(vty, ip_str);
7715 if (!peer)
7716 return CMD_WARNING_CONFIG_FAILED;
7717
7718 /* Check filter direction. */
7719 if (strncmp(direct_str, "i", 1) == 0)
7720 direct = FILTER_IN;
7721 else if (strncmp(direct_str, "o", 1) == 0)
7722 direct = FILTER_OUT;
7723
7724 ret = peer_prefix_list_unset(peer, afi, safi, direct);
7725
7726 return bgp_vty_return(vty, ret);
7727 }
7728
7729 DEFUN (neighbor_prefix_list,
7730 neighbor_prefix_list_cmd,
7731 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7732 NEIGHBOR_STR
7733 NEIGHBOR_ADDR_STR2
7734 "Filter updates to/from this neighbor\n"
7735 "Name of a prefix list\n"
7736 "Filter incoming updates\n"
7737 "Filter outgoing updates\n")
7738 {
7739 int idx_peer = 1;
7740 int idx_word = 3;
7741 int idx_in_out = 4;
7742 return peer_prefix_list_set_vty(
7743 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7744 argv[idx_word]->arg, argv[idx_in_out]->arg);
7745 }
7746
7747 ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
7748 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7749 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7750 "Filter updates to/from this neighbor\n"
7751 "Name of a prefix list\n"
7752 "Filter incoming updates\n"
7753 "Filter outgoing updates\n")
7754
7755 DEFUN (no_neighbor_prefix_list,
7756 no_neighbor_prefix_list_cmd,
7757 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7758 NO_STR
7759 NEIGHBOR_STR
7760 NEIGHBOR_ADDR_STR2
7761 "Filter updates to/from this neighbor\n"
7762 "Name of a prefix list\n"
7763 "Filter incoming updates\n"
7764 "Filter outgoing updates\n")
7765 {
7766 int idx_peer = 2;
7767 int idx_in_out = 5;
7768 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
7769 bgp_node_afi(vty), bgp_node_safi(vty),
7770 argv[idx_in_out]->arg);
7771 }
7772
7773 ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
7774 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7775 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7776 "Filter updates to/from this neighbor\n"
7777 "Name of a prefix list\n"
7778 "Filter incoming updates\n"
7779 "Filter outgoing updates\n")
7780
7781 static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7782 safi_t safi, const char *name_str,
7783 const char *direct_str)
7784 {
7785 int ret;
7786 struct peer *peer;
7787 int direct = FILTER_IN;
7788
7789 peer = peer_and_group_lookup_vty(vty, ip_str);
7790 if (!peer)
7791 return CMD_WARNING_CONFIG_FAILED;
7792
7793 /* Check filter direction. */
7794 if (strncmp(direct_str, "i", 1) == 0)
7795 direct = FILTER_IN;
7796 else if (strncmp(direct_str, "o", 1) == 0)
7797 direct = FILTER_OUT;
7798
7799 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
7800
7801 return bgp_vty_return(vty, ret);
7802 }
7803
7804 static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7805 safi_t safi, const char *direct_str)
7806 {
7807 int ret;
7808 struct peer *peer;
7809 int direct = FILTER_IN;
7810
7811 peer = peer_and_group_lookup_vty(vty, ip_str);
7812 if (!peer)
7813 return CMD_WARNING_CONFIG_FAILED;
7814
7815 /* Check filter direction. */
7816 if (strncmp(direct_str, "i", 1) == 0)
7817 direct = FILTER_IN;
7818 else if (strncmp(direct_str, "o", 1) == 0)
7819 direct = FILTER_OUT;
7820
7821 ret = peer_aslist_unset(peer, afi, safi, direct);
7822
7823 return bgp_vty_return(vty, ret);
7824 }
7825
7826 DEFUN (neighbor_filter_list,
7827 neighbor_filter_list_cmd,
7828 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
7829 NEIGHBOR_STR
7830 NEIGHBOR_ADDR_STR2
7831 "Establish BGP filters\n"
7832 "AS path access-list name\n"
7833 "Filter incoming routes\n"
7834 "Filter outgoing routes\n")
7835 {
7836 int idx_peer = 1;
7837 int idx_word = 3;
7838 int idx_in_out = 4;
7839 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7840 bgp_node_safi(vty), argv[idx_word]->arg,
7841 argv[idx_in_out]->arg);
7842 }
7843
7844 ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
7845 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
7846 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7847 "Establish BGP filters\n"
7848 "AS path access-list name\n"
7849 "Filter incoming routes\n"
7850 "Filter outgoing routes\n")
7851
7852 DEFUN (no_neighbor_filter_list,
7853 no_neighbor_filter_list_cmd,
7854 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
7855 NO_STR
7856 NEIGHBOR_STR
7857 NEIGHBOR_ADDR_STR2
7858 "Establish BGP filters\n"
7859 "AS path access-list name\n"
7860 "Filter incoming routes\n"
7861 "Filter outgoing routes\n")
7862 {
7863 int idx_peer = 2;
7864 int idx_in_out = 5;
7865 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
7866 bgp_node_afi(vty), bgp_node_safi(vty),
7867 argv[idx_in_out]->arg);
7868 }
7869
7870 ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
7871 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
7872 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7873 "Establish BGP filters\n"
7874 "AS path access-list name\n"
7875 "Filter incoming routes\n"
7876 "Filter outgoing routes\n")
7877
7878 /* Set advertise-map to the peer. */
7879 static int peer_advertise_map_set_vty(struct vty *vty, const char *ip_str,
7880 afi_t afi, safi_t safi,
7881 const char *advertise_str,
7882 const char *condition_str, bool condition,
7883 bool set)
7884 {
7885 int ret = CMD_WARNING_CONFIG_FAILED;
7886 struct peer *peer;
7887 struct route_map *advertise_map;
7888 struct route_map *condition_map;
7889
7890 peer = peer_and_group_lookup_vty(vty, ip_str);
7891 if (!peer)
7892 return ret;
7893
7894 condition_map = route_map_lookup_warn_noexist(vty, condition_str);
7895 advertise_map = route_map_lookup_warn_noexist(vty, advertise_str);
7896
7897 if (set)
7898 ret = peer_advertise_map_set(peer, afi, safi, advertise_str,
7899 advertise_map, condition_str,
7900 condition_map, condition);
7901 else
7902 ret = peer_advertise_map_unset(peer, afi, safi, advertise_str,
7903 advertise_map, condition_str,
7904 condition_map, condition);
7905
7906 return bgp_vty_return(vty, ret);
7907 }
7908
7909 DEFPY (neighbor_advertise_map,
7910 neighbor_advertise_map_cmd,
7911 "[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",
7912 NO_STR
7913 NEIGHBOR_STR
7914 NEIGHBOR_ADDR_STR2
7915 "Route-map to conditionally advertise routes\n"
7916 "Name of advertise map\n"
7917 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7918 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
7919 "Name of the exist or non exist map\n")
7920 {
7921 bool condition = CONDITION_EXIST;
7922
7923 if (!strcmp(exist, "non-exist-map"))
7924 condition = CONDITION_NON_EXIST;
7925
7926 return peer_advertise_map_set_vty(vty, neighbor, bgp_node_afi(vty),
7927 bgp_node_safi(vty), advertise_str,
7928 condition_str, condition, !no);
7929 }
7930
7931 ALIAS_HIDDEN(neighbor_advertise_map, neighbor_advertise_map_hidden_cmd,
7932 "[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",
7933 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7934 "Route-map to conditionally advertise routes\n"
7935 "Name of advertise map\n"
7936 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7937 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
7938 "Name of the exist or non exist map\n")
7939
7940 /* Set route-map to the peer. */
7941 static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
7942 afi_t afi, safi_t safi, const char *name_str,
7943 const char *direct_str)
7944 {
7945 int ret;
7946 struct peer *peer;
7947 int direct = RMAP_IN;
7948 struct route_map *route_map;
7949
7950 peer = peer_and_group_lookup_vty(vty, ip_str);
7951 if (!peer)
7952 return CMD_WARNING_CONFIG_FAILED;
7953
7954 /* Check filter direction. */
7955 if (strncmp(direct_str, "in", 2) == 0)
7956 direct = RMAP_IN;
7957 else if (strncmp(direct_str, "o", 1) == 0)
7958 direct = RMAP_OUT;
7959
7960 route_map = route_map_lookup_warn_noexist(vty, name_str);
7961 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
7962
7963 return bgp_vty_return(vty, ret);
7964 }
7965
7966 static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
7967 afi_t afi, safi_t safi,
7968 const char *direct_str)
7969 {
7970 int ret;
7971 struct peer *peer;
7972 int direct = RMAP_IN;
7973
7974 peer = peer_and_group_lookup_vty(vty, ip_str);
7975 if (!peer)
7976 return CMD_WARNING_CONFIG_FAILED;
7977
7978 /* Check filter direction. */
7979 if (strncmp(direct_str, "in", 2) == 0)
7980 direct = RMAP_IN;
7981 else if (strncmp(direct_str, "o", 1) == 0)
7982 direct = RMAP_OUT;
7983
7984 ret = peer_route_map_unset(peer, afi, safi, direct);
7985
7986 return bgp_vty_return(vty, ret);
7987 }
7988
7989 DEFUN (neighbor_route_map,
7990 neighbor_route_map_cmd,
7991 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
7992 NEIGHBOR_STR
7993 NEIGHBOR_ADDR_STR2
7994 "Apply route map to neighbor\n"
7995 "Name of route map\n"
7996 "Apply map to incoming routes\n"
7997 "Apply map to outbound routes\n")
7998 {
7999 int idx_peer = 1;
8000 int idx_word = 3;
8001 int idx_in_out = 4;
8002 return peer_route_map_set_vty(
8003 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8004 argv[idx_word]->arg, argv[idx_in_out]->arg);
8005 }
8006
8007 ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
8008 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
8009 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8010 "Apply route map to neighbor\n"
8011 "Name of route map\n"
8012 "Apply map to incoming routes\n"
8013 "Apply map to outbound routes\n")
8014
8015 DEFUN (no_neighbor_route_map,
8016 no_neighbor_route_map_cmd,
8017 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
8018 NO_STR
8019 NEIGHBOR_STR
8020 NEIGHBOR_ADDR_STR2
8021 "Apply route map to neighbor\n"
8022 "Name of route map\n"
8023 "Apply map to incoming routes\n"
8024 "Apply map to outbound routes\n")
8025 {
8026 int idx_peer = 2;
8027 int idx_in_out = 5;
8028 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
8029 bgp_node_afi(vty), bgp_node_safi(vty),
8030 argv[idx_in_out]->arg);
8031 }
8032
8033 ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
8034 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
8035 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8036 "Apply route map to neighbor\n"
8037 "Name of route map\n"
8038 "Apply map to incoming routes\n"
8039 "Apply map to outbound routes\n")
8040
8041 /* Set unsuppress-map to the peer. */
8042 static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
8043 afi_t afi, safi_t safi,
8044 const char *name_str)
8045 {
8046 int ret;
8047 struct peer *peer;
8048 struct route_map *route_map;
8049
8050 peer = peer_and_group_lookup_vty(vty, ip_str);
8051 if (!peer)
8052 return CMD_WARNING_CONFIG_FAILED;
8053
8054 route_map = route_map_lookup_warn_noexist(vty, name_str);
8055 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
8056
8057 return bgp_vty_return(vty, ret);
8058 }
8059
8060 /* Unset route-map from the peer. */
8061 static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
8062 afi_t afi, safi_t safi)
8063 {
8064 int ret;
8065 struct peer *peer;
8066
8067 peer = peer_and_group_lookup_vty(vty, ip_str);
8068 if (!peer)
8069 return CMD_WARNING_CONFIG_FAILED;
8070
8071 ret = peer_unsuppress_map_unset(peer, afi, safi);
8072
8073 return bgp_vty_return(vty, ret);
8074 }
8075
8076 DEFUN (neighbor_unsuppress_map,
8077 neighbor_unsuppress_map_cmd,
8078 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8079 NEIGHBOR_STR
8080 NEIGHBOR_ADDR_STR2
8081 "Route-map to selectively unsuppress suppressed routes\n"
8082 "Name of route map\n")
8083 {
8084 int idx_peer = 1;
8085 int idx_word = 3;
8086 return peer_unsuppress_map_set_vty(
8087 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8088 argv[idx_word]->arg);
8089 }
8090
8091 ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
8092 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8093 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8094 "Route-map to selectively unsuppress suppressed routes\n"
8095 "Name of route map\n")
8096
8097 DEFUN (no_neighbor_unsuppress_map,
8098 no_neighbor_unsuppress_map_cmd,
8099 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8100 NO_STR
8101 NEIGHBOR_STR
8102 NEIGHBOR_ADDR_STR2
8103 "Route-map to selectively unsuppress suppressed routes\n"
8104 "Name of route map\n")
8105 {
8106 int idx_peer = 2;
8107 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
8108 bgp_node_afi(vty),
8109 bgp_node_safi(vty));
8110 }
8111
8112 ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
8113 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8114 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8115 "Route-map to selectively unsuppress suppressed routes\n"
8116 "Name of route map\n")
8117
8118 /* Maximum number of prefix to be sent to the neighbor. */
8119 DEFUN_YANG(neighbor_maximum_prefix_out,
8120 neighbor_maximum_prefix_out_cmd,
8121 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out (1-4294967295)",
8122 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8123 "Maximum number of prefixes to be sent to this peer\n"
8124 "Maximum no. of prefix limit\n")
8125 {
8126 char base_xpath[XPATH_MAXLEN];
8127 char af_xpath[XPATH_MAXLEN];
8128 char attr_xpath[XPATH_MAXLEN];
8129 int idx_peer = 1;
8130 int idx_number = 3;
8131 afi_t afi = bgp_node_afi(vty);
8132 safi_t safi = bgp_node_safi(vty);
8133
8134 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8135 yang_afi_safi_value2identity(afi, safi));
8136 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8137 sizeof(base_xpath), af_xpath)
8138 < 0)
8139 return CMD_WARNING_CONFIG_FAILED;
8140
8141 snprintf(attr_xpath, sizeof(attr_xpath),
8142 "/%s/prefix-limit/direction-list[direction='out']",
8143 bgp_afi_safi_get_container_str(afi, safi));
8144 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8145
8146 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8147
8148 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8149 argv[idx_number]->arg);
8150
8151 return nb_cli_apply_changes(vty, base_xpath);
8152 }
8153
8154 DEFUN_YANG(no_neighbor_maximum_prefix_out,
8155 no_neighbor_maximum_prefix_out_cmd,
8156 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out",
8157 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8158 "Maximum number of prefixes to be sent to this peer\n")
8159 {
8160 char base_xpath[XPATH_MAXLEN];
8161 char af_xpath[XPATH_MAXLEN];
8162 char attr_xpath[XPATH_MAXLEN];
8163 int idx_peer = 2;
8164 afi_t afi = bgp_node_afi(vty);
8165 safi_t safi = bgp_node_safi(vty);
8166
8167 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8168 yang_afi_safi_value2identity(afi, safi));
8169 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8170 sizeof(base_xpath), af_xpath)
8171 < 0)
8172 return CMD_WARNING_CONFIG_FAILED;
8173
8174 snprintf(attr_xpath, sizeof(attr_xpath),
8175 "/%s/prefix-limit/direction-list[direction='out']",
8176 bgp_afi_safi_get_container_str(afi, safi));
8177 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8178
8179 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
8180
8181 return nb_cli_apply_changes(vty, base_xpath);
8182 }
8183
8184 /* Maximum number of prefix configuration. Prefix count is different
8185 for each peer configuration. So this configuration can be set for
8186 each peer configuration. */
8187 DEFUN_YANG(neighbor_maximum_prefix,
8188 neighbor_maximum_prefix_cmd,
8189 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
8190 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8191 "Maximum number of prefix accept from this peer\n"
8192 "maximum no. of prefix limit\n"
8193 "Force checking all received routes not only accepted\n")
8194 {
8195 int idx_peer = 1;
8196 int idx_number = 3;
8197 int idx_force = 0;
8198 char base_xpath[XPATH_MAXLEN];
8199 char af_xpath[XPATH_MAXLEN];
8200 char attr_xpath[XPATH_MAXLEN];
8201 afi_t afi = bgp_node_afi(vty);
8202 safi_t safi = bgp_node_safi(vty);
8203
8204 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8205 yang_afi_safi_value2identity(afi, safi));
8206 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8207 sizeof(base_xpath), af_xpath)
8208 < 0)
8209 return CMD_WARNING_CONFIG_FAILED;
8210
8211 snprintf(attr_xpath, sizeof(attr_xpath),
8212 "/%s/prefix-limit/direction-list[direction='in']",
8213 bgp_afi_safi_get_container_str(afi, safi));
8214 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8215
8216 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8217
8218 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8219 argv[idx_number]->arg);
8220 if (argv_find(argv, argc, "force", &idx_force))
8221 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8222 "true");
8223
8224 return nb_cli_apply_changes(vty, base_xpath);
8225 }
8226
8227 ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
8228 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
8229 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8230 "Maximum number of prefix accept from this peer\n"
8231 "maximum no. of prefix limit\n"
8232 "Force checking all received routes not only accepted\n")
8233
8234 DEFUN_YANG(neighbor_maximum_prefix_threshold,
8235 neighbor_maximum_prefix_threshold_cmd,
8236 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
8237 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8238 "Maximum number of prefix accept from this peer\n"
8239 "maximum no. of prefix limit\n"
8240 "Threshold value (%) at which to generate a warning msg\n"
8241 "Force checking all received routes not only accepted\n")
8242 {
8243 int idx_peer = 1;
8244 int idx_number = 3;
8245 int idx_number_2 = 4;
8246 int idx_force = 0;
8247 char base_xpath[XPATH_MAXLEN];
8248 char af_xpath[XPATH_MAXLEN];
8249 char attr_xpath[XPATH_MAXLEN];
8250 afi_t afi = bgp_node_afi(vty);
8251 safi_t safi = bgp_node_safi(vty);
8252
8253 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8254 yang_afi_safi_value2identity(afi, safi));
8255 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8256 sizeof(base_xpath), af_xpath)
8257 < 0)
8258 return CMD_WARNING_CONFIG_FAILED;
8259
8260 snprintf(attr_xpath, sizeof(attr_xpath),
8261 "/%s/prefix-limit/direction-list[direction='in']",
8262 bgp_afi_safi_get_container_str(afi, safi));
8263 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8264
8265 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8266
8267 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8268 argv[idx_number]->arg);
8269
8270 nb_cli_enqueue_change(vty, "./options/shutdown-threshold-pct",
8271 NB_OP_MODIFY, argv[idx_number_2]->arg);
8272
8273 if (argv_find(argv, argc, "force", &idx_force))
8274 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8275 "true");
8276
8277 return nb_cli_apply_changes(vty, base_xpath);
8278 }
8279
8280 ALIAS_HIDDEN(
8281 neighbor_maximum_prefix_threshold,
8282 neighbor_maximum_prefix_threshold_hidden_cmd,
8283 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
8284 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8285 "Maximum number of prefix accept from this peer\n"
8286 "maximum no. of prefix limit\n"
8287 "Threshold value (%) at which to generate a warning msg\n"
8288 "Force checking all received routes not only accepted\n")
8289
8290 DEFUN_YANG(neighbor_maximum_prefix_warning,
8291 neighbor_maximum_prefix_warning_cmd,
8292 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
8293 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8294 "Maximum number of prefix accept from this peer\n"
8295 "maximum no. of prefix limit\n"
8296 "Only give warning message when limit is exceeded\n"
8297 "Force checking all received routes not only accepted\n")
8298 {
8299 int idx_peer = 1;
8300 int idx_number = 3;
8301 int idx_force = 0;
8302 char base_xpath[XPATH_MAXLEN];
8303 char af_xpath[XPATH_MAXLEN];
8304 char attr_xpath[XPATH_MAXLEN];
8305 afi_t afi = bgp_node_afi(vty);
8306 safi_t safi = bgp_node_safi(vty);
8307
8308 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8309 yang_afi_safi_value2identity(afi, safi));
8310 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8311 sizeof(base_xpath), af_xpath)
8312 < 0)
8313 return CMD_WARNING_CONFIG_FAILED;
8314
8315 snprintf(attr_xpath, sizeof(attr_xpath),
8316 "/%s/prefix-limit/direction-list[direction='in']",
8317 bgp_afi_safi_get_container_str(afi, safi));
8318 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8319
8320 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8321
8322 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8323 argv[idx_number]->arg);
8324
8325 nb_cli_enqueue_change(vty, "./options/warning-only", NB_OP_MODIFY,
8326 "true");
8327 if (argv_find(argv, argc, "force", &idx_force))
8328 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8329 "true");
8330
8331 return nb_cli_apply_changes(vty, base_xpath);
8332 }
8333
8334 ALIAS_HIDDEN(
8335 neighbor_maximum_prefix_warning,
8336 neighbor_maximum_prefix_warning_hidden_cmd,
8337 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
8338 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8339 "Maximum number of prefix accept from this peer\n"
8340 "maximum no. of prefix limit\n"
8341 "Only give warning message when limit is exceeded\n"
8342 "Force checking all received routes not only accepted\n")
8343
8344 DEFUN_YANG(neighbor_maximum_prefix_threshold_warning,
8345 neighbor_maximum_prefix_threshold_warning_cmd,
8346 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
8347 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8348 "Maximum number of prefix accept from this peer\n"
8349 "maximum no. of prefix limit\n"
8350 "Threshold value (%) at which to generate a warning msg\n"
8351 "Only give warning message when limit is exceeded\n"
8352 "Force checking all received routes not only accepted\n")
8353 {
8354 int idx_peer = 1;
8355 int idx_number = 3;
8356 int idx_number_2 = 4;
8357 int idx_force = 0;
8358 char base_xpath[XPATH_MAXLEN];
8359 char af_xpath[XPATH_MAXLEN];
8360 char attr_xpath[XPATH_MAXLEN];
8361 afi_t afi = bgp_node_afi(vty);
8362 safi_t safi = bgp_node_safi(vty);
8363
8364 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8365 yang_afi_safi_value2identity(afi, safi));
8366 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8367 sizeof(base_xpath), af_xpath)
8368 < 0)
8369 return CMD_WARNING_CONFIG_FAILED;
8370
8371 snprintf(attr_xpath, sizeof(attr_xpath),
8372 "/%s/prefix-limit/direction-list[direction='in']",
8373 bgp_afi_safi_get_container_str(afi, safi));
8374 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8375
8376 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8377
8378 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8379 argv[idx_number]->arg);
8380 nb_cli_enqueue_change(vty, "./options/tw-shutdown-threshold-pct",
8381 NB_OP_MODIFY, argv[idx_number_2]->arg);
8382 nb_cli_enqueue_change(vty, "./options/tw-warning-only", NB_OP_MODIFY,
8383 "true");
8384 if (argv_find(argv, argc, "force", &idx_force))
8385 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8386 "true");
8387
8388 return nb_cli_apply_changes(vty, base_xpath);
8389 }
8390
8391 ALIAS_HIDDEN(
8392 neighbor_maximum_prefix_threshold_warning,
8393 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
8394 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [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 "Only give warning message when limit is exceeded\n"
8400 "Force checking all received routes not only accepted\n")
8401
8402 DEFUN_YANG(neighbor_maximum_prefix_restart,
8403 neighbor_maximum_prefix_restart_cmd,
8404 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8405 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8406 "Maximum number of prefix accept from this peer\n"
8407 "maximum no. of prefix limit\n"
8408 "Restart bgp connection after limit is exceeded\n"
8409 "Restart interval in minutes\n"
8410 "Force checking all received routes not only accepted\n")
8411 {
8412 int idx_peer = 1;
8413 int idx_number = 3;
8414 int idx_number_2 = 5;
8415 int idx_force = 0;
8416 char base_xpath[XPATH_MAXLEN];
8417 char af_xpath[XPATH_MAXLEN];
8418 char attr_xpath[XPATH_MAXLEN];
8419 afi_t afi = bgp_node_afi(vty);
8420 safi_t safi = bgp_node_safi(vty);
8421
8422 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8423 yang_afi_safi_value2identity(afi, safi));
8424 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8425 sizeof(base_xpath), af_xpath)
8426 < 0)
8427 return CMD_WARNING_CONFIG_FAILED;
8428
8429 snprintf(attr_xpath, sizeof(attr_xpath),
8430 "/%s/prefix-limit/direction-list[direction='in']",
8431 bgp_afi_safi_get_container_str(afi, safi));
8432 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8433
8434 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8435
8436 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8437 argv[idx_number]->arg);
8438 nb_cli_enqueue_change(vty, "./options/restart-timer", NB_OP_MODIFY,
8439 argv[idx_number_2]->arg);
8440 if (argv_find(argv, argc, "force", &idx_force))
8441 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8442 "true");
8443
8444 return nb_cli_apply_changes(vty, base_xpath);
8445 }
8446
8447 ALIAS_HIDDEN(
8448 neighbor_maximum_prefix_restart,
8449 neighbor_maximum_prefix_restart_hidden_cmd,
8450 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [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 "Restart bgp connection after limit is exceeded\n"
8455 "Restart interval in minutes\n"
8456 "Force checking all received routes not only accepted\n")
8457
8458 DEFUN_YANG(neighbor_maximum_prefix_threshold_restart,
8459 neighbor_maximum_prefix_threshold_restart_cmd,
8460 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8461 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8462 "Maximum number of prefixes to accept from this peer\n"
8463 "maximum no. of prefix limit\n"
8464 "Threshold value (%) at which to generate a warning msg\n"
8465 "Restart bgp connection after limit is exceeded\n"
8466 "Restart interval in minutes\n"
8467 "Force checking all received routes not only accepted\n")
8468 {
8469 int idx_peer = 1;
8470 int idx_number = 3;
8471 int idx_number_2 = 4;
8472 int idx_number_3 = 6;
8473 int idx_force = 0;
8474 char base_xpath[XPATH_MAXLEN];
8475 char af_xpath[XPATH_MAXLEN];
8476 char attr_xpath[XPATH_MAXLEN];
8477 afi_t afi = bgp_node_afi(vty);
8478 safi_t safi = bgp_node_safi(vty);
8479
8480 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8481 yang_afi_safi_value2identity(afi, safi));
8482 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8483 sizeof(base_xpath), af_xpath)
8484 < 0)
8485 return CMD_WARNING_CONFIG_FAILED;
8486
8487 snprintf(attr_xpath, sizeof(attr_xpath),
8488 "/%s/prefix-limit/direction-list[direction='in']",
8489 bgp_afi_safi_get_container_str(afi, safi));
8490 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8491
8492 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8493
8494 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8495 argv[idx_number]->arg);
8496 nb_cli_enqueue_change(vty, "./options/tr-shutdown-threshold-pct",
8497 NB_OP_MODIFY, argv[idx_number_2]->arg);
8498 nb_cli_enqueue_change(vty, "./options/tr-restart-timer", NB_OP_MODIFY,
8499 argv[idx_number_3]->arg);
8500 if (argv_find(argv, argc, "force", &idx_force))
8501 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8502 "true");
8503
8504 return nb_cli_apply_changes(vty, base_xpath);
8505 }
8506
8507 ALIAS_HIDDEN(
8508 neighbor_maximum_prefix_threshold_restart,
8509 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
8510 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8511 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8512 "Maximum number of prefixes to accept from this peer\n"
8513 "maximum no. of prefix limit\n"
8514 "Threshold value (%) at which to generate a warning msg\n"
8515 "Restart bgp connection after limit is exceeded\n"
8516 "Restart interval in minutes\n"
8517 "Force checking all received routes not only accepted\n")
8518
8519 DEFUN_YANG(no_neighbor_maximum_prefix,
8520 no_neighbor_maximum_prefix_cmd,
8521 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8522 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8523 "Maximum number of prefixes to accept from this peer\n"
8524 "maximum no. of prefix limit\n"
8525 "Threshold value (%) at which to generate a warning msg\n"
8526 "Restart bgp connection after limit is exceeded\n"
8527 "Restart interval in minutes\n"
8528 "Only give warning message when limit is exceeded\n"
8529 "Force checking all received routes not only accepted\n")
8530 {
8531 int idx_peer = 2;
8532 char base_xpath[XPATH_MAXLEN];
8533 char af_xpath[XPATH_MAXLEN];
8534 char attr_xpath[XPATH_MAXLEN];
8535 afi_t afi = bgp_node_afi(vty);
8536 safi_t safi = bgp_node_safi(vty);
8537
8538 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8539 yang_afi_safi_value2identity(afi, safi));
8540 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8541 sizeof(base_xpath), af_xpath)
8542 < 0)
8543 return CMD_WARNING_CONFIG_FAILED;
8544
8545 snprintf(attr_xpath, sizeof(attr_xpath),
8546 "/%s/prefix-limit/direction-list[direction='in']",
8547 bgp_afi_safi_get_container_str(afi, safi));
8548 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8549
8550 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
8551
8552 return nb_cli_apply_changes(vty, base_xpath);
8553 }
8554
8555 ALIAS_HIDDEN(
8556 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
8557 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8558 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8559 "Maximum number of prefixes to accept from this peer\n"
8560 "maximum no. of prefix limit\n"
8561 "Threshold value (%) at which to generate a warning msg\n"
8562 "Restart bgp connection after limit is exceeded\n"
8563 "Restart interval in minutes\n"
8564 "Only give warning message when limit is exceeded\n"
8565 "Force checking all received routes not only accepted\n")
8566
8567
8568 /* "neighbor allowas-in" */
8569 DEFUN (neighbor_allowas_in,
8570 neighbor_allowas_in_cmd,
8571 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8572 NEIGHBOR_STR
8573 NEIGHBOR_ADDR_STR2
8574 "Accept as-path with my AS present in it\n"
8575 "Number of occurrences of AS number\n"
8576 "Only accept my AS in the as-path if the route was originated in my AS\n")
8577 {
8578 int idx_peer = 1;
8579 int idx_number_origin = 3;
8580 int ret;
8581 int origin = 0;
8582 struct peer *peer;
8583 int allow_num = 0;
8584
8585 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8586 if (!peer)
8587 return CMD_WARNING_CONFIG_FAILED;
8588
8589 if (argc <= idx_number_origin)
8590 allow_num = 3;
8591 else {
8592 if (argv[idx_number_origin]->type == WORD_TKN)
8593 origin = 1;
8594 else
8595 allow_num = atoi(argv[idx_number_origin]->arg);
8596 }
8597
8598 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8599 allow_num, origin);
8600
8601 return bgp_vty_return(vty, ret);
8602 }
8603
8604 ALIAS_HIDDEN(
8605 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
8606 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8607 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8608 "Accept as-path with my AS present in it\n"
8609 "Number of occurrences of AS number\n"
8610 "Only accept my AS in the as-path if the route was originated in my AS\n")
8611
8612 DEFUN (no_neighbor_allowas_in,
8613 no_neighbor_allowas_in_cmd,
8614 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8615 NO_STR
8616 NEIGHBOR_STR
8617 NEIGHBOR_ADDR_STR2
8618 "allow local ASN appears in aspath attribute\n"
8619 "Number of occurrences of AS number\n"
8620 "Only accept my AS in the as-path if the route was originated in my AS\n")
8621 {
8622 int idx_peer = 2;
8623 int ret;
8624 struct peer *peer;
8625
8626 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8627 if (!peer)
8628 return CMD_WARNING_CONFIG_FAILED;
8629
8630 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
8631 bgp_node_safi(vty));
8632
8633 return bgp_vty_return(vty, ret);
8634 }
8635
8636 ALIAS_HIDDEN(
8637 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
8638 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8639 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8640 "allow local ASN appears in aspath attribute\n"
8641 "Number of occurrences of AS number\n"
8642 "Only accept my AS in the as-path if the route was originated in my AS\n")
8643
8644 DEFUN_YANG (neighbor_ttl_security,
8645 neighbor_ttl_security_cmd,
8646 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8647 NEIGHBOR_STR
8648 NEIGHBOR_ADDR_STR2
8649 "BGP ttl-security parameters\n"
8650 "Specify the maximum number of hops to the BGP peer\n"
8651 "Number of hops to BGP peer\n")
8652 {
8653 int idx_peer = 1;
8654 int idx_number = 4;
8655 char base_xpath[XPATH_MAXLEN];
8656
8657 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8658 sizeof(base_xpath), NULL)
8659 < 0)
8660 return CMD_WARNING_CONFIG_FAILED;
8661
8662 nb_cli_enqueue_change(vty, "./ttl-security", NB_OP_MODIFY,
8663 argv[idx_number]->arg);
8664
8665 return nb_cli_apply_changes(vty, base_xpath);
8666 }
8667
8668 DEFUN_YANG(no_neighbor_ttl_security,
8669 no_neighbor_ttl_security_cmd,
8670 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8671 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8672 "BGP ttl-security parameters\n"
8673 "Specify the maximum number of hops to the BGP peer\n"
8674 "Number of hops to BGP peer\n")
8675 {
8676 int idx_peer = 2;
8677 char base_xpath[XPATH_MAXLEN];
8678
8679 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8680 sizeof(base_xpath), NULL)
8681 < 0)
8682 return CMD_WARNING_CONFIG_FAILED;
8683
8684 nb_cli_enqueue_change(vty, "./ttl-security", NB_OP_DESTROY, NULL);
8685
8686 return nb_cli_apply_changes(vty, base_xpath);
8687 }
8688
8689 DEFUN (neighbor_addpath_tx_all_paths,
8690 neighbor_addpath_tx_all_paths_cmd,
8691 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8692 NEIGHBOR_STR
8693 NEIGHBOR_ADDR_STR2
8694 "Use addpath to advertise all paths to a neighbor\n")
8695 {
8696 int idx_peer = 1;
8697 struct peer *peer;
8698
8699 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8700 if (!peer)
8701 return CMD_WARNING_CONFIG_FAILED;
8702
8703 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8704 BGP_ADDPATH_ALL);
8705 return CMD_SUCCESS;
8706 }
8707
8708 ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
8709 neighbor_addpath_tx_all_paths_hidden_cmd,
8710 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8711 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8712 "Use addpath to advertise all paths to a neighbor\n")
8713
8714 DEFUN (no_neighbor_addpath_tx_all_paths,
8715 no_neighbor_addpath_tx_all_paths_cmd,
8716 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8717 NO_STR
8718 NEIGHBOR_STR
8719 NEIGHBOR_ADDR_STR2
8720 "Use addpath to advertise all paths to a neighbor\n")
8721 {
8722 int idx_peer = 2;
8723 struct peer *peer;
8724
8725 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8726 if (!peer)
8727 return CMD_WARNING_CONFIG_FAILED;
8728
8729 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8730 != BGP_ADDPATH_ALL) {
8731 vty_out(vty,
8732 "%% Peer not currently configured to transmit all paths.");
8733 return CMD_WARNING_CONFIG_FAILED;
8734 }
8735
8736 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8737 BGP_ADDPATH_NONE);
8738
8739 return CMD_SUCCESS;
8740 }
8741
8742 ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
8743 no_neighbor_addpath_tx_all_paths_hidden_cmd,
8744 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8745 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8746 "Use addpath to advertise all paths to a neighbor\n")
8747
8748 DEFUN (neighbor_addpath_tx_bestpath_per_as,
8749 neighbor_addpath_tx_bestpath_per_as_cmd,
8750 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8751 NEIGHBOR_STR
8752 NEIGHBOR_ADDR_STR2
8753 "Use addpath to advertise the bestpath per each neighboring AS\n")
8754 {
8755 int idx_peer = 1;
8756 struct peer *peer;
8757
8758 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8759 if (!peer)
8760 return CMD_WARNING_CONFIG_FAILED;
8761
8762 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8763 BGP_ADDPATH_BEST_PER_AS);
8764
8765 return CMD_SUCCESS;
8766 }
8767
8768 ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
8769 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8770 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8771 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8772 "Use addpath to advertise the bestpath per each neighboring AS\n")
8773
8774 DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
8775 no_neighbor_addpath_tx_bestpath_per_as_cmd,
8776 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8777 NO_STR
8778 NEIGHBOR_STR
8779 NEIGHBOR_ADDR_STR2
8780 "Use addpath to advertise the bestpath per each neighboring AS\n")
8781 {
8782 int idx_peer = 2;
8783 struct peer *peer;
8784
8785 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8786 if (!peer)
8787 return CMD_WARNING_CONFIG_FAILED;
8788
8789 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8790 != BGP_ADDPATH_BEST_PER_AS) {
8791 vty_out(vty,
8792 "%% Peer not currently configured to transmit all best path per as.");
8793 return CMD_WARNING_CONFIG_FAILED;
8794 }
8795
8796 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8797 BGP_ADDPATH_NONE);
8798
8799 return CMD_SUCCESS;
8800 }
8801
8802 ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
8803 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8804 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8805 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8806 "Use addpath to advertise the bestpath per each neighboring AS\n")
8807
8808 DEFPY(
8809 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
8810 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8811 NEIGHBOR_STR
8812 NEIGHBOR_ADDR_STR2
8813 "Detect AS loops before sending to neighbor\n")
8814 {
8815 struct peer *peer;
8816
8817 peer = peer_and_group_lookup_vty(vty, neighbor);
8818 if (!peer)
8819 return CMD_WARNING_CONFIG_FAILED;
8820
8821 peer->as_path_loop_detection = true;
8822
8823 return CMD_SUCCESS;
8824 }
8825
8826 DEFPY(
8827 no_neighbor_aspath_loop_detection,
8828 no_neighbor_aspath_loop_detection_cmd,
8829 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8830 NO_STR
8831 NEIGHBOR_STR
8832 NEIGHBOR_ADDR_STR2
8833 "Detect AS loops before sending to neighbor\n")
8834 {
8835 struct peer *peer;
8836
8837 peer = peer_and_group_lookup_vty(vty, neighbor);
8838 if (!peer)
8839 return CMD_WARNING_CONFIG_FAILED;
8840
8841 peer->as_path_loop_detection = false;
8842
8843 return CMD_SUCCESS;
8844 }
8845
8846 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
8847 struct ecommunity **list, bool is_rt6)
8848 {
8849 struct ecommunity *ecom = NULL;
8850 struct ecommunity *ecomadd;
8851
8852 for (; argc; --argc, ++argv) {
8853 if (is_rt6)
8854 ecomadd = ecommunity_str2com_ipv6(argv[0]->arg,
8855 ECOMMUNITY_ROUTE_TARGET,
8856 0);
8857 else
8858 ecomadd = ecommunity_str2com(argv[0]->arg,
8859 ECOMMUNITY_ROUTE_TARGET,
8860 0);
8861 if (!ecomadd) {
8862 vty_out(vty, "Malformed community-list value\n");
8863 if (ecom)
8864 ecommunity_free(&ecom);
8865 return CMD_WARNING_CONFIG_FAILED;
8866 }
8867
8868 if (ecom) {
8869 ecommunity_merge(ecom, ecomadd);
8870 ecommunity_free(&ecomadd);
8871 } else {
8872 ecom = ecomadd;
8873 }
8874 }
8875
8876 if (*list) {
8877 ecommunity_free(&*list);
8878 }
8879 *list = ecom;
8880
8881 return CMD_SUCCESS;
8882 }
8883
8884 bool vpn_policy_check_import(struct bgp *bgp, afi_t afi, safi_t safi,
8885 bool v2vimport, char *errmsg, size_t errmsg_len)
8886 {
8887 if (!v2vimport) {
8888 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8889 BGP_CONFIG_VRF_TO_VRF_IMPORT)
8890 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8891 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
8892 snprintf(
8893 errmsg, errmsg_len, "%s",
8894 "%% error: Please unconfigure import vrf commands before using vpn commands");
8895 return false;
8896 }
8897 } else {
8898 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8899 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
8900 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8901 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
8902 snprintf(
8903 errmsg, errmsg_len, "%s",
8904 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands");
8905 return false;
8906 }
8907 }
8908 return true;
8909 }
8910
8911 /*
8912 * v2vimport is true if we are handling a `import vrf ...` command
8913 */
8914 static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
8915 {
8916 afi_t afi;
8917
8918 switch (vty->node) {
8919 case BGP_IPV4_NODE:
8920 afi = AFI_IP;
8921 break;
8922 case BGP_IPV6_NODE:
8923 afi = AFI_IP6;
8924 break;
8925 default:
8926 vty_out(vty,
8927 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
8928 return AFI_MAX;
8929 }
8930
8931 if (!v2vimport) {
8932 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8933 BGP_CONFIG_VRF_TO_VRF_IMPORT)
8934 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8935 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
8936 vty_out(vty,
8937 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
8938 return AFI_MAX;
8939 }
8940 } else {
8941 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8942 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
8943 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8944 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
8945 vty_out(vty,
8946 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
8947 return AFI_MAX;
8948 }
8949 }
8950 return afi;
8951 }
8952
8953 DEFPY_YANG(
8954 af_rd_vpn_export,
8955 af_rd_vpn_export_cmd,
8956 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
8957 NO_STR
8958 "Specify route distinguisher\n"
8959 "Between current address-family and vpn\n"
8960 "For routes leaked from current address-family to vpn\n"
8961 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
8962 {
8963 char base_xpath[XPATH_MAXLEN];
8964 afi_t afi;
8965 safi_t safi;
8966 int idx = 0;
8967
8968 afi = bgp_node_afi(vty);
8969 safi = bgp_node_safi(vty);
8970
8971 snprintf(
8972 base_xpath, sizeof(base_xpath),
8973 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config",
8974 yang_afi_safi_value2identity(afi, safi),
8975 bgp_afi_safi_get_container_str(afi, safi));
8976
8977 if (argv_find(argv, argc, "no", &idx))
8978 nb_cli_enqueue_change(vty, "./rd", NB_OP_DESTROY, NULL);
8979 else
8980 nb_cli_enqueue_change(vty, "./rd", NB_OP_MODIFY, rd_str);
8981
8982 return nb_cli_apply_changes(vty, base_xpath);
8983 }
8984
8985 void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rd(
8986 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
8987 {
8988 int indent = 2;
8989
8990 vty_out(vty, "%*srd vpn export %s\n", indent, "",
8991 yang_dnode_get_string(dnode, NULL));
8992 }
8993
8994 ALIAS (af_rd_vpn_export,
8995 af_no_rd_vpn_export_cmd,
8996 "no rd vpn export",
8997 NO_STR
8998 "Specify route distinguisher\n"
8999 "Between current address-family and vpn\n"
9000 "For routes leaked from current address-family to vpn\n")
9001
9002 DEFPY (af_label_vpn_export,
9003 af_label_vpn_export_cmd,
9004 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
9005 NO_STR
9006 "label value for VRF\n"
9007 "Between current address-family and vpn\n"
9008 "For routes leaked from current address-family to vpn\n"
9009 "Label Value <0-1048575>\n"
9010 "Automatically assign a label\n")
9011 {
9012 VTY_DECLVAR_CONTEXT(bgp, bgp);
9013 mpls_label_t label = MPLS_LABEL_NONE;
9014 afi_t afi;
9015 int idx = 0;
9016 bool yes = true;
9017
9018 if (argv_find(argv, argc, "no", &idx))
9019 yes = false;
9020
9021 /* If "no ...", squash trailing parameter */
9022 if (!yes)
9023 label_auto = NULL;
9024
9025 if (yes) {
9026 if (!label_auto)
9027 label = label_val; /* parser should force unsigned */
9028 }
9029
9030 afi = vpn_policy_getafi(vty, bgp, false);
9031 if (afi == AFI_MAX)
9032 return CMD_WARNING_CONFIG_FAILED;
9033
9034
9035 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9036 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
9037 /* no change */
9038 return CMD_SUCCESS;
9039
9040 /*
9041 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
9042 */
9043 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9044 bgp_get_default(), bgp);
9045
9046 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9047 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
9048
9049 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
9050
9051 /*
9052 * label has previously been automatically
9053 * assigned by labelpool: release it
9054 *
9055 * NB if tovpn_label == MPLS_LABEL_NONE it
9056 * means the automatic assignment is in flight
9057 * and therefore the labelpool callback must
9058 * detect that the auto label is not needed.
9059 */
9060
9061 bgp_lp_release(LP_TYPE_VRF,
9062 &bgp->vpn_policy[afi],
9063 bgp->vpn_policy[afi].tovpn_label);
9064 }
9065 UNSET_FLAG(bgp->vpn_policy[afi].flags,
9066 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
9067 }
9068
9069 bgp->vpn_policy[afi].tovpn_label = label;
9070 if (label_auto) {
9071 SET_FLAG(bgp->vpn_policy[afi].flags,
9072 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
9073 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
9074 vpn_leak_label_callback);
9075 }
9076
9077 /* post-change: re-export vpn routes */
9078 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9079 bgp_get_default(), bgp);
9080
9081 return CMD_SUCCESS;
9082 }
9083
9084 ALIAS (af_label_vpn_export,
9085 af_no_label_vpn_export_cmd,
9086 "no label vpn export",
9087 NO_STR
9088 "label value for VRF\n"
9089 "Between current address-family and vpn\n"
9090 "For routes leaked from current address-family to vpn\n")
9091
9092 DEFPY_YANG (af_nexthop_vpn_export,
9093 af_nexthop_vpn_export_cmd,
9094 "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
9095 NO_STR
9096 "Specify next hop to use for VRF advertised prefixes\n"
9097 "Between current address-family and vpn\n"
9098 "For routes leaked from current address-family to vpn\n"
9099 "IPv4 prefix\n"
9100 "IPv6 prefix\n")
9101 {
9102 char base_xpath[XPATH_MAXLEN];
9103 afi_t afi;
9104 safi_t safi;
9105 int idx = 0;
9106 struct prefix p;
9107
9108 if (!no) {
9109 if (!nexthop_su) {
9110 vty_out(vty, "%% Nexthop required\n");
9111 return CMD_WARNING_CONFIG_FAILED;
9112 }
9113 if (!sockunion2hostprefix(nexthop_su, &p))
9114 return CMD_WARNING_CONFIG_FAILED;
9115 }
9116
9117 afi = bgp_node_afi(vty);
9118 safi = bgp_node_safi(vty);
9119
9120 snprintf(
9121 base_xpath, sizeof(base_xpath),
9122 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config",
9123 yang_afi_safi_value2identity(afi, safi),
9124 bgp_afi_safi_get_container_str(afi, safi));
9125
9126 if (argv_find(argv, argc, "no", &idx))
9127 nb_cli_enqueue_change(vty, "./nexthop", NB_OP_DESTROY, NULL);
9128 else
9129 nb_cli_enqueue_change(vty, "./nexthop", NB_OP_MODIFY,
9130 nexthop_su_str);
9131
9132 return nb_cli_apply_changes(vty, base_xpath);
9133 }
9134
9135 void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_nexthop(
9136 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9137 {
9138 int indent = 2;
9139
9140 vty_out(vty, "%*snexthop vpn export %s\n", indent, "",
9141 yang_dnode_get_string(dnode, NULL));
9142 }
9143
9144 static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
9145 {
9146 if (!strcmp(dstr, "import")) {
9147 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9148 } else if (!strcmp(dstr, "export")) {
9149 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9150 } else if (!strcmp(dstr, "both")) {
9151 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9152 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9153 } else {
9154 vty_out(vty, "%% direction parse error\n");
9155 return CMD_WARNING_CONFIG_FAILED;
9156 }
9157 return CMD_SUCCESS;
9158 }
9159
9160 DEFPY (af_rt_vpn_imexport,
9161 af_rt_vpn_imexport_cmd,
9162 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
9163 NO_STR
9164 "Specify route target list\n"
9165 "Specify route target list\n"
9166 "Between current address-family and vpn\n"
9167 "For routes leaked from vpn to current address-family: match any\n"
9168 "For routes leaked from current address-family to vpn: set\n"
9169 "both import: match any and export: set\n"
9170 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
9171 {
9172 VTY_DECLVAR_CONTEXT(bgp, bgp);
9173 int ret;
9174 struct ecommunity *ecom = NULL;
9175 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
9176 vpn_policy_direction_t dir;
9177 afi_t afi;
9178 int idx = 0;
9179 bool yes = true;
9180
9181 if (argv_find(argv, argc, "no", &idx))
9182 yes = false;
9183
9184 afi = vpn_policy_getafi(vty, bgp, false);
9185 if (afi == AFI_MAX)
9186 return CMD_WARNING_CONFIG_FAILED;
9187
9188 ret = vpn_policy_getdirs(vty, direction_str, dodir);
9189 if (ret != CMD_SUCCESS)
9190 return ret;
9191
9192 if (yes) {
9193 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9194 vty_out(vty, "%% Missing RTLIST\n");
9195 return CMD_WARNING_CONFIG_FAILED;
9196 }
9197 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, false);
9198 if (ret != CMD_SUCCESS) {
9199 return ret;
9200 }
9201 }
9202
9203 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9204 if (!dodir[dir])
9205 continue;
9206
9207 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9208
9209 if (yes) {
9210 if (bgp->vpn_policy[afi].rtlist[dir])
9211 ecommunity_free(
9212 &bgp->vpn_policy[afi].rtlist[dir]);
9213 bgp->vpn_policy[afi].rtlist[dir] =
9214 ecommunity_dup(ecom);
9215 } else {
9216 if (bgp->vpn_policy[afi].rtlist[dir])
9217 ecommunity_free(
9218 &bgp->vpn_policy[afi].rtlist[dir]);
9219 bgp->vpn_policy[afi].rtlist[dir] = NULL;
9220 }
9221
9222 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9223 }
9224
9225 if (ecom)
9226 ecommunity_free(&ecom);
9227
9228 return CMD_SUCCESS;
9229 }
9230
9231 ALIAS (af_rt_vpn_imexport,
9232 af_no_rt_vpn_imexport_cmd,
9233 "no <rt|route-target> vpn <import|export|both>$direction_str",
9234 NO_STR
9235 "Specify route target list\n"
9236 "Specify route target list\n"
9237 "Between current address-family and vpn\n"
9238 "For routes leaked from vpn to current address-family\n"
9239 "For routes leaked from current address-family to vpn\n"
9240 "both import and export\n")
9241
9242 DEFPY_YANG (af_route_map_vpn_imexport,
9243 af_route_map_vpn_imexport_cmd,
9244 /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
9245 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
9246 NO_STR
9247 "Specify route map\n"
9248 "Between current address-family and vpn\n"
9249 "For routes leaked from vpn to current address-family\n"
9250 "For routes leaked from current address-family to vpn\n"
9251 "name of route-map\n")
9252 {
9253 char base_xpath[XPATH_MAXLEN];
9254 afi_t afi;
9255 safi_t safi;
9256 int idx = 0;
9257
9258 afi = bgp_node_afi(vty);
9259 safi = bgp_node_safi(vty);
9260
9261 snprintf(
9262 base_xpath, sizeof(base_xpath),
9263 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config",
9264 yang_afi_safi_value2identity(afi, safi),
9265 bgp_afi_safi_get_container_str(afi, safi));
9266
9267 if (argv_find(argv, argc, "no", &idx)) {
9268 if (!strcmp(direction_str, "import"))
9269 nb_cli_enqueue_change(vty, "./rmap-import",
9270 NB_OP_DESTROY, NULL);
9271 else if (!strcmp(direction_str, "export"))
9272 nb_cli_enqueue_change(vty, "./rmap-export",
9273 NB_OP_DESTROY, NULL);
9274 } else {
9275 if (!strcmp(direction_str, "import"))
9276 nb_cli_enqueue_change(vty, "./rmap-import",
9277 NB_OP_MODIFY, rmap_str);
9278 if (!strcmp(direction_str, "export"))
9279 nb_cli_enqueue_change(vty, "./rmap-export",
9280 NB_OP_MODIFY, rmap_str);
9281 }
9282 return nb_cli_apply_changes(vty, base_xpath);
9283 }
9284
9285 void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rmap_import(
9286 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9287 {
9288 int indent = 2;
9289
9290 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
9291 yang_dnode_get_string(dnode, NULL));
9292 }
9293
9294 void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rmap_export(
9295 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9296 {
9297 int indent = 2;
9298
9299 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
9300 yang_dnode_get_string(dnode, NULL));
9301 }
9302
9303 ALIAS (af_route_map_vpn_imexport,
9304 af_no_route_map_vpn_imexport_cmd,
9305 "no route-map vpn <import|export>$direction_str",
9306 NO_STR
9307 "Specify route map\n"
9308 "Between current address-family and vpn\n"
9309 "For routes leaked from vpn to current address-family\n"
9310 "For routes leaked from current address-family to vpn\n")
9311
9312 DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
9313 "import vrf route-map RMAP$rmap_str",
9314 "Import routes from another VRF\n"
9315 "Vrf routes being filtered\n"
9316 "Specify route map\n"
9317 "name of route-map\n")
9318 {
9319 VTY_DECLVAR_CONTEXT(bgp, bgp);
9320 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
9321 afi_t afi;
9322 struct bgp *bgp_default;
9323
9324 afi = vpn_policy_getafi(vty, bgp, true);
9325 if (afi == AFI_MAX)
9326 return CMD_WARNING_CONFIG_FAILED;
9327
9328 bgp_default = bgp_get_default();
9329 if (!bgp_default) {
9330 int32_t ret;
9331 as_t as = bgp->as;
9332
9333 /* Auto-create assuming the same AS */
9334 ret = bgp_get_vty(&bgp_default, &as, NULL,
9335 BGP_INSTANCE_TYPE_DEFAULT);
9336
9337 if (ret) {
9338 vty_out(vty,
9339 "VRF default is not configured as a bgp instance\n");
9340 return CMD_WARNING;
9341 }
9342 }
9343
9344 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9345
9346 if (bgp->vpn_policy[afi].rmap_name[dir])
9347 XFREE(MTYPE_ROUTE_MAP_NAME,
9348 bgp->vpn_policy[afi].rmap_name[dir]);
9349 bgp->vpn_policy[afi].rmap_name[dir] =
9350 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
9351 bgp->vpn_policy[afi].rmap[dir] =
9352 route_map_lookup_warn_noexist(vty, rmap_str);
9353 if (!bgp->vpn_policy[afi].rmap[dir])
9354 return CMD_SUCCESS;
9355
9356 SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9357 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9358
9359 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9360
9361 return CMD_SUCCESS;
9362 }
9363
9364 DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
9365 "no import vrf route-map [RMAP$rmap_str]",
9366 NO_STR
9367 "Import routes from another VRF\n"
9368 "Vrf routes being filtered\n"
9369 "Specify route map\n"
9370 "name of route-map\n")
9371 {
9372 VTY_DECLVAR_CONTEXT(bgp, bgp);
9373 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
9374 afi_t afi;
9375
9376 afi = vpn_policy_getafi(vty, bgp, true);
9377 if (afi == AFI_MAX)
9378 return CMD_WARNING_CONFIG_FAILED;
9379
9380 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9381
9382 if (bgp->vpn_policy[afi].rmap_name[dir])
9383 XFREE(MTYPE_ROUTE_MAP_NAME,
9384 bgp->vpn_policy[afi].rmap_name[dir]);
9385 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9386 bgp->vpn_policy[afi].rmap[dir] = NULL;
9387
9388 if (bgp->vpn_policy[afi].import_vrf->count == 0)
9389 UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9390 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9391
9392 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9393
9394 return CMD_SUCCESS;
9395 }
9396
9397 DEFPY_YANG(bgp_imexport_vrf,
9398 bgp_imexport_vrf_cmd,
9399 "[no] import vrf VIEWVRFNAME$import_name",
9400 NO_STR
9401 "Import routes from another VRF\n"
9402 "VRF to import from\n"
9403 "The name of the VRF\n")
9404 {
9405 char base_xpath[XPATH_MAXLEN];
9406 safi_t safi;
9407 afi_t afi;
9408 int32_t idx = 0;
9409
9410 if (import_name == NULL) {
9411 vty_out(vty, "%% Missing import name\n");
9412 return CMD_WARNING;
9413 }
9414
9415 if (strcmp(import_name, "route-map") == 0) {
9416 vty_out(vty, "%% Must include route-map name\n");
9417 return CMD_WARNING;
9418 }
9419
9420 afi = bgp_node_afi(vty);
9421 safi = bgp_node_safi(vty);
9422
9423 snprintf(
9424 base_xpath, sizeof(base_xpath),
9425 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config/import-vrf-list[vrf='%s']",
9426 yang_afi_safi_value2identity(afi, safi),
9427 bgp_afi_safi_get_container_str(afi, safi), import_name);
9428
9429 if (argv_find(argv, argc, "no", &idx))
9430 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
9431 else
9432 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
9433
9434 return nb_cli_apply_changes(vty, base_xpath);
9435 }
9436
9437 void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_import_vrfs(
9438 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9439 {
9440 vty_out(vty, " import vrf %s\n",
9441 yang_dnode_get_string(dnode, "./vrf"));
9442 }
9443
9444 /* This command is valid only in a bgp vrf instance or the default instance */
9445 DEFPY_YANG (bgp_imexport_vpn,
9446 bgp_imexport_vpn_cmd,
9447 "[no] <import|export>$direction_str vpn",
9448 NO_STR
9449 "Import routes to this address-family\n"
9450 "Export routes from this address-family\n"
9451 "to/from default instance VPN RIB\n")
9452 {
9453 char base_xpath[XPATH_MAXLEN];
9454 safi_t safi;
9455 afi_t afi;
9456 int32_t idx = 0;
9457
9458 afi = bgp_node_afi(vty);
9459 safi = bgp_node_safi(vty);
9460
9461 if (!strcmp(direction_str, "import")) {
9462 snprintf(
9463 base_xpath, sizeof(base_xpath),
9464 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config/import-vpn",
9465 yang_afi_safi_value2identity(afi, safi),
9466 bgp_afi_safi_get_container_str(afi, safi));
9467 } else if (!strcmp(direction_str, "export")) {
9468 snprintf(
9469 base_xpath, sizeof(base_xpath),
9470 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config/export-vpn",
9471 yang_afi_safi_value2identity(afi, safi),
9472 bgp_afi_safi_get_container_str(afi, safi));
9473 } else {
9474 vty_out(vty, "%% unknown direction %s\n", direction_str);
9475 return CMD_WARNING_CONFIG_FAILED;
9476 }
9477
9478 if (argv_find(argv, argc, "no", &idx))
9479 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
9480 else
9481 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, "true");
9482
9483 return nb_cli_apply_changes(vty, base_xpath);
9484 }
9485
9486 void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_import_vpn(
9487 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9488 {
9489 if (yang_dnode_get_bool(dnode, NULL))
9490 vty_out(vty, " import vpn\n");
9491 }
9492
9493 void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_export_vpn(
9494 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9495 {
9496 if (yang_dnode_get_bool(dnode, NULL))
9497 vty_out(vty, " export vpn\n");
9498 }
9499
9500 DEFPY (af_routetarget_import,
9501 af_routetarget_import_cmd,
9502 "[no] <rt|route-target|route-target6|rt6> redirect import RTLIST...",
9503 NO_STR
9504 "Specify route target list\n"
9505 "Specify route target list\n"
9506 "Specify route target list\n"
9507 "Specify route target list\n"
9508 "Flow-spec redirect type route target\n"
9509 "Import routes to this address-family\n"
9510 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN|IPV6:MN)\n")
9511 {
9512 VTY_DECLVAR_CONTEXT(bgp, bgp);
9513 int ret;
9514 struct ecommunity *ecom = NULL;
9515 afi_t afi;
9516 int idx = 0, idx_unused = 0;
9517 bool yes = true;
9518 bool rt6 = false;
9519
9520 if (argv_find(argv, argc, "no", &idx))
9521 yes = false;
9522
9523 if (argv_find(argv, argc, "rt6", &idx_unused) ||
9524 argv_find(argv, argc, "route-target6", &idx_unused))
9525 rt6 = true;
9526
9527 afi = vpn_policy_getafi(vty, bgp, false);
9528 if (afi == AFI_MAX)
9529 return CMD_WARNING_CONFIG_FAILED;
9530
9531 if (rt6 && afi != AFI_IP6)
9532 return CMD_WARNING_CONFIG_FAILED;
9533
9534 if (yes) {
9535 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9536 vty_out(vty, "%% Missing RTLIST\n");
9537 return CMD_WARNING_CONFIG_FAILED;
9538 }
9539 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, rt6);
9540 if (ret != CMD_SUCCESS)
9541 return ret;
9542 }
9543
9544 if (yes) {
9545 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9546 ecommunity_free(&bgp->vpn_policy[afi]
9547 .import_redirect_rtlist);
9548 bgp->vpn_policy[afi].import_redirect_rtlist =
9549 ecommunity_dup(ecom);
9550 } else {
9551 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9552 ecommunity_free(&bgp->vpn_policy[afi]
9553 .import_redirect_rtlist);
9554 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
9555 }
9556
9557 if (ecom)
9558 ecommunity_free(&ecom);
9559
9560 return CMD_SUCCESS;
9561 }
9562
9563 void cli_show_bgp_global_afi_safi_header(struct vty *vty,
9564 struct lyd_node *dnode,
9565 bool show_defaults)
9566 {
9567 const char *af_name;
9568 afi_t afi;
9569 safi_t safi;
9570
9571 af_name = yang_dnode_get_string(dnode, "./afi-safi-name");
9572 yang_afi_safi_identity2value(af_name, &afi, &safi);
9573
9574 vty_out(vty, " !\n address-family ");
9575 if (afi == AFI_IP) {
9576 if (safi == SAFI_UNICAST)
9577 vty_out(vty, "ipv4 unicast");
9578 else if (safi == SAFI_LABELED_UNICAST)
9579 vty_out(vty, "ipv4 labeled-unicast");
9580 else if (safi == SAFI_MULTICAST)
9581 vty_out(vty, "ipv4 multicast");
9582 else if (safi == SAFI_MPLS_VPN)
9583 vty_out(vty, "ipv4 vpn");
9584 else if (safi == SAFI_ENCAP)
9585 vty_out(vty, "ipv4 encap");
9586 else if (safi == SAFI_FLOWSPEC)
9587 vty_out(vty, "ipv4 flowspec");
9588 } else if (afi == AFI_IP6) {
9589 if (safi == SAFI_UNICAST)
9590 vty_out(vty, "ipv6 unicast");
9591 else if (safi == SAFI_LABELED_UNICAST)
9592 vty_out(vty, "ipv6 labeled-unicast");
9593 else if (safi == SAFI_MULTICAST)
9594 vty_out(vty, "ipv6 multicast");
9595 else if (safi == SAFI_MPLS_VPN)
9596 vty_out(vty, "ipv6 vpn");
9597 else if (safi == SAFI_ENCAP)
9598 vty_out(vty, "ipv6 encap");
9599 else if (safi == SAFI_FLOWSPEC)
9600 vty_out(vty, "ipv6 flowspec");
9601 } else if (afi == AFI_L2VPN) {
9602 if (safi == SAFI_EVPN)
9603 vty_out(vty, "l2vpn evpn");
9604 }
9605 vty_out(vty, "\n");
9606 }
9607
9608 DEFUN_NOSH (address_family_ipv4_safi,
9609 address_family_ipv4_safi_cmd,
9610 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9611 "Enter Address Family command mode\n"
9612 "Address Family\n"
9613 BGP_SAFI_WITH_LABEL_HELP_STR)
9614 {
9615
9616 safi_t safi = SAFI_UNICAST;
9617 const struct lyd_node *vrf_dnode, *bgp_glb_dnode;
9618 const char *vrf_name = NULL;
9619
9620 if (argc == 3) {
9621 safi = bgp_vty_safi_from_str(argv[2]->text);
9622
9623 bgp_glb_dnode = yang_dnode_get(vty->candidate_config->dnode,
9624 VTY_CURR_XPATH);
9625 vrf_dnode = yang_dnode_get_parent(bgp_glb_dnode,
9626 "control-plane-protocol");
9627 vrf_name = yang_dnode_get_string(vrf_dnode, "./vrf");
9628
9629 if (!strmatch(vrf_name, VRF_DEFAULT_NAME)
9630 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9631 && safi != SAFI_EVPN) {
9632 vty_out(vty,
9633 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9634 return CMD_WARNING_CONFIG_FAILED;
9635 }
9636 }
9637 vty->node = bgp_node_type(AFI_IP, safi);
9638
9639 return CMD_SUCCESS;
9640 }
9641
9642 DEFUN_NOSH (address_family_ipv6_safi,
9643 address_family_ipv6_safi_cmd,
9644 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9645 "Enter Address Family command mode\n"
9646 "Address Family\n"
9647 BGP_SAFI_WITH_LABEL_HELP_STR)
9648 {
9649 safi_t safi = SAFI_UNICAST;
9650 const struct lyd_node *vrf_dnode, *bgp_glb_dnode;
9651 const char *vrf_name = NULL;
9652
9653 if (argc == 3) {
9654 safi = bgp_vty_safi_from_str(argv[2]->text);
9655 bgp_glb_dnode = yang_dnode_get(vty->candidate_config->dnode,
9656 VTY_CURR_XPATH);
9657 vrf_dnode = yang_dnode_get_parent(bgp_glb_dnode,
9658 "control-plane-protocol");
9659 vrf_name = yang_dnode_get_string(vrf_dnode, "./vrf");
9660
9661 if (!strmatch(vrf_name, VRF_DEFAULT_NAME)
9662 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9663 && safi != SAFI_EVPN) {
9664 vty_out(vty,
9665 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9666 return CMD_WARNING_CONFIG_FAILED;
9667 }
9668 }
9669 vty->node = bgp_node_type(AFI_IP6, safi);
9670
9671 return CMD_SUCCESS;
9672 }
9673
9674 #ifdef KEEP_OLD_VPN_COMMANDS
9675 DEFUN_NOSH (address_family_vpnv4,
9676 address_family_vpnv4_cmd,
9677 "address-family vpnv4 [unicast]",
9678 "Enter Address Family command mode\n"
9679 "Address Family\n"
9680 "Address Family modifier\n")
9681 {
9682 vty->node = BGP_VPNV4_NODE;
9683 return CMD_SUCCESS;
9684 }
9685
9686 DEFUN_NOSH (address_family_vpnv6,
9687 address_family_vpnv6_cmd,
9688 "address-family vpnv6 [unicast]",
9689 "Enter Address Family command mode\n"
9690 "Address Family\n"
9691 "Address Family modifier\n")
9692 {
9693 vty->node = BGP_VPNV6_NODE;
9694 return CMD_SUCCESS;
9695 }
9696 #endif /* KEEP_OLD_VPN_COMMANDS */
9697
9698 DEFUN_NOSH (address_family_evpn,
9699 address_family_evpn_cmd,
9700 "address-family l2vpn evpn",
9701 "Enter Address Family command mode\n"
9702 "Address Family\n"
9703 "Address Family modifier\n")
9704 {
9705 VTY_DECLVAR_CONTEXT(bgp, bgp);
9706 vty->node = BGP_EVPN_NODE;
9707 return CMD_SUCCESS;
9708 }
9709
9710 DEFUN_NOSH (exit_address_family,
9711 exit_address_family_cmd,
9712 "exit-address-family",
9713 "Exit from Address Family configuration mode\n")
9714 {
9715 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
9716 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
9717 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
9718 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
9719 || vty->node == BGP_EVPN_NODE
9720 || vty->node == BGP_FLOWSPECV4_NODE
9721 || vty->node == BGP_FLOWSPECV6_NODE)
9722 vty->node = BGP_NODE;
9723 return CMD_SUCCESS;
9724 }
9725
9726 void cli_show_bgp_global_afi_safi_header_end(struct vty *vty,
9727 struct lyd_node *dnode
9728 __attribute__((__unused__)))
9729 {
9730 vty_out(vty, " exit-address-family\n");
9731 }
9732
9733 /* Recalculate bestpath and re-advertise a prefix */
9734 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
9735 const char *ip_str, afi_t afi, safi_t safi,
9736 struct prefix_rd *prd)
9737 {
9738 int ret;
9739 struct prefix match;
9740 struct bgp_dest *dest;
9741 struct bgp_dest *rm;
9742 struct bgp *bgp;
9743 struct bgp_table *table;
9744 struct bgp_table *rib;
9745
9746 /* BGP structure lookup. */
9747 if (view_name) {
9748 bgp = bgp_lookup_by_name(view_name);
9749 if (bgp == NULL) {
9750 vty_out(vty, "%% Can't find BGP instance %s\n",
9751 view_name);
9752 return CMD_WARNING;
9753 }
9754 } else {
9755 bgp = bgp_get_default();
9756 if (bgp == NULL) {
9757 vty_out(vty, "%% No BGP process is configured\n");
9758 return CMD_WARNING;
9759 }
9760 }
9761
9762 /* Check IP address argument. */
9763 ret = str2prefix(ip_str, &match);
9764 if (!ret) {
9765 vty_out(vty, "%% address is malformed\n");
9766 return CMD_WARNING;
9767 }
9768
9769 match.family = afi2family(afi);
9770 rib = bgp->rib[afi][safi];
9771
9772 if (safi == SAFI_MPLS_VPN) {
9773 for (dest = bgp_table_top(rib); dest;
9774 dest = bgp_route_next(dest)) {
9775 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
9776
9777 if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
9778 continue;
9779
9780 table = bgp_dest_get_bgp_table_info(dest);
9781 if (table == NULL)
9782 continue;
9783
9784 if ((rm = bgp_node_match(table, &match)) != NULL) {
9785 const struct prefix *rm_p =
9786 bgp_dest_get_prefix(rm);
9787
9788 if (rm_p->prefixlen == match.prefixlen) {
9789 SET_FLAG(rm->flags,
9790 BGP_NODE_USER_CLEAR);
9791 bgp_process(bgp, rm, afi, safi);
9792 }
9793 bgp_dest_unlock_node(rm);
9794 }
9795 }
9796 } else {
9797 if ((dest = bgp_node_match(rib, &match)) != NULL) {
9798 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
9799
9800 if (dest_p->prefixlen == match.prefixlen) {
9801 SET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
9802 bgp_process(bgp, dest, afi, safi);
9803 }
9804 bgp_dest_unlock_node(dest);
9805 }
9806 }
9807
9808 return CMD_SUCCESS;
9809 }
9810
9811 /* one clear bgp command to rule them all */
9812 DEFUN (clear_ip_bgp_all,
9813 clear_ip_bgp_all_cmd,
9814 "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>]",
9815 CLEAR_STR
9816 IP_STR
9817 BGP_STR
9818 BGP_INSTANCE_HELP_STR
9819 BGP_AFI_HELP_STR
9820 "Address Family\n"
9821 BGP_SAFI_WITH_LABEL_HELP_STR
9822 "Address Family modifier\n"
9823 "Clear all peers\n"
9824 "BGP IPv4 neighbor to clear\n"
9825 "BGP IPv6 neighbor to clear\n"
9826 "BGP neighbor on interface to clear\n"
9827 "Clear peers with the AS number\n"
9828 "Clear all external peers\n"
9829 "Clear all members of peer-group\n"
9830 "BGP peer-group name\n"
9831 BGP_SOFT_STR
9832 BGP_SOFT_IN_STR
9833 BGP_SOFT_OUT_STR
9834 BGP_SOFT_IN_STR
9835 "Push out prefix-list ORF and do inbound soft reconfig\n"
9836 BGP_SOFT_OUT_STR)
9837 {
9838 char *vrf = NULL;
9839
9840 afi_t afi = AFI_UNSPEC;
9841 safi_t safi = SAFI_UNSPEC;
9842 enum clear_sort clr_sort = clear_peer;
9843 enum bgp_clear_type clr_type;
9844 char *clr_arg = NULL;
9845
9846 int idx = 0;
9847 char errmsg[BUFSIZ] = {'\0'};
9848 int ret;
9849
9850 /* clear [ip] bgp */
9851 if (argv_find(argv, argc, "ip", &idx))
9852 afi = AFI_IP;
9853
9854 /* [<vrf> VIEWVRFNAME] */
9855 if (argv_find(argv, argc, "vrf", &idx)) {
9856 vrf = argv[idx + 1]->arg;
9857 idx += 2;
9858 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9859 vrf = NULL;
9860 } else if (argv_find(argv, argc, "view", &idx)) {
9861 /* [<view> VIEWVRFNAME] */
9862 vrf = argv[idx + 1]->arg;
9863 idx += 2;
9864 }
9865 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
9866 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
9867 argv_find_and_parse_safi(argv, argc, &idx, &safi);
9868
9869 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
9870 if (argv_find(argv, argc, "*", &idx)) {
9871 clr_sort = clear_all;
9872 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
9873 clr_sort = clear_peer;
9874 clr_arg = argv[idx]->arg;
9875 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
9876 clr_sort = clear_peer;
9877 clr_arg = argv[idx]->arg;
9878 } else if (argv_find(argv, argc, "peer-group", &idx)) {
9879 clr_sort = clear_group;
9880 idx++;
9881 clr_arg = argv[idx]->arg;
9882 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
9883 clr_sort = clear_peer;
9884 clr_arg = argv[idx]->arg;
9885 } else if (argv_find(argv, argc, "WORD", &idx)) {
9886 clr_sort = clear_peer;
9887 clr_arg = argv[idx]->arg;
9888 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
9889 clr_sort = clear_as;
9890 clr_arg = argv[idx]->arg;
9891 } else if (argv_find(argv, argc, "external", &idx)) {
9892 clr_sort = clear_external;
9893 }
9894
9895 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
9896 if (argv_find(argv, argc, "soft", &idx)) {
9897 if (argv_find(argv, argc, "in", &idx)
9898 || argv_find(argv, argc, "out", &idx))
9899 clr_type = strmatch(argv[idx]->text, "in")
9900 ? BGP_CLEAR_SOFT_IN
9901 : BGP_CLEAR_SOFT_OUT;
9902 else
9903 clr_type = BGP_CLEAR_SOFT_BOTH;
9904 } else if (argv_find(argv, argc, "in", &idx)) {
9905 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
9906 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
9907 : BGP_CLEAR_SOFT_IN;
9908 } else if (argv_find(argv, argc, "out", &idx)) {
9909 clr_type = BGP_CLEAR_SOFT_OUT;
9910 } else
9911 clr_type = BGP_CLEAR_SOFT_NONE;
9912
9913 ret = bgp_clear_vty(vrf, afi, safi, clr_sort, clr_type, clr_arg, errmsg,
9914 sizeof(errmsg));
9915 if (ret != NB_OK)
9916 vty_out(vty, "Error description: %s\n", errmsg);
9917
9918 return ret;
9919 }
9920
9921 DEFUN (clear_ip_bgp_prefix,
9922 clear_ip_bgp_prefix_cmd,
9923 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
9924 CLEAR_STR
9925 IP_STR
9926 BGP_STR
9927 BGP_INSTANCE_HELP_STR
9928 "Clear bestpath and re-advertise\n"
9929 "IPv4 prefix\n")
9930 {
9931 char *vrf = NULL;
9932 char *prefix = NULL;
9933
9934 int idx = 0;
9935
9936 /* [<view|vrf> VIEWVRFNAME] */
9937 if (argv_find(argv, argc, "vrf", &idx)) {
9938 vrf = argv[idx + 1]->arg;
9939 idx += 2;
9940 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9941 vrf = NULL;
9942 } else if (argv_find(argv, argc, "view", &idx)) {
9943 /* [<view> VIEWVRFNAME] */
9944 vrf = argv[idx + 1]->arg;
9945 idx += 2;
9946 }
9947
9948 prefix = argv[argc - 1]->arg;
9949
9950 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
9951 }
9952
9953 DEFUN (clear_bgp_ipv6_safi_prefix,
9954 clear_bgp_ipv6_safi_prefix_cmd,
9955 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
9956 CLEAR_STR
9957 IP_STR
9958 BGP_STR
9959 "Address Family\n"
9960 BGP_SAFI_HELP_STR
9961 "Clear bestpath and re-advertise\n"
9962 "IPv6 prefix\n")
9963 {
9964 int idx_safi = 0;
9965 int idx_ipv6_prefix = 0;
9966 safi_t safi = SAFI_UNICAST;
9967 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
9968 argv[idx_ipv6_prefix]->arg : NULL;
9969
9970 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
9971 return bgp_clear_prefix(
9972 vty, NULL, prefix, AFI_IP6,
9973 safi, NULL);
9974 }
9975
9976 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
9977 clear_bgp_instance_ipv6_safi_prefix_cmd,
9978 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
9979 CLEAR_STR
9980 IP_STR
9981 BGP_STR
9982 BGP_INSTANCE_HELP_STR
9983 "Address Family\n"
9984 BGP_SAFI_HELP_STR
9985 "Clear bestpath and re-advertise\n"
9986 "IPv6 prefix\n")
9987 {
9988 int idx_safi = 0;
9989 int idx_vrfview = 0;
9990 int idx_ipv6_prefix = 0;
9991 safi_t safi = SAFI_UNICAST;
9992 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
9993 argv[idx_ipv6_prefix]->arg : NULL;
9994 char *vrfview = NULL;
9995
9996 /* [<view|vrf> VIEWVRFNAME] */
9997 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
9998 vrfview = argv[idx_vrfview + 1]->arg;
9999 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
10000 vrfview = NULL;
10001 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
10002 /* [<view> VIEWVRFNAME] */
10003 vrfview = argv[idx_vrfview + 1]->arg;
10004 }
10005 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
10006
10007 return bgp_clear_prefix(
10008 vty, vrfview, prefix,
10009 AFI_IP6, safi, NULL);
10010 }
10011
10012 DEFUN (show_bgp_views,
10013 show_bgp_views_cmd,
10014 "show [ip] bgp views",
10015 SHOW_STR
10016 IP_STR
10017 BGP_STR
10018 "Show the defined BGP views\n")
10019 {
10020 struct list *inst = bm->bgp;
10021 struct listnode *node;
10022 struct bgp *bgp;
10023
10024 vty_out(vty, "Defined BGP views:\n");
10025 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10026 /* Skip VRFs. */
10027 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
10028 continue;
10029 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
10030 bgp->as);
10031 }
10032
10033 return CMD_SUCCESS;
10034 }
10035
10036 DEFUN (show_bgp_vrfs,
10037 show_bgp_vrfs_cmd,
10038 "show [ip] bgp vrfs [json]",
10039 SHOW_STR
10040 IP_STR
10041 BGP_STR
10042 "Show BGP VRFs\n"
10043 JSON_STR)
10044 {
10045 char buf[ETHER_ADDR_STRLEN];
10046 struct list *inst = bm->bgp;
10047 struct listnode *node;
10048 struct bgp *bgp;
10049 bool uj = use_json(argc, argv);
10050 json_object *json = NULL;
10051 json_object *json_vrfs = NULL;
10052 int count = 0;
10053
10054 if (uj) {
10055 json = json_object_new_object();
10056 json_vrfs = json_object_new_object();
10057 }
10058
10059 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10060 const char *name, *type;
10061 struct peer *peer;
10062 struct listnode *node2, *nnode2;
10063 int peers_cfg, peers_estb;
10064 json_object *json_vrf = NULL;
10065
10066 /* Skip Views. */
10067 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
10068 continue;
10069
10070 count++;
10071 if (!uj && count == 1) {
10072 vty_out(vty,
10073 "%4s %-5s %-16s %9s %10s %-37s\n",
10074 "Type", "Id", "routerId", "#PeersCfg",
10075 "#PeersEstb", "Name");
10076 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
10077 "L3-VNI", "RouterMAC", "Interface");
10078 }
10079
10080 peers_cfg = peers_estb = 0;
10081 if (uj)
10082 json_vrf = json_object_new_object();
10083
10084
10085 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
10086 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10087 continue;
10088 peers_cfg++;
10089 if (peer->status == Established)
10090 peers_estb++;
10091 }
10092
10093 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
10094 name = VRF_DEFAULT_NAME;
10095 type = "DFLT";
10096 } else {
10097 name = bgp->name;
10098 type = "VRF";
10099 }
10100
10101
10102 if (uj) {
10103 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10104 ? -1
10105 : (int64_t)bgp->vrf_id;
10106 char buf[BUFSIZ] = {0};
10107
10108 json_object_string_add(json_vrf, "type", type);
10109 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
10110 json_object_string_add(json_vrf, "routerId",
10111 inet_ntop(AF_INET,
10112 &bgp->router_id, buf,
10113 sizeof(buf)));
10114 json_object_int_add(json_vrf, "numConfiguredPeers",
10115 peers_cfg);
10116 json_object_int_add(json_vrf, "numEstablishedPeers",
10117 peers_estb);
10118
10119 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
10120 json_object_string_add(
10121 json_vrf, "rmac",
10122 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
10123 json_object_string_add(json_vrf, "interface",
10124 ifindex2ifname(bgp->l3vni_svi_ifindex,
10125 bgp->vrf_id));
10126 json_object_object_add(json_vrfs, name, json_vrf);
10127 } else {
10128 vty_out(vty, "%4s %-5d %-16pI4 %-9u %-10u %-37s\n",
10129 type,
10130 bgp->vrf_id == VRF_UNKNOWN ? -1
10131 : (int)bgp->vrf_id,
10132 &bgp->router_id, peers_cfg, peers_estb, name);
10133 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
10134 bgp->l3vni,
10135 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
10136 ifindex2ifname(bgp->l3vni_svi_ifindex,
10137 bgp->vrf_id));
10138 }
10139 }
10140
10141 if (uj) {
10142 json_object_object_add(json, "vrfs", json_vrfs);
10143
10144 json_object_int_add(json, "totalVrfs", count);
10145
10146 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10147 json, JSON_C_TO_STRING_PRETTY));
10148 json_object_free(json);
10149 } else {
10150 if (count)
10151 vty_out(vty,
10152 "\nTotal number of VRFs (including default): %d\n",
10153 count);
10154 }
10155
10156 return CMD_SUCCESS;
10157 }
10158
10159 DEFUN (show_bgp_mac_hash,
10160 show_bgp_mac_hash_cmd,
10161 "show bgp mac hash",
10162 SHOW_STR
10163 BGP_STR
10164 "Mac Address\n"
10165 "Mac Address database\n")
10166 {
10167 bgp_mac_dump_table(vty);
10168
10169 return CMD_SUCCESS;
10170 }
10171
10172 static void show_tip_entry(struct hash_bucket *bucket, void *args)
10173 {
10174 struct vty *vty = (struct vty *)args;
10175 struct tip_addr *tip = (struct tip_addr *)bucket->data;
10176
10177 vty_out(vty, "addr: %pI4, count: %d\n", &tip->addr, tip->refcnt);
10178 }
10179
10180 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
10181 {
10182 vty_out(vty, "self nexthop database:\n");
10183 bgp_nexthop_show_address_hash(vty, bgp);
10184
10185 vty_out(vty, "Tunnel-ip database:\n");
10186 hash_iterate(bgp->tip_hash,
10187 (void (*)(struct hash_bucket *, void *))show_tip_entry,
10188 vty);
10189 }
10190
10191 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
10192 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
10193 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
10194 "martian next-hops\n"
10195 "martian next-hop database\n")
10196 {
10197 struct bgp *bgp = NULL;
10198 int idx = 0;
10199 char *name = NULL;
10200
10201 /* [<vrf> VIEWVRFNAME] */
10202 if (argv_find(argv, argc, "vrf", &idx)) {
10203 name = argv[idx + 1]->arg;
10204 if (name && strmatch(name, VRF_DEFAULT_NAME))
10205 name = NULL;
10206 } else if (argv_find(argv, argc, "view", &idx))
10207 /* [<view> VIEWVRFNAME] */
10208 name = argv[idx + 1]->arg;
10209 if (name)
10210 bgp = bgp_lookup_by_name(name);
10211 else
10212 bgp = bgp_get_default();
10213
10214 if (!bgp) {
10215 vty_out(vty, "%% No BGP process is configured\n");
10216 return CMD_WARNING;
10217 }
10218 bgp_show_martian_nexthops(vty, bgp);
10219
10220 return CMD_SUCCESS;
10221 }
10222
10223 DEFUN (show_bgp_memory,
10224 show_bgp_memory_cmd,
10225 "show [ip] bgp memory",
10226 SHOW_STR
10227 IP_STR
10228 BGP_STR
10229 "Global BGP memory statistics\n")
10230 {
10231 char memstrbuf[MTYPE_MEMSTR_LEN];
10232 unsigned long count;
10233
10234 /* RIB related usage stats */
10235 count = mtype_stats_alloc(MTYPE_BGP_NODE);
10236 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
10237 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10238 count * sizeof(struct bgp_dest)));
10239
10240 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
10241 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
10242 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10243 count * sizeof(struct bgp_path_info)));
10244 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
10245 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
10246 count,
10247 mtype_memstr(
10248 memstrbuf, sizeof(memstrbuf),
10249 count * sizeof(struct bgp_path_info_extra)));
10250
10251 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
10252 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
10253 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10254 count * sizeof(struct bgp_static)));
10255
10256 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
10257 vty_out(vty, "%ld Packets, using %s of memory\n", count,
10258 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10259 count * sizeof(struct bpacket)));
10260
10261 /* Adj-In/Out */
10262 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
10263 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
10264 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10265 count * sizeof(struct bgp_adj_in)));
10266 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
10267 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
10268 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10269 count * sizeof(struct bgp_adj_out)));
10270
10271 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
10272 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
10273 count,
10274 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10275 count * sizeof(struct bgp_nexthop_cache)));
10276
10277 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
10278 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
10279 count,
10280 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10281 count * sizeof(struct bgp_damp_info)));
10282
10283 /* Attributes */
10284 count = attr_count();
10285 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
10286 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10287 count * sizeof(struct attr)));
10288
10289 if ((count = attr_unknown_count()))
10290 vty_out(vty, "%ld unknown attributes\n", count);
10291
10292 /* AS_PATH attributes */
10293 count = aspath_count();
10294 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
10295 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10296 count * sizeof(struct aspath)));
10297
10298 count = mtype_stats_alloc(MTYPE_AS_SEG);
10299 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
10300 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10301 count * sizeof(struct assegment)));
10302
10303 /* Other attributes */
10304 if ((count = community_count()))
10305 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
10306 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10307 count * sizeof(struct community)));
10308 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
10309 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
10310 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10311 count * sizeof(struct ecommunity)));
10312 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
10313 vty_out(vty,
10314 "%ld BGP large-community entries, using %s of memory\n",
10315 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10316 count * sizeof(struct lcommunity)));
10317
10318 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
10319 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
10320 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10321 count * sizeof(struct cluster_list)));
10322
10323 /* Peer related usage */
10324 count = mtype_stats_alloc(MTYPE_BGP_PEER);
10325 vty_out(vty, "%ld peers, using %s of memory\n", count,
10326 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10327 count * sizeof(struct peer)));
10328
10329 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
10330 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
10331 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10332 count * sizeof(struct peer_group)));
10333
10334 /* Other */
10335 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
10336 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
10337 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10338 count * sizeof(regex_t)));
10339 return CMD_SUCCESS;
10340 }
10341
10342 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
10343 {
10344 json_object *bestpath = json_object_new_object();
10345
10346 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
10347 json_object_string_add(bestpath, "asPath", "ignore");
10348
10349 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
10350 json_object_string_add(bestpath, "asPath", "confed");
10351
10352 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
10353 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
10354 json_object_string_add(bestpath, "multiPathRelax",
10355 "as-set");
10356 else
10357 json_object_string_add(bestpath, "multiPathRelax",
10358 "true");
10359 } else
10360 json_object_string_add(bestpath, "multiPathRelax", "false");
10361
10362 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
10363 json_object_string_add(bestpath, "compareRouterId", "true");
10364 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
10365 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
10366 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
10367 json_object_string_add(bestpath, "med", "confed");
10368 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
10369 json_object_string_add(bestpath, "med",
10370 "missing-as-worst");
10371 else
10372 json_object_string_add(bestpath, "med", "true");
10373 }
10374
10375 json_object_object_add(json, "bestPath", bestpath);
10376 }
10377
10378 /* Print the error code/subcode for why the peer is down */
10379 static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
10380 json_object *json_peer, bool use_json)
10381 {
10382 const char *code_str;
10383 const char *subcode_str;
10384
10385 if (use_json) {
10386 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10387 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10388 char errorcodesubcode_hexstr[5];
10389 char errorcodesubcode_str[256];
10390
10391 code_str = bgp_notify_code_str(peer->notify.code);
10392 subcode_str = bgp_notify_subcode_str(
10393 peer->notify.code,
10394 peer->notify.subcode);
10395
10396 snprintf(errorcodesubcode_hexstr,
10397 sizeof(errorcodesubcode_hexstr), "%02X%02X",
10398 peer->notify.code, peer->notify.subcode);
10399 json_object_string_add(json_peer,
10400 "lastErrorCodeSubcode",
10401 errorcodesubcode_hexstr);
10402 snprintf(errorcodesubcode_str, 255, "%s%s",
10403 code_str, subcode_str);
10404 json_object_string_add(json_peer,
10405 "lastNotificationReason",
10406 errorcodesubcode_str);
10407 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10408 && peer->notify.code == BGP_NOTIFY_CEASE
10409 && (peer->notify.subcode
10410 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10411 || peer->notify.subcode
10412 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10413 && peer->notify.length) {
10414 char msgbuf[1024];
10415 const char *msg_str;
10416
10417 msg_str = bgp_notify_admin_message(
10418 msgbuf, sizeof(msgbuf),
10419 (uint8_t *)peer->notify.data,
10420 peer->notify.length);
10421 if (msg_str)
10422 json_object_string_add(
10423 json_peer,
10424 "lastShutdownDescription",
10425 msg_str);
10426 }
10427
10428 }
10429 json_object_string_add(json_peer, "lastResetDueTo",
10430 peer_down_str[(int)peer->last_reset]);
10431 json_object_int_add(json_peer, "lastResetCode",
10432 peer->last_reset);
10433 } else {
10434 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10435 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10436 code_str = bgp_notify_code_str(peer->notify.code);
10437 subcode_str =
10438 bgp_notify_subcode_str(peer->notify.code,
10439 peer->notify.subcode);
10440 vty_out(vty, " Notification %s (%s%s)\n",
10441 peer->last_reset == PEER_DOWN_NOTIFY_SEND
10442 ? "sent"
10443 : "received",
10444 code_str, subcode_str);
10445 } else {
10446 vty_out(vty, " %s\n",
10447 peer_down_str[(int)peer->last_reset]);
10448 }
10449 }
10450 }
10451
10452 static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
10453 safi_t safi)
10454 {
10455 return ((peer->status != Established) ||
10456 !peer->afc_recv[afi][safi]);
10457 }
10458
10459 static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
10460 struct peer *peer, json_object *json_peer,
10461 int max_neighbor_width, bool use_json)
10462 {
10463 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10464 int len;
10465
10466 if (use_json) {
10467 if (peer_dynamic_neighbor(peer))
10468 json_object_boolean_true_add(json_peer,
10469 "dynamicPeer");
10470 if (peer->hostname)
10471 json_object_string_add(json_peer, "hostname",
10472 peer->hostname);
10473
10474 if (peer->domainname)
10475 json_object_string_add(json_peer, "domainname",
10476 peer->domainname);
10477 json_object_int_add(json_peer, "connectionsEstablished",
10478 peer->established);
10479 json_object_int_add(json_peer, "connectionsDropped",
10480 peer->dropped);
10481 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10482 use_json, json_peer);
10483 if (peer->status == Established)
10484 json_object_string_add(json_peer, "lastResetDueTo",
10485 "AFI/SAFI Not Negotiated");
10486 else
10487 bgp_show_peer_reset(NULL, peer, json_peer, true);
10488 } else {
10489 dn_flag[1] = '\0';
10490 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
10491 if (peer->hostname
10492 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
10493 len = vty_out(vty, "%s%s(%s)", dn_flag,
10494 peer->hostname, peer->host);
10495 else
10496 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10497
10498 /* pad the neighbor column with spaces */
10499 if (len < max_neighbor_width)
10500 vty_out(vty, "%*s", max_neighbor_width - len,
10501 " ");
10502 vty_out(vty, "%7d %7d %9s", peer->established,
10503 peer->dropped,
10504 peer_uptime(peer->uptime, timebuf,
10505 BGP_UPTIME_LEN, 0, NULL));
10506 if (peer->status == Established)
10507 vty_out(vty, " AFI/SAFI Not Negotiated\n");
10508 else
10509 bgp_show_peer_reset(vty, peer, NULL,
10510 false);
10511 }
10512 }
10513
10514
10515 /* Show BGP peer's summary information. */
10516 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
10517 bool show_failed, bool show_established,
10518 bool use_json)
10519 {
10520 struct peer *peer;
10521 struct listnode *node, *nnode;
10522 unsigned int count = 0, dn_count = 0;
10523 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10524 char neighbor_buf[VTY_BUFSIZ];
10525 int neighbor_col_default_width = 16;
10526 int len, failed_count = 0;
10527 int max_neighbor_width = 0;
10528 int pfx_rcd_safi;
10529 json_object *json = NULL;
10530 json_object *json_peer = NULL;
10531 json_object *json_peers = NULL;
10532 struct peer_af *paf;
10533 struct bgp_filter *filter;
10534
10535 /* labeled-unicast routes are installed in the unicast table so in order
10536 * to
10537 * display the correct PfxRcd value we must look at SAFI_UNICAST
10538 */
10539
10540 if (safi == SAFI_LABELED_UNICAST)
10541 pfx_rcd_safi = SAFI_UNICAST;
10542 else
10543 pfx_rcd_safi = safi;
10544
10545 if (use_json) {
10546 json = json_object_new_object();
10547 json_peers = json_object_new_object();
10548 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10549 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10550 continue;
10551
10552 if (peer->afc[afi][safi]) {
10553 /* See if we have at least a single failed peer */
10554 if (bgp_has_peer_failed(peer, afi, safi))
10555 failed_count++;
10556 count++;
10557 }
10558 if (peer_dynamic_neighbor(peer))
10559 dn_count++;
10560 }
10561
10562 } else {
10563 /* Loop over all neighbors that will be displayed to determine
10564 * how many
10565 * characters are needed for the Neighbor column
10566 */
10567 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10568 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10569 continue;
10570
10571 if (peer->afc[afi][safi]) {
10572 memset(dn_flag, '\0', sizeof(dn_flag));
10573 if (peer_dynamic_neighbor(peer))
10574 dn_flag[0] = '*';
10575
10576 if (peer->hostname
10577 && CHECK_FLAG(bgp->flags,
10578 BGP_FLAG_SHOW_HOSTNAME))
10579 snprintf(neighbor_buf,
10580 sizeof(neighbor_buf),
10581 "%s%s(%s) ", dn_flag,
10582 peer->hostname, peer->host);
10583 else
10584 snprintf(neighbor_buf,
10585 sizeof(neighbor_buf), "%s%s ",
10586 dn_flag, peer->host);
10587
10588 len = strlen(neighbor_buf);
10589
10590 if (len > max_neighbor_width)
10591 max_neighbor_width = len;
10592
10593 /* See if we have at least a single failed peer */
10594 if (bgp_has_peer_failed(peer, afi, safi))
10595 failed_count++;
10596 count++;
10597 }
10598 }
10599
10600 /* Originally we displayed the Neighbor column as 16
10601 * characters wide so make that the default
10602 */
10603 if (max_neighbor_width < neighbor_col_default_width)
10604 max_neighbor_width = neighbor_col_default_width;
10605 }
10606
10607 if (show_failed && !failed_count) {
10608 if (use_json) {
10609 json_object_int_add(json, "failedPeersCount", 0);
10610 json_object_int_add(json, "dynamicPeers", dn_count);
10611 json_object_int_add(json, "totalPeers", count);
10612
10613 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10614 json, JSON_C_TO_STRING_PRETTY));
10615 json_object_free(json);
10616 } else {
10617 vty_out(vty, "%% No failed BGP neighbors found\n");
10618 vty_out(vty, "\nTotal number of neighbors %d\n", count);
10619 }
10620 return CMD_SUCCESS;
10621 }
10622
10623 count = 0; /* Reset the value as its used again */
10624 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10625 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10626 continue;
10627
10628 if (!peer->afc[afi][safi])
10629 continue;
10630
10631 if (!count) {
10632 unsigned long ents;
10633 char memstrbuf[MTYPE_MEMSTR_LEN];
10634 int64_t vrf_id_ui;
10635
10636 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10637 ? -1
10638 : (int64_t)bgp->vrf_id;
10639
10640 /* Usage summary and header */
10641 if (use_json) {
10642 char buf[BUFSIZ] = {0};
10643
10644 json_object_string_add(
10645 json, "routerId",
10646 inet_ntop(AF_INET, &bgp->router_id, buf,
10647 sizeof(buf)));
10648 json_object_int_add(json, "as", bgp->as);
10649 json_object_int_add(json, "vrfId", vrf_id_ui);
10650 json_object_string_add(
10651 json, "vrfName",
10652 (bgp->inst_type
10653 == BGP_INSTANCE_TYPE_DEFAULT)
10654 ? VRF_DEFAULT_NAME
10655 : bgp->name);
10656 } else {
10657 vty_out(vty,
10658 "BGP router identifier %pI4, local AS number %u vrf-id %d",
10659 &bgp->router_id, bgp->as,
10660 bgp->vrf_id == VRF_UNKNOWN
10661 ? -1
10662 : (int)bgp->vrf_id);
10663 vty_out(vty, "\n");
10664 }
10665
10666 if (bgp_update_delay_configured(bgp)) {
10667 if (use_json) {
10668 json_object_int_add(
10669 json, "updateDelayLimit",
10670 bgp->v_update_delay);
10671
10672 if (bgp->v_update_delay
10673 != bgp->v_establish_wait)
10674 json_object_int_add(
10675 json,
10676 "updateDelayEstablishWait",
10677 bgp->v_establish_wait);
10678
10679 if (bgp_update_delay_active(bgp)) {
10680 json_object_string_add(
10681 json,
10682 "updateDelayFirstNeighbor",
10683 bgp->update_delay_begin_time);
10684 json_object_boolean_true_add(
10685 json,
10686 "updateDelayInProgress");
10687 } else {
10688 if (bgp->update_delay_over) {
10689 json_object_string_add(
10690 json,
10691 "updateDelayFirstNeighbor",
10692 bgp->update_delay_begin_time);
10693 json_object_string_add(
10694 json,
10695 "updateDelayBestpathResumed",
10696 bgp->update_delay_end_time);
10697 json_object_string_add(
10698 json,
10699 "updateDelayZebraUpdateResume",
10700 bgp->update_delay_zebra_resume_time);
10701 json_object_string_add(
10702 json,
10703 "updateDelayPeerUpdateResume",
10704 bgp->update_delay_peers_resume_time);
10705 }
10706 }
10707 } else {
10708 vty_out(vty,
10709 "Read-only mode update-delay limit: %d seconds\n",
10710 bgp->v_update_delay);
10711 if (bgp->v_update_delay
10712 != bgp->v_establish_wait)
10713 vty_out(vty,
10714 " Establish wait: %d seconds\n",
10715 bgp->v_establish_wait);
10716
10717 if (bgp_update_delay_active(bgp)) {
10718 vty_out(vty,
10719 " First neighbor established: %s\n",
10720 bgp->update_delay_begin_time);
10721 vty_out(vty,
10722 " Delay in progress\n");
10723 } else {
10724 if (bgp->update_delay_over) {
10725 vty_out(vty,
10726 " First neighbor established: %s\n",
10727 bgp->update_delay_begin_time);
10728 vty_out(vty,
10729 " Best-paths resumed: %s\n",
10730 bgp->update_delay_end_time);
10731 vty_out(vty,
10732 " zebra update resumed: %s\n",
10733 bgp->update_delay_zebra_resume_time);
10734 vty_out(vty,
10735 " peers update resumed: %s\n",
10736 bgp->update_delay_peers_resume_time);
10737 }
10738 }
10739 }
10740 }
10741
10742 if (use_json) {
10743 if (bgp_maxmed_onstartup_configured(bgp)
10744 && bgp->maxmed_active)
10745 json_object_boolean_true_add(
10746 json, "maxMedOnStartup");
10747 if (bgp->v_maxmed_admin)
10748 json_object_boolean_true_add(
10749 json, "maxMedAdministrative");
10750
10751 json_object_int_add(
10752 json, "tableVersion",
10753 bgp_table_version(bgp->rib[afi][safi]));
10754
10755 ents = bgp_table_count(bgp->rib[afi][safi]);
10756 json_object_int_add(json, "ribCount", ents);
10757 json_object_int_add(
10758 json, "ribMemory",
10759 ents * sizeof(struct bgp_dest));
10760
10761 ents = bgp->af_peer_count[afi][safi];
10762 json_object_int_add(json, "peerCount", ents);
10763 json_object_int_add(json, "peerMemory",
10764 ents * sizeof(struct peer));
10765
10766 if ((ents = listcount(bgp->group))) {
10767 json_object_int_add(
10768 json, "peerGroupCount", ents);
10769 json_object_int_add(
10770 json, "peerGroupMemory",
10771 ents * sizeof(struct
10772 peer_group));
10773 }
10774
10775 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10776 BGP_CONFIG_DAMPENING))
10777 json_object_boolean_true_add(
10778 json, "dampeningEnabled");
10779 } else {
10780 if (bgp_maxmed_onstartup_configured(bgp)
10781 && bgp->maxmed_active)
10782 vty_out(vty,
10783 "Max-med on-startup active\n");
10784 if (bgp->v_maxmed_admin)
10785 vty_out(vty,
10786 "Max-med administrative active\n");
10787
10788 vty_out(vty, "BGP table version %" PRIu64 "\n",
10789 bgp_table_version(bgp->rib[afi][safi]));
10790
10791 ents = bgp_table_count(bgp->rib[afi][safi]);
10792 vty_out(vty,
10793 "RIB entries %ld, using %s of memory\n",
10794 ents,
10795 mtype_memstr(
10796 memstrbuf, sizeof(memstrbuf),
10797 ents
10798 * sizeof(struct
10799 bgp_dest)));
10800
10801 /* Peer related usage */
10802 ents = bgp->af_peer_count[afi][safi];
10803 vty_out(vty, "Peers %ld, using %s of memory\n",
10804 ents,
10805 mtype_memstr(
10806 memstrbuf, sizeof(memstrbuf),
10807 ents * sizeof(struct peer)));
10808
10809 if ((ents = listcount(bgp->group)))
10810 vty_out(vty,
10811 "Peer groups %ld, using %s of memory\n",
10812 ents,
10813 mtype_memstr(
10814 memstrbuf,
10815 sizeof(memstrbuf),
10816 ents * sizeof(struct
10817 peer_group)));
10818
10819 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10820 BGP_CONFIG_DAMPENING))
10821 vty_out(vty, "Dampening enabled.\n");
10822 vty_out(vty, "\n");
10823
10824 /* Subtract 8 here because 'Neighbor' is
10825 * 8 characters */
10826 vty_out(vty, "Neighbor");
10827 vty_out(vty, "%*s", max_neighbor_width - 8,
10828 " ");
10829 if (show_failed)
10830 vty_out(vty, "EstdCnt DropCnt ResetTime Reason\n");
10831 else
10832 vty_out(vty,
10833 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd PfxSnt Desc\n");
10834 }
10835 }
10836
10837 paf = peer_af_find(peer, afi, safi);
10838 filter = &peer->filter[afi][safi];
10839
10840 count++;
10841 /* Works for both failed & successful cases */
10842 if (peer_dynamic_neighbor(peer))
10843 dn_count++;
10844
10845 if (use_json) {
10846 json_peer = NULL;
10847
10848 if (show_failed &&
10849 bgp_has_peer_failed(peer, afi, safi)) {
10850 json_peer = json_object_new_object();
10851 bgp_show_failed_summary(vty, bgp, peer,
10852 json_peer, 0, use_json);
10853 } else if (!show_failed) {
10854 if (show_established
10855 && bgp_has_peer_failed(peer, afi, safi))
10856 continue;
10857
10858 json_peer = json_object_new_object();
10859 if (peer_dynamic_neighbor(peer)) {
10860 json_object_boolean_true_add(json_peer,
10861 "dynamicPeer");
10862 }
10863
10864 if (peer->hostname)
10865 json_object_string_add(json_peer, "hostname",
10866 peer->hostname);
10867
10868 if (peer->domainname)
10869 json_object_string_add(json_peer, "domainname",
10870 peer->domainname);
10871
10872 json_object_int_add(json_peer, "remoteAs", peer->as);
10873 json_object_int_add(json_peer, "version", 4);
10874 json_object_int_add(json_peer, "msgRcvd",
10875 PEER_TOTAL_RX(peer));
10876 json_object_int_add(json_peer, "msgSent",
10877 PEER_TOTAL_TX(peer));
10878
10879 atomic_size_t outq_count, inq_count;
10880 outq_count = atomic_load_explicit(
10881 &peer->obuf->count,
10882 memory_order_relaxed);
10883 inq_count = atomic_load_explicit(
10884 &peer->ibuf->count,
10885 memory_order_relaxed);
10886
10887 json_object_int_add(json_peer, "tableVersion",
10888 peer->version[afi][safi]);
10889 json_object_int_add(json_peer, "outq",
10890 outq_count);
10891 json_object_int_add(json_peer, "inq",
10892 inq_count);
10893 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10894 use_json, json_peer);
10895
10896 json_object_int_add(json_peer, "pfxRcd",
10897 peer->pcount[afi][pfx_rcd_safi]);
10898
10899 if (paf && PAF_SUBGRP(paf))
10900 json_object_int_add(
10901 json_peer, "pfxSnt",
10902 (PAF_SUBGRP(paf))->scount);
10903 else
10904 json_object_int_add(json_peer, "pfxSnt",
10905 0);
10906
10907 /* BGP FSM state */
10908 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
10909 || CHECK_FLAG(peer->bgp->flags,
10910 BGP_FLAG_SHUTDOWN))
10911 json_object_string_add(json_peer,
10912 "state",
10913 "Idle (Admin)");
10914 else if (peer->afc_recv[afi][safi])
10915 json_object_string_add(
10916 json_peer, "state",
10917 lookup_msg(bgp_status_msg,
10918 peer->status, NULL));
10919 else if (CHECK_FLAG(
10920 peer->sflags,
10921 PEER_STATUS_PREFIX_OVERFLOW))
10922 json_object_string_add(json_peer,
10923 "state",
10924 "Idle (PfxCt)");
10925 else
10926 json_object_string_add(
10927 json_peer, "state",
10928 lookup_msg(bgp_status_msg,
10929 peer->status, NULL));
10930
10931 /* BGP peer state */
10932 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
10933 || CHECK_FLAG(peer->bgp->flags,
10934 BGP_FLAG_SHUTDOWN))
10935 json_object_string_add(json_peer,
10936 "peerState",
10937 "Admin");
10938 else if (CHECK_FLAG(
10939 peer->sflags,
10940 PEER_STATUS_PREFIX_OVERFLOW))
10941 json_object_string_add(json_peer,
10942 "peerState",
10943 "PfxCt");
10944 else if (CHECK_FLAG(peer->flags,
10945 PEER_FLAG_PASSIVE))
10946 json_object_string_add(json_peer,
10947 "peerState",
10948 "Passive");
10949 else if (CHECK_FLAG(peer->sflags,
10950 PEER_STATUS_NSF_WAIT))
10951 json_object_string_add(json_peer,
10952 "peerState",
10953 "NSF passive");
10954 else if (CHECK_FLAG(
10955 peer->bgp->flags,
10956 BGP_FLAG_EBGP_REQUIRES_POLICY)
10957 && (!bgp_inbound_policy_exists(peer,
10958 filter)
10959 || !bgp_outbound_policy_exists(
10960 peer, filter)))
10961 json_object_string_add(json_peer,
10962 "peerState",
10963 "Policy");
10964 else
10965 json_object_string_add(
10966 json_peer, "peerState", "OK");
10967
10968 json_object_int_add(json_peer, "connectionsEstablished",
10969 peer->established);
10970 json_object_int_add(json_peer, "connectionsDropped",
10971 peer->dropped);
10972 if (peer->desc)
10973 json_object_string_add(
10974 json_peer, "desc", peer->desc);
10975 }
10976 /* Avoid creating empty peer dicts in JSON */
10977 if (json_peer == NULL)
10978 continue;
10979
10980 if (peer->conf_if)
10981 json_object_string_add(json_peer, "idType",
10982 "interface");
10983 else if (peer->su.sa.sa_family == AF_INET)
10984 json_object_string_add(json_peer, "idType",
10985 "ipv4");
10986 else if (peer->su.sa.sa_family == AF_INET6)
10987 json_object_string_add(json_peer, "idType",
10988 "ipv6");
10989 json_object_object_add(json_peers, peer->host,
10990 json_peer);
10991 } else {
10992 if (show_failed &&
10993 bgp_has_peer_failed(peer, afi, safi)) {
10994 bgp_show_failed_summary(vty, bgp, peer, NULL,
10995 max_neighbor_width,
10996 use_json);
10997 } else if (!show_failed) {
10998 if (show_established
10999 && bgp_has_peer_failed(peer, afi, safi))
11000 continue;
11001
11002 memset(dn_flag, '\0', sizeof(dn_flag));
11003 if (peer_dynamic_neighbor(peer)) {
11004 dn_flag[0] = '*';
11005 }
11006
11007 if (peer->hostname
11008 && CHECK_FLAG(bgp->flags,
11009 BGP_FLAG_SHOW_HOSTNAME))
11010 len = vty_out(vty, "%s%s(%s)", dn_flag,
11011 peer->hostname,
11012 peer->host);
11013 else
11014 len = vty_out(vty, "%s%s", dn_flag, peer->host);
11015
11016 /* pad the neighbor column with spaces */
11017 if (len < max_neighbor_width)
11018 vty_out(vty, "%*s", max_neighbor_width - len,
11019 " ");
11020
11021 atomic_size_t outq_count, inq_count;
11022 outq_count = atomic_load_explicit(
11023 &peer->obuf->count,
11024 memory_order_relaxed);
11025 inq_count = atomic_load_explicit(
11026 &peer->ibuf->count,
11027 memory_order_relaxed);
11028
11029 vty_out(vty,
11030 "4 %10u %9u %9u %8" PRIu64" %4zu %4zu %8s",
11031 peer->as, PEER_TOTAL_RX(peer),
11032 PEER_TOTAL_TX(peer),
11033 peer->version[afi][safi], inq_count,
11034 outq_count,
11035 peer_uptime(peer->uptime, timebuf,
11036 BGP_UPTIME_LEN, 0, NULL));
11037
11038 if (peer->status == Established) {
11039 if (peer->afc_recv[afi][safi]) {
11040 if (CHECK_FLAG(
11041 bgp->flags,
11042 BGP_FLAG_EBGP_REQUIRES_POLICY)
11043 && !bgp_inbound_policy_exists(
11044 peer, filter))
11045 vty_out(vty, " %12s",
11046 "(Policy)");
11047 else
11048 vty_out(vty,
11049 " %12u",
11050 peer->pcount
11051 [afi]
11052 [pfx_rcd_safi]);
11053 } else {
11054 vty_out(vty, " NoNeg");
11055 }
11056
11057 if (paf && PAF_SUBGRP(paf)) {
11058 if (CHECK_FLAG(
11059 bgp->flags,
11060 BGP_FLAG_EBGP_REQUIRES_POLICY)
11061 && !bgp_outbound_policy_exists(
11062 peer, filter))
11063 vty_out(vty, " %8s",
11064 "(Policy)");
11065 else
11066 vty_out(vty,
11067 " %8u",
11068 (PAF_SUBGRP(
11069 paf))
11070 ->scount);
11071 }
11072 } else {
11073 if (CHECK_FLAG(peer->flags,
11074 PEER_FLAG_SHUTDOWN)
11075 || CHECK_FLAG(peer->bgp->flags,
11076 BGP_FLAG_SHUTDOWN))
11077 vty_out(vty, " Idle (Admin)");
11078 else if (CHECK_FLAG(
11079 peer->sflags,
11080 PEER_STATUS_PREFIX_OVERFLOW))
11081 vty_out(vty, " Idle (PfxCt)");
11082 else
11083 vty_out(vty, " %12s",
11084 lookup_msg(bgp_status_msg,
11085 peer->status, NULL));
11086
11087 vty_out(vty, " %8u", 0);
11088 }
11089 if (peer->desc)
11090 vty_out(vty, " %s", peer->desc);
11091 else
11092 vty_out(vty, " N/A");
11093 vty_out(vty, "\n");
11094 }
11095
11096 }
11097 }
11098
11099 if (use_json) {
11100 json_object_object_add(json, "peers", json_peers);
11101 json_object_int_add(json, "failedPeers", failed_count);
11102 json_object_int_add(json, "totalPeers", count);
11103 json_object_int_add(json, "dynamicPeers", dn_count);
11104
11105 if (!show_failed)
11106 bgp_show_bestpath_json(bgp, json);
11107
11108 vty_out(vty, "%s\n", json_object_to_json_string_ext(
11109 json, JSON_C_TO_STRING_PRETTY));
11110 json_object_free(json);
11111 } else {
11112 if (count)
11113 vty_out(vty, "\nTotal number of neighbors %d\n", count);
11114 else {
11115 vty_out(vty, "No %s neighbor is configured\n",
11116 get_afi_safi_str(afi, safi, false));
11117 }
11118
11119 if (dn_count) {
11120 vty_out(vty, "* - dynamic neighbor\n");
11121 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
11122 dn_count, bgp->dynamic_neighbors_limit);
11123 }
11124 }
11125
11126 return CMD_SUCCESS;
11127 }
11128
11129 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
11130 int safi, bool show_failed,
11131 bool show_established, bool use_json)
11132 {
11133 int is_first = 1;
11134 int afi_wildcard = (afi == AFI_MAX);
11135 int safi_wildcard = (safi == SAFI_MAX);
11136 int is_wildcard = (afi_wildcard || safi_wildcard);
11137 bool nbr_output = false;
11138
11139 if (use_json && is_wildcard)
11140 vty_out(vty, "{\n");
11141 if (afi_wildcard)
11142 afi = 1; /* AFI_IP */
11143 while (afi < AFI_MAX) {
11144 if (safi_wildcard)
11145 safi = 1; /* SAFI_UNICAST */
11146 while (safi < SAFI_MAX) {
11147 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
11148 nbr_output = true;
11149
11150 if (is_wildcard) {
11151 /*
11152 * So limit output to those afi/safi
11153 * pairs that
11154 * actualy have something interesting in
11155 * them
11156 */
11157 if (use_json) {
11158 if (!is_first)
11159 vty_out(vty, ",\n");
11160 else
11161 is_first = 0;
11162
11163 vty_out(vty, "\"%s\":",
11164 get_afi_safi_str(afi,
11165 safi,
11166 true));
11167 } else {
11168 vty_out(vty, "\n%s Summary:\n",
11169 get_afi_safi_str(afi,
11170 safi,
11171 false));
11172 }
11173 }
11174 bgp_show_summary(vty, bgp, afi, safi,
11175 show_failed, show_established,
11176 use_json);
11177 }
11178 safi++;
11179 if (!safi_wildcard)
11180 safi = SAFI_MAX;
11181 }
11182 afi++;
11183 if (!afi_wildcard)
11184 afi = AFI_MAX;
11185 }
11186
11187 if (use_json && is_wildcard)
11188 vty_out(vty, "}\n");
11189 else if (!nbr_output) {
11190 if (use_json)
11191 vty_out(vty, "{}\n");
11192 else
11193 vty_out(vty, "%% No BGP neighbors found\n");
11194 }
11195 }
11196
11197 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
11198 safi_t safi, bool show_failed,
11199 bool show_established,
11200 bool use_json)
11201 {
11202 struct listnode *node, *nnode;
11203 struct bgp *bgp;
11204 int is_first = 1;
11205 bool nbr_output = false;
11206
11207 if (use_json)
11208 vty_out(vty, "{\n");
11209
11210 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11211 nbr_output = true;
11212 if (use_json) {
11213 if (!is_first)
11214 vty_out(vty, ",\n");
11215 else
11216 is_first = 0;
11217
11218 vty_out(vty, "\"%s\":",
11219 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11220 ? VRF_DEFAULT_NAME
11221 : bgp->name);
11222 } else {
11223 vty_out(vty, "\nInstance %s:\n",
11224 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11225 ? VRF_DEFAULT_NAME
11226 : bgp->name);
11227 }
11228 bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_failed,
11229 show_established, use_json);
11230 }
11231
11232 if (use_json)
11233 vty_out(vty, "}\n");
11234 else if (!nbr_output)
11235 vty_out(vty, "%% BGP instance not found\n");
11236 }
11237
11238 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
11239 safi_t safi, bool show_failed, bool show_established,
11240 bool use_json)
11241 {
11242 struct bgp *bgp;
11243
11244 if (name) {
11245 if (strmatch(name, "all")) {
11246 bgp_show_all_instances_summary_vty(
11247 vty, afi, safi, show_failed, show_established,
11248 use_json);
11249 return CMD_SUCCESS;
11250 } else {
11251 bgp = bgp_lookup_by_name(name);
11252
11253 if (!bgp) {
11254 if (use_json)
11255 vty_out(vty, "{}\n");
11256 else
11257 vty_out(vty,
11258 "%% BGP instance not found\n");
11259 return CMD_WARNING;
11260 }
11261
11262 bgp_show_summary_afi_safi(vty, bgp, afi, safi,
11263 show_failed, show_established,
11264 use_json);
11265 return CMD_SUCCESS;
11266 }
11267 }
11268
11269 bgp = bgp_get_default();
11270
11271 if (bgp)
11272 bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_failed,
11273 show_established, use_json);
11274 else {
11275 if (use_json)
11276 vty_out(vty, "{}\n");
11277 else
11278 vty_out(vty, "%% BGP instance not found\n");
11279 return CMD_WARNING;
11280 }
11281
11282 return CMD_SUCCESS;
11283 }
11284
11285 /* `show [ip] bgp summary' commands. */
11286 DEFPY (show_ip_bgp_summary,
11287 show_ip_bgp_summary_cmd,
11288 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] [all$all] summary [established|failed] [json$uj]",
11289 SHOW_STR
11290 IP_STR
11291 BGP_STR
11292 BGP_INSTANCE_HELP_STR
11293 BGP_AFI_HELP_STR
11294 BGP_SAFI_WITH_LABEL_HELP_STR
11295 "Display the entries for all address families\n"
11296 "Summary of BGP neighbor status\n"
11297 "Show only sessions in Established state\n"
11298 "Show only sessions not in Established state\n"
11299 JSON_STR)
11300 {
11301 char *vrf = NULL;
11302 afi_t afi = AFI_MAX;
11303 safi_t safi = SAFI_MAX;
11304 bool show_failed = false;
11305 bool show_established = false;
11306
11307 int idx = 0;
11308
11309 /* show [ip] bgp */
11310 if (!all && argv_find(argv, argc, "ip", &idx))
11311 afi = AFI_IP;
11312 /* [<vrf> VIEWVRFNAME] */
11313 if (argv_find(argv, argc, "vrf", &idx)) {
11314 vrf = argv[idx + 1]->arg;
11315 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11316 vrf = NULL;
11317 } else if (argv_find(argv, argc, "view", &idx))
11318 /* [<view> VIEWVRFNAME] */
11319 vrf = argv[idx + 1]->arg;
11320 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11321 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11322 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11323 }
11324
11325 if (argv_find(argv, argc, "failed", &idx))
11326 show_failed = true;
11327 if (argv_find(argv, argc, "established", &idx))
11328 show_established = true;
11329
11330 return bgp_show_summary_vty(vty, vrf, afi, safi, show_failed,
11331 show_established, uj);
11332 }
11333
11334 const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
11335 {
11336 if (for_json)
11337 return get_afi_safi_json_str(afi, safi);
11338 else
11339 return get_afi_safi_vty_str(afi, safi);
11340 }
11341
11342
11343 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
11344 afi_t afi, safi_t safi,
11345 uint16_t adv_smcap, uint16_t adv_rmcap,
11346 uint16_t rcv_smcap, uint16_t rcv_rmcap,
11347 bool use_json, json_object *json_pref)
11348 {
11349 /* Send-Mode */
11350 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11351 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
11352 if (use_json) {
11353 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11354 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11355 json_object_string_add(json_pref, "sendMode",
11356 "advertisedAndReceived");
11357 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11358 json_object_string_add(json_pref, "sendMode",
11359 "advertised");
11360 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11361 json_object_string_add(json_pref, "sendMode",
11362 "received");
11363 } else {
11364 vty_out(vty, " Send-mode: ");
11365 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11366 vty_out(vty, "advertised");
11367 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11368 vty_out(vty, "%sreceived",
11369 CHECK_FLAG(p->af_cap[afi][safi],
11370 adv_smcap)
11371 ? ", "
11372 : "");
11373 vty_out(vty, "\n");
11374 }
11375 }
11376
11377 /* Receive-Mode */
11378 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11379 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
11380 if (use_json) {
11381 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11382 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11383 json_object_string_add(json_pref, "recvMode",
11384 "advertisedAndReceived");
11385 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11386 json_object_string_add(json_pref, "recvMode",
11387 "advertised");
11388 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11389 json_object_string_add(json_pref, "recvMode",
11390 "received");
11391 } else {
11392 vty_out(vty, " Receive-mode: ");
11393 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11394 vty_out(vty, "advertised");
11395 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11396 vty_out(vty, "%sreceived",
11397 CHECK_FLAG(p->af_cap[afi][safi],
11398 adv_rmcap)
11399 ? ", "
11400 : "");
11401 vty_out(vty, "\n");
11402 }
11403 }
11404 }
11405
11406 static void bgp_show_neighnor_graceful_restart_rbit(struct vty *vty,
11407 struct peer *p,
11408 bool use_json,
11409 json_object *json)
11410 {
11411 bool rbit_status = false;
11412
11413 if (!use_json)
11414 vty_out(vty, "\n R bit: ");
11415
11416 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
11417 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
11418 && (p->status == Established)) {
11419
11420 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_BIT_RCV))
11421 rbit_status = true;
11422 else
11423 rbit_status = false;
11424 }
11425
11426 if (rbit_status) {
11427 if (use_json)
11428 json_object_boolean_true_add(json, "rBit");
11429 else
11430 vty_out(vty, "True\n");
11431 } else {
11432 if (use_json)
11433 json_object_boolean_false_add(json, "rBit");
11434 else
11435 vty_out(vty, "False\n");
11436 }
11437 }
11438
11439 static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
11440 struct peer *peer,
11441 bool use_json,
11442 json_object *json)
11443 {
11444 const char *mode = "NotApplicable";
11445
11446 if (!use_json)
11447 vty_out(vty, "\n Remote GR Mode: ");
11448
11449 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
11450 && (peer->status == Established)) {
11451
11452 if ((peer->nsf_af_count == 0)
11453 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11454
11455 mode = "Disable";
11456
11457 } else if (peer->nsf_af_count == 0
11458 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11459
11460 mode = "Helper";
11461
11462 } else if (peer->nsf_af_count != 0
11463 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11464
11465 mode = "Restart";
11466 }
11467 }
11468
11469 if (use_json) {
11470 json_object_string_add(json, "remoteGrMode", mode);
11471 } else
11472 vty_out(vty, mode, "\n");
11473 }
11474
11475 static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
11476 struct peer *p,
11477 bool use_json,
11478 json_object *json)
11479 {
11480 const char *mode = "Invalid";
11481
11482 if (!use_json)
11483 vty_out(vty, " Local GR Mode: ");
11484
11485 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
11486 mode = "Helper";
11487 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
11488 mode = "Restart";
11489 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
11490 mode = "Disable";
11491 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
11492 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
11493 mode = "Helper*";
11494 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
11495 mode = "Restart*";
11496 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
11497 mode = "Disable*";
11498 else
11499 mode = "Invalid*";
11500 }
11501
11502 if (use_json) {
11503 json_object_string_add(json, "localGrMode", mode);
11504 } else {
11505 vty_out(vty, mode, "\n");
11506 }
11507 }
11508
11509 static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
11510 struct vty *vty, struct peer *peer, bool use_json, json_object *json)
11511 {
11512 afi_t afi;
11513 safi_t safi;
11514 json_object *json_afi_safi = NULL;
11515 json_object *json_timer = NULL;
11516 json_object *json_endofrib_status = NULL;
11517 bool eor_flag = false;
11518
11519 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
11520 for (safi = SAFI_UNICAST; safi <= SAFI_MPLS_VPN; safi++) {
11521 if (!peer->afc[afi][safi])
11522 continue;
11523
11524 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
11525 || !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
11526 continue;
11527
11528 if (use_json) {
11529 json_afi_safi = json_object_new_object();
11530 json_endofrib_status = json_object_new_object();
11531 json_timer = json_object_new_object();
11532 }
11533
11534 if (peer->eor_stime[afi][safi]
11535 >= peer->pkt_stime[afi][safi])
11536 eor_flag = true;
11537 else
11538 eor_flag = false;
11539
11540 if (!use_json) {
11541 vty_out(vty, " %s:\n",
11542 get_afi_safi_str(afi, safi, false));
11543
11544 vty_out(vty, " F bit: ");
11545 }
11546
11547 if (peer->nsf[afi][safi]
11548 && CHECK_FLAG(peer->af_cap[afi][safi],
11549 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
11550
11551 if (use_json) {
11552 json_object_boolean_true_add(
11553 json_afi_safi, "fBit");
11554 } else
11555 vty_out(vty, "True\n");
11556 } else {
11557 if (use_json)
11558 json_object_boolean_false_add(
11559 json_afi_safi, "fBit");
11560 else
11561 vty_out(vty, "False\n");
11562 }
11563
11564 if (!use_json)
11565 vty_out(vty, " End-of-RIB sent: ");
11566
11567 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11568 PEER_STATUS_EOR_SEND)) {
11569 if (use_json) {
11570 json_object_boolean_true_add(
11571 json_endofrib_status,
11572 "endOfRibSend");
11573
11574 PRINT_EOR_JSON(eor_flag);
11575 } else {
11576 vty_out(vty, "Yes\n");
11577 vty_out(vty,
11578 " End-of-RIB sent after update: ");
11579
11580 PRINT_EOR(eor_flag);
11581 }
11582 } else {
11583 if (use_json) {
11584 json_object_boolean_false_add(
11585 json_endofrib_status,
11586 "endOfRibSend");
11587 json_object_boolean_false_add(
11588 json_endofrib_status,
11589 "endOfRibSentAfterUpdate");
11590 } else {
11591 vty_out(vty, "No\n");
11592 vty_out(vty,
11593 " End-of-RIB sent after update: ");
11594 vty_out(vty, "No\n");
11595 }
11596 }
11597
11598 if (!use_json)
11599 vty_out(vty, " End-of-RIB received: ");
11600
11601 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11602 PEER_STATUS_EOR_RECEIVED)) {
11603 if (use_json)
11604 json_object_boolean_true_add(
11605 json_endofrib_status,
11606 "endOfRibRecv");
11607 else
11608 vty_out(vty, "Yes\n");
11609 } else {
11610 if (use_json)
11611 json_object_boolean_false_add(
11612 json_endofrib_status,
11613 "endOfRibRecv");
11614 else
11615 vty_out(vty, "No\n");
11616 }
11617
11618 if (use_json) {
11619 json_object_int_add(json_timer,
11620 "stalePathTimer",
11621 peer->bgp->stalepath_time);
11622
11623 if (peer->t_gr_stale != NULL) {
11624 json_object_int_add(
11625 json_timer,
11626 "stalePathTimerRemaining",
11627 thread_timer_remain_second(
11628 peer->t_gr_stale));
11629 }
11630
11631 /* Display Configured Selection
11632 * Deferral only when when
11633 * Gr mode is enabled.
11634 */
11635 if (CHECK_FLAG(peer->flags,
11636 PEER_FLAG_GRACEFUL_RESTART)) {
11637 json_object_int_add(
11638 json_timer,
11639 "selectionDeferralTimer",
11640 peer->bgp->stalepath_time);
11641 }
11642
11643 if (peer->bgp->gr_info[afi][safi]
11644 .t_select_deferral
11645 != NULL) {
11646
11647 json_object_int_add(
11648 json_timer,
11649 "selectionDeferralTimerRemaining",
11650 thread_timer_remain_second(
11651 peer->bgp
11652 ->gr_info[afi]
11653 [safi]
11654 .t_select_deferral));
11655 }
11656 } else {
11657 vty_out(vty, " Timers:\n");
11658 vty_out(vty,
11659 " Configured Stale Path Time(sec): %u\n",
11660 peer->bgp->stalepath_time);
11661
11662 if (peer->t_gr_stale != NULL)
11663 vty_out(vty,
11664 " Stale Path Remaining(sec): %ld\n",
11665 thread_timer_remain_second(
11666 peer->t_gr_stale));
11667 /* Display Configured Selection
11668 * Deferral only when when
11669 * Gr mode is enabled.
11670 */
11671 if (CHECK_FLAG(peer->flags,
11672 PEER_FLAG_GRACEFUL_RESTART))
11673 vty_out(vty,
11674 " Configured Selection Deferral Time(sec): %u\n",
11675 peer->bgp->select_defer_time);
11676
11677 if (peer->bgp->gr_info[afi][safi]
11678 .t_select_deferral
11679 != NULL)
11680 vty_out(vty,
11681 " Selection Deferral Time Remaining(sec): %ld\n",
11682 thread_timer_remain_second(
11683 peer->bgp
11684 ->gr_info[afi]
11685 [safi]
11686 .t_select_deferral));
11687 }
11688 if (use_json) {
11689 json_object_object_add(json_afi_safi,
11690 "endOfRibStatus",
11691 json_endofrib_status);
11692 json_object_object_add(json_afi_safi, "timers",
11693 json_timer);
11694 json_object_object_add(
11695 json, get_afi_safi_str(afi, safi, true),
11696 json_afi_safi);
11697 }
11698 }
11699 }
11700 }
11701
11702 static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
11703 struct peer *p,
11704 bool use_json,
11705 json_object *json)
11706 {
11707 if (use_json) {
11708 json_object *json_timer = NULL;
11709
11710 json_timer = json_object_new_object();
11711
11712 json_object_int_add(json_timer, "configuredRestartTimer",
11713 p->bgp->restart_time);
11714
11715 json_object_int_add(json_timer, "receivedRestartTimer",
11716 p->v_gr_restart);
11717
11718 if (p->t_gr_restart != NULL)
11719 json_object_int_add(
11720 json_timer, "restartTimerRemaining",
11721 thread_timer_remain_second(p->t_gr_restart));
11722
11723 json_object_object_add(json, "timers", json_timer);
11724 } else {
11725
11726 vty_out(vty, " Timers:\n");
11727 vty_out(vty, " Configured Restart Time(sec): %u\n",
11728 p->bgp->restart_time);
11729
11730 vty_out(vty, " Received Restart Time(sec): %u\n",
11731 p->v_gr_restart);
11732 if (p->t_gr_restart != NULL)
11733 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
11734 thread_timer_remain_second(p->t_gr_restart));
11735 if (p->t_gr_restart != NULL) {
11736 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
11737 thread_timer_remain_second(p->t_gr_restart));
11738 }
11739 }
11740 }
11741
11742 static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
11743 bool use_json, json_object *json)
11744 {
11745 char buf[SU_ADDRSTRLEN] = {0};
11746 char dn_flag[2] = {0};
11747 /* '*' + v6 address of neighbor */
11748 char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
11749
11750 if (!p->conf_if && peer_dynamic_neighbor(p))
11751 dn_flag[0] = '*';
11752
11753 if (p->conf_if) {
11754 if (use_json)
11755 json_object_string_add(
11756 json, "neighborAddr",
11757 BGP_PEER_SU_UNSPEC(p)
11758 ? "none"
11759 : sockunion2str(&p->su, buf,
11760 SU_ADDRSTRLEN));
11761 else
11762 vty_out(vty, "BGP neighbor on %s: %s\n", p->conf_if,
11763 BGP_PEER_SU_UNSPEC(p)
11764 ? "none"
11765 : sockunion2str(&p->su, buf,
11766 SU_ADDRSTRLEN));
11767 } else {
11768 snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
11769 p->host);
11770
11771 if (use_json)
11772 json_object_string_add(json, "neighborAddr",
11773 neighborAddr);
11774 else
11775 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
11776 }
11777
11778 /* more gr info in new format */
11779 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json);
11780 }
11781
11782 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
11783 safi_t safi, bool use_json,
11784 json_object *json_neigh)
11785 {
11786 struct bgp_filter *filter;
11787 struct peer_af *paf;
11788 char orf_pfx_name[BUFSIZ];
11789 int orf_pfx_count;
11790 json_object *json_af = NULL;
11791 json_object *json_prefA = NULL;
11792 json_object *json_prefB = NULL;
11793 json_object *json_addr = NULL;
11794 json_object *json_advmap = NULL;
11795
11796 if (use_json) {
11797 json_addr = json_object_new_object();
11798 json_af = json_object_new_object();
11799 filter = &p->filter[afi][safi];
11800
11801 if (peer_group_active(p))
11802 json_object_string_add(json_addr, "peerGroupMember",
11803 p->group->name);
11804
11805 paf = peer_af_find(p, afi, safi);
11806 if (paf && PAF_SUBGRP(paf)) {
11807 json_object_int_add(json_addr, "updateGroupId",
11808 PAF_UPDGRP(paf)->id);
11809 json_object_int_add(json_addr, "subGroupId",
11810 PAF_SUBGRP(paf)->id);
11811 json_object_int_add(json_addr, "packetQueueLength",
11812 bpacket_queue_virtual_length(paf));
11813 }
11814
11815 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11816 || CHECK_FLAG(p->af_cap[afi][safi],
11817 PEER_CAP_ORF_PREFIX_SM_RCV)
11818 || CHECK_FLAG(p->af_cap[afi][safi],
11819 PEER_CAP_ORF_PREFIX_RM_ADV)
11820 || CHECK_FLAG(p->af_cap[afi][safi],
11821 PEER_CAP_ORF_PREFIX_RM_RCV)) {
11822 json_object_int_add(json_af, "orfType",
11823 ORF_TYPE_PREFIX);
11824 json_prefA = json_object_new_object();
11825 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
11826 PEER_CAP_ORF_PREFIX_SM_ADV,
11827 PEER_CAP_ORF_PREFIX_RM_ADV,
11828 PEER_CAP_ORF_PREFIX_SM_RCV,
11829 PEER_CAP_ORF_PREFIX_RM_RCV,
11830 use_json, json_prefA);
11831 json_object_object_add(json_af, "orfPrefixList",
11832 json_prefA);
11833 }
11834
11835 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11836 || CHECK_FLAG(p->af_cap[afi][safi],
11837 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11838 || CHECK_FLAG(p->af_cap[afi][safi],
11839 PEER_CAP_ORF_PREFIX_RM_ADV)
11840 || CHECK_FLAG(p->af_cap[afi][safi],
11841 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
11842 json_object_int_add(json_af, "orfOldType",
11843 ORF_TYPE_PREFIX_OLD);
11844 json_prefB = json_object_new_object();
11845 bgp_show_peer_afi_orf_cap(
11846 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
11847 PEER_CAP_ORF_PREFIX_RM_ADV,
11848 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
11849 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
11850 json_prefB);
11851 json_object_object_add(json_af, "orfOldPrefixList",
11852 json_prefB);
11853 }
11854
11855 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11856 || CHECK_FLAG(p->af_cap[afi][safi],
11857 PEER_CAP_ORF_PREFIX_SM_RCV)
11858 || CHECK_FLAG(p->af_cap[afi][safi],
11859 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11860 || CHECK_FLAG(p->af_cap[afi][safi],
11861 PEER_CAP_ORF_PREFIX_RM_ADV)
11862 || CHECK_FLAG(p->af_cap[afi][safi],
11863 PEER_CAP_ORF_PREFIX_RM_RCV)
11864 || CHECK_FLAG(p->af_cap[afi][safi],
11865 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
11866 json_object_object_add(json_addr, "afDependentCap",
11867 json_af);
11868 else
11869 json_object_free(json_af);
11870
11871 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
11872 p->host, afi, safi);
11873 orf_pfx_count = prefix_bgp_show_prefix_list(
11874 NULL, afi, orf_pfx_name, use_json);
11875
11876 if (CHECK_FLAG(p->af_sflags[afi][safi],
11877 PEER_STATUS_ORF_PREFIX_SEND)
11878 || orf_pfx_count) {
11879 if (CHECK_FLAG(p->af_sflags[afi][safi],
11880 PEER_STATUS_ORF_PREFIX_SEND))
11881 json_object_boolean_true_add(json_neigh,
11882 "orfSent");
11883 if (orf_pfx_count)
11884 json_object_int_add(json_addr, "orfRecvCounter",
11885 orf_pfx_count);
11886 }
11887 if (CHECK_FLAG(p->af_sflags[afi][safi],
11888 PEER_STATUS_ORF_WAIT_REFRESH))
11889 json_object_string_add(
11890 json_addr, "orfFirstUpdate",
11891 "deferredUntilORFOrRouteRefreshRecvd");
11892
11893 if (CHECK_FLAG(p->af_flags[afi][safi],
11894 PEER_FLAG_REFLECTOR_CLIENT))
11895 json_object_boolean_true_add(json_addr,
11896 "routeReflectorClient");
11897 if (CHECK_FLAG(p->af_flags[afi][safi],
11898 PEER_FLAG_RSERVER_CLIENT))
11899 json_object_boolean_true_add(json_addr,
11900 "routeServerClient");
11901 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
11902 json_object_boolean_true_add(json_addr,
11903 "inboundSoftConfigPermit");
11904
11905 if (CHECK_FLAG(p->af_flags[afi][safi],
11906 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
11907 json_object_boolean_true_add(
11908 json_addr,
11909 "privateAsNumsAllReplacedInUpdatesToNbr");
11910 else if (CHECK_FLAG(p->af_flags[afi][safi],
11911 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
11912 json_object_boolean_true_add(
11913 json_addr,
11914 "privateAsNumsReplacedInUpdatesToNbr");
11915 else if (CHECK_FLAG(p->af_flags[afi][safi],
11916 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
11917 json_object_boolean_true_add(
11918 json_addr,
11919 "privateAsNumsAllRemovedInUpdatesToNbr");
11920 else if (CHECK_FLAG(p->af_flags[afi][safi],
11921 PEER_FLAG_REMOVE_PRIVATE_AS))
11922 json_object_boolean_true_add(
11923 json_addr,
11924 "privateAsNumsRemovedInUpdatesToNbr");
11925
11926 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
11927 json_object_boolean_true_add(
11928 json_addr,
11929 bgp_addpath_names(p->addpath_type[afi][safi])
11930 ->type_json_name);
11931
11932 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
11933 json_object_string_add(json_addr,
11934 "overrideASNsInOutboundUpdates",
11935 "ifAspathEqualRemoteAs");
11936
11937 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
11938 || CHECK_FLAG(p->af_flags[afi][safi],
11939 PEER_FLAG_FORCE_NEXTHOP_SELF))
11940 json_object_boolean_true_add(json_addr,
11941 "routerAlwaysNextHop");
11942 if (CHECK_FLAG(p->af_flags[afi][safi],
11943 PEER_FLAG_AS_PATH_UNCHANGED))
11944 json_object_boolean_true_add(
11945 json_addr, "unchangedAsPathPropogatedToNbr");
11946 if (CHECK_FLAG(p->af_flags[afi][safi],
11947 PEER_FLAG_NEXTHOP_UNCHANGED))
11948 json_object_boolean_true_add(
11949 json_addr, "unchangedNextHopPropogatedToNbr");
11950 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
11951 json_object_boolean_true_add(
11952 json_addr, "unchangedMedPropogatedToNbr");
11953 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
11954 || CHECK_FLAG(p->af_flags[afi][safi],
11955 PEER_FLAG_SEND_EXT_COMMUNITY)) {
11956 if (CHECK_FLAG(p->af_flags[afi][safi],
11957 PEER_FLAG_SEND_COMMUNITY)
11958 && CHECK_FLAG(p->af_flags[afi][safi],
11959 PEER_FLAG_SEND_EXT_COMMUNITY))
11960 json_object_string_add(json_addr,
11961 "commAttriSentToNbr",
11962 "extendedAndStandard");
11963 else if (CHECK_FLAG(p->af_flags[afi][safi],
11964 PEER_FLAG_SEND_EXT_COMMUNITY))
11965 json_object_string_add(json_addr,
11966 "commAttriSentToNbr",
11967 "extended");
11968 else
11969 json_object_string_add(json_addr,
11970 "commAttriSentToNbr",
11971 "standard");
11972 }
11973 if (CHECK_FLAG(p->af_flags[afi][safi],
11974 PEER_FLAG_DEFAULT_ORIGINATE)) {
11975 if (p->default_rmap[afi][safi].name)
11976 json_object_string_add(
11977 json_addr, "defaultRouteMap",
11978 p->default_rmap[afi][safi].name);
11979
11980 if (paf && PAF_SUBGRP(paf)
11981 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
11982 SUBGRP_STATUS_DEFAULT_ORIGINATE))
11983 json_object_boolean_true_add(json_addr,
11984 "defaultSent");
11985 else
11986 json_object_boolean_true_add(json_addr,
11987 "defaultNotSent");
11988 }
11989
11990 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
11991 if (is_evpn_enabled())
11992 json_object_boolean_true_add(
11993 json_addr, "advertiseAllVnis");
11994 }
11995
11996 if (filter->plist[FILTER_IN].name
11997 || filter->dlist[FILTER_IN].name
11998 || filter->aslist[FILTER_IN].name
11999 || filter->map[RMAP_IN].name)
12000 json_object_boolean_true_add(json_addr,
12001 "inboundPathPolicyConfig");
12002 if (filter->plist[FILTER_OUT].name
12003 || filter->dlist[FILTER_OUT].name
12004 || filter->aslist[FILTER_OUT].name
12005 || filter->map[RMAP_OUT].name || filter->usmap.name)
12006 json_object_boolean_true_add(
12007 json_addr, "outboundPathPolicyConfig");
12008
12009 /* prefix-list */
12010 if (filter->plist[FILTER_IN].name)
12011 json_object_string_add(json_addr,
12012 "incomingUpdatePrefixFilterList",
12013 filter->plist[FILTER_IN].name);
12014 if (filter->plist[FILTER_OUT].name)
12015 json_object_string_add(json_addr,
12016 "outgoingUpdatePrefixFilterList",
12017 filter->plist[FILTER_OUT].name);
12018
12019 /* distribute-list */
12020 if (filter->dlist[FILTER_IN].name)
12021 json_object_string_add(
12022 json_addr, "incomingUpdateNetworkFilterList",
12023 filter->dlist[FILTER_IN].name);
12024 if (filter->dlist[FILTER_OUT].name)
12025 json_object_string_add(
12026 json_addr, "outgoingUpdateNetworkFilterList",
12027 filter->dlist[FILTER_OUT].name);
12028
12029 /* filter-list. */
12030 if (filter->aslist[FILTER_IN].name)
12031 json_object_string_add(json_addr,
12032 "incomingUpdateAsPathFilterList",
12033 filter->aslist[FILTER_IN].name);
12034 if (filter->aslist[FILTER_OUT].name)
12035 json_object_string_add(json_addr,
12036 "outgoingUpdateAsPathFilterList",
12037 filter->aslist[FILTER_OUT].name);
12038
12039 /* route-map. */
12040 if (filter->map[RMAP_IN].name)
12041 json_object_string_add(
12042 json_addr, "routeMapForIncomingAdvertisements",
12043 filter->map[RMAP_IN].name);
12044 if (filter->map[RMAP_OUT].name)
12045 json_object_string_add(
12046 json_addr, "routeMapForOutgoingAdvertisements",
12047 filter->map[RMAP_OUT].name);
12048
12049 /* ebgp-requires-policy (inbound) */
12050 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12051 && !bgp_inbound_policy_exists(p, filter))
12052 json_object_string_add(
12053 json_addr, "inboundEbgpRequiresPolicy",
12054 "Inbound updates discarded due to missing policy");
12055
12056 /* ebgp-requires-policy (outbound) */
12057 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12058 && (!bgp_outbound_policy_exists(p, filter)))
12059 json_object_string_add(
12060 json_addr, "outboundEbgpRequiresPolicy",
12061 "Outbound updates discarded due to missing policy");
12062
12063 /* unsuppress-map */
12064 if (filter->usmap.name)
12065 json_object_string_add(json_addr,
12066 "selectiveUnsuppressRouteMap",
12067 filter->usmap.name);
12068
12069 /* advertise-map */
12070 if (filter->advmap.aname) {
12071 json_advmap = json_object_new_object();
12072 json_object_string_add(json_advmap, "condition",
12073 filter->advmap.condition
12074 ? "EXIST"
12075 : "NON_EXIST");
12076 json_object_string_add(json_advmap, "conditionMap",
12077 filter->advmap.cname);
12078 json_object_string_add(json_advmap, "advertiseMap",
12079 filter->advmap.aname);
12080 json_object_string_add(json_advmap, "advertiseStatus",
12081 filter->advmap.update_type
12082 == ADVERTISE
12083 ? "Advertise"
12084 : "Withdraw");
12085 json_object_object_add(json_addr, "advertiseMap",
12086 json_advmap);
12087 }
12088
12089 /* Receive prefix count */
12090 json_object_int_add(json_addr, "acceptedPrefixCounter",
12091 p->pcount[afi][safi]);
12092 if (paf && PAF_SUBGRP(paf))
12093 json_object_int_add(json_addr, "sentPrefixCounter",
12094 (PAF_SUBGRP(paf))->scount);
12095
12096 /* Maximum prefix */
12097 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
12098 json_object_int_add(json_addr, "prefixOutAllowedMax",
12099 p->pmax_out[afi][safi]);
12100
12101 /* Maximum prefix */
12102 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12103 json_object_int_add(json_addr, "prefixAllowedMax",
12104 p->pmax[afi][safi]);
12105 if (CHECK_FLAG(p->af_flags[afi][safi],
12106 PEER_FLAG_MAX_PREFIX_WARNING))
12107 json_object_boolean_true_add(
12108 json_addr, "prefixAllowedMaxWarning");
12109 json_object_int_add(json_addr,
12110 "prefixAllowedWarningThresh",
12111 p->pmax_threshold[afi][safi]);
12112 if (p->pmax_restart[afi][safi])
12113 json_object_int_add(
12114 json_addr,
12115 "prefixAllowedRestartIntervalMsecs",
12116 p->pmax_restart[afi][safi] * 60000);
12117 }
12118 json_object_object_add(json_neigh,
12119 get_afi_safi_str(afi, safi, true),
12120 json_addr);
12121
12122 } else {
12123 filter = &p->filter[afi][safi];
12124
12125 vty_out(vty, " For address family: %s\n",
12126 get_afi_safi_str(afi, safi, false));
12127
12128 if (peer_group_active(p))
12129 vty_out(vty, " %s peer-group member\n",
12130 p->group->name);
12131
12132 paf = peer_af_find(p, afi, safi);
12133 if (paf && PAF_SUBGRP(paf)) {
12134 vty_out(vty, " Update group %" PRIu64", subgroup %" PRIu64 "\n",
12135 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
12136 vty_out(vty, " Packet Queue length %d\n",
12137 bpacket_queue_virtual_length(paf));
12138 } else {
12139 vty_out(vty, " Not part of any update group\n");
12140 }
12141 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12142 || CHECK_FLAG(p->af_cap[afi][safi],
12143 PEER_CAP_ORF_PREFIX_SM_RCV)
12144 || CHECK_FLAG(p->af_cap[afi][safi],
12145 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12146 || CHECK_FLAG(p->af_cap[afi][safi],
12147 PEER_CAP_ORF_PREFIX_RM_ADV)
12148 || CHECK_FLAG(p->af_cap[afi][safi],
12149 PEER_CAP_ORF_PREFIX_RM_RCV)
12150 || CHECK_FLAG(p->af_cap[afi][safi],
12151 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12152 vty_out(vty, " AF-dependant capabilities:\n");
12153
12154 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12155 || CHECK_FLAG(p->af_cap[afi][safi],
12156 PEER_CAP_ORF_PREFIX_SM_RCV)
12157 || CHECK_FLAG(p->af_cap[afi][safi],
12158 PEER_CAP_ORF_PREFIX_RM_ADV)
12159 || CHECK_FLAG(p->af_cap[afi][safi],
12160 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12161 vty_out(vty,
12162 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12163 ORF_TYPE_PREFIX);
12164 bgp_show_peer_afi_orf_cap(
12165 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12166 PEER_CAP_ORF_PREFIX_RM_ADV,
12167 PEER_CAP_ORF_PREFIX_SM_RCV,
12168 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
12169 }
12170 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12171 || CHECK_FLAG(p->af_cap[afi][safi],
12172 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12173 || CHECK_FLAG(p->af_cap[afi][safi],
12174 PEER_CAP_ORF_PREFIX_RM_ADV)
12175 || CHECK_FLAG(p->af_cap[afi][safi],
12176 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12177 vty_out(vty,
12178 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12179 ORF_TYPE_PREFIX_OLD);
12180 bgp_show_peer_afi_orf_cap(
12181 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12182 PEER_CAP_ORF_PREFIX_RM_ADV,
12183 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12184 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
12185 }
12186
12187 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12188 p->host, afi, safi);
12189 orf_pfx_count = prefix_bgp_show_prefix_list(
12190 NULL, afi, orf_pfx_name, use_json);
12191
12192 if (CHECK_FLAG(p->af_sflags[afi][safi],
12193 PEER_STATUS_ORF_PREFIX_SEND)
12194 || orf_pfx_count) {
12195 vty_out(vty, " Outbound Route Filter (ORF):");
12196 if (CHECK_FLAG(p->af_sflags[afi][safi],
12197 PEER_STATUS_ORF_PREFIX_SEND))
12198 vty_out(vty, " sent;");
12199 if (orf_pfx_count)
12200 vty_out(vty, " received (%d entries)",
12201 orf_pfx_count);
12202 vty_out(vty, "\n");
12203 }
12204 if (CHECK_FLAG(p->af_sflags[afi][safi],
12205 PEER_STATUS_ORF_WAIT_REFRESH))
12206 vty_out(vty,
12207 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
12208
12209 if (CHECK_FLAG(p->af_flags[afi][safi],
12210 PEER_FLAG_REFLECTOR_CLIENT))
12211 vty_out(vty, " Route-Reflector Client\n");
12212 if (CHECK_FLAG(p->af_flags[afi][safi],
12213 PEER_FLAG_RSERVER_CLIENT))
12214 vty_out(vty, " Route-Server Client\n");
12215 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12216 vty_out(vty,
12217 " Inbound soft reconfiguration allowed\n");
12218
12219 if (CHECK_FLAG(p->af_flags[afi][safi],
12220 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12221 vty_out(vty,
12222 " Private AS numbers (all) replaced in updates to this neighbor\n");
12223 else if (CHECK_FLAG(p->af_flags[afi][safi],
12224 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12225 vty_out(vty,
12226 " Private AS numbers replaced in updates to this neighbor\n");
12227 else if (CHECK_FLAG(p->af_flags[afi][safi],
12228 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12229 vty_out(vty,
12230 " Private AS numbers (all) removed in updates to this neighbor\n");
12231 else if (CHECK_FLAG(p->af_flags[afi][safi],
12232 PEER_FLAG_REMOVE_PRIVATE_AS))
12233 vty_out(vty,
12234 " Private AS numbers removed in updates to this neighbor\n");
12235
12236 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12237 vty_out(vty, " %s\n",
12238 bgp_addpath_names(p->addpath_type[afi][safi])
12239 ->human_description);
12240
12241 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12242 vty_out(vty,
12243 " Override ASNs in outbound updates if aspath equals remote-as\n");
12244
12245 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12246 || CHECK_FLAG(p->af_flags[afi][safi],
12247 PEER_FLAG_FORCE_NEXTHOP_SELF))
12248 vty_out(vty, " NEXT_HOP is always this router\n");
12249 if (CHECK_FLAG(p->af_flags[afi][safi],
12250 PEER_FLAG_AS_PATH_UNCHANGED))
12251 vty_out(vty,
12252 " AS_PATH is propagated unchanged to this neighbor\n");
12253 if (CHECK_FLAG(p->af_flags[afi][safi],
12254 PEER_FLAG_NEXTHOP_UNCHANGED))
12255 vty_out(vty,
12256 " NEXT_HOP is propagated unchanged to this neighbor\n");
12257 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12258 vty_out(vty,
12259 " MED is propagated unchanged to this neighbor\n");
12260 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12261 || CHECK_FLAG(p->af_flags[afi][safi],
12262 PEER_FLAG_SEND_EXT_COMMUNITY)
12263 || CHECK_FLAG(p->af_flags[afi][safi],
12264 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
12265 vty_out(vty,
12266 " Community attribute sent to this neighbor");
12267 if (CHECK_FLAG(p->af_flags[afi][safi],
12268 PEER_FLAG_SEND_COMMUNITY)
12269 && CHECK_FLAG(p->af_flags[afi][safi],
12270 PEER_FLAG_SEND_EXT_COMMUNITY)
12271 && CHECK_FLAG(p->af_flags[afi][safi],
12272 PEER_FLAG_SEND_LARGE_COMMUNITY))
12273 vty_out(vty, "(all)\n");
12274 else if (CHECK_FLAG(p->af_flags[afi][safi],
12275 PEER_FLAG_SEND_LARGE_COMMUNITY))
12276 vty_out(vty, "(large)\n");
12277 else if (CHECK_FLAG(p->af_flags[afi][safi],
12278 PEER_FLAG_SEND_EXT_COMMUNITY))
12279 vty_out(vty, "(extended)\n");
12280 else
12281 vty_out(vty, "(standard)\n");
12282 }
12283 if (CHECK_FLAG(p->af_flags[afi][safi],
12284 PEER_FLAG_DEFAULT_ORIGINATE)) {
12285 vty_out(vty, " Default information originate,");
12286
12287 if (p->default_rmap[afi][safi].name)
12288 vty_out(vty, " default route-map %s%s,",
12289 p->default_rmap[afi][safi].map ? "*"
12290 : "",
12291 p->default_rmap[afi][safi].name);
12292 if (paf && PAF_SUBGRP(paf)
12293 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12294 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12295 vty_out(vty, " default sent\n");
12296 else
12297 vty_out(vty, " default not sent\n");
12298 }
12299
12300 /* advertise-vni-all */
12301 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
12302 if (is_evpn_enabled())
12303 vty_out(vty, " advertise-all-vni\n");
12304 }
12305
12306 if (filter->plist[FILTER_IN].name
12307 || filter->dlist[FILTER_IN].name
12308 || filter->aslist[FILTER_IN].name
12309 || filter->map[RMAP_IN].name)
12310 vty_out(vty, " Inbound path policy configured\n");
12311 if (filter->plist[FILTER_OUT].name
12312 || filter->dlist[FILTER_OUT].name
12313 || filter->aslist[FILTER_OUT].name
12314 || filter->map[RMAP_OUT].name || filter->usmap.name)
12315 vty_out(vty, " Outbound path policy configured\n");
12316
12317 /* prefix-list */
12318 if (filter->plist[FILTER_IN].name)
12319 vty_out(vty,
12320 " Incoming update prefix filter list is %s%s\n",
12321 filter->plist[FILTER_IN].plist ? "*" : "",
12322 filter->plist[FILTER_IN].name);
12323 if (filter->plist[FILTER_OUT].name)
12324 vty_out(vty,
12325 " Outgoing update prefix filter list is %s%s\n",
12326 filter->plist[FILTER_OUT].plist ? "*" : "",
12327 filter->plist[FILTER_OUT].name);
12328
12329 /* distribute-list */
12330 if (filter->dlist[FILTER_IN].name)
12331 vty_out(vty,
12332 " Incoming update network filter list is %s%s\n",
12333 filter->dlist[FILTER_IN].alist ? "*" : "",
12334 filter->dlist[FILTER_IN].name);
12335 if (filter->dlist[FILTER_OUT].name)
12336 vty_out(vty,
12337 " Outgoing update network filter list is %s%s\n",
12338 filter->dlist[FILTER_OUT].alist ? "*" : "",
12339 filter->dlist[FILTER_OUT].name);
12340
12341 /* filter-list. */
12342 if (filter->aslist[FILTER_IN].name)
12343 vty_out(vty,
12344 " Incoming update AS path filter list is %s%s\n",
12345 filter->aslist[FILTER_IN].aslist ? "*" : "",
12346 filter->aslist[FILTER_IN].name);
12347 if (filter->aslist[FILTER_OUT].name)
12348 vty_out(vty,
12349 " Outgoing update AS path filter list is %s%s\n",
12350 filter->aslist[FILTER_OUT].aslist ? "*" : "",
12351 filter->aslist[FILTER_OUT].name);
12352
12353 /* route-map. */
12354 if (filter->map[RMAP_IN].name)
12355 vty_out(vty,
12356 " Route map for incoming advertisements is %s%s\n",
12357 filter->map[RMAP_IN].map ? "*" : "",
12358 filter->map[RMAP_IN].name);
12359 if (filter->map[RMAP_OUT].name)
12360 vty_out(vty,
12361 " Route map for outgoing advertisements is %s%s\n",
12362 filter->map[RMAP_OUT].map ? "*" : "",
12363 filter->map[RMAP_OUT].name);
12364
12365 /* ebgp-requires-policy (inbound) */
12366 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12367 && !bgp_inbound_policy_exists(p, filter))
12368 vty_out(vty,
12369 " Inbound updates discarded due to missing policy\n");
12370
12371 /* ebgp-requires-policy (outbound) */
12372 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12373 && !bgp_outbound_policy_exists(p, filter))
12374 vty_out(vty,
12375 " Outbound updates discarded due to missing policy\n");
12376
12377 /* unsuppress-map */
12378 if (filter->usmap.name)
12379 vty_out(vty,
12380 " Route map for selective unsuppress is %s%s\n",
12381 filter->usmap.map ? "*" : "",
12382 filter->usmap.name);
12383
12384 /* advertise-map */
12385 if (filter->advmap.aname && filter->advmap.cname)
12386 vty_out(vty,
12387 " Condition %s, Condition-map %s%s, Advertise-map %s%s, status: %s\n",
12388 filter->advmap.condition ? "EXIST"
12389 : "NON_EXIST",
12390 filter->advmap.cmap ? "*" : "",
12391 filter->advmap.cname,
12392 filter->advmap.amap ? "*" : "",
12393 filter->advmap.aname,
12394 filter->advmap.update_type == ADVERTISE
12395 ? "Advertise"
12396 : "Withdraw");
12397
12398 /* Receive prefix count */
12399 vty_out(vty, " %u accepted prefixes\n",
12400 p->pcount[afi][safi]);
12401
12402 /* maximum-prefix-out */
12403 if (CHECK_FLAG(p->af_flags[afi][safi],
12404 PEER_FLAG_MAX_PREFIX_OUT))
12405 vty_out(vty,
12406 " Maximum allowed prefixes sent %u\n",
12407 p->pmax_out[afi][safi]);
12408
12409 /* Maximum prefix */
12410 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12411 vty_out(vty,
12412 " Maximum prefixes allowed %u%s\n",
12413 p->pmax[afi][safi],
12414 CHECK_FLAG(p->af_flags[afi][safi],
12415 PEER_FLAG_MAX_PREFIX_WARNING)
12416 ? " (warning-only)"
12417 : "");
12418 vty_out(vty, " Threshold for warning message %d%%",
12419 p->pmax_threshold[afi][safi]);
12420 if (p->pmax_restart[afi][safi])
12421 vty_out(vty, ", restart interval %d min",
12422 p->pmax_restart[afi][safi]);
12423 vty_out(vty, "\n");
12424 }
12425
12426 vty_out(vty, "\n");
12427 }
12428 }
12429
12430 static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
12431 json_object *json)
12432 {
12433 struct bgp *bgp;
12434 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
12435 char timebuf[BGP_UPTIME_LEN];
12436 char dn_flag[2];
12437 afi_t afi;
12438 safi_t safi;
12439 uint16_t i;
12440 uint8_t *msg;
12441 json_object *json_neigh = NULL;
12442 time_t epoch_tbuf;
12443
12444 bgp = p->bgp;
12445
12446 if (use_json)
12447 json_neigh = json_object_new_object();
12448
12449 memset(dn_flag, '\0', sizeof(dn_flag));
12450 if (!p->conf_if && peer_dynamic_neighbor(p))
12451 dn_flag[0] = '*';
12452
12453 if (!use_json) {
12454 if (p->conf_if) /* Configured interface name. */
12455 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
12456 BGP_PEER_SU_UNSPEC(p)
12457 ? "None"
12458 : sockunion2str(&p->su, buf,
12459 SU_ADDRSTRLEN));
12460 else /* Configured IP address. */
12461 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
12462 p->host);
12463 }
12464
12465 if (use_json) {
12466 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
12467 json_object_string_add(json_neigh, "bgpNeighborAddr",
12468 "none");
12469 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
12470 json_object_string_add(
12471 json_neigh, "bgpNeighborAddr",
12472 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
12473
12474 json_object_int_add(json_neigh, "remoteAs", p->as);
12475
12476 if (p->change_local_as)
12477 json_object_int_add(json_neigh, "localAs",
12478 p->change_local_as);
12479 else
12480 json_object_int_add(json_neigh, "localAs", p->local_as);
12481
12482 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
12483 json_object_boolean_true_add(json_neigh,
12484 "localAsNoPrepend");
12485
12486 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
12487 json_object_boolean_true_add(json_neigh,
12488 "localAsReplaceAs");
12489 } else {
12490 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
12491 || (p->as_type == AS_INTERNAL))
12492 vty_out(vty, "remote AS %u, ", p->as);
12493 else
12494 vty_out(vty, "remote AS Unspecified, ");
12495 vty_out(vty, "local AS %u%s%s, ",
12496 p->change_local_as ? p->change_local_as : p->local_as,
12497 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
12498 ? " no-prepend"
12499 : "",
12500 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
12501 ? " replace-as"
12502 : "");
12503 }
12504 /* peer type internal or confed-internal */
12505 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
12506 if (use_json) {
12507 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12508 json_object_boolean_true_add(
12509 json_neigh, "nbrConfedInternalLink");
12510 else
12511 json_object_boolean_true_add(json_neigh,
12512 "nbrInternalLink");
12513 } else {
12514 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12515 vty_out(vty, "confed-internal link\n");
12516 else
12517 vty_out(vty, "internal link\n");
12518 }
12519 /* peer type external or confed-external */
12520 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
12521 if (use_json) {
12522 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12523 json_object_boolean_true_add(
12524 json_neigh, "nbrConfedExternalLink");
12525 else
12526 json_object_boolean_true_add(json_neigh,
12527 "nbrExternalLink");
12528 } else {
12529 if (bgp_confederation_peers_check(bgp, p->as))
12530 vty_out(vty, "confed-external link\n");
12531 else
12532 vty_out(vty, "external link\n");
12533 }
12534 } else {
12535 if (use_json)
12536 json_object_boolean_true_add(json_neigh,
12537 "nbrUnspecifiedLink");
12538 else
12539 vty_out(vty, "unspecified link\n");
12540 }
12541
12542 /* Description. */
12543 if (p->desc) {
12544 if (use_json)
12545 json_object_string_add(json_neigh, "nbrDesc", p->desc);
12546 else
12547 vty_out(vty, " Description: %s\n", p->desc);
12548 }
12549
12550 if (p->hostname) {
12551 if (use_json) {
12552 if (p->hostname)
12553 json_object_string_add(json_neigh, "hostname",
12554 p->hostname);
12555
12556 if (p->domainname)
12557 json_object_string_add(json_neigh, "domainname",
12558 p->domainname);
12559 } else {
12560 if (p->domainname && (p->domainname[0] != '\0'))
12561 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
12562 p->domainname);
12563 else
12564 vty_out(vty, "Hostname: %s\n", p->hostname);
12565 }
12566 }
12567
12568 /* Peer-group */
12569 if (p->group) {
12570 if (use_json) {
12571 json_object_string_add(json_neigh, "peerGroup",
12572 p->group->name);
12573
12574 if (dn_flag[0]) {
12575 struct prefix prefix, *range = NULL;
12576
12577 if (sockunion2hostprefix(&(p->su), &prefix))
12578 range = peer_group_lookup_dynamic_neighbor_range(
12579 p->group, &prefix);
12580
12581 if (range) {
12582 prefix2str(range, buf1, sizeof(buf1));
12583 json_object_string_add(
12584 json_neigh,
12585 "peerSubnetRangeGroup", buf1);
12586 }
12587 }
12588 } else {
12589 vty_out(vty,
12590 " Member of peer-group %s for session parameters\n",
12591 p->group->name);
12592
12593 if (dn_flag[0]) {
12594 struct prefix prefix, *range = NULL;
12595
12596 if (sockunion2hostprefix(&(p->su), &prefix))
12597 range = peer_group_lookup_dynamic_neighbor_range(
12598 p->group, &prefix);
12599
12600 if (range) {
12601 vty_out(vty,
12602 " Belongs to the subnet range group: %pFX\n",
12603 range);
12604 }
12605 }
12606 }
12607 }
12608
12609 if (use_json) {
12610 /* Administrative shutdown. */
12611 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12612 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
12613 json_object_boolean_true_add(json_neigh,
12614 "adminShutDown");
12615
12616 /* BGP Version. */
12617 json_object_int_add(json_neigh, "bgpVersion", 4);
12618 json_object_string_add(
12619 json_neigh, "remoteRouterId",
12620 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
12621 json_object_string_add(
12622 json_neigh, "localRouterId",
12623 inet_ntop(AF_INET, &bgp->router_id, buf1,
12624 sizeof(buf1)));
12625
12626 /* Confederation */
12627 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12628 && bgp_confederation_peers_check(bgp, p->as))
12629 json_object_boolean_true_add(json_neigh,
12630 "nbrCommonAdmin");
12631
12632 /* Status. */
12633 json_object_string_add(
12634 json_neigh, "bgpState",
12635 lookup_msg(bgp_status_msg, p->status, NULL));
12636
12637 if (p->status == Established) {
12638 time_t uptime;
12639
12640 uptime = bgp_clock();
12641 uptime -= p->uptime;
12642 epoch_tbuf = time(NULL) - uptime;
12643
12644 json_object_int_add(json_neigh, "bgpTimerUpMsec",
12645 uptime * 1000);
12646 json_object_string_add(json_neigh, "bgpTimerUpString",
12647 peer_uptime(p->uptime, timebuf,
12648 BGP_UPTIME_LEN, 0,
12649 NULL));
12650 json_object_int_add(json_neigh,
12651 "bgpTimerUpEstablishedEpoch",
12652 epoch_tbuf);
12653 }
12654
12655 else if (p->status == Active) {
12656 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12657 json_object_string_add(json_neigh, "bgpStateIs",
12658 "passive");
12659 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12660 json_object_string_add(json_neigh, "bgpStateIs",
12661 "passiveNSF");
12662 }
12663
12664 /* read timer */
12665 time_t uptime;
12666 struct tm tm;
12667
12668 uptime = bgp_clock();
12669 uptime -= p->readtime;
12670 gmtime_r(&uptime, &tm);
12671
12672 json_object_int_add(json_neigh, "bgpTimerLastRead",
12673 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12674 + (tm.tm_hour * 3600000));
12675
12676 uptime = bgp_clock();
12677 uptime -= p->last_write;
12678 gmtime_r(&uptime, &tm);
12679
12680 json_object_int_add(json_neigh, "bgpTimerLastWrite",
12681 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12682 + (tm.tm_hour * 3600000));
12683
12684 uptime = bgp_clock();
12685 uptime -= p->update_time;
12686 gmtime_r(&uptime, &tm);
12687
12688 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
12689 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12690 + (tm.tm_hour * 3600000));
12691
12692 /* Configured timer values. */
12693 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
12694 p->v_holdtime * 1000);
12695 json_object_int_add(json_neigh,
12696 "bgpTimerKeepAliveIntervalMsecs",
12697 p->v_keepalive * 1000);
12698 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN)) {
12699 json_object_int_add(json_neigh,
12700 "bgpTimerDelayOpenTimeMsecs",
12701 p->v_delayopen * 1000);
12702 }
12703
12704 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
12705 json_object_int_add(json_neigh,
12706 "bgpTimerConfiguredHoldTimeMsecs",
12707 p->holdtime * 1000);
12708 json_object_int_add(
12709 json_neigh,
12710 "bgpTimerConfiguredKeepAliveIntervalMsecs",
12711 p->keepalive * 1000);
12712 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
12713 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
12714 json_object_int_add(json_neigh,
12715 "bgpTimerConfiguredHoldTimeMsecs",
12716 bgp->default_holdtime);
12717 json_object_int_add(
12718 json_neigh,
12719 "bgpTimerConfiguredKeepAliveIntervalMsecs",
12720 bgp->default_keepalive);
12721 }
12722 } else {
12723 /* Administrative shutdown. */
12724 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12725 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
12726 vty_out(vty, " Administratively shut down\n");
12727
12728 /* BGP Version. */
12729 vty_out(vty, " BGP version 4");
12730 vty_out(vty, ", remote router ID %s",
12731 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
12732 vty_out(vty, ", local router ID %s\n",
12733 inet_ntop(AF_INET, &bgp->router_id, buf1,
12734 sizeof(buf1)));
12735
12736 /* Confederation */
12737 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12738 && bgp_confederation_peers_check(bgp, p->as))
12739 vty_out(vty,
12740 " Neighbor under common administration\n");
12741
12742 /* Status. */
12743 vty_out(vty, " BGP state = %s",
12744 lookup_msg(bgp_status_msg, p->status, NULL));
12745
12746 if (p->status == Established)
12747 vty_out(vty, ", up for %8s",
12748 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
12749 0, NULL));
12750
12751 else if (p->status == Active) {
12752 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12753 vty_out(vty, " (passive)");
12754 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12755 vty_out(vty, " (NSF passive)");
12756 }
12757 vty_out(vty, "\n");
12758
12759 /* read timer */
12760 vty_out(vty, " Last read %s",
12761 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
12762 NULL));
12763 vty_out(vty, ", Last write %s\n",
12764 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
12765 NULL));
12766
12767 /* Configured timer values. */
12768 vty_out(vty,
12769 " Hold time is %d, keepalive interval is %d seconds\n",
12770 p->v_holdtime, p->v_keepalive);
12771 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
12772 vty_out(vty, " Configured hold time is %d",
12773 p->holdtime);
12774 vty_out(vty, ", keepalive interval is %d seconds\n",
12775 p->keepalive);
12776 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
12777 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
12778 vty_out(vty, " Configured hold time is %d",
12779 bgp->default_holdtime);
12780 vty_out(vty, ", keepalive interval is %d seconds\n",
12781 bgp->default_keepalive);
12782 }
12783 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN))
12784 vty_out(vty,
12785 " Configured DelayOpenTime is %d seconds\n",
12786 p->delayopen);
12787 }
12788 /* Capability. */
12789 if (p->status == Established) {
12790 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
12791 || p->afc_recv[AFI_IP][SAFI_UNICAST]
12792 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
12793 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
12794 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
12795 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
12796 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
12797 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
12798 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
12799 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
12800 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
12801 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
12802 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
12803 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
12804 || p->afc_adv[AFI_IP][SAFI_ENCAP]
12805 || p->afc_recv[AFI_IP][SAFI_ENCAP]
12806 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
12807 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
12808 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
12809 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
12810 if (use_json) {
12811 json_object *json_cap = NULL;
12812
12813 json_cap = json_object_new_object();
12814
12815 /* AS4 */
12816 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
12817 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
12818 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
12819 && CHECK_FLAG(p->cap,
12820 PEER_CAP_AS4_RCV))
12821 json_object_string_add(
12822 json_cap, "4byteAs",
12823 "advertisedAndReceived");
12824 else if (CHECK_FLAG(p->cap,
12825 PEER_CAP_AS4_ADV))
12826 json_object_string_add(
12827 json_cap, "4byteAs",
12828 "advertised");
12829 else if (CHECK_FLAG(p->cap,
12830 PEER_CAP_AS4_RCV))
12831 json_object_string_add(
12832 json_cap, "4byteAs",
12833 "received");
12834 }
12835
12836 /* AddPath */
12837 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
12838 || CHECK_FLAG(p->cap,
12839 PEER_CAP_ADDPATH_ADV)) {
12840 json_object *json_add = NULL;
12841 const char *print_store;
12842
12843 json_add = json_object_new_object();
12844
12845 FOREACH_AFI_SAFI (afi, safi) {
12846 json_object *json_sub = NULL;
12847 json_sub =
12848 json_object_new_object();
12849 print_store = get_afi_safi_str(
12850 afi, safi, true);
12851
12852 if (CHECK_FLAG(
12853 p->af_cap[afi]
12854 [safi],
12855 PEER_CAP_ADDPATH_AF_TX_ADV)
12856 || CHECK_FLAG(
12857 p->af_cap[afi]
12858 [safi],
12859 PEER_CAP_ADDPATH_AF_TX_RCV)) {
12860 if (CHECK_FLAG(
12861 p->af_cap
12862 [afi]
12863 [safi],
12864 PEER_CAP_ADDPATH_AF_TX_ADV)
12865 && CHECK_FLAG(
12866 p->af_cap
12867 [afi]
12868 [safi],
12869 PEER_CAP_ADDPATH_AF_TX_RCV))
12870 json_object_boolean_true_add(
12871 json_sub,
12872 "txAdvertisedAndReceived");
12873 else if (
12874 CHECK_FLAG(
12875 p->af_cap
12876 [afi]
12877 [safi],
12878 PEER_CAP_ADDPATH_AF_TX_ADV))
12879 json_object_boolean_true_add(
12880 json_sub,
12881 "txAdvertised");
12882 else if (
12883 CHECK_FLAG(
12884 p->af_cap
12885 [afi]
12886 [safi],
12887 PEER_CAP_ADDPATH_AF_TX_RCV))
12888 json_object_boolean_true_add(
12889 json_sub,
12890 "txReceived");
12891 }
12892
12893 if (CHECK_FLAG(
12894 p->af_cap[afi]
12895 [safi],
12896 PEER_CAP_ADDPATH_AF_RX_ADV)
12897 || CHECK_FLAG(
12898 p->af_cap[afi]
12899 [safi],
12900 PEER_CAP_ADDPATH_AF_RX_RCV)) {
12901 if (CHECK_FLAG(
12902 p->af_cap
12903 [afi]
12904 [safi],
12905 PEER_CAP_ADDPATH_AF_RX_ADV)
12906 && CHECK_FLAG(
12907 p->af_cap
12908 [afi]
12909 [safi],
12910 PEER_CAP_ADDPATH_AF_RX_RCV))
12911 json_object_boolean_true_add(
12912 json_sub,
12913 "rxAdvertisedAndReceived");
12914 else if (
12915 CHECK_FLAG(
12916 p->af_cap
12917 [afi]
12918 [safi],
12919 PEER_CAP_ADDPATH_AF_RX_ADV))
12920 json_object_boolean_true_add(
12921 json_sub,
12922 "rxAdvertised");
12923 else if (
12924 CHECK_FLAG(
12925 p->af_cap
12926 [afi]
12927 [safi],
12928 PEER_CAP_ADDPATH_AF_RX_RCV))
12929 json_object_boolean_true_add(
12930 json_sub,
12931 "rxReceived");
12932 }
12933
12934 if (CHECK_FLAG(
12935 p->af_cap[afi]
12936 [safi],
12937 PEER_CAP_ADDPATH_AF_TX_ADV)
12938 || CHECK_FLAG(
12939 p->af_cap[afi]
12940 [safi],
12941 PEER_CAP_ADDPATH_AF_TX_RCV)
12942 || CHECK_FLAG(
12943 p->af_cap[afi]
12944 [safi],
12945 PEER_CAP_ADDPATH_AF_RX_ADV)
12946 || CHECK_FLAG(
12947 p->af_cap[afi]
12948 [safi],
12949 PEER_CAP_ADDPATH_AF_RX_RCV))
12950 json_object_object_add(
12951 json_add,
12952 print_store,
12953 json_sub);
12954 else
12955 json_object_free(
12956 json_sub);
12957 }
12958
12959 json_object_object_add(
12960 json_cap, "addPath", json_add);
12961 }
12962
12963 /* Dynamic */
12964 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
12965 || CHECK_FLAG(p->cap,
12966 PEER_CAP_DYNAMIC_ADV)) {
12967 if (CHECK_FLAG(p->cap,
12968 PEER_CAP_DYNAMIC_ADV)
12969 && CHECK_FLAG(p->cap,
12970 PEER_CAP_DYNAMIC_RCV))
12971 json_object_string_add(
12972 json_cap, "dynamic",
12973 "advertisedAndReceived");
12974 else if (CHECK_FLAG(
12975 p->cap,
12976 PEER_CAP_DYNAMIC_ADV))
12977 json_object_string_add(
12978 json_cap, "dynamic",
12979 "advertised");
12980 else if (CHECK_FLAG(
12981 p->cap,
12982 PEER_CAP_DYNAMIC_RCV))
12983 json_object_string_add(
12984 json_cap, "dynamic",
12985 "received");
12986 }
12987
12988 /* Extended nexthop */
12989 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
12990 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
12991 json_object *json_nxt = NULL;
12992 const char *print_store;
12993
12994
12995 if (CHECK_FLAG(p->cap,
12996 PEER_CAP_ENHE_ADV)
12997 && CHECK_FLAG(p->cap,
12998 PEER_CAP_ENHE_RCV))
12999 json_object_string_add(
13000 json_cap,
13001 "extendedNexthop",
13002 "advertisedAndReceived");
13003 else if (CHECK_FLAG(p->cap,
13004 PEER_CAP_ENHE_ADV))
13005 json_object_string_add(
13006 json_cap,
13007 "extendedNexthop",
13008 "advertised");
13009 else if (CHECK_FLAG(p->cap,
13010 PEER_CAP_ENHE_RCV))
13011 json_object_string_add(
13012 json_cap,
13013 "extendedNexthop",
13014 "received");
13015
13016 if (CHECK_FLAG(p->cap,
13017 PEER_CAP_ENHE_RCV)) {
13018 json_nxt =
13019 json_object_new_object();
13020
13021 for (safi = SAFI_UNICAST;
13022 safi < SAFI_MAX; safi++) {
13023 if (CHECK_FLAG(
13024 p->af_cap
13025 [AFI_IP]
13026 [safi],
13027 PEER_CAP_ENHE_AF_RCV)) {
13028 print_store = get_afi_safi_str(
13029 AFI_IP,
13030 safi, true);
13031 json_object_string_add(
13032 json_nxt,
13033 print_store,
13034 "recieved"); /* misspelled for compatibility */
13035 }
13036 }
13037 json_object_object_add(
13038 json_cap,
13039 "extendedNexthopFamililesByPeer",
13040 json_nxt);
13041 }
13042 }
13043
13044 /* Route Refresh */
13045 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
13046 || CHECK_FLAG(p->cap,
13047 PEER_CAP_REFRESH_NEW_RCV)
13048 || CHECK_FLAG(p->cap,
13049 PEER_CAP_REFRESH_OLD_RCV)) {
13050 if (CHECK_FLAG(p->cap,
13051 PEER_CAP_REFRESH_ADV)
13052 && (CHECK_FLAG(
13053 p->cap,
13054 PEER_CAP_REFRESH_NEW_RCV)
13055 || CHECK_FLAG(
13056 p->cap,
13057 PEER_CAP_REFRESH_OLD_RCV))) {
13058 if (CHECK_FLAG(
13059 p->cap,
13060 PEER_CAP_REFRESH_OLD_RCV)
13061 && CHECK_FLAG(
13062 p->cap,
13063 PEER_CAP_REFRESH_NEW_RCV))
13064 json_object_string_add(
13065 json_cap,
13066 "routeRefresh",
13067 "advertisedAndReceivedOldNew");
13068 else {
13069 if (CHECK_FLAG(
13070 p->cap,
13071 PEER_CAP_REFRESH_OLD_RCV))
13072 json_object_string_add(
13073 json_cap,
13074 "routeRefresh",
13075 "advertisedAndReceivedOld");
13076 else
13077 json_object_string_add(
13078 json_cap,
13079 "routeRefresh",
13080 "advertisedAndReceivedNew");
13081 }
13082 } else if (
13083 CHECK_FLAG(
13084 p->cap,
13085 PEER_CAP_REFRESH_ADV))
13086 json_object_string_add(
13087 json_cap,
13088 "routeRefresh",
13089 "advertised");
13090 else if (
13091 CHECK_FLAG(
13092 p->cap,
13093 PEER_CAP_REFRESH_NEW_RCV)
13094 || CHECK_FLAG(
13095 p->cap,
13096 PEER_CAP_REFRESH_OLD_RCV))
13097 json_object_string_add(
13098 json_cap,
13099 "routeRefresh",
13100 "received");
13101 }
13102
13103 /* Multiprotocol Extensions */
13104 json_object *json_multi = NULL;
13105 json_multi = json_object_new_object();
13106
13107 FOREACH_AFI_SAFI (afi, safi) {
13108 if (p->afc_adv[afi][safi]
13109 || p->afc_recv[afi][safi]) {
13110 json_object *json_exten = NULL;
13111 json_exten =
13112 json_object_new_object();
13113
13114 if (p->afc_adv[afi][safi]
13115 && p->afc_recv[afi][safi])
13116 json_object_boolean_true_add(
13117 json_exten,
13118 "advertisedAndReceived");
13119 else if (p->afc_adv[afi][safi])
13120 json_object_boolean_true_add(
13121 json_exten,
13122 "advertised");
13123 else if (p->afc_recv[afi][safi])
13124 json_object_boolean_true_add(
13125 json_exten,
13126 "received");
13127
13128 json_object_object_add(
13129 json_multi,
13130 get_afi_safi_str(afi,
13131 safi,
13132 true),
13133 json_exten);
13134 }
13135 }
13136 json_object_object_add(
13137 json_cap, "multiprotocolExtensions",
13138 json_multi);
13139
13140 /* Hostname capabilities */
13141 json_object *json_hname = NULL;
13142
13143 json_hname = json_object_new_object();
13144
13145 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13146 json_object_string_add(
13147 json_hname, "advHostName",
13148 bgp->peer_self->hostname
13149 ? bgp->peer_self
13150 ->hostname
13151 : "n/a");
13152 json_object_string_add(
13153 json_hname, "advDomainName",
13154 bgp->peer_self->domainname
13155 ? bgp->peer_self
13156 ->domainname
13157 : "n/a");
13158 }
13159
13160
13161 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13162 json_object_string_add(
13163 json_hname, "rcvHostName",
13164 p->hostname ? p->hostname
13165 : "n/a");
13166 json_object_string_add(
13167 json_hname, "rcvDomainName",
13168 p->domainname ? p->domainname
13169 : "n/a");
13170 }
13171
13172 json_object_object_add(json_cap, "hostName",
13173 json_hname);
13174
13175 /* Gracefull Restart */
13176 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
13177 || CHECK_FLAG(p->cap,
13178 PEER_CAP_RESTART_ADV)) {
13179 if (CHECK_FLAG(p->cap,
13180 PEER_CAP_RESTART_ADV)
13181 && CHECK_FLAG(p->cap,
13182 PEER_CAP_RESTART_RCV))
13183 json_object_string_add(
13184 json_cap,
13185 "gracefulRestart",
13186 "advertisedAndReceived");
13187 else if (CHECK_FLAG(
13188 p->cap,
13189 PEER_CAP_RESTART_ADV))
13190 json_object_string_add(
13191 json_cap,
13192 "gracefulRestartCapability",
13193 "advertised");
13194 else if (CHECK_FLAG(
13195 p->cap,
13196 PEER_CAP_RESTART_RCV))
13197 json_object_string_add(
13198 json_cap,
13199 "gracefulRestartCapability",
13200 "received");
13201
13202 if (CHECK_FLAG(p->cap,
13203 PEER_CAP_RESTART_RCV)) {
13204 int restart_af_count = 0;
13205 json_object *json_restart =
13206 NULL;
13207 json_restart =
13208 json_object_new_object();
13209
13210 json_object_int_add(
13211 json_cap,
13212 "gracefulRestartRemoteTimerMsecs",
13213 p->v_gr_restart * 1000);
13214
13215 FOREACH_AFI_SAFI (afi, safi) {
13216 if (CHECK_FLAG(
13217 p->af_cap
13218 [afi]
13219 [safi],
13220 PEER_CAP_RESTART_AF_RCV)) {
13221 json_object *
13222 json_sub =
13223 NULL;
13224 json_sub =
13225 json_object_new_object();
13226
13227 if (CHECK_FLAG(
13228 p->af_cap
13229 [afi]
13230 [safi],
13231 PEER_CAP_RESTART_AF_PRESERVE_RCV))
13232 json_object_boolean_true_add(
13233 json_sub,
13234 "preserved");
13235 restart_af_count++;
13236 json_object_object_add(
13237 json_restart,
13238 get_afi_safi_str(
13239 afi,
13240 safi,
13241 true),
13242 json_sub);
13243 }
13244 }
13245 if (!restart_af_count) {
13246 json_object_string_add(
13247 json_cap,
13248 "addressFamiliesByPeer",
13249 "none");
13250 json_object_free(
13251 json_restart);
13252 } else
13253 json_object_object_add(
13254 json_cap,
13255 "addressFamiliesByPeer",
13256 json_restart);
13257 }
13258 }
13259 json_object_object_add(json_neigh,
13260 "neighborCapabilities",
13261 json_cap);
13262 } else {
13263 vty_out(vty, " Neighbor capabilities:\n");
13264
13265 /* AS4 */
13266 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
13267 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13268 vty_out(vty, " 4 Byte AS:");
13269 if (CHECK_FLAG(p->cap,
13270 PEER_CAP_AS4_ADV))
13271 vty_out(vty, " advertised");
13272 if (CHECK_FLAG(p->cap,
13273 PEER_CAP_AS4_RCV))
13274 vty_out(vty, " %sreceived",
13275 CHECK_FLAG(
13276 p->cap,
13277 PEER_CAP_AS4_ADV)
13278 ? "and "
13279 : "");
13280 vty_out(vty, "\n");
13281 }
13282
13283 /* AddPath */
13284 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
13285 || CHECK_FLAG(p->cap,
13286 PEER_CAP_ADDPATH_ADV)) {
13287 vty_out(vty, " AddPath:\n");
13288
13289 FOREACH_AFI_SAFI (afi, safi) {
13290 if (CHECK_FLAG(
13291 p->af_cap[afi]
13292 [safi],
13293 PEER_CAP_ADDPATH_AF_TX_ADV)
13294 || CHECK_FLAG(
13295 p->af_cap[afi]
13296 [safi],
13297 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13298 vty_out(vty,
13299 " %s: TX ",
13300 get_afi_safi_str(
13301 afi,
13302 safi,
13303 false));
13304
13305 if (CHECK_FLAG(
13306 p->af_cap
13307 [afi]
13308 [safi],
13309 PEER_CAP_ADDPATH_AF_TX_ADV))
13310 vty_out(vty,
13311 "advertised %s",
13312 get_afi_safi_str(
13313 afi,
13314 safi,
13315 false));
13316
13317 if (CHECK_FLAG(
13318 p->af_cap
13319 [afi]
13320 [safi],
13321 PEER_CAP_ADDPATH_AF_TX_RCV))
13322 vty_out(vty,
13323 "%sreceived",
13324 CHECK_FLAG(
13325 p->af_cap
13326 [afi]
13327 [safi],
13328 PEER_CAP_ADDPATH_AF_TX_ADV)
13329 ? " and "
13330 : "");
13331
13332 vty_out(vty, "\n");
13333 }
13334
13335 if (CHECK_FLAG(
13336 p->af_cap[afi]
13337 [safi],
13338 PEER_CAP_ADDPATH_AF_RX_ADV)
13339 || CHECK_FLAG(
13340 p->af_cap[afi]
13341 [safi],
13342 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13343 vty_out(vty,
13344 " %s: RX ",
13345 get_afi_safi_str(
13346 afi,
13347 safi,
13348 false));
13349
13350 if (CHECK_FLAG(
13351 p->af_cap
13352 [afi]
13353 [safi],
13354 PEER_CAP_ADDPATH_AF_RX_ADV))
13355 vty_out(vty,
13356 "advertised %s",
13357 get_afi_safi_str(
13358 afi,
13359 safi,
13360 false));
13361
13362 if (CHECK_FLAG(
13363 p->af_cap
13364 [afi]
13365 [safi],
13366 PEER_CAP_ADDPATH_AF_RX_RCV))
13367 vty_out(vty,
13368 "%sreceived",
13369 CHECK_FLAG(
13370 p->af_cap
13371 [afi]
13372 [safi],
13373 PEER_CAP_ADDPATH_AF_RX_ADV)
13374 ? " and "
13375 : "");
13376
13377 vty_out(vty, "\n");
13378 }
13379 }
13380 }
13381
13382 /* Dynamic */
13383 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
13384 || CHECK_FLAG(p->cap,
13385 PEER_CAP_DYNAMIC_ADV)) {
13386 vty_out(vty, " Dynamic:");
13387 if (CHECK_FLAG(p->cap,
13388 PEER_CAP_DYNAMIC_ADV))
13389 vty_out(vty, " advertised");
13390 if (CHECK_FLAG(p->cap,
13391 PEER_CAP_DYNAMIC_RCV))
13392 vty_out(vty, " %sreceived",
13393 CHECK_FLAG(
13394 p->cap,
13395 PEER_CAP_DYNAMIC_ADV)
13396 ? "and "
13397 : "");
13398 vty_out(vty, "\n");
13399 }
13400
13401 /* Extended nexthop */
13402 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
13403 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13404 vty_out(vty, " Extended nexthop:");
13405 if (CHECK_FLAG(p->cap,
13406 PEER_CAP_ENHE_ADV))
13407 vty_out(vty, " advertised");
13408 if (CHECK_FLAG(p->cap,
13409 PEER_CAP_ENHE_RCV))
13410 vty_out(vty, " %sreceived",
13411 CHECK_FLAG(
13412 p->cap,
13413 PEER_CAP_ENHE_ADV)
13414 ? "and "
13415 : "");
13416 vty_out(vty, "\n");
13417
13418 if (CHECK_FLAG(p->cap,
13419 PEER_CAP_ENHE_RCV)) {
13420 vty_out(vty,
13421 " Address families by peer:\n ");
13422 for (safi = SAFI_UNICAST;
13423 safi < SAFI_MAX; safi++)
13424 if (CHECK_FLAG(
13425 p->af_cap
13426 [AFI_IP]
13427 [safi],
13428 PEER_CAP_ENHE_AF_RCV))
13429 vty_out(vty,
13430 " %s\n",
13431 get_afi_safi_str(
13432 AFI_IP,
13433 safi,
13434 false));
13435 }
13436 }
13437
13438 /* Route Refresh */
13439 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
13440 || CHECK_FLAG(p->cap,
13441 PEER_CAP_REFRESH_NEW_RCV)
13442 || CHECK_FLAG(p->cap,
13443 PEER_CAP_REFRESH_OLD_RCV)) {
13444 vty_out(vty, " Route refresh:");
13445 if (CHECK_FLAG(p->cap,
13446 PEER_CAP_REFRESH_ADV))
13447 vty_out(vty, " advertised");
13448 if (CHECK_FLAG(p->cap,
13449 PEER_CAP_REFRESH_NEW_RCV)
13450 || CHECK_FLAG(
13451 p->cap,
13452 PEER_CAP_REFRESH_OLD_RCV))
13453 vty_out(vty, " %sreceived(%s)",
13454 CHECK_FLAG(
13455 p->cap,
13456 PEER_CAP_REFRESH_ADV)
13457 ? "and "
13458 : "",
13459 (CHECK_FLAG(
13460 p->cap,
13461 PEER_CAP_REFRESH_OLD_RCV)
13462 && CHECK_FLAG(
13463 p->cap,
13464 PEER_CAP_REFRESH_NEW_RCV))
13465 ? "old & new"
13466 : CHECK_FLAG(
13467 p->cap,
13468 PEER_CAP_REFRESH_OLD_RCV)
13469 ? "old"
13470 : "new");
13471
13472 vty_out(vty, "\n");
13473 }
13474
13475 /* Multiprotocol Extensions */
13476 FOREACH_AFI_SAFI (afi, safi)
13477 if (p->afc_adv[afi][safi]
13478 || p->afc_recv[afi][safi]) {
13479 vty_out(vty,
13480 " Address Family %s:",
13481 get_afi_safi_str(
13482 afi,
13483 safi,
13484 false));
13485 if (p->afc_adv[afi][safi])
13486 vty_out(vty,
13487 " advertised");
13488 if (p->afc_recv[afi][safi])
13489 vty_out(vty,
13490 " %sreceived",
13491 p->afc_adv[afi]
13492 [safi]
13493 ? "and "
13494 : "");
13495 vty_out(vty, "\n");
13496 }
13497
13498 /* Hostname capability */
13499 vty_out(vty, " Hostname Capability:");
13500
13501 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13502 vty_out(vty,
13503 " advertised (name: %s,domain name: %s)",
13504 bgp->peer_self->hostname
13505 ? bgp->peer_self
13506 ->hostname
13507 : "n/a",
13508 bgp->peer_self->domainname
13509 ? bgp->peer_self
13510 ->domainname
13511 : "n/a");
13512 } else {
13513 vty_out(vty, " not advertised");
13514 }
13515
13516 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13517 vty_out(vty,
13518 " received (name: %s,domain name: %s)",
13519 p->hostname ? p->hostname
13520 : "n/a",
13521 p->domainname ? p->domainname
13522 : "n/a");
13523 } else {
13524 vty_out(vty, " not received");
13525 }
13526
13527 vty_out(vty, "\n");
13528
13529 /* Graceful Restart */
13530 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
13531 || CHECK_FLAG(p->cap,
13532 PEER_CAP_RESTART_ADV)) {
13533 vty_out(vty,
13534 " Graceful Restart Capability:");
13535 if (CHECK_FLAG(p->cap,
13536 PEER_CAP_RESTART_ADV))
13537 vty_out(vty, " advertised");
13538 if (CHECK_FLAG(p->cap,
13539 PEER_CAP_RESTART_RCV))
13540 vty_out(vty, " %sreceived",
13541 CHECK_FLAG(
13542 p->cap,
13543 PEER_CAP_RESTART_ADV)
13544 ? "and "
13545 : "");
13546 vty_out(vty, "\n");
13547
13548 if (CHECK_FLAG(p->cap,
13549 PEER_CAP_RESTART_RCV)) {
13550 int restart_af_count = 0;
13551
13552 vty_out(vty,
13553 " Remote Restart timer is %d seconds\n",
13554 p->v_gr_restart);
13555 vty_out(vty,
13556 " Address families by peer:\n ");
13557
13558 FOREACH_AFI_SAFI (afi, safi)
13559 if (CHECK_FLAG(
13560 p->af_cap
13561 [afi]
13562 [safi],
13563 PEER_CAP_RESTART_AF_RCV)) {
13564 vty_out(vty,
13565 "%s%s(%s)",
13566 restart_af_count
13567 ? ", "
13568 : "",
13569 get_afi_safi_str(
13570 afi,
13571 safi,
13572 false),
13573 CHECK_FLAG(
13574 p->af_cap
13575 [afi]
13576 [safi],
13577 PEER_CAP_RESTART_AF_PRESERVE_RCV)
13578 ? "preserved"
13579 : "not preserved");
13580 restart_af_count++;
13581 }
13582 if (!restart_af_count)
13583 vty_out(vty, "none");
13584 vty_out(vty, "\n");
13585 }
13586 } /* Gracefull Restart */
13587 }
13588 }
13589 }
13590
13591 /* graceful restart information */
13592 json_object *json_grace = NULL;
13593 json_object *json_grace_send = NULL;
13594 json_object *json_grace_recv = NULL;
13595 int eor_send_af_count = 0;
13596 int eor_receive_af_count = 0;
13597
13598 if (use_json) {
13599 json_grace = json_object_new_object();
13600 json_grace_send = json_object_new_object();
13601 json_grace_recv = json_object_new_object();
13602
13603 if ((p->status == Established)
13604 && CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13605 FOREACH_AFI_SAFI (afi, safi) {
13606 if (CHECK_FLAG(p->af_sflags[afi][safi],
13607 PEER_STATUS_EOR_SEND)) {
13608 json_object_boolean_true_add(
13609 json_grace_send,
13610 get_afi_safi_str(afi,
13611 safi,
13612 true));
13613 eor_send_af_count++;
13614 }
13615 }
13616 FOREACH_AFI_SAFI (afi, safi) {
13617 if (CHECK_FLAG(
13618 p->af_sflags[afi][safi],
13619 PEER_STATUS_EOR_RECEIVED)) {
13620 json_object_boolean_true_add(
13621 json_grace_recv,
13622 get_afi_safi_str(afi,
13623 safi,
13624 true));
13625 eor_receive_af_count++;
13626 }
13627 }
13628 }
13629 json_object_object_add(json_grace, "endOfRibSend",
13630 json_grace_send);
13631 json_object_object_add(json_grace, "endOfRibRecv",
13632 json_grace_recv);
13633
13634
13635 if (p->t_gr_restart)
13636 json_object_int_add(json_grace,
13637 "gracefulRestartTimerMsecs",
13638 thread_timer_remain_second(
13639 p->t_gr_restart)
13640 * 1000);
13641
13642 if (p->t_gr_stale)
13643 json_object_int_add(
13644 json_grace,
13645 "gracefulStalepathTimerMsecs",
13646 thread_timer_remain_second(
13647 p->t_gr_stale)
13648 * 1000);
13649 /* more gr info in new format */
13650 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json,
13651 json_grace);
13652 json_object_object_add(
13653 json_neigh, "gracefulRestartInfo", json_grace);
13654 } else {
13655 vty_out(vty, " Graceful restart information:\n");
13656 if ((p->status == Established)
13657 && CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13658
13659 vty_out(vty, " End-of-RIB send: ");
13660 FOREACH_AFI_SAFI (afi, safi) {
13661 if (CHECK_FLAG(p->af_sflags[afi][safi],
13662 PEER_STATUS_EOR_SEND)) {
13663 vty_out(vty, "%s%s",
13664 eor_send_af_count ? ", "
13665 : "",
13666 get_afi_safi_str(
13667 afi, safi,
13668 false));
13669 eor_send_af_count++;
13670 }
13671 }
13672 vty_out(vty, "\n");
13673 vty_out(vty, " End-of-RIB received: ");
13674 FOREACH_AFI_SAFI (afi, safi) {
13675 if (CHECK_FLAG(
13676 p->af_sflags[afi][safi],
13677 PEER_STATUS_EOR_RECEIVED)) {
13678 vty_out(vty, "%s%s",
13679 eor_receive_af_count
13680 ? ", "
13681 : "",
13682 get_afi_safi_str(afi,
13683 safi,
13684 false));
13685 eor_receive_af_count++;
13686 }
13687 }
13688 vty_out(vty, "\n");
13689 }
13690
13691 if (p->t_gr_restart)
13692 vty_out(vty,
13693 " The remaining time of restart timer is %ld\n",
13694 thread_timer_remain_second(
13695 p->t_gr_restart));
13696
13697 if (p->t_gr_stale)
13698 vty_out(vty,
13699 " The remaining time of stalepath timer is %ld\n",
13700 thread_timer_remain_second(
13701 p->t_gr_stale));
13702
13703 /* more gr info in new format */
13704 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, NULL);
13705 }
13706
13707 if (use_json) {
13708 json_object *json_stat = NULL;
13709 json_stat = json_object_new_object();
13710 /* Packet counts. */
13711
13712 atomic_size_t outq_count, inq_count;
13713 outq_count = atomic_load_explicit(&p->obuf->count,
13714 memory_order_relaxed);
13715 inq_count = atomic_load_explicit(&p->ibuf->count,
13716 memory_order_relaxed);
13717
13718 json_object_int_add(json_stat, "depthInq",
13719 (unsigned long)inq_count);
13720 json_object_int_add(json_stat, "depthOutq",
13721 (unsigned long)outq_count);
13722 json_object_int_add(json_stat, "opensSent",
13723 atomic_load_explicit(&p->open_out,
13724 memory_order_relaxed));
13725 json_object_int_add(json_stat, "opensRecv",
13726 atomic_load_explicit(&p->open_in,
13727 memory_order_relaxed));
13728 json_object_int_add(json_stat, "notificationsSent",
13729 atomic_load_explicit(&p->notify_out,
13730 memory_order_relaxed));
13731 json_object_int_add(json_stat, "notificationsRecv",
13732 atomic_load_explicit(&p->notify_in,
13733 memory_order_relaxed));
13734 json_object_int_add(json_stat, "updatesSent",
13735 atomic_load_explicit(&p->update_out,
13736 memory_order_relaxed));
13737 json_object_int_add(json_stat, "updatesRecv",
13738 atomic_load_explicit(&p->update_in,
13739 memory_order_relaxed));
13740 json_object_int_add(json_stat, "keepalivesSent",
13741 atomic_load_explicit(&p->keepalive_out,
13742 memory_order_relaxed));
13743 json_object_int_add(json_stat, "keepalivesRecv",
13744 atomic_load_explicit(&p->keepalive_in,
13745 memory_order_relaxed));
13746 json_object_int_add(json_stat, "routeRefreshSent",
13747 atomic_load_explicit(&p->refresh_out,
13748 memory_order_relaxed));
13749 json_object_int_add(json_stat, "routeRefreshRecv",
13750 atomic_load_explicit(&p->refresh_in,
13751 memory_order_relaxed));
13752 json_object_int_add(json_stat, "capabilitySent",
13753 atomic_load_explicit(&p->dynamic_cap_out,
13754 memory_order_relaxed));
13755 json_object_int_add(json_stat, "capabilityRecv",
13756 atomic_load_explicit(&p->dynamic_cap_in,
13757 memory_order_relaxed));
13758 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
13759 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
13760 json_object_object_add(json_neigh, "messageStats", json_stat);
13761 } else {
13762 atomic_size_t outq_count, inq_count;
13763 outq_count = atomic_load_explicit(&p->obuf->count,
13764 memory_order_relaxed);
13765 inq_count = atomic_load_explicit(&p->ibuf->count,
13766 memory_order_relaxed);
13767
13768 /* Packet counts. */
13769 vty_out(vty, " Message statistics:\n");
13770 vty_out(vty, " Inq depth is %zu\n", inq_count);
13771 vty_out(vty, " Outq depth is %zu\n", outq_count);
13772 vty_out(vty, " Sent Rcvd\n");
13773 vty_out(vty, " Opens: %10d %10d\n",
13774 atomic_load_explicit(&p->open_out,
13775 memory_order_relaxed),
13776 atomic_load_explicit(&p->open_in,
13777 memory_order_relaxed));
13778 vty_out(vty, " Notifications: %10d %10d\n",
13779 atomic_load_explicit(&p->notify_out,
13780 memory_order_relaxed),
13781 atomic_load_explicit(&p->notify_in,
13782 memory_order_relaxed));
13783 vty_out(vty, " Updates: %10d %10d\n",
13784 atomic_load_explicit(&p->update_out,
13785 memory_order_relaxed),
13786 atomic_load_explicit(&p->update_in,
13787 memory_order_relaxed));
13788 vty_out(vty, " Keepalives: %10d %10d\n",
13789 atomic_load_explicit(&p->keepalive_out,
13790 memory_order_relaxed),
13791 atomic_load_explicit(&p->keepalive_in,
13792 memory_order_relaxed));
13793 vty_out(vty, " Route Refresh: %10d %10d\n",
13794 atomic_load_explicit(&p->refresh_out,
13795 memory_order_relaxed),
13796 atomic_load_explicit(&p->refresh_in,
13797 memory_order_relaxed));
13798 vty_out(vty, " Capability: %10d %10d\n",
13799 atomic_load_explicit(&p->dynamic_cap_out,
13800 memory_order_relaxed),
13801 atomic_load_explicit(&p->dynamic_cap_in,
13802 memory_order_relaxed));
13803 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
13804 PEER_TOTAL_RX(p));
13805 }
13806
13807 if (use_json) {
13808 /* advertisement-interval */
13809 json_object_int_add(json_neigh,
13810 "minBtwnAdvertisementRunsTimerMsecs",
13811 p->v_routeadv * 1000);
13812
13813 /* Update-source. */
13814 if (p->update_if || p->update_source) {
13815 if (p->update_if)
13816 json_object_string_add(json_neigh,
13817 "updateSource",
13818 p->update_if);
13819 else if (p->update_source)
13820 json_object_string_add(
13821 json_neigh, "updateSource",
13822 sockunion2str(p->update_source, buf1,
13823 SU_ADDRSTRLEN));
13824 }
13825 } else {
13826 /* advertisement-interval */
13827 vty_out(vty,
13828 " Minimum time between advertisement runs is %d seconds\n",
13829 p->v_routeadv);
13830
13831 /* Update-source. */
13832 if (p->update_if || p->update_source) {
13833 vty_out(vty, " Update source is ");
13834 if (p->update_if)
13835 vty_out(vty, "%s", p->update_if);
13836 else if (p->update_source)
13837 vty_out(vty, "%s",
13838 sockunion2str(p->update_source, buf1,
13839 SU_ADDRSTRLEN));
13840 vty_out(vty, "\n");
13841 }
13842
13843 vty_out(vty, "\n");
13844 }
13845
13846 /* Address Family Information */
13847 json_object *json_hold = NULL;
13848
13849 if (use_json)
13850 json_hold = json_object_new_object();
13851
13852 FOREACH_AFI_SAFI (afi, safi)
13853 if (p->afc[afi][safi])
13854 bgp_show_peer_afi(vty, p, afi, safi, use_json,
13855 json_hold);
13856
13857 if (use_json) {
13858 json_object_object_add(json_neigh, "addressFamilyInfo",
13859 json_hold);
13860 json_object_int_add(json_neigh, "connectionsEstablished",
13861 p->established);
13862 json_object_int_add(json_neigh, "connectionsDropped",
13863 p->dropped);
13864 } else
13865 vty_out(vty, " Connections established %d; dropped %d\n",
13866 p->established, p->dropped);
13867
13868 if (!p->last_reset) {
13869 if (use_json)
13870 json_object_string_add(json_neigh, "lastReset",
13871 "never");
13872 else
13873 vty_out(vty, " Last reset never\n");
13874 } else {
13875 if (use_json) {
13876 time_t uptime;
13877 struct tm tm;
13878
13879 uptime = bgp_clock();
13880 uptime -= p->resettime;
13881 gmtime_r(&uptime, &tm);
13882
13883 json_object_int_add(json_neigh, "lastResetTimerMsecs",
13884 (tm.tm_sec * 1000)
13885 + (tm.tm_min * 60000)
13886 + (tm.tm_hour * 3600000));
13887 bgp_show_peer_reset(NULL, p, json_neigh, true);
13888 } else {
13889 vty_out(vty, " Last reset %s, ",
13890 peer_uptime(p->resettime, timebuf,
13891 BGP_UPTIME_LEN, 0, NULL));
13892
13893 bgp_show_peer_reset(vty, p, NULL, false);
13894 if (p->last_reset_cause_size) {
13895 msg = p->last_reset_cause;
13896 vty_out(vty,
13897 " Message received that caused BGP to send a NOTIFICATION:\n ");
13898 for (i = 1; i <= p->last_reset_cause_size;
13899 i++) {
13900 vty_out(vty, "%02X", *msg++);
13901
13902 if (i != p->last_reset_cause_size) {
13903 if (i % 16 == 0) {
13904 vty_out(vty, "\n ");
13905 } else if (i % 4 == 0) {
13906 vty_out(vty, " ");
13907 }
13908 }
13909 }
13910 vty_out(vty, "\n");
13911 }
13912 }
13913 }
13914
13915 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
13916 if (use_json)
13917 json_object_boolean_true_add(json_neigh,
13918 "prefixesConfigExceedMax");
13919 else
13920 vty_out(vty,
13921 " Peer had exceeded the max. no. of prefixes configured.\n");
13922
13923 if (p->t_pmax_restart) {
13924 if (use_json) {
13925 json_object_boolean_true_add(
13926 json_neigh, "reducePrefixNumFrom");
13927 json_object_int_add(json_neigh,
13928 "restartInTimerMsec",
13929 thread_timer_remain_second(
13930 p->t_pmax_restart)
13931 * 1000);
13932 } else
13933 vty_out(vty,
13934 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
13935 p->host, thread_timer_remain_second(
13936 p->t_pmax_restart));
13937 } else {
13938 if (use_json)
13939 json_object_boolean_true_add(
13940 json_neigh,
13941 "reducePrefixNumAndClearIpBgp");
13942 else
13943 vty_out(vty,
13944 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
13945 p->host);
13946 }
13947 }
13948
13949 /* EBGP Multihop and GTSM */
13950 if (p->sort != BGP_PEER_IBGP) {
13951 if (use_json) {
13952 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
13953 json_object_int_add(json_neigh,
13954 "externalBgpNbrMaxHopsAway",
13955 p->gtsm_hops);
13956 else if (p->ttl > BGP_DEFAULT_TTL)
13957 json_object_int_add(json_neigh,
13958 "externalBgpNbrMaxHopsAway",
13959 p->ttl);
13960 } else {
13961 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
13962 vty_out(vty,
13963 " External BGP neighbor may be up to %d hops away.\n",
13964 p->gtsm_hops);
13965 else if (p->ttl > BGP_DEFAULT_TTL)
13966 vty_out(vty,
13967 " External BGP neighbor may be up to %d hops away.\n",
13968 p->ttl);
13969 }
13970 } else {
13971 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED) {
13972 if (use_json)
13973 json_object_int_add(json_neigh,
13974 "internalBgpNbrMaxHopsAway",
13975 p->gtsm_hops);
13976 else
13977 vty_out(vty,
13978 " Internal BGP neighbor may be up to %d hops away.\n",
13979 p->gtsm_hops);
13980 }
13981 }
13982
13983 /* Local address. */
13984 if (p->su_local) {
13985 if (use_json) {
13986 json_object_string_add(json_neigh, "hostLocal",
13987 sockunion2str(p->su_local, buf1,
13988 SU_ADDRSTRLEN));
13989 json_object_int_add(json_neigh, "portLocal",
13990 ntohs(p->su_local->sin.sin_port));
13991 } else
13992 vty_out(vty, "Local host: %s, Local port: %d\n",
13993 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
13994 ntohs(p->su_local->sin.sin_port));
13995 }
13996
13997 /* Remote address. */
13998 if (p->su_remote) {
13999 if (use_json) {
14000 json_object_string_add(json_neigh, "hostForeign",
14001 sockunion2str(p->su_remote, buf1,
14002 SU_ADDRSTRLEN));
14003 json_object_int_add(json_neigh, "portForeign",
14004 ntohs(p->su_remote->sin.sin_port));
14005 } else
14006 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
14007 sockunion2str(p->su_remote, buf1,
14008 SU_ADDRSTRLEN),
14009 ntohs(p->su_remote->sin.sin_port));
14010 }
14011
14012 /* Nexthop display. */
14013 if (p->su_local) {
14014 if (use_json) {
14015 json_object_string_add(json_neigh, "nexthop",
14016 inet_ntop(AF_INET,
14017 &p->nexthop.v4, buf1,
14018 sizeof(buf1)));
14019 json_object_string_add(json_neigh, "nexthopGlobal",
14020 inet_ntop(AF_INET6,
14021 &p->nexthop.v6_global,
14022 buf1, sizeof(buf1)));
14023 json_object_string_add(json_neigh, "nexthopLocal",
14024 inet_ntop(AF_INET6,
14025 &p->nexthop.v6_local,
14026 buf1, sizeof(buf1)));
14027 if (p->shared_network)
14028 json_object_string_add(json_neigh,
14029 "bgpConnection",
14030 "sharedNetwork");
14031 else
14032 json_object_string_add(json_neigh,
14033 "bgpConnection",
14034 "nonSharedNetwork");
14035 } else {
14036 vty_out(vty, "Nexthop: %s\n",
14037 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
14038 sizeof(buf1)));
14039 vty_out(vty, "Nexthop global: %s\n",
14040 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
14041 sizeof(buf1)));
14042 vty_out(vty, "Nexthop local: %s\n",
14043 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
14044 sizeof(buf1)));
14045 vty_out(vty, "BGP connection: %s\n",
14046 p->shared_network ? "shared network"
14047 : "non shared network");
14048 }
14049 }
14050
14051 /* Timer information. */
14052 if (use_json) {
14053 json_object_int_add(json_neigh, "connectRetryTimer",
14054 p->v_connect);
14055 if (p->status == Established && p->rtt)
14056 json_object_int_add(json_neigh, "estimatedRttInMsecs",
14057 p->rtt);
14058 if (p->t_start)
14059 json_object_int_add(
14060 json_neigh, "nextStartTimerDueInMsecs",
14061 thread_timer_remain_second(p->t_start) * 1000);
14062 if (p->t_connect)
14063 json_object_int_add(
14064 json_neigh, "nextConnectTimerDueInMsecs",
14065 thread_timer_remain_second(p->t_connect)
14066 * 1000);
14067 if (p->t_routeadv) {
14068 json_object_int_add(json_neigh, "mraiInterval",
14069 p->v_routeadv);
14070 json_object_int_add(
14071 json_neigh, "mraiTimerExpireInMsecs",
14072 thread_timer_remain_second(p->t_routeadv)
14073 * 1000);
14074 }
14075 if (p->password)
14076 json_object_int_add(json_neigh, "authenticationEnabled",
14077 1);
14078
14079 if (p->t_read)
14080 json_object_string_add(json_neigh, "readThread", "on");
14081 else
14082 json_object_string_add(json_neigh, "readThread", "off");
14083
14084 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
14085 json_object_string_add(json_neigh, "writeThread", "on");
14086 else
14087 json_object_string_add(json_neigh, "writeThread",
14088 "off");
14089 } else {
14090 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
14091 p->v_connect);
14092 if (p->status == Established && p->rtt)
14093 vty_out(vty, "Estimated round trip time: %d ms\n",
14094 p->rtt);
14095 if (p->t_start)
14096 vty_out(vty, "Next start timer due in %ld seconds\n",
14097 thread_timer_remain_second(p->t_start));
14098 if (p->t_connect)
14099 vty_out(vty, "Next connect timer due in %ld seconds\n",
14100 thread_timer_remain_second(p->t_connect));
14101 if (p->t_routeadv)
14102 vty_out(vty,
14103 "MRAI (interval %u) timer expires in %ld seconds\n",
14104 p->v_routeadv,
14105 thread_timer_remain_second(p->t_routeadv));
14106 if (p->password)
14107 vty_out(vty, "Peer Authentication Enabled\n");
14108
14109 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
14110 p->t_read ? "on" : "off",
14111 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
14112 ? "on"
14113 : "off", p->fd);
14114 }
14115
14116 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
14117 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
14118 bgp_capability_vty_out(vty, p, use_json, json_neigh);
14119
14120 if (!use_json)
14121 vty_out(vty, "\n");
14122
14123 /* BFD information. */
14124 bgp_bfd_show_info(vty, p, use_json, json_neigh);
14125
14126 if (use_json) {
14127 if (p->conf_if) /* Configured interface name. */
14128 json_object_object_add(json, p->conf_if, json_neigh);
14129 else /* Configured IP address. */
14130 json_object_object_add(json, p->host, json_neigh);
14131 }
14132 }
14133
14134 static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
14135 enum show_type type,
14136 union sockunion *su,
14137 const char *conf_if, afi_t afi,
14138 bool use_json)
14139 {
14140 struct listnode *node, *nnode;
14141 struct peer *peer;
14142 int find = 0;
14143 safi_t safi = SAFI_UNICAST;
14144 json_object *json = NULL;
14145 json_object *json_neighbor = NULL;
14146
14147 if (use_json) {
14148 json = json_object_new_object();
14149 json_neighbor = json_object_new_object();
14150 }
14151
14152 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14153
14154 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14155 continue;
14156
14157 if ((peer->afc[afi][safi]) == 0)
14158 continue;
14159
14160 if (type == show_all) {
14161 bgp_show_peer_gr_status(vty, peer, use_json,
14162 json_neighbor);
14163
14164 if (use_json) {
14165 json_object_object_add(json, peer->host,
14166 json_neighbor);
14167 json_neighbor = NULL;
14168 }
14169
14170 } else if (type == show_peer) {
14171 if (conf_if) {
14172 if ((peer->conf_if
14173 && !strcmp(peer->conf_if, conf_if))
14174 || (peer->hostname
14175 && !strcmp(peer->hostname, conf_if))) {
14176 find = 1;
14177 bgp_show_peer_gr_status(vty, peer,
14178 use_json,
14179 json_neighbor);
14180 }
14181 } else {
14182 if (sockunion_same(&peer->su, su)) {
14183 find = 1;
14184 bgp_show_peer_gr_status(vty, peer,
14185 use_json,
14186 json_neighbor);
14187 }
14188 }
14189 if (use_json && find)
14190 json_object_object_add(json, peer->host,
14191 json_neighbor);
14192 }
14193
14194 if (find) {
14195 json_neighbor = NULL;
14196 break;
14197 }
14198 }
14199
14200 if (type == show_peer && !find) {
14201 if (use_json)
14202 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14203 else
14204 vty_out(vty, "%% No such neighbor\n");
14205 }
14206 if (use_json) {
14207 vty_out(vty, "%s\n",
14208 json_object_to_json_string_ext(
14209 json, JSON_C_TO_STRING_PRETTY));
14210
14211 if (json_neighbor)
14212 json_object_free(json_neighbor);
14213 json_object_free(json);
14214 } else {
14215 vty_out(vty, "\n");
14216 }
14217
14218 return CMD_SUCCESS;
14219 }
14220
14221 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
14222 enum show_type type, union sockunion *su,
14223 const char *conf_if, bool use_json,
14224 json_object *json)
14225 {
14226 struct listnode *node, *nnode;
14227 struct peer *peer;
14228 int find = 0;
14229 bool nbr_output = false;
14230 afi_t afi = AFI_MAX;
14231 safi_t safi = SAFI_MAX;
14232
14233 if (type == show_ipv4_peer || type == show_ipv4_all) {
14234 afi = AFI_IP;
14235 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
14236 afi = AFI_IP6;
14237 }
14238
14239 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14240 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14241 continue;
14242
14243 switch (type) {
14244 case show_all:
14245 bgp_show_peer(vty, peer, use_json, json);
14246 nbr_output = true;
14247 break;
14248 case show_peer:
14249 if (conf_if) {
14250 if ((peer->conf_if
14251 && !strcmp(peer->conf_if, conf_if))
14252 || (peer->hostname
14253 && !strcmp(peer->hostname, conf_if))) {
14254 find = 1;
14255 bgp_show_peer(vty, peer, use_json,
14256 json);
14257 }
14258 } else {
14259 if (sockunion_same(&peer->su, su)) {
14260 find = 1;
14261 bgp_show_peer(vty, peer, use_json,
14262 json);
14263 }
14264 }
14265 break;
14266 case show_ipv4_peer:
14267 case show_ipv6_peer:
14268 FOREACH_SAFI (safi) {
14269 if (peer->afc[afi][safi]) {
14270 if (conf_if) {
14271 if ((peer->conf_if
14272 && !strcmp(peer->conf_if, conf_if))
14273 || (peer->hostname
14274 && !strcmp(peer->hostname, conf_if))) {
14275 find = 1;
14276 bgp_show_peer(vty, peer, use_json,
14277 json);
14278 break;
14279 }
14280 } else {
14281 if (sockunion_same(&peer->su, su)) {
14282 find = 1;
14283 bgp_show_peer(vty, peer, use_json,
14284 json);
14285 break;
14286 }
14287 }
14288 }
14289 }
14290 break;
14291 case show_ipv4_all:
14292 case show_ipv6_all:
14293 FOREACH_SAFI (safi) {
14294 if (peer->afc[afi][safi]) {
14295 bgp_show_peer(vty, peer, use_json, json);
14296 nbr_output = true;
14297 break;
14298 }
14299 }
14300 break;
14301 }
14302 }
14303
14304 if ((type == show_peer || type == show_ipv4_peer ||
14305 type == show_ipv6_peer) && !find) {
14306 if (use_json)
14307 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14308 else
14309 vty_out(vty, "%% No such neighbor in this view/vrf\n");
14310 }
14311
14312 if (type != show_peer && type != show_ipv4_peer &&
14313 type != show_ipv6_peer && !nbr_output && !use_json)
14314 vty_out(vty, "%% No BGP neighbors found\n");
14315
14316 if (use_json) {
14317 vty_out(vty, "%s\n", json_object_to_json_string_ext(
14318 json, JSON_C_TO_STRING_PRETTY));
14319 } else {
14320 vty_out(vty, "\n");
14321 }
14322
14323 return CMD_SUCCESS;
14324 }
14325
14326 static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
14327 enum show_type type,
14328 const char *ip_str,
14329 afi_t afi, bool use_json)
14330 {
14331
14332 int ret;
14333 struct bgp *bgp;
14334 union sockunion su;
14335
14336 bgp = bgp_get_default();
14337
14338 if (!bgp)
14339 return;
14340
14341 if (!use_json)
14342 bgp_show_global_graceful_restart_mode_vty(vty, bgp, use_json,
14343 NULL);
14344
14345 if (ip_str) {
14346 ret = str2sockunion(ip_str, &su);
14347 if (ret < 0)
14348 bgp_show_neighbor_graceful_restart(
14349 vty, bgp, type, NULL, ip_str, afi, use_json);
14350 else
14351 bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
14352 NULL, afi, use_json);
14353 } else
14354 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
14355 afi, use_json);
14356 }
14357
14358 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
14359 enum show_type type,
14360 const char *ip_str,
14361 bool use_json)
14362 {
14363 struct listnode *node, *nnode;
14364 struct bgp *bgp;
14365 union sockunion su;
14366 json_object *json = NULL;
14367 int ret, is_first = 1;
14368 bool nbr_output = false;
14369
14370 if (use_json)
14371 vty_out(vty, "{\n");
14372
14373 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
14374 nbr_output = true;
14375 if (use_json) {
14376 if (!(json = json_object_new_object())) {
14377 flog_err(
14378 EC_BGP_JSON_MEM_ERROR,
14379 "Unable to allocate memory for JSON object");
14380 vty_out(vty,
14381 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
14382 return;
14383 }
14384
14385 json_object_int_add(json, "vrfId",
14386 (bgp->vrf_id == VRF_UNKNOWN)
14387 ? -1
14388 : (int64_t)bgp->vrf_id);
14389 json_object_string_add(
14390 json, "vrfName",
14391 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14392 ? VRF_DEFAULT_NAME
14393 : bgp->name);
14394
14395 if (!is_first)
14396 vty_out(vty, ",\n");
14397 else
14398 is_first = 0;
14399
14400 vty_out(vty, "\"%s\":",
14401 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14402 ? VRF_DEFAULT_NAME
14403 : bgp->name);
14404 } else {
14405 vty_out(vty, "\nInstance %s:\n",
14406 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14407 ? VRF_DEFAULT_NAME
14408 : bgp->name);
14409 }
14410
14411 if (type == show_peer || type == show_ipv4_peer ||
14412 type == show_ipv6_peer) {
14413 ret = str2sockunion(ip_str, &su);
14414 if (ret < 0)
14415 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14416 use_json, json);
14417 else
14418 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14419 use_json, json);
14420 } else {
14421 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
14422 use_json, json);
14423 }
14424 json_object_free(json);
14425 json = NULL;
14426 }
14427
14428 if (use_json)
14429 vty_out(vty, "}\n");
14430 else if (!nbr_output)
14431 vty_out(vty, "%% BGP instance not found\n");
14432 }
14433
14434 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
14435 enum show_type type, const char *ip_str,
14436 bool use_json)
14437 {
14438 int ret;
14439 struct bgp *bgp;
14440 union sockunion su;
14441 json_object *json = NULL;
14442
14443 if (name) {
14444 if (strmatch(name, "all")) {
14445 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
14446 use_json);
14447 return CMD_SUCCESS;
14448 } else {
14449 bgp = bgp_lookup_by_name(name);
14450 if (!bgp) {
14451 if (use_json) {
14452 json = json_object_new_object();
14453 vty_out(vty, "%s\n",
14454 json_object_to_json_string_ext(
14455 json,
14456 JSON_C_TO_STRING_PRETTY));
14457 json_object_free(json);
14458 } else
14459 vty_out(vty,
14460 "%% BGP instance not found\n");
14461
14462 return CMD_WARNING;
14463 }
14464 }
14465 } else {
14466 bgp = bgp_get_default();
14467 }
14468
14469 if (bgp) {
14470 json = json_object_new_object();
14471 if (ip_str) {
14472 ret = str2sockunion(ip_str, &su);
14473 if (ret < 0)
14474 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14475 use_json, json);
14476 else
14477 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14478 use_json, json);
14479 } else {
14480 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
14481 json);
14482 }
14483 json_object_free(json);
14484 } else {
14485 if (use_json)
14486 vty_out(vty, "{}\n");
14487 else
14488 vty_out(vty, "%% BGP instance not found\n");
14489 }
14490
14491 return CMD_SUCCESS;
14492 }
14493
14494
14495
14496 /* "show [ip] bgp neighbors graceful-restart" commands. */
14497 DEFUN (show_ip_bgp_neighbors_gracrful_restart,
14498 show_ip_bgp_neighbors_graceful_restart_cmd,
14499 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
14500 SHOW_STR
14501 BGP_STR
14502 IP_STR
14503 IPV6_STR
14504 NEIGHBOR_STR
14505 "Neighbor to display information about\n"
14506 "Neighbor to display information about\n"
14507 "Neighbor on BGP configured interface\n"
14508 GR_SHOW
14509 JSON_STR)
14510 {
14511 char *sh_arg = NULL;
14512 enum show_type sh_type;
14513 int idx = 0;
14514 afi_t afi = AFI_MAX;
14515 bool uj = use_json(argc, argv);
14516
14517 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
14518 afi = AFI_MAX;
14519
14520 idx++;
14521
14522 if (argv_find(argv, argc, "A.B.C.D", &idx)
14523 || argv_find(argv, argc, "X:X::X:X", &idx)
14524 || argv_find(argv, argc, "WORD", &idx)) {
14525 sh_type = show_peer;
14526 sh_arg = argv[idx]->arg;
14527 } else
14528 sh_type = show_all;
14529
14530 if (!argv_find(argv, argc, "graceful-restart", &idx))
14531 return CMD_SUCCESS;
14532
14533
14534 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
14535 afi, uj);
14536 }
14537
14538 /* "show [ip] bgp neighbors" commands. */
14539 DEFUN (show_ip_bgp_neighbors,
14540 show_ip_bgp_neighbors_cmd,
14541 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
14542 SHOW_STR
14543 IP_STR
14544 BGP_STR
14545 BGP_INSTANCE_HELP_STR
14546 "Address Family\n"
14547 "Address Family\n"
14548 "Detailed information on TCP and BGP neighbor connections\n"
14549 "Neighbor to display information about\n"
14550 "Neighbor to display information about\n"
14551 "Neighbor on BGP configured interface\n"
14552 JSON_STR)
14553 {
14554 char *vrf = NULL;
14555 char *sh_arg = NULL;
14556 enum show_type sh_type;
14557 afi_t afi = AFI_MAX;
14558
14559 bool uj = use_json(argc, argv);
14560
14561 int idx = 0;
14562
14563 /* [<vrf> VIEWVRFNAME] */
14564 if (argv_find(argv, argc, "vrf", &idx)) {
14565 vrf = argv[idx + 1]->arg;
14566 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
14567 vrf = NULL;
14568 } else if (argv_find(argv, argc, "view", &idx))
14569 /* [<view> VIEWVRFNAME] */
14570 vrf = argv[idx + 1]->arg;
14571
14572 idx++;
14573
14574 if (argv_find(argv, argc, "ipv4", &idx)) {
14575 sh_type = show_ipv4_all;
14576 afi = AFI_IP;
14577 } else if (argv_find(argv, argc, "ipv6", &idx)) {
14578 sh_type = show_ipv6_all;
14579 afi = AFI_IP6;
14580 } else {
14581 sh_type = show_all;
14582 }
14583
14584 if (argv_find(argv, argc, "A.B.C.D", &idx)
14585 || argv_find(argv, argc, "X:X::X:X", &idx)
14586 || argv_find(argv, argc, "WORD", &idx)) {
14587 sh_type = show_peer;
14588 sh_arg = argv[idx]->arg;
14589 }
14590
14591 if (sh_type == show_peer && afi == AFI_IP) {
14592 sh_type = show_ipv4_peer;
14593 } else if (sh_type == show_peer && afi == AFI_IP6) {
14594 sh_type = show_ipv6_peer;
14595 }
14596
14597 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
14598 }
14599
14600 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
14601 paths' and `show ip mbgp paths'. Those functions results are the
14602 same.*/
14603 DEFUN (show_ip_bgp_paths,
14604 show_ip_bgp_paths_cmd,
14605 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
14606 SHOW_STR
14607 IP_STR
14608 BGP_STR
14609 BGP_SAFI_HELP_STR
14610 "Path information\n")
14611 {
14612 vty_out(vty, "Address Refcnt Path\n");
14613 aspath_print_all_vty(vty);
14614 return CMD_SUCCESS;
14615 }
14616
14617 #include "hash.h"
14618
14619 static void community_show_all_iterator(struct hash_bucket *bucket,
14620 struct vty *vty)
14621 {
14622 struct community *com;
14623
14624 com = (struct community *)bucket->data;
14625 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
14626 community_str(com, false));
14627 }
14628
14629 /* Show BGP's community internal data. */
14630 DEFUN (show_ip_bgp_community_info,
14631 show_ip_bgp_community_info_cmd,
14632 "show [ip] bgp community-info",
14633 SHOW_STR
14634 IP_STR
14635 BGP_STR
14636 "List all bgp community information\n")
14637 {
14638 vty_out(vty, "Address Refcnt Community\n");
14639
14640 hash_iterate(community_hash(),
14641 (void (*)(struct hash_bucket *,
14642 void *))community_show_all_iterator,
14643 vty);
14644
14645 return CMD_SUCCESS;
14646 }
14647
14648 static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
14649 struct vty *vty)
14650 {
14651 struct lcommunity *lcom;
14652
14653 lcom = (struct lcommunity *)bucket->data;
14654 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
14655 lcommunity_str(lcom, false));
14656 }
14657
14658 /* Show BGP's community internal data. */
14659 DEFUN (show_ip_bgp_lcommunity_info,
14660 show_ip_bgp_lcommunity_info_cmd,
14661 "show ip bgp large-community-info",
14662 SHOW_STR
14663 IP_STR
14664 BGP_STR
14665 "List all bgp large-community information\n")
14666 {
14667 vty_out(vty, "Address Refcnt Large-community\n");
14668
14669 hash_iterate(lcommunity_hash(),
14670 (void (*)(struct hash_bucket *,
14671 void *))lcommunity_show_all_iterator,
14672 vty);
14673
14674 return CMD_SUCCESS;
14675 }
14676 /* Graceful Restart */
14677
14678 static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
14679 struct bgp *bgp,
14680 bool use_json,
14681 json_object *json)
14682 {
14683
14684
14685 vty_out(vty, "\n%s", SHOW_GR_HEADER);
14686
14687 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
14688
14689 switch (bgp_global_gr_mode) {
14690
14691 case GLOBAL_HELPER:
14692 vty_out(vty, "Global BGP GR Mode : Helper\n");
14693 break;
14694
14695 case GLOBAL_GR:
14696 vty_out(vty, "Global BGP GR Mode : Restart\n");
14697 break;
14698
14699 case GLOBAL_DISABLE:
14700 vty_out(vty, "Global BGP GR Mode : Disable\n");
14701 break;
14702
14703 case GLOBAL_INVALID:
14704 vty_out(vty,
14705 "Global BGP GR Mode Invalid\n");
14706 break;
14707 }
14708 vty_out(vty, "\n");
14709 }
14710
14711 static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
14712 enum show_type type,
14713 const char *ip_str,
14714 afi_t afi, bool use_json)
14715 {
14716 if ((afi == AFI_MAX) && (ip_str == NULL)) {
14717 afi = AFI_IP;
14718
14719 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
14720
14721 bgp_show_neighbor_graceful_restart_vty(
14722 vty, type, ip_str, afi, use_json);
14723 afi++;
14724 }
14725 } else if (afi != AFI_MAX) {
14726 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
14727 use_json);
14728 } else {
14729 return CMD_ERR_INCOMPLETE;
14730 }
14731
14732 return CMD_SUCCESS;
14733 }
14734 /* Graceful Restart */
14735
14736 DEFUN (show_ip_bgp_attr_info,
14737 show_ip_bgp_attr_info_cmd,
14738 "show [ip] bgp attribute-info",
14739 SHOW_STR
14740 IP_STR
14741 BGP_STR
14742 "List all bgp attribute information\n")
14743 {
14744 attr_show_all(vty);
14745 return CMD_SUCCESS;
14746 }
14747
14748 static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
14749 afi_t afi, safi_t safi,
14750 bool use_json, json_object *json)
14751 {
14752 struct bgp *bgp;
14753 struct listnode *node;
14754 char *vname;
14755 char buf1[INET6_ADDRSTRLEN];
14756 char *ecom_str;
14757 vpn_policy_direction_t dir;
14758
14759 if (json) {
14760 json_object *json_import_vrfs = NULL;
14761 json_object *json_export_vrfs = NULL;
14762
14763 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
14764
14765 if (!bgp) {
14766 vty_out(vty, "%s\n",
14767 json_object_to_json_string_ext(
14768 json,
14769 JSON_C_TO_STRING_PRETTY));
14770 json_object_free(json);
14771
14772 return CMD_WARNING;
14773 }
14774
14775 /* Provide context for the block */
14776 json_object_string_add(json, "vrf", name ? name : "default");
14777 json_object_string_add(json, "afiSafi",
14778 get_afi_safi_str(afi, safi, true));
14779
14780 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14781 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
14782 json_object_string_add(json, "importFromVrfs", "none");
14783 json_object_string_add(json, "importRts", "none");
14784 } else {
14785 json_import_vrfs = json_object_new_array();
14786
14787 for (ALL_LIST_ELEMENTS_RO(
14788 bgp->vpn_policy[afi].import_vrf,
14789 node, vname))
14790 json_object_array_add(json_import_vrfs,
14791 json_object_new_string(vname));
14792
14793 json_object_object_add(json, "importFromVrfs",
14794 json_import_vrfs);
14795 dir = BGP_VPN_POLICY_DIR_FROMVPN;
14796 if (bgp->vpn_policy[afi].rtlist[dir]) {
14797 ecom_str = ecommunity_ecom2str(
14798 bgp->vpn_policy[afi].rtlist[dir],
14799 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
14800 json_object_string_add(json, "importRts",
14801 ecom_str);
14802 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14803 } else
14804 json_object_string_add(json, "importRts",
14805 "none");
14806 }
14807
14808 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14809 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
14810 json_object_string_add(json, "exportToVrfs", "none");
14811 json_object_string_add(json, "routeDistinguisher",
14812 "none");
14813 json_object_string_add(json, "exportRts", "none");
14814 } else {
14815 json_export_vrfs = json_object_new_array();
14816
14817 for (ALL_LIST_ELEMENTS_RO(
14818 bgp->vpn_policy[afi].export_vrf,
14819 node, vname))
14820 json_object_array_add(json_export_vrfs,
14821 json_object_new_string(vname));
14822 json_object_object_add(json, "exportToVrfs",
14823 json_export_vrfs);
14824 json_object_string_add(json, "routeDistinguisher",
14825 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
14826 buf1, RD_ADDRSTRLEN));
14827
14828 dir = BGP_VPN_POLICY_DIR_TOVPN;
14829 if (bgp->vpn_policy[afi].rtlist[dir]) {
14830 ecom_str = ecommunity_ecom2str(
14831 bgp->vpn_policy[afi].rtlist[dir],
14832 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
14833 json_object_string_add(json, "exportRts",
14834 ecom_str);
14835 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14836 } else
14837 json_object_string_add(json, "exportRts",
14838 "none");
14839 }
14840
14841 if (use_json) {
14842 vty_out(vty, "%s\n",
14843 json_object_to_json_string_ext(json,
14844 JSON_C_TO_STRING_PRETTY));
14845 json_object_free(json);
14846 }
14847 } else {
14848 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
14849
14850 if (!bgp) {
14851 vty_out(vty, "%% No such BGP instance exist\n");
14852 return CMD_WARNING;
14853 }
14854
14855 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14856 BGP_CONFIG_VRF_TO_VRF_IMPORT))
14857 vty_out(vty,
14858 "This VRF is not importing %s routes from any other VRF\n",
14859 get_afi_safi_str(afi, safi, false));
14860 else {
14861 vty_out(vty,
14862 "This VRF is importing %s routes from the following VRFs:\n",
14863 get_afi_safi_str(afi, safi, false));
14864
14865 for (ALL_LIST_ELEMENTS_RO(
14866 bgp->vpn_policy[afi].import_vrf,
14867 node, vname))
14868 vty_out(vty, " %s\n", vname);
14869
14870 dir = BGP_VPN_POLICY_DIR_FROMVPN;
14871 ecom_str = NULL;
14872 if (bgp->vpn_policy[afi].rtlist[dir]) {
14873 ecom_str = ecommunity_ecom2str(
14874 bgp->vpn_policy[afi].rtlist[dir],
14875 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
14876 vty_out(vty, "Import RT(s): %s\n", ecom_str);
14877
14878 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14879 } else
14880 vty_out(vty, "Import RT(s):\n");
14881 }
14882
14883 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14884 BGP_CONFIG_VRF_TO_VRF_EXPORT))
14885 vty_out(vty,
14886 "This VRF is not exporting %s routes to any other VRF\n",
14887 get_afi_safi_str(afi, safi, false));
14888 else {
14889 vty_out(vty,
14890 "This VRF is exporting %s routes to the following VRFs:\n",
14891 get_afi_safi_str(afi, safi, false));
14892
14893 for (ALL_LIST_ELEMENTS_RO(
14894 bgp->vpn_policy[afi].export_vrf,
14895 node, vname))
14896 vty_out(vty, " %s\n", vname);
14897
14898 vty_out(vty, "RD: %s\n",
14899 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
14900 buf1, RD_ADDRSTRLEN));
14901
14902 dir = BGP_VPN_POLICY_DIR_TOVPN;
14903 if (bgp->vpn_policy[afi].rtlist[dir]) {
14904 ecom_str = ecommunity_ecom2str(
14905 bgp->vpn_policy[afi].rtlist[dir],
14906 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
14907 vty_out(vty, "Export RT: %s\n", ecom_str);
14908 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14909 } else
14910 vty_out(vty, "Import RT(s):\n");
14911 }
14912 }
14913
14914 return CMD_SUCCESS;
14915 }
14916
14917 static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
14918 safi_t safi, bool use_json)
14919 {
14920 struct listnode *node, *nnode;
14921 struct bgp *bgp;
14922 char *vrf_name = NULL;
14923 json_object *json = NULL;
14924 json_object *json_vrf = NULL;
14925 json_object *json_vrfs = NULL;
14926
14927 if (use_json) {
14928 json = json_object_new_object();
14929 json_vrfs = json_object_new_object();
14930 }
14931
14932 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
14933
14934 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
14935 vrf_name = bgp->name;
14936
14937 if (use_json) {
14938 json_vrf = json_object_new_object();
14939 } else {
14940 vty_out(vty, "\nInstance %s:\n",
14941 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14942 ? VRF_DEFAULT_NAME : bgp->name);
14943 }
14944 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
14945 if (use_json) {
14946 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14947 json_object_object_add(json_vrfs,
14948 VRF_DEFAULT_NAME, json_vrf);
14949 else
14950 json_object_object_add(json_vrfs, vrf_name,
14951 json_vrf);
14952 }
14953 }
14954
14955 if (use_json) {
14956 json_object_object_add(json, "vrfs", json_vrfs);
14957 vty_out(vty, "%s\n", json_object_to_json_string_ext(json,
14958 JSON_C_TO_STRING_PRETTY));
14959 json_object_free(json);
14960 }
14961
14962 return CMD_SUCCESS;
14963 }
14964
14965 /* "show [ip] bgp route-leak" command. */
14966 DEFUN (show_ip_bgp_route_leak,
14967 show_ip_bgp_route_leak_cmd,
14968 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
14969 SHOW_STR
14970 IP_STR
14971 BGP_STR
14972 BGP_INSTANCE_HELP_STR
14973 BGP_AFI_HELP_STR
14974 BGP_SAFI_HELP_STR
14975 "Route leaking information\n"
14976 JSON_STR)
14977 {
14978 char *vrf = NULL;
14979 afi_t afi = AFI_MAX;
14980 safi_t safi = SAFI_MAX;
14981
14982 bool uj = use_json(argc, argv);
14983 int idx = 0;
14984 json_object *json = NULL;
14985
14986 /* show [ip] bgp */
14987 if (argv_find(argv, argc, "ip", &idx)) {
14988 afi = AFI_IP;
14989 safi = SAFI_UNICAST;
14990 }
14991 /* [vrf VIEWVRFNAME] */
14992 if (argv_find(argv, argc, "view", &idx)) {
14993 vty_out(vty,
14994 "%% This command is not applicable to BGP views\n");
14995 return CMD_WARNING;
14996 }
14997
14998 if (argv_find(argv, argc, "vrf", &idx)) {
14999 vrf = argv[idx + 1]->arg;
15000 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15001 vrf = NULL;
15002 }
15003 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15004 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
15005 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15006 }
15007
15008 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
15009 vty_out(vty,
15010 "%% This command is applicable only for unicast ipv4|ipv6\n");
15011 return CMD_WARNING;
15012 }
15013
15014 if (vrf && strmatch(vrf, "all"))
15015 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
15016
15017 if (uj)
15018 json = json_object_new_object();
15019
15020 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
15021 }
15022
15023 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
15024 safi_t safi)
15025 {
15026 struct listnode *node, *nnode;
15027 struct bgp *bgp;
15028
15029 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15030 vty_out(vty, "\nInstance %s:\n",
15031 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15032 ? VRF_DEFAULT_NAME
15033 : bgp->name);
15034 update_group_show(bgp, afi, safi, vty, 0);
15035 }
15036 }
15037
15038 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
15039 int safi, uint64_t subgrp_id)
15040 {
15041 struct bgp *bgp;
15042
15043 if (name) {
15044 if (strmatch(name, "all")) {
15045 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
15046 return CMD_SUCCESS;
15047 } else {
15048 bgp = bgp_lookup_by_name(name);
15049 }
15050 } else {
15051 bgp = bgp_get_default();
15052 }
15053
15054 if (bgp)
15055 update_group_show(bgp, afi, safi, vty, subgrp_id);
15056 return CMD_SUCCESS;
15057 }
15058
15059 DEFUN (show_ip_bgp_updgrps,
15060 show_ip_bgp_updgrps_cmd,
15061 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
15062 SHOW_STR
15063 IP_STR
15064 BGP_STR
15065 BGP_INSTANCE_HELP_STR
15066 BGP_AFI_HELP_STR
15067 BGP_SAFI_WITH_LABEL_HELP_STR
15068 "Detailed info about dynamic update groups\n"
15069 "Specific subgroup to display detailed info for\n")
15070 {
15071 char *vrf = NULL;
15072 afi_t afi = AFI_IP6;
15073 safi_t safi = SAFI_UNICAST;
15074 uint64_t subgrp_id = 0;
15075
15076 int idx = 0;
15077
15078 /* show [ip] bgp */
15079 if (argv_find(argv, argc, "ip", &idx))
15080 afi = AFI_IP;
15081 /* [<vrf> VIEWVRFNAME] */
15082 if (argv_find(argv, argc, "vrf", &idx)) {
15083 vrf = argv[idx + 1]->arg;
15084 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15085 vrf = NULL;
15086 } else if (argv_find(argv, argc, "view", &idx))
15087 /* [<view> VIEWVRFNAME] */
15088 vrf = argv[idx + 1]->arg;
15089 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15090 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
15091 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15092 }
15093
15094 /* get subgroup id, if provided */
15095 idx = argc - 1;
15096 if (argv[idx]->type == VARIABLE_TKN)
15097 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
15098
15099 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
15100 }
15101
15102 DEFUN (show_bgp_instance_all_ipv6_updgrps,
15103 show_bgp_instance_all_ipv6_updgrps_cmd,
15104 "show [ip] bgp <view|vrf> all update-groups",
15105 SHOW_STR
15106 IP_STR
15107 BGP_STR
15108 BGP_INSTANCE_ALL_HELP_STR
15109 "Detailed info about dynamic update groups\n")
15110 {
15111 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
15112 return CMD_SUCCESS;
15113 }
15114
15115 DEFUN (show_bgp_l2vpn_evpn_updgrps,
15116 show_bgp_l2vpn_evpn_updgrps_cmd,
15117 "show [ip] bgp l2vpn evpn update-groups",
15118 SHOW_STR
15119 IP_STR
15120 BGP_STR
15121 "l2vpn address family\n"
15122 "evpn sub-address family\n"
15123 "Detailed info about dynamic update groups\n")
15124 {
15125 char *vrf = NULL;
15126 uint64_t subgrp_id = 0;
15127
15128 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
15129 return CMD_SUCCESS;
15130 }
15131
15132 DEFUN (show_bgp_updgrps_stats,
15133 show_bgp_updgrps_stats_cmd,
15134 "show [ip] bgp update-groups statistics",
15135 SHOW_STR
15136 IP_STR
15137 BGP_STR
15138 "Detailed info about dynamic update groups\n"
15139 "Statistics\n")
15140 {
15141 struct bgp *bgp;
15142
15143 bgp = bgp_get_default();
15144 if (bgp)
15145 update_group_show_stats(bgp, vty);
15146
15147 return CMD_SUCCESS;
15148 }
15149
15150 DEFUN (show_bgp_instance_updgrps_stats,
15151 show_bgp_instance_updgrps_stats_cmd,
15152 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
15153 SHOW_STR
15154 IP_STR
15155 BGP_STR
15156 BGP_INSTANCE_HELP_STR
15157 "Detailed info about dynamic update groups\n"
15158 "Statistics\n")
15159 {
15160 int idx_word = 3;
15161 struct bgp *bgp;
15162
15163 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
15164 if (bgp)
15165 update_group_show_stats(bgp, vty);
15166
15167 return CMD_SUCCESS;
15168 }
15169
15170 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
15171 afi_t afi, safi_t safi,
15172 const char *what, uint64_t subgrp_id)
15173 {
15174 struct bgp *bgp;
15175
15176 if (name)
15177 bgp = bgp_lookup_by_name(name);
15178 else
15179 bgp = bgp_get_default();
15180
15181 if (bgp) {
15182 if (!strcmp(what, "advertise-queue"))
15183 update_group_show_adj_queue(bgp, afi, safi, vty,
15184 subgrp_id);
15185 else if (!strcmp(what, "advertised-routes"))
15186 update_group_show_advertised(bgp, afi, safi, vty,
15187 subgrp_id);
15188 else if (!strcmp(what, "packet-queue"))
15189 update_group_show_packet_queue(bgp, afi, safi, vty,
15190 subgrp_id);
15191 }
15192 }
15193
15194 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
15195 show_ip_bgp_instance_updgrps_adj_s_cmd,
15196 "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",
15197 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
15198 BGP_SAFI_HELP_STR
15199 "Detailed info about dynamic update groups\n"
15200 "Specific subgroup to display info for\n"
15201 "Advertisement queue\n"
15202 "Announced routes\n"
15203 "Packet queue\n")
15204 {
15205 uint64_t subgrp_id = 0;
15206 afi_t afiz;
15207 safi_t safiz;
15208 if (sgid)
15209 subgrp_id = strtoull(sgid, NULL, 10);
15210
15211 if (!ip && !afi)
15212 afiz = AFI_IP6;
15213 if (!ip && afi)
15214 afiz = bgp_vty_afi_from_str(afi);
15215 if (ip && !afi)
15216 afiz = AFI_IP;
15217 if (ip && afi) {
15218 afiz = bgp_vty_afi_from_str(afi);
15219 if (afiz != AFI_IP)
15220 vty_out(vty,
15221 "%% Cannot specify both 'ip' and 'ipv6'\n");
15222 return CMD_WARNING;
15223 }
15224
15225 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
15226
15227 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
15228 return CMD_SUCCESS;
15229 }
15230
15231 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
15232 {
15233 struct listnode *node, *nnode;
15234 struct prefix *range;
15235 struct peer *conf;
15236 struct peer *peer;
15237 afi_t afi;
15238 safi_t safi;
15239 const char *peer_status;
15240 const char *af_str;
15241 int lr_count;
15242 int dynamic;
15243 int af_cfgd;
15244
15245 conf = group->conf;
15246
15247 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
15248 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15249 group->name, conf->as);
15250 } else if (conf->as_type == AS_INTERNAL) {
15251 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15252 group->name, group->bgp->as);
15253 } else {
15254 vty_out(vty, "\nBGP peer-group %s\n", group->name);
15255 }
15256
15257 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
15258 vty_out(vty, " Peer-group type is internal\n");
15259 else
15260 vty_out(vty, " Peer-group type is external\n");
15261
15262 /* Display AFs configured. */
15263 vty_out(vty, " Configured address-families:");
15264 FOREACH_AFI_SAFI (afi, safi) {
15265 if (conf->afc[afi][safi]) {
15266 af_cfgd = 1;
15267 vty_out(vty, " %s;", get_afi_safi_str(afi, safi, false));
15268 }
15269 }
15270 if (!af_cfgd)
15271 vty_out(vty, " none\n");
15272 else
15273 vty_out(vty, "\n");
15274
15275 /* Display listen ranges (for dynamic neighbors), if any */
15276 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
15277 if (afi == AFI_IP)
15278 af_str = "IPv4";
15279 else if (afi == AFI_IP6)
15280 af_str = "IPv6";
15281 else
15282 af_str = "???";
15283 lr_count = listcount(group->listen_range[afi]);
15284 if (lr_count) {
15285 vty_out(vty, " %d %s listen range(s)\n", lr_count,
15286 af_str);
15287
15288
15289 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
15290 nnode, range))
15291 vty_out(vty, " %pFX\n", range);
15292 }
15293 }
15294
15295 /* Display group members and their status */
15296 if (listcount(group->peer)) {
15297 vty_out(vty, " Peer-group members:\n");
15298 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
15299 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
15300 || CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHUTDOWN))
15301 peer_status = "Idle (Admin)";
15302 else if (CHECK_FLAG(peer->sflags,
15303 PEER_STATUS_PREFIX_OVERFLOW))
15304 peer_status = "Idle (PfxCt)";
15305 else
15306 peer_status = lookup_msg(bgp_status_msg,
15307 peer->status, NULL);
15308
15309 dynamic = peer_dynamic_neighbor(peer);
15310 vty_out(vty, " %s %s %s \n", peer->host,
15311 dynamic ? "(dynamic)" : "", peer_status);
15312 }
15313 }
15314
15315 return CMD_SUCCESS;
15316 }
15317
15318 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
15319 const char *group_name)
15320 {
15321 struct bgp *bgp;
15322 struct listnode *node, *nnode;
15323 struct peer_group *group;
15324 bool found = false;
15325
15326 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15327
15328 if (!bgp) {
15329 vty_out(vty, "%% BGP instance not found\n");
15330 return CMD_WARNING;
15331 }
15332
15333 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
15334 if (group_name) {
15335 if (strmatch(group->name, group_name)) {
15336 bgp_show_one_peer_group(vty, group);
15337 found = true;
15338 break;
15339 }
15340 } else {
15341 bgp_show_one_peer_group(vty, group);
15342 }
15343 }
15344
15345 if (group_name && !found)
15346 vty_out(vty, "%% No such peer-group\n");
15347
15348 return CMD_SUCCESS;
15349 }
15350
15351 DEFUN (show_ip_bgp_peer_groups,
15352 show_ip_bgp_peer_groups_cmd,
15353 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
15354 SHOW_STR
15355 IP_STR
15356 BGP_STR
15357 BGP_INSTANCE_HELP_STR
15358 "Detailed information on BGP peer groups\n"
15359 "Peer group name\n")
15360 {
15361 char *vrf, *pg;
15362 int idx = 0;
15363
15364 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
15365 : NULL;
15366 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
15367
15368 return bgp_show_peer_group_vty(vty, vrf, pg);
15369 }
15370
15371
15372 /* Redistribute VTY commands. */
15373
15374 DEFUN_YANG (bgp_redistribute_ipv4,
15375 bgp_redistribute_ipv4_cmd,
15376 "redistribute " FRR_IP_REDIST_STR_BGPD,
15377 "Redistribute information from another routing protocol\n"
15378 FRR_IP_REDIST_HELP_STR_BGPD)
15379 {
15380 int idx_protocol = 1;
15381 char base_xpath[XPATH_MAXLEN];
15382
15383 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15384 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15385 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15386 argv[idx_protocol]->text, "0");
15387
15388 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15389
15390 return nb_cli_apply_changes(vty, base_xpath);
15391 }
15392
15393 ALIAS_HIDDEN(
15394 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
15395 "redistribute " FRR_IP_REDIST_STR_BGPD,
15396 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
15397
15398 DEFUN_YANG (bgp_redistribute_ipv4_rmap,
15399 bgp_redistribute_ipv4_rmap_cmd,
15400 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
15401 "Redistribute information from another routing protocol\n"
15402 FRR_IP_REDIST_HELP_STR_BGPD
15403 "Route map reference\n"
15404 "Pointer to route-map entries\n")
15405 {
15406 int idx_protocol = 1;
15407 int idx_word = 3;
15408 char base_xpath[XPATH_MAXLEN];
15409
15410 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15411 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15412 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15413 argv[idx_protocol]->text, "0");
15414
15415 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15416 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15417 argv[idx_word]->arg);
15418
15419 return nb_cli_apply_changes(vty, base_xpath);
15420 }
15421
15422 ALIAS_HIDDEN(
15423 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
15424 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
15425 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15426 "Route map reference\n"
15427 "Pointer to route-map entries\n")
15428
15429 DEFUN_YANG (bgp_redistribute_ipv4_metric,
15430 bgp_redistribute_ipv4_metric_cmd,
15431 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15432 "Redistribute information from another routing protocol\n"
15433 FRR_IP_REDIST_HELP_STR_BGPD
15434 "Metric for redistributed routes\n"
15435 "Default metric\n")
15436 {
15437 int idx_protocol = 1;
15438 int idx_number = 3;
15439 char base_xpath[XPATH_MAXLEN];
15440
15441 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15442 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15443 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15444 argv[idx_protocol]->text, "0");
15445
15446 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15447 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15448 argv[idx_number]->arg);
15449
15450 return nb_cli_apply_changes(vty, base_xpath);
15451 }
15452
15453 ALIAS_HIDDEN(
15454 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
15455 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15456 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15457 "Metric for redistributed routes\n"
15458 "Default metric\n")
15459
15460 DEFUN_YANG(
15461 bgp_redistribute_ipv4_rmap_metric,
15462 bgp_redistribute_ipv4_rmap_metric_cmd,
15463 "redistribute " FRR_IP_REDIST_STR_BGPD
15464 " route-map WORD metric (0-4294967295)",
15465 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15466 "Route map reference\n"
15467 "Pointer to route-map entries\n"
15468 "Metric for redistributed routes\n"
15469 "Default metric\n")
15470 {
15471 int idx_protocol = 1;
15472 int idx_word = 3;
15473 int idx_number = 5;
15474 char base_xpath[XPATH_MAXLEN];
15475
15476 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15477 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15478 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15479 argv[idx_protocol]->text, "0");
15480
15481 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15482 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15483 argv[idx_word]->arg);
15484 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15485 argv[idx_number]->arg);
15486
15487 return nb_cli_apply_changes(vty, base_xpath);
15488 }
15489
15490 ALIAS_HIDDEN(
15491 bgp_redistribute_ipv4_rmap_metric,
15492 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
15493 "redistribute " FRR_IP_REDIST_STR_BGPD
15494 " route-map WORD metric (0-4294967295)",
15495 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15496 "Route map reference\n"
15497 "Pointer to route-map entries\n"
15498 "Metric for redistributed routes\n"
15499 "Default metric\n")
15500
15501 DEFUN_YANG(
15502 bgp_redistribute_ipv4_metric_rmap,
15503 bgp_redistribute_ipv4_metric_rmap_cmd,
15504 "redistribute " FRR_IP_REDIST_STR_BGPD
15505 " metric (0-4294967295) route-map WORD",
15506 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15507 "Metric for redistributed routes\n"
15508 "Default metric\n"
15509 "Route map reference\n"
15510 "Pointer to route-map entries\n")
15511 {
15512 int idx_protocol = 1;
15513 int idx_word = 5;
15514 int idx_number = 3;
15515 char base_xpath[XPATH_MAXLEN];
15516
15517 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15518 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15519 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15520 argv[idx_protocol]->text, "0");
15521
15522 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15523 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15524 argv[idx_number]->arg);
15525 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15526 argv[idx_word]->arg);
15527
15528 return nb_cli_apply_changes(vty, base_xpath);
15529 }
15530
15531 ALIAS_HIDDEN(
15532 bgp_redistribute_ipv4_metric_rmap,
15533 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
15534 "redistribute " FRR_IP_REDIST_STR_BGPD
15535 " metric (0-4294967295) route-map WORD",
15536 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15537 "Metric for redistributed routes\n"
15538 "Default metric\n"
15539 "Route map reference\n"
15540 "Pointer to route-map entries\n")
15541
15542 DEFUN_YANG (bgp_redistribute_ipv4_ospf,
15543 bgp_redistribute_ipv4_ospf_cmd,
15544 "redistribute <ospf|table> (1-65535)",
15545 "Redistribute information from another routing protocol\n"
15546 "Open Shortest Path First (OSPFv2)\n"
15547 "Non-main Kernel Routing Table\n"
15548 "Instance ID/Table ID\n")
15549 {
15550 int idx_protocol = 1;
15551 int idx_number = 2;
15552 char base_xpath[XPATH_MAXLEN];
15553
15554 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15555 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15556 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15557 argv[idx_protocol]->text, argv[idx_number]->arg);
15558
15559 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15560
15561 return nb_cli_apply_changes(vty, base_xpath);
15562 }
15563
15564 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
15565 "redistribute <ospf|table> (1-65535)",
15566 "Redistribute information from another routing protocol\n"
15567 "Open Shortest Path First (OSPFv2)\n"
15568 "Non-main Kernel Routing Table\n"
15569 "Instance ID/Table ID\n")
15570
15571 DEFUN_YANG (bgp_redistribute_ipv4_ospf_rmap,
15572 bgp_redistribute_ipv4_ospf_rmap_cmd,
15573 "redistribute <ospf|table> (1-65535) route-map WORD",
15574 "Redistribute information from another routing protocol\n"
15575 "Open Shortest Path First (OSPFv2)\n"
15576 "Non-main Kernel Routing Table\n"
15577 "Instance ID/Table ID\n"
15578 "Route map reference\n"
15579 "Pointer to route-map entries\n")
15580 {
15581 int idx_protocol = 1;
15582 int idx_number = 2;
15583 int idx_word = 4;
15584 char base_xpath[XPATH_MAXLEN];
15585
15586 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15587 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15588 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15589 argv[idx_protocol]->text, argv[idx_number]->arg);
15590
15591 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15592
15593 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15594 argv[idx_word]->arg);
15595
15596 return nb_cli_apply_changes(vty, base_xpath);
15597 }
15598
15599 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
15600 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
15601 "redistribute <ospf|table> (1-65535) route-map WORD",
15602 "Redistribute information from another routing protocol\n"
15603 "Open Shortest Path First (OSPFv2)\n"
15604 "Non-main Kernel Routing Table\n"
15605 "Instance ID/Table ID\n"
15606 "Route map reference\n"
15607 "Pointer to route-map entries\n")
15608
15609 DEFUN_YANG(bgp_redistribute_ipv4_ospf_metric,
15610 bgp_redistribute_ipv4_ospf_metric_cmd,
15611 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
15612 "Redistribute information from another routing protocol\n"
15613 "Open Shortest Path First (OSPFv2)\n"
15614 "Non-main Kernel Routing Table\n"
15615 "Instance ID/Table ID\n"
15616 "Metric for redistributed routes\n"
15617 "Default metric\n")
15618 {
15619 int idx_protocol = 1;
15620 int idx_number = 2;
15621 int idx_number_2 = 4;
15622 char base_xpath[XPATH_MAXLEN];
15623
15624 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15625 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15626 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15627 argv[idx_protocol]->text, argv[idx_number]->arg);
15628
15629 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15630
15631 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15632 argv[idx_number_2]->arg);
15633
15634 return nb_cli_apply_changes(vty, base_xpath);
15635 }
15636
15637 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
15638 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
15639 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
15640 "Redistribute information from another routing protocol\n"
15641 "Open Shortest Path First (OSPFv2)\n"
15642 "Non-main Kernel Routing Table\n"
15643 "Instance ID/Table ID\n"
15644 "Metric for redistributed routes\n"
15645 "Default metric\n")
15646
15647 DEFUN_YANG(
15648 bgp_redistribute_ipv4_ospf_rmap_metric,
15649 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
15650 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
15651 "Redistribute information from another routing protocol\n"
15652 "Open Shortest Path First (OSPFv2)\n"
15653 "Non-main Kernel Routing Table\n"
15654 "Instance ID/Table ID\n"
15655 "Route map reference\n"
15656 "Pointer to route-map entries\n"
15657 "Metric for redistributed routes\n"
15658 "Default metric\n")
15659 {
15660 int idx_protocol = 1;
15661 int idx_number = 2;
15662 int idx_word = 4;
15663 int idx_number_2 = 6;
15664 char base_xpath[XPATH_MAXLEN];
15665
15666 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15667 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15668 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15669 argv[idx_protocol]->text, argv[idx_number]->arg);
15670
15671 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15672
15673 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15674 argv[idx_word]->arg);
15675 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15676 argv[idx_number_2]->arg);
15677
15678 return nb_cli_apply_changes(vty, base_xpath);
15679 }
15680
15681 ALIAS_HIDDEN(
15682 bgp_redistribute_ipv4_ospf_rmap_metric,
15683 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
15684 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
15685 "Redistribute information from another routing protocol\n"
15686 "Open Shortest Path First (OSPFv2)\n"
15687 "Non-main Kernel Routing Table\n"
15688 "Instance ID/Table ID\n"
15689 "Route map reference\n"
15690 "Pointer to route-map entries\n"
15691 "Metric for redistributed routes\n"
15692 "Default metric\n")
15693
15694 DEFUN_YANG(
15695 bgp_redistribute_ipv4_ospf_metric_rmap,
15696 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
15697 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
15698 "Redistribute information from another routing protocol\n"
15699 "Open Shortest Path First (OSPFv2)\n"
15700 "Non-main Kernel Routing Table\n"
15701 "Instance ID/Table ID\n"
15702 "Metric for redistributed routes\n"
15703 "Default metric\n"
15704 "Route map reference\n"
15705 "Pointer to route-map entries\n")
15706 {
15707 int idx_protocol = 1;
15708 int idx_number = 2;
15709 int idx_number_2 = 4;
15710 int idx_word = 6;
15711 char base_xpath[XPATH_MAXLEN];
15712
15713 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15714 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15715 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15716 argv[idx_protocol]->text, argv[idx_number]->arg);
15717
15718 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15719
15720 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15721 argv[idx_number_2]->arg);
15722 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15723 argv[idx_word]->arg);
15724
15725 return nb_cli_apply_changes(vty, base_xpath);
15726 }
15727
15728 ALIAS_HIDDEN(
15729 bgp_redistribute_ipv4_ospf_metric_rmap,
15730 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
15731 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
15732 "Redistribute information from another routing protocol\n"
15733 "Open Shortest Path First (OSPFv2)\n"
15734 "Non-main Kernel Routing Table\n"
15735 "Instance ID/Table ID\n"
15736 "Metric for redistributed routes\n"
15737 "Default metric\n"
15738 "Route map reference\n"
15739 "Pointer to route-map entries\n")
15740
15741 DEFUN_YANG (no_bgp_redistribute_ipv4_ospf,
15742 no_bgp_redistribute_ipv4_ospf_cmd,
15743 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
15744 NO_STR
15745 "Redistribute information from another routing protocol\n"
15746 "Open Shortest Path First (OSPFv2)\n"
15747 "Non-main Kernel Routing Table\n"
15748 "Instance ID/Table ID\n"
15749 "Metric for redistributed routes\n"
15750 "Default metric\n"
15751 "Route map reference\n"
15752 "Pointer to route-map entries\n")
15753 {
15754 int idx_protocol = 2;
15755 int idx_number = 3;
15756 char base_xpath[XPATH_MAXLEN];
15757
15758 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15759 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15760 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15761 argv[idx_protocol]->text, argv[idx_number]->arg);
15762
15763 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
15764
15765 return nb_cli_apply_changes(vty, base_xpath);
15766 }
15767
15768 ALIAS_HIDDEN(
15769 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
15770 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
15771 NO_STR
15772 "Redistribute information from another routing protocol\n"
15773 "Open Shortest Path First (OSPFv2)\n"
15774 "Non-main Kernel Routing Table\n"
15775 "Instance ID/Table ID\n"
15776 "Metric for redistributed routes\n"
15777 "Default metric\n"
15778 "Route map reference\n"
15779 "Pointer to route-map entries\n")
15780
15781 DEFUN_YANG (no_bgp_redistribute_ipv4,
15782 no_bgp_redistribute_ipv4_cmd,
15783 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
15784 NO_STR
15785 "Redistribute information from another routing protocol\n"
15786 FRR_IP_REDIST_HELP_STR_BGPD
15787 "Metric for redistributed routes\n"
15788 "Default metric\n"
15789 "Route map reference\n"
15790 "Pointer to route-map entries\n")
15791 {
15792 int idx_protocol = 2;
15793 char base_xpath[XPATH_MAXLEN];
15794
15795 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15796 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15797 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15798 argv[idx_protocol]->text, "0");
15799
15800 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
15801
15802 return nb_cli_apply_changes(vty, base_xpath);
15803 }
15804
15805 ALIAS_HIDDEN(
15806 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
15807 "no redistribute " FRR_IP_REDIST_STR_BGPD
15808 " [{metric (0-4294967295)|route-map WORD}]",
15809 NO_STR
15810 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15811 "Metric for redistributed routes\n"
15812 "Default metric\n"
15813 "Route map reference\n"
15814 "Pointer to route-map entries\n")
15815
15816 DEFUN_YANG (bgp_redistribute_ipv6,
15817 bgp_redistribute_ipv6_cmd,
15818 "redistribute " FRR_IP6_REDIST_STR_BGPD,
15819 "Redistribute information from another routing protocol\n"
15820 FRR_IP6_REDIST_HELP_STR_BGPD)
15821 {
15822 int idx_protocol = 1;
15823 char base_xpath[XPATH_MAXLEN];
15824
15825 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15826 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
15827 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
15828 argv[idx_protocol]->text, "0");
15829
15830 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15831
15832 return nb_cli_apply_changes(vty, base_xpath);
15833 }
15834
15835 DEFUN_YANG (bgp_redistribute_ipv6_rmap,
15836 bgp_redistribute_ipv6_rmap_cmd,
15837 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
15838 "Redistribute information from another routing protocol\n"
15839 FRR_IP6_REDIST_HELP_STR_BGPD
15840 "Route map reference\n"
15841 "Pointer to route-map entries\n")
15842 {
15843 int idx_protocol = 1;
15844 int idx_word = 3;
15845 char base_xpath[XPATH_MAXLEN];
15846
15847 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15848 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
15849 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
15850 argv[idx_protocol]->text, "0");
15851
15852 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15853 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15854 argv[idx_word]->arg);
15855
15856 return nb_cli_apply_changes(vty, base_xpath);
15857 }
15858
15859 DEFUN_YANG (bgp_redistribute_ipv6_metric,
15860 bgp_redistribute_ipv6_metric_cmd,
15861 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
15862 "Redistribute information from another routing protocol\n"
15863 FRR_IP6_REDIST_HELP_STR_BGPD
15864 "Metric for redistributed routes\n"
15865 "Default metric\n")
15866 {
15867 int idx_protocol = 1;
15868 int idx_number = 3;
15869 char base_xpath[XPATH_MAXLEN];
15870
15871 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15872 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
15873 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
15874 argv[idx_protocol]->text, "0");
15875
15876 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15877 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15878 argv[idx_number]->arg);
15879
15880 return nb_cli_apply_changes(vty, base_xpath);
15881 }
15882
15883 DEFUN_YANG(
15884 bgp_redistribute_ipv6_rmap_metric,
15885 bgp_redistribute_ipv6_rmap_metric_cmd,
15886 "redistribute " FRR_IP6_REDIST_STR_BGPD
15887 " route-map WORD metric (0-4294967295)",
15888 "Redistribute information from another routing protocol\n" FRR_IP6_REDIST_HELP_STR_BGPD
15889 "Route map reference\n"
15890 "Pointer to route-map entries\n"
15891 "Metric for redistributed routes\n"
15892 "Default metric\n")
15893 {
15894 int idx_protocol = 1;
15895 int idx_word = 3;
15896 int idx_number = 5;
15897 char base_xpath[XPATH_MAXLEN];
15898
15899 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15900 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
15901 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
15902 argv[idx_protocol]->text, "0");
15903
15904 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15905 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15906 argv[idx_word]->arg);
15907 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15908 argv[idx_number]->arg);
15909
15910 return nb_cli_apply_changes(vty, base_xpath);
15911 }
15912
15913 DEFUN_YANG(
15914 bgp_redistribute_ipv6_metric_rmap,
15915 bgp_redistribute_ipv6_metric_rmap_cmd,
15916 "redistribute " FRR_IP6_REDIST_STR_BGPD
15917 " metric (0-4294967295) route-map WORD",
15918 "Redistribute information from another routing protocol\n" FRR_IP6_REDIST_HELP_STR_BGPD
15919 "Metric for redistributed routes\n"
15920 "Default metric\n"
15921 "Route map reference\n"
15922 "Pointer to route-map entries\n")
15923 {
15924 int idx_protocol = 1;
15925 int idx_word = 5;
15926 int idx_number = 3;
15927 char base_xpath[XPATH_MAXLEN];
15928
15929 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15930 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
15931 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
15932 argv[idx_protocol]->text, "0");
15933
15934 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15935 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15936 argv[idx_number]->arg);
15937 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15938 argv[idx_word]->arg);
15939
15940 return nb_cli_apply_changes(vty, base_xpath);
15941 }
15942
15943 DEFUN_YANG(
15944 no_bgp_redistribute_ipv6,
15945 no_bgp_redistribute_ipv6_cmd,
15946 "no redistribute " FRR_IP6_REDIST_STR_BGPD
15947 " [{metric (0-4294967295)|route-map WORD}]",
15948 NO_STR
15949 "Redistribute information from another routing protocol\n" FRR_IP6_REDIST_HELP_STR_BGPD
15950 "Metric for redistributed routes\n"
15951 "Default metric\n"
15952 "Route map reference\n"
15953 "Pointer to route-map entries\n")
15954 {
15955 int idx_protocol = 2;
15956 char base_xpath[XPATH_MAXLEN];
15957
15958 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15959 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
15960 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
15961 argv[idx_protocol]->text, "0");
15962
15963 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
15964
15965 return nb_cli_apply_changes(vty, base_xpath);
15966 }
15967
15968 void cli_show_bgp_global_afi_safi_ip_unicast_redistribution_list(
15969 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
15970 {
15971 uint32_t instance = 0;
15972
15973 vty_out(vty, " redistribute %s",
15974 yang_dnode_get_string(dnode, "./route-type"));
15975 if ((instance = yang_dnode_get_uint16(dnode, "./route-instance")))
15976 vty_out(vty, " %d", instance);
15977 if (yang_dnode_exists(dnode, "./metric"))
15978 vty_out(vty, " metric %u",
15979 yang_dnode_get_uint32(dnode, "./metric"));
15980 if (yang_dnode_exists(dnode, "./rmap-policy-import"))
15981 vty_out(vty, " route-map %s",
15982 yang_dnode_get_string(dnode, "./rmap-policy-import"));
15983 vty_out(vty, "\n");
15984 }
15985
15986 static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
15987 afi_t afi, safi_t safi)
15988 {
15989 int i;
15990
15991 /* Unicast redistribution only. */
15992 if (safi != SAFI_UNICAST)
15993 return;
15994
15995 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
15996 /* Redistribute BGP does not make sense. */
15997 if (i != ZEBRA_ROUTE_BGP) {
15998 struct list *red_list;
15999 struct listnode *node;
16000 struct bgp_redist *red;
16001
16002 red_list = bgp->redist[afi][i];
16003 if (!red_list)
16004 continue;
16005
16006 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
16007 /* "redistribute" configuration. */
16008 vty_out(vty, " redistribute %s",
16009 zebra_route_string(i));
16010 if (red->instance)
16011 vty_out(vty, " %d", red->instance);
16012 if (red->redist_metric_flag)
16013 vty_out(vty, " metric %u",
16014 red->redist_metric);
16015 if (red->rmap.name)
16016 vty_out(vty, " route-map %s",
16017 red->rmap.name);
16018 vty_out(vty, "\n");
16019 }
16020 }
16021 }
16022 }
16023
16024 /* peer-group helpers for config-write */
16025
16026 static bool peergroup_flag_check(struct peer *peer, uint32_t flag)
16027 {
16028 if (!peer_group_active(peer)) {
16029 if (CHECK_FLAG(peer->flags_invert, flag))
16030 return !CHECK_FLAG(peer->flags, flag);
16031 else
16032 return !!CHECK_FLAG(peer->flags, flag);
16033 }
16034
16035 return !!CHECK_FLAG(peer->flags_override, flag);
16036 }
16037
16038 static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
16039 uint32_t flag)
16040 {
16041 if (!peer_group_active(peer)) {
16042 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
16043 return !peer_af_flag_check(peer, afi, safi, flag);
16044 else
16045 return !!peer_af_flag_check(peer, afi, safi, flag);
16046 }
16047
16048 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
16049 }
16050
16051 static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
16052 uint8_t type, int direct)
16053 {
16054 struct bgp_filter *filter;
16055
16056 if (peer_group_active(peer))
16057 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
16058 type);
16059
16060 filter = &peer->filter[afi][safi];
16061 switch (type) {
16062 case PEER_FT_DISTRIBUTE_LIST:
16063 return !!(filter->dlist[direct].name);
16064 case PEER_FT_FILTER_LIST:
16065 return !!(filter->aslist[direct].name);
16066 case PEER_FT_PREFIX_LIST:
16067 return !!(filter->plist[direct].name);
16068 case PEER_FT_ROUTE_MAP:
16069 return !!(filter->map[direct].name);
16070 case PEER_FT_UNSUPPRESS_MAP:
16071 return !!(filter->usmap.name);
16072 case PEER_FT_ADVERTISE_MAP:
16073 return !!(filter->advmap.aname
16074 && ((filter->advmap.condition == direct)
16075 && filter->advmap.cname));
16076 default:
16077 return false;
16078 }
16079 }
16080
16081 /* Return true if the addpath type is set for peer and different from
16082 * peer-group.
16083 */
16084 static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi,
16085 safi_t safi)
16086 {
16087 enum bgp_addpath_strat type, g_type;
16088
16089 type = peer->addpath_type[afi][safi];
16090
16091 if (type != BGP_ADDPATH_NONE) {
16092 if (peer_group_active(peer)) {
16093 g_type = peer->group->conf->addpath_type[afi][safi];
16094
16095 if (type != g_type)
16096 return true;
16097 else
16098 return false;
16099 }
16100
16101 return true;
16102 }
16103
16104 return false;
16105 }
16106
16107 /* This is part of the address-family block (unicast only) */
16108 static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
16109 afi_t afi)
16110 {
16111 int indent = 2;
16112
16113 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
16114 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16115 BGP_CONFIG_VRF_TO_VRF_IMPORT))
16116 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
16117 bgp->vpn_policy[afi]
16118 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16119 else
16120 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
16121 bgp->vpn_policy[afi]
16122 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16123 }
16124 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16125 BGP_CONFIG_VRF_TO_VRF_IMPORT)
16126 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16127 BGP_CONFIG_VRF_TO_VRF_EXPORT))
16128 return;
16129
16130 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16131 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
16132
16133 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
16134
16135 } else {
16136 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
16137 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
16138 bgp->vpn_policy[afi].tovpn_label);
16139 }
16140 }
16141 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16142 BGP_VPN_POLICY_TOVPN_RD_SET)) {
16143 char buf[RD_ADDRSTRLEN];
16144 vty_out(vty, "%*srd vpn export %s\n", indent, "",
16145 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
16146 sizeof(buf)));
16147 }
16148 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16149 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
16150
16151 char buf[PREFIX_STRLEN];
16152 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
16153 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
16154 sizeof(buf))) {
16155
16156 vty_out(vty, "%*snexthop vpn export %s\n",
16157 indent, "", buf);
16158 }
16159 }
16160 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
16161 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
16162 && ecommunity_cmp(
16163 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16164 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
16165
16166 char *b = ecommunity_ecom2str(
16167 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16168 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
16169 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
16170 XFREE(MTYPE_ECOMMUNITY_STR, b);
16171 } else {
16172 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
16173 char *b = ecommunity_ecom2str(
16174 bgp->vpn_policy[afi]
16175 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16176 ECOMMUNITY_FORMAT_ROUTE_MAP,
16177 ECOMMUNITY_ROUTE_TARGET);
16178 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
16179 XFREE(MTYPE_ECOMMUNITY_STR, b);
16180 }
16181 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
16182 char *b = ecommunity_ecom2str(
16183 bgp->vpn_policy[afi]
16184 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16185 ECOMMUNITY_FORMAT_ROUTE_MAP,
16186 ECOMMUNITY_ROUTE_TARGET);
16187 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
16188 XFREE(MTYPE_ECOMMUNITY_STR, b);
16189 }
16190 }
16191
16192 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
16193 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
16194 bgp->vpn_policy[afi]
16195 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
16196
16197 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
16198 char *b = ecommunity_ecom2str(
16199 bgp->vpn_policy[afi]
16200 .import_redirect_rtlist,
16201 ECOMMUNITY_FORMAT_ROUTE_MAP,
16202 ECOMMUNITY_ROUTE_TARGET);
16203
16204 if (bgp->vpn_policy[afi].import_redirect_rtlist->unit_size
16205 != ECOMMUNITY_SIZE)
16206 vty_out(vty, "%*srt6 redirect import %s\n",
16207 indent, "", b);
16208 else
16209 vty_out(vty, "%*srt redirect import %s\n",
16210 indent, "", b);
16211 XFREE(MTYPE_ECOMMUNITY_STR, b);
16212 }
16213 }
16214
16215 static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
16216 afi_t afi, safi_t safi)
16217 {
16218 struct bgp_filter *filter;
16219 char *addr;
16220
16221 addr = peer->host;
16222 filter = &peer->filter[afi][safi];
16223
16224 /* distribute-list. */
16225 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16226 FILTER_IN))
16227 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
16228 filter->dlist[FILTER_IN].name);
16229
16230 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16231 FILTER_OUT))
16232 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
16233 filter->dlist[FILTER_OUT].name);
16234
16235 /* prefix-list. */
16236 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16237 FILTER_IN))
16238 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
16239 filter->plist[FILTER_IN].name);
16240
16241 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16242 FILTER_OUT))
16243 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
16244 filter->plist[FILTER_OUT].name);
16245
16246 /* route-map. */
16247 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
16248 vty_out(vty, " neighbor %s route-map %s in\n", addr,
16249 filter->map[RMAP_IN].name);
16250
16251 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
16252 RMAP_OUT))
16253 vty_out(vty, " neighbor %s route-map %s out\n", addr,
16254 filter->map[RMAP_OUT].name);
16255
16256 /* unsuppress-map */
16257 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
16258 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
16259 filter->usmap.name);
16260
16261 /* advertise-map : always applied in OUT direction*/
16262 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16263 CONDITION_NON_EXIST))
16264 vty_out(vty,
16265 " neighbor %s advertise-map %s non-exist-map %s\n",
16266 addr, filter->advmap.aname, filter->advmap.cname);
16267
16268 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16269 CONDITION_EXIST))
16270 vty_out(vty, " neighbor %s advertise-map %s exist-map %s\n",
16271 addr, filter->advmap.aname, filter->advmap.cname);
16272
16273 /* filter-list. */
16274 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16275 FILTER_IN))
16276 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
16277 filter->aslist[FILTER_IN].name);
16278
16279 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16280 FILTER_OUT))
16281 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
16282 filter->aslist[FILTER_OUT].name);
16283 }
16284
16285 /* BGP peer configuration display function. */
16286 static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
16287 struct peer *peer)
16288 {
16289 struct peer *g_peer = NULL;
16290 char buf[SU_ADDRSTRLEN];
16291 char *addr;
16292 int if_pg_printed = false;
16293 int if_ras_printed = false;
16294
16295 /* Skip dynamic neighbors. */
16296 if (peer_dynamic_neighbor(peer))
16297 return;
16298
16299 if (peer->conf_if)
16300 addr = peer->conf_if;
16301 else
16302 addr = peer->host;
16303
16304 /************************************
16305 ****** Global to the neighbor ******
16306 ************************************/
16307 if (peer->conf_if) {
16308 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
16309 vty_out(vty, " neighbor %s interface v6only", addr);
16310 else
16311 vty_out(vty, " neighbor %s interface", addr);
16312
16313 if (peer_group_active(peer)) {
16314 vty_out(vty, " peer-group %s", peer->group->name);
16315 if_pg_printed = true;
16316 } else if (peer->as_type == AS_SPECIFIED) {
16317 vty_out(vty, " remote-as %u", peer->as);
16318 if_ras_printed = true;
16319 } else if (peer->as_type == AS_INTERNAL) {
16320 vty_out(vty, " remote-as internal");
16321 if_ras_printed = true;
16322 } else if (peer->as_type == AS_EXTERNAL) {
16323 vty_out(vty, " remote-as external");
16324 if_ras_printed = true;
16325 }
16326
16327 vty_out(vty, "\n");
16328 }
16329
16330 /* remote-as and peer-group */
16331 /* peer is a member of a peer-group */
16332 if (peer_group_active(peer)) {
16333 g_peer = peer->group->conf;
16334
16335 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
16336 if (peer->as_type == AS_SPECIFIED) {
16337 vty_out(vty, " neighbor %s remote-as %u\n",
16338 addr, peer->as);
16339 } else if (peer->as_type == AS_INTERNAL) {
16340 vty_out(vty,
16341 " neighbor %s remote-as internal\n",
16342 addr);
16343 } else if (peer->as_type == AS_EXTERNAL) {
16344 vty_out(vty,
16345 " neighbor %s remote-as external\n",
16346 addr);
16347 }
16348 }
16349
16350 /* For swpX peers we displayed the peer-group
16351 * via 'neighbor swpX interface peer-group PGNAME' */
16352 if (!if_pg_printed)
16353 vty_out(vty, " neighbor %s peer-group %s\n", addr,
16354 peer->group->name);
16355 }
16356
16357 /* peer is NOT a member of a peer-group */
16358 else {
16359 /* peer is a peer-group, declare the peer-group */
16360 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
16361 vty_out(vty, " neighbor %s peer-group\n", addr);
16362 }
16363
16364 if (!if_ras_printed) {
16365 if (peer->as_type == AS_SPECIFIED) {
16366 vty_out(vty, " neighbor %s remote-as %u\n",
16367 addr, peer->as);
16368 } else if (peer->as_type == AS_INTERNAL) {
16369 vty_out(vty,
16370 " neighbor %s remote-as internal\n",
16371 addr);
16372 } else if (peer->as_type == AS_EXTERNAL) {
16373 vty_out(vty,
16374 " neighbor %s remote-as external\n",
16375 addr);
16376 }
16377 }
16378 }
16379
16380 /* local-as */
16381 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
16382 vty_out(vty, " neighbor %s local-as %u", addr,
16383 peer->change_local_as);
16384 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
16385 vty_out(vty, " no-prepend");
16386 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
16387 vty_out(vty, " replace-as");
16388 vty_out(vty, "\n");
16389 }
16390
16391 /* description */
16392 if (peer->desc) {
16393 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
16394 }
16395
16396 /* shutdown */
16397 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
16398 if (peer->tx_shutdown_message)
16399 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
16400 peer->tx_shutdown_message);
16401 else
16402 vty_out(vty, " neighbor %s shutdown\n", addr);
16403 }
16404
16405 if (peergroup_flag_check(peer, PEER_FLAG_RTT_SHUTDOWN))
16406 vty_out(vty, " neighbor %s shutdown rtt %u count %u\n", addr,
16407 peer->rtt_expected, peer->rtt_keepalive_conf);
16408
16409 /* bfd */
16410 if (peer->bfd_info) {
16411 if (!peer_group_active(peer) || !g_peer->bfd_info) {
16412 bgp_bfd_peer_config_write(vty, peer, addr);
16413 }
16414 }
16415
16416 /* password */
16417 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
16418 vty_out(vty, " neighbor %s password %s\n", addr,
16419 peer->password);
16420
16421 /* neighbor solo */
16422 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
16423 if (!peer_group_active(peer)) {
16424 vty_out(vty, " neighbor %s solo\n", addr);
16425 }
16426 }
16427
16428 /* BGP port */
16429 if (peer->port != BGP_PORT_DEFAULT) {
16430 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
16431 }
16432
16433 /* Local interface name */
16434 if (peer->ifname) {
16435 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
16436 }
16437
16438 /* passive */
16439 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
16440 vty_out(vty, " neighbor %s passive\n", addr);
16441
16442 /* ebgp-multihop */
16443 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
16444 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
16445 && peer->ttl == MAXTTL)) {
16446 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
16447 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
16448 peer->ttl);
16449 }
16450 }
16451
16452 /* ttl-security hops */
16453 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
16454 if (!peer_group_active(peer)
16455 || g_peer->gtsm_hops != peer->gtsm_hops) {
16456 vty_out(vty, " neighbor %s ttl-security hops %d\n",
16457 addr, peer->gtsm_hops);
16458 }
16459 }
16460
16461 /* disable-connected-check */
16462 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
16463 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
16464
16465 /* enforce-first-as */
16466 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
16467 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
16468
16469 /* update-source */
16470 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
16471 if (peer->update_source)
16472 vty_out(vty, " neighbor %s update-source %s\n", addr,
16473 sockunion2str(peer->update_source, buf,
16474 SU_ADDRSTRLEN));
16475 else if (peer->update_if)
16476 vty_out(vty, " neighbor %s update-source %s\n", addr,
16477 peer->update_if);
16478 }
16479
16480 /* advertisement-interval */
16481 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
16482 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
16483 peer->routeadv);
16484
16485 /* timers */
16486 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
16487 vty_out(vty, " neighbor %s timers %u %u\n", addr,
16488 peer->keepalive, peer->holdtime);
16489
16490 /* timers connect */
16491 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
16492 vty_out(vty, " neighbor %s timers connect %u\n", addr,
16493 peer->connect);
16494 /* need special-case handling for changed default values due to
16495 * config profile / version (because there is no "timers bgp connect"
16496 * command, we need to save this per-peer :/)
16497 */
16498 else if (!peer_group_active(peer) && !peer->connect &&
16499 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
16500 vty_out(vty, " neighbor %s timers connect %u\n", addr,
16501 peer->bgp->default_connect_retry);
16502
16503 /* timers delayopen */
16504 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_DELAYOPEN))
16505 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
16506 peer->delayopen);
16507 /* Save config even though flag is not set if default values have been
16508 * changed
16509 */
16510 else if (!peer_group_active(peer) && !peer->delayopen
16511 && peer->bgp->default_delayopen != BGP_DEFAULT_DELAYOPEN)
16512 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
16513 peer->bgp->default_delayopen);
16514
16515 /* capability dynamic */
16516 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
16517 vty_out(vty, " neighbor %s capability dynamic\n", addr);
16518
16519 /* capability extended-nexthop */
16520 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
16521 if (!peer->conf_if) {
16522 if (CHECK_FLAG(peer->flags_invert,
16523 PEER_FLAG_CAPABILITY_ENHE))
16524 vty_out(vty,
16525 " no neighbor %s capability extended-nexthop\n",
16526 addr);
16527 else
16528 vty_out(vty,
16529 " neighbor %s capability extended-nexthop\n",
16530 addr);
16531 }
16532 }
16533
16534 /* dont-capability-negotiation */
16535 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
16536 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
16537
16538 /* override-capability */
16539 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
16540 vty_out(vty, " neighbor %s override-capability\n", addr);
16541
16542 /* strict-capability-match */
16543 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
16544 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
16545
16546 /* Sender side AS path loop detection. */
16547 if (peer->as_path_loop_detection)
16548 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
16549 addr);
16550
16551 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
16552 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
16553
16554 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
16555 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
16556 vty_out(vty,
16557 " neighbor %s graceful-restart-helper\n", addr);
16558 } else if (CHECK_FLAG(
16559 peer->peer_gr_new_status_flag,
16560 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
16561 vty_out(vty,
16562 " neighbor %s graceful-restart\n", addr);
16563 } else if (
16564 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
16565 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
16566 && !(CHECK_FLAG(
16567 peer->peer_gr_new_status_flag,
16568 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
16569 vty_out(vty, " neighbor %s graceful-restart-disable\n",
16570 addr);
16571 }
16572 }
16573 }
16574
16575 /* BGP peer configuration display function. */
16576 static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
16577 struct peer *peer, afi_t afi, safi_t safi)
16578 {
16579 struct peer *g_peer = NULL;
16580 char *addr;
16581 bool flag_scomm, flag_secomm, flag_slcomm;
16582
16583 /* Skip dynamic neighbors. */
16584 if (peer_dynamic_neighbor(peer))
16585 return;
16586
16587 if (peer->conf_if)
16588 addr = peer->conf_if;
16589 else
16590 addr = peer->host;
16591
16592 /************************************
16593 ****** Per AF to the neighbor ******
16594 ************************************/
16595 if (peer_group_active(peer)) {
16596 g_peer = peer->group->conf;
16597
16598 /* If the peer-group is active but peer is not, print a 'no
16599 * activate' */
16600 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
16601 vty_out(vty, " no neighbor %s activate\n", addr);
16602 }
16603
16604 /* If the peer-group is not active but peer is, print an
16605 'activate' */
16606 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
16607 vty_out(vty, " neighbor %s activate\n", addr);
16608 }
16609 } else {
16610 if (peer->afc[afi][safi]) {
16611 if ((afi == AFI_IP) && (safi == SAFI_UNICAST)) {
16612 if (CHECK_FLAG(bgp->flags,
16613 BGP_FLAG_NO_DEFAULT_IPV4)) {
16614 vty_out(vty, " neighbor %s activate\n",
16615 addr);
16616 }
16617 } else
16618 vty_out(vty, " neighbor %s activate\n", addr);
16619 } else {
16620 if ((afi == AFI_IP) && (safi == SAFI_UNICAST)) {
16621 if (!CHECK_FLAG(bgp->flags,
16622 BGP_FLAG_NO_DEFAULT_IPV4)) {
16623 vty_out(vty,
16624 " no neighbor %s activate\n",
16625 addr);
16626 }
16627 }
16628 }
16629 }
16630
16631 /* addpath TX knobs */
16632 if (peergroup_af_addpath_check(peer, afi, safi)) {
16633 switch (peer->addpath_type[afi][safi]) {
16634 case BGP_ADDPATH_ALL:
16635 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
16636 addr);
16637 break;
16638 case BGP_ADDPATH_BEST_PER_AS:
16639 vty_out(vty,
16640 " neighbor %s addpath-tx-bestpath-per-AS\n",
16641 addr);
16642 break;
16643 case BGP_ADDPATH_MAX:
16644 case BGP_ADDPATH_NONE:
16645 break;
16646 }
16647 }
16648
16649 /* ORF capability. */
16650 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
16651 || peergroup_af_flag_check(peer, afi, safi,
16652 PEER_FLAG_ORF_PREFIX_RM)) {
16653 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
16654
16655 if (peergroup_af_flag_check(peer, afi, safi,
16656 PEER_FLAG_ORF_PREFIX_SM)
16657 && peergroup_af_flag_check(peer, afi, safi,
16658 PEER_FLAG_ORF_PREFIX_RM))
16659 vty_out(vty, " both");
16660 else if (peergroup_af_flag_check(peer, afi, safi,
16661 PEER_FLAG_ORF_PREFIX_SM))
16662 vty_out(vty, " send");
16663 else
16664 vty_out(vty, " receive");
16665 vty_out(vty, "\n");
16666 }
16667
16668 /* Route reflector client. */
16669 if (peergroup_af_flag_check(peer, afi, safi,
16670 PEER_FLAG_REFLECTOR_CLIENT)) {
16671 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
16672 }
16673
16674 /* next-hop-self force */
16675 if (peergroup_af_flag_check(peer, afi, safi,
16676 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
16677 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
16678 }
16679
16680 /* next-hop-self */
16681 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
16682 vty_out(vty, " neighbor %s next-hop-self\n", addr);
16683 }
16684
16685 /* remove-private-AS */
16686 if (peergroup_af_flag_check(peer, afi, safi,
16687 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
16688 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
16689 addr);
16690 }
16691
16692 else if (peergroup_af_flag_check(peer, afi, safi,
16693 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
16694 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
16695 addr);
16696 }
16697
16698 else if (peergroup_af_flag_check(peer, afi, safi,
16699 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
16700 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
16701 }
16702
16703 else if (peergroup_af_flag_check(peer, afi, safi,
16704 PEER_FLAG_REMOVE_PRIVATE_AS)) {
16705 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
16706 }
16707
16708 /* as-override */
16709 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
16710 vty_out(vty, " neighbor %s as-override\n", addr);
16711 }
16712
16713 /* send-community print. */
16714 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
16715 PEER_FLAG_SEND_COMMUNITY);
16716 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
16717 PEER_FLAG_SEND_EXT_COMMUNITY);
16718 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
16719 PEER_FLAG_SEND_LARGE_COMMUNITY);
16720
16721 if (flag_scomm && flag_secomm && flag_slcomm) {
16722 vty_out(vty, " no neighbor %s send-community all\n", addr);
16723 } else {
16724 if (flag_scomm)
16725 vty_out(vty, " no neighbor %s send-community\n", addr);
16726 if (flag_secomm)
16727 vty_out(vty,
16728 " no neighbor %s send-community extended\n",
16729 addr);
16730
16731 if (flag_slcomm)
16732 vty_out(vty, " no neighbor %s send-community large\n",
16733 addr);
16734 }
16735
16736 /* Default information */
16737 if (peergroup_af_flag_check(peer, afi, safi,
16738 PEER_FLAG_DEFAULT_ORIGINATE)) {
16739 vty_out(vty, " neighbor %s default-originate", addr);
16740
16741 if (peer->default_rmap[afi][safi].name)
16742 vty_out(vty, " route-map %s",
16743 peer->default_rmap[afi][safi].name);
16744
16745 vty_out(vty, "\n");
16746 }
16747
16748 /* Soft reconfiguration inbound. */
16749 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
16750 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
16751 addr);
16752 }
16753
16754 /* maximum-prefix. */
16755 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
16756 vty_out(vty, " neighbor %s maximum-prefix %u", addr,
16757 peer->pmax[afi][safi]);
16758
16759 if (peer->pmax_threshold[afi][safi]
16760 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
16761 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
16762 if (peer_af_flag_check(peer, afi, safi,
16763 PEER_FLAG_MAX_PREFIX_WARNING))
16764 vty_out(vty, " warning-only");
16765 if (peer->pmax_restart[afi][safi])
16766 vty_out(vty, " restart %u",
16767 peer->pmax_restart[afi][safi]);
16768 if (peer_af_flag_check(peer, afi, safi,
16769 PEER_FLAG_MAX_PREFIX_FORCE))
16770 vty_out(vty, " force");
16771
16772 vty_out(vty, "\n");
16773 }
16774
16775 /* maximum-prefix-out */
16776 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
16777 vty_out(vty, " neighbor %s maximum-prefix-out %u\n",
16778 addr, peer->pmax_out[afi][safi]);
16779
16780 /* Route server client. */
16781 if (peergroup_af_flag_check(peer, afi, safi,
16782 PEER_FLAG_RSERVER_CLIENT)) {
16783 vty_out(vty, " neighbor %s route-server-client\n", addr);
16784 }
16785
16786 /* Nexthop-local unchanged. */
16787 if (peergroup_af_flag_check(peer, afi, safi,
16788 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
16789 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
16790 }
16791
16792 /* allowas-in <1-10> */
16793 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
16794 if (peer_af_flag_check(peer, afi, safi,
16795 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
16796 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
16797 } else if (peer->allowas_in[afi][safi] == 3) {
16798 vty_out(vty, " neighbor %s allowas-in\n", addr);
16799 } else {
16800 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
16801 peer->allowas_in[afi][safi]);
16802 }
16803 }
16804
16805 /* weight */
16806 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
16807 vty_out(vty, " neighbor %s weight %lu\n", addr,
16808 peer->weight[afi][safi]);
16809
16810 /* Filter. */
16811 bgp_config_write_filter(vty, peer, afi, safi);
16812
16813 /* atribute-unchanged. */
16814 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
16815 || (safi != SAFI_EVPN
16816 && peer_af_flag_check(peer, afi, safi,
16817 PEER_FLAG_NEXTHOP_UNCHANGED))
16818 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
16819
16820 if (!peer_group_active(peer)
16821 || peergroup_af_flag_check(peer, afi, safi,
16822 PEER_FLAG_AS_PATH_UNCHANGED)
16823 || peergroup_af_flag_check(peer, afi, safi,
16824 PEER_FLAG_NEXTHOP_UNCHANGED)
16825 || peergroup_af_flag_check(peer, afi, safi,
16826 PEER_FLAG_MED_UNCHANGED)) {
16827
16828 vty_out(vty,
16829 " neighbor %s attribute-unchanged%s%s%s\n",
16830 addr,
16831 peer_af_flag_check(peer, afi, safi,
16832 PEER_FLAG_AS_PATH_UNCHANGED)
16833 ? " as-path"
16834 : "",
16835 peer_af_flag_check(peer, afi, safi,
16836 PEER_FLAG_NEXTHOP_UNCHANGED)
16837 ? " next-hop"
16838 : "",
16839 peer_af_flag_check(peer, afi, safi,
16840 PEER_FLAG_MED_UNCHANGED)
16841 ? " med"
16842 : "");
16843 }
16844 }
16845 }
16846
16847 /* Address family based peer configuration display. */
16848 static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
16849 safi_t safi)
16850 {
16851 struct peer *peer;
16852 struct peer_group *group;
16853 struct listnode *node, *nnode;
16854
16855
16856 vty_frame(vty, " !\n address-family ");
16857 if (afi == AFI_IP) {
16858 if (safi == SAFI_UNICAST)
16859 vty_frame(vty, "ipv4 unicast");
16860 else if (safi == SAFI_LABELED_UNICAST)
16861 vty_frame(vty, "ipv4 labeled-unicast");
16862 else if (safi == SAFI_MULTICAST)
16863 vty_frame(vty, "ipv4 multicast");
16864 else if (safi == SAFI_MPLS_VPN)
16865 vty_frame(vty, "ipv4 vpn");
16866 else if (safi == SAFI_ENCAP)
16867 vty_frame(vty, "ipv4 encap");
16868 else if (safi == SAFI_FLOWSPEC)
16869 vty_frame(vty, "ipv4 flowspec");
16870 } else if (afi == AFI_IP6) {
16871 if (safi == SAFI_UNICAST)
16872 vty_frame(vty, "ipv6 unicast");
16873 else if (safi == SAFI_LABELED_UNICAST)
16874 vty_frame(vty, "ipv6 labeled-unicast");
16875 else if (safi == SAFI_MULTICAST)
16876 vty_frame(vty, "ipv6 multicast");
16877 else if (safi == SAFI_MPLS_VPN)
16878 vty_frame(vty, "ipv6 vpn");
16879 else if (safi == SAFI_ENCAP)
16880 vty_frame(vty, "ipv6 encap");
16881 else if (safi == SAFI_FLOWSPEC)
16882 vty_frame(vty, "ipv6 flowspec");
16883 } else if (afi == AFI_L2VPN) {
16884 if (safi == SAFI_EVPN)
16885 vty_frame(vty, "l2vpn evpn");
16886 }
16887 vty_frame(vty, "\n");
16888
16889 bgp_config_write_distance(vty, bgp, afi, safi);
16890
16891 bgp_config_write_network(vty, bgp, afi, safi);
16892
16893 bgp_config_write_redistribute(vty, bgp, afi, safi);
16894
16895 /* BGP flag dampening. */
16896 if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
16897 bgp_config_write_damp(vty, afi, safi);
16898
16899 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
16900 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
16901
16902 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
16903 /* Skip dynamic neighbors. */
16904 if (peer_dynamic_neighbor(peer))
16905 continue;
16906
16907 /* Do not display doppelganger peers */
16908 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
16909 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
16910 }
16911
16912 bgp_config_write_maxpaths(vty, bgp, afi, safi);
16913 bgp_config_write_table_map(vty, bgp, afi, safi);
16914
16915 if (safi == SAFI_EVPN)
16916 bgp_config_write_evpn_info(vty, bgp, afi, safi);
16917
16918 if (safi == SAFI_FLOWSPEC)
16919 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
16920
16921 if (safi == SAFI_UNICAST) {
16922 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
16923 if (CHECK_FLAG(bgp->af_flags[afi][safi],
16924 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
16925
16926 vty_out(vty, " export vpn\n");
16927 }
16928 if (CHECK_FLAG(bgp->af_flags[afi][safi],
16929 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
16930
16931 vty_out(vty, " import vpn\n");
16932 }
16933 if (CHECK_FLAG(bgp->af_flags[afi][safi],
16934 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
16935 char *name;
16936
16937 for (ALL_LIST_ELEMENTS_RO(
16938 bgp->vpn_policy[afi].import_vrf, node,
16939 name))
16940 vty_out(vty, " import vrf %s\n", name);
16941 }
16942 }
16943
16944 vty_endframe(vty, " exit-address-family\n");
16945 }
16946
16947 int bgp_config_write(struct vty *vty)
16948 {
16949 struct bgp *bgp;
16950 struct peer_group *group;
16951 struct peer *peer;
16952 struct listnode *node, *nnode;
16953 struct listnode *mnode, *mnnode;
16954
16955 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
16956 vty_out(vty, "bgp route-map delay-timer %u\n",
16957 bm->rmap_update_timer);
16958
16959 if (bm->v_update_delay != BGP_UPDATE_DELAY_DEF) {
16960 vty_out(vty, "bgp update-delay %d", bm->v_update_delay);
16961 if (bm->v_update_delay != bm->v_establish_wait)
16962 vty_out(vty, " %d", bm->v_establish_wait);
16963 vty_out(vty, "\n");
16964 }
16965
16966 if (bm->wait_for_fib)
16967 vty_out(vty, "bgp suppress-fib-pending\n");
16968
16969 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
16970 vty_out(vty, "bgp graceful-shutdown\n");
16971
16972 /* No-RIB (Zebra) option flag configuration */
16973 if (bgp_option_check(BGP_OPT_NO_FIB))
16974 vty_out(vty, "bgp no-rib\n");
16975
16976 if (!CHECK_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA))
16977 vty_out(vty, "no bgp send-extra-data zebra\n");
16978
16979 /* BGP configuration. */
16980 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
16981
16982 /* skip all auto created vrf as they dont have user config */
16983 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
16984 continue;
16985
16986 /* Router bgp ASN */
16987 vty_out(vty, "router bgp %u", bgp->as);
16988
16989 if (bgp->name)
16990 vty_out(vty, " %s %s",
16991 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
16992 ? "view" : "vrf", bgp->name);
16993 vty_out(vty, "\n");
16994
16995 /* BGP fast-external-failover. */
16996 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
16997 vty_out(vty, " no bgp fast-external-failover\n");
16998
16999 /* BGP router ID. */
17000 if (bgp->router_id_static.s_addr != INADDR_ANY)
17001 vty_out(vty, " bgp router-id %pI4\n",
17002 &bgp->router_id_static);
17003
17004 /* Suppress fib pending */
17005 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_FIB_PENDING))
17006 vty_out(vty, " bgp suppress-fib-pending\n");
17007
17008 /* BGP log-neighbor-changes. */
17009 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
17010 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
17011 vty_out(vty, " %sbgp log-neighbor-changes\n",
17012 CHECK_FLAG(bgp->flags,
17013 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
17014 ? ""
17015 : "no ");
17016
17017 /* BGP configuration. */
17018 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
17019 vty_out(vty, " bgp always-compare-med\n");
17020
17021 /* RFC8212 default eBGP policy. */
17022 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
17023 != SAVE_BGP_EBGP_REQUIRES_POLICY)
17024 vty_out(vty, " %sbgp ebgp-requires-policy\n",
17025 CHECK_FLAG(bgp->flags,
17026 BGP_FLAG_EBGP_REQUIRES_POLICY)
17027 ? ""
17028 : "no ");
17029
17030 /* draft-ietf-idr-deprecate-as-set-confed-set */
17031 if (bgp->reject_as_sets)
17032 vty_out(vty, " bgp reject-as-sets\n");
17033
17034 /* BGP default ipv4-unicast. */
17035 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4))
17036 vty_out(vty, " no bgp default ipv4-unicast\n");
17037
17038 /* BGP default local-preference. */
17039 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
17040 vty_out(vty, " bgp default local-preference %u\n",
17041 bgp->default_local_pref);
17042
17043 /* BGP default show-hostname */
17044 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
17045 != SAVE_BGP_SHOW_HOSTNAME)
17046 vty_out(vty, " %sbgp default show-hostname\n",
17047 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
17048 ? ""
17049 : "no ");
17050
17051 /* BGP default show-nexthop-hostname */
17052 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17053 != SAVE_BGP_SHOW_HOSTNAME)
17054 vty_out(vty, " %sbgp default show-nexthop-hostname\n",
17055 CHECK_FLAG(bgp->flags,
17056 BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17057 ? ""
17058 : "no ");
17059
17060 /* BGP default subgroup-pkt-queue-max. */
17061 if (bgp->default_subgroup_pkt_queue_max
17062 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
17063 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
17064 bgp->default_subgroup_pkt_queue_max);
17065
17066 /* BGP client-to-client reflection. */
17067 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
17068 vty_out(vty, " no bgp client-to-client reflection\n");
17069
17070 /* BGP cluster ID. */
17071 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
17072 vty_out(vty, " bgp cluster-id %pI4\n",
17073 &bgp->cluster_id);
17074
17075 /* Disable ebgp connected nexthop check */
17076 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
17077 vty_out(vty,
17078 " bgp disable-ebgp-connected-route-check\n");
17079
17080 /* Confederation identifier*/
17081 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
17082 vty_out(vty, " bgp confederation identifier %u\n",
17083 bgp->confed_id);
17084
17085 /* Confederation peer */
17086 if (bgp->confed_peers_cnt > 0) {
17087 int i;
17088
17089 vty_out(vty, " bgp confederation peers");
17090
17091 for (i = 0; i < bgp->confed_peers_cnt; i++)
17092 vty_out(vty, " %u", bgp->confed_peers[i]);
17093
17094 vty_out(vty, "\n");
17095 }
17096
17097 /* BGP deterministic-med. */
17098 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
17099 != SAVE_BGP_DETERMINISTIC_MED)
17100 vty_out(vty, " %sbgp deterministic-med\n",
17101 CHECK_FLAG(bgp->flags,
17102 BGP_FLAG_DETERMINISTIC_MED)
17103 ? ""
17104 : "no ");
17105
17106 /* BGP update-delay. */
17107 bgp_config_write_update_delay(vty, bgp);
17108
17109 if (bgp->v_maxmed_onstartup
17110 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
17111 vty_out(vty, " bgp max-med on-startup %u",
17112 bgp->v_maxmed_onstartup);
17113 if (bgp->maxmed_onstartup_value
17114 != BGP_MAXMED_VALUE_DEFAULT)
17115 vty_out(vty, " %u",
17116 bgp->maxmed_onstartup_value);
17117 vty_out(vty, "\n");
17118 }
17119 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
17120 vty_out(vty, " bgp max-med administrative");
17121 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
17122 vty_out(vty, " %u", bgp->maxmed_admin_value);
17123 vty_out(vty, "\n");
17124 }
17125
17126 /* write quanta */
17127 bgp_config_write_wpkt_quanta(vty, bgp);
17128 /* read quanta */
17129 bgp_config_write_rpkt_quanta(vty, bgp);
17130
17131 /* coalesce time */
17132 bgp_config_write_coalesce_time(vty, bgp);
17133
17134 /* BGP per-instance graceful-shutdown */
17135 /* BGP-wide settings and per-instance settings are mutually
17136 * exclusive.
17137 */
17138 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17139 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
17140 vty_out(vty, " bgp graceful-shutdown\n");
17141
17142 /* BGP graceful-restart. */
17143 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
17144 vty_out(vty,
17145 " bgp graceful-restart stalepath-time %u\n",
17146 bgp->stalepath_time);
17147
17148 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
17149 vty_out(vty, " bgp graceful-restart restart-time %u\n",
17150 bgp->restart_time);
17151
17152 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
17153 vty_out(vty,
17154 " bgp graceful-restart select-defer-time %u\n",
17155 bgp->select_defer_time);
17156
17157 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
17158 vty_out(vty, " bgp graceful-restart\n");
17159
17160 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
17161 vty_out(vty, " bgp graceful-restart-disable\n");
17162
17163 /* BGP graceful-restart Preserve State F bit. */
17164 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
17165 vty_out(vty,
17166 " bgp graceful-restart preserve-fw-state\n");
17167
17168 /* Stale timer for RIB */
17169 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
17170 vty_out(vty,
17171 " bgp graceful-restart rib-stale-time %u\n",
17172 bgp->rib_stale_time);
17173
17174 /* BGP bestpath method. */
17175 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
17176 vty_out(vty, " bgp bestpath as-path ignore\n");
17177 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
17178 vty_out(vty, " bgp bestpath as-path confed\n");
17179
17180 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
17181 if (CHECK_FLAG(bgp->flags,
17182 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
17183 vty_out(vty,
17184 " bgp bestpath as-path multipath-relax as-set\n");
17185 } else {
17186 vty_out(vty,
17187 " bgp bestpath as-path multipath-relax\n");
17188 }
17189 }
17190
17191 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
17192 vty_out(vty,
17193 " bgp route-reflector allow-outbound-policy\n");
17194 }
17195 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
17196 vty_out(vty, " bgp bestpath compare-routerid\n");
17197 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
17198 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
17199 vty_out(vty, " bgp bestpath med");
17200 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
17201 vty_out(vty, " confed");
17202 if (CHECK_FLAG(bgp->flags,
17203 BGP_FLAG_MED_MISSING_AS_WORST))
17204 vty_out(vty, " missing-as-worst");
17205 vty_out(vty, "\n");
17206 }
17207
17208 /* Link bandwidth handling. */
17209 if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW)
17210 vty_out(vty, " bgp bestpath bandwidth ignore\n");
17211 else if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
17212 vty_out(vty, " bgp bestpath bandwidth skip-missing\n");
17213 else if (bgp->lb_handling == BGP_LINK_BW_DEFWT_4_MISSING)
17214 vty_out(vty, " bgp bestpath bandwidth default-weight-for-missing\n");
17215
17216 /* BGP network import check. */
17217 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
17218 != SAVE_BGP_IMPORT_CHECK)
17219 vty_out(vty, " %sbgp network import-check\n",
17220 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
17221 ? ""
17222 : "no ");
17223
17224 /* BGP timers configuration. */
17225 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
17226 && bgp->default_holdtime != SAVE_BGP_HOLDTIME)
17227 vty_out(vty, " timers bgp %u %u\n",
17228 bgp->default_keepalive, bgp->default_holdtime);
17229
17230 /* peer-group */
17231 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
17232 bgp_config_write_peer_global(vty, bgp, group->conf);
17233 }
17234
17235 /* Normal neighbor configuration. */
17236 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17237 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17238 bgp_config_write_peer_global(vty, bgp, peer);
17239 }
17240
17241 /* listen range and limit for dynamic BGP neighbors */
17242 bgp_config_write_listen(vty, bgp);
17243
17244 /*
17245 * BGP default autoshutdown neighbors
17246 *
17247 * This must be placed after any peer and peer-group
17248 * configuration, to avoid setting all peers to shutdown after
17249 * a daemon restart, which is undesired behavior. (see #2286)
17250 */
17251 if (bgp->autoshutdown)
17252 vty_out(vty, " bgp default shutdown\n");
17253
17254 /* BGP instance administrative shutdown */
17255 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN))
17256 vty_out(vty, " bgp shutdown\n");
17257
17258 /* IPv4 unicast configuration. */
17259 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
17260
17261 /* IPv4 multicast configuration. */
17262 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
17263
17264 /* IPv4 labeled-unicast configuration. */
17265 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
17266
17267 /* IPv4 VPN configuration. */
17268 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
17269
17270 /* ENCAPv4 configuration. */
17271 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
17272
17273 /* FLOWSPEC v4 configuration. */
17274 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
17275
17276 /* IPv6 unicast configuration. */
17277 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
17278
17279 /* IPv6 multicast configuration. */
17280 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
17281
17282 /* IPv6 labeled-unicast configuration. */
17283 bgp_config_write_family(vty, bgp, AFI_IP6,
17284 SAFI_LABELED_UNICAST);
17285
17286 /* IPv6 VPN configuration. */
17287 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
17288
17289 /* ENCAPv6 configuration. */
17290 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
17291
17292 /* FLOWSPEC v6 configuration. */
17293 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
17294
17295 /* EVPN configuration. */
17296 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
17297
17298 hook_call(bgp_inst_config_write, bgp, vty);
17299
17300 #ifdef ENABLE_BGP_VNC
17301 bgp_rfapi_cfg_write(vty, bgp);
17302 #endif
17303
17304 vty_out(vty, "!\n");
17305 }
17306 return 0;
17307 }
17308
17309
17310 /* BGP node structure. */
17311 static struct cmd_node bgp_node = {
17312 .name = "bgp",
17313 .node = BGP_NODE,
17314 .parent_node = CONFIG_NODE,
17315 .prompt = "%s(config-router)# ",
17316 .config_write = bgp_config_write,
17317 };
17318
17319 static struct cmd_node bgp_ipv4_unicast_node = {
17320 .name = "bgp ipv4 unicast",
17321 .node = BGP_IPV4_NODE,
17322 .parent_node = BGP_NODE,
17323 .prompt = "%s(config-router-af)# ",
17324 };
17325
17326 static struct cmd_node bgp_ipv4_multicast_node = {
17327 .name = "bgp ipv4 multicast",
17328 .node = BGP_IPV4M_NODE,
17329 .parent_node = BGP_NODE,
17330 .prompt = "%s(config-router-af)# ",
17331 };
17332
17333 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
17334 .name = "bgp ipv4 labeled unicast",
17335 .node = BGP_IPV4L_NODE,
17336 .parent_node = BGP_NODE,
17337 .prompt = "%s(config-router-af)# ",
17338 };
17339
17340 static struct cmd_node bgp_ipv6_unicast_node = {
17341 .name = "bgp ipv6",
17342 .node = BGP_IPV6_NODE,
17343 .parent_node = BGP_NODE,
17344 .prompt = "%s(config-router-af)# ",
17345 };
17346
17347 static struct cmd_node bgp_ipv6_multicast_node = {
17348 .name = "bgp ipv6 multicast",
17349 .node = BGP_IPV6M_NODE,
17350 .parent_node = BGP_NODE,
17351 .prompt = "%s(config-router-af)# ",
17352 };
17353
17354 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
17355 .name = "bgp ipv6 labeled unicast",
17356 .node = BGP_IPV6L_NODE,
17357 .parent_node = BGP_NODE,
17358 .prompt = "%s(config-router-af)# ",
17359 };
17360
17361 static struct cmd_node bgp_vpnv4_node = {
17362 .name = "bgp vpnv4",
17363 .node = BGP_VPNV4_NODE,
17364 .parent_node = BGP_NODE,
17365 .prompt = "%s(config-router-af)# ",
17366 };
17367
17368 static struct cmd_node bgp_vpnv6_node = {
17369 .name = "bgp vpnv6",
17370 .node = BGP_VPNV6_NODE,
17371 .parent_node = BGP_NODE,
17372 .prompt = "%s(config-router-af-vpnv6)# ",
17373 };
17374
17375 static struct cmd_node bgp_evpn_node = {
17376 .name = "bgp evpn",
17377 .node = BGP_EVPN_NODE,
17378 .parent_node = BGP_NODE,
17379 .prompt = "%s(config-router-evpn)# ",
17380 };
17381
17382 static struct cmd_node bgp_evpn_vni_node = {
17383 .name = "bgp evpn vni",
17384 .node = BGP_EVPN_VNI_NODE,
17385 .parent_node = BGP_EVPN_NODE,
17386 .prompt = "%s(config-router-af-vni)# ",
17387 };
17388
17389 static struct cmd_node bgp_flowspecv4_node = {
17390 .name = "bgp ipv4 flowspec",
17391 .node = BGP_FLOWSPECV4_NODE,
17392 .parent_node = BGP_NODE,
17393 .prompt = "%s(config-router-af)# ",
17394 };
17395
17396 static struct cmd_node bgp_flowspecv6_node = {
17397 .name = "bgp ipv6 flowspec",
17398 .node = BGP_FLOWSPECV6_NODE,
17399 .parent_node = BGP_NODE,
17400 .prompt = "%s(config-router-af-vpnv6)# ",
17401 };
17402
17403 static void community_list_vty(void);
17404
17405 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
17406 {
17407 struct bgp *bgp;
17408 struct peer *peer;
17409 struct listnode *lnbgp, *lnpeer;
17410
17411 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
17412 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
17413 /* only provide suggestions on the appropriate input
17414 * token type,
17415 * they'll otherwise show up multiple times */
17416 enum cmd_token_type match_type;
17417 char *name = peer->host;
17418
17419 if (peer->conf_if) {
17420 match_type = VARIABLE_TKN;
17421 name = peer->conf_if;
17422 } else if (strchr(peer->host, ':'))
17423 match_type = IPV6_TKN;
17424 else
17425 match_type = IPV4_TKN;
17426
17427 if (token->type != match_type)
17428 continue;
17429
17430 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
17431 }
17432 }
17433 }
17434
17435 static const struct cmd_variable_handler bgp_var_neighbor[] = {
17436 {.varname = "neighbor", .completions = bgp_ac_neighbor},
17437 {.varname = "neighbors", .completions = bgp_ac_neighbor},
17438 {.varname = "peer", .completions = bgp_ac_neighbor},
17439 {.completions = NULL}};
17440
17441 static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
17442 {
17443 struct bgp *bgp;
17444 struct peer_group *group;
17445 struct listnode *lnbgp, *lnpeer;
17446
17447 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
17448 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
17449 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
17450 group->name));
17451 }
17452 }
17453
17454 static const struct cmd_variable_handler bgp_var_peergroup[] = {
17455 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
17456 {.completions = NULL} };
17457
17458 void bgp_vty_init(void)
17459 {
17460 cmd_variable_handler_register(bgp_var_neighbor);
17461 cmd_variable_handler_register(bgp_var_peergroup);
17462
17463 /* Install bgp top node. */
17464 install_node(&bgp_node);
17465 install_node(&bgp_ipv4_unicast_node);
17466 install_node(&bgp_ipv4_multicast_node);
17467 install_node(&bgp_ipv4_labeled_unicast_node);
17468 install_node(&bgp_ipv6_unicast_node);
17469 install_node(&bgp_ipv6_multicast_node);
17470 install_node(&bgp_ipv6_labeled_unicast_node);
17471 install_node(&bgp_vpnv4_node);
17472 install_node(&bgp_vpnv6_node);
17473 install_node(&bgp_evpn_node);
17474 install_node(&bgp_evpn_vni_node);
17475 install_node(&bgp_flowspecv4_node);
17476 install_node(&bgp_flowspecv6_node);
17477
17478 /* Install default VTY commands to new nodes. */
17479 install_default(BGP_NODE);
17480 install_default(BGP_IPV4_NODE);
17481 install_default(BGP_IPV4M_NODE);
17482 install_default(BGP_IPV4L_NODE);
17483 install_default(BGP_IPV6_NODE);
17484 install_default(BGP_IPV6M_NODE);
17485 install_default(BGP_IPV6L_NODE);
17486 install_default(BGP_VPNV4_NODE);
17487 install_default(BGP_VPNV6_NODE);
17488 install_default(BGP_FLOWSPECV4_NODE);
17489 install_default(BGP_FLOWSPECV6_NODE);
17490 install_default(BGP_EVPN_NODE);
17491 install_default(BGP_EVPN_VNI_NODE);
17492
17493 /* "bgp local-mac" hidden commands. */
17494 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
17495 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
17496
17497 /* "bgp suppress-fib-pending" global */
17498 install_element(CONFIG_NODE, &bgp_global_suppress_fib_pending_cmd);
17499
17500 /* bgp route-map delay-timer commands. */
17501 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
17502 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
17503
17504 /* global bgp update-delay command */
17505 install_element(CONFIG_NODE, &bgp_global_update_delay_cmd);
17506 install_element(CONFIG_NODE, &no_bgp_global_update_delay_cmd);
17507
17508 /* global bgp graceful-shutdown command */
17509 install_element(CONFIG_NODE, &bgp_graceful_shutdown_cmd);
17510 install_element(CONFIG_NODE, &no_bgp_graceful_shutdown_cmd);
17511
17512 /* Dummy commands (Currently not supported) */
17513 install_element(BGP_NODE, &no_synchronization_cmd);
17514 install_element(BGP_NODE, &no_auto_summary_cmd);
17515
17516 /* "router bgp" commands. */
17517 install_element(CONFIG_NODE, &router_bgp_cmd);
17518
17519 /* "no router bgp" commands. */
17520 install_element(CONFIG_NODE, &no_router_bgp_cmd);
17521
17522 /* "bgp router-id" commands. */
17523 install_element(BGP_NODE, &bgp_router_id_cmd);
17524 install_element(BGP_NODE, &no_bgp_router_id_cmd);
17525
17526 /* "bgp suppress-fib-pending" command */
17527 install_element(BGP_NODE, &bgp_suppress_fib_pending_cmd);
17528
17529 /* "bgp cluster-id" commands. */
17530 install_element(BGP_NODE, &bgp_cluster_id_cmd);
17531 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
17532
17533 /* "bgp no-rib" commands. */
17534 install_element(CONFIG_NODE, &bgp_norib_cmd);
17535 install_element(CONFIG_NODE, &no_bgp_norib_cmd);
17536
17537 install_element(CONFIG_NODE, &no_bgp_send_extra_data_cmd);
17538
17539 /* "bgp confederation" commands. */
17540 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
17541 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
17542
17543 /* "bgp confederation peers" commands. */
17544 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
17545 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
17546
17547 /* bgp max-med command */
17548 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
17549 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
17550 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
17551 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
17552 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
17553
17554 /* bgp disable-ebgp-connected-nh-check */
17555 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
17556 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
17557
17558 /* bgp update-delay command */
17559 install_element(BGP_NODE, &bgp_update_delay_cmd);
17560 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
17561
17562 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
17563 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
17564
17565 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
17566 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
17567
17568 /* "maximum-paths" commands. */
17569 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
17570 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
17571 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
17572 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
17573 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
17574 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
17575 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
17576 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
17577 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
17578 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
17579 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17580 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
17581 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
17582 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17583 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
17584
17585 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_cmd);
17586 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_cmd);
17587 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cmd);
17588 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17589 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_ibgp_cmd);
17590 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
17591 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
17592 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
17593 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17594 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
17595
17596 /* "timers bgp" commands. */
17597 install_element(BGP_NODE, &bgp_timers_cmd);
17598 install_element(BGP_NODE, &no_bgp_timers_cmd);
17599
17600 /* route-map delay-timer commands - per instance for backwards compat.
17601 */
17602 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
17603 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
17604
17605 /* "bgp client-to-client reflection" commands */
17606 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
17607 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
17608
17609 /* "bgp always-compare-med" commands */
17610 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
17611 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
17612
17613 /* bgp ebgp-requires-policy */
17614 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
17615 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
17616
17617 /* bgp reject-as-sets */
17618 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
17619 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
17620
17621 /* "bgp deterministic-med" commands */
17622 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
17623 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
17624
17625 /* "bgp graceful-restart" command */
17626 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
17627 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
17628
17629 /* "bgp graceful-restart-disable" command */
17630 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
17631 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
17632
17633 /* "neighbor a:b:c:d graceful-restart" command */
17634 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
17635 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
17636
17637 /* "neighbor a:b:c:d graceful-restart-disable" command */
17638 install_element(BGP_NODE,
17639 &bgp_neighbor_graceful_restart_disable_set_cmd);
17640 install_element(BGP_NODE,
17641 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
17642
17643 /* "neighbor a:b:c:d graceful-restart-helper" command */
17644 install_element(BGP_NODE,
17645 &bgp_neighbor_graceful_restart_helper_set_cmd);
17646 install_element(BGP_NODE,
17647 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
17648
17649 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
17650 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
17651 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
17652 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
17653 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
17654 install_element(BGP_NODE,
17655 &no_bgp_graceful_restart_select_defer_time_cmd);
17656 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
17657 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
17658
17659 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
17660 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
17661 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
17662 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
17663
17664 /* "bgp graceful-shutdown" commands */
17665 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
17666 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
17667
17668 /* "bgp fast-external-failover" commands */
17669 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
17670 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
17671
17672 /* "bgp bestpath compare-routerid" commands */
17673 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
17674 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
17675
17676 /* "bgp bestpath as-path ignore" commands */
17677 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
17678 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
17679
17680 /* "bgp bestpath as-path confed" commands */
17681 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
17682 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
17683
17684 /* "bgp bestpath as-path multipath-relax" commands */
17685 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
17686 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
17687
17688 /* "bgp log-neighbor-changes" commands */
17689 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
17690 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
17691
17692 /* "bgp bestpath med" commands */
17693 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
17694 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
17695
17696 /* "bgp bestpath bandwidth" commands */
17697 install_element(BGP_NODE, &bgp_bestpath_bw_cmd);
17698 install_element(BGP_NODE, &no_bgp_bestpath_bw_cmd);
17699
17700 /* "no bgp default ipv4-unicast" commands. */
17701 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
17702 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
17703
17704 /* "bgp network import-check" commands. */
17705 install_element(BGP_NODE, &bgp_network_import_check_cmd);
17706 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
17707 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
17708
17709 /* "bgp default local-preference" commands. */
17710 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
17711 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
17712
17713 /* bgp default show-hostname */
17714 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
17715 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
17716
17717 /* bgp default show-nexthop-hostname */
17718 install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
17719 install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
17720
17721 /* "bgp default subgroup-pkt-queue-max" commands. */
17722 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
17723 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
17724
17725 /* bgp ibgp-allow-policy-mods command */
17726 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
17727 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
17728
17729 /* "bgp listen limit" commands. */
17730 install_element(BGP_NODE, &bgp_listen_limit_cmd);
17731 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
17732
17733 /* "bgp listen range" commands. */
17734 install_element(BGP_NODE, &bgp_listen_range_cmd);
17735 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
17736
17737 /* "bgp default shutdown" command */
17738 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
17739
17740 /* "bgp shutdown" commands */
17741 install_element(BGP_NODE, &bgp_shutdown_cmd);
17742 install_element(BGP_NODE, &bgp_shutdown_msg_cmd);
17743 install_element(BGP_NODE, &no_bgp_shutdown_cmd);
17744 install_element(BGP_NODE, &no_bgp_shutdown_msg_cmd);
17745
17746 /* "neighbor remote-as" commands. */
17747 install_element(BGP_NODE, &neighbor_remote_as_cmd);
17748 install_element(BGP_NODE, &neighbor_interface_config_cmd);
17749 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
17750 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
17751 install_element(BGP_NODE,
17752 &neighbor_interface_v6only_config_remote_as_cmd);
17753 install_element(BGP_NODE, &no_neighbor_cmd);
17754 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
17755
17756 /* "neighbor peer-group" commands. */
17757 install_element(BGP_NODE, &neighbor_peer_group_cmd);
17758 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
17759 install_element(BGP_NODE,
17760 &no_neighbor_interface_peer_group_remote_as_cmd);
17761
17762 /* "neighbor local-as" commands. */
17763 install_element(BGP_NODE, &neighbor_local_as_cmd);
17764 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
17765 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
17766 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
17767
17768 /* "neighbor solo" commands. */
17769 install_element(BGP_NODE, &neighbor_solo_cmd);
17770 install_element(BGP_NODE, &no_neighbor_solo_cmd);
17771
17772 /* "neighbor password" commands. */
17773 install_element(BGP_NODE, &neighbor_password_cmd);
17774 install_element(BGP_NODE, &no_neighbor_password_cmd);
17775
17776 /* "neighbor activate" commands. */
17777 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
17778 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
17779 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
17780 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
17781 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
17782 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
17783 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
17784 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
17785 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
17786 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
17787 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
17788 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
17789
17790 /* "no neighbor activate" commands. */
17791 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
17792 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
17793 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
17794 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
17795 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
17796 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
17797 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
17798 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
17799 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
17800 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
17801 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
17802 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
17803
17804 /* "neighbor peer-group" set commands. */
17805 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
17806 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
17807 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
17808 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
17809 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
17810 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
17811 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
17812 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
17813 install_element(BGP_FLOWSPECV4_NODE,
17814 &neighbor_set_peer_group_hidden_cmd);
17815 install_element(BGP_FLOWSPECV6_NODE,
17816 &neighbor_set_peer_group_hidden_cmd);
17817
17818 /* "no neighbor peer-group unset" commands. */
17819 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
17820 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17821 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17822 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17823 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17824 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17825 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17826 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17827 install_element(BGP_FLOWSPECV4_NODE,
17828 &no_neighbor_set_peer_group_hidden_cmd);
17829 install_element(BGP_FLOWSPECV6_NODE,
17830 &no_neighbor_set_peer_group_hidden_cmd);
17831
17832 /* "neighbor softreconfiguration inbound" commands.*/
17833 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
17834 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
17835 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
17836 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
17837 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
17838 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
17839 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
17840 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
17841 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
17842 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
17843 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
17844 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
17845 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
17846 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
17847 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
17848 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
17849 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
17850 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
17851 install_element(BGP_FLOWSPECV4_NODE,
17852 &neighbor_soft_reconfiguration_cmd);
17853 install_element(BGP_FLOWSPECV4_NODE,
17854 &no_neighbor_soft_reconfiguration_cmd);
17855 install_element(BGP_FLOWSPECV6_NODE,
17856 &neighbor_soft_reconfiguration_cmd);
17857 install_element(BGP_FLOWSPECV6_NODE,
17858 &no_neighbor_soft_reconfiguration_cmd);
17859 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
17860 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
17861
17862 /* "neighbor attribute-unchanged" commands. */
17863 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
17864 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
17865 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
17866 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
17867 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
17868 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
17869 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
17870 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
17871 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
17872 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
17873 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
17874 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
17875 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
17876 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
17877 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
17878 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
17879 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
17880 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
17881
17882 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
17883 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
17884
17885 /* "nexthop-local unchanged" commands */
17886 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
17887 install_element(BGP_IPV6_NODE,
17888 &no_neighbor_nexthop_local_unchanged_cmd);
17889
17890 /* "neighbor next-hop-self" commands. */
17891 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
17892 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
17893 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
17894 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
17895 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
17896 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
17897 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
17898 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
17899 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
17900 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
17901 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
17902 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
17903 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
17904 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
17905 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
17906 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
17907 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
17908 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
17909 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
17910 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
17911
17912 /* "neighbor next-hop-self force" commands. */
17913 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
17914 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
17915 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
17916 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
17917 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
17918 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
17919 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
17920 install_element(BGP_IPV4_NODE,
17921 &no_neighbor_nexthop_self_all_hidden_cmd);
17922 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
17923 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
17924 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
17925 install_element(BGP_IPV4M_NODE,
17926 &no_neighbor_nexthop_self_all_hidden_cmd);
17927 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
17928 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
17929 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
17930 install_element(BGP_IPV4L_NODE,
17931 &no_neighbor_nexthop_self_all_hidden_cmd);
17932 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
17933 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
17934 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
17935 install_element(BGP_IPV6_NODE,
17936 &no_neighbor_nexthop_self_all_hidden_cmd);
17937 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
17938 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
17939 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
17940 install_element(BGP_IPV6M_NODE,
17941 &no_neighbor_nexthop_self_all_hidden_cmd);
17942 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
17943 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
17944 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
17945 install_element(BGP_IPV6L_NODE,
17946 &no_neighbor_nexthop_self_all_hidden_cmd);
17947 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
17948 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
17949 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
17950 install_element(BGP_VPNV4_NODE,
17951 &no_neighbor_nexthop_self_all_hidden_cmd);
17952 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
17953 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
17954 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
17955 install_element(BGP_VPNV6_NODE,
17956 &no_neighbor_nexthop_self_all_hidden_cmd);
17957 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_force_cmd);
17958 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_force_cmd);
17959
17960 /* "neighbor as-override" commands. */
17961 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
17962 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
17963 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
17964 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
17965 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
17966 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
17967 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
17968 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
17969 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
17970 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
17971 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
17972 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
17973 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
17974 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
17975 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
17976 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
17977 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
17978 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
17979
17980 /* "neighbor remove-private-AS" commands. */
17981 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
17982 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
17983 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
17984 install_element(BGP_NODE,
17985 &no_neighbor_remove_private_as_all_hidden_cmd);
17986 install_element(BGP_NODE,
17987 &neighbor_remove_private_as_replace_as_hidden_cmd);
17988 install_element(BGP_NODE,
17989 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
17990 install_element(BGP_NODE,
17991 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
17992 install_element(
17993 BGP_NODE,
17994 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
17995 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
17996 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
17997 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
17998 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
17999 install_element(BGP_IPV4_NODE,
18000 &neighbor_remove_private_as_replace_as_cmd);
18001 install_element(BGP_IPV4_NODE,
18002 &no_neighbor_remove_private_as_replace_as_cmd);
18003 install_element(BGP_IPV4_NODE,
18004 &neighbor_remove_private_as_all_replace_as_cmd);
18005 install_element(BGP_IPV4_NODE,
18006 &no_neighbor_remove_private_as_all_replace_as_cmd);
18007 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
18008 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
18009 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
18010 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
18011 install_element(BGP_IPV4M_NODE,
18012 &neighbor_remove_private_as_replace_as_cmd);
18013 install_element(BGP_IPV4M_NODE,
18014 &no_neighbor_remove_private_as_replace_as_cmd);
18015 install_element(BGP_IPV4M_NODE,
18016 &neighbor_remove_private_as_all_replace_as_cmd);
18017 install_element(BGP_IPV4M_NODE,
18018 &no_neighbor_remove_private_as_all_replace_as_cmd);
18019 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
18020 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
18021 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
18022 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
18023 install_element(BGP_IPV4L_NODE,
18024 &neighbor_remove_private_as_replace_as_cmd);
18025 install_element(BGP_IPV4L_NODE,
18026 &no_neighbor_remove_private_as_replace_as_cmd);
18027 install_element(BGP_IPV4L_NODE,
18028 &neighbor_remove_private_as_all_replace_as_cmd);
18029 install_element(BGP_IPV4L_NODE,
18030 &no_neighbor_remove_private_as_all_replace_as_cmd);
18031 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
18032 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
18033 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
18034 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18035 install_element(BGP_IPV6_NODE,
18036 &neighbor_remove_private_as_replace_as_cmd);
18037 install_element(BGP_IPV6_NODE,
18038 &no_neighbor_remove_private_as_replace_as_cmd);
18039 install_element(BGP_IPV6_NODE,
18040 &neighbor_remove_private_as_all_replace_as_cmd);
18041 install_element(BGP_IPV6_NODE,
18042 &no_neighbor_remove_private_as_all_replace_as_cmd);
18043 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
18044 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
18045 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
18046 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
18047 install_element(BGP_IPV6M_NODE,
18048 &neighbor_remove_private_as_replace_as_cmd);
18049 install_element(BGP_IPV6M_NODE,
18050 &no_neighbor_remove_private_as_replace_as_cmd);
18051 install_element(BGP_IPV6M_NODE,
18052 &neighbor_remove_private_as_all_replace_as_cmd);
18053 install_element(BGP_IPV6M_NODE,
18054 &no_neighbor_remove_private_as_all_replace_as_cmd);
18055 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
18056 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
18057 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
18058 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
18059 install_element(BGP_IPV6L_NODE,
18060 &neighbor_remove_private_as_replace_as_cmd);
18061 install_element(BGP_IPV6L_NODE,
18062 &no_neighbor_remove_private_as_replace_as_cmd);
18063 install_element(BGP_IPV6L_NODE,
18064 &neighbor_remove_private_as_all_replace_as_cmd);
18065 install_element(BGP_IPV6L_NODE,
18066 &no_neighbor_remove_private_as_all_replace_as_cmd);
18067 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
18068 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
18069 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
18070 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18071 install_element(BGP_VPNV4_NODE,
18072 &neighbor_remove_private_as_replace_as_cmd);
18073 install_element(BGP_VPNV4_NODE,
18074 &no_neighbor_remove_private_as_replace_as_cmd);
18075 install_element(BGP_VPNV4_NODE,
18076 &neighbor_remove_private_as_all_replace_as_cmd);
18077 install_element(BGP_VPNV4_NODE,
18078 &no_neighbor_remove_private_as_all_replace_as_cmd);
18079 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
18080 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
18081 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
18082 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18083 install_element(BGP_VPNV6_NODE,
18084 &neighbor_remove_private_as_replace_as_cmd);
18085 install_element(BGP_VPNV6_NODE,
18086 &no_neighbor_remove_private_as_replace_as_cmd);
18087 install_element(BGP_VPNV6_NODE,
18088 &neighbor_remove_private_as_all_replace_as_cmd);
18089 install_element(BGP_VPNV6_NODE,
18090 &no_neighbor_remove_private_as_all_replace_as_cmd);
18091
18092 /* "neighbor send-community" commands.*/
18093 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
18094 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
18095 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
18096 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
18097 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
18098 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
18099 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
18100 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
18101 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
18102 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
18103 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
18104 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
18105 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
18106 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
18107 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
18108 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
18109 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
18110 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
18111 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
18112 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
18113 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
18114 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
18115 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
18116 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
18117 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
18118 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
18119 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
18120 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
18121 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
18122 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
18123 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
18124 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
18125 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
18126 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
18127 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
18128 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
18129
18130 /* "neighbor route-reflector" commands.*/
18131 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
18132 install_element(BGP_NODE,
18133 &no_neighbor_route_reflector_client_hidden_cmd);
18134 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
18135 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
18136 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
18137 install_element(BGP_IPV4M_NODE,
18138 &no_neighbor_route_reflector_client_cmd);
18139 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
18140 install_element(BGP_IPV4L_NODE,
18141 &no_neighbor_route_reflector_client_cmd);
18142 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
18143 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
18144 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
18145 install_element(BGP_IPV6M_NODE,
18146 &no_neighbor_route_reflector_client_cmd);
18147 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
18148 install_element(BGP_IPV6L_NODE,
18149 &no_neighbor_route_reflector_client_cmd);
18150 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
18151 install_element(BGP_VPNV4_NODE,
18152 &no_neighbor_route_reflector_client_cmd);
18153 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
18154 install_element(BGP_VPNV6_NODE,
18155 &no_neighbor_route_reflector_client_cmd);
18156 install_element(BGP_FLOWSPECV4_NODE,
18157 &neighbor_route_reflector_client_cmd);
18158 install_element(BGP_FLOWSPECV4_NODE,
18159 &no_neighbor_route_reflector_client_cmd);
18160 install_element(BGP_FLOWSPECV6_NODE,
18161 &neighbor_route_reflector_client_cmd);
18162 install_element(BGP_FLOWSPECV6_NODE,
18163 &no_neighbor_route_reflector_client_cmd);
18164 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
18165 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
18166
18167 /* "neighbor route-server" commands.*/
18168 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
18169 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
18170 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
18171 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
18172 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
18173 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
18174 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
18175 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
18176 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
18177 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
18178 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
18179 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
18180 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
18181 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
18182 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
18183 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
18184 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
18185 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
18186 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
18187 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
18188 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
18189 install_element(BGP_FLOWSPECV4_NODE,
18190 &no_neighbor_route_server_client_cmd);
18191 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
18192 install_element(BGP_FLOWSPECV6_NODE,
18193 &no_neighbor_route_server_client_cmd);
18194
18195 /* "neighbor addpath-tx-all-paths" commands.*/
18196 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
18197 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
18198 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
18199 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18200 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
18201 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18202 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
18203 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18204 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
18205 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18206 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
18207 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18208 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
18209 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18210 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
18211 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18212 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
18213 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18214
18215 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
18216 install_element(BGP_NODE,
18217 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
18218 install_element(BGP_NODE,
18219 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
18220 install_element(BGP_IPV4_NODE,
18221 &neighbor_addpath_tx_bestpath_per_as_cmd);
18222 install_element(BGP_IPV4_NODE,
18223 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18224 install_element(BGP_IPV4M_NODE,
18225 &neighbor_addpath_tx_bestpath_per_as_cmd);
18226 install_element(BGP_IPV4M_NODE,
18227 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18228 install_element(BGP_IPV4L_NODE,
18229 &neighbor_addpath_tx_bestpath_per_as_cmd);
18230 install_element(BGP_IPV4L_NODE,
18231 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18232 install_element(BGP_IPV6_NODE,
18233 &neighbor_addpath_tx_bestpath_per_as_cmd);
18234 install_element(BGP_IPV6_NODE,
18235 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18236 install_element(BGP_IPV6M_NODE,
18237 &neighbor_addpath_tx_bestpath_per_as_cmd);
18238 install_element(BGP_IPV6M_NODE,
18239 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18240 install_element(BGP_IPV6L_NODE,
18241 &neighbor_addpath_tx_bestpath_per_as_cmd);
18242 install_element(BGP_IPV6L_NODE,
18243 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18244 install_element(BGP_VPNV4_NODE,
18245 &neighbor_addpath_tx_bestpath_per_as_cmd);
18246 install_element(BGP_VPNV4_NODE,
18247 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18248 install_element(BGP_VPNV6_NODE,
18249 &neighbor_addpath_tx_bestpath_per_as_cmd);
18250 install_element(BGP_VPNV6_NODE,
18251 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18252
18253 /* "neighbor sender-as-path-loop-detection" commands. */
18254 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
18255 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
18256
18257 /* "neighbor passive" commands. */
18258 install_element(BGP_NODE, &neighbor_passive_cmd);
18259 install_element(BGP_NODE, &no_neighbor_passive_cmd);
18260
18261
18262 /* "neighbor shutdown" commands. */
18263 install_element(BGP_NODE, &neighbor_shutdown_cmd);
18264 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
18265 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
18266 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
18267 install_element(BGP_NODE, &neighbor_shutdown_rtt_cmd);
18268 install_element(BGP_NODE, &no_neighbor_shutdown_rtt_cmd);
18269
18270 /* "neighbor capability extended-nexthop" commands.*/
18271 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
18272 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
18273
18274 /* "neighbor capability orf prefix-list" commands.*/
18275 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
18276 install_element(BGP_NODE,
18277 &no_neighbor_capability_orf_prefix_hidden_cmd);
18278 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
18279 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
18280 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
18281 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
18282 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
18283 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
18284 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
18285 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
18286 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
18287 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
18288 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
18289 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
18290
18291 /* "neighbor capability dynamic" commands.*/
18292 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
18293 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
18294
18295 /* "neighbor dont-capability-negotiate" commands. */
18296 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
18297 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
18298
18299 /* "neighbor ebgp-multihop" commands. */
18300 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
18301 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
18302 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
18303
18304 /* "neighbor disable-connected-check" commands. */
18305 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
18306 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
18307
18308 /* "neighbor enforce-first-as" commands. */
18309 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
18310 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
18311
18312 /* "neighbor description" commands. */
18313 install_element(BGP_NODE, &neighbor_description_cmd);
18314 install_element(BGP_NODE, &no_neighbor_description_cmd);
18315 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
18316
18317 /* "neighbor update-source" commands. "*/
18318 install_element(BGP_NODE, &neighbor_update_source_cmd);
18319 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
18320
18321 /* "neighbor default-originate" commands. */
18322 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
18323 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
18324 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
18325 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
18326 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
18327 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
18328 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
18329 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
18330 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
18331 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
18332 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
18333 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
18334 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
18335 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
18336 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
18337 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
18338 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
18339 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
18340 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
18341 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
18342 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
18343
18344 /* "neighbor port" commands. */
18345 install_element(BGP_NODE, &neighbor_port_cmd);
18346 install_element(BGP_NODE, &no_neighbor_port_cmd);
18347
18348 /* "neighbor weight" commands. */
18349 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
18350 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
18351
18352 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
18353 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
18354 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
18355 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
18356 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
18357 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
18358 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
18359 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
18360 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
18361 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
18362 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
18363 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
18364 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
18365 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
18366 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
18367 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
18368
18369 /* "neighbor override-capability" commands. */
18370 install_element(BGP_NODE, &neighbor_override_capability_cmd);
18371 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
18372
18373 /* "neighbor strict-capability-match" commands. */
18374 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
18375 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
18376
18377 /* "neighbor timers" commands. */
18378 install_element(BGP_NODE, &neighbor_timers_cmd);
18379 install_element(BGP_NODE, &no_neighbor_timers_cmd);
18380
18381 /* "neighbor timers connect" commands. */
18382 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
18383 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
18384
18385 /* "neighbor timers delayopen" commands. */
18386 install_element(BGP_NODE, &neighbor_timers_delayopen_cmd);
18387 install_element(BGP_NODE, &no_neighbor_timers_delayopen_cmd);
18388
18389 /* "neighbor advertisement-interval" commands. */
18390 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
18391 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
18392
18393 /* "neighbor interface" commands. */
18394 install_element(BGP_NODE, &neighbor_interface_cmd);
18395 install_element(BGP_NODE, &no_neighbor_interface_cmd);
18396
18397 /* "neighbor distribute" commands. */
18398 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
18399 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
18400 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
18401 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
18402 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
18403 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
18404 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
18405 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
18406 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
18407 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
18408 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
18409 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
18410 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
18411 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
18412 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
18413 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
18414 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
18415 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
18416
18417 /* "neighbor prefix-list" commands. */
18418 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
18419 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
18420 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
18421 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
18422 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
18423 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
18424 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
18425 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
18426 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
18427 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
18428 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
18429 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
18430 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
18431 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
18432 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
18433 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
18434 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
18435 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
18436 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
18437 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
18438 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
18439 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
18440
18441 /* "neighbor filter-list" commands. */
18442 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
18443 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
18444 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
18445 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
18446 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
18447 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
18448 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
18449 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
18450 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
18451 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
18452 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
18453 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
18454 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
18455 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
18456 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
18457 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
18458 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
18459 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
18460 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
18461 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
18462 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
18463 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
18464
18465 /* "neighbor route-map" commands. */
18466 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
18467 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
18468 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
18469 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
18470 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
18471 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
18472 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
18473 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
18474 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
18475 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
18476 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
18477 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
18478 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
18479 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
18480 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
18481 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
18482 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
18483 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
18484 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
18485 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
18486 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
18487 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
18488 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
18489 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
18490
18491 /* "neighbor unsuppress-map" commands. */
18492 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
18493 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
18494 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
18495 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
18496 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
18497 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
18498 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
18499 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
18500 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
18501 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
18502 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
18503 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
18504 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
18505 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
18506 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
18507 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
18508 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
18509 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
18510
18511 /* "neighbor advertise-map" commands. */
18512 install_element(BGP_NODE, &neighbor_advertise_map_hidden_cmd);
18513 install_element(BGP_IPV4_NODE, &neighbor_advertise_map_cmd);
18514 install_element(BGP_IPV4M_NODE, &neighbor_advertise_map_cmd);
18515 install_element(BGP_IPV4L_NODE, &neighbor_advertise_map_cmd);
18516 install_element(BGP_IPV6_NODE, &neighbor_advertise_map_cmd);
18517 install_element(BGP_IPV6M_NODE, &neighbor_advertise_map_cmd);
18518 install_element(BGP_IPV6L_NODE, &neighbor_advertise_map_cmd);
18519 install_element(BGP_VPNV4_NODE, &neighbor_advertise_map_cmd);
18520 install_element(BGP_VPNV6_NODE, &neighbor_advertise_map_cmd);
18521
18522 /* neighbor maximum-prefix-out commands. */
18523 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
18524 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
18525 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
18526 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
18527 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
18528 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
18529 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
18530 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
18531 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
18532 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
18533 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
18534 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
18535 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
18536 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
18537 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
18538 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
18539 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
18540 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
18541
18542 /* "neighbor maximum-prefix" commands. */
18543 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
18544 install_element(BGP_NODE,
18545 &neighbor_maximum_prefix_threshold_hidden_cmd);
18546 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
18547 install_element(BGP_NODE,
18548 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
18549 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
18550 install_element(BGP_NODE,
18551 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
18552 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
18553 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
18554 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
18555 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
18556 install_element(BGP_IPV4_NODE,
18557 &neighbor_maximum_prefix_threshold_warning_cmd);
18558 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
18559 install_element(BGP_IPV4_NODE,
18560 &neighbor_maximum_prefix_threshold_restart_cmd);
18561 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
18562 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
18563 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
18564 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
18565 install_element(BGP_IPV4M_NODE,
18566 &neighbor_maximum_prefix_threshold_warning_cmd);
18567 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
18568 install_element(BGP_IPV4M_NODE,
18569 &neighbor_maximum_prefix_threshold_restart_cmd);
18570 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
18571 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
18572 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
18573 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
18574 install_element(BGP_IPV4L_NODE,
18575 &neighbor_maximum_prefix_threshold_warning_cmd);
18576 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
18577 install_element(BGP_IPV4L_NODE,
18578 &neighbor_maximum_prefix_threshold_restart_cmd);
18579 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
18580 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
18581 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
18582 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
18583 install_element(BGP_IPV6_NODE,
18584 &neighbor_maximum_prefix_threshold_warning_cmd);
18585 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
18586 install_element(BGP_IPV6_NODE,
18587 &neighbor_maximum_prefix_threshold_restart_cmd);
18588 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
18589 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
18590 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
18591 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
18592 install_element(BGP_IPV6M_NODE,
18593 &neighbor_maximum_prefix_threshold_warning_cmd);
18594 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
18595 install_element(BGP_IPV6M_NODE,
18596 &neighbor_maximum_prefix_threshold_restart_cmd);
18597 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
18598 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
18599 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
18600 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
18601 install_element(BGP_IPV6L_NODE,
18602 &neighbor_maximum_prefix_threshold_warning_cmd);
18603 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
18604 install_element(BGP_IPV6L_NODE,
18605 &neighbor_maximum_prefix_threshold_restart_cmd);
18606 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
18607 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
18608 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
18609 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
18610 install_element(BGP_VPNV4_NODE,
18611 &neighbor_maximum_prefix_threshold_warning_cmd);
18612 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
18613 install_element(BGP_VPNV4_NODE,
18614 &neighbor_maximum_prefix_threshold_restart_cmd);
18615 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
18616 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
18617 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
18618 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
18619 install_element(BGP_VPNV6_NODE,
18620 &neighbor_maximum_prefix_threshold_warning_cmd);
18621 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
18622 install_element(BGP_VPNV6_NODE,
18623 &neighbor_maximum_prefix_threshold_restart_cmd);
18624 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
18625
18626 /* "neighbor allowas-in" */
18627 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
18628 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
18629 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
18630 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
18631 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
18632 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
18633 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
18634 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
18635 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
18636 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
18637 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
18638 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
18639 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
18640 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
18641 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
18642 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
18643 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
18644 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
18645 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
18646 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
18647
18648 /* address-family commands. */
18649 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
18650 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
18651 #ifdef KEEP_OLD_VPN_COMMANDS
18652 install_element(BGP_NODE, &address_family_vpnv4_cmd);
18653 install_element(BGP_NODE, &address_family_vpnv6_cmd);
18654 #endif /* KEEP_OLD_VPN_COMMANDS */
18655
18656 install_element(BGP_NODE, &address_family_evpn_cmd);
18657
18658 /* "exit-address-family" command. */
18659 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
18660 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
18661 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
18662 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
18663 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
18664 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
18665 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
18666 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
18667 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
18668 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
18669 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
18670
18671 /* "clear ip bgp commands" */
18672 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
18673
18674 /* clear ip bgp prefix */
18675 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
18676 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
18677 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
18678
18679 /* "show [ip] bgp summary" commands. */
18680 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
18681 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
18682 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
18683 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
18684 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
18685 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
18686 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
18687
18688 /* "show [ip] bgp neighbors" commands. */
18689 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
18690
18691 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
18692
18693 /* "show [ip] bgp peer-group" commands. */
18694 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
18695
18696 /* "show [ip] bgp paths" commands. */
18697 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
18698
18699 /* "show [ip] bgp community" commands. */
18700 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
18701
18702 /* "show ip bgp large-community" commands. */
18703 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
18704 /* "show [ip] bgp attribute-info" commands. */
18705 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
18706 /* "show [ip] bgp route-leak" command */
18707 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
18708
18709 /* "redistribute" commands. */
18710 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
18711 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
18712 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
18713 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
18714 install_element(BGP_NODE,
18715 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
18716 install_element(BGP_NODE,
18717 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
18718 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
18719 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
18720 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
18721 install_element(BGP_NODE,
18722 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
18723 install_element(BGP_NODE,
18724 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
18725 install_element(BGP_NODE,
18726 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
18727 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
18728 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
18729 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
18730 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
18731 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
18732 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
18733 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
18734 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
18735 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
18736 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
18737 install_element(BGP_IPV4_NODE,
18738 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
18739 install_element(BGP_IPV4_NODE,
18740 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
18741 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
18742 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
18743 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
18744 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
18745 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
18746 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
18747
18748 /* import|export vpn [route-map WORD] */
18749 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
18750 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
18751
18752 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
18753 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
18754
18755 /* ttl_security commands */
18756 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
18757 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
18758
18759 /* "show [ip] bgp memory" commands. */
18760 install_element(VIEW_NODE, &show_bgp_memory_cmd);
18761
18762 /* "show bgp martian next-hop" */
18763 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
18764
18765 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
18766
18767 /* "show [ip] bgp views" commands. */
18768 install_element(VIEW_NODE, &show_bgp_views_cmd);
18769
18770 /* "show [ip] bgp vrfs" commands. */
18771 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
18772
18773 /* Community-list. */
18774 community_list_vty();
18775
18776 /* vpn-policy commands */
18777 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
18778 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
18779 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
18780 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
18781 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
18782 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
18783 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
18784 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
18785 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
18786 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
18787 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
18788 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
18789
18790 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
18791 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
18792
18793 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
18794 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
18795 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
18796 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
18797 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
18798 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
18799 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
18800 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
18801 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
18802 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
18803 }
18804
18805 #include "memory.h"
18806 #include "bgp_regex.h"
18807 #include "bgp_clist.h"
18808 #include "bgp_ecommunity.h"
18809
18810 /* VTY functions. */
18811
18812 /* Direction value to string conversion. */
18813 static const char *community_direct_str(int direct)
18814 {
18815 switch (direct) {
18816 case COMMUNITY_DENY:
18817 return "deny";
18818 case COMMUNITY_PERMIT:
18819 return "permit";
18820 default:
18821 return "unknown";
18822 }
18823 }
18824
18825 /* Display error string. */
18826 static void community_list_perror(struct vty *vty, int ret)
18827 {
18828 switch (ret) {
18829 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
18830 vty_out(vty, "%% Can't find community-list\n");
18831 break;
18832 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
18833 vty_out(vty, "%% Malformed community-list value\n");
18834 break;
18835 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
18836 vty_out(vty,
18837 "%% Community name conflict, previously defined as standard community\n");
18838 break;
18839 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
18840 vty_out(vty,
18841 "%% Community name conflict, previously defined as expanded community\n");
18842 break;
18843 }
18844 }
18845
18846 /* "community-list" keyword help string. */
18847 #define COMMUNITY_LIST_STR "Add a community list entry\n"
18848
18849 /*community-list standard */
18850 DEFUN (community_list_standard,
18851 bgp_community_list_standard_cmd,
18852 "bgp community-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
18853 BGP_STR
18854 COMMUNITY_LIST_STR
18855 "Community list number (standard)\n"
18856 "Add an standard community-list entry\n"
18857 "Community list name\n"
18858 "Sequence number of an entry\n"
18859 "Sequence number\n"
18860 "Specify community to reject\n"
18861 "Specify community to accept\n"
18862 COMMUNITY_VAL_STR)
18863 {
18864 char *cl_name_or_number = NULL;
18865 char *seq = NULL;
18866 int direct = 0;
18867 int style = COMMUNITY_LIST_STANDARD;
18868 int idx = 0;
18869
18870 argv_find(argv, argc, "(1-4294967295)", &idx);
18871 if (idx)
18872 seq = argv[idx]->arg;
18873
18874 idx = 0;
18875 argv_find(argv, argc, "(1-99)", &idx);
18876 argv_find(argv, argc, "WORD", &idx);
18877 cl_name_or_number = argv[idx]->arg;
18878 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
18879 : COMMUNITY_DENY;
18880 argv_find(argv, argc, "AA:NN", &idx);
18881 char *str = argv_concat(argv, argc, idx);
18882
18883 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
18884 direct, style);
18885
18886 XFREE(MTYPE_TMP, str);
18887
18888 if (ret < 0) {
18889 /* Display error string. */
18890 community_list_perror(vty, ret);
18891 return CMD_WARNING_CONFIG_FAILED;
18892 }
18893
18894 return CMD_SUCCESS;
18895 }
18896
18897 DEFUN (no_community_list_standard_all,
18898 no_bgp_community_list_standard_all_cmd,
18899 "no bgp community-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
18900 NO_STR
18901 BGP_STR
18902 COMMUNITY_LIST_STR
18903 "Community list number (standard)\n"
18904 "Add an standard community-list entry\n"
18905 "Community list name\n"
18906 "Sequence number of an entry\n"
18907 "Sequence number\n"
18908 "Specify community to reject\n"
18909 "Specify community to accept\n"
18910 COMMUNITY_VAL_STR)
18911 {
18912 char *cl_name_or_number = NULL;
18913 char *str = NULL;
18914 int direct = 0;
18915 int style = COMMUNITY_LIST_STANDARD;
18916 char *seq = NULL;
18917 int idx = 0;
18918
18919 argv_find(argv, argc, "(1-4294967295)", &idx);
18920 if (idx)
18921 seq = argv[idx]->arg;
18922
18923 idx = 0;
18924 argv_find(argv, argc, "permit", &idx);
18925 argv_find(argv, argc, "deny", &idx);
18926
18927 if (idx) {
18928 direct = argv_find(argv, argc, "permit", &idx)
18929 ? COMMUNITY_PERMIT
18930 : COMMUNITY_DENY;
18931
18932 idx = 0;
18933 argv_find(argv, argc, "AA:NN", &idx);
18934 str = argv_concat(argv, argc, idx);
18935 }
18936
18937 idx = 0;
18938 argv_find(argv, argc, "(1-99)", &idx);
18939 argv_find(argv, argc, "WORD", &idx);
18940 cl_name_or_number = argv[idx]->arg;
18941
18942 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
18943 direct, style);
18944
18945 XFREE(MTYPE_TMP, str);
18946
18947 if (ret < 0) {
18948 community_list_perror(vty, ret);
18949 return CMD_WARNING_CONFIG_FAILED;
18950 }
18951
18952 return CMD_SUCCESS;
18953 }
18954
18955 ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
18956 "no bgp community-list <(1-99)|standard WORD>",
18957 NO_STR BGP_STR COMMUNITY_LIST_STR
18958 "Community list number (standard)\n"
18959 "Add an standard community-list entry\n"
18960 "Community list name\n")
18961
18962 /*community-list expanded */
18963 DEFUN (community_list_expanded_all,
18964 bgp_community_list_expanded_all_cmd,
18965 "bgp community-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
18966 BGP_STR
18967 COMMUNITY_LIST_STR
18968 "Community list number (expanded)\n"
18969 "Add an expanded community-list entry\n"
18970 "Community list name\n"
18971 "Sequence number of an entry\n"
18972 "Sequence number\n"
18973 "Specify community to reject\n"
18974 "Specify community to accept\n"
18975 COMMUNITY_VAL_STR)
18976 {
18977 char *cl_name_or_number = NULL;
18978 char *seq = NULL;
18979 int direct = 0;
18980 int style = COMMUNITY_LIST_EXPANDED;
18981 int idx = 0;
18982
18983 argv_find(argv, argc, "(1-4294967295)", &idx);
18984 if (idx)
18985 seq = argv[idx]->arg;
18986
18987 idx = 0;
18988
18989 argv_find(argv, argc, "(100-500)", &idx);
18990 argv_find(argv, argc, "WORD", &idx);
18991 cl_name_or_number = argv[idx]->arg;
18992 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
18993 : COMMUNITY_DENY;
18994 argv_find(argv, argc, "AA:NN", &idx);
18995 char *str = argv_concat(argv, argc, idx);
18996
18997 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
18998 direct, style);
18999
19000 XFREE(MTYPE_TMP, str);
19001
19002 if (ret < 0) {
19003 /* Display error string. */
19004 community_list_perror(vty, ret);
19005 return CMD_WARNING_CONFIG_FAILED;
19006 }
19007
19008 return CMD_SUCCESS;
19009 }
19010
19011 DEFUN (no_community_list_expanded_all,
19012 no_bgp_community_list_expanded_all_cmd,
19013 "no bgp community-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
19014 NO_STR
19015 BGP_STR
19016 COMMUNITY_LIST_STR
19017 "Community list number (expanded)\n"
19018 "Add an expanded community-list entry\n"
19019 "Community list name\n"
19020 "Sequence number of an entry\n"
19021 "Sequence number\n"
19022 "Specify community to reject\n"
19023 "Specify community to accept\n"
19024 COMMUNITY_VAL_STR)
19025 {
19026 char *cl_name_or_number = NULL;
19027 char *seq = NULL;
19028 char *str = NULL;
19029 int direct = 0;
19030 int style = COMMUNITY_LIST_EXPANDED;
19031 int idx = 0;
19032
19033 argv_find(argv, argc, "(1-4294967295)", &idx);
19034 if (idx)
19035 seq = argv[idx]->arg;
19036
19037 idx = 0;
19038 argv_find(argv, argc, "permit", &idx);
19039 argv_find(argv, argc, "deny", &idx);
19040
19041 if (idx) {
19042 direct = argv_find(argv, argc, "permit", &idx)
19043 ? COMMUNITY_PERMIT
19044 : COMMUNITY_DENY;
19045
19046 idx = 0;
19047 argv_find(argv, argc, "AA:NN", &idx);
19048 str = argv_concat(argv, argc, idx);
19049 }
19050
19051 idx = 0;
19052 argv_find(argv, argc, "(100-500)", &idx);
19053 argv_find(argv, argc, "WORD", &idx);
19054 cl_name_or_number = argv[idx]->arg;
19055
19056 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
19057 direct, style);
19058
19059 XFREE(MTYPE_TMP, str);
19060
19061 if (ret < 0) {
19062 community_list_perror(vty, ret);
19063 return CMD_WARNING_CONFIG_FAILED;
19064 }
19065
19066 return CMD_SUCCESS;
19067 }
19068
19069 ALIAS(no_community_list_expanded_all,
19070 no_bgp_community_list_expanded_all_list_cmd,
19071 "no bgp community-list <(100-500)|expanded WORD>",
19072 NO_STR BGP_STR COMMUNITY_LIST_STR
19073 "Community list number (expanded)\n"
19074 "Add an expanded community-list entry\n"
19075 "Community list name\n")
19076
19077 /* Return configuration string of community-list entry. */
19078 static const char *community_list_config_str(struct community_entry *entry)
19079 {
19080 const char *str;
19081
19082 if (entry->any)
19083 str = "";
19084 else {
19085 if (entry->style == COMMUNITY_LIST_STANDARD)
19086 str = community_str(entry->u.com, false);
19087 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
19088 str = lcommunity_str(entry->u.lcom, false);
19089 else
19090 str = entry->config;
19091 }
19092 return str;
19093 }
19094
19095 static void community_list_show(struct vty *vty, struct community_list *list)
19096 {
19097 struct community_entry *entry;
19098
19099 for (entry = list->head; entry; entry = entry->next) {
19100 if (entry == list->head) {
19101 if (all_digit(list->name))
19102 vty_out(vty, "Community %s list %s\n",
19103 entry->style == COMMUNITY_LIST_STANDARD
19104 ? "standard"
19105 : "(expanded) access",
19106 list->name);
19107 else
19108 vty_out(vty, "Named Community %s list %s\n",
19109 entry->style == COMMUNITY_LIST_STANDARD
19110 ? "standard"
19111 : "expanded",
19112 list->name);
19113 }
19114 if (entry->any)
19115 vty_out(vty, " %s\n",
19116 community_direct_str(entry->direct));
19117 else
19118 vty_out(vty, " %s %s\n",
19119 community_direct_str(entry->direct),
19120 community_list_config_str(entry));
19121 }
19122 }
19123
19124 DEFUN (show_community_list,
19125 show_bgp_community_list_cmd,
19126 "show bgp community-list",
19127 SHOW_STR
19128 BGP_STR
19129 "List community-list\n")
19130 {
19131 struct community_list *list;
19132 struct community_list_master *cm;
19133
19134 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
19135 if (!cm)
19136 return CMD_SUCCESS;
19137
19138 for (list = cm->num.head; list; list = list->next)
19139 community_list_show(vty, list);
19140
19141 for (list = cm->str.head; list; list = list->next)
19142 community_list_show(vty, list);
19143
19144 return CMD_SUCCESS;
19145 }
19146
19147 DEFUN (show_community_list_arg,
19148 show_bgp_community_list_arg_cmd,
19149 "show bgp community-list <(1-500)|WORD> detail",
19150 SHOW_STR
19151 BGP_STR
19152 "List community-list\n"
19153 "Community-list number\n"
19154 "Community-list name\n"
19155 "Detailed information on community-list\n")
19156 {
19157 int idx_comm_list = 3;
19158 struct community_list *list;
19159
19160 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
19161 COMMUNITY_LIST_MASTER);
19162 if (!list) {
19163 vty_out(vty, "%% Can't find community-list\n");
19164 return CMD_WARNING;
19165 }
19166
19167 community_list_show(vty, list);
19168
19169 return CMD_SUCCESS;
19170 }
19171
19172 /*
19173 * Large Community code.
19174 */
19175 static int lcommunity_list_set_vty(struct vty *vty, int argc,
19176 struct cmd_token **argv, int style,
19177 int reject_all_digit_name)
19178 {
19179 int ret;
19180 int direct;
19181 char *str;
19182 int idx = 0;
19183 char *cl_name;
19184 char *seq = NULL;
19185
19186 if (argv_find(argv, argc, "(1-4294967295)", &idx))
19187 seq = argv[idx]->arg;
19188
19189 idx = 0;
19190 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19191 : COMMUNITY_DENY;
19192
19193 /* All digit name check. */
19194 idx = 0;
19195 argv_find(argv, argc, "WORD", &idx);
19196 argv_find(argv, argc, "(1-99)", &idx);
19197 argv_find(argv, argc, "(100-500)", &idx);
19198 cl_name = argv[idx]->arg;
19199 if (reject_all_digit_name && all_digit(cl_name)) {
19200 vty_out(vty, "%% Community name cannot have all digits\n");
19201 return CMD_WARNING_CONFIG_FAILED;
19202 }
19203
19204 idx = 0;
19205 argv_find(argv, argc, "AA:BB:CC", &idx);
19206 argv_find(argv, argc, "LINE", &idx);
19207 /* Concat community string argument. */
19208 if (idx)
19209 str = argv_concat(argv, argc, idx);
19210 else
19211 str = NULL;
19212
19213 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
19214
19215 /* Free temporary community list string allocated by
19216 argv_concat(). */
19217 XFREE(MTYPE_TMP, str);
19218
19219 if (ret < 0) {
19220 community_list_perror(vty, ret);
19221 return CMD_WARNING_CONFIG_FAILED;
19222 }
19223 return CMD_SUCCESS;
19224 }
19225
19226 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
19227 struct cmd_token **argv, int style)
19228 {
19229 int ret;
19230 int direct = 0;
19231 char *str = NULL;
19232 int idx = 0;
19233 char *seq = NULL;
19234
19235 if (argv_find(argv, argc, "(1-4294967295)", &idx))
19236 seq = argv[idx]->arg;
19237
19238 idx = 0;
19239 argv_find(argv, argc, "permit", &idx);
19240 argv_find(argv, argc, "deny", &idx);
19241
19242 if (idx) {
19243 /* Check the list direct. */
19244 if (strncmp(argv[idx]->arg, "p", 1) == 0)
19245 direct = COMMUNITY_PERMIT;
19246 else
19247 direct = COMMUNITY_DENY;
19248
19249 idx = 0;
19250 argv_find(argv, argc, "LINE", &idx);
19251 argv_find(argv, argc, "AA:AA:NN", &idx);
19252 /* Concat community string argument. */
19253 str = argv_concat(argv, argc, idx);
19254 }
19255
19256 idx = 0;
19257 argv_find(argv, argc, "(1-99)", &idx);
19258 argv_find(argv, argc, "(100-500)", &idx);
19259 argv_find(argv, argc, "WORD", &idx);
19260
19261 /* Unset community list. */
19262 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
19263 style);
19264
19265 /* Free temporary community list string allocated by
19266 argv_concat(). */
19267 XFREE(MTYPE_TMP, str);
19268
19269 if (ret < 0) {
19270 community_list_perror(vty, ret);
19271 return CMD_WARNING_CONFIG_FAILED;
19272 }
19273
19274 return CMD_SUCCESS;
19275 }
19276
19277 /* "large-community-list" keyword help string. */
19278 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
19279 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
19280
19281 DEFUN (lcommunity_list_standard,
19282 bgp_lcommunity_list_standard_cmd,
19283 "bgp large-community-list (1-99) [seq (1-4294967295)] <deny|permit> AA:BB:CC...",
19284 BGP_STR
19285 LCOMMUNITY_LIST_STR
19286 "Large Community list number (standard)\n"
19287 "Sequence number of an entry\n"
19288 "Sequence number\n"
19289 "Specify large community to reject\n"
19290 "Specify large community to accept\n"
19291 LCOMMUNITY_VAL_STR)
19292 {
19293 return lcommunity_list_set_vty(vty, argc, argv,
19294 LARGE_COMMUNITY_LIST_STANDARD, 0);
19295 }
19296
19297 DEFUN (lcommunity_list_expanded,
19298 bgp_lcommunity_list_expanded_cmd,
19299 "bgp large-community-list (100-500) [seq (1-4294967295)] <deny|permit> LINE...",
19300 BGP_STR
19301 LCOMMUNITY_LIST_STR
19302 "Large Community list number (expanded)\n"
19303 "Sequence number of an entry\n"
19304 "Sequence number\n"
19305 "Specify large community to reject\n"
19306 "Specify large community to accept\n"
19307 "An ordered list as a regular-expression\n")
19308 {
19309 return lcommunity_list_set_vty(vty, argc, argv,
19310 LARGE_COMMUNITY_LIST_EXPANDED, 0);
19311 }
19312
19313 DEFUN (lcommunity_list_name_standard,
19314 bgp_lcommunity_list_name_standard_cmd,
19315 "bgp large-community-list standard WORD [seq (1-4294967295)] <deny|permit> AA:BB:CC...",
19316 BGP_STR
19317 LCOMMUNITY_LIST_STR
19318 "Specify standard large-community-list\n"
19319 "Large Community list name\n"
19320 "Sequence number of an entry\n"
19321 "Sequence number\n"
19322 "Specify large community to reject\n"
19323 "Specify large community to accept\n"
19324 LCOMMUNITY_VAL_STR)
19325 {
19326 return lcommunity_list_set_vty(vty, argc, argv,
19327 LARGE_COMMUNITY_LIST_STANDARD, 1);
19328 }
19329
19330 DEFUN (lcommunity_list_name_expanded,
19331 bgp_lcommunity_list_name_expanded_cmd,
19332 "bgp large-community-list expanded WORD [seq (1-4294967295)] <deny|permit> LINE...",
19333 BGP_STR
19334 LCOMMUNITY_LIST_STR
19335 "Specify expanded large-community-list\n"
19336 "Large Community list name\n"
19337 "Sequence number of an entry\n"
19338 "Sequence number\n"
19339 "Specify large community to reject\n"
19340 "Specify large community to accept\n"
19341 "An ordered list as a regular-expression\n")
19342 {
19343 return lcommunity_list_set_vty(vty, argc, argv,
19344 LARGE_COMMUNITY_LIST_EXPANDED, 1);
19345 }
19346
19347 DEFUN (no_lcommunity_list_all,
19348 no_bgp_lcommunity_list_all_cmd,
19349 "no bgp large-community-list <(1-99)|(100-500)|WORD>",
19350 NO_STR
19351 BGP_STR
19352 LCOMMUNITY_LIST_STR
19353 "Large Community list number (standard)\n"
19354 "Large Community list number (expanded)\n"
19355 "Large Community list name\n")
19356 {
19357 return lcommunity_list_unset_vty(vty, argc, argv,
19358 LARGE_COMMUNITY_LIST_STANDARD);
19359 }
19360
19361 DEFUN (no_lcommunity_list_name_standard_all,
19362 no_bgp_lcommunity_list_name_standard_all_cmd,
19363 "no bgp large-community-list standard WORD",
19364 NO_STR
19365 BGP_STR
19366 LCOMMUNITY_LIST_STR
19367 "Specify standard large-community-list\n"
19368 "Large Community list name\n")
19369 {
19370 return lcommunity_list_unset_vty(vty, argc, argv,
19371 LARGE_COMMUNITY_LIST_STANDARD);
19372 }
19373
19374 DEFUN (no_lcommunity_list_name_expanded_all,
19375 no_bgp_lcommunity_list_name_expanded_all_cmd,
19376 "no bgp large-community-list expanded WORD",
19377 NO_STR
19378 BGP_STR
19379 LCOMMUNITY_LIST_STR
19380 "Specify expanded large-community-list\n"
19381 "Large Community list name\n")
19382 {
19383 return lcommunity_list_unset_vty(vty, argc, argv,
19384 LARGE_COMMUNITY_LIST_EXPANDED);
19385 }
19386
19387 DEFUN (no_lcommunity_list_standard,
19388 no_bgp_lcommunity_list_standard_cmd,
19389 "no bgp large-community-list (1-99) [seq (1-4294967295)] <deny|permit> AA:AA:NN...",
19390 NO_STR
19391 BGP_STR
19392 LCOMMUNITY_LIST_STR
19393 "Large Community list number (standard)\n"
19394 "Sequence number of an entry\n"
19395 "Sequence number\n"
19396 "Specify large community to reject\n"
19397 "Specify large community to accept\n"
19398 LCOMMUNITY_VAL_STR)
19399 {
19400 return lcommunity_list_unset_vty(vty, argc, argv,
19401 LARGE_COMMUNITY_LIST_STANDARD);
19402 }
19403
19404 DEFUN (no_lcommunity_list_expanded,
19405 no_bgp_lcommunity_list_expanded_cmd,
19406 "no bgp large-community-list (100-500) [seq (1-4294967295)] <deny|permit> LINE...",
19407 NO_STR
19408 BGP_STR
19409 LCOMMUNITY_LIST_STR
19410 "Large Community list number (expanded)\n"
19411 "Sequence number of an entry\n"
19412 "Sequence number\n"
19413 "Specify large community to reject\n"
19414 "Specify large community to accept\n"
19415 "An ordered list as a regular-expression\n")
19416 {
19417 return lcommunity_list_unset_vty(vty, argc, argv,
19418 LARGE_COMMUNITY_LIST_EXPANDED);
19419 }
19420
19421 DEFUN (no_lcommunity_list_name_standard,
19422 no_bgp_lcommunity_list_name_standard_cmd,
19423 "no bgp large-community-list standard WORD [seq (1-4294967295)] <deny|permit> AA:AA:NN...",
19424 NO_STR
19425 BGP_STR
19426 LCOMMUNITY_LIST_STR
19427 "Specify standard large-community-list\n"
19428 "Large Community list name\n"
19429 "Sequence number of an entry\n"
19430 "Sequence number\n"
19431 "Specify large community to reject\n"
19432 "Specify large community to accept\n"
19433 LCOMMUNITY_VAL_STR)
19434 {
19435 return lcommunity_list_unset_vty(vty, argc, argv,
19436 LARGE_COMMUNITY_LIST_STANDARD);
19437 }
19438
19439 DEFUN (no_lcommunity_list_name_expanded,
19440 no_bgp_lcommunity_list_name_expanded_cmd,
19441 "no bgp large-community-list expanded WORD [seq (1-4294967295)] <deny|permit> LINE...",
19442 NO_STR
19443 BGP_STR
19444 LCOMMUNITY_LIST_STR
19445 "Specify expanded large-community-list\n"
19446 "Large community list name\n"
19447 "Sequence number of an entry\n"
19448 "Sequence number\n"
19449 "Specify large community to reject\n"
19450 "Specify large community to accept\n"
19451 "An ordered list as a regular-expression\n")
19452 {
19453 return lcommunity_list_unset_vty(vty, argc, argv,
19454 LARGE_COMMUNITY_LIST_EXPANDED);
19455 }
19456
19457 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
19458 {
19459 struct community_entry *entry;
19460
19461 for (entry = list->head; entry; entry = entry->next) {
19462 if (entry == list->head) {
19463 if (all_digit(list->name))
19464 vty_out(vty, "Large community %s list %s\n",
19465 entry->style ==
19466 LARGE_COMMUNITY_LIST_STANDARD
19467 ? "standard"
19468 : "(expanded) access",
19469 list->name);
19470 else
19471 vty_out(vty,
19472 "Named large community %s list %s\n",
19473 entry->style ==
19474 LARGE_COMMUNITY_LIST_STANDARD
19475 ? "standard"
19476 : "expanded",
19477 list->name);
19478 }
19479 if (entry->any)
19480 vty_out(vty, " %s\n",
19481 community_direct_str(entry->direct));
19482 else
19483 vty_out(vty, " %s %s\n",
19484 community_direct_str(entry->direct),
19485 community_list_config_str(entry));
19486 }
19487 }
19488
19489 DEFUN (show_lcommunity_list,
19490 show_bgp_lcommunity_list_cmd,
19491 "show bgp large-community-list",
19492 SHOW_STR
19493 BGP_STR
19494 "List large-community list\n")
19495 {
19496 struct community_list *list;
19497 struct community_list_master *cm;
19498
19499 cm = community_list_master_lookup(bgp_clist,
19500 LARGE_COMMUNITY_LIST_MASTER);
19501 if (!cm)
19502 return CMD_SUCCESS;
19503
19504 for (list = cm->num.head; list; list = list->next)
19505 lcommunity_list_show(vty, list);
19506
19507 for (list = cm->str.head; list; list = list->next)
19508 lcommunity_list_show(vty, list);
19509
19510 return CMD_SUCCESS;
19511 }
19512
19513 DEFUN (show_lcommunity_list_arg,
19514 show_bgp_lcommunity_list_arg_cmd,
19515 "show bgp large-community-list <(1-500)|WORD> detail",
19516 SHOW_STR
19517 BGP_STR
19518 "List large-community list\n"
19519 "Large-community-list number\n"
19520 "Large-community-list name\n"
19521 "Detailed information on large-community-list\n")
19522 {
19523 struct community_list *list;
19524
19525 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
19526 LARGE_COMMUNITY_LIST_MASTER);
19527 if (!list) {
19528 vty_out(vty, "%% Can't find large-community-list\n");
19529 return CMD_WARNING;
19530 }
19531
19532 lcommunity_list_show(vty, list);
19533
19534 return CMD_SUCCESS;
19535 }
19536
19537 /* "extcommunity-list" keyword help string. */
19538 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
19539 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
19540
19541 DEFUN (extcommunity_list_standard,
19542 bgp_extcommunity_list_standard_cmd,
19543 "bgp extcommunity-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
19544 BGP_STR
19545 EXTCOMMUNITY_LIST_STR
19546 "Extended Community list number (standard)\n"
19547 "Specify standard extcommunity-list\n"
19548 "Community list name\n"
19549 "Sequence number of an entry\n"
19550 "Sequence number\n"
19551 "Specify community to reject\n"
19552 "Specify community to accept\n"
19553 EXTCOMMUNITY_VAL_STR)
19554 {
19555 int style = EXTCOMMUNITY_LIST_STANDARD;
19556 int direct = 0;
19557 char *cl_number_or_name = NULL;
19558 char *seq = NULL;
19559
19560 int idx = 0;
19561
19562 argv_find(argv, argc, "(1-99)", &idx);
19563 argv_find(argv, argc, "WORD", &idx);
19564 cl_number_or_name = argv[idx]->arg;
19565
19566 if (argv_find(argv, argc, "(1-4294967295)", &idx))
19567 seq = argv[idx]->arg;
19568
19569 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19570 : COMMUNITY_DENY;
19571 argv_find(argv, argc, "AA:NN", &idx);
19572 char *str = argv_concat(argv, argc, idx);
19573
19574 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
19575 direct, style);
19576
19577 XFREE(MTYPE_TMP, str);
19578
19579 if (ret < 0) {
19580 community_list_perror(vty, ret);
19581 return CMD_WARNING_CONFIG_FAILED;
19582 }
19583
19584 return CMD_SUCCESS;
19585 }
19586
19587 DEFUN (extcommunity_list_name_expanded,
19588 bgp_extcommunity_list_name_expanded_cmd,
19589 "bgp extcommunity-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> LINE...",
19590 BGP_STR
19591 EXTCOMMUNITY_LIST_STR
19592 "Extended Community list number (expanded)\n"
19593 "Specify expanded extcommunity-list\n"
19594 "Extended Community list name\n"
19595 "Sequence number of an entry\n"
19596 "Sequence number\n"
19597 "Specify community to reject\n"
19598 "Specify community to accept\n"
19599 "An ordered list as a regular-expression\n")
19600 {
19601 int style = EXTCOMMUNITY_LIST_EXPANDED;
19602 int direct = 0;
19603 char *cl_number_or_name = NULL;
19604 char *seq = NULL;
19605 int idx = 0;
19606
19607 argv_find(argv, argc, "(100-500)", &idx);
19608 argv_find(argv, argc, "WORD", &idx);
19609 cl_number_or_name = argv[idx]->arg;
19610
19611 if (argv_find(argv, argc, "(1-4294967295)", &idx))
19612 seq = argv[idx]->arg;
19613
19614 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19615 : COMMUNITY_DENY;
19616 argv_find(argv, argc, "LINE", &idx);
19617 char *str = argv_concat(argv, argc, idx);
19618
19619 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
19620 direct, style);
19621
19622 XFREE(MTYPE_TMP, str);
19623
19624 if (ret < 0) {
19625 community_list_perror(vty, ret);
19626 return CMD_WARNING_CONFIG_FAILED;
19627 }
19628
19629 return CMD_SUCCESS;
19630 }
19631
19632 DEFUN (no_extcommunity_list_standard_all,
19633 no_bgp_extcommunity_list_standard_all_cmd,
19634 "no bgp extcommunity-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
19635 NO_STR
19636 BGP_STR
19637 EXTCOMMUNITY_LIST_STR
19638 "Extended Community list number (standard)\n"
19639 "Specify standard extcommunity-list\n"
19640 "Community list name\n"
19641 "Sequence number of an entry\n"
19642 "Sequence number\n"
19643 "Specify community to reject\n"
19644 "Specify community to accept\n"
19645 EXTCOMMUNITY_VAL_STR)
19646 {
19647 int style = EXTCOMMUNITY_LIST_STANDARD;
19648 int direct = 0;
19649 char *cl_number_or_name = NULL;
19650 char *str = NULL;
19651 char *seq = NULL;
19652 int idx = 0;
19653
19654 if (argv_find(argv, argc, "(1-4294967295)", &idx))
19655 seq = argv[idx]->arg;
19656
19657 idx = 0;
19658 argv_find(argv, argc, "permit", &idx);
19659 argv_find(argv, argc, "deny", &idx);
19660 if (idx) {
19661 direct = argv_find(argv, argc, "permit", &idx)
19662 ? COMMUNITY_PERMIT
19663 : COMMUNITY_DENY;
19664
19665 idx = 0;
19666 argv_find(argv, argc, "AA:NN", &idx);
19667 str = argv_concat(argv, argc, idx);
19668 }
19669
19670 idx = 0;
19671 argv_find(argv, argc, "(1-99)", &idx);
19672 argv_find(argv, argc, "WORD", &idx);
19673 cl_number_or_name = argv[idx]->arg;
19674
19675 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
19676 seq, direct, style);
19677
19678 XFREE(MTYPE_TMP, str);
19679
19680 if (ret < 0) {
19681 community_list_perror(vty, ret);
19682 return CMD_WARNING_CONFIG_FAILED;
19683 }
19684
19685 return CMD_SUCCESS;
19686 }
19687
19688 ALIAS(no_extcommunity_list_standard_all,
19689 no_bgp_extcommunity_list_standard_all_list_cmd,
19690 "no bgp extcommunity-list <(1-99)|standard WORD>",
19691 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
19692 "Extended Community list number (standard)\n"
19693 "Specify standard extcommunity-list\n"
19694 "Community list name\n")
19695
19696 DEFUN (no_extcommunity_list_expanded_all,
19697 no_bgp_extcommunity_list_expanded_all_cmd,
19698 "no bgp extcommunity-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> LINE...",
19699 NO_STR
19700 BGP_STR
19701 EXTCOMMUNITY_LIST_STR
19702 "Extended Community list number (expanded)\n"
19703 "Specify expanded extcommunity-list\n"
19704 "Extended Community list name\n"
19705 "Sequence number of an entry\n"
19706 "Sequence number\n"
19707 "Specify community to reject\n"
19708 "Specify community to accept\n"
19709 "An ordered list as a regular-expression\n")
19710 {
19711 int style = EXTCOMMUNITY_LIST_EXPANDED;
19712 int direct = 0;
19713 char *cl_number_or_name = NULL;
19714 char *str = NULL;
19715 char *seq = NULL;
19716 int idx = 0;
19717
19718 if (argv_find(argv, argc, "(1-4294967295)", &idx))
19719 seq = argv[idx]->arg;
19720
19721 idx = 0;
19722 argv_find(argv, argc, "permit", &idx);
19723 argv_find(argv, argc, "deny", &idx);
19724
19725 if (idx) {
19726 direct = argv_find(argv, argc, "permit", &idx)
19727 ? COMMUNITY_PERMIT
19728 : COMMUNITY_DENY;
19729
19730 idx = 0;
19731 argv_find(argv, argc, "LINE", &idx);
19732 str = argv_concat(argv, argc, idx);
19733 }
19734
19735 idx = 0;
19736 argv_find(argv, argc, "(100-500)", &idx);
19737 argv_find(argv, argc, "WORD", &idx);
19738 cl_number_or_name = argv[idx]->arg;
19739
19740 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
19741 seq, direct, style);
19742
19743 XFREE(MTYPE_TMP, str);
19744
19745 if (ret < 0) {
19746 community_list_perror(vty, ret);
19747 return CMD_WARNING_CONFIG_FAILED;
19748 }
19749
19750 return CMD_SUCCESS;
19751 }
19752
19753 ALIAS(no_extcommunity_list_expanded_all,
19754 no_bgp_extcommunity_list_expanded_all_list_cmd,
19755 "no bgp extcommunity-list <(100-500)|expanded WORD>",
19756 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
19757 "Extended Community list number (expanded)\n"
19758 "Specify expanded extcommunity-list\n"
19759 "Extended Community list name\n")
19760
19761 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
19762 {
19763 struct community_entry *entry;
19764
19765 for (entry = list->head; entry; entry = entry->next) {
19766 if (entry == list->head) {
19767 if (all_digit(list->name))
19768 vty_out(vty, "Extended community %s list %s\n",
19769 entry->style == EXTCOMMUNITY_LIST_STANDARD
19770 ? "standard"
19771 : "(expanded) access",
19772 list->name);
19773 else
19774 vty_out(vty,
19775 "Named extended community %s list %s\n",
19776 entry->style == EXTCOMMUNITY_LIST_STANDARD
19777 ? "standard"
19778 : "expanded",
19779 list->name);
19780 }
19781 if (entry->any)
19782 vty_out(vty, " %s\n",
19783 community_direct_str(entry->direct));
19784 else
19785 vty_out(vty, " %s %s\n",
19786 community_direct_str(entry->direct),
19787 community_list_config_str(entry));
19788 }
19789 }
19790
19791 DEFUN (show_extcommunity_list,
19792 show_bgp_extcommunity_list_cmd,
19793 "show bgp extcommunity-list",
19794 SHOW_STR
19795 BGP_STR
19796 "List extended-community list\n")
19797 {
19798 struct community_list *list;
19799 struct community_list_master *cm;
19800
19801 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
19802 if (!cm)
19803 return CMD_SUCCESS;
19804
19805 for (list = cm->num.head; list; list = list->next)
19806 extcommunity_list_show(vty, list);
19807
19808 for (list = cm->str.head; list; list = list->next)
19809 extcommunity_list_show(vty, list);
19810
19811 return CMD_SUCCESS;
19812 }
19813
19814 DEFUN (show_extcommunity_list_arg,
19815 show_bgp_extcommunity_list_arg_cmd,
19816 "show bgp extcommunity-list <(1-500)|WORD> detail",
19817 SHOW_STR
19818 BGP_STR
19819 "List extended-community list\n"
19820 "Extcommunity-list number\n"
19821 "Extcommunity-list name\n"
19822 "Detailed information on extcommunity-list\n")
19823 {
19824 int idx_comm_list = 3;
19825 struct community_list *list;
19826
19827 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
19828 EXTCOMMUNITY_LIST_MASTER);
19829 if (!list) {
19830 vty_out(vty, "%% Can't find extcommunity-list\n");
19831 return CMD_WARNING;
19832 }
19833
19834 extcommunity_list_show(vty, list);
19835
19836 return CMD_SUCCESS;
19837 }
19838
19839 /* Display community-list and extcommunity-list configuration. */
19840 static int community_list_config_write(struct vty *vty)
19841 {
19842 struct community_list *list;
19843 struct community_entry *entry;
19844 struct community_list_master *cm;
19845 int write = 0;
19846
19847 /* Community-list. */
19848 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
19849
19850 for (list = cm->num.head; list; list = list->next)
19851 for (entry = list->head; entry; entry = entry->next) {
19852 vty_out(vty,
19853 "bgp community-list %s seq %" PRId64 " %s %s\n",
19854 list->name, entry->seq,
19855 community_direct_str(entry->direct),
19856 community_list_config_str(entry));
19857 write++;
19858 }
19859 for (list = cm->str.head; list; list = list->next)
19860 for (entry = list->head; entry; entry = entry->next) {
19861 vty_out(vty,
19862 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
19863 entry->style == COMMUNITY_LIST_STANDARD
19864 ? "standard"
19865 : "expanded",
19866 list->name, entry->seq,
19867 community_direct_str(entry->direct),
19868 community_list_config_str(entry));
19869 write++;
19870 }
19871
19872 /* Extcommunity-list. */
19873 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
19874
19875 for (list = cm->num.head; list; list = list->next)
19876 for (entry = list->head; entry; entry = entry->next) {
19877 vty_out(vty,
19878 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
19879 list->name, entry->seq,
19880 community_direct_str(entry->direct),
19881 community_list_config_str(entry));
19882 write++;
19883 }
19884 for (list = cm->str.head; list; list = list->next)
19885 for (entry = list->head; entry; entry = entry->next) {
19886 vty_out(vty,
19887 "bgp extcommunity-list %s %s seq %" PRId64" %s %s\n",
19888 entry->style == EXTCOMMUNITY_LIST_STANDARD
19889 ? "standard"
19890 : "expanded",
19891 list->name, entry->seq,
19892 community_direct_str(entry->direct),
19893 community_list_config_str(entry));
19894 write++;
19895 }
19896
19897
19898 /* lcommunity-list. */
19899 cm = community_list_master_lookup(bgp_clist,
19900 LARGE_COMMUNITY_LIST_MASTER);
19901
19902 for (list = cm->num.head; list; list = list->next)
19903 for (entry = list->head; entry; entry = entry->next) {
19904 vty_out(vty,
19905 "bgp large-community-list %s seq %" PRId64" %s %s\n",
19906 list->name, entry->seq,
19907 community_direct_str(entry->direct),
19908 community_list_config_str(entry));
19909 write++;
19910 }
19911 for (list = cm->str.head; list; list = list->next)
19912 for (entry = list->head; entry; entry = entry->next) {
19913 vty_out(vty,
19914 "bgp large-community-list %s %s seq %" PRId64" %s %s\n",
19915
19916 entry->style == LARGE_COMMUNITY_LIST_STANDARD
19917 ? "standard"
19918 : "expanded",
19919 list->name, entry->seq, community_direct_str(entry->direct),
19920 community_list_config_str(entry));
19921 write++;
19922 }
19923
19924 return write;
19925 }
19926
19927 static int community_list_config_write(struct vty *vty);
19928 static struct cmd_node community_list_node = {
19929 .name = "community list",
19930 .node = COMMUNITY_LIST_NODE,
19931 .prompt = "",
19932 .config_write = community_list_config_write,
19933 };
19934
19935 static void community_list_vty(void)
19936 {
19937 install_node(&community_list_node);
19938
19939 /* Community-list. */
19940 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
19941 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
19942 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
19943 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
19944 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
19945 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
19946 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
19947 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
19948
19949 /* Extcommunity-list. */
19950 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
19951 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
19952 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
19953 install_element(CONFIG_NODE,
19954 &no_bgp_extcommunity_list_standard_all_list_cmd);
19955 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
19956 install_element(CONFIG_NODE,
19957 &no_bgp_extcommunity_list_expanded_all_list_cmd);
19958 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
19959 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
19960
19961 /* Large Community List */
19962 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
19963 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
19964 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
19965 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
19966 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
19967 install_element(CONFIG_NODE,
19968 &no_bgp_lcommunity_list_name_standard_all_cmd);
19969 install_element(CONFIG_NODE,
19970 &no_bgp_lcommunity_list_name_expanded_all_cmd);
19971 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
19972 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
19973 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
19974 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
19975 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
19976 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
19977 }