]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
Merge pull request #7572 from idryzhov/ospf6-cleanup
[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 && safi == SAFI_UNICAST)
213 return "IPv4 Unicast";
214 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
215 return "IPv4 Multicast";
216 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
217 return "IPv4 Labeled Unicast";
218 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
219 return "IPv4 VPN";
220 else if (afi == AFI_IP && safi == SAFI_ENCAP)
221 return "IPv4 Encap";
222 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
223 return "IPv4 Flowspec";
224 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
225 return "IPv6 Unicast";
226 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
227 return "IPv6 Multicast";
228 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
229 return "IPv6 Labeled Unicast";
230 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
231 return "IPv6 VPN";
232 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
233 return "IPv6 Encap";
234 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
235 return "IPv6 Flowspec";
236 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
237 return "L2VPN EVPN";
238 else
239 return "Unknown";
240 }
241
242 /*
243 * Please note that we have intentionally camelCased
244 * the return strings here. So if you want
245 * to use this function, please ensure you
246 * are doing this within json output
247 */
248 static const char *get_afi_safi_json_str(afi_t afi, safi_t safi)
249 {
250 if (afi == AFI_IP && safi == SAFI_UNICAST)
251 return "ipv4Unicast";
252 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
253 return "ipv4Multicast";
254 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
255 return "ipv4LabeledUnicast";
256 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
257 return "ipv4Vpn";
258 else if (afi == AFI_IP && safi == SAFI_ENCAP)
259 return "ipv4Encap";
260 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
261 return "ipv4Flowspec";
262 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
263 return "ipv6Unicast";
264 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
265 return "ipv6Multicast";
266 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
267 return "ipv6LabeledUnicast";
268 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
269 return "ipv6Vpn";
270 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
271 return "ipv6Encap";
272 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
273 return "ipv6Flowspec";
274 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
275 return "l2VpnEvpn";
276 else
277 return "Unknown";
278 }
279
280 /* return string maps to afi-safi specific container names
281 * defined in bgp yang file.
282 */
283 const char *bgp_afi_safi_get_container_str(afi_t afi, safi_t safi)
284 {
285 if (afi == AFI_IP && safi == SAFI_UNICAST)
286 return "ipv4-unicast";
287 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
288 return "ipv4-multicast";
289 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
290 return "ipv4-labeled-unicast";
291 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
292 return "l3vpn-ipv4-unicast";
293 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
294 return "ipv4-flowspec";
295 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
296 return "ipv6-unicast";
297 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
298 return "ipv6-multicast";
299 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
300 return "ipv6-labeled-unicast";
301 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
302 return "l3vpn-ipv6-unicast";
303 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
304 return "ipv6-flowspec";
305 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
306 return "l2vpn-evpn";
307 else
308 return "Unknown";
309 }
310
311 /* Utility function to get address family from current node. */
312 afi_t bgp_node_afi(struct vty *vty)
313 {
314 afi_t afi;
315 switch (vty->node) {
316 case BGP_IPV6_NODE:
317 case BGP_IPV6M_NODE:
318 case BGP_IPV6L_NODE:
319 case BGP_VPNV6_NODE:
320 case BGP_FLOWSPECV6_NODE:
321 afi = AFI_IP6;
322 break;
323 case BGP_EVPN_NODE:
324 afi = AFI_L2VPN;
325 break;
326 default:
327 afi = AFI_IP;
328 break;
329 }
330 return afi;
331 }
332
333 /* Utility function to get subsequent address family from current
334 node. */
335 safi_t bgp_node_safi(struct vty *vty)
336 {
337 safi_t safi;
338 switch (vty->node) {
339 case BGP_VPNV4_NODE:
340 case BGP_VPNV6_NODE:
341 safi = SAFI_MPLS_VPN;
342 break;
343 case BGP_IPV4M_NODE:
344 case BGP_IPV6M_NODE:
345 safi = SAFI_MULTICAST;
346 break;
347 case BGP_EVPN_NODE:
348 safi = SAFI_EVPN;
349 break;
350 case BGP_IPV4L_NODE:
351 case BGP_IPV6L_NODE:
352 safi = SAFI_LABELED_UNICAST;
353 break;
354 case BGP_FLOWSPECV4_NODE:
355 case BGP_FLOWSPECV6_NODE:
356 safi = SAFI_FLOWSPEC;
357 break;
358 default:
359 safi = SAFI_UNICAST;
360 break;
361 }
362 return safi;
363 }
364
365 /**
366 * Converts an AFI in string form to afi_t
367 *
368 * @param afi string, one of
369 * - "ipv4"
370 * - "ipv6"
371 * - "l2vpn"
372 * @return the corresponding afi_t
373 */
374 afi_t bgp_vty_afi_from_str(const char *afi_str)
375 {
376 afi_t afi = AFI_MAX; /* unknown */
377 if (strmatch(afi_str, "ipv4"))
378 afi = AFI_IP;
379 else if (strmatch(afi_str, "ipv6"))
380 afi = AFI_IP6;
381 else if (strmatch(afi_str, "l2vpn"))
382 afi = AFI_L2VPN;
383 return afi;
384 }
385
386 int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
387 afi_t *afi)
388 {
389 int ret = 0;
390 if (argv_find(argv, argc, "ipv4", index)) {
391 ret = 1;
392 if (afi)
393 *afi = AFI_IP;
394 } else if (argv_find(argv, argc, "ipv6", index)) {
395 ret = 1;
396 if (afi)
397 *afi = AFI_IP6;
398 } else if (argv_find(argv, argc, "l2vpn", index)) {
399 ret = 1;
400 if (afi)
401 *afi = AFI_L2VPN;
402 }
403 return ret;
404 }
405
406 /* supports <unicast|multicast|vpn|labeled-unicast> */
407 safi_t bgp_vty_safi_from_str(const char *safi_str)
408 {
409 safi_t safi = SAFI_MAX; /* unknown */
410 if (strmatch(safi_str, "multicast"))
411 safi = SAFI_MULTICAST;
412 else if (strmatch(safi_str, "unicast"))
413 safi = SAFI_UNICAST;
414 else if (strmatch(safi_str, "vpn"))
415 safi = SAFI_MPLS_VPN;
416 else if (strmatch(safi_str, "evpn"))
417 safi = SAFI_EVPN;
418 else if (strmatch(safi_str, "labeled-unicast"))
419 safi = SAFI_LABELED_UNICAST;
420 else if (strmatch(safi_str, "flowspec"))
421 safi = SAFI_FLOWSPEC;
422 return safi;
423 }
424
425 int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
426 safi_t *safi)
427 {
428 int ret = 0;
429 if (argv_find(argv, argc, "unicast", index)) {
430 ret = 1;
431 if (safi)
432 *safi = SAFI_UNICAST;
433 } else if (argv_find(argv, argc, "multicast", index)) {
434 ret = 1;
435 if (safi)
436 *safi = SAFI_MULTICAST;
437 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
438 ret = 1;
439 if (safi)
440 *safi = SAFI_LABELED_UNICAST;
441 } else if (argv_find(argv, argc, "vpn", index)) {
442 ret = 1;
443 if (safi)
444 *safi = SAFI_MPLS_VPN;
445 } else if (argv_find(argv, argc, "evpn", index)) {
446 ret = 1;
447 if (safi)
448 *safi = SAFI_EVPN;
449 } else if (argv_find(argv, argc, "flowspec", index)) {
450 ret = 1;
451 if (safi)
452 *safi = SAFI_FLOWSPEC;
453 }
454 return ret;
455 }
456
457 int bgp_get_vty(struct bgp **bgp, as_t *as, const char *name,
458 enum bgp_instance_type inst_type)
459 {
460 int ret = bgp_get(bgp, as, name, inst_type);
461
462 if (ret == BGP_CREATED) {
463 bgp_timers_set(*bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
464 DFLT_BGP_CONNECT_RETRY);
465
466 if (DFLT_BGP_IMPORT_CHECK)
467 SET_FLAG((*bgp)->flags, BGP_FLAG_IMPORT_CHECK);
468 if (DFLT_BGP_SHOW_HOSTNAME)
469 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_HOSTNAME);
470 if (DFLT_BGP_SHOW_NEXTHOP_HOSTNAME)
471 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
472 if (DFLT_BGP_LOG_NEIGHBOR_CHANGES)
473 SET_FLAG((*bgp)->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
474 if (DFLT_BGP_DETERMINISTIC_MED)
475 SET_FLAG((*bgp)->flags, BGP_FLAG_DETERMINISTIC_MED);
476 if (DFLT_BGP_EBGP_REQUIRES_POLICY)
477 SET_FLAG((*bgp)->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
478
479 ret = BGP_SUCCESS;
480 }
481 return ret;
482 }
483
484 /*
485 * bgp_vty_find_and_parse_afi_safi_bgp
486 *
487 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
488 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
489 * to appropriate values for the calling function. This is to allow the
490 * calling function to make decisions appropriate for the show command
491 * that is being parsed.
492 *
493 * The show commands are generally of the form:
494 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
495 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
496 *
497 * Since we use argv_find if the show command in particular doesn't have:
498 * [ip]
499 * [<view|vrf> VIEWVRFNAME]
500 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
501 * The command parsing should still be ok.
502 *
503 * vty -> The vty for the command so we can output some useful data in
504 * the event of a parse error in the vrf.
505 * argv -> The command tokens
506 * argc -> How many command tokens we have
507 * idx -> The current place in the command, generally should be 0 for this
508 * function
509 * afi -> The parsed afi if it was included in the show command, returned here
510 * safi -> The parsed safi if it was included in the show command, returned here
511 * bgp -> Pointer to the bgp data structure we need to fill in.
512 * use_json -> json is configured or not
513 *
514 * The function returns the correct location in the parse tree for the
515 * last token found.
516 *
517 * Returns 0 for failure to parse correctly, else the idx position of where
518 * it found the last token.
519 */
520 int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
521 struct cmd_token **argv, int argc,
522 int *idx, afi_t *afi, safi_t *safi,
523 struct bgp **bgp, bool use_json)
524 {
525 char *vrf_name = NULL;
526
527 assert(afi);
528 assert(safi);
529 assert(bgp);
530
531 if (argv_find(argv, argc, "ip", idx))
532 *afi = AFI_IP;
533
534 if (argv_find(argv, argc, "view", idx))
535 vrf_name = argv[*idx + 1]->arg;
536 else if (argv_find(argv, argc, "vrf", idx)) {
537 vrf_name = argv[*idx + 1]->arg;
538 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
539 vrf_name = NULL;
540 }
541 if (vrf_name) {
542 if (strmatch(vrf_name, "all"))
543 *bgp = NULL;
544 else {
545 *bgp = bgp_lookup_by_name(vrf_name);
546 if (!*bgp) {
547 if (use_json) {
548 json_object *json = NULL;
549 json = json_object_new_object();
550 json_object_string_add(
551 json, "warning",
552 "View/Vrf is unknown");
553 vty_out(vty, "%s\n",
554 json_object_to_json_string_ext(json,
555 JSON_C_TO_STRING_PRETTY));
556 json_object_free(json);
557 }
558 else
559 vty_out(vty, "View/Vrf %s is unknown\n",
560 vrf_name);
561 *idx = 0;
562 return 0;
563 }
564 }
565 } else {
566 *bgp = bgp_get_default();
567 if (!*bgp) {
568 if (use_json) {
569 json_object *json = NULL;
570 json = json_object_new_object();
571 json_object_string_add(
572 json, "warning",
573 "Default BGP instance not found");
574 vty_out(vty, "%s\n",
575 json_object_to_json_string_ext(json,
576 JSON_C_TO_STRING_PRETTY));
577 json_object_free(json);
578 }
579 else
580 vty_out(vty,
581 "Default BGP instance not found\n");
582 *idx = 0;
583 return 0;
584 }
585 }
586
587 if (argv_find_and_parse_afi(argv, argc, idx, afi))
588 argv_find_and_parse_safi(argv, argc, idx, safi);
589
590 *idx += 1;
591 return *idx;
592 }
593
594 bool peer_address_self_check(struct bgp *bgp, union sockunion *su)
595 {
596 struct interface *ifp = NULL;
597
598 if (su->sa.sa_family == AF_INET)
599 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
600 else if (su->sa.sa_family == AF_INET6)
601 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
602 su->sin6.sin6_scope_id,
603 bgp->vrf_id);
604
605 if (ifp)
606 return true;
607
608 return false;
609 }
610
611 /* Utility function for looking up peer or peer group. */
612 /* This is used only for configuration, so disallow if attempted on
613 * a dynamic neighbor.
614 */
615 struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
616 {
617 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
618 int ret;
619 union sockunion su;
620 struct peer *peer = NULL;
621 struct peer_group *group = NULL;
622
623 if (!bgp) {
624 return NULL;
625 }
626
627 ret = str2sockunion(peer_str, &su);
628 if (ret == 0) {
629 /* IP address, locate peer. */
630 peer = peer_lookup(bgp, &su);
631 } else {
632 /* Not IP, could match either peer configured on interface or a
633 * group. */
634 peer = peer_lookup_by_conf_if(bgp, peer_str);
635 if (!peer)
636 group = peer_group_lookup(bgp, peer_str);
637 }
638
639 if (peer) {
640 if (peer_dynamic_neighbor(peer)) {
641 vty_out(vty,
642 "%% Operation not allowed on a dynamic neighbor\n");
643 return NULL;
644 }
645
646 return peer;
647 }
648
649 if (group)
650 return group->conf;
651
652 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
653
654 return NULL;
655 }
656
657 int bgp_nb_errmsg_return(char *errmsg, size_t errmsg_len, int ret)
658 {
659 const char *str = NULL;
660
661 switch (ret) {
662 case BGP_ERR_INVALID_VALUE:
663 str = "Invalid value";
664 break;
665 case BGP_ERR_INVALID_FLAG:
666 str = "Invalid flag";
667 break;
668 case BGP_ERR_PEER_GROUP_SHUTDOWN:
669 str = "Peer-group has been shutdown. Activate the peer-group first";
670 break;
671 case BGP_ERR_PEER_FLAG_CONFLICT:
672 str = "Can't set override-capability and strict-capability-match at the same time";
673 break;
674 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
675 str = "Specify remote-as or peer-group remote AS first";
676 break;
677 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
678 str = "Cannot change the peer-group. Deconfigure first";
679 break;
680 case BGP_ERR_PEER_GROUP_MISMATCH:
681 str = "Peer is not a member of this peer-group";
682 break;
683 case BGP_ERR_PEER_FILTER_CONFLICT:
684 str = "Prefix/distribute list can not co-exist";
685 break;
686 case BGP_ERR_NOT_INTERNAL_PEER:
687 str = "Invalid command. Not an internal neighbor";
688 break;
689 case BGP_ERR_REMOVE_PRIVATE_AS:
690 str = "remove-private-AS cannot be configured for IBGP peers";
691 break;
692 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
693 str = "Local-AS allowed only for EBGP peers";
694 break;
695 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
696 str = "Cannot have local-as same as BGP AS number";
697 break;
698 case BGP_ERR_TCPSIG_FAILED:
699 str = "Error while applying TCP-Sig to session(s)";
700 break;
701 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
702 str = "ebgp-multihop and ttl-security cannot be configured together";
703 break;
704 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
705 str = "ttl-security only allowed for EBGP peers";
706 break;
707 case BGP_ERR_AS_OVERRIDE:
708 str = "as-override cannot be configured for IBGP peers";
709 break;
710 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
711 str = "Invalid limit for number of dynamic neighbors";
712 break;
713 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
714 str = "Dynamic neighbor listen range already exists";
715 break;
716 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
717 str = "Operation not allowed on a dynamic neighbor";
718 break;
719 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
720 str = "Operation not allowed on a directly connected neighbor";
721 break;
722 case BGP_ERR_PEER_SAFI_CONFLICT:
723 str = GR_INVALID;
724 break;
725 case BGP_ERR_GR_INVALID_CMD:
726 str = "The Graceful Restart command used is not valid at this moment.";
727 break;
728 case BGP_ERR_GR_OPERATION_FAILED:
729 str = "The Graceful Restart Operation failed due to an err.";
730 break;
731 case BGP_GR_NO_OPERATION:
732 str = GR_NO_OPER;
733 break;
734 case BGP_ERR_PEER_GROUP_MEMBER:
735 str = "Peer-group member cannot override remote-as of peer-group";
736 break;
737 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
738 str = "Peer-group members must be all internal or all external";
739 break;
740 }
741 if (str) {
742 snprintf(errmsg, errmsg_len, "%s", str);
743 return -1;
744 }
745
746 return 0;
747 }
748
749 int bgp_vty_return(struct vty *vty, int ret)
750 {
751 const char *str = NULL;
752
753 switch (ret) {
754 case BGP_ERR_INVALID_VALUE:
755 str = "Invalid value";
756 break;
757 case BGP_ERR_INVALID_FLAG:
758 str = "Invalid flag";
759 break;
760 case BGP_ERR_PEER_GROUP_SHUTDOWN:
761 str = "Peer-group has been shutdown. Activate the peer-group first";
762 break;
763 case BGP_ERR_PEER_FLAG_CONFLICT:
764 str = "Can't set override-capability and strict-capability-match at the same time";
765 break;
766 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
767 str = "Specify remote-as or peer-group remote AS first";
768 break;
769 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
770 str = "Cannot change the peer-group. Deconfigure first";
771 break;
772 case BGP_ERR_PEER_GROUP_MISMATCH:
773 str = "Peer is not a member of this peer-group";
774 break;
775 case BGP_ERR_PEER_FILTER_CONFLICT:
776 str = "Prefix/distribute list can not co-exist";
777 break;
778 case BGP_ERR_NOT_INTERNAL_PEER:
779 str = "Invalid command. Not an internal neighbor";
780 break;
781 case BGP_ERR_REMOVE_PRIVATE_AS:
782 str = "remove-private-AS cannot be configured for IBGP peers";
783 break;
784 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
785 str = "Local-AS allowed only for EBGP peers";
786 break;
787 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
788 str = "Cannot have local-as same as BGP AS number";
789 break;
790 case BGP_ERR_TCPSIG_FAILED:
791 str = "Error while applying TCP-Sig to session(s)";
792 break;
793 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
794 str = "ebgp-multihop and ttl-security cannot be configured together";
795 break;
796 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
797 str = "ttl-security only allowed for EBGP peers";
798 break;
799 case BGP_ERR_AS_OVERRIDE:
800 str = "as-override cannot be configured for IBGP peers";
801 break;
802 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
803 str = "Invalid limit for number of dynamic neighbors";
804 break;
805 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
806 str = "Dynamic neighbor listen range already exists";
807 break;
808 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
809 str = "Operation not allowed on a dynamic neighbor";
810 break;
811 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
812 str = "Operation not allowed on a directly connected neighbor";
813 break;
814 case BGP_ERR_PEER_SAFI_CONFLICT:
815 str = GR_INVALID;
816 break;
817 case BGP_ERR_GR_INVALID_CMD:
818 str = "The Graceful Restart command used is not valid at this moment.";
819 break;
820 case BGP_ERR_GR_OPERATION_FAILED:
821 str = "The Graceful Restart Operation failed due to an err.";
822 break;
823 case BGP_GR_NO_OPERATION:
824 str = GR_NO_OPER;
825 break;
826 }
827 if (str) {
828 vty_out(vty, "%% %s\n", str);
829 return CMD_WARNING_CONFIG_FAILED;
830 }
831 return CMD_SUCCESS;
832 }
833
834 /* BGP clear sort. */
835 enum clear_sort {
836 clear_all,
837 clear_peer,
838 clear_group,
839 clear_external,
840 clear_as
841 };
842
843 static void bgp_clear_vty_error(struct peer *peer, afi_t afi, safi_t safi,
844 int error, char *errmsg, size_t errmsg_len)
845 {
846 switch (error) {
847 case BGP_ERR_AF_UNCONFIGURED:
848 snprintf(errmsg, errmsg_len,
849 "%%BGP: Enable %s address family for the neighbor %s",
850 get_afi_safi_str(afi, safi, false), peer->host);
851 break;
852 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
853 snprintf(
854 errmsg, errmsg_len,
855 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig",
856 peer->host);
857 break;
858 default:
859 break;
860 }
861 }
862
863 static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi,
864 struct listnode **nnode, enum bgp_clear_type stype)
865 {
866 int ret = 0;
867
868 /* if afi/.safi not specified, spin thru all of them */
869 if ((afi == AFI_UNSPEC) && (safi == SAFI_UNSPEC)) {
870 afi_t tmp_afi;
871 safi_t tmp_safi;
872
873 FOREACH_AFI_SAFI (tmp_afi, tmp_safi) {
874 if (!peer->afc[tmp_afi][tmp_safi])
875 continue;
876
877 if (stype == BGP_CLEAR_SOFT_NONE)
878 ret = peer_clear(peer, nnode);
879 else
880 ret = peer_clear_soft(peer, tmp_afi, tmp_safi,
881 stype);
882 }
883 /* if afi specified and safi not, spin thru safis on this afi */
884 } else if (safi == SAFI_UNSPEC) {
885 safi_t tmp_safi;
886
887 for (tmp_safi = SAFI_UNICAST;
888 tmp_safi < SAFI_MAX; tmp_safi++) {
889 if (!peer->afc[afi][tmp_safi])
890 continue;
891
892 if (stype == BGP_CLEAR_SOFT_NONE)
893 ret = peer_clear(peer, nnode);
894 else
895 ret = peer_clear_soft(peer, afi,
896 tmp_safi, stype);
897 }
898 /* both afi/safi specified, let the caller know if not defined */
899 } else {
900 if (!peer->afc[afi][safi])
901 return 1;
902
903 if (stype == BGP_CLEAR_SOFT_NONE)
904 ret = peer_clear(peer, nnode);
905 else
906 ret = peer_clear_soft(peer, afi, safi, stype);
907 }
908
909 return ret;
910 }
911
912 /* `clear ip bgp' functions. */
913 static int bgp_clear(struct bgp *bgp, afi_t afi, safi_t safi,
914 enum clear_sort sort, enum bgp_clear_type stype,
915 const char *arg, char *errmsg, size_t errmsg_len)
916 {
917 int ret = 0;
918 bool found = false;
919 struct peer *peer;
920
921 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
922
923 /* Clear all neighbors. */
924 /*
925 * Pass along pointer to next node to peer_clear() when walking all
926 * nodes on the BGP instance as that may get freed if it is a
927 * doppelganger
928 */
929 if (sort == clear_all) {
930 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
931
932 bgp_peer_gr_flags_update(peer);
933
934 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
935 gr_router_detected = true;
936
937 ret = bgp_peer_clear(peer, afi, safi, &nnode,
938 stype);
939
940 if (ret < 0)
941 bgp_clear_vty_error(peer, afi, safi, ret,
942 errmsg, errmsg_len);
943 }
944
945 if (gr_router_detected
946 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
947 bgp_zebra_send_capabilities(bgp, false);
948 } else if (!gr_router_detected
949 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
950 bgp_zebra_send_capabilities(bgp, true);
951 }
952
953 /* This is to apply read-only mode on this clear. */
954 if (stype == BGP_CLEAR_SOFT_NONE)
955 bgp->update_delay_over = 0;
956
957 return CMD_SUCCESS;
958 }
959
960 /* Clear specified neighbor. */
961 if (sort == clear_peer) {
962 union sockunion su;
963
964 /* Make sockunion for lookup. */
965 ret = str2sockunion(arg, &su);
966 if (ret < 0) {
967 peer = peer_lookup_by_conf_if(bgp, arg);
968 if (!peer) {
969 peer = peer_lookup_by_hostname(bgp, arg);
970 if (!peer) {
971 snprintf(
972 errmsg, errmsg_len,
973 "Malformed address or name: %s",
974 arg);
975 return CMD_WARNING;
976 }
977 }
978 } else {
979 peer = peer_lookup(bgp, &su);
980 if (!peer) {
981 snprintf(errmsg, errmsg_len,
982 "%%BGP: Unknown neighbor - \"%s\"",
983 arg);
984 return CMD_WARNING;
985 }
986 }
987
988 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
989 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
990
991 ret = bgp_peer_clear(peer, afi, safi, NULL, stype);
992
993 /* if afi/safi not defined for this peer, let caller know */
994 if (ret == 1)
995 ret = BGP_ERR_AF_UNCONFIGURED;
996
997 if (ret < 0)
998 bgp_clear_vty_error(peer, afi, safi, ret, errmsg,
999 errmsg_len);
1000
1001 return CMD_SUCCESS;
1002 }
1003
1004 /* Clear all neighbors belonging to a specific peer-group. */
1005 if (sort == clear_group) {
1006 struct peer_group *group;
1007
1008 group = peer_group_lookup(bgp, arg);
1009 if (!group) {
1010 snprintf(errmsg, errmsg_len,
1011 "%%BGP: No such peer-group %s", arg);
1012 return CMD_WARNING;
1013 }
1014
1015 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
1016 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1017
1018 if (ret < 0)
1019 bgp_clear_vty_error(peer, afi, safi, ret,
1020 errmsg, errmsg_len);
1021 else
1022 found = true;
1023 }
1024
1025 if (!found)
1026 snprintf(
1027 errmsg, errmsg_len,
1028 "%%BGP: No %s peer belonging to peer-group %s is configured",
1029 get_afi_safi_str(afi, safi, false), arg);
1030
1031 return CMD_SUCCESS;
1032 }
1033
1034 /* Clear all external (eBGP) neighbors. */
1035 if (sort == clear_external) {
1036 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1037 if (peer->sort == BGP_PEER_IBGP)
1038 continue;
1039
1040 bgp_peer_gr_flags_update(peer);
1041
1042 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1043 gr_router_detected = true;
1044
1045 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1046
1047 if (ret < 0)
1048 bgp_clear_vty_error(peer, afi, safi, ret,
1049 errmsg, errmsg_len);
1050 else
1051 found = true;
1052 }
1053
1054 if (gr_router_detected
1055 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1056 bgp_zebra_send_capabilities(bgp, false);
1057 } else if (!gr_router_detected
1058 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1059 bgp_zebra_send_capabilities(bgp, true);
1060 }
1061
1062 if (!found)
1063 snprintf(errmsg, errmsg_len,
1064 "%%BGP: No external %s peer is configured",
1065 get_afi_safi_str(afi, safi, false));
1066
1067 return CMD_SUCCESS;
1068 }
1069
1070 /* Clear all neighbors belonging to a specific AS. */
1071 if (sort == clear_as) {
1072 as_t as = strtoul(arg, NULL, 10);
1073
1074 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1075 if (peer->as != as)
1076 continue;
1077
1078 bgp_peer_gr_flags_update(peer);
1079
1080 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1081 gr_router_detected = true;
1082
1083 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1084
1085 if (ret < 0)
1086 bgp_clear_vty_error(peer, afi, safi, ret,
1087 errmsg, errmsg_len);
1088 else
1089 found = true;
1090 }
1091
1092 if (gr_router_detected
1093 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1094 bgp_zebra_send_capabilities(bgp, false);
1095 } else if (!gr_router_detected
1096 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1097 bgp_zebra_send_capabilities(bgp, true);
1098 }
1099
1100 if (!found)
1101 snprintf(errmsg, errmsg_len,
1102 "%%BGP: No %s peer is configured with AS %s",
1103 get_afi_safi_str(afi, safi, false), arg);
1104
1105 return CMD_SUCCESS;
1106 }
1107
1108 return CMD_SUCCESS;
1109 }
1110
1111 static int bgp_clear_vty(const char *name, afi_t afi, safi_t safi,
1112 enum clear_sort sort, enum bgp_clear_type stype,
1113 const char *arg, char *errmsg, size_t errmsg_len)
1114 {
1115 struct bgp *bgp;
1116
1117 /* BGP structure lookup. */
1118 if (name) {
1119 bgp = bgp_lookup_by_name(name);
1120 if (bgp == NULL) {
1121 snprintf(errmsg, errmsg_len,
1122 "Can't find BGP instance %s", name);
1123 return CMD_WARNING;
1124 }
1125 } else {
1126 bgp = bgp_get_default();
1127 if (bgp == NULL) {
1128 snprintf(errmsg, errmsg_len,
1129 "No BGP process is configured");
1130 return CMD_WARNING;
1131 }
1132 }
1133
1134 return bgp_clear(bgp, afi, safi, sort, stype, arg, errmsg, errmsg_len);
1135 }
1136
1137 /* clear soft inbound */
1138 int bgp_clear_star_soft_in(const char *name, char *errmsg, size_t errmsg_len)
1139 {
1140 afi_t afi;
1141 safi_t safi;
1142 int ret;
1143
1144 FOREACH_AFI_SAFI (afi, safi) {
1145 ret = bgp_clear_vty(name, afi, safi, clear_all,
1146 BGP_CLEAR_SOFT_IN, NULL, errmsg,
1147 errmsg_len);
1148 if (ret != CMD_SUCCESS)
1149 return -1;
1150 }
1151
1152 return 0;
1153 }
1154
1155 /* clear soft outbound */
1156 int bgp_clear_star_soft_out(const char *name, char *errmsg, size_t errmsg_len)
1157 {
1158 afi_t afi;
1159 safi_t safi;
1160 int ret;
1161
1162 FOREACH_AFI_SAFI (afi, safi) {
1163 ret = bgp_clear_vty(name, afi, safi, clear_all,
1164 BGP_CLEAR_SOFT_OUT, NULL, errmsg,
1165 errmsg_len);
1166 if (ret != CMD_SUCCESS)
1167 return -1;
1168 }
1169
1170 return 0;
1171 }
1172
1173
1174 #ifndef VTYSH_EXTRACT_PL
1175 #include "bgpd/bgp_vty_clippy.c"
1176 #endif
1177
1178 DEFUN_HIDDEN (bgp_local_mac,
1179 bgp_local_mac_cmd,
1180 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
1181 BGP_STR
1182 "Local MAC config\n"
1183 "VxLAN Network Identifier\n"
1184 "VNI number\n"
1185 "local mac\n"
1186 "mac address\n"
1187 "mac-mobility sequence\n"
1188 "seq number\n")
1189 {
1190 int rv;
1191 vni_t vni;
1192 struct ethaddr mac;
1193 struct ipaddr ip;
1194 uint32_t seq;
1195 struct bgp *bgp;
1196
1197 vni = strtoul(argv[3]->arg, NULL, 10);
1198 if (!prefix_str2mac(argv[5]->arg, &mac)) {
1199 vty_out(vty, "%% Malformed MAC address\n");
1200 return CMD_WARNING;
1201 }
1202 memset(&ip, 0, sizeof(ip));
1203 seq = strtoul(argv[7]->arg, NULL, 10);
1204
1205 bgp = bgp_get_default();
1206 if (!bgp) {
1207 vty_out(vty, "Default BGP instance is not there\n");
1208 return CMD_WARNING;
1209 }
1210
1211 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq,
1212 zero_esi);
1213 if (rv < 0) {
1214 vty_out(vty, "Internal error\n");
1215 return CMD_WARNING;
1216 }
1217
1218 return CMD_SUCCESS;
1219 }
1220
1221 DEFUN_HIDDEN (no_bgp_local_mac,
1222 no_bgp_local_mac_cmd,
1223 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
1224 NO_STR
1225 BGP_STR
1226 "Local MAC config\n"
1227 "VxLAN Network Identifier\n"
1228 "VNI number\n"
1229 "local mac\n"
1230 "mac address\n")
1231 {
1232 int rv;
1233 vni_t vni;
1234 struct ethaddr mac;
1235 struct ipaddr ip;
1236 struct bgp *bgp;
1237
1238 vni = strtoul(argv[4]->arg, NULL, 10);
1239 if (!prefix_str2mac(argv[6]->arg, &mac)) {
1240 vty_out(vty, "%% Malformed MAC address\n");
1241 return CMD_WARNING;
1242 }
1243 memset(&ip, 0, sizeof(ip));
1244
1245 bgp = bgp_get_default();
1246 if (!bgp) {
1247 vty_out(vty, "Default BGP instance is not there\n");
1248 return CMD_WARNING;
1249 }
1250
1251 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
1252 if (rv < 0) {
1253 vty_out(vty, "Internal error\n");
1254 return CMD_WARNING;
1255 }
1256
1257 return CMD_SUCCESS;
1258 }
1259
1260 DEFUN (no_synchronization,
1261 no_synchronization_cmd,
1262 "no synchronization",
1263 NO_STR
1264 "Perform IGP synchronization\n")
1265 {
1266 return CMD_SUCCESS;
1267 }
1268
1269 DEFUN (no_auto_summary,
1270 no_auto_summary_cmd,
1271 "no auto-summary",
1272 NO_STR
1273 "Enable automatic network number summarization\n")
1274 {
1275 return CMD_SUCCESS;
1276 }
1277
1278 /* "router bgp" commands. */
1279 DEFUN_YANG_NOSH(router_bgp,
1280 router_bgp_cmd,
1281 "router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1282 ROUTER_STR BGP_STR AS_STR BGP_INSTANCE_HELP_STR)
1283 {
1284 int idx_asn = 2;
1285 int idx_view_vrf = 3;
1286 int idx_vrf = 4;
1287 int ret = CMD_SUCCESS;
1288 as_t as;
1289 struct bgp *bgp;
1290 const char *name = NULL;
1291 char as_str[12] = {'\0'};
1292 enum bgp_instance_type inst_type;
1293 char base_xpath[XPATH_MAXLEN];
1294
1295 // "router bgp" without an ASN
1296 if (argc == 2) {
1297 // Pending: Make VRF option available for ASN less config
1298 bgp = bgp_get_default();
1299
1300 if (bgp == NULL) {
1301 vty_out(vty, "%% No BGP process is configured\n");
1302 return CMD_WARNING_CONFIG_FAILED;
1303 }
1304
1305 if (listcount(bm->bgp) > 1) {
1306 vty_out(vty, "%% Please specify ASN and VRF\n");
1307 return CMD_WARNING_CONFIG_FAILED;
1308 }
1309
1310 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_GLOBAL_XPATH,
1311 "frr-bgp:bgp", "bgp", VRF_DEFAULT_NAME);
1312
1313 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
1314 snprintf(as_str, 12, "%d", bgp->as);
1315 nb_cli_enqueue_change(vty, "./global/local-as", NB_OP_MODIFY,
1316 as_str);
1317 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW) {
1318 nb_cli_enqueue_change(vty,
1319 "./global/instance-type-view",
1320 NB_OP_MODIFY, "true");
1321 }
1322
1323 nb_cli_pending_commit_check(vty);
1324 ret = nb_cli_apply_changes(vty, base_xpath);
1325 if (ret == CMD_SUCCESS) {
1326 VTY_PUSH_XPATH(BGP_NODE, base_xpath);
1327
1328 /*
1329 * For backward compatibility with old commands we still
1330 * need to use the qobj infrastructure.
1331 */
1332 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1333 }
1334 return ret;
1335 }
1336
1337 // "router bgp X"
1338 else {
1339
1340 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1341 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1342 if (argc > 3) {
1343 name = argv[idx_vrf]->arg;
1344
1345 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1346 if (strmatch(name, VRF_DEFAULT_NAME))
1347 name = NULL;
1348 else
1349 inst_type = BGP_INSTANCE_TYPE_VRF;
1350 } else if (!strcmp(argv[idx_view_vrf]->text, "view")) {
1351 inst_type = BGP_INSTANCE_TYPE_VIEW;
1352 }
1353 }
1354 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_GLOBAL_XPATH,
1355 "frr-bgp:bgp", "bgp", name ? name : VRF_DEFAULT_NAME);
1356
1357 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
1358 nb_cli_enqueue_change(vty, "./global/local-as", NB_OP_MODIFY,
1359 argv[idx_asn]->arg);
1360 if (inst_type == BGP_INSTANCE_TYPE_VIEW) {
1361 nb_cli_enqueue_change(vty,
1362 "./global/instance-type-view",
1363 NB_OP_MODIFY, "true");
1364 }
1365
1366 nb_cli_pending_commit_check(vty);
1367 ret = nb_cli_apply_changes(vty, base_xpath);
1368 if (ret == CMD_SUCCESS) {
1369 VTY_PUSH_XPATH(BGP_NODE, base_xpath);
1370
1371 /*
1372 * For backward compatibility with old commands we still
1373 * need to use the qobj infrastructure.
1374 */
1375 bgp = bgp_lookup(as, name);
1376 if (bgp)
1377 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1378 }
1379 }
1380
1381 return ret;
1382 }
1383
1384 /* "no router bgp" commands. */
1385 DEFUN_YANG(no_router_bgp,
1386 no_router_bgp_cmd,
1387 "no router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1388 NO_STR ROUTER_STR BGP_STR AS_STR BGP_INSTANCE_HELP_STR)
1389 {
1390 int idx_asn = 3;
1391 int idx_vrf = 5;
1392 as_t as = 0;
1393 struct bgp *bgp;
1394 const char *name = NULL;
1395 char base_xpath[XPATH_MAXLEN];
1396 const struct lyd_node *bgp_glb_dnode;
1397
1398 // "no router bgp" without an ASN
1399 if (argc == 3) {
1400 // Pending: Make VRF option available for ASN less config
1401 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_GLOBAL_XPATH,
1402 "frr-bgp:bgp", "bgp", VRF_DEFAULT_NAME);
1403
1404 bgp_glb_dnode = yang_dnode_get(vty->candidate_config->dnode,
1405 base_xpath);
1406 if (!bgp_glb_dnode) {
1407 vty_out(vty, "%% No BGP process is configured\n");
1408 return CMD_WARNING_CONFIG_FAILED;
1409 }
1410
1411 if (listcount(bm->bgp) > 1) {
1412 vty_out(vty, "%% Please specify ASN and VRF\n");
1413 return CMD_WARNING_CONFIG_FAILED;
1414 }
1415
1416 /* tcli mode bgp would not be set until apply stage. */
1417 bgp = nb_running_get_entry(bgp_glb_dnode, NULL, false);
1418 if (!bgp)
1419 return CMD_SUCCESS;
1420
1421 if (bgp->l3vni) {
1422 vty_out(vty, "%% Please unconfigure l3vni %u",
1423 bgp->l3vni);
1424 return CMD_WARNING_CONFIG_FAILED;
1425 }
1426 } else {
1427 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1428
1429 if (argc > 4)
1430 name = argv[idx_vrf]->arg;
1431
1432 /* Lookup bgp structure. */
1433 bgp = bgp_lookup(as, name);
1434 if (!bgp) {
1435 vty_out(vty, "%% Can't find BGP instance\n");
1436 return CMD_WARNING_CONFIG_FAILED;
1437 }
1438
1439 if (bgp->l3vni) {
1440 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1441 bgp->l3vni);
1442 return CMD_WARNING_CONFIG_FAILED;
1443 }
1444
1445 /* Cannot delete default instance if vrf instances exist */
1446 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
1447 struct listnode *node;
1448 struct bgp *tmp_bgp;
1449
1450 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, tmp_bgp)) {
1451 if (tmp_bgp->inst_type
1452 == BGP_INSTANCE_TYPE_VRF) {
1453 vty_out(vty,
1454 "%% Cannot delete default BGP instance. Dependent VRF instances exist\n");
1455 return CMD_WARNING_CONFIG_FAILED;
1456 }
1457 }
1458 }
1459 }
1460 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_GLOBAL_XPATH,
1461 "frr-bgp:bgp", "bgp",
1462 bgp->name ? bgp->name : VRF_DEFAULT_NAME);
1463
1464 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
1465
1466 return nb_cli_apply_changes(vty, base_xpath);
1467 }
1468
1469 void cli_show_router_bgp(struct vty *vty, struct lyd_node *dnode,
1470 bool show_defaults)
1471 {
1472 const struct lyd_node *vrf_dnode;
1473 const char *vrf_name;
1474 as_t as;
1475
1476 vrf_dnode = yang_dnode_get_parent(dnode, "control-plane-protocol");
1477 vrf_name = yang_dnode_get_string(vrf_dnode, "./vrf");
1478 as = yang_dnode_get_uint32(dnode, "./global/local-as");
1479
1480 vty_out(vty, "!\n");
1481 vty_out(vty, "router bgp %u", as);
1482 if (!strmatch(vrf_name, VRF_DEFAULT_NAME))
1483 vty_out(vty, " vrf %s", vrf_name);
1484 vty_out(vty, "\n");
1485 }
1486
1487 /* BGP router-id. */
1488
1489 DEFPY_YANG(bgp_router_id, bgp_router_id_cmd, "bgp router-id A.B.C.D",
1490 BGP_STR
1491 "Override configured router identifier\n"
1492 "Manually configured router identifier\n")
1493 {
1494 nb_cli_enqueue_change(vty, "./global/router-id", NB_OP_MODIFY,
1495 router_id_str);
1496
1497 return nb_cli_apply_changes(vty, NULL);
1498 }
1499
1500 DEFPY_YANG(no_bgp_router_id, no_bgp_router_id_cmd, "no bgp router-id [A.B.C.D]",
1501 NO_STR BGP_STR
1502 "Override configured router identifier\n"
1503 "Manually configured router identifier\n")
1504 {
1505 nb_cli_enqueue_change(vty, "./global/router-id", NB_OP_DESTROY,
1506 router_id_str ? router_id_str : NULL);
1507
1508 return nb_cli_apply_changes(vty, NULL);
1509 }
1510
1511 void cli_show_router_bgp_router_id(struct vty *vty, struct lyd_node *dnode,
1512 bool show_defaults)
1513 {
1514 vty_out(vty, " bgp router-id %s\n", yang_dnode_get_string(dnode, NULL));
1515 }
1516
1517 DEFPY (bgp_suppress_fib_pending,
1518 bgp_suppress_fib_pending_cmd,
1519 "[no] bgp suppress-fib-pending",
1520 NO_STR
1521 BGP_STR
1522 "Advertise only routes that are programmed in kernel to peers\n")
1523 {
1524 VTY_DECLVAR_CONTEXT(bgp, bgp);
1525
1526 bgp_suppress_fib_pending_set(bgp, !no);
1527 return CMD_SUCCESS;
1528 }
1529
1530
1531 /* BGP Cluster ID. */
1532 DEFUN_YANG(bgp_cluster_id,
1533 bgp_cluster_id_cmd,
1534 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1535 BGP_STR
1536 "Configure Route-Reflector Cluster-id\n"
1537 "Route-Reflector Cluster-id in IP address format\n"
1538 "Route-Reflector Cluster-id as 32 bit quantity\n")
1539 {
1540 int idx_ipv4 = 2;
1541
1542 nb_cli_enqueue_change(
1543 vty, "./global/route-reflector/route-reflector-cluster-id",
1544 NB_OP_MODIFY, argv[idx_ipv4]->arg);
1545
1546 return nb_cli_apply_changes(vty, NULL);
1547 }
1548
1549 DEFUN_YANG(no_bgp_cluster_id,
1550 no_bgp_cluster_id_cmd,
1551 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1552 NO_STR BGP_STR
1553 "Configure Route-Reflector Cluster-id\n"
1554 "Route-Reflector Cluster-id in IP address format\n"
1555 "Route-Reflector Cluster-id as 32 bit quantity\n")
1556 {
1557 nb_cli_enqueue_change(
1558 vty, "./global/route-reflector/route-reflector-cluster-id",
1559 NB_OP_DESTROY, NULL);
1560
1561 return nb_cli_apply_changes(vty, NULL);
1562 }
1563
1564 DEFPY (bgp_norib,
1565 bgp_norib_cmd,
1566 "bgp no-rib",
1567 BGP_STR
1568 "Disable BGP route installation to RIB (Zebra)\n")
1569 {
1570 if (bgp_option_check(BGP_OPT_NO_FIB)) {
1571 vty_out(vty,
1572 "%% No-RIB option is already set, nothing to do here.\n");
1573 return CMD_SUCCESS;
1574 }
1575
1576 bgp_option_norib_set_runtime();
1577
1578 return CMD_SUCCESS;
1579 }
1580
1581 DEFPY (no_bgp_norib,
1582 no_bgp_norib_cmd,
1583 "no bgp no-rib",
1584 NO_STR
1585 BGP_STR
1586 "Disable BGP route installation to RIB (Zebra)\n")
1587 {
1588 if (!bgp_option_check(BGP_OPT_NO_FIB)) {
1589 vty_out(vty,
1590 "%% No-RIB option is not set, nothing to do here.\n");
1591 return CMD_SUCCESS;
1592 }
1593
1594 bgp_option_norib_unset_runtime();
1595
1596 return CMD_SUCCESS;
1597 }
1598
1599 DEFUN_YANG(bgp_confederation_identifier,
1600 bgp_confederation_identifier_cmd,
1601 "bgp confederation identifier (1-4294967295)",
1602 "BGP specific commands\n"
1603 "AS confederation parameters\n"
1604 "AS number\n"
1605 "Set routing domain confederation AS\n")
1606 {
1607 int idx_number = 3;
1608
1609 nb_cli_enqueue_change(vty, "./global/confederation/identifier",
1610 NB_OP_MODIFY, argv[idx_number]->arg);
1611
1612 return nb_cli_apply_changes(vty, NULL);
1613 }
1614
1615 DEFUN_YANG(no_bgp_confederation_identifier,
1616 no_bgp_confederation_identifier_cmd,
1617 "no bgp confederation identifier [(1-4294967295)]",
1618 NO_STR
1619 "BGP specific commands\n"
1620 "AS confederation parameters\n"
1621 "AS number\n"
1622 "Set routing domain confederation AS\n")
1623 {
1624 nb_cli_enqueue_change(vty, "./global/confederation/identifier",
1625 NB_OP_DESTROY, NULL);
1626
1627 return nb_cli_apply_changes(vty, NULL);
1628 }
1629
1630 void cli_show_router_bgp_confederation_identifier(struct vty *vty,
1631 struct lyd_node *dnode,
1632 bool show_defaults)
1633 {
1634 vty_out(vty, " bgp confederation identifier %u\n",
1635 yang_dnode_get_uint32(dnode, NULL));
1636 }
1637
1638 DEFUN_YANG(bgp_confederation_peers,
1639 bgp_confederation_peers_cmd,
1640 "bgp confederation peers (1-4294967295)...",
1641 "BGP specific commands\n"
1642 "AS confederation parameters\n"
1643 "Peer ASs in BGP confederation\n" AS_STR)
1644 {
1645 int idx_asn = 3;
1646 int i;
1647
1648 for (i = idx_asn; i < argc; i++)
1649 nb_cli_enqueue_change(vty, "./global/confederation/member-as",
1650 NB_OP_CREATE, argv[i]->arg);
1651
1652 return nb_cli_apply_changes(vty, NULL);
1653 }
1654
1655 DEFUN_YANG(no_bgp_confederation_peers,
1656 no_bgp_confederation_peers_cmd,
1657 "no bgp confederation peers (1-4294967295)...",
1658 NO_STR
1659 "BGP specific commands\n"
1660 "AS confederation parameters\n"
1661 "Peer ASs in BGP confederation\n" AS_STR)
1662 {
1663 int idx_asn = 4;
1664 int i;
1665
1666 for (i = idx_asn; i < argc; i++)
1667 nb_cli_enqueue_change(vty, "./global/confederation/member-as",
1668 NB_OP_DESTROY, argv[i]->arg);
1669
1670 return nb_cli_apply_changes(vty, NULL);
1671 }
1672
1673 void cli_show_router_bgp_confederation_member_as(struct vty *vty,
1674 struct lyd_node *dnode,
1675 bool show_defaults)
1676 {
1677 vty_out(vty, " bgp confederation peers %u \n",
1678 yang_dnode_get_uint32(dnode, NULL));
1679 }
1680
1681 /**
1682 * Central routine for maximum-paths configuration.
1683 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1684 * @set: 1 for setting values, 0 for removing the max-paths config.
1685 */
1686 int bgp_maxpaths_config_vty(struct bgp *bgp, afi_t afi, safi_t safi,
1687 int peer_type, uint16_t maxpaths, uint16_t options,
1688 int set, char *errmsg, size_t errmsg_len)
1689 {
1690 int ret;
1691
1692 if (set) {
1693 if (maxpaths > multipath_num) {
1694 snprintf(
1695 errmsg, errmsg_len,
1696 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1697 maxpaths, multipath_num);
1698 return CMD_WARNING_CONFIG_FAILED;
1699 }
1700 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1701 options);
1702 } else
1703 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1704
1705 if (ret < 0) {
1706 snprintf(
1707 errmsg, errmsg_len,
1708 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1709 (set == 1) ? "" : "un",
1710 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1711 maxpaths, afi, safi);
1712 return CMD_WARNING_CONFIG_FAILED;
1713 }
1714
1715 bgp_recalculate_all_bestpaths(bgp);
1716
1717 return CMD_SUCCESS;
1718 }
1719
1720 void cli_show_router_bgp_med_config(struct vty *vty, struct lyd_node *dnode,
1721 bool show_defaults)
1722 {
1723 if (yang_dnode_get_bool(dnode, "./enable-med-admin")) {
1724 uint32_t med_admin_val;
1725
1726 vty_out(vty, " bgp max-med administrative");
1727 if ((med_admin_val =
1728 yang_dnode_get_uint32(dnode, "./max-med-admin"))
1729 != BGP_MAXMED_VALUE_DEFAULT)
1730 vty_out(vty, " %u", med_admin_val);
1731 vty_out(vty, "\n");
1732 }
1733
1734 if (yang_dnode_exists(dnode, "./max-med-onstart-up-time")) {
1735 uint32_t onstartup_val;
1736
1737 vty_out(vty, " bgp max-med on-startup %u",
1738 yang_dnode_get_uint32(dnode,
1739 "./max-med-onstart-up-time"));
1740 onstartup_val = yang_dnode_get_uint32(
1741 dnode, "./max-med-onstart-up-value");
1742 if (onstartup_val != BGP_MAXMED_VALUE_DEFAULT)
1743 vty_out(vty, " %u", onstartup_val);
1744
1745 vty_out(vty, "\n");
1746 }
1747 }
1748
1749 DEFUN_YANG(bgp_maxmed_admin,
1750 bgp_maxmed_admin_cmd,
1751 "bgp max-med administrative ",
1752 BGP_STR
1753 "Advertise routes with max-med\n"
1754 "Administratively applied, for an indefinite period\n")
1755 {
1756 nb_cli_enqueue_change(vty, "./global/med-config/enable-med-admin",
1757 NB_OP_MODIFY, "true");
1758
1759 return nb_cli_apply_changes(vty, NULL);
1760 }
1761
1762 DEFUN_YANG(bgp_maxmed_admin_medv,
1763 bgp_maxmed_admin_medv_cmd,
1764 "bgp max-med administrative (0-4294967295)",
1765 BGP_STR
1766 "Advertise routes with max-med\n"
1767 "Administratively applied, for an indefinite period\n"
1768 "Max MED value to be used\n")
1769 {
1770 int idx_number = 3;
1771
1772 nb_cli_enqueue_change(vty, "./global/med-config/enable-med-admin",
1773 NB_OP_MODIFY, "true");
1774
1775 nb_cli_enqueue_change(vty, "./global/med-config/max-med-admin",
1776 NB_OP_MODIFY, argv[idx_number]->arg);
1777
1778 return nb_cli_apply_changes(vty, NULL);
1779 }
1780
1781 DEFUN_YANG(no_bgp_maxmed_admin,
1782 no_bgp_maxmed_admin_cmd,
1783 "no bgp max-med administrative [(0-4294967295)]",
1784 NO_STR BGP_STR
1785 "Advertise routes with max-med\n"
1786 "Administratively applied, for an indefinite period\n"
1787 "Max MED value to be used\n")
1788 {
1789 nb_cli_enqueue_change(vty, "./global/med-config/enable-med-admin",
1790 NB_OP_MODIFY, "false");
1791
1792 nb_cli_enqueue_change(vty, "./global/med-config/max-med-admin",
1793 NB_OP_MODIFY, NULL);
1794
1795 return nb_cli_apply_changes(vty, NULL);
1796 }
1797
1798 DEFUN_YANG (bgp_maxmed_onstartup,
1799 bgp_maxmed_onstartup_cmd,
1800 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
1801 BGP_STR
1802 "Advertise routes with max-med\n"
1803 "Effective on a startup\n"
1804 "Time (seconds) period for max-med\n"
1805 "Max MED value to be used\n")
1806 {
1807 int idx = 0;
1808
1809 argv_find(argv, argc, "(5-86400)", &idx);
1810 nb_cli_enqueue_change(vty,
1811 "./global/med-config/max-med-onstart-up-time",
1812 NB_OP_MODIFY, argv[idx]->arg);
1813
1814 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1815 nb_cli_enqueue_change(
1816 vty, "./global/med-config/max-med-onstart-up-value",
1817 NB_OP_MODIFY, argv[idx]->arg);
1818 else
1819 nb_cli_enqueue_change(
1820 vty, "./global/med-config/max-med-onstart-up-value",
1821 NB_OP_MODIFY, NULL);
1822
1823 return nb_cli_apply_changes(vty, NULL);
1824 }
1825
1826 DEFUN_YANG (no_bgp_maxmed_onstartup,
1827 no_bgp_maxmed_onstartup_cmd,
1828 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
1829 NO_STR BGP_STR
1830 "Advertise routes with max-med\n"
1831 "Effective on a startup\n"
1832 "Time (seconds) period for max-med\n"
1833 "Max MED value to be used\n")
1834 {
1835 nb_cli_enqueue_change(vty,
1836 "./global/med-config/max-med-onstart-up-time",
1837 NB_OP_DESTROY, NULL);
1838
1839 nb_cli_enqueue_change(vty,
1840 "./global/med-config/max-med-onstart-up-value",
1841 NB_OP_MODIFY, NULL);
1842
1843 return nb_cli_apply_changes(vty, NULL);
1844 }
1845
1846 static int bgp_global_update_delay_config_vty(struct vty *vty,
1847 uint16_t update_delay,
1848 uint16_t establish_wait)
1849 {
1850 struct listnode *node, *nnode;
1851 struct bgp *bgp;
1852 bool vrf_cfg = false;
1853
1854 /*
1855 * See if update-delay is set per-vrf and warn user to delete it
1856 * Note that we only need to check this if this is the first time
1857 * setting the global config.
1858 */
1859 if (bm->v_update_delay == BGP_UPDATE_DELAY_DEF) {
1860 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
1861 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1862 vty_out(vty,
1863 "%% update-delay configuration found in vrf %s\n",
1864 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT
1865 ? VRF_DEFAULT_NAME
1866 : bgp->name);
1867 vrf_cfg = true;
1868 }
1869 }
1870 }
1871
1872 if (vrf_cfg) {
1873 vty_out(vty,
1874 "%%Failed: global update-delay config not permitted\n");
1875 return CMD_WARNING;
1876 }
1877
1878 if (!establish_wait) { /* update-delay <delay> */
1879 bm->v_update_delay = update_delay;
1880 bm->v_establish_wait = bm->v_update_delay;
1881 } else {
1882 /* update-delay <delay> <establish-wait> */
1883 if (update_delay < establish_wait) {
1884 vty_out(vty,
1885 "%%Failed: update-delay less than the establish-wait!\n");
1886 return CMD_WARNING_CONFIG_FAILED;
1887 }
1888
1889 bm->v_update_delay = update_delay;
1890 bm->v_establish_wait = establish_wait;
1891 }
1892
1893 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
1894 bgp->v_update_delay = bm->v_update_delay;
1895 bgp->v_establish_wait = bm->v_establish_wait;
1896 }
1897
1898 return CMD_SUCCESS;
1899 }
1900
1901 static int bgp_global_update_delay_deconfig_vty(struct vty *vty)
1902 {
1903 struct listnode *node, *nnode;
1904 struct bgp *bgp;
1905
1906 bm->v_update_delay = BGP_UPDATE_DELAY_DEF;
1907 bm->v_establish_wait = bm->v_update_delay;
1908
1909 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
1910 bgp->v_update_delay = bm->v_update_delay;
1911 bgp->v_establish_wait = bm->v_establish_wait;
1912 }
1913
1914 return CMD_SUCCESS;
1915 }
1916
1917 static int bgp_update_delay_config_vty(struct vty *vty, uint16_t update_delay,
1918 uint16_t establish_wait)
1919 {
1920 VTY_DECLVAR_CONTEXT(bgp, bgp);
1921
1922 /* if configured globally, per-instance config is not allowed */
1923 if (bm->v_update_delay) {
1924 vty_out(vty,
1925 "%%Failed: per-vrf update-delay config not permitted with global update-delay\n");
1926 return CMD_WARNING_CONFIG_FAILED;
1927 }
1928
1929
1930 if (!establish_wait) /* update-delay <delay> */
1931 {
1932 bgp->v_update_delay = update_delay;
1933 bgp->v_establish_wait = bgp->v_update_delay;
1934 return CMD_SUCCESS;
1935 }
1936
1937 /* update-delay <delay> <establish-wait> */
1938 if (update_delay < establish_wait) {
1939 vty_out(vty,
1940 "%%Failed: update-delay less than the establish-wait!\n");
1941 return CMD_WARNING_CONFIG_FAILED;
1942 }
1943
1944 bgp->v_update_delay = update_delay;
1945 bgp->v_establish_wait = establish_wait;
1946
1947 return CMD_SUCCESS;
1948 }
1949
1950 static int bgp_update_delay_deconfig_vty(struct vty *vty)
1951 {
1952 VTY_DECLVAR_CONTEXT(bgp, bgp);
1953
1954 /* If configured globally, cannot remove from one bgp instance */
1955 if (bm->v_update_delay) {
1956 vty_out(vty,
1957 "%%Failed: bgp update-delay configured globally. Delete per-vrf not permitted\n");
1958 return CMD_WARNING_CONFIG_FAILED;
1959 }
1960 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
1961 bgp->v_establish_wait = bgp->v_update_delay;
1962
1963 return CMD_SUCCESS;
1964 }
1965
1966 void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
1967 {
1968 /* If configured globally, no need to display per-instance value */
1969 if (bgp->v_update_delay != bm->v_update_delay) {
1970 vty_out(vty, " update-delay %d", bgp->v_update_delay);
1971 if (bgp->v_update_delay != bgp->v_establish_wait)
1972 vty_out(vty, " %d", bgp->v_establish_wait);
1973 vty_out(vty, "\n");
1974 }
1975 }
1976
1977 /* Global update-delay configuration */
1978 DEFPY (bgp_global_update_delay,
1979 bgp_global_update_delay_cmd,
1980 "bgp update-delay (0-3600)$delay [(1-3600)$wait]",
1981 BGP_STR
1982 "Force initial delay for best-path and updates for all bgp instances\n"
1983 "Max delay in seconds\n"
1984 "Establish wait in seconds\n")
1985 {
1986 return bgp_global_update_delay_config_vty(vty, delay, wait);
1987 }
1988
1989 /* Global update-delay deconfiguration */
1990 DEFPY (no_bgp_global_update_delay,
1991 no_bgp_global_update_delay_cmd,
1992 "no bgp update-delay [(0-3600) [(1-3600)]]",
1993 NO_STR
1994 BGP_STR
1995 "Force initial delay for best-path and updates\n"
1996 "Max delay in seconds\n"
1997 "Establish wait in seconds\n")
1998 {
1999 return bgp_global_update_delay_deconfig_vty(vty);
2000 }
2001
2002 /* Update-delay configuration */
2003
2004 DEFPY (bgp_update_delay,
2005 bgp_update_delay_cmd,
2006 "update-delay (0-3600)$delay [(1-3600)$wait]",
2007 "Force initial delay for best-path and updates\n"
2008 "Max delay in seconds\n"
2009 "Establish wait in seconds\n")
2010 {
2011 return bgp_update_delay_config_vty(vty, delay, wait);
2012 }
2013
2014 /* Update-delay deconfiguration */
2015 DEFPY (no_bgp_update_delay,
2016 no_bgp_update_delay_cmd,
2017 "no update-delay [(0-3600) [(1-3600)]]",
2018 NO_STR
2019 "Force initial delay for best-path and updates\n"
2020 "Max delay in seconds\n"
2021 "Establish wait in seconds\n")
2022 {
2023 return bgp_update_delay_deconfig_vty(vty);
2024 }
2025
2026
2027 int bgp_wpkt_quanta_config_vty(struct bgp *bgp, uint32_t quanta, bool set)
2028 {
2029 quanta = set ? quanta : BGP_WRITE_PACKET_MAX;
2030 atomic_store_explicit(&bgp->wpkt_quanta, quanta, memory_order_relaxed);
2031
2032 return CMD_SUCCESS;
2033 }
2034
2035 int bgp_rpkt_quanta_config_vty(struct bgp *bgp, uint32_t quanta, bool set)
2036 {
2037 quanta = set ? quanta : BGP_READ_PACKET_MAX;
2038 atomic_store_explicit(&bgp->rpkt_quanta, quanta, memory_order_relaxed);
2039
2040 return CMD_SUCCESS;
2041 }
2042
2043 void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
2044 {
2045 uint32_t quanta =
2046 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
2047 if (quanta != BGP_WRITE_PACKET_MAX)
2048 vty_out(vty, " write-quanta %d\n", quanta);
2049 }
2050
2051 void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
2052 {
2053 uint32_t quanta =
2054 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
2055 if (quanta != BGP_READ_PACKET_MAX)
2056 vty_out(vty, " read-quanta %d\n", quanta);
2057 }
2058
2059 /* Packet quanta configuration
2060 *
2061 * XXX: The value set here controls the size of a stack buffer in the IO
2062 * thread. When changing these limits be careful to prevent stack overflow.
2063 *
2064 * Furthermore, the maximums used here should correspond to
2065 * BGP_WRITE_PACKET_MAX and BGP_READ_PACKET_MAX.
2066 */
2067 DEFPY_YANG (bgp_wpkt_quanta,
2068 bgp_wpkt_quanta_cmd,
2069 "[no] write-quanta (1-64)$quanta",
2070 NO_STR
2071 "How many packets to write to peer socket per run\n"
2072 "Number of packets\n")
2073 {
2074 if (!no)
2075 nb_cli_enqueue_change(
2076 vty,
2077 "./global/global-neighbor-config/packet-quanta-config/wpkt-quanta",
2078 NB_OP_MODIFY, quanta_str);
2079 else
2080 nb_cli_enqueue_change(
2081 vty,
2082 "./global/global-neighbor-config/packet-quanta-config/wpkt-quanta",
2083 NB_OP_MODIFY, NULL);
2084
2085 return nb_cli_apply_changes(vty, NULL);
2086 }
2087
2088 DEFPY_YANG (bgp_rpkt_quanta,
2089 bgp_rpkt_quanta_cmd,
2090 "[no] read-quanta (1-10)$quanta",
2091 NO_STR
2092 "How many packets to read from peer socket per I/O cycle\n"
2093 "Number of packets\n")
2094 {
2095 if (!no)
2096 nb_cli_enqueue_change(
2097 vty,
2098 "./global/global-neighbor-config/packet-quanta-config/rpkt-quanta",
2099 NB_OP_MODIFY, quanta_str);
2100 else
2101 nb_cli_enqueue_change(
2102 vty,
2103 "./global/global-neighbor-config/packet-quanta-config/rpkt-quanta",
2104 NB_OP_MODIFY, NULL);
2105
2106 return nb_cli_apply_changes(vty, NULL);
2107 }
2108
2109 void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
2110 {
2111 if (!bgp->heuristic_coalesce)
2112 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
2113 }
2114
2115 void cli_show_router_global_update_group_config_coalesce_time(
2116 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
2117 {
2118 vty_out(vty, " coalesce-time %u\n", yang_dnode_get_uint32(dnode, NULL));
2119 }
2120
2121
2122 DEFUN_YANG (bgp_coalesce_time,
2123 bgp_coalesce_time_cmd,
2124 "coalesce-time (0-4294967295)",
2125 "Subgroup coalesce timer\n"
2126 "Subgroup coalesce timer value (in ms)\n")
2127 {
2128 int idx = 0;
2129
2130 argv_find(argv, argc, "(0-4294967295)", &idx);
2131 nb_cli_enqueue_change(
2132 vty, "./global/global-update-group-config/coalesce-time",
2133 NB_OP_MODIFY, argv[idx]->arg);
2134
2135 return nb_cli_apply_changes(vty, NULL);
2136 }
2137
2138 DEFUN_YANG(no_bgp_coalesce_time,
2139 no_bgp_coalesce_time_cmd,
2140 "no coalesce-time (0-4294967295)",
2141 NO_STR
2142 "Subgroup coalesce timer\n"
2143 "Subgroup coalesce timer value (in ms)\n")
2144 {
2145 nb_cli_enqueue_change(
2146 vty, "./global/global-update-group-config/coalesce-time",
2147 NB_OP_MODIFY, NULL);
2148
2149 return nb_cli_apply_changes(vty, NULL);
2150 }
2151
2152 /* Maximum-paths configuration */
2153 DEFUN_YANG (bgp_maxpaths,
2154 bgp_maxpaths_cmd,
2155 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2156 "Forward packets over multiple paths\n"
2157 "Number of paths\n")
2158 {
2159 int idx_number = 1;
2160 char base_xpath[XPATH_MAXLEN];
2161 afi_t afi;
2162 safi_t safi;
2163
2164 afi = bgp_node_afi(vty);
2165 safi = bgp_node_safi(vty);
2166
2167 snprintf(
2168 base_xpath, sizeof(base_xpath),
2169 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ebgp/maximum-paths",
2170 yang_afi_safi_value2identity(afi, safi),
2171 bgp_afi_safi_get_container_str(afi, safi));
2172
2173 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY,
2174 argv[idx_number]->arg);
2175
2176 return nb_cli_apply_changes(vty, NULL);
2177 }
2178
2179 void cli_show_bgp_global_afi_safi_unicast_use_multiple_paths_ebgp_maximum_paths(
2180 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
2181 {
2182 vty_out(vty, " maximum-paths %d\n",
2183 yang_dnode_get_uint16(dnode, NULL));
2184 }
2185
2186 ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
2187 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2188 "Forward packets over multiple paths\n"
2189 "Number of paths\n")
2190
2191 DEFUN_YANG (bgp_maxpaths_ibgp,
2192 bgp_maxpaths_ibgp_cmd,
2193 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2194 "Forward packets over multiple paths\n"
2195 "iBGP-multipath\n"
2196 "Number of paths\n")
2197 {
2198 int idx_number = 2;
2199 char base_xpath[XPATH_MAXLEN];
2200 afi_t afi;
2201 safi_t safi;
2202
2203 afi = bgp_node_afi(vty);
2204 safi = bgp_node_safi(vty);
2205
2206 snprintf(
2207 base_xpath, sizeof(base_xpath),
2208 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/maximum-paths",
2209 yang_afi_safi_value2identity(afi, safi),
2210 bgp_afi_safi_get_container_str(afi, safi));
2211
2212 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY,
2213 argv[idx_number]->arg);
2214
2215 return nb_cli_apply_changes(vty, NULL);
2216 }
2217
2218 ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
2219 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2220 "Forward packets over multiple paths\n"
2221 "iBGP-multipath\n"
2222 "Number of paths\n")
2223
2224 DEFUN_YANG (bgp_maxpaths_ibgp_cluster,
2225 bgp_maxpaths_ibgp_cluster_cmd,
2226 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
2227 "Forward packets over multiple paths\n"
2228 "iBGP-multipath\n"
2229 "Number of paths\n"
2230 "Match the cluster length\n")
2231 {
2232 int idx_number = 2;
2233 char base_xpath[XPATH_MAXLEN];
2234 afi_t afi;
2235 safi_t safi;
2236
2237 afi = bgp_node_afi(vty);
2238 safi = bgp_node_safi(vty);
2239
2240 snprintf(
2241 base_xpath, sizeof(base_xpath),
2242 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/maximum-paths",
2243 yang_afi_safi_value2identity(afi, safi),
2244 bgp_afi_safi_get_container_str(afi, safi));
2245
2246 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY,
2247 argv[idx_number]->arg);
2248
2249 snprintf(
2250 base_xpath, sizeof(base_xpath),
2251 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/cluster-length-list",
2252 yang_afi_safi_value2identity(afi, safi),
2253 bgp_afi_safi_get_container_str(afi, safi));
2254
2255 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, "true");
2256
2257 return nb_cli_apply_changes(vty, NULL);
2258 }
2259
2260 void cli_show_bgp_global_afi_safi_ip_unicast_use_multiple_paths_ibgp_maximum_paths(
2261 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
2262 {
2263 vty_out(vty, " maximum-paths ibgp %d",
2264 yang_dnode_get_uint16(dnode, "./maximum-paths"));
2265 if (yang_dnode_get_bool(dnode, "./cluster-length-list"))
2266 vty_out(vty, " equal-cluster-length");
2267 vty_out(vty, "\n");
2268 }
2269
2270 ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
2271 "maximum-paths ibgp " CMD_RANGE_STR(
2272 1, MULTIPATH_NUM) " equal-cluster-length",
2273 "Forward packets over multiple paths\n"
2274 "iBGP-multipath\n"
2275 "Number of paths\n"
2276 "Match the cluster length\n")
2277
2278 DEFUN_YANG (no_bgp_maxpaths,
2279 no_bgp_maxpaths_cmd,
2280 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
2281 NO_STR
2282 "Forward packets over multiple paths\n"
2283 "Number of paths\n")
2284 {
2285 char base_xpath[XPATH_MAXLEN];
2286 afi_t afi;
2287 safi_t safi;
2288
2289 afi = bgp_node_afi(vty);
2290 safi = bgp_node_safi(vty);
2291
2292 snprintf(
2293 base_xpath, sizeof(base_xpath),
2294 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ebgp/maximum-paths",
2295 yang_afi_safi_value2identity(afi, safi),
2296 bgp_afi_safi_get_container_str(afi, safi));
2297
2298 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, NULL);
2299
2300 return nb_cli_apply_changes(vty, NULL);
2301 }
2302
2303 ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
2304 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
2305 "Forward packets over multiple paths\n"
2306 "Number of paths\n")
2307
2308 DEFUN_YANG (no_bgp_maxpaths_ibgp,
2309 no_bgp_maxpaths_ibgp_cmd,
2310 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
2311 NO_STR
2312 "Forward packets over multiple paths\n"
2313 "iBGP-multipath\n"
2314 "Number of paths\n"
2315 "Match the cluster length\n")
2316 {
2317 char base_xpath[XPATH_MAXLEN];
2318 afi_t afi;
2319 safi_t safi;
2320
2321 afi = bgp_node_afi(vty);
2322 safi = bgp_node_safi(vty);
2323
2324 snprintf(
2325 base_xpath, sizeof(base_xpath),
2326 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/maximum-paths",
2327 yang_afi_safi_value2identity(afi, safi),
2328 bgp_afi_safi_get_container_str(afi, safi));
2329
2330 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, NULL);
2331
2332 snprintf(
2333 base_xpath, sizeof(base_xpath),
2334 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/cluster-length-list",
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, "false");
2339
2340 return nb_cli_apply_changes(vty, NULL);
2341 }
2342
2343 ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
2344 "no maximum-paths ibgp [" CMD_RANGE_STR(
2345 1, MULTIPATH_NUM) " [equal-cluster-length]]",
2346 NO_STR
2347 "Forward packets over multiple paths\n"
2348 "iBGP-multipath\n"
2349 "Number of paths\n"
2350 "Match the cluster length\n")
2351
2352 static void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp,
2353 afi_t afi, safi_t safi)
2354 {
2355 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != multipath_num) {
2356 vty_out(vty, " maximum-paths %d\n",
2357 bgp->maxpaths[afi][safi].maxpaths_ebgp);
2358 }
2359
2360 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != multipath_num) {
2361 vty_out(vty, " maximum-paths ibgp %d",
2362 bgp->maxpaths[afi][safi].maxpaths_ibgp);
2363 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
2364 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
2365 vty_out(vty, " equal-cluster-length");
2366 vty_out(vty, "\n");
2367 }
2368 }
2369
2370 /* BGP timers. */
2371
2372 DEFUN_YANG (bgp_timers,
2373 bgp_timers_cmd,
2374 "timers bgp (0-65535) (0-65535)",
2375 "Adjust routing timers\n"
2376 "BGP timers\n"
2377 "Keepalive interval\n"
2378 "Holdtime\n")
2379 {
2380 int idx_number = 2;
2381 int idx_number_2 = 3;
2382
2383 nb_cli_enqueue_change(vty, "./global/global-config-timers/keepalive",
2384 NB_OP_MODIFY, argv[idx_number]->arg);
2385 nb_cli_enqueue_change(vty, "./global/global-config-timers/hold-time",
2386 NB_OP_MODIFY, argv[idx_number_2]->arg);
2387
2388 return nb_cli_apply_changes(vty, NULL);
2389 }
2390
2391 DEFUN_YANG (no_bgp_timers,
2392 no_bgp_timers_cmd,
2393 "no timers bgp [(0-65535) (0-65535)]",
2394 NO_STR
2395 "Adjust routing timers\n"
2396 "BGP timers\n"
2397 "Keepalive interval\n"
2398 "Holdtime\n")
2399 {
2400 nb_cli_enqueue_change(vty, "./global/global-config-timers/keepalive",
2401 NB_OP_DESTROY, NULL);
2402 nb_cli_enqueue_change(vty, "./global/global-config-timers/hold-time",
2403 NB_OP_DESTROY, NULL);
2404
2405 return nb_cli_apply_changes(vty, NULL);
2406 }
2407
2408 void cli_show_router_bgp_route_reflector(struct vty *vty,
2409 struct lyd_node *dnode,
2410 bool show_defaults)
2411 {
2412 if (yang_dnode_get_bool(dnode, "./no-client-reflect"))
2413 vty_out(vty, " no bgp client-to-client reflection\n");
2414
2415 if (yang_dnode_get_bool(dnode, "./allow-outbound-policy"))
2416 vty_out(vty, " bgp route-reflector allow-outbound-policy\n");
2417
2418 if (yang_dnode_exists(dnode, "./route-reflector-cluster-id"))
2419 vty_out(vty, " bgp cluster-id %s\n",
2420 yang_dnode_get_string(dnode,
2421 "./route-reflector-cluster-id"));
2422 }
2423
2424 DEFUN_YANG(bgp_client_to_client_reflection,
2425 bgp_client_to_client_reflection_cmd,
2426 "bgp client-to-client reflection",
2427 "BGP specific commands\n"
2428 "Configure client to client route reflection\n"
2429 "reflection of routes allowed\n")
2430 {
2431 nb_cli_enqueue_change(vty, "./global/route-reflector/no-client-reflect",
2432 NB_OP_MODIFY, "false");
2433
2434 return nb_cli_apply_changes(vty, NULL);
2435 }
2436
2437 DEFUN_YANG(no_bgp_client_to_client_reflection,
2438 no_bgp_client_to_client_reflection_cmd,
2439 "no bgp client-to-client reflection",
2440 NO_STR
2441 "BGP specific commands\n"
2442 "Configure client to client route reflection\n"
2443 "reflection of routes allowed\n")
2444 {
2445 nb_cli_enqueue_change(vty, "./global/route-reflector/no-client-reflect",
2446 NB_OP_MODIFY, "true");
2447
2448 return nb_cli_apply_changes(vty, NULL);
2449 }
2450
2451 void cli_show_router_bgp_route_selection(struct vty *vty,
2452 struct lyd_node *dnode,
2453 bool show_defaults)
2454 {
2455
2456 if (yang_dnode_get_bool(dnode, "./always-compare-med"))
2457 vty_out(vty, " bgp always-compare-med\n");
2458
2459 if (yang_dnode_get_bool(dnode, "./ignore-as-path-length"))
2460 vty_out(vty, " bgp bestpath as-path ignore\n");
2461
2462 if (yang_dnode_get_bool(dnode, "./aspath-confed"))
2463 vty_out(vty, " bgp bestpath as-path confed\n");
2464
2465 if (yang_dnode_get_bool(dnode, "./external-compare-router-id"))
2466 vty_out(vty, " bgp bestpath compare-routerid\n");
2467
2468 if (yang_dnode_get_bool(dnode, "./allow-multiple-as")) {
2469 if (yang_dnode_get_bool(dnode, "./multi-path-as-set"))
2470 vty_out(vty,
2471 " bgp bestpath as-path multipath-relax as-set\n");
2472 else
2473 vty_out(vty, " bgp bestpath as-path multipath-relax\n");
2474 }
2475
2476 if (yang_dnode_get_bool(dnode, "./deterministic-med"))
2477 vty_out(vty, " bgp deterministic-med\n");
2478
2479 if (yang_dnode_get_bool(dnode, "./confed-med")
2480 || yang_dnode_get_bool(dnode, "./missing-as-worst-med")) {
2481 vty_out(vty, " bgp bestpath med");
2482 if (yang_dnode_get_bool(dnode, "./confed-med"))
2483 vty_out(vty, " confed");
2484 if (yang_dnode_get_bool(dnode, "./missing-as-worst-med"))
2485 vty_out(vty, " missing-as-worst");
2486 vty_out(vty, "\n");
2487 }
2488 }
2489
2490 /* "bgp always-compare-med" configuration. */
2491 DEFUN_YANG(bgp_always_compare_med,
2492 bgp_always_compare_med_cmd,
2493 "bgp always-compare-med",
2494 "BGP specific commands\n"
2495 "Allow comparing MED from different neighbors\n")
2496 {
2497 nb_cli_enqueue_change(
2498 vty, "./global/route-selection-options/always-compare-med",
2499 NB_OP_MODIFY, "true");
2500
2501 return nb_cli_apply_changes(vty, NULL);
2502 }
2503
2504 DEFUN_YANG(no_bgp_always_compare_med,
2505 no_bgp_always_compare_med_cmd,
2506 "no bgp always-compare-med",
2507 NO_STR
2508 "BGP specific commands\n"
2509 "Allow comparing MED from different neighbors\n")
2510 {
2511 nb_cli_enqueue_change(
2512 vty, "./global/route-selection-options/always-compare-med",
2513 NB_OP_MODIFY, "false");
2514
2515 return nb_cli_apply_changes(vty, NULL);
2516 }
2517
2518 DEFUN_YANG(bgp_ebgp_requires_policy,
2519 bgp_ebgp_requires_policy_cmd,
2520 "bgp ebgp-requires-policy",
2521 "BGP specific commands\n"
2522 "Require in and out policy for eBGP peers (RFC8212)\n")
2523 {
2524 nb_cli_enqueue_change(vty, "./global/ebgp-requires-policy",
2525 NB_OP_MODIFY, "true");
2526 return nb_cli_apply_changes(vty, NULL);
2527 }
2528
2529 DEFUN_YANG(no_bgp_ebgp_requires_policy,
2530 no_bgp_ebgp_requires_policy_cmd,
2531 "no bgp ebgp-requires-policy",
2532 NO_STR
2533 "BGP specific commands\n"
2534 "Require in and out policy for eBGP peers (RFC8212)\n")
2535 {
2536 nb_cli_enqueue_change(vty, "./global/ebgp-requires-policy",
2537 NB_OP_MODIFY, "false");
2538 return nb_cli_apply_changes(vty, NULL);
2539 }
2540
2541 void cli_show_router_bgp_ebgp_requires_policy(struct vty *vty,
2542 struct lyd_node *dnode,
2543 bool show_defaults)
2544 {
2545 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_EBGP_REQUIRES_POLICY)
2546 vty_out(vty, " bgp ebgp-requires-policy\n");
2547 }
2548
2549 DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd,
2550 "bgp reject-as-sets",
2551 "BGP specific commands\n"
2552 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2553 {
2554 VTY_DECLVAR_CONTEXT(bgp, bgp);
2555 struct listnode *node, *nnode;
2556 struct peer *peer;
2557
2558 bgp->reject_as_sets = true;
2559
2560 /* Reset existing BGP sessions to reject routes
2561 * with aspath containing AS_SET or AS_CONFED_SET.
2562 */
2563 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2564 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2565 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2566 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2567 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2568 }
2569 }
2570
2571 return CMD_SUCCESS;
2572 }
2573
2574 DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd,
2575 "no bgp reject-as-sets",
2576 NO_STR
2577 "BGP specific commands\n"
2578 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2579 {
2580 VTY_DECLVAR_CONTEXT(bgp, bgp);
2581 struct listnode *node, *nnode;
2582 struct peer *peer;
2583
2584 bgp->reject_as_sets = false;
2585
2586 /* Reset existing BGP sessions to reject routes
2587 * with aspath containing AS_SET or AS_CONFED_SET.
2588 */
2589 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2590 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2591 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2592 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2593 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2594 }
2595 }
2596
2597 return CMD_SUCCESS;
2598 }
2599
2600 /* "bgp deterministic-med" configuration. */
2601 DEFUN_YANG (bgp_deterministic_med,
2602 bgp_deterministic_med_cmd,
2603 "bgp deterministic-med",
2604 "BGP specific commands\n"
2605 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2606 {
2607 nb_cli_enqueue_change(
2608 vty, "./global/route-selection-options/deterministic-med",
2609 NB_OP_MODIFY, "true");
2610
2611 return nb_cli_apply_changes(vty, NULL);
2612 }
2613
2614 DEFUN_YANG (no_bgp_deterministic_med,
2615 no_bgp_deterministic_med_cmd,
2616 "no bgp deterministic-med",
2617 NO_STR
2618 "BGP specific commands\n"
2619 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2620 {
2621 nb_cli_enqueue_change(
2622 vty, "./global/route-selection-options/deterministic-med",
2623 NB_OP_MODIFY, "false");
2624
2625 return nb_cli_apply_changes(vty, NULL);
2626 }
2627
2628 /* "bgp graceful-restart mode" configuration. */
2629 DEFUN (bgp_graceful_restart,
2630 bgp_graceful_restart_cmd,
2631 "bgp graceful-restart",
2632 "BGP specific commands\n"
2633 GR_CMD
2634 )
2635 {
2636 int ret = BGP_GR_FAILURE;
2637
2638 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2639 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : START ");
2640
2641 VTY_DECLVAR_CONTEXT(bgp, bgp);
2642
2643 ret = bgp_gr_update_all(bgp, GLOBAL_GR_CMD);
2644
2645 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2646 ret);
2647
2648 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2649 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : END ");
2650 vty_out(vty,
2651 "Graceful restart configuration changed, reset all peers to take effect\n");
2652 return bgp_vty_return(vty, ret);
2653 }
2654
2655 DEFUN (no_bgp_graceful_restart,
2656 no_bgp_graceful_restart_cmd,
2657 "no bgp graceful-restart",
2658 NO_STR
2659 "BGP specific commands\n"
2660 NO_GR_CMD
2661 )
2662 {
2663 VTY_DECLVAR_CONTEXT(bgp, bgp);
2664
2665 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2666 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : START ");
2667
2668 int ret = BGP_GR_FAILURE;
2669
2670 ret = bgp_gr_update_all(bgp, NO_GLOBAL_GR_CMD);
2671
2672 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2673 ret);
2674
2675 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2676 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : END ");
2677 vty_out(vty,
2678 "Graceful restart configuration changed, reset all peers to take effect\n");
2679
2680 return bgp_vty_return(vty, ret);
2681 }
2682
2683 DEFUN (bgp_graceful_restart_stalepath_time,
2684 bgp_graceful_restart_stalepath_time_cmd,
2685 "bgp graceful-restart stalepath-time (1-4095)",
2686 "BGP specific commands\n"
2687 "Graceful restart capability parameters\n"
2688 "Set the max time to hold onto restarting peer's stale paths\n"
2689 "Delay value (seconds)\n")
2690 {
2691 VTY_DECLVAR_CONTEXT(bgp, bgp);
2692 int idx_number = 3;
2693 uint32_t stalepath;
2694
2695 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2696 bgp->stalepath_time = stalepath;
2697 return CMD_SUCCESS;
2698 }
2699
2700 DEFUN (bgp_graceful_restart_restart_time,
2701 bgp_graceful_restart_restart_time_cmd,
2702 "bgp graceful-restart restart-time (1-4095)",
2703 "BGP specific commands\n"
2704 "Graceful restart capability parameters\n"
2705 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2706 "Delay value (seconds)\n")
2707 {
2708 VTY_DECLVAR_CONTEXT(bgp, bgp);
2709 int idx_number = 3;
2710 uint32_t restart;
2711
2712 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2713 bgp->restart_time = restart;
2714 return CMD_SUCCESS;
2715 }
2716
2717 DEFUN (bgp_graceful_restart_select_defer_time,
2718 bgp_graceful_restart_select_defer_time_cmd,
2719 "bgp graceful-restart select-defer-time (0-3600)",
2720 "BGP specific commands\n"
2721 "Graceful restart capability parameters\n"
2722 "Set the time to defer the BGP route selection after restart\n"
2723 "Delay value (seconds, 0 - disable)\n")
2724 {
2725 VTY_DECLVAR_CONTEXT(bgp, bgp);
2726 int idx_number = 3;
2727 uint32_t defer_time;
2728
2729 defer_time = strtoul(argv[idx_number]->arg, NULL, 10);
2730 bgp->select_defer_time = defer_time;
2731 if (defer_time == 0)
2732 SET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2733 else
2734 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2735
2736 return CMD_SUCCESS;
2737 }
2738
2739 DEFUN (no_bgp_graceful_restart_stalepath_time,
2740 no_bgp_graceful_restart_stalepath_time_cmd,
2741 "no bgp graceful-restart stalepath-time [(1-4095)]",
2742 NO_STR
2743 "BGP specific commands\n"
2744 "Graceful restart capability parameters\n"
2745 "Set the max time to hold onto restarting peer's stale paths\n"
2746 "Delay value (seconds)\n")
2747 {
2748 VTY_DECLVAR_CONTEXT(bgp, bgp);
2749
2750 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2751 return CMD_SUCCESS;
2752 }
2753
2754 DEFUN (no_bgp_graceful_restart_restart_time,
2755 no_bgp_graceful_restart_restart_time_cmd,
2756 "no bgp graceful-restart restart-time [(1-4095)]",
2757 NO_STR
2758 "BGP specific commands\n"
2759 "Graceful restart capability parameters\n"
2760 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2761 "Delay value (seconds)\n")
2762 {
2763 VTY_DECLVAR_CONTEXT(bgp, bgp);
2764
2765 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2766 return CMD_SUCCESS;
2767 }
2768
2769 DEFUN (no_bgp_graceful_restart_select_defer_time,
2770 no_bgp_graceful_restart_select_defer_time_cmd,
2771 "no bgp graceful-restart select-defer-time [(0-3600)]",
2772 NO_STR
2773 "BGP specific commands\n"
2774 "Graceful restart capability parameters\n"
2775 "Set the time to defer the BGP route selection after restart\n"
2776 "Delay value (seconds)\n")
2777 {
2778 VTY_DECLVAR_CONTEXT(bgp, bgp);
2779
2780 bgp->select_defer_time = BGP_DEFAULT_SELECT_DEFERRAL_TIME;
2781 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2782
2783 return CMD_SUCCESS;
2784 }
2785
2786 DEFUN (bgp_graceful_restart_preserve_fw,
2787 bgp_graceful_restart_preserve_fw_cmd,
2788 "bgp graceful-restart preserve-fw-state",
2789 "BGP specific commands\n"
2790 "Graceful restart capability parameters\n"
2791 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
2792 {
2793 VTY_DECLVAR_CONTEXT(bgp, bgp);
2794 SET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
2795 return CMD_SUCCESS;
2796 }
2797
2798 DEFUN (no_bgp_graceful_restart_preserve_fw,
2799 no_bgp_graceful_restart_preserve_fw_cmd,
2800 "no bgp graceful-restart preserve-fw-state",
2801 NO_STR
2802 "BGP specific commands\n"
2803 "Graceful restart capability parameters\n"
2804 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
2805 {
2806 VTY_DECLVAR_CONTEXT(bgp, bgp);
2807 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
2808 return CMD_SUCCESS;
2809 }
2810
2811 DEFUN (bgp_graceful_restart_disable,
2812 bgp_graceful_restart_disable_cmd,
2813 "bgp graceful-restart-disable",
2814 "BGP specific commands\n"
2815 GR_DISABLE)
2816 {
2817 int ret = BGP_GR_FAILURE;
2818
2819 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2820 zlog_debug(
2821 "[BGP_GR] bgp_graceful_restart_disable_cmd : START ");
2822
2823 VTY_DECLVAR_CONTEXT(bgp, bgp);
2824
2825 ret = bgp_gr_update_all(bgp, GLOBAL_DISABLE_CMD);
2826
2827 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
2828 bgp->peer, ret);
2829
2830 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2831 zlog_debug(
2832 "[BGP_GR] bgp_graceful_restart_disable_cmd : END ");
2833 vty_out(vty,
2834 "Graceful restart configuration changed, reset all peers to take effect\n");
2835
2836 return bgp_vty_return(vty, ret);
2837 }
2838
2839 DEFUN (no_bgp_graceful_restart_disable,
2840 no_bgp_graceful_restart_disable_cmd,
2841 "no bgp graceful-restart-disable",
2842 NO_STR
2843 "BGP specific commands\n"
2844 NO_GR_DISABLE
2845 )
2846 {
2847 VTY_DECLVAR_CONTEXT(bgp, bgp);
2848
2849 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2850 zlog_debug(
2851 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : START ");
2852
2853 int ret = BGP_GR_FAILURE;
2854
2855 ret = bgp_gr_update_all(bgp, NO_GLOBAL_DISABLE_CMD);
2856
2857 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2858 ret);
2859
2860 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2861 zlog_debug(
2862 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : END ");
2863 vty_out(vty,
2864 "Graceful restart configuration changed, reset all peers to take effect\n");
2865
2866 return bgp_vty_return(vty, ret);
2867 }
2868
2869 DEFUN (bgp_neighbor_graceful_restart_set,
2870 bgp_neighbor_graceful_restart_set_cmd,
2871 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
2872 NEIGHBOR_STR
2873 NEIGHBOR_ADDR_STR2
2874 GR_NEIGHBOR_CMD
2875 )
2876 {
2877 int idx_peer = 1;
2878 struct peer *peer;
2879 int ret = BGP_GR_FAILURE;
2880
2881 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2882
2883 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2884 zlog_debug(
2885 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : START ");
2886
2887 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2888 if (!peer)
2889 return CMD_WARNING_CONFIG_FAILED;
2890
2891 ret = bgp_neighbor_graceful_restart(peer, PEER_GR_CMD);
2892
2893 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2894 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
2895
2896 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2897 zlog_debug(
2898 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : END ");
2899 vty_out(vty,
2900 "Graceful restart configuration changed, reset this peer to take effect\n");
2901
2902 return bgp_vty_return(vty, ret);
2903 }
2904
2905 DEFUN (no_bgp_neighbor_graceful_restart,
2906 no_bgp_neighbor_graceful_restart_set_cmd,
2907 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
2908 NO_STR
2909 NEIGHBOR_STR
2910 NEIGHBOR_ADDR_STR2
2911 NO_GR_NEIGHBOR_CMD
2912 )
2913 {
2914 int idx_peer = 2;
2915 int ret = BGP_GR_FAILURE;
2916 struct peer *peer;
2917
2918 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2919
2920 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2921 if (!peer)
2922 return CMD_WARNING_CONFIG_FAILED;
2923
2924 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2925 zlog_debug(
2926 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : START ");
2927
2928 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_GR_CMD);
2929
2930 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2931 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
2932
2933 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2934 zlog_debug(
2935 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : END ");
2936 vty_out(vty,
2937 "Graceful restart configuration changed, reset this peer to take effect\n");
2938
2939 return bgp_vty_return(vty, ret);
2940 }
2941
2942 DEFUN (bgp_neighbor_graceful_restart_helper_set,
2943 bgp_neighbor_graceful_restart_helper_set_cmd,
2944 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
2945 NEIGHBOR_STR
2946 NEIGHBOR_ADDR_STR2
2947 GR_NEIGHBOR_HELPER_CMD
2948 )
2949 {
2950 int idx_peer = 1;
2951 struct peer *peer;
2952 int ret = BGP_GR_FAILURE;
2953
2954 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2955
2956 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2957 zlog_debug(
2958 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : START ");
2959
2960 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2961
2962 if (!peer)
2963 return CMD_WARNING_CONFIG_FAILED;
2964
2965
2966 ret = bgp_neighbor_graceful_restart(peer, PEER_HELPER_CMD);
2967
2968 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2969 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
2970
2971 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2972 zlog_debug(
2973 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : END ");
2974 vty_out(vty,
2975 "Graceful restart configuration changed, reset this peer to take effect\n");
2976
2977 return bgp_vty_return(vty, ret);
2978 }
2979
2980 DEFUN (no_bgp_neighbor_graceful_restart_helper,
2981 no_bgp_neighbor_graceful_restart_helper_set_cmd,
2982 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
2983 NO_STR
2984 NEIGHBOR_STR
2985 NEIGHBOR_ADDR_STR2
2986 NO_GR_NEIGHBOR_HELPER_CMD
2987 )
2988 {
2989 int idx_peer = 2;
2990 int ret = BGP_GR_FAILURE;
2991 struct peer *peer;
2992
2993 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2994
2995 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2996 if (!peer)
2997 return CMD_WARNING_CONFIG_FAILED;
2998
2999 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3000 zlog_debug(
3001 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : START ");
3002
3003 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_HELPER_CMD);
3004
3005 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3006 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3007
3008 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3009 zlog_debug(
3010 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : END ");
3011 vty_out(vty,
3012 "Graceful restart configuration changed, reset this peer to take effect\n");
3013
3014 return bgp_vty_return(vty, ret);
3015 }
3016
3017 DEFUN (bgp_neighbor_graceful_restart_disable_set,
3018 bgp_neighbor_graceful_restart_disable_set_cmd,
3019 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3020 NEIGHBOR_STR
3021 NEIGHBOR_ADDR_STR2
3022 GR_NEIGHBOR_DISABLE_CMD
3023 )
3024 {
3025 int idx_peer = 1;
3026 struct peer *peer;
3027 int ret = BGP_GR_FAILURE;
3028
3029 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3030
3031 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3032 zlog_debug(
3033 "[BGP_GR] bgp_neighbor_graceful_restart_disable_set_cmd : START ");
3034
3035 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3036 if (!peer)
3037 return CMD_WARNING_CONFIG_FAILED;
3038
3039 ret = bgp_neighbor_graceful_restart(peer, PEER_DISABLE_CMD);
3040
3041 if (peer->bgp->t_startup)
3042 bgp_peer_gr_flags_update(peer);
3043
3044 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3045 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3046
3047 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3048 zlog_debug(
3049 "[BGP_GR]bgp_neighbor_graceful_restart_disable_set_cmd : END ");
3050 vty_out(vty,
3051 "Graceful restart configuration changed, reset this peer to take effect\n");
3052
3053 return bgp_vty_return(vty, ret);
3054 }
3055
3056 DEFUN (no_bgp_neighbor_graceful_restart_disable,
3057 no_bgp_neighbor_graceful_restart_disable_set_cmd,
3058 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3059 NO_STR
3060 NEIGHBOR_STR
3061 NEIGHBOR_ADDR_STR2
3062 NO_GR_NEIGHBOR_DISABLE_CMD
3063 )
3064 {
3065 int idx_peer = 2;
3066 int ret = BGP_GR_FAILURE;
3067 struct peer *peer;
3068
3069 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3070
3071 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3072 if (!peer)
3073 return CMD_WARNING_CONFIG_FAILED;
3074
3075 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3076 zlog_debug(
3077 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : START ");
3078
3079 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_DISABLE_CMD);
3080
3081 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3082 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3083
3084 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3085 zlog_debug(
3086 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : END ");
3087 vty_out(vty,
3088 "Graceful restart configuration changed, reset this peer to take effect\n");
3089
3090 return bgp_vty_return(vty, ret);
3091 }
3092
3093 DEFUN_HIDDEN (bgp_graceful_restart_disable_eor,
3094 bgp_graceful_restart_disable_eor_cmd,
3095 "bgp graceful-restart disable-eor",
3096 "BGP specific commands\n"
3097 "Graceful restart configuration parameters\n"
3098 "Disable EOR Check\n")
3099 {
3100 VTY_DECLVAR_CONTEXT(bgp, bgp);
3101 SET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
3102
3103 return CMD_SUCCESS;
3104 }
3105
3106 DEFUN_HIDDEN (no_bgp_graceful_restart_disable_eor,
3107 no_bgp_graceful_restart_disable_eor_cmd,
3108 "no bgp graceful-restart disable-eor",
3109 NO_STR
3110 "BGP specific commands\n"
3111 "Graceful restart configuration parameters\n"
3112 "Disable EOR Check\n")
3113 {
3114 VTY_DECLVAR_CONTEXT(bgp, bgp);
3115 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
3116
3117 return CMD_SUCCESS;
3118 }
3119
3120 DEFUN (bgp_graceful_restart_rib_stale_time,
3121 bgp_graceful_restart_rib_stale_time_cmd,
3122 "bgp graceful-restart rib-stale-time (1-3600)",
3123 "BGP specific commands\n"
3124 "Graceful restart configuration parameters\n"
3125 "Specify the stale route removal timer in rib\n"
3126 "Delay value (seconds)\n")
3127 {
3128 VTY_DECLVAR_CONTEXT(bgp, bgp);
3129 int idx_number = 3;
3130 uint32_t stale_time;
3131
3132 stale_time = strtoul(argv[idx_number]->arg, NULL, 10);
3133 bgp->rib_stale_time = stale_time;
3134 /* Send the stale timer update message to RIB */
3135 if (bgp_zebra_stale_timer_update(bgp))
3136 return CMD_WARNING;
3137
3138 return CMD_SUCCESS;
3139 }
3140
3141 DEFUN (no_bgp_graceful_restart_rib_stale_time,
3142 no_bgp_graceful_restart_rib_stale_time_cmd,
3143 "no bgp graceful-restart rib-stale-time [(1-3600)]",
3144 NO_STR
3145 "BGP specific commands\n"
3146 "Graceful restart configuration parameters\n"
3147 "Specify the stale route removal timer in rib\n"
3148 "Delay value (seconds)\n")
3149 {
3150 VTY_DECLVAR_CONTEXT(bgp, bgp);
3151
3152 bgp->rib_stale_time = BGP_DEFAULT_RIB_STALE_TIME;
3153 /* Send the stale timer update message to RIB */
3154 if (bgp_zebra_stale_timer_update(bgp))
3155 return CMD_WARNING;
3156
3157 return CMD_SUCCESS;
3158 }
3159
3160 static inline int bgp_initiate_graceful_shut_unshut(struct bgp *bgp,
3161 char *errmsg,
3162 size_t errmsg_len)
3163 {
3164 bgp_static_redo_import_check(bgp);
3165 bgp_redistribute_redo(bgp);
3166 if (bgp_clear_star_soft_out(bgp->name, errmsg, errmsg_len) < 0)
3167 return -1;
3168 if (bgp_clear_star_soft_in(bgp->name, errmsg, errmsg_len) < 0)
3169 return -1;
3170
3171 return 0;
3172 }
3173
3174 static int bgp_global_graceful_shutdown_config_vty(struct vty *vty)
3175 {
3176 struct listnode *node, *nnode;
3177 struct bgp *bgp;
3178 bool vrf_cfg = false;
3179 char errmsg[BUFSIZ] = {'\0'};
3180
3181 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3182 return CMD_SUCCESS;
3183
3184 /* See if graceful-shutdown is set per-vrf and warn user to delete */
3185 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3186 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3187 vty_out(vty,
3188 "%% graceful-shutdown configuration found in vrf %s\n",
3189 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT ?
3190 VRF_DEFAULT_NAME : bgp->name);
3191 vrf_cfg = true;
3192 }
3193 }
3194
3195 if (vrf_cfg) {
3196 vty_out(vty,
3197 "%%Failed: global graceful-shutdown not permitted\n");
3198 return CMD_WARNING;
3199 }
3200
3201 /* Set flag globally */
3202 SET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3203
3204 /* Initiate processing for all BGP instances. */
3205 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3206 if (bgp_initiate_graceful_shut_unshut(bgp, errmsg,
3207 sizeof(errmsg))
3208 < 0)
3209 if (strlen(errmsg))
3210 vty_out(vty, "%s\n", errmsg);
3211 }
3212
3213 return CMD_SUCCESS;
3214 }
3215
3216 static int bgp_global_graceful_shutdown_deconfig_vty(struct vty *vty)
3217 {
3218 struct listnode *node, *nnode;
3219 struct bgp *bgp;
3220 char errmsg[BUFSIZ] = {'\0'};
3221
3222 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3223 return CMD_SUCCESS;
3224
3225 /* Unset flag globally */
3226 UNSET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3227
3228 /* Initiate processing for all BGP instances. */
3229 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3230 if (bgp_initiate_graceful_shut_unshut(bgp, errmsg,
3231 sizeof(errmsg))
3232 < 0)
3233 if (strlen(errmsg))
3234 vty_out(vty, "%s\n", errmsg);
3235 }
3236
3237 return CMD_SUCCESS;
3238 }
3239
3240 /* "bgp graceful-shutdown" configuration */
3241 DEFUN (bgp_graceful_shutdown,
3242 bgp_graceful_shutdown_cmd,
3243 "bgp graceful-shutdown",
3244 BGP_STR
3245 "Graceful shutdown parameters\n")
3246 {
3247 if (vty->node == CONFIG_NODE)
3248 return bgp_global_graceful_shutdown_config_vty(vty);
3249
3250 nb_cli_enqueue_change(vty, "./global/graceful-shutdown/enable",
3251 NB_OP_MODIFY, "true");
3252
3253 return nb_cli_apply_changes(vty, NULL);
3254 }
3255
3256 DEFUN_YANG (no_bgp_graceful_shutdown,
3257 no_bgp_graceful_shutdown_cmd,
3258 "no bgp graceful-shutdown",
3259 NO_STR
3260 BGP_STR
3261 "Graceful shutdown parameters\n")
3262 {
3263 if (vty->node == CONFIG_NODE)
3264 return bgp_global_graceful_shutdown_deconfig_vty(vty);
3265
3266 nb_cli_enqueue_change(vty, "./global/graceful-shutdown/enable",
3267 NB_OP_MODIFY, "false");
3268
3269 return nb_cli_apply_changes(vty, NULL);
3270 }
3271
3272 void cli_show_router_bgp_graceful_shutdown(struct vty *vty,
3273 struct lyd_node *dnode,
3274 bool show_defaults)
3275 {
3276 if (yang_dnode_get_bool(dnode, NULL))
3277 vty_out(vty, " bgp graceful-shutdown\n");
3278 }
3279
3280 /* "bgp fast-external-failover" configuration. */
3281 DEFUN_YANG (bgp_fast_external_failover,
3282 bgp_fast_external_failover_cmd,
3283 "bgp fast-external-failover",
3284 BGP_STR
3285 "Immediately reset session if a link to a directly connected external peer goes down\n")
3286 {
3287 nb_cli_enqueue_change(vty, "./global/fast-external-failover",
3288 NB_OP_MODIFY, "false");
3289
3290 return nb_cli_apply_changes(vty, NULL);
3291 }
3292
3293 DEFUN_YANG (no_bgp_fast_external_failover,
3294 no_bgp_fast_external_failover_cmd,
3295 "no bgp fast-external-failover",
3296 NO_STR
3297 BGP_STR
3298 "Immediately reset session if a link to a directly connected external peer goes down\n")
3299 {
3300 nb_cli_enqueue_change(vty, "./global/fast-external-failover",
3301 NB_OP_MODIFY, "true");
3302
3303 return nb_cli_apply_changes(vty, NULL);
3304 }
3305
3306 void cli_show_router_bgp_fast_external_failover(struct vty *vty,
3307 struct lyd_node *dnode,
3308 bool show_defaults)
3309 {
3310 if (!yang_dnode_get_bool(dnode, NULL))
3311 vty_out(vty, " no bgp fast-external-failover\n");
3312 }
3313
3314 /* "bgp bestpath compare-routerid" configuration. */
3315 DEFUN_YANG(bgp_bestpath_compare_router_id,
3316 bgp_bestpath_compare_router_id_cmd,
3317 "bgp bestpath compare-routerid",
3318 "BGP specific commands\n"
3319 "Change the default bestpath selection\n"
3320 "Compare router-id for identical EBGP paths\n")
3321 {
3322 nb_cli_enqueue_change(
3323 vty,
3324 "./global/route-selection-options/external-compare-router-id",
3325 NB_OP_MODIFY, "true");
3326
3327 return nb_cli_apply_changes(vty, NULL);
3328 }
3329
3330 DEFUN_YANG(no_bgp_bestpath_compare_router_id,
3331 no_bgp_bestpath_compare_router_id_cmd,
3332 "no bgp bestpath compare-routerid",
3333 NO_STR
3334 "BGP specific commands\n"
3335 "Change the default bestpath selection\n"
3336 "Compare router-id for identical EBGP paths\n")
3337 {
3338 nb_cli_enqueue_change(
3339 vty,
3340 "./global/route-selection-options/external-compare-router-id",
3341 NB_OP_MODIFY, "false");
3342
3343 return nb_cli_apply_changes(vty, NULL);
3344 }
3345
3346 /* "bgp bestpath as-path ignore" configuration. */
3347 DEFUN_YANG(bgp_bestpath_aspath_ignore,
3348 bgp_bestpath_aspath_ignore_cmd,
3349 "bgp bestpath as-path ignore",
3350 "BGP specific commands\n"
3351 "Change the default bestpath selection\n"
3352 "AS-path attribute\n"
3353 "Ignore as-path length in selecting a route\n")
3354 {
3355 nb_cli_enqueue_change(
3356 vty, "./global/route-selection-options/ignore-as-path-length",
3357 NB_OP_MODIFY, "true");
3358
3359 return nb_cli_apply_changes(vty, NULL);
3360 }
3361
3362 DEFUN_YANG(no_bgp_bestpath_aspath_ignore,
3363 no_bgp_bestpath_aspath_ignore_cmd,
3364 "no bgp bestpath as-path ignore",
3365 NO_STR
3366 "BGP specific commands\n"
3367 "Change the default bestpath selection\n"
3368 "AS-path attribute\n"
3369 "Ignore as-path length in selecting a route\n")
3370 {
3371 nb_cli_enqueue_change(
3372 vty, "./global/route-selection-options/ignore-as-path-length",
3373 NB_OP_MODIFY, "false");
3374
3375 return nb_cli_apply_changes(vty, NULL);
3376 }
3377
3378 /* "bgp bestpath as-path confed" configuration. */
3379 DEFUN_YANG (bgp_bestpath_aspath_confed,
3380 bgp_bestpath_aspath_confed_cmd,
3381 "bgp bestpath as-path confed",
3382 "BGP specific commands\n"
3383 "Change the default bestpath selection\n"
3384 "AS-path attribute\n"
3385 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3386 {
3387 nb_cli_enqueue_change(vty,
3388 "./global/route-selection-options/aspath-confed",
3389 NB_OP_MODIFY, "true");
3390
3391 return nb_cli_apply_changes(vty, NULL);
3392 }
3393
3394 DEFUN_YANG (no_bgp_bestpath_aspath_confed,
3395 no_bgp_bestpath_aspath_confed_cmd,
3396 "no bgp bestpath as-path confed",
3397 NO_STR
3398 "BGP specific commands\n"
3399 "Change the default bestpath selection\n"
3400 "AS-path attribute\n"
3401 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3402 {
3403 nb_cli_enqueue_change(vty,
3404 "./global/route-selection-options/aspath-confed",
3405 NB_OP_MODIFY, "false");
3406
3407 return nb_cli_apply_changes(vty, NULL);
3408 }
3409
3410 /* "bgp bestpath as-path multipath-relax" configuration. */
3411 DEFUN_YANG (bgp_bestpath_aspath_multipath_relax,
3412 bgp_bestpath_aspath_multipath_relax_cmd,
3413 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
3414 "BGP specific commands\n"
3415 "Change the default bestpath selection\n"
3416 "AS-path attribute\n"
3417 "Allow load sharing across routes that have different AS paths (but same length)\n"
3418 "Generate an AS_SET\n"
3419 "Do not generate an AS_SET\n")
3420 {
3421 int idx = 0;
3422
3423 nb_cli_enqueue_change(
3424 vty, "./global/route-selection-options/allow-multiple-as",
3425 NB_OP_MODIFY, "true");
3426 if (argv_find(argv, argc, "as-set", &idx))
3427 nb_cli_enqueue_change(
3428 vty,
3429 "./global/route-selection-options/multi-path-as-set",
3430 NB_OP_MODIFY, "true");
3431 else
3432 nb_cli_enqueue_change(
3433 vty,
3434 "./global/route-selection-options/multi-path-as-set",
3435 NB_OP_MODIFY, "false");
3436
3437 return nb_cli_apply_changes(vty, NULL);
3438 }
3439
3440 DEFUN_YANG (no_bgp_bestpath_aspath_multipath_relax,
3441 no_bgp_bestpath_aspath_multipath_relax_cmd,
3442 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
3443 NO_STR
3444 "BGP specific commands\n"
3445 "Change the default bestpath selection\n"
3446 "AS-path attribute\n"
3447 "Allow load sharing across routes that have different AS paths (but same length)\n"
3448 "Generate an AS_SET\n"
3449 "Do not generate an AS_SET\n")
3450 {
3451 nb_cli_enqueue_change(
3452 vty, "./global/route-selection-options/allow-multiple-as",
3453 NB_OP_MODIFY, "false");
3454 nb_cli_enqueue_change(
3455 vty, "./global/route-selection-options/multi-path-as-set",
3456 NB_OP_MODIFY, "false");
3457
3458 return nb_cli_apply_changes(vty, NULL);
3459 }
3460
3461 /* "bgp log-neighbor-changes" configuration. */
3462 DEFUN_YANG(bgp_log_neighbor_changes,
3463 bgp_log_neighbor_changes_cmd,
3464 "bgp log-neighbor-changes",
3465 "BGP specific commands\n"
3466 "Log neighbor up/down and reset reason\n")
3467 {
3468 nb_cli_enqueue_change(
3469 vty, "./global/global-neighbor-config/log-neighbor-changes",
3470 NB_OP_MODIFY, "true");
3471
3472 return nb_cli_apply_changes(vty, NULL);
3473 }
3474
3475 DEFUN_YANG(no_bgp_log_neighbor_changes,
3476 no_bgp_log_neighbor_changes_cmd,
3477 "no bgp log-neighbor-changes",
3478 NO_STR
3479 "BGP specific commands\n"
3480 "Log neighbor up/down and reset reason\n")
3481 {
3482 nb_cli_enqueue_change(
3483 vty, "./global/global-neighbor-config/log-neighbor-changes",
3484 NB_OP_MODIFY, "false");
3485
3486 return nb_cli_apply_changes(vty, NULL);
3487 }
3488
3489 /* "bgp bestpath med" configuration. */
3490 DEFUN_YANG (bgp_bestpath_med,
3491 bgp_bestpath_med_cmd,
3492 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
3493 "BGP specific commands\n"
3494 "Change the default bestpath selection\n"
3495 "MED attribute\n"
3496 "Compare MED among confederation paths\n"
3497 "Treat missing MED as the least preferred one\n"
3498 "Treat missing MED as the least preferred one\n"
3499 "Compare MED among confederation paths\n")
3500 {
3501 int idx = 0;
3502 bool confed = false;
3503 bool worst_med = false;
3504
3505
3506 if (argv_find(argv, argc, "confed", &idx))
3507 confed = true;
3508
3509 nb_cli_enqueue_change(vty,
3510 "./global/route-selection-options/confed-med",
3511 NB_OP_MODIFY, confed ? "true" : "false");
3512
3513 idx = 0;
3514 if (argv_find(argv, argc, "missing-as-worst", &idx))
3515 worst_med = true;
3516
3517 nb_cli_enqueue_change(
3518 vty, "./global/route-selection-options/missing-as-worst-med",
3519 NB_OP_MODIFY, worst_med ? "true" : "false");
3520
3521 return nb_cli_apply_changes(vty, NULL);
3522 }
3523
3524 DEFUN_YANG (no_bgp_bestpath_med,
3525 no_bgp_bestpath_med_cmd,
3526 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
3527 NO_STR
3528 "BGP specific commands\n"
3529 "Change the default bestpath selection\n"
3530 "MED attribute\n"
3531 "Compare MED among confederation paths\n"
3532 "Treat missing MED as the least preferred one\n"
3533 "Treat missing MED as the least preferred one\n"
3534 "Compare MED among confederation paths\n")
3535 {
3536 int idx = 0;
3537
3538 if (argv_find(argv, argc, "confed", &idx))
3539 nb_cli_enqueue_change(
3540 vty, "./global/route-selection-options/confed-med",
3541 NB_OP_MODIFY, "false");
3542
3543 idx = 0;
3544 if (argv_find(argv, argc, "missing-as-worst", &idx))
3545 nb_cli_enqueue_change(
3546 vty,
3547 "./global/route-selection-options/missing-as-worst-med",
3548 NB_OP_MODIFY, "false");
3549
3550 return nb_cli_apply_changes(vty, NULL);
3551 }
3552
3553 /* "bgp bestpath bandwidth" configuration. */
3554 DEFPY (bgp_bestpath_bw,
3555 bgp_bestpath_bw_cmd,
3556 "bgp bestpath bandwidth <ignore|skip-missing|default-weight-for-missing>$bw_cfg",
3557 "BGP specific commands\n"
3558 "Change the default bestpath selection\n"
3559 "Link Bandwidth attribute\n"
3560 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3561 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3562 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3563 {
3564 VTY_DECLVAR_CONTEXT(bgp, bgp);
3565 afi_t afi;
3566 safi_t safi;
3567
3568 if (!bw_cfg) {
3569 vty_out(vty, "%% Bandwidth configuration must be specified\n");
3570 return CMD_ERR_INCOMPLETE;
3571 }
3572 if (!strcmp(bw_cfg, "ignore"))
3573 bgp->lb_handling = BGP_LINK_BW_IGNORE_BW;
3574 else if (!strcmp(bw_cfg, "skip-missing"))
3575 bgp->lb_handling = BGP_LINK_BW_SKIP_MISSING;
3576 else if (!strcmp(bw_cfg, "default-weight-for-missing"))
3577 bgp->lb_handling = BGP_LINK_BW_DEFWT_4_MISSING;
3578 else
3579 return CMD_ERR_NO_MATCH;
3580
3581 /* This config is used in route install, so redo that. */
3582 FOREACH_AFI_SAFI (afi, safi) {
3583 if (!bgp_fibupd_safi(safi))
3584 continue;
3585 bgp_zebra_announce_table(bgp, afi, safi);
3586 }
3587
3588 return CMD_SUCCESS;
3589 }
3590
3591 DEFPY (no_bgp_bestpath_bw,
3592 no_bgp_bestpath_bw_cmd,
3593 "no bgp bestpath bandwidth [<ignore|skip-missing|default-weight-for-missing>$bw_cfg]",
3594 NO_STR
3595 "BGP specific commands\n"
3596 "Change the default bestpath selection\n"
3597 "Link Bandwidth attribute\n"
3598 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3599 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3600 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3601 {
3602 VTY_DECLVAR_CONTEXT(bgp, bgp);
3603 afi_t afi;
3604 safi_t safi;
3605
3606 bgp->lb_handling = BGP_LINK_BW_ECMP;
3607
3608 /* This config is used in route install, so redo that. */
3609 FOREACH_AFI_SAFI (afi, safi) {
3610 if (!bgp_fibupd_safi(safi))
3611 continue;
3612 bgp_zebra_announce_table(bgp, afi, safi);
3613 }
3614 return CMD_SUCCESS;
3615 }
3616
3617 /* "no bgp default ipv4-unicast". */
3618 DEFUN (no_bgp_default_ipv4_unicast,
3619 no_bgp_default_ipv4_unicast_cmd,
3620 "no bgp default ipv4-unicast",
3621 NO_STR
3622 "BGP specific commands\n"
3623 "Configure BGP defaults\n"
3624 "Activate ipv4-unicast for a peer by default\n")
3625 {
3626 VTY_DECLVAR_CONTEXT(bgp, bgp);
3627 SET_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4);
3628 return CMD_SUCCESS;
3629 }
3630
3631 DEFUN (bgp_default_ipv4_unicast,
3632 bgp_default_ipv4_unicast_cmd,
3633 "bgp default ipv4-unicast",
3634 "BGP specific commands\n"
3635 "Configure BGP defaults\n"
3636 "Activate ipv4-unicast for a peer by default\n")
3637 {
3638 VTY_DECLVAR_CONTEXT(bgp, bgp);
3639 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4);
3640 return CMD_SUCCESS;
3641 }
3642
3643 /* Display hostname in certain command outputs */
3644 DEFUN_YANG (bgp_default_show_hostname,
3645 bgp_default_show_hostname_cmd,
3646 "bgp default show-hostname",
3647 "BGP specific commands\n"
3648 "Configure BGP defaults\n"
3649 "Show hostname in certain command outputs\n")
3650 {
3651 nb_cli_enqueue_change(vty, "./global/show-hostname", NB_OP_MODIFY,
3652 "true");
3653
3654 return nb_cli_apply_changes(vty, NULL);
3655 }
3656
3657 DEFUN_YANG(no_bgp_default_show_hostname,
3658 no_bgp_default_show_hostname_cmd,
3659 "no bgp default show-hostname",
3660 NO_STR
3661 "BGP specific commands\n"
3662 "Configure BGP defaults\n"
3663 "Show hostname in certain command outputs\n")
3664 {
3665 nb_cli_enqueue_change(vty, "./global/show-hostname", NB_OP_MODIFY,
3666 "false");
3667
3668 return nb_cli_apply_changes(vty, NULL);
3669 }
3670
3671 void cli_show_router_bgp_show_hostname(struct vty *vty, struct lyd_node *dnode,
3672 bool show_defaults)
3673 {
3674 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_SHOW_HOSTNAME)
3675 vty_out(vty, " bgp default show-hostname\n");
3676 }
3677
3678 /* Display hostname in certain command outputs */
3679 DEFUN_YANG(bgp_default_show_nexthop_hostname,
3680 bgp_default_show_nexthop_hostname_cmd,
3681 "bgp default show-nexthop-hostname",
3682 "BGP specific commands\n"
3683 "Configure BGP defaults\n"
3684 "Show hostname for nexthop in certain command outputs\n")
3685 {
3686 nb_cli_enqueue_change(vty, "./global/show-nexthop-hostname",
3687 NB_OP_MODIFY, "true");
3688
3689 return nb_cli_apply_changes(vty, NULL);
3690 }
3691
3692 DEFUN (no_bgp_default_show_nexthop_hostname,
3693 no_bgp_default_show_nexthop_hostname_cmd,
3694 "no bgp default show-nexthop-hostname",
3695 NO_STR
3696 "BGP specific commands\n"
3697 "Configure BGP defaults\n"
3698 "Show hostname for nexthop in certain command outputs\n")
3699 {
3700 nb_cli_enqueue_change(vty, "./global/show-nexthop-hostname",
3701 NB_OP_MODIFY, "false");
3702
3703 return nb_cli_apply_changes(vty, NULL);
3704 }
3705
3706 void cli_show_router_bgp_show_nexthop_hostname(struct vty *vty,
3707 struct lyd_node *dnode,
3708 bool show_defaults)
3709 {
3710 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_SHOW_HOSTNAME)
3711 vty_out(vty, " bgp default show-nexthop-hostname\n");
3712 }
3713
3714 /* "bgp network import-check" configuration. */
3715 DEFUN_YANG(bgp_network_import_check,
3716 bgp_network_import_check_cmd,
3717 "bgp network import-check",
3718 "BGP specific commands\n"
3719 "BGP network command\n"
3720 "Check BGP network route exists in IGP\n")
3721 {
3722 nb_cli_enqueue_change(vty, "./global/import-check", NB_OP_MODIFY,
3723 "true");
3724
3725 return nb_cli_apply_changes(vty, NULL);
3726 }
3727
3728 ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
3729 "bgp network import-check exact",
3730 "BGP specific commands\n"
3731 "BGP network command\n"
3732 "Check BGP network route exists in IGP\n"
3733 "Match route precisely\n")
3734
3735 DEFUN_YANG(no_bgp_network_import_check,
3736 no_bgp_network_import_check_cmd,
3737 "no bgp network import-check",
3738 NO_STR
3739 "BGP specific commands\n"
3740 "BGP network command\n"
3741 "Check BGP network route exists in IGP\n")
3742 {
3743 nb_cli_enqueue_change(vty, "./global/import-check", NB_OP_MODIFY,
3744 "false");
3745
3746 return nb_cli_apply_changes(vty, NULL);
3747 }
3748
3749 void cli_show_router_bgp_import_check(struct vty *vty, struct lyd_node *dnode,
3750 bool show_defaults)
3751 {
3752 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_IMPORT_CHECK)
3753 vty_out(vty, " bgp network import-check\n");
3754 }
3755
3756 DEFUN_YANG(bgp_default_local_preference,
3757 bgp_default_local_preference_cmd,
3758 "bgp default local-preference (0-4294967295)",
3759 "BGP specific commands\n"
3760 "Configure BGP defaults\n"
3761 "local preference (higher=more preferred)\n"
3762 "Configure default local preference value\n")
3763 {
3764 int idx_number = 3;
3765
3766 nb_cli_enqueue_change(vty, "./global/local-pref", NB_OP_MODIFY,
3767 argv[idx_number]->arg);
3768
3769 return nb_cli_apply_changes(vty, NULL);
3770 }
3771
3772 DEFUN_YANG(no_bgp_default_local_preference,
3773 no_bgp_default_local_preference_cmd,
3774 "no bgp default local-preference [(0-4294967295)]",
3775 NO_STR
3776 "BGP specific commands\n"
3777 "Configure BGP defaults\n"
3778 "local preference (higher=more preferred)\n"
3779 "Configure default local preference value\n")
3780 {
3781 nb_cli_enqueue_change(vty, "./global/local-pref", NB_OP_MODIFY, NULL);
3782
3783 return nb_cli_apply_changes(vty, NULL);
3784 }
3785
3786 void cli_show_router_bgp_local_pref(struct vty *vty, struct lyd_node *dnode,
3787 bool show_defaults)
3788 {
3789 vty_out(vty, " bgp default local-preference %u\n",
3790 yang_dnode_get_uint32(dnode, NULL));
3791 }
3792
3793
3794 DEFUN_YANG(bgp_default_subgroup_pkt_queue_max,
3795 bgp_default_subgroup_pkt_queue_max_cmd,
3796 "bgp default subgroup-pkt-queue-max (20-100)",
3797 "BGP specific commands\n"
3798 "Configure BGP defaults\n"
3799 "subgroup-pkt-queue-max\n"
3800 "Configure subgroup packet queue max\n")
3801 {
3802 int idx_number = 3;
3803
3804 nb_cli_enqueue_change(
3805 vty,
3806 "./global/global-update-group-config/subgroup-pkt-queue-size",
3807 NB_OP_MODIFY, argv[idx_number]->arg);
3808
3809 return nb_cli_apply_changes(vty, NULL);
3810 }
3811
3812 DEFUN_YANG(no_bgp_default_subgroup_pkt_queue_max,
3813 no_bgp_default_subgroup_pkt_queue_max_cmd,
3814 "no bgp default subgroup-pkt-queue-max [(20-100)]",
3815 NO_STR
3816 "BGP specific commands\n"
3817 "Configure BGP defaults\n"
3818 "subgroup-pkt-queue-max\n"
3819 "Configure subgroup packet queue max\n")
3820 {
3821 nb_cli_enqueue_change(
3822 vty,
3823 "./global/global-update-group-config/subgroup-pkt-queue-size",
3824 NB_OP_MODIFY, NULL);
3825
3826 return nb_cli_apply_changes(vty, NULL);
3827 }
3828
3829 void cli_show_router_global_update_group_config_subgroup_pkt_queue_size(
3830 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
3831 {
3832 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
3833 yang_dnode_get_uint32(dnode, NULL));
3834 }
3835
3836 DEFUN_YANG(bgp_rr_allow_outbound_policy,
3837 bgp_rr_allow_outbound_policy_cmd,
3838 "bgp route-reflector allow-outbound-policy",
3839 "BGP specific commands\n"
3840 "Allow modifications made by out route-map\n"
3841 "on ibgp neighbors\n")
3842 {
3843 nb_cli_enqueue_change(vty,
3844 "./global/route-reflector/allow-outbound-policy",
3845 NB_OP_MODIFY, "true");
3846
3847 return nb_cli_apply_changes(vty, NULL);
3848 }
3849
3850 DEFUN_YANG(no_bgp_rr_allow_outbound_policy,
3851 no_bgp_rr_allow_outbound_policy_cmd,
3852 "no bgp route-reflector allow-outbound-policy",
3853 NO_STR
3854 "BGP specific commands\n"
3855 "Allow modifications made by out route-map\n"
3856 "on ibgp neighbors\n")
3857 {
3858 nb_cli_enqueue_change(vty,
3859 "./global/route-reflector/allow-outbound-policy",
3860 NB_OP_MODIFY, "false");
3861
3862 return nb_cli_apply_changes(vty, NULL);
3863 }
3864
3865
3866 void cli_show_router_global_neighbor_config(struct vty *vty,
3867 struct lyd_node *dnode,
3868 bool show_defaults)
3869 {
3870 uint32_t write_quanta, read_quanta;
3871
3872 if (yang_dnode_get_bool(dnode, "./log-neighbor-changes"))
3873 vty_out(vty, " bgp log-neighbor-changes\n");
3874
3875 if (yang_dnode_exists(dnode, "./dynamic-neighbors-limit")) {
3876 uint32_t listen_limit = yang_dnode_get_uint32(
3877 dnode, "./dynamic-neighbors-limit");
3878 vty_out(vty, " bgp listen limit %u\n", listen_limit);
3879 }
3880
3881 write_quanta = yang_dnode_get_uint32(
3882 dnode, "./packet-quanta-config/wpkt-quanta");
3883 if (write_quanta != BGP_WRITE_PACKET_MAX)
3884 vty_out(vty, " write-quanta %d\n", write_quanta);
3885
3886 read_quanta = yang_dnode_get_uint32(
3887 dnode, "./packet-quanta-config/rpkt-quanta");
3888
3889 if (read_quanta != BGP_READ_PACKET_MAX)
3890 vty_out(vty, " read-quanta %d\n", read_quanta);
3891 }
3892
3893 DEFUN_YANG(bgp_listen_limit,
3894 bgp_listen_limit_cmd,
3895 "bgp listen limit (1-5000)",
3896 "BGP specific commands\n"
3897 "BGP Dynamic Neighbors listen commands\n"
3898 "Maximum number of BGP Dynamic Neighbors that can be created\n"
3899 "Configure Dynamic Neighbors listen limit value\n")
3900 {
3901 int idx_number = 3;
3902
3903 nb_cli_enqueue_change(
3904 vty, "./global/global-neighbor-config/dynamic-neighbors-limit",
3905 NB_OP_MODIFY, argv[idx_number]->arg);
3906
3907 return nb_cli_apply_changes(vty, NULL);
3908 }
3909
3910 DEFUN_YANG(no_bgp_listen_limit,
3911 no_bgp_listen_limit_cmd,
3912 "no bgp listen limit [(1-5000)]",
3913 NO_STR
3914 "BGP specific commands\n"
3915 "BGP Dynamic Neighbors listen commands\n"
3916 "Maximum number of BGP Dynamic Neighbors that can be created\n"
3917 "Configure Dynamic Neighbors listen limit value\n")
3918 {
3919 nb_cli_enqueue_change(
3920 vty, "./global/global-neighbor-config/dynamic-neighbors-limit",
3921 NB_OP_DESTROY, NULL);
3922
3923 return nb_cli_apply_changes(vty, NULL);
3924 }
3925
3926
3927 /*
3928 * Check if this listen range is already configured. Check for exact
3929 * match or overlap based on input.
3930 */
3931 static struct peer_group *listen_range_exists(struct bgp *bgp,
3932 struct prefix *range, int exact)
3933 {
3934 struct listnode *node, *nnode;
3935 struct listnode *node1, *nnode1;
3936 struct peer_group *group;
3937 struct prefix *lr;
3938 afi_t afi;
3939 int match;
3940
3941 afi = family2afi(range->family);
3942 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
3943 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
3944 lr)) {
3945 if (exact)
3946 match = prefix_same(range, lr);
3947 else
3948 match = (prefix_match(range, lr)
3949 || prefix_match(lr, range));
3950 if (match)
3951 return group;
3952 }
3953 }
3954
3955 return NULL;
3956 }
3957
3958 DEFUN (bgp_listen_range,
3959 bgp_listen_range_cmd,
3960 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
3961 "BGP specific commands\n"
3962 "Configure BGP dynamic neighbors listen range\n"
3963 "Configure BGP dynamic neighbors listen range\n"
3964 NEIGHBOR_ADDR_STR
3965 "Member of the peer-group\n"
3966 "Peer-group name\n")
3967 {
3968 VTY_DECLVAR_CONTEXT(bgp, bgp);
3969 struct prefix range;
3970 struct peer_group *group, *existing_group;
3971 afi_t afi;
3972 int ret;
3973 int idx = 0;
3974
3975 argv_find(argv, argc, "A.B.C.D/M", &idx);
3976 argv_find(argv, argc, "X:X::X:X/M", &idx);
3977 char *prefix = argv[idx]->arg;
3978 argv_find(argv, argc, "PGNAME", &idx);
3979 char *peergroup = argv[idx]->arg;
3980
3981 /* Convert IP prefix string to struct prefix. */
3982 ret = str2prefix(prefix, &range);
3983 if (!ret) {
3984 vty_out(vty, "%% Malformed listen range\n");
3985 return CMD_WARNING_CONFIG_FAILED;
3986 }
3987
3988 afi = family2afi(range.family);
3989
3990 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
3991 vty_out(vty,
3992 "%% Malformed listen range (link-local address)\n");
3993 return CMD_WARNING_CONFIG_FAILED;
3994 }
3995
3996 apply_mask(&range);
3997
3998 /* Check if same listen range is already configured. */
3999 existing_group = listen_range_exists(bgp, &range, 1);
4000 if (existing_group) {
4001 if (strcmp(existing_group->name, peergroup) == 0)
4002 return CMD_SUCCESS;
4003 else {
4004 vty_out(vty,
4005 "%% Same listen range is attached to peer-group %s\n",
4006 existing_group->name);
4007 return CMD_WARNING_CONFIG_FAILED;
4008 }
4009 }
4010
4011 /* Check if an overlapping listen range exists. */
4012 if (listen_range_exists(bgp, &range, 0)) {
4013 vty_out(vty,
4014 "%% Listen range overlaps with existing listen range\n");
4015 return CMD_WARNING_CONFIG_FAILED;
4016 }
4017
4018 group = peer_group_lookup(bgp, peergroup);
4019 if (!group) {
4020 vty_out(vty, "%% Configure the peer-group first\n");
4021 return CMD_WARNING_CONFIG_FAILED;
4022 }
4023
4024 ret = peer_group_listen_range_add(group, &range);
4025 return bgp_vty_return(vty, ret);
4026 }
4027
4028 DEFUN (no_bgp_listen_range,
4029 no_bgp_listen_range_cmd,
4030 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
4031 NO_STR
4032 "BGP specific commands\n"
4033 "Unconfigure BGP dynamic neighbors listen range\n"
4034 "Unconfigure BGP dynamic neighbors listen range\n"
4035 NEIGHBOR_ADDR_STR
4036 "Member of the peer-group\n"
4037 "Peer-group name\n")
4038 {
4039 VTY_DECLVAR_CONTEXT(bgp, bgp);
4040 struct prefix range;
4041 struct peer_group *group;
4042 afi_t afi;
4043 int ret;
4044 int idx = 0;
4045
4046 argv_find(argv, argc, "A.B.C.D/M", &idx);
4047 argv_find(argv, argc, "X:X::X:X/M", &idx);
4048 char *prefix = argv[idx]->arg;
4049 argv_find(argv, argc, "PGNAME", &idx);
4050 char *peergroup = argv[idx]->arg;
4051
4052 /* Convert IP prefix string to struct prefix. */
4053 ret = str2prefix(prefix, &range);
4054 if (!ret) {
4055 vty_out(vty, "%% Malformed listen range\n");
4056 return CMD_WARNING_CONFIG_FAILED;
4057 }
4058
4059 afi = family2afi(range.family);
4060
4061 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4062 vty_out(vty,
4063 "%% Malformed listen range (link-local address)\n");
4064 return CMD_WARNING_CONFIG_FAILED;
4065 }
4066
4067 apply_mask(&range);
4068
4069 group = peer_group_lookup(bgp, peergroup);
4070 if (!group) {
4071 vty_out(vty, "%% Peer-group does not exist\n");
4072 return CMD_WARNING_CONFIG_FAILED;
4073 }
4074
4075 ret = peer_group_listen_range_del(group, &range);
4076 return bgp_vty_return(vty, ret);
4077 }
4078
4079 void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
4080 {
4081 struct peer_group *group;
4082 struct listnode *node, *nnode, *rnode, *nrnode;
4083 struct prefix *range;
4084 afi_t afi;
4085
4086 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
4087 vty_out(vty, " bgp listen limit %d\n",
4088 bgp->dynamic_neighbors_limit);
4089
4090 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4091 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
4092 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
4093 nrnode, range)) {
4094 vty_out(vty,
4095 " bgp listen range %pFX peer-group %s\n",
4096 range, group->name);
4097 }
4098 }
4099 }
4100 }
4101
4102
4103 DEFUN_YANG(bgp_disable_connected_route_check,
4104 bgp_disable_connected_route_check_cmd,
4105 "bgp disable-ebgp-connected-route-check",
4106 "BGP specific commands\n"
4107 "Disable checking if nexthop is connected on ebgp sessions\n")
4108 {
4109 nb_cli_enqueue_change(vty,
4110 "./global/ebgp-multihop-connected-route-check",
4111 NB_OP_MODIFY, "true");
4112
4113 return nb_cli_apply_changes(vty, NULL);
4114 }
4115
4116 DEFUN_YANG(no_bgp_disable_connected_route_check,
4117 no_bgp_disable_connected_route_check_cmd,
4118 "no bgp disable-ebgp-connected-route-check",
4119 NO_STR
4120 "BGP specific commands\n"
4121 "Disable checking if nexthop is connected on ebgp sessions\n")
4122 {
4123 nb_cli_enqueue_change(vty,
4124 "./global/ebgp-multihop-connected-route-check",
4125 NB_OP_MODIFY, "false");
4126
4127 return nb_cli_apply_changes(vty, NULL);
4128 }
4129
4130 void cli_show_router_global_ebgp_multihop_connected_route_check(
4131 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
4132 {
4133 if (yang_dnode_get_bool(dnode, NULL))
4134 vty_out(vty, " bgp disable-ebgp-connected-route-check\n");
4135 }
4136
4137 DEFUN_YANG(bgp_default_shutdown,
4138 bgp_default_shutdown_cmd,
4139 "[no] bgp default shutdown",
4140 NO_STR BGP_STR
4141 "Configure BGP defaults\n"
4142 "Apply administrative shutdown to newly configured peers\n")
4143 {
4144 nb_cli_enqueue_change(vty, "./global/default-shutdown", NB_OP_MODIFY,
4145 strmatch(argv[0]->text, "no") ? "false" : "true");
4146
4147 return nb_cli_apply_changes(vty, NULL);
4148 }
4149
4150 void cli_show_router_bgp_default_shutdown(struct vty *vty,
4151 struct lyd_node *dnode,
4152 bool show_defaults)
4153 {
4154 if (yang_dnode_get_bool(dnode, NULL))
4155 vty_out(vty, " bgp default shutdown\n");
4156 }
4157
4158 DEFPY(bgp_shutdown_msg, bgp_shutdown_msg_cmd, "bgp shutdown message MSG...",
4159 BGP_STR
4160 "Administrative shutdown of the BGP instance\n"
4161 "Add a shutdown message (RFC 8203)\n"
4162 "Shutdown message\n")
4163 {
4164 char *msgstr = NULL;
4165
4166 VTY_DECLVAR_CONTEXT(bgp, bgp);
4167
4168 if (argc > 3)
4169 msgstr = argv_concat(argv, argc, 3);
4170
4171 bgp_shutdown_enable(bgp, msgstr);
4172 XFREE(MTYPE_TMP, msgstr);
4173
4174 return CMD_SUCCESS;
4175 }
4176
4177 DEFPY(bgp_shutdown, bgp_shutdown_cmd, "bgp shutdown",
4178 BGP_STR "Administrative shutdown of the BGP instance\n")
4179 {
4180 VTY_DECLVAR_CONTEXT(bgp, bgp);
4181
4182 bgp_shutdown_enable(bgp, NULL);
4183
4184 return CMD_SUCCESS;
4185 }
4186
4187 DEFPY(no_bgp_shutdown, no_bgp_shutdown_cmd, "no bgp shutdown",
4188 NO_STR BGP_STR "Administrative shutdown of the BGP instance\n")
4189 {
4190 VTY_DECLVAR_CONTEXT(bgp, bgp);
4191
4192 bgp_shutdown_disable(bgp);
4193
4194 return CMD_SUCCESS;
4195 }
4196
4197 ALIAS(no_bgp_shutdown, no_bgp_shutdown_msg_cmd,
4198 "no bgp shutdown message MSG...", NO_STR BGP_STR
4199 "Administrative shutdown of the BGP instance\n"
4200 "Add a shutdown message (RFC 8203)\n" "Shutdown message\n")
4201
4202 DEFUN_YANG(neighbor_remote_as,
4203 neighbor_remote_as_cmd,
4204 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
4205 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4206 "Specify a BGP neighbor\n" AS_STR
4207 "Internal BGP peer\n"
4208 "External BGP peer\n")
4209 {
4210 int idx_peer = 1;
4211 int idx_remote_as = 3;
4212 char base_xpath[XPATH_MAXLEN];
4213 char unnbr_xpath[XPATH_MAXLEN];
4214 char prgrp_xpath[XPATH_MAXLEN];
4215 union sockunion su;
4216 const char *as_type_str = "as-specified";
4217
4218 if (str2sockunion(argv[idx_peer]->arg, &su) < 0) {
4219 snprintf(unnbr_xpath, sizeof(unnbr_xpath),
4220 FRR_BGP_NEIGHBOR_UNNUM_XPATH, argv[idx_peer]->arg, "");
4221
4222 snprintf(prgrp_xpath, sizeof(prgrp_xpath),
4223 FRR_BGP_PEER_GROUP_XPATH, argv[idx_peer]->arg, "");
4224
4225 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
4226 VTY_CURR_XPATH, unnbr_xpath + 1)) {
4227 strlcpy(base_xpath, unnbr_xpath, sizeof(base_xpath));
4228 } else if (yang_dnode_exists(vty->candidate_config->dnode,
4229 "%s%s", VTY_CURR_XPATH,
4230 prgrp_xpath + 1)) {
4231 snprintf(base_xpath, sizeof(base_xpath),
4232 FRR_BGP_PEER_GROUP_XPATH, argv[idx_peer]->arg,
4233 "");
4234 } else {
4235 vty_out(vty,
4236 "%% Create the peer-group or interface first\n");
4237 return CMD_WARNING_CONFIG_FAILED;
4238 }
4239 } else {
4240 snprintf(base_xpath, sizeof(base_xpath),
4241 FRR_BGP_NEIGHBOR_NUM_XPATH, argv[idx_peer]->arg, "");
4242 }
4243
4244 if (argv[idx_remote_as]->arg[0] == 'i') {
4245 as_type_str = "internal";
4246 } else if (argv[idx_remote_as]->arg[0] == 'e') {
4247 as_type_str = "external";
4248 } else {
4249 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as",
4250 NB_OP_MODIFY, argv[idx_remote_as]->arg);
4251 }
4252 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as-type",
4253 NB_OP_MODIFY, as_type_str);
4254
4255 return nb_cli_apply_changes(vty, base_xpath);
4256 }
4257
4258 int peer_conf_interface_create(struct bgp *bgp, const char *conf_if, afi_t afi,
4259 safi_t safi, bool v6only,
4260 const char *peer_group_name, int as_type,
4261 as_t as, char *errmsg, size_t errmsg_len)
4262 {
4263 struct peer *peer;
4264 struct peer_group *group;
4265 int ret = 0;
4266
4267 group = peer_group_lookup(bgp, conf_if);
4268
4269 if (group) {
4270 snprintf(errmsg, errmsg_len,
4271 "Name conflict with peer-group \n");
4272 return -1;
4273 }
4274
4275 peer = peer_lookup_by_conf_if(bgp, conf_if);
4276 if (peer) {
4277 if (as_type != AS_UNSPECIFIED)
4278 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type,
4279 afi, safi);
4280 } else {
4281 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4)
4282 && afi == AFI_IP && safi == SAFI_UNICAST)
4283 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
4284 as_type, 0, 0, NULL);
4285 else
4286 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
4287 as_type, afi, safi, NULL);
4288
4289 if (!peer) {
4290 snprintf(errmsg, errmsg_len,
4291 "BGP failed to create peer\n");
4292 return -1;
4293 }
4294
4295 if (v6only)
4296 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
4297
4298 /* Request zebra to initiate IPv6 RAs on this interface. We do
4299 * this
4300 * any unnumbered peer in order to not worry about run-time
4301 * transitions
4302 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
4303 * address
4304 * gets deleted later etc.)
4305 */
4306 if (peer->ifp)
4307 bgp_zebra_initiate_radv(bgp, peer);
4308 }
4309
4310 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
4311 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
4312 if (v6only)
4313 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
4314 else
4315 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
4316
4317 /* v6only flag changed. Reset bgp seesion */
4318 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
4319 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
4320 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
4321 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
4322 } else
4323 bgp_session_reset(peer);
4324 }
4325
4326 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
4327 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
4328 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
4329 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
4330 }
4331
4332 if (peer_group_name) {
4333 group = peer_group_lookup(bgp, peer_group_name);
4334 if (!group) {
4335 snprintf(errmsg, errmsg_len,
4336 "Configure the peer-group first\n");
4337 return -1;
4338 }
4339
4340 ret = peer_group_bind(bgp, NULL, peer, group, &as);
4341 }
4342
4343 return bgp_nb_errmsg_return(errmsg, errmsg_len, ret);
4344 }
4345
4346 DEFUN_YANG(neighbor_interface_config,
4347 neighbor_interface_config_cmd,
4348 "neighbor WORD interface [peer-group PGNAME]",
4349 NEIGHBOR_STR
4350 "Interface name or neighbor tag\n"
4351 "Enable BGP on interface\n"
4352 "Member of the peer-group\n"
4353 "Peer-group name\n")
4354 {
4355 int idx_word = 1;
4356 int idx_peer_group_word = 4;
4357 char base_xpath[XPATH_MAXLEN];
4358
4359 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4360 argv[idx_word]->arg, "");
4361
4362 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
4363 if (argc > idx_peer_group_word)
4364 nb_cli_enqueue_change(vty, "./peer-group", NB_OP_MODIFY,
4365 argv[idx_peer_group_word]->arg);
4366
4367 return nb_cli_apply_changes(vty, base_xpath);
4368 }
4369
4370 DEFUN_YANG(neighbor_interface_config_v6only,
4371 neighbor_interface_config_v6only_cmd,
4372 "neighbor WORD interface v6only [peer-group PGNAME]",
4373 NEIGHBOR_STR
4374 "Interface name or neighbor tag\n"
4375 "Enable BGP on interface\n"
4376 "Enable BGP with v6 link-local only\n"
4377 "Member of the peer-group\n"
4378 "Peer-group name\n")
4379 {
4380 int idx_word = 1;
4381 int idx_peer_group_word = 5;
4382 char base_xpath[XPATH_MAXLEN];
4383
4384 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4385 argv[idx_word]->arg, "");
4386
4387 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
4388 if (argc > idx_peer_group_word)
4389 nb_cli_enqueue_change(vty, "./peer-group", NB_OP_MODIFY,
4390 argv[idx_peer_group_word]->arg);
4391
4392 nb_cli_enqueue_change(vty, "./v6only", NB_OP_MODIFY, "true");
4393
4394 return nb_cli_apply_changes(vty, base_xpath);
4395 }
4396
4397
4398 DEFUN_YANG(
4399 neighbor_interface_config_remote_as,
4400 neighbor_interface_config_remote_as_cmd,
4401 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
4402 NEIGHBOR_STR
4403 "Interface name or neighbor tag\n"
4404 "Enable BGP on interface\n"
4405 "Specify a BGP neighbor\n" AS_STR
4406 "Internal BGP peer\n"
4407 "External BGP peer\n")
4408 {
4409 int idx_word = 1;
4410 int idx_remote_as = 4;
4411 char base_xpath[XPATH_MAXLEN];
4412 const char *as_type_str = "as-specified";
4413
4414 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4415 argv[idx_word]->arg, "");
4416
4417 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
4418
4419 if (argv[idx_remote_as]->arg[0] == 'i') {
4420 as_type_str = "internal";
4421 } else if (argv[idx_remote_as]->arg[0] == 'e') {
4422 as_type_str = "external";
4423 } else {
4424 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as",
4425 NB_OP_MODIFY, argv[idx_remote_as]->arg);
4426 }
4427 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as-type",
4428 NB_OP_MODIFY, as_type_str);
4429
4430 return nb_cli_apply_changes(vty, base_xpath);
4431 }
4432
4433 DEFUN_YANG(
4434 neighbor_interface_v6only_config_remote_as,
4435 neighbor_interface_v6only_config_remote_as_cmd,
4436 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
4437 NEIGHBOR_STR
4438 "Interface name or neighbor tag\n"
4439 "Enable BGP with v6 link-local only\n"
4440 "Enable BGP on interface\n"
4441 "Specify a BGP neighbor\n" AS_STR
4442 "Internal BGP peer\n"
4443 "External BGP peer\n")
4444 {
4445 int idx_word = 1;
4446 int idx_remote_as = 5;
4447 char base_xpath[XPATH_MAXLEN];
4448 const char *as_type_str = "as-specified";
4449
4450 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4451 argv[idx_word]->arg, "");
4452
4453 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
4454
4455 nb_cli_enqueue_change(vty, "./v6only", NB_OP_MODIFY, "true");
4456
4457 if (argv[idx_remote_as]->arg[0] == 'i') {
4458 as_type_str = "internal";
4459 } else if (argv[idx_remote_as]->arg[0] == 'e') {
4460 as_type_str = "external";
4461 } else {
4462 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as",
4463 NB_OP_MODIFY, argv[idx_remote_as]->arg);
4464 }
4465 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as-type",
4466 NB_OP_MODIFY, as_type_str);
4467
4468 return nb_cli_apply_changes(vty, base_xpath);
4469 }
4470
4471 DEFUN_YANG(neighbor_peer_group, neighbor_peer_group_cmd,
4472 "neighbor WORD peer-group",
4473 NEIGHBOR_STR
4474 "Interface name or neighbor tag\n"
4475 "Configure peer-group\n")
4476 {
4477 char base_xpath[XPATH_MAXLEN];
4478 int idx_word = 1;
4479
4480 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_PEER_GROUP_XPATH,
4481 argv[idx_word]->arg, "");
4482
4483 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
4484
4485 return nb_cli_apply_changes(vty, base_xpath);
4486 }
4487
4488 DEFUN_YANG(no_neighbor,
4489 no_neighbor_cmd,
4490 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
4491 NO_STR NEIGHBOR_STR
4492 NEIGHBOR_ADDR_STR2
4493 "Specify a BGP neighbor\n" AS_STR
4494 "Internal BGP peer\n"
4495 "External BGP peer\n")
4496 {
4497 int idx_peer = 2;
4498 char base_xpath[XPATH_MAXLEN];
4499 char num_xpath[XPATH_MAXLEN];
4500 char unnbr_xpath[XPATH_MAXLEN];
4501 char prgrp_xpath[XPATH_MAXLEN];
4502 union sockunion su;
4503
4504 if (str2sockunion(argv[idx_peer]->arg, &su) == 0) {
4505 snprintf(num_xpath, sizeof(num_xpath),
4506 FRR_BGP_NEIGHBOR_NUM_XPATH, argv[idx_peer]->arg, "");
4507 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
4508 VTY_CURR_XPATH, num_xpath + 1)) {
4509 strlcpy(base_xpath, num_xpath, sizeof(base_xpath));
4510 }
4511 } else {
4512 snprintf(unnbr_xpath, sizeof(unnbr_xpath),
4513 FRR_BGP_NEIGHBOR_UNNUM_XPATH, argv[idx_peer]->arg, "");
4514
4515 snprintf(prgrp_xpath, sizeof(prgrp_xpath),
4516 FRR_BGP_PEER_GROUP_XPATH, argv[idx_peer]->arg, "");
4517
4518 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
4519 VTY_CURR_XPATH, unnbr_xpath + 1)) {
4520 strlcpy(base_xpath, unnbr_xpath, sizeof(base_xpath));
4521 } else if (yang_dnode_exists(vty->candidate_config->dnode,
4522 "%s%s", VTY_CURR_XPATH,
4523 prgrp_xpath + 1)) {
4524 strlcpy(base_xpath, prgrp_xpath, sizeof(base_xpath));
4525 } else {
4526 vty_out(vty,
4527 "%% Create the peer-group or interface first\n");
4528 return CMD_WARNING_CONFIG_FAILED;
4529 }
4530 }
4531
4532 nb_cli_enqueue_change(vty, base_xpath, NB_OP_DESTROY, NULL);
4533
4534 return nb_cli_apply_changes(vty, NULL);
4535 }
4536
4537 DEFUN_YANG(no_neighbor_interface_config,
4538 no_neighbor_interface_config_cmd,
4539 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
4540 NO_STR NEIGHBOR_STR
4541 "Interface name\n"
4542 "Configure BGP on interface\n"
4543 "Enable BGP with v6 link-local only\n"
4544 "Member of the peer-group\n"
4545 "Peer-group name\n"
4546 "Specify a BGP neighbor\n" AS_STR
4547 "Internal BGP peer\n"
4548 "External BGP peer\n")
4549 {
4550 int idx_word = 2;
4551 char base_xpath[XPATH_MAXLEN];
4552
4553 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4554 argv[idx_word]->arg, "");
4555
4556 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
4557
4558 return nb_cli_apply_changes(vty, base_xpath);
4559 }
4560
4561 DEFUN_YANG(no_neighbor_peer_group,
4562 no_neighbor_peer_group_cmd,
4563 "no neighbor WORD peer-group",
4564 NO_STR NEIGHBOR_STR
4565 "Neighbor tag\n"
4566 "Configure peer-group\n")
4567 {
4568 char base_xpath[XPATH_MAXLEN];
4569 int idx_word = 2;
4570
4571 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_PEER_GROUP_XPATH,
4572 argv[idx_word]->arg, "");
4573
4574 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
4575
4576 return nb_cli_apply_changes(vty, base_xpath);
4577 }
4578
4579 DEFUN_YANG(no_neighbor_interface_peer_group_remote_as,
4580 no_neighbor_interface_peer_group_remote_as_cmd,
4581 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
4582 NO_STR NEIGHBOR_STR
4583 "Interface name or neighbor tag\n"
4584 "Specify a BGP neighbor\n" AS_STR
4585 "Internal BGP peer\n"
4586 "External BGP peer\n")
4587 {
4588 int idx_peer = 2;
4589 char base_xpath[XPATH_MAXLEN];
4590 char unnbr_xpath[XPATH_MAXLEN];
4591 char prgrp_xpath[XPATH_MAXLEN];
4592
4593 snprintf(unnbr_xpath, sizeof(unnbr_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4594 argv[idx_peer]->arg, "");
4595
4596 snprintf(prgrp_xpath, sizeof(prgrp_xpath), FRR_BGP_PEER_GROUP_XPATH,
4597 argv[idx_peer]->arg, "");
4598
4599 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
4600 VTY_CURR_XPATH, unnbr_xpath + 1)) {
4601 strlcpy(base_xpath, unnbr_xpath, sizeof(base_xpath));
4602 } else if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
4603 VTY_CURR_XPATH, prgrp_xpath + 1)) {
4604 strlcpy(base_xpath, prgrp_xpath, sizeof(base_xpath));
4605 } else {
4606 vty_out(vty, "%% Create the peer-group or interface first\n");
4607 return CMD_WARNING_CONFIG_FAILED;
4608 }
4609
4610 strlcat(base_xpath, "/neighbor-remote-as/remote-as-type",
4611 sizeof(base_xpath));
4612
4613 nb_cli_enqueue_change(vty, base_xpath, NB_OP_DESTROY, NULL);
4614
4615 return nb_cli_apply_changes(vty, NULL);
4616 }
4617
4618 DEFUN_YANG(neighbor_local_as,
4619 neighbor_local_as_cmd,
4620 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
4621 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4622 "Specify a local-as number\n"
4623 "AS number used as local AS\n")
4624 {
4625 int idx_peer = 1;
4626 int idx_number = 3;
4627 char base_xpath[XPATH_MAXLEN];
4628
4629 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4630 sizeof(base_xpath), NULL)
4631 < 0)
4632 return CMD_WARNING_CONFIG_FAILED;
4633
4634 nb_cli_enqueue_change(vty, "./local-as/local-as", NB_OP_MODIFY,
4635 argv[idx_number]->arg);
4636
4637 return nb_cli_apply_changes(vty, base_xpath);
4638 }
4639
4640 DEFUN_YANG(
4641 neighbor_local_as_no_prepend, neighbor_local_as_no_prepend_cmd,
4642 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
4643 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4644 "Specify a local-as number\n"
4645 "AS number used as local AS\n"
4646 "Do not prepend local-as to updates from ebgp peers\n")
4647 {
4648 int idx_peer = 1;
4649 int idx_number = 3;
4650 char base_xpath[XPATH_MAXLEN];
4651
4652 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4653 sizeof(base_xpath), NULL)
4654 < 0)
4655 return CMD_WARNING_CONFIG_FAILED;
4656
4657 nb_cli_enqueue_change(vty, "./local-as/local-as", NB_OP_MODIFY,
4658 argv[idx_number]->arg);
4659 nb_cli_enqueue_change(vty, "./local-as/no-prepend", NB_OP_MODIFY,
4660 "true");
4661
4662 return nb_cli_apply_changes(vty, base_xpath);
4663 }
4664
4665 DEFUN_YANG(
4666 neighbor_local_as_no_prepend_replace_as,
4667 neighbor_local_as_no_prepend_replace_as_cmd,
4668 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
4669 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4670 "Specify a local-as number\n"
4671 "AS number used as local AS\n"
4672 "Do not prepend local-as to updates from ebgp peers\n"
4673 "Do not prepend local-as to updates from ibgp peers\n")
4674 {
4675 int idx_peer = 1;
4676 int idx_number = 3;
4677 char base_xpath[XPATH_MAXLEN];
4678
4679 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4680 sizeof(base_xpath), NULL)
4681 < 0)
4682 return CMD_WARNING_CONFIG_FAILED;
4683
4684 nb_cli_enqueue_change(vty, "./local-as/local-as", NB_OP_MODIFY,
4685 argv[idx_number]->arg);
4686 nb_cli_enqueue_change(vty, "./local-as/no-prepend", NB_OP_MODIFY,
4687 "true");
4688 nb_cli_enqueue_change(vty, "./local-as/no-replace-as", NB_OP_MODIFY,
4689 "true");
4690
4691 return nb_cli_apply_changes(vty, base_xpath);
4692 }
4693
4694 DEFUN_YANG(no_neighbor_local_as,
4695 no_neighbor_local_as_cmd,
4696 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
4697 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4698 "Specify a local-as number\n"
4699 "AS number used as local AS\n"
4700 "Do not prepend local-as to updates from ebgp peers\n"
4701 "Do not prepend local-as to updates from ibgp peers\n")
4702 {
4703 int idx_peer = 2;
4704 char base_xpath[XPATH_MAXLEN];
4705
4706 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4707 sizeof(base_xpath), NULL)
4708 < 0)
4709 return CMD_WARNING_CONFIG_FAILED;
4710
4711 nb_cli_enqueue_change(vty, "./local-as/local-as", NB_OP_DESTROY, NULL);
4712 nb_cli_enqueue_change(vty, "./local-as/no-prepend", NB_OP_MODIFY,
4713 "false");
4714 nb_cli_enqueue_change(vty, "./local-as/no-replace-as", NB_OP_MODIFY,
4715 "false");
4716
4717 return nb_cli_apply_changes(vty, base_xpath);
4718 }
4719
4720
4721 DEFUN (neighbor_solo,
4722 neighbor_solo_cmd,
4723 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
4724 NEIGHBOR_STR
4725 NEIGHBOR_ADDR_STR2
4726 "Solo peer - part of its own update group\n")
4727 {
4728 int idx_peer = 1;
4729 struct peer *peer;
4730 int ret;
4731
4732 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4733 if (!peer)
4734 return CMD_WARNING_CONFIG_FAILED;
4735
4736 ret = update_group_adjust_soloness(peer, 1);
4737 return bgp_vty_return(vty, ret);
4738 }
4739
4740 DEFUN (no_neighbor_solo,
4741 no_neighbor_solo_cmd,
4742 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
4743 NO_STR
4744 NEIGHBOR_STR
4745 NEIGHBOR_ADDR_STR2
4746 "Solo peer - part of its own update group\n")
4747 {
4748 int idx_peer = 2;
4749 struct peer *peer;
4750 int ret;
4751
4752 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4753 if (!peer)
4754 return CMD_WARNING_CONFIG_FAILED;
4755
4756 ret = update_group_adjust_soloness(peer, 0);
4757 return bgp_vty_return(vty, ret);
4758 }
4759
4760 DEFUN_YANG(neighbor_password,
4761 neighbor_password_cmd,
4762 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
4763 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4764 "Set a password\n"
4765 "The password\n")
4766 {
4767 int idx_peer = 1;
4768 int idx_line = 3;
4769 char base_xpath[XPATH_MAXLEN];
4770
4771 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4772 sizeof(base_xpath), NULL)
4773 < 0)
4774 return CMD_WARNING_CONFIG_FAILED;
4775
4776 nb_cli_enqueue_change(vty, "./password", NB_OP_MODIFY,
4777 argv[idx_line]->arg);
4778
4779 return nb_cli_apply_changes(vty, base_xpath);
4780 }
4781
4782 DEFUN_YANG(no_neighbor_password,
4783 no_neighbor_password_cmd,
4784 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
4785 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4786 "Set a password\n"
4787 "The password\n")
4788 {
4789 int idx_peer = 2;
4790 char base_xpath[XPATH_MAXLEN];
4791
4792 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4793 sizeof(base_xpath), NULL)
4794 < 0)
4795 return CMD_WARNING_CONFIG_FAILED;
4796
4797 nb_cli_enqueue_change(vty, "./password", NB_OP_DESTROY, NULL);
4798
4799 return nb_cli_apply_changes(vty, base_xpath);
4800 }
4801
4802 DEFUN_YANG(neighbor_activate,
4803 neighbor_activate_cmd,
4804 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4805 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4806 "Enable the Address Family for this Neighbor\n")
4807 {
4808 int idx_peer = 1;
4809 char base_xpath[XPATH_MAXLEN];
4810 char af_xpath[XPATH_MAXLEN];
4811 afi_t afi = bgp_node_afi(vty);
4812 safi_t safi = bgp_node_safi(vty);
4813
4814 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
4815 yang_afi_safi_value2identity(afi, safi));
4816 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4817 sizeof(base_xpath), af_xpath)
4818 < 0)
4819 return CMD_WARNING_CONFIG_FAILED;
4820
4821 nb_cli_enqueue_change(vty, "./enabled", NB_OP_MODIFY, "true");
4822
4823 return nb_cli_apply_changes(vty, base_xpath);
4824 }
4825
4826 ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
4827 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4828 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4829 "Enable the Address Family for this Neighbor\n")
4830
4831 DEFUN_YANG(no_neighbor_activate,
4832 no_neighbor_activate_cmd,
4833 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4834 NO_STR NEIGHBOR_STR
4835 NEIGHBOR_ADDR_STR2
4836 "Enable the Address Family for this Neighbor\n")
4837 {
4838 int idx_peer = 2;
4839 char base_xpath[XPATH_MAXLEN];
4840 char af_xpath[XPATH_MAXLEN];
4841 afi_t afi = bgp_node_afi(vty);
4842 safi_t safi = bgp_node_safi(vty);
4843
4844 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
4845 yang_afi_safi_value2identity(afi, safi));
4846
4847 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4848 sizeof(base_xpath), af_xpath)
4849 < 0)
4850 return CMD_WARNING_CONFIG_FAILED;
4851
4852 nb_cli_enqueue_change(vty, "./enabled", NB_OP_MODIFY, "false");
4853
4854 return nb_cli_apply_changes(vty, base_xpath);
4855 }
4856
4857 ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
4858 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4859 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4860 "Enable the Address Family for this Neighbor\n")
4861
4862 DEFUN_YANG (neighbor_set_peer_group,
4863 neighbor_set_peer_group_cmd,
4864 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
4865 NEIGHBOR_STR
4866 NEIGHBOR_ADDR_STR2
4867 "Member of the peer-group\n"
4868 "Peer-group name\n")
4869 {
4870 int idx_peer = 1;
4871 int idx_word = 3;
4872 char base_xpath[XPATH_MAXLEN];
4873
4874 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4875 sizeof(base_xpath), NULL)
4876 < 0)
4877 return CMD_WARNING_CONFIG_FAILED;
4878
4879 nb_cli_enqueue_change(vty, "./peer-group", NB_OP_MODIFY,
4880 argv[idx_word]->arg);
4881
4882 return nb_cli_apply_changes(vty, base_xpath);
4883 }
4884
4885 ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
4886 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
4887 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4888 "Member of the peer-group\n"
4889 "Peer-group name\n")
4890
4891 DEFUN_YANG (no_neighbor_set_peer_group,
4892 no_neighbor_set_peer_group_cmd,
4893 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
4894 NO_STR
4895 NEIGHBOR_STR
4896 NEIGHBOR_ADDR_STR2
4897 "Member of the peer-group\n"
4898 "Peer-group name\n")
4899 {
4900 int idx_peer = 2;
4901 char base_xpath[XPATH_MAXLEN];
4902
4903 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4904 sizeof(base_xpath), NULL)
4905 < 0)
4906 return CMD_WARNING_CONFIG_FAILED;
4907
4908 nb_cli_enqueue_change(vty, "./peer-group", NB_OP_DESTROY, NULL);
4909
4910 return nb_cli_apply_changes(vty, base_xpath);
4911 }
4912
4913 ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
4914 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
4915 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4916 "Member of the peer-group\n"
4917 "Peer-group name\n")
4918
4919 static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
4920 uint32_t flag, int set)
4921 {
4922 int ret;
4923 struct peer *peer;
4924
4925 peer = peer_and_group_lookup_vty(vty, ip_str);
4926 if (!peer)
4927 return CMD_WARNING_CONFIG_FAILED;
4928
4929 /*
4930 * If 'neighbor <interface>', then this is for directly connected peers,
4931 * we should not accept disable-connected-check.
4932 */
4933 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
4934 vty_out(vty,
4935 "%s is directly connected peer, cannot accept disable-connected-check\n",
4936 ip_str);
4937 return CMD_WARNING_CONFIG_FAILED;
4938 }
4939
4940 if (!set && flag == PEER_FLAG_SHUTDOWN)
4941 peer_tx_shutdown_message_unset(peer);
4942
4943 if (set)
4944 ret = peer_flag_set(peer, flag);
4945 else
4946 ret = peer_flag_unset(peer, flag);
4947
4948 return bgp_vty_return(vty, ret);
4949 }
4950
4951 static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
4952 {
4953 return peer_flag_modify_vty(vty, ip_str, flag, 1);
4954 }
4955
4956 static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
4957 uint32_t flag)
4958 {
4959 return peer_flag_modify_vty(vty, ip_str, flag, 0);
4960 }
4961
4962 int peer_flag_modify_nb(struct bgp *bgp, const char *ip_str, struct peer *peer,
4963 uint32_t flag, bool set, char *errmsg,
4964 size_t errmsg_len)
4965 {
4966 int ret;
4967
4968 /*
4969 * If 'neighbor <interface>', then this is for directly connected peers,
4970 * we should not accept disable-connected-check.
4971 */
4972 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
4973 snprintf(
4974 errmsg, errmsg_len,
4975 "%s is directly connected peer, cannot accept disable-connected-check\n",
4976 ip_str);
4977 return -1;
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_nb_errmsg_return(errmsg, errmsg_len, ret);
4989 }
4990
4991 /* neighbor passive. */
4992 DEFUN_YANG(neighbor_passive,
4993 neighbor_passive_cmd,
4994 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
4995 NEIGHBOR_STR
4996 NEIGHBOR_ADDR_STR2
4997 "Don't send open messages to this neighbor\n")
4998 {
4999 int idx_peer = 1;
5000 char base_xpath[XPATH_MAXLEN];
5001
5002 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5003 sizeof(base_xpath), NULL)
5004 < 0)
5005 return CMD_WARNING_CONFIG_FAILED;
5006
5007 nb_cli_enqueue_change(vty, "./passive-mode", NB_OP_MODIFY, "true");
5008
5009 return nb_cli_apply_changes(vty, base_xpath);
5010 }
5011
5012 DEFUN_YANG(no_neighbor_passive,
5013 no_neighbor_passive_cmd,
5014 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5015 NO_STR NEIGHBOR_STR
5016 NEIGHBOR_ADDR_STR2
5017 "Don't send open messages to this neighbor\n")
5018 {
5019 int idx_peer = 2;
5020 char base_xpath[XPATH_MAXLEN];
5021
5022 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5023 sizeof(base_xpath), NULL)
5024 < 0)
5025 return CMD_WARNING_CONFIG_FAILED;
5026
5027 nb_cli_enqueue_change(vty, "./passive-mode", NB_OP_MODIFY, "false");
5028
5029 return nb_cli_apply_changes(vty, base_xpath);
5030 }
5031
5032 /* neighbor shutdown. */
5033 DEFUN_YANG(neighbor_shutdown_msg,
5034 neighbor_shutdown_msg_cmd,
5035 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5036 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5037 "Administratively shut down this neighbor\n"
5038 "Add a shutdown message (RFC 8203)\n"
5039 "Shutdown message\n")
5040 {
5041 int idx_peer = 1;
5042 char base_xpath[XPATH_MAXLEN];
5043
5044 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5045 sizeof(base_xpath), NULL)
5046 < 0)
5047 return CMD_WARNING_CONFIG_FAILED;
5048
5049 if (argc >= 5) {
5050 char *message;
5051
5052 message = argv_concat(argv, argc, 4);
5053 nb_cli_enqueue_change(vty, "./admin-shutdown/message",
5054 NB_OP_MODIFY, message);
5055 }
5056
5057 nb_cli_enqueue_change(vty, "./admin-shutdown/enable", NB_OP_MODIFY,
5058 "true");
5059
5060 return nb_cli_apply_changes(vty, base_xpath);
5061 }
5062
5063 ALIAS_YANG(neighbor_shutdown_msg, neighbor_shutdown_cmd,
5064 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5065 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5066 "Administratively shut down this neighbor\n")
5067
5068 DEFUN_YANG(no_neighbor_shutdown_msg,
5069 no_neighbor_shutdown_msg_cmd,
5070 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5071 NO_STR NEIGHBOR_STR
5072 NEIGHBOR_ADDR_STR2
5073 "Administratively shut down this neighbor\n"
5074 "Remove a shutdown message (RFC 8203)\n"
5075 "Shutdown message\n")
5076 {
5077 int idx_peer = 2;
5078 char base_xpath[XPATH_MAXLEN];
5079
5080 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5081 sizeof(base_xpath), NULL)
5082 < 0)
5083 return CMD_WARNING_CONFIG_FAILED;
5084
5085 nb_cli_enqueue_change(vty, "./admin-shutdown/enable", NB_OP_MODIFY,
5086 "false");
5087
5088 return nb_cli_apply_changes(vty, base_xpath);
5089 }
5090
5091 ALIAS_YANG(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
5092 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5093 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5094 "Administratively shut down this neighbor\n")
5095
5096 DEFUN(neighbor_shutdown_rtt,
5097 neighbor_shutdown_rtt_cmd,
5098 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt (1-65535) [count (1-255)]",
5099 NEIGHBOR_STR
5100 NEIGHBOR_ADDR_STR2
5101 "Administratively shut down this neighbor\n"
5102 "Shutdown if round-trip-time is higher than expected\n"
5103 "Round-trip-time in milliseconds\n"
5104 "Specify the number of keepalives before shutdown\n"
5105 "The number of keepalives with higher RTT to shutdown\n")
5106 {
5107 int idx_peer = 1;
5108 int idx_rtt = 4;
5109 int idx_count = 0;
5110 struct peer *peer;
5111
5112 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5113
5114 if (!peer)
5115 return CMD_WARNING_CONFIG_FAILED;
5116
5117 peer->rtt_expected = strtol(argv[idx_rtt]->arg, NULL, 10);
5118
5119 if (argv_find(argv, argc, "count", &idx_count))
5120 peer->rtt_keepalive_conf =
5121 strtol(argv[idx_count + 1]->arg, NULL, 10);
5122
5123 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5124 PEER_FLAG_RTT_SHUTDOWN);
5125 }
5126
5127 DEFUN(no_neighbor_shutdown_rtt,
5128 no_neighbor_shutdown_rtt_cmd,
5129 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt [(1-65535) [count (1-255)]]",
5130 NO_STR
5131 NEIGHBOR_STR
5132 NEIGHBOR_ADDR_STR2
5133 "Administratively shut down this neighbor\n"
5134 "Shutdown if round-trip-time is higher than expected\n"
5135 "Round-trip-time in milliseconds\n"
5136 "Specify the number of keepalives before shutdown\n"
5137 "The number of keepalives with higher RTT to shutdown\n")
5138 {
5139 int idx_peer = 2;
5140 struct peer *peer;
5141
5142 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5143
5144 if (!peer)
5145 return CMD_WARNING_CONFIG_FAILED;
5146
5147 peer->rtt_expected = 0;
5148 peer->rtt_keepalive_conf = 1;
5149
5150 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5151 PEER_FLAG_RTT_SHUTDOWN);
5152 }
5153
5154 /* neighbor capability dynamic. */
5155 DEFUN_YANG (neighbor_capability_dynamic,
5156 neighbor_capability_dynamic_cmd,
5157 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5158 NEIGHBOR_STR
5159 NEIGHBOR_ADDR_STR2
5160 "Advertise capability to the peer\n"
5161 "Advertise dynamic capability to this neighbor\n")
5162 {
5163 int idx_peer = 1;
5164 char base_xpath[XPATH_MAXLEN];
5165
5166 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5167 sizeof(base_xpath), NULL)
5168 < 0)
5169 return CMD_WARNING_CONFIG_FAILED;
5170
5171 nb_cli_enqueue_change(vty, "./capability-options/dynamic-capability",
5172 NB_OP_MODIFY, "true");
5173
5174 return nb_cli_apply_changes(vty, base_xpath);
5175 }
5176
5177 DEFUN_YANG (no_neighbor_capability_dynamic,
5178 no_neighbor_capability_dynamic_cmd,
5179 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5180 NO_STR
5181 NEIGHBOR_STR
5182 NEIGHBOR_ADDR_STR2
5183 "Advertise capability to the peer\n"
5184 "Advertise dynamic capability to this neighbor\n")
5185 {
5186 int idx_peer = 2;
5187 char base_xpath[XPATH_MAXLEN];
5188
5189 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5190 sizeof(base_xpath), NULL)
5191 < 0)
5192 return CMD_WARNING_CONFIG_FAILED;
5193
5194 nb_cli_enqueue_change(vty, "./capability-options/dynamic-capability",
5195 NB_OP_MODIFY, "false");
5196
5197 return nb_cli_apply_changes(vty, base_xpath);
5198 }
5199
5200 /* neighbor dont-capability-negotiate */
5201 DEFUN (neighbor_dont_capability_negotiate,
5202 neighbor_dont_capability_negotiate_cmd,
5203 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
5204 NEIGHBOR_STR
5205 NEIGHBOR_ADDR_STR2
5206 "Do not perform capability negotiation\n")
5207 {
5208 int idx_peer = 1;
5209 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5210 PEER_FLAG_DONT_CAPABILITY);
5211 }
5212
5213 DEFUN (no_neighbor_dont_capability_negotiate,
5214 no_neighbor_dont_capability_negotiate_cmd,
5215 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
5216 NO_STR
5217 NEIGHBOR_STR
5218 NEIGHBOR_ADDR_STR2
5219 "Do not perform capability negotiation\n")
5220 {
5221 int idx_peer = 2;
5222 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5223 PEER_FLAG_DONT_CAPABILITY);
5224 }
5225
5226 /* neighbor capability extended next hop encoding */
5227 DEFUN_YANG (neighbor_capability_enhe,
5228 neighbor_capability_enhe_cmd,
5229 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5230 NEIGHBOR_STR
5231 NEIGHBOR_ADDR_STR2
5232 "Advertise capability to the peer\n"
5233 "Advertise extended next-hop capability to the peer\n")
5234 {
5235 int idx_peer = 1;
5236 char base_xpath[XPATH_MAXLEN];
5237
5238 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5239 sizeof(base_xpath), NULL)
5240 < 0)
5241 return CMD_WARNING_CONFIG_FAILED;
5242
5243 nb_cli_enqueue_change(
5244 vty, "./capability-options/extended-nexthop-capability",
5245 NB_OP_MODIFY, "true");
5246
5247 return nb_cli_apply_changes(vty, base_xpath);
5248 }
5249
5250 DEFUN_YANG (no_neighbor_capability_enhe,
5251 no_neighbor_capability_enhe_cmd,
5252 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5253 NO_STR
5254 NEIGHBOR_STR
5255 NEIGHBOR_ADDR_STR2
5256 "Advertise capability to the peer\n"
5257 "Advertise extended next-hop capability to the peer\n")
5258 {
5259 int idx_peer = 2;
5260 char base_xpath[XPATH_MAXLEN];
5261
5262 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5263 sizeof(base_xpath), NULL)
5264 < 0)
5265 return CMD_WARNING_CONFIG_FAILED;
5266
5267 nb_cli_enqueue_change(
5268 vty, "./capability-options/extended-nexthop-capability",
5269 NB_OP_MODIFY, "false");
5270
5271 return nb_cli_apply_changes(vty, base_xpath);
5272 }
5273
5274 int peer_af_flag_modify_nb(struct peer *peer, afi_t afi, safi_t safi,
5275 uint32_t flag, int set, char *errmsg,
5276 size_t errmsg_len)
5277 {
5278 int ret;
5279
5280 if (set)
5281 ret = peer_af_flag_set(peer, afi, safi, flag);
5282 else
5283 ret = peer_af_flag_unset(peer, afi, safi, flag);
5284
5285 return bgp_nb_errmsg_return(errmsg, errmsg_len, ret);
5286 }
5287
5288 static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
5289 afi_t afi, safi_t safi, uint32_t flag,
5290 int set)
5291 {
5292 int ret;
5293 struct peer *peer;
5294
5295 peer = peer_and_group_lookup_vty(vty, peer_str);
5296 if (!peer)
5297 return CMD_WARNING_CONFIG_FAILED;
5298
5299 if (set)
5300 ret = peer_af_flag_set(peer, afi, safi, flag);
5301 else
5302 ret = peer_af_flag_unset(peer, afi, safi, flag);
5303
5304 return bgp_vty_return(vty, ret);
5305 }
5306
5307 static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
5308 afi_t afi, safi_t safi, uint32_t flag)
5309 {
5310 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
5311 }
5312
5313 static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
5314 afi_t afi, safi_t safi, uint32_t flag)
5315 {
5316 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
5317 }
5318
5319 /* neighbor capability orf prefix-list. */
5320 DEFUN (neighbor_capability_orf_prefix,
5321 neighbor_capability_orf_prefix_cmd,
5322 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5323 NEIGHBOR_STR
5324 NEIGHBOR_ADDR_STR2
5325 "Advertise capability to the peer\n"
5326 "Advertise ORF capability to the peer\n"
5327 "Advertise prefixlist ORF capability to this neighbor\n"
5328 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5329 "Capability to RECEIVE the ORF from this neighbor\n"
5330 "Capability to SEND the ORF to this neighbor\n")
5331 {
5332 int idx_send_recv = 5;
5333 char *peer_str = argv[1]->arg;
5334 struct peer *peer;
5335 afi_t afi = bgp_node_afi(vty);
5336 safi_t safi = bgp_node_safi(vty);
5337
5338 peer = peer_and_group_lookup_vty(vty, peer_str);
5339 if (!peer)
5340 return CMD_WARNING_CONFIG_FAILED;
5341
5342 if (strmatch(argv[idx_send_recv]->text, "send"))
5343 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5344 PEER_FLAG_ORF_PREFIX_SM);
5345
5346 if (strmatch(argv[idx_send_recv]->text, "receive"))
5347 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5348 PEER_FLAG_ORF_PREFIX_RM);
5349
5350 if (strmatch(argv[idx_send_recv]->text, "both"))
5351 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5352 PEER_FLAG_ORF_PREFIX_SM)
5353 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5354 PEER_FLAG_ORF_PREFIX_RM);
5355
5356 return CMD_WARNING_CONFIG_FAILED;
5357 }
5358
5359 ALIAS_HIDDEN(
5360 neighbor_capability_orf_prefix,
5361 neighbor_capability_orf_prefix_hidden_cmd,
5362 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5363 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5364 "Advertise capability to the peer\n"
5365 "Advertise ORF capability to the peer\n"
5366 "Advertise prefixlist ORF capability to this neighbor\n"
5367 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5368 "Capability to RECEIVE the ORF from this neighbor\n"
5369 "Capability to SEND the ORF to this neighbor\n")
5370
5371 DEFUN (no_neighbor_capability_orf_prefix,
5372 no_neighbor_capability_orf_prefix_cmd,
5373 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5374 NO_STR
5375 NEIGHBOR_STR
5376 NEIGHBOR_ADDR_STR2
5377 "Advertise capability to the peer\n"
5378 "Advertise ORF capability to the peer\n"
5379 "Advertise prefixlist ORF capability to this neighbor\n"
5380 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5381 "Capability to RECEIVE the ORF from this neighbor\n"
5382 "Capability to SEND the ORF to this neighbor\n")
5383 {
5384 int idx_send_recv = 6;
5385 char *peer_str = argv[2]->arg;
5386 struct peer *peer;
5387 afi_t afi = bgp_node_afi(vty);
5388 safi_t safi = bgp_node_safi(vty);
5389
5390 peer = peer_and_group_lookup_vty(vty, peer_str);
5391 if (!peer)
5392 return CMD_WARNING_CONFIG_FAILED;
5393
5394 if (strmatch(argv[idx_send_recv]->text, "send"))
5395 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5396 PEER_FLAG_ORF_PREFIX_SM);
5397
5398 if (strmatch(argv[idx_send_recv]->text, "receive"))
5399 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5400 PEER_FLAG_ORF_PREFIX_RM);
5401
5402 if (strmatch(argv[idx_send_recv]->text, "both"))
5403 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5404 PEER_FLAG_ORF_PREFIX_SM)
5405 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5406 PEER_FLAG_ORF_PREFIX_RM);
5407
5408 return CMD_WARNING_CONFIG_FAILED;
5409 }
5410
5411 ALIAS_HIDDEN(
5412 no_neighbor_capability_orf_prefix,
5413 no_neighbor_capability_orf_prefix_hidden_cmd,
5414 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5415 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5416 "Advertise capability to the peer\n"
5417 "Advertise ORF capability to the peer\n"
5418 "Advertise prefixlist ORF capability to this neighbor\n"
5419 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5420 "Capability to RECEIVE the ORF from this neighbor\n"
5421 "Capability to SEND the ORF to this neighbor\n")
5422
5423 /* neighbor next-hop-self. */
5424 DEFUN_YANG (neighbor_nexthop_self,
5425 neighbor_nexthop_self_cmd,
5426 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5427 NEIGHBOR_STR
5428 NEIGHBOR_ADDR_STR2
5429 "Disable the next hop calculation for this neighbor\n")
5430 {
5431 int idx_peer = 1;
5432 char base_xpath[XPATH_MAXLEN];
5433 char af_xpath[XPATH_MAXLEN];
5434 char attr_xpath[XPATH_MAXLEN];
5435 afi_t afi = bgp_node_afi(vty);
5436 safi_t safi = bgp_node_safi(vty);
5437
5438
5439 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5440 yang_afi_safi_value2identity(afi, safi));
5441
5442 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5443 sizeof(base_xpath), af_xpath)
5444 < 0)
5445 return CMD_WARNING_CONFIG_FAILED;
5446
5447 snprintf(attr_xpath, sizeof(attr_xpath),
5448 "./%s/nexthop-self/next-hop-self",
5449 bgp_afi_safi_get_container_str(afi, safi));
5450
5451 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5452
5453 return nb_cli_apply_changes(vty, base_xpath);
5454 }
5455
5456 ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
5457 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5458 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5459 "Disable the next hop calculation for this neighbor\n")
5460
5461 /* neighbor next-hop-self. */
5462 DEFUN_YANG(neighbor_nexthop_self_force,
5463 neighbor_nexthop_self_force_cmd,
5464 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5465 NEIGHBOR_STR
5466 NEIGHBOR_ADDR_STR2
5467 "Disable the next hop calculation for this neighbor\n"
5468 "Set the next hop to self for reflected routes\n")
5469 {
5470 int idx_peer = 1;
5471 char base_xpath[XPATH_MAXLEN];
5472 char af_xpath[XPATH_MAXLEN];
5473 char attr_xpath[XPATH_MAXLEN];
5474 afi_t afi = bgp_node_afi(vty);
5475 safi_t safi = bgp_node_safi(vty);
5476
5477
5478 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5479 yang_afi_safi_value2identity(afi, safi));
5480
5481 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5482 sizeof(base_xpath), af_xpath)
5483 < 0)
5484 return CMD_WARNING_CONFIG_FAILED;
5485
5486 snprintf(attr_xpath, sizeof(attr_xpath),
5487 "./%s/nexthop-self/next-hop-self-force",
5488 bgp_afi_safi_get_container_str(afi, safi));
5489
5490 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5491
5492 return nb_cli_apply_changes(vty, base_xpath);
5493 }
5494
5495 ALIAS_HIDDEN(neighbor_nexthop_self_force,
5496 neighbor_nexthop_self_force_hidden_cmd,
5497 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5498 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5499 "Disable the next hop calculation for this neighbor\n"
5500 "Set the next hop to self for reflected routes\n")
5501
5502 ALIAS_HIDDEN(neighbor_nexthop_self_force,
5503 neighbor_nexthop_self_all_hidden_cmd,
5504 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5505 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5506 "Disable the next hop calculation for this neighbor\n"
5507 "Set the next hop to self for reflected routes\n")
5508
5509 DEFUN_YANG (no_neighbor_nexthop_self,
5510 no_neighbor_nexthop_self_cmd,
5511 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5512 NO_STR
5513 NEIGHBOR_STR
5514 NEIGHBOR_ADDR_STR2
5515 "Disable the next hop calculation for this neighbor\n")
5516 {
5517 int idx_peer = 2;
5518 char base_xpath[XPATH_MAXLEN];
5519 char af_xpath[XPATH_MAXLEN];
5520 char attr_xpath[XPATH_MAXLEN];
5521 afi_t afi = bgp_node_afi(vty);
5522 safi_t safi = bgp_node_safi(vty);
5523
5524 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5525 yang_afi_safi_value2identity(afi, safi));
5526
5527 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5528 sizeof(base_xpath), af_xpath)
5529 < 0)
5530 return CMD_WARNING_CONFIG_FAILED;
5531
5532 snprintf(attr_xpath, sizeof(attr_xpath),
5533 "./%s/nexthop-self/next-hop-self",
5534 bgp_afi_safi_get_container_str(afi, safi));
5535
5536 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5537
5538 return nb_cli_apply_changes(vty, base_xpath);
5539 }
5540
5541 ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
5542 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5543 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5544 "Disable the next hop calculation for this neighbor\n")
5545
5546 DEFUN_YANG (no_neighbor_nexthop_self_force,
5547 no_neighbor_nexthop_self_force_cmd,
5548 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5549 NO_STR
5550 NEIGHBOR_STR
5551 NEIGHBOR_ADDR_STR2
5552 "Disable the next hop calculation for this neighbor\n"
5553 "Set the next hop to self for reflected routes\n")
5554 {
5555 int idx_peer = 2;
5556 char base_xpath[XPATH_MAXLEN];
5557 char af_xpath[XPATH_MAXLEN];
5558 char attr_xpath[XPATH_MAXLEN];
5559 afi_t afi = bgp_node_afi(vty);
5560 safi_t safi = bgp_node_safi(vty);
5561
5562
5563 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5564 yang_afi_safi_value2identity(afi, safi));
5565
5566 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5567 sizeof(base_xpath), af_xpath)
5568 < 0)
5569 return CMD_WARNING_CONFIG_FAILED;
5570
5571 snprintf(attr_xpath, sizeof(attr_xpath),
5572 "./%s/nexthop-self/next-hop-self-force",
5573 bgp_afi_safi_get_container_str(afi, safi));
5574
5575 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5576
5577 return nb_cli_apply_changes(vty, base_xpath);
5578 }
5579
5580 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5581 no_neighbor_nexthop_self_force_hidden_cmd,
5582 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5583 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5584 "Disable the next hop calculation for this neighbor\n"
5585 "Set the next hop to self for reflected routes\n")
5586
5587 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5588 no_neighbor_nexthop_self_all_hidden_cmd,
5589 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5590 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5591 "Disable the next hop calculation for this neighbor\n"
5592 "Set the next hop to self for reflected routes\n")
5593
5594 /* neighbor as-override */
5595 DEFUN_YANG (neighbor_as_override,
5596 neighbor_as_override_cmd,
5597 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5598 NEIGHBOR_STR
5599 NEIGHBOR_ADDR_STR2
5600 "Override ASNs in outbound updates if aspath equals remote-as\n")
5601 {
5602 int idx_peer = 1;
5603 char base_xpath[XPATH_MAXLEN];
5604 char af_xpath[XPATH_MAXLEN];
5605 char attr_xpath[XPATH_MAXLEN];
5606 afi_t afi = bgp_node_afi(vty);
5607 safi_t safi = bgp_node_safi(vty);
5608
5609 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5610 yang_afi_safi_value2identity(afi, safi));
5611
5612 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5613 sizeof(base_xpath), af_xpath)
5614 < 0)
5615 return CMD_WARNING_CONFIG_FAILED;
5616
5617 snprintf(attr_xpath, sizeof(attr_xpath),
5618 "./%s/as-path-options/replace-peer-as",
5619 bgp_afi_safi_get_container_str(afi, safi));
5620
5621 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5622
5623 return nb_cli_apply_changes(vty, base_xpath);
5624 }
5625
5626 ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
5627 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5628 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5629 "Override ASNs in outbound updates if aspath equals remote-as\n")
5630
5631 DEFUN_YANG (no_neighbor_as_override,
5632 no_neighbor_as_override_cmd,
5633 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5634 NO_STR
5635 NEIGHBOR_STR
5636 NEIGHBOR_ADDR_STR2
5637 "Override ASNs in outbound updates if aspath equals remote-as\n")
5638 {
5639 int idx_peer = 2;
5640 char base_xpath[XPATH_MAXLEN];
5641 char af_xpath[XPATH_MAXLEN];
5642 char attr_xpath[XPATH_MAXLEN];
5643 afi_t afi = bgp_node_afi(vty);
5644 safi_t safi = bgp_node_safi(vty);
5645
5646 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5647 yang_afi_safi_value2identity(afi, safi));
5648
5649 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5650 sizeof(base_xpath), af_xpath)
5651 < 0)
5652 return CMD_WARNING_CONFIG_FAILED;
5653
5654 snprintf(attr_xpath, sizeof(attr_xpath),
5655 "./%s/as-path-options/replace-peer-as",
5656 bgp_afi_safi_get_container_str(afi, safi));
5657
5658 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5659
5660 return nb_cli_apply_changes(vty, base_xpath);
5661 }
5662
5663 ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
5664 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5665 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5666 "Override ASNs in outbound updates if aspath equals remote-as\n")
5667
5668 /* neighbor remove-private-AS. */
5669 DEFUN_YANG (neighbor_remove_private_as,
5670 neighbor_remove_private_as_cmd,
5671 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5672 NEIGHBOR_STR
5673 NEIGHBOR_ADDR_STR2
5674 "Remove private ASNs in outbound updates\n")
5675 {
5676 int idx_peer = 1;
5677 char base_xpath[XPATH_MAXLEN];
5678 char af_xpath[XPATH_MAXLEN];
5679 char attr_xpath[XPATH_MAXLEN];
5680 afi_t afi = bgp_node_afi(vty);
5681 safi_t safi = bgp_node_safi(vty);
5682
5683 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5684 yang_afi_safi_value2identity(afi, safi));
5685
5686 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5687 sizeof(base_xpath), af_xpath)
5688 < 0)
5689 return CMD_WARNING_CONFIG_FAILED;
5690
5691 snprintf(attr_xpath, sizeof(attr_xpath),
5692 "./%s/private-as/remove-private-as",
5693 bgp_afi_safi_get_container_str(afi, safi));
5694
5695 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5696
5697 return nb_cli_apply_changes(vty, base_xpath);
5698 }
5699
5700 ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
5701 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5702 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5703 "Remove private ASNs in outbound updates\n")
5704
5705 DEFUN_YANG (neighbor_remove_private_as_all,
5706 neighbor_remove_private_as_all_cmd,
5707 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5708 NEIGHBOR_STR
5709 NEIGHBOR_ADDR_STR2
5710 "Remove private ASNs in outbound updates\n"
5711 "Apply to all AS numbers\n")
5712 {
5713 int idx_peer = 1;
5714 char base_xpath[XPATH_MAXLEN];
5715 char af_xpath[XPATH_MAXLEN];
5716 char attr_xpath[XPATH_MAXLEN];
5717 afi_t afi = bgp_node_afi(vty);
5718 safi_t safi = bgp_node_safi(vty);
5719
5720
5721 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5722 yang_afi_safi_value2identity(afi, safi));
5723
5724 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5725 sizeof(base_xpath), af_xpath)
5726 < 0)
5727 return CMD_WARNING_CONFIG_FAILED;
5728
5729 snprintf(attr_xpath, sizeof(attr_xpath),
5730 "./%s/private-as/remove-private-as-all",
5731 bgp_afi_safi_get_container_str(afi, safi));
5732
5733 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5734
5735 return nb_cli_apply_changes(vty, base_xpath);
5736 }
5737
5738 ALIAS_HIDDEN(neighbor_remove_private_as_all,
5739 neighbor_remove_private_as_all_hidden_cmd,
5740 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5741 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5742 "Remove private ASNs in outbound updates\n"
5743 "Apply to all AS numbers")
5744
5745 DEFUN_YANG (neighbor_remove_private_as_replace_as,
5746 neighbor_remove_private_as_replace_as_cmd,
5747 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5748 NEIGHBOR_STR
5749 NEIGHBOR_ADDR_STR2
5750 "Remove private ASNs in outbound updates\n"
5751 "Replace private ASNs with our ASN in outbound updates\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-replace",
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_replace_as,
5779 neighbor_remove_private_as_replace_as_hidden_cmd,
5780 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5781 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5782 "Remove private ASNs in outbound updates\n"
5783 "Replace private ASNs with our ASN in outbound updates\n")
5784
5785 DEFUN_YANG (neighbor_remove_private_as_all_replace_as,
5786 neighbor_remove_private_as_all_replace_as_cmd,
5787 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5788 NEIGHBOR_STR
5789 NEIGHBOR_ADDR_STR2
5790 "Remove private ASNs in outbound updates\n"
5791 "Apply to all AS numbers\n"
5792 "Replace private ASNs with our ASN in outbound updates\n")
5793 {
5794 int idx_peer = 1;
5795 char base_xpath[XPATH_MAXLEN];
5796 char af_xpath[XPATH_MAXLEN];
5797 char attr_xpath[XPATH_MAXLEN];
5798 afi_t afi = bgp_node_afi(vty);
5799 safi_t safi = bgp_node_safi(vty);
5800
5801
5802 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5803 yang_afi_safi_value2identity(afi, safi));
5804
5805 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5806 sizeof(base_xpath), af_xpath)
5807 < 0)
5808 return CMD_WARNING_CONFIG_FAILED;
5809
5810 snprintf(attr_xpath, sizeof(attr_xpath),
5811 "./%s/private-as/remove-private-as-all-replace",
5812 bgp_afi_safi_get_container_str(afi, safi));
5813
5814 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5815
5816 return nb_cli_apply_changes(vty, base_xpath);
5817 }
5818
5819 ALIAS_HIDDEN(
5820 neighbor_remove_private_as_all_replace_as,
5821 neighbor_remove_private_as_all_replace_as_hidden_cmd,
5822 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5823 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5824 "Remove private ASNs in outbound updates\n"
5825 "Apply to all AS numbers\n"
5826 "Replace private ASNs with our ASN in outbound updates\n")
5827
5828 DEFUN_YANG (no_neighbor_remove_private_as,
5829 no_neighbor_remove_private_as_cmd,
5830 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5831 NO_STR
5832 NEIGHBOR_STR
5833 NEIGHBOR_ADDR_STR2
5834 "Remove private ASNs in outbound updates\n")
5835 {
5836 int idx_peer = 2;
5837 char base_xpath[XPATH_MAXLEN];
5838 char af_xpath[XPATH_MAXLEN];
5839 char attr_xpath[XPATH_MAXLEN];
5840 afi_t afi = bgp_node_afi(vty);
5841 safi_t safi = bgp_node_safi(vty);
5842
5843 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5844 yang_afi_safi_value2identity(afi, safi));
5845
5846 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5847 sizeof(base_xpath), af_xpath)
5848 < 0)
5849 return CMD_WARNING_CONFIG_FAILED;
5850
5851 snprintf(attr_xpath, sizeof(attr_xpath),
5852 "./%s/private-as/remove-private-as",
5853 bgp_afi_safi_get_container_str(afi, safi));
5854
5855 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5856
5857 return nb_cli_apply_changes(vty, base_xpath);
5858 }
5859
5860 ALIAS_HIDDEN(no_neighbor_remove_private_as,
5861 no_neighbor_remove_private_as_hidden_cmd,
5862 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5863 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5864 "Remove private ASNs in outbound updates\n")
5865
5866 DEFUN_YANG (no_neighbor_remove_private_as_all,
5867 no_neighbor_remove_private_as_all_cmd,
5868 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5869 NO_STR
5870 NEIGHBOR_STR
5871 NEIGHBOR_ADDR_STR2
5872 "Remove private ASNs in outbound updates\n"
5873 "Apply to all AS numbers\n")
5874 {
5875 int idx_peer = 2;
5876 char base_xpath[XPATH_MAXLEN];
5877 char af_xpath[XPATH_MAXLEN];
5878 char attr_xpath[XPATH_MAXLEN];
5879 afi_t afi = bgp_node_afi(vty);
5880 safi_t safi = bgp_node_safi(vty);
5881
5882
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-all",
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_all,
5901 no_neighbor_remove_private_as_all_hidden_cmd,
5902 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5903 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5904 "Remove private ASNs in outbound updates\n"
5905 "Apply to all AS numbers\n")
5906
5907 DEFUN_YANG (no_neighbor_remove_private_as_replace_as,
5908 no_neighbor_remove_private_as_replace_as_cmd,
5909 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5910 NO_STR
5911 NEIGHBOR_STR
5912 NEIGHBOR_ADDR_STR2
5913 "Remove private ASNs in outbound updates\n"
5914 "Replace private ASNs with our ASN in outbound updates\n")
5915 {
5916 int idx_peer = 2;
5917 char base_xpath[XPATH_MAXLEN];
5918 char af_xpath[XPATH_MAXLEN];
5919 char attr_xpath[XPATH_MAXLEN];
5920 afi_t afi = bgp_node_afi(vty);
5921 safi_t safi = bgp_node_safi(vty);
5922
5923
5924 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5925 yang_afi_safi_value2identity(afi, safi));
5926
5927 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5928 sizeof(base_xpath), af_xpath)
5929 < 0)
5930 return CMD_WARNING_CONFIG_FAILED;
5931
5932 snprintf(attr_xpath, sizeof(attr_xpath),
5933 "./%s/private-as/remove-private-as-replace",
5934 bgp_afi_safi_get_container_str(afi, safi));
5935
5936 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5937
5938 return nb_cli_apply_changes(vty, base_xpath);
5939 }
5940
5941 ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
5942 no_neighbor_remove_private_as_replace_as_hidden_cmd,
5943 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5944 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5945 "Remove private ASNs in outbound updates\n"
5946 "Replace private ASNs with our ASN in outbound updates\n")
5947
5948 DEFUN_YANG (no_neighbor_remove_private_as_all_replace_as,
5949 no_neighbor_remove_private_as_all_replace_as_cmd,
5950 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5951 NO_STR
5952 NEIGHBOR_STR
5953 NEIGHBOR_ADDR_STR2
5954 "Remove private ASNs in outbound updates\n"
5955 "Apply to all AS numbers\n"
5956 "Replace private ASNs with our ASN in outbound updates\n")
5957 {
5958 int idx_peer = 2;
5959 char base_xpath[XPATH_MAXLEN];
5960 char af_xpath[XPATH_MAXLEN];
5961 char attr_xpath[XPATH_MAXLEN];
5962 afi_t afi = bgp_node_afi(vty);
5963 safi_t safi = bgp_node_safi(vty);
5964
5965
5966 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5967 yang_afi_safi_value2identity(afi, safi));
5968
5969 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5970 sizeof(base_xpath), af_xpath)
5971 < 0)
5972 return CMD_WARNING_CONFIG_FAILED;
5973
5974 snprintf(attr_xpath, sizeof(attr_xpath),
5975 "./%s/private-as/remove-private-as-all-replace",
5976 bgp_afi_safi_get_container_str(afi, safi));
5977
5978 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5979
5980 return nb_cli_apply_changes(vty, base_xpath);
5981 }
5982
5983 ALIAS_HIDDEN(
5984 no_neighbor_remove_private_as_all_replace_as,
5985 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
5986 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5987 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5988 "Remove private ASNs in outbound updates\n"
5989 "Apply to all AS numbers\n"
5990 "Replace private ASNs with our ASN in outbound updates\n")
5991
5992
5993 /* neighbor send-community. */
5994 DEFUN_YANG (neighbor_send_community,
5995 neighbor_send_community_cmd,
5996 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5997 NEIGHBOR_STR
5998 NEIGHBOR_ADDR_STR2
5999 "Send Community attribute to this neighbor\n")
6000 {
6001 int idx_peer = 1;
6002
6003 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6004 bgp_node_safi(vty),
6005 PEER_FLAG_SEND_COMMUNITY);
6006 }
6007
6008 ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
6009 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6010 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6011 "Send Community attribute to this neighbor\n")
6012
6013 DEFUN_YANG (no_neighbor_send_community,
6014 no_neighbor_send_community_cmd,
6015 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6016 NO_STR
6017 NEIGHBOR_STR
6018 NEIGHBOR_ADDR_STR2
6019 "Send Community attribute to this neighbor\n")
6020 {
6021 int idx_peer = 2;
6022
6023 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6024 bgp_node_afi(vty), bgp_node_safi(vty),
6025 PEER_FLAG_SEND_COMMUNITY);
6026 }
6027
6028 ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
6029 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6030 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6031 "Send Community attribute to this neighbor\n")
6032
6033 /* neighbor send-community extended. */
6034 DEFUN_YANG (neighbor_send_community_type,
6035 neighbor_send_community_type_cmd,
6036 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6037 NEIGHBOR_STR
6038 NEIGHBOR_ADDR_STR2
6039 "Send Community attribute to this neighbor\n"
6040 "Send Standard and Extended Community attributes\n"
6041 "Send Standard, Large and Extended Community attributes\n"
6042 "Send Extended Community attributes\n"
6043 "Send Standard Community attributes\n"
6044 "Send Large Community attributes\n")
6045 {
6046 const char *type = argv[argc - 1]->text;
6047 char *peer_str = argv[1]->arg;
6048 char base_xpath[XPATH_MAXLEN];
6049 char af_xpath[XPATH_MAXLEN];
6050 char std_xpath[XPATH_MAXLEN];
6051 char ext_xpath[XPATH_MAXLEN];
6052 char lrg_xpath[XPATH_MAXLEN];
6053 afi_t afi = bgp_node_afi(vty);
6054 safi_t safi = bgp_node_safi(vty);
6055
6056 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6057 yang_afi_safi_value2identity(afi, safi));
6058
6059 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6060 sizeof(base_xpath), af_xpath)
6061 < 0)
6062 return CMD_WARNING_CONFIG_FAILED;
6063
6064 if (strmatch(type, "standard")) {
6065 snprintf(std_xpath, sizeof(std_xpath),
6066 "./%s/send-community/send-community",
6067 bgp_afi_safi_get_container_str(afi, safi));
6068
6069 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "true");
6070 }
6071
6072 if (strmatch(type, "extended")) {
6073 snprintf(ext_xpath, sizeof(ext_xpath),
6074 "./%s/send-community/send-ext-community",
6075 bgp_afi_safi_get_container_str(afi, safi));
6076
6077 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "true");
6078 }
6079
6080 if (strmatch(type, "large")) {
6081 snprintf(lrg_xpath, sizeof(lrg_xpath),
6082 "./%s/send-community/send-large-community",
6083 bgp_afi_safi_get_container_str(afi, safi));
6084
6085 nb_cli_enqueue_change(vty, lrg_xpath, NB_OP_MODIFY, "true");
6086 }
6087
6088 if (strmatch(type, "both")) {
6089 snprintf(std_xpath, sizeof(std_xpath),
6090 "./%s/send-community/send-community",
6091 bgp_afi_safi_get_container_str(afi, safi));
6092
6093 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "true");
6094
6095 snprintf(ext_xpath, sizeof(ext_xpath),
6096 "./%s/send-community/send-ext-community",
6097 bgp_afi_safi_get_container_str(afi, safi));
6098
6099 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "true");
6100 }
6101
6102 if (strmatch(type, "all")) {
6103 snprintf(std_xpath, sizeof(std_xpath),
6104 "./%s/send-community/send-community",
6105 bgp_afi_safi_get_container_str(afi, safi));
6106
6107 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "true");
6108
6109 snprintf(ext_xpath, sizeof(ext_xpath),
6110 "./%s/send-community/send-ext-community",
6111 bgp_afi_safi_get_container_str(afi, safi));
6112
6113 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "true");
6114
6115 snprintf(lrg_xpath, sizeof(lrg_xpath),
6116 "./%s/send-community/send-large-community",
6117 bgp_afi_safi_get_container_str(afi, safi));
6118
6119 nb_cli_enqueue_change(vty, lrg_xpath, NB_OP_MODIFY, "true");
6120 }
6121
6122 return nb_cli_apply_changes(vty, base_xpath);
6123 }
6124
6125 ALIAS_HIDDEN(
6126 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
6127 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6128 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6129 "Send Community attribute to this neighbor\n"
6130 "Send Standard and Extended Community attributes\n"
6131 "Send Standard, Large and Extended Community attributes\n"
6132 "Send Extended Community attributes\n"
6133 "Send Standard Community attributes\n"
6134 "Send Large Community attributes\n")
6135
6136 DEFUN_YANG (no_neighbor_send_community_type,
6137 no_neighbor_send_community_type_cmd,
6138 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6139 NO_STR
6140 NEIGHBOR_STR
6141 NEIGHBOR_ADDR_STR2
6142 "Send Community attribute to this neighbor\n"
6143 "Send Standard and Extended Community attributes\n"
6144 "Send Standard, Large and Extended Community attributes\n"
6145 "Send Extended Community attributes\n"
6146 "Send Standard Community attributes\n"
6147 "Send Large Community attributes\n")
6148 {
6149 const char *type = argv[argc - 1]->text;
6150 char *peer_str = argv[2]->arg;
6151 char base_xpath[XPATH_MAXLEN];
6152 char af_xpath[XPATH_MAXLEN];
6153 char std_xpath[XPATH_MAXLEN];
6154 char ext_xpath[XPATH_MAXLEN];
6155 char lrg_xpath[XPATH_MAXLEN];
6156 afi_t afi = bgp_node_afi(vty);
6157 safi_t safi = bgp_node_safi(vty);
6158
6159 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6160 yang_afi_safi_value2identity(afi, safi));
6161
6162 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6163 sizeof(base_xpath), af_xpath)
6164 < 0)
6165 return CMD_WARNING_CONFIG_FAILED;
6166
6167 if (strmatch(type, "standard")) {
6168 snprintf(std_xpath, sizeof(std_xpath),
6169 "./%s/send-community/send-community",
6170 bgp_afi_safi_get_container_str(afi, safi));
6171
6172 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "false");
6173 }
6174
6175 if (strmatch(type, "extended")) {
6176 snprintf(ext_xpath, sizeof(ext_xpath),
6177 "./%s/send-community/send-ext-community",
6178 bgp_afi_safi_get_container_str(afi, safi));
6179
6180 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "false");
6181 }
6182
6183 if (strmatch(type, "large")) {
6184 snprintf(lrg_xpath, sizeof(lrg_xpath),
6185 "./%s/send-community/send-large-community",
6186 bgp_afi_safi_get_container_str(afi, safi));
6187
6188 nb_cli_enqueue_change(vty, lrg_xpath, NB_OP_MODIFY, "false");
6189 }
6190
6191 if (strmatch(type, "both")) {
6192 snprintf(std_xpath, sizeof(std_xpath),
6193 "./%s/send-community/send-community",
6194 bgp_afi_safi_get_container_str(afi, safi));
6195
6196 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "false");
6197
6198 snprintf(ext_xpath, sizeof(ext_xpath),
6199 "./%s/send-community/send-ext-community",
6200 bgp_afi_safi_get_container_str(afi, safi));
6201
6202 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "false");
6203 }
6204
6205 if (strmatch(type, "all")) {
6206 snprintf(std_xpath, sizeof(std_xpath),
6207 "./%s/send-community/send-community",
6208 bgp_afi_safi_get_container_str(afi, safi));
6209
6210 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "false");
6211
6212 snprintf(ext_xpath, sizeof(ext_xpath),
6213 "./%s/send-community/send-ext-community",
6214 bgp_afi_safi_get_container_str(afi, safi));
6215
6216 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "false");
6217
6218 snprintf(lrg_xpath, sizeof(lrg_xpath),
6219 "./%s/send-community/send-large-community",
6220 bgp_afi_safi_get_container_str(afi, safi));
6221
6222 nb_cli_enqueue_change(vty, lrg_xpath, NB_OP_MODIFY, "false");
6223 }
6224
6225 return nb_cli_apply_changes(vty, base_xpath);
6226 }
6227
6228 ALIAS_HIDDEN(
6229 no_neighbor_send_community_type,
6230 no_neighbor_send_community_type_hidden_cmd,
6231 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6232 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6233 "Send Community attribute to this neighbor\n"
6234 "Send Standard and Extended Community attributes\n"
6235 "Send Standard, Large and Extended Community attributes\n"
6236 "Send Extended Community attributes\n"
6237 "Send Standard Community attributes\n"
6238 "Send Large Community attributes\n")
6239
6240 /* neighbor soft-reconfig. */
6241 DEFUN_YANG (neighbor_soft_reconfiguration,
6242 neighbor_soft_reconfiguration_cmd,
6243 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6244 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6245 "Per neighbor soft reconfiguration\n"
6246 "Allow inbound soft reconfiguration for this neighbor\n")
6247 {
6248 int idx_peer = 1;
6249 char base_xpath[XPATH_MAXLEN];
6250 char af_xpath[XPATH_MAXLEN];
6251 char soft_xpath[XPATH_MAXLEN];
6252 afi_t afi = bgp_node_afi(vty);
6253 safi_t safi = bgp_node_safi(vty);
6254
6255
6256 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6257 yang_afi_safi_value2identity(afi, safi));
6258
6259 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6260 sizeof(base_xpath), af_xpath)
6261 < 0)
6262 return CMD_WARNING_CONFIG_FAILED;
6263
6264 snprintf(soft_xpath, sizeof(soft_xpath), "./%s/soft-reconfiguration",
6265 bgp_afi_safi_get_container_str(afi, safi));
6266
6267 nb_cli_enqueue_change(vty, soft_xpath, NB_OP_MODIFY, "true");
6268
6269 return nb_cli_apply_changes(vty, base_xpath);
6270 }
6271
6272 ALIAS_HIDDEN(neighbor_soft_reconfiguration,
6273 neighbor_soft_reconfiguration_hidden_cmd,
6274 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6275 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6276 "Per neighbor soft reconfiguration\n"
6277 "Allow inbound soft reconfiguration for this neighbor\n")
6278
6279 DEFUN_YANG (no_neighbor_soft_reconfiguration,
6280 no_neighbor_soft_reconfiguration_cmd,
6281 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6282 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6283 "Per neighbor soft reconfiguration\n"
6284 "Allow inbound soft reconfiguration for this neighbor\n")
6285 {
6286 int idx_peer = 2;
6287 char base_xpath[XPATH_MAXLEN];
6288 char af_xpath[XPATH_MAXLEN];
6289 char soft_xpath[XPATH_MAXLEN];
6290 afi_t afi = bgp_node_afi(vty);
6291 safi_t safi = bgp_node_safi(vty);
6292
6293 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6294 yang_afi_safi_value2identity(afi, safi));
6295
6296 snprintf(soft_xpath, sizeof(soft_xpath), "./%s/soft-reconfiguration",
6297 bgp_afi_safi_get_container_str(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 nb_cli_enqueue_change(vty, soft_xpath, NB_OP_MODIFY, "false");
6305
6306 return nb_cli_apply_changes(vty, base_xpath);
6307 }
6308
6309 ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
6310 no_neighbor_soft_reconfiguration_hidden_cmd,
6311 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6312 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6313 "Per neighbor soft reconfiguration\n"
6314 "Allow inbound soft reconfiguration for this neighbor\n")
6315
6316 DEFUN_YANG (neighbor_route_reflector_client,
6317 neighbor_route_reflector_client_cmd,
6318 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6319 NEIGHBOR_STR
6320 NEIGHBOR_ADDR_STR2
6321 "Configure a neighbor as Route Reflector client\n")
6322 {
6323 int idx_peer = 1;
6324 char base_xpath[XPATH_MAXLEN];
6325 char af_xpath[XPATH_MAXLEN];
6326 char attr_xpath[XPATH_MAXLEN];
6327 afi_t afi = bgp_node_afi(vty);
6328 safi_t safi = bgp_node_safi(vty);
6329
6330 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6331 yang_afi_safi_value2identity(afi, safi));
6332
6333 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6334 sizeof(base_xpath), af_xpath)
6335 < 0)
6336 return CMD_WARNING_CONFIG_FAILED;
6337
6338 snprintf(attr_xpath, sizeof(attr_xpath),
6339 "./%s/route-reflector/route-reflector-client",
6340 bgp_afi_safi_get_container_str(afi, safi));
6341
6342 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
6343
6344 return nb_cli_apply_changes(vty, base_xpath);
6345 }
6346
6347 ALIAS_HIDDEN(neighbor_route_reflector_client,
6348 neighbor_route_reflector_client_hidden_cmd,
6349 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6350 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6351 "Configure a neighbor as Route Reflector client\n")
6352
6353 DEFUN_YANG (no_neighbor_route_reflector_client,
6354 no_neighbor_route_reflector_client_cmd,
6355 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6356 NO_STR
6357 NEIGHBOR_STR
6358 NEIGHBOR_ADDR_STR2
6359 "Configure a neighbor as Route Reflector client\n")
6360 {
6361 int idx_peer = 2;
6362 char base_xpath[XPATH_MAXLEN];
6363 char af_xpath[XPATH_MAXLEN];
6364 char attr_xpath[XPATH_MAXLEN];
6365 afi_t afi = bgp_node_afi(vty);
6366 safi_t safi = bgp_node_safi(vty);
6367
6368 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6369 yang_afi_safi_value2identity(afi, safi));
6370
6371 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6372 sizeof(base_xpath), af_xpath)
6373 < 0)
6374 return CMD_WARNING_CONFIG_FAILED;
6375
6376 snprintf(attr_xpath, sizeof(attr_xpath),
6377 "./%s/route-reflector/route-reflector-client",
6378 bgp_afi_safi_get_container_str(afi, safi));
6379
6380 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6381
6382 return nb_cli_apply_changes(vty, base_xpath);
6383 }
6384
6385 ALIAS_HIDDEN(no_neighbor_route_reflector_client,
6386 no_neighbor_route_reflector_client_hidden_cmd,
6387 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6388 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6389 "Configure a neighbor as Route Reflector client\n")
6390
6391 /* neighbor route-server-client. */
6392 DEFUN_YANG (neighbor_route_server_client,
6393 neighbor_route_server_client_cmd,
6394 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6395 NEIGHBOR_STR
6396 NEIGHBOR_ADDR_STR2
6397 "Configure a neighbor as Route Server client\n")
6398 {
6399 int idx_peer = 1;
6400 char base_xpath[XPATH_MAXLEN];
6401 char af_xpath[XPATH_MAXLEN];
6402 char attr_xpath[XPATH_MAXLEN];
6403 afi_t afi = bgp_node_afi(vty);
6404 safi_t safi = bgp_node_safi(vty);
6405
6406 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6407 yang_afi_safi_value2identity(afi, safi));
6408
6409 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6410 sizeof(base_xpath), af_xpath)
6411 < 0)
6412 return CMD_WARNING_CONFIG_FAILED;
6413
6414 snprintf(attr_xpath, sizeof(attr_xpath),
6415 "./%s/route-server/route-server-client",
6416 bgp_afi_safi_get_container_str(afi, safi));
6417
6418 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
6419
6420 return nb_cli_apply_changes(vty, base_xpath);
6421 }
6422
6423 ALIAS_HIDDEN(neighbor_route_server_client,
6424 neighbor_route_server_client_hidden_cmd,
6425 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6426 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6427 "Configure a neighbor as Route Server client\n")
6428
6429 DEFUN_YANG (no_neighbor_route_server_client,
6430 no_neighbor_route_server_client_cmd,
6431 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6432 NO_STR
6433 NEIGHBOR_STR
6434 NEIGHBOR_ADDR_STR2
6435 "Configure a neighbor as Route Server client\n")
6436 {
6437 int idx_peer = 2;
6438 char base_xpath[XPATH_MAXLEN];
6439 char af_xpath[XPATH_MAXLEN];
6440 char attr_xpath[XPATH_MAXLEN];
6441 afi_t afi = bgp_node_afi(vty);
6442 safi_t safi = bgp_node_safi(vty);
6443
6444 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6445 yang_afi_safi_value2identity(afi, safi));
6446
6447 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6448 sizeof(base_xpath), af_xpath)
6449 < 0)
6450 return CMD_WARNING_CONFIG_FAILED;
6451
6452 snprintf(attr_xpath, sizeof(attr_xpath),
6453 "./%s/route-server/route-server-client",
6454 bgp_afi_safi_get_container_str(afi, safi));
6455
6456 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6457
6458 return nb_cli_apply_changes(vty, base_xpath);
6459 }
6460
6461 ALIAS_HIDDEN(no_neighbor_route_server_client,
6462 no_neighbor_route_server_client_hidden_cmd,
6463 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6464 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6465 "Configure a neighbor as Route Server client\n")
6466
6467 DEFUN (neighbor_nexthop_local_unchanged,
6468 neighbor_nexthop_local_unchanged_cmd,
6469 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
6470 NEIGHBOR_STR
6471 NEIGHBOR_ADDR_STR2
6472 "Configure treatment of outgoing link-local nexthop attribute\n"
6473 "Leave link-local nexthop unchanged for this peer\n")
6474 {
6475 int idx_peer = 1;
6476 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6477 bgp_node_safi(vty),
6478 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
6479 }
6480
6481 DEFUN (no_neighbor_nexthop_local_unchanged,
6482 no_neighbor_nexthop_local_unchanged_cmd,
6483 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
6484 NO_STR
6485 NEIGHBOR_STR
6486 NEIGHBOR_ADDR_STR2
6487 "Configure treatment of outgoing link-local-nexthop attribute\n"
6488 "Leave link-local nexthop unchanged for this peer\n")
6489 {
6490 int idx_peer = 2;
6491 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6492 bgp_node_afi(vty), bgp_node_safi(vty),
6493 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
6494 }
6495
6496 DEFUN_YANG (neighbor_attr_unchanged,
6497 neighbor_attr_unchanged_cmd,
6498 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6499 NEIGHBOR_STR
6500 NEIGHBOR_ADDR_STR2
6501 "BGP attribute is propagated unchanged to this neighbor\n"
6502 "As-path attribute\n"
6503 "Nexthop attribute\n"
6504 "Med attribute\n")
6505 {
6506 int idx = 0;
6507 char *peer_str = argv[1]->arg;
6508 bool aspath = false;
6509 bool nexthop = false;
6510 bool med = false;
6511 afi_t afi = bgp_node_afi(vty);
6512 safi_t safi = bgp_node_safi(vty);
6513 char base_xpath[XPATH_MAXLEN];
6514 char af_xpath[XPATH_MAXLEN];
6515 char as_xpath[XPATH_MAXLEN];
6516 char nxthop_xpath[XPATH_MAXLEN];
6517 char med_xpath[XPATH_MAXLEN];
6518
6519 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6520 yang_afi_safi_value2identity(afi, safi));
6521
6522 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6523 sizeof(base_xpath), af_xpath)
6524 < 0)
6525 return CMD_WARNING_CONFIG_FAILED;
6526
6527 if (argv_find(argv, argc, "as-path", &idx))
6528 aspath = true;
6529
6530 idx = 0;
6531 if (argv_find(argv, argc, "next-hop", &idx))
6532 nexthop = true;
6533
6534 idx = 0;
6535 if (argv_find(argv, argc, "med", &idx))
6536 med = true;
6537
6538 snprintf(as_xpath, sizeof(as_xpath),
6539 "./%s/attr-unchanged/as-path-unchanged",
6540 bgp_afi_safi_get_container_str(afi, safi));
6541 snprintf(nxthop_xpath, sizeof(nxthop_xpath),
6542 "./%s/attr-unchanged/next-hop-unchanged",
6543 bgp_afi_safi_get_container_str(afi, safi));
6544 snprintf(med_xpath, sizeof(med_xpath),
6545 "./%s/attr-unchanged/med-unchanged",
6546 bgp_afi_safi_get_container_str(afi, safi));
6547
6548 /* no flags means all of them! */
6549 if (!aspath && !nexthop && !med) {
6550 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY, "true");
6551 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY, "true");
6552 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY, "true");
6553 } else {
6554 if (!aspath)
6555 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY,
6556 "false");
6557 else
6558 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY,
6559 "true");
6560
6561 if (!nexthop)
6562 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY,
6563 "false");
6564 else
6565 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY,
6566 "true");
6567
6568 if (!med)
6569 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY,
6570 "false");
6571 else
6572 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY,
6573 "true");
6574 }
6575
6576 return nb_cli_apply_changes(vty, base_xpath);
6577 }
6578
6579 ALIAS_HIDDEN(
6580 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
6581 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6582 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6583 "BGP attribute is propagated unchanged to this neighbor\n"
6584 "As-path attribute\n"
6585 "Nexthop attribute\n"
6586 "Med attribute\n")
6587
6588 DEFUN_YANG (no_neighbor_attr_unchanged,
6589 no_neighbor_attr_unchanged_cmd,
6590 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6591 NO_STR
6592 NEIGHBOR_STR
6593 NEIGHBOR_ADDR_STR2
6594 "BGP attribute is propagated unchanged to this neighbor\n"
6595 "As-path attribute\n"
6596 "Nexthop attribute\n"
6597 "Med attribute\n")
6598 {
6599 int idx = 0;
6600 char *peer_str = argv[2]->arg;
6601 bool aspath = false;
6602 bool nexthop = false;
6603 bool med = false;
6604 afi_t afi = bgp_node_afi(vty);
6605 safi_t safi = bgp_node_safi(vty);
6606 char base_xpath[XPATH_MAXLEN];
6607 char af_xpath[XPATH_MAXLEN];
6608 char as_xpath[XPATH_MAXLEN];
6609 char nxthop_xpath[XPATH_MAXLEN];
6610 char med_xpath[XPATH_MAXLEN];
6611
6612 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6613 yang_afi_safi_value2identity(afi, safi));
6614
6615 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6616 sizeof(base_xpath), af_xpath)
6617 < 0)
6618 return CMD_WARNING_CONFIG_FAILED;
6619
6620 if (argv_find(argv, argc, "as-path", &idx))
6621 aspath = true;
6622
6623 idx = 0;
6624 if (argv_find(argv, argc, "next-hop", &idx))
6625 nexthop = true;
6626
6627 idx = 0;
6628 if (argv_find(argv, argc, "med", &idx))
6629 med = true;
6630
6631 snprintf(as_xpath, sizeof(as_xpath),
6632 "./%s/attr-unchanged/as-path-unchanged",
6633 bgp_afi_safi_get_container_str(afi, safi));
6634 snprintf(nxthop_xpath, sizeof(nxthop_xpath),
6635 "./%s/attr-unchanged/next-hop-unchanged",
6636 bgp_afi_safi_get_container_str(afi, safi));
6637 snprintf(med_xpath, sizeof(med_xpath),
6638 "./%s/attr-unchanged/med-unchanged",
6639 bgp_afi_safi_get_container_str(afi, safi));
6640
6641 /* no flags means all of them! */
6642 if (!aspath && !nexthop && !med) {
6643 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY, "false");
6644 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY, "false");
6645 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY, "false");
6646 }
6647
6648 if (aspath)
6649 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY, "false");
6650
6651 if (nexthop)
6652 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY, "false");
6653
6654 if (med)
6655 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY, "false");
6656
6657 return nb_cli_apply_changes(vty, base_xpath);
6658 }
6659
6660 ALIAS_HIDDEN(
6661 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
6662 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6663 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6664 "BGP attribute is propagated unchanged to this neighbor\n"
6665 "As-path attribute\n"
6666 "Nexthop attribute\n"
6667 "Med attribute\n")
6668
6669 /* neighbor ebgp-multihop. */
6670 DEFUN_YANG (neighbor_ebgp_multihop,
6671 neighbor_ebgp_multihop_cmd,
6672 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
6673 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6674 "Allow EBGP neighbors not on directly connected networks\n")
6675 {
6676 int idx_peer = 1;
6677 char base_xpath[XPATH_MAXLEN];
6678
6679 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6680 sizeof(base_xpath), NULL)
6681 < 0)
6682 return CMD_WARNING_CONFIG_FAILED;
6683
6684 nb_cli_enqueue_change(vty, "./ebgp-multihop/enabled", NB_OP_MODIFY,
6685 "true");
6686
6687 return nb_cli_apply_changes(vty, base_xpath);
6688 }
6689
6690 DEFUN_YANG (neighbor_ebgp_multihop_ttl,
6691 neighbor_ebgp_multihop_ttl_cmd,
6692 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
6693 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6694 "Allow EBGP neighbors not on directly connected networks\n"
6695 "maximum hop count\n")
6696 {
6697 int idx_peer = 1;
6698 int idx_number = 3;
6699 char base_xpath[XPATH_MAXLEN];
6700
6701 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6702 sizeof(base_xpath), NULL)
6703 < 0)
6704 return CMD_WARNING_CONFIG_FAILED;
6705
6706 nb_cli_enqueue_change(vty, "./ebgp-multihop/multihop-ttl", NB_OP_MODIFY,
6707 argv[idx_number]->arg);
6708
6709 return nb_cli_apply_changes(vty, base_xpath);
6710 }
6711
6712 DEFUN_YANG (no_neighbor_ebgp_multihop,
6713 no_neighbor_ebgp_multihop_cmd,
6714 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
6715 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6716 "Allow EBGP neighbors not on directly connected networks\n"
6717 "maximum hop count\n")
6718 {
6719 int idx_peer = 2;
6720 char base_xpath[XPATH_MAXLEN];
6721
6722 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6723 sizeof(base_xpath), NULL)
6724 < 0)
6725 return CMD_WARNING_CONFIG_FAILED;
6726
6727 if (argc > 4)
6728 nb_cli_enqueue_change(vty, "./ebgp-multihop/multihop-ttl",
6729 NB_OP_DESTROY, NULL);
6730 else
6731 nb_cli_enqueue_change(vty, "./ebgp-multihop/enabled",
6732 NB_OP_MODIFY, "false");
6733
6734 return nb_cli_apply_changes(vty, base_xpath);
6735 }
6736
6737
6738 /* disable-connected-check */
6739 DEFUN_YANG (neighbor_disable_connected_check,
6740 neighbor_disable_connected_check_cmd,
6741 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6742 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6743 "one-hop away EBGP peer using loopback address\n"
6744 "Enforce EBGP neighbors perform multihop\n")
6745 {
6746 int idx_peer = 1;
6747 char base_xpath[XPATH_MAXLEN];
6748
6749 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6750 sizeof(base_xpath), NULL)
6751 < 0)
6752 return CMD_WARNING_CONFIG_FAILED;
6753
6754 nb_cli_enqueue_change(vty, "./ebgp-multihop/disable-connected-check",
6755 NB_OP_MODIFY, "true");
6756
6757 return nb_cli_apply_changes(vty, base_xpath);
6758 }
6759
6760 DEFUN_YANG (no_neighbor_disable_connected_check,
6761 no_neighbor_disable_connected_check_cmd,
6762 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6763 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6764 "one-hop away EBGP peer using loopback address\n"
6765 "Enforce EBGP neighbors perform multihop\n")
6766 {
6767 int idx_peer = 2;
6768 char base_xpath[XPATH_MAXLEN];
6769
6770 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6771 sizeof(base_xpath), NULL)
6772 < 0)
6773 return CMD_WARNING_CONFIG_FAILED;
6774
6775 nb_cli_enqueue_change(vty, "./ebgp-multihop/disable-connected-check",
6776 NB_OP_MODIFY, "false");
6777
6778 return nb_cli_apply_changes(vty, base_xpath);
6779 }
6780
6781
6782 /* enforce-first-as */
6783 DEFUN_YANG (neighbor_enforce_first_as,
6784 neighbor_enforce_first_as_cmd,
6785 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6786 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6787 "Enforce the first AS for EBGP routes\n")
6788 {
6789 int idx_peer = 1;
6790 char base_xpath[XPATH_MAXLEN];
6791
6792 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6793 sizeof(base_xpath), NULL)
6794 < 0)
6795 return CMD_WARNING_CONFIG_FAILED;
6796
6797 nb_cli_enqueue_change(vty, "./enforce-first-as", NB_OP_MODIFY, "true");
6798
6799 return nb_cli_apply_changes(vty, base_xpath);
6800 }
6801
6802 DEFUN_YANG (no_neighbor_enforce_first_as,
6803 no_neighbor_enforce_first_as_cmd,
6804 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6805 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6806 "Enforce the first AS for EBGP routes\n")
6807 {
6808 int idx_peer = 2;
6809 char base_xpath[XPATH_MAXLEN];
6810
6811 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6812 sizeof(base_xpath), NULL)
6813 < 0)
6814 return CMD_WARNING_CONFIG_FAILED;
6815
6816 nb_cli_enqueue_change(vty, "./enforce-first-as", NB_OP_MODIFY, "false");
6817
6818 return nb_cli_apply_changes(vty, base_xpath);
6819 }
6820
6821 static int peer_and_group_lookup_nb(struct vty *vty, const char *peer_str,
6822 char *base_xpath, int xpath_len,
6823 char *xpath)
6824 {
6825 union sockunion su;
6826 char num_xpath[XPATH_MAXLEN];
6827 char unnbr_xpath[XPATH_MAXLEN];
6828 char prgrp_xpath[XPATH_MAXLEN];
6829
6830 if (str2sockunion(peer_str, &su) == 0) {
6831 snprintf(num_xpath, sizeof(num_xpath),
6832 "/neighbors/neighbor[remote-address='%s']", peer_str);
6833 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
6834 VTY_CURR_XPATH, num_xpath)) {
6835 snprintf(base_xpath, xpath_len,
6836 FRR_BGP_NEIGHBOR_NUM_XPATH, peer_str,
6837 xpath ? xpath : "");
6838 } else {
6839 vty_out(vty,
6840 "%% Specify remote-as or peer-group commands first\n");
6841 return -1;
6842 }
6843
6844 } else {
6845 snprintf(unnbr_xpath, sizeof(unnbr_xpath),
6846 "/neighbors/unnumbered-neighbor[interface='%s']",
6847 peer_str);
6848
6849 snprintf(prgrp_xpath, sizeof(prgrp_xpath),
6850 "/peer-groups/peer-group[peer-group-name='%s']",
6851 peer_str);
6852
6853 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
6854 VTY_CURR_XPATH, unnbr_xpath)) {
6855 snprintf(base_xpath, xpath_len,
6856 FRR_BGP_NEIGHBOR_UNNUM_XPATH, peer_str,
6857 xpath ? xpath : "");
6858 } else if (yang_dnode_exists(vty->candidate_config->dnode,
6859 "%s%s", VTY_CURR_XPATH,
6860 prgrp_xpath)) {
6861 snprintf(base_xpath, xpath_len,
6862 FRR_BGP_PEER_GROUP_XPATH, peer_str,
6863 xpath ? xpath : "");
6864 } else {
6865 vty_out(vty,
6866 "%% Create the peer-group or interface first\n");
6867 return -1;
6868 }
6869 }
6870
6871 return 0;
6872 }
6873
6874 DEFUN_YANG (neighbor_description,
6875 neighbor_description_cmd,
6876 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6877 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6878 "Neighbor specific description\n"
6879 "Up to 80 characters describing this neighbor\n")
6880 {
6881 int idx_peer = 1;
6882 int idx_line = 3;
6883 int ret;
6884 char base_xpath[XPATH_MAXLEN];
6885 char *str;
6886
6887 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6888 sizeof(base_xpath), NULL)
6889 < 0)
6890 return CMD_WARNING_CONFIG_FAILED;
6891
6892 str = argv_concat(argv, argc, idx_line);
6893
6894 nb_cli_enqueue_change(vty, "./description", NB_OP_MODIFY, str);
6895
6896 ret = nb_cli_apply_changes(vty, base_xpath);
6897
6898 XFREE(MTYPE_TMP, str);
6899
6900 return ret;
6901 }
6902
6903 DEFUN_YANG (no_neighbor_description,
6904 no_neighbor_description_cmd,
6905 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
6906 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6907 "Neighbor specific description\n")
6908 {
6909 int idx_peer = 2;
6910 char base_xpath[XPATH_MAXLEN];
6911
6912 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6913 sizeof(base_xpath), NULL)
6914 < 0)
6915 return CMD_WARNING_CONFIG_FAILED;
6916
6917 nb_cli_enqueue_change(vty, "./description", NB_OP_DESTROY, NULL);
6918
6919 return nb_cli_apply_changes(vty, base_xpath);
6920 }
6921
6922 ALIAS_YANG(no_neighbor_description, no_neighbor_description_comment_cmd,
6923 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6924 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6925 "Neighbor specific description\n"
6926 "Up to 80 characters describing this neighbor\n")
6927
6928 #define BGP_UPDATE_SOURCE_HELP_STR \
6929 "IPv4 address\n" \
6930 "IPv6 address\n" \
6931 "Interface name (requires zebra to be running)\n"
6932
6933 DEFUN_YANG (neighbor_update_source,
6934 neighbor_update_source_cmd,
6935 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
6936 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6937 "Source of routing updates\n"
6938 BGP_UPDATE_SOURCE_HELP_STR)
6939 {
6940 int idx_peer = 1;
6941 int idx_peer_2 = 3;
6942 union sockunion su;
6943 char base_xpath[XPATH_MAXLEN];
6944
6945 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6946 sizeof(base_xpath), NULL)
6947 < 0)
6948 return CMD_WARNING_CONFIG_FAILED;
6949
6950 if (str2sockunion(argv[idx_peer_2]->arg, &su) == 0)
6951 nb_cli_enqueue_change(vty, "./update-source/ip", NB_OP_MODIFY,
6952 argv[idx_peer_2]->arg);
6953 else
6954 nb_cli_enqueue_change(vty, "./update-source/interface",
6955 NB_OP_MODIFY, argv[idx_peer_2]->arg);
6956
6957 return nb_cli_apply_changes(vty, base_xpath);
6958 }
6959
6960 DEFUN_YANG (no_neighbor_update_source,
6961 no_neighbor_update_source_cmd,
6962 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
6963 NO_STR NEIGHBOR_STR
6964 NEIGHBOR_ADDR_STR2
6965 "Source of routing updates\n"
6966 BGP_UPDATE_SOURCE_HELP_STR)
6967 {
6968 int idx_peer = 2;
6969 char base_xpath[XPATH_MAXLEN];
6970
6971 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6972 sizeof(base_xpath), NULL)
6973 < 0)
6974 return CMD_WARNING_CONFIG_FAILED;
6975
6976 nb_cli_enqueue_change(vty, "./update-source/ip", NB_OP_DESTROY, NULL);
6977 nb_cli_enqueue_change(vty, "./update-source/interface", NB_OP_DESTROY,
6978 NULL);
6979
6980 return nb_cli_apply_changes(vty, base_xpath);
6981 }
6982
6983 static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
6984 afi_t afi, safi_t safi,
6985 const char *rmap, int set)
6986 {
6987 int ret;
6988 struct peer *peer;
6989 struct route_map *route_map = NULL;
6990
6991 peer = peer_and_group_lookup_vty(vty, peer_str);
6992 if (!peer)
6993 return CMD_WARNING_CONFIG_FAILED;
6994
6995 if (set) {
6996 if (rmap)
6997 route_map = route_map_lookup_warn_noexist(vty, rmap);
6998 ret = peer_default_originate_set(peer, afi, safi,
6999 rmap, route_map);
7000 } else
7001 ret = peer_default_originate_unset(peer, afi, safi);
7002
7003 return bgp_vty_return(vty, ret);
7004 }
7005
7006 /* neighbor default-originate. */
7007 DEFUN (neighbor_default_originate,
7008 neighbor_default_originate_cmd,
7009 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
7010 NEIGHBOR_STR
7011 NEIGHBOR_ADDR_STR2
7012 "Originate default route to this neighbor\n")
7013 {
7014 int idx_peer = 1;
7015 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
7016 bgp_node_afi(vty),
7017 bgp_node_safi(vty), NULL, 1);
7018 }
7019
7020 ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
7021 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
7022 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7023 "Originate default route to this neighbor\n")
7024
7025 DEFUN (neighbor_default_originate_rmap,
7026 neighbor_default_originate_rmap_cmd,
7027 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
7028 NEIGHBOR_STR
7029 NEIGHBOR_ADDR_STR2
7030 "Originate default route to this neighbor\n"
7031 "Route-map to specify criteria to originate default\n"
7032 "route-map name\n")
7033 {
7034 int idx_peer = 1;
7035 int idx_word = 4;
7036 return peer_default_originate_set_vty(
7037 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7038 argv[idx_word]->arg, 1);
7039 }
7040
7041 ALIAS_HIDDEN(
7042 neighbor_default_originate_rmap,
7043 neighbor_default_originate_rmap_hidden_cmd,
7044 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
7045 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7046 "Originate default route to this neighbor\n"
7047 "Route-map to specify criteria to originate default\n"
7048 "route-map name\n")
7049
7050 DEFUN (no_neighbor_default_originate,
7051 no_neighbor_default_originate_cmd,
7052 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
7053 NO_STR
7054 NEIGHBOR_STR
7055 NEIGHBOR_ADDR_STR2
7056 "Originate default route to this neighbor\n"
7057 "Route-map to specify criteria to originate default\n"
7058 "route-map name\n")
7059 {
7060 int idx_peer = 2;
7061 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
7062 bgp_node_afi(vty),
7063 bgp_node_safi(vty), NULL, 0);
7064 }
7065
7066 ALIAS_HIDDEN(
7067 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
7068 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
7069 NO_STR NEIGHBOR_STR 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
7075 /* Set specified peer's BGP port. */
7076 DEFUN_YANG (neighbor_port,
7077 neighbor_port_cmd,
7078 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
7079 NEIGHBOR_STR
7080 NEIGHBOR_ADDR_STR
7081 "Neighbor's BGP port\n"
7082 "TCP port number\n")
7083 {
7084 int idx_ip = 1;
7085 int idx_number = 3;
7086 char base_xpath[XPATH_MAXLEN];
7087
7088 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_NUM_XPATH,
7089 argv[idx_ip]->arg, "");
7090
7091 nb_cli_enqueue_change(vty, "./local-port", NB_OP_MODIFY,
7092 argv[idx_number]->arg);
7093
7094 return nb_cli_apply_changes(vty, base_xpath);
7095 }
7096
7097 DEFUN_YANG (no_neighbor_port,
7098 no_neighbor_port_cmd,
7099 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
7100 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR
7101 "Neighbor's BGP port\n"
7102 "TCP port number\n")
7103 {
7104 int idx_ip = 2;
7105 char base_xpath[XPATH_MAXLEN];
7106
7107 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_NUM_XPATH,
7108 argv[idx_ip]->arg, "");
7109
7110 nb_cli_enqueue_change(vty, "./local-port", NB_OP_DESTROY, NULL);
7111
7112 return nb_cli_apply_changes(vty, base_xpath);
7113 }
7114
7115 DEFUN_YANG (neighbor_weight,
7116 neighbor_weight_cmd,
7117 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7118 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7119 "Set default weight for routes from this neighbor\n"
7120 "default weight\n")
7121 {
7122 int idx_peer = 1;
7123 int idx_number = 3;
7124 char base_xpath[XPATH_MAXLEN];
7125 char af_xpath[XPATH_MAXLEN];
7126 char attr_xpath[XPATH_MAXLEN];
7127 afi_t afi = bgp_node_afi(vty);
7128 safi_t safi = bgp_node_safi(vty);
7129
7130 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
7131 yang_afi_safi_value2identity(afi, safi));
7132
7133 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7134 sizeof(base_xpath), af_xpath)
7135 < 0)
7136 return CMD_WARNING_CONFIG_FAILED;
7137
7138 snprintf(attr_xpath, sizeof(attr_xpath), "./%s/weight/weight-attribute",
7139 bgp_afi_safi_get_container_str(afi, safi));
7140
7141 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY,
7142 argv[idx_number]->arg);
7143
7144 return nb_cli_apply_changes(vty, base_xpath);
7145 }
7146
7147 ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
7148 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7149 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7150 "Set default weight for routes from this neighbor\n"
7151 "default weight\n")
7152
7153 DEFUN_YANG (no_neighbor_weight,
7154 no_neighbor_weight_cmd,
7155 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7156 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7157 "Set default weight for routes from this neighbor\n"
7158 "default weight\n")
7159 {
7160 int idx_peer = 2;
7161 char base_xpath[XPATH_MAXLEN];
7162 char af_xpath[XPATH_MAXLEN];
7163 char attr_xpath[XPATH_MAXLEN];
7164 afi_t afi = bgp_node_afi(vty);
7165 safi_t safi = bgp_node_safi(vty);
7166
7167 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
7168 yang_afi_safi_value2identity(afi, safi));
7169
7170 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7171 sizeof(base_xpath), af_xpath)
7172 < 0)
7173 return CMD_WARNING_CONFIG_FAILED;
7174
7175 snprintf(attr_xpath, sizeof(attr_xpath), "./%s/weight/weight-attribute",
7176 bgp_afi_safi_get_container_str(afi, safi));
7177
7178 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_DESTROY, NULL);
7179
7180 return nb_cli_apply_changes(vty, base_xpath);
7181 }
7182
7183 ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
7184 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7185 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7186 "Set default weight for routes from this neighbor\n"
7187 "default weight\n")
7188
7189
7190 /* Override capability negotiation. */
7191 DEFUN_YANG (neighbor_override_capability,
7192 neighbor_override_capability_cmd,
7193 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7194 NEIGHBOR_STR
7195 NEIGHBOR_ADDR_STR2
7196 "Override capability negotiation result\n")
7197 {
7198 int idx_peer = 1;
7199 char base_xpath[XPATH_MAXLEN];
7200
7201 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7202 sizeof(base_xpath), NULL)
7203 < 0)
7204 return CMD_WARNING_CONFIG_FAILED;
7205
7206 nb_cli_enqueue_change(
7207 vty, "./capability-options/override-capability",
7208 NB_OP_MODIFY, "true");
7209
7210 return nb_cli_apply_changes(vty, base_xpath);
7211 }
7212
7213 DEFUN_YANG (no_neighbor_override_capability,
7214 no_neighbor_override_capability_cmd,
7215 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7216 NO_STR
7217 NEIGHBOR_STR
7218 NEIGHBOR_ADDR_STR2
7219 "Override capability negotiation result\n")
7220 {
7221 int idx_peer = 2;
7222 char base_xpath[XPATH_MAXLEN];
7223
7224 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7225 sizeof(base_xpath), NULL)
7226 < 0)
7227 return CMD_WARNING_CONFIG_FAILED;
7228
7229 nb_cli_enqueue_change(
7230 vty, "./capability-options/override-capability",
7231 NB_OP_MODIFY, "false");
7232
7233 return nb_cli_apply_changes(vty, base_xpath);
7234 }
7235
7236 DEFUN_YANG (neighbor_strict_capability,
7237 neighbor_strict_capability_cmd,
7238 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7239 NEIGHBOR_STR
7240 NEIGHBOR_ADDR_STR2
7241 "Strict capability negotiation match\n")
7242 {
7243 int idx_peer = 1;
7244 char base_xpath[XPATH_MAXLEN];
7245
7246 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7247 sizeof(base_xpath), NULL)
7248 < 0)
7249 return CMD_WARNING_CONFIG_FAILED;
7250
7251 nb_cli_enqueue_change(
7252 vty, "./capability-options/strict-capability",
7253 NB_OP_MODIFY, "true");
7254
7255 return nb_cli_apply_changes(vty, base_xpath);
7256 }
7257
7258 DEFUN_YANG (no_neighbor_strict_capability,
7259 no_neighbor_strict_capability_cmd,
7260 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7261 NO_STR
7262 NEIGHBOR_STR
7263 NEIGHBOR_ADDR_STR2
7264 "Strict capability negotiation match\n")
7265 {
7266 int idx_peer = 2;
7267 char base_xpath[XPATH_MAXLEN];
7268
7269 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7270 sizeof(base_xpath), NULL)
7271 < 0)
7272 return CMD_WARNING_CONFIG_FAILED;
7273
7274 nb_cli_enqueue_change(
7275 vty, "./capability-options/strict-capability",
7276 NB_OP_MODIFY, "false");
7277
7278 return nb_cli_apply_changes(vty, base_xpath);
7279 }
7280
7281 DEFUN_YANG (neighbor_timers,
7282 neighbor_timers_cmd,
7283 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
7284 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7285 "BGP per neighbor timers\n"
7286 "Keepalive interval\n"
7287 "Holdtime\n")
7288 {
7289 int idx_peer = 1;
7290 int idx_number = 3;
7291 int idx_number_2 = 4;
7292 char base_xpath[XPATH_MAXLEN];
7293
7294 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7295 sizeof(base_xpath), NULL)
7296 < 0)
7297 return CMD_WARNING_CONFIG_FAILED;
7298
7299 nb_cli_enqueue_change(vty, "./timers/keepalive", NB_OP_MODIFY,
7300 argv[idx_number]->arg);
7301
7302 nb_cli_enqueue_change(vty, "./timers/hold-time", NB_OP_MODIFY,
7303 argv[idx_number_2]->arg);
7304
7305 return nb_cli_apply_changes(vty, base_xpath);
7306 }
7307
7308 DEFUN_YANG (no_neighbor_timers,
7309 no_neighbor_timers_cmd,
7310 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
7311 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7312 "BGP per neighbor timers\n"
7313 "Keepalive interval\n"
7314 "Holdtime\n")
7315 {
7316 int idx_peer = 2;
7317 char base_xpath[XPATH_MAXLEN];
7318
7319 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7320 sizeof(base_xpath), NULL)
7321 < 0)
7322 return CMD_WARNING_CONFIG_FAILED;
7323
7324 nb_cli_enqueue_change(vty, "./timers/hold-time", NB_OP_DESTROY, NULL);
7325
7326 nb_cli_enqueue_change(vty, "./timers/keepalive", NB_OP_DESTROY, NULL);
7327
7328 return nb_cli_apply_changes(vty, base_xpath);
7329 }
7330
7331 DEFUN_YANG (neighbor_timers_connect,
7332 neighbor_timers_connect_cmd,
7333 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
7334 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7335 "BGP per neighbor timers\n"
7336 "BGP connect timer\n"
7337 "Connect timer\n")
7338 {
7339 int idx_peer = 1;
7340 int idx_number = 4;
7341 char base_xpath[XPATH_MAXLEN];
7342
7343 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7344 sizeof(base_xpath), NULL)
7345 < 0)
7346 return CMD_WARNING_CONFIG_FAILED;
7347
7348 nb_cli_enqueue_change(vty, "./timers/connect-time", NB_OP_MODIFY,
7349 argv[idx_number]->arg);
7350
7351 return nb_cli_apply_changes(vty, base_xpath);
7352 }
7353
7354 DEFUN_YANG (no_neighbor_timers_connect,
7355 no_neighbor_timers_connect_cmd,
7356 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
7357 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7358 "BGP per neighbor timers\n"
7359 "BGP connect timer\n"
7360 "Connect timer\n")
7361 {
7362 int idx_peer = 2;
7363 char base_xpath[XPATH_MAXLEN];
7364
7365 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7366 sizeof(base_xpath), NULL)
7367 < 0)
7368 return CMD_WARNING_CONFIG_FAILED;
7369
7370 nb_cli_enqueue_change(vty, "./timers/connect-time", NB_OP_DESTROY,
7371 NULL);
7372
7373 return nb_cli_apply_changes(vty, base_xpath);
7374 }
7375
7376 DEFUN_YANG (neighbor_advertise_interval,
7377 neighbor_advertise_interval_cmd,
7378 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
7379 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7380 "Minimum interval between sending BGP routing updates\n"
7381 "time in seconds\n")
7382 {
7383 int idx_peer = 1;
7384 int idx_number = 3;
7385 char base_xpath[XPATH_MAXLEN];
7386
7387 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7388 sizeof(base_xpath), NULL)
7389 < 0)
7390 return CMD_WARNING_CONFIG_FAILED;
7391
7392 nb_cli_enqueue_change(vty, "./timers/advertise-interval", NB_OP_MODIFY,
7393 argv[idx_number]->arg);
7394
7395 return nb_cli_apply_changes(vty, base_xpath);
7396 }
7397
7398 DEFUN_YANG (no_neighbor_advertise_interval,
7399 no_neighbor_advertise_interval_cmd,
7400 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
7401 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7402 "Minimum interval between sending BGP routing updates\n"
7403 "time in seconds\n")
7404 {
7405 int idx_peer = 2;
7406 char base_xpath[XPATH_MAXLEN];
7407
7408 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7409 sizeof(base_xpath), NULL)
7410 < 0)
7411 return CMD_WARNING_CONFIG_FAILED;
7412
7413 nb_cli_enqueue_change(vty, "./timers/advertise-interval", NB_OP_DESTROY,
7414 NULL);
7415
7416 return nb_cli_apply_changes(vty, base_xpath);
7417 }
7418
7419
7420 /* Time to wait before processing route-map updates */
7421 DEFUN (bgp_set_route_map_delay_timer,
7422 bgp_set_route_map_delay_timer_cmd,
7423 "bgp route-map delay-timer (0-600)",
7424 SET_STR
7425 "BGP route-map delay timer\n"
7426 "Time in secs to wait before processing route-map changes\n"
7427 "0 disables the timer, no route updates happen when route-maps change\n")
7428 {
7429 int idx_number = 3;
7430 uint32_t rmap_delay_timer;
7431
7432 if (argv[idx_number]->arg) {
7433 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
7434 bm->rmap_update_timer = rmap_delay_timer;
7435
7436 /* if the dynamic update handling is being disabled, and a timer
7437 * is
7438 * running, stop the timer and act as if the timer has already
7439 * fired.
7440 */
7441 if (!rmap_delay_timer && bm->t_rmap_update) {
7442 BGP_TIMER_OFF(bm->t_rmap_update);
7443 thread_execute(bm->master, bgp_route_map_update_timer,
7444 NULL, 0);
7445 }
7446 return CMD_SUCCESS;
7447 } else {
7448 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
7449 return CMD_WARNING_CONFIG_FAILED;
7450 }
7451 }
7452
7453 DEFUN (no_bgp_set_route_map_delay_timer,
7454 no_bgp_set_route_map_delay_timer_cmd,
7455 "no bgp route-map delay-timer [(0-600)]",
7456 NO_STR
7457 BGP_STR
7458 "Default BGP route-map delay timer\n"
7459 "Reset to default time to wait for processing route-map changes\n"
7460 "0 disables the timer, no route updates happen when route-maps change\n")
7461 {
7462
7463 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
7464
7465 return CMD_SUCCESS;
7466 }
7467
7468 DEFUN_YANG (neighbor_interface,
7469 neighbor_interface_cmd,
7470 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
7471 NEIGHBOR_STR NEIGHBOR_ADDR_STR
7472 "Interface\n"
7473 "Interface name\n")
7474 {
7475 int idx_ip = 1;
7476 int idx_word = 3;
7477 char base_xpath[XPATH_MAXLEN];
7478
7479 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_NUM_XPATH,
7480 argv[idx_ip]->arg, "");
7481
7482 nb_cli_enqueue_change(vty, "./local-interface", NB_OP_MODIFY,
7483 argv[idx_word]->arg);
7484
7485 return nb_cli_apply_changes(vty, base_xpath);
7486 }
7487
7488 DEFUN_YANG (no_neighbor_interface,
7489 no_neighbor_interface_cmd,
7490 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
7491 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7492 "Interface\n"
7493 "Interface name\n")
7494 {
7495 int idx_peer = 2;
7496 char base_xpath[XPATH_MAXLEN];
7497
7498 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_NUM_XPATH,
7499 argv[idx_peer]->arg, "");
7500
7501 nb_cli_enqueue_change(vty, "./local-interface", NB_OP_DESTROY, NULL);
7502
7503 return nb_cli_apply_changes(vty, base_xpath);
7504 }
7505
7506 DEFUN (neighbor_distribute_list,
7507 neighbor_distribute_list_cmd,
7508 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
7509 NEIGHBOR_STR
7510 NEIGHBOR_ADDR_STR2
7511 "Filter updates to/from this neighbor\n"
7512 "IP access-list number\n"
7513 "IP access-list number (expanded range)\n"
7514 "IP Access-list name\n"
7515 "Filter incoming updates\n"
7516 "Filter outgoing updates\n")
7517 {
7518 int idx_peer = 1;
7519 int idx_acl = 3;
7520 int direct, ret;
7521 struct peer *peer;
7522
7523 const char *pstr = argv[idx_peer]->arg;
7524 const char *acl = argv[idx_acl]->arg;
7525 const char *inout = argv[argc - 1]->text;
7526
7527 peer = peer_and_group_lookup_vty(vty, pstr);
7528 if (!peer)
7529 return CMD_WARNING_CONFIG_FAILED;
7530
7531 /* Check filter direction. */
7532 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7533 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7534 direct, acl);
7535
7536 return bgp_vty_return(vty, ret);
7537 }
7538
7539 ALIAS_HIDDEN(
7540 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
7541 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
7542 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7543 "Filter updates to/from this neighbor\n"
7544 "IP access-list number\n"
7545 "IP access-list number (expanded range)\n"
7546 "IP Access-list name\n"
7547 "Filter incoming updates\n"
7548 "Filter outgoing updates\n")
7549
7550 DEFUN (no_neighbor_distribute_list,
7551 no_neighbor_distribute_list_cmd,
7552 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
7553 NO_STR
7554 NEIGHBOR_STR
7555 NEIGHBOR_ADDR_STR2
7556 "Filter updates to/from this neighbor\n"
7557 "IP access-list number\n"
7558 "IP access-list number (expanded range)\n"
7559 "IP Access-list name\n"
7560 "Filter incoming updates\n"
7561 "Filter outgoing updates\n")
7562 {
7563 int idx_peer = 2;
7564 int direct, ret;
7565 struct peer *peer;
7566
7567 const char *pstr = argv[idx_peer]->arg;
7568 const char *inout = argv[argc - 1]->text;
7569
7570 peer = peer_and_group_lookup_vty(vty, pstr);
7571 if (!peer)
7572 return CMD_WARNING_CONFIG_FAILED;
7573
7574 /* Check filter direction. */
7575 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7576 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7577 direct);
7578
7579 return bgp_vty_return(vty, ret);
7580 }
7581
7582 ALIAS_HIDDEN(
7583 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
7584 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
7585 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7586 "Filter updates to/from this neighbor\n"
7587 "IP access-list number\n"
7588 "IP access-list number (expanded range)\n"
7589 "IP Access-list name\n"
7590 "Filter incoming updates\n"
7591 "Filter outgoing updates\n")
7592
7593 /* Set prefix list to the peer. */
7594 static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
7595 afi_t afi, safi_t safi,
7596 const char *name_str,
7597 const char *direct_str)
7598 {
7599 int ret;
7600 int direct = FILTER_IN;
7601 struct peer *peer;
7602
7603 peer = peer_and_group_lookup_vty(vty, ip_str);
7604 if (!peer)
7605 return CMD_WARNING_CONFIG_FAILED;
7606
7607 /* Check filter direction. */
7608 if (strncmp(direct_str, "i", 1) == 0)
7609 direct = FILTER_IN;
7610 else if (strncmp(direct_str, "o", 1) == 0)
7611 direct = FILTER_OUT;
7612
7613 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
7614
7615 return bgp_vty_return(vty, ret);
7616 }
7617
7618 static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
7619 afi_t afi, safi_t safi,
7620 const char *direct_str)
7621 {
7622 int ret;
7623 struct peer *peer;
7624 int direct = FILTER_IN;
7625
7626 peer = peer_and_group_lookup_vty(vty, ip_str);
7627 if (!peer)
7628 return CMD_WARNING_CONFIG_FAILED;
7629
7630 /* Check filter direction. */
7631 if (strncmp(direct_str, "i", 1) == 0)
7632 direct = FILTER_IN;
7633 else if (strncmp(direct_str, "o", 1) == 0)
7634 direct = FILTER_OUT;
7635
7636 ret = peer_prefix_list_unset(peer, afi, safi, direct);
7637
7638 return bgp_vty_return(vty, ret);
7639 }
7640
7641 DEFUN (neighbor_prefix_list,
7642 neighbor_prefix_list_cmd,
7643 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7644 NEIGHBOR_STR
7645 NEIGHBOR_ADDR_STR2
7646 "Filter updates to/from this neighbor\n"
7647 "Name of a prefix list\n"
7648 "Filter incoming updates\n"
7649 "Filter outgoing updates\n")
7650 {
7651 int idx_peer = 1;
7652 int idx_word = 3;
7653 int idx_in_out = 4;
7654 return peer_prefix_list_set_vty(
7655 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7656 argv[idx_word]->arg, argv[idx_in_out]->arg);
7657 }
7658
7659 ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
7660 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7661 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7662 "Filter updates to/from this neighbor\n"
7663 "Name of a prefix list\n"
7664 "Filter incoming updates\n"
7665 "Filter outgoing updates\n")
7666
7667 DEFUN (no_neighbor_prefix_list,
7668 no_neighbor_prefix_list_cmd,
7669 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7670 NO_STR
7671 NEIGHBOR_STR
7672 NEIGHBOR_ADDR_STR2
7673 "Filter updates to/from this neighbor\n"
7674 "Name of a prefix list\n"
7675 "Filter incoming updates\n"
7676 "Filter outgoing updates\n")
7677 {
7678 int idx_peer = 2;
7679 int idx_in_out = 5;
7680 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
7681 bgp_node_afi(vty), bgp_node_safi(vty),
7682 argv[idx_in_out]->arg);
7683 }
7684
7685 ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
7686 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7687 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7688 "Filter updates to/from this neighbor\n"
7689 "Name of a prefix list\n"
7690 "Filter incoming updates\n"
7691 "Filter outgoing updates\n")
7692
7693 static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7694 safi_t safi, const char *name_str,
7695 const char *direct_str)
7696 {
7697 int ret;
7698 struct peer *peer;
7699 int direct = FILTER_IN;
7700
7701 peer = peer_and_group_lookup_vty(vty, ip_str);
7702 if (!peer)
7703 return CMD_WARNING_CONFIG_FAILED;
7704
7705 /* Check filter direction. */
7706 if (strncmp(direct_str, "i", 1) == 0)
7707 direct = FILTER_IN;
7708 else if (strncmp(direct_str, "o", 1) == 0)
7709 direct = FILTER_OUT;
7710
7711 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
7712
7713 return bgp_vty_return(vty, ret);
7714 }
7715
7716 static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7717 safi_t safi, const char *direct_str)
7718 {
7719 int ret;
7720 struct peer *peer;
7721 int direct = FILTER_IN;
7722
7723 peer = peer_and_group_lookup_vty(vty, ip_str);
7724 if (!peer)
7725 return CMD_WARNING_CONFIG_FAILED;
7726
7727 /* Check filter direction. */
7728 if (strncmp(direct_str, "i", 1) == 0)
7729 direct = FILTER_IN;
7730 else if (strncmp(direct_str, "o", 1) == 0)
7731 direct = FILTER_OUT;
7732
7733 ret = peer_aslist_unset(peer, afi, safi, direct);
7734
7735 return bgp_vty_return(vty, ret);
7736 }
7737
7738 DEFUN (neighbor_filter_list,
7739 neighbor_filter_list_cmd,
7740 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
7741 NEIGHBOR_STR
7742 NEIGHBOR_ADDR_STR2
7743 "Establish BGP filters\n"
7744 "AS path access-list name\n"
7745 "Filter incoming routes\n"
7746 "Filter outgoing routes\n")
7747 {
7748 int idx_peer = 1;
7749 int idx_word = 3;
7750 int idx_in_out = 4;
7751 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7752 bgp_node_safi(vty), argv[idx_word]->arg,
7753 argv[idx_in_out]->arg);
7754 }
7755
7756 ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
7757 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
7758 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7759 "Establish BGP filters\n"
7760 "AS path access-list name\n"
7761 "Filter incoming routes\n"
7762 "Filter outgoing routes\n")
7763
7764 DEFUN (no_neighbor_filter_list,
7765 no_neighbor_filter_list_cmd,
7766 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
7767 NO_STR
7768 NEIGHBOR_STR
7769 NEIGHBOR_ADDR_STR2
7770 "Establish BGP filters\n"
7771 "AS path access-list name\n"
7772 "Filter incoming routes\n"
7773 "Filter outgoing routes\n")
7774 {
7775 int idx_peer = 2;
7776 int idx_in_out = 5;
7777 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
7778 bgp_node_afi(vty), bgp_node_safi(vty),
7779 argv[idx_in_out]->arg);
7780 }
7781
7782 ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
7783 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
7784 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7785 "Establish BGP filters\n"
7786 "AS path access-list name\n"
7787 "Filter incoming routes\n"
7788 "Filter outgoing routes\n")
7789
7790 /* Set advertise-map to the peer. */
7791 static int peer_advertise_map_set_vty(struct vty *vty, const char *ip_str,
7792 afi_t afi, safi_t safi,
7793 const char *advertise_str,
7794 const char *condition_str, bool condition,
7795 bool set)
7796 {
7797 int ret = CMD_WARNING_CONFIG_FAILED;
7798 struct peer *peer;
7799 struct route_map *advertise_map;
7800 struct route_map *condition_map;
7801
7802 peer = peer_and_group_lookup_vty(vty, ip_str);
7803 if (!peer)
7804 return ret;
7805
7806 condition_map = route_map_lookup_warn_noexist(vty, condition_str);
7807 advertise_map = route_map_lookup_warn_noexist(vty, advertise_str);
7808
7809 if (set)
7810 ret = peer_advertise_map_set(peer, afi, safi, advertise_str,
7811 advertise_map, condition_str,
7812 condition_map, condition);
7813 else
7814 ret = peer_advertise_map_unset(peer, afi, safi, advertise_str,
7815 advertise_map, condition_str,
7816 condition_map, condition);
7817
7818 return bgp_vty_return(vty, ret);
7819 }
7820
7821 DEFPY (neighbor_advertise_map,
7822 neighbor_advertise_map_cmd,
7823 "[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",
7824 NO_STR
7825 NEIGHBOR_STR
7826 NEIGHBOR_ADDR_STR2
7827 "Route-map to conditionally advertise routes\n"
7828 "Name of advertise map\n"
7829 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7830 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
7831 "Name of the exist or non exist map\n")
7832 {
7833 bool condition = CONDITION_EXIST;
7834
7835 if (!strcmp(exist, "non-exist-map"))
7836 condition = CONDITION_NON_EXIST;
7837
7838 return peer_advertise_map_set_vty(vty, neighbor, bgp_node_afi(vty),
7839 bgp_node_safi(vty), advertise_str,
7840 condition_str, condition, !no);
7841 }
7842
7843 ALIAS_HIDDEN(neighbor_advertise_map, neighbor_advertise_map_hidden_cmd,
7844 "[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",
7845 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7846 "Route-map to conditionally advertise routes\n"
7847 "Name of advertise map\n"
7848 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7849 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
7850 "Name of the exist or non exist map\n")
7851
7852 /* Set route-map to the peer. */
7853 static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
7854 afi_t afi, safi_t safi, const char *name_str,
7855 const char *direct_str)
7856 {
7857 int ret;
7858 struct peer *peer;
7859 int direct = RMAP_IN;
7860 struct route_map *route_map;
7861
7862 peer = peer_and_group_lookup_vty(vty, ip_str);
7863 if (!peer)
7864 return CMD_WARNING_CONFIG_FAILED;
7865
7866 /* Check filter direction. */
7867 if (strncmp(direct_str, "in", 2) == 0)
7868 direct = RMAP_IN;
7869 else if (strncmp(direct_str, "o", 1) == 0)
7870 direct = RMAP_OUT;
7871
7872 route_map = route_map_lookup_warn_noexist(vty, name_str);
7873 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
7874
7875 return bgp_vty_return(vty, ret);
7876 }
7877
7878 static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
7879 afi_t afi, safi_t safi,
7880 const char *direct_str)
7881 {
7882 int ret;
7883 struct peer *peer;
7884 int direct = RMAP_IN;
7885
7886 peer = peer_and_group_lookup_vty(vty, ip_str);
7887 if (!peer)
7888 return CMD_WARNING_CONFIG_FAILED;
7889
7890 /* Check filter direction. */
7891 if (strncmp(direct_str, "in", 2) == 0)
7892 direct = RMAP_IN;
7893 else if (strncmp(direct_str, "o", 1) == 0)
7894 direct = RMAP_OUT;
7895
7896 ret = peer_route_map_unset(peer, afi, safi, direct);
7897
7898 return bgp_vty_return(vty, ret);
7899 }
7900
7901 DEFUN (neighbor_route_map,
7902 neighbor_route_map_cmd,
7903 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
7904 NEIGHBOR_STR
7905 NEIGHBOR_ADDR_STR2
7906 "Apply route map to neighbor\n"
7907 "Name of route map\n"
7908 "Apply map to incoming routes\n"
7909 "Apply map to outbound routes\n")
7910 {
7911 int idx_peer = 1;
7912 int idx_word = 3;
7913 int idx_in_out = 4;
7914 return peer_route_map_set_vty(
7915 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7916 argv[idx_word]->arg, argv[idx_in_out]->arg);
7917 }
7918
7919 ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
7920 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
7921 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7922 "Apply route map to neighbor\n"
7923 "Name of route map\n"
7924 "Apply map to incoming routes\n"
7925 "Apply map to outbound routes\n")
7926
7927 DEFUN (no_neighbor_route_map,
7928 no_neighbor_route_map_cmd,
7929 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
7930 NO_STR
7931 NEIGHBOR_STR
7932 NEIGHBOR_ADDR_STR2
7933 "Apply route map to neighbor\n"
7934 "Name of route map\n"
7935 "Apply map to incoming routes\n"
7936 "Apply map to outbound routes\n")
7937 {
7938 int idx_peer = 2;
7939 int idx_in_out = 5;
7940 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
7941 bgp_node_afi(vty), bgp_node_safi(vty),
7942 argv[idx_in_out]->arg);
7943 }
7944
7945 ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
7946 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
7947 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7948 "Apply route map to neighbor\n"
7949 "Name of route map\n"
7950 "Apply map to incoming routes\n"
7951 "Apply map to outbound routes\n")
7952
7953 /* Set unsuppress-map to the peer. */
7954 static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
7955 afi_t afi, safi_t safi,
7956 const char *name_str)
7957 {
7958 int ret;
7959 struct peer *peer;
7960 struct route_map *route_map;
7961
7962 peer = peer_and_group_lookup_vty(vty, ip_str);
7963 if (!peer)
7964 return CMD_WARNING_CONFIG_FAILED;
7965
7966 route_map = route_map_lookup_warn_noexist(vty, name_str);
7967 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
7968
7969 return bgp_vty_return(vty, ret);
7970 }
7971
7972 /* Unset route-map from the peer. */
7973 static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
7974 afi_t afi, safi_t safi)
7975 {
7976 int ret;
7977 struct peer *peer;
7978
7979 peer = peer_and_group_lookup_vty(vty, ip_str);
7980 if (!peer)
7981 return CMD_WARNING_CONFIG_FAILED;
7982
7983 ret = peer_unsuppress_map_unset(peer, afi, safi);
7984
7985 return bgp_vty_return(vty, ret);
7986 }
7987
7988 DEFUN (neighbor_unsuppress_map,
7989 neighbor_unsuppress_map_cmd,
7990 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7991 NEIGHBOR_STR
7992 NEIGHBOR_ADDR_STR2
7993 "Route-map to selectively unsuppress suppressed routes\n"
7994 "Name of route map\n")
7995 {
7996 int idx_peer = 1;
7997 int idx_word = 3;
7998 return peer_unsuppress_map_set_vty(
7999 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8000 argv[idx_word]->arg);
8001 }
8002
8003 ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
8004 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8005 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8006 "Route-map to selectively unsuppress suppressed routes\n"
8007 "Name of route map\n")
8008
8009 DEFUN (no_neighbor_unsuppress_map,
8010 no_neighbor_unsuppress_map_cmd,
8011 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8012 NO_STR
8013 NEIGHBOR_STR
8014 NEIGHBOR_ADDR_STR2
8015 "Route-map to selectively unsuppress suppressed routes\n"
8016 "Name of route map\n")
8017 {
8018 int idx_peer = 2;
8019 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
8020 bgp_node_afi(vty),
8021 bgp_node_safi(vty));
8022 }
8023
8024 ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
8025 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8026 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8027 "Route-map to selectively unsuppress suppressed routes\n"
8028 "Name of route map\n")
8029
8030 /* Maximum number of prefix to be sent to the neighbor. */
8031 DEFUN_YANG(neighbor_maximum_prefix_out,
8032 neighbor_maximum_prefix_out_cmd,
8033 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out (1-4294967295)",
8034 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8035 "Maximum number of prefixes to be sent to this peer\n"
8036 "Maximum no. of prefix limit\n")
8037 {
8038 char base_xpath[XPATH_MAXLEN];
8039 char af_xpath[XPATH_MAXLEN];
8040 char attr_xpath[XPATH_MAXLEN];
8041 int idx_peer = 1;
8042 int idx_number = 3;
8043 afi_t afi = bgp_node_afi(vty);
8044 safi_t safi = bgp_node_safi(vty);
8045
8046 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8047 yang_afi_safi_value2identity(afi, safi));
8048 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8049 sizeof(base_xpath), af_xpath)
8050 < 0)
8051 return CMD_WARNING_CONFIG_FAILED;
8052
8053 snprintf(attr_xpath, sizeof(attr_xpath),
8054 "/%s/prefix-limit/direction-list[direction='out']",
8055 bgp_afi_safi_get_container_str(afi, safi));
8056 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8057
8058 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8059
8060 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8061 argv[idx_number]->arg);
8062
8063 return nb_cli_apply_changes(vty, base_xpath);
8064 }
8065
8066 DEFUN_YANG(no_neighbor_maximum_prefix_out,
8067 no_neighbor_maximum_prefix_out_cmd,
8068 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out",
8069 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8070 "Maximum number of prefixes to be sent to this peer\n")
8071 {
8072 char base_xpath[XPATH_MAXLEN];
8073 char af_xpath[XPATH_MAXLEN];
8074 char attr_xpath[XPATH_MAXLEN];
8075 int idx_peer = 2;
8076 afi_t afi = bgp_node_afi(vty);
8077 safi_t safi = bgp_node_safi(vty);
8078
8079 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8080 yang_afi_safi_value2identity(afi, safi));
8081 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8082 sizeof(base_xpath), af_xpath)
8083 < 0)
8084 return CMD_WARNING_CONFIG_FAILED;
8085
8086 snprintf(attr_xpath, sizeof(attr_xpath),
8087 "/%s/prefix-limit/direction-list[direction='out']",
8088 bgp_afi_safi_get_container_str(afi, safi));
8089 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8090
8091 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
8092
8093 return nb_cli_apply_changes(vty, base_xpath);
8094 }
8095
8096 /* Maximum number of prefix configuration. Prefix count is different
8097 for each peer configuration. So this configuration can be set for
8098 each peer configuration. */
8099 DEFUN_YANG(neighbor_maximum_prefix,
8100 neighbor_maximum_prefix_cmd,
8101 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
8102 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8103 "Maximum number of prefix accept from this peer\n"
8104 "maximum no. of prefix limit\n"
8105 "Force checking all received routes not only accepted\n")
8106 {
8107 int idx_peer = 1;
8108 int idx_number = 3;
8109 int idx_force = 0;
8110 char base_xpath[XPATH_MAXLEN];
8111 char af_xpath[XPATH_MAXLEN];
8112 char attr_xpath[XPATH_MAXLEN];
8113 afi_t afi = bgp_node_afi(vty);
8114 safi_t safi = bgp_node_safi(vty);
8115
8116 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8117 yang_afi_safi_value2identity(afi, safi));
8118 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8119 sizeof(base_xpath), af_xpath)
8120 < 0)
8121 return CMD_WARNING_CONFIG_FAILED;
8122
8123 snprintf(attr_xpath, sizeof(attr_xpath),
8124 "/%s/prefix-limit/direction-list[direction='in']",
8125 bgp_afi_safi_get_container_str(afi, safi));
8126 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8127
8128 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8129
8130 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8131 argv[idx_number]->arg);
8132 if (argv_find(argv, argc, "force", &idx_force))
8133 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8134 "true");
8135
8136 return nb_cli_apply_changes(vty, base_xpath);
8137 }
8138
8139 ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
8140 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
8141 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8142 "Maximum number of prefix accept from this peer\n"
8143 "maximum no. of prefix limit\n"
8144 "Force checking all received routes not only accepted\n")
8145
8146 DEFUN_YANG(neighbor_maximum_prefix_threshold,
8147 neighbor_maximum_prefix_threshold_cmd,
8148 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
8149 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8150 "Maximum number of prefix accept from this peer\n"
8151 "maximum no. of prefix limit\n"
8152 "Threshold value (%) at which to generate a warning msg\n"
8153 "Force checking all received routes not only accepted\n")
8154 {
8155 int idx_peer = 1;
8156 int idx_number = 3;
8157 int idx_number_2 = 4;
8158 int idx_force = 0;
8159 char base_xpath[XPATH_MAXLEN];
8160 char af_xpath[XPATH_MAXLEN];
8161 char attr_xpath[XPATH_MAXLEN];
8162 afi_t afi = bgp_node_afi(vty);
8163 safi_t safi = bgp_node_safi(vty);
8164
8165 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8166 yang_afi_safi_value2identity(afi, safi));
8167 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8168 sizeof(base_xpath), af_xpath)
8169 < 0)
8170 return CMD_WARNING_CONFIG_FAILED;
8171
8172 snprintf(attr_xpath, sizeof(attr_xpath),
8173 "/%s/prefix-limit/direction-list[direction='in']",
8174 bgp_afi_safi_get_container_str(afi, safi));
8175 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8176
8177 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8178
8179 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8180 argv[idx_number]->arg);
8181
8182 nb_cli_enqueue_change(vty, "./options/shutdown-threshold-pct",
8183 NB_OP_MODIFY, argv[idx_number_2]->arg);
8184
8185 if (argv_find(argv, argc, "force", &idx_force))
8186 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8187 "true");
8188
8189 return nb_cli_apply_changes(vty, base_xpath);
8190 }
8191
8192 ALIAS_HIDDEN(
8193 neighbor_maximum_prefix_threshold,
8194 neighbor_maximum_prefix_threshold_hidden_cmd,
8195 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
8196 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8197 "Maximum number of prefix accept from this peer\n"
8198 "maximum no. of prefix limit\n"
8199 "Threshold value (%) at which to generate a warning msg\n"
8200 "Force checking all received routes not only accepted\n")
8201
8202 DEFUN_YANG(neighbor_maximum_prefix_warning,
8203 neighbor_maximum_prefix_warning_cmd,
8204 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
8205 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8206 "Maximum number of prefix accept from this peer\n"
8207 "maximum no. of prefix limit\n"
8208 "Only give warning message when limit is exceeded\n"
8209 "Force checking all received routes not only accepted\n")
8210 {
8211 int idx_peer = 1;
8212 int idx_number = 3;
8213 int idx_force = 0;
8214 char base_xpath[XPATH_MAXLEN];
8215 char af_xpath[XPATH_MAXLEN];
8216 char attr_xpath[XPATH_MAXLEN];
8217 afi_t afi = bgp_node_afi(vty);
8218 safi_t safi = bgp_node_safi(vty);
8219
8220 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8221 yang_afi_safi_value2identity(afi, safi));
8222 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8223 sizeof(base_xpath), af_xpath)
8224 < 0)
8225 return CMD_WARNING_CONFIG_FAILED;
8226
8227 snprintf(attr_xpath, sizeof(attr_xpath),
8228 "/%s/prefix-limit/direction-list[direction='in']",
8229 bgp_afi_safi_get_container_str(afi, safi));
8230 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8231
8232 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8233
8234 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8235 argv[idx_number]->arg);
8236
8237 nb_cli_enqueue_change(vty, "./options/warning-only", NB_OP_MODIFY,
8238 "true");
8239 if (argv_find(argv, argc, "force", &idx_force))
8240 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8241 "true");
8242
8243 return nb_cli_apply_changes(vty, base_xpath);
8244 }
8245
8246 ALIAS_HIDDEN(
8247 neighbor_maximum_prefix_warning,
8248 neighbor_maximum_prefix_warning_hidden_cmd,
8249 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
8250 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8251 "Maximum number of prefix accept from this peer\n"
8252 "maximum no. of prefix limit\n"
8253 "Only give warning message when limit is exceeded\n"
8254 "Force checking all received routes not only accepted\n")
8255
8256 DEFUN_YANG(neighbor_maximum_prefix_threshold_warning,
8257 neighbor_maximum_prefix_threshold_warning_cmd,
8258 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
8259 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8260 "Maximum number of prefix accept from this peer\n"
8261 "maximum no. of prefix limit\n"
8262 "Threshold value (%) at which to generate a warning msg\n"
8263 "Only give warning message when limit is exceeded\n"
8264 "Force checking all received routes not only accepted\n")
8265 {
8266 int idx_peer = 1;
8267 int idx_number = 3;
8268 int idx_number_2 = 4;
8269 int idx_force = 0;
8270 char base_xpath[XPATH_MAXLEN];
8271 char af_xpath[XPATH_MAXLEN];
8272 char attr_xpath[XPATH_MAXLEN];
8273 afi_t afi = bgp_node_afi(vty);
8274 safi_t safi = bgp_node_safi(vty);
8275
8276 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8277 yang_afi_safi_value2identity(afi, safi));
8278 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8279 sizeof(base_xpath), af_xpath)
8280 < 0)
8281 return CMD_WARNING_CONFIG_FAILED;
8282
8283 snprintf(attr_xpath, sizeof(attr_xpath),
8284 "/%s/prefix-limit/direction-list[direction='in']",
8285 bgp_afi_safi_get_container_str(afi, safi));
8286 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8287
8288 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8289
8290 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8291 argv[idx_number]->arg);
8292 nb_cli_enqueue_change(vty, "./options/tw-shutdown-threshold-pct",
8293 NB_OP_MODIFY, argv[idx_number_2]->arg);
8294 nb_cli_enqueue_change(vty, "./options/tw-warning-only", NB_OP_MODIFY,
8295 "true");
8296 if (argv_find(argv, argc, "force", &idx_force))
8297 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8298 "true");
8299
8300 return nb_cli_apply_changes(vty, base_xpath);
8301 }
8302
8303 ALIAS_HIDDEN(
8304 neighbor_maximum_prefix_threshold_warning,
8305 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
8306 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
8307 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8308 "Maximum number of prefix accept from this peer\n"
8309 "maximum no. of prefix limit\n"
8310 "Threshold value (%) at which to generate a warning msg\n"
8311 "Only give warning message when limit is exceeded\n"
8312 "Force checking all received routes not only accepted\n")
8313
8314 DEFUN_YANG(neighbor_maximum_prefix_restart,
8315 neighbor_maximum_prefix_restart_cmd,
8316 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8317 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8318 "Maximum number of prefix accept from this peer\n"
8319 "maximum no. of prefix limit\n"
8320 "Restart bgp connection after limit is exceeded\n"
8321 "Restart interval in minutes\n"
8322 "Force checking all received routes not only accepted\n")
8323 {
8324 int idx_peer = 1;
8325 int idx_number = 3;
8326 int idx_number_2 = 5;
8327 int idx_force = 0;
8328 char base_xpath[XPATH_MAXLEN];
8329 char af_xpath[XPATH_MAXLEN];
8330 char attr_xpath[XPATH_MAXLEN];
8331 afi_t afi = bgp_node_afi(vty);
8332 safi_t safi = bgp_node_safi(vty);
8333
8334 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8335 yang_afi_safi_value2identity(afi, safi));
8336 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8337 sizeof(base_xpath), af_xpath)
8338 < 0)
8339 return CMD_WARNING_CONFIG_FAILED;
8340
8341 snprintf(attr_xpath, sizeof(attr_xpath),
8342 "/%s/prefix-limit/direction-list[direction='in']",
8343 bgp_afi_safi_get_container_str(afi, safi));
8344 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8345
8346 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8347
8348 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8349 argv[idx_number]->arg);
8350 nb_cli_enqueue_change(vty, "./options/restart-timer", NB_OP_MODIFY,
8351 argv[idx_number_2]->arg);
8352 if (argv_find(argv, argc, "force", &idx_force))
8353 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8354 "true");
8355
8356 return nb_cli_apply_changes(vty, base_xpath);
8357 }
8358
8359 ALIAS_HIDDEN(
8360 neighbor_maximum_prefix_restart,
8361 neighbor_maximum_prefix_restart_hidden_cmd,
8362 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8363 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8364 "Maximum number of prefix accept from this peer\n"
8365 "maximum no. of prefix limit\n"
8366 "Restart bgp connection after limit is exceeded\n"
8367 "Restart interval in minutes\n"
8368 "Force checking all received routes not only accepted\n")
8369
8370 DEFUN_YANG(neighbor_maximum_prefix_threshold_restart,
8371 neighbor_maximum_prefix_threshold_restart_cmd,
8372 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8373 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8374 "Maximum number of prefixes to accept from this peer\n"
8375 "maximum no. of prefix limit\n"
8376 "Threshold value (%) at which to generate a warning msg\n"
8377 "Restart bgp connection after limit is exceeded\n"
8378 "Restart interval in minutes\n"
8379 "Force checking all received routes not only accepted\n")
8380 {
8381 int idx_peer = 1;
8382 int idx_number = 3;
8383 int idx_number_2 = 4;
8384 int idx_number_3 = 6;
8385 int idx_force = 0;
8386 char base_xpath[XPATH_MAXLEN];
8387 char af_xpath[XPATH_MAXLEN];
8388 char attr_xpath[XPATH_MAXLEN];
8389 afi_t afi = bgp_node_afi(vty);
8390 safi_t safi = bgp_node_safi(vty);
8391
8392 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8393 yang_afi_safi_value2identity(afi, safi));
8394 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8395 sizeof(base_xpath), af_xpath)
8396 < 0)
8397 return CMD_WARNING_CONFIG_FAILED;
8398
8399 snprintf(attr_xpath, sizeof(attr_xpath),
8400 "/%s/prefix-limit/direction-list[direction='in']",
8401 bgp_afi_safi_get_container_str(afi, safi));
8402 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8403
8404 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8405
8406 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8407 argv[idx_number]->arg);
8408 nb_cli_enqueue_change(vty, "./options/tr-shutdown-threshold-pct",
8409 NB_OP_MODIFY, argv[idx_number_2]->arg);
8410 nb_cli_enqueue_change(vty, "./options/tr-restart-timer", NB_OP_MODIFY,
8411 argv[idx_number_3]->arg);
8412 if (argv_find(argv, argc, "force", &idx_force))
8413 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8414 "true");
8415
8416 return nb_cli_apply_changes(vty, base_xpath);
8417 }
8418
8419 ALIAS_HIDDEN(
8420 neighbor_maximum_prefix_threshold_restart,
8421 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
8422 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8423 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8424 "Maximum number of prefixes to accept from this peer\n"
8425 "maximum no. of prefix limit\n"
8426 "Threshold value (%) at which to generate a warning msg\n"
8427 "Restart bgp connection after limit is exceeded\n"
8428 "Restart interval in minutes\n"
8429 "Force checking all received routes not only accepted\n")
8430
8431 DEFUN_YANG(no_neighbor_maximum_prefix,
8432 no_neighbor_maximum_prefix_cmd,
8433 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8434 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8435 "Maximum number of prefixes to accept from this peer\n"
8436 "maximum no. of prefix limit\n"
8437 "Threshold value (%) at which to generate a warning msg\n"
8438 "Restart bgp connection after limit is exceeded\n"
8439 "Restart interval in minutes\n"
8440 "Only give warning message when limit is exceeded\n"
8441 "Force checking all received routes not only accepted\n")
8442 {
8443 int idx_peer = 2;
8444 char base_xpath[XPATH_MAXLEN];
8445 char af_xpath[XPATH_MAXLEN];
8446 char attr_xpath[XPATH_MAXLEN];
8447 afi_t afi = bgp_node_afi(vty);
8448 safi_t safi = bgp_node_safi(vty);
8449
8450 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8451 yang_afi_safi_value2identity(afi, safi));
8452 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8453 sizeof(base_xpath), af_xpath)
8454 < 0)
8455 return CMD_WARNING_CONFIG_FAILED;
8456
8457 snprintf(attr_xpath, sizeof(attr_xpath),
8458 "/%s/prefix-limit/direction-list[direction='in']",
8459 bgp_afi_safi_get_container_str(afi, safi));
8460 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8461
8462 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
8463
8464 return nb_cli_apply_changes(vty, base_xpath);
8465 }
8466
8467 ALIAS_HIDDEN(
8468 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
8469 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8470 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8471 "Maximum number of prefixes to accept from this peer\n"
8472 "maximum no. of prefix limit\n"
8473 "Threshold value (%) at which to generate a warning msg\n"
8474 "Restart bgp connection after limit is exceeded\n"
8475 "Restart interval in minutes\n"
8476 "Only give warning message when limit is exceeded\n"
8477 "Force checking all received routes not only accepted\n")
8478
8479
8480 /* "neighbor allowas-in" */
8481 DEFUN (neighbor_allowas_in,
8482 neighbor_allowas_in_cmd,
8483 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8484 NEIGHBOR_STR
8485 NEIGHBOR_ADDR_STR2
8486 "Accept as-path with my AS present in it\n"
8487 "Number of occurrences of AS number\n"
8488 "Only accept my AS in the as-path if the route was originated in my AS\n")
8489 {
8490 int idx_peer = 1;
8491 int idx_number_origin = 3;
8492 int ret;
8493 int origin = 0;
8494 struct peer *peer;
8495 int allow_num = 0;
8496
8497 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8498 if (!peer)
8499 return CMD_WARNING_CONFIG_FAILED;
8500
8501 if (argc <= idx_number_origin)
8502 allow_num = 3;
8503 else {
8504 if (argv[idx_number_origin]->type == WORD_TKN)
8505 origin = 1;
8506 else
8507 allow_num = atoi(argv[idx_number_origin]->arg);
8508 }
8509
8510 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8511 allow_num, origin);
8512
8513 return bgp_vty_return(vty, ret);
8514 }
8515
8516 ALIAS_HIDDEN(
8517 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
8518 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8519 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8520 "Accept as-path with my AS present in it\n"
8521 "Number of occurrences of AS number\n"
8522 "Only accept my AS in the as-path if the route was originated in my AS\n")
8523
8524 DEFUN (no_neighbor_allowas_in,
8525 no_neighbor_allowas_in_cmd,
8526 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8527 NO_STR
8528 NEIGHBOR_STR
8529 NEIGHBOR_ADDR_STR2
8530 "allow local ASN appears in aspath attribute\n"
8531 "Number of occurrences of AS number\n"
8532 "Only accept my AS in the as-path if the route was originated in my AS\n")
8533 {
8534 int idx_peer = 2;
8535 int ret;
8536 struct peer *peer;
8537
8538 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8539 if (!peer)
8540 return CMD_WARNING_CONFIG_FAILED;
8541
8542 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
8543 bgp_node_safi(vty));
8544
8545 return bgp_vty_return(vty, ret);
8546 }
8547
8548 ALIAS_HIDDEN(
8549 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
8550 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8551 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8552 "allow local ASN appears in aspath attribute\n"
8553 "Number of occurrences of AS number\n"
8554 "Only accept my AS in the as-path if the route was originated in my AS\n")
8555
8556 DEFUN_YANG (neighbor_ttl_security,
8557 neighbor_ttl_security_cmd,
8558 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8559 NEIGHBOR_STR
8560 NEIGHBOR_ADDR_STR2
8561 "BGP ttl-security parameters\n"
8562 "Specify the maximum number of hops to the BGP peer\n"
8563 "Number of hops to BGP peer\n")
8564 {
8565 int idx_peer = 1;
8566 int idx_number = 4;
8567 char base_xpath[XPATH_MAXLEN];
8568
8569 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8570 sizeof(base_xpath), NULL)
8571 < 0)
8572 return CMD_WARNING_CONFIG_FAILED;
8573
8574 nb_cli_enqueue_change(vty, "./ttl-security", NB_OP_MODIFY,
8575 argv[idx_number]->arg);
8576
8577 return nb_cli_apply_changes(vty, base_xpath);
8578 }
8579
8580 DEFUN_YANG(no_neighbor_ttl_security,
8581 no_neighbor_ttl_security_cmd,
8582 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8583 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8584 "BGP ttl-security parameters\n"
8585 "Specify the maximum number of hops to the BGP peer\n"
8586 "Number of hops to BGP peer\n")
8587 {
8588 int idx_peer = 2;
8589 char base_xpath[XPATH_MAXLEN];
8590
8591 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8592 sizeof(base_xpath), NULL)
8593 < 0)
8594 return CMD_WARNING_CONFIG_FAILED;
8595
8596 nb_cli_enqueue_change(vty, "./ttl-security", NB_OP_DESTROY, NULL);
8597
8598 return nb_cli_apply_changes(vty, base_xpath);
8599 }
8600
8601 DEFUN (neighbor_addpath_tx_all_paths,
8602 neighbor_addpath_tx_all_paths_cmd,
8603 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8604 NEIGHBOR_STR
8605 NEIGHBOR_ADDR_STR2
8606 "Use addpath to advertise all paths to a neighbor\n")
8607 {
8608 int idx_peer = 1;
8609 struct peer *peer;
8610
8611 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8612 if (!peer)
8613 return CMD_WARNING_CONFIG_FAILED;
8614
8615 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8616 BGP_ADDPATH_ALL);
8617 return CMD_SUCCESS;
8618 }
8619
8620 ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
8621 neighbor_addpath_tx_all_paths_hidden_cmd,
8622 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8623 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8624 "Use addpath to advertise all paths to a neighbor\n")
8625
8626 DEFUN (no_neighbor_addpath_tx_all_paths,
8627 no_neighbor_addpath_tx_all_paths_cmd,
8628 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8629 NO_STR
8630 NEIGHBOR_STR
8631 NEIGHBOR_ADDR_STR2
8632 "Use addpath to advertise all paths to a neighbor\n")
8633 {
8634 int idx_peer = 2;
8635 struct peer *peer;
8636
8637 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8638 if (!peer)
8639 return CMD_WARNING_CONFIG_FAILED;
8640
8641 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8642 != BGP_ADDPATH_ALL) {
8643 vty_out(vty,
8644 "%% Peer not currently configured to transmit all paths.");
8645 return CMD_WARNING_CONFIG_FAILED;
8646 }
8647
8648 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8649 BGP_ADDPATH_NONE);
8650
8651 return CMD_SUCCESS;
8652 }
8653
8654 ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
8655 no_neighbor_addpath_tx_all_paths_hidden_cmd,
8656 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8657 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8658 "Use addpath to advertise all paths to a neighbor\n")
8659
8660 DEFUN (neighbor_addpath_tx_bestpath_per_as,
8661 neighbor_addpath_tx_bestpath_per_as_cmd,
8662 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8663 NEIGHBOR_STR
8664 NEIGHBOR_ADDR_STR2
8665 "Use addpath to advertise the bestpath per each neighboring AS\n")
8666 {
8667 int idx_peer = 1;
8668 struct peer *peer;
8669
8670 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8671 if (!peer)
8672 return CMD_WARNING_CONFIG_FAILED;
8673
8674 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8675 BGP_ADDPATH_BEST_PER_AS);
8676
8677 return CMD_SUCCESS;
8678 }
8679
8680 ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
8681 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8682 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8683 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8684 "Use addpath to advertise the bestpath per each neighboring AS\n")
8685
8686 DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
8687 no_neighbor_addpath_tx_bestpath_per_as_cmd,
8688 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8689 NO_STR
8690 NEIGHBOR_STR
8691 NEIGHBOR_ADDR_STR2
8692 "Use addpath to advertise the bestpath per each neighboring AS\n")
8693 {
8694 int idx_peer = 2;
8695 struct peer *peer;
8696
8697 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8698 if (!peer)
8699 return CMD_WARNING_CONFIG_FAILED;
8700
8701 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8702 != BGP_ADDPATH_BEST_PER_AS) {
8703 vty_out(vty,
8704 "%% Peer not currently configured to transmit all best path per as.");
8705 return CMD_WARNING_CONFIG_FAILED;
8706 }
8707
8708 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8709 BGP_ADDPATH_NONE);
8710
8711 return CMD_SUCCESS;
8712 }
8713
8714 ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
8715 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8716 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8717 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8718 "Use addpath to advertise the bestpath per each neighboring AS\n")
8719
8720 DEFPY(
8721 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
8722 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8723 NEIGHBOR_STR
8724 NEIGHBOR_ADDR_STR2
8725 "Detect AS loops before sending to neighbor\n")
8726 {
8727 struct peer *peer;
8728
8729 peer = peer_and_group_lookup_vty(vty, neighbor);
8730 if (!peer)
8731 return CMD_WARNING_CONFIG_FAILED;
8732
8733 peer->as_path_loop_detection = true;
8734
8735 return CMD_SUCCESS;
8736 }
8737
8738 DEFPY(
8739 no_neighbor_aspath_loop_detection,
8740 no_neighbor_aspath_loop_detection_cmd,
8741 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8742 NO_STR
8743 NEIGHBOR_STR
8744 NEIGHBOR_ADDR_STR2
8745 "Detect AS loops before sending to neighbor\n")
8746 {
8747 struct peer *peer;
8748
8749 peer = peer_and_group_lookup_vty(vty, neighbor);
8750 if (!peer)
8751 return CMD_WARNING_CONFIG_FAILED;
8752
8753 peer->as_path_loop_detection = false;
8754
8755 return CMD_SUCCESS;
8756 }
8757
8758 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
8759 struct ecommunity **list, bool is_rt6)
8760 {
8761 struct ecommunity *ecom = NULL;
8762 struct ecommunity *ecomadd;
8763
8764 for (; argc; --argc, ++argv) {
8765 if (is_rt6)
8766 ecomadd = ecommunity_str2com_ipv6(argv[0]->arg,
8767 ECOMMUNITY_ROUTE_TARGET,
8768 0);
8769 else
8770 ecomadd = ecommunity_str2com(argv[0]->arg,
8771 ECOMMUNITY_ROUTE_TARGET,
8772 0);
8773 if (!ecomadd) {
8774 vty_out(vty, "Malformed community-list value\n");
8775 if (ecom)
8776 ecommunity_free(&ecom);
8777 return CMD_WARNING_CONFIG_FAILED;
8778 }
8779
8780 if (ecom) {
8781 ecommunity_merge(ecom, ecomadd);
8782 ecommunity_free(&ecomadd);
8783 } else {
8784 ecom = ecomadd;
8785 }
8786 }
8787
8788 if (*list) {
8789 ecommunity_free(&*list);
8790 }
8791 *list = ecom;
8792
8793 return CMD_SUCCESS;
8794 }
8795
8796 bool vpn_policy_check_import(struct bgp *bgp, afi_t afi, safi_t safi,
8797 bool v2vimport, char *errmsg, size_t errmsg_len)
8798 {
8799 if (!v2vimport) {
8800 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8801 BGP_CONFIG_VRF_TO_VRF_IMPORT)
8802 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8803 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
8804 snprintf(
8805 errmsg, errmsg_len, "%s",
8806 "%% error: Please unconfigure import vrf commands before using vpn commands");
8807 return false;
8808 }
8809 } else {
8810 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8811 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
8812 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8813 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
8814 snprintf(
8815 errmsg, errmsg_len, "%s",
8816 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands");
8817 return false;
8818 }
8819 }
8820 return true;
8821 }
8822
8823 /*
8824 * v2vimport is true if we are handling a `import vrf ...` command
8825 */
8826 static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
8827 {
8828 afi_t afi;
8829
8830 switch (vty->node) {
8831 case BGP_IPV4_NODE:
8832 afi = AFI_IP;
8833 break;
8834 case BGP_IPV6_NODE:
8835 afi = AFI_IP6;
8836 break;
8837 default:
8838 vty_out(vty,
8839 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
8840 return AFI_MAX;
8841 }
8842
8843 if (!v2vimport) {
8844 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8845 BGP_CONFIG_VRF_TO_VRF_IMPORT)
8846 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8847 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
8848 vty_out(vty,
8849 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
8850 return AFI_MAX;
8851 }
8852 } else {
8853 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8854 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
8855 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8856 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
8857 vty_out(vty,
8858 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
8859 return AFI_MAX;
8860 }
8861 }
8862 return afi;
8863 }
8864
8865 DEFPY_YANG(
8866 af_rd_vpn_export,
8867 af_rd_vpn_export_cmd,
8868 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
8869 NO_STR
8870 "Specify route distinguisher\n"
8871 "Between current address-family and vpn\n"
8872 "For routes leaked from current address-family to vpn\n"
8873 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
8874 {
8875 char base_xpath[XPATH_MAXLEN];
8876 afi_t afi;
8877 safi_t safi;
8878 int idx = 0;
8879
8880 afi = bgp_node_afi(vty);
8881 safi = bgp_node_safi(vty);
8882
8883 snprintf(
8884 base_xpath, sizeof(base_xpath),
8885 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config",
8886 yang_afi_safi_value2identity(afi, safi),
8887 bgp_afi_safi_get_container_str(afi, safi));
8888
8889 if (argv_find(argv, argc, "no", &idx))
8890 nb_cli_enqueue_change(vty, "./rd", NB_OP_DESTROY, NULL);
8891 else
8892 nb_cli_enqueue_change(vty, "./rd", NB_OP_MODIFY, rd_str);
8893
8894 return nb_cli_apply_changes(vty, base_xpath);
8895 }
8896
8897 void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rd(
8898 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
8899 {
8900 int indent = 2;
8901
8902 vty_out(vty, "%*srd vpn export %s\n", indent, "",
8903 yang_dnode_get_string(dnode, NULL));
8904 }
8905
8906 ALIAS (af_rd_vpn_export,
8907 af_no_rd_vpn_export_cmd,
8908 "no rd vpn export",
8909 NO_STR
8910 "Specify route distinguisher\n"
8911 "Between current address-family and vpn\n"
8912 "For routes leaked from current address-family to vpn\n")
8913
8914 DEFPY (af_label_vpn_export,
8915 af_label_vpn_export_cmd,
8916 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
8917 NO_STR
8918 "label value for VRF\n"
8919 "Between current address-family and vpn\n"
8920 "For routes leaked from current address-family to vpn\n"
8921 "Label Value <0-1048575>\n"
8922 "Automatically assign a label\n")
8923 {
8924 VTY_DECLVAR_CONTEXT(bgp, bgp);
8925 mpls_label_t label = MPLS_LABEL_NONE;
8926 afi_t afi;
8927 int idx = 0;
8928 bool yes = true;
8929
8930 if (argv_find(argv, argc, "no", &idx))
8931 yes = false;
8932
8933 /* If "no ...", squash trailing parameter */
8934 if (!yes)
8935 label_auto = NULL;
8936
8937 if (yes) {
8938 if (!label_auto)
8939 label = label_val; /* parser should force unsigned */
8940 }
8941
8942 afi = vpn_policy_getafi(vty, bgp, false);
8943 if (afi == AFI_MAX)
8944 return CMD_WARNING_CONFIG_FAILED;
8945
8946
8947 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8948 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
8949 /* no change */
8950 return CMD_SUCCESS;
8951
8952 /*
8953 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8954 */
8955 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8956 bgp_get_default(), bgp);
8957
8958 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8959 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
8960
8961 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
8962
8963 /*
8964 * label has previously been automatically
8965 * assigned by labelpool: release it
8966 *
8967 * NB if tovpn_label == MPLS_LABEL_NONE it
8968 * means the automatic assignment is in flight
8969 * and therefore the labelpool callback must
8970 * detect that the auto label is not needed.
8971 */
8972
8973 bgp_lp_release(LP_TYPE_VRF,
8974 &bgp->vpn_policy[afi],
8975 bgp->vpn_policy[afi].tovpn_label);
8976 }
8977 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8978 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
8979 }
8980
8981 bgp->vpn_policy[afi].tovpn_label = label;
8982 if (label_auto) {
8983 SET_FLAG(bgp->vpn_policy[afi].flags,
8984 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
8985 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
8986 vpn_leak_label_callback);
8987 }
8988
8989 /* post-change: re-export vpn routes */
8990 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8991 bgp_get_default(), bgp);
8992
8993 return CMD_SUCCESS;
8994 }
8995
8996 ALIAS (af_label_vpn_export,
8997 af_no_label_vpn_export_cmd,
8998 "no label vpn export",
8999 NO_STR
9000 "label value for VRF\n"
9001 "Between current address-family and vpn\n"
9002 "For routes leaked from current address-family to vpn\n")
9003
9004 DEFPY_YANG (af_nexthop_vpn_export,
9005 af_nexthop_vpn_export_cmd,
9006 "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
9007 NO_STR
9008 "Specify next hop to use for VRF advertised prefixes\n"
9009 "Between current address-family and vpn\n"
9010 "For routes leaked from current address-family to vpn\n"
9011 "IPv4 prefix\n"
9012 "IPv6 prefix\n")
9013 {
9014 char base_xpath[XPATH_MAXLEN];
9015 afi_t afi;
9016 safi_t safi;
9017 int idx = 0;
9018 struct prefix p;
9019
9020 if (!no) {
9021 if (!nexthop_su) {
9022 vty_out(vty, "%% Nexthop required\n");
9023 return CMD_WARNING_CONFIG_FAILED;
9024 }
9025 if (!sockunion2hostprefix(nexthop_su, &p))
9026 return CMD_WARNING_CONFIG_FAILED;
9027 }
9028
9029 afi = bgp_node_afi(vty);
9030 safi = bgp_node_safi(vty);
9031
9032 snprintf(
9033 base_xpath, sizeof(base_xpath),
9034 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config",
9035 yang_afi_safi_value2identity(afi, safi),
9036 bgp_afi_safi_get_container_str(afi, safi));
9037
9038 if (argv_find(argv, argc, "no", &idx))
9039 nb_cli_enqueue_change(vty, "./nexthop", NB_OP_DESTROY, NULL);
9040 else
9041 nb_cli_enqueue_change(vty, "./nexthop", NB_OP_MODIFY,
9042 nexthop_su_str);
9043
9044 return nb_cli_apply_changes(vty, base_xpath);
9045 }
9046
9047 void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_nexthop(
9048 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9049 {
9050 int indent = 2;
9051
9052 vty_out(vty, "%*snexthop vpn export %s\n", indent, "",
9053 yang_dnode_get_string(dnode, NULL));
9054 }
9055
9056 static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
9057 {
9058 if (!strcmp(dstr, "import")) {
9059 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9060 } else if (!strcmp(dstr, "export")) {
9061 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9062 } else if (!strcmp(dstr, "both")) {
9063 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9064 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9065 } else {
9066 vty_out(vty, "%% direction parse error\n");
9067 return CMD_WARNING_CONFIG_FAILED;
9068 }
9069 return CMD_SUCCESS;
9070 }
9071
9072 DEFPY (af_rt_vpn_imexport,
9073 af_rt_vpn_imexport_cmd,
9074 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
9075 NO_STR
9076 "Specify route target list\n"
9077 "Specify route target list\n"
9078 "Between current address-family and vpn\n"
9079 "For routes leaked from vpn to current address-family: match any\n"
9080 "For routes leaked from current address-family to vpn: set\n"
9081 "both import: match any and export: set\n"
9082 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
9083 {
9084 VTY_DECLVAR_CONTEXT(bgp, bgp);
9085 int ret;
9086 struct ecommunity *ecom = NULL;
9087 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
9088 vpn_policy_direction_t dir;
9089 afi_t afi;
9090 int idx = 0;
9091 bool yes = true;
9092
9093 if (argv_find(argv, argc, "no", &idx))
9094 yes = false;
9095
9096 afi = vpn_policy_getafi(vty, bgp, false);
9097 if (afi == AFI_MAX)
9098 return CMD_WARNING_CONFIG_FAILED;
9099
9100 ret = vpn_policy_getdirs(vty, direction_str, dodir);
9101 if (ret != CMD_SUCCESS)
9102 return ret;
9103
9104 if (yes) {
9105 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9106 vty_out(vty, "%% Missing RTLIST\n");
9107 return CMD_WARNING_CONFIG_FAILED;
9108 }
9109 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, false);
9110 if (ret != CMD_SUCCESS) {
9111 return ret;
9112 }
9113 }
9114
9115 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9116 if (!dodir[dir])
9117 continue;
9118
9119 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9120
9121 if (yes) {
9122 if (bgp->vpn_policy[afi].rtlist[dir])
9123 ecommunity_free(
9124 &bgp->vpn_policy[afi].rtlist[dir]);
9125 bgp->vpn_policy[afi].rtlist[dir] =
9126 ecommunity_dup(ecom);
9127 } else {
9128 if (bgp->vpn_policy[afi].rtlist[dir])
9129 ecommunity_free(
9130 &bgp->vpn_policy[afi].rtlist[dir]);
9131 bgp->vpn_policy[afi].rtlist[dir] = NULL;
9132 }
9133
9134 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9135 }
9136
9137 if (ecom)
9138 ecommunity_free(&ecom);
9139
9140 return CMD_SUCCESS;
9141 }
9142
9143 ALIAS (af_rt_vpn_imexport,
9144 af_no_rt_vpn_imexport_cmd,
9145 "no <rt|route-target> vpn <import|export|both>$direction_str",
9146 NO_STR
9147 "Specify route target list\n"
9148 "Specify route target list\n"
9149 "Between current address-family and vpn\n"
9150 "For routes leaked from vpn to current address-family\n"
9151 "For routes leaked from current address-family to vpn\n"
9152 "both import and export\n")
9153
9154 DEFPY_YANG (af_route_map_vpn_imexport,
9155 af_route_map_vpn_imexport_cmd,
9156 /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
9157 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
9158 NO_STR
9159 "Specify route map\n"
9160 "Between current address-family and vpn\n"
9161 "For routes leaked from vpn to current address-family\n"
9162 "For routes leaked from current address-family to vpn\n"
9163 "name of route-map\n")
9164 {
9165 char base_xpath[XPATH_MAXLEN];
9166 afi_t afi;
9167 safi_t safi;
9168 int idx = 0;
9169
9170 afi = bgp_node_afi(vty);
9171 safi = bgp_node_safi(vty);
9172
9173 snprintf(
9174 base_xpath, sizeof(base_xpath),
9175 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config",
9176 yang_afi_safi_value2identity(afi, safi),
9177 bgp_afi_safi_get_container_str(afi, safi));
9178
9179 if (argv_find(argv, argc, "no", &idx)) {
9180 if (!strcmp(direction_str, "import"))
9181 nb_cli_enqueue_change(vty, "./rmap-import",
9182 NB_OP_DESTROY, NULL);
9183 else if (!strcmp(direction_str, "export"))
9184 nb_cli_enqueue_change(vty, "./rmap-export",
9185 NB_OP_DESTROY, NULL);
9186 } else {
9187 if (!strcmp(direction_str, "import"))
9188 nb_cli_enqueue_change(vty, "./rmap-import",
9189 NB_OP_MODIFY, rmap_str);
9190 if (!strcmp(direction_str, "export"))
9191 nb_cli_enqueue_change(vty, "./rmap-export",
9192 NB_OP_MODIFY, rmap_str);
9193 }
9194 return nb_cli_apply_changes(vty, base_xpath);
9195 }
9196
9197 void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rmap_import(
9198 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9199 {
9200 int indent = 2;
9201
9202 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
9203 yang_dnode_get_string(dnode, NULL));
9204 }
9205
9206 void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rmap_export(
9207 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9208 {
9209 int indent = 2;
9210
9211 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
9212 yang_dnode_get_string(dnode, NULL));
9213 }
9214
9215 ALIAS (af_route_map_vpn_imexport,
9216 af_no_route_map_vpn_imexport_cmd,
9217 "no route-map vpn <import|export>$direction_str",
9218 NO_STR
9219 "Specify route map\n"
9220 "Between current address-family and vpn\n"
9221 "For routes leaked from vpn to current address-family\n"
9222 "For routes leaked from current address-family to vpn\n")
9223
9224 DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
9225 "import vrf route-map RMAP$rmap_str",
9226 "Import routes from another VRF\n"
9227 "Vrf routes being filtered\n"
9228 "Specify route map\n"
9229 "name of route-map\n")
9230 {
9231 VTY_DECLVAR_CONTEXT(bgp, bgp);
9232 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
9233 afi_t afi;
9234 struct bgp *bgp_default;
9235
9236 afi = vpn_policy_getafi(vty, bgp, true);
9237 if (afi == AFI_MAX)
9238 return CMD_WARNING_CONFIG_FAILED;
9239
9240 bgp_default = bgp_get_default();
9241 if (!bgp_default) {
9242 int32_t ret;
9243 as_t as = bgp->as;
9244
9245 /* Auto-create assuming the same AS */
9246 ret = bgp_get_vty(&bgp_default, &as, NULL,
9247 BGP_INSTANCE_TYPE_DEFAULT);
9248
9249 if (ret) {
9250 vty_out(vty,
9251 "VRF default is not configured as a bgp instance\n");
9252 return CMD_WARNING;
9253 }
9254 }
9255
9256 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9257
9258 if (bgp->vpn_policy[afi].rmap_name[dir])
9259 XFREE(MTYPE_ROUTE_MAP_NAME,
9260 bgp->vpn_policy[afi].rmap_name[dir]);
9261 bgp->vpn_policy[afi].rmap_name[dir] =
9262 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
9263 bgp->vpn_policy[afi].rmap[dir] =
9264 route_map_lookup_warn_noexist(vty, rmap_str);
9265 if (!bgp->vpn_policy[afi].rmap[dir])
9266 return CMD_SUCCESS;
9267
9268 SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9269 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9270
9271 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9272
9273 return CMD_SUCCESS;
9274 }
9275
9276 DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
9277 "no import vrf route-map [RMAP$rmap_str]",
9278 NO_STR
9279 "Import routes from another VRF\n"
9280 "Vrf routes being filtered\n"
9281 "Specify route map\n"
9282 "name of route-map\n")
9283 {
9284 VTY_DECLVAR_CONTEXT(bgp, bgp);
9285 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
9286 afi_t afi;
9287
9288 afi = vpn_policy_getafi(vty, bgp, true);
9289 if (afi == AFI_MAX)
9290 return CMD_WARNING_CONFIG_FAILED;
9291
9292 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9293
9294 if (bgp->vpn_policy[afi].rmap_name[dir])
9295 XFREE(MTYPE_ROUTE_MAP_NAME,
9296 bgp->vpn_policy[afi].rmap_name[dir]);
9297 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9298 bgp->vpn_policy[afi].rmap[dir] = NULL;
9299
9300 if (bgp->vpn_policy[afi].import_vrf->count == 0)
9301 UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9302 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9303
9304 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9305
9306 return CMD_SUCCESS;
9307 }
9308
9309 DEFPY_YANG(bgp_imexport_vrf,
9310 bgp_imexport_vrf_cmd,
9311 "[no] import vrf VIEWVRFNAME$import_name",
9312 NO_STR
9313 "Import routes from another VRF\n"
9314 "VRF to import from\n"
9315 "The name of the VRF\n")
9316 {
9317 char base_xpath[XPATH_MAXLEN];
9318 safi_t safi;
9319 afi_t afi;
9320 int32_t idx = 0;
9321
9322 if (import_name == NULL) {
9323 vty_out(vty, "%% Missing import name\n");
9324 return CMD_WARNING;
9325 }
9326
9327 if (strcmp(import_name, "route-map") == 0) {
9328 vty_out(vty, "%% Must include route-map name\n");
9329 return CMD_WARNING;
9330 }
9331
9332 afi = bgp_node_afi(vty);
9333 safi = bgp_node_safi(vty);
9334
9335 snprintf(
9336 base_xpath, sizeof(base_xpath),
9337 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config/import-vrf-list[vrf='%s']",
9338 yang_afi_safi_value2identity(afi, safi),
9339 bgp_afi_safi_get_container_str(afi, safi), import_name);
9340
9341 if (argv_find(argv, argc, "no", &idx))
9342 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
9343 else
9344 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
9345
9346 return nb_cli_apply_changes(vty, base_xpath);
9347 }
9348
9349 void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_import_vrfs(
9350 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9351 {
9352 vty_out(vty, " import vrf %s\n",
9353 yang_dnode_get_string(dnode, "./vrf"));
9354 }
9355
9356 /* This command is valid only in a bgp vrf instance or the default instance */
9357 DEFPY_YANG (bgp_imexport_vpn,
9358 bgp_imexport_vpn_cmd,
9359 "[no] <import|export>$direction_str vpn",
9360 NO_STR
9361 "Import routes to this address-family\n"
9362 "Export routes from this address-family\n"
9363 "to/from default instance VPN RIB\n")
9364 {
9365 char base_xpath[XPATH_MAXLEN];
9366 safi_t safi;
9367 afi_t afi;
9368 int32_t idx = 0;
9369
9370 afi = bgp_node_afi(vty);
9371 safi = bgp_node_safi(vty);
9372
9373 if (!strcmp(direction_str, "import")) {
9374 snprintf(
9375 base_xpath, sizeof(base_xpath),
9376 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config/import-vpn",
9377 yang_afi_safi_value2identity(afi, safi),
9378 bgp_afi_safi_get_container_str(afi, safi));
9379 } else if (!strcmp(direction_str, "export")) {
9380 snprintf(
9381 base_xpath, sizeof(base_xpath),
9382 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config/export-vpn",
9383 yang_afi_safi_value2identity(afi, safi),
9384 bgp_afi_safi_get_container_str(afi, safi));
9385 } else {
9386 vty_out(vty, "%% unknown direction %s\n", direction_str);
9387 return CMD_WARNING_CONFIG_FAILED;
9388 }
9389
9390 if (argv_find(argv, argc, "no", &idx))
9391 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
9392 else
9393 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, "true");
9394
9395 return nb_cli_apply_changes(vty, base_xpath);
9396 }
9397
9398 void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_import_vpn(
9399 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9400 {
9401 if (yang_dnode_get_bool(dnode, NULL))
9402 vty_out(vty, " import vpn\n");
9403 }
9404
9405 void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_export_vpn(
9406 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9407 {
9408 if (yang_dnode_get_bool(dnode, NULL))
9409 vty_out(vty, " export vpn\n");
9410 }
9411
9412 DEFPY (af_routetarget_import,
9413 af_routetarget_import_cmd,
9414 "[no] <rt|route-target|route-target6|rt6> redirect import RTLIST...",
9415 NO_STR
9416 "Specify route target list\n"
9417 "Specify route target list\n"
9418 "Specify route target list\n"
9419 "Specify route target list\n"
9420 "Flow-spec redirect type route target\n"
9421 "Import routes to this address-family\n"
9422 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN|IPV6:MN)\n")
9423 {
9424 VTY_DECLVAR_CONTEXT(bgp, bgp);
9425 int ret;
9426 struct ecommunity *ecom = NULL;
9427 afi_t afi;
9428 int idx = 0, idx_unused = 0;
9429 bool yes = true;
9430 bool rt6 = false;
9431
9432 if (argv_find(argv, argc, "no", &idx))
9433 yes = false;
9434
9435 if (argv_find(argv, argc, "rt6", &idx_unused) ||
9436 argv_find(argv, argc, "route-target6", &idx_unused))
9437 rt6 = true;
9438
9439 afi = vpn_policy_getafi(vty, bgp, false);
9440 if (afi == AFI_MAX)
9441 return CMD_WARNING_CONFIG_FAILED;
9442
9443 if (rt6 && afi != AFI_IP6)
9444 return CMD_WARNING_CONFIG_FAILED;
9445
9446 if (yes) {
9447 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9448 vty_out(vty, "%% Missing RTLIST\n");
9449 return CMD_WARNING_CONFIG_FAILED;
9450 }
9451 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, rt6);
9452 if (ret != CMD_SUCCESS)
9453 return ret;
9454 }
9455
9456 if (yes) {
9457 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9458 ecommunity_free(&bgp->vpn_policy[afi]
9459 .import_redirect_rtlist);
9460 bgp->vpn_policy[afi].import_redirect_rtlist =
9461 ecommunity_dup(ecom);
9462 } else {
9463 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9464 ecommunity_free(&bgp->vpn_policy[afi]
9465 .import_redirect_rtlist);
9466 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
9467 }
9468
9469 if (ecom)
9470 ecommunity_free(&ecom);
9471
9472 return CMD_SUCCESS;
9473 }
9474
9475 void cli_show_bgp_global_afi_safi_header(struct vty *vty,
9476 struct lyd_node *dnode,
9477 bool show_defaults)
9478 {
9479 const char *af_name;
9480 afi_t afi;
9481 safi_t safi;
9482
9483 af_name = yang_dnode_get_string(dnode, "./afi-safi-name");
9484 yang_afi_safi_identity2value(af_name, &afi, &safi);
9485
9486 vty_out(vty, " !\n address-family ");
9487 if (afi == AFI_IP) {
9488 if (safi == SAFI_UNICAST)
9489 vty_out(vty, "ipv4 unicast");
9490 else if (safi == SAFI_LABELED_UNICAST)
9491 vty_out(vty, "ipv4 labeled-unicast");
9492 else if (safi == SAFI_MULTICAST)
9493 vty_out(vty, "ipv4 multicast");
9494 else if (safi == SAFI_MPLS_VPN)
9495 vty_out(vty, "ipv4 vpn");
9496 else if (safi == SAFI_ENCAP)
9497 vty_out(vty, "ipv4 encap");
9498 else if (safi == SAFI_FLOWSPEC)
9499 vty_out(vty, "ipv4 flowspec");
9500 } else if (afi == AFI_IP6) {
9501 if (safi == SAFI_UNICAST)
9502 vty_out(vty, "ipv6 unicast");
9503 else if (safi == SAFI_LABELED_UNICAST)
9504 vty_out(vty, "ipv6 labeled-unicast");
9505 else if (safi == SAFI_MULTICAST)
9506 vty_out(vty, "ipv6 multicast");
9507 else if (safi == SAFI_MPLS_VPN)
9508 vty_out(vty, "ipv6 vpn");
9509 else if (safi == SAFI_ENCAP)
9510 vty_out(vty, "ipv6 encap");
9511 else if (safi == SAFI_FLOWSPEC)
9512 vty_out(vty, "ipv6 flowspec");
9513 } else if (afi == AFI_L2VPN) {
9514 if (safi == SAFI_EVPN)
9515 vty_out(vty, "l2vpn evpn");
9516 }
9517 vty_out(vty, "\n");
9518 }
9519
9520 DEFUN_NOSH (address_family_ipv4_safi,
9521 address_family_ipv4_safi_cmd,
9522 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9523 "Enter Address Family command mode\n"
9524 "Address Family\n"
9525 BGP_SAFI_WITH_LABEL_HELP_STR)
9526 {
9527
9528 safi_t safi = SAFI_UNICAST;
9529 const struct lyd_node *vrf_dnode, *bgp_glb_dnode;
9530 const char *vrf_name = NULL;
9531
9532 if (argc == 3) {
9533 safi = bgp_vty_safi_from_str(argv[2]->text);
9534
9535 bgp_glb_dnode = yang_dnode_get(vty->candidate_config->dnode,
9536 VTY_CURR_XPATH);
9537 vrf_dnode = yang_dnode_get_parent(bgp_glb_dnode,
9538 "control-plane-protocol");
9539 vrf_name = yang_dnode_get_string(vrf_dnode, "./vrf");
9540
9541 if (!strmatch(vrf_name, VRF_DEFAULT_NAME)
9542 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9543 && safi != SAFI_EVPN) {
9544 vty_out(vty,
9545 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9546 return CMD_WARNING_CONFIG_FAILED;
9547 }
9548 }
9549 vty->node = bgp_node_type(AFI_IP, safi);
9550
9551 return CMD_SUCCESS;
9552 }
9553
9554 DEFUN_NOSH (address_family_ipv6_safi,
9555 address_family_ipv6_safi_cmd,
9556 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9557 "Enter Address Family command mode\n"
9558 "Address Family\n"
9559 BGP_SAFI_WITH_LABEL_HELP_STR)
9560 {
9561 safi_t safi = SAFI_UNICAST;
9562 const struct lyd_node *vrf_dnode, *bgp_glb_dnode;
9563 const char *vrf_name = NULL;
9564
9565 if (argc == 3) {
9566 safi = bgp_vty_safi_from_str(argv[2]->text);
9567 bgp_glb_dnode = yang_dnode_get(vty->candidate_config->dnode,
9568 VTY_CURR_XPATH);
9569 vrf_dnode = yang_dnode_get_parent(bgp_glb_dnode,
9570 "control-plane-protocol");
9571 vrf_name = yang_dnode_get_string(vrf_dnode, "./vrf");
9572
9573 if (!strmatch(vrf_name, VRF_DEFAULT_NAME)
9574 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9575 && safi != SAFI_EVPN) {
9576 vty_out(vty,
9577 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9578 return CMD_WARNING_CONFIG_FAILED;
9579 }
9580 }
9581 vty->node = bgp_node_type(AFI_IP6, safi);
9582
9583 return CMD_SUCCESS;
9584 }
9585
9586 #ifdef KEEP_OLD_VPN_COMMANDS
9587 DEFUN_NOSH (address_family_vpnv4,
9588 address_family_vpnv4_cmd,
9589 "address-family vpnv4 [unicast]",
9590 "Enter Address Family command mode\n"
9591 "Address Family\n"
9592 "Address Family modifier\n")
9593 {
9594 vty->node = BGP_VPNV4_NODE;
9595 return CMD_SUCCESS;
9596 }
9597
9598 DEFUN_NOSH (address_family_vpnv6,
9599 address_family_vpnv6_cmd,
9600 "address-family vpnv6 [unicast]",
9601 "Enter Address Family command mode\n"
9602 "Address Family\n"
9603 "Address Family modifier\n")
9604 {
9605 vty->node = BGP_VPNV6_NODE;
9606 return CMD_SUCCESS;
9607 }
9608 #endif /* KEEP_OLD_VPN_COMMANDS */
9609
9610 DEFUN_NOSH (address_family_evpn,
9611 address_family_evpn_cmd,
9612 "address-family l2vpn evpn",
9613 "Enter Address Family command mode\n"
9614 "Address Family\n"
9615 "Address Family modifier\n")
9616 {
9617 VTY_DECLVAR_CONTEXT(bgp, bgp);
9618 vty->node = BGP_EVPN_NODE;
9619 return CMD_SUCCESS;
9620 }
9621
9622 DEFUN_NOSH (exit_address_family,
9623 exit_address_family_cmd,
9624 "exit-address-family",
9625 "Exit from Address Family configuration mode\n")
9626 {
9627 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
9628 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
9629 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
9630 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
9631 || vty->node == BGP_EVPN_NODE
9632 || vty->node == BGP_FLOWSPECV4_NODE
9633 || vty->node == BGP_FLOWSPECV6_NODE)
9634 vty->node = BGP_NODE;
9635 return CMD_SUCCESS;
9636 }
9637
9638 void cli_show_bgp_global_afi_safi_header_end(struct vty *vty,
9639 struct lyd_node *dnode
9640 __attribute__((__unused__)))
9641 {
9642 vty_out(vty, " exit-address-family\n");
9643 }
9644
9645 /* Recalculate bestpath and re-advertise a prefix */
9646 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
9647 const char *ip_str, afi_t afi, safi_t safi,
9648 struct prefix_rd *prd)
9649 {
9650 int ret;
9651 struct prefix match;
9652 struct bgp_dest *dest;
9653 struct bgp_dest *rm;
9654 struct bgp *bgp;
9655 struct bgp_table *table;
9656 struct bgp_table *rib;
9657
9658 /* BGP structure lookup. */
9659 if (view_name) {
9660 bgp = bgp_lookup_by_name(view_name);
9661 if (bgp == NULL) {
9662 vty_out(vty, "%% Can't find BGP instance %s\n",
9663 view_name);
9664 return CMD_WARNING;
9665 }
9666 } else {
9667 bgp = bgp_get_default();
9668 if (bgp == NULL) {
9669 vty_out(vty, "%% No BGP process is configured\n");
9670 return CMD_WARNING;
9671 }
9672 }
9673
9674 /* Check IP address argument. */
9675 ret = str2prefix(ip_str, &match);
9676 if (!ret) {
9677 vty_out(vty, "%% address is malformed\n");
9678 return CMD_WARNING;
9679 }
9680
9681 match.family = afi2family(afi);
9682 rib = bgp->rib[afi][safi];
9683
9684 if (safi == SAFI_MPLS_VPN) {
9685 for (dest = bgp_table_top(rib); dest;
9686 dest = bgp_route_next(dest)) {
9687 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
9688
9689 if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
9690 continue;
9691
9692 table = bgp_dest_get_bgp_table_info(dest);
9693 if (table == NULL)
9694 continue;
9695
9696 if ((rm = bgp_node_match(table, &match)) != NULL) {
9697 const struct prefix *rm_p =
9698 bgp_dest_get_prefix(rm);
9699
9700 if (rm_p->prefixlen == match.prefixlen) {
9701 SET_FLAG(rm->flags,
9702 BGP_NODE_USER_CLEAR);
9703 bgp_process(bgp, rm, afi, safi);
9704 }
9705 bgp_dest_unlock_node(rm);
9706 }
9707 }
9708 } else {
9709 if ((dest = bgp_node_match(rib, &match)) != NULL) {
9710 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
9711
9712 if (dest_p->prefixlen == match.prefixlen) {
9713 SET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
9714 bgp_process(bgp, dest, afi, safi);
9715 }
9716 bgp_dest_unlock_node(dest);
9717 }
9718 }
9719
9720 return CMD_SUCCESS;
9721 }
9722
9723 /* one clear bgp command to rule them all */
9724 DEFUN (clear_ip_bgp_all,
9725 clear_ip_bgp_all_cmd,
9726 "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>]",
9727 CLEAR_STR
9728 IP_STR
9729 BGP_STR
9730 BGP_INSTANCE_HELP_STR
9731 BGP_AFI_HELP_STR
9732 "Address Family\n"
9733 BGP_SAFI_WITH_LABEL_HELP_STR
9734 "Address Family modifier\n"
9735 "Clear all peers\n"
9736 "BGP IPv4 neighbor to clear\n"
9737 "BGP IPv6 neighbor to clear\n"
9738 "BGP neighbor on interface to clear\n"
9739 "Clear peers with the AS number\n"
9740 "Clear all external peers\n"
9741 "Clear all members of peer-group\n"
9742 "BGP peer-group name\n"
9743 BGP_SOFT_STR
9744 BGP_SOFT_IN_STR
9745 BGP_SOFT_OUT_STR
9746 BGP_SOFT_IN_STR
9747 "Push out prefix-list ORF and do inbound soft reconfig\n"
9748 BGP_SOFT_OUT_STR)
9749 {
9750 char *vrf = NULL;
9751
9752 afi_t afi = AFI_UNSPEC;
9753 safi_t safi = SAFI_UNSPEC;
9754 enum clear_sort clr_sort = clear_peer;
9755 enum bgp_clear_type clr_type;
9756 char *clr_arg = NULL;
9757
9758 int idx = 0;
9759 char errmsg[BUFSIZ] = {'\0'};
9760 int ret;
9761
9762 /* clear [ip] bgp */
9763 if (argv_find(argv, argc, "ip", &idx))
9764 afi = AFI_IP;
9765
9766 /* [<vrf> VIEWVRFNAME] */
9767 if (argv_find(argv, argc, "vrf", &idx)) {
9768 vrf = argv[idx + 1]->arg;
9769 idx += 2;
9770 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9771 vrf = NULL;
9772 } else if (argv_find(argv, argc, "view", &idx)) {
9773 /* [<view> VIEWVRFNAME] */
9774 vrf = argv[idx + 1]->arg;
9775 idx += 2;
9776 }
9777 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
9778 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
9779 argv_find_and_parse_safi(argv, argc, &idx, &safi);
9780
9781 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
9782 if (argv_find(argv, argc, "*", &idx)) {
9783 clr_sort = clear_all;
9784 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
9785 clr_sort = clear_peer;
9786 clr_arg = argv[idx]->arg;
9787 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
9788 clr_sort = clear_peer;
9789 clr_arg = argv[idx]->arg;
9790 } else if (argv_find(argv, argc, "peer-group", &idx)) {
9791 clr_sort = clear_group;
9792 idx++;
9793 clr_arg = argv[idx]->arg;
9794 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
9795 clr_sort = clear_peer;
9796 clr_arg = argv[idx]->arg;
9797 } else if (argv_find(argv, argc, "WORD", &idx)) {
9798 clr_sort = clear_peer;
9799 clr_arg = argv[idx]->arg;
9800 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
9801 clr_sort = clear_as;
9802 clr_arg = argv[idx]->arg;
9803 } else if (argv_find(argv, argc, "external", &idx)) {
9804 clr_sort = clear_external;
9805 }
9806
9807 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
9808 if (argv_find(argv, argc, "soft", &idx)) {
9809 if (argv_find(argv, argc, "in", &idx)
9810 || argv_find(argv, argc, "out", &idx))
9811 clr_type = strmatch(argv[idx]->text, "in")
9812 ? BGP_CLEAR_SOFT_IN
9813 : BGP_CLEAR_SOFT_OUT;
9814 else
9815 clr_type = BGP_CLEAR_SOFT_BOTH;
9816 } else if (argv_find(argv, argc, "in", &idx)) {
9817 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
9818 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
9819 : BGP_CLEAR_SOFT_IN;
9820 } else if (argv_find(argv, argc, "out", &idx)) {
9821 clr_type = BGP_CLEAR_SOFT_OUT;
9822 } else
9823 clr_type = BGP_CLEAR_SOFT_NONE;
9824
9825 ret = bgp_clear_vty(vrf, afi, safi, clr_sort, clr_type, clr_arg, errmsg,
9826 sizeof(errmsg));
9827 if (ret != NB_OK)
9828 vty_out(vty, "Error description: %s\n", errmsg);
9829
9830 return ret;
9831 }
9832
9833 DEFUN (clear_ip_bgp_prefix,
9834 clear_ip_bgp_prefix_cmd,
9835 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
9836 CLEAR_STR
9837 IP_STR
9838 BGP_STR
9839 BGP_INSTANCE_HELP_STR
9840 "Clear bestpath and re-advertise\n"
9841 "IPv4 prefix\n")
9842 {
9843 char *vrf = NULL;
9844 char *prefix = NULL;
9845
9846 int idx = 0;
9847
9848 /* [<view|vrf> VIEWVRFNAME] */
9849 if (argv_find(argv, argc, "vrf", &idx)) {
9850 vrf = argv[idx + 1]->arg;
9851 idx += 2;
9852 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9853 vrf = NULL;
9854 } else if (argv_find(argv, argc, "view", &idx)) {
9855 /* [<view> VIEWVRFNAME] */
9856 vrf = argv[idx + 1]->arg;
9857 idx += 2;
9858 }
9859
9860 prefix = argv[argc - 1]->arg;
9861
9862 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
9863 }
9864
9865 DEFUN (clear_bgp_ipv6_safi_prefix,
9866 clear_bgp_ipv6_safi_prefix_cmd,
9867 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
9868 CLEAR_STR
9869 IP_STR
9870 BGP_STR
9871 "Address Family\n"
9872 BGP_SAFI_HELP_STR
9873 "Clear bestpath and re-advertise\n"
9874 "IPv6 prefix\n")
9875 {
9876 int idx_safi = 0;
9877 int idx_ipv6_prefix = 0;
9878 safi_t safi = SAFI_UNICAST;
9879 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
9880 argv[idx_ipv6_prefix]->arg : NULL;
9881
9882 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
9883 return bgp_clear_prefix(
9884 vty, NULL, prefix, AFI_IP6,
9885 safi, NULL);
9886 }
9887
9888 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
9889 clear_bgp_instance_ipv6_safi_prefix_cmd,
9890 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
9891 CLEAR_STR
9892 IP_STR
9893 BGP_STR
9894 BGP_INSTANCE_HELP_STR
9895 "Address Family\n"
9896 BGP_SAFI_HELP_STR
9897 "Clear bestpath and re-advertise\n"
9898 "IPv6 prefix\n")
9899 {
9900 int idx_safi = 0;
9901 int idx_vrfview = 0;
9902 int idx_ipv6_prefix = 0;
9903 safi_t safi = SAFI_UNICAST;
9904 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
9905 argv[idx_ipv6_prefix]->arg : NULL;
9906 char *vrfview = NULL;
9907
9908 /* [<view|vrf> VIEWVRFNAME] */
9909 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
9910 vrfview = argv[idx_vrfview + 1]->arg;
9911 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
9912 vrfview = NULL;
9913 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
9914 /* [<view> VIEWVRFNAME] */
9915 vrfview = argv[idx_vrfview + 1]->arg;
9916 }
9917 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
9918
9919 return bgp_clear_prefix(
9920 vty, vrfview, prefix,
9921 AFI_IP6, safi, NULL);
9922 }
9923
9924 DEFUN (show_bgp_views,
9925 show_bgp_views_cmd,
9926 "show [ip] bgp views",
9927 SHOW_STR
9928 IP_STR
9929 BGP_STR
9930 "Show the defined BGP views\n")
9931 {
9932 struct list *inst = bm->bgp;
9933 struct listnode *node;
9934 struct bgp *bgp;
9935
9936 vty_out(vty, "Defined BGP views:\n");
9937 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
9938 /* Skip VRFs. */
9939 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
9940 continue;
9941 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
9942 bgp->as);
9943 }
9944
9945 return CMD_SUCCESS;
9946 }
9947
9948 DEFUN (show_bgp_vrfs,
9949 show_bgp_vrfs_cmd,
9950 "show [ip] bgp vrfs [json]",
9951 SHOW_STR
9952 IP_STR
9953 BGP_STR
9954 "Show BGP VRFs\n"
9955 JSON_STR)
9956 {
9957 char buf[ETHER_ADDR_STRLEN];
9958 struct list *inst = bm->bgp;
9959 struct listnode *node;
9960 struct bgp *bgp;
9961 bool uj = use_json(argc, argv);
9962 json_object *json = NULL;
9963 json_object *json_vrfs = NULL;
9964 int count = 0;
9965
9966 if (uj) {
9967 json = json_object_new_object();
9968 json_vrfs = json_object_new_object();
9969 }
9970
9971 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
9972 const char *name, *type;
9973 struct peer *peer;
9974 struct listnode *node2, *nnode2;
9975 int peers_cfg, peers_estb;
9976 json_object *json_vrf = NULL;
9977
9978 /* Skip Views. */
9979 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
9980 continue;
9981
9982 count++;
9983 if (!uj && count == 1) {
9984 vty_out(vty,
9985 "%4s %-5s %-16s %9s %10s %-37s\n",
9986 "Type", "Id", "routerId", "#PeersCfg",
9987 "#PeersEstb", "Name");
9988 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
9989 "L3-VNI", "RouterMAC", "Interface");
9990 }
9991
9992 peers_cfg = peers_estb = 0;
9993 if (uj)
9994 json_vrf = json_object_new_object();
9995
9996
9997 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
9998 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
9999 continue;
10000 peers_cfg++;
10001 if (peer->status == Established)
10002 peers_estb++;
10003 }
10004
10005 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
10006 name = VRF_DEFAULT_NAME;
10007 type = "DFLT";
10008 } else {
10009 name = bgp->name;
10010 type = "VRF";
10011 }
10012
10013
10014 if (uj) {
10015 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10016 ? -1
10017 : (int64_t)bgp->vrf_id;
10018 char buf[BUFSIZ] = {0};
10019
10020 json_object_string_add(json_vrf, "type", type);
10021 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
10022 json_object_string_add(json_vrf, "routerId",
10023 inet_ntop(AF_INET,
10024 &bgp->router_id, buf,
10025 sizeof(buf)));
10026 json_object_int_add(json_vrf, "numConfiguredPeers",
10027 peers_cfg);
10028 json_object_int_add(json_vrf, "numEstablishedPeers",
10029 peers_estb);
10030
10031 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
10032 json_object_string_add(
10033 json_vrf, "rmac",
10034 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
10035 json_object_string_add(json_vrf, "interface",
10036 ifindex2ifname(bgp->l3vni_svi_ifindex,
10037 bgp->vrf_id));
10038 json_object_object_add(json_vrfs, name, json_vrf);
10039 } else {
10040 vty_out(vty, "%4s %-5d %-16pI4 %-9u %-10u %-37s\n",
10041 type,
10042 bgp->vrf_id == VRF_UNKNOWN ? -1
10043 : (int)bgp->vrf_id,
10044 &bgp->router_id, peers_cfg, peers_estb, name);
10045 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
10046 bgp->l3vni,
10047 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
10048 ifindex2ifname(bgp->l3vni_svi_ifindex,
10049 bgp->vrf_id));
10050 }
10051 }
10052
10053 if (uj) {
10054 json_object_object_add(json, "vrfs", json_vrfs);
10055
10056 json_object_int_add(json, "totalVrfs", count);
10057
10058 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10059 json, JSON_C_TO_STRING_PRETTY));
10060 json_object_free(json);
10061 } else {
10062 if (count)
10063 vty_out(vty,
10064 "\nTotal number of VRFs (including default): %d\n",
10065 count);
10066 }
10067
10068 return CMD_SUCCESS;
10069 }
10070
10071 DEFUN (show_bgp_mac_hash,
10072 show_bgp_mac_hash_cmd,
10073 "show bgp mac hash",
10074 SHOW_STR
10075 BGP_STR
10076 "Mac Address\n"
10077 "Mac Address database\n")
10078 {
10079 bgp_mac_dump_table(vty);
10080
10081 return CMD_SUCCESS;
10082 }
10083
10084 static void show_tip_entry(struct hash_bucket *bucket, void *args)
10085 {
10086 struct vty *vty = (struct vty *)args;
10087 struct tip_addr *tip = (struct tip_addr *)bucket->data;
10088
10089 vty_out(vty, "addr: %pI4, count: %d\n", &tip->addr, tip->refcnt);
10090 }
10091
10092 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
10093 {
10094 vty_out(vty, "self nexthop database:\n");
10095 bgp_nexthop_show_address_hash(vty, bgp);
10096
10097 vty_out(vty, "Tunnel-ip database:\n");
10098 hash_iterate(bgp->tip_hash,
10099 (void (*)(struct hash_bucket *, void *))show_tip_entry,
10100 vty);
10101 }
10102
10103 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
10104 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
10105 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
10106 "martian next-hops\n"
10107 "martian next-hop database\n")
10108 {
10109 struct bgp *bgp = NULL;
10110 int idx = 0;
10111 char *name = NULL;
10112
10113 /* [<vrf> VIEWVRFNAME] */
10114 if (argv_find(argv, argc, "vrf", &idx)) {
10115 name = argv[idx + 1]->arg;
10116 if (name && strmatch(name, VRF_DEFAULT_NAME))
10117 name = NULL;
10118 } else if (argv_find(argv, argc, "view", &idx))
10119 /* [<view> VIEWVRFNAME] */
10120 name = argv[idx + 1]->arg;
10121 if (name)
10122 bgp = bgp_lookup_by_name(name);
10123 else
10124 bgp = bgp_get_default();
10125
10126 if (!bgp) {
10127 vty_out(vty, "%% No BGP process is configured\n");
10128 return CMD_WARNING;
10129 }
10130 bgp_show_martian_nexthops(vty, bgp);
10131
10132 return CMD_SUCCESS;
10133 }
10134
10135 DEFUN (show_bgp_memory,
10136 show_bgp_memory_cmd,
10137 "show [ip] bgp memory",
10138 SHOW_STR
10139 IP_STR
10140 BGP_STR
10141 "Global BGP memory statistics\n")
10142 {
10143 char memstrbuf[MTYPE_MEMSTR_LEN];
10144 unsigned long count;
10145
10146 /* RIB related usage stats */
10147 count = mtype_stats_alloc(MTYPE_BGP_NODE);
10148 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
10149 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10150 count * sizeof(struct bgp_dest)));
10151
10152 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
10153 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
10154 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10155 count * sizeof(struct bgp_path_info)));
10156 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
10157 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
10158 count,
10159 mtype_memstr(
10160 memstrbuf, sizeof(memstrbuf),
10161 count * sizeof(struct bgp_path_info_extra)));
10162
10163 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
10164 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
10165 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10166 count * sizeof(struct bgp_static)));
10167
10168 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
10169 vty_out(vty, "%ld Packets, using %s of memory\n", count,
10170 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10171 count * sizeof(struct bpacket)));
10172
10173 /* Adj-In/Out */
10174 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
10175 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
10176 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10177 count * sizeof(struct bgp_adj_in)));
10178 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
10179 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
10180 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10181 count * sizeof(struct bgp_adj_out)));
10182
10183 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
10184 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
10185 count,
10186 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10187 count * sizeof(struct bgp_nexthop_cache)));
10188
10189 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
10190 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
10191 count,
10192 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10193 count * sizeof(struct bgp_damp_info)));
10194
10195 /* Attributes */
10196 count = attr_count();
10197 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
10198 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10199 count * sizeof(struct attr)));
10200
10201 if ((count = attr_unknown_count()))
10202 vty_out(vty, "%ld unknown attributes\n", count);
10203
10204 /* AS_PATH attributes */
10205 count = aspath_count();
10206 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
10207 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10208 count * sizeof(struct aspath)));
10209
10210 count = mtype_stats_alloc(MTYPE_AS_SEG);
10211 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
10212 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10213 count * sizeof(struct assegment)));
10214
10215 /* Other attributes */
10216 if ((count = community_count()))
10217 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
10218 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10219 count * sizeof(struct community)));
10220 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
10221 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
10222 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10223 count * sizeof(struct ecommunity)));
10224 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
10225 vty_out(vty,
10226 "%ld BGP large-community entries, using %s of memory\n",
10227 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10228 count * sizeof(struct lcommunity)));
10229
10230 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
10231 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
10232 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10233 count * sizeof(struct cluster_list)));
10234
10235 /* Peer related usage */
10236 count = mtype_stats_alloc(MTYPE_BGP_PEER);
10237 vty_out(vty, "%ld peers, using %s of memory\n", count,
10238 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10239 count * sizeof(struct peer)));
10240
10241 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
10242 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
10243 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10244 count * sizeof(struct peer_group)));
10245
10246 /* Other */
10247 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
10248 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
10249 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10250 count * sizeof(regex_t)));
10251 return CMD_SUCCESS;
10252 }
10253
10254 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
10255 {
10256 json_object *bestpath = json_object_new_object();
10257
10258 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
10259 json_object_string_add(bestpath, "asPath", "ignore");
10260
10261 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
10262 json_object_string_add(bestpath, "asPath", "confed");
10263
10264 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
10265 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
10266 json_object_string_add(bestpath, "multiPathRelax",
10267 "as-set");
10268 else
10269 json_object_string_add(bestpath, "multiPathRelax",
10270 "true");
10271 } else
10272 json_object_string_add(bestpath, "multiPathRelax", "false");
10273
10274 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
10275 json_object_string_add(bestpath, "compareRouterId", "true");
10276 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
10277 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
10278 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
10279 json_object_string_add(bestpath, "med", "confed");
10280 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
10281 json_object_string_add(bestpath, "med",
10282 "missing-as-worst");
10283 else
10284 json_object_string_add(bestpath, "med", "true");
10285 }
10286
10287 json_object_object_add(json, "bestPath", bestpath);
10288 }
10289
10290 /* Print the error code/subcode for why the peer is down */
10291 static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
10292 json_object *json_peer, bool use_json)
10293 {
10294 const char *code_str;
10295 const char *subcode_str;
10296
10297 if (use_json) {
10298 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10299 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10300 char errorcodesubcode_hexstr[5];
10301 char errorcodesubcode_str[256];
10302
10303 code_str = bgp_notify_code_str(peer->notify.code);
10304 subcode_str = bgp_notify_subcode_str(
10305 peer->notify.code,
10306 peer->notify.subcode);
10307
10308 snprintf(errorcodesubcode_hexstr,
10309 sizeof(errorcodesubcode_hexstr), "%02X%02X",
10310 peer->notify.code, peer->notify.subcode);
10311 json_object_string_add(json_peer,
10312 "lastErrorCodeSubcode",
10313 errorcodesubcode_hexstr);
10314 snprintf(errorcodesubcode_str, 255, "%s%s",
10315 code_str, subcode_str);
10316 json_object_string_add(json_peer,
10317 "lastNotificationReason",
10318 errorcodesubcode_str);
10319 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10320 && peer->notify.code == BGP_NOTIFY_CEASE
10321 && (peer->notify.subcode
10322 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10323 || peer->notify.subcode
10324 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10325 && peer->notify.length) {
10326 char msgbuf[1024];
10327 const char *msg_str;
10328
10329 msg_str = bgp_notify_admin_message(
10330 msgbuf, sizeof(msgbuf),
10331 (uint8_t *)peer->notify.data,
10332 peer->notify.length);
10333 if (msg_str)
10334 json_object_string_add(
10335 json_peer,
10336 "lastShutdownDescription",
10337 msg_str);
10338 }
10339
10340 }
10341 json_object_string_add(json_peer, "lastResetDueTo",
10342 peer_down_str[(int)peer->last_reset]);
10343 json_object_int_add(json_peer, "lastResetCode",
10344 peer->last_reset);
10345 } else {
10346 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10347 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10348 code_str = bgp_notify_code_str(peer->notify.code);
10349 subcode_str =
10350 bgp_notify_subcode_str(peer->notify.code,
10351 peer->notify.subcode);
10352 vty_out(vty, " Notification %s (%s%s)\n",
10353 peer->last_reset == PEER_DOWN_NOTIFY_SEND
10354 ? "sent"
10355 : "received",
10356 code_str, subcode_str);
10357 } else {
10358 vty_out(vty, " %s\n",
10359 peer_down_str[(int)peer->last_reset]);
10360 }
10361 }
10362 }
10363
10364 static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
10365 safi_t safi)
10366 {
10367 return ((peer->status != Established) ||
10368 !peer->afc_recv[afi][safi]);
10369 }
10370
10371 static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
10372 struct peer *peer, json_object *json_peer,
10373 int max_neighbor_width, bool use_json)
10374 {
10375 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10376 int len;
10377
10378 if (use_json) {
10379 if (peer_dynamic_neighbor(peer))
10380 json_object_boolean_true_add(json_peer,
10381 "dynamicPeer");
10382 if (peer->hostname)
10383 json_object_string_add(json_peer, "hostname",
10384 peer->hostname);
10385
10386 if (peer->domainname)
10387 json_object_string_add(json_peer, "domainname",
10388 peer->domainname);
10389 json_object_int_add(json_peer, "connectionsEstablished",
10390 peer->established);
10391 json_object_int_add(json_peer, "connectionsDropped",
10392 peer->dropped);
10393 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10394 use_json, json_peer);
10395 if (peer->status == Established)
10396 json_object_string_add(json_peer, "lastResetDueTo",
10397 "AFI/SAFI Not Negotiated");
10398 else
10399 bgp_show_peer_reset(NULL, peer, json_peer, true);
10400 } else {
10401 dn_flag[1] = '\0';
10402 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
10403 if (peer->hostname
10404 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
10405 len = vty_out(vty, "%s%s(%s)", dn_flag,
10406 peer->hostname, peer->host);
10407 else
10408 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10409
10410 /* pad the neighbor column with spaces */
10411 if (len < max_neighbor_width)
10412 vty_out(vty, "%*s", max_neighbor_width - len,
10413 " ");
10414 vty_out(vty, "%7d %7d %9s", peer->established,
10415 peer->dropped,
10416 peer_uptime(peer->uptime, timebuf,
10417 BGP_UPTIME_LEN, 0, NULL));
10418 if (peer->status == Established)
10419 vty_out(vty, " AFI/SAFI Not Negotiated\n");
10420 else
10421 bgp_show_peer_reset(vty, peer, NULL,
10422 false);
10423 }
10424 }
10425
10426
10427 /* Show BGP peer's summary information. */
10428 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
10429 bool show_failed, bool show_established,
10430 bool use_json)
10431 {
10432 struct peer *peer;
10433 struct listnode *node, *nnode;
10434 unsigned int count = 0, dn_count = 0;
10435 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10436 char neighbor_buf[VTY_BUFSIZ];
10437 int neighbor_col_default_width = 16;
10438 int len, failed_count = 0;
10439 int max_neighbor_width = 0;
10440 int pfx_rcd_safi;
10441 json_object *json = NULL;
10442 json_object *json_peer = NULL;
10443 json_object *json_peers = NULL;
10444 struct peer_af *paf;
10445 struct bgp_filter *filter;
10446
10447 /* labeled-unicast routes are installed in the unicast table so in order
10448 * to
10449 * display the correct PfxRcd value we must look at SAFI_UNICAST
10450 */
10451
10452 if (safi == SAFI_LABELED_UNICAST)
10453 pfx_rcd_safi = SAFI_UNICAST;
10454 else
10455 pfx_rcd_safi = safi;
10456
10457 if (use_json) {
10458 json = json_object_new_object();
10459 json_peers = json_object_new_object();
10460 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10461 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10462 continue;
10463
10464 if (peer->afc[afi][safi]) {
10465 /* See if we have at least a single failed peer */
10466 if (bgp_has_peer_failed(peer, afi, safi))
10467 failed_count++;
10468 count++;
10469 }
10470 if (peer_dynamic_neighbor(peer))
10471 dn_count++;
10472 }
10473
10474 } else {
10475 /* Loop over all neighbors that will be displayed to determine
10476 * how many
10477 * characters are needed for the Neighbor column
10478 */
10479 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10480 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10481 continue;
10482
10483 if (peer->afc[afi][safi]) {
10484 memset(dn_flag, '\0', sizeof(dn_flag));
10485 if (peer_dynamic_neighbor(peer))
10486 dn_flag[0] = '*';
10487
10488 if (peer->hostname
10489 && CHECK_FLAG(bgp->flags,
10490 BGP_FLAG_SHOW_HOSTNAME))
10491 snprintf(neighbor_buf,
10492 sizeof(neighbor_buf),
10493 "%s%s(%s) ", dn_flag,
10494 peer->hostname, peer->host);
10495 else
10496 snprintf(neighbor_buf,
10497 sizeof(neighbor_buf), "%s%s ",
10498 dn_flag, peer->host);
10499
10500 len = strlen(neighbor_buf);
10501
10502 if (len > max_neighbor_width)
10503 max_neighbor_width = len;
10504
10505 /* See if we have at least a single failed peer */
10506 if (bgp_has_peer_failed(peer, afi, safi))
10507 failed_count++;
10508 count++;
10509 }
10510 }
10511
10512 /* Originally we displayed the Neighbor column as 16
10513 * characters wide so make that the default
10514 */
10515 if (max_neighbor_width < neighbor_col_default_width)
10516 max_neighbor_width = neighbor_col_default_width;
10517 }
10518
10519 if (show_failed && !failed_count) {
10520 if (use_json) {
10521 json_object_int_add(json, "failedPeersCount", 0);
10522 json_object_int_add(json, "dynamicPeers", dn_count);
10523 json_object_int_add(json, "totalPeers", count);
10524
10525 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10526 json, JSON_C_TO_STRING_PRETTY));
10527 json_object_free(json);
10528 } else {
10529 vty_out(vty, "%% No failed BGP neighbors found\n");
10530 vty_out(vty, "\nTotal number of neighbors %d\n", count);
10531 }
10532 return CMD_SUCCESS;
10533 }
10534
10535 count = 0; /* Reset the value as its used again */
10536 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10537 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10538 continue;
10539
10540 if (!peer->afc[afi][safi])
10541 continue;
10542
10543 if (!count) {
10544 unsigned long ents;
10545 char memstrbuf[MTYPE_MEMSTR_LEN];
10546 int64_t vrf_id_ui;
10547
10548 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10549 ? -1
10550 : (int64_t)bgp->vrf_id;
10551
10552 /* Usage summary and header */
10553 if (use_json) {
10554 char buf[BUFSIZ] = {0};
10555
10556 json_object_string_add(
10557 json, "routerId",
10558 inet_ntop(AF_INET, &bgp->router_id, buf,
10559 sizeof(buf)));
10560 json_object_int_add(json, "as", bgp->as);
10561 json_object_int_add(json, "vrfId", vrf_id_ui);
10562 json_object_string_add(
10563 json, "vrfName",
10564 (bgp->inst_type
10565 == BGP_INSTANCE_TYPE_DEFAULT)
10566 ? VRF_DEFAULT_NAME
10567 : bgp->name);
10568 } else {
10569 vty_out(vty,
10570 "BGP router identifier %pI4, local AS number %u vrf-id %d",
10571 &bgp->router_id, bgp->as,
10572 bgp->vrf_id == VRF_UNKNOWN
10573 ? -1
10574 : (int)bgp->vrf_id);
10575 vty_out(vty, "\n");
10576 }
10577
10578 if (bgp_update_delay_configured(bgp)) {
10579 if (use_json) {
10580 json_object_int_add(
10581 json, "updateDelayLimit",
10582 bgp->v_update_delay);
10583
10584 if (bgp->v_update_delay
10585 != bgp->v_establish_wait)
10586 json_object_int_add(
10587 json,
10588 "updateDelayEstablishWait",
10589 bgp->v_establish_wait);
10590
10591 if (bgp_update_delay_active(bgp)) {
10592 json_object_string_add(
10593 json,
10594 "updateDelayFirstNeighbor",
10595 bgp->update_delay_begin_time);
10596 json_object_boolean_true_add(
10597 json,
10598 "updateDelayInProgress");
10599 } else {
10600 if (bgp->update_delay_over) {
10601 json_object_string_add(
10602 json,
10603 "updateDelayFirstNeighbor",
10604 bgp->update_delay_begin_time);
10605 json_object_string_add(
10606 json,
10607 "updateDelayBestpathResumed",
10608 bgp->update_delay_end_time);
10609 json_object_string_add(
10610 json,
10611 "updateDelayZebraUpdateResume",
10612 bgp->update_delay_zebra_resume_time);
10613 json_object_string_add(
10614 json,
10615 "updateDelayPeerUpdateResume",
10616 bgp->update_delay_peers_resume_time);
10617 }
10618 }
10619 } else {
10620 vty_out(vty,
10621 "Read-only mode update-delay limit: %d seconds\n",
10622 bgp->v_update_delay);
10623 if (bgp->v_update_delay
10624 != bgp->v_establish_wait)
10625 vty_out(vty,
10626 " Establish wait: %d seconds\n",
10627 bgp->v_establish_wait);
10628
10629 if (bgp_update_delay_active(bgp)) {
10630 vty_out(vty,
10631 " First neighbor established: %s\n",
10632 bgp->update_delay_begin_time);
10633 vty_out(vty,
10634 " Delay in progress\n");
10635 } else {
10636 if (bgp->update_delay_over) {
10637 vty_out(vty,
10638 " First neighbor established: %s\n",
10639 bgp->update_delay_begin_time);
10640 vty_out(vty,
10641 " Best-paths resumed: %s\n",
10642 bgp->update_delay_end_time);
10643 vty_out(vty,
10644 " zebra update resumed: %s\n",
10645 bgp->update_delay_zebra_resume_time);
10646 vty_out(vty,
10647 " peers update resumed: %s\n",
10648 bgp->update_delay_peers_resume_time);
10649 }
10650 }
10651 }
10652 }
10653
10654 if (use_json) {
10655 if (bgp_maxmed_onstartup_configured(bgp)
10656 && bgp->maxmed_active)
10657 json_object_boolean_true_add(
10658 json, "maxMedOnStartup");
10659 if (bgp->v_maxmed_admin)
10660 json_object_boolean_true_add(
10661 json, "maxMedAdministrative");
10662
10663 json_object_int_add(
10664 json, "tableVersion",
10665 bgp_table_version(bgp->rib[afi][safi]));
10666
10667 ents = bgp_table_count(bgp->rib[afi][safi]);
10668 json_object_int_add(json, "ribCount", ents);
10669 json_object_int_add(
10670 json, "ribMemory",
10671 ents * sizeof(struct bgp_dest));
10672
10673 ents = bgp->af_peer_count[afi][safi];
10674 json_object_int_add(json, "peerCount", ents);
10675 json_object_int_add(json, "peerMemory",
10676 ents * sizeof(struct peer));
10677
10678 if ((ents = listcount(bgp->group))) {
10679 json_object_int_add(
10680 json, "peerGroupCount", ents);
10681 json_object_int_add(
10682 json, "peerGroupMemory",
10683 ents * sizeof(struct
10684 peer_group));
10685 }
10686
10687 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10688 BGP_CONFIG_DAMPENING))
10689 json_object_boolean_true_add(
10690 json, "dampeningEnabled");
10691 } else {
10692 if (bgp_maxmed_onstartup_configured(bgp)
10693 && bgp->maxmed_active)
10694 vty_out(vty,
10695 "Max-med on-startup active\n");
10696 if (bgp->v_maxmed_admin)
10697 vty_out(vty,
10698 "Max-med administrative active\n");
10699
10700 vty_out(vty, "BGP table version %" PRIu64 "\n",
10701 bgp_table_version(bgp->rib[afi][safi]));
10702
10703 ents = bgp_table_count(bgp->rib[afi][safi]);
10704 vty_out(vty,
10705 "RIB entries %ld, using %s of memory\n",
10706 ents,
10707 mtype_memstr(
10708 memstrbuf, sizeof(memstrbuf),
10709 ents
10710 * sizeof(struct
10711 bgp_dest)));
10712
10713 /* Peer related usage */
10714 ents = bgp->af_peer_count[afi][safi];
10715 vty_out(vty, "Peers %ld, using %s of memory\n",
10716 ents,
10717 mtype_memstr(
10718 memstrbuf, sizeof(memstrbuf),
10719 ents * sizeof(struct peer)));
10720
10721 if ((ents = listcount(bgp->group)))
10722 vty_out(vty,
10723 "Peer groups %ld, using %s of memory\n",
10724 ents,
10725 mtype_memstr(
10726 memstrbuf,
10727 sizeof(memstrbuf),
10728 ents * sizeof(struct
10729 peer_group)));
10730
10731 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10732 BGP_CONFIG_DAMPENING))
10733 vty_out(vty, "Dampening enabled.\n");
10734 vty_out(vty, "\n");
10735
10736 /* Subtract 8 here because 'Neighbor' is
10737 * 8 characters */
10738 vty_out(vty, "Neighbor");
10739 vty_out(vty, "%*s", max_neighbor_width - 8,
10740 " ");
10741 if (show_failed)
10742 vty_out(vty, "EstdCnt DropCnt ResetTime Reason\n");
10743 else
10744 vty_out(vty,
10745 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd PfxSnt\n");
10746 }
10747 }
10748
10749 paf = peer_af_find(peer, afi, safi);
10750 filter = &peer->filter[afi][safi];
10751
10752 count++;
10753 /* Works for both failed & successful cases */
10754 if (peer_dynamic_neighbor(peer))
10755 dn_count++;
10756
10757 if (use_json) {
10758 json_peer = NULL;
10759
10760 if (show_failed &&
10761 bgp_has_peer_failed(peer, afi, safi)) {
10762 json_peer = json_object_new_object();
10763 bgp_show_failed_summary(vty, bgp, peer,
10764 json_peer, 0, use_json);
10765 } else if (!show_failed) {
10766 if (show_established
10767 && bgp_has_peer_failed(peer, afi, safi))
10768 continue;
10769
10770 json_peer = json_object_new_object();
10771 if (peer_dynamic_neighbor(peer)) {
10772 json_object_boolean_true_add(json_peer,
10773 "dynamicPeer");
10774 }
10775
10776 if (peer->hostname)
10777 json_object_string_add(json_peer, "hostname",
10778 peer->hostname);
10779
10780 if (peer->domainname)
10781 json_object_string_add(json_peer, "domainname",
10782 peer->domainname);
10783
10784 json_object_int_add(json_peer, "remoteAs", peer->as);
10785 json_object_int_add(json_peer, "version", 4);
10786 json_object_int_add(json_peer, "msgRcvd",
10787 PEER_TOTAL_RX(peer));
10788 json_object_int_add(json_peer, "msgSent",
10789 PEER_TOTAL_TX(peer));
10790
10791 atomic_size_t outq_count, inq_count;
10792 outq_count = atomic_load_explicit(
10793 &peer->obuf->count,
10794 memory_order_relaxed);
10795 inq_count = atomic_load_explicit(
10796 &peer->ibuf->count,
10797 memory_order_relaxed);
10798
10799 json_object_int_add(json_peer, "tableVersion",
10800 peer->version[afi][safi]);
10801 json_object_int_add(json_peer, "outq",
10802 outq_count);
10803 json_object_int_add(json_peer, "inq",
10804 inq_count);
10805 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10806 use_json, json_peer);
10807
10808 json_object_int_add(json_peer, "pfxRcd",
10809 peer->pcount[afi][pfx_rcd_safi]);
10810
10811 if (paf && PAF_SUBGRP(paf))
10812 json_object_int_add(
10813 json_peer, "pfxSnt",
10814 (PAF_SUBGRP(paf))->scount);
10815 else
10816 json_object_int_add(json_peer, "pfxSnt",
10817 0);
10818
10819 /* BGP FSM state */
10820 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
10821 || CHECK_FLAG(peer->bgp->flags,
10822 BGP_FLAG_SHUTDOWN))
10823 json_object_string_add(json_peer,
10824 "state",
10825 "Idle (Admin)");
10826 else if (peer->afc_recv[afi][safi])
10827 json_object_string_add(
10828 json_peer, "state",
10829 lookup_msg(bgp_status_msg,
10830 peer->status, NULL));
10831 else if (CHECK_FLAG(
10832 peer->sflags,
10833 PEER_STATUS_PREFIX_OVERFLOW))
10834 json_object_string_add(json_peer,
10835 "state",
10836 "Idle (PfxCt)");
10837 else
10838 json_object_string_add(
10839 json_peer, "state",
10840 lookup_msg(bgp_status_msg,
10841 peer->status, NULL));
10842
10843 /* BGP peer state */
10844 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
10845 || CHECK_FLAG(peer->bgp->flags,
10846 BGP_FLAG_SHUTDOWN))
10847 json_object_string_add(json_peer,
10848 "peerState",
10849 "Admin");
10850 else if (CHECK_FLAG(
10851 peer->sflags,
10852 PEER_STATUS_PREFIX_OVERFLOW))
10853 json_object_string_add(json_peer,
10854 "peerState",
10855 "PfxCt");
10856 else if (CHECK_FLAG(peer->flags,
10857 PEER_FLAG_PASSIVE))
10858 json_object_string_add(json_peer,
10859 "peerState",
10860 "Passive");
10861 else if (CHECK_FLAG(peer->sflags,
10862 PEER_STATUS_NSF_WAIT))
10863 json_object_string_add(json_peer,
10864 "peerState",
10865 "NSF passive");
10866 else if (CHECK_FLAG(
10867 peer->bgp->flags,
10868 BGP_FLAG_EBGP_REQUIRES_POLICY)
10869 && (!bgp_inbound_policy_exists(peer,
10870 filter)
10871 || !bgp_outbound_policy_exists(
10872 peer, filter)))
10873 json_object_string_add(json_peer,
10874 "peerState",
10875 "Policy");
10876 else
10877 json_object_string_add(
10878 json_peer, "peerState", "OK");
10879
10880 json_object_int_add(json_peer, "connectionsEstablished",
10881 peer->established);
10882 json_object_int_add(json_peer, "connectionsDropped",
10883 peer->dropped);
10884 }
10885 /* Avoid creating empty peer dicts in JSON */
10886 if (json_peer == NULL)
10887 continue;
10888
10889 if (peer->conf_if)
10890 json_object_string_add(json_peer, "idType",
10891 "interface");
10892 else if (peer->su.sa.sa_family == AF_INET)
10893 json_object_string_add(json_peer, "idType",
10894 "ipv4");
10895 else if (peer->su.sa.sa_family == AF_INET6)
10896 json_object_string_add(json_peer, "idType",
10897 "ipv6");
10898 json_object_object_add(json_peers, peer->host,
10899 json_peer);
10900 } else {
10901 if (show_failed &&
10902 bgp_has_peer_failed(peer, afi, safi)) {
10903 bgp_show_failed_summary(vty, bgp, peer, NULL,
10904 max_neighbor_width,
10905 use_json);
10906 } else if (!show_failed) {
10907 if (show_established
10908 && bgp_has_peer_failed(peer, afi, safi))
10909 continue;
10910
10911 memset(dn_flag, '\0', sizeof(dn_flag));
10912 if (peer_dynamic_neighbor(peer)) {
10913 dn_flag[0] = '*';
10914 }
10915
10916 if (peer->hostname
10917 && CHECK_FLAG(bgp->flags,
10918 BGP_FLAG_SHOW_HOSTNAME))
10919 len = vty_out(vty, "%s%s(%s)", dn_flag,
10920 peer->hostname,
10921 peer->host);
10922 else
10923 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10924
10925 /* pad the neighbor column with spaces */
10926 if (len < max_neighbor_width)
10927 vty_out(vty, "%*s", max_neighbor_width - len,
10928 " ");
10929
10930 atomic_size_t outq_count, inq_count;
10931 outq_count = atomic_load_explicit(
10932 &peer->obuf->count,
10933 memory_order_relaxed);
10934 inq_count = atomic_load_explicit(
10935 &peer->ibuf->count,
10936 memory_order_relaxed);
10937
10938 vty_out(vty,
10939 "4 %10u %9u %9u %8" PRIu64" %4zu %4zu %8s",
10940 peer->as, PEER_TOTAL_RX(peer),
10941 PEER_TOTAL_TX(peer),
10942 peer->version[afi][safi], inq_count,
10943 outq_count,
10944 peer_uptime(peer->uptime, timebuf,
10945 BGP_UPTIME_LEN, 0, NULL));
10946
10947 if (peer->status == Established) {
10948 if (peer->afc_recv[afi][safi]) {
10949 if (CHECK_FLAG(
10950 bgp->flags,
10951 BGP_FLAG_EBGP_REQUIRES_POLICY)
10952 && !bgp_inbound_policy_exists(
10953 peer, filter))
10954 vty_out(vty, " %12s",
10955 "(Policy)");
10956 else
10957 vty_out(vty,
10958 " %12u",
10959 peer->pcount
10960 [afi]
10961 [pfx_rcd_safi]);
10962 } else {
10963 vty_out(vty, " NoNeg");
10964 }
10965
10966 if (paf && PAF_SUBGRP(paf)) {
10967 if (CHECK_FLAG(
10968 bgp->flags,
10969 BGP_FLAG_EBGP_REQUIRES_POLICY)
10970 && !bgp_outbound_policy_exists(
10971 peer, filter))
10972 vty_out(vty, " %8s",
10973 "(Policy)");
10974 else
10975 vty_out(vty,
10976 " %8u",
10977 (PAF_SUBGRP(
10978 paf))
10979 ->scount);
10980 }
10981 } else {
10982 if (CHECK_FLAG(peer->flags,
10983 PEER_FLAG_SHUTDOWN)
10984 || CHECK_FLAG(peer->bgp->flags,
10985 BGP_FLAG_SHUTDOWN))
10986 vty_out(vty, " Idle (Admin)");
10987 else if (CHECK_FLAG(
10988 peer->sflags,
10989 PEER_STATUS_PREFIX_OVERFLOW))
10990 vty_out(vty, " Idle (PfxCt)");
10991 else
10992 vty_out(vty, " %12s",
10993 lookup_msg(bgp_status_msg,
10994 peer->status, NULL));
10995
10996 vty_out(vty, " %8u", 0);
10997 }
10998 vty_out(vty, "\n");
10999 }
11000
11001 }
11002 }
11003
11004 if (use_json) {
11005 json_object_object_add(json, "peers", json_peers);
11006 json_object_int_add(json, "failedPeers", failed_count);
11007 json_object_int_add(json, "totalPeers", count);
11008 json_object_int_add(json, "dynamicPeers", dn_count);
11009
11010 if (!show_failed)
11011 bgp_show_bestpath_json(bgp, json);
11012
11013 vty_out(vty, "%s\n", json_object_to_json_string_ext(
11014 json, JSON_C_TO_STRING_PRETTY));
11015 json_object_free(json);
11016 } else {
11017 if (count)
11018 vty_out(vty, "\nTotal number of neighbors %d\n", count);
11019 else {
11020 vty_out(vty, "No %s neighbor is configured\n",
11021 get_afi_safi_str(afi, safi, false));
11022 }
11023
11024 if (dn_count) {
11025 vty_out(vty, "* - dynamic neighbor\n");
11026 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
11027 dn_count, bgp->dynamic_neighbors_limit);
11028 }
11029 }
11030
11031 return CMD_SUCCESS;
11032 }
11033
11034 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
11035 int safi, bool show_failed,
11036 bool show_established, bool use_json)
11037 {
11038 int is_first = 1;
11039 int afi_wildcard = (afi == AFI_MAX);
11040 int safi_wildcard = (safi == SAFI_MAX);
11041 int is_wildcard = (afi_wildcard || safi_wildcard);
11042 bool nbr_output = false;
11043
11044 if (use_json && is_wildcard)
11045 vty_out(vty, "{\n");
11046 if (afi_wildcard)
11047 afi = 1; /* AFI_IP */
11048 while (afi < AFI_MAX) {
11049 if (safi_wildcard)
11050 safi = 1; /* SAFI_UNICAST */
11051 while (safi < SAFI_MAX) {
11052 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
11053 nbr_output = true;
11054
11055 if (is_wildcard) {
11056 /*
11057 * So limit output to those afi/safi
11058 * pairs that
11059 * actualy have something interesting in
11060 * them
11061 */
11062 if (use_json) {
11063 if (!is_first)
11064 vty_out(vty, ",\n");
11065 else
11066 is_first = 0;
11067
11068 vty_out(vty, "\"%s\":",
11069 get_afi_safi_str(afi,
11070 safi,
11071 true));
11072 } else {
11073 vty_out(vty, "\n%s Summary:\n",
11074 get_afi_safi_str(afi,
11075 safi,
11076 false));
11077 }
11078 }
11079 bgp_show_summary(vty, bgp, afi, safi,
11080 show_failed, show_established,
11081 use_json);
11082 }
11083 safi++;
11084 if (!safi_wildcard)
11085 safi = SAFI_MAX;
11086 }
11087 afi++;
11088 if (!afi_wildcard)
11089 afi = AFI_MAX;
11090 }
11091
11092 if (use_json && is_wildcard)
11093 vty_out(vty, "}\n");
11094 else if (!nbr_output) {
11095 if (use_json)
11096 vty_out(vty, "{}\n");
11097 else
11098 vty_out(vty, "%% No BGP neighbors found\n");
11099 }
11100 }
11101
11102 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
11103 safi_t safi, bool show_failed,
11104 bool show_established,
11105 bool use_json)
11106 {
11107 struct listnode *node, *nnode;
11108 struct bgp *bgp;
11109 int is_first = 1;
11110 bool nbr_output = false;
11111
11112 if (use_json)
11113 vty_out(vty, "{\n");
11114
11115 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11116 nbr_output = true;
11117 if (use_json) {
11118 if (!is_first)
11119 vty_out(vty, ",\n");
11120 else
11121 is_first = 0;
11122
11123 vty_out(vty, "\"%s\":",
11124 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11125 ? VRF_DEFAULT_NAME
11126 : bgp->name);
11127 } else {
11128 vty_out(vty, "\nInstance %s:\n",
11129 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11130 ? VRF_DEFAULT_NAME
11131 : bgp->name);
11132 }
11133 bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_failed,
11134 show_established, use_json);
11135 }
11136
11137 if (use_json)
11138 vty_out(vty, "}\n");
11139 else if (!nbr_output)
11140 vty_out(vty, "%% BGP instance not found\n");
11141 }
11142
11143 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
11144 safi_t safi, bool show_failed, bool show_established,
11145 bool use_json)
11146 {
11147 struct bgp *bgp;
11148
11149 if (name) {
11150 if (strmatch(name, "all")) {
11151 bgp_show_all_instances_summary_vty(
11152 vty, afi, safi, show_failed, show_established,
11153 use_json);
11154 return CMD_SUCCESS;
11155 } else {
11156 bgp = bgp_lookup_by_name(name);
11157
11158 if (!bgp) {
11159 if (use_json)
11160 vty_out(vty, "{}\n");
11161 else
11162 vty_out(vty,
11163 "%% BGP instance not found\n");
11164 return CMD_WARNING;
11165 }
11166
11167 bgp_show_summary_afi_safi(vty, bgp, afi, safi,
11168 show_failed, show_established,
11169 use_json);
11170 return CMD_SUCCESS;
11171 }
11172 }
11173
11174 bgp = bgp_get_default();
11175
11176 if (bgp)
11177 bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_failed,
11178 show_established, use_json);
11179 else {
11180 if (use_json)
11181 vty_out(vty, "{}\n");
11182 else
11183 vty_out(vty, "%% BGP instance not found\n");
11184 return CMD_WARNING;
11185 }
11186
11187 return CMD_SUCCESS;
11188 }
11189
11190 /* `show [ip] bgp summary' commands. */
11191 DEFPY (show_ip_bgp_summary,
11192 show_ip_bgp_summary_cmd,
11193 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] [all$all] summary [established|failed] [json$uj]",
11194 SHOW_STR
11195 IP_STR
11196 BGP_STR
11197 BGP_INSTANCE_HELP_STR
11198 BGP_AFI_HELP_STR
11199 BGP_SAFI_WITH_LABEL_HELP_STR
11200 "Display the entries for all address families\n"
11201 "Summary of BGP neighbor status\n"
11202 "Show only sessions in Established state\n"
11203 "Show only sessions not in Established state\n"
11204 JSON_STR)
11205 {
11206 char *vrf = NULL;
11207 afi_t afi = AFI_MAX;
11208 safi_t safi = SAFI_MAX;
11209 bool show_failed = false;
11210 bool show_established = false;
11211
11212 int idx = 0;
11213
11214 /* show [ip] bgp */
11215 if (!all && argv_find(argv, argc, "ip", &idx))
11216 afi = AFI_IP;
11217 /* [<vrf> VIEWVRFNAME] */
11218 if (argv_find(argv, argc, "vrf", &idx)) {
11219 vrf = argv[idx + 1]->arg;
11220 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11221 vrf = NULL;
11222 } else if (argv_find(argv, argc, "view", &idx))
11223 /* [<view> VIEWVRFNAME] */
11224 vrf = argv[idx + 1]->arg;
11225 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11226 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11227 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11228 }
11229
11230 if (argv_find(argv, argc, "failed", &idx))
11231 show_failed = true;
11232 if (argv_find(argv, argc, "established", &idx))
11233 show_established = true;
11234
11235 return bgp_show_summary_vty(vty, vrf, afi, safi, show_failed,
11236 show_established, uj);
11237 }
11238
11239 const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
11240 {
11241 if (for_json)
11242 return get_afi_safi_json_str(afi, safi);
11243 else
11244 return get_afi_safi_vty_str(afi, safi);
11245 }
11246
11247
11248 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
11249 afi_t afi, safi_t safi,
11250 uint16_t adv_smcap, uint16_t adv_rmcap,
11251 uint16_t rcv_smcap, uint16_t rcv_rmcap,
11252 bool use_json, json_object *json_pref)
11253 {
11254 /* Send-Mode */
11255 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11256 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
11257 if (use_json) {
11258 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11259 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11260 json_object_string_add(json_pref, "sendMode",
11261 "advertisedAndReceived");
11262 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11263 json_object_string_add(json_pref, "sendMode",
11264 "advertised");
11265 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11266 json_object_string_add(json_pref, "sendMode",
11267 "received");
11268 } else {
11269 vty_out(vty, " Send-mode: ");
11270 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11271 vty_out(vty, "advertised");
11272 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11273 vty_out(vty, "%sreceived",
11274 CHECK_FLAG(p->af_cap[afi][safi],
11275 adv_smcap)
11276 ? ", "
11277 : "");
11278 vty_out(vty, "\n");
11279 }
11280 }
11281
11282 /* Receive-Mode */
11283 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11284 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
11285 if (use_json) {
11286 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11287 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11288 json_object_string_add(json_pref, "recvMode",
11289 "advertisedAndReceived");
11290 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11291 json_object_string_add(json_pref, "recvMode",
11292 "advertised");
11293 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11294 json_object_string_add(json_pref, "recvMode",
11295 "received");
11296 } else {
11297 vty_out(vty, " Receive-mode: ");
11298 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11299 vty_out(vty, "advertised");
11300 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11301 vty_out(vty, "%sreceived",
11302 CHECK_FLAG(p->af_cap[afi][safi],
11303 adv_rmcap)
11304 ? ", "
11305 : "");
11306 vty_out(vty, "\n");
11307 }
11308 }
11309 }
11310
11311 static void bgp_show_neighnor_graceful_restart_rbit(struct vty *vty,
11312 struct peer *p,
11313 bool use_json,
11314 json_object *json)
11315 {
11316 bool rbit_status = false;
11317
11318 if (!use_json)
11319 vty_out(vty, "\n R bit: ");
11320
11321 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
11322 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
11323 && (p->status == Established)) {
11324
11325 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_BIT_RCV))
11326 rbit_status = true;
11327 else
11328 rbit_status = false;
11329 }
11330
11331 if (rbit_status) {
11332 if (use_json)
11333 json_object_boolean_true_add(json, "rBit");
11334 else
11335 vty_out(vty, "True\n");
11336 } else {
11337 if (use_json)
11338 json_object_boolean_false_add(json, "rBit");
11339 else
11340 vty_out(vty, "False\n");
11341 }
11342 }
11343
11344 static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
11345 struct peer *peer,
11346 bool use_json,
11347 json_object *json)
11348 {
11349 const char *mode = "NotApplicable";
11350
11351 if (!use_json)
11352 vty_out(vty, "\n Remote GR Mode: ");
11353
11354 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
11355 && (peer->status == Established)) {
11356
11357 if ((peer->nsf_af_count == 0)
11358 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11359
11360 mode = "Disable";
11361
11362 } else if (peer->nsf_af_count == 0
11363 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11364
11365 mode = "Helper";
11366
11367 } else if (peer->nsf_af_count != 0
11368 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11369
11370 mode = "Restart";
11371 }
11372 }
11373
11374 if (use_json) {
11375 json_object_string_add(json, "remoteGrMode", mode);
11376 } else
11377 vty_out(vty, mode, "\n");
11378 }
11379
11380 static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
11381 struct peer *p,
11382 bool use_json,
11383 json_object *json)
11384 {
11385 const char *mode = "Invalid";
11386
11387 if (!use_json)
11388 vty_out(vty, " Local GR Mode: ");
11389
11390 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
11391 mode = "Helper";
11392 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
11393 mode = "Restart";
11394 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
11395 mode = "Disable";
11396 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
11397 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
11398 mode = "Helper*";
11399 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
11400 mode = "Restart*";
11401 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
11402 mode = "Disable*";
11403 else
11404 mode = "Invalid*";
11405 }
11406
11407 if (use_json) {
11408 json_object_string_add(json, "localGrMode", mode);
11409 } else {
11410 vty_out(vty, mode, "\n");
11411 }
11412 }
11413
11414 static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
11415 struct vty *vty, struct peer *peer, bool use_json, json_object *json)
11416 {
11417 afi_t afi;
11418 safi_t safi;
11419 json_object *json_afi_safi = NULL;
11420 json_object *json_timer = NULL;
11421 json_object *json_endofrib_status = NULL;
11422 bool eor_flag = false;
11423
11424 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
11425 for (safi = SAFI_UNICAST; safi <= SAFI_MPLS_VPN; safi++) {
11426 if (!peer->afc[afi][safi])
11427 continue;
11428
11429 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
11430 || !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
11431 continue;
11432
11433 if (use_json) {
11434 json_afi_safi = json_object_new_object();
11435 json_endofrib_status = json_object_new_object();
11436 json_timer = json_object_new_object();
11437 }
11438
11439 if (peer->eor_stime[afi][safi]
11440 >= peer->pkt_stime[afi][safi])
11441 eor_flag = true;
11442 else
11443 eor_flag = false;
11444
11445 if (!use_json) {
11446 vty_out(vty, " %s:\n",
11447 get_afi_safi_str(afi, safi, false));
11448
11449 vty_out(vty, " F bit: ");
11450 }
11451
11452 if (peer->nsf[afi][safi]
11453 && CHECK_FLAG(peer->af_cap[afi][safi],
11454 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
11455
11456 if (use_json) {
11457 json_object_boolean_true_add(
11458 json_afi_safi, "fBit");
11459 } else
11460 vty_out(vty, "True\n");
11461 } else {
11462 if (use_json)
11463 json_object_boolean_false_add(
11464 json_afi_safi, "fBit");
11465 else
11466 vty_out(vty, "False\n");
11467 }
11468
11469 if (!use_json)
11470 vty_out(vty, " End-of-RIB sent: ");
11471
11472 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11473 PEER_STATUS_EOR_SEND)) {
11474 if (use_json) {
11475 json_object_boolean_true_add(
11476 json_endofrib_status,
11477 "endOfRibSend");
11478
11479 PRINT_EOR_JSON(eor_flag);
11480 } else {
11481 vty_out(vty, "Yes\n");
11482 vty_out(vty,
11483 " End-of-RIB sent after update: ");
11484
11485 PRINT_EOR(eor_flag);
11486 }
11487 } else {
11488 if (use_json) {
11489 json_object_boolean_false_add(
11490 json_endofrib_status,
11491 "endOfRibSend");
11492 json_object_boolean_false_add(
11493 json_endofrib_status,
11494 "endOfRibSentAfterUpdate");
11495 } else {
11496 vty_out(vty, "No\n");
11497 vty_out(vty,
11498 " End-of-RIB sent after update: ");
11499 vty_out(vty, "No\n");
11500 }
11501 }
11502
11503 if (!use_json)
11504 vty_out(vty, " End-of-RIB received: ");
11505
11506 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11507 PEER_STATUS_EOR_RECEIVED)) {
11508 if (use_json)
11509 json_object_boolean_true_add(
11510 json_endofrib_status,
11511 "endOfRibRecv");
11512 else
11513 vty_out(vty, "Yes\n");
11514 } else {
11515 if (use_json)
11516 json_object_boolean_false_add(
11517 json_endofrib_status,
11518 "endOfRibRecv");
11519 else
11520 vty_out(vty, "No\n");
11521 }
11522
11523 if (use_json) {
11524 json_object_int_add(json_timer,
11525 "stalePathTimer",
11526 peer->bgp->stalepath_time);
11527
11528 if (peer->t_gr_stale != NULL) {
11529 json_object_int_add(
11530 json_timer,
11531 "stalePathTimerRemaining",
11532 thread_timer_remain_second(
11533 peer->t_gr_stale));
11534 }
11535
11536 /* Display Configured Selection
11537 * Deferral only when when
11538 * Gr mode is enabled.
11539 */
11540 if (CHECK_FLAG(peer->flags,
11541 PEER_FLAG_GRACEFUL_RESTART)) {
11542 json_object_int_add(
11543 json_timer,
11544 "selectionDeferralTimer",
11545 peer->bgp->stalepath_time);
11546 }
11547
11548 if (peer->bgp->gr_info[afi][safi]
11549 .t_select_deferral
11550 != NULL) {
11551
11552 json_object_int_add(
11553 json_timer,
11554 "selectionDeferralTimerRemaining",
11555 thread_timer_remain_second(
11556 peer->bgp
11557 ->gr_info[afi]
11558 [safi]
11559 .t_select_deferral));
11560 }
11561 } else {
11562 vty_out(vty, " Timers:\n");
11563 vty_out(vty,
11564 " Configured Stale Path Time(sec): %u\n",
11565 peer->bgp->stalepath_time);
11566
11567 if (peer->t_gr_stale != NULL)
11568 vty_out(vty,
11569 " Stale Path Remaining(sec): %ld\n",
11570 thread_timer_remain_second(
11571 peer->t_gr_stale));
11572 /* Display Configured Selection
11573 * Deferral only when when
11574 * Gr mode is enabled.
11575 */
11576 if (CHECK_FLAG(peer->flags,
11577 PEER_FLAG_GRACEFUL_RESTART))
11578 vty_out(vty,
11579 " Configured Selection Deferral Time(sec): %u\n",
11580 peer->bgp->select_defer_time);
11581
11582 if (peer->bgp->gr_info[afi][safi]
11583 .t_select_deferral
11584 != NULL)
11585 vty_out(vty,
11586 " Selection Deferral Time Remaining(sec): %ld\n",
11587 thread_timer_remain_second(
11588 peer->bgp
11589 ->gr_info[afi]
11590 [safi]
11591 .t_select_deferral));
11592 }
11593 if (use_json) {
11594 json_object_object_add(json_afi_safi,
11595 "endOfRibStatus",
11596 json_endofrib_status);
11597 json_object_object_add(json_afi_safi, "timers",
11598 json_timer);
11599 json_object_object_add(
11600 json, get_afi_safi_str(afi, safi, true),
11601 json_afi_safi);
11602 }
11603 }
11604 }
11605 }
11606
11607 static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
11608 struct peer *p,
11609 bool use_json,
11610 json_object *json)
11611 {
11612 if (use_json) {
11613 json_object *json_timer = NULL;
11614
11615 json_timer = json_object_new_object();
11616
11617 json_object_int_add(json_timer, "configuredRestartTimer",
11618 p->bgp->restart_time);
11619
11620 json_object_int_add(json_timer, "receivedRestartTimer",
11621 p->v_gr_restart);
11622
11623 if (p->t_gr_restart != NULL)
11624 json_object_int_add(
11625 json_timer, "restartTimerRemaining",
11626 thread_timer_remain_second(p->t_gr_restart));
11627
11628 json_object_object_add(json, "timers", json_timer);
11629 } else {
11630
11631 vty_out(vty, " Timers:\n");
11632 vty_out(vty, " Configured Restart Time(sec): %u\n",
11633 p->bgp->restart_time);
11634
11635 vty_out(vty, " Received Restart Time(sec): %u\n",
11636 p->v_gr_restart);
11637 if (p->t_gr_restart != NULL)
11638 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
11639 thread_timer_remain_second(p->t_gr_restart));
11640 if (p->t_gr_restart != NULL) {
11641 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
11642 thread_timer_remain_second(p->t_gr_restart));
11643 }
11644 }
11645 }
11646
11647 static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
11648 bool use_json, json_object *json)
11649 {
11650 char buf[SU_ADDRSTRLEN] = {0};
11651 char dn_flag[2] = {0};
11652 /* '*' + v6 address of neighbor */
11653 char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
11654
11655 if (!p->conf_if && peer_dynamic_neighbor(p))
11656 dn_flag[0] = '*';
11657
11658 if (p->conf_if) {
11659 if (use_json)
11660 json_object_string_add(
11661 json, "neighborAddr",
11662 BGP_PEER_SU_UNSPEC(p)
11663 ? "none"
11664 : sockunion2str(&p->su, buf,
11665 SU_ADDRSTRLEN));
11666 else
11667 vty_out(vty, "BGP neighbor on %s: %s\n", p->conf_if,
11668 BGP_PEER_SU_UNSPEC(p)
11669 ? "none"
11670 : sockunion2str(&p->su, buf,
11671 SU_ADDRSTRLEN));
11672 } else {
11673 snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
11674 p->host);
11675
11676 if (use_json)
11677 json_object_string_add(json, "neighborAddr",
11678 neighborAddr);
11679 else
11680 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
11681 }
11682
11683 /* more gr info in new format */
11684 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json);
11685 }
11686
11687 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
11688 safi_t safi, bool use_json,
11689 json_object *json_neigh)
11690 {
11691 struct bgp_filter *filter;
11692 struct peer_af *paf;
11693 char orf_pfx_name[BUFSIZ];
11694 int orf_pfx_count;
11695 json_object *json_af = NULL;
11696 json_object *json_prefA = NULL;
11697 json_object *json_prefB = NULL;
11698 json_object *json_addr = NULL;
11699 json_object *json_advmap = NULL;
11700
11701 if (use_json) {
11702 json_addr = json_object_new_object();
11703 json_af = json_object_new_object();
11704 filter = &p->filter[afi][safi];
11705
11706 if (peer_group_active(p))
11707 json_object_string_add(json_addr, "peerGroupMember",
11708 p->group->name);
11709
11710 paf = peer_af_find(p, afi, safi);
11711 if (paf && PAF_SUBGRP(paf)) {
11712 json_object_int_add(json_addr, "updateGroupId",
11713 PAF_UPDGRP(paf)->id);
11714 json_object_int_add(json_addr, "subGroupId",
11715 PAF_SUBGRP(paf)->id);
11716 json_object_int_add(json_addr, "packetQueueLength",
11717 bpacket_queue_virtual_length(paf));
11718 }
11719
11720 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11721 || CHECK_FLAG(p->af_cap[afi][safi],
11722 PEER_CAP_ORF_PREFIX_SM_RCV)
11723 || CHECK_FLAG(p->af_cap[afi][safi],
11724 PEER_CAP_ORF_PREFIX_RM_ADV)
11725 || CHECK_FLAG(p->af_cap[afi][safi],
11726 PEER_CAP_ORF_PREFIX_RM_RCV)) {
11727 json_object_int_add(json_af, "orfType",
11728 ORF_TYPE_PREFIX);
11729 json_prefA = json_object_new_object();
11730 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
11731 PEER_CAP_ORF_PREFIX_SM_ADV,
11732 PEER_CAP_ORF_PREFIX_RM_ADV,
11733 PEER_CAP_ORF_PREFIX_SM_RCV,
11734 PEER_CAP_ORF_PREFIX_RM_RCV,
11735 use_json, json_prefA);
11736 json_object_object_add(json_af, "orfPrefixList",
11737 json_prefA);
11738 }
11739
11740 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11741 || CHECK_FLAG(p->af_cap[afi][safi],
11742 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11743 || CHECK_FLAG(p->af_cap[afi][safi],
11744 PEER_CAP_ORF_PREFIX_RM_ADV)
11745 || CHECK_FLAG(p->af_cap[afi][safi],
11746 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
11747 json_object_int_add(json_af, "orfOldType",
11748 ORF_TYPE_PREFIX_OLD);
11749 json_prefB = json_object_new_object();
11750 bgp_show_peer_afi_orf_cap(
11751 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
11752 PEER_CAP_ORF_PREFIX_RM_ADV,
11753 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
11754 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
11755 json_prefB);
11756 json_object_object_add(json_af, "orfOldPrefixList",
11757 json_prefB);
11758 }
11759
11760 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11761 || CHECK_FLAG(p->af_cap[afi][safi],
11762 PEER_CAP_ORF_PREFIX_SM_RCV)
11763 || CHECK_FLAG(p->af_cap[afi][safi],
11764 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11765 || CHECK_FLAG(p->af_cap[afi][safi],
11766 PEER_CAP_ORF_PREFIX_RM_ADV)
11767 || CHECK_FLAG(p->af_cap[afi][safi],
11768 PEER_CAP_ORF_PREFIX_RM_RCV)
11769 || CHECK_FLAG(p->af_cap[afi][safi],
11770 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
11771 json_object_object_add(json_addr, "afDependentCap",
11772 json_af);
11773 else
11774 json_object_free(json_af);
11775
11776 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
11777 p->host, afi, safi);
11778 orf_pfx_count = prefix_bgp_show_prefix_list(
11779 NULL, afi, orf_pfx_name, use_json);
11780
11781 if (CHECK_FLAG(p->af_sflags[afi][safi],
11782 PEER_STATUS_ORF_PREFIX_SEND)
11783 || orf_pfx_count) {
11784 if (CHECK_FLAG(p->af_sflags[afi][safi],
11785 PEER_STATUS_ORF_PREFIX_SEND))
11786 json_object_boolean_true_add(json_neigh,
11787 "orfSent");
11788 if (orf_pfx_count)
11789 json_object_int_add(json_addr, "orfRecvCounter",
11790 orf_pfx_count);
11791 }
11792 if (CHECK_FLAG(p->af_sflags[afi][safi],
11793 PEER_STATUS_ORF_WAIT_REFRESH))
11794 json_object_string_add(
11795 json_addr, "orfFirstUpdate",
11796 "deferredUntilORFOrRouteRefreshRecvd");
11797
11798 if (CHECK_FLAG(p->af_flags[afi][safi],
11799 PEER_FLAG_REFLECTOR_CLIENT))
11800 json_object_boolean_true_add(json_addr,
11801 "routeReflectorClient");
11802 if (CHECK_FLAG(p->af_flags[afi][safi],
11803 PEER_FLAG_RSERVER_CLIENT))
11804 json_object_boolean_true_add(json_addr,
11805 "routeServerClient");
11806 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
11807 json_object_boolean_true_add(json_addr,
11808 "inboundSoftConfigPermit");
11809
11810 if (CHECK_FLAG(p->af_flags[afi][safi],
11811 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
11812 json_object_boolean_true_add(
11813 json_addr,
11814 "privateAsNumsAllReplacedInUpdatesToNbr");
11815 else if (CHECK_FLAG(p->af_flags[afi][safi],
11816 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
11817 json_object_boolean_true_add(
11818 json_addr,
11819 "privateAsNumsReplacedInUpdatesToNbr");
11820 else if (CHECK_FLAG(p->af_flags[afi][safi],
11821 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
11822 json_object_boolean_true_add(
11823 json_addr,
11824 "privateAsNumsAllRemovedInUpdatesToNbr");
11825 else if (CHECK_FLAG(p->af_flags[afi][safi],
11826 PEER_FLAG_REMOVE_PRIVATE_AS))
11827 json_object_boolean_true_add(
11828 json_addr,
11829 "privateAsNumsRemovedInUpdatesToNbr");
11830
11831 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
11832 json_object_boolean_true_add(
11833 json_addr,
11834 bgp_addpath_names(p->addpath_type[afi][safi])
11835 ->type_json_name);
11836
11837 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
11838 json_object_string_add(json_addr,
11839 "overrideASNsInOutboundUpdates",
11840 "ifAspathEqualRemoteAs");
11841
11842 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
11843 || CHECK_FLAG(p->af_flags[afi][safi],
11844 PEER_FLAG_FORCE_NEXTHOP_SELF))
11845 json_object_boolean_true_add(json_addr,
11846 "routerAlwaysNextHop");
11847 if (CHECK_FLAG(p->af_flags[afi][safi],
11848 PEER_FLAG_AS_PATH_UNCHANGED))
11849 json_object_boolean_true_add(
11850 json_addr, "unchangedAsPathPropogatedToNbr");
11851 if (CHECK_FLAG(p->af_flags[afi][safi],
11852 PEER_FLAG_NEXTHOP_UNCHANGED))
11853 json_object_boolean_true_add(
11854 json_addr, "unchangedNextHopPropogatedToNbr");
11855 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
11856 json_object_boolean_true_add(
11857 json_addr, "unchangedMedPropogatedToNbr");
11858 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
11859 || CHECK_FLAG(p->af_flags[afi][safi],
11860 PEER_FLAG_SEND_EXT_COMMUNITY)) {
11861 if (CHECK_FLAG(p->af_flags[afi][safi],
11862 PEER_FLAG_SEND_COMMUNITY)
11863 && CHECK_FLAG(p->af_flags[afi][safi],
11864 PEER_FLAG_SEND_EXT_COMMUNITY))
11865 json_object_string_add(json_addr,
11866 "commAttriSentToNbr",
11867 "extendedAndStandard");
11868 else if (CHECK_FLAG(p->af_flags[afi][safi],
11869 PEER_FLAG_SEND_EXT_COMMUNITY))
11870 json_object_string_add(json_addr,
11871 "commAttriSentToNbr",
11872 "extended");
11873 else
11874 json_object_string_add(json_addr,
11875 "commAttriSentToNbr",
11876 "standard");
11877 }
11878 if (CHECK_FLAG(p->af_flags[afi][safi],
11879 PEER_FLAG_DEFAULT_ORIGINATE)) {
11880 if (p->default_rmap[afi][safi].name)
11881 json_object_string_add(
11882 json_addr, "defaultRouteMap",
11883 p->default_rmap[afi][safi].name);
11884
11885 if (paf && PAF_SUBGRP(paf)
11886 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
11887 SUBGRP_STATUS_DEFAULT_ORIGINATE))
11888 json_object_boolean_true_add(json_addr,
11889 "defaultSent");
11890 else
11891 json_object_boolean_true_add(json_addr,
11892 "defaultNotSent");
11893 }
11894
11895 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
11896 if (is_evpn_enabled())
11897 json_object_boolean_true_add(
11898 json_addr, "advertiseAllVnis");
11899 }
11900
11901 if (filter->plist[FILTER_IN].name
11902 || filter->dlist[FILTER_IN].name
11903 || filter->aslist[FILTER_IN].name
11904 || filter->map[RMAP_IN].name)
11905 json_object_boolean_true_add(json_addr,
11906 "inboundPathPolicyConfig");
11907 if (filter->plist[FILTER_OUT].name
11908 || filter->dlist[FILTER_OUT].name
11909 || filter->aslist[FILTER_OUT].name
11910 || filter->map[RMAP_OUT].name || filter->usmap.name)
11911 json_object_boolean_true_add(
11912 json_addr, "outboundPathPolicyConfig");
11913
11914 /* prefix-list */
11915 if (filter->plist[FILTER_IN].name)
11916 json_object_string_add(json_addr,
11917 "incomingUpdatePrefixFilterList",
11918 filter->plist[FILTER_IN].name);
11919 if (filter->plist[FILTER_OUT].name)
11920 json_object_string_add(json_addr,
11921 "outgoingUpdatePrefixFilterList",
11922 filter->plist[FILTER_OUT].name);
11923
11924 /* distribute-list */
11925 if (filter->dlist[FILTER_IN].name)
11926 json_object_string_add(
11927 json_addr, "incomingUpdateNetworkFilterList",
11928 filter->dlist[FILTER_IN].name);
11929 if (filter->dlist[FILTER_OUT].name)
11930 json_object_string_add(
11931 json_addr, "outgoingUpdateNetworkFilterList",
11932 filter->dlist[FILTER_OUT].name);
11933
11934 /* filter-list. */
11935 if (filter->aslist[FILTER_IN].name)
11936 json_object_string_add(json_addr,
11937 "incomingUpdateAsPathFilterList",
11938 filter->aslist[FILTER_IN].name);
11939 if (filter->aslist[FILTER_OUT].name)
11940 json_object_string_add(json_addr,
11941 "outgoingUpdateAsPathFilterList",
11942 filter->aslist[FILTER_OUT].name);
11943
11944 /* route-map. */
11945 if (filter->map[RMAP_IN].name)
11946 json_object_string_add(
11947 json_addr, "routeMapForIncomingAdvertisements",
11948 filter->map[RMAP_IN].name);
11949 if (filter->map[RMAP_OUT].name)
11950 json_object_string_add(
11951 json_addr, "routeMapForOutgoingAdvertisements",
11952 filter->map[RMAP_OUT].name);
11953
11954 /* ebgp-requires-policy (inbound) */
11955 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
11956 && !bgp_inbound_policy_exists(p, filter))
11957 json_object_string_add(
11958 json_addr, "inboundEbgpRequiresPolicy",
11959 "Inbound updates discarded due to missing policy");
11960
11961 /* ebgp-requires-policy (outbound) */
11962 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
11963 && (!bgp_outbound_policy_exists(p, filter)))
11964 json_object_string_add(
11965 json_addr, "outboundEbgpRequiresPolicy",
11966 "Outbound updates discarded due to missing policy");
11967
11968 /* unsuppress-map */
11969 if (filter->usmap.name)
11970 json_object_string_add(json_addr,
11971 "selectiveUnsuppressRouteMap",
11972 filter->usmap.name);
11973
11974 /* advertise-map */
11975 if (filter->advmap.aname) {
11976 json_advmap = json_object_new_object();
11977 json_object_string_add(json_advmap, "condition",
11978 filter->advmap.condition
11979 ? "EXIST"
11980 : "NON_EXIST");
11981 json_object_string_add(json_advmap, "conditionMap",
11982 filter->advmap.cname);
11983 json_object_string_add(json_advmap, "advertiseMap",
11984 filter->advmap.aname);
11985 json_object_string_add(json_advmap, "advertiseStatus",
11986 filter->advmap.update_type
11987 == ADVERTISE
11988 ? "Advertise"
11989 : "Withdraw");
11990 json_object_object_add(json_addr, "advertiseMap",
11991 json_advmap);
11992 }
11993
11994 /* Receive prefix count */
11995 json_object_int_add(json_addr, "acceptedPrefixCounter",
11996 p->pcount[afi][safi]);
11997 if (paf && PAF_SUBGRP(paf))
11998 json_object_int_add(json_addr, "sentPrefixCounter",
11999 (PAF_SUBGRP(paf))->scount);
12000
12001 /* Maximum prefix */
12002 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
12003 json_object_int_add(json_addr, "prefixOutAllowedMax",
12004 p->pmax_out[afi][safi]);
12005
12006 /* Maximum prefix */
12007 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12008 json_object_int_add(json_addr, "prefixAllowedMax",
12009 p->pmax[afi][safi]);
12010 if (CHECK_FLAG(p->af_flags[afi][safi],
12011 PEER_FLAG_MAX_PREFIX_WARNING))
12012 json_object_boolean_true_add(
12013 json_addr, "prefixAllowedMaxWarning");
12014 json_object_int_add(json_addr,
12015 "prefixAllowedWarningThresh",
12016 p->pmax_threshold[afi][safi]);
12017 if (p->pmax_restart[afi][safi])
12018 json_object_int_add(
12019 json_addr,
12020 "prefixAllowedRestartIntervalMsecs",
12021 p->pmax_restart[afi][safi] * 60000);
12022 }
12023 json_object_object_add(json_neigh,
12024 get_afi_safi_str(afi, safi, true),
12025 json_addr);
12026
12027 } else {
12028 filter = &p->filter[afi][safi];
12029
12030 vty_out(vty, " For address family: %s\n",
12031 get_afi_safi_str(afi, safi, false));
12032
12033 if (peer_group_active(p))
12034 vty_out(vty, " %s peer-group member\n",
12035 p->group->name);
12036
12037 paf = peer_af_find(p, afi, safi);
12038 if (paf && PAF_SUBGRP(paf)) {
12039 vty_out(vty, " Update group %" PRIu64", subgroup %" PRIu64 "\n",
12040 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
12041 vty_out(vty, " Packet Queue length %d\n",
12042 bpacket_queue_virtual_length(paf));
12043 } else {
12044 vty_out(vty, " Not part of any update group\n");
12045 }
12046 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12047 || CHECK_FLAG(p->af_cap[afi][safi],
12048 PEER_CAP_ORF_PREFIX_SM_RCV)
12049 || CHECK_FLAG(p->af_cap[afi][safi],
12050 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12051 || CHECK_FLAG(p->af_cap[afi][safi],
12052 PEER_CAP_ORF_PREFIX_RM_ADV)
12053 || CHECK_FLAG(p->af_cap[afi][safi],
12054 PEER_CAP_ORF_PREFIX_RM_RCV)
12055 || CHECK_FLAG(p->af_cap[afi][safi],
12056 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12057 vty_out(vty, " AF-dependant capabilities:\n");
12058
12059 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12060 || CHECK_FLAG(p->af_cap[afi][safi],
12061 PEER_CAP_ORF_PREFIX_SM_RCV)
12062 || CHECK_FLAG(p->af_cap[afi][safi],
12063 PEER_CAP_ORF_PREFIX_RM_ADV)
12064 || CHECK_FLAG(p->af_cap[afi][safi],
12065 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12066 vty_out(vty,
12067 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12068 ORF_TYPE_PREFIX);
12069 bgp_show_peer_afi_orf_cap(
12070 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12071 PEER_CAP_ORF_PREFIX_RM_ADV,
12072 PEER_CAP_ORF_PREFIX_SM_RCV,
12073 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
12074 }
12075 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12076 || CHECK_FLAG(p->af_cap[afi][safi],
12077 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12078 || CHECK_FLAG(p->af_cap[afi][safi],
12079 PEER_CAP_ORF_PREFIX_RM_ADV)
12080 || CHECK_FLAG(p->af_cap[afi][safi],
12081 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12082 vty_out(vty,
12083 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12084 ORF_TYPE_PREFIX_OLD);
12085 bgp_show_peer_afi_orf_cap(
12086 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12087 PEER_CAP_ORF_PREFIX_RM_ADV,
12088 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12089 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
12090 }
12091
12092 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12093 p->host, afi, safi);
12094 orf_pfx_count = prefix_bgp_show_prefix_list(
12095 NULL, afi, orf_pfx_name, use_json);
12096
12097 if (CHECK_FLAG(p->af_sflags[afi][safi],
12098 PEER_STATUS_ORF_PREFIX_SEND)
12099 || orf_pfx_count) {
12100 vty_out(vty, " Outbound Route Filter (ORF):");
12101 if (CHECK_FLAG(p->af_sflags[afi][safi],
12102 PEER_STATUS_ORF_PREFIX_SEND))
12103 vty_out(vty, " sent;");
12104 if (orf_pfx_count)
12105 vty_out(vty, " received (%d entries)",
12106 orf_pfx_count);
12107 vty_out(vty, "\n");
12108 }
12109 if (CHECK_FLAG(p->af_sflags[afi][safi],
12110 PEER_STATUS_ORF_WAIT_REFRESH))
12111 vty_out(vty,
12112 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
12113
12114 if (CHECK_FLAG(p->af_flags[afi][safi],
12115 PEER_FLAG_REFLECTOR_CLIENT))
12116 vty_out(vty, " Route-Reflector Client\n");
12117 if (CHECK_FLAG(p->af_flags[afi][safi],
12118 PEER_FLAG_RSERVER_CLIENT))
12119 vty_out(vty, " Route-Server Client\n");
12120 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12121 vty_out(vty,
12122 " Inbound soft reconfiguration allowed\n");
12123
12124 if (CHECK_FLAG(p->af_flags[afi][safi],
12125 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12126 vty_out(vty,
12127 " Private AS numbers (all) replaced in updates to this neighbor\n");
12128 else if (CHECK_FLAG(p->af_flags[afi][safi],
12129 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12130 vty_out(vty,
12131 " Private AS numbers replaced in updates to this neighbor\n");
12132 else if (CHECK_FLAG(p->af_flags[afi][safi],
12133 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12134 vty_out(vty,
12135 " Private AS numbers (all) removed in updates to this neighbor\n");
12136 else if (CHECK_FLAG(p->af_flags[afi][safi],
12137 PEER_FLAG_REMOVE_PRIVATE_AS))
12138 vty_out(vty,
12139 " Private AS numbers removed in updates to this neighbor\n");
12140
12141 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12142 vty_out(vty, " %s\n",
12143 bgp_addpath_names(p->addpath_type[afi][safi])
12144 ->human_description);
12145
12146 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12147 vty_out(vty,
12148 " Override ASNs in outbound updates if aspath equals remote-as\n");
12149
12150 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12151 || CHECK_FLAG(p->af_flags[afi][safi],
12152 PEER_FLAG_FORCE_NEXTHOP_SELF))
12153 vty_out(vty, " NEXT_HOP is always this router\n");
12154 if (CHECK_FLAG(p->af_flags[afi][safi],
12155 PEER_FLAG_AS_PATH_UNCHANGED))
12156 vty_out(vty,
12157 " AS_PATH is propagated unchanged to this neighbor\n");
12158 if (CHECK_FLAG(p->af_flags[afi][safi],
12159 PEER_FLAG_NEXTHOP_UNCHANGED))
12160 vty_out(vty,
12161 " NEXT_HOP is propagated unchanged to this neighbor\n");
12162 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12163 vty_out(vty,
12164 " MED is propagated unchanged to this neighbor\n");
12165 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12166 || CHECK_FLAG(p->af_flags[afi][safi],
12167 PEER_FLAG_SEND_EXT_COMMUNITY)
12168 || CHECK_FLAG(p->af_flags[afi][safi],
12169 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
12170 vty_out(vty,
12171 " Community attribute sent to this neighbor");
12172 if (CHECK_FLAG(p->af_flags[afi][safi],
12173 PEER_FLAG_SEND_COMMUNITY)
12174 && CHECK_FLAG(p->af_flags[afi][safi],
12175 PEER_FLAG_SEND_EXT_COMMUNITY)
12176 && CHECK_FLAG(p->af_flags[afi][safi],
12177 PEER_FLAG_SEND_LARGE_COMMUNITY))
12178 vty_out(vty, "(all)\n");
12179 else if (CHECK_FLAG(p->af_flags[afi][safi],
12180 PEER_FLAG_SEND_LARGE_COMMUNITY))
12181 vty_out(vty, "(large)\n");
12182 else if (CHECK_FLAG(p->af_flags[afi][safi],
12183 PEER_FLAG_SEND_EXT_COMMUNITY))
12184 vty_out(vty, "(extended)\n");
12185 else
12186 vty_out(vty, "(standard)\n");
12187 }
12188 if (CHECK_FLAG(p->af_flags[afi][safi],
12189 PEER_FLAG_DEFAULT_ORIGINATE)) {
12190 vty_out(vty, " Default information originate,");
12191
12192 if (p->default_rmap[afi][safi].name)
12193 vty_out(vty, " default route-map %s%s,",
12194 p->default_rmap[afi][safi].map ? "*"
12195 : "",
12196 p->default_rmap[afi][safi].name);
12197 if (paf && PAF_SUBGRP(paf)
12198 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12199 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12200 vty_out(vty, " default sent\n");
12201 else
12202 vty_out(vty, " default not sent\n");
12203 }
12204
12205 /* advertise-vni-all */
12206 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
12207 if (is_evpn_enabled())
12208 vty_out(vty, " advertise-all-vni\n");
12209 }
12210
12211 if (filter->plist[FILTER_IN].name
12212 || filter->dlist[FILTER_IN].name
12213 || filter->aslist[FILTER_IN].name
12214 || filter->map[RMAP_IN].name)
12215 vty_out(vty, " Inbound path policy configured\n");
12216 if (filter->plist[FILTER_OUT].name
12217 || filter->dlist[FILTER_OUT].name
12218 || filter->aslist[FILTER_OUT].name
12219 || filter->map[RMAP_OUT].name || filter->usmap.name)
12220 vty_out(vty, " Outbound path policy configured\n");
12221
12222 /* prefix-list */
12223 if (filter->plist[FILTER_IN].name)
12224 vty_out(vty,
12225 " Incoming update prefix filter list is %s%s\n",
12226 filter->plist[FILTER_IN].plist ? "*" : "",
12227 filter->plist[FILTER_IN].name);
12228 if (filter->plist[FILTER_OUT].name)
12229 vty_out(vty,
12230 " Outgoing update prefix filter list is %s%s\n",
12231 filter->plist[FILTER_OUT].plist ? "*" : "",
12232 filter->plist[FILTER_OUT].name);
12233
12234 /* distribute-list */
12235 if (filter->dlist[FILTER_IN].name)
12236 vty_out(vty,
12237 " Incoming update network filter list is %s%s\n",
12238 filter->dlist[FILTER_IN].alist ? "*" : "",
12239 filter->dlist[FILTER_IN].name);
12240 if (filter->dlist[FILTER_OUT].name)
12241 vty_out(vty,
12242 " Outgoing update network filter list is %s%s\n",
12243 filter->dlist[FILTER_OUT].alist ? "*" : "",
12244 filter->dlist[FILTER_OUT].name);
12245
12246 /* filter-list. */
12247 if (filter->aslist[FILTER_IN].name)
12248 vty_out(vty,
12249 " Incoming update AS path filter list is %s%s\n",
12250 filter->aslist[FILTER_IN].aslist ? "*" : "",
12251 filter->aslist[FILTER_IN].name);
12252 if (filter->aslist[FILTER_OUT].name)
12253 vty_out(vty,
12254 " Outgoing update AS path filter list is %s%s\n",
12255 filter->aslist[FILTER_OUT].aslist ? "*" : "",
12256 filter->aslist[FILTER_OUT].name);
12257
12258 /* route-map. */
12259 if (filter->map[RMAP_IN].name)
12260 vty_out(vty,
12261 " Route map for incoming advertisements is %s%s\n",
12262 filter->map[RMAP_IN].map ? "*" : "",
12263 filter->map[RMAP_IN].name);
12264 if (filter->map[RMAP_OUT].name)
12265 vty_out(vty,
12266 " Route map for outgoing advertisements is %s%s\n",
12267 filter->map[RMAP_OUT].map ? "*" : "",
12268 filter->map[RMAP_OUT].name);
12269
12270 /* ebgp-requires-policy (inbound) */
12271 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12272 && !bgp_inbound_policy_exists(p, filter))
12273 vty_out(vty,
12274 " Inbound updates discarded due to missing policy\n");
12275
12276 /* ebgp-requires-policy (outbound) */
12277 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12278 && !bgp_outbound_policy_exists(p, filter))
12279 vty_out(vty,
12280 " Outbound updates discarded due to missing policy\n");
12281
12282 /* unsuppress-map */
12283 if (filter->usmap.name)
12284 vty_out(vty,
12285 " Route map for selective unsuppress is %s%s\n",
12286 filter->usmap.map ? "*" : "",
12287 filter->usmap.name);
12288
12289 /* advertise-map */
12290 if (filter->advmap.aname && filter->advmap.cname)
12291 vty_out(vty,
12292 " Condition %s, Condition-map %s%s, Advertise-map %s%s, status: %s\n",
12293 filter->advmap.condition ? "EXIST"
12294 : "NON_EXIST",
12295 filter->advmap.cmap ? "*" : "",
12296 filter->advmap.cname,
12297 filter->advmap.amap ? "*" : "",
12298 filter->advmap.aname,
12299 filter->advmap.update_type == ADVERTISE
12300 ? "Advertise"
12301 : "Withdraw");
12302
12303 /* Receive prefix count */
12304 vty_out(vty, " %u accepted prefixes\n",
12305 p->pcount[afi][safi]);
12306
12307 /* maximum-prefix-out */
12308 if (CHECK_FLAG(p->af_flags[afi][safi],
12309 PEER_FLAG_MAX_PREFIX_OUT))
12310 vty_out(vty,
12311 " Maximum allowed prefixes sent %u\n",
12312 p->pmax_out[afi][safi]);
12313
12314 /* Maximum prefix */
12315 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12316 vty_out(vty,
12317 " Maximum prefixes allowed %u%s\n",
12318 p->pmax[afi][safi],
12319 CHECK_FLAG(p->af_flags[afi][safi],
12320 PEER_FLAG_MAX_PREFIX_WARNING)
12321 ? " (warning-only)"
12322 : "");
12323 vty_out(vty, " Threshold for warning message %d%%",
12324 p->pmax_threshold[afi][safi]);
12325 if (p->pmax_restart[afi][safi])
12326 vty_out(vty, ", restart interval %d min",
12327 p->pmax_restart[afi][safi]);
12328 vty_out(vty, "\n");
12329 }
12330
12331 vty_out(vty, "\n");
12332 }
12333 }
12334
12335 static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
12336 json_object *json)
12337 {
12338 struct bgp *bgp;
12339 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
12340 char timebuf[BGP_UPTIME_LEN];
12341 char dn_flag[2];
12342 afi_t afi;
12343 safi_t safi;
12344 uint16_t i;
12345 uint8_t *msg;
12346 json_object *json_neigh = NULL;
12347 time_t epoch_tbuf;
12348
12349 bgp = p->bgp;
12350
12351 if (use_json)
12352 json_neigh = json_object_new_object();
12353
12354 memset(dn_flag, '\0', sizeof(dn_flag));
12355 if (!p->conf_if && peer_dynamic_neighbor(p))
12356 dn_flag[0] = '*';
12357
12358 if (!use_json) {
12359 if (p->conf_if) /* Configured interface name. */
12360 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
12361 BGP_PEER_SU_UNSPEC(p)
12362 ? "None"
12363 : sockunion2str(&p->su, buf,
12364 SU_ADDRSTRLEN));
12365 else /* Configured IP address. */
12366 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
12367 p->host);
12368 }
12369
12370 if (use_json) {
12371 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
12372 json_object_string_add(json_neigh, "bgpNeighborAddr",
12373 "none");
12374 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
12375 json_object_string_add(
12376 json_neigh, "bgpNeighborAddr",
12377 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
12378
12379 json_object_int_add(json_neigh, "remoteAs", p->as);
12380
12381 if (p->change_local_as)
12382 json_object_int_add(json_neigh, "localAs",
12383 p->change_local_as);
12384 else
12385 json_object_int_add(json_neigh, "localAs", p->local_as);
12386
12387 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
12388 json_object_boolean_true_add(json_neigh,
12389 "localAsNoPrepend");
12390
12391 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
12392 json_object_boolean_true_add(json_neigh,
12393 "localAsReplaceAs");
12394 } else {
12395 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
12396 || (p->as_type == AS_INTERNAL))
12397 vty_out(vty, "remote AS %u, ", p->as);
12398 else
12399 vty_out(vty, "remote AS Unspecified, ");
12400 vty_out(vty, "local AS %u%s%s, ",
12401 p->change_local_as ? p->change_local_as : p->local_as,
12402 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
12403 ? " no-prepend"
12404 : "",
12405 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
12406 ? " replace-as"
12407 : "");
12408 }
12409 /* peer type internal or confed-internal */
12410 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
12411 if (use_json) {
12412 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12413 json_object_boolean_true_add(
12414 json_neigh, "nbrConfedInternalLink");
12415 else
12416 json_object_boolean_true_add(json_neigh,
12417 "nbrInternalLink");
12418 } else {
12419 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12420 vty_out(vty, "confed-internal link\n");
12421 else
12422 vty_out(vty, "internal link\n");
12423 }
12424 /* peer type external or confed-external */
12425 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
12426 if (use_json) {
12427 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12428 json_object_boolean_true_add(
12429 json_neigh, "nbrConfedExternalLink");
12430 else
12431 json_object_boolean_true_add(json_neigh,
12432 "nbrExternalLink");
12433 } else {
12434 if (bgp_confederation_peers_check(bgp, p->as))
12435 vty_out(vty, "confed-external link\n");
12436 else
12437 vty_out(vty, "external link\n");
12438 }
12439 } else {
12440 if (use_json)
12441 json_object_boolean_true_add(json_neigh,
12442 "nbrUnspecifiedLink");
12443 else
12444 vty_out(vty, "unspecified link\n");
12445 }
12446
12447 /* Description. */
12448 if (p->desc) {
12449 if (use_json)
12450 json_object_string_add(json_neigh, "nbrDesc", p->desc);
12451 else
12452 vty_out(vty, " Description: %s\n", p->desc);
12453 }
12454
12455 if (p->hostname) {
12456 if (use_json) {
12457 if (p->hostname)
12458 json_object_string_add(json_neigh, "hostname",
12459 p->hostname);
12460
12461 if (p->domainname)
12462 json_object_string_add(json_neigh, "domainname",
12463 p->domainname);
12464 } else {
12465 if (p->domainname && (p->domainname[0] != '\0'))
12466 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
12467 p->domainname);
12468 else
12469 vty_out(vty, "Hostname: %s\n", p->hostname);
12470 }
12471 }
12472
12473 /* Peer-group */
12474 if (p->group) {
12475 if (use_json) {
12476 json_object_string_add(json_neigh, "peerGroup",
12477 p->group->name);
12478
12479 if (dn_flag[0]) {
12480 struct prefix prefix, *range = NULL;
12481
12482 if (sockunion2hostprefix(&(p->su), &prefix))
12483 range = peer_group_lookup_dynamic_neighbor_range(
12484 p->group, &prefix);
12485
12486 if (range) {
12487 prefix2str(range, buf1, sizeof(buf1));
12488 json_object_string_add(
12489 json_neigh,
12490 "peerSubnetRangeGroup", buf1);
12491 }
12492 }
12493 } else {
12494 vty_out(vty,
12495 " Member of peer-group %s for session parameters\n",
12496 p->group->name);
12497
12498 if (dn_flag[0]) {
12499 struct prefix prefix, *range = NULL;
12500
12501 if (sockunion2hostprefix(&(p->su), &prefix))
12502 range = peer_group_lookup_dynamic_neighbor_range(
12503 p->group, &prefix);
12504
12505 if (range) {
12506 vty_out(vty,
12507 " Belongs to the subnet range group: %pFX\n",
12508 range);
12509 }
12510 }
12511 }
12512 }
12513
12514 if (use_json) {
12515 /* Administrative shutdown. */
12516 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12517 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
12518 json_object_boolean_true_add(json_neigh,
12519 "adminShutDown");
12520
12521 /* BGP Version. */
12522 json_object_int_add(json_neigh, "bgpVersion", 4);
12523 json_object_string_add(
12524 json_neigh, "remoteRouterId",
12525 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
12526 json_object_string_add(
12527 json_neigh, "localRouterId",
12528 inet_ntop(AF_INET, &bgp->router_id, buf1,
12529 sizeof(buf1)));
12530
12531 /* Confederation */
12532 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12533 && bgp_confederation_peers_check(bgp, p->as))
12534 json_object_boolean_true_add(json_neigh,
12535 "nbrCommonAdmin");
12536
12537 /* Status. */
12538 json_object_string_add(
12539 json_neigh, "bgpState",
12540 lookup_msg(bgp_status_msg, p->status, NULL));
12541
12542 if (p->status == Established) {
12543 time_t uptime;
12544
12545 uptime = bgp_clock();
12546 uptime -= p->uptime;
12547 epoch_tbuf = time(NULL) - uptime;
12548
12549 json_object_int_add(json_neigh, "bgpTimerUpMsec",
12550 uptime * 1000);
12551 json_object_string_add(json_neigh, "bgpTimerUpString",
12552 peer_uptime(p->uptime, timebuf,
12553 BGP_UPTIME_LEN, 0,
12554 NULL));
12555 json_object_int_add(json_neigh,
12556 "bgpTimerUpEstablishedEpoch",
12557 epoch_tbuf);
12558 }
12559
12560 else if (p->status == Active) {
12561 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12562 json_object_string_add(json_neigh, "bgpStateIs",
12563 "passive");
12564 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12565 json_object_string_add(json_neigh, "bgpStateIs",
12566 "passiveNSF");
12567 }
12568
12569 /* read timer */
12570 time_t uptime;
12571 struct tm tm;
12572
12573 uptime = bgp_clock();
12574 uptime -= p->readtime;
12575 gmtime_r(&uptime, &tm);
12576
12577 json_object_int_add(json_neigh, "bgpTimerLastRead",
12578 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12579 + (tm.tm_hour * 3600000));
12580
12581 uptime = bgp_clock();
12582 uptime -= p->last_write;
12583 gmtime_r(&uptime, &tm);
12584
12585 json_object_int_add(json_neigh, "bgpTimerLastWrite",
12586 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12587 + (tm.tm_hour * 3600000));
12588
12589 uptime = bgp_clock();
12590 uptime -= p->update_time;
12591 gmtime_r(&uptime, &tm);
12592
12593 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
12594 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12595 + (tm.tm_hour * 3600000));
12596
12597 /* Configured timer values. */
12598 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
12599 p->v_holdtime * 1000);
12600 json_object_int_add(json_neigh,
12601 "bgpTimerKeepAliveIntervalMsecs",
12602 p->v_keepalive * 1000);
12603 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
12604 json_object_int_add(json_neigh,
12605 "bgpTimerConfiguredHoldTimeMsecs",
12606 p->holdtime * 1000);
12607 json_object_int_add(
12608 json_neigh,
12609 "bgpTimerConfiguredKeepAliveIntervalMsecs",
12610 p->keepalive * 1000);
12611 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
12612 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
12613 json_object_int_add(json_neigh,
12614 "bgpTimerConfiguredHoldTimeMsecs",
12615 bgp->default_holdtime);
12616 json_object_int_add(
12617 json_neigh,
12618 "bgpTimerConfiguredKeepAliveIntervalMsecs",
12619 bgp->default_keepalive);
12620 }
12621 } else {
12622 /* Administrative shutdown. */
12623 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12624 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
12625 vty_out(vty, " Administratively shut down\n");
12626
12627 /* BGP Version. */
12628 vty_out(vty, " BGP version 4");
12629 vty_out(vty, ", remote router ID %s",
12630 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
12631 vty_out(vty, ", local router ID %s\n",
12632 inet_ntop(AF_INET, &bgp->router_id, buf1,
12633 sizeof(buf1)));
12634
12635 /* Confederation */
12636 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12637 && bgp_confederation_peers_check(bgp, p->as))
12638 vty_out(vty,
12639 " Neighbor under common administration\n");
12640
12641 /* Status. */
12642 vty_out(vty, " BGP state = %s",
12643 lookup_msg(bgp_status_msg, p->status, NULL));
12644
12645 if (p->status == Established)
12646 vty_out(vty, ", up for %8s",
12647 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
12648 0, NULL));
12649
12650 else if (p->status == Active) {
12651 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12652 vty_out(vty, " (passive)");
12653 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12654 vty_out(vty, " (NSF passive)");
12655 }
12656 vty_out(vty, "\n");
12657
12658 /* read timer */
12659 vty_out(vty, " Last read %s",
12660 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
12661 NULL));
12662 vty_out(vty, ", Last write %s\n",
12663 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
12664 NULL));
12665
12666 /* Configured timer values. */
12667 vty_out(vty,
12668 " Hold time is %d, keepalive interval is %d seconds\n",
12669 p->v_holdtime, p->v_keepalive);
12670 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
12671 vty_out(vty, " Configured hold time is %d",
12672 p->holdtime);
12673 vty_out(vty, ", keepalive interval is %d seconds\n",
12674 p->keepalive);
12675 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
12676 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
12677 vty_out(vty, " Configured hold time is %d",
12678 bgp->default_holdtime);
12679 vty_out(vty, ", keepalive interval is %d seconds\n",
12680 bgp->default_keepalive);
12681 }
12682 }
12683 /* Capability. */
12684 if (p->status == Established) {
12685 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
12686 || p->afc_recv[AFI_IP][SAFI_UNICAST]
12687 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
12688 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
12689 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
12690 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
12691 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
12692 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
12693 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
12694 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
12695 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
12696 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
12697 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
12698 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
12699 || p->afc_adv[AFI_IP][SAFI_ENCAP]
12700 || p->afc_recv[AFI_IP][SAFI_ENCAP]
12701 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
12702 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
12703 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
12704 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
12705 if (use_json) {
12706 json_object *json_cap = NULL;
12707
12708 json_cap = json_object_new_object();
12709
12710 /* AS4 */
12711 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
12712 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
12713 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
12714 && CHECK_FLAG(p->cap,
12715 PEER_CAP_AS4_RCV))
12716 json_object_string_add(
12717 json_cap, "4byteAs",
12718 "advertisedAndReceived");
12719 else if (CHECK_FLAG(p->cap,
12720 PEER_CAP_AS4_ADV))
12721 json_object_string_add(
12722 json_cap, "4byteAs",
12723 "advertised");
12724 else if (CHECK_FLAG(p->cap,
12725 PEER_CAP_AS4_RCV))
12726 json_object_string_add(
12727 json_cap, "4byteAs",
12728 "received");
12729 }
12730
12731 /* AddPath */
12732 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
12733 || CHECK_FLAG(p->cap,
12734 PEER_CAP_ADDPATH_ADV)) {
12735 json_object *json_add = NULL;
12736 const char *print_store;
12737
12738 json_add = json_object_new_object();
12739
12740 FOREACH_AFI_SAFI (afi, safi) {
12741 json_object *json_sub = NULL;
12742 json_sub =
12743 json_object_new_object();
12744 print_store = get_afi_safi_str(
12745 afi, safi, true);
12746
12747 if (CHECK_FLAG(
12748 p->af_cap[afi]
12749 [safi],
12750 PEER_CAP_ADDPATH_AF_TX_ADV)
12751 || CHECK_FLAG(
12752 p->af_cap[afi]
12753 [safi],
12754 PEER_CAP_ADDPATH_AF_TX_RCV)) {
12755 if (CHECK_FLAG(
12756 p->af_cap
12757 [afi]
12758 [safi],
12759 PEER_CAP_ADDPATH_AF_TX_ADV)
12760 && CHECK_FLAG(
12761 p->af_cap
12762 [afi]
12763 [safi],
12764 PEER_CAP_ADDPATH_AF_TX_RCV))
12765 json_object_boolean_true_add(
12766 json_sub,
12767 "txAdvertisedAndReceived");
12768 else if (
12769 CHECK_FLAG(
12770 p->af_cap
12771 [afi]
12772 [safi],
12773 PEER_CAP_ADDPATH_AF_TX_ADV))
12774 json_object_boolean_true_add(
12775 json_sub,
12776 "txAdvertised");
12777 else if (
12778 CHECK_FLAG(
12779 p->af_cap
12780 [afi]
12781 [safi],
12782 PEER_CAP_ADDPATH_AF_TX_RCV))
12783 json_object_boolean_true_add(
12784 json_sub,
12785 "txReceived");
12786 }
12787
12788 if (CHECK_FLAG(
12789 p->af_cap[afi]
12790 [safi],
12791 PEER_CAP_ADDPATH_AF_RX_ADV)
12792 || CHECK_FLAG(
12793 p->af_cap[afi]
12794 [safi],
12795 PEER_CAP_ADDPATH_AF_RX_RCV)) {
12796 if (CHECK_FLAG(
12797 p->af_cap
12798 [afi]
12799 [safi],
12800 PEER_CAP_ADDPATH_AF_RX_ADV)
12801 && CHECK_FLAG(
12802 p->af_cap
12803 [afi]
12804 [safi],
12805 PEER_CAP_ADDPATH_AF_RX_RCV))
12806 json_object_boolean_true_add(
12807 json_sub,
12808 "rxAdvertisedAndReceived");
12809 else if (
12810 CHECK_FLAG(
12811 p->af_cap
12812 [afi]
12813 [safi],
12814 PEER_CAP_ADDPATH_AF_RX_ADV))
12815 json_object_boolean_true_add(
12816 json_sub,
12817 "rxAdvertised");
12818 else if (
12819 CHECK_FLAG(
12820 p->af_cap
12821 [afi]
12822 [safi],
12823 PEER_CAP_ADDPATH_AF_RX_RCV))
12824 json_object_boolean_true_add(
12825 json_sub,
12826 "rxReceived");
12827 }
12828
12829 if (CHECK_FLAG(
12830 p->af_cap[afi]
12831 [safi],
12832 PEER_CAP_ADDPATH_AF_TX_ADV)
12833 || CHECK_FLAG(
12834 p->af_cap[afi]
12835 [safi],
12836 PEER_CAP_ADDPATH_AF_TX_RCV)
12837 || CHECK_FLAG(
12838 p->af_cap[afi]
12839 [safi],
12840 PEER_CAP_ADDPATH_AF_RX_ADV)
12841 || CHECK_FLAG(
12842 p->af_cap[afi]
12843 [safi],
12844 PEER_CAP_ADDPATH_AF_RX_RCV))
12845 json_object_object_add(
12846 json_add,
12847 print_store,
12848 json_sub);
12849 else
12850 json_object_free(
12851 json_sub);
12852 }
12853
12854 json_object_object_add(
12855 json_cap, "addPath", json_add);
12856 }
12857
12858 /* Dynamic */
12859 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
12860 || CHECK_FLAG(p->cap,
12861 PEER_CAP_DYNAMIC_ADV)) {
12862 if (CHECK_FLAG(p->cap,
12863 PEER_CAP_DYNAMIC_ADV)
12864 && CHECK_FLAG(p->cap,
12865 PEER_CAP_DYNAMIC_RCV))
12866 json_object_string_add(
12867 json_cap, "dynamic",
12868 "advertisedAndReceived");
12869 else if (CHECK_FLAG(
12870 p->cap,
12871 PEER_CAP_DYNAMIC_ADV))
12872 json_object_string_add(
12873 json_cap, "dynamic",
12874 "advertised");
12875 else if (CHECK_FLAG(
12876 p->cap,
12877 PEER_CAP_DYNAMIC_RCV))
12878 json_object_string_add(
12879 json_cap, "dynamic",
12880 "received");
12881 }
12882
12883 /* Extended nexthop */
12884 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
12885 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
12886 json_object *json_nxt = NULL;
12887 const char *print_store;
12888
12889
12890 if (CHECK_FLAG(p->cap,
12891 PEER_CAP_ENHE_ADV)
12892 && CHECK_FLAG(p->cap,
12893 PEER_CAP_ENHE_RCV))
12894 json_object_string_add(
12895 json_cap,
12896 "extendedNexthop",
12897 "advertisedAndReceived");
12898 else if (CHECK_FLAG(p->cap,
12899 PEER_CAP_ENHE_ADV))
12900 json_object_string_add(
12901 json_cap,
12902 "extendedNexthop",
12903 "advertised");
12904 else if (CHECK_FLAG(p->cap,
12905 PEER_CAP_ENHE_RCV))
12906 json_object_string_add(
12907 json_cap,
12908 "extendedNexthop",
12909 "received");
12910
12911 if (CHECK_FLAG(p->cap,
12912 PEER_CAP_ENHE_RCV)) {
12913 json_nxt =
12914 json_object_new_object();
12915
12916 for (safi = SAFI_UNICAST;
12917 safi < SAFI_MAX; safi++) {
12918 if (CHECK_FLAG(
12919 p->af_cap
12920 [AFI_IP]
12921 [safi],
12922 PEER_CAP_ENHE_AF_RCV)) {
12923 print_store = get_afi_safi_str(
12924 AFI_IP,
12925 safi, true);
12926 json_object_string_add(
12927 json_nxt,
12928 print_store,
12929 "recieved"); /* misspelled for compatibility */
12930 }
12931 }
12932 json_object_object_add(
12933 json_cap,
12934 "extendedNexthopFamililesByPeer",
12935 json_nxt);
12936 }
12937 }
12938
12939 /* Route Refresh */
12940 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
12941 || CHECK_FLAG(p->cap,
12942 PEER_CAP_REFRESH_NEW_RCV)
12943 || CHECK_FLAG(p->cap,
12944 PEER_CAP_REFRESH_OLD_RCV)) {
12945 if (CHECK_FLAG(p->cap,
12946 PEER_CAP_REFRESH_ADV)
12947 && (CHECK_FLAG(
12948 p->cap,
12949 PEER_CAP_REFRESH_NEW_RCV)
12950 || CHECK_FLAG(
12951 p->cap,
12952 PEER_CAP_REFRESH_OLD_RCV))) {
12953 if (CHECK_FLAG(
12954 p->cap,
12955 PEER_CAP_REFRESH_OLD_RCV)
12956 && CHECK_FLAG(
12957 p->cap,
12958 PEER_CAP_REFRESH_NEW_RCV))
12959 json_object_string_add(
12960 json_cap,
12961 "routeRefresh",
12962 "advertisedAndReceivedOldNew");
12963 else {
12964 if (CHECK_FLAG(
12965 p->cap,
12966 PEER_CAP_REFRESH_OLD_RCV))
12967 json_object_string_add(
12968 json_cap,
12969 "routeRefresh",
12970 "advertisedAndReceivedOld");
12971 else
12972 json_object_string_add(
12973 json_cap,
12974 "routeRefresh",
12975 "advertisedAndReceivedNew");
12976 }
12977 } else if (
12978 CHECK_FLAG(
12979 p->cap,
12980 PEER_CAP_REFRESH_ADV))
12981 json_object_string_add(
12982 json_cap,
12983 "routeRefresh",
12984 "advertised");
12985 else if (
12986 CHECK_FLAG(
12987 p->cap,
12988 PEER_CAP_REFRESH_NEW_RCV)
12989 || CHECK_FLAG(
12990 p->cap,
12991 PEER_CAP_REFRESH_OLD_RCV))
12992 json_object_string_add(
12993 json_cap,
12994 "routeRefresh",
12995 "received");
12996 }
12997
12998 /* Multiprotocol Extensions */
12999 json_object *json_multi = NULL;
13000 json_multi = json_object_new_object();
13001
13002 FOREACH_AFI_SAFI (afi, safi) {
13003 if (p->afc_adv[afi][safi]
13004 || p->afc_recv[afi][safi]) {
13005 json_object *json_exten = NULL;
13006 json_exten =
13007 json_object_new_object();
13008
13009 if (p->afc_adv[afi][safi]
13010 && p->afc_recv[afi][safi])
13011 json_object_boolean_true_add(
13012 json_exten,
13013 "advertisedAndReceived");
13014 else if (p->afc_adv[afi][safi])
13015 json_object_boolean_true_add(
13016 json_exten,
13017 "advertised");
13018 else if (p->afc_recv[afi][safi])
13019 json_object_boolean_true_add(
13020 json_exten,
13021 "received");
13022
13023 json_object_object_add(
13024 json_multi,
13025 get_afi_safi_str(afi,
13026 safi,
13027 true),
13028 json_exten);
13029 }
13030 }
13031 json_object_object_add(
13032 json_cap, "multiprotocolExtensions",
13033 json_multi);
13034
13035 /* Hostname capabilities */
13036 json_object *json_hname = NULL;
13037
13038 json_hname = json_object_new_object();
13039
13040 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13041 json_object_string_add(
13042 json_hname, "advHostName",
13043 bgp->peer_self->hostname
13044 ? bgp->peer_self
13045 ->hostname
13046 : "n/a");
13047 json_object_string_add(
13048 json_hname, "advDomainName",
13049 bgp->peer_self->domainname
13050 ? bgp->peer_self
13051 ->domainname
13052 : "n/a");
13053 }
13054
13055
13056 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13057 json_object_string_add(
13058 json_hname, "rcvHostName",
13059 p->hostname ? p->hostname
13060 : "n/a");
13061 json_object_string_add(
13062 json_hname, "rcvDomainName",
13063 p->domainname ? p->domainname
13064 : "n/a");
13065 }
13066
13067 json_object_object_add(json_cap, "hostName",
13068 json_hname);
13069
13070 /* Gracefull Restart */
13071 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
13072 || CHECK_FLAG(p->cap,
13073 PEER_CAP_RESTART_ADV)) {
13074 if (CHECK_FLAG(p->cap,
13075 PEER_CAP_RESTART_ADV)
13076 && CHECK_FLAG(p->cap,
13077 PEER_CAP_RESTART_RCV))
13078 json_object_string_add(
13079 json_cap,
13080 "gracefulRestart",
13081 "advertisedAndReceived");
13082 else if (CHECK_FLAG(
13083 p->cap,
13084 PEER_CAP_RESTART_ADV))
13085 json_object_string_add(
13086 json_cap,
13087 "gracefulRestartCapability",
13088 "advertised");
13089 else if (CHECK_FLAG(
13090 p->cap,
13091 PEER_CAP_RESTART_RCV))
13092 json_object_string_add(
13093 json_cap,
13094 "gracefulRestartCapability",
13095 "received");
13096
13097 if (CHECK_FLAG(p->cap,
13098 PEER_CAP_RESTART_RCV)) {
13099 int restart_af_count = 0;
13100 json_object *json_restart =
13101 NULL;
13102 json_restart =
13103 json_object_new_object();
13104
13105 json_object_int_add(
13106 json_cap,
13107 "gracefulRestartRemoteTimerMsecs",
13108 p->v_gr_restart * 1000);
13109
13110 FOREACH_AFI_SAFI (afi, safi) {
13111 if (CHECK_FLAG(
13112 p->af_cap
13113 [afi]
13114 [safi],
13115 PEER_CAP_RESTART_AF_RCV)) {
13116 json_object *
13117 json_sub =
13118 NULL;
13119 json_sub =
13120 json_object_new_object();
13121
13122 if (CHECK_FLAG(
13123 p->af_cap
13124 [afi]
13125 [safi],
13126 PEER_CAP_RESTART_AF_PRESERVE_RCV))
13127 json_object_boolean_true_add(
13128 json_sub,
13129 "preserved");
13130 restart_af_count++;
13131 json_object_object_add(
13132 json_restart,
13133 get_afi_safi_str(
13134 afi,
13135 safi,
13136 true),
13137 json_sub);
13138 }
13139 }
13140 if (!restart_af_count) {
13141 json_object_string_add(
13142 json_cap,
13143 "addressFamiliesByPeer",
13144 "none");
13145 json_object_free(
13146 json_restart);
13147 } else
13148 json_object_object_add(
13149 json_cap,
13150 "addressFamiliesByPeer",
13151 json_restart);
13152 }
13153 }
13154 json_object_object_add(json_neigh,
13155 "neighborCapabilities",
13156 json_cap);
13157 } else {
13158 vty_out(vty, " Neighbor capabilities:\n");
13159
13160 /* AS4 */
13161 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
13162 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13163 vty_out(vty, " 4 Byte AS:");
13164 if (CHECK_FLAG(p->cap,
13165 PEER_CAP_AS4_ADV))
13166 vty_out(vty, " advertised");
13167 if (CHECK_FLAG(p->cap,
13168 PEER_CAP_AS4_RCV))
13169 vty_out(vty, " %sreceived",
13170 CHECK_FLAG(
13171 p->cap,
13172 PEER_CAP_AS4_ADV)
13173 ? "and "
13174 : "");
13175 vty_out(vty, "\n");
13176 }
13177
13178 /* AddPath */
13179 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
13180 || CHECK_FLAG(p->cap,
13181 PEER_CAP_ADDPATH_ADV)) {
13182 vty_out(vty, " AddPath:\n");
13183
13184 FOREACH_AFI_SAFI (afi, safi) {
13185 if (CHECK_FLAG(
13186 p->af_cap[afi]
13187 [safi],
13188 PEER_CAP_ADDPATH_AF_TX_ADV)
13189 || CHECK_FLAG(
13190 p->af_cap[afi]
13191 [safi],
13192 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13193 vty_out(vty,
13194 " %s: TX ",
13195 get_afi_safi_str(
13196 afi,
13197 safi,
13198 false));
13199
13200 if (CHECK_FLAG(
13201 p->af_cap
13202 [afi]
13203 [safi],
13204 PEER_CAP_ADDPATH_AF_TX_ADV))
13205 vty_out(vty,
13206 "advertised %s",
13207 get_afi_safi_str(
13208 afi,
13209 safi,
13210 false));
13211
13212 if (CHECK_FLAG(
13213 p->af_cap
13214 [afi]
13215 [safi],
13216 PEER_CAP_ADDPATH_AF_TX_RCV))
13217 vty_out(vty,
13218 "%sreceived",
13219 CHECK_FLAG(
13220 p->af_cap
13221 [afi]
13222 [safi],
13223 PEER_CAP_ADDPATH_AF_TX_ADV)
13224 ? " and "
13225 : "");
13226
13227 vty_out(vty, "\n");
13228 }
13229
13230 if (CHECK_FLAG(
13231 p->af_cap[afi]
13232 [safi],
13233 PEER_CAP_ADDPATH_AF_RX_ADV)
13234 || CHECK_FLAG(
13235 p->af_cap[afi]
13236 [safi],
13237 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13238 vty_out(vty,
13239 " %s: RX ",
13240 get_afi_safi_str(
13241 afi,
13242 safi,
13243 false));
13244
13245 if (CHECK_FLAG(
13246 p->af_cap
13247 [afi]
13248 [safi],
13249 PEER_CAP_ADDPATH_AF_RX_ADV))
13250 vty_out(vty,
13251 "advertised %s",
13252 get_afi_safi_str(
13253 afi,
13254 safi,
13255 false));
13256
13257 if (CHECK_FLAG(
13258 p->af_cap
13259 [afi]
13260 [safi],
13261 PEER_CAP_ADDPATH_AF_RX_RCV))
13262 vty_out(vty,
13263 "%sreceived",
13264 CHECK_FLAG(
13265 p->af_cap
13266 [afi]
13267 [safi],
13268 PEER_CAP_ADDPATH_AF_RX_ADV)
13269 ? " and "
13270 : "");
13271
13272 vty_out(vty, "\n");
13273 }
13274 }
13275 }
13276
13277 /* Dynamic */
13278 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
13279 || CHECK_FLAG(p->cap,
13280 PEER_CAP_DYNAMIC_ADV)) {
13281 vty_out(vty, " Dynamic:");
13282 if (CHECK_FLAG(p->cap,
13283 PEER_CAP_DYNAMIC_ADV))
13284 vty_out(vty, " advertised");
13285 if (CHECK_FLAG(p->cap,
13286 PEER_CAP_DYNAMIC_RCV))
13287 vty_out(vty, " %sreceived",
13288 CHECK_FLAG(
13289 p->cap,
13290 PEER_CAP_DYNAMIC_ADV)
13291 ? "and "
13292 : "");
13293 vty_out(vty, "\n");
13294 }
13295
13296 /* Extended nexthop */
13297 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
13298 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13299 vty_out(vty, " Extended nexthop:");
13300 if (CHECK_FLAG(p->cap,
13301 PEER_CAP_ENHE_ADV))
13302 vty_out(vty, " advertised");
13303 if (CHECK_FLAG(p->cap,
13304 PEER_CAP_ENHE_RCV))
13305 vty_out(vty, " %sreceived",
13306 CHECK_FLAG(
13307 p->cap,
13308 PEER_CAP_ENHE_ADV)
13309 ? "and "
13310 : "");
13311 vty_out(vty, "\n");
13312
13313 if (CHECK_FLAG(p->cap,
13314 PEER_CAP_ENHE_RCV)) {
13315 vty_out(vty,
13316 " Address families by peer:\n ");
13317 for (safi = SAFI_UNICAST;
13318 safi < SAFI_MAX; safi++)
13319 if (CHECK_FLAG(
13320 p->af_cap
13321 [AFI_IP]
13322 [safi],
13323 PEER_CAP_ENHE_AF_RCV))
13324 vty_out(vty,
13325 " %s\n",
13326 get_afi_safi_str(
13327 AFI_IP,
13328 safi,
13329 false));
13330 }
13331 }
13332
13333 /* Route Refresh */
13334 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
13335 || CHECK_FLAG(p->cap,
13336 PEER_CAP_REFRESH_NEW_RCV)
13337 || CHECK_FLAG(p->cap,
13338 PEER_CAP_REFRESH_OLD_RCV)) {
13339 vty_out(vty, " Route refresh:");
13340 if (CHECK_FLAG(p->cap,
13341 PEER_CAP_REFRESH_ADV))
13342 vty_out(vty, " advertised");
13343 if (CHECK_FLAG(p->cap,
13344 PEER_CAP_REFRESH_NEW_RCV)
13345 || CHECK_FLAG(
13346 p->cap,
13347 PEER_CAP_REFRESH_OLD_RCV))
13348 vty_out(vty, " %sreceived(%s)",
13349 CHECK_FLAG(
13350 p->cap,
13351 PEER_CAP_REFRESH_ADV)
13352 ? "and "
13353 : "",
13354 (CHECK_FLAG(
13355 p->cap,
13356 PEER_CAP_REFRESH_OLD_RCV)
13357 && CHECK_FLAG(
13358 p->cap,
13359 PEER_CAP_REFRESH_NEW_RCV))
13360 ? "old & new"
13361 : CHECK_FLAG(
13362 p->cap,
13363 PEER_CAP_REFRESH_OLD_RCV)
13364 ? "old"
13365 : "new");
13366
13367 vty_out(vty, "\n");
13368 }
13369
13370 /* Multiprotocol Extensions */
13371 FOREACH_AFI_SAFI (afi, safi)
13372 if (p->afc_adv[afi][safi]
13373 || p->afc_recv[afi][safi]) {
13374 vty_out(vty,
13375 " Address Family %s:",
13376 get_afi_safi_str(
13377 afi,
13378 safi,
13379 false));
13380 if (p->afc_adv[afi][safi])
13381 vty_out(vty,
13382 " advertised");
13383 if (p->afc_recv[afi][safi])
13384 vty_out(vty,
13385 " %sreceived",
13386 p->afc_adv[afi]
13387 [safi]
13388 ? "and "
13389 : "");
13390 vty_out(vty, "\n");
13391 }
13392
13393 /* Hostname capability */
13394 vty_out(vty, " Hostname Capability:");
13395
13396 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13397 vty_out(vty,
13398 " advertised (name: %s,domain name: %s)",
13399 bgp->peer_self->hostname
13400 ? bgp->peer_self
13401 ->hostname
13402 : "n/a",
13403 bgp->peer_self->domainname
13404 ? bgp->peer_self
13405 ->domainname
13406 : "n/a");
13407 } else {
13408 vty_out(vty, " not advertised");
13409 }
13410
13411 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13412 vty_out(vty,
13413 " received (name: %s,domain name: %s)",
13414 p->hostname ? p->hostname
13415 : "n/a",
13416 p->domainname ? p->domainname
13417 : "n/a");
13418 } else {
13419 vty_out(vty, " not received");
13420 }
13421
13422 vty_out(vty, "\n");
13423
13424 /* Graceful Restart */
13425 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
13426 || CHECK_FLAG(p->cap,
13427 PEER_CAP_RESTART_ADV)) {
13428 vty_out(vty,
13429 " Graceful Restart Capability:");
13430 if (CHECK_FLAG(p->cap,
13431 PEER_CAP_RESTART_ADV))
13432 vty_out(vty, " advertised");
13433 if (CHECK_FLAG(p->cap,
13434 PEER_CAP_RESTART_RCV))
13435 vty_out(vty, " %sreceived",
13436 CHECK_FLAG(
13437 p->cap,
13438 PEER_CAP_RESTART_ADV)
13439 ? "and "
13440 : "");
13441 vty_out(vty, "\n");
13442
13443 if (CHECK_FLAG(p->cap,
13444 PEER_CAP_RESTART_RCV)) {
13445 int restart_af_count = 0;
13446
13447 vty_out(vty,
13448 " Remote Restart timer is %d seconds\n",
13449 p->v_gr_restart);
13450 vty_out(vty,
13451 " Address families by peer:\n ");
13452
13453 FOREACH_AFI_SAFI (afi, safi)
13454 if (CHECK_FLAG(
13455 p->af_cap
13456 [afi]
13457 [safi],
13458 PEER_CAP_RESTART_AF_RCV)) {
13459 vty_out(vty,
13460 "%s%s(%s)",
13461 restart_af_count
13462 ? ", "
13463 : "",
13464 get_afi_safi_str(
13465 afi,
13466 safi,
13467 false),
13468 CHECK_FLAG(
13469 p->af_cap
13470 [afi]
13471 [safi],
13472 PEER_CAP_RESTART_AF_PRESERVE_RCV)
13473 ? "preserved"
13474 : "not preserved");
13475 restart_af_count++;
13476 }
13477 if (!restart_af_count)
13478 vty_out(vty, "none");
13479 vty_out(vty, "\n");
13480 }
13481 } /* Gracefull Restart */
13482 }
13483 }
13484 }
13485
13486 /* graceful restart information */
13487 json_object *json_grace = NULL;
13488 json_object *json_grace_send = NULL;
13489 json_object *json_grace_recv = NULL;
13490 int eor_send_af_count = 0;
13491 int eor_receive_af_count = 0;
13492
13493 if (use_json) {
13494 json_grace = json_object_new_object();
13495 json_grace_send = json_object_new_object();
13496 json_grace_recv = json_object_new_object();
13497
13498 if ((p->status == Established)
13499 && CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13500 FOREACH_AFI_SAFI (afi, safi) {
13501 if (CHECK_FLAG(p->af_sflags[afi][safi],
13502 PEER_STATUS_EOR_SEND)) {
13503 json_object_boolean_true_add(
13504 json_grace_send,
13505 get_afi_safi_str(afi,
13506 safi,
13507 true));
13508 eor_send_af_count++;
13509 }
13510 }
13511 FOREACH_AFI_SAFI (afi, safi) {
13512 if (CHECK_FLAG(
13513 p->af_sflags[afi][safi],
13514 PEER_STATUS_EOR_RECEIVED)) {
13515 json_object_boolean_true_add(
13516 json_grace_recv,
13517 get_afi_safi_str(afi,
13518 safi,
13519 true));
13520 eor_receive_af_count++;
13521 }
13522 }
13523 }
13524 json_object_object_add(json_grace, "endOfRibSend",
13525 json_grace_send);
13526 json_object_object_add(json_grace, "endOfRibRecv",
13527 json_grace_recv);
13528
13529
13530 if (p->t_gr_restart)
13531 json_object_int_add(json_grace,
13532 "gracefulRestartTimerMsecs",
13533 thread_timer_remain_second(
13534 p->t_gr_restart)
13535 * 1000);
13536
13537 if (p->t_gr_stale)
13538 json_object_int_add(
13539 json_grace,
13540 "gracefulStalepathTimerMsecs",
13541 thread_timer_remain_second(
13542 p->t_gr_stale)
13543 * 1000);
13544 /* more gr info in new format */
13545 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json,
13546 json_grace);
13547 json_object_object_add(
13548 json_neigh, "gracefulRestartInfo", json_grace);
13549 } else {
13550 vty_out(vty, " Graceful restart information:\n");
13551 if ((p->status == Established)
13552 && CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13553
13554 vty_out(vty, " End-of-RIB send: ");
13555 FOREACH_AFI_SAFI (afi, safi) {
13556 if (CHECK_FLAG(p->af_sflags[afi][safi],
13557 PEER_STATUS_EOR_SEND)) {
13558 vty_out(vty, "%s%s",
13559 eor_send_af_count ? ", "
13560 : "",
13561 get_afi_safi_str(
13562 afi, safi,
13563 false));
13564 eor_send_af_count++;
13565 }
13566 }
13567 vty_out(vty, "\n");
13568 vty_out(vty, " End-of-RIB received: ");
13569 FOREACH_AFI_SAFI (afi, safi) {
13570 if (CHECK_FLAG(
13571 p->af_sflags[afi][safi],
13572 PEER_STATUS_EOR_RECEIVED)) {
13573 vty_out(vty, "%s%s",
13574 eor_receive_af_count
13575 ? ", "
13576 : "",
13577 get_afi_safi_str(afi,
13578 safi,
13579 false));
13580 eor_receive_af_count++;
13581 }
13582 }
13583 vty_out(vty, "\n");
13584 }
13585
13586 if (p->t_gr_restart)
13587 vty_out(vty,
13588 " The remaining time of restart timer is %ld\n",
13589 thread_timer_remain_second(
13590 p->t_gr_restart));
13591
13592 if (p->t_gr_stale)
13593 vty_out(vty,
13594 " The remaining time of stalepath timer is %ld\n",
13595 thread_timer_remain_second(
13596 p->t_gr_stale));
13597
13598 /* more gr info in new format */
13599 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, NULL);
13600 }
13601
13602 if (use_json) {
13603 json_object *json_stat = NULL;
13604 json_stat = json_object_new_object();
13605 /* Packet counts. */
13606
13607 atomic_size_t outq_count, inq_count;
13608 outq_count = atomic_load_explicit(&p->obuf->count,
13609 memory_order_relaxed);
13610 inq_count = atomic_load_explicit(&p->ibuf->count,
13611 memory_order_relaxed);
13612
13613 json_object_int_add(json_stat, "depthInq",
13614 (unsigned long)inq_count);
13615 json_object_int_add(json_stat, "depthOutq",
13616 (unsigned long)outq_count);
13617 json_object_int_add(json_stat, "opensSent",
13618 atomic_load_explicit(&p->open_out,
13619 memory_order_relaxed));
13620 json_object_int_add(json_stat, "opensRecv",
13621 atomic_load_explicit(&p->open_in,
13622 memory_order_relaxed));
13623 json_object_int_add(json_stat, "notificationsSent",
13624 atomic_load_explicit(&p->notify_out,
13625 memory_order_relaxed));
13626 json_object_int_add(json_stat, "notificationsRecv",
13627 atomic_load_explicit(&p->notify_in,
13628 memory_order_relaxed));
13629 json_object_int_add(json_stat, "updatesSent",
13630 atomic_load_explicit(&p->update_out,
13631 memory_order_relaxed));
13632 json_object_int_add(json_stat, "updatesRecv",
13633 atomic_load_explicit(&p->update_in,
13634 memory_order_relaxed));
13635 json_object_int_add(json_stat, "keepalivesSent",
13636 atomic_load_explicit(&p->keepalive_out,
13637 memory_order_relaxed));
13638 json_object_int_add(json_stat, "keepalivesRecv",
13639 atomic_load_explicit(&p->keepalive_in,
13640 memory_order_relaxed));
13641 json_object_int_add(json_stat, "routeRefreshSent",
13642 atomic_load_explicit(&p->refresh_out,
13643 memory_order_relaxed));
13644 json_object_int_add(json_stat, "routeRefreshRecv",
13645 atomic_load_explicit(&p->refresh_in,
13646 memory_order_relaxed));
13647 json_object_int_add(json_stat, "capabilitySent",
13648 atomic_load_explicit(&p->dynamic_cap_out,
13649 memory_order_relaxed));
13650 json_object_int_add(json_stat, "capabilityRecv",
13651 atomic_load_explicit(&p->dynamic_cap_in,
13652 memory_order_relaxed));
13653 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
13654 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
13655 json_object_object_add(json_neigh, "messageStats", json_stat);
13656 } else {
13657 atomic_size_t outq_count, inq_count;
13658 outq_count = atomic_load_explicit(&p->obuf->count,
13659 memory_order_relaxed);
13660 inq_count = atomic_load_explicit(&p->ibuf->count,
13661 memory_order_relaxed);
13662
13663 /* Packet counts. */
13664 vty_out(vty, " Message statistics:\n");
13665 vty_out(vty, " Inq depth is %zu\n", inq_count);
13666 vty_out(vty, " Outq depth is %zu\n", outq_count);
13667 vty_out(vty, " Sent Rcvd\n");
13668 vty_out(vty, " Opens: %10d %10d\n",
13669 atomic_load_explicit(&p->open_out,
13670 memory_order_relaxed),
13671 atomic_load_explicit(&p->open_in,
13672 memory_order_relaxed));
13673 vty_out(vty, " Notifications: %10d %10d\n",
13674 atomic_load_explicit(&p->notify_out,
13675 memory_order_relaxed),
13676 atomic_load_explicit(&p->notify_in,
13677 memory_order_relaxed));
13678 vty_out(vty, " Updates: %10d %10d\n",
13679 atomic_load_explicit(&p->update_out,
13680 memory_order_relaxed),
13681 atomic_load_explicit(&p->update_in,
13682 memory_order_relaxed));
13683 vty_out(vty, " Keepalives: %10d %10d\n",
13684 atomic_load_explicit(&p->keepalive_out,
13685 memory_order_relaxed),
13686 atomic_load_explicit(&p->keepalive_in,
13687 memory_order_relaxed));
13688 vty_out(vty, " Route Refresh: %10d %10d\n",
13689 atomic_load_explicit(&p->refresh_out,
13690 memory_order_relaxed),
13691 atomic_load_explicit(&p->refresh_in,
13692 memory_order_relaxed));
13693 vty_out(vty, " Capability: %10d %10d\n",
13694 atomic_load_explicit(&p->dynamic_cap_out,
13695 memory_order_relaxed),
13696 atomic_load_explicit(&p->dynamic_cap_in,
13697 memory_order_relaxed));
13698 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
13699 PEER_TOTAL_RX(p));
13700 }
13701
13702 if (use_json) {
13703 /* advertisement-interval */
13704 json_object_int_add(json_neigh,
13705 "minBtwnAdvertisementRunsTimerMsecs",
13706 p->v_routeadv * 1000);
13707
13708 /* Update-source. */
13709 if (p->update_if || p->update_source) {
13710 if (p->update_if)
13711 json_object_string_add(json_neigh,
13712 "updateSource",
13713 p->update_if);
13714 else if (p->update_source)
13715 json_object_string_add(
13716 json_neigh, "updateSource",
13717 sockunion2str(p->update_source, buf1,
13718 SU_ADDRSTRLEN));
13719 }
13720 } else {
13721 /* advertisement-interval */
13722 vty_out(vty,
13723 " Minimum time between advertisement runs is %d seconds\n",
13724 p->v_routeadv);
13725
13726 /* Update-source. */
13727 if (p->update_if || p->update_source) {
13728 vty_out(vty, " Update source is ");
13729 if (p->update_if)
13730 vty_out(vty, "%s", p->update_if);
13731 else if (p->update_source)
13732 vty_out(vty, "%s",
13733 sockunion2str(p->update_source, buf1,
13734 SU_ADDRSTRLEN));
13735 vty_out(vty, "\n");
13736 }
13737
13738 vty_out(vty, "\n");
13739 }
13740
13741 /* Address Family Information */
13742 json_object *json_hold = NULL;
13743
13744 if (use_json)
13745 json_hold = json_object_new_object();
13746
13747 FOREACH_AFI_SAFI (afi, safi)
13748 if (p->afc[afi][safi])
13749 bgp_show_peer_afi(vty, p, afi, safi, use_json,
13750 json_hold);
13751
13752 if (use_json) {
13753 json_object_object_add(json_neigh, "addressFamilyInfo",
13754 json_hold);
13755 json_object_int_add(json_neigh, "connectionsEstablished",
13756 p->established);
13757 json_object_int_add(json_neigh, "connectionsDropped",
13758 p->dropped);
13759 } else
13760 vty_out(vty, " Connections established %d; dropped %d\n",
13761 p->established, p->dropped);
13762
13763 if (!p->last_reset) {
13764 if (use_json)
13765 json_object_string_add(json_neigh, "lastReset",
13766 "never");
13767 else
13768 vty_out(vty, " Last reset never\n");
13769 } else {
13770 if (use_json) {
13771 time_t uptime;
13772 struct tm tm;
13773
13774 uptime = bgp_clock();
13775 uptime -= p->resettime;
13776 gmtime_r(&uptime, &tm);
13777
13778 json_object_int_add(json_neigh, "lastResetTimerMsecs",
13779 (tm.tm_sec * 1000)
13780 + (tm.tm_min * 60000)
13781 + (tm.tm_hour * 3600000));
13782 bgp_show_peer_reset(NULL, p, json_neigh, true);
13783 } else {
13784 vty_out(vty, " Last reset %s, ",
13785 peer_uptime(p->resettime, timebuf,
13786 BGP_UPTIME_LEN, 0, NULL));
13787
13788 bgp_show_peer_reset(vty, p, NULL, false);
13789 if (p->last_reset_cause_size) {
13790 msg = p->last_reset_cause;
13791 vty_out(vty,
13792 " Message received that caused BGP to send a NOTIFICATION:\n ");
13793 for (i = 1; i <= p->last_reset_cause_size;
13794 i++) {
13795 vty_out(vty, "%02X", *msg++);
13796
13797 if (i != p->last_reset_cause_size) {
13798 if (i % 16 == 0) {
13799 vty_out(vty, "\n ");
13800 } else if (i % 4 == 0) {
13801 vty_out(vty, " ");
13802 }
13803 }
13804 }
13805 vty_out(vty, "\n");
13806 }
13807 }
13808 }
13809
13810 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
13811 if (use_json)
13812 json_object_boolean_true_add(json_neigh,
13813 "prefixesConfigExceedMax");
13814 else
13815 vty_out(vty,
13816 " Peer had exceeded the max. no. of prefixes configured.\n");
13817
13818 if (p->t_pmax_restart) {
13819 if (use_json) {
13820 json_object_boolean_true_add(
13821 json_neigh, "reducePrefixNumFrom");
13822 json_object_int_add(json_neigh,
13823 "restartInTimerMsec",
13824 thread_timer_remain_second(
13825 p->t_pmax_restart)
13826 * 1000);
13827 } else
13828 vty_out(vty,
13829 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
13830 p->host, thread_timer_remain_second(
13831 p->t_pmax_restart));
13832 } else {
13833 if (use_json)
13834 json_object_boolean_true_add(
13835 json_neigh,
13836 "reducePrefixNumAndClearIpBgp");
13837 else
13838 vty_out(vty,
13839 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
13840 p->host);
13841 }
13842 }
13843
13844 /* EBGP Multihop and GTSM */
13845 if (p->sort != BGP_PEER_IBGP) {
13846 if (use_json) {
13847 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
13848 json_object_int_add(json_neigh,
13849 "externalBgpNbrMaxHopsAway",
13850 p->gtsm_hops);
13851 else if (p->ttl > BGP_DEFAULT_TTL)
13852 json_object_int_add(json_neigh,
13853 "externalBgpNbrMaxHopsAway",
13854 p->ttl);
13855 } else {
13856 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
13857 vty_out(vty,
13858 " External BGP neighbor may be up to %d hops away.\n",
13859 p->gtsm_hops);
13860 else if (p->ttl > BGP_DEFAULT_TTL)
13861 vty_out(vty,
13862 " External BGP neighbor may be up to %d hops away.\n",
13863 p->ttl);
13864 }
13865 } else {
13866 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED) {
13867 if (use_json)
13868 json_object_int_add(json_neigh,
13869 "internalBgpNbrMaxHopsAway",
13870 p->gtsm_hops);
13871 else
13872 vty_out(vty,
13873 " Internal BGP neighbor may be up to %d hops away.\n",
13874 p->gtsm_hops);
13875 }
13876 }
13877
13878 /* Local address. */
13879 if (p->su_local) {
13880 if (use_json) {
13881 json_object_string_add(json_neigh, "hostLocal",
13882 sockunion2str(p->su_local, buf1,
13883 SU_ADDRSTRLEN));
13884 json_object_int_add(json_neigh, "portLocal",
13885 ntohs(p->su_local->sin.sin_port));
13886 } else
13887 vty_out(vty, "Local host: %s, Local port: %d\n",
13888 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
13889 ntohs(p->su_local->sin.sin_port));
13890 }
13891
13892 /* Remote address. */
13893 if (p->su_remote) {
13894 if (use_json) {
13895 json_object_string_add(json_neigh, "hostForeign",
13896 sockunion2str(p->su_remote, buf1,
13897 SU_ADDRSTRLEN));
13898 json_object_int_add(json_neigh, "portForeign",
13899 ntohs(p->su_remote->sin.sin_port));
13900 } else
13901 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
13902 sockunion2str(p->su_remote, buf1,
13903 SU_ADDRSTRLEN),
13904 ntohs(p->su_remote->sin.sin_port));
13905 }
13906
13907 /* Nexthop display. */
13908 if (p->su_local) {
13909 if (use_json) {
13910 json_object_string_add(json_neigh, "nexthop",
13911 inet_ntop(AF_INET,
13912 &p->nexthop.v4, buf1,
13913 sizeof(buf1)));
13914 json_object_string_add(json_neigh, "nexthopGlobal",
13915 inet_ntop(AF_INET6,
13916 &p->nexthop.v6_global,
13917 buf1, sizeof(buf1)));
13918 json_object_string_add(json_neigh, "nexthopLocal",
13919 inet_ntop(AF_INET6,
13920 &p->nexthop.v6_local,
13921 buf1, sizeof(buf1)));
13922 if (p->shared_network)
13923 json_object_string_add(json_neigh,
13924 "bgpConnection",
13925 "sharedNetwork");
13926 else
13927 json_object_string_add(json_neigh,
13928 "bgpConnection",
13929 "nonSharedNetwork");
13930 } else {
13931 vty_out(vty, "Nexthop: %s\n",
13932 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
13933 sizeof(buf1)));
13934 vty_out(vty, "Nexthop global: %s\n",
13935 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
13936 sizeof(buf1)));
13937 vty_out(vty, "Nexthop local: %s\n",
13938 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
13939 sizeof(buf1)));
13940 vty_out(vty, "BGP connection: %s\n",
13941 p->shared_network ? "shared network"
13942 : "non shared network");
13943 }
13944 }
13945
13946 /* Timer information. */
13947 if (use_json) {
13948 json_object_int_add(json_neigh, "connectRetryTimer",
13949 p->v_connect);
13950 if (p->status == Established && p->rtt)
13951 json_object_int_add(json_neigh, "estimatedRttInMsecs",
13952 p->rtt);
13953 if (p->t_start)
13954 json_object_int_add(
13955 json_neigh, "nextStartTimerDueInMsecs",
13956 thread_timer_remain_second(p->t_start) * 1000);
13957 if (p->t_connect)
13958 json_object_int_add(
13959 json_neigh, "nextConnectTimerDueInMsecs",
13960 thread_timer_remain_second(p->t_connect)
13961 * 1000);
13962 if (p->t_routeadv) {
13963 json_object_int_add(json_neigh, "mraiInterval",
13964 p->v_routeadv);
13965 json_object_int_add(
13966 json_neigh, "mraiTimerExpireInMsecs",
13967 thread_timer_remain_second(p->t_routeadv)
13968 * 1000);
13969 }
13970 if (p->password)
13971 json_object_int_add(json_neigh, "authenticationEnabled",
13972 1);
13973
13974 if (p->t_read)
13975 json_object_string_add(json_neigh, "readThread", "on");
13976 else
13977 json_object_string_add(json_neigh, "readThread", "off");
13978
13979 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
13980 json_object_string_add(json_neigh, "writeThread", "on");
13981 else
13982 json_object_string_add(json_neigh, "writeThread",
13983 "off");
13984 } else {
13985 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
13986 p->v_connect);
13987 if (p->status == Established && p->rtt)
13988 vty_out(vty, "Estimated round trip time: %d ms\n",
13989 p->rtt);
13990 if (p->t_start)
13991 vty_out(vty, "Next start timer due in %ld seconds\n",
13992 thread_timer_remain_second(p->t_start));
13993 if (p->t_connect)
13994 vty_out(vty, "Next connect timer due in %ld seconds\n",
13995 thread_timer_remain_second(p->t_connect));
13996 if (p->t_routeadv)
13997 vty_out(vty,
13998 "MRAI (interval %u) timer expires in %ld seconds\n",
13999 p->v_routeadv,
14000 thread_timer_remain_second(p->t_routeadv));
14001 if (p->password)
14002 vty_out(vty, "Peer Authentication Enabled\n");
14003
14004 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
14005 p->t_read ? "on" : "off",
14006 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
14007 ? "on"
14008 : "off", p->fd);
14009 }
14010
14011 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
14012 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
14013 bgp_capability_vty_out(vty, p, use_json, json_neigh);
14014
14015 if (!use_json)
14016 vty_out(vty, "\n");
14017
14018 /* BFD information. */
14019 bgp_bfd_show_info(vty, p, use_json, json_neigh);
14020
14021 if (use_json) {
14022 if (p->conf_if) /* Configured interface name. */
14023 json_object_object_add(json, p->conf_if, json_neigh);
14024 else /* Configured IP address. */
14025 json_object_object_add(json, p->host, json_neigh);
14026 }
14027 }
14028
14029 static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
14030 enum show_type type,
14031 union sockunion *su,
14032 const char *conf_if, afi_t afi,
14033 bool use_json)
14034 {
14035 struct listnode *node, *nnode;
14036 struct peer *peer;
14037 int find = 0;
14038 safi_t safi = SAFI_UNICAST;
14039 json_object *json = NULL;
14040 json_object *json_neighbor = NULL;
14041
14042 if (use_json) {
14043 json = json_object_new_object();
14044 json_neighbor = json_object_new_object();
14045 }
14046
14047 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14048
14049 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14050 continue;
14051
14052 if ((peer->afc[afi][safi]) == 0)
14053 continue;
14054
14055 if (type == show_all) {
14056 bgp_show_peer_gr_status(vty, peer, use_json,
14057 json_neighbor);
14058
14059 if (use_json) {
14060 json_object_object_add(json, peer->host,
14061 json_neighbor);
14062 json_neighbor = NULL;
14063 }
14064
14065 } else if (type == show_peer) {
14066 if (conf_if) {
14067 if ((peer->conf_if
14068 && !strcmp(peer->conf_if, conf_if))
14069 || (peer->hostname
14070 && !strcmp(peer->hostname, conf_if))) {
14071 find = 1;
14072 bgp_show_peer_gr_status(vty, peer,
14073 use_json,
14074 json_neighbor);
14075 }
14076 } else {
14077 if (sockunion_same(&peer->su, su)) {
14078 find = 1;
14079 bgp_show_peer_gr_status(vty, peer,
14080 use_json,
14081 json_neighbor);
14082 }
14083 }
14084 if (use_json && find)
14085 json_object_object_add(json, peer->host,
14086 json_neighbor);
14087 }
14088
14089 if (find) {
14090 json_neighbor = NULL;
14091 break;
14092 }
14093 }
14094
14095 if (type == show_peer && !find) {
14096 if (use_json)
14097 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14098 else
14099 vty_out(vty, "%% No such neighbor\n");
14100 }
14101 if (use_json) {
14102 vty_out(vty, "%s\n",
14103 json_object_to_json_string_ext(
14104 json, JSON_C_TO_STRING_PRETTY));
14105
14106 if (json_neighbor)
14107 json_object_free(json_neighbor);
14108 json_object_free(json);
14109 } else {
14110 vty_out(vty, "\n");
14111 }
14112
14113 return CMD_SUCCESS;
14114 }
14115
14116 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
14117 enum show_type type, union sockunion *su,
14118 const char *conf_if, bool use_json,
14119 json_object *json)
14120 {
14121 struct listnode *node, *nnode;
14122 struct peer *peer;
14123 int find = 0;
14124 bool nbr_output = false;
14125 afi_t afi = AFI_MAX;
14126 safi_t safi = SAFI_MAX;
14127
14128 if (type == show_ipv4_peer || type == show_ipv4_all) {
14129 afi = AFI_IP;
14130 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
14131 afi = AFI_IP6;
14132 }
14133
14134 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14135 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14136 continue;
14137
14138 switch (type) {
14139 case show_all:
14140 bgp_show_peer(vty, peer, use_json, json);
14141 nbr_output = true;
14142 break;
14143 case show_peer:
14144 if (conf_if) {
14145 if ((peer->conf_if
14146 && !strcmp(peer->conf_if, conf_if))
14147 || (peer->hostname
14148 && !strcmp(peer->hostname, conf_if))) {
14149 find = 1;
14150 bgp_show_peer(vty, peer, use_json,
14151 json);
14152 }
14153 } else {
14154 if (sockunion_same(&peer->su, su)) {
14155 find = 1;
14156 bgp_show_peer(vty, peer, use_json,
14157 json);
14158 }
14159 }
14160 break;
14161 case show_ipv4_peer:
14162 case show_ipv6_peer:
14163 FOREACH_SAFI (safi) {
14164 if (peer->afc[afi][safi]) {
14165 if (conf_if) {
14166 if ((peer->conf_if
14167 && !strcmp(peer->conf_if, conf_if))
14168 || (peer->hostname
14169 && !strcmp(peer->hostname, conf_if))) {
14170 find = 1;
14171 bgp_show_peer(vty, peer, use_json,
14172 json);
14173 break;
14174 }
14175 } else {
14176 if (sockunion_same(&peer->su, su)) {
14177 find = 1;
14178 bgp_show_peer(vty, peer, use_json,
14179 json);
14180 break;
14181 }
14182 }
14183 }
14184 }
14185 break;
14186 case show_ipv4_all:
14187 case show_ipv6_all:
14188 FOREACH_SAFI (safi) {
14189 if (peer->afc[afi][safi]) {
14190 bgp_show_peer(vty, peer, use_json, json);
14191 nbr_output = true;
14192 break;
14193 }
14194 }
14195 break;
14196 }
14197 }
14198
14199 if ((type == show_peer || type == show_ipv4_peer ||
14200 type == show_ipv6_peer) && !find) {
14201 if (use_json)
14202 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14203 else
14204 vty_out(vty, "%% No such neighbor in this view/vrf\n");
14205 }
14206
14207 if (type != show_peer && type != show_ipv4_peer &&
14208 type != show_ipv6_peer && !nbr_output && !use_json)
14209 vty_out(vty, "%% No BGP neighbors found\n");
14210
14211 if (use_json) {
14212 vty_out(vty, "%s\n", json_object_to_json_string_ext(
14213 json, JSON_C_TO_STRING_PRETTY));
14214 } else {
14215 vty_out(vty, "\n");
14216 }
14217
14218 return CMD_SUCCESS;
14219 }
14220
14221 static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
14222 enum show_type type,
14223 const char *ip_str,
14224 afi_t afi, bool use_json)
14225 {
14226
14227 int ret;
14228 struct bgp *bgp;
14229 union sockunion su;
14230
14231 bgp = bgp_get_default();
14232
14233 if (!bgp)
14234 return;
14235
14236 if (!use_json)
14237 bgp_show_global_graceful_restart_mode_vty(vty, bgp, use_json,
14238 NULL);
14239
14240 if (ip_str) {
14241 ret = str2sockunion(ip_str, &su);
14242 if (ret < 0)
14243 bgp_show_neighbor_graceful_restart(
14244 vty, bgp, type, NULL, ip_str, afi, use_json);
14245 else
14246 bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
14247 NULL, afi, use_json);
14248 } else
14249 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
14250 afi, use_json);
14251 }
14252
14253 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
14254 enum show_type type,
14255 const char *ip_str,
14256 bool use_json)
14257 {
14258 struct listnode *node, *nnode;
14259 struct bgp *bgp;
14260 union sockunion su;
14261 json_object *json = NULL;
14262 int ret, is_first = 1;
14263 bool nbr_output = false;
14264
14265 if (use_json)
14266 vty_out(vty, "{\n");
14267
14268 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
14269 nbr_output = true;
14270 if (use_json) {
14271 if (!(json = json_object_new_object())) {
14272 flog_err(
14273 EC_BGP_JSON_MEM_ERROR,
14274 "Unable to allocate memory for JSON object");
14275 vty_out(vty,
14276 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
14277 return;
14278 }
14279
14280 json_object_int_add(json, "vrfId",
14281 (bgp->vrf_id == VRF_UNKNOWN)
14282 ? -1
14283 : (int64_t)bgp->vrf_id);
14284 json_object_string_add(
14285 json, "vrfName",
14286 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14287 ? VRF_DEFAULT_NAME
14288 : bgp->name);
14289
14290 if (!is_first)
14291 vty_out(vty, ",\n");
14292 else
14293 is_first = 0;
14294
14295 vty_out(vty, "\"%s\":",
14296 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14297 ? VRF_DEFAULT_NAME
14298 : bgp->name);
14299 } else {
14300 vty_out(vty, "\nInstance %s:\n",
14301 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14302 ? VRF_DEFAULT_NAME
14303 : bgp->name);
14304 }
14305
14306 if (type == show_peer || type == show_ipv4_peer ||
14307 type == show_ipv6_peer) {
14308 ret = str2sockunion(ip_str, &su);
14309 if (ret < 0)
14310 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14311 use_json, json);
14312 else
14313 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14314 use_json, json);
14315 } else {
14316 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
14317 use_json, json);
14318 }
14319 json_object_free(json);
14320 json = NULL;
14321 }
14322
14323 if (use_json)
14324 vty_out(vty, "}\n");
14325 else if (!nbr_output)
14326 vty_out(vty, "%% BGP instance not found\n");
14327 }
14328
14329 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
14330 enum show_type type, const char *ip_str,
14331 bool use_json)
14332 {
14333 int ret;
14334 struct bgp *bgp;
14335 union sockunion su;
14336 json_object *json = NULL;
14337
14338 if (name) {
14339 if (strmatch(name, "all")) {
14340 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
14341 use_json);
14342 return CMD_SUCCESS;
14343 } else {
14344 bgp = bgp_lookup_by_name(name);
14345 if (!bgp) {
14346 if (use_json) {
14347 json = json_object_new_object();
14348 vty_out(vty, "%s\n",
14349 json_object_to_json_string_ext(
14350 json,
14351 JSON_C_TO_STRING_PRETTY));
14352 json_object_free(json);
14353 } else
14354 vty_out(vty,
14355 "%% BGP instance not found\n");
14356
14357 return CMD_WARNING;
14358 }
14359 }
14360 } else {
14361 bgp = bgp_get_default();
14362 }
14363
14364 if (bgp) {
14365 json = json_object_new_object();
14366 if (ip_str) {
14367 ret = str2sockunion(ip_str, &su);
14368 if (ret < 0)
14369 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14370 use_json, json);
14371 else
14372 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14373 use_json, json);
14374 } else {
14375 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
14376 json);
14377 }
14378 json_object_free(json);
14379 } else {
14380 if (use_json)
14381 vty_out(vty, "{}\n");
14382 else
14383 vty_out(vty, "%% BGP instance not found\n");
14384 }
14385
14386 return CMD_SUCCESS;
14387 }
14388
14389
14390
14391 /* "show [ip] bgp neighbors graceful-restart" commands. */
14392 DEFUN (show_ip_bgp_neighbors_gracrful_restart,
14393 show_ip_bgp_neighbors_graceful_restart_cmd,
14394 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
14395 SHOW_STR
14396 BGP_STR
14397 IP_STR
14398 IPV6_STR
14399 NEIGHBOR_STR
14400 "Neighbor to display information about\n"
14401 "Neighbor to display information about\n"
14402 "Neighbor on BGP configured interface\n"
14403 GR_SHOW
14404 JSON_STR)
14405 {
14406 char *sh_arg = NULL;
14407 enum show_type sh_type;
14408 int idx = 0;
14409 afi_t afi = AFI_MAX;
14410 bool uj = use_json(argc, argv);
14411
14412 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
14413 afi = AFI_MAX;
14414
14415 idx++;
14416
14417 if (argv_find(argv, argc, "A.B.C.D", &idx)
14418 || argv_find(argv, argc, "X:X::X:X", &idx)
14419 || argv_find(argv, argc, "WORD", &idx)) {
14420 sh_type = show_peer;
14421 sh_arg = argv[idx]->arg;
14422 } else
14423 sh_type = show_all;
14424
14425 if (!argv_find(argv, argc, "graceful-restart", &idx))
14426 return CMD_SUCCESS;
14427
14428
14429 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
14430 afi, uj);
14431 }
14432
14433 /* "show [ip] bgp neighbors" commands. */
14434 DEFUN (show_ip_bgp_neighbors,
14435 show_ip_bgp_neighbors_cmd,
14436 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
14437 SHOW_STR
14438 IP_STR
14439 BGP_STR
14440 BGP_INSTANCE_HELP_STR
14441 "Address Family\n"
14442 "Address Family\n"
14443 "Detailed information on TCP and BGP neighbor connections\n"
14444 "Neighbor to display information about\n"
14445 "Neighbor to display information about\n"
14446 "Neighbor on BGP configured interface\n"
14447 JSON_STR)
14448 {
14449 char *vrf = NULL;
14450 char *sh_arg = NULL;
14451 enum show_type sh_type;
14452 afi_t afi = AFI_MAX;
14453
14454 bool uj = use_json(argc, argv);
14455
14456 int idx = 0;
14457
14458 /* [<vrf> VIEWVRFNAME] */
14459 if (argv_find(argv, argc, "vrf", &idx)) {
14460 vrf = argv[idx + 1]->arg;
14461 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
14462 vrf = NULL;
14463 } else if (argv_find(argv, argc, "view", &idx))
14464 /* [<view> VIEWVRFNAME] */
14465 vrf = argv[idx + 1]->arg;
14466
14467 idx++;
14468
14469 if (argv_find(argv, argc, "ipv4", &idx)) {
14470 sh_type = show_ipv4_all;
14471 afi = AFI_IP;
14472 } else if (argv_find(argv, argc, "ipv6", &idx)) {
14473 sh_type = show_ipv6_all;
14474 afi = AFI_IP6;
14475 } else {
14476 sh_type = show_all;
14477 }
14478
14479 if (argv_find(argv, argc, "A.B.C.D", &idx)
14480 || argv_find(argv, argc, "X:X::X:X", &idx)
14481 || argv_find(argv, argc, "WORD", &idx)) {
14482 sh_type = show_peer;
14483 sh_arg = argv[idx]->arg;
14484 }
14485
14486 if (sh_type == show_peer && afi == AFI_IP) {
14487 sh_type = show_ipv4_peer;
14488 } else if (sh_type == show_peer && afi == AFI_IP6) {
14489 sh_type = show_ipv6_peer;
14490 }
14491
14492 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
14493 }
14494
14495 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
14496 paths' and `show ip mbgp paths'. Those functions results are the
14497 same.*/
14498 DEFUN (show_ip_bgp_paths,
14499 show_ip_bgp_paths_cmd,
14500 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
14501 SHOW_STR
14502 IP_STR
14503 BGP_STR
14504 BGP_SAFI_HELP_STR
14505 "Path information\n")
14506 {
14507 vty_out(vty, "Address Refcnt Path\n");
14508 aspath_print_all_vty(vty);
14509 return CMD_SUCCESS;
14510 }
14511
14512 #include "hash.h"
14513
14514 static void community_show_all_iterator(struct hash_bucket *bucket,
14515 struct vty *vty)
14516 {
14517 struct community *com;
14518
14519 com = (struct community *)bucket->data;
14520 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
14521 community_str(com, false));
14522 }
14523
14524 /* Show BGP's community internal data. */
14525 DEFUN (show_ip_bgp_community_info,
14526 show_ip_bgp_community_info_cmd,
14527 "show [ip] bgp community-info",
14528 SHOW_STR
14529 IP_STR
14530 BGP_STR
14531 "List all bgp community information\n")
14532 {
14533 vty_out(vty, "Address Refcnt Community\n");
14534
14535 hash_iterate(community_hash(),
14536 (void (*)(struct hash_bucket *,
14537 void *))community_show_all_iterator,
14538 vty);
14539
14540 return CMD_SUCCESS;
14541 }
14542
14543 static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
14544 struct vty *vty)
14545 {
14546 struct lcommunity *lcom;
14547
14548 lcom = (struct lcommunity *)bucket->data;
14549 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
14550 lcommunity_str(lcom, false));
14551 }
14552
14553 /* Show BGP's community internal data. */
14554 DEFUN (show_ip_bgp_lcommunity_info,
14555 show_ip_bgp_lcommunity_info_cmd,
14556 "show ip bgp large-community-info",
14557 SHOW_STR
14558 IP_STR
14559 BGP_STR
14560 "List all bgp large-community information\n")
14561 {
14562 vty_out(vty, "Address Refcnt Large-community\n");
14563
14564 hash_iterate(lcommunity_hash(),
14565 (void (*)(struct hash_bucket *,
14566 void *))lcommunity_show_all_iterator,
14567 vty);
14568
14569 return CMD_SUCCESS;
14570 }
14571 /* Graceful Restart */
14572
14573 static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
14574 struct bgp *bgp,
14575 bool use_json,
14576 json_object *json)
14577 {
14578
14579
14580 vty_out(vty, "\n%s", SHOW_GR_HEADER);
14581
14582 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
14583
14584 switch (bgp_global_gr_mode) {
14585
14586 case GLOBAL_HELPER:
14587 vty_out(vty, "Global BGP GR Mode : Helper\n");
14588 break;
14589
14590 case GLOBAL_GR:
14591 vty_out(vty, "Global BGP GR Mode : Restart\n");
14592 break;
14593
14594 case GLOBAL_DISABLE:
14595 vty_out(vty, "Global BGP GR Mode : Disable\n");
14596 break;
14597
14598 case GLOBAL_INVALID:
14599 vty_out(vty,
14600 "Global BGP GR Mode Invalid\n");
14601 break;
14602 }
14603 vty_out(vty, "\n");
14604 }
14605
14606 static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
14607 enum show_type type,
14608 const char *ip_str,
14609 afi_t afi, bool use_json)
14610 {
14611 if ((afi == AFI_MAX) && (ip_str == NULL)) {
14612 afi = AFI_IP;
14613
14614 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
14615
14616 bgp_show_neighbor_graceful_restart_vty(
14617 vty, type, ip_str, afi, use_json);
14618 afi++;
14619 }
14620 } else if (afi != AFI_MAX) {
14621 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
14622 use_json);
14623 } else {
14624 return CMD_ERR_INCOMPLETE;
14625 }
14626
14627 return CMD_SUCCESS;
14628 }
14629 /* Graceful Restart */
14630
14631 DEFUN (show_ip_bgp_attr_info,
14632 show_ip_bgp_attr_info_cmd,
14633 "show [ip] bgp attribute-info",
14634 SHOW_STR
14635 IP_STR
14636 BGP_STR
14637 "List all bgp attribute information\n")
14638 {
14639 attr_show_all(vty);
14640 return CMD_SUCCESS;
14641 }
14642
14643 static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
14644 afi_t afi, safi_t safi,
14645 bool use_json, json_object *json)
14646 {
14647 struct bgp *bgp;
14648 struct listnode *node;
14649 char *vname;
14650 char buf1[INET6_ADDRSTRLEN];
14651 char *ecom_str;
14652 vpn_policy_direction_t dir;
14653
14654 if (json) {
14655 json_object *json_import_vrfs = NULL;
14656 json_object *json_export_vrfs = NULL;
14657
14658 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
14659
14660 if (!bgp) {
14661 vty_out(vty, "%s\n",
14662 json_object_to_json_string_ext(
14663 json,
14664 JSON_C_TO_STRING_PRETTY));
14665 json_object_free(json);
14666
14667 return CMD_WARNING;
14668 }
14669
14670 /* Provide context for the block */
14671 json_object_string_add(json, "vrf", name ? name : "default");
14672 json_object_string_add(json, "afiSafi",
14673 get_afi_safi_str(afi, safi, true));
14674
14675 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14676 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
14677 json_object_string_add(json, "importFromVrfs", "none");
14678 json_object_string_add(json, "importRts", "none");
14679 } else {
14680 json_import_vrfs = json_object_new_array();
14681
14682 for (ALL_LIST_ELEMENTS_RO(
14683 bgp->vpn_policy[afi].import_vrf,
14684 node, vname))
14685 json_object_array_add(json_import_vrfs,
14686 json_object_new_string(vname));
14687
14688 json_object_object_add(json, "importFromVrfs",
14689 json_import_vrfs);
14690 dir = BGP_VPN_POLICY_DIR_FROMVPN;
14691 if (bgp->vpn_policy[afi].rtlist[dir]) {
14692 ecom_str = ecommunity_ecom2str(
14693 bgp->vpn_policy[afi].rtlist[dir],
14694 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
14695 json_object_string_add(json, "importRts",
14696 ecom_str);
14697 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14698 } else
14699 json_object_string_add(json, "importRts",
14700 "none");
14701 }
14702
14703 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14704 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
14705 json_object_string_add(json, "exportToVrfs", "none");
14706 json_object_string_add(json, "routeDistinguisher",
14707 "none");
14708 json_object_string_add(json, "exportRts", "none");
14709 } else {
14710 json_export_vrfs = json_object_new_array();
14711
14712 for (ALL_LIST_ELEMENTS_RO(
14713 bgp->vpn_policy[afi].export_vrf,
14714 node, vname))
14715 json_object_array_add(json_export_vrfs,
14716 json_object_new_string(vname));
14717 json_object_object_add(json, "exportToVrfs",
14718 json_export_vrfs);
14719 json_object_string_add(json, "routeDistinguisher",
14720 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
14721 buf1, RD_ADDRSTRLEN));
14722
14723 dir = BGP_VPN_POLICY_DIR_TOVPN;
14724 if (bgp->vpn_policy[afi].rtlist[dir]) {
14725 ecom_str = ecommunity_ecom2str(
14726 bgp->vpn_policy[afi].rtlist[dir],
14727 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
14728 json_object_string_add(json, "exportRts",
14729 ecom_str);
14730 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14731 } else
14732 json_object_string_add(json, "exportRts",
14733 "none");
14734 }
14735
14736 if (use_json) {
14737 vty_out(vty, "%s\n",
14738 json_object_to_json_string_ext(json,
14739 JSON_C_TO_STRING_PRETTY));
14740 json_object_free(json);
14741 }
14742 } else {
14743 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
14744
14745 if (!bgp) {
14746 vty_out(vty, "%% No such BGP instance exist\n");
14747 return CMD_WARNING;
14748 }
14749
14750 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14751 BGP_CONFIG_VRF_TO_VRF_IMPORT))
14752 vty_out(vty,
14753 "This VRF is not importing %s routes from any other VRF\n",
14754 get_afi_safi_str(afi, safi, false));
14755 else {
14756 vty_out(vty,
14757 "This VRF is importing %s routes from the following VRFs:\n",
14758 get_afi_safi_str(afi, safi, false));
14759
14760 for (ALL_LIST_ELEMENTS_RO(
14761 bgp->vpn_policy[afi].import_vrf,
14762 node, vname))
14763 vty_out(vty, " %s\n", vname);
14764
14765 dir = BGP_VPN_POLICY_DIR_FROMVPN;
14766 ecom_str = NULL;
14767 if (bgp->vpn_policy[afi].rtlist[dir]) {
14768 ecom_str = ecommunity_ecom2str(
14769 bgp->vpn_policy[afi].rtlist[dir],
14770 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
14771 vty_out(vty, "Import RT(s): %s\n", ecom_str);
14772
14773 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14774 } else
14775 vty_out(vty, "Import RT(s):\n");
14776 }
14777
14778 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14779 BGP_CONFIG_VRF_TO_VRF_EXPORT))
14780 vty_out(vty,
14781 "This VRF is not exporting %s routes to any other VRF\n",
14782 get_afi_safi_str(afi, safi, false));
14783 else {
14784 vty_out(vty,
14785 "This VRF is exporting %s routes to the following VRFs:\n",
14786 get_afi_safi_str(afi, safi, false));
14787
14788 for (ALL_LIST_ELEMENTS_RO(
14789 bgp->vpn_policy[afi].export_vrf,
14790 node, vname))
14791 vty_out(vty, " %s\n", vname);
14792
14793 vty_out(vty, "RD: %s\n",
14794 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
14795 buf1, RD_ADDRSTRLEN));
14796
14797 dir = BGP_VPN_POLICY_DIR_TOVPN;
14798 if (bgp->vpn_policy[afi].rtlist[dir]) {
14799 ecom_str = ecommunity_ecom2str(
14800 bgp->vpn_policy[afi].rtlist[dir],
14801 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
14802 vty_out(vty, "Export RT: %s\n", ecom_str);
14803 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14804 } else
14805 vty_out(vty, "Import RT(s):\n");
14806 }
14807 }
14808
14809 return CMD_SUCCESS;
14810 }
14811
14812 static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
14813 safi_t safi, bool use_json)
14814 {
14815 struct listnode *node, *nnode;
14816 struct bgp *bgp;
14817 char *vrf_name = NULL;
14818 json_object *json = NULL;
14819 json_object *json_vrf = NULL;
14820 json_object *json_vrfs = NULL;
14821
14822 if (use_json) {
14823 json = json_object_new_object();
14824 json_vrfs = json_object_new_object();
14825 }
14826
14827 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
14828
14829 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
14830 vrf_name = bgp->name;
14831
14832 if (use_json) {
14833 json_vrf = json_object_new_object();
14834 } else {
14835 vty_out(vty, "\nInstance %s:\n",
14836 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14837 ? VRF_DEFAULT_NAME : bgp->name);
14838 }
14839 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
14840 if (use_json) {
14841 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14842 json_object_object_add(json_vrfs,
14843 VRF_DEFAULT_NAME, json_vrf);
14844 else
14845 json_object_object_add(json_vrfs, vrf_name,
14846 json_vrf);
14847 }
14848 }
14849
14850 if (use_json) {
14851 json_object_object_add(json, "vrfs", json_vrfs);
14852 vty_out(vty, "%s\n", json_object_to_json_string_ext(json,
14853 JSON_C_TO_STRING_PRETTY));
14854 json_object_free(json);
14855 }
14856
14857 return CMD_SUCCESS;
14858 }
14859
14860 /* "show [ip] bgp route-leak" command. */
14861 DEFUN (show_ip_bgp_route_leak,
14862 show_ip_bgp_route_leak_cmd,
14863 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
14864 SHOW_STR
14865 IP_STR
14866 BGP_STR
14867 BGP_INSTANCE_HELP_STR
14868 BGP_AFI_HELP_STR
14869 BGP_SAFI_HELP_STR
14870 "Route leaking information\n"
14871 JSON_STR)
14872 {
14873 char *vrf = NULL;
14874 afi_t afi = AFI_MAX;
14875 safi_t safi = SAFI_MAX;
14876
14877 bool uj = use_json(argc, argv);
14878 int idx = 0;
14879 json_object *json = NULL;
14880
14881 /* show [ip] bgp */
14882 if (argv_find(argv, argc, "ip", &idx)) {
14883 afi = AFI_IP;
14884 safi = SAFI_UNICAST;
14885 }
14886 /* [vrf VIEWVRFNAME] */
14887 if (argv_find(argv, argc, "view", &idx)) {
14888 vty_out(vty,
14889 "%% This command is not applicable to BGP views\n");
14890 return CMD_WARNING;
14891 }
14892
14893 if (argv_find(argv, argc, "vrf", &idx)) {
14894 vrf = argv[idx + 1]->arg;
14895 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
14896 vrf = NULL;
14897 }
14898 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
14899 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
14900 argv_find_and_parse_safi(argv, argc, &idx, &safi);
14901 }
14902
14903 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
14904 vty_out(vty,
14905 "%% This command is applicable only for unicast ipv4|ipv6\n");
14906 return CMD_WARNING;
14907 }
14908
14909 if (vrf && strmatch(vrf, "all"))
14910 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
14911
14912 if (uj)
14913 json = json_object_new_object();
14914
14915 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
14916 }
14917
14918 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
14919 safi_t safi)
14920 {
14921 struct listnode *node, *nnode;
14922 struct bgp *bgp;
14923
14924 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
14925 vty_out(vty, "\nInstance %s:\n",
14926 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14927 ? VRF_DEFAULT_NAME
14928 : bgp->name);
14929 update_group_show(bgp, afi, safi, vty, 0);
14930 }
14931 }
14932
14933 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
14934 int safi, uint64_t subgrp_id)
14935 {
14936 struct bgp *bgp;
14937
14938 if (name) {
14939 if (strmatch(name, "all")) {
14940 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
14941 return CMD_SUCCESS;
14942 } else {
14943 bgp = bgp_lookup_by_name(name);
14944 }
14945 } else {
14946 bgp = bgp_get_default();
14947 }
14948
14949 if (bgp)
14950 update_group_show(bgp, afi, safi, vty, subgrp_id);
14951 return CMD_SUCCESS;
14952 }
14953
14954 DEFUN (show_ip_bgp_updgrps,
14955 show_ip_bgp_updgrps_cmd,
14956 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
14957 SHOW_STR
14958 IP_STR
14959 BGP_STR
14960 BGP_INSTANCE_HELP_STR
14961 BGP_AFI_HELP_STR
14962 BGP_SAFI_WITH_LABEL_HELP_STR
14963 "Detailed info about dynamic update groups\n"
14964 "Specific subgroup to display detailed info for\n")
14965 {
14966 char *vrf = NULL;
14967 afi_t afi = AFI_IP6;
14968 safi_t safi = SAFI_UNICAST;
14969 uint64_t subgrp_id = 0;
14970
14971 int idx = 0;
14972
14973 /* show [ip] bgp */
14974 if (argv_find(argv, argc, "ip", &idx))
14975 afi = AFI_IP;
14976 /* [<vrf> VIEWVRFNAME] */
14977 if (argv_find(argv, argc, "vrf", &idx)) {
14978 vrf = argv[idx + 1]->arg;
14979 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
14980 vrf = NULL;
14981 } else if (argv_find(argv, argc, "view", &idx))
14982 /* [<view> VIEWVRFNAME] */
14983 vrf = argv[idx + 1]->arg;
14984 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
14985 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
14986 argv_find_and_parse_safi(argv, argc, &idx, &safi);
14987 }
14988
14989 /* get subgroup id, if provided */
14990 idx = argc - 1;
14991 if (argv[idx]->type == VARIABLE_TKN)
14992 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
14993
14994 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
14995 }
14996
14997 DEFUN (show_bgp_instance_all_ipv6_updgrps,
14998 show_bgp_instance_all_ipv6_updgrps_cmd,
14999 "show [ip] bgp <view|vrf> all update-groups",
15000 SHOW_STR
15001 IP_STR
15002 BGP_STR
15003 BGP_INSTANCE_ALL_HELP_STR
15004 "Detailed info about dynamic update groups\n")
15005 {
15006 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
15007 return CMD_SUCCESS;
15008 }
15009
15010 DEFUN (show_bgp_l2vpn_evpn_updgrps,
15011 show_bgp_l2vpn_evpn_updgrps_cmd,
15012 "show [ip] bgp l2vpn evpn update-groups",
15013 SHOW_STR
15014 IP_STR
15015 BGP_STR
15016 "l2vpn address family\n"
15017 "evpn sub-address family\n"
15018 "Detailed info about dynamic update groups\n")
15019 {
15020 char *vrf = NULL;
15021 uint64_t subgrp_id = 0;
15022
15023 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
15024 return CMD_SUCCESS;
15025 }
15026
15027 DEFUN (show_bgp_updgrps_stats,
15028 show_bgp_updgrps_stats_cmd,
15029 "show [ip] bgp update-groups statistics",
15030 SHOW_STR
15031 IP_STR
15032 BGP_STR
15033 "Detailed info about dynamic update groups\n"
15034 "Statistics\n")
15035 {
15036 struct bgp *bgp;
15037
15038 bgp = bgp_get_default();
15039 if (bgp)
15040 update_group_show_stats(bgp, vty);
15041
15042 return CMD_SUCCESS;
15043 }
15044
15045 DEFUN (show_bgp_instance_updgrps_stats,
15046 show_bgp_instance_updgrps_stats_cmd,
15047 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
15048 SHOW_STR
15049 IP_STR
15050 BGP_STR
15051 BGP_INSTANCE_HELP_STR
15052 "Detailed info about dynamic update groups\n"
15053 "Statistics\n")
15054 {
15055 int idx_word = 3;
15056 struct bgp *bgp;
15057
15058 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
15059 if (bgp)
15060 update_group_show_stats(bgp, vty);
15061
15062 return CMD_SUCCESS;
15063 }
15064
15065 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
15066 afi_t afi, safi_t safi,
15067 const char *what, uint64_t subgrp_id)
15068 {
15069 struct bgp *bgp;
15070
15071 if (name)
15072 bgp = bgp_lookup_by_name(name);
15073 else
15074 bgp = bgp_get_default();
15075
15076 if (bgp) {
15077 if (!strcmp(what, "advertise-queue"))
15078 update_group_show_adj_queue(bgp, afi, safi, vty,
15079 subgrp_id);
15080 else if (!strcmp(what, "advertised-routes"))
15081 update_group_show_advertised(bgp, afi, safi, vty,
15082 subgrp_id);
15083 else if (!strcmp(what, "packet-queue"))
15084 update_group_show_packet_queue(bgp, afi, safi, vty,
15085 subgrp_id);
15086 }
15087 }
15088
15089 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
15090 show_ip_bgp_instance_updgrps_adj_s_cmd,
15091 "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",
15092 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
15093 BGP_SAFI_HELP_STR
15094 "Detailed info about dynamic update groups\n"
15095 "Specific subgroup to display info for\n"
15096 "Advertisement queue\n"
15097 "Announced routes\n"
15098 "Packet queue\n")
15099 {
15100 uint64_t subgrp_id = 0;
15101 afi_t afiz;
15102 safi_t safiz;
15103 if (sgid)
15104 subgrp_id = strtoull(sgid, NULL, 10);
15105
15106 if (!ip && !afi)
15107 afiz = AFI_IP6;
15108 if (!ip && afi)
15109 afiz = bgp_vty_afi_from_str(afi);
15110 if (ip && !afi)
15111 afiz = AFI_IP;
15112 if (ip && afi) {
15113 afiz = bgp_vty_afi_from_str(afi);
15114 if (afiz != AFI_IP)
15115 vty_out(vty,
15116 "%% Cannot specify both 'ip' and 'ipv6'\n");
15117 return CMD_WARNING;
15118 }
15119
15120 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
15121
15122 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
15123 return CMD_SUCCESS;
15124 }
15125
15126 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
15127 {
15128 struct listnode *node, *nnode;
15129 struct prefix *range;
15130 struct peer *conf;
15131 struct peer *peer;
15132 afi_t afi;
15133 safi_t safi;
15134 const char *peer_status;
15135 const char *af_str;
15136 int lr_count;
15137 int dynamic;
15138 int af_cfgd;
15139
15140 conf = group->conf;
15141
15142 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
15143 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15144 group->name, conf->as);
15145 } else if (conf->as_type == AS_INTERNAL) {
15146 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15147 group->name, group->bgp->as);
15148 } else {
15149 vty_out(vty, "\nBGP peer-group %s\n", group->name);
15150 }
15151
15152 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
15153 vty_out(vty, " Peer-group type is internal\n");
15154 else
15155 vty_out(vty, " Peer-group type is external\n");
15156
15157 /* Display AFs configured. */
15158 vty_out(vty, " Configured address-families:");
15159 FOREACH_AFI_SAFI (afi, safi) {
15160 if (conf->afc[afi][safi]) {
15161 af_cfgd = 1;
15162 vty_out(vty, " %s;", get_afi_safi_str(afi, safi, false));
15163 }
15164 }
15165 if (!af_cfgd)
15166 vty_out(vty, " none\n");
15167 else
15168 vty_out(vty, "\n");
15169
15170 /* Display listen ranges (for dynamic neighbors), if any */
15171 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
15172 if (afi == AFI_IP)
15173 af_str = "IPv4";
15174 else if (afi == AFI_IP6)
15175 af_str = "IPv6";
15176 else
15177 af_str = "???";
15178 lr_count = listcount(group->listen_range[afi]);
15179 if (lr_count) {
15180 vty_out(vty, " %d %s listen range(s)\n", lr_count,
15181 af_str);
15182
15183
15184 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
15185 nnode, range))
15186 vty_out(vty, " %pFX\n", range);
15187 }
15188 }
15189
15190 /* Display group members and their status */
15191 if (listcount(group->peer)) {
15192 vty_out(vty, " Peer-group members:\n");
15193 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
15194 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
15195 || CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHUTDOWN))
15196 peer_status = "Idle (Admin)";
15197 else if (CHECK_FLAG(peer->sflags,
15198 PEER_STATUS_PREFIX_OVERFLOW))
15199 peer_status = "Idle (PfxCt)";
15200 else
15201 peer_status = lookup_msg(bgp_status_msg,
15202 peer->status, NULL);
15203
15204 dynamic = peer_dynamic_neighbor(peer);
15205 vty_out(vty, " %s %s %s \n", peer->host,
15206 dynamic ? "(dynamic)" : "", peer_status);
15207 }
15208 }
15209
15210 return CMD_SUCCESS;
15211 }
15212
15213 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
15214 const char *group_name)
15215 {
15216 struct bgp *bgp;
15217 struct listnode *node, *nnode;
15218 struct peer_group *group;
15219 bool found = false;
15220
15221 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15222
15223 if (!bgp) {
15224 vty_out(vty, "%% BGP instance not found\n");
15225 return CMD_WARNING;
15226 }
15227
15228 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
15229 if (group_name) {
15230 if (strmatch(group->name, group_name)) {
15231 bgp_show_one_peer_group(vty, group);
15232 found = true;
15233 break;
15234 }
15235 } else {
15236 bgp_show_one_peer_group(vty, group);
15237 }
15238 }
15239
15240 if (group_name && !found)
15241 vty_out(vty, "%% No such peer-group\n");
15242
15243 return CMD_SUCCESS;
15244 }
15245
15246 DEFUN (show_ip_bgp_peer_groups,
15247 show_ip_bgp_peer_groups_cmd,
15248 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
15249 SHOW_STR
15250 IP_STR
15251 BGP_STR
15252 BGP_INSTANCE_HELP_STR
15253 "Detailed information on BGP peer groups\n"
15254 "Peer group name\n")
15255 {
15256 char *vrf, *pg;
15257 int idx = 0;
15258
15259 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
15260 : NULL;
15261 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
15262
15263 return bgp_show_peer_group_vty(vty, vrf, pg);
15264 }
15265
15266
15267 /* Redistribute VTY commands. */
15268
15269 DEFUN_YANG (bgp_redistribute_ipv4,
15270 bgp_redistribute_ipv4_cmd,
15271 "redistribute " FRR_IP_REDIST_STR_BGPD,
15272 "Redistribute information from another routing protocol\n"
15273 FRR_IP_REDIST_HELP_STR_BGPD)
15274 {
15275 int idx_protocol = 1;
15276 char base_xpath[XPATH_MAXLEN];
15277
15278 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15279 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15280 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15281 argv[idx_protocol]->text, "0");
15282
15283 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15284
15285 return nb_cli_apply_changes(vty, base_xpath);
15286 }
15287
15288 ALIAS_HIDDEN(
15289 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
15290 "redistribute " FRR_IP_REDIST_STR_BGPD,
15291 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
15292
15293 DEFUN_YANG (bgp_redistribute_ipv4_rmap,
15294 bgp_redistribute_ipv4_rmap_cmd,
15295 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
15296 "Redistribute information from another routing protocol\n"
15297 FRR_IP_REDIST_HELP_STR_BGPD
15298 "Route map reference\n"
15299 "Pointer to route-map entries\n")
15300 {
15301 int idx_protocol = 1;
15302 int idx_word = 3;
15303 char base_xpath[XPATH_MAXLEN];
15304
15305 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15306 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15307 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15308 argv[idx_protocol]->text, "0");
15309
15310 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15311 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15312 argv[idx_word]->arg);
15313
15314 return nb_cli_apply_changes(vty, base_xpath);
15315 }
15316
15317 ALIAS_HIDDEN(
15318 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
15319 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
15320 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15321 "Route map reference\n"
15322 "Pointer to route-map entries\n")
15323
15324 DEFUN_YANG (bgp_redistribute_ipv4_metric,
15325 bgp_redistribute_ipv4_metric_cmd,
15326 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15327 "Redistribute information from another routing protocol\n"
15328 FRR_IP_REDIST_HELP_STR_BGPD
15329 "Metric for redistributed routes\n"
15330 "Default metric\n")
15331 {
15332 int idx_protocol = 1;
15333 int idx_number = 3;
15334 char base_xpath[XPATH_MAXLEN];
15335
15336 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15337 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15338 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15339 argv[idx_protocol]->text, "0");
15340
15341 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15342 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15343 argv[idx_number]->arg);
15344
15345 return nb_cli_apply_changes(vty, base_xpath);
15346 }
15347
15348 ALIAS_HIDDEN(
15349 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
15350 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15351 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15352 "Metric for redistributed routes\n"
15353 "Default metric\n")
15354
15355 DEFUN_YANG(
15356 bgp_redistribute_ipv4_rmap_metric,
15357 bgp_redistribute_ipv4_rmap_metric_cmd,
15358 "redistribute " FRR_IP_REDIST_STR_BGPD
15359 " route-map WORD metric (0-4294967295)",
15360 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15361 "Route map reference\n"
15362 "Pointer to route-map entries\n"
15363 "Metric for redistributed routes\n"
15364 "Default metric\n")
15365 {
15366 int idx_protocol = 1;
15367 int idx_word = 3;
15368 int idx_number = 5;
15369 char base_xpath[XPATH_MAXLEN];
15370
15371 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15372 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15373 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15374 argv[idx_protocol]->text, "0");
15375
15376 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15377 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15378 argv[idx_word]->arg);
15379 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15380 argv[idx_number]->arg);
15381
15382 return nb_cli_apply_changes(vty, base_xpath);
15383 }
15384
15385 ALIAS_HIDDEN(
15386 bgp_redistribute_ipv4_rmap_metric,
15387 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
15388 "redistribute " FRR_IP_REDIST_STR_BGPD
15389 " route-map WORD metric (0-4294967295)",
15390 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15391 "Route map reference\n"
15392 "Pointer to route-map entries\n"
15393 "Metric for redistributed routes\n"
15394 "Default metric\n")
15395
15396 DEFUN_YANG(
15397 bgp_redistribute_ipv4_metric_rmap,
15398 bgp_redistribute_ipv4_metric_rmap_cmd,
15399 "redistribute " FRR_IP_REDIST_STR_BGPD
15400 " metric (0-4294967295) route-map WORD",
15401 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15402 "Metric for redistributed routes\n"
15403 "Default metric\n"
15404 "Route map reference\n"
15405 "Pointer to route-map entries\n")
15406 {
15407 int idx_protocol = 1;
15408 int idx_word = 5;
15409 int idx_number = 3;
15410 char base_xpath[XPATH_MAXLEN];
15411
15412 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15413 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15414 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15415 argv[idx_protocol]->text, "0");
15416
15417 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15418 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15419 argv[idx_number]->arg);
15420 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15421 argv[idx_word]->arg);
15422
15423 return nb_cli_apply_changes(vty, base_xpath);
15424 }
15425
15426 ALIAS_HIDDEN(
15427 bgp_redistribute_ipv4_metric_rmap,
15428 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
15429 "redistribute " FRR_IP_REDIST_STR_BGPD
15430 " metric (0-4294967295) route-map WORD",
15431 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15432 "Metric for redistributed routes\n"
15433 "Default metric\n"
15434 "Route map reference\n"
15435 "Pointer to route-map entries\n")
15436
15437 DEFUN_YANG (bgp_redistribute_ipv4_ospf,
15438 bgp_redistribute_ipv4_ospf_cmd,
15439 "redistribute <ospf|table> (1-65535)",
15440 "Redistribute information from another routing protocol\n"
15441 "Open Shortest Path First (OSPFv2)\n"
15442 "Non-main Kernel Routing Table\n"
15443 "Instance ID/Table ID\n")
15444 {
15445 int idx_protocol = 1;
15446 int idx_number = 2;
15447 char base_xpath[XPATH_MAXLEN];
15448
15449 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15450 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15451 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15452 argv[idx_protocol]->text, argv[idx_number]->arg);
15453
15454 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15455
15456 return nb_cli_apply_changes(vty, base_xpath);
15457 }
15458
15459 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
15460 "redistribute <ospf|table> (1-65535)",
15461 "Redistribute information from another routing protocol\n"
15462 "Open Shortest Path First (OSPFv2)\n"
15463 "Non-main Kernel Routing Table\n"
15464 "Instance ID/Table ID\n")
15465
15466 DEFUN_YANG (bgp_redistribute_ipv4_ospf_rmap,
15467 bgp_redistribute_ipv4_ospf_rmap_cmd,
15468 "redistribute <ospf|table> (1-65535) route-map WORD",
15469 "Redistribute information from another routing protocol\n"
15470 "Open Shortest Path First (OSPFv2)\n"
15471 "Non-main Kernel Routing Table\n"
15472 "Instance ID/Table ID\n"
15473 "Route map reference\n"
15474 "Pointer to route-map entries\n")
15475 {
15476 int idx_protocol = 1;
15477 int idx_number = 2;
15478 int idx_word = 4;
15479 char base_xpath[XPATH_MAXLEN];
15480
15481 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15482 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15483 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15484 argv[idx_protocol]->text, argv[idx_number]->arg);
15485
15486 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15487
15488 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15489 argv[idx_word]->arg);
15490
15491 return nb_cli_apply_changes(vty, base_xpath);
15492 }
15493
15494 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
15495 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
15496 "redistribute <ospf|table> (1-65535) route-map WORD",
15497 "Redistribute information from another routing protocol\n"
15498 "Open Shortest Path First (OSPFv2)\n"
15499 "Non-main Kernel Routing Table\n"
15500 "Instance ID/Table ID\n"
15501 "Route map reference\n"
15502 "Pointer to route-map entries\n")
15503
15504 DEFUN_YANG(bgp_redistribute_ipv4_ospf_metric,
15505 bgp_redistribute_ipv4_ospf_metric_cmd,
15506 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
15507 "Redistribute information from another routing protocol\n"
15508 "Open Shortest Path First (OSPFv2)\n"
15509 "Non-main Kernel Routing Table\n"
15510 "Instance ID/Table ID\n"
15511 "Metric for redistributed routes\n"
15512 "Default metric\n")
15513 {
15514 int idx_protocol = 1;
15515 int idx_number = 2;
15516 int idx_number_2 = 4;
15517 char base_xpath[XPATH_MAXLEN];
15518
15519 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15520 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15521 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15522 argv[idx_protocol]->text, argv[idx_number]->arg);
15523
15524 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15525
15526 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15527 argv[idx_number_2]->arg);
15528
15529 return nb_cli_apply_changes(vty, base_xpath);
15530 }
15531
15532 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
15533 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
15534 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
15535 "Redistribute information from another routing protocol\n"
15536 "Open Shortest Path First (OSPFv2)\n"
15537 "Non-main Kernel Routing Table\n"
15538 "Instance ID/Table ID\n"
15539 "Metric for redistributed routes\n"
15540 "Default metric\n")
15541
15542 DEFUN_YANG(
15543 bgp_redistribute_ipv4_ospf_rmap_metric,
15544 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
15545 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
15546 "Redistribute information from another routing protocol\n"
15547 "Open Shortest Path First (OSPFv2)\n"
15548 "Non-main Kernel Routing Table\n"
15549 "Instance ID/Table ID\n"
15550 "Route map reference\n"
15551 "Pointer to route-map entries\n"
15552 "Metric for redistributed routes\n"
15553 "Default metric\n")
15554 {
15555 int idx_protocol = 1;
15556 int idx_number = 2;
15557 int idx_word = 4;
15558 int idx_number_2 = 6;
15559 char base_xpath[XPATH_MAXLEN];
15560
15561 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15562 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15563 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15564 argv[idx_protocol]->text, argv[idx_number]->arg);
15565
15566 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15567
15568 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15569 argv[idx_word]->arg);
15570 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15571 argv[idx_number_2]->arg);
15572
15573 return nb_cli_apply_changes(vty, base_xpath);
15574 }
15575
15576 ALIAS_HIDDEN(
15577 bgp_redistribute_ipv4_ospf_rmap_metric,
15578 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
15579 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
15580 "Redistribute information from another routing protocol\n"
15581 "Open Shortest Path First (OSPFv2)\n"
15582 "Non-main Kernel Routing Table\n"
15583 "Instance ID/Table ID\n"
15584 "Route map reference\n"
15585 "Pointer to route-map entries\n"
15586 "Metric for redistributed routes\n"
15587 "Default metric\n")
15588
15589 DEFUN_YANG(
15590 bgp_redistribute_ipv4_ospf_metric_rmap,
15591 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
15592 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
15593 "Redistribute information from another routing protocol\n"
15594 "Open Shortest Path First (OSPFv2)\n"
15595 "Non-main Kernel Routing Table\n"
15596 "Instance ID/Table ID\n"
15597 "Metric for redistributed routes\n"
15598 "Default metric\n"
15599 "Route map reference\n"
15600 "Pointer to route-map entries\n")
15601 {
15602 int idx_protocol = 1;
15603 int idx_number = 2;
15604 int idx_number_2 = 4;
15605 int idx_word = 6;
15606 char base_xpath[XPATH_MAXLEN];
15607
15608 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15609 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15610 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15611 argv[idx_protocol]->text, argv[idx_number]->arg);
15612
15613 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15614
15615 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15616 argv[idx_number_2]->arg);
15617 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15618 argv[idx_word]->arg);
15619
15620 return nb_cli_apply_changes(vty, base_xpath);
15621 }
15622
15623 ALIAS_HIDDEN(
15624 bgp_redistribute_ipv4_ospf_metric_rmap,
15625 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
15626 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
15627 "Redistribute information from another routing protocol\n"
15628 "Open Shortest Path First (OSPFv2)\n"
15629 "Non-main Kernel Routing Table\n"
15630 "Instance ID/Table ID\n"
15631 "Metric for redistributed routes\n"
15632 "Default metric\n"
15633 "Route map reference\n"
15634 "Pointer to route-map entries\n")
15635
15636 DEFUN_YANG (no_bgp_redistribute_ipv4_ospf,
15637 no_bgp_redistribute_ipv4_ospf_cmd,
15638 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
15639 NO_STR
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 "Route map reference\n"
15647 "Pointer to route-map entries\n")
15648 {
15649 int idx_protocol = 2;
15650 int idx_number = 3;
15651 char base_xpath[XPATH_MAXLEN];
15652
15653 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15654 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15655 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15656 argv[idx_protocol]->text, argv[idx_number]->arg);
15657
15658 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
15659
15660 return nb_cli_apply_changes(vty, base_xpath);
15661 }
15662
15663 ALIAS_HIDDEN(
15664 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
15665 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
15666 NO_STR
15667 "Redistribute information from another routing protocol\n"
15668 "Open Shortest Path First (OSPFv2)\n"
15669 "Non-main Kernel Routing Table\n"
15670 "Instance ID/Table ID\n"
15671 "Metric for redistributed routes\n"
15672 "Default metric\n"
15673 "Route map reference\n"
15674 "Pointer to route-map entries\n")
15675
15676 DEFUN_YANG (no_bgp_redistribute_ipv4,
15677 no_bgp_redistribute_ipv4_cmd,
15678 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
15679 NO_STR
15680 "Redistribute information from another routing protocol\n"
15681 FRR_IP_REDIST_HELP_STR_BGPD
15682 "Metric for redistributed routes\n"
15683 "Default metric\n"
15684 "Route map reference\n"
15685 "Pointer to route-map entries\n")
15686 {
15687 int idx_protocol = 2;
15688 char base_xpath[XPATH_MAXLEN];
15689
15690 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15691 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15692 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15693 argv[idx_protocol]->text, "0");
15694
15695 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
15696
15697 return nb_cli_apply_changes(vty, base_xpath);
15698 }
15699
15700 ALIAS_HIDDEN(
15701 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
15702 "no redistribute " FRR_IP_REDIST_STR_BGPD
15703 " [{metric (0-4294967295)|route-map WORD}]",
15704 NO_STR
15705 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15706 "Metric for redistributed routes\n"
15707 "Default metric\n"
15708 "Route map reference\n"
15709 "Pointer to route-map entries\n")
15710
15711 DEFUN_YANG (bgp_redistribute_ipv6,
15712 bgp_redistribute_ipv6_cmd,
15713 "redistribute " FRR_IP6_REDIST_STR_BGPD,
15714 "Redistribute information from another routing protocol\n"
15715 FRR_IP6_REDIST_HELP_STR_BGPD)
15716 {
15717 int idx_protocol = 1;
15718 char base_xpath[XPATH_MAXLEN];
15719
15720 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15721 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
15722 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
15723 argv[idx_protocol]->text, "0");
15724
15725 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15726
15727 return nb_cli_apply_changes(vty, base_xpath);
15728 }
15729
15730 DEFUN_YANG (bgp_redistribute_ipv6_rmap,
15731 bgp_redistribute_ipv6_rmap_cmd,
15732 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
15733 "Redistribute information from another routing protocol\n"
15734 FRR_IP6_REDIST_HELP_STR_BGPD
15735 "Route map reference\n"
15736 "Pointer to route-map entries\n")
15737 {
15738 int idx_protocol = 1;
15739 int idx_word = 3;
15740 char base_xpath[XPATH_MAXLEN];
15741
15742 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15743 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
15744 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
15745 argv[idx_protocol]->text, "0");
15746
15747 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15748 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15749 argv[idx_word]->arg);
15750
15751 return nb_cli_apply_changes(vty, base_xpath);
15752 }
15753
15754 DEFUN_YANG (bgp_redistribute_ipv6_metric,
15755 bgp_redistribute_ipv6_metric_cmd,
15756 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
15757 "Redistribute information from another routing protocol\n"
15758 FRR_IP6_REDIST_HELP_STR_BGPD
15759 "Metric for redistributed routes\n"
15760 "Default metric\n")
15761 {
15762 int idx_protocol = 1;
15763 int idx_number = 3;
15764 char base_xpath[XPATH_MAXLEN];
15765
15766 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15767 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
15768 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
15769 argv[idx_protocol]->text, "0");
15770
15771 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15772 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15773 argv[idx_number]->arg);
15774
15775 return nb_cli_apply_changes(vty, base_xpath);
15776 }
15777
15778 DEFUN_YANG(
15779 bgp_redistribute_ipv6_rmap_metric,
15780 bgp_redistribute_ipv6_rmap_metric_cmd,
15781 "redistribute " FRR_IP6_REDIST_STR_BGPD
15782 " route-map WORD metric (0-4294967295)",
15783 "Redistribute information from another routing protocol\n" FRR_IP6_REDIST_HELP_STR_BGPD
15784 "Route map reference\n"
15785 "Pointer to route-map entries\n"
15786 "Metric for redistributed routes\n"
15787 "Default metric\n")
15788 {
15789 int idx_protocol = 1;
15790 int idx_word = 3;
15791 int idx_number = 5;
15792 char base_xpath[XPATH_MAXLEN];
15793
15794 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15795 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
15796 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
15797 argv[idx_protocol]->text, "0");
15798
15799 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15800 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15801 argv[idx_word]->arg);
15802 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15803 argv[idx_number]->arg);
15804
15805 return nb_cli_apply_changes(vty, base_xpath);
15806 }
15807
15808 DEFUN_YANG(
15809 bgp_redistribute_ipv6_metric_rmap,
15810 bgp_redistribute_ipv6_metric_rmap_cmd,
15811 "redistribute " FRR_IP6_REDIST_STR_BGPD
15812 " metric (0-4294967295) route-map WORD",
15813 "Redistribute information from another routing protocol\n" FRR_IP6_REDIST_HELP_STR_BGPD
15814 "Metric for redistributed routes\n"
15815 "Default metric\n"
15816 "Route map reference\n"
15817 "Pointer to route-map entries\n")
15818 {
15819 int idx_protocol = 1;
15820 int idx_word = 5;
15821 int idx_number = 3;
15822 char base_xpath[XPATH_MAXLEN];
15823
15824 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15825 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
15826 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
15827 argv[idx_protocol]->text, "0");
15828
15829 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15830 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15831 argv[idx_number]->arg);
15832 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15833 argv[idx_word]->arg);
15834
15835 return nb_cli_apply_changes(vty, base_xpath);
15836 }
15837
15838 DEFUN_YANG(
15839 no_bgp_redistribute_ipv6,
15840 no_bgp_redistribute_ipv6_cmd,
15841 "no redistribute " FRR_IP6_REDIST_STR_BGPD
15842 " [{metric (0-4294967295)|route-map WORD}]",
15843 NO_STR
15844 "Redistribute information from another routing protocol\n" FRR_IP6_REDIST_HELP_STR_BGPD
15845 "Metric for redistributed routes\n"
15846 "Default metric\n"
15847 "Route map reference\n"
15848 "Pointer to route-map entries\n")
15849 {
15850 int idx_protocol = 2;
15851 char base_xpath[XPATH_MAXLEN];
15852
15853 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15854 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
15855 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
15856 argv[idx_protocol]->text, "0");
15857
15858 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
15859
15860 return nb_cli_apply_changes(vty, base_xpath);
15861 }
15862
15863 void cli_show_bgp_global_afi_safi_ip_unicast_redistribution_list(
15864 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
15865 {
15866 uint32_t instance = 0;
15867
15868 vty_out(vty, " redistribute %s",
15869 yang_dnode_get_string(dnode, "./route-type"));
15870 if ((instance = yang_dnode_get_uint16(dnode, "./route-instance")))
15871 vty_out(vty, " %d", instance);
15872 if (yang_dnode_exists(dnode, "./metric"))
15873 vty_out(vty, " metric %u",
15874 yang_dnode_get_uint32(dnode, "./metric"));
15875 if (yang_dnode_exists(dnode, "./rmap-policy-import"))
15876 vty_out(vty, " route-map %s",
15877 yang_dnode_get_string(dnode, "./rmap-policy-import"));
15878 vty_out(vty, "\n");
15879 }
15880
15881 static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
15882 afi_t afi, safi_t safi)
15883 {
15884 int i;
15885
15886 /* Unicast redistribution only. */
15887 if (safi != SAFI_UNICAST)
15888 return;
15889
15890 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
15891 /* Redistribute BGP does not make sense. */
15892 if (i != ZEBRA_ROUTE_BGP) {
15893 struct list *red_list;
15894 struct listnode *node;
15895 struct bgp_redist *red;
15896
15897 red_list = bgp->redist[afi][i];
15898 if (!red_list)
15899 continue;
15900
15901 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
15902 /* "redistribute" configuration. */
15903 vty_out(vty, " redistribute %s",
15904 zebra_route_string(i));
15905 if (red->instance)
15906 vty_out(vty, " %d", red->instance);
15907 if (red->redist_metric_flag)
15908 vty_out(vty, " metric %u",
15909 red->redist_metric);
15910 if (red->rmap.name)
15911 vty_out(vty, " route-map %s",
15912 red->rmap.name);
15913 vty_out(vty, "\n");
15914 }
15915 }
15916 }
15917 }
15918
15919 /* peer-group helpers for config-write */
15920
15921 static bool peergroup_flag_check(struct peer *peer, uint32_t flag)
15922 {
15923 if (!peer_group_active(peer)) {
15924 if (CHECK_FLAG(peer->flags_invert, flag))
15925 return !CHECK_FLAG(peer->flags, flag);
15926 else
15927 return !!CHECK_FLAG(peer->flags, flag);
15928 }
15929
15930 return !!CHECK_FLAG(peer->flags_override, flag);
15931 }
15932
15933 static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
15934 uint32_t flag)
15935 {
15936 if (!peer_group_active(peer)) {
15937 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
15938 return !peer_af_flag_check(peer, afi, safi, flag);
15939 else
15940 return !!peer_af_flag_check(peer, afi, safi, flag);
15941 }
15942
15943 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
15944 }
15945
15946 static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
15947 uint8_t type, int direct)
15948 {
15949 struct bgp_filter *filter;
15950
15951 if (peer_group_active(peer))
15952 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
15953 type);
15954
15955 filter = &peer->filter[afi][safi];
15956 switch (type) {
15957 case PEER_FT_DISTRIBUTE_LIST:
15958 return !!(filter->dlist[direct].name);
15959 case PEER_FT_FILTER_LIST:
15960 return !!(filter->aslist[direct].name);
15961 case PEER_FT_PREFIX_LIST:
15962 return !!(filter->plist[direct].name);
15963 case PEER_FT_ROUTE_MAP:
15964 return !!(filter->map[direct].name);
15965 case PEER_FT_UNSUPPRESS_MAP:
15966 return !!(filter->usmap.name);
15967 case PEER_FT_ADVERTISE_MAP:
15968 return !!(filter->advmap.aname
15969 && ((filter->advmap.condition == direct)
15970 && filter->advmap.cname));
15971 default:
15972 return false;
15973 }
15974 }
15975
15976 /* Return true if the addpath type is set for peer and different from
15977 * peer-group.
15978 */
15979 static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi,
15980 safi_t safi)
15981 {
15982 enum bgp_addpath_strat type, g_type;
15983
15984 type = peer->addpath_type[afi][safi];
15985
15986 if (type != BGP_ADDPATH_NONE) {
15987 if (peer_group_active(peer)) {
15988 g_type = peer->group->conf->addpath_type[afi][safi];
15989
15990 if (type != g_type)
15991 return true;
15992 else
15993 return false;
15994 }
15995
15996 return true;
15997 }
15998
15999 return false;
16000 }
16001
16002 /* This is part of the address-family block (unicast only) */
16003 static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
16004 afi_t afi)
16005 {
16006 int indent = 2;
16007
16008 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
16009 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16010 BGP_CONFIG_VRF_TO_VRF_IMPORT))
16011 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
16012 bgp->vpn_policy[afi]
16013 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16014 else
16015 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
16016 bgp->vpn_policy[afi]
16017 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16018 }
16019 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16020 BGP_CONFIG_VRF_TO_VRF_IMPORT)
16021 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16022 BGP_CONFIG_VRF_TO_VRF_EXPORT))
16023 return;
16024
16025 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16026 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
16027
16028 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
16029
16030 } else {
16031 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
16032 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
16033 bgp->vpn_policy[afi].tovpn_label);
16034 }
16035 }
16036 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16037 BGP_VPN_POLICY_TOVPN_RD_SET)) {
16038 char buf[RD_ADDRSTRLEN];
16039 vty_out(vty, "%*srd vpn export %s\n", indent, "",
16040 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
16041 sizeof(buf)));
16042 }
16043 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16044 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
16045
16046 char buf[PREFIX_STRLEN];
16047 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
16048 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
16049 sizeof(buf))) {
16050
16051 vty_out(vty, "%*snexthop vpn export %s\n",
16052 indent, "", buf);
16053 }
16054 }
16055 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
16056 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
16057 && ecommunity_cmp(
16058 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16059 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
16060
16061 char *b = ecommunity_ecom2str(
16062 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16063 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
16064 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
16065 XFREE(MTYPE_ECOMMUNITY_STR, b);
16066 } else {
16067 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
16068 char *b = ecommunity_ecom2str(
16069 bgp->vpn_policy[afi]
16070 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16071 ECOMMUNITY_FORMAT_ROUTE_MAP,
16072 ECOMMUNITY_ROUTE_TARGET);
16073 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
16074 XFREE(MTYPE_ECOMMUNITY_STR, b);
16075 }
16076 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
16077 char *b = ecommunity_ecom2str(
16078 bgp->vpn_policy[afi]
16079 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16080 ECOMMUNITY_FORMAT_ROUTE_MAP,
16081 ECOMMUNITY_ROUTE_TARGET);
16082 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
16083 XFREE(MTYPE_ECOMMUNITY_STR, b);
16084 }
16085 }
16086
16087 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
16088 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
16089 bgp->vpn_policy[afi]
16090 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
16091
16092 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
16093 char *b = ecommunity_ecom2str(
16094 bgp->vpn_policy[afi]
16095 .import_redirect_rtlist,
16096 ECOMMUNITY_FORMAT_ROUTE_MAP,
16097 ECOMMUNITY_ROUTE_TARGET);
16098
16099 if (bgp->vpn_policy[afi].import_redirect_rtlist->unit_size
16100 != ECOMMUNITY_SIZE)
16101 vty_out(vty, "%*srt6 redirect import %s\n",
16102 indent, "", b);
16103 else
16104 vty_out(vty, "%*srt redirect import %s\n",
16105 indent, "", b);
16106 XFREE(MTYPE_ECOMMUNITY_STR, b);
16107 }
16108 }
16109
16110 static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
16111 afi_t afi, safi_t safi)
16112 {
16113 struct bgp_filter *filter;
16114 char *addr;
16115
16116 addr = peer->host;
16117 filter = &peer->filter[afi][safi];
16118
16119 /* distribute-list. */
16120 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16121 FILTER_IN))
16122 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
16123 filter->dlist[FILTER_IN].name);
16124
16125 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16126 FILTER_OUT))
16127 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
16128 filter->dlist[FILTER_OUT].name);
16129
16130 /* prefix-list. */
16131 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16132 FILTER_IN))
16133 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
16134 filter->plist[FILTER_IN].name);
16135
16136 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16137 FILTER_OUT))
16138 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
16139 filter->plist[FILTER_OUT].name);
16140
16141 /* route-map. */
16142 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
16143 vty_out(vty, " neighbor %s route-map %s in\n", addr,
16144 filter->map[RMAP_IN].name);
16145
16146 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
16147 RMAP_OUT))
16148 vty_out(vty, " neighbor %s route-map %s out\n", addr,
16149 filter->map[RMAP_OUT].name);
16150
16151 /* unsuppress-map */
16152 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
16153 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
16154 filter->usmap.name);
16155
16156 /* advertise-map : always applied in OUT direction*/
16157 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16158 CONDITION_NON_EXIST))
16159 vty_out(vty,
16160 " neighbor %s advertise-map %s non-exist-map %s\n",
16161 addr, filter->advmap.aname, filter->advmap.cname);
16162
16163 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16164 CONDITION_EXIST))
16165 vty_out(vty, " neighbor %s advertise-map %s exist-map %s\n",
16166 addr, filter->advmap.aname, filter->advmap.cname);
16167
16168 /* filter-list. */
16169 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16170 FILTER_IN))
16171 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
16172 filter->aslist[FILTER_IN].name);
16173
16174 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16175 FILTER_OUT))
16176 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
16177 filter->aslist[FILTER_OUT].name);
16178 }
16179
16180 /* BGP peer configuration display function. */
16181 static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
16182 struct peer *peer)
16183 {
16184 struct peer *g_peer = NULL;
16185 char buf[SU_ADDRSTRLEN];
16186 char *addr;
16187 int if_pg_printed = false;
16188 int if_ras_printed = false;
16189
16190 /* Skip dynamic neighbors. */
16191 if (peer_dynamic_neighbor(peer))
16192 return;
16193
16194 if (peer->conf_if)
16195 addr = peer->conf_if;
16196 else
16197 addr = peer->host;
16198
16199 /************************************
16200 ****** Global to the neighbor ******
16201 ************************************/
16202 if (peer->conf_if) {
16203 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
16204 vty_out(vty, " neighbor %s interface v6only", addr);
16205 else
16206 vty_out(vty, " neighbor %s interface", addr);
16207
16208 if (peer_group_active(peer)) {
16209 vty_out(vty, " peer-group %s", peer->group->name);
16210 if_pg_printed = true;
16211 } else if (peer->as_type == AS_SPECIFIED) {
16212 vty_out(vty, " remote-as %u", peer->as);
16213 if_ras_printed = true;
16214 } else if (peer->as_type == AS_INTERNAL) {
16215 vty_out(vty, " remote-as internal");
16216 if_ras_printed = true;
16217 } else if (peer->as_type == AS_EXTERNAL) {
16218 vty_out(vty, " remote-as external");
16219 if_ras_printed = true;
16220 }
16221
16222 vty_out(vty, "\n");
16223 }
16224
16225 /* remote-as and peer-group */
16226 /* peer is a member of a peer-group */
16227 if (peer_group_active(peer)) {
16228 g_peer = peer->group->conf;
16229
16230 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
16231 if (peer->as_type == AS_SPECIFIED) {
16232 vty_out(vty, " neighbor %s remote-as %u\n",
16233 addr, peer->as);
16234 } else if (peer->as_type == AS_INTERNAL) {
16235 vty_out(vty,
16236 " neighbor %s remote-as internal\n",
16237 addr);
16238 } else if (peer->as_type == AS_EXTERNAL) {
16239 vty_out(vty,
16240 " neighbor %s remote-as external\n",
16241 addr);
16242 }
16243 }
16244
16245 /* For swpX peers we displayed the peer-group
16246 * via 'neighbor swpX interface peer-group PGNAME' */
16247 if (!if_pg_printed)
16248 vty_out(vty, " neighbor %s peer-group %s\n", addr,
16249 peer->group->name);
16250 }
16251
16252 /* peer is NOT a member of a peer-group */
16253 else {
16254 /* peer is a peer-group, declare the peer-group */
16255 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
16256 vty_out(vty, " neighbor %s peer-group\n", addr);
16257 }
16258
16259 if (!if_ras_printed) {
16260 if (peer->as_type == AS_SPECIFIED) {
16261 vty_out(vty, " neighbor %s remote-as %u\n",
16262 addr, peer->as);
16263 } else if (peer->as_type == AS_INTERNAL) {
16264 vty_out(vty,
16265 " neighbor %s remote-as internal\n",
16266 addr);
16267 } else if (peer->as_type == AS_EXTERNAL) {
16268 vty_out(vty,
16269 " neighbor %s remote-as external\n",
16270 addr);
16271 }
16272 }
16273 }
16274
16275 /* local-as */
16276 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
16277 vty_out(vty, " neighbor %s local-as %u", addr,
16278 peer->change_local_as);
16279 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
16280 vty_out(vty, " no-prepend");
16281 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
16282 vty_out(vty, " replace-as");
16283 vty_out(vty, "\n");
16284 }
16285
16286 /* description */
16287 if (peer->desc) {
16288 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
16289 }
16290
16291 /* shutdown */
16292 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
16293 if (peer->tx_shutdown_message)
16294 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
16295 peer->tx_shutdown_message);
16296 else
16297 vty_out(vty, " neighbor %s shutdown\n", addr);
16298 }
16299
16300 if (peergroup_flag_check(peer, PEER_FLAG_RTT_SHUTDOWN))
16301 vty_out(vty, " neighbor %s shutdown rtt %u count %u\n", addr,
16302 peer->rtt_expected, peer->rtt_keepalive_conf);
16303
16304 /* bfd */
16305 if (peer->bfd_info) {
16306 if (!peer_group_active(peer) || !g_peer->bfd_info) {
16307 bgp_bfd_peer_config_write(vty, peer, addr);
16308 }
16309 }
16310
16311 /* password */
16312 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
16313 vty_out(vty, " neighbor %s password %s\n", addr,
16314 peer->password);
16315
16316 /* neighbor solo */
16317 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
16318 if (!peer_group_active(peer)) {
16319 vty_out(vty, " neighbor %s solo\n", addr);
16320 }
16321 }
16322
16323 /* BGP port */
16324 if (peer->port != BGP_PORT_DEFAULT) {
16325 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
16326 }
16327
16328 /* Local interface name */
16329 if (peer->ifname) {
16330 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
16331 }
16332
16333 /* passive */
16334 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
16335 vty_out(vty, " neighbor %s passive\n", addr);
16336
16337 /* ebgp-multihop */
16338 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
16339 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
16340 && peer->ttl == MAXTTL)) {
16341 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
16342 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
16343 peer->ttl);
16344 }
16345 }
16346
16347 /* ttl-security hops */
16348 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
16349 if (!peer_group_active(peer)
16350 || g_peer->gtsm_hops != peer->gtsm_hops) {
16351 vty_out(vty, " neighbor %s ttl-security hops %d\n",
16352 addr, peer->gtsm_hops);
16353 }
16354 }
16355
16356 /* disable-connected-check */
16357 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
16358 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
16359
16360 /* enforce-first-as */
16361 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
16362 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
16363
16364 /* update-source */
16365 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
16366 if (peer->update_source)
16367 vty_out(vty, " neighbor %s update-source %s\n", addr,
16368 sockunion2str(peer->update_source, buf,
16369 SU_ADDRSTRLEN));
16370 else if (peer->update_if)
16371 vty_out(vty, " neighbor %s update-source %s\n", addr,
16372 peer->update_if);
16373 }
16374
16375 /* advertisement-interval */
16376 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
16377 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
16378 peer->routeadv);
16379
16380 /* timers */
16381 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
16382 vty_out(vty, " neighbor %s timers %u %u\n", addr,
16383 peer->keepalive, peer->holdtime);
16384
16385 /* timers connect */
16386 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
16387 vty_out(vty, " neighbor %s timers connect %u\n", addr,
16388 peer->connect);
16389 /* need special-case handling for changed default values due to
16390 * config profile / version (because there is no "timers bgp connect"
16391 * command, we need to save this per-peer :/)
16392 */
16393 else if (!peer_group_active(peer) && !peer->connect &&
16394 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
16395 vty_out(vty, " neighbor %s timers connect %u\n", addr,
16396 peer->bgp->default_connect_retry);
16397
16398 /* capability dynamic */
16399 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
16400 vty_out(vty, " neighbor %s capability dynamic\n", addr);
16401
16402 /* capability extended-nexthop */
16403 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
16404 if (!peer->conf_if) {
16405 if (CHECK_FLAG(peer->flags_invert,
16406 PEER_FLAG_CAPABILITY_ENHE))
16407 vty_out(vty,
16408 " no neighbor %s capability extended-nexthop\n",
16409 addr);
16410 else
16411 vty_out(vty,
16412 " neighbor %s capability extended-nexthop\n",
16413 addr);
16414 }
16415 }
16416
16417 /* dont-capability-negotiation */
16418 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
16419 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
16420
16421 /* override-capability */
16422 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
16423 vty_out(vty, " neighbor %s override-capability\n", addr);
16424
16425 /* strict-capability-match */
16426 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
16427 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
16428
16429 /* Sender side AS path loop detection. */
16430 if (peer->as_path_loop_detection)
16431 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
16432 addr);
16433
16434 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
16435 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
16436
16437 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
16438 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
16439 vty_out(vty,
16440 " neighbor %s graceful-restart-helper\n", addr);
16441 } else if (CHECK_FLAG(
16442 peer->peer_gr_new_status_flag,
16443 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
16444 vty_out(vty,
16445 " neighbor %s graceful-restart\n", addr);
16446 } else if (
16447 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
16448 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
16449 && !(CHECK_FLAG(
16450 peer->peer_gr_new_status_flag,
16451 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
16452 vty_out(vty, " neighbor %s graceful-restart-disable\n",
16453 addr);
16454 }
16455 }
16456 }
16457
16458 /* BGP peer configuration display function. */
16459 static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
16460 struct peer *peer, afi_t afi, safi_t safi)
16461 {
16462 struct peer *g_peer = NULL;
16463 char *addr;
16464 bool flag_scomm, flag_secomm, flag_slcomm;
16465
16466 /* Skip dynamic neighbors. */
16467 if (peer_dynamic_neighbor(peer))
16468 return;
16469
16470 if (peer->conf_if)
16471 addr = peer->conf_if;
16472 else
16473 addr = peer->host;
16474
16475 /************************************
16476 ****** Per AF to the neighbor ******
16477 ************************************/
16478 if (peer_group_active(peer)) {
16479 g_peer = peer->group->conf;
16480
16481 /* If the peer-group is active but peer is not, print a 'no
16482 * activate' */
16483 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
16484 vty_out(vty, " no neighbor %s activate\n", addr);
16485 }
16486
16487 /* If the peer-group is not active but peer is, print an
16488 'activate' */
16489 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
16490 vty_out(vty, " neighbor %s activate\n", addr);
16491 }
16492 } else {
16493 if (peer->afc[afi][safi]) {
16494 if ((afi == AFI_IP) && (safi == SAFI_UNICAST)) {
16495 if (CHECK_FLAG(bgp->flags,
16496 BGP_FLAG_NO_DEFAULT_IPV4)) {
16497 vty_out(vty, " neighbor %s activate\n",
16498 addr);
16499 }
16500 } else
16501 vty_out(vty, " neighbor %s activate\n", addr);
16502 } else {
16503 if ((afi == AFI_IP) && (safi == SAFI_UNICAST)) {
16504 if (!CHECK_FLAG(bgp->flags,
16505 BGP_FLAG_NO_DEFAULT_IPV4)) {
16506 vty_out(vty,
16507 " no neighbor %s activate\n",
16508 addr);
16509 }
16510 }
16511 }
16512 }
16513
16514 /* addpath TX knobs */
16515 if (peergroup_af_addpath_check(peer, afi, safi)) {
16516 switch (peer->addpath_type[afi][safi]) {
16517 case BGP_ADDPATH_ALL:
16518 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
16519 addr);
16520 break;
16521 case BGP_ADDPATH_BEST_PER_AS:
16522 vty_out(vty,
16523 " neighbor %s addpath-tx-bestpath-per-AS\n",
16524 addr);
16525 break;
16526 case BGP_ADDPATH_MAX:
16527 case BGP_ADDPATH_NONE:
16528 break;
16529 }
16530 }
16531
16532 /* ORF capability. */
16533 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
16534 || peergroup_af_flag_check(peer, afi, safi,
16535 PEER_FLAG_ORF_PREFIX_RM)) {
16536 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
16537
16538 if (peergroup_af_flag_check(peer, afi, safi,
16539 PEER_FLAG_ORF_PREFIX_SM)
16540 && peergroup_af_flag_check(peer, afi, safi,
16541 PEER_FLAG_ORF_PREFIX_RM))
16542 vty_out(vty, " both");
16543 else if (peergroup_af_flag_check(peer, afi, safi,
16544 PEER_FLAG_ORF_PREFIX_SM))
16545 vty_out(vty, " send");
16546 else
16547 vty_out(vty, " receive");
16548 vty_out(vty, "\n");
16549 }
16550
16551 /* Route reflector client. */
16552 if (peergroup_af_flag_check(peer, afi, safi,
16553 PEER_FLAG_REFLECTOR_CLIENT)) {
16554 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
16555 }
16556
16557 /* next-hop-self force */
16558 if (peergroup_af_flag_check(peer, afi, safi,
16559 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
16560 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
16561 }
16562
16563 /* next-hop-self */
16564 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
16565 vty_out(vty, " neighbor %s next-hop-self\n", addr);
16566 }
16567
16568 /* remove-private-AS */
16569 if (peergroup_af_flag_check(peer, afi, safi,
16570 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
16571 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
16572 addr);
16573 }
16574
16575 else if (peergroup_af_flag_check(peer, afi, safi,
16576 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
16577 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
16578 addr);
16579 }
16580
16581 else if (peergroup_af_flag_check(peer, afi, safi,
16582 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
16583 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
16584 }
16585
16586 else if (peergroup_af_flag_check(peer, afi, safi,
16587 PEER_FLAG_REMOVE_PRIVATE_AS)) {
16588 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
16589 }
16590
16591 /* as-override */
16592 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
16593 vty_out(vty, " neighbor %s as-override\n", addr);
16594 }
16595
16596 /* send-community print. */
16597 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
16598 PEER_FLAG_SEND_COMMUNITY);
16599 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
16600 PEER_FLAG_SEND_EXT_COMMUNITY);
16601 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
16602 PEER_FLAG_SEND_LARGE_COMMUNITY);
16603
16604 if (flag_scomm && flag_secomm && flag_slcomm) {
16605 vty_out(vty, " no neighbor %s send-community all\n", addr);
16606 } else {
16607 if (flag_scomm)
16608 vty_out(vty, " no neighbor %s send-community\n", addr);
16609 if (flag_secomm)
16610 vty_out(vty,
16611 " no neighbor %s send-community extended\n",
16612 addr);
16613
16614 if (flag_slcomm)
16615 vty_out(vty, " no neighbor %s send-community large\n",
16616 addr);
16617 }
16618
16619 /* Default information */
16620 if (peergroup_af_flag_check(peer, afi, safi,
16621 PEER_FLAG_DEFAULT_ORIGINATE)) {
16622 vty_out(vty, " neighbor %s default-originate", addr);
16623
16624 if (peer->default_rmap[afi][safi].name)
16625 vty_out(vty, " route-map %s",
16626 peer->default_rmap[afi][safi].name);
16627
16628 vty_out(vty, "\n");
16629 }
16630
16631 /* Soft reconfiguration inbound. */
16632 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
16633 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
16634 addr);
16635 }
16636
16637 /* maximum-prefix. */
16638 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
16639 vty_out(vty, " neighbor %s maximum-prefix %u", addr,
16640 peer->pmax[afi][safi]);
16641
16642 if (peer->pmax_threshold[afi][safi]
16643 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
16644 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
16645 if (peer_af_flag_check(peer, afi, safi,
16646 PEER_FLAG_MAX_PREFIX_WARNING))
16647 vty_out(vty, " warning-only");
16648 if (peer->pmax_restart[afi][safi])
16649 vty_out(vty, " restart %u",
16650 peer->pmax_restart[afi][safi]);
16651 if (peer_af_flag_check(peer, afi, safi,
16652 PEER_FLAG_MAX_PREFIX_FORCE))
16653 vty_out(vty, " force");
16654
16655 vty_out(vty, "\n");
16656 }
16657
16658 /* maximum-prefix-out */
16659 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
16660 vty_out(vty, " neighbor %s maximum-prefix-out %u\n",
16661 addr, peer->pmax_out[afi][safi]);
16662
16663 /* Route server client. */
16664 if (peergroup_af_flag_check(peer, afi, safi,
16665 PEER_FLAG_RSERVER_CLIENT)) {
16666 vty_out(vty, " neighbor %s route-server-client\n", addr);
16667 }
16668
16669 /* Nexthop-local unchanged. */
16670 if (peergroup_af_flag_check(peer, afi, safi,
16671 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
16672 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
16673 }
16674
16675 /* allowas-in <1-10> */
16676 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
16677 if (peer_af_flag_check(peer, afi, safi,
16678 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
16679 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
16680 } else if (peer->allowas_in[afi][safi] == 3) {
16681 vty_out(vty, " neighbor %s allowas-in\n", addr);
16682 } else {
16683 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
16684 peer->allowas_in[afi][safi]);
16685 }
16686 }
16687
16688 /* weight */
16689 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
16690 vty_out(vty, " neighbor %s weight %lu\n", addr,
16691 peer->weight[afi][safi]);
16692
16693 /* Filter. */
16694 bgp_config_write_filter(vty, peer, afi, safi);
16695
16696 /* atribute-unchanged. */
16697 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
16698 || (safi != SAFI_EVPN
16699 && peer_af_flag_check(peer, afi, safi,
16700 PEER_FLAG_NEXTHOP_UNCHANGED))
16701 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
16702
16703 if (!peer_group_active(peer)
16704 || peergroup_af_flag_check(peer, afi, safi,
16705 PEER_FLAG_AS_PATH_UNCHANGED)
16706 || peergroup_af_flag_check(peer, afi, safi,
16707 PEER_FLAG_NEXTHOP_UNCHANGED)
16708 || peergroup_af_flag_check(peer, afi, safi,
16709 PEER_FLAG_MED_UNCHANGED)) {
16710
16711 vty_out(vty,
16712 " neighbor %s attribute-unchanged%s%s%s\n",
16713 addr,
16714 peer_af_flag_check(peer, afi, safi,
16715 PEER_FLAG_AS_PATH_UNCHANGED)
16716 ? " as-path"
16717 : "",
16718 peer_af_flag_check(peer, afi, safi,
16719 PEER_FLAG_NEXTHOP_UNCHANGED)
16720 ? " next-hop"
16721 : "",
16722 peer_af_flag_check(peer, afi, safi,
16723 PEER_FLAG_MED_UNCHANGED)
16724 ? " med"
16725 : "");
16726 }
16727 }
16728 }
16729
16730 /* Address family based peer configuration display. */
16731 static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
16732 safi_t safi)
16733 {
16734 struct peer *peer;
16735 struct peer_group *group;
16736 struct listnode *node, *nnode;
16737
16738
16739 vty_frame(vty, " !\n address-family ");
16740 if (afi == AFI_IP) {
16741 if (safi == SAFI_UNICAST)
16742 vty_frame(vty, "ipv4 unicast");
16743 else if (safi == SAFI_LABELED_UNICAST)
16744 vty_frame(vty, "ipv4 labeled-unicast");
16745 else if (safi == SAFI_MULTICAST)
16746 vty_frame(vty, "ipv4 multicast");
16747 else if (safi == SAFI_MPLS_VPN)
16748 vty_frame(vty, "ipv4 vpn");
16749 else if (safi == SAFI_ENCAP)
16750 vty_frame(vty, "ipv4 encap");
16751 else if (safi == SAFI_FLOWSPEC)
16752 vty_frame(vty, "ipv4 flowspec");
16753 } else if (afi == AFI_IP6) {
16754 if (safi == SAFI_UNICAST)
16755 vty_frame(vty, "ipv6 unicast");
16756 else if (safi == SAFI_LABELED_UNICAST)
16757 vty_frame(vty, "ipv6 labeled-unicast");
16758 else if (safi == SAFI_MULTICAST)
16759 vty_frame(vty, "ipv6 multicast");
16760 else if (safi == SAFI_MPLS_VPN)
16761 vty_frame(vty, "ipv6 vpn");
16762 else if (safi == SAFI_ENCAP)
16763 vty_frame(vty, "ipv6 encap");
16764 else if (safi == SAFI_FLOWSPEC)
16765 vty_frame(vty, "ipv6 flowspec");
16766 } else if (afi == AFI_L2VPN) {
16767 if (safi == SAFI_EVPN)
16768 vty_frame(vty, "l2vpn evpn");
16769 }
16770 vty_frame(vty, "\n");
16771
16772 bgp_config_write_distance(vty, bgp, afi, safi);
16773
16774 bgp_config_write_network(vty, bgp, afi, safi);
16775
16776 bgp_config_write_redistribute(vty, bgp, afi, safi);
16777
16778 /* BGP flag dampening. */
16779 if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
16780 bgp_config_write_damp(vty, afi, safi);
16781
16782 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
16783 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
16784
16785 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
16786 /* Skip dynamic neighbors. */
16787 if (peer_dynamic_neighbor(peer))
16788 continue;
16789
16790 /* Do not display doppelganger peers */
16791 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
16792 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
16793 }
16794
16795 bgp_config_write_maxpaths(vty, bgp, afi, safi);
16796 bgp_config_write_table_map(vty, bgp, afi, safi);
16797
16798 if (safi == SAFI_EVPN)
16799 bgp_config_write_evpn_info(vty, bgp, afi, safi);
16800
16801 if (safi == SAFI_FLOWSPEC)
16802 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
16803
16804 if (safi == SAFI_UNICAST) {
16805 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
16806 if (CHECK_FLAG(bgp->af_flags[afi][safi],
16807 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
16808
16809 vty_out(vty, " export vpn\n");
16810 }
16811 if (CHECK_FLAG(bgp->af_flags[afi][safi],
16812 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
16813
16814 vty_out(vty, " import vpn\n");
16815 }
16816 if (CHECK_FLAG(bgp->af_flags[afi][safi],
16817 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
16818 char *name;
16819
16820 for (ALL_LIST_ELEMENTS_RO(
16821 bgp->vpn_policy[afi].import_vrf, node,
16822 name))
16823 vty_out(vty, " import vrf %s\n", name);
16824 }
16825 }
16826
16827 vty_endframe(vty, " exit-address-family\n");
16828 }
16829
16830 int bgp_config_write(struct vty *vty)
16831 {
16832 struct bgp *bgp;
16833 struct peer_group *group;
16834 struct peer *peer;
16835 struct listnode *node, *nnode;
16836 struct listnode *mnode, *mnnode;
16837
16838 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
16839 vty_out(vty, "bgp route-map delay-timer %u\n",
16840 bm->rmap_update_timer);
16841
16842 if (bm->v_update_delay != BGP_UPDATE_DELAY_DEF) {
16843 vty_out(vty, "bgp update-delay %d", bm->v_update_delay);
16844 if (bm->v_update_delay != bm->v_establish_wait)
16845 vty_out(vty, " %d", bm->v_establish_wait);
16846 vty_out(vty, "\n");
16847 }
16848
16849 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
16850 vty_out(vty, "bgp graceful-shutdown\n");
16851
16852 /* No-RIB (Zebra) option flag configuration */
16853 if (bgp_option_check(BGP_OPT_NO_FIB))
16854 vty_out(vty, "bgp no-rib\n");
16855
16856 /* BGP configuration. */
16857 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
16858
16859 /* skip all auto created vrf as they dont have user config */
16860 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
16861 continue;
16862
16863 /* Router bgp ASN */
16864 vty_out(vty, "router bgp %u", bgp->as);
16865
16866 if (bgp->name)
16867 vty_out(vty, " %s %s",
16868 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
16869 ? "view" : "vrf", bgp->name);
16870 vty_out(vty, "\n");
16871
16872 /* BGP fast-external-failover. */
16873 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
16874 vty_out(vty, " no bgp fast-external-failover\n");
16875
16876 /* BGP router ID. */
16877 if (bgp->router_id_static.s_addr != 0)
16878 vty_out(vty, " bgp router-id %pI4\n",
16879 &bgp->router_id_static);
16880
16881 /* Suppress fib pending */
16882 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_FIB_PENDING))
16883 vty_out(vty, " bgp suppress-fib-pending\n");
16884
16885 /* BGP log-neighbor-changes. */
16886 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
16887 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
16888 vty_out(vty, " %sbgp log-neighbor-changes\n",
16889 CHECK_FLAG(bgp->flags,
16890 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
16891 ? ""
16892 : "no ");
16893
16894 /* BGP configuration. */
16895 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
16896 vty_out(vty, " bgp always-compare-med\n");
16897
16898 /* RFC8212 default eBGP policy. */
16899 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
16900 != SAVE_BGP_EBGP_REQUIRES_POLICY)
16901 vty_out(vty, " %sbgp ebgp-requires-policy\n",
16902 CHECK_FLAG(bgp->flags,
16903 BGP_FLAG_EBGP_REQUIRES_POLICY)
16904 ? ""
16905 : "no ");
16906
16907 /* draft-ietf-idr-deprecate-as-set-confed-set */
16908 if (bgp->reject_as_sets)
16909 vty_out(vty, " bgp reject-as-sets\n");
16910
16911 /* BGP default ipv4-unicast. */
16912 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4))
16913 vty_out(vty, " no bgp default ipv4-unicast\n");
16914
16915 /* BGP default local-preference. */
16916 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
16917 vty_out(vty, " bgp default local-preference %u\n",
16918 bgp->default_local_pref);
16919
16920 /* BGP default show-hostname */
16921 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
16922 != SAVE_BGP_SHOW_HOSTNAME)
16923 vty_out(vty, " %sbgp default show-hostname\n",
16924 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
16925 ? ""
16926 : "no ");
16927
16928 /* BGP default show-nexthop-hostname */
16929 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
16930 != SAVE_BGP_SHOW_HOSTNAME)
16931 vty_out(vty, " %sbgp default show-nexthop-hostname\n",
16932 CHECK_FLAG(bgp->flags,
16933 BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
16934 ? ""
16935 : "no ");
16936
16937 /* BGP default subgroup-pkt-queue-max. */
16938 if (bgp->default_subgroup_pkt_queue_max
16939 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
16940 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
16941 bgp->default_subgroup_pkt_queue_max);
16942
16943 /* BGP client-to-client reflection. */
16944 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
16945 vty_out(vty, " no bgp client-to-client reflection\n");
16946
16947 /* BGP cluster ID. */
16948 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
16949 vty_out(vty, " bgp cluster-id %pI4\n",
16950 &bgp->cluster_id);
16951
16952 /* Disable ebgp connected nexthop check */
16953 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
16954 vty_out(vty,
16955 " bgp disable-ebgp-connected-route-check\n");
16956
16957 /* Confederation identifier*/
16958 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
16959 vty_out(vty, " bgp confederation identifier %u\n",
16960 bgp->confed_id);
16961
16962 /* Confederation peer */
16963 if (bgp->confed_peers_cnt > 0) {
16964 int i;
16965
16966 vty_out(vty, " bgp confederation peers");
16967
16968 for (i = 0; i < bgp->confed_peers_cnt; i++)
16969 vty_out(vty, " %u", bgp->confed_peers[i]);
16970
16971 vty_out(vty, "\n");
16972 }
16973
16974 /* BGP deterministic-med. */
16975 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
16976 != SAVE_BGP_DETERMINISTIC_MED)
16977 vty_out(vty, " %sbgp deterministic-med\n",
16978 CHECK_FLAG(bgp->flags,
16979 BGP_FLAG_DETERMINISTIC_MED)
16980 ? ""
16981 : "no ");
16982
16983 /* BGP update-delay. */
16984 bgp_config_write_update_delay(vty, bgp);
16985
16986 if (bgp->v_maxmed_onstartup
16987 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
16988 vty_out(vty, " bgp max-med on-startup %u",
16989 bgp->v_maxmed_onstartup);
16990 if (bgp->maxmed_onstartup_value
16991 != BGP_MAXMED_VALUE_DEFAULT)
16992 vty_out(vty, " %u",
16993 bgp->maxmed_onstartup_value);
16994 vty_out(vty, "\n");
16995 }
16996 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
16997 vty_out(vty, " bgp max-med administrative");
16998 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
16999 vty_out(vty, " %u", bgp->maxmed_admin_value);
17000 vty_out(vty, "\n");
17001 }
17002
17003 /* write quanta */
17004 bgp_config_write_wpkt_quanta(vty, bgp);
17005 /* read quanta */
17006 bgp_config_write_rpkt_quanta(vty, bgp);
17007
17008 /* coalesce time */
17009 bgp_config_write_coalesce_time(vty, bgp);
17010
17011 /* BGP per-instance graceful-shutdown */
17012 /* BGP-wide settings and per-instance settings are mutually
17013 * exclusive.
17014 */
17015 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17016 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
17017 vty_out(vty, " bgp graceful-shutdown\n");
17018
17019 /* BGP graceful-restart. */
17020 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
17021 vty_out(vty,
17022 " bgp graceful-restart stalepath-time %u\n",
17023 bgp->stalepath_time);
17024
17025 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
17026 vty_out(vty, " bgp graceful-restart restart-time %u\n",
17027 bgp->restart_time);
17028
17029 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
17030 vty_out(vty,
17031 " bgp graceful-restart select-defer-time %u\n",
17032 bgp->select_defer_time);
17033
17034 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
17035 vty_out(vty, " bgp graceful-restart\n");
17036
17037 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
17038 vty_out(vty, " bgp graceful-restart-disable\n");
17039
17040 /* BGP graceful-restart Preserve State F bit. */
17041 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
17042 vty_out(vty,
17043 " bgp graceful-restart preserve-fw-state\n");
17044
17045 /* Stale timer for RIB */
17046 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
17047 vty_out(vty,
17048 " bgp graceful-restart rib-stale-time %u\n",
17049 bgp->rib_stale_time);
17050
17051 /* BGP bestpath method. */
17052 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
17053 vty_out(vty, " bgp bestpath as-path ignore\n");
17054 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
17055 vty_out(vty, " bgp bestpath as-path confed\n");
17056
17057 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
17058 if (CHECK_FLAG(bgp->flags,
17059 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
17060 vty_out(vty,
17061 " bgp bestpath as-path multipath-relax as-set\n");
17062 } else {
17063 vty_out(vty,
17064 " bgp bestpath as-path multipath-relax\n");
17065 }
17066 }
17067
17068 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
17069 vty_out(vty,
17070 " bgp route-reflector allow-outbound-policy\n");
17071 }
17072 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
17073 vty_out(vty, " bgp bestpath compare-routerid\n");
17074 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
17075 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
17076 vty_out(vty, " bgp bestpath med");
17077 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
17078 vty_out(vty, " confed");
17079 if (CHECK_FLAG(bgp->flags,
17080 BGP_FLAG_MED_MISSING_AS_WORST))
17081 vty_out(vty, " missing-as-worst");
17082 vty_out(vty, "\n");
17083 }
17084
17085 /* Link bandwidth handling. */
17086 if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW)
17087 vty_out(vty, " bgp bestpath bandwidth ignore\n");
17088 else if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
17089 vty_out(vty, " bgp bestpath bandwidth skip-missing\n");
17090 else if (bgp->lb_handling == BGP_LINK_BW_DEFWT_4_MISSING)
17091 vty_out(vty, " bgp bestpath bandwidth default-weight-for-missing\n");
17092
17093 /* BGP network import check. */
17094 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
17095 != SAVE_BGP_IMPORT_CHECK)
17096 vty_out(vty, " %sbgp network import-check\n",
17097 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
17098 ? ""
17099 : "no ");
17100
17101 /* BGP timers configuration. */
17102 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
17103 && bgp->default_holdtime != SAVE_BGP_HOLDTIME)
17104 vty_out(vty, " timers bgp %u %u\n",
17105 bgp->default_keepalive, bgp->default_holdtime);
17106
17107 /* peer-group */
17108 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
17109 bgp_config_write_peer_global(vty, bgp, group->conf);
17110 }
17111
17112 /* Normal neighbor configuration. */
17113 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17114 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17115 bgp_config_write_peer_global(vty, bgp, peer);
17116 }
17117
17118 /* listen range and limit for dynamic BGP neighbors */
17119 bgp_config_write_listen(vty, bgp);
17120
17121 /*
17122 * BGP default autoshutdown neighbors
17123 *
17124 * This must be placed after any peer and peer-group
17125 * configuration, to avoid setting all peers to shutdown after
17126 * a daemon restart, which is undesired behavior. (see #2286)
17127 */
17128 if (bgp->autoshutdown)
17129 vty_out(vty, " bgp default shutdown\n");
17130
17131 /* BGP instance administrative shutdown */
17132 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN))
17133 vty_out(vty, " bgp shutdown\n");
17134
17135 /* IPv4 unicast configuration. */
17136 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
17137
17138 /* IPv4 multicast configuration. */
17139 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
17140
17141 /* IPv4 labeled-unicast configuration. */
17142 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
17143
17144 /* IPv4 VPN configuration. */
17145 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
17146
17147 /* ENCAPv4 configuration. */
17148 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
17149
17150 /* FLOWSPEC v4 configuration. */
17151 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
17152
17153 /* IPv6 unicast configuration. */
17154 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
17155
17156 /* IPv6 multicast configuration. */
17157 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
17158
17159 /* IPv6 labeled-unicast configuration. */
17160 bgp_config_write_family(vty, bgp, AFI_IP6,
17161 SAFI_LABELED_UNICAST);
17162
17163 /* IPv6 VPN configuration. */
17164 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
17165
17166 /* ENCAPv6 configuration. */
17167 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
17168
17169 /* FLOWSPEC v6 configuration. */
17170 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
17171
17172 /* EVPN configuration. */
17173 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
17174
17175 hook_call(bgp_inst_config_write, bgp, vty);
17176
17177 #ifdef ENABLE_BGP_VNC
17178 bgp_rfapi_cfg_write(vty, bgp);
17179 #endif
17180
17181 vty_out(vty, "!\n");
17182 }
17183 return 0;
17184 }
17185
17186
17187 /* BGP node structure. */
17188 static struct cmd_node bgp_node = {
17189 .name = "bgp",
17190 .node = BGP_NODE,
17191 .parent_node = CONFIG_NODE,
17192 .prompt = "%s(config-router)# ",
17193 .config_write = bgp_config_write,
17194 };
17195
17196 static struct cmd_node bgp_ipv4_unicast_node = {
17197 .name = "bgp ipv4 unicast",
17198 .node = BGP_IPV4_NODE,
17199 .parent_node = BGP_NODE,
17200 .prompt = "%s(config-router-af)# ",
17201 };
17202
17203 static struct cmd_node bgp_ipv4_multicast_node = {
17204 .name = "bgp ipv4 multicast",
17205 .node = BGP_IPV4M_NODE,
17206 .parent_node = BGP_NODE,
17207 .prompt = "%s(config-router-af)# ",
17208 };
17209
17210 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
17211 .name = "bgp ipv4 labeled unicast",
17212 .node = BGP_IPV4L_NODE,
17213 .parent_node = BGP_NODE,
17214 .prompt = "%s(config-router-af)# ",
17215 };
17216
17217 static struct cmd_node bgp_ipv6_unicast_node = {
17218 .name = "bgp ipv6",
17219 .node = BGP_IPV6_NODE,
17220 .parent_node = BGP_NODE,
17221 .prompt = "%s(config-router-af)# ",
17222 };
17223
17224 static struct cmd_node bgp_ipv6_multicast_node = {
17225 .name = "bgp ipv6 multicast",
17226 .node = BGP_IPV6M_NODE,
17227 .parent_node = BGP_NODE,
17228 .prompt = "%s(config-router-af)# ",
17229 };
17230
17231 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
17232 .name = "bgp ipv6 labeled unicast",
17233 .node = BGP_IPV6L_NODE,
17234 .parent_node = BGP_NODE,
17235 .prompt = "%s(config-router-af)# ",
17236 };
17237
17238 static struct cmd_node bgp_vpnv4_node = {
17239 .name = "bgp vpnv4",
17240 .node = BGP_VPNV4_NODE,
17241 .parent_node = BGP_NODE,
17242 .prompt = "%s(config-router-af)# ",
17243 };
17244
17245 static struct cmd_node bgp_vpnv6_node = {
17246 .name = "bgp vpnv6",
17247 .node = BGP_VPNV6_NODE,
17248 .parent_node = BGP_NODE,
17249 .prompt = "%s(config-router-af-vpnv6)# ",
17250 };
17251
17252 static struct cmd_node bgp_evpn_node = {
17253 .name = "bgp evpn",
17254 .node = BGP_EVPN_NODE,
17255 .parent_node = BGP_NODE,
17256 .prompt = "%s(config-router-evpn)# ",
17257 };
17258
17259 static struct cmd_node bgp_evpn_vni_node = {
17260 .name = "bgp evpn vni",
17261 .node = BGP_EVPN_VNI_NODE,
17262 .parent_node = BGP_EVPN_NODE,
17263 .prompt = "%s(config-router-af-vni)# ",
17264 };
17265
17266 static struct cmd_node bgp_flowspecv4_node = {
17267 .name = "bgp ipv4 flowspec",
17268 .node = BGP_FLOWSPECV4_NODE,
17269 .parent_node = BGP_NODE,
17270 .prompt = "%s(config-router-af)# ",
17271 };
17272
17273 static struct cmd_node bgp_flowspecv6_node = {
17274 .name = "bgp ipv6 flowspec",
17275 .node = BGP_FLOWSPECV6_NODE,
17276 .parent_node = BGP_NODE,
17277 .prompt = "%s(config-router-af-vpnv6)# ",
17278 };
17279
17280 static void community_list_vty(void);
17281
17282 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
17283 {
17284 struct bgp *bgp;
17285 struct peer *peer;
17286 struct listnode *lnbgp, *lnpeer;
17287
17288 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
17289 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
17290 /* only provide suggestions on the appropriate input
17291 * token type,
17292 * they'll otherwise show up multiple times */
17293 enum cmd_token_type match_type;
17294 char *name = peer->host;
17295
17296 if (peer->conf_if) {
17297 match_type = VARIABLE_TKN;
17298 name = peer->conf_if;
17299 } else if (strchr(peer->host, ':'))
17300 match_type = IPV6_TKN;
17301 else
17302 match_type = IPV4_TKN;
17303
17304 if (token->type != match_type)
17305 continue;
17306
17307 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
17308 }
17309 }
17310 }
17311
17312 static const struct cmd_variable_handler bgp_var_neighbor[] = {
17313 {.varname = "neighbor", .completions = bgp_ac_neighbor},
17314 {.varname = "neighbors", .completions = bgp_ac_neighbor},
17315 {.varname = "peer", .completions = bgp_ac_neighbor},
17316 {.completions = NULL}};
17317
17318 static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
17319 {
17320 struct bgp *bgp;
17321 struct peer_group *group;
17322 struct listnode *lnbgp, *lnpeer;
17323
17324 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
17325 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
17326 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
17327 group->name));
17328 }
17329 }
17330
17331 static const struct cmd_variable_handler bgp_var_peergroup[] = {
17332 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
17333 {.completions = NULL} };
17334
17335 void bgp_vty_init(void)
17336 {
17337 cmd_variable_handler_register(bgp_var_neighbor);
17338 cmd_variable_handler_register(bgp_var_peergroup);
17339
17340 /* Install bgp top node. */
17341 install_node(&bgp_node);
17342 install_node(&bgp_ipv4_unicast_node);
17343 install_node(&bgp_ipv4_multicast_node);
17344 install_node(&bgp_ipv4_labeled_unicast_node);
17345 install_node(&bgp_ipv6_unicast_node);
17346 install_node(&bgp_ipv6_multicast_node);
17347 install_node(&bgp_ipv6_labeled_unicast_node);
17348 install_node(&bgp_vpnv4_node);
17349 install_node(&bgp_vpnv6_node);
17350 install_node(&bgp_evpn_node);
17351 install_node(&bgp_evpn_vni_node);
17352 install_node(&bgp_flowspecv4_node);
17353 install_node(&bgp_flowspecv6_node);
17354
17355 /* Install default VTY commands to new nodes. */
17356 install_default(BGP_NODE);
17357 install_default(BGP_IPV4_NODE);
17358 install_default(BGP_IPV4M_NODE);
17359 install_default(BGP_IPV4L_NODE);
17360 install_default(BGP_IPV6_NODE);
17361 install_default(BGP_IPV6M_NODE);
17362 install_default(BGP_IPV6L_NODE);
17363 install_default(BGP_VPNV4_NODE);
17364 install_default(BGP_VPNV6_NODE);
17365 install_default(BGP_FLOWSPECV4_NODE);
17366 install_default(BGP_FLOWSPECV6_NODE);
17367 install_default(BGP_EVPN_NODE);
17368 install_default(BGP_EVPN_VNI_NODE);
17369
17370 /* "bgp local-mac" hidden commands. */
17371 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
17372 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
17373
17374 /* bgp route-map delay-timer commands. */
17375 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
17376 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
17377
17378 /* global bgp update-delay command */
17379 install_element(CONFIG_NODE, &bgp_global_update_delay_cmd);
17380 install_element(CONFIG_NODE, &no_bgp_global_update_delay_cmd);
17381
17382 /* global bgp graceful-shutdown command */
17383 install_element(CONFIG_NODE, &bgp_graceful_shutdown_cmd);
17384 install_element(CONFIG_NODE, &no_bgp_graceful_shutdown_cmd);
17385
17386 /* Dummy commands (Currently not supported) */
17387 install_element(BGP_NODE, &no_synchronization_cmd);
17388 install_element(BGP_NODE, &no_auto_summary_cmd);
17389
17390 /* "router bgp" commands. */
17391 install_element(CONFIG_NODE, &router_bgp_cmd);
17392
17393 /* "no router bgp" commands. */
17394 install_element(CONFIG_NODE, &no_router_bgp_cmd);
17395
17396 /* "bgp router-id" commands. */
17397 install_element(BGP_NODE, &bgp_router_id_cmd);
17398 install_element(BGP_NODE, &no_bgp_router_id_cmd);
17399
17400 /* "bgp suppress-fib-pending" command */
17401 install_element(BGP_NODE, &bgp_suppress_fib_pending_cmd);
17402
17403 /* "bgp cluster-id" commands. */
17404 install_element(BGP_NODE, &bgp_cluster_id_cmd);
17405 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
17406
17407 /* "bgp no-rib" commands. */
17408 install_element(CONFIG_NODE, &bgp_norib_cmd);
17409 install_element(CONFIG_NODE, &no_bgp_norib_cmd);
17410
17411 /* "bgp confederation" commands. */
17412 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
17413 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
17414
17415 /* "bgp confederation peers" commands. */
17416 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
17417 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
17418
17419 /* bgp max-med command */
17420 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
17421 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
17422 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
17423 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
17424 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
17425
17426 /* bgp disable-ebgp-connected-nh-check */
17427 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
17428 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
17429
17430 /* bgp update-delay command */
17431 install_element(BGP_NODE, &bgp_update_delay_cmd);
17432 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
17433
17434 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
17435 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
17436
17437 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
17438 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
17439
17440 /* "maximum-paths" commands. */
17441 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
17442 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
17443 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
17444 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
17445 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
17446 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
17447 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
17448 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
17449 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
17450 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
17451 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17452 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
17453 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
17454 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17455 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
17456
17457 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_cmd);
17458 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_cmd);
17459 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cmd);
17460 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17461 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_ibgp_cmd);
17462 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
17463 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
17464 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
17465 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17466 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
17467
17468 /* "timers bgp" commands. */
17469 install_element(BGP_NODE, &bgp_timers_cmd);
17470 install_element(BGP_NODE, &no_bgp_timers_cmd);
17471
17472 /* route-map delay-timer commands - per instance for backwards compat.
17473 */
17474 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
17475 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
17476
17477 /* "bgp client-to-client reflection" commands */
17478 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
17479 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
17480
17481 /* "bgp always-compare-med" commands */
17482 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
17483 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
17484
17485 /* bgp ebgp-requires-policy */
17486 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
17487 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
17488
17489 /* bgp reject-as-sets */
17490 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
17491 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
17492
17493 /* "bgp deterministic-med" commands */
17494 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
17495 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
17496
17497 /* "bgp graceful-restart" command */
17498 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
17499 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
17500
17501 /* "bgp graceful-restart-disable" command */
17502 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
17503 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
17504
17505 /* "neighbor a:b:c:d graceful-restart" command */
17506 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
17507 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
17508
17509 /* "neighbor a:b:c:d graceful-restart-disable" command */
17510 install_element(BGP_NODE,
17511 &bgp_neighbor_graceful_restart_disable_set_cmd);
17512 install_element(BGP_NODE,
17513 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
17514
17515 /* "neighbor a:b:c:d graceful-restart-helper" command */
17516 install_element(BGP_NODE,
17517 &bgp_neighbor_graceful_restart_helper_set_cmd);
17518 install_element(BGP_NODE,
17519 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
17520
17521 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
17522 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
17523 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
17524 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
17525 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
17526 install_element(BGP_NODE,
17527 &no_bgp_graceful_restart_select_defer_time_cmd);
17528 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
17529 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
17530
17531 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
17532 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
17533 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
17534 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
17535
17536 /* "bgp graceful-shutdown" commands */
17537 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
17538 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
17539
17540 /* "bgp fast-external-failover" commands */
17541 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
17542 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
17543
17544 /* "bgp bestpath compare-routerid" commands */
17545 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
17546 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
17547
17548 /* "bgp bestpath as-path ignore" commands */
17549 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
17550 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
17551
17552 /* "bgp bestpath as-path confed" commands */
17553 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
17554 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
17555
17556 /* "bgp bestpath as-path multipath-relax" commands */
17557 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
17558 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
17559
17560 /* "bgp log-neighbor-changes" commands */
17561 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
17562 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
17563
17564 /* "bgp bestpath med" commands */
17565 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
17566 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
17567
17568 /* "bgp bestpath bandwidth" commands */
17569 install_element(BGP_NODE, &bgp_bestpath_bw_cmd);
17570 install_element(BGP_NODE, &no_bgp_bestpath_bw_cmd);
17571
17572 /* "no bgp default ipv4-unicast" commands. */
17573 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
17574 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
17575
17576 /* "bgp network import-check" commands. */
17577 install_element(BGP_NODE, &bgp_network_import_check_cmd);
17578 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
17579 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
17580
17581 /* "bgp default local-preference" commands. */
17582 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
17583 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
17584
17585 /* bgp default show-hostname */
17586 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
17587 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
17588
17589 /* bgp default show-nexthop-hostname */
17590 install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
17591 install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
17592
17593 /* "bgp default subgroup-pkt-queue-max" commands. */
17594 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
17595 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
17596
17597 /* bgp ibgp-allow-policy-mods command */
17598 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
17599 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
17600
17601 /* "bgp listen limit" commands. */
17602 install_element(BGP_NODE, &bgp_listen_limit_cmd);
17603 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
17604
17605 /* "bgp listen range" commands. */
17606 install_element(BGP_NODE, &bgp_listen_range_cmd);
17607 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
17608
17609 /* "bgp default shutdown" command */
17610 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
17611
17612 /* "bgp shutdown" commands */
17613 install_element(BGP_NODE, &bgp_shutdown_cmd);
17614 install_element(BGP_NODE, &bgp_shutdown_msg_cmd);
17615 install_element(BGP_NODE, &no_bgp_shutdown_cmd);
17616 install_element(BGP_NODE, &no_bgp_shutdown_msg_cmd);
17617
17618 /* "neighbor remote-as" commands. */
17619 install_element(BGP_NODE, &neighbor_remote_as_cmd);
17620 install_element(BGP_NODE, &neighbor_interface_config_cmd);
17621 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
17622 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
17623 install_element(BGP_NODE,
17624 &neighbor_interface_v6only_config_remote_as_cmd);
17625 install_element(BGP_NODE, &no_neighbor_cmd);
17626 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
17627
17628 /* "neighbor peer-group" commands. */
17629 install_element(BGP_NODE, &neighbor_peer_group_cmd);
17630 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
17631 install_element(BGP_NODE,
17632 &no_neighbor_interface_peer_group_remote_as_cmd);
17633
17634 /* "neighbor local-as" commands. */
17635 install_element(BGP_NODE, &neighbor_local_as_cmd);
17636 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
17637 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
17638 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
17639
17640 /* "neighbor solo" commands. */
17641 install_element(BGP_NODE, &neighbor_solo_cmd);
17642 install_element(BGP_NODE, &no_neighbor_solo_cmd);
17643
17644 /* "neighbor password" commands. */
17645 install_element(BGP_NODE, &neighbor_password_cmd);
17646 install_element(BGP_NODE, &no_neighbor_password_cmd);
17647
17648 /* "neighbor activate" commands. */
17649 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
17650 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
17651 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
17652 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
17653 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
17654 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
17655 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
17656 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
17657 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
17658 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
17659 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
17660 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
17661
17662 /* "no neighbor activate" commands. */
17663 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
17664 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
17665 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
17666 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
17667 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
17668 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
17669 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
17670 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
17671 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
17672 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
17673 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
17674 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
17675
17676 /* "neighbor peer-group" set commands. */
17677 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
17678 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
17679 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
17680 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
17681 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
17682 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
17683 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
17684 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
17685 install_element(BGP_FLOWSPECV4_NODE,
17686 &neighbor_set_peer_group_hidden_cmd);
17687 install_element(BGP_FLOWSPECV6_NODE,
17688 &neighbor_set_peer_group_hidden_cmd);
17689
17690 /* "no neighbor peer-group unset" commands. */
17691 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
17692 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17693 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17694 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17695 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17696 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17697 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17698 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17699 install_element(BGP_FLOWSPECV4_NODE,
17700 &no_neighbor_set_peer_group_hidden_cmd);
17701 install_element(BGP_FLOWSPECV6_NODE,
17702 &no_neighbor_set_peer_group_hidden_cmd);
17703
17704 /* "neighbor softreconfiguration inbound" commands.*/
17705 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
17706 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
17707 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
17708 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
17709 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
17710 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
17711 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
17712 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
17713 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
17714 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
17715 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
17716 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
17717 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
17718 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
17719 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
17720 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
17721 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
17722 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
17723 install_element(BGP_FLOWSPECV4_NODE,
17724 &neighbor_soft_reconfiguration_cmd);
17725 install_element(BGP_FLOWSPECV4_NODE,
17726 &no_neighbor_soft_reconfiguration_cmd);
17727 install_element(BGP_FLOWSPECV6_NODE,
17728 &neighbor_soft_reconfiguration_cmd);
17729 install_element(BGP_FLOWSPECV6_NODE,
17730 &no_neighbor_soft_reconfiguration_cmd);
17731 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
17732 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
17733
17734 /* "neighbor attribute-unchanged" commands. */
17735 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
17736 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
17737 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
17738 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
17739 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
17740 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
17741 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
17742 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
17743 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
17744 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
17745 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
17746 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
17747 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
17748 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
17749 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
17750 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
17751 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
17752 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
17753
17754 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
17755 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
17756
17757 /* "nexthop-local unchanged" commands */
17758 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
17759 install_element(BGP_IPV6_NODE,
17760 &no_neighbor_nexthop_local_unchanged_cmd);
17761
17762 /* "neighbor next-hop-self" commands. */
17763 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
17764 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
17765 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
17766 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
17767 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
17768 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
17769 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
17770 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
17771 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
17772 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
17773 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
17774 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
17775 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
17776 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
17777 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
17778 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
17779 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
17780 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
17781 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
17782 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
17783
17784 /* "neighbor next-hop-self force" commands. */
17785 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
17786 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
17787 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
17788 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
17789 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
17790 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
17791 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
17792 install_element(BGP_IPV4_NODE,
17793 &no_neighbor_nexthop_self_all_hidden_cmd);
17794 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
17795 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
17796 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
17797 install_element(BGP_IPV4M_NODE,
17798 &no_neighbor_nexthop_self_all_hidden_cmd);
17799 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
17800 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
17801 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
17802 install_element(BGP_IPV4L_NODE,
17803 &no_neighbor_nexthop_self_all_hidden_cmd);
17804 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
17805 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
17806 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
17807 install_element(BGP_IPV6_NODE,
17808 &no_neighbor_nexthop_self_all_hidden_cmd);
17809 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
17810 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
17811 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
17812 install_element(BGP_IPV6M_NODE,
17813 &no_neighbor_nexthop_self_all_hidden_cmd);
17814 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
17815 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
17816 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
17817 install_element(BGP_IPV6L_NODE,
17818 &no_neighbor_nexthop_self_all_hidden_cmd);
17819 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
17820 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
17821 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
17822 install_element(BGP_VPNV4_NODE,
17823 &no_neighbor_nexthop_self_all_hidden_cmd);
17824 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
17825 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
17826 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
17827 install_element(BGP_VPNV6_NODE,
17828 &no_neighbor_nexthop_self_all_hidden_cmd);
17829 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_force_cmd);
17830 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_force_cmd);
17831
17832 /* "neighbor as-override" commands. */
17833 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
17834 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
17835 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
17836 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
17837 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
17838 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
17839 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
17840 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
17841 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
17842 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
17843 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
17844 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
17845 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
17846 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
17847 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
17848 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
17849 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
17850 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
17851
17852 /* "neighbor remove-private-AS" commands. */
17853 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
17854 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
17855 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
17856 install_element(BGP_NODE,
17857 &no_neighbor_remove_private_as_all_hidden_cmd);
17858 install_element(BGP_NODE,
17859 &neighbor_remove_private_as_replace_as_hidden_cmd);
17860 install_element(BGP_NODE,
17861 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
17862 install_element(BGP_NODE,
17863 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
17864 install_element(
17865 BGP_NODE,
17866 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
17867 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
17868 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
17869 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
17870 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
17871 install_element(BGP_IPV4_NODE,
17872 &neighbor_remove_private_as_replace_as_cmd);
17873 install_element(BGP_IPV4_NODE,
17874 &no_neighbor_remove_private_as_replace_as_cmd);
17875 install_element(BGP_IPV4_NODE,
17876 &neighbor_remove_private_as_all_replace_as_cmd);
17877 install_element(BGP_IPV4_NODE,
17878 &no_neighbor_remove_private_as_all_replace_as_cmd);
17879 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
17880 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
17881 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
17882 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
17883 install_element(BGP_IPV4M_NODE,
17884 &neighbor_remove_private_as_replace_as_cmd);
17885 install_element(BGP_IPV4M_NODE,
17886 &no_neighbor_remove_private_as_replace_as_cmd);
17887 install_element(BGP_IPV4M_NODE,
17888 &neighbor_remove_private_as_all_replace_as_cmd);
17889 install_element(BGP_IPV4M_NODE,
17890 &no_neighbor_remove_private_as_all_replace_as_cmd);
17891 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
17892 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
17893 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
17894 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
17895 install_element(BGP_IPV4L_NODE,
17896 &neighbor_remove_private_as_replace_as_cmd);
17897 install_element(BGP_IPV4L_NODE,
17898 &no_neighbor_remove_private_as_replace_as_cmd);
17899 install_element(BGP_IPV4L_NODE,
17900 &neighbor_remove_private_as_all_replace_as_cmd);
17901 install_element(BGP_IPV4L_NODE,
17902 &no_neighbor_remove_private_as_all_replace_as_cmd);
17903 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
17904 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
17905 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
17906 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
17907 install_element(BGP_IPV6_NODE,
17908 &neighbor_remove_private_as_replace_as_cmd);
17909 install_element(BGP_IPV6_NODE,
17910 &no_neighbor_remove_private_as_replace_as_cmd);
17911 install_element(BGP_IPV6_NODE,
17912 &neighbor_remove_private_as_all_replace_as_cmd);
17913 install_element(BGP_IPV6_NODE,
17914 &no_neighbor_remove_private_as_all_replace_as_cmd);
17915 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
17916 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
17917 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
17918 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
17919 install_element(BGP_IPV6M_NODE,
17920 &neighbor_remove_private_as_replace_as_cmd);
17921 install_element(BGP_IPV6M_NODE,
17922 &no_neighbor_remove_private_as_replace_as_cmd);
17923 install_element(BGP_IPV6M_NODE,
17924 &neighbor_remove_private_as_all_replace_as_cmd);
17925 install_element(BGP_IPV6M_NODE,
17926 &no_neighbor_remove_private_as_all_replace_as_cmd);
17927 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
17928 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
17929 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
17930 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
17931 install_element(BGP_IPV6L_NODE,
17932 &neighbor_remove_private_as_replace_as_cmd);
17933 install_element(BGP_IPV6L_NODE,
17934 &no_neighbor_remove_private_as_replace_as_cmd);
17935 install_element(BGP_IPV6L_NODE,
17936 &neighbor_remove_private_as_all_replace_as_cmd);
17937 install_element(BGP_IPV6L_NODE,
17938 &no_neighbor_remove_private_as_all_replace_as_cmd);
17939 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
17940 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
17941 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
17942 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
17943 install_element(BGP_VPNV4_NODE,
17944 &neighbor_remove_private_as_replace_as_cmd);
17945 install_element(BGP_VPNV4_NODE,
17946 &no_neighbor_remove_private_as_replace_as_cmd);
17947 install_element(BGP_VPNV4_NODE,
17948 &neighbor_remove_private_as_all_replace_as_cmd);
17949 install_element(BGP_VPNV4_NODE,
17950 &no_neighbor_remove_private_as_all_replace_as_cmd);
17951 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
17952 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
17953 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
17954 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
17955 install_element(BGP_VPNV6_NODE,
17956 &neighbor_remove_private_as_replace_as_cmd);
17957 install_element(BGP_VPNV6_NODE,
17958 &no_neighbor_remove_private_as_replace_as_cmd);
17959 install_element(BGP_VPNV6_NODE,
17960 &neighbor_remove_private_as_all_replace_as_cmd);
17961 install_element(BGP_VPNV6_NODE,
17962 &no_neighbor_remove_private_as_all_replace_as_cmd);
17963
17964 /* "neighbor send-community" commands.*/
17965 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
17966 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
17967 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
17968 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
17969 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
17970 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
17971 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
17972 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
17973 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
17974 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
17975 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
17976 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
17977 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
17978 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
17979 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
17980 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
17981 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
17982 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
17983 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
17984 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
17985 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
17986 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
17987 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
17988 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
17989 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
17990 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
17991 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
17992 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
17993 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
17994 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
17995 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
17996 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
17997 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
17998 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
17999 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
18000 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
18001
18002 /* "neighbor route-reflector" commands.*/
18003 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
18004 install_element(BGP_NODE,
18005 &no_neighbor_route_reflector_client_hidden_cmd);
18006 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
18007 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
18008 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
18009 install_element(BGP_IPV4M_NODE,
18010 &no_neighbor_route_reflector_client_cmd);
18011 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
18012 install_element(BGP_IPV4L_NODE,
18013 &no_neighbor_route_reflector_client_cmd);
18014 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
18015 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
18016 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
18017 install_element(BGP_IPV6M_NODE,
18018 &no_neighbor_route_reflector_client_cmd);
18019 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
18020 install_element(BGP_IPV6L_NODE,
18021 &no_neighbor_route_reflector_client_cmd);
18022 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
18023 install_element(BGP_VPNV4_NODE,
18024 &no_neighbor_route_reflector_client_cmd);
18025 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
18026 install_element(BGP_VPNV6_NODE,
18027 &no_neighbor_route_reflector_client_cmd);
18028 install_element(BGP_FLOWSPECV4_NODE,
18029 &neighbor_route_reflector_client_cmd);
18030 install_element(BGP_FLOWSPECV4_NODE,
18031 &no_neighbor_route_reflector_client_cmd);
18032 install_element(BGP_FLOWSPECV6_NODE,
18033 &neighbor_route_reflector_client_cmd);
18034 install_element(BGP_FLOWSPECV6_NODE,
18035 &no_neighbor_route_reflector_client_cmd);
18036 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
18037 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
18038
18039 /* "neighbor route-server" commands.*/
18040 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
18041 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
18042 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
18043 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
18044 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
18045 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
18046 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
18047 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
18048 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
18049 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
18050 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
18051 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
18052 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
18053 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
18054 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
18055 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
18056 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
18057 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
18058 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
18059 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
18060 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
18061 install_element(BGP_FLOWSPECV4_NODE,
18062 &no_neighbor_route_server_client_cmd);
18063 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
18064 install_element(BGP_FLOWSPECV6_NODE,
18065 &no_neighbor_route_server_client_cmd);
18066
18067 /* "neighbor addpath-tx-all-paths" commands.*/
18068 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
18069 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
18070 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
18071 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18072 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
18073 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18074 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
18075 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18076 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
18077 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18078 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
18079 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18080 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
18081 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18082 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
18083 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18084 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
18085 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18086
18087 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
18088 install_element(BGP_NODE,
18089 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
18090 install_element(BGP_NODE,
18091 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
18092 install_element(BGP_IPV4_NODE,
18093 &neighbor_addpath_tx_bestpath_per_as_cmd);
18094 install_element(BGP_IPV4_NODE,
18095 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18096 install_element(BGP_IPV4M_NODE,
18097 &neighbor_addpath_tx_bestpath_per_as_cmd);
18098 install_element(BGP_IPV4M_NODE,
18099 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18100 install_element(BGP_IPV4L_NODE,
18101 &neighbor_addpath_tx_bestpath_per_as_cmd);
18102 install_element(BGP_IPV4L_NODE,
18103 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18104 install_element(BGP_IPV6_NODE,
18105 &neighbor_addpath_tx_bestpath_per_as_cmd);
18106 install_element(BGP_IPV6_NODE,
18107 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18108 install_element(BGP_IPV6M_NODE,
18109 &neighbor_addpath_tx_bestpath_per_as_cmd);
18110 install_element(BGP_IPV6M_NODE,
18111 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18112 install_element(BGP_IPV6L_NODE,
18113 &neighbor_addpath_tx_bestpath_per_as_cmd);
18114 install_element(BGP_IPV6L_NODE,
18115 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18116 install_element(BGP_VPNV4_NODE,
18117 &neighbor_addpath_tx_bestpath_per_as_cmd);
18118 install_element(BGP_VPNV4_NODE,
18119 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18120 install_element(BGP_VPNV6_NODE,
18121 &neighbor_addpath_tx_bestpath_per_as_cmd);
18122 install_element(BGP_VPNV6_NODE,
18123 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18124
18125 /* "neighbor sender-as-path-loop-detection" commands. */
18126 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
18127 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
18128
18129 /* "neighbor passive" commands. */
18130 install_element(BGP_NODE, &neighbor_passive_cmd);
18131 install_element(BGP_NODE, &no_neighbor_passive_cmd);
18132
18133
18134 /* "neighbor shutdown" commands. */
18135 install_element(BGP_NODE, &neighbor_shutdown_cmd);
18136 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
18137 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
18138 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
18139 install_element(BGP_NODE, &neighbor_shutdown_rtt_cmd);
18140 install_element(BGP_NODE, &no_neighbor_shutdown_rtt_cmd);
18141
18142 /* "neighbor capability extended-nexthop" commands.*/
18143 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
18144 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
18145
18146 /* "neighbor capability orf prefix-list" commands.*/
18147 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
18148 install_element(BGP_NODE,
18149 &no_neighbor_capability_orf_prefix_hidden_cmd);
18150 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
18151 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
18152 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
18153 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
18154 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
18155 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
18156 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
18157 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
18158 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
18159 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
18160 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
18161 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
18162
18163 /* "neighbor capability dynamic" commands.*/
18164 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
18165 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
18166
18167 /* "neighbor dont-capability-negotiate" commands. */
18168 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
18169 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
18170
18171 /* "neighbor ebgp-multihop" commands. */
18172 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
18173 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
18174 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
18175
18176 /* "neighbor disable-connected-check" commands. */
18177 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
18178 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
18179
18180 /* "neighbor enforce-first-as" commands. */
18181 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
18182 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
18183
18184 /* "neighbor description" commands. */
18185 install_element(BGP_NODE, &neighbor_description_cmd);
18186 install_element(BGP_NODE, &no_neighbor_description_cmd);
18187 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
18188
18189 /* "neighbor update-source" commands. "*/
18190 install_element(BGP_NODE, &neighbor_update_source_cmd);
18191 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
18192
18193 /* "neighbor default-originate" commands. */
18194 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
18195 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
18196 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
18197 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
18198 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
18199 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
18200 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
18201 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
18202 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
18203 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
18204 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
18205 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
18206 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
18207 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
18208 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
18209 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
18210 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
18211 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
18212 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
18213 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
18214 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
18215
18216 /* "neighbor port" commands. */
18217 install_element(BGP_NODE, &neighbor_port_cmd);
18218 install_element(BGP_NODE, &no_neighbor_port_cmd);
18219
18220 /* "neighbor weight" commands. */
18221 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
18222 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
18223
18224 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
18225 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
18226 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
18227 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
18228 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
18229 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
18230 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
18231 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
18232 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
18233 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
18234 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
18235 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
18236 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
18237 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
18238 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
18239 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
18240
18241 /* "neighbor override-capability" commands. */
18242 install_element(BGP_NODE, &neighbor_override_capability_cmd);
18243 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
18244
18245 /* "neighbor strict-capability-match" commands. */
18246 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
18247 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
18248
18249 /* "neighbor timers" commands. */
18250 install_element(BGP_NODE, &neighbor_timers_cmd);
18251 install_element(BGP_NODE, &no_neighbor_timers_cmd);
18252
18253 /* "neighbor timers connect" commands. */
18254 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
18255 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
18256
18257 /* "neighbor advertisement-interval" commands. */
18258 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
18259 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
18260
18261 /* "neighbor interface" commands. */
18262 install_element(BGP_NODE, &neighbor_interface_cmd);
18263 install_element(BGP_NODE, &no_neighbor_interface_cmd);
18264
18265 /* "neighbor distribute" commands. */
18266 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
18267 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
18268 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
18269 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
18270 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
18271 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
18272 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
18273 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
18274 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
18275 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
18276 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
18277 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
18278 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
18279 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
18280 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
18281 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
18282 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
18283 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
18284
18285 /* "neighbor prefix-list" commands. */
18286 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
18287 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
18288 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
18289 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
18290 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
18291 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
18292 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
18293 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
18294 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
18295 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
18296 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
18297 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
18298 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
18299 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
18300 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
18301 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
18302 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
18303 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
18304 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
18305 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
18306 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
18307 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
18308
18309 /* "neighbor filter-list" commands. */
18310 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
18311 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
18312 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
18313 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
18314 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
18315 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
18316 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
18317 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
18318 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
18319 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
18320 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
18321 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
18322 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
18323 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
18324 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
18325 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
18326 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
18327 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
18328 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
18329 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
18330 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
18331 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
18332
18333 /* "neighbor route-map" commands. */
18334 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
18335 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
18336 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
18337 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
18338 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
18339 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
18340 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
18341 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
18342 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
18343 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
18344 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
18345 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
18346 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
18347 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
18348 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
18349 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
18350 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
18351 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
18352 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
18353 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
18354 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
18355 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
18356 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
18357 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
18358
18359 /* "neighbor unsuppress-map" commands. */
18360 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
18361 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
18362 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
18363 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
18364 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
18365 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
18366 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
18367 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
18368 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
18369 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
18370 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
18371 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
18372 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
18373 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
18374 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
18375 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
18376 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
18377 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
18378
18379 /* "neighbor advertise-map" commands. */
18380 install_element(BGP_NODE, &neighbor_advertise_map_hidden_cmd);
18381 install_element(BGP_IPV4_NODE, &neighbor_advertise_map_cmd);
18382 install_element(BGP_IPV4M_NODE, &neighbor_advertise_map_cmd);
18383 install_element(BGP_IPV4L_NODE, &neighbor_advertise_map_cmd);
18384 install_element(BGP_IPV6_NODE, &neighbor_advertise_map_cmd);
18385 install_element(BGP_IPV6M_NODE, &neighbor_advertise_map_cmd);
18386 install_element(BGP_IPV6L_NODE, &neighbor_advertise_map_cmd);
18387 install_element(BGP_VPNV4_NODE, &neighbor_advertise_map_cmd);
18388 install_element(BGP_VPNV6_NODE, &neighbor_advertise_map_cmd);
18389
18390 /* neighbor maximum-prefix-out commands. */
18391 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
18392 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
18393 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
18394 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
18395 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
18396 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
18397 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
18398 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
18399 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
18400 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
18401 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
18402 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
18403 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
18404 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
18405 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
18406 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
18407 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
18408 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
18409
18410 /* "neighbor maximum-prefix" commands. */
18411 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
18412 install_element(BGP_NODE,
18413 &neighbor_maximum_prefix_threshold_hidden_cmd);
18414 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
18415 install_element(BGP_NODE,
18416 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
18417 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
18418 install_element(BGP_NODE,
18419 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
18420 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
18421 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
18422 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
18423 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
18424 install_element(BGP_IPV4_NODE,
18425 &neighbor_maximum_prefix_threshold_warning_cmd);
18426 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
18427 install_element(BGP_IPV4_NODE,
18428 &neighbor_maximum_prefix_threshold_restart_cmd);
18429 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
18430 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
18431 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
18432 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
18433 install_element(BGP_IPV4M_NODE,
18434 &neighbor_maximum_prefix_threshold_warning_cmd);
18435 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
18436 install_element(BGP_IPV4M_NODE,
18437 &neighbor_maximum_prefix_threshold_restart_cmd);
18438 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
18439 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
18440 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
18441 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
18442 install_element(BGP_IPV4L_NODE,
18443 &neighbor_maximum_prefix_threshold_warning_cmd);
18444 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
18445 install_element(BGP_IPV4L_NODE,
18446 &neighbor_maximum_prefix_threshold_restart_cmd);
18447 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
18448 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
18449 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
18450 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
18451 install_element(BGP_IPV6_NODE,
18452 &neighbor_maximum_prefix_threshold_warning_cmd);
18453 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
18454 install_element(BGP_IPV6_NODE,
18455 &neighbor_maximum_prefix_threshold_restart_cmd);
18456 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
18457 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
18458 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
18459 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
18460 install_element(BGP_IPV6M_NODE,
18461 &neighbor_maximum_prefix_threshold_warning_cmd);
18462 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
18463 install_element(BGP_IPV6M_NODE,
18464 &neighbor_maximum_prefix_threshold_restart_cmd);
18465 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
18466 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
18467 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
18468 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
18469 install_element(BGP_IPV6L_NODE,
18470 &neighbor_maximum_prefix_threshold_warning_cmd);
18471 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
18472 install_element(BGP_IPV6L_NODE,
18473 &neighbor_maximum_prefix_threshold_restart_cmd);
18474 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
18475 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
18476 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
18477 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
18478 install_element(BGP_VPNV4_NODE,
18479 &neighbor_maximum_prefix_threshold_warning_cmd);
18480 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
18481 install_element(BGP_VPNV4_NODE,
18482 &neighbor_maximum_prefix_threshold_restart_cmd);
18483 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
18484 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
18485 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
18486 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
18487 install_element(BGP_VPNV6_NODE,
18488 &neighbor_maximum_prefix_threshold_warning_cmd);
18489 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
18490 install_element(BGP_VPNV6_NODE,
18491 &neighbor_maximum_prefix_threshold_restart_cmd);
18492 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
18493
18494 /* "neighbor allowas-in" */
18495 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
18496 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
18497 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
18498 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
18499 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
18500 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
18501 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
18502 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
18503 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
18504 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
18505 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
18506 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
18507 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
18508 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
18509 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
18510 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
18511 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
18512 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
18513 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
18514 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
18515
18516 /* address-family commands. */
18517 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
18518 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
18519 #ifdef KEEP_OLD_VPN_COMMANDS
18520 install_element(BGP_NODE, &address_family_vpnv4_cmd);
18521 install_element(BGP_NODE, &address_family_vpnv6_cmd);
18522 #endif /* KEEP_OLD_VPN_COMMANDS */
18523
18524 install_element(BGP_NODE, &address_family_evpn_cmd);
18525
18526 /* "exit-address-family" command. */
18527 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
18528 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
18529 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
18530 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
18531 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
18532 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
18533 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
18534 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
18535 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
18536 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
18537 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
18538
18539 /* "clear ip bgp commands" */
18540 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
18541
18542 /* clear ip bgp prefix */
18543 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
18544 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
18545 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
18546
18547 /* "show [ip] bgp summary" commands. */
18548 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
18549 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
18550 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
18551 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
18552 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
18553 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
18554 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
18555
18556 /* "show [ip] bgp neighbors" commands. */
18557 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
18558
18559 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
18560
18561 /* "show [ip] bgp peer-group" commands. */
18562 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
18563
18564 /* "show [ip] bgp paths" commands. */
18565 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
18566
18567 /* "show [ip] bgp community" commands. */
18568 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
18569
18570 /* "show ip bgp large-community" commands. */
18571 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
18572 /* "show [ip] bgp attribute-info" commands. */
18573 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
18574 /* "show [ip] bgp route-leak" command */
18575 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
18576
18577 /* "redistribute" commands. */
18578 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
18579 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
18580 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
18581 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
18582 install_element(BGP_NODE,
18583 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
18584 install_element(BGP_NODE,
18585 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
18586 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
18587 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
18588 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
18589 install_element(BGP_NODE,
18590 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
18591 install_element(BGP_NODE,
18592 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
18593 install_element(BGP_NODE,
18594 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
18595 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
18596 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
18597 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
18598 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
18599 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
18600 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
18601 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
18602 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
18603 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
18604 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
18605 install_element(BGP_IPV4_NODE,
18606 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
18607 install_element(BGP_IPV4_NODE,
18608 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
18609 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
18610 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
18611 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
18612 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
18613 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
18614 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
18615
18616 /* import|export vpn [route-map WORD] */
18617 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
18618 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
18619
18620 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
18621 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
18622
18623 /* ttl_security commands */
18624 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
18625 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
18626
18627 /* "show [ip] bgp memory" commands. */
18628 install_element(VIEW_NODE, &show_bgp_memory_cmd);
18629
18630 /* "show bgp martian next-hop" */
18631 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
18632
18633 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
18634
18635 /* "show [ip] bgp views" commands. */
18636 install_element(VIEW_NODE, &show_bgp_views_cmd);
18637
18638 /* "show [ip] bgp vrfs" commands. */
18639 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
18640
18641 /* Community-list. */
18642 community_list_vty();
18643
18644 /* vpn-policy commands */
18645 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
18646 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
18647 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
18648 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
18649 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
18650 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
18651 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
18652 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
18653 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
18654 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
18655 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
18656 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
18657
18658 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
18659 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
18660
18661 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
18662 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
18663 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
18664 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
18665 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
18666 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
18667 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
18668 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
18669 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
18670 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
18671 }
18672
18673 #include "memory.h"
18674 #include "bgp_regex.h"
18675 #include "bgp_clist.h"
18676 #include "bgp_ecommunity.h"
18677
18678 /* VTY functions. */
18679
18680 /* Direction value to string conversion. */
18681 static const char *community_direct_str(int direct)
18682 {
18683 switch (direct) {
18684 case COMMUNITY_DENY:
18685 return "deny";
18686 case COMMUNITY_PERMIT:
18687 return "permit";
18688 default:
18689 return "unknown";
18690 }
18691 }
18692
18693 /* Display error string. */
18694 static void community_list_perror(struct vty *vty, int ret)
18695 {
18696 switch (ret) {
18697 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
18698 vty_out(vty, "%% Can't find community-list\n");
18699 break;
18700 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
18701 vty_out(vty, "%% Malformed community-list value\n");
18702 break;
18703 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
18704 vty_out(vty,
18705 "%% Community name conflict, previously defined as standard community\n");
18706 break;
18707 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
18708 vty_out(vty,
18709 "%% Community name conflict, previously defined as expanded community\n");
18710 break;
18711 }
18712 }
18713
18714 /* "community-list" keyword help string. */
18715 #define COMMUNITY_LIST_STR "Add a community list entry\n"
18716
18717 /*community-list standard */
18718 DEFUN (community_list_standard,
18719 bgp_community_list_standard_cmd,
18720 "bgp community-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
18721 BGP_STR
18722 COMMUNITY_LIST_STR
18723 "Community list number (standard)\n"
18724 "Add an standard community-list entry\n"
18725 "Community list name\n"
18726 "Sequence number of an entry\n"
18727 "Sequence number\n"
18728 "Specify community to reject\n"
18729 "Specify community to accept\n"
18730 COMMUNITY_VAL_STR)
18731 {
18732 char *cl_name_or_number = NULL;
18733 char *seq = NULL;
18734 int direct = 0;
18735 int style = COMMUNITY_LIST_STANDARD;
18736 int idx = 0;
18737
18738 argv_find(argv, argc, "(1-4294967295)", &idx);
18739 if (idx)
18740 seq = argv[idx]->arg;
18741
18742 idx = 0;
18743 argv_find(argv, argc, "(1-99)", &idx);
18744 argv_find(argv, argc, "WORD", &idx);
18745 cl_name_or_number = argv[idx]->arg;
18746 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
18747 : COMMUNITY_DENY;
18748 argv_find(argv, argc, "AA:NN", &idx);
18749 char *str = argv_concat(argv, argc, idx);
18750
18751 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
18752 direct, style);
18753
18754 XFREE(MTYPE_TMP, str);
18755
18756 if (ret < 0) {
18757 /* Display error string. */
18758 community_list_perror(vty, ret);
18759 return CMD_WARNING_CONFIG_FAILED;
18760 }
18761
18762 return CMD_SUCCESS;
18763 }
18764
18765 DEFUN (no_community_list_standard_all,
18766 no_bgp_community_list_standard_all_cmd,
18767 "no bgp community-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
18768 NO_STR
18769 BGP_STR
18770 COMMUNITY_LIST_STR
18771 "Community list number (standard)\n"
18772 "Add an standard community-list entry\n"
18773 "Community list name\n"
18774 "Sequence number of an entry\n"
18775 "Sequence number\n"
18776 "Specify community to reject\n"
18777 "Specify community to accept\n"
18778 COMMUNITY_VAL_STR)
18779 {
18780 char *cl_name_or_number = NULL;
18781 char *str = NULL;
18782 int direct = 0;
18783 int style = COMMUNITY_LIST_STANDARD;
18784 char *seq = NULL;
18785 int idx = 0;
18786
18787 argv_find(argv, argc, "(1-4294967295)", &idx);
18788 if (idx)
18789 seq = argv[idx]->arg;
18790
18791 idx = 0;
18792 argv_find(argv, argc, "permit", &idx);
18793 argv_find(argv, argc, "deny", &idx);
18794
18795 if (idx) {
18796 direct = argv_find(argv, argc, "permit", &idx)
18797 ? COMMUNITY_PERMIT
18798 : COMMUNITY_DENY;
18799
18800 idx = 0;
18801 argv_find(argv, argc, "AA:NN", &idx);
18802 str = argv_concat(argv, argc, idx);
18803 }
18804
18805 idx = 0;
18806 argv_find(argv, argc, "(1-99)", &idx);
18807 argv_find(argv, argc, "WORD", &idx);
18808 cl_name_or_number = argv[idx]->arg;
18809
18810 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
18811 direct, style);
18812
18813 XFREE(MTYPE_TMP, str);
18814
18815 if (ret < 0) {
18816 community_list_perror(vty, ret);
18817 return CMD_WARNING_CONFIG_FAILED;
18818 }
18819
18820 return CMD_SUCCESS;
18821 }
18822
18823 ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
18824 "no bgp community-list <(1-99)|standard WORD>",
18825 NO_STR BGP_STR COMMUNITY_LIST_STR
18826 "Community list number (standard)\n"
18827 "Add an standard community-list entry\n"
18828 "Community list name\n")
18829
18830 /*community-list expanded */
18831 DEFUN (community_list_expanded_all,
18832 bgp_community_list_expanded_all_cmd,
18833 "bgp community-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
18834 BGP_STR
18835 COMMUNITY_LIST_STR
18836 "Community list number (expanded)\n"
18837 "Add an expanded community-list entry\n"
18838 "Community list name\n"
18839 "Sequence number of an entry\n"
18840 "Sequence number\n"
18841 "Specify community to reject\n"
18842 "Specify community to accept\n"
18843 COMMUNITY_VAL_STR)
18844 {
18845 char *cl_name_or_number = NULL;
18846 char *seq = NULL;
18847 int direct = 0;
18848 int style = COMMUNITY_LIST_EXPANDED;
18849 int idx = 0;
18850
18851 argv_find(argv, argc, "(1-4294967295)", &idx);
18852 if (idx)
18853 seq = argv[idx]->arg;
18854
18855 idx = 0;
18856
18857 argv_find(argv, argc, "(100-500)", &idx);
18858 argv_find(argv, argc, "WORD", &idx);
18859 cl_name_or_number = argv[idx]->arg;
18860 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
18861 : COMMUNITY_DENY;
18862 argv_find(argv, argc, "AA:NN", &idx);
18863 char *str = argv_concat(argv, argc, idx);
18864
18865 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
18866 direct, style);
18867
18868 XFREE(MTYPE_TMP, str);
18869
18870 if (ret < 0) {
18871 /* Display error string. */
18872 community_list_perror(vty, ret);
18873 return CMD_WARNING_CONFIG_FAILED;
18874 }
18875
18876 return CMD_SUCCESS;
18877 }
18878
18879 DEFUN (no_community_list_expanded_all,
18880 no_bgp_community_list_expanded_all_cmd,
18881 "no bgp community-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
18882 NO_STR
18883 BGP_STR
18884 COMMUNITY_LIST_STR
18885 "Community list number (expanded)\n"
18886 "Add an expanded community-list entry\n"
18887 "Community list name\n"
18888 "Sequence number of an entry\n"
18889 "Sequence number\n"
18890 "Specify community to reject\n"
18891 "Specify community to accept\n"
18892 COMMUNITY_VAL_STR)
18893 {
18894 char *cl_name_or_number = NULL;
18895 char *seq = NULL;
18896 char *str = NULL;
18897 int direct = 0;
18898 int style = COMMUNITY_LIST_EXPANDED;
18899 int idx = 0;
18900
18901 argv_find(argv, argc, "(1-4294967295)", &idx);
18902 if (idx)
18903 seq = argv[idx]->arg;
18904
18905 idx = 0;
18906 argv_find(argv, argc, "permit", &idx);
18907 argv_find(argv, argc, "deny", &idx);
18908
18909 if (idx) {
18910 direct = argv_find(argv, argc, "permit", &idx)
18911 ? COMMUNITY_PERMIT
18912 : COMMUNITY_DENY;
18913
18914 idx = 0;
18915 argv_find(argv, argc, "AA:NN", &idx);
18916 str = argv_concat(argv, argc, idx);
18917 }
18918
18919 idx = 0;
18920 argv_find(argv, argc, "(100-500)", &idx);
18921 argv_find(argv, argc, "WORD", &idx);
18922 cl_name_or_number = argv[idx]->arg;
18923
18924 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
18925 direct, style);
18926
18927 XFREE(MTYPE_TMP, str);
18928
18929 if (ret < 0) {
18930 community_list_perror(vty, ret);
18931 return CMD_WARNING_CONFIG_FAILED;
18932 }
18933
18934 return CMD_SUCCESS;
18935 }
18936
18937 ALIAS(no_community_list_expanded_all,
18938 no_bgp_community_list_expanded_all_list_cmd,
18939 "no bgp community-list <(100-500)|expanded WORD>",
18940 NO_STR BGP_STR COMMUNITY_LIST_STR
18941 "Community list number (expanded)\n"
18942 "Add an expanded community-list entry\n"
18943 "Community list name\n")
18944
18945 /* Return configuration string of community-list entry. */
18946 static const char *community_list_config_str(struct community_entry *entry)
18947 {
18948 const char *str;
18949
18950 if (entry->any)
18951 str = "";
18952 else {
18953 if (entry->style == COMMUNITY_LIST_STANDARD)
18954 str = community_str(entry->u.com, false);
18955 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
18956 str = lcommunity_str(entry->u.lcom, false);
18957 else
18958 str = entry->config;
18959 }
18960 return str;
18961 }
18962
18963 static void community_list_show(struct vty *vty, struct community_list *list)
18964 {
18965 struct community_entry *entry;
18966
18967 for (entry = list->head; entry; entry = entry->next) {
18968 if (entry == list->head) {
18969 if (all_digit(list->name))
18970 vty_out(vty, "Community %s list %s\n",
18971 entry->style == COMMUNITY_LIST_STANDARD
18972 ? "standard"
18973 : "(expanded) access",
18974 list->name);
18975 else
18976 vty_out(vty, "Named Community %s list %s\n",
18977 entry->style == COMMUNITY_LIST_STANDARD
18978 ? "standard"
18979 : "expanded",
18980 list->name);
18981 }
18982 if (entry->any)
18983 vty_out(vty, " %s\n",
18984 community_direct_str(entry->direct));
18985 else
18986 vty_out(vty, " %s %s\n",
18987 community_direct_str(entry->direct),
18988 community_list_config_str(entry));
18989 }
18990 }
18991
18992 DEFUN (show_community_list,
18993 show_bgp_community_list_cmd,
18994 "show bgp community-list",
18995 SHOW_STR
18996 BGP_STR
18997 "List community-list\n")
18998 {
18999 struct community_list *list;
19000 struct community_list_master *cm;
19001
19002 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
19003 if (!cm)
19004 return CMD_SUCCESS;
19005
19006 for (list = cm->num.head; list; list = list->next)
19007 community_list_show(vty, list);
19008
19009 for (list = cm->str.head; list; list = list->next)
19010 community_list_show(vty, list);
19011
19012 return CMD_SUCCESS;
19013 }
19014
19015 DEFUN (show_community_list_arg,
19016 show_bgp_community_list_arg_cmd,
19017 "show bgp community-list <(1-500)|WORD> detail",
19018 SHOW_STR
19019 BGP_STR
19020 "List community-list\n"
19021 "Community-list number\n"
19022 "Community-list name\n"
19023 "Detailed information on community-list\n")
19024 {
19025 int idx_comm_list = 3;
19026 struct community_list *list;
19027
19028 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
19029 COMMUNITY_LIST_MASTER);
19030 if (!list) {
19031 vty_out(vty, "%% Can't find community-list\n");
19032 return CMD_WARNING;
19033 }
19034
19035 community_list_show(vty, list);
19036
19037 return CMD_SUCCESS;
19038 }
19039
19040 /*
19041 * Large Community code.
19042 */
19043 static int lcommunity_list_set_vty(struct vty *vty, int argc,
19044 struct cmd_token **argv, int style,
19045 int reject_all_digit_name)
19046 {
19047 int ret;
19048 int direct;
19049 char *str;
19050 int idx = 0;
19051 char *cl_name;
19052 char *seq = NULL;
19053
19054 if (argv_find(argv, argc, "(1-4294967295)", &idx))
19055 seq = argv[idx]->arg;
19056
19057 idx = 0;
19058 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19059 : COMMUNITY_DENY;
19060
19061 /* All digit name check. */
19062 idx = 0;
19063 argv_find(argv, argc, "WORD", &idx);
19064 argv_find(argv, argc, "(1-99)", &idx);
19065 argv_find(argv, argc, "(100-500)", &idx);
19066 cl_name = argv[idx]->arg;
19067 if (reject_all_digit_name && all_digit(cl_name)) {
19068 vty_out(vty, "%% Community name cannot have all digits\n");
19069 return CMD_WARNING_CONFIG_FAILED;
19070 }
19071
19072 idx = 0;
19073 argv_find(argv, argc, "AA:BB:CC", &idx);
19074 argv_find(argv, argc, "LINE", &idx);
19075 /* Concat community string argument. */
19076 if (idx)
19077 str = argv_concat(argv, argc, idx);
19078 else
19079 str = NULL;
19080
19081 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
19082
19083 /* Free temporary community list string allocated by
19084 argv_concat(). */
19085 XFREE(MTYPE_TMP, str);
19086
19087 if (ret < 0) {
19088 community_list_perror(vty, ret);
19089 return CMD_WARNING_CONFIG_FAILED;
19090 }
19091 return CMD_SUCCESS;
19092 }
19093
19094 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
19095 struct cmd_token **argv, int style)
19096 {
19097 int ret;
19098 int direct = 0;
19099 char *str = NULL;
19100 int idx = 0;
19101 char *seq = NULL;
19102
19103 if (argv_find(argv, argc, "(1-4294967295)", &idx))
19104 seq = argv[idx]->arg;
19105
19106 idx = 0;
19107 argv_find(argv, argc, "permit", &idx);
19108 argv_find(argv, argc, "deny", &idx);
19109
19110 if (idx) {
19111 /* Check the list direct. */
19112 if (strncmp(argv[idx]->arg, "p", 1) == 0)
19113 direct = COMMUNITY_PERMIT;
19114 else
19115 direct = COMMUNITY_DENY;
19116
19117 idx = 0;
19118 argv_find(argv, argc, "LINE", &idx);
19119 argv_find(argv, argc, "AA:AA:NN", &idx);
19120 /* Concat community string argument. */
19121 str = argv_concat(argv, argc, idx);
19122 }
19123
19124 idx = 0;
19125 argv_find(argv, argc, "(1-99)", &idx);
19126 argv_find(argv, argc, "(100-500)", &idx);
19127 argv_find(argv, argc, "WORD", &idx);
19128
19129 /* Unset community list. */
19130 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
19131 style);
19132
19133 /* Free temporary community list string allocated by
19134 argv_concat(). */
19135 XFREE(MTYPE_TMP, str);
19136
19137 if (ret < 0) {
19138 community_list_perror(vty, ret);
19139 return CMD_WARNING_CONFIG_FAILED;
19140 }
19141
19142 return CMD_SUCCESS;
19143 }
19144
19145 /* "large-community-list" keyword help string. */
19146 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
19147 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
19148
19149 DEFUN (lcommunity_list_standard,
19150 bgp_lcommunity_list_standard_cmd,
19151 "bgp large-community-list (1-99) [seq (1-4294967295)] <deny|permit> AA:BB:CC...",
19152 BGP_STR
19153 LCOMMUNITY_LIST_STR
19154 "Large Community list number (standard)\n"
19155 "Sequence number of an entry\n"
19156 "Sequence number\n"
19157 "Specify large community to reject\n"
19158 "Specify large community to accept\n"
19159 LCOMMUNITY_VAL_STR)
19160 {
19161 return lcommunity_list_set_vty(vty, argc, argv,
19162 LARGE_COMMUNITY_LIST_STANDARD, 0);
19163 }
19164
19165 DEFUN (lcommunity_list_expanded,
19166 bgp_lcommunity_list_expanded_cmd,
19167 "bgp large-community-list (100-500) [seq (1-4294967295)] <deny|permit> LINE...",
19168 BGP_STR
19169 LCOMMUNITY_LIST_STR
19170 "Large Community list number (expanded)\n"
19171 "Sequence number of an entry\n"
19172 "Sequence number\n"
19173 "Specify large community to reject\n"
19174 "Specify large community to accept\n"
19175 "An ordered list as a regular-expression\n")
19176 {
19177 return lcommunity_list_set_vty(vty, argc, argv,
19178 LARGE_COMMUNITY_LIST_EXPANDED, 0);
19179 }
19180
19181 DEFUN (lcommunity_list_name_standard,
19182 bgp_lcommunity_list_name_standard_cmd,
19183 "bgp large-community-list standard WORD [seq (1-4294967295)] <deny|permit> AA:BB:CC...",
19184 BGP_STR
19185 LCOMMUNITY_LIST_STR
19186 "Specify standard large-community-list\n"
19187 "Large Community list name\n"
19188 "Sequence number of an entry\n"
19189 "Sequence number\n"
19190 "Specify large community to reject\n"
19191 "Specify large community to accept\n"
19192 LCOMMUNITY_VAL_STR)
19193 {
19194 return lcommunity_list_set_vty(vty, argc, argv,
19195 LARGE_COMMUNITY_LIST_STANDARD, 1);
19196 }
19197
19198 DEFUN (lcommunity_list_name_expanded,
19199 bgp_lcommunity_list_name_expanded_cmd,
19200 "bgp large-community-list expanded WORD [seq (1-4294967295)] <deny|permit> LINE...",
19201 BGP_STR
19202 LCOMMUNITY_LIST_STR
19203 "Specify expanded large-community-list\n"
19204 "Large Community list name\n"
19205 "Sequence number of an entry\n"
19206 "Sequence number\n"
19207 "Specify large community to reject\n"
19208 "Specify large community to accept\n"
19209 "An ordered list as a regular-expression\n")
19210 {
19211 return lcommunity_list_set_vty(vty, argc, argv,
19212 LARGE_COMMUNITY_LIST_EXPANDED, 1);
19213 }
19214
19215 DEFUN (no_lcommunity_list_all,
19216 no_bgp_lcommunity_list_all_cmd,
19217 "no bgp large-community-list <(1-99)|(100-500)|WORD>",
19218 NO_STR
19219 BGP_STR
19220 LCOMMUNITY_LIST_STR
19221 "Large Community list number (standard)\n"
19222 "Large Community list number (expanded)\n"
19223 "Large Community list name\n")
19224 {
19225 return lcommunity_list_unset_vty(vty, argc, argv,
19226 LARGE_COMMUNITY_LIST_STANDARD);
19227 }
19228
19229 DEFUN (no_lcommunity_list_name_standard_all,
19230 no_bgp_lcommunity_list_name_standard_all_cmd,
19231 "no bgp large-community-list standard WORD",
19232 NO_STR
19233 BGP_STR
19234 LCOMMUNITY_LIST_STR
19235 "Specify standard large-community-list\n"
19236 "Large Community list name\n")
19237 {
19238 return lcommunity_list_unset_vty(vty, argc, argv,
19239 LARGE_COMMUNITY_LIST_STANDARD);
19240 }
19241
19242 DEFUN (no_lcommunity_list_name_expanded_all,
19243 no_bgp_lcommunity_list_name_expanded_all_cmd,
19244 "no bgp large-community-list expanded WORD",
19245 NO_STR
19246 BGP_STR
19247 LCOMMUNITY_LIST_STR
19248 "Specify expanded large-community-list\n"
19249 "Large Community list name\n")
19250 {
19251 return lcommunity_list_unset_vty(vty, argc, argv,
19252 LARGE_COMMUNITY_LIST_EXPANDED);
19253 }
19254
19255 DEFUN (no_lcommunity_list_standard,
19256 no_bgp_lcommunity_list_standard_cmd,
19257 "no bgp large-community-list (1-99) [seq (1-4294967295)] <deny|permit> AA:AA:NN...",
19258 NO_STR
19259 BGP_STR
19260 LCOMMUNITY_LIST_STR
19261 "Large Community list number (standard)\n"
19262 "Sequence number of an entry\n"
19263 "Sequence number\n"
19264 "Specify large community to reject\n"
19265 "Specify large community to accept\n"
19266 LCOMMUNITY_VAL_STR)
19267 {
19268 return lcommunity_list_unset_vty(vty, argc, argv,
19269 LARGE_COMMUNITY_LIST_STANDARD);
19270 }
19271
19272 DEFUN (no_lcommunity_list_expanded,
19273 no_bgp_lcommunity_list_expanded_cmd,
19274 "no bgp large-community-list (100-500) [seq (1-4294967295)] <deny|permit> LINE...",
19275 NO_STR
19276 BGP_STR
19277 LCOMMUNITY_LIST_STR
19278 "Large Community list number (expanded)\n"
19279 "Sequence number of an entry\n"
19280 "Sequence number\n"
19281 "Specify large community to reject\n"
19282 "Specify large community to accept\n"
19283 "An ordered list as a regular-expression\n")
19284 {
19285 return lcommunity_list_unset_vty(vty, argc, argv,
19286 LARGE_COMMUNITY_LIST_EXPANDED);
19287 }
19288
19289 DEFUN (no_lcommunity_list_name_standard,
19290 no_bgp_lcommunity_list_name_standard_cmd,
19291 "no bgp large-community-list standard WORD [seq (1-4294967295)] <deny|permit> AA:AA:NN...",
19292 NO_STR
19293 BGP_STR
19294 LCOMMUNITY_LIST_STR
19295 "Specify standard large-community-list\n"
19296 "Large Community list name\n"
19297 "Sequence number of an entry\n"
19298 "Sequence number\n"
19299 "Specify large community to reject\n"
19300 "Specify large community to accept\n"
19301 LCOMMUNITY_VAL_STR)
19302 {
19303 return lcommunity_list_unset_vty(vty, argc, argv,
19304 LARGE_COMMUNITY_LIST_STANDARD);
19305 }
19306
19307 DEFUN (no_lcommunity_list_name_expanded,
19308 no_bgp_lcommunity_list_name_expanded_cmd,
19309 "no bgp large-community-list expanded WORD [seq (1-4294967295)] <deny|permit> LINE...",
19310 NO_STR
19311 BGP_STR
19312 LCOMMUNITY_LIST_STR
19313 "Specify expanded large-community-list\n"
19314 "Large community list name\n"
19315 "Sequence number of an entry\n"
19316 "Sequence number\n"
19317 "Specify large community to reject\n"
19318 "Specify large community to accept\n"
19319 "An ordered list as a regular-expression\n")
19320 {
19321 return lcommunity_list_unset_vty(vty, argc, argv,
19322 LARGE_COMMUNITY_LIST_EXPANDED);
19323 }
19324
19325 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
19326 {
19327 struct community_entry *entry;
19328
19329 for (entry = list->head; entry; entry = entry->next) {
19330 if (entry == list->head) {
19331 if (all_digit(list->name))
19332 vty_out(vty, "Large community %s list %s\n",
19333 entry->style ==
19334 LARGE_COMMUNITY_LIST_STANDARD
19335 ? "standard"
19336 : "(expanded) access",
19337 list->name);
19338 else
19339 vty_out(vty,
19340 "Named large community %s list %s\n",
19341 entry->style ==
19342 LARGE_COMMUNITY_LIST_STANDARD
19343 ? "standard"
19344 : "expanded",
19345 list->name);
19346 }
19347 if (entry->any)
19348 vty_out(vty, " %s\n",
19349 community_direct_str(entry->direct));
19350 else
19351 vty_out(vty, " %s %s\n",
19352 community_direct_str(entry->direct),
19353 community_list_config_str(entry));
19354 }
19355 }
19356
19357 DEFUN (show_lcommunity_list,
19358 show_bgp_lcommunity_list_cmd,
19359 "show bgp large-community-list",
19360 SHOW_STR
19361 BGP_STR
19362 "List large-community list\n")
19363 {
19364 struct community_list *list;
19365 struct community_list_master *cm;
19366
19367 cm = community_list_master_lookup(bgp_clist,
19368 LARGE_COMMUNITY_LIST_MASTER);
19369 if (!cm)
19370 return CMD_SUCCESS;
19371
19372 for (list = cm->num.head; list; list = list->next)
19373 lcommunity_list_show(vty, list);
19374
19375 for (list = cm->str.head; list; list = list->next)
19376 lcommunity_list_show(vty, list);
19377
19378 return CMD_SUCCESS;
19379 }
19380
19381 DEFUN (show_lcommunity_list_arg,
19382 show_bgp_lcommunity_list_arg_cmd,
19383 "show bgp large-community-list <(1-500)|WORD> detail",
19384 SHOW_STR
19385 BGP_STR
19386 "List large-community list\n"
19387 "Large-community-list number\n"
19388 "Large-community-list name\n"
19389 "Detailed information on large-community-list\n")
19390 {
19391 struct community_list *list;
19392
19393 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
19394 LARGE_COMMUNITY_LIST_MASTER);
19395 if (!list) {
19396 vty_out(vty, "%% Can't find large-community-list\n");
19397 return CMD_WARNING;
19398 }
19399
19400 lcommunity_list_show(vty, list);
19401
19402 return CMD_SUCCESS;
19403 }
19404
19405 /* "extcommunity-list" keyword help string. */
19406 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
19407 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
19408
19409 DEFUN (extcommunity_list_standard,
19410 bgp_extcommunity_list_standard_cmd,
19411 "bgp extcommunity-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
19412 BGP_STR
19413 EXTCOMMUNITY_LIST_STR
19414 "Extended Community list number (standard)\n"
19415 "Specify standard extcommunity-list\n"
19416 "Community list name\n"
19417 "Sequence number of an entry\n"
19418 "Sequence number\n"
19419 "Specify community to reject\n"
19420 "Specify community to accept\n"
19421 EXTCOMMUNITY_VAL_STR)
19422 {
19423 int style = EXTCOMMUNITY_LIST_STANDARD;
19424 int direct = 0;
19425 char *cl_number_or_name = NULL;
19426 char *seq = NULL;
19427
19428 int idx = 0;
19429
19430 argv_find(argv, argc, "(1-99)", &idx);
19431 argv_find(argv, argc, "WORD", &idx);
19432 cl_number_or_name = argv[idx]->arg;
19433
19434 if (argv_find(argv, argc, "(1-4294967295)", &idx))
19435 seq = argv[idx]->arg;
19436
19437 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19438 : COMMUNITY_DENY;
19439 argv_find(argv, argc, "AA:NN", &idx);
19440 char *str = argv_concat(argv, argc, idx);
19441
19442 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
19443 direct, style);
19444
19445 XFREE(MTYPE_TMP, str);
19446
19447 if (ret < 0) {
19448 community_list_perror(vty, ret);
19449 return CMD_WARNING_CONFIG_FAILED;
19450 }
19451
19452 return CMD_SUCCESS;
19453 }
19454
19455 DEFUN (extcommunity_list_name_expanded,
19456 bgp_extcommunity_list_name_expanded_cmd,
19457 "bgp extcommunity-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> LINE...",
19458 BGP_STR
19459 EXTCOMMUNITY_LIST_STR
19460 "Extended Community list number (expanded)\n"
19461 "Specify expanded extcommunity-list\n"
19462 "Extended Community list name\n"
19463 "Sequence number of an entry\n"
19464 "Sequence number\n"
19465 "Specify community to reject\n"
19466 "Specify community to accept\n"
19467 "An ordered list as a regular-expression\n")
19468 {
19469 int style = EXTCOMMUNITY_LIST_EXPANDED;
19470 int direct = 0;
19471 char *cl_number_or_name = NULL;
19472 char *seq = NULL;
19473 int idx = 0;
19474
19475 argv_find(argv, argc, "(100-500)", &idx);
19476 argv_find(argv, argc, "WORD", &idx);
19477 cl_number_or_name = argv[idx]->arg;
19478
19479 if (argv_find(argv, argc, "(1-4294967295)", &idx))
19480 seq = argv[idx]->arg;
19481
19482 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19483 : COMMUNITY_DENY;
19484 argv_find(argv, argc, "LINE", &idx);
19485 char *str = argv_concat(argv, argc, idx);
19486
19487 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
19488 direct, style);
19489
19490 XFREE(MTYPE_TMP, str);
19491
19492 if (ret < 0) {
19493 community_list_perror(vty, ret);
19494 return CMD_WARNING_CONFIG_FAILED;
19495 }
19496
19497 return CMD_SUCCESS;
19498 }
19499
19500 DEFUN (no_extcommunity_list_standard_all,
19501 no_bgp_extcommunity_list_standard_all_cmd,
19502 "no bgp extcommunity-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
19503 NO_STR
19504 BGP_STR
19505 EXTCOMMUNITY_LIST_STR
19506 "Extended Community list number (standard)\n"
19507 "Specify standard extcommunity-list\n"
19508 "Community list name\n"
19509 "Sequence number of an entry\n"
19510 "Sequence number\n"
19511 "Specify community to reject\n"
19512 "Specify community to accept\n"
19513 EXTCOMMUNITY_VAL_STR)
19514 {
19515 int style = EXTCOMMUNITY_LIST_STANDARD;
19516 int direct = 0;
19517 char *cl_number_or_name = NULL;
19518 char *str = NULL;
19519 char *seq = NULL;
19520 int idx = 0;
19521
19522 if (argv_find(argv, argc, "(1-4294967295)", &idx))
19523 seq = argv[idx]->arg;
19524
19525 idx = 0;
19526 argv_find(argv, argc, "permit", &idx);
19527 argv_find(argv, argc, "deny", &idx);
19528 if (idx) {
19529 direct = argv_find(argv, argc, "permit", &idx)
19530 ? COMMUNITY_PERMIT
19531 : COMMUNITY_DENY;
19532
19533 idx = 0;
19534 argv_find(argv, argc, "AA:NN", &idx);
19535 str = argv_concat(argv, argc, idx);
19536 }
19537
19538 idx = 0;
19539 argv_find(argv, argc, "(1-99)", &idx);
19540 argv_find(argv, argc, "WORD", &idx);
19541 cl_number_or_name = argv[idx]->arg;
19542
19543 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
19544 seq, direct, style);
19545
19546 XFREE(MTYPE_TMP, str);
19547
19548 if (ret < 0) {
19549 community_list_perror(vty, ret);
19550 return CMD_WARNING_CONFIG_FAILED;
19551 }
19552
19553 return CMD_SUCCESS;
19554 }
19555
19556 ALIAS(no_extcommunity_list_standard_all,
19557 no_bgp_extcommunity_list_standard_all_list_cmd,
19558 "no bgp extcommunity-list <(1-99)|standard WORD>",
19559 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
19560 "Extended Community list number (standard)\n"
19561 "Specify standard extcommunity-list\n"
19562 "Community list name\n")
19563
19564 DEFUN (no_extcommunity_list_expanded_all,
19565 no_bgp_extcommunity_list_expanded_all_cmd,
19566 "no bgp extcommunity-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> LINE...",
19567 NO_STR
19568 BGP_STR
19569 EXTCOMMUNITY_LIST_STR
19570 "Extended Community list number (expanded)\n"
19571 "Specify expanded extcommunity-list\n"
19572 "Extended Community list name\n"
19573 "Sequence number of an entry\n"
19574 "Sequence number\n"
19575 "Specify community to reject\n"
19576 "Specify community to accept\n"
19577 "An ordered list as a regular-expression\n")
19578 {
19579 int style = EXTCOMMUNITY_LIST_EXPANDED;
19580 int direct = 0;
19581 char *cl_number_or_name = NULL;
19582 char *str = NULL;
19583 char *seq = NULL;
19584 int idx = 0;
19585
19586 if (argv_find(argv, argc, "(1-4294967295)", &idx))
19587 seq = argv[idx]->arg;
19588
19589 idx = 0;
19590 argv_find(argv, argc, "permit", &idx);
19591 argv_find(argv, argc, "deny", &idx);
19592
19593 if (idx) {
19594 direct = argv_find(argv, argc, "permit", &idx)
19595 ? COMMUNITY_PERMIT
19596 : COMMUNITY_DENY;
19597
19598 idx = 0;
19599 argv_find(argv, argc, "LINE", &idx);
19600 str = argv_concat(argv, argc, idx);
19601 }
19602
19603 idx = 0;
19604 argv_find(argv, argc, "(100-500)", &idx);
19605 argv_find(argv, argc, "WORD", &idx);
19606 cl_number_or_name = argv[idx]->arg;
19607
19608 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
19609 seq, direct, style);
19610
19611 XFREE(MTYPE_TMP, str);
19612
19613 if (ret < 0) {
19614 community_list_perror(vty, ret);
19615 return CMD_WARNING_CONFIG_FAILED;
19616 }
19617
19618 return CMD_SUCCESS;
19619 }
19620
19621 ALIAS(no_extcommunity_list_expanded_all,
19622 no_bgp_extcommunity_list_expanded_all_list_cmd,
19623 "no bgp extcommunity-list <(100-500)|expanded WORD>",
19624 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
19625 "Extended Community list number (expanded)\n"
19626 "Specify expanded extcommunity-list\n"
19627 "Extended Community list name\n")
19628
19629 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
19630 {
19631 struct community_entry *entry;
19632
19633 for (entry = list->head; entry; entry = entry->next) {
19634 if (entry == list->head) {
19635 if (all_digit(list->name))
19636 vty_out(vty, "Extended community %s list %s\n",
19637 entry->style == EXTCOMMUNITY_LIST_STANDARD
19638 ? "standard"
19639 : "(expanded) access",
19640 list->name);
19641 else
19642 vty_out(vty,
19643 "Named extended community %s list %s\n",
19644 entry->style == EXTCOMMUNITY_LIST_STANDARD
19645 ? "standard"
19646 : "expanded",
19647 list->name);
19648 }
19649 if (entry->any)
19650 vty_out(vty, " %s\n",
19651 community_direct_str(entry->direct));
19652 else
19653 vty_out(vty, " %s %s\n",
19654 community_direct_str(entry->direct),
19655 community_list_config_str(entry));
19656 }
19657 }
19658
19659 DEFUN (show_extcommunity_list,
19660 show_bgp_extcommunity_list_cmd,
19661 "show bgp extcommunity-list",
19662 SHOW_STR
19663 BGP_STR
19664 "List extended-community list\n")
19665 {
19666 struct community_list *list;
19667 struct community_list_master *cm;
19668
19669 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
19670 if (!cm)
19671 return CMD_SUCCESS;
19672
19673 for (list = cm->num.head; list; list = list->next)
19674 extcommunity_list_show(vty, list);
19675
19676 for (list = cm->str.head; list; list = list->next)
19677 extcommunity_list_show(vty, list);
19678
19679 return CMD_SUCCESS;
19680 }
19681
19682 DEFUN (show_extcommunity_list_arg,
19683 show_bgp_extcommunity_list_arg_cmd,
19684 "show bgp extcommunity-list <(1-500)|WORD> detail",
19685 SHOW_STR
19686 BGP_STR
19687 "List extended-community list\n"
19688 "Extcommunity-list number\n"
19689 "Extcommunity-list name\n"
19690 "Detailed information on extcommunity-list\n")
19691 {
19692 int idx_comm_list = 3;
19693 struct community_list *list;
19694
19695 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
19696 EXTCOMMUNITY_LIST_MASTER);
19697 if (!list) {
19698 vty_out(vty, "%% Can't find extcommunity-list\n");
19699 return CMD_WARNING;
19700 }
19701
19702 extcommunity_list_show(vty, list);
19703
19704 return CMD_SUCCESS;
19705 }
19706
19707 /* Display community-list and extcommunity-list configuration. */
19708 static int community_list_config_write(struct vty *vty)
19709 {
19710 struct community_list *list;
19711 struct community_entry *entry;
19712 struct community_list_master *cm;
19713 int write = 0;
19714
19715 /* Community-list. */
19716 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
19717
19718 for (list = cm->num.head; list; list = list->next)
19719 for (entry = list->head; entry; entry = entry->next) {
19720 vty_out(vty,
19721 "bgp community-list %s seq %" PRId64 " %s %s\n",
19722 list->name, entry->seq,
19723 community_direct_str(entry->direct),
19724 community_list_config_str(entry));
19725 write++;
19726 }
19727 for (list = cm->str.head; list; list = list->next)
19728 for (entry = list->head; entry; entry = entry->next) {
19729 vty_out(vty,
19730 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
19731 entry->style == COMMUNITY_LIST_STANDARD
19732 ? "standard"
19733 : "expanded",
19734 list->name, entry->seq,
19735 community_direct_str(entry->direct),
19736 community_list_config_str(entry));
19737 write++;
19738 }
19739
19740 /* Extcommunity-list. */
19741 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
19742
19743 for (list = cm->num.head; list; list = list->next)
19744 for (entry = list->head; entry; entry = entry->next) {
19745 vty_out(vty,
19746 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
19747 list->name, entry->seq,
19748 community_direct_str(entry->direct),
19749 community_list_config_str(entry));
19750 write++;
19751 }
19752 for (list = cm->str.head; list; list = list->next)
19753 for (entry = list->head; entry; entry = entry->next) {
19754 vty_out(vty,
19755 "bgp extcommunity-list %s %s seq %" PRId64" %s %s\n",
19756 entry->style == EXTCOMMUNITY_LIST_STANDARD
19757 ? "standard"
19758 : "expanded",
19759 list->name, entry->seq,
19760 community_direct_str(entry->direct),
19761 community_list_config_str(entry));
19762 write++;
19763 }
19764
19765
19766 /* lcommunity-list. */
19767 cm = community_list_master_lookup(bgp_clist,
19768 LARGE_COMMUNITY_LIST_MASTER);
19769
19770 for (list = cm->num.head; list; list = list->next)
19771 for (entry = list->head; entry; entry = entry->next) {
19772 vty_out(vty,
19773 "bgp large-community-list %s seq %" PRId64" %s %s\n",
19774 list->name, entry->seq,
19775 community_direct_str(entry->direct),
19776 community_list_config_str(entry));
19777 write++;
19778 }
19779 for (list = cm->str.head; list; list = list->next)
19780 for (entry = list->head; entry; entry = entry->next) {
19781 vty_out(vty,
19782 "bgp large-community-list %s %s seq %" PRId64" %s %s\n",
19783
19784 entry->style == LARGE_COMMUNITY_LIST_STANDARD
19785 ? "standard"
19786 : "expanded",
19787 list->name, entry->seq, community_direct_str(entry->direct),
19788 community_list_config_str(entry));
19789 write++;
19790 }
19791
19792 return write;
19793 }
19794
19795 static int community_list_config_write(struct vty *vty);
19796 static struct cmd_node community_list_node = {
19797 .name = "community list",
19798 .node = COMMUNITY_LIST_NODE,
19799 .prompt = "",
19800 .config_write = community_list_config_write,
19801 };
19802
19803 static void community_list_vty(void)
19804 {
19805 install_node(&community_list_node);
19806
19807 /* Community-list. */
19808 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
19809 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
19810 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
19811 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
19812 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
19813 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
19814 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
19815 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
19816
19817 /* Extcommunity-list. */
19818 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
19819 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
19820 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
19821 install_element(CONFIG_NODE,
19822 &no_bgp_extcommunity_list_standard_all_list_cmd);
19823 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
19824 install_element(CONFIG_NODE,
19825 &no_bgp_extcommunity_list_expanded_all_list_cmd);
19826 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
19827 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
19828
19829 /* Large Community List */
19830 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
19831 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
19832 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
19833 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
19834 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
19835 install_element(CONFIG_NODE,
19836 &no_bgp_lcommunity_list_name_standard_all_cmd);
19837 install_element(CONFIG_NODE,
19838 &no_bgp_lcommunity_list_name_expanded_all_cmd);
19839 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
19840 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
19841 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
19842 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
19843 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
19844 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
19845 }