]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
Merge pull request #5785 from ton31337/fix/replace_gtsm_hops_to_readable_macros
[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_addpath.h"
69 #include "bgpd/bgp_mac.h"
70 #include "bgpd/bgp_flowspec.h"
71 #if ENABLE_BGP_VNC
72 #include "bgpd/rfapi/bgp_rfapi_cfg.h"
73 #endif
74
75 FRR_CFG_DEFAULT_BOOL(BGP_IMPORT_CHECK,
76 { .val_long = true, .match_profile = "datacenter", },
77 { .val_long = false },
78 )
79 FRR_CFG_DEFAULT_BOOL(BGP_SHOW_HOSTNAME,
80 { .val_long = true, .match_profile = "datacenter", },
81 { .val_long = false },
82 )
83 FRR_CFG_DEFAULT_BOOL(BGP_LOG_NEIGHBOR_CHANGES,
84 { .val_long = true, .match_profile = "datacenter", },
85 { .val_long = false },
86 )
87 FRR_CFG_DEFAULT_BOOL(BGP_DETERMINISTIC_MED,
88 { .val_long = true, .match_profile = "datacenter", },
89 { .val_long = false },
90 )
91 FRR_CFG_DEFAULT_ULONG(BGP_CONNECT_RETRY,
92 { .val_ulong = 10, .match_profile = "datacenter", },
93 { .val_ulong = 120 },
94 )
95 FRR_CFG_DEFAULT_ULONG(BGP_HOLDTIME,
96 { .val_ulong = 9, .match_profile = "datacenter", },
97 { .val_ulong = 180 },
98 )
99 FRR_CFG_DEFAULT_ULONG(BGP_KEEPALIVE,
100 { .val_ulong = 3, .match_profile = "datacenter", },
101 { .val_ulong = 60 },
102 )
103
104 DEFINE_HOOK(bgp_inst_config_write,
105 (struct bgp *bgp, struct vty *vty),
106 (bgp, vty))
107
108 #define GR_NO_OPER \
109 "The Graceful Restart No Operation was executed as cmd same as previous one."
110 #define GR_INVALID \
111 "The Graceful Restart command used is not valid at this moment."
112 static struct peer_group *listen_range_exists(struct bgp *bgp,
113 struct prefix *range, int exact);
114
115 /* Show BGP peer's information. */
116 enum show_type {
117 show_all,
118 show_peer,
119 show_ipv4_all,
120 show_ipv6_all,
121 show_ipv4_peer,
122 show_ipv6_peer
123 };
124
125 static struct peer_group *listen_range_exists(struct bgp *bgp,
126 struct prefix *range, int exact);
127
128 static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
129 struct bgp *bgp,
130 bool use_json,
131 json_object *json);
132
133 static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
134 enum show_type type,
135 const char *ip_str,
136 afi_t afi, bool use_json);
137
138 static enum node_type bgp_node_type(afi_t afi, safi_t safi)
139 {
140 switch (afi) {
141 case AFI_IP:
142 switch (safi) {
143 case SAFI_UNICAST:
144 return BGP_IPV4_NODE;
145 break;
146 case SAFI_MULTICAST:
147 return BGP_IPV4M_NODE;
148 break;
149 case SAFI_LABELED_UNICAST:
150 return BGP_IPV4L_NODE;
151 break;
152 case SAFI_MPLS_VPN:
153 return BGP_VPNV4_NODE;
154 break;
155 case SAFI_FLOWSPEC:
156 return BGP_FLOWSPECV4_NODE;
157 default:
158 /* not expected */
159 return BGP_IPV4_NODE;
160 break;
161 }
162 break;
163 case AFI_IP6:
164 switch (safi) {
165 case SAFI_UNICAST:
166 return BGP_IPV6_NODE;
167 break;
168 case SAFI_MULTICAST:
169 return BGP_IPV6M_NODE;
170 break;
171 case SAFI_LABELED_UNICAST:
172 return BGP_IPV6L_NODE;
173 break;
174 case SAFI_MPLS_VPN:
175 return BGP_VPNV6_NODE;
176 break;
177 case SAFI_FLOWSPEC:
178 return BGP_FLOWSPECV6_NODE;
179 default:
180 /* not expected */
181 return BGP_IPV4_NODE;
182 break;
183 }
184 break;
185 case AFI_L2VPN:
186 return BGP_EVPN_NODE;
187 break;
188 case AFI_UNSPEC:
189 case AFI_MAX:
190 // We should never be here but to clarify the switch statement..
191 return BGP_IPV4_NODE;
192 break;
193 }
194
195 // Impossible to happen
196 return BGP_IPV4_NODE;
197 }
198
199 static const char *get_afi_safi_vty_str(afi_t afi, safi_t safi)
200 {
201 if (afi == AFI_IP && safi == SAFI_UNICAST)
202 return "IPv4 Unicast";
203 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
204 return "IPv4 Multicast";
205 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
206 return "IPv4 Labeled Unicast";
207 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
208 return "IPv4 VPN";
209 else if (afi == AFI_IP && safi == SAFI_ENCAP)
210 return "IPv4 Encap";
211 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
212 return "IPv4 Flowspec";
213 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
214 return "IPv6 Unicast";
215 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
216 return "IPv6 Multicast";
217 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
218 return "IPv6 Labeled Unicast";
219 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
220 return "IPv6 VPN";
221 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
222 return "IPv6 Encap";
223 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
224 return "IPv6 Flowspec";
225 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
226 return "L2VPN EVPN";
227 else
228 return "Unknown";
229 }
230
231 /*
232 * Please note that we have intentionally camelCased
233 * the return strings here. So if you want
234 * to use this function, please ensure you
235 * are doing this within json output
236 */
237 static const char *get_afi_safi_json_str(afi_t afi, safi_t safi)
238 {
239 if (afi == AFI_IP && safi == SAFI_UNICAST)
240 return "ipv4Unicast";
241 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
242 return "ipv4Multicast";
243 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
244 return "ipv4LabeledUnicast";
245 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
246 return "ipv4Vpn";
247 else if (afi == AFI_IP && safi == SAFI_ENCAP)
248 return "ipv4Encap";
249 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
250 return "ipv4Flowspec";
251 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
252 return "ipv6Unicast";
253 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
254 return "ipv6Multicast";
255 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
256 return "ipv6LabeledUnicast";
257 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
258 return "ipv6Vpn";
259 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
260 return "ipv6Encap";
261 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
262 return "ipv6Flowspec";
263 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
264 return "l2VpnEvpn";
265 else
266 return "Unknown";
267 }
268
269 /* Utility function to get address family from current node. */
270 afi_t bgp_node_afi(struct vty *vty)
271 {
272 afi_t afi;
273 switch (vty->node) {
274 case BGP_IPV6_NODE:
275 case BGP_IPV6M_NODE:
276 case BGP_IPV6L_NODE:
277 case BGP_VPNV6_NODE:
278 case BGP_FLOWSPECV6_NODE:
279 afi = AFI_IP6;
280 break;
281 case BGP_EVPN_NODE:
282 afi = AFI_L2VPN;
283 break;
284 default:
285 afi = AFI_IP;
286 break;
287 }
288 return afi;
289 }
290
291 /* Utility function to get subsequent address family from current
292 node. */
293 safi_t bgp_node_safi(struct vty *vty)
294 {
295 safi_t safi;
296 switch (vty->node) {
297 case BGP_VPNV4_NODE:
298 case BGP_VPNV6_NODE:
299 safi = SAFI_MPLS_VPN;
300 break;
301 case BGP_IPV4M_NODE:
302 case BGP_IPV6M_NODE:
303 safi = SAFI_MULTICAST;
304 break;
305 case BGP_EVPN_NODE:
306 safi = SAFI_EVPN;
307 break;
308 case BGP_IPV4L_NODE:
309 case BGP_IPV6L_NODE:
310 safi = SAFI_LABELED_UNICAST;
311 break;
312 case BGP_FLOWSPECV4_NODE:
313 case BGP_FLOWSPECV6_NODE:
314 safi = SAFI_FLOWSPEC;
315 break;
316 default:
317 safi = SAFI_UNICAST;
318 break;
319 }
320 return safi;
321 }
322
323 /**
324 * Converts an AFI in string form to afi_t
325 *
326 * @param afi string, one of
327 * - "ipv4"
328 * - "ipv6"
329 * - "l2vpn"
330 * @return the corresponding afi_t
331 */
332 afi_t bgp_vty_afi_from_str(const char *afi_str)
333 {
334 afi_t afi = AFI_MAX; /* unknown */
335 if (strmatch(afi_str, "ipv4"))
336 afi = AFI_IP;
337 else if (strmatch(afi_str, "ipv6"))
338 afi = AFI_IP6;
339 else if (strmatch(afi_str, "l2vpn"))
340 afi = AFI_L2VPN;
341 return afi;
342 }
343
344 int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
345 afi_t *afi)
346 {
347 int ret = 0;
348 if (argv_find(argv, argc, "ipv4", index)) {
349 ret = 1;
350 if (afi)
351 *afi = AFI_IP;
352 } else if (argv_find(argv, argc, "ipv6", index)) {
353 ret = 1;
354 if (afi)
355 *afi = AFI_IP6;
356 } else if (argv_find(argv, argc, "l2vpn", index)) {
357 ret = 1;
358 if (afi)
359 *afi = AFI_L2VPN;
360 }
361 return ret;
362 }
363
364 /* supports <unicast|multicast|vpn|labeled-unicast> */
365 safi_t bgp_vty_safi_from_str(const char *safi_str)
366 {
367 safi_t safi = SAFI_MAX; /* unknown */
368 if (strmatch(safi_str, "multicast"))
369 safi = SAFI_MULTICAST;
370 else if (strmatch(safi_str, "unicast"))
371 safi = SAFI_UNICAST;
372 else if (strmatch(safi_str, "vpn"))
373 safi = SAFI_MPLS_VPN;
374 else if (strmatch(safi_str, "evpn"))
375 safi = SAFI_EVPN;
376 else if (strmatch(safi_str, "labeled-unicast"))
377 safi = SAFI_LABELED_UNICAST;
378 else if (strmatch(safi_str, "flowspec"))
379 safi = SAFI_FLOWSPEC;
380 return safi;
381 }
382
383 int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
384 safi_t *safi)
385 {
386 int ret = 0;
387 if (argv_find(argv, argc, "unicast", index)) {
388 ret = 1;
389 if (safi)
390 *safi = SAFI_UNICAST;
391 } else if (argv_find(argv, argc, "multicast", index)) {
392 ret = 1;
393 if (safi)
394 *safi = SAFI_MULTICAST;
395 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
396 ret = 1;
397 if (safi)
398 *safi = SAFI_LABELED_UNICAST;
399 } else if (argv_find(argv, argc, "vpn", index)) {
400 ret = 1;
401 if (safi)
402 *safi = SAFI_MPLS_VPN;
403 } else if (argv_find(argv, argc, "evpn", index)) {
404 ret = 1;
405 if (safi)
406 *safi = SAFI_EVPN;
407 } else if (argv_find(argv, argc, "flowspec", index)) {
408 ret = 1;
409 if (safi)
410 *safi = SAFI_FLOWSPEC;
411 }
412 return ret;
413 }
414
415 int bgp_get_vty(struct bgp **bgp, as_t *as, const char *name,
416 enum bgp_instance_type inst_type)
417 {
418 int ret = bgp_get(bgp, as, name, inst_type);
419
420 if (ret == BGP_CREATED) {
421 bgp_timers_set(*bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
422 DFLT_BGP_CONNECT_RETRY);
423
424 if (DFLT_BGP_IMPORT_CHECK)
425 SET_FLAG((*bgp)->flags, BGP_FLAG_IMPORT_CHECK);
426 if (DFLT_BGP_SHOW_HOSTNAME)
427 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_HOSTNAME);
428 if (DFLT_BGP_LOG_NEIGHBOR_CHANGES)
429 SET_FLAG((*bgp)->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
430 if (DFLT_BGP_DETERMINISTIC_MED)
431 SET_FLAG((*bgp)->flags, BGP_FLAG_DETERMINISTIC_MED);
432
433 ret = BGP_SUCCESS;
434 }
435 return ret;
436 }
437
438 /*
439 * bgp_vty_find_and_parse_afi_safi_bgp
440 *
441 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
442 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
443 * to appropriate values for the calling function. This is to allow the
444 * calling function to make decisions appropriate for the show command
445 * that is being parsed.
446 *
447 * The show commands are generally of the form:
448 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
449 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
450 *
451 * Since we use argv_find if the show command in particular doesn't have:
452 * [ip]
453 * [<view|vrf> VIEWVRFNAME]
454 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
455 * The command parsing should still be ok.
456 *
457 * vty -> The vty for the command so we can output some useful data in
458 * the event of a parse error in the vrf.
459 * argv -> The command tokens
460 * argc -> How many command tokens we have
461 * idx -> The current place in the command, generally should be 0 for this
462 * function
463 * afi -> The parsed afi if it was included in the show command, returned here
464 * safi -> The parsed safi if it was included in the show command, returned here
465 * bgp -> Pointer to the bgp data structure we need to fill in.
466 * use_json -> json is configured or not
467 *
468 * The function returns the correct location in the parse tree for the
469 * last token found.
470 *
471 * Returns 0 for failure to parse correctly, else the idx position of where
472 * it found the last token.
473 */
474 int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
475 struct cmd_token **argv, int argc,
476 int *idx, afi_t *afi, safi_t *safi,
477 struct bgp **bgp, bool use_json)
478 {
479 char *vrf_name = NULL;
480
481 assert(afi);
482 assert(safi);
483 assert(bgp);
484
485 if (argv_find(argv, argc, "ip", idx))
486 *afi = AFI_IP;
487
488 if (argv_find(argv, argc, "view", idx))
489 vrf_name = argv[*idx + 1]->arg;
490 else if (argv_find(argv, argc, "vrf", idx)) {
491 vrf_name = argv[*idx + 1]->arg;
492 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
493 vrf_name = NULL;
494 }
495 if (vrf_name) {
496 if (strmatch(vrf_name, "all"))
497 *bgp = NULL;
498 else {
499 *bgp = bgp_lookup_by_name(vrf_name);
500 if (!*bgp) {
501 if (use_json) {
502 json_object *json = NULL;
503 json = json_object_new_object();
504 json_object_string_add(
505 json, "warning",
506 "View/Vrf is unknown");
507 vty_out(vty, "%s\n",
508 json_object_to_json_string_ext(json,
509 JSON_C_TO_STRING_PRETTY));
510 json_object_free(json);
511 }
512 else
513 vty_out(vty, "View/Vrf %s is unknown\n",
514 vrf_name);
515 *idx = 0;
516 return 0;
517 }
518 }
519 } else {
520 *bgp = bgp_get_default();
521 if (!*bgp) {
522 if (use_json) {
523 json_object *json = NULL;
524 json = json_object_new_object();
525 json_object_string_add(
526 json, "warning",
527 "Default BGP instance not found");
528 vty_out(vty, "%s\n",
529 json_object_to_json_string_ext(json,
530 JSON_C_TO_STRING_PRETTY));
531 json_object_free(json);
532 }
533 else
534 vty_out(vty,
535 "Default BGP instance not found\n");
536 *idx = 0;
537 return 0;
538 }
539 }
540
541 if (argv_find_and_parse_afi(argv, argc, idx, afi))
542 argv_find_and_parse_safi(argv, argc, idx, safi);
543
544 *idx += 1;
545 return *idx;
546 }
547
548 static int peer_address_self_check(struct bgp *bgp, union sockunion *su)
549 {
550 struct interface *ifp = NULL;
551
552 if (su->sa.sa_family == AF_INET)
553 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
554 else if (su->sa.sa_family == AF_INET6)
555 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
556 su->sin6.sin6_scope_id,
557 bgp->vrf_id);
558
559 if (ifp)
560 return 1;
561
562 return 0;
563 }
564
565 /* Utility function for looking up peer from VTY. */
566 /* This is used only for configuration, so disallow if attempted on
567 * a dynamic neighbor.
568 */
569 static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
570 {
571 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
572 int ret;
573 union sockunion su;
574 struct peer *peer;
575
576 if (!bgp) {
577 return NULL;
578 }
579
580 ret = str2sockunion(ip_str, &su);
581 if (ret < 0) {
582 peer = peer_lookup_by_conf_if(bgp, ip_str);
583 if (!peer) {
584 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
585 == NULL) {
586 vty_out(vty,
587 "%% Malformed address or name: %s\n",
588 ip_str);
589 return NULL;
590 }
591 }
592 } else {
593 peer = peer_lookup(bgp, &su);
594 if (!peer) {
595 vty_out(vty,
596 "%% Specify remote-as or peer-group commands first\n");
597 return NULL;
598 }
599 if (peer_dynamic_neighbor(peer)) {
600 vty_out(vty,
601 "%% Operation not allowed on a dynamic neighbor\n");
602 return NULL;
603 }
604 }
605 return peer;
606 }
607
608 /* Utility function for looking up peer or peer group. */
609 /* This is used only for configuration, so disallow if attempted on
610 * a dynamic neighbor.
611 */
612 struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
613 {
614 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
615 int ret;
616 union sockunion su;
617 struct peer *peer = NULL;
618 struct peer_group *group = NULL;
619
620 if (!bgp) {
621 return NULL;
622 }
623
624 ret = str2sockunion(peer_str, &su);
625 if (ret == 0) {
626 /* IP address, locate peer. */
627 peer = peer_lookup(bgp, &su);
628 } else {
629 /* Not IP, could match either peer configured on interface or a
630 * group. */
631 peer = peer_lookup_by_conf_if(bgp, peer_str);
632 if (!peer)
633 group = peer_group_lookup(bgp, peer_str);
634 }
635
636 if (peer) {
637 if (peer_dynamic_neighbor(peer)) {
638 vty_out(vty,
639 "%% Operation not allowed on a dynamic neighbor\n");
640 return NULL;
641 }
642
643 return peer;
644 }
645
646 if (group)
647 return group->conf;
648
649 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
650
651 return NULL;
652 }
653
654 int bgp_vty_return(struct vty *vty, int ret)
655 {
656 const char *str = NULL;
657
658 switch (ret) {
659 case BGP_ERR_INVALID_VALUE:
660 str = "Invalid value";
661 break;
662 case BGP_ERR_INVALID_FLAG:
663 str = "Invalid flag";
664 break;
665 case BGP_ERR_PEER_GROUP_SHUTDOWN:
666 str = "Peer-group has been shutdown. Activate the peer-group first";
667 break;
668 case BGP_ERR_PEER_FLAG_CONFLICT:
669 str = "Can't set override-capability and strict-capability-match at the same time";
670 break;
671 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
672 str = "Specify remote-as or peer-group remote AS first";
673 break;
674 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
675 str = "Cannot change the peer-group. Deconfigure first";
676 break;
677 case BGP_ERR_PEER_GROUP_MISMATCH:
678 str = "Peer is not a member of this peer-group";
679 break;
680 case BGP_ERR_PEER_FILTER_CONFLICT:
681 str = "Prefix/distribute list can not co-exist";
682 break;
683 case BGP_ERR_NOT_INTERNAL_PEER:
684 str = "Invalid command. Not an internal neighbor";
685 break;
686 case BGP_ERR_REMOVE_PRIVATE_AS:
687 str = "remove-private-AS cannot be configured for IBGP peers";
688 break;
689 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
690 str = "Local-AS allowed only for EBGP peers";
691 break;
692 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
693 str = "Cannot have local-as same as BGP AS number";
694 break;
695 case BGP_ERR_TCPSIG_FAILED:
696 str = "Error while applying TCP-Sig to session(s)";
697 break;
698 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
699 str = "ebgp-multihop and ttl-security cannot be configured together";
700 break;
701 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
702 str = "ttl-security only allowed for EBGP peers";
703 break;
704 case BGP_ERR_AS_OVERRIDE:
705 str = "as-override cannot be configured for IBGP peers";
706 break;
707 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
708 str = "Invalid limit for number of dynamic neighbors";
709 break;
710 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
711 str = "Dynamic neighbor listen range already exists";
712 break;
713 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
714 str = "Operation not allowed on a dynamic neighbor";
715 break;
716 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
717 str = "Operation not allowed on a directly connected neighbor";
718 break;
719 case BGP_ERR_PEER_SAFI_CONFLICT:
720 str = GR_INVALID;
721 break;
722 case BGP_ERR_GR_INVALID_CMD:
723 str = "The Graceful Restart command used is not valid at this moment.";
724 break;
725 case BGP_ERR_GR_OPERATION_FAILED:
726 str = "The Graceful Restart Operation failed due to an err.";
727 break;
728 case BGP_GR_NO_OPERATION:
729 str = GR_NO_OPER;
730 break;
731 }
732 if (str) {
733 vty_out(vty, "%% %s\n", str);
734 return CMD_WARNING_CONFIG_FAILED;
735 }
736 return CMD_SUCCESS;
737 }
738
739 /* BGP clear sort. */
740 enum clear_sort {
741 clear_all,
742 clear_peer,
743 clear_group,
744 clear_external,
745 clear_as
746 };
747
748 static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
749 safi_t safi, int error)
750 {
751 switch (error) {
752 case BGP_ERR_AF_UNCONFIGURED:
753 vty_out(vty,
754 "%%BGP: Enable %s address family for the neighbor %s\n",
755 get_afi_safi_str(afi, safi, false), peer->host);
756 break;
757 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
758 vty_out(vty,
759 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
760 peer->host);
761 break;
762 default:
763 break;
764 }
765 }
766
767 static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi,
768 struct listnode *nnode, enum bgp_clear_type stype)
769 {
770 int ret = 0;
771
772 /* if afi/.safi not specified, spin thru all of them */
773 if ((afi == AFI_UNSPEC) && (safi == SAFI_UNSPEC)) {
774 afi_t tmp_afi;
775 safi_t tmp_safi;
776
777 FOREACH_AFI_SAFI (tmp_afi, tmp_safi) {
778 if (!peer->afc[tmp_afi][tmp_safi])
779 continue;
780
781 if (stype == BGP_CLEAR_SOFT_NONE)
782 ret = peer_clear(peer, &nnode);
783 else
784 ret = peer_clear_soft(peer, tmp_afi, tmp_safi,
785 stype);
786 }
787 /* if afi specified and safi not, spin thru safis on this afi */
788 } else if (safi == SAFI_UNSPEC) {
789 safi_t tmp_safi;
790
791 for (tmp_safi = SAFI_UNICAST;
792 tmp_safi < SAFI_MAX; tmp_safi++) {
793 if (!peer->afc[afi][tmp_safi])
794 continue;
795
796 if (stype == BGP_CLEAR_SOFT_NONE)
797 ret = peer_clear(peer, &nnode);
798 else
799 ret = peer_clear_soft(peer, afi,
800 tmp_safi, stype);
801 }
802 /* both afi/safi specified, let the caller know if not defined */
803 } else {
804 if (!peer->afc[afi][safi])
805 return 1;
806
807 if (stype == BGP_CLEAR_SOFT_NONE)
808 ret = peer_clear(peer, &nnode);
809 else
810 ret = peer_clear_soft(peer, afi, safi, stype);
811 }
812
813 return ret;
814 }
815
816 /* `clear ip bgp' functions. */
817 static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
818 enum clear_sort sort, enum bgp_clear_type stype,
819 const char *arg)
820 {
821 int ret = 0;
822 bool found = false;
823 struct peer *peer;
824
825 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
826
827 /* Clear all neighbors. */
828 /*
829 * Pass along pointer to next node to peer_clear() when walking all
830 * nodes on the BGP instance as that may get freed if it is a
831 * doppelganger
832 */
833 if (sort == clear_all) {
834 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
835
836 bgp_peer_gr_flags_update(peer);
837
838 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
839 gr_router_detected = true;
840
841 ret = bgp_peer_clear(peer, afi, safi, nnode,
842 stype);
843
844 if (ret < 0)
845 bgp_clear_vty_error(vty, peer, afi, safi, ret);
846 }
847
848 if (gr_router_detected
849 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
850 bgp_zebra_send_capabilities(bgp, false);
851 } else if (!gr_router_detected
852 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
853 bgp_zebra_send_capabilities(bgp, true);
854 }
855
856 /* This is to apply read-only mode on this clear. */
857 if (stype == BGP_CLEAR_SOFT_NONE)
858 bgp->update_delay_over = 0;
859
860 return CMD_SUCCESS;
861 }
862
863 /* Clear specified neighbor. */
864 if (sort == clear_peer) {
865 union sockunion su;
866
867 /* Make sockunion for lookup. */
868 ret = str2sockunion(arg, &su);
869 if (ret < 0) {
870 peer = peer_lookup_by_conf_if(bgp, arg);
871 if (!peer) {
872 peer = peer_lookup_by_hostname(bgp, arg);
873 if (!peer) {
874 vty_out(vty,
875 "Malformed address or name: %s\n",
876 arg);
877 return CMD_WARNING;
878 }
879 }
880 } else {
881 peer = peer_lookup(bgp, &su);
882 if (!peer) {
883 vty_out(vty,
884 "%%BGP: Unknown neighbor - \"%s\"\n",
885 arg);
886 return CMD_WARNING;
887 }
888 }
889
890 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
891 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
892
893 ret = bgp_peer_clear(peer, afi, safi, NULL, stype);
894
895 /* if afi/safi not defined for this peer, let caller know */
896 if (ret == 1)
897 ret = BGP_ERR_AF_UNCONFIGURED;
898
899 if (ret < 0)
900 bgp_clear_vty_error(vty, peer, afi, safi, ret);
901
902 return CMD_SUCCESS;
903 }
904
905 /* Clear all neighbors belonging to a specific peer-group. */
906 if (sort == clear_group) {
907 struct peer_group *group;
908
909 group = peer_group_lookup(bgp, arg);
910 if (!group) {
911 vty_out(vty, "%%BGP: No such peer-group %s\n", arg);
912 return CMD_WARNING;
913 }
914
915 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
916 ret = bgp_peer_clear(peer, afi, safi, nnode, stype);
917
918 if (ret < 0)
919 bgp_clear_vty_error(vty, peer, afi, safi, ret);
920 else
921 found = true;
922 }
923
924 if (!found)
925 vty_out(vty,
926 "%%BGP: No %s peer belonging to peer-group %s is configured\n",
927 get_afi_safi_str(afi, safi, false), arg);
928
929 return CMD_SUCCESS;
930 }
931
932 /* Clear all external (eBGP) neighbors. */
933 if (sort == clear_external) {
934 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
935 if (peer->sort == BGP_PEER_IBGP)
936 continue;
937
938 bgp_peer_gr_flags_update(peer);
939
940 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
941 gr_router_detected = true;
942
943 ret = bgp_peer_clear(peer, afi, safi, nnode, stype);
944
945 if (ret < 0)
946 bgp_clear_vty_error(vty, peer, afi, safi, ret);
947 else
948 found = true;
949 }
950
951 if (gr_router_detected
952 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
953 bgp_zebra_send_capabilities(bgp, false);
954 } else if (!gr_router_detected
955 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
956 bgp_zebra_send_capabilities(bgp, true);
957 }
958
959 if (!found)
960 vty_out(vty,
961 "%%BGP: No external %s peer is configured\n",
962 get_afi_safi_str(afi, safi, false));
963
964 return CMD_SUCCESS;
965 }
966
967 /* Clear all neighbors belonging to a specific AS. */
968 if (sort == clear_as) {
969 as_t as = strtoul(arg, NULL, 10);
970
971 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
972 if (peer->as != as)
973 continue;
974
975 bgp_peer_gr_flags_update(peer);
976
977 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
978 gr_router_detected = true;
979
980 ret = bgp_peer_clear(peer, afi, safi, nnode, stype);
981
982 if (ret < 0)
983 bgp_clear_vty_error(vty, peer, afi, safi, ret);
984 else
985 found = true;
986 }
987
988 if (gr_router_detected
989 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
990 bgp_zebra_send_capabilities(bgp, false);
991 } else if (!gr_router_detected
992 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
993 bgp_zebra_send_capabilities(bgp, true);
994 }
995
996 if (!found)
997 vty_out(vty,
998 "%%BGP: No %s peer is configured with AS %s\n",
999 get_afi_safi_str(afi, safi, false), arg);
1000
1001 return CMD_SUCCESS;
1002 }
1003
1004 return CMD_SUCCESS;
1005 }
1006
1007 static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
1008 safi_t safi, enum clear_sort sort,
1009 enum bgp_clear_type stype, const char *arg)
1010 {
1011 struct bgp *bgp;
1012
1013 /* BGP structure lookup. */
1014 if (name) {
1015 bgp = bgp_lookup_by_name(name);
1016 if (bgp == NULL) {
1017 vty_out(vty, "Can't find BGP instance %s\n", name);
1018 return CMD_WARNING;
1019 }
1020 } else {
1021 bgp = bgp_get_default();
1022 if (bgp == NULL) {
1023 vty_out(vty, "No BGP process is configured\n");
1024 return CMD_WARNING;
1025 }
1026 }
1027
1028 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
1029 }
1030
1031 /* clear soft inbound */
1032 static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
1033 {
1034 afi_t afi;
1035 safi_t safi;
1036
1037 FOREACH_AFI_SAFI (afi, safi)
1038 bgp_clear_vty(vty, name, afi, safi, clear_all,
1039 BGP_CLEAR_SOFT_IN, NULL);
1040 }
1041
1042 /* clear soft outbound */
1043 static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
1044 {
1045 afi_t afi;
1046 safi_t safi;
1047
1048 FOREACH_AFI_SAFI (afi, safi)
1049 bgp_clear_vty(vty, name, afi, safi, clear_all,
1050 BGP_CLEAR_SOFT_OUT, NULL);
1051 }
1052
1053
1054 #ifndef VTYSH_EXTRACT_PL
1055 #include "bgpd/bgp_vty_clippy.c"
1056 #endif
1057
1058 DEFUN_HIDDEN (bgp_local_mac,
1059 bgp_local_mac_cmd,
1060 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
1061 BGP_STR
1062 "Local MAC config\n"
1063 "VxLAN Network Identifier\n"
1064 "VNI number\n"
1065 "local mac\n"
1066 "mac address\n"
1067 "mac-mobility sequence\n"
1068 "seq number\n")
1069 {
1070 int rv;
1071 vni_t vni;
1072 struct ethaddr mac;
1073 struct ipaddr ip;
1074 uint32_t seq;
1075 struct bgp *bgp;
1076
1077 vni = strtoul(argv[3]->arg, NULL, 10);
1078 if (!prefix_str2mac(argv[5]->arg, &mac)) {
1079 vty_out(vty, "%% Malformed MAC address\n");
1080 return CMD_WARNING;
1081 }
1082 memset(&ip, 0, sizeof(ip));
1083 seq = strtoul(argv[7]->arg, NULL, 10);
1084
1085 bgp = bgp_get_default();
1086 if (!bgp) {
1087 vty_out(vty, "Default BGP instance is not there\n");
1088 return CMD_WARNING;
1089 }
1090
1091 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq);
1092 if (rv < 0) {
1093 vty_out(vty, "Internal error\n");
1094 return CMD_WARNING;
1095 }
1096
1097 return CMD_SUCCESS;
1098 }
1099
1100 DEFUN_HIDDEN (no_bgp_local_mac,
1101 no_bgp_local_mac_cmd,
1102 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
1103 NO_STR
1104 BGP_STR
1105 "Local MAC config\n"
1106 "VxLAN Network Identifier\n"
1107 "VNI number\n"
1108 "local mac\n"
1109 "mac address\n")
1110 {
1111 int rv;
1112 vni_t vni;
1113 struct ethaddr mac;
1114 struct ipaddr ip;
1115 struct bgp *bgp;
1116
1117 vni = strtoul(argv[4]->arg, NULL, 10);
1118 if (!prefix_str2mac(argv[6]->arg, &mac)) {
1119 vty_out(vty, "%% Malformed MAC address\n");
1120 return CMD_WARNING;
1121 }
1122 memset(&ip, 0, sizeof(ip));
1123
1124 bgp = bgp_get_default();
1125 if (!bgp) {
1126 vty_out(vty, "Default BGP instance is not there\n");
1127 return CMD_WARNING;
1128 }
1129
1130 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
1131 if (rv < 0) {
1132 vty_out(vty, "Internal error\n");
1133 return CMD_WARNING;
1134 }
1135
1136 return CMD_SUCCESS;
1137 }
1138
1139 DEFUN (no_synchronization,
1140 no_synchronization_cmd,
1141 "no synchronization",
1142 NO_STR
1143 "Perform IGP synchronization\n")
1144 {
1145 return CMD_SUCCESS;
1146 }
1147
1148 DEFUN (no_auto_summary,
1149 no_auto_summary_cmd,
1150 "no auto-summary",
1151 NO_STR
1152 "Enable automatic network number summarization\n")
1153 {
1154 return CMD_SUCCESS;
1155 }
1156
1157 /* "router bgp" commands. */
1158 DEFUN_NOSH (router_bgp,
1159 router_bgp_cmd,
1160 "router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1161 ROUTER_STR
1162 BGP_STR
1163 AS_STR
1164 BGP_INSTANCE_HELP_STR)
1165 {
1166 int idx_asn = 2;
1167 int idx_view_vrf = 3;
1168 int idx_vrf = 4;
1169 int is_new_bgp = 0;
1170 int ret;
1171 as_t as;
1172 struct bgp *bgp;
1173 const char *name = NULL;
1174 enum bgp_instance_type inst_type;
1175
1176 // "router bgp" without an ASN
1177 if (argc == 2) {
1178 // Pending: Make VRF option available for ASN less config
1179 bgp = bgp_get_default();
1180
1181 if (bgp == NULL) {
1182 vty_out(vty, "%% No BGP process is configured\n");
1183 return CMD_WARNING_CONFIG_FAILED;
1184 }
1185
1186 if (listcount(bm->bgp) > 1) {
1187 vty_out(vty, "%% Please specify ASN and VRF\n");
1188 return CMD_WARNING_CONFIG_FAILED;
1189 }
1190 }
1191
1192 // "router bgp X"
1193 else {
1194 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1195
1196 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1197 if (argc > 3) {
1198 name = argv[idx_vrf]->arg;
1199
1200 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1201 if (strmatch(name, VRF_DEFAULT_NAME))
1202 name = NULL;
1203 else
1204 inst_type = BGP_INSTANCE_TYPE_VRF;
1205 } else if (!strcmp(argv[idx_view_vrf]->text, "view"))
1206 inst_type = BGP_INSTANCE_TYPE_VIEW;
1207 }
1208
1209 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1210 is_new_bgp = (bgp_lookup(as, name) == NULL);
1211
1212 ret = bgp_get_vty(&bgp, &as, name, inst_type);
1213 switch (ret) {
1214 case BGP_ERR_AS_MISMATCH:
1215 vty_out(vty, "BGP is already running; AS is %u\n", as);
1216 return CMD_WARNING_CONFIG_FAILED;
1217 case BGP_ERR_INSTANCE_MISMATCH:
1218 vty_out(vty,
1219 "BGP instance name and AS number mismatch\n");
1220 vty_out(vty,
1221 "BGP instance is already running; AS is %u\n",
1222 as);
1223 return CMD_WARNING_CONFIG_FAILED;
1224 }
1225
1226 /*
1227 * If we just instantiated the default instance, complete
1228 * any pending VRF-VPN leaking that was configured via
1229 * earlier "router bgp X vrf FOO" blocks.
1230 */
1231 if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1232 vpn_leak_postchange_all();
1233
1234 if (inst_type == BGP_INSTANCE_TYPE_VRF)
1235 bgp_vpn_leak_export(bgp);
1236 /* Pending: handle when user tries to change a view to vrf n vv.
1237 */
1238 }
1239
1240 /* unset the auto created flag as the user config is now present */
1241 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
1242 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1243
1244 return CMD_SUCCESS;
1245 }
1246
1247 /* "no router bgp" commands. */
1248 DEFUN (no_router_bgp,
1249 no_router_bgp_cmd,
1250 "no router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1251 NO_STR
1252 ROUTER_STR
1253 BGP_STR
1254 AS_STR
1255 BGP_INSTANCE_HELP_STR)
1256 {
1257 int idx_asn = 3;
1258 int idx_vrf = 5;
1259 as_t as;
1260 struct bgp *bgp;
1261 const char *name = NULL;
1262
1263 // "no router bgp" without an ASN
1264 if (argc == 3) {
1265 // Pending: Make VRF option available for ASN less config
1266 bgp = bgp_get_default();
1267
1268 if (bgp == NULL) {
1269 vty_out(vty, "%% No BGP process is configured\n");
1270 return CMD_WARNING_CONFIG_FAILED;
1271 }
1272
1273 if (listcount(bm->bgp) > 1) {
1274 vty_out(vty, "%% Please specify ASN and VRF\n");
1275 return CMD_WARNING_CONFIG_FAILED;
1276 }
1277
1278 if (bgp->l3vni) {
1279 vty_out(vty, "%% Please unconfigure l3vni %u",
1280 bgp->l3vni);
1281 return CMD_WARNING_CONFIG_FAILED;
1282 }
1283 } else {
1284 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1285
1286 if (argc > 4)
1287 name = argv[idx_vrf]->arg;
1288
1289 /* Lookup bgp structure. */
1290 bgp = bgp_lookup(as, name);
1291 if (!bgp) {
1292 vty_out(vty, "%% Can't find BGP instance\n");
1293 return CMD_WARNING_CONFIG_FAILED;
1294 }
1295
1296 if (bgp->l3vni) {
1297 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1298 bgp->l3vni);
1299 return CMD_WARNING_CONFIG_FAILED;
1300 }
1301
1302 /* Cannot delete default instance if vrf instances exist */
1303 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
1304 struct listnode *node;
1305 struct bgp *tmp_bgp;
1306
1307 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, tmp_bgp)) {
1308 if (tmp_bgp->inst_type
1309 == BGP_INSTANCE_TYPE_VRF) {
1310 vty_out(vty,
1311 "%% Cannot delete default BGP instance. Dependent VRF instances exist\n");
1312 return CMD_WARNING_CONFIG_FAILED;
1313 }
1314 }
1315 }
1316 }
1317
1318 if (bgp_vpn_leak_unimport(bgp, vty))
1319 return CMD_WARNING_CONFIG_FAILED;
1320
1321 bgp_delete(bgp);
1322
1323 return CMD_SUCCESS;
1324 }
1325
1326
1327 /* BGP router-id. */
1328
1329 DEFPY (bgp_router_id,
1330 bgp_router_id_cmd,
1331 "bgp router-id A.B.C.D",
1332 BGP_STR
1333 "Override configured router identifier\n"
1334 "Manually configured router identifier\n")
1335 {
1336 VTY_DECLVAR_CONTEXT(bgp, bgp);
1337 bgp_router_id_static_set(bgp, router_id);
1338 return CMD_SUCCESS;
1339 }
1340
1341 DEFPY (no_bgp_router_id,
1342 no_bgp_router_id_cmd,
1343 "no bgp router-id [A.B.C.D]",
1344 NO_STR
1345 BGP_STR
1346 "Override configured router identifier\n"
1347 "Manually configured router identifier\n")
1348 {
1349 VTY_DECLVAR_CONTEXT(bgp, bgp);
1350
1351 if (router_id_str) {
1352 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1353 vty_out(vty, "%% BGP router-id doesn't match\n");
1354 return CMD_WARNING_CONFIG_FAILED;
1355 }
1356 }
1357
1358 router_id.s_addr = 0;
1359 bgp_router_id_static_set(bgp, router_id);
1360
1361 return CMD_SUCCESS;
1362 }
1363
1364
1365 /* BGP Cluster ID. */
1366 DEFUN (bgp_cluster_id,
1367 bgp_cluster_id_cmd,
1368 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1369 BGP_STR
1370 "Configure Route-Reflector Cluster-id\n"
1371 "Route-Reflector Cluster-id in IP address format\n"
1372 "Route-Reflector Cluster-id as 32 bit quantity\n")
1373 {
1374 VTY_DECLVAR_CONTEXT(bgp, bgp);
1375 int idx_ipv4 = 2;
1376 int ret;
1377 struct in_addr cluster;
1378
1379 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1380 if (!ret) {
1381 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1382 return CMD_WARNING_CONFIG_FAILED;
1383 }
1384
1385 bgp_cluster_id_set(bgp, &cluster);
1386 bgp_clear_star_soft_out(vty, bgp->name);
1387
1388 return CMD_SUCCESS;
1389 }
1390
1391 DEFUN (no_bgp_cluster_id,
1392 no_bgp_cluster_id_cmd,
1393 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1394 NO_STR
1395 BGP_STR
1396 "Configure Route-Reflector Cluster-id\n"
1397 "Route-Reflector Cluster-id in IP address format\n"
1398 "Route-Reflector Cluster-id as 32 bit quantity\n")
1399 {
1400 VTY_DECLVAR_CONTEXT(bgp, bgp);
1401 bgp_cluster_id_unset(bgp);
1402 bgp_clear_star_soft_out(vty, bgp->name);
1403
1404 return CMD_SUCCESS;
1405 }
1406
1407 DEFUN (bgp_confederation_identifier,
1408 bgp_confederation_identifier_cmd,
1409 "bgp confederation identifier (1-4294967295)",
1410 "BGP specific commands\n"
1411 "AS confederation parameters\n"
1412 "AS number\n"
1413 "Set routing domain confederation AS\n")
1414 {
1415 VTY_DECLVAR_CONTEXT(bgp, bgp);
1416 int idx_number = 3;
1417 as_t as;
1418
1419 as = strtoul(argv[idx_number]->arg, NULL, 10);
1420
1421 bgp_confederation_id_set(bgp, as);
1422
1423 return CMD_SUCCESS;
1424 }
1425
1426 DEFUN (no_bgp_confederation_identifier,
1427 no_bgp_confederation_identifier_cmd,
1428 "no bgp confederation identifier [(1-4294967295)]",
1429 NO_STR
1430 "BGP specific commands\n"
1431 "AS confederation parameters\n"
1432 "AS number\n"
1433 "Set routing domain confederation AS\n")
1434 {
1435 VTY_DECLVAR_CONTEXT(bgp, bgp);
1436 bgp_confederation_id_unset(bgp);
1437
1438 return CMD_SUCCESS;
1439 }
1440
1441 DEFUN (bgp_confederation_peers,
1442 bgp_confederation_peers_cmd,
1443 "bgp confederation peers (1-4294967295)...",
1444 "BGP specific commands\n"
1445 "AS confederation parameters\n"
1446 "Peer ASs in BGP confederation\n"
1447 AS_STR)
1448 {
1449 VTY_DECLVAR_CONTEXT(bgp, bgp);
1450 int idx_asn = 3;
1451 as_t as;
1452 int i;
1453
1454 for (i = idx_asn; i < argc; i++) {
1455 as = strtoul(argv[i]->arg, NULL, 10);
1456
1457 if (bgp->as == as) {
1458 vty_out(vty,
1459 "%% Local member-AS not allowed in confed peer list\n");
1460 continue;
1461 }
1462
1463 bgp_confederation_peers_add(bgp, as);
1464 }
1465 return CMD_SUCCESS;
1466 }
1467
1468 DEFUN (no_bgp_confederation_peers,
1469 no_bgp_confederation_peers_cmd,
1470 "no bgp confederation peers (1-4294967295)...",
1471 NO_STR
1472 "BGP specific commands\n"
1473 "AS confederation parameters\n"
1474 "Peer ASs in BGP confederation\n"
1475 AS_STR)
1476 {
1477 VTY_DECLVAR_CONTEXT(bgp, bgp);
1478 int idx_asn = 4;
1479 as_t as;
1480 int i;
1481
1482 for (i = idx_asn; i < argc; i++) {
1483 as = strtoul(argv[i]->arg, NULL, 10);
1484
1485 bgp_confederation_peers_remove(bgp, as);
1486 }
1487 return CMD_SUCCESS;
1488 }
1489
1490 /**
1491 * Central routine for maximum-paths configuration.
1492 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1493 * @set: 1 for setting values, 0 for removing the max-paths config.
1494 */
1495 static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
1496 const char *mpaths, uint16_t options,
1497 int set)
1498 {
1499 VTY_DECLVAR_CONTEXT(bgp, bgp);
1500 uint16_t maxpaths = 0;
1501 int ret;
1502 afi_t afi;
1503 safi_t safi;
1504
1505 afi = bgp_node_afi(vty);
1506 safi = bgp_node_safi(vty);
1507
1508 if (set) {
1509 maxpaths = strtol(mpaths, NULL, 10);
1510 if (maxpaths > multipath_num) {
1511 vty_out(vty,
1512 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1513 maxpaths, multipath_num);
1514 return CMD_WARNING_CONFIG_FAILED;
1515 }
1516 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1517 options);
1518 } else
1519 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1520
1521 if (ret < 0) {
1522 vty_out(vty,
1523 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1524 (set == 1) ? "" : "un",
1525 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1526 maxpaths, afi, safi);
1527 return CMD_WARNING_CONFIG_FAILED;
1528 }
1529
1530 bgp_recalculate_all_bestpaths(bgp);
1531
1532 return CMD_SUCCESS;
1533 }
1534
1535 DEFUN (bgp_maxmed_admin,
1536 bgp_maxmed_admin_cmd,
1537 "bgp max-med administrative ",
1538 BGP_STR
1539 "Advertise routes with max-med\n"
1540 "Administratively applied, for an indefinite period\n")
1541 {
1542 VTY_DECLVAR_CONTEXT(bgp, bgp);
1543
1544 bgp->v_maxmed_admin = 1;
1545 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1546
1547 bgp_maxmed_update(bgp);
1548
1549 return CMD_SUCCESS;
1550 }
1551
1552 DEFUN (bgp_maxmed_admin_medv,
1553 bgp_maxmed_admin_medv_cmd,
1554 "bgp max-med administrative (0-4294967295)",
1555 BGP_STR
1556 "Advertise routes with max-med\n"
1557 "Administratively applied, for an indefinite period\n"
1558 "Max MED value to be used\n")
1559 {
1560 VTY_DECLVAR_CONTEXT(bgp, bgp);
1561 int idx_number = 3;
1562
1563 bgp->v_maxmed_admin = 1;
1564 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
1565
1566 bgp_maxmed_update(bgp);
1567
1568 return CMD_SUCCESS;
1569 }
1570
1571 DEFUN (no_bgp_maxmed_admin,
1572 no_bgp_maxmed_admin_cmd,
1573 "no bgp max-med administrative [(0-4294967295)]",
1574 NO_STR
1575 BGP_STR
1576 "Advertise routes with max-med\n"
1577 "Administratively applied, for an indefinite period\n"
1578 "Max MED value to be used\n")
1579 {
1580 VTY_DECLVAR_CONTEXT(bgp, bgp);
1581 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1582 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1583 bgp_maxmed_update(bgp);
1584
1585 return CMD_SUCCESS;
1586 }
1587
1588 DEFUN (bgp_maxmed_onstartup,
1589 bgp_maxmed_onstartup_cmd,
1590 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
1591 BGP_STR
1592 "Advertise routes with max-med\n"
1593 "Effective on a startup\n"
1594 "Time (seconds) period for max-med\n"
1595 "Max MED value to be used\n")
1596 {
1597 VTY_DECLVAR_CONTEXT(bgp, bgp);
1598 int idx = 0;
1599
1600 argv_find(argv, argc, "(5-86400)", &idx);
1601 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
1602 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1603 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
1604 else
1605 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1606
1607 bgp_maxmed_update(bgp);
1608
1609 return CMD_SUCCESS;
1610 }
1611
1612 DEFUN (no_bgp_maxmed_onstartup,
1613 no_bgp_maxmed_onstartup_cmd,
1614 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
1615 NO_STR
1616 BGP_STR
1617 "Advertise routes with max-med\n"
1618 "Effective on a startup\n"
1619 "Time (seconds) period for max-med\n"
1620 "Max MED value to be used\n")
1621 {
1622 VTY_DECLVAR_CONTEXT(bgp, bgp);
1623
1624 /* Cancel max-med onstartup if its on */
1625 if (bgp->t_maxmed_onstartup) {
1626 THREAD_TIMER_OFF(bgp->t_maxmed_onstartup);
1627 bgp->maxmed_onstartup_over = 1;
1628 }
1629
1630 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
1631 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1632
1633 bgp_maxmed_update(bgp);
1634
1635 return CMD_SUCCESS;
1636 }
1637
1638 static int bgp_update_delay_config_vty(struct vty *vty, const char *delay,
1639 const char *wait)
1640 {
1641 VTY_DECLVAR_CONTEXT(bgp, bgp);
1642 uint16_t update_delay;
1643 uint16_t establish_wait;
1644
1645 update_delay = strtoul(delay, NULL, 10);
1646
1647 if (!wait) /* update-delay <delay> */
1648 {
1649 bgp->v_update_delay = update_delay;
1650 bgp->v_establish_wait = bgp->v_update_delay;
1651 return CMD_SUCCESS;
1652 }
1653
1654 /* update-delay <delay> <establish-wait> */
1655 establish_wait = atoi(wait);
1656 if (update_delay < establish_wait) {
1657 vty_out(vty,
1658 "%%Failed: update-delay less than the establish-wait!\n");
1659 return CMD_WARNING_CONFIG_FAILED;
1660 }
1661
1662 bgp->v_update_delay = update_delay;
1663 bgp->v_establish_wait = establish_wait;
1664
1665 return CMD_SUCCESS;
1666 }
1667
1668 static int bgp_update_delay_deconfig_vty(struct vty *vty)
1669 {
1670 VTY_DECLVAR_CONTEXT(bgp, bgp);
1671
1672 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
1673 bgp->v_establish_wait = bgp->v_update_delay;
1674
1675 return CMD_SUCCESS;
1676 }
1677
1678 void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
1679 {
1680 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1681 vty_out(vty, " update-delay %d", bgp->v_update_delay);
1682 if (bgp->v_update_delay != bgp->v_establish_wait)
1683 vty_out(vty, " %d", bgp->v_establish_wait);
1684 vty_out(vty, "\n");
1685 }
1686 }
1687
1688
1689 /* Update-delay configuration */
1690 DEFUN (bgp_update_delay,
1691 bgp_update_delay_cmd,
1692 "update-delay (0-3600)",
1693 "Force initial delay for best-path and updates\n"
1694 "Seconds\n")
1695 {
1696 int idx_number = 1;
1697 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg, NULL);
1698 }
1699
1700 DEFUN (bgp_update_delay_establish_wait,
1701 bgp_update_delay_establish_wait_cmd,
1702 "update-delay (0-3600) (1-3600)",
1703 "Force initial delay for best-path and updates\n"
1704 "Seconds\n"
1705 "Seconds\n")
1706 {
1707 int idx_number = 1;
1708 int idx_number_2 = 2;
1709 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg,
1710 argv[idx_number_2]->arg);
1711 }
1712
1713 /* Update-delay deconfiguration */
1714 DEFUN (no_bgp_update_delay,
1715 no_bgp_update_delay_cmd,
1716 "no update-delay [(0-3600) [(1-3600)]]",
1717 NO_STR
1718 "Force initial delay for best-path and updates\n"
1719 "Seconds\n"
1720 "Seconds\n")
1721 {
1722 return bgp_update_delay_deconfig_vty(vty);
1723 }
1724
1725
1726 static int bgp_wpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
1727 bool set)
1728 {
1729 VTY_DECLVAR_CONTEXT(bgp, bgp);
1730
1731 quanta = set ? quanta : BGP_WRITE_PACKET_MAX;
1732 atomic_store_explicit(&bgp->wpkt_quanta, quanta, memory_order_relaxed);
1733
1734 return CMD_SUCCESS;
1735 }
1736
1737 static int bgp_rpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
1738 bool set)
1739 {
1740 VTY_DECLVAR_CONTEXT(bgp, bgp);
1741
1742 quanta = set ? quanta : BGP_READ_PACKET_MAX;
1743 atomic_store_explicit(&bgp->rpkt_quanta, quanta, memory_order_relaxed);
1744
1745 return CMD_SUCCESS;
1746 }
1747
1748 void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
1749 {
1750 uint32_t quanta =
1751 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
1752 if (quanta != BGP_WRITE_PACKET_MAX)
1753 vty_out(vty, " write-quanta %d\n", quanta);
1754 }
1755
1756 void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
1757 {
1758 uint32_t quanta =
1759 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
1760 if (quanta != BGP_READ_PACKET_MAX)
1761 vty_out(vty, " read-quanta %d\n", quanta);
1762 }
1763
1764 /* Packet quanta configuration
1765 *
1766 * XXX: The value set here controls the size of a stack buffer in the IO
1767 * thread. When changing these limits be careful to prevent stack overflow.
1768 *
1769 * Furthermore, the maximums used here should correspond to
1770 * BGP_WRITE_PACKET_MAX and BGP_READ_PACKET_MAX.
1771 */
1772 DEFPY (bgp_wpkt_quanta,
1773 bgp_wpkt_quanta_cmd,
1774 "[no] write-quanta (1-64)$quanta",
1775 NO_STR
1776 "How many packets to write to peer socket per run\n"
1777 "Number of packets\n")
1778 {
1779 return bgp_wpkt_quanta_config_vty(vty, quanta, !no);
1780 }
1781
1782 DEFPY (bgp_rpkt_quanta,
1783 bgp_rpkt_quanta_cmd,
1784 "[no] read-quanta (1-10)$quanta",
1785 NO_STR
1786 "How many packets to read from peer socket per I/O cycle\n"
1787 "Number of packets\n")
1788 {
1789 return bgp_rpkt_quanta_config_vty(vty, quanta, !no);
1790 }
1791
1792 void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
1793 {
1794 if (!bgp->heuristic_coalesce)
1795 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
1796 }
1797
1798
1799 DEFUN (bgp_coalesce_time,
1800 bgp_coalesce_time_cmd,
1801 "coalesce-time (0-4294967295)",
1802 "Subgroup coalesce timer\n"
1803 "Subgroup coalesce timer value (in ms)\n")
1804 {
1805 VTY_DECLVAR_CONTEXT(bgp, bgp);
1806
1807 int idx = 0;
1808 argv_find(argv, argc, "(0-4294967295)", &idx);
1809 bgp->heuristic_coalesce = false;
1810 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
1811 return CMD_SUCCESS;
1812 }
1813
1814 DEFUN (no_bgp_coalesce_time,
1815 no_bgp_coalesce_time_cmd,
1816 "no coalesce-time (0-4294967295)",
1817 NO_STR
1818 "Subgroup coalesce timer\n"
1819 "Subgroup coalesce timer value (in ms)\n")
1820 {
1821 VTY_DECLVAR_CONTEXT(bgp, bgp);
1822
1823 bgp->heuristic_coalesce = true;
1824 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
1825 return CMD_SUCCESS;
1826 }
1827
1828 /* Maximum-paths configuration */
1829 DEFUN (bgp_maxpaths,
1830 bgp_maxpaths_cmd,
1831 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1832 "Forward packets over multiple paths\n"
1833 "Number of paths\n")
1834 {
1835 int idx_number = 1;
1836 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
1837 argv[idx_number]->arg, 0, 1);
1838 }
1839
1840 ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
1841 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1842 "Forward packets over multiple paths\n"
1843 "Number of paths\n")
1844
1845 DEFUN (bgp_maxpaths_ibgp,
1846 bgp_maxpaths_ibgp_cmd,
1847 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1848 "Forward packets over multiple paths\n"
1849 "iBGP-multipath\n"
1850 "Number of paths\n")
1851 {
1852 int idx_number = 2;
1853 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
1854 argv[idx_number]->arg, 0, 1);
1855 }
1856
1857 ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
1858 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1859 "Forward packets over multiple paths\n"
1860 "iBGP-multipath\n"
1861 "Number of paths\n")
1862
1863 DEFUN (bgp_maxpaths_ibgp_cluster,
1864 bgp_maxpaths_ibgp_cluster_cmd,
1865 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
1866 "Forward packets over multiple paths\n"
1867 "iBGP-multipath\n"
1868 "Number of paths\n"
1869 "Match the cluster length\n")
1870 {
1871 int idx_number = 2;
1872 return bgp_maxpaths_config_vty(
1873 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
1874 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
1875 }
1876
1877 ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
1878 "maximum-paths ibgp " CMD_RANGE_STR(
1879 1, MULTIPATH_NUM) " equal-cluster-length",
1880 "Forward packets over multiple paths\n"
1881 "iBGP-multipath\n"
1882 "Number of paths\n"
1883 "Match the cluster length\n")
1884
1885 DEFUN (no_bgp_maxpaths,
1886 no_bgp_maxpaths_cmd,
1887 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
1888 NO_STR
1889 "Forward packets over multiple paths\n"
1890 "Number of paths\n")
1891 {
1892 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
1893 }
1894
1895 ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
1896 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
1897 "Forward packets over multiple paths\n"
1898 "Number of paths\n")
1899
1900 DEFUN (no_bgp_maxpaths_ibgp,
1901 no_bgp_maxpaths_ibgp_cmd,
1902 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
1903 NO_STR
1904 "Forward packets over multiple paths\n"
1905 "iBGP-multipath\n"
1906 "Number of paths\n"
1907 "Match the cluster length\n")
1908 {
1909 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
1910 }
1911
1912 ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
1913 "no maximum-paths ibgp [" CMD_RANGE_STR(
1914 1, MULTIPATH_NUM) " [equal-cluster-length]]",
1915 NO_STR
1916 "Forward packets over multiple paths\n"
1917 "iBGP-multipath\n"
1918 "Number of paths\n"
1919 "Match the cluster length\n")
1920
1921 static void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp,
1922 afi_t afi, safi_t safi)
1923 {
1924 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != MULTIPATH_NUM) {
1925 vty_out(vty, " maximum-paths %d\n",
1926 bgp->maxpaths[afi][safi].maxpaths_ebgp);
1927 }
1928
1929 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != MULTIPATH_NUM) {
1930 vty_out(vty, " maximum-paths ibgp %d",
1931 bgp->maxpaths[afi][safi].maxpaths_ibgp);
1932 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
1933 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
1934 vty_out(vty, " equal-cluster-length");
1935 vty_out(vty, "\n");
1936 }
1937 }
1938
1939 /* BGP timers. */
1940
1941 DEFUN (bgp_timers,
1942 bgp_timers_cmd,
1943 "timers bgp (0-65535) (0-65535)",
1944 "Adjust routing timers\n"
1945 "BGP timers\n"
1946 "Keepalive interval\n"
1947 "Holdtime\n")
1948 {
1949 VTY_DECLVAR_CONTEXT(bgp, bgp);
1950 int idx_number = 2;
1951 int idx_number_2 = 3;
1952 unsigned long keepalive = 0;
1953 unsigned long holdtime = 0;
1954
1955 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
1956 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
1957
1958 /* Holdtime value check. */
1959 if (holdtime < 3 && holdtime != 0) {
1960 vty_out(vty,
1961 "%% hold time value must be either 0 or greater than 3\n");
1962 return CMD_WARNING_CONFIG_FAILED;
1963 }
1964
1965 bgp_timers_set(bgp, keepalive, holdtime, DFLT_BGP_CONNECT_RETRY);
1966
1967 return CMD_SUCCESS;
1968 }
1969
1970 DEFUN (no_bgp_timers,
1971 no_bgp_timers_cmd,
1972 "no timers bgp [(0-65535) (0-65535)]",
1973 NO_STR
1974 "Adjust routing timers\n"
1975 "BGP timers\n"
1976 "Keepalive interval\n"
1977 "Holdtime\n")
1978 {
1979 VTY_DECLVAR_CONTEXT(bgp, bgp);
1980 bgp_timers_set(bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
1981 DFLT_BGP_CONNECT_RETRY);
1982
1983 return CMD_SUCCESS;
1984 }
1985
1986
1987 DEFUN (bgp_client_to_client_reflection,
1988 bgp_client_to_client_reflection_cmd,
1989 "bgp client-to-client reflection",
1990 "BGP specific commands\n"
1991 "Configure client to client route reflection\n"
1992 "reflection of routes allowed\n")
1993 {
1994 VTY_DECLVAR_CONTEXT(bgp, bgp);
1995 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1996 bgp_clear_star_soft_out(vty, bgp->name);
1997
1998 return CMD_SUCCESS;
1999 }
2000
2001 DEFUN (no_bgp_client_to_client_reflection,
2002 no_bgp_client_to_client_reflection_cmd,
2003 "no bgp client-to-client reflection",
2004 NO_STR
2005 "BGP specific commands\n"
2006 "Configure client to client route reflection\n"
2007 "reflection of routes allowed\n")
2008 {
2009 VTY_DECLVAR_CONTEXT(bgp, bgp);
2010 SET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2011 bgp_clear_star_soft_out(vty, bgp->name);
2012
2013 return CMD_SUCCESS;
2014 }
2015
2016 /* "bgp always-compare-med" configuration. */
2017 DEFUN (bgp_always_compare_med,
2018 bgp_always_compare_med_cmd,
2019 "bgp always-compare-med",
2020 "BGP specific commands\n"
2021 "Allow comparing MED from different neighbors\n")
2022 {
2023 VTY_DECLVAR_CONTEXT(bgp, bgp);
2024 SET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2025 bgp_recalculate_all_bestpaths(bgp);
2026
2027 return CMD_SUCCESS;
2028 }
2029
2030 DEFUN (no_bgp_always_compare_med,
2031 no_bgp_always_compare_med_cmd,
2032 "no bgp always-compare-med",
2033 NO_STR
2034 "BGP specific commands\n"
2035 "Allow comparing MED from different neighbors\n")
2036 {
2037 VTY_DECLVAR_CONTEXT(bgp, bgp);
2038 UNSET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2039 bgp_recalculate_all_bestpaths(bgp);
2040
2041 return CMD_SUCCESS;
2042 }
2043
2044
2045 DEFUN(bgp_ebgp_requires_policy, bgp_ebgp_requires_policy_cmd,
2046 "bgp ebgp-requires-policy",
2047 "BGP specific commands\n"
2048 "Require in and out policy for eBGP peers (RFC8212)\n")
2049 {
2050 VTY_DECLVAR_CONTEXT(bgp, bgp);
2051 bgp->ebgp_requires_policy = DEFAULT_EBGP_POLICY_ENABLED;
2052 return CMD_SUCCESS;
2053 }
2054
2055 DEFUN(no_bgp_ebgp_requires_policy, no_bgp_ebgp_requires_policy_cmd,
2056 "no bgp ebgp-requires-policy",
2057 NO_STR
2058 "BGP specific commands\n"
2059 "Require in and out policy for eBGP peers (RFC8212)\n")
2060 {
2061 VTY_DECLVAR_CONTEXT(bgp, bgp);
2062 bgp->ebgp_requires_policy = DEFAULT_EBGP_POLICY_DISABLED;
2063 return CMD_SUCCESS;
2064 }
2065
2066 DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd,
2067 "bgp reject-as-sets",
2068 "BGP specific commands\n"
2069 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2070 {
2071 VTY_DECLVAR_CONTEXT(bgp, bgp);
2072 struct listnode *node, *nnode;
2073 struct peer *peer;
2074
2075 bgp->reject_as_sets = BGP_REJECT_AS_SETS_ENABLED;
2076
2077 /* Reset existing BGP sessions to reject routes
2078 * with aspath containing AS_SET or AS_CONFED_SET.
2079 */
2080 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2081 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2082 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2083 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2084 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2085 }
2086 }
2087
2088 return CMD_SUCCESS;
2089 }
2090
2091 DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd,
2092 "no bgp reject-as-sets",
2093 NO_STR
2094 "BGP specific commands\n"
2095 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2096 {
2097 VTY_DECLVAR_CONTEXT(bgp, bgp);
2098 struct listnode *node, *nnode;
2099 struct peer *peer;
2100
2101 bgp->reject_as_sets = BGP_REJECT_AS_SETS_DISABLED;
2102
2103 /* Reset existing BGP sessions to reject routes
2104 * with aspath containing AS_SET or AS_CONFED_SET.
2105 */
2106 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2107 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2108 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2109 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2110 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2111 }
2112 }
2113
2114 return CMD_SUCCESS;
2115 }
2116
2117 /* "bgp deterministic-med" configuration. */
2118 DEFUN (bgp_deterministic_med,
2119 bgp_deterministic_med_cmd,
2120 "bgp deterministic-med",
2121 "BGP specific commands\n"
2122 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2123 {
2124 VTY_DECLVAR_CONTEXT(bgp, bgp);
2125
2126 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2127 SET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2128 bgp_recalculate_all_bestpaths(bgp);
2129 }
2130
2131 return CMD_SUCCESS;
2132 }
2133
2134 DEFUN (no_bgp_deterministic_med,
2135 no_bgp_deterministic_med_cmd,
2136 "no bgp deterministic-med",
2137 NO_STR
2138 "BGP specific commands\n"
2139 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2140 {
2141 VTY_DECLVAR_CONTEXT(bgp, bgp);
2142 int bestpath_per_as_used;
2143 afi_t afi;
2144 safi_t safi;
2145 struct peer *peer;
2146 struct listnode *node, *nnode;
2147
2148 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2149 bestpath_per_as_used = 0;
2150
2151 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2152 FOREACH_AFI_SAFI (afi, safi)
2153 if (bgp_addpath_dmed_required(
2154 peer->addpath_type[afi][safi])) {
2155 bestpath_per_as_used = 1;
2156 break;
2157 }
2158
2159 if (bestpath_per_as_used)
2160 break;
2161 }
2162
2163 if (bestpath_per_as_used) {
2164 vty_out(vty,
2165 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
2166 return CMD_WARNING_CONFIG_FAILED;
2167 } else {
2168 UNSET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2169 bgp_recalculate_all_bestpaths(bgp);
2170 }
2171 }
2172
2173 return CMD_SUCCESS;
2174 }
2175
2176 /* "bgp graceful-restart mode" configuration. */
2177 DEFUN (bgp_graceful_restart,
2178 bgp_graceful_restart_cmd,
2179 "bgp graceful-restart",
2180 "BGP specific commands\n"
2181 GR_CMD
2182 )
2183 {
2184 int ret = BGP_GR_FAILURE;
2185
2186 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2187 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : START ");
2188
2189 VTY_DECLVAR_CONTEXT(bgp, bgp);
2190
2191 ret = bgp_gr_update_all(bgp, GLOBAL_GR_CMD);
2192
2193 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2194 ret);
2195
2196 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2197 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : END ");
2198 vty_out(vty,
2199 "Graceful restart configuration changed, reset all peers to take effect\n");
2200 return bgp_vty_return(vty, ret);
2201 }
2202
2203 DEFUN (no_bgp_graceful_restart,
2204 no_bgp_graceful_restart_cmd,
2205 "no bgp graceful-restart",
2206 NO_STR
2207 "BGP specific commands\n"
2208 NO_GR_CMD
2209 )
2210 {
2211 VTY_DECLVAR_CONTEXT(bgp, bgp);
2212
2213 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2214 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : START ");
2215
2216 int ret = BGP_GR_FAILURE;
2217
2218 ret = bgp_gr_update_all(bgp, NO_GLOBAL_GR_CMD);
2219
2220 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2221 ret);
2222
2223 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2224 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : END ");
2225 vty_out(vty,
2226 "Graceful restart configuration changed, reset all peers to take effect\n");
2227
2228 return bgp_vty_return(vty, ret);
2229 }
2230
2231 DEFUN (bgp_graceful_restart_stalepath_time,
2232 bgp_graceful_restart_stalepath_time_cmd,
2233 "bgp graceful-restart stalepath-time (1-4095)",
2234 "BGP specific commands\n"
2235 "Graceful restart capability parameters\n"
2236 "Set the max time to hold onto restarting peer's stale paths\n"
2237 "Delay value (seconds)\n")
2238 {
2239 VTY_DECLVAR_CONTEXT(bgp, bgp);
2240 int idx_number = 3;
2241 uint32_t stalepath;
2242
2243 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2244 bgp->stalepath_time = stalepath;
2245 return CMD_SUCCESS;
2246 }
2247
2248 DEFUN (bgp_graceful_restart_restart_time,
2249 bgp_graceful_restart_restart_time_cmd,
2250 "bgp graceful-restart restart-time (1-4095)",
2251 "BGP specific commands\n"
2252 "Graceful restart capability parameters\n"
2253 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2254 "Delay value (seconds)\n")
2255 {
2256 VTY_DECLVAR_CONTEXT(bgp, bgp);
2257 int idx_number = 3;
2258 uint32_t restart;
2259
2260 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2261 bgp->restart_time = restart;
2262 return CMD_SUCCESS;
2263 }
2264
2265 DEFUN (bgp_graceful_restart_select_defer_time,
2266 bgp_graceful_restart_select_defer_time_cmd,
2267 "bgp graceful-restart select-defer-time (0-3600)",
2268 "BGP specific commands\n"
2269 "Graceful restart capability parameters\n"
2270 "Set the time to defer the BGP route selection after restart\n"
2271 "Delay value (seconds, 0 - disable)\n")
2272 {
2273 VTY_DECLVAR_CONTEXT(bgp, bgp);
2274 int idx_number = 3;
2275 uint32_t defer_time;
2276
2277 defer_time = strtoul(argv[idx_number]->arg, NULL, 10);
2278 bgp->select_defer_time = defer_time;
2279 if (defer_time == 0)
2280 SET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2281 else
2282 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2283
2284 return CMD_SUCCESS;
2285 }
2286
2287 DEFUN (no_bgp_graceful_restart_stalepath_time,
2288 no_bgp_graceful_restart_stalepath_time_cmd,
2289 "no bgp graceful-restart stalepath-time [(1-4095)]",
2290 NO_STR
2291 "BGP specific commands\n"
2292 "Graceful restart capability parameters\n"
2293 "Set the max time to hold onto restarting peer's stale paths\n"
2294 "Delay value (seconds)\n")
2295 {
2296 VTY_DECLVAR_CONTEXT(bgp, bgp);
2297
2298 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2299 return CMD_SUCCESS;
2300 }
2301
2302 DEFUN (no_bgp_graceful_restart_restart_time,
2303 no_bgp_graceful_restart_restart_time_cmd,
2304 "no bgp graceful-restart restart-time [(1-4095)]",
2305 NO_STR
2306 "BGP specific commands\n"
2307 "Graceful restart capability parameters\n"
2308 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2309 "Delay value (seconds)\n")
2310 {
2311 VTY_DECLVAR_CONTEXT(bgp, bgp);
2312
2313 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2314 return CMD_SUCCESS;
2315 }
2316
2317 DEFUN (no_bgp_graceful_restart_select_defer_time,
2318 no_bgp_graceful_restart_select_defer_time_cmd,
2319 "no bgp graceful-restart select-defer-time [(0-3600)]",
2320 NO_STR
2321 "BGP specific commands\n"
2322 "Graceful restart capability parameters\n"
2323 "Set the time to defer the BGP route selection after restart\n"
2324 "Delay value (seconds)\n")
2325 {
2326 VTY_DECLVAR_CONTEXT(bgp, bgp);
2327
2328 bgp->select_defer_time = BGP_DEFAULT_SELECT_DEFERRAL_TIME;
2329 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2330
2331 return CMD_SUCCESS;
2332 }
2333
2334 DEFUN (bgp_graceful_restart_preserve_fw,
2335 bgp_graceful_restart_preserve_fw_cmd,
2336 "bgp graceful-restart preserve-fw-state",
2337 "BGP specific commands\n"
2338 "Graceful restart capability parameters\n"
2339 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
2340 {
2341 VTY_DECLVAR_CONTEXT(bgp, bgp);
2342 SET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
2343 return CMD_SUCCESS;
2344 }
2345
2346 DEFUN (no_bgp_graceful_restart_preserve_fw,
2347 no_bgp_graceful_restart_preserve_fw_cmd,
2348 "no bgp graceful-restart preserve-fw-state",
2349 NO_STR
2350 "BGP specific commands\n"
2351 "Graceful restart capability parameters\n"
2352 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
2353 {
2354 VTY_DECLVAR_CONTEXT(bgp, bgp);
2355 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
2356 return CMD_SUCCESS;
2357 }
2358
2359 DEFUN (bgp_graceful_restart_disable,
2360 bgp_graceful_restart_disable_cmd,
2361 "bgp graceful-restart-disable",
2362 "BGP specific commands\n"
2363 GR_DISABLE)
2364 {
2365 int ret = BGP_GR_FAILURE;
2366
2367 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2368 zlog_debug(
2369 "[BGP_GR] bgp_graceful_restart_disable_cmd : START ");
2370
2371 VTY_DECLVAR_CONTEXT(bgp, bgp);
2372
2373 ret = bgp_gr_update_all(bgp, GLOBAL_DISABLE_CMD);
2374
2375 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
2376 bgp->peer, ret);
2377
2378 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2379 zlog_debug(
2380 "[BGP_GR] bgp_graceful_restart_disable_cmd : END ");
2381 vty_out(vty,
2382 "Graceful restart configuration changed, reset all peers to take effect\n");
2383
2384 return bgp_vty_return(vty, ret);
2385 }
2386
2387 DEFUN (no_bgp_graceful_restart_disable,
2388 no_bgp_graceful_restart_disable_cmd,
2389 "no bgp graceful-restart-disable",
2390 NO_STR
2391 "BGP specific commands\n"
2392 NO_GR_DISABLE
2393 )
2394 {
2395 VTY_DECLVAR_CONTEXT(bgp, bgp);
2396
2397 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2398 zlog_debug(
2399 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : START ");
2400
2401 int ret = BGP_GR_FAILURE;
2402
2403 ret = bgp_gr_update_all(bgp, NO_GLOBAL_DISABLE_CMD);
2404
2405 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2406 ret);
2407
2408 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2409 zlog_debug(
2410 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : END ");
2411 vty_out(vty,
2412 "Graceful restart configuration changed, reset all peers to take effect\n");
2413
2414 return bgp_vty_return(vty, ret);
2415 }
2416
2417 DEFUN (bgp_neighbor_graceful_restart_set,
2418 bgp_neighbor_graceful_restart_set_cmd,
2419 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
2420 NEIGHBOR_STR
2421 NEIGHBOR_ADDR_STR2
2422 GR_NEIGHBOR_CMD
2423 )
2424 {
2425 int idx_peer = 1;
2426 struct peer *peer;
2427 int ret = BGP_GR_FAILURE;
2428
2429 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2430
2431 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2432 zlog_debug(
2433 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : START ");
2434
2435 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2436 if (!peer)
2437 return CMD_WARNING_CONFIG_FAILED;
2438
2439 ret = bgp_neighbor_graceful_restart(peer, PEER_GR_CMD);
2440
2441 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2442 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
2443
2444 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2445 zlog_debug(
2446 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : END ");
2447 vty_out(vty,
2448 "Graceful restart configuration changed, reset this peer to take effect\n");
2449
2450 return bgp_vty_return(vty, ret);
2451 }
2452
2453 DEFUN (no_bgp_neighbor_graceful_restart,
2454 no_bgp_neighbor_graceful_restart_set_cmd,
2455 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
2456 NO_STR
2457 NEIGHBOR_STR
2458 NEIGHBOR_ADDR_STR2
2459 NO_GR_NEIGHBOR_CMD
2460 )
2461 {
2462 int idx_peer = 2;
2463 int ret = BGP_GR_FAILURE;
2464 struct peer *peer;
2465
2466 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2467
2468 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2469 if (!peer)
2470 return CMD_WARNING_CONFIG_FAILED;
2471
2472 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2473 zlog_debug(
2474 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : START ");
2475
2476 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_GR_CMD);
2477
2478 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2479 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
2480
2481 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2482 zlog_debug(
2483 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : END ");
2484 vty_out(vty,
2485 "Graceful restart configuration changed, reset this peer to take effect\n");
2486
2487 return bgp_vty_return(vty, ret);
2488 }
2489
2490 DEFUN (bgp_neighbor_graceful_restart_helper_set,
2491 bgp_neighbor_graceful_restart_helper_set_cmd,
2492 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
2493 NEIGHBOR_STR
2494 NEIGHBOR_ADDR_STR2
2495 GR_NEIGHBOR_HELPER_CMD
2496 )
2497 {
2498 int idx_peer = 1;
2499 struct peer *peer;
2500 int ret = BGP_GR_FAILURE;
2501
2502 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2503
2504 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2505 zlog_debug(
2506 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : START ");
2507
2508 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2509
2510 if (!peer)
2511 return CMD_WARNING_CONFIG_FAILED;
2512
2513
2514 ret = bgp_neighbor_graceful_restart(peer, PEER_HELPER_CMD);
2515
2516 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2517 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
2518
2519 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2520 zlog_debug(
2521 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : END ");
2522 vty_out(vty,
2523 "Graceful restart configuration changed, reset this peer to take effect\n");
2524
2525 return bgp_vty_return(vty, ret);
2526 }
2527
2528 DEFUN (no_bgp_neighbor_graceful_restart_helper,
2529 no_bgp_neighbor_graceful_restart_helper_set_cmd,
2530 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
2531 NO_STR
2532 NEIGHBOR_STR
2533 NEIGHBOR_ADDR_STR2
2534 NO_GR_NEIGHBOR_HELPER_CMD
2535 )
2536 {
2537 int idx_peer = 2;
2538 int ret = BGP_GR_FAILURE;
2539 struct peer *peer;
2540
2541 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2542
2543 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2544 if (!peer)
2545 return CMD_WARNING_CONFIG_FAILED;
2546
2547 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2548 zlog_debug(
2549 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : START ");
2550
2551 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_HELPER_CMD);
2552
2553 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2554 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
2555
2556 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2557 zlog_debug(
2558 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : END ");
2559 vty_out(vty,
2560 "Graceful restart configuration changed, reset this peer to take effect\n");
2561
2562 return bgp_vty_return(vty, ret);
2563 }
2564
2565 DEFUN (bgp_neighbor_graceful_restart_disable_set,
2566 bgp_neighbor_graceful_restart_disable_set_cmd,
2567 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
2568 NEIGHBOR_STR
2569 NEIGHBOR_ADDR_STR2
2570 GR_NEIGHBOR_DISABLE_CMD
2571 )
2572 {
2573 int idx_peer = 1;
2574 struct peer *peer;
2575 int ret = BGP_GR_FAILURE;
2576
2577 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2578
2579 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2580 zlog_debug(
2581 "[BGP_GR] bgp_neighbor_graceful_restart_disable_set_cmd : START ");
2582
2583 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2584 if (!peer)
2585 return CMD_WARNING_CONFIG_FAILED;
2586
2587 ret = bgp_neighbor_graceful_restart(peer, PEER_DISABLE_CMD);
2588
2589 if (peer->bgp->t_startup)
2590 bgp_peer_gr_flags_update(peer);
2591
2592 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2593 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
2594
2595 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2596 zlog_debug(
2597 "[BGP_GR]bgp_neighbor_graceful_restart_disable_set_cmd : END ");
2598 vty_out(vty,
2599 "Graceful restart configuration changed, reset this peer to take effect\n");
2600
2601 return bgp_vty_return(vty, ret);
2602 }
2603
2604 DEFUN (no_bgp_neighbor_graceful_restart_disable,
2605 no_bgp_neighbor_graceful_restart_disable_set_cmd,
2606 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
2607 NO_STR
2608 NEIGHBOR_STR
2609 NEIGHBOR_ADDR_STR2
2610 NO_GR_NEIGHBOR_DISABLE_CMD
2611 )
2612 {
2613 int idx_peer = 2;
2614 int ret = BGP_GR_FAILURE;
2615 struct peer *peer;
2616
2617 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2618
2619 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2620 if (!peer)
2621 return CMD_WARNING_CONFIG_FAILED;
2622
2623 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2624 zlog_debug(
2625 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : START ");
2626
2627 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_DISABLE_CMD);
2628
2629 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2630 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
2631
2632 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2633 zlog_debug(
2634 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : END ");
2635 vty_out(vty,
2636 "Graceful restart configuration changed, reset this peer to take effect\n");
2637
2638 return bgp_vty_return(vty, ret);
2639 }
2640
2641 DEFUN_HIDDEN (bgp_graceful_restart_disable_eor,
2642 bgp_graceful_restart_disable_eor_cmd,
2643 "bgp graceful-restart disable-eor",
2644 "BGP specific commands\n"
2645 "Graceful restart configuration parameters\n"
2646 "Disable EOR Check\n")
2647 {
2648 VTY_DECLVAR_CONTEXT(bgp, bgp);
2649 SET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
2650
2651 return CMD_SUCCESS;
2652 }
2653
2654 DEFUN_HIDDEN (no_bgp_graceful_restart_disable_eor,
2655 no_bgp_graceful_restart_disable_eor_cmd,
2656 "no bgp graceful-restart disable-eor",
2657 NO_STR
2658 "BGP specific commands\n"
2659 "Graceful restart configuration parameters\n"
2660 "Disable EOR Check\n")
2661 {
2662 VTY_DECLVAR_CONTEXT(bgp, bgp);
2663 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
2664
2665 return CMD_SUCCESS;
2666 }
2667
2668 DEFUN (bgp_graceful_restart_rib_stale_time,
2669 bgp_graceful_restart_rib_stale_time_cmd,
2670 "bgp graceful-restart rib-stale-time (1-3600)",
2671 "BGP specific commands\n"
2672 "Graceful restart configuration parameters\n"
2673 "Specify the stale route removal timer in rib\n"
2674 "Delay value (seconds)\n")
2675 {
2676 VTY_DECLVAR_CONTEXT(bgp, bgp);
2677 int idx_number = 3;
2678 uint32_t stale_time;
2679
2680 stale_time = strtoul(argv[idx_number]->arg, NULL, 10);
2681 bgp->rib_stale_time = stale_time;
2682 /* Send the stale timer update message to RIB */
2683 if (bgp_zebra_stale_timer_update(bgp))
2684 return CMD_WARNING;
2685
2686 return CMD_SUCCESS;
2687 }
2688
2689 DEFUN (no_bgp_graceful_restart_rib_stale_time,
2690 no_bgp_graceful_restart_rib_stale_time_cmd,
2691 "no bgp graceful-restart rib-stale-time [(1-3600)]",
2692 NO_STR
2693 "BGP specific commands\n"
2694 "Graceful restart configuration parameters\n"
2695 "Specify the stale route removal timer in rib\n"
2696 "Delay value (seconds)\n")
2697 {
2698 VTY_DECLVAR_CONTEXT(bgp, bgp);
2699
2700 bgp->rib_stale_time = BGP_DEFAULT_RIB_STALE_TIME;
2701 /* Send the stale timer update message to RIB */
2702 if (bgp_zebra_stale_timer_update(bgp))
2703 return CMD_WARNING;
2704
2705 return CMD_SUCCESS;
2706 }
2707
2708 /* "bgp graceful-shutdown" configuration */
2709 DEFUN (bgp_graceful_shutdown,
2710 bgp_graceful_shutdown_cmd,
2711 "bgp graceful-shutdown",
2712 BGP_STR
2713 "Graceful shutdown parameters\n")
2714 {
2715 VTY_DECLVAR_CONTEXT(bgp, bgp);
2716
2717 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2718 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
2719 bgp_static_redo_import_check(bgp);
2720 bgp_redistribute_redo(bgp);
2721 bgp_clear_star_soft_out(vty, bgp->name);
2722 bgp_clear_star_soft_in(vty, bgp->name);
2723 }
2724
2725 return CMD_SUCCESS;
2726 }
2727
2728 DEFUN (no_bgp_graceful_shutdown,
2729 no_bgp_graceful_shutdown_cmd,
2730 "no bgp graceful-shutdown",
2731 NO_STR
2732 BGP_STR
2733 "Graceful shutdown parameters\n")
2734 {
2735 VTY_DECLVAR_CONTEXT(bgp, bgp);
2736
2737 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2738 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
2739 bgp_static_redo_import_check(bgp);
2740 bgp_redistribute_redo(bgp);
2741 bgp_clear_star_soft_out(vty, bgp->name);
2742 bgp_clear_star_soft_in(vty, bgp->name);
2743 }
2744
2745 return CMD_SUCCESS;
2746 }
2747
2748 /* "bgp fast-external-failover" configuration. */
2749 DEFUN (bgp_fast_external_failover,
2750 bgp_fast_external_failover_cmd,
2751 "bgp fast-external-failover",
2752 BGP_STR
2753 "Immediately reset session if a link to a directly connected external peer goes down\n")
2754 {
2755 VTY_DECLVAR_CONTEXT(bgp, bgp);
2756 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2757 return CMD_SUCCESS;
2758 }
2759
2760 DEFUN (no_bgp_fast_external_failover,
2761 no_bgp_fast_external_failover_cmd,
2762 "no bgp fast-external-failover",
2763 NO_STR
2764 BGP_STR
2765 "Immediately reset session if a link to a directly connected external peer goes down\n")
2766 {
2767 VTY_DECLVAR_CONTEXT(bgp, bgp);
2768 SET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2769 return CMD_SUCCESS;
2770 }
2771
2772 /* "bgp bestpath compare-routerid" configuration. */
2773 DEFUN (bgp_bestpath_compare_router_id,
2774 bgp_bestpath_compare_router_id_cmd,
2775 "bgp bestpath compare-routerid",
2776 "BGP specific commands\n"
2777 "Change the default bestpath selection\n"
2778 "Compare router-id for identical EBGP paths\n")
2779 {
2780 VTY_DECLVAR_CONTEXT(bgp, bgp);
2781 SET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
2782 bgp_recalculate_all_bestpaths(bgp);
2783
2784 return CMD_SUCCESS;
2785 }
2786
2787 DEFUN (no_bgp_bestpath_compare_router_id,
2788 no_bgp_bestpath_compare_router_id_cmd,
2789 "no bgp bestpath compare-routerid",
2790 NO_STR
2791 "BGP specific commands\n"
2792 "Change the default bestpath selection\n"
2793 "Compare router-id for identical EBGP paths\n")
2794 {
2795 VTY_DECLVAR_CONTEXT(bgp, bgp);
2796 UNSET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
2797 bgp_recalculate_all_bestpaths(bgp);
2798
2799 return CMD_SUCCESS;
2800 }
2801
2802 /* "bgp bestpath as-path ignore" configuration. */
2803 DEFUN (bgp_bestpath_aspath_ignore,
2804 bgp_bestpath_aspath_ignore_cmd,
2805 "bgp bestpath as-path ignore",
2806 "BGP specific commands\n"
2807 "Change the default bestpath selection\n"
2808 "AS-path attribute\n"
2809 "Ignore as-path length in selecting a route\n")
2810 {
2811 VTY_DECLVAR_CONTEXT(bgp, bgp);
2812 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
2813 bgp_recalculate_all_bestpaths(bgp);
2814
2815 return CMD_SUCCESS;
2816 }
2817
2818 DEFUN (no_bgp_bestpath_aspath_ignore,
2819 no_bgp_bestpath_aspath_ignore_cmd,
2820 "no bgp bestpath as-path ignore",
2821 NO_STR
2822 "BGP specific commands\n"
2823 "Change the default bestpath selection\n"
2824 "AS-path attribute\n"
2825 "Ignore as-path length in selecting a route\n")
2826 {
2827 VTY_DECLVAR_CONTEXT(bgp, bgp);
2828 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
2829 bgp_recalculate_all_bestpaths(bgp);
2830
2831 return CMD_SUCCESS;
2832 }
2833
2834 /* "bgp bestpath as-path confed" configuration. */
2835 DEFUN (bgp_bestpath_aspath_confed,
2836 bgp_bestpath_aspath_confed_cmd,
2837 "bgp bestpath as-path confed",
2838 "BGP specific commands\n"
2839 "Change the default bestpath selection\n"
2840 "AS-path attribute\n"
2841 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2842 {
2843 VTY_DECLVAR_CONTEXT(bgp, bgp);
2844 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
2845 bgp_recalculate_all_bestpaths(bgp);
2846
2847 return CMD_SUCCESS;
2848 }
2849
2850 DEFUN (no_bgp_bestpath_aspath_confed,
2851 no_bgp_bestpath_aspath_confed_cmd,
2852 "no bgp bestpath as-path confed",
2853 NO_STR
2854 "BGP specific commands\n"
2855 "Change the default bestpath selection\n"
2856 "AS-path attribute\n"
2857 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2858 {
2859 VTY_DECLVAR_CONTEXT(bgp, bgp);
2860 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
2861 bgp_recalculate_all_bestpaths(bgp);
2862
2863 return CMD_SUCCESS;
2864 }
2865
2866 /* "bgp bestpath as-path multipath-relax" configuration. */
2867 DEFUN (bgp_bestpath_aspath_multipath_relax,
2868 bgp_bestpath_aspath_multipath_relax_cmd,
2869 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
2870 "BGP specific commands\n"
2871 "Change the default bestpath selection\n"
2872 "AS-path attribute\n"
2873 "Allow load sharing across routes that have different AS paths (but same length)\n"
2874 "Generate an AS_SET\n"
2875 "Do not generate an AS_SET\n")
2876 {
2877 VTY_DECLVAR_CONTEXT(bgp, bgp);
2878 int idx = 0;
2879 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2880
2881 /* no-as-set is now the default behavior so we can silently
2882 * ignore it */
2883 if (argv_find(argv, argc, "as-set", &idx))
2884 SET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2885 else
2886 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2887
2888 bgp_recalculate_all_bestpaths(bgp);
2889
2890 return CMD_SUCCESS;
2891 }
2892
2893 DEFUN (no_bgp_bestpath_aspath_multipath_relax,
2894 no_bgp_bestpath_aspath_multipath_relax_cmd,
2895 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
2896 NO_STR
2897 "BGP specific commands\n"
2898 "Change the default bestpath selection\n"
2899 "AS-path attribute\n"
2900 "Allow load sharing across routes that have different AS paths (but same length)\n"
2901 "Generate an AS_SET\n"
2902 "Do not generate an AS_SET\n")
2903 {
2904 VTY_DECLVAR_CONTEXT(bgp, bgp);
2905 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2906 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2907 bgp_recalculate_all_bestpaths(bgp);
2908
2909 return CMD_SUCCESS;
2910 }
2911
2912 /* "bgp log-neighbor-changes" configuration. */
2913 DEFUN (bgp_log_neighbor_changes,
2914 bgp_log_neighbor_changes_cmd,
2915 "bgp log-neighbor-changes",
2916 "BGP specific commands\n"
2917 "Log neighbor up/down and reset reason\n")
2918 {
2919 VTY_DECLVAR_CONTEXT(bgp, bgp);
2920 SET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2921 return CMD_SUCCESS;
2922 }
2923
2924 DEFUN (no_bgp_log_neighbor_changes,
2925 no_bgp_log_neighbor_changes_cmd,
2926 "no bgp log-neighbor-changes",
2927 NO_STR
2928 "BGP specific commands\n"
2929 "Log neighbor up/down and reset reason\n")
2930 {
2931 VTY_DECLVAR_CONTEXT(bgp, bgp);
2932 UNSET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2933 return CMD_SUCCESS;
2934 }
2935
2936 /* "bgp bestpath med" configuration. */
2937 DEFUN (bgp_bestpath_med,
2938 bgp_bestpath_med_cmd,
2939 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
2940 "BGP specific commands\n"
2941 "Change the default bestpath selection\n"
2942 "MED attribute\n"
2943 "Compare MED among confederation paths\n"
2944 "Treat missing MED as the least preferred one\n"
2945 "Treat missing MED as the least preferred one\n"
2946 "Compare MED among confederation paths\n")
2947 {
2948 VTY_DECLVAR_CONTEXT(bgp, bgp);
2949
2950 int idx = 0;
2951 if (argv_find(argv, argc, "confed", &idx))
2952 SET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
2953 idx = 0;
2954 if (argv_find(argv, argc, "missing-as-worst", &idx))
2955 SET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
2956
2957 bgp_recalculate_all_bestpaths(bgp);
2958
2959 return CMD_SUCCESS;
2960 }
2961
2962 DEFUN (no_bgp_bestpath_med,
2963 no_bgp_bestpath_med_cmd,
2964 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
2965 NO_STR
2966 "BGP specific commands\n"
2967 "Change the default bestpath selection\n"
2968 "MED attribute\n"
2969 "Compare MED among confederation paths\n"
2970 "Treat missing MED as the least preferred one\n"
2971 "Treat missing MED as the least preferred one\n"
2972 "Compare MED among confederation paths\n")
2973 {
2974 VTY_DECLVAR_CONTEXT(bgp, bgp);
2975
2976 int idx = 0;
2977 if (argv_find(argv, argc, "confed", &idx))
2978 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
2979 idx = 0;
2980 if (argv_find(argv, argc, "missing-as-worst", &idx))
2981 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
2982
2983 bgp_recalculate_all_bestpaths(bgp);
2984
2985 return CMD_SUCCESS;
2986 }
2987
2988 /* "no bgp default ipv4-unicast". */
2989 DEFUN (no_bgp_default_ipv4_unicast,
2990 no_bgp_default_ipv4_unicast_cmd,
2991 "no bgp default ipv4-unicast",
2992 NO_STR
2993 "BGP specific commands\n"
2994 "Configure BGP defaults\n"
2995 "Activate ipv4-unicast for a peer by default\n")
2996 {
2997 VTY_DECLVAR_CONTEXT(bgp, bgp);
2998 SET_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4);
2999 return CMD_SUCCESS;
3000 }
3001
3002 DEFUN (bgp_default_ipv4_unicast,
3003 bgp_default_ipv4_unicast_cmd,
3004 "bgp default ipv4-unicast",
3005 "BGP specific commands\n"
3006 "Configure BGP defaults\n"
3007 "Activate ipv4-unicast for a peer by default\n")
3008 {
3009 VTY_DECLVAR_CONTEXT(bgp, bgp);
3010 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4);
3011 return CMD_SUCCESS;
3012 }
3013
3014 /* Display hostname in certain command outputs */
3015 DEFUN (bgp_default_show_hostname,
3016 bgp_default_show_hostname_cmd,
3017 "bgp default show-hostname",
3018 "BGP specific commands\n"
3019 "Configure BGP defaults\n"
3020 "Show hostname in certain command outputs\n")
3021 {
3022 VTY_DECLVAR_CONTEXT(bgp, bgp);
3023 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
3024 return CMD_SUCCESS;
3025 }
3026
3027 DEFUN (no_bgp_default_show_hostname,
3028 no_bgp_default_show_hostname_cmd,
3029 "no bgp default show-hostname",
3030 NO_STR
3031 "BGP specific commands\n"
3032 "Configure BGP defaults\n"
3033 "Show hostname in certain command outputs\n")
3034 {
3035 VTY_DECLVAR_CONTEXT(bgp, bgp);
3036 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
3037 return CMD_SUCCESS;
3038 }
3039
3040 /* "bgp network import-check" configuration. */
3041 DEFUN (bgp_network_import_check,
3042 bgp_network_import_check_cmd,
3043 "bgp network import-check",
3044 "BGP specific commands\n"
3045 "BGP network command\n"
3046 "Check BGP network route exists in IGP\n")
3047 {
3048 VTY_DECLVAR_CONTEXT(bgp, bgp);
3049 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
3050 SET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
3051 bgp_static_redo_import_check(bgp);
3052 }
3053
3054 return CMD_SUCCESS;
3055 }
3056
3057 ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
3058 "bgp network import-check exact",
3059 "BGP specific commands\n"
3060 "BGP network command\n"
3061 "Check BGP network route exists in IGP\n"
3062 "Match route precisely\n")
3063
3064 DEFUN (no_bgp_network_import_check,
3065 no_bgp_network_import_check_cmd,
3066 "no bgp network import-check",
3067 NO_STR
3068 "BGP specific commands\n"
3069 "BGP network command\n"
3070 "Check BGP network route exists in IGP\n")
3071 {
3072 VTY_DECLVAR_CONTEXT(bgp, bgp);
3073 if (CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
3074 UNSET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
3075 bgp_static_redo_import_check(bgp);
3076 }
3077
3078 return CMD_SUCCESS;
3079 }
3080
3081 DEFUN (bgp_default_local_preference,
3082 bgp_default_local_preference_cmd,
3083 "bgp default local-preference (0-4294967295)",
3084 "BGP specific commands\n"
3085 "Configure BGP defaults\n"
3086 "local preference (higher=more preferred)\n"
3087 "Configure default local preference value\n")
3088 {
3089 VTY_DECLVAR_CONTEXT(bgp, bgp);
3090 int idx_number = 3;
3091 uint32_t local_pref;
3092
3093 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
3094
3095 bgp_default_local_preference_set(bgp, local_pref);
3096 bgp_clear_star_soft_in(vty, bgp->name);
3097
3098 return CMD_SUCCESS;
3099 }
3100
3101 DEFUN (no_bgp_default_local_preference,
3102 no_bgp_default_local_preference_cmd,
3103 "no bgp default local-preference [(0-4294967295)]",
3104 NO_STR
3105 "BGP specific commands\n"
3106 "Configure BGP defaults\n"
3107 "local preference (higher=more preferred)\n"
3108 "Configure default local preference value\n")
3109 {
3110 VTY_DECLVAR_CONTEXT(bgp, bgp);
3111 bgp_default_local_preference_unset(bgp);
3112 bgp_clear_star_soft_in(vty, bgp->name);
3113
3114 return CMD_SUCCESS;
3115 }
3116
3117
3118 DEFUN (bgp_default_subgroup_pkt_queue_max,
3119 bgp_default_subgroup_pkt_queue_max_cmd,
3120 "bgp default subgroup-pkt-queue-max (20-100)",
3121 "BGP specific commands\n"
3122 "Configure BGP defaults\n"
3123 "subgroup-pkt-queue-max\n"
3124 "Configure subgroup packet queue max\n")
3125 {
3126 VTY_DECLVAR_CONTEXT(bgp, bgp);
3127 int idx_number = 3;
3128 uint32_t max_size;
3129
3130 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
3131
3132 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
3133
3134 return CMD_SUCCESS;
3135 }
3136
3137 DEFUN (no_bgp_default_subgroup_pkt_queue_max,
3138 no_bgp_default_subgroup_pkt_queue_max_cmd,
3139 "no bgp default subgroup-pkt-queue-max [(20-100)]",
3140 NO_STR
3141 "BGP specific commands\n"
3142 "Configure BGP defaults\n"
3143 "subgroup-pkt-queue-max\n"
3144 "Configure subgroup packet queue max\n")
3145 {
3146 VTY_DECLVAR_CONTEXT(bgp, bgp);
3147 bgp_default_subgroup_pkt_queue_max_unset(bgp);
3148 return CMD_SUCCESS;
3149 }
3150
3151
3152 DEFUN (bgp_rr_allow_outbound_policy,
3153 bgp_rr_allow_outbound_policy_cmd,
3154 "bgp route-reflector allow-outbound-policy",
3155 "BGP specific commands\n"
3156 "Allow modifications made by out route-map\n"
3157 "on ibgp neighbors\n")
3158 {
3159 VTY_DECLVAR_CONTEXT(bgp, bgp);
3160
3161 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
3162 SET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
3163 update_group_announce_rrclients(bgp);
3164 bgp_clear_star_soft_out(vty, bgp->name);
3165 }
3166
3167 return CMD_SUCCESS;
3168 }
3169
3170 DEFUN (no_bgp_rr_allow_outbound_policy,
3171 no_bgp_rr_allow_outbound_policy_cmd,
3172 "no bgp route-reflector allow-outbound-policy",
3173 NO_STR
3174 "BGP specific commands\n"
3175 "Allow modifications made by out route-map\n"
3176 "on ibgp neighbors\n")
3177 {
3178 VTY_DECLVAR_CONTEXT(bgp, bgp);
3179
3180 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
3181 UNSET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
3182 update_group_announce_rrclients(bgp);
3183 bgp_clear_star_soft_out(vty, bgp->name);
3184 }
3185
3186 return CMD_SUCCESS;
3187 }
3188
3189 DEFUN (bgp_listen_limit,
3190 bgp_listen_limit_cmd,
3191 "bgp listen limit (1-5000)",
3192 "BGP specific commands\n"
3193 "BGP Dynamic Neighbors listen commands\n"
3194 "Maximum number of BGP Dynamic Neighbors that can be created\n"
3195 "Configure Dynamic Neighbors listen limit value\n")
3196 {
3197 VTY_DECLVAR_CONTEXT(bgp, bgp);
3198 int idx_number = 3;
3199 int listen_limit;
3200
3201 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
3202
3203 bgp_listen_limit_set(bgp, listen_limit);
3204
3205 return CMD_SUCCESS;
3206 }
3207
3208 DEFUN (no_bgp_listen_limit,
3209 no_bgp_listen_limit_cmd,
3210 "no bgp listen limit [(1-5000)]",
3211 NO_STR
3212 "BGP specific commands\n"
3213 "BGP Dynamic Neighbors listen commands\n"
3214 "Maximum number of BGP Dynamic Neighbors that can be created\n"
3215 "Configure Dynamic Neighbors listen limit value\n")
3216 {
3217 VTY_DECLVAR_CONTEXT(bgp, bgp);
3218 bgp_listen_limit_unset(bgp);
3219 return CMD_SUCCESS;
3220 }
3221
3222
3223 /*
3224 * Check if this listen range is already configured. Check for exact
3225 * match or overlap based on input.
3226 */
3227 static struct peer_group *listen_range_exists(struct bgp *bgp,
3228 struct prefix *range, int exact)
3229 {
3230 struct listnode *node, *nnode;
3231 struct listnode *node1, *nnode1;
3232 struct peer_group *group;
3233 struct prefix *lr;
3234 afi_t afi;
3235 int match;
3236
3237 afi = family2afi(range->family);
3238 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
3239 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
3240 lr)) {
3241 if (exact)
3242 match = prefix_same(range, lr);
3243 else
3244 match = (prefix_match(range, lr)
3245 || prefix_match(lr, range));
3246 if (match)
3247 return group;
3248 }
3249 }
3250
3251 return NULL;
3252 }
3253
3254 DEFUN (bgp_listen_range,
3255 bgp_listen_range_cmd,
3256 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
3257 "BGP specific commands\n"
3258 "Configure BGP dynamic neighbors listen range\n"
3259 "Configure BGP dynamic neighbors listen range\n"
3260 NEIGHBOR_ADDR_STR
3261 "Member of the peer-group\n"
3262 "Peer-group name\n")
3263 {
3264 VTY_DECLVAR_CONTEXT(bgp, bgp);
3265 struct prefix range;
3266 struct peer_group *group, *existing_group;
3267 afi_t afi;
3268 int ret;
3269 int idx = 0;
3270
3271 argv_find(argv, argc, "A.B.C.D/M", &idx);
3272 argv_find(argv, argc, "X:X::X:X/M", &idx);
3273 char *prefix = argv[idx]->arg;
3274 argv_find(argv, argc, "PGNAME", &idx);
3275 char *peergroup = argv[idx]->arg;
3276
3277 /* Convert IP prefix string to struct prefix. */
3278 ret = str2prefix(prefix, &range);
3279 if (!ret) {
3280 vty_out(vty, "%% Malformed listen range\n");
3281 return CMD_WARNING_CONFIG_FAILED;
3282 }
3283
3284 afi = family2afi(range.family);
3285
3286 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
3287 vty_out(vty,
3288 "%% Malformed listen range (link-local address)\n");
3289 return CMD_WARNING_CONFIG_FAILED;
3290 }
3291
3292 apply_mask(&range);
3293
3294 /* Check if same listen range is already configured. */
3295 existing_group = listen_range_exists(bgp, &range, 1);
3296 if (existing_group) {
3297 if (strcmp(existing_group->name, peergroup) == 0)
3298 return CMD_SUCCESS;
3299 else {
3300 vty_out(vty,
3301 "%% Same listen range is attached to peer-group %s\n",
3302 existing_group->name);
3303 return CMD_WARNING_CONFIG_FAILED;
3304 }
3305 }
3306
3307 /* Check if an overlapping listen range exists. */
3308 if (listen_range_exists(bgp, &range, 0)) {
3309 vty_out(vty,
3310 "%% Listen range overlaps with existing listen range\n");
3311 return CMD_WARNING_CONFIG_FAILED;
3312 }
3313
3314 group = peer_group_lookup(bgp, peergroup);
3315 if (!group) {
3316 vty_out(vty, "%% Configure the peer-group first\n");
3317 return CMD_WARNING_CONFIG_FAILED;
3318 }
3319
3320 ret = peer_group_listen_range_add(group, &range);
3321 return bgp_vty_return(vty, ret);
3322 }
3323
3324 DEFUN (no_bgp_listen_range,
3325 no_bgp_listen_range_cmd,
3326 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
3327 NO_STR
3328 "BGP specific commands\n"
3329 "Unconfigure BGP dynamic neighbors listen range\n"
3330 "Unconfigure BGP dynamic neighbors listen range\n"
3331 NEIGHBOR_ADDR_STR
3332 "Member of the peer-group\n"
3333 "Peer-group name\n")
3334 {
3335 VTY_DECLVAR_CONTEXT(bgp, bgp);
3336 struct prefix range;
3337 struct peer_group *group;
3338 afi_t afi;
3339 int ret;
3340 int idx = 0;
3341
3342 argv_find(argv, argc, "A.B.C.D/M", &idx);
3343 argv_find(argv, argc, "X:X::X:X/M", &idx);
3344 char *prefix = argv[idx]->arg;
3345 argv_find(argv, argc, "PGNAME", &idx);
3346 char *peergroup = argv[idx]->arg;
3347
3348 /* Convert IP prefix string to struct prefix. */
3349 ret = str2prefix(prefix, &range);
3350 if (!ret) {
3351 vty_out(vty, "%% Malformed listen range\n");
3352 return CMD_WARNING_CONFIG_FAILED;
3353 }
3354
3355 afi = family2afi(range.family);
3356
3357 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
3358 vty_out(vty,
3359 "%% Malformed listen range (link-local address)\n");
3360 return CMD_WARNING_CONFIG_FAILED;
3361 }
3362
3363 apply_mask(&range);
3364
3365 group = peer_group_lookup(bgp, peergroup);
3366 if (!group) {
3367 vty_out(vty, "%% Peer-group does not exist\n");
3368 return CMD_WARNING_CONFIG_FAILED;
3369 }
3370
3371 ret = peer_group_listen_range_del(group, &range);
3372 return bgp_vty_return(vty, ret);
3373 }
3374
3375 void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
3376 {
3377 struct peer_group *group;
3378 struct listnode *node, *nnode, *rnode, *nrnode;
3379 struct prefix *range;
3380 afi_t afi;
3381 char buf[PREFIX2STR_BUFFER];
3382
3383 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
3384 vty_out(vty, " bgp listen limit %d\n",
3385 bgp->dynamic_neighbors_limit);
3386
3387 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
3388 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
3389 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
3390 nrnode, range)) {
3391 prefix2str(range, buf, sizeof(buf));
3392 vty_out(vty,
3393 " bgp listen range %s peer-group %s\n",
3394 buf, group->name);
3395 }
3396 }
3397 }
3398 }
3399
3400
3401 DEFUN (bgp_disable_connected_route_check,
3402 bgp_disable_connected_route_check_cmd,
3403 "bgp disable-ebgp-connected-route-check",
3404 "BGP specific commands\n"
3405 "Disable checking if nexthop is connected on ebgp sessions\n")
3406 {
3407 VTY_DECLVAR_CONTEXT(bgp, bgp);
3408 SET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
3409 bgp_clear_star_soft_in(vty, bgp->name);
3410
3411 return CMD_SUCCESS;
3412 }
3413
3414 DEFUN (no_bgp_disable_connected_route_check,
3415 no_bgp_disable_connected_route_check_cmd,
3416 "no bgp disable-ebgp-connected-route-check",
3417 NO_STR
3418 "BGP specific commands\n"
3419 "Disable checking if nexthop is connected on ebgp sessions\n")
3420 {
3421 VTY_DECLVAR_CONTEXT(bgp, bgp);
3422 UNSET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
3423 bgp_clear_star_soft_in(vty, bgp->name);
3424
3425 return CMD_SUCCESS;
3426 }
3427
3428
3429 static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
3430 const char *as_str, afi_t afi, safi_t safi)
3431 {
3432 VTY_DECLVAR_CONTEXT(bgp, bgp);
3433 int ret;
3434 as_t as;
3435 int as_type = AS_SPECIFIED;
3436 union sockunion su;
3437
3438 if (as_str[0] == 'i') {
3439 as = 0;
3440 as_type = AS_INTERNAL;
3441 } else if (as_str[0] == 'e') {
3442 as = 0;
3443 as_type = AS_EXTERNAL;
3444 } else {
3445 /* Get AS number. */
3446 as = strtoul(as_str, NULL, 10);
3447 }
3448
3449 /* If peer is peer group or interface peer, call proper function. */
3450 ret = str2sockunion(peer_str, &su);
3451 if (ret < 0) {
3452 struct peer *peer;
3453
3454 /* Check if existing interface peer */
3455 peer = peer_lookup_by_conf_if(bgp, peer_str);
3456
3457 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, afi,
3458 safi);
3459
3460 /* if not interface peer, check peer-group settings */
3461 if (ret < 0 && !peer) {
3462 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
3463 if (ret < 0) {
3464 vty_out(vty,
3465 "%% Create the peer-group or interface first\n");
3466 return CMD_WARNING_CONFIG_FAILED;
3467 }
3468 return CMD_SUCCESS;
3469 }
3470 } else {
3471 if (peer_address_self_check(bgp, &su)) {
3472 vty_out(vty,
3473 "%% Can not configure the local system as neighbor\n");
3474 return CMD_WARNING_CONFIG_FAILED;
3475 }
3476 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, afi, safi);
3477 }
3478
3479 /* This peer belongs to peer group. */
3480 switch (ret) {
3481 case BGP_ERR_PEER_GROUP_MEMBER:
3482 vty_out(vty,
3483 "%% Peer-group member cannot override remote-as of peer-group\n");
3484 return CMD_WARNING_CONFIG_FAILED;
3485 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
3486 vty_out(vty,
3487 "%% Peer-group members must be all internal or all external\n");
3488 return CMD_WARNING_CONFIG_FAILED;
3489 }
3490 return bgp_vty_return(vty, ret);
3491 }
3492
3493 DEFUN (bgp_default_shutdown,
3494 bgp_default_shutdown_cmd,
3495 "[no] bgp default shutdown",
3496 NO_STR
3497 BGP_STR
3498 "Configure BGP defaults\n"
3499 "Apply administrative shutdown to newly configured peers\n")
3500 {
3501 VTY_DECLVAR_CONTEXT(bgp, bgp);
3502 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
3503 return CMD_SUCCESS;
3504 }
3505
3506 DEFUN (neighbor_remote_as,
3507 neighbor_remote_as_cmd,
3508 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
3509 NEIGHBOR_STR
3510 NEIGHBOR_ADDR_STR2
3511 "Specify a BGP neighbor\n"
3512 AS_STR
3513 "Internal BGP peer\n"
3514 "External BGP peer\n")
3515 {
3516 int idx_peer = 1;
3517 int idx_remote_as = 3;
3518 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
3519 argv[idx_remote_as]->arg, AFI_IP,
3520 SAFI_UNICAST);
3521 }
3522
3523 static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
3524 afi_t afi, safi_t safi, int v6only,
3525 const char *peer_group_name,
3526 const char *as_str)
3527 {
3528 VTY_DECLVAR_CONTEXT(bgp, bgp);
3529 as_t as = 0;
3530 int as_type = AS_UNSPECIFIED;
3531 struct peer *peer;
3532 struct peer_group *group;
3533 int ret = 0;
3534 union sockunion su;
3535
3536 group = peer_group_lookup(bgp, conf_if);
3537
3538 if (group) {
3539 vty_out(vty, "%% Name conflict with peer-group \n");
3540 return CMD_WARNING_CONFIG_FAILED;
3541 }
3542
3543 if (as_str) {
3544 if (as_str[0] == 'i') {
3545 as_type = AS_INTERNAL;
3546 } else if (as_str[0] == 'e') {
3547 as_type = AS_EXTERNAL;
3548 } else {
3549 /* Get AS number. */
3550 as = strtoul(as_str, NULL, 10);
3551 as_type = AS_SPECIFIED;
3552 }
3553 }
3554
3555 peer = peer_lookup_by_conf_if(bgp, conf_if);
3556 if (peer) {
3557 if (as_str)
3558 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type,
3559 afi, safi);
3560 } else {
3561 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4)
3562 && afi == AFI_IP && safi == SAFI_UNICAST)
3563 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
3564 as_type, 0, 0, NULL);
3565 else
3566 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
3567 as_type, afi, safi, NULL);
3568
3569 if (!peer) {
3570 vty_out(vty, "%% BGP failed to create peer\n");
3571 return CMD_WARNING_CONFIG_FAILED;
3572 }
3573
3574 if (v6only)
3575 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
3576
3577 /* Request zebra to initiate IPv6 RAs on this interface. We do
3578 * this
3579 * any unnumbered peer in order to not worry about run-time
3580 * transitions
3581 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
3582 * address
3583 * gets deleted later etc.)
3584 */
3585 if (peer->ifp)
3586 bgp_zebra_initiate_radv(bgp, peer);
3587 }
3588
3589 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
3590 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
3591 if (v6only)
3592 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
3593 else
3594 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
3595
3596 /* v6only flag changed. Reset bgp seesion */
3597 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
3598 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
3599 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
3600 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
3601 } else
3602 bgp_session_reset(peer);
3603 }
3604
3605 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
3606 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
3607 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
3608 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
3609 }
3610
3611 if (peer_group_name) {
3612 group = peer_group_lookup(bgp, peer_group_name);
3613 if (!group) {
3614 vty_out(vty, "%% Configure the peer-group first\n");
3615 return CMD_WARNING_CONFIG_FAILED;
3616 }
3617
3618 ret = peer_group_bind(bgp, &su, peer, group, &as);
3619 }
3620
3621 return bgp_vty_return(vty, ret);
3622 }
3623
3624 DEFUN (neighbor_interface_config,
3625 neighbor_interface_config_cmd,
3626 "neighbor WORD interface [peer-group PGNAME]",
3627 NEIGHBOR_STR
3628 "Interface name or neighbor tag\n"
3629 "Enable BGP on interface\n"
3630 "Member of the peer-group\n"
3631 "Peer-group name\n")
3632 {
3633 int idx_word = 1;
3634 int idx_peer_group_word = 4;
3635
3636 if (argc > idx_peer_group_word)
3637 return peer_conf_interface_get(
3638 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
3639 argv[idx_peer_group_word]->arg, NULL);
3640 else
3641 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3642 SAFI_UNICAST, 0, NULL, NULL);
3643 }
3644
3645 DEFUN (neighbor_interface_config_v6only,
3646 neighbor_interface_config_v6only_cmd,
3647 "neighbor WORD interface v6only [peer-group PGNAME]",
3648 NEIGHBOR_STR
3649 "Interface name or neighbor tag\n"
3650 "Enable BGP on interface\n"
3651 "Enable BGP with v6 link-local only\n"
3652 "Member of the peer-group\n"
3653 "Peer-group name\n")
3654 {
3655 int idx_word = 1;
3656 int idx_peer_group_word = 5;
3657
3658 if (argc > idx_peer_group_word)
3659 return peer_conf_interface_get(
3660 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
3661 argv[idx_peer_group_word]->arg, NULL);
3662
3663 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3664 SAFI_UNICAST, 1, NULL, NULL);
3665 }
3666
3667
3668 DEFUN (neighbor_interface_config_remote_as,
3669 neighbor_interface_config_remote_as_cmd,
3670 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
3671 NEIGHBOR_STR
3672 "Interface name or neighbor tag\n"
3673 "Enable BGP on interface\n"
3674 "Specify a BGP neighbor\n"
3675 AS_STR
3676 "Internal BGP peer\n"
3677 "External BGP peer\n")
3678 {
3679 int idx_word = 1;
3680 int idx_remote_as = 4;
3681 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3682 SAFI_UNICAST, 0, NULL,
3683 argv[idx_remote_as]->arg);
3684 }
3685
3686 DEFUN (neighbor_interface_v6only_config_remote_as,
3687 neighbor_interface_v6only_config_remote_as_cmd,
3688 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
3689 NEIGHBOR_STR
3690 "Interface name or neighbor tag\n"
3691 "Enable BGP with v6 link-local only\n"
3692 "Enable BGP on interface\n"
3693 "Specify a BGP neighbor\n"
3694 AS_STR
3695 "Internal BGP peer\n"
3696 "External BGP peer\n")
3697 {
3698 int idx_word = 1;
3699 int idx_remote_as = 5;
3700 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3701 SAFI_UNICAST, 1, NULL,
3702 argv[idx_remote_as]->arg);
3703 }
3704
3705 DEFUN (neighbor_peer_group,
3706 neighbor_peer_group_cmd,
3707 "neighbor WORD peer-group",
3708 NEIGHBOR_STR
3709 "Interface name or neighbor tag\n"
3710 "Configure peer-group\n")
3711 {
3712 VTY_DECLVAR_CONTEXT(bgp, bgp);
3713 int idx_word = 1;
3714 struct peer *peer;
3715 struct peer_group *group;
3716
3717 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3718 if (peer) {
3719 vty_out(vty, "%% Name conflict with interface: \n");
3720 return CMD_WARNING_CONFIG_FAILED;
3721 }
3722
3723 group = peer_group_get(bgp, argv[idx_word]->arg);
3724 if (!group) {
3725 vty_out(vty, "%% BGP failed to find or create peer-group\n");
3726 return CMD_WARNING_CONFIG_FAILED;
3727 }
3728
3729 return CMD_SUCCESS;
3730 }
3731
3732 DEFUN (no_neighbor,
3733 no_neighbor_cmd,
3734 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
3735 NO_STR
3736 NEIGHBOR_STR
3737 NEIGHBOR_ADDR_STR2
3738 "Specify a BGP neighbor\n"
3739 AS_STR
3740 "Internal BGP peer\n"
3741 "External BGP peer\n")
3742 {
3743 VTY_DECLVAR_CONTEXT(bgp, bgp);
3744 int idx_peer = 2;
3745 int ret;
3746 union sockunion su;
3747 struct peer_group *group;
3748 struct peer *peer;
3749 struct peer *other;
3750
3751 ret = str2sockunion(argv[idx_peer]->arg, &su);
3752 if (ret < 0) {
3753 /* look up for neighbor by interface name config. */
3754 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3755 if (peer) {
3756 /* Request zebra to terminate IPv6 RAs on this
3757 * interface. */
3758 if (peer->ifp)
3759 bgp_zebra_terminate_radv(peer->bgp, peer);
3760 peer_notify_unconfig(peer);
3761 peer_delete(peer);
3762 return CMD_SUCCESS;
3763 }
3764
3765 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
3766 if (group) {
3767 peer_group_notify_unconfig(group);
3768 peer_group_delete(group);
3769 } else {
3770 vty_out(vty, "%% Create the peer-group first\n");
3771 return CMD_WARNING_CONFIG_FAILED;
3772 }
3773 } else {
3774 peer = peer_lookup(bgp, &su);
3775 if (peer) {
3776 if (peer_dynamic_neighbor(peer)) {
3777 vty_out(vty,
3778 "%% Operation not allowed on a dynamic neighbor\n");
3779 return CMD_WARNING_CONFIG_FAILED;
3780 }
3781
3782 other = peer->doppelganger;
3783 peer_notify_unconfig(peer);
3784 peer_delete(peer);
3785 if (other && other->status != Deleted) {
3786 peer_notify_unconfig(other);
3787 peer_delete(other);
3788 }
3789 }
3790 }
3791
3792 return CMD_SUCCESS;
3793 }
3794
3795 DEFUN (no_neighbor_interface_config,
3796 no_neighbor_interface_config_cmd,
3797 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
3798 NO_STR
3799 NEIGHBOR_STR
3800 "Interface name\n"
3801 "Configure BGP on interface\n"
3802 "Enable BGP with v6 link-local only\n"
3803 "Member of the peer-group\n"
3804 "Peer-group name\n"
3805 "Specify a BGP neighbor\n"
3806 AS_STR
3807 "Internal BGP peer\n"
3808 "External BGP peer\n")
3809 {
3810 VTY_DECLVAR_CONTEXT(bgp, bgp);
3811 int idx_word = 2;
3812 struct peer *peer;
3813
3814 /* look up for neighbor by interface name config. */
3815 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3816 if (peer) {
3817 /* Request zebra to terminate IPv6 RAs on this interface. */
3818 if (peer->ifp)
3819 bgp_zebra_terminate_radv(peer->bgp, peer);
3820 peer_notify_unconfig(peer);
3821 peer_delete(peer);
3822 } else {
3823 vty_out(vty, "%% Create the bgp interface first\n");
3824 return CMD_WARNING_CONFIG_FAILED;
3825 }
3826 return CMD_SUCCESS;
3827 }
3828
3829 DEFUN (no_neighbor_peer_group,
3830 no_neighbor_peer_group_cmd,
3831 "no neighbor WORD peer-group",
3832 NO_STR
3833 NEIGHBOR_STR
3834 "Neighbor tag\n"
3835 "Configure peer-group\n")
3836 {
3837 VTY_DECLVAR_CONTEXT(bgp, bgp);
3838 int idx_word = 2;
3839 struct peer_group *group;
3840
3841 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3842 if (group) {
3843 peer_group_notify_unconfig(group);
3844 peer_group_delete(group);
3845 } else {
3846 vty_out(vty, "%% Create the peer-group first\n");
3847 return CMD_WARNING_CONFIG_FAILED;
3848 }
3849 return CMD_SUCCESS;
3850 }
3851
3852 DEFUN (no_neighbor_interface_peer_group_remote_as,
3853 no_neighbor_interface_peer_group_remote_as_cmd,
3854 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
3855 NO_STR
3856 NEIGHBOR_STR
3857 "Interface name or neighbor tag\n"
3858 "Specify a BGP neighbor\n"
3859 AS_STR
3860 "Internal BGP peer\n"
3861 "External BGP peer\n")
3862 {
3863 VTY_DECLVAR_CONTEXT(bgp, bgp);
3864 int idx_word = 2;
3865 struct peer_group *group;
3866 struct peer *peer;
3867
3868 /* look up for neighbor by interface name config. */
3869 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3870 if (peer) {
3871 peer_as_change(peer, 0, AS_UNSPECIFIED);
3872 return CMD_SUCCESS;
3873 }
3874
3875 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3876 if (group)
3877 peer_group_remote_as_delete(group);
3878 else {
3879 vty_out(vty, "%% Create the peer-group or interface first\n");
3880 return CMD_WARNING_CONFIG_FAILED;
3881 }
3882 return CMD_SUCCESS;
3883 }
3884
3885 DEFUN (neighbor_local_as,
3886 neighbor_local_as_cmd,
3887 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
3888 NEIGHBOR_STR
3889 NEIGHBOR_ADDR_STR2
3890 "Specify a local-as number\n"
3891 "AS number used as local AS\n")
3892 {
3893 int idx_peer = 1;
3894 int idx_number = 3;
3895 struct peer *peer;
3896 int ret;
3897 as_t as;
3898
3899 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3900 if (!peer)
3901 return CMD_WARNING_CONFIG_FAILED;
3902
3903 as = strtoul(argv[idx_number]->arg, NULL, 10);
3904 ret = peer_local_as_set(peer, as, 0, 0);
3905 return bgp_vty_return(vty, ret);
3906 }
3907
3908 DEFUN (neighbor_local_as_no_prepend,
3909 neighbor_local_as_no_prepend_cmd,
3910 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
3911 NEIGHBOR_STR
3912 NEIGHBOR_ADDR_STR2
3913 "Specify a local-as number\n"
3914 "AS number used as local AS\n"
3915 "Do not prepend local-as to updates from ebgp peers\n")
3916 {
3917 int idx_peer = 1;
3918 int idx_number = 3;
3919 struct peer *peer;
3920 int ret;
3921 as_t as;
3922
3923 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3924 if (!peer)
3925 return CMD_WARNING_CONFIG_FAILED;
3926
3927 as = strtoul(argv[idx_number]->arg, NULL, 10);
3928 ret = peer_local_as_set(peer, as, 1, 0);
3929 return bgp_vty_return(vty, ret);
3930 }
3931
3932 DEFUN (neighbor_local_as_no_prepend_replace_as,
3933 neighbor_local_as_no_prepend_replace_as_cmd,
3934 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
3935 NEIGHBOR_STR
3936 NEIGHBOR_ADDR_STR2
3937 "Specify a local-as number\n"
3938 "AS number used as local AS\n"
3939 "Do not prepend local-as to updates from ebgp peers\n"
3940 "Do not prepend local-as to updates from ibgp peers\n")
3941 {
3942 int idx_peer = 1;
3943 int idx_number = 3;
3944 struct peer *peer;
3945 int ret;
3946 as_t as;
3947
3948 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3949 if (!peer)
3950 return CMD_WARNING_CONFIG_FAILED;
3951
3952 as = strtoul(argv[idx_number]->arg, NULL, 10);
3953 ret = peer_local_as_set(peer, as, 1, 1);
3954 return bgp_vty_return(vty, ret);
3955 }
3956
3957 DEFUN (no_neighbor_local_as,
3958 no_neighbor_local_as_cmd,
3959 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
3960 NO_STR
3961 NEIGHBOR_STR
3962 NEIGHBOR_ADDR_STR2
3963 "Specify a local-as number\n"
3964 "AS number used as local AS\n"
3965 "Do not prepend local-as to updates from ebgp peers\n"
3966 "Do not prepend local-as to updates from ibgp peers\n")
3967 {
3968 int idx_peer = 2;
3969 struct peer *peer;
3970 int ret;
3971
3972 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3973 if (!peer)
3974 return CMD_WARNING_CONFIG_FAILED;
3975
3976 ret = peer_local_as_unset(peer);
3977 return bgp_vty_return(vty, ret);
3978 }
3979
3980
3981 DEFUN (neighbor_solo,
3982 neighbor_solo_cmd,
3983 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3984 NEIGHBOR_STR
3985 NEIGHBOR_ADDR_STR2
3986 "Solo peer - part of its own update group\n")
3987 {
3988 int idx_peer = 1;
3989 struct peer *peer;
3990 int ret;
3991
3992 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3993 if (!peer)
3994 return CMD_WARNING_CONFIG_FAILED;
3995
3996 ret = update_group_adjust_soloness(peer, 1);
3997 return bgp_vty_return(vty, ret);
3998 }
3999
4000 DEFUN (no_neighbor_solo,
4001 no_neighbor_solo_cmd,
4002 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
4003 NO_STR
4004 NEIGHBOR_STR
4005 NEIGHBOR_ADDR_STR2
4006 "Solo peer - part of its own update group\n")
4007 {
4008 int idx_peer = 2;
4009 struct peer *peer;
4010 int ret;
4011
4012 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4013 if (!peer)
4014 return CMD_WARNING_CONFIG_FAILED;
4015
4016 ret = update_group_adjust_soloness(peer, 0);
4017 return bgp_vty_return(vty, ret);
4018 }
4019
4020 DEFUN (neighbor_password,
4021 neighbor_password_cmd,
4022 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
4023 NEIGHBOR_STR
4024 NEIGHBOR_ADDR_STR2
4025 "Set a password\n"
4026 "The password\n")
4027 {
4028 int idx_peer = 1;
4029 int idx_line = 3;
4030 struct peer *peer;
4031 int ret;
4032
4033 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4034 if (!peer)
4035 return CMD_WARNING_CONFIG_FAILED;
4036
4037 ret = peer_password_set(peer, argv[idx_line]->arg);
4038 return bgp_vty_return(vty, ret);
4039 }
4040
4041 DEFUN (no_neighbor_password,
4042 no_neighbor_password_cmd,
4043 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
4044 NO_STR
4045 NEIGHBOR_STR
4046 NEIGHBOR_ADDR_STR2
4047 "Set a password\n"
4048 "The password\n")
4049 {
4050 int idx_peer = 2;
4051 struct peer *peer;
4052 int ret;
4053
4054 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4055 if (!peer)
4056 return CMD_WARNING_CONFIG_FAILED;
4057
4058 ret = peer_password_unset(peer);
4059 return bgp_vty_return(vty, ret);
4060 }
4061
4062 DEFUN (neighbor_activate,
4063 neighbor_activate_cmd,
4064 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4065 NEIGHBOR_STR
4066 NEIGHBOR_ADDR_STR2
4067 "Enable the Address Family for this Neighbor\n")
4068 {
4069 int idx_peer = 1;
4070 int ret;
4071 struct peer *peer;
4072
4073 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4074 if (!peer)
4075 return CMD_WARNING_CONFIG_FAILED;
4076
4077 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
4078 return bgp_vty_return(vty, ret);
4079 }
4080
4081 ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
4082 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4083 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4084 "Enable the Address Family for this Neighbor\n")
4085
4086 DEFUN (no_neighbor_activate,
4087 no_neighbor_activate_cmd,
4088 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4089 NO_STR
4090 NEIGHBOR_STR
4091 NEIGHBOR_ADDR_STR2
4092 "Enable the Address Family for this Neighbor\n")
4093 {
4094 int idx_peer = 2;
4095 int ret;
4096 struct peer *peer;
4097
4098 /* Lookup peer. */
4099 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4100 if (!peer)
4101 return CMD_WARNING_CONFIG_FAILED;
4102
4103 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
4104 return bgp_vty_return(vty, ret);
4105 }
4106
4107 ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
4108 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4109 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4110 "Enable the Address Family for this Neighbor\n")
4111
4112 DEFUN (neighbor_set_peer_group,
4113 neighbor_set_peer_group_cmd,
4114 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
4115 NEIGHBOR_STR
4116 NEIGHBOR_ADDR_STR2
4117 "Member of the peer-group\n"
4118 "Peer-group name\n")
4119 {
4120 VTY_DECLVAR_CONTEXT(bgp, bgp);
4121 int idx_peer = 1;
4122 int idx_word = 3;
4123 int ret;
4124 as_t as;
4125 union sockunion su;
4126 struct peer *peer;
4127 struct peer_group *group;
4128
4129 ret = str2sockunion(argv[idx_peer]->arg, &su);
4130 if (ret < 0) {
4131 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4132 if (!peer) {
4133 vty_out(vty, "%% Malformed address or name: %s\n",
4134 argv[idx_peer]->arg);
4135 return CMD_WARNING_CONFIG_FAILED;
4136 }
4137 } else {
4138 if (peer_address_self_check(bgp, &su)) {
4139 vty_out(vty,
4140 "%% Can not configure the local system as neighbor\n");
4141 return CMD_WARNING_CONFIG_FAILED;
4142 }
4143
4144 /* Disallow for dynamic neighbor. */
4145 peer = peer_lookup(bgp, &su);
4146 if (peer && peer_dynamic_neighbor(peer)) {
4147 vty_out(vty,
4148 "%% Operation not allowed on a dynamic neighbor\n");
4149 return CMD_WARNING_CONFIG_FAILED;
4150 }
4151 }
4152
4153 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4154 if (!group) {
4155 vty_out(vty, "%% Configure the peer-group first\n");
4156 return CMD_WARNING_CONFIG_FAILED;
4157 }
4158
4159 ret = peer_group_bind(bgp, &su, peer, group, &as);
4160
4161 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
4162 vty_out(vty,
4163 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
4164 as);
4165 return CMD_WARNING_CONFIG_FAILED;
4166 }
4167
4168 return bgp_vty_return(vty, ret);
4169 }
4170
4171 ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
4172 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
4173 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4174 "Member of the peer-group\n"
4175 "Peer-group name\n")
4176
4177 DEFUN (no_neighbor_set_peer_group,
4178 no_neighbor_set_peer_group_cmd,
4179 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
4180 NO_STR
4181 NEIGHBOR_STR
4182 NEIGHBOR_ADDR_STR2
4183 "Member of the peer-group\n"
4184 "Peer-group name\n")
4185 {
4186 VTY_DECLVAR_CONTEXT(bgp, bgp);
4187 int idx_peer = 2;
4188 int idx_word = 4;
4189 int ret;
4190 struct peer *peer;
4191 struct peer_group *group;
4192
4193 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
4194 if (!peer)
4195 return CMD_WARNING_CONFIG_FAILED;
4196
4197 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4198 if (!group) {
4199 vty_out(vty, "%% Configure the peer-group first\n");
4200 return CMD_WARNING_CONFIG_FAILED;
4201 }
4202
4203 peer_notify_unconfig(peer);
4204 ret = peer_delete(peer);
4205
4206 return bgp_vty_return(vty, ret);
4207 }
4208
4209 ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
4210 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
4211 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4212 "Member of the peer-group\n"
4213 "Peer-group name\n")
4214
4215 static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
4216 uint32_t flag, int set)
4217 {
4218 int ret;
4219 struct peer *peer;
4220
4221 peer = peer_and_group_lookup_vty(vty, ip_str);
4222 if (!peer)
4223 return CMD_WARNING_CONFIG_FAILED;
4224
4225 /*
4226 * If 'neighbor <interface>', then this is for directly connected peers,
4227 * we should not accept disable-connected-check.
4228 */
4229 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
4230 vty_out(vty,
4231 "%s is directly connected peer, cannot accept disable-"
4232 "connected-check\n",
4233 ip_str);
4234 return CMD_WARNING_CONFIG_FAILED;
4235 }
4236
4237 if (!set && flag == PEER_FLAG_SHUTDOWN)
4238 peer_tx_shutdown_message_unset(peer);
4239
4240 if (set)
4241 ret = peer_flag_set(peer, flag);
4242 else
4243 ret = peer_flag_unset(peer, flag);
4244
4245 return bgp_vty_return(vty, ret);
4246 }
4247
4248 static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
4249 {
4250 return peer_flag_modify_vty(vty, ip_str, flag, 1);
4251 }
4252
4253 static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
4254 uint32_t flag)
4255 {
4256 return peer_flag_modify_vty(vty, ip_str, flag, 0);
4257 }
4258
4259 /* neighbor passive. */
4260 DEFUN (neighbor_passive,
4261 neighbor_passive_cmd,
4262 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
4263 NEIGHBOR_STR
4264 NEIGHBOR_ADDR_STR2
4265 "Don't send open messages to this neighbor\n")
4266 {
4267 int idx_peer = 1;
4268 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
4269 }
4270
4271 DEFUN (no_neighbor_passive,
4272 no_neighbor_passive_cmd,
4273 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
4274 NO_STR
4275 NEIGHBOR_STR
4276 NEIGHBOR_ADDR_STR2
4277 "Don't send open messages to this neighbor\n")
4278 {
4279 int idx_peer = 2;
4280 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
4281 }
4282
4283 /* neighbor shutdown. */
4284 DEFUN (neighbor_shutdown_msg,
4285 neighbor_shutdown_msg_cmd,
4286 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
4287 NEIGHBOR_STR
4288 NEIGHBOR_ADDR_STR2
4289 "Administratively shut down this neighbor\n"
4290 "Add a shutdown message (draft-ietf-idr-shutdown-06)\n"
4291 "Shutdown message\n")
4292 {
4293 int idx_peer = 1;
4294
4295 if (argc >= 5) {
4296 struct peer *peer =
4297 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4298 char *message;
4299
4300 if (!peer)
4301 return CMD_WARNING_CONFIG_FAILED;
4302 message = argv_concat(argv, argc, 4);
4303 peer_tx_shutdown_message_set(peer, message);
4304 XFREE(MTYPE_TMP, message);
4305 }
4306
4307 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
4308 }
4309
4310 ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
4311 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
4312 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4313 "Administratively shut down this neighbor\n")
4314
4315 DEFUN (no_neighbor_shutdown_msg,
4316 no_neighbor_shutdown_msg_cmd,
4317 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
4318 NO_STR
4319 NEIGHBOR_STR
4320 NEIGHBOR_ADDR_STR2
4321 "Administratively shut down this neighbor\n"
4322 "Remove a shutdown message (draft-ietf-idr-shutdown-06)\n"
4323 "Shutdown message\n")
4324 {
4325 int idx_peer = 2;
4326
4327 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4328 PEER_FLAG_SHUTDOWN);
4329 }
4330
4331 ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
4332 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
4333 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4334 "Administratively shut down this neighbor\n")
4335
4336 /* neighbor capability dynamic. */
4337 DEFUN (neighbor_capability_dynamic,
4338 neighbor_capability_dynamic_cmd,
4339 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
4340 NEIGHBOR_STR
4341 NEIGHBOR_ADDR_STR2
4342 "Advertise capability to the peer\n"
4343 "Advertise dynamic capability to this neighbor\n")
4344 {
4345 int idx_peer = 1;
4346 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4347 PEER_FLAG_DYNAMIC_CAPABILITY);
4348 }
4349
4350 DEFUN (no_neighbor_capability_dynamic,
4351 no_neighbor_capability_dynamic_cmd,
4352 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
4353 NO_STR
4354 NEIGHBOR_STR
4355 NEIGHBOR_ADDR_STR2
4356 "Advertise capability to the peer\n"
4357 "Advertise dynamic capability to this neighbor\n")
4358 {
4359 int idx_peer = 2;
4360 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4361 PEER_FLAG_DYNAMIC_CAPABILITY);
4362 }
4363
4364 /* neighbor dont-capability-negotiate */
4365 DEFUN (neighbor_dont_capability_negotiate,
4366 neighbor_dont_capability_negotiate_cmd,
4367 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
4368 NEIGHBOR_STR
4369 NEIGHBOR_ADDR_STR2
4370 "Do not perform capability negotiation\n")
4371 {
4372 int idx_peer = 1;
4373 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4374 PEER_FLAG_DONT_CAPABILITY);
4375 }
4376
4377 DEFUN (no_neighbor_dont_capability_negotiate,
4378 no_neighbor_dont_capability_negotiate_cmd,
4379 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
4380 NO_STR
4381 NEIGHBOR_STR
4382 NEIGHBOR_ADDR_STR2
4383 "Do not perform capability negotiation\n")
4384 {
4385 int idx_peer = 2;
4386 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4387 PEER_FLAG_DONT_CAPABILITY);
4388 }
4389
4390 /* neighbor capability extended next hop encoding */
4391 DEFUN (neighbor_capability_enhe,
4392 neighbor_capability_enhe_cmd,
4393 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
4394 NEIGHBOR_STR
4395 NEIGHBOR_ADDR_STR2
4396 "Advertise capability to the peer\n"
4397 "Advertise extended next-hop capability to the peer\n")
4398 {
4399 int idx_peer = 1;
4400 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4401 PEER_FLAG_CAPABILITY_ENHE);
4402 }
4403
4404 DEFUN (no_neighbor_capability_enhe,
4405 no_neighbor_capability_enhe_cmd,
4406 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
4407 NO_STR
4408 NEIGHBOR_STR
4409 NEIGHBOR_ADDR_STR2
4410 "Advertise capability to the peer\n"
4411 "Advertise extended next-hop capability to the peer\n")
4412 {
4413 int idx_peer = 2;
4414 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4415 PEER_FLAG_CAPABILITY_ENHE);
4416 }
4417
4418 static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
4419 afi_t afi, safi_t safi, uint32_t flag,
4420 int set)
4421 {
4422 int ret;
4423 struct peer *peer;
4424
4425 peer = peer_and_group_lookup_vty(vty, peer_str);
4426 if (!peer)
4427 return CMD_WARNING_CONFIG_FAILED;
4428
4429 if (set)
4430 ret = peer_af_flag_set(peer, afi, safi, flag);
4431 else
4432 ret = peer_af_flag_unset(peer, afi, safi, flag);
4433
4434 return bgp_vty_return(vty, ret);
4435 }
4436
4437 static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
4438 afi_t afi, safi_t safi, uint32_t flag)
4439 {
4440 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
4441 }
4442
4443 static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
4444 afi_t afi, safi_t safi, uint32_t flag)
4445 {
4446 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
4447 }
4448
4449 /* neighbor capability orf prefix-list. */
4450 DEFUN (neighbor_capability_orf_prefix,
4451 neighbor_capability_orf_prefix_cmd,
4452 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
4453 NEIGHBOR_STR
4454 NEIGHBOR_ADDR_STR2
4455 "Advertise capability to the peer\n"
4456 "Advertise ORF capability to the peer\n"
4457 "Advertise prefixlist ORF capability to this neighbor\n"
4458 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
4459 "Capability to RECEIVE the ORF from this neighbor\n"
4460 "Capability to SEND the ORF to this neighbor\n")
4461 {
4462 int idx_peer = 1;
4463 int idx_send_recv = 5;
4464 uint16_t flag = 0;
4465
4466 if (strmatch(argv[idx_send_recv]->text, "send"))
4467 flag = PEER_FLAG_ORF_PREFIX_SM;
4468 else if (strmatch(argv[idx_send_recv]->text, "receive"))
4469 flag = PEER_FLAG_ORF_PREFIX_RM;
4470 else if (strmatch(argv[idx_send_recv]->text, "both"))
4471 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
4472 else {
4473 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
4474 return CMD_WARNING_CONFIG_FAILED;
4475 }
4476
4477 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4478 bgp_node_safi(vty), flag);
4479 }
4480
4481 ALIAS_HIDDEN(
4482 neighbor_capability_orf_prefix,
4483 neighbor_capability_orf_prefix_hidden_cmd,
4484 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
4485 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4486 "Advertise capability to the peer\n"
4487 "Advertise ORF capability to the peer\n"
4488 "Advertise prefixlist ORF capability to this neighbor\n"
4489 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
4490 "Capability to RECEIVE the ORF from this neighbor\n"
4491 "Capability to SEND the ORF to this neighbor\n")
4492
4493 DEFUN (no_neighbor_capability_orf_prefix,
4494 no_neighbor_capability_orf_prefix_cmd,
4495 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
4496 NO_STR
4497 NEIGHBOR_STR
4498 NEIGHBOR_ADDR_STR2
4499 "Advertise capability to the peer\n"
4500 "Advertise ORF capability to the peer\n"
4501 "Advertise prefixlist ORF capability to this neighbor\n"
4502 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
4503 "Capability to RECEIVE the ORF from this neighbor\n"
4504 "Capability to SEND the ORF to this neighbor\n")
4505 {
4506 int idx_peer = 2;
4507 int idx_send_recv = 6;
4508 uint16_t flag = 0;
4509
4510 if (strmatch(argv[idx_send_recv]->text, "send"))
4511 flag = PEER_FLAG_ORF_PREFIX_SM;
4512 else if (strmatch(argv[idx_send_recv]->text, "receive"))
4513 flag = PEER_FLAG_ORF_PREFIX_RM;
4514 else if (strmatch(argv[idx_send_recv]->text, "both"))
4515 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
4516 else {
4517 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
4518 return CMD_WARNING_CONFIG_FAILED;
4519 }
4520
4521 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4522 bgp_node_afi(vty), bgp_node_safi(vty),
4523 flag);
4524 }
4525
4526 ALIAS_HIDDEN(
4527 no_neighbor_capability_orf_prefix,
4528 no_neighbor_capability_orf_prefix_hidden_cmd,
4529 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
4530 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4531 "Advertise capability to the peer\n"
4532 "Advertise ORF capability to the peer\n"
4533 "Advertise prefixlist ORF capability to this neighbor\n"
4534 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
4535 "Capability to RECEIVE the ORF from this neighbor\n"
4536 "Capability to SEND the ORF to this neighbor\n")
4537
4538 /* neighbor next-hop-self. */
4539 DEFUN (neighbor_nexthop_self,
4540 neighbor_nexthop_self_cmd,
4541 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
4542 NEIGHBOR_STR
4543 NEIGHBOR_ADDR_STR2
4544 "Disable the next hop calculation for this neighbor\n")
4545 {
4546 int idx_peer = 1;
4547 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4548 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
4549 }
4550
4551 ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
4552 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
4553 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4554 "Disable the next hop calculation for this neighbor\n")
4555
4556 /* neighbor next-hop-self. */
4557 DEFUN (neighbor_nexthop_self_force,
4558 neighbor_nexthop_self_force_cmd,
4559 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
4560 NEIGHBOR_STR
4561 NEIGHBOR_ADDR_STR2
4562 "Disable the next hop calculation for this neighbor\n"
4563 "Set the next hop to self for reflected routes\n")
4564 {
4565 int idx_peer = 1;
4566 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4567 bgp_node_safi(vty),
4568 PEER_FLAG_FORCE_NEXTHOP_SELF);
4569 }
4570
4571 ALIAS_HIDDEN(neighbor_nexthop_self_force,
4572 neighbor_nexthop_self_force_hidden_cmd,
4573 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
4574 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4575 "Disable the next hop calculation for this neighbor\n"
4576 "Set the next hop to self for reflected routes\n")
4577
4578 ALIAS_HIDDEN(neighbor_nexthop_self_force,
4579 neighbor_nexthop_self_all_hidden_cmd,
4580 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
4581 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4582 "Disable the next hop calculation for this neighbor\n"
4583 "Set the next hop to self for reflected routes\n")
4584
4585 DEFUN (no_neighbor_nexthop_self,
4586 no_neighbor_nexthop_self_cmd,
4587 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
4588 NO_STR
4589 NEIGHBOR_STR
4590 NEIGHBOR_ADDR_STR2
4591 "Disable the next hop calculation for this neighbor\n")
4592 {
4593 int idx_peer = 2;
4594 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4595 bgp_node_afi(vty), bgp_node_safi(vty),
4596 PEER_FLAG_NEXTHOP_SELF);
4597 }
4598
4599 ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
4600 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
4601 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4602 "Disable the next hop calculation for this neighbor\n")
4603
4604 DEFUN (no_neighbor_nexthop_self_force,
4605 no_neighbor_nexthop_self_force_cmd,
4606 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
4607 NO_STR
4608 NEIGHBOR_STR
4609 NEIGHBOR_ADDR_STR2
4610 "Disable the next hop calculation for this neighbor\n"
4611 "Set the next hop to self for reflected routes\n")
4612 {
4613 int idx_peer = 2;
4614 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4615 bgp_node_afi(vty), bgp_node_safi(vty),
4616 PEER_FLAG_FORCE_NEXTHOP_SELF);
4617 }
4618
4619 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
4620 no_neighbor_nexthop_self_force_hidden_cmd,
4621 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
4622 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4623 "Disable the next hop calculation for this neighbor\n"
4624 "Set the next hop to self for reflected routes\n")
4625
4626 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
4627 no_neighbor_nexthop_self_all_hidden_cmd,
4628 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
4629 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4630 "Disable the next hop calculation for this neighbor\n"
4631 "Set the next hop to self for reflected routes\n")
4632
4633 /* neighbor as-override */
4634 DEFUN (neighbor_as_override,
4635 neighbor_as_override_cmd,
4636 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4637 NEIGHBOR_STR
4638 NEIGHBOR_ADDR_STR2
4639 "Override ASNs in outbound updates if aspath equals remote-as\n")
4640 {
4641 int idx_peer = 1;
4642 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4643 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
4644 }
4645
4646 ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
4647 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4648 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4649 "Override ASNs in outbound updates if aspath equals remote-as\n")
4650
4651 DEFUN (no_neighbor_as_override,
4652 no_neighbor_as_override_cmd,
4653 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4654 NO_STR
4655 NEIGHBOR_STR
4656 NEIGHBOR_ADDR_STR2
4657 "Override ASNs in outbound updates if aspath equals remote-as\n")
4658 {
4659 int idx_peer = 2;
4660 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4661 bgp_node_afi(vty), bgp_node_safi(vty),
4662 PEER_FLAG_AS_OVERRIDE);
4663 }
4664
4665 ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
4666 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4667 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4668 "Override ASNs in outbound updates if aspath equals remote-as\n")
4669
4670 /* neighbor remove-private-AS. */
4671 DEFUN (neighbor_remove_private_as,
4672 neighbor_remove_private_as_cmd,
4673 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4674 NEIGHBOR_STR
4675 NEIGHBOR_ADDR_STR2
4676 "Remove private ASNs in outbound updates\n")
4677 {
4678 int idx_peer = 1;
4679 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4680 bgp_node_safi(vty),
4681 PEER_FLAG_REMOVE_PRIVATE_AS);
4682 }
4683
4684 ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
4685 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4686 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4687 "Remove private ASNs in outbound updates\n")
4688
4689 DEFUN (neighbor_remove_private_as_all,
4690 neighbor_remove_private_as_all_cmd,
4691 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4692 NEIGHBOR_STR
4693 NEIGHBOR_ADDR_STR2
4694 "Remove private ASNs in outbound updates\n"
4695 "Apply to all AS numbers\n")
4696 {
4697 int idx_peer = 1;
4698 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4699 bgp_node_safi(vty),
4700 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
4701 }
4702
4703 ALIAS_HIDDEN(neighbor_remove_private_as_all,
4704 neighbor_remove_private_as_all_hidden_cmd,
4705 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4706 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4707 "Remove private ASNs in outbound updates\n"
4708 "Apply to all AS numbers")
4709
4710 DEFUN (neighbor_remove_private_as_replace_as,
4711 neighbor_remove_private_as_replace_as_cmd,
4712 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4713 NEIGHBOR_STR
4714 NEIGHBOR_ADDR_STR2
4715 "Remove private ASNs in outbound updates\n"
4716 "Replace private ASNs with our ASN in outbound updates\n")
4717 {
4718 int idx_peer = 1;
4719 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4720 bgp_node_safi(vty),
4721 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
4722 }
4723
4724 ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
4725 neighbor_remove_private_as_replace_as_hidden_cmd,
4726 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4727 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4728 "Remove private ASNs in outbound updates\n"
4729 "Replace private ASNs with our ASN in outbound updates\n")
4730
4731 DEFUN (neighbor_remove_private_as_all_replace_as,
4732 neighbor_remove_private_as_all_replace_as_cmd,
4733 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4734 NEIGHBOR_STR
4735 NEIGHBOR_ADDR_STR2
4736 "Remove private ASNs in outbound updates\n"
4737 "Apply to all AS numbers\n"
4738 "Replace private ASNs with our ASN in outbound updates\n")
4739 {
4740 int idx_peer = 1;
4741 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4742 bgp_node_safi(vty),
4743 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
4744 }
4745
4746 ALIAS_HIDDEN(
4747 neighbor_remove_private_as_all_replace_as,
4748 neighbor_remove_private_as_all_replace_as_hidden_cmd,
4749 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4750 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4751 "Remove private ASNs in outbound updates\n"
4752 "Apply to all AS numbers\n"
4753 "Replace private ASNs with our ASN in outbound updates\n")
4754
4755 DEFUN (no_neighbor_remove_private_as,
4756 no_neighbor_remove_private_as_cmd,
4757 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4758 NO_STR
4759 NEIGHBOR_STR
4760 NEIGHBOR_ADDR_STR2
4761 "Remove private ASNs in outbound updates\n")
4762 {
4763 int idx_peer = 2;
4764 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4765 bgp_node_afi(vty), bgp_node_safi(vty),
4766 PEER_FLAG_REMOVE_PRIVATE_AS);
4767 }
4768
4769 ALIAS_HIDDEN(no_neighbor_remove_private_as,
4770 no_neighbor_remove_private_as_hidden_cmd,
4771 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4772 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4773 "Remove private ASNs in outbound updates\n")
4774
4775 DEFUN (no_neighbor_remove_private_as_all,
4776 no_neighbor_remove_private_as_all_cmd,
4777 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4778 NO_STR
4779 NEIGHBOR_STR
4780 NEIGHBOR_ADDR_STR2
4781 "Remove private ASNs in outbound updates\n"
4782 "Apply to all AS numbers\n")
4783 {
4784 int idx_peer = 2;
4785 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4786 bgp_node_afi(vty), bgp_node_safi(vty),
4787 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
4788 }
4789
4790 ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
4791 no_neighbor_remove_private_as_all_hidden_cmd,
4792 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4793 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4794 "Remove private ASNs in outbound updates\n"
4795 "Apply to all AS numbers\n")
4796
4797 DEFUN (no_neighbor_remove_private_as_replace_as,
4798 no_neighbor_remove_private_as_replace_as_cmd,
4799 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4800 NO_STR
4801 NEIGHBOR_STR
4802 NEIGHBOR_ADDR_STR2
4803 "Remove private ASNs in outbound updates\n"
4804 "Replace private ASNs with our ASN in outbound updates\n")
4805 {
4806 int idx_peer = 2;
4807 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4808 bgp_node_afi(vty), bgp_node_safi(vty),
4809 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
4810 }
4811
4812 ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
4813 no_neighbor_remove_private_as_replace_as_hidden_cmd,
4814 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4815 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4816 "Remove private ASNs in outbound updates\n"
4817 "Replace private ASNs with our ASN in outbound updates\n")
4818
4819 DEFUN (no_neighbor_remove_private_as_all_replace_as,
4820 no_neighbor_remove_private_as_all_replace_as_cmd,
4821 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4822 NO_STR
4823 NEIGHBOR_STR
4824 NEIGHBOR_ADDR_STR2
4825 "Remove private ASNs in outbound updates\n"
4826 "Apply to all AS numbers\n"
4827 "Replace private ASNs with our ASN in outbound updates\n")
4828 {
4829 int idx_peer = 2;
4830 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4831 bgp_node_afi(vty), bgp_node_safi(vty),
4832 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
4833 }
4834
4835 ALIAS_HIDDEN(
4836 no_neighbor_remove_private_as_all_replace_as,
4837 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
4838 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4839 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4840 "Remove private ASNs in outbound updates\n"
4841 "Apply to all AS numbers\n"
4842 "Replace private ASNs with our ASN in outbound updates\n")
4843
4844
4845 /* neighbor send-community. */
4846 DEFUN (neighbor_send_community,
4847 neighbor_send_community_cmd,
4848 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4849 NEIGHBOR_STR
4850 NEIGHBOR_ADDR_STR2
4851 "Send Community attribute to this neighbor\n")
4852 {
4853 int idx_peer = 1;
4854
4855 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4856 bgp_node_safi(vty),
4857 PEER_FLAG_SEND_COMMUNITY);
4858 }
4859
4860 ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
4861 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4862 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4863 "Send Community attribute to this neighbor\n")
4864
4865 DEFUN (no_neighbor_send_community,
4866 no_neighbor_send_community_cmd,
4867 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4868 NO_STR
4869 NEIGHBOR_STR
4870 NEIGHBOR_ADDR_STR2
4871 "Send Community attribute to this neighbor\n")
4872 {
4873 int idx_peer = 2;
4874
4875 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4876 bgp_node_afi(vty), bgp_node_safi(vty),
4877 PEER_FLAG_SEND_COMMUNITY);
4878 }
4879
4880 ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
4881 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4882 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4883 "Send Community attribute to this neighbor\n")
4884
4885 /* neighbor send-community extended. */
4886 DEFUN (neighbor_send_community_type,
4887 neighbor_send_community_type_cmd,
4888 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4889 NEIGHBOR_STR
4890 NEIGHBOR_ADDR_STR2
4891 "Send Community attribute to this neighbor\n"
4892 "Send Standard and Extended Community attributes\n"
4893 "Send Standard, Large and Extended Community attributes\n"
4894 "Send Extended Community attributes\n"
4895 "Send Standard Community attributes\n"
4896 "Send Large Community attributes\n")
4897 {
4898 int idx_peer = 1;
4899 uint32_t flag = 0;
4900 const char *type = argv[argc - 1]->text;
4901
4902 if (strmatch(type, "standard")) {
4903 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4904 } else if (strmatch(type, "extended")) {
4905 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4906 } else if (strmatch(type, "large")) {
4907 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4908 } else if (strmatch(type, "both")) {
4909 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4910 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4911 } else { /* if (strmatch(type, "all")) */
4912 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4913 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4914 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4915 }
4916
4917 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4918 bgp_node_safi(vty), flag);
4919 }
4920
4921 ALIAS_HIDDEN(
4922 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
4923 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4924 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4925 "Send Community attribute to this neighbor\n"
4926 "Send Standard and Extended Community attributes\n"
4927 "Send Standard, Large and Extended Community attributes\n"
4928 "Send Extended Community attributes\n"
4929 "Send Standard Community attributes\n"
4930 "Send Large Community attributes\n")
4931
4932 DEFUN (no_neighbor_send_community_type,
4933 no_neighbor_send_community_type_cmd,
4934 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4935 NO_STR
4936 NEIGHBOR_STR
4937 NEIGHBOR_ADDR_STR2
4938 "Send Community attribute to this neighbor\n"
4939 "Send Standard and Extended Community attributes\n"
4940 "Send Standard, Large and Extended Community attributes\n"
4941 "Send Extended Community attributes\n"
4942 "Send Standard Community attributes\n"
4943 "Send Large Community attributes\n")
4944 {
4945 int idx_peer = 2;
4946 uint32_t flag = 0;
4947 const char *type = argv[argc - 1]->text;
4948
4949 if (strmatch(type, "standard")) {
4950 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4951 } else if (strmatch(type, "extended")) {
4952 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4953 } else if (strmatch(type, "large")) {
4954 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4955 } else if (strmatch(type, "both")) {
4956 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4957 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4958 } else { /* if (strmatch(type, "all")) */
4959 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4960 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4961 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4962 }
4963
4964 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4965 bgp_node_afi(vty), bgp_node_safi(vty),
4966 flag);
4967 }
4968
4969 ALIAS_HIDDEN(
4970 no_neighbor_send_community_type,
4971 no_neighbor_send_community_type_hidden_cmd,
4972 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4973 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4974 "Send Community attribute to this neighbor\n"
4975 "Send Standard and Extended Community attributes\n"
4976 "Send Standard, Large and Extended Community attributes\n"
4977 "Send Extended Community attributes\n"
4978 "Send Standard Community attributes\n"
4979 "Send Large Community attributes\n")
4980
4981 /* neighbor soft-reconfig. */
4982 DEFUN (neighbor_soft_reconfiguration,
4983 neighbor_soft_reconfiguration_cmd,
4984 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4985 NEIGHBOR_STR
4986 NEIGHBOR_ADDR_STR2
4987 "Per neighbor soft reconfiguration\n"
4988 "Allow inbound soft reconfiguration for this neighbor\n")
4989 {
4990 int idx_peer = 1;
4991 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4992 bgp_node_safi(vty),
4993 PEER_FLAG_SOFT_RECONFIG);
4994 }
4995
4996 ALIAS_HIDDEN(neighbor_soft_reconfiguration,
4997 neighbor_soft_reconfiguration_hidden_cmd,
4998 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4999 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5000 "Per neighbor soft reconfiguration\n"
5001 "Allow inbound soft reconfiguration for this neighbor\n")
5002
5003 DEFUN (no_neighbor_soft_reconfiguration,
5004 no_neighbor_soft_reconfiguration_cmd,
5005 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
5006 NO_STR
5007 NEIGHBOR_STR
5008 NEIGHBOR_ADDR_STR2
5009 "Per neighbor soft reconfiguration\n"
5010 "Allow inbound soft reconfiguration for this neighbor\n")
5011 {
5012 int idx_peer = 2;
5013 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5014 bgp_node_afi(vty), bgp_node_safi(vty),
5015 PEER_FLAG_SOFT_RECONFIG);
5016 }
5017
5018 ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
5019 no_neighbor_soft_reconfiguration_hidden_cmd,
5020 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
5021 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5022 "Per neighbor soft reconfiguration\n"
5023 "Allow inbound soft reconfiguration for this neighbor\n")
5024
5025 DEFUN (neighbor_route_reflector_client,
5026 neighbor_route_reflector_client_cmd,
5027 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
5028 NEIGHBOR_STR
5029 NEIGHBOR_ADDR_STR2
5030 "Configure a neighbor as Route Reflector client\n")
5031 {
5032 int idx_peer = 1;
5033 struct peer *peer;
5034
5035
5036 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5037 if (!peer)
5038 return CMD_WARNING_CONFIG_FAILED;
5039
5040 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5041 bgp_node_safi(vty),
5042 PEER_FLAG_REFLECTOR_CLIENT);
5043 }
5044
5045 ALIAS_HIDDEN(neighbor_route_reflector_client,
5046 neighbor_route_reflector_client_hidden_cmd,
5047 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
5048 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5049 "Configure a neighbor as Route Reflector client\n")
5050
5051 DEFUN (no_neighbor_route_reflector_client,
5052 no_neighbor_route_reflector_client_cmd,
5053 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
5054 NO_STR
5055 NEIGHBOR_STR
5056 NEIGHBOR_ADDR_STR2
5057 "Configure a neighbor as Route Reflector client\n")
5058 {
5059 int idx_peer = 2;
5060 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5061 bgp_node_afi(vty), bgp_node_safi(vty),
5062 PEER_FLAG_REFLECTOR_CLIENT);
5063 }
5064
5065 ALIAS_HIDDEN(no_neighbor_route_reflector_client,
5066 no_neighbor_route_reflector_client_hidden_cmd,
5067 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
5068 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5069 "Configure a neighbor as Route Reflector client\n")
5070
5071 /* neighbor route-server-client. */
5072 DEFUN (neighbor_route_server_client,
5073 neighbor_route_server_client_cmd,
5074 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
5075 NEIGHBOR_STR
5076 NEIGHBOR_ADDR_STR2
5077 "Configure a neighbor as Route Server client\n")
5078 {
5079 int idx_peer = 1;
5080 struct peer *peer;
5081
5082 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5083 if (!peer)
5084 return CMD_WARNING_CONFIG_FAILED;
5085 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5086 bgp_node_safi(vty),
5087 PEER_FLAG_RSERVER_CLIENT);
5088 }
5089
5090 ALIAS_HIDDEN(neighbor_route_server_client,
5091 neighbor_route_server_client_hidden_cmd,
5092 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
5093 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5094 "Configure a neighbor as Route Server client\n")
5095
5096 DEFUN (no_neighbor_route_server_client,
5097 no_neighbor_route_server_client_cmd,
5098 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
5099 NO_STR
5100 NEIGHBOR_STR
5101 NEIGHBOR_ADDR_STR2
5102 "Configure a neighbor as Route Server client\n")
5103 {
5104 int idx_peer = 2;
5105 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5106 bgp_node_afi(vty), bgp_node_safi(vty),
5107 PEER_FLAG_RSERVER_CLIENT);
5108 }
5109
5110 ALIAS_HIDDEN(no_neighbor_route_server_client,
5111 no_neighbor_route_server_client_hidden_cmd,
5112 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
5113 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5114 "Configure a neighbor as Route Server client\n")
5115
5116 DEFUN (neighbor_nexthop_local_unchanged,
5117 neighbor_nexthop_local_unchanged_cmd,
5118 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
5119 NEIGHBOR_STR
5120 NEIGHBOR_ADDR_STR2
5121 "Configure treatment of outgoing link-local nexthop attribute\n"
5122 "Leave link-local nexthop unchanged for this peer\n")
5123 {
5124 int idx_peer = 1;
5125 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5126 bgp_node_safi(vty),
5127 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
5128 }
5129
5130 DEFUN (no_neighbor_nexthop_local_unchanged,
5131 no_neighbor_nexthop_local_unchanged_cmd,
5132 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
5133 NO_STR
5134 NEIGHBOR_STR
5135 NEIGHBOR_ADDR_STR2
5136 "Configure treatment of outgoing link-local-nexthop attribute\n"
5137 "Leave link-local nexthop unchanged for this peer\n")
5138 {
5139 int idx_peer = 2;
5140 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5141 bgp_node_afi(vty), bgp_node_safi(vty),
5142 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
5143 }
5144
5145 DEFUN (neighbor_attr_unchanged,
5146 neighbor_attr_unchanged_cmd,
5147 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
5148 NEIGHBOR_STR
5149 NEIGHBOR_ADDR_STR2
5150 "BGP attribute is propagated unchanged to this neighbor\n"
5151 "As-path attribute\n"
5152 "Nexthop attribute\n"
5153 "Med attribute\n")
5154 {
5155 int idx = 0;
5156 char *peer_str = argv[1]->arg;
5157 struct peer *peer;
5158 uint16_t flags = 0;
5159 afi_t afi = bgp_node_afi(vty);
5160 safi_t safi = bgp_node_safi(vty);
5161
5162 peer = peer_and_group_lookup_vty(vty, peer_str);
5163 if (!peer)
5164 return CMD_WARNING_CONFIG_FAILED;
5165
5166 if (argv_find(argv, argc, "as-path", &idx))
5167 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
5168 idx = 0;
5169 if (argv_find(argv, argc, "next-hop", &idx))
5170 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
5171 idx = 0;
5172 if (argv_find(argv, argc, "med", &idx))
5173 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
5174
5175 /* no flags means all of them! */
5176 if (!flags) {
5177 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
5178 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
5179 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
5180 } else {
5181 if (!CHECK_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED)
5182 && peer_af_flag_check(peer, afi, safi,
5183 PEER_FLAG_AS_PATH_UNCHANGED)) {
5184 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5185 PEER_FLAG_AS_PATH_UNCHANGED);
5186 }
5187
5188 if (!CHECK_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED)
5189 && peer_af_flag_check(peer, afi, safi,
5190 PEER_FLAG_NEXTHOP_UNCHANGED)) {
5191 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5192 PEER_FLAG_NEXTHOP_UNCHANGED);
5193 }
5194
5195 if (!CHECK_FLAG(flags, PEER_FLAG_MED_UNCHANGED)
5196 && peer_af_flag_check(peer, afi, safi,
5197 PEER_FLAG_MED_UNCHANGED)) {
5198 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5199 PEER_FLAG_MED_UNCHANGED);
5200 }
5201 }
5202
5203 return peer_af_flag_set_vty(vty, peer_str, afi, safi, flags);
5204 }
5205
5206 ALIAS_HIDDEN(
5207 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
5208 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
5209 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5210 "BGP attribute is propagated unchanged to this neighbor\n"
5211 "As-path attribute\n"
5212 "Nexthop attribute\n"
5213 "Med attribute\n")
5214
5215 DEFUN (no_neighbor_attr_unchanged,
5216 no_neighbor_attr_unchanged_cmd,
5217 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
5218 NO_STR
5219 NEIGHBOR_STR
5220 NEIGHBOR_ADDR_STR2
5221 "BGP attribute is propagated unchanged to this neighbor\n"
5222 "As-path attribute\n"
5223 "Nexthop attribute\n"
5224 "Med attribute\n")
5225 {
5226 int idx = 0;
5227 char *peer = argv[2]->arg;
5228 uint16_t flags = 0;
5229
5230 if (argv_find(argv, argc, "as-path", &idx))
5231 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
5232 idx = 0;
5233 if (argv_find(argv, argc, "next-hop", &idx))
5234 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
5235 idx = 0;
5236 if (argv_find(argv, argc, "med", &idx))
5237 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
5238
5239 if (!flags) // no flags means all of them!
5240 {
5241 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
5242 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
5243 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
5244 }
5245
5246 return peer_af_flag_unset_vty(vty, peer, bgp_node_afi(vty),
5247 bgp_node_safi(vty), flags);
5248 }
5249
5250 ALIAS_HIDDEN(
5251 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
5252 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
5253 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5254 "BGP attribute is propagated unchanged to this neighbor\n"
5255 "As-path attribute\n"
5256 "Nexthop attribute\n"
5257 "Med attribute\n")
5258
5259 /* EBGP multihop configuration. */
5260 static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
5261 const char *ttl_str)
5262 {
5263 struct peer *peer;
5264 unsigned int ttl;
5265
5266 peer = peer_and_group_lookup_vty(vty, ip_str);
5267 if (!peer)
5268 return CMD_WARNING_CONFIG_FAILED;
5269
5270 if (peer->conf_if)
5271 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
5272
5273 if (!ttl_str)
5274 ttl = MAXTTL;
5275 else
5276 ttl = strtoul(ttl_str, NULL, 10);
5277
5278 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
5279 }
5280
5281 static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
5282 {
5283 struct peer *peer;
5284
5285 peer = peer_and_group_lookup_vty(vty, ip_str);
5286 if (!peer)
5287 return CMD_WARNING_CONFIG_FAILED;
5288
5289 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
5290 }
5291
5292 /* neighbor ebgp-multihop. */
5293 DEFUN (neighbor_ebgp_multihop,
5294 neighbor_ebgp_multihop_cmd,
5295 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
5296 NEIGHBOR_STR
5297 NEIGHBOR_ADDR_STR2
5298 "Allow EBGP neighbors not on directly connected networks\n")
5299 {
5300 int idx_peer = 1;
5301 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
5302 }
5303
5304 DEFUN (neighbor_ebgp_multihop_ttl,
5305 neighbor_ebgp_multihop_ttl_cmd,
5306 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
5307 NEIGHBOR_STR
5308 NEIGHBOR_ADDR_STR2
5309 "Allow EBGP neighbors not on directly connected networks\n"
5310 "maximum hop count\n")
5311 {
5312 int idx_peer = 1;
5313 int idx_number = 3;
5314 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
5315 argv[idx_number]->arg);
5316 }
5317
5318 DEFUN (no_neighbor_ebgp_multihop,
5319 no_neighbor_ebgp_multihop_cmd,
5320 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
5321 NO_STR
5322 NEIGHBOR_STR
5323 NEIGHBOR_ADDR_STR2
5324 "Allow EBGP neighbors not on directly connected networks\n"
5325 "maximum hop count\n")
5326 {
5327 int idx_peer = 2;
5328 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
5329 }
5330
5331
5332 /* disable-connected-check */
5333 DEFUN (neighbor_disable_connected_check,
5334 neighbor_disable_connected_check_cmd,
5335 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
5336 NEIGHBOR_STR
5337 NEIGHBOR_ADDR_STR2
5338 "one-hop away EBGP peer using loopback address\n"
5339 "Enforce EBGP neighbors perform multihop\n")
5340 {
5341 int idx_peer = 1;
5342 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5343 PEER_FLAG_DISABLE_CONNECTED_CHECK);
5344 }
5345
5346 DEFUN (no_neighbor_disable_connected_check,
5347 no_neighbor_disable_connected_check_cmd,
5348 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
5349 NO_STR
5350 NEIGHBOR_STR
5351 NEIGHBOR_ADDR_STR2
5352 "one-hop away EBGP peer using loopback address\n"
5353 "Enforce EBGP neighbors perform multihop\n")
5354 {
5355 int idx_peer = 2;
5356 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5357 PEER_FLAG_DISABLE_CONNECTED_CHECK);
5358 }
5359
5360
5361 /* enforce-first-as */
5362 DEFUN (neighbor_enforce_first_as,
5363 neighbor_enforce_first_as_cmd,
5364 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
5365 NEIGHBOR_STR
5366 NEIGHBOR_ADDR_STR2
5367 "Enforce the first AS for EBGP routes\n")
5368 {
5369 int idx_peer = 1;
5370
5371 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5372 PEER_FLAG_ENFORCE_FIRST_AS);
5373 }
5374
5375 DEFUN (no_neighbor_enforce_first_as,
5376 no_neighbor_enforce_first_as_cmd,
5377 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
5378 NO_STR
5379 NEIGHBOR_STR
5380 NEIGHBOR_ADDR_STR2
5381 "Enforce the first AS for EBGP routes\n")
5382 {
5383 int idx_peer = 2;
5384
5385 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5386 PEER_FLAG_ENFORCE_FIRST_AS);
5387 }
5388
5389
5390 DEFUN (neighbor_description,
5391 neighbor_description_cmd,
5392 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
5393 NEIGHBOR_STR
5394 NEIGHBOR_ADDR_STR2
5395 "Neighbor specific description\n"
5396 "Up to 80 characters describing this neighbor\n")
5397 {
5398 int idx_peer = 1;
5399 int idx_line = 3;
5400 struct peer *peer;
5401 char *str;
5402
5403 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5404 if (!peer)
5405 return CMD_WARNING_CONFIG_FAILED;
5406
5407 str = argv_concat(argv, argc, idx_line);
5408
5409 peer_description_set(peer, str);
5410
5411 XFREE(MTYPE_TMP, str);
5412
5413 return CMD_SUCCESS;
5414 }
5415
5416 DEFUN (no_neighbor_description,
5417 no_neighbor_description_cmd,
5418 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
5419 NO_STR
5420 NEIGHBOR_STR
5421 NEIGHBOR_ADDR_STR2
5422 "Neighbor specific description\n")
5423 {
5424 int idx_peer = 2;
5425 struct peer *peer;
5426
5427 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5428 if (!peer)
5429 return CMD_WARNING_CONFIG_FAILED;
5430
5431 peer_description_unset(peer);
5432
5433 return CMD_SUCCESS;
5434 }
5435
5436 ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
5437 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
5438 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5439 "Neighbor specific description\n"
5440 "Up to 80 characters describing this neighbor\n")
5441
5442 /* Neighbor update-source. */
5443 static int peer_update_source_vty(struct vty *vty, const char *peer_str,
5444 const char *source_str)
5445 {
5446 struct peer *peer;
5447 struct prefix p;
5448 union sockunion su;
5449
5450 peer = peer_and_group_lookup_vty(vty, peer_str);
5451 if (!peer)
5452 return CMD_WARNING_CONFIG_FAILED;
5453
5454 if (peer->conf_if)
5455 return CMD_WARNING;
5456
5457 if (source_str) {
5458 if (str2sockunion(source_str, &su) == 0)
5459 peer_update_source_addr_set(peer, &su);
5460 else {
5461 if (str2prefix(source_str, &p)) {
5462 vty_out(vty,
5463 "%% Invalid update-source, remove prefix length \n");
5464 return CMD_WARNING_CONFIG_FAILED;
5465 } else
5466 peer_update_source_if_set(peer, source_str);
5467 }
5468 } else
5469 peer_update_source_unset(peer);
5470
5471 return CMD_SUCCESS;
5472 }
5473
5474 #define BGP_UPDATE_SOURCE_HELP_STR \
5475 "IPv4 address\n" \
5476 "IPv6 address\n" \
5477 "Interface name (requires zebra to be running)\n"
5478
5479 DEFUN (neighbor_update_source,
5480 neighbor_update_source_cmd,
5481 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
5482 NEIGHBOR_STR
5483 NEIGHBOR_ADDR_STR2
5484 "Source of routing updates\n"
5485 BGP_UPDATE_SOURCE_HELP_STR)
5486 {
5487 int idx_peer = 1;
5488 int idx_peer_2 = 3;
5489 return peer_update_source_vty(vty, argv[idx_peer]->arg,
5490 argv[idx_peer_2]->arg);
5491 }
5492
5493 DEFUN (no_neighbor_update_source,
5494 no_neighbor_update_source_cmd,
5495 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
5496 NO_STR
5497 NEIGHBOR_STR
5498 NEIGHBOR_ADDR_STR2
5499 "Source of routing updates\n"
5500 BGP_UPDATE_SOURCE_HELP_STR)
5501 {
5502 int idx_peer = 2;
5503 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
5504 }
5505
5506 static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
5507 afi_t afi, safi_t safi,
5508 const char *rmap, int set)
5509 {
5510 int ret;
5511 struct peer *peer;
5512 struct route_map *route_map = NULL;
5513
5514 peer = peer_and_group_lookup_vty(vty, peer_str);
5515 if (!peer)
5516 return CMD_WARNING_CONFIG_FAILED;
5517
5518 if (set) {
5519 if (rmap)
5520 route_map = route_map_lookup_warn_noexist(vty, rmap);
5521 ret = peer_default_originate_set(peer, afi, safi,
5522 rmap, route_map);
5523 } else
5524 ret = peer_default_originate_unset(peer, afi, safi);
5525
5526 return bgp_vty_return(vty, ret);
5527 }
5528
5529 /* neighbor default-originate. */
5530 DEFUN (neighbor_default_originate,
5531 neighbor_default_originate_cmd,
5532 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
5533 NEIGHBOR_STR
5534 NEIGHBOR_ADDR_STR2
5535 "Originate default route to this neighbor\n")
5536 {
5537 int idx_peer = 1;
5538 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
5539 bgp_node_afi(vty),
5540 bgp_node_safi(vty), NULL, 1);
5541 }
5542
5543 ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
5544 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
5545 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5546 "Originate default route to this neighbor\n")
5547
5548 DEFUN (neighbor_default_originate_rmap,
5549 neighbor_default_originate_rmap_cmd,
5550 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
5551 NEIGHBOR_STR
5552 NEIGHBOR_ADDR_STR2
5553 "Originate default route to this neighbor\n"
5554 "Route-map to specify criteria to originate default\n"
5555 "route-map name\n")
5556 {
5557 int idx_peer = 1;
5558 int idx_word = 4;
5559 return peer_default_originate_set_vty(
5560 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5561 argv[idx_word]->arg, 1);
5562 }
5563
5564 ALIAS_HIDDEN(
5565 neighbor_default_originate_rmap,
5566 neighbor_default_originate_rmap_hidden_cmd,
5567 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
5568 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5569 "Originate default route to this neighbor\n"
5570 "Route-map to specify criteria to originate default\n"
5571 "route-map name\n")
5572
5573 DEFUN (no_neighbor_default_originate,
5574 no_neighbor_default_originate_cmd,
5575 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
5576 NO_STR
5577 NEIGHBOR_STR
5578 NEIGHBOR_ADDR_STR2
5579 "Originate default route to this neighbor\n"
5580 "Route-map to specify criteria to originate default\n"
5581 "route-map name\n")
5582 {
5583 int idx_peer = 2;
5584 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
5585 bgp_node_afi(vty),
5586 bgp_node_safi(vty), NULL, 0);
5587 }
5588
5589 ALIAS_HIDDEN(
5590 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
5591 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
5592 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5593 "Originate default route to this neighbor\n"
5594 "Route-map to specify criteria to originate default\n"
5595 "route-map name\n")
5596
5597
5598 /* Set neighbor's BGP port. */
5599 static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
5600 const char *port_str)
5601 {
5602 struct peer *peer;
5603 uint16_t port;
5604 struct servent *sp;
5605
5606 peer = peer_lookup_vty(vty, ip_str);
5607 if (!peer)
5608 return CMD_WARNING_CONFIG_FAILED;
5609
5610 if (!port_str) {
5611 sp = getservbyname("bgp", "tcp");
5612 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
5613 } else {
5614 port = strtoul(port_str, NULL, 10);
5615 }
5616
5617 peer_port_set(peer, port);
5618
5619 return CMD_SUCCESS;
5620 }
5621
5622 /* Set specified peer's BGP port. */
5623 DEFUN (neighbor_port,
5624 neighbor_port_cmd,
5625 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
5626 NEIGHBOR_STR
5627 NEIGHBOR_ADDR_STR
5628 "Neighbor's BGP port\n"
5629 "TCP port number\n")
5630 {
5631 int idx_ip = 1;
5632 int idx_number = 3;
5633 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
5634 argv[idx_number]->arg);
5635 }
5636
5637 DEFUN (no_neighbor_port,
5638 no_neighbor_port_cmd,
5639 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
5640 NO_STR
5641 NEIGHBOR_STR
5642 NEIGHBOR_ADDR_STR
5643 "Neighbor's BGP port\n"
5644 "TCP port number\n")
5645 {
5646 int idx_ip = 2;
5647 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
5648 }
5649
5650
5651 /* neighbor weight. */
5652 static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5653 safi_t safi, const char *weight_str)
5654 {
5655 int ret;
5656 struct peer *peer;
5657 unsigned long weight;
5658
5659 peer = peer_and_group_lookup_vty(vty, ip_str);
5660 if (!peer)
5661 return CMD_WARNING_CONFIG_FAILED;
5662
5663 weight = strtoul(weight_str, NULL, 10);
5664
5665 ret = peer_weight_set(peer, afi, safi, weight);
5666 return bgp_vty_return(vty, ret);
5667 }
5668
5669 static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5670 safi_t safi)
5671 {
5672 int ret;
5673 struct peer *peer;
5674
5675 peer = peer_and_group_lookup_vty(vty, ip_str);
5676 if (!peer)
5677 return CMD_WARNING_CONFIG_FAILED;
5678
5679 ret = peer_weight_unset(peer, afi, safi);
5680 return bgp_vty_return(vty, ret);
5681 }
5682
5683 DEFUN (neighbor_weight,
5684 neighbor_weight_cmd,
5685 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
5686 NEIGHBOR_STR
5687 NEIGHBOR_ADDR_STR2
5688 "Set default weight for routes from this neighbor\n"
5689 "default weight\n")
5690 {
5691 int idx_peer = 1;
5692 int idx_number = 3;
5693 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5694 bgp_node_safi(vty), argv[idx_number]->arg);
5695 }
5696
5697 ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
5698 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
5699 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5700 "Set default weight for routes from this neighbor\n"
5701 "default weight\n")
5702
5703 DEFUN (no_neighbor_weight,
5704 no_neighbor_weight_cmd,
5705 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
5706 NO_STR
5707 NEIGHBOR_STR
5708 NEIGHBOR_ADDR_STR2
5709 "Set default weight for routes from this neighbor\n"
5710 "default weight\n")
5711 {
5712 int idx_peer = 2;
5713 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
5714 bgp_node_afi(vty), bgp_node_safi(vty));
5715 }
5716
5717 ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
5718 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
5719 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5720 "Set default weight for routes from this neighbor\n"
5721 "default weight\n")
5722
5723
5724 /* Override capability negotiation. */
5725 DEFUN (neighbor_override_capability,
5726 neighbor_override_capability_cmd,
5727 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
5728 NEIGHBOR_STR
5729 NEIGHBOR_ADDR_STR2
5730 "Override capability negotiation result\n")
5731 {
5732 int idx_peer = 1;
5733 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5734 PEER_FLAG_OVERRIDE_CAPABILITY);
5735 }
5736
5737 DEFUN (no_neighbor_override_capability,
5738 no_neighbor_override_capability_cmd,
5739 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
5740 NO_STR
5741 NEIGHBOR_STR
5742 NEIGHBOR_ADDR_STR2
5743 "Override capability negotiation result\n")
5744 {
5745 int idx_peer = 2;
5746 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5747 PEER_FLAG_OVERRIDE_CAPABILITY);
5748 }
5749
5750 DEFUN (neighbor_strict_capability,
5751 neighbor_strict_capability_cmd,
5752 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
5753 NEIGHBOR_STR
5754 NEIGHBOR_ADDR_STR2
5755 "Strict capability negotiation match\n")
5756 {
5757 int idx_peer = 1;
5758
5759 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5760 PEER_FLAG_STRICT_CAP_MATCH);
5761 }
5762
5763 DEFUN (no_neighbor_strict_capability,
5764 no_neighbor_strict_capability_cmd,
5765 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
5766 NO_STR
5767 NEIGHBOR_STR
5768 NEIGHBOR_ADDR_STR2
5769 "Strict capability negotiation match\n")
5770 {
5771 int idx_peer = 2;
5772
5773 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5774 PEER_FLAG_STRICT_CAP_MATCH);
5775 }
5776
5777 static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
5778 const char *keep_str, const char *hold_str)
5779 {
5780 int ret;
5781 struct peer *peer;
5782 uint32_t keepalive;
5783 uint32_t holdtime;
5784
5785 peer = peer_and_group_lookup_vty(vty, ip_str);
5786 if (!peer)
5787 return CMD_WARNING_CONFIG_FAILED;
5788
5789 keepalive = strtoul(keep_str, NULL, 10);
5790 holdtime = strtoul(hold_str, NULL, 10);
5791
5792 ret = peer_timers_set(peer, keepalive, holdtime);
5793
5794 return bgp_vty_return(vty, ret);
5795 }
5796
5797 static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
5798 {
5799 int ret;
5800 struct peer *peer;
5801
5802 peer = peer_and_group_lookup_vty(vty, ip_str);
5803 if (!peer)
5804 return CMD_WARNING_CONFIG_FAILED;
5805
5806 ret = peer_timers_unset(peer);
5807
5808 return bgp_vty_return(vty, ret);
5809 }
5810
5811 DEFUN (neighbor_timers,
5812 neighbor_timers_cmd,
5813 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
5814 NEIGHBOR_STR
5815 NEIGHBOR_ADDR_STR2
5816 "BGP per neighbor timers\n"
5817 "Keepalive interval\n"
5818 "Holdtime\n")
5819 {
5820 int idx_peer = 1;
5821 int idx_number = 3;
5822 int idx_number_2 = 4;
5823 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
5824 argv[idx_number]->arg,
5825 argv[idx_number_2]->arg);
5826 }
5827
5828 DEFUN (no_neighbor_timers,
5829 no_neighbor_timers_cmd,
5830 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
5831 NO_STR
5832 NEIGHBOR_STR
5833 NEIGHBOR_ADDR_STR2
5834 "BGP per neighbor timers\n"
5835 "Keepalive interval\n"
5836 "Holdtime\n")
5837 {
5838 int idx_peer = 2;
5839 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
5840 }
5841
5842
5843 static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
5844 const char *time_str)
5845 {
5846 int ret;
5847 struct peer *peer;
5848 uint32_t connect;
5849
5850 peer = peer_and_group_lookup_vty(vty, ip_str);
5851 if (!peer)
5852 return CMD_WARNING_CONFIG_FAILED;
5853
5854 connect = strtoul(time_str, NULL, 10);
5855
5856 ret = peer_timers_connect_set(peer, connect);
5857
5858 return bgp_vty_return(vty, ret);
5859 }
5860
5861 static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
5862 {
5863 int ret;
5864 struct peer *peer;
5865
5866 peer = peer_and_group_lookup_vty(vty, ip_str);
5867 if (!peer)
5868 return CMD_WARNING_CONFIG_FAILED;
5869
5870 ret = peer_timers_connect_unset(peer);
5871
5872 return bgp_vty_return(vty, ret);
5873 }
5874
5875 DEFUN (neighbor_timers_connect,
5876 neighbor_timers_connect_cmd,
5877 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
5878 NEIGHBOR_STR
5879 NEIGHBOR_ADDR_STR2
5880 "BGP per neighbor timers\n"
5881 "BGP connect timer\n"
5882 "Connect timer\n")
5883 {
5884 int idx_peer = 1;
5885 int idx_number = 4;
5886 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
5887 argv[idx_number]->arg);
5888 }
5889
5890 DEFUN (no_neighbor_timers_connect,
5891 no_neighbor_timers_connect_cmd,
5892 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
5893 NO_STR
5894 NEIGHBOR_STR
5895 NEIGHBOR_ADDR_STR2
5896 "BGP per neighbor timers\n"
5897 "BGP connect timer\n"
5898 "Connect timer\n")
5899 {
5900 int idx_peer = 2;
5901 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
5902 }
5903
5904
5905 static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
5906 const char *time_str, int set)
5907 {
5908 int ret;
5909 struct peer *peer;
5910 uint32_t routeadv = 0;
5911
5912 peer = peer_and_group_lookup_vty(vty, ip_str);
5913 if (!peer)
5914 return CMD_WARNING_CONFIG_FAILED;
5915
5916 if (time_str)
5917 routeadv = strtoul(time_str, NULL, 10);
5918
5919 if (set)
5920 ret = peer_advertise_interval_set(peer, routeadv);
5921 else
5922 ret = peer_advertise_interval_unset(peer);
5923
5924 return bgp_vty_return(vty, ret);
5925 }
5926
5927 DEFUN (neighbor_advertise_interval,
5928 neighbor_advertise_interval_cmd,
5929 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
5930 NEIGHBOR_STR
5931 NEIGHBOR_ADDR_STR2
5932 "Minimum interval between sending BGP routing updates\n"
5933 "time in seconds\n")
5934 {
5935 int idx_peer = 1;
5936 int idx_number = 3;
5937 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
5938 argv[idx_number]->arg, 1);
5939 }
5940
5941 DEFUN (no_neighbor_advertise_interval,
5942 no_neighbor_advertise_interval_cmd,
5943 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
5944 NO_STR
5945 NEIGHBOR_STR
5946 NEIGHBOR_ADDR_STR2
5947 "Minimum interval between sending BGP routing updates\n"
5948 "time in seconds\n")
5949 {
5950 int idx_peer = 2;
5951 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
5952 }
5953
5954
5955 /* Time to wait before processing route-map updates */
5956 DEFUN (bgp_set_route_map_delay_timer,
5957 bgp_set_route_map_delay_timer_cmd,
5958 "bgp route-map delay-timer (0-600)",
5959 SET_STR
5960 "BGP route-map delay timer\n"
5961 "Time in secs to wait before processing route-map changes\n"
5962 "0 disables the timer, no route updates happen when route-maps change\n")
5963 {
5964 int idx_number = 3;
5965 uint32_t rmap_delay_timer;
5966
5967 if (argv[idx_number]->arg) {
5968 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
5969 bm->rmap_update_timer = rmap_delay_timer;
5970
5971 /* if the dynamic update handling is being disabled, and a timer
5972 * is
5973 * running, stop the timer and act as if the timer has already
5974 * fired.
5975 */
5976 if (!rmap_delay_timer && bm->t_rmap_update) {
5977 BGP_TIMER_OFF(bm->t_rmap_update);
5978 thread_execute(bm->master, bgp_route_map_update_timer,
5979 NULL, 0);
5980 }
5981 return CMD_SUCCESS;
5982 } else {
5983 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
5984 return CMD_WARNING_CONFIG_FAILED;
5985 }
5986 }
5987
5988 DEFUN (no_bgp_set_route_map_delay_timer,
5989 no_bgp_set_route_map_delay_timer_cmd,
5990 "no bgp route-map delay-timer [(0-600)]",
5991 NO_STR
5992 BGP_STR
5993 "Default BGP route-map delay timer\n"
5994 "Reset to default time to wait for processing route-map changes\n"
5995 "0 disables the timer, no route updates happen when route-maps change\n")
5996 {
5997
5998 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
5999
6000 return CMD_SUCCESS;
6001 }
6002
6003
6004 /* neighbor interface */
6005 static int peer_interface_vty(struct vty *vty, const char *ip_str,
6006 const char *str)
6007 {
6008 struct peer *peer;
6009
6010 peer = peer_lookup_vty(vty, ip_str);
6011 if (!peer || peer->conf_if) {
6012 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
6013 return CMD_WARNING_CONFIG_FAILED;
6014 }
6015
6016 if (str)
6017 peer_interface_set(peer, str);
6018 else
6019 peer_interface_unset(peer);
6020
6021 return CMD_SUCCESS;
6022 }
6023
6024 DEFUN (neighbor_interface,
6025 neighbor_interface_cmd,
6026 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
6027 NEIGHBOR_STR
6028 NEIGHBOR_ADDR_STR
6029 "Interface\n"
6030 "Interface name\n")
6031 {
6032 int idx_ip = 1;
6033 int idx_word = 3;
6034 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
6035 }
6036
6037 DEFUN (no_neighbor_interface,
6038 no_neighbor_interface_cmd,
6039 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
6040 NO_STR
6041 NEIGHBOR_STR
6042 NEIGHBOR_ADDR_STR2
6043 "Interface\n"
6044 "Interface name\n")
6045 {
6046 int idx_peer = 2;
6047 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
6048 }
6049
6050 DEFUN (neighbor_distribute_list,
6051 neighbor_distribute_list_cmd,
6052 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
6053 NEIGHBOR_STR
6054 NEIGHBOR_ADDR_STR2
6055 "Filter updates to/from this neighbor\n"
6056 "IP access-list number\n"
6057 "IP access-list number (expanded range)\n"
6058 "IP Access-list name\n"
6059 "Filter incoming updates\n"
6060 "Filter outgoing updates\n")
6061 {
6062 int idx_peer = 1;
6063 int idx_acl = 3;
6064 int direct, ret;
6065 struct peer *peer;
6066
6067 const char *pstr = argv[idx_peer]->arg;
6068 const char *acl = argv[idx_acl]->arg;
6069 const char *inout = argv[argc - 1]->text;
6070
6071 peer = peer_and_group_lookup_vty(vty, pstr);
6072 if (!peer)
6073 return CMD_WARNING_CONFIG_FAILED;
6074
6075 /* Check filter direction. */
6076 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
6077 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6078 direct, acl);
6079
6080 return bgp_vty_return(vty, ret);
6081 }
6082
6083 ALIAS_HIDDEN(
6084 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
6085 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
6086 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6087 "Filter updates to/from this neighbor\n"
6088 "IP access-list number\n"
6089 "IP access-list number (expanded range)\n"
6090 "IP Access-list name\n"
6091 "Filter incoming updates\n"
6092 "Filter outgoing updates\n")
6093
6094 DEFUN (no_neighbor_distribute_list,
6095 no_neighbor_distribute_list_cmd,
6096 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
6097 NO_STR
6098 NEIGHBOR_STR
6099 NEIGHBOR_ADDR_STR2
6100 "Filter updates to/from this neighbor\n"
6101 "IP access-list number\n"
6102 "IP access-list number (expanded range)\n"
6103 "IP Access-list name\n"
6104 "Filter incoming updates\n"
6105 "Filter outgoing updates\n")
6106 {
6107 int idx_peer = 2;
6108 int direct, ret;
6109 struct peer *peer;
6110
6111 const char *pstr = argv[idx_peer]->arg;
6112 const char *inout = argv[argc - 1]->text;
6113
6114 peer = peer_and_group_lookup_vty(vty, pstr);
6115 if (!peer)
6116 return CMD_WARNING_CONFIG_FAILED;
6117
6118 /* Check filter direction. */
6119 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
6120 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6121 direct);
6122
6123 return bgp_vty_return(vty, ret);
6124 }
6125
6126 ALIAS_HIDDEN(
6127 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
6128 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
6129 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6130 "Filter updates to/from this neighbor\n"
6131 "IP access-list number\n"
6132 "IP access-list number (expanded range)\n"
6133 "IP Access-list name\n"
6134 "Filter incoming updates\n"
6135 "Filter outgoing updates\n")
6136
6137 /* Set prefix list to the peer. */
6138 static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
6139 afi_t afi, safi_t safi,
6140 const char *name_str,
6141 const char *direct_str)
6142 {
6143 int ret;
6144 int direct = FILTER_IN;
6145 struct peer *peer;
6146
6147 peer = peer_and_group_lookup_vty(vty, ip_str);
6148 if (!peer)
6149 return CMD_WARNING_CONFIG_FAILED;
6150
6151 /* Check filter direction. */
6152 if (strncmp(direct_str, "i", 1) == 0)
6153 direct = FILTER_IN;
6154 else if (strncmp(direct_str, "o", 1) == 0)
6155 direct = FILTER_OUT;
6156
6157 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
6158
6159 return bgp_vty_return(vty, ret);
6160 }
6161
6162 static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
6163 afi_t afi, safi_t safi,
6164 const char *direct_str)
6165 {
6166 int ret;
6167 struct peer *peer;
6168 int direct = FILTER_IN;
6169
6170 peer = peer_and_group_lookup_vty(vty, ip_str);
6171 if (!peer)
6172 return CMD_WARNING_CONFIG_FAILED;
6173
6174 /* Check filter direction. */
6175 if (strncmp(direct_str, "i", 1) == 0)
6176 direct = FILTER_IN;
6177 else if (strncmp(direct_str, "o", 1) == 0)
6178 direct = FILTER_OUT;
6179
6180 ret = peer_prefix_list_unset(peer, afi, safi, direct);
6181
6182 return bgp_vty_return(vty, ret);
6183 }
6184
6185 DEFUN (neighbor_prefix_list,
6186 neighbor_prefix_list_cmd,
6187 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
6188 NEIGHBOR_STR
6189 NEIGHBOR_ADDR_STR2
6190 "Filter updates to/from this neighbor\n"
6191 "Name of a prefix list\n"
6192 "Filter incoming updates\n"
6193 "Filter outgoing updates\n")
6194 {
6195 int idx_peer = 1;
6196 int idx_word = 3;
6197 int idx_in_out = 4;
6198 return peer_prefix_list_set_vty(
6199 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6200 argv[idx_word]->arg, argv[idx_in_out]->arg);
6201 }
6202
6203 ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
6204 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
6205 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6206 "Filter updates to/from this neighbor\n"
6207 "Name of a prefix list\n"
6208 "Filter incoming updates\n"
6209 "Filter outgoing updates\n")
6210
6211 DEFUN (no_neighbor_prefix_list,
6212 no_neighbor_prefix_list_cmd,
6213 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
6214 NO_STR
6215 NEIGHBOR_STR
6216 NEIGHBOR_ADDR_STR2
6217 "Filter updates to/from this neighbor\n"
6218 "Name of a prefix list\n"
6219 "Filter incoming updates\n"
6220 "Filter outgoing updates\n")
6221 {
6222 int idx_peer = 2;
6223 int idx_in_out = 5;
6224 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
6225 bgp_node_afi(vty), bgp_node_safi(vty),
6226 argv[idx_in_out]->arg);
6227 }
6228
6229 ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
6230 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
6231 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6232 "Filter updates to/from this neighbor\n"
6233 "Name of a prefix list\n"
6234 "Filter incoming updates\n"
6235 "Filter outgoing updates\n")
6236
6237 static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
6238 safi_t safi, const char *name_str,
6239 const char *direct_str)
6240 {
6241 int ret;
6242 struct peer *peer;
6243 int direct = FILTER_IN;
6244
6245 peer = peer_and_group_lookup_vty(vty, ip_str);
6246 if (!peer)
6247 return CMD_WARNING_CONFIG_FAILED;
6248
6249 /* Check filter direction. */
6250 if (strncmp(direct_str, "i", 1) == 0)
6251 direct = FILTER_IN;
6252 else if (strncmp(direct_str, "o", 1) == 0)
6253 direct = FILTER_OUT;
6254
6255 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
6256
6257 return bgp_vty_return(vty, ret);
6258 }
6259
6260 static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
6261 safi_t safi, const char *direct_str)
6262 {
6263 int ret;
6264 struct peer *peer;
6265 int direct = FILTER_IN;
6266
6267 peer = peer_and_group_lookup_vty(vty, ip_str);
6268 if (!peer)
6269 return CMD_WARNING_CONFIG_FAILED;
6270
6271 /* Check filter direction. */
6272 if (strncmp(direct_str, "i", 1) == 0)
6273 direct = FILTER_IN;
6274 else if (strncmp(direct_str, "o", 1) == 0)
6275 direct = FILTER_OUT;
6276
6277 ret = peer_aslist_unset(peer, afi, safi, direct);
6278
6279 return bgp_vty_return(vty, ret);
6280 }
6281
6282 DEFUN (neighbor_filter_list,
6283 neighbor_filter_list_cmd,
6284 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
6285 NEIGHBOR_STR
6286 NEIGHBOR_ADDR_STR2
6287 "Establish BGP filters\n"
6288 "AS path access-list name\n"
6289 "Filter incoming routes\n"
6290 "Filter outgoing routes\n")
6291 {
6292 int idx_peer = 1;
6293 int idx_word = 3;
6294 int idx_in_out = 4;
6295 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6296 bgp_node_safi(vty), argv[idx_word]->arg,
6297 argv[idx_in_out]->arg);
6298 }
6299
6300 ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
6301 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
6302 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6303 "Establish BGP filters\n"
6304 "AS path access-list name\n"
6305 "Filter incoming routes\n"
6306 "Filter outgoing routes\n")
6307
6308 DEFUN (no_neighbor_filter_list,
6309 no_neighbor_filter_list_cmd,
6310 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
6311 NO_STR
6312 NEIGHBOR_STR
6313 NEIGHBOR_ADDR_STR2
6314 "Establish BGP filters\n"
6315 "AS path access-list name\n"
6316 "Filter incoming routes\n"
6317 "Filter outgoing routes\n")
6318 {
6319 int idx_peer = 2;
6320 int idx_in_out = 5;
6321 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
6322 bgp_node_afi(vty), bgp_node_safi(vty),
6323 argv[idx_in_out]->arg);
6324 }
6325
6326 ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
6327 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
6328 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6329 "Establish BGP filters\n"
6330 "AS path access-list name\n"
6331 "Filter incoming routes\n"
6332 "Filter outgoing routes\n")
6333
6334 /* Set route-map to the peer. */
6335 static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
6336 afi_t afi, safi_t safi, const char *name_str,
6337 const char *direct_str)
6338 {
6339 int ret;
6340 struct peer *peer;
6341 int direct = RMAP_IN;
6342 struct route_map *route_map;
6343
6344 peer = peer_and_group_lookup_vty(vty, ip_str);
6345 if (!peer)
6346 return CMD_WARNING_CONFIG_FAILED;
6347
6348 /* Check filter direction. */
6349 if (strncmp(direct_str, "in", 2) == 0)
6350 direct = RMAP_IN;
6351 else if (strncmp(direct_str, "o", 1) == 0)
6352 direct = RMAP_OUT;
6353
6354 route_map = route_map_lookup_warn_noexist(vty, name_str);
6355 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
6356
6357 return bgp_vty_return(vty, ret);
6358 }
6359
6360 static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
6361 afi_t afi, safi_t safi,
6362 const char *direct_str)
6363 {
6364 int ret;
6365 struct peer *peer;
6366 int direct = RMAP_IN;
6367
6368 peer = peer_and_group_lookup_vty(vty, ip_str);
6369 if (!peer)
6370 return CMD_WARNING_CONFIG_FAILED;
6371
6372 /* Check filter direction. */
6373 if (strncmp(direct_str, "in", 2) == 0)
6374 direct = RMAP_IN;
6375 else if (strncmp(direct_str, "o", 1) == 0)
6376 direct = RMAP_OUT;
6377
6378 ret = peer_route_map_unset(peer, afi, safi, direct);
6379
6380 return bgp_vty_return(vty, ret);
6381 }
6382
6383 DEFUN (neighbor_route_map,
6384 neighbor_route_map_cmd,
6385 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
6386 NEIGHBOR_STR
6387 NEIGHBOR_ADDR_STR2
6388 "Apply route map to neighbor\n"
6389 "Name of route map\n"
6390 "Apply map to incoming routes\n"
6391 "Apply map to outbound routes\n")
6392 {
6393 int idx_peer = 1;
6394 int idx_word = 3;
6395 int idx_in_out = 4;
6396 return peer_route_map_set_vty(
6397 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6398 argv[idx_word]->arg, argv[idx_in_out]->arg);
6399 }
6400
6401 ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
6402 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
6403 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6404 "Apply route map to neighbor\n"
6405 "Name of route map\n"
6406 "Apply map to incoming routes\n"
6407 "Apply map to outbound routes\n")
6408
6409 DEFUN (no_neighbor_route_map,
6410 no_neighbor_route_map_cmd,
6411 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
6412 NO_STR
6413 NEIGHBOR_STR
6414 NEIGHBOR_ADDR_STR2
6415 "Apply route map to neighbor\n"
6416 "Name of route map\n"
6417 "Apply map to incoming routes\n"
6418 "Apply map to outbound routes\n")
6419 {
6420 int idx_peer = 2;
6421 int idx_in_out = 5;
6422 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
6423 bgp_node_afi(vty), bgp_node_safi(vty),
6424 argv[idx_in_out]->arg);
6425 }
6426
6427 ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
6428 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
6429 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6430 "Apply route map to neighbor\n"
6431 "Name of route map\n"
6432 "Apply map to incoming routes\n"
6433 "Apply map to outbound routes\n")
6434
6435 /* Set unsuppress-map to the peer. */
6436 static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
6437 afi_t afi, safi_t safi,
6438 const char *name_str)
6439 {
6440 int ret;
6441 struct peer *peer;
6442 struct route_map *route_map;
6443
6444 peer = peer_and_group_lookup_vty(vty, ip_str);
6445 if (!peer)
6446 return CMD_WARNING_CONFIG_FAILED;
6447
6448 route_map = route_map_lookup_warn_noexist(vty, name_str);
6449 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
6450
6451 return bgp_vty_return(vty, ret);
6452 }
6453
6454 /* Unset route-map from the peer. */
6455 static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
6456 afi_t afi, safi_t safi)
6457 {
6458 int ret;
6459 struct peer *peer;
6460
6461 peer = peer_and_group_lookup_vty(vty, ip_str);
6462 if (!peer)
6463 return CMD_WARNING_CONFIG_FAILED;
6464
6465 ret = peer_unsuppress_map_unset(peer, afi, safi);
6466
6467 return bgp_vty_return(vty, ret);
6468 }
6469
6470 DEFUN (neighbor_unsuppress_map,
6471 neighbor_unsuppress_map_cmd,
6472 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
6473 NEIGHBOR_STR
6474 NEIGHBOR_ADDR_STR2
6475 "Route-map to selectively unsuppress suppressed routes\n"
6476 "Name of route map\n")
6477 {
6478 int idx_peer = 1;
6479 int idx_word = 3;
6480 return peer_unsuppress_map_set_vty(
6481 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6482 argv[idx_word]->arg);
6483 }
6484
6485 ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
6486 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
6487 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6488 "Route-map to selectively unsuppress suppressed routes\n"
6489 "Name of route map\n")
6490
6491 DEFUN (no_neighbor_unsuppress_map,
6492 no_neighbor_unsuppress_map_cmd,
6493 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
6494 NO_STR
6495 NEIGHBOR_STR
6496 NEIGHBOR_ADDR_STR2
6497 "Route-map to selectively unsuppress suppressed routes\n"
6498 "Name of route map\n")
6499 {
6500 int idx_peer = 2;
6501 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
6502 bgp_node_afi(vty),
6503 bgp_node_safi(vty));
6504 }
6505
6506 ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
6507 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
6508 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6509 "Route-map to selectively unsuppress suppressed routes\n"
6510 "Name of route map\n")
6511
6512 static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
6513 afi_t afi, safi_t safi,
6514 const char *num_str,
6515 const char *threshold_str, int warning,
6516 const char *restart_str)
6517 {
6518 int ret;
6519 struct peer *peer;
6520 uint32_t max;
6521 uint8_t threshold;
6522 uint16_t restart;
6523
6524 peer = peer_and_group_lookup_vty(vty, ip_str);
6525 if (!peer)
6526 return CMD_WARNING_CONFIG_FAILED;
6527
6528 max = strtoul(num_str, NULL, 10);
6529 if (threshold_str)
6530 threshold = atoi(threshold_str);
6531 else
6532 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
6533
6534 if (restart_str)
6535 restart = atoi(restart_str);
6536 else
6537 restart = 0;
6538
6539 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
6540 restart);
6541
6542 return bgp_vty_return(vty, ret);
6543 }
6544
6545 static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
6546 afi_t afi, safi_t safi)
6547 {
6548 int ret;
6549 struct peer *peer;
6550
6551 peer = peer_and_group_lookup_vty(vty, ip_str);
6552 if (!peer)
6553 return CMD_WARNING_CONFIG_FAILED;
6554
6555 ret = peer_maximum_prefix_unset(peer, afi, safi);
6556
6557 return bgp_vty_return(vty, ret);
6558 }
6559
6560 /* Maximum number of prefix to be sent to the neighbor. */
6561 DEFUN(neighbor_maximum_prefix_out,
6562 neighbor_maximum_prefix_out_cmd,
6563 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out (1-4294967295)",
6564 NEIGHBOR_STR
6565 NEIGHBOR_ADDR_STR2
6566 "Maximum number of prefixes to be sent to this peer\n"
6567 "Maximum no. of prefix limit\n")
6568 {
6569 int idx_peer = 1;
6570 int idx_number = 3;
6571 struct peer *peer;
6572 uint32_t max;
6573 afi_t afi = bgp_node_afi(vty);
6574 safi_t safi = bgp_node_safi(vty);
6575
6576 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6577 if (!peer)
6578 return CMD_WARNING_CONFIG_FAILED;
6579
6580 max = strtoul(argv[idx_number]->arg, NULL, 10);
6581
6582 SET_FLAG(peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT);
6583 peer->pmax_out[afi][safi] = max;
6584
6585 return CMD_SUCCESS;
6586 }
6587
6588 DEFUN(no_neighbor_maximum_prefix_out,
6589 no_neighbor_maximum_prefix_out_cmd,
6590 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out",
6591 NO_STR
6592 NEIGHBOR_STR
6593 NEIGHBOR_ADDR_STR2
6594 "Maximum number of prefixes to be sent to this peer\n")
6595 {
6596 int idx_peer = 2;
6597 struct peer *peer;
6598 afi_t afi = bgp_node_afi(vty);
6599 safi_t safi = bgp_node_safi(vty);
6600
6601 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6602 if (!peer)
6603 return CMD_WARNING_CONFIG_FAILED;
6604
6605 peer->pmax_out[afi][safi] = 0;
6606
6607 return CMD_SUCCESS;
6608 }
6609
6610 /* Maximum number of prefix configuration. prefix count is different
6611 for each peer configuration. So this configuration can be set for
6612 each peer configuration. */
6613 DEFUN (neighbor_maximum_prefix,
6614 neighbor_maximum_prefix_cmd,
6615 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
6616 NEIGHBOR_STR
6617 NEIGHBOR_ADDR_STR2
6618 "Maximum number of prefix accept from this peer\n"
6619 "maximum no. of prefix limit\n")
6620 {
6621 int idx_peer = 1;
6622 int idx_number = 3;
6623 return peer_maximum_prefix_set_vty(
6624 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6625 argv[idx_number]->arg, NULL, 0, NULL);
6626 }
6627
6628 ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
6629 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
6630 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6631 "Maximum number of prefix accept from this peer\n"
6632 "maximum no. of prefix limit\n")
6633
6634 DEFUN (neighbor_maximum_prefix_threshold,
6635 neighbor_maximum_prefix_threshold_cmd,
6636 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
6637 NEIGHBOR_STR
6638 NEIGHBOR_ADDR_STR2
6639 "Maximum number of prefix accept from this peer\n"
6640 "maximum no. of prefix limit\n"
6641 "Threshold value (%) at which to generate a warning msg\n")
6642 {
6643 int idx_peer = 1;
6644 int idx_number = 3;
6645 int idx_number_2 = 4;
6646 return peer_maximum_prefix_set_vty(
6647 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6648 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL);
6649 }
6650
6651 ALIAS_HIDDEN(
6652 neighbor_maximum_prefix_threshold,
6653 neighbor_maximum_prefix_threshold_hidden_cmd,
6654 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
6655 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6656 "Maximum number of prefix accept from this peer\n"
6657 "maximum no. of prefix limit\n"
6658 "Threshold value (%) at which to generate a warning msg\n")
6659
6660 DEFUN (neighbor_maximum_prefix_warning,
6661 neighbor_maximum_prefix_warning_cmd,
6662 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
6663 NEIGHBOR_STR
6664 NEIGHBOR_ADDR_STR2
6665 "Maximum number of prefix accept from this peer\n"
6666 "maximum no. of prefix limit\n"
6667 "Only give warning message when limit is exceeded\n")
6668 {
6669 int idx_peer = 1;
6670 int idx_number = 3;
6671 return peer_maximum_prefix_set_vty(
6672 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6673 argv[idx_number]->arg, NULL, 1, NULL);
6674 }
6675
6676 ALIAS_HIDDEN(
6677 neighbor_maximum_prefix_warning,
6678 neighbor_maximum_prefix_warning_hidden_cmd,
6679 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
6680 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6681 "Maximum number of prefix accept from this peer\n"
6682 "maximum no. of prefix limit\n"
6683 "Only give warning message when limit is exceeded\n")
6684
6685 DEFUN (neighbor_maximum_prefix_threshold_warning,
6686 neighbor_maximum_prefix_threshold_warning_cmd,
6687 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
6688 NEIGHBOR_STR
6689 NEIGHBOR_ADDR_STR2
6690 "Maximum number of prefix accept from this peer\n"
6691 "maximum no. of prefix limit\n"
6692 "Threshold value (%) at which to generate a warning msg\n"
6693 "Only give warning message when limit is exceeded\n")
6694 {
6695 int idx_peer = 1;
6696 int idx_number = 3;
6697 int idx_number_2 = 4;
6698 return peer_maximum_prefix_set_vty(
6699 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6700 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL);
6701 }
6702
6703 ALIAS_HIDDEN(
6704 neighbor_maximum_prefix_threshold_warning,
6705 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
6706 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
6707 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6708 "Maximum number of prefix accept from this peer\n"
6709 "maximum no. of prefix limit\n"
6710 "Threshold value (%) at which to generate a warning msg\n"
6711 "Only give warning message when limit is exceeded\n")
6712
6713 DEFUN (neighbor_maximum_prefix_restart,
6714 neighbor_maximum_prefix_restart_cmd,
6715 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
6716 NEIGHBOR_STR
6717 NEIGHBOR_ADDR_STR2
6718 "Maximum number of prefix accept from this peer\n"
6719 "maximum no. of prefix limit\n"
6720 "Restart bgp connection after limit is exceeded\n"
6721 "Restart interval in minutes\n")
6722 {
6723 int idx_peer = 1;
6724 int idx_number = 3;
6725 int idx_number_2 = 5;
6726 return peer_maximum_prefix_set_vty(
6727 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6728 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg);
6729 }
6730
6731 ALIAS_HIDDEN(
6732 neighbor_maximum_prefix_restart,
6733 neighbor_maximum_prefix_restart_hidden_cmd,
6734 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
6735 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6736 "Maximum number of prefix accept from this peer\n"
6737 "maximum no. of prefix limit\n"
6738 "Restart bgp connection after limit is exceeded\n"
6739 "Restart interval in minutes\n")
6740
6741 DEFUN (neighbor_maximum_prefix_threshold_restart,
6742 neighbor_maximum_prefix_threshold_restart_cmd,
6743 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
6744 NEIGHBOR_STR
6745 NEIGHBOR_ADDR_STR2
6746 "Maximum number of prefixes to accept from this peer\n"
6747 "maximum no. of prefix limit\n"
6748 "Threshold value (%) at which to generate a warning msg\n"
6749 "Restart bgp connection after limit is exceeded\n"
6750 "Restart interval in minutes\n")
6751 {
6752 int idx_peer = 1;
6753 int idx_number = 3;
6754 int idx_number_2 = 4;
6755 int idx_number_3 = 6;
6756 return peer_maximum_prefix_set_vty(
6757 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6758 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
6759 argv[idx_number_3]->arg);
6760 }
6761
6762 ALIAS_HIDDEN(
6763 neighbor_maximum_prefix_threshold_restart,
6764 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
6765 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
6766 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6767 "Maximum number of prefixes to accept from this peer\n"
6768 "maximum no. of prefix limit\n"
6769 "Threshold value (%) at which to generate a warning msg\n"
6770 "Restart bgp connection after limit is exceeded\n"
6771 "Restart interval in minutes\n")
6772
6773 DEFUN (no_neighbor_maximum_prefix,
6774 no_neighbor_maximum_prefix_cmd,
6775 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
6776 NO_STR
6777 NEIGHBOR_STR
6778 NEIGHBOR_ADDR_STR2
6779 "Maximum number of prefixes to accept from this peer\n"
6780 "maximum no. of prefix limit\n"
6781 "Threshold value (%) at which to generate a warning msg\n"
6782 "Restart bgp connection after limit is exceeded\n"
6783 "Restart interval in minutes\n"
6784 "Only give warning message when limit is exceeded\n")
6785 {
6786 int idx_peer = 2;
6787 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
6788 bgp_node_afi(vty),
6789 bgp_node_safi(vty));
6790 }
6791
6792 ALIAS_HIDDEN(
6793 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
6794 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
6795 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6796 "Maximum number of prefixes to accept from this peer\n"
6797 "maximum no. of prefix limit\n"
6798 "Threshold value (%) at which to generate a warning msg\n"
6799 "Restart bgp connection after limit is exceeded\n"
6800 "Restart interval in minutes\n"
6801 "Only give warning message when limit is exceeded\n")
6802
6803
6804 /* "neighbor allowas-in" */
6805 DEFUN (neighbor_allowas_in,
6806 neighbor_allowas_in_cmd,
6807 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6808 NEIGHBOR_STR
6809 NEIGHBOR_ADDR_STR2
6810 "Accept as-path with my AS present in it\n"
6811 "Number of occurrences of AS number\n"
6812 "Only accept my AS in the as-path if the route was originated in my AS\n")
6813 {
6814 int idx_peer = 1;
6815 int idx_number_origin = 3;
6816 int ret;
6817 int origin = 0;
6818 struct peer *peer;
6819 int allow_num = 0;
6820
6821 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6822 if (!peer)
6823 return CMD_WARNING_CONFIG_FAILED;
6824
6825 if (argc <= idx_number_origin)
6826 allow_num = 3;
6827 else {
6828 if (argv[idx_number_origin]->type == WORD_TKN)
6829 origin = 1;
6830 else
6831 allow_num = atoi(argv[idx_number_origin]->arg);
6832 }
6833
6834 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6835 allow_num, origin);
6836
6837 return bgp_vty_return(vty, ret);
6838 }
6839
6840 ALIAS_HIDDEN(
6841 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
6842 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6843 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6844 "Accept as-path with my AS present in it\n"
6845 "Number of occurrences of AS number\n"
6846 "Only accept my AS in the as-path if the route was originated in my AS\n")
6847
6848 DEFUN (no_neighbor_allowas_in,
6849 no_neighbor_allowas_in_cmd,
6850 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6851 NO_STR
6852 NEIGHBOR_STR
6853 NEIGHBOR_ADDR_STR2
6854 "allow local ASN appears in aspath attribute\n"
6855 "Number of occurrences of AS number\n"
6856 "Only accept my AS in the as-path if the route was originated in my AS\n")
6857 {
6858 int idx_peer = 2;
6859 int ret;
6860 struct peer *peer;
6861
6862 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6863 if (!peer)
6864 return CMD_WARNING_CONFIG_FAILED;
6865
6866 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
6867 bgp_node_safi(vty));
6868
6869 return bgp_vty_return(vty, ret);
6870 }
6871
6872 ALIAS_HIDDEN(
6873 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
6874 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6875 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6876 "allow local ASN appears in aspath attribute\n"
6877 "Number of occurrences of AS number\n"
6878 "Only accept my AS in the as-path if the route was originated in my AS\n")
6879
6880 DEFUN (neighbor_ttl_security,
6881 neighbor_ttl_security_cmd,
6882 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
6883 NEIGHBOR_STR
6884 NEIGHBOR_ADDR_STR2
6885 "BGP ttl-security parameters\n"
6886 "Specify the maximum number of hops to the BGP peer\n"
6887 "Number of hops to BGP peer\n")
6888 {
6889 int idx_peer = 1;
6890 int idx_number = 4;
6891 struct peer *peer;
6892 int gtsm_hops;
6893
6894 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6895 if (!peer)
6896 return CMD_WARNING_CONFIG_FAILED;
6897
6898 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
6899
6900 /*
6901 * If 'neighbor swpX', then this is for directly connected peers,
6902 * we should not accept a ttl-security hops value greater than 1.
6903 */
6904 if (peer->conf_if && (gtsm_hops > BGP_GTSM_HOPS_CONNECTED)) {
6905 vty_out(vty,
6906 "%s is directly connected peer, hops cannot exceed 1\n",
6907 argv[idx_peer]->arg);
6908 return CMD_WARNING_CONFIG_FAILED;
6909 }
6910
6911 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
6912 }
6913
6914 DEFUN (no_neighbor_ttl_security,
6915 no_neighbor_ttl_security_cmd,
6916 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
6917 NO_STR
6918 NEIGHBOR_STR
6919 NEIGHBOR_ADDR_STR2
6920 "BGP ttl-security parameters\n"
6921 "Specify the maximum number of hops to the BGP peer\n"
6922 "Number of hops to BGP peer\n")
6923 {
6924 int idx_peer = 2;
6925 struct peer *peer;
6926
6927 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6928 if (!peer)
6929 return CMD_WARNING_CONFIG_FAILED;
6930
6931 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
6932 }
6933
6934 DEFUN (neighbor_addpath_tx_all_paths,
6935 neighbor_addpath_tx_all_paths_cmd,
6936 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6937 NEIGHBOR_STR
6938 NEIGHBOR_ADDR_STR2
6939 "Use addpath to advertise all paths to a neighbor\n")
6940 {
6941 int idx_peer = 1;
6942 struct peer *peer;
6943
6944 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6945 if (!peer)
6946 return CMD_WARNING_CONFIG_FAILED;
6947
6948 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6949 BGP_ADDPATH_ALL);
6950 return CMD_SUCCESS;
6951 }
6952
6953 ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
6954 neighbor_addpath_tx_all_paths_hidden_cmd,
6955 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6956 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6957 "Use addpath to advertise all paths to a neighbor\n")
6958
6959 DEFUN (no_neighbor_addpath_tx_all_paths,
6960 no_neighbor_addpath_tx_all_paths_cmd,
6961 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6962 NO_STR
6963 NEIGHBOR_STR
6964 NEIGHBOR_ADDR_STR2
6965 "Use addpath to advertise all paths to a neighbor\n")
6966 {
6967 int idx_peer = 2;
6968 struct peer *peer;
6969
6970 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6971 if (!peer)
6972 return CMD_WARNING_CONFIG_FAILED;
6973
6974 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
6975 != BGP_ADDPATH_ALL) {
6976 vty_out(vty,
6977 "%% Peer not currently configured to transmit all paths.");
6978 return CMD_WARNING_CONFIG_FAILED;
6979 }
6980
6981 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6982 BGP_ADDPATH_NONE);
6983
6984 return CMD_SUCCESS;
6985 }
6986
6987 ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
6988 no_neighbor_addpath_tx_all_paths_hidden_cmd,
6989 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6990 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6991 "Use addpath to advertise all paths to a neighbor\n")
6992
6993 DEFUN (neighbor_addpath_tx_bestpath_per_as,
6994 neighbor_addpath_tx_bestpath_per_as_cmd,
6995 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6996 NEIGHBOR_STR
6997 NEIGHBOR_ADDR_STR2
6998 "Use addpath to advertise the bestpath per each neighboring AS\n")
6999 {
7000 int idx_peer = 1;
7001 struct peer *peer;
7002
7003 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7004 if (!peer)
7005 return CMD_WARNING_CONFIG_FAILED;
7006
7007 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7008 BGP_ADDPATH_BEST_PER_AS);
7009
7010 return CMD_SUCCESS;
7011 }
7012
7013 ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
7014 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
7015 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
7016 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7017 "Use addpath to advertise the bestpath per each neighboring AS\n")
7018
7019 DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
7020 no_neighbor_addpath_tx_bestpath_per_as_cmd,
7021 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
7022 NO_STR
7023 NEIGHBOR_STR
7024 NEIGHBOR_ADDR_STR2
7025 "Use addpath to advertise the bestpath per each neighboring AS\n")
7026 {
7027 int idx_peer = 2;
7028 struct peer *peer;
7029
7030 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7031 if (!peer)
7032 return CMD_WARNING_CONFIG_FAILED;
7033
7034 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
7035 != BGP_ADDPATH_BEST_PER_AS) {
7036 vty_out(vty,
7037 "%% Peer not currently configured to transmit all best path per as.");
7038 return CMD_WARNING_CONFIG_FAILED;
7039 }
7040
7041 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7042 BGP_ADDPATH_NONE);
7043
7044 return CMD_SUCCESS;
7045 }
7046
7047 ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
7048 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
7049 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
7050 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7051 "Use addpath to advertise the bestpath per each neighboring AS\n")
7052
7053 DEFPY(
7054 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
7055 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
7056 NEIGHBOR_STR
7057 NEIGHBOR_ADDR_STR2
7058 "Detect AS loops before sending to neighbor\n")
7059 {
7060 struct peer *peer;
7061
7062 peer = peer_and_group_lookup_vty(vty, neighbor);
7063 if (!peer)
7064 return CMD_WARNING_CONFIG_FAILED;
7065
7066 peer->as_path_loop_detection = true;
7067
7068 return CMD_SUCCESS;
7069 }
7070
7071 DEFPY(
7072 no_neighbor_aspath_loop_detection,
7073 no_neighbor_aspath_loop_detection_cmd,
7074 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
7075 NO_STR
7076 NEIGHBOR_STR
7077 NEIGHBOR_ADDR_STR2
7078 "Detect AS loops before sending to neighbor\n")
7079 {
7080 struct peer *peer;
7081
7082 peer = peer_and_group_lookup_vty(vty, neighbor);
7083 if (!peer)
7084 return CMD_WARNING_CONFIG_FAILED;
7085
7086 peer->as_path_loop_detection = false;
7087
7088 return CMD_SUCCESS;
7089 }
7090
7091 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
7092 struct ecommunity **list)
7093 {
7094 struct ecommunity *ecom = NULL;
7095 struct ecommunity *ecomadd;
7096
7097 for (; argc; --argc, ++argv) {
7098
7099 ecomadd = ecommunity_str2com(argv[0]->arg,
7100 ECOMMUNITY_ROUTE_TARGET, 0);
7101 if (!ecomadd) {
7102 vty_out(vty, "Malformed community-list value\n");
7103 if (ecom)
7104 ecommunity_free(&ecom);
7105 return CMD_WARNING_CONFIG_FAILED;
7106 }
7107
7108 if (ecom) {
7109 ecommunity_merge(ecom, ecomadd);
7110 ecommunity_free(&ecomadd);
7111 } else {
7112 ecom = ecomadd;
7113 }
7114 }
7115
7116 if (*list) {
7117 ecommunity_free(&*list);
7118 }
7119 *list = ecom;
7120
7121 return CMD_SUCCESS;
7122 }
7123
7124 /*
7125 * v2vimport is true if we are handling a `import vrf ...` command
7126 */
7127 static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
7128 {
7129 afi_t afi;
7130
7131 switch (vty->node) {
7132 case BGP_IPV4_NODE:
7133 afi = AFI_IP;
7134 break;
7135 case BGP_IPV6_NODE:
7136 afi = AFI_IP6;
7137 break;
7138 default:
7139 vty_out(vty,
7140 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
7141 return AFI_MAX;
7142 }
7143
7144 if (!v2vimport) {
7145 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
7146 BGP_CONFIG_VRF_TO_VRF_IMPORT)
7147 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
7148 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
7149 vty_out(vty,
7150 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
7151 return AFI_MAX;
7152 }
7153 } else {
7154 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
7155 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
7156 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
7157 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
7158 vty_out(vty,
7159 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
7160 return AFI_MAX;
7161 }
7162 }
7163 return afi;
7164 }
7165
7166 DEFPY (af_rd_vpn_export,
7167 af_rd_vpn_export_cmd,
7168 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
7169 NO_STR
7170 "Specify route distinguisher\n"
7171 "Between current address-family and vpn\n"
7172 "For routes leaked from current address-family to vpn\n"
7173 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
7174 {
7175 VTY_DECLVAR_CONTEXT(bgp, bgp);
7176 struct prefix_rd prd;
7177 int ret;
7178 afi_t afi;
7179 int idx = 0;
7180 int yes = 1;
7181
7182 if (argv_find(argv, argc, "no", &idx))
7183 yes = 0;
7184
7185 if (yes) {
7186 ret = str2prefix_rd(rd_str, &prd);
7187 if (!ret) {
7188 vty_out(vty, "%% Malformed rd\n");
7189 return CMD_WARNING_CONFIG_FAILED;
7190 }
7191 }
7192
7193 afi = vpn_policy_getafi(vty, bgp, false);
7194 if (afi == AFI_MAX)
7195 return CMD_WARNING_CONFIG_FAILED;
7196
7197 /*
7198 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
7199 */
7200 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
7201 bgp_get_default(), bgp);
7202
7203 if (yes) {
7204 bgp->vpn_policy[afi].tovpn_rd = prd;
7205 SET_FLAG(bgp->vpn_policy[afi].flags,
7206 BGP_VPN_POLICY_TOVPN_RD_SET);
7207 } else {
7208 UNSET_FLAG(bgp->vpn_policy[afi].flags,
7209 BGP_VPN_POLICY_TOVPN_RD_SET);
7210 }
7211
7212 /* post-change: re-export vpn routes */
7213 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
7214 bgp_get_default(), bgp);
7215
7216 return CMD_SUCCESS;
7217 }
7218
7219 ALIAS (af_rd_vpn_export,
7220 af_no_rd_vpn_export_cmd,
7221 "no rd vpn export",
7222 NO_STR
7223 "Specify route distinguisher\n"
7224 "Between current address-family and vpn\n"
7225 "For routes leaked from current address-family to vpn\n")
7226
7227 DEFPY (af_label_vpn_export,
7228 af_label_vpn_export_cmd,
7229 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
7230 NO_STR
7231 "label value for VRF\n"
7232 "Between current address-family and vpn\n"
7233 "For routes leaked from current address-family to vpn\n"
7234 "Label Value <0-1048575>\n"
7235 "Automatically assign a label\n")
7236 {
7237 VTY_DECLVAR_CONTEXT(bgp, bgp);
7238 mpls_label_t label = MPLS_LABEL_NONE;
7239 afi_t afi;
7240 int idx = 0;
7241 int yes = 1;
7242
7243 if (argv_find(argv, argc, "no", &idx))
7244 yes = 0;
7245
7246 /* If "no ...", squash trailing parameter */
7247 if (!yes)
7248 label_auto = NULL;
7249
7250 if (yes) {
7251 if (!label_auto)
7252 label = label_val; /* parser should force unsigned */
7253 }
7254
7255 afi = vpn_policy_getafi(vty, bgp, false);
7256 if (afi == AFI_MAX)
7257 return CMD_WARNING_CONFIG_FAILED;
7258
7259
7260 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
7261 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
7262 /* no change */
7263 return CMD_SUCCESS;
7264
7265 /*
7266 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
7267 */
7268 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
7269 bgp_get_default(), bgp);
7270
7271 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
7272 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
7273
7274 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
7275
7276 /*
7277 * label has previously been automatically
7278 * assigned by labelpool: release it
7279 *
7280 * NB if tovpn_label == MPLS_LABEL_NONE it
7281 * means the automatic assignment is in flight
7282 * and therefore the labelpool callback must
7283 * detect that the auto label is not needed.
7284 */
7285
7286 bgp_lp_release(LP_TYPE_VRF,
7287 &bgp->vpn_policy[afi],
7288 bgp->vpn_policy[afi].tovpn_label);
7289 }
7290 UNSET_FLAG(bgp->vpn_policy[afi].flags,
7291 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
7292 }
7293
7294 bgp->vpn_policy[afi].tovpn_label = label;
7295 if (label_auto) {
7296 SET_FLAG(bgp->vpn_policy[afi].flags,
7297 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
7298 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
7299 vpn_leak_label_callback);
7300 }
7301
7302 /* post-change: re-export vpn routes */
7303 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
7304 bgp_get_default(), bgp);
7305
7306 return CMD_SUCCESS;
7307 }
7308
7309 ALIAS (af_label_vpn_export,
7310 af_no_label_vpn_export_cmd,
7311 "no label vpn export",
7312 NO_STR
7313 "label value for VRF\n"
7314 "Between current address-family and vpn\n"
7315 "For routes leaked from current address-family to vpn\n")
7316
7317 DEFPY (af_nexthop_vpn_export,
7318 af_nexthop_vpn_export_cmd,
7319 "[no] nexthop vpn export <A.B.C.D|X:X::X:X>$nexthop_str",
7320 NO_STR
7321 "Specify next hop to use for VRF advertised prefixes\n"
7322 "Between current address-family and vpn\n"
7323 "For routes leaked from current address-family to vpn\n"
7324 "IPv4 prefix\n"
7325 "IPv6 prefix\n")
7326 {
7327 VTY_DECLVAR_CONTEXT(bgp, bgp);
7328 afi_t afi;
7329 struct prefix p;
7330 int idx = 0;
7331 int yes = 1;
7332
7333 if (argv_find(argv, argc, "no", &idx))
7334 yes = 0;
7335
7336 if (yes) {
7337 if (!sockunion2hostprefix(nexthop_str, &p))
7338 return CMD_WARNING_CONFIG_FAILED;
7339 }
7340
7341 afi = vpn_policy_getafi(vty, bgp, false);
7342 if (afi == AFI_MAX)
7343 return CMD_WARNING_CONFIG_FAILED;
7344
7345 /*
7346 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
7347 */
7348 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
7349 bgp_get_default(), bgp);
7350
7351 if (yes) {
7352 bgp->vpn_policy[afi].tovpn_nexthop = p;
7353 SET_FLAG(bgp->vpn_policy[afi].flags,
7354 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
7355 } else {
7356 UNSET_FLAG(bgp->vpn_policy[afi].flags,
7357 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
7358 }
7359
7360 /* post-change: re-export vpn routes */
7361 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
7362 bgp_get_default(), bgp);
7363
7364 return CMD_SUCCESS;
7365 }
7366
7367 ALIAS (af_nexthop_vpn_export,
7368 af_no_nexthop_vpn_export_cmd,
7369 "no nexthop vpn export",
7370 NO_STR
7371 "Specify next hop to use for VRF advertised prefixes\n"
7372 "Between current address-family and vpn\n"
7373 "For routes leaked from current address-family to vpn\n")
7374
7375 static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
7376 {
7377 if (!strcmp(dstr, "import")) {
7378 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
7379 } else if (!strcmp(dstr, "export")) {
7380 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
7381 } else if (!strcmp(dstr, "both")) {
7382 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
7383 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
7384 } else {
7385 vty_out(vty, "%% direction parse error\n");
7386 return CMD_WARNING_CONFIG_FAILED;
7387 }
7388 return CMD_SUCCESS;
7389 }
7390
7391 DEFPY (af_rt_vpn_imexport,
7392 af_rt_vpn_imexport_cmd,
7393 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
7394 NO_STR
7395 "Specify route target list\n"
7396 "Specify route target list\n"
7397 "Between current address-family and vpn\n"
7398 "For routes leaked from vpn to current address-family: match any\n"
7399 "For routes leaked from current address-family to vpn: set\n"
7400 "both import: match any and export: set\n"
7401 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
7402 {
7403 VTY_DECLVAR_CONTEXT(bgp, bgp);
7404 int ret;
7405 struct ecommunity *ecom = NULL;
7406 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
7407 vpn_policy_direction_t dir;
7408 afi_t afi;
7409 int idx = 0;
7410 int yes = 1;
7411
7412 if (argv_find(argv, argc, "no", &idx))
7413 yes = 0;
7414
7415 afi = vpn_policy_getafi(vty, bgp, false);
7416 if (afi == AFI_MAX)
7417 return CMD_WARNING_CONFIG_FAILED;
7418
7419 ret = vpn_policy_getdirs(vty, direction_str, dodir);
7420 if (ret != CMD_SUCCESS)
7421 return ret;
7422
7423 if (yes) {
7424 if (!argv_find(argv, argc, "RTLIST", &idx)) {
7425 vty_out(vty, "%% Missing RTLIST\n");
7426 return CMD_WARNING_CONFIG_FAILED;
7427 }
7428 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
7429 if (ret != CMD_SUCCESS) {
7430 return ret;
7431 }
7432 }
7433
7434 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
7435 if (!dodir[dir])
7436 continue;
7437
7438 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
7439
7440 if (yes) {
7441 if (bgp->vpn_policy[afi].rtlist[dir])
7442 ecommunity_free(
7443 &bgp->vpn_policy[afi].rtlist[dir]);
7444 bgp->vpn_policy[afi].rtlist[dir] =
7445 ecommunity_dup(ecom);
7446 } else {
7447 if (bgp->vpn_policy[afi].rtlist[dir])
7448 ecommunity_free(
7449 &bgp->vpn_policy[afi].rtlist[dir]);
7450 bgp->vpn_policy[afi].rtlist[dir] = NULL;
7451 }
7452
7453 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
7454 }
7455
7456 if (ecom)
7457 ecommunity_free(&ecom);
7458
7459 return CMD_SUCCESS;
7460 }
7461
7462 ALIAS (af_rt_vpn_imexport,
7463 af_no_rt_vpn_imexport_cmd,
7464 "no <rt|route-target> vpn <import|export|both>$direction_str",
7465 NO_STR
7466 "Specify route target list\n"
7467 "Specify route target list\n"
7468 "Between current address-family and vpn\n"
7469 "For routes leaked from vpn to current address-family\n"
7470 "For routes leaked from current address-family to vpn\n"
7471 "both import and export\n")
7472
7473 DEFPY (af_route_map_vpn_imexport,
7474 af_route_map_vpn_imexport_cmd,
7475 /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
7476 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
7477 NO_STR
7478 "Specify route map\n"
7479 "Between current address-family and vpn\n"
7480 "For routes leaked from vpn to current address-family\n"
7481 "For routes leaked from current address-family to vpn\n"
7482 "name of route-map\n")
7483 {
7484 VTY_DECLVAR_CONTEXT(bgp, bgp);
7485 int ret;
7486 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
7487 vpn_policy_direction_t dir;
7488 afi_t afi;
7489 int idx = 0;
7490 int yes = 1;
7491
7492 if (argv_find(argv, argc, "no", &idx))
7493 yes = 0;
7494
7495 afi = vpn_policy_getafi(vty, bgp, false);
7496 if (afi == AFI_MAX)
7497 return CMD_WARNING_CONFIG_FAILED;
7498
7499 ret = vpn_policy_getdirs(vty, direction_str, dodir);
7500 if (ret != CMD_SUCCESS)
7501 return ret;
7502
7503 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
7504 if (!dodir[dir])
7505 continue;
7506
7507 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
7508
7509 if (yes) {
7510 if (bgp->vpn_policy[afi].rmap_name[dir])
7511 XFREE(MTYPE_ROUTE_MAP_NAME,
7512 bgp->vpn_policy[afi].rmap_name[dir]);
7513 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
7514 MTYPE_ROUTE_MAP_NAME, rmap_str);
7515 bgp->vpn_policy[afi].rmap[dir] =
7516 route_map_lookup_warn_noexist(vty, rmap_str);
7517 if (!bgp->vpn_policy[afi].rmap[dir])
7518 return CMD_SUCCESS;
7519 } else {
7520 if (bgp->vpn_policy[afi].rmap_name[dir])
7521 XFREE(MTYPE_ROUTE_MAP_NAME,
7522 bgp->vpn_policy[afi].rmap_name[dir]);
7523 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
7524 bgp->vpn_policy[afi].rmap[dir] = NULL;
7525 }
7526
7527 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
7528 }
7529
7530 return CMD_SUCCESS;
7531 }
7532
7533 ALIAS (af_route_map_vpn_imexport,
7534 af_no_route_map_vpn_imexport_cmd,
7535 "no route-map vpn <import|export>$direction_str",
7536 NO_STR
7537 "Specify route map\n"
7538 "Between current address-family and vpn\n"
7539 "For routes leaked from vpn to current address-family\n"
7540 "For routes leaked from current address-family to vpn\n")
7541
7542 DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
7543 "[no] import vrf route-map RMAP$rmap_str",
7544 NO_STR
7545 "Import routes from another VRF\n"
7546 "Vrf routes being filtered\n"
7547 "Specify route map\n"
7548 "name of route-map\n")
7549 {
7550 VTY_DECLVAR_CONTEXT(bgp, bgp);
7551 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
7552 afi_t afi;
7553 int idx = 0;
7554 int yes = 1;
7555 struct bgp *bgp_default;
7556
7557 if (argv_find(argv, argc, "no", &idx))
7558 yes = 0;
7559
7560 afi = vpn_policy_getafi(vty, bgp, true);
7561 if (afi == AFI_MAX)
7562 return CMD_WARNING_CONFIG_FAILED;
7563
7564 bgp_default = bgp_get_default();
7565 if (!bgp_default) {
7566 int32_t ret;
7567 as_t as = bgp->as;
7568
7569 /* Auto-create assuming the same AS */
7570 ret = bgp_get_vty(&bgp_default, &as, NULL,
7571 BGP_INSTANCE_TYPE_DEFAULT);
7572
7573 if (ret) {
7574 vty_out(vty,
7575 "VRF default is not configured as a bgp instance\n");
7576 return CMD_WARNING;
7577 }
7578 }
7579
7580 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
7581
7582 if (yes) {
7583 if (bgp->vpn_policy[afi].rmap_name[dir])
7584 XFREE(MTYPE_ROUTE_MAP_NAME,
7585 bgp->vpn_policy[afi].rmap_name[dir]);
7586 bgp->vpn_policy[afi].rmap_name[dir] =
7587 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
7588 bgp->vpn_policy[afi].rmap[dir] =
7589 route_map_lookup_warn_noexist(vty, rmap_str);
7590 if (!bgp->vpn_policy[afi].rmap[dir])
7591 return CMD_SUCCESS;
7592 } else {
7593 if (bgp->vpn_policy[afi].rmap_name[dir])
7594 XFREE(MTYPE_ROUTE_MAP_NAME,
7595 bgp->vpn_policy[afi].rmap_name[dir]);
7596 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
7597 bgp->vpn_policy[afi].rmap[dir] = NULL;
7598 }
7599
7600 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
7601
7602 return CMD_SUCCESS;
7603 }
7604
7605 ALIAS(af_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
7606 "no import vrf route-map",
7607 NO_STR
7608 "Import routes from another VRF\n"
7609 "Vrf routes being filtered\n"
7610 "Specify route map\n")
7611
7612 DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
7613 "[no] import vrf VIEWVRFNAME$import_name",
7614 NO_STR
7615 "Import routes from another VRF\n"
7616 "VRF to import from\n"
7617 "The name of the VRF\n")
7618 {
7619 VTY_DECLVAR_CONTEXT(bgp, bgp);
7620 struct listnode *node;
7621 struct bgp *vrf_bgp, *bgp_default;
7622 int32_t ret = 0;
7623 as_t as = bgp->as;
7624 bool remove = false;
7625 int32_t idx = 0;
7626 char *vname;
7627 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
7628 safi_t safi;
7629 afi_t afi;
7630
7631 if (import_name == NULL) {
7632 vty_out(vty, "%% Missing import name\n");
7633 return CMD_WARNING;
7634 }
7635
7636 if (argv_find(argv, argc, "no", &idx))
7637 remove = true;
7638
7639 afi = vpn_policy_getafi(vty, bgp, true);
7640 if (afi == AFI_MAX)
7641 return CMD_WARNING_CONFIG_FAILED;
7642
7643 safi = bgp_node_safi(vty);
7644
7645 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
7646 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
7647 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
7648 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
7649 remove ? "unimport" : "import", import_name);
7650 return CMD_WARNING;
7651 }
7652
7653 bgp_default = bgp_get_default();
7654 if (!bgp_default) {
7655 /* Auto-create assuming the same AS */
7656 ret = bgp_get_vty(&bgp_default, &as, NULL,
7657 BGP_INSTANCE_TYPE_DEFAULT);
7658
7659 if (ret) {
7660 vty_out(vty,
7661 "VRF default is not configured as a bgp instance\n");
7662 return CMD_WARNING;
7663 }
7664 }
7665
7666 vrf_bgp = bgp_lookup_by_name(import_name);
7667 if (!vrf_bgp) {
7668 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
7669 vrf_bgp = bgp_default;
7670 else
7671 /* Auto-create assuming the same AS */
7672 ret = bgp_get_vty(&vrf_bgp, &as, import_name, bgp_type);
7673
7674 if (ret) {
7675 vty_out(vty,
7676 "VRF %s is not configured as a bgp instance\n",
7677 import_name);
7678 return CMD_WARNING;
7679 }
7680 }
7681
7682 if (remove) {
7683 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
7684 } else {
7685 /* Already importing from "import_vrf"? */
7686 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
7687 vname)) {
7688 if (strcmp(vname, import_name) == 0)
7689 return CMD_WARNING;
7690 }
7691
7692 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
7693 }
7694
7695 return CMD_SUCCESS;
7696 }
7697
7698 /* This command is valid only in a bgp vrf instance or the default instance */
7699 DEFPY (bgp_imexport_vpn,
7700 bgp_imexport_vpn_cmd,
7701 "[no] <import|export>$direction_str vpn",
7702 NO_STR
7703 "Import routes to this address-family\n"
7704 "Export routes from this address-family\n"
7705 "to/from default instance VPN RIB\n")
7706 {
7707 VTY_DECLVAR_CONTEXT(bgp, bgp);
7708 int previous_state;
7709 afi_t afi;
7710 safi_t safi;
7711 int idx = 0;
7712 int yes = 1;
7713 int flag;
7714 vpn_policy_direction_t dir;
7715
7716 if (argv_find(argv, argc, "no", &idx))
7717 yes = 0;
7718
7719 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
7720 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
7721
7722 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
7723 return CMD_WARNING_CONFIG_FAILED;
7724 }
7725
7726 afi = bgp_node_afi(vty);
7727 safi = bgp_node_safi(vty);
7728 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
7729 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
7730 return CMD_WARNING_CONFIG_FAILED;
7731 }
7732
7733 if (!strcmp(direction_str, "import")) {
7734 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
7735 dir = BGP_VPN_POLICY_DIR_FROMVPN;
7736 } else if (!strcmp(direction_str, "export")) {
7737 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
7738 dir = BGP_VPN_POLICY_DIR_TOVPN;
7739 } else {
7740 vty_out(vty, "%% unknown direction %s\n", direction_str);
7741 return CMD_WARNING_CONFIG_FAILED;
7742 }
7743
7744 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
7745
7746 if (yes) {
7747 SET_FLAG(bgp->af_flags[afi][safi], flag);
7748 if (!previous_state) {
7749 /* trigger export current vrf */
7750 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
7751 }
7752 } else {
7753 if (previous_state) {
7754 /* trigger un-export current vrf */
7755 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
7756 }
7757 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
7758 }
7759
7760 return CMD_SUCCESS;
7761 }
7762
7763 DEFPY (af_routetarget_import,
7764 af_routetarget_import_cmd,
7765 "[no] <rt|route-target> redirect import RTLIST...",
7766 NO_STR
7767 "Specify route target list\n"
7768 "Specify route target list\n"
7769 "Flow-spec redirect type route target\n"
7770 "Import routes to this address-family\n"
7771 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
7772 {
7773 VTY_DECLVAR_CONTEXT(bgp, bgp);
7774 int ret;
7775 struct ecommunity *ecom = NULL;
7776 afi_t afi;
7777 int idx = 0;
7778 int yes = 1;
7779
7780 if (argv_find(argv, argc, "no", &idx))
7781 yes = 0;
7782
7783 afi = vpn_policy_getafi(vty, bgp, false);
7784 if (afi == AFI_MAX)
7785 return CMD_WARNING_CONFIG_FAILED;
7786
7787 if (yes) {
7788 if (!argv_find(argv, argc, "RTLIST", &idx)) {
7789 vty_out(vty, "%% Missing RTLIST\n");
7790 return CMD_WARNING_CONFIG_FAILED;
7791 }
7792 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
7793 if (ret != CMD_SUCCESS)
7794 return ret;
7795 }
7796
7797 if (yes) {
7798 if (bgp->vpn_policy[afi].import_redirect_rtlist)
7799 ecommunity_free(&bgp->vpn_policy[afi]
7800 .import_redirect_rtlist);
7801 bgp->vpn_policy[afi].import_redirect_rtlist =
7802 ecommunity_dup(ecom);
7803 } else {
7804 if (bgp->vpn_policy[afi].import_redirect_rtlist)
7805 ecommunity_free(&bgp->vpn_policy[afi]
7806 .import_redirect_rtlist);
7807 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
7808 }
7809
7810 if (ecom)
7811 ecommunity_free(&ecom);
7812
7813 return CMD_SUCCESS;
7814 }
7815
7816 DEFUN_NOSH (address_family_ipv4_safi,
7817 address_family_ipv4_safi_cmd,
7818 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
7819 "Enter Address Family command mode\n"
7820 "Address Family\n"
7821 BGP_SAFI_WITH_LABEL_HELP_STR)
7822 {
7823
7824 if (argc == 3) {
7825 VTY_DECLVAR_CONTEXT(bgp, bgp);
7826 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
7827 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
7828 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
7829 && safi != SAFI_EVPN) {
7830 vty_out(vty,
7831 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
7832 return CMD_WARNING_CONFIG_FAILED;
7833 }
7834 vty->node = bgp_node_type(AFI_IP, safi);
7835 } else
7836 vty->node = BGP_IPV4_NODE;
7837
7838 return CMD_SUCCESS;
7839 }
7840
7841 DEFUN_NOSH (address_family_ipv6_safi,
7842 address_family_ipv6_safi_cmd,
7843 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
7844 "Enter Address Family command mode\n"
7845 "Address Family\n"
7846 BGP_SAFI_WITH_LABEL_HELP_STR)
7847 {
7848 if (argc == 3) {
7849 VTY_DECLVAR_CONTEXT(bgp, bgp);
7850 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
7851 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
7852 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
7853 && safi != SAFI_EVPN) {
7854 vty_out(vty,
7855 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
7856 return CMD_WARNING_CONFIG_FAILED;
7857 }
7858 vty->node = bgp_node_type(AFI_IP6, safi);
7859 } else
7860 vty->node = BGP_IPV6_NODE;
7861
7862 return CMD_SUCCESS;
7863 }
7864
7865 #ifdef KEEP_OLD_VPN_COMMANDS
7866 DEFUN_NOSH (address_family_vpnv4,
7867 address_family_vpnv4_cmd,
7868 "address-family vpnv4 [unicast]",
7869 "Enter Address Family command mode\n"
7870 "Address Family\n"
7871 "Address Family modifier\n")
7872 {
7873 vty->node = BGP_VPNV4_NODE;
7874 return CMD_SUCCESS;
7875 }
7876
7877 DEFUN_NOSH (address_family_vpnv6,
7878 address_family_vpnv6_cmd,
7879 "address-family vpnv6 [unicast]",
7880 "Enter Address Family command mode\n"
7881 "Address Family\n"
7882 "Address Family modifier\n")
7883 {
7884 vty->node = BGP_VPNV6_NODE;
7885 return CMD_SUCCESS;
7886 }
7887 #endif /* KEEP_OLD_VPN_COMMANDS */
7888
7889 DEFUN_NOSH (address_family_evpn,
7890 address_family_evpn_cmd,
7891 "address-family l2vpn evpn",
7892 "Enter Address Family command mode\n"
7893 "Address Family\n"
7894 "Address Family modifier\n")
7895 {
7896 VTY_DECLVAR_CONTEXT(bgp, bgp);
7897 vty->node = BGP_EVPN_NODE;
7898 return CMD_SUCCESS;
7899 }
7900
7901 DEFUN_NOSH (exit_address_family,
7902 exit_address_family_cmd,
7903 "exit-address-family",
7904 "Exit from Address Family configuration mode\n")
7905 {
7906 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
7907 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
7908 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
7909 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
7910 || vty->node == BGP_EVPN_NODE
7911 || vty->node == BGP_FLOWSPECV4_NODE
7912 || vty->node == BGP_FLOWSPECV6_NODE)
7913 vty->node = BGP_NODE;
7914 return CMD_SUCCESS;
7915 }
7916
7917 /* Recalculate bestpath and re-advertise a prefix */
7918 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
7919 const char *ip_str, afi_t afi, safi_t safi,
7920 struct prefix_rd *prd)
7921 {
7922 int ret;
7923 struct prefix match;
7924 struct bgp_node *rn;
7925 struct bgp_node *rm;
7926 struct bgp *bgp;
7927 struct bgp_table *table;
7928 struct bgp_table *rib;
7929
7930 /* BGP structure lookup. */
7931 if (view_name) {
7932 bgp = bgp_lookup_by_name(view_name);
7933 if (bgp == NULL) {
7934 vty_out(vty, "%% Can't find BGP instance %s\n",
7935 view_name);
7936 return CMD_WARNING;
7937 }
7938 } else {
7939 bgp = bgp_get_default();
7940 if (bgp == NULL) {
7941 vty_out(vty, "%% No BGP process is configured\n");
7942 return CMD_WARNING;
7943 }
7944 }
7945
7946 /* Check IP address argument. */
7947 ret = str2prefix(ip_str, &match);
7948 if (!ret) {
7949 vty_out(vty, "%% address is malformed\n");
7950 return CMD_WARNING;
7951 }
7952
7953 match.family = afi2family(afi);
7954 rib = bgp->rib[afi][safi];
7955
7956 if (safi == SAFI_MPLS_VPN) {
7957 for (rn = bgp_table_top(rib); rn; rn = bgp_route_next(rn)) {
7958 if (prd && memcmp(rn->p.u.val, prd->val, 8) != 0)
7959 continue;
7960
7961 table = bgp_node_get_bgp_table_info(rn);
7962 if (table != NULL) {
7963
7964 if ((rm = bgp_node_match(table, &match))
7965 != NULL) {
7966 if (rm->p.prefixlen
7967 == match.prefixlen) {
7968 SET_FLAG(rm->flags,
7969 BGP_NODE_USER_CLEAR);
7970 bgp_process(bgp, rm, afi, safi);
7971 }
7972 bgp_unlock_node(rm);
7973 }
7974 }
7975 }
7976 } else {
7977 if ((rn = bgp_node_match(rib, &match)) != NULL) {
7978 if (rn->p.prefixlen == match.prefixlen) {
7979 SET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
7980 bgp_process(bgp, rn, afi, safi);
7981 }
7982 bgp_unlock_node(rn);
7983 }
7984 }
7985
7986 return CMD_SUCCESS;
7987 }
7988
7989 /* one clear bgp command to rule them all */
7990 DEFUN (clear_ip_bgp_all,
7991 clear_ip_bgp_all_cmd,
7992 "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>]",
7993 CLEAR_STR
7994 IP_STR
7995 BGP_STR
7996 BGP_INSTANCE_HELP_STR
7997 BGP_AFI_HELP_STR
7998 "Address Family\n"
7999 BGP_SAFI_WITH_LABEL_HELP_STR
8000 "Address Family modifier\n"
8001 "Clear all peers\n"
8002 "BGP IPv4 neighbor to clear\n"
8003 "BGP IPv6 neighbor to clear\n"
8004 "BGP neighbor on interface to clear\n"
8005 "Clear peers with the AS number\n"
8006 "Clear all external peers\n"
8007 "Clear all members of peer-group\n"
8008 "BGP peer-group name\n"
8009 BGP_SOFT_STR
8010 BGP_SOFT_IN_STR
8011 BGP_SOFT_OUT_STR
8012 BGP_SOFT_IN_STR
8013 "Push out prefix-list ORF and do inbound soft reconfig\n"
8014 BGP_SOFT_OUT_STR)
8015 {
8016 char *vrf = NULL;
8017
8018 afi_t afi = AFI_UNSPEC;
8019 safi_t safi = SAFI_UNSPEC;
8020 enum clear_sort clr_sort = clear_peer;
8021 enum bgp_clear_type clr_type;
8022 char *clr_arg = NULL;
8023
8024 int idx = 0;
8025
8026 /* clear [ip] bgp */
8027 if (argv_find(argv, argc, "ip", &idx))
8028 afi = AFI_IP;
8029
8030 /* [<vrf> VIEWVRFNAME] */
8031 if (argv_find(argv, argc, "vrf", &idx)) {
8032 vrf = argv[idx + 1]->arg;
8033 idx += 2;
8034 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
8035 vrf = NULL;
8036 } else if (argv_find(argv, argc, "view", &idx)) {
8037 /* [<view> VIEWVRFNAME] */
8038 vrf = argv[idx + 1]->arg;
8039 idx += 2;
8040 }
8041 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
8042 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
8043 argv_find_and_parse_safi(argv, argc, &idx, &safi);
8044
8045 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
8046 if (argv_find(argv, argc, "*", &idx)) {
8047 clr_sort = clear_all;
8048 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
8049 clr_sort = clear_peer;
8050 clr_arg = argv[idx]->arg;
8051 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
8052 clr_sort = clear_peer;
8053 clr_arg = argv[idx]->arg;
8054 } else if (argv_find(argv, argc, "peer-group", &idx)) {
8055 clr_sort = clear_group;
8056 idx++;
8057 clr_arg = argv[idx]->arg;
8058 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
8059 clr_sort = clear_peer;
8060 clr_arg = argv[idx]->arg;
8061 } else if (argv_find(argv, argc, "WORD", &idx)) {
8062 clr_sort = clear_peer;
8063 clr_arg = argv[idx]->arg;
8064 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
8065 clr_sort = clear_as;
8066 clr_arg = argv[idx]->arg;
8067 } else if (argv_find(argv, argc, "external", &idx)) {
8068 clr_sort = clear_external;
8069 }
8070
8071 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
8072 if (argv_find(argv, argc, "soft", &idx)) {
8073 if (argv_find(argv, argc, "in", &idx)
8074 || argv_find(argv, argc, "out", &idx))
8075 clr_type = strmatch(argv[idx]->text, "in")
8076 ? BGP_CLEAR_SOFT_IN
8077 : BGP_CLEAR_SOFT_OUT;
8078 else
8079 clr_type = BGP_CLEAR_SOFT_BOTH;
8080 } else if (argv_find(argv, argc, "in", &idx)) {
8081 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
8082 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
8083 : BGP_CLEAR_SOFT_IN;
8084 } else if (argv_find(argv, argc, "out", &idx)) {
8085 clr_type = BGP_CLEAR_SOFT_OUT;
8086 } else
8087 clr_type = BGP_CLEAR_SOFT_NONE;
8088
8089 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
8090 }
8091
8092 DEFUN (clear_ip_bgp_prefix,
8093 clear_ip_bgp_prefix_cmd,
8094 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
8095 CLEAR_STR
8096 IP_STR
8097 BGP_STR
8098 BGP_INSTANCE_HELP_STR
8099 "Clear bestpath and re-advertise\n"
8100 "IPv4 prefix\n")
8101 {
8102 char *vrf = NULL;
8103 char *prefix = NULL;
8104
8105 int idx = 0;
8106
8107 /* [<view|vrf> VIEWVRFNAME] */
8108 if (argv_find(argv, argc, "vrf", &idx)) {
8109 vrf = argv[idx + 1]->arg;
8110 idx += 2;
8111 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
8112 vrf = NULL;
8113 } else if (argv_find(argv, argc, "view", &idx)) {
8114 /* [<view> VIEWVRFNAME] */
8115 vrf = argv[idx + 1]->arg;
8116 idx += 2;
8117 }
8118
8119 prefix = argv[argc - 1]->arg;
8120
8121 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
8122 }
8123
8124 DEFUN (clear_bgp_ipv6_safi_prefix,
8125 clear_bgp_ipv6_safi_prefix_cmd,
8126 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
8127 CLEAR_STR
8128 IP_STR
8129 BGP_STR
8130 "Address Family\n"
8131 BGP_SAFI_HELP_STR
8132 "Clear bestpath and re-advertise\n"
8133 "IPv6 prefix\n")
8134 {
8135 int idx_safi = 0;
8136 int idx_ipv6_prefix = 0;
8137 safi_t safi = SAFI_UNICAST;
8138 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
8139 argv[idx_ipv6_prefix]->arg : NULL;
8140
8141 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
8142 return bgp_clear_prefix(
8143 vty, NULL, prefix, AFI_IP6,
8144 safi, NULL);
8145 }
8146
8147 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
8148 clear_bgp_instance_ipv6_safi_prefix_cmd,
8149 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
8150 CLEAR_STR
8151 IP_STR
8152 BGP_STR
8153 BGP_INSTANCE_HELP_STR
8154 "Address Family\n"
8155 BGP_SAFI_HELP_STR
8156 "Clear bestpath and re-advertise\n"
8157 "IPv6 prefix\n")
8158 {
8159 int idx_safi = 0;
8160 int idx_vrfview = 0;
8161 int idx_ipv6_prefix = 0;
8162 safi_t safi = SAFI_UNICAST;
8163 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
8164 argv[idx_ipv6_prefix]->arg : NULL;
8165 char *vrfview = NULL;
8166
8167 /* [<view|vrf> VIEWVRFNAME] */
8168 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
8169 vrfview = argv[idx_vrfview + 1]->arg;
8170 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
8171 vrfview = NULL;
8172 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
8173 /* [<view> VIEWVRFNAME] */
8174 vrfview = argv[idx_vrfview + 1]->arg;
8175 }
8176 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
8177
8178 return bgp_clear_prefix(
8179 vty, vrfview, prefix,
8180 AFI_IP6, safi, NULL);
8181 }
8182
8183 DEFUN (show_bgp_views,
8184 show_bgp_views_cmd,
8185 "show [ip] bgp views",
8186 SHOW_STR
8187 IP_STR
8188 BGP_STR
8189 "Show the defined BGP views\n")
8190 {
8191 struct list *inst = bm->bgp;
8192 struct listnode *node;
8193 struct bgp *bgp;
8194
8195 vty_out(vty, "Defined BGP views:\n");
8196 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
8197 /* Skip VRFs. */
8198 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
8199 continue;
8200 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
8201 bgp->as);
8202 }
8203
8204 return CMD_SUCCESS;
8205 }
8206
8207 DEFUN (show_bgp_vrfs,
8208 show_bgp_vrfs_cmd,
8209 "show [ip] bgp vrfs [json]",
8210 SHOW_STR
8211 IP_STR
8212 BGP_STR
8213 "Show BGP VRFs\n"
8214 JSON_STR)
8215 {
8216 char buf[ETHER_ADDR_STRLEN];
8217 struct list *inst = bm->bgp;
8218 struct listnode *node;
8219 struct bgp *bgp;
8220 bool uj = use_json(argc, argv);
8221 json_object *json = NULL;
8222 json_object *json_vrfs = NULL;
8223 int count = 0;
8224
8225 if (uj) {
8226 json = json_object_new_object();
8227 json_vrfs = json_object_new_object();
8228 }
8229
8230 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
8231 const char *name, *type;
8232 struct peer *peer;
8233 struct listnode *node2, *nnode2;
8234 int peers_cfg, peers_estb;
8235 json_object *json_vrf = NULL;
8236
8237 /* Skip Views. */
8238 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
8239 continue;
8240
8241 count++;
8242 if (!uj && count == 1) {
8243 vty_out(vty,
8244 "%4s %-5s %-16s %9s %10s %-37s\n",
8245 "Type", "Id", "routerId", "#PeersCfg",
8246 "#PeersEstb", "Name");
8247 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
8248 "L3-VNI", "RouterMAC", "Interface");
8249 }
8250
8251 peers_cfg = peers_estb = 0;
8252 if (uj)
8253 json_vrf = json_object_new_object();
8254
8255
8256 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
8257 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
8258 continue;
8259 peers_cfg++;
8260 if (peer->status == Established)
8261 peers_estb++;
8262 }
8263
8264 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
8265 name = VRF_DEFAULT_NAME;
8266 type = "DFLT";
8267 } else {
8268 name = bgp->name;
8269 type = "VRF";
8270 }
8271
8272
8273 if (uj) {
8274 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
8275 ? -1
8276 : (int64_t)bgp->vrf_id;
8277 json_object_string_add(json_vrf, "type", type);
8278 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
8279 json_object_string_add(json_vrf, "routerId",
8280 inet_ntoa(bgp->router_id));
8281 json_object_int_add(json_vrf, "numConfiguredPeers",
8282 peers_cfg);
8283 json_object_int_add(json_vrf, "numEstablishedPeers",
8284 peers_estb);
8285
8286 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
8287 json_object_string_add(
8288 json_vrf, "rmac",
8289 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
8290 json_object_string_add(json_vrf, "interface",
8291 ifindex2ifname(bgp->l3vni_svi_ifindex,
8292 bgp->vrf_id));
8293 json_object_object_add(json_vrfs, name, json_vrf);
8294 } else {
8295 vty_out(vty,
8296 "%4s %-5d %-16s %-9u %-10u %-37s\n",
8297 type,
8298 bgp->vrf_id == VRF_UNKNOWN ? -1
8299 : (int)bgp->vrf_id,
8300 inet_ntoa(bgp->router_id), peers_cfg,
8301 peers_estb, name);
8302 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
8303 bgp->l3vni,
8304 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
8305 ifindex2ifname(bgp->l3vni_svi_ifindex,
8306 bgp->vrf_id));
8307 }
8308 }
8309
8310 if (uj) {
8311 json_object_object_add(json, "vrfs", json_vrfs);
8312
8313 json_object_int_add(json, "totalVrfs", count);
8314
8315 vty_out(vty, "%s\n", json_object_to_json_string_ext(
8316 json, JSON_C_TO_STRING_PRETTY));
8317 json_object_free(json);
8318 } else {
8319 if (count)
8320 vty_out(vty,
8321 "\nTotal number of VRFs (including default): %d\n",
8322 count);
8323 }
8324
8325 return CMD_SUCCESS;
8326 }
8327
8328 DEFUN (show_bgp_mac_hash,
8329 show_bgp_mac_hash_cmd,
8330 "show bgp mac hash",
8331 SHOW_STR
8332 BGP_STR
8333 "Mac Address\n"
8334 "Mac Address database\n")
8335 {
8336 bgp_mac_dump_table(vty);
8337
8338 return CMD_SUCCESS;
8339 }
8340
8341 static void show_tip_entry(struct hash_bucket *bucket, void *args)
8342 {
8343 struct vty *vty = (struct vty *)args;
8344 struct tip_addr *tip = (struct tip_addr *)bucket->data;
8345
8346 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(tip->addr),
8347 tip->refcnt);
8348 }
8349
8350 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
8351 {
8352 vty_out(vty, "self nexthop database:\n");
8353 bgp_nexthop_show_address_hash(vty, bgp);
8354
8355 vty_out(vty, "Tunnel-ip database:\n");
8356 hash_iterate(bgp->tip_hash,
8357 (void (*)(struct hash_bucket *, void *))show_tip_entry,
8358 vty);
8359 }
8360
8361 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
8362 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
8363 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
8364 "martian next-hops\n"
8365 "martian next-hop database\n")
8366 {
8367 struct bgp *bgp = NULL;
8368 int idx = 0;
8369 char *name = NULL;
8370
8371 /* [<vrf> VIEWVRFNAME] */
8372 if (argv_find(argv, argc, "vrf", &idx)) {
8373 name = argv[idx + 1]->arg;
8374 if (name && strmatch(name, VRF_DEFAULT_NAME))
8375 name = NULL;
8376 } else if (argv_find(argv, argc, "view", &idx))
8377 /* [<view> VIEWVRFNAME] */
8378 name = argv[idx + 1]->arg;
8379 if (name)
8380 bgp = bgp_lookup_by_name(name);
8381 else
8382 bgp = bgp_get_default();
8383
8384 if (!bgp) {
8385 vty_out(vty, "%% No BGP process is configured\n");
8386 return CMD_WARNING;
8387 }
8388 bgp_show_martian_nexthops(vty, bgp);
8389
8390 return CMD_SUCCESS;
8391 }
8392
8393 DEFUN (show_bgp_memory,
8394 show_bgp_memory_cmd,
8395 "show [ip] bgp memory",
8396 SHOW_STR
8397 IP_STR
8398 BGP_STR
8399 "Global BGP memory statistics\n")
8400 {
8401 char memstrbuf[MTYPE_MEMSTR_LEN];
8402 unsigned long count;
8403
8404 /* RIB related usage stats */
8405 count = mtype_stats_alloc(MTYPE_BGP_NODE);
8406 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
8407 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8408 count * sizeof(struct bgp_node)));
8409
8410 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
8411 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
8412 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8413 count * sizeof(struct bgp_path_info)));
8414 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
8415 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
8416 count,
8417 mtype_memstr(
8418 memstrbuf, sizeof(memstrbuf),
8419 count * sizeof(struct bgp_path_info_extra)));
8420
8421 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
8422 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
8423 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8424 count * sizeof(struct bgp_static)));
8425
8426 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
8427 vty_out(vty, "%ld Packets, using %s of memory\n", count,
8428 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8429 count * sizeof(struct bpacket)));
8430
8431 /* Adj-In/Out */
8432 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
8433 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
8434 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8435 count * sizeof(struct bgp_adj_in)));
8436 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
8437 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
8438 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8439 count * sizeof(struct bgp_adj_out)));
8440
8441 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
8442 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
8443 count,
8444 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8445 count * sizeof(struct bgp_nexthop_cache)));
8446
8447 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
8448 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
8449 count,
8450 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8451 count * sizeof(struct bgp_damp_info)));
8452
8453 /* Attributes */
8454 count = attr_count();
8455 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
8456 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8457 count * sizeof(struct attr)));
8458
8459 if ((count = attr_unknown_count()))
8460 vty_out(vty, "%ld unknown attributes\n", count);
8461
8462 /* AS_PATH attributes */
8463 count = aspath_count();
8464 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
8465 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8466 count * sizeof(struct aspath)));
8467
8468 count = mtype_stats_alloc(MTYPE_AS_SEG);
8469 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
8470 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8471 count * sizeof(struct assegment)));
8472
8473 /* Other attributes */
8474 if ((count = community_count()))
8475 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
8476 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
8477 count * sizeof(struct community)));
8478 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
8479 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
8480 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
8481 count * sizeof(struct ecommunity)));
8482 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
8483 vty_out(vty,
8484 "%ld BGP large-community entries, using %s of memory\n",
8485 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
8486 count * sizeof(struct lcommunity)));
8487
8488 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
8489 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
8490 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8491 count * sizeof(struct cluster_list)));
8492
8493 /* Peer related usage */
8494 count = mtype_stats_alloc(MTYPE_BGP_PEER);
8495 vty_out(vty, "%ld peers, using %s of memory\n", count,
8496 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8497 count * sizeof(struct peer)));
8498
8499 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
8500 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
8501 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8502 count * sizeof(struct peer_group)));
8503
8504 /* Other */
8505 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
8506 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
8507 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
8508 count * sizeof(regex_t)));
8509 return CMD_SUCCESS;
8510 }
8511
8512 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
8513 {
8514 json_object *bestpath = json_object_new_object();
8515
8516 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
8517 json_object_string_add(bestpath, "asPath", "ignore");
8518
8519 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
8520 json_object_string_add(bestpath, "asPath", "confed");
8521
8522 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
8523 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
8524 json_object_string_add(bestpath, "multiPathRelax",
8525 "as-set");
8526 else
8527 json_object_string_add(bestpath, "multiPathRelax",
8528 "true");
8529 } else
8530 json_object_string_add(bestpath, "multiPathRelax", "false");
8531
8532 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
8533 json_object_string_add(bestpath, "compareRouterId", "true");
8534 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
8535 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
8536 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
8537 json_object_string_add(bestpath, "med", "confed");
8538 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
8539 json_object_string_add(bestpath, "med",
8540 "missing-as-worst");
8541 else
8542 json_object_string_add(bestpath, "med", "true");
8543 }
8544
8545 json_object_object_add(json, "bestPath", bestpath);
8546 }
8547
8548 /* Print the error code/subcode for why the peer is down */
8549 static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
8550 json_object *json_peer, bool use_json)
8551 {
8552 const char *code_str;
8553 const char *subcode_str;
8554
8555 if (use_json) {
8556 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
8557 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
8558 char errorcodesubcode_hexstr[5];
8559 char errorcodesubcode_str[256];
8560
8561 code_str = bgp_notify_code_str(peer->notify.code);
8562 subcode_str = bgp_notify_subcode_str(
8563 peer->notify.code,
8564 peer->notify.subcode);
8565
8566 sprintf(errorcodesubcode_hexstr, "%02X%02X",
8567 peer->notify.code, peer->notify.subcode);
8568 json_object_string_add(json_peer,
8569 "lastErrorCodeSubcode",
8570 errorcodesubcode_hexstr);
8571 snprintf(errorcodesubcode_str, 255, "%s%s",
8572 code_str, subcode_str);
8573 json_object_string_add(json_peer,
8574 "lastNotificationReason",
8575 errorcodesubcode_str);
8576 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
8577 && peer->notify.code == BGP_NOTIFY_CEASE
8578 && (peer->notify.subcode
8579 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
8580 || peer->notify.subcode
8581 == BGP_NOTIFY_CEASE_ADMIN_RESET)
8582 && peer->notify.length) {
8583 char msgbuf[1024];
8584 const char *msg_str;
8585
8586 msg_str = bgp_notify_admin_message(
8587 msgbuf, sizeof(msgbuf),
8588 (uint8_t *)peer->notify.data,
8589 peer->notify.length);
8590 if (msg_str)
8591 json_object_string_add(
8592 json_peer,
8593 "lastShutdownDescription",
8594 msg_str);
8595 }
8596
8597 }
8598 json_object_string_add(json_peer, "lastResetDueTo",
8599 peer_down_str[(int)peer->last_reset]);
8600 json_object_int_add(json_peer, "lastResetCode",
8601 peer->last_reset);
8602 } else {
8603 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
8604 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
8605 code_str = bgp_notify_code_str(peer->notify.code);
8606 subcode_str =
8607 bgp_notify_subcode_str(peer->notify.code,
8608 peer->notify.subcode);
8609 vty_out(vty, " Notification %s (%s%s)\n",
8610 peer->last_reset == PEER_DOWN_NOTIFY_SEND
8611 ? "sent"
8612 : "received",
8613 code_str, subcode_str);
8614 } else {
8615 vty_out(vty, " %s\n",
8616 peer_down_str[(int)peer->last_reset]);
8617 }
8618 }
8619 }
8620
8621 static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
8622 safi_t safi)
8623 {
8624 return ((peer->status != Established) ||
8625 !peer->afc_recv[afi][safi]);
8626 }
8627
8628 static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
8629 struct peer *peer, json_object *json_peer,
8630 int max_neighbor_width, bool use_json)
8631 {
8632 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
8633 int len;
8634
8635 if (use_json) {
8636 if (peer_dynamic_neighbor(peer))
8637 json_object_boolean_true_add(json_peer,
8638 "dynamicPeer");
8639 if (peer->hostname)
8640 json_object_string_add(json_peer, "hostname",
8641 peer->hostname);
8642
8643 if (peer->domainname)
8644 json_object_string_add(json_peer, "domainname",
8645 peer->domainname);
8646 json_object_int_add(json_peer, "connectionsEstablished",
8647 peer->established);
8648 json_object_int_add(json_peer, "connectionsDropped",
8649 peer->dropped);
8650 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
8651 use_json, json_peer);
8652 if (peer->status == Established)
8653 json_object_string_add(json_peer, "lastResetDueTo",
8654 "AFI/SAFI Not Negotiated");
8655 else
8656 bgp_show_peer_reset(NULL, peer, json_peer, true);
8657 } else {
8658 dn_flag[1] = '\0';
8659 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
8660 if (peer->hostname
8661 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
8662 len = vty_out(vty, "%s%s(%s)", dn_flag,
8663 peer->hostname, peer->host);
8664 else
8665 len = vty_out(vty, "%s%s", dn_flag, peer->host);
8666
8667 /* pad the neighbor column with spaces */
8668 if (len < max_neighbor_width)
8669 vty_out(vty, "%*s", max_neighbor_width - len,
8670 " ");
8671 vty_out(vty, "%7d %7d %8s", peer->established,
8672 peer->dropped,
8673 peer_uptime(peer->uptime, timebuf,
8674 BGP_UPTIME_LEN, 0, NULL));
8675 if (peer->status == Established)
8676 vty_out(vty, " AFI/SAFI Not Negotiated\n");
8677 else
8678 bgp_show_peer_reset(vty, peer, NULL,
8679 false);
8680 }
8681 }
8682
8683
8684 /* Show BGP peer's summary information. */
8685 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
8686 bool show_failed, bool use_json)
8687 {
8688 struct peer *peer;
8689 struct listnode *node, *nnode;
8690 unsigned int count = 0, dn_count = 0;
8691 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
8692 char neighbor_buf[VTY_BUFSIZ];
8693 int neighbor_col_default_width = 16;
8694 int len, failed_count = 0;
8695 int max_neighbor_width = 0;
8696 int pfx_rcd_safi;
8697 json_object *json = NULL;
8698 json_object *json_peer = NULL;
8699 json_object *json_peers = NULL;
8700 struct peer_af *paf;
8701
8702 /* labeled-unicast routes are installed in the unicast table so in order
8703 * to
8704 * display the correct PfxRcd value we must look at SAFI_UNICAST
8705 */
8706
8707 if (safi == SAFI_LABELED_UNICAST)
8708 pfx_rcd_safi = SAFI_UNICAST;
8709 else
8710 pfx_rcd_safi = safi;
8711
8712 if (use_json) {
8713 json = json_object_new_object();
8714 json_peers = json_object_new_object();
8715 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8716 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
8717 continue;
8718
8719 if (peer->afc[afi][safi]) {
8720 /* See if we have at least a single failed peer */
8721 if (bgp_has_peer_failed(peer, afi, safi))
8722 failed_count++;
8723 count++;
8724 }
8725 if (peer_dynamic_neighbor(peer))
8726 dn_count++;
8727 }
8728
8729 } else {
8730 /* Loop over all neighbors that will be displayed to determine
8731 * how many
8732 * characters are needed for the Neighbor column
8733 */
8734 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8735 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
8736 continue;
8737
8738 if (peer->afc[afi][safi]) {
8739 memset(dn_flag, '\0', sizeof(dn_flag));
8740 if (peer_dynamic_neighbor(peer))
8741 dn_flag[0] = '*';
8742
8743 if (peer->hostname
8744 && CHECK_FLAG(bgp->flags,
8745 BGP_FLAG_SHOW_HOSTNAME))
8746 sprintf(neighbor_buf, "%s%s(%s) ",
8747 dn_flag, peer->hostname,
8748 peer->host);
8749 else
8750 sprintf(neighbor_buf, "%s%s ", dn_flag,
8751 peer->host);
8752
8753 len = strlen(neighbor_buf);
8754
8755 if (len > max_neighbor_width)
8756 max_neighbor_width = len;
8757
8758 /* See if we have at least a single failed peer */
8759 if (bgp_has_peer_failed(peer, afi, safi))
8760 failed_count++;
8761 count++;
8762 }
8763 }
8764
8765 /* Originally we displayed the Neighbor column as 16
8766 * characters wide so make that the default
8767 */
8768 if (max_neighbor_width < neighbor_col_default_width)
8769 max_neighbor_width = neighbor_col_default_width;
8770 }
8771
8772 if (show_failed && !failed_count) {
8773 if (use_json) {
8774 json_object_int_add(json, "failedPeersCount", 0);
8775 json_object_int_add(json, "dynamicPeers", dn_count);
8776 json_object_int_add(json, "totalPeers", count);
8777
8778 vty_out(vty, "%s\n", json_object_to_json_string_ext(
8779 json, JSON_C_TO_STRING_PRETTY));
8780 json_object_free(json);
8781 } else {
8782 vty_out(vty, "%% No failed BGP neighbors found\n");
8783 vty_out(vty, "\nTotal number of neighbors %d\n", count);
8784 }
8785 return CMD_SUCCESS;
8786 }
8787
8788 count = 0; /* Reset the value as its used again */
8789 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8790 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
8791 continue;
8792
8793 if (!peer->afc[afi][safi])
8794 continue;
8795
8796 if (!count) {
8797 unsigned long ents;
8798 char memstrbuf[MTYPE_MEMSTR_LEN];
8799 int64_t vrf_id_ui;
8800
8801 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
8802 ? -1
8803 : (int64_t)bgp->vrf_id;
8804
8805 /* Usage summary and header */
8806 if (use_json) {
8807 json_object_string_add(
8808 json, "routerId",
8809 inet_ntoa(bgp->router_id));
8810 json_object_int_add(json, "as", bgp->as);
8811 json_object_int_add(json, "vrfId", vrf_id_ui);
8812 json_object_string_add(
8813 json, "vrfName",
8814 (bgp->inst_type
8815 == BGP_INSTANCE_TYPE_DEFAULT)
8816 ? VRF_DEFAULT_NAME
8817 : bgp->name);
8818 } else {
8819 vty_out(vty,
8820 "BGP router identifier %s, local AS number %u vrf-id %d",
8821 inet_ntoa(bgp->router_id), bgp->as,
8822 bgp->vrf_id == VRF_UNKNOWN
8823 ? -1
8824 : (int)bgp->vrf_id);
8825 vty_out(vty, "\n");
8826 }
8827
8828 if (bgp_update_delay_configured(bgp)) {
8829 if (use_json) {
8830 json_object_int_add(
8831 json, "updateDelayLimit",
8832 bgp->v_update_delay);
8833
8834 if (bgp->v_update_delay
8835 != bgp->v_establish_wait)
8836 json_object_int_add(
8837 json,
8838 "updateDelayEstablishWait",
8839 bgp->v_establish_wait);
8840
8841 if (bgp_update_delay_active(bgp)) {
8842 json_object_string_add(
8843 json,
8844 "updateDelayFirstNeighbor",
8845 bgp->update_delay_begin_time);
8846 json_object_boolean_true_add(
8847 json,
8848 "updateDelayInProgress");
8849 } else {
8850 if (bgp->update_delay_over) {
8851 json_object_string_add(
8852 json,
8853 "updateDelayFirstNeighbor",
8854 bgp->update_delay_begin_time);
8855 json_object_string_add(
8856 json,
8857 "updateDelayBestpathResumed",
8858 bgp->update_delay_end_time);
8859 json_object_string_add(
8860 json,
8861 "updateDelayZebraUpdateResume",
8862 bgp->update_delay_zebra_resume_time);
8863 json_object_string_add(
8864 json,
8865 "updateDelayPeerUpdateResume",
8866 bgp->update_delay_peers_resume_time);
8867 }
8868 }
8869 } else {
8870 vty_out(vty,
8871 "Read-only mode update-delay limit: %d seconds\n",
8872 bgp->v_update_delay);
8873 if (bgp->v_update_delay
8874 != bgp->v_establish_wait)
8875 vty_out(vty,
8876 " Establish wait: %d seconds\n",
8877 bgp->v_establish_wait);
8878
8879 if (bgp_update_delay_active(bgp)) {
8880 vty_out(vty,
8881 " First neighbor established: %s\n",
8882 bgp->update_delay_begin_time);
8883 vty_out(vty,
8884 " Delay in progress\n");
8885 } else {
8886 if (bgp->update_delay_over) {
8887 vty_out(vty,
8888 " First neighbor established: %s\n",
8889 bgp->update_delay_begin_time);
8890 vty_out(vty,
8891 " Best-paths resumed: %s\n",
8892 bgp->update_delay_end_time);
8893 vty_out(vty,
8894 " zebra update resumed: %s\n",
8895 bgp->update_delay_zebra_resume_time);
8896 vty_out(vty,
8897 " peers update resumed: %s\n",
8898 bgp->update_delay_peers_resume_time);
8899 }
8900 }
8901 }
8902 }
8903
8904 if (use_json) {
8905 if (bgp_maxmed_onstartup_configured(bgp)
8906 && bgp->maxmed_active)
8907 json_object_boolean_true_add(
8908 json, "maxMedOnStartup");
8909 if (bgp->v_maxmed_admin)
8910 json_object_boolean_true_add(
8911 json, "maxMedAdministrative");
8912
8913 json_object_int_add(
8914 json, "tableVersion",
8915 bgp_table_version(bgp->rib[afi][safi]));
8916
8917 ents = bgp_table_count(bgp->rib[afi][safi]);
8918 json_object_int_add(json, "ribCount", ents);
8919 json_object_int_add(
8920 json, "ribMemory",
8921 ents * sizeof(struct bgp_node));
8922
8923 ents = bgp->af_peer_count[afi][safi];
8924 json_object_int_add(json, "peerCount", ents);
8925 json_object_int_add(json, "peerMemory",
8926 ents * sizeof(struct peer));
8927
8928 if ((ents = listcount(bgp->group))) {
8929 json_object_int_add(
8930 json, "peerGroupCount", ents);
8931 json_object_int_add(
8932 json, "peerGroupMemory",
8933 ents * sizeof(struct
8934 peer_group));
8935 }
8936
8937 if (CHECK_FLAG(bgp->af_flags[afi][safi],
8938 BGP_CONFIG_DAMPENING))
8939 json_object_boolean_true_add(
8940 json, "dampeningEnabled");
8941 } else {
8942 if (bgp_maxmed_onstartup_configured(bgp)
8943 && bgp->maxmed_active)
8944 vty_out(vty,
8945 "Max-med on-startup active\n");
8946 if (bgp->v_maxmed_admin)
8947 vty_out(vty,
8948 "Max-med administrative active\n");
8949
8950 vty_out(vty, "BGP table version %" PRIu64 "\n",
8951 bgp_table_version(bgp->rib[afi][safi]));
8952
8953 ents = bgp_table_count(bgp->rib[afi][safi]);
8954 vty_out(vty,
8955 "RIB entries %ld, using %s of memory\n",
8956 ents,
8957 mtype_memstr(memstrbuf,
8958 sizeof(memstrbuf),
8959 ents * sizeof(struct
8960 bgp_node)));
8961
8962 /* Peer related usage */
8963 ents = bgp->af_peer_count[afi][safi];
8964 vty_out(vty, "Peers %ld, using %s of memory\n",
8965 ents,
8966 mtype_memstr(
8967 memstrbuf, sizeof(memstrbuf),
8968 ents * sizeof(struct peer)));
8969
8970 if ((ents = listcount(bgp->group)))
8971 vty_out(vty,
8972 "Peer groups %ld, using %s of memory\n",
8973 ents,
8974 mtype_memstr(
8975 memstrbuf,
8976 sizeof(memstrbuf),
8977 ents * sizeof(struct
8978 peer_group)));
8979
8980 if (CHECK_FLAG(bgp->af_flags[afi][safi],
8981 BGP_CONFIG_DAMPENING))
8982 vty_out(vty, "Dampening enabled.\n");
8983 vty_out(vty, "\n");
8984
8985 /* Subtract 8 here because 'Neighbor' is
8986 * 8 characters */
8987 vty_out(vty, "Neighbor");
8988 vty_out(vty, "%*s", max_neighbor_width - 8,
8989 " ");
8990 if (show_failed)
8991 vty_out(vty, "EstdCnt DropCnt ResetTime Reason\n");
8992 else
8993 vty_out(vty,
8994 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd\n");
8995 }
8996 }
8997
8998 count++;
8999 /* Works for both failed & successful cases */
9000 if (peer_dynamic_neighbor(peer))
9001 dn_count++;
9002
9003 if (use_json) {
9004 json_peer = NULL;
9005
9006 if (show_failed &&
9007 bgp_has_peer_failed(peer, afi, safi)) {
9008 json_peer = json_object_new_object();
9009 bgp_show_failed_summary(vty, bgp, peer,
9010 json_peer, 0, use_json);
9011 } else if (!show_failed) {
9012 json_peer = json_object_new_object();
9013 if (peer_dynamic_neighbor(peer)) {
9014 json_object_boolean_true_add(json_peer,
9015 "dynamicPeer");
9016 }
9017
9018 if (peer->hostname)
9019 json_object_string_add(json_peer, "hostname",
9020 peer->hostname);
9021
9022 if (peer->domainname)
9023 json_object_string_add(json_peer, "domainname",
9024 peer->domainname);
9025
9026 json_object_int_add(json_peer, "remoteAs", peer->as);
9027 json_object_int_add(json_peer, "version", 4);
9028 json_object_int_add(json_peer, "msgRcvd",
9029 PEER_TOTAL_RX(peer));
9030 json_object_int_add(json_peer, "msgSent",
9031 PEER_TOTAL_TX(peer));
9032
9033 json_object_int_add(json_peer, "tableVersion",
9034 peer->version[afi][safi]);
9035 json_object_int_add(json_peer, "outq",
9036 peer->obuf->count);
9037 json_object_int_add(json_peer, "inq", 0);
9038 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
9039 use_json, json_peer);
9040
9041 /*
9042 * Adding "pfxRcd" field to match with the corresponding
9043 * CLI. "prefixReceivedCount" will be deprecated in
9044 * future.
9045 */
9046 json_object_int_add(json_peer, "prefixReceivedCount",
9047 peer->pcount[afi][pfx_rcd_safi]);
9048 json_object_int_add(json_peer, "pfxRcd",
9049 peer->pcount[afi][pfx_rcd_safi]);
9050
9051 paf = peer_af_find(peer, afi, pfx_rcd_safi);
9052 if (paf && PAF_SUBGRP(paf))
9053 json_object_int_add(json_peer,
9054 "pfxSnt",
9055 (PAF_SUBGRP(paf))->scount);
9056 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
9057 json_object_string_add(json_peer, "state",
9058 "Idle (Admin)");
9059 else if (peer->afc_recv[afi][safi])
9060 json_object_string_add(
9061 json_peer, "state",
9062 lookup_msg(bgp_status_msg, peer->status,
9063 NULL));
9064 else if (CHECK_FLAG(peer->sflags,
9065 PEER_STATUS_PREFIX_OVERFLOW))
9066 json_object_string_add(json_peer, "state",
9067 "Idle (PfxCt)");
9068 else
9069 json_object_string_add(
9070 json_peer, "state",
9071 lookup_msg(bgp_status_msg, peer->status,
9072 NULL));
9073 json_object_int_add(json_peer, "connectionsEstablished",
9074 peer->established);
9075 json_object_int_add(json_peer, "connectionsDropped",
9076 peer->dropped);
9077 }
9078 /* Avoid creating empty peer dicts in JSON */
9079 if (json_peer == NULL)
9080 continue;
9081
9082 if (peer->conf_if)
9083 json_object_string_add(json_peer, "idType",
9084 "interface");
9085 else if (peer->su.sa.sa_family == AF_INET)
9086 json_object_string_add(json_peer, "idType",
9087 "ipv4");
9088 else if (peer->su.sa.sa_family == AF_INET6)
9089 json_object_string_add(json_peer, "idType",
9090 "ipv6");
9091 json_object_object_add(json_peers, peer->host,
9092 json_peer);
9093 } else {
9094 if (show_failed &&
9095 bgp_has_peer_failed(peer, afi, safi)) {
9096 bgp_show_failed_summary(vty, bgp, peer, NULL,
9097 max_neighbor_width,
9098 use_json);
9099 } else if (!show_failed) {
9100 memset(dn_flag, '\0', sizeof(dn_flag));
9101 if (peer_dynamic_neighbor(peer)) {
9102 dn_flag[0] = '*';
9103 }
9104
9105 if (peer->hostname
9106 && CHECK_FLAG(bgp->flags,
9107 BGP_FLAG_SHOW_HOSTNAME))
9108 len = vty_out(vty, "%s%s(%s)", dn_flag,
9109 peer->hostname,
9110 peer->host);
9111 else
9112 len = vty_out(vty, "%s%s", dn_flag, peer->host);
9113
9114 /* pad the neighbor column with spaces */
9115 if (len < max_neighbor_width)
9116 vty_out(vty, "%*s", max_neighbor_width - len,
9117 " ");
9118
9119 vty_out(vty, "4 %10u %7u %7u %8" PRIu64 " %4d %4zd %8s",
9120 peer->as, PEER_TOTAL_RX(peer),
9121 PEER_TOTAL_TX(peer), peer->version[afi][safi],
9122 0, peer->obuf->count,
9123 peer_uptime(peer->uptime, timebuf,
9124 BGP_UPTIME_LEN, 0, NULL));
9125
9126 if (peer->status == Established)
9127 if (peer->afc_recv[afi][safi])
9128 vty_out(vty, " %12" PRIu32,
9129 peer->pcount
9130 [afi]
9131 [pfx_rcd_safi]);
9132 else
9133 vty_out(vty, " NoNeg");
9134 else {
9135 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
9136 vty_out(vty, " Idle (Admin)");
9137 else if (CHECK_FLAG(
9138 peer->sflags,
9139 PEER_STATUS_PREFIX_OVERFLOW))
9140 vty_out(vty, " Idle (PfxCt)");
9141 else
9142 vty_out(vty, " %12s",
9143 lookup_msg(bgp_status_msg,
9144 peer->status, NULL));
9145 }
9146 vty_out(vty, "\n");
9147 }
9148
9149 }
9150 }
9151
9152 if (use_json) {
9153 json_object_object_add(json, "peers", json_peers);
9154 json_object_int_add(json, "failedPeers", failed_count);
9155 json_object_int_add(json, "totalPeers", count);
9156 json_object_int_add(json, "dynamicPeers", dn_count);
9157
9158 if (!show_failed)
9159 bgp_show_bestpath_json(bgp, json);
9160
9161 vty_out(vty, "%s\n", json_object_to_json_string_ext(
9162 json, JSON_C_TO_STRING_PRETTY));
9163 json_object_free(json);
9164 } else {
9165 if (count)
9166 vty_out(vty, "\nTotal number of neighbors %d\n", count);
9167 else {
9168 vty_out(vty, "No %s neighbor is configured\n",
9169 get_afi_safi_str(afi, safi, false));
9170 }
9171
9172 if (dn_count) {
9173 vty_out(vty, "* - dynamic neighbor\n");
9174 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
9175 dn_count, bgp->dynamic_neighbors_limit);
9176 }
9177 }
9178
9179 return CMD_SUCCESS;
9180 }
9181
9182 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
9183 int safi, bool show_failed, bool use_json)
9184 {
9185 int is_first = 1;
9186 int afi_wildcard = (afi == AFI_MAX);
9187 int safi_wildcard = (safi == SAFI_MAX);
9188 int is_wildcard = (afi_wildcard || safi_wildcard);
9189 bool nbr_output = false;
9190
9191 if (use_json && is_wildcard)
9192 vty_out(vty, "{\n");
9193 if (afi_wildcard)
9194 afi = 1; /* AFI_IP */
9195 while (afi < AFI_MAX) {
9196 if (safi_wildcard)
9197 safi = 1; /* SAFI_UNICAST */
9198 while (safi < SAFI_MAX) {
9199 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
9200 nbr_output = true;
9201
9202 if (is_wildcard) {
9203 /*
9204 * So limit output to those afi/safi
9205 * pairs that
9206 * actualy have something interesting in
9207 * them
9208 */
9209 if (use_json) {
9210 if (!is_first)
9211 vty_out(vty, ",\n");
9212 else
9213 is_first = 0;
9214
9215 vty_out(vty, "\"%s\":",
9216 get_afi_safi_str(afi,
9217 safi,
9218 true));
9219 } else {
9220 vty_out(vty, "\n%s Summary:\n",
9221 get_afi_safi_str(afi,
9222 safi,
9223 false));
9224 }
9225 }
9226 bgp_show_summary(vty, bgp, afi, safi, show_failed,
9227 use_json);
9228 }
9229 safi++;
9230 if (!safi_wildcard)
9231 safi = SAFI_MAX;
9232 }
9233 afi++;
9234 if (!afi_wildcard)
9235 afi = AFI_MAX;
9236 }
9237
9238 if (use_json && is_wildcard)
9239 vty_out(vty, "}\n");
9240 else if (!nbr_output) {
9241 if (use_json)
9242 vty_out(vty, "{}\n");
9243 else
9244 vty_out(vty, "%% No BGP neighbors found\n");
9245 }
9246 }
9247
9248 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
9249 safi_t safi, bool show_failed,
9250 bool use_json)
9251 {
9252 struct listnode *node, *nnode;
9253 struct bgp *bgp;
9254 int is_first = 1;
9255 bool nbr_output = false;
9256
9257 if (use_json)
9258 vty_out(vty, "{\n");
9259
9260 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9261 nbr_output = true;
9262 if (use_json) {
9263 if (!is_first)
9264 vty_out(vty, ",\n");
9265 else
9266 is_first = 0;
9267
9268 vty_out(vty, "\"%s\":",
9269 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
9270 ? VRF_DEFAULT_NAME
9271 : bgp->name);
9272 } else {
9273 vty_out(vty, "\nInstance %s:\n",
9274 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
9275 ? VRF_DEFAULT_NAME
9276 : bgp->name);
9277 }
9278 bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_failed,
9279 use_json);
9280 }
9281
9282 if (use_json)
9283 vty_out(vty, "}\n");
9284 else if (!nbr_output)
9285 vty_out(vty, "%% BGP instance not found\n");
9286 }
9287
9288 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
9289 safi_t safi, bool show_failed, bool use_json)
9290 {
9291 struct bgp *bgp;
9292
9293 if (name) {
9294 if (strmatch(name, "all")) {
9295 bgp_show_all_instances_summary_vty(vty, afi, safi,
9296 show_failed,
9297 use_json);
9298 return CMD_SUCCESS;
9299 } else {
9300 bgp = bgp_lookup_by_name(name);
9301
9302 if (!bgp) {
9303 if (use_json)
9304 vty_out(vty, "{}\n");
9305 else
9306 vty_out(vty,
9307 "%% BGP instance not found\n");
9308 return CMD_WARNING;
9309 }
9310
9311 bgp_show_summary_afi_safi(vty, bgp, afi, safi,
9312 show_failed, use_json);
9313 return CMD_SUCCESS;
9314 }
9315 }
9316
9317 bgp = bgp_get_default();
9318
9319 if (bgp)
9320 bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_failed,
9321 use_json);
9322 else {
9323 if (use_json)
9324 vty_out(vty, "{}\n");
9325 else
9326 vty_out(vty, "%% BGP instance not found\n");
9327 return CMD_WARNING;
9328 }
9329
9330 return CMD_SUCCESS;
9331 }
9332
9333 /* `show [ip] bgp summary' commands. */
9334 DEFUN (show_ip_bgp_summary,
9335 show_ip_bgp_summary_cmd,
9336 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [failed] [json]",
9337 SHOW_STR
9338 IP_STR
9339 BGP_STR
9340 BGP_INSTANCE_HELP_STR
9341 BGP_AFI_HELP_STR
9342 BGP_SAFI_WITH_LABEL_HELP_STR
9343 "Summary of BGP neighbor status\n"
9344 "Show only sessions not in Established state\n"
9345 JSON_STR)
9346 {
9347 char *vrf = NULL;
9348 afi_t afi = AFI_MAX;
9349 safi_t safi = SAFI_MAX;
9350 bool show_failed = false;
9351
9352 int idx = 0;
9353
9354 /* show [ip] bgp */
9355 if (argv_find(argv, argc, "ip", &idx))
9356 afi = AFI_IP;
9357 /* [<vrf> VIEWVRFNAME] */
9358 if (argv_find(argv, argc, "vrf", &idx)) {
9359 vrf = argv[idx + 1]->arg;
9360 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9361 vrf = NULL;
9362 } else if (argv_find(argv, argc, "view", &idx))
9363 /* [<view> VIEWVRFNAME] */
9364 vrf = argv[idx + 1]->arg;
9365 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
9366 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
9367 argv_find_and_parse_safi(argv, argc, &idx, &safi);
9368 }
9369
9370 if (argv_find(argv, argc, "failed", &idx))
9371 show_failed = true;
9372
9373 bool uj = use_json(argc, argv);
9374
9375 return bgp_show_summary_vty(vty, vrf, afi, safi, show_failed, uj);
9376 }
9377
9378 const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
9379 {
9380 if (for_json)
9381 return get_afi_safi_json_str(afi, safi);
9382 else
9383 return get_afi_safi_vty_str(afi, safi);
9384 }
9385
9386
9387 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
9388 afi_t afi, safi_t safi,
9389 uint16_t adv_smcap, uint16_t adv_rmcap,
9390 uint16_t rcv_smcap, uint16_t rcv_rmcap,
9391 bool use_json, json_object *json_pref)
9392 {
9393 /* Send-Mode */
9394 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
9395 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
9396 if (use_json) {
9397 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
9398 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
9399 json_object_string_add(json_pref, "sendMode",
9400 "advertisedAndReceived");
9401 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
9402 json_object_string_add(json_pref, "sendMode",
9403 "advertised");
9404 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
9405 json_object_string_add(json_pref, "sendMode",
9406 "received");
9407 } else {
9408 vty_out(vty, " Send-mode: ");
9409 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
9410 vty_out(vty, "advertised");
9411 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
9412 vty_out(vty, "%sreceived",
9413 CHECK_FLAG(p->af_cap[afi][safi],
9414 adv_smcap)
9415 ? ", "
9416 : "");
9417 vty_out(vty, "\n");
9418 }
9419 }
9420
9421 /* Receive-Mode */
9422 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
9423 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
9424 if (use_json) {
9425 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
9426 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
9427 json_object_string_add(json_pref, "recvMode",
9428 "advertisedAndReceived");
9429 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
9430 json_object_string_add(json_pref, "recvMode",
9431 "advertised");
9432 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
9433 json_object_string_add(json_pref, "recvMode",
9434 "received");
9435 } else {
9436 vty_out(vty, " Receive-mode: ");
9437 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
9438 vty_out(vty, "advertised");
9439 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
9440 vty_out(vty, "%sreceived",
9441 CHECK_FLAG(p->af_cap[afi][safi],
9442 adv_rmcap)
9443 ? ", "
9444 : "");
9445 vty_out(vty, "\n");
9446 }
9447 }
9448 }
9449
9450 static void bgp_show_neighnor_graceful_restart_rbit(struct vty *vty,
9451 struct peer *p,
9452 bool use_json,
9453 json_object *json)
9454 {
9455 bool rbit_status = 0;
9456
9457 if (!use_json)
9458 vty_out(vty, "\n R bit : ");
9459
9460 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
9461 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
9462 && (p->status == Established)) {
9463
9464 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_BIT_RCV))
9465 rbit_status = 1;
9466 else
9467 rbit_status = 0;
9468 }
9469
9470 if (rbit_status) {
9471 if (use_json)
9472 json_object_boolean_true_add(json, "rBit");
9473 else
9474 vty_out(vty, "True\n");
9475 } else {
9476 if (use_json)
9477 json_object_boolean_false_add(json, "rBit");
9478 else
9479 vty_out(vty, "False\n");
9480 }
9481 }
9482
9483 static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
9484 struct peer *peer,
9485 bool use_json,
9486 json_object *json)
9487 {
9488 const char *mode = "NotApplicable";
9489
9490 if (!use_json)
9491 vty_out(vty, "\n Remote GR Mode : ");
9492
9493 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
9494 && (peer->status == Established)) {
9495
9496 if ((peer->nsf_af_count == 0)
9497 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
9498
9499 mode = "Disable";
9500
9501 } else if (peer->nsf_af_count == 0
9502 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
9503
9504 mode = "Helper";
9505
9506 } else if (peer->nsf_af_count != 0
9507 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
9508
9509 mode = "Restart";
9510 }
9511 }
9512
9513 if (use_json) {
9514 json_object_string_add(json, "remoteGrMode", mode);
9515 } else
9516 vty_out(vty, mode, "\n");
9517 }
9518
9519 static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
9520 struct peer *p,
9521 bool use_json,
9522 json_object *json)
9523 {
9524 const char *mode = "Invalid";
9525
9526 if (!use_json)
9527 vty_out(vty, " Local GR Mode : ");
9528
9529 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
9530 mode = "Helper";
9531 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
9532 mode = "Restart";
9533 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
9534 mode = "Disable";
9535 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
9536 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
9537 mode = "Helper*";
9538 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
9539 mode = "Restart*";
9540 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
9541 mode = "Disable*";
9542 else
9543 mode = "Invalid*";
9544 }
9545
9546 if (use_json) {
9547 json_object_string_add(json, "localGrMode", mode);
9548 } else {
9549 vty_out(vty, mode, "\n");
9550 }
9551 }
9552
9553 static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
9554 struct vty *vty, struct peer *peer, bool use_json, json_object *json)
9555 {
9556 afi_t afi;
9557 safi_t safi;
9558 json_object *json_afi_safi = NULL;
9559 json_object *json_timer = NULL;
9560 json_object *json_endofrib_status = NULL;
9561 bool eor_flag = false;
9562
9563 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
9564 for (safi = SAFI_UNICAST; safi <= SAFI_MPLS_VPN; safi++) {
9565 if (!peer->afc[afi][safi])
9566 continue;
9567
9568 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
9569 || !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
9570 continue;
9571
9572 if (use_json) {
9573 json_afi_safi = json_object_new_object();
9574 json_endofrib_status = json_object_new_object();
9575 json_timer = json_object_new_object();
9576 }
9577
9578 if (peer->eor_stime[afi][safi]
9579 >= peer->pkt_stime[afi][safi])
9580 eor_flag = true;
9581 else
9582 eor_flag = false;
9583
9584 if (!use_json) {
9585 vty_out(vty, " %s :\n",
9586 get_afi_safi_str(afi, safi, false));
9587
9588 vty_out(vty, " F bit : ");
9589 }
9590
9591 if (peer->nsf[afi][safi]
9592 && CHECK_FLAG(peer->af_cap[afi][safi],
9593 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
9594
9595 if (use_json) {
9596 json_object_boolean_true_add(
9597 json_afi_safi, "fBit");
9598 } else
9599 vty_out(vty, "True\n");
9600 } else {
9601 if (use_json)
9602 json_object_boolean_false_add(
9603 json_afi_safi, "fBit");
9604 else
9605 vty_out(vty, "False\n");
9606 }
9607
9608 if (!use_json)
9609 vty_out(vty, " End-of-RIB Received : ");
9610
9611 if (CHECK_FLAG(peer->af_sflags[afi][safi],
9612 PEER_STATUS_EOR_RECEIVED)) {
9613 if (use_json)
9614 json_object_boolean_true_add(
9615 json_endofrib_status,
9616 "endOfRibRecv");
9617 else
9618 vty_out(vty, "Yes\n");
9619 } else {
9620 if (use_json)
9621 json_object_boolean_false_add(
9622 json_endofrib_status,
9623 "endOfRibRecv");
9624 else
9625 vty_out(vty, "No\n");
9626 }
9627
9628 if (!use_json)
9629 vty_out(vty, " End-of-RIB Send : ");
9630
9631 if (CHECK_FLAG(peer->af_sflags[afi][safi],
9632 PEER_STATUS_EOR_SEND)) {
9633 if (use_json) {
9634 json_object_boolean_true_add(
9635 json_endofrib_status,
9636 "endOfRibSend");
9637
9638 PRINT_EOR_JSON(eor_flag);
9639 } else {
9640 vty_out(vty, "Yes\n");
9641 vty_out(vty,
9642 " EoRSentAfterUpdate : ");
9643
9644 PRINT_EOR(eor_flag);
9645 }
9646 } else {
9647 if (use_json) {
9648 json_object_boolean_false_add(
9649 json_endofrib_status,
9650 "endOfRibSend");
9651 json_object_boolean_false_add(
9652 json_endofrib_status,
9653 "endOfRibSentAfterUpdate");
9654 } else {
9655 vty_out(vty, "No\n");
9656 vty_out(vty,
9657 " EoRSentAfterUpdate : ");
9658 vty_out(vty, "No\n");
9659 }
9660 }
9661
9662 if (use_json) {
9663 json_object_int_add(json_timer,
9664 "stalePathTimer",
9665 peer->bgp->stalepath_time);
9666
9667 if (peer->t_gr_stale != NULL) {
9668 json_object_int_add(
9669 json_timer,
9670 "stalePathTimerRemaining",
9671 thread_timer_remain_second(
9672 peer->t_gr_stale));
9673 }
9674
9675 /* Display Configured Selection
9676 * Deferral only when when
9677 * Gr mode is enabled.
9678 */
9679 if (CHECK_FLAG(peer->flags,
9680 PEER_FLAG_GRACEFUL_RESTART)) {
9681 json_object_int_add(
9682 json_timer,
9683 "selectionDeferralTimer",
9684 peer->bgp->stalepath_time);
9685 }
9686
9687 if (peer->bgp->gr_info[afi][safi]
9688 .t_select_deferral
9689 != NULL) {
9690
9691 json_object_int_add(
9692 json_timer,
9693 "selectionDeferralTimerRemaining",
9694 thread_timer_remain_second(
9695 peer->bgp
9696 ->gr_info[afi]
9697 [safi]
9698 .t_select_deferral));
9699 }
9700 } else {
9701 vty_out(vty, " Timers:\n");
9702
9703 vty_out(vty, "%*s", 6, "");
9704 vty_out(vty,
9705 "Configured Stale Path Time(sec)%*s: %u\n",
9706 8, "", peer->bgp->stalepath_time);
9707
9708 if (peer->t_gr_stale != NULL) {
9709 vty_out(vty, "%*s", 6, "");
9710 vty_out(vty,
9711 "Stale Path Remaining(sec)%*s: %ld\n",
9712 14, "",
9713 thread_timer_remain_second(
9714 peer->t_gr_stale));
9715 }
9716 /* Display Configured Selection
9717 * Deferral only when when
9718 * Gr mode is enabled.
9719 */
9720 if (CHECK_FLAG(peer->flags,
9721 PEER_FLAG_GRACEFUL_RESTART)) {
9722 vty_out(vty, "%*s", 6, "");
9723 vty_out(vty,
9724 "Configured Selection Deferral Time(sec): %u\n",
9725 peer->bgp->select_defer_time);
9726 }
9727
9728 if (peer->bgp->gr_info[afi][safi]
9729 .t_select_deferral
9730 != NULL) {
9731
9732 vty_out(vty, "%*s", 6, "");
9733 vty_out(vty,
9734 "Selection Deferral Time Remaining(sec) : %ld\n",
9735 thread_timer_remain_second(
9736 peer->bgp
9737 ->gr_info[afi]
9738 [safi]
9739 .t_select_deferral));
9740 }
9741 }
9742 if (use_json) {
9743 json_object_object_add(json_afi_safi,
9744 "endOfRibStatus",
9745 json_endofrib_status);
9746 json_object_object_add(json_afi_safi, "timers",
9747 json_timer);
9748 json_object_object_add(
9749 json, get_afi_safi_str(afi, safi, true),
9750 json_afi_safi);
9751 }
9752 }
9753 }
9754 }
9755
9756 static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
9757 struct peer *p,
9758 bool use_json,
9759 json_object *json)
9760 {
9761 if (use_json) {
9762 json_object *json_timer = NULL;
9763
9764 json_timer = json_object_new_object();
9765
9766 json_object_int_add(json_timer, "configuredRestartTimer",
9767 p->bgp->restart_time);
9768
9769 json_object_int_add(json_timer, "receivedRestartTimer",
9770 p->v_gr_restart);
9771
9772 if (p->t_gr_restart != NULL)
9773 json_object_int_add(
9774 json_timer, "restartTimerRemaining",
9775 thread_timer_remain_second(p->t_gr_restart));
9776
9777 json_object_object_add(json, "timers", json_timer);
9778 } else {
9779
9780 vty_out(vty, " Timers :\n");
9781 vty_out(vty, " Configured Restart Time(sec) : %u\n",
9782 p->bgp->restart_time);
9783
9784 vty_out(vty, " Received Restart Time(sec) : %u\n",
9785 p->v_gr_restart);
9786 if (p->t_gr_restart != NULL)
9787 vty_out(vty,
9788 " Restart Time Remaining(sec) : %ld\n",
9789 thread_timer_remain_second(p->t_gr_restart));
9790 if (p->t_gr_restart != NULL) {
9791 vty_out(vty,
9792 " Restart Time Remaining(sec) : %ld\n",
9793 thread_timer_remain_second(p->t_gr_restart));
9794 }
9795 }
9796 }
9797
9798 static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
9799 bool use_json, json_object *json)
9800 {
9801 char buf[SU_ADDRSTRLEN] = {0};
9802 char dn_flag[2] = {0};
9803 char neighborAddr[INET6_ADDRSTRLEN] = {0};
9804
9805 if (!p->conf_if && peer_dynamic_neighbor(p))
9806 dn_flag[0] = '*';
9807
9808 if (p->conf_if) {
9809 if (use_json)
9810 json_object_string_add(
9811 json, "neighborAddr",
9812 BGP_PEER_SU_UNSPEC(p)
9813 ? "none"
9814 : sockunion2str(&p->su, buf,
9815 SU_ADDRSTRLEN));
9816 else
9817 vty_out(vty, "BGP neighbor on %s: %s\n", p->conf_if,
9818 BGP_PEER_SU_UNSPEC(p)
9819 ? "none"
9820 : sockunion2str(&p->su, buf,
9821 SU_ADDRSTRLEN));
9822 } else {
9823 sprintf(neighborAddr, "%s%s", dn_flag, p->host);
9824
9825 if (use_json)
9826 json_object_string_add(json, "neighborAddr",
9827 neighborAddr);
9828 else
9829 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
9830 }
9831
9832 /* more gr info in new format */
9833 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json);
9834 }
9835
9836 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
9837 safi_t safi, bool use_json,
9838 json_object *json_neigh)
9839 {
9840 struct bgp_filter *filter;
9841 struct peer_af *paf;
9842 char orf_pfx_name[BUFSIZ];
9843 int orf_pfx_count;
9844 json_object *json_af = NULL;
9845 json_object *json_prefA = NULL;
9846 json_object *json_prefB = NULL;
9847 json_object *json_addr = NULL;
9848
9849 if (use_json) {
9850 json_addr = json_object_new_object();
9851 json_af = json_object_new_object();
9852 filter = &p->filter[afi][safi];
9853
9854 if (peer_group_active(p))
9855 json_object_string_add(json_addr, "peerGroupMember",
9856 p->group->name);
9857
9858 paf = peer_af_find(p, afi, safi);
9859 if (paf && PAF_SUBGRP(paf)) {
9860 json_object_int_add(json_addr, "updateGroupId",
9861 PAF_UPDGRP(paf)->id);
9862 json_object_int_add(json_addr, "subGroupId",
9863 PAF_SUBGRP(paf)->id);
9864 json_object_int_add(json_addr, "packetQueueLength",
9865 bpacket_queue_virtual_length(paf));
9866 }
9867
9868 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
9869 || CHECK_FLAG(p->af_cap[afi][safi],
9870 PEER_CAP_ORF_PREFIX_SM_RCV)
9871 || CHECK_FLAG(p->af_cap[afi][safi],
9872 PEER_CAP_ORF_PREFIX_RM_ADV)
9873 || CHECK_FLAG(p->af_cap[afi][safi],
9874 PEER_CAP_ORF_PREFIX_RM_RCV)) {
9875 json_object_int_add(json_af, "orfType",
9876 ORF_TYPE_PREFIX);
9877 json_prefA = json_object_new_object();
9878 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
9879 PEER_CAP_ORF_PREFIX_SM_ADV,
9880 PEER_CAP_ORF_PREFIX_RM_ADV,
9881 PEER_CAP_ORF_PREFIX_SM_RCV,
9882 PEER_CAP_ORF_PREFIX_RM_RCV,
9883 use_json, json_prefA);
9884 json_object_object_add(json_af, "orfPrefixList",
9885 json_prefA);
9886 }
9887
9888 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
9889 || CHECK_FLAG(p->af_cap[afi][safi],
9890 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
9891 || CHECK_FLAG(p->af_cap[afi][safi],
9892 PEER_CAP_ORF_PREFIX_RM_ADV)
9893 || CHECK_FLAG(p->af_cap[afi][safi],
9894 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
9895 json_object_int_add(json_af, "orfOldType",
9896 ORF_TYPE_PREFIX_OLD);
9897 json_prefB = json_object_new_object();
9898 bgp_show_peer_afi_orf_cap(
9899 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
9900 PEER_CAP_ORF_PREFIX_RM_ADV,
9901 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
9902 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
9903 json_prefB);
9904 json_object_object_add(json_af, "orfOldPrefixList",
9905 json_prefB);
9906 }
9907
9908 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
9909 || CHECK_FLAG(p->af_cap[afi][safi],
9910 PEER_CAP_ORF_PREFIX_SM_RCV)
9911 || CHECK_FLAG(p->af_cap[afi][safi],
9912 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
9913 || CHECK_FLAG(p->af_cap[afi][safi],
9914 PEER_CAP_ORF_PREFIX_RM_ADV)
9915 || CHECK_FLAG(p->af_cap[afi][safi],
9916 PEER_CAP_ORF_PREFIX_RM_RCV)
9917 || CHECK_FLAG(p->af_cap[afi][safi],
9918 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
9919 json_object_object_add(json_addr, "afDependentCap",
9920 json_af);
9921 else
9922 json_object_free(json_af);
9923
9924 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
9925 orf_pfx_count = prefix_bgp_show_prefix_list(
9926 NULL, afi, orf_pfx_name, use_json);
9927
9928 if (CHECK_FLAG(p->af_sflags[afi][safi],
9929 PEER_STATUS_ORF_PREFIX_SEND)
9930 || orf_pfx_count) {
9931 if (CHECK_FLAG(p->af_sflags[afi][safi],
9932 PEER_STATUS_ORF_PREFIX_SEND))
9933 json_object_boolean_true_add(json_neigh,
9934 "orfSent");
9935 if (orf_pfx_count)
9936 json_object_int_add(json_addr, "orfRecvCounter",
9937 orf_pfx_count);
9938 }
9939 if (CHECK_FLAG(p->af_sflags[afi][safi],
9940 PEER_STATUS_ORF_WAIT_REFRESH))
9941 json_object_string_add(
9942 json_addr, "orfFirstUpdate",
9943 "deferredUntilORFOrRouteRefreshRecvd");
9944
9945 if (CHECK_FLAG(p->af_flags[afi][safi],
9946 PEER_FLAG_REFLECTOR_CLIENT))
9947 json_object_boolean_true_add(json_addr,
9948 "routeReflectorClient");
9949 if (CHECK_FLAG(p->af_flags[afi][safi],
9950 PEER_FLAG_RSERVER_CLIENT))
9951 json_object_boolean_true_add(json_addr,
9952 "routeServerClient");
9953 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9954 json_object_boolean_true_add(json_addr,
9955 "inboundSoftConfigPermit");
9956
9957 if (CHECK_FLAG(p->af_flags[afi][safi],
9958 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
9959 json_object_boolean_true_add(
9960 json_addr,
9961 "privateAsNumsAllReplacedInUpdatesToNbr");
9962 else if (CHECK_FLAG(p->af_flags[afi][safi],
9963 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
9964 json_object_boolean_true_add(
9965 json_addr,
9966 "privateAsNumsReplacedInUpdatesToNbr");
9967 else if (CHECK_FLAG(p->af_flags[afi][safi],
9968 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
9969 json_object_boolean_true_add(
9970 json_addr,
9971 "privateAsNumsAllRemovedInUpdatesToNbr");
9972 else if (CHECK_FLAG(p->af_flags[afi][safi],
9973 PEER_FLAG_REMOVE_PRIVATE_AS))
9974 json_object_boolean_true_add(
9975 json_addr,
9976 "privateAsNumsRemovedInUpdatesToNbr");
9977
9978 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
9979 json_object_boolean_true_add(
9980 json_addr,
9981 bgp_addpath_names(p->addpath_type[afi][safi])
9982 ->type_json_name);
9983
9984 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
9985 json_object_string_add(json_addr,
9986 "overrideASNsInOutboundUpdates",
9987 "ifAspathEqualRemoteAs");
9988
9989 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
9990 || CHECK_FLAG(p->af_flags[afi][safi],
9991 PEER_FLAG_FORCE_NEXTHOP_SELF))
9992 json_object_boolean_true_add(json_addr,
9993 "routerAlwaysNextHop");
9994 if (CHECK_FLAG(p->af_flags[afi][safi],
9995 PEER_FLAG_AS_PATH_UNCHANGED))
9996 json_object_boolean_true_add(
9997 json_addr, "unchangedAsPathPropogatedToNbr");
9998 if (CHECK_FLAG(p->af_flags[afi][safi],
9999 PEER_FLAG_NEXTHOP_UNCHANGED))
10000 json_object_boolean_true_add(
10001 json_addr, "unchangedNextHopPropogatedToNbr");
10002 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
10003 json_object_boolean_true_add(
10004 json_addr, "unchangedMedPropogatedToNbr");
10005 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
10006 || CHECK_FLAG(p->af_flags[afi][safi],
10007 PEER_FLAG_SEND_EXT_COMMUNITY)) {
10008 if (CHECK_FLAG(p->af_flags[afi][safi],
10009 PEER_FLAG_SEND_COMMUNITY)
10010 && CHECK_FLAG(p->af_flags[afi][safi],
10011 PEER_FLAG_SEND_EXT_COMMUNITY))
10012 json_object_string_add(json_addr,
10013 "commAttriSentToNbr",
10014 "extendedAndStandard");
10015 else if (CHECK_FLAG(p->af_flags[afi][safi],
10016 PEER_FLAG_SEND_EXT_COMMUNITY))
10017 json_object_string_add(json_addr,
10018 "commAttriSentToNbr",
10019 "extended");
10020 else
10021 json_object_string_add(json_addr,
10022 "commAttriSentToNbr",
10023 "standard");
10024 }
10025 if (CHECK_FLAG(p->af_flags[afi][safi],
10026 PEER_FLAG_DEFAULT_ORIGINATE)) {
10027 if (p->default_rmap[afi][safi].name)
10028 json_object_string_add(
10029 json_addr, "defaultRouteMap",
10030 p->default_rmap[afi][safi].name);
10031
10032 if (paf && PAF_SUBGRP(paf)
10033 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
10034 SUBGRP_STATUS_DEFAULT_ORIGINATE))
10035 json_object_boolean_true_add(json_addr,
10036 "defaultSent");
10037 else
10038 json_object_boolean_true_add(json_addr,
10039 "defaultNotSent");
10040 }
10041
10042 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
10043 if (is_evpn_enabled())
10044 json_object_boolean_true_add(
10045 json_addr, "advertiseAllVnis");
10046 }
10047
10048 if (filter->plist[FILTER_IN].name
10049 || filter->dlist[FILTER_IN].name
10050 || filter->aslist[FILTER_IN].name
10051 || filter->map[RMAP_IN].name)
10052 json_object_boolean_true_add(json_addr,
10053 "inboundPathPolicyConfig");
10054 if (filter->plist[FILTER_OUT].name
10055 || filter->dlist[FILTER_OUT].name
10056 || filter->aslist[FILTER_OUT].name
10057 || filter->map[RMAP_OUT].name || filter->usmap.name)
10058 json_object_boolean_true_add(
10059 json_addr, "outboundPathPolicyConfig");
10060
10061 /* prefix-list */
10062 if (filter->plist[FILTER_IN].name)
10063 json_object_string_add(json_addr,
10064 "incomingUpdatePrefixFilterList",
10065 filter->plist[FILTER_IN].name);
10066 if (filter->plist[FILTER_OUT].name)
10067 json_object_string_add(json_addr,
10068 "outgoingUpdatePrefixFilterList",
10069 filter->plist[FILTER_OUT].name);
10070
10071 /* distribute-list */
10072 if (filter->dlist[FILTER_IN].name)
10073 json_object_string_add(
10074 json_addr, "incomingUpdateNetworkFilterList",
10075 filter->dlist[FILTER_IN].name);
10076 if (filter->dlist[FILTER_OUT].name)
10077 json_object_string_add(
10078 json_addr, "outgoingUpdateNetworkFilterList",
10079 filter->dlist[FILTER_OUT].name);
10080
10081 /* filter-list. */
10082 if (filter->aslist[FILTER_IN].name)
10083 json_object_string_add(json_addr,
10084 "incomingUpdateAsPathFilterList",
10085 filter->aslist[FILTER_IN].name);
10086 if (filter->aslist[FILTER_OUT].name)
10087 json_object_string_add(json_addr,
10088 "outgoingUpdateAsPathFilterList",
10089 filter->aslist[FILTER_OUT].name);
10090
10091 /* route-map. */
10092 if (filter->map[RMAP_IN].name)
10093 json_object_string_add(
10094 json_addr, "routeMapForIncomingAdvertisements",
10095 filter->map[RMAP_IN].name);
10096 if (filter->map[RMAP_OUT].name)
10097 json_object_string_add(
10098 json_addr, "routeMapForOutgoingAdvertisements",
10099 filter->map[RMAP_OUT].name);
10100
10101 /* ebgp-requires-policy (inbound) */
10102 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
10103 && !bgp_inbound_policy_exists(p, filter))
10104 json_object_string_add(
10105 json_addr, "inboundEbgpRequiresPolicy",
10106 "Inbound updates discarded due to missing policy");
10107
10108 /* ebgp-requires-policy (outbound) */
10109 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
10110 && (!bgp_outbound_policy_exists(p, filter)))
10111 json_object_string_add(
10112 json_addr, "outboundEbgpRequiresPolicy",
10113 "Outbound updates discarded due to missing policy");
10114
10115 /* unsuppress-map */
10116 if (filter->usmap.name)
10117 json_object_string_add(json_addr,
10118 "selectiveUnsuppressRouteMap",
10119 filter->usmap.name);
10120
10121 /* Receive prefix count */
10122 json_object_int_add(json_addr, "acceptedPrefixCounter",
10123 p->pcount[afi][safi]);
10124 if (paf && PAF_SUBGRP(paf))
10125 json_object_int_add(json_addr, "sentPrefixCounter",
10126 (PAF_SUBGRP(paf))->scount);
10127
10128 /* Maximum prefix */
10129 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
10130 json_object_int_add(json_addr, "prefixOutAllowedMax",
10131 p->pmax_out[afi][safi]);
10132
10133 /* Maximum prefix */
10134 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
10135 json_object_int_add(json_addr, "prefixAllowedMax",
10136 p->pmax[afi][safi]);
10137 if (CHECK_FLAG(p->af_flags[afi][safi],
10138 PEER_FLAG_MAX_PREFIX_WARNING))
10139 json_object_boolean_true_add(
10140 json_addr, "prefixAllowedMaxWarning");
10141 json_object_int_add(json_addr,
10142 "prefixAllowedWarningThresh",
10143 p->pmax_threshold[afi][safi]);
10144 if (p->pmax_restart[afi][safi])
10145 json_object_int_add(
10146 json_addr,
10147 "prefixAllowedRestartIntervalMsecs",
10148 p->pmax_restart[afi][safi] * 60000);
10149 }
10150 json_object_object_add(json_neigh,
10151 get_afi_safi_str(afi, safi, true),
10152 json_addr);
10153
10154 } else {
10155 filter = &p->filter[afi][safi];
10156
10157 vty_out(vty, " For address family: %s\n",
10158 get_afi_safi_str(afi, safi, false));
10159
10160 if (peer_group_active(p))
10161 vty_out(vty, " %s peer-group member\n",
10162 p->group->name);
10163
10164 paf = peer_af_find(p, afi, safi);
10165 if (paf && PAF_SUBGRP(paf)) {
10166 vty_out(vty, " Update group %" PRIu64
10167 ", subgroup %" PRIu64 "\n",
10168 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
10169 vty_out(vty, " Packet Queue length %d\n",
10170 bpacket_queue_virtual_length(paf));
10171 } else {
10172 vty_out(vty, " Not part of any update group\n");
10173 }
10174 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
10175 || CHECK_FLAG(p->af_cap[afi][safi],
10176 PEER_CAP_ORF_PREFIX_SM_RCV)
10177 || CHECK_FLAG(p->af_cap[afi][safi],
10178 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
10179 || CHECK_FLAG(p->af_cap[afi][safi],
10180 PEER_CAP_ORF_PREFIX_RM_ADV)
10181 || CHECK_FLAG(p->af_cap[afi][safi],
10182 PEER_CAP_ORF_PREFIX_RM_RCV)
10183 || CHECK_FLAG(p->af_cap[afi][safi],
10184 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
10185 vty_out(vty, " AF-dependant capabilities:\n");
10186
10187 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
10188 || CHECK_FLAG(p->af_cap[afi][safi],
10189 PEER_CAP_ORF_PREFIX_SM_RCV)
10190 || CHECK_FLAG(p->af_cap[afi][safi],
10191 PEER_CAP_ORF_PREFIX_RM_ADV)
10192 || CHECK_FLAG(p->af_cap[afi][safi],
10193 PEER_CAP_ORF_PREFIX_RM_RCV)) {
10194 vty_out(vty,
10195 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
10196 ORF_TYPE_PREFIX);
10197 bgp_show_peer_afi_orf_cap(
10198 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
10199 PEER_CAP_ORF_PREFIX_RM_ADV,
10200 PEER_CAP_ORF_PREFIX_SM_RCV,
10201 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
10202 }
10203 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
10204 || CHECK_FLAG(p->af_cap[afi][safi],
10205 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
10206 || CHECK_FLAG(p->af_cap[afi][safi],
10207 PEER_CAP_ORF_PREFIX_RM_ADV)
10208 || CHECK_FLAG(p->af_cap[afi][safi],
10209 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
10210 vty_out(vty,
10211 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
10212 ORF_TYPE_PREFIX_OLD);
10213 bgp_show_peer_afi_orf_cap(
10214 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
10215 PEER_CAP_ORF_PREFIX_RM_ADV,
10216 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
10217 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
10218 }
10219
10220 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
10221 orf_pfx_count = prefix_bgp_show_prefix_list(
10222 NULL, afi, orf_pfx_name, use_json);
10223
10224 if (CHECK_FLAG(p->af_sflags[afi][safi],
10225 PEER_STATUS_ORF_PREFIX_SEND)
10226 || orf_pfx_count) {
10227 vty_out(vty, " Outbound Route Filter (ORF):");
10228 if (CHECK_FLAG(p->af_sflags[afi][safi],
10229 PEER_STATUS_ORF_PREFIX_SEND))
10230 vty_out(vty, " sent;");
10231 if (orf_pfx_count)
10232 vty_out(vty, " received (%d entries)",
10233 orf_pfx_count);
10234 vty_out(vty, "\n");
10235 }
10236 if (CHECK_FLAG(p->af_sflags[afi][safi],
10237 PEER_STATUS_ORF_WAIT_REFRESH))
10238 vty_out(vty,
10239 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
10240
10241 if (CHECK_FLAG(p->af_flags[afi][safi],
10242 PEER_FLAG_REFLECTOR_CLIENT))
10243 vty_out(vty, " Route-Reflector Client\n");
10244 if (CHECK_FLAG(p->af_flags[afi][safi],
10245 PEER_FLAG_RSERVER_CLIENT))
10246 vty_out(vty, " Route-Server Client\n");
10247 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
10248 vty_out(vty,
10249 " Inbound soft reconfiguration allowed\n");
10250
10251 if (CHECK_FLAG(p->af_flags[afi][safi],
10252 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
10253 vty_out(vty,
10254 " Private AS numbers (all) replaced in updates to this neighbor\n");
10255 else if (CHECK_FLAG(p->af_flags[afi][safi],
10256 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
10257 vty_out(vty,
10258 " Private AS numbers replaced in updates to this neighbor\n");
10259 else if (CHECK_FLAG(p->af_flags[afi][safi],
10260 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
10261 vty_out(vty,
10262 " Private AS numbers (all) removed in updates to this neighbor\n");
10263 else if (CHECK_FLAG(p->af_flags[afi][safi],
10264 PEER_FLAG_REMOVE_PRIVATE_AS))
10265 vty_out(vty,
10266 " Private AS numbers removed in updates to this neighbor\n");
10267
10268 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
10269 vty_out(vty, " %s\n",
10270 bgp_addpath_names(p->addpath_type[afi][safi])
10271 ->human_description);
10272
10273 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
10274 vty_out(vty,
10275 " Override ASNs in outbound updates if aspath equals remote-as\n");
10276
10277 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
10278 || CHECK_FLAG(p->af_flags[afi][safi],
10279 PEER_FLAG_FORCE_NEXTHOP_SELF))
10280 vty_out(vty, " NEXT_HOP is always this router\n");
10281 if (CHECK_FLAG(p->af_flags[afi][safi],
10282 PEER_FLAG_AS_PATH_UNCHANGED))
10283 vty_out(vty,
10284 " AS_PATH is propagated unchanged to this neighbor\n");
10285 if (CHECK_FLAG(p->af_flags[afi][safi],
10286 PEER_FLAG_NEXTHOP_UNCHANGED))
10287 vty_out(vty,
10288 " NEXT_HOP is propagated unchanged to this neighbor\n");
10289 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
10290 vty_out(vty,
10291 " MED is propagated unchanged to this neighbor\n");
10292 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
10293 || CHECK_FLAG(p->af_flags[afi][safi],
10294 PEER_FLAG_SEND_EXT_COMMUNITY)
10295 || CHECK_FLAG(p->af_flags[afi][safi],
10296 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
10297 vty_out(vty,
10298 " Community attribute sent to this neighbor");
10299 if (CHECK_FLAG(p->af_flags[afi][safi],
10300 PEER_FLAG_SEND_COMMUNITY)
10301 && CHECK_FLAG(p->af_flags[afi][safi],
10302 PEER_FLAG_SEND_EXT_COMMUNITY)
10303 && CHECK_FLAG(p->af_flags[afi][safi],
10304 PEER_FLAG_SEND_LARGE_COMMUNITY))
10305 vty_out(vty, "(all)\n");
10306 else if (CHECK_FLAG(p->af_flags[afi][safi],
10307 PEER_FLAG_SEND_LARGE_COMMUNITY))
10308 vty_out(vty, "(large)\n");
10309 else if (CHECK_FLAG(p->af_flags[afi][safi],
10310 PEER_FLAG_SEND_EXT_COMMUNITY))
10311 vty_out(vty, "(extended)\n");
10312 else
10313 vty_out(vty, "(standard)\n");
10314 }
10315 if (CHECK_FLAG(p->af_flags[afi][safi],
10316 PEER_FLAG_DEFAULT_ORIGINATE)) {
10317 vty_out(vty, " Default information originate,");
10318
10319 if (p->default_rmap[afi][safi].name)
10320 vty_out(vty, " default route-map %s%s,",
10321 p->default_rmap[afi][safi].map ? "*"
10322 : "",
10323 p->default_rmap[afi][safi].name);
10324 if (paf && PAF_SUBGRP(paf)
10325 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
10326 SUBGRP_STATUS_DEFAULT_ORIGINATE))
10327 vty_out(vty, " default sent\n");
10328 else
10329 vty_out(vty, " default not sent\n");
10330 }
10331
10332 /* advertise-vni-all */
10333 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
10334 if (is_evpn_enabled())
10335 vty_out(vty, " advertise-all-vni\n");
10336 }
10337
10338 if (filter->plist[FILTER_IN].name
10339 || filter->dlist[FILTER_IN].name
10340 || filter->aslist[FILTER_IN].name
10341 || filter->map[RMAP_IN].name)
10342 vty_out(vty, " Inbound path policy configured\n");
10343 if (filter->plist[FILTER_OUT].name
10344 || filter->dlist[FILTER_OUT].name
10345 || filter->aslist[FILTER_OUT].name
10346 || filter->map[RMAP_OUT].name || filter->usmap.name)
10347 vty_out(vty, " Outbound path policy configured\n");
10348
10349 /* prefix-list */
10350 if (filter->plist[FILTER_IN].name)
10351 vty_out(vty,
10352 " Incoming update prefix filter list is %s%s\n",
10353 filter->plist[FILTER_IN].plist ? "*" : "",
10354 filter->plist[FILTER_IN].name);
10355 if (filter->plist[FILTER_OUT].name)
10356 vty_out(vty,
10357 " Outgoing update prefix filter list is %s%s\n",
10358 filter->plist[FILTER_OUT].plist ? "*" : "",
10359 filter->plist[FILTER_OUT].name);
10360
10361 /* distribute-list */
10362 if (filter->dlist[FILTER_IN].name)
10363 vty_out(vty,
10364 " Incoming update network filter list is %s%s\n",
10365 filter->dlist[FILTER_IN].alist ? "*" : "",
10366 filter->dlist[FILTER_IN].name);
10367 if (filter->dlist[FILTER_OUT].name)
10368 vty_out(vty,
10369 " Outgoing update network filter list is %s%s\n",
10370 filter->dlist[FILTER_OUT].alist ? "*" : "",
10371 filter->dlist[FILTER_OUT].name);
10372
10373 /* filter-list. */
10374 if (filter->aslist[FILTER_IN].name)
10375 vty_out(vty,
10376 " Incoming update AS path filter list is %s%s\n",
10377 filter->aslist[FILTER_IN].aslist ? "*" : "",
10378 filter->aslist[FILTER_IN].name);
10379 if (filter->aslist[FILTER_OUT].name)
10380 vty_out(vty,
10381 " Outgoing update AS path filter list is %s%s\n",
10382 filter->aslist[FILTER_OUT].aslist ? "*" : "",
10383 filter->aslist[FILTER_OUT].name);
10384
10385 /* route-map. */
10386 if (filter->map[RMAP_IN].name)
10387 vty_out(vty,
10388 " Route map for incoming advertisements is %s%s\n",
10389 filter->map[RMAP_IN].map ? "*" : "",
10390 filter->map[RMAP_IN].name);
10391 if (filter->map[RMAP_OUT].name)
10392 vty_out(vty,
10393 " Route map for outgoing advertisements is %s%s\n",
10394 filter->map[RMAP_OUT].map ? "*" : "",
10395 filter->map[RMAP_OUT].name);
10396
10397 /* ebgp-requires-policy (inbound) */
10398 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
10399 && !bgp_inbound_policy_exists(p, filter))
10400 vty_out(vty,
10401 " Inbound updates discarded due to missing policy\n");
10402
10403 /* ebgp-requires-policy (outbound) */
10404 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
10405 && !bgp_outbound_policy_exists(p, filter))
10406 vty_out(vty,
10407 " Outbound updates discarded due to missing policy\n");
10408
10409 /* unsuppress-map */
10410 if (filter->usmap.name)
10411 vty_out(vty,
10412 " Route map for selective unsuppress is %s%s\n",
10413 filter->usmap.map ? "*" : "",
10414 filter->usmap.name);
10415
10416 /* Receive prefix count */
10417 vty_out(vty, " %" PRIu32 " accepted prefixes\n",
10418 p->pcount[afi][safi]);
10419
10420 /* maximum-prefix-out */
10421 if (CHECK_FLAG(p->af_flags[afi][safi],
10422 PEER_FLAG_MAX_PREFIX_OUT))
10423 vty_out(vty,
10424 " Maximum allowed prefixes sent %" PRIu32 "\n",
10425 p->pmax_out[afi][safi]);
10426
10427 /* Maximum prefix */
10428 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
10429 vty_out(vty,
10430 " Maximum prefixes allowed %" PRIu32 "%s\n",
10431 p->pmax[afi][safi],
10432 CHECK_FLAG(p->af_flags[afi][safi],
10433 PEER_FLAG_MAX_PREFIX_WARNING)
10434 ? " (warning-only)"
10435 : "");
10436 vty_out(vty, " Threshold for warning message %d%%",
10437 p->pmax_threshold[afi][safi]);
10438 if (p->pmax_restart[afi][safi])
10439 vty_out(vty, ", restart interval %d min",
10440 p->pmax_restart[afi][safi]);
10441 vty_out(vty, "\n");
10442 }
10443
10444 vty_out(vty, "\n");
10445 }
10446 }
10447
10448 static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
10449 json_object *json)
10450 {
10451 struct bgp *bgp;
10452 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
10453 char timebuf[BGP_UPTIME_LEN];
10454 char dn_flag[2];
10455 afi_t afi;
10456 safi_t safi;
10457 uint16_t i;
10458 uint8_t *msg;
10459 json_object *json_neigh = NULL;
10460 time_t epoch_tbuf;
10461
10462 bgp = p->bgp;
10463
10464 if (use_json)
10465 json_neigh = json_object_new_object();
10466
10467 memset(dn_flag, '\0', sizeof(dn_flag));
10468 if (!p->conf_if && peer_dynamic_neighbor(p))
10469 dn_flag[0] = '*';
10470
10471 if (!use_json) {
10472 if (p->conf_if) /* Configured interface name. */
10473 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
10474 BGP_PEER_SU_UNSPEC(p)
10475 ? "None"
10476 : sockunion2str(&p->su, buf,
10477 SU_ADDRSTRLEN));
10478 else /* Configured IP address. */
10479 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
10480 p->host);
10481 }
10482
10483 if (use_json) {
10484 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
10485 json_object_string_add(json_neigh, "bgpNeighborAddr",
10486 "none");
10487 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
10488 json_object_string_add(
10489 json_neigh, "bgpNeighborAddr",
10490 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
10491
10492 json_object_int_add(json_neigh, "remoteAs", p->as);
10493
10494 if (p->change_local_as)
10495 json_object_int_add(json_neigh, "localAs",
10496 p->change_local_as);
10497 else
10498 json_object_int_add(json_neigh, "localAs", p->local_as);
10499
10500 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
10501 json_object_boolean_true_add(json_neigh,
10502 "localAsNoPrepend");
10503
10504 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
10505 json_object_boolean_true_add(json_neigh,
10506 "localAsReplaceAs");
10507 } else {
10508 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
10509 || (p->as_type == AS_INTERNAL))
10510 vty_out(vty, "remote AS %u, ", p->as);
10511 else
10512 vty_out(vty, "remote AS Unspecified, ");
10513 vty_out(vty, "local AS %u%s%s, ",
10514 p->change_local_as ? p->change_local_as : p->local_as,
10515 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
10516 ? " no-prepend"
10517 : "",
10518 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
10519 ? " replace-as"
10520 : "");
10521 }
10522 /* peer type internal or confed-internal */
10523 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
10524 if (use_json) {
10525 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
10526 json_object_boolean_true_add(
10527 json_neigh, "nbrConfedInternalLink");
10528 else
10529 json_object_boolean_true_add(json_neigh,
10530 "nbrInternalLink");
10531 } else {
10532 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
10533 vty_out(vty, "confed-internal link\n");
10534 else
10535 vty_out(vty, "internal link\n");
10536 }
10537 /* peer type external or confed-external */
10538 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
10539 if (use_json) {
10540 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
10541 json_object_boolean_true_add(
10542 json_neigh, "nbrConfedExternalLink");
10543 else
10544 json_object_boolean_true_add(json_neigh,
10545 "nbrExternalLink");
10546 } else {
10547 if (bgp_confederation_peers_check(bgp, p->as))
10548 vty_out(vty, "confed-external link\n");
10549 else
10550 vty_out(vty, "external link\n");
10551 }
10552 } else {
10553 if (use_json)
10554 json_object_boolean_true_add(json_neigh,
10555 "nbrUnspecifiedLink");
10556 else
10557 vty_out(vty, "unspecified link\n");
10558 }
10559
10560 /* Description. */
10561 if (p->desc) {
10562 if (use_json)
10563 json_object_string_add(json_neigh, "nbrDesc", p->desc);
10564 else
10565 vty_out(vty, " Description: %s\n", p->desc);
10566 }
10567
10568 if (p->hostname) {
10569 if (use_json) {
10570 if (p->hostname)
10571 json_object_string_add(json_neigh, "hostname",
10572 p->hostname);
10573
10574 if (p->domainname)
10575 json_object_string_add(json_neigh, "domainname",
10576 p->domainname);
10577 } else {
10578 if (p->domainname && (p->domainname[0] != '\0'))
10579 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
10580 p->domainname);
10581 else
10582 vty_out(vty, "Hostname: %s\n", p->hostname);
10583 }
10584 }
10585
10586 /* Peer-group */
10587 if (p->group) {
10588 if (use_json) {
10589 json_object_string_add(json_neigh, "peerGroup",
10590 p->group->name);
10591
10592 if (dn_flag[0]) {
10593 struct prefix prefix, *range = NULL;
10594
10595 sockunion2hostprefix(&(p->su), &prefix);
10596 range = peer_group_lookup_dynamic_neighbor_range(
10597 p->group, &prefix);
10598
10599 if (range) {
10600 prefix2str(range, buf1, sizeof(buf1));
10601 json_object_string_add(
10602 json_neigh,
10603 "peerSubnetRangeGroup", buf1);
10604 }
10605 }
10606 } else {
10607 vty_out(vty,
10608 " Member of peer-group %s for session parameters\n",
10609 p->group->name);
10610
10611 if (dn_flag[0]) {
10612 struct prefix prefix, *range = NULL;
10613
10614 sockunion2hostprefix(&(p->su), &prefix);
10615 range = peer_group_lookup_dynamic_neighbor_range(
10616 p->group, &prefix);
10617
10618 if (range) {
10619 prefix2str(range, buf1, sizeof(buf1));
10620 vty_out(vty,
10621 " Belongs to the subnet range group: %s\n",
10622 buf1);
10623 }
10624 }
10625 }
10626 }
10627
10628 if (use_json) {
10629 /* Administrative shutdown. */
10630 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
10631 json_object_boolean_true_add(json_neigh,
10632 "adminShutDown");
10633
10634 /* BGP Version. */
10635 json_object_int_add(json_neigh, "bgpVersion", 4);
10636 json_object_string_add(
10637 json_neigh, "remoteRouterId",
10638 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
10639 json_object_string_add(
10640 json_neigh, "localRouterId",
10641 inet_ntop(AF_INET, &bgp->router_id, buf1,
10642 sizeof(buf1)));
10643
10644 /* Confederation */
10645 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
10646 && bgp_confederation_peers_check(bgp, p->as))
10647 json_object_boolean_true_add(json_neigh,
10648 "nbrCommonAdmin");
10649
10650 /* Status. */
10651 json_object_string_add(
10652 json_neigh, "bgpState",
10653 lookup_msg(bgp_status_msg, p->status, NULL));
10654
10655 if (p->status == Established) {
10656 time_t uptime;
10657
10658 uptime = bgp_clock();
10659 uptime -= p->uptime;
10660 epoch_tbuf = time(NULL) - uptime;
10661
10662 json_object_int_add(json_neigh, "bgpTimerUpMsec",
10663 uptime * 1000);
10664 json_object_string_add(json_neigh, "bgpTimerUpString",
10665 peer_uptime(p->uptime, timebuf,
10666 BGP_UPTIME_LEN, 0,
10667 NULL));
10668 json_object_int_add(json_neigh,
10669 "bgpTimerUpEstablishedEpoch",
10670 epoch_tbuf);
10671 }
10672
10673 else if (p->status == Active) {
10674 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
10675 json_object_string_add(json_neigh, "bgpStateIs",
10676 "passive");
10677 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
10678 json_object_string_add(json_neigh, "bgpStateIs",
10679 "passiveNSF");
10680 }
10681
10682 /* read timer */
10683 time_t uptime;
10684 struct tm *tm;
10685
10686 uptime = bgp_clock();
10687 uptime -= p->readtime;
10688 tm = gmtime(&uptime);
10689 json_object_int_add(json_neigh, "bgpTimerLastRead",
10690 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
10691 + (tm->tm_hour * 3600000));
10692
10693 uptime = bgp_clock();
10694 uptime -= p->last_write;
10695 tm = gmtime(&uptime);
10696 json_object_int_add(json_neigh, "bgpTimerLastWrite",
10697 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
10698 + (tm->tm_hour * 3600000));
10699
10700 uptime = bgp_clock();
10701 uptime -= p->update_time;
10702 tm = gmtime(&uptime);
10703 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
10704 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
10705 + (tm->tm_hour * 3600000));
10706
10707 /* Configured timer values. */
10708 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
10709 p->v_holdtime * 1000);
10710 json_object_int_add(json_neigh,
10711 "bgpTimerKeepAliveIntervalMsecs",
10712 p->v_keepalive * 1000);
10713 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
10714 json_object_int_add(json_neigh,
10715 "bgpTimerConfiguredHoldTimeMsecs",
10716 p->holdtime * 1000);
10717 json_object_int_add(
10718 json_neigh,
10719 "bgpTimerConfiguredKeepAliveIntervalMsecs",
10720 p->keepalive * 1000);
10721 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
10722 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
10723 json_object_int_add(json_neigh,
10724 "bgpTimerConfiguredHoldTimeMsecs",
10725 bgp->default_holdtime);
10726 json_object_int_add(
10727 json_neigh,
10728 "bgpTimerConfiguredKeepAliveIntervalMsecs",
10729 bgp->default_keepalive);
10730 }
10731 } else {
10732 /* Administrative shutdown. */
10733 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
10734 vty_out(vty, " Administratively shut down\n");
10735
10736 /* BGP Version. */
10737 vty_out(vty, " BGP version 4");
10738 vty_out(vty, ", remote router ID %s",
10739 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
10740 vty_out(vty, ", local router ID %s\n",
10741 inet_ntop(AF_INET, &bgp->router_id, buf1,
10742 sizeof(buf1)));
10743
10744 /* Confederation */
10745 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
10746 && bgp_confederation_peers_check(bgp, p->as))
10747 vty_out(vty,
10748 " Neighbor under common administration\n");
10749
10750 /* Status. */
10751 vty_out(vty, " BGP state = %s",
10752 lookup_msg(bgp_status_msg, p->status, NULL));
10753
10754 if (p->status == Established)
10755 vty_out(vty, ", up for %8s",
10756 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
10757 0, NULL));
10758
10759 else if (p->status == Active) {
10760 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
10761 vty_out(vty, " (passive)");
10762 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
10763 vty_out(vty, " (NSF passive)");
10764 }
10765 vty_out(vty, "\n");
10766
10767 /* read timer */
10768 vty_out(vty, " Last read %s",
10769 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
10770 NULL));
10771 vty_out(vty, ", Last write %s\n",
10772 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
10773 NULL));
10774
10775 /* Configured timer values. */
10776 vty_out(vty,
10777 " Hold time is %d, keepalive interval is %d seconds\n",
10778 p->v_holdtime, p->v_keepalive);
10779 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
10780 vty_out(vty, " Configured hold time is %d",
10781 p->holdtime);
10782 vty_out(vty, ", keepalive interval is %d seconds\n",
10783 p->keepalive);
10784 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
10785 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
10786 vty_out(vty, " Configured hold time is %d",
10787 bgp->default_holdtime);
10788 vty_out(vty, ", keepalive interval is %d seconds\n",
10789 bgp->default_keepalive);
10790 }
10791 }
10792 /* Capability. */
10793 if (p->status == Established) {
10794 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
10795 || p->afc_recv[AFI_IP][SAFI_UNICAST]
10796 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
10797 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
10798 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
10799 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
10800 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
10801 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
10802 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
10803 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
10804 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
10805 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
10806 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
10807 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
10808 || p->afc_adv[AFI_IP][SAFI_ENCAP]
10809 || p->afc_recv[AFI_IP][SAFI_ENCAP]
10810 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
10811 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
10812 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
10813 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
10814 if (use_json) {
10815 json_object *json_cap = NULL;
10816
10817 json_cap = json_object_new_object();
10818
10819 /* AS4 */
10820 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
10821 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
10822 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
10823 && CHECK_FLAG(p->cap,
10824 PEER_CAP_AS4_RCV))
10825 json_object_string_add(
10826 json_cap, "4byteAs",
10827 "advertisedAndReceived");
10828 else if (CHECK_FLAG(p->cap,
10829 PEER_CAP_AS4_ADV))
10830 json_object_string_add(
10831 json_cap, "4byteAs",
10832 "advertised");
10833 else if (CHECK_FLAG(p->cap,
10834 PEER_CAP_AS4_RCV))
10835 json_object_string_add(
10836 json_cap, "4byteAs",
10837 "received");
10838 }
10839
10840 /* AddPath */
10841 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
10842 || CHECK_FLAG(p->cap,
10843 PEER_CAP_ADDPATH_ADV)) {
10844 json_object *json_add = NULL;
10845 const char *print_store;
10846
10847 json_add = json_object_new_object();
10848
10849 FOREACH_AFI_SAFI (afi, safi) {
10850 json_object *json_sub = NULL;
10851 json_sub =
10852 json_object_new_object();
10853 print_store = get_afi_safi_str(
10854 afi, safi, true);
10855
10856 if (CHECK_FLAG(
10857 p->af_cap[afi]
10858 [safi],
10859 PEER_CAP_ADDPATH_AF_TX_ADV)
10860 || CHECK_FLAG(
10861 p->af_cap[afi]
10862 [safi],
10863 PEER_CAP_ADDPATH_AF_TX_RCV)) {
10864 if (CHECK_FLAG(
10865 p->af_cap
10866 [afi]
10867 [safi],
10868 PEER_CAP_ADDPATH_AF_TX_ADV)
10869 && CHECK_FLAG(
10870 p->af_cap
10871 [afi]
10872 [safi],
10873 PEER_CAP_ADDPATH_AF_TX_RCV))
10874 json_object_boolean_true_add(
10875 json_sub,
10876 "txAdvertisedAndReceived");
10877 else if (
10878 CHECK_FLAG(
10879 p->af_cap
10880 [afi]
10881 [safi],
10882 PEER_CAP_ADDPATH_AF_TX_ADV))
10883 json_object_boolean_true_add(
10884 json_sub,
10885 "txAdvertised");
10886 else if (
10887 CHECK_FLAG(
10888 p->af_cap
10889 [afi]
10890 [safi],
10891 PEER_CAP_ADDPATH_AF_TX_RCV))
10892 json_object_boolean_true_add(
10893 json_sub,
10894 "txReceived");
10895 }
10896
10897 if (CHECK_FLAG(
10898 p->af_cap[afi]
10899 [safi],
10900 PEER_CAP_ADDPATH_AF_RX_ADV)
10901 || CHECK_FLAG(
10902 p->af_cap[afi]
10903 [safi],
10904 PEER_CAP_ADDPATH_AF_RX_RCV)) {
10905 if (CHECK_FLAG(
10906 p->af_cap
10907 [afi]
10908 [safi],
10909 PEER_CAP_ADDPATH_AF_RX_ADV)
10910 && CHECK_FLAG(
10911 p->af_cap
10912 [afi]
10913 [safi],
10914 PEER_CAP_ADDPATH_AF_RX_RCV))
10915 json_object_boolean_true_add(
10916 json_sub,
10917 "rxAdvertisedAndReceived");
10918 else if (
10919 CHECK_FLAG(
10920 p->af_cap
10921 [afi]
10922 [safi],
10923 PEER_CAP_ADDPATH_AF_RX_ADV))
10924 json_object_boolean_true_add(
10925 json_sub,
10926 "rxAdvertised");
10927 else if (
10928 CHECK_FLAG(
10929 p->af_cap
10930 [afi]
10931 [safi],
10932 PEER_CAP_ADDPATH_AF_RX_RCV))
10933 json_object_boolean_true_add(
10934 json_sub,
10935 "rxReceived");
10936 }
10937
10938 if (CHECK_FLAG(
10939 p->af_cap[afi]
10940 [safi],
10941 PEER_CAP_ADDPATH_AF_TX_ADV)
10942 || CHECK_FLAG(
10943 p->af_cap[afi]
10944 [safi],
10945 PEER_CAP_ADDPATH_AF_TX_RCV)
10946 || CHECK_FLAG(
10947 p->af_cap[afi]
10948 [safi],
10949 PEER_CAP_ADDPATH_AF_RX_ADV)
10950 || CHECK_FLAG(
10951 p->af_cap[afi]
10952 [safi],
10953 PEER_CAP_ADDPATH_AF_RX_RCV))
10954 json_object_object_add(
10955 json_add,
10956 print_store,
10957 json_sub);
10958 else
10959 json_object_free(
10960 json_sub);
10961 }
10962
10963 json_object_object_add(
10964 json_cap, "addPath", json_add);
10965 }
10966
10967 /* Dynamic */
10968 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
10969 || CHECK_FLAG(p->cap,
10970 PEER_CAP_DYNAMIC_ADV)) {
10971 if (CHECK_FLAG(p->cap,
10972 PEER_CAP_DYNAMIC_ADV)
10973 && CHECK_FLAG(p->cap,
10974 PEER_CAP_DYNAMIC_RCV))
10975 json_object_string_add(
10976 json_cap, "dynamic",
10977 "advertisedAndReceived");
10978 else if (CHECK_FLAG(
10979 p->cap,
10980 PEER_CAP_DYNAMIC_ADV))
10981 json_object_string_add(
10982 json_cap, "dynamic",
10983 "advertised");
10984 else if (CHECK_FLAG(
10985 p->cap,
10986 PEER_CAP_DYNAMIC_RCV))
10987 json_object_string_add(
10988 json_cap, "dynamic",
10989 "received");
10990 }
10991
10992 /* Extended nexthop */
10993 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
10994 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
10995 json_object *json_nxt = NULL;
10996 const char *print_store;
10997
10998
10999 if (CHECK_FLAG(p->cap,
11000 PEER_CAP_ENHE_ADV)
11001 && CHECK_FLAG(p->cap,
11002 PEER_CAP_ENHE_RCV))
11003 json_object_string_add(
11004 json_cap,
11005 "extendedNexthop",
11006 "advertisedAndReceived");
11007 else if (CHECK_FLAG(p->cap,
11008 PEER_CAP_ENHE_ADV))
11009 json_object_string_add(
11010 json_cap,
11011 "extendedNexthop",
11012 "advertised");
11013 else if (CHECK_FLAG(p->cap,
11014 PEER_CAP_ENHE_RCV))
11015 json_object_string_add(
11016 json_cap,
11017 "extendedNexthop",
11018 "received");
11019
11020 if (CHECK_FLAG(p->cap,
11021 PEER_CAP_ENHE_RCV)) {
11022 json_nxt =
11023 json_object_new_object();
11024
11025 for (safi = SAFI_UNICAST;
11026 safi < SAFI_MAX; safi++) {
11027 if (CHECK_FLAG(
11028 p->af_cap
11029 [AFI_IP]
11030 [safi],
11031 PEER_CAP_ENHE_AF_RCV)) {
11032 print_store = get_afi_safi_str(
11033 AFI_IP,
11034 safi, true);
11035 json_object_string_add(
11036 json_nxt,
11037 print_store,
11038 "recieved"); /* misspelled for compatibility */
11039 }
11040 }
11041 json_object_object_add(
11042 json_cap,
11043 "extendedNexthopFamililesByPeer",
11044 json_nxt);
11045 }
11046 }
11047
11048 /* Route Refresh */
11049 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
11050 || CHECK_FLAG(p->cap,
11051 PEER_CAP_REFRESH_NEW_RCV)
11052 || CHECK_FLAG(p->cap,
11053 PEER_CAP_REFRESH_OLD_RCV)) {
11054 if (CHECK_FLAG(p->cap,
11055 PEER_CAP_REFRESH_ADV)
11056 && (CHECK_FLAG(
11057 p->cap,
11058 PEER_CAP_REFRESH_NEW_RCV)
11059 || CHECK_FLAG(
11060 p->cap,
11061 PEER_CAP_REFRESH_OLD_RCV))) {
11062 if (CHECK_FLAG(
11063 p->cap,
11064 PEER_CAP_REFRESH_OLD_RCV)
11065 && CHECK_FLAG(
11066 p->cap,
11067 PEER_CAP_REFRESH_NEW_RCV))
11068 json_object_string_add(
11069 json_cap,
11070 "routeRefresh",
11071 "advertisedAndReceivedOldNew");
11072 else {
11073 if (CHECK_FLAG(
11074 p->cap,
11075 PEER_CAP_REFRESH_OLD_RCV))
11076 json_object_string_add(
11077 json_cap,
11078 "routeRefresh",
11079 "advertisedAndReceivedOld");
11080 else
11081 json_object_string_add(
11082 json_cap,
11083 "routeRefresh",
11084 "advertisedAndReceivedNew");
11085 }
11086 } else if (
11087 CHECK_FLAG(
11088 p->cap,
11089 PEER_CAP_REFRESH_ADV))
11090 json_object_string_add(
11091 json_cap,
11092 "routeRefresh",
11093 "advertised");
11094 else if (
11095 CHECK_FLAG(
11096 p->cap,
11097 PEER_CAP_REFRESH_NEW_RCV)
11098 || CHECK_FLAG(
11099 p->cap,
11100 PEER_CAP_REFRESH_OLD_RCV))
11101 json_object_string_add(
11102 json_cap,
11103 "routeRefresh",
11104 "received");
11105 }
11106
11107 /* Multiprotocol Extensions */
11108 json_object *json_multi = NULL;
11109 json_multi = json_object_new_object();
11110
11111 FOREACH_AFI_SAFI (afi, safi) {
11112 if (p->afc_adv[afi][safi]
11113 || p->afc_recv[afi][safi]) {
11114 json_object *json_exten = NULL;
11115 json_exten =
11116 json_object_new_object();
11117
11118 if (p->afc_adv[afi][safi]
11119 && p->afc_recv[afi][safi])
11120 json_object_boolean_true_add(
11121 json_exten,
11122 "advertisedAndReceived");
11123 else if (p->afc_adv[afi][safi])
11124 json_object_boolean_true_add(
11125 json_exten,
11126 "advertised");
11127 else if (p->afc_recv[afi][safi])
11128 json_object_boolean_true_add(
11129 json_exten,
11130 "received");
11131
11132 json_object_object_add(
11133 json_multi,
11134 get_afi_safi_str(afi,
11135 safi,
11136 true),
11137 json_exten);
11138 }
11139 }
11140 json_object_object_add(
11141 json_cap, "multiprotocolExtensions",
11142 json_multi);
11143
11144 /* Hostname capabilities */
11145 json_object *json_hname = NULL;
11146
11147 json_hname = json_object_new_object();
11148
11149 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
11150 json_object_string_add(
11151 json_hname, "advHostName",
11152 bgp->peer_self->hostname
11153 ? bgp->peer_self
11154 ->hostname
11155 : "n/a");
11156 json_object_string_add(
11157 json_hname, "advDomainName",
11158 bgp->peer_self->domainname
11159 ? bgp->peer_self
11160 ->domainname
11161 : "n/a");
11162 }
11163
11164
11165 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
11166 json_object_string_add(
11167 json_hname, "rcvHostName",
11168 p->hostname ? p->hostname
11169 : "n/a");
11170 json_object_string_add(
11171 json_hname, "rcvDomainName",
11172 p->domainname ? p->domainname
11173 : "n/a");
11174 }
11175
11176 json_object_object_add(json_cap, "hostName",
11177 json_hname);
11178
11179 /* Gracefull Restart */
11180 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
11181 || CHECK_FLAG(p->cap,
11182 PEER_CAP_RESTART_ADV)) {
11183 if (CHECK_FLAG(p->cap,
11184 PEER_CAP_RESTART_ADV)
11185 && CHECK_FLAG(p->cap,
11186 PEER_CAP_RESTART_RCV))
11187 json_object_string_add(
11188 json_cap,
11189 "gracefulRestart",
11190 "advertisedAndReceived");
11191 else if (CHECK_FLAG(
11192 p->cap,
11193 PEER_CAP_RESTART_ADV))
11194 json_object_string_add(
11195 json_cap,
11196 "gracefulRestartCapability",
11197 "advertised");
11198 else if (CHECK_FLAG(
11199 p->cap,
11200 PEER_CAP_RESTART_RCV))
11201 json_object_string_add(
11202 json_cap,
11203 "gracefulRestartCapability",
11204 "received");
11205
11206 if (CHECK_FLAG(p->cap,
11207 PEER_CAP_RESTART_RCV)) {
11208 int restart_af_count = 0;
11209 json_object *json_restart =
11210 NULL;
11211 json_restart =
11212 json_object_new_object();
11213
11214 json_object_int_add(
11215 json_cap,
11216 "gracefulRestartRemoteTimerMsecs",
11217 p->v_gr_restart * 1000);
11218
11219 FOREACH_AFI_SAFI (afi, safi) {
11220 if (CHECK_FLAG(
11221 p->af_cap
11222 [afi]
11223 [safi],
11224 PEER_CAP_RESTART_AF_RCV)) {
11225 json_object *
11226 json_sub =
11227 NULL;
11228 json_sub =
11229 json_object_new_object();
11230
11231 if (CHECK_FLAG(
11232 p->af_cap
11233 [afi]
11234 [safi],
11235 PEER_CAP_RESTART_AF_PRESERVE_RCV))
11236 json_object_boolean_true_add(
11237 json_sub,
11238 "preserved");
11239 restart_af_count++;
11240 json_object_object_add(
11241 json_restart,
11242 get_afi_safi_str(
11243 afi,
11244 safi,
11245 true),
11246 json_sub);
11247 }
11248 }
11249 if (!restart_af_count) {
11250 json_object_string_add(
11251 json_cap,
11252 "addressFamiliesByPeer",
11253 "none");
11254 json_object_free(
11255 json_restart);
11256 } else
11257 json_object_object_add(
11258 json_cap,
11259 "addressFamiliesByPeer",
11260 json_restart);
11261 }
11262 }
11263 json_object_object_add(json_neigh,
11264 "neighborCapabilities",
11265 json_cap);
11266 } else {
11267 vty_out(vty, " Neighbor capabilities:\n");
11268
11269 /* AS4 */
11270 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
11271 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
11272 vty_out(vty, " 4 Byte AS:");
11273 if (CHECK_FLAG(p->cap,
11274 PEER_CAP_AS4_ADV))
11275 vty_out(vty, " advertised");
11276 if (CHECK_FLAG(p->cap,
11277 PEER_CAP_AS4_RCV))
11278 vty_out(vty, " %sreceived",
11279 CHECK_FLAG(
11280 p->cap,
11281 PEER_CAP_AS4_ADV)
11282 ? "and "
11283 : "");
11284 vty_out(vty, "\n");
11285 }
11286
11287 /* AddPath */
11288 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
11289 || CHECK_FLAG(p->cap,
11290 PEER_CAP_ADDPATH_ADV)) {
11291 vty_out(vty, " AddPath:\n");
11292
11293 FOREACH_AFI_SAFI (afi, safi) {
11294 if (CHECK_FLAG(
11295 p->af_cap[afi]
11296 [safi],
11297 PEER_CAP_ADDPATH_AF_TX_ADV)
11298 || CHECK_FLAG(
11299 p->af_cap[afi]
11300 [safi],
11301 PEER_CAP_ADDPATH_AF_TX_RCV)) {
11302 vty_out(vty,
11303 " %s: TX ",
11304 get_afi_safi_str(
11305 afi,
11306 safi,
11307 false));
11308
11309 if (CHECK_FLAG(
11310 p->af_cap
11311 [afi]
11312 [safi],
11313 PEER_CAP_ADDPATH_AF_TX_ADV))
11314 vty_out(vty,
11315 "advertised %s",
11316 get_afi_safi_str(
11317 afi,
11318 safi,
11319 false));
11320
11321 if (CHECK_FLAG(
11322 p->af_cap
11323 [afi]
11324 [safi],
11325 PEER_CAP_ADDPATH_AF_TX_RCV))
11326 vty_out(vty,
11327 "%sreceived",
11328 CHECK_FLAG(
11329 p->af_cap
11330 [afi]
11331 [safi],
11332 PEER_CAP_ADDPATH_AF_TX_ADV)
11333 ? " and "
11334 : "");
11335
11336 vty_out(vty, "\n");
11337 }
11338
11339 if (CHECK_FLAG(
11340 p->af_cap[afi]
11341 [safi],
11342 PEER_CAP_ADDPATH_AF_RX_ADV)
11343 || CHECK_FLAG(
11344 p->af_cap[afi]
11345 [safi],
11346 PEER_CAP_ADDPATH_AF_RX_RCV)) {
11347 vty_out(vty,
11348 " %s: RX ",
11349 get_afi_safi_str(
11350 afi,
11351 safi,
11352 false));
11353
11354 if (CHECK_FLAG(
11355 p->af_cap
11356 [afi]
11357 [safi],
11358 PEER_CAP_ADDPATH_AF_RX_ADV))
11359 vty_out(vty,
11360 "advertised %s",
11361 get_afi_safi_str(
11362 afi,
11363 safi,
11364 false));
11365
11366 if (CHECK_FLAG(
11367 p->af_cap
11368 [afi]
11369 [safi],
11370 PEER_CAP_ADDPATH_AF_RX_RCV))
11371 vty_out(vty,
11372 "%sreceived",
11373 CHECK_FLAG(
11374 p->af_cap
11375 [afi]
11376 [safi],
11377 PEER_CAP_ADDPATH_AF_RX_ADV)
11378 ? " and "
11379 : "");
11380
11381 vty_out(vty, "\n");
11382 }
11383 }
11384 }
11385
11386 /* Dynamic */
11387 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
11388 || CHECK_FLAG(p->cap,
11389 PEER_CAP_DYNAMIC_ADV)) {
11390 vty_out(vty, " Dynamic:");
11391 if (CHECK_FLAG(p->cap,
11392 PEER_CAP_DYNAMIC_ADV))
11393 vty_out(vty, " advertised");
11394 if (CHECK_FLAG(p->cap,
11395 PEER_CAP_DYNAMIC_RCV))
11396 vty_out(vty, " %sreceived",
11397 CHECK_FLAG(
11398 p->cap,
11399 PEER_CAP_DYNAMIC_ADV)
11400 ? "and "
11401 : "");
11402 vty_out(vty, "\n");
11403 }
11404
11405 /* Extended nexthop */
11406 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
11407 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
11408 vty_out(vty, " Extended nexthop:");
11409 if (CHECK_FLAG(p->cap,
11410 PEER_CAP_ENHE_ADV))
11411 vty_out(vty, " advertised");
11412 if (CHECK_FLAG(p->cap,
11413 PEER_CAP_ENHE_RCV))
11414 vty_out(vty, " %sreceived",
11415 CHECK_FLAG(
11416 p->cap,
11417 PEER_CAP_ENHE_ADV)
11418 ? "and "
11419 : "");
11420 vty_out(vty, "\n");
11421
11422 if (CHECK_FLAG(p->cap,
11423 PEER_CAP_ENHE_RCV)) {
11424 vty_out(vty,
11425 " Address families by peer:\n ");
11426 for (safi = SAFI_UNICAST;
11427 safi < SAFI_MAX; safi++)
11428 if (CHECK_FLAG(
11429 p->af_cap
11430 [AFI_IP]
11431 [safi],
11432 PEER_CAP_ENHE_AF_RCV))
11433 vty_out(vty,
11434 " %s\n",
11435 get_afi_safi_str(
11436 AFI_IP,
11437 safi,
11438 false));
11439 }
11440 }
11441
11442 /* Route Refresh */
11443 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
11444 || CHECK_FLAG(p->cap,
11445 PEER_CAP_REFRESH_NEW_RCV)
11446 || CHECK_FLAG(p->cap,
11447 PEER_CAP_REFRESH_OLD_RCV)) {
11448 vty_out(vty, " Route refresh:");
11449 if (CHECK_FLAG(p->cap,
11450 PEER_CAP_REFRESH_ADV))
11451 vty_out(vty, " advertised");
11452 if (CHECK_FLAG(p->cap,
11453 PEER_CAP_REFRESH_NEW_RCV)
11454 || CHECK_FLAG(
11455 p->cap,
11456 PEER_CAP_REFRESH_OLD_RCV))
11457 vty_out(vty, " %sreceived(%s)",
11458 CHECK_FLAG(
11459 p->cap,
11460 PEER_CAP_REFRESH_ADV)
11461 ? "and "
11462 : "",
11463 (CHECK_FLAG(
11464 p->cap,
11465 PEER_CAP_REFRESH_OLD_RCV)
11466 && CHECK_FLAG(
11467 p->cap,
11468 PEER_CAP_REFRESH_NEW_RCV))
11469 ? "old & new"
11470 : CHECK_FLAG(
11471 p->cap,
11472 PEER_CAP_REFRESH_OLD_RCV)
11473 ? "old"
11474 : "new");
11475
11476 vty_out(vty, "\n");
11477 }
11478
11479 /* Multiprotocol Extensions */
11480 FOREACH_AFI_SAFI (afi, safi)
11481 if (p->afc_adv[afi][safi]
11482 || p->afc_recv[afi][safi]) {
11483 vty_out(vty,
11484 " Address Family %s:",
11485 get_afi_safi_str(
11486 afi,
11487 safi,
11488 false));
11489 if (p->afc_adv[afi][safi])
11490 vty_out(vty,
11491 " advertised");
11492 if (p->afc_recv[afi][safi])
11493 vty_out(vty,
11494 " %sreceived",
11495 p->afc_adv[afi]
11496 [safi]
11497 ? "and "
11498 : "");
11499 vty_out(vty, "\n");
11500 }
11501
11502 /* Hostname capability */
11503 vty_out(vty, " Hostname Capability:");
11504
11505 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
11506 vty_out(vty,
11507 " advertised (name: %s,domain name: %s)",
11508 bgp->peer_self->hostname
11509 ? bgp->peer_self
11510 ->hostname
11511 : "n/a",
11512 bgp->peer_self->domainname
11513 ? bgp->peer_self
11514 ->domainname
11515 : "n/a");
11516 } else {
11517 vty_out(vty, " not advertised");
11518 }
11519
11520 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
11521 vty_out(vty,
11522 " received (name: %s,domain name: %s)",
11523 p->hostname ? p->hostname
11524 : "n/a",
11525 p->domainname ? p->domainname
11526 : "n/a");
11527 } else {
11528 vty_out(vty, " not received");
11529 }
11530
11531 vty_out(vty, "\n");
11532
11533 /* Gracefull Restart */
11534 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
11535 || CHECK_FLAG(p->cap,
11536 PEER_CAP_RESTART_ADV)) {
11537 vty_out(vty,
11538 " Graceful Restart Capabilty:");
11539 if (CHECK_FLAG(p->cap,
11540 PEER_CAP_RESTART_ADV))
11541 vty_out(vty, " advertised");
11542 if (CHECK_FLAG(p->cap,
11543 PEER_CAP_RESTART_RCV))
11544 vty_out(vty, " %sreceived",
11545 CHECK_FLAG(
11546 p->cap,
11547 PEER_CAP_RESTART_ADV)
11548 ? "and "
11549 : "");
11550 vty_out(vty, "\n");
11551
11552 if (CHECK_FLAG(p->cap,
11553 PEER_CAP_RESTART_RCV)) {
11554 int restart_af_count = 0;
11555
11556 vty_out(vty,
11557 " Remote Restart timer is %d seconds\n",
11558 p->v_gr_restart);
11559 vty_out(vty,
11560 " Address families by peer:\n ");
11561
11562 FOREACH_AFI_SAFI (afi, safi)
11563 if (CHECK_FLAG(
11564 p->af_cap
11565 [afi]
11566 [safi],
11567 PEER_CAP_RESTART_AF_RCV)) {
11568 vty_out(vty,
11569 "%s%s(%s)",
11570 restart_af_count
11571 ? ", "
11572 : "",
11573 get_afi_safi_str(
11574 afi,
11575 safi,
11576 false),
11577 CHECK_FLAG(
11578 p->af_cap
11579 [afi]
11580 [safi],
11581 PEER_CAP_RESTART_AF_PRESERVE_RCV)
11582 ? "preserved"
11583 : "not preserved");
11584 restart_af_count++;
11585 }
11586 if (!restart_af_count)
11587 vty_out(vty, "none");
11588 vty_out(vty, "\n");
11589 }
11590 } /* Gracefull Restart */
11591 }
11592 }
11593 }
11594
11595 /* graceful restart information */
11596 json_object *json_grace = NULL;
11597 json_object *json_grace_send = NULL;
11598 json_object *json_grace_recv = NULL;
11599 int eor_send_af_count = 0;
11600 int eor_receive_af_count = 0;
11601
11602 if (use_json) {
11603 json_grace = json_object_new_object();
11604 json_grace_send = json_object_new_object();
11605 json_grace_recv = json_object_new_object();
11606
11607 if ((p->status == Established)
11608 && CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
11609 FOREACH_AFI_SAFI (afi, safi) {
11610 if (CHECK_FLAG(p->af_sflags[afi][safi],
11611 PEER_STATUS_EOR_SEND)) {
11612 json_object_boolean_true_add(
11613 json_grace_send,
11614 get_afi_safi_str(afi,
11615 safi,
11616 true));
11617 eor_send_af_count++;
11618 }
11619 }
11620 FOREACH_AFI_SAFI (afi, safi) {
11621 if (CHECK_FLAG(
11622 p->af_sflags[afi][safi],
11623 PEER_STATUS_EOR_RECEIVED)) {
11624 json_object_boolean_true_add(
11625 json_grace_recv,
11626 get_afi_safi_str(afi,
11627 safi,
11628 true));
11629 eor_receive_af_count++;
11630 }
11631 }
11632 }
11633 json_object_object_add(json_grace, "endOfRibSend",
11634 json_grace_send);
11635 json_object_object_add(json_grace, "endOfRibRecv",
11636 json_grace_recv);
11637
11638
11639 if (p->t_gr_restart)
11640 json_object_int_add(json_grace,
11641 "gracefulRestartTimerMsecs",
11642 thread_timer_remain_second(
11643 p->t_gr_restart)
11644 * 1000);
11645
11646 if (p->t_gr_stale)
11647 json_object_int_add(
11648 json_grace,
11649 "gracefulStalepathTimerMsecs",
11650 thread_timer_remain_second(
11651 p->t_gr_stale)
11652 * 1000);
11653 /* more gr info in new format */
11654 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json,
11655 json_grace);
11656 json_object_object_add(
11657 json_neigh, "gracefulRestartInfo", json_grace);
11658 } else {
11659 vty_out(vty, " Graceful restart informations:\n");
11660 if ((p->status == Established)
11661 && CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
11662
11663 vty_out(vty, " End-of-RIB send: ");
11664 FOREACH_AFI_SAFI (afi, safi) {
11665 if (CHECK_FLAG(p->af_sflags[afi][safi],
11666 PEER_STATUS_EOR_SEND)) {
11667 vty_out(vty, "%s%s",
11668 eor_send_af_count ? ", "
11669 : "",
11670 get_afi_safi_str(
11671 afi, safi,
11672 false));
11673 eor_send_af_count++;
11674 }
11675 }
11676 vty_out(vty, "\n");
11677 vty_out(vty, " End-of-RIB received: ");
11678 FOREACH_AFI_SAFI (afi, safi) {
11679 if (CHECK_FLAG(
11680 p->af_sflags[afi][safi],
11681 PEER_STATUS_EOR_RECEIVED)) {
11682 vty_out(vty, "%s%s",
11683 eor_receive_af_count
11684 ? ", "
11685 : "",
11686 get_afi_safi_str(afi,
11687 safi,
11688 false));
11689 eor_receive_af_count++;
11690 }
11691 }
11692 vty_out(vty, "\n");
11693 }
11694
11695 if (p->t_gr_restart)
11696 vty_out(vty,
11697 " The remaining time of restart timer is %ld\n",
11698 thread_timer_remain_second(
11699 p->t_gr_restart));
11700
11701 if (p->t_gr_stale)
11702 vty_out(vty,
11703 " The remaining time of stalepath timer is %ld\n",
11704 thread_timer_remain_second(
11705 p->t_gr_stale));
11706
11707 /* more gr info in new format */
11708 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, NULL);
11709 }
11710
11711 if (use_json) {
11712 json_object *json_stat = NULL;
11713 json_stat = json_object_new_object();
11714 /* Packet counts. */
11715 json_object_int_add(json_stat, "depthInq", 0);
11716 json_object_int_add(json_stat, "depthOutq",
11717 (unsigned long)p->obuf->count);
11718 json_object_int_add(json_stat, "opensSent",
11719 atomic_load_explicit(&p->open_out,
11720 memory_order_relaxed));
11721 json_object_int_add(json_stat, "opensRecv",
11722 atomic_load_explicit(&p->open_in,
11723 memory_order_relaxed));
11724 json_object_int_add(json_stat, "notificationsSent",
11725 atomic_load_explicit(&p->notify_out,
11726 memory_order_relaxed));
11727 json_object_int_add(json_stat, "notificationsRecv",
11728 atomic_load_explicit(&p->notify_in,
11729 memory_order_relaxed));
11730 json_object_int_add(json_stat, "updatesSent",
11731 atomic_load_explicit(&p->update_out,
11732 memory_order_relaxed));
11733 json_object_int_add(json_stat, "updatesRecv",
11734 atomic_load_explicit(&p->update_in,
11735 memory_order_relaxed));
11736 json_object_int_add(json_stat, "keepalivesSent",
11737 atomic_load_explicit(&p->keepalive_out,
11738 memory_order_relaxed));
11739 json_object_int_add(json_stat, "keepalivesRecv",
11740 atomic_load_explicit(&p->keepalive_in,
11741 memory_order_relaxed));
11742 json_object_int_add(json_stat, "routeRefreshSent",
11743 atomic_load_explicit(&p->refresh_out,
11744 memory_order_relaxed));
11745 json_object_int_add(json_stat, "routeRefreshRecv",
11746 atomic_load_explicit(&p->refresh_in,
11747 memory_order_relaxed));
11748 json_object_int_add(json_stat, "capabilitySent",
11749 atomic_load_explicit(&p->dynamic_cap_out,
11750 memory_order_relaxed));
11751 json_object_int_add(json_stat, "capabilityRecv",
11752 atomic_load_explicit(&p->dynamic_cap_in,
11753 memory_order_relaxed));
11754 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
11755 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
11756 json_object_object_add(json_neigh, "messageStats", json_stat);
11757 } else {
11758 /* Packet counts. */
11759 vty_out(vty, " Message statistics:\n");
11760 vty_out(vty, " Inq depth is 0\n");
11761 vty_out(vty, " Outq depth is %lu\n",
11762 (unsigned long)p->obuf->count);
11763 vty_out(vty, " Sent Rcvd\n");
11764 vty_out(vty, " Opens: %10d %10d\n",
11765 atomic_load_explicit(&p->open_out,
11766 memory_order_relaxed),
11767 atomic_load_explicit(&p->open_in,
11768 memory_order_relaxed));
11769 vty_out(vty, " Notifications: %10d %10d\n",
11770 atomic_load_explicit(&p->notify_out,
11771 memory_order_relaxed),
11772 atomic_load_explicit(&p->notify_in,
11773 memory_order_relaxed));
11774 vty_out(vty, " Updates: %10d %10d\n",
11775 atomic_load_explicit(&p->update_out,
11776 memory_order_relaxed),
11777 atomic_load_explicit(&p->update_in,
11778 memory_order_relaxed));
11779 vty_out(vty, " Keepalives: %10d %10d\n",
11780 atomic_load_explicit(&p->keepalive_out,
11781 memory_order_relaxed),
11782 atomic_load_explicit(&p->keepalive_in,
11783 memory_order_relaxed));
11784 vty_out(vty, " Route Refresh: %10d %10d\n",
11785 atomic_load_explicit(&p->refresh_out,
11786 memory_order_relaxed),
11787 atomic_load_explicit(&p->refresh_in,
11788 memory_order_relaxed));
11789 vty_out(vty, " Capability: %10d %10d\n",
11790 atomic_load_explicit(&p->dynamic_cap_out,
11791 memory_order_relaxed),
11792 atomic_load_explicit(&p->dynamic_cap_in,
11793 memory_order_relaxed));
11794 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
11795 PEER_TOTAL_RX(p));
11796 }
11797
11798 if (use_json) {
11799 /* advertisement-interval */
11800 json_object_int_add(json_neigh,
11801 "minBtwnAdvertisementRunsTimerMsecs",
11802 p->v_routeadv * 1000);
11803
11804 /* Update-source. */
11805 if (p->update_if || p->update_source) {
11806 if (p->update_if)
11807 json_object_string_add(json_neigh,
11808 "updateSource",
11809 p->update_if);
11810 else if (p->update_source)
11811 json_object_string_add(
11812 json_neigh, "updateSource",
11813 sockunion2str(p->update_source, buf1,
11814 SU_ADDRSTRLEN));
11815 }
11816 } else {
11817 /* advertisement-interval */
11818 vty_out(vty,
11819 " Minimum time between advertisement runs is %d seconds\n",
11820 p->v_routeadv);
11821
11822 /* Update-source. */
11823 if (p->update_if || p->update_source) {
11824 vty_out(vty, " Update source is ");
11825 if (p->update_if)
11826 vty_out(vty, "%s", p->update_if);
11827 else if (p->update_source)
11828 vty_out(vty, "%s",
11829 sockunion2str(p->update_source, buf1,
11830 SU_ADDRSTRLEN));
11831 vty_out(vty, "\n");
11832 }
11833
11834 vty_out(vty, "\n");
11835 }
11836
11837 /* Address Family Information */
11838 json_object *json_hold = NULL;
11839
11840 if (use_json)
11841 json_hold = json_object_new_object();
11842
11843 FOREACH_AFI_SAFI (afi, safi)
11844 if (p->afc[afi][safi])
11845 bgp_show_peer_afi(vty, p, afi, safi, use_json,
11846 json_hold);
11847
11848 if (use_json) {
11849 json_object_object_add(json_neigh, "addressFamilyInfo",
11850 json_hold);
11851 json_object_int_add(json_neigh, "connectionsEstablished",
11852 p->established);
11853 json_object_int_add(json_neigh, "connectionsDropped",
11854 p->dropped);
11855 } else
11856 vty_out(vty, " Connections established %d; dropped %d\n",
11857 p->established, p->dropped);
11858
11859 if (!p->last_reset) {
11860 if (use_json)
11861 json_object_string_add(json_neigh, "lastReset",
11862 "never");
11863 else
11864 vty_out(vty, " Last reset never\n");
11865 } else {
11866 if (use_json) {
11867 time_t uptime;
11868 struct tm *tm;
11869
11870 uptime = bgp_clock();
11871 uptime -= p->resettime;
11872 tm = gmtime(&uptime);
11873 json_object_int_add(json_neigh, "lastResetTimerMsecs",
11874 (tm->tm_sec * 1000)
11875 + (tm->tm_min * 60000)
11876 + (tm->tm_hour * 3600000));
11877 bgp_show_peer_reset(NULL, p, json_neigh, true);
11878 } else {
11879 vty_out(vty, " Last reset %s, ",
11880 peer_uptime(p->resettime, timebuf,
11881 BGP_UPTIME_LEN, 0, NULL));
11882
11883 bgp_show_peer_reset(vty, p, NULL, false);
11884 if (p->last_reset_cause_size) {
11885 msg = p->last_reset_cause;
11886 vty_out(vty,
11887 " Message received that caused BGP to send a NOTIFICATION:\n ");
11888 for (i = 1; i <= p->last_reset_cause_size;
11889 i++) {
11890 vty_out(vty, "%02X", *msg++);
11891
11892 if (i != p->last_reset_cause_size) {
11893 if (i % 16 == 0) {
11894 vty_out(vty, "\n ");
11895 } else if (i % 4 == 0) {
11896 vty_out(vty, " ");
11897 }
11898 }
11899 }
11900 vty_out(vty, "\n");
11901 }
11902 }
11903 }
11904
11905 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
11906 if (use_json)
11907 json_object_boolean_true_add(json_neigh,
11908 "prefixesConfigExceedMax");
11909 else
11910 vty_out(vty,
11911 " Peer had exceeded the max. no. of prefixes configured.\n");
11912
11913 if (p->t_pmax_restart) {
11914 if (use_json) {
11915 json_object_boolean_true_add(
11916 json_neigh, "reducePrefixNumFrom");
11917 json_object_int_add(json_neigh,
11918 "restartInTimerMsec",
11919 thread_timer_remain_second(
11920 p->t_pmax_restart)
11921 * 1000);
11922 } else
11923 vty_out(vty,
11924 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
11925 p->host, thread_timer_remain_second(
11926 p->t_pmax_restart));
11927 } else {
11928 if (use_json)
11929 json_object_boolean_true_add(
11930 json_neigh,
11931 "reducePrefixNumAndClearIpBgp");
11932 else
11933 vty_out(vty,
11934 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
11935 p->host);
11936 }
11937 }
11938
11939 /* EBGP Multihop and GTSM */
11940 if (p->sort != BGP_PEER_IBGP) {
11941 if (use_json) {
11942 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
11943 json_object_int_add(json_neigh,
11944 "externalBgpNbrMaxHopsAway",
11945 p->gtsm_hops);
11946 else if (p->ttl > BGP_DEFAULT_TTL)
11947 json_object_int_add(json_neigh,
11948 "externalBgpNbrMaxHopsAway",
11949 p->ttl);
11950 } else {
11951 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
11952 vty_out(vty,
11953 " External BGP neighbor may be up to %d hops away.\n",
11954 p->gtsm_hops);
11955 else if (p->ttl > BGP_DEFAULT_TTL)
11956 vty_out(vty,
11957 " External BGP neighbor may be up to %d hops away.\n",
11958 p->ttl);
11959 }
11960 } else {
11961 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED) {
11962 if (use_json)
11963 json_object_int_add(json_neigh,
11964 "internalBgpNbrMaxHopsAway",
11965 p->gtsm_hops);
11966 else
11967 vty_out(vty,
11968 " Internal BGP neighbor may be up to %d hops away.\n",
11969 p->gtsm_hops);
11970 }
11971 }
11972
11973 /* Local address. */
11974 if (p->su_local) {
11975 if (use_json) {
11976 json_object_string_add(json_neigh, "hostLocal",
11977 sockunion2str(p->su_local, buf1,
11978 SU_ADDRSTRLEN));
11979 json_object_int_add(json_neigh, "portLocal",
11980 ntohs(p->su_local->sin.sin_port));
11981 } else
11982 vty_out(vty, "Local host: %s, Local port: %d\n",
11983 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
11984 ntohs(p->su_local->sin.sin_port));
11985 }
11986
11987 /* Remote address. */
11988 if (p->su_remote) {
11989 if (use_json) {
11990 json_object_string_add(json_neigh, "hostForeign",
11991 sockunion2str(p->su_remote, buf1,
11992 SU_ADDRSTRLEN));
11993 json_object_int_add(json_neigh, "portForeign",
11994 ntohs(p->su_remote->sin.sin_port));
11995 } else
11996 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
11997 sockunion2str(p->su_remote, buf1,
11998 SU_ADDRSTRLEN),
11999 ntohs(p->su_remote->sin.sin_port));
12000 }
12001
12002 /* Nexthop display. */
12003 if (p->su_local) {
12004 if (use_json) {
12005 json_object_string_add(json_neigh, "nexthop",
12006 inet_ntop(AF_INET,
12007 &p->nexthop.v4, buf1,
12008 sizeof(buf1)));
12009 json_object_string_add(json_neigh, "nexthopGlobal",
12010 inet_ntop(AF_INET6,
12011 &p->nexthop.v6_global,
12012 buf1, sizeof(buf1)));
12013 json_object_string_add(json_neigh, "nexthopLocal",
12014 inet_ntop(AF_INET6,
12015 &p->nexthop.v6_local,
12016 buf1, sizeof(buf1)));
12017 if (p->shared_network)
12018 json_object_string_add(json_neigh,
12019 "bgpConnection",
12020 "sharedNetwork");
12021 else
12022 json_object_string_add(json_neigh,
12023 "bgpConnection",
12024 "nonSharedNetwork");
12025 } else {
12026 vty_out(vty, "Nexthop: %s\n",
12027 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
12028 sizeof(buf1)));
12029 vty_out(vty, "Nexthop global: %s\n",
12030 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
12031 sizeof(buf1)));
12032 vty_out(vty, "Nexthop local: %s\n",
12033 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
12034 sizeof(buf1)));
12035 vty_out(vty, "BGP connection: %s\n",
12036 p->shared_network ? "shared network"
12037 : "non shared network");
12038 }
12039 }
12040
12041 /* Timer information. */
12042 if (use_json) {
12043 json_object_int_add(json_neigh, "connectRetryTimer",
12044 p->v_connect);
12045 if (p->status == Established && p->rtt)
12046 json_object_int_add(json_neigh, "estimatedRttInMsecs",
12047 p->rtt);
12048 if (p->t_start)
12049 json_object_int_add(
12050 json_neigh, "nextStartTimerDueInMsecs",
12051 thread_timer_remain_second(p->t_start) * 1000);
12052 if (p->t_connect)
12053 json_object_int_add(
12054 json_neigh, "nextConnectTimerDueInMsecs",
12055 thread_timer_remain_second(p->t_connect)
12056 * 1000);
12057 if (p->t_routeadv) {
12058 json_object_int_add(json_neigh, "mraiInterval",
12059 p->v_routeadv);
12060 json_object_int_add(
12061 json_neigh, "mraiTimerExpireInMsecs",
12062 thread_timer_remain_second(p->t_routeadv)
12063 * 1000);
12064 }
12065 if (p->password)
12066 json_object_int_add(json_neigh, "authenticationEnabled",
12067 1);
12068
12069 if (p->t_read)
12070 json_object_string_add(json_neigh, "readThread", "on");
12071 else
12072 json_object_string_add(json_neigh, "readThread", "off");
12073
12074 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
12075 json_object_string_add(json_neigh, "writeThread", "on");
12076 else
12077 json_object_string_add(json_neigh, "writeThread",
12078 "off");
12079 } else {
12080 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
12081 p->v_connect);
12082 if (p->status == Established && p->rtt)
12083 vty_out(vty, "Estimated round trip time: %d ms\n",
12084 p->rtt);
12085 if (p->t_start)
12086 vty_out(vty, "Next start timer due in %ld seconds\n",
12087 thread_timer_remain_second(p->t_start));
12088 if (p->t_connect)
12089 vty_out(vty, "Next connect timer due in %ld seconds\n",
12090 thread_timer_remain_second(p->t_connect));
12091 if (p->t_routeadv)
12092 vty_out(vty,
12093 "MRAI (interval %u) timer expires in %ld seconds\n",
12094 p->v_routeadv,
12095 thread_timer_remain_second(p->t_routeadv));
12096 if (p->password)
12097 vty_out(vty, "Peer Authentication Enabled\n");
12098
12099 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
12100 p->t_read ? "on" : "off",
12101 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
12102 ? "on"
12103 : "off", p->fd);
12104 }
12105
12106 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
12107 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
12108 bgp_capability_vty_out(vty, p, use_json, json_neigh);
12109
12110 if (!use_json)
12111 vty_out(vty, "\n");
12112
12113 /* BFD information. */
12114 bgp_bfd_show_info(vty, p, use_json, json_neigh);
12115
12116 if (use_json) {
12117 if (p->conf_if) /* Configured interface name. */
12118 json_object_object_add(json, p->conf_if, json_neigh);
12119 else /* Configured IP address. */
12120 json_object_object_add(json, p->host, json_neigh);
12121 }
12122 }
12123
12124 static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
12125 enum show_type type,
12126 union sockunion *su,
12127 const char *conf_if, afi_t afi,
12128 bool use_json, json_object *json)
12129 {
12130 struct listnode *node, *nnode;
12131 struct peer *peer;
12132 int find = 0;
12133 safi_t safi = SAFI_UNICAST;
12134 json_object *json_neighbor = NULL;
12135
12136 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
12137
12138 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
12139 continue;
12140
12141 if ((peer->afc[afi][safi]) == 0)
12142 continue;
12143
12144 if (use_json)
12145 json_neighbor = json_object_new_object();
12146
12147 if (type == show_all) {
12148 bgp_show_peer_gr_status(vty, peer, use_json,
12149 json_neighbor);
12150
12151 if (use_json)
12152 json_object_object_add(json, peer->host,
12153 json_neighbor);
12154
12155 } else if (type == show_peer) {
12156 if (conf_if) {
12157 if ((peer->conf_if
12158 && !strcmp(peer->conf_if, conf_if))
12159 || (peer->hostname
12160 && !strcmp(peer->hostname, conf_if))) {
12161 find = 1;
12162 bgp_show_peer_gr_status(vty, peer,
12163 use_json,
12164 json_neighbor);
12165 }
12166 } else {
12167 if (sockunion_same(&peer->su, su)) {
12168 find = 1;
12169 bgp_show_peer_gr_status(vty, peer,
12170 use_json,
12171 json_neighbor);
12172 }
12173 }
12174 if (use_json && find)
12175 json_object_object_add(json, peer->host,
12176 json_neighbor);
12177 }
12178
12179 if (find)
12180 break;
12181 }
12182
12183 if (type == show_peer && !find) {
12184 if (use_json)
12185 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
12186 else
12187 vty_out(vty, "%% No such neighbor\n");
12188 }
12189 if (use_json) {
12190 vty_out(vty, "%s\n",
12191 json_object_to_json_string_ext(
12192 json, JSON_C_TO_STRING_PRETTY));
12193 } else {
12194 vty_out(vty, "\n");
12195 }
12196
12197 return CMD_SUCCESS;
12198 }
12199
12200 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
12201 enum show_type type, union sockunion *su,
12202 const char *conf_if, bool use_json,
12203 json_object *json)
12204 {
12205 struct listnode *node, *nnode;
12206 struct peer *peer;
12207 int find = 0;
12208 bool nbr_output = false;
12209 afi_t afi = AFI_MAX;
12210 safi_t safi = SAFI_MAX;
12211
12212 if (type == show_ipv4_peer || type == show_ipv4_all) {
12213 afi = AFI_IP;
12214 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
12215 afi = AFI_IP6;
12216 }
12217
12218 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
12219 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
12220 continue;
12221
12222 switch (type) {
12223 case show_all:
12224 bgp_show_peer(vty, peer, use_json, json);
12225 nbr_output = true;
12226 break;
12227 case show_peer:
12228 if (conf_if) {
12229 if ((peer->conf_if
12230 && !strcmp(peer->conf_if, conf_if))
12231 || (peer->hostname
12232 && !strcmp(peer->hostname, conf_if))) {
12233 find = 1;
12234 bgp_show_peer(vty, peer, use_json,
12235 json);
12236 }
12237 } else {
12238 if (sockunion_same(&peer->su, su)) {
12239 find = 1;
12240 bgp_show_peer(vty, peer, use_json,
12241 json);
12242 }
12243 }
12244 break;
12245 case show_ipv4_peer:
12246 case show_ipv6_peer:
12247 FOREACH_SAFI (safi) {
12248 if (peer->afc[afi][safi]) {
12249 if (conf_if) {
12250 if ((peer->conf_if
12251 && !strcmp(peer->conf_if, conf_if))
12252 || (peer->hostname
12253 && !strcmp(peer->hostname, conf_if))) {
12254 find = 1;
12255 bgp_show_peer(vty, peer, use_json,
12256 json);
12257 break;
12258 }
12259 } else {
12260 if (sockunion_same(&peer->su, su)) {
12261 find = 1;
12262 bgp_show_peer(vty, peer, use_json,
12263 json);
12264 break;
12265 }
12266 }
12267 }
12268 }
12269 break;
12270 case show_ipv4_all:
12271 case show_ipv6_all:
12272 FOREACH_SAFI (safi) {
12273 if (peer->afc[afi][safi]) {
12274 bgp_show_peer(vty, peer, use_json, json);
12275 nbr_output = true;
12276 break;
12277 }
12278 }
12279 break;
12280 }
12281 }
12282
12283 if ((type == show_peer || type == show_ipv4_peer ||
12284 type == show_ipv6_peer) && !find) {
12285 if (use_json)
12286 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
12287 else
12288 vty_out(vty, "%% No such neighbor in this view/vrf\n");
12289 }
12290
12291 if (type != show_peer && type != show_ipv4_peer &&
12292 type != show_ipv6_peer && !nbr_output && !use_json)
12293 vty_out(vty, "%% No BGP neighbors found\n");
12294
12295 if (use_json) {
12296 vty_out(vty, "%s\n", json_object_to_json_string_ext(
12297 json, JSON_C_TO_STRING_PRETTY));
12298 } else {
12299 vty_out(vty, "\n");
12300 }
12301
12302 return CMD_SUCCESS;
12303 }
12304
12305 static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
12306 enum show_type type,
12307 const char *ip_str,
12308 afi_t afi, bool use_json)
12309 {
12310
12311 int ret;
12312 struct bgp *bgp;
12313 union sockunion su;
12314 json_object *json = NULL;
12315
12316 bgp = bgp_get_default();
12317
12318 if (!bgp)
12319 return;
12320
12321 if (!use_json)
12322 bgp_show_global_graceful_restart_mode_vty(vty, bgp, use_json,
12323 NULL);
12324
12325 json = json_object_new_object();
12326 if (ip_str) {
12327 ret = str2sockunion(ip_str, &su);
12328 if (ret < 0)
12329 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL,
12330 ip_str, afi,
12331 use_json, json);
12332 else
12333 bgp_show_neighbor_graceful_restart(
12334 vty, bgp, type, &su, NULL, afi, use_json, json);
12335 } else
12336 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
12337 afi, use_json, json);
12338 json_object_free(json);
12339 }
12340
12341 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
12342 enum show_type type,
12343 const char *ip_str,
12344 bool use_json)
12345 {
12346 struct listnode *node, *nnode;
12347 struct bgp *bgp;
12348 union sockunion su;
12349 json_object *json = NULL;
12350 int ret, is_first = 1;
12351 bool nbr_output = false;
12352
12353 if (use_json)
12354 vty_out(vty, "{\n");
12355
12356 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
12357 nbr_output = true;
12358 if (use_json) {
12359 if (!(json = json_object_new_object())) {
12360 flog_err(
12361 EC_BGP_JSON_MEM_ERROR,
12362 "Unable to allocate memory for JSON object");
12363 vty_out(vty,
12364 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
12365 return;
12366 }
12367
12368 json_object_int_add(json, "vrfId",
12369 (bgp->vrf_id == VRF_UNKNOWN)
12370 ? -1
12371 : (int64_t)bgp->vrf_id);
12372 json_object_string_add(
12373 json, "vrfName",
12374 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
12375 ? VRF_DEFAULT_NAME
12376 : bgp->name);
12377
12378 if (!is_first)
12379 vty_out(vty, ",\n");
12380 else
12381 is_first = 0;
12382
12383 vty_out(vty, "\"%s\":",
12384 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
12385 ? VRF_DEFAULT_NAME
12386 : bgp->name);
12387 } else {
12388 vty_out(vty, "\nInstance %s:\n",
12389 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
12390 ? VRF_DEFAULT_NAME
12391 : bgp->name);
12392 }
12393
12394 if (type == show_peer || type == show_ipv4_peer ||
12395 type == show_ipv6_peer) {
12396 ret = str2sockunion(ip_str, &su);
12397 if (ret < 0)
12398 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
12399 use_json, json);
12400 else
12401 bgp_show_neighbor(vty, bgp, type, &su, NULL,
12402 use_json, json);
12403 } else {
12404 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
12405 use_json, json);
12406 }
12407 json_object_free(json);
12408 }
12409
12410 if (use_json) {
12411 vty_out(vty, "}\n");
12412 json_object_free(json);
12413 }
12414 else if (!nbr_output)
12415 vty_out(vty, "%% BGP instance not found\n");
12416 }
12417
12418 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
12419 enum show_type type, const char *ip_str,
12420 bool use_json)
12421 {
12422 int ret;
12423 struct bgp *bgp;
12424 union sockunion su;
12425 json_object *json = NULL;
12426
12427 if (name) {
12428 if (strmatch(name, "all")) {
12429 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
12430 use_json);
12431 return CMD_SUCCESS;
12432 } else {
12433 bgp = bgp_lookup_by_name(name);
12434 if (!bgp) {
12435 if (use_json) {
12436 json = json_object_new_object();
12437 vty_out(vty, "%s\n",
12438 json_object_to_json_string_ext(
12439 json,
12440 JSON_C_TO_STRING_PRETTY));
12441 json_object_free(json);
12442 } else
12443 vty_out(vty,
12444 "%% BGP instance not found\n");
12445
12446 return CMD_WARNING;
12447 }
12448 }
12449 } else {
12450 bgp = bgp_get_default();
12451 }
12452
12453 if (bgp) {
12454 json = json_object_new_object();
12455 if (ip_str) {
12456 ret = str2sockunion(ip_str, &su);
12457 if (ret < 0)
12458 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
12459 use_json, json);
12460 else
12461 bgp_show_neighbor(vty, bgp, type, &su, NULL,
12462 use_json, json);
12463 } else {
12464 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
12465 json);
12466 }
12467 json_object_free(json);
12468 } else {
12469 if (use_json)
12470 vty_out(vty, "{}\n");
12471 else
12472 vty_out(vty, "%% BGP instance not found\n");
12473 }
12474
12475 return CMD_SUCCESS;
12476 }
12477
12478
12479
12480 /* "show [ip] bgp neighbors graceful-restart" commands. */
12481 DEFUN (show_ip_bgp_neighbors_gracrful_restart,
12482 show_ip_bgp_neighbors_graceful_restart_cmd,
12483 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
12484 SHOW_STR
12485 BGP_STR
12486 IP_STR
12487 IPV6_STR
12488 NEIGHBOR_STR
12489 "Neighbor to display information about\n"
12490 "Neighbor to display information about\n"
12491 "Neighbor on BGP configured interface\n"
12492 GR_SHOW
12493 JSON_STR)
12494 {
12495 char *sh_arg = NULL;
12496 enum show_type sh_type;
12497 int idx = 0;
12498 afi_t afi = AFI_MAX;
12499 bool uj = use_json(argc, argv);
12500
12501 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
12502 afi = AFI_MAX;
12503
12504 idx++;
12505
12506 if (argv_find(argv, argc, "A.B.C.D", &idx)
12507 || argv_find(argv, argc, "X:X::X:X", &idx)
12508 || argv_find(argv, argc, "WORD", &idx)) {
12509 sh_type = show_peer;
12510 sh_arg = argv[idx]->arg;
12511 } else
12512 sh_type = show_all;
12513
12514 if (!argv_find(argv, argc, "graceful-restart", &idx))
12515 return CMD_SUCCESS;
12516
12517
12518 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
12519 afi, uj);
12520 }
12521
12522 /* "show [ip] bgp neighbors" commands. */
12523 DEFUN (show_ip_bgp_neighbors,
12524 show_ip_bgp_neighbors_cmd,
12525 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
12526 SHOW_STR
12527 IP_STR
12528 BGP_STR
12529 BGP_INSTANCE_HELP_STR
12530 "Address Family\n"
12531 "Address Family\n"
12532 "Detailed information on TCP and BGP neighbor connections\n"
12533 "Neighbor to display information about\n"
12534 "Neighbor to display information about\n"
12535 "Neighbor on BGP configured interface\n"
12536 JSON_STR)
12537 {
12538 char *vrf = NULL;
12539 char *sh_arg = NULL;
12540 enum show_type sh_type;
12541 afi_t afi = AFI_MAX;
12542
12543 bool uj = use_json(argc, argv);
12544
12545 int idx = 0;
12546
12547 /* [<vrf> VIEWVRFNAME] */
12548 if (argv_find(argv, argc, "vrf", &idx)) {
12549 vrf = argv[idx + 1]->arg;
12550 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
12551 vrf = NULL;
12552 } else if (argv_find(argv, argc, "view", &idx))
12553 /* [<view> VIEWVRFNAME] */
12554 vrf = argv[idx + 1]->arg;
12555
12556 idx++;
12557
12558 if (argv_find(argv, argc, "ipv4", &idx)) {
12559 sh_type = show_ipv4_all;
12560 afi = AFI_IP;
12561 } else if (argv_find(argv, argc, "ipv6", &idx)) {
12562 sh_type = show_ipv6_all;
12563 afi = AFI_IP6;
12564 } else {
12565 sh_type = show_all;
12566 }
12567
12568 if (argv_find(argv, argc, "A.B.C.D", &idx)
12569 || argv_find(argv, argc, "X:X::X:X", &idx)
12570 || argv_find(argv, argc, "WORD", &idx)) {
12571 sh_type = show_peer;
12572 sh_arg = argv[idx]->arg;
12573 }
12574
12575 if (sh_type == show_peer && afi == AFI_IP) {
12576 sh_type = show_ipv4_peer;
12577 } else if (sh_type == show_peer && afi == AFI_IP6) {
12578 sh_type = show_ipv6_peer;
12579 }
12580
12581 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
12582 }
12583
12584 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
12585 paths' and `show ip mbgp paths'. Those functions results are the
12586 same.*/
12587 DEFUN (show_ip_bgp_paths,
12588 show_ip_bgp_paths_cmd,
12589 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
12590 SHOW_STR
12591 IP_STR
12592 BGP_STR
12593 BGP_SAFI_HELP_STR
12594 "Path information\n")
12595 {
12596 vty_out(vty, "Address Refcnt Path\n");
12597 aspath_print_all_vty(vty);
12598 return CMD_SUCCESS;
12599 }
12600
12601 #include "hash.h"
12602
12603 static void community_show_all_iterator(struct hash_bucket *bucket,
12604 struct vty *vty)
12605 {
12606 struct community *com;
12607
12608 com = (struct community *)bucket->data;
12609 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
12610 community_str(com, false));
12611 }
12612
12613 /* Show BGP's community internal data. */
12614 DEFUN (show_ip_bgp_community_info,
12615 show_ip_bgp_community_info_cmd,
12616 "show [ip] bgp community-info",
12617 SHOW_STR
12618 IP_STR
12619 BGP_STR
12620 "List all bgp community information\n")
12621 {
12622 vty_out(vty, "Address Refcnt Community\n");
12623
12624 hash_iterate(community_hash(),
12625 (void (*)(struct hash_bucket *,
12626 void *))community_show_all_iterator,
12627 vty);
12628
12629 return CMD_SUCCESS;
12630 }
12631
12632 static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
12633 struct vty *vty)
12634 {
12635 struct lcommunity *lcom;
12636
12637 lcom = (struct lcommunity *)bucket->data;
12638 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
12639 lcommunity_str(lcom, false));
12640 }
12641
12642 /* Show BGP's community internal data. */
12643 DEFUN (show_ip_bgp_lcommunity_info,
12644 show_ip_bgp_lcommunity_info_cmd,
12645 "show ip bgp large-community-info",
12646 SHOW_STR
12647 IP_STR
12648 BGP_STR
12649 "List all bgp large-community information\n")
12650 {
12651 vty_out(vty, "Address Refcnt Large-community\n");
12652
12653 hash_iterate(lcommunity_hash(),
12654 (void (*)(struct hash_bucket *,
12655 void *))lcommunity_show_all_iterator,
12656 vty);
12657
12658 return CMD_SUCCESS;
12659 }
12660 /* Graceful Restart */
12661
12662 static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
12663 struct bgp *bgp,
12664 bool use_json,
12665 json_object *json)
12666 {
12667
12668
12669 vty_out(vty, "\n%s", SHOW_GR_HEADER);
12670
12671 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
12672
12673 switch (bgp_global_gr_mode) {
12674
12675 case GLOBAL_HELPER:
12676 vty_out(vty, "Global BGP GR Mode : Helper\n");
12677 break;
12678
12679 case GLOBAL_GR:
12680 vty_out(vty, "Global BGP GR Mode : Restart\n");
12681 break;
12682
12683 case GLOBAL_DISABLE:
12684 vty_out(vty, "Global BGP GR Mode : Disable\n");
12685 break;
12686
12687 case GLOBAL_INVALID:
12688 vty_out(vty,
12689 "Global BGP GR Mode Invalid\n");
12690 break;
12691 }
12692 vty_out(vty, "\n");
12693 }
12694
12695 static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
12696 enum show_type type,
12697 const char *ip_str,
12698 afi_t afi, bool use_json)
12699 {
12700 if ((afi == AFI_MAX) && (ip_str == NULL)) {
12701 afi = AFI_IP;
12702
12703 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
12704
12705 bgp_show_neighbor_graceful_restart_vty(
12706 vty, type, ip_str, afi, use_json);
12707 afi++;
12708 }
12709 } else if (afi != AFI_MAX) {
12710 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
12711 use_json);
12712 } else {
12713 return CMD_ERR_INCOMPLETE;
12714 }
12715
12716 return CMD_SUCCESS;
12717 }
12718 /* Graceful Restart */
12719
12720 DEFUN (show_ip_bgp_attr_info,
12721 show_ip_bgp_attr_info_cmd,
12722 "show [ip] bgp attribute-info",
12723 SHOW_STR
12724 IP_STR
12725 BGP_STR
12726 "List all bgp attribute information\n")
12727 {
12728 attr_show_all(vty);
12729 return CMD_SUCCESS;
12730 }
12731
12732 static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
12733 afi_t afi, safi_t safi,
12734 bool use_json, json_object *json)
12735 {
12736 struct bgp *bgp;
12737 struct listnode *node;
12738 char *vname;
12739 char buf1[INET6_ADDRSTRLEN];
12740 char *ecom_str;
12741 vpn_policy_direction_t dir;
12742
12743 if (json) {
12744 json_object *json_import_vrfs = NULL;
12745 json_object *json_export_vrfs = NULL;
12746
12747 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
12748
12749 if (!bgp) {
12750 vty_out(vty, "%s\n",
12751 json_object_to_json_string_ext(
12752 json,
12753 JSON_C_TO_STRING_PRETTY));
12754 json_object_free(json);
12755
12756 return CMD_WARNING;
12757 }
12758
12759 /* Provide context for the block */
12760 json_object_string_add(json, "vrf", name ? name : "default");
12761 json_object_string_add(json, "afiSafi",
12762 get_afi_safi_str(afi, safi, true));
12763
12764 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
12765 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
12766 json_object_string_add(json, "importFromVrfs", "none");
12767 json_object_string_add(json, "importRts", "none");
12768 } else {
12769 json_import_vrfs = json_object_new_array();
12770
12771 for (ALL_LIST_ELEMENTS_RO(
12772 bgp->vpn_policy[afi].import_vrf,
12773 node, vname))
12774 json_object_array_add(json_import_vrfs,
12775 json_object_new_string(vname));
12776
12777 json_object_object_add(json, "importFromVrfs",
12778 json_import_vrfs);
12779 dir = BGP_VPN_POLICY_DIR_FROMVPN;
12780 if (bgp->vpn_policy[afi].rtlist[dir]) {
12781 ecom_str = ecommunity_ecom2str(
12782 bgp->vpn_policy[afi].rtlist[dir],
12783 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
12784 json_object_string_add(json, "importRts",
12785 ecom_str);
12786 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
12787 } else
12788 json_object_string_add(json, "importRts",
12789 "none");
12790 }
12791
12792 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
12793 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
12794 json_object_string_add(json, "exportToVrfs", "none");
12795 json_object_string_add(json, "routeDistinguisher",
12796 "none");
12797 json_object_string_add(json, "exportRts", "none");
12798 } else {
12799 json_export_vrfs = json_object_new_array();
12800
12801 for (ALL_LIST_ELEMENTS_RO(
12802 bgp->vpn_policy[afi].export_vrf,
12803 node, vname))
12804 json_object_array_add(json_export_vrfs,
12805 json_object_new_string(vname));
12806 json_object_object_add(json, "exportToVrfs",
12807 json_export_vrfs);
12808 json_object_string_add(json, "routeDistinguisher",
12809 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
12810 buf1, RD_ADDRSTRLEN));
12811
12812 dir = BGP_VPN_POLICY_DIR_TOVPN;
12813 if (bgp->vpn_policy[afi].rtlist[dir]) {
12814 ecom_str = ecommunity_ecom2str(
12815 bgp->vpn_policy[afi].rtlist[dir],
12816 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
12817 json_object_string_add(json, "exportRts",
12818 ecom_str);
12819 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
12820 } else
12821 json_object_string_add(json, "exportRts",
12822 "none");
12823 }
12824
12825 if (use_json) {
12826 vty_out(vty, "%s\n",
12827 json_object_to_json_string_ext(json,
12828 JSON_C_TO_STRING_PRETTY));
12829 json_object_free(json);
12830 }
12831 } else {
12832 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
12833
12834 if (!bgp) {
12835 vty_out(vty, "%% No such BGP instance exist\n");
12836 return CMD_WARNING;
12837 }
12838
12839 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
12840 BGP_CONFIG_VRF_TO_VRF_IMPORT))
12841 vty_out(vty,
12842 "This VRF is not importing %s routes from any other VRF\n",
12843 get_afi_safi_str(afi, safi, false));
12844 else {
12845 vty_out(vty,
12846 "This VRF is importing %s routes from the following VRFs:\n",
12847 get_afi_safi_str(afi, safi, false));
12848
12849 for (ALL_LIST_ELEMENTS_RO(
12850 bgp->vpn_policy[afi].import_vrf,
12851 node, vname))
12852 vty_out(vty, " %s\n", vname);
12853
12854 dir = BGP_VPN_POLICY_DIR_FROMVPN;
12855 ecom_str = NULL;
12856 if (bgp->vpn_policy[afi].rtlist[dir]) {
12857 ecom_str = ecommunity_ecom2str(
12858 bgp->vpn_policy[afi].rtlist[dir],
12859 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
12860 vty_out(vty, "Import RT(s): %s\n", ecom_str);
12861
12862 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
12863 } else
12864 vty_out(vty, "Import RT(s):\n");
12865 }
12866
12867 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
12868 BGP_CONFIG_VRF_TO_VRF_EXPORT))
12869 vty_out(vty,
12870 "This VRF is not exporting %s routes to any other VRF\n",
12871 get_afi_safi_str(afi, safi, false));
12872 else {
12873 vty_out(vty,
12874 "This VRF is exporting %s routes to the following VRFs:\n",
12875 get_afi_safi_str(afi, safi, false));
12876
12877 for (ALL_LIST_ELEMENTS_RO(
12878 bgp->vpn_policy[afi].export_vrf,
12879 node, vname))
12880 vty_out(vty, " %s\n", vname);
12881
12882 vty_out(vty, "RD: %s\n",
12883 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
12884 buf1, RD_ADDRSTRLEN));
12885
12886 dir = BGP_VPN_POLICY_DIR_TOVPN;
12887 if (bgp->vpn_policy[afi].rtlist[dir]) {
12888 ecom_str = ecommunity_ecom2str(
12889 bgp->vpn_policy[afi].rtlist[dir],
12890 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
12891 vty_out(vty, "Export RT: %s\n", ecom_str);
12892 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
12893 } else
12894 vty_out(vty, "Import RT(s):\n");
12895 }
12896 }
12897
12898 return CMD_SUCCESS;
12899 }
12900
12901 static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
12902 safi_t safi, bool use_json)
12903 {
12904 struct listnode *node, *nnode;
12905 struct bgp *bgp;
12906 char *vrf_name = NULL;
12907 json_object *json = NULL;
12908 json_object *json_vrf = NULL;
12909 json_object *json_vrfs = NULL;
12910
12911 if (use_json) {
12912 json = json_object_new_object();
12913 json_vrfs = json_object_new_object();
12914 }
12915
12916 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
12917
12918 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
12919 vrf_name = bgp->name;
12920
12921 if (use_json) {
12922 json_vrf = json_object_new_object();
12923 } else {
12924 vty_out(vty, "\nInstance %s:\n",
12925 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
12926 ? VRF_DEFAULT_NAME : bgp->name);
12927 }
12928 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
12929 if (use_json) {
12930 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
12931 json_object_object_add(json_vrfs,
12932 VRF_DEFAULT_NAME, json_vrf);
12933 else
12934 json_object_object_add(json_vrfs, vrf_name,
12935 json_vrf);
12936 }
12937 }
12938
12939 if (use_json) {
12940 json_object_object_add(json, "vrfs", json_vrfs);
12941 vty_out(vty, "%s\n", json_object_to_json_string_ext(json,
12942 JSON_C_TO_STRING_PRETTY));
12943 json_object_free(json);
12944 }
12945
12946 return CMD_SUCCESS;
12947 }
12948
12949 /* "show [ip] bgp route-leak" command. */
12950 DEFUN (show_ip_bgp_route_leak,
12951 show_ip_bgp_route_leak_cmd,
12952 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
12953 SHOW_STR
12954 IP_STR
12955 BGP_STR
12956 BGP_INSTANCE_HELP_STR
12957 BGP_AFI_HELP_STR
12958 BGP_SAFI_HELP_STR
12959 "Route leaking information\n"
12960 JSON_STR)
12961 {
12962 char *vrf = NULL;
12963 afi_t afi = AFI_MAX;
12964 safi_t safi = SAFI_MAX;
12965
12966 bool uj = use_json(argc, argv);
12967 int idx = 0;
12968 json_object *json = NULL;
12969
12970 /* show [ip] bgp */
12971 if (argv_find(argv, argc, "ip", &idx)) {
12972 afi = AFI_IP;
12973 safi = SAFI_UNICAST;
12974 }
12975 /* [vrf VIEWVRFNAME] */
12976 if (argv_find(argv, argc, "view", &idx)) {
12977 vty_out(vty,
12978 "%% This command is not applicable to BGP views\n");
12979 return CMD_WARNING;
12980 }
12981
12982 if (argv_find(argv, argc, "vrf", &idx)) {
12983 vrf = argv[idx + 1]->arg;
12984 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
12985 vrf = NULL;
12986 }
12987 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
12988 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
12989 argv_find_and_parse_safi(argv, argc, &idx, &safi);
12990 }
12991
12992 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
12993 vty_out(vty,
12994 "%% This command is applicable only for unicast ipv4|ipv6\n");
12995 return CMD_WARNING;
12996 }
12997
12998 if (vrf && strmatch(vrf, "all"))
12999 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
13000
13001 if (uj)
13002 json = json_object_new_object();
13003
13004 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
13005 }
13006
13007 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
13008 safi_t safi)
13009 {
13010 struct listnode *node, *nnode;
13011 struct bgp *bgp;
13012
13013 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
13014 vty_out(vty, "\nInstance %s:\n",
13015 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
13016 ? VRF_DEFAULT_NAME
13017 : bgp->name);
13018 update_group_show(bgp, afi, safi, vty, 0);
13019 }
13020 }
13021
13022 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
13023 int safi, uint64_t subgrp_id)
13024 {
13025 struct bgp *bgp;
13026
13027 if (name) {
13028 if (strmatch(name, "all")) {
13029 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
13030 return CMD_SUCCESS;
13031 } else {
13032 bgp = bgp_lookup_by_name(name);
13033 }
13034 } else {
13035 bgp = bgp_get_default();
13036 }
13037
13038 if (bgp)
13039 update_group_show(bgp, afi, safi, vty, subgrp_id);
13040 return CMD_SUCCESS;
13041 }
13042
13043 DEFUN (show_ip_bgp_updgrps,
13044 show_ip_bgp_updgrps_cmd,
13045 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
13046 SHOW_STR
13047 IP_STR
13048 BGP_STR
13049 BGP_INSTANCE_HELP_STR
13050 BGP_AFI_HELP_STR
13051 BGP_SAFI_WITH_LABEL_HELP_STR
13052 "Detailed info about dynamic update groups\n"
13053 "Specific subgroup to display detailed info for\n")
13054 {
13055 char *vrf = NULL;
13056 afi_t afi = AFI_IP6;
13057 safi_t safi = SAFI_UNICAST;
13058 uint64_t subgrp_id = 0;
13059
13060 int idx = 0;
13061
13062 /* show [ip] bgp */
13063 if (argv_find(argv, argc, "ip", &idx))
13064 afi = AFI_IP;
13065 /* [<vrf> VIEWVRFNAME] */
13066 if (argv_find(argv, argc, "vrf", &idx)) {
13067 vrf = argv[idx + 1]->arg;
13068 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
13069 vrf = NULL;
13070 } else if (argv_find(argv, argc, "view", &idx))
13071 /* [<view> VIEWVRFNAME] */
13072 vrf = argv[idx + 1]->arg;
13073 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
13074 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
13075 argv_find_and_parse_safi(argv, argc, &idx, &safi);
13076 }
13077
13078 /* get subgroup id, if provided */
13079 idx = argc - 1;
13080 if (argv[idx]->type == VARIABLE_TKN)
13081 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
13082
13083 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
13084 }
13085
13086 DEFUN (show_bgp_instance_all_ipv6_updgrps,
13087 show_bgp_instance_all_ipv6_updgrps_cmd,
13088 "show [ip] bgp <view|vrf> all update-groups",
13089 SHOW_STR
13090 IP_STR
13091 BGP_STR
13092 BGP_INSTANCE_ALL_HELP_STR
13093 "Detailed info about dynamic update groups\n")
13094 {
13095 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
13096 return CMD_SUCCESS;
13097 }
13098
13099 DEFUN (show_bgp_l2vpn_evpn_updgrps,
13100 show_bgp_l2vpn_evpn_updgrps_cmd,
13101 "show [ip] bgp l2vpn evpn update-groups",
13102 SHOW_STR
13103 IP_STR
13104 BGP_STR
13105 "l2vpn address family\n"
13106 "evpn sub-address family\n"
13107 "Detailed info about dynamic update groups\n")
13108 {
13109 char *vrf = NULL;
13110 uint64_t subgrp_id = 0;
13111
13112 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
13113 return CMD_SUCCESS;
13114 }
13115
13116 DEFUN (show_bgp_updgrps_stats,
13117 show_bgp_updgrps_stats_cmd,
13118 "show [ip] bgp update-groups statistics",
13119 SHOW_STR
13120 IP_STR
13121 BGP_STR
13122 "Detailed info about dynamic update groups\n"
13123 "Statistics\n")
13124 {
13125 struct bgp *bgp;
13126
13127 bgp = bgp_get_default();
13128 if (bgp)
13129 update_group_show_stats(bgp, vty);
13130
13131 return CMD_SUCCESS;
13132 }
13133
13134 DEFUN (show_bgp_instance_updgrps_stats,
13135 show_bgp_instance_updgrps_stats_cmd,
13136 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
13137 SHOW_STR
13138 IP_STR
13139 BGP_STR
13140 BGP_INSTANCE_HELP_STR
13141 "Detailed info about dynamic update groups\n"
13142 "Statistics\n")
13143 {
13144 int idx_word = 3;
13145 struct bgp *bgp;
13146
13147 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
13148 if (bgp)
13149 update_group_show_stats(bgp, vty);
13150
13151 return CMD_SUCCESS;
13152 }
13153
13154 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
13155 afi_t afi, safi_t safi,
13156 const char *what, uint64_t subgrp_id)
13157 {
13158 struct bgp *bgp;
13159
13160 if (name)
13161 bgp = bgp_lookup_by_name(name);
13162 else
13163 bgp = bgp_get_default();
13164
13165 if (bgp) {
13166 if (!strcmp(what, "advertise-queue"))
13167 update_group_show_adj_queue(bgp, afi, safi, vty,
13168 subgrp_id);
13169 else if (!strcmp(what, "advertised-routes"))
13170 update_group_show_advertised(bgp, afi, safi, vty,
13171 subgrp_id);
13172 else if (!strcmp(what, "packet-queue"))
13173 update_group_show_packet_queue(bgp, afi, safi, vty,
13174 subgrp_id);
13175 }
13176 }
13177
13178 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
13179 show_ip_bgp_instance_updgrps_adj_s_cmd,
13180 "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",
13181 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
13182 BGP_SAFI_HELP_STR
13183 "Detailed info about dynamic update groups\n"
13184 "Specific subgroup to display info for\n"
13185 "Advertisement queue\n"
13186 "Announced routes\n"
13187 "Packet queue\n")
13188 {
13189 uint64_t subgrp_id = 0;
13190 afi_t afiz;
13191 safi_t safiz;
13192 if (sgid)
13193 subgrp_id = strtoull(sgid, NULL, 10);
13194
13195 if (!ip && !afi)
13196 afiz = AFI_IP6;
13197 if (!ip && afi)
13198 afiz = bgp_vty_afi_from_str(afi);
13199 if (ip && !afi)
13200 afiz = AFI_IP;
13201 if (ip && afi) {
13202 afiz = bgp_vty_afi_from_str(afi);
13203 if (afiz != AFI_IP)
13204 vty_out(vty,
13205 "%% Cannot specify both 'ip' and 'ipv6'\n");
13206 return CMD_WARNING;
13207 }
13208
13209 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
13210
13211 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
13212 return CMD_SUCCESS;
13213 }
13214
13215 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
13216 {
13217 struct listnode *node, *nnode;
13218 struct prefix *range;
13219 struct peer *conf;
13220 struct peer *peer;
13221 char buf[PREFIX2STR_BUFFER];
13222 afi_t afi;
13223 safi_t safi;
13224 const char *peer_status;
13225 const char *af_str;
13226 int lr_count;
13227 int dynamic;
13228 int af_cfgd;
13229
13230 conf = group->conf;
13231
13232 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
13233 vty_out(vty, "\nBGP peer-group %s, remote AS %" PRIu32 "\n",
13234 group->name, conf->as);
13235 } else if (conf->as_type == AS_INTERNAL) {
13236 vty_out(vty, "\nBGP peer-group %s, remote AS %" PRIu32 "\n",
13237 group->name, group->bgp->as);
13238 } else {
13239 vty_out(vty, "\nBGP peer-group %s\n", group->name);
13240 }
13241
13242 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
13243 vty_out(vty, " Peer-group type is internal\n");
13244 else
13245 vty_out(vty, " Peer-group type is external\n");
13246
13247 /* Display AFs configured. */
13248 vty_out(vty, " Configured address-families:");
13249 FOREACH_AFI_SAFI (afi, safi) {
13250 if (conf->afc[afi][safi]) {
13251 af_cfgd = 1;
13252 vty_out(vty, " %s;", get_afi_safi_str(afi, safi, false));
13253 }
13254 }
13255 if (!af_cfgd)
13256 vty_out(vty, " none\n");
13257 else
13258 vty_out(vty, "\n");
13259
13260 /* Display listen ranges (for dynamic neighbors), if any */
13261 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
13262 if (afi == AFI_IP)
13263 af_str = "IPv4";
13264 else if (afi == AFI_IP6)
13265 af_str = "IPv6";
13266 else
13267 af_str = "???";
13268 lr_count = listcount(group->listen_range[afi]);
13269 if (lr_count) {
13270 vty_out(vty, " %d %s listen range(s)\n", lr_count,
13271 af_str);
13272
13273
13274 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
13275 nnode, range)) {
13276 prefix2str(range, buf, sizeof(buf));
13277 vty_out(vty, " %s\n", buf);
13278 }
13279 }
13280 }
13281
13282 /* Display group members and their status */
13283 if (listcount(group->peer)) {
13284 vty_out(vty, " Peer-group members:\n");
13285 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
13286 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
13287 peer_status = "Idle (Admin)";
13288 else if (CHECK_FLAG(peer->sflags,
13289 PEER_STATUS_PREFIX_OVERFLOW))
13290 peer_status = "Idle (PfxCt)";
13291 else
13292 peer_status = lookup_msg(bgp_status_msg,
13293 peer->status, NULL);
13294
13295 dynamic = peer_dynamic_neighbor(peer);
13296 vty_out(vty, " %s %s %s \n", peer->host,
13297 dynamic ? "(dynamic)" : "", peer_status);
13298 }
13299 }
13300
13301 return CMD_SUCCESS;
13302 }
13303
13304 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
13305 const char *group_name)
13306 {
13307 struct bgp *bgp;
13308 struct listnode *node, *nnode;
13309 struct peer_group *group;
13310 bool found = false;
13311
13312 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
13313
13314 if (!bgp) {
13315 vty_out(vty, "%% BGP instance not found\n");
13316 return CMD_WARNING;
13317 }
13318
13319 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
13320 if (group_name) {
13321 if (strmatch(group->name, group_name)) {
13322 bgp_show_one_peer_group(vty, group);
13323 found = true;
13324 break;
13325 }
13326 } else {
13327 bgp_show_one_peer_group(vty, group);
13328 }
13329 }
13330
13331 if (group_name && !found)
13332 vty_out(vty, "%% No such peer-group\n");
13333
13334 return CMD_SUCCESS;
13335 }
13336
13337 DEFUN (show_ip_bgp_peer_groups,
13338 show_ip_bgp_peer_groups_cmd,
13339 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
13340 SHOW_STR
13341 IP_STR
13342 BGP_STR
13343 BGP_INSTANCE_HELP_STR
13344 "Detailed information on BGP peer groups\n"
13345 "Peer group name\n")
13346 {
13347 char *vrf, *pg;
13348 int idx = 0;
13349
13350 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
13351 : NULL;
13352 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
13353
13354 return bgp_show_peer_group_vty(vty, vrf, pg);
13355 }
13356
13357
13358 /* Redistribute VTY commands. */
13359
13360 DEFUN (bgp_redistribute_ipv4,
13361 bgp_redistribute_ipv4_cmd,
13362 "redistribute " FRR_IP_REDIST_STR_BGPD,
13363 "Redistribute information from another routing protocol\n"
13364 FRR_IP_REDIST_HELP_STR_BGPD)
13365 {
13366 VTY_DECLVAR_CONTEXT(bgp, bgp);
13367 int idx_protocol = 1;
13368 int type;
13369
13370 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
13371 if (type < 0) {
13372 vty_out(vty, "%% Invalid route type\n");
13373 return CMD_WARNING_CONFIG_FAILED;
13374 }
13375
13376 bgp_redist_add(bgp, AFI_IP, type, 0);
13377 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
13378 }
13379
13380 ALIAS_HIDDEN(
13381 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
13382 "redistribute " FRR_IP_REDIST_STR_BGPD,
13383 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
13384
13385 DEFUN (bgp_redistribute_ipv4_rmap,
13386 bgp_redistribute_ipv4_rmap_cmd,
13387 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
13388 "Redistribute information from another routing protocol\n"
13389 FRR_IP_REDIST_HELP_STR_BGPD
13390 "Route map reference\n"
13391 "Pointer to route-map entries\n")
13392 {
13393 VTY_DECLVAR_CONTEXT(bgp, bgp);
13394 int idx_protocol = 1;
13395 int idx_word = 3;
13396 int type;
13397 struct bgp_redist *red;
13398 bool changed;
13399 struct route_map *route_map = route_map_lookup_warn_noexist(
13400 vty, argv[idx_word]->arg);
13401
13402 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
13403 if (type < 0) {
13404 vty_out(vty, "%% Invalid route type\n");
13405 return CMD_WARNING_CONFIG_FAILED;
13406 }
13407
13408 red = bgp_redist_add(bgp, AFI_IP, type, 0);
13409 changed =
13410 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
13411 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
13412 }
13413
13414 ALIAS_HIDDEN(
13415 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
13416 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
13417 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
13418 "Route map reference\n"
13419 "Pointer to route-map entries\n")
13420
13421 DEFUN (bgp_redistribute_ipv4_metric,
13422 bgp_redistribute_ipv4_metric_cmd,
13423 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
13424 "Redistribute information from another routing protocol\n"
13425 FRR_IP_REDIST_HELP_STR_BGPD
13426 "Metric for redistributed routes\n"
13427 "Default metric\n")
13428 {
13429 VTY_DECLVAR_CONTEXT(bgp, bgp);
13430 int idx_protocol = 1;
13431 int idx_number = 3;
13432 int type;
13433 uint32_t metric;
13434 struct bgp_redist *red;
13435 bool changed;
13436
13437 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
13438 if (type < 0) {
13439 vty_out(vty, "%% Invalid route type\n");
13440 return CMD_WARNING_CONFIG_FAILED;
13441 }
13442 metric = strtoul(argv[idx_number]->arg, NULL, 10);
13443
13444 red = bgp_redist_add(bgp, AFI_IP, type, 0);
13445 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
13446 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
13447 }
13448
13449 ALIAS_HIDDEN(
13450 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
13451 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
13452 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
13453 "Metric for redistributed routes\n"
13454 "Default metric\n")
13455
13456 DEFUN (bgp_redistribute_ipv4_rmap_metric,
13457 bgp_redistribute_ipv4_rmap_metric_cmd,
13458 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
13459 "Redistribute information from another routing protocol\n"
13460 FRR_IP_REDIST_HELP_STR_BGPD
13461 "Route map reference\n"
13462 "Pointer to route-map entries\n"
13463 "Metric for redistributed routes\n"
13464 "Default metric\n")
13465 {
13466 VTY_DECLVAR_CONTEXT(bgp, bgp);
13467 int idx_protocol = 1;
13468 int idx_word = 3;
13469 int idx_number = 5;
13470 int type;
13471 uint32_t metric;
13472 struct bgp_redist *red;
13473 bool changed;
13474 struct route_map *route_map =
13475 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
13476
13477 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
13478 if (type < 0) {
13479 vty_out(vty, "%% Invalid route type\n");
13480 return CMD_WARNING_CONFIG_FAILED;
13481 }
13482 metric = strtoul(argv[idx_number]->arg, NULL, 10);
13483
13484 red = bgp_redist_add(bgp, AFI_IP, type, 0);
13485 changed =
13486 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
13487 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
13488 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
13489 }
13490
13491 ALIAS_HIDDEN(
13492 bgp_redistribute_ipv4_rmap_metric,
13493 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
13494 "redistribute " FRR_IP_REDIST_STR_BGPD
13495 " route-map WORD metric (0-4294967295)",
13496 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
13497 "Route map reference\n"
13498 "Pointer to route-map entries\n"
13499 "Metric for redistributed routes\n"
13500 "Default metric\n")
13501
13502 DEFUN (bgp_redistribute_ipv4_metric_rmap,
13503 bgp_redistribute_ipv4_metric_rmap_cmd,
13504 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
13505 "Redistribute information from another routing protocol\n"
13506 FRR_IP_REDIST_HELP_STR_BGPD
13507 "Metric for redistributed routes\n"
13508 "Default metric\n"
13509 "Route map reference\n"
13510 "Pointer to route-map entries\n")
13511 {
13512 VTY_DECLVAR_CONTEXT(bgp, bgp);
13513 int idx_protocol = 1;
13514 int idx_number = 3;
13515 int idx_word = 5;
13516 int type;
13517 uint32_t metric;
13518 struct bgp_redist *red;
13519 bool changed;
13520 struct route_map *route_map =
13521 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
13522
13523 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
13524 if (type < 0) {
13525 vty_out(vty, "%% Invalid route type\n");
13526 return CMD_WARNING_CONFIG_FAILED;
13527 }
13528 metric = strtoul(argv[idx_number]->arg, NULL, 10);
13529
13530 red = bgp_redist_add(bgp, AFI_IP, type, 0);
13531 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
13532 changed |=
13533 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
13534 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
13535 }
13536
13537 ALIAS_HIDDEN(
13538 bgp_redistribute_ipv4_metric_rmap,
13539 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
13540 "redistribute " FRR_IP_REDIST_STR_BGPD
13541 " metric (0-4294967295) route-map WORD",
13542 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
13543 "Metric for redistributed routes\n"
13544 "Default metric\n"
13545 "Route map reference\n"
13546 "Pointer to route-map entries\n")
13547
13548 DEFUN (bgp_redistribute_ipv4_ospf,
13549 bgp_redistribute_ipv4_ospf_cmd,
13550 "redistribute <ospf|table> (1-65535)",
13551 "Redistribute information from another routing protocol\n"
13552 "Open Shortest Path First (OSPFv2)\n"
13553 "Non-main Kernel Routing Table\n"
13554 "Instance ID/Table ID\n")
13555 {
13556 VTY_DECLVAR_CONTEXT(bgp, bgp);
13557 int idx_ospf_table = 1;
13558 int idx_number = 2;
13559 unsigned short instance;
13560 unsigned short protocol;
13561
13562 instance = strtoul(argv[idx_number]->arg, NULL, 10);
13563
13564 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
13565 protocol = ZEBRA_ROUTE_OSPF;
13566 else
13567 protocol = ZEBRA_ROUTE_TABLE;
13568
13569 bgp_redist_add(bgp, AFI_IP, protocol, instance);
13570 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
13571 }
13572
13573 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
13574 "redistribute <ospf|table> (1-65535)",
13575 "Redistribute information from another routing protocol\n"
13576 "Open Shortest Path First (OSPFv2)\n"
13577 "Non-main Kernel Routing Table\n"
13578 "Instance ID/Table ID\n")
13579
13580 DEFUN (bgp_redistribute_ipv4_ospf_rmap,
13581 bgp_redistribute_ipv4_ospf_rmap_cmd,
13582 "redistribute <ospf|table> (1-65535) route-map WORD",
13583 "Redistribute information from another routing protocol\n"
13584 "Open Shortest Path First (OSPFv2)\n"
13585 "Non-main Kernel Routing Table\n"
13586 "Instance ID/Table ID\n"
13587 "Route map reference\n"
13588 "Pointer to route-map entries\n")
13589 {
13590 VTY_DECLVAR_CONTEXT(bgp, bgp);
13591 int idx_ospf_table = 1;
13592 int idx_number = 2;
13593 int idx_word = 4;
13594 struct bgp_redist *red;
13595 unsigned short instance;
13596 int protocol;
13597 bool changed;
13598 struct route_map *route_map =
13599 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
13600
13601 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
13602 protocol = ZEBRA_ROUTE_OSPF;
13603 else
13604 protocol = ZEBRA_ROUTE_TABLE;
13605
13606 instance = strtoul(argv[idx_number]->arg, NULL, 10);
13607 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
13608 changed =
13609 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
13610 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
13611 }
13612
13613 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
13614 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
13615 "redistribute <ospf|table> (1-65535) route-map WORD",
13616 "Redistribute information from another routing protocol\n"
13617 "Open Shortest Path First (OSPFv2)\n"
13618 "Non-main Kernel Routing Table\n"
13619 "Instance ID/Table ID\n"
13620 "Route map reference\n"
13621 "Pointer to route-map entries\n")
13622
13623 DEFUN (bgp_redistribute_ipv4_ospf_metric,
13624 bgp_redistribute_ipv4_ospf_metric_cmd,
13625 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
13626 "Redistribute information from another routing protocol\n"
13627 "Open Shortest Path First (OSPFv2)\n"
13628 "Non-main Kernel Routing Table\n"
13629 "Instance ID/Table ID\n"
13630 "Metric for redistributed routes\n"
13631 "Default metric\n")
13632 {
13633 VTY_DECLVAR_CONTEXT(bgp, bgp);
13634 int idx_ospf_table = 1;
13635 int idx_number = 2;
13636 int idx_number_2 = 4;
13637 uint32_t metric;
13638 struct bgp_redist *red;
13639 unsigned short instance;
13640 int protocol;
13641 bool changed;
13642
13643 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
13644 protocol = ZEBRA_ROUTE_OSPF;
13645 else
13646 protocol = ZEBRA_ROUTE_TABLE;
13647
13648 instance = strtoul(argv[idx_number]->arg, NULL, 10);
13649 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
13650
13651 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
13652 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
13653 metric);
13654 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
13655 }
13656
13657 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
13658 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
13659 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
13660 "Redistribute information from another routing protocol\n"
13661 "Open Shortest Path First (OSPFv2)\n"
13662 "Non-main Kernel Routing Table\n"
13663 "Instance ID/Table ID\n"
13664 "Metric for redistributed routes\n"
13665 "Default metric\n")
13666
13667 DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
13668 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
13669 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
13670 "Redistribute information from another routing protocol\n"
13671 "Open Shortest Path First (OSPFv2)\n"
13672 "Non-main Kernel Routing Table\n"
13673 "Instance ID/Table ID\n"
13674 "Route map reference\n"
13675 "Pointer to route-map entries\n"
13676 "Metric for redistributed routes\n"
13677 "Default metric\n")
13678 {
13679 VTY_DECLVAR_CONTEXT(bgp, bgp);
13680 int idx_ospf_table = 1;
13681 int idx_number = 2;
13682 int idx_word = 4;
13683 int idx_number_2 = 6;
13684 uint32_t metric;
13685 struct bgp_redist *red;
13686 unsigned short instance;
13687 int protocol;
13688 bool changed;
13689 struct route_map *route_map =
13690 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
13691
13692 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
13693 protocol = ZEBRA_ROUTE_OSPF;
13694 else
13695 protocol = ZEBRA_ROUTE_TABLE;
13696
13697 instance = strtoul(argv[idx_number]->arg, NULL, 10);
13698 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
13699
13700 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
13701 changed =
13702 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
13703 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
13704 metric);
13705 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
13706 }
13707
13708 ALIAS_HIDDEN(
13709 bgp_redistribute_ipv4_ospf_rmap_metric,
13710 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
13711 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
13712 "Redistribute information from another routing protocol\n"
13713 "Open Shortest Path First (OSPFv2)\n"
13714 "Non-main Kernel Routing Table\n"
13715 "Instance ID/Table ID\n"
13716 "Route map reference\n"
13717 "Pointer to route-map entries\n"
13718 "Metric for redistributed routes\n"
13719 "Default metric\n")
13720
13721 DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
13722 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
13723 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
13724 "Redistribute information from another routing protocol\n"
13725 "Open Shortest Path First (OSPFv2)\n"
13726 "Non-main Kernel Routing Table\n"
13727 "Instance ID/Table ID\n"
13728 "Metric for redistributed routes\n"
13729 "Default metric\n"
13730 "Route map reference\n"
13731 "Pointer to route-map entries\n")
13732 {
13733 VTY_DECLVAR_CONTEXT(bgp, bgp);
13734 int idx_ospf_table = 1;
13735 int idx_number = 2;
13736 int idx_number_2 = 4;
13737 int idx_word = 6;
13738 uint32_t metric;
13739 struct bgp_redist *red;
13740 unsigned short instance;
13741 int protocol;
13742 bool changed;
13743 struct route_map *route_map =
13744 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
13745
13746 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
13747 protocol = ZEBRA_ROUTE_OSPF;
13748 else
13749 protocol = ZEBRA_ROUTE_TABLE;
13750
13751 instance = strtoul(argv[idx_number]->arg, NULL, 10);
13752 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
13753
13754 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
13755 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
13756 metric);
13757 changed |=
13758 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
13759 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
13760 }
13761
13762 ALIAS_HIDDEN(
13763 bgp_redistribute_ipv4_ospf_metric_rmap,
13764 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
13765 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
13766 "Redistribute information from another routing protocol\n"
13767 "Open Shortest Path First (OSPFv2)\n"
13768 "Non-main Kernel Routing Table\n"
13769 "Instance ID/Table ID\n"
13770 "Metric for redistributed routes\n"
13771 "Default metric\n"
13772 "Route map reference\n"
13773 "Pointer to route-map entries\n")
13774
13775 DEFUN (no_bgp_redistribute_ipv4_ospf,
13776 no_bgp_redistribute_ipv4_ospf_cmd,
13777 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
13778 NO_STR
13779 "Redistribute information from another routing protocol\n"
13780 "Open Shortest Path First (OSPFv2)\n"
13781 "Non-main Kernel Routing Table\n"
13782 "Instance ID/Table ID\n"
13783 "Metric for redistributed routes\n"
13784 "Default metric\n"
13785 "Route map reference\n"
13786 "Pointer to route-map entries\n")
13787 {
13788 VTY_DECLVAR_CONTEXT(bgp, bgp);
13789 int idx_ospf_table = 2;
13790 int idx_number = 3;
13791 unsigned short instance;
13792 int protocol;
13793
13794 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
13795 protocol = ZEBRA_ROUTE_OSPF;
13796 else
13797 protocol = ZEBRA_ROUTE_TABLE;
13798
13799 instance = strtoul(argv[idx_number]->arg, NULL, 10);
13800 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
13801 }
13802
13803 ALIAS_HIDDEN(
13804 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
13805 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
13806 NO_STR
13807 "Redistribute information from another routing protocol\n"
13808 "Open Shortest Path First (OSPFv2)\n"
13809 "Non-main Kernel Routing Table\n"
13810 "Instance ID/Table ID\n"
13811 "Metric for redistributed routes\n"
13812 "Default metric\n"
13813 "Route map reference\n"
13814 "Pointer to route-map entries\n")
13815
13816 DEFUN (no_bgp_redistribute_ipv4,
13817 no_bgp_redistribute_ipv4_cmd,
13818 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
13819 NO_STR
13820 "Redistribute information from another routing protocol\n"
13821 FRR_IP_REDIST_HELP_STR_BGPD
13822 "Metric for redistributed routes\n"
13823 "Default metric\n"
13824 "Route map reference\n"
13825 "Pointer to route-map entries\n")
13826 {
13827 VTY_DECLVAR_CONTEXT(bgp, bgp);
13828 int idx_protocol = 2;
13829 int type;
13830
13831 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
13832 if (type < 0) {
13833 vty_out(vty, "%% Invalid route type\n");
13834 return CMD_WARNING_CONFIG_FAILED;
13835 }
13836 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
13837 }
13838
13839 ALIAS_HIDDEN(
13840 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
13841 "no redistribute " FRR_IP_REDIST_STR_BGPD
13842 " [{metric (0-4294967295)|route-map WORD}]",
13843 NO_STR
13844 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
13845 "Metric for redistributed routes\n"
13846 "Default metric\n"
13847 "Route map reference\n"
13848 "Pointer to route-map entries\n")
13849
13850 DEFUN (bgp_redistribute_ipv6,
13851 bgp_redistribute_ipv6_cmd,
13852 "redistribute " FRR_IP6_REDIST_STR_BGPD,
13853 "Redistribute information from another routing protocol\n"
13854 FRR_IP6_REDIST_HELP_STR_BGPD)
13855 {
13856 VTY_DECLVAR_CONTEXT(bgp, bgp);
13857 int idx_protocol = 1;
13858 int type;
13859
13860 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
13861 if (type < 0) {
13862 vty_out(vty, "%% Invalid route type\n");
13863 return CMD_WARNING_CONFIG_FAILED;
13864 }
13865
13866 bgp_redist_add(bgp, AFI_IP6, type, 0);
13867 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
13868 }
13869
13870 DEFUN (bgp_redistribute_ipv6_rmap,
13871 bgp_redistribute_ipv6_rmap_cmd,
13872 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
13873 "Redistribute information from another routing protocol\n"
13874 FRR_IP6_REDIST_HELP_STR_BGPD
13875 "Route map reference\n"
13876 "Pointer to route-map entries\n")
13877 {
13878 VTY_DECLVAR_CONTEXT(bgp, bgp);
13879 int idx_protocol = 1;
13880 int idx_word = 3;
13881 int type;
13882 struct bgp_redist *red;
13883 bool changed;
13884 struct route_map *route_map =
13885 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
13886
13887 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
13888 if (type < 0) {
13889 vty_out(vty, "%% Invalid route type\n");
13890 return CMD_WARNING_CONFIG_FAILED;
13891 }
13892
13893 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
13894 changed =
13895 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
13896 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
13897 }
13898
13899 DEFUN (bgp_redistribute_ipv6_metric,
13900 bgp_redistribute_ipv6_metric_cmd,
13901 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
13902 "Redistribute information from another routing protocol\n"
13903 FRR_IP6_REDIST_HELP_STR_BGPD
13904 "Metric for redistributed routes\n"
13905 "Default metric\n")
13906 {
13907 VTY_DECLVAR_CONTEXT(bgp, bgp);
13908 int idx_protocol = 1;
13909 int idx_number = 3;
13910 int type;
13911 uint32_t metric;
13912 struct bgp_redist *red;
13913 bool changed;
13914
13915 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
13916 if (type < 0) {
13917 vty_out(vty, "%% Invalid route type\n");
13918 return CMD_WARNING_CONFIG_FAILED;
13919 }
13920 metric = strtoul(argv[idx_number]->arg, NULL, 10);
13921
13922 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
13923 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
13924 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
13925 }
13926
13927 DEFUN (bgp_redistribute_ipv6_rmap_metric,
13928 bgp_redistribute_ipv6_rmap_metric_cmd,
13929 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
13930 "Redistribute information from another routing protocol\n"
13931 FRR_IP6_REDIST_HELP_STR_BGPD
13932 "Route map reference\n"
13933 "Pointer to route-map entries\n"
13934 "Metric for redistributed routes\n"
13935 "Default metric\n")
13936 {
13937 VTY_DECLVAR_CONTEXT(bgp, bgp);
13938 int idx_protocol = 1;
13939 int idx_word = 3;
13940 int idx_number = 5;
13941 int type;
13942 uint32_t metric;
13943 struct bgp_redist *red;
13944 bool changed;
13945 struct route_map *route_map =
13946 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
13947
13948 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
13949 if (type < 0) {
13950 vty_out(vty, "%% Invalid route type\n");
13951 return CMD_WARNING_CONFIG_FAILED;
13952 }
13953 metric = strtoul(argv[idx_number]->arg, NULL, 10);
13954
13955 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
13956 changed =
13957 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
13958 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
13959 metric);
13960 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
13961 }
13962
13963 DEFUN (bgp_redistribute_ipv6_metric_rmap,
13964 bgp_redistribute_ipv6_metric_rmap_cmd,
13965 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
13966 "Redistribute information from another routing protocol\n"
13967 FRR_IP6_REDIST_HELP_STR_BGPD
13968 "Metric for redistributed routes\n"
13969 "Default metric\n"
13970 "Route map reference\n"
13971 "Pointer to route-map entries\n")
13972 {
13973 VTY_DECLVAR_CONTEXT(bgp, bgp);
13974 int idx_protocol = 1;
13975 int idx_number = 3;
13976 int idx_word = 5;
13977 int type;
13978 uint32_t metric;
13979 struct bgp_redist *red;
13980 bool changed;
13981 struct route_map *route_map =
13982 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
13983
13984 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
13985 if (type < 0) {
13986 vty_out(vty, "%% Invalid route type\n");
13987 return CMD_WARNING_CONFIG_FAILED;
13988 }
13989 metric = strtoul(argv[idx_number]->arg, NULL, 10);
13990
13991 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
13992 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
13993 metric);
13994 changed |=
13995 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
13996 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
13997 }
13998
13999 DEFUN (no_bgp_redistribute_ipv6,
14000 no_bgp_redistribute_ipv6_cmd,
14001 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
14002 NO_STR
14003 "Redistribute information from another routing protocol\n"
14004 FRR_IP6_REDIST_HELP_STR_BGPD
14005 "Metric for redistributed routes\n"
14006 "Default metric\n"
14007 "Route map reference\n"
14008 "Pointer to route-map entries\n")
14009 {
14010 VTY_DECLVAR_CONTEXT(bgp, bgp);
14011 int idx_protocol = 2;
14012 int type;
14013
14014 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
14015 if (type < 0) {
14016 vty_out(vty, "%% Invalid route type\n");
14017 return CMD_WARNING_CONFIG_FAILED;
14018 }
14019
14020 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
14021 }
14022
14023 static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
14024 afi_t afi, safi_t safi)
14025 {
14026 int i;
14027
14028 /* Unicast redistribution only. */
14029 if (safi != SAFI_UNICAST)
14030 return;
14031
14032 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
14033 /* Redistribute BGP does not make sense. */
14034 if (i != ZEBRA_ROUTE_BGP) {
14035 struct list *red_list;
14036 struct listnode *node;
14037 struct bgp_redist *red;
14038
14039 red_list = bgp->redist[afi][i];
14040 if (!red_list)
14041 continue;
14042
14043 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
14044 /* "redistribute" configuration. */
14045 vty_out(vty, " redistribute %s",
14046 zebra_route_string(i));
14047 if (red->instance)
14048 vty_out(vty, " %d", red->instance);
14049 if (red->redist_metric_flag)
14050 vty_out(vty, " metric %u",
14051 red->redist_metric);
14052 if (red->rmap.name)
14053 vty_out(vty, " route-map %s",
14054 red->rmap.name);
14055 vty_out(vty, "\n");
14056 }
14057 }
14058 }
14059 }
14060
14061 /* peer-group helpers for config-write */
14062
14063 static bool peergroup_flag_check(struct peer *peer, uint32_t flag)
14064 {
14065 if (!peer_group_active(peer)) {
14066 if (CHECK_FLAG(peer->flags_invert, flag))
14067 return !CHECK_FLAG(peer->flags, flag);
14068 else
14069 return !!CHECK_FLAG(peer->flags, flag);
14070 }
14071
14072 return !!CHECK_FLAG(peer->flags_override, flag);
14073 }
14074
14075 static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
14076 uint32_t flag)
14077 {
14078 if (!peer_group_active(peer)) {
14079 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
14080 return !peer_af_flag_check(peer, afi, safi, flag);
14081 else
14082 return !!peer_af_flag_check(peer, afi, safi, flag);
14083 }
14084
14085 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
14086 }
14087
14088 static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
14089 uint8_t type, int direct)
14090 {
14091 struct bgp_filter *filter;
14092
14093 if (peer_group_active(peer))
14094 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
14095 type);
14096
14097 filter = &peer->filter[afi][safi];
14098 switch (type) {
14099 case PEER_FT_DISTRIBUTE_LIST:
14100 return !!(filter->dlist[direct].name);
14101 case PEER_FT_FILTER_LIST:
14102 return !!(filter->aslist[direct].name);
14103 case PEER_FT_PREFIX_LIST:
14104 return !!(filter->plist[direct].name);
14105 case PEER_FT_ROUTE_MAP:
14106 return !!(filter->map[direct].name);
14107 case PEER_FT_UNSUPPRESS_MAP:
14108 return !!(filter->usmap.name);
14109 default:
14110 return false;
14111 }
14112 }
14113
14114 /* Return true if the addpath type is set for peer and different from
14115 * peer-group.
14116 */
14117 static int peergroup_af_addpath_check(struct peer *peer, afi_t afi, safi_t safi)
14118 {
14119 enum bgp_addpath_strat type, g_type;
14120
14121 type = peer->addpath_type[afi][safi];
14122
14123 if (type != BGP_ADDPATH_NONE) {
14124 if (peer_group_active(peer)) {
14125 g_type = peer->group->conf->addpath_type[afi][safi];
14126
14127 if (type != g_type)
14128 return 1;
14129 else
14130 return 0;
14131 }
14132
14133 return 1;
14134 }
14135
14136 return 0;
14137 }
14138
14139 /* This is part of the address-family block (unicast only) */
14140 static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
14141 afi_t afi)
14142 {
14143 int indent = 2;
14144
14145 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
14146 if (listcount(bgp->vpn_policy[afi].import_vrf))
14147 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
14148 bgp->vpn_policy[afi]
14149 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
14150 else
14151 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
14152 bgp->vpn_policy[afi]
14153 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
14154 }
14155 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
14156 BGP_CONFIG_VRF_TO_VRF_IMPORT)
14157 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
14158 BGP_CONFIG_VRF_TO_VRF_EXPORT))
14159 return;
14160
14161 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
14162 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
14163
14164 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
14165
14166 } else {
14167 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
14168 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
14169 bgp->vpn_policy[afi].tovpn_label);
14170 }
14171 }
14172 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
14173 BGP_VPN_POLICY_TOVPN_RD_SET)) {
14174 char buf[RD_ADDRSTRLEN];
14175 vty_out(vty, "%*srd vpn export %s\n", indent, "",
14176 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
14177 sizeof(buf)));
14178 }
14179 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
14180 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
14181
14182 char buf[PREFIX_STRLEN];
14183 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
14184 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
14185 sizeof(buf))) {
14186
14187 vty_out(vty, "%*snexthop vpn export %s\n",
14188 indent, "", buf);
14189 }
14190 }
14191 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
14192 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
14193 && ecommunity_cmp(
14194 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
14195 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
14196
14197 char *b = ecommunity_ecom2str(
14198 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
14199 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
14200 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
14201 XFREE(MTYPE_ECOMMUNITY_STR, b);
14202 } else {
14203 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
14204 char *b = ecommunity_ecom2str(
14205 bgp->vpn_policy[afi]
14206 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
14207 ECOMMUNITY_FORMAT_ROUTE_MAP,
14208 ECOMMUNITY_ROUTE_TARGET);
14209 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
14210 XFREE(MTYPE_ECOMMUNITY_STR, b);
14211 }
14212 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
14213 char *b = ecommunity_ecom2str(
14214 bgp->vpn_policy[afi]
14215 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
14216 ECOMMUNITY_FORMAT_ROUTE_MAP,
14217 ECOMMUNITY_ROUTE_TARGET);
14218 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
14219 XFREE(MTYPE_ECOMMUNITY_STR, b);
14220 }
14221 }
14222
14223 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
14224 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
14225 bgp->vpn_policy[afi]
14226 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
14227
14228 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
14229 char *b = ecommunity_ecom2str(
14230 bgp->vpn_policy[afi]
14231 .import_redirect_rtlist,
14232 ECOMMUNITY_FORMAT_ROUTE_MAP,
14233 ECOMMUNITY_ROUTE_TARGET);
14234
14235 vty_out(vty, "%*srt redirect import %s\n", indent, "", b);
14236 XFREE(MTYPE_ECOMMUNITY_STR, b);
14237 }
14238 }
14239
14240 static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
14241 afi_t afi, safi_t safi)
14242 {
14243 struct bgp_filter *filter;
14244 char *addr;
14245
14246 addr = peer->host;
14247 filter = &peer->filter[afi][safi];
14248
14249 /* distribute-list. */
14250 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
14251 FILTER_IN))
14252 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
14253 filter->dlist[FILTER_IN].name);
14254
14255 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
14256 FILTER_OUT))
14257 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
14258 filter->dlist[FILTER_OUT].name);
14259
14260 /* prefix-list. */
14261 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
14262 FILTER_IN))
14263 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
14264 filter->plist[FILTER_IN].name);
14265
14266 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
14267 FILTER_OUT))
14268 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
14269 filter->plist[FILTER_OUT].name);
14270
14271 /* route-map. */
14272 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
14273 vty_out(vty, " neighbor %s route-map %s in\n", addr,
14274 filter->map[RMAP_IN].name);
14275
14276 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
14277 RMAP_OUT))
14278 vty_out(vty, " neighbor %s route-map %s out\n", addr,
14279 filter->map[RMAP_OUT].name);
14280
14281 /* unsuppress-map */
14282 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
14283 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
14284 filter->usmap.name);
14285
14286 /* filter-list. */
14287 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
14288 FILTER_IN))
14289 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
14290 filter->aslist[FILTER_IN].name);
14291
14292 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
14293 FILTER_OUT))
14294 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
14295 filter->aslist[FILTER_OUT].name);
14296 }
14297
14298 /* BGP peer configuration display function. */
14299 static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
14300 struct peer *peer)
14301 {
14302 struct peer *g_peer = NULL;
14303 char buf[SU_ADDRSTRLEN];
14304 char *addr;
14305 int if_pg_printed = false;
14306 int if_ras_printed = false;
14307
14308 /* Skip dynamic neighbors. */
14309 if (peer_dynamic_neighbor(peer))
14310 return;
14311
14312 if (peer->conf_if)
14313 addr = peer->conf_if;
14314 else
14315 addr = peer->host;
14316
14317 /************************************
14318 ****** Global to the neighbor ******
14319 ************************************/
14320 if (peer->conf_if) {
14321 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
14322 vty_out(vty, " neighbor %s interface v6only", addr);
14323 else
14324 vty_out(vty, " neighbor %s interface", addr);
14325
14326 if (peer_group_active(peer)) {
14327 vty_out(vty, " peer-group %s", peer->group->name);
14328 if_pg_printed = true;
14329 } else if (peer->as_type == AS_SPECIFIED) {
14330 vty_out(vty, " remote-as %u", peer->as);
14331 if_ras_printed = true;
14332 } else if (peer->as_type == AS_INTERNAL) {
14333 vty_out(vty, " remote-as internal");
14334 if_ras_printed = true;
14335 } else if (peer->as_type == AS_EXTERNAL) {
14336 vty_out(vty, " remote-as external");
14337 if_ras_printed = true;
14338 }
14339
14340 vty_out(vty, "\n");
14341 }
14342
14343 /* remote-as and peer-group */
14344 /* peer is a member of a peer-group */
14345 if (peer_group_active(peer)) {
14346 g_peer = peer->group->conf;
14347
14348 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
14349 if (peer->as_type == AS_SPECIFIED) {
14350 vty_out(vty, " neighbor %s remote-as %u\n",
14351 addr, peer->as);
14352 } else if (peer->as_type == AS_INTERNAL) {
14353 vty_out(vty,
14354 " neighbor %s remote-as internal\n",
14355 addr);
14356 } else if (peer->as_type == AS_EXTERNAL) {
14357 vty_out(vty,
14358 " neighbor %s remote-as external\n",
14359 addr);
14360 }
14361 }
14362
14363 /* For swpX peers we displayed the peer-group
14364 * via 'neighbor swpX interface peer-group PGNAME' */
14365 if (!if_pg_printed)
14366 vty_out(vty, " neighbor %s peer-group %s\n", addr,
14367 peer->group->name);
14368 }
14369
14370 /* peer is NOT a member of a peer-group */
14371 else {
14372 /* peer is a peer-group, declare the peer-group */
14373 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
14374 vty_out(vty, " neighbor %s peer-group\n", addr);
14375 }
14376
14377 if (!if_ras_printed) {
14378 if (peer->as_type == AS_SPECIFIED) {
14379 vty_out(vty, " neighbor %s remote-as %u\n",
14380 addr, peer->as);
14381 } else if (peer->as_type == AS_INTERNAL) {
14382 vty_out(vty,
14383 " neighbor %s remote-as internal\n",
14384 addr);
14385 } else if (peer->as_type == AS_EXTERNAL) {
14386 vty_out(vty,
14387 " neighbor %s remote-as external\n",
14388 addr);
14389 }
14390 }
14391 }
14392
14393 /* local-as */
14394 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
14395 vty_out(vty, " neighbor %s local-as %u", addr,
14396 peer->change_local_as);
14397 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
14398 vty_out(vty, " no-prepend");
14399 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
14400 vty_out(vty, " replace-as");
14401 vty_out(vty, "\n");
14402 }
14403
14404 /* description */
14405 if (peer->desc) {
14406 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
14407 }
14408
14409 /* shutdown */
14410 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
14411 if (peer->tx_shutdown_message)
14412 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
14413 peer->tx_shutdown_message);
14414 else
14415 vty_out(vty, " neighbor %s shutdown\n", addr);
14416 }
14417
14418 /* bfd */
14419 if (peer->bfd_info) {
14420 if (!peer_group_active(peer) || !g_peer->bfd_info) {
14421 bgp_bfd_peer_config_write(vty, peer, addr);
14422 }
14423 }
14424
14425 /* password */
14426 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
14427 vty_out(vty, " neighbor %s password %s\n", addr,
14428 peer->password);
14429
14430 /* neighbor solo */
14431 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
14432 if (!peer_group_active(peer)) {
14433 vty_out(vty, " neighbor %s solo\n", addr);
14434 }
14435 }
14436
14437 /* BGP port */
14438 if (peer->port != BGP_PORT_DEFAULT) {
14439 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
14440 }
14441
14442 /* Local interface name */
14443 if (peer->ifname) {
14444 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
14445 }
14446
14447 /* passive */
14448 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
14449 vty_out(vty, " neighbor %s passive\n", addr);
14450
14451 /* ebgp-multihop */
14452 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
14453 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
14454 && peer->ttl == MAXTTL)) {
14455 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
14456 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
14457 peer->ttl);
14458 }
14459 }
14460
14461 /* ttl-security hops */
14462 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
14463 if (!peer_group_active(peer)
14464 || g_peer->gtsm_hops != peer->gtsm_hops) {
14465 vty_out(vty, " neighbor %s ttl-security hops %d\n",
14466 addr, peer->gtsm_hops);
14467 }
14468 }
14469
14470 /* disable-connected-check */
14471 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
14472 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
14473
14474 /* enforce-first-as */
14475 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
14476 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
14477
14478 /* update-source */
14479 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
14480 if (peer->update_source)
14481 vty_out(vty, " neighbor %s update-source %s\n", addr,
14482 sockunion2str(peer->update_source, buf,
14483 SU_ADDRSTRLEN));
14484 else if (peer->update_if)
14485 vty_out(vty, " neighbor %s update-source %s\n", addr,
14486 peer->update_if);
14487 }
14488
14489 /* advertisement-interval */
14490 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
14491 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
14492 peer->routeadv);
14493
14494 /* timers */
14495 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
14496 vty_out(vty, " neighbor %s timers %u %u\n", addr,
14497 peer->keepalive, peer->holdtime);
14498
14499 /* timers connect */
14500 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
14501 vty_out(vty, " neighbor %s timers connect %u\n", addr,
14502 peer->connect);
14503 /* need special-case handling for changed default values due to
14504 * config profile / version (because there is no "timers bgp connect"
14505 * command, we need to save this per-peer :/)
14506 */
14507 else if (!peer_group_active(peer) && !peer->connect &&
14508 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
14509 vty_out(vty, " neighbor %s timers connect %u\n", addr,
14510 peer->bgp->default_connect_retry);
14511
14512 /* capability dynamic */
14513 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
14514 vty_out(vty, " neighbor %s capability dynamic\n", addr);
14515
14516 /* capability extended-nexthop */
14517 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
14518 if (!peer->conf_if) {
14519 if (CHECK_FLAG(peer->flags_invert,
14520 PEER_FLAG_CAPABILITY_ENHE))
14521 vty_out(vty,
14522 " no neighbor %s capability extended-nexthop\n",
14523 addr);
14524 else
14525 vty_out(vty,
14526 " neighbor %s capability extended-nexthop\n",
14527 addr);
14528 }
14529 }
14530
14531 /* dont-capability-negotiation */
14532 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
14533 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
14534
14535 /* override-capability */
14536 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
14537 vty_out(vty, " neighbor %s override-capability\n", addr);
14538
14539 /* strict-capability-match */
14540 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
14541 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
14542
14543 /* Sender side AS path loop detection. */
14544 if (peer->as_path_loop_detection)
14545 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
14546 addr);
14547
14548 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
14549 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
14550
14551 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
14552 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
14553 vty_out(vty,
14554 " neighbor %s graceful-restart-helper\n", addr);
14555 } else if (CHECK_FLAG(
14556 peer->peer_gr_new_status_flag,
14557 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
14558 vty_out(vty,
14559 " neighbor %s graceful-restart\n", addr);
14560 } else if (
14561 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
14562 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
14563 && !(CHECK_FLAG(
14564 peer->peer_gr_new_status_flag,
14565 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
14566 vty_out(vty, " neighbor %s graceful-restart-disable\n",
14567 addr);
14568 }
14569 }
14570 }
14571
14572 /* BGP peer configuration display function. */
14573 static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
14574 struct peer *peer, afi_t afi, safi_t safi)
14575 {
14576 struct peer *g_peer = NULL;
14577 char *addr;
14578 bool flag_scomm, flag_secomm, flag_slcomm;
14579
14580 /* Skip dynamic neighbors. */
14581 if (peer_dynamic_neighbor(peer))
14582 return;
14583
14584 if (peer->conf_if)
14585 addr = peer->conf_if;
14586 else
14587 addr = peer->host;
14588
14589 /************************************
14590 ****** Per AF to the neighbor ******
14591 ************************************/
14592 if (peer_group_active(peer)) {
14593 g_peer = peer->group->conf;
14594
14595 /* If the peer-group is active but peer is not, print a 'no
14596 * activate' */
14597 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
14598 vty_out(vty, " no neighbor %s activate\n", addr);
14599 }
14600
14601 /* If the peer-group is not active but peer is, print an
14602 'activate' */
14603 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
14604 vty_out(vty, " neighbor %s activate\n", addr);
14605 }
14606 } else {
14607 if (peer->afc[afi][safi]) {
14608 if ((afi == AFI_IP) && (safi == SAFI_UNICAST)) {
14609 if (CHECK_FLAG(bgp->flags,
14610 BGP_FLAG_NO_DEFAULT_IPV4)) {
14611 vty_out(vty, " neighbor %s activate\n",
14612 addr);
14613 }
14614 } else
14615 vty_out(vty, " neighbor %s activate\n", addr);
14616 } else {
14617 if ((afi == AFI_IP) && (safi == SAFI_UNICAST)) {
14618 if (!CHECK_FLAG(bgp->flags,
14619 BGP_FLAG_NO_DEFAULT_IPV4)) {
14620 vty_out(vty,
14621 " no neighbor %s activate\n",
14622 addr);
14623 }
14624 }
14625 }
14626 }
14627
14628 /* addpath TX knobs */
14629 if (peergroup_af_addpath_check(peer, afi, safi)) {
14630 switch (peer->addpath_type[afi][safi]) {
14631 case BGP_ADDPATH_ALL:
14632 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
14633 addr);
14634 break;
14635 case BGP_ADDPATH_BEST_PER_AS:
14636 vty_out(vty,
14637 " neighbor %s addpath-tx-bestpath-per-AS\n",
14638 addr);
14639 break;
14640 case BGP_ADDPATH_MAX:
14641 case BGP_ADDPATH_NONE:
14642 break;
14643 }
14644 }
14645
14646 /* ORF capability. */
14647 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
14648 || peergroup_af_flag_check(peer, afi, safi,
14649 PEER_FLAG_ORF_PREFIX_RM)) {
14650 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
14651
14652 if (peergroup_af_flag_check(peer, afi, safi,
14653 PEER_FLAG_ORF_PREFIX_SM)
14654 && peergroup_af_flag_check(peer, afi, safi,
14655 PEER_FLAG_ORF_PREFIX_RM))
14656 vty_out(vty, " both");
14657 else if (peergroup_af_flag_check(peer, afi, safi,
14658 PEER_FLAG_ORF_PREFIX_SM))
14659 vty_out(vty, " send");
14660 else
14661 vty_out(vty, " receive");
14662 vty_out(vty, "\n");
14663 }
14664
14665 /* BGP flag dampening. */
14666 if (CHECK_FLAG(bgp->af_flags[afi][safi],
14667 BGP_CONFIG_DAMPENING))
14668 bgp_config_write_damp(vty, afi, safi);
14669
14670 /* Route reflector client. */
14671 if (peergroup_af_flag_check(peer, afi, safi,
14672 PEER_FLAG_REFLECTOR_CLIENT)) {
14673 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
14674 }
14675
14676 /* next-hop-self force */
14677 if (peergroup_af_flag_check(peer, afi, safi,
14678 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
14679 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
14680 }
14681
14682 /* next-hop-self */
14683 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
14684 vty_out(vty, " neighbor %s next-hop-self\n", addr);
14685 }
14686
14687 /* remove-private-AS */
14688 if (peergroup_af_flag_check(peer, afi, safi,
14689 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
14690 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
14691 addr);
14692 }
14693
14694 else if (peergroup_af_flag_check(peer, afi, safi,
14695 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
14696 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
14697 addr);
14698 }
14699
14700 else if (peergroup_af_flag_check(peer, afi, safi,
14701 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
14702 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
14703 }
14704
14705 else if (peergroup_af_flag_check(peer, afi, safi,
14706 PEER_FLAG_REMOVE_PRIVATE_AS)) {
14707 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
14708 }
14709
14710 /* as-override */
14711 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
14712 vty_out(vty, " neighbor %s as-override\n", addr);
14713 }
14714
14715 /* send-community print. */
14716 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
14717 PEER_FLAG_SEND_COMMUNITY);
14718 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
14719 PEER_FLAG_SEND_EXT_COMMUNITY);
14720 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
14721 PEER_FLAG_SEND_LARGE_COMMUNITY);
14722
14723 if (flag_scomm && flag_secomm && flag_slcomm) {
14724 vty_out(vty, " no neighbor %s send-community all\n", addr);
14725 } else {
14726 if (flag_scomm)
14727 vty_out(vty, " no neighbor %s send-community\n", addr);
14728 if (flag_secomm)
14729 vty_out(vty,
14730 " no neighbor %s send-community extended\n",
14731 addr);
14732
14733 if (flag_slcomm)
14734 vty_out(vty, " no neighbor %s send-community large\n",
14735 addr);
14736 }
14737
14738 /* Default information */
14739 if (peergroup_af_flag_check(peer, afi, safi,
14740 PEER_FLAG_DEFAULT_ORIGINATE)) {
14741 vty_out(vty, " neighbor %s default-originate", addr);
14742
14743 if (peer->default_rmap[afi][safi].name)
14744 vty_out(vty, " route-map %s",
14745 peer->default_rmap[afi][safi].name);
14746
14747 vty_out(vty, "\n");
14748 }
14749
14750 /* Soft reconfiguration inbound. */
14751 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
14752 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
14753 addr);
14754 }
14755
14756 /* maximum-prefix. */
14757 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
14758 vty_out(vty, " neighbor %s maximum-prefix %" PRIu32, addr,
14759 peer->pmax[afi][safi]);
14760
14761 if (peer->pmax_threshold[afi][safi]
14762 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
14763 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
14764 if (peer_af_flag_check(peer, afi, safi,
14765 PEER_FLAG_MAX_PREFIX_WARNING))
14766 vty_out(vty, " warning-only");
14767 if (peer->pmax_restart[afi][safi])
14768 vty_out(vty, " restart %u",
14769 peer->pmax_restart[afi][safi]);
14770
14771 vty_out(vty, "\n");
14772 }
14773
14774 /* maximum-prefix-out */
14775 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
14776 vty_out(vty, " neighbor %s maximum-prefix-out %" PRIu32 "\n",
14777 addr, peer->pmax_out[afi][safi]);
14778
14779 /* Route server client. */
14780 if (peergroup_af_flag_check(peer, afi, safi,
14781 PEER_FLAG_RSERVER_CLIENT)) {
14782 vty_out(vty, " neighbor %s route-server-client\n", addr);
14783 }
14784
14785 /* Nexthop-local unchanged. */
14786 if (peergroup_af_flag_check(peer, afi, safi,
14787 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
14788 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
14789 }
14790
14791 /* allowas-in <1-10> */
14792 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
14793 if (peer_af_flag_check(peer, afi, safi,
14794 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
14795 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
14796 } else if (peer->allowas_in[afi][safi] == 3) {
14797 vty_out(vty, " neighbor %s allowas-in\n", addr);
14798 } else {
14799 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
14800 peer->allowas_in[afi][safi]);
14801 }
14802 }
14803
14804 /* weight */
14805 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
14806 vty_out(vty, " neighbor %s weight %lu\n", addr,
14807 peer->weight[afi][safi]);
14808
14809 /* Filter. */
14810 bgp_config_write_filter(vty, peer, afi, safi);
14811
14812 /* atribute-unchanged. */
14813 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
14814 || (safi != SAFI_EVPN
14815 && peer_af_flag_check(peer, afi, safi,
14816 PEER_FLAG_NEXTHOP_UNCHANGED))
14817 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
14818
14819 if (!peer_group_active(peer)
14820 || peergroup_af_flag_check(peer, afi, safi,
14821 PEER_FLAG_AS_PATH_UNCHANGED)
14822 || peergroup_af_flag_check(peer, afi, safi,
14823 PEER_FLAG_NEXTHOP_UNCHANGED)
14824 || peergroup_af_flag_check(peer, afi, safi,
14825 PEER_FLAG_MED_UNCHANGED)) {
14826
14827 vty_out(vty,
14828 " neighbor %s attribute-unchanged%s%s%s\n",
14829 addr,
14830 peer_af_flag_check(peer, afi, safi,
14831 PEER_FLAG_AS_PATH_UNCHANGED)
14832 ? " as-path"
14833 : "",
14834 peer_af_flag_check(peer, afi, safi,
14835 PEER_FLAG_NEXTHOP_UNCHANGED)
14836 ? " next-hop"
14837 : "",
14838 peer_af_flag_check(peer, afi, safi,
14839 PEER_FLAG_MED_UNCHANGED)
14840 ? " med"
14841 : "");
14842 }
14843 }
14844 }
14845
14846 /* Address family based peer configuration display. */
14847 static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
14848 safi_t safi)
14849 {
14850 struct peer *peer;
14851 struct peer_group *group;
14852 struct listnode *node, *nnode;
14853
14854
14855 vty_frame(vty, " !\n address-family ");
14856 if (afi == AFI_IP) {
14857 if (safi == SAFI_UNICAST)
14858 vty_frame(vty, "ipv4 unicast");
14859 else if (safi == SAFI_LABELED_UNICAST)
14860 vty_frame(vty, "ipv4 labeled-unicast");
14861 else if (safi == SAFI_MULTICAST)
14862 vty_frame(vty, "ipv4 multicast");
14863 else if (safi == SAFI_MPLS_VPN)
14864 vty_frame(vty, "ipv4 vpn");
14865 else if (safi == SAFI_ENCAP)
14866 vty_frame(vty, "ipv4 encap");
14867 else if (safi == SAFI_FLOWSPEC)
14868 vty_frame(vty, "ipv4 flowspec");
14869 } else if (afi == AFI_IP6) {
14870 if (safi == SAFI_UNICAST)
14871 vty_frame(vty, "ipv6 unicast");
14872 else if (safi == SAFI_LABELED_UNICAST)
14873 vty_frame(vty, "ipv6 labeled-unicast");
14874 else if (safi == SAFI_MULTICAST)
14875 vty_frame(vty, "ipv6 multicast");
14876 else if (safi == SAFI_MPLS_VPN)
14877 vty_frame(vty, "ipv6 vpn");
14878 else if (safi == SAFI_ENCAP)
14879 vty_frame(vty, "ipv6 encap");
14880 else if (safi == SAFI_FLOWSPEC)
14881 vty_frame(vty, "ipv6 flowspec");
14882 } else if (afi == AFI_L2VPN) {
14883 if (safi == SAFI_EVPN)
14884 vty_frame(vty, "l2vpn evpn");
14885 }
14886 vty_frame(vty, "\n");
14887
14888 bgp_config_write_distance(vty, bgp, afi, safi);
14889
14890 bgp_config_write_network(vty, bgp, afi, safi);
14891
14892 bgp_config_write_redistribute(vty, bgp, afi, safi);
14893
14894 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
14895 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
14896
14897 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14898 /* Skip dynamic neighbors. */
14899 if (peer_dynamic_neighbor(peer))
14900 continue;
14901
14902 /* Do not display doppelganger peers */
14903 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14904 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
14905 }
14906
14907 bgp_config_write_maxpaths(vty, bgp, afi, safi);
14908 bgp_config_write_table_map(vty, bgp, afi, safi);
14909
14910 if (safi == SAFI_EVPN)
14911 bgp_config_write_evpn_info(vty, bgp, afi, safi);
14912
14913 if (safi == SAFI_FLOWSPEC)
14914 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
14915
14916 if (safi == SAFI_UNICAST) {
14917 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
14918 if (CHECK_FLAG(bgp->af_flags[afi][safi],
14919 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
14920
14921 vty_out(vty, " export vpn\n");
14922 }
14923 if (CHECK_FLAG(bgp->af_flags[afi][safi],
14924 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
14925
14926 vty_out(vty, " import vpn\n");
14927 }
14928 if (CHECK_FLAG(bgp->af_flags[afi][safi],
14929 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
14930 char *name;
14931
14932 for (ALL_LIST_ELEMENTS_RO(
14933 bgp->vpn_policy[afi].import_vrf, node,
14934 name))
14935 vty_out(vty, " import vrf %s\n", name);
14936 }
14937 }
14938
14939 vty_endframe(vty, " exit-address-family\n");
14940 }
14941
14942 int bgp_config_write(struct vty *vty)
14943 {
14944 struct bgp *bgp;
14945 struct peer_group *group;
14946 struct peer *peer;
14947 struct listnode *node, *nnode;
14948 struct listnode *mnode, *mnnode;
14949
14950 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
14951 vty_out(vty, "bgp route-map delay-timer %u\n",
14952 bm->rmap_update_timer);
14953
14954 /* BGP configuration. */
14955 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
14956
14957 /* skip all auto created vrf as they dont have user config */
14958 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
14959 continue;
14960
14961 /* Router bgp ASN */
14962 vty_out(vty, "router bgp %u", bgp->as);
14963
14964 if (bgp->name)
14965 vty_out(vty, " %s %s",
14966 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
14967 ? "view" : "vrf", bgp->name);
14968 vty_out(vty, "\n");
14969
14970 /* BGP fast-external-failover. */
14971 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
14972 vty_out(vty, " no bgp fast-external-failover\n");
14973
14974 /* BGP router ID. */
14975 if (bgp->router_id_static.s_addr != 0)
14976 vty_out(vty, " bgp router-id %s\n",
14977 inet_ntoa(bgp->router_id_static));
14978
14979 /* BGP log-neighbor-changes. */
14980 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
14981 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
14982 vty_out(vty, " %sbgp log-neighbor-changes\n",
14983 CHECK_FLAG(bgp->flags,
14984 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
14985 ? ""
14986 : "no ");
14987
14988 /* BGP configuration. */
14989 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
14990 vty_out(vty, " bgp always-compare-med\n");
14991
14992 /* RFC8212 default eBGP policy. */
14993 if (bgp->ebgp_requires_policy
14994 == DEFAULT_EBGP_POLICY_ENABLED)
14995 vty_out(vty, " bgp ebgp-requires-policy\n");
14996
14997 /* draft-ietf-idr-deprecate-as-set-confed-set */
14998 if (bgp->reject_as_sets == BGP_REJECT_AS_SETS_ENABLED)
14999 vty_out(vty, " bgp reject-as-sets\n");
15000
15001 /* BGP default ipv4-unicast. */
15002 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4))
15003 vty_out(vty, " no bgp default ipv4-unicast\n");
15004
15005 /* BGP default local-preference. */
15006 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
15007 vty_out(vty, " bgp default local-preference %u\n",
15008 bgp->default_local_pref);
15009
15010 /* BGP default show-hostname */
15011 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
15012 != SAVE_BGP_SHOW_HOSTNAME)
15013 vty_out(vty, " %sbgp default show-hostname\n",
15014 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
15015 ? ""
15016 : "no ");
15017
15018 /* BGP default subgroup-pkt-queue-max. */
15019 if (bgp->default_subgroup_pkt_queue_max
15020 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
15021 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
15022 bgp->default_subgroup_pkt_queue_max);
15023
15024 /* BGP client-to-client reflection. */
15025 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
15026 vty_out(vty, " no bgp client-to-client reflection\n");
15027
15028 /* BGP cluster ID. */
15029 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
15030 vty_out(vty, " bgp cluster-id %s\n",
15031 inet_ntoa(bgp->cluster_id));
15032
15033 /* Disable ebgp connected nexthop check */
15034 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
15035 vty_out(vty,
15036 " bgp disable-ebgp-connected-route-check\n");
15037
15038 /* Confederation identifier*/
15039 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
15040 vty_out(vty, " bgp confederation identifier %u\n",
15041 bgp->confed_id);
15042
15043 /* Confederation peer */
15044 if (bgp->confed_peers_cnt > 0) {
15045 int i;
15046
15047 vty_out(vty, " bgp confederation peers");
15048
15049 for (i = 0; i < bgp->confed_peers_cnt; i++)
15050 vty_out(vty, " %u", bgp->confed_peers[i]);
15051
15052 vty_out(vty, "\n");
15053 }
15054
15055 /* BGP deterministic-med. */
15056 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
15057 != SAVE_BGP_DETERMINISTIC_MED)
15058 vty_out(vty, " %sbgp deterministic-med\n",
15059 CHECK_FLAG(bgp->flags,
15060 BGP_FLAG_DETERMINISTIC_MED)
15061 ? ""
15062 : "no ");
15063
15064 /* BGP update-delay. */
15065 bgp_config_write_update_delay(vty, bgp);
15066
15067 if (bgp->v_maxmed_onstartup
15068 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
15069 vty_out(vty, " bgp max-med on-startup %u",
15070 bgp->v_maxmed_onstartup);
15071 if (bgp->maxmed_onstartup_value
15072 != BGP_MAXMED_VALUE_DEFAULT)
15073 vty_out(vty, " %u",
15074 bgp->maxmed_onstartup_value);
15075 vty_out(vty, "\n");
15076 }
15077 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
15078 vty_out(vty, " bgp max-med administrative");
15079 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
15080 vty_out(vty, " %u", bgp->maxmed_admin_value);
15081 vty_out(vty, "\n");
15082 }
15083
15084 /* write quanta */
15085 bgp_config_write_wpkt_quanta(vty, bgp);
15086 /* read quanta */
15087 bgp_config_write_rpkt_quanta(vty, bgp);
15088
15089 /* coalesce time */
15090 bgp_config_write_coalesce_time(vty, bgp);
15091
15092 /* BGP graceful-restart. */
15093 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
15094 vty_out(vty,
15095 " bgp graceful-restart stalepath-time %u\n",
15096 bgp->stalepath_time);
15097
15098 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
15099 vty_out(vty, " bgp graceful-restart restart-time %u\n",
15100 bgp->restart_time);
15101
15102 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
15103 vty_out(vty,
15104 " bgp graceful-restart select-defer-time %u\n",
15105 bgp->select_defer_time);
15106
15107 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
15108 vty_out(vty, " bgp graceful-restart\n");
15109
15110 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
15111 vty_out(vty, " bgp graceful-restart-disable\n");
15112
15113 /* BGP graceful-shutdown */
15114 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
15115 vty_out(vty, " bgp graceful-shutdown\n");
15116
15117 /* BGP graceful-restart Preserve State F bit. */
15118 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
15119 vty_out(vty,
15120 " bgp graceful-restart preserve-fw-state\n");
15121
15122 /* Stale timer for RIB */
15123 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
15124 vty_out(vty,
15125 " bgp graceful-restart rib-stale-time %u\n",
15126 bgp->rib_stale_time);
15127
15128 /* BGP bestpath method. */
15129 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
15130 vty_out(vty, " bgp bestpath as-path ignore\n");
15131 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
15132 vty_out(vty, " bgp bestpath as-path confed\n");
15133
15134 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
15135 if (CHECK_FLAG(bgp->flags,
15136 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
15137 vty_out(vty,
15138 " bgp bestpath as-path multipath-relax as-set\n");
15139 } else {
15140 vty_out(vty,
15141 " bgp bestpath as-path multipath-relax\n");
15142 }
15143 }
15144
15145 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
15146 vty_out(vty,
15147 " bgp route-reflector allow-outbound-policy\n");
15148 }
15149 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
15150 vty_out(vty, " bgp bestpath compare-routerid\n");
15151 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
15152 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
15153 vty_out(vty, " bgp bestpath med");
15154 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
15155 vty_out(vty, " confed");
15156 if (CHECK_FLAG(bgp->flags,
15157 BGP_FLAG_MED_MISSING_AS_WORST))
15158 vty_out(vty, " missing-as-worst");
15159 vty_out(vty, "\n");
15160 }
15161
15162 /* BGP network import check. */
15163 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
15164 != SAVE_BGP_IMPORT_CHECK)
15165 vty_out(vty, " %sbgp network import-check\n",
15166 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
15167 ? ""
15168 : "no ");
15169
15170 /* BGP timers configuration. */
15171 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
15172 && bgp->default_holdtime != SAVE_BGP_HOLDTIME)
15173 vty_out(vty, " timers bgp %u %u\n",
15174 bgp->default_keepalive, bgp->default_holdtime);
15175
15176 /* peer-group */
15177 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
15178 bgp_config_write_peer_global(vty, bgp, group->conf);
15179 }
15180
15181 /* Normal neighbor configuration. */
15182 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
15183 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
15184 bgp_config_write_peer_global(vty, bgp, peer);
15185 }
15186
15187 /* listen range and limit for dynamic BGP neighbors */
15188 bgp_config_write_listen(vty, bgp);
15189
15190 /*
15191 * BGP default autoshutdown neighbors
15192 *
15193 * This must be placed after any peer and peer-group
15194 * configuration, to avoid setting all peers to shutdown after
15195 * a daemon restart, which is undesired behavior. (see #2286)
15196 */
15197 if (bgp->autoshutdown)
15198 vty_out(vty, " bgp default shutdown\n");
15199
15200 /* IPv4 unicast configuration. */
15201 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
15202
15203 /* IPv4 multicast configuration. */
15204 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
15205
15206 /* IPv4 labeled-unicast configuration. */
15207 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
15208
15209 /* IPv4 VPN configuration. */
15210 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
15211
15212 /* ENCAPv4 configuration. */
15213 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
15214
15215 /* FLOWSPEC v4 configuration. */
15216 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
15217
15218 /* IPv6 unicast configuration. */
15219 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
15220
15221 /* IPv6 multicast configuration. */
15222 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
15223
15224 /* IPv6 labeled-unicast configuration. */
15225 bgp_config_write_family(vty, bgp, AFI_IP6,
15226 SAFI_LABELED_UNICAST);
15227
15228 /* IPv6 VPN configuration. */
15229 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
15230
15231 /* ENCAPv6 configuration. */
15232 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
15233
15234 /* FLOWSPEC v6 configuration. */
15235 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
15236
15237 /* EVPN configuration. */
15238 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
15239
15240 hook_call(bgp_inst_config_write, bgp, vty);
15241
15242 #if ENABLE_BGP_VNC
15243 bgp_rfapi_cfg_write(vty, bgp);
15244 #endif
15245
15246 vty_out(vty, "!\n");
15247 }
15248 return 0;
15249 }
15250
15251
15252 /* BGP node structure. */
15253 static struct cmd_node bgp_node = {
15254 BGP_NODE, "%s(config-router)# ", 1,
15255 };
15256
15257 static struct cmd_node bgp_ipv4_unicast_node = {
15258 BGP_IPV4_NODE, "%s(config-router-af)# ", 1,
15259 };
15260
15261 static struct cmd_node bgp_ipv4_multicast_node = {
15262 BGP_IPV4M_NODE, "%s(config-router-af)# ", 1,
15263 };
15264
15265 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
15266 BGP_IPV4L_NODE, "%s(config-router-af)# ", 1,
15267 };
15268
15269 static struct cmd_node bgp_ipv6_unicast_node = {
15270 BGP_IPV6_NODE, "%s(config-router-af)# ", 1,
15271 };
15272
15273 static struct cmd_node bgp_ipv6_multicast_node = {
15274 BGP_IPV6M_NODE, "%s(config-router-af)# ", 1,
15275 };
15276
15277 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
15278 BGP_IPV6L_NODE, "%s(config-router-af)# ", 1,
15279 };
15280
15281 static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
15282 "%s(config-router-af)# ", 1};
15283
15284 static struct cmd_node bgp_vpnv6_node = {BGP_VPNV6_NODE,
15285 "%s(config-router-af-vpnv6)# ", 1};
15286
15287 static struct cmd_node bgp_evpn_node = {BGP_EVPN_NODE,
15288 "%s(config-router-evpn)# ", 1};
15289
15290 static struct cmd_node bgp_evpn_vni_node = {BGP_EVPN_VNI_NODE,
15291 "%s(config-router-af-vni)# ", 1};
15292
15293 static struct cmd_node bgp_flowspecv4_node = {BGP_FLOWSPECV4_NODE,
15294 "%s(config-router-af)# ", 1};
15295
15296 static struct cmd_node bgp_flowspecv6_node = {BGP_FLOWSPECV6_NODE,
15297 "%s(config-router-af-vpnv6)# ", 1};
15298
15299 static void community_list_vty(void);
15300
15301 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
15302 {
15303 struct bgp *bgp;
15304 struct peer *peer;
15305 struct listnode *lnbgp, *lnpeer;
15306
15307 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
15308 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
15309 /* only provide suggestions on the appropriate input
15310 * token type,
15311 * they'll otherwise show up multiple times */
15312 enum cmd_token_type match_type;
15313 char *name = peer->host;
15314
15315 if (peer->conf_if) {
15316 match_type = VARIABLE_TKN;
15317 name = peer->conf_if;
15318 } else if (strchr(peer->host, ':'))
15319 match_type = IPV6_TKN;
15320 else
15321 match_type = IPV4_TKN;
15322
15323 if (token->type != match_type)
15324 continue;
15325
15326 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
15327 }
15328 }
15329 }
15330
15331 static const struct cmd_variable_handler bgp_var_neighbor[] = {
15332 {.varname = "neighbor", .completions = bgp_ac_neighbor},
15333 {.varname = "neighbors", .completions = bgp_ac_neighbor},
15334 {.varname = "peer", .completions = bgp_ac_neighbor},
15335 {.completions = NULL}};
15336
15337 static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
15338 {
15339 struct bgp *bgp;
15340 struct peer_group *group;
15341 struct listnode *lnbgp, *lnpeer;
15342
15343 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
15344 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
15345 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
15346 group->name));
15347 }
15348 }
15349
15350 static const struct cmd_variable_handler bgp_var_peergroup[] = {
15351 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
15352 {.completions = NULL} };
15353
15354 void bgp_vty_init(void)
15355 {
15356 cmd_variable_handler_register(bgp_var_neighbor);
15357 cmd_variable_handler_register(bgp_var_peergroup);
15358
15359 /* Install bgp top node. */
15360 install_node(&bgp_node, bgp_config_write);
15361 install_node(&bgp_ipv4_unicast_node, NULL);
15362 install_node(&bgp_ipv4_multicast_node, NULL);
15363 install_node(&bgp_ipv4_labeled_unicast_node, NULL);
15364 install_node(&bgp_ipv6_unicast_node, NULL);
15365 install_node(&bgp_ipv6_multicast_node, NULL);
15366 install_node(&bgp_ipv6_labeled_unicast_node, NULL);
15367 install_node(&bgp_vpnv4_node, NULL);
15368 install_node(&bgp_vpnv6_node, NULL);
15369 install_node(&bgp_evpn_node, NULL);
15370 install_node(&bgp_evpn_vni_node, NULL);
15371 install_node(&bgp_flowspecv4_node, NULL);
15372 install_node(&bgp_flowspecv6_node, NULL);
15373
15374 /* Install default VTY commands to new nodes. */
15375 install_default(BGP_NODE);
15376 install_default(BGP_IPV4_NODE);
15377 install_default(BGP_IPV4M_NODE);
15378 install_default(BGP_IPV4L_NODE);
15379 install_default(BGP_IPV6_NODE);
15380 install_default(BGP_IPV6M_NODE);
15381 install_default(BGP_IPV6L_NODE);
15382 install_default(BGP_VPNV4_NODE);
15383 install_default(BGP_VPNV6_NODE);
15384 install_default(BGP_FLOWSPECV4_NODE);
15385 install_default(BGP_FLOWSPECV6_NODE);
15386 install_default(BGP_EVPN_NODE);
15387 install_default(BGP_EVPN_VNI_NODE);
15388
15389 /* "bgp local-mac" hidden commands. */
15390 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
15391 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
15392
15393 /* bgp route-map delay-timer commands. */
15394 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
15395 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
15396
15397 /* Dummy commands (Currently not supported) */
15398 install_element(BGP_NODE, &no_synchronization_cmd);
15399 install_element(BGP_NODE, &no_auto_summary_cmd);
15400
15401 /* "router bgp" commands. */
15402 install_element(CONFIG_NODE, &router_bgp_cmd);
15403
15404 /* "no router bgp" commands. */
15405 install_element(CONFIG_NODE, &no_router_bgp_cmd);
15406
15407 /* "bgp router-id" commands. */
15408 install_element(BGP_NODE, &bgp_router_id_cmd);
15409 install_element(BGP_NODE, &no_bgp_router_id_cmd);
15410
15411 /* "bgp cluster-id" commands. */
15412 install_element(BGP_NODE, &bgp_cluster_id_cmd);
15413 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
15414
15415 /* "bgp confederation" commands. */
15416 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
15417 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
15418
15419 /* "bgp confederation peers" commands. */
15420 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
15421 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
15422
15423 /* bgp max-med command */
15424 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
15425 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
15426 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
15427 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
15428 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
15429
15430 /* bgp disable-ebgp-connected-nh-check */
15431 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
15432 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
15433
15434 /* bgp update-delay command */
15435 install_element(BGP_NODE, &bgp_update_delay_cmd);
15436 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
15437 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
15438
15439 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
15440 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
15441
15442 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
15443 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
15444
15445 /* "maximum-paths" commands. */
15446 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
15447 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
15448 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
15449 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
15450 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
15451 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
15452 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
15453 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
15454 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
15455 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
15456 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
15457 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
15458 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
15459 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
15460 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
15461
15462 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
15463 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
15464 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
15465 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
15466 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
15467
15468 /* "timers bgp" commands. */
15469 install_element(BGP_NODE, &bgp_timers_cmd);
15470 install_element(BGP_NODE, &no_bgp_timers_cmd);
15471
15472 /* route-map delay-timer commands - per instance for backwards compat.
15473 */
15474 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
15475 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
15476
15477 /* "bgp client-to-client reflection" commands */
15478 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
15479 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
15480
15481 /* "bgp always-compare-med" commands */
15482 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
15483 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
15484
15485 /* bgp ebgp-requires-policy */
15486 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
15487 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
15488
15489 /* bgp reject-as-sets */
15490 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
15491 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
15492
15493 /* "bgp deterministic-med" commands */
15494 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
15495 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
15496
15497 /* "bgp graceful-restart" command */
15498 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
15499 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
15500
15501 /* "bgp graceful-restart-disable" command */
15502 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
15503 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
15504
15505 /* "neighbor a:b:c:d graceful-restart" command */
15506 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
15507 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
15508
15509 /* "neighbor a:b:c:d graceful-restart-disable" command */
15510 install_element(BGP_NODE,
15511 &bgp_neighbor_graceful_restart_disable_set_cmd);
15512 install_element(BGP_NODE,
15513 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
15514
15515 /* "neighbor a:b:c:d graceful-restart-helper" command */
15516 install_element(BGP_NODE,
15517 &bgp_neighbor_graceful_restart_helper_set_cmd);
15518 install_element(BGP_NODE,
15519 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
15520
15521 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
15522 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
15523 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
15524 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
15525 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
15526 install_element(BGP_NODE,
15527 &no_bgp_graceful_restart_select_defer_time_cmd);
15528 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
15529 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
15530
15531 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
15532 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
15533 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
15534 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
15535
15536 /* "bgp graceful-shutdown" commands */
15537 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
15538 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
15539
15540 /* "bgp fast-external-failover" commands */
15541 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
15542 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
15543
15544 /* "bgp bestpath compare-routerid" commands */
15545 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
15546 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
15547
15548 /* "bgp bestpath as-path ignore" commands */
15549 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
15550 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
15551
15552 /* "bgp bestpath as-path confed" commands */
15553 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
15554 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
15555
15556 /* "bgp bestpath as-path multipath-relax" commands */
15557 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
15558 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
15559
15560 /* "bgp log-neighbor-changes" commands */
15561 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
15562 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
15563
15564 /* "bgp bestpath med" commands */
15565 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
15566 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
15567
15568 /* "no bgp default ipv4-unicast" commands. */
15569 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
15570 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
15571
15572 /* "bgp network import-check" commands. */
15573 install_element(BGP_NODE, &bgp_network_import_check_cmd);
15574 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
15575 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
15576
15577 /* "bgp default local-preference" commands. */
15578 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
15579 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
15580
15581 /* bgp default show-hostname */
15582 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
15583 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
15584
15585 /* "bgp default subgroup-pkt-queue-max" commands. */
15586 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
15587 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
15588
15589 /* bgp ibgp-allow-policy-mods command */
15590 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
15591 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
15592
15593 /* "bgp listen limit" commands. */
15594 install_element(BGP_NODE, &bgp_listen_limit_cmd);
15595 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
15596
15597 /* "bgp listen range" commands. */
15598 install_element(BGP_NODE, &bgp_listen_range_cmd);
15599 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
15600
15601 /* "bgp default shutdown" command */
15602 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
15603
15604 /* "neighbor remote-as" commands. */
15605 install_element(BGP_NODE, &neighbor_remote_as_cmd);
15606 install_element(BGP_NODE, &neighbor_interface_config_cmd);
15607 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
15608 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
15609 install_element(BGP_NODE,
15610 &neighbor_interface_v6only_config_remote_as_cmd);
15611 install_element(BGP_NODE, &no_neighbor_cmd);
15612 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
15613
15614 /* "neighbor peer-group" commands. */
15615 install_element(BGP_NODE, &neighbor_peer_group_cmd);
15616 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
15617 install_element(BGP_NODE,
15618 &no_neighbor_interface_peer_group_remote_as_cmd);
15619
15620 /* "neighbor local-as" commands. */
15621 install_element(BGP_NODE, &neighbor_local_as_cmd);
15622 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
15623 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
15624 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
15625
15626 /* "neighbor solo" commands. */
15627 install_element(BGP_NODE, &neighbor_solo_cmd);
15628 install_element(BGP_NODE, &no_neighbor_solo_cmd);
15629
15630 /* "neighbor password" commands. */
15631 install_element(BGP_NODE, &neighbor_password_cmd);
15632 install_element(BGP_NODE, &no_neighbor_password_cmd);
15633
15634 /* "neighbor activate" commands. */
15635 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
15636 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
15637 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
15638 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
15639 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
15640 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
15641 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
15642 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
15643 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
15644 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
15645 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
15646 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
15647
15648 /* "no neighbor activate" commands. */
15649 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
15650 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
15651 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
15652 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
15653 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
15654 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
15655 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
15656 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
15657 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
15658 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
15659 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
15660 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
15661
15662 /* "neighbor peer-group" set commands. */
15663 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
15664 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
15665 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
15666 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
15667 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
15668 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
15669 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
15670 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
15671 install_element(BGP_FLOWSPECV4_NODE,
15672 &neighbor_set_peer_group_hidden_cmd);
15673 install_element(BGP_FLOWSPECV6_NODE,
15674 &neighbor_set_peer_group_hidden_cmd);
15675
15676 /* "no neighbor peer-group unset" commands. */
15677 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
15678 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
15679 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
15680 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
15681 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
15682 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
15683 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
15684 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
15685 install_element(BGP_FLOWSPECV4_NODE,
15686 &no_neighbor_set_peer_group_hidden_cmd);
15687 install_element(BGP_FLOWSPECV6_NODE,
15688 &no_neighbor_set_peer_group_hidden_cmd);
15689
15690 /* "neighbor softreconfiguration inbound" commands.*/
15691 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
15692 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
15693 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
15694 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
15695 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
15696 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
15697 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
15698 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
15699 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
15700 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
15701 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
15702 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
15703 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
15704 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
15705 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
15706 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
15707 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
15708 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
15709 install_element(BGP_FLOWSPECV4_NODE,
15710 &neighbor_soft_reconfiguration_cmd);
15711 install_element(BGP_FLOWSPECV4_NODE,
15712 &no_neighbor_soft_reconfiguration_cmd);
15713 install_element(BGP_FLOWSPECV6_NODE,
15714 &neighbor_soft_reconfiguration_cmd);
15715 install_element(BGP_FLOWSPECV6_NODE,
15716 &no_neighbor_soft_reconfiguration_cmd);
15717 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
15718 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
15719
15720 /* "neighbor attribute-unchanged" commands. */
15721 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
15722 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
15723 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
15724 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
15725 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
15726 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
15727 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
15728 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
15729 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
15730 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
15731 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
15732 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
15733 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
15734 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
15735 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
15736 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
15737 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
15738 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
15739
15740 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
15741 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
15742
15743 /* "nexthop-local unchanged" commands */
15744 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
15745 install_element(BGP_IPV6_NODE,
15746 &no_neighbor_nexthop_local_unchanged_cmd);
15747
15748 /* "neighbor next-hop-self" commands. */
15749 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
15750 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
15751 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
15752 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
15753 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
15754 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
15755 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
15756 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
15757 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
15758 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
15759 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
15760 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
15761 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
15762 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
15763 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
15764 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
15765 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
15766 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
15767 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
15768 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
15769
15770 /* "neighbor next-hop-self force" commands. */
15771 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
15772 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
15773 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
15774 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
15775 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
15776 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
15777 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
15778 install_element(BGP_IPV4_NODE,
15779 &no_neighbor_nexthop_self_all_hidden_cmd);
15780 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
15781 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
15782 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
15783 install_element(BGP_IPV4M_NODE,
15784 &no_neighbor_nexthop_self_all_hidden_cmd);
15785 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
15786 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
15787 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
15788 install_element(BGP_IPV4L_NODE,
15789 &no_neighbor_nexthop_self_all_hidden_cmd);
15790 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
15791 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
15792 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
15793 install_element(BGP_IPV6_NODE,
15794 &no_neighbor_nexthop_self_all_hidden_cmd);
15795 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
15796 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
15797 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
15798 install_element(BGP_IPV6M_NODE,
15799 &no_neighbor_nexthop_self_all_hidden_cmd);
15800 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
15801 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
15802 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
15803 install_element(BGP_IPV6L_NODE,
15804 &no_neighbor_nexthop_self_all_hidden_cmd);
15805 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
15806 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
15807 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
15808 install_element(BGP_VPNV4_NODE,
15809 &no_neighbor_nexthop_self_all_hidden_cmd);
15810 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
15811 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
15812 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
15813 install_element(BGP_VPNV6_NODE,
15814 &no_neighbor_nexthop_self_all_hidden_cmd);
15815
15816 /* "neighbor as-override" commands. */
15817 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
15818 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
15819 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
15820 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
15821 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
15822 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
15823 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
15824 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
15825 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
15826 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
15827 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
15828 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
15829 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
15830 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
15831 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
15832 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
15833 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
15834 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
15835
15836 /* "neighbor remove-private-AS" commands. */
15837 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
15838 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
15839 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
15840 install_element(BGP_NODE,
15841 &no_neighbor_remove_private_as_all_hidden_cmd);
15842 install_element(BGP_NODE,
15843 &neighbor_remove_private_as_replace_as_hidden_cmd);
15844 install_element(BGP_NODE,
15845 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
15846 install_element(BGP_NODE,
15847 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
15848 install_element(
15849 BGP_NODE,
15850 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
15851 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
15852 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
15853 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
15854 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
15855 install_element(BGP_IPV4_NODE,
15856 &neighbor_remove_private_as_replace_as_cmd);
15857 install_element(BGP_IPV4_NODE,
15858 &no_neighbor_remove_private_as_replace_as_cmd);
15859 install_element(BGP_IPV4_NODE,
15860 &neighbor_remove_private_as_all_replace_as_cmd);
15861 install_element(BGP_IPV4_NODE,
15862 &no_neighbor_remove_private_as_all_replace_as_cmd);
15863 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
15864 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
15865 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
15866 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
15867 install_element(BGP_IPV4M_NODE,
15868 &neighbor_remove_private_as_replace_as_cmd);
15869 install_element(BGP_IPV4M_NODE,
15870 &no_neighbor_remove_private_as_replace_as_cmd);
15871 install_element(BGP_IPV4M_NODE,
15872 &neighbor_remove_private_as_all_replace_as_cmd);
15873 install_element(BGP_IPV4M_NODE,
15874 &no_neighbor_remove_private_as_all_replace_as_cmd);
15875 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
15876 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
15877 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
15878 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
15879 install_element(BGP_IPV4L_NODE,
15880 &neighbor_remove_private_as_replace_as_cmd);
15881 install_element(BGP_IPV4L_NODE,
15882 &no_neighbor_remove_private_as_replace_as_cmd);
15883 install_element(BGP_IPV4L_NODE,
15884 &neighbor_remove_private_as_all_replace_as_cmd);
15885 install_element(BGP_IPV4L_NODE,
15886 &no_neighbor_remove_private_as_all_replace_as_cmd);
15887 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
15888 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
15889 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
15890 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
15891 install_element(BGP_IPV6_NODE,
15892 &neighbor_remove_private_as_replace_as_cmd);
15893 install_element(BGP_IPV6_NODE,
15894 &no_neighbor_remove_private_as_replace_as_cmd);
15895 install_element(BGP_IPV6_NODE,
15896 &neighbor_remove_private_as_all_replace_as_cmd);
15897 install_element(BGP_IPV6_NODE,
15898 &no_neighbor_remove_private_as_all_replace_as_cmd);
15899 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
15900 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
15901 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
15902 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
15903 install_element(BGP_IPV6M_NODE,
15904 &neighbor_remove_private_as_replace_as_cmd);
15905 install_element(BGP_IPV6M_NODE,
15906 &no_neighbor_remove_private_as_replace_as_cmd);
15907 install_element(BGP_IPV6M_NODE,
15908 &neighbor_remove_private_as_all_replace_as_cmd);
15909 install_element(BGP_IPV6M_NODE,
15910 &no_neighbor_remove_private_as_all_replace_as_cmd);
15911 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
15912 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
15913 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
15914 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
15915 install_element(BGP_IPV6L_NODE,
15916 &neighbor_remove_private_as_replace_as_cmd);
15917 install_element(BGP_IPV6L_NODE,
15918 &no_neighbor_remove_private_as_replace_as_cmd);
15919 install_element(BGP_IPV6L_NODE,
15920 &neighbor_remove_private_as_all_replace_as_cmd);
15921 install_element(BGP_IPV6L_NODE,
15922 &no_neighbor_remove_private_as_all_replace_as_cmd);
15923 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
15924 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
15925 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
15926 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
15927 install_element(BGP_VPNV4_NODE,
15928 &neighbor_remove_private_as_replace_as_cmd);
15929 install_element(BGP_VPNV4_NODE,
15930 &no_neighbor_remove_private_as_replace_as_cmd);
15931 install_element(BGP_VPNV4_NODE,
15932 &neighbor_remove_private_as_all_replace_as_cmd);
15933 install_element(BGP_VPNV4_NODE,
15934 &no_neighbor_remove_private_as_all_replace_as_cmd);
15935 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
15936 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
15937 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
15938 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
15939 install_element(BGP_VPNV6_NODE,
15940 &neighbor_remove_private_as_replace_as_cmd);
15941 install_element(BGP_VPNV6_NODE,
15942 &no_neighbor_remove_private_as_replace_as_cmd);
15943 install_element(BGP_VPNV6_NODE,
15944 &neighbor_remove_private_as_all_replace_as_cmd);
15945 install_element(BGP_VPNV6_NODE,
15946 &no_neighbor_remove_private_as_all_replace_as_cmd);
15947
15948 /* "neighbor send-community" commands.*/
15949 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
15950 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
15951 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
15952 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
15953 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
15954 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
15955 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
15956 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
15957 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
15958 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
15959 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
15960 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
15961 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
15962 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
15963 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
15964 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
15965 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
15966 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
15967 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
15968 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
15969 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
15970 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
15971 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
15972 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
15973 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
15974 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
15975 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
15976 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
15977 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
15978 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
15979 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
15980 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
15981 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
15982 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
15983 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
15984 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
15985
15986 /* "neighbor route-reflector" commands.*/
15987 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
15988 install_element(BGP_NODE,
15989 &no_neighbor_route_reflector_client_hidden_cmd);
15990 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
15991 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
15992 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
15993 install_element(BGP_IPV4M_NODE,
15994 &no_neighbor_route_reflector_client_cmd);
15995 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
15996 install_element(BGP_IPV4L_NODE,
15997 &no_neighbor_route_reflector_client_cmd);
15998 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
15999 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
16000 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
16001 install_element(BGP_IPV6M_NODE,
16002 &no_neighbor_route_reflector_client_cmd);
16003 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
16004 install_element(BGP_IPV6L_NODE,
16005 &no_neighbor_route_reflector_client_cmd);
16006 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
16007 install_element(BGP_VPNV4_NODE,
16008 &no_neighbor_route_reflector_client_cmd);
16009 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
16010 install_element(BGP_VPNV6_NODE,
16011 &no_neighbor_route_reflector_client_cmd);
16012 install_element(BGP_FLOWSPECV4_NODE,
16013 &neighbor_route_reflector_client_cmd);
16014 install_element(BGP_FLOWSPECV4_NODE,
16015 &no_neighbor_route_reflector_client_cmd);
16016 install_element(BGP_FLOWSPECV6_NODE,
16017 &neighbor_route_reflector_client_cmd);
16018 install_element(BGP_FLOWSPECV6_NODE,
16019 &no_neighbor_route_reflector_client_cmd);
16020 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
16021 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
16022
16023 /* "neighbor route-server" commands.*/
16024 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
16025 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
16026 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
16027 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
16028 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
16029 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
16030 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
16031 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
16032 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
16033 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
16034 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
16035 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
16036 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
16037 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
16038 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
16039 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
16040 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
16041 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
16042 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
16043 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
16044 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
16045 install_element(BGP_FLOWSPECV4_NODE,
16046 &no_neighbor_route_server_client_cmd);
16047 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
16048 install_element(BGP_FLOWSPECV6_NODE,
16049 &no_neighbor_route_server_client_cmd);
16050
16051 /* "neighbor addpath-tx-all-paths" commands.*/
16052 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
16053 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
16054 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
16055 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16056 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
16057 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16058 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
16059 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16060 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
16061 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16062 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
16063 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16064 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
16065 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16066 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
16067 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16068 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
16069 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16070
16071 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
16072 install_element(BGP_NODE,
16073 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
16074 install_element(BGP_NODE,
16075 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
16076 install_element(BGP_IPV4_NODE,
16077 &neighbor_addpath_tx_bestpath_per_as_cmd);
16078 install_element(BGP_IPV4_NODE,
16079 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16080 install_element(BGP_IPV4M_NODE,
16081 &neighbor_addpath_tx_bestpath_per_as_cmd);
16082 install_element(BGP_IPV4M_NODE,
16083 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16084 install_element(BGP_IPV4L_NODE,
16085 &neighbor_addpath_tx_bestpath_per_as_cmd);
16086 install_element(BGP_IPV4L_NODE,
16087 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16088 install_element(BGP_IPV6_NODE,
16089 &neighbor_addpath_tx_bestpath_per_as_cmd);
16090 install_element(BGP_IPV6_NODE,
16091 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16092 install_element(BGP_IPV6M_NODE,
16093 &neighbor_addpath_tx_bestpath_per_as_cmd);
16094 install_element(BGP_IPV6M_NODE,
16095 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16096 install_element(BGP_IPV6L_NODE,
16097 &neighbor_addpath_tx_bestpath_per_as_cmd);
16098 install_element(BGP_IPV6L_NODE,
16099 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16100 install_element(BGP_VPNV4_NODE,
16101 &neighbor_addpath_tx_bestpath_per_as_cmd);
16102 install_element(BGP_VPNV4_NODE,
16103 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16104 install_element(BGP_VPNV6_NODE,
16105 &neighbor_addpath_tx_bestpath_per_as_cmd);
16106 install_element(BGP_VPNV6_NODE,
16107 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16108
16109 /* "neighbor sender-as-path-loop-detection" commands. */
16110 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
16111 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
16112
16113 /* "neighbor passive" commands. */
16114 install_element(BGP_NODE, &neighbor_passive_cmd);
16115 install_element(BGP_NODE, &no_neighbor_passive_cmd);
16116
16117
16118 /* "neighbor shutdown" commands. */
16119 install_element(BGP_NODE, &neighbor_shutdown_cmd);
16120 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
16121 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
16122 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
16123
16124 /* "neighbor capability extended-nexthop" commands.*/
16125 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
16126 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
16127
16128 /* "neighbor capability orf prefix-list" commands.*/
16129 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
16130 install_element(BGP_NODE,
16131 &no_neighbor_capability_orf_prefix_hidden_cmd);
16132 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
16133 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
16134 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
16135 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
16136 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
16137 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
16138 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
16139 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
16140 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
16141 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
16142 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
16143 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
16144
16145 /* "neighbor capability dynamic" commands.*/
16146 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
16147 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
16148
16149 /* "neighbor dont-capability-negotiate" commands. */
16150 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
16151 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
16152
16153 /* "neighbor ebgp-multihop" commands. */
16154 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
16155 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
16156 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
16157
16158 /* "neighbor disable-connected-check" commands. */
16159 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
16160 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
16161
16162 /* "neighbor enforce-first-as" commands. */
16163 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
16164 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
16165
16166 /* "neighbor description" commands. */
16167 install_element(BGP_NODE, &neighbor_description_cmd);
16168 install_element(BGP_NODE, &no_neighbor_description_cmd);
16169 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
16170
16171 /* "neighbor update-source" commands. "*/
16172 install_element(BGP_NODE, &neighbor_update_source_cmd);
16173 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
16174
16175 /* "neighbor default-originate" commands. */
16176 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
16177 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
16178 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
16179 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
16180 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
16181 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
16182 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
16183 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
16184 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
16185 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
16186 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
16187 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
16188 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
16189 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
16190 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
16191 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
16192 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
16193 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
16194 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
16195 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
16196 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
16197
16198 /* "neighbor port" commands. */
16199 install_element(BGP_NODE, &neighbor_port_cmd);
16200 install_element(BGP_NODE, &no_neighbor_port_cmd);
16201
16202 /* "neighbor weight" commands. */
16203 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
16204 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
16205
16206 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
16207 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
16208 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
16209 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
16210 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
16211 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
16212 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
16213 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
16214 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
16215 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
16216 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
16217 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
16218 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
16219 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
16220 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
16221 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
16222
16223 /* "neighbor override-capability" commands. */
16224 install_element(BGP_NODE, &neighbor_override_capability_cmd);
16225 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
16226
16227 /* "neighbor strict-capability-match" commands. */
16228 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
16229 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
16230
16231 /* "neighbor timers" commands. */
16232 install_element(BGP_NODE, &neighbor_timers_cmd);
16233 install_element(BGP_NODE, &no_neighbor_timers_cmd);
16234
16235 /* "neighbor timers connect" commands. */
16236 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
16237 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
16238
16239 /* "neighbor advertisement-interval" commands. */
16240 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
16241 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
16242
16243 /* "neighbor interface" commands. */
16244 install_element(BGP_NODE, &neighbor_interface_cmd);
16245 install_element(BGP_NODE, &no_neighbor_interface_cmd);
16246
16247 /* "neighbor distribute" commands. */
16248 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
16249 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
16250 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
16251 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
16252 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
16253 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
16254 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
16255 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
16256 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
16257 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
16258 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
16259 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
16260 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
16261 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
16262 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
16263 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
16264 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
16265 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
16266
16267 /* "neighbor prefix-list" commands. */
16268 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
16269 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
16270 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
16271 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
16272 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
16273 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
16274 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
16275 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
16276 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
16277 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
16278 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
16279 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
16280 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
16281 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
16282 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
16283 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
16284 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
16285 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
16286 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
16287 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
16288 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
16289 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
16290
16291 /* "neighbor filter-list" commands. */
16292 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
16293 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
16294 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
16295 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
16296 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
16297 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
16298 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
16299 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
16300 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
16301 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
16302 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
16303 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
16304 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
16305 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
16306 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
16307 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
16308 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
16309 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
16310 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
16311 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
16312 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
16313 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
16314
16315 /* "neighbor route-map" commands. */
16316 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
16317 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
16318 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
16319 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
16320 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
16321 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
16322 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
16323 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
16324 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
16325 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
16326 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
16327 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
16328 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
16329 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
16330 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
16331 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
16332 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
16333 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
16334 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
16335 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
16336 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
16337 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
16338 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
16339 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
16340
16341 /* "neighbor unsuppress-map" commands. */
16342 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
16343 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
16344 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
16345 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
16346 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
16347 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
16348 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
16349 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
16350 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
16351 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
16352 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
16353 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
16354 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
16355 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
16356 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
16357 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
16358 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
16359 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
16360
16361 /* neighbor maximum-prefix-out commands. */
16362 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
16363 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
16364 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
16365 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
16366 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
16367 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
16368 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
16369 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
16370 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
16371 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
16372 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
16373 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
16374 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
16375 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
16376 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
16377 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
16378 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
16379 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
16380
16381 /* "neighbor maximum-prefix" commands. */
16382 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
16383 install_element(BGP_NODE,
16384 &neighbor_maximum_prefix_threshold_hidden_cmd);
16385 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
16386 install_element(BGP_NODE,
16387 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
16388 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
16389 install_element(BGP_NODE,
16390 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
16391 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
16392 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
16393 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
16394 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
16395 install_element(BGP_IPV4_NODE,
16396 &neighbor_maximum_prefix_threshold_warning_cmd);
16397 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
16398 install_element(BGP_IPV4_NODE,
16399 &neighbor_maximum_prefix_threshold_restart_cmd);
16400 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
16401 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
16402 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
16403 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
16404 install_element(BGP_IPV4M_NODE,
16405 &neighbor_maximum_prefix_threshold_warning_cmd);
16406 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
16407 install_element(BGP_IPV4M_NODE,
16408 &neighbor_maximum_prefix_threshold_restart_cmd);
16409 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
16410 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
16411 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
16412 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
16413 install_element(BGP_IPV4L_NODE,
16414 &neighbor_maximum_prefix_threshold_warning_cmd);
16415 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
16416 install_element(BGP_IPV4L_NODE,
16417 &neighbor_maximum_prefix_threshold_restart_cmd);
16418 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
16419 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
16420 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
16421 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
16422 install_element(BGP_IPV6_NODE,
16423 &neighbor_maximum_prefix_threshold_warning_cmd);
16424 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
16425 install_element(BGP_IPV6_NODE,
16426 &neighbor_maximum_prefix_threshold_restart_cmd);
16427 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
16428 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
16429 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
16430 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
16431 install_element(BGP_IPV6M_NODE,
16432 &neighbor_maximum_prefix_threshold_warning_cmd);
16433 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
16434 install_element(BGP_IPV6M_NODE,
16435 &neighbor_maximum_prefix_threshold_restart_cmd);
16436 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
16437 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
16438 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
16439 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
16440 install_element(BGP_IPV6L_NODE,
16441 &neighbor_maximum_prefix_threshold_warning_cmd);
16442 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
16443 install_element(BGP_IPV6L_NODE,
16444 &neighbor_maximum_prefix_threshold_restart_cmd);
16445 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
16446 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
16447 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
16448 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
16449 install_element(BGP_VPNV4_NODE,
16450 &neighbor_maximum_prefix_threshold_warning_cmd);
16451 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
16452 install_element(BGP_VPNV4_NODE,
16453 &neighbor_maximum_prefix_threshold_restart_cmd);
16454 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
16455 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
16456 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
16457 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
16458 install_element(BGP_VPNV6_NODE,
16459 &neighbor_maximum_prefix_threshold_warning_cmd);
16460 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
16461 install_element(BGP_VPNV6_NODE,
16462 &neighbor_maximum_prefix_threshold_restart_cmd);
16463 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
16464
16465 /* "neighbor allowas-in" */
16466 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
16467 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
16468 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
16469 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
16470 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
16471 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
16472 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
16473 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
16474 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
16475 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
16476 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
16477 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
16478 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
16479 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
16480 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
16481 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
16482 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
16483 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
16484 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
16485 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
16486
16487 /* address-family commands. */
16488 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
16489 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
16490 #ifdef KEEP_OLD_VPN_COMMANDS
16491 install_element(BGP_NODE, &address_family_vpnv4_cmd);
16492 install_element(BGP_NODE, &address_family_vpnv6_cmd);
16493 #endif /* KEEP_OLD_VPN_COMMANDS */
16494
16495 install_element(BGP_NODE, &address_family_evpn_cmd);
16496
16497 /* "exit-address-family" command. */
16498 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
16499 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
16500 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
16501 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
16502 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
16503 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
16504 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
16505 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
16506 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
16507 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
16508 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
16509
16510 /* "clear ip bgp commands" */
16511 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
16512
16513 /* clear ip bgp prefix */
16514 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
16515 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
16516 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
16517
16518 /* "show [ip] bgp summary" commands. */
16519 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
16520 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
16521 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
16522 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
16523 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
16524 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
16525 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
16526
16527 /* "show [ip] bgp neighbors" commands. */
16528 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
16529
16530 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
16531
16532 /* "show [ip] bgp peer-group" commands. */
16533 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
16534
16535 /* "show [ip] bgp paths" commands. */
16536 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
16537
16538 /* "show [ip] bgp community" commands. */
16539 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
16540
16541 /* "show ip bgp large-community" commands. */
16542 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
16543 /* "show [ip] bgp attribute-info" commands. */
16544 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
16545 /* "show [ip] bgp route-leak" command */
16546 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
16547
16548 /* "redistribute" commands. */
16549 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
16550 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
16551 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
16552 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
16553 install_element(BGP_NODE,
16554 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
16555 install_element(BGP_NODE,
16556 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
16557 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
16558 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
16559 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
16560 install_element(BGP_NODE,
16561 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
16562 install_element(BGP_NODE,
16563 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
16564 install_element(BGP_NODE,
16565 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
16566 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
16567 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
16568 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
16569 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
16570 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
16571 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
16572 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
16573 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
16574 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
16575 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
16576 install_element(BGP_IPV4_NODE,
16577 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
16578 install_element(BGP_IPV4_NODE,
16579 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
16580 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
16581 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
16582 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
16583 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
16584 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
16585 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
16586
16587 /* import|export vpn [route-map WORD] */
16588 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
16589 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
16590
16591 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
16592 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
16593
16594 /* ttl_security commands */
16595 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
16596 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
16597
16598 /* "show [ip] bgp memory" commands. */
16599 install_element(VIEW_NODE, &show_bgp_memory_cmd);
16600
16601 /* "show bgp martian next-hop" */
16602 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
16603
16604 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
16605
16606 /* "show [ip] bgp views" commands. */
16607 install_element(VIEW_NODE, &show_bgp_views_cmd);
16608
16609 /* "show [ip] bgp vrfs" commands. */
16610 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
16611
16612 /* Community-list. */
16613 community_list_vty();
16614
16615 /* vpn-policy commands */
16616 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
16617 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
16618 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
16619 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
16620 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
16621 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
16622 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
16623 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
16624 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
16625 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
16626 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
16627 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
16628
16629 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
16630 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
16631
16632 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
16633 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
16634 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
16635 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
16636 install_element(BGP_IPV4_NODE, &af_no_nexthop_vpn_export_cmd);
16637 install_element(BGP_IPV6_NODE, &af_no_nexthop_vpn_export_cmd);
16638 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
16639 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
16640 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
16641 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
16642 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
16643 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
16644 }
16645
16646 #include "memory.h"
16647 #include "bgp_regex.h"
16648 #include "bgp_clist.h"
16649 #include "bgp_ecommunity.h"
16650
16651 /* VTY functions. */
16652
16653 /* Direction value to string conversion. */
16654 static const char *community_direct_str(int direct)
16655 {
16656 switch (direct) {
16657 case COMMUNITY_DENY:
16658 return "deny";
16659 case COMMUNITY_PERMIT:
16660 return "permit";
16661 default:
16662 return "unknown";
16663 }
16664 }
16665
16666 /* Display error string. */
16667 static void community_list_perror(struct vty *vty, int ret)
16668 {
16669 switch (ret) {
16670 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
16671 vty_out(vty, "%% Can't find community-list\n");
16672 break;
16673 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
16674 vty_out(vty, "%% Malformed community-list value\n");
16675 break;
16676 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
16677 vty_out(vty,
16678 "%% Community name conflict, previously defined as standard community\n");
16679 break;
16680 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
16681 vty_out(vty,
16682 "%% Community name conflict, previously defined as expanded community\n");
16683 break;
16684 }
16685 }
16686
16687 /* "community-list" keyword help string. */
16688 #define COMMUNITY_LIST_STR "Add a community list entry\n"
16689
16690 /*community-list standard */
16691 DEFUN (community_list_standard,
16692 bgp_community_list_standard_cmd,
16693 "bgp community-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
16694 BGP_STR
16695 COMMUNITY_LIST_STR
16696 "Community list number (standard)\n"
16697 "Add an standard community-list entry\n"
16698 "Community list name\n"
16699 "Sequence number of an entry\n"
16700 "Sequence number\n"
16701 "Specify community to reject\n"
16702 "Specify community to accept\n"
16703 COMMUNITY_VAL_STR)
16704 {
16705 char *cl_name_or_number = NULL;
16706 char *seq = NULL;
16707 int direct = 0;
16708 int style = COMMUNITY_LIST_STANDARD;
16709 int idx = 0;
16710
16711 argv_find(argv, argc, "(1-4294967295)", &idx);
16712 if (idx)
16713 seq = argv[idx]->arg;
16714
16715 idx = 0;
16716 argv_find(argv, argc, "(1-99)", &idx);
16717 argv_find(argv, argc, "WORD", &idx);
16718 cl_name_or_number = argv[idx]->arg;
16719 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
16720 : COMMUNITY_DENY;
16721 argv_find(argv, argc, "AA:NN", &idx);
16722 char *str = argv_concat(argv, argc, idx);
16723
16724 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
16725 direct, style);
16726
16727 XFREE(MTYPE_TMP, str);
16728
16729 if (ret < 0) {
16730 /* Display error string. */
16731 community_list_perror(vty, ret);
16732 return CMD_WARNING_CONFIG_FAILED;
16733 }
16734
16735 return CMD_SUCCESS;
16736 }
16737
16738 DEFUN (no_community_list_standard_all,
16739 no_bgp_community_list_standard_all_cmd,
16740 "no bgp community-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
16741 NO_STR
16742 BGP_STR
16743 COMMUNITY_LIST_STR
16744 "Community list number (standard)\n"
16745 "Add an standard community-list entry\n"
16746 "Community list name\n"
16747 "Sequence number of an entry\n"
16748 "Sequence number\n"
16749 "Specify community to reject\n"
16750 "Specify community to accept\n"
16751 COMMUNITY_VAL_STR)
16752 {
16753 char *cl_name_or_number = NULL;
16754 char *str = NULL;
16755 int direct = 0;
16756 int style = COMMUNITY_LIST_STANDARD;
16757 char *seq = NULL;
16758 int idx = 0;
16759
16760 argv_find(argv, argc, "(1-4294967295)", &idx);
16761 if (idx)
16762 seq = argv[idx]->arg;
16763
16764 idx = 0;
16765 argv_find(argv, argc, "permit", &idx);
16766 argv_find(argv, argc, "deny", &idx);
16767
16768 if (idx) {
16769 direct = argv_find(argv, argc, "permit", &idx)
16770 ? COMMUNITY_PERMIT
16771 : COMMUNITY_DENY;
16772
16773 idx = 0;
16774 argv_find(argv, argc, "AA:NN", &idx);
16775 str = argv_concat(argv, argc, idx);
16776 }
16777
16778 idx = 0;
16779 argv_find(argv, argc, "(1-99)", &idx);
16780 argv_find(argv, argc, "WORD", &idx);
16781 cl_name_or_number = argv[idx]->arg;
16782
16783 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
16784 direct, style);
16785
16786 XFREE(MTYPE_TMP, str);
16787
16788 if (ret < 0) {
16789 community_list_perror(vty, ret);
16790 return CMD_WARNING_CONFIG_FAILED;
16791 }
16792
16793 return CMD_SUCCESS;
16794 }
16795
16796 ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
16797 "no bgp community-list <(1-99)|standard WORD>",
16798 NO_STR BGP_STR COMMUNITY_LIST_STR
16799 "Community list number (standard)\n"
16800 "Add an standard community-list entry\n"
16801 "Community list name\n")
16802
16803 /*community-list expanded */
16804 DEFUN (community_list_expanded_all,
16805 bgp_community_list_expanded_all_cmd,
16806 "bgp community-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
16807 BGP_STR
16808 COMMUNITY_LIST_STR
16809 "Community list number (expanded)\n"
16810 "Add an expanded community-list entry\n"
16811 "Community list name\n"
16812 "Sequence number of an entry\n"
16813 "Sequence number\n"
16814 "Specify community to reject\n"
16815 "Specify community to accept\n"
16816 COMMUNITY_VAL_STR)
16817 {
16818 char *cl_name_or_number = NULL;
16819 char *seq = NULL;
16820 int direct = 0;
16821 int style = COMMUNITY_LIST_EXPANDED;
16822 int idx = 0;
16823
16824 argv_find(argv, argc, "(1-4294967295)", &idx);
16825 if (idx)
16826 seq = argv[idx]->arg;
16827
16828 idx = 0;
16829
16830 argv_find(argv, argc, "(100-500)", &idx);
16831 argv_find(argv, argc, "WORD", &idx);
16832 cl_name_or_number = argv[idx]->arg;
16833 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
16834 : COMMUNITY_DENY;
16835 argv_find(argv, argc, "AA:NN", &idx);
16836 char *str = argv_concat(argv, argc, idx);
16837
16838 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
16839 direct, style);
16840
16841 XFREE(MTYPE_TMP, str);
16842
16843 if (ret < 0) {
16844 /* Display error string. */
16845 community_list_perror(vty, ret);
16846 return CMD_WARNING_CONFIG_FAILED;
16847 }
16848
16849 return CMD_SUCCESS;
16850 }
16851
16852 DEFUN (no_community_list_expanded_all,
16853 no_bgp_community_list_expanded_all_cmd,
16854 "no bgp community-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
16855 NO_STR
16856 BGP_STR
16857 COMMUNITY_LIST_STR
16858 "Community list number (expanded)\n"
16859 "Add an expanded community-list entry\n"
16860 "Community list name\n"
16861 "Sequence number of an entry\n"
16862 "Sequence number\n"
16863 "Specify community to reject\n"
16864 "Specify community to accept\n"
16865 COMMUNITY_VAL_STR)
16866 {
16867 char *cl_name_or_number = NULL;
16868 char *seq = NULL;
16869 char *str = NULL;
16870 int direct = 0;
16871 int style = COMMUNITY_LIST_EXPANDED;
16872 int idx = 0;
16873
16874 argv_find(argv, argc, "(1-4294967295)", &idx);
16875 if (idx)
16876 seq = argv[idx]->arg;
16877
16878 idx = 0;
16879 argv_find(argv, argc, "permit", &idx);
16880 argv_find(argv, argc, "deny", &idx);
16881
16882 if (idx) {
16883 direct = argv_find(argv, argc, "permit", &idx)
16884 ? COMMUNITY_PERMIT
16885 : COMMUNITY_DENY;
16886
16887 idx = 0;
16888 argv_find(argv, argc, "AA:NN", &idx);
16889 str = argv_concat(argv, argc, idx);
16890 }
16891
16892 idx = 0;
16893 argv_find(argv, argc, "(100-500)", &idx);
16894 argv_find(argv, argc, "WORD", &idx);
16895 cl_name_or_number = argv[idx]->arg;
16896
16897 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
16898 direct, style);
16899
16900 XFREE(MTYPE_TMP, str);
16901
16902 if (ret < 0) {
16903 community_list_perror(vty, ret);
16904 return CMD_WARNING_CONFIG_FAILED;
16905 }
16906
16907 return CMD_SUCCESS;
16908 }
16909
16910 ALIAS(no_community_list_expanded_all, no_bgp_community_list_expanded_all_list_cmd,
16911 "no bgp community-list <(100-500)|expanded WORD>",
16912 NO_STR IP_STR COMMUNITY_LIST_STR
16913 "Community list number (expanded)\n"
16914 "Add an expanded community-list entry\n"
16915 "Community list name\n")
16916
16917 /* Return configuration string of community-list entry. */
16918 static const char *community_list_config_str(struct community_entry *entry)
16919 {
16920 const char *str;
16921
16922 if (entry->any)
16923 str = "";
16924 else {
16925 if (entry->style == COMMUNITY_LIST_STANDARD)
16926 str = community_str(entry->u.com, false);
16927 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
16928 str = lcommunity_str(entry->u.lcom, false);
16929 else
16930 str = entry->config;
16931 }
16932 return str;
16933 }
16934
16935 static void community_list_show(struct vty *vty, struct community_list *list)
16936 {
16937 struct community_entry *entry;
16938
16939 for (entry = list->head; entry; entry = entry->next) {
16940 if (entry == list->head) {
16941 if (all_digit(list->name))
16942 vty_out(vty, "Community %s list %s\n",
16943 entry->style == COMMUNITY_LIST_STANDARD
16944 ? "standard"
16945 : "(expanded) access",
16946 list->name);
16947 else
16948 vty_out(vty, "Named Community %s list %s\n",
16949 entry->style == COMMUNITY_LIST_STANDARD
16950 ? "standard"
16951 : "expanded",
16952 list->name);
16953 }
16954 if (entry->any)
16955 vty_out(vty, " %s\n",
16956 community_direct_str(entry->direct));
16957 else
16958 vty_out(vty, " %s %s\n",
16959 community_direct_str(entry->direct),
16960 community_list_config_str(entry));
16961 }
16962 }
16963
16964 DEFUN (show_community_list,
16965 show_bgp_community_list_cmd,
16966 "show bgp community-list",
16967 SHOW_STR
16968 BGP_STR
16969 "List community-list\n")
16970 {
16971 struct community_list *list;
16972 struct community_list_master *cm;
16973
16974 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
16975 if (!cm)
16976 return CMD_SUCCESS;
16977
16978 for (list = cm->num.head; list; list = list->next)
16979 community_list_show(vty, list);
16980
16981 for (list = cm->str.head; list; list = list->next)
16982 community_list_show(vty, list);
16983
16984 return CMD_SUCCESS;
16985 }
16986
16987 DEFUN (show_community_list_arg,
16988 show_bgp_community_list_arg_cmd,
16989 "show bgp community-list <(1-500)|WORD> detail",
16990 SHOW_STR
16991 BGP_STR
16992 "List community-list\n"
16993 "Community-list number\n"
16994 "Community-list name\n"
16995 "Detailed information on community-list\n")
16996 {
16997 int idx_comm_list = 3;
16998 struct community_list *list;
16999
17000 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
17001 COMMUNITY_LIST_MASTER);
17002 if (!list) {
17003 vty_out(vty, "%% Can't find community-list\n");
17004 return CMD_WARNING;
17005 }
17006
17007 community_list_show(vty, list);
17008
17009 return CMD_SUCCESS;
17010 }
17011
17012 /*
17013 * Large Community code.
17014 */
17015 static int lcommunity_list_set_vty(struct vty *vty, int argc,
17016 struct cmd_token **argv, int style,
17017 int reject_all_digit_name)
17018 {
17019 int ret;
17020 int direct;
17021 char *str;
17022 int idx = 0;
17023 char *cl_name;
17024 char *seq = NULL;
17025
17026 argv_find(argv, argc, "(1-4294967295)", &idx);
17027 if (idx)
17028 seq = argv[idx]->arg;
17029
17030 idx = 0;
17031 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
17032 : COMMUNITY_DENY;
17033
17034 /* All digit name check. */
17035 idx = 0;
17036 argv_find(argv, argc, "WORD", &idx);
17037 argv_find(argv, argc, "(1-99)", &idx);
17038 argv_find(argv, argc, "(100-500)", &idx);
17039 cl_name = argv[idx]->arg;
17040 if (reject_all_digit_name && all_digit(cl_name)) {
17041 vty_out(vty, "%% Community name cannot have all digits\n");
17042 return CMD_WARNING_CONFIG_FAILED;
17043 }
17044
17045 idx = 0;
17046 argv_find(argv, argc, "AA:BB:CC", &idx);
17047 argv_find(argv, argc, "LINE", &idx);
17048 /* Concat community string argument. */
17049 if (idx)
17050 str = argv_concat(argv, argc, idx);
17051 else
17052 str = NULL;
17053
17054 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
17055
17056 /* Free temporary community list string allocated by
17057 argv_concat(). */
17058 XFREE(MTYPE_TMP, str);
17059
17060 if (ret < 0) {
17061 community_list_perror(vty, ret);
17062 return CMD_WARNING_CONFIG_FAILED;
17063 }
17064 return CMD_SUCCESS;
17065 }
17066
17067 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
17068 struct cmd_token **argv, int style)
17069 {
17070 int ret;
17071 int direct = 0;
17072 char *str = NULL;
17073 int idx = 0;
17074 char *seq = NULL;
17075
17076 argv_find(argv, argc, "(1-4294967295)", &idx);
17077 if (idx)
17078 seq = argv[idx]->arg;
17079
17080 idx = 0;
17081 argv_find(argv, argc, "permit", &idx);
17082 argv_find(argv, argc, "deny", &idx);
17083
17084 if (idx) {
17085 /* Check the list direct. */
17086 if (strncmp(argv[idx]->arg, "p", 1) == 0)
17087 direct = COMMUNITY_PERMIT;
17088 else
17089 direct = COMMUNITY_DENY;
17090
17091 idx = 0;
17092 argv_find(argv, argc, "LINE", &idx);
17093 argv_find(argv, argc, "AA:AA:NN", &idx);
17094 /* Concat community string argument. */
17095 str = argv_concat(argv, argc, idx);
17096 }
17097
17098 idx = 0;
17099 argv_find(argv, argc, "(1-99)", &idx);
17100 argv_find(argv, argc, "(100-500)", &idx);
17101 argv_find(argv, argc, "WORD", &idx);
17102
17103 /* Unset community list. */
17104 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
17105 style);
17106
17107 /* Free temporary community list string allocated by
17108 argv_concat(). */
17109 XFREE(MTYPE_TMP, str);
17110
17111 if (ret < 0) {
17112 community_list_perror(vty, ret);
17113 return CMD_WARNING_CONFIG_FAILED;
17114 }
17115
17116 return CMD_SUCCESS;
17117 }
17118
17119 /* "large-community-list" keyword help string. */
17120 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
17121 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
17122
17123 DEFUN (lcommunity_list_standard,
17124 bgp_lcommunity_list_standard_cmd,
17125 "bgp large-community-list (1-99) [seq (1-4294967295)] <deny|permit> AA:BB:CC...",
17126 BGP_STR
17127 LCOMMUNITY_LIST_STR
17128 "Large Community list number (standard)\n"
17129 "Sequence number of an entry\n"
17130 "Sequence number\n"
17131 "Specify large community to reject\n"
17132 "Specify large community to accept\n"
17133 LCOMMUNITY_VAL_STR)
17134 {
17135 return lcommunity_list_set_vty(vty, argc, argv,
17136 LARGE_COMMUNITY_LIST_STANDARD, 0);
17137 }
17138
17139 DEFUN (lcommunity_list_expanded,
17140 bgp_lcommunity_list_expanded_cmd,
17141 "bgp large-community-list (100-500) [seq (1-4294967295)] <deny|permit> LINE...",
17142 BGP_STR
17143 LCOMMUNITY_LIST_STR
17144 "Large Community list number (expanded)\n"
17145 "Sequence number of an entry\n"
17146 "Sequence number\n"
17147 "Specify large community to reject\n"
17148 "Specify large community to accept\n"
17149 "An ordered list as a regular-expression\n")
17150 {
17151 return lcommunity_list_set_vty(vty, argc, argv,
17152 LARGE_COMMUNITY_LIST_EXPANDED, 0);
17153 }
17154
17155 DEFUN (lcommunity_list_name_standard,
17156 bgp_lcommunity_list_name_standard_cmd,
17157 "bgp large-community-list standard WORD [seq (1-4294967295)] <deny|permit> AA:BB:CC...",
17158 BGP_STR
17159 LCOMMUNITY_LIST_STR
17160 "Specify standard large-community-list\n"
17161 "Large Community list name\n"
17162 "Sequence number of an entry\n"
17163 "Sequence number\n"
17164 "Specify large community to reject\n"
17165 "Specify large community to accept\n"
17166 LCOMMUNITY_VAL_STR)
17167 {
17168 return lcommunity_list_set_vty(vty, argc, argv,
17169 LARGE_COMMUNITY_LIST_STANDARD, 1);
17170 }
17171
17172 DEFUN (lcommunity_list_name_expanded,
17173 bgp_lcommunity_list_name_expanded_cmd,
17174 "bgp large-community-list expanded WORD [seq (1-4294967295)] <deny|permit> LINE...",
17175 BGP_STR
17176 LCOMMUNITY_LIST_STR
17177 "Specify expanded large-community-list\n"
17178 "Large Community list name\n"
17179 "Sequence number of an entry\n"
17180 "Sequence number\n"
17181 "Specify large community to reject\n"
17182 "Specify large community to accept\n"
17183 "An ordered list as a regular-expression\n")
17184 {
17185 return lcommunity_list_set_vty(vty, argc, argv,
17186 LARGE_COMMUNITY_LIST_EXPANDED, 1);
17187 }
17188
17189 DEFUN (no_lcommunity_list_all,
17190 no_bgp_lcommunity_list_all_cmd,
17191 "no bgp large-community-list <(1-99)|(100-500)|WORD>",
17192 NO_STR
17193 BGP_STR
17194 LCOMMUNITY_LIST_STR
17195 "Large Community list number (standard)\n"
17196 "Large Community list number (expanded)\n"
17197 "Large Community list name\n")
17198 {
17199 return lcommunity_list_unset_vty(vty, argc, argv,
17200 LARGE_COMMUNITY_LIST_STANDARD);
17201 }
17202
17203 DEFUN (no_lcommunity_list_name_standard_all,
17204 no_bgp_lcommunity_list_name_standard_all_cmd,
17205 "no bgp large-community-list standard WORD",
17206 NO_STR
17207 BGP_STR
17208 LCOMMUNITY_LIST_STR
17209 "Specify standard large-community-list\n"
17210 "Large Community list name\n")
17211 {
17212 return lcommunity_list_unset_vty(vty, argc, argv,
17213 LARGE_COMMUNITY_LIST_STANDARD);
17214 }
17215
17216 DEFUN (no_lcommunity_list_name_expanded_all,
17217 no_bgp_lcommunity_list_name_expanded_all_cmd,
17218 "no bgp large-community-list expanded WORD",
17219 NO_STR
17220 BGP_STR
17221 LCOMMUNITY_LIST_STR
17222 "Specify expanded large-community-list\n"
17223 "Large Community list name\n")
17224 {
17225 return lcommunity_list_unset_vty(vty, argc, argv,
17226 LARGE_COMMUNITY_LIST_EXPANDED);
17227 }
17228
17229 DEFUN (no_lcommunity_list_standard,
17230 no_bgp_lcommunity_list_standard_cmd,
17231 "no bgp large-community-list (1-99) [seq (1-4294967295)] <deny|permit> AA:AA:NN...",
17232 NO_STR
17233 BGP_STR
17234 LCOMMUNITY_LIST_STR
17235 "Large Community list number (standard)\n"
17236 "Sequence number of an entry\n"
17237 "Sequence number\n"
17238 "Specify large community to reject\n"
17239 "Specify large community to accept\n"
17240 LCOMMUNITY_VAL_STR)
17241 {
17242 return lcommunity_list_unset_vty(vty, argc, argv,
17243 LARGE_COMMUNITY_LIST_STANDARD);
17244 }
17245
17246 DEFUN (no_lcommunity_list_expanded,
17247 no_bgp_lcommunity_list_expanded_cmd,
17248 "no bgp large-community-list (100-500) [seq (1-4294967295)] <deny|permit> LINE...",
17249 NO_STR
17250 BGP_STR
17251 LCOMMUNITY_LIST_STR
17252 "Large Community list number (expanded)\n"
17253 "Sequence number of an entry\n"
17254 "Sequence number\n"
17255 "Specify large community to reject\n"
17256 "Specify large community to accept\n"
17257 "An ordered list as a regular-expression\n")
17258 {
17259 return lcommunity_list_unset_vty(vty, argc, argv,
17260 LARGE_COMMUNITY_LIST_EXPANDED);
17261 }
17262
17263 DEFUN (no_lcommunity_list_name_standard,
17264 no_bgp_lcommunity_list_name_standard_cmd,
17265 "no bgp large-community-list standard WORD [seq (1-4294967295)] <deny|permit> AA:AA:NN...",
17266 NO_STR
17267 BGP_STR
17268 LCOMMUNITY_LIST_STR
17269 "Specify standard large-community-list\n"
17270 "Large Community list name\n"
17271 "Sequence number of an entry\n"
17272 "Sequence number\n"
17273 "Specify large community to reject\n"
17274 "Specify large community to accept\n"
17275 LCOMMUNITY_VAL_STR)
17276 {
17277 return lcommunity_list_unset_vty(vty, argc, argv,
17278 LARGE_COMMUNITY_LIST_STANDARD);
17279 }
17280
17281 DEFUN (no_lcommunity_list_name_expanded,
17282 no_bgp_lcommunity_list_name_expanded_cmd,
17283 "no bgp large-community-list expanded WORD [seq (1-4294967295)] <deny|permit> LINE...",
17284 NO_STR
17285 BGP_STR
17286 LCOMMUNITY_LIST_STR
17287 "Specify expanded large-community-list\n"
17288 "Large community list name\n"
17289 "Sequence number of an entry\n"
17290 "Sequence number\n"
17291 "Specify large community to reject\n"
17292 "Specify large community to accept\n"
17293 "An ordered list as a regular-expression\n")
17294 {
17295 return lcommunity_list_unset_vty(vty, argc, argv,
17296 LARGE_COMMUNITY_LIST_EXPANDED);
17297 }
17298
17299 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
17300 {
17301 struct community_entry *entry;
17302
17303 for (entry = list->head; entry; entry = entry->next) {
17304 if (entry == list->head) {
17305 if (all_digit(list->name))
17306 vty_out(vty, "Large community %s list %s\n",
17307 entry->style ==
17308 LARGE_COMMUNITY_LIST_STANDARD
17309 ? "standard"
17310 : "(expanded) access",
17311 list->name);
17312 else
17313 vty_out(vty,
17314 "Named large community %s list %s\n",
17315 entry->style ==
17316 LARGE_COMMUNITY_LIST_STANDARD
17317 ? "standard"
17318 : "expanded",
17319 list->name);
17320 }
17321 if (entry->any)
17322 vty_out(vty, " %s\n",
17323 community_direct_str(entry->direct));
17324 else
17325 vty_out(vty, " %s %s\n",
17326 community_direct_str(entry->direct),
17327 community_list_config_str(entry));
17328 }
17329 }
17330
17331 DEFUN (show_lcommunity_list,
17332 show_bgp_lcommunity_list_cmd,
17333 "show bgp large-community-list",
17334 SHOW_STR
17335 BGP_STR
17336 "List large-community list\n")
17337 {
17338 struct community_list *list;
17339 struct community_list_master *cm;
17340
17341 cm = community_list_master_lookup(bgp_clist,
17342 LARGE_COMMUNITY_LIST_MASTER);
17343 if (!cm)
17344 return CMD_SUCCESS;
17345
17346 for (list = cm->num.head; list; list = list->next)
17347 lcommunity_list_show(vty, list);
17348
17349 for (list = cm->str.head; list; list = list->next)
17350 lcommunity_list_show(vty, list);
17351
17352 return CMD_SUCCESS;
17353 }
17354
17355 DEFUN (show_lcommunity_list_arg,
17356 show_bgp_lcommunity_list_arg_cmd,
17357 "show bgp large-community-list <(1-500)|WORD> detail",
17358 SHOW_STR
17359 BGP_STR
17360 "List large-community list\n"
17361 "Large-community-list number\n"
17362 "Large-community-list name\n"
17363 "Detailed information on large-community-list\n")
17364 {
17365 struct community_list *list;
17366
17367 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
17368 LARGE_COMMUNITY_LIST_MASTER);
17369 if (!list) {
17370 vty_out(vty, "%% Can't find large-community-list\n");
17371 return CMD_WARNING;
17372 }
17373
17374 lcommunity_list_show(vty, list);
17375
17376 return CMD_SUCCESS;
17377 }
17378
17379 /* "extcommunity-list" keyword help string. */
17380 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
17381 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
17382
17383 DEFUN (extcommunity_list_standard,
17384 bgp_extcommunity_list_standard_cmd,
17385 "bgp extcommunity-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
17386 BGP_STR
17387 EXTCOMMUNITY_LIST_STR
17388 "Extended Community list number (standard)\n"
17389 "Specify standard extcommunity-list\n"
17390 "Community list name\n"
17391 "Sequence number of an entry\n"
17392 "Sequence number\n"
17393 "Specify community to reject\n"
17394 "Specify community to accept\n"
17395 EXTCOMMUNITY_VAL_STR)
17396 {
17397 int style = EXTCOMMUNITY_LIST_STANDARD;
17398 int direct = 0;
17399 char *cl_number_or_name = NULL;
17400 char *seq = NULL;
17401
17402 int idx = 0;
17403
17404 argv_find(argv, argc, "(1-99)", &idx);
17405 argv_find(argv, argc, "WORD", &idx);
17406 cl_number_or_name = argv[idx]->arg;
17407
17408 argv_find(argv, argc, "(1-4294967295)", &idx);
17409 if (idx)
17410 seq = argv[idx]->arg;
17411
17412 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
17413 : COMMUNITY_DENY;
17414 argv_find(argv, argc, "AA:NN", &idx);
17415 char *str = argv_concat(argv, argc, idx);
17416
17417 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
17418 direct, style);
17419
17420 XFREE(MTYPE_TMP, str);
17421
17422 if (ret < 0) {
17423 community_list_perror(vty, ret);
17424 return CMD_WARNING_CONFIG_FAILED;
17425 }
17426
17427 return CMD_SUCCESS;
17428 }
17429
17430 DEFUN (extcommunity_list_name_expanded,
17431 bgp_extcommunity_list_name_expanded_cmd,
17432 "bgp extcommunity-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> LINE...",
17433 BGP_STR
17434 EXTCOMMUNITY_LIST_STR
17435 "Extended Community list number (expanded)\n"
17436 "Specify expanded extcommunity-list\n"
17437 "Extended Community list name\n"
17438 "Sequence number of an entry\n"
17439 "Sequence number\n"
17440 "Specify community to reject\n"
17441 "Specify community to accept\n"
17442 "An ordered list as a regular-expression\n")
17443 {
17444 int style = EXTCOMMUNITY_LIST_EXPANDED;
17445 int direct = 0;
17446 char *cl_number_or_name = NULL;
17447 char *seq = NULL;
17448 int idx = 0;
17449
17450 argv_find(argv, argc, "(100-500)", &idx);
17451 argv_find(argv, argc, "WORD", &idx);
17452 cl_number_or_name = argv[idx]->arg;
17453
17454 argv_find(argv, argc, "(1-4294967295)", &idx);
17455 if (idx)
17456 seq = argv[idx]->arg;
17457
17458 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
17459 : COMMUNITY_DENY;
17460 argv_find(argv, argc, "LINE", &idx);
17461 char *str = argv_concat(argv, argc, idx);
17462
17463 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
17464 direct, style);
17465
17466 XFREE(MTYPE_TMP, str);
17467
17468 if (ret < 0) {
17469 community_list_perror(vty, ret);
17470 return CMD_WARNING_CONFIG_FAILED;
17471 }
17472
17473 return CMD_SUCCESS;
17474 }
17475
17476 DEFUN (no_extcommunity_list_standard_all,
17477 no_bgp_extcommunity_list_standard_all_cmd,
17478 "no bgp extcommunity-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
17479 NO_STR
17480 BGP_STR
17481 EXTCOMMUNITY_LIST_STR
17482 "Extended Community list number (standard)\n"
17483 "Specify standard extcommunity-list\n"
17484 "Community list name\n"
17485 "Sequence number of an entry\n"
17486 "Sequence number\n"
17487 "Specify community to reject\n"
17488 "Specify community to accept\n"
17489 EXTCOMMUNITY_VAL_STR)
17490 {
17491 int style = EXTCOMMUNITY_LIST_STANDARD;
17492 int direct = 0;
17493 char *cl_number_or_name = NULL;
17494 char *str = NULL;
17495 char *seq = NULL;
17496 int idx = 0;
17497
17498 argv_find(argv, argc, "(1-4294967295)", &idx);
17499 if (idx)
17500 seq = argv[idx]->arg;
17501
17502 idx = 0;
17503 argv_find(argv, argc, "permit", &idx);
17504 argv_find(argv, argc, "deny", &idx);
17505 if (idx) {
17506 direct = argv_find(argv, argc, "permit", &idx)
17507 ? COMMUNITY_PERMIT
17508 : COMMUNITY_DENY;
17509
17510 idx = 0;
17511 argv_find(argv, argc, "AA:NN", &idx);
17512 str = argv_concat(argv, argc, idx);
17513 }
17514
17515 idx = 0;
17516 argv_find(argv, argc, "(1-99)", &idx);
17517 argv_find(argv, argc, "WORD", &idx);
17518 cl_number_or_name = argv[idx]->arg;
17519
17520 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
17521 seq, direct, style);
17522
17523 XFREE(MTYPE_TMP, str);
17524
17525 if (ret < 0) {
17526 community_list_perror(vty, ret);
17527 return CMD_WARNING_CONFIG_FAILED;
17528 }
17529
17530 return CMD_SUCCESS;
17531 }
17532
17533 ALIAS(no_extcommunity_list_standard_all,
17534 no_bgp_extcommunity_list_standard_all_list_cmd,
17535 "no bgp extcommunity-list <(1-99)|standard WORD>",
17536 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
17537 "Extended Community list number (standard)\n"
17538 "Specify standard extcommunity-list\n"
17539 "Community list name\n")
17540
17541 DEFUN (no_extcommunity_list_expanded_all,
17542 no_bgp_extcommunity_list_expanded_all_cmd,
17543 "no bgp extcommunity-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> LINE...",
17544 NO_STR
17545 BGP_STR
17546 EXTCOMMUNITY_LIST_STR
17547 "Extended Community list number (expanded)\n"
17548 "Specify expanded extcommunity-list\n"
17549 "Extended Community list name\n"
17550 "Sequence number of an entry\n"
17551 "Sequence number\n"
17552 "Specify community to reject\n"
17553 "Specify community to accept\n"
17554 "An ordered list as a regular-expression\n")
17555 {
17556 int style = EXTCOMMUNITY_LIST_EXPANDED;
17557 int direct = 0;
17558 char *cl_number_or_name = NULL;
17559 char *str = NULL;
17560 char *seq = NULL;
17561 int idx = 0;
17562
17563 argv_find(argv, argc, "(1-4294967295)", &idx);
17564 if (idx)
17565 seq = argv[idx]->arg;
17566
17567 idx = 0;
17568 argv_find(argv, argc, "permit", &idx);
17569 argv_find(argv, argc, "deny", &idx);
17570
17571 if (idx) {
17572 direct = argv_find(argv, argc, "permit", &idx)
17573 ? COMMUNITY_PERMIT
17574 : COMMUNITY_DENY;
17575
17576 idx = 0;
17577 argv_find(argv, argc, "LINE", &idx);
17578 str = argv_concat(argv, argc, idx);
17579 }
17580
17581 idx = 0;
17582 argv_find(argv, argc, "(100-500)", &idx);
17583 argv_find(argv, argc, "WORD", &idx);
17584 cl_number_or_name = argv[idx]->arg;
17585
17586 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
17587 seq, direct, style);
17588
17589 XFREE(MTYPE_TMP, str);
17590
17591 if (ret < 0) {
17592 community_list_perror(vty, ret);
17593 return CMD_WARNING_CONFIG_FAILED;
17594 }
17595
17596 return CMD_SUCCESS;
17597 }
17598
17599 ALIAS(no_extcommunity_list_expanded_all,
17600 no_bgp_extcommunity_list_expanded_all_list_cmd,
17601 "no bgp extcommunity-list <(100-500)|expanded WORD>",
17602 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
17603 "Extended Community list number (expanded)\n"
17604 "Specify expanded extcommunity-list\n"
17605 "Extended Community list name\n")
17606
17607 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
17608 {
17609 struct community_entry *entry;
17610
17611 for (entry = list->head; entry; entry = entry->next) {
17612 if (entry == list->head) {
17613 if (all_digit(list->name))
17614 vty_out(vty, "Extended community %s list %s\n",
17615 entry->style == EXTCOMMUNITY_LIST_STANDARD
17616 ? "standard"
17617 : "(expanded) access",
17618 list->name);
17619 else
17620 vty_out(vty,
17621 "Named extended community %s list %s\n",
17622 entry->style == EXTCOMMUNITY_LIST_STANDARD
17623 ? "standard"
17624 : "expanded",
17625 list->name);
17626 }
17627 if (entry->any)
17628 vty_out(vty, " %s\n",
17629 community_direct_str(entry->direct));
17630 else
17631 vty_out(vty, " %s %s\n",
17632 community_direct_str(entry->direct),
17633 community_list_config_str(entry));
17634 }
17635 }
17636
17637 DEFUN (show_extcommunity_list,
17638 show_bgp_extcommunity_list_cmd,
17639 "show bgp extcommunity-list",
17640 SHOW_STR
17641 BGP_STR
17642 "List extended-community list\n")
17643 {
17644 struct community_list *list;
17645 struct community_list_master *cm;
17646
17647 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
17648 if (!cm)
17649 return CMD_SUCCESS;
17650
17651 for (list = cm->num.head; list; list = list->next)
17652 extcommunity_list_show(vty, list);
17653
17654 for (list = cm->str.head; list; list = list->next)
17655 extcommunity_list_show(vty, list);
17656
17657 return CMD_SUCCESS;
17658 }
17659
17660 DEFUN (show_extcommunity_list_arg,
17661 show_bgp_extcommunity_list_arg_cmd,
17662 "show bgp extcommunity-list <(1-500)|WORD> detail",
17663 SHOW_STR
17664 BGP_STR
17665 "List extended-community list\n"
17666 "Extcommunity-list number\n"
17667 "Extcommunity-list name\n"
17668 "Detailed information on extcommunity-list\n")
17669 {
17670 int idx_comm_list = 3;
17671 struct community_list *list;
17672
17673 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
17674 EXTCOMMUNITY_LIST_MASTER);
17675 if (!list) {
17676 vty_out(vty, "%% Can't find extcommunity-list\n");
17677 return CMD_WARNING;
17678 }
17679
17680 extcommunity_list_show(vty, list);
17681
17682 return CMD_SUCCESS;
17683 }
17684
17685 /* Display community-list and extcommunity-list configuration. */
17686 static int community_list_config_write(struct vty *vty)
17687 {
17688 struct community_list *list;
17689 struct community_entry *entry;
17690 struct community_list_master *cm;
17691 int write = 0;
17692
17693 /* Community-list. */
17694 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
17695
17696 for (list = cm->num.head; list; list = list->next)
17697 for (entry = list->head; entry; entry = entry->next) {
17698 vty_out(vty,
17699 "bgp community-list %s seq %" PRId64 " %s %s\n",
17700 list->name, entry->seq,
17701 community_direct_str(entry->direct),
17702 community_list_config_str(entry));
17703 write++;
17704 }
17705 for (list = cm->str.head; list; list = list->next)
17706 for (entry = list->head; entry; entry = entry->next) {
17707 vty_out(vty,
17708 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
17709 entry->style == COMMUNITY_LIST_STANDARD
17710 ? "standard"
17711 : "expanded",
17712 list->name, entry->seq,
17713 community_direct_str(entry->direct),
17714 community_list_config_str(entry));
17715 write++;
17716 }
17717
17718 /* Extcommunity-list. */
17719 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
17720
17721 for (list = cm->num.head; list; list = list->next)
17722 for (entry = list->head; entry; entry = entry->next) {
17723 vty_out(vty,
17724 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
17725 list->name, entry->seq,
17726 community_direct_str(entry->direct),
17727 community_list_config_str(entry));
17728 write++;
17729 }
17730 for (list = cm->str.head; list; list = list->next)
17731 for (entry = list->head; entry; entry = entry->next) {
17732 vty_out(vty,
17733 "bgp extcommunity-list %s %s seq %" PRId64
17734 " %s %s\n",
17735 entry->style == EXTCOMMUNITY_LIST_STANDARD
17736 ? "standard"
17737 : "expanded",
17738 list->name, entry->seq,
17739 community_direct_str(entry->direct),
17740 community_list_config_str(entry));
17741 write++;
17742 }
17743
17744
17745 /* lcommunity-list. */
17746 cm = community_list_master_lookup(bgp_clist,
17747 LARGE_COMMUNITY_LIST_MASTER);
17748
17749 for (list = cm->num.head; list; list = list->next)
17750 for (entry = list->head; entry; entry = entry->next) {
17751 vty_out(vty,
17752 "bgp large-community-list %s seq %" PRId64
17753 " %s %s\n",
17754 list->name, entry->seq,
17755 community_direct_str(entry->direct),
17756 community_list_config_str(entry));
17757 write++;
17758 }
17759 for (list = cm->str.head; list; list = list->next)
17760 for (entry = list->head; entry; entry = entry->next) {
17761 vty_out(vty,
17762 "bgp large-community-list %s %s seq %" PRId64
17763 " %s %s\n",
17764
17765 entry->style == LARGE_COMMUNITY_LIST_STANDARD
17766 ? "standard"
17767 : "expanded",
17768 list->name, entry->seq, community_direct_str(entry->direct),
17769 community_list_config_str(entry));
17770 write++;
17771 }
17772
17773 return write;
17774 }
17775
17776 static struct cmd_node community_list_node = {
17777 COMMUNITY_LIST_NODE, "", 1 /* Export to vtysh. */
17778 };
17779
17780 static void community_list_vty(void)
17781 {
17782 install_node(&community_list_node, community_list_config_write);
17783
17784 /* Community-list. */
17785 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
17786 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
17787 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
17788 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
17789 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
17790 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
17791 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
17792 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
17793
17794 /* Extcommunity-list. */
17795 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
17796 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
17797 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
17798 install_element(CONFIG_NODE,
17799 &no_bgp_extcommunity_list_standard_all_list_cmd);
17800 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
17801 install_element(CONFIG_NODE,
17802 &no_bgp_extcommunity_list_expanded_all_list_cmd);
17803 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
17804 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
17805
17806 /* Large Community List */
17807 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
17808 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
17809 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
17810 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
17811 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
17812 install_element(CONFIG_NODE,
17813 &no_bgp_lcommunity_list_name_standard_all_cmd);
17814 install_element(CONFIG_NODE,
17815 &no_bgp_lcommunity_list_name_expanded_all_cmd);
17816 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
17817 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
17818 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
17819 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
17820 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
17821 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
17822 }