]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
bgpd: additional no bgp shutdown cli command
[mirror_frr.git] / bgpd / bgp_vty.c
1 /* BGP VTY interface.
2 * Copyright (C) 1996, 97, 98, 99, 2000 Kunihiro Ishiguro
3 *
4 * This file is part of GNU Zebra.
5 *
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
10 *
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include <zebra.h>
22
23 #include "command.h"
24 #include "lib/json.h"
25 #include "lib_errors.h"
26 #include "lib/zclient.h"
27 #include "prefix.h"
28 #include "plist.h"
29 #include "buffer.h"
30 #include "linklist.h"
31 #include "stream.h"
32 #include "thread.h"
33 #include "log.h"
34 #include "memory.h"
35 #include "lib_vty.h"
36 #include "hash.h"
37 #include "queue.h"
38 #include "filter.h"
39 #include "frrstr.h"
40
41 #include "bgpd/bgpd.h"
42 #include "bgpd/bgp_attr_evpn.h"
43 #include "bgpd/bgp_advertise.h"
44 #include "bgpd/bgp_attr.h"
45 #include "bgpd/bgp_aspath.h"
46 #include "bgpd/bgp_community.h"
47 #include "bgpd/bgp_ecommunity.h"
48 #include "bgpd/bgp_lcommunity.h"
49 #include "bgpd/bgp_damp.h"
50 #include "bgpd/bgp_debug.h"
51 #include "bgpd/bgp_errors.h"
52 #include "bgpd/bgp_fsm.h"
53 #include "bgpd/bgp_nexthop.h"
54 #include "bgpd/bgp_open.h"
55 #include "bgpd/bgp_regex.h"
56 #include "bgpd/bgp_route.h"
57 #include "bgpd/bgp_mplsvpn.h"
58 #include "bgpd/bgp_zebra.h"
59 #include "bgpd/bgp_table.h"
60 #include "bgpd/bgp_vty.h"
61 #include "bgpd/bgp_mpath.h"
62 #include "bgpd/bgp_packet.h"
63 #include "bgpd/bgp_updgrp.h"
64 #include "bgpd/bgp_bfd.h"
65 #include "bgpd/bgp_io.h"
66 #include "bgpd/bgp_evpn.h"
67 #include "bgpd/bgp_evpn_vty.h"
68 #include "bgpd/bgp_evpn_mh.h"
69 #include "bgpd/bgp_addpath.h"
70 #include "bgpd/bgp_mac.h"
71 #include "bgpd/bgp_flowspec.h"
72 #ifdef ENABLE_BGP_VNC
73 #include "bgpd/rfapi/bgp_rfapi_cfg.h"
74 #endif
75
76 FRR_CFG_DEFAULT_BOOL(BGP_IMPORT_CHECK,
77 {
78 .val_bool = false,
79 .match_profile = "traditional",
80 .match_version = "< 7.4",
81 },
82 { .val_bool = true },
83 )
84 FRR_CFG_DEFAULT_BOOL(BGP_SHOW_HOSTNAME,
85 { .val_bool = true, .match_profile = "datacenter", },
86 { .val_bool = false },
87 )
88 FRR_CFG_DEFAULT_BOOL(BGP_SHOW_NEXTHOP_HOSTNAME,
89 { .val_bool = true, .match_profile = "datacenter", },
90 { .val_bool = false },
91 )
92 FRR_CFG_DEFAULT_BOOL(BGP_LOG_NEIGHBOR_CHANGES,
93 { .val_bool = true, .match_profile = "datacenter", },
94 { .val_bool = false },
95 )
96 FRR_CFG_DEFAULT_BOOL(BGP_DETERMINISTIC_MED,
97 { .val_bool = true, .match_profile = "datacenter", },
98 { .val_bool = false },
99 )
100 FRR_CFG_DEFAULT_ULONG(BGP_CONNECT_RETRY,
101 { .val_ulong = 10, .match_profile = "datacenter", },
102 { .val_ulong = 120 },
103 )
104 FRR_CFG_DEFAULT_ULONG(BGP_HOLDTIME,
105 { .val_ulong = 9, .match_profile = "datacenter", },
106 { .val_ulong = 180 },
107 )
108 FRR_CFG_DEFAULT_ULONG(BGP_KEEPALIVE,
109 { .val_ulong = 3, .match_profile = "datacenter", },
110 { .val_ulong = 60 },
111 )
112 FRR_CFG_DEFAULT_BOOL(BGP_EBGP_REQUIRES_POLICY,
113 { .val_bool = false, .match_profile = "datacenter", },
114 { .val_bool = false, .match_version = "< 7.4", },
115 { .val_bool = true },
116 )
117
118 DEFINE_HOOK(bgp_inst_config_write,
119 (struct bgp *bgp, struct vty *vty),
120 (bgp, vty))
121
122 #define GR_NO_OPER \
123 "The Graceful Restart No Operation was executed as cmd same as previous one."
124 #define GR_INVALID \
125 "The Graceful Restart command used is not valid at this moment."
126 static struct peer_group *listen_range_exists(struct bgp *bgp,
127 struct prefix *range, int exact);
128
129 /* Show BGP peer's information. */
130 enum show_type {
131 show_all,
132 show_peer,
133 show_ipv4_all,
134 show_ipv6_all,
135 show_ipv4_peer,
136 show_ipv6_peer
137 };
138
139 static struct peer_group *listen_range_exists(struct bgp *bgp,
140 struct prefix *range, int exact);
141
142 static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
143 struct bgp *bgp,
144 bool use_json,
145 json_object *json);
146
147 static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
148 enum show_type type,
149 const char *ip_str,
150 afi_t afi, bool use_json);
151
152 static enum node_type bgp_node_type(afi_t afi, safi_t safi)
153 {
154 switch (afi) {
155 case AFI_IP:
156 switch (safi) {
157 case SAFI_UNICAST:
158 return BGP_IPV4_NODE;
159 case SAFI_MULTICAST:
160 return BGP_IPV4M_NODE;
161 case SAFI_LABELED_UNICAST:
162 return BGP_IPV4L_NODE;
163 case SAFI_MPLS_VPN:
164 return BGP_VPNV4_NODE;
165 case SAFI_FLOWSPEC:
166 return BGP_FLOWSPECV4_NODE;
167 default:
168 /* not expected */
169 return BGP_IPV4_NODE;
170 }
171 break;
172 case AFI_IP6:
173 switch (safi) {
174 case SAFI_UNICAST:
175 return BGP_IPV6_NODE;
176 case SAFI_MULTICAST:
177 return BGP_IPV6M_NODE;
178 case SAFI_LABELED_UNICAST:
179 return BGP_IPV6L_NODE;
180 case SAFI_MPLS_VPN:
181 return BGP_VPNV6_NODE;
182 case SAFI_FLOWSPEC:
183 return BGP_FLOWSPECV6_NODE;
184 default:
185 /* not expected */
186 return BGP_IPV4_NODE;
187 }
188 break;
189 case AFI_L2VPN:
190 return BGP_EVPN_NODE;
191 case AFI_UNSPEC:
192 case AFI_MAX:
193 // We should never be here but to clarify the switch statement..
194 return BGP_IPV4_NODE;
195 }
196
197 // Impossible to happen
198 return BGP_IPV4_NODE;
199 }
200
201 static const char *get_afi_safi_vty_str(afi_t afi, safi_t safi)
202 {
203 if (afi == AFI_IP && safi == SAFI_UNICAST)
204 return "IPv4 Unicast";
205 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
206 return "IPv4 Multicast";
207 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
208 return "IPv4 Labeled Unicast";
209 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
210 return "IPv4 VPN";
211 else if (afi == AFI_IP && safi == SAFI_ENCAP)
212 return "IPv4 Encap";
213 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
214 return "IPv4 Flowspec";
215 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
216 return "IPv6 Unicast";
217 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
218 return "IPv6 Multicast";
219 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
220 return "IPv6 Labeled Unicast";
221 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
222 return "IPv6 VPN";
223 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
224 return "IPv6 Encap";
225 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
226 return "IPv6 Flowspec";
227 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
228 return "L2VPN EVPN";
229 else
230 return "Unknown";
231 }
232
233 /*
234 * Please note that we have intentionally camelCased
235 * the return strings here. So if you want
236 * to use this function, please ensure you
237 * are doing this within json output
238 */
239 static const char *get_afi_safi_json_str(afi_t afi, safi_t safi)
240 {
241 if (afi == AFI_IP && safi == SAFI_UNICAST)
242 return "ipv4Unicast";
243 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
244 return "ipv4Multicast";
245 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
246 return "ipv4LabeledUnicast";
247 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
248 return "ipv4Vpn";
249 else if (afi == AFI_IP && safi == SAFI_ENCAP)
250 return "ipv4Encap";
251 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
252 return "ipv4Flowspec";
253 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
254 return "ipv6Unicast";
255 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
256 return "ipv6Multicast";
257 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
258 return "ipv6LabeledUnicast";
259 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
260 return "ipv6Vpn";
261 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
262 return "ipv6Encap";
263 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
264 return "ipv6Flowspec";
265 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
266 return "l2VpnEvpn";
267 else
268 return "Unknown";
269 }
270
271 /* Utility function to get address family from current node. */
272 afi_t bgp_node_afi(struct vty *vty)
273 {
274 afi_t afi;
275 switch (vty->node) {
276 case BGP_IPV6_NODE:
277 case BGP_IPV6M_NODE:
278 case BGP_IPV6L_NODE:
279 case BGP_VPNV6_NODE:
280 case BGP_FLOWSPECV6_NODE:
281 afi = AFI_IP6;
282 break;
283 case BGP_EVPN_NODE:
284 afi = AFI_L2VPN;
285 break;
286 default:
287 afi = AFI_IP;
288 break;
289 }
290 return afi;
291 }
292
293 /* Utility function to get subsequent address family from current
294 node. */
295 safi_t bgp_node_safi(struct vty *vty)
296 {
297 safi_t safi;
298 switch (vty->node) {
299 case BGP_VPNV4_NODE:
300 case BGP_VPNV6_NODE:
301 safi = SAFI_MPLS_VPN;
302 break;
303 case BGP_IPV4M_NODE:
304 case BGP_IPV6M_NODE:
305 safi = SAFI_MULTICAST;
306 break;
307 case BGP_EVPN_NODE:
308 safi = SAFI_EVPN;
309 break;
310 case BGP_IPV4L_NODE:
311 case BGP_IPV6L_NODE:
312 safi = SAFI_LABELED_UNICAST;
313 break;
314 case BGP_FLOWSPECV4_NODE:
315 case BGP_FLOWSPECV6_NODE:
316 safi = SAFI_FLOWSPEC;
317 break;
318 default:
319 safi = SAFI_UNICAST;
320 break;
321 }
322 return safi;
323 }
324
325 /**
326 * Converts an AFI in string form to afi_t
327 *
328 * @param afi string, one of
329 * - "ipv4"
330 * - "ipv6"
331 * - "l2vpn"
332 * @return the corresponding afi_t
333 */
334 afi_t bgp_vty_afi_from_str(const char *afi_str)
335 {
336 afi_t afi = AFI_MAX; /* unknown */
337 if (strmatch(afi_str, "ipv4"))
338 afi = AFI_IP;
339 else if (strmatch(afi_str, "ipv6"))
340 afi = AFI_IP6;
341 else if (strmatch(afi_str, "l2vpn"))
342 afi = AFI_L2VPN;
343 return afi;
344 }
345
346 int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
347 afi_t *afi)
348 {
349 int ret = 0;
350 if (argv_find(argv, argc, "ipv4", index)) {
351 ret = 1;
352 if (afi)
353 *afi = AFI_IP;
354 } else if (argv_find(argv, argc, "ipv6", index)) {
355 ret = 1;
356 if (afi)
357 *afi = AFI_IP6;
358 } else if (argv_find(argv, argc, "l2vpn", index)) {
359 ret = 1;
360 if (afi)
361 *afi = AFI_L2VPN;
362 }
363 return ret;
364 }
365
366 /* supports <unicast|multicast|vpn|labeled-unicast> */
367 safi_t bgp_vty_safi_from_str(const char *safi_str)
368 {
369 safi_t safi = SAFI_MAX; /* unknown */
370 if (strmatch(safi_str, "multicast"))
371 safi = SAFI_MULTICAST;
372 else if (strmatch(safi_str, "unicast"))
373 safi = SAFI_UNICAST;
374 else if (strmatch(safi_str, "vpn"))
375 safi = SAFI_MPLS_VPN;
376 else if (strmatch(safi_str, "evpn"))
377 safi = SAFI_EVPN;
378 else if (strmatch(safi_str, "labeled-unicast"))
379 safi = SAFI_LABELED_UNICAST;
380 else if (strmatch(safi_str, "flowspec"))
381 safi = SAFI_FLOWSPEC;
382 return safi;
383 }
384
385 int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
386 safi_t *safi)
387 {
388 int ret = 0;
389 if (argv_find(argv, argc, "unicast", index)) {
390 ret = 1;
391 if (safi)
392 *safi = SAFI_UNICAST;
393 } else if (argv_find(argv, argc, "multicast", index)) {
394 ret = 1;
395 if (safi)
396 *safi = SAFI_MULTICAST;
397 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
398 ret = 1;
399 if (safi)
400 *safi = SAFI_LABELED_UNICAST;
401 } else if (argv_find(argv, argc, "vpn", index)) {
402 ret = 1;
403 if (safi)
404 *safi = SAFI_MPLS_VPN;
405 } else if (argv_find(argv, argc, "evpn", index)) {
406 ret = 1;
407 if (safi)
408 *safi = SAFI_EVPN;
409 } else if (argv_find(argv, argc, "flowspec", index)) {
410 ret = 1;
411 if (safi)
412 *safi = SAFI_FLOWSPEC;
413 }
414 return ret;
415 }
416
417 int bgp_get_vty(struct bgp **bgp, as_t *as, const char *name,
418 enum bgp_instance_type inst_type)
419 {
420 int ret = bgp_get(bgp, as, name, inst_type);
421
422 if (ret == BGP_CREATED) {
423 bgp_timers_set(*bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
424 DFLT_BGP_CONNECT_RETRY);
425
426 if (DFLT_BGP_IMPORT_CHECK)
427 SET_FLAG((*bgp)->flags, BGP_FLAG_IMPORT_CHECK);
428 if (DFLT_BGP_SHOW_HOSTNAME)
429 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_HOSTNAME);
430 if (DFLT_BGP_SHOW_NEXTHOP_HOSTNAME)
431 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
432 if (DFLT_BGP_LOG_NEIGHBOR_CHANGES)
433 SET_FLAG((*bgp)->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
434 if (DFLT_BGP_DETERMINISTIC_MED)
435 SET_FLAG((*bgp)->flags, BGP_FLAG_DETERMINISTIC_MED);
436 if (DFLT_BGP_EBGP_REQUIRES_POLICY)
437 SET_FLAG((*bgp)->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
438
439 ret = BGP_SUCCESS;
440 }
441 return ret;
442 }
443
444 /*
445 * bgp_vty_find_and_parse_afi_safi_bgp
446 *
447 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
448 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
449 * to appropriate values for the calling function. This is to allow the
450 * calling function to make decisions appropriate for the show command
451 * that is being parsed.
452 *
453 * The show commands are generally of the form:
454 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
455 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
456 *
457 * Since we use argv_find if the show command in particular doesn't have:
458 * [ip]
459 * [<view|vrf> VIEWVRFNAME]
460 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
461 * The command parsing should still be ok.
462 *
463 * vty -> The vty for the command so we can output some useful data in
464 * the event of a parse error in the vrf.
465 * argv -> The command tokens
466 * argc -> How many command tokens we have
467 * idx -> The current place in the command, generally should be 0 for this
468 * function
469 * afi -> The parsed afi if it was included in the show command, returned here
470 * safi -> The parsed safi if it was included in the show command, returned here
471 * bgp -> Pointer to the bgp data structure we need to fill in.
472 * use_json -> json is configured or not
473 *
474 * The function returns the correct location in the parse tree for the
475 * last token found.
476 *
477 * Returns 0 for failure to parse correctly, else the idx position of where
478 * it found the last token.
479 */
480 int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
481 struct cmd_token **argv, int argc,
482 int *idx, afi_t *afi, safi_t *safi,
483 struct bgp **bgp, bool use_json)
484 {
485 char *vrf_name = NULL;
486
487 assert(afi);
488 assert(safi);
489 assert(bgp);
490
491 if (argv_find(argv, argc, "ip", idx))
492 *afi = AFI_IP;
493
494 if (argv_find(argv, argc, "view", idx))
495 vrf_name = argv[*idx + 1]->arg;
496 else if (argv_find(argv, argc, "vrf", idx)) {
497 vrf_name = argv[*idx + 1]->arg;
498 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
499 vrf_name = NULL;
500 }
501 if (vrf_name) {
502 if (strmatch(vrf_name, "all"))
503 *bgp = NULL;
504 else {
505 *bgp = bgp_lookup_by_name(vrf_name);
506 if (!*bgp) {
507 if (use_json) {
508 json_object *json = NULL;
509 json = json_object_new_object();
510 json_object_string_add(
511 json, "warning",
512 "View/Vrf is unknown");
513 vty_out(vty, "%s\n",
514 json_object_to_json_string_ext(json,
515 JSON_C_TO_STRING_PRETTY));
516 json_object_free(json);
517 }
518 else
519 vty_out(vty, "View/Vrf %s is unknown\n",
520 vrf_name);
521 *idx = 0;
522 return 0;
523 }
524 }
525 } else {
526 *bgp = bgp_get_default();
527 if (!*bgp) {
528 if (use_json) {
529 json_object *json = NULL;
530 json = json_object_new_object();
531 json_object_string_add(
532 json, "warning",
533 "Default BGP instance not found");
534 vty_out(vty, "%s\n",
535 json_object_to_json_string_ext(json,
536 JSON_C_TO_STRING_PRETTY));
537 json_object_free(json);
538 }
539 else
540 vty_out(vty,
541 "Default BGP instance not found\n");
542 *idx = 0;
543 return 0;
544 }
545 }
546
547 if (argv_find_and_parse_afi(argv, argc, idx, afi))
548 argv_find_and_parse_safi(argv, argc, idx, safi);
549
550 *idx += 1;
551 return *idx;
552 }
553
554 static bool peer_address_self_check(struct bgp *bgp, union sockunion *su)
555 {
556 struct interface *ifp = NULL;
557
558 if (su->sa.sa_family == AF_INET)
559 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
560 else if (su->sa.sa_family == AF_INET6)
561 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
562 su->sin6.sin6_scope_id,
563 bgp->vrf_id);
564
565 if (ifp)
566 return true;
567
568 return false;
569 }
570
571 /* Utility function for looking up peer from VTY. */
572 /* This is used only for configuration, so disallow if attempted on
573 * a dynamic neighbor.
574 */
575 static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
576 {
577 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
578 int ret;
579 union sockunion su;
580 struct peer *peer;
581
582 if (!bgp) {
583 return NULL;
584 }
585
586 ret = str2sockunion(ip_str, &su);
587 if (ret < 0) {
588 peer = peer_lookup_by_conf_if(bgp, ip_str);
589 if (!peer) {
590 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
591 == NULL) {
592 vty_out(vty,
593 "%% Malformed address or name: %s\n",
594 ip_str);
595 return NULL;
596 }
597 }
598 } else {
599 peer = peer_lookup(bgp, &su);
600 if (!peer) {
601 vty_out(vty,
602 "%% Specify remote-as or peer-group commands first\n");
603 return NULL;
604 }
605 if (peer_dynamic_neighbor(peer)) {
606 vty_out(vty,
607 "%% Operation not allowed on a dynamic neighbor\n");
608 return NULL;
609 }
610 }
611 return peer;
612 }
613
614 /* Utility function for looking up peer or peer group. */
615 /* This is used only for configuration, so disallow if attempted on
616 * a dynamic neighbor.
617 */
618 struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
619 {
620 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
621 int ret;
622 union sockunion su;
623 struct peer *peer = NULL;
624 struct peer_group *group = NULL;
625
626 if (!bgp) {
627 return NULL;
628 }
629
630 ret = str2sockunion(peer_str, &su);
631 if (ret == 0) {
632 /* IP address, locate peer. */
633 peer = peer_lookup(bgp, &su);
634 } else {
635 /* Not IP, could match either peer configured on interface or a
636 * group. */
637 peer = peer_lookup_by_conf_if(bgp, peer_str);
638 if (!peer)
639 group = peer_group_lookup(bgp, peer_str);
640 }
641
642 if (peer) {
643 if (peer_dynamic_neighbor(peer)) {
644 vty_out(vty,
645 "%% Operation not allowed on a dynamic neighbor\n");
646 return NULL;
647 }
648
649 return peer;
650 }
651
652 if (group)
653 return group->conf;
654
655 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
656
657 return NULL;
658 }
659
660 int bgp_vty_return(struct vty *vty, int ret)
661 {
662 const char *str = NULL;
663
664 switch (ret) {
665 case BGP_ERR_INVALID_VALUE:
666 str = "Invalid value";
667 break;
668 case BGP_ERR_INVALID_FLAG:
669 str = "Invalid flag";
670 break;
671 case BGP_ERR_PEER_GROUP_SHUTDOWN:
672 str = "Peer-group has been shutdown. Activate the peer-group first";
673 break;
674 case BGP_ERR_PEER_FLAG_CONFLICT:
675 str = "Can't set override-capability and strict-capability-match at the same time";
676 break;
677 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
678 str = "Specify remote-as or peer-group remote AS first";
679 break;
680 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
681 str = "Cannot change the peer-group. Deconfigure first";
682 break;
683 case BGP_ERR_PEER_GROUP_MISMATCH:
684 str = "Peer is not a member of this peer-group";
685 break;
686 case BGP_ERR_PEER_FILTER_CONFLICT:
687 str = "Prefix/distribute list can not co-exist";
688 break;
689 case BGP_ERR_NOT_INTERNAL_PEER:
690 str = "Invalid command. Not an internal neighbor";
691 break;
692 case BGP_ERR_REMOVE_PRIVATE_AS:
693 str = "remove-private-AS cannot be configured for IBGP peers";
694 break;
695 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
696 str = "Local-AS allowed only for EBGP peers";
697 break;
698 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
699 str = "Cannot have local-as same as BGP AS number";
700 break;
701 case BGP_ERR_TCPSIG_FAILED:
702 str = "Error while applying TCP-Sig to session(s)";
703 break;
704 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
705 str = "ebgp-multihop and ttl-security cannot be configured together";
706 break;
707 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
708 str = "ttl-security only allowed for EBGP peers";
709 break;
710 case BGP_ERR_AS_OVERRIDE:
711 str = "as-override cannot be configured for IBGP peers";
712 break;
713 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
714 str = "Invalid limit for number of dynamic neighbors";
715 break;
716 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
717 str = "Dynamic neighbor listen range already exists";
718 break;
719 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
720 str = "Operation not allowed on a dynamic neighbor";
721 break;
722 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
723 str = "Operation not allowed on a directly connected neighbor";
724 break;
725 case BGP_ERR_PEER_SAFI_CONFLICT:
726 str = GR_INVALID;
727 break;
728 case BGP_ERR_GR_INVALID_CMD:
729 str = "The Graceful Restart command used is not valid at this moment.";
730 break;
731 case BGP_ERR_GR_OPERATION_FAILED:
732 str = "The Graceful Restart Operation failed due to an err.";
733 break;
734 case BGP_GR_NO_OPERATION:
735 str = GR_NO_OPER;
736 break;
737 }
738 if (str) {
739 vty_out(vty, "%% %s\n", str);
740 return CMD_WARNING_CONFIG_FAILED;
741 }
742 return CMD_SUCCESS;
743 }
744
745 /* BGP clear sort. */
746 enum clear_sort {
747 clear_all,
748 clear_peer,
749 clear_group,
750 clear_external,
751 clear_as
752 };
753
754 static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
755 safi_t safi, int error)
756 {
757 switch (error) {
758 case BGP_ERR_AF_UNCONFIGURED:
759 vty_out(vty,
760 "%%BGP: Enable %s address family for the neighbor %s\n",
761 get_afi_safi_str(afi, safi, false), peer->host);
762 break;
763 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
764 vty_out(vty,
765 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
766 peer->host);
767 break;
768 default:
769 break;
770 }
771 }
772
773 static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi,
774 struct listnode **nnode, enum bgp_clear_type stype)
775 {
776 int ret = 0;
777
778 /* if afi/.safi not specified, spin thru all of them */
779 if ((afi == AFI_UNSPEC) && (safi == SAFI_UNSPEC)) {
780 afi_t tmp_afi;
781 safi_t tmp_safi;
782
783 FOREACH_AFI_SAFI (tmp_afi, tmp_safi) {
784 if (!peer->afc[tmp_afi][tmp_safi])
785 continue;
786
787 if (stype == BGP_CLEAR_SOFT_NONE)
788 ret = peer_clear(peer, nnode);
789 else
790 ret = peer_clear_soft(peer, tmp_afi, tmp_safi,
791 stype);
792 }
793 /* if afi specified and safi not, spin thru safis on this afi */
794 } else if (safi == SAFI_UNSPEC) {
795 safi_t tmp_safi;
796
797 for (tmp_safi = SAFI_UNICAST;
798 tmp_safi < SAFI_MAX; tmp_safi++) {
799 if (!peer->afc[afi][tmp_safi])
800 continue;
801
802 if (stype == BGP_CLEAR_SOFT_NONE)
803 ret = peer_clear(peer, nnode);
804 else
805 ret = peer_clear_soft(peer, afi,
806 tmp_safi, stype);
807 }
808 /* both afi/safi specified, let the caller know if not defined */
809 } else {
810 if (!peer->afc[afi][safi])
811 return 1;
812
813 if (stype == BGP_CLEAR_SOFT_NONE)
814 ret = peer_clear(peer, nnode);
815 else
816 ret = peer_clear_soft(peer, afi, safi, stype);
817 }
818
819 return ret;
820 }
821
822 /* `clear ip bgp' functions. */
823 static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
824 enum clear_sort sort, enum bgp_clear_type stype,
825 const char *arg)
826 {
827 int ret = 0;
828 bool found = false;
829 struct peer *peer;
830
831 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
832
833 /* Clear all neighbors. */
834 /*
835 * Pass along pointer to next node to peer_clear() when walking all
836 * nodes on the BGP instance as that may get freed if it is a
837 * doppelganger
838 */
839 if (sort == clear_all) {
840 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
841
842 bgp_peer_gr_flags_update(peer);
843
844 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
845 gr_router_detected = true;
846
847 ret = bgp_peer_clear(peer, afi, safi, &nnode,
848 stype);
849
850 if (ret < 0)
851 bgp_clear_vty_error(vty, peer, afi, safi, ret);
852 }
853
854 if (gr_router_detected
855 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
856 bgp_zebra_send_capabilities(bgp, false);
857 } else if (!gr_router_detected
858 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
859 bgp_zebra_send_capabilities(bgp, true);
860 }
861
862 /* This is to apply read-only mode on this clear. */
863 if (stype == BGP_CLEAR_SOFT_NONE)
864 bgp->update_delay_over = 0;
865
866 return CMD_SUCCESS;
867 }
868
869 /* Clear specified neighbor. */
870 if (sort == clear_peer) {
871 union sockunion su;
872
873 /* Make sockunion for lookup. */
874 ret = str2sockunion(arg, &su);
875 if (ret < 0) {
876 peer = peer_lookup_by_conf_if(bgp, arg);
877 if (!peer) {
878 peer = peer_lookup_by_hostname(bgp, arg);
879 if (!peer) {
880 vty_out(vty,
881 "Malformed address or name: %s\n",
882 arg);
883 return CMD_WARNING;
884 }
885 }
886 } else {
887 peer = peer_lookup(bgp, &su);
888 if (!peer) {
889 vty_out(vty,
890 "%%BGP: Unknown neighbor - \"%s\"\n",
891 arg);
892 return CMD_WARNING;
893 }
894 }
895
896 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
897 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
898
899 ret = bgp_peer_clear(peer, afi, safi, NULL, stype);
900
901 /* if afi/safi not defined for this peer, let caller know */
902 if (ret == 1)
903 ret = BGP_ERR_AF_UNCONFIGURED;
904
905 if (ret < 0)
906 bgp_clear_vty_error(vty, peer, afi, safi, ret);
907
908 return CMD_SUCCESS;
909 }
910
911 /* Clear all neighbors belonging to a specific peer-group. */
912 if (sort == clear_group) {
913 struct peer_group *group;
914
915 group = peer_group_lookup(bgp, arg);
916 if (!group) {
917 vty_out(vty, "%%BGP: No such peer-group %s\n", arg);
918 return CMD_WARNING;
919 }
920
921 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
922 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
923
924 if (ret < 0)
925 bgp_clear_vty_error(vty, peer, afi, safi, ret);
926 else
927 found = true;
928 }
929
930 if (!found)
931 vty_out(vty,
932 "%%BGP: No %s peer belonging to peer-group %s is configured\n",
933 get_afi_safi_str(afi, safi, false), arg);
934
935 return CMD_SUCCESS;
936 }
937
938 /* Clear all external (eBGP) neighbors. */
939 if (sort == clear_external) {
940 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
941 if (peer->sort == BGP_PEER_IBGP)
942 continue;
943
944 bgp_peer_gr_flags_update(peer);
945
946 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
947 gr_router_detected = true;
948
949 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
950
951 if (ret < 0)
952 bgp_clear_vty_error(vty, peer, afi, safi, ret);
953 else
954 found = true;
955 }
956
957 if (gr_router_detected
958 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
959 bgp_zebra_send_capabilities(bgp, false);
960 } else if (!gr_router_detected
961 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
962 bgp_zebra_send_capabilities(bgp, true);
963 }
964
965 if (!found)
966 vty_out(vty,
967 "%%BGP: No external %s peer is configured\n",
968 get_afi_safi_str(afi, safi, false));
969
970 return CMD_SUCCESS;
971 }
972
973 /* Clear all neighbors belonging to a specific AS. */
974 if (sort == clear_as) {
975 as_t as = strtoul(arg, NULL, 10);
976
977 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
978 if (peer->as != as)
979 continue;
980
981 bgp_peer_gr_flags_update(peer);
982
983 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
984 gr_router_detected = true;
985
986 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
987
988 if (ret < 0)
989 bgp_clear_vty_error(vty, peer, afi, safi, ret);
990 else
991 found = true;
992 }
993
994 if (gr_router_detected
995 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
996 bgp_zebra_send_capabilities(bgp, false);
997 } else if (!gr_router_detected
998 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
999 bgp_zebra_send_capabilities(bgp, true);
1000 }
1001
1002 if (!found)
1003 vty_out(vty,
1004 "%%BGP: No %s peer is configured with AS %s\n",
1005 get_afi_safi_str(afi, safi, false), arg);
1006
1007 return CMD_SUCCESS;
1008 }
1009
1010 return CMD_SUCCESS;
1011 }
1012
1013 static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
1014 safi_t safi, enum clear_sort sort,
1015 enum bgp_clear_type stype, const char *arg)
1016 {
1017 struct bgp *bgp;
1018
1019 /* BGP structure lookup. */
1020 if (name) {
1021 bgp = bgp_lookup_by_name(name);
1022 if (bgp == NULL) {
1023 vty_out(vty, "Can't find BGP instance %s\n", name);
1024 return CMD_WARNING;
1025 }
1026 } else {
1027 bgp = bgp_get_default();
1028 if (bgp == NULL) {
1029 vty_out(vty, "No BGP process is configured\n");
1030 return CMD_WARNING;
1031 }
1032 }
1033
1034 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
1035 }
1036
1037 /* clear soft inbound */
1038 static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
1039 {
1040 afi_t afi;
1041 safi_t safi;
1042
1043 FOREACH_AFI_SAFI (afi, safi)
1044 bgp_clear_vty(vty, name, afi, safi, clear_all,
1045 BGP_CLEAR_SOFT_IN, NULL);
1046 }
1047
1048 /* clear soft outbound */
1049 static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
1050 {
1051 afi_t afi;
1052 safi_t safi;
1053
1054 FOREACH_AFI_SAFI (afi, safi)
1055 bgp_clear_vty(vty, name, afi, safi, clear_all,
1056 BGP_CLEAR_SOFT_OUT, NULL);
1057 }
1058
1059
1060 #ifndef VTYSH_EXTRACT_PL
1061 #include "bgpd/bgp_vty_clippy.c"
1062 #endif
1063
1064 DEFUN_HIDDEN (bgp_local_mac,
1065 bgp_local_mac_cmd,
1066 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
1067 BGP_STR
1068 "Local MAC config\n"
1069 "VxLAN Network Identifier\n"
1070 "VNI number\n"
1071 "local mac\n"
1072 "mac address\n"
1073 "mac-mobility sequence\n"
1074 "seq number\n")
1075 {
1076 int rv;
1077 vni_t vni;
1078 struct ethaddr mac;
1079 struct ipaddr ip;
1080 uint32_t seq;
1081 struct bgp *bgp;
1082
1083 vni = strtoul(argv[3]->arg, NULL, 10);
1084 if (!prefix_str2mac(argv[5]->arg, &mac)) {
1085 vty_out(vty, "%% Malformed MAC address\n");
1086 return CMD_WARNING;
1087 }
1088 memset(&ip, 0, sizeof(ip));
1089 seq = strtoul(argv[7]->arg, NULL, 10);
1090
1091 bgp = bgp_get_default();
1092 if (!bgp) {
1093 vty_out(vty, "Default BGP instance is not there\n");
1094 return CMD_WARNING;
1095 }
1096
1097 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq,
1098 zero_esi);
1099 if (rv < 0) {
1100 vty_out(vty, "Internal error\n");
1101 return CMD_WARNING;
1102 }
1103
1104 return CMD_SUCCESS;
1105 }
1106
1107 DEFUN_HIDDEN (no_bgp_local_mac,
1108 no_bgp_local_mac_cmd,
1109 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
1110 NO_STR
1111 BGP_STR
1112 "Local MAC config\n"
1113 "VxLAN Network Identifier\n"
1114 "VNI number\n"
1115 "local mac\n"
1116 "mac address\n")
1117 {
1118 int rv;
1119 vni_t vni;
1120 struct ethaddr mac;
1121 struct ipaddr ip;
1122 struct bgp *bgp;
1123
1124 vni = strtoul(argv[4]->arg, NULL, 10);
1125 if (!prefix_str2mac(argv[6]->arg, &mac)) {
1126 vty_out(vty, "%% Malformed MAC address\n");
1127 return CMD_WARNING;
1128 }
1129 memset(&ip, 0, sizeof(ip));
1130
1131 bgp = bgp_get_default();
1132 if (!bgp) {
1133 vty_out(vty, "Default BGP instance is not there\n");
1134 return CMD_WARNING;
1135 }
1136
1137 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
1138 if (rv < 0) {
1139 vty_out(vty, "Internal error\n");
1140 return CMD_WARNING;
1141 }
1142
1143 return CMD_SUCCESS;
1144 }
1145
1146 DEFUN (no_synchronization,
1147 no_synchronization_cmd,
1148 "no synchronization",
1149 NO_STR
1150 "Perform IGP synchronization\n")
1151 {
1152 return CMD_SUCCESS;
1153 }
1154
1155 DEFUN (no_auto_summary,
1156 no_auto_summary_cmd,
1157 "no auto-summary",
1158 NO_STR
1159 "Enable automatic network number summarization\n")
1160 {
1161 return CMD_SUCCESS;
1162 }
1163
1164 /* "router bgp" commands. */
1165 DEFUN_NOSH (router_bgp,
1166 router_bgp_cmd,
1167 "router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1168 ROUTER_STR
1169 BGP_STR
1170 AS_STR
1171 BGP_INSTANCE_HELP_STR)
1172 {
1173 int idx_asn = 2;
1174 int idx_view_vrf = 3;
1175 int idx_vrf = 4;
1176 int is_new_bgp = 0;
1177 int ret;
1178 as_t as;
1179 struct bgp *bgp;
1180 const char *name = NULL;
1181 enum bgp_instance_type inst_type;
1182
1183 // "router bgp" without an ASN
1184 if (argc == 2) {
1185 // Pending: Make VRF option available for ASN less config
1186 bgp = bgp_get_default();
1187
1188 if (bgp == NULL) {
1189 vty_out(vty, "%% No BGP process is configured\n");
1190 return CMD_WARNING_CONFIG_FAILED;
1191 }
1192
1193 if (listcount(bm->bgp) > 1) {
1194 vty_out(vty, "%% Please specify ASN and VRF\n");
1195 return CMD_WARNING_CONFIG_FAILED;
1196 }
1197 }
1198
1199 // "router bgp X"
1200 else {
1201 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1202
1203 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1204 if (argc > 3) {
1205 name = argv[idx_vrf]->arg;
1206
1207 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1208 if (strmatch(name, VRF_DEFAULT_NAME))
1209 name = NULL;
1210 else
1211 inst_type = BGP_INSTANCE_TYPE_VRF;
1212 } else if (!strcmp(argv[idx_view_vrf]->text, "view"))
1213 inst_type = BGP_INSTANCE_TYPE_VIEW;
1214 }
1215
1216 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1217 is_new_bgp = (bgp_lookup(as, name) == NULL);
1218
1219 ret = bgp_get_vty(&bgp, &as, name, inst_type);
1220 switch (ret) {
1221 case BGP_ERR_AS_MISMATCH:
1222 vty_out(vty, "BGP is already running; AS is %u\n", as);
1223 return CMD_WARNING_CONFIG_FAILED;
1224 case BGP_ERR_INSTANCE_MISMATCH:
1225 vty_out(vty,
1226 "BGP instance name and AS number mismatch\n");
1227 vty_out(vty,
1228 "BGP instance is already running; AS is %u\n",
1229 as);
1230 return CMD_WARNING_CONFIG_FAILED;
1231 }
1232
1233 /*
1234 * If we just instantiated the default instance, complete
1235 * any pending VRF-VPN leaking that was configured via
1236 * earlier "router bgp X vrf FOO" blocks.
1237 */
1238 if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1239 vpn_leak_postchange_all();
1240
1241 if (inst_type == BGP_INSTANCE_TYPE_VRF)
1242 bgp_vpn_leak_export(bgp);
1243 /* Pending: handle when user tries to change a view to vrf n vv.
1244 */
1245 }
1246
1247 /* unset the auto created flag as the user config is now present */
1248 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
1249 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1250
1251 return CMD_SUCCESS;
1252 }
1253
1254 /* "no router bgp" commands. */
1255 DEFUN (no_router_bgp,
1256 no_router_bgp_cmd,
1257 "no router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1258 NO_STR
1259 ROUTER_STR
1260 BGP_STR
1261 AS_STR
1262 BGP_INSTANCE_HELP_STR)
1263 {
1264 int idx_asn = 3;
1265 int idx_vrf = 5;
1266 as_t as;
1267 struct bgp *bgp;
1268 const char *name = NULL;
1269
1270 // "no router bgp" without an ASN
1271 if (argc == 3) {
1272 // Pending: Make VRF option available for ASN less config
1273 bgp = bgp_get_default();
1274
1275 if (bgp == NULL) {
1276 vty_out(vty, "%% No BGP process is configured\n");
1277 return CMD_WARNING_CONFIG_FAILED;
1278 }
1279
1280 if (listcount(bm->bgp) > 1) {
1281 vty_out(vty, "%% Please specify ASN and VRF\n");
1282 return CMD_WARNING_CONFIG_FAILED;
1283 }
1284
1285 if (bgp->l3vni) {
1286 vty_out(vty, "%% Please unconfigure l3vni %u",
1287 bgp->l3vni);
1288 return CMD_WARNING_CONFIG_FAILED;
1289 }
1290 } else {
1291 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1292
1293 if (argc > 4)
1294 name = argv[idx_vrf]->arg;
1295
1296 /* Lookup bgp structure. */
1297 bgp = bgp_lookup(as, name);
1298 if (!bgp) {
1299 vty_out(vty, "%% Can't find BGP instance\n");
1300 return CMD_WARNING_CONFIG_FAILED;
1301 }
1302
1303 if (bgp->l3vni) {
1304 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1305 bgp->l3vni);
1306 return CMD_WARNING_CONFIG_FAILED;
1307 }
1308
1309 /* Cannot delete default instance if vrf instances exist */
1310 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
1311 struct listnode *node;
1312 struct bgp *tmp_bgp;
1313
1314 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, tmp_bgp)) {
1315 if (tmp_bgp->inst_type
1316 == BGP_INSTANCE_TYPE_VRF) {
1317 vty_out(vty,
1318 "%% Cannot delete default BGP instance. Dependent VRF instances exist\n");
1319 return CMD_WARNING_CONFIG_FAILED;
1320 }
1321 }
1322 }
1323 }
1324
1325 if (bgp_vpn_leak_unimport(bgp, vty))
1326 return CMD_WARNING_CONFIG_FAILED;
1327
1328 bgp_delete(bgp);
1329
1330 return CMD_SUCCESS;
1331 }
1332
1333
1334 /* BGP router-id. */
1335
1336 DEFPY (bgp_router_id,
1337 bgp_router_id_cmd,
1338 "bgp router-id A.B.C.D",
1339 BGP_STR
1340 "Override configured router identifier\n"
1341 "Manually configured router identifier\n")
1342 {
1343 VTY_DECLVAR_CONTEXT(bgp, bgp);
1344 bgp_router_id_static_set(bgp, router_id);
1345 return CMD_SUCCESS;
1346 }
1347
1348 DEFPY (no_bgp_router_id,
1349 no_bgp_router_id_cmd,
1350 "no bgp router-id [A.B.C.D]",
1351 NO_STR
1352 BGP_STR
1353 "Override configured router identifier\n"
1354 "Manually configured router identifier\n")
1355 {
1356 VTY_DECLVAR_CONTEXT(bgp, bgp);
1357
1358 if (router_id_str) {
1359 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1360 vty_out(vty, "%% BGP router-id doesn't match\n");
1361 return CMD_WARNING_CONFIG_FAILED;
1362 }
1363 }
1364
1365 router_id.s_addr = 0;
1366 bgp_router_id_static_set(bgp, router_id);
1367
1368 return CMD_SUCCESS;
1369 }
1370
1371
1372 /* BGP Cluster ID. */
1373 DEFUN (bgp_cluster_id,
1374 bgp_cluster_id_cmd,
1375 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1376 BGP_STR
1377 "Configure Route-Reflector Cluster-id\n"
1378 "Route-Reflector Cluster-id in IP address format\n"
1379 "Route-Reflector Cluster-id as 32 bit quantity\n")
1380 {
1381 VTY_DECLVAR_CONTEXT(bgp, bgp);
1382 int idx_ipv4 = 2;
1383 int ret;
1384 struct in_addr cluster;
1385
1386 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1387 if (!ret) {
1388 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1389 return CMD_WARNING_CONFIG_FAILED;
1390 }
1391
1392 bgp_cluster_id_set(bgp, &cluster);
1393 bgp_clear_star_soft_out(vty, bgp->name);
1394
1395 return CMD_SUCCESS;
1396 }
1397
1398 DEFUN (no_bgp_cluster_id,
1399 no_bgp_cluster_id_cmd,
1400 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1401 NO_STR
1402 BGP_STR
1403 "Configure Route-Reflector Cluster-id\n"
1404 "Route-Reflector Cluster-id in IP address format\n"
1405 "Route-Reflector Cluster-id as 32 bit quantity\n")
1406 {
1407 VTY_DECLVAR_CONTEXT(bgp, bgp);
1408 bgp_cluster_id_unset(bgp);
1409 bgp_clear_star_soft_out(vty, bgp->name);
1410
1411 return CMD_SUCCESS;
1412 }
1413
1414 DEFUN (bgp_confederation_identifier,
1415 bgp_confederation_identifier_cmd,
1416 "bgp confederation identifier (1-4294967295)",
1417 "BGP specific commands\n"
1418 "AS confederation parameters\n"
1419 "AS number\n"
1420 "Set routing domain confederation AS\n")
1421 {
1422 VTY_DECLVAR_CONTEXT(bgp, bgp);
1423 int idx_number = 3;
1424 as_t as;
1425
1426 as = strtoul(argv[idx_number]->arg, NULL, 10);
1427
1428 bgp_confederation_id_set(bgp, as);
1429
1430 return CMD_SUCCESS;
1431 }
1432
1433 DEFUN (no_bgp_confederation_identifier,
1434 no_bgp_confederation_identifier_cmd,
1435 "no bgp confederation identifier [(1-4294967295)]",
1436 NO_STR
1437 "BGP specific commands\n"
1438 "AS confederation parameters\n"
1439 "AS number\n"
1440 "Set routing domain confederation AS\n")
1441 {
1442 VTY_DECLVAR_CONTEXT(bgp, bgp);
1443 bgp_confederation_id_unset(bgp);
1444
1445 return CMD_SUCCESS;
1446 }
1447
1448 DEFUN (bgp_confederation_peers,
1449 bgp_confederation_peers_cmd,
1450 "bgp confederation peers (1-4294967295)...",
1451 "BGP specific commands\n"
1452 "AS confederation parameters\n"
1453 "Peer ASs in BGP confederation\n"
1454 AS_STR)
1455 {
1456 VTY_DECLVAR_CONTEXT(bgp, bgp);
1457 int idx_asn = 3;
1458 as_t as;
1459 int i;
1460
1461 for (i = idx_asn; i < argc; i++) {
1462 as = strtoul(argv[i]->arg, NULL, 10);
1463
1464 if (bgp->as == as) {
1465 vty_out(vty,
1466 "%% Local member-AS not allowed in confed peer list\n");
1467 continue;
1468 }
1469
1470 bgp_confederation_peers_add(bgp, as);
1471 }
1472 return CMD_SUCCESS;
1473 }
1474
1475 DEFUN (no_bgp_confederation_peers,
1476 no_bgp_confederation_peers_cmd,
1477 "no bgp confederation peers (1-4294967295)...",
1478 NO_STR
1479 "BGP specific commands\n"
1480 "AS confederation parameters\n"
1481 "Peer ASs in BGP confederation\n"
1482 AS_STR)
1483 {
1484 VTY_DECLVAR_CONTEXT(bgp, bgp);
1485 int idx_asn = 4;
1486 as_t as;
1487 int i;
1488
1489 for (i = idx_asn; i < argc; i++) {
1490 as = strtoul(argv[i]->arg, NULL, 10);
1491
1492 bgp_confederation_peers_remove(bgp, as);
1493 }
1494 return CMD_SUCCESS;
1495 }
1496
1497 /**
1498 * Central routine for maximum-paths configuration.
1499 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1500 * @set: 1 for setting values, 0 for removing the max-paths config.
1501 */
1502 static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
1503 const char *mpaths, uint16_t options,
1504 int set)
1505 {
1506 VTY_DECLVAR_CONTEXT(bgp, bgp);
1507 uint16_t maxpaths = 0;
1508 int ret;
1509 afi_t afi;
1510 safi_t safi;
1511
1512 afi = bgp_node_afi(vty);
1513 safi = bgp_node_safi(vty);
1514
1515 if (set) {
1516 maxpaths = strtol(mpaths, NULL, 10);
1517 if (maxpaths > multipath_num) {
1518 vty_out(vty,
1519 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1520 maxpaths, multipath_num);
1521 return CMD_WARNING_CONFIG_FAILED;
1522 }
1523 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1524 options);
1525 } else
1526 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1527
1528 if (ret < 0) {
1529 vty_out(vty,
1530 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1531 (set == 1) ? "" : "un",
1532 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1533 maxpaths, afi, safi);
1534 return CMD_WARNING_CONFIG_FAILED;
1535 }
1536
1537 bgp_recalculate_all_bestpaths(bgp);
1538
1539 return CMD_SUCCESS;
1540 }
1541
1542 DEFUN (bgp_maxmed_admin,
1543 bgp_maxmed_admin_cmd,
1544 "bgp max-med administrative ",
1545 BGP_STR
1546 "Advertise routes with max-med\n"
1547 "Administratively applied, for an indefinite period\n")
1548 {
1549 VTY_DECLVAR_CONTEXT(bgp, bgp);
1550
1551 bgp->v_maxmed_admin = 1;
1552 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1553
1554 bgp_maxmed_update(bgp);
1555
1556 return CMD_SUCCESS;
1557 }
1558
1559 DEFUN (bgp_maxmed_admin_medv,
1560 bgp_maxmed_admin_medv_cmd,
1561 "bgp max-med administrative (0-4294967295)",
1562 BGP_STR
1563 "Advertise routes with max-med\n"
1564 "Administratively applied, for an indefinite period\n"
1565 "Max MED value to be used\n")
1566 {
1567 VTY_DECLVAR_CONTEXT(bgp, bgp);
1568 int idx_number = 3;
1569
1570 bgp->v_maxmed_admin = 1;
1571 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
1572
1573 bgp_maxmed_update(bgp);
1574
1575 return CMD_SUCCESS;
1576 }
1577
1578 DEFUN (no_bgp_maxmed_admin,
1579 no_bgp_maxmed_admin_cmd,
1580 "no bgp max-med administrative [(0-4294967295)]",
1581 NO_STR
1582 BGP_STR
1583 "Advertise routes with max-med\n"
1584 "Administratively applied, for an indefinite period\n"
1585 "Max MED value to be used\n")
1586 {
1587 VTY_DECLVAR_CONTEXT(bgp, bgp);
1588 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1589 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1590 bgp_maxmed_update(bgp);
1591
1592 return CMD_SUCCESS;
1593 }
1594
1595 DEFUN (bgp_maxmed_onstartup,
1596 bgp_maxmed_onstartup_cmd,
1597 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
1598 BGP_STR
1599 "Advertise routes with max-med\n"
1600 "Effective on a startup\n"
1601 "Time (seconds) period for max-med\n"
1602 "Max MED value to be used\n")
1603 {
1604 VTY_DECLVAR_CONTEXT(bgp, bgp);
1605 int idx = 0;
1606
1607 argv_find(argv, argc, "(5-86400)", &idx);
1608 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
1609 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1610 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
1611 else
1612 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1613
1614 bgp_maxmed_update(bgp);
1615
1616 return CMD_SUCCESS;
1617 }
1618
1619 DEFUN (no_bgp_maxmed_onstartup,
1620 no_bgp_maxmed_onstartup_cmd,
1621 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
1622 NO_STR
1623 BGP_STR
1624 "Advertise routes with max-med\n"
1625 "Effective on a startup\n"
1626 "Time (seconds) period for max-med\n"
1627 "Max MED value to be used\n")
1628 {
1629 VTY_DECLVAR_CONTEXT(bgp, bgp);
1630
1631 /* Cancel max-med onstartup if its on */
1632 if (bgp->t_maxmed_onstartup) {
1633 THREAD_TIMER_OFF(bgp->t_maxmed_onstartup);
1634 bgp->maxmed_onstartup_over = 1;
1635 }
1636
1637 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
1638 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1639
1640 bgp_maxmed_update(bgp);
1641
1642 return CMD_SUCCESS;
1643 }
1644
1645 static int bgp_update_delay_config_vty(struct vty *vty, const char *delay,
1646 const char *wait)
1647 {
1648 VTY_DECLVAR_CONTEXT(bgp, bgp);
1649 uint16_t update_delay;
1650 uint16_t establish_wait;
1651
1652 update_delay = strtoul(delay, NULL, 10);
1653
1654 if (!wait) /* update-delay <delay> */
1655 {
1656 bgp->v_update_delay = update_delay;
1657 bgp->v_establish_wait = bgp->v_update_delay;
1658 return CMD_SUCCESS;
1659 }
1660
1661 /* update-delay <delay> <establish-wait> */
1662 establish_wait = atoi(wait);
1663 if (update_delay < establish_wait) {
1664 vty_out(vty,
1665 "%%Failed: update-delay less than the establish-wait!\n");
1666 return CMD_WARNING_CONFIG_FAILED;
1667 }
1668
1669 bgp->v_update_delay = update_delay;
1670 bgp->v_establish_wait = establish_wait;
1671
1672 return CMD_SUCCESS;
1673 }
1674
1675 static int bgp_update_delay_deconfig_vty(struct vty *vty)
1676 {
1677 VTY_DECLVAR_CONTEXT(bgp, bgp);
1678
1679 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
1680 bgp->v_establish_wait = bgp->v_update_delay;
1681
1682 return CMD_SUCCESS;
1683 }
1684
1685 void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
1686 {
1687 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1688 vty_out(vty, " update-delay %d", bgp->v_update_delay);
1689 if (bgp->v_update_delay != bgp->v_establish_wait)
1690 vty_out(vty, " %d", bgp->v_establish_wait);
1691 vty_out(vty, "\n");
1692 }
1693 }
1694
1695
1696 /* Update-delay configuration */
1697 DEFUN (bgp_update_delay,
1698 bgp_update_delay_cmd,
1699 "update-delay (0-3600)",
1700 "Force initial delay for best-path and updates\n"
1701 "Seconds\n")
1702 {
1703 int idx_number = 1;
1704 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg, NULL);
1705 }
1706
1707 DEFUN (bgp_update_delay_establish_wait,
1708 bgp_update_delay_establish_wait_cmd,
1709 "update-delay (0-3600) (1-3600)",
1710 "Force initial delay for best-path and updates\n"
1711 "Seconds\n"
1712 "Seconds\n")
1713 {
1714 int idx_number = 1;
1715 int idx_number_2 = 2;
1716 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg,
1717 argv[idx_number_2]->arg);
1718 }
1719
1720 /* Update-delay deconfiguration */
1721 DEFUN (no_bgp_update_delay,
1722 no_bgp_update_delay_cmd,
1723 "no update-delay [(0-3600) [(1-3600)]]",
1724 NO_STR
1725 "Force initial delay for best-path and updates\n"
1726 "Seconds\n"
1727 "Seconds\n")
1728 {
1729 return bgp_update_delay_deconfig_vty(vty);
1730 }
1731
1732
1733 static int bgp_wpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
1734 bool set)
1735 {
1736 VTY_DECLVAR_CONTEXT(bgp, bgp);
1737
1738 quanta = set ? quanta : BGP_WRITE_PACKET_MAX;
1739 atomic_store_explicit(&bgp->wpkt_quanta, quanta, memory_order_relaxed);
1740
1741 return CMD_SUCCESS;
1742 }
1743
1744 static int bgp_rpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
1745 bool set)
1746 {
1747 VTY_DECLVAR_CONTEXT(bgp, bgp);
1748
1749 quanta = set ? quanta : BGP_READ_PACKET_MAX;
1750 atomic_store_explicit(&bgp->rpkt_quanta, quanta, memory_order_relaxed);
1751
1752 return CMD_SUCCESS;
1753 }
1754
1755 void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
1756 {
1757 uint32_t quanta =
1758 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
1759 if (quanta != BGP_WRITE_PACKET_MAX)
1760 vty_out(vty, " write-quanta %d\n", quanta);
1761 }
1762
1763 void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
1764 {
1765 uint32_t quanta =
1766 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
1767 if (quanta != BGP_READ_PACKET_MAX)
1768 vty_out(vty, " read-quanta %d\n", quanta);
1769 }
1770
1771 /* Packet quanta configuration
1772 *
1773 * XXX: The value set here controls the size of a stack buffer in the IO
1774 * thread. When changing these limits be careful to prevent stack overflow.
1775 *
1776 * Furthermore, the maximums used here should correspond to
1777 * BGP_WRITE_PACKET_MAX and BGP_READ_PACKET_MAX.
1778 */
1779 DEFPY (bgp_wpkt_quanta,
1780 bgp_wpkt_quanta_cmd,
1781 "[no] write-quanta (1-64)$quanta",
1782 NO_STR
1783 "How many packets to write to peer socket per run\n"
1784 "Number of packets\n")
1785 {
1786 return bgp_wpkt_quanta_config_vty(vty, quanta, !no);
1787 }
1788
1789 DEFPY (bgp_rpkt_quanta,
1790 bgp_rpkt_quanta_cmd,
1791 "[no] read-quanta (1-10)$quanta",
1792 NO_STR
1793 "How many packets to read from peer socket per I/O cycle\n"
1794 "Number of packets\n")
1795 {
1796 return bgp_rpkt_quanta_config_vty(vty, quanta, !no);
1797 }
1798
1799 void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
1800 {
1801 if (!bgp->heuristic_coalesce)
1802 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
1803 }
1804
1805
1806 DEFUN (bgp_coalesce_time,
1807 bgp_coalesce_time_cmd,
1808 "coalesce-time (0-4294967295)",
1809 "Subgroup coalesce timer\n"
1810 "Subgroup coalesce timer value (in ms)\n")
1811 {
1812 VTY_DECLVAR_CONTEXT(bgp, bgp);
1813
1814 int idx = 0;
1815 argv_find(argv, argc, "(0-4294967295)", &idx);
1816 bgp->heuristic_coalesce = false;
1817 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
1818 return CMD_SUCCESS;
1819 }
1820
1821 DEFUN (no_bgp_coalesce_time,
1822 no_bgp_coalesce_time_cmd,
1823 "no coalesce-time (0-4294967295)",
1824 NO_STR
1825 "Subgroup coalesce timer\n"
1826 "Subgroup coalesce timer value (in ms)\n")
1827 {
1828 VTY_DECLVAR_CONTEXT(bgp, bgp);
1829
1830 bgp->heuristic_coalesce = true;
1831 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
1832 return CMD_SUCCESS;
1833 }
1834
1835 /* Maximum-paths configuration */
1836 DEFUN (bgp_maxpaths,
1837 bgp_maxpaths_cmd,
1838 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1839 "Forward packets over multiple paths\n"
1840 "Number of paths\n")
1841 {
1842 int idx_number = 1;
1843 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
1844 argv[idx_number]->arg, 0, 1);
1845 }
1846
1847 ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
1848 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1849 "Forward packets over multiple paths\n"
1850 "Number of paths\n")
1851
1852 DEFUN (bgp_maxpaths_ibgp,
1853 bgp_maxpaths_ibgp_cmd,
1854 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1855 "Forward packets over multiple paths\n"
1856 "iBGP-multipath\n"
1857 "Number of paths\n")
1858 {
1859 int idx_number = 2;
1860 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
1861 argv[idx_number]->arg, 0, 1);
1862 }
1863
1864 ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
1865 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1866 "Forward packets over multiple paths\n"
1867 "iBGP-multipath\n"
1868 "Number of paths\n")
1869
1870 DEFUN (bgp_maxpaths_ibgp_cluster,
1871 bgp_maxpaths_ibgp_cluster_cmd,
1872 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
1873 "Forward packets over multiple paths\n"
1874 "iBGP-multipath\n"
1875 "Number of paths\n"
1876 "Match the cluster length\n")
1877 {
1878 int idx_number = 2;
1879 return bgp_maxpaths_config_vty(
1880 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
1881 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
1882 }
1883
1884 ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
1885 "maximum-paths ibgp " CMD_RANGE_STR(
1886 1, MULTIPATH_NUM) " equal-cluster-length",
1887 "Forward packets over multiple paths\n"
1888 "iBGP-multipath\n"
1889 "Number of paths\n"
1890 "Match the cluster length\n")
1891
1892 DEFUN (no_bgp_maxpaths,
1893 no_bgp_maxpaths_cmd,
1894 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
1895 NO_STR
1896 "Forward packets over multiple paths\n"
1897 "Number of paths\n")
1898 {
1899 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
1900 }
1901
1902 ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
1903 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
1904 "Forward packets over multiple paths\n"
1905 "Number of paths\n")
1906
1907 DEFUN (no_bgp_maxpaths_ibgp,
1908 no_bgp_maxpaths_ibgp_cmd,
1909 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
1910 NO_STR
1911 "Forward packets over multiple paths\n"
1912 "iBGP-multipath\n"
1913 "Number of paths\n"
1914 "Match the cluster length\n")
1915 {
1916 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
1917 }
1918
1919 ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
1920 "no maximum-paths ibgp [" CMD_RANGE_STR(
1921 1, MULTIPATH_NUM) " [equal-cluster-length]]",
1922 NO_STR
1923 "Forward packets over multiple paths\n"
1924 "iBGP-multipath\n"
1925 "Number of paths\n"
1926 "Match the cluster length\n")
1927
1928 static void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp,
1929 afi_t afi, safi_t safi)
1930 {
1931 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != MULTIPATH_NUM) {
1932 vty_out(vty, " maximum-paths %d\n",
1933 bgp->maxpaths[afi][safi].maxpaths_ebgp);
1934 }
1935
1936 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != MULTIPATH_NUM) {
1937 vty_out(vty, " maximum-paths ibgp %d",
1938 bgp->maxpaths[afi][safi].maxpaths_ibgp);
1939 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
1940 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
1941 vty_out(vty, " equal-cluster-length");
1942 vty_out(vty, "\n");
1943 }
1944 }
1945
1946 /* BGP timers. */
1947
1948 DEFUN (bgp_timers,
1949 bgp_timers_cmd,
1950 "timers bgp (0-65535) (0-65535)",
1951 "Adjust routing timers\n"
1952 "BGP timers\n"
1953 "Keepalive interval\n"
1954 "Holdtime\n")
1955 {
1956 VTY_DECLVAR_CONTEXT(bgp, bgp);
1957 int idx_number = 2;
1958 int idx_number_2 = 3;
1959 unsigned long keepalive = 0;
1960 unsigned long holdtime = 0;
1961
1962 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
1963 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
1964
1965 /* Holdtime value check. */
1966 if (holdtime < 3 && holdtime != 0) {
1967 vty_out(vty,
1968 "%% hold time value must be either 0 or greater than 3\n");
1969 return CMD_WARNING_CONFIG_FAILED;
1970 }
1971
1972 bgp_timers_set(bgp, keepalive, holdtime, DFLT_BGP_CONNECT_RETRY);
1973
1974 return CMD_SUCCESS;
1975 }
1976
1977 DEFUN (no_bgp_timers,
1978 no_bgp_timers_cmd,
1979 "no timers bgp [(0-65535) (0-65535)]",
1980 NO_STR
1981 "Adjust routing timers\n"
1982 "BGP timers\n"
1983 "Keepalive interval\n"
1984 "Holdtime\n")
1985 {
1986 VTY_DECLVAR_CONTEXT(bgp, bgp);
1987 bgp_timers_set(bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
1988 DFLT_BGP_CONNECT_RETRY);
1989
1990 return CMD_SUCCESS;
1991 }
1992
1993
1994 DEFUN (bgp_client_to_client_reflection,
1995 bgp_client_to_client_reflection_cmd,
1996 "bgp client-to-client reflection",
1997 "BGP specific commands\n"
1998 "Configure client to client route reflection\n"
1999 "reflection of routes allowed\n")
2000 {
2001 VTY_DECLVAR_CONTEXT(bgp, bgp);
2002 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2003 bgp_clear_star_soft_out(vty, bgp->name);
2004
2005 return CMD_SUCCESS;
2006 }
2007
2008 DEFUN (no_bgp_client_to_client_reflection,
2009 no_bgp_client_to_client_reflection_cmd,
2010 "no bgp client-to-client reflection",
2011 NO_STR
2012 "BGP specific commands\n"
2013 "Configure client to client route reflection\n"
2014 "reflection of routes allowed\n")
2015 {
2016 VTY_DECLVAR_CONTEXT(bgp, bgp);
2017 SET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2018 bgp_clear_star_soft_out(vty, bgp->name);
2019
2020 return CMD_SUCCESS;
2021 }
2022
2023 /* "bgp always-compare-med" configuration. */
2024 DEFUN (bgp_always_compare_med,
2025 bgp_always_compare_med_cmd,
2026 "bgp always-compare-med",
2027 "BGP specific commands\n"
2028 "Allow comparing MED from different neighbors\n")
2029 {
2030 VTY_DECLVAR_CONTEXT(bgp, bgp);
2031 SET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2032 bgp_recalculate_all_bestpaths(bgp);
2033
2034 return CMD_SUCCESS;
2035 }
2036
2037 DEFUN (no_bgp_always_compare_med,
2038 no_bgp_always_compare_med_cmd,
2039 "no bgp always-compare-med",
2040 NO_STR
2041 "BGP specific commands\n"
2042 "Allow comparing MED from different neighbors\n")
2043 {
2044 VTY_DECLVAR_CONTEXT(bgp, bgp);
2045 UNSET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2046 bgp_recalculate_all_bestpaths(bgp);
2047
2048 return CMD_SUCCESS;
2049 }
2050
2051
2052 DEFUN(bgp_ebgp_requires_policy, bgp_ebgp_requires_policy_cmd,
2053 "bgp ebgp-requires-policy",
2054 "BGP specific commands\n"
2055 "Require in and out policy for eBGP peers (RFC8212)\n")
2056 {
2057 VTY_DECLVAR_CONTEXT(bgp, bgp);
2058 SET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2059 return CMD_SUCCESS;
2060 }
2061
2062 DEFUN(no_bgp_ebgp_requires_policy, no_bgp_ebgp_requires_policy_cmd,
2063 "no bgp ebgp-requires-policy",
2064 NO_STR
2065 "BGP specific commands\n"
2066 "Require in and out policy for eBGP peers (RFC8212)\n")
2067 {
2068 VTY_DECLVAR_CONTEXT(bgp, bgp);
2069 UNSET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2070 return CMD_SUCCESS;
2071 }
2072
2073 DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd,
2074 "bgp reject-as-sets",
2075 "BGP specific commands\n"
2076 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2077 {
2078 VTY_DECLVAR_CONTEXT(bgp, bgp);
2079 struct listnode *node, *nnode;
2080 struct peer *peer;
2081
2082 bgp->reject_as_sets = true;
2083
2084 /* Reset existing BGP sessions to reject routes
2085 * with aspath containing AS_SET or AS_CONFED_SET.
2086 */
2087 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2088 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2089 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2090 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2091 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2092 }
2093 }
2094
2095 return CMD_SUCCESS;
2096 }
2097
2098 DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd,
2099 "no bgp reject-as-sets",
2100 NO_STR
2101 "BGP specific commands\n"
2102 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2103 {
2104 VTY_DECLVAR_CONTEXT(bgp, bgp);
2105 struct listnode *node, *nnode;
2106 struct peer *peer;
2107
2108 bgp->reject_as_sets = false;
2109
2110 /* Reset existing BGP sessions to reject routes
2111 * with aspath containing AS_SET or AS_CONFED_SET.
2112 */
2113 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2114 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2115 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2116 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2117 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2118 }
2119 }
2120
2121 return CMD_SUCCESS;
2122 }
2123
2124 /* "bgp deterministic-med" configuration. */
2125 DEFUN (bgp_deterministic_med,
2126 bgp_deterministic_med_cmd,
2127 "bgp deterministic-med",
2128 "BGP specific commands\n"
2129 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2130 {
2131 VTY_DECLVAR_CONTEXT(bgp, bgp);
2132
2133 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2134 SET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2135 bgp_recalculate_all_bestpaths(bgp);
2136 }
2137
2138 return CMD_SUCCESS;
2139 }
2140
2141 DEFUN (no_bgp_deterministic_med,
2142 no_bgp_deterministic_med_cmd,
2143 "no bgp deterministic-med",
2144 NO_STR
2145 "BGP specific commands\n"
2146 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2147 {
2148 VTY_DECLVAR_CONTEXT(bgp, bgp);
2149 int bestpath_per_as_used;
2150 afi_t afi;
2151 safi_t safi;
2152 struct peer *peer;
2153 struct listnode *node, *nnode;
2154
2155 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2156 bestpath_per_as_used = 0;
2157
2158 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2159 FOREACH_AFI_SAFI (afi, safi)
2160 if (bgp_addpath_dmed_required(
2161 peer->addpath_type[afi][safi])) {
2162 bestpath_per_as_used = 1;
2163 break;
2164 }
2165
2166 if (bestpath_per_as_used)
2167 break;
2168 }
2169
2170 if (bestpath_per_as_used) {
2171 vty_out(vty,
2172 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
2173 return CMD_WARNING_CONFIG_FAILED;
2174 } else {
2175 UNSET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2176 bgp_recalculate_all_bestpaths(bgp);
2177 }
2178 }
2179
2180 return CMD_SUCCESS;
2181 }
2182
2183 /* "bgp graceful-restart mode" configuration. */
2184 DEFUN (bgp_graceful_restart,
2185 bgp_graceful_restart_cmd,
2186 "bgp graceful-restart",
2187 "BGP specific commands\n"
2188 GR_CMD
2189 )
2190 {
2191 int ret = BGP_GR_FAILURE;
2192
2193 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2194 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : START ");
2195
2196 VTY_DECLVAR_CONTEXT(bgp, bgp);
2197
2198 ret = bgp_gr_update_all(bgp, GLOBAL_GR_CMD);
2199
2200 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2201 ret);
2202
2203 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2204 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : END ");
2205 vty_out(vty,
2206 "Graceful restart configuration changed, reset all peers to take effect\n");
2207 return bgp_vty_return(vty, ret);
2208 }
2209
2210 DEFUN (no_bgp_graceful_restart,
2211 no_bgp_graceful_restart_cmd,
2212 "no bgp graceful-restart",
2213 NO_STR
2214 "BGP specific commands\n"
2215 NO_GR_CMD
2216 )
2217 {
2218 VTY_DECLVAR_CONTEXT(bgp, bgp);
2219
2220 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2221 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : START ");
2222
2223 int ret = BGP_GR_FAILURE;
2224
2225 ret = bgp_gr_update_all(bgp, NO_GLOBAL_GR_CMD);
2226
2227 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2228 ret);
2229
2230 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2231 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : END ");
2232 vty_out(vty,
2233 "Graceful restart configuration changed, reset all peers to take effect\n");
2234
2235 return bgp_vty_return(vty, ret);
2236 }
2237
2238 DEFUN (bgp_graceful_restart_stalepath_time,
2239 bgp_graceful_restart_stalepath_time_cmd,
2240 "bgp graceful-restart stalepath-time (1-4095)",
2241 "BGP specific commands\n"
2242 "Graceful restart capability parameters\n"
2243 "Set the max time to hold onto restarting peer's stale paths\n"
2244 "Delay value (seconds)\n")
2245 {
2246 VTY_DECLVAR_CONTEXT(bgp, bgp);
2247 int idx_number = 3;
2248 uint32_t stalepath;
2249
2250 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2251 bgp->stalepath_time = stalepath;
2252 return CMD_SUCCESS;
2253 }
2254
2255 DEFUN (bgp_graceful_restart_restart_time,
2256 bgp_graceful_restart_restart_time_cmd,
2257 "bgp graceful-restart restart-time (1-4095)",
2258 "BGP specific commands\n"
2259 "Graceful restart capability parameters\n"
2260 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2261 "Delay value (seconds)\n")
2262 {
2263 VTY_DECLVAR_CONTEXT(bgp, bgp);
2264 int idx_number = 3;
2265 uint32_t restart;
2266
2267 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2268 bgp->restart_time = restart;
2269 return CMD_SUCCESS;
2270 }
2271
2272 DEFUN (bgp_graceful_restart_select_defer_time,
2273 bgp_graceful_restart_select_defer_time_cmd,
2274 "bgp graceful-restart select-defer-time (0-3600)",
2275 "BGP specific commands\n"
2276 "Graceful restart capability parameters\n"
2277 "Set the time to defer the BGP route selection after restart\n"
2278 "Delay value (seconds, 0 - disable)\n")
2279 {
2280 VTY_DECLVAR_CONTEXT(bgp, bgp);
2281 int idx_number = 3;
2282 uint32_t defer_time;
2283
2284 defer_time = strtoul(argv[idx_number]->arg, NULL, 10);
2285 bgp->select_defer_time = defer_time;
2286 if (defer_time == 0)
2287 SET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2288 else
2289 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2290
2291 return CMD_SUCCESS;
2292 }
2293
2294 DEFUN (no_bgp_graceful_restart_stalepath_time,
2295 no_bgp_graceful_restart_stalepath_time_cmd,
2296 "no bgp graceful-restart stalepath-time [(1-4095)]",
2297 NO_STR
2298 "BGP specific commands\n"
2299 "Graceful restart capability parameters\n"
2300 "Set the max time to hold onto restarting peer's stale paths\n"
2301 "Delay value (seconds)\n")
2302 {
2303 VTY_DECLVAR_CONTEXT(bgp, bgp);
2304
2305 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2306 return CMD_SUCCESS;
2307 }
2308
2309 DEFUN (no_bgp_graceful_restart_restart_time,
2310 no_bgp_graceful_restart_restart_time_cmd,
2311 "no bgp graceful-restart restart-time [(1-4095)]",
2312 NO_STR
2313 "BGP specific commands\n"
2314 "Graceful restart capability parameters\n"
2315 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2316 "Delay value (seconds)\n")
2317 {
2318 VTY_DECLVAR_CONTEXT(bgp, bgp);
2319
2320 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2321 return CMD_SUCCESS;
2322 }
2323
2324 DEFUN (no_bgp_graceful_restart_select_defer_time,
2325 no_bgp_graceful_restart_select_defer_time_cmd,
2326 "no bgp graceful-restart select-defer-time [(0-3600)]",
2327 NO_STR
2328 "BGP specific commands\n"
2329 "Graceful restart capability parameters\n"
2330 "Set the time to defer the BGP route selection after restart\n"
2331 "Delay value (seconds)\n")
2332 {
2333 VTY_DECLVAR_CONTEXT(bgp, bgp);
2334
2335 bgp->select_defer_time = BGP_DEFAULT_SELECT_DEFERRAL_TIME;
2336 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2337
2338 return CMD_SUCCESS;
2339 }
2340
2341 DEFUN (bgp_graceful_restart_preserve_fw,
2342 bgp_graceful_restart_preserve_fw_cmd,
2343 "bgp graceful-restart preserve-fw-state",
2344 "BGP specific commands\n"
2345 "Graceful restart capability parameters\n"
2346 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
2347 {
2348 VTY_DECLVAR_CONTEXT(bgp, bgp);
2349 SET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
2350 return CMD_SUCCESS;
2351 }
2352
2353 DEFUN (no_bgp_graceful_restart_preserve_fw,
2354 no_bgp_graceful_restart_preserve_fw_cmd,
2355 "no bgp graceful-restart preserve-fw-state",
2356 NO_STR
2357 "BGP specific commands\n"
2358 "Graceful restart capability parameters\n"
2359 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
2360 {
2361 VTY_DECLVAR_CONTEXT(bgp, bgp);
2362 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
2363 return CMD_SUCCESS;
2364 }
2365
2366 DEFUN (bgp_graceful_restart_disable,
2367 bgp_graceful_restart_disable_cmd,
2368 "bgp graceful-restart-disable",
2369 "BGP specific commands\n"
2370 GR_DISABLE)
2371 {
2372 int ret = BGP_GR_FAILURE;
2373
2374 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2375 zlog_debug(
2376 "[BGP_GR] bgp_graceful_restart_disable_cmd : START ");
2377
2378 VTY_DECLVAR_CONTEXT(bgp, bgp);
2379
2380 ret = bgp_gr_update_all(bgp, GLOBAL_DISABLE_CMD);
2381
2382 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
2383 bgp->peer, ret);
2384
2385 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2386 zlog_debug(
2387 "[BGP_GR] bgp_graceful_restart_disable_cmd : END ");
2388 vty_out(vty,
2389 "Graceful restart configuration changed, reset all peers to take effect\n");
2390
2391 return bgp_vty_return(vty, ret);
2392 }
2393
2394 DEFUN (no_bgp_graceful_restart_disable,
2395 no_bgp_graceful_restart_disable_cmd,
2396 "no bgp graceful-restart-disable",
2397 NO_STR
2398 "BGP specific commands\n"
2399 NO_GR_DISABLE
2400 )
2401 {
2402 VTY_DECLVAR_CONTEXT(bgp, bgp);
2403
2404 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2405 zlog_debug(
2406 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : START ");
2407
2408 int ret = BGP_GR_FAILURE;
2409
2410 ret = bgp_gr_update_all(bgp, NO_GLOBAL_DISABLE_CMD);
2411
2412 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2413 ret);
2414
2415 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2416 zlog_debug(
2417 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : END ");
2418 vty_out(vty,
2419 "Graceful restart configuration changed, reset all peers to take effect\n");
2420
2421 return bgp_vty_return(vty, ret);
2422 }
2423
2424 DEFUN (bgp_neighbor_graceful_restart_set,
2425 bgp_neighbor_graceful_restart_set_cmd,
2426 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
2427 NEIGHBOR_STR
2428 NEIGHBOR_ADDR_STR2
2429 GR_NEIGHBOR_CMD
2430 )
2431 {
2432 int idx_peer = 1;
2433 struct peer *peer;
2434 int ret = BGP_GR_FAILURE;
2435
2436 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2437
2438 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2439 zlog_debug(
2440 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : START ");
2441
2442 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2443 if (!peer)
2444 return CMD_WARNING_CONFIG_FAILED;
2445
2446 ret = bgp_neighbor_graceful_restart(peer, PEER_GR_CMD);
2447
2448 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2449 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
2450
2451 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2452 zlog_debug(
2453 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : END ");
2454 vty_out(vty,
2455 "Graceful restart configuration changed, reset this peer to take effect\n");
2456
2457 return bgp_vty_return(vty, ret);
2458 }
2459
2460 DEFUN (no_bgp_neighbor_graceful_restart,
2461 no_bgp_neighbor_graceful_restart_set_cmd,
2462 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
2463 NO_STR
2464 NEIGHBOR_STR
2465 NEIGHBOR_ADDR_STR2
2466 NO_GR_NEIGHBOR_CMD
2467 )
2468 {
2469 int idx_peer = 2;
2470 int ret = BGP_GR_FAILURE;
2471 struct peer *peer;
2472
2473 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2474
2475 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2476 if (!peer)
2477 return CMD_WARNING_CONFIG_FAILED;
2478
2479 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2480 zlog_debug(
2481 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : START ");
2482
2483 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_GR_CMD);
2484
2485 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2486 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
2487
2488 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2489 zlog_debug(
2490 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : END ");
2491 vty_out(vty,
2492 "Graceful restart configuration changed, reset this peer to take effect\n");
2493
2494 return bgp_vty_return(vty, ret);
2495 }
2496
2497 DEFUN (bgp_neighbor_graceful_restart_helper_set,
2498 bgp_neighbor_graceful_restart_helper_set_cmd,
2499 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
2500 NEIGHBOR_STR
2501 NEIGHBOR_ADDR_STR2
2502 GR_NEIGHBOR_HELPER_CMD
2503 )
2504 {
2505 int idx_peer = 1;
2506 struct peer *peer;
2507 int ret = BGP_GR_FAILURE;
2508
2509 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2510
2511 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2512 zlog_debug(
2513 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : START ");
2514
2515 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2516
2517 if (!peer)
2518 return CMD_WARNING_CONFIG_FAILED;
2519
2520
2521 ret = bgp_neighbor_graceful_restart(peer, PEER_HELPER_CMD);
2522
2523 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2524 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
2525
2526 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2527 zlog_debug(
2528 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : END ");
2529 vty_out(vty,
2530 "Graceful restart configuration changed, reset this peer to take effect\n");
2531
2532 return bgp_vty_return(vty, ret);
2533 }
2534
2535 DEFUN (no_bgp_neighbor_graceful_restart_helper,
2536 no_bgp_neighbor_graceful_restart_helper_set_cmd,
2537 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
2538 NO_STR
2539 NEIGHBOR_STR
2540 NEIGHBOR_ADDR_STR2
2541 NO_GR_NEIGHBOR_HELPER_CMD
2542 )
2543 {
2544 int idx_peer = 2;
2545 int ret = BGP_GR_FAILURE;
2546 struct peer *peer;
2547
2548 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2549
2550 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2551 if (!peer)
2552 return CMD_WARNING_CONFIG_FAILED;
2553
2554 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2555 zlog_debug(
2556 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : START ");
2557
2558 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_HELPER_CMD);
2559
2560 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2561 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
2562
2563 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2564 zlog_debug(
2565 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : END ");
2566 vty_out(vty,
2567 "Graceful restart configuration changed, reset this peer to take effect\n");
2568
2569 return bgp_vty_return(vty, ret);
2570 }
2571
2572 DEFUN (bgp_neighbor_graceful_restart_disable_set,
2573 bgp_neighbor_graceful_restart_disable_set_cmd,
2574 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
2575 NEIGHBOR_STR
2576 NEIGHBOR_ADDR_STR2
2577 GR_NEIGHBOR_DISABLE_CMD
2578 )
2579 {
2580 int idx_peer = 1;
2581 struct peer *peer;
2582 int ret = BGP_GR_FAILURE;
2583
2584 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2585
2586 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2587 zlog_debug(
2588 "[BGP_GR] bgp_neighbor_graceful_restart_disable_set_cmd : START ");
2589
2590 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2591 if (!peer)
2592 return CMD_WARNING_CONFIG_FAILED;
2593
2594 ret = bgp_neighbor_graceful_restart(peer, PEER_DISABLE_CMD);
2595
2596 if (peer->bgp->t_startup)
2597 bgp_peer_gr_flags_update(peer);
2598
2599 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2600 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
2601
2602 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2603 zlog_debug(
2604 "[BGP_GR]bgp_neighbor_graceful_restart_disable_set_cmd : END ");
2605 vty_out(vty,
2606 "Graceful restart configuration changed, reset this peer to take effect\n");
2607
2608 return bgp_vty_return(vty, ret);
2609 }
2610
2611 DEFUN (no_bgp_neighbor_graceful_restart_disable,
2612 no_bgp_neighbor_graceful_restart_disable_set_cmd,
2613 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
2614 NO_STR
2615 NEIGHBOR_STR
2616 NEIGHBOR_ADDR_STR2
2617 NO_GR_NEIGHBOR_DISABLE_CMD
2618 )
2619 {
2620 int idx_peer = 2;
2621 int ret = BGP_GR_FAILURE;
2622 struct peer *peer;
2623
2624 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2625
2626 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2627 if (!peer)
2628 return CMD_WARNING_CONFIG_FAILED;
2629
2630 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2631 zlog_debug(
2632 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : START ");
2633
2634 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_DISABLE_CMD);
2635
2636 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2637 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
2638
2639 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2640 zlog_debug(
2641 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : END ");
2642 vty_out(vty,
2643 "Graceful restart configuration changed, reset this peer to take effect\n");
2644
2645 return bgp_vty_return(vty, ret);
2646 }
2647
2648 DEFUN_HIDDEN (bgp_graceful_restart_disable_eor,
2649 bgp_graceful_restart_disable_eor_cmd,
2650 "bgp graceful-restart disable-eor",
2651 "BGP specific commands\n"
2652 "Graceful restart configuration parameters\n"
2653 "Disable EOR Check\n")
2654 {
2655 VTY_DECLVAR_CONTEXT(bgp, bgp);
2656 SET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
2657
2658 return CMD_SUCCESS;
2659 }
2660
2661 DEFUN_HIDDEN (no_bgp_graceful_restart_disable_eor,
2662 no_bgp_graceful_restart_disable_eor_cmd,
2663 "no bgp graceful-restart disable-eor",
2664 NO_STR
2665 "BGP specific commands\n"
2666 "Graceful restart configuration parameters\n"
2667 "Disable EOR Check\n")
2668 {
2669 VTY_DECLVAR_CONTEXT(bgp, bgp);
2670 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
2671
2672 return CMD_SUCCESS;
2673 }
2674
2675 DEFUN (bgp_graceful_restart_rib_stale_time,
2676 bgp_graceful_restart_rib_stale_time_cmd,
2677 "bgp graceful-restart rib-stale-time (1-3600)",
2678 "BGP specific commands\n"
2679 "Graceful restart configuration parameters\n"
2680 "Specify the stale route removal timer in rib\n"
2681 "Delay value (seconds)\n")
2682 {
2683 VTY_DECLVAR_CONTEXT(bgp, bgp);
2684 int idx_number = 3;
2685 uint32_t stale_time;
2686
2687 stale_time = strtoul(argv[idx_number]->arg, NULL, 10);
2688 bgp->rib_stale_time = stale_time;
2689 /* Send the stale timer update message to RIB */
2690 if (bgp_zebra_stale_timer_update(bgp))
2691 return CMD_WARNING;
2692
2693 return CMD_SUCCESS;
2694 }
2695
2696 DEFUN (no_bgp_graceful_restart_rib_stale_time,
2697 no_bgp_graceful_restart_rib_stale_time_cmd,
2698 "no bgp graceful-restart rib-stale-time [(1-3600)]",
2699 NO_STR
2700 "BGP specific commands\n"
2701 "Graceful restart configuration parameters\n"
2702 "Specify the stale route removal timer in rib\n"
2703 "Delay value (seconds)\n")
2704 {
2705 VTY_DECLVAR_CONTEXT(bgp, bgp);
2706
2707 bgp->rib_stale_time = BGP_DEFAULT_RIB_STALE_TIME;
2708 /* Send the stale timer update message to RIB */
2709 if (bgp_zebra_stale_timer_update(bgp))
2710 return CMD_WARNING;
2711
2712 return CMD_SUCCESS;
2713 }
2714
2715 /* "bgp graceful-shutdown" configuration */
2716 DEFUN (bgp_graceful_shutdown,
2717 bgp_graceful_shutdown_cmd,
2718 "bgp graceful-shutdown",
2719 BGP_STR
2720 "Graceful shutdown parameters\n")
2721 {
2722 VTY_DECLVAR_CONTEXT(bgp, bgp);
2723
2724 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2725 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
2726 bgp_static_redo_import_check(bgp);
2727 bgp_redistribute_redo(bgp);
2728 bgp_clear_star_soft_out(vty, bgp->name);
2729 bgp_clear_star_soft_in(vty, bgp->name);
2730 }
2731
2732 return CMD_SUCCESS;
2733 }
2734
2735 DEFUN (no_bgp_graceful_shutdown,
2736 no_bgp_graceful_shutdown_cmd,
2737 "no bgp graceful-shutdown",
2738 NO_STR
2739 BGP_STR
2740 "Graceful shutdown parameters\n")
2741 {
2742 VTY_DECLVAR_CONTEXT(bgp, bgp);
2743
2744 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2745 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
2746 bgp_static_redo_import_check(bgp);
2747 bgp_redistribute_redo(bgp);
2748 bgp_clear_star_soft_out(vty, bgp->name);
2749 bgp_clear_star_soft_in(vty, bgp->name);
2750 }
2751
2752 return CMD_SUCCESS;
2753 }
2754
2755 /* "bgp fast-external-failover" configuration. */
2756 DEFUN (bgp_fast_external_failover,
2757 bgp_fast_external_failover_cmd,
2758 "bgp fast-external-failover",
2759 BGP_STR
2760 "Immediately reset session if a link to a directly connected external peer goes down\n")
2761 {
2762 VTY_DECLVAR_CONTEXT(bgp, bgp);
2763 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2764 return CMD_SUCCESS;
2765 }
2766
2767 DEFUN (no_bgp_fast_external_failover,
2768 no_bgp_fast_external_failover_cmd,
2769 "no bgp fast-external-failover",
2770 NO_STR
2771 BGP_STR
2772 "Immediately reset session if a link to a directly connected external peer goes down\n")
2773 {
2774 VTY_DECLVAR_CONTEXT(bgp, bgp);
2775 SET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2776 return CMD_SUCCESS;
2777 }
2778
2779 /* "bgp bestpath compare-routerid" configuration. */
2780 DEFUN (bgp_bestpath_compare_router_id,
2781 bgp_bestpath_compare_router_id_cmd,
2782 "bgp bestpath compare-routerid",
2783 "BGP specific commands\n"
2784 "Change the default bestpath selection\n"
2785 "Compare router-id for identical EBGP paths\n")
2786 {
2787 VTY_DECLVAR_CONTEXT(bgp, bgp);
2788 SET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
2789 bgp_recalculate_all_bestpaths(bgp);
2790
2791 return CMD_SUCCESS;
2792 }
2793
2794 DEFUN (no_bgp_bestpath_compare_router_id,
2795 no_bgp_bestpath_compare_router_id_cmd,
2796 "no bgp bestpath compare-routerid",
2797 NO_STR
2798 "BGP specific commands\n"
2799 "Change the default bestpath selection\n"
2800 "Compare router-id for identical EBGP paths\n")
2801 {
2802 VTY_DECLVAR_CONTEXT(bgp, bgp);
2803 UNSET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
2804 bgp_recalculate_all_bestpaths(bgp);
2805
2806 return CMD_SUCCESS;
2807 }
2808
2809 /* "bgp bestpath as-path ignore" configuration. */
2810 DEFUN (bgp_bestpath_aspath_ignore,
2811 bgp_bestpath_aspath_ignore_cmd,
2812 "bgp bestpath as-path ignore",
2813 "BGP specific commands\n"
2814 "Change the default bestpath selection\n"
2815 "AS-path attribute\n"
2816 "Ignore as-path length in selecting a route\n")
2817 {
2818 VTY_DECLVAR_CONTEXT(bgp, bgp);
2819 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
2820 bgp_recalculate_all_bestpaths(bgp);
2821
2822 return CMD_SUCCESS;
2823 }
2824
2825 DEFUN (no_bgp_bestpath_aspath_ignore,
2826 no_bgp_bestpath_aspath_ignore_cmd,
2827 "no bgp bestpath as-path ignore",
2828 NO_STR
2829 "BGP specific commands\n"
2830 "Change the default bestpath selection\n"
2831 "AS-path attribute\n"
2832 "Ignore as-path length in selecting a route\n")
2833 {
2834 VTY_DECLVAR_CONTEXT(bgp, bgp);
2835 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
2836 bgp_recalculate_all_bestpaths(bgp);
2837
2838 return CMD_SUCCESS;
2839 }
2840
2841 /* "bgp bestpath as-path confed" configuration. */
2842 DEFUN (bgp_bestpath_aspath_confed,
2843 bgp_bestpath_aspath_confed_cmd,
2844 "bgp bestpath as-path confed",
2845 "BGP specific commands\n"
2846 "Change the default bestpath selection\n"
2847 "AS-path attribute\n"
2848 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2849 {
2850 VTY_DECLVAR_CONTEXT(bgp, bgp);
2851 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
2852 bgp_recalculate_all_bestpaths(bgp);
2853
2854 return CMD_SUCCESS;
2855 }
2856
2857 DEFUN (no_bgp_bestpath_aspath_confed,
2858 no_bgp_bestpath_aspath_confed_cmd,
2859 "no bgp bestpath as-path confed",
2860 NO_STR
2861 "BGP specific commands\n"
2862 "Change the default bestpath selection\n"
2863 "AS-path attribute\n"
2864 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2865 {
2866 VTY_DECLVAR_CONTEXT(bgp, bgp);
2867 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
2868 bgp_recalculate_all_bestpaths(bgp);
2869
2870 return CMD_SUCCESS;
2871 }
2872
2873 /* "bgp bestpath as-path multipath-relax" configuration. */
2874 DEFUN (bgp_bestpath_aspath_multipath_relax,
2875 bgp_bestpath_aspath_multipath_relax_cmd,
2876 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
2877 "BGP specific commands\n"
2878 "Change the default bestpath selection\n"
2879 "AS-path attribute\n"
2880 "Allow load sharing across routes that have different AS paths (but same length)\n"
2881 "Generate an AS_SET\n"
2882 "Do not generate an AS_SET\n")
2883 {
2884 VTY_DECLVAR_CONTEXT(bgp, bgp);
2885 int idx = 0;
2886 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2887
2888 /* no-as-set is now the default behavior so we can silently
2889 * ignore it */
2890 if (argv_find(argv, argc, "as-set", &idx))
2891 SET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2892 else
2893 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2894
2895 bgp_recalculate_all_bestpaths(bgp);
2896
2897 return CMD_SUCCESS;
2898 }
2899
2900 DEFUN (no_bgp_bestpath_aspath_multipath_relax,
2901 no_bgp_bestpath_aspath_multipath_relax_cmd,
2902 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
2903 NO_STR
2904 "BGP specific commands\n"
2905 "Change the default bestpath selection\n"
2906 "AS-path attribute\n"
2907 "Allow load sharing across routes that have different AS paths (but same length)\n"
2908 "Generate an AS_SET\n"
2909 "Do not generate an AS_SET\n")
2910 {
2911 VTY_DECLVAR_CONTEXT(bgp, bgp);
2912 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2913 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2914 bgp_recalculate_all_bestpaths(bgp);
2915
2916 return CMD_SUCCESS;
2917 }
2918
2919 /* "bgp log-neighbor-changes" configuration. */
2920 DEFUN (bgp_log_neighbor_changes,
2921 bgp_log_neighbor_changes_cmd,
2922 "bgp log-neighbor-changes",
2923 "BGP specific commands\n"
2924 "Log neighbor up/down and reset reason\n")
2925 {
2926 VTY_DECLVAR_CONTEXT(bgp, bgp);
2927 SET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2928 return CMD_SUCCESS;
2929 }
2930
2931 DEFUN (no_bgp_log_neighbor_changes,
2932 no_bgp_log_neighbor_changes_cmd,
2933 "no bgp log-neighbor-changes",
2934 NO_STR
2935 "BGP specific commands\n"
2936 "Log neighbor up/down and reset reason\n")
2937 {
2938 VTY_DECLVAR_CONTEXT(bgp, bgp);
2939 UNSET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2940 return CMD_SUCCESS;
2941 }
2942
2943 /* "bgp bestpath med" configuration. */
2944 DEFUN (bgp_bestpath_med,
2945 bgp_bestpath_med_cmd,
2946 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
2947 "BGP specific commands\n"
2948 "Change the default bestpath selection\n"
2949 "MED attribute\n"
2950 "Compare MED among confederation paths\n"
2951 "Treat missing MED as the least preferred one\n"
2952 "Treat missing MED as the least preferred one\n"
2953 "Compare MED among confederation paths\n")
2954 {
2955 VTY_DECLVAR_CONTEXT(bgp, bgp);
2956
2957 int idx = 0;
2958 if (argv_find(argv, argc, "confed", &idx))
2959 SET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
2960 idx = 0;
2961 if (argv_find(argv, argc, "missing-as-worst", &idx))
2962 SET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
2963
2964 bgp_recalculate_all_bestpaths(bgp);
2965
2966 return CMD_SUCCESS;
2967 }
2968
2969 DEFUN (no_bgp_bestpath_med,
2970 no_bgp_bestpath_med_cmd,
2971 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
2972 NO_STR
2973 "BGP specific commands\n"
2974 "Change the default bestpath selection\n"
2975 "MED attribute\n"
2976 "Compare MED among confederation paths\n"
2977 "Treat missing MED as the least preferred one\n"
2978 "Treat missing MED as the least preferred one\n"
2979 "Compare MED among confederation paths\n")
2980 {
2981 VTY_DECLVAR_CONTEXT(bgp, bgp);
2982
2983 int idx = 0;
2984 if (argv_find(argv, argc, "confed", &idx))
2985 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
2986 idx = 0;
2987 if (argv_find(argv, argc, "missing-as-worst", &idx))
2988 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
2989
2990 bgp_recalculate_all_bestpaths(bgp);
2991
2992 return CMD_SUCCESS;
2993 }
2994
2995 /* "bgp bestpath bandwidth" configuration. */
2996 DEFPY (bgp_bestpath_bw,
2997 bgp_bestpath_bw_cmd,
2998 "bgp bestpath bandwidth <ignore|skip-missing|default-weight-for-missing>$bw_cfg",
2999 "BGP specific commands\n"
3000 "Change the default bestpath selection\n"
3001 "Link Bandwidth attribute\n"
3002 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3003 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3004 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3005 {
3006 VTY_DECLVAR_CONTEXT(bgp, bgp);
3007 afi_t afi;
3008 safi_t safi;
3009
3010 if (!bw_cfg) {
3011 vty_out(vty, "%% Bandwidth configuration must be specified\n");
3012 return CMD_ERR_INCOMPLETE;
3013 }
3014 if (!strcmp(bw_cfg, "ignore"))
3015 bgp->lb_handling = BGP_LINK_BW_IGNORE_BW;
3016 else if (!strcmp(bw_cfg, "skip-missing"))
3017 bgp->lb_handling = BGP_LINK_BW_SKIP_MISSING;
3018 else if (!strcmp(bw_cfg, "default-weight-for-missing"))
3019 bgp->lb_handling = BGP_LINK_BW_DEFWT_4_MISSING;
3020 else
3021 return CMD_ERR_NO_MATCH;
3022
3023 /* This config is used in route install, so redo that. */
3024 FOREACH_AFI_SAFI (afi, safi) {
3025 if (!bgp_fibupd_safi(safi))
3026 continue;
3027 bgp_zebra_announce_table(bgp, afi, safi);
3028 }
3029
3030 return CMD_SUCCESS;
3031 }
3032
3033 DEFPY (no_bgp_bestpath_bw,
3034 no_bgp_bestpath_bw_cmd,
3035 "no bgp bestpath bandwidth [<ignore|skip-missing|default-weight-for-missing>$bw_cfg]",
3036 NO_STR
3037 "BGP specific commands\n"
3038 "Change the default bestpath selection\n"
3039 "Link Bandwidth attribute\n"
3040 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3041 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3042 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3043 {
3044 VTY_DECLVAR_CONTEXT(bgp, bgp);
3045 afi_t afi;
3046 safi_t safi;
3047
3048 bgp->lb_handling = BGP_LINK_BW_ECMP;
3049
3050 /* This config is used in route install, so redo that. */
3051 FOREACH_AFI_SAFI (afi, safi) {
3052 if (!bgp_fibupd_safi(safi))
3053 continue;
3054 bgp_zebra_announce_table(bgp, afi, safi);
3055 }
3056 return CMD_SUCCESS;
3057 }
3058
3059 /* "no bgp default ipv4-unicast". */
3060 DEFUN (no_bgp_default_ipv4_unicast,
3061 no_bgp_default_ipv4_unicast_cmd,
3062 "no bgp default ipv4-unicast",
3063 NO_STR
3064 "BGP specific commands\n"
3065 "Configure BGP defaults\n"
3066 "Activate ipv4-unicast for a peer by default\n")
3067 {
3068 VTY_DECLVAR_CONTEXT(bgp, bgp);
3069 SET_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4);
3070 return CMD_SUCCESS;
3071 }
3072
3073 DEFUN (bgp_default_ipv4_unicast,
3074 bgp_default_ipv4_unicast_cmd,
3075 "bgp default ipv4-unicast",
3076 "BGP specific commands\n"
3077 "Configure BGP defaults\n"
3078 "Activate ipv4-unicast for a peer by default\n")
3079 {
3080 VTY_DECLVAR_CONTEXT(bgp, bgp);
3081 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4);
3082 return CMD_SUCCESS;
3083 }
3084
3085 /* Display hostname in certain command outputs */
3086 DEFUN (bgp_default_show_hostname,
3087 bgp_default_show_hostname_cmd,
3088 "bgp default show-hostname",
3089 "BGP specific commands\n"
3090 "Configure BGP defaults\n"
3091 "Show hostname in certain command outputs\n")
3092 {
3093 VTY_DECLVAR_CONTEXT(bgp, bgp);
3094 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
3095 return CMD_SUCCESS;
3096 }
3097
3098 DEFUN (no_bgp_default_show_hostname,
3099 no_bgp_default_show_hostname_cmd,
3100 "no bgp default show-hostname",
3101 NO_STR
3102 "BGP specific commands\n"
3103 "Configure BGP defaults\n"
3104 "Show hostname in certain command outputs\n")
3105 {
3106 VTY_DECLVAR_CONTEXT(bgp, bgp);
3107 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
3108 return CMD_SUCCESS;
3109 }
3110
3111 /* Display hostname in certain command outputs */
3112 DEFUN (bgp_default_show_nexthop_hostname,
3113 bgp_default_show_nexthop_hostname_cmd,
3114 "bgp default show-nexthop-hostname",
3115 "BGP specific commands\n"
3116 "Configure BGP defaults\n"
3117 "Show hostname for nexthop in certain command outputs\n")
3118 {
3119 VTY_DECLVAR_CONTEXT(bgp, bgp);
3120 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
3121 return CMD_SUCCESS;
3122 }
3123
3124 DEFUN (no_bgp_default_show_nexthop_hostname,
3125 no_bgp_default_show_nexthop_hostname_cmd,
3126 "no bgp default show-nexthop-hostname",
3127 NO_STR
3128 "BGP specific commands\n"
3129 "Configure BGP defaults\n"
3130 "Show hostname for nexthop in certain command outputs\n")
3131 {
3132 VTY_DECLVAR_CONTEXT(bgp, bgp);
3133 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
3134 return CMD_SUCCESS;
3135 }
3136
3137 /* "bgp network import-check" configuration. */
3138 DEFUN (bgp_network_import_check,
3139 bgp_network_import_check_cmd,
3140 "bgp network import-check",
3141 "BGP specific commands\n"
3142 "BGP network command\n"
3143 "Check BGP network route exists in IGP\n")
3144 {
3145 VTY_DECLVAR_CONTEXT(bgp, bgp);
3146 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
3147 SET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
3148 bgp_static_redo_import_check(bgp);
3149 }
3150
3151 return CMD_SUCCESS;
3152 }
3153
3154 ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
3155 "bgp network import-check exact",
3156 "BGP specific commands\n"
3157 "BGP network command\n"
3158 "Check BGP network route exists in IGP\n"
3159 "Match route precisely\n")
3160
3161 DEFUN (no_bgp_network_import_check,
3162 no_bgp_network_import_check_cmd,
3163 "no bgp network import-check",
3164 NO_STR
3165 "BGP specific commands\n"
3166 "BGP network command\n"
3167 "Check BGP network route exists in IGP\n")
3168 {
3169 VTY_DECLVAR_CONTEXT(bgp, bgp);
3170 if (CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
3171 UNSET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
3172 bgp_static_redo_import_check(bgp);
3173 }
3174
3175 return CMD_SUCCESS;
3176 }
3177
3178 DEFUN (bgp_default_local_preference,
3179 bgp_default_local_preference_cmd,
3180 "bgp default local-preference (0-4294967295)",
3181 "BGP specific commands\n"
3182 "Configure BGP defaults\n"
3183 "local preference (higher=more preferred)\n"
3184 "Configure default local preference value\n")
3185 {
3186 VTY_DECLVAR_CONTEXT(bgp, bgp);
3187 int idx_number = 3;
3188 uint32_t local_pref;
3189
3190 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
3191
3192 bgp_default_local_preference_set(bgp, local_pref);
3193 bgp_clear_star_soft_in(vty, bgp->name);
3194
3195 return CMD_SUCCESS;
3196 }
3197
3198 DEFUN (no_bgp_default_local_preference,
3199 no_bgp_default_local_preference_cmd,
3200 "no bgp default local-preference [(0-4294967295)]",
3201 NO_STR
3202 "BGP specific commands\n"
3203 "Configure BGP defaults\n"
3204 "local preference (higher=more preferred)\n"
3205 "Configure default local preference value\n")
3206 {
3207 VTY_DECLVAR_CONTEXT(bgp, bgp);
3208 bgp_default_local_preference_unset(bgp);
3209 bgp_clear_star_soft_in(vty, bgp->name);
3210
3211 return CMD_SUCCESS;
3212 }
3213
3214
3215 DEFUN (bgp_default_subgroup_pkt_queue_max,
3216 bgp_default_subgroup_pkt_queue_max_cmd,
3217 "bgp default subgroup-pkt-queue-max (20-100)",
3218 "BGP specific commands\n"
3219 "Configure BGP defaults\n"
3220 "subgroup-pkt-queue-max\n"
3221 "Configure subgroup packet queue max\n")
3222 {
3223 VTY_DECLVAR_CONTEXT(bgp, bgp);
3224 int idx_number = 3;
3225 uint32_t max_size;
3226
3227 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
3228
3229 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
3230
3231 return CMD_SUCCESS;
3232 }
3233
3234 DEFUN (no_bgp_default_subgroup_pkt_queue_max,
3235 no_bgp_default_subgroup_pkt_queue_max_cmd,
3236 "no bgp default subgroup-pkt-queue-max [(20-100)]",
3237 NO_STR
3238 "BGP specific commands\n"
3239 "Configure BGP defaults\n"
3240 "subgroup-pkt-queue-max\n"
3241 "Configure subgroup packet queue max\n")
3242 {
3243 VTY_DECLVAR_CONTEXT(bgp, bgp);
3244 bgp_default_subgroup_pkt_queue_max_unset(bgp);
3245 return CMD_SUCCESS;
3246 }
3247
3248
3249 DEFUN (bgp_rr_allow_outbound_policy,
3250 bgp_rr_allow_outbound_policy_cmd,
3251 "bgp route-reflector allow-outbound-policy",
3252 "BGP specific commands\n"
3253 "Allow modifications made by out route-map\n"
3254 "on ibgp neighbors\n")
3255 {
3256 VTY_DECLVAR_CONTEXT(bgp, bgp);
3257
3258 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
3259 SET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
3260 update_group_announce_rrclients(bgp);
3261 bgp_clear_star_soft_out(vty, bgp->name);
3262 }
3263
3264 return CMD_SUCCESS;
3265 }
3266
3267 DEFUN (no_bgp_rr_allow_outbound_policy,
3268 no_bgp_rr_allow_outbound_policy_cmd,
3269 "no bgp route-reflector allow-outbound-policy",
3270 NO_STR
3271 "BGP specific commands\n"
3272 "Allow modifications made by out route-map\n"
3273 "on ibgp neighbors\n")
3274 {
3275 VTY_DECLVAR_CONTEXT(bgp, bgp);
3276
3277 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
3278 UNSET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
3279 update_group_announce_rrclients(bgp);
3280 bgp_clear_star_soft_out(vty, bgp->name);
3281 }
3282
3283 return CMD_SUCCESS;
3284 }
3285
3286 DEFUN (bgp_listen_limit,
3287 bgp_listen_limit_cmd,
3288 "bgp listen limit (1-5000)",
3289 "BGP specific commands\n"
3290 "BGP Dynamic Neighbors listen commands\n"
3291 "Maximum number of BGP Dynamic Neighbors that can be created\n"
3292 "Configure Dynamic Neighbors listen limit value\n")
3293 {
3294 VTY_DECLVAR_CONTEXT(bgp, bgp);
3295 int idx_number = 3;
3296 int listen_limit;
3297
3298 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
3299
3300 bgp_listen_limit_set(bgp, listen_limit);
3301
3302 return CMD_SUCCESS;
3303 }
3304
3305 DEFUN (no_bgp_listen_limit,
3306 no_bgp_listen_limit_cmd,
3307 "no bgp listen limit [(1-5000)]",
3308 NO_STR
3309 "BGP specific commands\n"
3310 "BGP Dynamic Neighbors listen commands\n"
3311 "Maximum number of BGP Dynamic Neighbors that can be created\n"
3312 "Configure Dynamic Neighbors listen limit value\n")
3313 {
3314 VTY_DECLVAR_CONTEXT(bgp, bgp);
3315 bgp_listen_limit_unset(bgp);
3316 return CMD_SUCCESS;
3317 }
3318
3319
3320 /*
3321 * Check if this listen range is already configured. Check for exact
3322 * match or overlap based on input.
3323 */
3324 static struct peer_group *listen_range_exists(struct bgp *bgp,
3325 struct prefix *range, int exact)
3326 {
3327 struct listnode *node, *nnode;
3328 struct listnode *node1, *nnode1;
3329 struct peer_group *group;
3330 struct prefix *lr;
3331 afi_t afi;
3332 int match;
3333
3334 afi = family2afi(range->family);
3335 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
3336 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
3337 lr)) {
3338 if (exact)
3339 match = prefix_same(range, lr);
3340 else
3341 match = (prefix_match(range, lr)
3342 || prefix_match(lr, range));
3343 if (match)
3344 return group;
3345 }
3346 }
3347
3348 return NULL;
3349 }
3350
3351 DEFUN (bgp_listen_range,
3352 bgp_listen_range_cmd,
3353 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
3354 "BGP specific commands\n"
3355 "Configure BGP dynamic neighbors listen range\n"
3356 "Configure BGP dynamic neighbors listen range\n"
3357 NEIGHBOR_ADDR_STR
3358 "Member of the peer-group\n"
3359 "Peer-group name\n")
3360 {
3361 VTY_DECLVAR_CONTEXT(bgp, bgp);
3362 struct prefix range;
3363 struct peer_group *group, *existing_group;
3364 afi_t afi;
3365 int ret;
3366 int idx = 0;
3367
3368 argv_find(argv, argc, "A.B.C.D/M", &idx);
3369 argv_find(argv, argc, "X:X::X:X/M", &idx);
3370 char *prefix = argv[idx]->arg;
3371 argv_find(argv, argc, "PGNAME", &idx);
3372 char *peergroup = argv[idx]->arg;
3373
3374 /* Convert IP prefix string to struct prefix. */
3375 ret = str2prefix(prefix, &range);
3376 if (!ret) {
3377 vty_out(vty, "%% Malformed listen range\n");
3378 return CMD_WARNING_CONFIG_FAILED;
3379 }
3380
3381 afi = family2afi(range.family);
3382
3383 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
3384 vty_out(vty,
3385 "%% Malformed listen range (link-local address)\n");
3386 return CMD_WARNING_CONFIG_FAILED;
3387 }
3388
3389 apply_mask(&range);
3390
3391 /* Check if same listen range is already configured. */
3392 existing_group = listen_range_exists(bgp, &range, 1);
3393 if (existing_group) {
3394 if (strcmp(existing_group->name, peergroup) == 0)
3395 return CMD_SUCCESS;
3396 else {
3397 vty_out(vty,
3398 "%% Same listen range is attached to peer-group %s\n",
3399 existing_group->name);
3400 return CMD_WARNING_CONFIG_FAILED;
3401 }
3402 }
3403
3404 /* Check if an overlapping listen range exists. */
3405 if (listen_range_exists(bgp, &range, 0)) {
3406 vty_out(vty,
3407 "%% Listen range overlaps with existing listen range\n");
3408 return CMD_WARNING_CONFIG_FAILED;
3409 }
3410
3411 group = peer_group_lookup(bgp, peergroup);
3412 if (!group) {
3413 vty_out(vty, "%% Configure the peer-group first\n");
3414 return CMD_WARNING_CONFIG_FAILED;
3415 }
3416
3417 ret = peer_group_listen_range_add(group, &range);
3418 return bgp_vty_return(vty, ret);
3419 }
3420
3421 DEFUN (no_bgp_listen_range,
3422 no_bgp_listen_range_cmd,
3423 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
3424 NO_STR
3425 "BGP specific commands\n"
3426 "Unconfigure BGP dynamic neighbors listen range\n"
3427 "Unconfigure BGP dynamic neighbors listen range\n"
3428 NEIGHBOR_ADDR_STR
3429 "Member of the peer-group\n"
3430 "Peer-group name\n")
3431 {
3432 VTY_DECLVAR_CONTEXT(bgp, bgp);
3433 struct prefix range;
3434 struct peer_group *group;
3435 afi_t afi;
3436 int ret;
3437 int idx = 0;
3438
3439 argv_find(argv, argc, "A.B.C.D/M", &idx);
3440 argv_find(argv, argc, "X:X::X:X/M", &idx);
3441 char *prefix = argv[idx]->arg;
3442 argv_find(argv, argc, "PGNAME", &idx);
3443 char *peergroup = argv[idx]->arg;
3444
3445 /* Convert IP prefix string to struct prefix. */
3446 ret = str2prefix(prefix, &range);
3447 if (!ret) {
3448 vty_out(vty, "%% Malformed listen range\n");
3449 return CMD_WARNING_CONFIG_FAILED;
3450 }
3451
3452 afi = family2afi(range.family);
3453
3454 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
3455 vty_out(vty,
3456 "%% Malformed listen range (link-local address)\n");
3457 return CMD_WARNING_CONFIG_FAILED;
3458 }
3459
3460 apply_mask(&range);
3461
3462 group = peer_group_lookup(bgp, peergroup);
3463 if (!group) {
3464 vty_out(vty, "%% Peer-group does not exist\n");
3465 return CMD_WARNING_CONFIG_FAILED;
3466 }
3467
3468 ret = peer_group_listen_range_del(group, &range);
3469 return bgp_vty_return(vty, ret);
3470 }
3471
3472 void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
3473 {
3474 struct peer_group *group;
3475 struct listnode *node, *nnode, *rnode, *nrnode;
3476 struct prefix *range;
3477 afi_t afi;
3478 char buf[PREFIX2STR_BUFFER];
3479
3480 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
3481 vty_out(vty, " bgp listen limit %d\n",
3482 bgp->dynamic_neighbors_limit);
3483
3484 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
3485 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
3486 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
3487 nrnode, range)) {
3488 prefix2str(range, buf, sizeof(buf));
3489 vty_out(vty,
3490 " bgp listen range %s peer-group %s\n",
3491 buf, group->name);
3492 }
3493 }
3494 }
3495 }
3496
3497
3498 DEFUN (bgp_disable_connected_route_check,
3499 bgp_disable_connected_route_check_cmd,
3500 "bgp disable-ebgp-connected-route-check",
3501 "BGP specific commands\n"
3502 "Disable checking if nexthop is connected on ebgp sessions\n")
3503 {
3504 VTY_DECLVAR_CONTEXT(bgp, bgp);
3505 SET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
3506 bgp_clear_star_soft_in(vty, bgp->name);
3507
3508 return CMD_SUCCESS;
3509 }
3510
3511 DEFUN (no_bgp_disable_connected_route_check,
3512 no_bgp_disable_connected_route_check_cmd,
3513 "no bgp disable-ebgp-connected-route-check",
3514 NO_STR
3515 "BGP specific commands\n"
3516 "Disable checking if nexthop is connected on ebgp sessions\n")
3517 {
3518 VTY_DECLVAR_CONTEXT(bgp, bgp);
3519 UNSET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
3520 bgp_clear_star_soft_in(vty, bgp->name);
3521
3522 return CMD_SUCCESS;
3523 }
3524
3525
3526 static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
3527 const char *as_str, afi_t afi, safi_t safi)
3528 {
3529 VTY_DECLVAR_CONTEXT(bgp, bgp);
3530 int ret;
3531 as_t as;
3532 int as_type = AS_SPECIFIED;
3533 union sockunion su;
3534
3535 if (as_str[0] == 'i') {
3536 as = 0;
3537 as_type = AS_INTERNAL;
3538 } else if (as_str[0] == 'e') {
3539 as = 0;
3540 as_type = AS_EXTERNAL;
3541 } else {
3542 /* Get AS number. */
3543 as = strtoul(as_str, NULL, 10);
3544 }
3545
3546 /* If peer is peer group or interface peer, call proper function. */
3547 ret = str2sockunion(peer_str, &su);
3548 if (ret < 0) {
3549 struct peer *peer;
3550
3551 /* Check if existing interface peer */
3552 peer = peer_lookup_by_conf_if(bgp, peer_str);
3553
3554 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, afi,
3555 safi);
3556
3557 /* if not interface peer, check peer-group settings */
3558 if (ret < 0 && !peer) {
3559 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
3560 if (ret < 0) {
3561 vty_out(vty,
3562 "%% Create the peer-group or interface first\n");
3563 return CMD_WARNING_CONFIG_FAILED;
3564 }
3565 return CMD_SUCCESS;
3566 }
3567 } else {
3568 if (peer_address_self_check(bgp, &su)) {
3569 vty_out(vty,
3570 "%% Can not configure the local system as neighbor\n");
3571 return CMD_WARNING_CONFIG_FAILED;
3572 }
3573 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, afi, safi);
3574 }
3575
3576 /* This peer belongs to peer group. */
3577 switch (ret) {
3578 case BGP_ERR_PEER_GROUP_MEMBER:
3579 vty_out(vty,
3580 "%% Peer-group member cannot override remote-as of peer-group\n");
3581 return CMD_WARNING_CONFIG_FAILED;
3582 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
3583 vty_out(vty,
3584 "%% Peer-group members must be all internal or all external\n");
3585 return CMD_WARNING_CONFIG_FAILED;
3586 }
3587 return bgp_vty_return(vty, ret);
3588 }
3589
3590 DEFUN (bgp_default_shutdown,
3591 bgp_default_shutdown_cmd,
3592 "[no] bgp default shutdown",
3593 NO_STR
3594 BGP_STR
3595 "Configure BGP defaults\n"
3596 "Apply administrative shutdown to newly configured peers\n")
3597 {
3598 VTY_DECLVAR_CONTEXT(bgp, bgp);
3599 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
3600 return CMD_SUCCESS;
3601 }
3602
3603 DEFPY(bgp_shutdown_msg, bgp_shutdown_msg_cmd, "bgp shutdown message MSG...",
3604 BGP_STR
3605 "Enable administrative shutdown of the BGP instance\n"
3606 "Add a shutdown message (RFC 8203)\n"
3607 "Shutdown message\n")
3608 {
3609 char *msgstr = NULL;
3610
3611 VTY_DECLVAR_CONTEXT(bgp, bgp);
3612
3613 if (argc > 3)
3614 msgstr = argv_concat(argv, argc, 3);
3615
3616 bgp_shutdown_enable(bgp, msgstr);
3617 XFREE(MTYPE_TMP, msgstr);
3618
3619 return CMD_SUCCESS;
3620 }
3621
3622 DEFPY(bgp_shutdown, bgp_shutdown_cmd, "bgp shutdown",
3623 BGP_STR "Enable administrative shutdown of the BGP instance\n")
3624 {
3625 VTY_DECLVAR_CONTEXT(bgp, bgp);
3626
3627 bgp_shutdown_enable(bgp, NULL);
3628
3629 return CMD_SUCCESS;
3630 }
3631
3632 DEFPY(no_bgp_shutdown, no_bgp_shutdown_cmd, "no bgp shutdown",
3633 NO_STR BGP_STR "Disable administrative shutdown of the BGP instance\n")
3634 {
3635 VTY_DECLVAR_CONTEXT(bgp, bgp);
3636
3637 bgp_shutdown_disable(bgp);
3638
3639 return CMD_SUCCESS;
3640 }
3641
3642 DEFPY(no_bgp_shutdown_msg, no_bgp_shutdown_msg_cmd,
3643 "no bgp shutdown message MSG...", NO_STR BGP_STR
3644 "Disable administrative shutdown of the BGP instance\n"
3645 "Add a shutdown message (RFC 8203)\n" "Shutdown message\n")
3646 {
3647 VTY_DECLVAR_CONTEXT(bgp, bgp);
3648
3649 bgp_shutdown_disable(bgp);
3650
3651 return CMD_SUCCESS;
3652 }
3653
3654 DEFUN (neighbor_remote_as,
3655 neighbor_remote_as_cmd,
3656 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
3657 NEIGHBOR_STR
3658 NEIGHBOR_ADDR_STR2
3659 "Specify a BGP neighbor\n"
3660 AS_STR
3661 "Internal BGP peer\n"
3662 "External BGP peer\n")
3663 {
3664 int idx_peer = 1;
3665 int idx_remote_as = 3;
3666 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
3667 argv[idx_remote_as]->arg, AFI_IP,
3668 SAFI_UNICAST);
3669 }
3670
3671 static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
3672 afi_t afi, safi_t safi, int v6only,
3673 const char *peer_group_name,
3674 const char *as_str)
3675 {
3676 VTY_DECLVAR_CONTEXT(bgp, bgp);
3677 as_t as = 0;
3678 int as_type = AS_UNSPECIFIED;
3679 struct peer *peer;
3680 struct peer_group *group;
3681 int ret = 0;
3682 union sockunion su;
3683
3684 group = peer_group_lookup(bgp, conf_if);
3685
3686 if (group) {
3687 vty_out(vty, "%% Name conflict with peer-group \n");
3688 return CMD_WARNING_CONFIG_FAILED;
3689 }
3690
3691 if (as_str) {
3692 if (as_str[0] == 'i') {
3693 as_type = AS_INTERNAL;
3694 } else if (as_str[0] == 'e') {
3695 as_type = AS_EXTERNAL;
3696 } else {
3697 /* Get AS number. */
3698 as = strtoul(as_str, NULL, 10);
3699 as_type = AS_SPECIFIED;
3700 }
3701 }
3702
3703 peer = peer_lookup_by_conf_if(bgp, conf_if);
3704 if (peer) {
3705 if (as_str)
3706 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type,
3707 afi, safi);
3708 } else {
3709 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4)
3710 && afi == AFI_IP && safi == SAFI_UNICAST)
3711 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
3712 as_type, 0, 0, NULL);
3713 else
3714 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
3715 as_type, afi, safi, NULL);
3716
3717 if (!peer) {
3718 vty_out(vty, "%% BGP failed to create peer\n");
3719 return CMD_WARNING_CONFIG_FAILED;
3720 }
3721
3722 if (v6only)
3723 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
3724
3725 /* Request zebra to initiate IPv6 RAs on this interface. We do
3726 * this
3727 * any unnumbered peer in order to not worry about run-time
3728 * transitions
3729 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
3730 * address
3731 * gets deleted later etc.)
3732 */
3733 if (peer->ifp)
3734 bgp_zebra_initiate_radv(bgp, peer);
3735 }
3736
3737 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
3738 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
3739 if (v6only)
3740 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
3741 else
3742 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
3743
3744 /* v6only flag changed. Reset bgp seesion */
3745 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
3746 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
3747 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
3748 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
3749 } else
3750 bgp_session_reset(peer);
3751 }
3752
3753 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
3754 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
3755 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
3756 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
3757 }
3758
3759 if (peer_group_name) {
3760 group = peer_group_lookup(bgp, peer_group_name);
3761 if (!group) {
3762 vty_out(vty, "%% Configure the peer-group first\n");
3763 return CMD_WARNING_CONFIG_FAILED;
3764 }
3765
3766 ret = peer_group_bind(bgp, &su, peer, group, &as);
3767 }
3768
3769 return bgp_vty_return(vty, ret);
3770 }
3771
3772 DEFUN (neighbor_interface_config,
3773 neighbor_interface_config_cmd,
3774 "neighbor WORD interface [peer-group PGNAME]",
3775 NEIGHBOR_STR
3776 "Interface name or neighbor tag\n"
3777 "Enable BGP on interface\n"
3778 "Member of the peer-group\n"
3779 "Peer-group name\n")
3780 {
3781 int idx_word = 1;
3782 int idx_peer_group_word = 4;
3783
3784 if (argc > idx_peer_group_word)
3785 return peer_conf_interface_get(
3786 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
3787 argv[idx_peer_group_word]->arg, NULL);
3788 else
3789 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3790 SAFI_UNICAST, 0, NULL, NULL);
3791 }
3792
3793 DEFUN (neighbor_interface_config_v6only,
3794 neighbor_interface_config_v6only_cmd,
3795 "neighbor WORD interface v6only [peer-group PGNAME]",
3796 NEIGHBOR_STR
3797 "Interface name or neighbor tag\n"
3798 "Enable BGP on interface\n"
3799 "Enable BGP with v6 link-local only\n"
3800 "Member of the peer-group\n"
3801 "Peer-group name\n")
3802 {
3803 int idx_word = 1;
3804 int idx_peer_group_word = 5;
3805
3806 if (argc > idx_peer_group_word)
3807 return peer_conf_interface_get(
3808 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
3809 argv[idx_peer_group_word]->arg, NULL);
3810
3811 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3812 SAFI_UNICAST, 1, NULL, NULL);
3813 }
3814
3815
3816 DEFUN (neighbor_interface_config_remote_as,
3817 neighbor_interface_config_remote_as_cmd,
3818 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
3819 NEIGHBOR_STR
3820 "Interface name or neighbor tag\n"
3821 "Enable BGP on interface\n"
3822 "Specify a BGP neighbor\n"
3823 AS_STR
3824 "Internal BGP peer\n"
3825 "External BGP peer\n")
3826 {
3827 int idx_word = 1;
3828 int idx_remote_as = 4;
3829 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3830 SAFI_UNICAST, 0, NULL,
3831 argv[idx_remote_as]->arg);
3832 }
3833
3834 DEFUN (neighbor_interface_v6only_config_remote_as,
3835 neighbor_interface_v6only_config_remote_as_cmd,
3836 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
3837 NEIGHBOR_STR
3838 "Interface name or neighbor tag\n"
3839 "Enable BGP with v6 link-local only\n"
3840 "Enable BGP on interface\n"
3841 "Specify a BGP neighbor\n"
3842 AS_STR
3843 "Internal BGP peer\n"
3844 "External BGP peer\n")
3845 {
3846 int idx_word = 1;
3847 int idx_remote_as = 5;
3848 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3849 SAFI_UNICAST, 1, NULL,
3850 argv[idx_remote_as]->arg);
3851 }
3852
3853 DEFUN (neighbor_peer_group,
3854 neighbor_peer_group_cmd,
3855 "neighbor WORD peer-group",
3856 NEIGHBOR_STR
3857 "Interface name or neighbor tag\n"
3858 "Configure peer-group\n")
3859 {
3860 VTY_DECLVAR_CONTEXT(bgp, bgp);
3861 int idx_word = 1;
3862 struct peer *peer;
3863 struct peer_group *group;
3864
3865 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3866 if (peer) {
3867 vty_out(vty, "%% Name conflict with interface: \n");
3868 return CMD_WARNING_CONFIG_FAILED;
3869 }
3870
3871 group = peer_group_get(bgp, argv[idx_word]->arg);
3872 if (!group) {
3873 vty_out(vty, "%% BGP failed to find or create peer-group\n");
3874 return CMD_WARNING_CONFIG_FAILED;
3875 }
3876
3877 return CMD_SUCCESS;
3878 }
3879
3880 DEFUN (no_neighbor,
3881 no_neighbor_cmd,
3882 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
3883 NO_STR
3884 NEIGHBOR_STR
3885 NEIGHBOR_ADDR_STR2
3886 "Specify a BGP neighbor\n"
3887 AS_STR
3888 "Internal BGP peer\n"
3889 "External BGP peer\n")
3890 {
3891 VTY_DECLVAR_CONTEXT(bgp, bgp);
3892 int idx_peer = 2;
3893 int ret;
3894 union sockunion su;
3895 struct peer_group *group;
3896 struct peer *peer;
3897 struct peer *other;
3898
3899 ret = str2sockunion(argv[idx_peer]->arg, &su);
3900 if (ret < 0) {
3901 /* look up for neighbor by interface name config. */
3902 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3903 if (peer) {
3904 /* Request zebra to terminate IPv6 RAs on this
3905 * interface. */
3906 if (peer->ifp)
3907 bgp_zebra_terminate_radv(peer->bgp, peer);
3908 peer_notify_unconfig(peer);
3909 peer_delete(peer);
3910 return CMD_SUCCESS;
3911 }
3912
3913 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
3914 if (group) {
3915 peer_group_notify_unconfig(group);
3916 peer_group_delete(group);
3917 } else {
3918 vty_out(vty, "%% Create the peer-group first\n");
3919 return CMD_WARNING_CONFIG_FAILED;
3920 }
3921 } else {
3922 peer = peer_lookup(bgp, &su);
3923 if (peer) {
3924 if (peer_dynamic_neighbor(peer)) {
3925 vty_out(vty,
3926 "%% Operation not allowed on a dynamic neighbor\n");
3927 return CMD_WARNING_CONFIG_FAILED;
3928 }
3929
3930 other = peer->doppelganger;
3931
3932 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
3933 bgp_zebra_terminate_radv(peer->bgp, peer);
3934
3935 peer_notify_unconfig(peer);
3936 peer_delete(peer);
3937 if (other && other->status != Deleted) {
3938 peer_notify_unconfig(other);
3939 peer_delete(other);
3940 }
3941 }
3942 }
3943
3944 return CMD_SUCCESS;
3945 }
3946
3947 DEFUN (no_neighbor_interface_config,
3948 no_neighbor_interface_config_cmd,
3949 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
3950 NO_STR
3951 NEIGHBOR_STR
3952 "Interface name\n"
3953 "Configure BGP on interface\n"
3954 "Enable BGP with v6 link-local only\n"
3955 "Member of the peer-group\n"
3956 "Peer-group name\n"
3957 "Specify a BGP neighbor\n"
3958 AS_STR
3959 "Internal BGP peer\n"
3960 "External BGP peer\n")
3961 {
3962 VTY_DECLVAR_CONTEXT(bgp, bgp);
3963 int idx_word = 2;
3964 struct peer *peer;
3965
3966 /* look up for neighbor by interface name config. */
3967 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3968 if (peer) {
3969 /* Request zebra to terminate IPv6 RAs on this interface. */
3970 if (peer->ifp)
3971 bgp_zebra_terminate_radv(peer->bgp, peer);
3972 peer_notify_unconfig(peer);
3973 peer_delete(peer);
3974 } else {
3975 vty_out(vty, "%% Create the bgp interface first\n");
3976 return CMD_WARNING_CONFIG_FAILED;
3977 }
3978 return CMD_SUCCESS;
3979 }
3980
3981 DEFUN (no_neighbor_peer_group,
3982 no_neighbor_peer_group_cmd,
3983 "no neighbor WORD peer-group",
3984 NO_STR
3985 NEIGHBOR_STR
3986 "Neighbor tag\n"
3987 "Configure peer-group\n")
3988 {
3989 VTY_DECLVAR_CONTEXT(bgp, bgp);
3990 int idx_word = 2;
3991 struct peer_group *group;
3992
3993 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3994 if (group) {
3995 peer_group_notify_unconfig(group);
3996 peer_group_delete(group);
3997 } else {
3998 vty_out(vty, "%% Create the peer-group first\n");
3999 return CMD_WARNING_CONFIG_FAILED;
4000 }
4001 return CMD_SUCCESS;
4002 }
4003
4004 DEFUN (no_neighbor_interface_peer_group_remote_as,
4005 no_neighbor_interface_peer_group_remote_as_cmd,
4006 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
4007 NO_STR
4008 NEIGHBOR_STR
4009 "Interface name or neighbor tag\n"
4010 "Specify a BGP neighbor\n"
4011 AS_STR
4012 "Internal BGP peer\n"
4013 "External BGP peer\n")
4014 {
4015 VTY_DECLVAR_CONTEXT(bgp, bgp);
4016 int idx_word = 2;
4017 struct peer_group *group;
4018 struct peer *peer;
4019
4020 /* look up for neighbor by interface name config. */
4021 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4022 if (peer) {
4023 peer_as_change(peer, 0, AS_UNSPECIFIED);
4024 return CMD_SUCCESS;
4025 }
4026
4027 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4028 if (group)
4029 peer_group_remote_as_delete(group);
4030 else {
4031 vty_out(vty, "%% Create the peer-group or interface first\n");
4032 return CMD_WARNING_CONFIG_FAILED;
4033 }
4034 return CMD_SUCCESS;
4035 }
4036
4037 DEFUN (neighbor_local_as,
4038 neighbor_local_as_cmd,
4039 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
4040 NEIGHBOR_STR
4041 NEIGHBOR_ADDR_STR2
4042 "Specify a local-as number\n"
4043 "AS number used as local AS\n")
4044 {
4045 int idx_peer = 1;
4046 int idx_number = 3;
4047 struct peer *peer;
4048 int ret;
4049 as_t as;
4050
4051 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4052 if (!peer)
4053 return CMD_WARNING_CONFIG_FAILED;
4054
4055 as = strtoul(argv[idx_number]->arg, NULL, 10);
4056 ret = peer_local_as_set(peer, as, 0, 0);
4057 return bgp_vty_return(vty, ret);
4058 }
4059
4060 DEFUN (neighbor_local_as_no_prepend,
4061 neighbor_local_as_no_prepend_cmd,
4062 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
4063 NEIGHBOR_STR
4064 NEIGHBOR_ADDR_STR2
4065 "Specify a local-as number\n"
4066 "AS number used as local AS\n"
4067 "Do not prepend local-as to updates from ebgp peers\n")
4068 {
4069 int idx_peer = 1;
4070 int idx_number = 3;
4071 struct peer *peer;
4072 int ret;
4073 as_t as;
4074
4075 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4076 if (!peer)
4077 return CMD_WARNING_CONFIG_FAILED;
4078
4079 as = strtoul(argv[idx_number]->arg, NULL, 10);
4080 ret = peer_local_as_set(peer, as, 1, 0);
4081 return bgp_vty_return(vty, ret);
4082 }
4083
4084 DEFUN (neighbor_local_as_no_prepend_replace_as,
4085 neighbor_local_as_no_prepend_replace_as_cmd,
4086 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
4087 NEIGHBOR_STR
4088 NEIGHBOR_ADDR_STR2
4089 "Specify a local-as number\n"
4090 "AS number used as local AS\n"
4091 "Do not prepend local-as to updates from ebgp peers\n"
4092 "Do not prepend local-as to updates from ibgp peers\n")
4093 {
4094 int idx_peer = 1;
4095 int idx_number = 3;
4096 struct peer *peer;
4097 int ret;
4098 as_t as;
4099
4100 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4101 if (!peer)
4102 return CMD_WARNING_CONFIG_FAILED;
4103
4104 as = strtoul(argv[idx_number]->arg, NULL, 10);
4105 ret = peer_local_as_set(peer, as, 1, 1);
4106 return bgp_vty_return(vty, ret);
4107 }
4108
4109 DEFUN (no_neighbor_local_as,
4110 no_neighbor_local_as_cmd,
4111 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
4112 NO_STR
4113 NEIGHBOR_STR
4114 NEIGHBOR_ADDR_STR2
4115 "Specify a local-as number\n"
4116 "AS number used as local AS\n"
4117 "Do not prepend local-as to updates from ebgp peers\n"
4118 "Do not prepend local-as to updates from ibgp peers\n")
4119 {
4120 int idx_peer = 2;
4121 struct peer *peer;
4122 int ret;
4123
4124 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4125 if (!peer)
4126 return CMD_WARNING_CONFIG_FAILED;
4127
4128 ret = peer_local_as_unset(peer);
4129 return bgp_vty_return(vty, ret);
4130 }
4131
4132
4133 DEFUN (neighbor_solo,
4134 neighbor_solo_cmd,
4135 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
4136 NEIGHBOR_STR
4137 NEIGHBOR_ADDR_STR2
4138 "Solo peer - part of its own update group\n")
4139 {
4140 int idx_peer = 1;
4141 struct peer *peer;
4142 int ret;
4143
4144 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4145 if (!peer)
4146 return CMD_WARNING_CONFIG_FAILED;
4147
4148 ret = update_group_adjust_soloness(peer, 1);
4149 return bgp_vty_return(vty, ret);
4150 }
4151
4152 DEFUN (no_neighbor_solo,
4153 no_neighbor_solo_cmd,
4154 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
4155 NO_STR
4156 NEIGHBOR_STR
4157 NEIGHBOR_ADDR_STR2
4158 "Solo peer - part of its own update group\n")
4159 {
4160 int idx_peer = 2;
4161 struct peer *peer;
4162 int ret;
4163
4164 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4165 if (!peer)
4166 return CMD_WARNING_CONFIG_FAILED;
4167
4168 ret = update_group_adjust_soloness(peer, 0);
4169 return bgp_vty_return(vty, ret);
4170 }
4171
4172 DEFUN (neighbor_password,
4173 neighbor_password_cmd,
4174 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
4175 NEIGHBOR_STR
4176 NEIGHBOR_ADDR_STR2
4177 "Set a password\n"
4178 "The password\n")
4179 {
4180 int idx_peer = 1;
4181 int idx_line = 3;
4182 struct peer *peer;
4183 int ret;
4184
4185 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4186 if (!peer)
4187 return CMD_WARNING_CONFIG_FAILED;
4188
4189 ret = peer_password_set(peer, argv[idx_line]->arg);
4190 return bgp_vty_return(vty, ret);
4191 }
4192
4193 DEFUN (no_neighbor_password,
4194 no_neighbor_password_cmd,
4195 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
4196 NO_STR
4197 NEIGHBOR_STR
4198 NEIGHBOR_ADDR_STR2
4199 "Set a password\n"
4200 "The password\n")
4201 {
4202 int idx_peer = 2;
4203 struct peer *peer;
4204 int ret;
4205
4206 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4207 if (!peer)
4208 return CMD_WARNING_CONFIG_FAILED;
4209
4210 ret = peer_password_unset(peer);
4211 return bgp_vty_return(vty, ret);
4212 }
4213
4214 DEFUN (neighbor_activate,
4215 neighbor_activate_cmd,
4216 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4217 NEIGHBOR_STR
4218 NEIGHBOR_ADDR_STR2
4219 "Enable the Address Family for this Neighbor\n")
4220 {
4221 int idx_peer = 1;
4222 int ret;
4223 struct peer *peer;
4224
4225 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4226 if (!peer)
4227 return CMD_WARNING_CONFIG_FAILED;
4228
4229 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
4230 return bgp_vty_return(vty, ret);
4231 }
4232
4233 ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
4234 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4235 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4236 "Enable the Address Family for this Neighbor\n")
4237
4238 DEFUN (no_neighbor_activate,
4239 no_neighbor_activate_cmd,
4240 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4241 NO_STR
4242 NEIGHBOR_STR
4243 NEIGHBOR_ADDR_STR2
4244 "Enable the Address Family for this Neighbor\n")
4245 {
4246 int idx_peer = 2;
4247 int ret;
4248 struct peer *peer;
4249
4250 /* Lookup peer. */
4251 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4252 if (!peer)
4253 return CMD_WARNING_CONFIG_FAILED;
4254
4255 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
4256 return bgp_vty_return(vty, ret);
4257 }
4258
4259 ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
4260 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4261 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4262 "Enable the Address Family for this Neighbor\n")
4263
4264 DEFUN (neighbor_set_peer_group,
4265 neighbor_set_peer_group_cmd,
4266 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
4267 NEIGHBOR_STR
4268 NEIGHBOR_ADDR_STR2
4269 "Member of the peer-group\n"
4270 "Peer-group name\n")
4271 {
4272 VTY_DECLVAR_CONTEXT(bgp, bgp);
4273 int idx_peer = 1;
4274 int idx_word = 3;
4275 int ret;
4276 as_t as;
4277 union sockunion su;
4278 struct peer *peer;
4279 struct peer_group *group;
4280
4281 ret = str2sockunion(argv[idx_peer]->arg, &su);
4282 if (ret < 0) {
4283 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4284 if (!peer) {
4285 vty_out(vty, "%% Malformed address or name: %s\n",
4286 argv[idx_peer]->arg);
4287 return CMD_WARNING_CONFIG_FAILED;
4288 }
4289 } else {
4290 if (peer_address_self_check(bgp, &su)) {
4291 vty_out(vty,
4292 "%% Can not configure the local system as neighbor\n");
4293 return CMD_WARNING_CONFIG_FAILED;
4294 }
4295
4296 /* Disallow for dynamic neighbor. */
4297 peer = peer_lookup(bgp, &su);
4298 if (peer && peer_dynamic_neighbor(peer)) {
4299 vty_out(vty,
4300 "%% Operation not allowed on a dynamic neighbor\n");
4301 return CMD_WARNING_CONFIG_FAILED;
4302 }
4303 }
4304
4305 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4306 if (!group) {
4307 vty_out(vty, "%% Configure the peer-group first\n");
4308 return CMD_WARNING_CONFIG_FAILED;
4309 }
4310
4311 ret = peer_group_bind(bgp, &su, peer, group, &as);
4312
4313 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
4314 vty_out(vty,
4315 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
4316 as);
4317 return CMD_WARNING_CONFIG_FAILED;
4318 }
4319
4320 return bgp_vty_return(vty, ret);
4321 }
4322
4323 ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
4324 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
4325 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4326 "Member of the peer-group\n"
4327 "Peer-group name\n")
4328
4329 DEFUN (no_neighbor_set_peer_group,
4330 no_neighbor_set_peer_group_cmd,
4331 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
4332 NO_STR
4333 NEIGHBOR_STR
4334 NEIGHBOR_ADDR_STR2
4335 "Member of the peer-group\n"
4336 "Peer-group name\n")
4337 {
4338 VTY_DECLVAR_CONTEXT(bgp, bgp);
4339 int idx_peer = 2;
4340 int idx_word = 4;
4341 int ret;
4342 struct peer *peer;
4343 struct peer_group *group;
4344
4345 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
4346 if (!peer)
4347 return CMD_WARNING_CONFIG_FAILED;
4348
4349 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4350 if (!group) {
4351 vty_out(vty, "%% Configure the peer-group first\n");
4352 return CMD_WARNING_CONFIG_FAILED;
4353 }
4354
4355 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
4356 bgp_zebra_terminate_radv(peer->bgp, peer);
4357
4358 peer_notify_unconfig(peer);
4359 ret = peer_delete(peer);
4360
4361 return bgp_vty_return(vty, ret);
4362 }
4363
4364 ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
4365 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
4366 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4367 "Member of the peer-group\n"
4368 "Peer-group name\n")
4369
4370 static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
4371 uint32_t flag, int set)
4372 {
4373 int ret;
4374 struct peer *peer;
4375
4376 peer = peer_and_group_lookup_vty(vty, ip_str);
4377 if (!peer)
4378 return CMD_WARNING_CONFIG_FAILED;
4379
4380 /*
4381 * If 'neighbor <interface>', then this is for directly connected peers,
4382 * we should not accept disable-connected-check.
4383 */
4384 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
4385 vty_out(vty,
4386 "%s is directly connected peer, cannot accept disable-connected-check\n",
4387 ip_str);
4388 return CMD_WARNING_CONFIG_FAILED;
4389 }
4390
4391 if (!set && flag == PEER_FLAG_SHUTDOWN)
4392 peer_tx_shutdown_message_unset(peer);
4393
4394 if (set)
4395 ret = peer_flag_set(peer, flag);
4396 else
4397 ret = peer_flag_unset(peer, flag);
4398
4399 return bgp_vty_return(vty, ret);
4400 }
4401
4402 static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
4403 {
4404 return peer_flag_modify_vty(vty, ip_str, flag, 1);
4405 }
4406
4407 static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
4408 uint32_t flag)
4409 {
4410 return peer_flag_modify_vty(vty, ip_str, flag, 0);
4411 }
4412
4413 /* neighbor passive. */
4414 DEFUN (neighbor_passive,
4415 neighbor_passive_cmd,
4416 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
4417 NEIGHBOR_STR
4418 NEIGHBOR_ADDR_STR2
4419 "Don't send open messages to this neighbor\n")
4420 {
4421 int idx_peer = 1;
4422 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
4423 }
4424
4425 DEFUN (no_neighbor_passive,
4426 no_neighbor_passive_cmd,
4427 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
4428 NO_STR
4429 NEIGHBOR_STR
4430 NEIGHBOR_ADDR_STR2
4431 "Don't send open messages to this neighbor\n")
4432 {
4433 int idx_peer = 2;
4434 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
4435 }
4436
4437 /* neighbor shutdown. */
4438 DEFUN (neighbor_shutdown_msg,
4439 neighbor_shutdown_msg_cmd,
4440 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
4441 NEIGHBOR_STR
4442 NEIGHBOR_ADDR_STR2
4443 "Administratively shut down this neighbor\n"
4444 "Add a shutdown message (RFC 8203)\n"
4445 "Shutdown message\n")
4446 {
4447 int idx_peer = 1;
4448
4449 if (argc >= 5) {
4450 struct peer *peer =
4451 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4452 char *message;
4453
4454 if (!peer)
4455 return CMD_WARNING_CONFIG_FAILED;
4456 message = argv_concat(argv, argc, 4);
4457 peer_tx_shutdown_message_set(peer, message);
4458 XFREE(MTYPE_TMP, message);
4459 }
4460
4461 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
4462 }
4463
4464 ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
4465 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
4466 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4467 "Administratively shut down this neighbor\n")
4468
4469 DEFUN (no_neighbor_shutdown_msg,
4470 no_neighbor_shutdown_msg_cmd,
4471 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
4472 NO_STR
4473 NEIGHBOR_STR
4474 NEIGHBOR_ADDR_STR2
4475 "Administratively shut down this neighbor\n"
4476 "Remove a shutdown message (RFC 8203)\n"
4477 "Shutdown message\n")
4478 {
4479 int idx_peer = 2;
4480
4481 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4482 PEER_FLAG_SHUTDOWN);
4483 }
4484
4485 ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
4486 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
4487 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4488 "Administratively shut down this neighbor\n")
4489
4490 /* neighbor capability dynamic. */
4491 DEFUN (neighbor_capability_dynamic,
4492 neighbor_capability_dynamic_cmd,
4493 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
4494 NEIGHBOR_STR
4495 NEIGHBOR_ADDR_STR2
4496 "Advertise capability to the peer\n"
4497 "Advertise dynamic capability to this neighbor\n")
4498 {
4499 int idx_peer = 1;
4500 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4501 PEER_FLAG_DYNAMIC_CAPABILITY);
4502 }
4503
4504 DEFUN (no_neighbor_capability_dynamic,
4505 no_neighbor_capability_dynamic_cmd,
4506 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
4507 NO_STR
4508 NEIGHBOR_STR
4509 NEIGHBOR_ADDR_STR2
4510 "Advertise capability to the peer\n"
4511 "Advertise dynamic capability to this neighbor\n")
4512 {
4513 int idx_peer = 2;
4514 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4515 PEER_FLAG_DYNAMIC_CAPABILITY);
4516 }
4517
4518 /* neighbor dont-capability-negotiate */
4519 DEFUN (neighbor_dont_capability_negotiate,
4520 neighbor_dont_capability_negotiate_cmd,
4521 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
4522 NEIGHBOR_STR
4523 NEIGHBOR_ADDR_STR2
4524 "Do not perform capability negotiation\n")
4525 {
4526 int idx_peer = 1;
4527 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4528 PEER_FLAG_DONT_CAPABILITY);
4529 }
4530
4531 DEFUN (no_neighbor_dont_capability_negotiate,
4532 no_neighbor_dont_capability_negotiate_cmd,
4533 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
4534 NO_STR
4535 NEIGHBOR_STR
4536 NEIGHBOR_ADDR_STR2
4537 "Do not perform capability negotiation\n")
4538 {
4539 int idx_peer = 2;
4540 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4541 PEER_FLAG_DONT_CAPABILITY);
4542 }
4543
4544 /* neighbor capability extended next hop encoding */
4545 DEFUN (neighbor_capability_enhe,
4546 neighbor_capability_enhe_cmd,
4547 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
4548 NEIGHBOR_STR
4549 NEIGHBOR_ADDR_STR2
4550 "Advertise capability to the peer\n"
4551 "Advertise extended next-hop capability to the peer\n")
4552 {
4553 int idx_peer = 1;
4554 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4555 PEER_FLAG_CAPABILITY_ENHE);
4556 }
4557
4558 DEFUN (no_neighbor_capability_enhe,
4559 no_neighbor_capability_enhe_cmd,
4560 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
4561 NO_STR
4562 NEIGHBOR_STR
4563 NEIGHBOR_ADDR_STR2
4564 "Advertise capability to the peer\n"
4565 "Advertise extended next-hop capability to the peer\n")
4566 {
4567 int idx_peer = 2;
4568 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4569 PEER_FLAG_CAPABILITY_ENHE);
4570 }
4571
4572 static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
4573 afi_t afi, safi_t safi, uint32_t flag,
4574 int set)
4575 {
4576 int ret;
4577 struct peer *peer;
4578
4579 peer = peer_and_group_lookup_vty(vty, peer_str);
4580 if (!peer)
4581 return CMD_WARNING_CONFIG_FAILED;
4582
4583 if (set)
4584 ret = peer_af_flag_set(peer, afi, safi, flag);
4585 else
4586 ret = peer_af_flag_unset(peer, afi, safi, flag);
4587
4588 return bgp_vty_return(vty, ret);
4589 }
4590
4591 static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
4592 afi_t afi, safi_t safi, uint32_t flag)
4593 {
4594 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
4595 }
4596
4597 static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
4598 afi_t afi, safi_t safi, uint32_t flag)
4599 {
4600 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
4601 }
4602
4603 /* neighbor capability orf prefix-list. */
4604 DEFUN (neighbor_capability_orf_prefix,
4605 neighbor_capability_orf_prefix_cmd,
4606 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
4607 NEIGHBOR_STR
4608 NEIGHBOR_ADDR_STR2
4609 "Advertise capability to the peer\n"
4610 "Advertise ORF capability to the peer\n"
4611 "Advertise prefixlist ORF capability to this neighbor\n"
4612 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
4613 "Capability to RECEIVE the ORF from this neighbor\n"
4614 "Capability to SEND the ORF to this neighbor\n")
4615 {
4616 int idx_send_recv = 5;
4617 char *peer_str = argv[1]->arg;
4618 struct peer *peer;
4619 afi_t afi = bgp_node_afi(vty);
4620 safi_t safi = bgp_node_safi(vty);
4621
4622 peer = peer_and_group_lookup_vty(vty, peer_str);
4623 if (!peer)
4624 return CMD_WARNING_CONFIG_FAILED;
4625
4626 if (strmatch(argv[idx_send_recv]->text, "send"))
4627 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
4628 PEER_FLAG_ORF_PREFIX_SM);
4629
4630 if (strmatch(argv[idx_send_recv]->text, "receive"))
4631 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
4632 PEER_FLAG_ORF_PREFIX_RM);
4633
4634 if (strmatch(argv[idx_send_recv]->text, "both"))
4635 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
4636 PEER_FLAG_ORF_PREFIX_SM)
4637 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
4638 PEER_FLAG_ORF_PREFIX_RM);
4639
4640 return CMD_WARNING_CONFIG_FAILED;
4641 }
4642
4643 ALIAS_HIDDEN(
4644 neighbor_capability_orf_prefix,
4645 neighbor_capability_orf_prefix_hidden_cmd,
4646 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
4647 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4648 "Advertise capability to the peer\n"
4649 "Advertise ORF capability to the peer\n"
4650 "Advertise prefixlist ORF capability to this neighbor\n"
4651 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
4652 "Capability to RECEIVE the ORF from this neighbor\n"
4653 "Capability to SEND the ORF to this neighbor\n")
4654
4655 DEFUN (no_neighbor_capability_orf_prefix,
4656 no_neighbor_capability_orf_prefix_cmd,
4657 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
4658 NO_STR
4659 NEIGHBOR_STR
4660 NEIGHBOR_ADDR_STR2
4661 "Advertise capability to the peer\n"
4662 "Advertise ORF capability to the peer\n"
4663 "Advertise prefixlist ORF capability to this neighbor\n"
4664 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
4665 "Capability to RECEIVE the ORF from this neighbor\n"
4666 "Capability to SEND the ORF to this neighbor\n")
4667 {
4668 int idx_send_recv = 6;
4669 char *peer_str = argv[2]->arg;
4670 struct peer *peer;
4671 afi_t afi = bgp_node_afi(vty);
4672 safi_t safi = bgp_node_safi(vty);
4673
4674 peer = peer_and_group_lookup_vty(vty, peer_str);
4675 if (!peer)
4676 return CMD_WARNING_CONFIG_FAILED;
4677
4678 if (strmatch(argv[idx_send_recv]->text, "send"))
4679 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4680 PEER_FLAG_ORF_PREFIX_SM);
4681
4682 if (strmatch(argv[idx_send_recv]->text, "receive"))
4683 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4684 PEER_FLAG_ORF_PREFIX_RM);
4685
4686 if (strmatch(argv[idx_send_recv]->text, "both"))
4687 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4688 PEER_FLAG_ORF_PREFIX_SM)
4689 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4690 PEER_FLAG_ORF_PREFIX_RM);
4691
4692 return CMD_WARNING_CONFIG_FAILED;
4693 }
4694
4695 ALIAS_HIDDEN(
4696 no_neighbor_capability_orf_prefix,
4697 no_neighbor_capability_orf_prefix_hidden_cmd,
4698 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
4699 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4700 "Advertise capability to the peer\n"
4701 "Advertise ORF capability to the peer\n"
4702 "Advertise prefixlist ORF capability to this neighbor\n"
4703 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
4704 "Capability to RECEIVE the ORF from this neighbor\n"
4705 "Capability to SEND the ORF to this neighbor\n")
4706
4707 /* neighbor next-hop-self. */
4708 DEFUN (neighbor_nexthop_self,
4709 neighbor_nexthop_self_cmd,
4710 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
4711 NEIGHBOR_STR
4712 NEIGHBOR_ADDR_STR2
4713 "Disable the next hop calculation for this neighbor\n")
4714 {
4715 int idx_peer = 1;
4716 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4717 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
4718 }
4719
4720 ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
4721 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
4722 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4723 "Disable the next hop calculation for this neighbor\n")
4724
4725 /* neighbor next-hop-self. */
4726 DEFUN (neighbor_nexthop_self_force,
4727 neighbor_nexthop_self_force_cmd,
4728 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
4729 NEIGHBOR_STR
4730 NEIGHBOR_ADDR_STR2
4731 "Disable the next hop calculation for this neighbor\n"
4732 "Set the next hop to self for reflected routes\n")
4733 {
4734 int idx_peer = 1;
4735 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4736 bgp_node_safi(vty),
4737 PEER_FLAG_FORCE_NEXTHOP_SELF);
4738 }
4739
4740 ALIAS_HIDDEN(neighbor_nexthop_self_force,
4741 neighbor_nexthop_self_force_hidden_cmd,
4742 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
4743 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4744 "Disable the next hop calculation for this neighbor\n"
4745 "Set the next hop to self for reflected routes\n")
4746
4747 ALIAS_HIDDEN(neighbor_nexthop_self_force,
4748 neighbor_nexthop_self_all_hidden_cmd,
4749 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
4750 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4751 "Disable the next hop calculation for this neighbor\n"
4752 "Set the next hop to self for reflected routes\n")
4753
4754 DEFUN (no_neighbor_nexthop_self,
4755 no_neighbor_nexthop_self_cmd,
4756 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
4757 NO_STR
4758 NEIGHBOR_STR
4759 NEIGHBOR_ADDR_STR2
4760 "Disable the next hop calculation for this neighbor\n")
4761 {
4762 int idx_peer = 2;
4763 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4764 bgp_node_afi(vty), bgp_node_safi(vty),
4765 PEER_FLAG_NEXTHOP_SELF);
4766 }
4767
4768 ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
4769 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
4770 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4771 "Disable the next hop calculation for this neighbor\n")
4772
4773 DEFUN (no_neighbor_nexthop_self_force,
4774 no_neighbor_nexthop_self_force_cmd,
4775 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
4776 NO_STR
4777 NEIGHBOR_STR
4778 NEIGHBOR_ADDR_STR2
4779 "Disable the next hop calculation for this neighbor\n"
4780 "Set the next hop to self for reflected routes\n")
4781 {
4782 int idx_peer = 2;
4783 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4784 bgp_node_afi(vty), bgp_node_safi(vty),
4785 PEER_FLAG_FORCE_NEXTHOP_SELF);
4786 }
4787
4788 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
4789 no_neighbor_nexthop_self_force_hidden_cmd,
4790 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
4791 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4792 "Disable the next hop calculation for this neighbor\n"
4793 "Set the next hop to self for reflected routes\n")
4794
4795 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
4796 no_neighbor_nexthop_self_all_hidden_cmd,
4797 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
4798 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4799 "Disable the next hop calculation for this neighbor\n"
4800 "Set the next hop to self for reflected routes\n")
4801
4802 /* neighbor as-override */
4803 DEFUN (neighbor_as_override,
4804 neighbor_as_override_cmd,
4805 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4806 NEIGHBOR_STR
4807 NEIGHBOR_ADDR_STR2
4808 "Override ASNs in outbound updates if aspath equals remote-as\n")
4809 {
4810 int idx_peer = 1;
4811 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4812 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
4813 }
4814
4815 ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
4816 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4817 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4818 "Override ASNs in outbound updates if aspath equals remote-as\n")
4819
4820 DEFUN (no_neighbor_as_override,
4821 no_neighbor_as_override_cmd,
4822 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4823 NO_STR
4824 NEIGHBOR_STR
4825 NEIGHBOR_ADDR_STR2
4826 "Override ASNs in outbound updates if aspath equals remote-as\n")
4827 {
4828 int idx_peer = 2;
4829 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4830 bgp_node_afi(vty), bgp_node_safi(vty),
4831 PEER_FLAG_AS_OVERRIDE);
4832 }
4833
4834 ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
4835 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4836 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4837 "Override ASNs in outbound updates if aspath equals remote-as\n")
4838
4839 /* neighbor remove-private-AS. */
4840 DEFUN (neighbor_remove_private_as,
4841 neighbor_remove_private_as_cmd,
4842 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4843 NEIGHBOR_STR
4844 NEIGHBOR_ADDR_STR2
4845 "Remove private ASNs in outbound updates\n")
4846 {
4847 int idx_peer = 1;
4848 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4849 bgp_node_safi(vty),
4850 PEER_FLAG_REMOVE_PRIVATE_AS);
4851 }
4852
4853 ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
4854 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4855 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4856 "Remove private ASNs in outbound updates\n")
4857
4858 DEFUN (neighbor_remove_private_as_all,
4859 neighbor_remove_private_as_all_cmd,
4860 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4861 NEIGHBOR_STR
4862 NEIGHBOR_ADDR_STR2
4863 "Remove private ASNs in outbound updates\n"
4864 "Apply to all AS numbers\n")
4865 {
4866 int idx_peer = 1;
4867 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4868 bgp_node_safi(vty),
4869 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
4870 }
4871
4872 ALIAS_HIDDEN(neighbor_remove_private_as_all,
4873 neighbor_remove_private_as_all_hidden_cmd,
4874 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4875 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4876 "Remove private ASNs in outbound updates\n"
4877 "Apply to all AS numbers")
4878
4879 DEFUN (neighbor_remove_private_as_replace_as,
4880 neighbor_remove_private_as_replace_as_cmd,
4881 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4882 NEIGHBOR_STR
4883 NEIGHBOR_ADDR_STR2
4884 "Remove private ASNs in outbound updates\n"
4885 "Replace private ASNs with our ASN in outbound updates\n")
4886 {
4887 int idx_peer = 1;
4888 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4889 bgp_node_safi(vty),
4890 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
4891 }
4892
4893 ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
4894 neighbor_remove_private_as_replace_as_hidden_cmd,
4895 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4896 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4897 "Remove private ASNs in outbound updates\n"
4898 "Replace private ASNs with our ASN in outbound updates\n")
4899
4900 DEFUN (neighbor_remove_private_as_all_replace_as,
4901 neighbor_remove_private_as_all_replace_as_cmd,
4902 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4903 NEIGHBOR_STR
4904 NEIGHBOR_ADDR_STR2
4905 "Remove private ASNs in outbound updates\n"
4906 "Apply to all AS numbers\n"
4907 "Replace private ASNs with our ASN in outbound updates\n")
4908 {
4909 int idx_peer = 1;
4910 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4911 bgp_node_safi(vty),
4912 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
4913 }
4914
4915 ALIAS_HIDDEN(
4916 neighbor_remove_private_as_all_replace_as,
4917 neighbor_remove_private_as_all_replace_as_hidden_cmd,
4918 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4919 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4920 "Remove private ASNs in outbound updates\n"
4921 "Apply to all AS numbers\n"
4922 "Replace private ASNs with our ASN in outbound updates\n")
4923
4924 DEFUN (no_neighbor_remove_private_as,
4925 no_neighbor_remove_private_as_cmd,
4926 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4927 NO_STR
4928 NEIGHBOR_STR
4929 NEIGHBOR_ADDR_STR2
4930 "Remove private ASNs in outbound updates\n")
4931 {
4932 int idx_peer = 2;
4933 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4934 bgp_node_afi(vty), bgp_node_safi(vty),
4935 PEER_FLAG_REMOVE_PRIVATE_AS);
4936 }
4937
4938 ALIAS_HIDDEN(no_neighbor_remove_private_as,
4939 no_neighbor_remove_private_as_hidden_cmd,
4940 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4941 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4942 "Remove private ASNs in outbound updates\n")
4943
4944 DEFUN (no_neighbor_remove_private_as_all,
4945 no_neighbor_remove_private_as_all_cmd,
4946 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4947 NO_STR
4948 NEIGHBOR_STR
4949 NEIGHBOR_ADDR_STR2
4950 "Remove private ASNs in outbound updates\n"
4951 "Apply to all AS numbers\n")
4952 {
4953 int idx_peer = 2;
4954 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4955 bgp_node_afi(vty), bgp_node_safi(vty),
4956 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
4957 }
4958
4959 ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
4960 no_neighbor_remove_private_as_all_hidden_cmd,
4961 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4962 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4963 "Remove private ASNs in outbound updates\n"
4964 "Apply to all AS numbers\n")
4965
4966 DEFUN (no_neighbor_remove_private_as_replace_as,
4967 no_neighbor_remove_private_as_replace_as_cmd,
4968 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4969 NO_STR
4970 NEIGHBOR_STR
4971 NEIGHBOR_ADDR_STR2
4972 "Remove private ASNs in outbound updates\n"
4973 "Replace private ASNs with our ASN in outbound updates\n")
4974 {
4975 int idx_peer = 2;
4976 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4977 bgp_node_afi(vty), bgp_node_safi(vty),
4978 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
4979 }
4980
4981 ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
4982 no_neighbor_remove_private_as_replace_as_hidden_cmd,
4983 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4984 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4985 "Remove private ASNs in outbound updates\n"
4986 "Replace private ASNs with our ASN in outbound updates\n")
4987
4988 DEFUN (no_neighbor_remove_private_as_all_replace_as,
4989 no_neighbor_remove_private_as_all_replace_as_cmd,
4990 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4991 NO_STR
4992 NEIGHBOR_STR
4993 NEIGHBOR_ADDR_STR2
4994 "Remove private ASNs in outbound updates\n"
4995 "Apply to all AS numbers\n"
4996 "Replace private ASNs with our ASN in outbound updates\n")
4997 {
4998 int idx_peer = 2;
4999 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5000 bgp_node_afi(vty), bgp_node_safi(vty),
5001 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5002 }
5003
5004 ALIAS_HIDDEN(
5005 no_neighbor_remove_private_as_all_replace_as,
5006 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
5007 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5008 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5009 "Remove private ASNs in outbound updates\n"
5010 "Apply to all AS numbers\n"
5011 "Replace private ASNs with our ASN in outbound updates\n")
5012
5013
5014 /* neighbor send-community. */
5015 DEFUN (neighbor_send_community,
5016 neighbor_send_community_cmd,
5017 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5018 NEIGHBOR_STR
5019 NEIGHBOR_ADDR_STR2
5020 "Send Community attribute to this neighbor\n")
5021 {
5022 int idx_peer = 1;
5023
5024 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5025 bgp_node_safi(vty),
5026 PEER_FLAG_SEND_COMMUNITY);
5027 }
5028
5029 ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
5030 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5031 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5032 "Send Community attribute to this neighbor\n")
5033
5034 DEFUN (no_neighbor_send_community,
5035 no_neighbor_send_community_cmd,
5036 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5037 NO_STR
5038 NEIGHBOR_STR
5039 NEIGHBOR_ADDR_STR2
5040 "Send Community attribute to this neighbor\n")
5041 {
5042 int idx_peer = 2;
5043
5044 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5045 bgp_node_afi(vty), bgp_node_safi(vty),
5046 PEER_FLAG_SEND_COMMUNITY);
5047 }
5048
5049 ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
5050 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5051 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5052 "Send Community attribute to this neighbor\n")
5053
5054 /* neighbor send-community extended. */
5055 DEFUN (neighbor_send_community_type,
5056 neighbor_send_community_type_cmd,
5057 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5058 NEIGHBOR_STR
5059 NEIGHBOR_ADDR_STR2
5060 "Send Community attribute to this neighbor\n"
5061 "Send Standard and Extended Community attributes\n"
5062 "Send Standard, Large and Extended Community attributes\n"
5063 "Send Extended Community attributes\n"
5064 "Send Standard Community attributes\n"
5065 "Send Large Community attributes\n")
5066 {
5067 const char *type = argv[argc - 1]->text;
5068 char *peer_str = argv[1]->arg;
5069 struct peer *peer;
5070 afi_t afi = bgp_node_afi(vty);
5071 safi_t safi = bgp_node_safi(vty);
5072
5073 peer = peer_and_group_lookup_vty(vty, peer_str);
5074 if (!peer)
5075 return CMD_WARNING_CONFIG_FAILED;
5076
5077 if (strmatch(type, "standard"))
5078 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5079 PEER_FLAG_SEND_COMMUNITY);
5080
5081 if (strmatch(type, "extended"))
5082 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5083 PEER_FLAG_SEND_EXT_COMMUNITY);
5084
5085 if (strmatch(type, "large"))
5086 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5087 PEER_FLAG_SEND_LARGE_COMMUNITY);
5088
5089 if (strmatch(type, "both")) {
5090 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5091 PEER_FLAG_SEND_COMMUNITY)
5092 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5093 PEER_FLAG_SEND_EXT_COMMUNITY);
5094 }
5095 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5096 PEER_FLAG_SEND_COMMUNITY)
5097 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5098 PEER_FLAG_SEND_EXT_COMMUNITY)
5099 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5100 PEER_FLAG_SEND_LARGE_COMMUNITY);
5101 }
5102
5103 ALIAS_HIDDEN(
5104 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
5105 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5106 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5107 "Send Community attribute to this neighbor\n"
5108 "Send Standard and Extended Community attributes\n"
5109 "Send Standard, Large and Extended Community attributes\n"
5110 "Send Extended Community attributes\n"
5111 "Send Standard Community attributes\n"
5112 "Send Large Community attributes\n")
5113
5114 DEFUN (no_neighbor_send_community_type,
5115 no_neighbor_send_community_type_cmd,
5116 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5117 NO_STR
5118 NEIGHBOR_STR
5119 NEIGHBOR_ADDR_STR2
5120 "Send Community attribute to this neighbor\n"
5121 "Send Standard and Extended Community attributes\n"
5122 "Send Standard, Large and Extended Community attributes\n"
5123 "Send Extended Community attributes\n"
5124 "Send Standard Community attributes\n"
5125 "Send Large Community attributes\n")
5126 {
5127 const char *type = argv[argc - 1]->text;
5128 char *peer_str = argv[2]->arg;
5129 struct peer *peer;
5130 afi_t afi = bgp_node_afi(vty);
5131 safi_t safi = bgp_node_safi(vty);
5132
5133 peer = peer_and_group_lookup_vty(vty, peer_str);
5134 if (!peer)
5135 return CMD_WARNING_CONFIG_FAILED;
5136
5137 if (strmatch(type, "standard"))
5138 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5139 PEER_FLAG_SEND_COMMUNITY);
5140
5141 if (strmatch(type, "extended"))
5142 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5143 PEER_FLAG_SEND_EXT_COMMUNITY);
5144
5145 if (strmatch(type, "large"))
5146 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5147 PEER_FLAG_SEND_LARGE_COMMUNITY);
5148
5149 if (strmatch(type, "both")) {
5150
5151 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5152 PEER_FLAG_SEND_COMMUNITY)
5153 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5154 PEER_FLAG_SEND_EXT_COMMUNITY);
5155 }
5156
5157 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5158 PEER_FLAG_SEND_COMMUNITY)
5159 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5160 PEER_FLAG_SEND_EXT_COMMUNITY)
5161 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5162 PEER_FLAG_SEND_LARGE_COMMUNITY);
5163 }
5164
5165 ALIAS_HIDDEN(
5166 no_neighbor_send_community_type,
5167 no_neighbor_send_community_type_hidden_cmd,
5168 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5169 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5170 "Send Community attribute to this neighbor\n"
5171 "Send Standard and Extended Community attributes\n"
5172 "Send Standard, Large and Extended Community attributes\n"
5173 "Send Extended Community attributes\n"
5174 "Send Standard Community attributes\n"
5175 "Send Large Community attributes\n")
5176
5177 /* neighbor soft-reconfig. */
5178 DEFUN (neighbor_soft_reconfiguration,
5179 neighbor_soft_reconfiguration_cmd,
5180 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
5181 NEIGHBOR_STR
5182 NEIGHBOR_ADDR_STR2
5183 "Per neighbor soft reconfiguration\n"
5184 "Allow inbound soft reconfiguration for this neighbor\n")
5185 {
5186 int idx_peer = 1;
5187 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5188 bgp_node_safi(vty),
5189 PEER_FLAG_SOFT_RECONFIG);
5190 }
5191
5192 ALIAS_HIDDEN(neighbor_soft_reconfiguration,
5193 neighbor_soft_reconfiguration_hidden_cmd,
5194 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
5195 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5196 "Per neighbor soft reconfiguration\n"
5197 "Allow inbound soft reconfiguration for this neighbor\n")
5198
5199 DEFUN (no_neighbor_soft_reconfiguration,
5200 no_neighbor_soft_reconfiguration_cmd,
5201 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
5202 NO_STR
5203 NEIGHBOR_STR
5204 NEIGHBOR_ADDR_STR2
5205 "Per neighbor soft reconfiguration\n"
5206 "Allow inbound soft reconfiguration for this neighbor\n")
5207 {
5208 int idx_peer = 2;
5209 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5210 bgp_node_afi(vty), bgp_node_safi(vty),
5211 PEER_FLAG_SOFT_RECONFIG);
5212 }
5213
5214 ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
5215 no_neighbor_soft_reconfiguration_hidden_cmd,
5216 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
5217 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5218 "Per neighbor soft reconfiguration\n"
5219 "Allow inbound soft reconfiguration for this neighbor\n")
5220
5221 DEFUN (neighbor_route_reflector_client,
5222 neighbor_route_reflector_client_cmd,
5223 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
5224 NEIGHBOR_STR
5225 NEIGHBOR_ADDR_STR2
5226 "Configure a neighbor as Route Reflector client\n")
5227 {
5228 int idx_peer = 1;
5229 struct peer *peer;
5230
5231
5232 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5233 if (!peer)
5234 return CMD_WARNING_CONFIG_FAILED;
5235
5236 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5237 bgp_node_safi(vty),
5238 PEER_FLAG_REFLECTOR_CLIENT);
5239 }
5240
5241 ALIAS_HIDDEN(neighbor_route_reflector_client,
5242 neighbor_route_reflector_client_hidden_cmd,
5243 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
5244 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5245 "Configure a neighbor as Route Reflector client\n")
5246
5247 DEFUN (no_neighbor_route_reflector_client,
5248 no_neighbor_route_reflector_client_cmd,
5249 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
5250 NO_STR
5251 NEIGHBOR_STR
5252 NEIGHBOR_ADDR_STR2
5253 "Configure a neighbor as Route Reflector client\n")
5254 {
5255 int idx_peer = 2;
5256 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5257 bgp_node_afi(vty), bgp_node_safi(vty),
5258 PEER_FLAG_REFLECTOR_CLIENT);
5259 }
5260
5261 ALIAS_HIDDEN(no_neighbor_route_reflector_client,
5262 no_neighbor_route_reflector_client_hidden_cmd,
5263 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
5264 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5265 "Configure a neighbor as Route Reflector client\n")
5266
5267 /* neighbor route-server-client. */
5268 DEFUN (neighbor_route_server_client,
5269 neighbor_route_server_client_cmd,
5270 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
5271 NEIGHBOR_STR
5272 NEIGHBOR_ADDR_STR2
5273 "Configure a neighbor as Route Server client\n")
5274 {
5275 int idx_peer = 1;
5276 struct peer *peer;
5277
5278 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5279 if (!peer)
5280 return CMD_WARNING_CONFIG_FAILED;
5281 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5282 bgp_node_safi(vty),
5283 PEER_FLAG_RSERVER_CLIENT);
5284 }
5285
5286 ALIAS_HIDDEN(neighbor_route_server_client,
5287 neighbor_route_server_client_hidden_cmd,
5288 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
5289 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5290 "Configure a neighbor as Route Server client\n")
5291
5292 DEFUN (no_neighbor_route_server_client,
5293 no_neighbor_route_server_client_cmd,
5294 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
5295 NO_STR
5296 NEIGHBOR_STR
5297 NEIGHBOR_ADDR_STR2
5298 "Configure a neighbor as Route Server client\n")
5299 {
5300 int idx_peer = 2;
5301 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5302 bgp_node_afi(vty), bgp_node_safi(vty),
5303 PEER_FLAG_RSERVER_CLIENT);
5304 }
5305
5306 ALIAS_HIDDEN(no_neighbor_route_server_client,
5307 no_neighbor_route_server_client_hidden_cmd,
5308 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
5309 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5310 "Configure a neighbor as Route Server client\n")
5311
5312 DEFUN (neighbor_nexthop_local_unchanged,
5313 neighbor_nexthop_local_unchanged_cmd,
5314 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
5315 NEIGHBOR_STR
5316 NEIGHBOR_ADDR_STR2
5317 "Configure treatment of outgoing link-local nexthop attribute\n"
5318 "Leave link-local nexthop unchanged for this peer\n")
5319 {
5320 int idx_peer = 1;
5321 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5322 bgp_node_safi(vty),
5323 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
5324 }
5325
5326 DEFUN (no_neighbor_nexthop_local_unchanged,
5327 no_neighbor_nexthop_local_unchanged_cmd,
5328 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
5329 NO_STR
5330 NEIGHBOR_STR
5331 NEIGHBOR_ADDR_STR2
5332 "Configure treatment of outgoing link-local-nexthop attribute\n"
5333 "Leave link-local nexthop unchanged for this peer\n")
5334 {
5335 int idx_peer = 2;
5336 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5337 bgp_node_afi(vty), bgp_node_safi(vty),
5338 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
5339 }
5340
5341 DEFUN (neighbor_attr_unchanged,
5342 neighbor_attr_unchanged_cmd,
5343 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
5344 NEIGHBOR_STR
5345 NEIGHBOR_ADDR_STR2
5346 "BGP attribute is propagated unchanged to this neighbor\n"
5347 "As-path attribute\n"
5348 "Nexthop attribute\n"
5349 "Med attribute\n")
5350 {
5351 int idx = 0;
5352 char *peer_str = argv[1]->arg;
5353 struct peer *peer;
5354 bool aspath = false;
5355 bool nexthop = false;
5356 bool med = false;
5357 afi_t afi = bgp_node_afi(vty);
5358 safi_t safi = bgp_node_safi(vty);
5359 int ret = 0;
5360
5361 peer = peer_and_group_lookup_vty(vty, peer_str);
5362 if (!peer)
5363 return CMD_WARNING_CONFIG_FAILED;
5364
5365 if (argv_find(argv, argc, "as-path", &idx))
5366 aspath = true;
5367
5368 idx = 0;
5369 if (argv_find(argv, argc, "next-hop", &idx))
5370 nexthop = true;
5371
5372 idx = 0;
5373 if (argv_find(argv, argc, "med", &idx))
5374 med = true;
5375
5376 /* no flags means all of them! */
5377 if (!aspath && !nexthop && !med) {
5378 ret = peer_af_flag_set_vty(vty, peer_str, afi, safi,
5379 PEER_FLAG_AS_PATH_UNCHANGED);
5380 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
5381 PEER_FLAG_NEXTHOP_UNCHANGED);
5382 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
5383 PEER_FLAG_MED_UNCHANGED);
5384 } else {
5385 if (!aspath) {
5386 if (peer_af_flag_check(peer, afi, safi,
5387 PEER_FLAG_AS_PATH_UNCHANGED)) {
5388 ret |= peer_af_flag_unset_vty(
5389 vty, peer_str, afi, safi,
5390 PEER_FLAG_AS_PATH_UNCHANGED);
5391 }
5392 } else
5393 ret |= peer_af_flag_set_vty(
5394 vty, peer_str, afi, safi,
5395 PEER_FLAG_AS_PATH_UNCHANGED);
5396
5397 if (!nexthop) {
5398 if (peer_af_flag_check(peer, afi, safi,
5399 PEER_FLAG_NEXTHOP_UNCHANGED)) {
5400 ret |= peer_af_flag_unset_vty(
5401 vty, peer_str, afi, safi,
5402 PEER_FLAG_NEXTHOP_UNCHANGED);
5403 }
5404 } else
5405 ret |= peer_af_flag_set_vty(
5406 vty, peer_str, afi, safi,
5407 PEER_FLAG_NEXTHOP_UNCHANGED);
5408
5409 if (!med) {
5410 if (peer_af_flag_check(peer, afi, safi,
5411 PEER_FLAG_MED_UNCHANGED)) {
5412 ret |= peer_af_flag_unset_vty(
5413 vty, peer_str, afi, safi,
5414 PEER_FLAG_MED_UNCHANGED);
5415 }
5416 } else
5417 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
5418 PEER_FLAG_MED_UNCHANGED);
5419 }
5420
5421 return ret;
5422 }
5423
5424 ALIAS_HIDDEN(
5425 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
5426 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
5427 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5428 "BGP attribute is propagated unchanged to this neighbor\n"
5429 "As-path attribute\n"
5430 "Nexthop attribute\n"
5431 "Med attribute\n")
5432
5433 DEFUN (no_neighbor_attr_unchanged,
5434 no_neighbor_attr_unchanged_cmd,
5435 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
5436 NO_STR
5437 NEIGHBOR_STR
5438 NEIGHBOR_ADDR_STR2
5439 "BGP attribute is propagated unchanged to this neighbor\n"
5440 "As-path attribute\n"
5441 "Nexthop attribute\n"
5442 "Med attribute\n")
5443 {
5444 int idx = 0;
5445 char *peer_str = argv[2]->arg;
5446 struct peer *peer;
5447 bool aspath = false;
5448 bool nexthop = false;
5449 bool med = false;
5450 afi_t afi = bgp_node_afi(vty);
5451 safi_t safi = bgp_node_safi(vty);
5452 int ret = 0;
5453
5454 peer = peer_and_group_lookup_vty(vty, peer_str);
5455 if (!peer)
5456 return CMD_WARNING_CONFIG_FAILED;
5457
5458 if (argv_find(argv, argc, "as-path", &idx))
5459 aspath = true;
5460
5461 idx = 0;
5462 if (argv_find(argv, argc, "next-hop", &idx))
5463 nexthop = true;
5464
5465 idx = 0;
5466 if (argv_find(argv, argc, "med", &idx))
5467 med = true;
5468
5469 if (!aspath && !nexthop && !med) // no flags means all of them!
5470 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5471 PEER_FLAG_AS_PATH_UNCHANGED)
5472 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5473 PEER_FLAG_NEXTHOP_UNCHANGED)
5474 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5475 PEER_FLAG_MED_UNCHANGED);
5476
5477 if (aspath)
5478 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5479 PEER_FLAG_AS_PATH_UNCHANGED);
5480
5481 if (nexthop)
5482 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5483 PEER_FLAG_NEXTHOP_UNCHANGED);
5484
5485 if (med)
5486 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5487 PEER_FLAG_MED_UNCHANGED);
5488
5489 return ret;
5490 }
5491
5492 ALIAS_HIDDEN(
5493 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
5494 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
5495 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5496 "BGP attribute is propagated unchanged to this neighbor\n"
5497 "As-path attribute\n"
5498 "Nexthop attribute\n"
5499 "Med attribute\n")
5500
5501 /* EBGP multihop configuration. */
5502 static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
5503 const char *ttl_str)
5504 {
5505 struct peer *peer;
5506 unsigned int ttl;
5507
5508 peer = peer_and_group_lookup_vty(vty, ip_str);
5509 if (!peer)
5510 return CMD_WARNING_CONFIG_FAILED;
5511
5512 if (peer->conf_if)
5513 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
5514
5515 if (!ttl_str)
5516 ttl = MAXTTL;
5517 else
5518 ttl = strtoul(ttl_str, NULL, 10);
5519
5520 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
5521 }
5522
5523 static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
5524 {
5525 struct peer *peer;
5526
5527 peer = peer_and_group_lookup_vty(vty, ip_str);
5528 if (!peer)
5529 return CMD_WARNING_CONFIG_FAILED;
5530
5531 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
5532 }
5533
5534 /* neighbor ebgp-multihop. */
5535 DEFUN (neighbor_ebgp_multihop,
5536 neighbor_ebgp_multihop_cmd,
5537 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
5538 NEIGHBOR_STR
5539 NEIGHBOR_ADDR_STR2
5540 "Allow EBGP neighbors not on directly connected networks\n")
5541 {
5542 int idx_peer = 1;
5543 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
5544 }
5545
5546 DEFUN (neighbor_ebgp_multihop_ttl,
5547 neighbor_ebgp_multihop_ttl_cmd,
5548 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
5549 NEIGHBOR_STR
5550 NEIGHBOR_ADDR_STR2
5551 "Allow EBGP neighbors not on directly connected networks\n"
5552 "maximum hop count\n")
5553 {
5554 int idx_peer = 1;
5555 int idx_number = 3;
5556 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
5557 argv[idx_number]->arg);
5558 }
5559
5560 DEFUN (no_neighbor_ebgp_multihop,
5561 no_neighbor_ebgp_multihop_cmd,
5562 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
5563 NO_STR
5564 NEIGHBOR_STR
5565 NEIGHBOR_ADDR_STR2
5566 "Allow EBGP neighbors not on directly connected networks\n"
5567 "maximum hop count\n")
5568 {
5569 int idx_peer = 2;
5570 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
5571 }
5572
5573
5574 /* disable-connected-check */
5575 DEFUN (neighbor_disable_connected_check,
5576 neighbor_disable_connected_check_cmd,
5577 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
5578 NEIGHBOR_STR
5579 NEIGHBOR_ADDR_STR2
5580 "one-hop away EBGP peer using loopback address\n"
5581 "Enforce EBGP neighbors perform multihop\n")
5582 {
5583 int idx_peer = 1;
5584 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5585 PEER_FLAG_DISABLE_CONNECTED_CHECK);
5586 }
5587
5588 DEFUN (no_neighbor_disable_connected_check,
5589 no_neighbor_disable_connected_check_cmd,
5590 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
5591 NO_STR
5592 NEIGHBOR_STR
5593 NEIGHBOR_ADDR_STR2
5594 "one-hop away EBGP peer using loopback address\n"
5595 "Enforce EBGP neighbors perform multihop\n")
5596 {
5597 int idx_peer = 2;
5598 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5599 PEER_FLAG_DISABLE_CONNECTED_CHECK);
5600 }
5601
5602
5603 /* enforce-first-as */
5604 DEFUN (neighbor_enforce_first_as,
5605 neighbor_enforce_first_as_cmd,
5606 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
5607 NEIGHBOR_STR
5608 NEIGHBOR_ADDR_STR2
5609 "Enforce the first AS for EBGP routes\n")
5610 {
5611 int idx_peer = 1;
5612
5613 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5614 PEER_FLAG_ENFORCE_FIRST_AS);
5615 }
5616
5617 DEFUN (no_neighbor_enforce_first_as,
5618 no_neighbor_enforce_first_as_cmd,
5619 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
5620 NO_STR
5621 NEIGHBOR_STR
5622 NEIGHBOR_ADDR_STR2
5623 "Enforce the first AS for EBGP routes\n")
5624 {
5625 int idx_peer = 2;
5626
5627 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5628 PEER_FLAG_ENFORCE_FIRST_AS);
5629 }
5630
5631
5632 DEFUN (neighbor_description,
5633 neighbor_description_cmd,
5634 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
5635 NEIGHBOR_STR
5636 NEIGHBOR_ADDR_STR2
5637 "Neighbor specific description\n"
5638 "Up to 80 characters describing this neighbor\n")
5639 {
5640 int idx_peer = 1;
5641 int idx_line = 3;
5642 struct peer *peer;
5643 char *str;
5644
5645 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5646 if (!peer)
5647 return CMD_WARNING_CONFIG_FAILED;
5648
5649 str = argv_concat(argv, argc, idx_line);
5650
5651 peer_description_set(peer, str);
5652
5653 XFREE(MTYPE_TMP, str);
5654
5655 return CMD_SUCCESS;
5656 }
5657
5658 DEFUN (no_neighbor_description,
5659 no_neighbor_description_cmd,
5660 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
5661 NO_STR
5662 NEIGHBOR_STR
5663 NEIGHBOR_ADDR_STR2
5664 "Neighbor specific description\n")
5665 {
5666 int idx_peer = 2;
5667 struct peer *peer;
5668
5669 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5670 if (!peer)
5671 return CMD_WARNING_CONFIG_FAILED;
5672
5673 peer_description_unset(peer);
5674
5675 return CMD_SUCCESS;
5676 }
5677
5678 ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
5679 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
5680 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5681 "Neighbor specific description\n"
5682 "Up to 80 characters describing this neighbor\n")
5683
5684 /* Neighbor update-source. */
5685 static int peer_update_source_vty(struct vty *vty, const char *peer_str,
5686 const char *source_str)
5687 {
5688 struct peer *peer;
5689 struct prefix p;
5690 union sockunion su;
5691
5692 peer = peer_and_group_lookup_vty(vty, peer_str);
5693 if (!peer)
5694 return CMD_WARNING_CONFIG_FAILED;
5695
5696 if (peer->conf_if)
5697 return CMD_WARNING;
5698
5699 if (source_str) {
5700 if (str2sockunion(source_str, &su) == 0)
5701 peer_update_source_addr_set(peer, &su);
5702 else {
5703 if (str2prefix(source_str, &p)) {
5704 vty_out(vty,
5705 "%% Invalid update-source, remove prefix length \n");
5706 return CMD_WARNING_CONFIG_FAILED;
5707 } else
5708 peer_update_source_if_set(peer, source_str);
5709 }
5710 } else
5711 peer_update_source_unset(peer);
5712
5713 return CMD_SUCCESS;
5714 }
5715
5716 #define BGP_UPDATE_SOURCE_HELP_STR \
5717 "IPv4 address\n" \
5718 "IPv6 address\n" \
5719 "Interface name (requires zebra to be running)\n"
5720
5721 DEFUN (neighbor_update_source,
5722 neighbor_update_source_cmd,
5723 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
5724 NEIGHBOR_STR
5725 NEIGHBOR_ADDR_STR2
5726 "Source of routing updates\n"
5727 BGP_UPDATE_SOURCE_HELP_STR)
5728 {
5729 int idx_peer = 1;
5730 int idx_peer_2 = 3;
5731 return peer_update_source_vty(vty, argv[idx_peer]->arg,
5732 argv[idx_peer_2]->arg);
5733 }
5734
5735 DEFUN (no_neighbor_update_source,
5736 no_neighbor_update_source_cmd,
5737 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
5738 NO_STR
5739 NEIGHBOR_STR
5740 NEIGHBOR_ADDR_STR2
5741 "Source of routing updates\n"
5742 BGP_UPDATE_SOURCE_HELP_STR)
5743 {
5744 int idx_peer = 2;
5745 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
5746 }
5747
5748 static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
5749 afi_t afi, safi_t safi,
5750 const char *rmap, int set)
5751 {
5752 int ret;
5753 struct peer *peer;
5754 struct route_map *route_map = NULL;
5755
5756 peer = peer_and_group_lookup_vty(vty, peer_str);
5757 if (!peer)
5758 return CMD_WARNING_CONFIG_FAILED;
5759
5760 if (set) {
5761 if (rmap)
5762 route_map = route_map_lookup_warn_noexist(vty, rmap);
5763 ret = peer_default_originate_set(peer, afi, safi,
5764 rmap, route_map);
5765 } else
5766 ret = peer_default_originate_unset(peer, afi, safi);
5767
5768 return bgp_vty_return(vty, ret);
5769 }
5770
5771 /* neighbor default-originate. */
5772 DEFUN (neighbor_default_originate,
5773 neighbor_default_originate_cmd,
5774 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
5775 NEIGHBOR_STR
5776 NEIGHBOR_ADDR_STR2
5777 "Originate default route to this neighbor\n")
5778 {
5779 int idx_peer = 1;
5780 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
5781 bgp_node_afi(vty),
5782 bgp_node_safi(vty), NULL, 1);
5783 }
5784
5785 ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
5786 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
5787 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5788 "Originate default route to this neighbor\n")
5789
5790 DEFUN (neighbor_default_originate_rmap,
5791 neighbor_default_originate_rmap_cmd,
5792 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
5793 NEIGHBOR_STR
5794 NEIGHBOR_ADDR_STR2
5795 "Originate default route to this neighbor\n"
5796 "Route-map to specify criteria to originate default\n"
5797 "route-map name\n")
5798 {
5799 int idx_peer = 1;
5800 int idx_word = 4;
5801 return peer_default_originate_set_vty(
5802 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5803 argv[idx_word]->arg, 1);
5804 }
5805
5806 ALIAS_HIDDEN(
5807 neighbor_default_originate_rmap,
5808 neighbor_default_originate_rmap_hidden_cmd,
5809 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
5810 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5811 "Originate default route to this neighbor\n"
5812 "Route-map to specify criteria to originate default\n"
5813 "route-map name\n")
5814
5815 DEFUN (no_neighbor_default_originate,
5816 no_neighbor_default_originate_cmd,
5817 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
5818 NO_STR
5819 NEIGHBOR_STR
5820 NEIGHBOR_ADDR_STR2
5821 "Originate default route to this neighbor\n"
5822 "Route-map to specify criteria to originate default\n"
5823 "route-map name\n")
5824 {
5825 int idx_peer = 2;
5826 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
5827 bgp_node_afi(vty),
5828 bgp_node_safi(vty), NULL, 0);
5829 }
5830
5831 ALIAS_HIDDEN(
5832 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
5833 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
5834 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5835 "Originate default route to this neighbor\n"
5836 "Route-map to specify criteria to originate default\n"
5837 "route-map name\n")
5838
5839
5840 /* Set neighbor's BGP port. */
5841 static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
5842 const char *port_str)
5843 {
5844 struct peer *peer;
5845 uint16_t port;
5846 struct servent *sp;
5847
5848 peer = peer_lookup_vty(vty, ip_str);
5849 if (!peer)
5850 return CMD_WARNING_CONFIG_FAILED;
5851
5852 if (!port_str) {
5853 sp = getservbyname("bgp", "tcp");
5854 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
5855 } else {
5856 port = strtoul(port_str, NULL, 10);
5857 }
5858
5859 peer_port_set(peer, port);
5860
5861 return CMD_SUCCESS;
5862 }
5863
5864 /* Set specified peer's BGP port. */
5865 DEFUN (neighbor_port,
5866 neighbor_port_cmd,
5867 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
5868 NEIGHBOR_STR
5869 NEIGHBOR_ADDR_STR
5870 "Neighbor's BGP port\n"
5871 "TCP port number\n")
5872 {
5873 int idx_ip = 1;
5874 int idx_number = 3;
5875 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
5876 argv[idx_number]->arg);
5877 }
5878
5879 DEFUN (no_neighbor_port,
5880 no_neighbor_port_cmd,
5881 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
5882 NO_STR
5883 NEIGHBOR_STR
5884 NEIGHBOR_ADDR_STR
5885 "Neighbor's BGP port\n"
5886 "TCP port number\n")
5887 {
5888 int idx_ip = 2;
5889 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
5890 }
5891
5892
5893 /* neighbor weight. */
5894 static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5895 safi_t safi, const char *weight_str)
5896 {
5897 int ret;
5898 struct peer *peer;
5899 unsigned long weight;
5900
5901 peer = peer_and_group_lookup_vty(vty, ip_str);
5902 if (!peer)
5903 return CMD_WARNING_CONFIG_FAILED;
5904
5905 weight = strtoul(weight_str, NULL, 10);
5906
5907 ret = peer_weight_set(peer, afi, safi, weight);
5908 return bgp_vty_return(vty, ret);
5909 }
5910
5911 static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5912 safi_t safi)
5913 {
5914 int ret;
5915 struct peer *peer;
5916
5917 peer = peer_and_group_lookup_vty(vty, ip_str);
5918 if (!peer)
5919 return CMD_WARNING_CONFIG_FAILED;
5920
5921 ret = peer_weight_unset(peer, afi, safi);
5922 return bgp_vty_return(vty, ret);
5923 }
5924
5925 DEFUN (neighbor_weight,
5926 neighbor_weight_cmd,
5927 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
5928 NEIGHBOR_STR
5929 NEIGHBOR_ADDR_STR2
5930 "Set default weight for routes from this neighbor\n"
5931 "default weight\n")
5932 {
5933 int idx_peer = 1;
5934 int idx_number = 3;
5935 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5936 bgp_node_safi(vty), argv[idx_number]->arg);
5937 }
5938
5939 ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
5940 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
5941 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5942 "Set default weight for routes from this neighbor\n"
5943 "default weight\n")
5944
5945 DEFUN (no_neighbor_weight,
5946 no_neighbor_weight_cmd,
5947 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
5948 NO_STR
5949 NEIGHBOR_STR
5950 NEIGHBOR_ADDR_STR2
5951 "Set default weight for routes from this neighbor\n"
5952 "default weight\n")
5953 {
5954 int idx_peer = 2;
5955 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
5956 bgp_node_afi(vty), bgp_node_safi(vty));
5957 }
5958
5959 ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
5960 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
5961 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5962 "Set default weight for routes from this neighbor\n"
5963 "default weight\n")
5964
5965
5966 /* Override capability negotiation. */
5967 DEFUN (neighbor_override_capability,
5968 neighbor_override_capability_cmd,
5969 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
5970 NEIGHBOR_STR
5971 NEIGHBOR_ADDR_STR2
5972 "Override capability negotiation result\n")
5973 {
5974 int idx_peer = 1;
5975 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5976 PEER_FLAG_OVERRIDE_CAPABILITY);
5977 }
5978
5979 DEFUN (no_neighbor_override_capability,
5980 no_neighbor_override_capability_cmd,
5981 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
5982 NO_STR
5983 NEIGHBOR_STR
5984 NEIGHBOR_ADDR_STR2
5985 "Override capability negotiation result\n")
5986 {
5987 int idx_peer = 2;
5988 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5989 PEER_FLAG_OVERRIDE_CAPABILITY);
5990 }
5991
5992 DEFUN (neighbor_strict_capability,
5993 neighbor_strict_capability_cmd,
5994 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
5995 NEIGHBOR_STR
5996 NEIGHBOR_ADDR_STR2
5997 "Strict capability negotiation match\n")
5998 {
5999 int idx_peer = 1;
6000
6001 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6002 PEER_FLAG_STRICT_CAP_MATCH);
6003 }
6004
6005 DEFUN (no_neighbor_strict_capability,
6006 no_neighbor_strict_capability_cmd,
6007 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
6008 NO_STR
6009 NEIGHBOR_STR
6010 NEIGHBOR_ADDR_STR2
6011 "Strict capability negotiation match\n")
6012 {
6013 int idx_peer = 2;
6014
6015 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6016 PEER_FLAG_STRICT_CAP_MATCH);
6017 }
6018
6019 static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
6020 const char *keep_str, const char *hold_str)
6021 {
6022 int ret;
6023 struct peer *peer;
6024 uint32_t keepalive;
6025 uint32_t holdtime;
6026
6027 peer = peer_and_group_lookup_vty(vty, ip_str);
6028 if (!peer)
6029 return CMD_WARNING_CONFIG_FAILED;
6030
6031 keepalive = strtoul(keep_str, NULL, 10);
6032 holdtime = strtoul(hold_str, NULL, 10);
6033
6034 ret = peer_timers_set(peer, keepalive, holdtime);
6035
6036 return bgp_vty_return(vty, ret);
6037 }
6038
6039 static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
6040 {
6041 int ret;
6042 struct peer *peer;
6043
6044 peer = peer_and_group_lookup_vty(vty, ip_str);
6045 if (!peer)
6046 return CMD_WARNING_CONFIG_FAILED;
6047
6048 ret = peer_timers_unset(peer);
6049
6050 return bgp_vty_return(vty, ret);
6051 }
6052
6053 DEFUN (neighbor_timers,
6054 neighbor_timers_cmd,
6055 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
6056 NEIGHBOR_STR
6057 NEIGHBOR_ADDR_STR2
6058 "BGP per neighbor timers\n"
6059 "Keepalive interval\n"
6060 "Holdtime\n")
6061 {
6062 int idx_peer = 1;
6063 int idx_number = 3;
6064 int idx_number_2 = 4;
6065 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
6066 argv[idx_number]->arg,
6067 argv[idx_number_2]->arg);
6068 }
6069
6070 DEFUN (no_neighbor_timers,
6071 no_neighbor_timers_cmd,
6072 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
6073 NO_STR
6074 NEIGHBOR_STR
6075 NEIGHBOR_ADDR_STR2
6076 "BGP per neighbor timers\n"
6077 "Keepalive interval\n"
6078 "Holdtime\n")
6079 {
6080 int idx_peer = 2;
6081 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
6082 }
6083
6084
6085 static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
6086 const char *time_str)
6087 {
6088 int ret;
6089 struct peer *peer;
6090 uint32_t connect;
6091
6092 peer = peer_and_group_lookup_vty(vty, ip_str);
6093 if (!peer)
6094 return CMD_WARNING_CONFIG_FAILED;
6095
6096 connect = strtoul(time_str, NULL, 10);
6097
6098 ret = peer_timers_connect_set(peer, connect);
6099
6100 return bgp_vty_return(vty, ret);
6101 }
6102
6103 static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
6104 {
6105 int ret;
6106 struct peer *peer;
6107
6108 peer = peer_and_group_lookup_vty(vty, ip_str);
6109 if (!peer)
6110 return CMD_WARNING_CONFIG_FAILED;
6111
6112 ret = peer_timers_connect_unset(peer);
6113
6114 return bgp_vty_return(vty, ret);
6115 }
6116
6117 DEFUN (neighbor_timers_connect,
6118 neighbor_timers_connect_cmd,
6119 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
6120 NEIGHBOR_STR
6121 NEIGHBOR_ADDR_STR2
6122 "BGP per neighbor timers\n"
6123 "BGP connect timer\n"
6124 "Connect timer\n")
6125 {
6126 int idx_peer = 1;
6127 int idx_number = 4;
6128 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
6129 argv[idx_number]->arg);
6130 }
6131
6132 DEFUN (no_neighbor_timers_connect,
6133 no_neighbor_timers_connect_cmd,
6134 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
6135 NO_STR
6136 NEIGHBOR_STR
6137 NEIGHBOR_ADDR_STR2
6138 "BGP per neighbor timers\n"
6139 "BGP connect timer\n"
6140 "Connect timer\n")
6141 {
6142 int idx_peer = 2;
6143 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
6144 }
6145
6146
6147 static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
6148 const char *time_str, int set)
6149 {
6150 int ret;
6151 struct peer *peer;
6152 uint32_t routeadv = 0;
6153
6154 peer = peer_and_group_lookup_vty(vty, ip_str);
6155 if (!peer)
6156 return CMD_WARNING_CONFIG_FAILED;
6157
6158 if (time_str)
6159 routeadv = strtoul(time_str, NULL, 10);
6160
6161 if (set)
6162 ret = peer_advertise_interval_set(peer, routeadv);
6163 else
6164 ret = peer_advertise_interval_unset(peer);
6165
6166 return bgp_vty_return(vty, ret);
6167 }
6168
6169 DEFUN (neighbor_advertise_interval,
6170 neighbor_advertise_interval_cmd,
6171 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
6172 NEIGHBOR_STR
6173 NEIGHBOR_ADDR_STR2
6174 "Minimum interval between sending BGP routing updates\n"
6175 "time in seconds\n")
6176 {
6177 int idx_peer = 1;
6178 int idx_number = 3;
6179 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
6180 argv[idx_number]->arg, 1);
6181 }
6182
6183 DEFUN (no_neighbor_advertise_interval,
6184 no_neighbor_advertise_interval_cmd,
6185 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
6186 NO_STR
6187 NEIGHBOR_STR
6188 NEIGHBOR_ADDR_STR2
6189 "Minimum interval between sending BGP routing updates\n"
6190 "time in seconds\n")
6191 {
6192 int idx_peer = 2;
6193 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
6194 }
6195
6196
6197 /* Time to wait before processing route-map updates */
6198 DEFUN (bgp_set_route_map_delay_timer,
6199 bgp_set_route_map_delay_timer_cmd,
6200 "bgp route-map delay-timer (0-600)",
6201 SET_STR
6202 "BGP route-map delay timer\n"
6203 "Time in secs to wait before processing route-map changes\n"
6204 "0 disables the timer, no route updates happen when route-maps change\n")
6205 {
6206 int idx_number = 3;
6207 uint32_t rmap_delay_timer;
6208
6209 if (argv[idx_number]->arg) {
6210 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
6211 bm->rmap_update_timer = rmap_delay_timer;
6212
6213 /* if the dynamic update handling is being disabled, and a timer
6214 * is
6215 * running, stop the timer and act as if the timer has already
6216 * fired.
6217 */
6218 if (!rmap_delay_timer && bm->t_rmap_update) {
6219 BGP_TIMER_OFF(bm->t_rmap_update);
6220 thread_execute(bm->master, bgp_route_map_update_timer,
6221 NULL, 0);
6222 }
6223 return CMD_SUCCESS;
6224 } else {
6225 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
6226 return CMD_WARNING_CONFIG_FAILED;
6227 }
6228 }
6229
6230 DEFUN (no_bgp_set_route_map_delay_timer,
6231 no_bgp_set_route_map_delay_timer_cmd,
6232 "no bgp route-map delay-timer [(0-600)]",
6233 NO_STR
6234 BGP_STR
6235 "Default BGP route-map delay timer\n"
6236 "Reset to default time to wait for processing route-map changes\n"
6237 "0 disables the timer, no route updates happen when route-maps change\n")
6238 {
6239
6240 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
6241
6242 return CMD_SUCCESS;
6243 }
6244
6245
6246 /* neighbor interface */
6247 static int peer_interface_vty(struct vty *vty, const char *ip_str,
6248 const char *str)
6249 {
6250 struct peer *peer;
6251
6252 peer = peer_lookup_vty(vty, ip_str);
6253 if (!peer || peer->conf_if) {
6254 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
6255 return CMD_WARNING_CONFIG_FAILED;
6256 }
6257
6258 if (str)
6259 peer_interface_set(peer, str);
6260 else
6261 peer_interface_unset(peer);
6262
6263 return CMD_SUCCESS;
6264 }
6265
6266 DEFUN (neighbor_interface,
6267 neighbor_interface_cmd,
6268 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
6269 NEIGHBOR_STR
6270 NEIGHBOR_ADDR_STR
6271 "Interface\n"
6272 "Interface name\n")
6273 {
6274 int idx_ip = 1;
6275 int idx_word = 3;
6276 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
6277 }
6278
6279 DEFUN (no_neighbor_interface,
6280 no_neighbor_interface_cmd,
6281 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
6282 NO_STR
6283 NEIGHBOR_STR
6284 NEIGHBOR_ADDR_STR2
6285 "Interface\n"
6286 "Interface name\n")
6287 {
6288 int idx_peer = 2;
6289 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
6290 }
6291
6292 DEFUN (neighbor_distribute_list,
6293 neighbor_distribute_list_cmd,
6294 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
6295 NEIGHBOR_STR
6296 NEIGHBOR_ADDR_STR2
6297 "Filter updates to/from this neighbor\n"
6298 "IP access-list number\n"
6299 "IP access-list number (expanded range)\n"
6300 "IP Access-list name\n"
6301 "Filter incoming updates\n"
6302 "Filter outgoing updates\n")
6303 {
6304 int idx_peer = 1;
6305 int idx_acl = 3;
6306 int direct, ret;
6307 struct peer *peer;
6308
6309 const char *pstr = argv[idx_peer]->arg;
6310 const char *acl = argv[idx_acl]->arg;
6311 const char *inout = argv[argc - 1]->text;
6312
6313 peer = peer_and_group_lookup_vty(vty, pstr);
6314 if (!peer)
6315 return CMD_WARNING_CONFIG_FAILED;
6316
6317 /* Check filter direction. */
6318 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
6319 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6320 direct, acl);
6321
6322 return bgp_vty_return(vty, ret);
6323 }
6324
6325 ALIAS_HIDDEN(
6326 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
6327 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
6328 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6329 "Filter updates to/from this neighbor\n"
6330 "IP access-list number\n"
6331 "IP access-list number (expanded range)\n"
6332 "IP Access-list name\n"
6333 "Filter incoming updates\n"
6334 "Filter outgoing updates\n")
6335
6336 DEFUN (no_neighbor_distribute_list,
6337 no_neighbor_distribute_list_cmd,
6338 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
6339 NO_STR
6340 NEIGHBOR_STR
6341 NEIGHBOR_ADDR_STR2
6342 "Filter updates to/from this neighbor\n"
6343 "IP access-list number\n"
6344 "IP access-list number (expanded range)\n"
6345 "IP Access-list name\n"
6346 "Filter incoming updates\n"
6347 "Filter outgoing updates\n")
6348 {
6349 int idx_peer = 2;
6350 int direct, ret;
6351 struct peer *peer;
6352
6353 const char *pstr = argv[idx_peer]->arg;
6354 const char *inout = argv[argc - 1]->text;
6355
6356 peer = peer_and_group_lookup_vty(vty, pstr);
6357 if (!peer)
6358 return CMD_WARNING_CONFIG_FAILED;
6359
6360 /* Check filter direction. */
6361 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
6362 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6363 direct);
6364
6365 return bgp_vty_return(vty, ret);
6366 }
6367
6368 ALIAS_HIDDEN(
6369 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
6370 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
6371 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6372 "Filter updates to/from this neighbor\n"
6373 "IP access-list number\n"
6374 "IP access-list number (expanded range)\n"
6375 "IP Access-list name\n"
6376 "Filter incoming updates\n"
6377 "Filter outgoing updates\n")
6378
6379 /* Set prefix list to the peer. */
6380 static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
6381 afi_t afi, safi_t safi,
6382 const char *name_str,
6383 const char *direct_str)
6384 {
6385 int ret;
6386 int direct = FILTER_IN;
6387 struct peer *peer;
6388
6389 peer = peer_and_group_lookup_vty(vty, ip_str);
6390 if (!peer)
6391 return CMD_WARNING_CONFIG_FAILED;
6392
6393 /* Check filter direction. */
6394 if (strncmp(direct_str, "i", 1) == 0)
6395 direct = FILTER_IN;
6396 else if (strncmp(direct_str, "o", 1) == 0)
6397 direct = FILTER_OUT;
6398
6399 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
6400
6401 return bgp_vty_return(vty, ret);
6402 }
6403
6404 static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
6405 afi_t afi, safi_t safi,
6406 const char *direct_str)
6407 {
6408 int ret;
6409 struct peer *peer;
6410 int direct = FILTER_IN;
6411
6412 peer = peer_and_group_lookup_vty(vty, ip_str);
6413 if (!peer)
6414 return CMD_WARNING_CONFIG_FAILED;
6415
6416 /* Check filter direction. */
6417 if (strncmp(direct_str, "i", 1) == 0)
6418 direct = FILTER_IN;
6419 else if (strncmp(direct_str, "o", 1) == 0)
6420 direct = FILTER_OUT;
6421
6422 ret = peer_prefix_list_unset(peer, afi, safi, direct);
6423
6424 return bgp_vty_return(vty, ret);
6425 }
6426
6427 DEFUN (neighbor_prefix_list,
6428 neighbor_prefix_list_cmd,
6429 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
6430 NEIGHBOR_STR
6431 NEIGHBOR_ADDR_STR2
6432 "Filter updates to/from this neighbor\n"
6433 "Name of a prefix list\n"
6434 "Filter incoming updates\n"
6435 "Filter outgoing updates\n")
6436 {
6437 int idx_peer = 1;
6438 int idx_word = 3;
6439 int idx_in_out = 4;
6440 return peer_prefix_list_set_vty(
6441 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6442 argv[idx_word]->arg, argv[idx_in_out]->arg);
6443 }
6444
6445 ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
6446 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
6447 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6448 "Filter updates to/from this neighbor\n"
6449 "Name of a prefix list\n"
6450 "Filter incoming updates\n"
6451 "Filter outgoing updates\n")
6452
6453 DEFUN (no_neighbor_prefix_list,
6454 no_neighbor_prefix_list_cmd,
6455 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
6456 NO_STR
6457 NEIGHBOR_STR
6458 NEIGHBOR_ADDR_STR2
6459 "Filter updates to/from this neighbor\n"
6460 "Name of a prefix list\n"
6461 "Filter incoming updates\n"
6462 "Filter outgoing updates\n")
6463 {
6464 int idx_peer = 2;
6465 int idx_in_out = 5;
6466 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
6467 bgp_node_afi(vty), bgp_node_safi(vty),
6468 argv[idx_in_out]->arg);
6469 }
6470
6471 ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
6472 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
6473 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6474 "Filter updates to/from this neighbor\n"
6475 "Name of a prefix list\n"
6476 "Filter incoming updates\n"
6477 "Filter outgoing updates\n")
6478
6479 static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
6480 safi_t safi, const char *name_str,
6481 const char *direct_str)
6482 {
6483 int ret;
6484 struct peer *peer;
6485 int direct = FILTER_IN;
6486
6487 peer = peer_and_group_lookup_vty(vty, ip_str);
6488 if (!peer)
6489 return CMD_WARNING_CONFIG_FAILED;
6490
6491 /* Check filter direction. */
6492 if (strncmp(direct_str, "i", 1) == 0)
6493 direct = FILTER_IN;
6494 else if (strncmp(direct_str, "o", 1) == 0)
6495 direct = FILTER_OUT;
6496
6497 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
6498
6499 return bgp_vty_return(vty, ret);
6500 }
6501
6502 static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
6503 safi_t safi, const char *direct_str)
6504 {
6505 int ret;
6506 struct peer *peer;
6507 int direct = FILTER_IN;
6508
6509 peer = peer_and_group_lookup_vty(vty, ip_str);
6510 if (!peer)
6511 return CMD_WARNING_CONFIG_FAILED;
6512
6513 /* Check filter direction. */
6514 if (strncmp(direct_str, "i", 1) == 0)
6515 direct = FILTER_IN;
6516 else if (strncmp(direct_str, "o", 1) == 0)
6517 direct = FILTER_OUT;
6518
6519 ret = peer_aslist_unset(peer, afi, safi, direct);
6520
6521 return bgp_vty_return(vty, ret);
6522 }
6523
6524 DEFUN (neighbor_filter_list,
6525 neighbor_filter_list_cmd,
6526 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
6527 NEIGHBOR_STR
6528 NEIGHBOR_ADDR_STR2
6529 "Establish BGP filters\n"
6530 "AS path access-list name\n"
6531 "Filter incoming routes\n"
6532 "Filter outgoing routes\n")
6533 {
6534 int idx_peer = 1;
6535 int idx_word = 3;
6536 int idx_in_out = 4;
6537 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6538 bgp_node_safi(vty), argv[idx_word]->arg,
6539 argv[idx_in_out]->arg);
6540 }
6541
6542 ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
6543 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
6544 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6545 "Establish BGP filters\n"
6546 "AS path access-list name\n"
6547 "Filter incoming routes\n"
6548 "Filter outgoing routes\n")
6549
6550 DEFUN (no_neighbor_filter_list,
6551 no_neighbor_filter_list_cmd,
6552 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
6553 NO_STR
6554 NEIGHBOR_STR
6555 NEIGHBOR_ADDR_STR2
6556 "Establish BGP filters\n"
6557 "AS path access-list name\n"
6558 "Filter incoming routes\n"
6559 "Filter outgoing routes\n")
6560 {
6561 int idx_peer = 2;
6562 int idx_in_out = 5;
6563 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
6564 bgp_node_afi(vty), bgp_node_safi(vty),
6565 argv[idx_in_out]->arg);
6566 }
6567
6568 ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
6569 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
6570 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6571 "Establish BGP filters\n"
6572 "AS path access-list name\n"
6573 "Filter incoming routes\n"
6574 "Filter outgoing routes\n")
6575
6576 /* Set route-map to the peer. */
6577 static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
6578 afi_t afi, safi_t safi, const char *name_str,
6579 const char *direct_str)
6580 {
6581 int ret;
6582 struct peer *peer;
6583 int direct = RMAP_IN;
6584 struct route_map *route_map;
6585
6586 peer = peer_and_group_lookup_vty(vty, ip_str);
6587 if (!peer)
6588 return CMD_WARNING_CONFIG_FAILED;
6589
6590 /* Check filter direction. */
6591 if (strncmp(direct_str, "in", 2) == 0)
6592 direct = RMAP_IN;
6593 else if (strncmp(direct_str, "o", 1) == 0)
6594 direct = RMAP_OUT;
6595
6596 route_map = route_map_lookup_warn_noexist(vty, name_str);
6597 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
6598
6599 return bgp_vty_return(vty, ret);
6600 }
6601
6602 static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
6603 afi_t afi, safi_t safi,
6604 const char *direct_str)
6605 {
6606 int ret;
6607 struct peer *peer;
6608 int direct = RMAP_IN;
6609
6610 peer = peer_and_group_lookup_vty(vty, ip_str);
6611 if (!peer)
6612 return CMD_WARNING_CONFIG_FAILED;
6613
6614 /* Check filter direction. */
6615 if (strncmp(direct_str, "in", 2) == 0)
6616 direct = RMAP_IN;
6617 else if (strncmp(direct_str, "o", 1) == 0)
6618 direct = RMAP_OUT;
6619
6620 ret = peer_route_map_unset(peer, afi, safi, direct);
6621
6622 return bgp_vty_return(vty, ret);
6623 }
6624
6625 DEFUN (neighbor_route_map,
6626 neighbor_route_map_cmd,
6627 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
6628 NEIGHBOR_STR
6629 NEIGHBOR_ADDR_STR2
6630 "Apply route map to neighbor\n"
6631 "Name of route map\n"
6632 "Apply map to incoming routes\n"
6633 "Apply map to outbound routes\n")
6634 {
6635 int idx_peer = 1;
6636 int idx_word = 3;
6637 int idx_in_out = 4;
6638 return peer_route_map_set_vty(
6639 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6640 argv[idx_word]->arg, argv[idx_in_out]->arg);
6641 }
6642
6643 ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
6644 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
6645 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6646 "Apply route map to neighbor\n"
6647 "Name of route map\n"
6648 "Apply map to incoming routes\n"
6649 "Apply map to outbound routes\n")
6650
6651 DEFUN (no_neighbor_route_map,
6652 no_neighbor_route_map_cmd,
6653 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
6654 NO_STR
6655 NEIGHBOR_STR
6656 NEIGHBOR_ADDR_STR2
6657 "Apply route map to neighbor\n"
6658 "Name of route map\n"
6659 "Apply map to incoming routes\n"
6660 "Apply map to outbound routes\n")
6661 {
6662 int idx_peer = 2;
6663 int idx_in_out = 5;
6664 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
6665 bgp_node_afi(vty), bgp_node_safi(vty),
6666 argv[idx_in_out]->arg);
6667 }
6668
6669 ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
6670 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
6671 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6672 "Apply route map to neighbor\n"
6673 "Name of route map\n"
6674 "Apply map to incoming routes\n"
6675 "Apply map to outbound routes\n")
6676
6677 /* Set unsuppress-map to the peer. */
6678 static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
6679 afi_t afi, safi_t safi,
6680 const char *name_str)
6681 {
6682 int ret;
6683 struct peer *peer;
6684 struct route_map *route_map;
6685
6686 peer = peer_and_group_lookup_vty(vty, ip_str);
6687 if (!peer)
6688 return CMD_WARNING_CONFIG_FAILED;
6689
6690 route_map = route_map_lookup_warn_noexist(vty, name_str);
6691 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
6692
6693 return bgp_vty_return(vty, ret);
6694 }
6695
6696 /* Unset route-map from the peer. */
6697 static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
6698 afi_t afi, safi_t safi)
6699 {
6700 int ret;
6701 struct peer *peer;
6702
6703 peer = peer_and_group_lookup_vty(vty, ip_str);
6704 if (!peer)
6705 return CMD_WARNING_CONFIG_FAILED;
6706
6707 ret = peer_unsuppress_map_unset(peer, afi, safi);
6708
6709 return bgp_vty_return(vty, ret);
6710 }
6711
6712 DEFUN (neighbor_unsuppress_map,
6713 neighbor_unsuppress_map_cmd,
6714 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
6715 NEIGHBOR_STR
6716 NEIGHBOR_ADDR_STR2
6717 "Route-map to selectively unsuppress suppressed routes\n"
6718 "Name of route map\n")
6719 {
6720 int idx_peer = 1;
6721 int idx_word = 3;
6722 return peer_unsuppress_map_set_vty(
6723 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6724 argv[idx_word]->arg);
6725 }
6726
6727 ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
6728 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
6729 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6730 "Route-map to selectively unsuppress suppressed routes\n"
6731 "Name of route map\n")
6732
6733 DEFUN (no_neighbor_unsuppress_map,
6734 no_neighbor_unsuppress_map_cmd,
6735 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
6736 NO_STR
6737 NEIGHBOR_STR
6738 NEIGHBOR_ADDR_STR2
6739 "Route-map to selectively unsuppress suppressed routes\n"
6740 "Name of route map\n")
6741 {
6742 int idx_peer = 2;
6743 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
6744 bgp_node_afi(vty),
6745 bgp_node_safi(vty));
6746 }
6747
6748 ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
6749 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
6750 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6751 "Route-map to selectively unsuppress suppressed routes\n"
6752 "Name of route map\n")
6753
6754 static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
6755 afi_t afi, safi_t safi,
6756 const char *num_str,
6757 const char *threshold_str, int warning,
6758 const char *restart_str,
6759 const char *force_str)
6760 {
6761 int ret;
6762 struct peer *peer;
6763 uint32_t max;
6764 uint8_t threshold;
6765 uint16_t restart;
6766
6767 peer = peer_and_group_lookup_vty(vty, ip_str);
6768 if (!peer)
6769 return CMD_WARNING_CONFIG_FAILED;
6770
6771 max = strtoul(num_str, NULL, 10);
6772 if (threshold_str)
6773 threshold = atoi(threshold_str);
6774 else
6775 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
6776
6777 if (restart_str)
6778 restart = atoi(restart_str);
6779 else
6780 restart = 0;
6781
6782 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
6783 restart, force_str ? true : false);
6784
6785 return bgp_vty_return(vty, ret);
6786 }
6787
6788 static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
6789 afi_t afi, safi_t safi)
6790 {
6791 int ret;
6792 struct peer *peer;
6793
6794 peer = peer_and_group_lookup_vty(vty, ip_str);
6795 if (!peer)
6796 return CMD_WARNING_CONFIG_FAILED;
6797
6798 ret = peer_maximum_prefix_unset(peer, afi, safi);
6799
6800 return bgp_vty_return(vty, ret);
6801 }
6802
6803 /* Maximum number of prefix to be sent to the neighbor. */
6804 DEFUN(neighbor_maximum_prefix_out,
6805 neighbor_maximum_prefix_out_cmd,
6806 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out (1-4294967295)",
6807 NEIGHBOR_STR
6808 NEIGHBOR_ADDR_STR2
6809 "Maximum number of prefixes to be sent to this peer\n"
6810 "Maximum no. of prefix limit\n")
6811 {
6812 int idx_peer = 1;
6813 int idx_number = 3;
6814 struct peer *peer;
6815 uint32_t max;
6816 afi_t afi = bgp_node_afi(vty);
6817 safi_t safi = bgp_node_safi(vty);
6818
6819 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6820 if (!peer)
6821 return CMD_WARNING_CONFIG_FAILED;
6822
6823 max = strtoul(argv[idx_number]->arg, NULL, 10);
6824
6825 SET_FLAG(peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT);
6826 peer->pmax_out[afi][safi] = max;
6827
6828 return CMD_SUCCESS;
6829 }
6830
6831 DEFUN(no_neighbor_maximum_prefix_out,
6832 no_neighbor_maximum_prefix_out_cmd,
6833 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out",
6834 NO_STR
6835 NEIGHBOR_STR
6836 NEIGHBOR_ADDR_STR2
6837 "Maximum number of prefixes to be sent to this peer\n")
6838 {
6839 int idx_peer = 2;
6840 struct peer *peer;
6841 afi_t afi = bgp_node_afi(vty);
6842 safi_t safi = bgp_node_safi(vty);
6843
6844 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6845 if (!peer)
6846 return CMD_WARNING_CONFIG_FAILED;
6847
6848 UNSET_FLAG(peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT);
6849 peer->pmax_out[afi][safi] = 0;
6850
6851 return CMD_SUCCESS;
6852 }
6853
6854 /* Maximum number of prefix configuration. Prefix count is different
6855 for each peer configuration. So this configuration can be set for
6856 each peer configuration. */
6857 DEFUN (neighbor_maximum_prefix,
6858 neighbor_maximum_prefix_cmd,
6859 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
6860 NEIGHBOR_STR
6861 NEIGHBOR_ADDR_STR2
6862 "Maximum number of prefix accept from this peer\n"
6863 "maximum no. of prefix limit\n"
6864 "Force checking all received routes not only accepted\n")
6865 {
6866 int idx_peer = 1;
6867 int idx_number = 3;
6868 int idx_force = 0;
6869 char *force = NULL;
6870
6871 if (argv_find(argv, argc, "force", &idx_force))
6872 force = argv[idx_force]->arg;
6873
6874 return peer_maximum_prefix_set_vty(
6875 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6876 argv[idx_number]->arg, NULL, 0, NULL, force);
6877 }
6878
6879 ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
6880 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
6881 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6882 "Maximum number of prefix accept from this peer\n"
6883 "maximum no. of prefix limit\n"
6884 "Force checking all received routes not only accepted\n")
6885
6886 DEFUN (neighbor_maximum_prefix_threshold,
6887 neighbor_maximum_prefix_threshold_cmd,
6888 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
6889 NEIGHBOR_STR
6890 NEIGHBOR_ADDR_STR2
6891 "Maximum number of prefix accept from this peer\n"
6892 "maximum no. of prefix limit\n"
6893 "Threshold value (%) at which to generate a warning msg\n"
6894 "Force checking all received routes not only accepted\n")
6895 {
6896 int idx_peer = 1;
6897 int idx_number = 3;
6898 int idx_number_2 = 4;
6899 int idx_force = 0;
6900 char *force = NULL;
6901
6902 if (argv_find(argv, argc, "force", &idx_force))
6903 force = argv[idx_force]->arg;
6904
6905 return peer_maximum_prefix_set_vty(
6906 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6907 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL, force);
6908 }
6909
6910 ALIAS_HIDDEN(
6911 neighbor_maximum_prefix_threshold,
6912 neighbor_maximum_prefix_threshold_hidden_cmd,
6913 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
6914 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6915 "Maximum number of prefix accept from this peer\n"
6916 "maximum no. of prefix limit\n"
6917 "Threshold value (%) at which to generate a warning msg\n"
6918 "Force checking all received routes not only accepted\n")
6919
6920 DEFUN (neighbor_maximum_prefix_warning,
6921 neighbor_maximum_prefix_warning_cmd,
6922 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
6923 NEIGHBOR_STR
6924 NEIGHBOR_ADDR_STR2
6925 "Maximum number of prefix accept from this peer\n"
6926 "maximum no. of prefix limit\n"
6927 "Only give warning message when limit is exceeded\n"
6928 "Force checking all received routes not only accepted\n")
6929 {
6930 int idx_peer = 1;
6931 int idx_number = 3;
6932 int idx_force = 0;
6933 char *force = NULL;
6934
6935 if (argv_find(argv, argc, "force", &idx_force))
6936 force = argv[idx_force]->arg;
6937
6938 return peer_maximum_prefix_set_vty(
6939 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6940 argv[idx_number]->arg, NULL, 1, NULL, force);
6941 }
6942
6943 ALIAS_HIDDEN(
6944 neighbor_maximum_prefix_warning,
6945 neighbor_maximum_prefix_warning_hidden_cmd,
6946 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
6947 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6948 "Maximum number of prefix accept from this peer\n"
6949 "maximum no. of prefix limit\n"
6950 "Only give warning message when limit is exceeded\n"
6951 "Force checking all received routes not only accepted\n")
6952
6953 DEFUN (neighbor_maximum_prefix_threshold_warning,
6954 neighbor_maximum_prefix_threshold_warning_cmd,
6955 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
6956 NEIGHBOR_STR
6957 NEIGHBOR_ADDR_STR2
6958 "Maximum number of prefix accept from this peer\n"
6959 "maximum no. of prefix limit\n"
6960 "Threshold value (%) at which to generate a warning msg\n"
6961 "Only give warning message when limit is exceeded\n"
6962 "Force checking all received routes not only accepted\n")
6963 {
6964 int idx_peer = 1;
6965 int idx_number = 3;
6966 int idx_number_2 = 4;
6967 int idx_force = 0;
6968 char *force = NULL;
6969
6970 if (argv_find(argv, argc, "force", &idx_force))
6971 force = argv[idx_force]->arg;
6972
6973 return peer_maximum_prefix_set_vty(
6974 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6975 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL, force);
6976 }
6977
6978 ALIAS_HIDDEN(
6979 neighbor_maximum_prefix_threshold_warning,
6980 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
6981 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
6982 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6983 "Maximum number of prefix accept from this peer\n"
6984 "maximum no. of prefix limit\n"
6985 "Threshold value (%) at which to generate a warning msg\n"
6986 "Only give warning message when limit is exceeded\n"
6987 "Force checking all received routes not only accepted\n")
6988
6989 DEFUN (neighbor_maximum_prefix_restart,
6990 neighbor_maximum_prefix_restart_cmd,
6991 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
6992 NEIGHBOR_STR
6993 NEIGHBOR_ADDR_STR2
6994 "Maximum number of prefix accept from this peer\n"
6995 "maximum no. of prefix limit\n"
6996 "Restart bgp connection after limit is exceeded\n"
6997 "Restart interval in minutes\n"
6998 "Force checking all received routes not only accepted\n")
6999 {
7000 int idx_peer = 1;
7001 int idx_number = 3;
7002 int idx_number_2 = 5;
7003 int idx_force = 0;
7004 char *force = NULL;
7005
7006 if (argv_find(argv, argc, "force", &idx_force))
7007 force = argv[idx_force]->arg;
7008
7009 return peer_maximum_prefix_set_vty(
7010 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7011 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg, force);
7012 }
7013
7014 ALIAS_HIDDEN(
7015 neighbor_maximum_prefix_restart,
7016 neighbor_maximum_prefix_restart_hidden_cmd,
7017 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
7018 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7019 "Maximum number of prefix accept from this peer\n"
7020 "maximum no. of prefix limit\n"
7021 "Restart bgp connection after limit is exceeded\n"
7022 "Restart interval in minutes\n"
7023 "Force checking all received routes not only accepted\n")
7024
7025 DEFUN (neighbor_maximum_prefix_threshold_restart,
7026 neighbor_maximum_prefix_threshold_restart_cmd,
7027 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
7028 NEIGHBOR_STR
7029 NEIGHBOR_ADDR_STR2
7030 "Maximum number of prefixes to accept from this peer\n"
7031 "maximum no. of prefix limit\n"
7032 "Threshold value (%) at which to generate a warning msg\n"
7033 "Restart bgp connection after limit is exceeded\n"
7034 "Restart interval in minutes\n"
7035 "Force checking all received routes not only accepted\n")
7036 {
7037 int idx_peer = 1;
7038 int idx_number = 3;
7039 int idx_number_2 = 4;
7040 int idx_number_3 = 6;
7041 int idx_force = 0;
7042 char *force = NULL;
7043
7044 if (argv_find(argv, argc, "force", &idx_force))
7045 force = argv[idx_force]->arg;
7046
7047 return peer_maximum_prefix_set_vty(
7048 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7049 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
7050 argv[idx_number_3]->arg, force);
7051 }
7052
7053 ALIAS_HIDDEN(
7054 neighbor_maximum_prefix_threshold_restart,
7055 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
7056 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
7057 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7058 "Maximum number of prefixes to accept from this peer\n"
7059 "maximum no. of prefix limit\n"
7060 "Threshold value (%) at which to generate a warning msg\n"
7061 "Restart bgp connection after limit is exceeded\n"
7062 "Restart interval in minutes\n"
7063 "Force checking all received routes not only accepted\n")
7064
7065 DEFUN (no_neighbor_maximum_prefix,
7066 no_neighbor_maximum_prefix_cmd,
7067 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
7068 NO_STR
7069 NEIGHBOR_STR
7070 NEIGHBOR_ADDR_STR2
7071 "Maximum number of prefixes to accept from this peer\n"
7072 "maximum no. of prefix limit\n"
7073 "Threshold value (%) at which to generate a warning msg\n"
7074 "Restart bgp connection after limit is exceeded\n"
7075 "Restart interval in minutes\n"
7076 "Only give warning message when limit is exceeded\n"
7077 "Force checking all received routes not only accepted\n")
7078 {
7079 int idx_peer = 2;
7080 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
7081 bgp_node_afi(vty),
7082 bgp_node_safi(vty));
7083 }
7084
7085 ALIAS_HIDDEN(
7086 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
7087 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
7088 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7089 "Maximum number of prefixes to accept from this peer\n"
7090 "maximum no. of prefix limit\n"
7091 "Threshold value (%) at which to generate a warning msg\n"
7092 "Restart bgp connection after limit is exceeded\n"
7093 "Restart interval in minutes\n"
7094 "Only give warning message when limit is exceeded\n"
7095 "Force checking all received routes not only accepted\n")
7096
7097
7098 /* "neighbor allowas-in" */
7099 DEFUN (neighbor_allowas_in,
7100 neighbor_allowas_in_cmd,
7101 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
7102 NEIGHBOR_STR
7103 NEIGHBOR_ADDR_STR2
7104 "Accept as-path with my AS present in it\n"
7105 "Number of occurrences of AS number\n"
7106 "Only accept my AS in the as-path if the route was originated in my AS\n")
7107 {
7108 int idx_peer = 1;
7109 int idx_number_origin = 3;
7110 int ret;
7111 int origin = 0;
7112 struct peer *peer;
7113 int allow_num = 0;
7114
7115 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7116 if (!peer)
7117 return CMD_WARNING_CONFIG_FAILED;
7118
7119 if (argc <= idx_number_origin)
7120 allow_num = 3;
7121 else {
7122 if (argv[idx_number_origin]->type == WORD_TKN)
7123 origin = 1;
7124 else
7125 allow_num = atoi(argv[idx_number_origin]->arg);
7126 }
7127
7128 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7129 allow_num, origin);
7130
7131 return bgp_vty_return(vty, ret);
7132 }
7133
7134 ALIAS_HIDDEN(
7135 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
7136 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
7137 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7138 "Accept as-path with my AS present in it\n"
7139 "Number of occurrences of AS number\n"
7140 "Only accept my AS in the as-path if the route was originated in my AS\n")
7141
7142 DEFUN (no_neighbor_allowas_in,
7143 no_neighbor_allowas_in_cmd,
7144 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
7145 NO_STR
7146 NEIGHBOR_STR
7147 NEIGHBOR_ADDR_STR2
7148 "allow local ASN appears in aspath attribute\n"
7149 "Number of occurrences of AS number\n"
7150 "Only accept my AS in the as-path if the route was originated in my AS\n")
7151 {
7152 int idx_peer = 2;
7153 int ret;
7154 struct peer *peer;
7155
7156 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7157 if (!peer)
7158 return CMD_WARNING_CONFIG_FAILED;
7159
7160 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
7161 bgp_node_safi(vty));
7162
7163 return bgp_vty_return(vty, ret);
7164 }
7165
7166 ALIAS_HIDDEN(
7167 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
7168 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
7169 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7170 "allow local ASN appears in aspath attribute\n"
7171 "Number of occurrences of AS number\n"
7172 "Only accept my AS in the as-path if the route was originated in my AS\n")
7173
7174 DEFUN (neighbor_ttl_security,
7175 neighbor_ttl_security_cmd,
7176 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
7177 NEIGHBOR_STR
7178 NEIGHBOR_ADDR_STR2
7179 "BGP ttl-security parameters\n"
7180 "Specify the maximum number of hops to the BGP peer\n"
7181 "Number of hops to BGP peer\n")
7182 {
7183 int idx_peer = 1;
7184 int idx_number = 4;
7185 struct peer *peer;
7186 int gtsm_hops;
7187
7188 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7189 if (!peer)
7190 return CMD_WARNING_CONFIG_FAILED;
7191
7192 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
7193
7194 /*
7195 * If 'neighbor swpX', then this is for directly connected peers,
7196 * we should not accept a ttl-security hops value greater than 1.
7197 */
7198 if (peer->conf_if && (gtsm_hops > BGP_GTSM_HOPS_CONNECTED)) {
7199 vty_out(vty,
7200 "%s is directly connected peer, hops cannot exceed 1\n",
7201 argv[idx_peer]->arg);
7202 return CMD_WARNING_CONFIG_FAILED;
7203 }
7204
7205 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
7206 }
7207
7208 DEFUN (no_neighbor_ttl_security,
7209 no_neighbor_ttl_security_cmd,
7210 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
7211 NO_STR
7212 NEIGHBOR_STR
7213 NEIGHBOR_ADDR_STR2
7214 "BGP ttl-security parameters\n"
7215 "Specify the maximum number of hops to the BGP peer\n"
7216 "Number of hops to BGP peer\n")
7217 {
7218 int idx_peer = 2;
7219 struct peer *peer;
7220
7221 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7222 if (!peer)
7223 return CMD_WARNING_CONFIG_FAILED;
7224
7225 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
7226 }
7227
7228 DEFUN (neighbor_addpath_tx_all_paths,
7229 neighbor_addpath_tx_all_paths_cmd,
7230 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
7231 NEIGHBOR_STR
7232 NEIGHBOR_ADDR_STR2
7233 "Use addpath to advertise all paths to a neighbor\n")
7234 {
7235 int idx_peer = 1;
7236 struct peer *peer;
7237
7238 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7239 if (!peer)
7240 return CMD_WARNING_CONFIG_FAILED;
7241
7242 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7243 BGP_ADDPATH_ALL);
7244 return CMD_SUCCESS;
7245 }
7246
7247 ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
7248 neighbor_addpath_tx_all_paths_hidden_cmd,
7249 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
7250 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7251 "Use addpath to advertise all paths to a neighbor\n")
7252
7253 DEFUN (no_neighbor_addpath_tx_all_paths,
7254 no_neighbor_addpath_tx_all_paths_cmd,
7255 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
7256 NO_STR
7257 NEIGHBOR_STR
7258 NEIGHBOR_ADDR_STR2
7259 "Use addpath to advertise all paths to a neighbor\n")
7260 {
7261 int idx_peer = 2;
7262 struct peer *peer;
7263
7264 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7265 if (!peer)
7266 return CMD_WARNING_CONFIG_FAILED;
7267
7268 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
7269 != BGP_ADDPATH_ALL) {
7270 vty_out(vty,
7271 "%% Peer not currently configured to transmit all paths.");
7272 return CMD_WARNING_CONFIG_FAILED;
7273 }
7274
7275 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7276 BGP_ADDPATH_NONE);
7277
7278 return CMD_SUCCESS;
7279 }
7280
7281 ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
7282 no_neighbor_addpath_tx_all_paths_hidden_cmd,
7283 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
7284 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7285 "Use addpath to advertise all paths to a neighbor\n")
7286
7287 DEFUN (neighbor_addpath_tx_bestpath_per_as,
7288 neighbor_addpath_tx_bestpath_per_as_cmd,
7289 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
7290 NEIGHBOR_STR
7291 NEIGHBOR_ADDR_STR2
7292 "Use addpath to advertise the bestpath per each neighboring AS\n")
7293 {
7294 int idx_peer = 1;
7295 struct peer *peer;
7296
7297 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7298 if (!peer)
7299 return CMD_WARNING_CONFIG_FAILED;
7300
7301 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7302 BGP_ADDPATH_BEST_PER_AS);
7303
7304 return CMD_SUCCESS;
7305 }
7306
7307 ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
7308 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
7309 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
7310 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7311 "Use addpath to advertise the bestpath per each neighboring AS\n")
7312
7313 DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
7314 no_neighbor_addpath_tx_bestpath_per_as_cmd,
7315 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
7316 NO_STR
7317 NEIGHBOR_STR
7318 NEIGHBOR_ADDR_STR2
7319 "Use addpath to advertise the bestpath per each neighboring AS\n")
7320 {
7321 int idx_peer = 2;
7322 struct peer *peer;
7323
7324 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7325 if (!peer)
7326 return CMD_WARNING_CONFIG_FAILED;
7327
7328 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
7329 != BGP_ADDPATH_BEST_PER_AS) {
7330 vty_out(vty,
7331 "%% Peer not currently configured to transmit all best path per as.");
7332 return CMD_WARNING_CONFIG_FAILED;
7333 }
7334
7335 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7336 BGP_ADDPATH_NONE);
7337
7338 return CMD_SUCCESS;
7339 }
7340
7341 ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
7342 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
7343 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
7344 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7345 "Use addpath to advertise the bestpath per each neighboring AS\n")
7346
7347 DEFPY(
7348 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
7349 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
7350 NEIGHBOR_STR
7351 NEIGHBOR_ADDR_STR2
7352 "Detect AS loops before sending to neighbor\n")
7353 {
7354 struct peer *peer;
7355
7356 peer = peer_and_group_lookup_vty(vty, neighbor);
7357 if (!peer)
7358 return CMD_WARNING_CONFIG_FAILED;
7359
7360 peer->as_path_loop_detection = true;
7361
7362 return CMD_SUCCESS;
7363 }
7364
7365 DEFPY(
7366 no_neighbor_aspath_loop_detection,
7367 no_neighbor_aspath_loop_detection_cmd,
7368 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
7369 NO_STR
7370 NEIGHBOR_STR
7371 NEIGHBOR_ADDR_STR2
7372 "Detect AS loops before sending to neighbor\n")
7373 {
7374 struct peer *peer;
7375
7376 peer = peer_and_group_lookup_vty(vty, neighbor);
7377 if (!peer)
7378 return CMD_WARNING_CONFIG_FAILED;
7379
7380 peer->as_path_loop_detection = false;
7381
7382 return CMD_SUCCESS;
7383 }
7384
7385 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
7386 struct ecommunity **list)
7387 {
7388 struct ecommunity *ecom = NULL;
7389 struct ecommunity *ecomadd;
7390
7391 for (; argc; --argc, ++argv) {
7392
7393 ecomadd = ecommunity_str2com(argv[0]->arg,
7394 ECOMMUNITY_ROUTE_TARGET, 0);
7395 if (!ecomadd) {
7396 vty_out(vty, "Malformed community-list value\n");
7397 if (ecom)
7398 ecommunity_free(&ecom);
7399 return CMD_WARNING_CONFIG_FAILED;
7400 }
7401
7402 if (ecom) {
7403 ecommunity_merge(ecom, ecomadd);
7404 ecommunity_free(&ecomadd);
7405 } else {
7406 ecom = ecomadd;
7407 }
7408 }
7409
7410 if (*list) {
7411 ecommunity_free(&*list);
7412 }
7413 *list = ecom;
7414
7415 return CMD_SUCCESS;
7416 }
7417
7418 /*
7419 * v2vimport is true if we are handling a `import vrf ...` command
7420 */
7421 static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
7422 {
7423 afi_t afi;
7424
7425 switch (vty->node) {
7426 case BGP_IPV4_NODE:
7427 afi = AFI_IP;
7428 break;
7429 case BGP_IPV6_NODE:
7430 afi = AFI_IP6;
7431 break;
7432 default:
7433 vty_out(vty,
7434 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
7435 return AFI_MAX;
7436 }
7437
7438 if (!v2vimport) {
7439 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
7440 BGP_CONFIG_VRF_TO_VRF_IMPORT)
7441 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
7442 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
7443 vty_out(vty,
7444 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
7445 return AFI_MAX;
7446 }
7447 } else {
7448 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
7449 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
7450 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
7451 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
7452 vty_out(vty,
7453 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
7454 return AFI_MAX;
7455 }
7456 }
7457 return afi;
7458 }
7459
7460 DEFPY (af_rd_vpn_export,
7461 af_rd_vpn_export_cmd,
7462 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
7463 NO_STR
7464 "Specify route distinguisher\n"
7465 "Between current address-family and vpn\n"
7466 "For routes leaked from current address-family to vpn\n"
7467 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
7468 {
7469 VTY_DECLVAR_CONTEXT(bgp, bgp);
7470 struct prefix_rd prd;
7471 int ret;
7472 afi_t afi;
7473 int idx = 0;
7474 int yes = 1;
7475
7476 if (argv_find(argv, argc, "no", &idx))
7477 yes = 0;
7478
7479 if (yes) {
7480 ret = str2prefix_rd(rd_str, &prd);
7481 if (!ret) {
7482 vty_out(vty, "%% Malformed rd\n");
7483 return CMD_WARNING_CONFIG_FAILED;
7484 }
7485 }
7486
7487 afi = vpn_policy_getafi(vty, bgp, false);
7488 if (afi == AFI_MAX)
7489 return CMD_WARNING_CONFIG_FAILED;
7490
7491 /*
7492 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
7493 */
7494 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
7495 bgp_get_default(), bgp);
7496
7497 if (yes) {
7498 bgp->vpn_policy[afi].tovpn_rd = prd;
7499 SET_FLAG(bgp->vpn_policy[afi].flags,
7500 BGP_VPN_POLICY_TOVPN_RD_SET);
7501 } else {
7502 UNSET_FLAG(bgp->vpn_policy[afi].flags,
7503 BGP_VPN_POLICY_TOVPN_RD_SET);
7504 }
7505
7506 /* post-change: re-export vpn routes */
7507 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
7508 bgp_get_default(), bgp);
7509
7510 return CMD_SUCCESS;
7511 }
7512
7513 ALIAS (af_rd_vpn_export,
7514 af_no_rd_vpn_export_cmd,
7515 "no rd vpn export",
7516 NO_STR
7517 "Specify route distinguisher\n"
7518 "Between current address-family and vpn\n"
7519 "For routes leaked from current address-family to vpn\n")
7520
7521 DEFPY (af_label_vpn_export,
7522 af_label_vpn_export_cmd,
7523 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
7524 NO_STR
7525 "label value for VRF\n"
7526 "Between current address-family and vpn\n"
7527 "For routes leaked from current address-family to vpn\n"
7528 "Label Value <0-1048575>\n"
7529 "Automatically assign a label\n")
7530 {
7531 VTY_DECLVAR_CONTEXT(bgp, bgp);
7532 mpls_label_t label = MPLS_LABEL_NONE;
7533 afi_t afi;
7534 int idx = 0;
7535 int yes = 1;
7536
7537 if (argv_find(argv, argc, "no", &idx))
7538 yes = 0;
7539
7540 /* If "no ...", squash trailing parameter */
7541 if (!yes)
7542 label_auto = NULL;
7543
7544 if (yes) {
7545 if (!label_auto)
7546 label = label_val; /* parser should force unsigned */
7547 }
7548
7549 afi = vpn_policy_getafi(vty, bgp, false);
7550 if (afi == AFI_MAX)
7551 return CMD_WARNING_CONFIG_FAILED;
7552
7553
7554 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
7555 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
7556 /* no change */
7557 return CMD_SUCCESS;
7558
7559 /*
7560 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
7561 */
7562 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
7563 bgp_get_default(), bgp);
7564
7565 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
7566 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
7567
7568 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
7569
7570 /*
7571 * label has previously been automatically
7572 * assigned by labelpool: release it
7573 *
7574 * NB if tovpn_label == MPLS_LABEL_NONE it
7575 * means the automatic assignment is in flight
7576 * and therefore the labelpool callback must
7577 * detect that the auto label is not needed.
7578 */
7579
7580 bgp_lp_release(LP_TYPE_VRF,
7581 &bgp->vpn_policy[afi],
7582 bgp->vpn_policy[afi].tovpn_label);
7583 }
7584 UNSET_FLAG(bgp->vpn_policy[afi].flags,
7585 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
7586 }
7587
7588 bgp->vpn_policy[afi].tovpn_label = label;
7589 if (label_auto) {
7590 SET_FLAG(bgp->vpn_policy[afi].flags,
7591 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
7592 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
7593 vpn_leak_label_callback);
7594 }
7595
7596 /* post-change: re-export vpn routes */
7597 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
7598 bgp_get_default(), bgp);
7599
7600 return CMD_SUCCESS;
7601 }
7602
7603 ALIAS (af_label_vpn_export,
7604 af_no_label_vpn_export_cmd,
7605 "no label vpn export",
7606 NO_STR
7607 "label value for VRF\n"
7608 "Between current address-family and vpn\n"
7609 "For routes leaked from current address-family to vpn\n")
7610
7611 DEFPY (af_nexthop_vpn_export,
7612 af_nexthop_vpn_export_cmd,
7613 "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
7614 NO_STR
7615 "Specify next hop to use for VRF advertised prefixes\n"
7616 "Between current address-family and vpn\n"
7617 "For routes leaked from current address-family to vpn\n"
7618 "IPv4 prefix\n"
7619 "IPv6 prefix\n")
7620 {
7621 VTY_DECLVAR_CONTEXT(bgp, bgp);
7622 afi_t afi;
7623 struct prefix p;
7624
7625 if (!no) {
7626 if (!nexthop_su) {
7627 vty_out(vty, "%% Nexthop required\n");
7628 return CMD_WARNING_CONFIG_FAILED;
7629 }
7630
7631 if (!sockunion2hostprefix(nexthop_su, &p))
7632 return CMD_WARNING_CONFIG_FAILED;
7633 }
7634
7635 afi = vpn_policy_getafi(vty, bgp, false);
7636 if (afi == AFI_MAX)
7637 return CMD_WARNING_CONFIG_FAILED;
7638
7639 /*
7640 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
7641 */
7642 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
7643 bgp_get_default(), bgp);
7644
7645 if (!no) {
7646 bgp->vpn_policy[afi].tovpn_nexthop = p;
7647 SET_FLAG(bgp->vpn_policy[afi].flags,
7648 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
7649 } else {
7650 UNSET_FLAG(bgp->vpn_policy[afi].flags,
7651 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
7652 }
7653
7654 /* post-change: re-export vpn routes */
7655 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
7656 bgp_get_default(), bgp);
7657
7658 return CMD_SUCCESS;
7659 }
7660
7661 static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
7662 {
7663 if (!strcmp(dstr, "import")) {
7664 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
7665 } else if (!strcmp(dstr, "export")) {
7666 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
7667 } else if (!strcmp(dstr, "both")) {
7668 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
7669 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
7670 } else {
7671 vty_out(vty, "%% direction parse error\n");
7672 return CMD_WARNING_CONFIG_FAILED;
7673 }
7674 return CMD_SUCCESS;
7675 }
7676
7677 DEFPY (af_rt_vpn_imexport,
7678 af_rt_vpn_imexport_cmd,
7679 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
7680 NO_STR
7681 "Specify route target list\n"
7682 "Specify route target list\n"
7683 "Between current address-family and vpn\n"
7684 "For routes leaked from vpn to current address-family: match any\n"
7685 "For routes leaked from current address-family to vpn: set\n"
7686 "both import: match any and export: set\n"
7687 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
7688 {
7689 VTY_DECLVAR_CONTEXT(bgp, bgp);
7690 int ret;
7691 struct ecommunity *ecom = NULL;
7692 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
7693 vpn_policy_direction_t dir;
7694 afi_t afi;
7695 int idx = 0;
7696 int yes = 1;
7697
7698 if (argv_find(argv, argc, "no", &idx))
7699 yes = 0;
7700
7701 afi = vpn_policy_getafi(vty, bgp, false);
7702 if (afi == AFI_MAX)
7703 return CMD_WARNING_CONFIG_FAILED;
7704
7705 ret = vpn_policy_getdirs(vty, direction_str, dodir);
7706 if (ret != CMD_SUCCESS)
7707 return ret;
7708
7709 if (yes) {
7710 if (!argv_find(argv, argc, "RTLIST", &idx)) {
7711 vty_out(vty, "%% Missing RTLIST\n");
7712 return CMD_WARNING_CONFIG_FAILED;
7713 }
7714 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
7715 if (ret != CMD_SUCCESS) {
7716 return ret;
7717 }
7718 }
7719
7720 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
7721 if (!dodir[dir])
7722 continue;
7723
7724 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
7725
7726 if (yes) {
7727 if (bgp->vpn_policy[afi].rtlist[dir])
7728 ecommunity_free(
7729 &bgp->vpn_policy[afi].rtlist[dir]);
7730 bgp->vpn_policy[afi].rtlist[dir] =
7731 ecommunity_dup(ecom);
7732 } else {
7733 if (bgp->vpn_policy[afi].rtlist[dir])
7734 ecommunity_free(
7735 &bgp->vpn_policy[afi].rtlist[dir]);
7736 bgp->vpn_policy[afi].rtlist[dir] = NULL;
7737 }
7738
7739 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
7740 }
7741
7742 if (ecom)
7743 ecommunity_free(&ecom);
7744
7745 return CMD_SUCCESS;
7746 }
7747
7748 ALIAS (af_rt_vpn_imexport,
7749 af_no_rt_vpn_imexport_cmd,
7750 "no <rt|route-target> vpn <import|export|both>$direction_str",
7751 NO_STR
7752 "Specify route target list\n"
7753 "Specify route target list\n"
7754 "Between current address-family and vpn\n"
7755 "For routes leaked from vpn to current address-family\n"
7756 "For routes leaked from current address-family to vpn\n"
7757 "both import and export\n")
7758
7759 DEFPY (af_route_map_vpn_imexport,
7760 af_route_map_vpn_imexport_cmd,
7761 /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
7762 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
7763 NO_STR
7764 "Specify route map\n"
7765 "Between current address-family and vpn\n"
7766 "For routes leaked from vpn to current address-family\n"
7767 "For routes leaked from current address-family to vpn\n"
7768 "name of route-map\n")
7769 {
7770 VTY_DECLVAR_CONTEXT(bgp, bgp);
7771 int ret;
7772 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
7773 vpn_policy_direction_t dir;
7774 afi_t afi;
7775 int idx = 0;
7776 int yes = 1;
7777
7778 if (argv_find(argv, argc, "no", &idx))
7779 yes = 0;
7780
7781 afi = vpn_policy_getafi(vty, bgp, false);
7782 if (afi == AFI_MAX)
7783 return CMD_WARNING_CONFIG_FAILED;
7784
7785 ret = vpn_policy_getdirs(vty, direction_str, dodir);
7786 if (ret != CMD_SUCCESS)
7787 return ret;
7788
7789 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
7790 if (!dodir[dir])
7791 continue;
7792
7793 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
7794
7795 if (yes) {
7796 if (bgp->vpn_policy[afi].rmap_name[dir])
7797 XFREE(MTYPE_ROUTE_MAP_NAME,
7798 bgp->vpn_policy[afi].rmap_name[dir]);
7799 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
7800 MTYPE_ROUTE_MAP_NAME, rmap_str);
7801 bgp->vpn_policy[afi].rmap[dir] =
7802 route_map_lookup_warn_noexist(vty, rmap_str);
7803 if (!bgp->vpn_policy[afi].rmap[dir])
7804 return CMD_SUCCESS;
7805 } else {
7806 if (bgp->vpn_policy[afi].rmap_name[dir])
7807 XFREE(MTYPE_ROUTE_MAP_NAME,
7808 bgp->vpn_policy[afi].rmap_name[dir]);
7809 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
7810 bgp->vpn_policy[afi].rmap[dir] = NULL;
7811 }
7812
7813 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
7814 }
7815
7816 return CMD_SUCCESS;
7817 }
7818
7819 ALIAS (af_route_map_vpn_imexport,
7820 af_no_route_map_vpn_imexport_cmd,
7821 "no route-map vpn <import|export>$direction_str",
7822 NO_STR
7823 "Specify route map\n"
7824 "Between current address-family and vpn\n"
7825 "For routes leaked from vpn to current address-family\n"
7826 "For routes leaked from current address-family to vpn\n")
7827
7828 DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
7829 "import vrf route-map RMAP$rmap_str",
7830 "Import routes from another VRF\n"
7831 "Vrf routes being filtered\n"
7832 "Specify route map\n"
7833 "name of route-map\n")
7834 {
7835 VTY_DECLVAR_CONTEXT(bgp, bgp);
7836 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
7837 afi_t afi;
7838 struct bgp *bgp_default;
7839
7840 afi = vpn_policy_getafi(vty, bgp, true);
7841 if (afi == AFI_MAX)
7842 return CMD_WARNING_CONFIG_FAILED;
7843
7844 bgp_default = bgp_get_default();
7845 if (!bgp_default) {
7846 int32_t ret;
7847 as_t as = bgp->as;
7848
7849 /* Auto-create assuming the same AS */
7850 ret = bgp_get_vty(&bgp_default, &as, NULL,
7851 BGP_INSTANCE_TYPE_DEFAULT);
7852
7853 if (ret) {
7854 vty_out(vty,
7855 "VRF default is not configured as a bgp instance\n");
7856 return CMD_WARNING;
7857 }
7858 }
7859
7860 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
7861
7862 if (bgp->vpn_policy[afi].rmap_name[dir])
7863 XFREE(MTYPE_ROUTE_MAP_NAME,
7864 bgp->vpn_policy[afi].rmap_name[dir]);
7865 bgp->vpn_policy[afi].rmap_name[dir] =
7866 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
7867 bgp->vpn_policy[afi].rmap[dir] =
7868 route_map_lookup_warn_noexist(vty, rmap_str);
7869 if (!bgp->vpn_policy[afi].rmap[dir])
7870 return CMD_SUCCESS;
7871
7872 SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
7873 BGP_CONFIG_VRF_TO_VRF_IMPORT);
7874
7875 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
7876
7877 return CMD_SUCCESS;
7878 }
7879
7880 DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
7881 "no import vrf route-map [RMAP$rmap_str]",
7882 NO_STR
7883 "Import routes from another VRF\n"
7884 "Vrf routes being filtered\n"
7885 "Specify route map\n"
7886 "name of route-map\n")
7887 {
7888 VTY_DECLVAR_CONTEXT(bgp, bgp);
7889 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
7890 afi_t afi;
7891
7892 afi = vpn_policy_getafi(vty, bgp, true);
7893 if (afi == AFI_MAX)
7894 return CMD_WARNING_CONFIG_FAILED;
7895
7896 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
7897
7898 if (bgp->vpn_policy[afi].rmap_name[dir])
7899 XFREE(MTYPE_ROUTE_MAP_NAME,
7900 bgp->vpn_policy[afi].rmap_name[dir]);
7901 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
7902 bgp->vpn_policy[afi].rmap[dir] = NULL;
7903
7904 if (bgp->vpn_policy[afi].import_vrf->count == 0)
7905 UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
7906 BGP_CONFIG_VRF_TO_VRF_IMPORT);
7907
7908 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
7909
7910 return CMD_SUCCESS;
7911 }
7912
7913 DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
7914 "[no] import vrf VIEWVRFNAME$import_name",
7915 NO_STR
7916 "Import routes from another VRF\n"
7917 "VRF to import from\n"
7918 "The name of the VRF\n")
7919 {
7920 VTY_DECLVAR_CONTEXT(bgp, bgp);
7921 struct listnode *node;
7922 struct bgp *vrf_bgp, *bgp_default;
7923 int32_t ret = 0;
7924 as_t as = bgp->as;
7925 bool remove = false;
7926 int32_t idx = 0;
7927 char *vname;
7928 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
7929 safi_t safi;
7930 afi_t afi;
7931
7932 if (import_name == NULL) {
7933 vty_out(vty, "%% Missing import name\n");
7934 return CMD_WARNING;
7935 }
7936
7937 if (strcmp(import_name, "route-map") == 0) {
7938 vty_out(vty, "%% Must include route-map name\n");
7939 return CMD_WARNING;
7940 }
7941
7942 if (argv_find(argv, argc, "no", &idx))
7943 remove = true;
7944
7945 afi = vpn_policy_getafi(vty, bgp, true);
7946 if (afi == AFI_MAX)
7947 return CMD_WARNING_CONFIG_FAILED;
7948
7949 safi = bgp_node_safi(vty);
7950
7951 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
7952 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
7953 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
7954 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
7955 remove ? "unimport" : "import", import_name);
7956 return CMD_WARNING;
7957 }
7958
7959 bgp_default = bgp_get_default();
7960 if (!bgp_default) {
7961 /* Auto-create assuming the same AS */
7962 ret = bgp_get_vty(&bgp_default, &as, NULL,
7963 BGP_INSTANCE_TYPE_DEFAULT);
7964
7965 if (ret) {
7966 vty_out(vty,
7967 "VRF default is not configured as a bgp instance\n");
7968 return CMD_WARNING;
7969 }
7970 }
7971
7972 vrf_bgp = bgp_lookup_by_name(import_name);
7973 if (!vrf_bgp) {
7974 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
7975 vrf_bgp = bgp_default;
7976 else
7977 /* Auto-create assuming the same AS */
7978 ret = bgp_get_vty(&vrf_bgp, &as, import_name, bgp_type);
7979
7980 if (ret) {
7981 vty_out(vty,
7982 "VRF %s is not configured as a bgp instance\n",
7983 import_name);
7984 return CMD_WARNING;
7985 }
7986 }
7987
7988 if (remove) {
7989 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
7990 } else {
7991 /* Already importing from "import_vrf"? */
7992 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
7993 vname)) {
7994 if (strcmp(vname, import_name) == 0)
7995 return CMD_WARNING;
7996 }
7997
7998 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
7999 }
8000
8001 return CMD_SUCCESS;
8002 }
8003
8004 /* This command is valid only in a bgp vrf instance or the default instance */
8005 DEFPY (bgp_imexport_vpn,
8006 bgp_imexport_vpn_cmd,
8007 "[no] <import|export>$direction_str vpn",
8008 NO_STR
8009 "Import routes to this address-family\n"
8010 "Export routes from this address-family\n"
8011 "to/from default instance VPN RIB\n")
8012 {
8013 VTY_DECLVAR_CONTEXT(bgp, bgp);
8014 int previous_state;
8015 afi_t afi;
8016 safi_t safi;
8017 int idx = 0;
8018 int yes = 1;
8019 int flag;
8020 vpn_policy_direction_t dir;
8021
8022 if (argv_find(argv, argc, "no", &idx))
8023 yes = 0;
8024
8025 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
8026 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
8027
8028 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
8029 return CMD_WARNING_CONFIG_FAILED;
8030 }
8031
8032 afi = bgp_node_afi(vty);
8033 safi = bgp_node_safi(vty);
8034 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
8035 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
8036 return CMD_WARNING_CONFIG_FAILED;
8037 }
8038
8039 if (!strcmp(direction_str, "import")) {
8040 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
8041 dir = BGP_VPN_POLICY_DIR_FROMVPN;
8042 } else if (!strcmp(direction_str, "export")) {
8043 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
8044 dir = BGP_VPN_POLICY_DIR_TOVPN;
8045 } else {
8046 vty_out(vty, "%% unknown direction %s\n", direction_str);
8047 return CMD_WARNING_CONFIG_FAILED;
8048 }
8049
8050 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
8051
8052 if (yes) {
8053 SET_FLAG(bgp->af_flags[afi][safi], flag);
8054 if (!previous_state) {
8055 /* trigger export current vrf */
8056 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
8057 }
8058 } else {
8059 if (previous_state) {
8060 /* trigger un-export current vrf */
8061 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
8062 }
8063 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
8064 }
8065
8066 return CMD_SUCCESS;
8067 }
8068
8069 DEFPY (af_routetarget_import,
8070 af_routetarget_import_cmd,
8071 "[no] <rt|route-target> redirect import RTLIST...",
8072 NO_STR
8073 "Specify route target list\n"
8074 "Specify route target list\n"
8075 "Flow-spec redirect type route target\n"
8076 "Import routes to this address-family\n"
8077 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
8078 {
8079 VTY_DECLVAR_CONTEXT(bgp, bgp);
8080 int ret;
8081 struct ecommunity *ecom = NULL;
8082 afi_t afi;
8083 int idx = 0;
8084 int yes = 1;
8085
8086 if (argv_find(argv, argc, "no", &idx))
8087 yes = 0;
8088
8089 afi = vpn_policy_getafi(vty, bgp, false);
8090 if (afi == AFI_MAX)
8091 return CMD_WARNING_CONFIG_FAILED;
8092
8093 if (yes) {
8094 if (!argv_find(argv, argc, "RTLIST", &idx)) {
8095 vty_out(vty, "%% Missing RTLIST\n");
8096 return CMD_WARNING_CONFIG_FAILED;
8097 }
8098 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
8099 if (ret != CMD_SUCCESS)
8100 return ret;
8101 }
8102
8103 if (yes) {
8104 if (bgp->vpn_policy[afi].import_redirect_rtlist)
8105 ecommunity_free(&bgp->vpn_policy[afi]
8106 .import_redirect_rtlist);
8107 bgp->vpn_policy[afi].import_redirect_rtlist =
8108 ecommunity_dup(ecom);
8109 } else {
8110 if (bgp->vpn_policy[afi].import_redirect_rtlist)
8111 ecommunity_free(&bgp->vpn_policy[afi]
8112 .import_redirect_rtlist);
8113 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
8114 }
8115
8116 if (ecom)
8117 ecommunity_free(&ecom);
8118
8119 return CMD_SUCCESS;
8120 }
8121
8122 DEFUN_NOSH (address_family_ipv4_safi,
8123 address_family_ipv4_safi_cmd,
8124 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
8125 "Enter Address Family command mode\n"
8126 "Address Family\n"
8127 BGP_SAFI_WITH_LABEL_HELP_STR)
8128 {
8129
8130 if (argc == 3) {
8131 VTY_DECLVAR_CONTEXT(bgp, bgp);
8132 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
8133 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
8134 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
8135 && safi != SAFI_EVPN) {
8136 vty_out(vty,
8137 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
8138 return CMD_WARNING_CONFIG_FAILED;
8139 }
8140 vty->node = bgp_node_type(AFI_IP, safi);
8141 } else
8142 vty->node = BGP_IPV4_NODE;
8143
8144 return CMD_SUCCESS;
8145 }
8146
8147 DEFUN_NOSH (address_family_ipv6_safi,
8148 address_family_ipv6_safi_cmd,
8149 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
8150 "Enter Address Family command mode\n"
8151 "Address Family\n"
8152 BGP_SAFI_WITH_LABEL_HELP_STR)
8153 {
8154 if (argc == 3) {
8155 VTY_DECLVAR_CONTEXT(bgp, bgp);
8156 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
8157 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
8158 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
8159 && safi != SAFI_EVPN) {
8160 vty_out(vty,
8161 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
8162 return CMD_WARNING_CONFIG_FAILED;
8163 }
8164 vty->node = bgp_node_type(AFI_IP6, safi);
8165 } else
8166 vty->node = BGP_IPV6_NODE;
8167
8168 return CMD_SUCCESS;
8169 }
8170
8171 #ifdef KEEP_OLD_VPN_COMMANDS
8172 DEFUN_NOSH (address_family_vpnv4,
8173 address_family_vpnv4_cmd,
8174 "address-family vpnv4 [unicast]",
8175 "Enter Address Family command mode\n"
8176 "Address Family\n"
8177 "Address Family modifier\n")
8178 {
8179 vty->node = BGP_VPNV4_NODE;
8180 return CMD_SUCCESS;
8181 }
8182
8183 DEFUN_NOSH (address_family_vpnv6,
8184 address_family_vpnv6_cmd,
8185 "address-family vpnv6 [unicast]",
8186 "Enter Address Family command mode\n"
8187 "Address Family\n"
8188 "Address Family modifier\n")
8189 {
8190 vty->node = BGP_VPNV6_NODE;
8191 return CMD_SUCCESS;
8192 }
8193 #endif /* KEEP_OLD_VPN_COMMANDS */
8194
8195 DEFUN_NOSH (address_family_evpn,
8196 address_family_evpn_cmd,
8197 "address-family l2vpn evpn",
8198 "Enter Address Family command mode\n"
8199 "Address Family\n"
8200 "Address Family modifier\n")
8201 {
8202 VTY_DECLVAR_CONTEXT(bgp, bgp);
8203 vty->node = BGP_EVPN_NODE;
8204 return CMD_SUCCESS;
8205 }
8206
8207 DEFUN_NOSH (exit_address_family,
8208 exit_address_family_cmd,
8209 "exit-address-family",
8210 "Exit from Address Family configuration mode\n")
8211 {
8212 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
8213 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
8214 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
8215 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
8216 || vty->node == BGP_EVPN_NODE
8217 || vty->node == BGP_FLOWSPECV4_NODE
8218 || vty->node == BGP_FLOWSPECV6_NODE)
8219 vty->node = BGP_NODE;
8220 return CMD_SUCCESS;
8221 }
8222
8223 /* Recalculate bestpath and re-advertise a prefix */
8224 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
8225 const char *ip_str, afi_t afi, safi_t safi,
8226 struct prefix_rd *prd)
8227 {
8228 int ret;
8229 struct prefix match;
8230 struct bgp_dest *dest;
8231 struct bgp_dest *rm;
8232 struct bgp *bgp;
8233 struct bgp_table *table;
8234 struct bgp_table *rib;
8235
8236 /* BGP structure lookup. */
8237 if (view_name) {
8238 bgp = bgp_lookup_by_name(view_name);
8239 if (bgp == NULL) {
8240 vty_out(vty, "%% Can't find BGP instance %s\n",
8241 view_name);
8242 return CMD_WARNING;
8243 }
8244 } else {
8245 bgp = bgp_get_default();
8246 if (bgp == NULL) {
8247 vty_out(vty, "%% No BGP process is configured\n");
8248 return CMD_WARNING;
8249 }
8250 }
8251
8252 /* Check IP address argument. */
8253 ret = str2prefix(ip_str, &match);
8254 if (!ret) {
8255 vty_out(vty, "%% address is malformed\n");
8256 return CMD_WARNING;
8257 }
8258
8259 match.family = afi2family(afi);
8260 rib = bgp->rib[afi][safi];
8261
8262 if (safi == SAFI_MPLS_VPN) {
8263 for (dest = bgp_table_top(rib); dest;
8264 dest = bgp_route_next(dest)) {
8265 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
8266
8267 if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
8268 continue;
8269
8270 table = bgp_dest_get_bgp_table_info(dest);
8271 if (table == NULL)
8272 continue;
8273
8274 if ((rm = bgp_node_match(table, &match)) != NULL) {
8275 const struct prefix *rm_p =
8276 bgp_dest_get_prefix(rm);
8277
8278 if (rm_p->prefixlen == match.prefixlen) {
8279 SET_FLAG(rm->flags,
8280 BGP_NODE_USER_CLEAR);
8281 bgp_process(bgp, rm, afi, safi);
8282 }
8283 bgp_dest_unlock_node(rm);
8284 }
8285 }
8286 } else {
8287 if ((dest = bgp_node_match(rib, &match)) != NULL) {
8288 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
8289
8290 if (dest_p->prefixlen == match.prefixlen) {
8291 SET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
8292 bgp_process(bgp, dest, afi, safi);
8293 }
8294 bgp_dest_unlock_node(dest);
8295 }
8296 }
8297
8298 return CMD_SUCCESS;
8299 }
8300
8301 /* one clear bgp command to rule them all */
8302 DEFUN (clear_ip_bgp_all,
8303 clear_ip_bgp_all_cmd,
8304 "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>]",
8305 CLEAR_STR
8306 IP_STR
8307 BGP_STR
8308 BGP_INSTANCE_HELP_STR
8309 BGP_AFI_HELP_STR
8310 "Address Family\n"
8311 BGP_SAFI_WITH_LABEL_HELP_STR
8312 "Address Family modifier\n"
8313 "Clear all peers\n"
8314 "BGP IPv4 neighbor to clear\n"
8315 "BGP IPv6 neighbor to clear\n"
8316 "BGP neighbor on interface to clear\n"
8317 "Clear peers with the AS number\n"
8318 "Clear all external peers\n"
8319 "Clear all members of peer-group\n"
8320 "BGP peer-group name\n"
8321 BGP_SOFT_STR
8322 BGP_SOFT_IN_STR
8323 BGP_SOFT_OUT_STR
8324 BGP_SOFT_IN_STR
8325 "Push out prefix-list ORF and do inbound soft reconfig\n"
8326 BGP_SOFT_OUT_STR)
8327 {
8328 char *vrf = NULL;
8329
8330 afi_t afi = AFI_UNSPEC;
8331 safi_t safi = SAFI_UNSPEC;
8332 enum clear_sort clr_sort = clear_peer;
8333 enum bgp_clear_type clr_type;
8334 char *clr_arg = NULL;
8335
8336 int idx = 0;
8337
8338 /* clear [ip] bgp */
8339 if (argv_find(argv, argc, "ip", &idx))
8340 afi = AFI_IP;
8341
8342 /* [<vrf> VIEWVRFNAME] */
8343 if (argv_find(argv, argc, "vrf", &idx)) {
8344 vrf = argv[idx + 1]->arg;
8345 idx += 2;
8346 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
8347 vrf = NULL;
8348 } else if (argv_find(argv, argc, "view", &idx)) {
8349 /* [<view> VIEWVRFNAME] */
8350 vrf = argv[idx + 1]->arg;
8351 idx += 2;
8352 }
8353 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
8354 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
8355 argv_find_and_parse_safi(argv, argc, &idx, &safi);
8356
8357 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
8358 if (argv_find(argv, argc, "*", &idx)) {
8359 clr_sort = clear_all;
8360 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
8361 clr_sort = clear_peer;
8362 clr_arg = argv[idx]->arg;
8363 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
8364 clr_sort = clear_peer;
8365 clr_arg = argv[idx]->arg;
8366 } else if (argv_find(argv, argc, "peer-group", &idx)) {
8367 clr_sort = clear_group;
8368 idx++;
8369 clr_arg = argv[idx]->arg;
8370 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
8371 clr_sort = clear_peer;
8372 clr_arg = argv[idx]->arg;
8373 } else if (argv_find(argv, argc, "WORD", &idx)) {
8374 clr_sort = clear_peer;
8375 clr_arg = argv[idx]->arg;
8376 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
8377 clr_sort = clear_as;
8378 clr_arg = argv[idx]->arg;
8379 } else if (argv_find(argv, argc, "external", &idx)) {
8380 clr_sort = clear_external;
8381 }
8382
8383 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
8384 if (argv_find(argv, argc, "soft", &idx)) {
8385 if (argv_find(argv, argc, "in", &idx)
8386 || argv_find(argv, argc, "out", &idx))
8387 clr_type = strmatch(argv[idx]->text, "in")
8388 ? BGP_CLEAR_SOFT_IN
8389 : BGP_CLEAR_SOFT_OUT;
8390 else
8391 clr_type = BGP_CLEAR_SOFT_BOTH;
8392 } else if (argv_find(argv, argc, "in", &idx)) {
8393 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
8394 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
8395 : BGP_CLEAR_SOFT_IN;
8396 } else if (argv_find(argv, argc, "out", &idx)) {
8397 clr_type = BGP_CLEAR_SOFT_OUT;
8398 } else
8399 clr_type = BGP_CLEAR_SOFT_NONE;
8400
8401 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
8402 }
8403
8404 DEFUN (clear_ip_bgp_prefix,
8405 clear_ip_bgp_prefix_cmd,
8406 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
8407 CLEAR_STR
8408 IP_STR
8409 BGP_STR
8410 BGP_INSTANCE_HELP_STR
8411 "Clear bestpath and re-advertise\n"
8412 "IPv4 prefix\n")
8413 {
8414 char *vrf = NULL;
8415 char *prefix = NULL;
8416
8417 int idx = 0;
8418
8419 /* [<view|vrf> VIEWVRFNAME] */
8420 if (argv_find(argv, argc, "vrf", &idx)) {
8421 vrf = argv[idx + 1]->arg;
8422 idx += 2;
8423 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
8424 vrf = NULL;
8425 } else if (argv_find(argv, argc, "view", &idx)) {
8426 /* [<view> VIEWVRFNAME] */
8427 vrf = argv[idx + 1]->arg;
8428 idx += 2;
8429 }
8430
8431 prefix = argv[argc - 1]->arg;
8432
8433 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
8434 }
8435
8436 DEFUN (clear_bgp_ipv6_safi_prefix,
8437 clear_bgp_ipv6_safi_prefix_cmd,
8438 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
8439 CLEAR_STR
8440 IP_STR
8441 BGP_STR
8442 "Address Family\n"
8443 BGP_SAFI_HELP_STR
8444 "Clear bestpath and re-advertise\n"
8445 "IPv6 prefix\n")
8446 {
8447 int idx_safi = 0;
8448 int idx_ipv6_prefix = 0;
8449 safi_t safi = SAFI_UNICAST;
8450 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
8451 argv[idx_ipv6_prefix]->arg : NULL;
8452
8453 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
8454 return bgp_clear_prefix(
8455 vty, NULL, prefix, AFI_IP6,
8456 safi, NULL);
8457 }
8458
8459 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
8460 clear_bgp_instance_ipv6_safi_prefix_cmd,
8461 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
8462 CLEAR_STR
8463 IP_STR
8464 BGP_STR
8465 BGP_INSTANCE_HELP_STR
8466 "Address Family\n"
8467 BGP_SAFI_HELP_STR
8468 "Clear bestpath and re-advertise\n"
8469 "IPv6 prefix\n")
8470 {
8471 int idx_safi = 0;
8472 int idx_vrfview = 0;
8473 int idx_ipv6_prefix = 0;
8474 safi_t safi = SAFI_UNICAST;
8475 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
8476 argv[idx_ipv6_prefix]->arg : NULL;
8477 char *vrfview = NULL;
8478
8479 /* [<view|vrf> VIEWVRFNAME] */
8480 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
8481 vrfview = argv[idx_vrfview + 1]->arg;
8482 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
8483 vrfview = NULL;
8484 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
8485 /* [<view> VIEWVRFNAME] */
8486 vrfview = argv[idx_vrfview + 1]->arg;
8487 }
8488 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
8489
8490 return bgp_clear_prefix(
8491 vty, vrfview, prefix,
8492 AFI_IP6, safi, NULL);
8493 }
8494
8495 DEFUN (show_bgp_views,
8496 show_bgp_views_cmd,
8497 "show [ip] bgp views",
8498 SHOW_STR
8499 IP_STR
8500 BGP_STR
8501 "Show the defined BGP views\n")
8502 {
8503 struct list *inst = bm->bgp;
8504 struct listnode *node;
8505 struct bgp *bgp;
8506
8507 vty_out(vty, "Defined BGP views:\n");
8508 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
8509 /* Skip VRFs. */
8510 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
8511 continue;
8512 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
8513 bgp->as);
8514 }
8515
8516 return CMD_SUCCESS;
8517 }
8518
8519 DEFUN (show_bgp_vrfs,
8520 show_bgp_vrfs_cmd,
8521 "show [ip] bgp vrfs [json]",
8522 SHOW_STR
8523 IP_STR
8524 BGP_STR
8525 "Show BGP VRFs\n"
8526 JSON_STR)
8527 {
8528 char buf[ETHER_ADDR_STRLEN];
8529 struct list *inst = bm->bgp;
8530 struct listnode *node;
8531 struct bgp *bgp;
8532 bool uj = use_json(argc, argv);
8533 json_object *json = NULL;
8534 json_object *json_vrfs = NULL;
8535 int count = 0;
8536
8537 if (uj) {
8538 json = json_object_new_object();
8539 json_vrfs = json_object_new_object();
8540 }
8541
8542 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
8543 const char *name, *type;
8544 struct peer *peer;
8545 struct listnode *node2, *nnode2;
8546 int peers_cfg, peers_estb;
8547 json_object *json_vrf = NULL;
8548
8549 /* Skip Views. */
8550 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
8551 continue;
8552
8553 count++;
8554 if (!uj && count == 1) {
8555 vty_out(vty,
8556 "%4s %-5s %-16s %9s %10s %-37s\n",
8557 "Type", "Id", "routerId", "#PeersCfg",
8558 "#PeersEstb", "Name");
8559 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
8560 "L3-VNI", "RouterMAC", "Interface");
8561 }
8562
8563 peers_cfg = peers_estb = 0;
8564 if (uj)
8565 json_vrf = json_object_new_object();
8566
8567
8568 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
8569 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
8570 continue;
8571 peers_cfg++;
8572 if (peer->status == Established)
8573 peers_estb++;
8574 }
8575
8576 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
8577 name = VRF_DEFAULT_NAME;
8578 type = "DFLT";
8579 } else {
8580 name = bgp->name;
8581 type = "VRF";
8582 }
8583
8584
8585 if (uj) {
8586 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
8587 ? -1
8588 : (int64_t)bgp->vrf_id;
8589 json_object_string_add(json_vrf, "type", type);
8590 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
8591 json_object_string_add(json_vrf, "routerId",
8592 inet_ntoa(bgp->router_id));
8593 json_object_int_add(json_vrf, "numConfiguredPeers",
8594 peers_cfg);
8595 json_object_int_add(json_vrf, "numEstablishedPeers",
8596 peers_estb);
8597
8598 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
8599 json_object_string_add(
8600 json_vrf, "rmac",
8601 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
8602 json_object_string_add(json_vrf, "interface",
8603 ifindex2ifname(bgp->l3vni_svi_ifindex,
8604 bgp->vrf_id));
8605 json_object_object_add(json_vrfs, name, json_vrf);
8606 } else {
8607 vty_out(vty,
8608 "%4s %-5d %-16s %-9u %-10u %-37s\n",
8609 type,
8610 bgp->vrf_id == VRF_UNKNOWN ? -1
8611 : (int)bgp->vrf_id,
8612 inet_ntoa(bgp->router_id), peers_cfg,
8613 peers_estb, name);
8614 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
8615 bgp->l3vni,
8616 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
8617 ifindex2ifname(bgp->l3vni_svi_ifindex,
8618 bgp->vrf_id));
8619 }
8620 }
8621
8622 if (uj) {
8623 json_object_object_add(json, "vrfs", json_vrfs);
8624
8625 json_object_int_add(json, "totalVrfs", count);
8626
8627 vty_out(vty, "%s\n", json_object_to_json_string_ext(
8628 json, JSON_C_TO_STRING_PRETTY));
8629 json_object_free(json);
8630 } else {
8631 if (count)
8632 vty_out(vty,
8633 "\nTotal number of VRFs (including default): %d\n",
8634 count);
8635 }
8636
8637 return CMD_SUCCESS;
8638 }
8639
8640 DEFUN (show_bgp_mac_hash,
8641 show_bgp_mac_hash_cmd,
8642 "show bgp mac hash",
8643 SHOW_STR
8644 BGP_STR
8645 "Mac Address\n"
8646 "Mac Address database\n")
8647 {
8648 bgp_mac_dump_table(vty);
8649
8650 return CMD_SUCCESS;
8651 }
8652
8653 static void show_tip_entry(struct hash_bucket *bucket, void *args)
8654 {
8655 struct vty *vty = (struct vty *)args;
8656 struct tip_addr *tip = (struct tip_addr *)bucket->data;
8657
8658 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(tip->addr),
8659 tip->refcnt);
8660 }
8661
8662 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
8663 {
8664 vty_out(vty, "self nexthop database:\n");
8665 bgp_nexthop_show_address_hash(vty, bgp);
8666
8667 vty_out(vty, "Tunnel-ip database:\n");
8668 hash_iterate(bgp->tip_hash,
8669 (void (*)(struct hash_bucket *, void *))show_tip_entry,
8670 vty);
8671 }
8672
8673 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
8674 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
8675 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
8676 "martian next-hops\n"
8677 "martian next-hop database\n")
8678 {
8679 struct bgp *bgp = NULL;
8680 int idx = 0;
8681 char *name = NULL;
8682
8683 /* [<vrf> VIEWVRFNAME] */
8684 if (argv_find(argv, argc, "vrf", &idx)) {
8685 name = argv[idx + 1]->arg;
8686 if (name && strmatch(name, VRF_DEFAULT_NAME))
8687 name = NULL;
8688 } else if (argv_find(argv, argc, "view", &idx))
8689 /* [<view> VIEWVRFNAME] */
8690 name = argv[idx + 1]->arg;
8691 if (name)
8692 bgp = bgp_lookup_by_name(name);
8693 else
8694 bgp = bgp_get_default();
8695
8696 if (!bgp) {
8697 vty_out(vty, "%% No BGP process is configured\n");
8698 return CMD_WARNING;
8699 }
8700 bgp_show_martian_nexthops(vty, bgp);
8701
8702 return CMD_SUCCESS;
8703 }
8704
8705 DEFUN (show_bgp_memory,
8706 show_bgp_memory_cmd,
8707 "show [ip] bgp memory",
8708 SHOW_STR
8709 IP_STR
8710 BGP_STR
8711 "Global BGP memory statistics\n")
8712 {
8713 char memstrbuf[MTYPE_MEMSTR_LEN];
8714 unsigned long count;
8715
8716 /* RIB related usage stats */
8717 count = mtype_stats_alloc(MTYPE_BGP_NODE);
8718 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
8719 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8720 count * sizeof(struct bgp_dest)));
8721
8722 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
8723 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
8724 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8725 count * sizeof(struct bgp_path_info)));
8726 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
8727 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
8728 count,
8729 mtype_memstr(
8730 memstrbuf, sizeof(memstrbuf),
8731 count * sizeof(struct bgp_path_info_extra)));
8732
8733 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
8734 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
8735 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8736 count * sizeof(struct bgp_static)));
8737
8738 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
8739 vty_out(vty, "%ld Packets, using %s of memory\n", count,
8740 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8741 count * sizeof(struct bpacket)));
8742
8743 /* Adj-In/Out */
8744 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
8745 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
8746 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8747 count * sizeof(struct bgp_adj_in)));
8748 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
8749 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
8750 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8751 count * sizeof(struct bgp_adj_out)));
8752
8753 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
8754 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
8755 count,
8756 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8757 count * sizeof(struct bgp_nexthop_cache)));
8758
8759 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
8760 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
8761 count,
8762 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8763 count * sizeof(struct bgp_damp_info)));
8764
8765 /* Attributes */
8766 count = attr_count();
8767 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
8768 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8769 count * sizeof(struct attr)));
8770
8771 if ((count = attr_unknown_count()))
8772 vty_out(vty, "%ld unknown attributes\n", count);
8773
8774 /* AS_PATH attributes */
8775 count = aspath_count();
8776 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
8777 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8778 count * sizeof(struct aspath)));
8779
8780 count = mtype_stats_alloc(MTYPE_AS_SEG);
8781 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
8782 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8783 count * sizeof(struct assegment)));
8784
8785 /* Other attributes */
8786 if ((count = community_count()))
8787 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
8788 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
8789 count * sizeof(struct community)));
8790 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
8791 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
8792 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
8793 count * sizeof(struct ecommunity)));
8794 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
8795 vty_out(vty,
8796 "%ld BGP large-community entries, using %s of memory\n",
8797 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
8798 count * sizeof(struct lcommunity)));
8799
8800 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
8801 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
8802 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8803 count * sizeof(struct cluster_list)));
8804
8805 /* Peer related usage */
8806 count = mtype_stats_alloc(MTYPE_BGP_PEER);
8807 vty_out(vty, "%ld peers, using %s of memory\n", count,
8808 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8809 count * sizeof(struct peer)));
8810
8811 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
8812 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
8813 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8814 count * sizeof(struct peer_group)));
8815
8816 /* Other */
8817 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
8818 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
8819 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
8820 count * sizeof(regex_t)));
8821 return CMD_SUCCESS;
8822 }
8823
8824 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
8825 {
8826 json_object *bestpath = json_object_new_object();
8827
8828 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
8829 json_object_string_add(bestpath, "asPath", "ignore");
8830
8831 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
8832 json_object_string_add(bestpath, "asPath", "confed");
8833
8834 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
8835 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
8836 json_object_string_add(bestpath, "multiPathRelax",
8837 "as-set");
8838 else
8839 json_object_string_add(bestpath, "multiPathRelax",
8840 "true");
8841 } else
8842 json_object_string_add(bestpath, "multiPathRelax", "false");
8843
8844 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
8845 json_object_string_add(bestpath, "compareRouterId", "true");
8846 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
8847 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
8848 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
8849 json_object_string_add(bestpath, "med", "confed");
8850 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
8851 json_object_string_add(bestpath, "med",
8852 "missing-as-worst");
8853 else
8854 json_object_string_add(bestpath, "med", "true");
8855 }
8856
8857 json_object_object_add(json, "bestPath", bestpath);
8858 }
8859
8860 /* Print the error code/subcode for why the peer is down */
8861 static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
8862 json_object *json_peer, bool use_json)
8863 {
8864 const char *code_str;
8865 const char *subcode_str;
8866
8867 if (use_json) {
8868 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
8869 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
8870 char errorcodesubcode_hexstr[5];
8871 char errorcodesubcode_str[256];
8872
8873 code_str = bgp_notify_code_str(peer->notify.code);
8874 subcode_str = bgp_notify_subcode_str(
8875 peer->notify.code,
8876 peer->notify.subcode);
8877
8878 snprintf(errorcodesubcode_hexstr,
8879 sizeof(errorcodesubcode_hexstr), "%02X%02X",
8880 peer->notify.code, peer->notify.subcode);
8881 json_object_string_add(json_peer,
8882 "lastErrorCodeSubcode",
8883 errorcodesubcode_hexstr);
8884 snprintf(errorcodesubcode_str, 255, "%s%s",
8885 code_str, subcode_str);
8886 json_object_string_add(json_peer,
8887 "lastNotificationReason",
8888 errorcodesubcode_str);
8889 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
8890 && peer->notify.code == BGP_NOTIFY_CEASE
8891 && (peer->notify.subcode
8892 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
8893 || peer->notify.subcode
8894 == BGP_NOTIFY_CEASE_ADMIN_RESET)
8895 && peer->notify.length) {
8896 char msgbuf[1024];
8897 const char *msg_str;
8898
8899 msg_str = bgp_notify_admin_message(
8900 msgbuf, sizeof(msgbuf),
8901 (uint8_t *)peer->notify.data,
8902 peer->notify.length);
8903 if (msg_str)
8904 json_object_string_add(
8905 json_peer,
8906 "lastShutdownDescription",
8907 msg_str);
8908 }
8909
8910 }
8911 json_object_string_add(json_peer, "lastResetDueTo",
8912 peer_down_str[(int)peer->last_reset]);
8913 json_object_int_add(json_peer, "lastResetCode",
8914 peer->last_reset);
8915 } else {
8916 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
8917 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
8918 code_str = bgp_notify_code_str(peer->notify.code);
8919 subcode_str =
8920 bgp_notify_subcode_str(peer->notify.code,
8921 peer->notify.subcode);
8922 vty_out(vty, " Notification %s (%s%s)\n",
8923 peer->last_reset == PEER_DOWN_NOTIFY_SEND
8924 ? "sent"
8925 : "received",
8926 code_str, subcode_str);
8927 } else {
8928 vty_out(vty, " %s\n",
8929 peer_down_str[(int)peer->last_reset]);
8930 }
8931 }
8932 }
8933
8934 static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
8935 safi_t safi)
8936 {
8937 return ((peer->status != Established) ||
8938 !peer->afc_recv[afi][safi]);
8939 }
8940
8941 static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
8942 struct peer *peer, json_object *json_peer,
8943 int max_neighbor_width, bool use_json)
8944 {
8945 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
8946 int len;
8947
8948 if (use_json) {
8949 if (peer_dynamic_neighbor(peer))
8950 json_object_boolean_true_add(json_peer,
8951 "dynamicPeer");
8952 if (peer->hostname)
8953 json_object_string_add(json_peer, "hostname",
8954 peer->hostname);
8955
8956 if (peer->domainname)
8957 json_object_string_add(json_peer, "domainname",
8958 peer->domainname);
8959 json_object_int_add(json_peer, "connectionsEstablished",
8960 peer->established);
8961 json_object_int_add(json_peer, "connectionsDropped",
8962 peer->dropped);
8963 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
8964 use_json, json_peer);
8965 if (peer->status == Established)
8966 json_object_string_add(json_peer, "lastResetDueTo",
8967 "AFI/SAFI Not Negotiated");
8968 else
8969 bgp_show_peer_reset(NULL, peer, json_peer, true);
8970 } else {
8971 dn_flag[1] = '\0';
8972 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
8973 if (peer->hostname
8974 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
8975 len = vty_out(vty, "%s%s(%s)", dn_flag,
8976 peer->hostname, peer->host);
8977 else
8978 len = vty_out(vty, "%s%s", dn_flag, peer->host);
8979
8980 /* pad the neighbor column with spaces */
8981 if (len < max_neighbor_width)
8982 vty_out(vty, "%*s", max_neighbor_width - len,
8983 " ");
8984 vty_out(vty, "%7d %7d %9s", peer->established,
8985 peer->dropped,
8986 peer_uptime(peer->uptime, timebuf,
8987 BGP_UPTIME_LEN, 0, NULL));
8988 if (peer->status == Established)
8989 vty_out(vty, " AFI/SAFI Not Negotiated\n");
8990 else
8991 bgp_show_peer_reset(vty, peer, NULL,
8992 false);
8993 }
8994 }
8995
8996
8997 /* Show BGP peer's summary information. */
8998 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
8999 bool show_failed, bool show_established,
9000 bool use_json)
9001 {
9002 struct peer *peer;
9003 struct listnode *node, *nnode;
9004 unsigned int count = 0, dn_count = 0;
9005 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
9006 char neighbor_buf[VTY_BUFSIZ];
9007 int neighbor_col_default_width = 16;
9008 int len, failed_count = 0;
9009 int max_neighbor_width = 0;
9010 int pfx_rcd_safi;
9011 json_object *json = NULL;
9012 json_object *json_peer = NULL;
9013 json_object *json_peers = NULL;
9014 struct peer_af *paf;
9015 struct bgp_filter *filter;
9016
9017 /* labeled-unicast routes are installed in the unicast table so in order
9018 * to
9019 * display the correct PfxRcd value we must look at SAFI_UNICAST
9020 */
9021
9022 if (safi == SAFI_LABELED_UNICAST)
9023 pfx_rcd_safi = SAFI_UNICAST;
9024 else
9025 pfx_rcd_safi = safi;
9026
9027 if (use_json) {
9028 json = json_object_new_object();
9029 json_peers = json_object_new_object();
9030 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
9031 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
9032 continue;
9033
9034 if (peer->afc[afi][safi]) {
9035 /* See if we have at least a single failed peer */
9036 if (bgp_has_peer_failed(peer, afi, safi))
9037 failed_count++;
9038 count++;
9039 }
9040 if (peer_dynamic_neighbor(peer))
9041 dn_count++;
9042 }
9043
9044 } else {
9045 /* Loop over all neighbors that will be displayed to determine
9046 * how many
9047 * characters are needed for the Neighbor column
9048 */
9049 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
9050 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
9051 continue;
9052
9053 if (peer->afc[afi][safi]) {
9054 memset(dn_flag, '\0', sizeof(dn_flag));
9055 if (peer_dynamic_neighbor(peer))
9056 dn_flag[0] = '*';
9057
9058 if (peer->hostname
9059 && CHECK_FLAG(bgp->flags,
9060 BGP_FLAG_SHOW_HOSTNAME))
9061 snprintf(neighbor_buf,
9062 sizeof(neighbor_buf),
9063 "%s%s(%s) ", dn_flag,
9064 peer->hostname, peer->host);
9065 else
9066 snprintf(neighbor_buf,
9067 sizeof(neighbor_buf), "%s%s ",
9068 dn_flag, peer->host);
9069
9070 len = strlen(neighbor_buf);
9071
9072 if (len > max_neighbor_width)
9073 max_neighbor_width = len;
9074
9075 /* See if we have at least a single failed peer */
9076 if (bgp_has_peer_failed(peer, afi, safi))
9077 failed_count++;
9078 count++;
9079 }
9080 }
9081
9082 /* Originally we displayed the Neighbor column as 16
9083 * characters wide so make that the default
9084 */
9085 if (max_neighbor_width < neighbor_col_default_width)
9086 max_neighbor_width = neighbor_col_default_width;
9087 }
9088
9089 if (show_failed && !failed_count) {
9090 if (use_json) {
9091 json_object_int_add(json, "failedPeersCount", 0);
9092 json_object_int_add(json, "dynamicPeers", dn_count);
9093 json_object_int_add(json, "totalPeers", count);
9094
9095 vty_out(vty, "%s\n", json_object_to_json_string_ext(
9096 json, JSON_C_TO_STRING_PRETTY));
9097 json_object_free(json);
9098 } else {
9099 vty_out(vty, "%% No failed BGP neighbors found\n");
9100 vty_out(vty, "\nTotal number of neighbors %d\n", count);
9101 }
9102 return CMD_SUCCESS;
9103 }
9104
9105 count = 0; /* Reset the value as its used again */
9106 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
9107 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
9108 continue;
9109
9110 if (!peer->afc[afi][safi])
9111 continue;
9112
9113 if (!count) {
9114 unsigned long ents;
9115 char memstrbuf[MTYPE_MEMSTR_LEN];
9116 int64_t vrf_id_ui;
9117
9118 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
9119 ? -1
9120 : (int64_t)bgp->vrf_id;
9121
9122 /* Usage summary and header */
9123 if (use_json) {
9124 json_object_string_add(
9125 json, "routerId",
9126 inet_ntoa(bgp->router_id));
9127 json_object_int_add(json, "as", bgp->as);
9128 json_object_int_add(json, "vrfId", vrf_id_ui);
9129 json_object_string_add(
9130 json, "vrfName",
9131 (bgp->inst_type
9132 == BGP_INSTANCE_TYPE_DEFAULT)
9133 ? VRF_DEFAULT_NAME
9134 : bgp->name);
9135 } else {
9136 vty_out(vty,
9137 "BGP router identifier %s, local AS number %u vrf-id %d",
9138 inet_ntoa(bgp->router_id), bgp->as,
9139 bgp->vrf_id == VRF_UNKNOWN
9140 ? -1
9141 : (int)bgp->vrf_id);
9142 vty_out(vty, "\n");
9143 }
9144
9145 if (bgp_update_delay_configured(bgp)) {
9146 if (use_json) {
9147 json_object_int_add(
9148 json, "updateDelayLimit",
9149 bgp->v_update_delay);
9150
9151 if (bgp->v_update_delay
9152 != bgp->v_establish_wait)
9153 json_object_int_add(
9154 json,
9155 "updateDelayEstablishWait",
9156 bgp->v_establish_wait);
9157
9158 if (bgp_update_delay_active(bgp)) {
9159 json_object_string_add(
9160 json,
9161 "updateDelayFirstNeighbor",
9162 bgp->update_delay_begin_time);
9163 json_object_boolean_true_add(
9164 json,
9165 "updateDelayInProgress");
9166 } else {
9167 if (bgp->update_delay_over) {
9168 json_object_string_add(
9169 json,
9170 "updateDelayFirstNeighbor",
9171 bgp->update_delay_begin_time);
9172 json_object_string_add(
9173 json,
9174 "updateDelayBestpathResumed",
9175 bgp->update_delay_end_time);
9176 json_object_string_add(
9177 json,
9178 "updateDelayZebraUpdateResume",
9179 bgp->update_delay_zebra_resume_time);
9180 json_object_string_add(
9181 json,
9182 "updateDelayPeerUpdateResume",
9183 bgp->update_delay_peers_resume_time);
9184 }
9185 }
9186 } else {
9187 vty_out(vty,
9188 "Read-only mode update-delay limit: %d seconds\n",
9189 bgp->v_update_delay);
9190 if (bgp->v_update_delay
9191 != bgp->v_establish_wait)
9192 vty_out(vty,
9193 " Establish wait: %d seconds\n",
9194 bgp->v_establish_wait);
9195
9196 if (bgp_update_delay_active(bgp)) {
9197 vty_out(vty,
9198 " First neighbor established: %s\n",
9199 bgp->update_delay_begin_time);
9200 vty_out(vty,
9201 " Delay in progress\n");
9202 } else {
9203 if (bgp->update_delay_over) {
9204 vty_out(vty,
9205 " First neighbor established: %s\n",
9206 bgp->update_delay_begin_time);
9207 vty_out(vty,
9208 " Best-paths resumed: %s\n",
9209 bgp->update_delay_end_time);
9210 vty_out(vty,
9211 " zebra update resumed: %s\n",
9212 bgp->update_delay_zebra_resume_time);
9213 vty_out(vty,
9214 " peers update resumed: %s\n",
9215 bgp->update_delay_peers_resume_time);
9216 }
9217 }
9218 }
9219 }
9220
9221 if (use_json) {
9222 if (bgp_maxmed_onstartup_configured(bgp)
9223 && bgp->maxmed_active)
9224 json_object_boolean_true_add(
9225 json, "maxMedOnStartup");
9226 if (bgp->v_maxmed_admin)
9227 json_object_boolean_true_add(
9228 json, "maxMedAdministrative");
9229
9230 json_object_int_add(
9231 json, "tableVersion",
9232 bgp_table_version(bgp->rib[afi][safi]));
9233
9234 ents = bgp_table_count(bgp->rib[afi][safi]);
9235 json_object_int_add(json, "ribCount", ents);
9236 json_object_int_add(
9237 json, "ribMemory",
9238 ents * sizeof(struct bgp_dest));
9239
9240 ents = bgp->af_peer_count[afi][safi];
9241 json_object_int_add(json, "peerCount", ents);
9242 json_object_int_add(json, "peerMemory",
9243 ents * sizeof(struct peer));
9244
9245 if ((ents = listcount(bgp->group))) {
9246 json_object_int_add(
9247 json, "peerGroupCount", ents);
9248 json_object_int_add(
9249 json, "peerGroupMemory",
9250 ents * sizeof(struct
9251 peer_group));
9252 }
9253
9254 if (CHECK_FLAG(bgp->af_flags[afi][safi],
9255 BGP_CONFIG_DAMPENING))
9256 json_object_boolean_true_add(
9257 json, "dampeningEnabled");
9258 } else {
9259 if (bgp_maxmed_onstartup_configured(bgp)
9260 && bgp->maxmed_active)
9261 vty_out(vty,
9262 "Max-med on-startup active\n");
9263 if (bgp->v_maxmed_admin)
9264 vty_out(vty,
9265 "Max-med administrative active\n");
9266
9267 vty_out(vty, "BGP table version %" PRIu64 "\n",
9268 bgp_table_version(bgp->rib[afi][safi]));
9269
9270 ents = bgp_table_count(bgp->rib[afi][safi]);
9271 vty_out(vty,
9272 "RIB entries %ld, using %s of memory\n",
9273 ents,
9274 mtype_memstr(
9275 memstrbuf, sizeof(memstrbuf),
9276 ents
9277 * sizeof(struct
9278 bgp_dest)));
9279
9280 /* Peer related usage */
9281 ents = bgp->af_peer_count[afi][safi];
9282 vty_out(vty, "Peers %ld, using %s of memory\n",
9283 ents,
9284 mtype_memstr(
9285 memstrbuf, sizeof(memstrbuf),
9286 ents * sizeof(struct peer)));
9287
9288 if ((ents = listcount(bgp->group)))
9289 vty_out(vty,
9290 "Peer groups %ld, using %s of memory\n",
9291 ents,
9292 mtype_memstr(
9293 memstrbuf,
9294 sizeof(memstrbuf),
9295 ents * sizeof(struct
9296 peer_group)));
9297
9298 if (CHECK_FLAG(bgp->af_flags[afi][safi],
9299 BGP_CONFIG_DAMPENING))
9300 vty_out(vty, "Dampening enabled.\n");
9301 vty_out(vty, "\n");
9302
9303 /* Subtract 8 here because 'Neighbor' is
9304 * 8 characters */
9305 vty_out(vty, "Neighbor");
9306 vty_out(vty, "%*s", max_neighbor_width - 8,
9307 " ");
9308 if (show_failed)
9309 vty_out(vty, "EstdCnt DropCnt ResetTime Reason\n");
9310 else
9311 vty_out(vty,
9312 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd PfxSnt\n");
9313 }
9314 }
9315
9316 paf = peer_af_find(peer, afi, safi);
9317 filter = &peer->filter[afi][safi];
9318
9319 count++;
9320 /* Works for both failed & successful cases */
9321 if (peer_dynamic_neighbor(peer))
9322 dn_count++;
9323
9324 if (use_json) {
9325 json_peer = NULL;
9326
9327 if (show_failed &&
9328 bgp_has_peer_failed(peer, afi, safi)) {
9329 json_peer = json_object_new_object();
9330 bgp_show_failed_summary(vty, bgp, peer,
9331 json_peer, 0, use_json);
9332 } else if (!show_failed) {
9333 if (show_established
9334 && bgp_has_peer_failed(peer, afi, safi))
9335 continue;
9336
9337 json_peer = json_object_new_object();
9338 if (peer_dynamic_neighbor(peer)) {
9339 json_object_boolean_true_add(json_peer,
9340 "dynamicPeer");
9341 }
9342
9343 if (peer->hostname)
9344 json_object_string_add(json_peer, "hostname",
9345 peer->hostname);
9346
9347 if (peer->domainname)
9348 json_object_string_add(json_peer, "domainname",
9349 peer->domainname);
9350
9351 json_object_int_add(json_peer, "remoteAs", peer->as);
9352 json_object_int_add(json_peer, "version", 4);
9353 json_object_int_add(json_peer, "msgRcvd",
9354 PEER_TOTAL_RX(peer));
9355 json_object_int_add(json_peer, "msgSent",
9356 PEER_TOTAL_TX(peer));
9357
9358 atomic_size_t outq_count, inq_count;
9359 outq_count = atomic_load_explicit(
9360 &peer->obuf->count,
9361 memory_order_relaxed);
9362 inq_count = atomic_load_explicit(
9363 &peer->ibuf->count,
9364 memory_order_relaxed);
9365
9366 json_object_int_add(json_peer, "tableVersion",
9367 peer->version[afi][safi]);
9368 json_object_int_add(json_peer, "outq",
9369 outq_count);
9370 json_object_int_add(json_peer, "inq",
9371 inq_count);
9372 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
9373 use_json, json_peer);
9374
9375 json_object_int_add(json_peer, "pfxRcd",
9376 peer->pcount[afi][pfx_rcd_safi]);
9377
9378 if (paf && PAF_SUBGRP(paf))
9379 json_object_int_add(json_peer,
9380 "pfxSnt",
9381 (PAF_SUBGRP(paf))->scount);
9382 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
9383 || CHECK_FLAG(peer->bgp->flags,
9384 BGP_FLAG_SHUTDOWN))
9385 json_object_string_add(json_peer, "state",
9386 "Idle (Admin)");
9387 else if (peer->afc_recv[afi][safi])
9388 json_object_string_add(
9389 json_peer, "state",
9390 lookup_msg(bgp_status_msg, peer->status,
9391 NULL));
9392 else if (CHECK_FLAG(peer->sflags,
9393 PEER_STATUS_PREFIX_OVERFLOW))
9394 json_object_string_add(json_peer, "state",
9395 "Idle (PfxCt)");
9396 else
9397 json_object_string_add(
9398 json_peer, "state",
9399 lookup_msg(bgp_status_msg, peer->status,
9400 NULL));
9401 json_object_int_add(json_peer, "connectionsEstablished",
9402 peer->established);
9403 json_object_int_add(json_peer, "connectionsDropped",
9404 peer->dropped);
9405 }
9406 /* Avoid creating empty peer dicts in JSON */
9407 if (json_peer == NULL)
9408 continue;
9409
9410 if (peer->conf_if)
9411 json_object_string_add(json_peer, "idType",
9412 "interface");
9413 else if (peer->su.sa.sa_family == AF_INET)
9414 json_object_string_add(json_peer, "idType",
9415 "ipv4");
9416 else if (peer->su.sa.sa_family == AF_INET6)
9417 json_object_string_add(json_peer, "idType",
9418 "ipv6");
9419 json_object_object_add(json_peers, peer->host,
9420 json_peer);
9421 } else {
9422 if (show_failed &&
9423 bgp_has_peer_failed(peer, afi, safi)) {
9424 bgp_show_failed_summary(vty, bgp, peer, NULL,
9425 max_neighbor_width,
9426 use_json);
9427 } else if (!show_failed) {
9428 if (show_established
9429 && bgp_has_peer_failed(peer, afi, safi))
9430 continue;
9431
9432 memset(dn_flag, '\0', sizeof(dn_flag));
9433 if (peer_dynamic_neighbor(peer)) {
9434 dn_flag[0] = '*';
9435 }
9436
9437 if (peer->hostname
9438 && CHECK_FLAG(bgp->flags,
9439 BGP_FLAG_SHOW_HOSTNAME))
9440 len = vty_out(vty, "%s%s(%s)", dn_flag,
9441 peer->hostname,
9442 peer->host);
9443 else
9444 len = vty_out(vty, "%s%s", dn_flag, peer->host);
9445
9446 /* pad the neighbor column with spaces */
9447 if (len < max_neighbor_width)
9448 vty_out(vty, "%*s", max_neighbor_width - len,
9449 " ");
9450
9451 atomic_size_t outq_count, inq_count;
9452 outq_count = atomic_load_explicit(
9453 &peer->obuf->count,
9454 memory_order_relaxed);
9455 inq_count = atomic_load_explicit(
9456 &peer->ibuf->count,
9457 memory_order_relaxed);
9458
9459 vty_out(vty,
9460 "4 %10u %9u %9u %8" PRIu64" %4zu %4zu %8s",
9461 peer->as, PEER_TOTAL_RX(peer),
9462 PEER_TOTAL_TX(peer),
9463 peer->version[afi][safi], inq_count,
9464 outq_count,
9465 peer_uptime(peer->uptime, timebuf,
9466 BGP_UPTIME_LEN, 0, NULL));
9467
9468 if (peer->status == Established) {
9469 if (peer->afc_recv[afi][safi]) {
9470 if (CHECK_FLAG(
9471 bgp->flags,
9472 BGP_FLAG_EBGP_REQUIRES_POLICY)
9473 && !bgp_inbound_policy_exists(
9474 peer, filter))
9475 vty_out(vty, " %12s",
9476 "(Policy)");
9477 else
9478 vty_out(vty,
9479 " %12u",
9480 peer->pcount
9481 [afi]
9482 [pfx_rcd_safi]);
9483 } else {
9484 vty_out(vty, " NoNeg");
9485 }
9486
9487 if (paf && PAF_SUBGRP(paf)) {
9488 if (CHECK_FLAG(
9489 bgp->flags,
9490 BGP_FLAG_EBGP_REQUIRES_POLICY)
9491 && !bgp_outbound_policy_exists(
9492 peer, filter))
9493 vty_out(vty, " %8s",
9494 "(Policy)");
9495 else
9496 vty_out(vty,
9497 " %8u",
9498 (PAF_SUBGRP(
9499 paf))
9500 ->scount);
9501 }
9502 } else {
9503 if (CHECK_FLAG(peer->flags,
9504 PEER_FLAG_SHUTDOWN)
9505 || CHECK_FLAG(peer->bgp->flags,
9506 BGP_FLAG_SHUTDOWN))
9507 vty_out(vty, " Idle (Admin)");
9508 else if (CHECK_FLAG(
9509 peer->sflags,
9510 PEER_STATUS_PREFIX_OVERFLOW))
9511 vty_out(vty, " Idle (PfxCt)");
9512 else
9513 vty_out(vty, " %12s",
9514 lookup_msg(bgp_status_msg,
9515 peer->status, NULL));
9516
9517 vty_out(vty, " %8u", 0);
9518 }
9519 vty_out(vty, "\n");
9520 }
9521
9522 }
9523 }
9524
9525 if (use_json) {
9526 json_object_object_add(json, "peers", json_peers);
9527 json_object_int_add(json, "failedPeers", failed_count);
9528 json_object_int_add(json, "totalPeers", count);
9529 json_object_int_add(json, "dynamicPeers", dn_count);
9530
9531 if (!show_failed)
9532 bgp_show_bestpath_json(bgp, json);
9533
9534 vty_out(vty, "%s\n", json_object_to_json_string_ext(
9535 json, JSON_C_TO_STRING_PRETTY));
9536 json_object_free(json);
9537 } else {
9538 if (count)
9539 vty_out(vty, "\nTotal number of neighbors %d\n", count);
9540 else {
9541 vty_out(vty, "No %s neighbor is configured\n",
9542 get_afi_safi_str(afi, safi, false));
9543 }
9544
9545 if (dn_count) {
9546 vty_out(vty, "* - dynamic neighbor\n");
9547 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
9548 dn_count, bgp->dynamic_neighbors_limit);
9549 }
9550 }
9551
9552 return CMD_SUCCESS;
9553 }
9554
9555 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
9556 int safi, bool show_failed,
9557 bool show_established, bool use_json)
9558 {
9559 int is_first = 1;
9560 int afi_wildcard = (afi == AFI_MAX);
9561 int safi_wildcard = (safi == SAFI_MAX);
9562 int is_wildcard = (afi_wildcard || safi_wildcard);
9563 bool nbr_output = false;
9564
9565 if (use_json && is_wildcard)
9566 vty_out(vty, "{\n");
9567 if (afi_wildcard)
9568 afi = 1; /* AFI_IP */
9569 while (afi < AFI_MAX) {
9570 if (safi_wildcard)
9571 safi = 1; /* SAFI_UNICAST */
9572 while (safi < SAFI_MAX) {
9573 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
9574 nbr_output = true;
9575
9576 if (is_wildcard) {
9577 /*
9578 * So limit output to those afi/safi
9579 * pairs that
9580 * actualy have something interesting in
9581 * them
9582 */
9583 if (use_json) {
9584 if (!is_first)
9585 vty_out(vty, ",\n");
9586 else
9587 is_first = 0;
9588
9589 vty_out(vty, "\"%s\":",
9590 get_afi_safi_str(afi,
9591 safi,
9592 true));
9593 } else {
9594 vty_out(vty, "\n%s Summary:\n",
9595 get_afi_safi_str(afi,
9596 safi,
9597 false));
9598 }
9599 }
9600 bgp_show_summary(vty, bgp, afi, safi,
9601 show_failed, show_established,
9602 use_json);
9603 }
9604 safi++;
9605 if (!safi_wildcard)
9606 safi = SAFI_MAX;
9607 }
9608 afi++;
9609 if (!afi_wildcard)
9610 afi = AFI_MAX;
9611 }
9612
9613 if (use_json && is_wildcard)
9614 vty_out(vty, "}\n");
9615 else if (!nbr_output) {
9616 if (use_json)
9617 vty_out(vty, "{}\n");
9618 else
9619 vty_out(vty, "%% No BGP neighbors found\n");
9620 }
9621 }
9622
9623 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
9624 safi_t safi, bool show_failed,
9625 bool show_established,
9626 bool use_json)
9627 {
9628 struct listnode *node, *nnode;
9629 struct bgp *bgp;
9630 int is_first = 1;
9631 bool nbr_output = false;
9632
9633 if (use_json)
9634 vty_out(vty, "{\n");
9635
9636 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9637 nbr_output = true;
9638 if (use_json) {
9639 if (!is_first)
9640 vty_out(vty, ",\n");
9641 else
9642 is_first = 0;
9643
9644 vty_out(vty, "\"%s\":",
9645 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
9646 ? VRF_DEFAULT_NAME
9647 : bgp->name);
9648 } else {
9649 vty_out(vty, "\nInstance %s:\n",
9650 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
9651 ? VRF_DEFAULT_NAME
9652 : bgp->name);
9653 }
9654 bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_failed,
9655 show_established, use_json);
9656 }
9657
9658 if (use_json)
9659 vty_out(vty, "}\n");
9660 else if (!nbr_output)
9661 vty_out(vty, "%% BGP instance not found\n");
9662 }
9663
9664 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
9665 safi_t safi, bool show_failed, bool show_established,
9666 bool use_json)
9667 {
9668 struct bgp *bgp;
9669
9670 if (name) {
9671 if (strmatch(name, "all")) {
9672 bgp_show_all_instances_summary_vty(
9673 vty, afi, safi, show_failed, show_established,
9674 use_json);
9675 return CMD_SUCCESS;
9676 } else {
9677 bgp = bgp_lookup_by_name(name);
9678
9679 if (!bgp) {
9680 if (use_json)
9681 vty_out(vty, "{}\n");
9682 else
9683 vty_out(vty,
9684 "%% BGP instance not found\n");
9685 return CMD_WARNING;
9686 }
9687
9688 bgp_show_summary_afi_safi(vty, bgp, afi, safi,
9689 show_failed, show_established,
9690 use_json);
9691 return CMD_SUCCESS;
9692 }
9693 }
9694
9695 bgp = bgp_get_default();
9696
9697 if (bgp)
9698 bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_failed,
9699 show_established, use_json);
9700 else {
9701 if (use_json)
9702 vty_out(vty, "{}\n");
9703 else
9704 vty_out(vty, "%% BGP instance not found\n");
9705 return CMD_WARNING;
9706 }
9707
9708 return CMD_SUCCESS;
9709 }
9710
9711 /* `show [ip] bgp summary' commands. */
9712 DEFUN (show_ip_bgp_summary,
9713 show_ip_bgp_summary_cmd,
9714 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [established|failed] [json]",
9715 SHOW_STR
9716 IP_STR
9717 BGP_STR
9718 BGP_INSTANCE_HELP_STR
9719 BGP_AFI_HELP_STR
9720 BGP_SAFI_WITH_LABEL_HELP_STR
9721 "Summary of BGP neighbor status\n"
9722 "Show only sessions in Established state\n"
9723 "Show only sessions not in Established state\n"
9724 JSON_STR)
9725 {
9726 char *vrf = NULL;
9727 afi_t afi = AFI_MAX;
9728 safi_t safi = SAFI_MAX;
9729 bool show_failed = false;
9730 bool show_established = false;
9731
9732 int idx = 0;
9733
9734 /* show [ip] bgp */
9735 if (argv_find(argv, argc, "ip", &idx))
9736 afi = AFI_IP;
9737 /* [<vrf> VIEWVRFNAME] */
9738 if (argv_find(argv, argc, "vrf", &idx)) {
9739 vrf = argv[idx + 1]->arg;
9740 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9741 vrf = NULL;
9742 } else if (argv_find(argv, argc, "view", &idx))
9743 /* [<view> VIEWVRFNAME] */
9744 vrf = argv[idx + 1]->arg;
9745 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
9746 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
9747 argv_find_and_parse_safi(argv, argc, &idx, &safi);
9748 }
9749
9750 if (argv_find(argv, argc, "failed", &idx))
9751 show_failed = true;
9752 if (argv_find(argv, argc, "established", &idx))
9753 show_established = true;
9754
9755 bool uj = use_json(argc, argv);
9756
9757 return bgp_show_summary_vty(vty, vrf, afi, safi, show_failed,
9758 show_established, uj);
9759 }
9760
9761 const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
9762 {
9763 if (for_json)
9764 return get_afi_safi_json_str(afi, safi);
9765 else
9766 return get_afi_safi_vty_str(afi, safi);
9767 }
9768
9769
9770 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
9771 afi_t afi, safi_t safi,
9772 uint16_t adv_smcap, uint16_t adv_rmcap,
9773 uint16_t rcv_smcap, uint16_t rcv_rmcap,
9774 bool use_json, json_object *json_pref)
9775 {
9776 /* Send-Mode */
9777 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
9778 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
9779 if (use_json) {
9780 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
9781 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
9782 json_object_string_add(json_pref, "sendMode",
9783 "advertisedAndReceived");
9784 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
9785 json_object_string_add(json_pref, "sendMode",
9786 "advertised");
9787 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
9788 json_object_string_add(json_pref, "sendMode",
9789 "received");
9790 } else {
9791 vty_out(vty, " Send-mode: ");
9792 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
9793 vty_out(vty, "advertised");
9794 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
9795 vty_out(vty, "%sreceived",
9796 CHECK_FLAG(p->af_cap[afi][safi],
9797 adv_smcap)
9798 ? ", "
9799 : "");
9800 vty_out(vty, "\n");
9801 }
9802 }
9803
9804 /* Receive-Mode */
9805 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
9806 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
9807 if (use_json) {
9808 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
9809 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
9810 json_object_string_add(json_pref, "recvMode",
9811 "advertisedAndReceived");
9812 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
9813 json_object_string_add(json_pref, "recvMode",
9814 "advertised");
9815 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
9816 json_object_string_add(json_pref, "recvMode",
9817 "received");
9818 } else {
9819 vty_out(vty, " Receive-mode: ");
9820 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
9821 vty_out(vty, "advertised");
9822 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
9823 vty_out(vty, "%sreceived",
9824 CHECK_FLAG(p->af_cap[afi][safi],
9825 adv_rmcap)
9826 ? ", "
9827 : "");
9828 vty_out(vty, "\n");
9829 }
9830 }
9831 }
9832
9833 static void bgp_show_neighnor_graceful_restart_rbit(struct vty *vty,
9834 struct peer *p,
9835 bool use_json,
9836 json_object *json)
9837 {
9838 bool rbit_status = false;
9839
9840 if (!use_json)
9841 vty_out(vty, "\n R bit: ");
9842
9843 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
9844 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
9845 && (p->status == Established)) {
9846
9847 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_BIT_RCV))
9848 rbit_status = true;
9849 else
9850 rbit_status = false;
9851 }
9852
9853 if (rbit_status) {
9854 if (use_json)
9855 json_object_boolean_true_add(json, "rBit");
9856 else
9857 vty_out(vty, "True\n");
9858 } else {
9859 if (use_json)
9860 json_object_boolean_false_add(json, "rBit");
9861 else
9862 vty_out(vty, "False\n");
9863 }
9864 }
9865
9866 static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
9867 struct peer *peer,
9868 bool use_json,
9869 json_object *json)
9870 {
9871 const char *mode = "NotApplicable";
9872
9873 if (!use_json)
9874 vty_out(vty, "\n Remote GR Mode: ");
9875
9876 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
9877 && (peer->status == Established)) {
9878
9879 if ((peer->nsf_af_count == 0)
9880 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
9881
9882 mode = "Disable";
9883
9884 } else if (peer->nsf_af_count == 0
9885 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
9886
9887 mode = "Helper";
9888
9889 } else if (peer->nsf_af_count != 0
9890 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
9891
9892 mode = "Restart";
9893 }
9894 }
9895
9896 if (use_json) {
9897 json_object_string_add(json, "remoteGrMode", mode);
9898 } else
9899 vty_out(vty, mode, "\n");
9900 }
9901
9902 static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
9903 struct peer *p,
9904 bool use_json,
9905 json_object *json)
9906 {
9907 const char *mode = "Invalid";
9908
9909 if (!use_json)
9910 vty_out(vty, " Local GR Mode: ");
9911
9912 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
9913 mode = "Helper";
9914 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
9915 mode = "Restart";
9916 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
9917 mode = "Disable";
9918 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
9919 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
9920 mode = "Helper*";
9921 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
9922 mode = "Restart*";
9923 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
9924 mode = "Disable*";
9925 else
9926 mode = "Invalid*";
9927 }
9928
9929 if (use_json) {
9930 json_object_string_add(json, "localGrMode", mode);
9931 } else {
9932 vty_out(vty, mode, "\n");
9933 }
9934 }
9935
9936 static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
9937 struct vty *vty, struct peer *peer, bool use_json, json_object *json)
9938 {
9939 afi_t afi;
9940 safi_t safi;
9941 json_object *json_afi_safi = NULL;
9942 json_object *json_timer = NULL;
9943 json_object *json_endofrib_status = NULL;
9944 bool eor_flag = false;
9945
9946 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
9947 for (safi = SAFI_UNICAST; safi <= SAFI_MPLS_VPN; safi++) {
9948 if (!peer->afc[afi][safi])
9949 continue;
9950
9951 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
9952 || !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
9953 continue;
9954
9955 if (use_json) {
9956 json_afi_safi = json_object_new_object();
9957 json_endofrib_status = json_object_new_object();
9958 json_timer = json_object_new_object();
9959 }
9960
9961 if (peer->eor_stime[afi][safi]
9962 >= peer->pkt_stime[afi][safi])
9963 eor_flag = true;
9964 else
9965 eor_flag = false;
9966
9967 if (!use_json) {
9968 vty_out(vty, " %s:\n",
9969 get_afi_safi_str(afi, safi, false));
9970
9971 vty_out(vty, " F bit: ");
9972 }
9973
9974 if (peer->nsf[afi][safi]
9975 && CHECK_FLAG(peer->af_cap[afi][safi],
9976 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
9977
9978 if (use_json) {
9979 json_object_boolean_true_add(
9980 json_afi_safi, "fBit");
9981 } else
9982 vty_out(vty, "True\n");
9983 } else {
9984 if (use_json)
9985 json_object_boolean_false_add(
9986 json_afi_safi, "fBit");
9987 else
9988 vty_out(vty, "False\n");
9989 }
9990
9991 if (!use_json)
9992 vty_out(vty, " End-of-RIB sent: ");
9993
9994 if (CHECK_FLAG(peer->af_sflags[afi][safi],
9995 PEER_STATUS_EOR_SEND)) {
9996 if (use_json) {
9997 json_object_boolean_true_add(
9998 json_endofrib_status,
9999 "endOfRibSend");
10000
10001 PRINT_EOR_JSON(eor_flag);
10002 } else {
10003 vty_out(vty, "Yes\n");
10004 vty_out(vty,
10005 " End-of-RIB sent after update: ");
10006
10007 PRINT_EOR(eor_flag);
10008 }
10009 } else {
10010 if (use_json) {
10011 json_object_boolean_false_add(
10012 json_endofrib_status,
10013 "endOfRibSend");
10014 json_object_boolean_false_add(
10015 json_endofrib_status,
10016 "endOfRibSentAfterUpdate");
10017 } else {
10018 vty_out(vty, "No\n");
10019 vty_out(vty,
10020 " End-of-RIB sent after update: ");
10021 vty_out(vty, "No\n");
10022 }
10023 }
10024
10025 if (!use_json)
10026 vty_out(vty, " End-of-RIB received: ");
10027
10028 if (CHECK_FLAG(peer->af_sflags[afi][safi],
10029 PEER_STATUS_EOR_RECEIVED)) {
10030 if (use_json)
10031 json_object_boolean_true_add(
10032 json_endofrib_status,
10033 "endOfRibRecv");
10034 else
10035 vty_out(vty, "Yes\n");
10036 } else {
10037 if (use_json)
10038 json_object_boolean_false_add(
10039 json_endofrib_status,
10040 "endOfRibRecv");
10041 else
10042 vty_out(vty, "No\n");
10043 }
10044
10045 if (use_json) {
10046 json_object_int_add(json_timer,
10047 "stalePathTimer",
10048 peer->bgp->stalepath_time);
10049
10050 if (peer->t_gr_stale != NULL) {
10051 json_object_int_add(
10052 json_timer,
10053 "stalePathTimerRemaining",
10054 thread_timer_remain_second(
10055 peer->t_gr_stale));
10056 }
10057
10058 /* Display Configured Selection
10059 * Deferral only when when
10060 * Gr mode is enabled.
10061 */
10062 if (CHECK_FLAG(peer->flags,
10063 PEER_FLAG_GRACEFUL_RESTART)) {
10064 json_object_int_add(
10065 json_timer,
10066 "selectionDeferralTimer",
10067 peer->bgp->stalepath_time);
10068 }
10069
10070 if (peer->bgp->gr_info[afi][safi]
10071 .t_select_deferral
10072 != NULL) {
10073
10074 json_object_int_add(
10075 json_timer,
10076 "selectionDeferralTimerRemaining",
10077 thread_timer_remain_second(
10078 peer->bgp
10079 ->gr_info[afi]
10080 [safi]
10081 .t_select_deferral));
10082 }
10083 } else {
10084 vty_out(vty, " Timers:\n");
10085 vty_out(vty,
10086 " Configured Stale Path Time(sec): %u\n",
10087 peer->bgp->stalepath_time);
10088
10089 if (peer->t_gr_stale != NULL)
10090 vty_out(vty,
10091 " Stale Path Remaining(sec): %ld\n",
10092 thread_timer_remain_second(
10093 peer->t_gr_stale));
10094 /* Display Configured Selection
10095 * Deferral only when when
10096 * Gr mode is enabled.
10097 */
10098 if (CHECK_FLAG(peer->flags,
10099 PEER_FLAG_GRACEFUL_RESTART))
10100 vty_out(vty,
10101 " Configured Selection Deferral Time(sec): %u\n",
10102 peer->bgp->select_defer_time);
10103
10104 if (peer->bgp->gr_info[afi][safi]
10105 .t_select_deferral
10106 != NULL)
10107 vty_out(vty,
10108 " Selection Deferral Time Remaining(sec): %ld\n",
10109 thread_timer_remain_second(
10110 peer->bgp
10111 ->gr_info[afi]
10112 [safi]
10113 .t_select_deferral));
10114 }
10115 if (use_json) {
10116 json_object_object_add(json_afi_safi,
10117 "endOfRibStatus",
10118 json_endofrib_status);
10119 json_object_object_add(json_afi_safi, "timers",
10120 json_timer);
10121 json_object_object_add(
10122 json, get_afi_safi_str(afi, safi, true),
10123 json_afi_safi);
10124 }
10125 }
10126 }
10127 }
10128
10129 static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
10130 struct peer *p,
10131 bool use_json,
10132 json_object *json)
10133 {
10134 if (use_json) {
10135 json_object *json_timer = NULL;
10136
10137 json_timer = json_object_new_object();
10138
10139 json_object_int_add(json_timer, "configuredRestartTimer",
10140 p->bgp->restart_time);
10141
10142 json_object_int_add(json_timer, "receivedRestartTimer",
10143 p->v_gr_restart);
10144
10145 if (p->t_gr_restart != NULL)
10146 json_object_int_add(
10147 json_timer, "restartTimerRemaining",
10148 thread_timer_remain_second(p->t_gr_restart));
10149
10150 json_object_object_add(json, "timers", json_timer);
10151 } else {
10152
10153 vty_out(vty, " Timers:\n");
10154 vty_out(vty, " Configured Restart Time(sec): %u\n",
10155 p->bgp->restart_time);
10156
10157 vty_out(vty, " Received Restart Time(sec): %u\n",
10158 p->v_gr_restart);
10159 if (p->t_gr_restart != NULL)
10160 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
10161 thread_timer_remain_second(p->t_gr_restart));
10162 if (p->t_gr_restart != NULL) {
10163 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
10164 thread_timer_remain_second(p->t_gr_restart));
10165 }
10166 }
10167 }
10168
10169 static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
10170 bool use_json, json_object *json)
10171 {
10172 char buf[SU_ADDRSTRLEN] = {0};
10173 char dn_flag[2] = {0};
10174 /* '*' + v6 address of neighbor */
10175 char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
10176
10177 if (!p->conf_if && peer_dynamic_neighbor(p))
10178 dn_flag[0] = '*';
10179
10180 if (p->conf_if) {
10181 if (use_json)
10182 json_object_string_add(
10183 json, "neighborAddr",
10184 BGP_PEER_SU_UNSPEC(p)
10185 ? "none"
10186 : sockunion2str(&p->su, buf,
10187 SU_ADDRSTRLEN));
10188 else
10189 vty_out(vty, "BGP neighbor on %s: %s\n", p->conf_if,
10190 BGP_PEER_SU_UNSPEC(p)
10191 ? "none"
10192 : sockunion2str(&p->su, buf,
10193 SU_ADDRSTRLEN));
10194 } else {
10195 snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
10196 p->host);
10197
10198 if (use_json)
10199 json_object_string_add(json, "neighborAddr",
10200 neighborAddr);
10201 else
10202 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
10203 }
10204
10205 /* more gr info in new format */
10206 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json);
10207 }
10208
10209 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
10210 safi_t safi, bool use_json,
10211 json_object *json_neigh)
10212 {
10213 struct bgp_filter *filter;
10214 struct peer_af *paf;
10215 char orf_pfx_name[BUFSIZ];
10216 int orf_pfx_count;
10217 json_object *json_af = NULL;
10218 json_object *json_prefA = NULL;
10219 json_object *json_prefB = NULL;
10220 json_object *json_addr = NULL;
10221
10222 if (use_json) {
10223 json_addr = json_object_new_object();
10224 json_af = json_object_new_object();
10225 filter = &p->filter[afi][safi];
10226
10227 if (peer_group_active(p))
10228 json_object_string_add(json_addr, "peerGroupMember",
10229 p->group->name);
10230
10231 paf = peer_af_find(p, afi, safi);
10232 if (paf && PAF_SUBGRP(paf)) {
10233 json_object_int_add(json_addr, "updateGroupId",
10234 PAF_UPDGRP(paf)->id);
10235 json_object_int_add(json_addr, "subGroupId",
10236 PAF_SUBGRP(paf)->id);
10237 json_object_int_add(json_addr, "packetQueueLength",
10238 bpacket_queue_virtual_length(paf));
10239 }
10240
10241 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
10242 || CHECK_FLAG(p->af_cap[afi][safi],
10243 PEER_CAP_ORF_PREFIX_SM_RCV)
10244 || CHECK_FLAG(p->af_cap[afi][safi],
10245 PEER_CAP_ORF_PREFIX_RM_ADV)
10246 || CHECK_FLAG(p->af_cap[afi][safi],
10247 PEER_CAP_ORF_PREFIX_RM_RCV)) {
10248 json_object_int_add(json_af, "orfType",
10249 ORF_TYPE_PREFIX);
10250 json_prefA = json_object_new_object();
10251 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
10252 PEER_CAP_ORF_PREFIX_SM_ADV,
10253 PEER_CAP_ORF_PREFIX_RM_ADV,
10254 PEER_CAP_ORF_PREFIX_SM_RCV,
10255 PEER_CAP_ORF_PREFIX_RM_RCV,
10256 use_json, json_prefA);
10257 json_object_object_add(json_af, "orfPrefixList",
10258 json_prefA);
10259 }
10260
10261 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
10262 || CHECK_FLAG(p->af_cap[afi][safi],
10263 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
10264 || CHECK_FLAG(p->af_cap[afi][safi],
10265 PEER_CAP_ORF_PREFIX_RM_ADV)
10266 || CHECK_FLAG(p->af_cap[afi][safi],
10267 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
10268 json_object_int_add(json_af, "orfOldType",
10269 ORF_TYPE_PREFIX_OLD);
10270 json_prefB = json_object_new_object();
10271 bgp_show_peer_afi_orf_cap(
10272 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
10273 PEER_CAP_ORF_PREFIX_RM_ADV,
10274 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
10275 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
10276 json_prefB);
10277 json_object_object_add(json_af, "orfOldPrefixList",
10278 json_prefB);
10279 }
10280
10281 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
10282 || CHECK_FLAG(p->af_cap[afi][safi],
10283 PEER_CAP_ORF_PREFIX_SM_RCV)
10284 || CHECK_FLAG(p->af_cap[afi][safi],
10285 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
10286 || CHECK_FLAG(p->af_cap[afi][safi],
10287 PEER_CAP_ORF_PREFIX_RM_ADV)
10288 || CHECK_FLAG(p->af_cap[afi][safi],
10289 PEER_CAP_ORF_PREFIX_RM_RCV)
10290 || CHECK_FLAG(p->af_cap[afi][safi],
10291 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
10292 json_object_object_add(json_addr, "afDependentCap",
10293 json_af);
10294 else
10295 json_object_free(json_af);
10296
10297 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
10298 p->host, afi, safi);
10299 orf_pfx_count = prefix_bgp_show_prefix_list(
10300 NULL, afi, orf_pfx_name, use_json);
10301
10302 if (CHECK_FLAG(p->af_sflags[afi][safi],
10303 PEER_STATUS_ORF_PREFIX_SEND)
10304 || orf_pfx_count) {
10305 if (CHECK_FLAG(p->af_sflags[afi][safi],
10306 PEER_STATUS_ORF_PREFIX_SEND))
10307 json_object_boolean_true_add(json_neigh,
10308 "orfSent");
10309 if (orf_pfx_count)
10310 json_object_int_add(json_addr, "orfRecvCounter",
10311 orf_pfx_count);
10312 }
10313 if (CHECK_FLAG(p->af_sflags[afi][safi],
10314 PEER_STATUS_ORF_WAIT_REFRESH))
10315 json_object_string_add(
10316 json_addr, "orfFirstUpdate",
10317 "deferredUntilORFOrRouteRefreshRecvd");
10318
10319 if (CHECK_FLAG(p->af_flags[afi][safi],
10320 PEER_FLAG_REFLECTOR_CLIENT))
10321 json_object_boolean_true_add(json_addr,
10322 "routeReflectorClient");
10323 if (CHECK_FLAG(p->af_flags[afi][safi],
10324 PEER_FLAG_RSERVER_CLIENT))
10325 json_object_boolean_true_add(json_addr,
10326 "routeServerClient");
10327 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
10328 json_object_boolean_true_add(json_addr,
10329 "inboundSoftConfigPermit");
10330
10331 if (CHECK_FLAG(p->af_flags[afi][safi],
10332 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
10333 json_object_boolean_true_add(
10334 json_addr,
10335 "privateAsNumsAllReplacedInUpdatesToNbr");
10336 else if (CHECK_FLAG(p->af_flags[afi][safi],
10337 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
10338 json_object_boolean_true_add(
10339 json_addr,
10340 "privateAsNumsReplacedInUpdatesToNbr");
10341 else if (CHECK_FLAG(p->af_flags[afi][safi],
10342 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
10343 json_object_boolean_true_add(
10344 json_addr,
10345 "privateAsNumsAllRemovedInUpdatesToNbr");
10346 else if (CHECK_FLAG(p->af_flags[afi][safi],
10347 PEER_FLAG_REMOVE_PRIVATE_AS))
10348 json_object_boolean_true_add(
10349 json_addr,
10350 "privateAsNumsRemovedInUpdatesToNbr");
10351
10352 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
10353 json_object_boolean_true_add(
10354 json_addr,
10355 bgp_addpath_names(p->addpath_type[afi][safi])
10356 ->type_json_name);
10357
10358 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
10359 json_object_string_add(json_addr,
10360 "overrideASNsInOutboundUpdates",
10361 "ifAspathEqualRemoteAs");
10362
10363 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
10364 || CHECK_FLAG(p->af_flags[afi][safi],
10365 PEER_FLAG_FORCE_NEXTHOP_SELF))
10366 json_object_boolean_true_add(json_addr,
10367 "routerAlwaysNextHop");
10368 if (CHECK_FLAG(p->af_flags[afi][safi],
10369 PEER_FLAG_AS_PATH_UNCHANGED))
10370 json_object_boolean_true_add(
10371 json_addr, "unchangedAsPathPropogatedToNbr");
10372 if (CHECK_FLAG(p->af_flags[afi][safi],
10373 PEER_FLAG_NEXTHOP_UNCHANGED))
10374 json_object_boolean_true_add(
10375 json_addr, "unchangedNextHopPropogatedToNbr");
10376 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
10377 json_object_boolean_true_add(
10378 json_addr, "unchangedMedPropogatedToNbr");
10379 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
10380 || CHECK_FLAG(p->af_flags[afi][safi],
10381 PEER_FLAG_SEND_EXT_COMMUNITY)) {
10382 if (CHECK_FLAG(p->af_flags[afi][safi],
10383 PEER_FLAG_SEND_COMMUNITY)
10384 && CHECK_FLAG(p->af_flags[afi][safi],
10385 PEER_FLAG_SEND_EXT_COMMUNITY))
10386 json_object_string_add(json_addr,
10387 "commAttriSentToNbr",
10388 "extendedAndStandard");
10389 else if (CHECK_FLAG(p->af_flags[afi][safi],
10390 PEER_FLAG_SEND_EXT_COMMUNITY))
10391 json_object_string_add(json_addr,
10392 "commAttriSentToNbr",
10393 "extended");
10394 else
10395 json_object_string_add(json_addr,
10396 "commAttriSentToNbr",
10397 "standard");
10398 }
10399 if (CHECK_FLAG(p->af_flags[afi][safi],
10400 PEER_FLAG_DEFAULT_ORIGINATE)) {
10401 if (p->default_rmap[afi][safi].name)
10402 json_object_string_add(
10403 json_addr, "defaultRouteMap",
10404 p->default_rmap[afi][safi].name);
10405
10406 if (paf && PAF_SUBGRP(paf)
10407 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
10408 SUBGRP_STATUS_DEFAULT_ORIGINATE))
10409 json_object_boolean_true_add(json_addr,
10410 "defaultSent");
10411 else
10412 json_object_boolean_true_add(json_addr,
10413 "defaultNotSent");
10414 }
10415
10416 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
10417 if (is_evpn_enabled())
10418 json_object_boolean_true_add(
10419 json_addr, "advertiseAllVnis");
10420 }
10421
10422 if (filter->plist[FILTER_IN].name
10423 || filter->dlist[FILTER_IN].name
10424 || filter->aslist[FILTER_IN].name
10425 || filter->map[RMAP_IN].name)
10426 json_object_boolean_true_add(json_addr,
10427 "inboundPathPolicyConfig");
10428 if (filter->plist[FILTER_OUT].name
10429 || filter->dlist[FILTER_OUT].name
10430 || filter->aslist[FILTER_OUT].name
10431 || filter->map[RMAP_OUT].name || filter->usmap.name)
10432 json_object_boolean_true_add(
10433 json_addr, "outboundPathPolicyConfig");
10434
10435 /* prefix-list */
10436 if (filter->plist[FILTER_IN].name)
10437 json_object_string_add(json_addr,
10438 "incomingUpdatePrefixFilterList",
10439 filter->plist[FILTER_IN].name);
10440 if (filter->plist[FILTER_OUT].name)
10441 json_object_string_add(json_addr,
10442 "outgoingUpdatePrefixFilterList",
10443 filter->plist[FILTER_OUT].name);
10444
10445 /* distribute-list */
10446 if (filter->dlist[FILTER_IN].name)
10447 json_object_string_add(
10448 json_addr, "incomingUpdateNetworkFilterList",
10449 filter->dlist[FILTER_IN].name);
10450 if (filter->dlist[FILTER_OUT].name)
10451 json_object_string_add(
10452 json_addr, "outgoingUpdateNetworkFilterList",
10453 filter->dlist[FILTER_OUT].name);
10454
10455 /* filter-list. */
10456 if (filter->aslist[FILTER_IN].name)
10457 json_object_string_add(json_addr,
10458 "incomingUpdateAsPathFilterList",
10459 filter->aslist[FILTER_IN].name);
10460 if (filter->aslist[FILTER_OUT].name)
10461 json_object_string_add(json_addr,
10462 "outgoingUpdateAsPathFilterList",
10463 filter->aslist[FILTER_OUT].name);
10464
10465 /* route-map. */
10466 if (filter->map[RMAP_IN].name)
10467 json_object_string_add(
10468 json_addr, "routeMapForIncomingAdvertisements",
10469 filter->map[RMAP_IN].name);
10470 if (filter->map[RMAP_OUT].name)
10471 json_object_string_add(
10472 json_addr, "routeMapForOutgoingAdvertisements",
10473 filter->map[RMAP_OUT].name);
10474
10475 /* ebgp-requires-policy (inbound) */
10476 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
10477 && !bgp_inbound_policy_exists(p, filter))
10478 json_object_string_add(
10479 json_addr, "inboundEbgpRequiresPolicy",
10480 "Inbound updates discarded due to missing policy");
10481
10482 /* ebgp-requires-policy (outbound) */
10483 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
10484 && (!bgp_outbound_policy_exists(p, filter)))
10485 json_object_string_add(
10486 json_addr, "outboundEbgpRequiresPolicy",
10487 "Outbound updates discarded due to missing policy");
10488
10489 /* unsuppress-map */
10490 if (filter->usmap.name)
10491 json_object_string_add(json_addr,
10492 "selectiveUnsuppressRouteMap",
10493 filter->usmap.name);
10494
10495 /* Receive prefix count */
10496 json_object_int_add(json_addr, "acceptedPrefixCounter",
10497 p->pcount[afi][safi]);
10498 if (paf && PAF_SUBGRP(paf))
10499 json_object_int_add(json_addr, "sentPrefixCounter",
10500 (PAF_SUBGRP(paf))->scount);
10501
10502 /* Maximum prefix */
10503 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
10504 json_object_int_add(json_addr, "prefixOutAllowedMax",
10505 p->pmax_out[afi][safi]);
10506
10507 /* Maximum prefix */
10508 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
10509 json_object_int_add(json_addr, "prefixAllowedMax",
10510 p->pmax[afi][safi]);
10511 if (CHECK_FLAG(p->af_flags[afi][safi],
10512 PEER_FLAG_MAX_PREFIX_WARNING))
10513 json_object_boolean_true_add(
10514 json_addr, "prefixAllowedMaxWarning");
10515 json_object_int_add(json_addr,
10516 "prefixAllowedWarningThresh",
10517 p->pmax_threshold[afi][safi]);
10518 if (p->pmax_restart[afi][safi])
10519 json_object_int_add(
10520 json_addr,
10521 "prefixAllowedRestartIntervalMsecs",
10522 p->pmax_restart[afi][safi] * 60000);
10523 }
10524 json_object_object_add(json_neigh,
10525 get_afi_safi_str(afi, safi, true),
10526 json_addr);
10527
10528 } else {
10529 filter = &p->filter[afi][safi];
10530
10531 vty_out(vty, " For address family: %s\n",
10532 get_afi_safi_str(afi, safi, false));
10533
10534 if (peer_group_active(p))
10535 vty_out(vty, " %s peer-group member\n",
10536 p->group->name);
10537
10538 paf = peer_af_find(p, afi, safi);
10539 if (paf && PAF_SUBGRP(paf)) {
10540 vty_out(vty, " Update group %" PRIu64", subgroup %" PRIu64 "\n",
10541 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
10542 vty_out(vty, " Packet Queue length %d\n",
10543 bpacket_queue_virtual_length(paf));
10544 } else {
10545 vty_out(vty, " Not part of any update group\n");
10546 }
10547 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
10548 || CHECK_FLAG(p->af_cap[afi][safi],
10549 PEER_CAP_ORF_PREFIX_SM_RCV)
10550 || CHECK_FLAG(p->af_cap[afi][safi],
10551 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
10552 || CHECK_FLAG(p->af_cap[afi][safi],
10553 PEER_CAP_ORF_PREFIX_RM_ADV)
10554 || CHECK_FLAG(p->af_cap[afi][safi],
10555 PEER_CAP_ORF_PREFIX_RM_RCV)
10556 || CHECK_FLAG(p->af_cap[afi][safi],
10557 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
10558 vty_out(vty, " AF-dependant capabilities:\n");
10559
10560 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
10561 || CHECK_FLAG(p->af_cap[afi][safi],
10562 PEER_CAP_ORF_PREFIX_SM_RCV)
10563 || CHECK_FLAG(p->af_cap[afi][safi],
10564 PEER_CAP_ORF_PREFIX_RM_ADV)
10565 || CHECK_FLAG(p->af_cap[afi][safi],
10566 PEER_CAP_ORF_PREFIX_RM_RCV)) {
10567 vty_out(vty,
10568 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
10569 ORF_TYPE_PREFIX);
10570 bgp_show_peer_afi_orf_cap(
10571 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
10572 PEER_CAP_ORF_PREFIX_RM_ADV,
10573 PEER_CAP_ORF_PREFIX_SM_RCV,
10574 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
10575 }
10576 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
10577 || CHECK_FLAG(p->af_cap[afi][safi],
10578 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
10579 || CHECK_FLAG(p->af_cap[afi][safi],
10580 PEER_CAP_ORF_PREFIX_RM_ADV)
10581 || CHECK_FLAG(p->af_cap[afi][safi],
10582 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
10583 vty_out(vty,
10584 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
10585 ORF_TYPE_PREFIX_OLD);
10586 bgp_show_peer_afi_orf_cap(
10587 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
10588 PEER_CAP_ORF_PREFIX_RM_ADV,
10589 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
10590 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
10591 }
10592
10593 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
10594 p->host, afi, safi);
10595 orf_pfx_count = prefix_bgp_show_prefix_list(
10596 NULL, afi, orf_pfx_name, use_json);
10597
10598 if (CHECK_FLAG(p->af_sflags[afi][safi],
10599 PEER_STATUS_ORF_PREFIX_SEND)
10600 || orf_pfx_count) {
10601 vty_out(vty, " Outbound Route Filter (ORF):");
10602 if (CHECK_FLAG(p->af_sflags[afi][safi],
10603 PEER_STATUS_ORF_PREFIX_SEND))
10604 vty_out(vty, " sent;");
10605 if (orf_pfx_count)
10606 vty_out(vty, " received (%d entries)",
10607 orf_pfx_count);
10608 vty_out(vty, "\n");
10609 }
10610 if (CHECK_FLAG(p->af_sflags[afi][safi],
10611 PEER_STATUS_ORF_WAIT_REFRESH))
10612 vty_out(vty,
10613 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
10614
10615 if (CHECK_FLAG(p->af_flags[afi][safi],
10616 PEER_FLAG_REFLECTOR_CLIENT))
10617 vty_out(vty, " Route-Reflector Client\n");
10618 if (CHECK_FLAG(p->af_flags[afi][safi],
10619 PEER_FLAG_RSERVER_CLIENT))
10620 vty_out(vty, " Route-Server Client\n");
10621 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
10622 vty_out(vty,
10623 " Inbound soft reconfiguration allowed\n");
10624
10625 if (CHECK_FLAG(p->af_flags[afi][safi],
10626 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
10627 vty_out(vty,
10628 " Private AS numbers (all) replaced in updates to this neighbor\n");
10629 else if (CHECK_FLAG(p->af_flags[afi][safi],
10630 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
10631 vty_out(vty,
10632 " Private AS numbers replaced in updates to this neighbor\n");
10633 else if (CHECK_FLAG(p->af_flags[afi][safi],
10634 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
10635 vty_out(vty,
10636 " Private AS numbers (all) removed in updates to this neighbor\n");
10637 else if (CHECK_FLAG(p->af_flags[afi][safi],
10638 PEER_FLAG_REMOVE_PRIVATE_AS))
10639 vty_out(vty,
10640 " Private AS numbers removed in updates to this neighbor\n");
10641
10642 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
10643 vty_out(vty, " %s\n",
10644 bgp_addpath_names(p->addpath_type[afi][safi])
10645 ->human_description);
10646
10647 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
10648 vty_out(vty,
10649 " Override ASNs in outbound updates if aspath equals remote-as\n");
10650
10651 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
10652 || CHECK_FLAG(p->af_flags[afi][safi],
10653 PEER_FLAG_FORCE_NEXTHOP_SELF))
10654 vty_out(vty, " NEXT_HOP is always this router\n");
10655 if (CHECK_FLAG(p->af_flags[afi][safi],
10656 PEER_FLAG_AS_PATH_UNCHANGED))
10657 vty_out(vty,
10658 " AS_PATH is propagated unchanged to this neighbor\n");
10659 if (CHECK_FLAG(p->af_flags[afi][safi],
10660 PEER_FLAG_NEXTHOP_UNCHANGED))
10661 vty_out(vty,
10662 " NEXT_HOP is propagated unchanged to this neighbor\n");
10663 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
10664 vty_out(vty,
10665 " MED is propagated unchanged to this neighbor\n");
10666 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
10667 || CHECK_FLAG(p->af_flags[afi][safi],
10668 PEER_FLAG_SEND_EXT_COMMUNITY)
10669 || CHECK_FLAG(p->af_flags[afi][safi],
10670 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
10671 vty_out(vty,
10672 " Community attribute sent to this neighbor");
10673 if (CHECK_FLAG(p->af_flags[afi][safi],
10674 PEER_FLAG_SEND_COMMUNITY)
10675 && CHECK_FLAG(p->af_flags[afi][safi],
10676 PEER_FLAG_SEND_EXT_COMMUNITY)
10677 && CHECK_FLAG(p->af_flags[afi][safi],
10678 PEER_FLAG_SEND_LARGE_COMMUNITY))
10679 vty_out(vty, "(all)\n");
10680 else if (CHECK_FLAG(p->af_flags[afi][safi],
10681 PEER_FLAG_SEND_LARGE_COMMUNITY))
10682 vty_out(vty, "(large)\n");
10683 else if (CHECK_FLAG(p->af_flags[afi][safi],
10684 PEER_FLAG_SEND_EXT_COMMUNITY))
10685 vty_out(vty, "(extended)\n");
10686 else
10687 vty_out(vty, "(standard)\n");
10688 }
10689 if (CHECK_FLAG(p->af_flags[afi][safi],
10690 PEER_FLAG_DEFAULT_ORIGINATE)) {
10691 vty_out(vty, " Default information originate,");
10692
10693 if (p->default_rmap[afi][safi].name)
10694 vty_out(vty, " default route-map %s%s,",
10695 p->default_rmap[afi][safi].map ? "*"
10696 : "",
10697 p->default_rmap[afi][safi].name);
10698 if (paf && PAF_SUBGRP(paf)
10699 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
10700 SUBGRP_STATUS_DEFAULT_ORIGINATE))
10701 vty_out(vty, " default sent\n");
10702 else
10703 vty_out(vty, " default not sent\n");
10704 }
10705
10706 /* advertise-vni-all */
10707 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
10708 if (is_evpn_enabled())
10709 vty_out(vty, " advertise-all-vni\n");
10710 }
10711
10712 if (filter->plist[FILTER_IN].name
10713 || filter->dlist[FILTER_IN].name
10714 || filter->aslist[FILTER_IN].name
10715 || filter->map[RMAP_IN].name)
10716 vty_out(vty, " Inbound path policy configured\n");
10717 if (filter->plist[FILTER_OUT].name
10718 || filter->dlist[FILTER_OUT].name
10719 || filter->aslist[FILTER_OUT].name
10720 || filter->map[RMAP_OUT].name || filter->usmap.name)
10721 vty_out(vty, " Outbound path policy configured\n");
10722
10723 /* prefix-list */
10724 if (filter->plist[FILTER_IN].name)
10725 vty_out(vty,
10726 " Incoming update prefix filter list is %s%s\n",
10727 filter->plist[FILTER_IN].plist ? "*" : "",
10728 filter->plist[FILTER_IN].name);
10729 if (filter->plist[FILTER_OUT].name)
10730 vty_out(vty,
10731 " Outgoing update prefix filter list is %s%s\n",
10732 filter->plist[FILTER_OUT].plist ? "*" : "",
10733 filter->plist[FILTER_OUT].name);
10734
10735 /* distribute-list */
10736 if (filter->dlist[FILTER_IN].name)
10737 vty_out(vty,
10738 " Incoming update network filter list is %s%s\n",
10739 filter->dlist[FILTER_IN].alist ? "*" : "",
10740 filter->dlist[FILTER_IN].name);
10741 if (filter->dlist[FILTER_OUT].name)
10742 vty_out(vty,
10743 " Outgoing update network filter list is %s%s\n",
10744 filter->dlist[FILTER_OUT].alist ? "*" : "",
10745 filter->dlist[FILTER_OUT].name);
10746
10747 /* filter-list. */
10748 if (filter->aslist[FILTER_IN].name)
10749 vty_out(vty,
10750 " Incoming update AS path filter list is %s%s\n",
10751 filter->aslist[FILTER_IN].aslist ? "*" : "",
10752 filter->aslist[FILTER_IN].name);
10753 if (filter->aslist[FILTER_OUT].name)
10754 vty_out(vty,
10755 " Outgoing update AS path filter list is %s%s\n",
10756 filter->aslist[FILTER_OUT].aslist ? "*" : "",
10757 filter->aslist[FILTER_OUT].name);
10758
10759 /* route-map. */
10760 if (filter->map[RMAP_IN].name)
10761 vty_out(vty,
10762 " Route map for incoming advertisements is %s%s\n",
10763 filter->map[RMAP_IN].map ? "*" : "",
10764 filter->map[RMAP_IN].name);
10765 if (filter->map[RMAP_OUT].name)
10766 vty_out(vty,
10767 " Route map for outgoing advertisements is %s%s\n",
10768 filter->map[RMAP_OUT].map ? "*" : "",
10769 filter->map[RMAP_OUT].name);
10770
10771 /* ebgp-requires-policy (inbound) */
10772 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
10773 && !bgp_inbound_policy_exists(p, filter))
10774 vty_out(vty,
10775 " Inbound updates discarded due to missing policy\n");
10776
10777 /* ebgp-requires-policy (outbound) */
10778 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
10779 && !bgp_outbound_policy_exists(p, filter))
10780 vty_out(vty,
10781 " Outbound updates discarded due to missing policy\n");
10782
10783 /* unsuppress-map */
10784 if (filter->usmap.name)
10785 vty_out(vty,
10786 " Route map for selective unsuppress is %s%s\n",
10787 filter->usmap.map ? "*" : "",
10788 filter->usmap.name);
10789
10790 /* Receive prefix count */
10791 vty_out(vty, " %u accepted prefixes\n",
10792 p->pcount[afi][safi]);
10793
10794 /* maximum-prefix-out */
10795 if (CHECK_FLAG(p->af_flags[afi][safi],
10796 PEER_FLAG_MAX_PREFIX_OUT))
10797 vty_out(vty,
10798 " Maximum allowed prefixes sent %u\n",
10799 p->pmax_out[afi][safi]);
10800
10801 /* Maximum prefix */
10802 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
10803 vty_out(vty,
10804 " Maximum prefixes allowed %u%s\n",
10805 p->pmax[afi][safi],
10806 CHECK_FLAG(p->af_flags[afi][safi],
10807 PEER_FLAG_MAX_PREFIX_WARNING)
10808 ? " (warning-only)"
10809 : "");
10810 vty_out(vty, " Threshold for warning message %d%%",
10811 p->pmax_threshold[afi][safi]);
10812 if (p->pmax_restart[afi][safi])
10813 vty_out(vty, ", restart interval %d min",
10814 p->pmax_restart[afi][safi]);
10815 vty_out(vty, "\n");
10816 }
10817
10818 vty_out(vty, "\n");
10819 }
10820 }
10821
10822 static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
10823 json_object *json)
10824 {
10825 struct bgp *bgp;
10826 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
10827 char timebuf[BGP_UPTIME_LEN];
10828 char dn_flag[2];
10829 afi_t afi;
10830 safi_t safi;
10831 uint16_t i;
10832 uint8_t *msg;
10833 json_object *json_neigh = NULL;
10834 time_t epoch_tbuf;
10835
10836 bgp = p->bgp;
10837
10838 if (use_json)
10839 json_neigh = json_object_new_object();
10840
10841 memset(dn_flag, '\0', sizeof(dn_flag));
10842 if (!p->conf_if && peer_dynamic_neighbor(p))
10843 dn_flag[0] = '*';
10844
10845 if (!use_json) {
10846 if (p->conf_if) /* Configured interface name. */
10847 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
10848 BGP_PEER_SU_UNSPEC(p)
10849 ? "None"
10850 : sockunion2str(&p->su, buf,
10851 SU_ADDRSTRLEN));
10852 else /* Configured IP address. */
10853 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
10854 p->host);
10855 }
10856
10857 if (use_json) {
10858 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
10859 json_object_string_add(json_neigh, "bgpNeighborAddr",
10860 "none");
10861 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
10862 json_object_string_add(
10863 json_neigh, "bgpNeighborAddr",
10864 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
10865
10866 json_object_int_add(json_neigh, "remoteAs", p->as);
10867
10868 if (p->change_local_as)
10869 json_object_int_add(json_neigh, "localAs",
10870 p->change_local_as);
10871 else
10872 json_object_int_add(json_neigh, "localAs", p->local_as);
10873
10874 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
10875 json_object_boolean_true_add(json_neigh,
10876 "localAsNoPrepend");
10877
10878 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
10879 json_object_boolean_true_add(json_neigh,
10880 "localAsReplaceAs");
10881 } else {
10882 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
10883 || (p->as_type == AS_INTERNAL))
10884 vty_out(vty, "remote AS %u, ", p->as);
10885 else
10886 vty_out(vty, "remote AS Unspecified, ");
10887 vty_out(vty, "local AS %u%s%s, ",
10888 p->change_local_as ? p->change_local_as : p->local_as,
10889 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
10890 ? " no-prepend"
10891 : "",
10892 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
10893 ? " replace-as"
10894 : "");
10895 }
10896 /* peer type internal or confed-internal */
10897 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
10898 if (use_json) {
10899 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
10900 json_object_boolean_true_add(
10901 json_neigh, "nbrConfedInternalLink");
10902 else
10903 json_object_boolean_true_add(json_neigh,
10904 "nbrInternalLink");
10905 } else {
10906 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
10907 vty_out(vty, "confed-internal link\n");
10908 else
10909 vty_out(vty, "internal link\n");
10910 }
10911 /* peer type external or confed-external */
10912 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
10913 if (use_json) {
10914 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
10915 json_object_boolean_true_add(
10916 json_neigh, "nbrConfedExternalLink");
10917 else
10918 json_object_boolean_true_add(json_neigh,
10919 "nbrExternalLink");
10920 } else {
10921 if (bgp_confederation_peers_check(bgp, p->as))
10922 vty_out(vty, "confed-external link\n");
10923 else
10924 vty_out(vty, "external link\n");
10925 }
10926 } else {
10927 if (use_json)
10928 json_object_boolean_true_add(json_neigh,
10929 "nbrUnspecifiedLink");
10930 else
10931 vty_out(vty, "unspecified link\n");
10932 }
10933
10934 /* Description. */
10935 if (p->desc) {
10936 if (use_json)
10937 json_object_string_add(json_neigh, "nbrDesc", p->desc);
10938 else
10939 vty_out(vty, " Description: %s\n", p->desc);
10940 }
10941
10942 if (p->hostname) {
10943 if (use_json) {
10944 if (p->hostname)
10945 json_object_string_add(json_neigh, "hostname",
10946 p->hostname);
10947
10948 if (p->domainname)
10949 json_object_string_add(json_neigh, "domainname",
10950 p->domainname);
10951 } else {
10952 if (p->domainname && (p->domainname[0] != '\0'))
10953 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
10954 p->domainname);
10955 else
10956 vty_out(vty, "Hostname: %s\n", p->hostname);
10957 }
10958 }
10959
10960 /* Peer-group */
10961 if (p->group) {
10962 if (use_json) {
10963 json_object_string_add(json_neigh, "peerGroup",
10964 p->group->name);
10965
10966 if (dn_flag[0]) {
10967 struct prefix prefix, *range = NULL;
10968
10969 sockunion2hostprefix(&(p->su), &prefix);
10970 range = peer_group_lookup_dynamic_neighbor_range(
10971 p->group, &prefix);
10972
10973 if (range) {
10974 prefix2str(range, buf1, sizeof(buf1));
10975 json_object_string_add(
10976 json_neigh,
10977 "peerSubnetRangeGroup", buf1);
10978 }
10979 }
10980 } else {
10981 vty_out(vty,
10982 " Member of peer-group %s for session parameters\n",
10983 p->group->name);
10984
10985 if (dn_flag[0]) {
10986 struct prefix prefix, *range = NULL;
10987
10988 sockunion2hostprefix(&(p->su), &prefix);
10989 range = peer_group_lookup_dynamic_neighbor_range(
10990 p->group, &prefix);
10991
10992 if (range) {
10993 vty_out(vty,
10994 " Belongs to the subnet range group: %pFX\n",
10995 range);
10996 }
10997 }
10998 }
10999 }
11000
11001 if (use_json) {
11002 /* Administrative shutdown. */
11003 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
11004 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
11005 json_object_boolean_true_add(json_neigh,
11006 "adminShutDown");
11007
11008 /* BGP Version. */
11009 json_object_int_add(json_neigh, "bgpVersion", 4);
11010 json_object_string_add(
11011 json_neigh, "remoteRouterId",
11012 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
11013 json_object_string_add(
11014 json_neigh, "localRouterId",
11015 inet_ntop(AF_INET, &bgp->router_id, buf1,
11016 sizeof(buf1)));
11017
11018 /* Confederation */
11019 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
11020 && bgp_confederation_peers_check(bgp, p->as))
11021 json_object_boolean_true_add(json_neigh,
11022 "nbrCommonAdmin");
11023
11024 /* Status. */
11025 json_object_string_add(
11026 json_neigh, "bgpState",
11027 lookup_msg(bgp_status_msg, p->status, NULL));
11028
11029 if (p->status == Established) {
11030 time_t uptime;
11031
11032 uptime = bgp_clock();
11033 uptime -= p->uptime;
11034 epoch_tbuf = time(NULL) - uptime;
11035
11036 json_object_int_add(json_neigh, "bgpTimerUpMsec",
11037 uptime * 1000);
11038 json_object_string_add(json_neigh, "bgpTimerUpString",
11039 peer_uptime(p->uptime, timebuf,
11040 BGP_UPTIME_LEN, 0,
11041 NULL));
11042 json_object_int_add(json_neigh,
11043 "bgpTimerUpEstablishedEpoch",
11044 epoch_tbuf);
11045 }
11046
11047 else if (p->status == Active) {
11048 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
11049 json_object_string_add(json_neigh, "bgpStateIs",
11050 "passive");
11051 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
11052 json_object_string_add(json_neigh, "bgpStateIs",
11053 "passiveNSF");
11054 }
11055
11056 /* read timer */
11057 time_t uptime;
11058 struct tm tm;
11059
11060 uptime = bgp_clock();
11061 uptime -= p->readtime;
11062 gmtime_r(&uptime, &tm);
11063
11064 json_object_int_add(json_neigh, "bgpTimerLastRead",
11065 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
11066 + (tm.tm_hour * 3600000));
11067
11068 uptime = bgp_clock();
11069 uptime -= p->last_write;
11070 gmtime_r(&uptime, &tm);
11071
11072 json_object_int_add(json_neigh, "bgpTimerLastWrite",
11073 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
11074 + (tm.tm_hour * 3600000));
11075
11076 uptime = bgp_clock();
11077 uptime -= p->update_time;
11078 gmtime_r(&uptime, &tm);
11079
11080 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
11081 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
11082 + (tm.tm_hour * 3600000));
11083
11084 /* Configured timer values. */
11085 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
11086 p->v_holdtime * 1000);
11087 json_object_int_add(json_neigh,
11088 "bgpTimerKeepAliveIntervalMsecs",
11089 p->v_keepalive * 1000);
11090 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
11091 json_object_int_add(json_neigh,
11092 "bgpTimerConfiguredHoldTimeMsecs",
11093 p->holdtime * 1000);
11094 json_object_int_add(
11095 json_neigh,
11096 "bgpTimerConfiguredKeepAliveIntervalMsecs",
11097 p->keepalive * 1000);
11098 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
11099 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
11100 json_object_int_add(json_neigh,
11101 "bgpTimerConfiguredHoldTimeMsecs",
11102 bgp->default_holdtime);
11103 json_object_int_add(
11104 json_neigh,
11105 "bgpTimerConfiguredKeepAliveIntervalMsecs",
11106 bgp->default_keepalive);
11107 }
11108 } else {
11109 /* Administrative shutdown. */
11110 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
11111 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
11112 vty_out(vty, " Administratively shut down\n");
11113
11114 /* BGP Version. */
11115 vty_out(vty, " BGP version 4");
11116 vty_out(vty, ", remote router ID %s",
11117 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
11118 vty_out(vty, ", local router ID %s\n",
11119 inet_ntop(AF_INET, &bgp->router_id, buf1,
11120 sizeof(buf1)));
11121
11122 /* Confederation */
11123 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
11124 && bgp_confederation_peers_check(bgp, p->as))
11125 vty_out(vty,
11126 " Neighbor under common administration\n");
11127
11128 /* Status. */
11129 vty_out(vty, " BGP state = %s",
11130 lookup_msg(bgp_status_msg, p->status, NULL));
11131
11132 if (p->status == Established)
11133 vty_out(vty, ", up for %8s",
11134 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
11135 0, NULL));
11136
11137 else if (p->status == Active) {
11138 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
11139 vty_out(vty, " (passive)");
11140 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
11141 vty_out(vty, " (NSF passive)");
11142 }
11143 vty_out(vty, "\n");
11144
11145 /* read timer */
11146 vty_out(vty, " Last read %s",
11147 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
11148 NULL));
11149 vty_out(vty, ", Last write %s\n",
11150 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
11151 NULL));
11152
11153 /* Configured timer values. */
11154 vty_out(vty,
11155 " Hold time is %d, keepalive interval is %d seconds\n",
11156 p->v_holdtime, p->v_keepalive);
11157 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
11158 vty_out(vty, " Configured hold time is %d",
11159 p->holdtime);
11160 vty_out(vty, ", keepalive interval is %d seconds\n",
11161 p->keepalive);
11162 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
11163 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
11164 vty_out(vty, " Configured hold time is %d",
11165 bgp->default_holdtime);
11166 vty_out(vty, ", keepalive interval is %d seconds\n",
11167 bgp->default_keepalive);
11168 }
11169 }
11170 /* Capability. */
11171 if (p->status == Established) {
11172 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
11173 || p->afc_recv[AFI_IP][SAFI_UNICAST]
11174 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
11175 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
11176 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
11177 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
11178 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
11179 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
11180 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
11181 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
11182 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
11183 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
11184 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
11185 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
11186 || p->afc_adv[AFI_IP][SAFI_ENCAP]
11187 || p->afc_recv[AFI_IP][SAFI_ENCAP]
11188 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
11189 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
11190 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
11191 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
11192 if (use_json) {
11193 json_object *json_cap = NULL;
11194
11195 json_cap = json_object_new_object();
11196
11197 /* AS4 */
11198 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
11199 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
11200 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
11201 && CHECK_FLAG(p->cap,
11202 PEER_CAP_AS4_RCV))
11203 json_object_string_add(
11204 json_cap, "4byteAs",
11205 "advertisedAndReceived");
11206 else if (CHECK_FLAG(p->cap,
11207 PEER_CAP_AS4_ADV))
11208 json_object_string_add(
11209 json_cap, "4byteAs",
11210 "advertised");
11211 else if (CHECK_FLAG(p->cap,
11212 PEER_CAP_AS4_RCV))
11213 json_object_string_add(
11214 json_cap, "4byteAs",
11215 "received");
11216 }
11217
11218 /* AddPath */
11219 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
11220 || CHECK_FLAG(p->cap,
11221 PEER_CAP_ADDPATH_ADV)) {
11222 json_object *json_add = NULL;
11223 const char *print_store;
11224
11225 json_add = json_object_new_object();
11226
11227 FOREACH_AFI_SAFI (afi, safi) {
11228 json_object *json_sub = NULL;
11229 json_sub =
11230 json_object_new_object();
11231 print_store = get_afi_safi_str(
11232 afi, safi, true);
11233
11234 if (CHECK_FLAG(
11235 p->af_cap[afi]
11236 [safi],
11237 PEER_CAP_ADDPATH_AF_TX_ADV)
11238 || CHECK_FLAG(
11239 p->af_cap[afi]
11240 [safi],
11241 PEER_CAP_ADDPATH_AF_TX_RCV)) {
11242 if (CHECK_FLAG(
11243 p->af_cap
11244 [afi]
11245 [safi],
11246 PEER_CAP_ADDPATH_AF_TX_ADV)
11247 && CHECK_FLAG(
11248 p->af_cap
11249 [afi]
11250 [safi],
11251 PEER_CAP_ADDPATH_AF_TX_RCV))
11252 json_object_boolean_true_add(
11253 json_sub,
11254 "txAdvertisedAndReceived");
11255 else if (
11256 CHECK_FLAG(
11257 p->af_cap
11258 [afi]
11259 [safi],
11260 PEER_CAP_ADDPATH_AF_TX_ADV))
11261 json_object_boolean_true_add(
11262 json_sub,
11263 "txAdvertised");
11264 else if (
11265 CHECK_FLAG(
11266 p->af_cap
11267 [afi]
11268 [safi],
11269 PEER_CAP_ADDPATH_AF_TX_RCV))
11270 json_object_boolean_true_add(
11271 json_sub,
11272 "txReceived");
11273 }
11274
11275 if (CHECK_FLAG(
11276 p->af_cap[afi]
11277 [safi],
11278 PEER_CAP_ADDPATH_AF_RX_ADV)
11279 || CHECK_FLAG(
11280 p->af_cap[afi]
11281 [safi],
11282 PEER_CAP_ADDPATH_AF_RX_RCV)) {
11283 if (CHECK_FLAG(
11284 p->af_cap
11285 [afi]
11286 [safi],
11287 PEER_CAP_ADDPATH_AF_RX_ADV)
11288 && CHECK_FLAG(
11289 p->af_cap
11290 [afi]
11291 [safi],
11292 PEER_CAP_ADDPATH_AF_RX_RCV))
11293 json_object_boolean_true_add(
11294 json_sub,
11295 "rxAdvertisedAndReceived");
11296 else if (
11297 CHECK_FLAG(
11298 p->af_cap
11299 [afi]
11300 [safi],
11301 PEER_CAP_ADDPATH_AF_RX_ADV))
11302 json_object_boolean_true_add(
11303 json_sub,
11304 "rxAdvertised");
11305 else if (
11306 CHECK_FLAG(
11307 p->af_cap
11308 [afi]
11309 [safi],
11310 PEER_CAP_ADDPATH_AF_RX_RCV))
11311 json_object_boolean_true_add(
11312 json_sub,
11313 "rxReceived");
11314 }
11315
11316 if (CHECK_FLAG(
11317 p->af_cap[afi]
11318 [safi],
11319 PEER_CAP_ADDPATH_AF_TX_ADV)
11320 || CHECK_FLAG(
11321 p->af_cap[afi]
11322 [safi],
11323 PEER_CAP_ADDPATH_AF_TX_RCV)
11324 || CHECK_FLAG(
11325 p->af_cap[afi]
11326 [safi],
11327 PEER_CAP_ADDPATH_AF_RX_ADV)
11328 || CHECK_FLAG(
11329 p->af_cap[afi]
11330 [safi],
11331 PEER_CAP_ADDPATH_AF_RX_RCV))
11332 json_object_object_add(
11333 json_add,
11334 print_store,
11335 json_sub);
11336 else
11337 json_object_free(
11338 json_sub);
11339 }
11340
11341 json_object_object_add(
11342 json_cap, "addPath", json_add);
11343 }
11344
11345 /* Dynamic */
11346 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
11347 || CHECK_FLAG(p->cap,
11348 PEER_CAP_DYNAMIC_ADV)) {
11349 if (CHECK_FLAG(p->cap,
11350 PEER_CAP_DYNAMIC_ADV)
11351 && CHECK_FLAG(p->cap,
11352 PEER_CAP_DYNAMIC_RCV))
11353 json_object_string_add(
11354 json_cap, "dynamic",
11355 "advertisedAndReceived");
11356 else if (CHECK_FLAG(
11357 p->cap,
11358 PEER_CAP_DYNAMIC_ADV))
11359 json_object_string_add(
11360 json_cap, "dynamic",
11361 "advertised");
11362 else if (CHECK_FLAG(
11363 p->cap,
11364 PEER_CAP_DYNAMIC_RCV))
11365 json_object_string_add(
11366 json_cap, "dynamic",
11367 "received");
11368 }
11369
11370 /* Extended nexthop */
11371 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
11372 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
11373 json_object *json_nxt = NULL;
11374 const char *print_store;
11375
11376
11377 if (CHECK_FLAG(p->cap,
11378 PEER_CAP_ENHE_ADV)
11379 && CHECK_FLAG(p->cap,
11380 PEER_CAP_ENHE_RCV))
11381 json_object_string_add(
11382 json_cap,
11383 "extendedNexthop",
11384 "advertisedAndReceived");
11385 else if (CHECK_FLAG(p->cap,
11386 PEER_CAP_ENHE_ADV))
11387 json_object_string_add(
11388 json_cap,
11389 "extendedNexthop",
11390 "advertised");
11391 else if (CHECK_FLAG(p->cap,
11392 PEER_CAP_ENHE_RCV))
11393 json_object_string_add(
11394 json_cap,
11395 "extendedNexthop",
11396 "received");
11397
11398 if (CHECK_FLAG(p->cap,
11399 PEER_CAP_ENHE_RCV)) {
11400 json_nxt =
11401 json_object_new_object();
11402
11403 for (safi = SAFI_UNICAST;
11404 safi < SAFI_MAX; safi++) {
11405 if (CHECK_FLAG(
11406 p->af_cap
11407 [AFI_IP]
11408 [safi],
11409 PEER_CAP_ENHE_AF_RCV)) {
11410 print_store = get_afi_safi_str(
11411 AFI_IP,
11412 safi, true);
11413 json_object_string_add(
11414 json_nxt,
11415 print_store,
11416 "recieved"); /* misspelled for compatibility */
11417 }
11418 }
11419 json_object_object_add(
11420 json_cap,
11421 "extendedNexthopFamililesByPeer",
11422 json_nxt);
11423 }
11424 }
11425
11426 /* Route Refresh */
11427 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
11428 || CHECK_FLAG(p->cap,
11429 PEER_CAP_REFRESH_NEW_RCV)
11430 || CHECK_FLAG(p->cap,
11431 PEER_CAP_REFRESH_OLD_RCV)) {
11432 if (CHECK_FLAG(p->cap,
11433 PEER_CAP_REFRESH_ADV)
11434 && (CHECK_FLAG(
11435 p->cap,
11436 PEER_CAP_REFRESH_NEW_RCV)
11437 || CHECK_FLAG(
11438 p->cap,
11439 PEER_CAP_REFRESH_OLD_RCV))) {
11440 if (CHECK_FLAG(
11441 p->cap,
11442 PEER_CAP_REFRESH_OLD_RCV)
11443 && CHECK_FLAG(
11444 p->cap,
11445 PEER_CAP_REFRESH_NEW_RCV))
11446 json_object_string_add(
11447 json_cap,
11448 "routeRefresh",
11449 "advertisedAndReceivedOldNew");
11450 else {
11451 if (CHECK_FLAG(
11452 p->cap,
11453 PEER_CAP_REFRESH_OLD_RCV))
11454 json_object_string_add(
11455 json_cap,
11456 "routeRefresh",
11457 "advertisedAndReceivedOld");
11458 else
11459 json_object_string_add(
11460 json_cap,
11461 "routeRefresh",
11462 "advertisedAndReceivedNew");
11463 }
11464 } else if (
11465 CHECK_FLAG(
11466 p->cap,
11467 PEER_CAP_REFRESH_ADV))
11468 json_object_string_add(
11469 json_cap,
11470 "routeRefresh",
11471 "advertised");
11472 else if (
11473 CHECK_FLAG(
11474 p->cap,
11475 PEER_CAP_REFRESH_NEW_RCV)
11476 || CHECK_FLAG(
11477 p->cap,
11478 PEER_CAP_REFRESH_OLD_RCV))
11479 json_object_string_add(
11480 json_cap,
11481 "routeRefresh",
11482 "received");
11483 }
11484
11485 /* Multiprotocol Extensions */
11486 json_object *json_multi = NULL;
11487 json_multi = json_object_new_object();
11488
11489 FOREACH_AFI_SAFI (afi, safi) {
11490 if (p->afc_adv[afi][safi]
11491 || p->afc_recv[afi][safi]) {
11492 json_object *json_exten = NULL;
11493 json_exten =
11494 json_object_new_object();
11495
11496 if (p->afc_adv[afi][safi]
11497 && p->afc_recv[afi][safi])
11498 json_object_boolean_true_add(
11499 json_exten,
11500 "advertisedAndReceived");
11501 else if (p->afc_adv[afi][safi])
11502 json_object_boolean_true_add(
11503 json_exten,
11504 "advertised");
11505 else if (p->afc_recv[afi][safi])
11506 json_object_boolean_true_add(
11507 json_exten,
11508 "received");
11509
11510 json_object_object_add(
11511 json_multi,
11512 get_afi_safi_str(afi,
11513 safi,
11514 true),
11515 json_exten);
11516 }
11517 }
11518 json_object_object_add(
11519 json_cap, "multiprotocolExtensions",
11520 json_multi);
11521
11522 /* Hostname capabilities */
11523 json_object *json_hname = NULL;
11524
11525 json_hname = json_object_new_object();
11526
11527 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
11528 json_object_string_add(
11529 json_hname, "advHostName",
11530 bgp->peer_self->hostname
11531 ? bgp->peer_self
11532 ->hostname
11533 : "n/a");
11534 json_object_string_add(
11535 json_hname, "advDomainName",
11536 bgp->peer_self->domainname
11537 ? bgp->peer_self
11538 ->domainname
11539 : "n/a");
11540 }
11541
11542
11543 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
11544 json_object_string_add(
11545 json_hname, "rcvHostName",
11546 p->hostname ? p->hostname
11547 : "n/a");
11548 json_object_string_add(
11549 json_hname, "rcvDomainName",
11550 p->domainname ? p->domainname
11551 : "n/a");
11552 }
11553
11554 json_object_object_add(json_cap, "hostName",
11555 json_hname);
11556
11557 /* Gracefull Restart */
11558 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
11559 || CHECK_FLAG(p->cap,
11560 PEER_CAP_RESTART_ADV)) {
11561 if (CHECK_FLAG(p->cap,
11562 PEER_CAP_RESTART_ADV)
11563 && CHECK_FLAG(p->cap,
11564 PEER_CAP_RESTART_RCV))
11565 json_object_string_add(
11566 json_cap,
11567 "gracefulRestart",
11568 "advertisedAndReceived");
11569 else if (CHECK_FLAG(
11570 p->cap,
11571 PEER_CAP_RESTART_ADV))
11572 json_object_string_add(
11573 json_cap,
11574 "gracefulRestartCapability",
11575 "advertised");
11576 else if (CHECK_FLAG(
11577 p->cap,
11578 PEER_CAP_RESTART_RCV))
11579 json_object_string_add(
11580 json_cap,
11581 "gracefulRestartCapability",
11582 "received");
11583
11584 if (CHECK_FLAG(p->cap,
11585 PEER_CAP_RESTART_RCV)) {
11586 int restart_af_count = 0;
11587 json_object *json_restart =
11588 NULL;
11589 json_restart =
11590 json_object_new_object();
11591
11592 json_object_int_add(
11593 json_cap,
11594 "gracefulRestartRemoteTimerMsecs",
11595 p->v_gr_restart * 1000);
11596
11597 FOREACH_AFI_SAFI (afi, safi) {
11598 if (CHECK_FLAG(
11599 p->af_cap
11600 [afi]
11601 [safi],
11602 PEER_CAP_RESTART_AF_RCV)) {
11603 json_object *
11604 json_sub =
11605 NULL;
11606 json_sub =
11607 json_object_new_object();
11608
11609 if (CHECK_FLAG(
11610 p->af_cap
11611 [afi]
11612 [safi],
11613 PEER_CAP_RESTART_AF_PRESERVE_RCV))
11614 json_object_boolean_true_add(
11615 json_sub,
11616 "preserved");
11617 restart_af_count++;
11618 json_object_object_add(
11619 json_restart,
11620 get_afi_safi_str(
11621 afi,
11622 safi,
11623 true),
11624 json_sub);
11625 }
11626 }
11627 if (!restart_af_count) {
11628 json_object_string_add(
11629 json_cap,
11630 "addressFamiliesByPeer",
11631 "none");
11632 json_object_free(
11633 json_restart);
11634 } else
11635 json_object_object_add(
11636 json_cap,
11637 "addressFamiliesByPeer",
11638 json_restart);
11639 }
11640 }
11641 json_object_object_add(json_neigh,
11642 "neighborCapabilities",
11643 json_cap);
11644 } else {
11645 vty_out(vty, " Neighbor capabilities:\n");
11646
11647 /* AS4 */
11648 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
11649 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
11650 vty_out(vty, " 4 Byte AS:");
11651 if (CHECK_FLAG(p->cap,
11652 PEER_CAP_AS4_ADV))
11653 vty_out(vty, " advertised");
11654 if (CHECK_FLAG(p->cap,
11655 PEER_CAP_AS4_RCV))
11656 vty_out(vty, " %sreceived",
11657 CHECK_FLAG(
11658 p->cap,
11659 PEER_CAP_AS4_ADV)
11660 ? "and "
11661 : "");
11662 vty_out(vty, "\n");
11663 }
11664
11665 /* AddPath */
11666 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
11667 || CHECK_FLAG(p->cap,
11668 PEER_CAP_ADDPATH_ADV)) {
11669 vty_out(vty, " AddPath:\n");
11670
11671 FOREACH_AFI_SAFI (afi, safi) {
11672 if (CHECK_FLAG(
11673 p->af_cap[afi]
11674 [safi],
11675 PEER_CAP_ADDPATH_AF_TX_ADV)
11676 || CHECK_FLAG(
11677 p->af_cap[afi]
11678 [safi],
11679 PEER_CAP_ADDPATH_AF_TX_RCV)) {
11680 vty_out(vty,
11681 " %s: TX ",
11682 get_afi_safi_str(
11683 afi,
11684 safi,
11685 false));
11686
11687 if (CHECK_FLAG(
11688 p->af_cap
11689 [afi]
11690 [safi],
11691 PEER_CAP_ADDPATH_AF_TX_ADV))
11692 vty_out(vty,
11693 "advertised %s",
11694 get_afi_safi_str(
11695 afi,
11696 safi,
11697 false));
11698
11699 if (CHECK_FLAG(
11700 p->af_cap
11701 [afi]
11702 [safi],
11703 PEER_CAP_ADDPATH_AF_TX_RCV))
11704 vty_out(vty,
11705 "%sreceived",
11706 CHECK_FLAG(
11707 p->af_cap
11708 [afi]
11709 [safi],
11710 PEER_CAP_ADDPATH_AF_TX_ADV)
11711 ? " and "
11712 : "");
11713
11714 vty_out(vty, "\n");
11715 }
11716
11717 if (CHECK_FLAG(
11718 p->af_cap[afi]
11719 [safi],
11720 PEER_CAP_ADDPATH_AF_RX_ADV)
11721 || CHECK_FLAG(
11722 p->af_cap[afi]
11723 [safi],
11724 PEER_CAP_ADDPATH_AF_RX_RCV)) {
11725 vty_out(vty,
11726 " %s: RX ",
11727 get_afi_safi_str(
11728 afi,
11729 safi,
11730 false));
11731
11732 if (CHECK_FLAG(
11733 p->af_cap
11734 [afi]
11735 [safi],
11736 PEER_CAP_ADDPATH_AF_RX_ADV))
11737 vty_out(vty,
11738 "advertised %s",
11739 get_afi_safi_str(
11740 afi,
11741 safi,
11742 false));
11743
11744 if (CHECK_FLAG(
11745 p->af_cap
11746 [afi]
11747 [safi],
11748 PEER_CAP_ADDPATH_AF_RX_RCV))
11749 vty_out(vty,
11750 "%sreceived",
11751 CHECK_FLAG(
11752 p->af_cap
11753 [afi]
11754 [safi],
11755 PEER_CAP_ADDPATH_AF_RX_ADV)
11756 ? " and "
11757 : "");
11758
11759 vty_out(vty, "\n");
11760 }
11761 }
11762 }
11763
11764 /* Dynamic */
11765 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
11766 || CHECK_FLAG(p->cap,
11767 PEER_CAP_DYNAMIC_ADV)) {
11768 vty_out(vty, " Dynamic:");
11769 if (CHECK_FLAG(p->cap,
11770 PEER_CAP_DYNAMIC_ADV))
11771 vty_out(vty, " advertised");
11772 if (CHECK_FLAG(p->cap,
11773 PEER_CAP_DYNAMIC_RCV))
11774 vty_out(vty, " %sreceived",
11775 CHECK_FLAG(
11776 p->cap,
11777 PEER_CAP_DYNAMIC_ADV)
11778 ? "and "
11779 : "");
11780 vty_out(vty, "\n");
11781 }
11782
11783 /* Extended nexthop */
11784 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
11785 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
11786 vty_out(vty, " Extended nexthop:");
11787 if (CHECK_FLAG(p->cap,
11788 PEER_CAP_ENHE_ADV))
11789 vty_out(vty, " advertised");
11790 if (CHECK_FLAG(p->cap,
11791 PEER_CAP_ENHE_RCV))
11792 vty_out(vty, " %sreceived",
11793 CHECK_FLAG(
11794 p->cap,
11795 PEER_CAP_ENHE_ADV)
11796 ? "and "
11797 : "");
11798 vty_out(vty, "\n");
11799
11800 if (CHECK_FLAG(p->cap,
11801 PEER_CAP_ENHE_RCV)) {
11802 vty_out(vty,
11803 " Address families by peer:\n ");
11804 for (safi = SAFI_UNICAST;
11805 safi < SAFI_MAX; safi++)
11806 if (CHECK_FLAG(
11807 p->af_cap
11808 [AFI_IP]
11809 [safi],
11810 PEER_CAP_ENHE_AF_RCV))
11811 vty_out(vty,
11812 " %s\n",
11813 get_afi_safi_str(
11814 AFI_IP,
11815 safi,
11816 false));
11817 }
11818 }
11819
11820 /* Route Refresh */
11821 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
11822 || CHECK_FLAG(p->cap,
11823 PEER_CAP_REFRESH_NEW_RCV)
11824 || CHECK_FLAG(p->cap,
11825 PEER_CAP_REFRESH_OLD_RCV)) {
11826 vty_out(vty, " Route refresh:");
11827 if (CHECK_FLAG(p->cap,
11828 PEER_CAP_REFRESH_ADV))
11829 vty_out(vty, " advertised");
11830 if (CHECK_FLAG(p->cap,
11831 PEER_CAP_REFRESH_NEW_RCV)
11832 || CHECK_FLAG(
11833 p->cap,
11834 PEER_CAP_REFRESH_OLD_RCV))
11835 vty_out(vty, " %sreceived(%s)",
11836 CHECK_FLAG(
11837 p->cap,
11838 PEER_CAP_REFRESH_ADV)
11839 ? "and "
11840 : "",
11841 (CHECK_FLAG(
11842 p->cap,
11843 PEER_CAP_REFRESH_OLD_RCV)
11844 && CHECK_FLAG(
11845 p->cap,
11846 PEER_CAP_REFRESH_NEW_RCV))
11847 ? "old & new"
11848 : CHECK_FLAG(
11849 p->cap,
11850 PEER_CAP_REFRESH_OLD_RCV)
11851 ? "old"
11852 : "new");
11853
11854 vty_out(vty, "\n");
11855 }
11856
11857 /* Multiprotocol Extensions */
11858 FOREACH_AFI_SAFI (afi, safi)
11859 if (p->afc_adv[afi][safi]
11860 || p->afc_recv[afi][safi]) {
11861 vty_out(vty,
11862 " Address Family %s:",
11863 get_afi_safi_str(
11864 afi,
11865 safi,
11866 false));
11867 if (p->afc_adv[afi][safi])
11868 vty_out(vty,
11869 " advertised");
11870 if (p->afc_recv[afi][safi])
11871 vty_out(vty,
11872 " %sreceived",
11873 p->afc_adv[afi]
11874 [safi]
11875 ? "and "
11876 : "");
11877 vty_out(vty, "\n");
11878 }
11879
11880 /* Hostname capability */
11881 vty_out(vty, " Hostname Capability:");
11882
11883 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
11884 vty_out(vty,
11885 " advertised (name: %s,domain name: %s)",
11886 bgp->peer_self->hostname
11887 ? bgp->peer_self
11888 ->hostname
11889 : "n/a",
11890 bgp->peer_self->domainname
11891 ? bgp->peer_self
11892 ->domainname
11893 : "n/a");
11894 } else {
11895 vty_out(vty, " not advertised");
11896 }
11897
11898 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
11899 vty_out(vty,
11900 " received (name: %s,domain name: %s)",
11901 p->hostname ? p->hostname
11902 : "n/a",
11903 p->domainname ? p->domainname
11904 : "n/a");
11905 } else {
11906 vty_out(vty, " not received");
11907 }
11908
11909 vty_out(vty, "\n");
11910
11911 /* Graceful Restart */
11912 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
11913 || CHECK_FLAG(p->cap,
11914 PEER_CAP_RESTART_ADV)) {
11915 vty_out(vty,
11916 " Graceful Restart Capability:");
11917 if (CHECK_FLAG(p->cap,
11918 PEER_CAP_RESTART_ADV))
11919 vty_out(vty, " advertised");
11920 if (CHECK_FLAG(p->cap,
11921 PEER_CAP_RESTART_RCV))
11922 vty_out(vty, " %sreceived",
11923 CHECK_FLAG(
11924 p->cap,
11925 PEER_CAP_RESTART_ADV)
11926 ? "and "
11927 : "");
11928 vty_out(vty, "\n");
11929
11930 if (CHECK_FLAG(p->cap,
11931 PEER_CAP_RESTART_RCV)) {
11932 int restart_af_count = 0;
11933
11934 vty_out(vty,
11935 " Remote Restart timer is %d seconds\n",
11936 p->v_gr_restart);
11937 vty_out(vty,
11938 " Address families by peer:\n ");
11939
11940 FOREACH_AFI_SAFI (afi, safi)
11941 if (CHECK_FLAG(
11942 p->af_cap
11943 [afi]
11944 [safi],
11945 PEER_CAP_RESTART_AF_RCV)) {
11946 vty_out(vty,
11947 "%s%s(%s)",
11948 restart_af_count
11949 ? ", "
11950 : "",
11951 get_afi_safi_str(
11952 afi,
11953 safi,
11954 false),
11955 CHECK_FLAG(
11956 p->af_cap
11957 [afi]
11958 [safi],
11959 PEER_CAP_RESTART_AF_PRESERVE_RCV)
11960 ? "preserved"
11961 : "not preserved");
11962 restart_af_count++;
11963 }
11964 if (!restart_af_count)
11965 vty_out(vty, "none");
11966 vty_out(vty, "\n");
11967 }
11968 } /* Gracefull Restart */
11969 }
11970 }
11971 }
11972
11973 /* graceful restart information */
11974 json_object *json_grace = NULL;
11975 json_object *json_grace_send = NULL;
11976 json_object *json_grace_recv = NULL;
11977 int eor_send_af_count = 0;
11978 int eor_receive_af_count = 0;
11979
11980 if (use_json) {
11981 json_grace = json_object_new_object();
11982 json_grace_send = json_object_new_object();
11983 json_grace_recv = json_object_new_object();
11984
11985 if ((p->status == Established)
11986 && CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
11987 FOREACH_AFI_SAFI (afi, safi) {
11988 if (CHECK_FLAG(p->af_sflags[afi][safi],
11989 PEER_STATUS_EOR_SEND)) {
11990 json_object_boolean_true_add(
11991 json_grace_send,
11992 get_afi_safi_str(afi,
11993 safi,
11994 true));
11995 eor_send_af_count++;
11996 }
11997 }
11998 FOREACH_AFI_SAFI (afi, safi) {
11999 if (CHECK_FLAG(
12000 p->af_sflags[afi][safi],
12001 PEER_STATUS_EOR_RECEIVED)) {
12002 json_object_boolean_true_add(
12003 json_grace_recv,
12004 get_afi_safi_str(afi,
12005 safi,
12006 true));
12007 eor_receive_af_count++;
12008 }
12009 }
12010 }
12011 json_object_object_add(json_grace, "endOfRibSend",
12012 json_grace_send);
12013 json_object_object_add(json_grace, "endOfRibRecv",
12014 json_grace_recv);
12015
12016
12017 if (p->t_gr_restart)
12018 json_object_int_add(json_grace,
12019 "gracefulRestartTimerMsecs",
12020 thread_timer_remain_second(
12021 p->t_gr_restart)
12022 * 1000);
12023
12024 if (p->t_gr_stale)
12025 json_object_int_add(
12026 json_grace,
12027 "gracefulStalepathTimerMsecs",
12028 thread_timer_remain_second(
12029 p->t_gr_stale)
12030 * 1000);
12031 /* more gr info in new format */
12032 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json,
12033 json_grace);
12034 json_object_object_add(
12035 json_neigh, "gracefulRestartInfo", json_grace);
12036 } else {
12037 vty_out(vty, " Graceful restart information:\n");
12038 if ((p->status == Established)
12039 && CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
12040
12041 vty_out(vty, " End-of-RIB send: ");
12042 FOREACH_AFI_SAFI (afi, safi) {
12043 if (CHECK_FLAG(p->af_sflags[afi][safi],
12044 PEER_STATUS_EOR_SEND)) {
12045 vty_out(vty, "%s%s",
12046 eor_send_af_count ? ", "
12047 : "",
12048 get_afi_safi_str(
12049 afi, safi,
12050 false));
12051 eor_send_af_count++;
12052 }
12053 }
12054 vty_out(vty, "\n");
12055 vty_out(vty, " End-of-RIB received: ");
12056 FOREACH_AFI_SAFI (afi, safi) {
12057 if (CHECK_FLAG(
12058 p->af_sflags[afi][safi],
12059 PEER_STATUS_EOR_RECEIVED)) {
12060 vty_out(vty, "%s%s",
12061 eor_receive_af_count
12062 ? ", "
12063 : "",
12064 get_afi_safi_str(afi,
12065 safi,
12066 false));
12067 eor_receive_af_count++;
12068 }
12069 }
12070 vty_out(vty, "\n");
12071 }
12072
12073 if (p->t_gr_restart)
12074 vty_out(vty,
12075 " The remaining time of restart timer is %ld\n",
12076 thread_timer_remain_second(
12077 p->t_gr_restart));
12078
12079 if (p->t_gr_stale)
12080 vty_out(vty,
12081 " The remaining time of stalepath timer is %ld\n",
12082 thread_timer_remain_second(
12083 p->t_gr_stale));
12084
12085 /* more gr info in new format */
12086 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, NULL);
12087 }
12088
12089 if (use_json) {
12090 json_object *json_stat = NULL;
12091 json_stat = json_object_new_object();
12092 /* Packet counts. */
12093
12094 atomic_size_t outq_count, inq_count;
12095 outq_count = atomic_load_explicit(&p->obuf->count,
12096 memory_order_relaxed);
12097 inq_count = atomic_load_explicit(&p->ibuf->count,
12098 memory_order_relaxed);
12099
12100 json_object_int_add(json_stat, "depthInq",
12101 (unsigned long)inq_count);
12102 json_object_int_add(json_stat, "depthOutq",
12103 (unsigned long)outq_count);
12104 json_object_int_add(json_stat, "opensSent",
12105 atomic_load_explicit(&p->open_out,
12106 memory_order_relaxed));
12107 json_object_int_add(json_stat, "opensRecv",
12108 atomic_load_explicit(&p->open_in,
12109 memory_order_relaxed));
12110 json_object_int_add(json_stat, "notificationsSent",
12111 atomic_load_explicit(&p->notify_out,
12112 memory_order_relaxed));
12113 json_object_int_add(json_stat, "notificationsRecv",
12114 atomic_load_explicit(&p->notify_in,
12115 memory_order_relaxed));
12116 json_object_int_add(json_stat, "updatesSent",
12117 atomic_load_explicit(&p->update_out,
12118 memory_order_relaxed));
12119 json_object_int_add(json_stat, "updatesRecv",
12120 atomic_load_explicit(&p->update_in,
12121 memory_order_relaxed));
12122 json_object_int_add(json_stat, "keepalivesSent",
12123 atomic_load_explicit(&p->keepalive_out,
12124 memory_order_relaxed));
12125 json_object_int_add(json_stat, "keepalivesRecv",
12126 atomic_load_explicit(&p->keepalive_in,
12127 memory_order_relaxed));
12128 json_object_int_add(json_stat, "routeRefreshSent",
12129 atomic_load_explicit(&p->refresh_out,
12130 memory_order_relaxed));
12131 json_object_int_add(json_stat, "routeRefreshRecv",
12132 atomic_load_explicit(&p->refresh_in,
12133 memory_order_relaxed));
12134 json_object_int_add(json_stat, "capabilitySent",
12135 atomic_load_explicit(&p->dynamic_cap_out,
12136 memory_order_relaxed));
12137 json_object_int_add(json_stat, "capabilityRecv",
12138 atomic_load_explicit(&p->dynamic_cap_in,
12139 memory_order_relaxed));
12140 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
12141 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
12142 json_object_object_add(json_neigh, "messageStats", json_stat);
12143 } else {
12144 atomic_size_t outq_count, inq_count;
12145 outq_count = atomic_load_explicit(&p->obuf->count,
12146 memory_order_relaxed);
12147 inq_count = atomic_load_explicit(&p->ibuf->count,
12148 memory_order_relaxed);
12149
12150 /* Packet counts. */
12151 vty_out(vty, " Message statistics:\n");
12152 vty_out(vty, " Inq depth is %zu\n", inq_count);
12153 vty_out(vty, " Outq depth is %zu\n", outq_count);
12154 vty_out(vty, " Sent Rcvd\n");
12155 vty_out(vty, " Opens: %10d %10d\n",
12156 atomic_load_explicit(&p->open_out,
12157 memory_order_relaxed),
12158 atomic_load_explicit(&p->open_in,
12159 memory_order_relaxed));
12160 vty_out(vty, " Notifications: %10d %10d\n",
12161 atomic_load_explicit(&p->notify_out,
12162 memory_order_relaxed),
12163 atomic_load_explicit(&p->notify_in,
12164 memory_order_relaxed));
12165 vty_out(vty, " Updates: %10d %10d\n",
12166 atomic_load_explicit(&p->update_out,
12167 memory_order_relaxed),
12168 atomic_load_explicit(&p->update_in,
12169 memory_order_relaxed));
12170 vty_out(vty, " Keepalives: %10d %10d\n",
12171 atomic_load_explicit(&p->keepalive_out,
12172 memory_order_relaxed),
12173 atomic_load_explicit(&p->keepalive_in,
12174 memory_order_relaxed));
12175 vty_out(vty, " Route Refresh: %10d %10d\n",
12176 atomic_load_explicit(&p->refresh_out,
12177 memory_order_relaxed),
12178 atomic_load_explicit(&p->refresh_in,
12179 memory_order_relaxed));
12180 vty_out(vty, " Capability: %10d %10d\n",
12181 atomic_load_explicit(&p->dynamic_cap_out,
12182 memory_order_relaxed),
12183 atomic_load_explicit(&p->dynamic_cap_in,
12184 memory_order_relaxed));
12185 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
12186 PEER_TOTAL_RX(p));
12187 }
12188
12189 if (use_json) {
12190 /* advertisement-interval */
12191 json_object_int_add(json_neigh,
12192 "minBtwnAdvertisementRunsTimerMsecs",
12193 p->v_routeadv * 1000);
12194
12195 /* Update-source. */
12196 if (p->update_if || p->update_source) {
12197 if (p->update_if)
12198 json_object_string_add(json_neigh,
12199 "updateSource",
12200 p->update_if);
12201 else if (p->update_source)
12202 json_object_string_add(
12203 json_neigh, "updateSource",
12204 sockunion2str(p->update_source, buf1,
12205 SU_ADDRSTRLEN));
12206 }
12207 } else {
12208 /* advertisement-interval */
12209 vty_out(vty,
12210 " Minimum time between advertisement runs is %d seconds\n",
12211 p->v_routeadv);
12212
12213 /* Update-source. */
12214 if (p->update_if || p->update_source) {
12215 vty_out(vty, " Update source is ");
12216 if (p->update_if)
12217 vty_out(vty, "%s", p->update_if);
12218 else if (p->update_source)
12219 vty_out(vty, "%s",
12220 sockunion2str(p->update_source, buf1,
12221 SU_ADDRSTRLEN));
12222 vty_out(vty, "\n");
12223 }
12224
12225 vty_out(vty, "\n");
12226 }
12227
12228 /* Address Family Information */
12229 json_object *json_hold = NULL;
12230
12231 if (use_json)
12232 json_hold = json_object_new_object();
12233
12234 FOREACH_AFI_SAFI (afi, safi)
12235 if (p->afc[afi][safi])
12236 bgp_show_peer_afi(vty, p, afi, safi, use_json,
12237 json_hold);
12238
12239 if (use_json) {
12240 json_object_object_add(json_neigh, "addressFamilyInfo",
12241 json_hold);
12242 json_object_int_add(json_neigh, "connectionsEstablished",
12243 p->established);
12244 json_object_int_add(json_neigh, "connectionsDropped",
12245 p->dropped);
12246 } else
12247 vty_out(vty, " Connections established %d; dropped %d\n",
12248 p->established, p->dropped);
12249
12250 if (!p->last_reset) {
12251 if (use_json)
12252 json_object_string_add(json_neigh, "lastReset",
12253 "never");
12254 else
12255 vty_out(vty, " Last reset never\n");
12256 } else {
12257 if (use_json) {
12258 time_t uptime;
12259 struct tm tm;
12260
12261 uptime = bgp_clock();
12262 uptime -= p->resettime;
12263 gmtime_r(&uptime, &tm);
12264
12265 json_object_int_add(json_neigh, "lastResetTimerMsecs",
12266 (tm.tm_sec * 1000)
12267 + (tm.tm_min * 60000)
12268 + (tm.tm_hour * 3600000));
12269 bgp_show_peer_reset(NULL, p, json_neigh, true);
12270 } else {
12271 vty_out(vty, " Last reset %s, ",
12272 peer_uptime(p->resettime, timebuf,
12273 BGP_UPTIME_LEN, 0, NULL));
12274
12275 bgp_show_peer_reset(vty, p, NULL, false);
12276 if (p->last_reset_cause_size) {
12277 msg = p->last_reset_cause;
12278 vty_out(vty,
12279 " Message received that caused BGP to send a NOTIFICATION:\n ");
12280 for (i = 1; i <= p->last_reset_cause_size;
12281 i++) {
12282 vty_out(vty, "%02X", *msg++);
12283
12284 if (i != p->last_reset_cause_size) {
12285 if (i % 16 == 0) {
12286 vty_out(vty, "\n ");
12287 } else if (i % 4 == 0) {
12288 vty_out(vty, " ");
12289 }
12290 }
12291 }
12292 vty_out(vty, "\n");
12293 }
12294 }
12295 }
12296
12297 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
12298 if (use_json)
12299 json_object_boolean_true_add(json_neigh,
12300 "prefixesConfigExceedMax");
12301 else
12302 vty_out(vty,
12303 " Peer had exceeded the max. no. of prefixes configured.\n");
12304
12305 if (p->t_pmax_restart) {
12306 if (use_json) {
12307 json_object_boolean_true_add(
12308 json_neigh, "reducePrefixNumFrom");
12309 json_object_int_add(json_neigh,
12310 "restartInTimerMsec",
12311 thread_timer_remain_second(
12312 p->t_pmax_restart)
12313 * 1000);
12314 } else
12315 vty_out(vty,
12316 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
12317 p->host, thread_timer_remain_second(
12318 p->t_pmax_restart));
12319 } else {
12320 if (use_json)
12321 json_object_boolean_true_add(
12322 json_neigh,
12323 "reducePrefixNumAndClearIpBgp");
12324 else
12325 vty_out(vty,
12326 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
12327 p->host);
12328 }
12329 }
12330
12331 /* EBGP Multihop and GTSM */
12332 if (p->sort != BGP_PEER_IBGP) {
12333 if (use_json) {
12334 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
12335 json_object_int_add(json_neigh,
12336 "externalBgpNbrMaxHopsAway",
12337 p->gtsm_hops);
12338 else if (p->ttl > BGP_DEFAULT_TTL)
12339 json_object_int_add(json_neigh,
12340 "externalBgpNbrMaxHopsAway",
12341 p->ttl);
12342 } else {
12343 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
12344 vty_out(vty,
12345 " External BGP neighbor may be up to %d hops away.\n",
12346 p->gtsm_hops);
12347 else if (p->ttl > BGP_DEFAULT_TTL)
12348 vty_out(vty,
12349 " External BGP neighbor may be up to %d hops away.\n",
12350 p->ttl);
12351 }
12352 } else {
12353 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED) {
12354 if (use_json)
12355 json_object_int_add(json_neigh,
12356 "internalBgpNbrMaxHopsAway",
12357 p->gtsm_hops);
12358 else
12359 vty_out(vty,
12360 " Internal BGP neighbor may be up to %d hops away.\n",
12361 p->gtsm_hops);
12362 }
12363 }
12364
12365 /* Local address. */
12366 if (p->su_local) {
12367 if (use_json) {
12368 json_object_string_add(json_neigh, "hostLocal",
12369 sockunion2str(p->su_local, buf1,
12370 SU_ADDRSTRLEN));
12371 json_object_int_add(json_neigh, "portLocal",
12372 ntohs(p->su_local->sin.sin_port));
12373 } else
12374 vty_out(vty, "Local host: %s, Local port: %d\n",
12375 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
12376 ntohs(p->su_local->sin.sin_port));
12377 }
12378
12379 /* Remote address. */
12380 if (p->su_remote) {
12381 if (use_json) {
12382 json_object_string_add(json_neigh, "hostForeign",
12383 sockunion2str(p->su_remote, buf1,
12384 SU_ADDRSTRLEN));
12385 json_object_int_add(json_neigh, "portForeign",
12386 ntohs(p->su_remote->sin.sin_port));
12387 } else
12388 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
12389 sockunion2str(p->su_remote, buf1,
12390 SU_ADDRSTRLEN),
12391 ntohs(p->su_remote->sin.sin_port));
12392 }
12393
12394 /* Nexthop display. */
12395 if (p->su_local) {
12396 if (use_json) {
12397 json_object_string_add(json_neigh, "nexthop",
12398 inet_ntop(AF_INET,
12399 &p->nexthop.v4, buf1,
12400 sizeof(buf1)));
12401 json_object_string_add(json_neigh, "nexthopGlobal",
12402 inet_ntop(AF_INET6,
12403 &p->nexthop.v6_global,
12404 buf1, sizeof(buf1)));
12405 json_object_string_add(json_neigh, "nexthopLocal",
12406 inet_ntop(AF_INET6,
12407 &p->nexthop.v6_local,
12408 buf1, sizeof(buf1)));
12409 if (p->shared_network)
12410 json_object_string_add(json_neigh,
12411 "bgpConnection",
12412 "sharedNetwork");
12413 else
12414 json_object_string_add(json_neigh,
12415 "bgpConnection",
12416 "nonSharedNetwork");
12417 } else {
12418 vty_out(vty, "Nexthop: %s\n",
12419 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
12420 sizeof(buf1)));
12421 vty_out(vty, "Nexthop global: %s\n",
12422 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
12423 sizeof(buf1)));
12424 vty_out(vty, "Nexthop local: %s\n",
12425 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
12426 sizeof(buf1)));
12427 vty_out(vty, "BGP connection: %s\n",
12428 p->shared_network ? "shared network"
12429 : "non shared network");
12430 }
12431 }
12432
12433 /* Timer information. */
12434 if (use_json) {
12435 json_object_int_add(json_neigh, "connectRetryTimer",
12436 p->v_connect);
12437 if (p->status == Established && p->rtt)
12438 json_object_int_add(json_neigh, "estimatedRttInMsecs",
12439 p->rtt);
12440 if (p->t_start)
12441 json_object_int_add(
12442 json_neigh, "nextStartTimerDueInMsecs",
12443 thread_timer_remain_second(p->t_start) * 1000);
12444 if (p->t_connect)
12445 json_object_int_add(
12446 json_neigh, "nextConnectTimerDueInMsecs",
12447 thread_timer_remain_second(p->t_connect)
12448 * 1000);
12449 if (p->t_routeadv) {
12450 json_object_int_add(json_neigh, "mraiInterval",
12451 p->v_routeadv);
12452 json_object_int_add(
12453 json_neigh, "mraiTimerExpireInMsecs",
12454 thread_timer_remain_second(p->t_routeadv)
12455 * 1000);
12456 }
12457 if (p->password)
12458 json_object_int_add(json_neigh, "authenticationEnabled",
12459 1);
12460
12461 if (p->t_read)
12462 json_object_string_add(json_neigh, "readThread", "on");
12463 else
12464 json_object_string_add(json_neigh, "readThread", "off");
12465
12466 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
12467 json_object_string_add(json_neigh, "writeThread", "on");
12468 else
12469 json_object_string_add(json_neigh, "writeThread",
12470 "off");
12471 } else {
12472 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
12473 p->v_connect);
12474 if (p->status == Established && p->rtt)
12475 vty_out(vty, "Estimated round trip time: %d ms\n",
12476 p->rtt);
12477 if (p->t_start)
12478 vty_out(vty, "Next start timer due in %ld seconds\n",
12479 thread_timer_remain_second(p->t_start));
12480 if (p->t_connect)
12481 vty_out(vty, "Next connect timer due in %ld seconds\n",
12482 thread_timer_remain_second(p->t_connect));
12483 if (p->t_routeadv)
12484 vty_out(vty,
12485 "MRAI (interval %u) timer expires in %ld seconds\n",
12486 p->v_routeadv,
12487 thread_timer_remain_second(p->t_routeadv));
12488 if (p->password)
12489 vty_out(vty, "Peer Authentication Enabled\n");
12490
12491 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
12492 p->t_read ? "on" : "off",
12493 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
12494 ? "on"
12495 : "off", p->fd);
12496 }
12497
12498 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
12499 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
12500 bgp_capability_vty_out(vty, p, use_json, json_neigh);
12501
12502 if (!use_json)
12503 vty_out(vty, "\n");
12504
12505 /* BFD information. */
12506 bgp_bfd_show_info(vty, p, use_json, json_neigh);
12507
12508 if (use_json) {
12509 if (p->conf_if) /* Configured interface name. */
12510 json_object_object_add(json, p->conf_if, json_neigh);
12511 else /* Configured IP address. */
12512 json_object_object_add(json, p->host, json_neigh);
12513 }
12514 }
12515
12516 static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
12517 enum show_type type,
12518 union sockunion *su,
12519 const char *conf_if, afi_t afi,
12520 bool use_json)
12521 {
12522 struct listnode *node, *nnode;
12523 struct peer *peer;
12524 int find = 0;
12525 safi_t safi = SAFI_UNICAST;
12526 json_object *json = NULL;
12527 json_object *json_neighbor = NULL;
12528
12529 if (use_json) {
12530 json = json_object_new_object();
12531 json_neighbor = json_object_new_object();
12532 }
12533
12534 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
12535
12536 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
12537 continue;
12538
12539 if ((peer->afc[afi][safi]) == 0)
12540 continue;
12541
12542 if (type == show_all) {
12543 bgp_show_peer_gr_status(vty, peer, use_json,
12544 json_neighbor);
12545
12546 if (use_json) {
12547 json_object_object_add(json, peer->host,
12548 json_neighbor);
12549 json_neighbor = NULL;
12550 }
12551
12552 } else if (type == show_peer) {
12553 if (conf_if) {
12554 if ((peer->conf_if
12555 && !strcmp(peer->conf_if, conf_if))
12556 || (peer->hostname
12557 && !strcmp(peer->hostname, conf_if))) {
12558 find = 1;
12559 bgp_show_peer_gr_status(vty, peer,
12560 use_json,
12561 json_neighbor);
12562 }
12563 } else {
12564 if (sockunion_same(&peer->su, su)) {
12565 find = 1;
12566 bgp_show_peer_gr_status(vty, peer,
12567 use_json,
12568 json_neighbor);
12569 }
12570 }
12571 if (use_json && find)
12572 json_object_object_add(json, peer->host,
12573 json_neighbor);
12574 }
12575
12576 if (find) {
12577 json_neighbor = NULL;
12578 break;
12579 }
12580 }
12581
12582 if (type == show_peer && !find) {
12583 if (use_json)
12584 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
12585 else
12586 vty_out(vty, "%% No such neighbor\n");
12587 }
12588 if (use_json) {
12589 vty_out(vty, "%s\n",
12590 json_object_to_json_string_ext(
12591 json, JSON_C_TO_STRING_PRETTY));
12592
12593 if (json_neighbor)
12594 json_object_free(json_neighbor);
12595 json_object_free(json);
12596 } else {
12597 vty_out(vty, "\n");
12598 }
12599
12600 return CMD_SUCCESS;
12601 }
12602
12603 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
12604 enum show_type type, union sockunion *su,
12605 const char *conf_if, bool use_json,
12606 json_object *json)
12607 {
12608 struct listnode *node, *nnode;
12609 struct peer *peer;
12610 int find = 0;
12611 bool nbr_output = false;
12612 afi_t afi = AFI_MAX;
12613 safi_t safi = SAFI_MAX;
12614
12615 if (type == show_ipv4_peer || type == show_ipv4_all) {
12616 afi = AFI_IP;
12617 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
12618 afi = AFI_IP6;
12619 }
12620
12621 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
12622 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
12623 continue;
12624
12625 switch (type) {
12626 case show_all:
12627 bgp_show_peer(vty, peer, use_json, json);
12628 nbr_output = true;
12629 break;
12630 case show_peer:
12631 if (conf_if) {
12632 if ((peer->conf_if
12633 && !strcmp(peer->conf_if, conf_if))
12634 || (peer->hostname
12635 && !strcmp(peer->hostname, conf_if))) {
12636 find = 1;
12637 bgp_show_peer(vty, peer, use_json,
12638 json);
12639 }
12640 } else {
12641 if (sockunion_same(&peer->su, su)) {
12642 find = 1;
12643 bgp_show_peer(vty, peer, use_json,
12644 json);
12645 }
12646 }
12647 break;
12648 case show_ipv4_peer:
12649 case show_ipv6_peer:
12650 FOREACH_SAFI (safi) {
12651 if (peer->afc[afi][safi]) {
12652 if (conf_if) {
12653 if ((peer->conf_if
12654 && !strcmp(peer->conf_if, conf_if))
12655 || (peer->hostname
12656 && !strcmp(peer->hostname, conf_if))) {
12657 find = 1;
12658 bgp_show_peer(vty, peer, use_json,
12659 json);
12660 break;
12661 }
12662 } else {
12663 if (sockunion_same(&peer->su, su)) {
12664 find = 1;
12665 bgp_show_peer(vty, peer, use_json,
12666 json);
12667 break;
12668 }
12669 }
12670 }
12671 }
12672 break;
12673 case show_ipv4_all:
12674 case show_ipv6_all:
12675 FOREACH_SAFI (safi) {
12676 if (peer->afc[afi][safi]) {
12677 bgp_show_peer(vty, peer, use_json, json);
12678 nbr_output = true;
12679 break;
12680 }
12681 }
12682 break;
12683 }
12684 }
12685
12686 if ((type == show_peer || type == show_ipv4_peer ||
12687 type == show_ipv6_peer) && !find) {
12688 if (use_json)
12689 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
12690 else
12691 vty_out(vty, "%% No such neighbor in this view/vrf\n");
12692 }
12693
12694 if (type != show_peer && type != show_ipv4_peer &&
12695 type != show_ipv6_peer && !nbr_output && !use_json)
12696 vty_out(vty, "%% No BGP neighbors found\n");
12697
12698 if (use_json) {
12699 vty_out(vty, "%s\n", json_object_to_json_string_ext(
12700 json, JSON_C_TO_STRING_PRETTY));
12701 } else {
12702 vty_out(vty, "\n");
12703 }
12704
12705 return CMD_SUCCESS;
12706 }
12707
12708 static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
12709 enum show_type type,
12710 const char *ip_str,
12711 afi_t afi, bool use_json)
12712 {
12713
12714 int ret;
12715 struct bgp *bgp;
12716 union sockunion su;
12717
12718 bgp = bgp_get_default();
12719
12720 if (!bgp)
12721 return;
12722
12723 if (!use_json)
12724 bgp_show_global_graceful_restart_mode_vty(vty, bgp, use_json,
12725 NULL);
12726
12727 if (ip_str) {
12728 ret = str2sockunion(ip_str, &su);
12729 if (ret < 0)
12730 bgp_show_neighbor_graceful_restart(
12731 vty, bgp, type, NULL, ip_str, afi, use_json);
12732 else
12733 bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
12734 NULL, afi, use_json);
12735 } else
12736 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
12737 afi, use_json);
12738 }
12739
12740 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
12741 enum show_type type,
12742 const char *ip_str,
12743 bool use_json)
12744 {
12745 struct listnode *node, *nnode;
12746 struct bgp *bgp;
12747 union sockunion su;
12748 json_object *json = NULL;
12749 int ret, is_first = 1;
12750 bool nbr_output = false;
12751
12752 if (use_json)
12753 vty_out(vty, "{\n");
12754
12755 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
12756 nbr_output = true;
12757 if (use_json) {
12758 if (!(json = json_object_new_object())) {
12759 flog_err(
12760 EC_BGP_JSON_MEM_ERROR,
12761 "Unable to allocate memory for JSON object");
12762 vty_out(vty,
12763 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
12764 return;
12765 }
12766
12767 json_object_int_add(json, "vrfId",
12768 (bgp->vrf_id == VRF_UNKNOWN)
12769 ? -1
12770 : (int64_t)bgp->vrf_id);
12771 json_object_string_add(
12772 json, "vrfName",
12773 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
12774 ? VRF_DEFAULT_NAME
12775 : bgp->name);
12776
12777 if (!is_first)
12778 vty_out(vty, ",\n");
12779 else
12780 is_first = 0;
12781
12782 vty_out(vty, "\"%s\":",
12783 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
12784 ? VRF_DEFAULT_NAME
12785 : bgp->name);
12786 } else {
12787 vty_out(vty, "\nInstance %s:\n",
12788 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
12789 ? VRF_DEFAULT_NAME
12790 : bgp->name);
12791 }
12792
12793 if (type == show_peer || type == show_ipv4_peer ||
12794 type == show_ipv6_peer) {
12795 ret = str2sockunion(ip_str, &su);
12796 if (ret < 0)
12797 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
12798 use_json, json);
12799 else
12800 bgp_show_neighbor(vty, bgp, type, &su, NULL,
12801 use_json, json);
12802 } else {
12803 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
12804 use_json, json);
12805 }
12806 json_object_free(json);
12807 }
12808
12809 if (use_json) {
12810 vty_out(vty, "}\n");
12811 json_object_free(json);
12812 }
12813 else if (!nbr_output)
12814 vty_out(vty, "%% BGP instance not found\n");
12815 }
12816
12817 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
12818 enum show_type type, const char *ip_str,
12819 bool use_json)
12820 {
12821 int ret;
12822 struct bgp *bgp;
12823 union sockunion su;
12824 json_object *json = NULL;
12825
12826 if (name) {
12827 if (strmatch(name, "all")) {
12828 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
12829 use_json);
12830 return CMD_SUCCESS;
12831 } else {
12832 bgp = bgp_lookup_by_name(name);
12833 if (!bgp) {
12834 if (use_json) {
12835 json = json_object_new_object();
12836 vty_out(vty, "%s\n",
12837 json_object_to_json_string_ext(
12838 json,
12839 JSON_C_TO_STRING_PRETTY));
12840 json_object_free(json);
12841 } else
12842 vty_out(vty,
12843 "%% BGP instance not found\n");
12844
12845 return CMD_WARNING;
12846 }
12847 }
12848 } else {
12849 bgp = bgp_get_default();
12850 }
12851
12852 if (bgp) {
12853 json = json_object_new_object();
12854 if (ip_str) {
12855 ret = str2sockunion(ip_str, &su);
12856 if (ret < 0)
12857 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
12858 use_json, json);
12859 else
12860 bgp_show_neighbor(vty, bgp, type, &su, NULL,
12861 use_json, json);
12862 } else {
12863 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
12864 json);
12865 }
12866 json_object_free(json);
12867 } else {
12868 if (use_json)
12869 vty_out(vty, "{}\n");
12870 else
12871 vty_out(vty, "%% BGP instance not found\n");
12872 }
12873
12874 return CMD_SUCCESS;
12875 }
12876
12877
12878
12879 /* "show [ip] bgp neighbors graceful-restart" commands. */
12880 DEFUN (show_ip_bgp_neighbors_gracrful_restart,
12881 show_ip_bgp_neighbors_graceful_restart_cmd,
12882 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
12883 SHOW_STR
12884 BGP_STR
12885 IP_STR
12886 IPV6_STR
12887 NEIGHBOR_STR
12888 "Neighbor to display information about\n"
12889 "Neighbor to display information about\n"
12890 "Neighbor on BGP configured interface\n"
12891 GR_SHOW
12892 JSON_STR)
12893 {
12894 char *sh_arg = NULL;
12895 enum show_type sh_type;
12896 int idx = 0;
12897 afi_t afi = AFI_MAX;
12898 bool uj = use_json(argc, argv);
12899
12900 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
12901 afi = AFI_MAX;
12902
12903 idx++;
12904
12905 if (argv_find(argv, argc, "A.B.C.D", &idx)
12906 || argv_find(argv, argc, "X:X::X:X", &idx)
12907 || argv_find(argv, argc, "WORD", &idx)) {
12908 sh_type = show_peer;
12909 sh_arg = argv[idx]->arg;
12910 } else
12911 sh_type = show_all;
12912
12913 if (!argv_find(argv, argc, "graceful-restart", &idx))
12914 return CMD_SUCCESS;
12915
12916
12917 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
12918 afi, uj);
12919 }
12920
12921 /* "show [ip] bgp neighbors" commands. */
12922 DEFUN (show_ip_bgp_neighbors,
12923 show_ip_bgp_neighbors_cmd,
12924 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
12925 SHOW_STR
12926 IP_STR
12927 BGP_STR
12928 BGP_INSTANCE_HELP_STR
12929 "Address Family\n"
12930 "Address Family\n"
12931 "Detailed information on TCP and BGP neighbor connections\n"
12932 "Neighbor to display information about\n"
12933 "Neighbor to display information about\n"
12934 "Neighbor on BGP configured interface\n"
12935 JSON_STR)
12936 {
12937 char *vrf = NULL;
12938 char *sh_arg = NULL;
12939 enum show_type sh_type;
12940 afi_t afi = AFI_MAX;
12941
12942 bool uj = use_json(argc, argv);
12943
12944 int idx = 0;
12945
12946 /* [<vrf> VIEWVRFNAME] */
12947 if (argv_find(argv, argc, "vrf", &idx)) {
12948 vrf = argv[idx + 1]->arg;
12949 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
12950 vrf = NULL;
12951 } else if (argv_find(argv, argc, "view", &idx))
12952 /* [<view> VIEWVRFNAME] */
12953 vrf = argv[idx + 1]->arg;
12954
12955 idx++;
12956
12957 if (argv_find(argv, argc, "ipv4", &idx)) {
12958 sh_type = show_ipv4_all;
12959 afi = AFI_IP;
12960 } else if (argv_find(argv, argc, "ipv6", &idx)) {
12961 sh_type = show_ipv6_all;
12962 afi = AFI_IP6;
12963 } else {
12964 sh_type = show_all;
12965 }
12966
12967 if (argv_find(argv, argc, "A.B.C.D", &idx)
12968 || argv_find(argv, argc, "X:X::X:X", &idx)
12969 || argv_find(argv, argc, "WORD", &idx)) {
12970 sh_type = show_peer;
12971 sh_arg = argv[idx]->arg;
12972 }
12973
12974 if (sh_type == show_peer && afi == AFI_IP) {
12975 sh_type = show_ipv4_peer;
12976 } else if (sh_type == show_peer && afi == AFI_IP6) {
12977 sh_type = show_ipv6_peer;
12978 }
12979
12980 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
12981 }
12982
12983 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
12984 paths' and `show ip mbgp paths'. Those functions results are the
12985 same.*/
12986 DEFUN (show_ip_bgp_paths,
12987 show_ip_bgp_paths_cmd,
12988 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
12989 SHOW_STR
12990 IP_STR
12991 BGP_STR
12992 BGP_SAFI_HELP_STR
12993 "Path information\n")
12994 {
12995 vty_out(vty, "Address Refcnt Path\n");
12996 aspath_print_all_vty(vty);
12997 return CMD_SUCCESS;
12998 }
12999
13000 #include "hash.h"
13001
13002 static void community_show_all_iterator(struct hash_bucket *bucket,
13003 struct vty *vty)
13004 {
13005 struct community *com;
13006
13007 com = (struct community *)bucket->data;
13008 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
13009 community_str(com, false));
13010 }
13011
13012 /* Show BGP's community internal data. */
13013 DEFUN (show_ip_bgp_community_info,
13014 show_ip_bgp_community_info_cmd,
13015 "show [ip] bgp community-info",
13016 SHOW_STR
13017 IP_STR
13018 BGP_STR
13019 "List all bgp community information\n")
13020 {
13021 vty_out(vty, "Address Refcnt Community\n");
13022
13023 hash_iterate(community_hash(),
13024 (void (*)(struct hash_bucket *,
13025 void *))community_show_all_iterator,
13026 vty);
13027
13028 return CMD_SUCCESS;
13029 }
13030
13031 static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
13032 struct vty *vty)
13033 {
13034 struct lcommunity *lcom;
13035
13036 lcom = (struct lcommunity *)bucket->data;
13037 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
13038 lcommunity_str(lcom, false));
13039 }
13040
13041 /* Show BGP's community internal data. */
13042 DEFUN (show_ip_bgp_lcommunity_info,
13043 show_ip_bgp_lcommunity_info_cmd,
13044 "show ip bgp large-community-info",
13045 SHOW_STR
13046 IP_STR
13047 BGP_STR
13048 "List all bgp large-community information\n")
13049 {
13050 vty_out(vty, "Address Refcnt Large-community\n");
13051
13052 hash_iterate(lcommunity_hash(),
13053 (void (*)(struct hash_bucket *,
13054 void *))lcommunity_show_all_iterator,
13055 vty);
13056
13057 return CMD_SUCCESS;
13058 }
13059 /* Graceful Restart */
13060
13061 static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
13062 struct bgp *bgp,
13063 bool use_json,
13064 json_object *json)
13065 {
13066
13067
13068 vty_out(vty, "\n%s", SHOW_GR_HEADER);
13069
13070 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
13071
13072 switch (bgp_global_gr_mode) {
13073
13074 case GLOBAL_HELPER:
13075 vty_out(vty, "Global BGP GR Mode : Helper\n");
13076 break;
13077
13078 case GLOBAL_GR:
13079 vty_out(vty, "Global BGP GR Mode : Restart\n");
13080 break;
13081
13082 case GLOBAL_DISABLE:
13083 vty_out(vty, "Global BGP GR Mode : Disable\n");
13084 break;
13085
13086 case GLOBAL_INVALID:
13087 vty_out(vty,
13088 "Global BGP GR Mode Invalid\n");
13089 break;
13090 }
13091 vty_out(vty, "\n");
13092 }
13093
13094 static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
13095 enum show_type type,
13096 const char *ip_str,
13097 afi_t afi, bool use_json)
13098 {
13099 if ((afi == AFI_MAX) && (ip_str == NULL)) {
13100 afi = AFI_IP;
13101
13102 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
13103
13104 bgp_show_neighbor_graceful_restart_vty(
13105 vty, type, ip_str, afi, use_json);
13106 afi++;
13107 }
13108 } else if (afi != AFI_MAX) {
13109 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
13110 use_json);
13111 } else {
13112 return CMD_ERR_INCOMPLETE;
13113 }
13114
13115 return CMD_SUCCESS;
13116 }
13117 /* Graceful Restart */
13118
13119 DEFUN (show_ip_bgp_attr_info,
13120 show_ip_bgp_attr_info_cmd,
13121 "show [ip] bgp attribute-info",
13122 SHOW_STR
13123 IP_STR
13124 BGP_STR
13125 "List all bgp attribute information\n")
13126 {
13127 attr_show_all(vty);
13128 return CMD_SUCCESS;
13129 }
13130
13131 static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
13132 afi_t afi, safi_t safi,
13133 bool use_json, json_object *json)
13134 {
13135 struct bgp *bgp;
13136 struct listnode *node;
13137 char *vname;
13138 char buf1[INET6_ADDRSTRLEN];
13139 char *ecom_str;
13140 vpn_policy_direction_t dir;
13141
13142 if (json) {
13143 json_object *json_import_vrfs = NULL;
13144 json_object *json_export_vrfs = NULL;
13145
13146 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
13147
13148 if (!bgp) {
13149 vty_out(vty, "%s\n",
13150 json_object_to_json_string_ext(
13151 json,
13152 JSON_C_TO_STRING_PRETTY));
13153 json_object_free(json);
13154
13155 return CMD_WARNING;
13156 }
13157
13158 /* Provide context for the block */
13159 json_object_string_add(json, "vrf", name ? name : "default");
13160 json_object_string_add(json, "afiSafi",
13161 get_afi_safi_str(afi, safi, true));
13162
13163 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
13164 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
13165 json_object_string_add(json, "importFromVrfs", "none");
13166 json_object_string_add(json, "importRts", "none");
13167 } else {
13168 json_import_vrfs = json_object_new_array();
13169
13170 for (ALL_LIST_ELEMENTS_RO(
13171 bgp->vpn_policy[afi].import_vrf,
13172 node, vname))
13173 json_object_array_add(json_import_vrfs,
13174 json_object_new_string(vname));
13175
13176 json_object_object_add(json, "importFromVrfs",
13177 json_import_vrfs);
13178 dir = BGP_VPN_POLICY_DIR_FROMVPN;
13179 if (bgp->vpn_policy[afi].rtlist[dir]) {
13180 ecom_str = ecommunity_ecom2str(
13181 bgp->vpn_policy[afi].rtlist[dir],
13182 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
13183 json_object_string_add(json, "importRts",
13184 ecom_str);
13185 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
13186 } else
13187 json_object_string_add(json, "importRts",
13188 "none");
13189 }
13190
13191 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
13192 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
13193 json_object_string_add(json, "exportToVrfs", "none");
13194 json_object_string_add(json, "routeDistinguisher",
13195 "none");
13196 json_object_string_add(json, "exportRts", "none");
13197 } else {
13198 json_export_vrfs = json_object_new_array();
13199
13200 for (ALL_LIST_ELEMENTS_RO(
13201 bgp->vpn_policy[afi].export_vrf,
13202 node, vname))
13203 json_object_array_add(json_export_vrfs,
13204 json_object_new_string(vname));
13205 json_object_object_add(json, "exportToVrfs",
13206 json_export_vrfs);
13207 json_object_string_add(json, "routeDistinguisher",
13208 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
13209 buf1, RD_ADDRSTRLEN));
13210
13211 dir = BGP_VPN_POLICY_DIR_TOVPN;
13212 if (bgp->vpn_policy[afi].rtlist[dir]) {
13213 ecom_str = ecommunity_ecom2str(
13214 bgp->vpn_policy[afi].rtlist[dir],
13215 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
13216 json_object_string_add(json, "exportRts",
13217 ecom_str);
13218 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
13219 } else
13220 json_object_string_add(json, "exportRts",
13221 "none");
13222 }
13223
13224 if (use_json) {
13225 vty_out(vty, "%s\n",
13226 json_object_to_json_string_ext(json,
13227 JSON_C_TO_STRING_PRETTY));
13228 json_object_free(json);
13229 }
13230 } else {
13231 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
13232
13233 if (!bgp) {
13234 vty_out(vty, "%% No such BGP instance exist\n");
13235 return CMD_WARNING;
13236 }
13237
13238 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
13239 BGP_CONFIG_VRF_TO_VRF_IMPORT))
13240 vty_out(vty,
13241 "This VRF is not importing %s routes from any other VRF\n",
13242 get_afi_safi_str(afi, safi, false));
13243 else {
13244 vty_out(vty,
13245 "This VRF is importing %s routes from the following VRFs:\n",
13246 get_afi_safi_str(afi, safi, false));
13247
13248 for (ALL_LIST_ELEMENTS_RO(
13249 bgp->vpn_policy[afi].import_vrf,
13250 node, vname))
13251 vty_out(vty, " %s\n", vname);
13252
13253 dir = BGP_VPN_POLICY_DIR_FROMVPN;
13254 ecom_str = NULL;
13255 if (bgp->vpn_policy[afi].rtlist[dir]) {
13256 ecom_str = ecommunity_ecom2str(
13257 bgp->vpn_policy[afi].rtlist[dir],
13258 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
13259 vty_out(vty, "Import RT(s): %s\n", ecom_str);
13260
13261 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
13262 } else
13263 vty_out(vty, "Import RT(s):\n");
13264 }
13265
13266 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
13267 BGP_CONFIG_VRF_TO_VRF_EXPORT))
13268 vty_out(vty,
13269 "This VRF is not exporting %s routes to any other VRF\n",
13270 get_afi_safi_str(afi, safi, false));
13271 else {
13272 vty_out(vty,
13273 "This VRF is exporting %s routes to the following VRFs:\n",
13274 get_afi_safi_str(afi, safi, false));
13275
13276 for (ALL_LIST_ELEMENTS_RO(
13277 bgp->vpn_policy[afi].export_vrf,
13278 node, vname))
13279 vty_out(vty, " %s\n", vname);
13280
13281 vty_out(vty, "RD: %s\n",
13282 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
13283 buf1, RD_ADDRSTRLEN));
13284
13285 dir = BGP_VPN_POLICY_DIR_TOVPN;
13286 if (bgp->vpn_policy[afi].rtlist[dir]) {
13287 ecom_str = ecommunity_ecom2str(
13288 bgp->vpn_policy[afi].rtlist[dir],
13289 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
13290 vty_out(vty, "Export RT: %s\n", ecom_str);
13291 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
13292 } else
13293 vty_out(vty, "Import RT(s):\n");
13294 }
13295 }
13296
13297 return CMD_SUCCESS;
13298 }
13299
13300 static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
13301 safi_t safi, bool use_json)
13302 {
13303 struct listnode *node, *nnode;
13304 struct bgp *bgp;
13305 char *vrf_name = NULL;
13306 json_object *json = NULL;
13307 json_object *json_vrf = NULL;
13308 json_object *json_vrfs = NULL;
13309
13310 if (use_json) {
13311 json = json_object_new_object();
13312 json_vrfs = json_object_new_object();
13313 }
13314
13315 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
13316
13317 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
13318 vrf_name = bgp->name;
13319
13320 if (use_json) {
13321 json_vrf = json_object_new_object();
13322 } else {
13323 vty_out(vty, "\nInstance %s:\n",
13324 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
13325 ? VRF_DEFAULT_NAME : bgp->name);
13326 }
13327 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
13328 if (use_json) {
13329 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
13330 json_object_object_add(json_vrfs,
13331 VRF_DEFAULT_NAME, json_vrf);
13332 else
13333 json_object_object_add(json_vrfs, vrf_name,
13334 json_vrf);
13335 }
13336 }
13337
13338 if (use_json) {
13339 json_object_object_add(json, "vrfs", json_vrfs);
13340 vty_out(vty, "%s\n", json_object_to_json_string_ext(json,
13341 JSON_C_TO_STRING_PRETTY));
13342 json_object_free(json);
13343 }
13344
13345 return CMD_SUCCESS;
13346 }
13347
13348 /* "show [ip] bgp route-leak" command. */
13349 DEFUN (show_ip_bgp_route_leak,
13350 show_ip_bgp_route_leak_cmd,
13351 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
13352 SHOW_STR
13353 IP_STR
13354 BGP_STR
13355 BGP_INSTANCE_HELP_STR
13356 BGP_AFI_HELP_STR
13357 BGP_SAFI_HELP_STR
13358 "Route leaking information\n"
13359 JSON_STR)
13360 {
13361 char *vrf = NULL;
13362 afi_t afi = AFI_MAX;
13363 safi_t safi = SAFI_MAX;
13364
13365 bool uj = use_json(argc, argv);
13366 int idx = 0;
13367 json_object *json = NULL;
13368
13369 /* show [ip] bgp */
13370 if (argv_find(argv, argc, "ip", &idx)) {
13371 afi = AFI_IP;
13372 safi = SAFI_UNICAST;
13373 }
13374 /* [vrf VIEWVRFNAME] */
13375 if (argv_find(argv, argc, "view", &idx)) {
13376 vty_out(vty,
13377 "%% This command is not applicable to BGP views\n");
13378 return CMD_WARNING;
13379 }
13380
13381 if (argv_find(argv, argc, "vrf", &idx)) {
13382 vrf = argv[idx + 1]->arg;
13383 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
13384 vrf = NULL;
13385 }
13386 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
13387 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
13388 argv_find_and_parse_safi(argv, argc, &idx, &safi);
13389 }
13390
13391 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
13392 vty_out(vty,
13393 "%% This command is applicable only for unicast ipv4|ipv6\n");
13394 return CMD_WARNING;
13395 }
13396
13397 if (vrf && strmatch(vrf, "all"))
13398 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
13399
13400 if (uj)
13401 json = json_object_new_object();
13402
13403 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
13404 }
13405
13406 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
13407 safi_t safi)
13408 {
13409 struct listnode *node, *nnode;
13410 struct bgp *bgp;
13411
13412 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
13413 vty_out(vty, "\nInstance %s:\n",
13414 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
13415 ? VRF_DEFAULT_NAME
13416 : bgp->name);
13417 update_group_show(bgp, afi, safi, vty, 0);
13418 }
13419 }
13420
13421 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
13422 int safi, uint64_t subgrp_id)
13423 {
13424 struct bgp *bgp;
13425
13426 if (name) {
13427 if (strmatch(name, "all")) {
13428 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
13429 return CMD_SUCCESS;
13430 } else {
13431 bgp = bgp_lookup_by_name(name);
13432 }
13433 } else {
13434 bgp = bgp_get_default();
13435 }
13436
13437 if (bgp)
13438 update_group_show(bgp, afi, safi, vty, subgrp_id);
13439 return CMD_SUCCESS;
13440 }
13441
13442 DEFUN (show_ip_bgp_updgrps,
13443 show_ip_bgp_updgrps_cmd,
13444 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
13445 SHOW_STR
13446 IP_STR
13447 BGP_STR
13448 BGP_INSTANCE_HELP_STR
13449 BGP_AFI_HELP_STR
13450 BGP_SAFI_WITH_LABEL_HELP_STR
13451 "Detailed info about dynamic update groups\n"
13452 "Specific subgroup to display detailed info for\n")
13453 {
13454 char *vrf = NULL;
13455 afi_t afi = AFI_IP6;
13456 safi_t safi = SAFI_UNICAST;
13457 uint64_t subgrp_id = 0;
13458
13459 int idx = 0;
13460
13461 /* show [ip] bgp */
13462 if (argv_find(argv, argc, "ip", &idx))
13463 afi = AFI_IP;
13464 /* [<vrf> VIEWVRFNAME] */
13465 if (argv_find(argv, argc, "vrf", &idx)) {
13466 vrf = argv[idx + 1]->arg;
13467 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
13468 vrf = NULL;
13469 } else if (argv_find(argv, argc, "view", &idx))
13470 /* [<view> VIEWVRFNAME] */
13471 vrf = argv[idx + 1]->arg;
13472 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
13473 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
13474 argv_find_and_parse_safi(argv, argc, &idx, &safi);
13475 }
13476
13477 /* get subgroup id, if provided */
13478 idx = argc - 1;
13479 if (argv[idx]->type == VARIABLE_TKN)
13480 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
13481
13482 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
13483 }
13484
13485 DEFUN (show_bgp_instance_all_ipv6_updgrps,
13486 show_bgp_instance_all_ipv6_updgrps_cmd,
13487 "show [ip] bgp <view|vrf> all update-groups",
13488 SHOW_STR
13489 IP_STR
13490 BGP_STR
13491 BGP_INSTANCE_ALL_HELP_STR
13492 "Detailed info about dynamic update groups\n")
13493 {
13494 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
13495 return CMD_SUCCESS;
13496 }
13497
13498 DEFUN (show_bgp_l2vpn_evpn_updgrps,
13499 show_bgp_l2vpn_evpn_updgrps_cmd,
13500 "show [ip] bgp l2vpn evpn update-groups",
13501 SHOW_STR
13502 IP_STR
13503 BGP_STR
13504 "l2vpn address family\n"
13505 "evpn sub-address family\n"
13506 "Detailed info about dynamic update groups\n")
13507 {
13508 char *vrf = NULL;
13509 uint64_t subgrp_id = 0;
13510
13511 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
13512 return CMD_SUCCESS;
13513 }
13514
13515 DEFUN (show_bgp_updgrps_stats,
13516 show_bgp_updgrps_stats_cmd,
13517 "show [ip] bgp update-groups statistics",
13518 SHOW_STR
13519 IP_STR
13520 BGP_STR
13521 "Detailed info about dynamic update groups\n"
13522 "Statistics\n")
13523 {
13524 struct bgp *bgp;
13525
13526 bgp = bgp_get_default();
13527 if (bgp)
13528 update_group_show_stats(bgp, vty);
13529
13530 return CMD_SUCCESS;
13531 }
13532
13533 DEFUN (show_bgp_instance_updgrps_stats,
13534 show_bgp_instance_updgrps_stats_cmd,
13535 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
13536 SHOW_STR
13537 IP_STR
13538 BGP_STR
13539 BGP_INSTANCE_HELP_STR
13540 "Detailed info about dynamic update groups\n"
13541 "Statistics\n")
13542 {
13543 int idx_word = 3;
13544 struct bgp *bgp;
13545
13546 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
13547 if (bgp)
13548 update_group_show_stats(bgp, vty);
13549
13550 return CMD_SUCCESS;
13551 }
13552
13553 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
13554 afi_t afi, safi_t safi,
13555 const char *what, uint64_t subgrp_id)
13556 {
13557 struct bgp *bgp;
13558
13559 if (name)
13560 bgp = bgp_lookup_by_name(name);
13561 else
13562 bgp = bgp_get_default();
13563
13564 if (bgp) {
13565 if (!strcmp(what, "advertise-queue"))
13566 update_group_show_adj_queue(bgp, afi, safi, vty,
13567 subgrp_id);
13568 else if (!strcmp(what, "advertised-routes"))
13569 update_group_show_advertised(bgp, afi, safi, vty,
13570 subgrp_id);
13571 else if (!strcmp(what, "packet-queue"))
13572 update_group_show_packet_queue(bgp, afi, safi, vty,
13573 subgrp_id);
13574 }
13575 }
13576
13577 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
13578 show_ip_bgp_instance_updgrps_adj_s_cmd,
13579 "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",
13580 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
13581 BGP_SAFI_HELP_STR
13582 "Detailed info about dynamic update groups\n"
13583 "Specific subgroup to display info for\n"
13584 "Advertisement queue\n"
13585 "Announced routes\n"
13586 "Packet queue\n")
13587 {
13588 uint64_t subgrp_id = 0;
13589 afi_t afiz;
13590 safi_t safiz;
13591 if (sgid)
13592 subgrp_id = strtoull(sgid, NULL, 10);
13593
13594 if (!ip && !afi)
13595 afiz = AFI_IP6;
13596 if (!ip && afi)
13597 afiz = bgp_vty_afi_from_str(afi);
13598 if (ip && !afi)
13599 afiz = AFI_IP;
13600 if (ip && afi) {
13601 afiz = bgp_vty_afi_from_str(afi);
13602 if (afiz != AFI_IP)
13603 vty_out(vty,
13604 "%% Cannot specify both 'ip' and 'ipv6'\n");
13605 return CMD_WARNING;
13606 }
13607
13608 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
13609
13610 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
13611 return CMD_SUCCESS;
13612 }
13613
13614 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
13615 {
13616 struct listnode *node, *nnode;
13617 struct prefix *range;
13618 struct peer *conf;
13619 struct peer *peer;
13620 char buf[PREFIX2STR_BUFFER];
13621 afi_t afi;
13622 safi_t safi;
13623 const char *peer_status;
13624 const char *af_str;
13625 int lr_count;
13626 int dynamic;
13627 int af_cfgd;
13628
13629 conf = group->conf;
13630
13631 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
13632 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
13633 group->name, conf->as);
13634 } else if (conf->as_type == AS_INTERNAL) {
13635 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
13636 group->name, group->bgp->as);
13637 } else {
13638 vty_out(vty, "\nBGP peer-group %s\n", group->name);
13639 }
13640
13641 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
13642 vty_out(vty, " Peer-group type is internal\n");
13643 else
13644 vty_out(vty, " Peer-group type is external\n");
13645
13646 /* Display AFs configured. */
13647 vty_out(vty, " Configured address-families:");
13648 FOREACH_AFI_SAFI (afi, safi) {
13649 if (conf->afc[afi][safi]) {
13650 af_cfgd = 1;
13651 vty_out(vty, " %s;", get_afi_safi_str(afi, safi, false));
13652 }
13653 }
13654 if (!af_cfgd)
13655 vty_out(vty, " none\n");
13656 else
13657 vty_out(vty, "\n");
13658
13659 /* Display listen ranges (for dynamic neighbors), if any */
13660 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
13661 if (afi == AFI_IP)
13662 af_str = "IPv4";
13663 else if (afi == AFI_IP6)
13664 af_str = "IPv6";
13665 else
13666 af_str = "???";
13667 lr_count = listcount(group->listen_range[afi]);
13668 if (lr_count) {
13669 vty_out(vty, " %d %s listen range(s)\n", lr_count,
13670 af_str);
13671
13672
13673 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
13674 nnode, range)) {
13675 prefix2str(range, buf, sizeof(buf));
13676 vty_out(vty, " %s\n", buf);
13677 }
13678 }
13679 }
13680
13681 /* Display group members and their status */
13682 if (listcount(group->peer)) {
13683 vty_out(vty, " Peer-group members:\n");
13684 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
13685 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
13686 || CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHUTDOWN))
13687 peer_status = "Idle (Admin)";
13688 else if (CHECK_FLAG(peer->sflags,
13689 PEER_STATUS_PREFIX_OVERFLOW))
13690 peer_status = "Idle (PfxCt)";
13691 else
13692 peer_status = lookup_msg(bgp_status_msg,
13693 peer->status, NULL);
13694
13695 dynamic = peer_dynamic_neighbor(peer);
13696 vty_out(vty, " %s %s %s \n", peer->host,
13697 dynamic ? "(dynamic)" : "", peer_status);
13698 }
13699 }
13700
13701 return CMD_SUCCESS;
13702 }
13703
13704 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
13705 const char *group_name)
13706 {
13707 struct bgp *bgp;
13708 struct listnode *node, *nnode;
13709 struct peer_group *group;
13710 bool found = false;
13711
13712 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
13713
13714 if (!bgp) {
13715 vty_out(vty, "%% BGP instance not found\n");
13716 return CMD_WARNING;
13717 }
13718
13719 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
13720 if (group_name) {
13721 if (strmatch(group->name, group_name)) {
13722 bgp_show_one_peer_group(vty, group);
13723 found = true;
13724 break;
13725 }
13726 } else {
13727 bgp_show_one_peer_group(vty, group);
13728 }
13729 }
13730
13731 if (group_name && !found)
13732 vty_out(vty, "%% No such peer-group\n");
13733
13734 return CMD_SUCCESS;
13735 }
13736
13737 DEFUN (show_ip_bgp_peer_groups,
13738 show_ip_bgp_peer_groups_cmd,
13739 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
13740 SHOW_STR
13741 IP_STR
13742 BGP_STR
13743 BGP_INSTANCE_HELP_STR
13744 "Detailed information on BGP peer groups\n"
13745 "Peer group name\n")
13746 {
13747 char *vrf, *pg;
13748 int idx = 0;
13749
13750 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
13751 : NULL;
13752 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
13753
13754 return bgp_show_peer_group_vty(vty, vrf, pg);
13755 }
13756
13757
13758 /* Redistribute VTY commands. */
13759
13760 DEFUN (bgp_redistribute_ipv4,
13761 bgp_redistribute_ipv4_cmd,
13762 "redistribute " FRR_IP_REDIST_STR_BGPD,
13763 "Redistribute information from another routing protocol\n"
13764 FRR_IP_REDIST_HELP_STR_BGPD)
13765 {
13766 VTY_DECLVAR_CONTEXT(bgp, bgp);
13767 int idx_protocol = 1;
13768 int type;
13769
13770 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
13771 if (type < 0) {
13772 vty_out(vty, "%% Invalid route type\n");
13773 return CMD_WARNING_CONFIG_FAILED;
13774 }
13775
13776 bgp_redist_add(bgp, AFI_IP, type, 0);
13777 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
13778 }
13779
13780 ALIAS_HIDDEN(
13781 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
13782 "redistribute " FRR_IP_REDIST_STR_BGPD,
13783 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
13784
13785 DEFUN (bgp_redistribute_ipv4_rmap,
13786 bgp_redistribute_ipv4_rmap_cmd,
13787 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
13788 "Redistribute information from another routing protocol\n"
13789 FRR_IP_REDIST_HELP_STR_BGPD
13790 "Route map reference\n"
13791 "Pointer to route-map entries\n")
13792 {
13793 VTY_DECLVAR_CONTEXT(bgp, bgp);
13794 int idx_protocol = 1;
13795 int idx_word = 3;
13796 int type;
13797 struct bgp_redist *red;
13798 bool changed;
13799 struct route_map *route_map = route_map_lookup_warn_noexist(
13800 vty, argv[idx_word]->arg);
13801
13802 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
13803 if (type < 0) {
13804 vty_out(vty, "%% Invalid route type\n");
13805 return CMD_WARNING_CONFIG_FAILED;
13806 }
13807
13808 red = bgp_redist_add(bgp, AFI_IP, type, 0);
13809 changed =
13810 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
13811 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
13812 }
13813
13814 ALIAS_HIDDEN(
13815 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
13816 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
13817 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
13818 "Route map reference\n"
13819 "Pointer to route-map entries\n")
13820
13821 DEFUN (bgp_redistribute_ipv4_metric,
13822 bgp_redistribute_ipv4_metric_cmd,
13823 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
13824 "Redistribute information from another routing protocol\n"
13825 FRR_IP_REDIST_HELP_STR_BGPD
13826 "Metric for redistributed routes\n"
13827 "Default metric\n")
13828 {
13829 VTY_DECLVAR_CONTEXT(bgp, bgp);
13830 int idx_protocol = 1;
13831 int idx_number = 3;
13832 int type;
13833 uint32_t metric;
13834 struct bgp_redist *red;
13835 bool changed;
13836
13837 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
13838 if (type < 0) {
13839 vty_out(vty, "%% Invalid route type\n");
13840 return CMD_WARNING_CONFIG_FAILED;
13841 }
13842 metric = strtoul(argv[idx_number]->arg, NULL, 10);
13843
13844 red = bgp_redist_add(bgp, AFI_IP, type, 0);
13845 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
13846 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
13847 }
13848
13849 ALIAS_HIDDEN(
13850 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
13851 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
13852 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
13853 "Metric for redistributed routes\n"
13854 "Default metric\n")
13855
13856 DEFUN (bgp_redistribute_ipv4_rmap_metric,
13857 bgp_redistribute_ipv4_rmap_metric_cmd,
13858 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
13859 "Redistribute information from another routing protocol\n"
13860 FRR_IP_REDIST_HELP_STR_BGPD
13861 "Route map reference\n"
13862 "Pointer to route-map entries\n"
13863 "Metric for redistributed routes\n"
13864 "Default metric\n")
13865 {
13866 VTY_DECLVAR_CONTEXT(bgp, bgp);
13867 int idx_protocol = 1;
13868 int idx_word = 3;
13869 int idx_number = 5;
13870 int type;
13871 uint32_t metric;
13872 struct bgp_redist *red;
13873 bool changed;
13874 struct route_map *route_map =
13875 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
13876
13877 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
13878 if (type < 0) {
13879 vty_out(vty, "%% Invalid route type\n");
13880 return CMD_WARNING_CONFIG_FAILED;
13881 }
13882 metric = strtoul(argv[idx_number]->arg, NULL, 10);
13883
13884 red = bgp_redist_add(bgp, AFI_IP, type, 0);
13885 changed =
13886 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
13887 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
13888 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
13889 }
13890
13891 ALIAS_HIDDEN(
13892 bgp_redistribute_ipv4_rmap_metric,
13893 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
13894 "redistribute " FRR_IP_REDIST_STR_BGPD
13895 " route-map WORD metric (0-4294967295)",
13896 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
13897 "Route map reference\n"
13898 "Pointer to route-map entries\n"
13899 "Metric for redistributed routes\n"
13900 "Default metric\n")
13901
13902 DEFUN (bgp_redistribute_ipv4_metric_rmap,
13903 bgp_redistribute_ipv4_metric_rmap_cmd,
13904 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
13905 "Redistribute information from another routing protocol\n"
13906 FRR_IP_REDIST_HELP_STR_BGPD
13907 "Metric for redistributed routes\n"
13908 "Default metric\n"
13909 "Route map reference\n"
13910 "Pointer to route-map entries\n")
13911 {
13912 VTY_DECLVAR_CONTEXT(bgp, bgp);
13913 int idx_protocol = 1;
13914 int idx_number = 3;
13915 int idx_word = 5;
13916 int type;
13917 uint32_t metric;
13918 struct bgp_redist *red;
13919 bool changed;
13920 struct route_map *route_map =
13921 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
13922
13923 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
13924 if (type < 0) {
13925 vty_out(vty, "%% Invalid route type\n");
13926 return CMD_WARNING_CONFIG_FAILED;
13927 }
13928 metric = strtoul(argv[idx_number]->arg, NULL, 10);
13929
13930 red = bgp_redist_add(bgp, AFI_IP, type, 0);
13931 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
13932 changed |=
13933 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
13934 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
13935 }
13936
13937 ALIAS_HIDDEN(
13938 bgp_redistribute_ipv4_metric_rmap,
13939 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
13940 "redistribute " FRR_IP_REDIST_STR_BGPD
13941 " metric (0-4294967295) route-map WORD",
13942 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
13943 "Metric for redistributed routes\n"
13944 "Default metric\n"
13945 "Route map reference\n"
13946 "Pointer to route-map entries\n")
13947
13948 DEFUN (bgp_redistribute_ipv4_ospf,
13949 bgp_redistribute_ipv4_ospf_cmd,
13950 "redistribute <ospf|table> (1-65535)",
13951 "Redistribute information from another routing protocol\n"
13952 "Open Shortest Path First (OSPFv2)\n"
13953 "Non-main Kernel Routing Table\n"
13954 "Instance ID/Table ID\n")
13955 {
13956 VTY_DECLVAR_CONTEXT(bgp, bgp);
13957 int idx_ospf_table = 1;
13958 int idx_number = 2;
13959 unsigned short instance;
13960 unsigned short protocol;
13961
13962 instance = strtoul(argv[idx_number]->arg, NULL, 10);
13963
13964 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
13965 protocol = ZEBRA_ROUTE_OSPF;
13966 else
13967 protocol = ZEBRA_ROUTE_TABLE;
13968
13969 bgp_redist_add(bgp, AFI_IP, protocol, instance);
13970 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
13971 }
13972
13973 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
13974 "redistribute <ospf|table> (1-65535)",
13975 "Redistribute information from another routing protocol\n"
13976 "Open Shortest Path First (OSPFv2)\n"
13977 "Non-main Kernel Routing Table\n"
13978 "Instance ID/Table ID\n")
13979
13980 DEFUN (bgp_redistribute_ipv4_ospf_rmap,
13981 bgp_redistribute_ipv4_ospf_rmap_cmd,
13982 "redistribute <ospf|table> (1-65535) route-map WORD",
13983 "Redistribute information from another routing protocol\n"
13984 "Open Shortest Path First (OSPFv2)\n"
13985 "Non-main Kernel Routing Table\n"
13986 "Instance ID/Table ID\n"
13987 "Route map reference\n"
13988 "Pointer to route-map entries\n")
13989 {
13990 VTY_DECLVAR_CONTEXT(bgp, bgp);
13991 int idx_ospf_table = 1;
13992 int idx_number = 2;
13993 int idx_word = 4;
13994 struct bgp_redist *red;
13995 unsigned short instance;
13996 int protocol;
13997 bool changed;
13998 struct route_map *route_map =
13999 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
14000
14001 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
14002 protocol = ZEBRA_ROUTE_OSPF;
14003 else
14004 protocol = ZEBRA_ROUTE_TABLE;
14005
14006 instance = strtoul(argv[idx_number]->arg, NULL, 10);
14007 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
14008 changed =
14009 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
14010 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
14011 }
14012
14013 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
14014 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
14015 "redistribute <ospf|table> (1-65535) route-map WORD",
14016 "Redistribute information from another routing protocol\n"
14017 "Open Shortest Path First (OSPFv2)\n"
14018 "Non-main Kernel Routing Table\n"
14019 "Instance ID/Table ID\n"
14020 "Route map reference\n"
14021 "Pointer to route-map entries\n")
14022
14023 DEFUN (bgp_redistribute_ipv4_ospf_metric,
14024 bgp_redistribute_ipv4_ospf_metric_cmd,
14025 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
14026 "Redistribute information from another routing protocol\n"
14027 "Open Shortest Path First (OSPFv2)\n"
14028 "Non-main Kernel Routing Table\n"
14029 "Instance ID/Table ID\n"
14030 "Metric for redistributed routes\n"
14031 "Default metric\n")
14032 {
14033 VTY_DECLVAR_CONTEXT(bgp, bgp);
14034 int idx_ospf_table = 1;
14035 int idx_number = 2;
14036 int idx_number_2 = 4;
14037 uint32_t metric;
14038 struct bgp_redist *red;
14039 unsigned short instance;
14040 int protocol;
14041 bool changed;
14042
14043 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
14044 protocol = ZEBRA_ROUTE_OSPF;
14045 else
14046 protocol = ZEBRA_ROUTE_TABLE;
14047
14048 instance = strtoul(argv[idx_number]->arg, NULL, 10);
14049 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
14050
14051 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
14052 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
14053 metric);
14054 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
14055 }
14056
14057 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
14058 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
14059 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
14060 "Redistribute information from another routing protocol\n"
14061 "Open Shortest Path First (OSPFv2)\n"
14062 "Non-main Kernel Routing Table\n"
14063 "Instance ID/Table ID\n"
14064 "Metric for redistributed routes\n"
14065 "Default metric\n")
14066
14067 DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
14068 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
14069 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
14070 "Redistribute information from another routing protocol\n"
14071 "Open Shortest Path First (OSPFv2)\n"
14072 "Non-main Kernel Routing Table\n"
14073 "Instance ID/Table ID\n"
14074 "Route map reference\n"
14075 "Pointer to route-map entries\n"
14076 "Metric for redistributed routes\n"
14077 "Default metric\n")
14078 {
14079 VTY_DECLVAR_CONTEXT(bgp, bgp);
14080 int idx_ospf_table = 1;
14081 int idx_number = 2;
14082 int idx_word = 4;
14083 int idx_number_2 = 6;
14084 uint32_t metric;
14085 struct bgp_redist *red;
14086 unsigned short instance;
14087 int protocol;
14088 bool changed;
14089 struct route_map *route_map =
14090 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
14091
14092 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
14093 protocol = ZEBRA_ROUTE_OSPF;
14094 else
14095 protocol = ZEBRA_ROUTE_TABLE;
14096
14097 instance = strtoul(argv[idx_number]->arg, NULL, 10);
14098 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
14099
14100 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
14101 changed =
14102 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
14103 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
14104 metric);
14105 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
14106 }
14107
14108 ALIAS_HIDDEN(
14109 bgp_redistribute_ipv4_ospf_rmap_metric,
14110 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
14111 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
14112 "Redistribute information from another routing protocol\n"
14113 "Open Shortest Path First (OSPFv2)\n"
14114 "Non-main Kernel Routing Table\n"
14115 "Instance ID/Table ID\n"
14116 "Route map reference\n"
14117 "Pointer to route-map entries\n"
14118 "Metric for redistributed routes\n"
14119 "Default metric\n")
14120
14121 DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
14122 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
14123 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
14124 "Redistribute information from another routing protocol\n"
14125 "Open Shortest Path First (OSPFv2)\n"
14126 "Non-main Kernel Routing Table\n"
14127 "Instance ID/Table ID\n"
14128 "Metric for redistributed routes\n"
14129 "Default metric\n"
14130 "Route map reference\n"
14131 "Pointer to route-map entries\n")
14132 {
14133 VTY_DECLVAR_CONTEXT(bgp, bgp);
14134 int idx_ospf_table = 1;
14135 int idx_number = 2;
14136 int idx_number_2 = 4;
14137 int idx_word = 6;
14138 uint32_t metric;
14139 struct bgp_redist *red;
14140 unsigned short instance;
14141 int protocol;
14142 bool changed;
14143 struct route_map *route_map =
14144 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
14145
14146 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
14147 protocol = ZEBRA_ROUTE_OSPF;
14148 else
14149 protocol = ZEBRA_ROUTE_TABLE;
14150
14151 instance = strtoul(argv[idx_number]->arg, NULL, 10);
14152 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
14153
14154 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
14155 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
14156 metric);
14157 changed |=
14158 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
14159 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
14160 }
14161
14162 ALIAS_HIDDEN(
14163 bgp_redistribute_ipv4_ospf_metric_rmap,
14164 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
14165 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
14166 "Redistribute information from another routing protocol\n"
14167 "Open Shortest Path First (OSPFv2)\n"
14168 "Non-main Kernel Routing Table\n"
14169 "Instance ID/Table ID\n"
14170 "Metric for redistributed routes\n"
14171 "Default metric\n"
14172 "Route map reference\n"
14173 "Pointer to route-map entries\n")
14174
14175 DEFUN (no_bgp_redistribute_ipv4_ospf,
14176 no_bgp_redistribute_ipv4_ospf_cmd,
14177 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
14178 NO_STR
14179 "Redistribute information from another routing protocol\n"
14180 "Open Shortest Path First (OSPFv2)\n"
14181 "Non-main Kernel Routing Table\n"
14182 "Instance ID/Table ID\n"
14183 "Metric for redistributed routes\n"
14184 "Default metric\n"
14185 "Route map reference\n"
14186 "Pointer to route-map entries\n")
14187 {
14188 VTY_DECLVAR_CONTEXT(bgp, bgp);
14189 int idx_ospf_table = 2;
14190 int idx_number = 3;
14191 unsigned short instance;
14192 int protocol;
14193
14194 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
14195 protocol = ZEBRA_ROUTE_OSPF;
14196 else
14197 protocol = ZEBRA_ROUTE_TABLE;
14198
14199 instance = strtoul(argv[idx_number]->arg, NULL, 10);
14200 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
14201 }
14202
14203 ALIAS_HIDDEN(
14204 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
14205 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
14206 NO_STR
14207 "Redistribute information from another routing protocol\n"
14208 "Open Shortest Path First (OSPFv2)\n"
14209 "Non-main Kernel Routing Table\n"
14210 "Instance ID/Table ID\n"
14211 "Metric for redistributed routes\n"
14212 "Default metric\n"
14213 "Route map reference\n"
14214 "Pointer to route-map entries\n")
14215
14216 DEFUN (no_bgp_redistribute_ipv4,
14217 no_bgp_redistribute_ipv4_cmd,
14218 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
14219 NO_STR
14220 "Redistribute information from another routing protocol\n"
14221 FRR_IP_REDIST_HELP_STR_BGPD
14222 "Metric for redistributed routes\n"
14223 "Default metric\n"
14224 "Route map reference\n"
14225 "Pointer to route-map entries\n")
14226 {
14227 VTY_DECLVAR_CONTEXT(bgp, bgp);
14228 int idx_protocol = 2;
14229 int type;
14230
14231 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
14232 if (type < 0) {
14233 vty_out(vty, "%% Invalid route type\n");
14234 return CMD_WARNING_CONFIG_FAILED;
14235 }
14236 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
14237 }
14238
14239 ALIAS_HIDDEN(
14240 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
14241 "no redistribute " FRR_IP_REDIST_STR_BGPD
14242 " [{metric (0-4294967295)|route-map WORD}]",
14243 NO_STR
14244 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
14245 "Metric for redistributed routes\n"
14246 "Default metric\n"
14247 "Route map reference\n"
14248 "Pointer to route-map entries\n")
14249
14250 DEFUN (bgp_redistribute_ipv6,
14251 bgp_redistribute_ipv6_cmd,
14252 "redistribute " FRR_IP6_REDIST_STR_BGPD,
14253 "Redistribute information from another routing protocol\n"
14254 FRR_IP6_REDIST_HELP_STR_BGPD)
14255 {
14256 VTY_DECLVAR_CONTEXT(bgp, bgp);
14257 int idx_protocol = 1;
14258 int type;
14259
14260 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
14261 if (type < 0) {
14262 vty_out(vty, "%% Invalid route type\n");
14263 return CMD_WARNING_CONFIG_FAILED;
14264 }
14265
14266 bgp_redist_add(bgp, AFI_IP6, type, 0);
14267 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
14268 }
14269
14270 DEFUN (bgp_redistribute_ipv6_rmap,
14271 bgp_redistribute_ipv6_rmap_cmd,
14272 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
14273 "Redistribute information from another routing protocol\n"
14274 FRR_IP6_REDIST_HELP_STR_BGPD
14275 "Route map reference\n"
14276 "Pointer to route-map entries\n")
14277 {
14278 VTY_DECLVAR_CONTEXT(bgp, bgp);
14279 int idx_protocol = 1;
14280 int idx_word = 3;
14281 int type;
14282 struct bgp_redist *red;
14283 bool changed;
14284 struct route_map *route_map =
14285 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
14286
14287 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
14288 if (type < 0) {
14289 vty_out(vty, "%% Invalid route type\n");
14290 return CMD_WARNING_CONFIG_FAILED;
14291 }
14292
14293 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
14294 changed =
14295 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
14296 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
14297 }
14298
14299 DEFUN (bgp_redistribute_ipv6_metric,
14300 bgp_redistribute_ipv6_metric_cmd,
14301 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
14302 "Redistribute information from another routing protocol\n"
14303 FRR_IP6_REDIST_HELP_STR_BGPD
14304 "Metric for redistributed routes\n"
14305 "Default metric\n")
14306 {
14307 VTY_DECLVAR_CONTEXT(bgp, bgp);
14308 int idx_protocol = 1;
14309 int idx_number = 3;
14310 int type;
14311 uint32_t metric;
14312 struct bgp_redist *red;
14313 bool changed;
14314
14315 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
14316 if (type < 0) {
14317 vty_out(vty, "%% Invalid route type\n");
14318 return CMD_WARNING_CONFIG_FAILED;
14319 }
14320 metric = strtoul(argv[idx_number]->arg, NULL, 10);
14321
14322 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
14323 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
14324 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
14325 }
14326
14327 DEFUN (bgp_redistribute_ipv6_rmap_metric,
14328 bgp_redistribute_ipv6_rmap_metric_cmd,
14329 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
14330 "Redistribute information from another routing protocol\n"
14331 FRR_IP6_REDIST_HELP_STR_BGPD
14332 "Route map reference\n"
14333 "Pointer to route-map entries\n"
14334 "Metric for redistributed routes\n"
14335 "Default metric\n")
14336 {
14337 VTY_DECLVAR_CONTEXT(bgp, bgp);
14338 int idx_protocol = 1;
14339 int idx_word = 3;
14340 int idx_number = 5;
14341 int type;
14342 uint32_t metric;
14343 struct bgp_redist *red;
14344 bool changed;
14345 struct route_map *route_map =
14346 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
14347
14348 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
14349 if (type < 0) {
14350 vty_out(vty, "%% Invalid route type\n");
14351 return CMD_WARNING_CONFIG_FAILED;
14352 }
14353 metric = strtoul(argv[idx_number]->arg, NULL, 10);
14354
14355 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
14356 changed =
14357 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
14358 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
14359 metric);
14360 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
14361 }
14362
14363 DEFUN (bgp_redistribute_ipv6_metric_rmap,
14364 bgp_redistribute_ipv6_metric_rmap_cmd,
14365 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
14366 "Redistribute information from another routing protocol\n"
14367 FRR_IP6_REDIST_HELP_STR_BGPD
14368 "Metric for redistributed routes\n"
14369 "Default metric\n"
14370 "Route map reference\n"
14371 "Pointer to route-map entries\n")
14372 {
14373 VTY_DECLVAR_CONTEXT(bgp, bgp);
14374 int idx_protocol = 1;
14375 int idx_number = 3;
14376 int idx_word = 5;
14377 int type;
14378 uint32_t metric;
14379 struct bgp_redist *red;
14380 bool changed;
14381 struct route_map *route_map =
14382 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
14383
14384 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
14385 if (type < 0) {
14386 vty_out(vty, "%% Invalid route type\n");
14387 return CMD_WARNING_CONFIG_FAILED;
14388 }
14389 metric = strtoul(argv[idx_number]->arg, NULL, 10);
14390
14391 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
14392 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
14393 metric);
14394 changed |=
14395 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
14396 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
14397 }
14398
14399 DEFUN (no_bgp_redistribute_ipv6,
14400 no_bgp_redistribute_ipv6_cmd,
14401 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
14402 NO_STR
14403 "Redistribute information from another routing protocol\n"
14404 FRR_IP6_REDIST_HELP_STR_BGPD
14405 "Metric for redistributed routes\n"
14406 "Default metric\n"
14407 "Route map reference\n"
14408 "Pointer to route-map entries\n")
14409 {
14410 VTY_DECLVAR_CONTEXT(bgp, bgp);
14411 int idx_protocol = 2;
14412 int type;
14413
14414 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
14415 if (type < 0) {
14416 vty_out(vty, "%% Invalid route type\n");
14417 return CMD_WARNING_CONFIG_FAILED;
14418 }
14419
14420 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
14421 }
14422
14423 static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
14424 afi_t afi, safi_t safi)
14425 {
14426 int i;
14427
14428 /* Unicast redistribution only. */
14429 if (safi != SAFI_UNICAST)
14430 return;
14431
14432 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
14433 /* Redistribute BGP does not make sense. */
14434 if (i != ZEBRA_ROUTE_BGP) {
14435 struct list *red_list;
14436 struct listnode *node;
14437 struct bgp_redist *red;
14438
14439 red_list = bgp->redist[afi][i];
14440 if (!red_list)
14441 continue;
14442
14443 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
14444 /* "redistribute" configuration. */
14445 vty_out(vty, " redistribute %s",
14446 zebra_route_string(i));
14447 if (red->instance)
14448 vty_out(vty, " %d", red->instance);
14449 if (red->redist_metric_flag)
14450 vty_out(vty, " metric %u",
14451 red->redist_metric);
14452 if (red->rmap.name)
14453 vty_out(vty, " route-map %s",
14454 red->rmap.name);
14455 vty_out(vty, "\n");
14456 }
14457 }
14458 }
14459 }
14460
14461 /* peer-group helpers for config-write */
14462
14463 static bool peergroup_flag_check(struct peer *peer, uint32_t flag)
14464 {
14465 if (!peer_group_active(peer)) {
14466 if (CHECK_FLAG(peer->flags_invert, flag))
14467 return !CHECK_FLAG(peer->flags, flag);
14468 else
14469 return !!CHECK_FLAG(peer->flags, flag);
14470 }
14471
14472 return !!CHECK_FLAG(peer->flags_override, flag);
14473 }
14474
14475 static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
14476 uint32_t flag)
14477 {
14478 if (!peer_group_active(peer)) {
14479 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
14480 return !peer_af_flag_check(peer, afi, safi, flag);
14481 else
14482 return !!peer_af_flag_check(peer, afi, safi, flag);
14483 }
14484
14485 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
14486 }
14487
14488 static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
14489 uint8_t type, int direct)
14490 {
14491 struct bgp_filter *filter;
14492
14493 if (peer_group_active(peer))
14494 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
14495 type);
14496
14497 filter = &peer->filter[afi][safi];
14498 switch (type) {
14499 case PEER_FT_DISTRIBUTE_LIST:
14500 return !!(filter->dlist[direct].name);
14501 case PEER_FT_FILTER_LIST:
14502 return !!(filter->aslist[direct].name);
14503 case PEER_FT_PREFIX_LIST:
14504 return !!(filter->plist[direct].name);
14505 case PEER_FT_ROUTE_MAP:
14506 return !!(filter->map[direct].name);
14507 case PEER_FT_UNSUPPRESS_MAP:
14508 return !!(filter->usmap.name);
14509 default:
14510 return false;
14511 }
14512 }
14513
14514 /* Return true if the addpath type is set for peer and different from
14515 * peer-group.
14516 */
14517 static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi,
14518 safi_t safi)
14519 {
14520 enum bgp_addpath_strat type, g_type;
14521
14522 type = peer->addpath_type[afi][safi];
14523
14524 if (type != BGP_ADDPATH_NONE) {
14525 if (peer_group_active(peer)) {
14526 g_type = peer->group->conf->addpath_type[afi][safi];
14527
14528 if (type != g_type)
14529 return true;
14530 else
14531 return false;
14532 }
14533
14534 return true;
14535 }
14536
14537 return false;
14538 }
14539
14540 /* This is part of the address-family block (unicast only) */
14541 static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
14542 afi_t afi)
14543 {
14544 int indent = 2;
14545
14546 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
14547 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
14548 BGP_CONFIG_VRF_TO_VRF_IMPORT))
14549 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
14550 bgp->vpn_policy[afi]
14551 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
14552 else
14553 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
14554 bgp->vpn_policy[afi]
14555 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
14556 }
14557 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
14558 BGP_CONFIG_VRF_TO_VRF_IMPORT)
14559 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
14560 BGP_CONFIG_VRF_TO_VRF_EXPORT))
14561 return;
14562
14563 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
14564 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
14565
14566 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
14567
14568 } else {
14569 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
14570 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
14571 bgp->vpn_policy[afi].tovpn_label);
14572 }
14573 }
14574 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
14575 BGP_VPN_POLICY_TOVPN_RD_SET)) {
14576 char buf[RD_ADDRSTRLEN];
14577 vty_out(vty, "%*srd vpn export %s\n", indent, "",
14578 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
14579 sizeof(buf)));
14580 }
14581 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
14582 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
14583
14584 char buf[PREFIX_STRLEN];
14585 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
14586 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
14587 sizeof(buf))) {
14588
14589 vty_out(vty, "%*snexthop vpn export %s\n",
14590 indent, "", buf);
14591 }
14592 }
14593 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
14594 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
14595 && ecommunity_cmp(
14596 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
14597 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
14598
14599 char *b = ecommunity_ecom2str(
14600 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
14601 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
14602 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
14603 XFREE(MTYPE_ECOMMUNITY_STR, b);
14604 } else {
14605 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
14606 char *b = ecommunity_ecom2str(
14607 bgp->vpn_policy[afi]
14608 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
14609 ECOMMUNITY_FORMAT_ROUTE_MAP,
14610 ECOMMUNITY_ROUTE_TARGET);
14611 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
14612 XFREE(MTYPE_ECOMMUNITY_STR, b);
14613 }
14614 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
14615 char *b = ecommunity_ecom2str(
14616 bgp->vpn_policy[afi]
14617 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
14618 ECOMMUNITY_FORMAT_ROUTE_MAP,
14619 ECOMMUNITY_ROUTE_TARGET);
14620 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
14621 XFREE(MTYPE_ECOMMUNITY_STR, b);
14622 }
14623 }
14624
14625 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
14626 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
14627 bgp->vpn_policy[afi]
14628 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
14629
14630 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
14631 char *b = ecommunity_ecom2str(
14632 bgp->vpn_policy[afi]
14633 .import_redirect_rtlist,
14634 ECOMMUNITY_FORMAT_ROUTE_MAP,
14635 ECOMMUNITY_ROUTE_TARGET);
14636
14637 vty_out(vty, "%*srt redirect import %s\n", indent, "", b);
14638 XFREE(MTYPE_ECOMMUNITY_STR, b);
14639 }
14640 }
14641
14642 static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
14643 afi_t afi, safi_t safi)
14644 {
14645 struct bgp_filter *filter;
14646 char *addr;
14647
14648 addr = peer->host;
14649 filter = &peer->filter[afi][safi];
14650
14651 /* distribute-list. */
14652 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
14653 FILTER_IN))
14654 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
14655 filter->dlist[FILTER_IN].name);
14656
14657 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
14658 FILTER_OUT))
14659 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
14660 filter->dlist[FILTER_OUT].name);
14661
14662 /* prefix-list. */
14663 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
14664 FILTER_IN))
14665 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
14666 filter->plist[FILTER_IN].name);
14667
14668 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
14669 FILTER_OUT))
14670 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
14671 filter->plist[FILTER_OUT].name);
14672
14673 /* route-map. */
14674 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
14675 vty_out(vty, " neighbor %s route-map %s in\n", addr,
14676 filter->map[RMAP_IN].name);
14677
14678 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
14679 RMAP_OUT))
14680 vty_out(vty, " neighbor %s route-map %s out\n", addr,
14681 filter->map[RMAP_OUT].name);
14682
14683 /* unsuppress-map */
14684 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
14685 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
14686 filter->usmap.name);
14687
14688 /* filter-list. */
14689 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
14690 FILTER_IN))
14691 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
14692 filter->aslist[FILTER_IN].name);
14693
14694 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
14695 FILTER_OUT))
14696 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
14697 filter->aslist[FILTER_OUT].name);
14698 }
14699
14700 /* BGP peer configuration display function. */
14701 static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
14702 struct peer *peer)
14703 {
14704 struct peer *g_peer = NULL;
14705 char buf[SU_ADDRSTRLEN];
14706 char *addr;
14707 int if_pg_printed = false;
14708 int if_ras_printed = false;
14709
14710 /* Skip dynamic neighbors. */
14711 if (peer_dynamic_neighbor(peer))
14712 return;
14713
14714 if (peer->conf_if)
14715 addr = peer->conf_if;
14716 else
14717 addr = peer->host;
14718
14719 /************************************
14720 ****** Global to the neighbor ******
14721 ************************************/
14722 if (peer->conf_if) {
14723 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
14724 vty_out(vty, " neighbor %s interface v6only", addr);
14725 else
14726 vty_out(vty, " neighbor %s interface", addr);
14727
14728 if (peer_group_active(peer)) {
14729 vty_out(vty, " peer-group %s", peer->group->name);
14730 if_pg_printed = true;
14731 } else if (peer->as_type == AS_SPECIFIED) {
14732 vty_out(vty, " remote-as %u", peer->as);
14733 if_ras_printed = true;
14734 } else if (peer->as_type == AS_INTERNAL) {
14735 vty_out(vty, " remote-as internal");
14736 if_ras_printed = true;
14737 } else if (peer->as_type == AS_EXTERNAL) {
14738 vty_out(vty, " remote-as external");
14739 if_ras_printed = true;
14740 }
14741
14742 vty_out(vty, "\n");
14743 }
14744
14745 /* remote-as and peer-group */
14746 /* peer is a member of a peer-group */
14747 if (peer_group_active(peer)) {
14748 g_peer = peer->group->conf;
14749
14750 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
14751 if (peer->as_type == AS_SPECIFIED) {
14752 vty_out(vty, " neighbor %s remote-as %u\n",
14753 addr, peer->as);
14754 } else if (peer->as_type == AS_INTERNAL) {
14755 vty_out(vty,
14756 " neighbor %s remote-as internal\n",
14757 addr);
14758 } else if (peer->as_type == AS_EXTERNAL) {
14759 vty_out(vty,
14760 " neighbor %s remote-as external\n",
14761 addr);
14762 }
14763 }
14764
14765 /* For swpX peers we displayed the peer-group
14766 * via 'neighbor swpX interface peer-group PGNAME' */
14767 if (!if_pg_printed)
14768 vty_out(vty, " neighbor %s peer-group %s\n", addr,
14769 peer->group->name);
14770 }
14771
14772 /* peer is NOT a member of a peer-group */
14773 else {
14774 /* peer is a peer-group, declare the peer-group */
14775 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
14776 vty_out(vty, " neighbor %s peer-group\n", addr);
14777 }
14778
14779 if (!if_ras_printed) {
14780 if (peer->as_type == AS_SPECIFIED) {
14781 vty_out(vty, " neighbor %s remote-as %u\n",
14782 addr, peer->as);
14783 } else if (peer->as_type == AS_INTERNAL) {
14784 vty_out(vty,
14785 " neighbor %s remote-as internal\n",
14786 addr);
14787 } else if (peer->as_type == AS_EXTERNAL) {
14788 vty_out(vty,
14789 " neighbor %s remote-as external\n",
14790 addr);
14791 }
14792 }
14793 }
14794
14795 /* local-as */
14796 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
14797 vty_out(vty, " neighbor %s local-as %u", addr,
14798 peer->change_local_as);
14799 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
14800 vty_out(vty, " no-prepend");
14801 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
14802 vty_out(vty, " replace-as");
14803 vty_out(vty, "\n");
14804 }
14805
14806 /* description */
14807 if (peer->desc) {
14808 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
14809 }
14810
14811 /* shutdown */
14812 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
14813 if (peer->tx_shutdown_message)
14814 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
14815 peer->tx_shutdown_message);
14816 else
14817 vty_out(vty, " neighbor %s shutdown\n", addr);
14818 }
14819
14820 /* bfd */
14821 if (peer->bfd_info) {
14822 if (!peer_group_active(peer) || !g_peer->bfd_info) {
14823 bgp_bfd_peer_config_write(vty, peer, addr);
14824 }
14825 }
14826
14827 /* password */
14828 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
14829 vty_out(vty, " neighbor %s password %s\n", addr,
14830 peer->password);
14831
14832 /* neighbor solo */
14833 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
14834 if (!peer_group_active(peer)) {
14835 vty_out(vty, " neighbor %s solo\n", addr);
14836 }
14837 }
14838
14839 /* BGP port */
14840 if (peer->port != BGP_PORT_DEFAULT) {
14841 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
14842 }
14843
14844 /* Local interface name */
14845 if (peer->ifname) {
14846 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
14847 }
14848
14849 /* passive */
14850 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
14851 vty_out(vty, " neighbor %s passive\n", addr);
14852
14853 /* ebgp-multihop */
14854 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
14855 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
14856 && peer->ttl == MAXTTL)) {
14857 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
14858 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
14859 peer->ttl);
14860 }
14861 }
14862
14863 /* ttl-security hops */
14864 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
14865 if (!peer_group_active(peer)
14866 || g_peer->gtsm_hops != peer->gtsm_hops) {
14867 vty_out(vty, " neighbor %s ttl-security hops %d\n",
14868 addr, peer->gtsm_hops);
14869 }
14870 }
14871
14872 /* disable-connected-check */
14873 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
14874 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
14875
14876 /* enforce-first-as */
14877 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
14878 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
14879
14880 /* update-source */
14881 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
14882 if (peer->update_source)
14883 vty_out(vty, " neighbor %s update-source %s\n", addr,
14884 sockunion2str(peer->update_source, buf,
14885 SU_ADDRSTRLEN));
14886 else if (peer->update_if)
14887 vty_out(vty, " neighbor %s update-source %s\n", addr,
14888 peer->update_if);
14889 }
14890
14891 /* advertisement-interval */
14892 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
14893 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
14894 peer->routeadv);
14895
14896 /* timers */
14897 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
14898 vty_out(vty, " neighbor %s timers %u %u\n", addr,
14899 peer->keepalive, peer->holdtime);
14900
14901 /* timers connect */
14902 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
14903 vty_out(vty, " neighbor %s timers connect %u\n", addr,
14904 peer->connect);
14905 /* need special-case handling for changed default values due to
14906 * config profile / version (because there is no "timers bgp connect"
14907 * command, we need to save this per-peer :/)
14908 */
14909 else if (!peer_group_active(peer) && !peer->connect &&
14910 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
14911 vty_out(vty, " neighbor %s timers connect %u\n", addr,
14912 peer->bgp->default_connect_retry);
14913
14914 /* capability dynamic */
14915 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
14916 vty_out(vty, " neighbor %s capability dynamic\n", addr);
14917
14918 /* capability extended-nexthop */
14919 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
14920 if (!peer->conf_if) {
14921 if (CHECK_FLAG(peer->flags_invert,
14922 PEER_FLAG_CAPABILITY_ENHE))
14923 vty_out(vty,
14924 " no neighbor %s capability extended-nexthop\n",
14925 addr);
14926 else
14927 vty_out(vty,
14928 " neighbor %s capability extended-nexthop\n",
14929 addr);
14930 }
14931 }
14932
14933 /* dont-capability-negotiation */
14934 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
14935 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
14936
14937 /* override-capability */
14938 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
14939 vty_out(vty, " neighbor %s override-capability\n", addr);
14940
14941 /* strict-capability-match */
14942 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
14943 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
14944
14945 /* Sender side AS path loop detection. */
14946 if (peer->as_path_loop_detection)
14947 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
14948 addr);
14949
14950 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
14951 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
14952
14953 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
14954 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
14955 vty_out(vty,
14956 " neighbor %s graceful-restart-helper\n", addr);
14957 } else if (CHECK_FLAG(
14958 peer->peer_gr_new_status_flag,
14959 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
14960 vty_out(vty,
14961 " neighbor %s graceful-restart\n", addr);
14962 } else if (
14963 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
14964 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
14965 && !(CHECK_FLAG(
14966 peer->peer_gr_new_status_flag,
14967 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
14968 vty_out(vty, " neighbor %s graceful-restart-disable\n",
14969 addr);
14970 }
14971 }
14972 }
14973
14974 /* BGP peer configuration display function. */
14975 static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
14976 struct peer *peer, afi_t afi, safi_t safi)
14977 {
14978 struct peer *g_peer = NULL;
14979 char *addr;
14980 bool flag_scomm, flag_secomm, flag_slcomm;
14981
14982 /* Skip dynamic neighbors. */
14983 if (peer_dynamic_neighbor(peer))
14984 return;
14985
14986 if (peer->conf_if)
14987 addr = peer->conf_if;
14988 else
14989 addr = peer->host;
14990
14991 /************************************
14992 ****** Per AF to the neighbor ******
14993 ************************************/
14994 if (peer_group_active(peer)) {
14995 g_peer = peer->group->conf;
14996
14997 /* If the peer-group is active but peer is not, print a 'no
14998 * activate' */
14999 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
15000 vty_out(vty, " no neighbor %s activate\n", addr);
15001 }
15002
15003 /* If the peer-group is not active but peer is, print an
15004 'activate' */
15005 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
15006 vty_out(vty, " neighbor %s activate\n", addr);
15007 }
15008 } else {
15009 if (peer->afc[afi][safi]) {
15010 if ((afi == AFI_IP) && (safi == SAFI_UNICAST)) {
15011 if (CHECK_FLAG(bgp->flags,
15012 BGP_FLAG_NO_DEFAULT_IPV4)) {
15013 vty_out(vty, " neighbor %s activate\n",
15014 addr);
15015 }
15016 } else
15017 vty_out(vty, " neighbor %s activate\n", addr);
15018 } else {
15019 if ((afi == AFI_IP) && (safi == SAFI_UNICAST)) {
15020 if (!CHECK_FLAG(bgp->flags,
15021 BGP_FLAG_NO_DEFAULT_IPV4)) {
15022 vty_out(vty,
15023 " no neighbor %s activate\n",
15024 addr);
15025 }
15026 }
15027 }
15028 }
15029
15030 /* addpath TX knobs */
15031 if (peergroup_af_addpath_check(peer, afi, safi)) {
15032 switch (peer->addpath_type[afi][safi]) {
15033 case BGP_ADDPATH_ALL:
15034 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
15035 addr);
15036 break;
15037 case BGP_ADDPATH_BEST_PER_AS:
15038 vty_out(vty,
15039 " neighbor %s addpath-tx-bestpath-per-AS\n",
15040 addr);
15041 break;
15042 case BGP_ADDPATH_MAX:
15043 case BGP_ADDPATH_NONE:
15044 break;
15045 }
15046 }
15047
15048 /* ORF capability. */
15049 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
15050 || peergroup_af_flag_check(peer, afi, safi,
15051 PEER_FLAG_ORF_PREFIX_RM)) {
15052 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
15053
15054 if (peergroup_af_flag_check(peer, afi, safi,
15055 PEER_FLAG_ORF_PREFIX_SM)
15056 && peergroup_af_flag_check(peer, afi, safi,
15057 PEER_FLAG_ORF_PREFIX_RM))
15058 vty_out(vty, " both");
15059 else if (peergroup_af_flag_check(peer, afi, safi,
15060 PEER_FLAG_ORF_PREFIX_SM))
15061 vty_out(vty, " send");
15062 else
15063 vty_out(vty, " receive");
15064 vty_out(vty, "\n");
15065 }
15066
15067 /* Route reflector client. */
15068 if (peergroup_af_flag_check(peer, afi, safi,
15069 PEER_FLAG_REFLECTOR_CLIENT)) {
15070 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
15071 }
15072
15073 /* next-hop-self force */
15074 if (peergroup_af_flag_check(peer, afi, safi,
15075 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
15076 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
15077 }
15078
15079 /* next-hop-self */
15080 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
15081 vty_out(vty, " neighbor %s next-hop-self\n", addr);
15082 }
15083
15084 /* remove-private-AS */
15085 if (peergroup_af_flag_check(peer, afi, safi,
15086 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
15087 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
15088 addr);
15089 }
15090
15091 else if (peergroup_af_flag_check(peer, afi, safi,
15092 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
15093 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
15094 addr);
15095 }
15096
15097 else if (peergroup_af_flag_check(peer, afi, safi,
15098 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
15099 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
15100 }
15101
15102 else if (peergroup_af_flag_check(peer, afi, safi,
15103 PEER_FLAG_REMOVE_PRIVATE_AS)) {
15104 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
15105 }
15106
15107 /* as-override */
15108 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
15109 vty_out(vty, " neighbor %s as-override\n", addr);
15110 }
15111
15112 /* send-community print. */
15113 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
15114 PEER_FLAG_SEND_COMMUNITY);
15115 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
15116 PEER_FLAG_SEND_EXT_COMMUNITY);
15117 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
15118 PEER_FLAG_SEND_LARGE_COMMUNITY);
15119
15120 if (flag_scomm && flag_secomm && flag_slcomm) {
15121 vty_out(vty, " no neighbor %s send-community all\n", addr);
15122 } else {
15123 if (flag_scomm)
15124 vty_out(vty, " no neighbor %s send-community\n", addr);
15125 if (flag_secomm)
15126 vty_out(vty,
15127 " no neighbor %s send-community extended\n",
15128 addr);
15129
15130 if (flag_slcomm)
15131 vty_out(vty, " no neighbor %s send-community large\n",
15132 addr);
15133 }
15134
15135 /* Default information */
15136 if (peergroup_af_flag_check(peer, afi, safi,
15137 PEER_FLAG_DEFAULT_ORIGINATE)) {
15138 vty_out(vty, " neighbor %s default-originate", addr);
15139
15140 if (peer->default_rmap[afi][safi].name)
15141 vty_out(vty, " route-map %s",
15142 peer->default_rmap[afi][safi].name);
15143
15144 vty_out(vty, "\n");
15145 }
15146
15147 /* Soft reconfiguration inbound. */
15148 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
15149 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
15150 addr);
15151 }
15152
15153 /* maximum-prefix. */
15154 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
15155 vty_out(vty, " neighbor %s maximum-prefix %u", addr,
15156 peer->pmax[afi][safi]);
15157
15158 if (peer->pmax_threshold[afi][safi]
15159 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
15160 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
15161 if (peer_af_flag_check(peer, afi, safi,
15162 PEER_FLAG_MAX_PREFIX_WARNING))
15163 vty_out(vty, " warning-only");
15164 if (peer->pmax_restart[afi][safi])
15165 vty_out(vty, " restart %u",
15166 peer->pmax_restart[afi][safi]);
15167 if (peer_af_flag_check(peer, afi, safi,
15168 PEER_FLAG_MAX_PREFIX_FORCE))
15169 vty_out(vty, " force");
15170
15171 vty_out(vty, "\n");
15172 }
15173
15174 /* maximum-prefix-out */
15175 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
15176 vty_out(vty, " neighbor %s maximum-prefix-out %u\n",
15177 addr, peer->pmax_out[afi][safi]);
15178
15179 /* Route server client. */
15180 if (peergroup_af_flag_check(peer, afi, safi,
15181 PEER_FLAG_RSERVER_CLIENT)) {
15182 vty_out(vty, " neighbor %s route-server-client\n", addr);
15183 }
15184
15185 /* Nexthop-local unchanged. */
15186 if (peergroup_af_flag_check(peer, afi, safi,
15187 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
15188 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
15189 }
15190
15191 /* allowas-in <1-10> */
15192 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
15193 if (peer_af_flag_check(peer, afi, safi,
15194 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
15195 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
15196 } else if (peer->allowas_in[afi][safi] == 3) {
15197 vty_out(vty, " neighbor %s allowas-in\n", addr);
15198 } else {
15199 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
15200 peer->allowas_in[afi][safi]);
15201 }
15202 }
15203
15204 /* weight */
15205 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
15206 vty_out(vty, " neighbor %s weight %lu\n", addr,
15207 peer->weight[afi][safi]);
15208
15209 /* Filter. */
15210 bgp_config_write_filter(vty, peer, afi, safi);
15211
15212 /* atribute-unchanged. */
15213 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
15214 || (safi != SAFI_EVPN
15215 && peer_af_flag_check(peer, afi, safi,
15216 PEER_FLAG_NEXTHOP_UNCHANGED))
15217 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
15218
15219 if (!peer_group_active(peer)
15220 || peergroup_af_flag_check(peer, afi, safi,
15221 PEER_FLAG_AS_PATH_UNCHANGED)
15222 || peergroup_af_flag_check(peer, afi, safi,
15223 PEER_FLAG_NEXTHOP_UNCHANGED)
15224 || peergroup_af_flag_check(peer, afi, safi,
15225 PEER_FLAG_MED_UNCHANGED)) {
15226
15227 vty_out(vty,
15228 " neighbor %s attribute-unchanged%s%s%s\n",
15229 addr,
15230 peer_af_flag_check(peer, afi, safi,
15231 PEER_FLAG_AS_PATH_UNCHANGED)
15232 ? " as-path"
15233 : "",
15234 peer_af_flag_check(peer, afi, safi,
15235 PEER_FLAG_NEXTHOP_UNCHANGED)
15236 ? " next-hop"
15237 : "",
15238 peer_af_flag_check(peer, afi, safi,
15239 PEER_FLAG_MED_UNCHANGED)
15240 ? " med"
15241 : "");
15242 }
15243 }
15244 }
15245
15246 /* Address family based peer configuration display. */
15247 static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
15248 safi_t safi)
15249 {
15250 struct peer *peer;
15251 struct peer_group *group;
15252 struct listnode *node, *nnode;
15253
15254
15255 vty_frame(vty, " !\n address-family ");
15256 if (afi == AFI_IP) {
15257 if (safi == SAFI_UNICAST)
15258 vty_frame(vty, "ipv4 unicast");
15259 else if (safi == SAFI_LABELED_UNICAST)
15260 vty_frame(vty, "ipv4 labeled-unicast");
15261 else if (safi == SAFI_MULTICAST)
15262 vty_frame(vty, "ipv4 multicast");
15263 else if (safi == SAFI_MPLS_VPN)
15264 vty_frame(vty, "ipv4 vpn");
15265 else if (safi == SAFI_ENCAP)
15266 vty_frame(vty, "ipv4 encap");
15267 else if (safi == SAFI_FLOWSPEC)
15268 vty_frame(vty, "ipv4 flowspec");
15269 } else if (afi == AFI_IP6) {
15270 if (safi == SAFI_UNICAST)
15271 vty_frame(vty, "ipv6 unicast");
15272 else if (safi == SAFI_LABELED_UNICAST)
15273 vty_frame(vty, "ipv6 labeled-unicast");
15274 else if (safi == SAFI_MULTICAST)
15275 vty_frame(vty, "ipv6 multicast");
15276 else if (safi == SAFI_MPLS_VPN)
15277 vty_frame(vty, "ipv6 vpn");
15278 else if (safi == SAFI_ENCAP)
15279 vty_frame(vty, "ipv6 encap");
15280 else if (safi == SAFI_FLOWSPEC)
15281 vty_frame(vty, "ipv6 flowspec");
15282 } else if (afi == AFI_L2VPN) {
15283 if (safi == SAFI_EVPN)
15284 vty_frame(vty, "l2vpn evpn");
15285 }
15286 vty_frame(vty, "\n");
15287
15288 bgp_config_write_distance(vty, bgp, afi, safi);
15289
15290 bgp_config_write_network(vty, bgp, afi, safi);
15291
15292 bgp_config_write_redistribute(vty, bgp, afi, safi);
15293
15294 /* BGP flag dampening. */
15295 if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
15296 bgp_config_write_damp(vty, afi, safi);
15297
15298 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
15299 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
15300
15301 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
15302 /* Skip dynamic neighbors. */
15303 if (peer_dynamic_neighbor(peer))
15304 continue;
15305
15306 /* Do not display doppelganger peers */
15307 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
15308 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
15309 }
15310
15311 bgp_config_write_maxpaths(vty, bgp, afi, safi);
15312 bgp_config_write_table_map(vty, bgp, afi, safi);
15313
15314 if (safi == SAFI_EVPN)
15315 bgp_config_write_evpn_info(vty, bgp, afi, safi);
15316
15317 if (safi == SAFI_FLOWSPEC)
15318 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
15319
15320 if (safi == SAFI_UNICAST) {
15321 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
15322 if (CHECK_FLAG(bgp->af_flags[afi][safi],
15323 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
15324
15325 vty_out(vty, " export vpn\n");
15326 }
15327 if (CHECK_FLAG(bgp->af_flags[afi][safi],
15328 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
15329
15330 vty_out(vty, " import vpn\n");
15331 }
15332 if (CHECK_FLAG(bgp->af_flags[afi][safi],
15333 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
15334 char *name;
15335
15336 for (ALL_LIST_ELEMENTS_RO(
15337 bgp->vpn_policy[afi].import_vrf, node,
15338 name))
15339 vty_out(vty, " import vrf %s\n", name);
15340 }
15341 }
15342
15343 vty_endframe(vty, " exit-address-family\n");
15344 }
15345
15346 int bgp_config_write(struct vty *vty)
15347 {
15348 struct bgp *bgp;
15349 struct peer_group *group;
15350 struct peer *peer;
15351 struct listnode *node, *nnode;
15352 struct listnode *mnode, *mnnode;
15353
15354 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
15355 vty_out(vty, "bgp route-map delay-timer %u\n",
15356 bm->rmap_update_timer);
15357
15358 /* BGP configuration. */
15359 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
15360
15361 /* skip all auto created vrf as they dont have user config */
15362 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
15363 continue;
15364
15365 /* Router bgp ASN */
15366 vty_out(vty, "router bgp %u", bgp->as);
15367
15368 if (bgp->name)
15369 vty_out(vty, " %s %s",
15370 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
15371 ? "view" : "vrf", bgp->name);
15372 vty_out(vty, "\n");
15373
15374 /* BGP fast-external-failover. */
15375 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
15376 vty_out(vty, " no bgp fast-external-failover\n");
15377
15378 /* BGP router ID. */
15379 if (bgp->router_id_static.s_addr != 0)
15380 vty_out(vty, " bgp router-id %s\n",
15381 inet_ntoa(bgp->router_id_static));
15382
15383 /* BGP log-neighbor-changes. */
15384 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
15385 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
15386 vty_out(vty, " %sbgp log-neighbor-changes\n",
15387 CHECK_FLAG(bgp->flags,
15388 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
15389 ? ""
15390 : "no ");
15391
15392 /* BGP configuration. */
15393 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
15394 vty_out(vty, " bgp always-compare-med\n");
15395
15396 /* RFC8212 default eBGP policy. */
15397 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
15398 != SAVE_BGP_EBGP_REQUIRES_POLICY)
15399 vty_out(vty, " %sbgp ebgp-requires-policy\n",
15400 CHECK_FLAG(bgp->flags,
15401 BGP_FLAG_EBGP_REQUIRES_POLICY)
15402 ? ""
15403 : "no ");
15404
15405 /* draft-ietf-idr-deprecate-as-set-confed-set */
15406 if (bgp->reject_as_sets)
15407 vty_out(vty, " bgp reject-as-sets\n");
15408
15409 /* BGP default ipv4-unicast. */
15410 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4))
15411 vty_out(vty, " no bgp default ipv4-unicast\n");
15412
15413 /* BGP default local-preference. */
15414 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
15415 vty_out(vty, " bgp default local-preference %u\n",
15416 bgp->default_local_pref);
15417
15418 /* BGP default show-hostname */
15419 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
15420 != SAVE_BGP_SHOW_HOSTNAME)
15421 vty_out(vty, " %sbgp default show-hostname\n",
15422 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
15423 ? ""
15424 : "no ");
15425
15426 /* BGP default show-nexthop-hostname */
15427 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
15428 != SAVE_BGP_SHOW_HOSTNAME)
15429 vty_out(vty, " %sbgp default show-nexthop-hostname\n",
15430 CHECK_FLAG(bgp->flags,
15431 BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
15432 ? ""
15433 : "no ");
15434
15435 /* BGP default subgroup-pkt-queue-max. */
15436 if (bgp->default_subgroup_pkt_queue_max
15437 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
15438 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
15439 bgp->default_subgroup_pkt_queue_max);
15440
15441 /* BGP client-to-client reflection. */
15442 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
15443 vty_out(vty, " no bgp client-to-client reflection\n");
15444
15445 /* BGP cluster ID. */
15446 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
15447 vty_out(vty, " bgp cluster-id %s\n",
15448 inet_ntoa(bgp->cluster_id));
15449
15450 /* Disable ebgp connected nexthop check */
15451 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
15452 vty_out(vty,
15453 " bgp disable-ebgp-connected-route-check\n");
15454
15455 /* Confederation identifier*/
15456 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
15457 vty_out(vty, " bgp confederation identifier %u\n",
15458 bgp->confed_id);
15459
15460 /* Confederation peer */
15461 if (bgp->confed_peers_cnt > 0) {
15462 int i;
15463
15464 vty_out(vty, " bgp confederation peers");
15465
15466 for (i = 0; i < bgp->confed_peers_cnt; i++)
15467 vty_out(vty, " %u", bgp->confed_peers[i]);
15468
15469 vty_out(vty, "\n");
15470 }
15471
15472 /* BGP deterministic-med. */
15473 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
15474 != SAVE_BGP_DETERMINISTIC_MED)
15475 vty_out(vty, " %sbgp deterministic-med\n",
15476 CHECK_FLAG(bgp->flags,
15477 BGP_FLAG_DETERMINISTIC_MED)
15478 ? ""
15479 : "no ");
15480
15481 /* BGP update-delay. */
15482 bgp_config_write_update_delay(vty, bgp);
15483
15484 if (bgp->v_maxmed_onstartup
15485 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
15486 vty_out(vty, " bgp max-med on-startup %u",
15487 bgp->v_maxmed_onstartup);
15488 if (bgp->maxmed_onstartup_value
15489 != BGP_MAXMED_VALUE_DEFAULT)
15490 vty_out(vty, " %u",
15491 bgp->maxmed_onstartup_value);
15492 vty_out(vty, "\n");
15493 }
15494 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
15495 vty_out(vty, " bgp max-med administrative");
15496 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
15497 vty_out(vty, " %u", bgp->maxmed_admin_value);
15498 vty_out(vty, "\n");
15499 }
15500
15501 /* write quanta */
15502 bgp_config_write_wpkt_quanta(vty, bgp);
15503 /* read quanta */
15504 bgp_config_write_rpkt_quanta(vty, bgp);
15505
15506 /* coalesce time */
15507 bgp_config_write_coalesce_time(vty, bgp);
15508
15509 /* BGP graceful-restart. */
15510 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
15511 vty_out(vty,
15512 " bgp graceful-restart stalepath-time %u\n",
15513 bgp->stalepath_time);
15514
15515 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
15516 vty_out(vty, " bgp graceful-restart restart-time %u\n",
15517 bgp->restart_time);
15518
15519 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
15520 vty_out(vty,
15521 " bgp graceful-restart select-defer-time %u\n",
15522 bgp->select_defer_time);
15523
15524 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
15525 vty_out(vty, " bgp graceful-restart\n");
15526
15527 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
15528 vty_out(vty, " bgp graceful-restart-disable\n");
15529
15530 /* BGP graceful-shutdown */
15531 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
15532 vty_out(vty, " bgp graceful-shutdown\n");
15533
15534 /* BGP graceful-restart Preserve State F bit. */
15535 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
15536 vty_out(vty,
15537 " bgp graceful-restart preserve-fw-state\n");
15538
15539 /* Stale timer for RIB */
15540 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
15541 vty_out(vty,
15542 " bgp graceful-restart rib-stale-time %u\n",
15543 bgp->rib_stale_time);
15544
15545 /* BGP bestpath method. */
15546 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
15547 vty_out(vty, " bgp bestpath as-path ignore\n");
15548 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
15549 vty_out(vty, " bgp bestpath as-path confed\n");
15550
15551 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
15552 if (CHECK_FLAG(bgp->flags,
15553 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
15554 vty_out(vty,
15555 " bgp bestpath as-path multipath-relax as-set\n");
15556 } else {
15557 vty_out(vty,
15558 " bgp bestpath as-path multipath-relax\n");
15559 }
15560 }
15561
15562 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
15563 vty_out(vty,
15564 " bgp route-reflector allow-outbound-policy\n");
15565 }
15566 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
15567 vty_out(vty, " bgp bestpath compare-routerid\n");
15568 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
15569 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
15570 vty_out(vty, " bgp bestpath med");
15571 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
15572 vty_out(vty, " confed");
15573 if (CHECK_FLAG(bgp->flags,
15574 BGP_FLAG_MED_MISSING_AS_WORST))
15575 vty_out(vty, " missing-as-worst");
15576 vty_out(vty, "\n");
15577 }
15578
15579 /* Link bandwidth handling. */
15580 if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW)
15581 vty_out(vty, " bgp bestpath bandwidth ignore\n");
15582 else if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
15583 vty_out(vty, " bgp bestpath bandwidth skip-missing\n");
15584 else if (bgp->lb_handling == BGP_LINK_BW_DEFWT_4_MISSING)
15585 vty_out(vty, " bgp bestpath bandwidth default-weight-for-missing\n");
15586
15587 /* BGP network import check. */
15588 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
15589 != SAVE_BGP_IMPORT_CHECK)
15590 vty_out(vty, " %sbgp network import-check\n",
15591 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
15592 ? ""
15593 : "no ");
15594
15595 /* BGP timers configuration. */
15596 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
15597 && bgp->default_holdtime != SAVE_BGP_HOLDTIME)
15598 vty_out(vty, " timers bgp %u %u\n",
15599 bgp->default_keepalive, bgp->default_holdtime);
15600
15601 /* peer-group */
15602 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
15603 bgp_config_write_peer_global(vty, bgp, group->conf);
15604 }
15605
15606 /* Normal neighbor configuration. */
15607 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
15608 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
15609 bgp_config_write_peer_global(vty, bgp, peer);
15610 }
15611
15612 /* listen range and limit for dynamic BGP neighbors */
15613 bgp_config_write_listen(vty, bgp);
15614
15615 /*
15616 * BGP default autoshutdown neighbors
15617 *
15618 * This must be placed after any peer and peer-group
15619 * configuration, to avoid setting all peers to shutdown after
15620 * a daemon restart, which is undesired behavior. (see #2286)
15621 */
15622 if (bgp->autoshutdown)
15623 vty_out(vty, " bgp default shutdown\n");
15624
15625 /* BGP instance administrative shutdown */
15626 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN))
15627 vty_out(vty, " bgp shutdown\n");
15628
15629 /* IPv4 unicast configuration. */
15630 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
15631
15632 /* IPv4 multicast configuration. */
15633 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
15634
15635 /* IPv4 labeled-unicast configuration. */
15636 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
15637
15638 /* IPv4 VPN configuration. */
15639 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
15640
15641 /* ENCAPv4 configuration. */
15642 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
15643
15644 /* FLOWSPEC v4 configuration. */
15645 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
15646
15647 /* IPv6 unicast configuration. */
15648 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
15649
15650 /* IPv6 multicast configuration. */
15651 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
15652
15653 /* IPv6 labeled-unicast configuration. */
15654 bgp_config_write_family(vty, bgp, AFI_IP6,
15655 SAFI_LABELED_UNICAST);
15656
15657 /* IPv6 VPN configuration. */
15658 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
15659
15660 /* ENCAPv6 configuration. */
15661 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
15662
15663 /* FLOWSPEC v6 configuration. */
15664 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
15665
15666 /* EVPN configuration. */
15667 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
15668
15669 hook_call(bgp_inst_config_write, bgp, vty);
15670
15671 #ifdef ENABLE_BGP_VNC
15672 bgp_rfapi_cfg_write(vty, bgp);
15673 #endif
15674
15675 vty_out(vty, "!\n");
15676 }
15677 return 0;
15678 }
15679
15680
15681 /* BGP node structure. */
15682 static struct cmd_node bgp_node = {
15683 .name = "bgp",
15684 .node = BGP_NODE,
15685 .parent_node = CONFIG_NODE,
15686 .prompt = "%s(config-router)# ",
15687 .config_write = bgp_config_write,
15688 };
15689
15690 static struct cmd_node bgp_ipv4_unicast_node = {
15691 .name = "bgp ipv4 unicast",
15692 .node = BGP_IPV4_NODE,
15693 .parent_node = BGP_NODE,
15694 .prompt = "%s(config-router-af)# ",
15695 };
15696
15697 static struct cmd_node bgp_ipv4_multicast_node = {
15698 .name = "bgp ipv4 multicast",
15699 .node = BGP_IPV4M_NODE,
15700 .parent_node = BGP_NODE,
15701 .prompt = "%s(config-router-af)# ",
15702 };
15703
15704 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
15705 .name = "bgp ipv4 labeled unicast",
15706 .node = BGP_IPV4L_NODE,
15707 .parent_node = BGP_NODE,
15708 .prompt = "%s(config-router-af)# ",
15709 };
15710
15711 static struct cmd_node bgp_ipv6_unicast_node = {
15712 .name = "bgp ipv6",
15713 .node = BGP_IPV6_NODE,
15714 .parent_node = BGP_NODE,
15715 .prompt = "%s(config-router-af)# ",
15716 };
15717
15718 static struct cmd_node bgp_ipv6_multicast_node = {
15719 .name = "bgp ipv6 multicast",
15720 .node = BGP_IPV6M_NODE,
15721 .parent_node = BGP_NODE,
15722 .prompt = "%s(config-router-af)# ",
15723 };
15724
15725 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
15726 .name = "bgp ipv6 labeled unicast",
15727 .node = BGP_IPV6L_NODE,
15728 .parent_node = BGP_NODE,
15729 .prompt = "%s(config-router-af)# ",
15730 };
15731
15732 static struct cmd_node bgp_vpnv4_node = {
15733 .name = "bgp vpnv4",
15734 .node = BGP_VPNV4_NODE,
15735 .parent_node = BGP_NODE,
15736 .prompt = "%s(config-router-af)# ",
15737 };
15738
15739 static struct cmd_node bgp_vpnv6_node = {
15740 .name = "bgp vpnv6",
15741 .node = BGP_VPNV6_NODE,
15742 .parent_node = BGP_NODE,
15743 .prompt = "%s(config-router-af-vpnv6)# ",
15744 };
15745
15746 static struct cmd_node bgp_evpn_node = {
15747 .name = "bgp evpn",
15748 .node = BGP_EVPN_NODE,
15749 .parent_node = BGP_NODE,
15750 .prompt = "%s(config-router-evpn)# ",
15751 };
15752
15753 static struct cmd_node bgp_evpn_vni_node = {
15754 .name = "bgp evpn vni",
15755 .node = BGP_EVPN_VNI_NODE,
15756 .parent_node = BGP_EVPN_NODE,
15757 .prompt = "%s(config-router-af-vni)# ",
15758 };
15759
15760 static struct cmd_node bgp_flowspecv4_node = {
15761 .name = "bgp ipv4 flowspec",
15762 .node = BGP_FLOWSPECV4_NODE,
15763 .parent_node = BGP_NODE,
15764 .prompt = "%s(config-router-af)# ",
15765 };
15766
15767 static struct cmd_node bgp_flowspecv6_node = {
15768 .name = "bgp ipv6 flowspec",
15769 .node = BGP_FLOWSPECV6_NODE,
15770 .parent_node = BGP_NODE,
15771 .prompt = "%s(config-router-af-vpnv6)# ",
15772 };
15773
15774 static void community_list_vty(void);
15775
15776 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
15777 {
15778 struct bgp *bgp;
15779 struct peer *peer;
15780 struct listnode *lnbgp, *lnpeer;
15781
15782 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
15783 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
15784 /* only provide suggestions on the appropriate input
15785 * token type,
15786 * they'll otherwise show up multiple times */
15787 enum cmd_token_type match_type;
15788 char *name = peer->host;
15789
15790 if (peer->conf_if) {
15791 match_type = VARIABLE_TKN;
15792 name = peer->conf_if;
15793 } else if (strchr(peer->host, ':'))
15794 match_type = IPV6_TKN;
15795 else
15796 match_type = IPV4_TKN;
15797
15798 if (token->type != match_type)
15799 continue;
15800
15801 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
15802 }
15803 }
15804 }
15805
15806 static const struct cmd_variable_handler bgp_var_neighbor[] = {
15807 {.varname = "neighbor", .completions = bgp_ac_neighbor},
15808 {.varname = "neighbors", .completions = bgp_ac_neighbor},
15809 {.varname = "peer", .completions = bgp_ac_neighbor},
15810 {.completions = NULL}};
15811
15812 static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
15813 {
15814 struct bgp *bgp;
15815 struct peer_group *group;
15816 struct listnode *lnbgp, *lnpeer;
15817
15818 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
15819 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
15820 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
15821 group->name));
15822 }
15823 }
15824
15825 static const struct cmd_variable_handler bgp_var_peergroup[] = {
15826 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
15827 {.completions = NULL} };
15828
15829 void bgp_vty_init(void)
15830 {
15831 cmd_variable_handler_register(bgp_var_neighbor);
15832 cmd_variable_handler_register(bgp_var_peergroup);
15833
15834 /* Install bgp top node. */
15835 install_node(&bgp_node);
15836 install_node(&bgp_ipv4_unicast_node);
15837 install_node(&bgp_ipv4_multicast_node);
15838 install_node(&bgp_ipv4_labeled_unicast_node);
15839 install_node(&bgp_ipv6_unicast_node);
15840 install_node(&bgp_ipv6_multicast_node);
15841 install_node(&bgp_ipv6_labeled_unicast_node);
15842 install_node(&bgp_vpnv4_node);
15843 install_node(&bgp_vpnv6_node);
15844 install_node(&bgp_evpn_node);
15845 install_node(&bgp_evpn_vni_node);
15846 install_node(&bgp_flowspecv4_node);
15847 install_node(&bgp_flowspecv6_node);
15848
15849 /* Install default VTY commands to new nodes. */
15850 install_default(BGP_NODE);
15851 install_default(BGP_IPV4_NODE);
15852 install_default(BGP_IPV4M_NODE);
15853 install_default(BGP_IPV4L_NODE);
15854 install_default(BGP_IPV6_NODE);
15855 install_default(BGP_IPV6M_NODE);
15856 install_default(BGP_IPV6L_NODE);
15857 install_default(BGP_VPNV4_NODE);
15858 install_default(BGP_VPNV6_NODE);
15859 install_default(BGP_FLOWSPECV4_NODE);
15860 install_default(BGP_FLOWSPECV6_NODE);
15861 install_default(BGP_EVPN_NODE);
15862 install_default(BGP_EVPN_VNI_NODE);
15863
15864 /* "bgp local-mac" hidden commands. */
15865 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
15866 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
15867
15868 /* bgp route-map delay-timer commands. */
15869 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
15870 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
15871
15872 /* Dummy commands (Currently not supported) */
15873 install_element(BGP_NODE, &no_synchronization_cmd);
15874 install_element(BGP_NODE, &no_auto_summary_cmd);
15875
15876 /* "router bgp" commands. */
15877 install_element(CONFIG_NODE, &router_bgp_cmd);
15878
15879 /* "no router bgp" commands. */
15880 install_element(CONFIG_NODE, &no_router_bgp_cmd);
15881
15882 /* "bgp router-id" commands. */
15883 install_element(BGP_NODE, &bgp_router_id_cmd);
15884 install_element(BGP_NODE, &no_bgp_router_id_cmd);
15885
15886 /* "bgp cluster-id" commands. */
15887 install_element(BGP_NODE, &bgp_cluster_id_cmd);
15888 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
15889
15890 /* "bgp confederation" commands. */
15891 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
15892 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
15893
15894 /* "bgp confederation peers" commands. */
15895 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
15896 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
15897
15898 /* bgp max-med command */
15899 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
15900 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
15901 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
15902 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
15903 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
15904
15905 /* bgp disable-ebgp-connected-nh-check */
15906 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
15907 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
15908
15909 /* bgp update-delay command */
15910 install_element(BGP_NODE, &bgp_update_delay_cmd);
15911 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
15912 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
15913
15914 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
15915 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
15916
15917 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
15918 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
15919
15920 /* "maximum-paths" commands. */
15921 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
15922 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
15923 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
15924 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
15925 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
15926 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
15927 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
15928 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
15929 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
15930 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
15931 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
15932 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
15933 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
15934 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
15935 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
15936
15937 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_cmd);
15938 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_cmd);
15939 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cmd);
15940 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
15941 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_ibgp_cmd);
15942 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
15943 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
15944 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
15945 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
15946 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
15947
15948 /* "timers bgp" commands. */
15949 install_element(BGP_NODE, &bgp_timers_cmd);
15950 install_element(BGP_NODE, &no_bgp_timers_cmd);
15951
15952 /* route-map delay-timer commands - per instance for backwards compat.
15953 */
15954 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
15955 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
15956
15957 /* "bgp client-to-client reflection" commands */
15958 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
15959 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
15960
15961 /* "bgp always-compare-med" commands */
15962 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
15963 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
15964
15965 /* bgp ebgp-requires-policy */
15966 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
15967 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
15968
15969 /* bgp reject-as-sets */
15970 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
15971 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
15972
15973 /* "bgp deterministic-med" commands */
15974 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
15975 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
15976
15977 /* "bgp graceful-restart" command */
15978 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
15979 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
15980
15981 /* "bgp graceful-restart-disable" command */
15982 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
15983 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
15984
15985 /* "neighbor a:b:c:d graceful-restart" command */
15986 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
15987 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
15988
15989 /* "neighbor a:b:c:d graceful-restart-disable" command */
15990 install_element(BGP_NODE,
15991 &bgp_neighbor_graceful_restart_disable_set_cmd);
15992 install_element(BGP_NODE,
15993 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
15994
15995 /* "neighbor a:b:c:d graceful-restart-helper" command */
15996 install_element(BGP_NODE,
15997 &bgp_neighbor_graceful_restart_helper_set_cmd);
15998 install_element(BGP_NODE,
15999 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
16000
16001 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
16002 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
16003 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
16004 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
16005 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
16006 install_element(BGP_NODE,
16007 &no_bgp_graceful_restart_select_defer_time_cmd);
16008 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
16009 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
16010
16011 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
16012 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
16013 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
16014 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
16015
16016 /* "bgp graceful-shutdown" commands */
16017 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
16018 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
16019
16020 /* "bgp fast-external-failover" commands */
16021 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
16022 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
16023
16024 /* "bgp bestpath compare-routerid" commands */
16025 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
16026 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
16027
16028 /* "bgp bestpath as-path ignore" commands */
16029 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
16030 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
16031
16032 /* "bgp bestpath as-path confed" commands */
16033 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
16034 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
16035
16036 /* "bgp bestpath as-path multipath-relax" commands */
16037 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
16038 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
16039
16040 /* "bgp log-neighbor-changes" commands */
16041 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
16042 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
16043
16044 /* "bgp bestpath med" commands */
16045 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
16046 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
16047
16048 /* "bgp bestpath bandwidth" commands */
16049 install_element(BGP_NODE, &bgp_bestpath_bw_cmd);
16050 install_element(BGP_NODE, &no_bgp_bestpath_bw_cmd);
16051
16052 /* "no bgp default ipv4-unicast" commands. */
16053 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
16054 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
16055
16056 /* "bgp network import-check" commands. */
16057 install_element(BGP_NODE, &bgp_network_import_check_cmd);
16058 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
16059 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
16060
16061 /* "bgp default local-preference" commands. */
16062 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
16063 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
16064
16065 /* bgp default show-hostname */
16066 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
16067 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
16068
16069 /* bgp default show-nexthop-hostname */
16070 install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
16071 install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
16072
16073 /* "bgp default subgroup-pkt-queue-max" commands. */
16074 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
16075 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
16076
16077 /* bgp ibgp-allow-policy-mods command */
16078 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
16079 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
16080
16081 /* "bgp listen limit" commands. */
16082 install_element(BGP_NODE, &bgp_listen_limit_cmd);
16083 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
16084
16085 /* "bgp listen range" commands. */
16086 install_element(BGP_NODE, &bgp_listen_range_cmd);
16087 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
16088
16089 /* "bgp default shutdown" command */
16090 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
16091
16092 /* "bgp shutdown" commands */
16093 install_element(BGP_NODE, &bgp_shutdown_cmd);
16094 install_element(BGP_NODE, &bgp_shutdown_msg_cmd);
16095 install_element(BGP_NODE, &no_bgp_shutdown_cmd);
16096 install_element(BGP_NODE, &no_bgp_shutdown_msg_cmd);
16097
16098 /* "neighbor remote-as" commands. */
16099 install_element(BGP_NODE, &neighbor_remote_as_cmd);
16100 install_element(BGP_NODE, &neighbor_interface_config_cmd);
16101 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
16102 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
16103 install_element(BGP_NODE,
16104 &neighbor_interface_v6only_config_remote_as_cmd);
16105 install_element(BGP_NODE, &no_neighbor_cmd);
16106 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
16107
16108 /* "neighbor peer-group" commands. */
16109 install_element(BGP_NODE, &neighbor_peer_group_cmd);
16110 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
16111 install_element(BGP_NODE,
16112 &no_neighbor_interface_peer_group_remote_as_cmd);
16113
16114 /* "neighbor local-as" commands. */
16115 install_element(BGP_NODE, &neighbor_local_as_cmd);
16116 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
16117 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
16118 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
16119
16120 /* "neighbor solo" commands. */
16121 install_element(BGP_NODE, &neighbor_solo_cmd);
16122 install_element(BGP_NODE, &no_neighbor_solo_cmd);
16123
16124 /* "neighbor password" commands. */
16125 install_element(BGP_NODE, &neighbor_password_cmd);
16126 install_element(BGP_NODE, &no_neighbor_password_cmd);
16127
16128 /* "neighbor activate" commands. */
16129 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
16130 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
16131 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
16132 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
16133 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
16134 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
16135 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
16136 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
16137 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
16138 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
16139 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
16140 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
16141
16142 /* "no neighbor activate" commands. */
16143 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
16144 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
16145 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
16146 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
16147 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
16148 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
16149 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
16150 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
16151 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
16152 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
16153 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
16154 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
16155
16156 /* "neighbor peer-group" set commands. */
16157 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
16158 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
16159 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
16160 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
16161 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
16162 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
16163 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
16164 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
16165 install_element(BGP_FLOWSPECV4_NODE,
16166 &neighbor_set_peer_group_hidden_cmd);
16167 install_element(BGP_FLOWSPECV6_NODE,
16168 &neighbor_set_peer_group_hidden_cmd);
16169
16170 /* "no neighbor peer-group unset" commands. */
16171 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
16172 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
16173 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
16174 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
16175 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
16176 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
16177 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
16178 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
16179 install_element(BGP_FLOWSPECV4_NODE,
16180 &no_neighbor_set_peer_group_hidden_cmd);
16181 install_element(BGP_FLOWSPECV6_NODE,
16182 &no_neighbor_set_peer_group_hidden_cmd);
16183
16184 /* "neighbor softreconfiguration inbound" commands.*/
16185 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
16186 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
16187 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
16188 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
16189 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
16190 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
16191 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
16192 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
16193 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
16194 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
16195 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
16196 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
16197 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
16198 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
16199 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
16200 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
16201 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
16202 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
16203 install_element(BGP_FLOWSPECV4_NODE,
16204 &neighbor_soft_reconfiguration_cmd);
16205 install_element(BGP_FLOWSPECV4_NODE,
16206 &no_neighbor_soft_reconfiguration_cmd);
16207 install_element(BGP_FLOWSPECV6_NODE,
16208 &neighbor_soft_reconfiguration_cmd);
16209 install_element(BGP_FLOWSPECV6_NODE,
16210 &no_neighbor_soft_reconfiguration_cmd);
16211 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
16212 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
16213
16214 /* "neighbor attribute-unchanged" commands. */
16215 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
16216 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
16217 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
16218 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
16219 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
16220 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
16221 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
16222 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
16223 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
16224 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
16225 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
16226 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
16227 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
16228 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
16229 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
16230 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
16231 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
16232 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
16233
16234 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
16235 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
16236
16237 /* "nexthop-local unchanged" commands */
16238 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
16239 install_element(BGP_IPV6_NODE,
16240 &no_neighbor_nexthop_local_unchanged_cmd);
16241
16242 /* "neighbor next-hop-self" commands. */
16243 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
16244 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
16245 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
16246 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
16247 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
16248 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
16249 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
16250 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
16251 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
16252 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
16253 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
16254 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
16255 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
16256 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
16257 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
16258 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
16259 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
16260 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
16261 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
16262 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
16263
16264 /* "neighbor next-hop-self force" commands. */
16265 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
16266 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
16267 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
16268 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
16269 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
16270 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
16271 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
16272 install_element(BGP_IPV4_NODE,
16273 &no_neighbor_nexthop_self_all_hidden_cmd);
16274 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
16275 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
16276 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
16277 install_element(BGP_IPV4M_NODE,
16278 &no_neighbor_nexthop_self_all_hidden_cmd);
16279 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
16280 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
16281 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
16282 install_element(BGP_IPV4L_NODE,
16283 &no_neighbor_nexthop_self_all_hidden_cmd);
16284 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
16285 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
16286 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
16287 install_element(BGP_IPV6_NODE,
16288 &no_neighbor_nexthop_self_all_hidden_cmd);
16289 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
16290 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
16291 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
16292 install_element(BGP_IPV6M_NODE,
16293 &no_neighbor_nexthop_self_all_hidden_cmd);
16294 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
16295 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
16296 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
16297 install_element(BGP_IPV6L_NODE,
16298 &no_neighbor_nexthop_self_all_hidden_cmd);
16299 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
16300 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
16301 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
16302 install_element(BGP_VPNV4_NODE,
16303 &no_neighbor_nexthop_self_all_hidden_cmd);
16304 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
16305 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
16306 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
16307 install_element(BGP_VPNV6_NODE,
16308 &no_neighbor_nexthop_self_all_hidden_cmd);
16309 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_force_cmd);
16310 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_force_cmd);
16311
16312 /* "neighbor as-override" commands. */
16313 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
16314 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
16315 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
16316 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
16317 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
16318 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
16319 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
16320 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
16321 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
16322 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
16323 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
16324 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
16325 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
16326 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
16327 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
16328 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
16329 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
16330 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
16331
16332 /* "neighbor remove-private-AS" commands. */
16333 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
16334 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
16335 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
16336 install_element(BGP_NODE,
16337 &no_neighbor_remove_private_as_all_hidden_cmd);
16338 install_element(BGP_NODE,
16339 &neighbor_remove_private_as_replace_as_hidden_cmd);
16340 install_element(BGP_NODE,
16341 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
16342 install_element(BGP_NODE,
16343 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
16344 install_element(
16345 BGP_NODE,
16346 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
16347 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
16348 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
16349 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
16350 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
16351 install_element(BGP_IPV4_NODE,
16352 &neighbor_remove_private_as_replace_as_cmd);
16353 install_element(BGP_IPV4_NODE,
16354 &no_neighbor_remove_private_as_replace_as_cmd);
16355 install_element(BGP_IPV4_NODE,
16356 &neighbor_remove_private_as_all_replace_as_cmd);
16357 install_element(BGP_IPV4_NODE,
16358 &no_neighbor_remove_private_as_all_replace_as_cmd);
16359 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
16360 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
16361 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
16362 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
16363 install_element(BGP_IPV4M_NODE,
16364 &neighbor_remove_private_as_replace_as_cmd);
16365 install_element(BGP_IPV4M_NODE,
16366 &no_neighbor_remove_private_as_replace_as_cmd);
16367 install_element(BGP_IPV4M_NODE,
16368 &neighbor_remove_private_as_all_replace_as_cmd);
16369 install_element(BGP_IPV4M_NODE,
16370 &no_neighbor_remove_private_as_all_replace_as_cmd);
16371 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
16372 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
16373 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
16374 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
16375 install_element(BGP_IPV4L_NODE,
16376 &neighbor_remove_private_as_replace_as_cmd);
16377 install_element(BGP_IPV4L_NODE,
16378 &no_neighbor_remove_private_as_replace_as_cmd);
16379 install_element(BGP_IPV4L_NODE,
16380 &neighbor_remove_private_as_all_replace_as_cmd);
16381 install_element(BGP_IPV4L_NODE,
16382 &no_neighbor_remove_private_as_all_replace_as_cmd);
16383 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
16384 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
16385 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
16386 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
16387 install_element(BGP_IPV6_NODE,
16388 &neighbor_remove_private_as_replace_as_cmd);
16389 install_element(BGP_IPV6_NODE,
16390 &no_neighbor_remove_private_as_replace_as_cmd);
16391 install_element(BGP_IPV6_NODE,
16392 &neighbor_remove_private_as_all_replace_as_cmd);
16393 install_element(BGP_IPV6_NODE,
16394 &no_neighbor_remove_private_as_all_replace_as_cmd);
16395 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
16396 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
16397 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
16398 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
16399 install_element(BGP_IPV6M_NODE,
16400 &neighbor_remove_private_as_replace_as_cmd);
16401 install_element(BGP_IPV6M_NODE,
16402 &no_neighbor_remove_private_as_replace_as_cmd);
16403 install_element(BGP_IPV6M_NODE,
16404 &neighbor_remove_private_as_all_replace_as_cmd);
16405 install_element(BGP_IPV6M_NODE,
16406 &no_neighbor_remove_private_as_all_replace_as_cmd);
16407 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
16408 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
16409 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
16410 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
16411 install_element(BGP_IPV6L_NODE,
16412 &neighbor_remove_private_as_replace_as_cmd);
16413 install_element(BGP_IPV6L_NODE,
16414 &no_neighbor_remove_private_as_replace_as_cmd);
16415 install_element(BGP_IPV6L_NODE,
16416 &neighbor_remove_private_as_all_replace_as_cmd);
16417 install_element(BGP_IPV6L_NODE,
16418 &no_neighbor_remove_private_as_all_replace_as_cmd);
16419 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
16420 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
16421 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
16422 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
16423 install_element(BGP_VPNV4_NODE,
16424 &neighbor_remove_private_as_replace_as_cmd);
16425 install_element(BGP_VPNV4_NODE,
16426 &no_neighbor_remove_private_as_replace_as_cmd);
16427 install_element(BGP_VPNV4_NODE,
16428 &neighbor_remove_private_as_all_replace_as_cmd);
16429 install_element(BGP_VPNV4_NODE,
16430 &no_neighbor_remove_private_as_all_replace_as_cmd);
16431 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
16432 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
16433 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
16434 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
16435 install_element(BGP_VPNV6_NODE,
16436 &neighbor_remove_private_as_replace_as_cmd);
16437 install_element(BGP_VPNV6_NODE,
16438 &no_neighbor_remove_private_as_replace_as_cmd);
16439 install_element(BGP_VPNV6_NODE,
16440 &neighbor_remove_private_as_all_replace_as_cmd);
16441 install_element(BGP_VPNV6_NODE,
16442 &no_neighbor_remove_private_as_all_replace_as_cmd);
16443
16444 /* "neighbor send-community" commands.*/
16445 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
16446 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
16447 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
16448 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
16449 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
16450 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
16451 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
16452 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
16453 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
16454 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
16455 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
16456 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
16457 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
16458 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
16459 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
16460 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
16461 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
16462 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
16463 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
16464 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
16465 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
16466 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
16467 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
16468 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
16469 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
16470 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
16471 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
16472 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
16473 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
16474 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
16475 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
16476 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
16477 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
16478 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
16479 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
16480 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
16481
16482 /* "neighbor route-reflector" commands.*/
16483 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
16484 install_element(BGP_NODE,
16485 &no_neighbor_route_reflector_client_hidden_cmd);
16486 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
16487 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
16488 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
16489 install_element(BGP_IPV4M_NODE,
16490 &no_neighbor_route_reflector_client_cmd);
16491 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
16492 install_element(BGP_IPV4L_NODE,
16493 &no_neighbor_route_reflector_client_cmd);
16494 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
16495 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
16496 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
16497 install_element(BGP_IPV6M_NODE,
16498 &no_neighbor_route_reflector_client_cmd);
16499 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
16500 install_element(BGP_IPV6L_NODE,
16501 &no_neighbor_route_reflector_client_cmd);
16502 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
16503 install_element(BGP_VPNV4_NODE,
16504 &no_neighbor_route_reflector_client_cmd);
16505 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
16506 install_element(BGP_VPNV6_NODE,
16507 &no_neighbor_route_reflector_client_cmd);
16508 install_element(BGP_FLOWSPECV4_NODE,
16509 &neighbor_route_reflector_client_cmd);
16510 install_element(BGP_FLOWSPECV4_NODE,
16511 &no_neighbor_route_reflector_client_cmd);
16512 install_element(BGP_FLOWSPECV6_NODE,
16513 &neighbor_route_reflector_client_cmd);
16514 install_element(BGP_FLOWSPECV6_NODE,
16515 &no_neighbor_route_reflector_client_cmd);
16516 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
16517 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
16518
16519 /* "neighbor route-server" commands.*/
16520 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
16521 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
16522 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
16523 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
16524 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
16525 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
16526 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
16527 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
16528 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
16529 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
16530 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
16531 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
16532 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
16533 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
16534 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
16535 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
16536 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
16537 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
16538 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
16539 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
16540 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
16541 install_element(BGP_FLOWSPECV4_NODE,
16542 &no_neighbor_route_server_client_cmd);
16543 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
16544 install_element(BGP_FLOWSPECV6_NODE,
16545 &no_neighbor_route_server_client_cmd);
16546
16547 /* "neighbor addpath-tx-all-paths" commands.*/
16548 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
16549 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
16550 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
16551 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16552 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
16553 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16554 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
16555 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16556 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
16557 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16558 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
16559 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16560 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
16561 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16562 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
16563 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16564 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
16565 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16566
16567 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
16568 install_element(BGP_NODE,
16569 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
16570 install_element(BGP_NODE,
16571 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
16572 install_element(BGP_IPV4_NODE,
16573 &neighbor_addpath_tx_bestpath_per_as_cmd);
16574 install_element(BGP_IPV4_NODE,
16575 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16576 install_element(BGP_IPV4M_NODE,
16577 &neighbor_addpath_tx_bestpath_per_as_cmd);
16578 install_element(BGP_IPV4M_NODE,
16579 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16580 install_element(BGP_IPV4L_NODE,
16581 &neighbor_addpath_tx_bestpath_per_as_cmd);
16582 install_element(BGP_IPV4L_NODE,
16583 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16584 install_element(BGP_IPV6_NODE,
16585 &neighbor_addpath_tx_bestpath_per_as_cmd);
16586 install_element(BGP_IPV6_NODE,
16587 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16588 install_element(BGP_IPV6M_NODE,
16589 &neighbor_addpath_tx_bestpath_per_as_cmd);
16590 install_element(BGP_IPV6M_NODE,
16591 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16592 install_element(BGP_IPV6L_NODE,
16593 &neighbor_addpath_tx_bestpath_per_as_cmd);
16594 install_element(BGP_IPV6L_NODE,
16595 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16596 install_element(BGP_VPNV4_NODE,
16597 &neighbor_addpath_tx_bestpath_per_as_cmd);
16598 install_element(BGP_VPNV4_NODE,
16599 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16600 install_element(BGP_VPNV6_NODE,
16601 &neighbor_addpath_tx_bestpath_per_as_cmd);
16602 install_element(BGP_VPNV6_NODE,
16603 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16604
16605 /* "neighbor sender-as-path-loop-detection" commands. */
16606 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
16607 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
16608
16609 /* "neighbor passive" commands. */
16610 install_element(BGP_NODE, &neighbor_passive_cmd);
16611 install_element(BGP_NODE, &no_neighbor_passive_cmd);
16612
16613
16614 /* "neighbor shutdown" commands. */
16615 install_element(BGP_NODE, &neighbor_shutdown_cmd);
16616 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
16617 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
16618 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
16619
16620 /* "neighbor capability extended-nexthop" commands.*/
16621 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
16622 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
16623
16624 /* "neighbor capability orf prefix-list" commands.*/
16625 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
16626 install_element(BGP_NODE,
16627 &no_neighbor_capability_orf_prefix_hidden_cmd);
16628 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
16629 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
16630 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
16631 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
16632 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
16633 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
16634 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
16635 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
16636 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
16637 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
16638 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
16639 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
16640
16641 /* "neighbor capability dynamic" commands.*/
16642 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
16643 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
16644
16645 /* "neighbor dont-capability-negotiate" commands. */
16646 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
16647 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
16648
16649 /* "neighbor ebgp-multihop" commands. */
16650 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
16651 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
16652 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
16653
16654 /* "neighbor disable-connected-check" commands. */
16655 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
16656 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
16657
16658 /* "neighbor enforce-first-as" commands. */
16659 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
16660 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
16661
16662 /* "neighbor description" commands. */
16663 install_element(BGP_NODE, &neighbor_description_cmd);
16664 install_element(BGP_NODE, &no_neighbor_description_cmd);
16665 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
16666
16667 /* "neighbor update-source" commands. "*/
16668 install_element(BGP_NODE, &neighbor_update_source_cmd);
16669 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
16670
16671 /* "neighbor default-originate" commands. */
16672 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
16673 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
16674 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
16675 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
16676 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
16677 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
16678 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
16679 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
16680 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
16681 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
16682 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
16683 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
16684 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
16685 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
16686 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
16687 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
16688 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
16689 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
16690 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
16691 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
16692 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
16693
16694 /* "neighbor port" commands. */
16695 install_element(BGP_NODE, &neighbor_port_cmd);
16696 install_element(BGP_NODE, &no_neighbor_port_cmd);
16697
16698 /* "neighbor weight" commands. */
16699 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
16700 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
16701
16702 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
16703 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
16704 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
16705 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
16706 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
16707 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
16708 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
16709 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
16710 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
16711 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
16712 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
16713 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
16714 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
16715 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
16716 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
16717 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
16718
16719 /* "neighbor override-capability" commands. */
16720 install_element(BGP_NODE, &neighbor_override_capability_cmd);
16721 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
16722
16723 /* "neighbor strict-capability-match" commands. */
16724 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
16725 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
16726
16727 /* "neighbor timers" commands. */
16728 install_element(BGP_NODE, &neighbor_timers_cmd);
16729 install_element(BGP_NODE, &no_neighbor_timers_cmd);
16730
16731 /* "neighbor timers connect" commands. */
16732 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
16733 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
16734
16735 /* "neighbor advertisement-interval" commands. */
16736 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
16737 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
16738
16739 /* "neighbor interface" commands. */
16740 install_element(BGP_NODE, &neighbor_interface_cmd);
16741 install_element(BGP_NODE, &no_neighbor_interface_cmd);
16742
16743 /* "neighbor distribute" commands. */
16744 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
16745 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
16746 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
16747 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
16748 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
16749 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
16750 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
16751 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
16752 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
16753 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
16754 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
16755 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
16756 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
16757 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
16758 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
16759 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
16760 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
16761 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
16762
16763 /* "neighbor prefix-list" commands. */
16764 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
16765 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
16766 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
16767 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
16768 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
16769 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
16770 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
16771 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
16772 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
16773 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
16774 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
16775 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
16776 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
16777 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
16778 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
16779 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
16780 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
16781 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
16782 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
16783 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
16784 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
16785 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
16786
16787 /* "neighbor filter-list" commands. */
16788 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
16789 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
16790 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
16791 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
16792 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
16793 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
16794 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
16795 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
16796 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
16797 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
16798 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
16799 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
16800 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
16801 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
16802 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
16803 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
16804 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
16805 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
16806 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
16807 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
16808 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
16809 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
16810
16811 /* "neighbor route-map" commands. */
16812 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
16813 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
16814 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
16815 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
16816 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
16817 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
16818 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
16819 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
16820 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
16821 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
16822 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
16823 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
16824 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
16825 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
16826 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
16827 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
16828 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
16829 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
16830 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
16831 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
16832 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
16833 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
16834 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
16835 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
16836
16837 /* "neighbor unsuppress-map" commands. */
16838 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
16839 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
16840 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
16841 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
16842 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
16843 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
16844 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
16845 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
16846 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
16847 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
16848 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
16849 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
16850 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
16851 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
16852 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
16853 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
16854 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
16855 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
16856
16857 /* neighbor maximum-prefix-out commands. */
16858 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
16859 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
16860 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
16861 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
16862 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
16863 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
16864 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
16865 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
16866 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
16867 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
16868 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
16869 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
16870 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
16871 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
16872 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
16873 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
16874 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
16875 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
16876
16877 /* "neighbor maximum-prefix" commands. */
16878 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
16879 install_element(BGP_NODE,
16880 &neighbor_maximum_prefix_threshold_hidden_cmd);
16881 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
16882 install_element(BGP_NODE,
16883 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
16884 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
16885 install_element(BGP_NODE,
16886 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
16887 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
16888 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
16889 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
16890 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
16891 install_element(BGP_IPV4_NODE,
16892 &neighbor_maximum_prefix_threshold_warning_cmd);
16893 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
16894 install_element(BGP_IPV4_NODE,
16895 &neighbor_maximum_prefix_threshold_restart_cmd);
16896 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
16897 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
16898 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
16899 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
16900 install_element(BGP_IPV4M_NODE,
16901 &neighbor_maximum_prefix_threshold_warning_cmd);
16902 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
16903 install_element(BGP_IPV4M_NODE,
16904 &neighbor_maximum_prefix_threshold_restart_cmd);
16905 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
16906 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
16907 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
16908 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
16909 install_element(BGP_IPV4L_NODE,
16910 &neighbor_maximum_prefix_threshold_warning_cmd);
16911 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
16912 install_element(BGP_IPV4L_NODE,
16913 &neighbor_maximum_prefix_threshold_restart_cmd);
16914 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
16915 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
16916 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
16917 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
16918 install_element(BGP_IPV6_NODE,
16919 &neighbor_maximum_prefix_threshold_warning_cmd);
16920 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
16921 install_element(BGP_IPV6_NODE,
16922 &neighbor_maximum_prefix_threshold_restart_cmd);
16923 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
16924 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
16925 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
16926 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
16927 install_element(BGP_IPV6M_NODE,
16928 &neighbor_maximum_prefix_threshold_warning_cmd);
16929 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
16930 install_element(BGP_IPV6M_NODE,
16931 &neighbor_maximum_prefix_threshold_restart_cmd);
16932 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
16933 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
16934 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
16935 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
16936 install_element(BGP_IPV6L_NODE,
16937 &neighbor_maximum_prefix_threshold_warning_cmd);
16938 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
16939 install_element(BGP_IPV6L_NODE,
16940 &neighbor_maximum_prefix_threshold_restart_cmd);
16941 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
16942 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
16943 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
16944 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
16945 install_element(BGP_VPNV4_NODE,
16946 &neighbor_maximum_prefix_threshold_warning_cmd);
16947 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
16948 install_element(BGP_VPNV4_NODE,
16949 &neighbor_maximum_prefix_threshold_restart_cmd);
16950 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
16951 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
16952 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
16953 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
16954 install_element(BGP_VPNV6_NODE,
16955 &neighbor_maximum_prefix_threshold_warning_cmd);
16956 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
16957 install_element(BGP_VPNV6_NODE,
16958 &neighbor_maximum_prefix_threshold_restart_cmd);
16959 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
16960
16961 /* "neighbor allowas-in" */
16962 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
16963 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
16964 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
16965 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
16966 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
16967 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
16968 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
16969 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
16970 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
16971 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
16972 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
16973 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
16974 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
16975 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
16976 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
16977 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
16978 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
16979 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
16980 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
16981 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
16982
16983 /* address-family commands. */
16984 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
16985 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
16986 #ifdef KEEP_OLD_VPN_COMMANDS
16987 install_element(BGP_NODE, &address_family_vpnv4_cmd);
16988 install_element(BGP_NODE, &address_family_vpnv6_cmd);
16989 #endif /* KEEP_OLD_VPN_COMMANDS */
16990
16991 install_element(BGP_NODE, &address_family_evpn_cmd);
16992
16993 /* "exit-address-family" command. */
16994 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
16995 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
16996 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
16997 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
16998 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
16999 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
17000 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
17001 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
17002 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
17003 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
17004 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
17005
17006 /* "clear ip bgp commands" */
17007 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
17008
17009 /* clear ip bgp prefix */
17010 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
17011 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
17012 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
17013
17014 /* "show [ip] bgp summary" commands. */
17015 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
17016 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
17017 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
17018 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
17019 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
17020 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
17021 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
17022
17023 /* "show [ip] bgp neighbors" commands. */
17024 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
17025
17026 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
17027
17028 /* "show [ip] bgp peer-group" commands. */
17029 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
17030
17031 /* "show [ip] bgp paths" commands. */
17032 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
17033
17034 /* "show [ip] bgp community" commands. */
17035 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
17036
17037 /* "show ip bgp large-community" commands. */
17038 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
17039 /* "show [ip] bgp attribute-info" commands. */
17040 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
17041 /* "show [ip] bgp route-leak" command */
17042 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
17043
17044 /* "redistribute" commands. */
17045 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
17046 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
17047 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
17048 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
17049 install_element(BGP_NODE,
17050 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
17051 install_element(BGP_NODE,
17052 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
17053 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
17054 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
17055 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
17056 install_element(BGP_NODE,
17057 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
17058 install_element(BGP_NODE,
17059 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
17060 install_element(BGP_NODE,
17061 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
17062 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
17063 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
17064 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
17065 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
17066 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
17067 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
17068 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
17069 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
17070 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
17071 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
17072 install_element(BGP_IPV4_NODE,
17073 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
17074 install_element(BGP_IPV4_NODE,
17075 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
17076 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
17077 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
17078 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
17079 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
17080 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
17081 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
17082
17083 /* import|export vpn [route-map WORD] */
17084 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
17085 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
17086
17087 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
17088 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
17089
17090 /* ttl_security commands */
17091 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
17092 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
17093
17094 /* "show [ip] bgp memory" commands. */
17095 install_element(VIEW_NODE, &show_bgp_memory_cmd);
17096
17097 /* "show bgp martian next-hop" */
17098 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
17099
17100 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
17101
17102 /* "show [ip] bgp views" commands. */
17103 install_element(VIEW_NODE, &show_bgp_views_cmd);
17104
17105 /* "show [ip] bgp vrfs" commands. */
17106 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
17107
17108 /* Community-list. */
17109 community_list_vty();
17110
17111 /* vpn-policy commands */
17112 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
17113 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
17114 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
17115 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
17116 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
17117 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
17118 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
17119 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
17120 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
17121 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
17122 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
17123 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
17124
17125 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
17126 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
17127
17128 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
17129 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
17130 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
17131 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
17132 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
17133 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
17134 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
17135 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
17136 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
17137 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
17138 }
17139
17140 #include "memory.h"
17141 #include "bgp_regex.h"
17142 #include "bgp_clist.h"
17143 #include "bgp_ecommunity.h"
17144
17145 /* VTY functions. */
17146
17147 /* Direction value to string conversion. */
17148 static const char *community_direct_str(int direct)
17149 {
17150 switch (direct) {
17151 case COMMUNITY_DENY:
17152 return "deny";
17153 case COMMUNITY_PERMIT:
17154 return "permit";
17155 default:
17156 return "unknown";
17157 }
17158 }
17159
17160 /* Display error string. */
17161 static void community_list_perror(struct vty *vty, int ret)
17162 {
17163 switch (ret) {
17164 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
17165 vty_out(vty, "%% Can't find community-list\n");
17166 break;
17167 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
17168 vty_out(vty, "%% Malformed community-list value\n");
17169 break;
17170 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
17171 vty_out(vty,
17172 "%% Community name conflict, previously defined as standard community\n");
17173 break;
17174 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
17175 vty_out(vty,
17176 "%% Community name conflict, previously defined as expanded community\n");
17177 break;
17178 }
17179 }
17180
17181 /* "community-list" keyword help string. */
17182 #define COMMUNITY_LIST_STR "Add a community list entry\n"
17183
17184 /*community-list standard */
17185 DEFUN (community_list_standard,
17186 bgp_community_list_standard_cmd,
17187 "bgp community-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
17188 BGP_STR
17189 COMMUNITY_LIST_STR
17190 "Community list number (standard)\n"
17191 "Add an standard community-list entry\n"
17192 "Community list name\n"
17193 "Sequence number of an entry\n"
17194 "Sequence number\n"
17195 "Specify community to reject\n"
17196 "Specify community to accept\n"
17197 COMMUNITY_VAL_STR)
17198 {
17199 char *cl_name_or_number = NULL;
17200 char *seq = NULL;
17201 int direct = 0;
17202 int style = COMMUNITY_LIST_STANDARD;
17203 int idx = 0;
17204
17205 argv_find(argv, argc, "(1-4294967295)", &idx);
17206 if (idx)
17207 seq = argv[idx]->arg;
17208
17209 idx = 0;
17210 argv_find(argv, argc, "(1-99)", &idx);
17211 argv_find(argv, argc, "WORD", &idx);
17212 cl_name_or_number = argv[idx]->arg;
17213 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
17214 : COMMUNITY_DENY;
17215 argv_find(argv, argc, "AA:NN", &idx);
17216 char *str = argv_concat(argv, argc, idx);
17217
17218 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
17219 direct, style);
17220
17221 XFREE(MTYPE_TMP, str);
17222
17223 if (ret < 0) {
17224 /* Display error string. */
17225 community_list_perror(vty, ret);
17226 return CMD_WARNING_CONFIG_FAILED;
17227 }
17228
17229 return CMD_SUCCESS;
17230 }
17231
17232 DEFUN (no_community_list_standard_all,
17233 no_bgp_community_list_standard_all_cmd,
17234 "no bgp community-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
17235 NO_STR
17236 BGP_STR
17237 COMMUNITY_LIST_STR
17238 "Community list number (standard)\n"
17239 "Add an standard community-list entry\n"
17240 "Community list name\n"
17241 "Sequence number of an entry\n"
17242 "Sequence number\n"
17243 "Specify community to reject\n"
17244 "Specify community to accept\n"
17245 COMMUNITY_VAL_STR)
17246 {
17247 char *cl_name_or_number = NULL;
17248 char *str = NULL;
17249 int direct = 0;
17250 int style = COMMUNITY_LIST_STANDARD;
17251 char *seq = NULL;
17252 int idx = 0;
17253
17254 argv_find(argv, argc, "(1-4294967295)", &idx);
17255 if (idx)
17256 seq = argv[idx]->arg;
17257
17258 idx = 0;
17259 argv_find(argv, argc, "permit", &idx);
17260 argv_find(argv, argc, "deny", &idx);
17261
17262 if (idx) {
17263 direct = argv_find(argv, argc, "permit", &idx)
17264 ? COMMUNITY_PERMIT
17265 : COMMUNITY_DENY;
17266
17267 idx = 0;
17268 argv_find(argv, argc, "AA:NN", &idx);
17269 str = argv_concat(argv, argc, idx);
17270 }
17271
17272 idx = 0;
17273 argv_find(argv, argc, "(1-99)", &idx);
17274 argv_find(argv, argc, "WORD", &idx);
17275 cl_name_or_number = argv[idx]->arg;
17276
17277 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
17278 direct, style);
17279
17280 XFREE(MTYPE_TMP, str);
17281
17282 if (ret < 0) {
17283 community_list_perror(vty, ret);
17284 return CMD_WARNING_CONFIG_FAILED;
17285 }
17286
17287 return CMD_SUCCESS;
17288 }
17289
17290 ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
17291 "no bgp community-list <(1-99)|standard WORD>",
17292 NO_STR BGP_STR COMMUNITY_LIST_STR
17293 "Community list number (standard)\n"
17294 "Add an standard community-list entry\n"
17295 "Community list name\n")
17296
17297 /*community-list expanded */
17298 DEFUN (community_list_expanded_all,
17299 bgp_community_list_expanded_all_cmd,
17300 "bgp community-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
17301 BGP_STR
17302 COMMUNITY_LIST_STR
17303 "Community list number (expanded)\n"
17304 "Add an expanded community-list entry\n"
17305 "Community list name\n"
17306 "Sequence number of an entry\n"
17307 "Sequence number\n"
17308 "Specify community to reject\n"
17309 "Specify community to accept\n"
17310 COMMUNITY_VAL_STR)
17311 {
17312 char *cl_name_or_number = NULL;
17313 char *seq = NULL;
17314 int direct = 0;
17315 int style = COMMUNITY_LIST_EXPANDED;
17316 int idx = 0;
17317
17318 argv_find(argv, argc, "(1-4294967295)", &idx);
17319 if (idx)
17320 seq = argv[idx]->arg;
17321
17322 idx = 0;
17323
17324 argv_find(argv, argc, "(100-500)", &idx);
17325 argv_find(argv, argc, "WORD", &idx);
17326 cl_name_or_number = argv[idx]->arg;
17327 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
17328 : COMMUNITY_DENY;
17329 argv_find(argv, argc, "AA:NN", &idx);
17330 char *str = argv_concat(argv, argc, idx);
17331
17332 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
17333 direct, style);
17334
17335 XFREE(MTYPE_TMP, str);
17336
17337 if (ret < 0) {
17338 /* Display error string. */
17339 community_list_perror(vty, ret);
17340 return CMD_WARNING_CONFIG_FAILED;
17341 }
17342
17343 return CMD_SUCCESS;
17344 }
17345
17346 DEFUN (no_community_list_expanded_all,
17347 no_bgp_community_list_expanded_all_cmd,
17348 "no bgp community-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
17349 NO_STR
17350 BGP_STR
17351 COMMUNITY_LIST_STR
17352 "Community list number (expanded)\n"
17353 "Add an expanded community-list entry\n"
17354 "Community list name\n"
17355 "Sequence number of an entry\n"
17356 "Sequence number\n"
17357 "Specify community to reject\n"
17358 "Specify community to accept\n"
17359 COMMUNITY_VAL_STR)
17360 {
17361 char *cl_name_or_number = NULL;
17362 char *seq = NULL;
17363 char *str = NULL;
17364 int direct = 0;
17365 int style = COMMUNITY_LIST_EXPANDED;
17366 int idx = 0;
17367
17368 argv_find(argv, argc, "(1-4294967295)", &idx);
17369 if (idx)
17370 seq = argv[idx]->arg;
17371
17372 idx = 0;
17373 argv_find(argv, argc, "permit", &idx);
17374 argv_find(argv, argc, "deny", &idx);
17375
17376 if (idx) {
17377 direct = argv_find(argv, argc, "permit", &idx)
17378 ? COMMUNITY_PERMIT
17379 : COMMUNITY_DENY;
17380
17381 idx = 0;
17382 argv_find(argv, argc, "AA:NN", &idx);
17383 str = argv_concat(argv, argc, idx);
17384 }
17385
17386 idx = 0;
17387 argv_find(argv, argc, "(100-500)", &idx);
17388 argv_find(argv, argc, "WORD", &idx);
17389 cl_name_or_number = argv[idx]->arg;
17390
17391 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
17392 direct, style);
17393
17394 XFREE(MTYPE_TMP, str);
17395
17396 if (ret < 0) {
17397 community_list_perror(vty, ret);
17398 return CMD_WARNING_CONFIG_FAILED;
17399 }
17400
17401 return CMD_SUCCESS;
17402 }
17403
17404 ALIAS(no_community_list_expanded_all, no_bgp_community_list_expanded_all_list_cmd,
17405 "no bgp community-list <(100-500)|expanded WORD>",
17406 NO_STR IP_STR COMMUNITY_LIST_STR
17407 "Community list number (expanded)\n"
17408 "Add an expanded community-list entry\n"
17409 "Community list name\n")
17410
17411 /* Return configuration string of community-list entry. */
17412 static const char *community_list_config_str(struct community_entry *entry)
17413 {
17414 const char *str;
17415
17416 if (entry->any)
17417 str = "";
17418 else {
17419 if (entry->style == COMMUNITY_LIST_STANDARD)
17420 str = community_str(entry->u.com, false);
17421 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
17422 str = lcommunity_str(entry->u.lcom, false);
17423 else
17424 str = entry->config;
17425 }
17426 return str;
17427 }
17428
17429 static void community_list_show(struct vty *vty, struct community_list *list)
17430 {
17431 struct community_entry *entry;
17432
17433 for (entry = list->head; entry; entry = entry->next) {
17434 if (entry == list->head) {
17435 if (all_digit(list->name))
17436 vty_out(vty, "Community %s list %s\n",
17437 entry->style == COMMUNITY_LIST_STANDARD
17438 ? "standard"
17439 : "(expanded) access",
17440 list->name);
17441 else
17442 vty_out(vty, "Named Community %s list %s\n",
17443 entry->style == COMMUNITY_LIST_STANDARD
17444 ? "standard"
17445 : "expanded",
17446 list->name);
17447 }
17448 if (entry->any)
17449 vty_out(vty, " %s\n",
17450 community_direct_str(entry->direct));
17451 else
17452 vty_out(vty, " %s %s\n",
17453 community_direct_str(entry->direct),
17454 community_list_config_str(entry));
17455 }
17456 }
17457
17458 DEFUN (show_community_list,
17459 show_bgp_community_list_cmd,
17460 "show bgp community-list",
17461 SHOW_STR
17462 BGP_STR
17463 "List community-list\n")
17464 {
17465 struct community_list *list;
17466 struct community_list_master *cm;
17467
17468 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
17469 if (!cm)
17470 return CMD_SUCCESS;
17471
17472 for (list = cm->num.head; list; list = list->next)
17473 community_list_show(vty, list);
17474
17475 for (list = cm->str.head; list; list = list->next)
17476 community_list_show(vty, list);
17477
17478 return CMD_SUCCESS;
17479 }
17480
17481 DEFUN (show_community_list_arg,
17482 show_bgp_community_list_arg_cmd,
17483 "show bgp community-list <(1-500)|WORD> detail",
17484 SHOW_STR
17485 BGP_STR
17486 "List community-list\n"
17487 "Community-list number\n"
17488 "Community-list name\n"
17489 "Detailed information on community-list\n")
17490 {
17491 int idx_comm_list = 3;
17492 struct community_list *list;
17493
17494 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
17495 COMMUNITY_LIST_MASTER);
17496 if (!list) {
17497 vty_out(vty, "%% Can't find community-list\n");
17498 return CMD_WARNING;
17499 }
17500
17501 community_list_show(vty, list);
17502
17503 return CMD_SUCCESS;
17504 }
17505
17506 /*
17507 * Large Community code.
17508 */
17509 static int lcommunity_list_set_vty(struct vty *vty, int argc,
17510 struct cmd_token **argv, int style,
17511 int reject_all_digit_name)
17512 {
17513 int ret;
17514 int direct;
17515 char *str;
17516 int idx = 0;
17517 char *cl_name;
17518 char *seq = NULL;
17519
17520 if (argv_find(argv, argc, "(1-4294967295)", &idx))
17521 seq = argv[idx]->arg;
17522
17523 idx = 0;
17524 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
17525 : COMMUNITY_DENY;
17526
17527 /* All digit name check. */
17528 idx = 0;
17529 argv_find(argv, argc, "WORD", &idx);
17530 argv_find(argv, argc, "(1-99)", &idx);
17531 argv_find(argv, argc, "(100-500)", &idx);
17532 cl_name = argv[idx]->arg;
17533 if (reject_all_digit_name && all_digit(cl_name)) {
17534 vty_out(vty, "%% Community name cannot have all digits\n");
17535 return CMD_WARNING_CONFIG_FAILED;
17536 }
17537
17538 idx = 0;
17539 argv_find(argv, argc, "AA:BB:CC", &idx);
17540 argv_find(argv, argc, "LINE", &idx);
17541 /* Concat community string argument. */
17542 if (idx)
17543 str = argv_concat(argv, argc, idx);
17544 else
17545 str = NULL;
17546
17547 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
17548
17549 /* Free temporary community list string allocated by
17550 argv_concat(). */
17551 XFREE(MTYPE_TMP, str);
17552
17553 if (ret < 0) {
17554 community_list_perror(vty, ret);
17555 return CMD_WARNING_CONFIG_FAILED;
17556 }
17557 return CMD_SUCCESS;
17558 }
17559
17560 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
17561 struct cmd_token **argv, int style)
17562 {
17563 int ret;
17564 int direct = 0;
17565 char *str = NULL;
17566 int idx = 0;
17567 char *seq = NULL;
17568
17569 if (argv_find(argv, argc, "(1-4294967295)", &idx))
17570 seq = argv[idx]->arg;
17571
17572 idx = 0;
17573 argv_find(argv, argc, "permit", &idx);
17574 argv_find(argv, argc, "deny", &idx);
17575
17576 if (idx) {
17577 /* Check the list direct. */
17578 if (strncmp(argv[idx]->arg, "p", 1) == 0)
17579 direct = COMMUNITY_PERMIT;
17580 else
17581 direct = COMMUNITY_DENY;
17582
17583 idx = 0;
17584 argv_find(argv, argc, "LINE", &idx);
17585 argv_find(argv, argc, "AA:AA:NN", &idx);
17586 /* Concat community string argument. */
17587 str = argv_concat(argv, argc, idx);
17588 }
17589
17590 idx = 0;
17591 argv_find(argv, argc, "(1-99)", &idx);
17592 argv_find(argv, argc, "(100-500)", &idx);
17593 argv_find(argv, argc, "WORD", &idx);
17594
17595 /* Unset community list. */
17596 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
17597 style);
17598
17599 /* Free temporary community list string allocated by
17600 argv_concat(). */
17601 XFREE(MTYPE_TMP, str);
17602
17603 if (ret < 0) {
17604 community_list_perror(vty, ret);
17605 return CMD_WARNING_CONFIG_FAILED;
17606 }
17607
17608 return CMD_SUCCESS;
17609 }
17610
17611 /* "large-community-list" keyword help string. */
17612 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
17613 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
17614
17615 DEFUN (lcommunity_list_standard,
17616 bgp_lcommunity_list_standard_cmd,
17617 "bgp large-community-list (1-99) [seq (1-4294967295)] <deny|permit> AA:BB:CC...",
17618 BGP_STR
17619 LCOMMUNITY_LIST_STR
17620 "Large Community list number (standard)\n"
17621 "Sequence number of an entry\n"
17622 "Sequence number\n"
17623 "Specify large community to reject\n"
17624 "Specify large community to accept\n"
17625 LCOMMUNITY_VAL_STR)
17626 {
17627 return lcommunity_list_set_vty(vty, argc, argv,
17628 LARGE_COMMUNITY_LIST_STANDARD, 0);
17629 }
17630
17631 DEFUN (lcommunity_list_expanded,
17632 bgp_lcommunity_list_expanded_cmd,
17633 "bgp large-community-list (100-500) [seq (1-4294967295)] <deny|permit> LINE...",
17634 BGP_STR
17635 LCOMMUNITY_LIST_STR
17636 "Large Community list number (expanded)\n"
17637 "Sequence number of an entry\n"
17638 "Sequence number\n"
17639 "Specify large community to reject\n"
17640 "Specify large community to accept\n"
17641 "An ordered list as a regular-expression\n")
17642 {
17643 return lcommunity_list_set_vty(vty, argc, argv,
17644 LARGE_COMMUNITY_LIST_EXPANDED, 0);
17645 }
17646
17647 DEFUN (lcommunity_list_name_standard,
17648 bgp_lcommunity_list_name_standard_cmd,
17649 "bgp large-community-list standard WORD [seq (1-4294967295)] <deny|permit> AA:BB:CC...",
17650 BGP_STR
17651 LCOMMUNITY_LIST_STR
17652 "Specify standard large-community-list\n"
17653 "Large Community list name\n"
17654 "Sequence number of an entry\n"
17655 "Sequence number\n"
17656 "Specify large community to reject\n"
17657 "Specify large community to accept\n"
17658 LCOMMUNITY_VAL_STR)
17659 {
17660 return lcommunity_list_set_vty(vty, argc, argv,
17661 LARGE_COMMUNITY_LIST_STANDARD, 1);
17662 }
17663
17664 DEFUN (lcommunity_list_name_expanded,
17665 bgp_lcommunity_list_name_expanded_cmd,
17666 "bgp large-community-list expanded WORD [seq (1-4294967295)] <deny|permit> LINE...",
17667 BGP_STR
17668 LCOMMUNITY_LIST_STR
17669 "Specify expanded large-community-list\n"
17670 "Large Community list name\n"
17671 "Sequence number of an entry\n"
17672 "Sequence number\n"
17673 "Specify large community to reject\n"
17674 "Specify large community to accept\n"
17675 "An ordered list as a regular-expression\n")
17676 {
17677 return lcommunity_list_set_vty(vty, argc, argv,
17678 LARGE_COMMUNITY_LIST_EXPANDED, 1);
17679 }
17680
17681 DEFUN (no_lcommunity_list_all,
17682 no_bgp_lcommunity_list_all_cmd,
17683 "no bgp large-community-list <(1-99)|(100-500)|WORD>",
17684 NO_STR
17685 BGP_STR
17686 LCOMMUNITY_LIST_STR
17687 "Large Community list number (standard)\n"
17688 "Large Community list number (expanded)\n"
17689 "Large Community list name\n")
17690 {
17691 return lcommunity_list_unset_vty(vty, argc, argv,
17692 LARGE_COMMUNITY_LIST_STANDARD);
17693 }
17694
17695 DEFUN (no_lcommunity_list_name_standard_all,
17696 no_bgp_lcommunity_list_name_standard_all_cmd,
17697 "no bgp large-community-list standard WORD",
17698 NO_STR
17699 BGP_STR
17700 LCOMMUNITY_LIST_STR
17701 "Specify standard large-community-list\n"
17702 "Large Community list name\n")
17703 {
17704 return lcommunity_list_unset_vty(vty, argc, argv,
17705 LARGE_COMMUNITY_LIST_STANDARD);
17706 }
17707
17708 DEFUN (no_lcommunity_list_name_expanded_all,
17709 no_bgp_lcommunity_list_name_expanded_all_cmd,
17710 "no bgp large-community-list expanded WORD",
17711 NO_STR
17712 BGP_STR
17713 LCOMMUNITY_LIST_STR
17714 "Specify expanded large-community-list\n"
17715 "Large Community list name\n")
17716 {
17717 return lcommunity_list_unset_vty(vty, argc, argv,
17718 LARGE_COMMUNITY_LIST_EXPANDED);
17719 }
17720
17721 DEFUN (no_lcommunity_list_standard,
17722 no_bgp_lcommunity_list_standard_cmd,
17723 "no bgp large-community-list (1-99) [seq (1-4294967295)] <deny|permit> AA:AA:NN...",
17724 NO_STR
17725 BGP_STR
17726 LCOMMUNITY_LIST_STR
17727 "Large Community list number (standard)\n"
17728 "Sequence number of an entry\n"
17729 "Sequence number\n"
17730 "Specify large community to reject\n"
17731 "Specify large community to accept\n"
17732 LCOMMUNITY_VAL_STR)
17733 {
17734 return lcommunity_list_unset_vty(vty, argc, argv,
17735 LARGE_COMMUNITY_LIST_STANDARD);
17736 }
17737
17738 DEFUN (no_lcommunity_list_expanded,
17739 no_bgp_lcommunity_list_expanded_cmd,
17740 "no bgp large-community-list (100-500) [seq (1-4294967295)] <deny|permit> LINE...",
17741 NO_STR
17742 BGP_STR
17743 LCOMMUNITY_LIST_STR
17744 "Large Community list number (expanded)\n"
17745 "Sequence number of an entry\n"
17746 "Sequence number\n"
17747 "Specify large community to reject\n"
17748 "Specify large community to accept\n"
17749 "An ordered list as a regular-expression\n")
17750 {
17751 return lcommunity_list_unset_vty(vty, argc, argv,
17752 LARGE_COMMUNITY_LIST_EXPANDED);
17753 }
17754
17755 DEFUN (no_lcommunity_list_name_standard,
17756 no_bgp_lcommunity_list_name_standard_cmd,
17757 "no bgp large-community-list standard WORD [seq (1-4294967295)] <deny|permit> AA:AA:NN...",
17758 NO_STR
17759 BGP_STR
17760 LCOMMUNITY_LIST_STR
17761 "Specify standard large-community-list\n"
17762 "Large Community list name\n"
17763 "Sequence number of an entry\n"
17764 "Sequence number\n"
17765 "Specify large community to reject\n"
17766 "Specify large community to accept\n"
17767 LCOMMUNITY_VAL_STR)
17768 {
17769 return lcommunity_list_unset_vty(vty, argc, argv,
17770 LARGE_COMMUNITY_LIST_STANDARD);
17771 }
17772
17773 DEFUN (no_lcommunity_list_name_expanded,
17774 no_bgp_lcommunity_list_name_expanded_cmd,
17775 "no bgp large-community-list expanded WORD [seq (1-4294967295)] <deny|permit> LINE...",
17776 NO_STR
17777 BGP_STR
17778 LCOMMUNITY_LIST_STR
17779 "Specify expanded large-community-list\n"
17780 "Large community list name\n"
17781 "Sequence number of an entry\n"
17782 "Sequence number\n"
17783 "Specify large community to reject\n"
17784 "Specify large community to accept\n"
17785 "An ordered list as a regular-expression\n")
17786 {
17787 return lcommunity_list_unset_vty(vty, argc, argv,
17788 LARGE_COMMUNITY_LIST_EXPANDED);
17789 }
17790
17791 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
17792 {
17793 struct community_entry *entry;
17794
17795 for (entry = list->head; entry; entry = entry->next) {
17796 if (entry == list->head) {
17797 if (all_digit(list->name))
17798 vty_out(vty, "Large community %s list %s\n",
17799 entry->style ==
17800 LARGE_COMMUNITY_LIST_STANDARD
17801 ? "standard"
17802 : "(expanded) access",
17803 list->name);
17804 else
17805 vty_out(vty,
17806 "Named large community %s list %s\n",
17807 entry->style ==
17808 LARGE_COMMUNITY_LIST_STANDARD
17809 ? "standard"
17810 : "expanded",
17811 list->name);
17812 }
17813 if (entry->any)
17814 vty_out(vty, " %s\n",
17815 community_direct_str(entry->direct));
17816 else
17817 vty_out(vty, " %s %s\n",
17818 community_direct_str(entry->direct),
17819 community_list_config_str(entry));
17820 }
17821 }
17822
17823 DEFUN (show_lcommunity_list,
17824 show_bgp_lcommunity_list_cmd,
17825 "show bgp large-community-list",
17826 SHOW_STR
17827 BGP_STR
17828 "List large-community list\n")
17829 {
17830 struct community_list *list;
17831 struct community_list_master *cm;
17832
17833 cm = community_list_master_lookup(bgp_clist,
17834 LARGE_COMMUNITY_LIST_MASTER);
17835 if (!cm)
17836 return CMD_SUCCESS;
17837
17838 for (list = cm->num.head; list; list = list->next)
17839 lcommunity_list_show(vty, list);
17840
17841 for (list = cm->str.head; list; list = list->next)
17842 lcommunity_list_show(vty, list);
17843
17844 return CMD_SUCCESS;
17845 }
17846
17847 DEFUN (show_lcommunity_list_arg,
17848 show_bgp_lcommunity_list_arg_cmd,
17849 "show bgp large-community-list <(1-500)|WORD> detail",
17850 SHOW_STR
17851 BGP_STR
17852 "List large-community list\n"
17853 "Large-community-list number\n"
17854 "Large-community-list name\n"
17855 "Detailed information on large-community-list\n")
17856 {
17857 struct community_list *list;
17858
17859 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
17860 LARGE_COMMUNITY_LIST_MASTER);
17861 if (!list) {
17862 vty_out(vty, "%% Can't find large-community-list\n");
17863 return CMD_WARNING;
17864 }
17865
17866 lcommunity_list_show(vty, list);
17867
17868 return CMD_SUCCESS;
17869 }
17870
17871 /* "extcommunity-list" keyword help string. */
17872 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
17873 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
17874
17875 DEFUN (extcommunity_list_standard,
17876 bgp_extcommunity_list_standard_cmd,
17877 "bgp extcommunity-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
17878 BGP_STR
17879 EXTCOMMUNITY_LIST_STR
17880 "Extended Community list number (standard)\n"
17881 "Specify standard extcommunity-list\n"
17882 "Community list name\n"
17883 "Sequence number of an entry\n"
17884 "Sequence number\n"
17885 "Specify community to reject\n"
17886 "Specify community to accept\n"
17887 EXTCOMMUNITY_VAL_STR)
17888 {
17889 int style = EXTCOMMUNITY_LIST_STANDARD;
17890 int direct = 0;
17891 char *cl_number_or_name = NULL;
17892 char *seq = NULL;
17893
17894 int idx = 0;
17895
17896 argv_find(argv, argc, "(1-99)", &idx);
17897 argv_find(argv, argc, "WORD", &idx);
17898 cl_number_or_name = argv[idx]->arg;
17899
17900 if (argv_find(argv, argc, "(1-4294967295)", &idx))
17901 seq = argv[idx]->arg;
17902
17903 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
17904 : COMMUNITY_DENY;
17905 argv_find(argv, argc, "AA:NN", &idx);
17906 char *str = argv_concat(argv, argc, idx);
17907
17908 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
17909 direct, style);
17910
17911 XFREE(MTYPE_TMP, str);
17912
17913 if (ret < 0) {
17914 community_list_perror(vty, ret);
17915 return CMD_WARNING_CONFIG_FAILED;
17916 }
17917
17918 return CMD_SUCCESS;
17919 }
17920
17921 DEFUN (extcommunity_list_name_expanded,
17922 bgp_extcommunity_list_name_expanded_cmd,
17923 "bgp extcommunity-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> LINE...",
17924 BGP_STR
17925 EXTCOMMUNITY_LIST_STR
17926 "Extended Community list number (expanded)\n"
17927 "Specify expanded extcommunity-list\n"
17928 "Extended Community list name\n"
17929 "Sequence number of an entry\n"
17930 "Sequence number\n"
17931 "Specify community to reject\n"
17932 "Specify community to accept\n"
17933 "An ordered list as a regular-expression\n")
17934 {
17935 int style = EXTCOMMUNITY_LIST_EXPANDED;
17936 int direct = 0;
17937 char *cl_number_or_name = NULL;
17938 char *seq = NULL;
17939 int idx = 0;
17940
17941 argv_find(argv, argc, "(100-500)", &idx);
17942 argv_find(argv, argc, "WORD", &idx);
17943 cl_number_or_name = argv[idx]->arg;
17944
17945 if (argv_find(argv, argc, "(1-4294967295)", &idx))
17946 seq = argv[idx]->arg;
17947
17948 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
17949 : COMMUNITY_DENY;
17950 argv_find(argv, argc, "LINE", &idx);
17951 char *str = argv_concat(argv, argc, idx);
17952
17953 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
17954 direct, style);
17955
17956 XFREE(MTYPE_TMP, str);
17957
17958 if (ret < 0) {
17959 community_list_perror(vty, ret);
17960 return CMD_WARNING_CONFIG_FAILED;
17961 }
17962
17963 return CMD_SUCCESS;
17964 }
17965
17966 DEFUN (no_extcommunity_list_standard_all,
17967 no_bgp_extcommunity_list_standard_all_cmd,
17968 "no bgp extcommunity-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
17969 NO_STR
17970 BGP_STR
17971 EXTCOMMUNITY_LIST_STR
17972 "Extended Community list number (standard)\n"
17973 "Specify standard extcommunity-list\n"
17974 "Community list name\n"
17975 "Sequence number of an entry\n"
17976 "Sequence number\n"
17977 "Specify community to reject\n"
17978 "Specify community to accept\n"
17979 EXTCOMMUNITY_VAL_STR)
17980 {
17981 int style = EXTCOMMUNITY_LIST_STANDARD;
17982 int direct = 0;
17983 char *cl_number_or_name = NULL;
17984 char *str = NULL;
17985 char *seq = NULL;
17986 int idx = 0;
17987
17988 if (argv_find(argv, argc, "(1-4294967295)", &idx))
17989 seq = argv[idx]->arg;
17990
17991 idx = 0;
17992 argv_find(argv, argc, "permit", &idx);
17993 argv_find(argv, argc, "deny", &idx);
17994 if (idx) {
17995 direct = argv_find(argv, argc, "permit", &idx)
17996 ? COMMUNITY_PERMIT
17997 : COMMUNITY_DENY;
17998
17999 idx = 0;
18000 argv_find(argv, argc, "AA:NN", &idx);
18001 str = argv_concat(argv, argc, idx);
18002 }
18003
18004 idx = 0;
18005 argv_find(argv, argc, "(1-99)", &idx);
18006 argv_find(argv, argc, "WORD", &idx);
18007 cl_number_or_name = argv[idx]->arg;
18008
18009 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
18010 seq, direct, style);
18011
18012 XFREE(MTYPE_TMP, str);
18013
18014 if (ret < 0) {
18015 community_list_perror(vty, ret);
18016 return CMD_WARNING_CONFIG_FAILED;
18017 }
18018
18019 return CMD_SUCCESS;
18020 }
18021
18022 ALIAS(no_extcommunity_list_standard_all,
18023 no_bgp_extcommunity_list_standard_all_list_cmd,
18024 "no bgp extcommunity-list <(1-99)|standard WORD>",
18025 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
18026 "Extended Community list number (standard)\n"
18027 "Specify standard extcommunity-list\n"
18028 "Community list name\n")
18029
18030 DEFUN (no_extcommunity_list_expanded_all,
18031 no_bgp_extcommunity_list_expanded_all_cmd,
18032 "no bgp extcommunity-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> LINE...",
18033 NO_STR
18034 BGP_STR
18035 EXTCOMMUNITY_LIST_STR
18036 "Extended Community list number (expanded)\n"
18037 "Specify expanded extcommunity-list\n"
18038 "Extended Community list name\n"
18039 "Sequence number of an entry\n"
18040 "Sequence number\n"
18041 "Specify community to reject\n"
18042 "Specify community to accept\n"
18043 "An ordered list as a regular-expression\n")
18044 {
18045 int style = EXTCOMMUNITY_LIST_EXPANDED;
18046 int direct = 0;
18047 char *cl_number_or_name = NULL;
18048 char *str = NULL;
18049 char *seq = NULL;
18050 int idx = 0;
18051
18052 if (argv_find(argv, argc, "(1-4294967295)", &idx))
18053 seq = argv[idx]->arg;
18054
18055 idx = 0;
18056 argv_find(argv, argc, "permit", &idx);
18057 argv_find(argv, argc, "deny", &idx);
18058
18059 if (idx) {
18060 direct = argv_find(argv, argc, "permit", &idx)
18061 ? COMMUNITY_PERMIT
18062 : COMMUNITY_DENY;
18063
18064 idx = 0;
18065 argv_find(argv, argc, "LINE", &idx);
18066 str = argv_concat(argv, argc, idx);
18067 }
18068
18069 idx = 0;
18070 argv_find(argv, argc, "(100-500)", &idx);
18071 argv_find(argv, argc, "WORD", &idx);
18072 cl_number_or_name = argv[idx]->arg;
18073
18074 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
18075 seq, direct, style);
18076
18077 XFREE(MTYPE_TMP, str);
18078
18079 if (ret < 0) {
18080 community_list_perror(vty, ret);
18081 return CMD_WARNING_CONFIG_FAILED;
18082 }
18083
18084 return CMD_SUCCESS;
18085 }
18086
18087 ALIAS(no_extcommunity_list_expanded_all,
18088 no_bgp_extcommunity_list_expanded_all_list_cmd,
18089 "no bgp extcommunity-list <(100-500)|expanded WORD>",
18090 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
18091 "Extended Community list number (expanded)\n"
18092 "Specify expanded extcommunity-list\n"
18093 "Extended Community list name\n")
18094
18095 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
18096 {
18097 struct community_entry *entry;
18098
18099 for (entry = list->head; entry; entry = entry->next) {
18100 if (entry == list->head) {
18101 if (all_digit(list->name))
18102 vty_out(vty, "Extended community %s list %s\n",
18103 entry->style == EXTCOMMUNITY_LIST_STANDARD
18104 ? "standard"
18105 : "(expanded) access",
18106 list->name);
18107 else
18108 vty_out(vty,
18109 "Named extended community %s list %s\n",
18110 entry->style == EXTCOMMUNITY_LIST_STANDARD
18111 ? "standard"
18112 : "expanded",
18113 list->name);
18114 }
18115 if (entry->any)
18116 vty_out(vty, " %s\n",
18117 community_direct_str(entry->direct));
18118 else
18119 vty_out(vty, " %s %s\n",
18120 community_direct_str(entry->direct),
18121 community_list_config_str(entry));
18122 }
18123 }
18124
18125 DEFUN (show_extcommunity_list,
18126 show_bgp_extcommunity_list_cmd,
18127 "show bgp extcommunity-list",
18128 SHOW_STR
18129 BGP_STR
18130 "List extended-community list\n")
18131 {
18132 struct community_list *list;
18133 struct community_list_master *cm;
18134
18135 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
18136 if (!cm)
18137 return CMD_SUCCESS;
18138
18139 for (list = cm->num.head; list; list = list->next)
18140 extcommunity_list_show(vty, list);
18141
18142 for (list = cm->str.head; list; list = list->next)
18143 extcommunity_list_show(vty, list);
18144
18145 return CMD_SUCCESS;
18146 }
18147
18148 DEFUN (show_extcommunity_list_arg,
18149 show_bgp_extcommunity_list_arg_cmd,
18150 "show bgp extcommunity-list <(1-500)|WORD> detail",
18151 SHOW_STR
18152 BGP_STR
18153 "List extended-community list\n"
18154 "Extcommunity-list number\n"
18155 "Extcommunity-list name\n"
18156 "Detailed information on extcommunity-list\n")
18157 {
18158 int idx_comm_list = 3;
18159 struct community_list *list;
18160
18161 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
18162 EXTCOMMUNITY_LIST_MASTER);
18163 if (!list) {
18164 vty_out(vty, "%% Can't find extcommunity-list\n");
18165 return CMD_WARNING;
18166 }
18167
18168 extcommunity_list_show(vty, list);
18169
18170 return CMD_SUCCESS;
18171 }
18172
18173 /* Display community-list and extcommunity-list configuration. */
18174 static int community_list_config_write(struct vty *vty)
18175 {
18176 struct community_list *list;
18177 struct community_entry *entry;
18178 struct community_list_master *cm;
18179 int write = 0;
18180
18181 /* Community-list. */
18182 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
18183
18184 for (list = cm->num.head; list; list = list->next)
18185 for (entry = list->head; entry; entry = entry->next) {
18186 vty_out(vty,
18187 "bgp community-list %s seq %" PRId64 " %s %s\n",
18188 list->name, entry->seq,
18189 community_direct_str(entry->direct),
18190 community_list_config_str(entry));
18191 write++;
18192 }
18193 for (list = cm->str.head; list; list = list->next)
18194 for (entry = list->head; entry; entry = entry->next) {
18195 vty_out(vty,
18196 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
18197 entry->style == COMMUNITY_LIST_STANDARD
18198 ? "standard"
18199 : "expanded",
18200 list->name, entry->seq,
18201 community_direct_str(entry->direct),
18202 community_list_config_str(entry));
18203 write++;
18204 }
18205
18206 /* Extcommunity-list. */
18207 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
18208
18209 for (list = cm->num.head; list; list = list->next)
18210 for (entry = list->head; entry; entry = entry->next) {
18211 vty_out(vty,
18212 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
18213 list->name, entry->seq,
18214 community_direct_str(entry->direct),
18215 community_list_config_str(entry));
18216 write++;
18217 }
18218 for (list = cm->str.head; list; list = list->next)
18219 for (entry = list->head; entry; entry = entry->next) {
18220 vty_out(vty,
18221 "bgp extcommunity-list %s %s seq %" PRId64" %s %s\n",
18222 entry->style == EXTCOMMUNITY_LIST_STANDARD
18223 ? "standard"
18224 : "expanded",
18225 list->name, entry->seq,
18226 community_direct_str(entry->direct),
18227 community_list_config_str(entry));
18228 write++;
18229 }
18230
18231
18232 /* lcommunity-list. */
18233 cm = community_list_master_lookup(bgp_clist,
18234 LARGE_COMMUNITY_LIST_MASTER);
18235
18236 for (list = cm->num.head; list; list = list->next)
18237 for (entry = list->head; entry; entry = entry->next) {
18238 vty_out(vty,
18239 "bgp large-community-list %s seq %" PRId64" %s %s\n",
18240 list->name, entry->seq,
18241 community_direct_str(entry->direct),
18242 community_list_config_str(entry));
18243 write++;
18244 }
18245 for (list = cm->str.head; list; list = list->next)
18246 for (entry = list->head; entry; entry = entry->next) {
18247 vty_out(vty,
18248 "bgp large-community-list %s %s seq %" PRId64" %s %s\n",
18249
18250 entry->style == LARGE_COMMUNITY_LIST_STANDARD
18251 ? "standard"
18252 : "expanded",
18253 list->name, entry->seq, community_direct_str(entry->direct),
18254 community_list_config_str(entry));
18255 write++;
18256 }
18257
18258 return write;
18259 }
18260
18261 static int community_list_config_write(struct vty *vty);
18262 static struct cmd_node community_list_node = {
18263 .name = "community list",
18264 .node = COMMUNITY_LIST_NODE,
18265 .prompt = "",
18266 .config_write = community_list_config_write,
18267 };
18268
18269 static void community_list_vty(void)
18270 {
18271 install_node(&community_list_node);
18272
18273 /* Community-list. */
18274 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
18275 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
18276 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
18277 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
18278 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
18279 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
18280 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
18281 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
18282
18283 /* Extcommunity-list. */
18284 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
18285 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
18286 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
18287 install_element(CONFIG_NODE,
18288 &no_bgp_extcommunity_list_standard_all_list_cmd);
18289 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
18290 install_element(CONFIG_NODE,
18291 &no_bgp_extcommunity_list_expanded_all_list_cmd);
18292 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
18293 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
18294
18295 /* Large Community List */
18296 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
18297 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
18298 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
18299 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
18300 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
18301 install_element(CONFIG_NODE,
18302 &no_bgp_lcommunity_list_name_standard_all_cmd);
18303 install_element(CONFIG_NODE,
18304 &no_bgp_lcommunity_list_name_expanded_all_cmd);
18305 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
18306 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
18307 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
18308 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
18309 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
18310 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
18311 }