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