]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
c8a3c28523a498cc4b8339f993612a57f22bd721
[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 enum node_type bgp_node_type(afi_t afi, safi_t safi)
158 {
159 switch (afi) {
160 case AFI_IP:
161 switch (safi) {
162 case SAFI_UNICAST:
163 return BGP_IPV4_NODE;
164 case SAFI_MULTICAST:
165 return BGP_IPV4M_NODE;
166 case SAFI_LABELED_UNICAST:
167 return BGP_IPV4L_NODE;
168 case SAFI_MPLS_VPN:
169 return BGP_VPNV4_NODE;
170 case SAFI_FLOWSPEC:
171 return BGP_FLOWSPECV4_NODE;
172 default:
173 /* not expected */
174 return BGP_IPV4_NODE;
175 }
176 break;
177 case AFI_IP6:
178 switch (safi) {
179 case SAFI_UNICAST:
180 return BGP_IPV6_NODE;
181 case SAFI_MULTICAST:
182 return BGP_IPV6M_NODE;
183 case SAFI_LABELED_UNICAST:
184 return BGP_IPV6L_NODE;
185 case SAFI_MPLS_VPN:
186 return BGP_VPNV6_NODE;
187 case SAFI_FLOWSPEC:
188 return BGP_FLOWSPECV6_NODE;
189 default:
190 /* not expected */
191 return BGP_IPV4_NODE;
192 }
193 break;
194 case AFI_L2VPN:
195 return BGP_EVPN_NODE;
196 case AFI_UNSPEC:
197 case AFI_MAX:
198 // We should never be here but to clarify the switch statement..
199 return BGP_IPV4_NODE;
200 }
201
202 // Impossible to happen
203 return BGP_IPV4_NODE;
204 }
205
206 static const char *get_afi_safi_vty_str(afi_t afi, safi_t safi)
207 {
208 if (afi == AFI_IP && safi == SAFI_UNICAST)
209 return "IPv4 Unicast";
210 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
211 return "IPv4 Multicast";
212 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
213 return "IPv4 Labeled Unicast";
214 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
215 return "IPv4 VPN";
216 else if (afi == AFI_IP && safi == SAFI_ENCAP)
217 return "IPv4 Encap";
218 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
219 return "IPv4 Flowspec";
220 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
221 return "IPv6 Unicast";
222 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
223 return "IPv6 Multicast";
224 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
225 return "IPv6 Labeled Unicast";
226 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
227 return "IPv6 VPN";
228 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
229 return "IPv6 Encap";
230 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
231 return "IPv6 Flowspec";
232 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
233 return "L2VPN EVPN";
234 else
235 return "Unknown";
236 }
237
238 /*
239 * Please note that we have intentionally camelCased
240 * the return strings here. So if you want
241 * to use this function, please ensure you
242 * are doing this within json output
243 */
244 static const char *get_afi_safi_json_str(afi_t afi, safi_t safi)
245 {
246 if (afi == AFI_IP && safi == SAFI_UNICAST)
247 return "ipv4Unicast";
248 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
249 return "ipv4Multicast";
250 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
251 return "ipv4LabeledUnicast";
252 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
253 return "ipv4Vpn";
254 else if (afi == AFI_IP && safi == SAFI_ENCAP)
255 return "ipv4Encap";
256 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
257 return "ipv4Flowspec";
258 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
259 return "ipv6Unicast";
260 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
261 return "ipv6Multicast";
262 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
263 return "ipv6LabeledUnicast";
264 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
265 return "ipv6Vpn";
266 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
267 return "ipv6Encap";
268 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
269 return "ipv6Flowspec";
270 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
271 return "l2VpnEvpn";
272 else
273 return "Unknown";
274 }
275
276 /* Utility function to get address family from current node. */
277 afi_t bgp_node_afi(struct vty *vty)
278 {
279 afi_t afi;
280 switch (vty->node) {
281 case BGP_IPV6_NODE:
282 case BGP_IPV6M_NODE:
283 case BGP_IPV6L_NODE:
284 case BGP_VPNV6_NODE:
285 case BGP_FLOWSPECV6_NODE:
286 afi = AFI_IP6;
287 break;
288 case BGP_EVPN_NODE:
289 afi = AFI_L2VPN;
290 break;
291 default:
292 afi = AFI_IP;
293 break;
294 }
295 return afi;
296 }
297
298 /* Utility function to get subsequent address family from current
299 node. */
300 safi_t bgp_node_safi(struct vty *vty)
301 {
302 safi_t safi;
303 switch (vty->node) {
304 case BGP_VPNV4_NODE:
305 case BGP_VPNV6_NODE:
306 safi = SAFI_MPLS_VPN;
307 break;
308 case BGP_IPV4M_NODE:
309 case BGP_IPV6M_NODE:
310 safi = SAFI_MULTICAST;
311 break;
312 case BGP_EVPN_NODE:
313 safi = SAFI_EVPN;
314 break;
315 case BGP_IPV4L_NODE:
316 case BGP_IPV6L_NODE:
317 safi = SAFI_LABELED_UNICAST;
318 break;
319 case BGP_FLOWSPECV4_NODE:
320 case BGP_FLOWSPECV6_NODE:
321 safi = SAFI_FLOWSPEC;
322 break;
323 default:
324 safi = SAFI_UNICAST;
325 break;
326 }
327 return safi;
328 }
329
330 /**
331 * Converts an AFI in string form to afi_t
332 *
333 * @param afi string, one of
334 * - "ipv4"
335 * - "ipv6"
336 * - "l2vpn"
337 * @return the corresponding afi_t
338 */
339 afi_t bgp_vty_afi_from_str(const char *afi_str)
340 {
341 afi_t afi = AFI_MAX; /* unknown */
342 if (strmatch(afi_str, "ipv4"))
343 afi = AFI_IP;
344 else if (strmatch(afi_str, "ipv6"))
345 afi = AFI_IP6;
346 else if (strmatch(afi_str, "l2vpn"))
347 afi = AFI_L2VPN;
348 return afi;
349 }
350
351 int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
352 afi_t *afi)
353 {
354 int ret = 0;
355 if (argv_find(argv, argc, "ipv4", index)) {
356 ret = 1;
357 if (afi)
358 *afi = AFI_IP;
359 } else if (argv_find(argv, argc, "ipv6", index)) {
360 ret = 1;
361 if (afi)
362 *afi = AFI_IP6;
363 } else if (argv_find(argv, argc, "l2vpn", index)) {
364 ret = 1;
365 if (afi)
366 *afi = AFI_L2VPN;
367 }
368 return ret;
369 }
370
371 /* supports <unicast|multicast|vpn|labeled-unicast> */
372 safi_t bgp_vty_safi_from_str(const char *safi_str)
373 {
374 safi_t safi = SAFI_MAX; /* unknown */
375 if (strmatch(safi_str, "multicast"))
376 safi = SAFI_MULTICAST;
377 else if (strmatch(safi_str, "unicast"))
378 safi = SAFI_UNICAST;
379 else if (strmatch(safi_str, "vpn"))
380 safi = SAFI_MPLS_VPN;
381 else if (strmatch(safi_str, "evpn"))
382 safi = SAFI_EVPN;
383 else if (strmatch(safi_str, "labeled-unicast"))
384 safi = SAFI_LABELED_UNICAST;
385 else if (strmatch(safi_str, "flowspec"))
386 safi = SAFI_FLOWSPEC;
387 return safi;
388 }
389
390 int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
391 safi_t *safi)
392 {
393 int ret = 0;
394 if (argv_find(argv, argc, "unicast", index)) {
395 ret = 1;
396 if (safi)
397 *safi = SAFI_UNICAST;
398 } else if (argv_find(argv, argc, "multicast", index)) {
399 ret = 1;
400 if (safi)
401 *safi = SAFI_MULTICAST;
402 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
403 ret = 1;
404 if (safi)
405 *safi = SAFI_LABELED_UNICAST;
406 } else if (argv_find(argv, argc, "vpn", index)) {
407 ret = 1;
408 if (safi)
409 *safi = SAFI_MPLS_VPN;
410 } else if (argv_find(argv, argc, "evpn", index)) {
411 ret = 1;
412 if (safi)
413 *safi = SAFI_EVPN;
414 } else if (argv_find(argv, argc, "flowspec", index)) {
415 ret = 1;
416 if (safi)
417 *safi = SAFI_FLOWSPEC;
418 }
419 return ret;
420 }
421
422 int bgp_get_vty(struct bgp **bgp, as_t *as, const char *name,
423 enum bgp_instance_type inst_type)
424 {
425 int ret = bgp_get(bgp, as, name, inst_type);
426
427 if (ret == BGP_CREATED) {
428 bgp_timers_set(*bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
429 DFLT_BGP_CONNECT_RETRY);
430
431 if (DFLT_BGP_IMPORT_CHECK)
432 SET_FLAG((*bgp)->flags, BGP_FLAG_IMPORT_CHECK);
433 if (DFLT_BGP_SHOW_HOSTNAME)
434 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_HOSTNAME);
435 if (DFLT_BGP_SHOW_NEXTHOP_HOSTNAME)
436 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
437 if (DFLT_BGP_LOG_NEIGHBOR_CHANGES)
438 SET_FLAG((*bgp)->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
439 if (DFLT_BGP_DETERMINISTIC_MED)
440 SET_FLAG((*bgp)->flags, BGP_FLAG_DETERMINISTIC_MED);
441 if (DFLT_BGP_EBGP_REQUIRES_POLICY)
442 SET_FLAG((*bgp)->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
443
444 ret = BGP_SUCCESS;
445 }
446 return ret;
447 }
448
449 /*
450 * bgp_vty_find_and_parse_afi_safi_bgp
451 *
452 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
453 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
454 * to appropriate values for the calling function. This is to allow the
455 * calling function to make decisions appropriate for the show command
456 * that is being parsed.
457 *
458 * The show commands are generally of the form:
459 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
460 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
461 *
462 * Since we use argv_find if the show command in particular doesn't have:
463 * [ip]
464 * [<view|vrf> VIEWVRFNAME]
465 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
466 * The command parsing should still be ok.
467 *
468 * vty -> The vty for the command so we can output some useful data in
469 * the event of a parse error in the vrf.
470 * argv -> The command tokens
471 * argc -> How many command tokens we have
472 * idx -> The current place in the command, generally should be 0 for this
473 * function
474 * afi -> The parsed afi if it was included in the show command, returned here
475 * safi -> The parsed safi if it was included in the show command, returned here
476 * bgp -> Pointer to the bgp data structure we need to fill in.
477 * use_json -> json is configured or not
478 *
479 * The function returns the correct location in the parse tree for the
480 * last token found.
481 *
482 * Returns 0 for failure to parse correctly, else the idx position of where
483 * it found the last token.
484 */
485 int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
486 struct cmd_token **argv, int argc,
487 int *idx, afi_t *afi, safi_t *safi,
488 struct bgp **bgp, bool use_json)
489 {
490 char *vrf_name = NULL;
491
492 assert(afi);
493 assert(safi);
494 assert(bgp);
495
496 if (argv_find(argv, argc, "ip", idx))
497 *afi = AFI_IP;
498
499 if (argv_find(argv, argc, "view", idx))
500 vrf_name = argv[*idx + 1]->arg;
501 else if (argv_find(argv, argc, "vrf", idx)) {
502 vrf_name = argv[*idx + 1]->arg;
503 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
504 vrf_name = NULL;
505 }
506 if (vrf_name) {
507 if (strmatch(vrf_name, "all"))
508 *bgp = NULL;
509 else {
510 *bgp = bgp_lookup_by_name(vrf_name);
511 if (!*bgp) {
512 if (use_json) {
513 json_object *json = NULL;
514 json = json_object_new_object();
515 json_object_string_add(
516 json, "warning",
517 "View/Vrf is unknown");
518 vty_out(vty, "%s\n",
519 json_object_to_json_string_ext(json,
520 JSON_C_TO_STRING_PRETTY));
521 json_object_free(json);
522 }
523 else
524 vty_out(vty, "View/Vrf %s is unknown\n",
525 vrf_name);
526 *idx = 0;
527 return 0;
528 }
529 }
530 } else {
531 *bgp = bgp_get_default();
532 if (!*bgp) {
533 if (use_json) {
534 json_object *json = NULL;
535 json = json_object_new_object();
536 json_object_string_add(
537 json, "warning",
538 "Default BGP instance not found");
539 vty_out(vty, "%s\n",
540 json_object_to_json_string_ext(json,
541 JSON_C_TO_STRING_PRETTY));
542 json_object_free(json);
543 }
544 else
545 vty_out(vty,
546 "Default BGP instance not found\n");
547 *idx = 0;
548 return 0;
549 }
550 }
551
552 if (argv_find_and_parse_afi(argv, argc, idx, afi))
553 argv_find_and_parse_safi(argv, argc, idx, safi);
554
555 *idx += 1;
556 return *idx;
557 }
558
559 static bool peer_address_self_check(struct bgp *bgp, union sockunion *su)
560 {
561 struct interface *ifp = NULL;
562
563 if (su->sa.sa_family == AF_INET)
564 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
565 else if (su->sa.sa_family == AF_INET6)
566 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
567 su->sin6.sin6_scope_id,
568 bgp->vrf_id);
569
570 if (ifp)
571 return true;
572
573 return false;
574 }
575
576 /* Utility function for looking up peer from VTY. */
577 /* This is used only for configuration, so disallow if attempted on
578 * a dynamic neighbor.
579 */
580 static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
581 {
582 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
583 int ret;
584 union sockunion su;
585 struct peer *peer;
586
587 if (!bgp) {
588 return NULL;
589 }
590
591 ret = str2sockunion(ip_str, &su);
592 if (ret < 0) {
593 peer = peer_lookup_by_conf_if(bgp, ip_str);
594 if (!peer) {
595 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
596 == NULL) {
597 vty_out(vty,
598 "%% Malformed address or name: %s\n",
599 ip_str);
600 return NULL;
601 }
602 }
603 } else {
604 peer = peer_lookup(bgp, &su);
605 if (!peer) {
606 vty_out(vty,
607 "%% Specify remote-as or peer-group commands first\n");
608 return NULL;
609 }
610 if (peer_dynamic_neighbor(peer)) {
611 vty_out(vty,
612 "%% Operation not allowed on a dynamic neighbor\n");
613 return NULL;
614 }
615 }
616 return peer;
617 }
618
619 /* Utility function for looking up peer or peer group. */
620 /* This is used only for configuration, so disallow if attempted on
621 * a dynamic neighbor.
622 */
623 struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
624 {
625 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
626 int ret;
627 union sockunion su;
628 struct peer *peer = NULL;
629 struct peer_group *group = NULL;
630
631 if (!bgp) {
632 return NULL;
633 }
634
635 ret = str2sockunion(peer_str, &su);
636 if (ret == 0) {
637 /* IP address, locate peer. */
638 peer = peer_lookup(bgp, &su);
639 } else {
640 /* Not IP, could match either peer configured on interface or a
641 * group. */
642 peer = peer_lookup_by_conf_if(bgp, peer_str);
643 if (!peer)
644 group = peer_group_lookup(bgp, peer_str);
645 }
646
647 if (peer) {
648 if (peer_dynamic_neighbor(peer)) {
649 vty_out(vty,
650 "%% Operation not allowed on a dynamic neighbor\n");
651 return NULL;
652 }
653
654 return peer;
655 }
656
657 if (group)
658 return group->conf;
659
660 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
661
662 return NULL;
663 }
664
665 int bgp_vty_return(struct vty *vty, int ret)
666 {
667 const char *str = NULL;
668
669 switch (ret) {
670 case BGP_ERR_INVALID_VALUE:
671 str = "Invalid value";
672 break;
673 case BGP_ERR_INVALID_FLAG:
674 str = "Invalid flag";
675 break;
676 case BGP_ERR_PEER_GROUP_SHUTDOWN:
677 str = "Peer-group has been shutdown. Activate the peer-group first";
678 break;
679 case BGP_ERR_PEER_FLAG_CONFLICT:
680 str = "Can't set override-capability and strict-capability-match at the same time";
681 break;
682 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
683 str = "Specify remote-as or peer-group remote AS first";
684 break;
685 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
686 str = "Cannot change the peer-group. Deconfigure first";
687 break;
688 case BGP_ERR_PEER_GROUP_MISMATCH:
689 str = "Peer is not a member of this peer-group";
690 break;
691 case BGP_ERR_PEER_FILTER_CONFLICT:
692 str = "Prefix/distribute list can not co-exist";
693 break;
694 case BGP_ERR_NOT_INTERNAL_PEER:
695 str = "Invalid command. Not an internal neighbor";
696 break;
697 case BGP_ERR_REMOVE_PRIVATE_AS:
698 str = "remove-private-AS cannot be configured for IBGP peers";
699 break;
700 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
701 str = "Local-AS allowed only for EBGP peers";
702 break;
703 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
704 str = "Cannot have local-as same as BGP AS number";
705 break;
706 case BGP_ERR_TCPSIG_FAILED:
707 str = "Error while applying TCP-Sig to session(s)";
708 break;
709 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
710 str = "ebgp-multihop and ttl-security cannot be configured together";
711 break;
712 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
713 str = "ttl-security only allowed for EBGP peers";
714 break;
715 case BGP_ERR_AS_OVERRIDE:
716 str = "as-override cannot be configured for IBGP peers";
717 break;
718 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
719 str = "Invalid limit for number of dynamic neighbors";
720 break;
721 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
722 str = "Dynamic neighbor listen range already exists";
723 break;
724 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
725 str = "Operation not allowed on a dynamic neighbor";
726 break;
727 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
728 str = "Operation not allowed on a directly connected neighbor";
729 break;
730 case BGP_ERR_PEER_SAFI_CONFLICT:
731 str = GR_INVALID;
732 break;
733 case BGP_ERR_GR_INVALID_CMD:
734 str = "The Graceful Restart command used is not valid at this moment.";
735 break;
736 case BGP_ERR_GR_OPERATION_FAILED:
737 str = "The Graceful Restart Operation failed due to an err.";
738 break;
739 case BGP_GR_NO_OPERATION:
740 str = GR_NO_OPER;
741 break;
742 }
743 if (str) {
744 vty_out(vty, "%% %s\n", str);
745 return CMD_WARNING_CONFIG_FAILED;
746 }
747 return CMD_SUCCESS;
748 }
749
750 /* BGP clear sort. */
751 enum clear_sort {
752 clear_all,
753 clear_peer,
754 clear_group,
755 clear_external,
756 clear_as
757 };
758
759 static void bgp_clear_vty_error(struct peer *peer, afi_t afi, safi_t safi,
760 int error, char *errmsg, size_t errmsg_len)
761 {
762 switch (error) {
763 case BGP_ERR_AF_UNCONFIGURED:
764 snprintf(errmsg, errmsg_len,
765 "%%BGP: Enable %s address family for the neighbor %s",
766 get_afi_safi_str(afi, safi, false), peer->host);
767 break;
768 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
769 snprintf(
770 errmsg, errmsg_len,
771 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig",
772 peer->host);
773 break;
774 default:
775 break;
776 }
777 }
778
779 static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi,
780 struct listnode **nnode, enum bgp_clear_type stype)
781 {
782 int ret = 0;
783
784 /* if afi/.safi not specified, spin thru all of them */
785 if ((afi == AFI_UNSPEC) && (safi == SAFI_UNSPEC)) {
786 afi_t tmp_afi;
787 safi_t tmp_safi;
788
789 FOREACH_AFI_SAFI (tmp_afi, tmp_safi) {
790 if (!peer->afc[tmp_afi][tmp_safi])
791 continue;
792
793 if (stype == BGP_CLEAR_SOFT_NONE)
794 ret = peer_clear(peer, nnode);
795 else
796 ret = peer_clear_soft(peer, tmp_afi, tmp_safi,
797 stype);
798 }
799 /* if afi specified and safi not, spin thru safis on this afi */
800 } else if (safi == SAFI_UNSPEC) {
801 safi_t tmp_safi;
802
803 for (tmp_safi = SAFI_UNICAST;
804 tmp_safi < SAFI_MAX; tmp_safi++) {
805 if (!peer->afc[afi][tmp_safi])
806 continue;
807
808 if (stype == BGP_CLEAR_SOFT_NONE)
809 ret = peer_clear(peer, nnode);
810 else
811 ret = peer_clear_soft(peer, afi,
812 tmp_safi, stype);
813 }
814 /* both afi/safi specified, let the caller know if not defined */
815 } else {
816 if (!peer->afc[afi][safi])
817 return 1;
818
819 if (stype == BGP_CLEAR_SOFT_NONE)
820 ret = peer_clear(peer, nnode);
821 else
822 ret = peer_clear_soft(peer, afi, safi, stype);
823 }
824
825 return ret;
826 }
827
828 /* `clear ip bgp' functions. */
829 static int bgp_clear(struct bgp *bgp, afi_t afi, safi_t safi,
830 enum clear_sort sort, enum bgp_clear_type stype,
831 const char *arg, char *errmsg, size_t errmsg_len)
832 {
833 int ret = 0;
834 bool found = false;
835 struct peer *peer;
836
837 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
838
839 /* Clear all neighbors. */
840 /*
841 * Pass along pointer to next node to peer_clear() when walking all
842 * nodes on the BGP instance as that may get freed if it is a
843 * doppelganger
844 */
845 if (sort == clear_all) {
846 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
847
848 bgp_peer_gr_flags_update(peer);
849
850 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
851 gr_router_detected = true;
852
853 ret = bgp_peer_clear(peer, afi, safi, &nnode,
854 stype);
855
856 if (ret < 0)
857 bgp_clear_vty_error(peer, afi, safi, ret,
858 errmsg, errmsg_len);
859 }
860
861 if (gr_router_detected
862 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
863 bgp_zebra_send_capabilities(bgp, false);
864 } else if (!gr_router_detected
865 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
866 bgp_zebra_send_capabilities(bgp, true);
867 }
868
869 /* This is to apply read-only mode on this clear. */
870 if (stype == BGP_CLEAR_SOFT_NONE)
871 bgp->update_delay_over = 0;
872
873 return CMD_SUCCESS;
874 }
875
876 /* Clear specified neighbor. */
877 if (sort == clear_peer) {
878 union sockunion su;
879
880 /* Make sockunion for lookup. */
881 ret = str2sockunion(arg, &su);
882 if (ret < 0) {
883 peer = peer_lookup_by_conf_if(bgp, arg);
884 if (!peer) {
885 peer = peer_lookup_by_hostname(bgp, arg);
886 if (!peer) {
887 snprintf(
888 errmsg, errmsg_len,
889 "Malformed address or name: %s",
890 arg);
891 return CMD_WARNING;
892 }
893 }
894 } else {
895 peer = peer_lookup(bgp, &su);
896 if (!peer) {
897 snprintf(errmsg, errmsg_len,
898 "%%BGP: Unknown neighbor - \"%s\"",
899 arg);
900 return CMD_WARNING;
901 }
902 }
903
904 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
905 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
906
907 ret = bgp_peer_clear(peer, afi, safi, NULL, stype);
908
909 /* if afi/safi not defined for this peer, let caller know */
910 if (ret == 1)
911 ret = BGP_ERR_AF_UNCONFIGURED;
912
913 if (ret < 0)
914 bgp_clear_vty_error(peer, afi, safi, ret, errmsg,
915 errmsg_len);
916
917 return CMD_SUCCESS;
918 }
919
920 /* Clear all neighbors belonging to a specific peer-group. */
921 if (sort == clear_group) {
922 struct peer_group *group;
923
924 group = peer_group_lookup(bgp, arg);
925 if (!group) {
926 snprintf(errmsg, errmsg_len,
927 "%%BGP: No such peer-group %s", arg);
928 return CMD_WARNING;
929 }
930
931 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
932 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
933
934 if (ret < 0)
935 bgp_clear_vty_error(peer, afi, safi, ret,
936 errmsg, errmsg_len);
937 else
938 found = true;
939 }
940
941 if (!found)
942 snprintf(
943 errmsg, errmsg_len,
944 "%%BGP: No %s peer belonging to peer-group %s is configured",
945 get_afi_safi_str(afi, safi, false), arg);
946
947 return CMD_SUCCESS;
948 }
949
950 /* Clear all external (eBGP) neighbors. */
951 if (sort == clear_external) {
952 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
953 if (peer->sort == BGP_PEER_IBGP)
954 continue;
955
956 bgp_peer_gr_flags_update(peer);
957
958 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
959 gr_router_detected = true;
960
961 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
962
963 if (ret < 0)
964 bgp_clear_vty_error(peer, afi, safi, ret,
965 errmsg, errmsg_len);
966 else
967 found = true;
968 }
969
970 if (gr_router_detected
971 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
972 bgp_zebra_send_capabilities(bgp, false);
973 } else if (!gr_router_detected
974 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
975 bgp_zebra_send_capabilities(bgp, true);
976 }
977
978 if (!found)
979 snprintf(errmsg, errmsg_len,
980 "%%BGP: No external %s peer is configured",
981 get_afi_safi_str(afi, safi, false));
982
983 return CMD_SUCCESS;
984 }
985
986 /* Clear all neighbors belonging to a specific AS. */
987 if (sort == clear_as) {
988 as_t as = strtoul(arg, NULL, 10);
989
990 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
991 if (peer->as != as)
992 continue;
993
994 bgp_peer_gr_flags_update(peer);
995
996 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
997 gr_router_detected = true;
998
999 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1000
1001 if (ret < 0)
1002 bgp_clear_vty_error(peer, afi, safi, ret,
1003 errmsg, errmsg_len);
1004 else
1005 found = true;
1006 }
1007
1008 if (gr_router_detected
1009 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1010 bgp_zebra_send_capabilities(bgp, false);
1011 } else if (!gr_router_detected
1012 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1013 bgp_zebra_send_capabilities(bgp, true);
1014 }
1015
1016 if (!found)
1017 snprintf(errmsg, errmsg_len,
1018 "%%BGP: No %s peer is configured with AS %s",
1019 get_afi_safi_str(afi, safi, false), arg);
1020
1021 return CMD_SUCCESS;
1022 }
1023
1024 return CMD_SUCCESS;
1025 }
1026
1027 static int bgp_clear_vty(const char *name, afi_t afi, safi_t safi,
1028 enum clear_sort sort, enum bgp_clear_type stype,
1029 const char *arg, char *errmsg, size_t errmsg_len)
1030 {
1031 struct bgp *bgp;
1032
1033 /* BGP structure lookup. */
1034 if (name) {
1035 bgp = bgp_lookup_by_name(name);
1036 if (bgp == NULL) {
1037 snprintf(errmsg, errmsg_len,
1038 "Can't find BGP instance %s", name);
1039 return CMD_WARNING;
1040 }
1041 } else {
1042 bgp = bgp_get_default();
1043 if (bgp == NULL) {
1044 snprintf(errmsg, errmsg_len,
1045 "No BGP process is configured");
1046 return CMD_WARNING;
1047 }
1048 }
1049
1050 return bgp_clear(bgp, afi, safi, sort, stype, arg, errmsg, errmsg_len);
1051 }
1052
1053 /* clear soft inbound */
1054 int bgp_clear_star_soft_in(const char *name, char *errmsg, size_t errmsg_len)
1055 {
1056 afi_t afi;
1057 safi_t safi;
1058 int ret;
1059
1060 FOREACH_AFI_SAFI (afi, safi) {
1061 ret = bgp_clear_vty(name, afi, safi, clear_all,
1062 BGP_CLEAR_SOFT_IN, NULL, errmsg,
1063 errmsg_len);
1064 if (ret != CMD_SUCCESS)
1065 return -1;
1066 }
1067
1068 return 0;
1069 }
1070
1071 /* clear soft outbound */
1072 int bgp_clear_star_soft_out(const char *name, char *errmsg, size_t errmsg_len)
1073 {
1074 afi_t afi;
1075 safi_t safi;
1076 int ret;
1077
1078 FOREACH_AFI_SAFI (afi, safi) {
1079 ret = bgp_clear_vty(name, afi, safi, clear_all,
1080 BGP_CLEAR_SOFT_OUT, NULL, errmsg,
1081 errmsg_len);
1082 if (ret != CMD_SUCCESS)
1083 return -1;
1084 }
1085
1086 return 0;
1087 }
1088
1089
1090 #ifndef VTYSH_EXTRACT_PL
1091 #include "bgpd/bgp_vty_clippy.c"
1092 #endif
1093
1094 DEFUN_HIDDEN (bgp_local_mac,
1095 bgp_local_mac_cmd,
1096 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
1097 BGP_STR
1098 "Local MAC config\n"
1099 "VxLAN Network Identifier\n"
1100 "VNI number\n"
1101 "local mac\n"
1102 "mac address\n"
1103 "mac-mobility sequence\n"
1104 "seq number\n")
1105 {
1106 int rv;
1107 vni_t vni;
1108 struct ethaddr mac;
1109 struct ipaddr ip;
1110 uint32_t seq;
1111 struct bgp *bgp;
1112
1113 vni = strtoul(argv[3]->arg, NULL, 10);
1114 if (!prefix_str2mac(argv[5]->arg, &mac)) {
1115 vty_out(vty, "%% Malformed MAC address\n");
1116 return CMD_WARNING;
1117 }
1118 memset(&ip, 0, sizeof(ip));
1119 seq = strtoul(argv[7]->arg, NULL, 10);
1120
1121 bgp = bgp_get_default();
1122 if (!bgp) {
1123 vty_out(vty, "Default BGP instance is not there\n");
1124 return CMD_WARNING;
1125 }
1126
1127 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq,
1128 zero_esi);
1129 if (rv < 0) {
1130 vty_out(vty, "Internal error\n");
1131 return CMD_WARNING;
1132 }
1133
1134 return CMD_SUCCESS;
1135 }
1136
1137 DEFUN_HIDDEN (no_bgp_local_mac,
1138 no_bgp_local_mac_cmd,
1139 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
1140 NO_STR
1141 BGP_STR
1142 "Local MAC config\n"
1143 "VxLAN Network Identifier\n"
1144 "VNI number\n"
1145 "local mac\n"
1146 "mac address\n")
1147 {
1148 int rv;
1149 vni_t vni;
1150 struct ethaddr mac;
1151 struct ipaddr ip;
1152 struct bgp *bgp;
1153
1154 vni = strtoul(argv[4]->arg, NULL, 10);
1155 if (!prefix_str2mac(argv[6]->arg, &mac)) {
1156 vty_out(vty, "%% Malformed MAC address\n");
1157 return CMD_WARNING;
1158 }
1159 memset(&ip, 0, sizeof(ip));
1160
1161 bgp = bgp_get_default();
1162 if (!bgp) {
1163 vty_out(vty, "Default BGP instance is not there\n");
1164 return CMD_WARNING;
1165 }
1166
1167 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
1168 if (rv < 0) {
1169 vty_out(vty, "Internal error\n");
1170 return CMD_WARNING;
1171 }
1172
1173 return CMD_SUCCESS;
1174 }
1175
1176 DEFUN (no_synchronization,
1177 no_synchronization_cmd,
1178 "no synchronization",
1179 NO_STR
1180 "Perform IGP synchronization\n")
1181 {
1182 return CMD_SUCCESS;
1183 }
1184
1185 DEFUN (no_auto_summary,
1186 no_auto_summary_cmd,
1187 "no auto-summary",
1188 NO_STR
1189 "Enable automatic network number summarization\n")
1190 {
1191 return CMD_SUCCESS;
1192 }
1193
1194 /* "router bgp" commands. */
1195 DEFUN_YANG_NOSH(router_bgp,
1196 router_bgp_cmd,
1197 "router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1198 ROUTER_STR BGP_STR AS_STR BGP_INSTANCE_HELP_STR)
1199 {
1200 int idx_asn = 2;
1201 int idx_view_vrf = 3;
1202 int idx_vrf = 4;
1203 int ret = CMD_SUCCESS;
1204 as_t as;
1205 struct bgp *bgp;
1206 const char *name = NULL;
1207 char as_str[12] = {'\0'};
1208 enum bgp_instance_type inst_type;
1209 char base_xpath[XPATH_MAXLEN];
1210
1211 // "router bgp" without an ASN
1212 if (argc == 2) {
1213 // Pending: Make VRF option available for ASN less config
1214 bgp = bgp_get_default();
1215
1216 if (bgp == NULL) {
1217 vty_out(vty, "%% No BGP process is configured\n");
1218 return CMD_WARNING_CONFIG_FAILED;
1219 }
1220
1221 if (listcount(bm->bgp) > 1) {
1222 vty_out(vty, "%% Please specify ASN and VRF\n");
1223 return CMD_WARNING_CONFIG_FAILED;
1224 }
1225
1226 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_GLOBAL_XPATH,
1227 "frr-bgp:bgp", "bgp", VRF_DEFAULT_NAME);
1228
1229 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
1230 snprintf(as_str, 12, "%d", bgp->as);
1231 nb_cli_enqueue_change(vty, "./global/local-as", NB_OP_MODIFY,
1232 as_str);
1233 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW) {
1234 nb_cli_enqueue_change(vty,
1235 "./global/instance-type-view",
1236 NB_OP_MODIFY, "true");
1237 }
1238
1239 nb_cli_pending_commit_check(vty);
1240 ret = nb_cli_apply_changes(vty, base_xpath);
1241 if (ret == CMD_SUCCESS) {
1242 VTY_PUSH_XPATH(BGP_NODE, base_xpath);
1243
1244 /*
1245 * For backward compatibility with old commands we still
1246 * need to use the qobj infrastructure.
1247 */
1248 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1249 }
1250 return ret;
1251 }
1252
1253 // "router bgp X"
1254 else {
1255
1256 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1257 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1258 if (argc > 3) {
1259 name = argv[idx_vrf]->arg;
1260
1261 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1262 if (strmatch(name, VRF_DEFAULT_NAME))
1263 name = NULL;
1264 else
1265 inst_type = BGP_INSTANCE_TYPE_VRF;
1266 } else if (!strcmp(argv[idx_view_vrf]->text, "view")) {
1267 inst_type = BGP_INSTANCE_TYPE_VIEW;
1268 }
1269 }
1270 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_GLOBAL_XPATH,
1271 "frr-bgp:bgp", "bgp", name ? name : VRF_DEFAULT_NAME);
1272
1273 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
1274 nb_cli_enqueue_change(vty, "./global/local-as", NB_OP_MODIFY,
1275 argv[idx_asn]->arg);
1276 if (inst_type == BGP_INSTANCE_TYPE_VIEW) {
1277 nb_cli_enqueue_change(vty,
1278 "./global/instance-type-view",
1279 NB_OP_MODIFY, "true");
1280 }
1281
1282 nb_cli_pending_commit_check(vty);
1283 ret = nb_cli_apply_changes(vty, base_xpath);
1284 if (ret == CMD_SUCCESS) {
1285 VTY_PUSH_XPATH(BGP_NODE, base_xpath);
1286
1287 /*
1288 * For backward compatibility with old commands we still
1289 * need to use the qobj infrastructure.
1290 */
1291 bgp = bgp_lookup(as, name);
1292 if (bgp)
1293 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1294 }
1295 }
1296
1297 return ret;
1298 }
1299
1300 /* "no router bgp" commands. */
1301 DEFUN_YANG(no_router_bgp,
1302 no_router_bgp_cmd,
1303 "no router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1304 NO_STR ROUTER_STR BGP_STR AS_STR BGP_INSTANCE_HELP_STR)
1305 {
1306 int idx_asn = 3;
1307 int idx_vrf = 5;
1308 as_t as = 0;
1309 struct bgp *bgp;
1310 const char *name = NULL;
1311 char base_xpath[XPATH_MAXLEN];
1312 const struct lyd_node *bgp_glb_dnode;
1313
1314 // "no router bgp" without an ASN
1315 if (argc == 3) {
1316 // Pending: Make VRF option available for ASN less config
1317 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_GLOBAL_XPATH,
1318 "frr-bgp:bgp", "bgp", VRF_DEFAULT_NAME);
1319
1320 bgp_glb_dnode = yang_dnode_get(vty->candidate_config->dnode,
1321 base_xpath);
1322 if (!bgp_glb_dnode) {
1323 vty_out(vty, "%% No BGP process is configured\n");
1324 return CMD_WARNING_CONFIG_FAILED;
1325 }
1326
1327 if (listcount(bm->bgp) > 1) {
1328 vty_out(vty, "%% Please specify ASN and VRF\n");
1329 return CMD_WARNING_CONFIG_FAILED;
1330 }
1331
1332 /* tcli mode bgp would not be set until apply stage. */
1333 bgp = nb_running_get_entry(bgp_glb_dnode, NULL, false);
1334 if (!bgp)
1335 return CMD_SUCCESS;
1336
1337 if (bgp->l3vni) {
1338 vty_out(vty, "%% Please unconfigure l3vni %u",
1339 bgp->l3vni);
1340 return CMD_WARNING_CONFIG_FAILED;
1341 }
1342 } else {
1343 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1344
1345 if (argc > 4)
1346 name = argv[idx_vrf]->arg;
1347
1348 /* Lookup bgp structure. */
1349 bgp = bgp_lookup(as, name);
1350 if (!bgp) {
1351 vty_out(vty, "%% Can't find BGP instance\n");
1352 return CMD_WARNING_CONFIG_FAILED;
1353 }
1354
1355 if (bgp->l3vni) {
1356 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1357 bgp->l3vni);
1358 return CMD_WARNING_CONFIG_FAILED;
1359 }
1360
1361 /* Cannot delete default instance if vrf instances exist */
1362 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
1363 struct listnode *node;
1364 struct bgp *tmp_bgp;
1365
1366 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, tmp_bgp)) {
1367 if (tmp_bgp->inst_type
1368 == BGP_INSTANCE_TYPE_VRF) {
1369 vty_out(vty,
1370 "%% Cannot delete default BGP instance. Dependent VRF instances exist\n");
1371 return CMD_WARNING_CONFIG_FAILED;
1372 }
1373 }
1374 }
1375 }
1376 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_GLOBAL_XPATH,
1377 "frr-bgp:bgp", "bgp",
1378 bgp->name ? bgp->name : VRF_DEFAULT_NAME);
1379
1380 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
1381
1382 return nb_cli_apply_changes(vty, base_xpath);
1383 }
1384
1385 void cli_show_router_bgp(struct vty *vty, struct lyd_node *dnode,
1386 bool show_defaults)
1387 {
1388 const struct lyd_node *vrf_dnode;
1389 const char *vrf_name;
1390 as_t as;
1391
1392 vrf_dnode = yang_dnode_get_parent(dnode, "control-plane-protocol");
1393 vrf_name = yang_dnode_get_string(vrf_dnode, "./vrf");
1394 as = yang_dnode_get_uint32(dnode, "./global/local-as");
1395
1396 vty_out(vty, "!\n");
1397 vty_out(vty, "router bgp %u", as);
1398 if (!strmatch(vrf_name, VRF_DEFAULT_NAME))
1399 vty_out(vty, " vrf %s", vrf_name);
1400 vty_out(vty, "\n");
1401 }
1402
1403 /* BGP router-id. */
1404
1405 DEFPY_YANG(bgp_router_id, bgp_router_id_cmd, "bgp router-id A.B.C.D",
1406 BGP_STR
1407 "Override configured router identifier\n"
1408 "Manually configured router identifier\n")
1409 {
1410 nb_cli_enqueue_change(vty, "./global/router-id", NB_OP_MODIFY,
1411 router_id_str);
1412
1413 return nb_cli_apply_changes(vty, NULL);
1414 }
1415
1416 DEFPY_YANG(no_bgp_router_id, no_bgp_router_id_cmd, "no bgp router-id [A.B.C.D]",
1417 NO_STR BGP_STR
1418 "Override configured router identifier\n"
1419 "Manually configured router identifier\n")
1420 {
1421 nb_cli_enqueue_change(vty, "./global/router-id", NB_OP_DESTROY,
1422 router_id_str ? router_id_str : NULL);
1423
1424 return nb_cli_apply_changes(vty, NULL);
1425 }
1426
1427 void cli_show_router_bgp_router_id(struct vty *vty, struct lyd_node *dnode,
1428 bool show_defaults)
1429 {
1430 vty_out(vty, " bgp router-id %s\n", yang_dnode_get_string(dnode, NULL));
1431 }
1432
1433 /* BGP Cluster ID. */
1434 DEFUN_YANG(bgp_cluster_id,
1435 bgp_cluster_id_cmd,
1436 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1437 BGP_STR
1438 "Configure Route-Reflector Cluster-id\n"
1439 "Route-Reflector Cluster-id in IP address format\n"
1440 "Route-Reflector Cluster-id as 32 bit quantity\n")
1441 {
1442 int idx_ipv4 = 2;
1443
1444 nb_cli_enqueue_change(
1445 vty, "./global/route-reflector/route-reflector-cluster-id",
1446 NB_OP_MODIFY, argv[idx_ipv4]->arg);
1447
1448 return nb_cli_apply_changes(vty, NULL);
1449 }
1450
1451 DEFUN_YANG(no_bgp_cluster_id,
1452 no_bgp_cluster_id_cmd,
1453 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1454 NO_STR BGP_STR
1455 "Configure Route-Reflector Cluster-id\n"
1456 "Route-Reflector Cluster-id in IP address format\n"
1457 "Route-Reflector Cluster-id as 32 bit quantity\n")
1458 {
1459 nb_cli_enqueue_change(
1460 vty, "./global/route-reflector/route-reflector-cluster-id",
1461 NB_OP_DESTROY, NULL);
1462
1463 return nb_cli_apply_changes(vty, NULL);
1464 }
1465
1466 DEFPY (bgp_norib,
1467 bgp_norib_cmd,
1468 "bgp no-rib",
1469 BGP_STR
1470 "Disable BGP route installation to RIB (Zebra)\n")
1471 {
1472 if (bgp_option_check(BGP_OPT_NO_FIB)) {
1473 vty_out(vty,
1474 "%% No-RIB option is already set, nothing to do here.\n");
1475 return CMD_SUCCESS;
1476 }
1477
1478 bgp_option_norib_set_runtime();
1479
1480 return CMD_SUCCESS;
1481 }
1482
1483 DEFPY (no_bgp_norib,
1484 no_bgp_norib_cmd,
1485 "no bgp no-rib",
1486 NO_STR
1487 BGP_STR
1488 "Disable BGP route installation to RIB (Zebra)\n")
1489 {
1490 if (!bgp_option_check(BGP_OPT_NO_FIB)) {
1491 vty_out(vty,
1492 "%% No-RIB option is not set, nothing to do here.\n");
1493 return CMD_SUCCESS;
1494 }
1495
1496 bgp_option_norib_unset_runtime();
1497
1498 return CMD_SUCCESS;
1499 }
1500
1501 DEFUN_YANG(bgp_confederation_identifier,
1502 bgp_confederation_identifier_cmd,
1503 "bgp confederation identifier (1-4294967295)",
1504 "BGP specific commands\n"
1505 "AS confederation parameters\n"
1506 "AS number\n"
1507 "Set routing domain confederation AS\n")
1508 {
1509 int idx_number = 3;
1510
1511 nb_cli_enqueue_change(vty, "./global/confederation/identifier",
1512 NB_OP_MODIFY, argv[idx_number]->arg);
1513
1514 return nb_cli_apply_changes(vty, NULL);
1515 }
1516
1517 DEFUN_YANG(no_bgp_confederation_identifier,
1518 no_bgp_confederation_identifier_cmd,
1519 "no bgp confederation identifier [(1-4294967295)]",
1520 NO_STR
1521 "BGP specific commands\n"
1522 "AS confederation parameters\n"
1523 "AS number\n"
1524 "Set routing domain confederation AS\n")
1525 {
1526 nb_cli_enqueue_change(vty, "./global/confederation/identifier",
1527 NB_OP_DESTROY, NULL);
1528
1529 return nb_cli_apply_changes(vty, NULL);
1530 }
1531
1532 void cli_show_router_bgp_confederation_identifier(struct vty *vty,
1533 struct lyd_node *dnode,
1534 bool show_defaults)
1535 {
1536 vty_out(vty, " bgp confederation identifier %u\n",
1537 yang_dnode_get_uint32(dnode, NULL));
1538 }
1539
1540 DEFUN_YANG(bgp_confederation_peers,
1541 bgp_confederation_peers_cmd,
1542 "bgp confederation peers (1-4294967295)...",
1543 "BGP specific commands\n"
1544 "AS confederation parameters\n"
1545 "Peer ASs in BGP confederation\n" AS_STR)
1546 {
1547 int idx_asn = 3;
1548 int i;
1549
1550 for (i = idx_asn; i < argc; i++)
1551 nb_cli_enqueue_change(vty, "./global/confederation/member-as",
1552 NB_OP_CREATE, argv[i]->arg);
1553
1554 return nb_cli_apply_changes(vty, NULL);
1555 }
1556
1557 DEFUN_YANG(no_bgp_confederation_peers,
1558 no_bgp_confederation_peers_cmd,
1559 "no bgp confederation peers (1-4294967295)...",
1560 NO_STR
1561 "BGP specific commands\n"
1562 "AS confederation parameters\n"
1563 "Peer ASs in BGP confederation\n" AS_STR)
1564 {
1565 int idx_asn = 4;
1566 int i;
1567
1568 for (i = idx_asn; i < argc; i++)
1569 nb_cli_enqueue_change(vty, "./global/confederation/member-as",
1570 NB_OP_DESTROY, argv[i]->arg);
1571
1572 return nb_cli_apply_changes(vty, NULL);
1573 }
1574
1575 void cli_show_router_bgp_confederation_member_as(struct vty *vty,
1576 struct lyd_node *dnode,
1577 bool show_defaults)
1578 {
1579 vty_out(vty, " bgp confederation peers %u \n",
1580 yang_dnode_get_uint32(dnode, NULL));
1581 }
1582
1583 /**
1584 * Central routine for maximum-paths configuration.
1585 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1586 * @set: 1 for setting values, 0 for removing the max-paths config.
1587 */
1588 static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
1589 const char *mpaths, uint16_t options,
1590 int set)
1591 {
1592 VTY_DECLVAR_CONTEXT(bgp, bgp);
1593 uint16_t maxpaths = 0;
1594 int ret;
1595 afi_t afi;
1596 safi_t safi;
1597
1598 afi = bgp_node_afi(vty);
1599 safi = bgp_node_safi(vty);
1600
1601 if (set) {
1602 maxpaths = strtol(mpaths, NULL, 10);
1603 if (maxpaths > multipath_num) {
1604 vty_out(vty,
1605 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1606 maxpaths, multipath_num);
1607 return CMD_WARNING_CONFIG_FAILED;
1608 }
1609 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1610 options);
1611 } else
1612 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1613
1614 if (ret < 0) {
1615 vty_out(vty,
1616 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1617 (set == 1) ? "" : "un",
1618 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1619 maxpaths, afi, safi);
1620 return CMD_WARNING_CONFIG_FAILED;
1621 }
1622
1623 bgp_recalculate_all_bestpaths(bgp);
1624
1625 return CMD_SUCCESS;
1626 }
1627
1628 void cli_show_router_bgp_med_config(struct vty *vty, struct lyd_node *dnode,
1629 bool show_defaults)
1630 {
1631 if (yang_dnode_get_bool(dnode, "./enable-med-admin")) {
1632 uint32_t med_admin_val;
1633
1634 vty_out(vty, " bgp max-med administrative");
1635 if ((med_admin_val =
1636 yang_dnode_get_uint32(dnode, "./max-med-admin"))
1637 != BGP_MAXMED_VALUE_DEFAULT)
1638 vty_out(vty, " %u", med_admin_val);
1639 vty_out(vty, "\n");
1640 }
1641
1642 if (yang_dnode_exists(dnode, "./max-med-onstart-up-time")) {
1643 uint32_t onstartup_val;
1644
1645 vty_out(vty, " bgp max-med on-startup %u",
1646 yang_dnode_get_uint32(dnode,
1647 "./max-med-onstart-up-time"));
1648 onstartup_val = yang_dnode_get_uint32(
1649 dnode, "./max-med-onstart-up-value");
1650 if (onstartup_val != BGP_MAXMED_VALUE_DEFAULT)
1651 vty_out(vty, " %u", onstartup_val);
1652
1653 vty_out(vty, "\n");
1654 }
1655 }
1656
1657 DEFUN_YANG(bgp_maxmed_admin,
1658 bgp_maxmed_admin_cmd,
1659 "bgp max-med administrative ",
1660 BGP_STR
1661 "Advertise routes with max-med\n"
1662 "Administratively applied, for an indefinite period\n")
1663 {
1664 nb_cli_enqueue_change(vty, "./global/med-config/enable-med-admin",
1665 NB_OP_MODIFY, "true");
1666
1667 return nb_cli_apply_changes(vty, NULL);
1668 }
1669
1670 DEFUN_YANG(bgp_maxmed_admin_medv,
1671 bgp_maxmed_admin_medv_cmd,
1672 "bgp max-med administrative (0-4294967295)",
1673 BGP_STR
1674 "Advertise routes with max-med\n"
1675 "Administratively applied, for an indefinite period\n"
1676 "Max MED value to be used\n")
1677 {
1678 int idx_number = 3;
1679
1680 nb_cli_enqueue_change(vty, "./global/med-config/enable-med-admin",
1681 NB_OP_MODIFY, "true");
1682
1683 nb_cli_enqueue_change(vty, "./global/med-config/max-med-admin",
1684 NB_OP_MODIFY, argv[idx_number]->arg);
1685
1686 return nb_cli_apply_changes(vty, NULL);
1687 }
1688
1689 DEFUN_YANG(no_bgp_maxmed_admin,
1690 no_bgp_maxmed_admin_cmd,
1691 "no bgp max-med administrative [(0-4294967295)]",
1692 NO_STR BGP_STR
1693 "Advertise routes with max-med\n"
1694 "Administratively applied, for an indefinite period\n"
1695 "Max MED value to be used\n")
1696 {
1697 nb_cli_enqueue_change(vty, "./global/med-config/enable-med-admin",
1698 NB_OP_MODIFY, "false");
1699
1700 nb_cli_enqueue_change(vty, "./global/med-config/max-med-admin",
1701 NB_OP_MODIFY, NULL);
1702
1703 return nb_cli_apply_changes(vty, NULL);
1704 }
1705
1706 DEFUN_YANG(bgp_maxmed_onstartup,
1707 bgp_maxmed_onstartup_cmd,
1708 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
1709 BGP_STR
1710 "Advertise routes with max-med\n"
1711 "Effective on a startup\n"
1712 "Time (seconds) period for max-med\n"
1713 "Max MED value to be used\n")
1714 {
1715 int idx = 0;
1716
1717 argv_find(argv, argc, "(5-86400)", &idx);
1718 nb_cli_enqueue_change(vty,
1719 "./global/med-config/max-med-onstart-up-time",
1720 NB_OP_MODIFY, argv[idx]->arg);
1721
1722 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1723 nb_cli_enqueue_change(
1724 vty, "./global/med-config/max-med-onstart-up-value",
1725 NB_OP_MODIFY, argv[idx]->arg);
1726 else
1727 nb_cli_enqueue_change(
1728 vty, "./global/med-config/max-med-onstart-up-value",
1729 NB_OP_MODIFY, NULL);
1730
1731 return nb_cli_apply_changes(vty, NULL);
1732 }
1733
1734 DEFUN_YANG(no_bgp_maxmed_onstartup,
1735 no_bgp_maxmed_onstartup_cmd,
1736 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
1737 NO_STR BGP_STR
1738 "Advertise routes with max-med\n"
1739 "Effective on a startup\n"
1740 "Time (seconds) period for max-med\n"
1741 "Max MED value to be used\n")
1742 {
1743 nb_cli_enqueue_change(vty,
1744 "./global/med-config/max-med-onstart-up-time",
1745 NB_OP_DESTROY, NULL);
1746
1747 nb_cli_enqueue_change(vty,
1748 "./global/med-config/max-med-onstart-up-value",
1749 NB_OP_MODIFY, NULL);
1750
1751 return nb_cli_apply_changes(vty, NULL);
1752 }
1753
1754 static int bgp_global_update_delay_config_vty(struct vty *vty,
1755 uint16_t update_delay,
1756 uint16_t establish_wait)
1757 {
1758 struct listnode *node, *nnode;
1759 struct bgp *bgp;
1760 bool vrf_cfg = false;
1761
1762 /*
1763 * See if update-delay is set per-vrf and warn user to delete it
1764 * Note that we only need to check this if this is the first time
1765 * setting the global config.
1766 */
1767 if (bm->v_update_delay == BGP_UPDATE_DELAY_DEF) {
1768 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
1769 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1770 vty_out(vty,
1771 "%% update-delay configuration found in vrf %s\n",
1772 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT
1773 ? VRF_DEFAULT_NAME
1774 : bgp->name);
1775 vrf_cfg = true;
1776 }
1777 }
1778 }
1779
1780 if (vrf_cfg) {
1781 vty_out(vty,
1782 "%%Failed: global update-delay config not permitted\n");
1783 return CMD_WARNING;
1784 }
1785
1786 if (!establish_wait) { /* update-delay <delay> */
1787 bm->v_update_delay = update_delay;
1788 bm->v_establish_wait = bm->v_update_delay;
1789 } else {
1790 /* update-delay <delay> <establish-wait> */
1791 if (update_delay < establish_wait) {
1792 vty_out(vty,
1793 "%%Failed: update-delay less than the establish-wait!\n");
1794 return CMD_WARNING_CONFIG_FAILED;
1795 }
1796
1797 bm->v_update_delay = update_delay;
1798 bm->v_establish_wait = establish_wait;
1799 }
1800
1801 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
1802 bgp->v_update_delay = bm->v_update_delay;
1803 bgp->v_establish_wait = bm->v_establish_wait;
1804 }
1805
1806 return CMD_SUCCESS;
1807 }
1808
1809 static int bgp_global_update_delay_deconfig_vty(struct vty *vty)
1810 {
1811 struct listnode *node, *nnode;
1812 struct bgp *bgp;
1813
1814 bm->v_update_delay = BGP_UPDATE_DELAY_DEF;
1815 bm->v_establish_wait = bm->v_update_delay;
1816
1817 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
1818 bgp->v_update_delay = bm->v_update_delay;
1819 bgp->v_establish_wait = bm->v_establish_wait;
1820 }
1821
1822 return CMD_SUCCESS;
1823 }
1824
1825 static int bgp_update_delay_config_vty(struct vty *vty, uint16_t update_delay,
1826 uint16_t establish_wait)
1827 {
1828 VTY_DECLVAR_CONTEXT(bgp, bgp);
1829
1830 /* if configured globally, per-instance config is not allowed */
1831 if (bm->v_update_delay) {
1832 vty_out(vty,
1833 "%%Failed: per-vrf update-delay config not permitted with global update-delay\n");
1834 return CMD_WARNING_CONFIG_FAILED;
1835 }
1836
1837
1838 if (!establish_wait) /* update-delay <delay> */
1839 {
1840 bgp->v_update_delay = update_delay;
1841 bgp->v_establish_wait = bgp->v_update_delay;
1842 return CMD_SUCCESS;
1843 }
1844
1845 /* update-delay <delay> <establish-wait> */
1846 if (update_delay < establish_wait) {
1847 vty_out(vty,
1848 "%%Failed: update-delay less than the establish-wait!\n");
1849 return CMD_WARNING_CONFIG_FAILED;
1850 }
1851
1852 bgp->v_update_delay = update_delay;
1853 bgp->v_establish_wait = establish_wait;
1854
1855 return CMD_SUCCESS;
1856 }
1857
1858 static int bgp_update_delay_deconfig_vty(struct vty *vty)
1859 {
1860 VTY_DECLVAR_CONTEXT(bgp, bgp);
1861
1862 /* If configured globally, cannot remove from one bgp instance */
1863 if (bm->v_update_delay) {
1864 vty_out(vty,
1865 "%%Failed: bgp update-delay configured globally. Delete per-vrf not permitted\n");
1866 return CMD_WARNING_CONFIG_FAILED;
1867 }
1868 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
1869 bgp->v_establish_wait = bgp->v_update_delay;
1870
1871 return CMD_SUCCESS;
1872 }
1873
1874 void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
1875 {
1876 /* If configured globally, no need to display per-instance value */
1877 if (bgp->v_update_delay != bm->v_update_delay) {
1878 vty_out(vty, " update-delay %d", bgp->v_update_delay);
1879 if (bgp->v_update_delay != bgp->v_establish_wait)
1880 vty_out(vty, " %d", bgp->v_establish_wait);
1881 vty_out(vty, "\n");
1882 }
1883 }
1884
1885 /* Global update-delay configuration */
1886 DEFPY (bgp_global_update_delay,
1887 bgp_global_update_delay_cmd,
1888 "bgp update-delay (0-3600)$delay [(1-3600)$wait]",
1889 BGP_STR
1890 "Force initial delay for best-path and updates for all bgp instances\n"
1891 "Max delay in seconds\n"
1892 "Establish wait in seconds\n")
1893 {
1894 return bgp_global_update_delay_config_vty(vty, delay, wait);
1895 }
1896
1897 /* Global update-delay deconfiguration */
1898 DEFPY (no_bgp_global_update_delay,
1899 no_bgp_global_update_delay_cmd,
1900 "no bgp update-delay [(0-3600) [(1-3600)]]",
1901 NO_STR
1902 BGP_STR
1903 "Force initial delay for best-path and updates\n"
1904 "Max delay in seconds\n"
1905 "Establish wait in seconds\n")
1906 {
1907 return bgp_global_update_delay_deconfig_vty(vty);
1908 }
1909
1910 /* Update-delay configuration */
1911
1912 DEFPY (bgp_update_delay,
1913 bgp_update_delay_cmd,
1914 "update-delay (0-3600)$delay [(1-3600)$wait]",
1915 "Force initial delay for best-path and updates\n"
1916 "Max delay in seconds\n"
1917 "Establish wait in seconds\n")
1918 {
1919 return bgp_update_delay_config_vty(vty, delay, wait);
1920 }
1921
1922 /* Update-delay deconfiguration */
1923 DEFPY (no_bgp_update_delay,
1924 no_bgp_update_delay_cmd,
1925 "no update-delay [(0-3600) [(1-3600)]]",
1926 NO_STR
1927 "Force initial delay for best-path and updates\n"
1928 "Max delay in seconds\n"
1929 "Establish wait in seconds\n")
1930 {
1931 return bgp_update_delay_deconfig_vty(vty);
1932 }
1933
1934
1935 int bgp_wpkt_quanta_config_vty(struct bgp *bgp, uint32_t quanta, bool set)
1936 {
1937 quanta = set ? quanta : BGP_WRITE_PACKET_MAX;
1938 atomic_store_explicit(&bgp->wpkt_quanta, quanta, memory_order_relaxed);
1939
1940 return CMD_SUCCESS;
1941 }
1942
1943 int bgp_rpkt_quanta_config_vty(struct bgp *bgp, uint32_t quanta, bool set)
1944 {
1945 quanta = set ? quanta : BGP_READ_PACKET_MAX;
1946 atomic_store_explicit(&bgp->rpkt_quanta, quanta, memory_order_relaxed);
1947
1948 return CMD_SUCCESS;
1949 }
1950
1951 void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
1952 {
1953 uint32_t quanta =
1954 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
1955 if (quanta != BGP_WRITE_PACKET_MAX)
1956 vty_out(vty, " write-quanta %d\n", quanta);
1957 }
1958
1959 void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
1960 {
1961 uint32_t quanta =
1962 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
1963 if (quanta != BGP_READ_PACKET_MAX)
1964 vty_out(vty, " read-quanta %d\n", quanta);
1965 }
1966
1967 /* Packet quanta configuration
1968 *
1969 * XXX: The value set here controls the size of a stack buffer in the IO
1970 * thread. When changing these limits be careful to prevent stack overflow.
1971 *
1972 * Furthermore, the maximums used here should correspond to
1973 * BGP_WRITE_PACKET_MAX and BGP_READ_PACKET_MAX.
1974 */
1975 DEFPY_YANG(bgp_wpkt_quanta,
1976 bgp_wpkt_quanta_cmd,
1977 "[no] write-quanta (1-64)$quanta",
1978 NO_STR
1979 "How many packets to write to peer socket per run\n"
1980 "Number of packets\n")
1981 {
1982 if (!no)
1983 nb_cli_enqueue_change(
1984 vty,
1985 "./global/global-neighbor-config/packet-quanta-config/wpkt-quanta",
1986 NB_OP_MODIFY, quanta_str);
1987 else
1988 nb_cli_enqueue_change(
1989 vty,
1990 "./global/global-neighbor-config/packet-quanta-config/wpkt-quanta",
1991 NB_OP_MODIFY, NULL);
1992
1993 return nb_cli_apply_changes(vty, NULL);
1994 }
1995
1996 DEFPY_YANG(bgp_rpkt_quanta,
1997 bgp_rpkt_quanta_cmd,
1998 "[no] read-quanta (1-10)$quanta",
1999 NO_STR
2000 "How many packets to read from peer socket per I/O cycle\n"
2001 "Number of packets\n")
2002 {
2003 if (!no)
2004 nb_cli_enqueue_change(
2005 vty,
2006 "./global/global-neighbor-config/packet-quanta-config/rpkt-quanta",
2007 NB_OP_MODIFY, quanta_str);
2008 else
2009 nb_cli_enqueue_change(
2010 vty,
2011 "./global/global-neighbor-config/packet-quanta-config/rpkt-quanta",
2012 NB_OP_MODIFY, NULL);
2013
2014 return nb_cli_apply_changes(vty, NULL);
2015 }
2016
2017 void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
2018 {
2019 if (!bgp->heuristic_coalesce)
2020 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
2021 }
2022
2023 void cli_show_router_global_update_group_config_coalesce_time(
2024 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
2025 {
2026 vty_out(vty, " coalesce-time %u\n", yang_dnode_get_uint32(dnode, NULL));
2027 }
2028
2029
2030 DEFUN_YANG(bgp_coalesce_time,
2031 bgp_coalesce_time_cmd,
2032 "coalesce-time (0-4294967295)",
2033 "Subgroup coalesce timer\n"
2034 "Subgroup coalesce timer value (in ms)\n")
2035 {
2036 int idx = 0;
2037
2038 argv_find(argv, argc, "(0-4294967295)", &idx);
2039 nb_cli_enqueue_change(
2040 vty, "./global/global-update-group-config/coalesce-time",
2041 NB_OP_MODIFY, argv[idx]->arg);
2042
2043 return nb_cli_apply_changes(vty, NULL);
2044 }
2045
2046 DEFUN_YANG(no_bgp_coalesce_time,
2047 no_bgp_coalesce_time_cmd,
2048 "no coalesce-time (0-4294967295)",
2049 NO_STR
2050 "Subgroup coalesce timer\n"
2051 "Subgroup coalesce timer value (in ms)\n")
2052 {
2053 nb_cli_enqueue_change(
2054 vty, "./global/global-update-group-config/coalesce-time",
2055 NB_OP_MODIFY, NULL);
2056
2057 return nb_cli_apply_changes(vty, NULL);
2058 }
2059
2060 /* Maximum-paths configuration */
2061 DEFUN (bgp_maxpaths,
2062 bgp_maxpaths_cmd,
2063 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2064 "Forward packets over multiple paths\n"
2065 "Number of paths\n")
2066 {
2067 int idx_number = 1;
2068 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
2069 argv[idx_number]->arg, 0, 1);
2070 }
2071
2072 ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
2073 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2074 "Forward packets over multiple paths\n"
2075 "Number of paths\n")
2076
2077 DEFUN (bgp_maxpaths_ibgp,
2078 bgp_maxpaths_ibgp_cmd,
2079 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2080 "Forward packets over multiple paths\n"
2081 "iBGP-multipath\n"
2082 "Number of paths\n")
2083 {
2084 int idx_number = 2;
2085 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
2086 argv[idx_number]->arg, 0, 1);
2087 }
2088
2089 ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
2090 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2091 "Forward packets over multiple paths\n"
2092 "iBGP-multipath\n"
2093 "Number of paths\n")
2094
2095 DEFUN (bgp_maxpaths_ibgp_cluster,
2096 bgp_maxpaths_ibgp_cluster_cmd,
2097 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
2098 "Forward packets over multiple paths\n"
2099 "iBGP-multipath\n"
2100 "Number of paths\n"
2101 "Match the cluster length\n")
2102 {
2103 int idx_number = 2;
2104 return bgp_maxpaths_config_vty(
2105 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
2106 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
2107 }
2108
2109 ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
2110 "maximum-paths ibgp " CMD_RANGE_STR(
2111 1, MULTIPATH_NUM) " equal-cluster-length",
2112 "Forward packets over multiple paths\n"
2113 "iBGP-multipath\n"
2114 "Number of paths\n"
2115 "Match the cluster length\n")
2116
2117 DEFUN (no_bgp_maxpaths,
2118 no_bgp_maxpaths_cmd,
2119 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
2120 NO_STR
2121 "Forward packets over multiple paths\n"
2122 "Number of paths\n")
2123 {
2124 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
2125 }
2126
2127 ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
2128 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
2129 "Forward packets over multiple paths\n"
2130 "Number of paths\n")
2131
2132 DEFUN (no_bgp_maxpaths_ibgp,
2133 no_bgp_maxpaths_ibgp_cmd,
2134 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
2135 NO_STR
2136 "Forward packets over multiple paths\n"
2137 "iBGP-multipath\n"
2138 "Number of paths\n"
2139 "Match the cluster length\n")
2140 {
2141 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
2142 }
2143
2144 ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
2145 "no maximum-paths ibgp [" CMD_RANGE_STR(
2146 1, MULTIPATH_NUM) " [equal-cluster-length]]",
2147 NO_STR
2148 "Forward packets over multiple paths\n"
2149 "iBGP-multipath\n"
2150 "Number of paths\n"
2151 "Match the cluster length\n")
2152
2153 static void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp,
2154 afi_t afi, safi_t safi)
2155 {
2156 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != MULTIPATH_NUM) {
2157 vty_out(vty, " maximum-paths %d\n",
2158 bgp->maxpaths[afi][safi].maxpaths_ebgp);
2159 }
2160
2161 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != MULTIPATH_NUM) {
2162 vty_out(vty, " maximum-paths ibgp %d",
2163 bgp->maxpaths[afi][safi].maxpaths_ibgp);
2164 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
2165 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
2166 vty_out(vty, " equal-cluster-length");
2167 vty_out(vty, "\n");
2168 }
2169 }
2170
2171 /* BGP timers. */
2172
2173 DEFUN_YANG(bgp_timers,
2174 bgp_timers_cmd,
2175 "timers bgp (0-65535) (0-65535)",
2176 "Adjust routing timers\n"
2177 "BGP timers\n"
2178 "Keepalive interval\n"
2179 "Holdtime\n")
2180 {
2181 int idx_number = 2;
2182 int idx_number_2 = 3;
2183
2184 nb_cli_enqueue_change(vty, "./global/global-config-timers/keepalive",
2185 NB_OP_MODIFY, argv[idx_number]->arg);
2186 nb_cli_enqueue_change(vty, "./global/global-config-timers/hold-time",
2187 NB_OP_MODIFY, argv[idx_number_2]->arg);
2188
2189 return nb_cli_apply_changes(vty, NULL);
2190 }
2191
2192 DEFUN_YANG(no_bgp_timers,
2193 no_bgp_timers_cmd,
2194 "no timers bgp [(0-65535) (0-65535)]",
2195 NO_STR
2196 "Adjust routing timers\n"
2197 "BGP timers\n"
2198 "Keepalive interval\n"
2199 "Holdtime\n")
2200 {
2201 nb_cli_enqueue_change(vty, "./global/global-config-timers/keepalive",
2202 NB_OP_DESTROY, NULL);
2203 nb_cli_enqueue_change(vty, "./global/global-config-timers/hold-time",
2204 NB_OP_DESTROY, NULL);
2205
2206 return nb_cli_apply_changes(vty, NULL);
2207 }
2208
2209 void cli_show_router_bgp_route_reflector(struct vty *vty,
2210 struct lyd_node *dnode,
2211 bool show_defaults)
2212 {
2213 if (yang_dnode_get_bool(dnode, "./no-client-reflect"))
2214 vty_out(vty, " no bgp client-to-client reflection\n");
2215
2216 if (yang_dnode_get_bool(dnode, "./allow-outbound-policy"))
2217 vty_out(vty, " bgp route-reflector allow-outbound-policy\n");
2218
2219 if (yang_dnode_exists(dnode, "./route-reflector-cluster-id"))
2220 vty_out(vty, " bgp cluster-id %s\n",
2221 yang_dnode_get_string(dnode,
2222 "./route-reflector-cluster-id"));
2223 }
2224
2225 DEFUN_YANG(bgp_client_to_client_reflection,
2226 bgp_client_to_client_reflection_cmd,
2227 "bgp client-to-client reflection",
2228 "BGP specific commands\n"
2229 "Configure client to client route reflection\n"
2230 "reflection of routes allowed\n")
2231 {
2232 nb_cli_enqueue_change(vty, "./global/route-reflector/no-client-reflect",
2233 NB_OP_MODIFY, "false");
2234
2235 return nb_cli_apply_changes(vty, NULL);
2236 }
2237
2238 DEFUN_YANG(no_bgp_client_to_client_reflection,
2239 no_bgp_client_to_client_reflection_cmd,
2240 "no bgp client-to-client reflection",
2241 NO_STR
2242 "BGP specific commands\n"
2243 "Configure client to client route reflection\n"
2244 "reflection of routes allowed\n")
2245 {
2246 nb_cli_enqueue_change(vty, "./global/route-reflector/no-client-reflect",
2247 NB_OP_MODIFY, "true");
2248
2249 return nb_cli_apply_changes(vty, NULL);
2250 }
2251
2252 void cli_show_router_bgp_route_selection(struct vty *vty,
2253 struct lyd_node *dnode,
2254 bool show_defaults)
2255 {
2256
2257 if (yang_dnode_get_bool(dnode, "./always-compare-med"))
2258 vty_out(vty, " bgp always-compare-med\n");
2259
2260 if (yang_dnode_get_bool(dnode, "./ignore-as-path-length"))
2261 vty_out(vty, " bgp bestpath as-path ignore\n");
2262
2263 if (yang_dnode_get_bool(dnode, "./aspath-confed"))
2264 vty_out(vty, " bgp bestpath as-path confed\n");
2265
2266 if (yang_dnode_get_bool(dnode, "./external-compare-router-id"))
2267 vty_out(vty, " bgp bestpath compare-routerid\n");
2268
2269 if (yang_dnode_get_bool(dnode, "./allow-multiple-as")) {
2270 if (yang_dnode_get_bool(dnode, "./multi-path-as-set"))
2271 vty_out(vty,
2272 " bgp bestpath as-path multipath-relax as-set\n");
2273 else
2274 vty_out(vty, " bgp bestpath as-path multipath-relax\n");
2275 }
2276
2277 if (yang_dnode_get_bool(dnode, "./deterministic-med"))
2278 vty_out(vty, " bgp deterministic-med\n");
2279
2280 if (yang_dnode_get_bool(dnode, "./confed-med")
2281 || yang_dnode_get_bool(dnode, "./missing-as-worst-med")) {
2282 vty_out(vty, " bgp bestpath med");
2283 if (yang_dnode_get_bool(dnode, "./confed-med"))
2284 vty_out(vty, " confed");
2285 if (yang_dnode_get_bool(dnode, "./missing-as-worst-med"))
2286 vty_out(vty, " missing-as-worst");
2287 vty_out(vty, "\n");
2288 }
2289 }
2290
2291 /* "bgp always-compare-med" configuration. */
2292 DEFUN_YANG(bgp_always_compare_med,
2293 bgp_always_compare_med_cmd,
2294 "bgp always-compare-med",
2295 "BGP specific commands\n"
2296 "Allow comparing MED from different neighbors\n")
2297 {
2298 nb_cli_enqueue_change(
2299 vty, "./global/route-selection-options/always-compare-med",
2300 NB_OP_MODIFY, "true");
2301
2302 return nb_cli_apply_changes(vty, NULL);
2303 }
2304
2305 DEFUN_YANG(no_bgp_always_compare_med,
2306 no_bgp_always_compare_med_cmd,
2307 "no bgp always-compare-med",
2308 NO_STR
2309 "BGP specific commands\n"
2310 "Allow comparing MED from different neighbors\n")
2311 {
2312 nb_cli_enqueue_change(
2313 vty, "./global/route-selection-options/always-compare-med",
2314 NB_OP_MODIFY, "false");
2315
2316 return nb_cli_apply_changes(vty, NULL);
2317 }
2318
2319 DEFUN_YANG(bgp_ebgp_requires_policy,
2320 bgp_ebgp_requires_policy_cmd,
2321 "bgp ebgp-requires-policy",
2322 "BGP specific commands\n"
2323 "Require in and out policy for eBGP peers (RFC8212)\n")
2324 {
2325 nb_cli_enqueue_change(vty, "./global/ebgp-requires-policy",
2326 NB_OP_MODIFY, "true");
2327 return nb_cli_apply_changes(vty, NULL);
2328 }
2329
2330 DEFUN_YANG(no_bgp_ebgp_requires_policy,
2331 no_bgp_ebgp_requires_policy_cmd,
2332 "no bgp ebgp-requires-policy",
2333 NO_STR
2334 "BGP specific commands\n"
2335 "Require in and out policy for eBGP peers (RFC8212)\n")
2336 {
2337 nb_cli_enqueue_change(vty, "./global/ebgp-requires-policy",
2338 NB_OP_MODIFY, "false");
2339 return nb_cli_apply_changes(vty, NULL);
2340 }
2341
2342 void cli_show_router_bgp_ebgp_requires_policy(struct vty *vty,
2343 struct lyd_node *dnode,
2344 bool show_defaults)
2345 {
2346 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_EBGP_REQUIRES_POLICY)
2347 vty_out(vty, " bgp ebgp-requires-policy\n");
2348 }
2349
2350 DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd,
2351 "bgp reject-as-sets",
2352 "BGP specific commands\n"
2353 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2354 {
2355 VTY_DECLVAR_CONTEXT(bgp, bgp);
2356 struct listnode *node, *nnode;
2357 struct peer *peer;
2358
2359 bgp->reject_as_sets = true;
2360
2361 /* Reset existing BGP sessions to reject routes
2362 * with aspath containing AS_SET or AS_CONFED_SET.
2363 */
2364 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2365 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2366 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2367 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2368 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2369 }
2370 }
2371
2372 return CMD_SUCCESS;
2373 }
2374
2375 DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd,
2376 "no bgp reject-as-sets",
2377 NO_STR
2378 "BGP specific commands\n"
2379 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2380 {
2381 VTY_DECLVAR_CONTEXT(bgp, bgp);
2382 struct listnode *node, *nnode;
2383 struct peer *peer;
2384
2385 bgp->reject_as_sets = false;
2386
2387 /* Reset existing BGP sessions to reject routes
2388 * with aspath containing AS_SET or AS_CONFED_SET.
2389 */
2390 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2391 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2392 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2393 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2394 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2395 }
2396 }
2397
2398 return CMD_SUCCESS;
2399 }
2400
2401 /* "bgp deterministic-med" configuration. */
2402 DEFUN_YANG (bgp_deterministic_med,
2403 bgp_deterministic_med_cmd,
2404 "bgp deterministic-med",
2405 "BGP specific commands\n"
2406 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2407 {
2408 nb_cli_enqueue_change(
2409 vty, "./global/route-selection-options/deterministic-med",
2410 NB_OP_MODIFY, "true");
2411
2412 return nb_cli_apply_changes(vty, NULL);
2413 }
2414
2415 DEFUN_YANG (no_bgp_deterministic_med,
2416 no_bgp_deterministic_med_cmd,
2417 "no bgp deterministic-med",
2418 NO_STR
2419 "BGP specific commands\n"
2420 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2421 {
2422 nb_cli_enqueue_change(
2423 vty, "./global/route-selection-options/deterministic-med",
2424 NB_OP_MODIFY, "false");
2425
2426 return nb_cli_apply_changes(vty, NULL);
2427 }
2428
2429 /* "bgp graceful-restart mode" configuration. */
2430 DEFUN (bgp_graceful_restart,
2431 bgp_graceful_restart_cmd,
2432 "bgp graceful-restart",
2433 "BGP specific commands\n"
2434 GR_CMD
2435 )
2436 {
2437 int ret = BGP_GR_FAILURE;
2438
2439 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2440 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : START ");
2441
2442 VTY_DECLVAR_CONTEXT(bgp, bgp);
2443
2444 ret = bgp_gr_update_all(bgp, GLOBAL_GR_CMD);
2445
2446 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2447 ret);
2448
2449 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2450 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : END ");
2451 vty_out(vty,
2452 "Graceful restart configuration changed, reset all peers to take effect\n");
2453 return bgp_vty_return(vty, ret);
2454 }
2455
2456 DEFUN (no_bgp_graceful_restart,
2457 no_bgp_graceful_restart_cmd,
2458 "no bgp graceful-restart",
2459 NO_STR
2460 "BGP specific commands\n"
2461 NO_GR_CMD
2462 )
2463 {
2464 VTY_DECLVAR_CONTEXT(bgp, bgp);
2465
2466 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2467 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : START ");
2468
2469 int ret = BGP_GR_FAILURE;
2470
2471 ret = bgp_gr_update_all(bgp, NO_GLOBAL_GR_CMD);
2472
2473 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2474 ret);
2475
2476 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2477 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : END ");
2478 vty_out(vty,
2479 "Graceful restart configuration changed, reset all peers to take effect\n");
2480
2481 return bgp_vty_return(vty, ret);
2482 }
2483
2484 DEFUN (bgp_graceful_restart_stalepath_time,
2485 bgp_graceful_restart_stalepath_time_cmd,
2486 "bgp graceful-restart stalepath-time (1-4095)",
2487 "BGP specific commands\n"
2488 "Graceful restart capability parameters\n"
2489 "Set the max time to hold onto restarting peer's stale paths\n"
2490 "Delay value (seconds)\n")
2491 {
2492 VTY_DECLVAR_CONTEXT(bgp, bgp);
2493 int idx_number = 3;
2494 uint32_t stalepath;
2495
2496 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2497 bgp->stalepath_time = stalepath;
2498 return CMD_SUCCESS;
2499 }
2500
2501 DEFUN (bgp_graceful_restart_restart_time,
2502 bgp_graceful_restart_restart_time_cmd,
2503 "bgp graceful-restart restart-time (1-4095)",
2504 "BGP specific commands\n"
2505 "Graceful restart capability parameters\n"
2506 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2507 "Delay value (seconds)\n")
2508 {
2509 VTY_DECLVAR_CONTEXT(bgp, bgp);
2510 int idx_number = 3;
2511 uint32_t restart;
2512
2513 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2514 bgp->restart_time = restart;
2515 return CMD_SUCCESS;
2516 }
2517
2518 DEFUN (bgp_graceful_restart_select_defer_time,
2519 bgp_graceful_restart_select_defer_time_cmd,
2520 "bgp graceful-restart select-defer-time (0-3600)",
2521 "BGP specific commands\n"
2522 "Graceful restart capability parameters\n"
2523 "Set the time to defer the BGP route selection after restart\n"
2524 "Delay value (seconds, 0 - disable)\n")
2525 {
2526 VTY_DECLVAR_CONTEXT(bgp, bgp);
2527 int idx_number = 3;
2528 uint32_t defer_time;
2529
2530 defer_time = strtoul(argv[idx_number]->arg, NULL, 10);
2531 bgp->select_defer_time = defer_time;
2532 if (defer_time == 0)
2533 SET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2534 else
2535 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2536
2537 return CMD_SUCCESS;
2538 }
2539
2540 DEFUN (no_bgp_graceful_restart_stalepath_time,
2541 no_bgp_graceful_restart_stalepath_time_cmd,
2542 "no bgp graceful-restart stalepath-time [(1-4095)]",
2543 NO_STR
2544 "BGP specific commands\n"
2545 "Graceful restart capability parameters\n"
2546 "Set the max time to hold onto restarting peer's stale paths\n"
2547 "Delay value (seconds)\n")
2548 {
2549 VTY_DECLVAR_CONTEXT(bgp, bgp);
2550
2551 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2552 return CMD_SUCCESS;
2553 }
2554
2555 DEFUN (no_bgp_graceful_restart_restart_time,
2556 no_bgp_graceful_restart_restart_time_cmd,
2557 "no bgp graceful-restart restart-time [(1-4095)]",
2558 NO_STR
2559 "BGP specific commands\n"
2560 "Graceful restart capability parameters\n"
2561 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2562 "Delay value (seconds)\n")
2563 {
2564 VTY_DECLVAR_CONTEXT(bgp, bgp);
2565
2566 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2567 return CMD_SUCCESS;
2568 }
2569
2570 DEFUN (no_bgp_graceful_restart_select_defer_time,
2571 no_bgp_graceful_restart_select_defer_time_cmd,
2572 "no bgp graceful-restart select-defer-time [(0-3600)]",
2573 NO_STR
2574 "BGP specific commands\n"
2575 "Graceful restart capability parameters\n"
2576 "Set the time to defer the BGP route selection after restart\n"
2577 "Delay value (seconds)\n")
2578 {
2579 VTY_DECLVAR_CONTEXT(bgp, bgp);
2580
2581 bgp->select_defer_time = BGP_DEFAULT_SELECT_DEFERRAL_TIME;
2582 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2583
2584 return CMD_SUCCESS;
2585 }
2586
2587 DEFUN (bgp_graceful_restart_preserve_fw,
2588 bgp_graceful_restart_preserve_fw_cmd,
2589 "bgp graceful-restart preserve-fw-state",
2590 "BGP specific commands\n"
2591 "Graceful restart capability parameters\n"
2592 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
2593 {
2594 VTY_DECLVAR_CONTEXT(bgp, bgp);
2595 SET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
2596 return CMD_SUCCESS;
2597 }
2598
2599 DEFUN (no_bgp_graceful_restart_preserve_fw,
2600 no_bgp_graceful_restart_preserve_fw_cmd,
2601 "no bgp graceful-restart preserve-fw-state",
2602 NO_STR
2603 "BGP specific commands\n"
2604 "Graceful restart capability parameters\n"
2605 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
2606 {
2607 VTY_DECLVAR_CONTEXT(bgp, bgp);
2608 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
2609 return CMD_SUCCESS;
2610 }
2611
2612 DEFUN (bgp_graceful_restart_disable,
2613 bgp_graceful_restart_disable_cmd,
2614 "bgp graceful-restart-disable",
2615 "BGP specific commands\n"
2616 GR_DISABLE)
2617 {
2618 int ret = BGP_GR_FAILURE;
2619
2620 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2621 zlog_debug(
2622 "[BGP_GR] bgp_graceful_restart_disable_cmd : START ");
2623
2624 VTY_DECLVAR_CONTEXT(bgp, bgp);
2625
2626 ret = bgp_gr_update_all(bgp, GLOBAL_DISABLE_CMD);
2627
2628 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
2629 bgp->peer, ret);
2630
2631 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2632 zlog_debug(
2633 "[BGP_GR] bgp_graceful_restart_disable_cmd : END ");
2634 vty_out(vty,
2635 "Graceful restart configuration changed, reset all peers to take effect\n");
2636
2637 return bgp_vty_return(vty, ret);
2638 }
2639
2640 DEFUN (no_bgp_graceful_restart_disable,
2641 no_bgp_graceful_restart_disable_cmd,
2642 "no bgp graceful-restart-disable",
2643 NO_STR
2644 "BGP specific commands\n"
2645 NO_GR_DISABLE
2646 )
2647 {
2648 VTY_DECLVAR_CONTEXT(bgp, bgp);
2649
2650 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2651 zlog_debug(
2652 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : START ");
2653
2654 int ret = BGP_GR_FAILURE;
2655
2656 ret = bgp_gr_update_all(bgp, NO_GLOBAL_DISABLE_CMD);
2657
2658 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2659 ret);
2660
2661 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2662 zlog_debug(
2663 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : END ");
2664 vty_out(vty,
2665 "Graceful restart configuration changed, reset all peers to take effect\n");
2666
2667 return bgp_vty_return(vty, ret);
2668 }
2669
2670 DEFUN (bgp_neighbor_graceful_restart_set,
2671 bgp_neighbor_graceful_restart_set_cmd,
2672 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
2673 NEIGHBOR_STR
2674 NEIGHBOR_ADDR_STR2
2675 GR_NEIGHBOR_CMD
2676 )
2677 {
2678 int idx_peer = 1;
2679 struct peer *peer;
2680 int ret = BGP_GR_FAILURE;
2681
2682 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2683
2684 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2685 zlog_debug(
2686 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : START ");
2687
2688 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2689 if (!peer)
2690 return CMD_WARNING_CONFIG_FAILED;
2691
2692 ret = bgp_neighbor_graceful_restart(peer, PEER_GR_CMD);
2693
2694 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2695 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
2696
2697 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2698 zlog_debug(
2699 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : END ");
2700 vty_out(vty,
2701 "Graceful restart configuration changed, reset this peer to take effect\n");
2702
2703 return bgp_vty_return(vty, ret);
2704 }
2705
2706 DEFUN (no_bgp_neighbor_graceful_restart,
2707 no_bgp_neighbor_graceful_restart_set_cmd,
2708 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
2709 NO_STR
2710 NEIGHBOR_STR
2711 NEIGHBOR_ADDR_STR2
2712 NO_GR_NEIGHBOR_CMD
2713 )
2714 {
2715 int idx_peer = 2;
2716 int ret = BGP_GR_FAILURE;
2717 struct peer *peer;
2718
2719 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2720
2721 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2722 if (!peer)
2723 return CMD_WARNING_CONFIG_FAILED;
2724
2725 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2726 zlog_debug(
2727 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : START ");
2728
2729 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_GR_CMD);
2730
2731 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2732 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
2733
2734 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2735 zlog_debug(
2736 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : END ");
2737 vty_out(vty,
2738 "Graceful restart configuration changed, reset this peer to take effect\n");
2739
2740 return bgp_vty_return(vty, ret);
2741 }
2742
2743 DEFUN (bgp_neighbor_graceful_restart_helper_set,
2744 bgp_neighbor_graceful_restart_helper_set_cmd,
2745 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
2746 NEIGHBOR_STR
2747 NEIGHBOR_ADDR_STR2
2748 GR_NEIGHBOR_HELPER_CMD
2749 )
2750 {
2751 int idx_peer = 1;
2752 struct peer *peer;
2753 int ret = BGP_GR_FAILURE;
2754
2755 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2756
2757 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2758 zlog_debug(
2759 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : START ");
2760
2761 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2762
2763 if (!peer)
2764 return CMD_WARNING_CONFIG_FAILED;
2765
2766
2767 ret = bgp_neighbor_graceful_restart(peer, PEER_HELPER_CMD);
2768
2769 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2770 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
2771
2772 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2773 zlog_debug(
2774 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : END ");
2775 vty_out(vty,
2776 "Graceful restart configuration changed, reset this peer to take effect\n");
2777
2778 return bgp_vty_return(vty, ret);
2779 }
2780
2781 DEFUN (no_bgp_neighbor_graceful_restart_helper,
2782 no_bgp_neighbor_graceful_restart_helper_set_cmd,
2783 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
2784 NO_STR
2785 NEIGHBOR_STR
2786 NEIGHBOR_ADDR_STR2
2787 NO_GR_NEIGHBOR_HELPER_CMD
2788 )
2789 {
2790 int idx_peer = 2;
2791 int ret = BGP_GR_FAILURE;
2792 struct peer *peer;
2793
2794 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2795
2796 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2797 if (!peer)
2798 return CMD_WARNING_CONFIG_FAILED;
2799
2800 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2801 zlog_debug(
2802 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : START ");
2803
2804 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_HELPER_CMD);
2805
2806 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2807 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
2808
2809 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2810 zlog_debug(
2811 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : END ");
2812 vty_out(vty,
2813 "Graceful restart configuration changed, reset this peer to take effect\n");
2814
2815 return bgp_vty_return(vty, ret);
2816 }
2817
2818 DEFUN (bgp_neighbor_graceful_restart_disable_set,
2819 bgp_neighbor_graceful_restart_disable_set_cmd,
2820 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
2821 NEIGHBOR_STR
2822 NEIGHBOR_ADDR_STR2
2823 GR_NEIGHBOR_DISABLE_CMD
2824 )
2825 {
2826 int idx_peer = 1;
2827 struct peer *peer;
2828 int ret = BGP_GR_FAILURE;
2829
2830 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2831
2832 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2833 zlog_debug(
2834 "[BGP_GR] bgp_neighbor_graceful_restart_disable_set_cmd : START ");
2835
2836 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2837 if (!peer)
2838 return CMD_WARNING_CONFIG_FAILED;
2839
2840 ret = bgp_neighbor_graceful_restart(peer, PEER_DISABLE_CMD);
2841
2842 if (peer->bgp->t_startup)
2843 bgp_peer_gr_flags_update(peer);
2844
2845 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2846 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
2847
2848 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2849 zlog_debug(
2850 "[BGP_GR]bgp_neighbor_graceful_restart_disable_set_cmd : END ");
2851 vty_out(vty,
2852 "Graceful restart configuration changed, reset this peer to take effect\n");
2853
2854 return bgp_vty_return(vty, ret);
2855 }
2856
2857 DEFUN (no_bgp_neighbor_graceful_restart_disable,
2858 no_bgp_neighbor_graceful_restart_disable_set_cmd,
2859 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
2860 NO_STR
2861 NEIGHBOR_STR
2862 NEIGHBOR_ADDR_STR2
2863 NO_GR_NEIGHBOR_DISABLE_CMD
2864 )
2865 {
2866 int idx_peer = 2;
2867 int ret = BGP_GR_FAILURE;
2868 struct peer *peer;
2869
2870 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2871
2872 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2873 if (!peer)
2874 return CMD_WARNING_CONFIG_FAILED;
2875
2876 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2877 zlog_debug(
2878 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : START ");
2879
2880 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_DISABLE_CMD);
2881
2882 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2883 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
2884
2885 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2886 zlog_debug(
2887 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : END ");
2888 vty_out(vty,
2889 "Graceful restart configuration changed, reset this peer to take effect\n");
2890
2891 return bgp_vty_return(vty, ret);
2892 }
2893
2894 DEFUN_HIDDEN (bgp_graceful_restart_disable_eor,
2895 bgp_graceful_restart_disable_eor_cmd,
2896 "bgp graceful-restart disable-eor",
2897 "BGP specific commands\n"
2898 "Graceful restart configuration parameters\n"
2899 "Disable EOR Check\n")
2900 {
2901 VTY_DECLVAR_CONTEXT(bgp, bgp);
2902 SET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
2903
2904 return CMD_SUCCESS;
2905 }
2906
2907 DEFUN_HIDDEN (no_bgp_graceful_restart_disable_eor,
2908 no_bgp_graceful_restart_disable_eor_cmd,
2909 "no bgp graceful-restart disable-eor",
2910 NO_STR
2911 "BGP specific commands\n"
2912 "Graceful restart configuration parameters\n"
2913 "Disable EOR Check\n")
2914 {
2915 VTY_DECLVAR_CONTEXT(bgp, bgp);
2916 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
2917
2918 return CMD_SUCCESS;
2919 }
2920
2921 DEFUN (bgp_graceful_restart_rib_stale_time,
2922 bgp_graceful_restart_rib_stale_time_cmd,
2923 "bgp graceful-restart rib-stale-time (1-3600)",
2924 "BGP specific commands\n"
2925 "Graceful restart configuration parameters\n"
2926 "Specify the stale route removal timer in rib\n"
2927 "Delay value (seconds)\n")
2928 {
2929 VTY_DECLVAR_CONTEXT(bgp, bgp);
2930 int idx_number = 3;
2931 uint32_t stale_time;
2932
2933 stale_time = strtoul(argv[idx_number]->arg, NULL, 10);
2934 bgp->rib_stale_time = stale_time;
2935 /* Send the stale timer update message to RIB */
2936 if (bgp_zebra_stale_timer_update(bgp))
2937 return CMD_WARNING;
2938
2939 return CMD_SUCCESS;
2940 }
2941
2942 DEFUN (no_bgp_graceful_restart_rib_stale_time,
2943 no_bgp_graceful_restart_rib_stale_time_cmd,
2944 "no bgp graceful-restart rib-stale-time [(1-3600)]",
2945 NO_STR
2946 "BGP specific commands\n"
2947 "Graceful restart configuration parameters\n"
2948 "Specify the stale route removal timer in rib\n"
2949 "Delay value (seconds)\n")
2950 {
2951 VTY_DECLVAR_CONTEXT(bgp, bgp);
2952
2953 bgp->rib_stale_time = BGP_DEFAULT_RIB_STALE_TIME;
2954 /* Send the stale timer update message to RIB */
2955 if (bgp_zebra_stale_timer_update(bgp))
2956 return CMD_WARNING;
2957
2958 return CMD_SUCCESS;
2959 }
2960
2961 static inline int bgp_initiate_graceful_shut_unshut(struct bgp *bgp,
2962 char *errmsg,
2963 size_t errmsg_len)
2964 {
2965 bgp_static_redo_import_check(bgp);
2966 bgp_redistribute_redo(bgp);
2967 if (bgp_clear_star_soft_out(bgp->name, errmsg, errmsg_len) < 0)
2968 return -1;
2969 if (bgp_clear_star_soft_in(bgp->name, errmsg, errmsg_len) < 0)
2970 return -1;
2971
2972 return 0;
2973 }
2974
2975 static int bgp_global_graceful_shutdown_config_vty(struct vty *vty)
2976 {
2977 struct listnode *node, *nnode;
2978 struct bgp *bgp;
2979 bool vrf_cfg = false;
2980 char errmsg[BUFSIZ] = {'\0'};
2981
2982 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
2983 return CMD_SUCCESS;
2984
2985 /* See if graceful-shutdown is set per-vrf and warn user to delete */
2986 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2987 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2988 vty_out(vty,
2989 "%% graceful-shutdown configuration found in vrf %s\n",
2990 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT ?
2991 VRF_DEFAULT_NAME : bgp->name);
2992 vrf_cfg = true;
2993 }
2994 }
2995
2996 if (vrf_cfg) {
2997 vty_out(vty,
2998 "%%Failed: global graceful-shutdown not permitted\n");
2999 return CMD_WARNING;
3000 }
3001
3002 /* Set flag globally */
3003 SET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3004
3005 /* Initiate processing for all BGP instances. */
3006 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3007 if (bgp_initiate_graceful_shut_unshut(bgp, errmsg,
3008 sizeof(errmsg))
3009 < 0)
3010 if (strlen(errmsg))
3011 vty_out(vty, "%s\n", errmsg);
3012 }
3013
3014 return CMD_SUCCESS;
3015 }
3016
3017 static int bgp_global_graceful_shutdown_deconfig_vty(struct vty *vty)
3018 {
3019 struct listnode *node, *nnode;
3020 struct bgp *bgp;
3021 char errmsg[BUFSIZ] = {'\0'};
3022
3023 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3024 return CMD_SUCCESS;
3025
3026 /* Unset flag globally */
3027 UNSET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3028
3029 /* Initiate processing for all BGP instances. */
3030 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3031 if (bgp_initiate_graceful_shut_unshut(bgp, errmsg,
3032 sizeof(errmsg))
3033 < 0)
3034 if (strlen(errmsg))
3035 vty_out(vty, "%s\n", errmsg);
3036 }
3037
3038 return CMD_SUCCESS;
3039 }
3040
3041 /* "bgp graceful-shutdown" configuration */
3042 DEFUN (bgp_graceful_shutdown,
3043 bgp_graceful_shutdown_cmd,
3044 "bgp graceful-shutdown",
3045 BGP_STR
3046 "Graceful shutdown parameters\n")
3047 {
3048 if (vty->node == CONFIG_NODE)
3049 return bgp_global_graceful_shutdown_config_vty(vty);
3050
3051 nb_cli_enqueue_change(vty, "./global/graceful-shutdown/enable",
3052 NB_OP_MODIFY, "true");
3053
3054 return nb_cli_apply_changes(vty, NULL);
3055 }
3056
3057 DEFUN_YANG (no_bgp_graceful_shutdown,
3058 no_bgp_graceful_shutdown_cmd,
3059 "no bgp graceful-shutdown",
3060 NO_STR
3061 BGP_STR
3062 "Graceful shutdown parameters\n")
3063 {
3064 if (vty->node == CONFIG_NODE)
3065 return bgp_global_graceful_shutdown_deconfig_vty(vty);
3066
3067 nb_cli_enqueue_change(vty, "./global/graceful-shutdown/enable",
3068 NB_OP_MODIFY, "false");
3069
3070 return nb_cli_apply_changes(vty, NULL);
3071 }
3072
3073 void cli_show_router_bgp_graceful_shutdown(struct vty *vty,
3074 struct lyd_node *dnode,
3075 bool show_defaults)
3076 {
3077 if (yang_dnode_get_bool(dnode, NULL))
3078 vty_out(vty, " bgp graceful-shutdown\n");
3079 }
3080
3081 /* "bgp fast-external-failover" configuration. */
3082 DEFUN_YANG (bgp_fast_external_failover,
3083 bgp_fast_external_failover_cmd,
3084 "bgp fast-external-failover",
3085 BGP_STR
3086 "Immediately reset session if a link to a directly connected external peer goes down\n")
3087 {
3088 nb_cli_enqueue_change(vty, "./global/fast-external-failover",
3089 NB_OP_MODIFY, "false");
3090
3091 return nb_cli_apply_changes(vty, NULL);
3092 }
3093
3094 DEFUN_YANG (no_bgp_fast_external_failover,
3095 no_bgp_fast_external_failover_cmd,
3096 "no bgp fast-external-failover",
3097 NO_STR
3098 BGP_STR
3099 "Immediately reset session if a link to a directly connected external peer goes down\n")
3100 {
3101 nb_cli_enqueue_change(vty, "./global/fast-external-failover",
3102 NB_OP_MODIFY, "true");
3103
3104 return nb_cli_apply_changes(vty, NULL);
3105 }
3106
3107 void cli_show_router_bgp_fast_external_failover(struct vty *vty,
3108 struct lyd_node *dnode,
3109 bool show_defaults)
3110 {
3111 if (!yang_dnode_get_bool(dnode, NULL))
3112 vty_out(vty, " no bgp fast-external-failover\n");
3113 }
3114
3115 /* "bgp bestpath compare-routerid" configuration. */
3116 DEFUN_YANG(bgp_bestpath_compare_router_id,
3117 bgp_bestpath_compare_router_id_cmd,
3118 "bgp bestpath compare-routerid",
3119 "BGP specific commands\n"
3120 "Change the default bestpath selection\n"
3121 "Compare router-id for identical EBGP paths\n")
3122 {
3123 nb_cli_enqueue_change(
3124 vty,
3125 "./global/route-selection-options/external-compare-router-id",
3126 NB_OP_MODIFY, "true");
3127
3128 return nb_cli_apply_changes(vty, NULL);
3129 }
3130
3131 DEFUN_YANG(no_bgp_bestpath_compare_router_id,
3132 no_bgp_bestpath_compare_router_id_cmd,
3133 "no bgp bestpath compare-routerid",
3134 NO_STR
3135 "BGP specific commands\n"
3136 "Change the default bestpath selection\n"
3137 "Compare router-id for identical EBGP paths\n")
3138 {
3139 nb_cli_enqueue_change(
3140 vty,
3141 "./global/route-selection-options/external-compare-router-id",
3142 NB_OP_MODIFY, "false");
3143
3144 return nb_cli_apply_changes(vty, NULL);
3145 }
3146
3147 /* "bgp bestpath as-path ignore" configuration. */
3148 DEFUN_YANG(bgp_bestpath_aspath_ignore,
3149 bgp_bestpath_aspath_ignore_cmd,
3150 "bgp bestpath as-path ignore",
3151 "BGP specific commands\n"
3152 "Change the default bestpath selection\n"
3153 "AS-path attribute\n"
3154 "Ignore as-path length in selecting a route\n")
3155 {
3156 nb_cli_enqueue_change(
3157 vty, "./global/route-selection-options/ignore-as-path-length",
3158 NB_OP_MODIFY, "true");
3159
3160 return nb_cli_apply_changes(vty, NULL);
3161 }
3162
3163 DEFUN_YANG(no_bgp_bestpath_aspath_ignore,
3164 no_bgp_bestpath_aspath_ignore_cmd,
3165 "no bgp bestpath as-path ignore",
3166 NO_STR
3167 "BGP specific commands\n"
3168 "Change the default bestpath selection\n"
3169 "AS-path attribute\n"
3170 "Ignore as-path length in selecting a route\n")
3171 {
3172 nb_cli_enqueue_change(
3173 vty, "./global/route-selection-options/ignore-as-path-length",
3174 NB_OP_MODIFY, "false");
3175
3176 return nb_cli_apply_changes(vty, NULL);
3177 }
3178
3179 /* "bgp bestpath as-path confed" configuration. */
3180 DEFUN_YANG (bgp_bestpath_aspath_confed,
3181 bgp_bestpath_aspath_confed_cmd,
3182 "bgp bestpath as-path confed",
3183 "BGP specific commands\n"
3184 "Change the default bestpath selection\n"
3185 "AS-path attribute\n"
3186 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3187 {
3188 nb_cli_enqueue_change(vty,
3189 "./global/route-selection-options/aspath-confed",
3190 NB_OP_MODIFY, "true");
3191
3192 return nb_cli_apply_changes(vty, NULL);
3193 }
3194
3195 DEFUN_YANG (no_bgp_bestpath_aspath_confed,
3196 no_bgp_bestpath_aspath_confed_cmd,
3197 "no bgp bestpath as-path confed",
3198 NO_STR
3199 "BGP specific commands\n"
3200 "Change the default bestpath selection\n"
3201 "AS-path attribute\n"
3202 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3203 {
3204 nb_cli_enqueue_change(vty,
3205 "./global/route-selection-options/aspath-confed",
3206 NB_OP_MODIFY, "false");
3207
3208 return nb_cli_apply_changes(vty, NULL);
3209 }
3210
3211 /* "bgp bestpath as-path multipath-relax" configuration. */
3212 DEFUN_YANG (bgp_bestpath_aspath_multipath_relax,
3213 bgp_bestpath_aspath_multipath_relax_cmd,
3214 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
3215 "BGP specific commands\n"
3216 "Change the default bestpath selection\n"
3217 "AS-path attribute\n"
3218 "Allow load sharing across routes that have different AS paths (but same length)\n"
3219 "Generate an AS_SET\n"
3220 "Do not generate an AS_SET\n")
3221 {
3222 int idx = 0;
3223
3224 nb_cli_enqueue_change(
3225 vty, "./global/route-selection-options/allow-multiple-as",
3226 NB_OP_MODIFY, "true");
3227 if (argv_find(argv, argc, "as-set", &idx))
3228 nb_cli_enqueue_change(
3229 vty,
3230 "./global/route-selection-options/multi-path-as-set",
3231 NB_OP_MODIFY, "true");
3232 else
3233 nb_cli_enqueue_change(
3234 vty,
3235 "./global/route-selection-options/multi-path-as-set",
3236 NB_OP_MODIFY, "false");
3237
3238 return nb_cli_apply_changes(vty, NULL);
3239 }
3240
3241 DEFUN_YANG (no_bgp_bestpath_aspath_multipath_relax,
3242 no_bgp_bestpath_aspath_multipath_relax_cmd,
3243 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
3244 NO_STR
3245 "BGP specific commands\n"
3246 "Change the default bestpath selection\n"
3247 "AS-path attribute\n"
3248 "Allow load sharing across routes that have different AS paths (but same length)\n"
3249 "Generate an AS_SET\n"
3250 "Do not generate an AS_SET\n")
3251 {
3252 nb_cli_enqueue_change(
3253 vty, "./global/route-selection-options/allow-multiple-as",
3254 NB_OP_MODIFY, "false");
3255 nb_cli_enqueue_change(
3256 vty, "./global/route-selection-options/multi-path-as-set",
3257 NB_OP_MODIFY, "false");
3258
3259 return nb_cli_apply_changes(vty, NULL);
3260 }
3261
3262 /* "bgp log-neighbor-changes" configuration. */
3263 DEFUN_YANG(bgp_log_neighbor_changes,
3264 bgp_log_neighbor_changes_cmd,
3265 "bgp log-neighbor-changes",
3266 "BGP specific commands\n"
3267 "Log neighbor up/down and reset reason\n")
3268 {
3269 nb_cli_enqueue_change(
3270 vty, "./global/global-neighbor-config/log-neighbor-changes",
3271 NB_OP_MODIFY, "true");
3272
3273 return nb_cli_apply_changes(vty, NULL);
3274 }
3275
3276 DEFUN_YANG(no_bgp_log_neighbor_changes,
3277 no_bgp_log_neighbor_changes_cmd,
3278 "no bgp log-neighbor-changes",
3279 NO_STR
3280 "BGP specific commands\n"
3281 "Log neighbor up/down and reset reason\n")
3282 {
3283 nb_cli_enqueue_change(
3284 vty, "./global/global-neighbor-config/log-neighbor-changes",
3285 NB_OP_MODIFY, "false");
3286
3287 return nb_cli_apply_changes(vty, NULL);
3288 }
3289
3290 /* "bgp bestpath med" configuration. */
3291 DEFUN_YANG (bgp_bestpath_med,
3292 bgp_bestpath_med_cmd,
3293 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
3294 "BGP specific commands\n"
3295 "Change the default bestpath selection\n"
3296 "MED attribute\n"
3297 "Compare MED among confederation paths\n"
3298 "Treat missing MED as the least preferred one\n"
3299 "Treat missing MED as the least preferred one\n"
3300 "Compare MED among confederation paths\n")
3301 {
3302 int idx = 0;
3303 bool confed = false;
3304 bool worst_med = false;
3305
3306
3307 if (argv_find(argv, argc, "confed", &idx))
3308 confed = true;
3309
3310 nb_cli_enqueue_change(vty,
3311 "./global/route-selection-options/confed-med",
3312 NB_OP_MODIFY, confed ? "true" : "false");
3313
3314 idx = 0;
3315 if (argv_find(argv, argc, "missing-as-worst", &idx))
3316 worst_med = true;
3317
3318 nb_cli_enqueue_change(
3319 vty, "./global/route-selection-options/missing-as-worst-med",
3320 NB_OP_MODIFY, worst_med ? "true" : "false");
3321
3322 return nb_cli_apply_changes(vty, NULL);
3323 }
3324
3325 DEFUN_YANG (no_bgp_bestpath_med,
3326 no_bgp_bestpath_med_cmd,
3327 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
3328 NO_STR
3329 "BGP specific commands\n"
3330 "Change the default bestpath selection\n"
3331 "MED attribute\n"
3332 "Compare MED among confederation paths\n"
3333 "Treat missing MED as the least preferred one\n"
3334 "Treat missing MED as the least preferred one\n"
3335 "Compare MED among confederation paths\n")
3336 {
3337 int idx = 0;
3338
3339 if (argv_find(argv, argc, "confed", &idx))
3340 nb_cli_enqueue_change(
3341 vty, "./global/route-selection-options/confed-med",
3342 NB_OP_MODIFY, "false");
3343
3344 idx = 0;
3345 if (argv_find(argv, argc, "missing-as-worst", &idx))
3346 nb_cli_enqueue_change(
3347 vty,
3348 "./global/route-selection-options/missing-as-worst-med",
3349 NB_OP_MODIFY, "false");
3350
3351 return nb_cli_apply_changes(vty, NULL);
3352 }
3353
3354 /* "bgp bestpath bandwidth" configuration. */
3355 DEFPY (bgp_bestpath_bw,
3356 bgp_bestpath_bw_cmd,
3357 "bgp bestpath bandwidth <ignore|skip-missing|default-weight-for-missing>$bw_cfg",
3358 "BGP specific commands\n"
3359 "Change the default bestpath selection\n"
3360 "Link Bandwidth attribute\n"
3361 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3362 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3363 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3364 {
3365 VTY_DECLVAR_CONTEXT(bgp, bgp);
3366 afi_t afi;
3367 safi_t safi;
3368
3369 if (!bw_cfg) {
3370 vty_out(vty, "%% Bandwidth configuration must be specified\n");
3371 return CMD_ERR_INCOMPLETE;
3372 }
3373 if (!strcmp(bw_cfg, "ignore"))
3374 bgp->lb_handling = BGP_LINK_BW_IGNORE_BW;
3375 else if (!strcmp(bw_cfg, "skip-missing"))
3376 bgp->lb_handling = BGP_LINK_BW_SKIP_MISSING;
3377 else if (!strcmp(bw_cfg, "default-weight-for-missing"))
3378 bgp->lb_handling = BGP_LINK_BW_DEFWT_4_MISSING;
3379 else
3380 return CMD_ERR_NO_MATCH;
3381
3382 /* This config is used in route install, so redo that. */
3383 FOREACH_AFI_SAFI (afi, safi) {
3384 if (!bgp_fibupd_safi(safi))
3385 continue;
3386 bgp_zebra_announce_table(bgp, afi, safi);
3387 }
3388
3389 return CMD_SUCCESS;
3390 }
3391
3392 DEFPY (no_bgp_bestpath_bw,
3393 no_bgp_bestpath_bw_cmd,
3394 "no bgp bestpath bandwidth [<ignore|skip-missing|default-weight-for-missing>$bw_cfg]",
3395 NO_STR
3396 "BGP specific commands\n"
3397 "Change the default bestpath selection\n"
3398 "Link Bandwidth attribute\n"
3399 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3400 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3401 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3402 {
3403 VTY_DECLVAR_CONTEXT(bgp, bgp);
3404 afi_t afi;
3405 safi_t safi;
3406
3407 bgp->lb_handling = BGP_LINK_BW_ECMP;
3408
3409 /* This config is used in route install, so redo that. */
3410 FOREACH_AFI_SAFI (afi, safi) {
3411 if (!bgp_fibupd_safi(safi))
3412 continue;
3413 bgp_zebra_announce_table(bgp, afi, safi);
3414 }
3415 return CMD_SUCCESS;
3416 }
3417
3418 /* "no bgp default ipv4-unicast". */
3419 DEFUN (no_bgp_default_ipv4_unicast,
3420 no_bgp_default_ipv4_unicast_cmd,
3421 "no bgp default ipv4-unicast",
3422 NO_STR
3423 "BGP specific commands\n"
3424 "Configure BGP defaults\n"
3425 "Activate ipv4-unicast for a peer by default\n")
3426 {
3427 VTY_DECLVAR_CONTEXT(bgp, bgp);
3428 SET_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4);
3429 return CMD_SUCCESS;
3430 }
3431
3432 DEFUN (bgp_default_ipv4_unicast,
3433 bgp_default_ipv4_unicast_cmd,
3434 "bgp default ipv4-unicast",
3435 "BGP specific commands\n"
3436 "Configure BGP defaults\n"
3437 "Activate ipv4-unicast for a peer by default\n")
3438 {
3439 VTY_DECLVAR_CONTEXT(bgp, bgp);
3440 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4);
3441 return CMD_SUCCESS;
3442 }
3443
3444 /* Display hostname in certain command outputs */
3445 DEFUN_YANG (bgp_default_show_hostname,
3446 bgp_default_show_hostname_cmd,
3447 "bgp default show-hostname",
3448 "BGP specific commands\n"
3449 "Configure BGP defaults\n"
3450 "Show hostname in certain command outputs\n")
3451 {
3452 nb_cli_enqueue_change(vty, "./global/show-hostname", NB_OP_MODIFY,
3453 "true");
3454
3455 return nb_cli_apply_changes(vty, NULL);
3456 }
3457
3458 DEFUN_YANG(no_bgp_default_show_hostname,
3459 no_bgp_default_show_hostname_cmd,
3460 "no bgp default show-hostname",
3461 NO_STR
3462 "BGP specific commands\n"
3463 "Configure BGP defaults\n"
3464 "Show hostname in certain command outputs\n")
3465 {
3466 nb_cli_enqueue_change(vty, "./global/show-hostname", NB_OP_MODIFY,
3467 "false");
3468
3469 return nb_cli_apply_changes(vty, NULL);
3470 }
3471
3472 void cli_show_router_bgp_show_hostname(struct vty *vty, struct lyd_node *dnode,
3473 bool show_defaults)
3474 {
3475 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_SHOW_HOSTNAME)
3476 vty_out(vty, " bgp default show-hostname\n");
3477 }
3478
3479 /* Display hostname in certain command outputs */
3480 DEFUN (bgp_default_show_nexthop_hostname,
3481 bgp_default_show_nexthop_hostname_cmd,
3482 "bgp default show-nexthop-hostname",
3483 "BGP specific commands\n"
3484 "Configure BGP defaults\n"
3485 "Show hostname for nexthop in certain command outputs\n")
3486 {
3487 nb_cli_enqueue_change(vty, "./global/show-nexthop-hostname",
3488 NB_OP_MODIFY, "true");
3489
3490 return nb_cli_apply_changes(vty, NULL);
3491 }
3492
3493 DEFUN (no_bgp_default_show_nexthop_hostname,
3494 no_bgp_default_show_nexthop_hostname_cmd,
3495 "no bgp default show-nexthop-hostname",
3496 NO_STR
3497 "BGP specific commands\n"
3498 "Configure BGP defaults\n"
3499 "Show hostname for nexthop in certain command outputs\n")
3500 {
3501 nb_cli_enqueue_change(vty, "./global/show-nexthop-hostname",
3502 NB_OP_MODIFY, "false");
3503
3504 return nb_cli_apply_changes(vty, NULL);
3505 }
3506
3507 void cli_show_router_bgp_show_nexthop_hostname(struct vty *vty,
3508 struct lyd_node *dnode,
3509 bool show_defaults)
3510 {
3511 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_SHOW_HOSTNAME)
3512 vty_out(vty, " bgp default show-nexthop-hostname\n");
3513 }
3514
3515 /* "bgp network import-check" configuration. */
3516 DEFUN_YANG(bgp_network_import_check,
3517 bgp_network_import_check_cmd,
3518 "bgp network import-check",
3519 "BGP specific commands\n"
3520 "BGP network command\n"
3521 "Check BGP network route exists in IGP\n")
3522 {
3523 nb_cli_enqueue_change(vty, "./global/import-check", NB_OP_MODIFY,
3524 "true");
3525
3526 return nb_cli_apply_changes(vty, NULL);
3527 }
3528
3529 ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
3530 "bgp network import-check exact",
3531 "BGP specific commands\n"
3532 "BGP network command\n"
3533 "Check BGP network route exists in IGP\n"
3534 "Match route precisely\n")
3535
3536 DEFUN_YANG(no_bgp_network_import_check,
3537 no_bgp_network_import_check_cmd,
3538 "no bgp network import-check",
3539 NO_STR
3540 "BGP specific commands\n"
3541 "BGP network command\n"
3542 "Check BGP network route exists in IGP\n")
3543 {
3544 nb_cli_enqueue_change(vty, "./global/import-check", NB_OP_MODIFY,
3545 "false");
3546
3547 return nb_cli_apply_changes(vty, NULL);
3548 }
3549
3550 void cli_show_router_bgp_import_check(struct vty *vty, struct lyd_node *dnode,
3551 bool show_defaults)
3552 {
3553 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_IMPORT_CHECK)
3554 vty_out(vty, " bgp network import-check\n");
3555 }
3556
3557 DEFUN_YANG(bgp_default_local_preference,
3558 bgp_default_local_preference_cmd,
3559 "bgp default local-preference (0-4294967295)",
3560 "BGP specific commands\n"
3561 "Configure BGP defaults\n"
3562 "local preference (higher=more preferred)\n"
3563 "Configure default local preference value\n")
3564 {
3565 int idx_number = 3;
3566
3567 nb_cli_enqueue_change(vty, "./global/local-pref", NB_OP_MODIFY,
3568 argv[idx_number]->arg);
3569
3570 return nb_cli_apply_changes(vty, NULL);
3571 }
3572
3573 DEFUN_YANG(no_bgp_default_local_preference,
3574 no_bgp_default_local_preference_cmd,
3575 "no bgp default local-preference [(0-4294967295)]",
3576 NO_STR
3577 "BGP specific commands\n"
3578 "Configure BGP defaults\n"
3579 "local preference (higher=more preferred)\n"
3580 "Configure default local preference value\n")
3581 {
3582 nb_cli_enqueue_change(vty, "./global/local-pref", NB_OP_MODIFY, NULL);
3583
3584 return nb_cli_apply_changes(vty, NULL);
3585 }
3586
3587 void cli_show_router_bgp_local_pref(struct vty *vty, struct lyd_node *dnode,
3588 bool show_defaults)
3589 {
3590 vty_out(vty, " bgp default local-preference %u\n",
3591 yang_dnode_get_uint32(dnode, NULL));
3592 }
3593
3594
3595 DEFUN_YANG(bgp_default_subgroup_pkt_queue_max,
3596 bgp_default_subgroup_pkt_queue_max_cmd,
3597 "bgp default subgroup-pkt-queue-max (20-100)",
3598 "BGP specific commands\n"
3599 "Configure BGP defaults\n"
3600 "subgroup-pkt-queue-max\n"
3601 "Configure subgroup packet queue max\n")
3602 {
3603 int idx_number = 3;
3604
3605 nb_cli_enqueue_change(
3606 vty,
3607 "./global/global-update-group-config/subgroup-pkt-queue-size",
3608 NB_OP_MODIFY, argv[idx_number]->arg);
3609
3610 return nb_cli_apply_changes(vty, NULL);
3611 }
3612
3613 DEFUN_YANG(no_bgp_default_subgroup_pkt_queue_max,
3614 no_bgp_default_subgroup_pkt_queue_max_cmd,
3615 "no bgp default subgroup-pkt-queue-max [(20-100)]",
3616 NO_STR
3617 "BGP specific commands\n"
3618 "Configure BGP defaults\n"
3619 "subgroup-pkt-queue-max\n"
3620 "Configure subgroup packet queue max\n")
3621 {
3622 nb_cli_enqueue_change(
3623 vty,
3624 "./global/global-update-group-config/subgroup-pkt-queue-size",
3625 NB_OP_MODIFY, NULL);
3626
3627 return nb_cli_apply_changes(vty, NULL);
3628 }
3629
3630 void cli_show_router_global_update_group_config_subgroup_pkt_queue_size(
3631 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
3632 {
3633 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
3634 yang_dnode_get_uint32(dnode, NULL));
3635 }
3636
3637 DEFUN_YANG(bgp_rr_allow_outbound_policy,
3638 bgp_rr_allow_outbound_policy_cmd,
3639 "bgp route-reflector allow-outbound-policy",
3640 "BGP specific commands\n"
3641 "Allow modifications made by out route-map\n"
3642 "on ibgp neighbors\n")
3643 {
3644 nb_cli_enqueue_change(vty,
3645 "./global/route-reflector/allow-outbound-policy",
3646 NB_OP_MODIFY, "true");
3647
3648 return nb_cli_apply_changes(vty, NULL);
3649 }
3650
3651 DEFUN_YANG(no_bgp_rr_allow_outbound_policy,
3652 no_bgp_rr_allow_outbound_policy_cmd,
3653 "no bgp route-reflector allow-outbound-policy",
3654 NO_STR
3655 "BGP specific commands\n"
3656 "Allow modifications made by out route-map\n"
3657 "on ibgp neighbors\n")
3658 {
3659 nb_cli_enqueue_change(vty,
3660 "./global/route-reflector/allow-outbound-policy",
3661 NB_OP_MODIFY, "false");
3662
3663 return nb_cli_apply_changes(vty, NULL);
3664 }
3665
3666
3667 void cli_show_router_global_neighbor_config(struct vty *vty,
3668 struct lyd_node *dnode,
3669 bool show_defaults)
3670 {
3671 uint32_t write_quanta, read_quanta;
3672
3673 if (yang_dnode_get_bool(dnode, "./log-neighbor-changes"))
3674 vty_out(vty, " bgp log-neighbor-changes\n");
3675
3676 if (yang_dnode_exists(dnode, "./dynamic-neighbors-limit")) {
3677 uint32_t listen_limit = yang_dnode_get_uint32(
3678 dnode, "./dynamic-neighbors-limit");
3679 vty_out(vty, " bgp listen limit %u\n", listen_limit);
3680 }
3681
3682 write_quanta = yang_dnode_get_uint32(
3683 dnode, "./packet-quanta-config/wpkt-quanta");
3684 if (write_quanta != BGP_WRITE_PACKET_MAX)
3685 vty_out(vty, " write-quanta %d\n", write_quanta);
3686
3687 read_quanta = yang_dnode_get_uint32(
3688 dnode, "./packet-quanta-config/rpkt-quanta");
3689
3690 if (read_quanta != BGP_READ_PACKET_MAX)
3691 vty_out(vty, " read-quanta %d\n", read_quanta);
3692 }
3693
3694 DEFUN_YANG(bgp_listen_limit,
3695 bgp_listen_limit_cmd,
3696 "bgp listen limit (1-5000)",
3697 "BGP specific commands\n"
3698 "BGP Dynamic Neighbors listen commands\n"
3699 "Maximum number of BGP Dynamic Neighbors that can be created\n"
3700 "Configure Dynamic Neighbors listen limit value\n")
3701 {
3702 int idx_number = 3;
3703
3704 nb_cli_enqueue_change(
3705 vty, "./global/global-neighbor-config/dynamic-neighbors-limit",
3706 NB_OP_MODIFY, argv[idx_number]->arg);
3707
3708 return nb_cli_apply_changes(vty, NULL);
3709 }
3710
3711 DEFUN_YANG(no_bgp_listen_limit,
3712 no_bgp_listen_limit_cmd,
3713 "no bgp listen limit [(1-5000)]",
3714 NO_STR
3715 "BGP specific commands\n"
3716 "BGP Dynamic Neighbors listen commands\n"
3717 "Maximum number of BGP Dynamic Neighbors that can be created\n"
3718 "Configure Dynamic Neighbors listen limit value\n")
3719 {
3720 nb_cli_enqueue_change(
3721 vty, "./global/global-neighbor-config/dynamic-neighbors-limit",
3722 NB_OP_DESTROY, NULL);
3723
3724 return nb_cli_apply_changes(vty, NULL);
3725 }
3726
3727
3728 /*
3729 * Check if this listen range is already configured. Check for exact
3730 * match or overlap based on input.
3731 */
3732 static struct peer_group *listen_range_exists(struct bgp *bgp,
3733 struct prefix *range, int exact)
3734 {
3735 struct listnode *node, *nnode;
3736 struct listnode *node1, *nnode1;
3737 struct peer_group *group;
3738 struct prefix *lr;
3739 afi_t afi;
3740 int match;
3741
3742 afi = family2afi(range->family);
3743 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
3744 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
3745 lr)) {
3746 if (exact)
3747 match = prefix_same(range, lr);
3748 else
3749 match = (prefix_match(range, lr)
3750 || prefix_match(lr, range));
3751 if (match)
3752 return group;
3753 }
3754 }
3755
3756 return NULL;
3757 }
3758
3759 DEFUN (bgp_listen_range,
3760 bgp_listen_range_cmd,
3761 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
3762 "BGP specific commands\n"
3763 "Configure BGP dynamic neighbors listen range\n"
3764 "Configure BGP dynamic neighbors listen range\n"
3765 NEIGHBOR_ADDR_STR
3766 "Member of the peer-group\n"
3767 "Peer-group name\n")
3768 {
3769 VTY_DECLVAR_CONTEXT(bgp, bgp);
3770 struct prefix range;
3771 struct peer_group *group, *existing_group;
3772 afi_t afi;
3773 int ret;
3774 int idx = 0;
3775
3776 argv_find(argv, argc, "A.B.C.D/M", &idx);
3777 argv_find(argv, argc, "X:X::X:X/M", &idx);
3778 char *prefix = argv[idx]->arg;
3779 argv_find(argv, argc, "PGNAME", &idx);
3780 char *peergroup = argv[idx]->arg;
3781
3782 /* Convert IP prefix string to struct prefix. */
3783 ret = str2prefix(prefix, &range);
3784 if (!ret) {
3785 vty_out(vty, "%% Malformed listen range\n");
3786 return CMD_WARNING_CONFIG_FAILED;
3787 }
3788
3789 afi = family2afi(range.family);
3790
3791 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
3792 vty_out(vty,
3793 "%% Malformed listen range (link-local address)\n");
3794 return CMD_WARNING_CONFIG_FAILED;
3795 }
3796
3797 apply_mask(&range);
3798
3799 /* Check if same listen range is already configured. */
3800 existing_group = listen_range_exists(bgp, &range, 1);
3801 if (existing_group) {
3802 if (strcmp(existing_group->name, peergroup) == 0)
3803 return CMD_SUCCESS;
3804 else {
3805 vty_out(vty,
3806 "%% Same listen range is attached to peer-group %s\n",
3807 existing_group->name);
3808 return CMD_WARNING_CONFIG_FAILED;
3809 }
3810 }
3811
3812 /* Check if an overlapping listen range exists. */
3813 if (listen_range_exists(bgp, &range, 0)) {
3814 vty_out(vty,
3815 "%% Listen range overlaps with existing listen range\n");
3816 return CMD_WARNING_CONFIG_FAILED;
3817 }
3818
3819 group = peer_group_lookup(bgp, peergroup);
3820 if (!group) {
3821 vty_out(vty, "%% Configure the peer-group first\n");
3822 return CMD_WARNING_CONFIG_FAILED;
3823 }
3824
3825 ret = peer_group_listen_range_add(group, &range);
3826 return bgp_vty_return(vty, ret);
3827 }
3828
3829 DEFUN (no_bgp_listen_range,
3830 no_bgp_listen_range_cmd,
3831 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
3832 NO_STR
3833 "BGP specific commands\n"
3834 "Unconfigure BGP dynamic neighbors listen range\n"
3835 "Unconfigure BGP dynamic neighbors listen range\n"
3836 NEIGHBOR_ADDR_STR
3837 "Member of the peer-group\n"
3838 "Peer-group name\n")
3839 {
3840 VTY_DECLVAR_CONTEXT(bgp, bgp);
3841 struct prefix range;
3842 struct peer_group *group;
3843 afi_t afi;
3844 int ret;
3845 int idx = 0;
3846
3847 argv_find(argv, argc, "A.B.C.D/M", &idx);
3848 argv_find(argv, argc, "X:X::X:X/M", &idx);
3849 char *prefix = argv[idx]->arg;
3850 argv_find(argv, argc, "PGNAME", &idx);
3851 char *peergroup = argv[idx]->arg;
3852
3853 /* Convert IP prefix string to struct prefix. */
3854 ret = str2prefix(prefix, &range);
3855 if (!ret) {
3856 vty_out(vty, "%% Malformed listen range\n");
3857 return CMD_WARNING_CONFIG_FAILED;
3858 }
3859
3860 afi = family2afi(range.family);
3861
3862 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
3863 vty_out(vty,
3864 "%% Malformed listen range (link-local address)\n");
3865 return CMD_WARNING_CONFIG_FAILED;
3866 }
3867
3868 apply_mask(&range);
3869
3870 group = peer_group_lookup(bgp, peergroup);
3871 if (!group) {
3872 vty_out(vty, "%% Peer-group does not exist\n");
3873 return CMD_WARNING_CONFIG_FAILED;
3874 }
3875
3876 ret = peer_group_listen_range_del(group, &range);
3877 return bgp_vty_return(vty, ret);
3878 }
3879
3880 void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
3881 {
3882 struct peer_group *group;
3883 struct listnode *node, *nnode, *rnode, *nrnode;
3884 struct prefix *range;
3885 afi_t afi;
3886 char buf[PREFIX2STR_BUFFER];
3887
3888 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
3889 vty_out(vty, " bgp listen limit %d\n",
3890 bgp->dynamic_neighbors_limit);
3891
3892 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
3893 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
3894 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
3895 nrnode, range)) {
3896 prefix2str(range, buf, sizeof(buf));
3897 vty_out(vty,
3898 " bgp listen range %s peer-group %s\n",
3899 buf, group->name);
3900 }
3901 }
3902 }
3903 }
3904
3905
3906 DEFUN_YANG(bgp_disable_connected_route_check,
3907 bgp_disable_connected_route_check_cmd,
3908 "bgp disable-ebgp-connected-route-check",
3909 "BGP specific commands\n"
3910 "Disable checking if nexthop is connected on ebgp sessions\n")
3911 {
3912 nb_cli_enqueue_change(vty,
3913 "./global/ebgp-multihop-connected-route-check",
3914 NB_OP_MODIFY, "true");
3915
3916 return nb_cli_apply_changes(vty, NULL);
3917 }
3918
3919 DEFUN_YANG(no_bgp_disable_connected_route_check,
3920 no_bgp_disable_connected_route_check_cmd,
3921 "no bgp disable-ebgp-connected-route-check",
3922 NO_STR
3923 "BGP specific commands\n"
3924 "Disable checking if nexthop is connected on ebgp sessions\n")
3925 {
3926 nb_cli_enqueue_change(vty,
3927 "./global/ebgp-multihop-connected-route-check",
3928 NB_OP_MODIFY, "false");
3929
3930 return nb_cli_apply_changes(vty, NULL);
3931 }
3932
3933 void cli_show_router_global_ebgp_multihop_connected_route_check(
3934 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
3935 {
3936 if (yang_dnode_get_bool(dnode, NULL))
3937 vty_out(vty, " bgp disable-ebgp-connected-route-check\n");
3938 }
3939
3940 static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
3941 const char *as_str, afi_t afi, safi_t safi)
3942 {
3943 VTY_DECLVAR_CONTEXT(bgp, bgp);
3944 int ret;
3945 as_t as;
3946 int as_type = AS_SPECIFIED;
3947 union sockunion su;
3948
3949 if (as_str[0] == 'i') {
3950 as = 0;
3951 as_type = AS_INTERNAL;
3952 } else if (as_str[0] == 'e') {
3953 as = 0;
3954 as_type = AS_EXTERNAL;
3955 } else {
3956 /* Get AS number. */
3957 as = strtoul(as_str, NULL, 10);
3958 }
3959
3960 /* If peer is peer group or interface peer, call proper function. */
3961 ret = str2sockunion(peer_str, &su);
3962 if (ret < 0) {
3963 struct peer *peer;
3964
3965 /* Check if existing interface peer */
3966 peer = peer_lookup_by_conf_if(bgp, peer_str);
3967
3968 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, afi,
3969 safi);
3970
3971 /* if not interface peer, check peer-group settings */
3972 if (ret < 0 && !peer) {
3973 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
3974 if (ret < 0) {
3975 vty_out(vty,
3976 "%% Create the peer-group or interface first\n");
3977 return CMD_WARNING_CONFIG_FAILED;
3978 }
3979 return CMD_SUCCESS;
3980 }
3981 } else {
3982 if (peer_address_self_check(bgp, &su)) {
3983 vty_out(vty,
3984 "%% Can not configure the local system as neighbor\n");
3985 return CMD_WARNING_CONFIG_FAILED;
3986 }
3987 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, afi, safi);
3988 }
3989
3990 /* This peer belongs to peer group. */
3991 switch (ret) {
3992 case BGP_ERR_PEER_GROUP_MEMBER:
3993 vty_out(vty,
3994 "%% Peer-group member cannot override remote-as of peer-group\n");
3995 return CMD_WARNING_CONFIG_FAILED;
3996 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
3997 vty_out(vty,
3998 "%% Peer-group members must be all internal or all external\n");
3999 return CMD_WARNING_CONFIG_FAILED;
4000 }
4001 return bgp_vty_return(vty, ret);
4002 }
4003
4004 DEFUN_YANG(bgp_default_shutdown,
4005 bgp_default_shutdown_cmd,
4006 "[no] bgp default shutdown",
4007 NO_STR BGP_STR
4008 "Configure BGP defaults\n"
4009 "Apply administrative shutdown to newly configured peers\n")
4010 {
4011 nb_cli_enqueue_change(vty, "./global/default-shutdown", NB_OP_MODIFY,
4012 strmatch(argv[0]->text, "no") ? "false" : "true");
4013
4014 return nb_cli_apply_changes(vty, NULL);
4015 }
4016
4017 void cli_show_router_bgp_default_shutdown(struct vty *vty,
4018 struct lyd_node *dnode,
4019 bool show_defaults)
4020 {
4021 if (yang_dnode_get_bool(dnode, NULL))
4022 vty_out(vty, " bgp default shutdown\n");
4023 }
4024
4025 DEFPY(bgp_shutdown_msg, bgp_shutdown_msg_cmd, "bgp shutdown message MSG...",
4026 BGP_STR
4027 "Administrative shutdown of the BGP instance\n"
4028 "Add a shutdown message (RFC 8203)\n"
4029 "Shutdown message\n")
4030 {
4031 char *msgstr = NULL;
4032
4033 VTY_DECLVAR_CONTEXT(bgp, bgp);
4034
4035 if (argc > 3)
4036 msgstr = argv_concat(argv, argc, 3);
4037
4038 bgp_shutdown_enable(bgp, msgstr);
4039 XFREE(MTYPE_TMP, msgstr);
4040
4041 return CMD_SUCCESS;
4042 }
4043
4044 DEFPY(bgp_shutdown, bgp_shutdown_cmd, "bgp shutdown",
4045 BGP_STR "Administrative shutdown of the BGP instance\n")
4046 {
4047 VTY_DECLVAR_CONTEXT(bgp, bgp);
4048
4049 bgp_shutdown_enable(bgp, NULL);
4050
4051 return CMD_SUCCESS;
4052 }
4053
4054 DEFPY(no_bgp_shutdown, no_bgp_shutdown_cmd, "no bgp shutdown",
4055 NO_STR BGP_STR "Administrative shutdown of the BGP instance\n")
4056 {
4057 VTY_DECLVAR_CONTEXT(bgp, bgp);
4058
4059 bgp_shutdown_disable(bgp);
4060
4061 return CMD_SUCCESS;
4062 }
4063
4064 ALIAS(no_bgp_shutdown, no_bgp_shutdown_msg_cmd,
4065 "no bgp shutdown message MSG...", NO_STR BGP_STR
4066 "Administrative shutdown of the BGP instance\n"
4067 "Add a shutdown message (RFC 8203)\n" "Shutdown message\n")
4068
4069 DEFUN (neighbor_remote_as,
4070 neighbor_remote_as_cmd,
4071 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
4072 NEIGHBOR_STR
4073 NEIGHBOR_ADDR_STR2
4074 "Specify a BGP neighbor\n"
4075 AS_STR
4076 "Internal BGP peer\n"
4077 "External BGP peer\n")
4078 {
4079 int idx_peer = 1;
4080 int idx_remote_as = 3;
4081 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
4082 argv[idx_remote_as]->arg, AFI_IP,
4083 SAFI_UNICAST);
4084 }
4085
4086 static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
4087 afi_t afi, safi_t safi, int v6only,
4088 const char *peer_group_name,
4089 const char *as_str)
4090 {
4091 VTY_DECLVAR_CONTEXT(bgp, bgp);
4092 as_t as = 0;
4093 int as_type = AS_UNSPECIFIED;
4094 struct peer *peer;
4095 struct peer_group *group;
4096 int ret = 0;
4097 union sockunion su;
4098
4099 group = peer_group_lookup(bgp, conf_if);
4100
4101 if (group) {
4102 vty_out(vty, "%% Name conflict with peer-group \n");
4103 return CMD_WARNING_CONFIG_FAILED;
4104 }
4105
4106 if (as_str) {
4107 if (as_str[0] == 'i') {
4108 as_type = AS_INTERNAL;
4109 } else if (as_str[0] == 'e') {
4110 as_type = AS_EXTERNAL;
4111 } else {
4112 /* Get AS number. */
4113 as = strtoul(as_str, NULL, 10);
4114 as_type = AS_SPECIFIED;
4115 }
4116 }
4117
4118 peer = peer_lookup_by_conf_if(bgp, conf_if);
4119 if (peer) {
4120 if (as_str)
4121 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type,
4122 afi, safi);
4123 } else {
4124 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4)
4125 && afi == AFI_IP && safi == SAFI_UNICAST)
4126 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
4127 as_type, 0, 0, NULL);
4128 else
4129 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
4130 as_type, afi, safi, NULL);
4131
4132 if (!peer) {
4133 vty_out(vty, "%% BGP failed to create peer\n");
4134 return CMD_WARNING_CONFIG_FAILED;
4135 }
4136
4137 if (v6only)
4138 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
4139
4140 /* Request zebra to initiate IPv6 RAs on this interface. We do
4141 * this
4142 * any unnumbered peer in order to not worry about run-time
4143 * transitions
4144 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
4145 * address
4146 * gets deleted later etc.)
4147 */
4148 if (peer->ifp)
4149 bgp_zebra_initiate_radv(bgp, peer);
4150 }
4151
4152 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
4153 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
4154 if (v6only)
4155 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
4156 else
4157 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
4158
4159 /* v6only flag changed. Reset bgp seesion */
4160 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
4161 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
4162 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
4163 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
4164 } else
4165 bgp_session_reset(peer);
4166 }
4167
4168 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
4169 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
4170 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
4171 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
4172 }
4173
4174 if (peer_group_name) {
4175 group = peer_group_lookup(bgp, peer_group_name);
4176 if (!group) {
4177 vty_out(vty, "%% Configure the peer-group first\n");
4178 return CMD_WARNING_CONFIG_FAILED;
4179 }
4180
4181 ret = peer_group_bind(bgp, &su, peer, group, &as);
4182 }
4183
4184 return bgp_vty_return(vty, ret);
4185 }
4186
4187 DEFUN (neighbor_interface_config,
4188 neighbor_interface_config_cmd,
4189 "neighbor WORD interface [peer-group PGNAME]",
4190 NEIGHBOR_STR
4191 "Interface name or neighbor tag\n"
4192 "Enable BGP on interface\n"
4193 "Member of the peer-group\n"
4194 "Peer-group name\n")
4195 {
4196 int idx_word = 1;
4197 int idx_peer_group_word = 4;
4198
4199 if (argc > idx_peer_group_word)
4200 return peer_conf_interface_get(
4201 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
4202 argv[idx_peer_group_word]->arg, NULL);
4203 else
4204 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
4205 SAFI_UNICAST, 0, NULL, NULL);
4206 }
4207
4208 DEFUN (neighbor_interface_config_v6only,
4209 neighbor_interface_config_v6only_cmd,
4210 "neighbor WORD interface v6only [peer-group PGNAME]",
4211 NEIGHBOR_STR
4212 "Interface name or neighbor tag\n"
4213 "Enable BGP on interface\n"
4214 "Enable BGP with v6 link-local only\n"
4215 "Member of the peer-group\n"
4216 "Peer-group name\n")
4217 {
4218 int idx_word = 1;
4219 int idx_peer_group_word = 5;
4220
4221 if (argc > idx_peer_group_word)
4222 return peer_conf_interface_get(
4223 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
4224 argv[idx_peer_group_word]->arg, NULL);
4225
4226 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
4227 SAFI_UNICAST, 1, NULL, NULL);
4228 }
4229
4230
4231 DEFUN (neighbor_interface_config_remote_as,
4232 neighbor_interface_config_remote_as_cmd,
4233 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
4234 NEIGHBOR_STR
4235 "Interface name or neighbor tag\n"
4236 "Enable BGP on interface\n"
4237 "Specify a BGP neighbor\n"
4238 AS_STR
4239 "Internal BGP peer\n"
4240 "External BGP peer\n")
4241 {
4242 int idx_word = 1;
4243 int idx_remote_as = 4;
4244 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
4245 SAFI_UNICAST, 0, NULL,
4246 argv[idx_remote_as]->arg);
4247 }
4248
4249 DEFUN (neighbor_interface_v6only_config_remote_as,
4250 neighbor_interface_v6only_config_remote_as_cmd,
4251 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
4252 NEIGHBOR_STR
4253 "Interface name or neighbor tag\n"
4254 "Enable BGP with v6 link-local only\n"
4255 "Enable BGP on interface\n"
4256 "Specify a BGP neighbor\n"
4257 AS_STR
4258 "Internal BGP peer\n"
4259 "External BGP peer\n")
4260 {
4261 int idx_word = 1;
4262 int idx_remote_as = 5;
4263 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
4264 SAFI_UNICAST, 1, NULL,
4265 argv[idx_remote_as]->arg);
4266 }
4267
4268 DEFUN (neighbor_peer_group,
4269 neighbor_peer_group_cmd,
4270 "neighbor WORD peer-group",
4271 NEIGHBOR_STR
4272 "Interface name or neighbor tag\n"
4273 "Configure peer-group\n")
4274 {
4275 VTY_DECLVAR_CONTEXT(bgp, bgp);
4276 int idx_word = 1;
4277 struct peer *peer;
4278 struct peer_group *group;
4279
4280 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4281 if (peer) {
4282 vty_out(vty, "%% Name conflict with interface: \n");
4283 return CMD_WARNING_CONFIG_FAILED;
4284 }
4285
4286 group = peer_group_get(bgp, argv[idx_word]->arg);
4287 if (!group) {
4288 vty_out(vty, "%% BGP failed to find or create peer-group\n");
4289 return CMD_WARNING_CONFIG_FAILED;
4290 }
4291
4292 return CMD_SUCCESS;
4293 }
4294
4295 DEFUN (no_neighbor,
4296 no_neighbor_cmd,
4297 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
4298 NO_STR
4299 NEIGHBOR_STR
4300 NEIGHBOR_ADDR_STR2
4301 "Specify a BGP neighbor\n"
4302 AS_STR
4303 "Internal BGP peer\n"
4304 "External BGP peer\n")
4305 {
4306 VTY_DECLVAR_CONTEXT(bgp, bgp);
4307 int idx_peer = 2;
4308 int ret;
4309 union sockunion su;
4310 struct peer_group *group;
4311 struct peer *peer;
4312 struct peer *other;
4313
4314 ret = str2sockunion(argv[idx_peer]->arg, &su);
4315 if (ret < 0) {
4316 /* look up for neighbor by interface name config. */
4317 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4318 if (peer) {
4319 /* Request zebra to terminate IPv6 RAs on this
4320 * interface. */
4321 if (peer->ifp)
4322 bgp_zebra_terminate_radv(peer->bgp, peer);
4323 peer_notify_unconfig(peer);
4324 peer_delete(peer);
4325 return CMD_SUCCESS;
4326 }
4327
4328 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
4329 if (group) {
4330 peer_group_notify_unconfig(group);
4331 peer_group_delete(group);
4332 } else {
4333 vty_out(vty, "%% Create the peer-group first\n");
4334 return CMD_WARNING_CONFIG_FAILED;
4335 }
4336 } else {
4337 peer = peer_lookup(bgp, &su);
4338 if (peer) {
4339 if (peer_dynamic_neighbor(peer)) {
4340 vty_out(vty,
4341 "%% Operation not allowed on a dynamic neighbor\n");
4342 return CMD_WARNING_CONFIG_FAILED;
4343 }
4344
4345 other = peer->doppelganger;
4346
4347 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
4348 bgp_zebra_terminate_radv(peer->bgp, peer);
4349
4350 peer_notify_unconfig(peer);
4351 peer_delete(peer);
4352 if (other && other->status != Deleted) {
4353 peer_notify_unconfig(other);
4354 peer_delete(other);
4355 }
4356 }
4357 }
4358
4359 return CMD_SUCCESS;
4360 }
4361
4362 DEFUN (no_neighbor_interface_config,
4363 no_neighbor_interface_config_cmd,
4364 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
4365 NO_STR
4366 NEIGHBOR_STR
4367 "Interface name\n"
4368 "Configure BGP on interface\n"
4369 "Enable BGP with v6 link-local only\n"
4370 "Member of the peer-group\n"
4371 "Peer-group name\n"
4372 "Specify a BGP neighbor\n"
4373 AS_STR
4374 "Internal BGP peer\n"
4375 "External BGP peer\n")
4376 {
4377 VTY_DECLVAR_CONTEXT(bgp, bgp);
4378 int idx_word = 2;
4379 struct peer *peer;
4380
4381 /* look up for neighbor by interface name config. */
4382 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4383 if (peer) {
4384 /* Request zebra to terminate IPv6 RAs on this interface. */
4385 if (peer->ifp)
4386 bgp_zebra_terminate_radv(peer->bgp, peer);
4387 peer_notify_unconfig(peer);
4388 peer_delete(peer);
4389 } else {
4390 vty_out(vty, "%% Create the bgp interface first\n");
4391 return CMD_WARNING_CONFIG_FAILED;
4392 }
4393 return CMD_SUCCESS;
4394 }
4395
4396 DEFUN (no_neighbor_peer_group,
4397 no_neighbor_peer_group_cmd,
4398 "no neighbor WORD peer-group",
4399 NO_STR
4400 NEIGHBOR_STR
4401 "Neighbor tag\n"
4402 "Configure peer-group\n")
4403 {
4404 VTY_DECLVAR_CONTEXT(bgp, bgp);
4405 int idx_word = 2;
4406 struct peer_group *group;
4407
4408 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4409 if (group) {
4410 peer_group_notify_unconfig(group);
4411 peer_group_delete(group);
4412 } else {
4413 vty_out(vty, "%% Create the peer-group first\n");
4414 return CMD_WARNING_CONFIG_FAILED;
4415 }
4416 return CMD_SUCCESS;
4417 }
4418
4419 DEFUN (no_neighbor_interface_peer_group_remote_as,
4420 no_neighbor_interface_peer_group_remote_as_cmd,
4421 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
4422 NO_STR
4423 NEIGHBOR_STR
4424 "Interface name or neighbor tag\n"
4425 "Specify a BGP neighbor\n"
4426 AS_STR
4427 "Internal BGP peer\n"
4428 "External BGP peer\n")
4429 {
4430 VTY_DECLVAR_CONTEXT(bgp, bgp);
4431 int idx_word = 2;
4432 struct peer_group *group;
4433 struct peer *peer;
4434
4435 /* look up for neighbor by interface name config. */
4436 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4437 if (peer) {
4438 peer_as_change(peer, 0, AS_UNSPECIFIED);
4439 return CMD_SUCCESS;
4440 }
4441
4442 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4443 if (group)
4444 peer_group_remote_as_delete(group);
4445 else {
4446 vty_out(vty, "%% Create the peer-group or interface first\n");
4447 return CMD_WARNING_CONFIG_FAILED;
4448 }
4449 return CMD_SUCCESS;
4450 }
4451
4452 DEFUN (neighbor_local_as,
4453 neighbor_local_as_cmd,
4454 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
4455 NEIGHBOR_STR
4456 NEIGHBOR_ADDR_STR2
4457 "Specify a local-as number\n"
4458 "AS number used as local AS\n")
4459 {
4460 int idx_peer = 1;
4461 int idx_number = 3;
4462 struct peer *peer;
4463 int ret;
4464 as_t as;
4465
4466 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4467 if (!peer)
4468 return CMD_WARNING_CONFIG_FAILED;
4469
4470 as = strtoul(argv[idx_number]->arg, NULL, 10);
4471 ret = peer_local_as_set(peer, as, 0, 0);
4472 return bgp_vty_return(vty, ret);
4473 }
4474
4475 DEFUN (neighbor_local_as_no_prepend,
4476 neighbor_local_as_no_prepend_cmd,
4477 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
4478 NEIGHBOR_STR
4479 NEIGHBOR_ADDR_STR2
4480 "Specify a local-as number\n"
4481 "AS number used as local AS\n"
4482 "Do not prepend local-as to updates from ebgp peers\n")
4483 {
4484 int idx_peer = 1;
4485 int idx_number = 3;
4486 struct peer *peer;
4487 int ret;
4488 as_t as;
4489
4490 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4491 if (!peer)
4492 return CMD_WARNING_CONFIG_FAILED;
4493
4494 as = strtoul(argv[idx_number]->arg, NULL, 10);
4495 ret = peer_local_as_set(peer, as, 1, 0);
4496 return bgp_vty_return(vty, ret);
4497 }
4498
4499 DEFUN (neighbor_local_as_no_prepend_replace_as,
4500 neighbor_local_as_no_prepend_replace_as_cmd,
4501 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
4502 NEIGHBOR_STR
4503 NEIGHBOR_ADDR_STR2
4504 "Specify a local-as number\n"
4505 "AS number used as local AS\n"
4506 "Do not prepend local-as to updates from ebgp peers\n"
4507 "Do not prepend local-as to updates from ibgp peers\n")
4508 {
4509 int idx_peer = 1;
4510 int idx_number = 3;
4511 struct peer *peer;
4512 int ret;
4513 as_t as;
4514
4515 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4516 if (!peer)
4517 return CMD_WARNING_CONFIG_FAILED;
4518
4519 as = strtoul(argv[idx_number]->arg, NULL, 10);
4520 ret = peer_local_as_set(peer, as, 1, 1);
4521 return bgp_vty_return(vty, ret);
4522 }
4523
4524 DEFUN (no_neighbor_local_as,
4525 no_neighbor_local_as_cmd,
4526 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
4527 NO_STR
4528 NEIGHBOR_STR
4529 NEIGHBOR_ADDR_STR2
4530 "Specify a local-as number\n"
4531 "AS number used as local AS\n"
4532 "Do not prepend local-as to updates from ebgp peers\n"
4533 "Do not prepend local-as to updates from ibgp peers\n")
4534 {
4535 int idx_peer = 2;
4536 struct peer *peer;
4537 int ret;
4538
4539 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4540 if (!peer)
4541 return CMD_WARNING_CONFIG_FAILED;
4542
4543 ret = peer_local_as_unset(peer);
4544 return bgp_vty_return(vty, ret);
4545 }
4546
4547
4548 DEFUN (neighbor_solo,
4549 neighbor_solo_cmd,
4550 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
4551 NEIGHBOR_STR
4552 NEIGHBOR_ADDR_STR2
4553 "Solo peer - part of its own update group\n")
4554 {
4555 int idx_peer = 1;
4556 struct peer *peer;
4557 int ret;
4558
4559 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4560 if (!peer)
4561 return CMD_WARNING_CONFIG_FAILED;
4562
4563 ret = update_group_adjust_soloness(peer, 1);
4564 return bgp_vty_return(vty, ret);
4565 }
4566
4567 DEFUN (no_neighbor_solo,
4568 no_neighbor_solo_cmd,
4569 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
4570 NO_STR
4571 NEIGHBOR_STR
4572 NEIGHBOR_ADDR_STR2
4573 "Solo peer - part of its own update group\n")
4574 {
4575 int idx_peer = 2;
4576 struct peer *peer;
4577 int ret;
4578
4579 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4580 if (!peer)
4581 return CMD_WARNING_CONFIG_FAILED;
4582
4583 ret = update_group_adjust_soloness(peer, 0);
4584 return bgp_vty_return(vty, ret);
4585 }
4586
4587 DEFUN (neighbor_password,
4588 neighbor_password_cmd,
4589 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
4590 NEIGHBOR_STR
4591 NEIGHBOR_ADDR_STR2
4592 "Set a password\n"
4593 "The password\n")
4594 {
4595 int idx_peer = 1;
4596 int idx_line = 3;
4597 struct peer *peer;
4598 int ret;
4599
4600 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4601 if (!peer)
4602 return CMD_WARNING_CONFIG_FAILED;
4603
4604 ret = peer_password_set(peer, argv[idx_line]->arg);
4605 return bgp_vty_return(vty, ret);
4606 }
4607
4608 DEFUN (no_neighbor_password,
4609 no_neighbor_password_cmd,
4610 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
4611 NO_STR
4612 NEIGHBOR_STR
4613 NEIGHBOR_ADDR_STR2
4614 "Set a password\n"
4615 "The password\n")
4616 {
4617 int idx_peer = 2;
4618 struct peer *peer;
4619 int ret;
4620
4621 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4622 if (!peer)
4623 return CMD_WARNING_CONFIG_FAILED;
4624
4625 ret = peer_password_unset(peer);
4626 return bgp_vty_return(vty, ret);
4627 }
4628
4629 DEFUN (neighbor_activate,
4630 neighbor_activate_cmd,
4631 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4632 NEIGHBOR_STR
4633 NEIGHBOR_ADDR_STR2
4634 "Enable the Address Family for this Neighbor\n")
4635 {
4636 int idx_peer = 1;
4637 int ret;
4638 struct peer *peer;
4639
4640 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4641 if (!peer)
4642 return CMD_WARNING_CONFIG_FAILED;
4643
4644 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
4645 return bgp_vty_return(vty, ret);
4646 }
4647
4648 ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
4649 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4650 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4651 "Enable the Address Family for this Neighbor\n")
4652
4653 DEFUN (no_neighbor_activate,
4654 no_neighbor_activate_cmd,
4655 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4656 NO_STR
4657 NEIGHBOR_STR
4658 NEIGHBOR_ADDR_STR2
4659 "Enable the Address Family for this Neighbor\n")
4660 {
4661 int idx_peer = 2;
4662 int ret;
4663 struct peer *peer;
4664
4665 /* Lookup peer. */
4666 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4667 if (!peer)
4668 return CMD_WARNING_CONFIG_FAILED;
4669
4670 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
4671 return bgp_vty_return(vty, ret);
4672 }
4673
4674 ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
4675 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4676 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4677 "Enable the Address Family for this Neighbor\n")
4678
4679 DEFUN (neighbor_set_peer_group,
4680 neighbor_set_peer_group_cmd,
4681 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
4682 NEIGHBOR_STR
4683 NEIGHBOR_ADDR_STR2
4684 "Member of the peer-group\n"
4685 "Peer-group name\n")
4686 {
4687 VTY_DECLVAR_CONTEXT(bgp, bgp);
4688 int idx_peer = 1;
4689 int idx_word = 3;
4690 int ret;
4691 as_t as;
4692 union sockunion su;
4693 struct peer *peer;
4694 struct peer_group *group;
4695
4696 ret = str2sockunion(argv[idx_peer]->arg, &su);
4697 if (ret < 0) {
4698 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4699 if (!peer) {
4700 vty_out(vty, "%% Malformed address or name: %s\n",
4701 argv[idx_peer]->arg);
4702 return CMD_WARNING_CONFIG_FAILED;
4703 }
4704 } else {
4705 if (peer_address_self_check(bgp, &su)) {
4706 vty_out(vty,
4707 "%% Can not configure the local system as neighbor\n");
4708 return CMD_WARNING_CONFIG_FAILED;
4709 }
4710
4711 /* Disallow for dynamic neighbor. */
4712 peer = peer_lookup(bgp, &su);
4713 if (peer && peer_dynamic_neighbor(peer)) {
4714 vty_out(vty,
4715 "%% Operation not allowed on a dynamic neighbor\n");
4716 return CMD_WARNING_CONFIG_FAILED;
4717 }
4718 }
4719
4720 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4721 if (!group) {
4722 vty_out(vty, "%% Configure the peer-group first\n");
4723 return CMD_WARNING_CONFIG_FAILED;
4724 }
4725
4726 ret = peer_group_bind(bgp, &su, peer, group, &as);
4727
4728 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
4729 vty_out(vty,
4730 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
4731 as);
4732 return CMD_WARNING_CONFIG_FAILED;
4733 }
4734
4735 return bgp_vty_return(vty, ret);
4736 }
4737
4738 ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
4739 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
4740 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4741 "Member of the peer-group\n"
4742 "Peer-group name\n")
4743
4744 DEFUN (no_neighbor_set_peer_group,
4745 no_neighbor_set_peer_group_cmd,
4746 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
4747 NO_STR
4748 NEIGHBOR_STR
4749 NEIGHBOR_ADDR_STR2
4750 "Member of the peer-group\n"
4751 "Peer-group name\n")
4752 {
4753 VTY_DECLVAR_CONTEXT(bgp, bgp);
4754 int idx_peer = 2;
4755 int idx_word = 4;
4756 int ret;
4757 struct peer *peer;
4758 struct peer_group *group;
4759
4760 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
4761 if (!peer)
4762 return CMD_WARNING_CONFIG_FAILED;
4763
4764 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4765 if (!group) {
4766 vty_out(vty, "%% Configure the peer-group first\n");
4767 return CMD_WARNING_CONFIG_FAILED;
4768 }
4769
4770 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
4771 bgp_zebra_terminate_radv(peer->bgp, peer);
4772
4773 peer_notify_unconfig(peer);
4774 ret = peer_delete(peer);
4775
4776 return bgp_vty_return(vty, ret);
4777 }
4778
4779 ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
4780 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
4781 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4782 "Member of the peer-group\n"
4783 "Peer-group name\n")
4784
4785 static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
4786 uint32_t flag, int set)
4787 {
4788 int ret;
4789 struct peer *peer;
4790
4791 peer = peer_and_group_lookup_vty(vty, ip_str);
4792 if (!peer)
4793 return CMD_WARNING_CONFIG_FAILED;
4794
4795 /*
4796 * If 'neighbor <interface>', then this is for directly connected peers,
4797 * we should not accept disable-connected-check.
4798 */
4799 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
4800 vty_out(vty,
4801 "%s is directly connected peer, cannot accept disable-connected-check\n",
4802 ip_str);
4803 return CMD_WARNING_CONFIG_FAILED;
4804 }
4805
4806 if (!set && flag == PEER_FLAG_SHUTDOWN)
4807 peer_tx_shutdown_message_unset(peer);
4808
4809 if (set)
4810 ret = peer_flag_set(peer, flag);
4811 else
4812 ret = peer_flag_unset(peer, flag);
4813
4814 return bgp_vty_return(vty, ret);
4815 }
4816
4817 static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
4818 {
4819 return peer_flag_modify_vty(vty, ip_str, flag, 1);
4820 }
4821
4822 static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
4823 uint32_t flag)
4824 {
4825 return peer_flag_modify_vty(vty, ip_str, flag, 0);
4826 }
4827
4828 /* neighbor passive. */
4829 DEFUN (neighbor_passive,
4830 neighbor_passive_cmd,
4831 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
4832 NEIGHBOR_STR
4833 NEIGHBOR_ADDR_STR2
4834 "Don't send open messages to this neighbor\n")
4835 {
4836 int idx_peer = 1;
4837 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
4838 }
4839
4840 DEFUN (no_neighbor_passive,
4841 no_neighbor_passive_cmd,
4842 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
4843 NO_STR
4844 NEIGHBOR_STR
4845 NEIGHBOR_ADDR_STR2
4846 "Don't send open messages to this neighbor\n")
4847 {
4848 int idx_peer = 2;
4849 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
4850 }
4851
4852 /* neighbor shutdown. */
4853 DEFUN (neighbor_shutdown_msg,
4854 neighbor_shutdown_msg_cmd,
4855 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
4856 NEIGHBOR_STR
4857 NEIGHBOR_ADDR_STR2
4858 "Administratively shut down this neighbor\n"
4859 "Add a shutdown message (RFC 8203)\n"
4860 "Shutdown message\n")
4861 {
4862 int idx_peer = 1;
4863
4864 if (argc >= 5) {
4865 struct peer *peer =
4866 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4867 char *message;
4868
4869 if (!peer)
4870 return CMD_WARNING_CONFIG_FAILED;
4871 message = argv_concat(argv, argc, 4);
4872 peer_tx_shutdown_message_set(peer, message);
4873 XFREE(MTYPE_TMP, message);
4874 }
4875
4876 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
4877 }
4878
4879 ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
4880 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
4881 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4882 "Administratively shut down this neighbor\n")
4883
4884 DEFUN (no_neighbor_shutdown_msg,
4885 no_neighbor_shutdown_msg_cmd,
4886 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
4887 NO_STR
4888 NEIGHBOR_STR
4889 NEIGHBOR_ADDR_STR2
4890 "Administratively shut down this neighbor\n"
4891 "Remove a shutdown message (RFC 8203)\n"
4892 "Shutdown message\n")
4893 {
4894 int idx_peer = 2;
4895
4896 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4897 PEER_FLAG_SHUTDOWN);
4898 }
4899
4900 ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
4901 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
4902 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4903 "Administratively shut down this neighbor\n")
4904
4905 DEFUN(neighbor_shutdown_rtt,
4906 neighbor_shutdown_rtt_cmd,
4907 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt (1-65535) [count (1-255)]",
4908 NEIGHBOR_STR
4909 NEIGHBOR_ADDR_STR2
4910 "Administratively shut down this neighbor\n"
4911 "Shutdown if round-trip-time is higher than expected\n"
4912 "Round-trip-time in milliseconds\n"
4913 "Specify the number of keepalives before shutdown\n"
4914 "The number of keepalives with higher RTT to shutdown\n")
4915 {
4916 int idx_peer = 1;
4917 int idx_rtt = 4;
4918 int idx_count = 0;
4919 struct peer *peer;
4920
4921 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4922
4923 if (!peer)
4924 return CMD_WARNING_CONFIG_FAILED;
4925
4926 peer->rtt_expected = strtol(argv[idx_rtt]->arg, NULL, 10);
4927
4928 if (argv_find(argv, argc, "count", &idx_count))
4929 peer->rtt_keepalive_conf =
4930 strtol(argv[idx_count + 1]->arg, NULL, 10);
4931
4932 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4933 PEER_FLAG_RTT_SHUTDOWN);
4934 }
4935
4936 DEFUN(no_neighbor_shutdown_rtt,
4937 no_neighbor_shutdown_rtt_cmd,
4938 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt [(1-65535) [count (1-255)]]",
4939 NO_STR
4940 NEIGHBOR_STR
4941 NEIGHBOR_ADDR_STR2
4942 "Administratively shut down this neighbor\n"
4943 "Shutdown if round-trip-time is higher than expected\n"
4944 "Round-trip-time in milliseconds\n"
4945 "Specify the number of keepalives before shutdown\n"
4946 "The number of keepalives with higher RTT to shutdown\n")
4947 {
4948 int idx_peer = 2;
4949 struct peer *peer;
4950
4951 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4952
4953 if (!peer)
4954 return CMD_WARNING_CONFIG_FAILED;
4955
4956 peer->rtt_expected = 0;
4957 peer->rtt_keepalive_conf = 1;
4958
4959 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4960 PEER_FLAG_RTT_SHUTDOWN);
4961 }
4962
4963 /* neighbor capability dynamic. */
4964 DEFUN (neighbor_capability_dynamic,
4965 neighbor_capability_dynamic_cmd,
4966 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
4967 NEIGHBOR_STR
4968 NEIGHBOR_ADDR_STR2
4969 "Advertise capability to the peer\n"
4970 "Advertise dynamic capability to this neighbor\n")
4971 {
4972 int idx_peer = 1;
4973 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4974 PEER_FLAG_DYNAMIC_CAPABILITY);
4975 }
4976
4977 DEFUN (no_neighbor_capability_dynamic,
4978 no_neighbor_capability_dynamic_cmd,
4979 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
4980 NO_STR
4981 NEIGHBOR_STR
4982 NEIGHBOR_ADDR_STR2
4983 "Advertise capability to the peer\n"
4984 "Advertise dynamic capability to this neighbor\n")
4985 {
4986 int idx_peer = 2;
4987 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4988 PEER_FLAG_DYNAMIC_CAPABILITY);
4989 }
4990
4991 /* neighbor dont-capability-negotiate */
4992 DEFUN (neighbor_dont_capability_negotiate,
4993 neighbor_dont_capability_negotiate_cmd,
4994 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
4995 NEIGHBOR_STR
4996 NEIGHBOR_ADDR_STR2
4997 "Do not perform capability negotiation\n")
4998 {
4999 int idx_peer = 1;
5000 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5001 PEER_FLAG_DONT_CAPABILITY);
5002 }
5003
5004 DEFUN (no_neighbor_dont_capability_negotiate,
5005 no_neighbor_dont_capability_negotiate_cmd,
5006 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
5007 NO_STR
5008 NEIGHBOR_STR
5009 NEIGHBOR_ADDR_STR2
5010 "Do not perform capability negotiation\n")
5011 {
5012 int idx_peer = 2;
5013 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5014 PEER_FLAG_DONT_CAPABILITY);
5015 }
5016
5017 /* neighbor capability extended next hop encoding */
5018 DEFUN (neighbor_capability_enhe,
5019 neighbor_capability_enhe_cmd,
5020 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5021 NEIGHBOR_STR
5022 NEIGHBOR_ADDR_STR2
5023 "Advertise capability to the peer\n"
5024 "Advertise extended next-hop capability to the peer\n")
5025 {
5026 int idx_peer = 1;
5027 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5028 PEER_FLAG_CAPABILITY_ENHE);
5029 }
5030
5031 DEFUN (no_neighbor_capability_enhe,
5032 no_neighbor_capability_enhe_cmd,
5033 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5034 NO_STR
5035 NEIGHBOR_STR
5036 NEIGHBOR_ADDR_STR2
5037 "Advertise capability to the peer\n"
5038 "Advertise extended next-hop capability to the peer\n")
5039 {
5040 int idx_peer = 2;
5041 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5042 PEER_FLAG_CAPABILITY_ENHE);
5043 }
5044
5045 static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
5046 afi_t afi, safi_t safi, uint32_t flag,
5047 int set)
5048 {
5049 int ret;
5050 struct peer *peer;
5051
5052 peer = peer_and_group_lookup_vty(vty, peer_str);
5053 if (!peer)
5054 return CMD_WARNING_CONFIG_FAILED;
5055
5056 if (set)
5057 ret = peer_af_flag_set(peer, afi, safi, flag);
5058 else
5059 ret = peer_af_flag_unset(peer, afi, safi, flag);
5060
5061 return bgp_vty_return(vty, ret);
5062 }
5063
5064 static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
5065 afi_t afi, safi_t safi, uint32_t flag)
5066 {
5067 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
5068 }
5069
5070 static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
5071 afi_t afi, safi_t safi, uint32_t flag)
5072 {
5073 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
5074 }
5075
5076 /* neighbor capability orf prefix-list. */
5077 DEFUN (neighbor_capability_orf_prefix,
5078 neighbor_capability_orf_prefix_cmd,
5079 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5080 NEIGHBOR_STR
5081 NEIGHBOR_ADDR_STR2
5082 "Advertise capability to the peer\n"
5083 "Advertise ORF capability to the peer\n"
5084 "Advertise prefixlist ORF capability to this neighbor\n"
5085 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5086 "Capability to RECEIVE the ORF from this neighbor\n"
5087 "Capability to SEND the ORF to this neighbor\n")
5088 {
5089 int idx_send_recv = 5;
5090 char *peer_str = argv[1]->arg;
5091 struct peer *peer;
5092 afi_t afi = bgp_node_afi(vty);
5093 safi_t safi = bgp_node_safi(vty);
5094
5095 peer = peer_and_group_lookup_vty(vty, peer_str);
5096 if (!peer)
5097 return CMD_WARNING_CONFIG_FAILED;
5098
5099 if (strmatch(argv[idx_send_recv]->text, "send"))
5100 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5101 PEER_FLAG_ORF_PREFIX_SM);
5102
5103 if (strmatch(argv[idx_send_recv]->text, "receive"))
5104 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5105 PEER_FLAG_ORF_PREFIX_RM);
5106
5107 if (strmatch(argv[idx_send_recv]->text, "both"))
5108 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5109 PEER_FLAG_ORF_PREFIX_SM)
5110 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5111 PEER_FLAG_ORF_PREFIX_RM);
5112
5113 return CMD_WARNING_CONFIG_FAILED;
5114 }
5115
5116 ALIAS_HIDDEN(
5117 neighbor_capability_orf_prefix,
5118 neighbor_capability_orf_prefix_hidden_cmd,
5119 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5120 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5121 "Advertise capability to the peer\n"
5122 "Advertise ORF capability to the peer\n"
5123 "Advertise prefixlist ORF capability to this neighbor\n"
5124 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5125 "Capability to RECEIVE the ORF from this neighbor\n"
5126 "Capability to SEND the ORF to this neighbor\n")
5127
5128 DEFUN (no_neighbor_capability_orf_prefix,
5129 no_neighbor_capability_orf_prefix_cmd,
5130 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5131 NO_STR
5132 NEIGHBOR_STR
5133 NEIGHBOR_ADDR_STR2
5134 "Advertise capability to the peer\n"
5135 "Advertise ORF capability to the peer\n"
5136 "Advertise prefixlist ORF capability to this neighbor\n"
5137 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5138 "Capability to RECEIVE the ORF from this neighbor\n"
5139 "Capability to SEND the ORF to this neighbor\n")
5140 {
5141 int idx_send_recv = 6;
5142 char *peer_str = argv[2]->arg;
5143 struct peer *peer;
5144 afi_t afi = bgp_node_afi(vty);
5145 safi_t safi = bgp_node_safi(vty);
5146
5147 peer = peer_and_group_lookup_vty(vty, peer_str);
5148 if (!peer)
5149 return CMD_WARNING_CONFIG_FAILED;
5150
5151 if (strmatch(argv[idx_send_recv]->text, "send"))
5152 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5153 PEER_FLAG_ORF_PREFIX_SM);
5154
5155 if (strmatch(argv[idx_send_recv]->text, "receive"))
5156 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5157 PEER_FLAG_ORF_PREFIX_RM);
5158
5159 if (strmatch(argv[idx_send_recv]->text, "both"))
5160 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5161 PEER_FLAG_ORF_PREFIX_SM)
5162 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5163 PEER_FLAG_ORF_PREFIX_RM);
5164
5165 return CMD_WARNING_CONFIG_FAILED;
5166 }
5167
5168 ALIAS_HIDDEN(
5169 no_neighbor_capability_orf_prefix,
5170 no_neighbor_capability_orf_prefix_hidden_cmd,
5171 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5172 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5173 "Advertise capability to the peer\n"
5174 "Advertise ORF capability to the peer\n"
5175 "Advertise prefixlist ORF capability to this neighbor\n"
5176 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5177 "Capability to RECEIVE the ORF from this neighbor\n"
5178 "Capability to SEND the ORF to this neighbor\n")
5179
5180 /* neighbor next-hop-self. */
5181 DEFUN (neighbor_nexthop_self,
5182 neighbor_nexthop_self_cmd,
5183 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5184 NEIGHBOR_STR
5185 NEIGHBOR_ADDR_STR2
5186 "Disable the next hop calculation for this neighbor\n")
5187 {
5188 int idx_peer = 1;
5189 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5190 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
5191 }
5192
5193 ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
5194 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5195 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5196 "Disable the next hop calculation for this neighbor\n")
5197
5198 /* neighbor next-hop-self. */
5199 DEFUN (neighbor_nexthop_self_force,
5200 neighbor_nexthop_self_force_cmd,
5201 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5202 NEIGHBOR_STR
5203 NEIGHBOR_ADDR_STR2
5204 "Disable the next hop calculation for this neighbor\n"
5205 "Set the next hop to self for reflected routes\n")
5206 {
5207 int idx_peer = 1;
5208 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5209 bgp_node_safi(vty),
5210 PEER_FLAG_FORCE_NEXTHOP_SELF);
5211 }
5212
5213 ALIAS_HIDDEN(neighbor_nexthop_self_force,
5214 neighbor_nexthop_self_force_hidden_cmd,
5215 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5216 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5217 "Disable the next hop calculation for this neighbor\n"
5218 "Set the next hop to self for reflected routes\n")
5219
5220 ALIAS_HIDDEN(neighbor_nexthop_self_force,
5221 neighbor_nexthop_self_all_hidden_cmd,
5222 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5223 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5224 "Disable the next hop calculation for this neighbor\n"
5225 "Set the next hop to self for reflected routes\n")
5226
5227 DEFUN (no_neighbor_nexthop_self,
5228 no_neighbor_nexthop_self_cmd,
5229 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5230 NO_STR
5231 NEIGHBOR_STR
5232 NEIGHBOR_ADDR_STR2
5233 "Disable the next hop calculation for this neighbor\n")
5234 {
5235 int idx_peer = 2;
5236 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5237 bgp_node_afi(vty), bgp_node_safi(vty),
5238 PEER_FLAG_NEXTHOP_SELF);
5239 }
5240
5241 ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
5242 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5243 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5244 "Disable the next hop calculation for this neighbor\n")
5245
5246 DEFUN (no_neighbor_nexthop_self_force,
5247 no_neighbor_nexthop_self_force_cmd,
5248 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5249 NO_STR
5250 NEIGHBOR_STR
5251 NEIGHBOR_ADDR_STR2
5252 "Disable the next hop calculation for this neighbor\n"
5253 "Set the next hop to self for reflected routes\n")
5254 {
5255 int idx_peer = 2;
5256 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5257 bgp_node_afi(vty), bgp_node_safi(vty),
5258 PEER_FLAG_FORCE_NEXTHOP_SELF);
5259 }
5260
5261 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5262 no_neighbor_nexthop_self_force_hidden_cmd,
5263 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5264 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5265 "Disable the next hop calculation for this neighbor\n"
5266 "Set the next hop to self for reflected routes\n")
5267
5268 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5269 no_neighbor_nexthop_self_all_hidden_cmd,
5270 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5271 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5272 "Disable the next hop calculation for this neighbor\n"
5273 "Set the next hop to self for reflected routes\n")
5274
5275 /* neighbor as-override */
5276 DEFUN (neighbor_as_override,
5277 neighbor_as_override_cmd,
5278 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5279 NEIGHBOR_STR
5280 NEIGHBOR_ADDR_STR2
5281 "Override ASNs in outbound updates if aspath equals remote-as\n")
5282 {
5283 int idx_peer = 1;
5284 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5285 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
5286 }
5287
5288 ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
5289 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5290 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5291 "Override ASNs in outbound updates if aspath equals remote-as\n")
5292
5293 DEFUN (no_neighbor_as_override,
5294 no_neighbor_as_override_cmd,
5295 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5296 NO_STR
5297 NEIGHBOR_STR
5298 NEIGHBOR_ADDR_STR2
5299 "Override ASNs in outbound updates if aspath equals remote-as\n")
5300 {
5301 int idx_peer = 2;
5302 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5303 bgp_node_afi(vty), bgp_node_safi(vty),
5304 PEER_FLAG_AS_OVERRIDE);
5305 }
5306
5307 ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
5308 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5309 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5310 "Override ASNs in outbound updates if aspath equals remote-as\n")
5311
5312 /* neighbor remove-private-AS. */
5313 DEFUN (neighbor_remove_private_as,
5314 neighbor_remove_private_as_cmd,
5315 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5316 NEIGHBOR_STR
5317 NEIGHBOR_ADDR_STR2
5318 "Remove private ASNs in outbound updates\n")
5319 {
5320 int idx_peer = 1;
5321 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5322 bgp_node_safi(vty),
5323 PEER_FLAG_REMOVE_PRIVATE_AS);
5324 }
5325
5326 ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
5327 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5328 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5329 "Remove private ASNs in outbound updates\n")
5330
5331 DEFUN (neighbor_remove_private_as_all,
5332 neighbor_remove_private_as_all_cmd,
5333 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5334 NEIGHBOR_STR
5335 NEIGHBOR_ADDR_STR2
5336 "Remove private ASNs in outbound updates\n"
5337 "Apply to all AS numbers\n")
5338 {
5339 int idx_peer = 1;
5340 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5341 bgp_node_safi(vty),
5342 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5343 }
5344
5345 ALIAS_HIDDEN(neighbor_remove_private_as_all,
5346 neighbor_remove_private_as_all_hidden_cmd,
5347 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5348 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5349 "Remove private ASNs in outbound updates\n"
5350 "Apply to all AS numbers")
5351
5352 DEFUN (neighbor_remove_private_as_replace_as,
5353 neighbor_remove_private_as_replace_as_cmd,
5354 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5355 NEIGHBOR_STR
5356 NEIGHBOR_ADDR_STR2
5357 "Remove private ASNs in outbound updates\n"
5358 "Replace private ASNs with our ASN in outbound updates\n")
5359 {
5360 int idx_peer = 1;
5361 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5362 bgp_node_safi(vty),
5363 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5364 }
5365
5366 ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
5367 neighbor_remove_private_as_replace_as_hidden_cmd,
5368 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5369 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5370 "Remove private ASNs in outbound updates\n"
5371 "Replace private ASNs with our ASN in outbound updates\n")
5372
5373 DEFUN (neighbor_remove_private_as_all_replace_as,
5374 neighbor_remove_private_as_all_replace_as_cmd,
5375 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5376 NEIGHBOR_STR
5377 NEIGHBOR_ADDR_STR2
5378 "Remove private ASNs in outbound updates\n"
5379 "Apply to all AS numbers\n"
5380 "Replace private ASNs with our ASN in outbound updates\n")
5381 {
5382 int idx_peer = 1;
5383 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5384 bgp_node_safi(vty),
5385 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5386 }
5387
5388 ALIAS_HIDDEN(
5389 neighbor_remove_private_as_all_replace_as,
5390 neighbor_remove_private_as_all_replace_as_hidden_cmd,
5391 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5392 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5393 "Remove private ASNs in outbound updates\n"
5394 "Apply to all AS numbers\n"
5395 "Replace private ASNs with our ASN in outbound updates\n")
5396
5397 DEFUN (no_neighbor_remove_private_as,
5398 no_neighbor_remove_private_as_cmd,
5399 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5400 NO_STR
5401 NEIGHBOR_STR
5402 NEIGHBOR_ADDR_STR2
5403 "Remove private ASNs in outbound updates\n")
5404 {
5405 int idx_peer = 2;
5406 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5407 bgp_node_afi(vty), bgp_node_safi(vty),
5408 PEER_FLAG_REMOVE_PRIVATE_AS);
5409 }
5410
5411 ALIAS_HIDDEN(no_neighbor_remove_private_as,
5412 no_neighbor_remove_private_as_hidden_cmd,
5413 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5414 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5415 "Remove private ASNs in outbound updates\n")
5416
5417 DEFUN (no_neighbor_remove_private_as_all,
5418 no_neighbor_remove_private_as_all_cmd,
5419 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5420 NO_STR
5421 NEIGHBOR_STR
5422 NEIGHBOR_ADDR_STR2
5423 "Remove private ASNs in outbound updates\n"
5424 "Apply to all AS numbers\n")
5425 {
5426 int idx_peer = 2;
5427 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5428 bgp_node_afi(vty), bgp_node_safi(vty),
5429 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5430 }
5431
5432 ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
5433 no_neighbor_remove_private_as_all_hidden_cmd,
5434 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5435 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5436 "Remove private ASNs in outbound updates\n"
5437 "Apply to all AS numbers\n")
5438
5439 DEFUN (no_neighbor_remove_private_as_replace_as,
5440 no_neighbor_remove_private_as_replace_as_cmd,
5441 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5442 NO_STR
5443 NEIGHBOR_STR
5444 NEIGHBOR_ADDR_STR2
5445 "Remove private ASNs in outbound updates\n"
5446 "Replace private ASNs with our ASN in outbound updates\n")
5447 {
5448 int idx_peer = 2;
5449 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5450 bgp_node_afi(vty), bgp_node_safi(vty),
5451 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5452 }
5453
5454 ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
5455 no_neighbor_remove_private_as_replace_as_hidden_cmd,
5456 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5457 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5458 "Remove private ASNs in outbound updates\n"
5459 "Replace private ASNs with our ASN in outbound updates\n")
5460
5461 DEFUN (no_neighbor_remove_private_as_all_replace_as,
5462 no_neighbor_remove_private_as_all_replace_as_cmd,
5463 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5464 NO_STR
5465 NEIGHBOR_STR
5466 NEIGHBOR_ADDR_STR2
5467 "Remove private ASNs in outbound updates\n"
5468 "Apply to all AS numbers\n"
5469 "Replace private ASNs with our ASN in outbound updates\n")
5470 {
5471 int idx_peer = 2;
5472 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5473 bgp_node_afi(vty), bgp_node_safi(vty),
5474 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5475 }
5476
5477 ALIAS_HIDDEN(
5478 no_neighbor_remove_private_as_all_replace_as,
5479 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
5480 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5481 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5482 "Remove private ASNs in outbound updates\n"
5483 "Apply to all AS numbers\n"
5484 "Replace private ASNs with our ASN in outbound updates\n")
5485
5486
5487 /* neighbor send-community. */
5488 DEFUN (neighbor_send_community,
5489 neighbor_send_community_cmd,
5490 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5491 NEIGHBOR_STR
5492 NEIGHBOR_ADDR_STR2
5493 "Send Community attribute to this neighbor\n")
5494 {
5495 int idx_peer = 1;
5496
5497 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5498 bgp_node_safi(vty),
5499 PEER_FLAG_SEND_COMMUNITY);
5500 }
5501
5502 ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
5503 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5504 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5505 "Send Community attribute to this neighbor\n")
5506
5507 DEFUN (no_neighbor_send_community,
5508 no_neighbor_send_community_cmd,
5509 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5510 NO_STR
5511 NEIGHBOR_STR
5512 NEIGHBOR_ADDR_STR2
5513 "Send Community attribute to this neighbor\n")
5514 {
5515 int idx_peer = 2;
5516
5517 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5518 bgp_node_afi(vty), bgp_node_safi(vty),
5519 PEER_FLAG_SEND_COMMUNITY);
5520 }
5521
5522 ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
5523 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5524 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5525 "Send Community attribute to this neighbor\n")
5526
5527 /* neighbor send-community extended. */
5528 DEFUN (neighbor_send_community_type,
5529 neighbor_send_community_type_cmd,
5530 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5531 NEIGHBOR_STR
5532 NEIGHBOR_ADDR_STR2
5533 "Send Community attribute to this neighbor\n"
5534 "Send Standard and Extended Community attributes\n"
5535 "Send Standard, Large and Extended Community attributes\n"
5536 "Send Extended Community attributes\n"
5537 "Send Standard Community attributes\n"
5538 "Send Large Community attributes\n")
5539 {
5540 const char *type = argv[argc - 1]->text;
5541 char *peer_str = argv[1]->arg;
5542 struct peer *peer;
5543 afi_t afi = bgp_node_afi(vty);
5544 safi_t safi = bgp_node_safi(vty);
5545
5546 peer = peer_and_group_lookup_vty(vty, peer_str);
5547 if (!peer)
5548 return CMD_WARNING_CONFIG_FAILED;
5549
5550 if (strmatch(type, "standard"))
5551 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5552 PEER_FLAG_SEND_COMMUNITY);
5553
5554 if (strmatch(type, "extended"))
5555 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5556 PEER_FLAG_SEND_EXT_COMMUNITY);
5557
5558 if (strmatch(type, "large"))
5559 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5560 PEER_FLAG_SEND_LARGE_COMMUNITY);
5561
5562 if (strmatch(type, "both")) {
5563 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5564 PEER_FLAG_SEND_COMMUNITY)
5565 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5566 PEER_FLAG_SEND_EXT_COMMUNITY);
5567 }
5568 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5569 PEER_FLAG_SEND_COMMUNITY)
5570 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5571 PEER_FLAG_SEND_EXT_COMMUNITY)
5572 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5573 PEER_FLAG_SEND_LARGE_COMMUNITY);
5574 }
5575
5576 ALIAS_HIDDEN(
5577 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
5578 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5579 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5580 "Send Community attribute to this neighbor\n"
5581 "Send Standard and Extended Community attributes\n"
5582 "Send Standard, Large and Extended Community attributes\n"
5583 "Send Extended Community attributes\n"
5584 "Send Standard Community attributes\n"
5585 "Send Large Community attributes\n")
5586
5587 DEFUN (no_neighbor_send_community_type,
5588 no_neighbor_send_community_type_cmd,
5589 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5590 NO_STR
5591 NEIGHBOR_STR
5592 NEIGHBOR_ADDR_STR2
5593 "Send Community attribute to this neighbor\n"
5594 "Send Standard and Extended Community attributes\n"
5595 "Send Standard, Large and Extended Community attributes\n"
5596 "Send Extended Community attributes\n"
5597 "Send Standard Community attributes\n"
5598 "Send Large Community attributes\n")
5599 {
5600 const char *type = argv[argc - 1]->text;
5601 char *peer_str = argv[2]->arg;
5602 struct peer *peer;
5603 afi_t afi = bgp_node_afi(vty);
5604 safi_t safi = bgp_node_safi(vty);
5605
5606 peer = peer_and_group_lookup_vty(vty, peer_str);
5607 if (!peer)
5608 return CMD_WARNING_CONFIG_FAILED;
5609
5610 if (strmatch(type, "standard"))
5611 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5612 PEER_FLAG_SEND_COMMUNITY);
5613
5614 if (strmatch(type, "extended"))
5615 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5616 PEER_FLAG_SEND_EXT_COMMUNITY);
5617
5618 if (strmatch(type, "large"))
5619 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5620 PEER_FLAG_SEND_LARGE_COMMUNITY);
5621
5622 if (strmatch(type, "both")) {
5623
5624 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5625 PEER_FLAG_SEND_COMMUNITY)
5626 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5627 PEER_FLAG_SEND_EXT_COMMUNITY);
5628 }
5629
5630 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5631 PEER_FLAG_SEND_COMMUNITY)
5632 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5633 PEER_FLAG_SEND_EXT_COMMUNITY)
5634 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5635 PEER_FLAG_SEND_LARGE_COMMUNITY);
5636 }
5637
5638 ALIAS_HIDDEN(
5639 no_neighbor_send_community_type,
5640 no_neighbor_send_community_type_hidden_cmd,
5641 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5642 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5643 "Send Community attribute to this neighbor\n"
5644 "Send Standard and Extended Community attributes\n"
5645 "Send Standard, Large and Extended Community attributes\n"
5646 "Send Extended Community attributes\n"
5647 "Send Standard Community attributes\n"
5648 "Send Large Community attributes\n")
5649
5650 /* neighbor soft-reconfig. */
5651 DEFUN (neighbor_soft_reconfiguration,
5652 neighbor_soft_reconfiguration_cmd,
5653 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
5654 NEIGHBOR_STR
5655 NEIGHBOR_ADDR_STR2
5656 "Per neighbor soft reconfiguration\n"
5657 "Allow inbound soft reconfiguration for this neighbor\n")
5658 {
5659 int idx_peer = 1;
5660 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5661 bgp_node_safi(vty),
5662 PEER_FLAG_SOFT_RECONFIG);
5663 }
5664
5665 ALIAS_HIDDEN(neighbor_soft_reconfiguration,
5666 neighbor_soft_reconfiguration_hidden_cmd,
5667 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
5668 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5669 "Per neighbor soft reconfiguration\n"
5670 "Allow inbound soft reconfiguration for this neighbor\n")
5671
5672 DEFUN (no_neighbor_soft_reconfiguration,
5673 no_neighbor_soft_reconfiguration_cmd,
5674 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
5675 NO_STR
5676 NEIGHBOR_STR
5677 NEIGHBOR_ADDR_STR2
5678 "Per neighbor soft reconfiguration\n"
5679 "Allow inbound soft reconfiguration for this neighbor\n")
5680 {
5681 int idx_peer = 2;
5682 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5683 bgp_node_afi(vty), bgp_node_safi(vty),
5684 PEER_FLAG_SOFT_RECONFIG);
5685 }
5686
5687 ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
5688 no_neighbor_soft_reconfiguration_hidden_cmd,
5689 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
5690 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5691 "Per neighbor soft reconfiguration\n"
5692 "Allow inbound soft reconfiguration for this neighbor\n")
5693
5694 DEFUN (neighbor_route_reflector_client,
5695 neighbor_route_reflector_client_cmd,
5696 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
5697 NEIGHBOR_STR
5698 NEIGHBOR_ADDR_STR2
5699 "Configure a neighbor as Route Reflector client\n")
5700 {
5701 int idx_peer = 1;
5702 struct peer *peer;
5703
5704
5705 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5706 if (!peer)
5707 return CMD_WARNING_CONFIG_FAILED;
5708
5709 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5710 bgp_node_safi(vty),
5711 PEER_FLAG_REFLECTOR_CLIENT);
5712 }
5713
5714 ALIAS_HIDDEN(neighbor_route_reflector_client,
5715 neighbor_route_reflector_client_hidden_cmd,
5716 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
5717 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5718 "Configure a neighbor as Route Reflector client\n")
5719
5720 DEFUN (no_neighbor_route_reflector_client,
5721 no_neighbor_route_reflector_client_cmd,
5722 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
5723 NO_STR
5724 NEIGHBOR_STR
5725 NEIGHBOR_ADDR_STR2
5726 "Configure a neighbor as Route Reflector client\n")
5727 {
5728 int idx_peer = 2;
5729 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5730 bgp_node_afi(vty), bgp_node_safi(vty),
5731 PEER_FLAG_REFLECTOR_CLIENT);
5732 }
5733
5734 ALIAS_HIDDEN(no_neighbor_route_reflector_client,
5735 no_neighbor_route_reflector_client_hidden_cmd,
5736 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
5737 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5738 "Configure a neighbor as Route Reflector client\n")
5739
5740 /* neighbor route-server-client. */
5741 DEFUN (neighbor_route_server_client,
5742 neighbor_route_server_client_cmd,
5743 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
5744 NEIGHBOR_STR
5745 NEIGHBOR_ADDR_STR2
5746 "Configure a neighbor as Route Server client\n")
5747 {
5748 int idx_peer = 1;
5749 struct peer *peer;
5750
5751 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5752 if (!peer)
5753 return CMD_WARNING_CONFIG_FAILED;
5754 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5755 bgp_node_safi(vty),
5756 PEER_FLAG_RSERVER_CLIENT);
5757 }
5758
5759 ALIAS_HIDDEN(neighbor_route_server_client,
5760 neighbor_route_server_client_hidden_cmd,
5761 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
5762 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5763 "Configure a neighbor as Route Server client\n")
5764
5765 DEFUN (no_neighbor_route_server_client,
5766 no_neighbor_route_server_client_cmd,
5767 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
5768 NO_STR
5769 NEIGHBOR_STR
5770 NEIGHBOR_ADDR_STR2
5771 "Configure a neighbor as Route Server client\n")
5772 {
5773 int idx_peer = 2;
5774 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5775 bgp_node_afi(vty), bgp_node_safi(vty),
5776 PEER_FLAG_RSERVER_CLIENT);
5777 }
5778
5779 ALIAS_HIDDEN(no_neighbor_route_server_client,
5780 no_neighbor_route_server_client_hidden_cmd,
5781 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
5782 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5783 "Configure a neighbor as Route Server client\n")
5784
5785 DEFUN (neighbor_nexthop_local_unchanged,
5786 neighbor_nexthop_local_unchanged_cmd,
5787 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
5788 NEIGHBOR_STR
5789 NEIGHBOR_ADDR_STR2
5790 "Configure treatment of outgoing link-local nexthop attribute\n"
5791 "Leave link-local nexthop unchanged for this peer\n")
5792 {
5793 int idx_peer = 1;
5794 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5795 bgp_node_safi(vty),
5796 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
5797 }
5798
5799 DEFUN (no_neighbor_nexthop_local_unchanged,
5800 no_neighbor_nexthop_local_unchanged_cmd,
5801 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
5802 NO_STR
5803 NEIGHBOR_STR
5804 NEIGHBOR_ADDR_STR2
5805 "Configure treatment of outgoing link-local-nexthop attribute\n"
5806 "Leave link-local nexthop unchanged for this peer\n")
5807 {
5808 int idx_peer = 2;
5809 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5810 bgp_node_afi(vty), bgp_node_safi(vty),
5811 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
5812 }
5813
5814 DEFUN (neighbor_attr_unchanged,
5815 neighbor_attr_unchanged_cmd,
5816 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
5817 NEIGHBOR_STR
5818 NEIGHBOR_ADDR_STR2
5819 "BGP attribute is propagated unchanged to this neighbor\n"
5820 "As-path attribute\n"
5821 "Nexthop attribute\n"
5822 "Med attribute\n")
5823 {
5824 int idx = 0;
5825 char *peer_str = argv[1]->arg;
5826 struct peer *peer;
5827 bool aspath = false;
5828 bool nexthop = false;
5829 bool med = false;
5830 afi_t afi = bgp_node_afi(vty);
5831 safi_t safi = bgp_node_safi(vty);
5832 int ret = 0;
5833
5834 peer = peer_and_group_lookup_vty(vty, peer_str);
5835 if (!peer)
5836 return CMD_WARNING_CONFIG_FAILED;
5837
5838 if (argv_find(argv, argc, "as-path", &idx))
5839 aspath = true;
5840
5841 idx = 0;
5842 if (argv_find(argv, argc, "next-hop", &idx))
5843 nexthop = true;
5844
5845 idx = 0;
5846 if (argv_find(argv, argc, "med", &idx))
5847 med = true;
5848
5849 /* no flags means all of them! */
5850 if (!aspath && !nexthop && !med) {
5851 ret = peer_af_flag_set_vty(vty, peer_str, afi, safi,
5852 PEER_FLAG_AS_PATH_UNCHANGED);
5853 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
5854 PEER_FLAG_NEXTHOP_UNCHANGED);
5855 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
5856 PEER_FLAG_MED_UNCHANGED);
5857 } else {
5858 if (!aspath) {
5859 if (peer_af_flag_check(peer, afi, safi,
5860 PEER_FLAG_AS_PATH_UNCHANGED)) {
5861 ret |= peer_af_flag_unset_vty(
5862 vty, peer_str, afi, safi,
5863 PEER_FLAG_AS_PATH_UNCHANGED);
5864 }
5865 } else
5866 ret |= peer_af_flag_set_vty(
5867 vty, peer_str, afi, safi,
5868 PEER_FLAG_AS_PATH_UNCHANGED);
5869
5870 if (!nexthop) {
5871 if (peer_af_flag_check(peer, afi, safi,
5872 PEER_FLAG_NEXTHOP_UNCHANGED)) {
5873 ret |= peer_af_flag_unset_vty(
5874 vty, peer_str, afi, safi,
5875 PEER_FLAG_NEXTHOP_UNCHANGED);
5876 }
5877 } else
5878 ret |= peer_af_flag_set_vty(
5879 vty, peer_str, afi, safi,
5880 PEER_FLAG_NEXTHOP_UNCHANGED);
5881
5882 if (!med) {
5883 if (peer_af_flag_check(peer, afi, safi,
5884 PEER_FLAG_MED_UNCHANGED)) {
5885 ret |= peer_af_flag_unset_vty(
5886 vty, peer_str, afi, safi,
5887 PEER_FLAG_MED_UNCHANGED);
5888 }
5889 } else
5890 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
5891 PEER_FLAG_MED_UNCHANGED);
5892 }
5893
5894 return ret;
5895 }
5896
5897 ALIAS_HIDDEN(
5898 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
5899 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
5900 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5901 "BGP attribute is propagated unchanged to this neighbor\n"
5902 "As-path attribute\n"
5903 "Nexthop attribute\n"
5904 "Med attribute\n")
5905
5906 DEFUN (no_neighbor_attr_unchanged,
5907 no_neighbor_attr_unchanged_cmd,
5908 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
5909 NO_STR
5910 NEIGHBOR_STR
5911 NEIGHBOR_ADDR_STR2
5912 "BGP attribute is propagated unchanged to this neighbor\n"
5913 "As-path attribute\n"
5914 "Nexthop attribute\n"
5915 "Med attribute\n")
5916 {
5917 int idx = 0;
5918 char *peer_str = argv[2]->arg;
5919 struct peer *peer;
5920 bool aspath = false;
5921 bool nexthop = false;
5922 bool med = false;
5923 afi_t afi = bgp_node_afi(vty);
5924 safi_t safi = bgp_node_safi(vty);
5925 int ret = 0;
5926
5927 peer = peer_and_group_lookup_vty(vty, peer_str);
5928 if (!peer)
5929 return CMD_WARNING_CONFIG_FAILED;
5930
5931 if (argv_find(argv, argc, "as-path", &idx))
5932 aspath = true;
5933
5934 idx = 0;
5935 if (argv_find(argv, argc, "next-hop", &idx))
5936 nexthop = true;
5937
5938 idx = 0;
5939 if (argv_find(argv, argc, "med", &idx))
5940 med = true;
5941
5942 if (!aspath && !nexthop && !med) // no flags means all of them!
5943 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5944 PEER_FLAG_AS_PATH_UNCHANGED)
5945 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5946 PEER_FLAG_NEXTHOP_UNCHANGED)
5947 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5948 PEER_FLAG_MED_UNCHANGED);
5949
5950 if (aspath)
5951 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5952 PEER_FLAG_AS_PATH_UNCHANGED);
5953
5954 if (nexthop)
5955 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5956 PEER_FLAG_NEXTHOP_UNCHANGED);
5957
5958 if (med)
5959 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5960 PEER_FLAG_MED_UNCHANGED);
5961
5962 return ret;
5963 }
5964
5965 ALIAS_HIDDEN(
5966 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
5967 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
5968 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5969 "BGP attribute is propagated unchanged to this neighbor\n"
5970 "As-path attribute\n"
5971 "Nexthop attribute\n"
5972 "Med attribute\n")
5973
5974 /* EBGP multihop configuration. */
5975 static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
5976 const char *ttl_str)
5977 {
5978 struct peer *peer;
5979 unsigned int ttl;
5980
5981 peer = peer_and_group_lookup_vty(vty, ip_str);
5982 if (!peer)
5983 return CMD_WARNING_CONFIG_FAILED;
5984
5985 if (peer->conf_if)
5986 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
5987
5988 if (!ttl_str)
5989 ttl = MAXTTL;
5990 else
5991 ttl = strtoul(ttl_str, NULL, 10);
5992
5993 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
5994 }
5995
5996 static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
5997 {
5998 struct peer *peer;
5999
6000 peer = peer_and_group_lookup_vty(vty, ip_str);
6001 if (!peer)
6002 return CMD_WARNING_CONFIG_FAILED;
6003
6004 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
6005 }
6006
6007 /* neighbor ebgp-multihop. */
6008 DEFUN (neighbor_ebgp_multihop,
6009 neighbor_ebgp_multihop_cmd,
6010 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
6011 NEIGHBOR_STR
6012 NEIGHBOR_ADDR_STR2
6013 "Allow EBGP neighbors not on directly connected networks\n")
6014 {
6015 int idx_peer = 1;
6016 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
6017 }
6018
6019 DEFUN (neighbor_ebgp_multihop_ttl,
6020 neighbor_ebgp_multihop_ttl_cmd,
6021 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
6022 NEIGHBOR_STR
6023 NEIGHBOR_ADDR_STR2
6024 "Allow EBGP neighbors not on directly connected networks\n"
6025 "maximum hop count\n")
6026 {
6027 int idx_peer = 1;
6028 int idx_number = 3;
6029 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
6030 argv[idx_number]->arg);
6031 }
6032
6033 DEFUN (no_neighbor_ebgp_multihop,
6034 no_neighbor_ebgp_multihop_cmd,
6035 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
6036 NO_STR
6037 NEIGHBOR_STR
6038 NEIGHBOR_ADDR_STR2
6039 "Allow EBGP neighbors not on directly connected networks\n"
6040 "maximum hop count\n")
6041 {
6042 int idx_peer = 2;
6043 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
6044 }
6045
6046
6047 /* disable-connected-check */
6048 DEFUN (neighbor_disable_connected_check,
6049 neighbor_disable_connected_check_cmd,
6050 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6051 NEIGHBOR_STR
6052 NEIGHBOR_ADDR_STR2
6053 "one-hop away EBGP peer using loopback address\n"
6054 "Enforce EBGP neighbors perform multihop\n")
6055 {
6056 int idx_peer = 1;
6057 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6058 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6059 }
6060
6061 DEFUN (no_neighbor_disable_connected_check,
6062 no_neighbor_disable_connected_check_cmd,
6063 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6064 NO_STR
6065 NEIGHBOR_STR
6066 NEIGHBOR_ADDR_STR2
6067 "one-hop away EBGP peer using loopback address\n"
6068 "Enforce EBGP neighbors perform multihop\n")
6069 {
6070 int idx_peer = 2;
6071 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6072 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6073 }
6074
6075
6076 /* enforce-first-as */
6077 DEFUN (neighbor_enforce_first_as,
6078 neighbor_enforce_first_as_cmd,
6079 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6080 NEIGHBOR_STR
6081 NEIGHBOR_ADDR_STR2
6082 "Enforce the first AS for EBGP routes\n")
6083 {
6084 int idx_peer = 1;
6085
6086 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6087 PEER_FLAG_ENFORCE_FIRST_AS);
6088 }
6089
6090 DEFUN (no_neighbor_enforce_first_as,
6091 no_neighbor_enforce_first_as_cmd,
6092 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6093 NO_STR
6094 NEIGHBOR_STR
6095 NEIGHBOR_ADDR_STR2
6096 "Enforce the first AS for EBGP routes\n")
6097 {
6098 int idx_peer = 2;
6099
6100 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6101 PEER_FLAG_ENFORCE_FIRST_AS);
6102 }
6103
6104
6105 DEFUN (neighbor_description,
6106 neighbor_description_cmd,
6107 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6108 NEIGHBOR_STR
6109 NEIGHBOR_ADDR_STR2
6110 "Neighbor specific description\n"
6111 "Up to 80 characters describing this neighbor\n")
6112 {
6113 int idx_peer = 1;
6114 int idx_line = 3;
6115 struct peer *peer;
6116 char *str;
6117
6118 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6119 if (!peer)
6120 return CMD_WARNING_CONFIG_FAILED;
6121
6122 str = argv_concat(argv, argc, idx_line);
6123
6124 peer_description_set(peer, str);
6125
6126 XFREE(MTYPE_TMP, str);
6127
6128 return CMD_SUCCESS;
6129 }
6130
6131 DEFUN (no_neighbor_description,
6132 no_neighbor_description_cmd,
6133 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
6134 NO_STR
6135 NEIGHBOR_STR
6136 NEIGHBOR_ADDR_STR2
6137 "Neighbor specific description\n")
6138 {
6139 int idx_peer = 2;
6140 struct peer *peer;
6141
6142 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6143 if (!peer)
6144 return CMD_WARNING_CONFIG_FAILED;
6145
6146 peer_description_unset(peer);
6147
6148 return CMD_SUCCESS;
6149 }
6150
6151 ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
6152 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6153 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6154 "Neighbor specific description\n"
6155 "Up to 80 characters describing this neighbor\n")
6156
6157 /* Neighbor update-source. */
6158 static int peer_update_source_vty(struct vty *vty, const char *peer_str,
6159 const char *source_str)
6160 {
6161 struct peer *peer;
6162 struct prefix p;
6163 union sockunion su;
6164
6165 peer = peer_and_group_lookup_vty(vty, peer_str);
6166 if (!peer)
6167 return CMD_WARNING_CONFIG_FAILED;
6168
6169 if (peer->conf_if)
6170 return CMD_WARNING;
6171
6172 if (source_str) {
6173 if (str2sockunion(source_str, &su) == 0)
6174 peer_update_source_addr_set(peer, &su);
6175 else {
6176 if (str2prefix(source_str, &p)) {
6177 vty_out(vty,
6178 "%% Invalid update-source, remove prefix length \n");
6179 return CMD_WARNING_CONFIG_FAILED;
6180 } else
6181 peer_update_source_if_set(peer, source_str);
6182 }
6183 } else
6184 peer_update_source_unset(peer);
6185
6186 return CMD_SUCCESS;
6187 }
6188
6189 #define BGP_UPDATE_SOURCE_HELP_STR \
6190 "IPv4 address\n" \
6191 "IPv6 address\n" \
6192 "Interface name (requires zebra to be running)\n"
6193
6194 DEFUN (neighbor_update_source,
6195 neighbor_update_source_cmd,
6196 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
6197 NEIGHBOR_STR
6198 NEIGHBOR_ADDR_STR2
6199 "Source of routing updates\n"
6200 BGP_UPDATE_SOURCE_HELP_STR)
6201 {
6202 int idx_peer = 1;
6203 int idx_peer_2 = 3;
6204 return peer_update_source_vty(vty, argv[idx_peer]->arg,
6205 argv[idx_peer_2]->arg);
6206 }
6207
6208 DEFUN (no_neighbor_update_source,
6209 no_neighbor_update_source_cmd,
6210 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
6211 NO_STR
6212 NEIGHBOR_STR
6213 NEIGHBOR_ADDR_STR2
6214 "Source of routing updates\n"
6215 BGP_UPDATE_SOURCE_HELP_STR)
6216 {
6217 int idx_peer = 2;
6218 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
6219 }
6220
6221 static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
6222 afi_t afi, safi_t safi,
6223 const char *rmap, int set)
6224 {
6225 int ret;
6226 struct peer *peer;
6227 struct route_map *route_map = NULL;
6228
6229 peer = peer_and_group_lookup_vty(vty, peer_str);
6230 if (!peer)
6231 return CMD_WARNING_CONFIG_FAILED;
6232
6233 if (set) {
6234 if (rmap)
6235 route_map = route_map_lookup_warn_noexist(vty, rmap);
6236 ret = peer_default_originate_set(peer, afi, safi,
6237 rmap, route_map);
6238 } else
6239 ret = peer_default_originate_unset(peer, afi, safi);
6240
6241 return bgp_vty_return(vty, ret);
6242 }
6243
6244 /* neighbor default-originate. */
6245 DEFUN (neighbor_default_originate,
6246 neighbor_default_originate_cmd,
6247 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
6248 NEIGHBOR_STR
6249 NEIGHBOR_ADDR_STR2
6250 "Originate default route to this neighbor\n")
6251 {
6252 int idx_peer = 1;
6253 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6254 bgp_node_afi(vty),
6255 bgp_node_safi(vty), NULL, 1);
6256 }
6257
6258 ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
6259 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
6260 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6261 "Originate default route to this neighbor\n")
6262
6263 DEFUN (neighbor_default_originate_rmap,
6264 neighbor_default_originate_rmap_cmd,
6265 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
6266 NEIGHBOR_STR
6267 NEIGHBOR_ADDR_STR2
6268 "Originate default route to this neighbor\n"
6269 "Route-map to specify criteria to originate default\n"
6270 "route-map name\n")
6271 {
6272 int idx_peer = 1;
6273 int idx_word = 4;
6274 return peer_default_originate_set_vty(
6275 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6276 argv[idx_word]->arg, 1);
6277 }
6278
6279 ALIAS_HIDDEN(
6280 neighbor_default_originate_rmap,
6281 neighbor_default_originate_rmap_hidden_cmd,
6282 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
6283 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6284 "Originate default route to this neighbor\n"
6285 "Route-map to specify criteria to originate default\n"
6286 "route-map name\n")
6287
6288 DEFUN (no_neighbor_default_originate,
6289 no_neighbor_default_originate_cmd,
6290 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
6291 NO_STR
6292 NEIGHBOR_STR
6293 NEIGHBOR_ADDR_STR2
6294 "Originate default route to this neighbor\n"
6295 "Route-map to specify criteria to originate default\n"
6296 "route-map name\n")
6297 {
6298 int idx_peer = 2;
6299 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6300 bgp_node_afi(vty),
6301 bgp_node_safi(vty), NULL, 0);
6302 }
6303
6304 ALIAS_HIDDEN(
6305 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
6306 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
6307 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6308 "Originate default route to this neighbor\n"
6309 "Route-map to specify criteria to originate default\n"
6310 "route-map name\n")
6311
6312
6313 /* Set neighbor's BGP port. */
6314 static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
6315 const char *port_str)
6316 {
6317 struct peer *peer;
6318 uint16_t port;
6319 struct servent *sp;
6320
6321 peer = peer_lookup_vty(vty, ip_str);
6322 if (!peer)
6323 return CMD_WARNING_CONFIG_FAILED;
6324
6325 if (!port_str) {
6326 sp = getservbyname("bgp", "tcp");
6327 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
6328 } else {
6329 port = strtoul(port_str, NULL, 10);
6330 }
6331
6332 peer_port_set(peer, port);
6333
6334 return CMD_SUCCESS;
6335 }
6336
6337 /* Set specified peer's BGP port. */
6338 DEFUN (neighbor_port,
6339 neighbor_port_cmd,
6340 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
6341 NEIGHBOR_STR
6342 NEIGHBOR_ADDR_STR
6343 "Neighbor's BGP port\n"
6344 "TCP port number\n")
6345 {
6346 int idx_ip = 1;
6347 int idx_number = 3;
6348 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
6349 argv[idx_number]->arg);
6350 }
6351
6352 DEFUN (no_neighbor_port,
6353 no_neighbor_port_cmd,
6354 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
6355 NO_STR
6356 NEIGHBOR_STR
6357 NEIGHBOR_ADDR_STR
6358 "Neighbor's BGP port\n"
6359 "TCP port number\n")
6360 {
6361 int idx_ip = 2;
6362 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
6363 }
6364
6365
6366 /* neighbor weight. */
6367 static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
6368 safi_t safi, const char *weight_str)
6369 {
6370 int ret;
6371 struct peer *peer;
6372 unsigned long weight;
6373
6374 peer = peer_and_group_lookup_vty(vty, ip_str);
6375 if (!peer)
6376 return CMD_WARNING_CONFIG_FAILED;
6377
6378 weight = strtoul(weight_str, NULL, 10);
6379
6380 ret = peer_weight_set(peer, afi, safi, weight);
6381 return bgp_vty_return(vty, ret);
6382 }
6383
6384 static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
6385 safi_t safi)
6386 {
6387 int ret;
6388 struct peer *peer;
6389
6390 peer = peer_and_group_lookup_vty(vty, ip_str);
6391 if (!peer)
6392 return CMD_WARNING_CONFIG_FAILED;
6393
6394 ret = peer_weight_unset(peer, afi, safi);
6395 return bgp_vty_return(vty, ret);
6396 }
6397
6398 DEFUN (neighbor_weight,
6399 neighbor_weight_cmd,
6400 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
6401 NEIGHBOR_STR
6402 NEIGHBOR_ADDR_STR2
6403 "Set default weight for routes from this neighbor\n"
6404 "default weight\n")
6405 {
6406 int idx_peer = 1;
6407 int idx_number = 3;
6408 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6409 bgp_node_safi(vty), argv[idx_number]->arg);
6410 }
6411
6412 ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
6413 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
6414 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6415 "Set default weight for routes from this neighbor\n"
6416 "default weight\n")
6417
6418 DEFUN (no_neighbor_weight,
6419 no_neighbor_weight_cmd,
6420 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
6421 NO_STR
6422 NEIGHBOR_STR
6423 NEIGHBOR_ADDR_STR2
6424 "Set default weight for routes from this neighbor\n"
6425 "default weight\n")
6426 {
6427 int idx_peer = 2;
6428 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
6429 bgp_node_afi(vty), bgp_node_safi(vty));
6430 }
6431
6432 ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
6433 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
6434 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6435 "Set default weight for routes from this neighbor\n"
6436 "default weight\n")
6437
6438
6439 /* Override capability negotiation. */
6440 DEFUN (neighbor_override_capability,
6441 neighbor_override_capability_cmd,
6442 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
6443 NEIGHBOR_STR
6444 NEIGHBOR_ADDR_STR2
6445 "Override capability negotiation result\n")
6446 {
6447 int idx_peer = 1;
6448 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6449 PEER_FLAG_OVERRIDE_CAPABILITY);
6450 }
6451
6452 DEFUN (no_neighbor_override_capability,
6453 no_neighbor_override_capability_cmd,
6454 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
6455 NO_STR
6456 NEIGHBOR_STR
6457 NEIGHBOR_ADDR_STR2
6458 "Override capability negotiation result\n")
6459 {
6460 int idx_peer = 2;
6461 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6462 PEER_FLAG_OVERRIDE_CAPABILITY);
6463 }
6464
6465 DEFUN (neighbor_strict_capability,
6466 neighbor_strict_capability_cmd,
6467 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
6468 NEIGHBOR_STR
6469 NEIGHBOR_ADDR_STR2
6470 "Strict capability negotiation match\n")
6471 {
6472 int idx_peer = 1;
6473
6474 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6475 PEER_FLAG_STRICT_CAP_MATCH);
6476 }
6477
6478 DEFUN (no_neighbor_strict_capability,
6479 no_neighbor_strict_capability_cmd,
6480 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
6481 NO_STR
6482 NEIGHBOR_STR
6483 NEIGHBOR_ADDR_STR2
6484 "Strict capability negotiation match\n")
6485 {
6486 int idx_peer = 2;
6487
6488 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6489 PEER_FLAG_STRICT_CAP_MATCH);
6490 }
6491
6492 static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
6493 const char *keep_str, const char *hold_str)
6494 {
6495 int ret;
6496 struct peer *peer;
6497 uint32_t keepalive;
6498 uint32_t holdtime;
6499
6500 peer = peer_and_group_lookup_vty(vty, ip_str);
6501 if (!peer)
6502 return CMD_WARNING_CONFIG_FAILED;
6503
6504 keepalive = strtoul(keep_str, NULL, 10);
6505 holdtime = strtoul(hold_str, NULL, 10);
6506
6507 ret = peer_timers_set(peer, keepalive, holdtime);
6508
6509 return bgp_vty_return(vty, ret);
6510 }
6511
6512 static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
6513 {
6514 int ret;
6515 struct peer *peer;
6516
6517 peer = peer_and_group_lookup_vty(vty, ip_str);
6518 if (!peer)
6519 return CMD_WARNING_CONFIG_FAILED;
6520
6521 ret = peer_timers_unset(peer);
6522
6523 return bgp_vty_return(vty, ret);
6524 }
6525
6526 DEFUN (neighbor_timers,
6527 neighbor_timers_cmd,
6528 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
6529 NEIGHBOR_STR
6530 NEIGHBOR_ADDR_STR2
6531 "BGP per neighbor timers\n"
6532 "Keepalive interval\n"
6533 "Holdtime\n")
6534 {
6535 int idx_peer = 1;
6536 int idx_number = 3;
6537 int idx_number_2 = 4;
6538 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
6539 argv[idx_number]->arg,
6540 argv[idx_number_2]->arg);
6541 }
6542
6543 DEFUN (no_neighbor_timers,
6544 no_neighbor_timers_cmd,
6545 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
6546 NO_STR
6547 NEIGHBOR_STR
6548 NEIGHBOR_ADDR_STR2
6549 "BGP per neighbor timers\n"
6550 "Keepalive interval\n"
6551 "Holdtime\n")
6552 {
6553 int idx_peer = 2;
6554 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
6555 }
6556
6557
6558 static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
6559 const char *time_str)
6560 {
6561 int ret;
6562 struct peer *peer;
6563 uint32_t connect;
6564
6565 peer = peer_and_group_lookup_vty(vty, ip_str);
6566 if (!peer)
6567 return CMD_WARNING_CONFIG_FAILED;
6568
6569 connect = strtoul(time_str, NULL, 10);
6570
6571 ret = peer_timers_connect_set(peer, connect);
6572
6573 return bgp_vty_return(vty, ret);
6574 }
6575
6576 static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
6577 {
6578 int ret;
6579 struct peer *peer;
6580
6581 peer = peer_and_group_lookup_vty(vty, ip_str);
6582 if (!peer)
6583 return CMD_WARNING_CONFIG_FAILED;
6584
6585 ret = peer_timers_connect_unset(peer);
6586
6587 return bgp_vty_return(vty, ret);
6588 }
6589
6590 DEFUN (neighbor_timers_connect,
6591 neighbor_timers_connect_cmd,
6592 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
6593 NEIGHBOR_STR
6594 NEIGHBOR_ADDR_STR2
6595 "BGP per neighbor timers\n"
6596 "BGP connect timer\n"
6597 "Connect timer\n")
6598 {
6599 int idx_peer = 1;
6600 int idx_number = 4;
6601 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
6602 argv[idx_number]->arg);
6603 }
6604
6605 DEFUN (no_neighbor_timers_connect,
6606 no_neighbor_timers_connect_cmd,
6607 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
6608 NO_STR
6609 NEIGHBOR_STR
6610 NEIGHBOR_ADDR_STR2
6611 "BGP per neighbor timers\n"
6612 "BGP connect timer\n"
6613 "Connect timer\n")
6614 {
6615 int idx_peer = 2;
6616 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
6617 }
6618
6619
6620 static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
6621 const char *time_str, int set)
6622 {
6623 int ret;
6624 struct peer *peer;
6625 uint32_t routeadv = 0;
6626
6627 peer = peer_and_group_lookup_vty(vty, ip_str);
6628 if (!peer)
6629 return CMD_WARNING_CONFIG_FAILED;
6630
6631 if (time_str)
6632 routeadv = strtoul(time_str, NULL, 10);
6633
6634 if (set)
6635 ret = peer_advertise_interval_set(peer, routeadv);
6636 else
6637 ret = peer_advertise_interval_unset(peer);
6638
6639 return bgp_vty_return(vty, ret);
6640 }
6641
6642 DEFUN (neighbor_advertise_interval,
6643 neighbor_advertise_interval_cmd,
6644 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
6645 NEIGHBOR_STR
6646 NEIGHBOR_ADDR_STR2
6647 "Minimum interval between sending BGP routing updates\n"
6648 "time in seconds\n")
6649 {
6650 int idx_peer = 1;
6651 int idx_number = 3;
6652 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
6653 argv[idx_number]->arg, 1);
6654 }
6655
6656 DEFUN (no_neighbor_advertise_interval,
6657 no_neighbor_advertise_interval_cmd,
6658 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
6659 NO_STR
6660 NEIGHBOR_STR
6661 NEIGHBOR_ADDR_STR2
6662 "Minimum interval between sending BGP routing updates\n"
6663 "time in seconds\n")
6664 {
6665 int idx_peer = 2;
6666 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
6667 }
6668
6669
6670 /* Time to wait before processing route-map updates */
6671 DEFUN (bgp_set_route_map_delay_timer,
6672 bgp_set_route_map_delay_timer_cmd,
6673 "bgp route-map delay-timer (0-600)",
6674 SET_STR
6675 "BGP route-map delay timer\n"
6676 "Time in secs to wait before processing route-map changes\n"
6677 "0 disables the timer, no route updates happen when route-maps change\n")
6678 {
6679 int idx_number = 3;
6680 uint32_t rmap_delay_timer;
6681
6682 if (argv[idx_number]->arg) {
6683 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
6684 bm->rmap_update_timer = rmap_delay_timer;
6685
6686 /* if the dynamic update handling is being disabled, and a timer
6687 * is
6688 * running, stop the timer and act as if the timer has already
6689 * fired.
6690 */
6691 if (!rmap_delay_timer && bm->t_rmap_update) {
6692 BGP_TIMER_OFF(bm->t_rmap_update);
6693 thread_execute(bm->master, bgp_route_map_update_timer,
6694 NULL, 0);
6695 }
6696 return CMD_SUCCESS;
6697 } else {
6698 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
6699 return CMD_WARNING_CONFIG_FAILED;
6700 }
6701 }
6702
6703 DEFUN (no_bgp_set_route_map_delay_timer,
6704 no_bgp_set_route_map_delay_timer_cmd,
6705 "no bgp route-map delay-timer [(0-600)]",
6706 NO_STR
6707 BGP_STR
6708 "Default BGP route-map delay timer\n"
6709 "Reset to default time to wait for processing route-map changes\n"
6710 "0 disables the timer, no route updates happen when route-maps change\n")
6711 {
6712
6713 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
6714
6715 return CMD_SUCCESS;
6716 }
6717
6718 /* neighbor interface */
6719 static int peer_interface_vty(struct vty *vty, const char *ip_str,
6720 const char *str)
6721 {
6722 struct peer *peer;
6723
6724 peer = peer_lookup_vty(vty, ip_str);
6725 if (!peer || peer->conf_if) {
6726 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
6727 return CMD_WARNING_CONFIG_FAILED;
6728 }
6729
6730 if (str)
6731 peer_interface_set(peer, str);
6732 else
6733 peer_interface_unset(peer);
6734
6735 return CMD_SUCCESS;
6736 }
6737
6738 DEFUN (neighbor_interface,
6739 neighbor_interface_cmd,
6740 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
6741 NEIGHBOR_STR
6742 NEIGHBOR_ADDR_STR
6743 "Interface\n"
6744 "Interface name\n")
6745 {
6746 int idx_ip = 1;
6747 int idx_word = 3;
6748 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
6749 }
6750
6751 DEFUN (no_neighbor_interface,
6752 no_neighbor_interface_cmd,
6753 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
6754 NO_STR
6755 NEIGHBOR_STR
6756 NEIGHBOR_ADDR_STR2
6757 "Interface\n"
6758 "Interface name\n")
6759 {
6760 int idx_peer = 2;
6761 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
6762 }
6763
6764 DEFUN (neighbor_distribute_list,
6765 neighbor_distribute_list_cmd,
6766 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
6767 NEIGHBOR_STR
6768 NEIGHBOR_ADDR_STR2
6769 "Filter updates to/from this neighbor\n"
6770 "IP access-list number\n"
6771 "IP access-list number (expanded range)\n"
6772 "IP Access-list name\n"
6773 "Filter incoming updates\n"
6774 "Filter outgoing updates\n")
6775 {
6776 int idx_peer = 1;
6777 int idx_acl = 3;
6778 int direct, ret;
6779 struct peer *peer;
6780
6781 const char *pstr = argv[idx_peer]->arg;
6782 const char *acl = argv[idx_acl]->arg;
6783 const char *inout = argv[argc - 1]->text;
6784
6785 peer = peer_and_group_lookup_vty(vty, pstr);
6786 if (!peer)
6787 return CMD_WARNING_CONFIG_FAILED;
6788
6789 /* Check filter direction. */
6790 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
6791 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6792 direct, acl);
6793
6794 return bgp_vty_return(vty, ret);
6795 }
6796
6797 ALIAS_HIDDEN(
6798 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
6799 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
6800 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6801 "Filter updates to/from this neighbor\n"
6802 "IP access-list number\n"
6803 "IP access-list number (expanded range)\n"
6804 "IP Access-list name\n"
6805 "Filter incoming updates\n"
6806 "Filter outgoing updates\n")
6807
6808 DEFUN (no_neighbor_distribute_list,
6809 no_neighbor_distribute_list_cmd,
6810 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
6811 NO_STR
6812 NEIGHBOR_STR
6813 NEIGHBOR_ADDR_STR2
6814 "Filter updates to/from this neighbor\n"
6815 "IP access-list number\n"
6816 "IP access-list number (expanded range)\n"
6817 "IP Access-list name\n"
6818 "Filter incoming updates\n"
6819 "Filter outgoing updates\n")
6820 {
6821 int idx_peer = 2;
6822 int direct, ret;
6823 struct peer *peer;
6824
6825 const char *pstr = argv[idx_peer]->arg;
6826 const char *inout = argv[argc - 1]->text;
6827
6828 peer = peer_and_group_lookup_vty(vty, pstr);
6829 if (!peer)
6830 return CMD_WARNING_CONFIG_FAILED;
6831
6832 /* Check filter direction. */
6833 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
6834 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6835 direct);
6836
6837 return bgp_vty_return(vty, ret);
6838 }
6839
6840 ALIAS_HIDDEN(
6841 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
6842 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
6843 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6844 "Filter updates to/from this neighbor\n"
6845 "IP access-list number\n"
6846 "IP access-list number (expanded range)\n"
6847 "IP Access-list name\n"
6848 "Filter incoming updates\n"
6849 "Filter outgoing updates\n")
6850
6851 /* Set prefix list to the peer. */
6852 static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
6853 afi_t afi, safi_t safi,
6854 const char *name_str,
6855 const char *direct_str)
6856 {
6857 int ret;
6858 int direct = FILTER_IN;
6859 struct peer *peer;
6860
6861 peer = peer_and_group_lookup_vty(vty, ip_str);
6862 if (!peer)
6863 return CMD_WARNING_CONFIG_FAILED;
6864
6865 /* Check filter direction. */
6866 if (strncmp(direct_str, "i", 1) == 0)
6867 direct = FILTER_IN;
6868 else if (strncmp(direct_str, "o", 1) == 0)
6869 direct = FILTER_OUT;
6870
6871 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
6872
6873 return bgp_vty_return(vty, ret);
6874 }
6875
6876 static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
6877 afi_t afi, safi_t safi,
6878 const char *direct_str)
6879 {
6880 int ret;
6881 struct peer *peer;
6882 int direct = FILTER_IN;
6883
6884 peer = peer_and_group_lookup_vty(vty, ip_str);
6885 if (!peer)
6886 return CMD_WARNING_CONFIG_FAILED;
6887
6888 /* Check filter direction. */
6889 if (strncmp(direct_str, "i", 1) == 0)
6890 direct = FILTER_IN;
6891 else if (strncmp(direct_str, "o", 1) == 0)
6892 direct = FILTER_OUT;
6893
6894 ret = peer_prefix_list_unset(peer, afi, safi, direct);
6895
6896 return bgp_vty_return(vty, ret);
6897 }
6898
6899 DEFUN (neighbor_prefix_list,
6900 neighbor_prefix_list_cmd,
6901 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
6902 NEIGHBOR_STR
6903 NEIGHBOR_ADDR_STR2
6904 "Filter updates to/from this neighbor\n"
6905 "Name of a prefix list\n"
6906 "Filter incoming updates\n"
6907 "Filter outgoing updates\n")
6908 {
6909 int idx_peer = 1;
6910 int idx_word = 3;
6911 int idx_in_out = 4;
6912 return peer_prefix_list_set_vty(
6913 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6914 argv[idx_word]->arg, argv[idx_in_out]->arg);
6915 }
6916
6917 ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
6918 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
6919 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6920 "Filter updates to/from this neighbor\n"
6921 "Name of a prefix list\n"
6922 "Filter incoming updates\n"
6923 "Filter outgoing updates\n")
6924
6925 DEFUN (no_neighbor_prefix_list,
6926 no_neighbor_prefix_list_cmd,
6927 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
6928 NO_STR
6929 NEIGHBOR_STR
6930 NEIGHBOR_ADDR_STR2
6931 "Filter updates to/from this neighbor\n"
6932 "Name of a prefix list\n"
6933 "Filter incoming updates\n"
6934 "Filter outgoing updates\n")
6935 {
6936 int idx_peer = 2;
6937 int idx_in_out = 5;
6938 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
6939 bgp_node_afi(vty), bgp_node_safi(vty),
6940 argv[idx_in_out]->arg);
6941 }
6942
6943 ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
6944 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
6945 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6946 "Filter updates to/from this neighbor\n"
6947 "Name of a prefix list\n"
6948 "Filter incoming updates\n"
6949 "Filter outgoing updates\n")
6950
6951 static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
6952 safi_t safi, const char *name_str,
6953 const char *direct_str)
6954 {
6955 int ret;
6956 struct peer *peer;
6957 int direct = FILTER_IN;
6958
6959 peer = peer_and_group_lookup_vty(vty, ip_str);
6960 if (!peer)
6961 return CMD_WARNING_CONFIG_FAILED;
6962
6963 /* Check filter direction. */
6964 if (strncmp(direct_str, "i", 1) == 0)
6965 direct = FILTER_IN;
6966 else if (strncmp(direct_str, "o", 1) == 0)
6967 direct = FILTER_OUT;
6968
6969 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
6970
6971 return bgp_vty_return(vty, ret);
6972 }
6973
6974 static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
6975 safi_t safi, const char *direct_str)
6976 {
6977 int ret;
6978 struct peer *peer;
6979 int direct = FILTER_IN;
6980
6981 peer = peer_and_group_lookup_vty(vty, ip_str);
6982 if (!peer)
6983 return CMD_WARNING_CONFIG_FAILED;
6984
6985 /* Check filter direction. */
6986 if (strncmp(direct_str, "i", 1) == 0)
6987 direct = FILTER_IN;
6988 else if (strncmp(direct_str, "o", 1) == 0)
6989 direct = FILTER_OUT;
6990
6991 ret = peer_aslist_unset(peer, afi, safi, direct);
6992
6993 return bgp_vty_return(vty, ret);
6994 }
6995
6996 DEFUN (neighbor_filter_list,
6997 neighbor_filter_list_cmd,
6998 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
6999 NEIGHBOR_STR
7000 NEIGHBOR_ADDR_STR2
7001 "Establish BGP filters\n"
7002 "AS path access-list name\n"
7003 "Filter incoming routes\n"
7004 "Filter outgoing routes\n")
7005 {
7006 int idx_peer = 1;
7007 int idx_word = 3;
7008 int idx_in_out = 4;
7009 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7010 bgp_node_safi(vty), argv[idx_word]->arg,
7011 argv[idx_in_out]->arg);
7012 }
7013
7014 ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
7015 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
7016 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7017 "Establish BGP filters\n"
7018 "AS path access-list name\n"
7019 "Filter incoming routes\n"
7020 "Filter outgoing routes\n")
7021
7022 DEFUN (no_neighbor_filter_list,
7023 no_neighbor_filter_list_cmd,
7024 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
7025 NO_STR
7026 NEIGHBOR_STR
7027 NEIGHBOR_ADDR_STR2
7028 "Establish BGP filters\n"
7029 "AS path access-list name\n"
7030 "Filter incoming routes\n"
7031 "Filter outgoing routes\n")
7032 {
7033 int idx_peer = 2;
7034 int idx_in_out = 5;
7035 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
7036 bgp_node_afi(vty), bgp_node_safi(vty),
7037 argv[idx_in_out]->arg);
7038 }
7039
7040 ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
7041 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
7042 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7043 "Establish BGP filters\n"
7044 "AS path access-list name\n"
7045 "Filter incoming routes\n"
7046 "Filter outgoing routes\n")
7047
7048 /* Set route-map to the peer. */
7049 static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
7050 afi_t afi, safi_t safi, const char *name_str,
7051 const char *direct_str)
7052 {
7053 int ret;
7054 struct peer *peer;
7055 int direct = RMAP_IN;
7056 struct route_map *route_map;
7057
7058 peer = peer_and_group_lookup_vty(vty, ip_str);
7059 if (!peer)
7060 return CMD_WARNING_CONFIG_FAILED;
7061
7062 /* Check filter direction. */
7063 if (strncmp(direct_str, "in", 2) == 0)
7064 direct = RMAP_IN;
7065 else if (strncmp(direct_str, "o", 1) == 0)
7066 direct = RMAP_OUT;
7067
7068 route_map = route_map_lookup_warn_noexist(vty, name_str);
7069 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
7070
7071 return bgp_vty_return(vty, ret);
7072 }
7073
7074 static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
7075 afi_t afi, safi_t safi,
7076 const char *direct_str)
7077 {
7078 int ret;
7079 struct peer *peer;
7080 int direct = RMAP_IN;
7081
7082 peer = peer_and_group_lookup_vty(vty, ip_str);
7083 if (!peer)
7084 return CMD_WARNING_CONFIG_FAILED;
7085
7086 /* Check filter direction. */
7087 if (strncmp(direct_str, "in", 2) == 0)
7088 direct = RMAP_IN;
7089 else if (strncmp(direct_str, "o", 1) == 0)
7090 direct = RMAP_OUT;
7091
7092 ret = peer_route_map_unset(peer, afi, safi, direct);
7093
7094 return bgp_vty_return(vty, ret);
7095 }
7096
7097 DEFUN (neighbor_route_map,
7098 neighbor_route_map_cmd,
7099 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
7100 NEIGHBOR_STR
7101 NEIGHBOR_ADDR_STR2
7102 "Apply route map to neighbor\n"
7103 "Name of route map\n"
7104 "Apply map to incoming routes\n"
7105 "Apply map to outbound routes\n")
7106 {
7107 int idx_peer = 1;
7108 int idx_word = 3;
7109 int idx_in_out = 4;
7110 return peer_route_map_set_vty(
7111 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7112 argv[idx_word]->arg, argv[idx_in_out]->arg);
7113 }
7114
7115 ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
7116 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
7117 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7118 "Apply route map to neighbor\n"
7119 "Name of route map\n"
7120 "Apply map to incoming routes\n"
7121 "Apply map to outbound routes\n")
7122
7123 DEFUN (no_neighbor_route_map,
7124 no_neighbor_route_map_cmd,
7125 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
7126 NO_STR
7127 NEIGHBOR_STR
7128 NEIGHBOR_ADDR_STR2
7129 "Apply route map to neighbor\n"
7130 "Name of route map\n"
7131 "Apply map to incoming routes\n"
7132 "Apply map to outbound routes\n")
7133 {
7134 int idx_peer = 2;
7135 int idx_in_out = 5;
7136 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
7137 bgp_node_afi(vty), bgp_node_safi(vty),
7138 argv[idx_in_out]->arg);
7139 }
7140
7141 ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
7142 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
7143 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7144 "Apply route map to neighbor\n"
7145 "Name of route map\n"
7146 "Apply map to incoming routes\n"
7147 "Apply map to outbound routes\n")
7148
7149 /* Set unsuppress-map to the peer. */
7150 static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
7151 afi_t afi, safi_t safi,
7152 const char *name_str)
7153 {
7154 int ret;
7155 struct peer *peer;
7156 struct route_map *route_map;
7157
7158 peer = peer_and_group_lookup_vty(vty, ip_str);
7159 if (!peer)
7160 return CMD_WARNING_CONFIG_FAILED;
7161
7162 route_map = route_map_lookup_warn_noexist(vty, name_str);
7163 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
7164
7165 return bgp_vty_return(vty, ret);
7166 }
7167
7168 /* Unset route-map from the peer. */
7169 static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
7170 afi_t afi, safi_t safi)
7171 {
7172 int ret;
7173 struct peer *peer;
7174
7175 peer = peer_and_group_lookup_vty(vty, ip_str);
7176 if (!peer)
7177 return CMD_WARNING_CONFIG_FAILED;
7178
7179 ret = peer_unsuppress_map_unset(peer, afi, safi);
7180
7181 return bgp_vty_return(vty, ret);
7182 }
7183
7184 DEFUN (neighbor_unsuppress_map,
7185 neighbor_unsuppress_map_cmd,
7186 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7187 NEIGHBOR_STR
7188 NEIGHBOR_ADDR_STR2
7189 "Route-map to selectively unsuppress suppressed routes\n"
7190 "Name of route map\n")
7191 {
7192 int idx_peer = 1;
7193 int idx_word = 3;
7194 return peer_unsuppress_map_set_vty(
7195 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7196 argv[idx_word]->arg);
7197 }
7198
7199 ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
7200 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7201 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7202 "Route-map to selectively unsuppress suppressed routes\n"
7203 "Name of route map\n")
7204
7205 DEFUN (no_neighbor_unsuppress_map,
7206 no_neighbor_unsuppress_map_cmd,
7207 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7208 NO_STR
7209 NEIGHBOR_STR
7210 NEIGHBOR_ADDR_STR2
7211 "Route-map to selectively unsuppress suppressed routes\n"
7212 "Name of route map\n")
7213 {
7214 int idx_peer = 2;
7215 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
7216 bgp_node_afi(vty),
7217 bgp_node_safi(vty));
7218 }
7219
7220 ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
7221 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7222 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7223 "Route-map to selectively unsuppress suppressed routes\n"
7224 "Name of route map\n")
7225
7226 static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
7227 afi_t afi, safi_t safi,
7228 const char *num_str,
7229 const char *threshold_str, int warning,
7230 const char *restart_str,
7231 const char *force_str)
7232 {
7233 int ret;
7234 struct peer *peer;
7235 uint32_t max;
7236 uint8_t threshold;
7237 uint16_t restart;
7238
7239 peer = peer_and_group_lookup_vty(vty, ip_str);
7240 if (!peer)
7241 return CMD_WARNING_CONFIG_FAILED;
7242
7243 max = strtoul(num_str, NULL, 10);
7244 if (threshold_str)
7245 threshold = atoi(threshold_str);
7246 else
7247 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
7248
7249 if (restart_str)
7250 restart = atoi(restart_str);
7251 else
7252 restart = 0;
7253
7254 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
7255 restart, force_str ? true : false);
7256
7257 return bgp_vty_return(vty, ret);
7258 }
7259
7260 static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
7261 afi_t afi, safi_t safi)
7262 {
7263 int ret;
7264 struct peer *peer;
7265
7266 peer = peer_and_group_lookup_vty(vty, ip_str);
7267 if (!peer)
7268 return CMD_WARNING_CONFIG_FAILED;
7269
7270 ret = peer_maximum_prefix_unset(peer, afi, safi);
7271
7272 return bgp_vty_return(vty, ret);
7273 }
7274
7275 /* Maximum number of prefix to be sent to the neighbor. */
7276 DEFUN(neighbor_maximum_prefix_out,
7277 neighbor_maximum_prefix_out_cmd,
7278 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out (1-4294967295)",
7279 NEIGHBOR_STR
7280 NEIGHBOR_ADDR_STR2
7281 "Maximum number of prefixes to be sent to this peer\n"
7282 "Maximum no. of prefix limit\n")
7283 {
7284 int idx_peer = 1;
7285 int idx_number = 3;
7286 struct peer *peer;
7287 uint32_t max;
7288 afi_t afi = bgp_node_afi(vty);
7289 safi_t safi = bgp_node_safi(vty);
7290
7291 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7292 if (!peer)
7293 return CMD_WARNING_CONFIG_FAILED;
7294
7295 max = strtoul(argv[idx_number]->arg, NULL, 10);
7296
7297 SET_FLAG(peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT);
7298 peer->pmax_out[afi][safi] = max;
7299
7300 return CMD_SUCCESS;
7301 }
7302
7303 DEFUN(no_neighbor_maximum_prefix_out,
7304 no_neighbor_maximum_prefix_out_cmd,
7305 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out",
7306 NO_STR
7307 NEIGHBOR_STR
7308 NEIGHBOR_ADDR_STR2
7309 "Maximum number of prefixes to be sent to this peer\n")
7310 {
7311 int idx_peer = 2;
7312 struct peer *peer;
7313 afi_t afi = bgp_node_afi(vty);
7314 safi_t safi = bgp_node_safi(vty);
7315
7316 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7317 if (!peer)
7318 return CMD_WARNING_CONFIG_FAILED;
7319
7320 UNSET_FLAG(peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT);
7321 peer->pmax_out[afi][safi] = 0;
7322
7323 return CMD_SUCCESS;
7324 }
7325
7326 /* Maximum number of prefix configuration. Prefix count is different
7327 for each peer configuration. So this configuration can be set for
7328 each peer configuration. */
7329 DEFUN (neighbor_maximum_prefix,
7330 neighbor_maximum_prefix_cmd,
7331 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
7332 NEIGHBOR_STR
7333 NEIGHBOR_ADDR_STR2
7334 "Maximum number of prefix accept from this peer\n"
7335 "maximum no. of prefix limit\n"
7336 "Force checking all received routes not only accepted\n")
7337 {
7338 int idx_peer = 1;
7339 int idx_number = 3;
7340 int idx_force = 0;
7341 char *force = NULL;
7342
7343 if (argv_find(argv, argc, "force", &idx_force))
7344 force = argv[idx_force]->arg;
7345
7346 return peer_maximum_prefix_set_vty(
7347 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7348 argv[idx_number]->arg, NULL, 0, NULL, force);
7349 }
7350
7351 ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
7352 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
7353 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7354 "Maximum number of prefix accept from this peer\n"
7355 "maximum no. of prefix limit\n"
7356 "Force checking all received routes not only accepted\n")
7357
7358 DEFUN (neighbor_maximum_prefix_threshold,
7359 neighbor_maximum_prefix_threshold_cmd,
7360 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
7361 NEIGHBOR_STR
7362 NEIGHBOR_ADDR_STR2
7363 "Maximum number of prefix accept from this peer\n"
7364 "maximum no. of prefix limit\n"
7365 "Threshold value (%) at which to generate a warning msg\n"
7366 "Force checking all received routes not only accepted\n")
7367 {
7368 int idx_peer = 1;
7369 int idx_number = 3;
7370 int idx_number_2 = 4;
7371 int idx_force = 0;
7372 char *force = NULL;
7373
7374 if (argv_find(argv, argc, "force", &idx_force))
7375 force = argv[idx_force]->arg;
7376
7377 return peer_maximum_prefix_set_vty(
7378 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7379 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL, force);
7380 }
7381
7382 ALIAS_HIDDEN(
7383 neighbor_maximum_prefix_threshold,
7384 neighbor_maximum_prefix_threshold_hidden_cmd,
7385 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
7386 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7387 "Maximum number of prefix accept from this peer\n"
7388 "maximum no. of prefix limit\n"
7389 "Threshold value (%) at which to generate a warning msg\n"
7390 "Force checking all received routes not only accepted\n")
7391
7392 DEFUN (neighbor_maximum_prefix_warning,
7393 neighbor_maximum_prefix_warning_cmd,
7394 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
7395 NEIGHBOR_STR
7396 NEIGHBOR_ADDR_STR2
7397 "Maximum number of prefix accept from this peer\n"
7398 "maximum no. of prefix limit\n"
7399 "Only give warning message when limit is exceeded\n"
7400 "Force checking all received routes not only accepted\n")
7401 {
7402 int idx_peer = 1;
7403 int idx_number = 3;
7404 int idx_force = 0;
7405 char *force = NULL;
7406
7407 if (argv_find(argv, argc, "force", &idx_force))
7408 force = argv[idx_force]->arg;
7409
7410 return peer_maximum_prefix_set_vty(
7411 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7412 argv[idx_number]->arg, NULL, 1, NULL, force);
7413 }
7414
7415 ALIAS_HIDDEN(
7416 neighbor_maximum_prefix_warning,
7417 neighbor_maximum_prefix_warning_hidden_cmd,
7418 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
7419 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7420 "Maximum number of prefix accept from this peer\n"
7421 "maximum no. of prefix limit\n"
7422 "Only give warning message when limit is exceeded\n"
7423 "Force checking all received routes not only accepted\n")
7424
7425 DEFUN (neighbor_maximum_prefix_threshold_warning,
7426 neighbor_maximum_prefix_threshold_warning_cmd,
7427 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
7428 NEIGHBOR_STR
7429 NEIGHBOR_ADDR_STR2
7430 "Maximum number of prefix accept from this peer\n"
7431 "maximum no. of prefix limit\n"
7432 "Threshold value (%) at which to generate a warning msg\n"
7433 "Only give warning message when limit is exceeded\n"
7434 "Force checking all received routes not only accepted\n")
7435 {
7436 int idx_peer = 1;
7437 int idx_number = 3;
7438 int idx_number_2 = 4;
7439 int idx_force = 0;
7440 char *force = NULL;
7441
7442 if (argv_find(argv, argc, "force", &idx_force))
7443 force = argv[idx_force]->arg;
7444
7445 return peer_maximum_prefix_set_vty(
7446 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7447 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL, force);
7448 }
7449
7450 ALIAS_HIDDEN(
7451 neighbor_maximum_prefix_threshold_warning,
7452 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
7453 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
7454 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7455 "Maximum number of prefix accept from this peer\n"
7456 "maximum no. of prefix limit\n"
7457 "Threshold value (%) at which to generate a warning msg\n"
7458 "Only give warning message when limit is exceeded\n"
7459 "Force checking all received routes not only accepted\n")
7460
7461 DEFUN (neighbor_maximum_prefix_restart,
7462 neighbor_maximum_prefix_restart_cmd,
7463 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
7464 NEIGHBOR_STR
7465 NEIGHBOR_ADDR_STR2
7466 "Maximum number of prefix accept from this peer\n"
7467 "maximum no. of prefix limit\n"
7468 "Restart bgp connection after limit is exceeded\n"
7469 "Restart interval in minutes\n"
7470 "Force checking all received routes not only accepted\n")
7471 {
7472 int idx_peer = 1;
7473 int idx_number = 3;
7474 int idx_number_2 = 5;
7475 int idx_force = 0;
7476 char *force = NULL;
7477
7478 if (argv_find(argv, argc, "force", &idx_force))
7479 force = argv[idx_force]->arg;
7480
7481 return peer_maximum_prefix_set_vty(
7482 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7483 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg, force);
7484 }
7485
7486 ALIAS_HIDDEN(
7487 neighbor_maximum_prefix_restart,
7488 neighbor_maximum_prefix_restart_hidden_cmd,
7489 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
7490 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7491 "Maximum number of prefix accept from this peer\n"
7492 "maximum no. of prefix limit\n"
7493 "Restart bgp connection after limit is exceeded\n"
7494 "Restart interval in minutes\n"
7495 "Force checking all received routes not only accepted\n")
7496
7497 DEFUN (neighbor_maximum_prefix_threshold_restart,
7498 neighbor_maximum_prefix_threshold_restart_cmd,
7499 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
7500 NEIGHBOR_STR
7501 NEIGHBOR_ADDR_STR2
7502 "Maximum number of prefixes to accept from this peer\n"
7503 "maximum no. of prefix limit\n"
7504 "Threshold value (%) at which to generate a warning msg\n"
7505 "Restart bgp connection after limit is exceeded\n"
7506 "Restart interval in minutes\n"
7507 "Force checking all received routes not only accepted\n")
7508 {
7509 int idx_peer = 1;
7510 int idx_number = 3;
7511 int idx_number_2 = 4;
7512 int idx_number_3 = 6;
7513 int idx_force = 0;
7514 char *force = NULL;
7515
7516 if (argv_find(argv, argc, "force", &idx_force))
7517 force = argv[idx_force]->arg;
7518
7519 return peer_maximum_prefix_set_vty(
7520 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7521 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
7522 argv[idx_number_3]->arg, force);
7523 }
7524
7525 ALIAS_HIDDEN(
7526 neighbor_maximum_prefix_threshold_restart,
7527 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
7528 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
7529 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7530 "Maximum number of prefixes to accept from this peer\n"
7531 "maximum no. of prefix limit\n"
7532 "Threshold value (%) at which to generate a warning msg\n"
7533 "Restart bgp connection after limit is exceeded\n"
7534 "Restart interval in minutes\n"
7535 "Force checking all received routes not only accepted\n")
7536
7537 DEFUN (no_neighbor_maximum_prefix,
7538 no_neighbor_maximum_prefix_cmd,
7539 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
7540 NO_STR
7541 NEIGHBOR_STR
7542 NEIGHBOR_ADDR_STR2
7543 "Maximum number of prefixes to accept from this peer\n"
7544 "maximum no. of prefix limit\n"
7545 "Threshold value (%) at which to generate a warning msg\n"
7546 "Restart bgp connection after limit is exceeded\n"
7547 "Restart interval in minutes\n"
7548 "Only give warning message when limit is exceeded\n"
7549 "Force checking all received routes not only accepted\n")
7550 {
7551 int idx_peer = 2;
7552 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
7553 bgp_node_afi(vty),
7554 bgp_node_safi(vty));
7555 }
7556
7557 ALIAS_HIDDEN(
7558 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
7559 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
7560 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7561 "Maximum number of prefixes to accept from this peer\n"
7562 "maximum no. of prefix limit\n"
7563 "Threshold value (%) at which to generate a warning msg\n"
7564 "Restart bgp connection after limit is exceeded\n"
7565 "Restart interval in minutes\n"
7566 "Only give warning message when limit is exceeded\n"
7567 "Force checking all received routes not only accepted\n")
7568
7569
7570 /* "neighbor allowas-in" */
7571 DEFUN (neighbor_allowas_in,
7572 neighbor_allowas_in_cmd,
7573 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
7574 NEIGHBOR_STR
7575 NEIGHBOR_ADDR_STR2
7576 "Accept as-path with my AS present in it\n"
7577 "Number of occurrences of AS number\n"
7578 "Only accept my AS in the as-path if the route was originated in my AS\n")
7579 {
7580 int idx_peer = 1;
7581 int idx_number_origin = 3;
7582 int ret;
7583 int origin = 0;
7584 struct peer *peer;
7585 int allow_num = 0;
7586
7587 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7588 if (!peer)
7589 return CMD_WARNING_CONFIG_FAILED;
7590
7591 if (argc <= idx_number_origin)
7592 allow_num = 3;
7593 else {
7594 if (argv[idx_number_origin]->type == WORD_TKN)
7595 origin = 1;
7596 else
7597 allow_num = atoi(argv[idx_number_origin]->arg);
7598 }
7599
7600 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7601 allow_num, origin);
7602
7603 return bgp_vty_return(vty, ret);
7604 }
7605
7606 ALIAS_HIDDEN(
7607 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
7608 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
7609 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7610 "Accept as-path with my AS present in it\n"
7611 "Number of occurrences of AS number\n"
7612 "Only accept my AS in the as-path if the route was originated in my AS\n")
7613
7614 DEFUN (no_neighbor_allowas_in,
7615 no_neighbor_allowas_in_cmd,
7616 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
7617 NO_STR
7618 NEIGHBOR_STR
7619 NEIGHBOR_ADDR_STR2
7620 "allow local ASN appears in aspath attribute\n"
7621 "Number of occurrences of AS number\n"
7622 "Only accept my AS in the as-path if the route was originated in my AS\n")
7623 {
7624 int idx_peer = 2;
7625 int ret;
7626 struct peer *peer;
7627
7628 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7629 if (!peer)
7630 return CMD_WARNING_CONFIG_FAILED;
7631
7632 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
7633 bgp_node_safi(vty));
7634
7635 return bgp_vty_return(vty, ret);
7636 }
7637
7638 ALIAS_HIDDEN(
7639 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
7640 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
7641 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7642 "allow local ASN appears in aspath attribute\n"
7643 "Number of occurrences of AS number\n"
7644 "Only accept my AS in the as-path if the route was originated in my AS\n")
7645
7646 DEFUN (neighbor_ttl_security,
7647 neighbor_ttl_security_cmd,
7648 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
7649 NEIGHBOR_STR
7650 NEIGHBOR_ADDR_STR2
7651 "BGP ttl-security parameters\n"
7652 "Specify the maximum number of hops to the BGP peer\n"
7653 "Number of hops to BGP peer\n")
7654 {
7655 int idx_peer = 1;
7656 int idx_number = 4;
7657 struct peer *peer;
7658 int gtsm_hops;
7659
7660 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7661 if (!peer)
7662 return CMD_WARNING_CONFIG_FAILED;
7663
7664 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
7665
7666 /*
7667 * If 'neighbor swpX', then this is for directly connected peers,
7668 * we should not accept a ttl-security hops value greater than 1.
7669 */
7670 if (peer->conf_if && (gtsm_hops > BGP_GTSM_HOPS_CONNECTED)) {
7671 vty_out(vty,
7672 "%s is directly connected peer, hops cannot exceed 1\n",
7673 argv[idx_peer]->arg);
7674 return CMD_WARNING_CONFIG_FAILED;
7675 }
7676
7677 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
7678 }
7679
7680 DEFUN (no_neighbor_ttl_security,
7681 no_neighbor_ttl_security_cmd,
7682 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
7683 NO_STR
7684 NEIGHBOR_STR
7685 NEIGHBOR_ADDR_STR2
7686 "BGP ttl-security parameters\n"
7687 "Specify the maximum number of hops to the BGP peer\n"
7688 "Number of hops to BGP peer\n")
7689 {
7690 int idx_peer = 2;
7691 struct peer *peer;
7692
7693 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7694 if (!peer)
7695 return CMD_WARNING_CONFIG_FAILED;
7696
7697 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
7698 }
7699
7700 DEFUN (neighbor_addpath_tx_all_paths,
7701 neighbor_addpath_tx_all_paths_cmd,
7702 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
7703 NEIGHBOR_STR
7704 NEIGHBOR_ADDR_STR2
7705 "Use addpath to advertise all paths to a neighbor\n")
7706 {
7707 int idx_peer = 1;
7708 struct peer *peer;
7709
7710 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7711 if (!peer)
7712 return CMD_WARNING_CONFIG_FAILED;
7713
7714 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7715 BGP_ADDPATH_ALL);
7716 return CMD_SUCCESS;
7717 }
7718
7719 ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
7720 neighbor_addpath_tx_all_paths_hidden_cmd,
7721 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
7722 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7723 "Use addpath to advertise all paths to a neighbor\n")
7724
7725 DEFUN (no_neighbor_addpath_tx_all_paths,
7726 no_neighbor_addpath_tx_all_paths_cmd,
7727 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
7728 NO_STR
7729 NEIGHBOR_STR
7730 NEIGHBOR_ADDR_STR2
7731 "Use addpath to advertise all paths to a neighbor\n")
7732 {
7733 int idx_peer = 2;
7734 struct peer *peer;
7735
7736 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7737 if (!peer)
7738 return CMD_WARNING_CONFIG_FAILED;
7739
7740 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
7741 != BGP_ADDPATH_ALL) {
7742 vty_out(vty,
7743 "%% Peer not currently configured to transmit all paths.");
7744 return CMD_WARNING_CONFIG_FAILED;
7745 }
7746
7747 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7748 BGP_ADDPATH_NONE);
7749
7750 return CMD_SUCCESS;
7751 }
7752
7753 ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
7754 no_neighbor_addpath_tx_all_paths_hidden_cmd,
7755 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
7756 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7757 "Use addpath to advertise all paths to a neighbor\n")
7758
7759 DEFUN (neighbor_addpath_tx_bestpath_per_as,
7760 neighbor_addpath_tx_bestpath_per_as_cmd,
7761 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
7762 NEIGHBOR_STR
7763 NEIGHBOR_ADDR_STR2
7764 "Use addpath to advertise the bestpath per each neighboring AS\n")
7765 {
7766 int idx_peer = 1;
7767 struct peer *peer;
7768
7769 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7770 if (!peer)
7771 return CMD_WARNING_CONFIG_FAILED;
7772
7773 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7774 BGP_ADDPATH_BEST_PER_AS);
7775
7776 return CMD_SUCCESS;
7777 }
7778
7779 ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
7780 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
7781 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
7782 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7783 "Use addpath to advertise the bestpath per each neighboring AS\n")
7784
7785 DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
7786 no_neighbor_addpath_tx_bestpath_per_as_cmd,
7787 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
7788 NO_STR
7789 NEIGHBOR_STR
7790 NEIGHBOR_ADDR_STR2
7791 "Use addpath to advertise the bestpath per each neighboring AS\n")
7792 {
7793 int idx_peer = 2;
7794 struct peer *peer;
7795
7796 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7797 if (!peer)
7798 return CMD_WARNING_CONFIG_FAILED;
7799
7800 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
7801 != BGP_ADDPATH_BEST_PER_AS) {
7802 vty_out(vty,
7803 "%% Peer not currently configured to transmit all best path per as.");
7804 return CMD_WARNING_CONFIG_FAILED;
7805 }
7806
7807 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7808 BGP_ADDPATH_NONE);
7809
7810 return CMD_SUCCESS;
7811 }
7812
7813 ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
7814 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
7815 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
7816 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7817 "Use addpath to advertise the bestpath per each neighboring AS\n")
7818
7819 DEFPY(
7820 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
7821 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
7822 NEIGHBOR_STR
7823 NEIGHBOR_ADDR_STR2
7824 "Detect AS loops before sending to neighbor\n")
7825 {
7826 struct peer *peer;
7827
7828 peer = peer_and_group_lookup_vty(vty, neighbor);
7829 if (!peer)
7830 return CMD_WARNING_CONFIG_FAILED;
7831
7832 peer->as_path_loop_detection = true;
7833
7834 return CMD_SUCCESS;
7835 }
7836
7837 DEFPY(
7838 no_neighbor_aspath_loop_detection,
7839 no_neighbor_aspath_loop_detection_cmd,
7840 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
7841 NO_STR
7842 NEIGHBOR_STR
7843 NEIGHBOR_ADDR_STR2
7844 "Detect AS loops before sending to neighbor\n")
7845 {
7846 struct peer *peer;
7847
7848 peer = peer_and_group_lookup_vty(vty, neighbor);
7849 if (!peer)
7850 return CMD_WARNING_CONFIG_FAILED;
7851
7852 peer->as_path_loop_detection = false;
7853
7854 return CMD_SUCCESS;
7855 }
7856
7857 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
7858 struct ecommunity **list, bool is_rt6)
7859 {
7860 struct ecommunity *ecom = NULL;
7861 struct ecommunity *ecomadd;
7862
7863 for (; argc; --argc, ++argv) {
7864 if (is_rt6)
7865 ecomadd = ecommunity_str2com_ipv6(argv[0]->arg,
7866 ECOMMUNITY_ROUTE_TARGET,
7867 0);
7868 else
7869 ecomadd = ecommunity_str2com(argv[0]->arg,
7870 ECOMMUNITY_ROUTE_TARGET,
7871 0);
7872 if (!ecomadd) {
7873 vty_out(vty, "Malformed community-list value\n");
7874 if (ecom)
7875 ecommunity_free(&ecom);
7876 return CMD_WARNING_CONFIG_FAILED;
7877 }
7878
7879 if (ecom) {
7880 ecommunity_merge(ecom, ecomadd);
7881 ecommunity_free(&ecomadd);
7882 } else {
7883 ecom = ecomadd;
7884 }
7885 }
7886
7887 if (*list) {
7888 ecommunity_free(&*list);
7889 }
7890 *list = ecom;
7891
7892 return CMD_SUCCESS;
7893 }
7894
7895 /*
7896 * v2vimport is true if we are handling a `import vrf ...` command
7897 */
7898 static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
7899 {
7900 afi_t afi;
7901
7902 switch (vty->node) {
7903 case BGP_IPV4_NODE:
7904 afi = AFI_IP;
7905 break;
7906 case BGP_IPV6_NODE:
7907 afi = AFI_IP6;
7908 break;
7909 default:
7910 vty_out(vty,
7911 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
7912 return AFI_MAX;
7913 }
7914
7915 if (!v2vimport) {
7916 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
7917 BGP_CONFIG_VRF_TO_VRF_IMPORT)
7918 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
7919 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
7920 vty_out(vty,
7921 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
7922 return AFI_MAX;
7923 }
7924 } else {
7925 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
7926 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
7927 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
7928 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
7929 vty_out(vty,
7930 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
7931 return AFI_MAX;
7932 }
7933 }
7934 return afi;
7935 }
7936
7937 DEFPY (af_rd_vpn_export,
7938 af_rd_vpn_export_cmd,
7939 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
7940 NO_STR
7941 "Specify route distinguisher\n"
7942 "Between current address-family and vpn\n"
7943 "For routes leaked from current address-family to vpn\n"
7944 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
7945 {
7946 VTY_DECLVAR_CONTEXT(bgp, bgp);
7947 struct prefix_rd prd;
7948 int ret;
7949 afi_t afi;
7950 int idx = 0;
7951 bool yes = true;
7952
7953 if (argv_find(argv, argc, "no", &idx))
7954 yes = false;
7955
7956 if (yes) {
7957 ret = str2prefix_rd(rd_str, &prd);
7958 if (!ret) {
7959 vty_out(vty, "%% Malformed rd\n");
7960 return CMD_WARNING_CONFIG_FAILED;
7961 }
7962 }
7963
7964 afi = vpn_policy_getafi(vty, bgp, false);
7965 if (afi == AFI_MAX)
7966 return CMD_WARNING_CONFIG_FAILED;
7967
7968 /*
7969 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
7970 */
7971 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
7972 bgp_get_default(), bgp);
7973
7974 if (yes) {
7975 bgp->vpn_policy[afi].tovpn_rd = prd;
7976 SET_FLAG(bgp->vpn_policy[afi].flags,
7977 BGP_VPN_POLICY_TOVPN_RD_SET);
7978 } else {
7979 UNSET_FLAG(bgp->vpn_policy[afi].flags,
7980 BGP_VPN_POLICY_TOVPN_RD_SET);
7981 }
7982
7983 /* post-change: re-export vpn routes */
7984 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
7985 bgp_get_default(), bgp);
7986
7987 return CMD_SUCCESS;
7988 }
7989
7990 ALIAS (af_rd_vpn_export,
7991 af_no_rd_vpn_export_cmd,
7992 "no rd vpn export",
7993 NO_STR
7994 "Specify route distinguisher\n"
7995 "Between current address-family and vpn\n"
7996 "For routes leaked from current address-family to vpn\n")
7997
7998 DEFPY (af_label_vpn_export,
7999 af_label_vpn_export_cmd,
8000 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
8001 NO_STR
8002 "label value for VRF\n"
8003 "Between current address-family and vpn\n"
8004 "For routes leaked from current address-family to vpn\n"
8005 "Label Value <0-1048575>\n"
8006 "Automatically assign a label\n")
8007 {
8008 VTY_DECLVAR_CONTEXT(bgp, bgp);
8009 mpls_label_t label = MPLS_LABEL_NONE;
8010 afi_t afi;
8011 int idx = 0;
8012 bool yes = true;
8013
8014 if (argv_find(argv, argc, "no", &idx))
8015 yes = false;
8016
8017 /* If "no ...", squash trailing parameter */
8018 if (!yes)
8019 label_auto = NULL;
8020
8021 if (yes) {
8022 if (!label_auto)
8023 label = label_val; /* parser should force unsigned */
8024 }
8025
8026 afi = vpn_policy_getafi(vty, bgp, false);
8027 if (afi == AFI_MAX)
8028 return CMD_WARNING_CONFIG_FAILED;
8029
8030
8031 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8032 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
8033 /* no change */
8034 return CMD_SUCCESS;
8035
8036 /*
8037 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8038 */
8039 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8040 bgp_get_default(), bgp);
8041
8042 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8043 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
8044
8045 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
8046
8047 /*
8048 * label has previously been automatically
8049 * assigned by labelpool: release it
8050 *
8051 * NB if tovpn_label == MPLS_LABEL_NONE it
8052 * means the automatic assignment is in flight
8053 * and therefore the labelpool callback must
8054 * detect that the auto label is not needed.
8055 */
8056
8057 bgp_lp_release(LP_TYPE_VRF,
8058 &bgp->vpn_policy[afi],
8059 bgp->vpn_policy[afi].tovpn_label);
8060 }
8061 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8062 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
8063 }
8064
8065 bgp->vpn_policy[afi].tovpn_label = label;
8066 if (label_auto) {
8067 SET_FLAG(bgp->vpn_policy[afi].flags,
8068 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
8069 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
8070 vpn_leak_label_callback);
8071 }
8072
8073 /* post-change: re-export vpn routes */
8074 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8075 bgp_get_default(), bgp);
8076
8077 return CMD_SUCCESS;
8078 }
8079
8080 ALIAS (af_label_vpn_export,
8081 af_no_label_vpn_export_cmd,
8082 "no label vpn export",
8083 NO_STR
8084 "label value for VRF\n"
8085 "Between current address-family and vpn\n"
8086 "For routes leaked from current address-family to vpn\n")
8087
8088 DEFPY (af_nexthop_vpn_export,
8089 af_nexthop_vpn_export_cmd,
8090 "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
8091 NO_STR
8092 "Specify next hop to use for VRF advertised prefixes\n"
8093 "Between current address-family and vpn\n"
8094 "For routes leaked from current address-family to vpn\n"
8095 "IPv4 prefix\n"
8096 "IPv6 prefix\n")
8097 {
8098 VTY_DECLVAR_CONTEXT(bgp, bgp);
8099 afi_t afi;
8100 struct prefix p;
8101
8102 if (!no) {
8103 if (!nexthop_su) {
8104 vty_out(vty, "%% Nexthop required\n");
8105 return CMD_WARNING_CONFIG_FAILED;
8106 }
8107 if (!sockunion2hostprefix(nexthop_su, &p))
8108 return CMD_WARNING_CONFIG_FAILED;
8109 }
8110
8111 afi = vpn_policy_getafi(vty, bgp, false);
8112 if (afi == AFI_MAX)
8113 return CMD_WARNING_CONFIG_FAILED;
8114
8115 /*
8116 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8117 */
8118 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8119 bgp_get_default(), bgp);
8120
8121 if (!no) {
8122 bgp->vpn_policy[afi].tovpn_nexthop = p;
8123 SET_FLAG(bgp->vpn_policy[afi].flags,
8124 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
8125 } else {
8126 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8127 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
8128 }
8129
8130 /* post-change: re-export vpn routes */
8131 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8132 bgp_get_default(), bgp);
8133
8134 return CMD_SUCCESS;
8135 }
8136
8137 static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
8138 {
8139 if (!strcmp(dstr, "import")) {
8140 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
8141 } else if (!strcmp(dstr, "export")) {
8142 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
8143 } else if (!strcmp(dstr, "both")) {
8144 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
8145 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
8146 } else {
8147 vty_out(vty, "%% direction parse error\n");
8148 return CMD_WARNING_CONFIG_FAILED;
8149 }
8150 return CMD_SUCCESS;
8151 }
8152
8153 DEFPY (af_rt_vpn_imexport,
8154 af_rt_vpn_imexport_cmd,
8155 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
8156 NO_STR
8157 "Specify route target list\n"
8158 "Specify route target list\n"
8159 "Between current address-family and vpn\n"
8160 "For routes leaked from vpn to current address-family: match any\n"
8161 "For routes leaked from current address-family to vpn: set\n"
8162 "both import: match any and export: set\n"
8163 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
8164 {
8165 VTY_DECLVAR_CONTEXT(bgp, bgp);
8166 int ret;
8167 struct ecommunity *ecom = NULL;
8168 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
8169 vpn_policy_direction_t dir;
8170 afi_t afi;
8171 int idx = 0;
8172 bool yes = true;
8173
8174 if (argv_find(argv, argc, "no", &idx))
8175 yes = false;
8176
8177 afi = vpn_policy_getafi(vty, bgp, false);
8178 if (afi == AFI_MAX)
8179 return CMD_WARNING_CONFIG_FAILED;
8180
8181 ret = vpn_policy_getdirs(vty, direction_str, dodir);
8182 if (ret != CMD_SUCCESS)
8183 return ret;
8184
8185 if (yes) {
8186 if (!argv_find(argv, argc, "RTLIST", &idx)) {
8187 vty_out(vty, "%% Missing RTLIST\n");
8188 return CMD_WARNING_CONFIG_FAILED;
8189 }
8190 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, false);
8191 if (ret != CMD_SUCCESS) {
8192 return ret;
8193 }
8194 }
8195
8196 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
8197 if (!dodir[dir])
8198 continue;
8199
8200 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
8201
8202 if (yes) {
8203 if (bgp->vpn_policy[afi].rtlist[dir])
8204 ecommunity_free(
8205 &bgp->vpn_policy[afi].rtlist[dir]);
8206 bgp->vpn_policy[afi].rtlist[dir] =
8207 ecommunity_dup(ecom);
8208 } else {
8209 if (bgp->vpn_policy[afi].rtlist[dir])
8210 ecommunity_free(
8211 &bgp->vpn_policy[afi].rtlist[dir]);
8212 bgp->vpn_policy[afi].rtlist[dir] = NULL;
8213 }
8214
8215 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
8216 }
8217
8218 if (ecom)
8219 ecommunity_free(&ecom);
8220
8221 return CMD_SUCCESS;
8222 }
8223
8224 ALIAS (af_rt_vpn_imexport,
8225 af_no_rt_vpn_imexport_cmd,
8226 "no <rt|route-target> vpn <import|export|both>$direction_str",
8227 NO_STR
8228 "Specify route target list\n"
8229 "Specify route target list\n"
8230 "Between current address-family and vpn\n"
8231 "For routes leaked from vpn to current address-family\n"
8232 "For routes leaked from current address-family to vpn\n"
8233 "both import and export\n")
8234
8235 DEFPY (af_route_map_vpn_imexport,
8236 af_route_map_vpn_imexport_cmd,
8237 /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
8238 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
8239 NO_STR
8240 "Specify route map\n"
8241 "Between current address-family and vpn\n"
8242 "For routes leaked from vpn to current address-family\n"
8243 "For routes leaked from current address-family to vpn\n"
8244 "name of route-map\n")
8245 {
8246 VTY_DECLVAR_CONTEXT(bgp, bgp);
8247 int ret;
8248 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
8249 vpn_policy_direction_t dir;
8250 afi_t afi;
8251 int idx = 0;
8252 bool yes = true;
8253
8254 if (argv_find(argv, argc, "no", &idx))
8255 yes = false;
8256
8257 afi = vpn_policy_getafi(vty, bgp, false);
8258 if (afi == AFI_MAX)
8259 return CMD_WARNING_CONFIG_FAILED;
8260
8261 ret = vpn_policy_getdirs(vty, direction_str, dodir);
8262 if (ret != CMD_SUCCESS)
8263 return ret;
8264
8265 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
8266 if (!dodir[dir])
8267 continue;
8268
8269 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
8270
8271 if (yes) {
8272 if (bgp->vpn_policy[afi].rmap_name[dir])
8273 XFREE(MTYPE_ROUTE_MAP_NAME,
8274 bgp->vpn_policy[afi].rmap_name[dir]);
8275 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
8276 MTYPE_ROUTE_MAP_NAME, rmap_str);
8277 bgp->vpn_policy[afi].rmap[dir] =
8278 route_map_lookup_warn_noexist(vty, rmap_str);
8279 if (!bgp->vpn_policy[afi].rmap[dir])
8280 return CMD_SUCCESS;
8281 } else {
8282 if (bgp->vpn_policy[afi].rmap_name[dir])
8283 XFREE(MTYPE_ROUTE_MAP_NAME,
8284 bgp->vpn_policy[afi].rmap_name[dir]);
8285 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
8286 bgp->vpn_policy[afi].rmap[dir] = NULL;
8287 }
8288
8289 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
8290 }
8291
8292 return CMD_SUCCESS;
8293 }
8294
8295 ALIAS (af_route_map_vpn_imexport,
8296 af_no_route_map_vpn_imexport_cmd,
8297 "no route-map vpn <import|export>$direction_str",
8298 NO_STR
8299 "Specify route map\n"
8300 "Between current address-family and vpn\n"
8301 "For routes leaked from vpn to current address-family\n"
8302 "For routes leaked from current address-family to vpn\n")
8303
8304 DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
8305 "import vrf route-map RMAP$rmap_str",
8306 "Import routes from another VRF\n"
8307 "Vrf routes being filtered\n"
8308 "Specify route map\n"
8309 "name of route-map\n")
8310 {
8311 VTY_DECLVAR_CONTEXT(bgp, bgp);
8312 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
8313 afi_t afi;
8314 struct bgp *bgp_default;
8315
8316 afi = vpn_policy_getafi(vty, bgp, true);
8317 if (afi == AFI_MAX)
8318 return CMD_WARNING_CONFIG_FAILED;
8319
8320 bgp_default = bgp_get_default();
8321 if (!bgp_default) {
8322 int32_t ret;
8323 as_t as = bgp->as;
8324
8325 /* Auto-create assuming the same AS */
8326 ret = bgp_get_vty(&bgp_default, &as, NULL,
8327 BGP_INSTANCE_TYPE_DEFAULT);
8328
8329 if (ret) {
8330 vty_out(vty,
8331 "VRF default is not configured as a bgp instance\n");
8332 return CMD_WARNING;
8333 }
8334 }
8335
8336 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
8337
8338 if (bgp->vpn_policy[afi].rmap_name[dir])
8339 XFREE(MTYPE_ROUTE_MAP_NAME,
8340 bgp->vpn_policy[afi].rmap_name[dir]);
8341 bgp->vpn_policy[afi].rmap_name[dir] =
8342 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
8343 bgp->vpn_policy[afi].rmap[dir] =
8344 route_map_lookup_warn_noexist(vty, rmap_str);
8345 if (!bgp->vpn_policy[afi].rmap[dir])
8346 return CMD_SUCCESS;
8347
8348 SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8349 BGP_CONFIG_VRF_TO_VRF_IMPORT);
8350
8351 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
8352
8353 return CMD_SUCCESS;
8354 }
8355
8356 DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
8357 "no import vrf route-map [RMAP$rmap_str]",
8358 NO_STR
8359 "Import routes from another VRF\n"
8360 "Vrf routes being filtered\n"
8361 "Specify route map\n"
8362 "name of route-map\n")
8363 {
8364 VTY_DECLVAR_CONTEXT(bgp, bgp);
8365 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
8366 afi_t afi;
8367
8368 afi = vpn_policy_getafi(vty, bgp, true);
8369 if (afi == AFI_MAX)
8370 return CMD_WARNING_CONFIG_FAILED;
8371
8372 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
8373
8374 if (bgp->vpn_policy[afi].rmap_name[dir])
8375 XFREE(MTYPE_ROUTE_MAP_NAME,
8376 bgp->vpn_policy[afi].rmap_name[dir]);
8377 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
8378 bgp->vpn_policy[afi].rmap[dir] = NULL;
8379
8380 if (bgp->vpn_policy[afi].import_vrf->count == 0)
8381 UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8382 BGP_CONFIG_VRF_TO_VRF_IMPORT);
8383
8384 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
8385
8386 return CMD_SUCCESS;
8387 }
8388
8389 DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
8390 "[no] import vrf VIEWVRFNAME$import_name",
8391 NO_STR
8392 "Import routes from another VRF\n"
8393 "VRF to import from\n"
8394 "The name of the VRF\n")
8395 {
8396 VTY_DECLVAR_CONTEXT(bgp, bgp);
8397 struct listnode *node;
8398 struct bgp *vrf_bgp, *bgp_default;
8399 int32_t ret = 0;
8400 as_t as = bgp->as;
8401 bool remove = false;
8402 int32_t idx = 0;
8403 char *vname;
8404 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
8405 safi_t safi;
8406 afi_t afi;
8407
8408 if (import_name == NULL) {
8409 vty_out(vty, "%% Missing import name\n");
8410 return CMD_WARNING;
8411 }
8412
8413 if (strcmp(import_name, "route-map") == 0) {
8414 vty_out(vty, "%% Must include route-map name\n");
8415 return CMD_WARNING;
8416 }
8417
8418 if (argv_find(argv, argc, "no", &idx))
8419 remove = true;
8420
8421 afi = vpn_policy_getafi(vty, bgp, true);
8422 if (afi == AFI_MAX)
8423 return CMD_WARNING_CONFIG_FAILED;
8424
8425 safi = bgp_node_safi(vty);
8426
8427 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
8428 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
8429 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
8430 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
8431 remove ? "unimport" : "import", import_name);
8432 return CMD_WARNING;
8433 }
8434
8435 bgp_default = bgp_get_default();
8436 if (!bgp_default) {
8437 /* Auto-create assuming the same AS */
8438 ret = bgp_get_vty(&bgp_default, &as, NULL,
8439 BGP_INSTANCE_TYPE_DEFAULT);
8440
8441 if (ret) {
8442 vty_out(vty,
8443 "VRF default is not configured as a bgp instance\n");
8444 return CMD_WARNING;
8445 }
8446 }
8447
8448 vrf_bgp = bgp_lookup_by_name(import_name);
8449 if (!vrf_bgp) {
8450 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
8451 vrf_bgp = bgp_default;
8452 else
8453 /* Auto-create assuming the same AS */
8454 ret = bgp_get_vty(&vrf_bgp, &as, import_name, bgp_type);
8455
8456 if (ret) {
8457 vty_out(vty,
8458 "VRF %s is not configured as a bgp instance\n",
8459 import_name);
8460 return CMD_WARNING;
8461 }
8462 }
8463
8464 if (remove) {
8465 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
8466 } else {
8467 /* Already importing from "import_vrf"? */
8468 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
8469 vname)) {
8470 if (strcmp(vname, import_name) == 0)
8471 return CMD_WARNING;
8472 }
8473
8474 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
8475 }
8476
8477 return CMD_SUCCESS;
8478 }
8479
8480 /* This command is valid only in a bgp vrf instance or the default instance */
8481 DEFPY (bgp_imexport_vpn,
8482 bgp_imexport_vpn_cmd,
8483 "[no] <import|export>$direction_str vpn",
8484 NO_STR
8485 "Import routes to this address-family\n"
8486 "Export routes from this address-family\n"
8487 "to/from default instance VPN RIB\n")
8488 {
8489 VTY_DECLVAR_CONTEXT(bgp, bgp);
8490 int previous_state;
8491 afi_t afi;
8492 safi_t safi;
8493 int idx = 0;
8494 bool yes = true;
8495 int flag;
8496 vpn_policy_direction_t dir;
8497
8498 if (argv_find(argv, argc, "no", &idx))
8499 yes = false;
8500
8501 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
8502 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
8503
8504 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
8505 return CMD_WARNING_CONFIG_FAILED;
8506 }
8507
8508 afi = bgp_node_afi(vty);
8509 safi = bgp_node_safi(vty);
8510 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
8511 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
8512 return CMD_WARNING_CONFIG_FAILED;
8513 }
8514
8515 if (!strcmp(direction_str, "import")) {
8516 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
8517 dir = BGP_VPN_POLICY_DIR_FROMVPN;
8518 } else if (!strcmp(direction_str, "export")) {
8519 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
8520 dir = BGP_VPN_POLICY_DIR_TOVPN;
8521 } else {
8522 vty_out(vty, "%% unknown direction %s\n", direction_str);
8523 return CMD_WARNING_CONFIG_FAILED;
8524 }
8525
8526 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
8527
8528 if (yes) {
8529 SET_FLAG(bgp->af_flags[afi][safi], flag);
8530 if (!previous_state) {
8531 /* trigger export current vrf */
8532 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
8533 }
8534 } else {
8535 if (previous_state) {
8536 /* trigger un-export current vrf */
8537 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
8538 }
8539 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
8540 }
8541
8542 return CMD_SUCCESS;
8543 }
8544
8545 DEFPY (af_routetarget_import,
8546 af_routetarget_import_cmd,
8547 "[no] <rt|route-target|route-target6|rt6> redirect import RTLIST...",
8548 NO_STR
8549 "Specify route target list\n"
8550 "Specify route target list\n"
8551 "Specify route target list\n"
8552 "Specify route target list\n"
8553 "Flow-spec redirect type route target\n"
8554 "Import routes to this address-family\n"
8555 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN|IPV6:MN)\n")
8556 {
8557 VTY_DECLVAR_CONTEXT(bgp, bgp);
8558 int ret;
8559 struct ecommunity *ecom = NULL;
8560 afi_t afi;
8561 int idx = 0, idx_unused = 0;
8562 bool yes = true;
8563 bool rt6 = false;
8564
8565 if (argv_find(argv, argc, "no", &idx))
8566 yes = false;
8567
8568 if (argv_find(argv, argc, "rt6", &idx_unused) ||
8569 argv_find(argv, argc, "route-target6", &idx_unused))
8570 rt6 = true;
8571
8572 afi = vpn_policy_getafi(vty, bgp, false);
8573 if (afi == AFI_MAX)
8574 return CMD_WARNING_CONFIG_FAILED;
8575
8576 if (rt6 && afi != AFI_IP6)
8577 return CMD_WARNING_CONFIG_FAILED;
8578
8579 if (yes) {
8580 if (!argv_find(argv, argc, "RTLIST", &idx)) {
8581 vty_out(vty, "%% Missing RTLIST\n");
8582 return CMD_WARNING_CONFIG_FAILED;
8583 }
8584 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, rt6);
8585 if (ret != CMD_SUCCESS)
8586 return ret;
8587 }
8588
8589 if (yes) {
8590 if (bgp->vpn_policy[afi].import_redirect_rtlist)
8591 ecommunity_free(&bgp->vpn_policy[afi]
8592 .import_redirect_rtlist);
8593 bgp->vpn_policy[afi].import_redirect_rtlist =
8594 ecommunity_dup(ecom);
8595 } else {
8596 if (bgp->vpn_policy[afi].import_redirect_rtlist)
8597 ecommunity_free(&bgp->vpn_policy[afi]
8598 .import_redirect_rtlist);
8599 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
8600 }
8601
8602 if (ecom)
8603 ecommunity_free(&ecom);
8604
8605 return CMD_SUCCESS;
8606 }
8607
8608 DEFUN_NOSH (address_family_ipv4_safi,
8609 address_family_ipv4_safi_cmd,
8610 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
8611 "Enter Address Family command mode\n"
8612 "Address Family\n"
8613 BGP_SAFI_WITH_LABEL_HELP_STR)
8614 {
8615
8616 if (argc == 3) {
8617 VTY_DECLVAR_CONTEXT(bgp, bgp);
8618 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
8619 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
8620 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
8621 && safi != SAFI_EVPN) {
8622 vty_out(vty,
8623 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
8624 return CMD_WARNING_CONFIG_FAILED;
8625 }
8626 vty->node = bgp_node_type(AFI_IP, safi);
8627 } else
8628 vty->node = BGP_IPV4_NODE;
8629
8630 return CMD_SUCCESS;
8631 }
8632
8633 DEFUN_NOSH (address_family_ipv6_safi,
8634 address_family_ipv6_safi_cmd,
8635 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
8636 "Enter Address Family command mode\n"
8637 "Address Family\n"
8638 BGP_SAFI_WITH_LABEL_HELP_STR)
8639 {
8640 if (argc == 3) {
8641 VTY_DECLVAR_CONTEXT(bgp, bgp);
8642 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
8643 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
8644 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
8645 && safi != SAFI_EVPN) {
8646 vty_out(vty,
8647 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
8648 return CMD_WARNING_CONFIG_FAILED;
8649 }
8650 vty->node = bgp_node_type(AFI_IP6, safi);
8651 } else
8652 vty->node = BGP_IPV6_NODE;
8653
8654 return CMD_SUCCESS;
8655 }
8656
8657 #ifdef KEEP_OLD_VPN_COMMANDS
8658 DEFUN_NOSH (address_family_vpnv4,
8659 address_family_vpnv4_cmd,
8660 "address-family vpnv4 [unicast]",
8661 "Enter Address Family command mode\n"
8662 "Address Family\n"
8663 "Address Family modifier\n")
8664 {
8665 vty->node = BGP_VPNV4_NODE;
8666 return CMD_SUCCESS;
8667 }
8668
8669 DEFUN_NOSH (address_family_vpnv6,
8670 address_family_vpnv6_cmd,
8671 "address-family vpnv6 [unicast]",
8672 "Enter Address Family command mode\n"
8673 "Address Family\n"
8674 "Address Family modifier\n")
8675 {
8676 vty->node = BGP_VPNV6_NODE;
8677 return CMD_SUCCESS;
8678 }
8679 #endif /* KEEP_OLD_VPN_COMMANDS */
8680
8681 DEFUN_NOSH (address_family_evpn,
8682 address_family_evpn_cmd,
8683 "address-family l2vpn evpn",
8684 "Enter Address Family command mode\n"
8685 "Address Family\n"
8686 "Address Family modifier\n")
8687 {
8688 VTY_DECLVAR_CONTEXT(bgp, bgp);
8689 vty->node = BGP_EVPN_NODE;
8690 return CMD_SUCCESS;
8691 }
8692
8693 DEFUN_NOSH (exit_address_family,
8694 exit_address_family_cmd,
8695 "exit-address-family",
8696 "Exit from Address Family configuration mode\n")
8697 {
8698 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
8699 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
8700 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
8701 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
8702 || vty->node == BGP_EVPN_NODE
8703 || vty->node == BGP_FLOWSPECV4_NODE
8704 || vty->node == BGP_FLOWSPECV6_NODE)
8705 vty->node = BGP_NODE;
8706 return CMD_SUCCESS;
8707 }
8708
8709 /* Recalculate bestpath and re-advertise a prefix */
8710 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
8711 const char *ip_str, afi_t afi, safi_t safi,
8712 struct prefix_rd *prd)
8713 {
8714 int ret;
8715 struct prefix match;
8716 struct bgp_dest *dest;
8717 struct bgp_dest *rm;
8718 struct bgp *bgp;
8719 struct bgp_table *table;
8720 struct bgp_table *rib;
8721
8722 /* BGP structure lookup. */
8723 if (view_name) {
8724 bgp = bgp_lookup_by_name(view_name);
8725 if (bgp == NULL) {
8726 vty_out(vty, "%% Can't find BGP instance %s\n",
8727 view_name);
8728 return CMD_WARNING;
8729 }
8730 } else {
8731 bgp = bgp_get_default();
8732 if (bgp == NULL) {
8733 vty_out(vty, "%% No BGP process is configured\n");
8734 return CMD_WARNING;
8735 }
8736 }
8737
8738 /* Check IP address argument. */
8739 ret = str2prefix(ip_str, &match);
8740 if (!ret) {
8741 vty_out(vty, "%% address is malformed\n");
8742 return CMD_WARNING;
8743 }
8744
8745 match.family = afi2family(afi);
8746 rib = bgp->rib[afi][safi];
8747
8748 if (safi == SAFI_MPLS_VPN) {
8749 for (dest = bgp_table_top(rib); dest;
8750 dest = bgp_route_next(dest)) {
8751 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
8752
8753 if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
8754 continue;
8755
8756 table = bgp_dest_get_bgp_table_info(dest);
8757 if (table == NULL)
8758 continue;
8759
8760 if ((rm = bgp_node_match(table, &match)) != NULL) {
8761 const struct prefix *rm_p =
8762 bgp_dest_get_prefix(rm);
8763
8764 if (rm_p->prefixlen == match.prefixlen) {
8765 SET_FLAG(rm->flags,
8766 BGP_NODE_USER_CLEAR);
8767 bgp_process(bgp, rm, afi, safi);
8768 }
8769 bgp_dest_unlock_node(rm);
8770 }
8771 }
8772 } else {
8773 if ((dest = bgp_node_match(rib, &match)) != NULL) {
8774 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
8775
8776 if (dest_p->prefixlen == match.prefixlen) {
8777 SET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
8778 bgp_process(bgp, dest, afi, safi);
8779 }
8780 bgp_dest_unlock_node(dest);
8781 }
8782 }
8783
8784 return CMD_SUCCESS;
8785 }
8786
8787 /* one clear bgp command to rule them all */
8788 DEFUN (clear_ip_bgp_all,
8789 clear_ip_bgp_all_cmd,
8790 "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>]",
8791 CLEAR_STR
8792 IP_STR
8793 BGP_STR
8794 BGP_INSTANCE_HELP_STR
8795 BGP_AFI_HELP_STR
8796 "Address Family\n"
8797 BGP_SAFI_WITH_LABEL_HELP_STR
8798 "Address Family modifier\n"
8799 "Clear all peers\n"
8800 "BGP IPv4 neighbor to clear\n"
8801 "BGP IPv6 neighbor to clear\n"
8802 "BGP neighbor on interface to clear\n"
8803 "Clear peers with the AS number\n"
8804 "Clear all external peers\n"
8805 "Clear all members of peer-group\n"
8806 "BGP peer-group name\n"
8807 BGP_SOFT_STR
8808 BGP_SOFT_IN_STR
8809 BGP_SOFT_OUT_STR
8810 BGP_SOFT_IN_STR
8811 "Push out prefix-list ORF and do inbound soft reconfig\n"
8812 BGP_SOFT_OUT_STR)
8813 {
8814 char *vrf = NULL;
8815
8816 afi_t afi = AFI_UNSPEC;
8817 safi_t safi = SAFI_UNSPEC;
8818 enum clear_sort clr_sort = clear_peer;
8819 enum bgp_clear_type clr_type;
8820 char *clr_arg = NULL;
8821
8822 int idx = 0;
8823 char errmsg[BUFSIZ] = {'\0'};
8824 int ret;
8825
8826 /* clear [ip] bgp */
8827 if (argv_find(argv, argc, "ip", &idx))
8828 afi = AFI_IP;
8829
8830 /* [<vrf> VIEWVRFNAME] */
8831 if (argv_find(argv, argc, "vrf", &idx)) {
8832 vrf = argv[idx + 1]->arg;
8833 idx += 2;
8834 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
8835 vrf = NULL;
8836 } else if (argv_find(argv, argc, "view", &idx)) {
8837 /* [<view> VIEWVRFNAME] */
8838 vrf = argv[idx + 1]->arg;
8839 idx += 2;
8840 }
8841 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
8842 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
8843 argv_find_and_parse_safi(argv, argc, &idx, &safi);
8844
8845 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
8846 if (argv_find(argv, argc, "*", &idx)) {
8847 clr_sort = clear_all;
8848 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
8849 clr_sort = clear_peer;
8850 clr_arg = argv[idx]->arg;
8851 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
8852 clr_sort = clear_peer;
8853 clr_arg = argv[idx]->arg;
8854 } else if (argv_find(argv, argc, "peer-group", &idx)) {
8855 clr_sort = clear_group;
8856 idx++;
8857 clr_arg = argv[idx]->arg;
8858 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
8859 clr_sort = clear_peer;
8860 clr_arg = argv[idx]->arg;
8861 } else if (argv_find(argv, argc, "WORD", &idx)) {
8862 clr_sort = clear_peer;
8863 clr_arg = argv[idx]->arg;
8864 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
8865 clr_sort = clear_as;
8866 clr_arg = argv[idx]->arg;
8867 } else if (argv_find(argv, argc, "external", &idx)) {
8868 clr_sort = clear_external;
8869 }
8870
8871 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
8872 if (argv_find(argv, argc, "soft", &idx)) {
8873 if (argv_find(argv, argc, "in", &idx)
8874 || argv_find(argv, argc, "out", &idx))
8875 clr_type = strmatch(argv[idx]->text, "in")
8876 ? BGP_CLEAR_SOFT_IN
8877 : BGP_CLEAR_SOFT_OUT;
8878 else
8879 clr_type = BGP_CLEAR_SOFT_BOTH;
8880 } else if (argv_find(argv, argc, "in", &idx)) {
8881 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
8882 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
8883 : BGP_CLEAR_SOFT_IN;
8884 } else if (argv_find(argv, argc, "out", &idx)) {
8885 clr_type = BGP_CLEAR_SOFT_OUT;
8886 } else
8887 clr_type = BGP_CLEAR_SOFT_NONE;
8888
8889 ret = bgp_clear_vty(vrf, afi, safi, clr_sort, clr_type, clr_arg, errmsg,
8890 sizeof(errmsg));
8891 if (ret != NB_OK)
8892 vty_out(vty, "Error description: %s\n", errmsg);
8893
8894 return ret;
8895 }
8896
8897 DEFUN (clear_ip_bgp_prefix,
8898 clear_ip_bgp_prefix_cmd,
8899 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
8900 CLEAR_STR
8901 IP_STR
8902 BGP_STR
8903 BGP_INSTANCE_HELP_STR
8904 "Clear bestpath and re-advertise\n"
8905 "IPv4 prefix\n")
8906 {
8907 char *vrf = NULL;
8908 char *prefix = NULL;
8909
8910 int idx = 0;
8911
8912 /* [<view|vrf> VIEWVRFNAME] */
8913 if (argv_find(argv, argc, "vrf", &idx)) {
8914 vrf = argv[idx + 1]->arg;
8915 idx += 2;
8916 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
8917 vrf = NULL;
8918 } else if (argv_find(argv, argc, "view", &idx)) {
8919 /* [<view> VIEWVRFNAME] */
8920 vrf = argv[idx + 1]->arg;
8921 idx += 2;
8922 }
8923
8924 prefix = argv[argc - 1]->arg;
8925
8926 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
8927 }
8928
8929 DEFUN (clear_bgp_ipv6_safi_prefix,
8930 clear_bgp_ipv6_safi_prefix_cmd,
8931 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
8932 CLEAR_STR
8933 IP_STR
8934 BGP_STR
8935 "Address Family\n"
8936 BGP_SAFI_HELP_STR
8937 "Clear bestpath and re-advertise\n"
8938 "IPv6 prefix\n")
8939 {
8940 int idx_safi = 0;
8941 int idx_ipv6_prefix = 0;
8942 safi_t safi = SAFI_UNICAST;
8943 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
8944 argv[idx_ipv6_prefix]->arg : NULL;
8945
8946 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
8947 return bgp_clear_prefix(
8948 vty, NULL, prefix, AFI_IP6,
8949 safi, NULL);
8950 }
8951
8952 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
8953 clear_bgp_instance_ipv6_safi_prefix_cmd,
8954 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
8955 CLEAR_STR
8956 IP_STR
8957 BGP_STR
8958 BGP_INSTANCE_HELP_STR
8959 "Address Family\n"
8960 BGP_SAFI_HELP_STR
8961 "Clear bestpath and re-advertise\n"
8962 "IPv6 prefix\n")
8963 {
8964 int idx_safi = 0;
8965 int idx_vrfview = 0;
8966 int idx_ipv6_prefix = 0;
8967 safi_t safi = SAFI_UNICAST;
8968 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
8969 argv[idx_ipv6_prefix]->arg : NULL;
8970 char *vrfview = NULL;
8971
8972 /* [<view|vrf> VIEWVRFNAME] */
8973 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
8974 vrfview = argv[idx_vrfview + 1]->arg;
8975 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
8976 vrfview = NULL;
8977 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
8978 /* [<view> VIEWVRFNAME] */
8979 vrfview = argv[idx_vrfview + 1]->arg;
8980 }
8981 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
8982
8983 return bgp_clear_prefix(
8984 vty, vrfview, prefix,
8985 AFI_IP6, safi, NULL);
8986 }
8987
8988 DEFUN (show_bgp_views,
8989 show_bgp_views_cmd,
8990 "show [ip] bgp views",
8991 SHOW_STR
8992 IP_STR
8993 BGP_STR
8994 "Show the defined BGP views\n")
8995 {
8996 struct list *inst = bm->bgp;
8997 struct listnode *node;
8998 struct bgp *bgp;
8999
9000 vty_out(vty, "Defined BGP views:\n");
9001 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
9002 /* Skip VRFs. */
9003 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
9004 continue;
9005 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
9006 bgp->as);
9007 }
9008
9009 return CMD_SUCCESS;
9010 }
9011
9012 DEFUN (show_bgp_vrfs,
9013 show_bgp_vrfs_cmd,
9014 "show [ip] bgp vrfs [json]",
9015 SHOW_STR
9016 IP_STR
9017 BGP_STR
9018 "Show BGP VRFs\n"
9019 JSON_STR)
9020 {
9021 char buf[ETHER_ADDR_STRLEN];
9022 struct list *inst = bm->bgp;
9023 struct listnode *node;
9024 struct bgp *bgp;
9025 bool uj = use_json(argc, argv);
9026 json_object *json = NULL;
9027 json_object *json_vrfs = NULL;
9028 int count = 0;
9029
9030 if (uj) {
9031 json = json_object_new_object();
9032 json_vrfs = json_object_new_object();
9033 }
9034
9035 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
9036 const char *name, *type;
9037 struct peer *peer;
9038 struct listnode *node2, *nnode2;
9039 int peers_cfg, peers_estb;
9040 json_object *json_vrf = NULL;
9041
9042 /* Skip Views. */
9043 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
9044 continue;
9045
9046 count++;
9047 if (!uj && count == 1) {
9048 vty_out(vty,
9049 "%4s %-5s %-16s %9s %10s %-37s\n",
9050 "Type", "Id", "routerId", "#PeersCfg",
9051 "#PeersEstb", "Name");
9052 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
9053 "L3-VNI", "RouterMAC", "Interface");
9054 }
9055
9056 peers_cfg = peers_estb = 0;
9057 if (uj)
9058 json_vrf = json_object_new_object();
9059
9060
9061 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
9062 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
9063 continue;
9064 peers_cfg++;
9065 if (peer->status == Established)
9066 peers_estb++;
9067 }
9068
9069 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
9070 name = VRF_DEFAULT_NAME;
9071 type = "DFLT";
9072 } else {
9073 name = bgp->name;
9074 type = "VRF";
9075 }
9076
9077
9078 if (uj) {
9079 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
9080 ? -1
9081 : (int64_t)bgp->vrf_id;
9082 json_object_string_add(json_vrf, "type", type);
9083 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
9084 json_object_string_add(json_vrf, "routerId",
9085 inet_ntoa(bgp->router_id));
9086 json_object_int_add(json_vrf, "numConfiguredPeers",
9087 peers_cfg);
9088 json_object_int_add(json_vrf, "numEstablishedPeers",
9089 peers_estb);
9090
9091 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
9092 json_object_string_add(
9093 json_vrf, "rmac",
9094 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
9095 json_object_string_add(json_vrf, "interface",
9096 ifindex2ifname(bgp->l3vni_svi_ifindex,
9097 bgp->vrf_id));
9098 json_object_object_add(json_vrfs, name, json_vrf);
9099 } else {
9100 vty_out(vty,
9101 "%4s %-5d %-16s %-9u %-10u %-37s\n",
9102 type,
9103 bgp->vrf_id == VRF_UNKNOWN ? -1
9104 : (int)bgp->vrf_id,
9105 inet_ntoa(bgp->router_id), peers_cfg,
9106 peers_estb, name);
9107 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
9108 bgp->l3vni,
9109 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
9110 ifindex2ifname(bgp->l3vni_svi_ifindex,
9111 bgp->vrf_id));
9112 }
9113 }
9114
9115 if (uj) {
9116 json_object_object_add(json, "vrfs", json_vrfs);
9117
9118 json_object_int_add(json, "totalVrfs", count);
9119
9120 vty_out(vty, "%s\n", json_object_to_json_string_ext(
9121 json, JSON_C_TO_STRING_PRETTY));
9122 json_object_free(json);
9123 } else {
9124 if (count)
9125 vty_out(vty,
9126 "\nTotal number of VRFs (including default): %d\n",
9127 count);
9128 }
9129
9130 return CMD_SUCCESS;
9131 }
9132
9133 DEFUN (show_bgp_mac_hash,
9134 show_bgp_mac_hash_cmd,
9135 "show bgp mac hash",
9136 SHOW_STR
9137 BGP_STR
9138 "Mac Address\n"
9139 "Mac Address database\n")
9140 {
9141 bgp_mac_dump_table(vty);
9142
9143 return CMD_SUCCESS;
9144 }
9145
9146 static void show_tip_entry(struct hash_bucket *bucket, void *args)
9147 {
9148 struct vty *vty = (struct vty *)args;
9149 struct tip_addr *tip = (struct tip_addr *)bucket->data;
9150
9151 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(tip->addr),
9152 tip->refcnt);
9153 }
9154
9155 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
9156 {
9157 vty_out(vty, "self nexthop database:\n");
9158 bgp_nexthop_show_address_hash(vty, bgp);
9159
9160 vty_out(vty, "Tunnel-ip database:\n");
9161 hash_iterate(bgp->tip_hash,
9162 (void (*)(struct hash_bucket *, void *))show_tip_entry,
9163 vty);
9164 }
9165
9166 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
9167 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
9168 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
9169 "martian next-hops\n"
9170 "martian next-hop database\n")
9171 {
9172 struct bgp *bgp = NULL;
9173 int idx = 0;
9174 char *name = NULL;
9175
9176 /* [<vrf> VIEWVRFNAME] */
9177 if (argv_find(argv, argc, "vrf", &idx)) {
9178 name = argv[idx + 1]->arg;
9179 if (name && strmatch(name, VRF_DEFAULT_NAME))
9180 name = NULL;
9181 } else if (argv_find(argv, argc, "view", &idx))
9182 /* [<view> VIEWVRFNAME] */
9183 name = argv[idx + 1]->arg;
9184 if (name)
9185 bgp = bgp_lookup_by_name(name);
9186 else
9187 bgp = bgp_get_default();
9188
9189 if (!bgp) {
9190 vty_out(vty, "%% No BGP process is configured\n");
9191 return CMD_WARNING;
9192 }
9193 bgp_show_martian_nexthops(vty, bgp);
9194
9195 return CMD_SUCCESS;
9196 }
9197
9198 DEFUN (show_bgp_memory,
9199 show_bgp_memory_cmd,
9200 "show [ip] bgp memory",
9201 SHOW_STR
9202 IP_STR
9203 BGP_STR
9204 "Global BGP memory statistics\n")
9205 {
9206 char memstrbuf[MTYPE_MEMSTR_LEN];
9207 unsigned long count;
9208
9209 /* RIB related usage stats */
9210 count = mtype_stats_alloc(MTYPE_BGP_NODE);
9211 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
9212 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9213 count * sizeof(struct bgp_dest)));
9214
9215 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
9216 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
9217 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9218 count * sizeof(struct bgp_path_info)));
9219 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
9220 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
9221 count,
9222 mtype_memstr(
9223 memstrbuf, sizeof(memstrbuf),
9224 count * sizeof(struct bgp_path_info_extra)));
9225
9226 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
9227 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
9228 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9229 count * sizeof(struct bgp_static)));
9230
9231 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
9232 vty_out(vty, "%ld Packets, using %s of memory\n", count,
9233 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9234 count * sizeof(struct bpacket)));
9235
9236 /* Adj-In/Out */
9237 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
9238 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
9239 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9240 count * sizeof(struct bgp_adj_in)));
9241 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
9242 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
9243 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9244 count * sizeof(struct bgp_adj_out)));
9245
9246 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
9247 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
9248 count,
9249 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9250 count * sizeof(struct bgp_nexthop_cache)));
9251
9252 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
9253 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
9254 count,
9255 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9256 count * sizeof(struct bgp_damp_info)));
9257
9258 /* Attributes */
9259 count = attr_count();
9260 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
9261 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9262 count * sizeof(struct attr)));
9263
9264 if ((count = attr_unknown_count()))
9265 vty_out(vty, "%ld unknown attributes\n", count);
9266
9267 /* AS_PATH attributes */
9268 count = aspath_count();
9269 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
9270 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9271 count * sizeof(struct aspath)));
9272
9273 count = mtype_stats_alloc(MTYPE_AS_SEG);
9274 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
9275 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9276 count * sizeof(struct assegment)));
9277
9278 /* Other attributes */
9279 if ((count = community_count()))
9280 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
9281 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
9282 count * sizeof(struct community)));
9283 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
9284 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
9285 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
9286 count * sizeof(struct ecommunity)));
9287 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
9288 vty_out(vty,
9289 "%ld BGP large-community entries, using %s of memory\n",
9290 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
9291 count * sizeof(struct lcommunity)));
9292
9293 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
9294 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
9295 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9296 count * sizeof(struct cluster_list)));
9297
9298 /* Peer related usage */
9299 count = mtype_stats_alloc(MTYPE_BGP_PEER);
9300 vty_out(vty, "%ld peers, using %s of memory\n", count,
9301 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9302 count * sizeof(struct peer)));
9303
9304 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
9305 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
9306 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9307 count * sizeof(struct peer_group)));
9308
9309 /* Other */
9310 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
9311 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
9312 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
9313 count * sizeof(regex_t)));
9314 return CMD_SUCCESS;
9315 }
9316
9317 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
9318 {
9319 json_object *bestpath = json_object_new_object();
9320
9321 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
9322 json_object_string_add(bestpath, "asPath", "ignore");
9323
9324 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
9325 json_object_string_add(bestpath, "asPath", "confed");
9326
9327 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
9328 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
9329 json_object_string_add(bestpath, "multiPathRelax",
9330 "as-set");
9331 else
9332 json_object_string_add(bestpath, "multiPathRelax",
9333 "true");
9334 } else
9335 json_object_string_add(bestpath, "multiPathRelax", "false");
9336
9337 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
9338 json_object_string_add(bestpath, "compareRouterId", "true");
9339 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
9340 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
9341 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
9342 json_object_string_add(bestpath, "med", "confed");
9343 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
9344 json_object_string_add(bestpath, "med",
9345 "missing-as-worst");
9346 else
9347 json_object_string_add(bestpath, "med", "true");
9348 }
9349
9350 json_object_object_add(json, "bestPath", bestpath);
9351 }
9352
9353 /* Print the error code/subcode for why the peer is down */
9354 static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
9355 json_object *json_peer, bool use_json)
9356 {
9357 const char *code_str;
9358 const char *subcode_str;
9359
9360 if (use_json) {
9361 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
9362 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
9363 char errorcodesubcode_hexstr[5];
9364 char errorcodesubcode_str[256];
9365
9366 code_str = bgp_notify_code_str(peer->notify.code);
9367 subcode_str = bgp_notify_subcode_str(
9368 peer->notify.code,
9369 peer->notify.subcode);
9370
9371 snprintf(errorcodesubcode_hexstr,
9372 sizeof(errorcodesubcode_hexstr), "%02X%02X",
9373 peer->notify.code, peer->notify.subcode);
9374 json_object_string_add(json_peer,
9375 "lastErrorCodeSubcode",
9376 errorcodesubcode_hexstr);
9377 snprintf(errorcodesubcode_str, 255, "%s%s",
9378 code_str, subcode_str);
9379 json_object_string_add(json_peer,
9380 "lastNotificationReason",
9381 errorcodesubcode_str);
9382 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
9383 && peer->notify.code == BGP_NOTIFY_CEASE
9384 && (peer->notify.subcode
9385 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
9386 || peer->notify.subcode
9387 == BGP_NOTIFY_CEASE_ADMIN_RESET)
9388 && peer->notify.length) {
9389 char msgbuf[1024];
9390 const char *msg_str;
9391
9392 msg_str = bgp_notify_admin_message(
9393 msgbuf, sizeof(msgbuf),
9394 (uint8_t *)peer->notify.data,
9395 peer->notify.length);
9396 if (msg_str)
9397 json_object_string_add(
9398 json_peer,
9399 "lastShutdownDescription",
9400 msg_str);
9401 }
9402
9403 }
9404 json_object_string_add(json_peer, "lastResetDueTo",
9405 peer_down_str[(int)peer->last_reset]);
9406 json_object_int_add(json_peer, "lastResetCode",
9407 peer->last_reset);
9408 } else {
9409 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
9410 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
9411 code_str = bgp_notify_code_str(peer->notify.code);
9412 subcode_str =
9413 bgp_notify_subcode_str(peer->notify.code,
9414 peer->notify.subcode);
9415 vty_out(vty, " Notification %s (%s%s)\n",
9416 peer->last_reset == PEER_DOWN_NOTIFY_SEND
9417 ? "sent"
9418 : "received",
9419 code_str, subcode_str);
9420 } else {
9421 vty_out(vty, " %s\n",
9422 peer_down_str[(int)peer->last_reset]);
9423 }
9424 }
9425 }
9426
9427 static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
9428 safi_t safi)
9429 {
9430 return ((peer->status != Established) ||
9431 !peer->afc_recv[afi][safi]);
9432 }
9433
9434 static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
9435 struct peer *peer, json_object *json_peer,
9436 int max_neighbor_width, bool use_json)
9437 {
9438 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
9439 int len;
9440
9441 if (use_json) {
9442 if (peer_dynamic_neighbor(peer))
9443 json_object_boolean_true_add(json_peer,
9444 "dynamicPeer");
9445 if (peer->hostname)
9446 json_object_string_add(json_peer, "hostname",
9447 peer->hostname);
9448
9449 if (peer->domainname)
9450 json_object_string_add(json_peer, "domainname",
9451 peer->domainname);
9452 json_object_int_add(json_peer, "connectionsEstablished",
9453 peer->established);
9454 json_object_int_add(json_peer, "connectionsDropped",
9455 peer->dropped);
9456 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
9457 use_json, json_peer);
9458 if (peer->status == Established)
9459 json_object_string_add(json_peer, "lastResetDueTo",
9460 "AFI/SAFI Not Negotiated");
9461 else
9462 bgp_show_peer_reset(NULL, peer, json_peer, true);
9463 } else {
9464 dn_flag[1] = '\0';
9465 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
9466 if (peer->hostname
9467 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
9468 len = vty_out(vty, "%s%s(%s)", dn_flag,
9469 peer->hostname, peer->host);
9470 else
9471 len = vty_out(vty, "%s%s", dn_flag, peer->host);
9472
9473 /* pad the neighbor column with spaces */
9474 if (len < max_neighbor_width)
9475 vty_out(vty, "%*s", max_neighbor_width - len,
9476 " ");
9477 vty_out(vty, "%7d %7d %9s", peer->established,
9478 peer->dropped,
9479 peer_uptime(peer->uptime, timebuf,
9480 BGP_UPTIME_LEN, 0, NULL));
9481 if (peer->status == Established)
9482 vty_out(vty, " AFI/SAFI Not Negotiated\n");
9483 else
9484 bgp_show_peer_reset(vty, peer, NULL,
9485 false);
9486 }
9487 }
9488
9489
9490 /* Show BGP peer's summary information. */
9491 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
9492 bool show_failed, bool show_established,
9493 bool use_json)
9494 {
9495 struct peer *peer;
9496 struct listnode *node, *nnode;
9497 unsigned int count = 0, dn_count = 0;
9498 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
9499 char neighbor_buf[VTY_BUFSIZ];
9500 int neighbor_col_default_width = 16;
9501 int len, failed_count = 0;
9502 int max_neighbor_width = 0;
9503 int pfx_rcd_safi;
9504 json_object *json = NULL;
9505 json_object *json_peer = NULL;
9506 json_object *json_peers = NULL;
9507 struct peer_af *paf;
9508 struct bgp_filter *filter;
9509
9510 /* labeled-unicast routes are installed in the unicast table so in order
9511 * to
9512 * display the correct PfxRcd value we must look at SAFI_UNICAST
9513 */
9514
9515 if (safi == SAFI_LABELED_UNICAST)
9516 pfx_rcd_safi = SAFI_UNICAST;
9517 else
9518 pfx_rcd_safi = safi;
9519
9520 if (use_json) {
9521 json = json_object_new_object();
9522 json_peers = json_object_new_object();
9523 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
9524 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
9525 continue;
9526
9527 if (peer->afc[afi][safi]) {
9528 /* See if we have at least a single failed peer */
9529 if (bgp_has_peer_failed(peer, afi, safi))
9530 failed_count++;
9531 count++;
9532 }
9533 if (peer_dynamic_neighbor(peer))
9534 dn_count++;
9535 }
9536
9537 } else {
9538 /* Loop over all neighbors that will be displayed to determine
9539 * how many
9540 * characters are needed for the Neighbor column
9541 */
9542 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
9543 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
9544 continue;
9545
9546 if (peer->afc[afi][safi]) {
9547 memset(dn_flag, '\0', sizeof(dn_flag));
9548 if (peer_dynamic_neighbor(peer))
9549 dn_flag[0] = '*';
9550
9551 if (peer->hostname
9552 && CHECK_FLAG(bgp->flags,
9553 BGP_FLAG_SHOW_HOSTNAME))
9554 snprintf(neighbor_buf,
9555 sizeof(neighbor_buf),
9556 "%s%s(%s) ", dn_flag,
9557 peer->hostname, peer->host);
9558 else
9559 snprintf(neighbor_buf,
9560 sizeof(neighbor_buf), "%s%s ",
9561 dn_flag, peer->host);
9562
9563 len = strlen(neighbor_buf);
9564
9565 if (len > max_neighbor_width)
9566 max_neighbor_width = len;
9567
9568 /* See if we have at least a single failed peer */
9569 if (bgp_has_peer_failed(peer, afi, safi))
9570 failed_count++;
9571 count++;
9572 }
9573 }
9574
9575 /* Originally we displayed the Neighbor column as 16
9576 * characters wide so make that the default
9577 */
9578 if (max_neighbor_width < neighbor_col_default_width)
9579 max_neighbor_width = neighbor_col_default_width;
9580 }
9581
9582 if (show_failed && !failed_count) {
9583 if (use_json) {
9584 json_object_int_add(json, "failedPeersCount", 0);
9585 json_object_int_add(json, "dynamicPeers", dn_count);
9586 json_object_int_add(json, "totalPeers", count);
9587
9588 vty_out(vty, "%s\n", json_object_to_json_string_ext(
9589 json, JSON_C_TO_STRING_PRETTY));
9590 json_object_free(json);
9591 } else {
9592 vty_out(vty, "%% No failed BGP neighbors found\n");
9593 vty_out(vty, "\nTotal number of neighbors %d\n", count);
9594 }
9595 return CMD_SUCCESS;
9596 }
9597
9598 count = 0; /* Reset the value as its used again */
9599 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
9600 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
9601 continue;
9602
9603 if (!peer->afc[afi][safi])
9604 continue;
9605
9606 if (!count) {
9607 unsigned long ents;
9608 char memstrbuf[MTYPE_MEMSTR_LEN];
9609 int64_t vrf_id_ui;
9610
9611 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
9612 ? -1
9613 : (int64_t)bgp->vrf_id;
9614
9615 /* Usage summary and header */
9616 if (use_json) {
9617 json_object_string_add(
9618 json, "routerId",
9619 inet_ntoa(bgp->router_id));
9620 json_object_int_add(json, "as", bgp->as);
9621 json_object_int_add(json, "vrfId", vrf_id_ui);
9622 json_object_string_add(
9623 json, "vrfName",
9624 (bgp->inst_type
9625 == BGP_INSTANCE_TYPE_DEFAULT)
9626 ? VRF_DEFAULT_NAME
9627 : bgp->name);
9628 } else {
9629 vty_out(vty,
9630 "BGP router identifier %s, local AS number %u vrf-id %d",
9631 inet_ntoa(bgp->router_id), bgp->as,
9632 bgp->vrf_id == VRF_UNKNOWN
9633 ? -1
9634 : (int)bgp->vrf_id);
9635 vty_out(vty, "\n");
9636 }
9637
9638 if (bgp_update_delay_configured(bgp)) {
9639 if (use_json) {
9640 json_object_int_add(
9641 json, "updateDelayLimit",
9642 bgp->v_update_delay);
9643
9644 if (bgp->v_update_delay
9645 != bgp->v_establish_wait)
9646 json_object_int_add(
9647 json,
9648 "updateDelayEstablishWait",
9649 bgp->v_establish_wait);
9650
9651 if (bgp_update_delay_active(bgp)) {
9652 json_object_string_add(
9653 json,
9654 "updateDelayFirstNeighbor",
9655 bgp->update_delay_begin_time);
9656 json_object_boolean_true_add(
9657 json,
9658 "updateDelayInProgress");
9659 } else {
9660 if (bgp->update_delay_over) {
9661 json_object_string_add(
9662 json,
9663 "updateDelayFirstNeighbor",
9664 bgp->update_delay_begin_time);
9665 json_object_string_add(
9666 json,
9667 "updateDelayBestpathResumed",
9668 bgp->update_delay_end_time);
9669 json_object_string_add(
9670 json,
9671 "updateDelayZebraUpdateResume",
9672 bgp->update_delay_zebra_resume_time);
9673 json_object_string_add(
9674 json,
9675 "updateDelayPeerUpdateResume",
9676 bgp->update_delay_peers_resume_time);
9677 }
9678 }
9679 } else {
9680 vty_out(vty,
9681 "Read-only mode update-delay limit: %d seconds\n",
9682 bgp->v_update_delay);
9683 if (bgp->v_update_delay
9684 != bgp->v_establish_wait)
9685 vty_out(vty,
9686 " Establish wait: %d seconds\n",
9687 bgp->v_establish_wait);
9688
9689 if (bgp_update_delay_active(bgp)) {
9690 vty_out(vty,
9691 " First neighbor established: %s\n",
9692 bgp->update_delay_begin_time);
9693 vty_out(vty,
9694 " Delay in progress\n");
9695 } else {
9696 if (bgp->update_delay_over) {
9697 vty_out(vty,
9698 " First neighbor established: %s\n",
9699 bgp->update_delay_begin_time);
9700 vty_out(vty,
9701 " Best-paths resumed: %s\n",
9702 bgp->update_delay_end_time);
9703 vty_out(vty,
9704 " zebra update resumed: %s\n",
9705 bgp->update_delay_zebra_resume_time);
9706 vty_out(vty,
9707 " peers update resumed: %s\n",
9708 bgp->update_delay_peers_resume_time);
9709 }
9710 }
9711 }
9712 }
9713
9714 if (use_json) {
9715 if (bgp_maxmed_onstartup_configured(bgp)
9716 && bgp->maxmed_active)
9717 json_object_boolean_true_add(
9718 json, "maxMedOnStartup");
9719 if (bgp->v_maxmed_admin)
9720 json_object_boolean_true_add(
9721 json, "maxMedAdministrative");
9722
9723 json_object_int_add(
9724 json, "tableVersion",
9725 bgp_table_version(bgp->rib[afi][safi]));
9726
9727 ents = bgp_table_count(bgp->rib[afi][safi]);
9728 json_object_int_add(json, "ribCount", ents);
9729 json_object_int_add(
9730 json, "ribMemory",
9731 ents * sizeof(struct bgp_dest));
9732
9733 ents = bgp->af_peer_count[afi][safi];
9734 json_object_int_add(json, "peerCount", ents);
9735 json_object_int_add(json, "peerMemory",
9736 ents * sizeof(struct peer));
9737
9738 if ((ents = listcount(bgp->group))) {
9739 json_object_int_add(
9740 json, "peerGroupCount", ents);
9741 json_object_int_add(
9742 json, "peerGroupMemory",
9743 ents * sizeof(struct
9744 peer_group));
9745 }
9746
9747 if (CHECK_FLAG(bgp->af_flags[afi][safi],
9748 BGP_CONFIG_DAMPENING))
9749 json_object_boolean_true_add(
9750 json, "dampeningEnabled");
9751 } else {
9752 if (bgp_maxmed_onstartup_configured(bgp)
9753 && bgp->maxmed_active)
9754 vty_out(vty,
9755 "Max-med on-startup active\n");
9756 if (bgp->v_maxmed_admin)
9757 vty_out(vty,
9758 "Max-med administrative active\n");
9759
9760 vty_out(vty, "BGP table version %" PRIu64 "\n",
9761 bgp_table_version(bgp->rib[afi][safi]));
9762
9763 ents = bgp_table_count(bgp->rib[afi][safi]);
9764 vty_out(vty,
9765 "RIB entries %ld, using %s of memory\n",
9766 ents,
9767 mtype_memstr(
9768 memstrbuf, sizeof(memstrbuf),
9769 ents
9770 * sizeof(struct
9771 bgp_dest)));
9772
9773 /* Peer related usage */
9774 ents = bgp->af_peer_count[afi][safi];
9775 vty_out(vty, "Peers %ld, using %s of memory\n",
9776 ents,
9777 mtype_memstr(
9778 memstrbuf, sizeof(memstrbuf),
9779 ents * sizeof(struct peer)));
9780
9781 if ((ents = listcount(bgp->group)))
9782 vty_out(vty,
9783 "Peer groups %ld, using %s of memory\n",
9784 ents,
9785 mtype_memstr(
9786 memstrbuf,
9787 sizeof(memstrbuf),
9788 ents * sizeof(struct
9789 peer_group)));
9790
9791 if (CHECK_FLAG(bgp->af_flags[afi][safi],
9792 BGP_CONFIG_DAMPENING))
9793 vty_out(vty, "Dampening enabled.\n");
9794 vty_out(vty, "\n");
9795
9796 /* Subtract 8 here because 'Neighbor' is
9797 * 8 characters */
9798 vty_out(vty, "Neighbor");
9799 vty_out(vty, "%*s", max_neighbor_width - 8,
9800 " ");
9801 if (show_failed)
9802 vty_out(vty, "EstdCnt DropCnt ResetTime Reason\n");
9803 else
9804 vty_out(vty,
9805 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd PfxSnt\n");
9806 }
9807 }
9808
9809 paf = peer_af_find(peer, afi, safi);
9810 filter = &peer->filter[afi][safi];
9811
9812 count++;
9813 /* Works for both failed & successful cases */
9814 if (peer_dynamic_neighbor(peer))
9815 dn_count++;
9816
9817 if (use_json) {
9818 json_peer = NULL;
9819
9820 if (show_failed &&
9821 bgp_has_peer_failed(peer, afi, safi)) {
9822 json_peer = json_object_new_object();
9823 bgp_show_failed_summary(vty, bgp, peer,
9824 json_peer, 0, use_json);
9825 } else if (!show_failed) {
9826 if (show_established
9827 && bgp_has_peer_failed(peer, afi, safi))
9828 continue;
9829
9830 json_peer = json_object_new_object();
9831 if (peer_dynamic_neighbor(peer)) {
9832 json_object_boolean_true_add(json_peer,
9833 "dynamicPeer");
9834 }
9835
9836 if (peer->hostname)
9837 json_object_string_add(json_peer, "hostname",
9838 peer->hostname);
9839
9840 if (peer->domainname)
9841 json_object_string_add(json_peer, "domainname",
9842 peer->domainname);
9843
9844 json_object_int_add(json_peer, "remoteAs", peer->as);
9845 json_object_int_add(json_peer, "version", 4);
9846 json_object_int_add(json_peer, "msgRcvd",
9847 PEER_TOTAL_RX(peer));
9848 json_object_int_add(json_peer, "msgSent",
9849 PEER_TOTAL_TX(peer));
9850
9851 atomic_size_t outq_count, inq_count;
9852 outq_count = atomic_load_explicit(
9853 &peer->obuf->count,
9854 memory_order_relaxed);
9855 inq_count = atomic_load_explicit(
9856 &peer->ibuf->count,
9857 memory_order_relaxed);
9858
9859 json_object_int_add(json_peer, "tableVersion",
9860 peer->version[afi][safi]);
9861 json_object_int_add(json_peer, "outq",
9862 outq_count);
9863 json_object_int_add(json_peer, "inq",
9864 inq_count);
9865 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
9866 use_json, json_peer);
9867
9868 json_object_int_add(json_peer, "pfxRcd",
9869 peer->pcount[afi][pfx_rcd_safi]);
9870
9871 if (paf && PAF_SUBGRP(paf))
9872 json_object_int_add(json_peer,
9873 "pfxSnt",
9874 (PAF_SUBGRP(paf))->scount);
9875 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
9876 || CHECK_FLAG(peer->bgp->flags,
9877 BGP_FLAG_SHUTDOWN))
9878 json_object_string_add(json_peer, "state",
9879 "Idle (Admin)");
9880 else if (peer->afc_recv[afi][safi])
9881 json_object_string_add(
9882 json_peer, "state",
9883 lookup_msg(bgp_status_msg, peer->status,
9884 NULL));
9885 else if (CHECK_FLAG(peer->sflags,
9886 PEER_STATUS_PREFIX_OVERFLOW))
9887 json_object_string_add(json_peer, "state",
9888 "Idle (PfxCt)");
9889 else
9890 json_object_string_add(
9891 json_peer, "state",
9892 lookup_msg(bgp_status_msg, peer->status,
9893 NULL));
9894 json_object_int_add(json_peer, "connectionsEstablished",
9895 peer->established);
9896 json_object_int_add(json_peer, "connectionsDropped",
9897 peer->dropped);
9898 }
9899 /* Avoid creating empty peer dicts in JSON */
9900 if (json_peer == NULL)
9901 continue;
9902
9903 if (peer->conf_if)
9904 json_object_string_add(json_peer, "idType",
9905 "interface");
9906 else if (peer->su.sa.sa_family == AF_INET)
9907 json_object_string_add(json_peer, "idType",
9908 "ipv4");
9909 else if (peer->su.sa.sa_family == AF_INET6)
9910 json_object_string_add(json_peer, "idType",
9911 "ipv6");
9912 json_object_object_add(json_peers, peer->host,
9913 json_peer);
9914 } else {
9915 if (show_failed &&
9916 bgp_has_peer_failed(peer, afi, safi)) {
9917 bgp_show_failed_summary(vty, bgp, peer, NULL,
9918 max_neighbor_width,
9919 use_json);
9920 } else if (!show_failed) {
9921 if (show_established
9922 && bgp_has_peer_failed(peer, afi, safi))
9923 continue;
9924
9925 memset(dn_flag, '\0', sizeof(dn_flag));
9926 if (peer_dynamic_neighbor(peer)) {
9927 dn_flag[0] = '*';
9928 }
9929
9930 if (peer->hostname
9931 && CHECK_FLAG(bgp->flags,
9932 BGP_FLAG_SHOW_HOSTNAME))
9933 len = vty_out(vty, "%s%s(%s)", dn_flag,
9934 peer->hostname,
9935 peer->host);
9936 else
9937 len = vty_out(vty, "%s%s", dn_flag, peer->host);
9938
9939 /* pad the neighbor column with spaces */
9940 if (len < max_neighbor_width)
9941 vty_out(vty, "%*s", max_neighbor_width - len,
9942 " ");
9943
9944 atomic_size_t outq_count, inq_count;
9945 outq_count = atomic_load_explicit(
9946 &peer->obuf->count,
9947 memory_order_relaxed);
9948 inq_count = atomic_load_explicit(
9949 &peer->ibuf->count,
9950 memory_order_relaxed);
9951
9952 vty_out(vty,
9953 "4 %10u %9u %9u %8" PRIu64" %4zu %4zu %8s",
9954 peer->as, PEER_TOTAL_RX(peer),
9955 PEER_TOTAL_TX(peer),
9956 peer->version[afi][safi], inq_count,
9957 outq_count,
9958 peer_uptime(peer->uptime, timebuf,
9959 BGP_UPTIME_LEN, 0, NULL));
9960
9961 if (peer->status == Established) {
9962 if (peer->afc_recv[afi][safi]) {
9963 if (CHECK_FLAG(
9964 bgp->flags,
9965 BGP_FLAG_EBGP_REQUIRES_POLICY)
9966 && !bgp_inbound_policy_exists(
9967 peer, filter))
9968 vty_out(vty, " %12s",
9969 "(Policy)");
9970 else
9971 vty_out(vty,
9972 " %12u",
9973 peer->pcount
9974 [afi]
9975 [pfx_rcd_safi]);
9976 } else {
9977 vty_out(vty, " NoNeg");
9978 }
9979
9980 if (paf && PAF_SUBGRP(paf)) {
9981 if (CHECK_FLAG(
9982 bgp->flags,
9983 BGP_FLAG_EBGP_REQUIRES_POLICY)
9984 && !bgp_outbound_policy_exists(
9985 peer, filter))
9986 vty_out(vty, " %8s",
9987 "(Policy)");
9988 else
9989 vty_out(vty,
9990 " %8u",
9991 (PAF_SUBGRP(
9992 paf))
9993 ->scount);
9994 }
9995 } else {
9996 if (CHECK_FLAG(peer->flags,
9997 PEER_FLAG_SHUTDOWN)
9998 || CHECK_FLAG(peer->bgp->flags,
9999 BGP_FLAG_SHUTDOWN))
10000 vty_out(vty, " Idle (Admin)");
10001 else if (CHECK_FLAG(
10002 peer->sflags,
10003 PEER_STATUS_PREFIX_OVERFLOW))
10004 vty_out(vty, " Idle (PfxCt)");
10005 else
10006 vty_out(vty, " %12s",
10007 lookup_msg(bgp_status_msg,
10008 peer->status, NULL));
10009
10010 vty_out(vty, " %8u", 0);
10011 }
10012 vty_out(vty, "\n");
10013 }
10014
10015 }
10016 }
10017
10018 if (use_json) {
10019 json_object_object_add(json, "peers", json_peers);
10020 json_object_int_add(json, "failedPeers", failed_count);
10021 json_object_int_add(json, "totalPeers", count);
10022 json_object_int_add(json, "dynamicPeers", dn_count);
10023
10024 if (!show_failed)
10025 bgp_show_bestpath_json(bgp, json);
10026
10027 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10028 json, JSON_C_TO_STRING_PRETTY));
10029 json_object_free(json);
10030 } else {
10031 if (count)
10032 vty_out(vty, "\nTotal number of neighbors %d\n", count);
10033 else {
10034 vty_out(vty, "No %s neighbor is configured\n",
10035 get_afi_safi_str(afi, safi, false));
10036 }
10037
10038 if (dn_count) {
10039 vty_out(vty, "* - dynamic neighbor\n");
10040 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
10041 dn_count, bgp->dynamic_neighbors_limit);
10042 }
10043 }
10044
10045 return CMD_SUCCESS;
10046 }
10047
10048 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
10049 int safi, bool show_failed,
10050 bool show_established, bool use_json)
10051 {
10052 int is_first = 1;
10053 int afi_wildcard = (afi == AFI_MAX);
10054 int safi_wildcard = (safi == SAFI_MAX);
10055 int is_wildcard = (afi_wildcard || safi_wildcard);
10056 bool nbr_output = false;
10057
10058 if (use_json && is_wildcard)
10059 vty_out(vty, "{\n");
10060 if (afi_wildcard)
10061 afi = 1; /* AFI_IP */
10062 while (afi < AFI_MAX) {
10063 if (safi_wildcard)
10064 safi = 1; /* SAFI_UNICAST */
10065 while (safi < SAFI_MAX) {
10066 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
10067 nbr_output = true;
10068
10069 if (is_wildcard) {
10070 /*
10071 * So limit output to those afi/safi
10072 * pairs that
10073 * actualy have something interesting in
10074 * them
10075 */
10076 if (use_json) {
10077 if (!is_first)
10078 vty_out(vty, ",\n");
10079 else
10080 is_first = 0;
10081
10082 vty_out(vty, "\"%s\":",
10083 get_afi_safi_str(afi,
10084 safi,
10085 true));
10086 } else {
10087 vty_out(vty, "\n%s Summary:\n",
10088 get_afi_safi_str(afi,
10089 safi,
10090 false));
10091 }
10092 }
10093 bgp_show_summary(vty, bgp, afi, safi,
10094 show_failed, show_established,
10095 use_json);
10096 }
10097 safi++;
10098 if (!safi_wildcard)
10099 safi = SAFI_MAX;
10100 }
10101 afi++;
10102 if (!afi_wildcard)
10103 afi = AFI_MAX;
10104 }
10105
10106 if (use_json && is_wildcard)
10107 vty_out(vty, "}\n");
10108 else if (!nbr_output) {
10109 if (use_json)
10110 vty_out(vty, "{}\n");
10111 else
10112 vty_out(vty, "%% No BGP neighbors found\n");
10113 }
10114 }
10115
10116 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
10117 safi_t safi, bool show_failed,
10118 bool show_established,
10119 bool use_json)
10120 {
10121 struct listnode *node, *nnode;
10122 struct bgp *bgp;
10123 int is_first = 1;
10124 bool nbr_output = false;
10125
10126 if (use_json)
10127 vty_out(vty, "{\n");
10128
10129 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
10130 nbr_output = true;
10131 if (use_json) {
10132 if (!is_first)
10133 vty_out(vty, ",\n");
10134 else
10135 is_first = 0;
10136
10137 vty_out(vty, "\"%s\":",
10138 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10139 ? VRF_DEFAULT_NAME
10140 : bgp->name);
10141 } else {
10142 vty_out(vty, "\nInstance %s:\n",
10143 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10144 ? VRF_DEFAULT_NAME
10145 : bgp->name);
10146 }
10147 bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_failed,
10148 show_established, use_json);
10149 }
10150
10151 if (use_json)
10152 vty_out(vty, "}\n");
10153 else if (!nbr_output)
10154 vty_out(vty, "%% BGP instance not found\n");
10155 }
10156
10157 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
10158 safi_t safi, bool show_failed, bool show_established,
10159 bool use_json)
10160 {
10161 struct bgp *bgp;
10162
10163 if (name) {
10164 if (strmatch(name, "all")) {
10165 bgp_show_all_instances_summary_vty(
10166 vty, afi, safi, show_failed, show_established,
10167 use_json);
10168 return CMD_SUCCESS;
10169 } else {
10170 bgp = bgp_lookup_by_name(name);
10171
10172 if (!bgp) {
10173 if (use_json)
10174 vty_out(vty, "{}\n");
10175 else
10176 vty_out(vty,
10177 "%% BGP instance not found\n");
10178 return CMD_WARNING;
10179 }
10180
10181 bgp_show_summary_afi_safi(vty, bgp, afi, safi,
10182 show_failed, show_established,
10183 use_json);
10184 return CMD_SUCCESS;
10185 }
10186 }
10187
10188 bgp = bgp_get_default();
10189
10190 if (bgp)
10191 bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_failed,
10192 show_established, use_json);
10193 else {
10194 if (use_json)
10195 vty_out(vty, "{}\n");
10196 else
10197 vty_out(vty, "%% BGP instance not found\n");
10198 return CMD_WARNING;
10199 }
10200
10201 return CMD_SUCCESS;
10202 }
10203
10204 /* `show [ip] bgp summary' commands. */
10205 DEFPY (show_ip_bgp_summary,
10206 show_ip_bgp_summary_cmd,
10207 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] [all$all] summary [established|failed] [json$uj]",
10208 SHOW_STR
10209 IP_STR
10210 BGP_STR
10211 BGP_INSTANCE_HELP_STR
10212 BGP_AFI_HELP_STR
10213 BGP_SAFI_WITH_LABEL_HELP_STR
10214 "Display the entries for all address families\n"
10215 "Summary of BGP neighbor status\n"
10216 "Show only sessions in Established state\n"
10217 "Show only sessions not in Established state\n"
10218 JSON_STR)
10219 {
10220 char *vrf = NULL;
10221 afi_t afi = AFI_MAX;
10222 safi_t safi = SAFI_MAX;
10223 bool show_failed = false;
10224 bool show_established = false;
10225
10226 int idx = 0;
10227
10228 /* show [ip] bgp */
10229 if (!all && argv_find(argv, argc, "ip", &idx))
10230 afi = AFI_IP;
10231 /* [<vrf> VIEWVRFNAME] */
10232 if (argv_find(argv, argc, "vrf", &idx)) {
10233 vrf = argv[idx + 1]->arg;
10234 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
10235 vrf = NULL;
10236 } else if (argv_find(argv, argc, "view", &idx))
10237 /* [<view> VIEWVRFNAME] */
10238 vrf = argv[idx + 1]->arg;
10239 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
10240 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
10241 argv_find_and_parse_safi(argv, argc, &idx, &safi);
10242 }
10243
10244 if (argv_find(argv, argc, "failed", &idx))
10245 show_failed = true;
10246 if (argv_find(argv, argc, "established", &idx))
10247 show_established = true;
10248
10249 return bgp_show_summary_vty(vty, vrf, afi, safi, show_failed,
10250 show_established, uj);
10251 }
10252
10253 const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
10254 {
10255 if (for_json)
10256 return get_afi_safi_json_str(afi, safi);
10257 else
10258 return get_afi_safi_vty_str(afi, safi);
10259 }
10260
10261
10262 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
10263 afi_t afi, safi_t safi,
10264 uint16_t adv_smcap, uint16_t adv_rmcap,
10265 uint16_t rcv_smcap, uint16_t rcv_rmcap,
10266 bool use_json, json_object *json_pref)
10267 {
10268 /* Send-Mode */
10269 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
10270 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
10271 if (use_json) {
10272 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
10273 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
10274 json_object_string_add(json_pref, "sendMode",
10275 "advertisedAndReceived");
10276 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
10277 json_object_string_add(json_pref, "sendMode",
10278 "advertised");
10279 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
10280 json_object_string_add(json_pref, "sendMode",
10281 "received");
10282 } else {
10283 vty_out(vty, " Send-mode: ");
10284 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
10285 vty_out(vty, "advertised");
10286 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
10287 vty_out(vty, "%sreceived",
10288 CHECK_FLAG(p->af_cap[afi][safi],
10289 adv_smcap)
10290 ? ", "
10291 : "");
10292 vty_out(vty, "\n");
10293 }
10294 }
10295
10296 /* Receive-Mode */
10297 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
10298 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
10299 if (use_json) {
10300 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
10301 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
10302 json_object_string_add(json_pref, "recvMode",
10303 "advertisedAndReceived");
10304 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
10305 json_object_string_add(json_pref, "recvMode",
10306 "advertised");
10307 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
10308 json_object_string_add(json_pref, "recvMode",
10309 "received");
10310 } else {
10311 vty_out(vty, " Receive-mode: ");
10312 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
10313 vty_out(vty, "advertised");
10314 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
10315 vty_out(vty, "%sreceived",
10316 CHECK_FLAG(p->af_cap[afi][safi],
10317 adv_rmcap)
10318 ? ", "
10319 : "");
10320 vty_out(vty, "\n");
10321 }
10322 }
10323 }
10324
10325 static void bgp_show_neighnor_graceful_restart_rbit(struct vty *vty,
10326 struct peer *p,
10327 bool use_json,
10328 json_object *json)
10329 {
10330 bool rbit_status = false;
10331
10332 if (!use_json)
10333 vty_out(vty, "\n R bit: ");
10334
10335 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
10336 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
10337 && (p->status == Established)) {
10338
10339 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_BIT_RCV))
10340 rbit_status = true;
10341 else
10342 rbit_status = false;
10343 }
10344
10345 if (rbit_status) {
10346 if (use_json)
10347 json_object_boolean_true_add(json, "rBit");
10348 else
10349 vty_out(vty, "True\n");
10350 } else {
10351 if (use_json)
10352 json_object_boolean_false_add(json, "rBit");
10353 else
10354 vty_out(vty, "False\n");
10355 }
10356 }
10357
10358 static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
10359 struct peer *peer,
10360 bool use_json,
10361 json_object *json)
10362 {
10363 const char *mode = "NotApplicable";
10364
10365 if (!use_json)
10366 vty_out(vty, "\n Remote GR Mode: ");
10367
10368 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
10369 && (peer->status == Established)) {
10370
10371 if ((peer->nsf_af_count == 0)
10372 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
10373
10374 mode = "Disable";
10375
10376 } else if (peer->nsf_af_count == 0
10377 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
10378
10379 mode = "Helper";
10380
10381 } else if (peer->nsf_af_count != 0
10382 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
10383
10384 mode = "Restart";
10385 }
10386 }
10387
10388 if (use_json) {
10389 json_object_string_add(json, "remoteGrMode", mode);
10390 } else
10391 vty_out(vty, mode, "\n");
10392 }
10393
10394 static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
10395 struct peer *p,
10396 bool use_json,
10397 json_object *json)
10398 {
10399 const char *mode = "Invalid";
10400
10401 if (!use_json)
10402 vty_out(vty, " Local GR Mode: ");
10403
10404 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
10405 mode = "Helper";
10406 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
10407 mode = "Restart";
10408 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
10409 mode = "Disable";
10410 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
10411 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
10412 mode = "Helper*";
10413 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
10414 mode = "Restart*";
10415 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
10416 mode = "Disable*";
10417 else
10418 mode = "Invalid*";
10419 }
10420
10421 if (use_json) {
10422 json_object_string_add(json, "localGrMode", mode);
10423 } else {
10424 vty_out(vty, mode, "\n");
10425 }
10426 }
10427
10428 static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
10429 struct vty *vty, struct peer *peer, bool use_json, json_object *json)
10430 {
10431 afi_t afi;
10432 safi_t safi;
10433 json_object *json_afi_safi = NULL;
10434 json_object *json_timer = NULL;
10435 json_object *json_endofrib_status = NULL;
10436 bool eor_flag = false;
10437
10438 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
10439 for (safi = SAFI_UNICAST; safi <= SAFI_MPLS_VPN; safi++) {
10440 if (!peer->afc[afi][safi])
10441 continue;
10442
10443 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
10444 || !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
10445 continue;
10446
10447 if (use_json) {
10448 json_afi_safi = json_object_new_object();
10449 json_endofrib_status = json_object_new_object();
10450 json_timer = json_object_new_object();
10451 }
10452
10453 if (peer->eor_stime[afi][safi]
10454 >= peer->pkt_stime[afi][safi])
10455 eor_flag = true;
10456 else
10457 eor_flag = false;
10458
10459 if (!use_json) {
10460 vty_out(vty, " %s:\n",
10461 get_afi_safi_str(afi, safi, false));
10462
10463 vty_out(vty, " F bit: ");
10464 }
10465
10466 if (peer->nsf[afi][safi]
10467 && CHECK_FLAG(peer->af_cap[afi][safi],
10468 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
10469
10470 if (use_json) {
10471 json_object_boolean_true_add(
10472 json_afi_safi, "fBit");
10473 } else
10474 vty_out(vty, "True\n");
10475 } else {
10476 if (use_json)
10477 json_object_boolean_false_add(
10478 json_afi_safi, "fBit");
10479 else
10480 vty_out(vty, "False\n");
10481 }
10482
10483 if (!use_json)
10484 vty_out(vty, " End-of-RIB sent: ");
10485
10486 if (CHECK_FLAG(peer->af_sflags[afi][safi],
10487 PEER_STATUS_EOR_SEND)) {
10488 if (use_json) {
10489 json_object_boolean_true_add(
10490 json_endofrib_status,
10491 "endOfRibSend");
10492
10493 PRINT_EOR_JSON(eor_flag);
10494 } else {
10495 vty_out(vty, "Yes\n");
10496 vty_out(vty,
10497 " End-of-RIB sent after update: ");
10498
10499 PRINT_EOR(eor_flag);
10500 }
10501 } else {
10502 if (use_json) {
10503 json_object_boolean_false_add(
10504 json_endofrib_status,
10505 "endOfRibSend");
10506 json_object_boolean_false_add(
10507 json_endofrib_status,
10508 "endOfRibSentAfterUpdate");
10509 } else {
10510 vty_out(vty, "No\n");
10511 vty_out(vty,
10512 " End-of-RIB sent after update: ");
10513 vty_out(vty, "No\n");
10514 }
10515 }
10516
10517 if (!use_json)
10518 vty_out(vty, " End-of-RIB received: ");
10519
10520 if (CHECK_FLAG(peer->af_sflags[afi][safi],
10521 PEER_STATUS_EOR_RECEIVED)) {
10522 if (use_json)
10523 json_object_boolean_true_add(
10524 json_endofrib_status,
10525 "endOfRibRecv");
10526 else
10527 vty_out(vty, "Yes\n");
10528 } else {
10529 if (use_json)
10530 json_object_boolean_false_add(
10531 json_endofrib_status,
10532 "endOfRibRecv");
10533 else
10534 vty_out(vty, "No\n");
10535 }
10536
10537 if (use_json) {
10538 json_object_int_add(json_timer,
10539 "stalePathTimer",
10540 peer->bgp->stalepath_time);
10541
10542 if (peer->t_gr_stale != NULL) {
10543 json_object_int_add(
10544 json_timer,
10545 "stalePathTimerRemaining",
10546 thread_timer_remain_second(
10547 peer->t_gr_stale));
10548 }
10549
10550 /* Display Configured Selection
10551 * Deferral only when when
10552 * Gr mode is enabled.
10553 */
10554 if (CHECK_FLAG(peer->flags,
10555 PEER_FLAG_GRACEFUL_RESTART)) {
10556 json_object_int_add(
10557 json_timer,
10558 "selectionDeferralTimer",
10559 peer->bgp->stalepath_time);
10560 }
10561
10562 if (peer->bgp->gr_info[afi][safi]
10563 .t_select_deferral
10564 != NULL) {
10565
10566 json_object_int_add(
10567 json_timer,
10568 "selectionDeferralTimerRemaining",
10569 thread_timer_remain_second(
10570 peer->bgp
10571 ->gr_info[afi]
10572 [safi]
10573 .t_select_deferral));
10574 }
10575 } else {
10576 vty_out(vty, " Timers:\n");
10577 vty_out(vty,
10578 " Configured Stale Path Time(sec): %u\n",
10579 peer->bgp->stalepath_time);
10580
10581 if (peer->t_gr_stale != NULL)
10582 vty_out(vty,
10583 " Stale Path Remaining(sec): %ld\n",
10584 thread_timer_remain_second(
10585 peer->t_gr_stale));
10586 /* Display Configured Selection
10587 * Deferral only when when
10588 * Gr mode is enabled.
10589 */
10590 if (CHECK_FLAG(peer->flags,
10591 PEER_FLAG_GRACEFUL_RESTART))
10592 vty_out(vty,
10593 " Configured Selection Deferral Time(sec): %u\n",
10594 peer->bgp->select_defer_time);
10595
10596 if (peer->bgp->gr_info[afi][safi]
10597 .t_select_deferral
10598 != NULL)
10599 vty_out(vty,
10600 " Selection Deferral Time Remaining(sec): %ld\n",
10601 thread_timer_remain_second(
10602 peer->bgp
10603 ->gr_info[afi]
10604 [safi]
10605 .t_select_deferral));
10606 }
10607 if (use_json) {
10608 json_object_object_add(json_afi_safi,
10609 "endOfRibStatus",
10610 json_endofrib_status);
10611 json_object_object_add(json_afi_safi, "timers",
10612 json_timer);
10613 json_object_object_add(
10614 json, get_afi_safi_str(afi, safi, true),
10615 json_afi_safi);
10616 }
10617 }
10618 }
10619 }
10620
10621 static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
10622 struct peer *p,
10623 bool use_json,
10624 json_object *json)
10625 {
10626 if (use_json) {
10627 json_object *json_timer = NULL;
10628
10629 json_timer = json_object_new_object();
10630
10631 json_object_int_add(json_timer, "configuredRestartTimer",
10632 p->bgp->restart_time);
10633
10634 json_object_int_add(json_timer, "receivedRestartTimer",
10635 p->v_gr_restart);
10636
10637 if (p->t_gr_restart != NULL)
10638 json_object_int_add(
10639 json_timer, "restartTimerRemaining",
10640 thread_timer_remain_second(p->t_gr_restart));
10641
10642 json_object_object_add(json, "timers", json_timer);
10643 } else {
10644
10645 vty_out(vty, " Timers:\n");
10646 vty_out(vty, " Configured Restart Time(sec): %u\n",
10647 p->bgp->restart_time);
10648
10649 vty_out(vty, " Received Restart Time(sec): %u\n",
10650 p->v_gr_restart);
10651 if (p->t_gr_restart != NULL)
10652 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
10653 thread_timer_remain_second(p->t_gr_restart));
10654 if (p->t_gr_restart != NULL) {
10655 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
10656 thread_timer_remain_second(p->t_gr_restart));
10657 }
10658 }
10659 }
10660
10661 static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
10662 bool use_json, json_object *json)
10663 {
10664 char buf[SU_ADDRSTRLEN] = {0};
10665 char dn_flag[2] = {0};
10666 /* '*' + v6 address of neighbor */
10667 char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
10668
10669 if (!p->conf_if && peer_dynamic_neighbor(p))
10670 dn_flag[0] = '*';
10671
10672 if (p->conf_if) {
10673 if (use_json)
10674 json_object_string_add(
10675 json, "neighborAddr",
10676 BGP_PEER_SU_UNSPEC(p)
10677 ? "none"
10678 : sockunion2str(&p->su, buf,
10679 SU_ADDRSTRLEN));
10680 else
10681 vty_out(vty, "BGP neighbor on %s: %s\n", p->conf_if,
10682 BGP_PEER_SU_UNSPEC(p)
10683 ? "none"
10684 : sockunion2str(&p->su, buf,
10685 SU_ADDRSTRLEN));
10686 } else {
10687 snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
10688 p->host);
10689
10690 if (use_json)
10691 json_object_string_add(json, "neighborAddr",
10692 neighborAddr);
10693 else
10694 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
10695 }
10696
10697 /* more gr info in new format */
10698 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json);
10699 }
10700
10701 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
10702 safi_t safi, bool use_json,
10703 json_object *json_neigh)
10704 {
10705 struct bgp_filter *filter;
10706 struct peer_af *paf;
10707 char orf_pfx_name[BUFSIZ];
10708 int orf_pfx_count;
10709 json_object *json_af = NULL;
10710 json_object *json_prefA = NULL;
10711 json_object *json_prefB = NULL;
10712 json_object *json_addr = NULL;
10713
10714 if (use_json) {
10715 json_addr = json_object_new_object();
10716 json_af = json_object_new_object();
10717 filter = &p->filter[afi][safi];
10718
10719 if (peer_group_active(p))
10720 json_object_string_add(json_addr, "peerGroupMember",
10721 p->group->name);
10722
10723 paf = peer_af_find(p, afi, safi);
10724 if (paf && PAF_SUBGRP(paf)) {
10725 json_object_int_add(json_addr, "updateGroupId",
10726 PAF_UPDGRP(paf)->id);
10727 json_object_int_add(json_addr, "subGroupId",
10728 PAF_SUBGRP(paf)->id);
10729 json_object_int_add(json_addr, "packetQueueLength",
10730 bpacket_queue_virtual_length(paf));
10731 }
10732
10733 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
10734 || CHECK_FLAG(p->af_cap[afi][safi],
10735 PEER_CAP_ORF_PREFIX_SM_RCV)
10736 || CHECK_FLAG(p->af_cap[afi][safi],
10737 PEER_CAP_ORF_PREFIX_RM_ADV)
10738 || CHECK_FLAG(p->af_cap[afi][safi],
10739 PEER_CAP_ORF_PREFIX_RM_RCV)) {
10740 json_object_int_add(json_af, "orfType",
10741 ORF_TYPE_PREFIX);
10742 json_prefA = json_object_new_object();
10743 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
10744 PEER_CAP_ORF_PREFIX_SM_ADV,
10745 PEER_CAP_ORF_PREFIX_RM_ADV,
10746 PEER_CAP_ORF_PREFIX_SM_RCV,
10747 PEER_CAP_ORF_PREFIX_RM_RCV,
10748 use_json, json_prefA);
10749 json_object_object_add(json_af, "orfPrefixList",
10750 json_prefA);
10751 }
10752
10753 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
10754 || CHECK_FLAG(p->af_cap[afi][safi],
10755 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
10756 || CHECK_FLAG(p->af_cap[afi][safi],
10757 PEER_CAP_ORF_PREFIX_RM_ADV)
10758 || CHECK_FLAG(p->af_cap[afi][safi],
10759 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
10760 json_object_int_add(json_af, "orfOldType",
10761 ORF_TYPE_PREFIX_OLD);
10762 json_prefB = json_object_new_object();
10763 bgp_show_peer_afi_orf_cap(
10764 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
10765 PEER_CAP_ORF_PREFIX_RM_ADV,
10766 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
10767 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
10768 json_prefB);
10769 json_object_object_add(json_af, "orfOldPrefixList",
10770 json_prefB);
10771 }
10772
10773 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
10774 || CHECK_FLAG(p->af_cap[afi][safi],
10775 PEER_CAP_ORF_PREFIX_SM_RCV)
10776 || CHECK_FLAG(p->af_cap[afi][safi],
10777 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
10778 || CHECK_FLAG(p->af_cap[afi][safi],
10779 PEER_CAP_ORF_PREFIX_RM_ADV)
10780 || CHECK_FLAG(p->af_cap[afi][safi],
10781 PEER_CAP_ORF_PREFIX_RM_RCV)
10782 || CHECK_FLAG(p->af_cap[afi][safi],
10783 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
10784 json_object_object_add(json_addr, "afDependentCap",
10785 json_af);
10786 else
10787 json_object_free(json_af);
10788
10789 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
10790 p->host, afi, safi);
10791 orf_pfx_count = prefix_bgp_show_prefix_list(
10792 NULL, afi, orf_pfx_name, use_json);
10793
10794 if (CHECK_FLAG(p->af_sflags[afi][safi],
10795 PEER_STATUS_ORF_PREFIX_SEND)
10796 || orf_pfx_count) {
10797 if (CHECK_FLAG(p->af_sflags[afi][safi],
10798 PEER_STATUS_ORF_PREFIX_SEND))
10799 json_object_boolean_true_add(json_neigh,
10800 "orfSent");
10801 if (orf_pfx_count)
10802 json_object_int_add(json_addr, "orfRecvCounter",
10803 orf_pfx_count);
10804 }
10805 if (CHECK_FLAG(p->af_sflags[afi][safi],
10806 PEER_STATUS_ORF_WAIT_REFRESH))
10807 json_object_string_add(
10808 json_addr, "orfFirstUpdate",
10809 "deferredUntilORFOrRouteRefreshRecvd");
10810
10811 if (CHECK_FLAG(p->af_flags[afi][safi],
10812 PEER_FLAG_REFLECTOR_CLIENT))
10813 json_object_boolean_true_add(json_addr,
10814 "routeReflectorClient");
10815 if (CHECK_FLAG(p->af_flags[afi][safi],
10816 PEER_FLAG_RSERVER_CLIENT))
10817 json_object_boolean_true_add(json_addr,
10818 "routeServerClient");
10819 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
10820 json_object_boolean_true_add(json_addr,
10821 "inboundSoftConfigPermit");
10822
10823 if (CHECK_FLAG(p->af_flags[afi][safi],
10824 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
10825 json_object_boolean_true_add(
10826 json_addr,
10827 "privateAsNumsAllReplacedInUpdatesToNbr");
10828 else if (CHECK_FLAG(p->af_flags[afi][safi],
10829 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
10830 json_object_boolean_true_add(
10831 json_addr,
10832 "privateAsNumsReplacedInUpdatesToNbr");
10833 else if (CHECK_FLAG(p->af_flags[afi][safi],
10834 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
10835 json_object_boolean_true_add(
10836 json_addr,
10837 "privateAsNumsAllRemovedInUpdatesToNbr");
10838 else if (CHECK_FLAG(p->af_flags[afi][safi],
10839 PEER_FLAG_REMOVE_PRIVATE_AS))
10840 json_object_boolean_true_add(
10841 json_addr,
10842 "privateAsNumsRemovedInUpdatesToNbr");
10843
10844 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
10845 json_object_boolean_true_add(
10846 json_addr,
10847 bgp_addpath_names(p->addpath_type[afi][safi])
10848 ->type_json_name);
10849
10850 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
10851 json_object_string_add(json_addr,
10852 "overrideASNsInOutboundUpdates",
10853 "ifAspathEqualRemoteAs");
10854
10855 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
10856 || CHECK_FLAG(p->af_flags[afi][safi],
10857 PEER_FLAG_FORCE_NEXTHOP_SELF))
10858 json_object_boolean_true_add(json_addr,
10859 "routerAlwaysNextHop");
10860 if (CHECK_FLAG(p->af_flags[afi][safi],
10861 PEER_FLAG_AS_PATH_UNCHANGED))
10862 json_object_boolean_true_add(
10863 json_addr, "unchangedAsPathPropogatedToNbr");
10864 if (CHECK_FLAG(p->af_flags[afi][safi],
10865 PEER_FLAG_NEXTHOP_UNCHANGED))
10866 json_object_boolean_true_add(
10867 json_addr, "unchangedNextHopPropogatedToNbr");
10868 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
10869 json_object_boolean_true_add(
10870 json_addr, "unchangedMedPropogatedToNbr");
10871 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
10872 || CHECK_FLAG(p->af_flags[afi][safi],
10873 PEER_FLAG_SEND_EXT_COMMUNITY)) {
10874 if (CHECK_FLAG(p->af_flags[afi][safi],
10875 PEER_FLAG_SEND_COMMUNITY)
10876 && CHECK_FLAG(p->af_flags[afi][safi],
10877 PEER_FLAG_SEND_EXT_COMMUNITY))
10878 json_object_string_add(json_addr,
10879 "commAttriSentToNbr",
10880 "extendedAndStandard");
10881 else if (CHECK_FLAG(p->af_flags[afi][safi],
10882 PEER_FLAG_SEND_EXT_COMMUNITY))
10883 json_object_string_add(json_addr,
10884 "commAttriSentToNbr",
10885 "extended");
10886 else
10887 json_object_string_add(json_addr,
10888 "commAttriSentToNbr",
10889 "standard");
10890 }
10891 if (CHECK_FLAG(p->af_flags[afi][safi],
10892 PEER_FLAG_DEFAULT_ORIGINATE)) {
10893 if (p->default_rmap[afi][safi].name)
10894 json_object_string_add(
10895 json_addr, "defaultRouteMap",
10896 p->default_rmap[afi][safi].name);
10897
10898 if (paf && PAF_SUBGRP(paf)
10899 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
10900 SUBGRP_STATUS_DEFAULT_ORIGINATE))
10901 json_object_boolean_true_add(json_addr,
10902 "defaultSent");
10903 else
10904 json_object_boolean_true_add(json_addr,
10905 "defaultNotSent");
10906 }
10907
10908 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
10909 if (is_evpn_enabled())
10910 json_object_boolean_true_add(
10911 json_addr, "advertiseAllVnis");
10912 }
10913
10914 if (filter->plist[FILTER_IN].name
10915 || filter->dlist[FILTER_IN].name
10916 || filter->aslist[FILTER_IN].name
10917 || filter->map[RMAP_IN].name)
10918 json_object_boolean_true_add(json_addr,
10919 "inboundPathPolicyConfig");
10920 if (filter->plist[FILTER_OUT].name
10921 || filter->dlist[FILTER_OUT].name
10922 || filter->aslist[FILTER_OUT].name
10923 || filter->map[RMAP_OUT].name || filter->usmap.name)
10924 json_object_boolean_true_add(
10925 json_addr, "outboundPathPolicyConfig");
10926
10927 /* prefix-list */
10928 if (filter->plist[FILTER_IN].name)
10929 json_object_string_add(json_addr,
10930 "incomingUpdatePrefixFilterList",
10931 filter->plist[FILTER_IN].name);
10932 if (filter->plist[FILTER_OUT].name)
10933 json_object_string_add(json_addr,
10934 "outgoingUpdatePrefixFilterList",
10935 filter->plist[FILTER_OUT].name);
10936
10937 /* distribute-list */
10938 if (filter->dlist[FILTER_IN].name)
10939 json_object_string_add(
10940 json_addr, "incomingUpdateNetworkFilterList",
10941 filter->dlist[FILTER_IN].name);
10942 if (filter->dlist[FILTER_OUT].name)
10943 json_object_string_add(
10944 json_addr, "outgoingUpdateNetworkFilterList",
10945 filter->dlist[FILTER_OUT].name);
10946
10947 /* filter-list. */
10948 if (filter->aslist[FILTER_IN].name)
10949 json_object_string_add(json_addr,
10950 "incomingUpdateAsPathFilterList",
10951 filter->aslist[FILTER_IN].name);
10952 if (filter->aslist[FILTER_OUT].name)
10953 json_object_string_add(json_addr,
10954 "outgoingUpdateAsPathFilterList",
10955 filter->aslist[FILTER_OUT].name);
10956
10957 /* route-map. */
10958 if (filter->map[RMAP_IN].name)
10959 json_object_string_add(
10960 json_addr, "routeMapForIncomingAdvertisements",
10961 filter->map[RMAP_IN].name);
10962 if (filter->map[RMAP_OUT].name)
10963 json_object_string_add(
10964 json_addr, "routeMapForOutgoingAdvertisements",
10965 filter->map[RMAP_OUT].name);
10966
10967 /* ebgp-requires-policy (inbound) */
10968 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
10969 && !bgp_inbound_policy_exists(p, filter))
10970 json_object_string_add(
10971 json_addr, "inboundEbgpRequiresPolicy",
10972 "Inbound updates discarded due to missing policy");
10973
10974 /* ebgp-requires-policy (outbound) */
10975 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
10976 && (!bgp_outbound_policy_exists(p, filter)))
10977 json_object_string_add(
10978 json_addr, "outboundEbgpRequiresPolicy",
10979 "Outbound updates discarded due to missing policy");
10980
10981 /* unsuppress-map */
10982 if (filter->usmap.name)
10983 json_object_string_add(json_addr,
10984 "selectiveUnsuppressRouteMap",
10985 filter->usmap.name);
10986
10987 /* Receive prefix count */
10988 json_object_int_add(json_addr, "acceptedPrefixCounter",
10989 p->pcount[afi][safi]);
10990 if (paf && PAF_SUBGRP(paf))
10991 json_object_int_add(json_addr, "sentPrefixCounter",
10992 (PAF_SUBGRP(paf))->scount);
10993
10994 /* Maximum prefix */
10995 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
10996 json_object_int_add(json_addr, "prefixOutAllowedMax",
10997 p->pmax_out[afi][safi]);
10998
10999 /* Maximum prefix */
11000 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
11001 json_object_int_add(json_addr, "prefixAllowedMax",
11002 p->pmax[afi][safi]);
11003 if (CHECK_FLAG(p->af_flags[afi][safi],
11004 PEER_FLAG_MAX_PREFIX_WARNING))
11005 json_object_boolean_true_add(
11006 json_addr, "prefixAllowedMaxWarning");
11007 json_object_int_add(json_addr,
11008 "prefixAllowedWarningThresh",
11009 p->pmax_threshold[afi][safi]);
11010 if (p->pmax_restart[afi][safi])
11011 json_object_int_add(
11012 json_addr,
11013 "prefixAllowedRestartIntervalMsecs",
11014 p->pmax_restart[afi][safi] * 60000);
11015 }
11016 json_object_object_add(json_neigh,
11017 get_afi_safi_str(afi, safi, true),
11018 json_addr);
11019
11020 } else {
11021 filter = &p->filter[afi][safi];
11022
11023 vty_out(vty, " For address family: %s\n",
11024 get_afi_safi_str(afi, safi, false));
11025
11026 if (peer_group_active(p))
11027 vty_out(vty, " %s peer-group member\n",
11028 p->group->name);
11029
11030 paf = peer_af_find(p, afi, safi);
11031 if (paf && PAF_SUBGRP(paf)) {
11032 vty_out(vty, " Update group %" PRIu64", subgroup %" PRIu64 "\n",
11033 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
11034 vty_out(vty, " Packet Queue length %d\n",
11035 bpacket_queue_virtual_length(paf));
11036 } else {
11037 vty_out(vty, " Not part of any update group\n");
11038 }
11039 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11040 || CHECK_FLAG(p->af_cap[afi][safi],
11041 PEER_CAP_ORF_PREFIX_SM_RCV)
11042 || CHECK_FLAG(p->af_cap[afi][safi],
11043 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11044 || CHECK_FLAG(p->af_cap[afi][safi],
11045 PEER_CAP_ORF_PREFIX_RM_ADV)
11046 || CHECK_FLAG(p->af_cap[afi][safi],
11047 PEER_CAP_ORF_PREFIX_RM_RCV)
11048 || CHECK_FLAG(p->af_cap[afi][safi],
11049 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
11050 vty_out(vty, " AF-dependant capabilities:\n");
11051
11052 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11053 || CHECK_FLAG(p->af_cap[afi][safi],
11054 PEER_CAP_ORF_PREFIX_SM_RCV)
11055 || CHECK_FLAG(p->af_cap[afi][safi],
11056 PEER_CAP_ORF_PREFIX_RM_ADV)
11057 || CHECK_FLAG(p->af_cap[afi][safi],
11058 PEER_CAP_ORF_PREFIX_RM_RCV)) {
11059 vty_out(vty,
11060 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
11061 ORF_TYPE_PREFIX);
11062 bgp_show_peer_afi_orf_cap(
11063 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
11064 PEER_CAP_ORF_PREFIX_RM_ADV,
11065 PEER_CAP_ORF_PREFIX_SM_RCV,
11066 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
11067 }
11068 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11069 || CHECK_FLAG(p->af_cap[afi][safi],
11070 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11071 || CHECK_FLAG(p->af_cap[afi][safi],
11072 PEER_CAP_ORF_PREFIX_RM_ADV)
11073 || CHECK_FLAG(p->af_cap[afi][safi],
11074 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
11075 vty_out(vty,
11076 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
11077 ORF_TYPE_PREFIX_OLD);
11078 bgp_show_peer_afi_orf_cap(
11079 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
11080 PEER_CAP_ORF_PREFIX_RM_ADV,
11081 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
11082 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
11083 }
11084
11085 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
11086 p->host, afi, safi);
11087 orf_pfx_count = prefix_bgp_show_prefix_list(
11088 NULL, afi, orf_pfx_name, use_json);
11089
11090 if (CHECK_FLAG(p->af_sflags[afi][safi],
11091 PEER_STATUS_ORF_PREFIX_SEND)
11092 || orf_pfx_count) {
11093 vty_out(vty, " Outbound Route Filter (ORF):");
11094 if (CHECK_FLAG(p->af_sflags[afi][safi],
11095 PEER_STATUS_ORF_PREFIX_SEND))
11096 vty_out(vty, " sent;");
11097 if (orf_pfx_count)
11098 vty_out(vty, " received (%d entries)",
11099 orf_pfx_count);
11100 vty_out(vty, "\n");
11101 }
11102 if (CHECK_FLAG(p->af_sflags[afi][safi],
11103 PEER_STATUS_ORF_WAIT_REFRESH))
11104 vty_out(vty,
11105 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
11106
11107 if (CHECK_FLAG(p->af_flags[afi][safi],
11108 PEER_FLAG_REFLECTOR_CLIENT))
11109 vty_out(vty, " Route-Reflector Client\n");
11110 if (CHECK_FLAG(p->af_flags[afi][safi],
11111 PEER_FLAG_RSERVER_CLIENT))
11112 vty_out(vty, " Route-Server Client\n");
11113 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
11114 vty_out(vty,
11115 " Inbound soft reconfiguration allowed\n");
11116
11117 if (CHECK_FLAG(p->af_flags[afi][safi],
11118 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
11119 vty_out(vty,
11120 " Private AS numbers (all) replaced in updates to this neighbor\n");
11121 else if (CHECK_FLAG(p->af_flags[afi][safi],
11122 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
11123 vty_out(vty,
11124 " Private AS numbers replaced in updates to this neighbor\n");
11125 else if (CHECK_FLAG(p->af_flags[afi][safi],
11126 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
11127 vty_out(vty,
11128 " Private AS numbers (all) removed in updates to this neighbor\n");
11129 else if (CHECK_FLAG(p->af_flags[afi][safi],
11130 PEER_FLAG_REMOVE_PRIVATE_AS))
11131 vty_out(vty,
11132 " Private AS numbers removed in updates to this neighbor\n");
11133
11134 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
11135 vty_out(vty, " %s\n",
11136 bgp_addpath_names(p->addpath_type[afi][safi])
11137 ->human_description);
11138
11139 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
11140 vty_out(vty,
11141 " Override ASNs in outbound updates if aspath equals remote-as\n");
11142
11143 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
11144 || CHECK_FLAG(p->af_flags[afi][safi],
11145 PEER_FLAG_FORCE_NEXTHOP_SELF))
11146 vty_out(vty, " NEXT_HOP is always this router\n");
11147 if (CHECK_FLAG(p->af_flags[afi][safi],
11148 PEER_FLAG_AS_PATH_UNCHANGED))
11149 vty_out(vty,
11150 " AS_PATH is propagated unchanged to this neighbor\n");
11151 if (CHECK_FLAG(p->af_flags[afi][safi],
11152 PEER_FLAG_NEXTHOP_UNCHANGED))
11153 vty_out(vty,
11154 " NEXT_HOP is propagated unchanged to this neighbor\n");
11155 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
11156 vty_out(vty,
11157 " MED is propagated unchanged to this neighbor\n");
11158 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
11159 || CHECK_FLAG(p->af_flags[afi][safi],
11160 PEER_FLAG_SEND_EXT_COMMUNITY)
11161 || CHECK_FLAG(p->af_flags[afi][safi],
11162 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
11163 vty_out(vty,
11164 " Community attribute sent to this neighbor");
11165 if (CHECK_FLAG(p->af_flags[afi][safi],
11166 PEER_FLAG_SEND_COMMUNITY)
11167 && CHECK_FLAG(p->af_flags[afi][safi],
11168 PEER_FLAG_SEND_EXT_COMMUNITY)
11169 && CHECK_FLAG(p->af_flags[afi][safi],
11170 PEER_FLAG_SEND_LARGE_COMMUNITY))
11171 vty_out(vty, "(all)\n");
11172 else if (CHECK_FLAG(p->af_flags[afi][safi],
11173 PEER_FLAG_SEND_LARGE_COMMUNITY))
11174 vty_out(vty, "(large)\n");
11175 else if (CHECK_FLAG(p->af_flags[afi][safi],
11176 PEER_FLAG_SEND_EXT_COMMUNITY))
11177 vty_out(vty, "(extended)\n");
11178 else
11179 vty_out(vty, "(standard)\n");
11180 }
11181 if (CHECK_FLAG(p->af_flags[afi][safi],
11182 PEER_FLAG_DEFAULT_ORIGINATE)) {
11183 vty_out(vty, " Default information originate,");
11184
11185 if (p->default_rmap[afi][safi].name)
11186 vty_out(vty, " default route-map %s%s,",
11187 p->default_rmap[afi][safi].map ? "*"
11188 : "",
11189 p->default_rmap[afi][safi].name);
11190 if (paf && PAF_SUBGRP(paf)
11191 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
11192 SUBGRP_STATUS_DEFAULT_ORIGINATE))
11193 vty_out(vty, " default sent\n");
11194 else
11195 vty_out(vty, " default not sent\n");
11196 }
11197
11198 /* advertise-vni-all */
11199 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
11200 if (is_evpn_enabled())
11201 vty_out(vty, " advertise-all-vni\n");
11202 }
11203
11204 if (filter->plist[FILTER_IN].name
11205 || filter->dlist[FILTER_IN].name
11206 || filter->aslist[FILTER_IN].name
11207 || filter->map[RMAP_IN].name)
11208 vty_out(vty, " Inbound path policy configured\n");
11209 if (filter->plist[FILTER_OUT].name
11210 || filter->dlist[FILTER_OUT].name
11211 || filter->aslist[FILTER_OUT].name
11212 || filter->map[RMAP_OUT].name || filter->usmap.name)
11213 vty_out(vty, " Outbound path policy configured\n");
11214
11215 /* prefix-list */
11216 if (filter->plist[FILTER_IN].name)
11217 vty_out(vty,
11218 " Incoming update prefix filter list is %s%s\n",
11219 filter->plist[FILTER_IN].plist ? "*" : "",
11220 filter->plist[FILTER_IN].name);
11221 if (filter->plist[FILTER_OUT].name)
11222 vty_out(vty,
11223 " Outgoing update prefix filter list is %s%s\n",
11224 filter->plist[FILTER_OUT].plist ? "*" : "",
11225 filter->plist[FILTER_OUT].name);
11226
11227 /* distribute-list */
11228 if (filter->dlist[FILTER_IN].name)
11229 vty_out(vty,
11230 " Incoming update network filter list is %s%s\n",
11231 filter->dlist[FILTER_IN].alist ? "*" : "",
11232 filter->dlist[FILTER_IN].name);
11233 if (filter->dlist[FILTER_OUT].name)
11234 vty_out(vty,
11235 " Outgoing update network filter list is %s%s\n",
11236 filter->dlist[FILTER_OUT].alist ? "*" : "",
11237 filter->dlist[FILTER_OUT].name);
11238
11239 /* filter-list. */
11240 if (filter->aslist[FILTER_IN].name)
11241 vty_out(vty,
11242 " Incoming update AS path filter list is %s%s\n",
11243 filter->aslist[FILTER_IN].aslist ? "*" : "",
11244 filter->aslist[FILTER_IN].name);
11245 if (filter->aslist[FILTER_OUT].name)
11246 vty_out(vty,
11247 " Outgoing update AS path filter list is %s%s\n",
11248 filter->aslist[FILTER_OUT].aslist ? "*" : "",
11249 filter->aslist[FILTER_OUT].name);
11250
11251 /* route-map. */
11252 if (filter->map[RMAP_IN].name)
11253 vty_out(vty,
11254 " Route map for incoming advertisements is %s%s\n",
11255 filter->map[RMAP_IN].map ? "*" : "",
11256 filter->map[RMAP_IN].name);
11257 if (filter->map[RMAP_OUT].name)
11258 vty_out(vty,
11259 " Route map for outgoing advertisements is %s%s\n",
11260 filter->map[RMAP_OUT].map ? "*" : "",
11261 filter->map[RMAP_OUT].name);
11262
11263 /* ebgp-requires-policy (inbound) */
11264 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
11265 && !bgp_inbound_policy_exists(p, filter))
11266 vty_out(vty,
11267 " Inbound updates discarded due to missing policy\n");
11268
11269 /* ebgp-requires-policy (outbound) */
11270 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
11271 && !bgp_outbound_policy_exists(p, filter))
11272 vty_out(vty,
11273 " Outbound updates discarded due to missing policy\n");
11274
11275 /* unsuppress-map */
11276 if (filter->usmap.name)
11277 vty_out(vty,
11278 " Route map for selective unsuppress is %s%s\n",
11279 filter->usmap.map ? "*" : "",
11280 filter->usmap.name);
11281
11282 /* Receive prefix count */
11283 vty_out(vty, " %u accepted prefixes\n",
11284 p->pcount[afi][safi]);
11285
11286 /* maximum-prefix-out */
11287 if (CHECK_FLAG(p->af_flags[afi][safi],
11288 PEER_FLAG_MAX_PREFIX_OUT))
11289 vty_out(vty,
11290 " Maximum allowed prefixes sent %u\n",
11291 p->pmax_out[afi][safi]);
11292
11293 /* Maximum prefix */
11294 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
11295 vty_out(vty,
11296 " Maximum prefixes allowed %u%s\n",
11297 p->pmax[afi][safi],
11298 CHECK_FLAG(p->af_flags[afi][safi],
11299 PEER_FLAG_MAX_PREFIX_WARNING)
11300 ? " (warning-only)"
11301 : "");
11302 vty_out(vty, " Threshold for warning message %d%%",
11303 p->pmax_threshold[afi][safi]);
11304 if (p->pmax_restart[afi][safi])
11305 vty_out(vty, ", restart interval %d min",
11306 p->pmax_restart[afi][safi]);
11307 vty_out(vty, "\n");
11308 }
11309
11310 vty_out(vty, "\n");
11311 }
11312 }
11313
11314 static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
11315 json_object *json)
11316 {
11317 struct bgp *bgp;
11318 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
11319 char timebuf[BGP_UPTIME_LEN];
11320 char dn_flag[2];
11321 afi_t afi;
11322 safi_t safi;
11323 uint16_t i;
11324 uint8_t *msg;
11325 json_object *json_neigh = NULL;
11326 time_t epoch_tbuf;
11327
11328 bgp = p->bgp;
11329
11330 if (use_json)
11331 json_neigh = json_object_new_object();
11332
11333 memset(dn_flag, '\0', sizeof(dn_flag));
11334 if (!p->conf_if && peer_dynamic_neighbor(p))
11335 dn_flag[0] = '*';
11336
11337 if (!use_json) {
11338 if (p->conf_if) /* Configured interface name. */
11339 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
11340 BGP_PEER_SU_UNSPEC(p)
11341 ? "None"
11342 : sockunion2str(&p->su, buf,
11343 SU_ADDRSTRLEN));
11344 else /* Configured IP address. */
11345 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
11346 p->host);
11347 }
11348
11349 if (use_json) {
11350 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
11351 json_object_string_add(json_neigh, "bgpNeighborAddr",
11352 "none");
11353 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
11354 json_object_string_add(
11355 json_neigh, "bgpNeighborAddr",
11356 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
11357
11358 json_object_int_add(json_neigh, "remoteAs", p->as);
11359
11360 if (p->change_local_as)
11361 json_object_int_add(json_neigh, "localAs",
11362 p->change_local_as);
11363 else
11364 json_object_int_add(json_neigh, "localAs", p->local_as);
11365
11366 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
11367 json_object_boolean_true_add(json_neigh,
11368 "localAsNoPrepend");
11369
11370 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
11371 json_object_boolean_true_add(json_neigh,
11372 "localAsReplaceAs");
11373 } else {
11374 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
11375 || (p->as_type == AS_INTERNAL))
11376 vty_out(vty, "remote AS %u, ", p->as);
11377 else
11378 vty_out(vty, "remote AS Unspecified, ");
11379 vty_out(vty, "local AS %u%s%s, ",
11380 p->change_local_as ? p->change_local_as : p->local_as,
11381 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
11382 ? " no-prepend"
11383 : "",
11384 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
11385 ? " replace-as"
11386 : "");
11387 }
11388 /* peer type internal or confed-internal */
11389 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
11390 if (use_json) {
11391 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
11392 json_object_boolean_true_add(
11393 json_neigh, "nbrConfedInternalLink");
11394 else
11395 json_object_boolean_true_add(json_neigh,
11396 "nbrInternalLink");
11397 } else {
11398 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
11399 vty_out(vty, "confed-internal link\n");
11400 else
11401 vty_out(vty, "internal link\n");
11402 }
11403 /* peer type external or confed-external */
11404 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
11405 if (use_json) {
11406 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
11407 json_object_boolean_true_add(
11408 json_neigh, "nbrConfedExternalLink");
11409 else
11410 json_object_boolean_true_add(json_neigh,
11411 "nbrExternalLink");
11412 } else {
11413 if (bgp_confederation_peers_check(bgp, p->as))
11414 vty_out(vty, "confed-external link\n");
11415 else
11416 vty_out(vty, "external link\n");
11417 }
11418 } else {
11419 if (use_json)
11420 json_object_boolean_true_add(json_neigh,
11421 "nbrUnspecifiedLink");
11422 else
11423 vty_out(vty, "unspecified link\n");
11424 }
11425
11426 /* Description. */
11427 if (p->desc) {
11428 if (use_json)
11429 json_object_string_add(json_neigh, "nbrDesc", p->desc);
11430 else
11431 vty_out(vty, " Description: %s\n", p->desc);
11432 }
11433
11434 if (p->hostname) {
11435 if (use_json) {
11436 if (p->hostname)
11437 json_object_string_add(json_neigh, "hostname",
11438 p->hostname);
11439
11440 if (p->domainname)
11441 json_object_string_add(json_neigh, "domainname",
11442 p->domainname);
11443 } else {
11444 if (p->domainname && (p->domainname[0] != '\0'))
11445 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
11446 p->domainname);
11447 else
11448 vty_out(vty, "Hostname: %s\n", p->hostname);
11449 }
11450 }
11451
11452 /* Peer-group */
11453 if (p->group) {
11454 if (use_json) {
11455 json_object_string_add(json_neigh, "peerGroup",
11456 p->group->name);
11457
11458 if (dn_flag[0]) {
11459 struct prefix prefix, *range = NULL;
11460
11461 sockunion2hostprefix(&(p->su), &prefix);
11462 range = peer_group_lookup_dynamic_neighbor_range(
11463 p->group, &prefix);
11464
11465 if (range) {
11466 prefix2str(range, buf1, sizeof(buf1));
11467 json_object_string_add(
11468 json_neigh,
11469 "peerSubnetRangeGroup", buf1);
11470 }
11471 }
11472 } else {
11473 vty_out(vty,
11474 " Member of peer-group %s for session parameters\n",
11475 p->group->name);
11476
11477 if (dn_flag[0]) {
11478 struct prefix prefix, *range = NULL;
11479
11480 sockunion2hostprefix(&(p->su), &prefix);
11481 range = peer_group_lookup_dynamic_neighbor_range(
11482 p->group, &prefix);
11483
11484 if (range) {
11485 vty_out(vty,
11486 " Belongs to the subnet range group: %pFX\n",
11487 range);
11488 }
11489 }
11490 }
11491 }
11492
11493 if (use_json) {
11494 /* Administrative shutdown. */
11495 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
11496 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
11497 json_object_boolean_true_add(json_neigh,
11498 "adminShutDown");
11499
11500 /* BGP Version. */
11501 json_object_int_add(json_neigh, "bgpVersion", 4);
11502 json_object_string_add(
11503 json_neigh, "remoteRouterId",
11504 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
11505 json_object_string_add(
11506 json_neigh, "localRouterId",
11507 inet_ntop(AF_INET, &bgp->router_id, buf1,
11508 sizeof(buf1)));
11509
11510 /* Confederation */
11511 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
11512 && bgp_confederation_peers_check(bgp, p->as))
11513 json_object_boolean_true_add(json_neigh,
11514 "nbrCommonAdmin");
11515
11516 /* Status. */
11517 json_object_string_add(
11518 json_neigh, "bgpState",
11519 lookup_msg(bgp_status_msg, p->status, NULL));
11520
11521 if (p->status == Established) {
11522 time_t uptime;
11523
11524 uptime = bgp_clock();
11525 uptime -= p->uptime;
11526 epoch_tbuf = time(NULL) - uptime;
11527
11528 json_object_int_add(json_neigh, "bgpTimerUpMsec",
11529 uptime * 1000);
11530 json_object_string_add(json_neigh, "bgpTimerUpString",
11531 peer_uptime(p->uptime, timebuf,
11532 BGP_UPTIME_LEN, 0,
11533 NULL));
11534 json_object_int_add(json_neigh,
11535 "bgpTimerUpEstablishedEpoch",
11536 epoch_tbuf);
11537 }
11538
11539 else if (p->status == Active) {
11540 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
11541 json_object_string_add(json_neigh, "bgpStateIs",
11542 "passive");
11543 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
11544 json_object_string_add(json_neigh, "bgpStateIs",
11545 "passiveNSF");
11546 }
11547
11548 /* read timer */
11549 time_t uptime;
11550 struct tm tm;
11551
11552 uptime = bgp_clock();
11553 uptime -= p->readtime;
11554 gmtime_r(&uptime, &tm);
11555
11556 json_object_int_add(json_neigh, "bgpTimerLastRead",
11557 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
11558 + (tm.tm_hour * 3600000));
11559
11560 uptime = bgp_clock();
11561 uptime -= p->last_write;
11562 gmtime_r(&uptime, &tm);
11563
11564 json_object_int_add(json_neigh, "bgpTimerLastWrite",
11565 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
11566 + (tm.tm_hour * 3600000));
11567
11568 uptime = bgp_clock();
11569 uptime -= p->update_time;
11570 gmtime_r(&uptime, &tm);
11571
11572 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
11573 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
11574 + (tm.tm_hour * 3600000));
11575
11576 /* Configured timer values. */
11577 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
11578 p->v_holdtime * 1000);
11579 json_object_int_add(json_neigh,
11580 "bgpTimerKeepAliveIntervalMsecs",
11581 p->v_keepalive * 1000);
11582 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
11583 json_object_int_add(json_neigh,
11584 "bgpTimerConfiguredHoldTimeMsecs",
11585 p->holdtime * 1000);
11586 json_object_int_add(
11587 json_neigh,
11588 "bgpTimerConfiguredKeepAliveIntervalMsecs",
11589 p->keepalive * 1000);
11590 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
11591 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
11592 json_object_int_add(json_neigh,
11593 "bgpTimerConfiguredHoldTimeMsecs",
11594 bgp->default_holdtime);
11595 json_object_int_add(
11596 json_neigh,
11597 "bgpTimerConfiguredKeepAliveIntervalMsecs",
11598 bgp->default_keepalive);
11599 }
11600 } else {
11601 /* Administrative shutdown. */
11602 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
11603 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
11604 vty_out(vty, " Administratively shut down\n");
11605
11606 /* BGP Version. */
11607 vty_out(vty, " BGP version 4");
11608 vty_out(vty, ", remote router ID %s",
11609 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
11610 vty_out(vty, ", local router ID %s\n",
11611 inet_ntop(AF_INET, &bgp->router_id, buf1,
11612 sizeof(buf1)));
11613
11614 /* Confederation */
11615 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
11616 && bgp_confederation_peers_check(bgp, p->as))
11617 vty_out(vty,
11618 " Neighbor under common administration\n");
11619
11620 /* Status. */
11621 vty_out(vty, " BGP state = %s",
11622 lookup_msg(bgp_status_msg, p->status, NULL));
11623
11624 if (p->status == Established)
11625 vty_out(vty, ", up for %8s",
11626 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
11627 0, NULL));
11628
11629 else if (p->status == Active) {
11630 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
11631 vty_out(vty, " (passive)");
11632 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
11633 vty_out(vty, " (NSF passive)");
11634 }
11635 vty_out(vty, "\n");
11636
11637 /* read timer */
11638 vty_out(vty, " Last read %s",
11639 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
11640 NULL));
11641 vty_out(vty, ", Last write %s\n",
11642 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
11643 NULL));
11644
11645 /* Configured timer values. */
11646 vty_out(vty,
11647 " Hold time is %d, keepalive interval is %d seconds\n",
11648 p->v_holdtime, p->v_keepalive);
11649 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
11650 vty_out(vty, " Configured hold time is %d",
11651 p->holdtime);
11652 vty_out(vty, ", keepalive interval is %d seconds\n",
11653 p->keepalive);
11654 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
11655 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
11656 vty_out(vty, " Configured hold time is %d",
11657 bgp->default_holdtime);
11658 vty_out(vty, ", keepalive interval is %d seconds\n",
11659 bgp->default_keepalive);
11660 }
11661 }
11662 /* Capability. */
11663 if (p->status == Established) {
11664 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
11665 || p->afc_recv[AFI_IP][SAFI_UNICAST]
11666 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
11667 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
11668 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
11669 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
11670 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
11671 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
11672 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
11673 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
11674 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
11675 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
11676 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
11677 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
11678 || p->afc_adv[AFI_IP][SAFI_ENCAP]
11679 || p->afc_recv[AFI_IP][SAFI_ENCAP]
11680 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
11681 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
11682 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
11683 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
11684 if (use_json) {
11685 json_object *json_cap = NULL;
11686
11687 json_cap = json_object_new_object();
11688
11689 /* AS4 */
11690 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
11691 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
11692 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
11693 && CHECK_FLAG(p->cap,
11694 PEER_CAP_AS4_RCV))
11695 json_object_string_add(
11696 json_cap, "4byteAs",
11697 "advertisedAndReceived");
11698 else if (CHECK_FLAG(p->cap,
11699 PEER_CAP_AS4_ADV))
11700 json_object_string_add(
11701 json_cap, "4byteAs",
11702 "advertised");
11703 else if (CHECK_FLAG(p->cap,
11704 PEER_CAP_AS4_RCV))
11705 json_object_string_add(
11706 json_cap, "4byteAs",
11707 "received");
11708 }
11709
11710 /* AddPath */
11711 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
11712 || CHECK_FLAG(p->cap,
11713 PEER_CAP_ADDPATH_ADV)) {
11714 json_object *json_add = NULL;
11715 const char *print_store;
11716
11717 json_add = json_object_new_object();
11718
11719 FOREACH_AFI_SAFI (afi, safi) {
11720 json_object *json_sub = NULL;
11721 json_sub =
11722 json_object_new_object();
11723 print_store = get_afi_safi_str(
11724 afi, safi, true);
11725
11726 if (CHECK_FLAG(
11727 p->af_cap[afi]
11728 [safi],
11729 PEER_CAP_ADDPATH_AF_TX_ADV)
11730 || CHECK_FLAG(
11731 p->af_cap[afi]
11732 [safi],
11733 PEER_CAP_ADDPATH_AF_TX_RCV)) {
11734 if (CHECK_FLAG(
11735 p->af_cap
11736 [afi]
11737 [safi],
11738 PEER_CAP_ADDPATH_AF_TX_ADV)
11739 && CHECK_FLAG(
11740 p->af_cap
11741 [afi]
11742 [safi],
11743 PEER_CAP_ADDPATH_AF_TX_RCV))
11744 json_object_boolean_true_add(
11745 json_sub,
11746 "txAdvertisedAndReceived");
11747 else if (
11748 CHECK_FLAG(
11749 p->af_cap
11750 [afi]
11751 [safi],
11752 PEER_CAP_ADDPATH_AF_TX_ADV))
11753 json_object_boolean_true_add(
11754 json_sub,
11755 "txAdvertised");
11756 else if (
11757 CHECK_FLAG(
11758 p->af_cap
11759 [afi]
11760 [safi],
11761 PEER_CAP_ADDPATH_AF_TX_RCV))
11762 json_object_boolean_true_add(
11763 json_sub,
11764 "txReceived");
11765 }
11766
11767 if (CHECK_FLAG(
11768 p->af_cap[afi]
11769 [safi],
11770 PEER_CAP_ADDPATH_AF_RX_ADV)
11771 || CHECK_FLAG(
11772 p->af_cap[afi]
11773 [safi],
11774 PEER_CAP_ADDPATH_AF_RX_RCV)) {
11775 if (CHECK_FLAG(
11776 p->af_cap
11777 [afi]
11778 [safi],
11779 PEER_CAP_ADDPATH_AF_RX_ADV)
11780 && CHECK_FLAG(
11781 p->af_cap
11782 [afi]
11783 [safi],
11784 PEER_CAP_ADDPATH_AF_RX_RCV))
11785 json_object_boolean_true_add(
11786 json_sub,
11787 "rxAdvertisedAndReceived");
11788 else if (
11789 CHECK_FLAG(
11790 p->af_cap
11791 [afi]
11792 [safi],
11793 PEER_CAP_ADDPATH_AF_RX_ADV))
11794 json_object_boolean_true_add(
11795 json_sub,
11796 "rxAdvertised");
11797 else if (
11798 CHECK_FLAG(
11799 p->af_cap
11800 [afi]
11801 [safi],
11802 PEER_CAP_ADDPATH_AF_RX_RCV))
11803 json_object_boolean_true_add(
11804 json_sub,
11805 "rxReceived");
11806 }
11807
11808 if (CHECK_FLAG(
11809 p->af_cap[afi]
11810 [safi],
11811 PEER_CAP_ADDPATH_AF_TX_ADV)
11812 || CHECK_FLAG(
11813 p->af_cap[afi]
11814 [safi],
11815 PEER_CAP_ADDPATH_AF_TX_RCV)
11816 || CHECK_FLAG(
11817 p->af_cap[afi]
11818 [safi],
11819 PEER_CAP_ADDPATH_AF_RX_ADV)
11820 || CHECK_FLAG(
11821 p->af_cap[afi]
11822 [safi],
11823 PEER_CAP_ADDPATH_AF_RX_RCV))
11824 json_object_object_add(
11825 json_add,
11826 print_store,
11827 json_sub);
11828 else
11829 json_object_free(
11830 json_sub);
11831 }
11832
11833 json_object_object_add(
11834 json_cap, "addPath", json_add);
11835 }
11836
11837 /* Dynamic */
11838 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
11839 || CHECK_FLAG(p->cap,
11840 PEER_CAP_DYNAMIC_ADV)) {
11841 if (CHECK_FLAG(p->cap,
11842 PEER_CAP_DYNAMIC_ADV)
11843 && CHECK_FLAG(p->cap,
11844 PEER_CAP_DYNAMIC_RCV))
11845 json_object_string_add(
11846 json_cap, "dynamic",
11847 "advertisedAndReceived");
11848 else if (CHECK_FLAG(
11849 p->cap,
11850 PEER_CAP_DYNAMIC_ADV))
11851 json_object_string_add(
11852 json_cap, "dynamic",
11853 "advertised");
11854 else if (CHECK_FLAG(
11855 p->cap,
11856 PEER_CAP_DYNAMIC_RCV))
11857 json_object_string_add(
11858 json_cap, "dynamic",
11859 "received");
11860 }
11861
11862 /* Extended nexthop */
11863 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
11864 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
11865 json_object *json_nxt = NULL;
11866 const char *print_store;
11867
11868
11869 if (CHECK_FLAG(p->cap,
11870 PEER_CAP_ENHE_ADV)
11871 && CHECK_FLAG(p->cap,
11872 PEER_CAP_ENHE_RCV))
11873 json_object_string_add(
11874 json_cap,
11875 "extendedNexthop",
11876 "advertisedAndReceived");
11877 else if (CHECK_FLAG(p->cap,
11878 PEER_CAP_ENHE_ADV))
11879 json_object_string_add(
11880 json_cap,
11881 "extendedNexthop",
11882 "advertised");
11883 else if (CHECK_FLAG(p->cap,
11884 PEER_CAP_ENHE_RCV))
11885 json_object_string_add(
11886 json_cap,
11887 "extendedNexthop",
11888 "received");
11889
11890 if (CHECK_FLAG(p->cap,
11891 PEER_CAP_ENHE_RCV)) {
11892 json_nxt =
11893 json_object_new_object();
11894
11895 for (safi = SAFI_UNICAST;
11896 safi < SAFI_MAX; safi++) {
11897 if (CHECK_FLAG(
11898 p->af_cap
11899 [AFI_IP]
11900 [safi],
11901 PEER_CAP_ENHE_AF_RCV)) {
11902 print_store = get_afi_safi_str(
11903 AFI_IP,
11904 safi, true);
11905 json_object_string_add(
11906 json_nxt,
11907 print_store,
11908 "recieved"); /* misspelled for compatibility */
11909 }
11910 }
11911 json_object_object_add(
11912 json_cap,
11913 "extendedNexthopFamililesByPeer",
11914 json_nxt);
11915 }
11916 }
11917
11918 /* Route Refresh */
11919 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
11920 || CHECK_FLAG(p->cap,
11921 PEER_CAP_REFRESH_NEW_RCV)
11922 || CHECK_FLAG(p->cap,
11923 PEER_CAP_REFRESH_OLD_RCV)) {
11924 if (CHECK_FLAG(p->cap,
11925 PEER_CAP_REFRESH_ADV)
11926 && (CHECK_FLAG(
11927 p->cap,
11928 PEER_CAP_REFRESH_NEW_RCV)
11929 || CHECK_FLAG(
11930 p->cap,
11931 PEER_CAP_REFRESH_OLD_RCV))) {
11932 if (CHECK_FLAG(
11933 p->cap,
11934 PEER_CAP_REFRESH_OLD_RCV)
11935 && CHECK_FLAG(
11936 p->cap,
11937 PEER_CAP_REFRESH_NEW_RCV))
11938 json_object_string_add(
11939 json_cap,
11940 "routeRefresh",
11941 "advertisedAndReceivedOldNew");
11942 else {
11943 if (CHECK_FLAG(
11944 p->cap,
11945 PEER_CAP_REFRESH_OLD_RCV))
11946 json_object_string_add(
11947 json_cap,
11948 "routeRefresh",
11949 "advertisedAndReceivedOld");
11950 else
11951 json_object_string_add(
11952 json_cap,
11953 "routeRefresh",
11954 "advertisedAndReceivedNew");
11955 }
11956 } else if (
11957 CHECK_FLAG(
11958 p->cap,
11959 PEER_CAP_REFRESH_ADV))
11960 json_object_string_add(
11961 json_cap,
11962 "routeRefresh",
11963 "advertised");
11964 else if (
11965 CHECK_FLAG(
11966 p->cap,
11967 PEER_CAP_REFRESH_NEW_RCV)
11968 || CHECK_FLAG(
11969 p->cap,
11970 PEER_CAP_REFRESH_OLD_RCV))
11971 json_object_string_add(
11972 json_cap,
11973 "routeRefresh",
11974 "received");
11975 }
11976
11977 /* Multiprotocol Extensions */
11978 json_object *json_multi = NULL;
11979 json_multi = json_object_new_object();
11980
11981 FOREACH_AFI_SAFI (afi, safi) {
11982 if (p->afc_adv[afi][safi]
11983 || p->afc_recv[afi][safi]) {
11984 json_object *json_exten = NULL;
11985 json_exten =
11986 json_object_new_object();
11987
11988 if (p->afc_adv[afi][safi]
11989 && p->afc_recv[afi][safi])
11990 json_object_boolean_true_add(
11991 json_exten,
11992 "advertisedAndReceived");
11993 else if (p->afc_adv[afi][safi])
11994 json_object_boolean_true_add(
11995 json_exten,
11996 "advertised");
11997 else if (p->afc_recv[afi][safi])
11998 json_object_boolean_true_add(
11999 json_exten,
12000 "received");
12001
12002 json_object_object_add(
12003 json_multi,
12004 get_afi_safi_str(afi,
12005 safi,
12006 true),
12007 json_exten);
12008 }
12009 }
12010 json_object_object_add(
12011 json_cap, "multiprotocolExtensions",
12012 json_multi);
12013
12014 /* Hostname capabilities */
12015 json_object *json_hname = NULL;
12016
12017 json_hname = json_object_new_object();
12018
12019 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
12020 json_object_string_add(
12021 json_hname, "advHostName",
12022 bgp->peer_self->hostname
12023 ? bgp->peer_self
12024 ->hostname
12025 : "n/a");
12026 json_object_string_add(
12027 json_hname, "advDomainName",
12028 bgp->peer_self->domainname
12029 ? bgp->peer_self
12030 ->domainname
12031 : "n/a");
12032 }
12033
12034
12035 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
12036 json_object_string_add(
12037 json_hname, "rcvHostName",
12038 p->hostname ? p->hostname
12039 : "n/a");
12040 json_object_string_add(
12041 json_hname, "rcvDomainName",
12042 p->domainname ? p->domainname
12043 : "n/a");
12044 }
12045
12046 json_object_object_add(json_cap, "hostName",
12047 json_hname);
12048
12049 /* Gracefull Restart */
12050 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
12051 || CHECK_FLAG(p->cap,
12052 PEER_CAP_RESTART_ADV)) {
12053 if (CHECK_FLAG(p->cap,
12054 PEER_CAP_RESTART_ADV)
12055 && CHECK_FLAG(p->cap,
12056 PEER_CAP_RESTART_RCV))
12057 json_object_string_add(
12058 json_cap,
12059 "gracefulRestart",
12060 "advertisedAndReceived");
12061 else if (CHECK_FLAG(
12062 p->cap,
12063 PEER_CAP_RESTART_ADV))
12064 json_object_string_add(
12065 json_cap,
12066 "gracefulRestartCapability",
12067 "advertised");
12068 else if (CHECK_FLAG(
12069 p->cap,
12070 PEER_CAP_RESTART_RCV))
12071 json_object_string_add(
12072 json_cap,
12073 "gracefulRestartCapability",
12074 "received");
12075
12076 if (CHECK_FLAG(p->cap,
12077 PEER_CAP_RESTART_RCV)) {
12078 int restart_af_count = 0;
12079 json_object *json_restart =
12080 NULL;
12081 json_restart =
12082 json_object_new_object();
12083
12084 json_object_int_add(
12085 json_cap,
12086 "gracefulRestartRemoteTimerMsecs",
12087 p->v_gr_restart * 1000);
12088
12089 FOREACH_AFI_SAFI (afi, safi) {
12090 if (CHECK_FLAG(
12091 p->af_cap
12092 [afi]
12093 [safi],
12094 PEER_CAP_RESTART_AF_RCV)) {
12095 json_object *
12096 json_sub =
12097 NULL;
12098 json_sub =
12099 json_object_new_object();
12100
12101 if (CHECK_FLAG(
12102 p->af_cap
12103 [afi]
12104 [safi],
12105 PEER_CAP_RESTART_AF_PRESERVE_RCV))
12106 json_object_boolean_true_add(
12107 json_sub,
12108 "preserved");
12109 restart_af_count++;
12110 json_object_object_add(
12111 json_restart,
12112 get_afi_safi_str(
12113 afi,
12114 safi,
12115 true),
12116 json_sub);
12117 }
12118 }
12119 if (!restart_af_count) {
12120 json_object_string_add(
12121 json_cap,
12122 "addressFamiliesByPeer",
12123 "none");
12124 json_object_free(
12125 json_restart);
12126 } else
12127 json_object_object_add(
12128 json_cap,
12129 "addressFamiliesByPeer",
12130 json_restart);
12131 }
12132 }
12133 json_object_object_add(json_neigh,
12134 "neighborCapabilities",
12135 json_cap);
12136 } else {
12137 vty_out(vty, " Neighbor capabilities:\n");
12138
12139 /* AS4 */
12140 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
12141 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
12142 vty_out(vty, " 4 Byte AS:");
12143 if (CHECK_FLAG(p->cap,
12144 PEER_CAP_AS4_ADV))
12145 vty_out(vty, " advertised");
12146 if (CHECK_FLAG(p->cap,
12147 PEER_CAP_AS4_RCV))
12148 vty_out(vty, " %sreceived",
12149 CHECK_FLAG(
12150 p->cap,
12151 PEER_CAP_AS4_ADV)
12152 ? "and "
12153 : "");
12154 vty_out(vty, "\n");
12155 }
12156
12157 /* AddPath */
12158 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
12159 || CHECK_FLAG(p->cap,
12160 PEER_CAP_ADDPATH_ADV)) {
12161 vty_out(vty, " AddPath:\n");
12162
12163 FOREACH_AFI_SAFI (afi, safi) {
12164 if (CHECK_FLAG(
12165 p->af_cap[afi]
12166 [safi],
12167 PEER_CAP_ADDPATH_AF_TX_ADV)
12168 || CHECK_FLAG(
12169 p->af_cap[afi]
12170 [safi],
12171 PEER_CAP_ADDPATH_AF_TX_RCV)) {
12172 vty_out(vty,
12173 " %s: TX ",
12174 get_afi_safi_str(
12175 afi,
12176 safi,
12177 false));
12178
12179 if (CHECK_FLAG(
12180 p->af_cap
12181 [afi]
12182 [safi],
12183 PEER_CAP_ADDPATH_AF_TX_ADV))
12184 vty_out(vty,
12185 "advertised %s",
12186 get_afi_safi_str(
12187 afi,
12188 safi,
12189 false));
12190
12191 if (CHECK_FLAG(
12192 p->af_cap
12193 [afi]
12194 [safi],
12195 PEER_CAP_ADDPATH_AF_TX_RCV))
12196 vty_out(vty,
12197 "%sreceived",
12198 CHECK_FLAG(
12199 p->af_cap
12200 [afi]
12201 [safi],
12202 PEER_CAP_ADDPATH_AF_TX_ADV)
12203 ? " and "
12204 : "");
12205
12206 vty_out(vty, "\n");
12207 }
12208
12209 if (CHECK_FLAG(
12210 p->af_cap[afi]
12211 [safi],
12212 PEER_CAP_ADDPATH_AF_RX_ADV)
12213 || CHECK_FLAG(
12214 p->af_cap[afi]
12215 [safi],
12216 PEER_CAP_ADDPATH_AF_RX_RCV)) {
12217 vty_out(vty,
12218 " %s: RX ",
12219 get_afi_safi_str(
12220 afi,
12221 safi,
12222 false));
12223
12224 if (CHECK_FLAG(
12225 p->af_cap
12226 [afi]
12227 [safi],
12228 PEER_CAP_ADDPATH_AF_RX_ADV))
12229 vty_out(vty,
12230 "advertised %s",
12231 get_afi_safi_str(
12232 afi,
12233 safi,
12234 false));
12235
12236 if (CHECK_FLAG(
12237 p->af_cap
12238 [afi]
12239 [safi],
12240 PEER_CAP_ADDPATH_AF_RX_RCV))
12241 vty_out(vty,
12242 "%sreceived",
12243 CHECK_FLAG(
12244 p->af_cap
12245 [afi]
12246 [safi],
12247 PEER_CAP_ADDPATH_AF_RX_ADV)
12248 ? " and "
12249 : "");
12250
12251 vty_out(vty, "\n");
12252 }
12253 }
12254 }
12255
12256 /* Dynamic */
12257 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
12258 || CHECK_FLAG(p->cap,
12259 PEER_CAP_DYNAMIC_ADV)) {
12260 vty_out(vty, " Dynamic:");
12261 if (CHECK_FLAG(p->cap,
12262 PEER_CAP_DYNAMIC_ADV))
12263 vty_out(vty, " advertised");
12264 if (CHECK_FLAG(p->cap,
12265 PEER_CAP_DYNAMIC_RCV))
12266 vty_out(vty, " %sreceived",
12267 CHECK_FLAG(
12268 p->cap,
12269 PEER_CAP_DYNAMIC_ADV)
12270 ? "and "
12271 : "");
12272 vty_out(vty, "\n");
12273 }
12274
12275 /* Extended nexthop */
12276 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
12277 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
12278 vty_out(vty, " Extended nexthop:");
12279 if (CHECK_FLAG(p->cap,
12280 PEER_CAP_ENHE_ADV))
12281 vty_out(vty, " advertised");
12282 if (CHECK_FLAG(p->cap,
12283 PEER_CAP_ENHE_RCV))
12284 vty_out(vty, " %sreceived",
12285 CHECK_FLAG(
12286 p->cap,
12287 PEER_CAP_ENHE_ADV)
12288 ? "and "
12289 : "");
12290 vty_out(vty, "\n");
12291
12292 if (CHECK_FLAG(p->cap,
12293 PEER_CAP_ENHE_RCV)) {
12294 vty_out(vty,
12295 " Address families by peer:\n ");
12296 for (safi = SAFI_UNICAST;
12297 safi < SAFI_MAX; safi++)
12298 if (CHECK_FLAG(
12299 p->af_cap
12300 [AFI_IP]
12301 [safi],
12302 PEER_CAP_ENHE_AF_RCV))
12303 vty_out(vty,
12304 " %s\n",
12305 get_afi_safi_str(
12306 AFI_IP,
12307 safi,
12308 false));
12309 }
12310 }
12311
12312 /* Route Refresh */
12313 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
12314 || CHECK_FLAG(p->cap,
12315 PEER_CAP_REFRESH_NEW_RCV)
12316 || CHECK_FLAG(p->cap,
12317 PEER_CAP_REFRESH_OLD_RCV)) {
12318 vty_out(vty, " Route refresh:");
12319 if (CHECK_FLAG(p->cap,
12320 PEER_CAP_REFRESH_ADV))
12321 vty_out(vty, " advertised");
12322 if (CHECK_FLAG(p->cap,
12323 PEER_CAP_REFRESH_NEW_RCV)
12324 || CHECK_FLAG(
12325 p->cap,
12326 PEER_CAP_REFRESH_OLD_RCV))
12327 vty_out(vty, " %sreceived(%s)",
12328 CHECK_FLAG(
12329 p->cap,
12330 PEER_CAP_REFRESH_ADV)
12331 ? "and "
12332 : "",
12333 (CHECK_FLAG(
12334 p->cap,
12335 PEER_CAP_REFRESH_OLD_RCV)
12336 && CHECK_FLAG(
12337 p->cap,
12338 PEER_CAP_REFRESH_NEW_RCV))
12339 ? "old & new"
12340 : CHECK_FLAG(
12341 p->cap,
12342 PEER_CAP_REFRESH_OLD_RCV)
12343 ? "old"
12344 : "new");
12345
12346 vty_out(vty, "\n");
12347 }
12348
12349 /* Multiprotocol Extensions */
12350 FOREACH_AFI_SAFI (afi, safi)
12351 if (p->afc_adv[afi][safi]
12352 || p->afc_recv[afi][safi]) {
12353 vty_out(vty,
12354 " Address Family %s:",
12355 get_afi_safi_str(
12356 afi,
12357 safi,
12358 false));
12359 if (p->afc_adv[afi][safi])
12360 vty_out(vty,
12361 " advertised");
12362 if (p->afc_recv[afi][safi])
12363 vty_out(vty,
12364 " %sreceived",
12365 p->afc_adv[afi]
12366 [safi]
12367 ? "and "
12368 : "");
12369 vty_out(vty, "\n");
12370 }
12371
12372 /* Hostname capability */
12373 vty_out(vty, " Hostname Capability:");
12374
12375 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
12376 vty_out(vty,
12377 " advertised (name: %s,domain name: %s)",
12378 bgp->peer_self->hostname
12379 ? bgp->peer_self
12380 ->hostname
12381 : "n/a",
12382 bgp->peer_self->domainname
12383 ? bgp->peer_self
12384 ->domainname
12385 : "n/a");
12386 } else {
12387 vty_out(vty, " not advertised");
12388 }
12389
12390 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
12391 vty_out(vty,
12392 " received (name: %s,domain name: %s)",
12393 p->hostname ? p->hostname
12394 : "n/a",
12395 p->domainname ? p->domainname
12396 : "n/a");
12397 } else {
12398 vty_out(vty, " not received");
12399 }
12400
12401 vty_out(vty, "\n");
12402
12403 /* Graceful Restart */
12404 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
12405 || CHECK_FLAG(p->cap,
12406 PEER_CAP_RESTART_ADV)) {
12407 vty_out(vty,
12408 " Graceful Restart Capability:");
12409 if (CHECK_FLAG(p->cap,
12410 PEER_CAP_RESTART_ADV))
12411 vty_out(vty, " advertised");
12412 if (CHECK_FLAG(p->cap,
12413 PEER_CAP_RESTART_RCV))
12414 vty_out(vty, " %sreceived",
12415 CHECK_FLAG(
12416 p->cap,
12417 PEER_CAP_RESTART_ADV)
12418 ? "and "
12419 : "");
12420 vty_out(vty, "\n");
12421
12422 if (CHECK_FLAG(p->cap,
12423 PEER_CAP_RESTART_RCV)) {
12424 int restart_af_count = 0;
12425
12426 vty_out(vty,
12427 " Remote Restart timer is %d seconds\n",
12428 p->v_gr_restart);
12429 vty_out(vty,
12430 " Address families by peer:\n ");
12431
12432 FOREACH_AFI_SAFI (afi, safi)
12433 if (CHECK_FLAG(
12434 p->af_cap
12435 [afi]
12436 [safi],
12437 PEER_CAP_RESTART_AF_RCV)) {
12438 vty_out(vty,
12439 "%s%s(%s)",
12440 restart_af_count
12441 ? ", "
12442 : "",
12443 get_afi_safi_str(
12444 afi,
12445 safi,
12446 false),
12447 CHECK_FLAG(
12448 p->af_cap
12449 [afi]
12450 [safi],
12451 PEER_CAP_RESTART_AF_PRESERVE_RCV)
12452 ? "preserved"
12453 : "not preserved");
12454 restart_af_count++;
12455 }
12456 if (!restart_af_count)
12457 vty_out(vty, "none");
12458 vty_out(vty, "\n");
12459 }
12460 } /* Gracefull Restart */
12461 }
12462 }
12463 }
12464
12465 /* graceful restart information */
12466 json_object *json_grace = NULL;
12467 json_object *json_grace_send = NULL;
12468 json_object *json_grace_recv = NULL;
12469 int eor_send_af_count = 0;
12470 int eor_receive_af_count = 0;
12471
12472 if (use_json) {
12473 json_grace = json_object_new_object();
12474 json_grace_send = json_object_new_object();
12475 json_grace_recv = json_object_new_object();
12476
12477 if ((p->status == Established)
12478 && CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
12479 FOREACH_AFI_SAFI (afi, safi) {
12480 if (CHECK_FLAG(p->af_sflags[afi][safi],
12481 PEER_STATUS_EOR_SEND)) {
12482 json_object_boolean_true_add(
12483 json_grace_send,
12484 get_afi_safi_str(afi,
12485 safi,
12486 true));
12487 eor_send_af_count++;
12488 }
12489 }
12490 FOREACH_AFI_SAFI (afi, safi) {
12491 if (CHECK_FLAG(
12492 p->af_sflags[afi][safi],
12493 PEER_STATUS_EOR_RECEIVED)) {
12494 json_object_boolean_true_add(
12495 json_grace_recv,
12496 get_afi_safi_str(afi,
12497 safi,
12498 true));
12499 eor_receive_af_count++;
12500 }
12501 }
12502 }
12503 json_object_object_add(json_grace, "endOfRibSend",
12504 json_grace_send);
12505 json_object_object_add(json_grace, "endOfRibRecv",
12506 json_grace_recv);
12507
12508
12509 if (p->t_gr_restart)
12510 json_object_int_add(json_grace,
12511 "gracefulRestartTimerMsecs",
12512 thread_timer_remain_second(
12513 p->t_gr_restart)
12514 * 1000);
12515
12516 if (p->t_gr_stale)
12517 json_object_int_add(
12518 json_grace,
12519 "gracefulStalepathTimerMsecs",
12520 thread_timer_remain_second(
12521 p->t_gr_stale)
12522 * 1000);
12523 /* more gr info in new format */
12524 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json,
12525 json_grace);
12526 json_object_object_add(
12527 json_neigh, "gracefulRestartInfo", json_grace);
12528 } else {
12529 vty_out(vty, " Graceful restart information:\n");
12530 if ((p->status == Established)
12531 && CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
12532
12533 vty_out(vty, " End-of-RIB send: ");
12534 FOREACH_AFI_SAFI (afi, safi) {
12535 if (CHECK_FLAG(p->af_sflags[afi][safi],
12536 PEER_STATUS_EOR_SEND)) {
12537 vty_out(vty, "%s%s",
12538 eor_send_af_count ? ", "
12539 : "",
12540 get_afi_safi_str(
12541 afi, safi,
12542 false));
12543 eor_send_af_count++;
12544 }
12545 }
12546 vty_out(vty, "\n");
12547 vty_out(vty, " End-of-RIB received: ");
12548 FOREACH_AFI_SAFI (afi, safi) {
12549 if (CHECK_FLAG(
12550 p->af_sflags[afi][safi],
12551 PEER_STATUS_EOR_RECEIVED)) {
12552 vty_out(vty, "%s%s",
12553 eor_receive_af_count
12554 ? ", "
12555 : "",
12556 get_afi_safi_str(afi,
12557 safi,
12558 false));
12559 eor_receive_af_count++;
12560 }
12561 }
12562 vty_out(vty, "\n");
12563 }
12564
12565 if (p->t_gr_restart)
12566 vty_out(vty,
12567 " The remaining time of restart timer is %ld\n",
12568 thread_timer_remain_second(
12569 p->t_gr_restart));
12570
12571 if (p->t_gr_stale)
12572 vty_out(vty,
12573 " The remaining time of stalepath timer is %ld\n",
12574 thread_timer_remain_second(
12575 p->t_gr_stale));
12576
12577 /* more gr info in new format */
12578 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, NULL);
12579 }
12580
12581 if (use_json) {
12582 json_object *json_stat = NULL;
12583 json_stat = json_object_new_object();
12584 /* Packet counts. */
12585
12586 atomic_size_t outq_count, inq_count;
12587 outq_count = atomic_load_explicit(&p->obuf->count,
12588 memory_order_relaxed);
12589 inq_count = atomic_load_explicit(&p->ibuf->count,
12590 memory_order_relaxed);
12591
12592 json_object_int_add(json_stat, "depthInq",
12593 (unsigned long)inq_count);
12594 json_object_int_add(json_stat, "depthOutq",
12595 (unsigned long)outq_count);
12596 json_object_int_add(json_stat, "opensSent",
12597 atomic_load_explicit(&p->open_out,
12598 memory_order_relaxed));
12599 json_object_int_add(json_stat, "opensRecv",
12600 atomic_load_explicit(&p->open_in,
12601 memory_order_relaxed));
12602 json_object_int_add(json_stat, "notificationsSent",
12603 atomic_load_explicit(&p->notify_out,
12604 memory_order_relaxed));
12605 json_object_int_add(json_stat, "notificationsRecv",
12606 atomic_load_explicit(&p->notify_in,
12607 memory_order_relaxed));
12608 json_object_int_add(json_stat, "updatesSent",
12609 atomic_load_explicit(&p->update_out,
12610 memory_order_relaxed));
12611 json_object_int_add(json_stat, "updatesRecv",
12612 atomic_load_explicit(&p->update_in,
12613 memory_order_relaxed));
12614 json_object_int_add(json_stat, "keepalivesSent",
12615 atomic_load_explicit(&p->keepalive_out,
12616 memory_order_relaxed));
12617 json_object_int_add(json_stat, "keepalivesRecv",
12618 atomic_load_explicit(&p->keepalive_in,
12619 memory_order_relaxed));
12620 json_object_int_add(json_stat, "routeRefreshSent",
12621 atomic_load_explicit(&p->refresh_out,
12622 memory_order_relaxed));
12623 json_object_int_add(json_stat, "routeRefreshRecv",
12624 atomic_load_explicit(&p->refresh_in,
12625 memory_order_relaxed));
12626 json_object_int_add(json_stat, "capabilitySent",
12627 atomic_load_explicit(&p->dynamic_cap_out,
12628 memory_order_relaxed));
12629 json_object_int_add(json_stat, "capabilityRecv",
12630 atomic_load_explicit(&p->dynamic_cap_in,
12631 memory_order_relaxed));
12632 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
12633 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
12634 json_object_object_add(json_neigh, "messageStats", json_stat);
12635 } else {
12636 atomic_size_t outq_count, inq_count;
12637 outq_count = atomic_load_explicit(&p->obuf->count,
12638 memory_order_relaxed);
12639 inq_count = atomic_load_explicit(&p->ibuf->count,
12640 memory_order_relaxed);
12641
12642 /* Packet counts. */
12643 vty_out(vty, " Message statistics:\n");
12644 vty_out(vty, " Inq depth is %zu\n", inq_count);
12645 vty_out(vty, " Outq depth is %zu\n", outq_count);
12646 vty_out(vty, " Sent Rcvd\n");
12647 vty_out(vty, " Opens: %10d %10d\n",
12648 atomic_load_explicit(&p->open_out,
12649 memory_order_relaxed),
12650 atomic_load_explicit(&p->open_in,
12651 memory_order_relaxed));
12652 vty_out(vty, " Notifications: %10d %10d\n",
12653 atomic_load_explicit(&p->notify_out,
12654 memory_order_relaxed),
12655 atomic_load_explicit(&p->notify_in,
12656 memory_order_relaxed));
12657 vty_out(vty, " Updates: %10d %10d\n",
12658 atomic_load_explicit(&p->update_out,
12659 memory_order_relaxed),
12660 atomic_load_explicit(&p->update_in,
12661 memory_order_relaxed));
12662 vty_out(vty, " Keepalives: %10d %10d\n",
12663 atomic_load_explicit(&p->keepalive_out,
12664 memory_order_relaxed),
12665 atomic_load_explicit(&p->keepalive_in,
12666 memory_order_relaxed));
12667 vty_out(vty, " Route Refresh: %10d %10d\n",
12668 atomic_load_explicit(&p->refresh_out,
12669 memory_order_relaxed),
12670 atomic_load_explicit(&p->refresh_in,
12671 memory_order_relaxed));
12672 vty_out(vty, " Capability: %10d %10d\n",
12673 atomic_load_explicit(&p->dynamic_cap_out,
12674 memory_order_relaxed),
12675 atomic_load_explicit(&p->dynamic_cap_in,
12676 memory_order_relaxed));
12677 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
12678 PEER_TOTAL_RX(p));
12679 }
12680
12681 if (use_json) {
12682 /* advertisement-interval */
12683 json_object_int_add(json_neigh,
12684 "minBtwnAdvertisementRunsTimerMsecs",
12685 p->v_routeadv * 1000);
12686
12687 /* Update-source. */
12688 if (p->update_if || p->update_source) {
12689 if (p->update_if)
12690 json_object_string_add(json_neigh,
12691 "updateSource",
12692 p->update_if);
12693 else if (p->update_source)
12694 json_object_string_add(
12695 json_neigh, "updateSource",
12696 sockunion2str(p->update_source, buf1,
12697 SU_ADDRSTRLEN));
12698 }
12699 } else {
12700 /* advertisement-interval */
12701 vty_out(vty,
12702 " Minimum time between advertisement runs is %d seconds\n",
12703 p->v_routeadv);
12704
12705 /* Update-source. */
12706 if (p->update_if || p->update_source) {
12707 vty_out(vty, " Update source is ");
12708 if (p->update_if)
12709 vty_out(vty, "%s", p->update_if);
12710 else if (p->update_source)
12711 vty_out(vty, "%s",
12712 sockunion2str(p->update_source, buf1,
12713 SU_ADDRSTRLEN));
12714 vty_out(vty, "\n");
12715 }
12716
12717 vty_out(vty, "\n");
12718 }
12719
12720 /* Address Family Information */
12721 json_object *json_hold = NULL;
12722
12723 if (use_json)
12724 json_hold = json_object_new_object();
12725
12726 FOREACH_AFI_SAFI (afi, safi)
12727 if (p->afc[afi][safi])
12728 bgp_show_peer_afi(vty, p, afi, safi, use_json,
12729 json_hold);
12730
12731 if (use_json) {
12732 json_object_object_add(json_neigh, "addressFamilyInfo",
12733 json_hold);
12734 json_object_int_add(json_neigh, "connectionsEstablished",
12735 p->established);
12736 json_object_int_add(json_neigh, "connectionsDropped",
12737 p->dropped);
12738 } else
12739 vty_out(vty, " Connections established %d; dropped %d\n",
12740 p->established, p->dropped);
12741
12742 if (!p->last_reset) {
12743 if (use_json)
12744 json_object_string_add(json_neigh, "lastReset",
12745 "never");
12746 else
12747 vty_out(vty, " Last reset never\n");
12748 } else {
12749 if (use_json) {
12750 time_t uptime;
12751 struct tm tm;
12752
12753 uptime = bgp_clock();
12754 uptime -= p->resettime;
12755 gmtime_r(&uptime, &tm);
12756
12757 json_object_int_add(json_neigh, "lastResetTimerMsecs",
12758 (tm.tm_sec * 1000)
12759 + (tm.tm_min * 60000)
12760 + (tm.tm_hour * 3600000));
12761 bgp_show_peer_reset(NULL, p, json_neigh, true);
12762 } else {
12763 vty_out(vty, " Last reset %s, ",
12764 peer_uptime(p->resettime, timebuf,
12765 BGP_UPTIME_LEN, 0, NULL));
12766
12767 bgp_show_peer_reset(vty, p, NULL, false);
12768 if (p->last_reset_cause_size) {
12769 msg = p->last_reset_cause;
12770 vty_out(vty,
12771 " Message received that caused BGP to send a NOTIFICATION:\n ");
12772 for (i = 1; i <= p->last_reset_cause_size;
12773 i++) {
12774 vty_out(vty, "%02X", *msg++);
12775
12776 if (i != p->last_reset_cause_size) {
12777 if (i % 16 == 0) {
12778 vty_out(vty, "\n ");
12779 } else if (i % 4 == 0) {
12780 vty_out(vty, " ");
12781 }
12782 }
12783 }
12784 vty_out(vty, "\n");
12785 }
12786 }
12787 }
12788
12789 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
12790 if (use_json)
12791 json_object_boolean_true_add(json_neigh,
12792 "prefixesConfigExceedMax");
12793 else
12794 vty_out(vty,
12795 " Peer had exceeded the max. no. of prefixes configured.\n");
12796
12797 if (p->t_pmax_restart) {
12798 if (use_json) {
12799 json_object_boolean_true_add(
12800 json_neigh, "reducePrefixNumFrom");
12801 json_object_int_add(json_neigh,
12802 "restartInTimerMsec",
12803 thread_timer_remain_second(
12804 p->t_pmax_restart)
12805 * 1000);
12806 } else
12807 vty_out(vty,
12808 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
12809 p->host, thread_timer_remain_second(
12810 p->t_pmax_restart));
12811 } else {
12812 if (use_json)
12813 json_object_boolean_true_add(
12814 json_neigh,
12815 "reducePrefixNumAndClearIpBgp");
12816 else
12817 vty_out(vty,
12818 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
12819 p->host);
12820 }
12821 }
12822
12823 /* EBGP Multihop and GTSM */
12824 if (p->sort != BGP_PEER_IBGP) {
12825 if (use_json) {
12826 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
12827 json_object_int_add(json_neigh,
12828 "externalBgpNbrMaxHopsAway",
12829 p->gtsm_hops);
12830 else if (p->ttl > BGP_DEFAULT_TTL)
12831 json_object_int_add(json_neigh,
12832 "externalBgpNbrMaxHopsAway",
12833 p->ttl);
12834 } else {
12835 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
12836 vty_out(vty,
12837 " External BGP neighbor may be up to %d hops away.\n",
12838 p->gtsm_hops);
12839 else if (p->ttl > BGP_DEFAULT_TTL)
12840 vty_out(vty,
12841 " External BGP neighbor may be up to %d hops away.\n",
12842 p->ttl);
12843 }
12844 } else {
12845 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED) {
12846 if (use_json)
12847 json_object_int_add(json_neigh,
12848 "internalBgpNbrMaxHopsAway",
12849 p->gtsm_hops);
12850 else
12851 vty_out(vty,
12852 " Internal BGP neighbor may be up to %d hops away.\n",
12853 p->gtsm_hops);
12854 }
12855 }
12856
12857 /* Local address. */
12858 if (p->su_local) {
12859 if (use_json) {
12860 json_object_string_add(json_neigh, "hostLocal",
12861 sockunion2str(p->su_local, buf1,
12862 SU_ADDRSTRLEN));
12863 json_object_int_add(json_neigh, "portLocal",
12864 ntohs(p->su_local->sin.sin_port));
12865 } else
12866 vty_out(vty, "Local host: %s, Local port: %d\n",
12867 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
12868 ntohs(p->su_local->sin.sin_port));
12869 }
12870
12871 /* Remote address. */
12872 if (p->su_remote) {
12873 if (use_json) {
12874 json_object_string_add(json_neigh, "hostForeign",
12875 sockunion2str(p->su_remote, buf1,
12876 SU_ADDRSTRLEN));
12877 json_object_int_add(json_neigh, "portForeign",
12878 ntohs(p->su_remote->sin.sin_port));
12879 } else
12880 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
12881 sockunion2str(p->su_remote, buf1,
12882 SU_ADDRSTRLEN),
12883 ntohs(p->su_remote->sin.sin_port));
12884 }
12885
12886 /* Nexthop display. */
12887 if (p->su_local) {
12888 if (use_json) {
12889 json_object_string_add(json_neigh, "nexthop",
12890 inet_ntop(AF_INET,
12891 &p->nexthop.v4, buf1,
12892 sizeof(buf1)));
12893 json_object_string_add(json_neigh, "nexthopGlobal",
12894 inet_ntop(AF_INET6,
12895 &p->nexthop.v6_global,
12896 buf1, sizeof(buf1)));
12897 json_object_string_add(json_neigh, "nexthopLocal",
12898 inet_ntop(AF_INET6,
12899 &p->nexthop.v6_local,
12900 buf1, sizeof(buf1)));
12901 if (p->shared_network)
12902 json_object_string_add(json_neigh,
12903 "bgpConnection",
12904 "sharedNetwork");
12905 else
12906 json_object_string_add(json_neigh,
12907 "bgpConnection",
12908 "nonSharedNetwork");
12909 } else {
12910 vty_out(vty, "Nexthop: %s\n",
12911 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
12912 sizeof(buf1)));
12913 vty_out(vty, "Nexthop global: %s\n",
12914 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
12915 sizeof(buf1)));
12916 vty_out(vty, "Nexthop local: %s\n",
12917 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
12918 sizeof(buf1)));
12919 vty_out(vty, "BGP connection: %s\n",
12920 p->shared_network ? "shared network"
12921 : "non shared network");
12922 }
12923 }
12924
12925 /* Timer information. */
12926 if (use_json) {
12927 json_object_int_add(json_neigh, "connectRetryTimer",
12928 p->v_connect);
12929 if (p->status == Established && p->rtt)
12930 json_object_int_add(json_neigh, "estimatedRttInMsecs",
12931 p->rtt);
12932 if (p->t_start)
12933 json_object_int_add(
12934 json_neigh, "nextStartTimerDueInMsecs",
12935 thread_timer_remain_second(p->t_start) * 1000);
12936 if (p->t_connect)
12937 json_object_int_add(
12938 json_neigh, "nextConnectTimerDueInMsecs",
12939 thread_timer_remain_second(p->t_connect)
12940 * 1000);
12941 if (p->t_routeadv) {
12942 json_object_int_add(json_neigh, "mraiInterval",
12943 p->v_routeadv);
12944 json_object_int_add(
12945 json_neigh, "mraiTimerExpireInMsecs",
12946 thread_timer_remain_second(p->t_routeadv)
12947 * 1000);
12948 }
12949 if (p->password)
12950 json_object_int_add(json_neigh, "authenticationEnabled",
12951 1);
12952
12953 if (p->t_read)
12954 json_object_string_add(json_neigh, "readThread", "on");
12955 else
12956 json_object_string_add(json_neigh, "readThread", "off");
12957
12958 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
12959 json_object_string_add(json_neigh, "writeThread", "on");
12960 else
12961 json_object_string_add(json_neigh, "writeThread",
12962 "off");
12963 } else {
12964 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
12965 p->v_connect);
12966 if (p->status == Established && p->rtt)
12967 vty_out(vty, "Estimated round trip time: %d ms\n",
12968 p->rtt);
12969 if (p->t_start)
12970 vty_out(vty, "Next start timer due in %ld seconds\n",
12971 thread_timer_remain_second(p->t_start));
12972 if (p->t_connect)
12973 vty_out(vty, "Next connect timer due in %ld seconds\n",
12974 thread_timer_remain_second(p->t_connect));
12975 if (p->t_routeadv)
12976 vty_out(vty,
12977 "MRAI (interval %u) timer expires in %ld seconds\n",
12978 p->v_routeadv,
12979 thread_timer_remain_second(p->t_routeadv));
12980 if (p->password)
12981 vty_out(vty, "Peer Authentication Enabled\n");
12982
12983 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
12984 p->t_read ? "on" : "off",
12985 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
12986 ? "on"
12987 : "off", p->fd);
12988 }
12989
12990 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
12991 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
12992 bgp_capability_vty_out(vty, p, use_json, json_neigh);
12993
12994 if (!use_json)
12995 vty_out(vty, "\n");
12996
12997 /* BFD information. */
12998 bgp_bfd_show_info(vty, p, use_json, json_neigh);
12999
13000 if (use_json) {
13001 if (p->conf_if) /* Configured interface name. */
13002 json_object_object_add(json, p->conf_if, json_neigh);
13003 else /* Configured IP address. */
13004 json_object_object_add(json, p->host, json_neigh);
13005 }
13006 }
13007
13008 static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
13009 enum show_type type,
13010 union sockunion *su,
13011 const char *conf_if, afi_t afi,
13012 bool use_json)
13013 {
13014 struct listnode *node, *nnode;
13015 struct peer *peer;
13016 int find = 0;
13017 safi_t safi = SAFI_UNICAST;
13018 json_object *json = NULL;
13019 json_object *json_neighbor = NULL;
13020
13021 if (use_json) {
13022 json = json_object_new_object();
13023 json_neighbor = json_object_new_object();
13024 }
13025
13026 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
13027
13028 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
13029 continue;
13030
13031 if ((peer->afc[afi][safi]) == 0)
13032 continue;
13033
13034 if (type == show_all) {
13035 bgp_show_peer_gr_status(vty, peer, use_json,
13036 json_neighbor);
13037
13038 if (use_json) {
13039 json_object_object_add(json, peer->host,
13040 json_neighbor);
13041 json_neighbor = NULL;
13042 }
13043
13044 } else if (type == show_peer) {
13045 if (conf_if) {
13046 if ((peer->conf_if
13047 && !strcmp(peer->conf_if, conf_if))
13048 || (peer->hostname
13049 && !strcmp(peer->hostname, conf_if))) {
13050 find = 1;
13051 bgp_show_peer_gr_status(vty, peer,
13052 use_json,
13053 json_neighbor);
13054 }
13055 } else {
13056 if (sockunion_same(&peer->su, su)) {
13057 find = 1;
13058 bgp_show_peer_gr_status(vty, peer,
13059 use_json,
13060 json_neighbor);
13061 }
13062 }
13063 if (use_json && find)
13064 json_object_object_add(json, peer->host,
13065 json_neighbor);
13066 }
13067
13068 if (find) {
13069 json_neighbor = NULL;
13070 break;
13071 }
13072 }
13073
13074 if (type == show_peer && !find) {
13075 if (use_json)
13076 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
13077 else
13078 vty_out(vty, "%% No such neighbor\n");
13079 }
13080 if (use_json) {
13081 vty_out(vty, "%s\n",
13082 json_object_to_json_string_ext(
13083 json, JSON_C_TO_STRING_PRETTY));
13084
13085 if (json_neighbor)
13086 json_object_free(json_neighbor);
13087 json_object_free(json);
13088 } else {
13089 vty_out(vty, "\n");
13090 }
13091
13092 return CMD_SUCCESS;
13093 }
13094
13095 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
13096 enum show_type type, union sockunion *su,
13097 const char *conf_if, bool use_json,
13098 json_object *json)
13099 {
13100 struct listnode *node, *nnode;
13101 struct peer *peer;
13102 int find = 0;
13103 bool nbr_output = false;
13104 afi_t afi = AFI_MAX;
13105 safi_t safi = SAFI_MAX;
13106
13107 if (type == show_ipv4_peer || type == show_ipv4_all) {
13108 afi = AFI_IP;
13109 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
13110 afi = AFI_IP6;
13111 }
13112
13113 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
13114 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
13115 continue;
13116
13117 switch (type) {
13118 case show_all:
13119 bgp_show_peer(vty, peer, use_json, json);
13120 nbr_output = true;
13121 break;
13122 case show_peer:
13123 if (conf_if) {
13124 if ((peer->conf_if
13125 && !strcmp(peer->conf_if, conf_if))
13126 || (peer->hostname
13127 && !strcmp(peer->hostname, conf_if))) {
13128 find = 1;
13129 bgp_show_peer(vty, peer, use_json,
13130 json);
13131 }
13132 } else {
13133 if (sockunion_same(&peer->su, su)) {
13134 find = 1;
13135 bgp_show_peer(vty, peer, use_json,
13136 json);
13137 }
13138 }
13139 break;
13140 case show_ipv4_peer:
13141 case show_ipv6_peer:
13142 FOREACH_SAFI (safi) {
13143 if (peer->afc[afi][safi]) {
13144 if (conf_if) {
13145 if ((peer->conf_if
13146 && !strcmp(peer->conf_if, conf_if))
13147 || (peer->hostname
13148 && !strcmp(peer->hostname, conf_if))) {
13149 find = 1;
13150 bgp_show_peer(vty, peer, use_json,
13151 json);
13152 break;
13153 }
13154 } else {
13155 if (sockunion_same(&peer->su, su)) {
13156 find = 1;
13157 bgp_show_peer(vty, peer, use_json,
13158 json);
13159 break;
13160 }
13161 }
13162 }
13163 }
13164 break;
13165 case show_ipv4_all:
13166 case show_ipv6_all:
13167 FOREACH_SAFI (safi) {
13168 if (peer->afc[afi][safi]) {
13169 bgp_show_peer(vty, peer, use_json, json);
13170 nbr_output = true;
13171 break;
13172 }
13173 }
13174 break;
13175 }
13176 }
13177
13178 if ((type == show_peer || type == show_ipv4_peer ||
13179 type == show_ipv6_peer) && !find) {
13180 if (use_json)
13181 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
13182 else
13183 vty_out(vty, "%% No such neighbor in this view/vrf\n");
13184 }
13185
13186 if (type != show_peer && type != show_ipv4_peer &&
13187 type != show_ipv6_peer && !nbr_output && !use_json)
13188 vty_out(vty, "%% No BGP neighbors found\n");
13189
13190 if (use_json) {
13191 vty_out(vty, "%s\n", json_object_to_json_string_ext(
13192 json, JSON_C_TO_STRING_PRETTY));
13193 } else {
13194 vty_out(vty, "\n");
13195 }
13196
13197 return CMD_SUCCESS;
13198 }
13199
13200 static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
13201 enum show_type type,
13202 const char *ip_str,
13203 afi_t afi, bool use_json)
13204 {
13205
13206 int ret;
13207 struct bgp *bgp;
13208 union sockunion su;
13209
13210 bgp = bgp_get_default();
13211
13212 if (!bgp)
13213 return;
13214
13215 if (!use_json)
13216 bgp_show_global_graceful_restart_mode_vty(vty, bgp, use_json,
13217 NULL);
13218
13219 if (ip_str) {
13220 ret = str2sockunion(ip_str, &su);
13221 if (ret < 0)
13222 bgp_show_neighbor_graceful_restart(
13223 vty, bgp, type, NULL, ip_str, afi, use_json);
13224 else
13225 bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
13226 NULL, afi, use_json);
13227 } else
13228 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
13229 afi, use_json);
13230 }
13231
13232 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
13233 enum show_type type,
13234 const char *ip_str,
13235 bool use_json)
13236 {
13237 struct listnode *node, *nnode;
13238 struct bgp *bgp;
13239 union sockunion su;
13240 json_object *json = NULL;
13241 int ret, is_first = 1;
13242 bool nbr_output = false;
13243
13244 if (use_json)
13245 vty_out(vty, "{\n");
13246
13247 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
13248 nbr_output = true;
13249 if (use_json) {
13250 if (!(json = json_object_new_object())) {
13251 flog_err(
13252 EC_BGP_JSON_MEM_ERROR,
13253 "Unable to allocate memory for JSON object");
13254 vty_out(vty,
13255 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
13256 return;
13257 }
13258
13259 json_object_int_add(json, "vrfId",
13260 (bgp->vrf_id == VRF_UNKNOWN)
13261 ? -1
13262 : (int64_t)bgp->vrf_id);
13263 json_object_string_add(
13264 json, "vrfName",
13265 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
13266 ? VRF_DEFAULT_NAME
13267 : bgp->name);
13268
13269 if (!is_first)
13270 vty_out(vty, ",\n");
13271 else
13272 is_first = 0;
13273
13274 vty_out(vty, "\"%s\":",
13275 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
13276 ? VRF_DEFAULT_NAME
13277 : bgp->name);
13278 } else {
13279 vty_out(vty, "\nInstance %s:\n",
13280 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
13281 ? VRF_DEFAULT_NAME
13282 : bgp->name);
13283 }
13284
13285 if (type == show_peer || type == show_ipv4_peer ||
13286 type == show_ipv6_peer) {
13287 ret = str2sockunion(ip_str, &su);
13288 if (ret < 0)
13289 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
13290 use_json, json);
13291 else
13292 bgp_show_neighbor(vty, bgp, type, &su, NULL,
13293 use_json, json);
13294 } else {
13295 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
13296 use_json, json);
13297 }
13298 json_object_free(json);
13299 json = NULL;
13300 }
13301
13302 if (use_json)
13303 vty_out(vty, "}\n");
13304 else if (!nbr_output)
13305 vty_out(vty, "%% BGP instance not found\n");
13306 }
13307
13308 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
13309 enum show_type type, const char *ip_str,
13310 bool use_json)
13311 {
13312 int ret;
13313 struct bgp *bgp;
13314 union sockunion su;
13315 json_object *json = NULL;
13316
13317 if (name) {
13318 if (strmatch(name, "all")) {
13319 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
13320 use_json);
13321 return CMD_SUCCESS;
13322 } else {
13323 bgp = bgp_lookup_by_name(name);
13324 if (!bgp) {
13325 if (use_json) {
13326 json = json_object_new_object();
13327 vty_out(vty, "%s\n",
13328 json_object_to_json_string_ext(
13329 json,
13330 JSON_C_TO_STRING_PRETTY));
13331 json_object_free(json);
13332 } else
13333 vty_out(vty,
13334 "%% BGP instance not found\n");
13335
13336 return CMD_WARNING;
13337 }
13338 }
13339 } else {
13340 bgp = bgp_get_default();
13341 }
13342
13343 if (bgp) {
13344 json = json_object_new_object();
13345 if (ip_str) {
13346 ret = str2sockunion(ip_str, &su);
13347 if (ret < 0)
13348 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
13349 use_json, json);
13350 else
13351 bgp_show_neighbor(vty, bgp, type, &su, NULL,
13352 use_json, json);
13353 } else {
13354 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
13355 json);
13356 }
13357 json_object_free(json);
13358 } else {
13359 if (use_json)
13360 vty_out(vty, "{}\n");
13361 else
13362 vty_out(vty, "%% BGP instance not found\n");
13363 }
13364
13365 return CMD_SUCCESS;
13366 }
13367
13368
13369
13370 /* "show [ip] bgp neighbors graceful-restart" commands. */
13371 DEFUN (show_ip_bgp_neighbors_gracrful_restart,
13372 show_ip_bgp_neighbors_graceful_restart_cmd,
13373 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
13374 SHOW_STR
13375 BGP_STR
13376 IP_STR
13377 IPV6_STR
13378 NEIGHBOR_STR
13379 "Neighbor to display information about\n"
13380 "Neighbor to display information about\n"
13381 "Neighbor on BGP configured interface\n"
13382 GR_SHOW
13383 JSON_STR)
13384 {
13385 char *sh_arg = NULL;
13386 enum show_type sh_type;
13387 int idx = 0;
13388 afi_t afi = AFI_MAX;
13389 bool uj = use_json(argc, argv);
13390
13391 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
13392 afi = AFI_MAX;
13393
13394 idx++;
13395
13396 if (argv_find(argv, argc, "A.B.C.D", &idx)
13397 || argv_find(argv, argc, "X:X::X:X", &idx)
13398 || argv_find(argv, argc, "WORD", &idx)) {
13399 sh_type = show_peer;
13400 sh_arg = argv[idx]->arg;
13401 } else
13402 sh_type = show_all;
13403
13404 if (!argv_find(argv, argc, "graceful-restart", &idx))
13405 return CMD_SUCCESS;
13406
13407
13408 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
13409 afi, uj);
13410 }
13411
13412 /* "show [ip] bgp neighbors" commands. */
13413 DEFUN (show_ip_bgp_neighbors,
13414 show_ip_bgp_neighbors_cmd,
13415 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
13416 SHOW_STR
13417 IP_STR
13418 BGP_STR
13419 BGP_INSTANCE_HELP_STR
13420 "Address Family\n"
13421 "Address Family\n"
13422 "Detailed information on TCP and BGP neighbor connections\n"
13423 "Neighbor to display information about\n"
13424 "Neighbor to display information about\n"
13425 "Neighbor on BGP configured interface\n"
13426 JSON_STR)
13427 {
13428 char *vrf = NULL;
13429 char *sh_arg = NULL;
13430 enum show_type sh_type;
13431 afi_t afi = AFI_MAX;
13432
13433 bool uj = use_json(argc, argv);
13434
13435 int idx = 0;
13436
13437 /* [<vrf> VIEWVRFNAME] */
13438 if (argv_find(argv, argc, "vrf", &idx)) {
13439 vrf = argv[idx + 1]->arg;
13440 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
13441 vrf = NULL;
13442 } else if (argv_find(argv, argc, "view", &idx))
13443 /* [<view> VIEWVRFNAME] */
13444 vrf = argv[idx + 1]->arg;
13445
13446 idx++;
13447
13448 if (argv_find(argv, argc, "ipv4", &idx)) {
13449 sh_type = show_ipv4_all;
13450 afi = AFI_IP;
13451 } else if (argv_find(argv, argc, "ipv6", &idx)) {
13452 sh_type = show_ipv6_all;
13453 afi = AFI_IP6;
13454 } else {
13455 sh_type = show_all;
13456 }
13457
13458 if (argv_find(argv, argc, "A.B.C.D", &idx)
13459 || argv_find(argv, argc, "X:X::X:X", &idx)
13460 || argv_find(argv, argc, "WORD", &idx)) {
13461 sh_type = show_peer;
13462 sh_arg = argv[idx]->arg;
13463 }
13464
13465 if (sh_type == show_peer && afi == AFI_IP) {
13466 sh_type = show_ipv4_peer;
13467 } else if (sh_type == show_peer && afi == AFI_IP6) {
13468 sh_type = show_ipv6_peer;
13469 }
13470
13471 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
13472 }
13473
13474 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
13475 paths' and `show ip mbgp paths'. Those functions results are the
13476 same.*/
13477 DEFUN (show_ip_bgp_paths,
13478 show_ip_bgp_paths_cmd,
13479 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
13480 SHOW_STR
13481 IP_STR
13482 BGP_STR
13483 BGP_SAFI_HELP_STR
13484 "Path information\n")
13485 {
13486 vty_out(vty, "Address Refcnt Path\n");
13487 aspath_print_all_vty(vty);
13488 return CMD_SUCCESS;
13489 }
13490
13491 #include "hash.h"
13492
13493 static void community_show_all_iterator(struct hash_bucket *bucket,
13494 struct vty *vty)
13495 {
13496 struct community *com;
13497
13498 com = (struct community *)bucket->data;
13499 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
13500 community_str(com, false));
13501 }
13502
13503 /* Show BGP's community internal data. */
13504 DEFUN (show_ip_bgp_community_info,
13505 show_ip_bgp_community_info_cmd,
13506 "show [ip] bgp community-info",
13507 SHOW_STR
13508 IP_STR
13509 BGP_STR
13510 "List all bgp community information\n")
13511 {
13512 vty_out(vty, "Address Refcnt Community\n");
13513
13514 hash_iterate(community_hash(),
13515 (void (*)(struct hash_bucket *,
13516 void *))community_show_all_iterator,
13517 vty);
13518
13519 return CMD_SUCCESS;
13520 }
13521
13522 static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
13523 struct vty *vty)
13524 {
13525 struct lcommunity *lcom;
13526
13527 lcom = (struct lcommunity *)bucket->data;
13528 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
13529 lcommunity_str(lcom, false));
13530 }
13531
13532 /* Show BGP's community internal data. */
13533 DEFUN (show_ip_bgp_lcommunity_info,
13534 show_ip_bgp_lcommunity_info_cmd,
13535 "show ip bgp large-community-info",
13536 SHOW_STR
13537 IP_STR
13538 BGP_STR
13539 "List all bgp large-community information\n")
13540 {
13541 vty_out(vty, "Address Refcnt Large-community\n");
13542
13543 hash_iterate(lcommunity_hash(),
13544 (void (*)(struct hash_bucket *,
13545 void *))lcommunity_show_all_iterator,
13546 vty);
13547
13548 return CMD_SUCCESS;
13549 }
13550 /* Graceful Restart */
13551
13552 static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
13553 struct bgp *bgp,
13554 bool use_json,
13555 json_object *json)
13556 {
13557
13558
13559 vty_out(vty, "\n%s", SHOW_GR_HEADER);
13560
13561 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
13562
13563 switch (bgp_global_gr_mode) {
13564
13565 case GLOBAL_HELPER:
13566 vty_out(vty, "Global BGP GR Mode : Helper\n");
13567 break;
13568
13569 case GLOBAL_GR:
13570 vty_out(vty, "Global BGP GR Mode : Restart\n");
13571 break;
13572
13573 case GLOBAL_DISABLE:
13574 vty_out(vty, "Global BGP GR Mode : Disable\n");
13575 break;
13576
13577 case GLOBAL_INVALID:
13578 vty_out(vty,
13579 "Global BGP GR Mode Invalid\n");
13580 break;
13581 }
13582 vty_out(vty, "\n");
13583 }
13584
13585 static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
13586 enum show_type type,
13587 const char *ip_str,
13588 afi_t afi, bool use_json)
13589 {
13590 if ((afi == AFI_MAX) && (ip_str == NULL)) {
13591 afi = AFI_IP;
13592
13593 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
13594
13595 bgp_show_neighbor_graceful_restart_vty(
13596 vty, type, ip_str, afi, use_json);
13597 afi++;
13598 }
13599 } else if (afi != AFI_MAX) {
13600 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
13601 use_json);
13602 } else {
13603 return CMD_ERR_INCOMPLETE;
13604 }
13605
13606 return CMD_SUCCESS;
13607 }
13608 /* Graceful Restart */
13609
13610 DEFUN (show_ip_bgp_attr_info,
13611 show_ip_bgp_attr_info_cmd,
13612 "show [ip] bgp attribute-info",
13613 SHOW_STR
13614 IP_STR
13615 BGP_STR
13616 "List all bgp attribute information\n")
13617 {
13618 attr_show_all(vty);
13619 return CMD_SUCCESS;
13620 }
13621
13622 static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
13623 afi_t afi, safi_t safi,
13624 bool use_json, json_object *json)
13625 {
13626 struct bgp *bgp;
13627 struct listnode *node;
13628 char *vname;
13629 char buf1[INET6_ADDRSTRLEN];
13630 char *ecom_str;
13631 vpn_policy_direction_t dir;
13632
13633 if (json) {
13634 json_object *json_import_vrfs = NULL;
13635 json_object *json_export_vrfs = NULL;
13636
13637 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
13638
13639 if (!bgp) {
13640 vty_out(vty, "%s\n",
13641 json_object_to_json_string_ext(
13642 json,
13643 JSON_C_TO_STRING_PRETTY));
13644 json_object_free(json);
13645
13646 return CMD_WARNING;
13647 }
13648
13649 /* Provide context for the block */
13650 json_object_string_add(json, "vrf", name ? name : "default");
13651 json_object_string_add(json, "afiSafi",
13652 get_afi_safi_str(afi, safi, true));
13653
13654 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
13655 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
13656 json_object_string_add(json, "importFromVrfs", "none");
13657 json_object_string_add(json, "importRts", "none");
13658 } else {
13659 json_import_vrfs = json_object_new_array();
13660
13661 for (ALL_LIST_ELEMENTS_RO(
13662 bgp->vpn_policy[afi].import_vrf,
13663 node, vname))
13664 json_object_array_add(json_import_vrfs,
13665 json_object_new_string(vname));
13666
13667 json_object_object_add(json, "importFromVrfs",
13668 json_import_vrfs);
13669 dir = BGP_VPN_POLICY_DIR_FROMVPN;
13670 if (bgp->vpn_policy[afi].rtlist[dir]) {
13671 ecom_str = ecommunity_ecom2str(
13672 bgp->vpn_policy[afi].rtlist[dir],
13673 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
13674 json_object_string_add(json, "importRts",
13675 ecom_str);
13676 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
13677 } else
13678 json_object_string_add(json, "importRts",
13679 "none");
13680 }
13681
13682 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
13683 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
13684 json_object_string_add(json, "exportToVrfs", "none");
13685 json_object_string_add(json, "routeDistinguisher",
13686 "none");
13687 json_object_string_add(json, "exportRts", "none");
13688 } else {
13689 json_export_vrfs = json_object_new_array();
13690
13691 for (ALL_LIST_ELEMENTS_RO(
13692 bgp->vpn_policy[afi].export_vrf,
13693 node, vname))
13694 json_object_array_add(json_export_vrfs,
13695 json_object_new_string(vname));
13696 json_object_object_add(json, "exportToVrfs",
13697 json_export_vrfs);
13698 json_object_string_add(json, "routeDistinguisher",
13699 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
13700 buf1, RD_ADDRSTRLEN));
13701
13702 dir = BGP_VPN_POLICY_DIR_TOVPN;
13703 if (bgp->vpn_policy[afi].rtlist[dir]) {
13704 ecom_str = ecommunity_ecom2str(
13705 bgp->vpn_policy[afi].rtlist[dir],
13706 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
13707 json_object_string_add(json, "exportRts",
13708 ecom_str);
13709 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
13710 } else
13711 json_object_string_add(json, "exportRts",
13712 "none");
13713 }
13714
13715 if (use_json) {
13716 vty_out(vty, "%s\n",
13717 json_object_to_json_string_ext(json,
13718 JSON_C_TO_STRING_PRETTY));
13719 json_object_free(json);
13720 }
13721 } else {
13722 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
13723
13724 if (!bgp) {
13725 vty_out(vty, "%% No such BGP instance exist\n");
13726 return CMD_WARNING;
13727 }
13728
13729 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
13730 BGP_CONFIG_VRF_TO_VRF_IMPORT))
13731 vty_out(vty,
13732 "This VRF is not importing %s routes from any other VRF\n",
13733 get_afi_safi_str(afi, safi, false));
13734 else {
13735 vty_out(vty,
13736 "This VRF is importing %s routes from the following VRFs:\n",
13737 get_afi_safi_str(afi, safi, false));
13738
13739 for (ALL_LIST_ELEMENTS_RO(
13740 bgp->vpn_policy[afi].import_vrf,
13741 node, vname))
13742 vty_out(vty, " %s\n", vname);
13743
13744 dir = BGP_VPN_POLICY_DIR_FROMVPN;
13745 ecom_str = NULL;
13746 if (bgp->vpn_policy[afi].rtlist[dir]) {
13747 ecom_str = ecommunity_ecom2str(
13748 bgp->vpn_policy[afi].rtlist[dir],
13749 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
13750 vty_out(vty, "Import RT(s): %s\n", ecom_str);
13751
13752 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
13753 } else
13754 vty_out(vty, "Import RT(s):\n");
13755 }
13756
13757 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
13758 BGP_CONFIG_VRF_TO_VRF_EXPORT))
13759 vty_out(vty,
13760 "This VRF is not exporting %s routes to any other VRF\n",
13761 get_afi_safi_str(afi, safi, false));
13762 else {
13763 vty_out(vty,
13764 "This VRF is exporting %s routes to the following VRFs:\n",
13765 get_afi_safi_str(afi, safi, false));
13766
13767 for (ALL_LIST_ELEMENTS_RO(
13768 bgp->vpn_policy[afi].export_vrf,
13769 node, vname))
13770 vty_out(vty, " %s\n", vname);
13771
13772 vty_out(vty, "RD: %s\n",
13773 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
13774 buf1, RD_ADDRSTRLEN));
13775
13776 dir = BGP_VPN_POLICY_DIR_TOVPN;
13777 if (bgp->vpn_policy[afi].rtlist[dir]) {
13778 ecom_str = ecommunity_ecom2str(
13779 bgp->vpn_policy[afi].rtlist[dir],
13780 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
13781 vty_out(vty, "Export RT: %s\n", ecom_str);
13782 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
13783 } else
13784 vty_out(vty, "Import RT(s):\n");
13785 }
13786 }
13787
13788 return CMD_SUCCESS;
13789 }
13790
13791 static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
13792 safi_t safi, bool use_json)
13793 {
13794 struct listnode *node, *nnode;
13795 struct bgp *bgp;
13796 char *vrf_name = NULL;
13797 json_object *json = NULL;
13798 json_object *json_vrf = NULL;
13799 json_object *json_vrfs = NULL;
13800
13801 if (use_json) {
13802 json = json_object_new_object();
13803 json_vrfs = json_object_new_object();
13804 }
13805
13806 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
13807
13808 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
13809 vrf_name = bgp->name;
13810
13811 if (use_json) {
13812 json_vrf = json_object_new_object();
13813 } else {
13814 vty_out(vty, "\nInstance %s:\n",
13815 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
13816 ? VRF_DEFAULT_NAME : bgp->name);
13817 }
13818 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
13819 if (use_json) {
13820 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
13821 json_object_object_add(json_vrfs,
13822 VRF_DEFAULT_NAME, json_vrf);
13823 else
13824 json_object_object_add(json_vrfs, vrf_name,
13825 json_vrf);
13826 }
13827 }
13828
13829 if (use_json) {
13830 json_object_object_add(json, "vrfs", json_vrfs);
13831 vty_out(vty, "%s\n", json_object_to_json_string_ext(json,
13832 JSON_C_TO_STRING_PRETTY));
13833 json_object_free(json);
13834 }
13835
13836 return CMD_SUCCESS;
13837 }
13838
13839 /* "show [ip] bgp route-leak" command. */
13840 DEFUN (show_ip_bgp_route_leak,
13841 show_ip_bgp_route_leak_cmd,
13842 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
13843 SHOW_STR
13844 IP_STR
13845 BGP_STR
13846 BGP_INSTANCE_HELP_STR
13847 BGP_AFI_HELP_STR
13848 BGP_SAFI_HELP_STR
13849 "Route leaking information\n"
13850 JSON_STR)
13851 {
13852 char *vrf = NULL;
13853 afi_t afi = AFI_MAX;
13854 safi_t safi = SAFI_MAX;
13855
13856 bool uj = use_json(argc, argv);
13857 int idx = 0;
13858 json_object *json = NULL;
13859
13860 /* show [ip] bgp */
13861 if (argv_find(argv, argc, "ip", &idx)) {
13862 afi = AFI_IP;
13863 safi = SAFI_UNICAST;
13864 }
13865 /* [vrf VIEWVRFNAME] */
13866 if (argv_find(argv, argc, "view", &idx)) {
13867 vty_out(vty,
13868 "%% This command is not applicable to BGP views\n");
13869 return CMD_WARNING;
13870 }
13871
13872 if (argv_find(argv, argc, "vrf", &idx)) {
13873 vrf = argv[idx + 1]->arg;
13874 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
13875 vrf = NULL;
13876 }
13877 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
13878 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
13879 argv_find_and_parse_safi(argv, argc, &idx, &safi);
13880 }
13881
13882 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
13883 vty_out(vty,
13884 "%% This command is applicable only for unicast ipv4|ipv6\n");
13885 return CMD_WARNING;
13886 }
13887
13888 if (vrf && strmatch(vrf, "all"))
13889 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
13890
13891 if (uj)
13892 json = json_object_new_object();
13893
13894 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
13895 }
13896
13897 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
13898 safi_t safi)
13899 {
13900 struct listnode *node, *nnode;
13901 struct bgp *bgp;
13902
13903 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
13904 vty_out(vty, "\nInstance %s:\n",
13905 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
13906 ? VRF_DEFAULT_NAME
13907 : bgp->name);
13908 update_group_show(bgp, afi, safi, vty, 0);
13909 }
13910 }
13911
13912 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
13913 int safi, uint64_t subgrp_id)
13914 {
13915 struct bgp *bgp;
13916
13917 if (name) {
13918 if (strmatch(name, "all")) {
13919 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
13920 return CMD_SUCCESS;
13921 } else {
13922 bgp = bgp_lookup_by_name(name);
13923 }
13924 } else {
13925 bgp = bgp_get_default();
13926 }
13927
13928 if (bgp)
13929 update_group_show(bgp, afi, safi, vty, subgrp_id);
13930 return CMD_SUCCESS;
13931 }
13932
13933 DEFUN (show_ip_bgp_updgrps,
13934 show_ip_bgp_updgrps_cmd,
13935 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
13936 SHOW_STR
13937 IP_STR
13938 BGP_STR
13939 BGP_INSTANCE_HELP_STR
13940 BGP_AFI_HELP_STR
13941 BGP_SAFI_WITH_LABEL_HELP_STR
13942 "Detailed info about dynamic update groups\n"
13943 "Specific subgroup to display detailed info for\n")
13944 {
13945 char *vrf = NULL;
13946 afi_t afi = AFI_IP6;
13947 safi_t safi = SAFI_UNICAST;
13948 uint64_t subgrp_id = 0;
13949
13950 int idx = 0;
13951
13952 /* show [ip] bgp */
13953 if (argv_find(argv, argc, "ip", &idx))
13954 afi = AFI_IP;
13955 /* [<vrf> VIEWVRFNAME] */
13956 if (argv_find(argv, argc, "vrf", &idx)) {
13957 vrf = argv[idx + 1]->arg;
13958 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
13959 vrf = NULL;
13960 } else if (argv_find(argv, argc, "view", &idx))
13961 /* [<view> VIEWVRFNAME] */
13962 vrf = argv[idx + 1]->arg;
13963 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
13964 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
13965 argv_find_and_parse_safi(argv, argc, &idx, &safi);
13966 }
13967
13968 /* get subgroup id, if provided */
13969 idx = argc - 1;
13970 if (argv[idx]->type == VARIABLE_TKN)
13971 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
13972
13973 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
13974 }
13975
13976 DEFUN (show_bgp_instance_all_ipv6_updgrps,
13977 show_bgp_instance_all_ipv6_updgrps_cmd,
13978 "show [ip] bgp <view|vrf> all update-groups",
13979 SHOW_STR
13980 IP_STR
13981 BGP_STR
13982 BGP_INSTANCE_ALL_HELP_STR
13983 "Detailed info about dynamic update groups\n")
13984 {
13985 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
13986 return CMD_SUCCESS;
13987 }
13988
13989 DEFUN (show_bgp_l2vpn_evpn_updgrps,
13990 show_bgp_l2vpn_evpn_updgrps_cmd,
13991 "show [ip] bgp l2vpn evpn update-groups",
13992 SHOW_STR
13993 IP_STR
13994 BGP_STR
13995 "l2vpn address family\n"
13996 "evpn sub-address family\n"
13997 "Detailed info about dynamic update groups\n")
13998 {
13999 char *vrf = NULL;
14000 uint64_t subgrp_id = 0;
14001
14002 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
14003 return CMD_SUCCESS;
14004 }
14005
14006 DEFUN (show_bgp_updgrps_stats,
14007 show_bgp_updgrps_stats_cmd,
14008 "show [ip] bgp update-groups statistics",
14009 SHOW_STR
14010 IP_STR
14011 BGP_STR
14012 "Detailed info about dynamic update groups\n"
14013 "Statistics\n")
14014 {
14015 struct bgp *bgp;
14016
14017 bgp = bgp_get_default();
14018 if (bgp)
14019 update_group_show_stats(bgp, vty);
14020
14021 return CMD_SUCCESS;
14022 }
14023
14024 DEFUN (show_bgp_instance_updgrps_stats,
14025 show_bgp_instance_updgrps_stats_cmd,
14026 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
14027 SHOW_STR
14028 IP_STR
14029 BGP_STR
14030 BGP_INSTANCE_HELP_STR
14031 "Detailed info about dynamic update groups\n"
14032 "Statistics\n")
14033 {
14034 int idx_word = 3;
14035 struct bgp *bgp;
14036
14037 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
14038 if (bgp)
14039 update_group_show_stats(bgp, vty);
14040
14041 return CMD_SUCCESS;
14042 }
14043
14044 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
14045 afi_t afi, safi_t safi,
14046 const char *what, uint64_t subgrp_id)
14047 {
14048 struct bgp *bgp;
14049
14050 if (name)
14051 bgp = bgp_lookup_by_name(name);
14052 else
14053 bgp = bgp_get_default();
14054
14055 if (bgp) {
14056 if (!strcmp(what, "advertise-queue"))
14057 update_group_show_adj_queue(bgp, afi, safi, vty,
14058 subgrp_id);
14059 else if (!strcmp(what, "advertised-routes"))
14060 update_group_show_advertised(bgp, afi, safi, vty,
14061 subgrp_id);
14062 else if (!strcmp(what, "packet-queue"))
14063 update_group_show_packet_queue(bgp, afi, safi, vty,
14064 subgrp_id);
14065 }
14066 }
14067
14068 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
14069 show_ip_bgp_instance_updgrps_adj_s_cmd,
14070 "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",
14071 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
14072 BGP_SAFI_HELP_STR
14073 "Detailed info about dynamic update groups\n"
14074 "Specific subgroup to display info for\n"
14075 "Advertisement queue\n"
14076 "Announced routes\n"
14077 "Packet queue\n")
14078 {
14079 uint64_t subgrp_id = 0;
14080 afi_t afiz;
14081 safi_t safiz;
14082 if (sgid)
14083 subgrp_id = strtoull(sgid, NULL, 10);
14084
14085 if (!ip && !afi)
14086 afiz = AFI_IP6;
14087 if (!ip && afi)
14088 afiz = bgp_vty_afi_from_str(afi);
14089 if (ip && !afi)
14090 afiz = AFI_IP;
14091 if (ip && afi) {
14092 afiz = bgp_vty_afi_from_str(afi);
14093 if (afiz != AFI_IP)
14094 vty_out(vty,
14095 "%% Cannot specify both 'ip' and 'ipv6'\n");
14096 return CMD_WARNING;
14097 }
14098
14099 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
14100
14101 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
14102 return CMD_SUCCESS;
14103 }
14104
14105 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
14106 {
14107 struct listnode *node, *nnode;
14108 struct prefix *range;
14109 struct peer *conf;
14110 struct peer *peer;
14111 char buf[PREFIX2STR_BUFFER];
14112 afi_t afi;
14113 safi_t safi;
14114 const char *peer_status;
14115 const char *af_str;
14116 int lr_count;
14117 int dynamic;
14118 int af_cfgd;
14119
14120 conf = group->conf;
14121
14122 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
14123 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
14124 group->name, conf->as);
14125 } else if (conf->as_type == AS_INTERNAL) {
14126 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
14127 group->name, group->bgp->as);
14128 } else {
14129 vty_out(vty, "\nBGP peer-group %s\n", group->name);
14130 }
14131
14132 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
14133 vty_out(vty, " Peer-group type is internal\n");
14134 else
14135 vty_out(vty, " Peer-group type is external\n");
14136
14137 /* Display AFs configured. */
14138 vty_out(vty, " Configured address-families:");
14139 FOREACH_AFI_SAFI (afi, safi) {
14140 if (conf->afc[afi][safi]) {
14141 af_cfgd = 1;
14142 vty_out(vty, " %s;", get_afi_safi_str(afi, safi, false));
14143 }
14144 }
14145 if (!af_cfgd)
14146 vty_out(vty, " none\n");
14147 else
14148 vty_out(vty, "\n");
14149
14150 /* Display listen ranges (for dynamic neighbors), if any */
14151 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
14152 if (afi == AFI_IP)
14153 af_str = "IPv4";
14154 else if (afi == AFI_IP6)
14155 af_str = "IPv6";
14156 else
14157 af_str = "???";
14158 lr_count = listcount(group->listen_range[afi]);
14159 if (lr_count) {
14160 vty_out(vty, " %d %s listen range(s)\n", lr_count,
14161 af_str);
14162
14163
14164 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
14165 nnode, range)) {
14166 prefix2str(range, buf, sizeof(buf));
14167 vty_out(vty, " %s\n", buf);
14168 }
14169 }
14170 }
14171
14172 /* Display group members and their status */
14173 if (listcount(group->peer)) {
14174 vty_out(vty, " Peer-group members:\n");
14175 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
14176 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
14177 || CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHUTDOWN))
14178 peer_status = "Idle (Admin)";
14179 else if (CHECK_FLAG(peer->sflags,
14180 PEER_STATUS_PREFIX_OVERFLOW))
14181 peer_status = "Idle (PfxCt)";
14182 else
14183 peer_status = lookup_msg(bgp_status_msg,
14184 peer->status, NULL);
14185
14186 dynamic = peer_dynamic_neighbor(peer);
14187 vty_out(vty, " %s %s %s \n", peer->host,
14188 dynamic ? "(dynamic)" : "", peer_status);
14189 }
14190 }
14191
14192 return CMD_SUCCESS;
14193 }
14194
14195 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
14196 const char *group_name)
14197 {
14198 struct bgp *bgp;
14199 struct listnode *node, *nnode;
14200 struct peer_group *group;
14201 bool found = false;
14202
14203 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
14204
14205 if (!bgp) {
14206 vty_out(vty, "%% BGP instance not found\n");
14207 return CMD_WARNING;
14208 }
14209
14210 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
14211 if (group_name) {
14212 if (strmatch(group->name, group_name)) {
14213 bgp_show_one_peer_group(vty, group);
14214 found = true;
14215 break;
14216 }
14217 } else {
14218 bgp_show_one_peer_group(vty, group);
14219 }
14220 }
14221
14222 if (group_name && !found)
14223 vty_out(vty, "%% No such peer-group\n");
14224
14225 return CMD_SUCCESS;
14226 }
14227
14228 DEFUN (show_ip_bgp_peer_groups,
14229 show_ip_bgp_peer_groups_cmd,
14230 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
14231 SHOW_STR
14232 IP_STR
14233 BGP_STR
14234 BGP_INSTANCE_HELP_STR
14235 "Detailed information on BGP peer groups\n"
14236 "Peer group name\n")
14237 {
14238 char *vrf, *pg;
14239 int idx = 0;
14240
14241 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
14242 : NULL;
14243 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
14244
14245 return bgp_show_peer_group_vty(vty, vrf, pg);
14246 }
14247
14248
14249 /* Redistribute VTY commands. */
14250
14251 DEFUN (bgp_redistribute_ipv4,
14252 bgp_redistribute_ipv4_cmd,
14253 "redistribute " FRR_IP_REDIST_STR_BGPD,
14254 "Redistribute information from another routing protocol\n"
14255 FRR_IP_REDIST_HELP_STR_BGPD)
14256 {
14257 VTY_DECLVAR_CONTEXT(bgp, bgp);
14258 int idx_protocol = 1;
14259 int type;
14260
14261 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
14262 if (type < 0) {
14263 vty_out(vty, "%% Invalid route type\n");
14264 return CMD_WARNING_CONFIG_FAILED;
14265 }
14266
14267 bgp_redist_add(bgp, AFI_IP, type, 0);
14268 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
14269 }
14270
14271 ALIAS_HIDDEN(
14272 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
14273 "redistribute " FRR_IP_REDIST_STR_BGPD,
14274 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
14275
14276 DEFUN (bgp_redistribute_ipv4_rmap,
14277 bgp_redistribute_ipv4_rmap_cmd,
14278 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
14279 "Redistribute information from another routing protocol\n"
14280 FRR_IP_REDIST_HELP_STR_BGPD
14281 "Route map reference\n"
14282 "Pointer to route-map entries\n")
14283 {
14284 VTY_DECLVAR_CONTEXT(bgp, bgp);
14285 int idx_protocol = 1;
14286 int idx_word = 3;
14287 int type;
14288 struct bgp_redist *red;
14289 bool changed;
14290 struct route_map *route_map = route_map_lookup_warn_noexist(
14291 vty, argv[idx_word]->arg);
14292
14293 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
14294 if (type < 0) {
14295 vty_out(vty, "%% Invalid route type\n");
14296 return CMD_WARNING_CONFIG_FAILED;
14297 }
14298
14299 red = bgp_redist_add(bgp, AFI_IP, type, 0);
14300 changed =
14301 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
14302 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
14303 }
14304
14305 ALIAS_HIDDEN(
14306 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
14307 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
14308 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
14309 "Route map reference\n"
14310 "Pointer to route-map entries\n")
14311
14312 DEFUN (bgp_redistribute_ipv4_metric,
14313 bgp_redistribute_ipv4_metric_cmd,
14314 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
14315 "Redistribute information from another routing protocol\n"
14316 FRR_IP_REDIST_HELP_STR_BGPD
14317 "Metric for redistributed routes\n"
14318 "Default metric\n")
14319 {
14320 VTY_DECLVAR_CONTEXT(bgp, bgp);
14321 int idx_protocol = 1;
14322 int idx_number = 3;
14323 int type;
14324 uint32_t metric;
14325 struct bgp_redist *red;
14326 bool changed;
14327
14328 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
14329 if (type < 0) {
14330 vty_out(vty, "%% Invalid route type\n");
14331 return CMD_WARNING_CONFIG_FAILED;
14332 }
14333 metric = strtoul(argv[idx_number]->arg, NULL, 10);
14334
14335 red = bgp_redist_add(bgp, AFI_IP, type, 0);
14336 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
14337 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
14338 }
14339
14340 ALIAS_HIDDEN(
14341 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
14342 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
14343 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
14344 "Metric for redistributed routes\n"
14345 "Default metric\n")
14346
14347 DEFUN (bgp_redistribute_ipv4_rmap_metric,
14348 bgp_redistribute_ipv4_rmap_metric_cmd,
14349 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
14350 "Redistribute information from another routing protocol\n"
14351 FRR_IP_REDIST_HELP_STR_BGPD
14352 "Route map reference\n"
14353 "Pointer to route-map entries\n"
14354 "Metric for redistributed routes\n"
14355 "Default metric\n")
14356 {
14357 VTY_DECLVAR_CONTEXT(bgp, bgp);
14358 int idx_protocol = 1;
14359 int idx_word = 3;
14360 int idx_number = 5;
14361 int type;
14362 uint32_t metric;
14363 struct bgp_redist *red;
14364 bool changed;
14365 struct route_map *route_map =
14366 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
14367
14368 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
14369 if (type < 0) {
14370 vty_out(vty, "%% Invalid route type\n");
14371 return CMD_WARNING_CONFIG_FAILED;
14372 }
14373 metric = strtoul(argv[idx_number]->arg, NULL, 10);
14374
14375 red = bgp_redist_add(bgp, AFI_IP, type, 0);
14376 changed =
14377 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
14378 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
14379 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
14380 }
14381
14382 ALIAS_HIDDEN(
14383 bgp_redistribute_ipv4_rmap_metric,
14384 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
14385 "redistribute " FRR_IP_REDIST_STR_BGPD
14386 " route-map WORD metric (0-4294967295)",
14387 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
14388 "Route map reference\n"
14389 "Pointer to route-map entries\n"
14390 "Metric for redistributed routes\n"
14391 "Default metric\n")
14392
14393 DEFUN (bgp_redistribute_ipv4_metric_rmap,
14394 bgp_redistribute_ipv4_metric_rmap_cmd,
14395 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
14396 "Redistribute information from another routing protocol\n"
14397 FRR_IP_REDIST_HELP_STR_BGPD
14398 "Metric for redistributed routes\n"
14399 "Default metric\n"
14400 "Route map reference\n"
14401 "Pointer to route-map entries\n")
14402 {
14403 VTY_DECLVAR_CONTEXT(bgp, bgp);
14404 int idx_protocol = 1;
14405 int idx_number = 3;
14406 int idx_word = 5;
14407 int type;
14408 uint32_t metric;
14409 struct bgp_redist *red;
14410 bool changed;
14411 struct route_map *route_map =
14412 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
14413
14414 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
14415 if (type < 0) {
14416 vty_out(vty, "%% Invalid route type\n");
14417 return CMD_WARNING_CONFIG_FAILED;
14418 }
14419 metric = strtoul(argv[idx_number]->arg, NULL, 10);
14420
14421 red = bgp_redist_add(bgp, AFI_IP, type, 0);
14422 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
14423 changed |=
14424 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
14425 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
14426 }
14427
14428 ALIAS_HIDDEN(
14429 bgp_redistribute_ipv4_metric_rmap,
14430 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
14431 "redistribute " FRR_IP_REDIST_STR_BGPD
14432 " metric (0-4294967295) route-map WORD",
14433 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
14434 "Metric for redistributed routes\n"
14435 "Default metric\n"
14436 "Route map reference\n"
14437 "Pointer to route-map entries\n")
14438
14439 DEFUN (bgp_redistribute_ipv4_ospf,
14440 bgp_redistribute_ipv4_ospf_cmd,
14441 "redistribute <ospf|table> (1-65535)",
14442 "Redistribute information from another routing protocol\n"
14443 "Open Shortest Path First (OSPFv2)\n"
14444 "Non-main Kernel Routing Table\n"
14445 "Instance ID/Table ID\n")
14446 {
14447 VTY_DECLVAR_CONTEXT(bgp, bgp);
14448 int idx_ospf_table = 1;
14449 int idx_number = 2;
14450 unsigned short instance;
14451 unsigned short protocol;
14452
14453 instance = strtoul(argv[idx_number]->arg, NULL, 10);
14454
14455 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
14456 protocol = ZEBRA_ROUTE_OSPF;
14457 else
14458 protocol = ZEBRA_ROUTE_TABLE;
14459
14460 bgp_redist_add(bgp, AFI_IP, protocol, instance);
14461 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
14462 }
14463
14464 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
14465 "redistribute <ospf|table> (1-65535)",
14466 "Redistribute information from another routing protocol\n"
14467 "Open Shortest Path First (OSPFv2)\n"
14468 "Non-main Kernel Routing Table\n"
14469 "Instance ID/Table ID\n")
14470
14471 DEFUN (bgp_redistribute_ipv4_ospf_rmap,
14472 bgp_redistribute_ipv4_ospf_rmap_cmd,
14473 "redistribute <ospf|table> (1-65535) route-map WORD",
14474 "Redistribute information from another routing protocol\n"
14475 "Open Shortest Path First (OSPFv2)\n"
14476 "Non-main Kernel Routing Table\n"
14477 "Instance ID/Table ID\n"
14478 "Route map reference\n"
14479 "Pointer to route-map entries\n")
14480 {
14481 VTY_DECLVAR_CONTEXT(bgp, bgp);
14482 int idx_ospf_table = 1;
14483 int idx_number = 2;
14484 int idx_word = 4;
14485 struct bgp_redist *red;
14486 unsigned short instance;
14487 int protocol;
14488 bool changed;
14489 struct route_map *route_map =
14490 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
14491
14492 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
14493 protocol = ZEBRA_ROUTE_OSPF;
14494 else
14495 protocol = ZEBRA_ROUTE_TABLE;
14496
14497 instance = strtoul(argv[idx_number]->arg, NULL, 10);
14498 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
14499 changed =
14500 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
14501 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
14502 }
14503
14504 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
14505 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
14506 "redistribute <ospf|table> (1-65535) route-map WORD",
14507 "Redistribute information from another routing protocol\n"
14508 "Open Shortest Path First (OSPFv2)\n"
14509 "Non-main Kernel Routing Table\n"
14510 "Instance ID/Table ID\n"
14511 "Route map reference\n"
14512 "Pointer to route-map entries\n")
14513
14514 DEFUN (bgp_redistribute_ipv4_ospf_metric,
14515 bgp_redistribute_ipv4_ospf_metric_cmd,
14516 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
14517 "Redistribute information from another routing protocol\n"
14518 "Open Shortest Path First (OSPFv2)\n"
14519 "Non-main Kernel Routing Table\n"
14520 "Instance ID/Table ID\n"
14521 "Metric for redistributed routes\n"
14522 "Default metric\n")
14523 {
14524 VTY_DECLVAR_CONTEXT(bgp, bgp);
14525 int idx_ospf_table = 1;
14526 int idx_number = 2;
14527 int idx_number_2 = 4;
14528 uint32_t metric;
14529 struct bgp_redist *red;
14530 unsigned short instance;
14531 int protocol;
14532 bool changed;
14533
14534 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
14535 protocol = ZEBRA_ROUTE_OSPF;
14536 else
14537 protocol = ZEBRA_ROUTE_TABLE;
14538
14539 instance = strtoul(argv[idx_number]->arg, NULL, 10);
14540 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
14541
14542 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
14543 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
14544 metric);
14545 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
14546 }
14547
14548 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
14549 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
14550 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
14551 "Redistribute information from another routing protocol\n"
14552 "Open Shortest Path First (OSPFv2)\n"
14553 "Non-main Kernel Routing Table\n"
14554 "Instance ID/Table ID\n"
14555 "Metric for redistributed routes\n"
14556 "Default metric\n")
14557
14558 DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
14559 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
14560 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
14561 "Redistribute information from another routing protocol\n"
14562 "Open Shortest Path First (OSPFv2)\n"
14563 "Non-main Kernel Routing Table\n"
14564 "Instance ID/Table ID\n"
14565 "Route map reference\n"
14566 "Pointer to route-map entries\n"
14567 "Metric for redistributed routes\n"
14568 "Default metric\n")
14569 {
14570 VTY_DECLVAR_CONTEXT(bgp, bgp);
14571 int idx_ospf_table = 1;
14572 int idx_number = 2;
14573 int idx_word = 4;
14574 int idx_number_2 = 6;
14575 uint32_t metric;
14576 struct bgp_redist *red;
14577 unsigned short instance;
14578 int protocol;
14579 bool changed;
14580 struct route_map *route_map =
14581 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
14582
14583 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
14584 protocol = ZEBRA_ROUTE_OSPF;
14585 else
14586 protocol = ZEBRA_ROUTE_TABLE;
14587
14588 instance = strtoul(argv[idx_number]->arg, NULL, 10);
14589 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
14590
14591 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
14592 changed =
14593 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
14594 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
14595 metric);
14596 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
14597 }
14598
14599 ALIAS_HIDDEN(
14600 bgp_redistribute_ipv4_ospf_rmap_metric,
14601 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
14602 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
14603 "Redistribute information from another routing protocol\n"
14604 "Open Shortest Path First (OSPFv2)\n"
14605 "Non-main Kernel Routing Table\n"
14606 "Instance ID/Table ID\n"
14607 "Route map reference\n"
14608 "Pointer to route-map entries\n"
14609 "Metric for redistributed routes\n"
14610 "Default metric\n")
14611
14612 DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
14613 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
14614 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
14615 "Redistribute information from another routing protocol\n"
14616 "Open Shortest Path First (OSPFv2)\n"
14617 "Non-main Kernel Routing Table\n"
14618 "Instance ID/Table ID\n"
14619 "Metric for redistributed routes\n"
14620 "Default metric\n"
14621 "Route map reference\n"
14622 "Pointer to route-map entries\n")
14623 {
14624 VTY_DECLVAR_CONTEXT(bgp, bgp);
14625 int idx_ospf_table = 1;
14626 int idx_number = 2;
14627 int idx_number_2 = 4;
14628 int idx_word = 6;
14629 uint32_t metric;
14630 struct bgp_redist *red;
14631 unsigned short instance;
14632 int protocol;
14633 bool changed;
14634 struct route_map *route_map =
14635 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
14636
14637 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
14638 protocol = ZEBRA_ROUTE_OSPF;
14639 else
14640 protocol = ZEBRA_ROUTE_TABLE;
14641
14642 instance = strtoul(argv[idx_number]->arg, NULL, 10);
14643 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
14644
14645 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
14646 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
14647 metric);
14648 changed |=
14649 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
14650 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
14651 }
14652
14653 ALIAS_HIDDEN(
14654 bgp_redistribute_ipv4_ospf_metric_rmap,
14655 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
14656 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
14657 "Redistribute information from another routing protocol\n"
14658 "Open Shortest Path First (OSPFv2)\n"
14659 "Non-main Kernel Routing Table\n"
14660 "Instance ID/Table ID\n"
14661 "Metric for redistributed routes\n"
14662 "Default metric\n"
14663 "Route map reference\n"
14664 "Pointer to route-map entries\n")
14665
14666 DEFUN (no_bgp_redistribute_ipv4_ospf,
14667 no_bgp_redistribute_ipv4_ospf_cmd,
14668 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
14669 NO_STR
14670 "Redistribute information from another routing protocol\n"
14671 "Open Shortest Path First (OSPFv2)\n"
14672 "Non-main Kernel Routing Table\n"
14673 "Instance ID/Table ID\n"
14674 "Metric for redistributed routes\n"
14675 "Default metric\n"
14676 "Route map reference\n"
14677 "Pointer to route-map entries\n")
14678 {
14679 VTY_DECLVAR_CONTEXT(bgp, bgp);
14680 int idx_ospf_table = 2;
14681 int idx_number = 3;
14682 unsigned short instance;
14683 int protocol;
14684
14685 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
14686 protocol = ZEBRA_ROUTE_OSPF;
14687 else
14688 protocol = ZEBRA_ROUTE_TABLE;
14689
14690 instance = strtoul(argv[idx_number]->arg, NULL, 10);
14691 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
14692 }
14693
14694 ALIAS_HIDDEN(
14695 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
14696 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
14697 NO_STR
14698 "Redistribute information from another routing protocol\n"
14699 "Open Shortest Path First (OSPFv2)\n"
14700 "Non-main Kernel Routing Table\n"
14701 "Instance ID/Table ID\n"
14702 "Metric for redistributed routes\n"
14703 "Default metric\n"
14704 "Route map reference\n"
14705 "Pointer to route-map entries\n")
14706
14707 DEFUN (no_bgp_redistribute_ipv4,
14708 no_bgp_redistribute_ipv4_cmd,
14709 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
14710 NO_STR
14711 "Redistribute information from another routing protocol\n"
14712 FRR_IP_REDIST_HELP_STR_BGPD
14713 "Metric for redistributed routes\n"
14714 "Default metric\n"
14715 "Route map reference\n"
14716 "Pointer to route-map entries\n")
14717 {
14718 VTY_DECLVAR_CONTEXT(bgp, bgp);
14719 int idx_protocol = 2;
14720 int type;
14721
14722 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
14723 if (type < 0) {
14724 vty_out(vty, "%% Invalid route type\n");
14725 return CMD_WARNING_CONFIG_FAILED;
14726 }
14727 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
14728 }
14729
14730 ALIAS_HIDDEN(
14731 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
14732 "no redistribute " FRR_IP_REDIST_STR_BGPD
14733 " [{metric (0-4294967295)|route-map WORD}]",
14734 NO_STR
14735 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
14736 "Metric for redistributed routes\n"
14737 "Default metric\n"
14738 "Route map reference\n"
14739 "Pointer to route-map entries\n")
14740
14741 DEFUN (bgp_redistribute_ipv6,
14742 bgp_redistribute_ipv6_cmd,
14743 "redistribute " FRR_IP6_REDIST_STR_BGPD,
14744 "Redistribute information from another routing protocol\n"
14745 FRR_IP6_REDIST_HELP_STR_BGPD)
14746 {
14747 VTY_DECLVAR_CONTEXT(bgp, bgp);
14748 int idx_protocol = 1;
14749 int type;
14750
14751 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
14752 if (type < 0) {
14753 vty_out(vty, "%% Invalid route type\n");
14754 return CMD_WARNING_CONFIG_FAILED;
14755 }
14756
14757 bgp_redist_add(bgp, AFI_IP6, type, 0);
14758 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
14759 }
14760
14761 DEFUN (bgp_redistribute_ipv6_rmap,
14762 bgp_redistribute_ipv6_rmap_cmd,
14763 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
14764 "Redistribute information from another routing protocol\n"
14765 FRR_IP6_REDIST_HELP_STR_BGPD
14766 "Route map reference\n"
14767 "Pointer to route-map entries\n")
14768 {
14769 VTY_DECLVAR_CONTEXT(bgp, bgp);
14770 int idx_protocol = 1;
14771 int idx_word = 3;
14772 int type;
14773 struct bgp_redist *red;
14774 bool changed;
14775 struct route_map *route_map =
14776 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
14777
14778 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
14779 if (type < 0) {
14780 vty_out(vty, "%% Invalid route type\n");
14781 return CMD_WARNING_CONFIG_FAILED;
14782 }
14783
14784 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
14785 changed =
14786 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
14787 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
14788 }
14789
14790 DEFUN (bgp_redistribute_ipv6_metric,
14791 bgp_redistribute_ipv6_metric_cmd,
14792 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
14793 "Redistribute information from another routing protocol\n"
14794 FRR_IP6_REDIST_HELP_STR_BGPD
14795 "Metric for redistributed routes\n"
14796 "Default metric\n")
14797 {
14798 VTY_DECLVAR_CONTEXT(bgp, bgp);
14799 int idx_protocol = 1;
14800 int idx_number = 3;
14801 int type;
14802 uint32_t metric;
14803 struct bgp_redist *red;
14804 bool changed;
14805
14806 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
14807 if (type < 0) {
14808 vty_out(vty, "%% Invalid route type\n");
14809 return CMD_WARNING_CONFIG_FAILED;
14810 }
14811 metric = strtoul(argv[idx_number]->arg, NULL, 10);
14812
14813 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
14814 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
14815 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
14816 }
14817
14818 DEFUN (bgp_redistribute_ipv6_rmap_metric,
14819 bgp_redistribute_ipv6_rmap_metric_cmd,
14820 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
14821 "Redistribute information from another routing protocol\n"
14822 FRR_IP6_REDIST_HELP_STR_BGPD
14823 "Route map reference\n"
14824 "Pointer to route-map entries\n"
14825 "Metric for redistributed routes\n"
14826 "Default metric\n")
14827 {
14828 VTY_DECLVAR_CONTEXT(bgp, bgp);
14829 int idx_protocol = 1;
14830 int idx_word = 3;
14831 int idx_number = 5;
14832 int type;
14833 uint32_t metric;
14834 struct bgp_redist *red;
14835 bool changed;
14836 struct route_map *route_map =
14837 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
14838
14839 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
14840 if (type < 0) {
14841 vty_out(vty, "%% Invalid route type\n");
14842 return CMD_WARNING_CONFIG_FAILED;
14843 }
14844 metric = strtoul(argv[idx_number]->arg, NULL, 10);
14845
14846 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
14847 changed =
14848 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
14849 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
14850 metric);
14851 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
14852 }
14853
14854 DEFUN (bgp_redistribute_ipv6_metric_rmap,
14855 bgp_redistribute_ipv6_metric_rmap_cmd,
14856 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
14857 "Redistribute information from another routing protocol\n"
14858 FRR_IP6_REDIST_HELP_STR_BGPD
14859 "Metric for redistributed routes\n"
14860 "Default metric\n"
14861 "Route map reference\n"
14862 "Pointer to route-map entries\n")
14863 {
14864 VTY_DECLVAR_CONTEXT(bgp, bgp);
14865 int idx_protocol = 1;
14866 int idx_number = 3;
14867 int idx_word = 5;
14868 int type;
14869 uint32_t metric;
14870 struct bgp_redist *red;
14871 bool changed;
14872 struct route_map *route_map =
14873 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
14874
14875 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
14876 if (type < 0) {
14877 vty_out(vty, "%% Invalid route type\n");
14878 return CMD_WARNING_CONFIG_FAILED;
14879 }
14880 metric = strtoul(argv[idx_number]->arg, NULL, 10);
14881
14882 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
14883 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
14884 metric);
14885 changed |=
14886 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
14887 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
14888 }
14889
14890 DEFUN (no_bgp_redistribute_ipv6,
14891 no_bgp_redistribute_ipv6_cmd,
14892 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
14893 NO_STR
14894 "Redistribute information from another routing protocol\n"
14895 FRR_IP6_REDIST_HELP_STR_BGPD
14896 "Metric for redistributed routes\n"
14897 "Default metric\n"
14898 "Route map reference\n"
14899 "Pointer to route-map entries\n")
14900 {
14901 VTY_DECLVAR_CONTEXT(bgp, bgp);
14902 int idx_protocol = 2;
14903 int type;
14904
14905 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
14906 if (type < 0) {
14907 vty_out(vty, "%% Invalid route type\n");
14908 return CMD_WARNING_CONFIG_FAILED;
14909 }
14910
14911 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
14912 }
14913
14914 static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
14915 afi_t afi, safi_t safi)
14916 {
14917 int i;
14918
14919 /* Unicast redistribution only. */
14920 if (safi != SAFI_UNICAST)
14921 return;
14922
14923 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
14924 /* Redistribute BGP does not make sense. */
14925 if (i != ZEBRA_ROUTE_BGP) {
14926 struct list *red_list;
14927 struct listnode *node;
14928 struct bgp_redist *red;
14929
14930 red_list = bgp->redist[afi][i];
14931 if (!red_list)
14932 continue;
14933
14934 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
14935 /* "redistribute" configuration. */
14936 vty_out(vty, " redistribute %s",
14937 zebra_route_string(i));
14938 if (red->instance)
14939 vty_out(vty, " %d", red->instance);
14940 if (red->redist_metric_flag)
14941 vty_out(vty, " metric %u",
14942 red->redist_metric);
14943 if (red->rmap.name)
14944 vty_out(vty, " route-map %s",
14945 red->rmap.name);
14946 vty_out(vty, "\n");
14947 }
14948 }
14949 }
14950 }
14951
14952 /* peer-group helpers for config-write */
14953
14954 static bool peergroup_flag_check(struct peer *peer, uint32_t flag)
14955 {
14956 if (!peer_group_active(peer)) {
14957 if (CHECK_FLAG(peer->flags_invert, flag))
14958 return !CHECK_FLAG(peer->flags, flag);
14959 else
14960 return !!CHECK_FLAG(peer->flags, flag);
14961 }
14962
14963 return !!CHECK_FLAG(peer->flags_override, flag);
14964 }
14965
14966 static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
14967 uint32_t flag)
14968 {
14969 if (!peer_group_active(peer)) {
14970 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
14971 return !peer_af_flag_check(peer, afi, safi, flag);
14972 else
14973 return !!peer_af_flag_check(peer, afi, safi, flag);
14974 }
14975
14976 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
14977 }
14978
14979 static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
14980 uint8_t type, int direct)
14981 {
14982 struct bgp_filter *filter;
14983
14984 if (peer_group_active(peer))
14985 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
14986 type);
14987
14988 filter = &peer->filter[afi][safi];
14989 switch (type) {
14990 case PEER_FT_DISTRIBUTE_LIST:
14991 return !!(filter->dlist[direct].name);
14992 case PEER_FT_FILTER_LIST:
14993 return !!(filter->aslist[direct].name);
14994 case PEER_FT_PREFIX_LIST:
14995 return !!(filter->plist[direct].name);
14996 case PEER_FT_ROUTE_MAP:
14997 return !!(filter->map[direct].name);
14998 case PEER_FT_UNSUPPRESS_MAP:
14999 return !!(filter->usmap.name);
15000 default:
15001 return false;
15002 }
15003 }
15004
15005 /* Return true if the addpath type is set for peer and different from
15006 * peer-group.
15007 */
15008 static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi,
15009 safi_t safi)
15010 {
15011 enum bgp_addpath_strat type, g_type;
15012
15013 type = peer->addpath_type[afi][safi];
15014
15015 if (type != BGP_ADDPATH_NONE) {
15016 if (peer_group_active(peer)) {
15017 g_type = peer->group->conf->addpath_type[afi][safi];
15018
15019 if (type != g_type)
15020 return true;
15021 else
15022 return false;
15023 }
15024
15025 return true;
15026 }
15027
15028 return false;
15029 }
15030
15031 /* This is part of the address-family block (unicast only) */
15032 static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
15033 afi_t afi)
15034 {
15035 int indent = 2;
15036
15037 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
15038 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
15039 BGP_CONFIG_VRF_TO_VRF_IMPORT))
15040 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
15041 bgp->vpn_policy[afi]
15042 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
15043 else
15044 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
15045 bgp->vpn_policy[afi]
15046 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
15047 }
15048 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
15049 BGP_CONFIG_VRF_TO_VRF_IMPORT)
15050 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
15051 BGP_CONFIG_VRF_TO_VRF_EXPORT))
15052 return;
15053
15054 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
15055 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
15056
15057 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
15058
15059 } else {
15060 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
15061 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
15062 bgp->vpn_policy[afi].tovpn_label);
15063 }
15064 }
15065 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
15066 BGP_VPN_POLICY_TOVPN_RD_SET)) {
15067 char buf[RD_ADDRSTRLEN];
15068 vty_out(vty, "%*srd vpn export %s\n", indent, "",
15069 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
15070 sizeof(buf)));
15071 }
15072 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
15073 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
15074
15075 char buf[PREFIX_STRLEN];
15076 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
15077 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
15078 sizeof(buf))) {
15079
15080 vty_out(vty, "%*snexthop vpn export %s\n",
15081 indent, "", buf);
15082 }
15083 }
15084 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
15085 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
15086 && ecommunity_cmp(
15087 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
15088 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
15089
15090 char *b = ecommunity_ecom2str(
15091 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
15092 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
15093 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
15094 XFREE(MTYPE_ECOMMUNITY_STR, b);
15095 } else {
15096 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
15097 char *b = ecommunity_ecom2str(
15098 bgp->vpn_policy[afi]
15099 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
15100 ECOMMUNITY_FORMAT_ROUTE_MAP,
15101 ECOMMUNITY_ROUTE_TARGET);
15102 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
15103 XFREE(MTYPE_ECOMMUNITY_STR, b);
15104 }
15105 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
15106 char *b = ecommunity_ecom2str(
15107 bgp->vpn_policy[afi]
15108 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
15109 ECOMMUNITY_FORMAT_ROUTE_MAP,
15110 ECOMMUNITY_ROUTE_TARGET);
15111 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
15112 XFREE(MTYPE_ECOMMUNITY_STR, b);
15113 }
15114 }
15115
15116 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
15117 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
15118 bgp->vpn_policy[afi]
15119 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
15120
15121 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
15122 char *b = ecommunity_ecom2str(
15123 bgp->vpn_policy[afi]
15124 .import_redirect_rtlist,
15125 ECOMMUNITY_FORMAT_ROUTE_MAP,
15126 ECOMMUNITY_ROUTE_TARGET);
15127
15128 if (bgp->vpn_policy[afi].import_redirect_rtlist->unit_size
15129 != ECOMMUNITY_SIZE)
15130 vty_out(vty, "%*srt6 redirect import %s\n",
15131 indent, "", b);
15132 else
15133 vty_out(vty, "%*srt redirect import %s\n",
15134 indent, "", b);
15135 XFREE(MTYPE_ECOMMUNITY_STR, b);
15136 }
15137 }
15138
15139 static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
15140 afi_t afi, safi_t safi)
15141 {
15142 struct bgp_filter *filter;
15143 char *addr;
15144
15145 addr = peer->host;
15146 filter = &peer->filter[afi][safi];
15147
15148 /* distribute-list. */
15149 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
15150 FILTER_IN))
15151 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
15152 filter->dlist[FILTER_IN].name);
15153
15154 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
15155 FILTER_OUT))
15156 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
15157 filter->dlist[FILTER_OUT].name);
15158
15159 /* prefix-list. */
15160 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
15161 FILTER_IN))
15162 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
15163 filter->plist[FILTER_IN].name);
15164
15165 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
15166 FILTER_OUT))
15167 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
15168 filter->plist[FILTER_OUT].name);
15169
15170 /* route-map. */
15171 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
15172 vty_out(vty, " neighbor %s route-map %s in\n", addr,
15173 filter->map[RMAP_IN].name);
15174
15175 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
15176 RMAP_OUT))
15177 vty_out(vty, " neighbor %s route-map %s out\n", addr,
15178 filter->map[RMAP_OUT].name);
15179
15180 /* unsuppress-map */
15181 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
15182 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
15183 filter->usmap.name);
15184
15185 /* filter-list. */
15186 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
15187 FILTER_IN))
15188 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
15189 filter->aslist[FILTER_IN].name);
15190
15191 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
15192 FILTER_OUT))
15193 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
15194 filter->aslist[FILTER_OUT].name);
15195 }
15196
15197 /* BGP peer configuration display function. */
15198 static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
15199 struct peer *peer)
15200 {
15201 struct peer *g_peer = NULL;
15202 char buf[SU_ADDRSTRLEN];
15203 char *addr;
15204 int if_pg_printed = false;
15205 int if_ras_printed = false;
15206
15207 /* Skip dynamic neighbors. */
15208 if (peer_dynamic_neighbor(peer))
15209 return;
15210
15211 if (peer->conf_if)
15212 addr = peer->conf_if;
15213 else
15214 addr = peer->host;
15215
15216 /************************************
15217 ****** Global to the neighbor ******
15218 ************************************/
15219 if (peer->conf_if) {
15220 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
15221 vty_out(vty, " neighbor %s interface v6only", addr);
15222 else
15223 vty_out(vty, " neighbor %s interface", addr);
15224
15225 if (peer_group_active(peer)) {
15226 vty_out(vty, " peer-group %s", peer->group->name);
15227 if_pg_printed = true;
15228 } else if (peer->as_type == AS_SPECIFIED) {
15229 vty_out(vty, " remote-as %u", peer->as);
15230 if_ras_printed = true;
15231 } else if (peer->as_type == AS_INTERNAL) {
15232 vty_out(vty, " remote-as internal");
15233 if_ras_printed = true;
15234 } else if (peer->as_type == AS_EXTERNAL) {
15235 vty_out(vty, " remote-as external");
15236 if_ras_printed = true;
15237 }
15238
15239 vty_out(vty, "\n");
15240 }
15241
15242 /* remote-as and peer-group */
15243 /* peer is a member of a peer-group */
15244 if (peer_group_active(peer)) {
15245 g_peer = peer->group->conf;
15246
15247 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
15248 if (peer->as_type == AS_SPECIFIED) {
15249 vty_out(vty, " neighbor %s remote-as %u\n",
15250 addr, peer->as);
15251 } else if (peer->as_type == AS_INTERNAL) {
15252 vty_out(vty,
15253 " neighbor %s remote-as internal\n",
15254 addr);
15255 } else if (peer->as_type == AS_EXTERNAL) {
15256 vty_out(vty,
15257 " neighbor %s remote-as external\n",
15258 addr);
15259 }
15260 }
15261
15262 /* For swpX peers we displayed the peer-group
15263 * via 'neighbor swpX interface peer-group PGNAME' */
15264 if (!if_pg_printed)
15265 vty_out(vty, " neighbor %s peer-group %s\n", addr,
15266 peer->group->name);
15267 }
15268
15269 /* peer is NOT a member of a peer-group */
15270 else {
15271 /* peer is a peer-group, declare the peer-group */
15272 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
15273 vty_out(vty, " neighbor %s peer-group\n", addr);
15274 }
15275
15276 if (!if_ras_printed) {
15277 if (peer->as_type == AS_SPECIFIED) {
15278 vty_out(vty, " neighbor %s remote-as %u\n",
15279 addr, peer->as);
15280 } else if (peer->as_type == AS_INTERNAL) {
15281 vty_out(vty,
15282 " neighbor %s remote-as internal\n",
15283 addr);
15284 } else if (peer->as_type == AS_EXTERNAL) {
15285 vty_out(vty,
15286 " neighbor %s remote-as external\n",
15287 addr);
15288 }
15289 }
15290 }
15291
15292 /* local-as */
15293 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
15294 vty_out(vty, " neighbor %s local-as %u", addr,
15295 peer->change_local_as);
15296 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
15297 vty_out(vty, " no-prepend");
15298 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
15299 vty_out(vty, " replace-as");
15300 vty_out(vty, "\n");
15301 }
15302
15303 /* description */
15304 if (peer->desc) {
15305 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
15306 }
15307
15308 /* shutdown */
15309 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
15310 if (peer->tx_shutdown_message)
15311 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
15312 peer->tx_shutdown_message);
15313 else
15314 vty_out(vty, " neighbor %s shutdown\n", addr);
15315 }
15316
15317 if (peergroup_flag_check(peer, PEER_FLAG_RTT_SHUTDOWN))
15318 vty_out(vty, " neighbor %s shutdown rtt %u count %u\n", addr,
15319 peer->rtt_expected, peer->rtt_keepalive_conf);
15320
15321 /* bfd */
15322 if (peer->bfd_info) {
15323 if (!peer_group_active(peer) || !g_peer->bfd_info) {
15324 bgp_bfd_peer_config_write(vty, peer, addr);
15325 }
15326 }
15327
15328 /* password */
15329 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
15330 vty_out(vty, " neighbor %s password %s\n", addr,
15331 peer->password);
15332
15333 /* neighbor solo */
15334 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
15335 if (!peer_group_active(peer)) {
15336 vty_out(vty, " neighbor %s solo\n", addr);
15337 }
15338 }
15339
15340 /* BGP port */
15341 if (peer->port != BGP_PORT_DEFAULT) {
15342 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
15343 }
15344
15345 /* Local interface name */
15346 if (peer->ifname) {
15347 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
15348 }
15349
15350 /* passive */
15351 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
15352 vty_out(vty, " neighbor %s passive\n", addr);
15353
15354 /* ebgp-multihop */
15355 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
15356 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
15357 && peer->ttl == MAXTTL)) {
15358 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
15359 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
15360 peer->ttl);
15361 }
15362 }
15363
15364 /* ttl-security hops */
15365 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
15366 if (!peer_group_active(peer)
15367 || g_peer->gtsm_hops != peer->gtsm_hops) {
15368 vty_out(vty, " neighbor %s ttl-security hops %d\n",
15369 addr, peer->gtsm_hops);
15370 }
15371 }
15372
15373 /* disable-connected-check */
15374 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
15375 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
15376
15377 /* enforce-first-as */
15378 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
15379 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
15380
15381 /* update-source */
15382 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
15383 if (peer->update_source)
15384 vty_out(vty, " neighbor %s update-source %s\n", addr,
15385 sockunion2str(peer->update_source, buf,
15386 SU_ADDRSTRLEN));
15387 else if (peer->update_if)
15388 vty_out(vty, " neighbor %s update-source %s\n", addr,
15389 peer->update_if);
15390 }
15391
15392 /* advertisement-interval */
15393 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
15394 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
15395 peer->routeadv);
15396
15397 /* timers */
15398 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
15399 vty_out(vty, " neighbor %s timers %u %u\n", addr,
15400 peer->keepalive, peer->holdtime);
15401
15402 /* timers connect */
15403 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
15404 vty_out(vty, " neighbor %s timers connect %u\n", addr,
15405 peer->connect);
15406 /* need special-case handling for changed default values due to
15407 * config profile / version (because there is no "timers bgp connect"
15408 * command, we need to save this per-peer :/)
15409 */
15410 else if (!peer_group_active(peer) && !peer->connect &&
15411 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
15412 vty_out(vty, " neighbor %s timers connect %u\n", addr,
15413 peer->bgp->default_connect_retry);
15414
15415 /* capability dynamic */
15416 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
15417 vty_out(vty, " neighbor %s capability dynamic\n", addr);
15418
15419 /* capability extended-nexthop */
15420 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
15421 if (!peer->conf_if) {
15422 if (CHECK_FLAG(peer->flags_invert,
15423 PEER_FLAG_CAPABILITY_ENHE))
15424 vty_out(vty,
15425 " no neighbor %s capability extended-nexthop\n",
15426 addr);
15427 else
15428 vty_out(vty,
15429 " neighbor %s capability extended-nexthop\n",
15430 addr);
15431 }
15432 }
15433
15434 /* dont-capability-negotiation */
15435 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
15436 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
15437
15438 /* override-capability */
15439 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
15440 vty_out(vty, " neighbor %s override-capability\n", addr);
15441
15442 /* strict-capability-match */
15443 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
15444 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
15445
15446 /* Sender side AS path loop detection. */
15447 if (peer->as_path_loop_detection)
15448 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
15449 addr);
15450
15451 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
15452 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
15453
15454 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
15455 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
15456 vty_out(vty,
15457 " neighbor %s graceful-restart-helper\n", addr);
15458 } else if (CHECK_FLAG(
15459 peer->peer_gr_new_status_flag,
15460 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
15461 vty_out(vty,
15462 " neighbor %s graceful-restart\n", addr);
15463 } else if (
15464 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
15465 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
15466 && !(CHECK_FLAG(
15467 peer->peer_gr_new_status_flag,
15468 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
15469 vty_out(vty, " neighbor %s graceful-restart-disable\n",
15470 addr);
15471 }
15472 }
15473 }
15474
15475 /* BGP peer configuration display function. */
15476 static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
15477 struct peer *peer, afi_t afi, safi_t safi)
15478 {
15479 struct peer *g_peer = NULL;
15480 char *addr;
15481 bool flag_scomm, flag_secomm, flag_slcomm;
15482
15483 /* Skip dynamic neighbors. */
15484 if (peer_dynamic_neighbor(peer))
15485 return;
15486
15487 if (peer->conf_if)
15488 addr = peer->conf_if;
15489 else
15490 addr = peer->host;
15491
15492 /************************************
15493 ****** Per AF to the neighbor ******
15494 ************************************/
15495 if (peer_group_active(peer)) {
15496 g_peer = peer->group->conf;
15497
15498 /* If the peer-group is active but peer is not, print a 'no
15499 * activate' */
15500 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
15501 vty_out(vty, " no neighbor %s activate\n", addr);
15502 }
15503
15504 /* If the peer-group is not active but peer is, print an
15505 'activate' */
15506 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
15507 vty_out(vty, " neighbor %s activate\n", addr);
15508 }
15509 } else {
15510 if (peer->afc[afi][safi]) {
15511 if ((afi == AFI_IP) && (safi == SAFI_UNICAST)) {
15512 if (CHECK_FLAG(bgp->flags,
15513 BGP_FLAG_NO_DEFAULT_IPV4)) {
15514 vty_out(vty, " neighbor %s activate\n",
15515 addr);
15516 }
15517 } else
15518 vty_out(vty, " neighbor %s activate\n", addr);
15519 } else {
15520 if ((afi == AFI_IP) && (safi == SAFI_UNICAST)) {
15521 if (!CHECK_FLAG(bgp->flags,
15522 BGP_FLAG_NO_DEFAULT_IPV4)) {
15523 vty_out(vty,
15524 " no neighbor %s activate\n",
15525 addr);
15526 }
15527 }
15528 }
15529 }
15530
15531 /* addpath TX knobs */
15532 if (peergroup_af_addpath_check(peer, afi, safi)) {
15533 switch (peer->addpath_type[afi][safi]) {
15534 case BGP_ADDPATH_ALL:
15535 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
15536 addr);
15537 break;
15538 case BGP_ADDPATH_BEST_PER_AS:
15539 vty_out(vty,
15540 " neighbor %s addpath-tx-bestpath-per-AS\n",
15541 addr);
15542 break;
15543 case BGP_ADDPATH_MAX:
15544 case BGP_ADDPATH_NONE:
15545 break;
15546 }
15547 }
15548
15549 /* ORF capability. */
15550 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
15551 || peergroup_af_flag_check(peer, afi, safi,
15552 PEER_FLAG_ORF_PREFIX_RM)) {
15553 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
15554
15555 if (peergroup_af_flag_check(peer, afi, safi,
15556 PEER_FLAG_ORF_PREFIX_SM)
15557 && peergroup_af_flag_check(peer, afi, safi,
15558 PEER_FLAG_ORF_PREFIX_RM))
15559 vty_out(vty, " both");
15560 else if (peergroup_af_flag_check(peer, afi, safi,
15561 PEER_FLAG_ORF_PREFIX_SM))
15562 vty_out(vty, " send");
15563 else
15564 vty_out(vty, " receive");
15565 vty_out(vty, "\n");
15566 }
15567
15568 /* Route reflector client. */
15569 if (peergroup_af_flag_check(peer, afi, safi,
15570 PEER_FLAG_REFLECTOR_CLIENT)) {
15571 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
15572 }
15573
15574 /* next-hop-self force */
15575 if (peergroup_af_flag_check(peer, afi, safi,
15576 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
15577 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
15578 }
15579
15580 /* next-hop-self */
15581 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
15582 vty_out(vty, " neighbor %s next-hop-self\n", addr);
15583 }
15584
15585 /* remove-private-AS */
15586 if (peergroup_af_flag_check(peer, afi, safi,
15587 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
15588 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
15589 addr);
15590 }
15591
15592 else if (peergroup_af_flag_check(peer, afi, safi,
15593 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
15594 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
15595 addr);
15596 }
15597
15598 else if (peergroup_af_flag_check(peer, afi, safi,
15599 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
15600 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
15601 }
15602
15603 else if (peergroup_af_flag_check(peer, afi, safi,
15604 PEER_FLAG_REMOVE_PRIVATE_AS)) {
15605 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
15606 }
15607
15608 /* as-override */
15609 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
15610 vty_out(vty, " neighbor %s as-override\n", addr);
15611 }
15612
15613 /* send-community print. */
15614 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
15615 PEER_FLAG_SEND_COMMUNITY);
15616 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
15617 PEER_FLAG_SEND_EXT_COMMUNITY);
15618 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
15619 PEER_FLAG_SEND_LARGE_COMMUNITY);
15620
15621 if (flag_scomm && flag_secomm && flag_slcomm) {
15622 vty_out(vty, " no neighbor %s send-community all\n", addr);
15623 } else {
15624 if (flag_scomm)
15625 vty_out(vty, " no neighbor %s send-community\n", addr);
15626 if (flag_secomm)
15627 vty_out(vty,
15628 " no neighbor %s send-community extended\n",
15629 addr);
15630
15631 if (flag_slcomm)
15632 vty_out(vty, " no neighbor %s send-community large\n",
15633 addr);
15634 }
15635
15636 /* Default information */
15637 if (peergroup_af_flag_check(peer, afi, safi,
15638 PEER_FLAG_DEFAULT_ORIGINATE)) {
15639 vty_out(vty, " neighbor %s default-originate", addr);
15640
15641 if (peer->default_rmap[afi][safi].name)
15642 vty_out(vty, " route-map %s",
15643 peer->default_rmap[afi][safi].name);
15644
15645 vty_out(vty, "\n");
15646 }
15647
15648 /* Soft reconfiguration inbound. */
15649 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
15650 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
15651 addr);
15652 }
15653
15654 /* maximum-prefix. */
15655 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
15656 vty_out(vty, " neighbor %s maximum-prefix %u", addr,
15657 peer->pmax[afi][safi]);
15658
15659 if (peer->pmax_threshold[afi][safi]
15660 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
15661 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
15662 if (peer_af_flag_check(peer, afi, safi,
15663 PEER_FLAG_MAX_PREFIX_WARNING))
15664 vty_out(vty, " warning-only");
15665 if (peer->pmax_restart[afi][safi])
15666 vty_out(vty, " restart %u",
15667 peer->pmax_restart[afi][safi]);
15668 if (peer_af_flag_check(peer, afi, safi,
15669 PEER_FLAG_MAX_PREFIX_FORCE))
15670 vty_out(vty, " force");
15671
15672 vty_out(vty, "\n");
15673 }
15674
15675 /* maximum-prefix-out */
15676 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
15677 vty_out(vty, " neighbor %s maximum-prefix-out %u\n",
15678 addr, peer->pmax_out[afi][safi]);
15679
15680 /* Route server client. */
15681 if (peergroup_af_flag_check(peer, afi, safi,
15682 PEER_FLAG_RSERVER_CLIENT)) {
15683 vty_out(vty, " neighbor %s route-server-client\n", addr);
15684 }
15685
15686 /* Nexthop-local unchanged. */
15687 if (peergroup_af_flag_check(peer, afi, safi,
15688 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
15689 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
15690 }
15691
15692 /* allowas-in <1-10> */
15693 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
15694 if (peer_af_flag_check(peer, afi, safi,
15695 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
15696 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
15697 } else if (peer->allowas_in[afi][safi] == 3) {
15698 vty_out(vty, " neighbor %s allowas-in\n", addr);
15699 } else {
15700 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
15701 peer->allowas_in[afi][safi]);
15702 }
15703 }
15704
15705 /* weight */
15706 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
15707 vty_out(vty, " neighbor %s weight %lu\n", addr,
15708 peer->weight[afi][safi]);
15709
15710 /* Filter. */
15711 bgp_config_write_filter(vty, peer, afi, safi);
15712
15713 /* atribute-unchanged. */
15714 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
15715 || (safi != SAFI_EVPN
15716 && peer_af_flag_check(peer, afi, safi,
15717 PEER_FLAG_NEXTHOP_UNCHANGED))
15718 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
15719
15720 if (!peer_group_active(peer)
15721 || peergroup_af_flag_check(peer, afi, safi,
15722 PEER_FLAG_AS_PATH_UNCHANGED)
15723 || peergroup_af_flag_check(peer, afi, safi,
15724 PEER_FLAG_NEXTHOP_UNCHANGED)
15725 || peergroup_af_flag_check(peer, afi, safi,
15726 PEER_FLAG_MED_UNCHANGED)) {
15727
15728 vty_out(vty,
15729 " neighbor %s attribute-unchanged%s%s%s\n",
15730 addr,
15731 peer_af_flag_check(peer, afi, safi,
15732 PEER_FLAG_AS_PATH_UNCHANGED)
15733 ? " as-path"
15734 : "",
15735 peer_af_flag_check(peer, afi, safi,
15736 PEER_FLAG_NEXTHOP_UNCHANGED)
15737 ? " next-hop"
15738 : "",
15739 peer_af_flag_check(peer, afi, safi,
15740 PEER_FLAG_MED_UNCHANGED)
15741 ? " med"
15742 : "");
15743 }
15744 }
15745 }
15746
15747 /* Address family based peer configuration display. */
15748 static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
15749 safi_t safi)
15750 {
15751 struct peer *peer;
15752 struct peer_group *group;
15753 struct listnode *node, *nnode;
15754
15755
15756 vty_frame(vty, " !\n address-family ");
15757 if (afi == AFI_IP) {
15758 if (safi == SAFI_UNICAST)
15759 vty_frame(vty, "ipv4 unicast");
15760 else if (safi == SAFI_LABELED_UNICAST)
15761 vty_frame(vty, "ipv4 labeled-unicast");
15762 else if (safi == SAFI_MULTICAST)
15763 vty_frame(vty, "ipv4 multicast");
15764 else if (safi == SAFI_MPLS_VPN)
15765 vty_frame(vty, "ipv4 vpn");
15766 else if (safi == SAFI_ENCAP)
15767 vty_frame(vty, "ipv4 encap");
15768 else if (safi == SAFI_FLOWSPEC)
15769 vty_frame(vty, "ipv4 flowspec");
15770 } else if (afi == AFI_IP6) {
15771 if (safi == SAFI_UNICAST)
15772 vty_frame(vty, "ipv6 unicast");
15773 else if (safi == SAFI_LABELED_UNICAST)
15774 vty_frame(vty, "ipv6 labeled-unicast");
15775 else if (safi == SAFI_MULTICAST)
15776 vty_frame(vty, "ipv6 multicast");
15777 else if (safi == SAFI_MPLS_VPN)
15778 vty_frame(vty, "ipv6 vpn");
15779 else if (safi == SAFI_ENCAP)
15780 vty_frame(vty, "ipv6 encap");
15781 else if (safi == SAFI_FLOWSPEC)
15782 vty_frame(vty, "ipv6 flowspec");
15783 } else if (afi == AFI_L2VPN) {
15784 if (safi == SAFI_EVPN)
15785 vty_frame(vty, "l2vpn evpn");
15786 }
15787 vty_frame(vty, "\n");
15788
15789 bgp_config_write_distance(vty, bgp, afi, safi);
15790
15791 bgp_config_write_network(vty, bgp, afi, safi);
15792
15793 bgp_config_write_redistribute(vty, bgp, afi, safi);
15794
15795 /* BGP flag dampening. */
15796 if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
15797 bgp_config_write_damp(vty, afi, safi);
15798
15799 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
15800 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
15801
15802 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
15803 /* Skip dynamic neighbors. */
15804 if (peer_dynamic_neighbor(peer))
15805 continue;
15806
15807 /* Do not display doppelganger peers */
15808 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
15809 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
15810 }
15811
15812 bgp_config_write_maxpaths(vty, bgp, afi, safi);
15813 bgp_config_write_table_map(vty, bgp, afi, safi);
15814
15815 if (safi == SAFI_EVPN)
15816 bgp_config_write_evpn_info(vty, bgp, afi, safi);
15817
15818 if (safi == SAFI_FLOWSPEC)
15819 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
15820
15821 if (safi == SAFI_UNICAST) {
15822 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
15823 if (CHECK_FLAG(bgp->af_flags[afi][safi],
15824 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
15825
15826 vty_out(vty, " export vpn\n");
15827 }
15828 if (CHECK_FLAG(bgp->af_flags[afi][safi],
15829 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
15830
15831 vty_out(vty, " import vpn\n");
15832 }
15833 if (CHECK_FLAG(bgp->af_flags[afi][safi],
15834 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
15835 char *name;
15836
15837 for (ALL_LIST_ELEMENTS_RO(
15838 bgp->vpn_policy[afi].import_vrf, node,
15839 name))
15840 vty_out(vty, " import vrf %s\n", name);
15841 }
15842 }
15843
15844 vty_endframe(vty, " exit-address-family\n");
15845 }
15846
15847 int bgp_config_write(struct vty *vty)
15848 {
15849 struct bgp *bgp;
15850 struct peer_group *group;
15851 struct peer *peer;
15852 struct listnode *node, *nnode;
15853 struct listnode *mnode, *mnnode;
15854
15855 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
15856 vty_out(vty, "bgp route-map delay-timer %u\n",
15857 bm->rmap_update_timer);
15858
15859 if (bm->v_update_delay != BGP_UPDATE_DELAY_DEF) {
15860 vty_out(vty, "bgp update-delay %d", bm->v_update_delay);
15861 if (bm->v_update_delay != bm->v_establish_wait)
15862 vty_out(vty, " %d", bm->v_establish_wait);
15863 vty_out(vty, "\n");
15864 }
15865
15866 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
15867 vty_out(vty, "bgp graceful-shutdown\n");
15868
15869 /* No-RIB (Zebra) option flag configuration */
15870 if (bgp_option_check(BGP_OPT_NO_FIB))
15871 vty_out(vty, "bgp no-rib\n");
15872
15873 /* BGP configuration. */
15874 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
15875
15876 /* skip all auto created vrf as they dont have user config */
15877 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
15878 continue;
15879
15880 /* Router bgp ASN */
15881 vty_out(vty, "router bgp %u", bgp->as);
15882
15883 if (bgp->name)
15884 vty_out(vty, " %s %s",
15885 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
15886 ? "view" : "vrf", bgp->name);
15887 vty_out(vty, "\n");
15888
15889 /* BGP fast-external-failover. */
15890 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
15891 vty_out(vty, " no bgp fast-external-failover\n");
15892
15893 /* BGP router ID. */
15894 if (bgp->router_id_static.s_addr != 0)
15895 vty_out(vty, " bgp router-id %s\n",
15896 inet_ntoa(bgp->router_id_static));
15897
15898 /* BGP log-neighbor-changes. */
15899 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
15900 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
15901 vty_out(vty, " %sbgp log-neighbor-changes\n",
15902 CHECK_FLAG(bgp->flags,
15903 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
15904 ? ""
15905 : "no ");
15906
15907 /* BGP configuration. */
15908 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
15909 vty_out(vty, " bgp always-compare-med\n");
15910
15911 /* RFC8212 default eBGP policy. */
15912 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
15913 != SAVE_BGP_EBGP_REQUIRES_POLICY)
15914 vty_out(vty, " %sbgp ebgp-requires-policy\n",
15915 CHECK_FLAG(bgp->flags,
15916 BGP_FLAG_EBGP_REQUIRES_POLICY)
15917 ? ""
15918 : "no ");
15919
15920 /* draft-ietf-idr-deprecate-as-set-confed-set */
15921 if (bgp->reject_as_sets)
15922 vty_out(vty, " bgp reject-as-sets\n");
15923
15924 /* BGP default ipv4-unicast. */
15925 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4))
15926 vty_out(vty, " no bgp default ipv4-unicast\n");
15927
15928 /* BGP default local-preference. */
15929 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
15930 vty_out(vty, " bgp default local-preference %u\n",
15931 bgp->default_local_pref);
15932
15933 /* BGP default show-hostname */
15934 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
15935 != SAVE_BGP_SHOW_HOSTNAME)
15936 vty_out(vty, " %sbgp default show-hostname\n",
15937 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
15938 ? ""
15939 : "no ");
15940
15941 /* BGP default show-nexthop-hostname */
15942 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
15943 != SAVE_BGP_SHOW_HOSTNAME)
15944 vty_out(vty, " %sbgp default show-nexthop-hostname\n",
15945 CHECK_FLAG(bgp->flags,
15946 BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
15947 ? ""
15948 : "no ");
15949
15950 /* BGP default subgroup-pkt-queue-max. */
15951 if (bgp->default_subgroup_pkt_queue_max
15952 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
15953 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
15954 bgp->default_subgroup_pkt_queue_max);
15955
15956 /* BGP client-to-client reflection. */
15957 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
15958 vty_out(vty, " no bgp client-to-client reflection\n");
15959
15960 /* BGP cluster ID. */
15961 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
15962 vty_out(vty, " bgp cluster-id %s\n",
15963 inet_ntoa(bgp->cluster_id));
15964
15965 /* Disable ebgp connected nexthop check */
15966 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
15967 vty_out(vty,
15968 " bgp disable-ebgp-connected-route-check\n");
15969
15970 /* Confederation identifier*/
15971 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
15972 vty_out(vty, " bgp confederation identifier %u\n",
15973 bgp->confed_id);
15974
15975 /* Confederation peer */
15976 if (bgp->confed_peers_cnt > 0) {
15977 int i;
15978
15979 vty_out(vty, " bgp confederation peers");
15980
15981 for (i = 0; i < bgp->confed_peers_cnt; i++)
15982 vty_out(vty, " %u", bgp->confed_peers[i]);
15983
15984 vty_out(vty, "\n");
15985 }
15986
15987 /* BGP deterministic-med. */
15988 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
15989 != SAVE_BGP_DETERMINISTIC_MED)
15990 vty_out(vty, " %sbgp deterministic-med\n",
15991 CHECK_FLAG(bgp->flags,
15992 BGP_FLAG_DETERMINISTIC_MED)
15993 ? ""
15994 : "no ");
15995
15996 /* BGP update-delay. */
15997 bgp_config_write_update_delay(vty, bgp);
15998
15999 if (bgp->v_maxmed_onstartup
16000 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
16001 vty_out(vty, " bgp max-med on-startup %u",
16002 bgp->v_maxmed_onstartup);
16003 if (bgp->maxmed_onstartup_value
16004 != BGP_MAXMED_VALUE_DEFAULT)
16005 vty_out(vty, " %u",
16006 bgp->maxmed_onstartup_value);
16007 vty_out(vty, "\n");
16008 }
16009 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
16010 vty_out(vty, " bgp max-med administrative");
16011 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
16012 vty_out(vty, " %u", bgp->maxmed_admin_value);
16013 vty_out(vty, "\n");
16014 }
16015
16016 /* write quanta */
16017 bgp_config_write_wpkt_quanta(vty, bgp);
16018 /* read quanta */
16019 bgp_config_write_rpkt_quanta(vty, bgp);
16020
16021 /* coalesce time */
16022 bgp_config_write_coalesce_time(vty, bgp);
16023
16024 /* BGP per-instance graceful-shutdown */
16025 /* BGP-wide settings and per-instance settings are mutually
16026 * exclusive.
16027 */
16028 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
16029 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
16030 vty_out(vty, " bgp graceful-shutdown\n");
16031
16032 /* BGP graceful-restart. */
16033 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
16034 vty_out(vty,
16035 " bgp graceful-restart stalepath-time %u\n",
16036 bgp->stalepath_time);
16037
16038 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
16039 vty_out(vty, " bgp graceful-restart restart-time %u\n",
16040 bgp->restart_time);
16041
16042 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
16043 vty_out(vty,
16044 " bgp graceful-restart select-defer-time %u\n",
16045 bgp->select_defer_time);
16046
16047 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
16048 vty_out(vty, " bgp graceful-restart\n");
16049
16050 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
16051 vty_out(vty, " bgp graceful-restart-disable\n");
16052
16053 /* BGP graceful-restart Preserve State F bit. */
16054 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
16055 vty_out(vty,
16056 " bgp graceful-restart preserve-fw-state\n");
16057
16058 /* Stale timer for RIB */
16059 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
16060 vty_out(vty,
16061 " bgp graceful-restart rib-stale-time %u\n",
16062 bgp->rib_stale_time);
16063
16064 /* BGP bestpath method. */
16065 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
16066 vty_out(vty, " bgp bestpath as-path ignore\n");
16067 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
16068 vty_out(vty, " bgp bestpath as-path confed\n");
16069
16070 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
16071 if (CHECK_FLAG(bgp->flags,
16072 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
16073 vty_out(vty,
16074 " bgp bestpath as-path multipath-relax as-set\n");
16075 } else {
16076 vty_out(vty,
16077 " bgp bestpath as-path multipath-relax\n");
16078 }
16079 }
16080
16081 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
16082 vty_out(vty,
16083 " bgp route-reflector allow-outbound-policy\n");
16084 }
16085 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
16086 vty_out(vty, " bgp bestpath compare-routerid\n");
16087 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
16088 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
16089 vty_out(vty, " bgp bestpath med");
16090 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
16091 vty_out(vty, " confed");
16092 if (CHECK_FLAG(bgp->flags,
16093 BGP_FLAG_MED_MISSING_AS_WORST))
16094 vty_out(vty, " missing-as-worst");
16095 vty_out(vty, "\n");
16096 }
16097
16098 /* Link bandwidth handling. */
16099 if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW)
16100 vty_out(vty, " bgp bestpath bandwidth ignore\n");
16101 else if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
16102 vty_out(vty, " bgp bestpath bandwidth skip-missing\n");
16103 else if (bgp->lb_handling == BGP_LINK_BW_DEFWT_4_MISSING)
16104 vty_out(vty, " bgp bestpath bandwidth default-weight-for-missing\n");
16105
16106 /* BGP network import check. */
16107 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
16108 != SAVE_BGP_IMPORT_CHECK)
16109 vty_out(vty, " %sbgp network import-check\n",
16110 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
16111 ? ""
16112 : "no ");
16113
16114 /* BGP timers configuration. */
16115 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
16116 && bgp->default_holdtime != SAVE_BGP_HOLDTIME)
16117 vty_out(vty, " timers bgp %u %u\n",
16118 bgp->default_keepalive, bgp->default_holdtime);
16119
16120 /* peer-group */
16121 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
16122 bgp_config_write_peer_global(vty, bgp, group->conf);
16123 }
16124
16125 /* Normal neighbor configuration. */
16126 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
16127 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
16128 bgp_config_write_peer_global(vty, bgp, peer);
16129 }
16130
16131 /* listen range and limit for dynamic BGP neighbors */
16132 bgp_config_write_listen(vty, bgp);
16133
16134 /*
16135 * BGP default autoshutdown neighbors
16136 *
16137 * This must be placed after any peer and peer-group
16138 * configuration, to avoid setting all peers to shutdown after
16139 * a daemon restart, which is undesired behavior. (see #2286)
16140 */
16141 if (bgp->autoshutdown)
16142 vty_out(vty, " bgp default shutdown\n");
16143
16144 /* BGP instance administrative shutdown */
16145 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN))
16146 vty_out(vty, " bgp shutdown\n");
16147
16148 /* IPv4 unicast configuration. */
16149 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
16150
16151 /* IPv4 multicast configuration. */
16152 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
16153
16154 /* IPv4 labeled-unicast configuration. */
16155 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
16156
16157 /* IPv4 VPN configuration. */
16158 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
16159
16160 /* ENCAPv4 configuration. */
16161 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
16162
16163 /* FLOWSPEC v4 configuration. */
16164 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
16165
16166 /* IPv6 unicast configuration. */
16167 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
16168
16169 /* IPv6 multicast configuration. */
16170 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
16171
16172 /* IPv6 labeled-unicast configuration. */
16173 bgp_config_write_family(vty, bgp, AFI_IP6,
16174 SAFI_LABELED_UNICAST);
16175
16176 /* IPv6 VPN configuration. */
16177 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
16178
16179 /* ENCAPv6 configuration. */
16180 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
16181
16182 /* FLOWSPEC v6 configuration. */
16183 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
16184
16185 /* EVPN configuration. */
16186 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
16187
16188 hook_call(bgp_inst_config_write, bgp, vty);
16189
16190 #ifdef ENABLE_BGP_VNC
16191 bgp_rfapi_cfg_write(vty, bgp);
16192 #endif
16193
16194 vty_out(vty, "!\n");
16195 }
16196 return 0;
16197 }
16198
16199
16200 /* BGP node structure. */
16201 static struct cmd_node bgp_node = {
16202 .name = "bgp",
16203 .node = BGP_NODE,
16204 .parent_node = CONFIG_NODE,
16205 .prompt = "%s(config-router)# ",
16206 .config_write = bgp_config_write,
16207 };
16208
16209 static struct cmd_node bgp_ipv4_unicast_node = {
16210 .name = "bgp ipv4 unicast",
16211 .node = BGP_IPV4_NODE,
16212 .parent_node = BGP_NODE,
16213 .prompt = "%s(config-router-af)# ",
16214 };
16215
16216 static struct cmd_node bgp_ipv4_multicast_node = {
16217 .name = "bgp ipv4 multicast",
16218 .node = BGP_IPV4M_NODE,
16219 .parent_node = BGP_NODE,
16220 .prompt = "%s(config-router-af)# ",
16221 };
16222
16223 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
16224 .name = "bgp ipv4 labeled unicast",
16225 .node = BGP_IPV4L_NODE,
16226 .parent_node = BGP_NODE,
16227 .prompt = "%s(config-router-af)# ",
16228 };
16229
16230 static struct cmd_node bgp_ipv6_unicast_node = {
16231 .name = "bgp ipv6",
16232 .node = BGP_IPV6_NODE,
16233 .parent_node = BGP_NODE,
16234 .prompt = "%s(config-router-af)# ",
16235 };
16236
16237 static struct cmd_node bgp_ipv6_multicast_node = {
16238 .name = "bgp ipv6 multicast",
16239 .node = BGP_IPV6M_NODE,
16240 .parent_node = BGP_NODE,
16241 .prompt = "%s(config-router-af)# ",
16242 };
16243
16244 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
16245 .name = "bgp ipv6 labeled unicast",
16246 .node = BGP_IPV6L_NODE,
16247 .parent_node = BGP_NODE,
16248 .prompt = "%s(config-router-af)# ",
16249 };
16250
16251 static struct cmd_node bgp_vpnv4_node = {
16252 .name = "bgp vpnv4",
16253 .node = BGP_VPNV4_NODE,
16254 .parent_node = BGP_NODE,
16255 .prompt = "%s(config-router-af)# ",
16256 };
16257
16258 static struct cmd_node bgp_vpnv6_node = {
16259 .name = "bgp vpnv6",
16260 .node = BGP_VPNV6_NODE,
16261 .parent_node = BGP_NODE,
16262 .prompt = "%s(config-router-af-vpnv6)# ",
16263 };
16264
16265 static struct cmd_node bgp_evpn_node = {
16266 .name = "bgp evpn",
16267 .node = BGP_EVPN_NODE,
16268 .parent_node = BGP_NODE,
16269 .prompt = "%s(config-router-evpn)# ",
16270 };
16271
16272 static struct cmd_node bgp_evpn_vni_node = {
16273 .name = "bgp evpn vni",
16274 .node = BGP_EVPN_VNI_NODE,
16275 .parent_node = BGP_EVPN_NODE,
16276 .prompt = "%s(config-router-af-vni)# ",
16277 };
16278
16279 static struct cmd_node bgp_flowspecv4_node = {
16280 .name = "bgp ipv4 flowspec",
16281 .node = BGP_FLOWSPECV4_NODE,
16282 .parent_node = BGP_NODE,
16283 .prompt = "%s(config-router-af)# ",
16284 };
16285
16286 static struct cmd_node bgp_flowspecv6_node = {
16287 .name = "bgp ipv6 flowspec",
16288 .node = BGP_FLOWSPECV6_NODE,
16289 .parent_node = BGP_NODE,
16290 .prompt = "%s(config-router-af-vpnv6)# ",
16291 };
16292
16293 static void community_list_vty(void);
16294
16295 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
16296 {
16297 struct bgp *bgp;
16298 struct peer *peer;
16299 struct listnode *lnbgp, *lnpeer;
16300
16301 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
16302 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
16303 /* only provide suggestions on the appropriate input
16304 * token type,
16305 * they'll otherwise show up multiple times */
16306 enum cmd_token_type match_type;
16307 char *name = peer->host;
16308
16309 if (peer->conf_if) {
16310 match_type = VARIABLE_TKN;
16311 name = peer->conf_if;
16312 } else if (strchr(peer->host, ':'))
16313 match_type = IPV6_TKN;
16314 else
16315 match_type = IPV4_TKN;
16316
16317 if (token->type != match_type)
16318 continue;
16319
16320 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
16321 }
16322 }
16323 }
16324
16325 static const struct cmd_variable_handler bgp_var_neighbor[] = {
16326 {.varname = "neighbor", .completions = bgp_ac_neighbor},
16327 {.varname = "neighbors", .completions = bgp_ac_neighbor},
16328 {.varname = "peer", .completions = bgp_ac_neighbor},
16329 {.completions = NULL}};
16330
16331 static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
16332 {
16333 struct bgp *bgp;
16334 struct peer_group *group;
16335 struct listnode *lnbgp, *lnpeer;
16336
16337 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
16338 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
16339 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
16340 group->name));
16341 }
16342 }
16343
16344 static const struct cmd_variable_handler bgp_var_peergroup[] = {
16345 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
16346 {.completions = NULL} };
16347
16348 void bgp_vty_init(void)
16349 {
16350 cmd_variable_handler_register(bgp_var_neighbor);
16351 cmd_variable_handler_register(bgp_var_peergroup);
16352
16353 /* Install bgp top node. */
16354 install_node(&bgp_node);
16355 install_node(&bgp_ipv4_unicast_node);
16356 install_node(&bgp_ipv4_multicast_node);
16357 install_node(&bgp_ipv4_labeled_unicast_node);
16358 install_node(&bgp_ipv6_unicast_node);
16359 install_node(&bgp_ipv6_multicast_node);
16360 install_node(&bgp_ipv6_labeled_unicast_node);
16361 install_node(&bgp_vpnv4_node);
16362 install_node(&bgp_vpnv6_node);
16363 install_node(&bgp_evpn_node);
16364 install_node(&bgp_evpn_vni_node);
16365 install_node(&bgp_flowspecv4_node);
16366 install_node(&bgp_flowspecv6_node);
16367
16368 /* Install default VTY commands to new nodes. */
16369 install_default(BGP_NODE);
16370 install_default(BGP_IPV4_NODE);
16371 install_default(BGP_IPV4M_NODE);
16372 install_default(BGP_IPV4L_NODE);
16373 install_default(BGP_IPV6_NODE);
16374 install_default(BGP_IPV6M_NODE);
16375 install_default(BGP_IPV6L_NODE);
16376 install_default(BGP_VPNV4_NODE);
16377 install_default(BGP_VPNV6_NODE);
16378 install_default(BGP_FLOWSPECV4_NODE);
16379 install_default(BGP_FLOWSPECV6_NODE);
16380 install_default(BGP_EVPN_NODE);
16381 install_default(BGP_EVPN_VNI_NODE);
16382
16383 /* "bgp local-mac" hidden commands. */
16384 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
16385 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
16386
16387 /* bgp route-map delay-timer commands. */
16388 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
16389 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
16390
16391 /* global bgp update-delay command */
16392 install_element(CONFIG_NODE, &bgp_global_update_delay_cmd);
16393 install_element(CONFIG_NODE, &no_bgp_global_update_delay_cmd);
16394
16395 /* global bgp graceful-shutdown command */
16396 install_element(CONFIG_NODE, &bgp_graceful_shutdown_cmd);
16397 install_element(CONFIG_NODE, &no_bgp_graceful_shutdown_cmd);
16398
16399 /* Dummy commands (Currently not supported) */
16400 install_element(BGP_NODE, &no_synchronization_cmd);
16401 install_element(BGP_NODE, &no_auto_summary_cmd);
16402
16403 /* "router bgp" commands. */
16404 install_element(CONFIG_NODE, &router_bgp_cmd);
16405
16406 /* "no router bgp" commands. */
16407 install_element(CONFIG_NODE, &no_router_bgp_cmd);
16408
16409 /* "bgp router-id" commands. */
16410 install_element(BGP_NODE, &bgp_router_id_cmd);
16411 install_element(BGP_NODE, &no_bgp_router_id_cmd);
16412
16413 /* "bgp cluster-id" commands. */
16414 install_element(BGP_NODE, &bgp_cluster_id_cmd);
16415 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
16416
16417 /* "bgp no-rib" commands. */
16418 install_element(CONFIG_NODE, &bgp_norib_cmd);
16419 install_element(CONFIG_NODE, &no_bgp_norib_cmd);
16420
16421 /* "bgp confederation" commands. */
16422 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
16423 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
16424
16425 /* "bgp confederation peers" commands. */
16426 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
16427 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
16428
16429 /* bgp max-med command */
16430 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
16431 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
16432 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
16433 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
16434 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
16435
16436 /* bgp disable-ebgp-connected-nh-check */
16437 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
16438 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
16439
16440 /* bgp update-delay command */
16441 install_element(BGP_NODE, &bgp_update_delay_cmd);
16442 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
16443
16444 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
16445 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
16446
16447 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
16448 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
16449
16450 /* "maximum-paths" commands. */
16451 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
16452 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
16453 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
16454 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
16455 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
16456 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
16457 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
16458 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
16459 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
16460 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
16461 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
16462 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
16463 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
16464 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
16465 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
16466
16467 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_cmd);
16468 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_cmd);
16469 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cmd);
16470 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
16471 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_ibgp_cmd);
16472 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
16473 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
16474 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
16475 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
16476 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
16477
16478 /* "timers bgp" commands. */
16479 install_element(BGP_NODE, &bgp_timers_cmd);
16480 install_element(BGP_NODE, &no_bgp_timers_cmd);
16481
16482 /* route-map delay-timer commands - per instance for backwards compat.
16483 */
16484 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
16485 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
16486
16487 /* "bgp client-to-client reflection" commands */
16488 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
16489 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
16490
16491 /* "bgp always-compare-med" commands */
16492 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
16493 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
16494
16495 /* bgp ebgp-requires-policy */
16496 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
16497 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
16498
16499 /* bgp reject-as-sets */
16500 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
16501 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
16502
16503 /* "bgp deterministic-med" commands */
16504 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
16505 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
16506
16507 /* "bgp graceful-restart" command */
16508 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
16509 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
16510
16511 /* "bgp graceful-restart-disable" command */
16512 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
16513 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
16514
16515 /* "neighbor a:b:c:d graceful-restart" command */
16516 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
16517 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
16518
16519 /* "neighbor a:b:c:d graceful-restart-disable" command */
16520 install_element(BGP_NODE,
16521 &bgp_neighbor_graceful_restart_disable_set_cmd);
16522 install_element(BGP_NODE,
16523 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
16524
16525 /* "neighbor a:b:c:d graceful-restart-helper" command */
16526 install_element(BGP_NODE,
16527 &bgp_neighbor_graceful_restart_helper_set_cmd);
16528 install_element(BGP_NODE,
16529 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
16530
16531 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
16532 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
16533 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
16534 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
16535 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
16536 install_element(BGP_NODE,
16537 &no_bgp_graceful_restart_select_defer_time_cmd);
16538 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
16539 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
16540
16541 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
16542 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
16543 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
16544 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
16545
16546 /* "bgp graceful-shutdown" commands */
16547 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
16548 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
16549
16550 /* "bgp fast-external-failover" commands */
16551 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
16552 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
16553
16554 /* "bgp bestpath compare-routerid" commands */
16555 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
16556 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
16557
16558 /* "bgp bestpath as-path ignore" commands */
16559 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
16560 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
16561
16562 /* "bgp bestpath as-path confed" commands */
16563 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
16564 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
16565
16566 /* "bgp bestpath as-path multipath-relax" commands */
16567 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
16568 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
16569
16570 /* "bgp log-neighbor-changes" commands */
16571 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
16572 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
16573
16574 /* "bgp bestpath med" commands */
16575 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
16576 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
16577
16578 /* "bgp bestpath bandwidth" commands */
16579 install_element(BGP_NODE, &bgp_bestpath_bw_cmd);
16580 install_element(BGP_NODE, &no_bgp_bestpath_bw_cmd);
16581
16582 /* "no bgp default ipv4-unicast" commands. */
16583 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
16584 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
16585
16586 /* "bgp network import-check" commands. */
16587 install_element(BGP_NODE, &bgp_network_import_check_cmd);
16588 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
16589 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
16590
16591 /* "bgp default local-preference" commands. */
16592 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
16593 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
16594
16595 /* bgp default show-hostname */
16596 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
16597 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
16598
16599 /* bgp default show-nexthop-hostname */
16600 install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
16601 install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
16602
16603 /* "bgp default subgroup-pkt-queue-max" commands. */
16604 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
16605 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
16606
16607 /* bgp ibgp-allow-policy-mods command */
16608 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
16609 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
16610
16611 /* "bgp listen limit" commands. */
16612 install_element(BGP_NODE, &bgp_listen_limit_cmd);
16613 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
16614
16615 /* "bgp listen range" commands. */
16616 install_element(BGP_NODE, &bgp_listen_range_cmd);
16617 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
16618
16619 /* "bgp default shutdown" command */
16620 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
16621
16622 /* "bgp shutdown" commands */
16623 install_element(BGP_NODE, &bgp_shutdown_cmd);
16624 install_element(BGP_NODE, &bgp_shutdown_msg_cmd);
16625 install_element(BGP_NODE, &no_bgp_shutdown_cmd);
16626 install_element(BGP_NODE, &no_bgp_shutdown_msg_cmd);
16627
16628 /* "neighbor remote-as" commands. */
16629 install_element(BGP_NODE, &neighbor_remote_as_cmd);
16630 install_element(BGP_NODE, &neighbor_interface_config_cmd);
16631 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
16632 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
16633 install_element(BGP_NODE,
16634 &neighbor_interface_v6only_config_remote_as_cmd);
16635 install_element(BGP_NODE, &no_neighbor_cmd);
16636 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
16637
16638 /* "neighbor peer-group" commands. */
16639 install_element(BGP_NODE, &neighbor_peer_group_cmd);
16640 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
16641 install_element(BGP_NODE,
16642 &no_neighbor_interface_peer_group_remote_as_cmd);
16643
16644 /* "neighbor local-as" commands. */
16645 install_element(BGP_NODE, &neighbor_local_as_cmd);
16646 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
16647 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
16648 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
16649
16650 /* "neighbor solo" commands. */
16651 install_element(BGP_NODE, &neighbor_solo_cmd);
16652 install_element(BGP_NODE, &no_neighbor_solo_cmd);
16653
16654 /* "neighbor password" commands. */
16655 install_element(BGP_NODE, &neighbor_password_cmd);
16656 install_element(BGP_NODE, &no_neighbor_password_cmd);
16657
16658 /* "neighbor activate" commands. */
16659 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
16660 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
16661 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
16662 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
16663 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
16664 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
16665 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
16666 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
16667 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
16668 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
16669 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
16670 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
16671
16672 /* "no neighbor activate" commands. */
16673 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
16674 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
16675 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
16676 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
16677 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
16678 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
16679 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
16680 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
16681 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
16682 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
16683 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
16684 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
16685
16686 /* "neighbor peer-group" set commands. */
16687 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
16688 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
16689 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
16690 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
16691 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
16692 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
16693 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
16694 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
16695 install_element(BGP_FLOWSPECV4_NODE,
16696 &neighbor_set_peer_group_hidden_cmd);
16697 install_element(BGP_FLOWSPECV6_NODE,
16698 &neighbor_set_peer_group_hidden_cmd);
16699
16700 /* "no neighbor peer-group unset" commands. */
16701 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
16702 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
16703 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
16704 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
16705 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
16706 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
16707 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
16708 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
16709 install_element(BGP_FLOWSPECV4_NODE,
16710 &no_neighbor_set_peer_group_hidden_cmd);
16711 install_element(BGP_FLOWSPECV6_NODE,
16712 &no_neighbor_set_peer_group_hidden_cmd);
16713
16714 /* "neighbor softreconfiguration inbound" commands.*/
16715 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
16716 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
16717 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
16718 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
16719 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
16720 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
16721 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
16722 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
16723 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
16724 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
16725 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
16726 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
16727 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
16728 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
16729 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
16730 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
16731 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
16732 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
16733 install_element(BGP_FLOWSPECV4_NODE,
16734 &neighbor_soft_reconfiguration_cmd);
16735 install_element(BGP_FLOWSPECV4_NODE,
16736 &no_neighbor_soft_reconfiguration_cmd);
16737 install_element(BGP_FLOWSPECV6_NODE,
16738 &neighbor_soft_reconfiguration_cmd);
16739 install_element(BGP_FLOWSPECV6_NODE,
16740 &no_neighbor_soft_reconfiguration_cmd);
16741 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
16742 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
16743
16744 /* "neighbor attribute-unchanged" commands. */
16745 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
16746 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
16747 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
16748 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
16749 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
16750 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
16751 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
16752 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
16753 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
16754 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
16755 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
16756 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
16757 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
16758 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
16759 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
16760 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
16761 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
16762 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
16763
16764 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
16765 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
16766
16767 /* "nexthop-local unchanged" commands */
16768 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
16769 install_element(BGP_IPV6_NODE,
16770 &no_neighbor_nexthop_local_unchanged_cmd);
16771
16772 /* "neighbor next-hop-self" commands. */
16773 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
16774 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
16775 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
16776 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
16777 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
16778 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
16779 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
16780 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
16781 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
16782 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
16783 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
16784 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
16785 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
16786 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
16787 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
16788 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
16789 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
16790 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
16791 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
16792 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
16793
16794 /* "neighbor next-hop-self force" commands. */
16795 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
16796 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
16797 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
16798 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
16799 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
16800 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
16801 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
16802 install_element(BGP_IPV4_NODE,
16803 &no_neighbor_nexthop_self_all_hidden_cmd);
16804 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
16805 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
16806 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
16807 install_element(BGP_IPV4M_NODE,
16808 &no_neighbor_nexthop_self_all_hidden_cmd);
16809 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
16810 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
16811 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
16812 install_element(BGP_IPV4L_NODE,
16813 &no_neighbor_nexthop_self_all_hidden_cmd);
16814 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
16815 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
16816 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
16817 install_element(BGP_IPV6_NODE,
16818 &no_neighbor_nexthop_self_all_hidden_cmd);
16819 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
16820 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
16821 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
16822 install_element(BGP_IPV6M_NODE,
16823 &no_neighbor_nexthop_self_all_hidden_cmd);
16824 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
16825 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
16826 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
16827 install_element(BGP_IPV6L_NODE,
16828 &no_neighbor_nexthop_self_all_hidden_cmd);
16829 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
16830 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
16831 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
16832 install_element(BGP_VPNV4_NODE,
16833 &no_neighbor_nexthop_self_all_hidden_cmd);
16834 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
16835 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
16836 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
16837 install_element(BGP_VPNV6_NODE,
16838 &no_neighbor_nexthop_self_all_hidden_cmd);
16839 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_force_cmd);
16840 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_force_cmd);
16841
16842 /* "neighbor as-override" commands. */
16843 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
16844 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
16845 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
16846 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
16847 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
16848 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
16849 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
16850 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
16851 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
16852 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
16853 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
16854 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
16855 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
16856 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
16857 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
16858 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
16859 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
16860 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
16861
16862 /* "neighbor remove-private-AS" commands. */
16863 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
16864 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
16865 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
16866 install_element(BGP_NODE,
16867 &no_neighbor_remove_private_as_all_hidden_cmd);
16868 install_element(BGP_NODE,
16869 &neighbor_remove_private_as_replace_as_hidden_cmd);
16870 install_element(BGP_NODE,
16871 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
16872 install_element(BGP_NODE,
16873 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
16874 install_element(
16875 BGP_NODE,
16876 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
16877 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
16878 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
16879 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
16880 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
16881 install_element(BGP_IPV4_NODE,
16882 &neighbor_remove_private_as_replace_as_cmd);
16883 install_element(BGP_IPV4_NODE,
16884 &no_neighbor_remove_private_as_replace_as_cmd);
16885 install_element(BGP_IPV4_NODE,
16886 &neighbor_remove_private_as_all_replace_as_cmd);
16887 install_element(BGP_IPV4_NODE,
16888 &no_neighbor_remove_private_as_all_replace_as_cmd);
16889 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
16890 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
16891 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
16892 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
16893 install_element(BGP_IPV4M_NODE,
16894 &neighbor_remove_private_as_replace_as_cmd);
16895 install_element(BGP_IPV4M_NODE,
16896 &no_neighbor_remove_private_as_replace_as_cmd);
16897 install_element(BGP_IPV4M_NODE,
16898 &neighbor_remove_private_as_all_replace_as_cmd);
16899 install_element(BGP_IPV4M_NODE,
16900 &no_neighbor_remove_private_as_all_replace_as_cmd);
16901 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
16902 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
16903 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
16904 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
16905 install_element(BGP_IPV4L_NODE,
16906 &neighbor_remove_private_as_replace_as_cmd);
16907 install_element(BGP_IPV4L_NODE,
16908 &no_neighbor_remove_private_as_replace_as_cmd);
16909 install_element(BGP_IPV4L_NODE,
16910 &neighbor_remove_private_as_all_replace_as_cmd);
16911 install_element(BGP_IPV4L_NODE,
16912 &no_neighbor_remove_private_as_all_replace_as_cmd);
16913 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
16914 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
16915 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
16916 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
16917 install_element(BGP_IPV6_NODE,
16918 &neighbor_remove_private_as_replace_as_cmd);
16919 install_element(BGP_IPV6_NODE,
16920 &no_neighbor_remove_private_as_replace_as_cmd);
16921 install_element(BGP_IPV6_NODE,
16922 &neighbor_remove_private_as_all_replace_as_cmd);
16923 install_element(BGP_IPV6_NODE,
16924 &no_neighbor_remove_private_as_all_replace_as_cmd);
16925 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
16926 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
16927 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
16928 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
16929 install_element(BGP_IPV6M_NODE,
16930 &neighbor_remove_private_as_replace_as_cmd);
16931 install_element(BGP_IPV6M_NODE,
16932 &no_neighbor_remove_private_as_replace_as_cmd);
16933 install_element(BGP_IPV6M_NODE,
16934 &neighbor_remove_private_as_all_replace_as_cmd);
16935 install_element(BGP_IPV6M_NODE,
16936 &no_neighbor_remove_private_as_all_replace_as_cmd);
16937 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
16938 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
16939 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
16940 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
16941 install_element(BGP_IPV6L_NODE,
16942 &neighbor_remove_private_as_replace_as_cmd);
16943 install_element(BGP_IPV6L_NODE,
16944 &no_neighbor_remove_private_as_replace_as_cmd);
16945 install_element(BGP_IPV6L_NODE,
16946 &neighbor_remove_private_as_all_replace_as_cmd);
16947 install_element(BGP_IPV6L_NODE,
16948 &no_neighbor_remove_private_as_all_replace_as_cmd);
16949 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
16950 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
16951 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
16952 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
16953 install_element(BGP_VPNV4_NODE,
16954 &neighbor_remove_private_as_replace_as_cmd);
16955 install_element(BGP_VPNV4_NODE,
16956 &no_neighbor_remove_private_as_replace_as_cmd);
16957 install_element(BGP_VPNV4_NODE,
16958 &neighbor_remove_private_as_all_replace_as_cmd);
16959 install_element(BGP_VPNV4_NODE,
16960 &no_neighbor_remove_private_as_all_replace_as_cmd);
16961 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
16962 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
16963 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
16964 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
16965 install_element(BGP_VPNV6_NODE,
16966 &neighbor_remove_private_as_replace_as_cmd);
16967 install_element(BGP_VPNV6_NODE,
16968 &no_neighbor_remove_private_as_replace_as_cmd);
16969 install_element(BGP_VPNV6_NODE,
16970 &neighbor_remove_private_as_all_replace_as_cmd);
16971 install_element(BGP_VPNV6_NODE,
16972 &no_neighbor_remove_private_as_all_replace_as_cmd);
16973
16974 /* "neighbor send-community" commands.*/
16975 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
16976 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
16977 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
16978 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
16979 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
16980 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
16981 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
16982 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
16983 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
16984 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
16985 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
16986 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
16987 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
16988 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
16989 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
16990 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
16991 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
16992 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
16993 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
16994 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
16995 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
16996 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
16997 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
16998 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
16999 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
17000 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
17001 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
17002 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
17003 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
17004 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
17005 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
17006 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
17007 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
17008 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
17009 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
17010 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
17011
17012 /* "neighbor route-reflector" commands.*/
17013 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
17014 install_element(BGP_NODE,
17015 &no_neighbor_route_reflector_client_hidden_cmd);
17016 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
17017 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
17018 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
17019 install_element(BGP_IPV4M_NODE,
17020 &no_neighbor_route_reflector_client_cmd);
17021 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
17022 install_element(BGP_IPV4L_NODE,
17023 &no_neighbor_route_reflector_client_cmd);
17024 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
17025 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
17026 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
17027 install_element(BGP_IPV6M_NODE,
17028 &no_neighbor_route_reflector_client_cmd);
17029 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
17030 install_element(BGP_IPV6L_NODE,
17031 &no_neighbor_route_reflector_client_cmd);
17032 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
17033 install_element(BGP_VPNV4_NODE,
17034 &no_neighbor_route_reflector_client_cmd);
17035 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
17036 install_element(BGP_VPNV6_NODE,
17037 &no_neighbor_route_reflector_client_cmd);
17038 install_element(BGP_FLOWSPECV4_NODE,
17039 &neighbor_route_reflector_client_cmd);
17040 install_element(BGP_FLOWSPECV4_NODE,
17041 &no_neighbor_route_reflector_client_cmd);
17042 install_element(BGP_FLOWSPECV6_NODE,
17043 &neighbor_route_reflector_client_cmd);
17044 install_element(BGP_FLOWSPECV6_NODE,
17045 &no_neighbor_route_reflector_client_cmd);
17046 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
17047 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
17048
17049 /* "neighbor route-server" commands.*/
17050 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
17051 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
17052 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
17053 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
17054 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
17055 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
17056 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
17057 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
17058 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
17059 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
17060 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
17061 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
17062 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
17063 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
17064 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
17065 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
17066 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
17067 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
17068 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
17069 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
17070 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
17071 install_element(BGP_FLOWSPECV4_NODE,
17072 &no_neighbor_route_server_client_cmd);
17073 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
17074 install_element(BGP_FLOWSPECV6_NODE,
17075 &no_neighbor_route_server_client_cmd);
17076
17077 /* "neighbor addpath-tx-all-paths" commands.*/
17078 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
17079 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
17080 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
17081 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
17082 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
17083 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
17084 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
17085 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
17086 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
17087 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
17088 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
17089 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
17090 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
17091 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
17092 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
17093 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
17094 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
17095 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
17096
17097 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
17098 install_element(BGP_NODE,
17099 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
17100 install_element(BGP_NODE,
17101 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
17102 install_element(BGP_IPV4_NODE,
17103 &neighbor_addpath_tx_bestpath_per_as_cmd);
17104 install_element(BGP_IPV4_NODE,
17105 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
17106 install_element(BGP_IPV4M_NODE,
17107 &neighbor_addpath_tx_bestpath_per_as_cmd);
17108 install_element(BGP_IPV4M_NODE,
17109 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
17110 install_element(BGP_IPV4L_NODE,
17111 &neighbor_addpath_tx_bestpath_per_as_cmd);
17112 install_element(BGP_IPV4L_NODE,
17113 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
17114 install_element(BGP_IPV6_NODE,
17115 &neighbor_addpath_tx_bestpath_per_as_cmd);
17116 install_element(BGP_IPV6_NODE,
17117 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
17118 install_element(BGP_IPV6M_NODE,
17119 &neighbor_addpath_tx_bestpath_per_as_cmd);
17120 install_element(BGP_IPV6M_NODE,
17121 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
17122 install_element(BGP_IPV6L_NODE,
17123 &neighbor_addpath_tx_bestpath_per_as_cmd);
17124 install_element(BGP_IPV6L_NODE,
17125 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
17126 install_element(BGP_VPNV4_NODE,
17127 &neighbor_addpath_tx_bestpath_per_as_cmd);
17128 install_element(BGP_VPNV4_NODE,
17129 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
17130 install_element(BGP_VPNV6_NODE,
17131 &neighbor_addpath_tx_bestpath_per_as_cmd);
17132 install_element(BGP_VPNV6_NODE,
17133 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
17134
17135 /* "neighbor sender-as-path-loop-detection" commands. */
17136 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
17137 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
17138
17139 /* "neighbor passive" commands. */
17140 install_element(BGP_NODE, &neighbor_passive_cmd);
17141 install_element(BGP_NODE, &no_neighbor_passive_cmd);
17142
17143
17144 /* "neighbor shutdown" commands. */
17145 install_element(BGP_NODE, &neighbor_shutdown_cmd);
17146 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
17147 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
17148 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
17149 install_element(BGP_NODE, &neighbor_shutdown_rtt_cmd);
17150 install_element(BGP_NODE, &no_neighbor_shutdown_rtt_cmd);
17151
17152 /* "neighbor capability extended-nexthop" commands.*/
17153 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
17154 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
17155
17156 /* "neighbor capability orf prefix-list" commands.*/
17157 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
17158 install_element(BGP_NODE,
17159 &no_neighbor_capability_orf_prefix_hidden_cmd);
17160 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
17161 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
17162 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
17163 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
17164 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
17165 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
17166 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
17167 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
17168 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
17169 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
17170 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
17171 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
17172
17173 /* "neighbor capability dynamic" commands.*/
17174 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
17175 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
17176
17177 /* "neighbor dont-capability-negotiate" commands. */
17178 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
17179 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
17180
17181 /* "neighbor ebgp-multihop" commands. */
17182 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
17183 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
17184 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
17185
17186 /* "neighbor disable-connected-check" commands. */
17187 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
17188 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
17189
17190 /* "neighbor enforce-first-as" commands. */
17191 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
17192 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
17193
17194 /* "neighbor description" commands. */
17195 install_element(BGP_NODE, &neighbor_description_cmd);
17196 install_element(BGP_NODE, &no_neighbor_description_cmd);
17197 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
17198
17199 /* "neighbor update-source" commands. "*/
17200 install_element(BGP_NODE, &neighbor_update_source_cmd);
17201 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
17202
17203 /* "neighbor default-originate" commands. */
17204 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
17205 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
17206 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
17207 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
17208 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
17209 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
17210 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
17211 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
17212 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
17213 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
17214 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
17215 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
17216 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
17217 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
17218 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
17219 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
17220 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
17221 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
17222 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
17223 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
17224 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
17225
17226 /* "neighbor port" commands. */
17227 install_element(BGP_NODE, &neighbor_port_cmd);
17228 install_element(BGP_NODE, &no_neighbor_port_cmd);
17229
17230 /* "neighbor weight" commands. */
17231 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
17232 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
17233
17234 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
17235 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
17236 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
17237 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
17238 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
17239 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
17240 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
17241 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
17242 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
17243 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
17244 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
17245 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
17246 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
17247 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
17248 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
17249 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
17250
17251 /* "neighbor override-capability" commands. */
17252 install_element(BGP_NODE, &neighbor_override_capability_cmd);
17253 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
17254
17255 /* "neighbor strict-capability-match" commands. */
17256 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
17257 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
17258
17259 /* "neighbor timers" commands. */
17260 install_element(BGP_NODE, &neighbor_timers_cmd);
17261 install_element(BGP_NODE, &no_neighbor_timers_cmd);
17262
17263 /* "neighbor timers connect" commands. */
17264 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
17265 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
17266
17267 /* "neighbor advertisement-interval" commands. */
17268 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
17269 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
17270
17271 /* "neighbor interface" commands. */
17272 install_element(BGP_NODE, &neighbor_interface_cmd);
17273 install_element(BGP_NODE, &no_neighbor_interface_cmd);
17274
17275 /* "neighbor distribute" commands. */
17276 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
17277 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
17278 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
17279 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
17280 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
17281 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
17282 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
17283 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
17284 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
17285 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
17286 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
17287 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
17288 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
17289 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
17290 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
17291 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
17292 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
17293 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
17294
17295 /* "neighbor prefix-list" commands. */
17296 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
17297 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
17298 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
17299 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
17300 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
17301 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
17302 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
17303 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
17304 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
17305 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
17306 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
17307 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
17308 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
17309 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
17310 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
17311 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
17312 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
17313 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
17314 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
17315 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
17316 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
17317 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
17318
17319 /* "neighbor filter-list" commands. */
17320 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
17321 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
17322 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
17323 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
17324 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
17325 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
17326 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
17327 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
17328 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
17329 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
17330 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
17331 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
17332 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
17333 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
17334 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
17335 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
17336 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
17337 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
17338 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
17339 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
17340 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
17341 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
17342
17343 /* "neighbor route-map" commands. */
17344 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
17345 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
17346 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
17347 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
17348 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
17349 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
17350 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
17351 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
17352 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
17353 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
17354 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
17355 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
17356 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
17357 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
17358 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
17359 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
17360 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
17361 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
17362 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
17363 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
17364 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
17365 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
17366 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
17367 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
17368
17369 /* "neighbor unsuppress-map" commands. */
17370 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
17371 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
17372 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
17373 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
17374 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
17375 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
17376 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
17377 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
17378 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
17379 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
17380 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
17381 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
17382 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
17383 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
17384 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
17385 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
17386 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
17387 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
17388
17389 /* neighbor maximum-prefix-out commands. */
17390 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
17391 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
17392 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
17393 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
17394 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
17395 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
17396 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
17397 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
17398 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
17399 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
17400 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
17401 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
17402 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
17403 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
17404 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
17405 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
17406 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
17407 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
17408
17409 /* "neighbor maximum-prefix" commands. */
17410 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
17411 install_element(BGP_NODE,
17412 &neighbor_maximum_prefix_threshold_hidden_cmd);
17413 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
17414 install_element(BGP_NODE,
17415 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
17416 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
17417 install_element(BGP_NODE,
17418 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
17419 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
17420 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
17421 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
17422 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
17423 install_element(BGP_IPV4_NODE,
17424 &neighbor_maximum_prefix_threshold_warning_cmd);
17425 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
17426 install_element(BGP_IPV4_NODE,
17427 &neighbor_maximum_prefix_threshold_restart_cmd);
17428 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
17429 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
17430 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
17431 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
17432 install_element(BGP_IPV4M_NODE,
17433 &neighbor_maximum_prefix_threshold_warning_cmd);
17434 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
17435 install_element(BGP_IPV4M_NODE,
17436 &neighbor_maximum_prefix_threshold_restart_cmd);
17437 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
17438 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
17439 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
17440 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
17441 install_element(BGP_IPV4L_NODE,
17442 &neighbor_maximum_prefix_threshold_warning_cmd);
17443 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
17444 install_element(BGP_IPV4L_NODE,
17445 &neighbor_maximum_prefix_threshold_restart_cmd);
17446 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
17447 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
17448 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
17449 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
17450 install_element(BGP_IPV6_NODE,
17451 &neighbor_maximum_prefix_threshold_warning_cmd);
17452 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
17453 install_element(BGP_IPV6_NODE,
17454 &neighbor_maximum_prefix_threshold_restart_cmd);
17455 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
17456 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
17457 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
17458 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
17459 install_element(BGP_IPV6M_NODE,
17460 &neighbor_maximum_prefix_threshold_warning_cmd);
17461 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
17462 install_element(BGP_IPV6M_NODE,
17463 &neighbor_maximum_prefix_threshold_restart_cmd);
17464 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
17465 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
17466 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
17467 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
17468 install_element(BGP_IPV6L_NODE,
17469 &neighbor_maximum_prefix_threshold_warning_cmd);
17470 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
17471 install_element(BGP_IPV6L_NODE,
17472 &neighbor_maximum_prefix_threshold_restart_cmd);
17473 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
17474 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
17475 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
17476 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
17477 install_element(BGP_VPNV4_NODE,
17478 &neighbor_maximum_prefix_threshold_warning_cmd);
17479 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
17480 install_element(BGP_VPNV4_NODE,
17481 &neighbor_maximum_prefix_threshold_restart_cmd);
17482 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
17483 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
17484 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
17485 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
17486 install_element(BGP_VPNV6_NODE,
17487 &neighbor_maximum_prefix_threshold_warning_cmd);
17488 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
17489 install_element(BGP_VPNV6_NODE,
17490 &neighbor_maximum_prefix_threshold_restart_cmd);
17491 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
17492
17493 /* "neighbor allowas-in" */
17494 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
17495 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
17496 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
17497 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
17498 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
17499 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
17500 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
17501 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
17502 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
17503 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
17504 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
17505 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
17506 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
17507 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
17508 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
17509 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
17510 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
17511 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
17512 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
17513 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
17514
17515 /* address-family commands. */
17516 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
17517 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
17518 #ifdef KEEP_OLD_VPN_COMMANDS
17519 install_element(BGP_NODE, &address_family_vpnv4_cmd);
17520 install_element(BGP_NODE, &address_family_vpnv6_cmd);
17521 #endif /* KEEP_OLD_VPN_COMMANDS */
17522
17523 install_element(BGP_NODE, &address_family_evpn_cmd);
17524
17525 /* "exit-address-family" command. */
17526 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
17527 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
17528 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
17529 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
17530 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
17531 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
17532 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
17533 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
17534 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
17535 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
17536 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
17537
17538 /* "clear ip bgp commands" */
17539 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
17540
17541 /* clear ip bgp prefix */
17542 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
17543 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
17544 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
17545
17546 /* "show [ip] bgp summary" commands. */
17547 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
17548 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
17549 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
17550 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
17551 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
17552 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
17553 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
17554
17555 /* "show [ip] bgp neighbors" commands. */
17556 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
17557
17558 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
17559
17560 /* "show [ip] bgp peer-group" commands. */
17561 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
17562
17563 /* "show [ip] bgp paths" commands. */
17564 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
17565
17566 /* "show [ip] bgp community" commands. */
17567 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
17568
17569 /* "show ip bgp large-community" commands. */
17570 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
17571 /* "show [ip] bgp attribute-info" commands. */
17572 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
17573 /* "show [ip] bgp route-leak" command */
17574 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
17575
17576 /* "redistribute" commands. */
17577 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
17578 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
17579 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
17580 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
17581 install_element(BGP_NODE,
17582 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
17583 install_element(BGP_NODE,
17584 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
17585 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
17586 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
17587 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
17588 install_element(BGP_NODE,
17589 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
17590 install_element(BGP_NODE,
17591 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
17592 install_element(BGP_NODE,
17593 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
17594 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
17595 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
17596 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
17597 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
17598 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
17599 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
17600 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
17601 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
17602 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
17603 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
17604 install_element(BGP_IPV4_NODE,
17605 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
17606 install_element(BGP_IPV4_NODE,
17607 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
17608 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
17609 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
17610 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
17611 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
17612 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
17613 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
17614
17615 /* import|export vpn [route-map WORD] */
17616 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
17617 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
17618
17619 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
17620 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
17621
17622 /* ttl_security commands */
17623 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
17624 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
17625
17626 /* "show [ip] bgp memory" commands. */
17627 install_element(VIEW_NODE, &show_bgp_memory_cmd);
17628
17629 /* "show bgp martian next-hop" */
17630 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
17631
17632 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
17633
17634 /* "show [ip] bgp views" commands. */
17635 install_element(VIEW_NODE, &show_bgp_views_cmd);
17636
17637 /* "show [ip] bgp vrfs" commands. */
17638 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
17639
17640 /* Community-list. */
17641 community_list_vty();
17642
17643 /* vpn-policy commands */
17644 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
17645 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
17646 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
17647 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
17648 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
17649 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
17650 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
17651 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
17652 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
17653 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
17654 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
17655 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
17656
17657 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
17658 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
17659
17660 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
17661 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
17662 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
17663 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
17664 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
17665 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
17666 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
17667 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
17668 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
17669 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
17670 }
17671
17672 #include "memory.h"
17673 #include "bgp_regex.h"
17674 #include "bgp_clist.h"
17675 #include "bgp_ecommunity.h"
17676
17677 /* VTY functions. */
17678
17679 /* Direction value to string conversion. */
17680 static const char *community_direct_str(int direct)
17681 {
17682 switch (direct) {
17683 case COMMUNITY_DENY:
17684 return "deny";
17685 case COMMUNITY_PERMIT:
17686 return "permit";
17687 default:
17688 return "unknown";
17689 }
17690 }
17691
17692 /* Display error string. */
17693 static void community_list_perror(struct vty *vty, int ret)
17694 {
17695 switch (ret) {
17696 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
17697 vty_out(vty, "%% Can't find community-list\n");
17698 break;
17699 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
17700 vty_out(vty, "%% Malformed community-list value\n");
17701 break;
17702 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
17703 vty_out(vty,
17704 "%% Community name conflict, previously defined as standard community\n");
17705 break;
17706 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
17707 vty_out(vty,
17708 "%% Community name conflict, previously defined as expanded community\n");
17709 break;
17710 }
17711 }
17712
17713 /* "community-list" keyword help string. */
17714 #define COMMUNITY_LIST_STR "Add a community list entry\n"
17715
17716 /*community-list standard */
17717 DEFUN (community_list_standard,
17718 bgp_community_list_standard_cmd,
17719 "bgp community-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
17720 BGP_STR
17721 COMMUNITY_LIST_STR
17722 "Community list number (standard)\n"
17723 "Add an standard community-list entry\n"
17724 "Community list name\n"
17725 "Sequence number of an entry\n"
17726 "Sequence number\n"
17727 "Specify community to reject\n"
17728 "Specify community to accept\n"
17729 COMMUNITY_VAL_STR)
17730 {
17731 char *cl_name_or_number = NULL;
17732 char *seq = NULL;
17733 int direct = 0;
17734 int style = COMMUNITY_LIST_STANDARD;
17735 int idx = 0;
17736
17737 argv_find(argv, argc, "(1-4294967295)", &idx);
17738 if (idx)
17739 seq = argv[idx]->arg;
17740
17741 idx = 0;
17742 argv_find(argv, argc, "(1-99)", &idx);
17743 argv_find(argv, argc, "WORD", &idx);
17744 cl_name_or_number = argv[idx]->arg;
17745 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
17746 : COMMUNITY_DENY;
17747 argv_find(argv, argc, "AA:NN", &idx);
17748 char *str = argv_concat(argv, argc, idx);
17749
17750 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
17751 direct, style);
17752
17753 XFREE(MTYPE_TMP, str);
17754
17755 if (ret < 0) {
17756 /* Display error string. */
17757 community_list_perror(vty, ret);
17758 return CMD_WARNING_CONFIG_FAILED;
17759 }
17760
17761 return CMD_SUCCESS;
17762 }
17763
17764 DEFUN (no_community_list_standard_all,
17765 no_bgp_community_list_standard_all_cmd,
17766 "no bgp community-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
17767 NO_STR
17768 BGP_STR
17769 COMMUNITY_LIST_STR
17770 "Community list number (standard)\n"
17771 "Add an standard community-list entry\n"
17772 "Community list name\n"
17773 "Sequence number of an entry\n"
17774 "Sequence number\n"
17775 "Specify community to reject\n"
17776 "Specify community to accept\n"
17777 COMMUNITY_VAL_STR)
17778 {
17779 char *cl_name_or_number = NULL;
17780 char *str = NULL;
17781 int direct = 0;
17782 int style = COMMUNITY_LIST_STANDARD;
17783 char *seq = NULL;
17784 int idx = 0;
17785
17786 argv_find(argv, argc, "(1-4294967295)", &idx);
17787 if (idx)
17788 seq = argv[idx]->arg;
17789
17790 idx = 0;
17791 argv_find(argv, argc, "permit", &idx);
17792 argv_find(argv, argc, "deny", &idx);
17793
17794 if (idx) {
17795 direct = argv_find(argv, argc, "permit", &idx)
17796 ? COMMUNITY_PERMIT
17797 : COMMUNITY_DENY;
17798
17799 idx = 0;
17800 argv_find(argv, argc, "AA:NN", &idx);
17801 str = argv_concat(argv, argc, idx);
17802 }
17803
17804 idx = 0;
17805 argv_find(argv, argc, "(1-99)", &idx);
17806 argv_find(argv, argc, "WORD", &idx);
17807 cl_name_or_number = argv[idx]->arg;
17808
17809 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
17810 direct, style);
17811
17812 XFREE(MTYPE_TMP, str);
17813
17814 if (ret < 0) {
17815 community_list_perror(vty, ret);
17816 return CMD_WARNING_CONFIG_FAILED;
17817 }
17818
17819 return CMD_SUCCESS;
17820 }
17821
17822 ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
17823 "no bgp community-list <(1-99)|standard WORD>",
17824 NO_STR BGP_STR COMMUNITY_LIST_STR
17825 "Community list number (standard)\n"
17826 "Add an standard community-list entry\n"
17827 "Community list name\n")
17828
17829 /*community-list expanded */
17830 DEFUN (community_list_expanded_all,
17831 bgp_community_list_expanded_all_cmd,
17832 "bgp community-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
17833 BGP_STR
17834 COMMUNITY_LIST_STR
17835 "Community list number (expanded)\n"
17836 "Add an expanded community-list entry\n"
17837 "Community list name\n"
17838 "Sequence number of an entry\n"
17839 "Sequence number\n"
17840 "Specify community to reject\n"
17841 "Specify community to accept\n"
17842 COMMUNITY_VAL_STR)
17843 {
17844 char *cl_name_or_number = NULL;
17845 char *seq = NULL;
17846 int direct = 0;
17847 int style = COMMUNITY_LIST_EXPANDED;
17848 int idx = 0;
17849
17850 argv_find(argv, argc, "(1-4294967295)", &idx);
17851 if (idx)
17852 seq = argv[idx]->arg;
17853
17854 idx = 0;
17855
17856 argv_find(argv, argc, "(100-500)", &idx);
17857 argv_find(argv, argc, "WORD", &idx);
17858 cl_name_or_number = argv[idx]->arg;
17859 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
17860 : COMMUNITY_DENY;
17861 argv_find(argv, argc, "AA:NN", &idx);
17862 char *str = argv_concat(argv, argc, idx);
17863
17864 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
17865 direct, style);
17866
17867 XFREE(MTYPE_TMP, str);
17868
17869 if (ret < 0) {
17870 /* Display error string. */
17871 community_list_perror(vty, ret);
17872 return CMD_WARNING_CONFIG_FAILED;
17873 }
17874
17875 return CMD_SUCCESS;
17876 }
17877
17878 DEFUN (no_community_list_expanded_all,
17879 no_bgp_community_list_expanded_all_cmd,
17880 "no bgp community-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
17881 NO_STR
17882 BGP_STR
17883 COMMUNITY_LIST_STR
17884 "Community list number (expanded)\n"
17885 "Add an expanded community-list entry\n"
17886 "Community list name\n"
17887 "Sequence number of an entry\n"
17888 "Sequence number\n"
17889 "Specify community to reject\n"
17890 "Specify community to accept\n"
17891 COMMUNITY_VAL_STR)
17892 {
17893 char *cl_name_or_number = NULL;
17894 char *seq = NULL;
17895 char *str = NULL;
17896 int direct = 0;
17897 int style = COMMUNITY_LIST_EXPANDED;
17898 int idx = 0;
17899
17900 argv_find(argv, argc, "(1-4294967295)", &idx);
17901 if (idx)
17902 seq = argv[idx]->arg;
17903
17904 idx = 0;
17905 argv_find(argv, argc, "permit", &idx);
17906 argv_find(argv, argc, "deny", &idx);
17907
17908 if (idx) {
17909 direct = argv_find(argv, argc, "permit", &idx)
17910 ? COMMUNITY_PERMIT
17911 : COMMUNITY_DENY;
17912
17913 idx = 0;
17914 argv_find(argv, argc, "AA:NN", &idx);
17915 str = argv_concat(argv, argc, idx);
17916 }
17917
17918 idx = 0;
17919 argv_find(argv, argc, "(100-500)", &idx);
17920 argv_find(argv, argc, "WORD", &idx);
17921 cl_name_or_number = argv[idx]->arg;
17922
17923 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
17924 direct, style);
17925
17926 XFREE(MTYPE_TMP, str);
17927
17928 if (ret < 0) {
17929 community_list_perror(vty, ret);
17930 return CMD_WARNING_CONFIG_FAILED;
17931 }
17932
17933 return CMD_SUCCESS;
17934 }
17935
17936 ALIAS(no_community_list_expanded_all, no_bgp_community_list_expanded_all_list_cmd,
17937 "no bgp community-list <(100-500)|expanded WORD>",
17938 NO_STR IP_STR COMMUNITY_LIST_STR
17939 "Community list number (expanded)\n"
17940 "Add an expanded community-list entry\n"
17941 "Community list name\n")
17942
17943 /* Return configuration string of community-list entry. */
17944 static const char *community_list_config_str(struct community_entry *entry)
17945 {
17946 const char *str;
17947
17948 if (entry->any)
17949 str = "";
17950 else {
17951 if (entry->style == COMMUNITY_LIST_STANDARD)
17952 str = community_str(entry->u.com, false);
17953 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
17954 str = lcommunity_str(entry->u.lcom, false);
17955 else
17956 str = entry->config;
17957 }
17958 return str;
17959 }
17960
17961 static void community_list_show(struct vty *vty, struct community_list *list)
17962 {
17963 struct community_entry *entry;
17964
17965 for (entry = list->head; entry; entry = entry->next) {
17966 if (entry == list->head) {
17967 if (all_digit(list->name))
17968 vty_out(vty, "Community %s list %s\n",
17969 entry->style == COMMUNITY_LIST_STANDARD
17970 ? "standard"
17971 : "(expanded) access",
17972 list->name);
17973 else
17974 vty_out(vty, "Named Community %s list %s\n",
17975 entry->style == COMMUNITY_LIST_STANDARD
17976 ? "standard"
17977 : "expanded",
17978 list->name);
17979 }
17980 if (entry->any)
17981 vty_out(vty, " %s\n",
17982 community_direct_str(entry->direct));
17983 else
17984 vty_out(vty, " %s %s\n",
17985 community_direct_str(entry->direct),
17986 community_list_config_str(entry));
17987 }
17988 }
17989
17990 DEFUN (show_community_list,
17991 show_bgp_community_list_cmd,
17992 "show bgp community-list",
17993 SHOW_STR
17994 BGP_STR
17995 "List community-list\n")
17996 {
17997 struct community_list *list;
17998 struct community_list_master *cm;
17999
18000 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
18001 if (!cm)
18002 return CMD_SUCCESS;
18003
18004 for (list = cm->num.head; list; list = list->next)
18005 community_list_show(vty, list);
18006
18007 for (list = cm->str.head; list; list = list->next)
18008 community_list_show(vty, list);
18009
18010 return CMD_SUCCESS;
18011 }
18012
18013 DEFUN (show_community_list_arg,
18014 show_bgp_community_list_arg_cmd,
18015 "show bgp community-list <(1-500)|WORD> detail",
18016 SHOW_STR
18017 BGP_STR
18018 "List community-list\n"
18019 "Community-list number\n"
18020 "Community-list name\n"
18021 "Detailed information on community-list\n")
18022 {
18023 int idx_comm_list = 3;
18024 struct community_list *list;
18025
18026 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
18027 COMMUNITY_LIST_MASTER);
18028 if (!list) {
18029 vty_out(vty, "%% Can't find community-list\n");
18030 return CMD_WARNING;
18031 }
18032
18033 community_list_show(vty, list);
18034
18035 return CMD_SUCCESS;
18036 }
18037
18038 /*
18039 * Large Community code.
18040 */
18041 static int lcommunity_list_set_vty(struct vty *vty, int argc,
18042 struct cmd_token **argv, int style,
18043 int reject_all_digit_name)
18044 {
18045 int ret;
18046 int direct;
18047 char *str;
18048 int idx = 0;
18049 char *cl_name;
18050 char *seq = NULL;
18051
18052 if (argv_find(argv, argc, "(1-4294967295)", &idx))
18053 seq = argv[idx]->arg;
18054
18055 idx = 0;
18056 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
18057 : COMMUNITY_DENY;
18058
18059 /* All digit name check. */
18060 idx = 0;
18061 argv_find(argv, argc, "WORD", &idx);
18062 argv_find(argv, argc, "(1-99)", &idx);
18063 argv_find(argv, argc, "(100-500)", &idx);
18064 cl_name = argv[idx]->arg;
18065 if (reject_all_digit_name && all_digit(cl_name)) {
18066 vty_out(vty, "%% Community name cannot have all digits\n");
18067 return CMD_WARNING_CONFIG_FAILED;
18068 }
18069
18070 idx = 0;
18071 argv_find(argv, argc, "AA:BB:CC", &idx);
18072 argv_find(argv, argc, "LINE", &idx);
18073 /* Concat community string argument. */
18074 if (idx)
18075 str = argv_concat(argv, argc, idx);
18076 else
18077 str = NULL;
18078
18079 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
18080
18081 /* Free temporary community list string allocated by
18082 argv_concat(). */
18083 XFREE(MTYPE_TMP, str);
18084
18085 if (ret < 0) {
18086 community_list_perror(vty, ret);
18087 return CMD_WARNING_CONFIG_FAILED;
18088 }
18089 return CMD_SUCCESS;
18090 }
18091
18092 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
18093 struct cmd_token **argv, int style)
18094 {
18095 int ret;
18096 int direct = 0;
18097 char *str = NULL;
18098 int idx = 0;
18099 char *seq = NULL;
18100
18101 if (argv_find(argv, argc, "(1-4294967295)", &idx))
18102 seq = argv[idx]->arg;
18103
18104 idx = 0;
18105 argv_find(argv, argc, "permit", &idx);
18106 argv_find(argv, argc, "deny", &idx);
18107
18108 if (idx) {
18109 /* Check the list direct. */
18110 if (strncmp(argv[idx]->arg, "p", 1) == 0)
18111 direct = COMMUNITY_PERMIT;
18112 else
18113 direct = COMMUNITY_DENY;
18114
18115 idx = 0;
18116 argv_find(argv, argc, "LINE", &idx);
18117 argv_find(argv, argc, "AA:AA:NN", &idx);
18118 /* Concat community string argument. */
18119 str = argv_concat(argv, argc, idx);
18120 }
18121
18122 idx = 0;
18123 argv_find(argv, argc, "(1-99)", &idx);
18124 argv_find(argv, argc, "(100-500)", &idx);
18125 argv_find(argv, argc, "WORD", &idx);
18126
18127 /* Unset community list. */
18128 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
18129 style);
18130
18131 /* Free temporary community list string allocated by
18132 argv_concat(). */
18133 XFREE(MTYPE_TMP, str);
18134
18135 if (ret < 0) {
18136 community_list_perror(vty, ret);
18137 return CMD_WARNING_CONFIG_FAILED;
18138 }
18139
18140 return CMD_SUCCESS;
18141 }
18142
18143 /* "large-community-list" keyword help string. */
18144 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
18145 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
18146
18147 DEFUN (lcommunity_list_standard,
18148 bgp_lcommunity_list_standard_cmd,
18149 "bgp large-community-list (1-99) [seq (1-4294967295)] <deny|permit> AA:BB:CC...",
18150 BGP_STR
18151 LCOMMUNITY_LIST_STR
18152 "Large Community list number (standard)\n"
18153 "Sequence number of an entry\n"
18154 "Sequence number\n"
18155 "Specify large community to reject\n"
18156 "Specify large community to accept\n"
18157 LCOMMUNITY_VAL_STR)
18158 {
18159 return lcommunity_list_set_vty(vty, argc, argv,
18160 LARGE_COMMUNITY_LIST_STANDARD, 0);
18161 }
18162
18163 DEFUN (lcommunity_list_expanded,
18164 bgp_lcommunity_list_expanded_cmd,
18165 "bgp large-community-list (100-500) [seq (1-4294967295)] <deny|permit> LINE...",
18166 BGP_STR
18167 LCOMMUNITY_LIST_STR
18168 "Large Community list number (expanded)\n"
18169 "Sequence number of an entry\n"
18170 "Sequence number\n"
18171 "Specify large community to reject\n"
18172 "Specify large community to accept\n"
18173 "An ordered list as a regular-expression\n")
18174 {
18175 return lcommunity_list_set_vty(vty, argc, argv,
18176 LARGE_COMMUNITY_LIST_EXPANDED, 0);
18177 }
18178
18179 DEFUN (lcommunity_list_name_standard,
18180 bgp_lcommunity_list_name_standard_cmd,
18181 "bgp large-community-list standard WORD [seq (1-4294967295)] <deny|permit> AA:BB:CC...",
18182 BGP_STR
18183 LCOMMUNITY_LIST_STR
18184 "Specify standard large-community-list\n"
18185 "Large Community list name\n"
18186 "Sequence number of an entry\n"
18187 "Sequence number\n"
18188 "Specify large community to reject\n"
18189 "Specify large community to accept\n"
18190 LCOMMUNITY_VAL_STR)
18191 {
18192 return lcommunity_list_set_vty(vty, argc, argv,
18193 LARGE_COMMUNITY_LIST_STANDARD, 1);
18194 }
18195
18196 DEFUN (lcommunity_list_name_expanded,
18197 bgp_lcommunity_list_name_expanded_cmd,
18198 "bgp large-community-list expanded WORD [seq (1-4294967295)] <deny|permit> LINE...",
18199 BGP_STR
18200 LCOMMUNITY_LIST_STR
18201 "Specify expanded large-community-list\n"
18202 "Large Community list name\n"
18203 "Sequence number of an entry\n"
18204 "Sequence number\n"
18205 "Specify large community to reject\n"
18206 "Specify large community to accept\n"
18207 "An ordered list as a regular-expression\n")
18208 {
18209 return lcommunity_list_set_vty(vty, argc, argv,
18210 LARGE_COMMUNITY_LIST_EXPANDED, 1);
18211 }
18212
18213 DEFUN (no_lcommunity_list_all,
18214 no_bgp_lcommunity_list_all_cmd,
18215 "no bgp large-community-list <(1-99)|(100-500)|WORD>",
18216 NO_STR
18217 BGP_STR
18218 LCOMMUNITY_LIST_STR
18219 "Large Community list number (standard)\n"
18220 "Large Community list number (expanded)\n"
18221 "Large Community list name\n")
18222 {
18223 return lcommunity_list_unset_vty(vty, argc, argv,
18224 LARGE_COMMUNITY_LIST_STANDARD);
18225 }
18226
18227 DEFUN (no_lcommunity_list_name_standard_all,
18228 no_bgp_lcommunity_list_name_standard_all_cmd,
18229 "no bgp large-community-list standard WORD",
18230 NO_STR
18231 BGP_STR
18232 LCOMMUNITY_LIST_STR
18233 "Specify standard large-community-list\n"
18234 "Large Community list name\n")
18235 {
18236 return lcommunity_list_unset_vty(vty, argc, argv,
18237 LARGE_COMMUNITY_LIST_STANDARD);
18238 }
18239
18240 DEFUN (no_lcommunity_list_name_expanded_all,
18241 no_bgp_lcommunity_list_name_expanded_all_cmd,
18242 "no bgp large-community-list expanded WORD",
18243 NO_STR
18244 BGP_STR
18245 LCOMMUNITY_LIST_STR
18246 "Specify expanded large-community-list\n"
18247 "Large Community list name\n")
18248 {
18249 return lcommunity_list_unset_vty(vty, argc, argv,
18250 LARGE_COMMUNITY_LIST_EXPANDED);
18251 }
18252
18253 DEFUN (no_lcommunity_list_standard,
18254 no_bgp_lcommunity_list_standard_cmd,
18255 "no bgp large-community-list (1-99) [seq (1-4294967295)] <deny|permit> AA:AA:NN...",
18256 NO_STR
18257 BGP_STR
18258 LCOMMUNITY_LIST_STR
18259 "Large Community list number (standard)\n"
18260 "Sequence number of an entry\n"
18261 "Sequence number\n"
18262 "Specify large community to reject\n"
18263 "Specify large community to accept\n"
18264 LCOMMUNITY_VAL_STR)
18265 {
18266 return lcommunity_list_unset_vty(vty, argc, argv,
18267 LARGE_COMMUNITY_LIST_STANDARD);
18268 }
18269
18270 DEFUN (no_lcommunity_list_expanded,
18271 no_bgp_lcommunity_list_expanded_cmd,
18272 "no bgp large-community-list (100-500) [seq (1-4294967295)] <deny|permit> LINE...",
18273 NO_STR
18274 BGP_STR
18275 LCOMMUNITY_LIST_STR
18276 "Large Community list number (expanded)\n"
18277 "Sequence number of an entry\n"
18278 "Sequence number\n"
18279 "Specify large community to reject\n"
18280 "Specify large community to accept\n"
18281 "An ordered list as a regular-expression\n")
18282 {
18283 return lcommunity_list_unset_vty(vty, argc, argv,
18284 LARGE_COMMUNITY_LIST_EXPANDED);
18285 }
18286
18287 DEFUN (no_lcommunity_list_name_standard,
18288 no_bgp_lcommunity_list_name_standard_cmd,
18289 "no bgp large-community-list standard WORD [seq (1-4294967295)] <deny|permit> AA:AA:NN...",
18290 NO_STR
18291 BGP_STR
18292 LCOMMUNITY_LIST_STR
18293 "Specify standard large-community-list\n"
18294 "Large Community list name\n"
18295 "Sequence number of an entry\n"
18296 "Sequence number\n"
18297 "Specify large community to reject\n"
18298 "Specify large community to accept\n"
18299 LCOMMUNITY_VAL_STR)
18300 {
18301 return lcommunity_list_unset_vty(vty, argc, argv,
18302 LARGE_COMMUNITY_LIST_STANDARD);
18303 }
18304
18305 DEFUN (no_lcommunity_list_name_expanded,
18306 no_bgp_lcommunity_list_name_expanded_cmd,
18307 "no bgp large-community-list expanded WORD [seq (1-4294967295)] <deny|permit> LINE...",
18308 NO_STR
18309 BGP_STR
18310 LCOMMUNITY_LIST_STR
18311 "Specify expanded large-community-list\n"
18312 "Large community list name\n"
18313 "Sequence number of an entry\n"
18314 "Sequence number\n"
18315 "Specify large community to reject\n"
18316 "Specify large community to accept\n"
18317 "An ordered list as a regular-expression\n")
18318 {
18319 return lcommunity_list_unset_vty(vty, argc, argv,
18320 LARGE_COMMUNITY_LIST_EXPANDED);
18321 }
18322
18323 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
18324 {
18325 struct community_entry *entry;
18326
18327 for (entry = list->head; entry; entry = entry->next) {
18328 if (entry == list->head) {
18329 if (all_digit(list->name))
18330 vty_out(vty, "Large community %s list %s\n",
18331 entry->style ==
18332 LARGE_COMMUNITY_LIST_STANDARD
18333 ? "standard"
18334 : "(expanded) access",
18335 list->name);
18336 else
18337 vty_out(vty,
18338 "Named large community %s list %s\n",
18339 entry->style ==
18340 LARGE_COMMUNITY_LIST_STANDARD
18341 ? "standard"
18342 : "expanded",
18343 list->name);
18344 }
18345 if (entry->any)
18346 vty_out(vty, " %s\n",
18347 community_direct_str(entry->direct));
18348 else
18349 vty_out(vty, " %s %s\n",
18350 community_direct_str(entry->direct),
18351 community_list_config_str(entry));
18352 }
18353 }
18354
18355 DEFUN (show_lcommunity_list,
18356 show_bgp_lcommunity_list_cmd,
18357 "show bgp large-community-list",
18358 SHOW_STR
18359 BGP_STR
18360 "List large-community list\n")
18361 {
18362 struct community_list *list;
18363 struct community_list_master *cm;
18364
18365 cm = community_list_master_lookup(bgp_clist,
18366 LARGE_COMMUNITY_LIST_MASTER);
18367 if (!cm)
18368 return CMD_SUCCESS;
18369
18370 for (list = cm->num.head; list; list = list->next)
18371 lcommunity_list_show(vty, list);
18372
18373 for (list = cm->str.head; list; list = list->next)
18374 lcommunity_list_show(vty, list);
18375
18376 return CMD_SUCCESS;
18377 }
18378
18379 DEFUN (show_lcommunity_list_arg,
18380 show_bgp_lcommunity_list_arg_cmd,
18381 "show bgp large-community-list <(1-500)|WORD> detail",
18382 SHOW_STR
18383 BGP_STR
18384 "List large-community list\n"
18385 "Large-community-list number\n"
18386 "Large-community-list name\n"
18387 "Detailed information on large-community-list\n")
18388 {
18389 struct community_list *list;
18390
18391 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
18392 LARGE_COMMUNITY_LIST_MASTER);
18393 if (!list) {
18394 vty_out(vty, "%% Can't find large-community-list\n");
18395 return CMD_WARNING;
18396 }
18397
18398 lcommunity_list_show(vty, list);
18399
18400 return CMD_SUCCESS;
18401 }
18402
18403 /* "extcommunity-list" keyword help string. */
18404 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
18405 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
18406
18407 DEFUN (extcommunity_list_standard,
18408 bgp_extcommunity_list_standard_cmd,
18409 "bgp extcommunity-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
18410 BGP_STR
18411 EXTCOMMUNITY_LIST_STR
18412 "Extended Community list number (standard)\n"
18413 "Specify standard extcommunity-list\n"
18414 "Community list name\n"
18415 "Sequence number of an entry\n"
18416 "Sequence number\n"
18417 "Specify community to reject\n"
18418 "Specify community to accept\n"
18419 EXTCOMMUNITY_VAL_STR)
18420 {
18421 int style = EXTCOMMUNITY_LIST_STANDARD;
18422 int direct = 0;
18423 char *cl_number_or_name = NULL;
18424 char *seq = NULL;
18425
18426 int idx = 0;
18427
18428 argv_find(argv, argc, "(1-99)", &idx);
18429 argv_find(argv, argc, "WORD", &idx);
18430 cl_number_or_name = argv[idx]->arg;
18431
18432 if (argv_find(argv, argc, "(1-4294967295)", &idx))
18433 seq = argv[idx]->arg;
18434
18435 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
18436 : COMMUNITY_DENY;
18437 argv_find(argv, argc, "AA:NN", &idx);
18438 char *str = argv_concat(argv, argc, idx);
18439
18440 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
18441 direct, style);
18442
18443 XFREE(MTYPE_TMP, str);
18444
18445 if (ret < 0) {
18446 community_list_perror(vty, ret);
18447 return CMD_WARNING_CONFIG_FAILED;
18448 }
18449
18450 return CMD_SUCCESS;
18451 }
18452
18453 DEFUN (extcommunity_list_name_expanded,
18454 bgp_extcommunity_list_name_expanded_cmd,
18455 "bgp extcommunity-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> LINE...",
18456 BGP_STR
18457 EXTCOMMUNITY_LIST_STR
18458 "Extended Community list number (expanded)\n"
18459 "Specify expanded extcommunity-list\n"
18460 "Extended Community list name\n"
18461 "Sequence number of an entry\n"
18462 "Sequence number\n"
18463 "Specify community to reject\n"
18464 "Specify community to accept\n"
18465 "An ordered list as a regular-expression\n")
18466 {
18467 int style = EXTCOMMUNITY_LIST_EXPANDED;
18468 int direct = 0;
18469 char *cl_number_or_name = NULL;
18470 char *seq = NULL;
18471 int idx = 0;
18472
18473 argv_find(argv, argc, "(100-500)", &idx);
18474 argv_find(argv, argc, "WORD", &idx);
18475 cl_number_or_name = argv[idx]->arg;
18476
18477 if (argv_find(argv, argc, "(1-4294967295)", &idx))
18478 seq = argv[idx]->arg;
18479
18480 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
18481 : COMMUNITY_DENY;
18482 argv_find(argv, argc, "LINE", &idx);
18483 char *str = argv_concat(argv, argc, idx);
18484
18485 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
18486 direct, style);
18487
18488 XFREE(MTYPE_TMP, str);
18489
18490 if (ret < 0) {
18491 community_list_perror(vty, ret);
18492 return CMD_WARNING_CONFIG_FAILED;
18493 }
18494
18495 return CMD_SUCCESS;
18496 }
18497
18498 DEFUN (no_extcommunity_list_standard_all,
18499 no_bgp_extcommunity_list_standard_all_cmd,
18500 "no bgp extcommunity-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
18501 NO_STR
18502 BGP_STR
18503 EXTCOMMUNITY_LIST_STR
18504 "Extended Community list number (standard)\n"
18505 "Specify standard extcommunity-list\n"
18506 "Community list name\n"
18507 "Sequence number of an entry\n"
18508 "Sequence number\n"
18509 "Specify community to reject\n"
18510 "Specify community to accept\n"
18511 EXTCOMMUNITY_VAL_STR)
18512 {
18513 int style = EXTCOMMUNITY_LIST_STANDARD;
18514 int direct = 0;
18515 char *cl_number_or_name = NULL;
18516 char *str = NULL;
18517 char *seq = NULL;
18518 int idx = 0;
18519
18520 if (argv_find(argv, argc, "(1-4294967295)", &idx))
18521 seq = argv[idx]->arg;
18522
18523 idx = 0;
18524 argv_find(argv, argc, "permit", &idx);
18525 argv_find(argv, argc, "deny", &idx);
18526 if (idx) {
18527 direct = argv_find(argv, argc, "permit", &idx)
18528 ? COMMUNITY_PERMIT
18529 : COMMUNITY_DENY;
18530
18531 idx = 0;
18532 argv_find(argv, argc, "AA:NN", &idx);
18533 str = argv_concat(argv, argc, idx);
18534 }
18535
18536 idx = 0;
18537 argv_find(argv, argc, "(1-99)", &idx);
18538 argv_find(argv, argc, "WORD", &idx);
18539 cl_number_or_name = argv[idx]->arg;
18540
18541 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
18542 seq, direct, style);
18543
18544 XFREE(MTYPE_TMP, str);
18545
18546 if (ret < 0) {
18547 community_list_perror(vty, ret);
18548 return CMD_WARNING_CONFIG_FAILED;
18549 }
18550
18551 return CMD_SUCCESS;
18552 }
18553
18554 ALIAS(no_extcommunity_list_standard_all,
18555 no_bgp_extcommunity_list_standard_all_list_cmd,
18556 "no bgp extcommunity-list <(1-99)|standard WORD>",
18557 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
18558 "Extended Community list number (standard)\n"
18559 "Specify standard extcommunity-list\n"
18560 "Community list name\n")
18561
18562 DEFUN (no_extcommunity_list_expanded_all,
18563 no_bgp_extcommunity_list_expanded_all_cmd,
18564 "no bgp extcommunity-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> LINE...",
18565 NO_STR
18566 BGP_STR
18567 EXTCOMMUNITY_LIST_STR
18568 "Extended Community list number (expanded)\n"
18569 "Specify expanded extcommunity-list\n"
18570 "Extended Community list name\n"
18571 "Sequence number of an entry\n"
18572 "Sequence number\n"
18573 "Specify community to reject\n"
18574 "Specify community to accept\n"
18575 "An ordered list as a regular-expression\n")
18576 {
18577 int style = EXTCOMMUNITY_LIST_EXPANDED;
18578 int direct = 0;
18579 char *cl_number_or_name = NULL;
18580 char *str = NULL;
18581 char *seq = NULL;
18582 int idx = 0;
18583
18584 if (argv_find(argv, argc, "(1-4294967295)", &idx))
18585 seq = argv[idx]->arg;
18586
18587 idx = 0;
18588 argv_find(argv, argc, "permit", &idx);
18589 argv_find(argv, argc, "deny", &idx);
18590
18591 if (idx) {
18592 direct = argv_find(argv, argc, "permit", &idx)
18593 ? COMMUNITY_PERMIT
18594 : COMMUNITY_DENY;
18595
18596 idx = 0;
18597 argv_find(argv, argc, "LINE", &idx);
18598 str = argv_concat(argv, argc, idx);
18599 }
18600
18601 idx = 0;
18602 argv_find(argv, argc, "(100-500)", &idx);
18603 argv_find(argv, argc, "WORD", &idx);
18604 cl_number_or_name = argv[idx]->arg;
18605
18606 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
18607 seq, direct, style);
18608
18609 XFREE(MTYPE_TMP, str);
18610
18611 if (ret < 0) {
18612 community_list_perror(vty, ret);
18613 return CMD_WARNING_CONFIG_FAILED;
18614 }
18615
18616 return CMD_SUCCESS;
18617 }
18618
18619 ALIAS(no_extcommunity_list_expanded_all,
18620 no_bgp_extcommunity_list_expanded_all_list_cmd,
18621 "no bgp extcommunity-list <(100-500)|expanded WORD>",
18622 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
18623 "Extended Community list number (expanded)\n"
18624 "Specify expanded extcommunity-list\n"
18625 "Extended Community list name\n")
18626
18627 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
18628 {
18629 struct community_entry *entry;
18630
18631 for (entry = list->head; entry; entry = entry->next) {
18632 if (entry == list->head) {
18633 if (all_digit(list->name))
18634 vty_out(vty, "Extended community %s list %s\n",
18635 entry->style == EXTCOMMUNITY_LIST_STANDARD
18636 ? "standard"
18637 : "(expanded) access",
18638 list->name);
18639 else
18640 vty_out(vty,
18641 "Named extended community %s list %s\n",
18642 entry->style == EXTCOMMUNITY_LIST_STANDARD
18643 ? "standard"
18644 : "expanded",
18645 list->name);
18646 }
18647 if (entry->any)
18648 vty_out(vty, " %s\n",
18649 community_direct_str(entry->direct));
18650 else
18651 vty_out(vty, " %s %s\n",
18652 community_direct_str(entry->direct),
18653 community_list_config_str(entry));
18654 }
18655 }
18656
18657 DEFUN (show_extcommunity_list,
18658 show_bgp_extcommunity_list_cmd,
18659 "show bgp extcommunity-list",
18660 SHOW_STR
18661 BGP_STR
18662 "List extended-community list\n")
18663 {
18664 struct community_list *list;
18665 struct community_list_master *cm;
18666
18667 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
18668 if (!cm)
18669 return CMD_SUCCESS;
18670
18671 for (list = cm->num.head; list; list = list->next)
18672 extcommunity_list_show(vty, list);
18673
18674 for (list = cm->str.head; list; list = list->next)
18675 extcommunity_list_show(vty, list);
18676
18677 return CMD_SUCCESS;
18678 }
18679
18680 DEFUN (show_extcommunity_list_arg,
18681 show_bgp_extcommunity_list_arg_cmd,
18682 "show bgp extcommunity-list <(1-500)|WORD> detail",
18683 SHOW_STR
18684 BGP_STR
18685 "List extended-community list\n"
18686 "Extcommunity-list number\n"
18687 "Extcommunity-list name\n"
18688 "Detailed information on extcommunity-list\n")
18689 {
18690 int idx_comm_list = 3;
18691 struct community_list *list;
18692
18693 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
18694 EXTCOMMUNITY_LIST_MASTER);
18695 if (!list) {
18696 vty_out(vty, "%% Can't find extcommunity-list\n");
18697 return CMD_WARNING;
18698 }
18699
18700 extcommunity_list_show(vty, list);
18701
18702 return CMD_SUCCESS;
18703 }
18704
18705 /* Display community-list and extcommunity-list configuration. */
18706 static int community_list_config_write(struct vty *vty)
18707 {
18708 struct community_list *list;
18709 struct community_entry *entry;
18710 struct community_list_master *cm;
18711 int write = 0;
18712
18713 /* Community-list. */
18714 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
18715
18716 for (list = cm->num.head; list; list = list->next)
18717 for (entry = list->head; entry; entry = entry->next) {
18718 vty_out(vty,
18719 "bgp community-list %s seq %" PRId64 " %s %s\n",
18720 list->name, entry->seq,
18721 community_direct_str(entry->direct),
18722 community_list_config_str(entry));
18723 write++;
18724 }
18725 for (list = cm->str.head; list; list = list->next)
18726 for (entry = list->head; entry; entry = entry->next) {
18727 vty_out(vty,
18728 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
18729 entry->style == COMMUNITY_LIST_STANDARD
18730 ? "standard"
18731 : "expanded",
18732 list->name, entry->seq,
18733 community_direct_str(entry->direct),
18734 community_list_config_str(entry));
18735 write++;
18736 }
18737
18738 /* Extcommunity-list. */
18739 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
18740
18741 for (list = cm->num.head; list; list = list->next)
18742 for (entry = list->head; entry; entry = entry->next) {
18743 vty_out(vty,
18744 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
18745 list->name, entry->seq,
18746 community_direct_str(entry->direct),
18747 community_list_config_str(entry));
18748 write++;
18749 }
18750 for (list = cm->str.head; list; list = list->next)
18751 for (entry = list->head; entry; entry = entry->next) {
18752 vty_out(vty,
18753 "bgp extcommunity-list %s %s seq %" PRId64" %s %s\n",
18754 entry->style == EXTCOMMUNITY_LIST_STANDARD
18755 ? "standard"
18756 : "expanded",
18757 list->name, entry->seq,
18758 community_direct_str(entry->direct),
18759 community_list_config_str(entry));
18760 write++;
18761 }
18762
18763
18764 /* lcommunity-list. */
18765 cm = community_list_master_lookup(bgp_clist,
18766 LARGE_COMMUNITY_LIST_MASTER);
18767
18768 for (list = cm->num.head; list; list = list->next)
18769 for (entry = list->head; entry; entry = entry->next) {
18770 vty_out(vty,
18771 "bgp large-community-list %s seq %" PRId64" %s %s\n",
18772 list->name, entry->seq,
18773 community_direct_str(entry->direct),
18774 community_list_config_str(entry));
18775 write++;
18776 }
18777 for (list = cm->str.head; list; list = list->next)
18778 for (entry = list->head; entry; entry = entry->next) {
18779 vty_out(vty,
18780 "bgp large-community-list %s %s seq %" PRId64" %s %s\n",
18781
18782 entry->style == LARGE_COMMUNITY_LIST_STANDARD
18783 ? "standard"
18784 : "expanded",
18785 list->name, entry->seq, community_direct_str(entry->direct),
18786 community_list_config_str(entry));
18787 write++;
18788 }
18789
18790 return write;
18791 }
18792
18793 static int community_list_config_write(struct vty *vty);
18794 static struct cmd_node community_list_node = {
18795 .name = "community list",
18796 .node = COMMUNITY_LIST_NODE,
18797 .prompt = "",
18798 .config_write = community_list_config_write,
18799 };
18800
18801 static void community_list_vty(void)
18802 {
18803 install_node(&community_list_node);
18804
18805 /* Community-list. */
18806 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
18807 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
18808 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
18809 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
18810 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
18811 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
18812 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
18813 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
18814
18815 /* Extcommunity-list. */
18816 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
18817 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
18818 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
18819 install_element(CONFIG_NODE,
18820 &no_bgp_extcommunity_list_standard_all_list_cmd);
18821 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
18822 install_element(CONFIG_NODE,
18823 &no_bgp_extcommunity_list_expanded_all_list_cmd);
18824 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
18825 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
18826
18827 /* Large Community List */
18828 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
18829 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
18830 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
18831 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
18832 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
18833 install_element(CONFIG_NODE,
18834 &no_bgp_lcommunity_list_name_standard_all_cmd);
18835 install_element(CONFIG_NODE,
18836 &no_bgp_lcommunity_list_name_expanded_all_cmd);
18837 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
18838 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
18839 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
18840 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
18841 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
18842 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
18843 }