]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
*: Use true/false instead of 1/0 when assigning variable for bool type
[mirror_frr.git] / bgpd / bgp_vty.c
1 /* BGP VTY interface.
2 * Copyright (C) 1996, 97, 98, 99, 2000 Kunihiro Ishiguro
3 *
4 * This file is part of GNU Zebra.
5 *
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
10 *
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include <zebra.h>
22
23 #include "command.h"
24 #include "lib/json.h"
25 #include "lib_errors.h"
26 #include "lib/zclient.h"
27 #include "prefix.h"
28 #include "plist.h"
29 #include "buffer.h"
30 #include "linklist.h"
31 #include "stream.h"
32 #include "thread.h"
33 #include "log.h"
34 #include "memory.h"
35 #include "lib_vty.h"
36 #include "hash.h"
37 #include "queue.h"
38 #include "filter.h"
39 #include "frrstr.h"
40
41 #include "bgpd/bgpd.h"
42 #include "bgpd/bgp_attr_evpn.h"
43 #include "bgpd/bgp_advertise.h"
44 #include "bgpd/bgp_attr.h"
45 #include "bgpd/bgp_aspath.h"
46 #include "bgpd/bgp_community.h"
47 #include "bgpd/bgp_ecommunity.h"
48 #include "bgpd/bgp_lcommunity.h"
49 #include "bgpd/bgp_damp.h"
50 #include "bgpd/bgp_debug.h"
51 #include "bgpd/bgp_errors.h"
52 #include "bgpd/bgp_fsm.h"
53 #include "bgpd/bgp_nexthop.h"
54 #include "bgpd/bgp_open.h"
55 #include "bgpd/bgp_regex.h"
56 #include "bgpd/bgp_route.h"
57 #include "bgpd/bgp_mplsvpn.h"
58 #include "bgpd/bgp_zebra.h"
59 #include "bgpd/bgp_table.h"
60 #include "bgpd/bgp_vty.h"
61 #include "bgpd/bgp_mpath.h"
62 #include "bgpd/bgp_packet.h"
63 #include "bgpd/bgp_updgrp.h"
64 #include "bgpd/bgp_bfd.h"
65 #include "bgpd/bgp_io.h"
66 #include "bgpd/bgp_evpn.h"
67 #include "bgpd/bgp_evpn_vty.h"
68 #include "bgpd/bgp_addpath.h"
69 #include "bgpd/bgp_mac.h"
70 #include "bgpd/bgp_flowspec.h"
71 #if ENABLE_BGP_VNC
72 #include "bgpd/rfapi/bgp_rfapi_cfg.h"
73 #endif
74
75 FRR_CFG_DEFAULT_BOOL(BGP_IMPORT_CHECK,
76 { .val_long = true, .match_profile = "datacenter", },
77 { .val_long = false },
78 )
79 FRR_CFG_DEFAULT_BOOL(BGP_SHOW_HOSTNAME,
80 { .val_long = true, .match_profile = "datacenter", },
81 { .val_long = false },
82 )
83 FRR_CFG_DEFAULT_BOOL(BGP_LOG_NEIGHBOR_CHANGES,
84 { .val_long = true, .match_profile = "datacenter", },
85 { .val_long = false },
86 )
87 FRR_CFG_DEFAULT_BOOL(BGP_DETERMINISTIC_MED,
88 { .val_long = true, .match_profile = "datacenter", },
89 { .val_long = false },
90 )
91 FRR_CFG_DEFAULT_ULONG(BGP_CONNECT_RETRY,
92 { .val_ulong = 10, .match_profile = "datacenter", },
93 { .val_ulong = 120 },
94 )
95 FRR_CFG_DEFAULT_ULONG(BGP_HOLDTIME,
96 { .val_ulong = 9, .match_profile = "datacenter", },
97 { .val_ulong = 180 },
98 )
99 FRR_CFG_DEFAULT_ULONG(BGP_KEEPALIVE,
100 { .val_ulong = 3, .match_profile = "datacenter", },
101 { .val_ulong = 60 },
102 )
103
104 DEFINE_HOOK(bgp_inst_config_write,
105 (struct bgp *bgp, struct vty *vty),
106 (bgp, vty))
107
108 #define GR_NO_OPER \
109 "The Graceful Restart No Operation was executed as cmd same as previous one."
110 #define GR_INVALID \
111 "The Graceful Restart command used is not valid at this moment."
112 static struct peer_group *listen_range_exists(struct bgp *bgp,
113 struct prefix *range, int exact);
114
115 /* Show BGP peer's information. */
116 enum show_type {
117 show_all,
118 show_peer,
119 show_ipv4_all,
120 show_ipv6_all,
121 show_ipv4_peer,
122 show_ipv6_peer
123 };
124
125 static struct peer_group *listen_range_exists(struct bgp *bgp,
126 struct prefix *range, int exact);
127
128 static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
129 struct bgp *bgp,
130 bool use_json,
131 json_object *json);
132
133 static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
134 enum show_type type,
135 const char *ip_str,
136 afi_t afi, bool use_json);
137
138 static enum node_type bgp_node_type(afi_t afi, safi_t safi)
139 {
140 switch (afi) {
141 case AFI_IP:
142 switch (safi) {
143 case SAFI_UNICAST:
144 return BGP_IPV4_NODE;
145 case SAFI_MULTICAST:
146 return BGP_IPV4M_NODE;
147 case SAFI_LABELED_UNICAST:
148 return BGP_IPV4L_NODE;
149 case SAFI_MPLS_VPN:
150 return BGP_VPNV4_NODE;
151 case SAFI_FLOWSPEC:
152 return BGP_FLOWSPECV4_NODE;
153 default:
154 /* not expected */
155 return BGP_IPV4_NODE;
156 }
157 break;
158 case AFI_IP6:
159 switch (safi) {
160 case SAFI_UNICAST:
161 return BGP_IPV6_NODE;
162 case SAFI_MULTICAST:
163 return BGP_IPV6M_NODE;
164 case SAFI_LABELED_UNICAST:
165 return BGP_IPV6L_NODE;
166 case SAFI_MPLS_VPN:
167 return BGP_VPNV6_NODE;
168 case SAFI_FLOWSPEC:
169 return BGP_FLOWSPECV6_NODE;
170 default:
171 /* not expected */
172 return BGP_IPV4_NODE;
173 }
174 break;
175 case AFI_L2VPN:
176 return BGP_EVPN_NODE;
177 case AFI_UNSPEC:
178 case AFI_MAX:
179 // We should never be here but to clarify the switch statement..
180 return BGP_IPV4_NODE;
181 }
182
183 // Impossible to happen
184 return BGP_IPV4_NODE;
185 }
186
187 static const char *get_afi_safi_vty_str(afi_t afi, safi_t safi)
188 {
189 if (afi == AFI_IP && safi == SAFI_UNICAST)
190 return "IPv4 Unicast";
191 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
192 return "IPv4 Multicast";
193 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
194 return "IPv4 Labeled Unicast";
195 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
196 return "IPv4 VPN";
197 else if (afi == AFI_IP && safi == SAFI_ENCAP)
198 return "IPv4 Encap";
199 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
200 return "IPv4 Flowspec";
201 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
202 return "IPv6 Unicast";
203 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
204 return "IPv6 Multicast";
205 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
206 return "IPv6 Labeled Unicast";
207 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
208 return "IPv6 VPN";
209 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
210 return "IPv6 Encap";
211 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
212 return "IPv6 Flowspec";
213 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
214 return "L2VPN EVPN";
215 else
216 return "Unknown";
217 }
218
219 /*
220 * Please note that we have intentionally camelCased
221 * the return strings here. So if you want
222 * to use this function, please ensure you
223 * are doing this within json output
224 */
225 static const char *get_afi_safi_json_str(afi_t afi, safi_t safi)
226 {
227 if (afi == AFI_IP && safi == SAFI_UNICAST)
228 return "ipv4Unicast";
229 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
230 return "ipv4Multicast";
231 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
232 return "ipv4LabeledUnicast";
233 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
234 return "ipv4Vpn";
235 else if (afi == AFI_IP && safi == SAFI_ENCAP)
236 return "ipv4Encap";
237 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
238 return "ipv4Flowspec";
239 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
240 return "ipv6Unicast";
241 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
242 return "ipv6Multicast";
243 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
244 return "ipv6LabeledUnicast";
245 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
246 return "ipv6Vpn";
247 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
248 return "ipv6Encap";
249 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
250 return "ipv6Flowspec";
251 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
252 return "l2VpnEvpn";
253 else
254 return "Unknown";
255 }
256
257 /* Utility function to get address family from current node. */
258 afi_t bgp_node_afi(struct vty *vty)
259 {
260 afi_t afi;
261 switch (vty->node) {
262 case BGP_IPV6_NODE:
263 case BGP_IPV6M_NODE:
264 case BGP_IPV6L_NODE:
265 case BGP_VPNV6_NODE:
266 case BGP_FLOWSPECV6_NODE:
267 afi = AFI_IP6;
268 break;
269 case BGP_EVPN_NODE:
270 afi = AFI_L2VPN;
271 break;
272 default:
273 afi = AFI_IP;
274 break;
275 }
276 return afi;
277 }
278
279 /* Utility function to get subsequent address family from current
280 node. */
281 safi_t bgp_node_safi(struct vty *vty)
282 {
283 safi_t safi;
284 switch (vty->node) {
285 case BGP_VPNV4_NODE:
286 case BGP_VPNV6_NODE:
287 safi = SAFI_MPLS_VPN;
288 break;
289 case BGP_IPV4M_NODE:
290 case BGP_IPV6M_NODE:
291 safi = SAFI_MULTICAST;
292 break;
293 case BGP_EVPN_NODE:
294 safi = SAFI_EVPN;
295 break;
296 case BGP_IPV4L_NODE:
297 case BGP_IPV6L_NODE:
298 safi = SAFI_LABELED_UNICAST;
299 break;
300 case BGP_FLOWSPECV4_NODE:
301 case BGP_FLOWSPECV6_NODE:
302 safi = SAFI_FLOWSPEC;
303 break;
304 default:
305 safi = SAFI_UNICAST;
306 break;
307 }
308 return safi;
309 }
310
311 /**
312 * Converts an AFI in string form to afi_t
313 *
314 * @param afi string, one of
315 * - "ipv4"
316 * - "ipv6"
317 * - "l2vpn"
318 * @return the corresponding afi_t
319 */
320 afi_t bgp_vty_afi_from_str(const char *afi_str)
321 {
322 afi_t afi = AFI_MAX; /* unknown */
323 if (strmatch(afi_str, "ipv4"))
324 afi = AFI_IP;
325 else if (strmatch(afi_str, "ipv6"))
326 afi = AFI_IP6;
327 else if (strmatch(afi_str, "l2vpn"))
328 afi = AFI_L2VPN;
329 return afi;
330 }
331
332 int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
333 afi_t *afi)
334 {
335 int ret = 0;
336 if (argv_find(argv, argc, "ipv4", index)) {
337 ret = 1;
338 if (afi)
339 *afi = AFI_IP;
340 } else if (argv_find(argv, argc, "ipv6", index)) {
341 ret = 1;
342 if (afi)
343 *afi = AFI_IP6;
344 } else if (argv_find(argv, argc, "l2vpn", index)) {
345 ret = 1;
346 if (afi)
347 *afi = AFI_L2VPN;
348 }
349 return ret;
350 }
351
352 /* supports <unicast|multicast|vpn|labeled-unicast> */
353 safi_t bgp_vty_safi_from_str(const char *safi_str)
354 {
355 safi_t safi = SAFI_MAX; /* unknown */
356 if (strmatch(safi_str, "multicast"))
357 safi = SAFI_MULTICAST;
358 else if (strmatch(safi_str, "unicast"))
359 safi = SAFI_UNICAST;
360 else if (strmatch(safi_str, "vpn"))
361 safi = SAFI_MPLS_VPN;
362 else if (strmatch(safi_str, "evpn"))
363 safi = SAFI_EVPN;
364 else if (strmatch(safi_str, "labeled-unicast"))
365 safi = SAFI_LABELED_UNICAST;
366 else if (strmatch(safi_str, "flowspec"))
367 safi = SAFI_FLOWSPEC;
368 return safi;
369 }
370
371 int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
372 safi_t *safi)
373 {
374 int ret = 0;
375 if (argv_find(argv, argc, "unicast", index)) {
376 ret = 1;
377 if (safi)
378 *safi = SAFI_UNICAST;
379 } else if (argv_find(argv, argc, "multicast", index)) {
380 ret = 1;
381 if (safi)
382 *safi = SAFI_MULTICAST;
383 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
384 ret = 1;
385 if (safi)
386 *safi = SAFI_LABELED_UNICAST;
387 } else if (argv_find(argv, argc, "vpn", index)) {
388 ret = 1;
389 if (safi)
390 *safi = SAFI_MPLS_VPN;
391 } else if (argv_find(argv, argc, "evpn", index)) {
392 ret = 1;
393 if (safi)
394 *safi = SAFI_EVPN;
395 } else if (argv_find(argv, argc, "flowspec", index)) {
396 ret = 1;
397 if (safi)
398 *safi = SAFI_FLOWSPEC;
399 }
400 return ret;
401 }
402
403 int bgp_get_vty(struct bgp **bgp, as_t *as, const char *name,
404 enum bgp_instance_type inst_type)
405 {
406 int ret = bgp_get(bgp, as, name, inst_type);
407
408 if (ret == BGP_CREATED) {
409 bgp_timers_set(*bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
410 DFLT_BGP_CONNECT_RETRY);
411
412 if (DFLT_BGP_IMPORT_CHECK)
413 SET_FLAG((*bgp)->flags, BGP_FLAG_IMPORT_CHECK);
414 if (DFLT_BGP_SHOW_HOSTNAME)
415 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_HOSTNAME);
416 if (DFLT_BGP_LOG_NEIGHBOR_CHANGES)
417 SET_FLAG((*bgp)->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
418 if (DFLT_BGP_DETERMINISTIC_MED)
419 SET_FLAG((*bgp)->flags, BGP_FLAG_DETERMINISTIC_MED);
420
421 ret = BGP_SUCCESS;
422 }
423 return ret;
424 }
425
426 /*
427 * bgp_vty_find_and_parse_afi_safi_bgp
428 *
429 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
430 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
431 * to appropriate values for the calling function. This is to allow the
432 * calling function to make decisions appropriate for the show command
433 * that is being parsed.
434 *
435 * The show commands are generally of the form:
436 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
437 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
438 *
439 * Since we use argv_find if the show command in particular doesn't have:
440 * [ip]
441 * [<view|vrf> VIEWVRFNAME]
442 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
443 * The command parsing should still be ok.
444 *
445 * vty -> The vty for the command so we can output some useful data in
446 * the event of a parse error in the vrf.
447 * argv -> The command tokens
448 * argc -> How many command tokens we have
449 * idx -> The current place in the command, generally should be 0 for this
450 * function
451 * afi -> The parsed afi if it was included in the show command, returned here
452 * safi -> The parsed safi if it was included in the show command, returned here
453 * bgp -> Pointer to the bgp data structure we need to fill in.
454 * use_json -> json is configured or not
455 *
456 * The function returns the correct location in the parse tree for the
457 * last token found.
458 *
459 * Returns 0 for failure to parse correctly, else the idx position of where
460 * it found the last token.
461 */
462 int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
463 struct cmd_token **argv, int argc,
464 int *idx, afi_t *afi, safi_t *safi,
465 struct bgp **bgp, bool use_json)
466 {
467 char *vrf_name = NULL;
468
469 assert(afi);
470 assert(safi);
471 assert(bgp);
472
473 if (argv_find(argv, argc, "ip", idx))
474 *afi = AFI_IP;
475
476 if (argv_find(argv, argc, "view", idx))
477 vrf_name = argv[*idx + 1]->arg;
478 else if (argv_find(argv, argc, "vrf", idx)) {
479 vrf_name = argv[*idx + 1]->arg;
480 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
481 vrf_name = NULL;
482 }
483 if (vrf_name) {
484 if (strmatch(vrf_name, "all"))
485 *bgp = NULL;
486 else {
487 *bgp = bgp_lookup_by_name(vrf_name);
488 if (!*bgp) {
489 if (use_json) {
490 json_object *json = NULL;
491 json = json_object_new_object();
492 json_object_string_add(
493 json, "warning",
494 "View/Vrf is unknown");
495 vty_out(vty, "%s\n",
496 json_object_to_json_string_ext(json,
497 JSON_C_TO_STRING_PRETTY));
498 json_object_free(json);
499 }
500 else
501 vty_out(vty, "View/Vrf %s is unknown\n",
502 vrf_name);
503 *idx = 0;
504 return 0;
505 }
506 }
507 } else {
508 *bgp = bgp_get_default();
509 if (!*bgp) {
510 if (use_json) {
511 json_object *json = NULL;
512 json = json_object_new_object();
513 json_object_string_add(
514 json, "warning",
515 "Default BGP instance not found");
516 vty_out(vty, "%s\n",
517 json_object_to_json_string_ext(json,
518 JSON_C_TO_STRING_PRETTY));
519 json_object_free(json);
520 }
521 else
522 vty_out(vty,
523 "Default BGP instance not found\n");
524 *idx = 0;
525 return 0;
526 }
527 }
528
529 if (argv_find_and_parse_afi(argv, argc, idx, afi))
530 argv_find_and_parse_safi(argv, argc, idx, safi);
531
532 *idx += 1;
533 return *idx;
534 }
535
536 static int peer_address_self_check(struct bgp *bgp, union sockunion *su)
537 {
538 struct interface *ifp = NULL;
539
540 if (su->sa.sa_family == AF_INET)
541 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
542 else if (su->sa.sa_family == AF_INET6)
543 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
544 su->sin6.sin6_scope_id,
545 bgp->vrf_id);
546
547 if (ifp)
548 return 1;
549
550 return 0;
551 }
552
553 /* Utility function for looking up peer from VTY. */
554 /* This is used only for configuration, so disallow if attempted on
555 * a dynamic neighbor.
556 */
557 static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
558 {
559 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
560 int ret;
561 union sockunion su;
562 struct peer *peer;
563
564 if (!bgp) {
565 return NULL;
566 }
567
568 ret = str2sockunion(ip_str, &su);
569 if (ret < 0) {
570 peer = peer_lookup_by_conf_if(bgp, ip_str);
571 if (!peer) {
572 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
573 == NULL) {
574 vty_out(vty,
575 "%% Malformed address or name: %s\n",
576 ip_str);
577 return NULL;
578 }
579 }
580 } else {
581 peer = peer_lookup(bgp, &su);
582 if (!peer) {
583 vty_out(vty,
584 "%% Specify remote-as or peer-group commands first\n");
585 return NULL;
586 }
587 if (peer_dynamic_neighbor(peer)) {
588 vty_out(vty,
589 "%% Operation not allowed on a dynamic neighbor\n");
590 return NULL;
591 }
592 }
593 return peer;
594 }
595
596 /* Utility function for looking up peer or peer group. */
597 /* This is used only for configuration, so disallow if attempted on
598 * a dynamic neighbor.
599 */
600 struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
601 {
602 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
603 int ret;
604 union sockunion su;
605 struct peer *peer = NULL;
606 struct peer_group *group = NULL;
607
608 if (!bgp) {
609 return NULL;
610 }
611
612 ret = str2sockunion(peer_str, &su);
613 if (ret == 0) {
614 /* IP address, locate peer. */
615 peer = peer_lookup(bgp, &su);
616 } else {
617 /* Not IP, could match either peer configured on interface or a
618 * group. */
619 peer = peer_lookup_by_conf_if(bgp, peer_str);
620 if (!peer)
621 group = peer_group_lookup(bgp, peer_str);
622 }
623
624 if (peer) {
625 if (peer_dynamic_neighbor(peer)) {
626 vty_out(vty,
627 "%% Operation not allowed on a dynamic neighbor\n");
628 return NULL;
629 }
630
631 return peer;
632 }
633
634 if (group)
635 return group->conf;
636
637 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
638
639 return NULL;
640 }
641
642 int bgp_vty_return(struct vty *vty, int ret)
643 {
644 const char *str = NULL;
645
646 switch (ret) {
647 case BGP_ERR_INVALID_VALUE:
648 str = "Invalid value";
649 break;
650 case BGP_ERR_INVALID_FLAG:
651 str = "Invalid flag";
652 break;
653 case BGP_ERR_PEER_GROUP_SHUTDOWN:
654 str = "Peer-group has been shutdown. Activate the peer-group first";
655 break;
656 case BGP_ERR_PEER_FLAG_CONFLICT:
657 str = "Can't set override-capability and strict-capability-match at the same time";
658 break;
659 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
660 str = "Specify remote-as or peer-group remote AS first";
661 break;
662 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
663 str = "Cannot change the peer-group. Deconfigure first";
664 break;
665 case BGP_ERR_PEER_GROUP_MISMATCH:
666 str = "Peer is not a member of this peer-group";
667 break;
668 case BGP_ERR_PEER_FILTER_CONFLICT:
669 str = "Prefix/distribute list can not co-exist";
670 break;
671 case BGP_ERR_NOT_INTERNAL_PEER:
672 str = "Invalid command. Not an internal neighbor";
673 break;
674 case BGP_ERR_REMOVE_PRIVATE_AS:
675 str = "remove-private-AS cannot be configured for IBGP peers";
676 break;
677 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
678 str = "Local-AS allowed only for EBGP peers";
679 break;
680 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
681 str = "Cannot have local-as same as BGP AS number";
682 break;
683 case BGP_ERR_TCPSIG_FAILED:
684 str = "Error while applying TCP-Sig to session(s)";
685 break;
686 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
687 str = "ebgp-multihop and ttl-security cannot be configured together";
688 break;
689 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
690 str = "ttl-security only allowed for EBGP peers";
691 break;
692 case BGP_ERR_AS_OVERRIDE:
693 str = "as-override cannot be configured for IBGP peers";
694 break;
695 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
696 str = "Invalid limit for number of dynamic neighbors";
697 break;
698 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
699 str = "Dynamic neighbor listen range already exists";
700 break;
701 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
702 str = "Operation not allowed on a dynamic neighbor";
703 break;
704 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
705 str = "Operation not allowed on a directly connected neighbor";
706 break;
707 case BGP_ERR_PEER_SAFI_CONFLICT:
708 str = GR_INVALID;
709 break;
710 case BGP_ERR_GR_INVALID_CMD:
711 str = "The Graceful Restart command used is not valid at this moment.";
712 break;
713 case BGP_ERR_GR_OPERATION_FAILED:
714 str = "The Graceful Restart Operation failed due to an err.";
715 break;
716 case BGP_GR_NO_OPERATION:
717 str = GR_NO_OPER;
718 break;
719 }
720 if (str) {
721 vty_out(vty, "%% %s\n", str);
722 return CMD_WARNING_CONFIG_FAILED;
723 }
724 return CMD_SUCCESS;
725 }
726
727 /* BGP clear sort. */
728 enum clear_sort {
729 clear_all,
730 clear_peer,
731 clear_group,
732 clear_external,
733 clear_as
734 };
735
736 static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
737 safi_t safi, int error)
738 {
739 switch (error) {
740 case BGP_ERR_AF_UNCONFIGURED:
741 vty_out(vty,
742 "%%BGP: Enable %s address family for the neighbor %s\n",
743 get_afi_safi_str(afi, safi, false), peer->host);
744 break;
745 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
746 vty_out(vty,
747 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
748 peer->host);
749 break;
750 default:
751 break;
752 }
753 }
754
755 static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi,
756 struct listnode **nnode, enum bgp_clear_type stype)
757 {
758 int ret = 0;
759
760 /* if afi/.safi not specified, spin thru all of them */
761 if ((afi == AFI_UNSPEC) && (safi == SAFI_UNSPEC)) {
762 afi_t tmp_afi;
763 safi_t tmp_safi;
764
765 FOREACH_AFI_SAFI (tmp_afi, tmp_safi) {
766 if (!peer->afc[tmp_afi][tmp_safi])
767 continue;
768
769 if (stype == BGP_CLEAR_SOFT_NONE)
770 ret = peer_clear(peer, nnode);
771 else
772 ret = peer_clear_soft(peer, tmp_afi, tmp_safi,
773 stype);
774 }
775 /* if afi specified and safi not, spin thru safis on this afi */
776 } else if (safi == SAFI_UNSPEC) {
777 safi_t tmp_safi;
778
779 for (tmp_safi = SAFI_UNICAST;
780 tmp_safi < SAFI_MAX; tmp_safi++) {
781 if (!peer->afc[afi][tmp_safi])
782 continue;
783
784 if (stype == BGP_CLEAR_SOFT_NONE)
785 ret = peer_clear(peer, nnode);
786 else
787 ret = peer_clear_soft(peer, afi,
788 tmp_safi, stype);
789 }
790 /* both afi/safi specified, let the caller know if not defined */
791 } else {
792 if (!peer->afc[afi][safi])
793 return 1;
794
795 if (stype == BGP_CLEAR_SOFT_NONE)
796 ret = peer_clear(peer, nnode);
797 else
798 ret = peer_clear_soft(peer, afi, safi, stype);
799 }
800
801 return ret;
802 }
803
804 /* `clear ip bgp' functions. */
805 static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
806 enum clear_sort sort, enum bgp_clear_type stype,
807 const char *arg)
808 {
809 int ret = 0;
810 bool found = false;
811 struct peer *peer;
812
813 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
814
815 /* Clear all neighbors. */
816 /*
817 * Pass along pointer to next node to peer_clear() when walking all
818 * nodes on the BGP instance as that may get freed if it is a
819 * doppelganger
820 */
821 if (sort == clear_all) {
822 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
823
824 bgp_peer_gr_flags_update(peer);
825
826 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
827 gr_router_detected = true;
828
829 ret = bgp_peer_clear(peer, afi, safi, &nnode,
830 stype);
831
832 if (ret < 0)
833 bgp_clear_vty_error(vty, peer, afi, safi, ret);
834 }
835
836 if (gr_router_detected
837 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
838 bgp_zebra_send_capabilities(bgp, false);
839 } else if (!gr_router_detected
840 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
841 bgp_zebra_send_capabilities(bgp, true);
842 }
843
844 /* This is to apply read-only mode on this clear. */
845 if (stype == BGP_CLEAR_SOFT_NONE)
846 bgp->update_delay_over = 0;
847
848 return CMD_SUCCESS;
849 }
850
851 /* Clear specified neighbor. */
852 if (sort == clear_peer) {
853 union sockunion su;
854
855 /* Make sockunion for lookup. */
856 ret = str2sockunion(arg, &su);
857 if (ret < 0) {
858 peer = peer_lookup_by_conf_if(bgp, arg);
859 if (!peer) {
860 peer = peer_lookup_by_hostname(bgp, arg);
861 if (!peer) {
862 vty_out(vty,
863 "Malformed address or name: %s\n",
864 arg);
865 return CMD_WARNING;
866 }
867 }
868 } else {
869 peer = peer_lookup(bgp, &su);
870 if (!peer) {
871 vty_out(vty,
872 "%%BGP: Unknown neighbor - \"%s\"\n",
873 arg);
874 return CMD_WARNING;
875 }
876 }
877
878 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
879 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
880
881 ret = bgp_peer_clear(peer, afi, safi, NULL, stype);
882
883 /* if afi/safi not defined for this peer, let caller know */
884 if (ret == 1)
885 ret = BGP_ERR_AF_UNCONFIGURED;
886
887 if (ret < 0)
888 bgp_clear_vty_error(vty, peer, afi, safi, ret);
889
890 return CMD_SUCCESS;
891 }
892
893 /* Clear all neighbors belonging to a specific peer-group. */
894 if (sort == clear_group) {
895 struct peer_group *group;
896
897 group = peer_group_lookup(bgp, arg);
898 if (!group) {
899 vty_out(vty, "%%BGP: No such peer-group %s\n", arg);
900 return CMD_WARNING;
901 }
902
903 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
904 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
905
906 if (ret < 0)
907 bgp_clear_vty_error(vty, peer, afi, safi, ret);
908 else
909 found = true;
910 }
911
912 if (!found)
913 vty_out(vty,
914 "%%BGP: No %s peer belonging to peer-group %s is configured\n",
915 get_afi_safi_str(afi, safi, false), arg);
916
917 return CMD_SUCCESS;
918 }
919
920 /* Clear all external (eBGP) neighbors. */
921 if (sort == clear_external) {
922 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
923 if (peer->sort == BGP_PEER_IBGP)
924 continue;
925
926 bgp_peer_gr_flags_update(peer);
927
928 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
929 gr_router_detected = true;
930
931 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
932
933 if (ret < 0)
934 bgp_clear_vty_error(vty, peer, afi, safi, ret);
935 else
936 found = true;
937 }
938
939 if (gr_router_detected
940 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
941 bgp_zebra_send_capabilities(bgp, false);
942 } else if (!gr_router_detected
943 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
944 bgp_zebra_send_capabilities(bgp, true);
945 }
946
947 if (!found)
948 vty_out(vty,
949 "%%BGP: No external %s peer is configured\n",
950 get_afi_safi_str(afi, safi, false));
951
952 return CMD_SUCCESS;
953 }
954
955 /* Clear all neighbors belonging to a specific AS. */
956 if (sort == clear_as) {
957 as_t as = strtoul(arg, NULL, 10);
958
959 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
960 if (peer->as != as)
961 continue;
962
963 bgp_peer_gr_flags_update(peer);
964
965 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
966 gr_router_detected = true;
967
968 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
969
970 if (ret < 0)
971 bgp_clear_vty_error(vty, peer, afi, safi, ret);
972 else
973 found = true;
974 }
975
976 if (gr_router_detected
977 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
978 bgp_zebra_send_capabilities(bgp, false);
979 } else if (!gr_router_detected
980 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
981 bgp_zebra_send_capabilities(bgp, true);
982 }
983
984 if (!found)
985 vty_out(vty,
986 "%%BGP: No %s peer is configured with AS %s\n",
987 get_afi_safi_str(afi, safi, false), arg);
988
989 return CMD_SUCCESS;
990 }
991
992 return CMD_SUCCESS;
993 }
994
995 static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
996 safi_t safi, enum clear_sort sort,
997 enum bgp_clear_type stype, const char *arg)
998 {
999 struct bgp *bgp;
1000
1001 /* BGP structure lookup. */
1002 if (name) {
1003 bgp = bgp_lookup_by_name(name);
1004 if (bgp == NULL) {
1005 vty_out(vty, "Can't find BGP instance %s\n", name);
1006 return CMD_WARNING;
1007 }
1008 } else {
1009 bgp = bgp_get_default();
1010 if (bgp == NULL) {
1011 vty_out(vty, "No BGP process is configured\n");
1012 return CMD_WARNING;
1013 }
1014 }
1015
1016 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
1017 }
1018
1019 /* clear soft inbound */
1020 static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
1021 {
1022 afi_t afi;
1023 safi_t safi;
1024
1025 FOREACH_AFI_SAFI (afi, safi)
1026 bgp_clear_vty(vty, name, afi, safi, clear_all,
1027 BGP_CLEAR_SOFT_IN, NULL);
1028 }
1029
1030 /* clear soft outbound */
1031 static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
1032 {
1033 afi_t afi;
1034 safi_t safi;
1035
1036 FOREACH_AFI_SAFI (afi, safi)
1037 bgp_clear_vty(vty, name, afi, safi, clear_all,
1038 BGP_CLEAR_SOFT_OUT, NULL);
1039 }
1040
1041
1042 #ifndef VTYSH_EXTRACT_PL
1043 #include "bgpd/bgp_vty_clippy.c"
1044 #endif
1045
1046 DEFUN_HIDDEN (bgp_local_mac,
1047 bgp_local_mac_cmd,
1048 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
1049 BGP_STR
1050 "Local MAC config\n"
1051 "VxLAN Network Identifier\n"
1052 "VNI number\n"
1053 "local mac\n"
1054 "mac address\n"
1055 "mac-mobility sequence\n"
1056 "seq number\n")
1057 {
1058 int rv;
1059 vni_t vni;
1060 struct ethaddr mac;
1061 struct ipaddr ip;
1062 uint32_t seq;
1063 struct bgp *bgp;
1064
1065 vni = strtoul(argv[3]->arg, NULL, 10);
1066 if (!prefix_str2mac(argv[5]->arg, &mac)) {
1067 vty_out(vty, "%% Malformed MAC address\n");
1068 return CMD_WARNING;
1069 }
1070 memset(&ip, 0, sizeof(ip));
1071 seq = strtoul(argv[7]->arg, NULL, 10);
1072
1073 bgp = bgp_get_default();
1074 if (!bgp) {
1075 vty_out(vty, "Default BGP instance is not there\n");
1076 return CMD_WARNING;
1077 }
1078
1079 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq);
1080 if (rv < 0) {
1081 vty_out(vty, "Internal error\n");
1082 return CMD_WARNING;
1083 }
1084
1085 return CMD_SUCCESS;
1086 }
1087
1088 DEFUN_HIDDEN (no_bgp_local_mac,
1089 no_bgp_local_mac_cmd,
1090 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
1091 NO_STR
1092 BGP_STR
1093 "Local MAC config\n"
1094 "VxLAN Network Identifier\n"
1095 "VNI number\n"
1096 "local mac\n"
1097 "mac address\n")
1098 {
1099 int rv;
1100 vni_t vni;
1101 struct ethaddr mac;
1102 struct ipaddr ip;
1103 struct bgp *bgp;
1104
1105 vni = strtoul(argv[4]->arg, NULL, 10);
1106 if (!prefix_str2mac(argv[6]->arg, &mac)) {
1107 vty_out(vty, "%% Malformed MAC address\n");
1108 return CMD_WARNING;
1109 }
1110 memset(&ip, 0, sizeof(ip));
1111
1112 bgp = bgp_get_default();
1113 if (!bgp) {
1114 vty_out(vty, "Default BGP instance is not there\n");
1115 return CMD_WARNING;
1116 }
1117
1118 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
1119 if (rv < 0) {
1120 vty_out(vty, "Internal error\n");
1121 return CMD_WARNING;
1122 }
1123
1124 return CMD_SUCCESS;
1125 }
1126
1127 DEFUN (no_synchronization,
1128 no_synchronization_cmd,
1129 "no synchronization",
1130 NO_STR
1131 "Perform IGP synchronization\n")
1132 {
1133 return CMD_SUCCESS;
1134 }
1135
1136 DEFUN (no_auto_summary,
1137 no_auto_summary_cmd,
1138 "no auto-summary",
1139 NO_STR
1140 "Enable automatic network number summarization\n")
1141 {
1142 return CMD_SUCCESS;
1143 }
1144
1145 /* "router bgp" commands. */
1146 DEFUN_NOSH (router_bgp,
1147 router_bgp_cmd,
1148 "router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1149 ROUTER_STR
1150 BGP_STR
1151 AS_STR
1152 BGP_INSTANCE_HELP_STR)
1153 {
1154 int idx_asn = 2;
1155 int idx_view_vrf = 3;
1156 int idx_vrf = 4;
1157 int is_new_bgp = 0;
1158 int ret;
1159 as_t as;
1160 struct bgp *bgp;
1161 const char *name = NULL;
1162 enum bgp_instance_type inst_type;
1163
1164 // "router bgp" without an ASN
1165 if (argc == 2) {
1166 // Pending: Make VRF option available for ASN less config
1167 bgp = bgp_get_default();
1168
1169 if (bgp == NULL) {
1170 vty_out(vty, "%% No BGP process is configured\n");
1171 return CMD_WARNING_CONFIG_FAILED;
1172 }
1173
1174 if (listcount(bm->bgp) > 1) {
1175 vty_out(vty, "%% Please specify ASN and VRF\n");
1176 return CMD_WARNING_CONFIG_FAILED;
1177 }
1178 }
1179
1180 // "router bgp X"
1181 else {
1182 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1183
1184 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1185 if (argc > 3) {
1186 name = argv[idx_vrf]->arg;
1187
1188 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1189 if (strmatch(name, VRF_DEFAULT_NAME))
1190 name = NULL;
1191 else
1192 inst_type = BGP_INSTANCE_TYPE_VRF;
1193 } else if (!strcmp(argv[idx_view_vrf]->text, "view"))
1194 inst_type = BGP_INSTANCE_TYPE_VIEW;
1195 }
1196
1197 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1198 is_new_bgp = (bgp_lookup(as, name) == NULL);
1199
1200 ret = bgp_get_vty(&bgp, &as, name, inst_type);
1201 switch (ret) {
1202 case BGP_ERR_AS_MISMATCH:
1203 vty_out(vty, "BGP is already running; AS is %u\n", as);
1204 return CMD_WARNING_CONFIG_FAILED;
1205 case BGP_ERR_INSTANCE_MISMATCH:
1206 vty_out(vty,
1207 "BGP instance name and AS number mismatch\n");
1208 vty_out(vty,
1209 "BGP instance is already running; AS is %u\n",
1210 as);
1211 return CMD_WARNING_CONFIG_FAILED;
1212 }
1213
1214 /*
1215 * If we just instantiated the default instance, complete
1216 * any pending VRF-VPN leaking that was configured via
1217 * earlier "router bgp X vrf FOO" blocks.
1218 */
1219 if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1220 vpn_leak_postchange_all();
1221
1222 if (inst_type == BGP_INSTANCE_TYPE_VRF)
1223 bgp_vpn_leak_export(bgp);
1224 /* Pending: handle when user tries to change a view to vrf n vv.
1225 */
1226 }
1227
1228 /* unset the auto created flag as the user config is now present */
1229 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
1230 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1231
1232 return CMD_SUCCESS;
1233 }
1234
1235 /* "no router bgp" commands. */
1236 DEFUN (no_router_bgp,
1237 no_router_bgp_cmd,
1238 "no router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1239 NO_STR
1240 ROUTER_STR
1241 BGP_STR
1242 AS_STR
1243 BGP_INSTANCE_HELP_STR)
1244 {
1245 int idx_asn = 3;
1246 int idx_vrf = 5;
1247 as_t as;
1248 struct bgp *bgp;
1249 const char *name = NULL;
1250
1251 // "no router bgp" without an ASN
1252 if (argc == 3) {
1253 // Pending: Make VRF option available for ASN less config
1254 bgp = bgp_get_default();
1255
1256 if (bgp == NULL) {
1257 vty_out(vty, "%% No BGP process is configured\n");
1258 return CMD_WARNING_CONFIG_FAILED;
1259 }
1260
1261 if (listcount(bm->bgp) > 1) {
1262 vty_out(vty, "%% Please specify ASN and VRF\n");
1263 return CMD_WARNING_CONFIG_FAILED;
1264 }
1265
1266 if (bgp->l3vni) {
1267 vty_out(vty, "%% Please unconfigure l3vni %u",
1268 bgp->l3vni);
1269 return CMD_WARNING_CONFIG_FAILED;
1270 }
1271 } else {
1272 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1273
1274 if (argc > 4)
1275 name = argv[idx_vrf]->arg;
1276
1277 /* Lookup bgp structure. */
1278 bgp = bgp_lookup(as, name);
1279 if (!bgp) {
1280 vty_out(vty, "%% Can't find BGP instance\n");
1281 return CMD_WARNING_CONFIG_FAILED;
1282 }
1283
1284 if (bgp->l3vni) {
1285 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1286 bgp->l3vni);
1287 return CMD_WARNING_CONFIG_FAILED;
1288 }
1289
1290 /* Cannot delete default instance if vrf instances exist */
1291 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
1292 struct listnode *node;
1293 struct bgp *tmp_bgp;
1294
1295 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, tmp_bgp)) {
1296 if (tmp_bgp->inst_type
1297 == BGP_INSTANCE_TYPE_VRF) {
1298 vty_out(vty,
1299 "%% Cannot delete default BGP instance. Dependent VRF instances exist\n");
1300 return CMD_WARNING_CONFIG_FAILED;
1301 }
1302 }
1303 }
1304 }
1305
1306 if (bgp_vpn_leak_unimport(bgp, vty))
1307 return CMD_WARNING_CONFIG_FAILED;
1308
1309 bgp_delete(bgp);
1310
1311 return CMD_SUCCESS;
1312 }
1313
1314
1315 /* BGP router-id. */
1316
1317 DEFPY (bgp_router_id,
1318 bgp_router_id_cmd,
1319 "bgp router-id A.B.C.D",
1320 BGP_STR
1321 "Override configured router identifier\n"
1322 "Manually configured router identifier\n")
1323 {
1324 VTY_DECLVAR_CONTEXT(bgp, bgp);
1325 bgp_router_id_static_set(bgp, router_id);
1326 return CMD_SUCCESS;
1327 }
1328
1329 DEFPY (no_bgp_router_id,
1330 no_bgp_router_id_cmd,
1331 "no bgp router-id [A.B.C.D]",
1332 NO_STR
1333 BGP_STR
1334 "Override configured router identifier\n"
1335 "Manually configured router identifier\n")
1336 {
1337 VTY_DECLVAR_CONTEXT(bgp, bgp);
1338
1339 if (router_id_str) {
1340 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1341 vty_out(vty, "%% BGP router-id doesn't match\n");
1342 return CMD_WARNING_CONFIG_FAILED;
1343 }
1344 }
1345
1346 router_id.s_addr = 0;
1347 bgp_router_id_static_set(bgp, router_id);
1348
1349 return CMD_SUCCESS;
1350 }
1351
1352
1353 /* BGP Cluster ID. */
1354 DEFUN (bgp_cluster_id,
1355 bgp_cluster_id_cmd,
1356 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1357 BGP_STR
1358 "Configure Route-Reflector Cluster-id\n"
1359 "Route-Reflector Cluster-id in IP address format\n"
1360 "Route-Reflector Cluster-id as 32 bit quantity\n")
1361 {
1362 VTY_DECLVAR_CONTEXT(bgp, bgp);
1363 int idx_ipv4 = 2;
1364 int ret;
1365 struct in_addr cluster;
1366
1367 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1368 if (!ret) {
1369 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1370 return CMD_WARNING_CONFIG_FAILED;
1371 }
1372
1373 bgp_cluster_id_set(bgp, &cluster);
1374 bgp_clear_star_soft_out(vty, bgp->name);
1375
1376 return CMD_SUCCESS;
1377 }
1378
1379 DEFUN (no_bgp_cluster_id,
1380 no_bgp_cluster_id_cmd,
1381 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1382 NO_STR
1383 BGP_STR
1384 "Configure Route-Reflector Cluster-id\n"
1385 "Route-Reflector Cluster-id in IP address format\n"
1386 "Route-Reflector Cluster-id as 32 bit quantity\n")
1387 {
1388 VTY_DECLVAR_CONTEXT(bgp, bgp);
1389 bgp_cluster_id_unset(bgp);
1390 bgp_clear_star_soft_out(vty, bgp->name);
1391
1392 return CMD_SUCCESS;
1393 }
1394
1395 DEFUN (bgp_confederation_identifier,
1396 bgp_confederation_identifier_cmd,
1397 "bgp confederation identifier (1-4294967295)",
1398 "BGP specific commands\n"
1399 "AS confederation parameters\n"
1400 "AS number\n"
1401 "Set routing domain confederation AS\n")
1402 {
1403 VTY_DECLVAR_CONTEXT(bgp, bgp);
1404 int idx_number = 3;
1405 as_t as;
1406
1407 as = strtoul(argv[idx_number]->arg, NULL, 10);
1408
1409 bgp_confederation_id_set(bgp, as);
1410
1411 return CMD_SUCCESS;
1412 }
1413
1414 DEFUN (no_bgp_confederation_identifier,
1415 no_bgp_confederation_identifier_cmd,
1416 "no bgp confederation identifier [(1-4294967295)]",
1417 NO_STR
1418 "BGP specific commands\n"
1419 "AS confederation parameters\n"
1420 "AS number\n"
1421 "Set routing domain confederation AS\n")
1422 {
1423 VTY_DECLVAR_CONTEXT(bgp, bgp);
1424 bgp_confederation_id_unset(bgp);
1425
1426 return CMD_SUCCESS;
1427 }
1428
1429 DEFUN (bgp_confederation_peers,
1430 bgp_confederation_peers_cmd,
1431 "bgp confederation peers (1-4294967295)...",
1432 "BGP specific commands\n"
1433 "AS confederation parameters\n"
1434 "Peer ASs in BGP confederation\n"
1435 AS_STR)
1436 {
1437 VTY_DECLVAR_CONTEXT(bgp, bgp);
1438 int idx_asn = 3;
1439 as_t as;
1440 int i;
1441
1442 for (i = idx_asn; i < argc; i++) {
1443 as = strtoul(argv[i]->arg, NULL, 10);
1444
1445 if (bgp->as == as) {
1446 vty_out(vty,
1447 "%% Local member-AS not allowed in confed peer list\n");
1448 continue;
1449 }
1450
1451 bgp_confederation_peers_add(bgp, as);
1452 }
1453 return CMD_SUCCESS;
1454 }
1455
1456 DEFUN (no_bgp_confederation_peers,
1457 no_bgp_confederation_peers_cmd,
1458 "no bgp confederation peers (1-4294967295)...",
1459 NO_STR
1460 "BGP specific commands\n"
1461 "AS confederation parameters\n"
1462 "Peer ASs in BGP confederation\n"
1463 AS_STR)
1464 {
1465 VTY_DECLVAR_CONTEXT(bgp, bgp);
1466 int idx_asn = 4;
1467 as_t as;
1468 int i;
1469
1470 for (i = idx_asn; i < argc; i++) {
1471 as = strtoul(argv[i]->arg, NULL, 10);
1472
1473 bgp_confederation_peers_remove(bgp, as);
1474 }
1475 return CMD_SUCCESS;
1476 }
1477
1478 /**
1479 * Central routine for maximum-paths configuration.
1480 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1481 * @set: 1 for setting values, 0 for removing the max-paths config.
1482 */
1483 static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
1484 const char *mpaths, uint16_t options,
1485 int set)
1486 {
1487 VTY_DECLVAR_CONTEXT(bgp, bgp);
1488 uint16_t maxpaths = 0;
1489 int ret;
1490 afi_t afi;
1491 safi_t safi;
1492
1493 afi = bgp_node_afi(vty);
1494 safi = bgp_node_safi(vty);
1495
1496 if (set) {
1497 maxpaths = strtol(mpaths, NULL, 10);
1498 if (maxpaths > multipath_num) {
1499 vty_out(vty,
1500 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1501 maxpaths, multipath_num);
1502 return CMD_WARNING_CONFIG_FAILED;
1503 }
1504 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1505 options);
1506 } else
1507 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1508
1509 if (ret < 0) {
1510 vty_out(vty,
1511 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1512 (set == 1) ? "" : "un",
1513 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1514 maxpaths, afi, safi);
1515 return CMD_WARNING_CONFIG_FAILED;
1516 }
1517
1518 bgp_recalculate_all_bestpaths(bgp);
1519
1520 return CMD_SUCCESS;
1521 }
1522
1523 DEFUN (bgp_maxmed_admin,
1524 bgp_maxmed_admin_cmd,
1525 "bgp max-med administrative ",
1526 BGP_STR
1527 "Advertise routes with max-med\n"
1528 "Administratively applied, for an indefinite period\n")
1529 {
1530 VTY_DECLVAR_CONTEXT(bgp, bgp);
1531
1532 bgp->v_maxmed_admin = 1;
1533 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1534
1535 bgp_maxmed_update(bgp);
1536
1537 return CMD_SUCCESS;
1538 }
1539
1540 DEFUN (bgp_maxmed_admin_medv,
1541 bgp_maxmed_admin_medv_cmd,
1542 "bgp max-med administrative (0-4294967295)",
1543 BGP_STR
1544 "Advertise routes with max-med\n"
1545 "Administratively applied, for an indefinite period\n"
1546 "Max MED value to be used\n")
1547 {
1548 VTY_DECLVAR_CONTEXT(bgp, bgp);
1549 int idx_number = 3;
1550
1551 bgp->v_maxmed_admin = 1;
1552 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
1553
1554 bgp_maxmed_update(bgp);
1555
1556 return CMD_SUCCESS;
1557 }
1558
1559 DEFUN (no_bgp_maxmed_admin,
1560 no_bgp_maxmed_admin_cmd,
1561 "no bgp max-med administrative [(0-4294967295)]",
1562 NO_STR
1563 BGP_STR
1564 "Advertise routes with max-med\n"
1565 "Administratively applied, for an indefinite period\n"
1566 "Max MED value to be used\n")
1567 {
1568 VTY_DECLVAR_CONTEXT(bgp, bgp);
1569 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1570 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1571 bgp_maxmed_update(bgp);
1572
1573 return CMD_SUCCESS;
1574 }
1575
1576 DEFUN (bgp_maxmed_onstartup,
1577 bgp_maxmed_onstartup_cmd,
1578 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
1579 BGP_STR
1580 "Advertise routes with max-med\n"
1581 "Effective on a startup\n"
1582 "Time (seconds) period for max-med\n"
1583 "Max MED value to be used\n")
1584 {
1585 VTY_DECLVAR_CONTEXT(bgp, bgp);
1586 int idx = 0;
1587
1588 argv_find(argv, argc, "(5-86400)", &idx);
1589 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
1590 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1591 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
1592 else
1593 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1594
1595 bgp_maxmed_update(bgp);
1596
1597 return CMD_SUCCESS;
1598 }
1599
1600 DEFUN (no_bgp_maxmed_onstartup,
1601 no_bgp_maxmed_onstartup_cmd,
1602 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
1603 NO_STR
1604 BGP_STR
1605 "Advertise routes with max-med\n"
1606 "Effective on a startup\n"
1607 "Time (seconds) period for max-med\n"
1608 "Max MED value to be used\n")
1609 {
1610 VTY_DECLVAR_CONTEXT(bgp, bgp);
1611
1612 /* Cancel max-med onstartup if its on */
1613 if (bgp->t_maxmed_onstartup) {
1614 THREAD_TIMER_OFF(bgp->t_maxmed_onstartup);
1615 bgp->maxmed_onstartup_over = 1;
1616 }
1617
1618 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
1619 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1620
1621 bgp_maxmed_update(bgp);
1622
1623 return CMD_SUCCESS;
1624 }
1625
1626 static int bgp_update_delay_config_vty(struct vty *vty, const char *delay,
1627 const char *wait)
1628 {
1629 VTY_DECLVAR_CONTEXT(bgp, bgp);
1630 uint16_t update_delay;
1631 uint16_t establish_wait;
1632
1633 update_delay = strtoul(delay, NULL, 10);
1634
1635 if (!wait) /* update-delay <delay> */
1636 {
1637 bgp->v_update_delay = update_delay;
1638 bgp->v_establish_wait = bgp->v_update_delay;
1639 return CMD_SUCCESS;
1640 }
1641
1642 /* update-delay <delay> <establish-wait> */
1643 establish_wait = atoi(wait);
1644 if (update_delay < establish_wait) {
1645 vty_out(vty,
1646 "%%Failed: update-delay less than the establish-wait!\n");
1647 return CMD_WARNING_CONFIG_FAILED;
1648 }
1649
1650 bgp->v_update_delay = update_delay;
1651 bgp->v_establish_wait = establish_wait;
1652
1653 return CMD_SUCCESS;
1654 }
1655
1656 static int bgp_update_delay_deconfig_vty(struct vty *vty)
1657 {
1658 VTY_DECLVAR_CONTEXT(bgp, bgp);
1659
1660 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
1661 bgp->v_establish_wait = bgp->v_update_delay;
1662
1663 return CMD_SUCCESS;
1664 }
1665
1666 void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
1667 {
1668 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1669 vty_out(vty, " update-delay %d", bgp->v_update_delay);
1670 if (bgp->v_update_delay != bgp->v_establish_wait)
1671 vty_out(vty, " %d", bgp->v_establish_wait);
1672 vty_out(vty, "\n");
1673 }
1674 }
1675
1676
1677 /* Update-delay configuration */
1678 DEFUN (bgp_update_delay,
1679 bgp_update_delay_cmd,
1680 "update-delay (0-3600)",
1681 "Force initial delay for best-path and updates\n"
1682 "Seconds\n")
1683 {
1684 int idx_number = 1;
1685 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg, NULL);
1686 }
1687
1688 DEFUN (bgp_update_delay_establish_wait,
1689 bgp_update_delay_establish_wait_cmd,
1690 "update-delay (0-3600) (1-3600)",
1691 "Force initial delay for best-path and updates\n"
1692 "Seconds\n"
1693 "Seconds\n")
1694 {
1695 int idx_number = 1;
1696 int idx_number_2 = 2;
1697 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg,
1698 argv[idx_number_2]->arg);
1699 }
1700
1701 /* Update-delay deconfiguration */
1702 DEFUN (no_bgp_update_delay,
1703 no_bgp_update_delay_cmd,
1704 "no update-delay [(0-3600) [(1-3600)]]",
1705 NO_STR
1706 "Force initial delay for best-path and updates\n"
1707 "Seconds\n"
1708 "Seconds\n")
1709 {
1710 return bgp_update_delay_deconfig_vty(vty);
1711 }
1712
1713
1714 static int bgp_wpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
1715 bool set)
1716 {
1717 VTY_DECLVAR_CONTEXT(bgp, bgp);
1718
1719 quanta = set ? quanta : BGP_WRITE_PACKET_MAX;
1720 atomic_store_explicit(&bgp->wpkt_quanta, quanta, memory_order_relaxed);
1721
1722 return CMD_SUCCESS;
1723 }
1724
1725 static int bgp_rpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
1726 bool set)
1727 {
1728 VTY_DECLVAR_CONTEXT(bgp, bgp);
1729
1730 quanta = set ? quanta : BGP_READ_PACKET_MAX;
1731 atomic_store_explicit(&bgp->rpkt_quanta, quanta, memory_order_relaxed);
1732
1733 return CMD_SUCCESS;
1734 }
1735
1736 void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
1737 {
1738 uint32_t quanta =
1739 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
1740 if (quanta != BGP_WRITE_PACKET_MAX)
1741 vty_out(vty, " write-quanta %d\n", quanta);
1742 }
1743
1744 void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
1745 {
1746 uint32_t quanta =
1747 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
1748 if (quanta != BGP_READ_PACKET_MAX)
1749 vty_out(vty, " read-quanta %d\n", quanta);
1750 }
1751
1752 /* Packet quanta configuration
1753 *
1754 * XXX: The value set here controls the size of a stack buffer in the IO
1755 * thread. When changing these limits be careful to prevent stack overflow.
1756 *
1757 * Furthermore, the maximums used here should correspond to
1758 * BGP_WRITE_PACKET_MAX and BGP_READ_PACKET_MAX.
1759 */
1760 DEFPY (bgp_wpkt_quanta,
1761 bgp_wpkt_quanta_cmd,
1762 "[no] write-quanta (1-64)$quanta",
1763 NO_STR
1764 "How many packets to write to peer socket per run\n"
1765 "Number of packets\n")
1766 {
1767 return bgp_wpkt_quanta_config_vty(vty, quanta, !no);
1768 }
1769
1770 DEFPY (bgp_rpkt_quanta,
1771 bgp_rpkt_quanta_cmd,
1772 "[no] read-quanta (1-10)$quanta",
1773 NO_STR
1774 "How many packets to read from peer socket per I/O cycle\n"
1775 "Number of packets\n")
1776 {
1777 return bgp_rpkt_quanta_config_vty(vty, quanta, !no);
1778 }
1779
1780 void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
1781 {
1782 if (!bgp->heuristic_coalesce)
1783 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
1784 }
1785
1786
1787 DEFUN (bgp_coalesce_time,
1788 bgp_coalesce_time_cmd,
1789 "coalesce-time (0-4294967295)",
1790 "Subgroup coalesce timer\n"
1791 "Subgroup coalesce timer value (in ms)\n")
1792 {
1793 VTY_DECLVAR_CONTEXT(bgp, bgp);
1794
1795 int idx = 0;
1796 argv_find(argv, argc, "(0-4294967295)", &idx);
1797 bgp->heuristic_coalesce = false;
1798 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
1799 return CMD_SUCCESS;
1800 }
1801
1802 DEFUN (no_bgp_coalesce_time,
1803 no_bgp_coalesce_time_cmd,
1804 "no coalesce-time (0-4294967295)",
1805 NO_STR
1806 "Subgroup coalesce timer\n"
1807 "Subgroup coalesce timer value (in ms)\n")
1808 {
1809 VTY_DECLVAR_CONTEXT(bgp, bgp);
1810
1811 bgp->heuristic_coalesce = true;
1812 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
1813 return CMD_SUCCESS;
1814 }
1815
1816 /* Maximum-paths configuration */
1817 DEFUN (bgp_maxpaths,
1818 bgp_maxpaths_cmd,
1819 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1820 "Forward packets over multiple paths\n"
1821 "Number of paths\n")
1822 {
1823 int idx_number = 1;
1824 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
1825 argv[idx_number]->arg, 0, 1);
1826 }
1827
1828 ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
1829 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1830 "Forward packets over multiple paths\n"
1831 "Number of paths\n")
1832
1833 DEFUN (bgp_maxpaths_ibgp,
1834 bgp_maxpaths_ibgp_cmd,
1835 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1836 "Forward packets over multiple paths\n"
1837 "iBGP-multipath\n"
1838 "Number of paths\n")
1839 {
1840 int idx_number = 2;
1841 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
1842 argv[idx_number]->arg, 0, 1);
1843 }
1844
1845 ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
1846 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1847 "Forward packets over multiple paths\n"
1848 "iBGP-multipath\n"
1849 "Number of paths\n")
1850
1851 DEFUN (bgp_maxpaths_ibgp_cluster,
1852 bgp_maxpaths_ibgp_cluster_cmd,
1853 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
1854 "Forward packets over multiple paths\n"
1855 "iBGP-multipath\n"
1856 "Number of paths\n"
1857 "Match the cluster length\n")
1858 {
1859 int idx_number = 2;
1860 return bgp_maxpaths_config_vty(
1861 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
1862 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
1863 }
1864
1865 ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
1866 "maximum-paths ibgp " CMD_RANGE_STR(
1867 1, MULTIPATH_NUM) " equal-cluster-length",
1868 "Forward packets over multiple paths\n"
1869 "iBGP-multipath\n"
1870 "Number of paths\n"
1871 "Match the cluster length\n")
1872
1873 DEFUN (no_bgp_maxpaths,
1874 no_bgp_maxpaths_cmd,
1875 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
1876 NO_STR
1877 "Forward packets over multiple paths\n"
1878 "Number of paths\n")
1879 {
1880 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
1881 }
1882
1883 ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
1884 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
1885 "Forward packets over multiple paths\n"
1886 "Number of paths\n")
1887
1888 DEFUN (no_bgp_maxpaths_ibgp,
1889 no_bgp_maxpaths_ibgp_cmd,
1890 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
1891 NO_STR
1892 "Forward packets over multiple paths\n"
1893 "iBGP-multipath\n"
1894 "Number of paths\n"
1895 "Match the cluster length\n")
1896 {
1897 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
1898 }
1899
1900 ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
1901 "no maximum-paths ibgp [" CMD_RANGE_STR(
1902 1, MULTIPATH_NUM) " [equal-cluster-length]]",
1903 NO_STR
1904 "Forward packets over multiple paths\n"
1905 "iBGP-multipath\n"
1906 "Number of paths\n"
1907 "Match the cluster length\n")
1908
1909 static void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp,
1910 afi_t afi, safi_t safi)
1911 {
1912 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != MULTIPATH_NUM) {
1913 vty_out(vty, " maximum-paths %d\n",
1914 bgp->maxpaths[afi][safi].maxpaths_ebgp);
1915 }
1916
1917 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != MULTIPATH_NUM) {
1918 vty_out(vty, " maximum-paths ibgp %d",
1919 bgp->maxpaths[afi][safi].maxpaths_ibgp);
1920 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
1921 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
1922 vty_out(vty, " equal-cluster-length");
1923 vty_out(vty, "\n");
1924 }
1925 }
1926
1927 /* BGP timers. */
1928
1929 DEFUN (bgp_timers,
1930 bgp_timers_cmd,
1931 "timers bgp (0-65535) (0-65535)",
1932 "Adjust routing timers\n"
1933 "BGP timers\n"
1934 "Keepalive interval\n"
1935 "Holdtime\n")
1936 {
1937 VTY_DECLVAR_CONTEXT(bgp, bgp);
1938 int idx_number = 2;
1939 int idx_number_2 = 3;
1940 unsigned long keepalive = 0;
1941 unsigned long holdtime = 0;
1942
1943 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
1944 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
1945
1946 /* Holdtime value check. */
1947 if (holdtime < 3 && holdtime != 0) {
1948 vty_out(vty,
1949 "%% hold time value must be either 0 or greater than 3\n");
1950 return CMD_WARNING_CONFIG_FAILED;
1951 }
1952
1953 bgp_timers_set(bgp, keepalive, holdtime, DFLT_BGP_CONNECT_RETRY);
1954
1955 return CMD_SUCCESS;
1956 }
1957
1958 DEFUN (no_bgp_timers,
1959 no_bgp_timers_cmd,
1960 "no timers bgp [(0-65535) (0-65535)]",
1961 NO_STR
1962 "Adjust routing timers\n"
1963 "BGP timers\n"
1964 "Keepalive interval\n"
1965 "Holdtime\n")
1966 {
1967 VTY_DECLVAR_CONTEXT(bgp, bgp);
1968 bgp_timers_set(bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
1969 DFLT_BGP_CONNECT_RETRY);
1970
1971 return CMD_SUCCESS;
1972 }
1973
1974
1975 DEFUN (bgp_client_to_client_reflection,
1976 bgp_client_to_client_reflection_cmd,
1977 "bgp client-to-client reflection",
1978 "BGP specific commands\n"
1979 "Configure client to client route reflection\n"
1980 "reflection of routes allowed\n")
1981 {
1982 VTY_DECLVAR_CONTEXT(bgp, bgp);
1983 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1984 bgp_clear_star_soft_out(vty, bgp->name);
1985
1986 return CMD_SUCCESS;
1987 }
1988
1989 DEFUN (no_bgp_client_to_client_reflection,
1990 no_bgp_client_to_client_reflection_cmd,
1991 "no bgp client-to-client reflection",
1992 NO_STR
1993 "BGP specific commands\n"
1994 "Configure client to client route reflection\n"
1995 "reflection of routes allowed\n")
1996 {
1997 VTY_DECLVAR_CONTEXT(bgp, bgp);
1998 SET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1999 bgp_clear_star_soft_out(vty, bgp->name);
2000
2001 return CMD_SUCCESS;
2002 }
2003
2004 /* "bgp always-compare-med" configuration. */
2005 DEFUN (bgp_always_compare_med,
2006 bgp_always_compare_med_cmd,
2007 "bgp always-compare-med",
2008 "BGP specific commands\n"
2009 "Allow comparing MED from different neighbors\n")
2010 {
2011 VTY_DECLVAR_CONTEXT(bgp, bgp);
2012 SET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2013 bgp_recalculate_all_bestpaths(bgp);
2014
2015 return CMD_SUCCESS;
2016 }
2017
2018 DEFUN (no_bgp_always_compare_med,
2019 no_bgp_always_compare_med_cmd,
2020 "no bgp always-compare-med",
2021 NO_STR
2022 "BGP specific commands\n"
2023 "Allow comparing MED from different neighbors\n")
2024 {
2025 VTY_DECLVAR_CONTEXT(bgp, bgp);
2026 UNSET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2027 bgp_recalculate_all_bestpaths(bgp);
2028
2029 return CMD_SUCCESS;
2030 }
2031
2032
2033 DEFUN(bgp_ebgp_requires_policy, bgp_ebgp_requires_policy_cmd,
2034 "bgp ebgp-requires-policy",
2035 "BGP specific commands\n"
2036 "Require in and out policy for eBGP peers (RFC8212)\n")
2037 {
2038 VTY_DECLVAR_CONTEXT(bgp, bgp);
2039 bgp->ebgp_requires_policy = DEFAULT_EBGP_POLICY_ENABLED;
2040 return CMD_SUCCESS;
2041 }
2042
2043 DEFUN(no_bgp_ebgp_requires_policy, no_bgp_ebgp_requires_policy_cmd,
2044 "no bgp ebgp-requires-policy",
2045 NO_STR
2046 "BGP specific commands\n"
2047 "Require in and out policy for eBGP peers (RFC8212)\n")
2048 {
2049 VTY_DECLVAR_CONTEXT(bgp, bgp);
2050 bgp->ebgp_requires_policy = DEFAULT_EBGP_POLICY_DISABLED;
2051 return CMD_SUCCESS;
2052 }
2053
2054 DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd,
2055 "bgp reject-as-sets",
2056 "BGP specific commands\n"
2057 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2058 {
2059 VTY_DECLVAR_CONTEXT(bgp, bgp);
2060 struct listnode *node, *nnode;
2061 struct peer *peer;
2062
2063 bgp->reject_as_sets = BGP_REJECT_AS_SETS_ENABLED;
2064
2065 /* Reset existing BGP sessions to reject routes
2066 * with aspath containing AS_SET or AS_CONFED_SET.
2067 */
2068 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2069 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2070 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2071 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2072 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2073 }
2074 }
2075
2076 return CMD_SUCCESS;
2077 }
2078
2079 DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd,
2080 "no bgp reject-as-sets",
2081 NO_STR
2082 "BGP specific commands\n"
2083 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2084 {
2085 VTY_DECLVAR_CONTEXT(bgp, bgp);
2086 struct listnode *node, *nnode;
2087 struct peer *peer;
2088
2089 bgp->reject_as_sets = BGP_REJECT_AS_SETS_DISABLED;
2090
2091 /* Reset existing BGP sessions to reject routes
2092 * with aspath containing AS_SET or AS_CONFED_SET.
2093 */
2094 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2095 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2096 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2097 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2098 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2099 }
2100 }
2101
2102 return CMD_SUCCESS;
2103 }
2104
2105 /* "bgp deterministic-med" configuration. */
2106 DEFUN (bgp_deterministic_med,
2107 bgp_deterministic_med_cmd,
2108 "bgp deterministic-med",
2109 "BGP specific commands\n"
2110 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2111 {
2112 VTY_DECLVAR_CONTEXT(bgp, bgp);
2113
2114 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2115 SET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2116 bgp_recalculate_all_bestpaths(bgp);
2117 }
2118
2119 return CMD_SUCCESS;
2120 }
2121
2122 DEFUN (no_bgp_deterministic_med,
2123 no_bgp_deterministic_med_cmd,
2124 "no bgp deterministic-med",
2125 NO_STR
2126 "BGP specific commands\n"
2127 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2128 {
2129 VTY_DECLVAR_CONTEXT(bgp, bgp);
2130 int bestpath_per_as_used;
2131 afi_t afi;
2132 safi_t safi;
2133 struct peer *peer;
2134 struct listnode *node, *nnode;
2135
2136 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2137 bestpath_per_as_used = 0;
2138
2139 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2140 FOREACH_AFI_SAFI (afi, safi)
2141 if (bgp_addpath_dmed_required(
2142 peer->addpath_type[afi][safi])) {
2143 bestpath_per_as_used = 1;
2144 break;
2145 }
2146
2147 if (bestpath_per_as_used)
2148 break;
2149 }
2150
2151 if (bestpath_per_as_used) {
2152 vty_out(vty,
2153 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
2154 return CMD_WARNING_CONFIG_FAILED;
2155 } else {
2156 UNSET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2157 bgp_recalculate_all_bestpaths(bgp);
2158 }
2159 }
2160
2161 return CMD_SUCCESS;
2162 }
2163
2164 /* "bgp graceful-restart mode" configuration. */
2165 DEFUN (bgp_graceful_restart,
2166 bgp_graceful_restart_cmd,
2167 "bgp graceful-restart",
2168 "BGP specific commands\n"
2169 GR_CMD
2170 )
2171 {
2172 int ret = BGP_GR_FAILURE;
2173
2174 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2175 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : START ");
2176
2177 VTY_DECLVAR_CONTEXT(bgp, bgp);
2178
2179 ret = bgp_gr_update_all(bgp, GLOBAL_GR_CMD);
2180
2181 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2182 ret);
2183
2184 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2185 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : END ");
2186 vty_out(vty,
2187 "Graceful restart configuration changed, reset all peers to take effect\n");
2188 return bgp_vty_return(vty, ret);
2189 }
2190
2191 DEFUN (no_bgp_graceful_restart,
2192 no_bgp_graceful_restart_cmd,
2193 "no bgp graceful-restart",
2194 NO_STR
2195 "BGP specific commands\n"
2196 NO_GR_CMD
2197 )
2198 {
2199 VTY_DECLVAR_CONTEXT(bgp, bgp);
2200
2201 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2202 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : START ");
2203
2204 int ret = BGP_GR_FAILURE;
2205
2206 ret = bgp_gr_update_all(bgp, NO_GLOBAL_GR_CMD);
2207
2208 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2209 ret);
2210
2211 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2212 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : END ");
2213 vty_out(vty,
2214 "Graceful restart configuration changed, reset all peers to take effect\n");
2215
2216 return bgp_vty_return(vty, ret);
2217 }
2218
2219 DEFUN (bgp_graceful_restart_stalepath_time,
2220 bgp_graceful_restart_stalepath_time_cmd,
2221 "bgp graceful-restart stalepath-time (1-4095)",
2222 "BGP specific commands\n"
2223 "Graceful restart capability parameters\n"
2224 "Set the max time to hold onto restarting peer's stale paths\n"
2225 "Delay value (seconds)\n")
2226 {
2227 VTY_DECLVAR_CONTEXT(bgp, bgp);
2228 int idx_number = 3;
2229 uint32_t stalepath;
2230
2231 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2232 bgp->stalepath_time = stalepath;
2233 return CMD_SUCCESS;
2234 }
2235
2236 DEFUN (bgp_graceful_restart_restart_time,
2237 bgp_graceful_restart_restart_time_cmd,
2238 "bgp graceful-restart restart-time (1-4095)",
2239 "BGP specific commands\n"
2240 "Graceful restart capability parameters\n"
2241 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2242 "Delay value (seconds)\n")
2243 {
2244 VTY_DECLVAR_CONTEXT(bgp, bgp);
2245 int idx_number = 3;
2246 uint32_t restart;
2247
2248 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2249 bgp->restart_time = restart;
2250 return CMD_SUCCESS;
2251 }
2252
2253 DEFUN (bgp_graceful_restart_select_defer_time,
2254 bgp_graceful_restart_select_defer_time_cmd,
2255 "bgp graceful-restart select-defer-time (0-3600)",
2256 "BGP specific commands\n"
2257 "Graceful restart capability parameters\n"
2258 "Set the time to defer the BGP route selection after restart\n"
2259 "Delay value (seconds, 0 - disable)\n")
2260 {
2261 VTY_DECLVAR_CONTEXT(bgp, bgp);
2262 int idx_number = 3;
2263 uint32_t defer_time;
2264
2265 defer_time = strtoul(argv[idx_number]->arg, NULL, 10);
2266 bgp->select_defer_time = defer_time;
2267 if (defer_time == 0)
2268 SET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2269 else
2270 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2271
2272 return CMD_SUCCESS;
2273 }
2274
2275 DEFUN (no_bgp_graceful_restart_stalepath_time,
2276 no_bgp_graceful_restart_stalepath_time_cmd,
2277 "no bgp graceful-restart stalepath-time [(1-4095)]",
2278 NO_STR
2279 "BGP specific commands\n"
2280 "Graceful restart capability parameters\n"
2281 "Set the max time to hold onto restarting peer's stale paths\n"
2282 "Delay value (seconds)\n")
2283 {
2284 VTY_DECLVAR_CONTEXT(bgp, bgp);
2285
2286 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2287 return CMD_SUCCESS;
2288 }
2289
2290 DEFUN (no_bgp_graceful_restart_restart_time,
2291 no_bgp_graceful_restart_restart_time_cmd,
2292 "no bgp graceful-restart restart-time [(1-4095)]",
2293 NO_STR
2294 "BGP specific commands\n"
2295 "Graceful restart capability parameters\n"
2296 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2297 "Delay value (seconds)\n")
2298 {
2299 VTY_DECLVAR_CONTEXT(bgp, bgp);
2300
2301 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2302 return CMD_SUCCESS;
2303 }
2304
2305 DEFUN (no_bgp_graceful_restart_select_defer_time,
2306 no_bgp_graceful_restart_select_defer_time_cmd,
2307 "no bgp graceful-restart select-defer-time [(0-3600)]",
2308 NO_STR
2309 "BGP specific commands\n"
2310 "Graceful restart capability parameters\n"
2311 "Set the time to defer the BGP route selection after restart\n"
2312 "Delay value (seconds)\n")
2313 {
2314 VTY_DECLVAR_CONTEXT(bgp, bgp);
2315
2316 bgp->select_defer_time = BGP_DEFAULT_SELECT_DEFERRAL_TIME;
2317 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2318
2319 return CMD_SUCCESS;
2320 }
2321
2322 DEFUN (bgp_graceful_restart_preserve_fw,
2323 bgp_graceful_restart_preserve_fw_cmd,
2324 "bgp graceful-restart preserve-fw-state",
2325 "BGP specific commands\n"
2326 "Graceful restart capability parameters\n"
2327 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
2328 {
2329 VTY_DECLVAR_CONTEXT(bgp, bgp);
2330 SET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
2331 return CMD_SUCCESS;
2332 }
2333
2334 DEFUN (no_bgp_graceful_restart_preserve_fw,
2335 no_bgp_graceful_restart_preserve_fw_cmd,
2336 "no bgp graceful-restart preserve-fw-state",
2337 NO_STR
2338 "BGP specific commands\n"
2339 "Graceful restart capability parameters\n"
2340 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
2341 {
2342 VTY_DECLVAR_CONTEXT(bgp, bgp);
2343 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
2344 return CMD_SUCCESS;
2345 }
2346
2347 DEFUN (bgp_graceful_restart_disable,
2348 bgp_graceful_restart_disable_cmd,
2349 "bgp graceful-restart-disable",
2350 "BGP specific commands\n"
2351 GR_DISABLE)
2352 {
2353 int ret = BGP_GR_FAILURE;
2354
2355 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2356 zlog_debug(
2357 "[BGP_GR] bgp_graceful_restart_disable_cmd : START ");
2358
2359 VTY_DECLVAR_CONTEXT(bgp, bgp);
2360
2361 ret = bgp_gr_update_all(bgp, GLOBAL_DISABLE_CMD);
2362
2363 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
2364 bgp->peer, ret);
2365
2366 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2367 zlog_debug(
2368 "[BGP_GR] bgp_graceful_restart_disable_cmd : END ");
2369 vty_out(vty,
2370 "Graceful restart configuration changed, reset all peers to take effect\n");
2371
2372 return bgp_vty_return(vty, ret);
2373 }
2374
2375 DEFUN (no_bgp_graceful_restart_disable,
2376 no_bgp_graceful_restart_disable_cmd,
2377 "no bgp graceful-restart-disable",
2378 NO_STR
2379 "BGP specific commands\n"
2380 NO_GR_DISABLE
2381 )
2382 {
2383 VTY_DECLVAR_CONTEXT(bgp, bgp);
2384
2385 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2386 zlog_debug(
2387 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : START ");
2388
2389 int ret = BGP_GR_FAILURE;
2390
2391 ret = bgp_gr_update_all(bgp, NO_GLOBAL_DISABLE_CMD);
2392
2393 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2394 ret);
2395
2396 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2397 zlog_debug(
2398 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : END ");
2399 vty_out(vty,
2400 "Graceful restart configuration changed, reset all peers to take effect\n");
2401
2402 return bgp_vty_return(vty, ret);
2403 }
2404
2405 DEFUN (bgp_neighbor_graceful_restart_set,
2406 bgp_neighbor_graceful_restart_set_cmd,
2407 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
2408 NEIGHBOR_STR
2409 NEIGHBOR_ADDR_STR2
2410 GR_NEIGHBOR_CMD
2411 )
2412 {
2413 int idx_peer = 1;
2414 struct peer *peer;
2415 int ret = BGP_GR_FAILURE;
2416
2417 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2418
2419 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2420 zlog_debug(
2421 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : START ");
2422
2423 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2424 if (!peer)
2425 return CMD_WARNING_CONFIG_FAILED;
2426
2427 ret = bgp_neighbor_graceful_restart(peer, PEER_GR_CMD);
2428
2429 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2430 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
2431
2432 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2433 zlog_debug(
2434 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : END ");
2435 vty_out(vty,
2436 "Graceful restart configuration changed, reset this peer to take effect\n");
2437
2438 return bgp_vty_return(vty, ret);
2439 }
2440
2441 DEFUN (no_bgp_neighbor_graceful_restart,
2442 no_bgp_neighbor_graceful_restart_set_cmd,
2443 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
2444 NO_STR
2445 NEIGHBOR_STR
2446 NEIGHBOR_ADDR_STR2
2447 NO_GR_NEIGHBOR_CMD
2448 )
2449 {
2450 int idx_peer = 2;
2451 int ret = BGP_GR_FAILURE;
2452 struct peer *peer;
2453
2454 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2455
2456 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2457 if (!peer)
2458 return CMD_WARNING_CONFIG_FAILED;
2459
2460 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2461 zlog_debug(
2462 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : START ");
2463
2464 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_GR_CMD);
2465
2466 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2467 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
2468
2469 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2470 zlog_debug(
2471 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : END ");
2472 vty_out(vty,
2473 "Graceful restart configuration changed, reset this peer to take effect\n");
2474
2475 return bgp_vty_return(vty, ret);
2476 }
2477
2478 DEFUN (bgp_neighbor_graceful_restart_helper_set,
2479 bgp_neighbor_graceful_restart_helper_set_cmd,
2480 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
2481 NEIGHBOR_STR
2482 NEIGHBOR_ADDR_STR2
2483 GR_NEIGHBOR_HELPER_CMD
2484 )
2485 {
2486 int idx_peer = 1;
2487 struct peer *peer;
2488 int ret = BGP_GR_FAILURE;
2489
2490 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2491
2492 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2493 zlog_debug(
2494 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : START ");
2495
2496 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2497
2498 if (!peer)
2499 return CMD_WARNING_CONFIG_FAILED;
2500
2501
2502 ret = bgp_neighbor_graceful_restart(peer, PEER_HELPER_CMD);
2503
2504 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2505 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
2506
2507 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2508 zlog_debug(
2509 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : END ");
2510 vty_out(vty,
2511 "Graceful restart configuration changed, reset this peer to take effect\n");
2512
2513 return bgp_vty_return(vty, ret);
2514 }
2515
2516 DEFUN (no_bgp_neighbor_graceful_restart_helper,
2517 no_bgp_neighbor_graceful_restart_helper_set_cmd,
2518 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
2519 NO_STR
2520 NEIGHBOR_STR
2521 NEIGHBOR_ADDR_STR2
2522 NO_GR_NEIGHBOR_HELPER_CMD
2523 )
2524 {
2525 int idx_peer = 2;
2526 int ret = BGP_GR_FAILURE;
2527 struct peer *peer;
2528
2529 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2530
2531 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2532 if (!peer)
2533 return CMD_WARNING_CONFIG_FAILED;
2534
2535 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2536 zlog_debug(
2537 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : START ");
2538
2539 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_HELPER_CMD);
2540
2541 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2542 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
2543
2544 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2545 zlog_debug(
2546 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : END ");
2547 vty_out(vty,
2548 "Graceful restart configuration changed, reset this peer to take effect\n");
2549
2550 return bgp_vty_return(vty, ret);
2551 }
2552
2553 DEFUN (bgp_neighbor_graceful_restart_disable_set,
2554 bgp_neighbor_graceful_restart_disable_set_cmd,
2555 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
2556 NEIGHBOR_STR
2557 NEIGHBOR_ADDR_STR2
2558 GR_NEIGHBOR_DISABLE_CMD
2559 )
2560 {
2561 int idx_peer = 1;
2562 struct peer *peer;
2563 int ret = BGP_GR_FAILURE;
2564
2565 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2566
2567 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2568 zlog_debug(
2569 "[BGP_GR] bgp_neighbor_graceful_restart_disable_set_cmd : START ");
2570
2571 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2572 if (!peer)
2573 return CMD_WARNING_CONFIG_FAILED;
2574
2575 ret = bgp_neighbor_graceful_restart(peer, PEER_DISABLE_CMD);
2576
2577 if (peer->bgp->t_startup)
2578 bgp_peer_gr_flags_update(peer);
2579
2580 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2581 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
2582
2583 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2584 zlog_debug(
2585 "[BGP_GR]bgp_neighbor_graceful_restart_disable_set_cmd : END ");
2586 vty_out(vty,
2587 "Graceful restart configuration changed, reset this peer to take effect\n");
2588
2589 return bgp_vty_return(vty, ret);
2590 }
2591
2592 DEFUN (no_bgp_neighbor_graceful_restart_disable,
2593 no_bgp_neighbor_graceful_restart_disable_set_cmd,
2594 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
2595 NO_STR
2596 NEIGHBOR_STR
2597 NEIGHBOR_ADDR_STR2
2598 NO_GR_NEIGHBOR_DISABLE_CMD
2599 )
2600 {
2601 int idx_peer = 2;
2602 int ret = BGP_GR_FAILURE;
2603 struct peer *peer;
2604
2605 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2606
2607 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2608 if (!peer)
2609 return CMD_WARNING_CONFIG_FAILED;
2610
2611 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2612 zlog_debug(
2613 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : START ");
2614
2615 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_DISABLE_CMD);
2616
2617 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2618 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
2619
2620 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2621 zlog_debug(
2622 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : END ");
2623 vty_out(vty,
2624 "Graceful restart configuration changed, reset this peer to take effect\n");
2625
2626 return bgp_vty_return(vty, ret);
2627 }
2628
2629 DEFUN_HIDDEN (bgp_graceful_restart_disable_eor,
2630 bgp_graceful_restart_disable_eor_cmd,
2631 "bgp graceful-restart disable-eor",
2632 "BGP specific commands\n"
2633 "Graceful restart configuration parameters\n"
2634 "Disable EOR Check\n")
2635 {
2636 VTY_DECLVAR_CONTEXT(bgp, bgp);
2637 SET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
2638
2639 return CMD_SUCCESS;
2640 }
2641
2642 DEFUN_HIDDEN (no_bgp_graceful_restart_disable_eor,
2643 no_bgp_graceful_restart_disable_eor_cmd,
2644 "no bgp graceful-restart disable-eor",
2645 NO_STR
2646 "BGP specific commands\n"
2647 "Graceful restart configuration parameters\n"
2648 "Disable EOR Check\n")
2649 {
2650 VTY_DECLVAR_CONTEXT(bgp, bgp);
2651 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
2652
2653 return CMD_SUCCESS;
2654 }
2655
2656 DEFUN (bgp_graceful_restart_rib_stale_time,
2657 bgp_graceful_restart_rib_stale_time_cmd,
2658 "bgp graceful-restart rib-stale-time (1-3600)",
2659 "BGP specific commands\n"
2660 "Graceful restart configuration parameters\n"
2661 "Specify the stale route removal timer in rib\n"
2662 "Delay value (seconds)\n")
2663 {
2664 VTY_DECLVAR_CONTEXT(bgp, bgp);
2665 int idx_number = 3;
2666 uint32_t stale_time;
2667
2668 stale_time = strtoul(argv[idx_number]->arg, NULL, 10);
2669 bgp->rib_stale_time = stale_time;
2670 /* Send the stale timer update message to RIB */
2671 if (bgp_zebra_stale_timer_update(bgp))
2672 return CMD_WARNING;
2673
2674 return CMD_SUCCESS;
2675 }
2676
2677 DEFUN (no_bgp_graceful_restart_rib_stale_time,
2678 no_bgp_graceful_restart_rib_stale_time_cmd,
2679 "no bgp graceful-restart rib-stale-time [(1-3600)]",
2680 NO_STR
2681 "BGP specific commands\n"
2682 "Graceful restart configuration parameters\n"
2683 "Specify the stale route removal timer in rib\n"
2684 "Delay value (seconds)\n")
2685 {
2686 VTY_DECLVAR_CONTEXT(bgp, bgp);
2687
2688 bgp->rib_stale_time = BGP_DEFAULT_RIB_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 /* "bgp graceful-shutdown" configuration */
2697 DEFUN (bgp_graceful_shutdown,
2698 bgp_graceful_shutdown_cmd,
2699 "bgp graceful-shutdown",
2700 BGP_STR
2701 "Graceful shutdown parameters\n")
2702 {
2703 VTY_DECLVAR_CONTEXT(bgp, bgp);
2704
2705 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2706 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
2707 bgp_static_redo_import_check(bgp);
2708 bgp_redistribute_redo(bgp);
2709 bgp_clear_star_soft_out(vty, bgp->name);
2710 bgp_clear_star_soft_in(vty, bgp->name);
2711 }
2712
2713 return CMD_SUCCESS;
2714 }
2715
2716 DEFUN (no_bgp_graceful_shutdown,
2717 no_bgp_graceful_shutdown_cmd,
2718 "no bgp graceful-shutdown",
2719 NO_STR
2720 BGP_STR
2721 "Graceful shutdown parameters\n")
2722 {
2723 VTY_DECLVAR_CONTEXT(bgp, bgp);
2724
2725 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2726 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
2727 bgp_static_redo_import_check(bgp);
2728 bgp_redistribute_redo(bgp);
2729 bgp_clear_star_soft_out(vty, bgp->name);
2730 bgp_clear_star_soft_in(vty, bgp->name);
2731 }
2732
2733 return CMD_SUCCESS;
2734 }
2735
2736 /* "bgp fast-external-failover" configuration. */
2737 DEFUN (bgp_fast_external_failover,
2738 bgp_fast_external_failover_cmd,
2739 "bgp fast-external-failover",
2740 BGP_STR
2741 "Immediately reset session if a link to a directly connected external peer goes down\n")
2742 {
2743 VTY_DECLVAR_CONTEXT(bgp, bgp);
2744 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2745 return CMD_SUCCESS;
2746 }
2747
2748 DEFUN (no_bgp_fast_external_failover,
2749 no_bgp_fast_external_failover_cmd,
2750 "no bgp fast-external-failover",
2751 NO_STR
2752 BGP_STR
2753 "Immediately reset session if a link to a directly connected external peer goes down\n")
2754 {
2755 VTY_DECLVAR_CONTEXT(bgp, bgp);
2756 SET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2757 return CMD_SUCCESS;
2758 }
2759
2760 /* "bgp bestpath compare-routerid" configuration. */
2761 DEFUN (bgp_bestpath_compare_router_id,
2762 bgp_bestpath_compare_router_id_cmd,
2763 "bgp bestpath compare-routerid",
2764 "BGP specific commands\n"
2765 "Change the default bestpath selection\n"
2766 "Compare router-id for identical EBGP paths\n")
2767 {
2768 VTY_DECLVAR_CONTEXT(bgp, bgp);
2769 SET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
2770 bgp_recalculate_all_bestpaths(bgp);
2771
2772 return CMD_SUCCESS;
2773 }
2774
2775 DEFUN (no_bgp_bestpath_compare_router_id,
2776 no_bgp_bestpath_compare_router_id_cmd,
2777 "no bgp bestpath compare-routerid",
2778 NO_STR
2779 "BGP specific commands\n"
2780 "Change the default bestpath selection\n"
2781 "Compare router-id for identical EBGP paths\n")
2782 {
2783 VTY_DECLVAR_CONTEXT(bgp, bgp);
2784 UNSET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
2785 bgp_recalculate_all_bestpaths(bgp);
2786
2787 return CMD_SUCCESS;
2788 }
2789
2790 /* "bgp bestpath as-path ignore" configuration. */
2791 DEFUN (bgp_bestpath_aspath_ignore,
2792 bgp_bestpath_aspath_ignore_cmd,
2793 "bgp bestpath as-path ignore",
2794 "BGP specific commands\n"
2795 "Change the default bestpath selection\n"
2796 "AS-path attribute\n"
2797 "Ignore as-path length in selecting a route\n")
2798 {
2799 VTY_DECLVAR_CONTEXT(bgp, bgp);
2800 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
2801 bgp_recalculate_all_bestpaths(bgp);
2802
2803 return CMD_SUCCESS;
2804 }
2805
2806 DEFUN (no_bgp_bestpath_aspath_ignore,
2807 no_bgp_bestpath_aspath_ignore_cmd,
2808 "no bgp bestpath as-path ignore",
2809 NO_STR
2810 "BGP specific commands\n"
2811 "Change the default bestpath selection\n"
2812 "AS-path attribute\n"
2813 "Ignore as-path length in selecting a route\n")
2814 {
2815 VTY_DECLVAR_CONTEXT(bgp, bgp);
2816 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
2817 bgp_recalculate_all_bestpaths(bgp);
2818
2819 return CMD_SUCCESS;
2820 }
2821
2822 /* "bgp bestpath as-path confed" configuration. */
2823 DEFUN (bgp_bestpath_aspath_confed,
2824 bgp_bestpath_aspath_confed_cmd,
2825 "bgp bestpath as-path confed",
2826 "BGP specific commands\n"
2827 "Change the default bestpath selection\n"
2828 "AS-path attribute\n"
2829 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2830 {
2831 VTY_DECLVAR_CONTEXT(bgp, bgp);
2832 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
2833 bgp_recalculate_all_bestpaths(bgp);
2834
2835 return CMD_SUCCESS;
2836 }
2837
2838 DEFUN (no_bgp_bestpath_aspath_confed,
2839 no_bgp_bestpath_aspath_confed_cmd,
2840 "no bgp bestpath as-path confed",
2841 NO_STR
2842 "BGP specific commands\n"
2843 "Change the default bestpath selection\n"
2844 "AS-path attribute\n"
2845 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2846 {
2847 VTY_DECLVAR_CONTEXT(bgp, bgp);
2848 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
2849 bgp_recalculate_all_bestpaths(bgp);
2850
2851 return CMD_SUCCESS;
2852 }
2853
2854 /* "bgp bestpath as-path multipath-relax" configuration. */
2855 DEFUN (bgp_bestpath_aspath_multipath_relax,
2856 bgp_bestpath_aspath_multipath_relax_cmd,
2857 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
2858 "BGP specific commands\n"
2859 "Change the default bestpath selection\n"
2860 "AS-path attribute\n"
2861 "Allow load sharing across routes that have different AS paths (but same length)\n"
2862 "Generate an AS_SET\n"
2863 "Do not generate an AS_SET\n")
2864 {
2865 VTY_DECLVAR_CONTEXT(bgp, bgp);
2866 int idx = 0;
2867 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2868
2869 /* no-as-set is now the default behavior so we can silently
2870 * ignore it */
2871 if (argv_find(argv, argc, "as-set", &idx))
2872 SET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2873 else
2874 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2875
2876 bgp_recalculate_all_bestpaths(bgp);
2877
2878 return CMD_SUCCESS;
2879 }
2880
2881 DEFUN (no_bgp_bestpath_aspath_multipath_relax,
2882 no_bgp_bestpath_aspath_multipath_relax_cmd,
2883 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
2884 NO_STR
2885 "BGP specific commands\n"
2886 "Change the default bestpath selection\n"
2887 "AS-path attribute\n"
2888 "Allow load sharing across routes that have different AS paths (but same length)\n"
2889 "Generate an AS_SET\n"
2890 "Do not generate an AS_SET\n")
2891 {
2892 VTY_DECLVAR_CONTEXT(bgp, bgp);
2893 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2894 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2895 bgp_recalculate_all_bestpaths(bgp);
2896
2897 return CMD_SUCCESS;
2898 }
2899
2900 /* "bgp log-neighbor-changes" configuration. */
2901 DEFUN (bgp_log_neighbor_changes,
2902 bgp_log_neighbor_changes_cmd,
2903 "bgp log-neighbor-changes",
2904 "BGP specific commands\n"
2905 "Log neighbor up/down and reset reason\n")
2906 {
2907 VTY_DECLVAR_CONTEXT(bgp, bgp);
2908 SET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2909 return CMD_SUCCESS;
2910 }
2911
2912 DEFUN (no_bgp_log_neighbor_changes,
2913 no_bgp_log_neighbor_changes_cmd,
2914 "no bgp log-neighbor-changes",
2915 NO_STR
2916 "BGP specific commands\n"
2917 "Log neighbor up/down and reset reason\n")
2918 {
2919 VTY_DECLVAR_CONTEXT(bgp, bgp);
2920 UNSET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2921 return CMD_SUCCESS;
2922 }
2923
2924 /* "bgp bestpath med" configuration. */
2925 DEFUN (bgp_bestpath_med,
2926 bgp_bestpath_med_cmd,
2927 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
2928 "BGP specific commands\n"
2929 "Change the default bestpath selection\n"
2930 "MED attribute\n"
2931 "Compare MED among confederation paths\n"
2932 "Treat missing MED as the least preferred one\n"
2933 "Treat missing MED as the least preferred one\n"
2934 "Compare MED among confederation paths\n")
2935 {
2936 VTY_DECLVAR_CONTEXT(bgp, bgp);
2937
2938 int idx = 0;
2939 if (argv_find(argv, argc, "confed", &idx))
2940 SET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
2941 idx = 0;
2942 if (argv_find(argv, argc, "missing-as-worst", &idx))
2943 SET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
2944
2945 bgp_recalculate_all_bestpaths(bgp);
2946
2947 return CMD_SUCCESS;
2948 }
2949
2950 DEFUN (no_bgp_bestpath_med,
2951 no_bgp_bestpath_med_cmd,
2952 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
2953 NO_STR
2954 "BGP specific commands\n"
2955 "Change the default bestpath selection\n"
2956 "MED attribute\n"
2957 "Compare MED among confederation paths\n"
2958 "Treat missing MED as the least preferred one\n"
2959 "Treat missing MED as the least preferred one\n"
2960 "Compare MED among confederation paths\n")
2961 {
2962 VTY_DECLVAR_CONTEXT(bgp, bgp);
2963
2964 int idx = 0;
2965 if (argv_find(argv, argc, "confed", &idx))
2966 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
2967 idx = 0;
2968 if (argv_find(argv, argc, "missing-as-worst", &idx))
2969 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
2970
2971 bgp_recalculate_all_bestpaths(bgp);
2972
2973 return CMD_SUCCESS;
2974 }
2975
2976 /* "no bgp default ipv4-unicast". */
2977 DEFUN (no_bgp_default_ipv4_unicast,
2978 no_bgp_default_ipv4_unicast_cmd,
2979 "no bgp default ipv4-unicast",
2980 NO_STR
2981 "BGP specific commands\n"
2982 "Configure BGP defaults\n"
2983 "Activate ipv4-unicast for a peer by default\n")
2984 {
2985 VTY_DECLVAR_CONTEXT(bgp, bgp);
2986 SET_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4);
2987 return CMD_SUCCESS;
2988 }
2989
2990 DEFUN (bgp_default_ipv4_unicast,
2991 bgp_default_ipv4_unicast_cmd,
2992 "bgp default ipv4-unicast",
2993 "BGP specific commands\n"
2994 "Configure BGP defaults\n"
2995 "Activate ipv4-unicast for a peer by default\n")
2996 {
2997 VTY_DECLVAR_CONTEXT(bgp, bgp);
2998 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4);
2999 return CMD_SUCCESS;
3000 }
3001
3002 /* Display hostname in certain command outputs */
3003 DEFUN (bgp_default_show_hostname,
3004 bgp_default_show_hostname_cmd,
3005 "bgp default show-hostname",
3006 "BGP specific commands\n"
3007 "Configure BGP defaults\n"
3008 "Show hostname in certain command outputs\n")
3009 {
3010 VTY_DECLVAR_CONTEXT(bgp, bgp);
3011 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
3012 return CMD_SUCCESS;
3013 }
3014
3015 DEFUN (no_bgp_default_show_hostname,
3016 no_bgp_default_show_hostname_cmd,
3017 "no bgp default show-hostname",
3018 NO_STR
3019 "BGP specific commands\n"
3020 "Configure BGP defaults\n"
3021 "Show hostname in certain command outputs\n")
3022 {
3023 VTY_DECLVAR_CONTEXT(bgp, bgp);
3024 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
3025 return CMD_SUCCESS;
3026 }
3027
3028 /* "bgp network import-check" configuration. */
3029 DEFUN (bgp_network_import_check,
3030 bgp_network_import_check_cmd,
3031 "bgp network import-check",
3032 "BGP specific commands\n"
3033 "BGP network command\n"
3034 "Check BGP network route exists in IGP\n")
3035 {
3036 VTY_DECLVAR_CONTEXT(bgp, bgp);
3037 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
3038 SET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
3039 bgp_static_redo_import_check(bgp);
3040 }
3041
3042 return CMD_SUCCESS;
3043 }
3044
3045 ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
3046 "bgp network import-check exact",
3047 "BGP specific commands\n"
3048 "BGP network command\n"
3049 "Check BGP network route exists in IGP\n"
3050 "Match route precisely\n")
3051
3052 DEFUN (no_bgp_network_import_check,
3053 no_bgp_network_import_check_cmd,
3054 "no bgp network import-check",
3055 NO_STR
3056 "BGP specific commands\n"
3057 "BGP network command\n"
3058 "Check BGP network route exists in IGP\n")
3059 {
3060 VTY_DECLVAR_CONTEXT(bgp, bgp);
3061 if (CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
3062 UNSET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
3063 bgp_static_redo_import_check(bgp);
3064 }
3065
3066 return CMD_SUCCESS;
3067 }
3068
3069 DEFUN (bgp_default_local_preference,
3070 bgp_default_local_preference_cmd,
3071 "bgp default local-preference (0-4294967295)",
3072 "BGP specific commands\n"
3073 "Configure BGP defaults\n"
3074 "local preference (higher=more preferred)\n"
3075 "Configure default local preference value\n")
3076 {
3077 VTY_DECLVAR_CONTEXT(bgp, bgp);
3078 int idx_number = 3;
3079 uint32_t local_pref;
3080
3081 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
3082
3083 bgp_default_local_preference_set(bgp, local_pref);
3084 bgp_clear_star_soft_in(vty, bgp->name);
3085
3086 return CMD_SUCCESS;
3087 }
3088
3089 DEFUN (no_bgp_default_local_preference,
3090 no_bgp_default_local_preference_cmd,
3091 "no bgp default local-preference [(0-4294967295)]",
3092 NO_STR
3093 "BGP specific commands\n"
3094 "Configure BGP defaults\n"
3095 "local preference (higher=more preferred)\n"
3096 "Configure default local preference value\n")
3097 {
3098 VTY_DECLVAR_CONTEXT(bgp, bgp);
3099 bgp_default_local_preference_unset(bgp);
3100 bgp_clear_star_soft_in(vty, bgp->name);
3101
3102 return CMD_SUCCESS;
3103 }
3104
3105
3106 DEFUN (bgp_default_subgroup_pkt_queue_max,
3107 bgp_default_subgroup_pkt_queue_max_cmd,
3108 "bgp default subgroup-pkt-queue-max (20-100)",
3109 "BGP specific commands\n"
3110 "Configure BGP defaults\n"
3111 "subgroup-pkt-queue-max\n"
3112 "Configure subgroup packet queue max\n")
3113 {
3114 VTY_DECLVAR_CONTEXT(bgp, bgp);
3115 int idx_number = 3;
3116 uint32_t max_size;
3117
3118 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
3119
3120 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
3121
3122 return CMD_SUCCESS;
3123 }
3124
3125 DEFUN (no_bgp_default_subgroup_pkt_queue_max,
3126 no_bgp_default_subgroup_pkt_queue_max_cmd,
3127 "no bgp default subgroup-pkt-queue-max [(20-100)]",
3128 NO_STR
3129 "BGP specific commands\n"
3130 "Configure BGP defaults\n"
3131 "subgroup-pkt-queue-max\n"
3132 "Configure subgroup packet queue max\n")
3133 {
3134 VTY_DECLVAR_CONTEXT(bgp, bgp);
3135 bgp_default_subgroup_pkt_queue_max_unset(bgp);
3136 return CMD_SUCCESS;
3137 }
3138
3139
3140 DEFUN (bgp_rr_allow_outbound_policy,
3141 bgp_rr_allow_outbound_policy_cmd,
3142 "bgp route-reflector allow-outbound-policy",
3143 "BGP specific commands\n"
3144 "Allow modifications made by out route-map\n"
3145 "on ibgp neighbors\n")
3146 {
3147 VTY_DECLVAR_CONTEXT(bgp, bgp);
3148
3149 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
3150 SET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
3151 update_group_announce_rrclients(bgp);
3152 bgp_clear_star_soft_out(vty, bgp->name);
3153 }
3154
3155 return CMD_SUCCESS;
3156 }
3157
3158 DEFUN (no_bgp_rr_allow_outbound_policy,
3159 no_bgp_rr_allow_outbound_policy_cmd,
3160 "no bgp route-reflector allow-outbound-policy",
3161 NO_STR
3162 "BGP specific commands\n"
3163 "Allow modifications made by out route-map\n"
3164 "on ibgp neighbors\n")
3165 {
3166 VTY_DECLVAR_CONTEXT(bgp, bgp);
3167
3168 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
3169 UNSET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
3170 update_group_announce_rrclients(bgp);
3171 bgp_clear_star_soft_out(vty, bgp->name);
3172 }
3173
3174 return CMD_SUCCESS;
3175 }
3176
3177 DEFUN (bgp_listen_limit,
3178 bgp_listen_limit_cmd,
3179 "bgp listen limit (1-5000)",
3180 "BGP specific commands\n"
3181 "BGP Dynamic Neighbors listen commands\n"
3182 "Maximum number of BGP Dynamic Neighbors that can be created\n"
3183 "Configure Dynamic Neighbors listen limit value\n")
3184 {
3185 VTY_DECLVAR_CONTEXT(bgp, bgp);
3186 int idx_number = 3;
3187 int listen_limit;
3188
3189 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
3190
3191 bgp_listen_limit_set(bgp, listen_limit);
3192
3193 return CMD_SUCCESS;
3194 }
3195
3196 DEFUN (no_bgp_listen_limit,
3197 no_bgp_listen_limit_cmd,
3198 "no bgp listen limit [(1-5000)]",
3199 NO_STR
3200 "BGP specific commands\n"
3201 "BGP Dynamic Neighbors listen commands\n"
3202 "Maximum number of BGP Dynamic Neighbors that can be created\n"
3203 "Configure Dynamic Neighbors listen limit value\n")
3204 {
3205 VTY_DECLVAR_CONTEXT(bgp, bgp);
3206 bgp_listen_limit_unset(bgp);
3207 return CMD_SUCCESS;
3208 }
3209
3210
3211 /*
3212 * Check if this listen range is already configured. Check for exact
3213 * match or overlap based on input.
3214 */
3215 static struct peer_group *listen_range_exists(struct bgp *bgp,
3216 struct prefix *range, int exact)
3217 {
3218 struct listnode *node, *nnode;
3219 struct listnode *node1, *nnode1;
3220 struct peer_group *group;
3221 struct prefix *lr;
3222 afi_t afi;
3223 int match;
3224
3225 afi = family2afi(range->family);
3226 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
3227 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
3228 lr)) {
3229 if (exact)
3230 match = prefix_same(range, lr);
3231 else
3232 match = (prefix_match(range, lr)
3233 || prefix_match(lr, range));
3234 if (match)
3235 return group;
3236 }
3237 }
3238
3239 return NULL;
3240 }
3241
3242 DEFUN (bgp_listen_range,
3243 bgp_listen_range_cmd,
3244 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
3245 "BGP specific commands\n"
3246 "Configure BGP dynamic neighbors listen range\n"
3247 "Configure BGP dynamic neighbors listen range\n"
3248 NEIGHBOR_ADDR_STR
3249 "Member of the peer-group\n"
3250 "Peer-group name\n")
3251 {
3252 VTY_DECLVAR_CONTEXT(bgp, bgp);
3253 struct prefix range;
3254 struct peer_group *group, *existing_group;
3255 afi_t afi;
3256 int ret;
3257 int idx = 0;
3258
3259 argv_find(argv, argc, "A.B.C.D/M", &idx);
3260 argv_find(argv, argc, "X:X::X:X/M", &idx);
3261 char *prefix = argv[idx]->arg;
3262 argv_find(argv, argc, "PGNAME", &idx);
3263 char *peergroup = argv[idx]->arg;
3264
3265 /* Convert IP prefix string to struct prefix. */
3266 ret = str2prefix(prefix, &range);
3267 if (!ret) {
3268 vty_out(vty, "%% Malformed listen range\n");
3269 return CMD_WARNING_CONFIG_FAILED;
3270 }
3271
3272 afi = family2afi(range.family);
3273
3274 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
3275 vty_out(vty,
3276 "%% Malformed listen range (link-local address)\n");
3277 return CMD_WARNING_CONFIG_FAILED;
3278 }
3279
3280 apply_mask(&range);
3281
3282 /* Check if same listen range is already configured. */
3283 existing_group = listen_range_exists(bgp, &range, 1);
3284 if (existing_group) {
3285 if (strcmp(existing_group->name, peergroup) == 0)
3286 return CMD_SUCCESS;
3287 else {
3288 vty_out(vty,
3289 "%% Same listen range is attached to peer-group %s\n",
3290 existing_group->name);
3291 return CMD_WARNING_CONFIG_FAILED;
3292 }
3293 }
3294
3295 /* Check if an overlapping listen range exists. */
3296 if (listen_range_exists(bgp, &range, 0)) {
3297 vty_out(vty,
3298 "%% Listen range overlaps with existing listen range\n");
3299 return CMD_WARNING_CONFIG_FAILED;
3300 }
3301
3302 group = peer_group_lookup(bgp, peergroup);
3303 if (!group) {
3304 vty_out(vty, "%% Configure the peer-group first\n");
3305 return CMD_WARNING_CONFIG_FAILED;
3306 }
3307
3308 ret = peer_group_listen_range_add(group, &range);
3309 return bgp_vty_return(vty, ret);
3310 }
3311
3312 DEFUN (no_bgp_listen_range,
3313 no_bgp_listen_range_cmd,
3314 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
3315 NO_STR
3316 "BGP specific commands\n"
3317 "Unconfigure BGP dynamic neighbors listen range\n"
3318 "Unconfigure BGP dynamic neighbors listen range\n"
3319 NEIGHBOR_ADDR_STR
3320 "Member of the peer-group\n"
3321 "Peer-group name\n")
3322 {
3323 VTY_DECLVAR_CONTEXT(bgp, bgp);
3324 struct prefix range;
3325 struct peer_group *group;
3326 afi_t afi;
3327 int ret;
3328 int idx = 0;
3329
3330 argv_find(argv, argc, "A.B.C.D/M", &idx);
3331 argv_find(argv, argc, "X:X::X:X/M", &idx);
3332 char *prefix = argv[idx]->arg;
3333 argv_find(argv, argc, "PGNAME", &idx);
3334 char *peergroup = argv[idx]->arg;
3335
3336 /* Convert IP prefix string to struct prefix. */
3337 ret = str2prefix(prefix, &range);
3338 if (!ret) {
3339 vty_out(vty, "%% Malformed listen range\n");
3340 return CMD_WARNING_CONFIG_FAILED;
3341 }
3342
3343 afi = family2afi(range.family);
3344
3345 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
3346 vty_out(vty,
3347 "%% Malformed listen range (link-local address)\n");
3348 return CMD_WARNING_CONFIG_FAILED;
3349 }
3350
3351 apply_mask(&range);
3352
3353 group = peer_group_lookup(bgp, peergroup);
3354 if (!group) {
3355 vty_out(vty, "%% Peer-group does not exist\n");
3356 return CMD_WARNING_CONFIG_FAILED;
3357 }
3358
3359 ret = peer_group_listen_range_del(group, &range);
3360 return bgp_vty_return(vty, ret);
3361 }
3362
3363 void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
3364 {
3365 struct peer_group *group;
3366 struct listnode *node, *nnode, *rnode, *nrnode;
3367 struct prefix *range;
3368 afi_t afi;
3369 char buf[PREFIX2STR_BUFFER];
3370
3371 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
3372 vty_out(vty, " bgp listen limit %d\n",
3373 bgp->dynamic_neighbors_limit);
3374
3375 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
3376 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
3377 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
3378 nrnode, range)) {
3379 prefix2str(range, buf, sizeof(buf));
3380 vty_out(vty,
3381 " bgp listen range %s peer-group %s\n",
3382 buf, group->name);
3383 }
3384 }
3385 }
3386 }
3387
3388
3389 DEFUN (bgp_disable_connected_route_check,
3390 bgp_disable_connected_route_check_cmd,
3391 "bgp disable-ebgp-connected-route-check",
3392 "BGP specific commands\n"
3393 "Disable checking if nexthop is connected on ebgp sessions\n")
3394 {
3395 VTY_DECLVAR_CONTEXT(bgp, bgp);
3396 SET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
3397 bgp_clear_star_soft_in(vty, bgp->name);
3398
3399 return CMD_SUCCESS;
3400 }
3401
3402 DEFUN (no_bgp_disable_connected_route_check,
3403 no_bgp_disable_connected_route_check_cmd,
3404 "no bgp disable-ebgp-connected-route-check",
3405 NO_STR
3406 "BGP specific commands\n"
3407 "Disable checking if nexthop is connected on ebgp sessions\n")
3408 {
3409 VTY_DECLVAR_CONTEXT(bgp, bgp);
3410 UNSET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
3411 bgp_clear_star_soft_in(vty, bgp->name);
3412
3413 return CMD_SUCCESS;
3414 }
3415
3416
3417 static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
3418 const char *as_str, afi_t afi, safi_t safi)
3419 {
3420 VTY_DECLVAR_CONTEXT(bgp, bgp);
3421 int ret;
3422 as_t as;
3423 int as_type = AS_SPECIFIED;
3424 union sockunion su;
3425
3426 if (as_str[0] == 'i') {
3427 as = 0;
3428 as_type = AS_INTERNAL;
3429 } else if (as_str[0] == 'e') {
3430 as = 0;
3431 as_type = AS_EXTERNAL;
3432 } else {
3433 /* Get AS number. */
3434 as = strtoul(as_str, NULL, 10);
3435 }
3436
3437 /* If peer is peer group or interface peer, call proper function. */
3438 ret = str2sockunion(peer_str, &su);
3439 if (ret < 0) {
3440 struct peer *peer;
3441
3442 /* Check if existing interface peer */
3443 peer = peer_lookup_by_conf_if(bgp, peer_str);
3444
3445 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, afi,
3446 safi);
3447
3448 /* if not interface peer, check peer-group settings */
3449 if (ret < 0 && !peer) {
3450 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
3451 if (ret < 0) {
3452 vty_out(vty,
3453 "%% Create the peer-group or interface first\n");
3454 return CMD_WARNING_CONFIG_FAILED;
3455 }
3456 return CMD_SUCCESS;
3457 }
3458 } else {
3459 if (peer_address_self_check(bgp, &su)) {
3460 vty_out(vty,
3461 "%% Can not configure the local system as neighbor\n");
3462 return CMD_WARNING_CONFIG_FAILED;
3463 }
3464 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, afi, safi);
3465 }
3466
3467 /* This peer belongs to peer group. */
3468 switch (ret) {
3469 case BGP_ERR_PEER_GROUP_MEMBER:
3470 vty_out(vty,
3471 "%% Peer-group member cannot override remote-as of peer-group\n");
3472 return CMD_WARNING_CONFIG_FAILED;
3473 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
3474 vty_out(vty,
3475 "%% Peer-group members must be all internal or all external\n");
3476 return CMD_WARNING_CONFIG_FAILED;
3477 }
3478 return bgp_vty_return(vty, ret);
3479 }
3480
3481 DEFUN (bgp_default_shutdown,
3482 bgp_default_shutdown_cmd,
3483 "[no] bgp default shutdown",
3484 NO_STR
3485 BGP_STR
3486 "Configure BGP defaults\n"
3487 "Apply administrative shutdown to newly configured peers\n")
3488 {
3489 VTY_DECLVAR_CONTEXT(bgp, bgp);
3490 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
3491 return CMD_SUCCESS;
3492 }
3493
3494 DEFUN (neighbor_remote_as,
3495 neighbor_remote_as_cmd,
3496 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
3497 NEIGHBOR_STR
3498 NEIGHBOR_ADDR_STR2
3499 "Specify a BGP neighbor\n"
3500 AS_STR
3501 "Internal BGP peer\n"
3502 "External BGP peer\n")
3503 {
3504 int idx_peer = 1;
3505 int idx_remote_as = 3;
3506 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
3507 argv[idx_remote_as]->arg, AFI_IP,
3508 SAFI_UNICAST);
3509 }
3510
3511 static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
3512 afi_t afi, safi_t safi, int v6only,
3513 const char *peer_group_name,
3514 const char *as_str)
3515 {
3516 VTY_DECLVAR_CONTEXT(bgp, bgp);
3517 as_t as = 0;
3518 int as_type = AS_UNSPECIFIED;
3519 struct peer *peer;
3520 struct peer_group *group;
3521 int ret = 0;
3522 union sockunion su;
3523
3524 group = peer_group_lookup(bgp, conf_if);
3525
3526 if (group) {
3527 vty_out(vty, "%% Name conflict with peer-group \n");
3528 return CMD_WARNING_CONFIG_FAILED;
3529 }
3530
3531 if (as_str) {
3532 if (as_str[0] == 'i') {
3533 as_type = AS_INTERNAL;
3534 } else if (as_str[0] == 'e') {
3535 as_type = AS_EXTERNAL;
3536 } else {
3537 /* Get AS number. */
3538 as = strtoul(as_str, NULL, 10);
3539 as_type = AS_SPECIFIED;
3540 }
3541 }
3542
3543 peer = peer_lookup_by_conf_if(bgp, conf_if);
3544 if (peer) {
3545 if (as_str)
3546 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type,
3547 afi, safi);
3548 } else {
3549 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4)
3550 && afi == AFI_IP && safi == SAFI_UNICAST)
3551 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
3552 as_type, 0, 0, NULL);
3553 else
3554 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
3555 as_type, afi, safi, NULL);
3556
3557 if (!peer) {
3558 vty_out(vty, "%% BGP failed to create peer\n");
3559 return CMD_WARNING_CONFIG_FAILED;
3560 }
3561
3562 if (v6only)
3563 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
3564
3565 /* Request zebra to initiate IPv6 RAs on this interface. We do
3566 * this
3567 * any unnumbered peer in order to not worry about run-time
3568 * transitions
3569 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
3570 * address
3571 * gets deleted later etc.)
3572 */
3573 if (peer->ifp)
3574 bgp_zebra_initiate_radv(bgp, peer);
3575 }
3576
3577 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
3578 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
3579 if (v6only)
3580 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
3581 else
3582 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
3583
3584 /* v6only flag changed. Reset bgp seesion */
3585 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
3586 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
3587 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
3588 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
3589 } else
3590 bgp_session_reset(peer);
3591 }
3592
3593 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
3594 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
3595 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
3596 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
3597 }
3598
3599 if (peer_group_name) {
3600 group = peer_group_lookup(bgp, peer_group_name);
3601 if (!group) {
3602 vty_out(vty, "%% Configure the peer-group first\n");
3603 return CMD_WARNING_CONFIG_FAILED;
3604 }
3605
3606 ret = peer_group_bind(bgp, &su, peer, group, &as);
3607 }
3608
3609 return bgp_vty_return(vty, ret);
3610 }
3611
3612 DEFUN (neighbor_interface_config,
3613 neighbor_interface_config_cmd,
3614 "neighbor WORD interface [peer-group PGNAME]",
3615 NEIGHBOR_STR
3616 "Interface name or neighbor tag\n"
3617 "Enable BGP on interface\n"
3618 "Member of the peer-group\n"
3619 "Peer-group name\n")
3620 {
3621 int idx_word = 1;
3622 int idx_peer_group_word = 4;
3623
3624 if (argc > idx_peer_group_word)
3625 return peer_conf_interface_get(
3626 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
3627 argv[idx_peer_group_word]->arg, NULL);
3628 else
3629 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3630 SAFI_UNICAST, 0, NULL, NULL);
3631 }
3632
3633 DEFUN (neighbor_interface_config_v6only,
3634 neighbor_interface_config_v6only_cmd,
3635 "neighbor WORD interface v6only [peer-group PGNAME]",
3636 NEIGHBOR_STR
3637 "Interface name or neighbor tag\n"
3638 "Enable BGP on interface\n"
3639 "Enable BGP with v6 link-local only\n"
3640 "Member of the peer-group\n"
3641 "Peer-group name\n")
3642 {
3643 int idx_word = 1;
3644 int idx_peer_group_word = 5;
3645
3646 if (argc > idx_peer_group_word)
3647 return peer_conf_interface_get(
3648 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
3649 argv[idx_peer_group_word]->arg, NULL);
3650
3651 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3652 SAFI_UNICAST, 1, NULL, NULL);
3653 }
3654
3655
3656 DEFUN (neighbor_interface_config_remote_as,
3657 neighbor_interface_config_remote_as_cmd,
3658 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
3659 NEIGHBOR_STR
3660 "Interface name or neighbor tag\n"
3661 "Enable BGP on interface\n"
3662 "Specify a BGP neighbor\n"
3663 AS_STR
3664 "Internal BGP peer\n"
3665 "External BGP peer\n")
3666 {
3667 int idx_word = 1;
3668 int idx_remote_as = 4;
3669 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3670 SAFI_UNICAST, 0, NULL,
3671 argv[idx_remote_as]->arg);
3672 }
3673
3674 DEFUN (neighbor_interface_v6only_config_remote_as,
3675 neighbor_interface_v6only_config_remote_as_cmd,
3676 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
3677 NEIGHBOR_STR
3678 "Interface name or neighbor tag\n"
3679 "Enable BGP with v6 link-local only\n"
3680 "Enable BGP on interface\n"
3681 "Specify a BGP neighbor\n"
3682 AS_STR
3683 "Internal BGP peer\n"
3684 "External BGP peer\n")
3685 {
3686 int idx_word = 1;
3687 int idx_remote_as = 5;
3688 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3689 SAFI_UNICAST, 1, NULL,
3690 argv[idx_remote_as]->arg);
3691 }
3692
3693 DEFUN (neighbor_peer_group,
3694 neighbor_peer_group_cmd,
3695 "neighbor WORD peer-group",
3696 NEIGHBOR_STR
3697 "Interface name or neighbor tag\n"
3698 "Configure peer-group\n")
3699 {
3700 VTY_DECLVAR_CONTEXT(bgp, bgp);
3701 int idx_word = 1;
3702 struct peer *peer;
3703 struct peer_group *group;
3704
3705 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3706 if (peer) {
3707 vty_out(vty, "%% Name conflict with interface: \n");
3708 return CMD_WARNING_CONFIG_FAILED;
3709 }
3710
3711 group = peer_group_get(bgp, argv[idx_word]->arg);
3712 if (!group) {
3713 vty_out(vty, "%% BGP failed to find or create peer-group\n");
3714 return CMD_WARNING_CONFIG_FAILED;
3715 }
3716
3717 return CMD_SUCCESS;
3718 }
3719
3720 DEFUN (no_neighbor,
3721 no_neighbor_cmd,
3722 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
3723 NO_STR
3724 NEIGHBOR_STR
3725 NEIGHBOR_ADDR_STR2
3726 "Specify a BGP neighbor\n"
3727 AS_STR
3728 "Internal BGP peer\n"
3729 "External BGP peer\n")
3730 {
3731 VTY_DECLVAR_CONTEXT(bgp, bgp);
3732 int idx_peer = 2;
3733 int ret;
3734 union sockunion su;
3735 struct peer_group *group;
3736 struct peer *peer;
3737 struct peer *other;
3738
3739 ret = str2sockunion(argv[idx_peer]->arg, &su);
3740 if (ret < 0) {
3741 /* look up for neighbor by interface name config. */
3742 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3743 if (peer) {
3744 /* Request zebra to terminate IPv6 RAs on this
3745 * interface. */
3746 if (peer->ifp)
3747 bgp_zebra_terminate_radv(peer->bgp, peer);
3748 peer_notify_unconfig(peer);
3749 peer_delete(peer);
3750 return CMD_SUCCESS;
3751 }
3752
3753 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
3754 if (group) {
3755 peer_group_notify_unconfig(group);
3756 peer_group_delete(group);
3757 } else {
3758 vty_out(vty, "%% Create the peer-group first\n");
3759 return CMD_WARNING_CONFIG_FAILED;
3760 }
3761 } else {
3762 peer = peer_lookup(bgp, &su);
3763 if (peer) {
3764 if (peer_dynamic_neighbor(peer)) {
3765 vty_out(vty,
3766 "%% Operation not allowed on a dynamic neighbor\n");
3767 return CMD_WARNING_CONFIG_FAILED;
3768 }
3769
3770 other = peer->doppelganger;
3771 peer_notify_unconfig(peer);
3772 peer_delete(peer);
3773 if (other && other->status != Deleted) {
3774 peer_notify_unconfig(other);
3775 peer_delete(other);
3776 }
3777 }
3778 }
3779
3780 return CMD_SUCCESS;
3781 }
3782
3783 DEFUN (no_neighbor_interface_config,
3784 no_neighbor_interface_config_cmd,
3785 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
3786 NO_STR
3787 NEIGHBOR_STR
3788 "Interface name\n"
3789 "Configure BGP on interface\n"
3790 "Enable BGP with v6 link-local only\n"
3791 "Member of the peer-group\n"
3792 "Peer-group name\n"
3793 "Specify a BGP neighbor\n"
3794 AS_STR
3795 "Internal BGP peer\n"
3796 "External BGP peer\n")
3797 {
3798 VTY_DECLVAR_CONTEXT(bgp, bgp);
3799 int idx_word = 2;
3800 struct peer *peer;
3801
3802 /* look up for neighbor by interface name config. */
3803 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3804 if (peer) {
3805 /* Request zebra to terminate IPv6 RAs on this interface. */
3806 if (peer->ifp)
3807 bgp_zebra_terminate_radv(peer->bgp, peer);
3808 peer_notify_unconfig(peer);
3809 peer_delete(peer);
3810 } else {
3811 vty_out(vty, "%% Create the bgp interface first\n");
3812 return CMD_WARNING_CONFIG_FAILED;
3813 }
3814 return CMD_SUCCESS;
3815 }
3816
3817 DEFUN (no_neighbor_peer_group,
3818 no_neighbor_peer_group_cmd,
3819 "no neighbor WORD peer-group",
3820 NO_STR
3821 NEIGHBOR_STR
3822 "Neighbor tag\n"
3823 "Configure peer-group\n")
3824 {
3825 VTY_DECLVAR_CONTEXT(bgp, bgp);
3826 int idx_word = 2;
3827 struct peer_group *group;
3828
3829 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3830 if (group) {
3831 peer_group_notify_unconfig(group);
3832 peer_group_delete(group);
3833 } else {
3834 vty_out(vty, "%% Create the peer-group first\n");
3835 return CMD_WARNING_CONFIG_FAILED;
3836 }
3837 return CMD_SUCCESS;
3838 }
3839
3840 DEFUN (no_neighbor_interface_peer_group_remote_as,
3841 no_neighbor_interface_peer_group_remote_as_cmd,
3842 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
3843 NO_STR
3844 NEIGHBOR_STR
3845 "Interface name or neighbor tag\n"
3846 "Specify a BGP neighbor\n"
3847 AS_STR
3848 "Internal BGP peer\n"
3849 "External BGP peer\n")
3850 {
3851 VTY_DECLVAR_CONTEXT(bgp, bgp);
3852 int idx_word = 2;
3853 struct peer_group *group;
3854 struct peer *peer;
3855
3856 /* look up for neighbor by interface name config. */
3857 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3858 if (peer) {
3859 peer_as_change(peer, 0, AS_UNSPECIFIED);
3860 return CMD_SUCCESS;
3861 }
3862
3863 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3864 if (group)
3865 peer_group_remote_as_delete(group);
3866 else {
3867 vty_out(vty, "%% Create the peer-group or interface first\n");
3868 return CMD_WARNING_CONFIG_FAILED;
3869 }
3870 return CMD_SUCCESS;
3871 }
3872
3873 DEFUN (neighbor_local_as,
3874 neighbor_local_as_cmd,
3875 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
3876 NEIGHBOR_STR
3877 NEIGHBOR_ADDR_STR2
3878 "Specify a local-as number\n"
3879 "AS number used as local AS\n")
3880 {
3881 int idx_peer = 1;
3882 int idx_number = 3;
3883 struct peer *peer;
3884 int ret;
3885 as_t as;
3886
3887 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3888 if (!peer)
3889 return CMD_WARNING_CONFIG_FAILED;
3890
3891 as = strtoul(argv[idx_number]->arg, NULL, 10);
3892 ret = peer_local_as_set(peer, as, 0, 0);
3893 return bgp_vty_return(vty, ret);
3894 }
3895
3896 DEFUN (neighbor_local_as_no_prepend,
3897 neighbor_local_as_no_prepend_cmd,
3898 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
3899 NEIGHBOR_STR
3900 NEIGHBOR_ADDR_STR2
3901 "Specify a local-as number\n"
3902 "AS number used as local AS\n"
3903 "Do not prepend local-as to updates from ebgp peers\n")
3904 {
3905 int idx_peer = 1;
3906 int idx_number = 3;
3907 struct peer *peer;
3908 int ret;
3909 as_t as;
3910
3911 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3912 if (!peer)
3913 return CMD_WARNING_CONFIG_FAILED;
3914
3915 as = strtoul(argv[idx_number]->arg, NULL, 10);
3916 ret = peer_local_as_set(peer, as, 1, 0);
3917 return bgp_vty_return(vty, ret);
3918 }
3919
3920 DEFUN (neighbor_local_as_no_prepend_replace_as,
3921 neighbor_local_as_no_prepend_replace_as_cmd,
3922 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
3923 NEIGHBOR_STR
3924 NEIGHBOR_ADDR_STR2
3925 "Specify a local-as number\n"
3926 "AS number used as local AS\n"
3927 "Do not prepend local-as to updates from ebgp peers\n"
3928 "Do not prepend local-as to updates from ibgp peers\n")
3929 {
3930 int idx_peer = 1;
3931 int idx_number = 3;
3932 struct peer *peer;
3933 int ret;
3934 as_t as;
3935
3936 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3937 if (!peer)
3938 return CMD_WARNING_CONFIG_FAILED;
3939
3940 as = strtoul(argv[idx_number]->arg, NULL, 10);
3941 ret = peer_local_as_set(peer, as, 1, 1);
3942 return bgp_vty_return(vty, ret);
3943 }
3944
3945 DEFUN (no_neighbor_local_as,
3946 no_neighbor_local_as_cmd,
3947 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
3948 NO_STR
3949 NEIGHBOR_STR
3950 NEIGHBOR_ADDR_STR2
3951 "Specify a local-as number\n"
3952 "AS number used as local AS\n"
3953 "Do not prepend local-as to updates from ebgp peers\n"
3954 "Do not prepend local-as to updates from ibgp peers\n")
3955 {
3956 int idx_peer = 2;
3957 struct peer *peer;
3958 int ret;
3959
3960 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3961 if (!peer)
3962 return CMD_WARNING_CONFIG_FAILED;
3963
3964 ret = peer_local_as_unset(peer);
3965 return bgp_vty_return(vty, ret);
3966 }
3967
3968
3969 DEFUN (neighbor_solo,
3970 neighbor_solo_cmd,
3971 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3972 NEIGHBOR_STR
3973 NEIGHBOR_ADDR_STR2
3974 "Solo peer - part of its own update group\n")
3975 {
3976 int idx_peer = 1;
3977 struct peer *peer;
3978 int ret;
3979
3980 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3981 if (!peer)
3982 return CMD_WARNING_CONFIG_FAILED;
3983
3984 ret = update_group_adjust_soloness(peer, 1);
3985 return bgp_vty_return(vty, ret);
3986 }
3987
3988 DEFUN (no_neighbor_solo,
3989 no_neighbor_solo_cmd,
3990 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3991 NO_STR
3992 NEIGHBOR_STR
3993 NEIGHBOR_ADDR_STR2
3994 "Solo peer - part of its own update group\n")
3995 {
3996 int idx_peer = 2;
3997 struct peer *peer;
3998 int ret;
3999
4000 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4001 if (!peer)
4002 return CMD_WARNING_CONFIG_FAILED;
4003
4004 ret = update_group_adjust_soloness(peer, 0);
4005 return bgp_vty_return(vty, ret);
4006 }
4007
4008 DEFUN (neighbor_password,
4009 neighbor_password_cmd,
4010 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
4011 NEIGHBOR_STR
4012 NEIGHBOR_ADDR_STR2
4013 "Set a password\n"
4014 "The password\n")
4015 {
4016 int idx_peer = 1;
4017 int idx_line = 3;
4018 struct peer *peer;
4019 int ret;
4020
4021 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4022 if (!peer)
4023 return CMD_WARNING_CONFIG_FAILED;
4024
4025 ret = peer_password_set(peer, argv[idx_line]->arg);
4026 return bgp_vty_return(vty, ret);
4027 }
4028
4029 DEFUN (no_neighbor_password,
4030 no_neighbor_password_cmd,
4031 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
4032 NO_STR
4033 NEIGHBOR_STR
4034 NEIGHBOR_ADDR_STR2
4035 "Set a password\n"
4036 "The password\n")
4037 {
4038 int idx_peer = 2;
4039 struct peer *peer;
4040 int ret;
4041
4042 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4043 if (!peer)
4044 return CMD_WARNING_CONFIG_FAILED;
4045
4046 ret = peer_password_unset(peer);
4047 return bgp_vty_return(vty, ret);
4048 }
4049
4050 DEFUN (neighbor_activate,
4051 neighbor_activate_cmd,
4052 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4053 NEIGHBOR_STR
4054 NEIGHBOR_ADDR_STR2
4055 "Enable the Address Family for this Neighbor\n")
4056 {
4057 int idx_peer = 1;
4058 int ret;
4059 struct peer *peer;
4060
4061 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4062 if (!peer)
4063 return CMD_WARNING_CONFIG_FAILED;
4064
4065 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
4066 return bgp_vty_return(vty, ret);
4067 }
4068
4069 ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
4070 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4071 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4072 "Enable the Address Family for this Neighbor\n")
4073
4074 DEFUN (no_neighbor_activate,
4075 no_neighbor_activate_cmd,
4076 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4077 NO_STR
4078 NEIGHBOR_STR
4079 NEIGHBOR_ADDR_STR2
4080 "Enable the Address Family for this Neighbor\n")
4081 {
4082 int idx_peer = 2;
4083 int ret;
4084 struct peer *peer;
4085
4086 /* Lookup peer. */
4087 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4088 if (!peer)
4089 return CMD_WARNING_CONFIG_FAILED;
4090
4091 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
4092 return bgp_vty_return(vty, ret);
4093 }
4094
4095 ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
4096 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4097 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4098 "Enable the Address Family for this Neighbor\n")
4099
4100 DEFUN (neighbor_set_peer_group,
4101 neighbor_set_peer_group_cmd,
4102 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
4103 NEIGHBOR_STR
4104 NEIGHBOR_ADDR_STR2
4105 "Member of the peer-group\n"
4106 "Peer-group name\n")
4107 {
4108 VTY_DECLVAR_CONTEXT(bgp, bgp);
4109 int idx_peer = 1;
4110 int idx_word = 3;
4111 int ret;
4112 as_t as;
4113 union sockunion su;
4114 struct peer *peer;
4115 struct peer_group *group;
4116
4117 ret = str2sockunion(argv[idx_peer]->arg, &su);
4118 if (ret < 0) {
4119 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4120 if (!peer) {
4121 vty_out(vty, "%% Malformed address or name: %s\n",
4122 argv[idx_peer]->arg);
4123 return CMD_WARNING_CONFIG_FAILED;
4124 }
4125 } else {
4126 if (peer_address_self_check(bgp, &su)) {
4127 vty_out(vty,
4128 "%% Can not configure the local system as neighbor\n");
4129 return CMD_WARNING_CONFIG_FAILED;
4130 }
4131
4132 /* Disallow for dynamic neighbor. */
4133 peer = peer_lookup(bgp, &su);
4134 if (peer && peer_dynamic_neighbor(peer)) {
4135 vty_out(vty,
4136 "%% Operation not allowed on a dynamic neighbor\n");
4137 return CMD_WARNING_CONFIG_FAILED;
4138 }
4139 }
4140
4141 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4142 if (!group) {
4143 vty_out(vty, "%% Configure the peer-group first\n");
4144 return CMD_WARNING_CONFIG_FAILED;
4145 }
4146
4147 ret = peer_group_bind(bgp, &su, peer, group, &as);
4148
4149 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
4150 vty_out(vty,
4151 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
4152 as);
4153 return CMD_WARNING_CONFIG_FAILED;
4154 }
4155
4156 return bgp_vty_return(vty, ret);
4157 }
4158
4159 ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
4160 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
4161 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4162 "Member of the peer-group\n"
4163 "Peer-group name\n")
4164
4165 DEFUN (no_neighbor_set_peer_group,
4166 no_neighbor_set_peer_group_cmd,
4167 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
4168 NO_STR
4169 NEIGHBOR_STR
4170 NEIGHBOR_ADDR_STR2
4171 "Member of the peer-group\n"
4172 "Peer-group name\n")
4173 {
4174 VTY_DECLVAR_CONTEXT(bgp, bgp);
4175 int idx_peer = 2;
4176 int idx_word = 4;
4177 int ret;
4178 struct peer *peer;
4179 struct peer_group *group;
4180
4181 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
4182 if (!peer)
4183 return CMD_WARNING_CONFIG_FAILED;
4184
4185 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4186 if (!group) {
4187 vty_out(vty, "%% Configure the peer-group first\n");
4188 return CMD_WARNING_CONFIG_FAILED;
4189 }
4190
4191 peer_notify_unconfig(peer);
4192 ret = peer_delete(peer);
4193
4194 return bgp_vty_return(vty, ret);
4195 }
4196
4197 ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
4198 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
4199 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4200 "Member of the peer-group\n"
4201 "Peer-group name\n")
4202
4203 static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
4204 uint32_t flag, int set)
4205 {
4206 int ret;
4207 struct peer *peer;
4208
4209 peer = peer_and_group_lookup_vty(vty, ip_str);
4210 if (!peer)
4211 return CMD_WARNING_CONFIG_FAILED;
4212
4213 /*
4214 * If 'neighbor <interface>', then this is for directly connected peers,
4215 * we should not accept disable-connected-check.
4216 */
4217 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
4218 vty_out(vty,
4219 "%s is directly connected peer, cannot accept disable-"
4220 "connected-check\n",
4221 ip_str);
4222 return CMD_WARNING_CONFIG_FAILED;
4223 }
4224
4225 if (!set && flag == PEER_FLAG_SHUTDOWN)
4226 peer_tx_shutdown_message_unset(peer);
4227
4228 if (set)
4229 ret = peer_flag_set(peer, flag);
4230 else
4231 ret = peer_flag_unset(peer, flag);
4232
4233 return bgp_vty_return(vty, ret);
4234 }
4235
4236 static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
4237 {
4238 return peer_flag_modify_vty(vty, ip_str, flag, 1);
4239 }
4240
4241 static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
4242 uint32_t flag)
4243 {
4244 return peer_flag_modify_vty(vty, ip_str, flag, 0);
4245 }
4246
4247 /* neighbor passive. */
4248 DEFUN (neighbor_passive,
4249 neighbor_passive_cmd,
4250 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
4251 NEIGHBOR_STR
4252 NEIGHBOR_ADDR_STR2
4253 "Don't send open messages to this neighbor\n")
4254 {
4255 int idx_peer = 1;
4256 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
4257 }
4258
4259 DEFUN (no_neighbor_passive,
4260 no_neighbor_passive_cmd,
4261 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
4262 NO_STR
4263 NEIGHBOR_STR
4264 NEIGHBOR_ADDR_STR2
4265 "Don't send open messages to this neighbor\n")
4266 {
4267 int idx_peer = 2;
4268 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
4269 }
4270
4271 /* neighbor shutdown. */
4272 DEFUN (neighbor_shutdown_msg,
4273 neighbor_shutdown_msg_cmd,
4274 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
4275 NEIGHBOR_STR
4276 NEIGHBOR_ADDR_STR2
4277 "Administratively shut down this neighbor\n"
4278 "Add a shutdown message (draft-ietf-idr-shutdown-06)\n"
4279 "Shutdown message\n")
4280 {
4281 int idx_peer = 1;
4282
4283 if (argc >= 5) {
4284 struct peer *peer =
4285 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4286 char *message;
4287
4288 if (!peer)
4289 return CMD_WARNING_CONFIG_FAILED;
4290 message = argv_concat(argv, argc, 4);
4291 peer_tx_shutdown_message_set(peer, message);
4292 XFREE(MTYPE_TMP, message);
4293 }
4294
4295 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
4296 }
4297
4298 ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
4299 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
4300 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4301 "Administratively shut down this neighbor\n")
4302
4303 DEFUN (no_neighbor_shutdown_msg,
4304 no_neighbor_shutdown_msg_cmd,
4305 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
4306 NO_STR
4307 NEIGHBOR_STR
4308 NEIGHBOR_ADDR_STR2
4309 "Administratively shut down this neighbor\n"
4310 "Remove a shutdown message (draft-ietf-idr-shutdown-06)\n"
4311 "Shutdown message\n")
4312 {
4313 int idx_peer = 2;
4314
4315 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4316 PEER_FLAG_SHUTDOWN);
4317 }
4318
4319 ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
4320 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
4321 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4322 "Administratively shut down this neighbor\n")
4323
4324 /* neighbor capability dynamic. */
4325 DEFUN (neighbor_capability_dynamic,
4326 neighbor_capability_dynamic_cmd,
4327 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
4328 NEIGHBOR_STR
4329 NEIGHBOR_ADDR_STR2
4330 "Advertise capability to the peer\n"
4331 "Advertise dynamic capability to this neighbor\n")
4332 {
4333 int idx_peer = 1;
4334 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4335 PEER_FLAG_DYNAMIC_CAPABILITY);
4336 }
4337
4338 DEFUN (no_neighbor_capability_dynamic,
4339 no_neighbor_capability_dynamic_cmd,
4340 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
4341 NO_STR
4342 NEIGHBOR_STR
4343 NEIGHBOR_ADDR_STR2
4344 "Advertise capability to the peer\n"
4345 "Advertise dynamic capability to this neighbor\n")
4346 {
4347 int idx_peer = 2;
4348 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4349 PEER_FLAG_DYNAMIC_CAPABILITY);
4350 }
4351
4352 /* neighbor dont-capability-negotiate */
4353 DEFUN (neighbor_dont_capability_negotiate,
4354 neighbor_dont_capability_negotiate_cmd,
4355 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
4356 NEIGHBOR_STR
4357 NEIGHBOR_ADDR_STR2
4358 "Do not perform capability negotiation\n")
4359 {
4360 int idx_peer = 1;
4361 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4362 PEER_FLAG_DONT_CAPABILITY);
4363 }
4364
4365 DEFUN (no_neighbor_dont_capability_negotiate,
4366 no_neighbor_dont_capability_negotiate_cmd,
4367 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
4368 NO_STR
4369 NEIGHBOR_STR
4370 NEIGHBOR_ADDR_STR2
4371 "Do not perform capability negotiation\n")
4372 {
4373 int idx_peer = 2;
4374 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4375 PEER_FLAG_DONT_CAPABILITY);
4376 }
4377
4378 /* neighbor capability extended next hop encoding */
4379 DEFUN (neighbor_capability_enhe,
4380 neighbor_capability_enhe_cmd,
4381 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
4382 NEIGHBOR_STR
4383 NEIGHBOR_ADDR_STR2
4384 "Advertise capability to the peer\n"
4385 "Advertise extended next-hop capability to the peer\n")
4386 {
4387 int idx_peer = 1;
4388 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4389 PEER_FLAG_CAPABILITY_ENHE);
4390 }
4391
4392 DEFUN (no_neighbor_capability_enhe,
4393 no_neighbor_capability_enhe_cmd,
4394 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
4395 NO_STR
4396 NEIGHBOR_STR
4397 NEIGHBOR_ADDR_STR2
4398 "Advertise capability to the peer\n"
4399 "Advertise extended next-hop capability to the peer\n")
4400 {
4401 int idx_peer = 2;
4402 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4403 PEER_FLAG_CAPABILITY_ENHE);
4404 }
4405
4406 static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
4407 afi_t afi, safi_t safi, uint32_t flag,
4408 int set)
4409 {
4410 int ret;
4411 struct peer *peer;
4412
4413 peer = peer_and_group_lookup_vty(vty, peer_str);
4414 if (!peer)
4415 return CMD_WARNING_CONFIG_FAILED;
4416
4417 if (set)
4418 ret = peer_af_flag_set(peer, afi, safi, flag);
4419 else
4420 ret = peer_af_flag_unset(peer, afi, safi, flag);
4421
4422 return bgp_vty_return(vty, ret);
4423 }
4424
4425 static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
4426 afi_t afi, safi_t safi, uint32_t flag)
4427 {
4428 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
4429 }
4430
4431 static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
4432 afi_t afi, safi_t safi, uint32_t flag)
4433 {
4434 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
4435 }
4436
4437 /* neighbor capability orf prefix-list. */
4438 DEFUN (neighbor_capability_orf_prefix,
4439 neighbor_capability_orf_prefix_cmd,
4440 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
4441 NEIGHBOR_STR
4442 NEIGHBOR_ADDR_STR2
4443 "Advertise capability to the peer\n"
4444 "Advertise ORF capability to the peer\n"
4445 "Advertise prefixlist ORF capability to this neighbor\n"
4446 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
4447 "Capability to RECEIVE the ORF from this neighbor\n"
4448 "Capability to SEND the ORF to this neighbor\n")
4449 {
4450 int idx_peer = 1;
4451 int idx_send_recv = 5;
4452 uint16_t flag = 0;
4453
4454 if (strmatch(argv[idx_send_recv]->text, "send"))
4455 flag = PEER_FLAG_ORF_PREFIX_SM;
4456 else if (strmatch(argv[idx_send_recv]->text, "receive"))
4457 flag = PEER_FLAG_ORF_PREFIX_RM;
4458 else if (strmatch(argv[idx_send_recv]->text, "both"))
4459 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
4460 else {
4461 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
4462 return CMD_WARNING_CONFIG_FAILED;
4463 }
4464
4465 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4466 bgp_node_safi(vty), flag);
4467 }
4468
4469 ALIAS_HIDDEN(
4470 neighbor_capability_orf_prefix,
4471 neighbor_capability_orf_prefix_hidden_cmd,
4472 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
4473 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4474 "Advertise capability to the peer\n"
4475 "Advertise ORF capability to the peer\n"
4476 "Advertise prefixlist ORF capability to this neighbor\n"
4477 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
4478 "Capability to RECEIVE the ORF from this neighbor\n"
4479 "Capability to SEND the ORF to this neighbor\n")
4480
4481 DEFUN (no_neighbor_capability_orf_prefix,
4482 no_neighbor_capability_orf_prefix_cmd,
4483 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
4484 NO_STR
4485 NEIGHBOR_STR
4486 NEIGHBOR_ADDR_STR2
4487 "Advertise capability to the peer\n"
4488 "Advertise ORF capability to the peer\n"
4489 "Advertise prefixlist ORF capability to this neighbor\n"
4490 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
4491 "Capability to RECEIVE the ORF from this neighbor\n"
4492 "Capability to SEND the ORF to this neighbor\n")
4493 {
4494 int idx_peer = 2;
4495 int idx_send_recv = 6;
4496 uint16_t flag = 0;
4497
4498 if (strmatch(argv[idx_send_recv]->text, "send"))
4499 flag = PEER_FLAG_ORF_PREFIX_SM;
4500 else if (strmatch(argv[idx_send_recv]->text, "receive"))
4501 flag = PEER_FLAG_ORF_PREFIX_RM;
4502 else if (strmatch(argv[idx_send_recv]->text, "both"))
4503 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
4504 else {
4505 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
4506 return CMD_WARNING_CONFIG_FAILED;
4507 }
4508
4509 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4510 bgp_node_afi(vty), bgp_node_safi(vty),
4511 flag);
4512 }
4513
4514 ALIAS_HIDDEN(
4515 no_neighbor_capability_orf_prefix,
4516 no_neighbor_capability_orf_prefix_hidden_cmd,
4517 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
4518 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4519 "Advertise capability to the peer\n"
4520 "Advertise ORF capability to the peer\n"
4521 "Advertise prefixlist ORF capability to this neighbor\n"
4522 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
4523 "Capability to RECEIVE the ORF from this neighbor\n"
4524 "Capability to SEND the ORF to this neighbor\n")
4525
4526 /* neighbor next-hop-self. */
4527 DEFUN (neighbor_nexthop_self,
4528 neighbor_nexthop_self_cmd,
4529 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
4530 NEIGHBOR_STR
4531 NEIGHBOR_ADDR_STR2
4532 "Disable the next hop calculation for this neighbor\n")
4533 {
4534 int idx_peer = 1;
4535 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4536 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
4537 }
4538
4539 ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
4540 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
4541 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4542 "Disable the next hop calculation for this neighbor\n")
4543
4544 /* neighbor next-hop-self. */
4545 DEFUN (neighbor_nexthop_self_force,
4546 neighbor_nexthop_self_force_cmd,
4547 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
4548 NEIGHBOR_STR
4549 NEIGHBOR_ADDR_STR2
4550 "Disable the next hop calculation for this neighbor\n"
4551 "Set the next hop to self for reflected routes\n")
4552 {
4553 int idx_peer = 1;
4554 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4555 bgp_node_safi(vty),
4556 PEER_FLAG_FORCE_NEXTHOP_SELF);
4557 }
4558
4559 ALIAS_HIDDEN(neighbor_nexthop_self_force,
4560 neighbor_nexthop_self_force_hidden_cmd,
4561 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
4562 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4563 "Disable the next hop calculation for this neighbor\n"
4564 "Set the next hop to self for reflected routes\n")
4565
4566 ALIAS_HIDDEN(neighbor_nexthop_self_force,
4567 neighbor_nexthop_self_all_hidden_cmd,
4568 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
4569 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4570 "Disable the next hop calculation for this neighbor\n"
4571 "Set the next hop to self for reflected routes\n")
4572
4573 DEFUN (no_neighbor_nexthop_self,
4574 no_neighbor_nexthop_self_cmd,
4575 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
4576 NO_STR
4577 NEIGHBOR_STR
4578 NEIGHBOR_ADDR_STR2
4579 "Disable the next hop calculation for this neighbor\n")
4580 {
4581 int idx_peer = 2;
4582 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4583 bgp_node_afi(vty), bgp_node_safi(vty),
4584 PEER_FLAG_NEXTHOP_SELF);
4585 }
4586
4587 ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
4588 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
4589 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4590 "Disable the next hop calculation for this neighbor\n")
4591
4592 DEFUN (no_neighbor_nexthop_self_force,
4593 no_neighbor_nexthop_self_force_cmd,
4594 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
4595 NO_STR
4596 NEIGHBOR_STR
4597 NEIGHBOR_ADDR_STR2
4598 "Disable the next hop calculation for this neighbor\n"
4599 "Set the next hop to self for reflected routes\n")
4600 {
4601 int idx_peer = 2;
4602 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4603 bgp_node_afi(vty), bgp_node_safi(vty),
4604 PEER_FLAG_FORCE_NEXTHOP_SELF);
4605 }
4606
4607 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
4608 no_neighbor_nexthop_self_force_hidden_cmd,
4609 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
4610 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4611 "Disable the next hop calculation for this neighbor\n"
4612 "Set the next hop to self for reflected routes\n")
4613
4614 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
4615 no_neighbor_nexthop_self_all_hidden_cmd,
4616 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
4617 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4618 "Disable the next hop calculation for this neighbor\n"
4619 "Set the next hop to self for reflected routes\n")
4620
4621 /* neighbor as-override */
4622 DEFUN (neighbor_as_override,
4623 neighbor_as_override_cmd,
4624 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4625 NEIGHBOR_STR
4626 NEIGHBOR_ADDR_STR2
4627 "Override ASNs in outbound updates if aspath equals remote-as\n")
4628 {
4629 int idx_peer = 1;
4630 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4631 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
4632 }
4633
4634 ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
4635 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4636 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4637 "Override ASNs in outbound updates if aspath equals remote-as\n")
4638
4639 DEFUN (no_neighbor_as_override,
4640 no_neighbor_as_override_cmd,
4641 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4642 NO_STR
4643 NEIGHBOR_STR
4644 NEIGHBOR_ADDR_STR2
4645 "Override ASNs in outbound updates if aspath equals remote-as\n")
4646 {
4647 int idx_peer = 2;
4648 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4649 bgp_node_afi(vty), bgp_node_safi(vty),
4650 PEER_FLAG_AS_OVERRIDE);
4651 }
4652
4653 ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
4654 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4655 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4656 "Override ASNs in outbound updates if aspath equals remote-as\n")
4657
4658 /* neighbor remove-private-AS. */
4659 DEFUN (neighbor_remove_private_as,
4660 neighbor_remove_private_as_cmd,
4661 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4662 NEIGHBOR_STR
4663 NEIGHBOR_ADDR_STR2
4664 "Remove private ASNs in outbound updates\n")
4665 {
4666 int idx_peer = 1;
4667 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4668 bgp_node_safi(vty),
4669 PEER_FLAG_REMOVE_PRIVATE_AS);
4670 }
4671
4672 ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
4673 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4674 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4675 "Remove private ASNs in outbound updates\n")
4676
4677 DEFUN (neighbor_remove_private_as_all,
4678 neighbor_remove_private_as_all_cmd,
4679 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4680 NEIGHBOR_STR
4681 NEIGHBOR_ADDR_STR2
4682 "Remove private ASNs in outbound updates\n"
4683 "Apply to all AS numbers\n")
4684 {
4685 int idx_peer = 1;
4686 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4687 bgp_node_safi(vty),
4688 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
4689 }
4690
4691 ALIAS_HIDDEN(neighbor_remove_private_as_all,
4692 neighbor_remove_private_as_all_hidden_cmd,
4693 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4694 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4695 "Remove private ASNs in outbound updates\n"
4696 "Apply to all AS numbers")
4697
4698 DEFUN (neighbor_remove_private_as_replace_as,
4699 neighbor_remove_private_as_replace_as_cmd,
4700 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4701 NEIGHBOR_STR
4702 NEIGHBOR_ADDR_STR2
4703 "Remove private ASNs in outbound updates\n"
4704 "Replace private ASNs with our ASN in outbound updates\n")
4705 {
4706 int idx_peer = 1;
4707 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4708 bgp_node_safi(vty),
4709 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
4710 }
4711
4712 ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
4713 neighbor_remove_private_as_replace_as_hidden_cmd,
4714 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4715 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4716 "Remove private ASNs in outbound updates\n"
4717 "Replace private ASNs with our ASN in outbound updates\n")
4718
4719 DEFUN (neighbor_remove_private_as_all_replace_as,
4720 neighbor_remove_private_as_all_replace_as_cmd,
4721 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4722 NEIGHBOR_STR
4723 NEIGHBOR_ADDR_STR2
4724 "Remove private ASNs in outbound updates\n"
4725 "Apply to all AS numbers\n"
4726 "Replace private ASNs with our ASN in outbound updates\n")
4727 {
4728 int idx_peer = 1;
4729 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4730 bgp_node_safi(vty),
4731 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
4732 }
4733
4734 ALIAS_HIDDEN(
4735 neighbor_remove_private_as_all_replace_as,
4736 neighbor_remove_private_as_all_replace_as_hidden_cmd,
4737 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4738 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4739 "Remove private ASNs in outbound updates\n"
4740 "Apply to all AS numbers\n"
4741 "Replace private ASNs with our ASN in outbound updates\n")
4742
4743 DEFUN (no_neighbor_remove_private_as,
4744 no_neighbor_remove_private_as_cmd,
4745 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4746 NO_STR
4747 NEIGHBOR_STR
4748 NEIGHBOR_ADDR_STR2
4749 "Remove private ASNs in outbound updates\n")
4750 {
4751 int idx_peer = 2;
4752 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4753 bgp_node_afi(vty), bgp_node_safi(vty),
4754 PEER_FLAG_REMOVE_PRIVATE_AS);
4755 }
4756
4757 ALIAS_HIDDEN(no_neighbor_remove_private_as,
4758 no_neighbor_remove_private_as_hidden_cmd,
4759 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4760 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4761 "Remove private ASNs in outbound updates\n")
4762
4763 DEFUN (no_neighbor_remove_private_as_all,
4764 no_neighbor_remove_private_as_all_cmd,
4765 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4766 NO_STR
4767 NEIGHBOR_STR
4768 NEIGHBOR_ADDR_STR2
4769 "Remove private ASNs in outbound updates\n"
4770 "Apply to all AS numbers\n")
4771 {
4772 int idx_peer = 2;
4773 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4774 bgp_node_afi(vty), bgp_node_safi(vty),
4775 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
4776 }
4777
4778 ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
4779 no_neighbor_remove_private_as_all_hidden_cmd,
4780 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4781 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4782 "Remove private ASNs in outbound updates\n"
4783 "Apply to all AS numbers\n")
4784
4785 DEFUN (no_neighbor_remove_private_as_replace_as,
4786 no_neighbor_remove_private_as_replace_as_cmd,
4787 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4788 NO_STR
4789 NEIGHBOR_STR
4790 NEIGHBOR_ADDR_STR2
4791 "Remove private ASNs in outbound updates\n"
4792 "Replace private ASNs with our ASN in outbound updates\n")
4793 {
4794 int idx_peer = 2;
4795 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4796 bgp_node_afi(vty), bgp_node_safi(vty),
4797 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
4798 }
4799
4800 ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
4801 no_neighbor_remove_private_as_replace_as_hidden_cmd,
4802 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4803 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4804 "Remove private ASNs in outbound updates\n"
4805 "Replace private ASNs with our ASN in outbound updates\n")
4806
4807 DEFUN (no_neighbor_remove_private_as_all_replace_as,
4808 no_neighbor_remove_private_as_all_replace_as_cmd,
4809 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4810 NO_STR
4811 NEIGHBOR_STR
4812 NEIGHBOR_ADDR_STR2
4813 "Remove private ASNs in outbound updates\n"
4814 "Apply to all AS numbers\n"
4815 "Replace private ASNs with our ASN in outbound updates\n")
4816 {
4817 int idx_peer = 2;
4818 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4819 bgp_node_afi(vty), bgp_node_safi(vty),
4820 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
4821 }
4822
4823 ALIAS_HIDDEN(
4824 no_neighbor_remove_private_as_all_replace_as,
4825 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
4826 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4827 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4828 "Remove private ASNs in outbound updates\n"
4829 "Apply to all AS numbers\n"
4830 "Replace private ASNs with our ASN in outbound updates\n")
4831
4832
4833 /* neighbor send-community. */
4834 DEFUN (neighbor_send_community,
4835 neighbor_send_community_cmd,
4836 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4837 NEIGHBOR_STR
4838 NEIGHBOR_ADDR_STR2
4839 "Send Community attribute to this neighbor\n")
4840 {
4841 int idx_peer = 1;
4842
4843 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4844 bgp_node_safi(vty),
4845 PEER_FLAG_SEND_COMMUNITY);
4846 }
4847
4848 ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
4849 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4850 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4851 "Send Community attribute to this neighbor\n")
4852
4853 DEFUN (no_neighbor_send_community,
4854 no_neighbor_send_community_cmd,
4855 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4856 NO_STR
4857 NEIGHBOR_STR
4858 NEIGHBOR_ADDR_STR2
4859 "Send Community attribute to this neighbor\n")
4860 {
4861 int idx_peer = 2;
4862
4863 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4864 bgp_node_afi(vty), bgp_node_safi(vty),
4865 PEER_FLAG_SEND_COMMUNITY);
4866 }
4867
4868 ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
4869 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4870 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4871 "Send Community attribute to this neighbor\n")
4872
4873 /* neighbor send-community extended. */
4874 DEFUN (neighbor_send_community_type,
4875 neighbor_send_community_type_cmd,
4876 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4877 NEIGHBOR_STR
4878 NEIGHBOR_ADDR_STR2
4879 "Send Community attribute to this neighbor\n"
4880 "Send Standard and Extended Community attributes\n"
4881 "Send Standard, Large and Extended Community attributes\n"
4882 "Send Extended Community attributes\n"
4883 "Send Standard Community attributes\n"
4884 "Send Large Community attributes\n")
4885 {
4886 int idx_peer = 1;
4887 uint32_t flag = 0;
4888 const char *type = argv[argc - 1]->text;
4889
4890 if (strmatch(type, "standard")) {
4891 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4892 } else if (strmatch(type, "extended")) {
4893 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4894 } else if (strmatch(type, "large")) {
4895 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4896 } else if (strmatch(type, "both")) {
4897 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4898 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4899 } else { /* if (strmatch(type, "all")) */
4900 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4901 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4902 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4903 }
4904
4905 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4906 bgp_node_safi(vty), flag);
4907 }
4908
4909 ALIAS_HIDDEN(
4910 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
4911 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4912 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4913 "Send Community attribute to this neighbor\n"
4914 "Send Standard and Extended Community attributes\n"
4915 "Send Standard, Large and Extended Community attributes\n"
4916 "Send Extended Community attributes\n"
4917 "Send Standard Community attributes\n"
4918 "Send Large Community attributes\n")
4919
4920 DEFUN (no_neighbor_send_community_type,
4921 no_neighbor_send_community_type_cmd,
4922 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4923 NO_STR
4924 NEIGHBOR_STR
4925 NEIGHBOR_ADDR_STR2
4926 "Send Community attribute to this neighbor\n"
4927 "Send Standard and Extended Community attributes\n"
4928 "Send Standard, Large and Extended Community attributes\n"
4929 "Send Extended Community attributes\n"
4930 "Send Standard Community attributes\n"
4931 "Send Large Community attributes\n")
4932 {
4933 int idx_peer = 2;
4934 uint32_t flag = 0;
4935 const char *type = argv[argc - 1]->text;
4936
4937 if (strmatch(type, "standard")) {
4938 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4939 } else if (strmatch(type, "extended")) {
4940 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4941 } else if (strmatch(type, "large")) {
4942 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4943 } else if (strmatch(type, "both")) {
4944 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4945 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4946 } else { /* if (strmatch(type, "all")) */
4947 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4948 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4949 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4950 }
4951
4952 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4953 bgp_node_afi(vty), bgp_node_safi(vty),
4954 flag);
4955 }
4956
4957 ALIAS_HIDDEN(
4958 no_neighbor_send_community_type,
4959 no_neighbor_send_community_type_hidden_cmd,
4960 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4961 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4962 "Send Community attribute to this neighbor\n"
4963 "Send Standard and Extended Community attributes\n"
4964 "Send Standard, Large and Extended Community attributes\n"
4965 "Send Extended Community attributes\n"
4966 "Send Standard Community attributes\n"
4967 "Send Large Community attributes\n")
4968
4969 /* neighbor soft-reconfig. */
4970 DEFUN (neighbor_soft_reconfiguration,
4971 neighbor_soft_reconfiguration_cmd,
4972 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4973 NEIGHBOR_STR
4974 NEIGHBOR_ADDR_STR2
4975 "Per neighbor soft reconfiguration\n"
4976 "Allow inbound soft reconfiguration for this neighbor\n")
4977 {
4978 int idx_peer = 1;
4979 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4980 bgp_node_safi(vty),
4981 PEER_FLAG_SOFT_RECONFIG);
4982 }
4983
4984 ALIAS_HIDDEN(neighbor_soft_reconfiguration,
4985 neighbor_soft_reconfiguration_hidden_cmd,
4986 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4987 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4988 "Per neighbor soft reconfiguration\n"
4989 "Allow inbound soft reconfiguration for this neighbor\n")
4990
4991 DEFUN (no_neighbor_soft_reconfiguration,
4992 no_neighbor_soft_reconfiguration_cmd,
4993 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4994 NO_STR
4995 NEIGHBOR_STR
4996 NEIGHBOR_ADDR_STR2
4997 "Per neighbor soft reconfiguration\n"
4998 "Allow inbound soft reconfiguration for this neighbor\n")
4999 {
5000 int idx_peer = 2;
5001 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5002 bgp_node_afi(vty), bgp_node_safi(vty),
5003 PEER_FLAG_SOFT_RECONFIG);
5004 }
5005
5006 ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
5007 no_neighbor_soft_reconfiguration_hidden_cmd,
5008 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
5009 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5010 "Per neighbor soft reconfiguration\n"
5011 "Allow inbound soft reconfiguration for this neighbor\n")
5012
5013 DEFUN (neighbor_route_reflector_client,
5014 neighbor_route_reflector_client_cmd,
5015 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
5016 NEIGHBOR_STR
5017 NEIGHBOR_ADDR_STR2
5018 "Configure a neighbor as Route Reflector client\n")
5019 {
5020 int idx_peer = 1;
5021 struct peer *peer;
5022
5023
5024 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5025 if (!peer)
5026 return CMD_WARNING_CONFIG_FAILED;
5027
5028 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5029 bgp_node_safi(vty),
5030 PEER_FLAG_REFLECTOR_CLIENT);
5031 }
5032
5033 ALIAS_HIDDEN(neighbor_route_reflector_client,
5034 neighbor_route_reflector_client_hidden_cmd,
5035 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
5036 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5037 "Configure a neighbor as Route Reflector client\n")
5038
5039 DEFUN (no_neighbor_route_reflector_client,
5040 no_neighbor_route_reflector_client_cmd,
5041 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
5042 NO_STR
5043 NEIGHBOR_STR
5044 NEIGHBOR_ADDR_STR2
5045 "Configure a neighbor as Route Reflector client\n")
5046 {
5047 int idx_peer = 2;
5048 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5049 bgp_node_afi(vty), bgp_node_safi(vty),
5050 PEER_FLAG_REFLECTOR_CLIENT);
5051 }
5052
5053 ALIAS_HIDDEN(no_neighbor_route_reflector_client,
5054 no_neighbor_route_reflector_client_hidden_cmd,
5055 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
5056 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5057 "Configure a neighbor as Route Reflector client\n")
5058
5059 /* neighbor route-server-client. */
5060 DEFUN (neighbor_route_server_client,
5061 neighbor_route_server_client_cmd,
5062 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
5063 NEIGHBOR_STR
5064 NEIGHBOR_ADDR_STR2
5065 "Configure a neighbor as Route Server client\n")
5066 {
5067 int idx_peer = 1;
5068 struct peer *peer;
5069
5070 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5071 if (!peer)
5072 return CMD_WARNING_CONFIG_FAILED;
5073 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5074 bgp_node_safi(vty),
5075 PEER_FLAG_RSERVER_CLIENT);
5076 }
5077
5078 ALIAS_HIDDEN(neighbor_route_server_client,
5079 neighbor_route_server_client_hidden_cmd,
5080 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
5081 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5082 "Configure a neighbor as Route Server client\n")
5083
5084 DEFUN (no_neighbor_route_server_client,
5085 no_neighbor_route_server_client_cmd,
5086 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
5087 NO_STR
5088 NEIGHBOR_STR
5089 NEIGHBOR_ADDR_STR2
5090 "Configure a neighbor as Route Server client\n")
5091 {
5092 int idx_peer = 2;
5093 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5094 bgp_node_afi(vty), bgp_node_safi(vty),
5095 PEER_FLAG_RSERVER_CLIENT);
5096 }
5097
5098 ALIAS_HIDDEN(no_neighbor_route_server_client,
5099 no_neighbor_route_server_client_hidden_cmd,
5100 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
5101 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5102 "Configure a neighbor as Route Server client\n")
5103
5104 DEFUN (neighbor_nexthop_local_unchanged,
5105 neighbor_nexthop_local_unchanged_cmd,
5106 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
5107 NEIGHBOR_STR
5108 NEIGHBOR_ADDR_STR2
5109 "Configure treatment of outgoing link-local nexthop attribute\n"
5110 "Leave link-local nexthop unchanged for this peer\n")
5111 {
5112 int idx_peer = 1;
5113 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5114 bgp_node_safi(vty),
5115 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
5116 }
5117
5118 DEFUN (no_neighbor_nexthop_local_unchanged,
5119 no_neighbor_nexthop_local_unchanged_cmd,
5120 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
5121 NO_STR
5122 NEIGHBOR_STR
5123 NEIGHBOR_ADDR_STR2
5124 "Configure treatment of outgoing link-local-nexthop attribute\n"
5125 "Leave link-local nexthop unchanged for this peer\n")
5126 {
5127 int idx_peer = 2;
5128 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5129 bgp_node_afi(vty), bgp_node_safi(vty),
5130 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
5131 }
5132
5133 DEFUN (neighbor_attr_unchanged,
5134 neighbor_attr_unchanged_cmd,
5135 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
5136 NEIGHBOR_STR
5137 NEIGHBOR_ADDR_STR2
5138 "BGP attribute is propagated unchanged to this neighbor\n"
5139 "As-path attribute\n"
5140 "Nexthop attribute\n"
5141 "Med attribute\n")
5142 {
5143 int idx = 0;
5144 char *peer_str = argv[1]->arg;
5145 struct peer *peer;
5146 uint16_t flags = 0;
5147 afi_t afi = bgp_node_afi(vty);
5148 safi_t safi = bgp_node_safi(vty);
5149
5150 peer = peer_and_group_lookup_vty(vty, peer_str);
5151 if (!peer)
5152 return CMD_WARNING_CONFIG_FAILED;
5153
5154 if (argv_find(argv, argc, "as-path", &idx))
5155 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
5156 idx = 0;
5157 if (argv_find(argv, argc, "next-hop", &idx))
5158 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
5159 idx = 0;
5160 if (argv_find(argv, argc, "med", &idx))
5161 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
5162
5163 /* no flags means all of them! */
5164 if (!flags) {
5165 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
5166 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
5167 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
5168 } else {
5169 if (!CHECK_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED)
5170 && peer_af_flag_check(peer, afi, safi,
5171 PEER_FLAG_AS_PATH_UNCHANGED)) {
5172 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5173 PEER_FLAG_AS_PATH_UNCHANGED);
5174 }
5175
5176 if (!CHECK_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED)
5177 && peer_af_flag_check(peer, afi, safi,
5178 PEER_FLAG_NEXTHOP_UNCHANGED)) {
5179 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5180 PEER_FLAG_NEXTHOP_UNCHANGED);
5181 }
5182
5183 if (!CHECK_FLAG(flags, PEER_FLAG_MED_UNCHANGED)
5184 && peer_af_flag_check(peer, afi, safi,
5185 PEER_FLAG_MED_UNCHANGED)) {
5186 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5187 PEER_FLAG_MED_UNCHANGED);
5188 }
5189 }
5190
5191 return peer_af_flag_set_vty(vty, peer_str, afi, safi, flags);
5192 }
5193
5194 ALIAS_HIDDEN(
5195 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
5196 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
5197 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5198 "BGP attribute is propagated unchanged to this neighbor\n"
5199 "As-path attribute\n"
5200 "Nexthop attribute\n"
5201 "Med attribute\n")
5202
5203 DEFUN (no_neighbor_attr_unchanged,
5204 no_neighbor_attr_unchanged_cmd,
5205 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
5206 NO_STR
5207 NEIGHBOR_STR
5208 NEIGHBOR_ADDR_STR2
5209 "BGP attribute is propagated unchanged to this neighbor\n"
5210 "As-path attribute\n"
5211 "Nexthop attribute\n"
5212 "Med attribute\n")
5213 {
5214 int idx = 0;
5215 char *peer = argv[2]->arg;
5216 uint16_t flags = 0;
5217
5218 if (argv_find(argv, argc, "as-path", &idx))
5219 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
5220 idx = 0;
5221 if (argv_find(argv, argc, "next-hop", &idx))
5222 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
5223 idx = 0;
5224 if (argv_find(argv, argc, "med", &idx))
5225 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
5226
5227 if (!flags) // no flags means all of them!
5228 {
5229 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
5230 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
5231 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
5232 }
5233
5234 return peer_af_flag_unset_vty(vty, peer, bgp_node_afi(vty),
5235 bgp_node_safi(vty), flags);
5236 }
5237
5238 ALIAS_HIDDEN(
5239 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
5240 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
5241 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5242 "BGP attribute is propagated unchanged to this neighbor\n"
5243 "As-path attribute\n"
5244 "Nexthop attribute\n"
5245 "Med attribute\n")
5246
5247 /* EBGP multihop configuration. */
5248 static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
5249 const char *ttl_str)
5250 {
5251 struct peer *peer;
5252 unsigned int ttl;
5253
5254 peer = peer_and_group_lookup_vty(vty, ip_str);
5255 if (!peer)
5256 return CMD_WARNING_CONFIG_FAILED;
5257
5258 if (peer->conf_if)
5259 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
5260
5261 if (!ttl_str)
5262 ttl = MAXTTL;
5263 else
5264 ttl = strtoul(ttl_str, NULL, 10);
5265
5266 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
5267 }
5268
5269 static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
5270 {
5271 struct peer *peer;
5272
5273 peer = peer_and_group_lookup_vty(vty, ip_str);
5274 if (!peer)
5275 return CMD_WARNING_CONFIG_FAILED;
5276
5277 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
5278 }
5279
5280 /* neighbor ebgp-multihop. */
5281 DEFUN (neighbor_ebgp_multihop,
5282 neighbor_ebgp_multihop_cmd,
5283 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
5284 NEIGHBOR_STR
5285 NEIGHBOR_ADDR_STR2
5286 "Allow EBGP neighbors not on directly connected networks\n")
5287 {
5288 int idx_peer = 1;
5289 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
5290 }
5291
5292 DEFUN (neighbor_ebgp_multihop_ttl,
5293 neighbor_ebgp_multihop_ttl_cmd,
5294 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
5295 NEIGHBOR_STR
5296 NEIGHBOR_ADDR_STR2
5297 "Allow EBGP neighbors not on directly connected networks\n"
5298 "maximum hop count\n")
5299 {
5300 int idx_peer = 1;
5301 int idx_number = 3;
5302 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
5303 argv[idx_number]->arg);
5304 }
5305
5306 DEFUN (no_neighbor_ebgp_multihop,
5307 no_neighbor_ebgp_multihop_cmd,
5308 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
5309 NO_STR
5310 NEIGHBOR_STR
5311 NEIGHBOR_ADDR_STR2
5312 "Allow EBGP neighbors not on directly connected networks\n"
5313 "maximum hop count\n")
5314 {
5315 int idx_peer = 2;
5316 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
5317 }
5318
5319
5320 /* disable-connected-check */
5321 DEFUN (neighbor_disable_connected_check,
5322 neighbor_disable_connected_check_cmd,
5323 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
5324 NEIGHBOR_STR
5325 NEIGHBOR_ADDR_STR2
5326 "one-hop away EBGP peer using loopback address\n"
5327 "Enforce EBGP neighbors perform multihop\n")
5328 {
5329 int idx_peer = 1;
5330 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5331 PEER_FLAG_DISABLE_CONNECTED_CHECK);
5332 }
5333
5334 DEFUN (no_neighbor_disable_connected_check,
5335 no_neighbor_disable_connected_check_cmd,
5336 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
5337 NO_STR
5338 NEIGHBOR_STR
5339 NEIGHBOR_ADDR_STR2
5340 "one-hop away EBGP peer using loopback address\n"
5341 "Enforce EBGP neighbors perform multihop\n")
5342 {
5343 int idx_peer = 2;
5344 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5345 PEER_FLAG_DISABLE_CONNECTED_CHECK);
5346 }
5347
5348
5349 /* enforce-first-as */
5350 DEFUN (neighbor_enforce_first_as,
5351 neighbor_enforce_first_as_cmd,
5352 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
5353 NEIGHBOR_STR
5354 NEIGHBOR_ADDR_STR2
5355 "Enforce the first AS for EBGP routes\n")
5356 {
5357 int idx_peer = 1;
5358
5359 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5360 PEER_FLAG_ENFORCE_FIRST_AS);
5361 }
5362
5363 DEFUN (no_neighbor_enforce_first_as,
5364 no_neighbor_enforce_first_as_cmd,
5365 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
5366 NO_STR
5367 NEIGHBOR_STR
5368 NEIGHBOR_ADDR_STR2
5369 "Enforce the first AS for EBGP routes\n")
5370 {
5371 int idx_peer = 2;
5372
5373 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5374 PEER_FLAG_ENFORCE_FIRST_AS);
5375 }
5376
5377
5378 DEFUN (neighbor_description,
5379 neighbor_description_cmd,
5380 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
5381 NEIGHBOR_STR
5382 NEIGHBOR_ADDR_STR2
5383 "Neighbor specific description\n"
5384 "Up to 80 characters describing this neighbor\n")
5385 {
5386 int idx_peer = 1;
5387 int idx_line = 3;
5388 struct peer *peer;
5389 char *str;
5390
5391 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5392 if (!peer)
5393 return CMD_WARNING_CONFIG_FAILED;
5394
5395 str = argv_concat(argv, argc, idx_line);
5396
5397 peer_description_set(peer, str);
5398
5399 XFREE(MTYPE_TMP, str);
5400
5401 return CMD_SUCCESS;
5402 }
5403
5404 DEFUN (no_neighbor_description,
5405 no_neighbor_description_cmd,
5406 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
5407 NO_STR
5408 NEIGHBOR_STR
5409 NEIGHBOR_ADDR_STR2
5410 "Neighbor specific description\n")
5411 {
5412 int idx_peer = 2;
5413 struct peer *peer;
5414
5415 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5416 if (!peer)
5417 return CMD_WARNING_CONFIG_FAILED;
5418
5419 peer_description_unset(peer);
5420
5421 return CMD_SUCCESS;
5422 }
5423
5424 ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
5425 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
5426 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5427 "Neighbor specific description\n"
5428 "Up to 80 characters describing this neighbor\n")
5429
5430 /* Neighbor update-source. */
5431 static int peer_update_source_vty(struct vty *vty, const char *peer_str,
5432 const char *source_str)
5433 {
5434 struct peer *peer;
5435 struct prefix p;
5436 union sockunion su;
5437
5438 peer = peer_and_group_lookup_vty(vty, peer_str);
5439 if (!peer)
5440 return CMD_WARNING_CONFIG_FAILED;
5441
5442 if (peer->conf_if)
5443 return CMD_WARNING;
5444
5445 if (source_str) {
5446 if (str2sockunion(source_str, &su) == 0)
5447 peer_update_source_addr_set(peer, &su);
5448 else {
5449 if (str2prefix(source_str, &p)) {
5450 vty_out(vty,
5451 "%% Invalid update-source, remove prefix length \n");
5452 return CMD_WARNING_CONFIG_FAILED;
5453 } else
5454 peer_update_source_if_set(peer, source_str);
5455 }
5456 } else
5457 peer_update_source_unset(peer);
5458
5459 return CMD_SUCCESS;
5460 }
5461
5462 #define BGP_UPDATE_SOURCE_HELP_STR \
5463 "IPv4 address\n" \
5464 "IPv6 address\n" \
5465 "Interface name (requires zebra to be running)\n"
5466
5467 DEFUN (neighbor_update_source,
5468 neighbor_update_source_cmd,
5469 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
5470 NEIGHBOR_STR
5471 NEIGHBOR_ADDR_STR2
5472 "Source of routing updates\n"
5473 BGP_UPDATE_SOURCE_HELP_STR)
5474 {
5475 int idx_peer = 1;
5476 int idx_peer_2 = 3;
5477 return peer_update_source_vty(vty, argv[idx_peer]->arg,
5478 argv[idx_peer_2]->arg);
5479 }
5480
5481 DEFUN (no_neighbor_update_source,
5482 no_neighbor_update_source_cmd,
5483 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
5484 NO_STR
5485 NEIGHBOR_STR
5486 NEIGHBOR_ADDR_STR2
5487 "Source of routing updates\n"
5488 BGP_UPDATE_SOURCE_HELP_STR)
5489 {
5490 int idx_peer = 2;
5491 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
5492 }
5493
5494 static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
5495 afi_t afi, safi_t safi,
5496 const char *rmap, int set)
5497 {
5498 int ret;
5499 struct peer *peer;
5500 struct route_map *route_map = NULL;
5501
5502 peer = peer_and_group_lookup_vty(vty, peer_str);
5503 if (!peer)
5504 return CMD_WARNING_CONFIG_FAILED;
5505
5506 if (set) {
5507 if (rmap)
5508 route_map = route_map_lookup_warn_noexist(vty, rmap);
5509 ret = peer_default_originate_set(peer, afi, safi,
5510 rmap, route_map);
5511 } else
5512 ret = peer_default_originate_unset(peer, afi, safi);
5513
5514 return bgp_vty_return(vty, ret);
5515 }
5516
5517 /* neighbor default-originate. */
5518 DEFUN (neighbor_default_originate,
5519 neighbor_default_originate_cmd,
5520 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
5521 NEIGHBOR_STR
5522 NEIGHBOR_ADDR_STR2
5523 "Originate default route to this neighbor\n")
5524 {
5525 int idx_peer = 1;
5526 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
5527 bgp_node_afi(vty),
5528 bgp_node_safi(vty), NULL, 1);
5529 }
5530
5531 ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
5532 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
5533 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5534 "Originate default route to this neighbor\n")
5535
5536 DEFUN (neighbor_default_originate_rmap,
5537 neighbor_default_originate_rmap_cmd,
5538 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
5539 NEIGHBOR_STR
5540 NEIGHBOR_ADDR_STR2
5541 "Originate default route to this neighbor\n"
5542 "Route-map to specify criteria to originate default\n"
5543 "route-map name\n")
5544 {
5545 int idx_peer = 1;
5546 int idx_word = 4;
5547 return peer_default_originate_set_vty(
5548 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5549 argv[idx_word]->arg, 1);
5550 }
5551
5552 ALIAS_HIDDEN(
5553 neighbor_default_originate_rmap,
5554 neighbor_default_originate_rmap_hidden_cmd,
5555 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
5556 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5557 "Originate default route to this neighbor\n"
5558 "Route-map to specify criteria to originate default\n"
5559 "route-map name\n")
5560
5561 DEFUN (no_neighbor_default_originate,
5562 no_neighbor_default_originate_cmd,
5563 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
5564 NO_STR
5565 NEIGHBOR_STR
5566 NEIGHBOR_ADDR_STR2
5567 "Originate default route to this neighbor\n"
5568 "Route-map to specify criteria to originate default\n"
5569 "route-map name\n")
5570 {
5571 int idx_peer = 2;
5572 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
5573 bgp_node_afi(vty),
5574 bgp_node_safi(vty), NULL, 0);
5575 }
5576
5577 ALIAS_HIDDEN(
5578 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
5579 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
5580 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5581 "Originate default route to this neighbor\n"
5582 "Route-map to specify criteria to originate default\n"
5583 "route-map name\n")
5584
5585
5586 /* Set neighbor's BGP port. */
5587 static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
5588 const char *port_str)
5589 {
5590 struct peer *peer;
5591 uint16_t port;
5592 struct servent *sp;
5593
5594 peer = peer_lookup_vty(vty, ip_str);
5595 if (!peer)
5596 return CMD_WARNING_CONFIG_FAILED;
5597
5598 if (!port_str) {
5599 sp = getservbyname("bgp", "tcp");
5600 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
5601 } else {
5602 port = strtoul(port_str, NULL, 10);
5603 }
5604
5605 peer_port_set(peer, port);
5606
5607 return CMD_SUCCESS;
5608 }
5609
5610 /* Set specified peer's BGP port. */
5611 DEFUN (neighbor_port,
5612 neighbor_port_cmd,
5613 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
5614 NEIGHBOR_STR
5615 NEIGHBOR_ADDR_STR
5616 "Neighbor's BGP port\n"
5617 "TCP port number\n")
5618 {
5619 int idx_ip = 1;
5620 int idx_number = 3;
5621 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
5622 argv[idx_number]->arg);
5623 }
5624
5625 DEFUN (no_neighbor_port,
5626 no_neighbor_port_cmd,
5627 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
5628 NO_STR
5629 NEIGHBOR_STR
5630 NEIGHBOR_ADDR_STR
5631 "Neighbor's BGP port\n"
5632 "TCP port number\n")
5633 {
5634 int idx_ip = 2;
5635 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
5636 }
5637
5638
5639 /* neighbor weight. */
5640 static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5641 safi_t safi, const char *weight_str)
5642 {
5643 int ret;
5644 struct peer *peer;
5645 unsigned long weight;
5646
5647 peer = peer_and_group_lookup_vty(vty, ip_str);
5648 if (!peer)
5649 return CMD_WARNING_CONFIG_FAILED;
5650
5651 weight = strtoul(weight_str, NULL, 10);
5652
5653 ret = peer_weight_set(peer, afi, safi, weight);
5654 return bgp_vty_return(vty, ret);
5655 }
5656
5657 static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5658 safi_t safi)
5659 {
5660 int ret;
5661 struct peer *peer;
5662
5663 peer = peer_and_group_lookup_vty(vty, ip_str);
5664 if (!peer)
5665 return CMD_WARNING_CONFIG_FAILED;
5666
5667 ret = peer_weight_unset(peer, afi, safi);
5668 return bgp_vty_return(vty, ret);
5669 }
5670
5671 DEFUN (neighbor_weight,
5672 neighbor_weight_cmd,
5673 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
5674 NEIGHBOR_STR
5675 NEIGHBOR_ADDR_STR2
5676 "Set default weight for routes from this neighbor\n"
5677 "default weight\n")
5678 {
5679 int idx_peer = 1;
5680 int idx_number = 3;
5681 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5682 bgp_node_safi(vty), argv[idx_number]->arg);
5683 }
5684
5685 ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
5686 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
5687 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5688 "Set default weight for routes from this neighbor\n"
5689 "default weight\n")
5690
5691 DEFUN (no_neighbor_weight,
5692 no_neighbor_weight_cmd,
5693 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
5694 NO_STR
5695 NEIGHBOR_STR
5696 NEIGHBOR_ADDR_STR2
5697 "Set default weight for routes from this neighbor\n"
5698 "default weight\n")
5699 {
5700 int idx_peer = 2;
5701 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
5702 bgp_node_afi(vty), bgp_node_safi(vty));
5703 }
5704
5705 ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
5706 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
5707 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5708 "Set default weight for routes from this neighbor\n"
5709 "default weight\n")
5710
5711
5712 /* Override capability negotiation. */
5713 DEFUN (neighbor_override_capability,
5714 neighbor_override_capability_cmd,
5715 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
5716 NEIGHBOR_STR
5717 NEIGHBOR_ADDR_STR2
5718 "Override capability negotiation result\n")
5719 {
5720 int idx_peer = 1;
5721 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5722 PEER_FLAG_OVERRIDE_CAPABILITY);
5723 }
5724
5725 DEFUN (no_neighbor_override_capability,
5726 no_neighbor_override_capability_cmd,
5727 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
5728 NO_STR
5729 NEIGHBOR_STR
5730 NEIGHBOR_ADDR_STR2
5731 "Override capability negotiation result\n")
5732 {
5733 int idx_peer = 2;
5734 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5735 PEER_FLAG_OVERRIDE_CAPABILITY);
5736 }
5737
5738 DEFUN (neighbor_strict_capability,
5739 neighbor_strict_capability_cmd,
5740 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
5741 NEIGHBOR_STR
5742 NEIGHBOR_ADDR_STR2
5743 "Strict capability negotiation match\n")
5744 {
5745 int idx_peer = 1;
5746
5747 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5748 PEER_FLAG_STRICT_CAP_MATCH);
5749 }
5750
5751 DEFUN (no_neighbor_strict_capability,
5752 no_neighbor_strict_capability_cmd,
5753 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
5754 NO_STR
5755 NEIGHBOR_STR
5756 NEIGHBOR_ADDR_STR2
5757 "Strict capability negotiation match\n")
5758 {
5759 int idx_peer = 2;
5760
5761 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5762 PEER_FLAG_STRICT_CAP_MATCH);
5763 }
5764
5765 static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
5766 const char *keep_str, const char *hold_str)
5767 {
5768 int ret;
5769 struct peer *peer;
5770 uint32_t keepalive;
5771 uint32_t holdtime;
5772
5773 peer = peer_and_group_lookup_vty(vty, ip_str);
5774 if (!peer)
5775 return CMD_WARNING_CONFIG_FAILED;
5776
5777 keepalive = strtoul(keep_str, NULL, 10);
5778 holdtime = strtoul(hold_str, NULL, 10);
5779
5780 ret = peer_timers_set(peer, keepalive, holdtime);
5781
5782 return bgp_vty_return(vty, ret);
5783 }
5784
5785 static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
5786 {
5787 int ret;
5788 struct peer *peer;
5789
5790 peer = peer_and_group_lookup_vty(vty, ip_str);
5791 if (!peer)
5792 return CMD_WARNING_CONFIG_FAILED;
5793
5794 ret = peer_timers_unset(peer);
5795
5796 return bgp_vty_return(vty, ret);
5797 }
5798
5799 DEFUN (neighbor_timers,
5800 neighbor_timers_cmd,
5801 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
5802 NEIGHBOR_STR
5803 NEIGHBOR_ADDR_STR2
5804 "BGP per neighbor timers\n"
5805 "Keepalive interval\n"
5806 "Holdtime\n")
5807 {
5808 int idx_peer = 1;
5809 int idx_number = 3;
5810 int idx_number_2 = 4;
5811 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
5812 argv[idx_number]->arg,
5813 argv[idx_number_2]->arg);
5814 }
5815
5816 DEFUN (no_neighbor_timers,
5817 no_neighbor_timers_cmd,
5818 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
5819 NO_STR
5820 NEIGHBOR_STR
5821 NEIGHBOR_ADDR_STR2
5822 "BGP per neighbor timers\n"
5823 "Keepalive interval\n"
5824 "Holdtime\n")
5825 {
5826 int idx_peer = 2;
5827 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
5828 }
5829
5830
5831 static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
5832 const char *time_str)
5833 {
5834 int ret;
5835 struct peer *peer;
5836 uint32_t connect;
5837
5838 peer = peer_and_group_lookup_vty(vty, ip_str);
5839 if (!peer)
5840 return CMD_WARNING_CONFIG_FAILED;
5841
5842 connect = strtoul(time_str, NULL, 10);
5843
5844 ret = peer_timers_connect_set(peer, connect);
5845
5846 return bgp_vty_return(vty, ret);
5847 }
5848
5849 static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
5850 {
5851 int ret;
5852 struct peer *peer;
5853
5854 peer = peer_and_group_lookup_vty(vty, ip_str);
5855 if (!peer)
5856 return CMD_WARNING_CONFIG_FAILED;
5857
5858 ret = peer_timers_connect_unset(peer);
5859
5860 return bgp_vty_return(vty, ret);
5861 }
5862
5863 DEFUN (neighbor_timers_connect,
5864 neighbor_timers_connect_cmd,
5865 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
5866 NEIGHBOR_STR
5867 NEIGHBOR_ADDR_STR2
5868 "BGP per neighbor timers\n"
5869 "BGP connect timer\n"
5870 "Connect timer\n")
5871 {
5872 int idx_peer = 1;
5873 int idx_number = 4;
5874 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
5875 argv[idx_number]->arg);
5876 }
5877
5878 DEFUN (no_neighbor_timers_connect,
5879 no_neighbor_timers_connect_cmd,
5880 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
5881 NO_STR
5882 NEIGHBOR_STR
5883 NEIGHBOR_ADDR_STR2
5884 "BGP per neighbor timers\n"
5885 "BGP connect timer\n"
5886 "Connect timer\n")
5887 {
5888 int idx_peer = 2;
5889 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
5890 }
5891
5892
5893 static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
5894 const char *time_str, int set)
5895 {
5896 int ret;
5897 struct peer *peer;
5898 uint32_t routeadv = 0;
5899
5900 peer = peer_and_group_lookup_vty(vty, ip_str);
5901 if (!peer)
5902 return CMD_WARNING_CONFIG_FAILED;
5903
5904 if (time_str)
5905 routeadv = strtoul(time_str, NULL, 10);
5906
5907 if (set)
5908 ret = peer_advertise_interval_set(peer, routeadv);
5909 else
5910 ret = peer_advertise_interval_unset(peer);
5911
5912 return bgp_vty_return(vty, ret);
5913 }
5914
5915 DEFUN (neighbor_advertise_interval,
5916 neighbor_advertise_interval_cmd,
5917 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
5918 NEIGHBOR_STR
5919 NEIGHBOR_ADDR_STR2
5920 "Minimum interval between sending BGP routing updates\n"
5921 "time in seconds\n")
5922 {
5923 int idx_peer = 1;
5924 int idx_number = 3;
5925 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
5926 argv[idx_number]->arg, 1);
5927 }
5928
5929 DEFUN (no_neighbor_advertise_interval,
5930 no_neighbor_advertise_interval_cmd,
5931 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
5932 NO_STR
5933 NEIGHBOR_STR
5934 NEIGHBOR_ADDR_STR2
5935 "Minimum interval between sending BGP routing updates\n"
5936 "time in seconds\n")
5937 {
5938 int idx_peer = 2;
5939 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
5940 }
5941
5942
5943 /* Time to wait before processing route-map updates */
5944 DEFUN (bgp_set_route_map_delay_timer,
5945 bgp_set_route_map_delay_timer_cmd,
5946 "bgp route-map delay-timer (0-600)",
5947 SET_STR
5948 "BGP route-map delay timer\n"
5949 "Time in secs to wait before processing route-map changes\n"
5950 "0 disables the timer, no route updates happen when route-maps change\n")
5951 {
5952 int idx_number = 3;
5953 uint32_t rmap_delay_timer;
5954
5955 if (argv[idx_number]->arg) {
5956 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
5957 bm->rmap_update_timer = rmap_delay_timer;
5958
5959 /* if the dynamic update handling is being disabled, and a timer
5960 * is
5961 * running, stop the timer and act as if the timer has already
5962 * fired.
5963 */
5964 if (!rmap_delay_timer && bm->t_rmap_update) {
5965 BGP_TIMER_OFF(bm->t_rmap_update);
5966 thread_execute(bm->master, bgp_route_map_update_timer,
5967 NULL, 0);
5968 }
5969 return CMD_SUCCESS;
5970 } else {
5971 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
5972 return CMD_WARNING_CONFIG_FAILED;
5973 }
5974 }
5975
5976 DEFUN (no_bgp_set_route_map_delay_timer,
5977 no_bgp_set_route_map_delay_timer_cmd,
5978 "no bgp route-map delay-timer [(0-600)]",
5979 NO_STR
5980 BGP_STR
5981 "Default BGP route-map delay timer\n"
5982 "Reset to default time to wait for processing route-map changes\n"
5983 "0 disables the timer, no route updates happen when route-maps change\n")
5984 {
5985
5986 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
5987
5988 return CMD_SUCCESS;
5989 }
5990
5991
5992 /* neighbor interface */
5993 static int peer_interface_vty(struct vty *vty, const char *ip_str,
5994 const char *str)
5995 {
5996 struct peer *peer;
5997
5998 peer = peer_lookup_vty(vty, ip_str);
5999 if (!peer || peer->conf_if) {
6000 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
6001 return CMD_WARNING_CONFIG_FAILED;
6002 }
6003
6004 if (str)
6005 peer_interface_set(peer, str);
6006 else
6007 peer_interface_unset(peer);
6008
6009 return CMD_SUCCESS;
6010 }
6011
6012 DEFUN (neighbor_interface,
6013 neighbor_interface_cmd,
6014 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
6015 NEIGHBOR_STR
6016 NEIGHBOR_ADDR_STR
6017 "Interface\n"
6018 "Interface name\n")
6019 {
6020 int idx_ip = 1;
6021 int idx_word = 3;
6022 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
6023 }
6024
6025 DEFUN (no_neighbor_interface,
6026 no_neighbor_interface_cmd,
6027 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
6028 NO_STR
6029 NEIGHBOR_STR
6030 NEIGHBOR_ADDR_STR2
6031 "Interface\n"
6032 "Interface name\n")
6033 {
6034 int idx_peer = 2;
6035 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
6036 }
6037
6038 DEFUN (neighbor_distribute_list,
6039 neighbor_distribute_list_cmd,
6040 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
6041 NEIGHBOR_STR
6042 NEIGHBOR_ADDR_STR2
6043 "Filter updates to/from this neighbor\n"
6044 "IP access-list number\n"
6045 "IP access-list number (expanded range)\n"
6046 "IP Access-list name\n"
6047 "Filter incoming updates\n"
6048 "Filter outgoing updates\n")
6049 {
6050 int idx_peer = 1;
6051 int idx_acl = 3;
6052 int direct, ret;
6053 struct peer *peer;
6054
6055 const char *pstr = argv[idx_peer]->arg;
6056 const char *acl = argv[idx_acl]->arg;
6057 const char *inout = argv[argc - 1]->text;
6058
6059 peer = peer_and_group_lookup_vty(vty, pstr);
6060 if (!peer)
6061 return CMD_WARNING_CONFIG_FAILED;
6062
6063 /* Check filter direction. */
6064 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
6065 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6066 direct, acl);
6067
6068 return bgp_vty_return(vty, ret);
6069 }
6070
6071 ALIAS_HIDDEN(
6072 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
6073 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
6074 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6075 "Filter updates to/from this neighbor\n"
6076 "IP access-list number\n"
6077 "IP access-list number (expanded range)\n"
6078 "IP Access-list name\n"
6079 "Filter incoming updates\n"
6080 "Filter outgoing updates\n")
6081
6082 DEFUN (no_neighbor_distribute_list,
6083 no_neighbor_distribute_list_cmd,
6084 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
6085 NO_STR
6086 NEIGHBOR_STR
6087 NEIGHBOR_ADDR_STR2
6088 "Filter updates to/from this neighbor\n"
6089 "IP access-list number\n"
6090 "IP access-list number (expanded range)\n"
6091 "IP Access-list name\n"
6092 "Filter incoming updates\n"
6093 "Filter outgoing updates\n")
6094 {
6095 int idx_peer = 2;
6096 int direct, ret;
6097 struct peer *peer;
6098
6099 const char *pstr = argv[idx_peer]->arg;
6100 const char *inout = argv[argc - 1]->text;
6101
6102 peer = peer_and_group_lookup_vty(vty, pstr);
6103 if (!peer)
6104 return CMD_WARNING_CONFIG_FAILED;
6105
6106 /* Check filter direction. */
6107 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
6108 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6109 direct);
6110
6111 return bgp_vty_return(vty, ret);
6112 }
6113
6114 ALIAS_HIDDEN(
6115 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
6116 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
6117 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6118 "Filter updates to/from this neighbor\n"
6119 "IP access-list number\n"
6120 "IP access-list number (expanded range)\n"
6121 "IP Access-list name\n"
6122 "Filter incoming updates\n"
6123 "Filter outgoing updates\n")
6124
6125 /* Set prefix list to the peer. */
6126 static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
6127 afi_t afi, safi_t safi,
6128 const char *name_str,
6129 const char *direct_str)
6130 {
6131 int ret;
6132 int direct = FILTER_IN;
6133 struct peer *peer;
6134
6135 peer = peer_and_group_lookup_vty(vty, ip_str);
6136 if (!peer)
6137 return CMD_WARNING_CONFIG_FAILED;
6138
6139 /* Check filter direction. */
6140 if (strncmp(direct_str, "i", 1) == 0)
6141 direct = FILTER_IN;
6142 else if (strncmp(direct_str, "o", 1) == 0)
6143 direct = FILTER_OUT;
6144
6145 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
6146
6147 return bgp_vty_return(vty, ret);
6148 }
6149
6150 static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
6151 afi_t afi, safi_t safi,
6152 const char *direct_str)
6153 {
6154 int ret;
6155 struct peer *peer;
6156 int direct = FILTER_IN;
6157
6158 peer = peer_and_group_lookup_vty(vty, ip_str);
6159 if (!peer)
6160 return CMD_WARNING_CONFIG_FAILED;
6161
6162 /* Check filter direction. */
6163 if (strncmp(direct_str, "i", 1) == 0)
6164 direct = FILTER_IN;
6165 else if (strncmp(direct_str, "o", 1) == 0)
6166 direct = FILTER_OUT;
6167
6168 ret = peer_prefix_list_unset(peer, afi, safi, direct);
6169
6170 return bgp_vty_return(vty, ret);
6171 }
6172
6173 DEFUN (neighbor_prefix_list,
6174 neighbor_prefix_list_cmd,
6175 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
6176 NEIGHBOR_STR
6177 NEIGHBOR_ADDR_STR2
6178 "Filter updates to/from this neighbor\n"
6179 "Name of a prefix list\n"
6180 "Filter incoming updates\n"
6181 "Filter outgoing updates\n")
6182 {
6183 int idx_peer = 1;
6184 int idx_word = 3;
6185 int idx_in_out = 4;
6186 return peer_prefix_list_set_vty(
6187 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6188 argv[idx_word]->arg, argv[idx_in_out]->arg);
6189 }
6190
6191 ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
6192 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
6193 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6194 "Filter updates to/from this neighbor\n"
6195 "Name of a prefix list\n"
6196 "Filter incoming updates\n"
6197 "Filter outgoing updates\n")
6198
6199 DEFUN (no_neighbor_prefix_list,
6200 no_neighbor_prefix_list_cmd,
6201 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
6202 NO_STR
6203 NEIGHBOR_STR
6204 NEIGHBOR_ADDR_STR2
6205 "Filter updates to/from this neighbor\n"
6206 "Name of a prefix list\n"
6207 "Filter incoming updates\n"
6208 "Filter outgoing updates\n")
6209 {
6210 int idx_peer = 2;
6211 int idx_in_out = 5;
6212 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
6213 bgp_node_afi(vty), bgp_node_safi(vty),
6214 argv[idx_in_out]->arg);
6215 }
6216
6217 ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
6218 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
6219 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6220 "Filter updates to/from this neighbor\n"
6221 "Name of a prefix list\n"
6222 "Filter incoming updates\n"
6223 "Filter outgoing updates\n")
6224
6225 static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
6226 safi_t safi, const char *name_str,
6227 const char *direct_str)
6228 {
6229 int ret;
6230 struct peer *peer;
6231 int direct = FILTER_IN;
6232
6233 peer = peer_and_group_lookup_vty(vty, ip_str);
6234 if (!peer)
6235 return CMD_WARNING_CONFIG_FAILED;
6236
6237 /* Check filter direction. */
6238 if (strncmp(direct_str, "i", 1) == 0)
6239 direct = FILTER_IN;
6240 else if (strncmp(direct_str, "o", 1) == 0)
6241 direct = FILTER_OUT;
6242
6243 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
6244
6245 return bgp_vty_return(vty, ret);
6246 }
6247
6248 static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
6249 safi_t safi, const char *direct_str)
6250 {
6251 int ret;
6252 struct peer *peer;
6253 int direct = FILTER_IN;
6254
6255 peer = peer_and_group_lookup_vty(vty, ip_str);
6256 if (!peer)
6257 return CMD_WARNING_CONFIG_FAILED;
6258
6259 /* Check filter direction. */
6260 if (strncmp(direct_str, "i", 1) == 0)
6261 direct = FILTER_IN;
6262 else if (strncmp(direct_str, "o", 1) == 0)
6263 direct = FILTER_OUT;
6264
6265 ret = peer_aslist_unset(peer, afi, safi, direct);
6266
6267 return bgp_vty_return(vty, ret);
6268 }
6269
6270 DEFUN (neighbor_filter_list,
6271 neighbor_filter_list_cmd,
6272 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
6273 NEIGHBOR_STR
6274 NEIGHBOR_ADDR_STR2
6275 "Establish BGP filters\n"
6276 "AS path access-list name\n"
6277 "Filter incoming routes\n"
6278 "Filter outgoing routes\n")
6279 {
6280 int idx_peer = 1;
6281 int idx_word = 3;
6282 int idx_in_out = 4;
6283 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6284 bgp_node_safi(vty), argv[idx_word]->arg,
6285 argv[idx_in_out]->arg);
6286 }
6287
6288 ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
6289 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
6290 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6291 "Establish BGP filters\n"
6292 "AS path access-list name\n"
6293 "Filter incoming routes\n"
6294 "Filter outgoing routes\n")
6295
6296 DEFUN (no_neighbor_filter_list,
6297 no_neighbor_filter_list_cmd,
6298 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
6299 NO_STR
6300 NEIGHBOR_STR
6301 NEIGHBOR_ADDR_STR2
6302 "Establish BGP filters\n"
6303 "AS path access-list name\n"
6304 "Filter incoming routes\n"
6305 "Filter outgoing routes\n")
6306 {
6307 int idx_peer = 2;
6308 int idx_in_out = 5;
6309 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
6310 bgp_node_afi(vty), bgp_node_safi(vty),
6311 argv[idx_in_out]->arg);
6312 }
6313
6314 ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
6315 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
6316 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6317 "Establish BGP filters\n"
6318 "AS path access-list name\n"
6319 "Filter incoming routes\n"
6320 "Filter outgoing routes\n")
6321
6322 /* Set route-map to the peer. */
6323 static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
6324 afi_t afi, safi_t safi, const char *name_str,
6325 const char *direct_str)
6326 {
6327 int ret;
6328 struct peer *peer;
6329 int direct = RMAP_IN;
6330 struct route_map *route_map;
6331
6332 peer = peer_and_group_lookup_vty(vty, ip_str);
6333 if (!peer)
6334 return CMD_WARNING_CONFIG_FAILED;
6335
6336 /* Check filter direction. */
6337 if (strncmp(direct_str, "in", 2) == 0)
6338 direct = RMAP_IN;
6339 else if (strncmp(direct_str, "o", 1) == 0)
6340 direct = RMAP_OUT;
6341
6342 route_map = route_map_lookup_warn_noexist(vty, name_str);
6343 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
6344
6345 return bgp_vty_return(vty, ret);
6346 }
6347
6348 static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
6349 afi_t afi, safi_t safi,
6350 const char *direct_str)
6351 {
6352 int ret;
6353 struct peer *peer;
6354 int direct = RMAP_IN;
6355
6356 peer = peer_and_group_lookup_vty(vty, ip_str);
6357 if (!peer)
6358 return CMD_WARNING_CONFIG_FAILED;
6359
6360 /* Check filter direction. */
6361 if (strncmp(direct_str, "in", 2) == 0)
6362 direct = RMAP_IN;
6363 else if (strncmp(direct_str, "o", 1) == 0)
6364 direct = RMAP_OUT;
6365
6366 ret = peer_route_map_unset(peer, afi, safi, direct);
6367
6368 return bgp_vty_return(vty, ret);
6369 }
6370
6371 DEFUN (neighbor_route_map,
6372 neighbor_route_map_cmd,
6373 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
6374 NEIGHBOR_STR
6375 NEIGHBOR_ADDR_STR2
6376 "Apply route map to neighbor\n"
6377 "Name of route map\n"
6378 "Apply map to incoming routes\n"
6379 "Apply map to outbound routes\n")
6380 {
6381 int idx_peer = 1;
6382 int idx_word = 3;
6383 int idx_in_out = 4;
6384 return peer_route_map_set_vty(
6385 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6386 argv[idx_word]->arg, argv[idx_in_out]->arg);
6387 }
6388
6389 ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
6390 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
6391 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6392 "Apply route map to neighbor\n"
6393 "Name of route map\n"
6394 "Apply map to incoming routes\n"
6395 "Apply map to outbound routes\n")
6396
6397 DEFUN (no_neighbor_route_map,
6398 no_neighbor_route_map_cmd,
6399 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
6400 NO_STR
6401 NEIGHBOR_STR
6402 NEIGHBOR_ADDR_STR2
6403 "Apply route map to neighbor\n"
6404 "Name of route map\n"
6405 "Apply map to incoming routes\n"
6406 "Apply map to outbound routes\n")
6407 {
6408 int idx_peer = 2;
6409 int idx_in_out = 5;
6410 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
6411 bgp_node_afi(vty), bgp_node_safi(vty),
6412 argv[idx_in_out]->arg);
6413 }
6414
6415 ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
6416 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
6417 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6418 "Apply route map to neighbor\n"
6419 "Name of route map\n"
6420 "Apply map to incoming routes\n"
6421 "Apply map to outbound routes\n")
6422
6423 /* Set unsuppress-map to the peer. */
6424 static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
6425 afi_t afi, safi_t safi,
6426 const char *name_str)
6427 {
6428 int ret;
6429 struct peer *peer;
6430 struct route_map *route_map;
6431
6432 peer = peer_and_group_lookup_vty(vty, ip_str);
6433 if (!peer)
6434 return CMD_WARNING_CONFIG_FAILED;
6435
6436 route_map = route_map_lookup_warn_noexist(vty, name_str);
6437 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
6438
6439 return bgp_vty_return(vty, ret);
6440 }
6441
6442 /* Unset route-map from the peer. */
6443 static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
6444 afi_t afi, safi_t safi)
6445 {
6446 int ret;
6447 struct peer *peer;
6448
6449 peer = peer_and_group_lookup_vty(vty, ip_str);
6450 if (!peer)
6451 return CMD_WARNING_CONFIG_FAILED;
6452
6453 ret = peer_unsuppress_map_unset(peer, afi, safi);
6454
6455 return bgp_vty_return(vty, ret);
6456 }
6457
6458 DEFUN (neighbor_unsuppress_map,
6459 neighbor_unsuppress_map_cmd,
6460 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
6461 NEIGHBOR_STR
6462 NEIGHBOR_ADDR_STR2
6463 "Route-map to selectively unsuppress suppressed routes\n"
6464 "Name of route map\n")
6465 {
6466 int idx_peer = 1;
6467 int idx_word = 3;
6468 return peer_unsuppress_map_set_vty(
6469 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6470 argv[idx_word]->arg);
6471 }
6472
6473 ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
6474 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
6475 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6476 "Route-map to selectively unsuppress suppressed routes\n"
6477 "Name of route map\n")
6478
6479 DEFUN (no_neighbor_unsuppress_map,
6480 no_neighbor_unsuppress_map_cmd,
6481 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
6482 NO_STR
6483 NEIGHBOR_STR
6484 NEIGHBOR_ADDR_STR2
6485 "Route-map to selectively unsuppress suppressed routes\n"
6486 "Name of route map\n")
6487 {
6488 int idx_peer = 2;
6489 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
6490 bgp_node_afi(vty),
6491 bgp_node_safi(vty));
6492 }
6493
6494 ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
6495 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
6496 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6497 "Route-map to selectively unsuppress suppressed routes\n"
6498 "Name of route map\n")
6499
6500 static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
6501 afi_t afi, safi_t safi,
6502 const char *num_str,
6503 const char *threshold_str, int warning,
6504 const char *restart_str)
6505 {
6506 int ret;
6507 struct peer *peer;
6508 uint32_t max;
6509 uint8_t threshold;
6510 uint16_t restart;
6511
6512 peer = peer_and_group_lookup_vty(vty, ip_str);
6513 if (!peer)
6514 return CMD_WARNING_CONFIG_FAILED;
6515
6516 max = strtoul(num_str, NULL, 10);
6517 if (threshold_str)
6518 threshold = atoi(threshold_str);
6519 else
6520 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
6521
6522 if (restart_str)
6523 restart = atoi(restart_str);
6524 else
6525 restart = 0;
6526
6527 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
6528 restart);
6529
6530 return bgp_vty_return(vty, ret);
6531 }
6532
6533 static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
6534 afi_t afi, safi_t safi)
6535 {
6536 int ret;
6537 struct peer *peer;
6538
6539 peer = peer_and_group_lookup_vty(vty, ip_str);
6540 if (!peer)
6541 return CMD_WARNING_CONFIG_FAILED;
6542
6543 ret = peer_maximum_prefix_unset(peer, afi, safi);
6544
6545 return bgp_vty_return(vty, ret);
6546 }
6547
6548 /* Maximum number of prefix to be sent to the neighbor. */
6549 DEFUN(neighbor_maximum_prefix_out,
6550 neighbor_maximum_prefix_out_cmd,
6551 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out (1-4294967295)",
6552 NEIGHBOR_STR
6553 NEIGHBOR_ADDR_STR2
6554 "Maximum number of prefixes to be sent to this peer\n"
6555 "Maximum no. of prefix limit\n")
6556 {
6557 int idx_peer = 1;
6558 int idx_number = 3;
6559 struct peer *peer;
6560 uint32_t max;
6561 afi_t afi = bgp_node_afi(vty);
6562 safi_t safi = bgp_node_safi(vty);
6563
6564 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6565 if (!peer)
6566 return CMD_WARNING_CONFIG_FAILED;
6567
6568 max = strtoul(argv[idx_number]->arg, NULL, 10);
6569
6570 SET_FLAG(peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT);
6571 peer->pmax_out[afi][safi] = max;
6572
6573 return CMD_SUCCESS;
6574 }
6575
6576 DEFUN(no_neighbor_maximum_prefix_out,
6577 no_neighbor_maximum_prefix_out_cmd,
6578 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out",
6579 NO_STR
6580 NEIGHBOR_STR
6581 NEIGHBOR_ADDR_STR2
6582 "Maximum number of prefixes to be sent to this peer\n")
6583 {
6584 int idx_peer = 2;
6585 struct peer *peer;
6586 afi_t afi = bgp_node_afi(vty);
6587 safi_t safi = bgp_node_safi(vty);
6588
6589 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6590 if (!peer)
6591 return CMD_WARNING_CONFIG_FAILED;
6592
6593 peer->pmax_out[afi][safi] = 0;
6594
6595 return CMD_SUCCESS;
6596 }
6597
6598 /* Maximum number of prefix configuration. prefix count is different
6599 for each peer configuration. So this configuration can be set for
6600 each peer configuration. */
6601 DEFUN (neighbor_maximum_prefix,
6602 neighbor_maximum_prefix_cmd,
6603 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
6604 NEIGHBOR_STR
6605 NEIGHBOR_ADDR_STR2
6606 "Maximum number of prefix accept from this peer\n"
6607 "maximum no. of prefix limit\n")
6608 {
6609 int idx_peer = 1;
6610 int idx_number = 3;
6611 return peer_maximum_prefix_set_vty(
6612 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6613 argv[idx_number]->arg, NULL, 0, NULL);
6614 }
6615
6616 ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
6617 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
6618 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6619 "Maximum number of prefix accept from this peer\n"
6620 "maximum no. of prefix limit\n")
6621
6622 DEFUN (neighbor_maximum_prefix_threshold,
6623 neighbor_maximum_prefix_threshold_cmd,
6624 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
6625 NEIGHBOR_STR
6626 NEIGHBOR_ADDR_STR2
6627 "Maximum number of prefix accept from this peer\n"
6628 "maximum no. of prefix limit\n"
6629 "Threshold value (%) at which to generate a warning msg\n")
6630 {
6631 int idx_peer = 1;
6632 int idx_number = 3;
6633 int idx_number_2 = 4;
6634 return peer_maximum_prefix_set_vty(
6635 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6636 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL);
6637 }
6638
6639 ALIAS_HIDDEN(
6640 neighbor_maximum_prefix_threshold,
6641 neighbor_maximum_prefix_threshold_hidden_cmd,
6642 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
6643 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6644 "Maximum number of prefix accept from this peer\n"
6645 "maximum no. of prefix limit\n"
6646 "Threshold value (%) at which to generate a warning msg\n")
6647
6648 DEFUN (neighbor_maximum_prefix_warning,
6649 neighbor_maximum_prefix_warning_cmd,
6650 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
6651 NEIGHBOR_STR
6652 NEIGHBOR_ADDR_STR2
6653 "Maximum number of prefix accept from this peer\n"
6654 "maximum no. of prefix limit\n"
6655 "Only give warning message when limit is exceeded\n")
6656 {
6657 int idx_peer = 1;
6658 int idx_number = 3;
6659 return peer_maximum_prefix_set_vty(
6660 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6661 argv[idx_number]->arg, NULL, 1, NULL);
6662 }
6663
6664 ALIAS_HIDDEN(
6665 neighbor_maximum_prefix_warning,
6666 neighbor_maximum_prefix_warning_hidden_cmd,
6667 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
6668 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6669 "Maximum number of prefix accept from this peer\n"
6670 "maximum no. of prefix limit\n"
6671 "Only give warning message when limit is exceeded\n")
6672
6673 DEFUN (neighbor_maximum_prefix_threshold_warning,
6674 neighbor_maximum_prefix_threshold_warning_cmd,
6675 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
6676 NEIGHBOR_STR
6677 NEIGHBOR_ADDR_STR2
6678 "Maximum number of prefix accept from this peer\n"
6679 "maximum no. of prefix limit\n"
6680 "Threshold value (%) at which to generate a warning msg\n"
6681 "Only give warning message when limit is exceeded\n")
6682 {
6683 int idx_peer = 1;
6684 int idx_number = 3;
6685 int idx_number_2 = 4;
6686 return peer_maximum_prefix_set_vty(
6687 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6688 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL);
6689 }
6690
6691 ALIAS_HIDDEN(
6692 neighbor_maximum_prefix_threshold_warning,
6693 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
6694 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
6695 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6696 "Maximum number of prefix accept from this peer\n"
6697 "maximum no. of prefix limit\n"
6698 "Threshold value (%) at which to generate a warning msg\n"
6699 "Only give warning message when limit is exceeded\n")
6700
6701 DEFUN (neighbor_maximum_prefix_restart,
6702 neighbor_maximum_prefix_restart_cmd,
6703 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
6704 NEIGHBOR_STR
6705 NEIGHBOR_ADDR_STR2
6706 "Maximum number of prefix accept from this peer\n"
6707 "maximum no. of prefix limit\n"
6708 "Restart bgp connection after limit is exceeded\n"
6709 "Restart interval in minutes\n")
6710 {
6711 int idx_peer = 1;
6712 int idx_number = 3;
6713 int idx_number_2 = 5;
6714 return peer_maximum_prefix_set_vty(
6715 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6716 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg);
6717 }
6718
6719 ALIAS_HIDDEN(
6720 neighbor_maximum_prefix_restart,
6721 neighbor_maximum_prefix_restart_hidden_cmd,
6722 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
6723 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6724 "Maximum number of prefix accept from this peer\n"
6725 "maximum no. of prefix limit\n"
6726 "Restart bgp connection after limit is exceeded\n"
6727 "Restart interval in minutes\n")
6728
6729 DEFUN (neighbor_maximum_prefix_threshold_restart,
6730 neighbor_maximum_prefix_threshold_restart_cmd,
6731 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
6732 NEIGHBOR_STR
6733 NEIGHBOR_ADDR_STR2
6734 "Maximum number of prefixes to accept from this peer\n"
6735 "maximum no. of prefix limit\n"
6736 "Threshold value (%) at which to generate a warning msg\n"
6737 "Restart bgp connection after limit is exceeded\n"
6738 "Restart interval in minutes\n")
6739 {
6740 int idx_peer = 1;
6741 int idx_number = 3;
6742 int idx_number_2 = 4;
6743 int idx_number_3 = 6;
6744 return peer_maximum_prefix_set_vty(
6745 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6746 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
6747 argv[idx_number_3]->arg);
6748 }
6749
6750 ALIAS_HIDDEN(
6751 neighbor_maximum_prefix_threshold_restart,
6752 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
6753 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
6754 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6755 "Maximum number of prefixes to accept from this peer\n"
6756 "maximum no. of prefix limit\n"
6757 "Threshold value (%) at which to generate a warning msg\n"
6758 "Restart bgp connection after limit is exceeded\n"
6759 "Restart interval in minutes\n")
6760
6761 DEFUN (no_neighbor_maximum_prefix,
6762 no_neighbor_maximum_prefix_cmd,
6763 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
6764 NO_STR
6765 NEIGHBOR_STR
6766 NEIGHBOR_ADDR_STR2
6767 "Maximum number of prefixes to accept from this peer\n"
6768 "maximum no. of prefix limit\n"
6769 "Threshold value (%) at which to generate a warning msg\n"
6770 "Restart bgp connection after limit is exceeded\n"
6771 "Restart interval in minutes\n"
6772 "Only give warning message when limit is exceeded\n")
6773 {
6774 int idx_peer = 2;
6775 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
6776 bgp_node_afi(vty),
6777 bgp_node_safi(vty));
6778 }
6779
6780 ALIAS_HIDDEN(
6781 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
6782 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
6783 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6784 "Maximum number of prefixes to accept from this peer\n"
6785 "maximum no. of prefix limit\n"
6786 "Threshold value (%) at which to generate a warning msg\n"
6787 "Restart bgp connection after limit is exceeded\n"
6788 "Restart interval in minutes\n"
6789 "Only give warning message when limit is exceeded\n")
6790
6791
6792 /* "neighbor allowas-in" */
6793 DEFUN (neighbor_allowas_in,
6794 neighbor_allowas_in_cmd,
6795 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6796 NEIGHBOR_STR
6797 NEIGHBOR_ADDR_STR2
6798 "Accept as-path with my AS present in it\n"
6799 "Number of occurrences of AS number\n"
6800 "Only accept my AS in the as-path if the route was originated in my AS\n")
6801 {
6802 int idx_peer = 1;
6803 int idx_number_origin = 3;
6804 int ret;
6805 int origin = 0;
6806 struct peer *peer;
6807 int allow_num = 0;
6808
6809 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6810 if (!peer)
6811 return CMD_WARNING_CONFIG_FAILED;
6812
6813 if (argc <= idx_number_origin)
6814 allow_num = 3;
6815 else {
6816 if (argv[idx_number_origin]->type == WORD_TKN)
6817 origin = 1;
6818 else
6819 allow_num = atoi(argv[idx_number_origin]->arg);
6820 }
6821
6822 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6823 allow_num, origin);
6824
6825 return bgp_vty_return(vty, ret);
6826 }
6827
6828 ALIAS_HIDDEN(
6829 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
6830 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6831 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6832 "Accept as-path with my AS present in it\n"
6833 "Number of occurrences of AS number\n"
6834 "Only accept my AS in the as-path if the route was originated in my AS\n")
6835
6836 DEFUN (no_neighbor_allowas_in,
6837 no_neighbor_allowas_in_cmd,
6838 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6839 NO_STR
6840 NEIGHBOR_STR
6841 NEIGHBOR_ADDR_STR2
6842 "allow local ASN appears in aspath attribute\n"
6843 "Number of occurrences of AS number\n"
6844 "Only accept my AS in the as-path if the route was originated in my AS\n")
6845 {
6846 int idx_peer = 2;
6847 int ret;
6848 struct peer *peer;
6849
6850 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6851 if (!peer)
6852 return CMD_WARNING_CONFIG_FAILED;
6853
6854 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
6855 bgp_node_safi(vty));
6856
6857 return bgp_vty_return(vty, ret);
6858 }
6859
6860 ALIAS_HIDDEN(
6861 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
6862 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6863 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6864 "allow local ASN appears in aspath attribute\n"
6865 "Number of occurrences of AS number\n"
6866 "Only accept my AS in the as-path if the route was originated in my AS\n")
6867
6868 DEFUN (neighbor_ttl_security,
6869 neighbor_ttl_security_cmd,
6870 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
6871 NEIGHBOR_STR
6872 NEIGHBOR_ADDR_STR2
6873 "BGP ttl-security parameters\n"
6874 "Specify the maximum number of hops to the BGP peer\n"
6875 "Number of hops to BGP peer\n")
6876 {
6877 int idx_peer = 1;
6878 int idx_number = 4;
6879 struct peer *peer;
6880 int gtsm_hops;
6881
6882 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6883 if (!peer)
6884 return CMD_WARNING_CONFIG_FAILED;
6885
6886 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
6887
6888 /*
6889 * If 'neighbor swpX', then this is for directly connected peers,
6890 * we should not accept a ttl-security hops value greater than 1.
6891 */
6892 if (peer->conf_if && (gtsm_hops > BGP_GTSM_HOPS_CONNECTED)) {
6893 vty_out(vty,
6894 "%s is directly connected peer, hops cannot exceed 1\n",
6895 argv[idx_peer]->arg);
6896 return CMD_WARNING_CONFIG_FAILED;
6897 }
6898
6899 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
6900 }
6901
6902 DEFUN (no_neighbor_ttl_security,
6903 no_neighbor_ttl_security_cmd,
6904 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
6905 NO_STR
6906 NEIGHBOR_STR
6907 NEIGHBOR_ADDR_STR2
6908 "BGP ttl-security parameters\n"
6909 "Specify the maximum number of hops to the BGP peer\n"
6910 "Number of hops to BGP peer\n")
6911 {
6912 int idx_peer = 2;
6913 struct peer *peer;
6914
6915 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6916 if (!peer)
6917 return CMD_WARNING_CONFIG_FAILED;
6918
6919 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
6920 }
6921
6922 DEFUN (neighbor_addpath_tx_all_paths,
6923 neighbor_addpath_tx_all_paths_cmd,
6924 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6925 NEIGHBOR_STR
6926 NEIGHBOR_ADDR_STR2
6927 "Use addpath to advertise all paths to a neighbor\n")
6928 {
6929 int idx_peer = 1;
6930 struct peer *peer;
6931
6932 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6933 if (!peer)
6934 return CMD_WARNING_CONFIG_FAILED;
6935
6936 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6937 BGP_ADDPATH_ALL);
6938 return CMD_SUCCESS;
6939 }
6940
6941 ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
6942 neighbor_addpath_tx_all_paths_hidden_cmd,
6943 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6944 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6945 "Use addpath to advertise all paths to a neighbor\n")
6946
6947 DEFUN (no_neighbor_addpath_tx_all_paths,
6948 no_neighbor_addpath_tx_all_paths_cmd,
6949 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6950 NO_STR
6951 NEIGHBOR_STR
6952 NEIGHBOR_ADDR_STR2
6953 "Use addpath to advertise all paths to a neighbor\n")
6954 {
6955 int idx_peer = 2;
6956 struct peer *peer;
6957
6958 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6959 if (!peer)
6960 return CMD_WARNING_CONFIG_FAILED;
6961
6962 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
6963 != BGP_ADDPATH_ALL) {
6964 vty_out(vty,
6965 "%% Peer not currently configured to transmit all paths.");
6966 return CMD_WARNING_CONFIG_FAILED;
6967 }
6968
6969 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6970 BGP_ADDPATH_NONE);
6971
6972 return CMD_SUCCESS;
6973 }
6974
6975 ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
6976 no_neighbor_addpath_tx_all_paths_hidden_cmd,
6977 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6978 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6979 "Use addpath to advertise all paths to a neighbor\n")
6980
6981 DEFUN (neighbor_addpath_tx_bestpath_per_as,
6982 neighbor_addpath_tx_bestpath_per_as_cmd,
6983 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6984 NEIGHBOR_STR
6985 NEIGHBOR_ADDR_STR2
6986 "Use addpath to advertise the bestpath per each neighboring AS\n")
6987 {
6988 int idx_peer = 1;
6989 struct peer *peer;
6990
6991 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6992 if (!peer)
6993 return CMD_WARNING_CONFIG_FAILED;
6994
6995 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6996 BGP_ADDPATH_BEST_PER_AS);
6997
6998 return CMD_SUCCESS;
6999 }
7000
7001 ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
7002 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
7003 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
7004 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7005 "Use addpath to advertise the bestpath per each neighboring AS\n")
7006
7007 DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
7008 no_neighbor_addpath_tx_bestpath_per_as_cmd,
7009 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
7010 NO_STR
7011 NEIGHBOR_STR
7012 NEIGHBOR_ADDR_STR2
7013 "Use addpath to advertise the bestpath per each neighboring AS\n")
7014 {
7015 int idx_peer = 2;
7016 struct peer *peer;
7017
7018 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7019 if (!peer)
7020 return CMD_WARNING_CONFIG_FAILED;
7021
7022 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
7023 != BGP_ADDPATH_BEST_PER_AS) {
7024 vty_out(vty,
7025 "%% Peer not currently configured to transmit all best path per as.");
7026 return CMD_WARNING_CONFIG_FAILED;
7027 }
7028
7029 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7030 BGP_ADDPATH_NONE);
7031
7032 return CMD_SUCCESS;
7033 }
7034
7035 ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
7036 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
7037 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
7038 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7039 "Use addpath to advertise the bestpath per each neighboring AS\n")
7040
7041 DEFPY(
7042 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
7043 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
7044 NEIGHBOR_STR
7045 NEIGHBOR_ADDR_STR2
7046 "Detect AS loops before sending to neighbor\n")
7047 {
7048 struct peer *peer;
7049
7050 peer = peer_and_group_lookup_vty(vty, neighbor);
7051 if (!peer)
7052 return CMD_WARNING_CONFIG_FAILED;
7053
7054 peer->as_path_loop_detection = true;
7055
7056 return CMD_SUCCESS;
7057 }
7058
7059 DEFPY(
7060 no_neighbor_aspath_loop_detection,
7061 no_neighbor_aspath_loop_detection_cmd,
7062 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
7063 NO_STR
7064 NEIGHBOR_STR
7065 NEIGHBOR_ADDR_STR2
7066 "Detect AS loops before sending to neighbor\n")
7067 {
7068 struct peer *peer;
7069
7070 peer = peer_and_group_lookup_vty(vty, neighbor);
7071 if (!peer)
7072 return CMD_WARNING_CONFIG_FAILED;
7073
7074 peer->as_path_loop_detection = false;
7075
7076 return CMD_SUCCESS;
7077 }
7078
7079 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
7080 struct ecommunity **list)
7081 {
7082 struct ecommunity *ecom = NULL;
7083 struct ecommunity *ecomadd;
7084
7085 for (; argc; --argc, ++argv) {
7086
7087 ecomadd = ecommunity_str2com(argv[0]->arg,
7088 ECOMMUNITY_ROUTE_TARGET, 0);
7089 if (!ecomadd) {
7090 vty_out(vty, "Malformed community-list value\n");
7091 if (ecom)
7092 ecommunity_free(&ecom);
7093 return CMD_WARNING_CONFIG_FAILED;
7094 }
7095
7096 if (ecom) {
7097 ecommunity_merge(ecom, ecomadd);
7098 ecommunity_free(&ecomadd);
7099 } else {
7100 ecom = ecomadd;
7101 }
7102 }
7103
7104 if (*list) {
7105 ecommunity_free(&*list);
7106 }
7107 *list = ecom;
7108
7109 return CMD_SUCCESS;
7110 }
7111
7112 /*
7113 * v2vimport is true if we are handling a `import vrf ...` command
7114 */
7115 static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
7116 {
7117 afi_t afi;
7118
7119 switch (vty->node) {
7120 case BGP_IPV4_NODE:
7121 afi = AFI_IP;
7122 break;
7123 case BGP_IPV6_NODE:
7124 afi = AFI_IP6;
7125 break;
7126 default:
7127 vty_out(vty,
7128 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
7129 return AFI_MAX;
7130 }
7131
7132 if (!v2vimport) {
7133 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
7134 BGP_CONFIG_VRF_TO_VRF_IMPORT)
7135 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
7136 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
7137 vty_out(vty,
7138 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
7139 return AFI_MAX;
7140 }
7141 } else {
7142 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
7143 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
7144 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
7145 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
7146 vty_out(vty,
7147 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
7148 return AFI_MAX;
7149 }
7150 }
7151 return afi;
7152 }
7153
7154 DEFPY (af_rd_vpn_export,
7155 af_rd_vpn_export_cmd,
7156 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
7157 NO_STR
7158 "Specify route distinguisher\n"
7159 "Between current address-family and vpn\n"
7160 "For routes leaked from current address-family to vpn\n"
7161 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
7162 {
7163 VTY_DECLVAR_CONTEXT(bgp, bgp);
7164 struct prefix_rd prd;
7165 int ret;
7166 afi_t afi;
7167 int idx = 0;
7168 int yes = 1;
7169
7170 if (argv_find(argv, argc, "no", &idx))
7171 yes = 0;
7172
7173 if (yes) {
7174 ret = str2prefix_rd(rd_str, &prd);
7175 if (!ret) {
7176 vty_out(vty, "%% Malformed rd\n");
7177 return CMD_WARNING_CONFIG_FAILED;
7178 }
7179 }
7180
7181 afi = vpn_policy_getafi(vty, bgp, false);
7182 if (afi == AFI_MAX)
7183 return CMD_WARNING_CONFIG_FAILED;
7184
7185 /*
7186 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
7187 */
7188 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
7189 bgp_get_default(), bgp);
7190
7191 if (yes) {
7192 bgp->vpn_policy[afi].tovpn_rd = prd;
7193 SET_FLAG(bgp->vpn_policy[afi].flags,
7194 BGP_VPN_POLICY_TOVPN_RD_SET);
7195 } else {
7196 UNSET_FLAG(bgp->vpn_policy[afi].flags,
7197 BGP_VPN_POLICY_TOVPN_RD_SET);
7198 }
7199
7200 /* post-change: re-export vpn routes */
7201 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
7202 bgp_get_default(), bgp);
7203
7204 return CMD_SUCCESS;
7205 }
7206
7207 ALIAS (af_rd_vpn_export,
7208 af_no_rd_vpn_export_cmd,
7209 "no rd vpn export",
7210 NO_STR
7211 "Specify route distinguisher\n"
7212 "Between current address-family and vpn\n"
7213 "For routes leaked from current address-family to vpn\n")
7214
7215 DEFPY (af_label_vpn_export,
7216 af_label_vpn_export_cmd,
7217 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
7218 NO_STR
7219 "label value for VRF\n"
7220 "Between current address-family and vpn\n"
7221 "For routes leaked from current address-family to vpn\n"
7222 "Label Value <0-1048575>\n"
7223 "Automatically assign a label\n")
7224 {
7225 VTY_DECLVAR_CONTEXT(bgp, bgp);
7226 mpls_label_t label = MPLS_LABEL_NONE;
7227 afi_t afi;
7228 int idx = 0;
7229 int yes = 1;
7230
7231 if (argv_find(argv, argc, "no", &idx))
7232 yes = 0;
7233
7234 /* If "no ...", squash trailing parameter */
7235 if (!yes)
7236 label_auto = NULL;
7237
7238 if (yes) {
7239 if (!label_auto)
7240 label = label_val; /* parser should force unsigned */
7241 }
7242
7243 afi = vpn_policy_getafi(vty, bgp, false);
7244 if (afi == AFI_MAX)
7245 return CMD_WARNING_CONFIG_FAILED;
7246
7247
7248 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
7249 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
7250 /* no change */
7251 return CMD_SUCCESS;
7252
7253 /*
7254 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
7255 */
7256 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
7257 bgp_get_default(), bgp);
7258
7259 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
7260 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
7261
7262 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
7263
7264 /*
7265 * label has previously been automatically
7266 * assigned by labelpool: release it
7267 *
7268 * NB if tovpn_label == MPLS_LABEL_NONE it
7269 * means the automatic assignment is in flight
7270 * and therefore the labelpool callback must
7271 * detect that the auto label is not needed.
7272 */
7273
7274 bgp_lp_release(LP_TYPE_VRF,
7275 &bgp->vpn_policy[afi],
7276 bgp->vpn_policy[afi].tovpn_label);
7277 }
7278 UNSET_FLAG(bgp->vpn_policy[afi].flags,
7279 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
7280 }
7281
7282 bgp->vpn_policy[afi].tovpn_label = label;
7283 if (label_auto) {
7284 SET_FLAG(bgp->vpn_policy[afi].flags,
7285 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
7286 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
7287 vpn_leak_label_callback);
7288 }
7289
7290 /* post-change: re-export vpn routes */
7291 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
7292 bgp_get_default(), bgp);
7293
7294 return CMD_SUCCESS;
7295 }
7296
7297 ALIAS (af_label_vpn_export,
7298 af_no_label_vpn_export_cmd,
7299 "no label vpn export",
7300 NO_STR
7301 "label value for VRF\n"
7302 "Between current address-family and vpn\n"
7303 "For routes leaked from current address-family to vpn\n")
7304
7305 DEFPY (af_nexthop_vpn_export,
7306 af_nexthop_vpn_export_cmd,
7307 "[no] nexthop vpn export <A.B.C.D|X:X::X:X>$nexthop_str",
7308 NO_STR
7309 "Specify next hop to use for VRF advertised prefixes\n"
7310 "Between current address-family and vpn\n"
7311 "For routes leaked from current address-family to vpn\n"
7312 "IPv4 prefix\n"
7313 "IPv6 prefix\n")
7314 {
7315 VTY_DECLVAR_CONTEXT(bgp, bgp);
7316 afi_t afi;
7317 struct prefix p;
7318 int idx = 0;
7319 int yes = 1;
7320
7321 if (argv_find(argv, argc, "no", &idx))
7322 yes = 0;
7323
7324 if (yes) {
7325 if (!sockunion2hostprefix(nexthop_str, &p))
7326 return CMD_WARNING_CONFIG_FAILED;
7327 }
7328
7329 afi = vpn_policy_getafi(vty, bgp, false);
7330 if (afi == AFI_MAX)
7331 return CMD_WARNING_CONFIG_FAILED;
7332
7333 /*
7334 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
7335 */
7336 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
7337 bgp_get_default(), bgp);
7338
7339 if (yes) {
7340 bgp->vpn_policy[afi].tovpn_nexthop = p;
7341 SET_FLAG(bgp->vpn_policy[afi].flags,
7342 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
7343 } else {
7344 UNSET_FLAG(bgp->vpn_policy[afi].flags,
7345 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
7346 }
7347
7348 /* post-change: re-export vpn routes */
7349 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
7350 bgp_get_default(), bgp);
7351
7352 return CMD_SUCCESS;
7353 }
7354
7355 ALIAS (af_nexthop_vpn_export,
7356 af_no_nexthop_vpn_export_cmd,
7357 "no nexthop vpn export",
7358 NO_STR
7359 "Specify next hop to use for VRF advertised prefixes\n"
7360 "Between current address-family and vpn\n"
7361 "For routes leaked from current address-family to vpn\n")
7362
7363 static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
7364 {
7365 if (!strcmp(dstr, "import")) {
7366 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
7367 } else if (!strcmp(dstr, "export")) {
7368 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
7369 } else if (!strcmp(dstr, "both")) {
7370 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
7371 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
7372 } else {
7373 vty_out(vty, "%% direction parse error\n");
7374 return CMD_WARNING_CONFIG_FAILED;
7375 }
7376 return CMD_SUCCESS;
7377 }
7378
7379 DEFPY (af_rt_vpn_imexport,
7380 af_rt_vpn_imexport_cmd,
7381 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
7382 NO_STR
7383 "Specify route target list\n"
7384 "Specify route target list\n"
7385 "Between current address-family and vpn\n"
7386 "For routes leaked from vpn to current address-family: match any\n"
7387 "For routes leaked from current address-family to vpn: set\n"
7388 "both import: match any and export: set\n"
7389 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
7390 {
7391 VTY_DECLVAR_CONTEXT(bgp, bgp);
7392 int ret;
7393 struct ecommunity *ecom = NULL;
7394 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
7395 vpn_policy_direction_t dir;
7396 afi_t afi;
7397 int idx = 0;
7398 int yes = 1;
7399
7400 if (argv_find(argv, argc, "no", &idx))
7401 yes = 0;
7402
7403 afi = vpn_policy_getafi(vty, bgp, false);
7404 if (afi == AFI_MAX)
7405 return CMD_WARNING_CONFIG_FAILED;
7406
7407 ret = vpn_policy_getdirs(vty, direction_str, dodir);
7408 if (ret != CMD_SUCCESS)
7409 return ret;
7410
7411 if (yes) {
7412 if (!argv_find(argv, argc, "RTLIST", &idx)) {
7413 vty_out(vty, "%% Missing RTLIST\n");
7414 return CMD_WARNING_CONFIG_FAILED;
7415 }
7416 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
7417 if (ret != CMD_SUCCESS) {
7418 return ret;
7419 }
7420 }
7421
7422 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
7423 if (!dodir[dir])
7424 continue;
7425
7426 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
7427
7428 if (yes) {
7429 if (bgp->vpn_policy[afi].rtlist[dir])
7430 ecommunity_free(
7431 &bgp->vpn_policy[afi].rtlist[dir]);
7432 bgp->vpn_policy[afi].rtlist[dir] =
7433 ecommunity_dup(ecom);
7434 } else {
7435 if (bgp->vpn_policy[afi].rtlist[dir])
7436 ecommunity_free(
7437 &bgp->vpn_policy[afi].rtlist[dir]);
7438 bgp->vpn_policy[afi].rtlist[dir] = NULL;
7439 }
7440
7441 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
7442 }
7443
7444 if (ecom)
7445 ecommunity_free(&ecom);
7446
7447 return CMD_SUCCESS;
7448 }
7449
7450 ALIAS (af_rt_vpn_imexport,
7451 af_no_rt_vpn_imexport_cmd,
7452 "no <rt|route-target> vpn <import|export|both>$direction_str",
7453 NO_STR
7454 "Specify route target list\n"
7455 "Specify route target list\n"
7456 "Between current address-family and vpn\n"
7457 "For routes leaked from vpn to current address-family\n"
7458 "For routes leaked from current address-family to vpn\n"
7459 "both import and export\n")
7460
7461 DEFPY (af_route_map_vpn_imexport,
7462 af_route_map_vpn_imexport_cmd,
7463 /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
7464 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
7465 NO_STR
7466 "Specify route map\n"
7467 "Between current address-family and vpn\n"
7468 "For routes leaked from vpn to current address-family\n"
7469 "For routes leaked from current address-family to vpn\n"
7470 "name of route-map\n")
7471 {
7472 VTY_DECLVAR_CONTEXT(bgp, bgp);
7473 int ret;
7474 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
7475 vpn_policy_direction_t dir;
7476 afi_t afi;
7477 int idx = 0;
7478 int yes = 1;
7479
7480 if (argv_find(argv, argc, "no", &idx))
7481 yes = 0;
7482
7483 afi = vpn_policy_getafi(vty, bgp, false);
7484 if (afi == AFI_MAX)
7485 return CMD_WARNING_CONFIG_FAILED;
7486
7487 ret = vpn_policy_getdirs(vty, direction_str, dodir);
7488 if (ret != CMD_SUCCESS)
7489 return ret;
7490
7491 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
7492 if (!dodir[dir])
7493 continue;
7494
7495 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
7496
7497 if (yes) {
7498 if (bgp->vpn_policy[afi].rmap_name[dir])
7499 XFREE(MTYPE_ROUTE_MAP_NAME,
7500 bgp->vpn_policy[afi].rmap_name[dir]);
7501 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
7502 MTYPE_ROUTE_MAP_NAME, rmap_str);
7503 bgp->vpn_policy[afi].rmap[dir] =
7504 route_map_lookup_warn_noexist(vty, rmap_str);
7505 if (!bgp->vpn_policy[afi].rmap[dir])
7506 return CMD_SUCCESS;
7507 } else {
7508 if (bgp->vpn_policy[afi].rmap_name[dir])
7509 XFREE(MTYPE_ROUTE_MAP_NAME,
7510 bgp->vpn_policy[afi].rmap_name[dir]);
7511 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
7512 bgp->vpn_policy[afi].rmap[dir] = NULL;
7513 }
7514
7515 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
7516 }
7517
7518 return CMD_SUCCESS;
7519 }
7520
7521 ALIAS (af_route_map_vpn_imexport,
7522 af_no_route_map_vpn_imexport_cmd,
7523 "no route-map vpn <import|export>$direction_str",
7524 NO_STR
7525 "Specify route map\n"
7526 "Between current address-family and vpn\n"
7527 "For routes leaked from vpn to current address-family\n"
7528 "For routes leaked from current address-family to vpn\n")
7529
7530 DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
7531 "[no] import vrf route-map RMAP$rmap_str",
7532 NO_STR
7533 "Import routes from another VRF\n"
7534 "Vrf routes being filtered\n"
7535 "Specify route map\n"
7536 "name of route-map\n")
7537 {
7538 VTY_DECLVAR_CONTEXT(bgp, bgp);
7539 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
7540 afi_t afi;
7541 int idx = 0;
7542 int yes = 1;
7543 struct bgp *bgp_default;
7544
7545 if (argv_find(argv, argc, "no", &idx))
7546 yes = 0;
7547
7548 afi = vpn_policy_getafi(vty, bgp, true);
7549 if (afi == AFI_MAX)
7550 return CMD_WARNING_CONFIG_FAILED;
7551
7552 bgp_default = bgp_get_default();
7553 if (!bgp_default) {
7554 int32_t ret;
7555 as_t as = bgp->as;
7556
7557 /* Auto-create assuming the same AS */
7558 ret = bgp_get_vty(&bgp_default, &as, NULL,
7559 BGP_INSTANCE_TYPE_DEFAULT);
7560
7561 if (ret) {
7562 vty_out(vty,
7563 "VRF default is not configured as a bgp instance\n");
7564 return CMD_WARNING;
7565 }
7566 }
7567
7568 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
7569
7570 if (yes) {
7571 if (bgp->vpn_policy[afi].rmap_name[dir])
7572 XFREE(MTYPE_ROUTE_MAP_NAME,
7573 bgp->vpn_policy[afi].rmap_name[dir]);
7574 bgp->vpn_policy[afi].rmap_name[dir] =
7575 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
7576 bgp->vpn_policy[afi].rmap[dir] =
7577 route_map_lookup_warn_noexist(vty, rmap_str);
7578 if (!bgp->vpn_policy[afi].rmap[dir])
7579 return CMD_SUCCESS;
7580 } else {
7581 if (bgp->vpn_policy[afi].rmap_name[dir])
7582 XFREE(MTYPE_ROUTE_MAP_NAME,
7583 bgp->vpn_policy[afi].rmap_name[dir]);
7584 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
7585 bgp->vpn_policy[afi].rmap[dir] = NULL;
7586 }
7587
7588 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
7589
7590 return CMD_SUCCESS;
7591 }
7592
7593 ALIAS(af_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
7594 "no import vrf route-map",
7595 NO_STR
7596 "Import routes from another VRF\n"
7597 "Vrf routes being filtered\n"
7598 "Specify route map\n")
7599
7600 DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
7601 "[no] import vrf VIEWVRFNAME$import_name",
7602 NO_STR
7603 "Import routes from another VRF\n"
7604 "VRF to import from\n"
7605 "The name of the VRF\n")
7606 {
7607 VTY_DECLVAR_CONTEXT(bgp, bgp);
7608 struct listnode *node;
7609 struct bgp *vrf_bgp, *bgp_default;
7610 int32_t ret = 0;
7611 as_t as = bgp->as;
7612 bool remove = false;
7613 int32_t idx = 0;
7614 char *vname;
7615 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
7616 safi_t safi;
7617 afi_t afi;
7618
7619 if (import_name == NULL) {
7620 vty_out(vty, "%% Missing import name\n");
7621 return CMD_WARNING;
7622 }
7623
7624 if (argv_find(argv, argc, "no", &idx))
7625 remove = true;
7626
7627 afi = vpn_policy_getafi(vty, bgp, true);
7628 if (afi == AFI_MAX)
7629 return CMD_WARNING_CONFIG_FAILED;
7630
7631 safi = bgp_node_safi(vty);
7632
7633 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
7634 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
7635 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
7636 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
7637 remove ? "unimport" : "import", import_name);
7638 return CMD_WARNING;
7639 }
7640
7641 bgp_default = bgp_get_default();
7642 if (!bgp_default) {
7643 /* Auto-create assuming the same AS */
7644 ret = bgp_get_vty(&bgp_default, &as, NULL,
7645 BGP_INSTANCE_TYPE_DEFAULT);
7646
7647 if (ret) {
7648 vty_out(vty,
7649 "VRF default is not configured as a bgp instance\n");
7650 return CMD_WARNING;
7651 }
7652 }
7653
7654 vrf_bgp = bgp_lookup_by_name(import_name);
7655 if (!vrf_bgp) {
7656 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
7657 vrf_bgp = bgp_default;
7658 else
7659 /* Auto-create assuming the same AS */
7660 ret = bgp_get_vty(&vrf_bgp, &as, import_name, bgp_type);
7661
7662 if (ret) {
7663 vty_out(vty,
7664 "VRF %s is not configured as a bgp instance\n",
7665 import_name);
7666 return CMD_WARNING;
7667 }
7668 }
7669
7670 if (remove) {
7671 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
7672 } else {
7673 /* Already importing from "import_vrf"? */
7674 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
7675 vname)) {
7676 if (strcmp(vname, import_name) == 0)
7677 return CMD_WARNING;
7678 }
7679
7680 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
7681 }
7682
7683 return CMD_SUCCESS;
7684 }
7685
7686 /* This command is valid only in a bgp vrf instance or the default instance */
7687 DEFPY (bgp_imexport_vpn,
7688 bgp_imexport_vpn_cmd,
7689 "[no] <import|export>$direction_str vpn",
7690 NO_STR
7691 "Import routes to this address-family\n"
7692 "Export routes from this address-family\n"
7693 "to/from default instance VPN RIB\n")
7694 {
7695 VTY_DECLVAR_CONTEXT(bgp, bgp);
7696 int previous_state;
7697 afi_t afi;
7698 safi_t safi;
7699 int idx = 0;
7700 int yes = 1;
7701 int flag;
7702 vpn_policy_direction_t dir;
7703
7704 if (argv_find(argv, argc, "no", &idx))
7705 yes = 0;
7706
7707 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
7708 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
7709
7710 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
7711 return CMD_WARNING_CONFIG_FAILED;
7712 }
7713
7714 afi = bgp_node_afi(vty);
7715 safi = bgp_node_safi(vty);
7716 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
7717 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
7718 return CMD_WARNING_CONFIG_FAILED;
7719 }
7720
7721 if (!strcmp(direction_str, "import")) {
7722 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
7723 dir = BGP_VPN_POLICY_DIR_FROMVPN;
7724 } else if (!strcmp(direction_str, "export")) {
7725 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
7726 dir = BGP_VPN_POLICY_DIR_TOVPN;
7727 } else {
7728 vty_out(vty, "%% unknown direction %s\n", direction_str);
7729 return CMD_WARNING_CONFIG_FAILED;
7730 }
7731
7732 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
7733
7734 if (yes) {
7735 SET_FLAG(bgp->af_flags[afi][safi], flag);
7736 if (!previous_state) {
7737 /* trigger export current vrf */
7738 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
7739 }
7740 } else {
7741 if (previous_state) {
7742 /* trigger un-export current vrf */
7743 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
7744 }
7745 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
7746 }
7747
7748 return CMD_SUCCESS;
7749 }
7750
7751 DEFPY (af_routetarget_import,
7752 af_routetarget_import_cmd,
7753 "[no] <rt|route-target> redirect import RTLIST...",
7754 NO_STR
7755 "Specify route target list\n"
7756 "Specify route target list\n"
7757 "Flow-spec redirect type route target\n"
7758 "Import routes to this address-family\n"
7759 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
7760 {
7761 VTY_DECLVAR_CONTEXT(bgp, bgp);
7762 int ret;
7763 struct ecommunity *ecom = NULL;
7764 afi_t afi;
7765 int idx = 0;
7766 int yes = 1;
7767
7768 if (argv_find(argv, argc, "no", &idx))
7769 yes = 0;
7770
7771 afi = vpn_policy_getafi(vty, bgp, false);
7772 if (afi == AFI_MAX)
7773 return CMD_WARNING_CONFIG_FAILED;
7774
7775 if (yes) {
7776 if (!argv_find(argv, argc, "RTLIST", &idx)) {
7777 vty_out(vty, "%% Missing RTLIST\n");
7778 return CMD_WARNING_CONFIG_FAILED;
7779 }
7780 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
7781 if (ret != CMD_SUCCESS)
7782 return ret;
7783 }
7784
7785 if (yes) {
7786 if (bgp->vpn_policy[afi].import_redirect_rtlist)
7787 ecommunity_free(&bgp->vpn_policy[afi]
7788 .import_redirect_rtlist);
7789 bgp->vpn_policy[afi].import_redirect_rtlist =
7790 ecommunity_dup(ecom);
7791 } else {
7792 if (bgp->vpn_policy[afi].import_redirect_rtlist)
7793 ecommunity_free(&bgp->vpn_policy[afi]
7794 .import_redirect_rtlist);
7795 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
7796 }
7797
7798 if (ecom)
7799 ecommunity_free(&ecom);
7800
7801 return CMD_SUCCESS;
7802 }
7803
7804 DEFUN_NOSH (address_family_ipv4_safi,
7805 address_family_ipv4_safi_cmd,
7806 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
7807 "Enter Address Family command mode\n"
7808 "Address Family\n"
7809 BGP_SAFI_WITH_LABEL_HELP_STR)
7810 {
7811
7812 if (argc == 3) {
7813 VTY_DECLVAR_CONTEXT(bgp, bgp);
7814 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
7815 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
7816 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
7817 && safi != SAFI_EVPN) {
7818 vty_out(vty,
7819 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
7820 return CMD_WARNING_CONFIG_FAILED;
7821 }
7822 vty->node = bgp_node_type(AFI_IP, safi);
7823 } else
7824 vty->node = BGP_IPV4_NODE;
7825
7826 return CMD_SUCCESS;
7827 }
7828
7829 DEFUN_NOSH (address_family_ipv6_safi,
7830 address_family_ipv6_safi_cmd,
7831 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
7832 "Enter Address Family command mode\n"
7833 "Address Family\n"
7834 BGP_SAFI_WITH_LABEL_HELP_STR)
7835 {
7836 if (argc == 3) {
7837 VTY_DECLVAR_CONTEXT(bgp, bgp);
7838 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
7839 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
7840 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
7841 && safi != SAFI_EVPN) {
7842 vty_out(vty,
7843 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
7844 return CMD_WARNING_CONFIG_FAILED;
7845 }
7846 vty->node = bgp_node_type(AFI_IP6, safi);
7847 } else
7848 vty->node = BGP_IPV6_NODE;
7849
7850 return CMD_SUCCESS;
7851 }
7852
7853 #ifdef KEEP_OLD_VPN_COMMANDS
7854 DEFUN_NOSH (address_family_vpnv4,
7855 address_family_vpnv4_cmd,
7856 "address-family vpnv4 [unicast]",
7857 "Enter Address Family command mode\n"
7858 "Address Family\n"
7859 "Address Family modifier\n")
7860 {
7861 vty->node = BGP_VPNV4_NODE;
7862 return CMD_SUCCESS;
7863 }
7864
7865 DEFUN_NOSH (address_family_vpnv6,
7866 address_family_vpnv6_cmd,
7867 "address-family vpnv6 [unicast]",
7868 "Enter Address Family command mode\n"
7869 "Address Family\n"
7870 "Address Family modifier\n")
7871 {
7872 vty->node = BGP_VPNV6_NODE;
7873 return CMD_SUCCESS;
7874 }
7875 #endif /* KEEP_OLD_VPN_COMMANDS */
7876
7877 DEFUN_NOSH (address_family_evpn,
7878 address_family_evpn_cmd,
7879 "address-family l2vpn evpn",
7880 "Enter Address Family command mode\n"
7881 "Address Family\n"
7882 "Address Family modifier\n")
7883 {
7884 VTY_DECLVAR_CONTEXT(bgp, bgp);
7885 vty->node = BGP_EVPN_NODE;
7886 return CMD_SUCCESS;
7887 }
7888
7889 DEFUN_NOSH (exit_address_family,
7890 exit_address_family_cmd,
7891 "exit-address-family",
7892 "Exit from Address Family configuration mode\n")
7893 {
7894 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
7895 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
7896 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
7897 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
7898 || vty->node == BGP_EVPN_NODE
7899 || vty->node == BGP_FLOWSPECV4_NODE
7900 || vty->node == BGP_FLOWSPECV6_NODE)
7901 vty->node = BGP_NODE;
7902 return CMD_SUCCESS;
7903 }
7904
7905 /* Recalculate bestpath and re-advertise a prefix */
7906 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
7907 const char *ip_str, afi_t afi, safi_t safi,
7908 struct prefix_rd *prd)
7909 {
7910 int ret;
7911 struct prefix match;
7912 struct bgp_node *rn;
7913 struct bgp_node *rm;
7914 struct bgp *bgp;
7915 struct bgp_table *table;
7916 struct bgp_table *rib;
7917
7918 /* BGP structure lookup. */
7919 if (view_name) {
7920 bgp = bgp_lookup_by_name(view_name);
7921 if (bgp == NULL) {
7922 vty_out(vty, "%% Can't find BGP instance %s\n",
7923 view_name);
7924 return CMD_WARNING;
7925 }
7926 } else {
7927 bgp = bgp_get_default();
7928 if (bgp == NULL) {
7929 vty_out(vty, "%% No BGP process is configured\n");
7930 return CMD_WARNING;
7931 }
7932 }
7933
7934 /* Check IP address argument. */
7935 ret = str2prefix(ip_str, &match);
7936 if (!ret) {
7937 vty_out(vty, "%% address is malformed\n");
7938 return CMD_WARNING;
7939 }
7940
7941 match.family = afi2family(afi);
7942 rib = bgp->rib[afi][safi];
7943
7944 if (safi == SAFI_MPLS_VPN) {
7945 for (rn = bgp_table_top(rib); rn; rn = bgp_route_next(rn)) {
7946 if (prd && memcmp(rn->p.u.val, prd->val, 8) != 0)
7947 continue;
7948
7949 table = bgp_node_get_bgp_table_info(rn);
7950 if (table != NULL) {
7951
7952 if ((rm = bgp_node_match(table, &match))
7953 != NULL) {
7954 if (rm->p.prefixlen
7955 == match.prefixlen) {
7956 SET_FLAG(rm->flags,
7957 BGP_NODE_USER_CLEAR);
7958 bgp_process(bgp, rm, afi, safi);
7959 }
7960 bgp_unlock_node(rm);
7961 }
7962 }
7963 }
7964 } else {
7965 if ((rn = bgp_node_match(rib, &match)) != NULL) {
7966 if (rn->p.prefixlen == match.prefixlen) {
7967 SET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
7968 bgp_process(bgp, rn, afi, safi);
7969 }
7970 bgp_unlock_node(rn);
7971 }
7972 }
7973
7974 return CMD_SUCCESS;
7975 }
7976
7977 /* one clear bgp command to rule them all */
7978 DEFUN (clear_ip_bgp_all,
7979 clear_ip_bgp_all_cmd,
7980 "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>]",
7981 CLEAR_STR
7982 IP_STR
7983 BGP_STR
7984 BGP_INSTANCE_HELP_STR
7985 BGP_AFI_HELP_STR
7986 "Address Family\n"
7987 BGP_SAFI_WITH_LABEL_HELP_STR
7988 "Address Family modifier\n"
7989 "Clear all peers\n"
7990 "BGP IPv4 neighbor to clear\n"
7991 "BGP IPv6 neighbor to clear\n"
7992 "BGP neighbor on interface to clear\n"
7993 "Clear peers with the AS number\n"
7994 "Clear all external peers\n"
7995 "Clear all members of peer-group\n"
7996 "BGP peer-group name\n"
7997 BGP_SOFT_STR
7998 BGP_SOFT_IN_STR
7999 BGP_SOFT_OUT_STR
8000 BGP_SOFT_IN_STR
8001 "Push out prefix-list ORF and do inbound soft reconfig\n"
8002 BGP_SOFT_OUT_STR)
8003 {
8004 char *vrf = NULL;
8005
8006 afi_t afi = AFI_UNSPEC;
8007 safi_t safi = SAFI_UNSPEC;
8008 enum clear_sort clr_sort = clear_peer;
8009 enum bgp_clear_type clr_type;
8010 char *clr_arg = NULL;
8011
8012 int idx = 0;
8013
8014 /* clear [ip] bgp */
8015 if (argv_find(argv, argc, "ip", &idx))
8016 afi = AFI_IP;
8017
8018 /* [<vrf> VIEWVRFNAME] */
8019 if (argv_find(argv, argc, "vrf", &idx)) {
8020 vrf = argv[idx + 1]->arg;
8021 idx += 2;
8022 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
8023 vrf = NULL;
8024 } else if (argv_find(argv, argc, "view", &idx)) {
8025 /* [<view> VIEWVRFNAME] */
8026 vrf = argv[idx + 1]->arg;
8027 idx += 2;
8028 }
8029 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
8030 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
8031 argv_find_and_parse_safi(argv, argc, &idx, &safi);
8032
8033 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
8034 if (argv_find(argv, argc, "*", &idx)) {
8035 clr_sort = clear_all;
8036 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
8037 clr_sort = clear_peer;
8038 clr_arg = argv[idx]->arg;
8039 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
8040 clr_sort = clear_peer;
8041 clr_arg = argv[idx]->arg;
8042 } else if (argv_find(argv, argc, "peer-group", &idx)) {
8043 clr_sort = clear_group;
8044 idx++;
8045 clr_arg = argv[idx]->arg;
8046 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
8047 clr_sort = clear_peer;
8048 clr_arg = argv[idx]->arg;
8049 } else if (argv_find(argv, argc, "WORD", &idx)) {
8050 clr_sort = clear_peer;
8051 clr_arg = argv[idx]->arg;
8052 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
8053 clr_sort = clear_as;
8054 clr_arg = argv[idx]->arg;
8055 } else if (argv_find(argv, argc, "external", &idx)) {
8056 clr_sort = clear_external;
8057 }
8058
8059 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
8060 if (argv_find(argv, argc, "soft", &idx)) {
8061 if (argv_find(argv, argc, "in", &idx)
8062 || argv_find(argv, argc, "out", &idx))
8063 clr_type = strmatch(argv[idx]->text, "in")
8064 ? BGP_CLEAR_SOFT_IN
8065 : BGP_CLEAR_SOFT_OUT;
8066 else
8067 clr_type = BGP_CLEAR_SOFT_BOTH;
8068 } else if (argv_find(argv, argc, "in", &idx)) {
8069 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
8070 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
8071 : BGP_CLEAR_SOFT_IN;
8072 } else if (argv_find(argv, argc, "out", &idx)) {
8073 clr_type = BGP_CLEAR_SOFT_OUT;
8074 } else
8075 clr_type = BGP_CLEAR_SOFT_NONE;
8076
8077 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
8078 }
8079
8080 DEFUN (clear_ip_bgp_prefix,
8081 clear_ip_bgp_prefix_cmd,
8082 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
8083 CLEAR_STR
8084 IP_STR
8085 BGP_STR
8086 BGP_INSTANCE_HELP_STR
8087 "Clear bestpath and re-advertise\n"
8088 "IPv4 prefix\n")
8089 {
8090 char *vrf = NULL;
8091 char *prefix = NULL;
8092
8093 int idx = 0;
8094
8095 /* [<view|vrf> VIEWVRFNAME] */
8096 if (argv_find(argv, argc, "vrf", &idx)) {
8097 vrf = argv[idx + 1]->arg;
8098 idx += 2;
8099 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
8100 vrf = NULL;
8101 } else if (argv_find(argv, argc, "view", &idx)) {
8102 /* [<view> VIEWVRFNAME] */
8103 vrf = argv[idx + 1]->arg;
8104 idx += 2;
8105 }
8106
8107 prefix = argv[argc - 1]->arg;
8108
8109 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
8110 }
8111
8112 DEFUN (clear_bgp_ipv6_safi_prefix,
8113 clear_bgp_ipv6_safi_prefix_cmd,
8114 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
8115 CLEAR_STR
8116 IP_STR
8117 BGP_STR
8118 "Address Family\n"
8119 BGP_SAFI_HELP_STR
8120 "Clear bestpath and re-advertise\n"
8121 "IPv6 prefix\n")
8122 {
8123 int idx_safi = 0;
8124 int idx_ipv6_prefix = 0;
8125 safi_t safi = SAFI_UNICAST;
8126 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
8127 argv[idx_ipv6_prefix]->arg : NULL;
8128
8129 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
8130 return bgp_clear_prefix(
8131 vty, NULL, prefix, AFI_IP6,
8132 safi, NULL);
8133 }
8134
8135 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
8136 clear_bgp_instance_ipv6_safi_prefix_cmd,
8137 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
8138 CLEAR_STR
8139 IP_STR
8140 BGP_STR
8141 BGP_INSTANCE_HELP_STR
8142 "Address Family\n"
8143 BGP_SAFI_HELP_STR
8144 "Clear bestpath and re-advertise\n"
8145 "IPv6 prefix\n")
8146 {
8147 int idx_safi = 0;
8148 int idx_vrfview = 0;
8149 int idx_ipv6_prefix = 0;
8150 safi_t safi = SAFI_UNICAST;
8151 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
8152 argv[idx_ipv6_prefix]->arg : NULL;
8153 char *vrfview = NULL;
8154
8155 /* [<view|vrf> VIEWVRFNAME] */
8156 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
8157 vrfview = argv[idx_vrfview + 1]->arg;
8158 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
8159 vrfview = NULL;
8160 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
8161 /* [<view> VIEWVRFNAME] */
8162 vrfview = argv[idx_vrfview + 1]->arg;
8163 }
8164 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
8165
8166 return bgp_clear_prefix(
8167 vty, vrfview, prefix,
8168 AFI_IP6, safi, NULL);
8169 }
8170
8171 DEFUN (show_bgp_views,
8172 show_bgp_views_cmd,
8173 "show [ip] bgp views",
8174 SHOW_STR
8175 IP_STR
8176 BGP_STR
8177 "Show the defined BGP views\n")
8178 {
8179 struct list *inst = bm->bgp;
8180 struct listnode *node;
8181 struct bgp *bgp;
8182
8183 vty_out(vty, "Defined BGP views:\n");
8184 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
8185 /* Skip VRFs. */
8186 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
8187 continue;
8188 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
8189 bgp->as);
8190 }
8191
8192 return CMD_SUCCESS;
8193 }
8194
8195 DEFUN (show_bgp_vrfs,
8196 show_bgp_vrfs_cmd,
8197 "show [ip] bgp vrfs [json]",
8198 SHOW_STR
8199 IP_STR
8200 BGP_STR
8201 "Show BGP VRFs\n"
8202 JSON_STR)
8203 {
8204 char buf[ETHER_ADDR_STRLEN];
8205 struct list *inst = bm->bgp;
8206 struct listnode *node;
8207 struct bgp *bgp;
8208 bool uj = use_json(argc, argv);
8209 json_object *json = NULL;
8210 json_object *json_vrfs = NULL;
8211 int count = 0;
8212
8213 if (uj) {
8214 json = json_object_new_object();
8215 json_vrfs = json_object_new_object();
8216 }
8217
8218 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
8219 const char *name, *type;
8220 struct peer *peer;
8221 struct listnode *node2, *nnode2;
8222 int peers_cfg, peers_estb;
8223 json_object *json_vrf = NULL;
8224
8225 /* Skip Views. */
8226 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
8227 continue;
8228
8229 count++;
8230 if (!uj && count == 1) {
8231 vty_out(vty,
8232 "%4s %-5s %-16s %9s %10s %-37s\n",
8233 "Type", "Id", "routerId", "#PeersCfg",
8234 "#PeersEstb", "Name");
8235 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
8236 "L3-VNI", "RouterMAC", "Interface");
8237 }
8238
8239 peers_cfg = peers_estb = 0;
8240 if (uj)
8241 json_vrf = json_object_new_object();
8242
8243
8244 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
8245 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
8246 continue;
8247 peers_cfg++;
8248 if (peer->status == Established)
8249 peers_estb++;
8250 }
8251
8252 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
8253 name = VRF_DEFAULT_NAME;
8254 type = "DFLT";
8255 } else {
8256 name = bgp->name;
8257 type = "VRF";
8258 }
8259
8260
8261 if (uj) {
8262 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
8263 ? -1
8264 : (int64_t)bgp->vrf_id;
8265 json_object_string_add(json_vrf, "type", type);
8266 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
8267 json_object_string_add(json_vrf, "routerId",
8268 inet_ntoa(bgp->router_id));
8269 json_object_int_add(json_vrf, "numConfiguredPeers",
8270 peers_cfg);
8271 json_object_int_add(json_vrf, "numEstablishedPeers",
8272 peers_estb);
8273
8274 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
8275 json_object_string_add(
8276 json_vrf, "rmac",
8277 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
8278 json_object_string_add(json_vrf, "interface",
8279 ifindex2ifname(bgp->l3vni_svi_ifindex,
8280 bgp->vrf_id));
8281 json_object_object_add(json_vrfs, name, json_vrf);
8282 } else {
8283 vty_out(vty,
8284 "%4s %-5d %-16s %-9u %-10u %-37s\n",
8285 type,
8286 bgp->vrf_id == VRF_UNKNOWN ? -1
8287 : (int)bgp->vrf_id,
8288 inet_ntoa(bgp->router_id), peers_cfg,
8289 peers_estb, name);
8290 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
8291 bgp->l3vni,
8292 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
8293 ifindex2ifname(bgp->l3vni_svi_ifindex,
8294 bgp->vrf_id));
8295 }
8296 }
8297
8298 if (uj) {
8299 json_object_object_add(json, "vrfs", json_vrfs);
8300
8301 json_object_int_add(json, "totalVrfs", count);
8302
8303 vty_out(vty, "%s\n", json_object_to_json_string_ext(
8304 json, JSON_C_TO_STRING_PRETTY));
8305 json_object_free(json);
8306 } else {
8307 if (count)
8308 vty_out(vty,
8309 "\nTotal number of VRFs (including default): %d\n",
8310 count);
8311 }
8312
8313 return CMD_SUCCESS;
8314 }
8315
8316 DEFUN (show_bgp_mac_hash,
8317 show_bgp_mac_hash_cmd,
8318 "show bgp mac hash",
8319 SHOW_STR
8320 BGP_STR
8321 "Mac Address\n"
8322 "Mac Address database\n")
8323 {
8324 bgp_mac_dump_table(vty);
8325
8326 return CMD_SUCCESS;
8327 }
8328
8329 static void show_tip_entry(struct hash_bucket *bucket, void *args)
8330 {
8331 struct vty *vty = (struct vty *)args;
8332 struct tip_addr *tip = (struct tip_addr *)bucket->data;
8333
8334 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(tip->addr),
8335 tip->refcnt);
8336 }
8337
8338 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
8339 {
8340 vty_out(vty, "self nexthop database:\n");
8341 bgp_nexthop_show_address_hash(vty, bgp);
8342
8343 vty_out(vty, "Tunnel-ip database:\n");
8344 hash_iterate(bgp->tip_hash,
8345 (void (*)(struct hash_bucket *, void *))show_tip_entry,
8346 vty);
8347 }
8348
8349 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
8350 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
8351 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
8352 "martian next-hops\n"
8353 "martian next-hop database\n")
8354 {
8355 struct bgp *bgp = NULL;
8356 int idx = 0;
8357 char *name = NULL;
8358
8359 /* [<vrf> VIEWVRFNAME] */
8360 if (argv_find(argv, argc, "vrf", &idx)) {
8361 name = argv[idx + 1]->arg;
8362 if (name && strmatch(name, VRF_DEFAULT_NAME))
8363 name = NULL;
8364 } else if (argv_find(argv, argc, "view", &idx))
8365 /* [<view> VIEWVRFNAME] */
8366 name = argv[idx + 1]->arg;
8367 if (name)
8368 bgp = bgp_lookup_by_name(name);
8369 else
8370 bgp = bgp_get_default();
8371
8372 if (!bgp) {
8373 vty_out(vty, "%% No BGP process is configured\n");
8374 return CMD_WARNING;
8375 }
8376 bgp_show_martian_nexthops(vty, bgp);
8377
8378 return CMD_SUCCESS;
8379 }
8380
8381 DEFUN (show_bgp_memory,
8382 show_bgp_memory_cmd,
8383 "show [ip] bgp memory",
8384 SHOW_STR
8385 IP_STR
8386 BGP_STR
8387 "Global BGP memory statistics\n")
8388 {
8389 char memstrbuf[MTYPE_MEMSTR_LEN];
8390 unsigned long count;
8391
8392 /* RIB related usage stats */
8393 count = mtype_stats_alloc(MTYPE_BGP_NODE);
8394 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
8395 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8396 count * sizeof(struct bgp_node)));
8397
8398 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
8399 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
8400 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8401 count * sizeof(struct bgp_path_info)));
8402 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
8403 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
8404 count,
8405 mtype_memstr(
8406 memstrbuf, sizeof(memstrbuf),
8407 count * sizeof(struct bgp_path_info_extra)));
8408
8409 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
8410 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
8411 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8412 count * sizeof(struct bgp_static)));
8413
8414 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
8415 vty_out(vty, "%ld Packets, using %s of memory\n", count,
8416 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8417 count * sizeof(struct bpacket)));
8418
8419 /* Adj-In/Out */
8420 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
8421 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
8422 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8423 count * sizeof(struct bgp_adj_in)));
8424 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
8425 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
8426 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8427 count * sizeof(struct bgp_adj_out)));
8428
8429 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
8430 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
8431 count,
8432 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8433 count * sizeof(struct bgp_nexthop_cache)));
8434
8435 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
8436 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
8437 count,
8438 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8439 count * sizeof(struct bgp_damp_info)));
8440
8441 /* Attributes */
8442 count = attr_count();
8443 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
8444 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8445 count * sizeof(struct attr)));
8446
8447 if ((count = attr_unknown_count()))
8448 vty_out(vty, "%ld unknown attributes\n", count);
8449
8450 /* AS_PATH attributes */
8451 count = aspath_count();
8452 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
8453 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8454 count * sizeof(struct aspath)));
8455
8456 count = mtype_stats_alloc(MTYPE_AS_SEG);
8457 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
8458 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8459 count * sizeof(struct assegment)));
8460
8461 /* Other attributes */
8462 if ((count = community_count()))
8463 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
8464 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
8465 count * sizeof(struct community)));
8466 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
8467 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
8468 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
8469 count * sizeof(struct ecommunity)));
8470 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
8471 vty_out(vty,
8472 "%ld BGP large-community entries, using %s of memory\n",
8473 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
8474 count * sizeof(struct lcommunity)));
8475
8476 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
8477 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
8478 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8479 count * sizeof(struct cluster_list)));
8480
8481 /* Peer related usage */
8482 count = mtype_stats_alloc(MTYPE_BGP_PEER);
8483 vty_out(vty, "%ld peers, using %s of memory\n", count,
8484 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8485 count * sizeof(struct peer)));
8486
8487 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
8488 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
8489 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8490 count * sizeof(struct peer_group)));
8491
8492 /* Other */
8493 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
8494 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
8495 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
8496 count * sizeof(regex_t)));
8497 return CMD_SUCCESS;
8498 }
8499
8500 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
8501 {
8502 json_object *bestpath = json_object_new_object();
8503
8504 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
8505 json_object_string_add(bestpath, "asPath", "ignore");
8506
8507 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
8508 json_object_string_add(bestpath, "asPath", "confed");
8509
8510 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
8511 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
8512 json_object_string_add(bestpath, "multiPathRelax",
8513 "as-set");
8514 else
8515 json_object_string_add(bestpath, "multiPathRelax",
8516 "true");
8517 } else
8518 json_object_string_add(bestpath, "multiPathRelax", "false");
8519
8520 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
8521 json_object_string_add(bestpath, "compareRouterId", "true");
8522 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
8523 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
8524 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
8525 json_object_string_add(bestpath, "med", "confed");
8526 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
8527 json_object_string_add(bestpath, "med",
8528 "missing-as-worst");
8529 else
8530 json_object_string_add(bestpath, "med", "true");
8531 }
8532
8533 json_object_object_add(json, "bestPath", bestpath);
8534 }
8535
8536 /* Print the error code/subcode for why the peer is down */
8537 static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
8538 json_object *json_peer, bool use_json)
8539 {
8540 const char *code_str;
8541 const char *subcode_str;
8542
8543 if (use_json) {
8544 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
8545 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
8546 char errorcodesubcode_hexstr[5];
8547 char errorcodesubcode_str[256];
8548
8549 code_str = bgp_notify_code_str(peer->notify.code);
8550 subcode_str = bgp_notify_subcode_str(
8551 peer->notify.code,
8552 peer->notify.subcode);
8553
8554 sprintf(errorcodesubcode_hexstr, "%02X%02X",
8555 peer->notify.code, peer->notify.subcode);
8556 json_object_string_add(json_peer,
8557 "lastErrorCodeSubcode",
8558 errorcodesubcode_hexstr);
8559 snprintf(errorcodesubcode_str, 255, "%s%s",
8560 code_str, subcode_str);
8561 json_object_string_add(json_peer,
8562 "lastNotificationReason",
8563 errorcodesubcode_str);
8564 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
8565 && peer->notify.code == BGP_NOTIFY_CEASE
8566 && (peer->notify.subcode
8567 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
8568 || peer->notify.subcode
8569 == BGP_NOTIFY_CEASE_ADMIN_RESET)
8570 && peer->notify.length) {
8571 char msgbuf[1024];
8572 const char *msg_str;
8573
8574 msg_str = bgp_notify_admin_message(
8575 msgbuf, sizeof(msgbuf),
8576 (uint8_t *)peer->notify.data,
8577 peer->notify.length);
8578 if (msg_str)
8579 json_object_string_add(
8580 json_peer,
8581 "lastShutdownDescription",
8582 msg_str);
8583 }
8584
8585 }
8586 json_object_string_add(json_peer, "lastResetDueTo",
8587 peer_down_str[(int)peer->last_reset]);
8588 json_object_int_add(json_peer, "lastResetCode",
8589 peer->last_reset);
8590 } else {
8591 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
8592 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
8593 code_str = bgp_notify_code_str(peer->notify.code);
8594 subcode_str =
8595 bgp_notify_subcode_str(peer->notify.code,
8596 peer->notify.subcode);
8597 vty_out(vty, " Notification %s (%s%s)\n",
8598 peer->last_reset == PEER_DOWN_NOTIFY_SEND
8599 ? "sent"
8600 : "received",
8601 code_str, subcode_str);
8602 } else {
8603 vty_out(vty, " %s\n",
8604 peer_down_str[(int)peer->last_reset]);
8605 }
8606 }
8607 }
8608
8609 static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
8610 safi_t safi)
8611 {
8612 return ((peer->status != Established) ||
8613 !peer->afc_recv[afi][safi]);
8614 }
8615
8616 static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
8617 struct peer *peer, json_object *json_peer,
8618 int max_neighbor_width, bool use_json)
8619 {
8620 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
8621 int len;
8622
8623 if (use_json) {
8624 if (peer_dynamic_neighbor(peer))
8625 json_object_boolean_true_add(json_peer,
8626 "dynamicPeer");
8627 if (peer->hostname)
8628 json_object_string_add(json_peer, "hostname",
8629 peer->hostname);
8630
8631 if (peer->domainname)
8632 json_object_string_add(json_peer, "domainname",
8633 peer->domainname);
8634 json_object_int_add(json_peer, "connectionsEstablished",
8635 peer->established);
8636 json_object_int_add(json_peer, "connectionsDropped",
8637 peer->dropped);
8638 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
8639 use_json, json_peer);
8640 if (peer->status == Established)
8641 json_object_string_add(json_peer, "lastResetDueTo",
8642 "AFI/SAFI Not Negotiated");
8643 else
8644 bgp_show_peer_reset(NULL, peer, json_peer, true);
8645 } else {
8646 dn_flag[1] = '\0';
8647 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
8648 if (peer->hostname
8649 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
8650 len = vty_out(vty, "%s%s(%s)", dn_flag,
8651 peer->hostname, peer->host);
8652 else
8653 len = vty_out(vty, "%s%s", dn_flag, peer->host);
8654
8655 /* pad the neighbor column with spaces */
8656 if (len < max_neighbor_width)
8657 vty_out(vty, "%*s", max_neighbor_width - len,
8658 " ");
8659 vty_out(vty, "%7d %7d %9s", peer->established,
8660 peer->dropped,
8661 peer_uptime(peer->uptime, timebuf,
8662 BGP_UPTIME_LEN, 0, NULL));
8663 if (peer->status == Established)
8664 vty_out(vty, " AFI/SAFI Not Negotiated\n");
8665 else
8666 bgp_show_peer_reset(vty, peer, NULL,
8667 false);
8668 }
8669 }
8670
8671
8672 /* Show BGP peer's summary information. */
8673 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
8674 bool show_failed, bool use_json)
8675 {
8676 struct peer *peer;
8677 struct listnode *node, *nnode;
8678 unsigned int count = 0, dn_count = 0;
8679 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
8680 char neighbor_buf[VTY_BUFSIZ];
8681 int neighbor_col_default_width = 16;
8682 int len, failed_count = 0;
8683 int max_neighbor_width = 0;
8684 int pfx_rcd_safi;
8685 json_object *json = NULL;
8686 json_object *json_peer = NULL;
8687 json_object *json_peers = NULL;
8688 struct peer_af *paf;
8689
8690 /* labeled-unicast routes are installed in the unicast table so in order
8691 * to
8692 * display the correct PfxRcd value we must look at SAFI_UNICAST
8693 */
8694
8695 if (safi == SAFI_LABELED_UNICAST)
8696 pfx_rcd_safi = SAFI_UNICAST;
8697 else
8698 pfx_rcd_safi = safi;
8699
8700 if (use_json) {
8701 json = json_object_new_object();
8702 json_peers = json_object_new_object();
8703 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8704 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
8705 continue;
8706
8707 if (peer->afc[afi][safi]) {
8708 /* See if we have at least a single failed peer */
8709 if (bgp_has_peer_failed(peer, afi, safi))
8710 failed_count++;
8711 count++;
8712 }
8713 if (peer_dynamic_neighbor(peer))
8714 dn_count++;
8715 }
8716
8717 } else {
8718 /* Loop over all neighbors that will be displayed to determine
8719 * how many
8720 * characters are needed for the Neighbor column
8721 */
8722 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8723 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
8724 continue;
8725
8726 if (peer->afc[afi][safi]) {
8727 memset(dn_flag, '\0', sizeof(dn_flag));
8728 if (peer_dynamic_neighbor(peer))
8729 dn_flag[0] = '*';
8730
8731 if (peer->hostname
8732 && CHECK_FLAG(bgp->flags,
8733 BGP_FLAG_SHOW_HOSTNAME))
8734 sprintf(neighbor_buf, "%s%s(%s) ",
8735 dn_flag, peer->hostname,
8736 peer->host);
8737 else
8738 sprintf(neighbor_buf, "%s%s ", dn_flag,
8739 peer->host);
8740
8741 len = strlen(neighbor_buf);
8742
8743 if (len > max_neighbor_width)
8744 max_neighbor_width = len;
8745
8746 /* See if we have at least a single failed peer */
8747 if (bgp_has_peer_failed(peer, afi, safi))
8748 failed_count++;
8749 count++;
8750 }
8751 }
8752
8753 /* Originally we displayed the Neighbor column as 16
8754 * characters wide so make that the default
8755 */
8756 if (max_neighbor_width < neighbor_col_default_width)
8757 max_neighbor_width = neighbor_col_default_width;
8758 }
8759
8760 if (show_failed && !failed_count) {
8761 if (use_json) {
8762 json_object_int_add(json, "failedPeersCount", 0);
8763 json_object_int_add(json, "dynamicPeers", dn_count);
8764 json_object_int_add(json, "totalPeers", count);
8765
8766 vty_out(vty, "%s\n", json_object_to_json_string_ext(
8767 json, JSON_C_TO_STRING_PRETTY));
8768 json_object_free(json);
8769 } else {
8770 vty_out(vty, "%% No failed BGP neighbors found\n");
8771 vty_out(vty, "\nTotal number of neighbors %d\n", count);
8772 }
8773 return CMD_SUCCESS;
8774 }
8775
8776 count = 0; /* Reset the value as its used again */
8777 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8778 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
8779 continue;
8780
8781 if (!peer->afc[afi][safi])
8782 continue;
8783
8784 if (!count) {
8785 unsigned long ents;
8786 char memstrbuf[MTYPE_MEMSTR_LEN];
8787 int64_t vrf_id_ui;
8788
8789 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
8790 ? -1
8791 : (int64_t)bgp->vrf_id;
8792
8793 /* Usage summary and header */
8794 if (use_json) {
8795 json_object_string_add(
8796 json, "routerId",
8797 inet_ntoa(bgp->router_id));
8798 json_object_int_add(json, "as", bgp->as);
8799 json_object_int_add(json, "vrfId", vrf_id_ui);
8800 json_object_string_add(
8801 json, "vrfName",
8802 (bgp->inst_type
8803 == BGP_INSTANCE_TYPE_DEFAULT)
8804 ? VRF_DEFAULT_NAME
8805 : bgp->name);
8806 } else {
8807 vty_out(vty,
8808 "BGP router identifier %s, local AS number %u vrf-id %d",
8809 inet_ntoa(bgp->router_id), bgp->as,
8810 bgp->vrf_id == VRF_UNKNOWN
8811 ? -1
8812 : (int)bgp->vrf_id);
8813 vty_out(vty, "\n");
8814 }
8815
8816 if (bgp_update_delay_configured(bgp)) {
8817 if (use_json) {
8818 json_object_int_add(
8819 json, "updateDelayLimit",
8820 bgp->v_update_delay);
8821
8822 if (bgp->v_update_delay
8823 != bgp->v_establish_wait)
8824 json_object_int_add(
8825 json,
8826 "updateDelayEstablishWait",
8827 bgp->v_establish_wait);
8828
8829 if (bgp_update_delay_active(bgp)) {
8830 json_object_string_add(
8831 json,
8832 "updateDelayFirstNeighbor",
8833 bgp->update_delay_begin_time);
8834 json_object_boolean_true_add(
8835 json,
8836 "updateDelayInProgress");
8837 } else {
8838 if (bgp->update_delay_over) {
8839 json_object_string_add(
8840 json,
8841 "updateDelayFirstNeighbor",
8842 bgp->update_delay_begin_time);
8843 json_object_string_add(
8844 json,
8845 "updateDelayBestpathResumed",
8846 bgp->update_delay_end_time);
8847 json_object_string_add(
8848 json,
8849 "updateDelayZebraUpdateResume",
8850 bgp->update_delay_zebra_resume_time);
8851 json_object_string_add(
8852 json,
8853 "updateDelayPeerUpdateResume",
8854 bgp->update_delay_peers_resume_time);
8855 }
8856 }
8857 } else {
8858 vty_out(vty,
8859 "Read-only mode update-delay limit: %d seconds\n",
8860 bgp->v_update_delay);
8861 if (bgp->v_update_delay
8862 != bgp->v_establish_wait)
8863 vty_out(vty,
8864 " Establish wait: %d seconds\n",
8865 bgp->v_establish_wait);
8866
8867 if (bgp_update_delay_active(bgp)) {
8868 vty_out(vty,
8869 " First neighbor established: %s\n",
8870 bgp->update_delay_begin_time);
8871 vty_out(vty,
8872 " Delay in progress\n");
8873 } else {
8874 if (bgp->update_delay_over) {
8875 vty_out(vty,
8876 " First neighbor established: %s\n",
8877 bgp->update_delay_begin_time);
8878 vty_out(vty,
8879 " Best-paths resumed: %s\n",
8880 bgp->update_delay_end_time);
8881 vty_out(vty,
8882 " zebra update resumed: %s\n",
8883 bgp->update_delay_zebra_resume_time);
8884 vty_out(vty,
8885 " peers update resumed: %s\n",
8886 bgp->update_delay_peers_resume_time);
8887 }
8888 }
8889 }
8890 }
8891
8892 if (use_json) {
8893 if (bgp_maxmed_onstartup_configured(bgp)
8894 && bgp->maxmed_active)
8895 json_object_boolean_true_add(
8896 json, "maxMedOnStartup");
8897 if (bgp->v_maxmed_admin)
8898 json_object_boolean_true_add(
8899 json, "maxMedAdministrative");
8900
8901 json_object_int_add(
8902 json, "tableVersion",
8903 bgp_table_version(bgp->rib[afi][safi]));
8904
8905 ents = bgp_table_count(bgp->rib[afi][safi]);
8906 json_object_int_add(json, "ribCount", ents);
8907 json_object_int_add(
8908 json, "ribMemory",
8909 ents * sizeof(struct bgp_node));
8910
8911 ents = bgp->af_peer_count[afi][safi];
8912 json_object_int_add(json, "peerCount", ents);
8913 json_object_int_add(json, "peerMemory",
8914 ents * sizeof(struct peer));
8915
8916 if ((ents = listcount(bgp->group))) {
8917 json_object_int_add(
8918 json, "peerGroupCount", ents);
8919 json_object_int_add(
8920 json, "peerGroupMemory",
8921 ents * sizeof(struct
8922 peer_group));
8923 }
8924
8925 if (CHECK_FLAG(bgp->af_flags[afi][safi],
8926 BGP_CONFIG_DAMPENING))
8927 json_object_boolean_true_add(
8928 json, "dampeningEnabled");
8929 } else {
8930 if (bgp_maxmed_onstartup_configured(bgp)
8931 && bgp->maxmed_active)
8932 vty_out(vty,
8933 "Max-med on-startup active\n");
8934 if (bgp->v_maxmed_admin)
8935 vty_out(vty,
8936 "Max-med administrative active\n");
8937
8938 vty_out(vty, "BGP table version %" PRIu64 "\n",
8939 bgp_table_version(bgp->rib[afi][safi]));
8940
8941 ents = bgp_table_count(bgp->rib[afi][safi]);
8942 vty_out(vty,
8943 "RIB entries %ld, using %s of memory\n",
8944 ents,
8945 mtype_memstr(memstrbuf,
8946 sizeof(memstrbuf),
8947 ents * sizeof(struct
8948 bgp_node)));
8949
8950 /* Peer related usage */
8951 ents = bgp->af_peer_count[afi][safi];
8952 vty_out(vty, "Peers %ld, using %s of memory\n",
8953 ents,
8954 mtype_memstr(
8955 memstrbuf, sizeof(memstrbuf),
8956 ents * sizeof(struct peer)));
8957
8958 if ((ents = listcount(bgp->group)))
8959 vty_out(vty,
8960 "Peer groups %ld, using %s of memory\n",
8961 ents,
8962 mtype_memstr(
8963 memstrbuf,
8964 sizeof(memstrbuf),
8965 ents * sizeof(struct
8966 peer_group)));
8967
8968 if (CHECK_FLAG(bgp->af_flags[afi][safi],
8969 BGP_CONFIG_DAMPENING))
8970 vty_out(vty, "Dampening enabled.\n");
8971 vty_out(vty, "\n");
8972
8973 /* Subtract 8 here because 'Neighbor' is
8974 * 8 characters */
8975 vty_out(vty, "Neighbor");
8976 vty_out(vty, "%*s", max_neighbor_width - 8,
8977 " ");
8978 if (show_failed)
8979 vty_out(vty, "EstdCnt DropCnt ResetTime Reason\n");
8980 else
8981 vty_out(vty,
8982 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd\n");
8983 }
8984 }
8985
8986 count++;
8987 /* Works for both failed & successful cases */
8988 if (peer_dynamic_neighbor(peer))
8989 dn_count++;
8990
8991 if (use_json) {
8992 json_peer = NULL;
8993
8994 if (show_failed &&
8995 bgp_has_peer_failed(peer, afi, safi)) {
8996 json_peer = json_object_new_object();
8997 bgp_show_failed_summary(vty, bgp, peer,
8998 json_peer, 0, use_json);
8999 } else if (!show_failed) {
9000 json_peer = json_object_new_object();
9001 if (peer_dynamic_neighbor(peer)) {
9002 json_object_boolean_true_add(json_peer,
9003 "dynamicPeer");
9004 }
9005
9006 if (peer->hostname)
9007 json_object_string_add(json_peer, "hostname",
9008 peer->hostname);
9009
9010 if (peer->domainname)
9011 json_object_string_add(json_peer, "domainname",
9012 peer->domainname);
9013
9014 json_object_int_add(json_peer, "remoteAs", peer->as);
9015 json_object_int_add(json_peer, "version", 4);
9016 json_object_int_add(json_peer, "msgRcvd",
9017 PEER_TOTAL_RX(peer));
9018 json_object_int_add(json_peer, "msgSent",
9019 PEER_TOTAL_TX(peer));
9020
9021 json_object_int_add(json_peer, "tableVersion",
9022 peer->version[afi][safi]);
9023 json_object_int_add(json_peer, "outq",
9024 peer->obuf->count);
9025 json_object_int_add(json_peer, "inq", 0);
9026 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
9027 use_json, json_peer);
9028
9029 /*
9030 * Adding "pfxRcd" field to match with the corresponding
9031 * CLI. "prefixReceivedCount" will be deprecated in
9032 * future.
9033 */
9034 json_object_int_add(json_peer, "prefixReceivedCount",
9035 peer->pcount[afi][pfx_rcd_safi]);
9036 json_object_int_add(json_peer, "pfxRcd",
9037 peer->pcount[afi][pfx_rcd_safi]);
9038
9039 paf = peer_af_find(peer, afi, pfx_rcd_safi);
9040 if (paf && PAF_SUBGRP(paf))
9041 json_object_int_add(json_peer,
9042 "pfxSnt",
9043 (PAF_SUBGRP(paf))->scount);
9044 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
9045 json_object_string_add(json_peer, "state",
9046 "Idle (Admin)");
9047 else if (peer->afc_recv[afi][safi])
9048 json_object_string_add(
9049 json_peer, "state",
9050 lookup_msg(bgp_status_msg, peer->status,
9051 NULL));
9052 else if (CHECK_FLAG(peer->sflags,
9053 PEER_STATUS_PREFIX_OVERFLOW))
9054 json_object_string_add(json_peer, "state",
9055 "Idle (PfxCt)");
9056 else
9057 json_object_string_add(
9058 json_peer, "state",
9059 lookup_msg(bgp_status_msg, peer->status,
9060 NULL));
9061 json_object_int_add(json_peer, "connectionsEstablished",
9062 peer->established);
9063 json_object_int_add(json_peer, "connectionsDropped",
9064 peer->dropped);
9065 }
9066 /* Avoid creating empty peer dicts in JSON */
9067 if (json_peer == NULL)
9068 continue;
9069
9070 if (peer->conf_if)
9071 json_object_string_add(json_peer, "idType",
9072 "interface");
9073 else if (peer->su.sa.sa_family == AF_INET)
9074 json_object_string_add(json_peer, "idType",
9075 "ipv4");
9076 else if (peer->su.sa.sa_family == AF_INET6)
9077 json_object_string_add(json_peer, "idType",
9078 "ipv6");
9079 json_object_object_add(json_peers, peer->host,
9080 json_peer);
9081 } else {
9082 if (show_failed &&
9083 bgp_has_peer_failed(peer, afi, safi)) {
9084 bgp_show_failed_summary(vty, bgp, peer, NULL,
9085 max_neighbor_width,
9086 use_json);
9087 } else if (!show_failed) {
9088 memset(dn_flag, '\0', sizeof(dn_flag));
9089 if (peer_dynamic_neighbor(peer)) {
9090 dn_flag[0] = '*';
9091 }
9092
9093 if (peer->hostname
9094 && CHECK_FLAG(bgp->flags,
9095 BGP_FLAG_SHOW_HOSTNAME))
9096 len = vty_out(vty, "%s%s(%s)", dn_flag,
9097 peer->hostname,
9098 peer->host);
9099 else
9100 len = vty_out(vty, "%s%s", dn_flag, peer->host);
9101
9102 /* pad the neighbor column with spaces */
9103 if (len < max_neighbor_width)
9104 vty_out(vty, "%*s", max_neighbor_width - len,
9105 " ");
9106
9107 vty_out(vty, "4 %10u %9u %9u %8" PRIu64 " %4d %4zd %8s",
9108 peer->as, PEER_TOTAL_RX(peer),
9109 PEER_TOTAL_TX(peer), peer->version[afi][safi],
9110 0, peer->obuf->count,
9111 peer_uptime(peer->uptime, timebuf,
9112 BGP_UPTIME_LEN, 0, NULL));
9113
9114 if (peer->status == Established)
9115 if (peer->afc_recv[afi][safi])
9116 vty_out(vty, " %12" PRIu32,
9117 peer->pcount
9118 [afi]
9119 [pfx_rcd_safi]);
9120 else
9121 vty_out(vty, " NoNeg");
9122 else {
9123 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
9124 vty_out(vty, " Idle (Admin)");
9125 else if (CHECK_FLAG(
9126 peer->sflags,
9127 PEER_STATUS_PREFIX_OVERFLOW))
9128 vty_out(vty, " Idle (PfxCt)");
9129 else
9130 vty_out(vty, " %12s",
9131 lookup_msg(bgp_status_msg,
9132 peer->status, NULL));
9133 }
9134 vty_out(vty, "\n");
9135 }
9136
9137 }
9138 }
9139
9140 if (use_json) {
9141 json_object_object_add(json, "peers", json_peers);
9142 json_object_int_add(json, "failedPeers", failed_count);
9143 json_object_int_add(json, "totalPeers", count);
9144 json_object_int_add(json, "dynamicPeers", dn_count);
9145
9146 if (!show_failed)
9147 bgp_show_bestpath_json(bgp, json);
9148
9149 vty_out(vty, "%s\n", json_object_to_json_string_ext(
9150 json, JSON_C_TO_STRING_PRETTY));
9151 json_object_free(json);
9152 } else {
9153 if (count)
9154 vty_out(vty, "\nTotal number of neighbors %d\n", count);
9155 else {
9156 vty_out(vty, "No %s neighbor is configured\n",
9157 get_afi_safi_str(afi, safi, false));
9158 }
9159
9160 if (dn_count) {
9161 vty_out(vty, "* - dynamic neighbor\n");
9162 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
9163 dn_count, bgp->dynamic_neighbors_limit);
9164 }
9165 }
9166
9167 return CMD_SUCCESS;
9168 }
9169
9170 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
9171 int safi, bool show_failed, bool use_json)
9172 {
9173 int is_first = 1;
9174 int afi_wildcard = (afi == AFI_MAX);
9175 int safi_wildcard = (safi == SAFI_MAX);
9176 int is_wildcard = (afi_wildcard || safi_wildcard);
9177 bool nbr_output = false;
9178
9179 if (use_json && is_wildcard)
9180 vty_out(vty, "{\n");
9181 if (afi_wildcard)
9182 afi = 1; /* AFI_IP */
9183 while (afi < AFI_MAX) {
9184 if (safi_wildcard)
9185 safi = 1; /* SAFI_UNICAST */
9186 while (safi < SAFI_MAX) {
9187 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
9188 nbr_output = true;
9189
9190 if (is_wildcard) {
9191 /*
9192 * So limit output to those afi/safi
9193 * pairs that
9194 * actualy have something interesting in
9195 * them
9196 */
9197 if (use_json) {
9198 if (!is_first)
9199 vty_out(vty, ",\n");
9200 else
9201 is_first = 0;
9202
9203 vty_out(vty, "\"%s\":",
9204 get_afi_safi_str(afi,
9205 safi,
9206 true));
9207 } else {
9208 vty_out(vty, "\n%s Summary:\n",
9209 get_afi_safi_str(afi,
9210 safi,
9211 false));
9212 }
9213 }
9214 bgp_show_summary(vty, bgp, afi, safi, show_failed,
9215 use_json);
9216 }
9217 safi++;
9218 if (!safi_wildcard)
9219 safi = SAFI_MAX;
9220 }
9221 afi++;
9222 if (!afi_wildcard)
9223 afi = AFI_MAX;
9224 }
9225
9226 if (use_json && is_wildcard)
9227 vty_out(vty, "}\n");
9228 else if (!nbr_output) {
9229 if (use_json)
9230 vty_out(vty, "{}\n");
9231 else
9232 vty_out(vty, "%% No BGP neighbors found\n");
9233 }
9234 }
9235
9236 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
9237 safi_t safi, bool show_failed,
9238 bool use_json)
9239 {
9240 struct listnode *node, *nnode;
9241 struct bgp *bgp;
9242 int is_first = 1;
9243 bool nbr_output = false;
9244
9245 if (use_json)
9246 vty_out(vty, "{\n");
9247
9248 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9249 nbr_output = true;
9250 if (use_json) {
9251 if (!is_first)
9252 vty_out(vty, ",\n");
9253 else
9254 is_first = 0;
9255
9256 vty_out(vty, "\"%s\":",
9257 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
9258 ? VRF_DEFAULT_NAME
9259 : bgp->name);
9260 } else {
9261 vty_out(vty, "\nInstance %s:\n",
9262 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
9263 ? VRF_DEFAULT_NAME
9264 : bgp->name);
9265 }
9266 bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_failed,
9267 use_json);
9268 }
9269
9270 if (use_json)
9271 vty_out(vty, "}\n");
9272 else if (!nbr_output)
9273 vty_out(vty, "%% BGP instance not found\n");
9274 }
9275
9276 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
9277 safi_t safi, bool show_failed, bool use_json)
9278 {
9279 struct bgp *bgp;
9280
9281 if (name) {
9282 if (strmatch(name, "all")) {
9283 bgp_show_all_instances_summary_vty(vty, afi, safi,
9284 show_failed,
9285 use_json);
9286 return CMD_SUCCESS;
9287 } else {
9288 bgp = bgp_lookup_by_name(name);
9289
9290 if (!bgp) {
9291 if (use_json)
9292 vty_out(vty, "{}\n");
9293 else
9294 vty_out(vty,
9295 "%% BGP instance not found\n");
9296 return CMD_WARNING;
9297 }
9298
9299 bgp_show_summary_afi_safi(vty, bgp, afi, safi,
9300 show_failed, use_json);
9301 return CMD_SUCCESS;
9302 }
9303 }
9304
9305 bgp = bgp_get_default();
9306
9307 if (bgp)
9308 bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_failed,
9309 use_json);
9310 else {
9311 if (use_json)
9312 vty_out(vty, "{}\n");
9313 else
9314 vty_out(vty, "%% BGP instance not found\n");
9315 return CMD_WARNING;
9316 }
9317
9318 return CMD_SUCCESS;
9319 }
9320
9321 /* `show [ip] bgp summary' commands. */
9322 DEFUN (show_ip_bgp_summary,
9323 show_ip_bgp_summary_cmd,
9324 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [failed] [json]",
9325 SHOW_STR
9326 IP_STR
9327 BGP_STR
9328 BGP_INSTANCE_HELP_STR
9329 BGP_AFI_HELP_STR
9330 BGP_SAFI_WITH_LABEL_HELP_STR
9331 "Summary of BGP neighbor status\n"
9332 "Show only sessions not in Established state\n"
9333 JSON_STR)
9334 {
9335 char *vrf = NULL;
9336 afi_t afi = AFI_MAX;
9337 safi_t safi = SAFI_MAX;
9338 bool show_failed = false;
9339
9340 int idx = 0;
9341
9342 /* show [ip] bgp */
9343 if (argv_find(argv, argc, "ip", &idx))
9344 afi = AFI_IP;
9345 /* [<vrf> VIEWVRFNAME] */
9346 if (argv_find(argv, argc, "vrf", &idx)) {
9347 vrf = argv[idx + 1]->arg;
9348 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9349 vrf = NULL;
9350 } else if (argv_find(argv, argc, "view", &idx))
9351 /* [<view> VIEWVRFNAME] */
9352 vrf = argv[idx + 1]->arg;
9353 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
9354 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
9355 argv_find_and_parse_safi(argv, argc, &idx, &safi);
9356 }
9357
9358 if (argv_find(argv, argc, "failed", &idx))
9359 show_failed = true;
9360
9361 bool uj = use_json(argc, argv);
9362
9363 return bgp_show_summary_vty(vty, vrf, afi, safi, show_failed, uj);
9364 }
9365
9366 const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
9367 {
9368 if (for_json)
9369 return get_afi_safi_json_str(afi, safi);
9370 else
9371 return get_afi_safi_vty_str(afi, safi);
9372 }
9373
9374
9375 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
9376 afi_t afi, safi_t safi,
9377 uint16_t adv_smcap, uint16_t adv_rmcap,
9378 uint16_t rcv_smcap, uint16_t rcv_rmcap,
9379 bool use_json, json_object *json_pref)
9380 {
9381 /* Send-Mode */
9382 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
9383 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
9384 if (use_json) {
9385 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
9386 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
9387 json_object_string_add(json_pref, "sendMode",
9388 "advertisedAndReceived");
9389 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
9390 json_object_string_add(json_pref, "sendMode",
9391 "advertised");
9392 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
9393 json_object_string_add(json_pref, "sendMode",
9394 "received");
9395 } else {
9396 vty_out(vty, " Send-mode: ");
9397 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
9398 vty_out(vty, "advertised");
9399 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
9400 vty_out(vty, "%sreceived",
9401 CHECK_FLAG(p->af_cap[afi][safi],
9402 adv_smcap)
9403 ? ", "
9404 : "");
9405 vty_out(vty, "\n");
9406 }
9407 }
9408
9409 /* Receive-Mode */
9410 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
9411 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
9412 if (use_json) {
9413 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
9414 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
9415 json_object_string_add(json_pref, "recvMode",
9416 "advertisedAndReceived");
9417 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
9418 json_object_string_add(json_pref, "recvMode",
9419 "advertised");
9420 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
9421 json_object_string_add(json_pref, "recvMode",
9422 "received");
9423 } else {
9424 vty_out(vty, " Receive-mode: ");
9425 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
9426 vty_out(vty, "advertised");
9427 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
9428 vty_out(vty, "%sreceived",
9429 CHECK_FLAG(p->af_cap[afi][safi],
9430 adv_rmcap)
9431 ? ", "
9432 : "");
9433 vty_out(vty, "\n");
9434 }
9435 }
9436 }
9437
9438 static void bgp_show_neighnor_graceful_restart_rbit(struct vty *vty,
9439 struct peer *p,
9440 bool use_json,
9441 json_object *json)
9442 {
9443 bool rbit_status = false;
9444
9445 if (!use_json)
9446 vty_out(vty, "\n R bit: ");
9447
9448 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
9449 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
9450 && (p->status == Established)) {
9451
9452 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_BIT_RCV))
9453 rbit_status = true;
9454 else
9455 rbit_status = false;
9456 }
9457
9458 if (rbit_status) {
9459 if (use_json)
9460 json_object_boolean_true_add(json, "rBit");
9461 else
9462 vty_out(vty, "True\n");
9463 } else {
9464 if (use_json)
9465 json_object_boolean_false_add(json, "rBit");
9466 else
9467 vty_out(vty, "False\n");
9468 }
9469 }
9470
9471 static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
9472 struct peer *peer,
9473 bool use_json,
9474 json_object *json)
9475 {
9476 const char *mode = "NotApplicable";
9477
9478 if (!use_json)
9479 vty_out(vty, "\n Remote GR Mode: ");
9480
9481 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
9482 && (peer->status == Established)) {
9483
9484 if ((peer->nsf_af_count == 0)
9485 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
9486
9487 mode = "Disable";
9488
9489 } else if (peer->nsf_af_count == 0
9490 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
9491
9492 mode = "Helper";
9493
9494 } else if (peer->nsf_af_count != 0
9495 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
9496
9497 mode = "Restart";
9498 }
9499 }
9500
9501 if (use_json) {
9502 json_object_string_add(json, "remoteGrMode", mode);
9503 } else
9504 vty_out(vty, mode, "\n");
9505 }
9506
9507 static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
9508 struct peer *p,
9509 bool use_json,
9510 json_object *json)
9511 {
9512 const char *mode = "Invalid";
9513
9514 if (!use_json)
9515 vty_out(vty, " Local GR Mode: ");
9516
9517 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
9518 mode = "Helper";
9519 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
9520 mode = "Restart";
9521 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
9522 mode = "Disable";
9523 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
9524 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
9525 mode = "Helper*";
9526 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
9527 mode = "Restart*";
9528 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
9529 mode = "Disable*";
9530 else
9531 mode = "Invalid*";
9532 }
9533
9534 if (use_json) {
9535 json_object_string_add(json, "localGrMode", mode);
9536 } else {
9537 vty_out(vty, mode, "\n");
9538 }
9539 }
9540
9541 static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
9542 struct vty *vty, struct peer *peer, bool use_json, json_object *json)
9543 {
9544 afi_t afi;
9545 safi_t safi;
9546 json_object *json_afi_safi = NULL;
9547 json_object *json_timer = NULL;
9548 json_object *json_endofrib_status = NULL;
9549 bool eor_flag = false;
9550
9551 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
9552 for (safi = SAFI_UNICAST; safi <= SAFI_MPLS_VPN; safi++) {
9553 if (!peer->afc[afi][safi])
9554 continue;
9555
9556 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
9557 || !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
9558 continue;
9559
9560 if (use_json) {
9561 json_afi_safi = json_object_new_object();
9562 json_endofrib_status = json_object_new_object();
9563 json_timer = json_object_new_object();
9564 }
9565
9566 if (peer->eor_stime[afi][safi]
9567 >= peer->pkt_stime[afi][safi])
9568 eor_flag = true;
9569 else
9570 eor_flag = false;
9571
9572 if (!use_json) {
9573 vty_out(vty, " %s:\n",
9574 get_afi_safi_str(afi, safi, false));
9575
9576 vty_out(vty, " F bit: ");
9577 }
9578
9579 if (peer->nsf[afi][safi]
9580 && CHECK_FLAG(peer->af_cap[afi][safi],
9581 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
9582
9583 if (use_json) {
9584 json_object_boolean_true_add(
9585 json_afi_safi, "fBit");
9586 } else
9587 vty_out(vty, "True\n");
9588 } else {
9589 if (use_json)
9590 json_object_boolean_false_add(
9591 json_afi_safi, "fBit");
9592 else
9593 vty_out(vty, "False\n");
9594 }
9595
9596 if (!use_json)
9597 vty_out(vty, " End-of-RIB sent: ");
9598
9599 if (CHECK_FLAG(peer->af_sflags[afi][safi],
9600 PEER_STATUS_EOR_SEND)) {
9601 if (use_json) {
9602 json_object_boolean_true_add(
9603 json_endofrib_status,
9604 "endOfRibSend");
9605
9606 PRINT_EOR_JSON(eor_flag);
9607 } else {
9608 vty_out(vty, "Yes\n");
9609 vty_out(vty,
9610 " End-of-RIB sent after update: ");
9611
9612 PRINT_EOR(eor_flag);
9613 }
9614 } else {
9615 if (use_json) {
9616 json_object_boolean_false_add(
9617 json_endofrib_status,
9618 "endOfRibSend");
9619 json_object_boolean_false_add(
9620 json_endofrib_status,
9621 "endOfRibSentAfterUpdate");
9622 } else {
9623 vty_out(vty, "No\n");
9624 vty_out(vty,
9625 " End-of-RIB sent after update: ");
9626 vty_out(vty, "No\n");
9627 }
9628 }
9629
9630 if (!use_json)
9631 vty_out(vty, " End-of-RIB received: ");
9632
9633 if (CHECK_FLAG(peer->af_sflags[afi][safi],
9634 PEER_STATUS_EOR_RECEIVED)) {
9635 if (use_json)
9636 json_object_boolean_true_add(
9637 json_endofrib_status,
9638 "endOfRibRecv");
9639 else
9640 vty_out(vty, "Yes\n");
9641 } else {
9642 if (use_json)
9643 json_object_boolean_false_add(
9644 json_endofrib_status,
9645 "endOfRibRecv");
9646 else
9647 vty_out(vty, "No\n");
9648 }
9649
9650 if (use_json) {
9651 json_object_int_add(json_timer,
9652 "stalePathTimer",
9653 peer->bgp->stalepath_time);
9654
9655 if (peer->t_gr_stale != NULL) {
9656 json_object_int_add(
9657 json_timer,
9658 "stalePathTimerRemaining",
9659 thread_timer_remain_second(
9660 peer->t_gr_stale));
9661 }
9662
9663 /* Display Configured Selection
9664 * Deferral only when when
9665 * Gr mode is enabled.
9666 */
9667 if (CHECK_FLAG(peer->flags,
9668 PEER_FLAG_GRACEFUL_RESTART)) {
9669 json_object_int_add(
9670 json_timer,
9671 "selectionDeferralTimer",
9672 peer->bgp->stalepath_time);
9673 }
9674
9675 if (peer->bgp->gr_info[afi][safi]
9676 .t_select_deferral
9677 != NULL) {
9678
9679 json_object_int_add(
9680 json_timer,
9681 "selectionDeferralTimerRemaining",
9682 thread_timer_remain_second(
9683 peer->bgp
9684 ->gr_info[afi]
9685 [safi]
9686 .t_select_deferral));
9687 }
9688 } else {
9689 vty_out(vty, " Timers:\n");
9690 vty_out(vty,
9691 " Configured Stale Path Time(sec): %u\n",
9692 peer->bgp->stalepath_time);
9693
9694 if (peer->t_gr_stale != NULL)
9695 vty_out(vty,
9696 " Stale Path Remaining(sec): %ld\n",
9697 thread_timer_remain_second(
9698 peer->t_gr_stale));
9699 /* Display Configured Selection
9700 * Deferral only when when
9701 * Gr mode is enabled.
9702 */
9703 if (CHECK_FLAG(peer->flags,
9704 PEER_FLAG_GRACEFUL_RESTART))
9705 vty_out(vty,
9706 " Configured Selection Deferral Time(sec): %u\n",
9707 peer->bgp->select_defer_time);
9708
9709 if (peer->bgp->gr_info[afi][safi]
9710 .t_select_deferral
9711 != NULL)
9712 vty_out(vty,
9713 " Selection Deferral Time Remaining(sec): %ld\n",
9714 thread_timer_remain_second(
9715 peer->bgp
9716 ->gr_info[afi]
9717 [safi]
9718 .t_select_deferral));
9719 }
9720 if (use_json) {
9721 json_object_object_add(json_afi_safi,
9722 "endOfRibStatus",
9723 json_endofrib_status);
9724 json_object_object_add(json_afi_safi, "timers",
9725 json_timer);
9726 json_object_object_add(
9727 json, get_afi_safi_str(afi, safi, true),
9728 json_afi_safi);
9729 }
9730 }
9731 }
9732 }
9733
9734 static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
9735 struct peer *p,
9736 bool use_json,
9737 json_object *json)
9738 {
9739 if (use_json) {
9740 json_object *json_timer = NULL;
9741
9742 json_timer = json_object_new_object();
9743
9744 json_object_int_add(json_timer, "configuredRestartTimer",
9745 p->bgp->restart_time);
9746
9747 json_object_int_add(json_timer, "receivedRestartTimer",
9748 p->v_gr_restart);
9749
9750 if (p->t_gr_restart != NULL)
9751 json_object_int_add(
9752 json_timer, "restartTimerRemaining",
9753 thread_timer_remain_second(p->t_gr_restart));
9754
9755 json_object_object_add(json, "timers", json_timer);
9756 } else {
9757
9758 vty_out(vty, " Timers:\n");
9759 vty_out(vty, " Configured Restart Time(sec): %u\n",
9760 p->bgp->restart_time);
9761
9762 vty_out(vty, " Received Restart Time(sec): %u\n",
9763 p->v_gr_restart);
9764 if (p->t_gr_restart != NULL)
9765 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
9766 thread_timer_remain_second(p->t_gr_restart));
9767 if (p->t_gr_restart != NULL) {
9768 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
9769 thread_timer_remain_second(p->t_gr_restart));
9770 }
9771 }
9772 }
9773
9774 static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
9775 bool use_json, json_object *json)
9776 {
9777 char buf[SU_ADDRSTRLEN] = {0};
9778 char dn_flag[2] = {0};
9779 char neighborAddr[INET6_ADDRSTRLEN] = {0};
9780
9781 if (!p->conf_if && peer_dynamic_neighbor(p))
9782 dn_flag[0] = '*';
9783
9784 if (p->conf_if) {
9785 if (use_json)
9786 json_object_string_add(
9787 json, "neighborAddr",
9788 BGP_PEER_SU_UNSPEC(p)
9789 ? "none"
9790 : sockunion2str(&p->su, buf,
9791 SU_ADDRSTRLEN));
9792 else
9793 vty_out(vty, "BGP neighbor on %s: %s\n", p->conf_if,
9794 BGP_PEER_SU_UNSPEC(p)
9795 ? "none"
9796 : sockunion2str(&p->su, buf,
9797 SU_ADDRSTRLEN));
9798 } else {
9799 sprintf(neighborAddr, "%s%s", dn_flag, p->host);
9800
9801 if (use_json)
9802 json_object_string_add(json, "neighborAddr",
9803 neighborAddr);
9804 else
9805 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
9806 }
9807
9808 /* more gr info in new format */
9809 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json);
9810 }
9811
9812 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
9813 safi_t safi, bool use_json,
9814 json_object *json_neigh)
9815 {
9816 struct bgp_filter *filter;
9817 struct peer_af *paf;
9818 char orf_pfx_name[BUFSIZ];
9819 int orf_pfx_count;
9820 json_object *json_af = NULL;
9821 json_object *json_prefA = NULL;
9822 json_object *json_prefB = NULL;
9823 json_object *json_addr = NULL;
9824
9825 if (use_json) {
9826 json_addr = json_object_new_object();
9827 json_af = json_object_new_object();
9828 filter = &p->filter[afi][safi];
9829
9830 if (peer_group_active(p))
9831 json_object_string_add(json_addr, "peerGroupMember",
9832 p->group->name);
9833
9834 paf = peer_af_find(p, afi, safi);
9835 if (paf && PAF_SUBGRP(paf)) {
9836 json_object_int_add(json_addr, "updateGroupId",
9837 PAF_UPDGRP(paf)->id);
9838 json_object_int_add(json_addr, "subGroupId",
9839 PAF_SUBGRP(paf)->id);
9840 json_object_int_add(json_addr, "packetQueueLength",
9841 bpacket_queue_virtual_length(paf));
9842 }
9843
9844 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
9845 || CHECK_FLAG(p->af_cap[afi][safi],
9846 PEER_CAP_ORF_PREFIX_SM_RCV)
9847 || CHECK_FLAG(p->af_cap[afi][safi],
9848 PEER_CAP_ORF_PREFIX_RM_ADV)
9849 || CHECK_FLAG(p->af_cap[afi][safi],
9850 PEER_CAP_ORF_PREFIX_RM_RCV)) {
9851 json_object_int_add(json_af, "orfType",
9852 ORF_TYPE_PREFIX);
9853 json_prefA = json_object_new_object();
9854 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
9855 PEER_CAP_ORF_PREFIX_SM_ADV,
9856 PEER_CAP_ORF_PREFIX_RM_ADV,
9857 PEER_CAP_ORF_PREFIX_SM_RCV,
9858 PEER_CAP_ORF_PREFIX_RM_RCV,
9859 use_json, json_prefA);
9860 json_object_object_add(json_af, "orfPrefixList",
9861 json_prefA);
9862 }
9863
9864 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
9865 || CHECK_FLAG(p->af_cap[afi][safi],
9866 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
9867 || CHECK_FLAG(p->af_cap[afi][safi],
9868 PEER_CAP_ORF_PREFIX_RM_ADV)
9869 || CHECK_FLAG(p->af_cap[afi][safi],
9870 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
9871 json_object_int_add(json_af, "orfOldType",
9872 ORF_TYPE_PREFIX_OLD);
9873 json_prefB = json_object_new_object();
9874 bgp_show_peer_afi_orf_cap(
9875 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
9876 PEER_CAP_ORF_PREFIX_RM_ADV,
9877 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
9878 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
9879 json_prefB);
9880 json_object_object_add(json_af, "orfOldPrefixList",
9881 json_prefB);
9882 }
9883
9884 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
9885 || CHECK_FLAG(p->af_cap[afi][safi],
9886 PEER_CAP_ORF_PREFIX_SM_RCV)
9887 || CHECK_FLAG(p->af_cap[afi][safi],
9888 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
9889 || CHECK_FLAG(p->af_cap[afi][safi],
9890 PEER_CAP_ORF_PREFIX_RM_ADV)
9891 || CHECK_FLAG(p->af_cap[afi][safi],
9892 PEER_CAP_ORF_PREFIX_RM_RCV)
9893 || CHECK_FLAG(p->af_cap[afi][safi],
9894 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
9895 json_object_object_add(json_addr, "afDependentCap",
9896 json_af);
9897 else
9898 json_object_free(json_af);
9899
9900 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
9901 orf_pfx_count = prefix_bgp_show_prefix_list(
9902 NULL, afi, orf_pfx_name, use_json);
9903
9904 if (CHECK_FLAG(p->af_sflags[afi][safi],
9905 PEER_STATUS_ORF_PREFIX_SEND)
9906 || orf_pfx_count) {
9907 if (CHECK_FLAG(p->af_sflags[afi][safi],
9908 PEER_STATUS_ORF_PREFIX_SEND))
9909 json_object_boolean_true_add(json_neigh,
9910 "orfSent");
9911 if (orf_pfx_count)
9912 json_object_int_add(json_addr, "orfRecvCounter",
9913 orf_pfx_count);
9914 }
9915 if (CHECK_FLAG(p->af_sflags[afi][safi],
9916 PEER_STATUS_ORF_WAIT_REFRESH))
9917 json_object_string_add(
9918 json_addr, "orfFirstUpdate",
9919 "deferredUntilORFOrRouteRefreshRecvd");
9920
9921 if (CHECK_FLAG(p->af_flags[afi][safi],
9922 PEER_FLAG_REFLECTOR_CLIENT))
9923 json_object_boolean_true_add(json_addr,
9924 "routeReflectorClient");
9925 if (CHECK_FLAG(p->af_flags[afi][safi],
9926 PEER_FLAG_RSERVER_CLIENT))
9927 json_object_boolean_true_add(json_addr,
9928 "routeServerClient");
9929 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9930 json_object_boolean_true_add(json_addr,
9931 "inboundSoftConfigPermit");
9932
9933 if (CHECK_FLAG(p->af_flags[afi][safi],
9934 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
9935 json_object_boolean_true_add(
9936 json_addr,
9937 "privateAsNumsAllReplacedInUpdatesToNbr");
9938 else if (CHECK_FLAG(p->af_flags[afi][safi],
9939 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
9940 json_object_boolean_true_add(
9941 json_addr,
9942 "privateAsNumsReplacedInUpdatesToNbr");
9943 else if (CHECK_FLAG(p->af_flags[afi][safi],
9944 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
9945 json_object_boolean_true_add(
9946 json_addr,
9947 "privateAsNumsAllRemovedInUpdatesToNbr");
9948 else if (CHECK_FLAG(p->af_flags[afi][safi],
9949 PEER_FLAG_REMOVE_PRIVATE_AS))
9950 json_object_boolean_true_add(
9951 json_addr,
9952 "privateAsNumsRemovedInUpdatesToNbr");
9953
9954 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
9955 json_object_boolean_true_add(
9956 json_addr,
9957 bgp_addpath_names(p->addpath_type[afi][safi])
9958 ->type_json_name);
9959
9960 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
9961 json_object_string_add(json_addr,
9962 "overrideASNsInOutboundUpdates",
9963 "ifAspathEqualRemoteAs");
9964
9965 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
9966 || CHECK_FLAG(p->af_flags[afi][safi],
9967 PEER_FLAG_FORCE_NEXTHOP_SELF))
9968 json_object_boolean_true_add(json_addr,
9969 "routerAlwaysNextHop");
9970 if (CHECK_FLAG(p->af_flags[afi][safi],
9971 PEER_FLAG_AS_PATH_UNCHANGED))
9972 json_object_boolean_true_add(
9973 json_addr, "unchangedAsPathPropogatedToNbr");
9974 if (CHECK_FLAG(p->af_flags[afi][safi],
9975 PEER_FLAG_NEXTHOP_UNCHANGED))
9976 json_object_boolean_true_add(
9977 json_addr, "unchangedNextHopPropogatedToNbr");
9978 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
9979 json_object_boolean_true_add(
9980 json_addr, "unchangedMedPropogatedToNbr");
9981 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
9982 || CHECK_FLAG(p->af_flags[afi][safi],
9983 PEER_FLAG_SEND_EXT_COMMUNITY)) {
9984 if (CHECK_FLAG(p->af_flags[afi][safi],
9985 PEER_FLAG_SEND_COMMUNITY)
9986 && CHECK_FLAG(p->af_flags[afi][safi],
9987 PEER_FLAG_SEND_EXT_COMMUNITY))
9988 json_object_string_add(json_addr,
9989 "commAttriSentToNbr",
9990 "extendedAndStandard");
9991 else if (CHECK_FLAG(p->af_flags[afi][safi],
9992 PEER_FLAG_SEND_EXT_COMMUNITY))
9993 json_object_string_add(json_addr,
9994 "commAttriSentToNbr",
9995 "extended");
9996 else
9997 json_object_string_add(json_addr,
9998 "commAttriSentToNbr",
9999 "standard");
10000 }
10001 if (CHECK_FLAG(p->af_flags[afi][safi],
10002 PEER_FLAG_DEFAULT_ORIGINATE)) {
10003 if (p->default_rmap[afi][safi].name)
10004 json_object_string_add(
10005 json_addr, "defaultRouteMap",
10006 p->default_rmap[afi][safi].name);
10007
10008 if (paf && PAF_SUBGRP(paf)
10009 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
10010 SUBGRP_STATUS_DEFAULT_ORIGINATE))
10011 json_object_boolean_true_add(json_addr,
10012 "defaultSent");
10013 else
10014 json_object_boolean_true_add(json_addr,
10015 "defaultNotSent");
10016 }
10017
10018 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
10019 if (is_evpn_enabled())
10020 json_object_boolean_true_add(
10021 json_addr, "advertiseAllVnis");
10022 }
10023
10024 if (filter->plist[FILTER_IN].name
10025 || filter->dlist[FILTER_IN].name
10026 || filter->aslist[FILTER_IN].name
10027 || filter->map[RMAP_IN].name)
10028 json_object_boolean_true_add(json_addr,
10029 "inboundPathPolicyConfig");
10030 if (filter->plist[FILTER_OUT].name
10031 || filter->dlist[FILTER_OUT].name
10032 || filter->aslist[FILTER_OUT].name
10033 || filter->map[RMAP_OUT].name || filter->usmap.name)
10034 json_object_boolean_true_add(
10035 json_addr, "outboundPathPolicyConfig");
10036
10037 /* prefix-list */
10038 if (filter->plist[FILTER_IN].name)
10039 json_object_string_add(json_addr,
10040 "incomingUpdatePrefixFilterList",
10041 filter->plist[FILTER_IN].name);
10042 if (filter->plist[FILTER_OUT].name)
10043 json_object_string_add(json_addr,
10044 "outgoingUpdatePrefixFilterList",
10045 filter->plist[FILTER_OUT].name);
10046
10047 /* distribute-list */
10048 if (filter->dlist[FILTER_IN].name)
10049 json_object_string_add(
10050 json_addr, "incomingUpdateNetworkFilterList",
10051 filter->dlist[FILTER_IN].name);
10052 if (filter->dlist[FILTER_OUT].name)
10053 json_object_string_add(
10054 json_addr, "outgoingUpdateNetworkFilterList",
10055 filter->dlist[FILTER_OUT].name);
10056
10057 /* filter-list. */
10058 if (filter->aslist[FILTER_IN].name)
10059 json_object_string_add(json_addr,
10060 "incomingUpdateAsPathFilterList",
10061 filter->aslist[FILTER_IN].name);
10062 if (filter->aslist[FILTER_OUT].name)
10063 json_object_string_add(json_addr,
10064 "outgoingUpdateAsPathFilterList",
10065 filter->aslist[FILTER_OUT].name);
10066
10067 /* route-map. */
10068 if (filter->map[RMAP_IN].name)
10069 json_object_string_add(
10070 json_addr, "routeMapForIncomingAdvertisements",
10071 filter->map[RMAP_IN].name);
10072 if (filter->map[RMAP_OUT].name)
10073 json_object_string_add(
10074 json_addr, "routeMapForOutgoingAdvertisements",
10075 filter->map[RMAP_OUT].name);
10076
10077 /* ebgp-requires-policy (inbound) */
10078 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
10079 && !bgp_inbound_policy_exists(p, filter))
10080 json_object_string_add(
10081 json_addr, "inboundEbgpRequiresPolicy",
10082 "Inbound updates discarded due to missing policy");
10083
10084 /* ebgp-requires-policy (outbound) */
10085 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
10086 && (!bgp_outbound_policy_exists(p, filter)))
10087 json_object_string_add(
10088 json_addr, "outboundEbgpRequiresPolicy",
10089 "Outbound updates discarded due to missing policy");
10090
10091 /* unsuppress-map */
10092 if (filter->usmap.name)
10093 json_object_string_add(json_addr,
10094 "selectiveUnsuppressRouteMap",
10095 filter->usmap.name);
10096
10097 /* Receive prefix count */
10098 json_object_int_add(json_addr, "acceptedPrefixCounter",
10099 p->pcount[afi][safi]);
10100 if (paf && PAF_SUBGRP(paf))
10101 json_object_int_add(json_addr, "sentPrefixCounter",
10102 (PAF_SUBGRP(paf))->scount);
10103
10104 /* Maximum prefix */
10105 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
10106 json_object_int_add(json_addr, "prefixOutAllowedMax",
10107 p->pmax_out[afi][safi]);
10108
10109 /* Maximum prefix */
10110 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
10111 json_object_int_add(json_addr, "prefixAllowedMax",
10112 p->pmax[afi][safi]);
10113 if (CHECK_FLAG(p->af_flags[afi][safi],
10114 PEER_FLAG_MAX_PREFIX_WARNING))
10115 json_object_boolean_true_add(
10116 json_addr, "prefixAllowedMaxWarning");
10117 json_object_int_add(json_addr,
10118 "prefixAllowedWarningThresh",
10119 p->pmax_threshold[afi][safi]);
10120 if (p->pmax_restart[afi][safi])
10121 json_object_int_add(
10122 json_addr,
10123 "prefixAllowedRestartIntervalMsecs",
10124 p->pmax_restart[afi][safi] * 60000);
10125 }
10126 json_object_object_add(json_neigh,
10127 get_afi_safi_str(afi, safi, true),
10128 json_addr);
10129
10130 } else {
10131 filter = &p->filter[afi][safi];
10132
10133 vty_out(vty, " For address family: %s\n",
10134 get_afi_safi_str(afi, safi, false));
10135
10136 if (peer_group_active(p))
10137 vty_out(vty, " %s peer-group member\n",
10138 p->group->name);
10139
10140 paf = peer_af_find(p, afi, safi);
10141 if (paf && PAF_SUBGRP(paf)) {
10142 vty_out(vty, " Update group %" PRIu64
10143 ", subgroup %" PRIu64 "\n",
10144 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
10145 vty_out(vty, " Packet Queue length %d\n",
10146 bpacket_queue_virtual_length(paf));
10147 } else {
10148 vty_out(vty, " Not part of any update group\n");
10149 }
10150 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
10151 || CHECK_FLAG(p->af_cap[afi][safi],
10152 PEER_CAP_ORF_PREFIX_SM_RCV)
10153 || CHECK_FLAG(p->af_cap[afi][safi],
10154 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
10155 || CHECK_FLAG(p->af_cap[afi][safi],
10156 PEER_CAP_ORF_PREFIX_RM_ADV)
10157 || CHECK_FLAG(p->af_cap[afi][safi],
10158 PEER_CAP_ORF_PREFIX_RM_RCV)
10159 || CHECK_FLAG(p->af_cap[afi][safi],
10160 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
10161 vty_out(vty, " AF-dependant capabilities:\n");
10162
10163 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
10164 || CHECK_FLAG(p->af_cap[afi][safi],
10165 PEER_CAP_ORF_PREFIX_SM_RCV)
10166 || CHECK_FLAG(p->af_cap[afi][safi],
10167 PEER_CAP_ORF_PREFIX_RM_ADV)
10168 || CHECK_FLAG(p->af_cap[afi][safi],
10169 PEER_CAP_ORF_PREFIX_RM_RCV)) {
10170 vty_out(vty,
10171 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
10172 ORF_TYPE_PREFIX);
10173 bgp_show_peer_afi_orf_cap(
10174 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
10175 PEER_CAP_ORF_PREFIX_RM_ADV,
10176 PEER_CAP_ORF_PREFIX_SM_RCV,
10177 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
10178 }
10179 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
10180 || CHECK_FLAG(p->af_cap[afi][safi],
10181 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
10182 || CHECK_FLAG(p->af_cap[afi][safi],
10183 PEER_CAP_ORF_PREFIX_RM_ADV)
10184 || CHECK_FLAG(p->af_cap[afi][safi],
10185 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
10186 vty_out(vty,
10187 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
10188 ORF_TYPE_PREFIX_OLD);
10189 bgp_show_peer_afi_orf_cap(
10190 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
10191 PEER_CAP_ORF_PREFIX_RM_ADV,
10192 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
10193 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
10194 }
10195
10196 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
10197 orf_pfx_count = prefix_bgp_show_prefix_list(
10198 NULL, afi, orf_pfx_name, use_json);
10199
10200 if (CHECK_FLAG(p->af_sflags[afi][safi],
10201 PEER_STATUS_ORF_PREFIX_SEND)
10202 || orf_pfx_count) {
10203 vty_out(vty, " Outbound Route Filter (ORF):");
10204 if (CHECK_FLAG(p->af_sflags[afi][safi],
10205 PEER_STATUS_ORF_PREFIX_SEND))
10206 vty_out(vty, " sent;");
10207 if (orf_pfx_count)
10208 vty_out(vty, " received (%d entries)",
10209 orf_pfx_count);
10210 vty_out(vty, "\n");
10211 }
10212 if (CHECK_FLAG(p->af_sflags[afi][safi],
10213 PEER_STATUS_ORF_WAIT_REFRESH))
10214 vty_out(vty,
10215 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
10216
10217 if (CHECK_FLAG(p->af_flags[afi][safi],
10218 PEER_FLAG_REFLECTOR_CLIENT))
10219 vty_out(vty, " Route-Reflector Client\n");
10220 if (CHECK_FLAG(p->af_flags[afi][safi],
10221 PEER_FLAG_RSERVER_CLIENT))
10222 vty_out(vty, " Route-Server Client\n");
10223 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
10224 vty_out(vty,
10225 " Inbound soft reconfiguration allowed\n");
10226
10227 if (CHECK_FLAG(p->af_flags[afi][safi],
10228 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
10229 vty_out(vty,
10230 " Private AS numbers (all) replaced in updates to this neighbor\n");
10231 else if (CHECK_FLAG(p->af_flags[afi][safi],
10232 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
10233 vty_out(vty,
10234 " Private AS numbers replaced in updates to this neighbor\n");
10235 else if (CHECK_FLAG(p->af_flags[afi][safi],
10236 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
10237 vty_out(vty,
10238 " Private AS numbers (all) removed in updates to this neighbor\n");
10239 else if (CHECK_FLAG(p->af_flags[afi][safi],
10240 PEER_FLAG_REMOVE_PRIVATE_AS))
10241 vty_out(vty,
10242 " Private AS numbers removed in updates to this neighbor\n");
10243
10244 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
10245 vty_out(vty, " %s\n",
10246 bgp_addpath_names(p->addpath_type[afi][safi])
10247 ->human_description);
10248
10249 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
10250 vty_out(vty,
10251 " Override ASNs in outbound updates if aspath equals remote-as\n");
10252
10253 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
10254 || CHECK_FLAG(p->af_flags[afi][safi],
10255 PEER_FLAG_FORCE_NEXTHOP_SELF))
10256 vty_out(vty, " NEXT_HOP is always this router\n");
10257 if (CHECK_FLAG(p->af_flags[afi][safi],
10258 PEER_FLAG_AS_PATH_UNCHANGED))
10259 vty_out(vty,
10260 " AS_PATH is propagated unchanged to this neighbor\n");
10261 if (CHECK_FLAG(p->af_flags[afi][safi],
10262 PEER_FLAG_NEXTHOP_UNCHANGED))
10263 vty_out(vty,
10264 " NEXT_HOP is propagated unchanged to this neighbor\n");
10265 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
10266 vty_out(vty,
10267 " MED is propagated unchanged to this neighbor\n");
10268 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
10269 || CHECK_FLAG(p->af_flags[afi][safi],
10270 PEER_FLAG_SEND_EXT_COMMUNITY)
10271 || CHECK_FLAG(p->af_flags[afi][safi],
10272 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
10273 vty_out(vty,
10274 " Community attribute sent to this neighbor");
10275 if (CHECK_FLAG(p->af_flags[afi][safi],
10276 PEER_FLAG_SEND_COMMUNITY)
10277 && CHECK_FLAG(p->af_flags[afi][safi],
10278 PEER_FLAG_SEND_EXT_COMMUNITY)
10279 && CHECK_FLAG(p->af_flags[afi][safi],
10280 PEER_FLAG_SEND_LARGE_COMMUNITY))
10281 vty_out(vty, "(all)\n");
10282 else if (CHECK_FLAG(p->af_flags[afi][safi],
10283 PEER_FLAG_SEND_LARGE_COMMUNITY))
10284 vty_out(vty, "(large)\n");
10285 else if (CHECK_FLAG(p->af_flags[afi][safi],
10286 PEER_FLAG_SEND_EXT_COMMUNITY))
10287 vty_out(vty, "(extended)\n");
10288 else
10289 vty_out(vty, "(standard)\n");
10290 }
10291 if (CHECK_FLAG(p->af_flags[afi][safi],
10292 PEER_FLAG_DEFAULT_ORIGINATE)) {
10293 vty_out(vty, " Default information originate,");
10294
10295 if (p->default_rmap[afi][safi].name)
10296 vty_out(vty, " default route-map %s%s,",
10297 p->default_rmap[afi][safi].map ? "*"
10298 : "",
10299 p->default_rmap[afi][safi].name);
10300 if (paf && PAF_SUBGRP(paf)
10301 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
10302 SUBGRP_STATUS_DEFAULT_ORIGINATE))
10303 vty_out(vty, " default sent\n");
10304 else
10305 vty_out(vty, " default not sent\n");
10306 }
10307
10308 /* advertise-vni-all */
10309 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
10310 if (is_evpn_enabled())
10311 vty_out(vty, " advertise-all-vni\n");
10312 }
10313
10314 if (filter->plist[FILTER_IN].name
10315 || filter->dlist[FILTER_IN].name
10316 || filter->aslist[FILTER_IN].name
10317 || filter->map[RMAP_IN].name)
10318 vty_out(vty, " Inbound path policy configured\n");
10319 if (filter->plist[FILTER_OUT].name
10320 || filter->dlist[FILTER_OUT].name
10321 || filter->aslist[FILTER_OUT].name
10322 || filter->map[RMAP_OUT].name || filter->usmap.name)
10323 vty_out(vty, " Outbound path policy configured\n");
10324
10325 /* prefix-list */
10326 if (filter->plist[FILTER_IN].name)
10327 vty_out(vty,
10328 " Incoming update prefix filter list is %s%s\n",
10329 filter->plist[FILTER_IN].plist ? "*" : "",
10330 filter->plist[FILTER_IN].name);
10331 if (filter->plist[FILTER_OUT].name)
10332 vty_out(vty,
10333 " Outgoing update prefix filter list is %s%s\n",
10334 filter->plist[FILTER_OUT].plist ? "*" : "",
10335 filter->plist[FILTER_OUT].name);
10336
10337 /* distribute-list */
10338 if (filter->dlist[FILTER_IN].name)
10339 vty_out(vty,
10340 " Incoming update network filter list is %s%s\n",
10341 filter->dlist[FILTER_IN].alist ? "*" : "",
10342 filter->dlist[FILTER_IN].name);
10343 if (filter->dlist[FILTER_OUT].name)
10344 vty_out(vty,
10345 " Outgoing update network filter list is %s%s\n",
10346 filter->dlist[FILTER_OUT].alist ? "*" : "",
10347 filter->dlist[FILTER_OUT].name);
10348
10349 /* filter-list. */
10350 if (filter->aslist[FILTER_IN].name)
10351 vty_out(vty,
10352 " Incoming update AS path filter list is %s%s\n",
10353 filter->aslist[FILTER_IN].aslist ? "*" : "",
10354 filter->aslist[FILTER_IN].name);
10355 if (filter->aslist[FILTER_OUT].name)
10356 vty_out(vty,
10357 " Outgoing update AS path filter list is %s%s\n",
10358 filter->aslist[FILTER_OUT].aslist ? "*" : "",
10359 filter->aslist[FILTER_OUT].name);
10360
10361 /* route-map. */
10362 if (filter->map[RMAP_IN].name)
10363 vty_out(vty,
10364 " Route map for incoming advertisements is %s%s\n",
10365 filter->map[RMAP_IN].map ? "*" : "",
10366 filter->map[RMAP_IN].name);
10367 if (filter->map[RMAP_OUT].name)
10368 vty_out(vty,
10369 " Route map for outgoing advertisements is %s%s\n",
10370 filter->map[RMAP_OUT].map ? "*" : "",
10371 filter->map[RMAP_OUT].name);
10372
10373 /* ebgp-requires-policy (inbound) */
10374 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
10375 && !bgp_inbound_policy_exists(p, filter))
10376 vty_out(vty,
10377 " Inbound updates discarded due to missing policy\n");
10378
10379 /* ebgp-requires-policy (outbound) */
10380 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
10381 && !bgp_outbound_policy_exists(p, filter))
10382 vty_out(vty,
10383 " Outbound updates discarded due to missing policy\n");
10384
10385 /* unsuppress-map */
10386 if (filter->usmap.name)
10387 vty_out(vty,
10388 " Route map for selective unsuppress is %s%s\n",
10389 filter->usmap.map ? "*" : "",
10390 filter->usmap.name);
10391
10392 /* Receive prefix count */
10393 vty_out(vty, " %" PRIu32 " accepted prefixes\n",
10394 p->pcount[afi][safi]);
10395
10396 /* maximum-prefix-out */
10397 if (CHECK_FLAG(p->af_flags[afi][safi],
10398 PEER_FLAG_MAX_PREFIX_OUT))
10399 vty_out(vty,
10400 " Maximum allowed prefixes sent %" PRIu32 "\n",
10401 p->pmax_out[afi][safi]);
10402
10403 /* Maximum prefix */
10404 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
10405 vty_out(vty,
10406 " Maximum prefixes allowed %" PRIu32 "%s\n",
10407 p->pmax[afi][safi],
10408 CHECK_FLAG(p->af_flags[afi][safi],
10409 PEER_FLAG_MAX_PREFIX_WARNING)
10410 ? " (warning-only)"
10411 : "");
10412 vty_out(vty, " Threshold for warning message %d%%",
10413 p->pmax_threshold[afi][safi]);
10414 if (p->pmax_restart[afi][safi])
10415 vty_out(vty, ", restart interval %d min",
10416 p->pmax_restart[afi][safi]);
10417 vty_out(vty, "\n");
10418 }
10419
10420 vty_out(vty, "\n");
10421 }
10422 }
10423
10424 static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
10425 json_object *json)
10426 {
10427 struct bgp *bgp;
10428 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
10429 char timebuf[BGP_UPTIME_LEN];
10430 char dn_flag[2];
10431 afi_t afi;
10432 safi_t safi;
10433 uint16_t i;
10434 uint8_t *msg;
10435 json_object *json_neigh = NULL;
10436 time_t epoch_tbuf;
10437
10438 bgp = p->bgp;
10439
10440 if (use_json)
10441 json_neigh = json_object_new_object();
10442
10443 memset(dn_flag, '\0', sizeof(dn_flag));
10444 if (!p->conf_if && peer_dynamic_neighbor(p))
10445 dn_flag[0] = '*';
10446
10447 if (!use_json) {
10448 if (p->conf_if) /* Configured interface name. */
10449 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
10450 BGP_PEER_SU_UNSPEC(p)
10451 ? "None"
10452 : sockunion2str(&p->su, buf,
10453 SU_ADDRSTRLEN));
10454 else /* Configured IP address. */
10455 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
10456 p->host);
10457 }
10458
10459 if (use_json) {
10460 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
10461 json_object_string_add(json_neigh, "bgpNeighborAddr",
10462 "none");
10463 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
10464 json_object_string_add(
10465 json_neigh, "bgpNeighborAddr",
10466 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
10467
10468 json_object_int_add(json_neigh, "remoteAs", p->as);
10469
10470 if (p->change_local_as)
10471 json_object_int_add(json_neigh, "localAs",
10472 p->change_local_as);
10473 else
10474 json_object_int_add(json_neigh, "localAs", p->local_as);
10475
10476 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
10477 json_object_boolean_true_add(json_neigh,
10478 "localAsNoPrepend");
10479
10480 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
10481 json_object_boolean_true_add(json_neigh,
10482 "localAsReplaceAs");
10483 } else {
10484 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
10485 || (p->as_type == AS_INTERNAL))
10486 vty_out(vty, "remote AS %u, ", p->as);
10487 else
10488 vty_out(vty, "remote AS Unspecified, ");
10489 vty_out(vty, "local AS %u%s%s, ",
10490 p->change_local_as ? p->change_local_as : p->local_as,
10491 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
10492 ? " no-prepend"
10493 : "",
10494 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
10495 ? " replace-as"
10496 : "");
10497 }
10498 /* peer type internal or confed-internal */
10499 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
10500 if (use_json) {
10501 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
10502 json_object_boolean_true_add(
10503 json_neigh, "nbrConfedInternalLink");
10504 else
10505 json_object_boolean_true_add(json_neigh,
10506 "nbrInternalLink");
10507 } else {
10508 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
10509 vty_out(vty, "confed-internal link\n");
10510 else
10511 vty_out(vty, "internal link\n");
10512 }
10513 /* peer type external or confed-external */
10514 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
10515 if (use_json) {
10516 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
10517 json_object_boolean_true_add(
10518 json_neigh, "nbrConfedExternalLink");
10519 else
10520 json_object_boolean_true_add(json_neigh,
10521 "nbrExternalLink");
10522 } else {
10523 if (bgp_confederation_peers_check(bgp, p->as))
10524 vty_out(vty, "confed-external link\n");
10525 else
10526 vty_out(vty, "external link\n");
10527 }
10528 } else {
10529 if (use_json)
10530 json_object_boolean_true_add(json_neigh,
10531 "nbrUnspecifiedLink");
10532 else
10533 vty_out(vty, "unspecified link\n");
10534 }
10535
10536 /* Description. */
10537 if (p->desc) {
10538 if (use_json)
10539 json_object_string_add(json_neigh, "nbrDesc", p->desc);
10540 else
10541 vty_out(vty, " Description: %s\n", p->desc);
10542 }
10543
10544 if (p->hostname) {
10545 if (use_json) {
10546 if (p->hostname)
10547 json_object_string_add(json_neigh, "hostname",
10548 p->hostname);
10549
10550 if (p->domainname)
10551 json_object_string_add(json_neigh, "domainname",
10552 p->domainname);
10553 } else {
10554 if (p->domainname && (p->domainname[0] != '\0'))
10555 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
10556 p->domainname);
10557 else
10558 vty_out(vty, "Hostname: %s\n", p->hostname);
10559 }
10560 }
10561
10562 /* Peer-group */
10563 if (p->group) {
10564 if (use_json) {
10565 json_object_string_add(json_neigh, "peerGroup",
10566 p->group->name);
10567
10568 if (dn_flag[0]) {
10569 struct prefix prefix, *range = NULL;
10570
10571 sockunion2hostprefix(&(p->su), &prefix);
10572 range = peer_group_lookup_dynamic_neighbor_range(
10573 p->group, &prefix);
10574
10575 if (range) {
10576 prefix2str(range, buf1, sizeof(buf1));
10577 json_object_string_add(
10578 json_neigh,
10579 "peerSubnetRangeGroup", buf1);
10580 }
10581 }
10582 } else {
10583 vty_out(vty,
10584 " Member of peer-group %s for session parameters\n",
10585 p->group->name);
10586
10587 if (dn_flag[0]) {
10588 struct prefix prefix, *range = NULL;
10589
10590 sockunion2hostprefix(&(p->su), &prefix);
10591 range = peer_group_lookup_dynamic_neighbor_range(
10592 p->group, &prefix);
10593
10594 if (range) {
10595 prefix2str(range, buf1, sizeof(buf1));
10596 vty_out(vty,
10597 " Belongs to the subnet range group: %s\n",
10598 buf1);
10599 }
10600 }
10601 }
10602 }
10603
10604 if (use_json) {
10605 /* Administrative shutdown. */
10606 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
10607 json_object_boolean_true_add(json_neigh,
10608 "adminShutDown");
10609
10610 /* BGP Version. */
10611 json_object_int_add(json_neigh, "bgpVersion", 4);
10612 json_object_string_add(
10613 json_neigh, "remoteRouterId",
10614 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
10615 json_object_string_add(
10616 json_neigh, "localRouterId",
10617 inet_ntop(AF_INET, &bgp->router_id, buf1,
10618 sizeof(buf1)));
10619
10620 /* Confederation */
10621 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
10622 && bgp_confederation_peers_check(bgp, p->as))
10623 json_object_boolean_true_add(json_neigh,
10624 "nbrCommonAdmin");
10625
10626 /* Status. */
10627 json_object_string_add(
10628 json_neigh, "bgpState",
10629 lookup_msg(bgp_status_msg, p->status, NULL));
10630
10631 if (p->status == Established) {
10632 time_t uptime;
10633
10634 uptime = bgp_clock();
10635 uptime -= p->uptime;
10636 epoch_tbuf = time(NULL) - uptime;
10637
10638 json_object_int_add(json_neigh, "bgpTimerUpMsec",
10639 uptime * 1000);
10640 json_object_string_add(json_neigh, "bgpTimerUpString",
10641 peer_uptime(p->uptime, timebuf,
10642 BGP_UPTIME_LEN, 0,
10643 NULL));
10644 json_object_int_add(json_neigh,
10645 "bgpTimerUpEstablishedEpoch",
10646 epoch_tbuf);
10647 }
10648
10649 else if (p->status == Active) {
10650 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
10651 json_object_string_add(json_neigh, "bgpStateIs",
10652 "passive");
10653 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
10654 json_object_string_add(json_neigh, "bgpStateIs",
10655 "passiveNSF");
10656 }
10657
10658 /* read timer */
10659 time_t uptime;
10660 struct tm *tm;
10661
10662 uptime = bgp_clock();
10663 uptime -= p->readtime;
10664 tm = gmtime(&uptime);
10665 json_object_int_add(json_neigh, "bgpTimerLastRead",
10666 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
10667 + (tm->tm_hour * 3600000));
10668
10669 uptime = bgp_clock();
10670 uptime -= p->last_write;
10671 tm = gmtime(&uptime);
10672 json_object_int_add(json_neigh, "bgpTimerLastWrite",
10673 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
10674 + (tm->tm_hour * 3600000));
10675
10676 uptime = bgp_clock();
10677 uptime -= p->update_time;
10678 tm = gmtime(&uptime);
10679 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
10680 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
10681 + (tm->tm_hour * 3600000));
10682
10683 /* Configured timer values. */
10684 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
10685 p->v_holdtime * 1000);
10686 json_object_int_add(json_neigh,
10687 "bgpTimerKeepAliveIntervalMsecs",
10688 p->v_keepalive * 1000);
10689 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
10690 json_object_int_add(json_neigh,
10691 "bgpTimerConfiguredHoldTimeMsecs",
10692 p->holdtime * 1000);
10693 json_object_int_add(
10694 json_neigh,
10695 "bgpTimerConfiguredKeepAliveIntervalMsecs",
10696 p->keepalive * 1000);
10697 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
10698 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
10699 json_object_int_add(json_neigh,
10700 "bgpTimerConfiguredHoldTimeMsecs",
10701 bgp->default_holdtime);
10702 json_object_int_add(
10703 json_neigh,
10704 "bgpTimerConfiguredKeepAliveIntervalMsecs",
10705 bgp->default_keepalive);
10706 }
10707 } else {
10708 /* Administrative shutdown. */
10709 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
10710 vty_out(vty, " Administratively shut down\n");
10711
10712 /* BGP Version. */
10713 vty_out(vty, " BGP version 4");
10714 vty_out(vty, ", remote router ID %s",
10715 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
10716 vty_out(vty, ", local router ID %s\n",
10717 inet_ntop(AF_INET, &bgp->router_id, buf1,
10718 sizeof(buf1)));
10719
10720 /* Confederation */
10721 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
10722 && bgp_confederation_peers_check(bgp, p->as))
10723 vty_out(vty,
10724 " Neighbor under common administration\n");
10725
10726 /* Status. */
10727 vty_out(vty, " BGP state = %s",
10728 lookup_msg(bgp_status_msg, p->status, NULL));
10729
10730 if (p->status == Established)
10731 vty_out(vty, ", up for %8s",
10732 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
10733 0, NULL));
10734
10735 else if (p->status == Active) {
10736 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
10737 vty_out(vty, " (passive)");
10738 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
10739 vty_out(vty, " (NSF passive)");
10740 }
10741 vty_out(vty, "\n");
10742
10743 /* read timer */
10744 vty_out(vty, " Last read %s",
10745 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
10746 NULL));
10747 vty_out(vty, ", Last write %s\n",
10748 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
10749 NULL));
10750
10751 /* Configured timer values. */
10752 vty_out(vty,
10753 " Hold time is %d, keepalive interval is %d seconds\n",
10754 p->v_holdtime, p->v_keepalive);
10755 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
10756 vty_out(vty, " Configured hold time is %d",
10757 p->holdtime);
10758 vty_out(vty, ", keepalive interval is %d seconds\n",
10759 p->keepalive);
10760 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
10761 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
10762 vty_out(vty, " Configured hold time is %d",
10763 bgp->default_holdtime);
10764 vty_out(vty, ", keepalive interval is %d seconds\n",
10765 bgp->default_keepalive);
10766 }
10767 }
10768 /* Capability. */
10769 if (p->status == Established) {
10770 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
10771 || p->afc_recv[AFI_IP][SAFI_UNICAST]
10772 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
10773 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
10774 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
10775 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
10776 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
10777 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
10778 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
10779 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
10780 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
10781 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
10782 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
10783 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
10784 || p->afc_adv[AFI_IP][SAFI_ENCAP]
10785 || p->afc_recv[AFI_IP][SAFI_ENCAP]
10786 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
10787 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
10788 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
10789 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
10790 if (use_json) {
10791 json_object *json_cap = NULL;
10792
10793 json_cap = json_object_new_object();
10794
10795 /* AS4 */
10796 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
10797 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
10798 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
10799 && CHECK_FLAG(p->cap,
10800 PEER_CAP_AS4_RCV))
10801 json_object_string_add(
10802 json_cap, "4byteAs",
10803 "advertisedAndReceived");
10804 else if (CHECK_FLAG(p->cap,
10805 PEER_CAP_AS4_ADV))
10806 json_object_string_add(
10807 json_cap, "4byteAs",
10808 "advertised");
10809 else if (CHECK_FLAG(p->cap,
10810 PEER_CAP_AS4_RCV))
10811 json_object_string_add(
10812 json_cap, "4byteAs",
10813 "received");
10814 }
10815
10816 /* AddPath */
10817 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
10818 || CHECK_FLAG(p->cap,
10819 PEER_CAP_ADDPATH_ADV)) {
10820 json_object *json_add = NULL;
10821 const char *print_store;
10822
10823 json_add = json_object_new_object();
10824
10825 FOREACH_AFI_SAFI (afi, safi) {
10826 json_object *json_sub = NULL;
10827 json_sub =
10828 json_object_new_object();
10829 print_store = get_afi_safi_str(
10830 afi, safi, true);
10831
10832 if (CHECK_FLAG(
10833 p->af_cap[afi]
10834 [safi],
10835 PEER_CAP_ADDPATH_AF_TX_ADV)
10836 || CHECK_FLAG(
10837 p->af_cap[afi]
10838 [safi],
10839 PEER_CAP_ADDPATH_AF_TX_RCV)) {
10840 if (CHECK_FLAG(
10841 p->af_cap
10842 [afi]
10843 [safi],
10844 PEER_CAP_ADDPATH_AF_TX_ADV)
10845 && CHECK_FLAG(
10846 p->af_cap
10847 [afi]
10848 [safi],
10849 PEER_CAP_ADDPATH_AF_TX_RCV))
10850 json_object_boolean_true_add(
10851 json_sub,
10852 "txAdvertisedAndReceived");
10853 else if (
10854 CHECK_FLAG(
10855 p->af_cap
10856 [afi]
10857 [safi],
10858 PEER_CAP_ADDPATH_AF_TX_ADV))
10859 json_object_boolean_true_add(
10860 json_sub,
10861 "txAdvertised");
10862 else if (
10863 CHECK_FLAG(
10864 p->af_cap
10865 [afi]
10866 [safi],
10867 PEER_CAP_ADDPATH_AF_TX_RCV))
10868 json_object_boolean_true_add(
10869 json_sub,
10870 "txReceived");
10871 }
10872
10873 if (CHECK_FLAG(
10874 p->af_cap[afi]
10875 [safi],
10876 PEER_CAP_ADDPATH_AF_RX_ADV)
10877 || CHECK_FLAG(
10878 p->af_cap[afi]
10879 [safi],
10880 PEER_CAP_ADDPATH_AF_RX_RCV)) {
10881 if (CHECK_FLAG(
10882 p->af_cap
10883 [afi]
10884 [safi],
10885 PEER_CAP_ADDPATH_AF_RX_ADV)
10886 && CHECK_FLAG(
10887 p->af_cap
10888 [afi]
10889 [safi],
10890 PEER_CAP_ADDPATH_AF_RX_RCV))
10891 json_object_boolean_true_add(
10892 json_sub,
10893 "rxAdvertisedAndReceived");
10894 else if (
10895 CHECK_FLAG(
10896 p->af_cap
10897 [afi]
10898 [safi],
10899 PEER_CAP_ADDPATH_AF_RX_ADV))
10900 json_object_boolean_true_add(
10901 json_sub,
10902 "rxAdvertised");
10903 else if (
10904 CHECK_FLAG(
10905 p->af_cap
10906 [afi]
10907 [safi],
10908 PEER_CAP_ADDPATH_AF_RX_RCV))
10909 json_object_boolean_true_add(
10910 json_sub,
10911 "rxReceived");
10912 }
10913
10914 if (CHECK_FLAG(
10915 p->af_cap[afi]
10916 [safi],
10917 PEER_CAP_ADDPATH_AF_TX_ADV)
10918 || CHECK_FLAG(
10919 p->af_cap[afi]
10920 [safi],
10921 PEER_CAP_ADDPATH_AF_TX_RCV)
10922 || CHECK_FLAG(
10923 p->af_cap[afi]
10924 [safi],
10925 PEER_CAP_ADDPATH_AF_RX_ADV)
10926 || CHECK_FLAG(
10927 p->af_cap[afi]
10928 [safi],
10929 PEER_CAP_ADDPATH_AF_RX_RCV))
10930 json_object_object_add(
10931 json_add,
10932 print_store,
10933 json_sub);
10934 else
10935 json_object_free(
10936 json_sub);
10937 }
10938
10939 json_object_object_add(
10940 json_cap, "addPath", json_add);
10941 }
10942
10943 /* Dynamic */
10944 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
10945 || CHECK_FLAG(p->cap,
10946 PEER_CAP_DYNAMIC_ADV)) {
10947 if (CHECK_FLAG(p->cap,
10948 PEER_CAP_DYNAMIC_ADV)
10949 && CHECK_FLAG(p->cap,
10950 PEER_CAP_DYNAMIC_RCV))
10951 json_object_string_add(
10952 json_cap, "dynamic",
10953 "advertisedAndReceived");
10954 else if (CHECK_FLAG(
10955 p->cap,
10956 PEER_CAP_DYNAMIC_ADV))
10957 json_object_string_add(
10958 json_cap, "dynamic",
10959 "advertised");
10960 else if (CHECK_FLAG(
10961 p->cap,
10962 PEER_CAP_DYNAMIC_RCV))
10963 json_object_string_add(
10964 json_cap, "dynamic",
10965 "received");
10966 }
10967
10968 /* Extended nexthop */
10969 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
10970 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
10971 json_object *json_nxt = NULL;
10972 const char *print_store;
10973
10974
10975 if (CHECK_FLAG(p->cap,
10976 PEER_CAP_ENHE_ADV)
10977 && CHECK_FLAG(p->cap,
10978 PEER_CAP_ENHE_RCV))
10979 json_object_string_add(
10980 json_cap,
10981 "extendedNexthop",
10982 "advertisedAndReceived");
10983 else if (CHECK_FLAG(p->cap,
10984 PEER_CAP_ENHE_ADV))
10985 json_object_string_add(
10986 json_cap,
10987 "extendedNexthop",
10988 "advertised");
10989 else if (CHECK_FLAG(p->cap,
10990 PEER_CAP_ENHE_RCV))
10991 json_object_string_add(
10992 json_cap,
10993 "extendedNexthop",
10994 "received");
10995
10996 if (CHECK_FLAG(p->cap,
10997 PEER_CAP_ENHE_RCV)) {
10998 json_nxt =
10999 json_object_new_object();
11000
11001 for (safi = SAFI_UNICAST;
11002 safi < SAFI_MAX; safi++) {
11003 if (CHECK_FLAG(
11004 p->af_cap
11005 [AFI_IP]
11006 [safi],
11007 PEER_CAP_ENHE_AF_RCV)) {
11008 print_store = get_afi_safi_str(
11009 AFI_IP,
11010 safi, true);
11011 json_object_string_add(
11012 json_nxt,
11013 print_store,
11014 "recieved"); /* misspelled for compatibility */
11015 }
11016 }
11017 json_object_object_add(
11018 json_cap,
11019 "extendedNexthopFamililesByPeer",
11020 json_nxt);
11021 }
11022 }
11023
11024 /* Route Refresh */
11025 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
11026 || CHECK_FLAG(p->cap,
11027 PEER_CAP_REFRESH_NEW_RCV)
11028 || CHECK_FLAG(p->cap,
11029 PEER_CAP_REFRESH_OLD_RCV)) {
11030 if (CHECK_FLAG(p->cap,
11031 PEER_CAP_REFRESH_ADV)
11032 && (CHECK_FLAG(
11033 p->cap,
11034 PEER_CAP_REFRESH_NEW_RCV)
11035 || CHECK_FLAG(
11036 p->cap,
11037 PEER_CAP_REFRESH_OLD_RCV))) {
11038 if (CHECK_FLAG(
11039 p->cap,
11040 PEER_CAP_REFRESH_OLD_RCV)
11041 && CHECK_FLAG(
11042 p->cap,
11043 PEER_CAP_REFRESH_NEW_RCV))
11044 json_object_string_add(
11045 json_cap,
11046 "routeRefresh",
11047 "advertisedAndReceivedOldNew");
11048 else {
11049 if (CHECK_FLAG(
11050 p->cap,
11051 PEER_CAP_REFRESH_OLD_RCV))
11052 json_object_string_add(
11053 json_cap,
11054 "routeRefresh",
11055 "advertisedAndReceivedOld");
11056 else
11057 json_object_string_add(
11058 json_cap,
11059 "routeRefresh",
11060 "advertisedAndReceivedNew");
11061 }
11062 } else if (
11063 CHECK_FLAG(
11064 p->cap,
11065 PEER_CAP_REFRESH_ADV))
11066 json_object_string_add(
11067 json_cap,
11068 "routeRefresh",
11069 "advertised");
11070 else if (
11071 CHECK_FLAG(
11072 p->cap,
11073 PEER_CAP_REFRESH_NEW_RCV)
11074 || CHECK_FLAG(
11075 p->cap,
11076 PEER_CAP_REFRESH_OLD_RCV))
11077 json_object_string_add(
11078 json_cap,
11079 "routeRefresh",
11080 "received");
11081 }
11082
11083 /* Multiprotocol Extensions */
11084 json_object *json_multi = NULL;
11085 json_multi = json_object_new_object();
11086
11087 FOREACH_AFI_SAFI (afi, safi) {
11088 if (p->afc_adv[afi][safi]
11089 || p->afc_recv[afi][safi]) {
11090 json_object *json_exten = NULL;
11091 json_exten =
11092 json_object_new_object();
11093
11094 if (p->afc_adv[afi][safi]
11095 && p->afc_recv[afi][safi])
11096 json_object_boolean_true_add(
11097 json_exten,
11098 "advertisedAndReceived");
11099 else if (p->afc_adv[afi][safi])
11100 json_object_boolean_true_add(
11101 json_exten,
11102 "advertised");
11103 else if (p->afc_recv[afi][safi])
11104 json_object_boolean_true_add(
11105 json_exten,
11106 "received");
11107
11108 json_object_object_add(
11109 json_multi,
11110 get_afi_safi_str(afi,
11111 safi,
11112 true),
11113 json_exten);
11114 }
11115 }
11116 json_object_object_add(
11117 json_cap, "multiprotocolExtensions",
11118 json_multi);
11119
11120 /* Hostname capabilities */
11121 json_object *json_hname = NULL;
11122
11123 json_hname = json_object_new_object();
11124
11125 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
11126 json_object_string_add(
11127 json_hname, "advHostName",
11128 bgp->peer_self->hostname
11129 ? bgp->peer_self
11130 ->hostname
11131 : "n/a");
11132 json_object_string_add(
11133 json_hname, "advDomainName",
11134 bgp->peer_self->domainname
11135 ? bgp->peer_self
11136 ->domainname
11137 : "n/a");
11138 }
11139
11140
11141 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
11142 json_object_string_add(
11143 json_hname, "rcvHostName",
11144 p->hostname ? p->hostname
11145 : "n/a");
11146 json_object_string_add(
11147 json_hname, "rcvDomainName",
11148 p->domainname ? p->domainname
11149 : "n/a");
11150 }
11151
11152 json_object_object_add(json_cap, "hostName",
11153 json_hname);
11154
11155 /* Gracefull Restart */
11156 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
11157 || CHECK_FLAG(p->cap,
11158 PEER_CAP_RESTART_ADV)) {
11159 if (CHECK_FLAG(p->cap,
11160 PEER_CAP_RESTART_ADV)
11161 && CHECK_FLAG(p->cap,
11162 PEER_CAP_RESTART_RCV))
11163 json_object_string_add(
11164 json_cap,
11165 "gracefulRestart",
11166 "advertisedAndReceived");
11167 else if (CHECK_FLAG(
11168 p->cap,
11169 PEER_CAP_RESTART_ADV))
11170 json_object_string_add(
11171 json_cap,
11172 "gracefulRestartCapability",
11173 "advertised");
11174 else if (CHECK_FLAG(
11175 p->cap,
11176 PEER_CAP_RESTART_RCV))
11177 json_object_string_add(
11178 json_cap,
11179 "gracefulRestartCapability",
11180 "received");
11181
11182 if (CHECK_FLAG(p->cap,
11183 PEER_CAP_RESTART_RCV)) {
11184 int restart_af_count = 0;
11185 json_object *json_restart =
11186 NULL;
11187 json_restart =
11188 json_object_new_object();
11189
11190 json_object_int_add(
11191 json_cap,
11192 "gracefulRestartRemoteTimerMsecs",
11193 p->v_gr_restart * 1000);
11194
11195 FOREACH_AFI_SAFI (afi, safi) {
11196 if (CHECK_FLAG(
11197 p->af_cap
11198 [afi]
11199 [safi],
11200 PEER_CAP_RESTART_AF_RCV)) {
11201 json_object *
11202 json_sub =
11203 NULL;
11204 json_sub =
11205 json_object_new_object();
11206
11207 if (CHECK_FLAG(
11208 p->af_cap
11209 [afi]
11210 [safi],
11211 PEER_CAP_RESTART_AF_PRESERVE_RCV))
11212 json_object_boolean_true_add(
11213 json_sub,
11214 "preserved");
11215 restart_af_count++;
11216 json_object_object_add(
11217 json_restart,
11218 get_afi_safi_str(
11219 afi,
11220 safi,
11221 true),
11222 json_sub);
11223 }
11224 }
11225 if (!restart_af_count) {
11226 json_object_string_add(
11227 json_cap,
11228 "addressFamiliesByPeer",
11229 "none");
11230 json_object_free(
11231 json_restart);
11232 } else
11233 json_object_object_add(
11234 json_cap,
11235 "addressFamiliesByPeer",
11236 json_restart);
11237 }
11238 }
11239 json_object_object_add(json_neigh,
11240 "neighborCapabilities",
11241 json_cap);
11242 } else {
11243 vty_out(vty, " Neighbor capabilities:\n");
11244
11245 /* AS4 */
11246 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
11247 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
11248 vty_out(vty, " 4 Byte AS:");
11249 if (CHECK_FLAG(p->cap,
11250 PEER_CAP_AS4_ADV))
11251 vty_out(vty, " advertised");
11252 if (CHECK_FLAG(p->cap,
11253 PEER_CAP_AS4_RCV))
11254 vty_out(vty, " %sreceived",
11255 CHECK_FLAG(
11256 p->cap,
11257 PEER_CAP_AS4_ADV)
11258 ? "and "
11259 : "");
11260 vty_out(vty, "\n");
11261 }
11262
11263 /* AddPath */
11264 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
11265 || CHECK_FLAG(p->cap,
11266 PEER_CAP_ADDPATH_ADV)) {
11267 vty_out(vty, " AddPath:\n");
11268
11269 FOREACH_AFI_SAFI (afi, safi) {
11270 if (CHECK_FLAG(
11271 p->af_cap[afi]
11272 [safi],
11273 PEER_CAP_ADDPATH_AF_TX_ADV)
11274 || CHECK_FLAG(
11275 p->af_cap[afi]
11276 [safi],
11277 PEER_CAP_ADDPATH_AF_TX_RCV)) {
11278 vty_out(vty,
11279 " %s: TX ",
11280 get_afi_safi_str(
11281 afi,
11282 safi,
11283 false));
11284
11285 if (CHECK_FLAG(
11286 p->af_cap
11287 [afi]
11288 [safi],
11289 PEER_CAP_ADDPATH_AF_TX_ADV))
11290 vty_out(vty,
11291 "advertised %s",
11292 get_afi_safi_str(
11293 afi,
11294 safi,
11295 false));
11296
11297 if (CHECK_FLAG(
11298 p->af_cap
11299 [afi]
11300 [safi],
11301 PEER_CAP_ADDPATH_AF_TX_RCV))
11302 vty_out(vty,
11303 "%sreceived",
11304 CHECK_FLAG(
11305 p->af_cap
11306 [afi]
11307 [safi],
11308 PEER_CAP_ADDPATH_AF_TX_ADV)
11309 ? " and "
11310 : "");
11311
11312 vty_out(vty, "\n");
11313 }
11314
11315 if (CHECK_FLAG(
11316 p->af_cap[afi]
11317 [safi],
11318 PEER_CAP_ADDPATH_AF_RX_ADV)
11319 || CHECK_FLAG(
11320 p->af_cap[afi]
11321 [safi],
11322 PEER_CAP_ADDPATH_AF_RX_RCV)) {
11323 vty_out(vty,
11324 " %s: RX ",
11325 get_afi_safi_str(
11326 afi,
11327 safi,
11328 false));
11329
11330 if (CHECK_FLAG(
11331 p->af_cap
11332 [afi]
11333 [safi],
11334 PEER_CAP_ADDPATH_AF_RX_ADV))
11335 vty_out(vty,
11336 "advertised %s",
11337 get_afi_safi_str(
11338 afi,
11339 safi,
11340 false));
11341
11342 if (CHECK_FLAG(
11343 p->af_cap
11344 [afi]
11345 [safi],
11346 PEER_CAP_ADDPATH_AF_RX_RCV))
11347 vty_out(vty,
11348 "%sreceived",
11349 CHECK_FLAG(
11350 p->af_cap
11351 [afi]
11352 [safi],
11353 PEER_CAP_ADDPATH_AF_RX_ADV)
11354 ? " and "
11355 : "");
11356
11357 vty_out(vty, "\n");
11358 }
11359 }
11360 }
11361
11362 /* Dynamic */
11363 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
11364 || CHECK_FLAG(p->cap,
11365 PEER_CAP_DYNAMIC_ADV)) {
11366 vty_out(vty, " Dynamic:");
11367 if (CHECK_FLAG(p->cap,
11368 PEER_CAP_DYNAMIC_ADV))
11369 vty_out(vty, " advertised");
11370 if (CHECK_FLAG(p->cap,
11371 PEER_CAP_DYNAMIC_RCV))
11372 vty_out(vty, " %sreceived",
11373 CHECK_FLAG(
11374 p->cap,
11375 PEER_CAP_DYNAMIC_ADV)
11376 ? "and "
11377 : "");
11378 vty_out(vty, "\n");
11379 }
11380
11381 /* Extended nexthop */
11382 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
11383 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
11384 vty_out(vty, " Extended nexthop:");
11385 if (CHECK_FLAG(p->cap,
11386 PEER_CAP_ENHE_ADV))
11387 vty_out(vty, " advertised");
11388 if (CHECK_FLAG(p->cap,
11389 PEER_CAP_ENHE_RCV))
11390 vty_out(vty, " %sreceived",
11391 CHECK_FLAG(
11392 p->cap,
11393 PEER_CAP_ENHE_ADV)
11394 ? "and "
11395 : "");
11396 vty_out(vty, "\n");
11397
11398 if (CHECK_FLAG(p->cap,
11399 PEER_CAP_ENHE_RCV)) {
11400 vty_out(vty,
11401 " Address families by peer:\n ");
11402 for (safi = SAFI_UNICAST;
11403 safi < SAFI_MAX; safi++)
11404 if (CHECK_FLAG(
11405 p->af_cap
11406 [AFI_IP]
11407 [safi],
11408 PEER_CAP_ENHE_AF_RCV))
11409 vty_out(vty,
11410 " %s\n",
11411 get_afi_safi_str(
11412 AFI_IP,
11413 safi,
11414 false));
11415 }
11416 }
11417
11418 /* Route Refresh */
11419 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
11420 || CHECK_FLAG(p->cap,
11421 PEER_CAP_REFRESH_NEW_RCV)
11422 || CHECK_FLAG(p->cap,
11423 PEER_CAP_REFRESH_OLD_RCV)) {
11424 vty_out(vty, " Route refresh:");
11425 if (CHECK_FLAG(p->cap,
11426 PEER_CAP_REFRESH_ADV))
11427 vty_out(vty, " advertised");
11428 if (CHECK_FLAG(p->cap,
11429 PEER_CAP_REFRESH_NEW_RCV)
11430 || CHECK_FLAG(
11431 p->cap,
11432 PEER_CAP_REFRESH_OLD_RCV))
11433 vty_out(vty, " %sreceived(%s)",
11434 CHECK_FLAG(
11435 p->cap,
11436 PEER_CAP_REFRESH_ADV)
11437 ? "and "
11438 : "",
11439 (CHECK_FLAG(
11440 p->cap,
11441 PEER_CAP_REFRESH_OLD_RCV)
11442 && CHECK_FLAG(
11443 p->cap,
11444 PEER_CAP_REFRESH_NEW_RCV))
11445 ? "old & new"
11446 : CHECK_FLAG(
11447 p->cap,
11448 PEER_CAP_REFRESH_OLD_RCV)
11449 ? "old"
11450 : "new");
11451
11452 vty_out(vty, "\n");
11453 }
11454
11455 /* Multiprotocol Extensions */
11456 FOREACH_AFI_SAFI (afi, safi)
11457 if (p->afc_adv[afi][safi]
11458 || p->afc_recv[afi][safi]) {
11459 vty_out(vty,
11460 " Address Family %s:",
11461 get_afi_safi_str(
11462 afi,
11463 safi,
11464 false));
11465 if (p->afc_adv[afi][safi])
11466 vty_out(vty,
11467 " advertised");
11468 if (p->afc_recv[afi][safi])
11469 vty_out(vty,
11470 " %sreceived",
11471 p->afc_adv[afi]
11472 [safi]
11473 ? "and "
11474 : "");
11475 vty_out(vty, "\n");
11476 }
11477
11478 /* Hostname capability */
11479 vty_out(vty, " Hostname Capability:");
11480
11481 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
11482 vty_out(vty,
11483 " advertised (name: %s,domain name: %s)",
11484 bgp->peer_self->hostname
11485 ? bgp->peer_self
11486 ->hostname
11487 : "n/a",
11488 bgp->peer_self->domainname
11489 ? bgp->peer_self
11490 ->domainname
11491 : "n/a");
11492 } else {
11493 vty_out(vty, " not advertised");
11494 }
11495
11496 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
11497 vty_out(vty,
11498 " received (name: %s,domain name: %s)",
11499 p->hostname ? p->hostname
11500 : "n/a",
11501 p->domainname ? p->domainname
11502 : "n/a");
11503 } else {
11504 vty_out(vty, " not received");
11505 }
11506
11507 vty_out(vty, "\n");
11508
11509 /* Graceful Restart */
11510 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
11511 || CHECK_FLAG(p->cap,
11512 PEER_CAP_RESTART_ADV)) {
11513 vty_out(vty,
11514 " Graceful Restart Capability:");
11515 if (CHECK_FLAG(p->cap,
11516 PEER_CAP_RESTART_ADV))
11517 vty_out(vty, " advertised");
11518 if (CHECK_FLAG(p->cap,
11519 PEER_CAP_RESTART_RCV))
11520 vty_out(vty, " %sreceived",
11521 CHECK_FLAG(
11522 p->cap,
11523 PEER_CAP_RESTART_ADV)
11524 ? "and "
11525 : "");
11526 vty_out(vty, "\n");
11527
11528 if (CHECK_FLAG(p->cap,
11529 PEER_CAP_RESTART_RCV)) {
11530 int restart_af_count = 0;
11531
11532 vty_out(vty,
11533 " Remote Restart timer is %d seconds\n",
11534 p->v_gr_restart);
11535 vty_out(vty,
11536 " Address families by peer:\n ");
11537
11538 FOREACH_AFI_SAFI (afi, safi)
11539 if (CHECK_FLAG(
11540 p->af_cap
11541 [afi]
11542 [safi],
11543 PEER_CAP_RESTART_AF_RCV)) {
11544 vty_out(vty,
11545 "%s%s(%s)",
11546 restart_af_count
11547 ? ", "
11548 : "",
11549 get_afi_safi_str(
11550 afi,
11551 safi,
11552 false),
11553 CHECK_FLAG(
11554 p->af_cap
11555 [afi]
11556 [safi],
11557 PEER_CAP_RESTART_AF_PRESERVE_RCV)
11558 ? "preserved"
11559 : "not preserved");
11560 restart_af_count++;
11561 }
11562 if (!restart_af_count)
11563 vty_out(vty, "none");
11564 vty_out(vty, "\n");
11565 }
11566 } /* Gracefull Restart */
11567 }
11568 }
11569 }
11570
11571 /* graceful restart information */
11572 json_object *json_grace = NULL;
11573 json_object *json_grace_send = NULL;
11574 json_object *json_grace_recv = NULL;
11575 int eor_send_af_count = 0;
11576 int eor_receive_af_count = 0;
11577
11578 if (use_json) {
11579 json_grace = json_object_new_object();
11580 json_grace_send = json_object_new_object();
11581 json_grace_recv = json_object_new_object();
11582
11583 if ((p->status == Established)
11584 && CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
11585 FOREACH_AFI_SAFI (afi, safi) {
11586 if (CHECK_FLAG(p->af_sflags[afi][safi],
11587 PEER_STATUS_EOR_SEND)) {
11588 json_object_boolean_true_add(
11589 json_grace_send,
11590 get_afi_safi_str(afi,
11591 safi,
11592 true));
11593 eor_send_af_count++;
11594 }
11595 }
11596 FOREACH_AFI_SAFI (afi, safi) {
11597 if (CHECK_FLAG(
11598 p->af_sflags[afi][safi],
11599 PEER_STATUS_EOR_RECEIVED)) {
11600 json_object_boolean_true_add(
11601 json_grace_recv,
11602 get_afi_safi_str(afi,
11603 safi,
11604 true));
11605 eor_receive_af_count++;
11606 }
11607 }
11608 }
11609 json_object_object_add(json_grace, "endOfRibSend",
11610 json_grace_send);
11611 json_object_object_add(json_grace, "endOfRibRecv",
11612 json_grace_recv);
11613
11614
11615 if (p->t_gr_restart)
11616 json_object_int_add(json_grace,
11617 "gracefulRestartTimerMsecs",
11618 thread_timer_remain_second(
11619 p->t_gr_restart)
11620 * 1000);
11621
11622 if (p->t_gr_stale)
11623 json_object_int_add(
11624 json_grace,
11625 "gracefulStalepathTimerMsecs",
11626 thread_timer_remain_second(
11627 p->t_gr_stale)
11628 * 1000);
11629 /* more gr info in new format */
11630 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json,
11631 json_grace);
11632 json_object_object_add(
11633 json_neigh, "gracefulRestartInfo", json_grace);
11634 } else {
11635 vty_out(vty, " Graceful restart informations:\n");
11636 if ((p->status == Established)
11637 && CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
11638
11639 vty_out(vty, " End-of-RIB send: ");
11640 FOREACH_AFI_SAFI (afi, safi) {
11641 if (CHECK_FLAG(p->af_sflags[afi][safi],
11642 PEER_STATUS_EOR_SEND)) {
11643 vty_out(vty, "%s%s",
11644 eor_send_af_count ? ", "
11645 : "",
11646 get_afi_safi_str(
11647 afi, safi,
11648 false));
11649 eor_send_af_count++;
11650 }
11651 }
11652 vty_out(vty, "\n");
11653 vty_out(vty, " End-of-RIB received: ");
11654 FOREACH_AFI_SAFI (afi, safi) {
11655 if (CHECK_FLAG(
11656 p->af_sflags[afi][safi],
11657 PEER_STATUS_EOR_RECEIVED)) {
11658 vty_out(vty, "%s%s",
11659 eor_receive_af_count
11660 ? ", "
11661 : "",
11662 get_afi_safi_str(afi,
11663 safi,
11664 false));
11665 eor_receive_af_count++;
11666 }
11667 }
11668 vty_out(vty, "\n");
11669 }
11670
11671 if (p->t_gr_restart)
11672 vty_out(vty,
11673 " The remaining time of restart timer is %ld\n",
11674 thread_timer_remain_second(
11675 p->t_gr_restart));
11676
11677 if (p->t_gr_stale)
11678 vty_out(vty,
11679 " The remaining time of stalepath timer is %ld\n",
11680 thread_timer_remain_second(
11681 p->t_gr_stale));
11682
11683 /* more gr info in new format */
11684 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, NULL);
11685 }
11686
11687 if (use_json) {
11688 json_object *json_stat = NULL;
11689 json_stat = json_object_new_object();
11690 /* Packet counts. */
11691 json_object_int_add(json_stat, "depthInq", 0);
11692 json_object_int_add(json_stat, "depthOutq",
11693 (unsigned long)p->obuf->count);
11694 json_object_int_add(json_stat, "opensSent",
11695 atomic_load_explicit(&p->open_out,
11696 memory_order_relaxed));
11697 json_object_int_add(json_stat, "opensRecv",
11698 atomic_load_explicit(&p->open_in,
11699 memory_order_relaxed));
11700 json_object_int_add(json_stat, "notificationsSent",
11701 atomic_load_explicit(&p->notify_out,
11702 memory_order_relaxed));
11703 json_object_int_add(json_stat, "notificationsRecv",
11704 atomic_load_explicit(&p->notify_in,
11705 memory_order_relaxed));
11706 json_object_int_add(json_stat, "updatesSent",
11707 atomic_load_explicit(&p->update_out,
11708 memory_order_relaxed));
11709 json_object_int_add(json_stat, "updatesRecv",
11710 atomic_load_explicit(&p->update_in,
11711 memory_order_relaxed));
11712 json_object_int_add(json_stat, "keepalivesSent",
11713 atomic_load_explicit(&p->keepalive_out,
11714 memory_order_relaxed));
11715 json_object_int_add(json_stat, "keepalivesRecv",
11716 atomic_load_explicit(&p->keepalive_in,
11717 memory_order_relaxed));
11718 json_object_int_add(json_stat, "routeRefreshSent",
11719 atomic_load_explicit(&p->refresh_out,
11720 memory_order_relaxed));
11721 json_object_int_add(json_stat, "routeRefreshRecv",
11722 atomic_load_explicit(&p->refresh_in,
11723 memory_order_relaxed));
11724 json_object_int_add(json_stat, "capabilitySent",
11725 atomic_load_explicit(&p->dynamic_cap_out,
11726 memory_order_relaxed));
11727 json_object_int_add(json_stat, "capabilityRecv",
11728 atomic_load_explicit(&p->dynamic_cap_in,
11729 memory_order_relaxed));
11730 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
11731 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
11732 json_object_object_add(json_neigh, "messageStats", json_stat);
11733 } else {
11734 /* Packet counts. */
11735 vty_out(vty, " Message statistics:\n");
11736 vty_out(vty, " Inq depth is 0\n");
11737 vty_out(vty, " Outq depth is %lu\n",
11738 (unsigned long)p->obuf->count);
11739 vty_out(vty, " Sent Rcvd\n");
11740 vty_out(vty, " Opens: %10d %10d\n",
11741 atomic_load_explicit(&p->open_out,
11742 memory_order_relaxed),
11743 atomic_load_explicit(&p->open_in,
11744 memory_order_relaxed));
11745 vty_out(vty, " Notifications: %10d %10d\n",
11746 atomic_load_explicit(&p->notify_out,
11747 memory_order_relaxed),
11748 atomic_load_explicit(&p->notify_in,
11749 memory_order_relaxed));
11750 vty_out(vty, " Updates: %10d %10d\n",
11751 atomic_load_explicit(&p->update_out,
11752 memory_order_relaxed),
11753 atomic_load_explicit(&p->update_in,
11754 memory_order_relaxed));
11755 vty_out(vty, " Keepalives: %10d %10d\n",
11756 atomic_load_explicit(&p->keepalive_out,
11757 memory_order_relaxed),
11758 atomic_load_explicit(&p->keepalive_in,
11759 memory_order_relaxed));
11760 vty_out(vty, " Route Refresh: %10d %10d\n",
11761 atomic_load_explicit(&p->refresh_out,
11762 memory_order_relaxed),
11763 atomic_load_explicit(&p->refresh_in,
11764 memory_order_relaxed));
11765 vty_out(vty, " Capability: %10d %10d\n",
11766 atomic_load_explicit(&p->dynamic_cap_out,
11767 memory_order_relaxed),
11768 atomic_load_explicit(&p->dynamic_cap_in,
11769 memory_order_relaxed));
11770 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
11771 PEER_TOTAL_RX(p));
11772 }
11773
11774 if (use_json) {
11775 /* advertisement-interval */
11776 json_object_int_add(json_neigh,
11777 "minBtwnAdvertisementRunsTimerMsecs",
11778 p->v_routeadv * 1000);
11779
11780 /* Update-source. */
11781 if (p->update_if || p->update_source) {
11782 if (p->update_if)
11783 json_object_string_add(json_neigh,
11784 "updateSource",
11785 p->update_if);
11786 else if (p->update_source)
11787 json_object_string_add(
11788 json_neigh, "updateSource",
11789 sockunion2str(p->update_source, buf1,
11790 SU_ADDRSTRLEN));
11791 }
11792 } else {
11793 /* advertisement-interval */
11794 vty_out(vty,
11795 " Minimum time between advertisement runs is %d seconds\n",
11796 p->v_routeadv);
11797
11798 /* Update-source. */
11799 if (p->update_if || p->update_source) {
11800 vty_out(vty, " Update source is ");
11801 if (p->update_if)
11802 vty_out(vty, "%s", p->update_if);
11803 else if (p->update_source)
11804 vty_out(vty, "%s",
11805 sockunion2str(p->update_source, buf1,
11806 SU_ADDRSTRLEN));
11807 vty_out(vty, "\n");
11808 }
11809
11810 vty_out(vty, "\n");
11811 }
11812
11813 /* Address Family Information */
11814 json_object *json_hold = NULL;
11815
11816 if (use_json)
11817 json_hold = json_object_new_object();
11818
11819 FOREACH_AFI_SAFI (afi, safi)
11820 if (p->afc[afi][safi])
11821 bgp_show_peer_afi(vty, p, afi, safi, use_json,
11822 json_hold);
11823
11824 if (use_json) {
11825 json_object_object_add(json_neigh, "addressFamilyInfo",
11826 json_hold);
11827 json_object_int_add(json_neigh, "connectionsEstablished",
11828 p->established);
11829 json_object_int_add(json_neigh, "connectionsDropped",
11830 p->dropped);
11831 } else
11832 vty_out(vty, " Connections established %d; dropped %d\n",
11833 p->established, p->dropped);
11834
11835 if (!p->last_reset) {
11836 if (use_json)
11837 json_object_string_add(json_neigh, "lastReset",
11838 "never");
11839 else
11840 vty_out(vty, " Last reset never\n");
11841 } else {
11842 if (use_json) {
11843 time_t uptime;
11844 struct tm *tm;
11845
11846 uptime = bgp_clock();
11847 uptime -= p->resettime;
11848 tm = gmtime(&uptime);
11849 json_object_int_add(json_neigh, "lastResetTimerMsecs",
11850 (tm->tm_sec * 1000)
11851 + (tm->tm_min * 60000)
11852 + (tm->tm_hour * 3600000));
11853 bgp_show_peer_reset(NULL, p, json_neigh, true);
11854 } else {
11855 vty_out(vty, " Last reset %s, ",
11856 peer_uptime(p->resettime, timebuf,
11857 BGP_UPTIME_LEN, 0, NULL));
11858
11859 bgp_show_peer_reset(vty, p, NULL, false);
11860 if (p->last_reset_cause_size) {
11861 msg = p->last_reset_cause;
11862 vty_out(vty,
11863 " Message received that caused BGP to send a NOTIFICATION:\n ");
11864 for (i = 1; i <= p->last_reset_cause_size;
11865 i++) {
11866 vty_out(vty, "%02X", *msg++);
11867
11868 if (i != p->last_reset_cause_size) {
11869 if (i % 16 == 0) {
11870 vty_out(vty, "\n ");
11871 } else if (i % 4 == 0) {
11872 vty_out(vty, " ");
11873 }
11874 }
11875 }
11876 vty_out(vty, "\n");
11877 }
11878 }
11879 }
11880
11881 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
11882 if (use_json)
11883 json_object_boolean_true_add(json_neigh,
11884 "prefixesConfigExceedMax");
11885 else
11886 vty_out(vty,
11887 " Peer had exceeded the max. no. of prefixes configured.\n");
11888
11889 if (p->t_pmax_restart) {
11890 if (use_json) {
11891 json_object_boolean_true_add(
11892 json_neigh, "reducePrefixNumFrom");
11893 json_object_int_add(json_neigh,
11894 "restartInTimerMsec",
11895 thread_timer_remain_second(
11896 p->t_pmax_restart)
11897 * 1000);
11898 } else
11899 vty_out(vty,
11900 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
11901 p->host, thread_timer_remain_second(
11902 p->t_pmax_restart));
11903 } else {
11904 if (use_json)
11905 json_object_boolean_true_add(
11906 json_neigh,
11907 "reducePrefixNumAndClearIpBgp");
11908 else
11909 vty_out(vty,
11910 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
11911 p->host);
11912 }
11913 }
11914
11915 /* EBGP Multihop and GTSM */
11916 if (p->sort != BGP_PEER_IBGP) {
11917 if (use_json) {
11918 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
11919 json_object_int_add(json_neigh,
11920 "externalBgpNbrMaxHopsAway",
11921 p->gtsm_hops);
11922 else if (p->ttl > BGP_DEFAULT_TTL)
11923 json_object_int_add(json_neigh,
11924 "externalBgpNbrMaxHopsAway",
11925 p->ttl);
11926 } else {
11927 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
11928 vty_out(vty,
11929 " External BGP neighbor may be up to %d hops away.\n",
11930 p->gtsm_hops);
11931 else if (p->ttl > BGP_DEFAULT_TTL)
11932 vty_out(vty,
11933 " External BGP neighbor may be up to %d hops away.\n",
11934 p->ttl);
11935 }
11936 } else {
11937 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED) {
11938 if (use_json)
11939 json_object_int_add(json_neigh,
11940 "internalBgpNbrMaxHopsAway",
11941 p->gtsm_hops);
11942 else
11943 vty_out(vty,
11944 " Internal BGP neighbor may be up to %d hops away.\n",
11945 p->gtsm_hops);
11946 }
11947 }
11948
11949 /* Local address. */
11950 if (p->su_local) {
11951 if (use_json) {
11952 json_object_string_add(json_neigh, "hostLocal",
11953 sockunion2str(p->su_local, buf1,
11954 SU_ADDRSTRLEN));
11955 json_object_int_add(json_neigh, "portLocal",
11956 ntohs(p->su_local->sin.sin_port));
11957 } else
11958 vty_out(vty, "Local host: %s, Local port: %d\n",
11959 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
11960 ntohs(p->su_local->sin.sin_port));
11961 }
11962
11963 /* Remote address. */
11964 if (p->su_remote) {
11965 if (use_json) {
11966 json_object_string_add(json_neigh, "hostForeign",
11967 sockunion2str(p->su_remote, buf1,
11968 SU_ADDRSTRLEN));
11969 json_object_int_add(json_neigh, "portForeign",
11970 ntohs(p->su_remote->sin.sin_port));
11971 } else
11972 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
11973 sockunion2str(p->su_remote, buf1,
11974 SU_ADDRSTRLEN),
11975 ntohs(p->su_remote->sin.sin_port));
11976 }
11977
11978 /* Nexthop display. */
11979 if (p->su_local) {
11980 if (use_json) {
11981 json_object_string_add(json_neigh, "nexthop",
11982 inet_ntop(AF_INET,
11983 &p->nexthop.v4, buf1,
11984 sizeof(buf1)));
11985 json_object_string_add(json_neigh, "nexthopGlobal",
11986 inet_ntop(AF_INET6,
11987 &p->nexthop.v6_global,
11988 buf1, sizeof(buf1)));
11989 json_object_string_add(json_neigh, "nexthopLocal",
11990 inet_ntop(AF_INET6,
11991 &p->nexthop.v6_local,
11992 buf1, sizeof(buf1)));
11993 if (p->shared_network)
11994 json_object_string_add(json_neigh,
11995 "bgpConnection",
11996 "sharedNetwork");
11997 else
11998 json_object_string_add(json_neigh,
11999 "bgpConnection",
12000 "nonSharedNetwork");
12001 } else {
12002 vty_out(vty, "Nexthop: %s\n",
12003 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
12004 sizeof(buf1)));
12005 vty_out(vty, "Nexthop global: %s\n",
12006 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
12007 sizeof(buf1)));
12008 vty_out(vty, "Nexthop local: %s\n",
12009 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
12010 sizeof(buf1)));
12011 vty_out(vty, "BGP connection: %s\n",
12012 p->shared_network ? "shared network"
12013 : "non shared network");
12014 }
12015 }
12016
12017 /* Timer information. */
12018 if (use_json) {
12019 json_object_int_add(json_neigh, "connectRetryTimer",
12020 p->v_connect);
12021 if (p->status == Established && p->rtt)
12022 json_object_int_add(json_neigh, "estimatedRttInMsecs",
12023 p->rtt);
12024 if (p->t_start)
12025 json_object_int_add(
12026 json_neigh, "nextStartTimerDueInMsecs",
12027 thread_timer_remain_second(p->t_start) * 1000);
12028 if (p->t_connect)
12029 json_object_int_add(
12030 json_neigh, "nextConnectTimerDueInMsecs",
12031 thread_timer_remain_second(p->t_connect)
12032 * 1000);
12033 if (p->t_routeadv) {
12034 json_object_int_add(json_neigh, "mraiInterval",
12035 p->v_routeadv);
12036 json_object_int_add(
12037 json_neigh, "mraiTimerExpireInMsecs",
12038 thread_timer_remain_second(p->t_routeadv)
12039 * 1000);
12040 }
12041 if (p->password)
12042 json_object_int_add(json_neigh, "authenticationEnabled",
12043 1);
12044
12045 if (p->t_read)
12046 json_object_string_add(json_neigh, "readThread", "on");
12047 else
12048 json_object_string_add(json_neigh, "readThread", "off");
12049
12050 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
12051 json_object_string_add(json_neigh, "writeThread", "on");
12052 else
12053 json_object_string_add(json_neigh, "writeThread",
12054 "off");
12055 } else {
12056 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
12057 p->v_connect);
12058 if (p->status == Established && p->rtt)
12059 vty_out(vty, "Estimated round trip time: %d ms\n",
12060 p->rtt);
12061 if (p->t_start)
12062 vty_out(vty, "Next start timer due in %ld seconds\n",
12063 thread_timer_remain_second(p->t_start));
12064 if (p->t_connect)
12065 vty_out(vty, "Next connect timer due in %ld seconds\n",
12066 thread_timer_remain_second(p->t_connect));
12067 if (p->t_routeadv)
12068 vty_out(vty,
12069 "MRAI (interval %u) timer expires in %ld seconds\n",
12070 p->v_routeadv,
12071 thread_timer_remain_second(p->t_routeadv));
12072 if (p->password)
12073 vty_out(vty, "Peer Authentication Enabled\n");
12074
12075 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
12076 p->t_read ? "on" : "off",
12077 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
12078 ? "on"
12079 : "off", p->fd);
12080 }
12081
12082 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
12083 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
12084 bgp_capability_vty_out(vty, p, use_json, json_neigh);
12085
12086 if (!use_json)
12087 vty_out(vty, "\n");
12088
12089 /* BFD information. */
12090 bgp_bfd_show_info(vty, p, use_json, json_neigh);
12091
12092 if (use_json) {
12093 if (p->conf_if) /* Configured interface name. */
12094 json_object_object_add(json, p->conf_if, json_neigh);
12095 else /* Configured IP address. */
12096 json_object_object_add(json, p->host, json_neigh);
12097 }
12098 }
12099
12100 static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
12101 enum show_type type,
12102 union sockunion *su,
12103 const char *conf_if, afi_t afi,
12104 bool use_json, json_object *json)
12105 {
12106 struct listnode *node, *nnode;
12107 struct peer *peer;
12108 int find = 0;
12109 safi_t safi = SAFI_UNICAST;
12110 json_object *json_neighbor = NULL;
12111
12112 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
12113
12114 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
12115 continue;
12116
12117 if ((peer->afc[afi][safi]) == 0)
12118 continue;
12119
12120 if (use_json)
12121 json_neighbor = json_object_new_object();
12122
12123 if (type == show_all) {
12124 bgp_show_peer_gr_status(vty, peer, use_json,
12125 json_neighbor);
12126
12127 if (use_json)
12128 json_object_object_add(json, peer->host,
12129 json_neighbor);
12130
12131 } else if (type == show_peer) {
12132 if (conf_if) {
12133 if ((peer->conf_if
12134 && !strcmp(peer->conf_if, conf_if))
12135 || (peer->hostname
12136 && !strcmp(peer->hostname, conf_if))) {
12137 find = 1;
12138 bgp_show_peer_gr_status(vty, peer,
12139 use_json,
12140 json_neighbor);
12141 }
12142 } else {
12143 if (sockunion_same(&peer->su, su)) {
12144 find = 1;
12145 bgp_show_peer_gr_status(vty, peer,
12146 use_json,
12147 json_neighbor);
12148 }
12149 }
12150 if (use_json && find)
12151 json_object_object_add(json, peer->host,
12152 json_neighbor);
12153 }
12154
12155 if (find)
12156 break;
12157 }
12158
12159 if (type == show_peer && !find) {
12160 if (use_json)
12161 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
12162 else
12163 vty_out(vty, "%% No such neighbor\n");
12164 }
12165 if (use_json) {
12166 vty_out(vty, "%s\n",
12167 json_object_to_json_string_ext(
12168 json, JSON_C_TO_STRING_PRETTY));
12169 } else {
12170 vty_out(vty, "\n");
12171 }
12172
12173 return CMD_SUCCESS;
12174 }
12175
12176 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
12177 enum show_type type, union sockunion *su,
12178 const char *conf_if, bool use_json,
12179 json_object *json)
12180 {
12181 struct listnode *node, *nnode;
12182 struct peer *peer;
12183 int find = 0;
12184 bool nbr_output = false;
12185 afi_t afi = AFI_MAX;
12186 safi_t safi = SAFI_MAX;
12187
12188 if (type == show_ipv4_peer || type == show_ipv4_all) {
12189 afi = AFI_IP;
12190 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
12191 afi = AFI_IP6;
12192 }
12193
12194 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
12195 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
12196 continue;
12197
12198 switch (type) {
12199 case show_all:
12200 bgp_show_peer(vty, peer, use_json, json);
12201 nbr_output = true;
12202 break;
12203 case show_peer:
12204 if (conf_if) {
12205 if ((peer->conf_if
12206 && !strcmp(peer->conf_if, conf_if))
12207 || (peer->hostname
12208 && !strcmp(peer->hostname, conf_if))) {
12209 find = 1;
12210 bgp_show_peer(vty, peer, use_json,
12211 json);
12212 }
12213 } else {
12214 if (sockunion_same(&peer->su, su)) {
12215 find = 1;
12216 bgp_show_peer(vty, peer, use_json,
12217 json);
12218 }
12219 }
12220 break;
12221 case show_ipv4_peer:
12222 case show_ipv6_peer:
12223 FOREACH_SAFI (safi) {
12224 if (peer->afc[afi][safi]) {
12225 if (conf_if) {
12226 if ((peer->conf_if
12227 && !strcmp(peer->conf_if, conf_if))
12228 || (peer->hostname
12229 && !strcmp(peer->hostname, conf_if))) {
12230 find = 1;
12231 bgp_show_peer(vty, peer, use_json,
12232 json);
12233 break;
12234 }
12235 } else {
12236 if (sockunion_same(&peer->su, su)) {
12237 find = 1;
12238 bgp_show_peer(vty, peer, use_json,
12239 json);
12240 break;
12241 }
12242 }
12243 }
12244 }
12245 break;
12246 case show_ipv4_all:
12247 case show_ipv6_all:
12248 FOREACH_SAFI (safi) {
12249 if (peer->afc[afi][safi]) {
12250 bgp_show_peer(vty, peer, use_json, json);
12251 nbr_output = true;
12252 break;
12253 }
12254 }
12255 break;
12256 }
12257 }
12258
12259 if ((type == show_peer || type == show_ipv4_peer ||
12260 type == show_ipv6_peer) && !find) {
12261 if (use_json)
12262 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
12263 else
12264 vty_out(vty, "%% No such neighbor in this view/vrf\n");
12265 }
12266
12267 if (type != show_peer && type != show_ipv4_peer &&
12268 type != show_ipv6_peer && !nbr_output && !use_json)
12269 vty_out(vty, "%% No BGP neighbors found\n");
12270
12271 if (use_json) {
12272 vty_out(vty, "%s\n", json_object_to_json_string_ext(
12273 json, JSON_C_TO_STRING_PRETTY));
12274 } else {
12275 vty_out(vty, "\n");
12276 }
12277
12278 return CMD_SUCCESS;
12279 }
12280
12281 static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
12282 enum show_type type,
12283 const char *ip_str,
12284 afi_t afi, bool use_json)
12285 {
12286
12287 int ret;
12288 struct bgp *bgp;
12289 union sockunion su;
12290 json_object *json = NULL;
12291
12292 bgp = bgp_get_default();
12293
12294 if (!bgp)
12295 return;
12296
12297 if (!use_json)
12298 bgp_show_global_graceful_restart_mode_vty(vty, bgp, use_json,
12299 NULL);
12300
12301 json = json_object_new_object();
12302 if (ip_str) {
12303 ret = str2sockunion(ip_str, &su);
12304 if (ret < 0)
12305 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL,
12306 ip_str, afi,
12307 use_json, json);
12308 else
12309 bgp_show_neighbor_graceful_restart(
12310 vty, bgp, type, &su, NULL, afi, use_json, json);
12311 } else
12312 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
12313 afi, use_json, json);
12314 json_object_free(json);
12315 }
12316
12317 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
12318 enum show_type type,
12319 const char *ip_str,
12320 bool use_json)
12321 {
12322 struct listnode *node, *nnode;
12323 struct bgp *bgp;
12324 union sockunion su;
12325 json_object *json = NULL;
12326 int ret, is_first = 1;
12327 bool nbr_output = false;
12328
12329 if (use_json)
12330 vty_out(vty, "{\n");
12331
12332 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
12333 nbr_output = true;
12334 if (use_json) {
12335 if (!(json = json_object_new_object())) {
12336 flog_err(
12337 EC_BGP_JSON_MEM_ERROR,
12338 "Unable to allocate memory for JSON object");
12339 vty_out(vty,
12340 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
12341 return;
12342 }
12343
12344 json_object_int_add(json, "vrfId",
12345 (bgp->vrf_id == VRF_UNKNOWN)
12346 ? -1
12347 : (int64_t)bgp->vrf_id);
12348 json_object_string_add(
12349 json, "vrfName",
12350 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
12351 ? VRF_DEFAULT_NAME
12352 : bgp->name);
12353
12354 if (!is_first)
12355 vty_out(vty, ",\n");
12356 else
12357 is_first = 0;
12358
12359 vty_out(vty, "\"%s\":",
12360 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
12361 ? VRF_DEFAULT_NAME
12362 : bgp->name);
12363 } else {
12364 vty_out(vty, "\nInstance %s:\n",
12365 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
12366 ? VRF_DEFAULT_NAME
12367 : bgp->name);
12368 }
12369
12370 if (type == show_peer || type == show_ipv4_peer ||
12371 type == show_ipv6_peer) {
12372 ret = str2sockunion(ip_str, &su);
12373 if (ret < 0)
12374 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
12375 use_json, json);
12376 else
12377 bgp_show_neighbor(vty, bgp, type, &su, NULL,
12378 use_json, json);
12379 } else {
12380 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
12381 use_json, json);
12382 }
12383 json_object_free(json);
12384 }
12385
12386 if (use_json) {
12387 vty_out(vty, "}\n");
12388 json_object_free(json);
12389 }
12390 else if (!nbr_output)
12391 vty_out(vty, "%% BGP instance not found\n");
12392 }
12393
12394 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
12395 enum show_type type, const char *ip_str,
12396 bool use_json)
12397 {
12398 int ret;
12399 struct bgp *bgp;
12400 union sockunion su;
12401 json_object *json = NULL;
12402
12403 if (name) {
12404 if (strmatch(name, "all")) {
12405 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
12406 use_json);
12407 return CMD_SUCCESS;
12408 } else {
12409 bgp = bgp_lookup_by_name(name);
12410 if (!bgp) {
12411 if (use_json) {
12412 json = json_object_new_object();
12413 vty_out(vty, "%s\n",
12414 json_object_to_json_string_ext(
12415 json,
12416 JSON_C_TO_STRING_PRETTY));
12417 json_object_free(json);
12418 } else
12419 vty_out(vty,
12420 "%% BGP instance not found\n");
12421
12422 return CMD_WARNING;
12423 }
12424 }
12425 } else {
12426 bgp = bgp_get_default();
12427 }
12428
12429 if (bgp) {
12430 json = json_object_new_object();
12431 if (ip_str) {
12432 ret = str2sockunion(ip_str, &su);
12433 if (ret < 0)
12434 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
12435 use_json, json);
12436 else
12437 bgp_show_neighbor(vty, bgp, type, &su, NULL,
12438 use_json, json);
12439 } else {
12440 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
12441 json);
12442 }
12443 json_object_free(json);
12444 } else {
12445 if (use_json)
12446 vty_out(vty, "{}\n");
12447 else
12448 vty_out(vty, "%% BGP instance not found\n");
12449 }
12450
12451 return CMD_SUCCESS;
12452 }
12453
12454
12455
12456 /* "show [ip] bgp neighbors graceful-restart" commands. */
12457 DEFUN (show_ip_bgp_neighbors_gracrful_restart,
12458 show_ip_bgp_neighbors_graceful_restart_cmd,
12459 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
12460 SHOW_STR
12461 BGP_STR
12462 IP_STR
12463 IPV6_STR
12464 NEIGHBOR_STR
12465 "Neighbor to display information about\n"
12466 "Neighbor to display information about\n"
12467 "Neighbor on BGP configured interface\n"
12468 GR_SHOW
12469 JSON_STR)
12470 {
12471 char *sh_arg = NULL;
12472 enum show_type sh_type;
12473 int idx = 0;
12474 afi_t afi = AFI_MAX;
12475 bool uj = use_json(argc, argv);
12476
12477 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
12478 afi = AFI_MAX;
12479
12480 idx++;
12481
12482 if (argv_find(argv, argc, "A.B.C.D", &idx)
12483 || argv_find(argv, argc, "X:X::X:X", &idx)
12484 || argv_find(argv, argc, "WORD", &idx)) {
12485 sh_type = show_peer;
12486 sh_arg = argv[idx]->arg;
12487 } else
12488 sh_type = show_all;
12489
12490 if (!argv_find(argv, argc, "graceful-restart", &idx))
12491 return CMD_SUCCESS;
12492
12493
12494 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
12495 afi, uj);
12496 }
12497
12498 /* "show [ip] bgp neighbors" commands. */
12499 DEFUN (show_ip_bgp_neighbors,
12500 show_ip_bgp_neighbors_cmd,
12501 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
12502 SHOW_STR
12503 IP_STR
12504 BGP_STR
12505 BGP_INSTANCE_HELP_STR
12506 "Address Family\n"
12507 "Address Family\n"
12508 "Detailed information on TCP and BGP neighbor connections\n"
12509 "Neighbor to display information about\n"
12510 "Neighbor to display information about\n"
12511 "Neighbor on BGP configured interface\n"
12512 JSON_STR)
12513 {
12514 char *vrf = NULL;
12515 char *sh_arg = NULL;
12516 enum show_type sh_type;
12517 afi_t afi = AFI_MAX;
12518
12519 bool uj = use_json(argc, argv);
12520
12521 int idx = 0;
12522
12523 /* [<vrf> VIEWVRFNAME] */
12524 if (argv_find(argv, argc, "vrf", &idx)) {
12525 vrf = argv[idx + 1]->arg;
12526 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
12527 vrf = NULL;
12528 } else if (argv_find(argv, argc, "view", &idx))
12529 /* [<view> VIEWVRFNAME] */
12530 vrf = argv[idx + 1]->arg;
12531
12532 idx++;
12533
12534 if (argv_find(argv, argc, "ipv4", &idx)) {
12535 sh_type = show_ipv4_all;
12536 afi = AFI_IP;
12537 } else if (argv_find(argv, argc, "ipv6", &idx)) {
12538 sh_type = show_ipv6_all;
12539 afi = AFI_IP6;
12540 } else {
12541 sh_type = show_all;
12542 }
12543
12544 if (argv_find(argv, argc, "A.B.C.D", &idx)
12545 || argv_find(argv, argc, "X:X::X:X", &idx)
12546 || argv_find(argv, argc, "WORD", &idx)) {
12547 sh_type = show_peer;
12548 sh_arg = argv[idx]->arg;
12549 }
12550
12551 if (sh_type == show_peer && afi == AFI_IP) {
12552 sh_type = show_ipv4_peer;
12553 } else if (sh_type == show_peer && afi == AFI_IP6) {
12554 sh_type = show_ipv6_peer;
12555 }
12556
12557 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
12558 }
12559
12560 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
12561 paths' and `show ip mbgp paths'. Those functions results are the
12562 same.*/
12563 DEFUN (show_ip_bgp_paths,
12564 show_ip_bgp_paths_cmd,
12565 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
12566 SHOW_STR
12567 IP_STR
12568 BGP_STR
12569 BGP_SAFI_HELP_STR
12570 "Path information\n")
12571 {
12572 vty_out(vty, "Address Refcnt Path\n");
12573 aspath_print_all_vty(vty);
12574 return CMD_SUCCESS;
12575 }
12576
12577 #include "hash.h"
12578
12579 static void community_show_all_iterator(struct hash_bucket *bucket,
12580 struct vty *vty)
12581 {
12582 struct community *com;
12583
12584 com = (struct community *)bucket->data;
12585 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
12586 community_str(com, false));
12587 }
12588
12589 /* Show BGP's community internal data. */
12590 DEFUN (show_ip_bgp_community_info,
12591 show_ip_bgp_community_info_cmd,
12592 "show [ip] bgp community-info",
12593 SHOW_STR
12594 IP_STR
12595 BGP_STR
12596 "List all bgp community information\n")
12597 {
12598 vty_out(vty, "Address Refcnt Community\n");
12599
12600 hash_iterate(community_hash(),
12601 (void (*)(struct hash_bucket *,
12602 void *))community_show_all_iterator,
12603 vty);
12604
12605 return CMD_SUCCESS;
12606 }
12607
12608 static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
12609 struct vty *vty)
12610 {
12611 struct lcommunity *lcom;
12612
12613 lcom = (struct lcommunity *)bucket->data;
12614 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
12615 lcommunity_str(lcom, false));
12616 }
12617
12618 /* Show BGP's community internal data. */
12619 DEFUN (show_ip_bgp_lcommunity_info,
12620 show_ip_bgp_lcommunity_info_cmd,
12621 "show ip bgp large-community-info",
12622 SHOW_STR
12623 IP_STR
12624 BGP_STR
12625 "List all bgp large-community information\n")
12626 {
12627 vty_out(vty, "Address Refcnt Large-community\n");
12628
12629 hash_iterate(lcommunity_hash(),
12630 (void (*)(struct hash_bucket *,
12631 void *))lcommunity_show_all_iterator,
12632 vty);
12633
12634 return CMD_SUCCESS;
12635 }
12636 /* Graceful Restart */
12637
12638 static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
12639 struct bgp *bgp,
12640 bool use_json,
12641 json_object *json)
12642 {
12643
12644
12645 vty_out(vty, "\n%s", SHOW_GR_HEADER);
12646
12647 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
12648
12649 switch (bgp_global_gr_mode) {
12650
12651 case GLOBAL_HELPER:
12652 vty_out(vty, "Global BGP GR Mode : Helper\n");
12653 break;
12654
12655 case GLOBAL_GR:
12656 vty_out(vty, "Global BGP GR Mode : Restart\n");
12657 break;
12658
12659 case GLOBAL_DISABLE:
12660 vty_out(vty, "Global BGP GR Mode : Disable\n");
12661 break;
12662
12663 case GLOBAL_INVALID:
12664 vty_out(vty,
12665 "Global BGP GR Mode Invalid\n");
12666 break;
12667 }
12668 vty_out(vty, "\n");
12669 }
12670
12671 static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
12672 enum show_type type,
12673 const char *ip_str,
12674 afi_t afi, bool use_json)
12675 {
12676 if ((afi == AFI_MAX) && (ip_str == NULL)) {
12677 afi = AFI_IP;
12678
12679 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
12680
12681 bgp_show_neighbor_graceful_restart_vty(
12682 vty, type, ip_str, afi, use_json);
12683 afi++;
12684 }
12685 } else if (afi != AFI_MAX) {
12686 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
12687 use_json);
12688 } else {
12689 return CMD_ERR_INCOMPLETE;
12690 }
12691
12692 return CMD_SUCCESS;
12693 }
12694 /* Graceful Restart */
12695
12696 DEFUN (show_ip_bgp_attr_info,
12697 show_ip_bgp_attr_info_cmd,
12698 "show [ip] bgp attribute-info",
12699 SHOW_STR
12700 IP_STR
12701 BGP_STR
12702 "List all bgp attribute information\n")
12703 {
12704 attr_show_all(vty);
12705 return CMD_SUCCESS;
12706 }
12707
12708 static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
12709 afi_t afi, safi_t safi,
12710 bool use_json, json_object *json)
12711 {
12712 struct bgp *bgp;
12713 struct listnode *node;
12714 char *vname;
12715 char buf1[INET6_ADDRSTRLEN];
12716 char *ecom_str;
12717 vpn_policy_direction_t dir;
12718
12719 if (json) {
12720 json_object *json_import_vrfs = NULL;
12721 json_object *json_export_vrfs = NULL;
12722
12723 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
12724
12725 if (!bgp) {
12726 vty_out(vty, "%s\n",
12727 json_object_to_json_string_ext(
12728 json,
12729 JSON_C_TO_STRING_PRETTY));
12730 json_object_free(json);
12731
12732 return CMD_WARNING;
12733 }
12734
12735 /* Provide context for the block */
12736 json_object_string_add(json, "vrf", name ? name : "default");
12737 json_object_string_add(json, "afiSafi",
12738 get_afi_safi_str(afi, safi, true));
12739
12740 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
12741 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
12742 json_object_string_add(json, "importFromVrfs", "none");
12743 json_object_string_add(json, "importRts", "none");
12744 } else {
12745 json_import_vrfs = json_object_new_array();
12746
12747 for (ALL_LIST_ELEMENTS_RO(
12748 bgp->vpn_policy[afi].import_vrf,
12749 node, vname))
12750 json_object_array_add(json_import_vrfs,
12751 json_object_new_string(vname));
12752
12753 json_object_object_add(json, "importFromVrfs",
12754 json_import_vrfs);
12755 dir = BGP_VPN_POLICY_DIR_FROMVPN;
12756 if (bgp->vpn_policy[afi].rtlist[dir]) {
12757 ecom_str = ecommunity_ecom2str(
12758 bgp->vpn_policy[afi].rtlist[dir],
12759 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
12760 json_object_string_add(json, "importRts",
12761 ecom_str);
12762 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
12763 } else
12764 json_object_string_add(json, "importRts",
12765 "none");
12766 }
12767
12768 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
12769 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
12770 json_object_string_add(json, "exportToVrfs", "none");
12771 json_object_string_add(json, "routeDistinguisher",
12772 "none");
12773 json_object_string_add(json, "exportRts", "none");
12774 } else {
12775 json_export_vrfs = json_object_new_array();
12776
12777 for (ALL_LIST_ELEMENTS_RO(
12778 bgp->vpn_policy[afi].export_vrf,
12779 node, vname))
12780 json_object_array_add(json_export_vrfs,
12781 json_object_new_string(vname));
12782 json_object_object_add(json, "exportToVrfs",
12783 json_export_vrfs);
12784 json_object_string_add(json, "routeDistinguisher",
12785 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
12786 buf1, RD_ADDRSTRLEN));
12787
12788 dir = BGP_VPN_POLICY_DIR_TOVPN;
12789 if (bgp->vpn_policy[afi].rtlist[dir]) {
12790 ecom_str = ecommunity_ecom2str(
12791 bgp->vpn_policy[afi].rtlist[dir],
12792 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
12793 json_object_string_add(json, "exportRts",
12794 ecom_str);
12795 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
12796 } else
12797 json_object_string_add(json, "exportRts",
12798 "none");
12799 }
12800
12801 if (use_json) {
12802 vty_out(vty, "%s\n",
12803 json_object_to_json_string_ext(json,
12804 JSON_C_TO_STRING_PRETTY));
12805 json_object_free(json);
12806 }
12807 } else {
12808 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
12809
12810 if (!bgp) {
12811 vty_out(vty, "%% No such BGP instance exist\n");
12812 return CMD_WARNING;
12813 }
12814
12815 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
12816 BGP_CONFIG_VRF_TO_VRF_IMPORT))
12817 vty_out(vty,
12818 "This VRF is not importing %s routes from any other VRF\n",
12819 get_afi_safi_str(afi, safi, false));
12820 else {
12821 vty_out(vty,
12822 "This VRF is importing %s routes from the following VRFs:\n",
12823 get_afi_safi_str(afi, safi, false));
12824
12825 for (ALL_LIST_ELEMENTS_RO(
12826 bgp->vpn_policy[afi].import_vrf,
12827 node, vname))
12828 vty_out(vty, " %s\n", vname);
12829
12830 dir = BGP_VPN_POLICY_DIR_FROMVPN;
12831 ecom_str = NULL;
12832 if (bgp->vpn_policy[afi].rtlist[dir]) {
12833 ecom_str = ecommunity_ecom2str(
12834 bgp->vpn_policy[afi].rtlist[dir],
12835 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
12836 vty_out(vty, "Import RT(s): %s\n", ecom_str);
12837
12838 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
12839 } else
12840 vty_out(vty, "Import RT(s):\n");
12841 }
12842
12843 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
12844 BGP_CONFIG_VRF_TO_VRF_EXPORT))
12845 vty_out(vty,
12846 "This VRF is not exporting %s routes to any other VRF\n",
12847 get_afi_safi_str(afi, safi, false));
12848 else {
12849 vty_out(vty,
12850 "This VRF is exporting %s routes to the following VRFs:\n",
12851 get_afi_safi_str(afi, safi, false));
12852
12853 for (ALL_LIST_ELEMENTS_RO(
12854 bgp->vpn_policy[afi].export_vrf,
12855 node, vname))
12856 vty_out(vty, " %s\n", vname);
12857
12858 vty_out(vty, "RD: %s\n",
12859 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
12860 buf1, RD_ADDRSTRLEN));
12861
12862 dir = BGP_VPN_POLICY_DIR_TOVPN;
12863 if (bgp->vpn_policy[afi].rtlist[dir]) {
12864 ecom_str = ecommunity_ecom2str(
12865 bgp->vpn_policy[afi].rtlist[dir],
12866 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
12867 vty_out(vty, "Export RT: %s\n", ecom_str);
12868 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
12869 } else
12870 vty_out(vty, "Import RT(s):\n");
12871 }
12872 }
12873
12874 return CMD_SUCCESS;
12875 }
12876
12877 static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
12878 safi_t safi, bool use_json)
12879 {
12880 struct listnode *node, *nnode;
12881 struct bgp *bgp;
12882 char *vrf_name = NULL;
12883 json_object *json = NULL;
12884 json_object *json_vrf = NULL;
12885 json_object *json_vrfs = NULL;
12886
12887 if (use_json) {
12888 json = json_object_new_object();
12889 json_vrfs = json_object_new_object();
12890 }
12891
12892 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
12893
12894 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
12895 vrf_name = bgp->name;
12896
12897 if (use_json) {
12898 json_vrf = json_object_new_object();
12899 } else {
12900 vty_out(vty, "\nInstance %s:\n",
12901 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
12902 ? VRF_DEFAULT_NAME : bgp->name);
12903 }
12904 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
12905 if (use_json) {
12906 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
12907 json_object_object_add(json_vrfs,
12908 VRF_DEFAULT_NAME, json_vrf);
12909 else
12910 json_object_object_add(json_vrfs, vrf_name,
12911 json_vrf);
12912 }
12913 }
12914
12915 if (use_json) {
12916 json_object_object_add(json, "vrfs", json_vrfs);
12917 vty_out(vty, "%s\n", json_object_to_json_string_ext(json,
12918 JSON_C_TO_STRING_PRETTY));
12919 json_object_free(json);
12920 }
12921
12922 return CMD_SUCCESS;
12923 }
12924
12925 /* "show [ip] bgp route-leak" command. */
12926 DEFUN (show_ip_bgp_route_leak,
12927 show_ip_bgp_route_leak_cmd,
12928 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
12929 SHOW_STR
12930 IP_STR
12931 BGP_STR
12932 BGP_INSTANCE_HELP_STR
12933 BGP_AFI_HELP_STR
12934 BGP_SAFI_HELP_STR
12935 "Route leaking information\n"
12936 JSON_STR)
12937 {
12938 char *vrf = NULL;
12939 afi_t afi = AFI_MAX;
12940 safi_t safi = SAFI_MAX;
12941
12942 bool uj = use_json(argc, argv);
12943 int idx = 0;
12944 json_object *json = NULL;
12945
12946 /* show [ip] bgp */
12947 if (argv_find(argv, argc, "ip", &idx)) {
12948 afi = AFI_IP;
12949 safi = SAFI_UNICAST;
12950 }
12951 /* [vrf VIEWVRFNAME] */
12952 if (argv_find(argv, argc, "view", &idx)) {
12953 vty_out(vty,
12954 "%% This command is not applicable to BGP views\n");
12955 return CMD_WARNING;
12956 }
12957
12958 if (argv_find(argv, argc, "vrf", &idx)) {
12959 vrf = argv[idx + 1]->arg;
12960 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
12961 vrf = NULL;
12962 }
12963 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
12964 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
12965 argv_find_and_parse_safi(argv, argc, &idx, &safi);
12966 }
12967
12968 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
12969 vty_out(vty,
12970 "%% This command is applicable only for unicast ipv4|ipv6\n");
12971 return CMD_WARNING;
12972 }
12973
12974 if (vrf && strmatch(vrf, "all"))
12975 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
12976
12977 if (uj)
12978 json = json_object_new_object();
12979
12980 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
12981 }
12982
12983 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
12984 safi_t safi)
12985 {
12986 struct listnode *node, *nnode;
12987 struct bgp *bgp;
12988
12989 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
12990 vty_out(vty, "\nInstance %s:\n",
12991 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
12992 ? VRF_DEFAULT_NAME
12993 : bgp->name);
12994 update_group_show(bgp, afi, safi, vty, 0);
12995 }
12996 }
12997
12998 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
12999 int safi, uint64_t subgrp_id)
13000 {
13001 struct bgp *bgp;
13002
13003 if (name) {
13004 if (strmatch(name, "all")) {
13005 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
13006 return CMD_SUCCESS;
13007 } else {
13008 bgp = bgp_lookup_by_name(name);
13009 }
13010 } else {
13011 bgp = bgp_get_default();
13012 }
13013
13014 if (bgp)
13015 update_group_show(bgp, afi, safi, vty, subgrp_id);
13016 return CMD_SUCCESS;
13017 }
13018
13019 DEFUN (show_ip_bgp_updgrps,
13020 show_ip_bgp_updgrps_cmd,
13021 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
13022 SHOW_STR
13023 IP_STR
13024 BGP_STR
13025 BGP_INSTANCE_HELP_STR
13026 BGP_AFI_HELP_STR
13027 BGP_SAFI_WITH_LABEL_HELP_STR
13028 "Detailed info about dynamic update groups\n"
13029 "Specific subgroup to display detailed info for\n")
13030 {
13031 char *vrf = NULL;
13032 afi_t afi = AFI_IP6;
13033 safi_t safi = SAFI_UNICAST;
13034 uint64_t subgrp_id = 0;
13035
13036 int idx = 0;
13037
13038 /* show [ip] bgp */
13039 if (argv_find(argv, argc, "ip", &idx))
13040 afi = AFI_IP;
13041 /* [<vrf> VIEWVRFNAME] */
13042 if (argv_find(argv, argc, "vrf", &idx)) {
13043 vrf = argv[idx + 1]->arg;
13044 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
13045 vrf = NULL;
13046 } else if (argv_find(argv, argc, "view", &idx))
13047 /* [<view> VIEWVRFNAME] */
13048 vrf = argv[idx + 1]->arg;
13049 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
13050 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
13051 argv_find_and_parse_safi(argv, argc, &idx, &safi);
13052 }
13053
13054 /* get subgroup id, if provided */
13055 idx = argc - 1;
13056 if (argv[idx]->type == VARIABLE_TKN)
13057 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
13058
13059 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
13060 }
13061
13062 DEFUN (show_bgp_instance_all_ipv6_updgrps,
13063 show_bgp_instance_all_ipv6_updgrps_cmd,
13064 "show [ip] bgp <view|vrf> all update-groups",
13065 SHOW_STR
13066 IP_STR
13067 BGP_STR
13068 BGP_INSTANCE_ALL_HELP_STR
13069 "Detailed info about dynamic update groups\n")
13070 {
13071 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
13072 return CMD_SUCCESS;
13073 }
13074
13075 DEFUN (show_bgp_l2vpn_evpn_updgrps,
13076 show_bgp_l2vpn_evpn_updgrps_cmd,
13077 "show [ip] bgp l2vpn evpn update-groups",
13078 SHOW_STR
13079 IP_STR
13080 BGP_STR
13081 "l2vpn address family\n"
13082 "evpn sub-address family\n"
13083 "Detailed info about dynamic update groups\n")
13084 {
13085 char *vrf = NULL;
13086 uint64_t subgrp_id = 0;
13087
13088 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
13089 return CMD_SUCCESS;
13090 }
13091
13092 DEFUN (show_bgp_updgrps_stats,
13093 show_bgp_updgrps_stats_cmd,
13094 "show [ip] bgp update-groups statistics",
13095 SHOW_STR
13096 IP_STR
13097 BGP_STR
13098 "Detailed info about dynamic update groups\n"
13099 "Statistics\n")
13100 {
13101 struct bgp *bgp;
13102
13103 bgp = bgp_get_default();
13104 if (bgp)
13105 update_group_show_stats(bgp, vty);
13106
13107 return CMD_SUCCESS;
13108 }
13109
13110 DEFUN (show_bgp_instance_updgrps_stats,
13111 show_bgp_instance_updgrps_stats_cmd,
13112 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
13113 SHOW_STR
13114 IP_STR
13115 BGP_STR
13116 BGP_INSTANCE_HELP_STR
13117 "Detailed info about dynamic update groups\n"
13118 "Statistics\n")
13119 {
13120 int idx_word = 3;
13121 struct bgp *bgp;
13122
13123 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
13124 if (bgp)
13125 update_group_show_stats(bgp, vty);
13126
13127 return CMD_SUCCESS;
13128 }
13129
13130 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
13131 afi_t afi, safi_t safi,
13132 const char *what, uint64_t subgrp_id)
13133 {
13134 struct bgp *bgp;
13135
13136 if (name)
13137 bgp = bgp_lookup_by_name(name);
13138 else
13139 bgp = bgp_get_default();
13140
13141 if (bgp) {
13142 if (!strcmp(what, "advertise-queue"))
13143 update_group_show_adj_queue(bgp, afi, safi, vty,
13144 subgrp_id);
13145 else if (!strcmp(what, "advertised-routes"))
13146 update_group_show_advertised(bgp, afi, safi, vty,
13147 subgrp_id);
13148 else if (!strcmp(what, "packet-queue"))
13149 update_group_show_packet_queue(bgp, afi, safi, vty,
13150 subgrp_id);
13151 }
13152 }
13153
13154 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
13155 show_ip_bgp_instance_updgrps_adj_s_cmd,
13156 "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",
13157 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
13158 BGP_SAFI_HELP_STR
13159 "Detailed info about dynamic update groups\n"
13160 "Specific subgroup to display info for\n"
13161 "Advertisement queue\n"
13162 "Announced routes\n"
13163 "Packet queue\n")
13164 {
13165 uint64_t subgrp_id = 0;
13166 afi_t afiz;
13167 safi_t safiz;
13168 if (sgid)
13169 subgrp_id = strtoull(sgid, NULL, 10);
13170
13171 if (!ip && !afi)
13172 afiz = AFI_IP6;
13173 if (!ip && afi)
13174 afiz = bgp_vty_afi_from_str(afi);
13175 if (ip && !afi)
13176 afiz = AFI_IP;
13177 if (ip && afi) {
13178 afiz = bgp_vty_afi_from_str(afi);
13179 if (afiz != AFI_IP)
13180 vty_out(vty,
13181 "%% Cannot specify both 'ip' and 'ipv6'\n");
13182 return CMD_WARNING;
13183 }
13184
13185 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
13186
13187 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
13188 return CMD_SUCCESS;
13189 }
13190
13191 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
13192 {
13193 struct listnode *node, *nnode;
13194 struct prefix *range;
13195 struct peer *conf;
13196 struct peer *peer;
13197 char buf[PREFIX2STR_BUFFER];
13198 afi_t afi;
13199 safi_t safi;
13200 const char *peer_status;
13201 const char *af_str;
13202 int lr_count;
13203 int dynamic;
13204 int af_cfgd;
13205
13206 conf = group->conf;
13207
13208 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
13209 vty_out(vty, "\nBGP peer-group %s, remote AS %" PRIu32 "\n",
13210 group->name, conf->as);
13211 } else if (conf->as_type == AS_INTERNAL) {
13212 vty_out(vty, "\nBGP peer-group %s, remote AS %" PRIu32 "\n",
13213 group->name, group->bgp->as);
13214 } else {
13215 vty_out(vty, "\nBGP peer-group %s\n", group->name);
13216 }
13217
13218 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
13219 vty_out(vty, " Peer-group type is internal\n");
13220 else
13221 vty_out(vty, " Peer-group type is external\n");
13222
13223 /* Display AFs configured. */
13224 vty_out(vty, " Configured address-families:");
13225 FOREACH_AFI_SAFI (afi, safi) {
13226 if (conf->afc[afi][safi]) {
13227 af_cfgd = 1;
13228 vty_out(vty, " %s;", get_afi_safi_str(afi, safi, false));
13229 }
13230 }
13231 if (!af_cfgd)
13232 vty_out(vty, " none\n");
13233 else
13234 vty_out(vty, "\n");
13235
13236 /* Display listen ranges (for dynamic neighbors), if any */
13237 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
13238 if (afi == AFI_IP)
13239 af_str = "IPv4";
13240 else if (afi == AFI_IP6)
13241 af_str = "IPv6";
13242 else
13243 af_str = "???";
13244 lr_count = listcount(group->listen_range[afi]);
13245 if (lr_count) {
13246 vty_out(vty, " %d %s listen range(s)\n", lr_count,
13247 af_str);
13248
13249
13250 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
13251 nnode, range)) {
13252 prefix2str(range, buf, sizeof(buf));
13253 vty_out(vty, " %s\n", buf);
13254 }
13255 }
13256 }
13257
13258 /* Display group members and their status */
13259 if (listcount(group->peer)) {
13260 vty_out(vty, " Peer-group members:\n");
13261 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
13262 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
13263 peer_status = "Idle (Admin)";
13264 else if (CHECK_FLAG(peer->sflags,
13265 PEER_STATUS_PREFIX_OVERFLOW))
13266 peer_status = "Idle (PfxCt)";
13267 else
13268 peer_status = lookup_msg(bgp_status_msg,
13269 peer->status, NULL);
13270
13271 dynamic = peer_dynamic_neighbor(peer);
13272 vty_out(vty, " %s %s %s \n", peer->host,
13273 dynamic ? "(dynamic)" : "", peer_status);
13274 }
13275 }
13276
13277 return CMD_SUCCESS;
13278 }
13279
13280 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
13281 const char *group_name)
13282 {
13283 struct bgp *bgp;
13284 struct listnode *node, *nnode;
13285 struct peer_group *group;
13286 bool found = false;
13287
13288 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
13289
13290 if (!bgp) {
13291 vty_out(vty, "%% BGP instance not found\n");
13292 return CMD_WARNING;
13293 }
13294
13295 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
13296 if (group_name) {
13297 if (strmatch(group->name, group_name)) {
13298 bgp_show_one_peer_group(vty, group);
13299 found = true;
13300 break;
13301 }
13302 } else {
13303 bgp_show_one_peer_group(vty, group);
13304 }
13305 }
13306
13307 if (group_name && !found)
13308 vty_out(vty, "%% No such peer-group\n");
13309
13310 return CMD_SUCCESS;
13311 }
13312
13313 DEFUN (show_ip_bgp_peer_groups,
13314 show_ip_bgp_peer_groups_cmd,
13315 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
13316 SHOW_STR
13317 IP_STR
13318 BGP_STR
13319 BGP_INSTANCE_HELP_STR
13320 "Detailed information on BGP peer groups\n"
13321 "Peer group name\n")
13322 {
13323 char *vrf, *pg;
13324 int idx = 0;
13325
13326 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
13327 : NULL;
13328 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
13329
13330 return bgp_show_peer_group_vty(vty, vrf, pg);
13331 }
13332
13333
13334 /* Redistribute VTY commands. */
13335
13336 DEFUN (bgp_redistribute_ipv4,
13337 bgp_redistribute_ipv4_cmd,
13338 "redistribute " FRR_IP_REDIST_STR_BGPD,
13339 "Redistribute information from another routing protocol\n"
13340 FRR_IP_REDIST_HELP_STR_BGPD)
13341 {
13342 VTY_DECLVAR_CONTEXT(bgp, bgp);
13343 int idx_protocol = 1;
13344 int type;
13345
13346 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
13347 if (type < 0) {
13348 vty_out(vty, "%% Invalid route type\n");
13349 return CMD_WARNING_CONFIG_FAILED;
13350 }
13351
13352 bgp_redist_add(bgp, AFI_IP, type, 0);
13353 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
13354 }
13355
13356 ALIAS_HIDDEN(
13357 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
13358 "redistribute " FRR_IP_REDIST_STR_BGPD,
13359 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
13360
13361 DEFUN (bgp_redistribute_ipv4_rmap,
13362 bgp_redistribute_ipv4_rmap_cmd,
13363 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
13364 "Redistribute information from another routing protocol\n"
13365 FRR_IP_REDIST_HELP_STR_BGPD
13366 "Route map reference\n"
13367 "Pointer to route-map entries\n")
13368 {
13369 VTY_DECLVAR_CONTEXT(bgp, bgp);
13370 int idx_protocol = 1;
13371 int idx_word = 3;
13372 int type;
13373 struct bgp_redist *red;
13374 bool changed;
13375 struct route_map *route_map = route_map_lookup_warn_noexist(
13376 vty, argv[idx_word]->arg);
13377
13378 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
13379 if (type < 0) {
13380 vty_out(vty, "%% Invalid route type\n");
13381 return CMD_WARNING_CONFIG_FAILED;
13382 }
13383
13384 red = bgp_redist_add(bgp, AFI_IP, type, 0);
13385 changed =
13386 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
13387 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
13388 }
13389
13390 ALIAS_HIDDEN(
13391 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
13392 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
13393 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
13394 "Route map reference\n"
13395 "Pointer to route-map entries\n")
13396
13397 DEFUN (bgp_redistribute_ipv4_metric,
13398 bgp_redistribute_ipv4_metric_cmd,
13399 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
13400 "Redistribute information from another routing protocol\n"
13401 FRR_IP_REDIST_HELP_STR_BGPD
13402 "Metric for redistributed routes\n"
13403 "Default metric\n")
13404 {
13405 VTY_DECLVAR_CONTEXT(bgp, bgp);
13406 int idx_protocol = 1;
13407 int idx_number = 3;
13408 int type;
13409 uint32_t metric;
13410 struct bgp_redist *red;
13411 bool changed;
13412
13413 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
13414 if (type < 0) {
13415 vty_out(vty, "%% Invalid route type\n");
13416 return CMD_WARNING_CONFIG_FAILED;
13417 }
13418 metric = strtoul(argv[idx_number]->arg, NULL, 10);
13419
13420 red = bgp_redist_add(bgp, AFI_IP, type, 0);
13421 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
13422 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
13423 }
13424
13425 ALIAS_HIDDEN(
13426 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
13427 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
13428 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
13429 "Metric for redistributed routes\n"
13430 "Default metric\n")
13431
13432 DEFUN (bgp_redistribute_ipv4_rmap_metric,
13433 bgp_redistribute_ipv4_rmap_metric_cmd,
13434 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
13435 "Redistribute information from another routing protocol\n"
13436 FRR_IP_REDIST_HELP_STR_BGPD
13437 "Route map reference\n"
13438 "Pointer to route-map entries\n"
13439 "Metric for redistributed routes\n"
13440 "Default metric\n")
13441 {
13442 VTY_DECLVAR_CONTEXT(bgp, bgp);
13443 int idx_protocol = 1;
13444 int idx_word = 3;
13445 int idx_number = 5;
13446 int type;
13447 uint32_t metric;
13448 struct bgp_redist *red;
13449 bool changed;
13450 struct route_map *route_map =
13451 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
13452
13453 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
13454 if (type < 0) {
13455 vty_out(vty, "%% Invalid route type\n");
13456 return CMD_WARNING_CONFIG_FAILED;
13457 }
13458 metric = strtoul(argv[idx_number]->arg, NULL, 10);
13459
13460 red = bgp_redist_add(bgp, AFI_IP, type, 0);
13461 changed =
13462 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
13463 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
13464 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
13465 }
13466
13467 ALIAS_HIDDEN(
13468 bgp_redistribute_ipv4_rmap_metric,
13469 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
13470 "redistribute " FRR_IP_REDIST_STR_BGPD
13471 " route-map WORD metric (0-4294967295)",
13472 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
13473 "Route map reference\n"
13474 "Pointer to route-map entries\n"
13475 "Metric for redistributed routes\n"
13476 "Default metric\n")
13477
13478 DEFUN (bgp_redistribute_ipv4_metric_rmap,
13479 bgp_redistribute_ipv4_metric_rmap_cmd,
13480 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
13481 "Redistribute information from another routing protocol\n"
13482 FRR_IP_REDIST_HELP_STR_BGPD
13483 "Metric for redistributed routes\n"
13484 "Default metric\n"
13485 "Route map reference\n"
13486 "Pointer to route-map entries\n")
13487 {
13488 VTY_DECLVAR_CONTEXT(bgp, bgp);
13489 int idx_protocol = 1;
13490 int idx_number = 3;
13491 int idx_word = 5;
13492 int type;
13493 uint32_t metric;
13494 struct bgp_redist *red;
13495 bool changed;
13496 struct route_map *route_map =
13497 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
13498
13499 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
13500 if (type < 0) {
13501 vty_out(vty, "%% Invalid route type\n");
13502 return CMD_WARNING_CONFIG_FAILED;
13503 }
13504 metric = strtoul(argv[idx_number]->arg, NULL, 10);
13505
13506 red = bgp_redist_add(bgp, AFI_IP, type, 0);
13507 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
13508 changed |=
13509 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
13510 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
13511 }
13512
13513 ALIAS_HIDDEN(
13514 bgp_redistribute_ipv4_metric_rmap,
13515 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
13516 "redistribute " FRR_IP_REDIST_STR_BGPD
13517 " metric (0-4294967295) route-map WORD",
13518 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
13519 "Metric for redistributed routes\n"
13520 "Default metric\n"
13521 "Route map reference\n"
13522 "Pointer to route-map entries\n")
13523
13524 DEFUN (bgp_redistribute_ipv4_ospf,
13525 bgp_redistribute_ipv4_ospf_cmd,
13526 "redistribute <ospf|table> (1-65535)",
13527 "Redistribute information from another routing protocol\n"
13528 "Open Shortest Path First (OSPFv2)\n"
13529 "Non-main Kernel Routing Table\n"
13530 "Instance ID/Table ID\n")
13531 {
13532 VTY_DECLVAR_CONTEXT(bgp, bgp);
13533 int idx_ospf_table = 1;
13534 int idx_number = 2;
13535 unsigned short instance;
13536 unsigned short protocol;
13537
13538 instance = strtoul(argv[idx_number]->arg, NULL, 10);
13539
13540 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
13541 protocol = ZEBRA_ROUTE_OSPF;
13542 else
13543 protocol = ZEBRA_ROUTE_TABLE;
13544
13545 bgp_redist_add(bgp, AFI_IP, protocol, instance);
13546 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
13547 }
13548
13549 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
13550 "redistribute <ospf|table> (1-65535)",
13551 "Redistribute information from another routing protocol\n"
13552 "Open Shortest Path First (OSPFv2)\n"
13553 "Non-main Kernel Routing Table\n"
13554 "Instance ID/Table ID\n")
13555
13556 DEFUN (bgp_redistribute_ipv4_ospf_rmap,
13557 bgp_redistribute_ipv4_ospf_rmap_cmd,
13558 "redistribute <ospf|table> (1-65535) route-map WORD",
13559 "Redistribute information from another routing protocol\n"
13560 "Open Shortest Path First (OSPFv2)\n"
13561 "Non-main Kernel Routing Table\n"
13562 "Instance ID/Table ID\n"
13563 "Route map reference\n"
13564 "Pointer to route-map entries\n")
13565 {
13566 VTY_DECLVAR_CONTEXT(bgp, bgp);
13567 int idx_ospf_table = 1;
13568 int idx_number = 2;
13569 int idx_word = 4;
13570 struct bgp_redist *red;
13571 unsigned short instance;
13572 int protocol;
13573 bool changed;
13574 struct route_map *route_map =
13575 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
13576
13577 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
13578 protocol = ZEBRA_ROUTE_OSPF;
13579 else
13580 protocol = ZEBRA_ROUTE_TABLE;
13581
13582 instance = strtoul(argv[idx_number]->arg, NULL, 10);
13583 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
13584 changed =
13585 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
13586 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
13587 }
13588
13589 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
13590 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
13591 "redistribute <ospf|table> (1-65535) route-map WORD",
13592 "Redistribute information from another routing protocol\n"
13593 "Open Shortest Path First (OSPFv2)\n"
13594 "Non-main Kernel Routing Table\n"
13595 "Instance ID/Table ID\n"
13596 "Route map reference\n"
13597 "Pointer to route-map entries\n")
13598
13599 DEFUN (bgp_redistribute_ipv4_ospf_metric,
13600 bgp_redistribute_ipv4_ospf_metric_cmd,
13601 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
13602 "Redistribute information from another routing protocol\n"
13603 "Open Shortest Path First (OSPFv2)\n"
13604 "Non-main Kernel Routing Table\n"
13605 "Instance ID/Table ID\n"
13606 "Metric for redistributed routes\n"
13607 "Default metric\n")
13608 {
13609 VTY_DECLVAR_CONTEXT(bgp, bgp);
13610 int idx_ospf_table = 1;
13611 int idx_number = 2;
13612 int idx_number_2 = 4;
13613 uint32_t metric;
13614 struct bgp_redist *red;
13615 unsigned short instance;
13616 int protocol;
13617 bool changed;
13618
13619 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
13620 protocol = ZEBRA_ROUTE_OSPF;
13621 else
13622 protocol = ZEBRA_ROUTE_TABLE;
13623
13624 instance = strtoul(argv[idx_number]->arg, NULL, 10);
13625 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
13626
13627 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
13628 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
13629 metric);
13630 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
13631 }
13632
13633 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
13634 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
13635 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
13636 "Redistribute information from another routing protocol\n"
13637 "Open Shortest Path First (OSPFv2)\n"
13638 "Non-main Kernel Routing Table\n"
13639 "Instance ID/Table ID\n"
13640 "Metric for redistributed routes\n"
13641 "Default metric\n")
13642
13643 DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
13644 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
13645 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
13646 "Redistribute information from another routing protocol\n"
13647 "Open Shortest Path First (OSPFv2)\n"
13648 "Non-main Kernel Routing Table\n"
13649 "Instance ID/Table ID\n"
13650 "Route map reference\n"
13651 "Pointer to route-map entries\n"
13652 "Metric for redistributed routes\n"
13653 "Default metric\n")
13654 {
13655 VTY_DECLVAR_CONTEXT(bgp, bgp);
13656 int idx_ospf_table = 1;
13657 int idx_number = 2;
13658 int idx_word = 4;
13659 int idx_number_2 = 6;
13660 uint32_t metric;
13661 struct bgp_redist *red;
13662 unsigned short instance;
13663 int protocol;
13664 bool changed;
13665 struct route_map *route_map =
13666 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
13667
13668 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
13669 protocol = ZEBRA_ROUTE_OSPF;
13670 else
13671 protocol = ZEBRA_ROUTE_TABLE;
13672
13673 instance = strtoul(argv[idx_number]->arg, NULL, 10);
13674 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
13675
13676 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
13677 changed =
13678 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
13679 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
13680 metric);
13681 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
13682 }
13683
13684 ALIAS_HIDDEN(
13685 bgp_redistribute_ipv4_ospf_rmap_metric,
13686 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
13687 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
13688 "Redistribute information from another routing protocol\n"
13689 "Open Shortest Path First (OSPFv2)\n"
13690 "Non-main Kernel Routing Table\n"
13691 "Instance ID/Table ID\n"
13692 "Route map reference\n"
13693 "Pointer to route-map entries\n"
13694 "Metric for redistributed routes\n"
13695 "Default metric\n")
13696
13697 DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
13698 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
13699 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
13700 "Redistribute information from another routing protocol\n"
13701 "Open Shortest Path First (OSPFv2)\n"
13702 "Non-main Kernel Routing Table\n"
13703 "Instance ID/Table ID\n"
13704 "Metric for redistributed routes\n"
13705 "Default metric\n"
13706 "Route map reference\n"
13707 "Pointer to route-map entries\n")
13708 {
13709 VTY_DECLVAR_CONTEXT(bgp, bgp);
13710 int idx_ospf_table = 1;
13711 int idx_number = 2;
13712 int idx_number_2 = 4;
13713 int idx_word = 6;
13714 uint32_t metric;
13715 struct bgp_redist *red;
13716 unsigned short instance;
13717 int protocol;
13718 bool changed;
13719 struct route_map *route_map =
13720 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
13721
13722 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
13723 protocol = ZEBRA_ROUTE_OSPF;
13724 else
13725 protocol = ZEBRA_ROUTE_TABLE;
13726
13727 instance = strtoul(argv[idx_number]->arg, NULL, 10);
13728 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
13729
13730 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
13731 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
13732 metric);
13733 changed |=
13734 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
13735 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
13736 }
13737
13738 ALIAS_HIDDEN(
13739 bgp_redistribute_ipv4_ospf_metric_rmap,
13740 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
13741 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
13742 "Redistribute information from another routing protocol\n"
13743 "Open Shortest Path First (OSPFv2)\n"
13744 "Non-main Kernel Routing Table\n"
13745 "Instance ID/Table ID\n"
13746 "Metric for redistributed routes\n"
13747 "Default metric\n"
13748 "Route map reference\n"
13749 "Pointer to route-map entries\n")
13750
13751 DEFUN (no_bgp_redistribute_ipv4_ospf,
13752 no_bgp_redistribute_ipv4_ospf_cmd,
13753 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
13754 NO_STR
13755 "Redistribute information from another routing protocol\n"
13756 "Open Shortest Path First (OSPFv2)\n"
13757 "Non-main Kernel Routing Table\n"
13758 "Instance ID/Table ID\n"
13759 "Metric for redistributed routes\n"
13760 "Default metric\n"
13761 "Route map reference\n"
13762 "Pointer to route-map entries\n")
13763 {
13764 VTY_DECLVAR_CONTEXT(bgp, bgp);
13765 int idx_ospf_table = 2;
13766 int idx_number = 3;
13767 unsigned short instance;
13768 int protocol;
13769
13770 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
13771 protocol = ZEBRA_ROUTE_OSPF;
13772 else
13773 protocol = ZEBRA_ROUTE_TABLE;
13774
13775 instance = strtoul(argv[idx_number]->arg, NULL, 10);
13776 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
13777 }
13778
13779 ALIAS_HIDDEN(
13780 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
13781 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
13782 NO_STR
13783 "Redistribute information from another routing protocol\n"
13784 "Open Shortest Path First (OSPFv2)\n"
13785 "Non-main Kernel Routing Table\n"
13786 "Instance ID/Table ID\n"
13787 "Metric for redistributed routes\n"
13788 "Default metric\n"
13789 "Route map reference\n"
13790 "Pointer to route-map entries\n")
13791
13792 DEFUN (no_bgp_redistribute_ipv4,
13793 no_bgp_redistribute_ipv4_cmd,
13794 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
13795 NO_STR
13796 "Redistribute information from another routing protocol\n"
13797 FRR_IP_REDIST_HELP_STR_BGPD
13798 "Metric for redistributed routes\n"
13799 "Default metric\n"
13800 "Route map reference\n"
13801 "Pointer to route-map entries\n")
13802 {
13803 VTY_DECLVAR_CONTEXT(bgp, bgp);
13804 int idx_protocol = 2;
13805 int type;
13806
13807 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
13808 if (type < 0) {
13809 vty_out(vty, "%% Invalid route type\n");
13810 return CMD_WARNING_CONFIG_FAILED;
13811 }
13812 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
13813 }
13814
13815 ALIAS_HIDDEN(
13816 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
13817 "no redistribute " FRR_IP_REDIST_STR_BGPD
13818 " [{metric (0-4294967295)|route-map WORD}]",
13819 NO_STR
13820 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
13821 "Metric for redistributed routes\n"
13822 "Default metric\n"
13823 "Route map reference\n"
13824 "Pointer to route-map entries\n")
13825
13826 DEFUN (bgp_redistribute_ipv6,
13827 bgp_redistribute_ipv6_cmd,
13828 "redistribute " FRR_IP6_REDIST_STR_BGPD,
13829 "Redistribute information from another routing protocol\n"
13830 FRR_IP6_REDIST_HELP_STR_BGPD)
13831 {
13832 VTY_DECLVAR_CONTEXT(bgp, bgp);
13833 int idx_protocol = 1;
13834 int type;
13835
13836 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
13837 if (type < 0) {
13838 vty_out(vty, "%% Invalid route type\n");
13839 return CMD_WARNING_CONFIG_FAILED;
13840 }
13841
13842 bgp_redist_add(bgp, AFI_IP6, type, 0);
13843 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
13844 }
13845
13846 DEFUN (bgp_redistribute_ipv6_rmap,
13847 bgp_redistribute_ipv6_rmap_cmd,
13848 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
13849 "Redistribute information from another routing protocol\n"
13850 FRR_IP6_REDIST_HELP_STR_BGPD
13851 "Route map reference\n"
13852 "Pointer to route-map entries\n")
13853 {
13854 VTY_DECLVAR_CONTEXT(bgp, bgp);
13855 int idx_protocol = 1;
13856 int idx_word = 3;
13857 int type;
13858 struct bgp_redist *red;
13859 bool changed;
13860 struct route_map *route_map =
13861 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
13862
13863 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
13864 if (type < 0) {
13865 vty_out(vty, "%% Invalid route type\n");
13866 return CMD_WARNING_CONFIG_FAILED;
13867 }
13868
13869 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
13870 changed =
13871 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
13872 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
13873 }
13874
13875 DEFUN (bgp_redistribute_ipv6_metric,
13876 bgp_redistribute_ipv6_metric_cmd,
13877 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
13878 "Redistribute information from another routing protocol\n"
13879 FRR_IP6_REDIST_HELP_STR_BGPD
13880 "Metric for redistributed routes\n"
13881 "Default metric\n")
13882 {
13883 VTY_DECLVAR_CONTEXT(bgp, bgp);
13884 int idx_protocol = 1;
13885 int idx_number = 3;
13886 int type;
13887 uint32_t metric;
13888 struct bgp_redist *red;
13889 bool changed;
13890
13891 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
13892 if (type < 0) {
13893 vty_out(vty, "%% Invalid route type\n");
13894 return CMD_WARNING_CONFIG_FAILED;
13895 }
13896 metric = strtoul(argv[idx_number]->arg, NULL, 10);
13897
13898 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
13899 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
13900 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
13901 }
13902
13903 DEFUN (bgp_redistribute_ipv6_rmap_metric,
13904 bgp_redistribute_ipv6_rmap_metric_cmd,
13905 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
13906 "Redistribute information from another routing protocol\n"
13907 FRR_IP6_REDIST_HELP_STR_BGPD
13908 "Route map reference\n"
13909 "Pointer to route-map entries\n"
13910 "Metric for redistributed routes\n"
13911 "Default metric\n")
13912 {
13913 VTY_DECLVAR_CONTEXT(bgp, bgp);
13914 int idx_protocol = 1;
13915 int idx_word = 3;
13916 int idx_number = 5;
13917 int type;
13918 uint32_t metric;
13919 struct bgp_redist *red;
13920 bool changed;
13921 struct route_map *route_map =
13922 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
13923
13924 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
13925 if (type < 0) {
13926 vty_out(vty, "%% Invalid route type\n");
13927 return CMD_WARNING_CONFIG_FAILED;
13928 }
13929 metric = strtoul(argv[idx_number]->arg, NULL, 10);
13930
13931 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
13932 changed =
13933 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
13934 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
13935 metric);
13936 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
13937 }
13938
13939 DEFUN (bgp_redistribute_ipv6_metric_rmap,
13940 bgp_redistribute_ipv6_metric_rmap_cmd,
13941 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
13942 "Redistribute information from another routing protocol\n"
13943 FRR_IP6_REDIST_HELP_STR_BGPD
13944 "Metric for redistributed routes\n"
13945 "Default metric\n"
13946 "Route map reference\n"
13947 "Pointer to route-map entries\n")
13948 {
13949 VTY_DECLVAR_CONTEXT(bgp, bgp);
13950 int idx_protocol = 1;
13951 int idx_number = 3;
13952 int idx_word = 5;
13953 int type;
13954 uint32_t metric;
13955 struct bgp_redist *red;
13956 bool changed;
13957 struct route_map *route_map =
13958 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
13959
13960 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
13961 if (type < 0) {
13962 vty_out(vty, "%% Invalid route type\n");
13963 return CMD_WARNING_CONFIG_FAILED;
13964 }
13965 metric = strtoul(argv[idx_number]->arg, NULL, 10);
13966
13967 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
13968 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
13969 metric);
13970 changed |=
13971 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
13972 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
13973 }
13974
13975 DEFUN (no_bgp_redistribute_ipv6,
13976 no_bgp_redistribute_ipv6_cmd,
13977 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
13978 NO_STR
13979 "Redistribute information from another routing protocol\n"
13980 FRR_IP6_REDIST_HELP_STR_BGPD
13981 "Metric for redistributed routes\n"
13982 "Default metric\n"
13983 "Route map reference\n"
13984 "Pointer to route-map entries\n")
13985 {
13986 VTY_DECLVAR_CONTEXT(bgp, bgp);
13987 int idx_protocol = 2;
13988 int type;
13989
13990 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
13991 if (type < 0) {
13992 vty_out(vty, "%% Invalid route type\n");
13993 return CMD_WARNING_CONFIG_FAILED;
13994 }
13995
13996 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
13997 }
13998
13999 static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
14000 afi_t afi, safi_t safi)
14001 {
14002 int i;
14003
14004 /* Unicast redistribution only. */
14005 if (safi != SAFI_UNICAST)
14006 return;
14007
14008 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
14009 /* Redistribute BGP does not make sense. */
14010 if (i != ZEBRA_ROUTE_BGP) {
14011 struct list *red_list;
14012 struct listnode *node;
14013 struct bgp_redist *red;
14014
14015 red_list = bgp->redist[afi][i];
14016 if (!red_list)
14017 continue;
14018
14019 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
14020 /* "redistribute" configuration. */
14021 vty_out(vty, " redistribute %s",
14022 zebra_route_string(i));
14023 if (red->instance)
14024 vty_out(vty, " %d", red->instance);
14025 if (red->redist_metric_flag)
14026 vty_out(vty, " metric %u",
14027 red->redist_metric);
14028 if (red->rmap.name)
14029 vty_out(vty, " route-map %s",
14030 red->rmap.name);
14031 vty_out(vty, "\n");
14032 }
14033 }
14034 }
14035 }
14036
14037 /* peer-group helpers for config-write */
14038
14039 static bool peergroup_flag_check(struct peer *peer, uint32_t flag)
14040 {
14041 if (!peer_group_active(peer)) {
14042 if (CHECK_FLAG(peer->flags_invert, flag))
14043 return !CHECK_FLAG(peer->flags, flag);
14044 else
14045 return !!CHECK_FLAG(peer->flags, flag);
14046 }
14047
14048 return !!CHECK_FLAG(peer->flags_override, flag);
14049 }
14050
14051 static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
14052 uint32_t flag)
14053 {
14054 if (!peer_group_active(peer)) {
14055 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
14056 return !peer_af_flag_check(peer, afi, safi, flag);
14057 else
14058 return !!peer_af_flag_check(peer, afi, safi, flag);
14059 }
14060
14061 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
14062 }
14063
14064 static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
14065 uint8_t type, int direct)
14066 {
14067 struct bgp_filter *filter;
14068
14069 if (peer_group_active(peer))
14070 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
14071 type);
14072
14073 filter = &peer->filter[afi][safi];
14074 switch (type) {
14075 case PEER_FT_DISTRIBUTE_LIST:
14076 return !!(filter->dlist[direct].name);
14077 case PEER_FT_FILTER_LIST:
14078 return !!(filter->aslist[direct].name);
14079 case PEER_FT_PREFIX_LIST:
14080 return !!(filter->plist[direct].name);
14081 case PEER_FT_ROUTE_MAP:
14082 return !!(filter->map[direct].name);
14083 case PEER_FT_UNSUPPRESS_MAP:
14084 return !!(filter->usmap.name);
14085 default:
14086 return false;
14087 }
14088 }
14089
14090 /* Return true if the addpath type is set for peer and different from
14091 * peer-group.
14092 */
14093 static int peergroup_af_addpath_check(struct peer *peer, afi_t afi, safi_t safi)
14094 {
14095 enum bgp_addpath_strat type, g_type;
14096
14097 type = peer->addpath_type[afi][safi];
14098
14099 if (type != BGP_ADDPATH_NONE) {
14100 if (peer_group_active(peer)) {
14101 g_type = peer->group->conf->addpath_type[afi][safi];
14102
14103 if (type != g_type)
14104 return 1;
14105 else
14106 return 0;
14107 }
14108
14109 return 1;
14110 }
14111
14112 return 0;
14113 }
14114
14115 /* This is part of the address-family block (unicast only) */
14116 static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
14117 afi_t afi)
14118 {
14119 int indent = 2;
14120
14121 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
14122 if (listcount(bgp->vpn_policy[afi].import_vrf))
14123 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
14124 bgp->vpn_policy[afi]
14125 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
14126 else
14127 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
14128 bgp->vpn_policy[afi]
14129 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
14130 }
14131 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
14132 BGP_CONFIG_VRF_TO_VRF_IMPORT)
14133 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
14134 BGP_CONFIG_VRF_TO_VRF_EXPORT))
14135 return;
14136
14137 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
14138 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
14139
14140 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
14141
14142 } else {
14143 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
14144 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
14145 bgp->vpn_policy[afi].tovpn_label);
14146 }
14147 }
14148 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
14149 BGP_VPN_POLICY_TOVPN_RD_SET)) {
14150 char buf[RD_ADDRSTRLEN];
14151 vty_out(vty, "%*srd vpn export %s\n", indent, "",
14152 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
14153 sizeof(buf)));
14154 }
14155 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
14156 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
14157
14158 char buf[PREFIX_STRLEN];
14159 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
14160 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
14161 sizeof(buf))) {
14162
14163 vty_out(vty, "%*snexthop vpn export %s\n",
14164 indent, "", buf);
14165 }
14166 }
14167 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
14168 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
14169 && ecommunity_cmp(
14170 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
14171 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
14172
14173 char *b = ecommunity_ecom2str(
14174 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
14175 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
14176 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
14177 XFREE(MTYPE_ECOMMUNITY_STR, b);
14178 } else {
14179 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
14180 char *b = ecommunity_ecom2str(
14181 bgp->vpn_policy[afi]
14182 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
14183 ECOMMUNITY_FORMAT_ROUTE_MAP,
14184 ECOMMUNITY_ROUTE_TARGET);
14185 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
14186 XFREE(MTYPE_ECOMMUNITY_STR, b);
14187 }
14188 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
14189 char *b = ecommunity_ecom2str(
14190 bgp->vpn_policy[afi]
14191 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
14192 ECOMMUNITY_FORMAT_ROUTE_MAP,
14193 ECOMMUNITY_ROUTE_TARGET);
14194 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
14195 XFREE(MTYPE_ECOMMUNITY_STR, b);
14196 }
14197 }
14198
14199 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
14200 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
14201 bgp->vpn_policy[afi]
14202 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
14203
14204 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
14205 char *b = ecommunity_ecom2str(
14206 bgp->vpn_policy[afi]
14207 .import_redirect_rtlist,
14208 ECOMMUNITY_FORMAT_ROUTE_MAP,
14209 ECOMMUNITY_ROUTE_TARGET);
14210
14211 vty_out(vty, "%*srt redirect import %s\n", indent, "", b);
14212 XFREE(MTYPE_ECOMMUNITY_STR, b);
14213 }
14214 }
14215
14216 static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
14217 afi_t afi, safi_t safi)
14218 {
14219 struct bgp_filter *filter;
14220 char *addr;
14221
14222 addr = peer->host;
14223 filter = &peer->filter[afi][safi];
14224
14225 /* distribute-list. */
14226 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
14227 FILTER_IN))
14228 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
14229 filter->dlist[FILTER_IN].name);
14230
14231 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
14232 FILTER_OUT))
14233 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
14234 filter->dlist[FILTER_OUT].name);
14235
14236 /* prefix-list. */
14237 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
14238 FILTER_IN))
14239 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
14240 filter->plist[FILTER_IN].name);
14241
14242 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
14243 FILTER_OUT))
14244 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
14245 filter->plist[FILTER_OUT].name);
14246
14247 /* route-map. */
14248 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
14249 vty_out(vty, " neighbor %s route-map %s in\n", addr,
14250 filter->map[RMAP_IN].name);
14251
14252 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
14253 RMAP_OUT))
14254 vty_out(vty, " neighbor %s route-map %s out\n", addr,
14255 filter->map[RMAP_OUT].name);
14256
14257 /* unsuppress-map */
14258 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
14259 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
14260 filter->usmap.name);
14261
14262 /* filter-list. */
14263 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
14264 FILTER_IN))
14265 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
14266 filter->aslist[FILTER_IN].name);
14267
14268 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
14269 FILTER_OUT))
14270 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
14271 filter->aslist[FILTER_OUT].name);
14272 }
14273
14274 /* BGP peer configuration display function. */
14275 static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
14276 struct peer *peer)
14277 {
14278 struct peer *g_peer = NULL;
14279 char buf[SU_ADDRSTRLEN];
14280 char *addr;
14281 int if_pg_printed = false;
14282 int if_ras_printed = false;
14283
14284 /* Skip dynamic neighbors. */
14285 if (peer_dynamic_neighbor(peer))
14286 return;
14287
14288 if (peer->conf_if)
14289 addr = peer->conf_if;
14290 else
14291 addr = peer->host;
14292
14293 /************************************
14294 ****** Global to the neighbor ******
14295 ************************************/
14296 if (peer->conf_if) {
14297 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
14298 vty_out(vty, " neighbor %s interface v6only", addr);
14299 else
14300 vty_out(vty, " neighbor %s interface", addr);
14301
14302 if (peer_group_active(peer)) {
14303 vty_out(vty, " peer-group %s", peer->group->name);
14304 if_pg_printed = true;
14305 } else if (peer->as_type == AS_SPECIFIED) {
14306 vty_out(vty, " remote-as %u", peer->as);
14307 if_ras_printed = true;
14308 } else if (peer->as_type == AS_INTERNAL) {
14309 vty_out(vty, " remote-as internal");
14310 if_ras_printed = true;
14311 } else if (peer->as_type == AS_EXTERNAL) {
14312 vty_out(vty, " remote-as external");
14313 if_ras_printed = true;
14314 }
14315
14316 vty_out(vty, "\n");
14317 }
14318
14319 /* remote-as and peer-group */
14320 /* peer is a member of a peer-group */
14321 if (peer_group_active(peer)) {
14322 g_peer = peer->group->conf;
14323
14324 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
14325 if (peer->as_type == AS_SPECIFIED) {
14326 vty_out(vty, " neighbor %s remote-as %u\n",
14327 addr, peer->as);
14328 } else if (peer->as_type == AS_INTERNAL) {
14329 vty_out(vty,
14330 " neighbor %s remote-as internal\n",
14331 addr);
14332 } else if (peer->as_type == AS_EXTERNAL) {
14333 vty_out(vty,
14334 " neighbor %s remote-as external\n",
14335 addr);
14336 }
14337 }
14338
14339 /* For swpX peers we displayed the peer-group
14340 * via 'neighbor swpX interface peer-group PGNAME' */
14341 if (!if_pg_printed)
14342 vty_out(vty, " neighbor %s peer-group %s\n", addr,
14343 peer->group->name);
14344 }
14345
14346 /* peer is NOT a member of a peer-group */
14347 else {
14348 /* peer is a peer-group, declare the peer-group */
14349 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
14350 vty_out(vty, " neighbor %s peer-group\n", addr);
14351 }
14352
14353 if (!if_ras_printed) {
14354 if (peer->as_type == AS_SPECIFIED) {
14355 vty_out(vty, " neighbor %s remote-as %u\n",
14356 addr, peer->as);
14357 } else if (peer->as_type == AS_INTERNAL) {
14358 vty_out(vty,
14359 " neighbor %s remote-as internal\n",
14360 addr);
14361 } else if (peer->as_type == AS_EXTERNAL) {
14362 vty_out(vty,
14363 " neighbor %s remote-as external\n",
14364 addr);
14365 }
14366 }
14367 }
14368
14369 /* local-as */
14370 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
14371 vty_out(vty, " neighbor %s local-as %u", addr,
14372 peer->change_local_as);
14373 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
14374 vty_out(vty, " no-prepend");
14375 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
14376 vty_out(vty, " replace-as");
14377 vty_out(vty, "\n");
14378 }
14379
14380 /* description */
14381 if (peer->desc) {
14382 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
14383 }
14384
14385 /* shutdown */
14386 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
14387 if (peer->tx_shutdown_message)
14388 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
14389 peer->tx_shutdown_message);
14390 else
14391 vty_out(vty, " neighbor %s shutdown\n", addr);
14392 }
14393
14394 /* bfd */
14395 if (peer->bfd_info) {
14396 if (!peer_group_active(peer) || !g_peer->bfd_info) {
14397 bgp_bfd_peer_config_write(vty, peer, addr);
14398 }
14399 }
14400
14401 /* password */
14402 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
14403 vty_out(vty, " neighbor %s password %s\n", addr,
14404 peer->password);
14405
14406 /* neighbor solo */
14407 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
14408 if (!peer_group_active(peer)) {
14409 vty_out(vty, " neighbor %s solo\n", addr);
14410 }
14411 }
14412
14413 /* BGP port */
14414 if (peer->port != BGP_PORT_DEFAULT) {
14415 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
14416 }
14417
14418 /* Local interface name */
14419 if (peer->ifname) {
14420 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
14421 }
14422
14423 /* passive */
14424 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
14425 vty_out(vty, " neighbor %s passive\n", addr);
14426
14427 /* ebgp-multihop */
14428 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
14429 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
14430 && peer->ttl == MAXTTL)) {
14431 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
14432 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
14433 peer->ttl);
14434 }
14435 }
14436
14437 /* ttl-security hops */
14438 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
14439 if (!peer_group_active(peer)
14440 || g_peer->gtsm_hops != peer->gtsm_hops) {
14441 vty_out(vty, " neighbor %s ttl-security hops %d\n",
14442 addr, peer->gtsm_hops);
14443 }
14444 }
14445
14446 /* disable-connected-check */
14447 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
14448 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
14449
14450 /* enforce-first-as */
14451 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
14452 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
14453
14454 /* update-source */
14455 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
14456 if (peer->update_source)
14457 vty_out(vty, " neighbor %s update-source %s\n", addr,
14458 sockunion2str(peer->update_source, buf,
14459 SU_ADDRSTRLEN));
14460 else if (peer->update_if)
14461 vty_out(vty, " neighbor %s update-source %s\n", addr,
14462 peer->update_if);
14463 }
14464
14465 /* advertisement-interval */
14466 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
14467 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
14468 peer->routeadv);
14469
14470 /* timers */
14471 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
14472 vty_out(vty, " neighbor %s timers %u %u\n", addr,
14473 peer->keepalive, peer->holdtime);
14474
14475 /* timers connect */
14476 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
14477 vty_out(vty, " neighbor %s timers connect %u\n", addr,
14478 peer->connect);
14479 /* need special-case handling for changed default values due to
14480 * config profile / version (because there is no "timers bgp connect"
14481 * command, we need to save this per-peer :/)
14482 */
14483 else if (!peer_group_active(peer) && !peer->connect &&
14484 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
14485 vty_out(vty, " neighbor %s timers connect %u\n", addr,
14486 peer->bgp->default_connect_retry);
14487
14488 /* capability dynamic */
14489 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
14490 vty_out(vty, " neighbor %s capability dynamic\n", addr);
14491
14492 /* capability extended-nexthop */
14493 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
14494 if (!peer->conf_if) {
14495 if (CHECK_FLAG(peer->flags_invert,
14496 PEER_FLAG_CAPABILITY_ENHE))
14497 vty_out(vty,
14498 " no neighbor %s capability extended-nexthop\n",
14499 addr);
14500 else
14501 vty_out(vty,
14502 " neighbor %s capability extended-nexthop\n",
14503 addr);
14504 }
14505 }
14506
14507 /* dont-capability-negotiation */
14508 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
14509 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
14510
14511 /* override-capability */
14512 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
14513 vty_out(vty, " neighbor %s override-capability\n", addr);
14514
14515 /* strict-capability-match */
14516 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
14517 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
14518
14519 /* Sender side AS path loop detection. */
14520 if (peer->as_path_loop_detection)
14521 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
14522 addr);
14523
14524 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
14525 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
14526
14527 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
14528 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
14529 vty_out(vty,
14530 " neighbor %s graceful-restart-helper\n", addr);
14531 } else if (CHECK_FLAG(
14532 peer->peer_gr_new_status_flag,
14533 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
14534 vty_out(vty,
14535 " neighbor %s graceful-restart\n", addr);
14536 } else if (
14537 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
14538 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
14539 && !(CHECK_FLAG(
14540 peer->peer_gr_new_status_flag,
14541 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
14542 vty_out(vty, " neighbor %s graceful-restart-disable\n",
14543 addr);
14544 }
14545 }
14546 }
14547
14548 /* BGP peer configuration display function. */
14549 static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
14550 struct peer *peer, afi_t afi, safi_t safi)
14551 {
14552 struct peer *g_peer = NULL;
14553 char *addr;
14554 bool flag_scomm, flag_secomm, flag_slcomm;
14555
14556 /* Skip dynamic neighbors. */
14557 if (peer_dynamic_neighbor(peer))
14558 return;
14559
14560 if (peer->conf_if)
14561 addr = peer->conf_if;
14562 else
14563 addr = peer->host;
14564
14565 /************************************
14566 ****** Per AF to the neighbor ******
14567 ************************************/
14568 if (peer_group_active(peer)) {
14569 g_peer = peer->group->conf;
14570
14571 /* If the peer-group is active but peer is not, print a 'no
14572 * activate' */
14573 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
14574 vty_out(vty, " no neighbor %s activate\n", addr);
14575 }
14576
14577 /* If the peer-group is not active but peer is, print an
14578 'activate' */
14579 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
14580 vty_out(vty, " neighbor %s activate\n", addr);
14581 }
14582 } else {
14583 if (peer->afc[afi][safi]) {
14584 if ((afi == AFI_IP) && (safi == SAFI_UNICAST)) {
14585 if (CHECK_FLAG(bgp->flags,
14586 BGP_FLAG_NO_DEFAULT_IPV4)) {
14587 vty_out(vty, " neighbor %s activate\n",
14588 addr);
14589 }
14590 } else
14591 vty_out(vty, " neighbor %s activate\n", addr);
14592 } else {
14593 if ((afi == AFI_IP) && (safi == SAFI_UNICAST)) {
14594 if (!CHECK_FLAG(bgp->flags,
14595 BGP_FLAG_NO_DEFAULT_IPV4)) {
14596 vty_out(vty,
14597 " no neighbor %s activate\n",
14598 addr);
14599 }
14600 }
14601 }
14602 }
14603
14604 /* addpath TX knobs */
14605 if (peergroup_af_addpath_check(peer, afi, safi)) {
14606 switch (peer->addpath_type[afi][safi]) {
14607 case BGP_ADDPATH_ALL:
14608 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
14609 addr);
14610 break;
14611 case BGP_ADDPATH_BEST_PER_AS:
14612 vty_out(vty,
14613 " neighbor %s addpath-tx-bestpath-per-AS\n",
14614 addr);
14615 break;
14616 case BGP_ADDPATH_MAX:
14617 case BGP_ADDPATH_NONE:
14618 break;
14619 }
14620 }
14621
14622 /* ORF capability. */
14623 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
14624 || peergroup_af_flag_check(peer, afi, safi,
14625 PEER_FLAG_ORF_PREFIX_RM)) {
14626 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
14627
14628 if (peergroup_af_flag_check(peer, afi, safi,
14629 PEER_FLAG_ORF_PREFIX_SM)
14630 && peergroup_af_flag_check(peer, afi, safi,
14631 PEER_FLAG_ORF_PREFIX_RM))
14632 vty_out(vty, " both");
14633 else if (peergroup_af_flag_check(peer, afi, safi,
14634 PEER_FLAG_ORF_PREFIX_SM))
14635 vty_out(vty, " send");
14636 else
14637 vty_out(vty, " receive");
14638 vty_out(vty, "\n");
14639 }
14640
14641 /* BGP flag dampening. */
14642 if (CHECK_FLAG(bgp->af_flags[afi][safi],
14643 BGP_CONFIG_DAMPENING))
14644 bgp_config_write_damp(vty, afi, safi);
14645
14646 /* Route reflector client. */
14647 if (peergroup_af_flag_check(peer, afi, safi,
14648 PEER_FLAG_REFLECTOR_CLIENT)) {
14649 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
14650 }
14651
14652 /* next-hop-self force */
14653 if (peergroup_af_flag_check(peer, afi, safi,
14654 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
14655 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
14656 }
14657
14658 /* next-hop-self */
14659 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
14660 vty_out(vty, " neighbor %s next-hop-self\n", addr);
14661 }
14662
14663 /* remove-private-AS */
14664 if (peergroup_af_flag_check(peer, afi, safi,
14665 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
14666 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
14667 addr);
14668 }
14669
14670 else if (peergroup_af_flag_check(peer, afi, safi,
14671 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
14672 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
14673 addr);
14674 }
14675
14676 else if (peergroup_af_flag_check(peer, afi, safi,
14677 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
14678 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
14679 }
14680
14681 else if (peergroup_af_flag_check(peer, afi, safi,
14682 PEER_FLAG_REMOVE_PRIVATE_AS)) {
14683 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
14684 }
14685
14686 /* as-override */
14687 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
14688 vty_out(vty, " neighbor %s as-override\n", addr);
14689 }
14690
14691 /* send-community print. */
14692 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
14693 PEER_FLAG_SEND_COMMUNITY);
14694 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
14695 PEER_FLAG_SEND_EXT_COMMUNITY);
14696 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
14697 PEER_FLAG_SEND_LARGE_COMMUNITY);
14698
14699 if (flag_scomm && flag_secomm && flag_slcomm) {
14700 vty_out(vty, " no neighbor %s send-community all\n", addr);
14701 } else {
14702 if (flag_scomm)
14703 vty_out(vty, " no neighbor %s send-community\n", addr);
14704 if (flag_secomm)
14705 vty_out(vty,
14706 " no neighbor %s send-community extended\n",
14707 addr);
14708
14709 if (flag_slcomm)
14710 vty_out(vty, " no neighbor %s send-community large\n",
14711 addr);
14712 }
14713
14714 /* Default information */
14715 if (peergroup_af_flag_check(peer, afi, safi,
14716 PEER_FLAG_DEFAULT_ORIGINATE)) {
14717 vty_out(vty, " neighbor %s default-originate", addr);
14718
14719 if (peer->default_rmap[afi][safi].name)
14720 vty_out(vty, " route-map %s",
14721 peer->default_rmap[afi][safi].name);
14722
14723 vty_out(vty, "\n");
14724 }
14725
14726 /* Soft reconfiguration inbound. */
14727 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
14728 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
14729 addr);
14730 }
14731
14732 /* maximum-prefix. */
14733 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
14734 vty_out(vty, " neighbor %s maximum-prefix %" PRIu32, addr,
14735 peer->pmax[afi][safi]);
14736
14737 if (peer->pmax_threshold[afi][safi]
14738 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
14739 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
14740 if (peer_af_flag_check(peer, afi, safi,
14741 PEER_FLAG_MAX_PREFIX_WARNING))
14742 vty_out(vty, " warning-only");
14743 if (peer->pmax_restart[afi][safi])
14744 vty_out(vty, " restart %u",
14745 peer->pmax_restart[afi][safi]);
14746
14747 vty_out(vty, "\n");
14748 }
14749
14750 /* maximum-prefix-out */
14751 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
14752 vty_out(vty, " neighbor %s maximum-prefix-out %" PRIu32 "\n",
14753 addr, peer->pmax_out[afi][safi]);
14754
14755 /* Route server client. */
14756 if (peergroup_af_flag_check(peer, afi, safi,
14757 PEER_FLAG_RSERVER_CLIENT)) {
14758 vty_out(vty, " neighbor %s route-server-client\n", addr);
14759 }
14760
14761 /* Nexthop-local unchanged. */
14762 if (peergroup_af_flag_check(peer, afi, safi,
14763 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
14764 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
14765 }
14766
14767 /* allowas-in <1-10> */
14768 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
14769 if (peer_af_flag_check(peer, afi, safi,
14770 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
14771 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
14772 } else if (peer->allowas_in[afi][safi] == 3) {
14773 vty_out(vty, " neighbor %s allowas-in\n", addr);
14774 } else {
14775 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
14776 peer->allowas_in[afi][safi]);
14777 }
14778 }
14779
14780 /* weight */
14781 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
14782 vty_out(vty, " neighbor %s weight %lu\n", addr,
14783 peer->weight[afi][safi]);
14784
14785 /* Filter. */
14786 bgp_config_write_filter(vty, peer, afi, safi);
14787
14788 /* atribute-unchanged. */
14789 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
14790 || (safi != SAFI_EVPN
14791 && peer_af_flag_check(peer, afi, safi,
14792 PEER_FLAG_NEXTHOP_UNCHANGED))
14793 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
14794
14795 if (!peer_group_active(peer)
14796 || peergroup_af_flag_check(peer, afi, safi,
14797 PEER_FLAG_AS_PATH_UNCHANGED)
14798 || peergroup_af_flag_check(peer, afi, safi,
14799 PEER_FLAG_NEXTHOP_UNCHANGED)
14800 || peergroup_af_flag_check(peer, afi, safi,
14801 PEER_FLAG_MED_UNCHANGED)) {
14802
14803 vty_out(vty,
14804 " neighbor %s attribute-unchanged%s%s%s\n",
14805 addr,
14806 peer_af_flag_check(peer, afi, safi,
14807 PEER_FLAG_AS_PATH_UNCHANGED)
14808 ? " as-path"
14809 : "",
14810 peer_af_flag_check(peer, afi, safi,
14811 PEER_FLAG_NEXTHOP_UNCHANGED)
14812 ? " next-hop"
14813 : "",
14814 peer_af_flag_check(peer, afi, safi,
14815 PEER_FLAG_MED_UNCHANGED)
14816 ? " med"
14817 : "");
14818 }
14819 }
14820 }
14821
14822 /* Address family based peer configuration display. */
14823 static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
14824 safi_t safi)
14825 {
14826 struct peer *peer;
14827 struct peer_group *group;
14828 struct listnode *node, *nnode;
14829
14830
14831 vty_frame(vty, " !\n address-family ");
14832 if (afi == AFI_IP) {
14833 if (safi == SAFI_UNICAST)
14834 vty_frame(vty, "ipv4 unicast");
14835 else if (safi == SAFI_LABELED_UNICAST)
14836 vty_frame(vty, "ipv4 labeled-unicast");
14837 else if (safi == SAFI_MULTICAST)
14838 vty_frame(vty, "ipv4 multicast");
14839 else if (safi == SAFI_MPLS_VPN)
14840 vty_frame(vty, "ipv4 vpn");
14841 else if (safi == SAFI_ENCAP)
14842 vty_frame(vty, "ipv4 encap");
14843 else if (safi == SAFI_FLOWSPEC)
14844 vty_frame(vty, "ipv4 flowspec");
14845 } else if (afi == AFI_IP6) {
14846 if (safi == SAFI_UNICAST)
14847 vty_frame(vty, "ipv6 unicast");
14848 else if (safi == SAFI_LABELED_UNICAST)
14849 vty_frame(vty, "ipv6 labeled-unicast");
14850 else if (safi == SAFI_MULTICAST)
14851 vty_frame(vty, "ipv6 multicast");
14852 else if (safi == SAFI_MPLS_VPN)
14853 vty_frame(vty, "ipv6 vpn");
14854 else if (safi == SAFI_ENCAP)
14855 vty_frame(vty, "ipv6 encap");
14856 else if (safi == SAFI_FLOWSPEC)
14857 vty_frame(vty, "ipv6 flowspec");
14858 } else if (afi == AFI_L2VPN) {
14859 if (safi == SAFI_EVPN)
14860 vty_frame(vty, "l2vpn evpn");
14861 }
14862 vty_frame(vty, "\n");
14863
14864 bgp_config_write_distance(vty, bgp, afi, safi);
14865
14866 bgp_config_write_network(vty, bgp, afi, safi);
14867
14868 bgp_config_write_redistribute(vty, bgp, afi, safi);
14869
14870 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
14871 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
14872
14873 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14874 /* Skip dynamic neighbors. */
14875 if (peer_dynamic_neighbor(peer))
14876 continue;
14877
14878 /* Do not display doppelganger peers */
14879 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14880 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
14881 }
14882
14883 bgp_config_write_maxpaths(vty, bgp, afi, safi);
14884 bgp_config_write_table_map(vty, bgp, afi, safi);
14885
14886 if (safi == SAFI_EVPN)
14887 bgp_config_write_evpn_info(vty, bgp, afi, safi);
14888
14889 if (safi == SAFI_FLOWSPEC)
14890 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
14891
14892 if (safi == SAFI_UNICAST) {
14893 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
14894 if (CHECK_FLAG(bgp->af_flags[afi][safi],
14895 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
14896
14897 vty_out(vty, " export vpn\n");
14898 }
14899 if (CHECK_FLAG(bgp->af_flags[afi][safi],
14900 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
14901
14902 vty_out(vty, " import vpn\n");
14903 }
14904 if (CHECK_FLAG(bgp->af_flags[afi][safi],
14905 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
14906 char *name;
14907
14908 for (ALL_LIST_ELEMENTS_RO(
14909 bgp->vpn_policy[afi].import_vrf, node,
14910 name))
14911 vty_out(vty, " import vrf %s\n", name);
14912 }
14913 }
14914
14915 vty_endframe(vty, " exit-address-family\n");
14916 }
14917
14918 int bgp_config_write(struct vty *vty)
14919 {
14920 struct bgp *bgp;
14921 struct peer_group *group;
14922 struct peer *peer;
14923 struct listnode *node, *nnode;
14924 struct listnode *mnode, *mnnode;
14925
14926 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
14927 vty_out(vty, "bgp route-map delay-timer %u\n",
14928 bm->rmap_update_timer);
14929
14930 /* BGP configuration. */
14931 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
14932
14933 /* skip all auto created vrf as they dont have user config */
14934 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
14935 continue;
14936
14937 /* Router bgp ASN */
14938 vty_out(vty, "router bgp %u", bgp->as);
14939
14940 if (bgp->name)
14941 vty_out(vty, " %s %s",
14942 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
14943 ? "view" : "vrf", bgp->name);
14944 vty_out(vty, "\n");
14945
14946 /* BGP fast-external-failover. */
14947 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
14948 vty_out(vty, " no bgp fast-external-failover\n");
14949
14950 /* BGP router ID. */
14951 if (bgp->router_id_static.s_addr != 0)
14952 vty_out(vty, " bgp router-id %s\n",
14953 inet_ntoa(bgp->router_id_static));
14954
14955 /* BGP log-neighbor-changes. */
14956 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
14957 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
14958 vty_out(vty, " %sbgp log-neighbor-changes\n",
14959 CHECK_FLAG(bgp->flags,
14960 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
14961 ? ""
14962 : "no ");
14963
14964 /* BGP configuration. */
14965 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
14966 vty_out(vty, " bgp always-compare-med\n");
14967
14968 /* RFC8212 default eBGP policy. */
14969 if (bgp->ebgp_requires_policy
14970 == DEFAULT_EBGP_POLICY_ENABLED)
14971 vty_out(vty, " bgp ebgp-requires-policy\n");
14972
14973 /* draft-ietf-idr-deprecate-as-set-confed-set */
14974 if (bgp->reject_as_sets == BGP_REJECT_AS_SETS_ENABLED)
14975 vty_out(vty, " bgp reject-as-sets\n");
14976
14977 /* BGP default ipv4-unicast. */
14978 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4))
14979 vty_out(vty, " no bgp default ipv4-unicast\n");
14980
14981 /* BGP default local-preference. */
14982 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
14983 vty_out(vty, " bgp default local-preference %u\n",
14984 bgp->default_local_pref);
14985
14986 /* BGP default show-hostname */
14987 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
14988 != SAVE_BGP_SHOW_HOSTNAME)
14989 vty_out(vty, " %sbgp default show-hostname\n",
14990 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
14991 ? ""
14992 : "no ");
14993
14994 /* BGP default subgroup-pkt-queue-max. */
14995 if (bgp->default_subgroup_pkt_queue_max
14996 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
14997 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
14998 bgp->default_subgroup_pkt_queue_max);
14999
15000 /* BGP client-to-client reflection. */
15001 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
15002 vty_out(vty, " no bgp client-to-client reflection\n");
15003
15004 /* BGP cluster ID. */
15005 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
15006 vty_out(vty, " bgp cluster-id %s\n",
15007 inet_ntoa(bgp->cluster_id));
15008
15009 /* Disable ebgp connected nexthop check */
15010 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
15011 vty_out(vty,
15012 " bgp disable-ebgp-connected-route-check\n");
15013
15014 /* Confederation identifier*/
15015 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
15016 vty_out(vty, " bgp confederation identifier %u\n",
15017 bgp->confed_id);
15018
15019 /* Confederation peer */
15020 if (bgp->confed_peers_cnt > 0) {
15021 int i;
15022
15023 vty_out(vty, " bgp confederation peers");
15024
15025 for (i = 0; i < bgp->confed_peers_cnt; i++)
15026 vty_out(vty, " %u", bgp->confed_peers[i]);
15027
15028 vty_out(vty, "\n");
15029 }
15030
15031 /* BGP deterministic-med. */
15032 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
15033 != SAVE_BGP_DETERMINISTIC_MED)
15034 vty_out(vty, " %sbgp deterministic-med\n",
15035 CHECK_FLAG(bgp->flags,
15036 BGP_FLAG_DETERMINISTIC_MED)
15037 ? ""
15038 : "no ");
15039
15040 /* BGP update-delay. */
15041 bgp_config_write_update_delay(vty, bgp);
15042
15043 if (bgp->v_maxmed_onstartup
15044 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
15045 vty_out(vty, " bgp max-med on-startup %u",
15046 bgp->v_maxmed_onstartup);
15047 if (bgp->maxmed_onstartup_value
15048 != BGP_MAXMED_VALUE_DEFAULT)
15049 vty_out(vty, " %u",
15050 bgp->maxmed_onstartup_value);
15051 vty_out(vty, "\n");
15052 }
15053 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
15054 vty_out(vty, " bgp max-med administrative");
15055 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
15056 vty_out(vty, " %u", bgp->maxmed_admin_value);
15057 vty_out(vty, "\n");
15058 }
15059
15060 /* write quanta */
15061 bgp_config_write_wpkt_quanta(vty, bgp);
15062 /* read quanta */
15063 bgp_config_write_rpkt_quanta(vty, bgp);
15064
15065 /* coalesce time */
15066 bgp_config_write_coalesce_time(vty, bgp);
15067
15068 /* BGP graceful-restart. */
15069 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
15070 vty_out(vty,
15071 " bgp graceful-restart stalepath-time %u\n",
15072 bgp->stalepath_time);
15073
15074 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
15075 vty_out(vty, " bgp graceful-restart restart-time %u\n",
15076 bgp->restart_time);
15077
15078 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
15079 vty_out(vty,
15080 " bgp graceful-restart select-defer-time %u\n",
15081 bgp->select_defer_time);
15082
15083 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
15084 vty_out(vty, " bgp graceful-restart\n");
15085
15086 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
15087 vty_out(vty, " bgp graceful-restart-disable\n");
15088
15089 /* BGP graceful-shutdown */
15090 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
15091 vty_out(vty, " bgp graceful-shutdown\n");
15092
15093 /* BGP graceful-restart Preserve State F bit. */
15094 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
15095 vty_out(vty,
15096 " bgp graceful-restart preserve-fw-state\n");
15097
15098 /* Stale timer for RIB */
15099 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
15100 vty_out(vty,
15101 " bgp graceful-restart rib-stale-time %u\n",
15102 bgp->rib_stale_time);
15103
15104 /* BGP bestpath method. */
15105 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
15106 vty_out(vty, " bgp bestpath as-path ignore\n");
15107 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
15108 vty_out(vty, " bgp bestpath as-path confed\n");
15109
15110 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
15111 if (CHECK_FLAG(bgp->flags,
15112 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
15113 vty_out(vty,
15114 " bgp bestpath as-path multipath-relax as-set\n");
15115 } else {
15116 vty_out(vty,
15117 " bgp bestpath as-path multipath-relax\n");
15118 }
15119 }
15120
15121 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
15122 vty_out(vty,
15123 " bgp route-reflector allow-outbound-policy\n");
15124 }
15125 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
15126 vty_out(vty, " bgp bestpath compare-routerid\n");
15127 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
15128 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
15129 vty_out(vty, " bgp bestpath med");
15130 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
15131 vty_out(vty, " confed");
15132 if (CHECK_FLAG(bgp->flags,
15133 BGP_FLAG_MED_MISSING_AS_WORST))
15134 vty_out(vty, " missing-as-worst");
15135 vty_out(vty, "\n");
15136 }
15137
15138 /* BGP network import check. */
15139 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
15140 != SAVE_BGP_IMPORT_CHECK)
15141 vty_out(vty, " %sbgp network import-check\n",
15142 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
15143 ? ""
15144 : "no ");
15145
15146 /* BGP timers configuration. */
15147 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
15148 && bgp->default_holdtime != SAVE_BGP_HOLDTIME)
15149 vty_out(vty, " timers bgp %u %u\n",
15150 bgp->default_keepalive, bgp->default_holdtime);
15151
15152 /* peer-group */
15153 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
15154 bgp_config_write_peer_global(vty, bgp, group->conf);
15155 }
15156
15157 /* Normal neighbor configuration. */
15158 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
15159 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
15160 bgp_config_write_peer_global(vty, bgp, peer);
15161 }
15162
15163 /* listen range and limit for dynamic BGP neighbors */
15164 bgp_config_write_listen(vty, bgp);
15165
15166 /*
15167 * BGP default autoshutdown neighbors
15168 *
15169 * This must be placed after any peer and peer-group
15170 * configuration, to avoid setting all peers to shutdown after
15171 * a daemon restart, which is undesired behavior. (see #2286)
15172 */
15173 if (bgp->autoshutdown)
15174 vty_out(vty, " bgp default shutdown\n");
15175
15176 /* IPv4 unicast configuration. */
15177 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
15178
15179 /* IPv4 multicast configuration. */
15180 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
15181
15182 /* IPv4 labeled-unicast configuration. */
15183 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
15184
15185 /* IPv4 VPN configuration. */
15186 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
15187
15188 /* ENCAPv4 configuration. */
15189 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
15190
15191 /* FLOWSPEC v4 configuration. */
15192 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
15193
15194 /* IPv6 unicast configuration. */
15195 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
15196
15197 /* IPv6 multicast configuration. */
15198 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
15199
15200 /* IPv6 labeled-unicast configuration. */
15201 bgp_config_write_family(vty, bgp, AFI_IP6,
15202 SAFI_LABELED_UNICAST);
15203
15204 /* IPv6 VPN configuration. */
15205 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
15206
15207 /* ENCAPv6 configuration. */
15208 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
15209
15210 /* FLOWSPEC v6 configuration. */
15211 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
15212
15213 /* EVPN configuration. */
15214 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
15215
15216 hook_call(bgp_inst_config_write, bgp, vty);
15217
15218 #if ENABLE_BGP_VNC
15219 bgp_rfapi_cfg_write(vty, bgp);
15220 #endif
15221
15222 vty_out(vty, "!\n");
15223 }
15224 return 0;
15225 }
15226
15227
15228 /* BGP node structure. */
15229 static struct cmd_node bgp_node = {
15230 BGP_NODE, "%s(config-router)# ", 1,
15231 };
15232
15233 static struct cmd_node bgp_ipv4_unicast_node = {
15234 BGP_IPV4_NODE, "%s(config-router-af)# ", 1,
15235 };
15236
15237 static struct cmd_node bgp_ipv4_multicast_node = {
15238 BGP_IPV4M_NODE, "%s(config-router-af)# ", 1,
15239 };
15240
15241 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
15242 BGP_IPV4L_NODE, "%s(config-router-af)# ", 1,
15243 };
15244
15245 static struct cmd_node bgp_ipv6_unicast_node = {
15246 BGP_IPV6_NODE, "%s(config-router-af)# ", 1,
15247 };
15248
15249 static struct cmd_node bgp_ipv6_multicast_node = {
15250 BGP_IPV6M_NODE, "%s(config-router-af)# ", 1,
15251 };
15252
15253 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
15254 BGP_IPV6L_NODE, "%s(config-router-af)# ", 1,
15255 };
15256
15257 static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
15258 "%s(config-router-af)# ", 1};
15259
15260 static struct cmd_node bgp_vpnv6_node = {BGP_VPNV6_NODE,
15261 "%s(config-router-af-vpnv6)# ", 1};
15262
15263 static struct cmd_node bgp_evpn_node = {BGP_EVPN_NODE,
15264 "%s(config-router-evpn)# ", 1};
15265
15266 static struct cmd_node bgp_evpn_vni_node = {BGP_EVPN_VNI_NODE,
15267 "%s(config-router-af-vni)# ", 1};
15268
15269 static struct cmd_node bgp_flowspecv4_node = {BGP_FLOWSPECV4_NODE,
15270 "%s(config-router-af)# ", 1};
15271
15272 static struct cmd_node bgp_flowspecv6_node = {BGP_FLOWSPECV6_NODE,
15273 "%s(config-router-af-vpnv6)# ", 1};
15274
15275 static void community_list_vty(void);
15276
15277 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
15278 {
15279 struct bgp *bgp;
15280 struct peer *peer;
15281 struct listnode *lnbgp, *lnpeer;
15282
15283 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
15284 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
15285 /* only provide suggestions on the appropriate input
15286 * token type,
15287 * they'll otherwise show up multiple times */
15288 enum cmd_token_type match_type;
15289 char *name = peer->host;
15290
15291 if (peer->conf_if) {
15292 match_type = VARIABLE_TKN;
15293 name = peer->conf_if;
15294 } else if (strchr(peer->host, ':'))
15295 match_type = IPV6_TKN;
15296 else
15297 match_type = IPV4_TKN;
15298
15299 if (token->type != match_type)
15300 continue;
15301
15302 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
15303 }
15304 }
15305 }
15306
15307 static const struct cmd_variable_handler bgp_var_neighbor[] = {
15308 {.varname = "neighbor", .completions = bgp_ac_neighbor},
15309 {.varname = "neighbors", .completions = bgp_ac_neighbor},
15310 {.varname = "peer", .completions = bgp_ac_neighbor},
15311 {.completions = NULL}};
15312
15313 static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
15314 {
15315 struct bgp *bgp;
15316 struct peer_group *group;
15317 struct listnode *lnbgp, *lnpeer;
15318
15319 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
15320 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
15321 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
15322 group->name));
15323 }
15324 }
15325
15326 static const struct cmd_variable_handler bgp_var_peergroup[] = {
15327 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
15328 {.completions = NULL} };
15329
15330 void bgp_vty_init(void)
15331 {
15332 cmd_variable_handler_register(bgp_var_neighbor);
15333 cmd_variable_handler_register(bgp_var_peergroup);
15334
15335 /* Install bgp top node. */
15336 install_node(&bgp_node, bgp_config_write);
15337 install_node(&bgp_ipv4_unicast_node, NULL);
15338 install_node(&bgp_ipv4_multicast_node, NULL);
15339 install_node(&bgp_ipv4_labeled_unicast_node, NULL);
15340 install_node(&bgp_ipv6_unicast_node, NULL);
15341 install_node(&bgp_ipv6_multicast_node, NULL);
15342 install_node(&bgp_ipv6_labeled_unicast_node, NULL);
15343 install_node(&bgp_vpnv4_node, NULL);
15344 install_node(&bgp_vpnv6_node, NULL);
15345 install_node(&bgp_evpn_node, NULL);
15346 install_node(&bgp_evpn_vni_node, NULL);
15347 install_node(&bgp_flowspecv4_node, NULL);
15348 install_node(&bgp_flowspecv6_node, NULL);
15349
15350 /* Install default VTY commands to new nodes. */
15351 install_default(BGP_NODE);
15352 install_default(BGP_IPV4_NODE);
15353 install_default(BGP_IPV4M_NODE);
15354 install_default(BGP_IPV4L_NODE);
15355 install_default(BGP_IPV6_NODE);
15356 install_default(BGP_IPV6M_NODE);
15357 install_default(BGP_IPV6L_NODE);
15358 install_default(BGP_VPNV4_NODE);
15359 install_default(BGP_VPNV6_NODE);
15360 install_default(BGP_FLOWSPECV4_NODE);
15361 install_default(BGP_FLOWSPECV6_NODE);
15362 install_default(BGP_EVPN_NODE);
15363 install_default(BGP_EVPN_VNI_NODE);
15364
15365 /* "bgp local-mac" hidden commands. */
15366 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
15367 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
15368
15369 /* bgp route-map delay-timer commands. */
15370 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
15371 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
15372
15373 /* Dummy commands (Currently not supported) */
15374 install_element(BGP_NODE, &no_synchronization_cmd);
15375 install_element(BGP_NODE, &no_auto_summary_cmd);
15376
15377 /* "router bgp" commands. */
15378 install_element(CONFIG_NODE, &router_bgp_cmd);
15379
15380 /* "no router bgp" commands. */
15381 install_element(CONFIG_NODE, &no_router_bgp_cmd);
15382
15383 /* "bgp router-id" commands. */
15384 install_element(BGP_NODE, &bgp_router_id_cmd);
15385 install_element(BGP_NODE, &no_bgp_router_id_cmd);
15386
15387 /* "bgp cluster-id" commands. */
15388 install_element(BGP_NODE, &bgp_cluster_id_cmd);
15389 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
15390
15391 /* "bgp confederation" commands. */
15392 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
15393 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
15394
15395 /* "bgp confederation peers" commands. */
15396 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
15397 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
15398
15399 /* bgp max-med command */
15400 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
15401 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
15402 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
15403 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
15404 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
15405
15406 /* bgp disable-ebgp-connected-nh-check */
15407 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
15408 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
15409
15410 /* bgp update-delay command */
15411 install_element(BGP_NODE, &bgp_update_delay_cmd);
15412 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
15413 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
15414
15415 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
15416 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
15417
15418 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
15419 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
15420
15421 /* "maximum-paths" commands. */
15422 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
15423 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
15424 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
15425 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
15426 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
15427 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
15428 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
15429 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
15430 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
15431 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
15432 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
15433 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
15434 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
15435 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
15436 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
15437
15438 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
15439 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
15440 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
15441 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
15442 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
15443
15444 /* "timers bgp" commands. */
15445 install_element(BGP_NODE, &bgp_timers_cmd);
15446 install_element(BGP_NODE, &no_bgp_timers_cmd);
15447
15448 /* route-map delay-timer commands - per instance for backwards compat.
15449 */
15450 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
15451 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
15452
15453 /* "bgp client-to-client reflection" commands */
15454 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
15455 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
15456
15457 /* "bgp always-compare-med" commands */
15458 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
15459 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
15460
15461 /* bgp ebgp-requires-policy */
15462 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
15463 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
15464
15465 /* bgp reject-as-sets */
15466 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
15467 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
15468
15469 /* "bgp deterministic-med" commands */
15470 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
15471 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
15472
15473 /* "bgp graceful-restart" command */
15474 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
15475 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
15476
15477 /* "bgp graceful-restart-disable" command */
15478 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
15479 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
15480
15481 /* "neighbor a:b:c:d graceful-restart" command */
15482 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
15483 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
15484
15485 /* "neighbor a:b:c:d graceful-restart-disable" command */
15486 install_element(BGP_NODE,
15487 &bgp_neighbor_graceful_restart_disable_set_cmd);
15488 install_element(BGP_NODE,
15489 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
15490
15491 /* "neighbor a:b:c:d graceful-restart-helper" command */
15492 install_element(BGP_NODE,
15493 &bgp_neighbor_graceful_restart_helper_set_cmd);
15494 install_element(BGP_NODE,
15495 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
15496
15497 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
15498 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
15499 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
15500 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
15501 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
15502 install_element(BGP_NODE,
15503 &no_bgp_graceful_restart_select_defer_time_cmd);
15504 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
15505 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
15506
15507 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
15508 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
15509 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
15510 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
15511
15512 /* "bgp graceful-shutdown" commands */
15513 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
15514 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
15515
15516 /* "bgp fast-external-failover" commands */
15517 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
15518 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
15519
15520 /* "bgp bestpath compare-routerid" commands */
15521 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
15522 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
15523
15524 /* "bgp bestpath as-path ignore" commands */
15525 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
15526 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
15527
15528 /* "bgp bestpath as-path confed" commands */
15529 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
15530 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
15531
15532 /* "bgp bestpath as-path multipath-relax" commands */
15533 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
15534 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
15535
15536 /* "bgp log-neighbor-changes" commands */
15537 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
15538 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
15539
15540 /* "bgp bestpath med" commands */
15541 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
15542 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
15543
15544 /* "no bgp default ipv4-unicast" commands. */
15545 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
15546 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
15547
15548 /* "bgp network import-check" commands. */
15549 install_element(BGP_NODE, &bgp_network_import_check_cmd);
15550 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
15551 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
15552
15553 /* "bgp default local-preference" commands. */
15554 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
15555 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
15556
15557 /* bgp default show-hostname */
15558 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
15559 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
15560
15561 /* "bgp default subgroup-pkt-queue-max" commands. */
15562 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
15563 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
15564
15565 /* bgp ibgp-allow-policy-mods command */
15566 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
15567 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
15568
15569 /* "bgp listen limit" commands. */
15570 install_element(BGP_NODE, &bgp_listen_limit_cmd);
15571 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
15572
15573 /* "bgp listen range" commands. */
15574 install_element(BGP_NODE, &bgp_listen_range_cmd);
15575 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
15576
15577 /* "bgp default shutdown" command */
15578 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
15579
15580 /* "neighbor remote-as" commands. */
15581 install_element(BGP_NODE, &neighbor_remote_as_cmd);
15582 install_element(BGP_NODE, &neighbor_interface_config_cmd);
15583 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
15584 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
15585 install_element(BGP_NODE,
15586 &neighbor_interface_v6only_config_remote_as_cmd);
15587 install_element(BGP_NODE, &no_neighbor_cmd);
15588 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
15589
15590 /* "neighbor peer-group" commands. */
15591 install_element(BGP_NODE, &neighbor_peer_group_cmd);
15592 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
15593 install_element(BGP_NODE,
15594 &no_neighbor_interface_peer_group_remote_as_cmd);
15595
15596 /* "neighbor local-as" commands. */
15597 install_element(BGP_NODE, &neighbor_local_as_cmd);
15598 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
15599 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
15600 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
15601
15602 /* "neighbor solo" commands. */
15603 install_element(BGP_NODE, &neighbor_solo_cmd);
15604 install_element(BGP_NODE, &no_neighbor_solo_cmd);
15605
15606 /* "neighbor password" commands. */
15607 install_element(BGP_NODE, &neighbor_password_cmd);
15608 install_element(BGP_NODE, &no_neighbor_password_cmd);
15609
15610 /* "neighbor activate" commands. */
15611 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
15612 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
15613 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
15614 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
15615 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
15616 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
15617 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
15618 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
15619 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
15620 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
15621 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
15622 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
15623
15624 /* "no neighbor activate" commands. */
15625 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
15626 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
15627 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
15628 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
15629 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
15630 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
15631 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
15632 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
15633 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
15634 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
15635 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
15636 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
15637
15638 /* "neighbor peer-group" set commands. */
15639 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
15640 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
15641 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
15642 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
15643 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
15644 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
15645 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
15646 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
15647 install_element(BGP_FLOWSPECV4_NODE,
15648 &neighbor_set_peer_group_hidden_cmd);
15649 install_element(BGP_FLOWSPECV6_NODE,
15650 &neighbor_set_peer_group_hidden_cmd);
15651
15652 /* "no neighbor peer-group unset" commands. */
15653 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
15654 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
15655 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
15656 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
15657 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
15658 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
15659 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
15660 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
15661 install_element(BGP_FLOWSPECV4_NODE,
15662 &no_neighbor_set_peer_group_hidden_cmd);
15663 install_element(BGP_FLOWSPECV6_NODE,
15664 &no_neighbor_set_peer_group_hidden_cmd);
15665
15666 /* "neighbor softreconfiguration inbound" commands.*/
15667 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
15668 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
15669 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
15670 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
15671 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
15672 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
15673 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
15674 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
15675 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
15676 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
15677 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
15678 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
15679 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
15680 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
15681 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
15682 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
15683 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
15684 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
15685 install_element(BGP_FLOWSPECV4_NODE,
15686 &neighbor_soft_reconfiguration_cmd);
15687 install_element(BGP_FLOWSPECV4_NODE,
15688 &no_neighbor_soft_reconfiguration_cmd);
15689 install_element(BGP_FLOWSPECV6_NODE,
15690 &neighbor_soft_reconfiguration_cmd);
15691 install_element(BGP_FLOWSPECV6_NODE,
15692 &no_neighbor_soft_reconfiguration_cmd);
15693 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
15694 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
15695
15696 /* "neighbor attribute-unchanged" commands. */
15697 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
15698 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
15699 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
15700 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
15701 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
15702 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
15703 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
15704 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
15705 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
15706 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
15707 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
15708 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
15709 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
15710 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
15711 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
15712 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
15713 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
15714 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
15715
15716 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
15717 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
15718
15719 /* "nexthop-local unchanged" commands */
15720 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
15721 install_element(BGP_IPV6_NODE,
15722 &no_neighbor_nexthop_local_unchanged_cmd);
15723
15724 /* "neighbor next-hop-self" commands. */
15725 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
15726 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
15727 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
15728 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
15729 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
15730 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
15731 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
15732 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
15733 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
15734 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
15735 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
15736 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
15737 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
15738 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
15739 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
15740 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
15741 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
15742 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
15743 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
15744 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
15745
15746 /* "neighbor next-hop-self force" commands. */
15747 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
15748 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
15749 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
15750 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
15751 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
15752 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
15753 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
15754 install_element(BGP_IPV4_NODE,
15755 &no_neighbor_nexthop_self_all_hidden_cmd);
15756 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
15757 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
15758 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
15759 install_element(BGP_IPV4M_NODE,
15760 &no_neighbor_nexthop_self_all_hidden_cmd);
15761 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
15762 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
15763 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
15764 install_element(BGP_IPV4L_NODE,
15765 &no_neighbor_nexthop_self_all_hidden_cmd);
15766 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
15767 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
15768 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
15769 install_element(BGP_IPV6_NODE,
15770 &no_neighbor_nexthop_self_all_hidden_cmd);
15771 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
15772 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
15773 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
15774 install_element(BGP_IPV6M_NODE,
15775 &no_neighbor_nexthop_self_all_hidden_cmd);
15776 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
15777 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
15778 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
15779 install_element(BGP_IPV6L_NODE,
15780 &no_neighbor_nexthop_self_all_hidden_cmd);
15781 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
15782 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
15783 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
15784 install_element(BGP_VPNV4_NODE,
15785 &no_neighbor_nexthop_self_all_hidden_cmd);
15786 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
15787 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
15788 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
15789 install_element(BGP_VPNV6_NODE,
15790 &no_neighbor_nexthop_self_all_hidden_cmd);
15791
15792 /* "neighbor as-override" commands. */
15793 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
15794 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
15795 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
15796 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
15797 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
15798 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
15799 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
15800 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
15801 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
15802 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
15803 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
15804 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
15805 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
15806 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
15807 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
15808 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
15809 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
15810 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
15811
15812 /* "neighbor remove-private-AS" commands. */
15813 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
15814 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
15815 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
15816 install_element(BGP_NODE,
15817 &no_neighbor_remove_private_as_all_hidden_cmd);
15818 install_element(BGP_NODE,
15819 &neighbor_remove_private_as_replace_as_hidden_cmd);
15820 install_element(BGP_NODE,
15821 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
15822 install_element(BGP_NODE,
15823 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
15824 install_element(
15825 BGP_NODE,
15826 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
15827 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
15828 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
15829 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
15830 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
15831 install_element(BGP_IPV4_NODE,
15832 &neighbor_remove_private_as_replace_as_cmd);
15833 install_element(BGP_IPV4_NODE,
15834 &no_neighbor_remove_private_as_replace_as_cmd);
15835 install_element(BGP_IPV4_NODE,
15836 &neighbor_remove_private_as_all_replace_as_cmd);
15837 install_element(BGP_IPV4_NODE,
15838 &no_neighbor_remove_private_as_all_replace_as_cmd);
15839 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
15840 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
15841 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
15842 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
15843 install_element(BGP_IPV4M_NODE,
15844 &neighbor_remove_private_as_replace_as_cmd);
15845 install_element(BGP_IPV4M_NODE,
15846 &no_neighbor_remove_private_as_replace_as_cmd);
15847 install_element(BGP_IPV4M_NODE,
15848 &neighbor_remove_private_as_all_replace_as_cmd);
15849 install_element(BGP_IPV4M_NODE,
15850 &no_neighbor_remove_private_as_all_replace_as_cmd);
15851 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
15852 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
15853 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
15854 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
15855 install_element(BGP_IPV4L_NODE,
15856 &neighbor_remove_private_as_replace_as_cmd);
15857 install_element(BGP_IPV4L_NODE,
15858 &no_neighbor_remove_private_as_replace_as_cmd);
15859 install_element(BGP_IPV4L_NODE,
15860 &neighbor_remove_private_as_all_replace_as_cmd);
15861 install_element(BGP_IPV4L_NODE,
15862 &no_neighbor_remove_private_as_all_replace_as_cmd);
15863 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
15864 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
15865 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
15866 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
15867 install_element(BGP_IPV6_NODE,
15868 &neighbor_remove_private_as_replace_as_cmd);
15869 install_element(BGP_IPV6_NODE,
15870 &no_neighbor_remove_private_as_replace_as_cmd);
15871 install_element(BGP_IPV6_NODE,
15872 &neighbor_remove_private_as_all_replace_as_cmd);
15873 install_element(BGP_IPV6_NODE,
15874 &no_neighbor_remove_private_as_all_replace_as_cmd);
15875 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
15876 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
15877 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
15878 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
15879 install_element(BGP_IPV6M_NODE,
15880 &neighbor_remove_private_as_replace_as_cmd);
15881 install_element(BGP_IPV6M_NODE,
15882 &no_neighbor_remove_private_as_replace_as_cmd);
15883 install_element(BGP_IPV6M_NODE,
15884 &neighbor_remove_private_as_all_replace_as_cmd);
15885 install_element(BGP_IPV6M_NODE,
15886 &no_neighbor_remove_private_as_all_replace_as_cmd);
15887 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
15888 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
15889 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
15890 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
15891 install_element(BGP_IPV6L_NODE,
15892 &neighbor_remove_private_as_replace_as_cmd);
15893 install_element(BGP_IPV6L_NODE,
15894 &no_neighbor_remove_private_as_replace_as_cmd);
15895 install_element(BGP_IPV6L_NODE,
15896 &neighbor_remove_private_as_all_replace_as_cmd);
15897 install_element(BGP_IPV6L_NODE,
15898 &no_neighbor_remove_private_as_all_replace_as_cmd);
15899 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
15900 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
15901 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
15902 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
15903 install_element(BGP_VPNV4_NODE,
15904 &neighbor_remove_private_as_replace_as_cmd);
15905 install_element(BGP_VPNV4_NODE,
15906 &no_neighbor_remove_private_as_replace_as_cmd);
15907 install_element(BGP_VPNV4_NODE,
15908 &neighbor_remove_private_as_all_replace_as_cmd);
15909 install_element(BGP_VPNV4_NODE,
15910 &no_neighbor_remove_private_as_all_replace_as_cmd);
15911 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
15912 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
15913 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
15914 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
15915 install_element(BGP_VPNV6_NODE,
15916 &neighbor_remove_private_as_replace_as_cmd);
15917 install_element(BGP_VPNV6_NODE,
15918 &no_neighbor_remove_private_as_replace_as_cmd);
15919 install_element(BGP_VPNV6_NODE,
15920 &neighbor_remove_private_as_all_replace_as_cmd);
15921 install_element(BGP_VPNV6_NODE,
15922 &no_neighbor_remove_private_as_all_replace_as_cmd);
15923
15924 /* "neighbor send-community" commands.*/
15925 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
15926 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
15927 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
15928 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
15929 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
15930 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
15931 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
15932 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
15933 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
15934 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
15935 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
15936 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
15937 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
15938 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
15939 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
15940 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
15941 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
15942 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
15943 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
15944 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
15945 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
15946 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
15947 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
15948 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
15949 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
15950 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
15951 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
15952 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
15953 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
15954 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
15955 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
15956 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
15957 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
15958 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
15959 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
15960 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
15961
15962 /* "neighbor route-reflector" commands.*/
15963 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
15964 install_element(BGP_NODE,
15965 &no_neighbor_route_reflector_client_hidden_cmd);
15966 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
15967 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
15968 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
15969 install_element(BGP_IPV4M_NODE,
15970 &no_neighbor_route_reflector_client_cmd);
15971 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
15972 install_element(BGP_IPV4L_NODE,
15973 &no_neighbor_route_reflector_client_cmd);
15974 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
15975 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
15976 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
15977 install_element(BGP_IPV6M_NODE,
15978 &no_neighbor_route_reflector_client_cmd);
15979 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
15980 install_element(BGP_IPV6L_NODE,
15981 &no_neighbor_route_reflector_client_cmd);
15982 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
15983 install_element(BGP_VPNV4_NODE,
15984 &no_neighbor_route_reflector_client_cmd);
15985 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
15986 install_element(BGP_VPNV6_NODE,
15987 &no_neighbor_route_reflector_client_cmd);
15988 install_element(BGP_FLOWSPECV4_NODE,
15989 &neighbor_route_reflector_client_cmd);
15990 install_element(BGP_FLOWSPECV4_NODE,
15991 &no_neighbor_route_reflector_client_cmd);
15992 install_element(BGP_FLOWSPECV6_NODE,
15993 &neighbor_route_reflector_client_cmd);
15994 install_element(BGP_FLOWSPECV6_NODE,
15995 &no_neighbor_route_reflector_client_cmd);
15996 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
15997 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
15998
15999 /* "neighbor route-server" commands.*/
16000 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
16001 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
16002 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
16003 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
16004 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
16005 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
16006 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
16007 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
16008 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
16009 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
16010 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
16011 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
16012 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
16013 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
16014 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
16015 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
16016 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
16017 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
16018 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
16019 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
16020 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
16021 install_element(BGP_FLOWSPECV4_NODE,
16022 &no_neighbor_route_server_client_cmd);
16023 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
16024 install_element(BGP_FLOWSPECV6_NODE,
16025 &no_neighbor_route_server_client_cmd);
16026
16027 /* "neighbor addpath-tx-all-paths" commands.*/
16028 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
16029 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
16030 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
16031 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16032 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
16033 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16034 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
16035 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16036 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
16037 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16038 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
16039 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16040 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
16041 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16042 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
16043 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16044 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
16045 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16046
16047 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
16048 install_element(BGP_NODE,
16049 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
16050 install_element(BGP_NODE,
16051 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
16052 install_element(BGP_IPV4_NODE,
16053 &neighbor_addpath_tx_bestpath_per_as_cmd);
16054 install_element(BGP_IPV4_NODE,
16055 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16056 install_element(BGP_IPV4M_NODE,
16057 &neighbor_addpath_tx_bestpath_per_as_cmd);
16058 install_element(BGP_IPV4M_NODE,
16059 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16060 install_element(BGP_IPV4L_NODE,
16061 &neighbor_addpath_tx_bestpath_per_as_cmd);
16062 install_element(BGP_IPV4L_NODE,
16063 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16064 install_element(BGP_IPV6_NODE,
16065 &neighbor_addpath_tx_bestpath_per_as_cmd);
16066 install_element(BGP_IPV6_NODE,
16067 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16068 install_element(BGP_IPV6M_NODE,
16069 &neighbor_addpath_tx_bestpath_per_as_cmd);
16070 install_element(BGP_IPV6M_NODE,
16071 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16072 install_element(BGP_IPV6L_NODE,
16073 &neighbor_addpath_tx_bestpath_per_as_cmd);
16074 install_element(BGP_IPV6L_NODE,
16075 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16076 install_element(BGP_VPNV4_NODE,
16077 &neighbor_addpath_tx_bestpath_per_as_cmd);
16078 install_element(BGP_VPNV4_NODE,
16079 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16080 install_element(BGP_VPNV6_NODE,
16081 &neighbor_addpath_tx_bestpath_per_as_cmd);
16082 install_element(BGP_VPNV6_NODE,
16083 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16084
16085 /* "neighbor sender-as-path-loop-detection" commands. */
16086 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
16087 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
16088
16089 /* "neighbor passive" commands. */
16090 install_element(BGP_NODE, &neighbor_passive_cmd);
16091 install_element(BGP_NODE, &no_neighbor_passive_cmd);
16092
16093
16094 /* "neighbor shutdown" commands. */
16095 install_element(BGP_NODE, &neighbor_shutdown_cmd);
16096 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
16097 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
16098 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
16099
16100 /* "neighbor capability extended-nexthop" commands.*/
16101 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
16102 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
16103
16104 /* "neighbor capability orf prefix-list" commands.*/
16105 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
16106 install_element(BGP_NODE,
16107 &no_neighbor_capability_orf_prefix_hidden_cmd);
16108 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
16109 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
16110 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
16111 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
16112 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
16113 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
16114 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
16115 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
16116 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
16117 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
16118 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
16119 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
16120
16121 /* "neighbor capability dynamic" commands.*/
16122 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
16123 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
16124
16125 /* "neighbor dont-capability-negotiate" commands. */
16126 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
16127 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
16128
16129 /* "neighbor ebgp-multihop" commands. */
16130 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
16131 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
16132 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
16133
16134 /* "neighbor disable-connected-check" commands. */
16135 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
16136 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
16137
16138 /* "neighbor enforce-first-as" commands. */
16139 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
16140 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
16141
16142 /* "neighbor description" commands. */
16143 install_element(BGP_NODE, &neighbor_description_cmd);
16144 install_element(BGP_NODE, &no_neighbor_description_cmd);
16145 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
16146
16147 /* "neighbor update-source" commands. "*/
16148 install_element(BGP_NODE, &neighbor_update_source_cmd);
16149 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
16150
16151 /* "neighbor default-originate" commands. */
16152 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
16153 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
16154 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
16155 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
16156 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
16157 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
16158 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
16159 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
16160 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
16161 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
16162 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
16163 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
16164 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
16165 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
16166 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
16167 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
16168 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
16169 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
16170 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
16171 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
16172 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
16173
16174 /* "neighbor port" commands. */
16175 install_element(BGP_NODE, &neighbor_port_cmd);
16176 install_element(BGP_NODE, &no_neighbor_port_cmd);
16177
16178 /* "neighbor weight" commands. */
16179 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
16180 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
16181
16182 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
16183 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
16184 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
16185 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
16186 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
16187 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
16188 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
16189 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
16190 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
16191 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
16192 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
16193 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
16194 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
16195 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
16196 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
16197 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
16198
16199 /* "neighbor override-capability" commands. */
16200 install_element(BGP_NODE, &neighbor_override_capability_cmd);
16201 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
16202
16203 /* "neighbor strict-capability-match" commands. */
16204 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
16205 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
16206
16207 /* "neighbor timers" commands. */
16208 install_element(BGP_NODE, &neighbor_timers_cmd);
16209 install_element(BGP_NODE, &no_neighbor_timers_cmd);
16210
16211 /* "neighbor timers connect" commands. */
16212 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
16213 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
16214
16215 /* "neighbor advertisement-interval" commands. */
16216 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
16217 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
16218
16219 /* "neighbor interface" commands. */
16220 install_element(BGP_NODE, &neighbor_interface_cmd);
16221 install_element(BGP_NODE, &no_neighbor_interface_cmd);
16222
16223 /* "neighbor distribute" commands. */
16224 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
16225 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
16226 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
16227 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
16228 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
16229 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
16230 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
16231 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
16232 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
16233 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
16234 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
16235 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
16236 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
16237 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
16238 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
16239 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
16240 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
16241 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
16242
16243 /* "neighbor prefix-list" commands. */
16244 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
16245 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
16246 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
16247 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
16248 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
16249 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
16250 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
16251 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
16252 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
16253 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
16254 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
16255 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
16256 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
16257 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
16258 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
16259 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
16260 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
16261 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
16262 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
16263 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
16264 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
16265 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
16266
16267 /* "neighbor filter-list" commands. */
16268 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
16269 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
16270 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
16271 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
16272 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
16273 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
16274 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
16275 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
16276 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
16277 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
16278 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
16279 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
16280 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
16281 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
16282 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
16283 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
16284 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
16285 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
16286 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
16287 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
16288 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
16289 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
16290
16291 /* "neighbor route-map" commands. */
16292 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
16293 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
16294 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
16295 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
16296 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
16297 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
16298 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
16299 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
16300 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
16301 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
16302 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
16303 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
16304 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
16305 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
16306 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
16307 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
16308 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
16309 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
16310 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
16311 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
16312 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
16313 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
16314 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
16315 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
16316
16317 /* "neighbor unsuppress-map" commands. */
16318 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
16319 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
16320 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
16321 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
16322 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
16323 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
16324 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
16325 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
16326 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
16327 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
16328 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
16329 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
16330 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
16331 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
16332 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
16333 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
16334 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
16335 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
16336
16337 /* neighbor maximum-prefix-out commands. */
16338 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
16339 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
16340 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
16341 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
16342 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
16343 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
16344 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
16345 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
16346 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
16347 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
16348 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
16349 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
16350 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
16351 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
16352 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
16353 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
16354 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
16355 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
16356
16357 /* "neighbor maximum-prefix" commands. */
16358 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
16359 install_element(BGP_NODE,
16360 &neighbor_maximum_prefix_threshold_hidden_cmd);
16361 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
16362 install_element(BGP_NODE,
16363 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
16364 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
16365 install_element(BGP_NODE,
16366 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
16367 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
16368 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
16369 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
16370 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
16371 install_element(BGP_IPV4_NODE,
16372 &neighbor_maximum_prefix_threshold_warning_cmd);
16373 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
16374 install_element(BGP_IPV4_NODE,
16375 &neighbor_maximum_prefix_threshold_restart_cmd);
16376 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
16377 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
16378 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
16379 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
16380 install_element(BGP_IPV4M_NODE,
16381 &neighbor_maximum_prefix_threshold_warning_cmd);
16382 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
16383 install_element(BGP_IPV4M_NODE,
16384 &neighbor_maximum_prefix_threshold_restart_cmd);
16385 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
16386 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
16387 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
16388 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
16389 install_element(BGP_IPV4L_NODE,
16390 &neighbor_maximum_prefix_threshold_warning_cmd);
16391 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
16392 install_element(BGP_IPV4L_NODE,
16393 &neighbor_maximum_prefix_threshold_restart_cmd);
16394 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
16395 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
16396 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
16397 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
16398 install_element(BGP_IPV6_NODE,
16399 &neighbor_maximum_prefix_threshold_warning_cmd);
16400 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
16401 install_element(BGP_IPV6_NODE,
16402 &neighbor_maximum_prefix_threshold_restart_cmd);
16403 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
16404 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
16405 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
16406 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
16407 install_element(BGP_IPV6M_NODE,
16408 &neighbor_maximum_prefix_threshold_warning_cmd);
16409 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
16410 install_element(BGP_IPV6M_NODE,
16411 &neighbor_maximum_prefix_threshold_restart_cmd);
16412 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
16413 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
16414 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
16415 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
16416 install_element(BGP_IPV6L_NODE,
16417 &neighbor_maximum_prefix_threshold_warning_cmd);
16418 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
16419 install_element(BGP_IPV6L_NODE,
16420 &neighbor_maximum_prefix_threshold_restart_cmd);
16421 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
16422 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
16423 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
16424 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
16425 install_element(BGP_VPNV4_NODE,
16426 &neighbor_maximum_prefix_threshold_warning_cmd);
16427 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
16428 install_element(BGP_VPNV4_NODE,
16429 &neighbor_maximum_prefix_threshold_restart_cmd);
16430 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
16431 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
16432 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
16433 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
16434 install_element(BGP_VPNV6_NODE,
16435 &neighbor_maximum_prefix_threshold_warning_cmd);
16436 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
16437 install_element(BGP_VPNV6_NODE,
16438 &neighbor_maximum_prefix_threshold_restart_cmd);
16439 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
16440
16441 /* "neighbor allowas-in" */
16442 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
16443 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
16444 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
16445 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
16446 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
16447 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
16448 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
16449 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
16450 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
16451 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
16452 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
16453 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
16454 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
16455 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
16456 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
16457 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
16458 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
16459 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
16460 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
16461 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
16462
16463 /* address-family commands. */
16464 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
16465 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
16466 #ifdef KEEP_OLD_VPN_COMMANDS
16467 install_element(BGP_NODE, &address_family_vpnv4_cmd);
16468 install_element(BGP_NODE, &address_family_vpnv6_cmd);
16469 #endif /* KEEP_OLD_VPN_COMMANDS */
16470
16471 install_element(BGP_NODE, &address_family_evpn_cmd);
16472
16473 /* "exit-address-family" command. */
16474 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
16475 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
16476 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
16477 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
16478 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
16479 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
16480 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
16481 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
16482 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
16483 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
16484 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
16485
16486 /* "clear ip bgp commands" */
16487 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
16488
16489 /* clear ip bgp prefix */
16490 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
16491 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
16492 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
16493
16494 /* "show [ip] bgp summary" commands. */
16495 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
16496 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
16497 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
16498 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
16499 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
16500 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
16501 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
16502
16503 /* "show [ip] bgp neighbors" commands. */
16504 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
16505
16506 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
16507
16508 /* "show [ip] bgp peer-group" commands. */
16509 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
16510
16511 /* "show [ip] bgp paths" commands. */
16512 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
16513
16514 /* "show [ip] bgp community" commands. */
16515 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
16516
16517 /* "show ip bgp large-community" commands. */
16518 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
16519 /* "show [ip] bgp attribute-info" commands. */
16520 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
16521 /* "show [ip] bgp route-leak" command */
16522 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
16523
16524 /* "redistribute" commands. */
16525 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
16526 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
16527 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
16528 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
16529 install_element(BGP_NODE,
16530 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
16531 install_element(BGP_NODE,
16532 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
16533 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
16534 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
16535 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
16536 install_element(BGP_NODE,
16537 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
16538 install_element(BGP_NODE,
16539 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
16540 install_element(BGP_NODE,
16541 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
16542 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
16543 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
16544 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
16545 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
16546 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
16547 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
16548 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
16549 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
16550 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
16551 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
16552 install_element(BGP_IPV4_NODE,
16553 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
16554 install_element(BGP_IPV4_NODE,
16555 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
16556 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
16557 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
16558 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
16559 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
16560 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
16561 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
16562
16563 /* import|export vpn [route-map WORD] */
16564 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
16565 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
16566
16567 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
16568 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
16569
16570 /* ttl_security commands */
16571 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
16572 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
16573
16574 /* "show [ip] bgp memory" commands. */
16575 install_element(VIEW_NODE, &show_bgp_memory_cmd);
16576
16577 /* "show bgp martian next-hop" */
16578 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
16579
16580 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
16581
16582 /* "show [ip] bgp views" commands. */
16583 install_element(VIEW_NODE, &show_bgp_views_cmd);
16584
16585 /* "show [ip] bgp vrfs" commands. */
16586 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
16587
16588 /* Community-list. */
16589 community_list_vty();
16590
16591 /* vpn-policy commands */
16592 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
16593 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
16594 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
16595 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
16596 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
16597 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
16598 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
16599 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
16600 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
16601 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
16602 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
16603 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
16604
16605 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
16606 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
16607
16608 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
16609 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
16610 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
16611 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
16612 install_element(BGP_IPV4_NODE, &af_no_nexthop_vpn_export_cmd);
16613 install_element(BGP_IPV6_NODE, &af_no_nexthop_vpn_export_cmd);
16614 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
16615 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
16616 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
16617 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
16618 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
16619 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
16620 }
16621
16622 #include "memory.h"
16623 #include "bgp_regex.h"
16624 #include "bgp_clist.h"
16625 #include "bgp_ecommunity.h"
16626
16627 /* VTY functions. */
16628
16629 /* Direction value to string conversion. */
16630 static const char *community_direct_str(int direct)
16631 {
16632 switch (direct) {
16633 case COMMUNITY_DENY:
16634 return "deny";
16635 case COMMUNITY_PERMIT:
16636 return "permit";
16637 default:
16638 return "unknown";
16639 }
16640 }
16641
16642 /* Display error string. */
16643 static void community_list_perror(struct vty *vty, int ret)
16644 {
16645 switch (ret) {
16646 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
16647 vty_out(vty, "%% Can't find community-list\n");
16648 break;
16649 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
16650 vty_out(vty, "%% Malformed community-list value\n");
16651 break;
16652 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
16653 vty_out(vty,
16654 "%% Community name conflict, previously defined as standard community\n");
16655 break;
16656 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
16657 vty_out(vty,
16658 "%% Community name conflict, previously defined as expanded community\n");
16659 break;
16660 }
16661 }
16662
16663 /* "community-list" keyword help string. */
16664 #define COMMUNITY_LIST_STR "Add a community list entry\n"
16665
16666 /*community-list standard */
16667 DEFUN (community_list_standard,
16668 bgp_community_list_standard_cmd,
16669 "bgp community-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
16670 BGP_STR
16671 COMMUNITY_LIST_STR
16672 "Community list number (standard)\n"
16673 "Add an standard community-list entry\n"
16674 "Community list name\n"
16675 "Sequence number of an entry\n"
16676 "Sequence number\n"
16677 "Specify community to reject\n"
16678 "Specify community to accept\n"
16679 COMMUNITY_VAL_STR)
16680 {
16681 char *cl_name_or_number = NULL;
16682 char *seq = NULL;
16683 int direct = 0;
16684 int style = COMMUNITY_LIST_STANDARD;
16685 int idx = 0;
16686
16687 argv_find(argv, argc, "(1-4294967295)", &idx);
16688 if (idx)
16689 seq = argv[idx]->arg;
16690
16691 idx = 0;
16692 argv_find(argv, argc, "(1-99)", &idx);
16693 argv_find(argv, argc, "WORD", &idx);
16694 cl_name_or_number = argv[idx]->arg;
16695 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
16696 : COMMUNITY_DENY;
16697 argv_find(argv, argc, "AA:NN", &idx);
16698 char *str = argv_concat(argv, argc, idx);
16699
16700 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
16701 direct, style);
16702
16703 XFREE(MTYPE_TMP, str);
16704
16705 if (ret < 0) {
16706 /* Display error string. */
16707 community_list_perror(vty, ret);
16708 return CMD_WARNING_CONFIG_FAILED;
16709 }
16710
16711 return CMD_SUCCESS;
16712 }
16713
16714 DEFUN (no_community_list_standard_all,
16715 no_bgp_community_list_standard_all_cmd,
16716 "no bgp community-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
16717 NO_STR
16718 BGP_STR
16719 COMMUNITY_LIST_STR
16720 "Community list number (standard)\n"
16721 "Add an standard community-list entry\n"
16722 "Community list name\n"
16723 "Sequence number of an entry\n"
16724 "Sequence number\n"
16725 "Specify community to reject\n"
16726 "Specify community to accept\n"
16727 COMMUNITY_VAL_STR)
16728 {
16729 char *cl_name_or_number = NULL;
16730 char *str = NULL;
16731 int direct = 0;
16732 int style = COMMUNITY_LIST_STANDARD;
16733 char *seq = NULL;
16734 int idx = 0;
16735
16736 argv_find(argv, argc, "(1-4294967295)", &idx);
16737 if (idx)
16738 seq = argv[idx]->arg;
16739
16740 idx = 0;
16741 argv_find(argv, argc, "permit", &idx);
16742 argv_find(argv, argc, "deny", &idx);
16743
16744 if (idx) {
16745 direct = argv_find(argv, argc, "permit", &idx)
16746 ? COMMUNITY_PERMIT
16747 : COMMUNITY_DENY;
16748
16749 idx = 0;
16750 argv_find(argv, argc, "AA:NN", &idx);
16751 str = argv_concat(argv, argc, idx);
16752 }
16753
16754 idx = 0;
16755 argv_find(argv, argc, "(1-99)", &idx);
16756 argv_find(argv, argc, "WORD", &idx);
16757 cl_name_or_number = argv[idx]->arg;
16758
16759 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
16760 direct, style);
16761
16762 XFREE(MTYPE_TMP, str);
16763
16764 if (ret < 0) {
16765 community_list_perror(vty, ret);
16766 return CMD_WARNING_CONFIG_FAILED;
16767 }
16768
16769 return CMD_SUCCESS;
16770 }
16771
16772 ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
16773 "no bgp community-list <(1-99)|standard WORD>",
16774 NO_STR BGP_STR COMMUNITY_LIST_STR
16775 "Community list number (standard)\n"
16776 "Add an standard community-list entry\n"
16777 "Community list name\n")
16778
16779 /*community-list expanded */
16780 DEFUN (community_list_expanded_all,
16781 bgp_community_list_expanded_all_cmd,
16782 "bgp community-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
16783 BGP_STR
16784 COMMUNITY_LIST_STR
16785 "Community list number (expanded)\n"
16786 "Add an expanded community-list entry\n"
16787 "Community list name\n"
16788 "Sequence number of an entry\n"
16789 "Sequence number\n"
16790 "Specify community to reject\n"
16791 "Specify community to accept\n"
16792 COMMUNITY_VAL_STR)
16793 {
16794 char *cl_name_or_number = NULL;
16795 char *seq = NULL;
16796 int direct = 0;
16797 int style = COMMUNITY_LIST_EXPANDED;
16798 int idx = 0;
16799
16800 argv_find(argv, argc, "(1-4294967295)", &idx);
16801 if (idx)
16802 seq = argv[idx]->arg;
16803
16804 idx = 0;
16805
16806 argv_find(argv, argc, "(100-500)", &idx);
16807 argv_find(argv, argc, "WORD", &idx);
16808 cl_name_or_number = argv[idx]->arg;
16809 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
16810 : COMMUNITY_DENY;
16811 argv_find(argv, argc, "AA:NN", &idx);
16812 char *str = argv_concat(argv, argc, idx);
16813
16814 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
16815 direct, style);
16816
16817 XFREE(MTYPE_TMP, str);
16818
16819 if (ret < 0) {
16820 /* Display error string. */
16821 community_list_perror(vty, ret);
16822 return CMD_WARNING_CONFIG_FAILED;
16823 }
16824
16825 return CMD_SUCCESS;
16826 }
16827
16828 DEFUN (no_community_list_expanded_all,
16829 no_bgp_community_list_expanded_all_cmd,
16830 "no bgp community-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
16831 NO_STR
16832 BGP_STR
16833 COMMUNITY_LIST_STR
16834 "Community list number (expanded)\n"
16835 "Add an expanded community-list entry\n"
16836 "Community list name\n"
16837 "Sequence number of an entry\n"
16838 "Sequence number\n"
16839 "Specify community to reject\n"
16840 "Specify community to accept\n"
16841 COMMUNITY_VAL_STR)
16842 {
16843 char *cl_name_or_number = NULL;
16844 char *seq = NULL;
16845 char *str = NULL;
16846 int direct = 0;
16847 int style = COMMUNITY_LIST_EXPANDED;
16848 int idx = 0;
16849
16850 argv_find(argv, argc, "(1-4294967295)", &idx);
16851 if (idx)
16852 seq = argv[idx]->arg;
16853
16854 idx = 0;
16855 argv_find(argv, argc, "permit", &idx);
16856 argv_find(argv, argc, "deny", &idx);
16857
16858 if (idx) {
16859 direct = argv_find(argv, argc, "permit", &idx)
16860 ? COMMUNITY_PERMIT
16861 : COMMUNITY_DENY;
16862
16863 idx = 0;
16864 argv_find(argv, argc, "AA:NN", &idx);
16865 str = argv_concat(argv, argc, idx);
16866 }
16867
16868 idx = 0;
16869 argv_find(argv, argc, "(100-500)", &idx);
16870 argv_find(argv, argc, "WORD", &idx);
16871 cl_name_or_number = argv[idx]->arg;
16872
16873 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
16874 direct, style);
16875
16876 XFREE(MTYPE_TMP, str);
16877
16878 if (ret < 0) {
16879 community_list_perror(vty, ret);
16880 return CMD_WARNING_CONFIG_FAILED;
16881 }
16882
16883 return CMD_SUCCESS;
16884 }
16885
16886 ALIAS(no_community_list_expanded_all, no_bgp_community_list_expanded_all_list_cmd,
16887 "no bgp community-list <(100-500)|expanded WORD>",
16888 NO_STR IP_STR COMMUNITY_LIST_STR
16889 "Community list number (expanded)\n"
16890 "Add an expanded community-list entry\n"
16891 "Community list name\n")
16892
16893 /* Return configuration string of community-list entry. */
16894 static const char *community_list_config_str(struct community_entry *entry)
16895 {
16896 const char *str;
16897
16898 if (entry->any)
16899 str = "";
16900 else {
16901 if (entry->style == COMMUNITY_LIST_STANDARD)
16902 str = community_str(entry->u.com, false);
16903 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
16904 str = lcommunity_str(entry->u.lcom, false);
16905 else
16906 str = entry->config;
16907 }
16908 return str;
16909 }
16910
16911 static void community_list_show(struct vty *vty, struct community_list *list)
16912 {
16913 struct community_entry *entry;
16914
16915 for (entry = list->head; entry; entry = entry->next) {
16916 if (entry == list->head) {
16917 if (all_digit(list->name))
16918 vty_out(vty, "Community %s list %s\n",
16919 entry->style == COMMUNITY_LIST_STANDARD
16920 ? "standard"
16921 : "(expanded) access",
16922 list->name);
16923 else
16924 vty_out(vty, "Named Community %s list %s\n",
16925 entry->style == COMMUNITY_LIST_STANDARD
16926 ? "standard"
16927 : "expanded",
16928 list->name);
16929 }
16930 if (entry->any)
16931 vty_out(vty, " %s\n",
16932 community_direct_str(entry->direct));
16933 else
16934 vty_out(vty, " %s %s\n",
16935 community_direct_str(entry->direct),
16936 community_list_config_str(entry));
16937 }
16938 }
16939
16940 DEFUN (show_community_list,
16941 show_bgp_community_list_cmd,
16942 "show bgp community-list",
16943 SHOW_STR
16944 BGP_STR
16945 "List community-list\n")
16946 {
16947 struct community_list *list;
16948 struct community_list_master *cm;
16949
16950 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
16951 if (!cm)
16952 return CMD_SUCCESS;
16953
16954 for (list = cm->num.head; list; list = list->next)
16955 community_list_show(vty, list);
16956
16957 for (list = cm->str.head; list; list = list->next)
16958 community_list_show(vty, list);
16959
16960 return CMD_SUCCESS;
16961 }
16962
16963 DEFUN (show_community_list_arg,
16964 show_bgp_community_list_arg_cmd,
16965 "show bgp community-list <(1-500)|WORD> detail",
16966 SHOW_STR
16967 BGP_STR
16968 "List community-list\n"
16969 "Community-list number\n"
16970 "Community-list name\n"
16971 "Detailed information on community-list\n")
16972 {
16973 int idx_comm_list = 3;
16974 struct community_list *list;
16975
16976 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
16977 COMMUNITY_LIST_MASTER);
16978 if (!list) {
16979 vty_out(vty, "%% Can't find community-list\n");
16980 return CMD_WARNING;
16981 }
16982
16983 community_list_show(vty, list);
16984
16985 return CMD_SUCCESS;
16986 }
16987
16988 /*
16989 * Large Community code.
16990 */
16991 static int lcommunity_list_set_vty(struct vty *vty, int argc,
16992 struct cmd_token **argv, int style,
16993 int reject_all_digit_name)
16994 {
16995 int ret;
16996 int direct;
16997 char *str;
16998 int idx = 0;
16999 char *cl_name;
17000 char *seq = NULL;
17001
17002 argv_find(argv, argc, "(1-4294967295)", &idx);
17003 if (idx)
17004 seq = argv[idx]->arg;
17005
17006 idx = 0;
17007 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
17008 : COMMUNITY_DENY;
17009
17010 /* All digit name check. */
17011 idx = 0;
17012 argv_find(argv, argc, "WORD", &idx);
17013 argv_find(argv, argc, "(1-99)", &idx);
17014 argv_find(argv, argc, "(100-500)", &idx);
17015 cl_name = argv[idx]->arg;
17016 if (reject_all_digit_name && all_digit(cl_name)) {
17017 vty_out(vty, "%% Community name cannot have all digits\n");
17018 return CMD_WARNING_CONFIG_FAILED;
17019 }
17020
17021 idx = 0;
17022 argv_find(argv, argc, "AA:BB:CC", &idx);
17023 argv_find(argv, argc, "LINE", &idx);
17024 /* Concat community string argument. */
17025 if (idx)
17026 str = argv_concat(argv, argc, idx);
17027 else
17028 str = NULL;
17029
17030 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
17031
17032 /* Free temporary community list string allocated by
17033 argv_concat(). */
17034 XFREE(MTYPE_TMP, str);
17035
17036 if (ret < 0) {
17037 community_list_perror(vty, ret);
17038 return CMD_WARNING_CONFIG_FAILED;
17039 }
17040 return CMD_SUCCESS;
17041 }
17042
17043 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
17044 struct cmd_token **argv, int style)
17045 {
17046 int ret;
17047 int direct = 0;
17048 char *str = NULL;
17049 int idx = 0;
17050 char *seq = NULL;
17051
17052 argv_find(argv, argc, "(1-4294967295)", &idx);
17053 if (idx)
17054 seq = argv[idx]->arg;
17055
17056 idx = 0;
17057 argv_find(argv, argc, "permit", &idx);
17058 argv_find(argv, argc, "deny", &idx);
17059
17060 if (idx) {
17061 /* Check the list direct. */
17062 if (strncmp(argv[idx]->arg, "p", 1) == 0)
17063 direct = COMMUNITY_PERMIT;
17064 else
17065 direct = COMMUNITY_DENY;
17066
17067 idx = 0;
17068 argv_find(argv, argc, "LINE", &idx);
17069 argv_find(argv, argc, "AA:AA:NN", &idx);
17070 /* Concat community string argument. */
17071 str = argv_concat(argv, argc, idx);
17072 }
17073
17074 idx = 0;
17075 argv_find(argv, argc, "(1-99)", &idx);
17076 argv_find(argv, argc, "(100-500)", &idx);
17077 argv_find(argv, argc, "WORD", &idx);
17078
17079 /* Unset community list. */
17080 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
17081 style);
17082
17083 /* Free temporary community list string allocated by
17084 argv_concat(). */
17085 XFREE(MTYPE_TMP, str);
17086
17087 if (ret < 0) {
17088 community_list_perror(vty, ret);
17089 return CMD_WARNING_CONFIG_FAILED;
17090 }
17091
17092 return CMD_SUCCESS;
17093 }
17094
17095 /* "large-community-list" keyword help string. */
17096 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
17097 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
17098
17099 DEFUN (lcommunity_list_standard,
17100 bgp_lcommunity_list_standard_cmd,
17101 "bgp large-community-list (1-99) [seq (1-4294967295)] <deny|permit> AA:BB:CC...",
17102 BGP_STR
17103 LCOMMUNITY_LIST_STR
17104 "Large Community list number (standard)\n"
17105 "Sequence number of an entry\n"
17106 "Sequence number\n"
17107 "Specify large community to reject\n"
17108 "Specify large community to accept\n"
17109 LCOMMUNITY_VAL_STR)
17110 {
17111 return lcommunity_list_set_vty(vty, argc, argv,
17112 LARGE_COMMUNITY_LIST_STANDARD, 0);
17113 }
17114
17115 DEFUN (lcommunity_list_expanded,
17116 bgp_lcommunity_list_expanded_cmd,
17117 "bgp large-community-list (100-500) [seq (1-4294967295)] <deny|permit> LINE...",
17118 BGP_STR
17119 LCOMMUNITY_LIST_STR
17120 "Large Community list number (expanded)\n"
17121 "Sequence number of an entry\n"
17122 "Sequence number\n"
17123 "Specify large community to reject\n"
17124 "Specify large community to accept\n"
17125 "An ordered list as a regular-expression\n")
17126 {
17127 return lcommunity_list_set_vty(vty, argc, argv,
17128 LARGE_COMMUNITY_LIST_EXPANDED, 0);
17129 }
17130
17131 DEFUN (lcommunity_list_name_standard,
17132 bgp_lcommunity_list_name_standard_cmd,
17133 "bgp large-community-list standard WORD [seq (1-4294967295)] <deny|permit> AA:BB:CC...",
17134 BGP_STR
17135 LCOMMUNITY_LIST_STR
17136 "Specify standard large-community-list\n"
17137 "Large Community list name\n"
17138 "Sequence number of an entry\n"
17139 "Sequence number\n"
17140 "Specify large community to reject\n"
17141 "Specify large community to accept\n"
17142 LCOMMUNITY_VAL_STR)
17143 {
17144 return lcommunity_list_set_vty(vty, argc, argv,
17145 LARGE_COMMUNITY_LIST_STANDARD, 1);
17146 }
17147
17148 DEFUN (lcommunity_list_name_expanded,
17149 bgp_lcommunity_list_name_expanded_cmd,
17150 "bgp large-community-list expanded WORD [seq (1-4294967295)] <deny|permit> LINE...",
17151 BGP_STR
17152 LCOMMUNITY_LIST_STR
17153 "Specify expanded large-community-list\n"
17154 "Large Community list name\n"
17155 "Sequence number of an entry\n"
17156 "Sequence number\n"
17157 "Specify large community to reject\n"
17158 "Specify large community to accept\n"
17159 "An ordered list as a regular-expression\n")
17160 {
17161 return lcommunity_list_set_vty(vty, argc, argv,
17162 LARGE_COMMUNITY_LIST_EXPANDED, 1);
17163 }
17164
17165 DEFUN (no_lcommunity_list_all,
17166 no_bgp_lcommunity_list_all_cmd,
17167 "no bgp large-community-list <(1-99)|(100-500)|WORD>",
17168 NO_STR
17169 BGP_STR
17170 LCOMMUNITY_LIST_STR
17171 "Large Community list number (standard)\n"
17172 "Large Community list number (expanded)\n"
17173 "Large Community list name\n")
17174 {
17175 return lcommunity_list_unset_vty(vty, argc, argv,
17176 LARGE_COMMUNITY_LIST_STANDARD);
17177 }
17178
17179 DEFUN (no_lcommunity_list_name_standard_all,
17180 no_bgp_lcommunity_list_name_standard_all_cmd,
17181 "no bgp large-community-list standard WORD",
17182 NO_STR
17183 BGP_STR
17184 LCOMMUNITY_LIST_STR
17185 "Specify standard large-community-list\n"
17186 "Large Community list name\n")
17187 {
17188 return lcommunity_list_unset_vty(vty, argc, argv,
17189 LARGE_COMMUNITY_LIST_STANDARD);
17190 }
17191
17192 DEFUN (no_lcommunity_list_name_expanded_all,
17193 no_bgp_lcommunity_list_name_expanded_all_cmd,
17194 "no bgp large-community-list expanded WORD",
17195 NO_STR
17196 BGP_STR
17197 LCOMMUNITY_LIST_STR
17198 "Specify expanded large-community-list\n"
17199 "Large Community list name\n")
17200 {
17201 return lcommunity_list_unset_vty(vty, argc, argv,
17202 LARGE_COMMUNITY_LIST_EXPANDED);
17203 }
17204
17205 DEFUN (no_lcommunity_list_standard,
17206 no_bgp_lcommunity_list_standard_cmd,
17207 "no bgp large-community-list (1-99) [seq (1-4294967295)] <deny|permit> AA:AA:NN...",
17208 NO_STR
17209 BGP_STR
17210 LCOMMUNITY_LIST_STR
17211 "Large Community list number (standard)\n"
17212 "Sequence number of an entry\n"
17213 "Sequence number\n"
17214 "Specify large community to reject\n"
17215 "Specify large community to accept\n"
17216 LCOMMUNITY_VAL_STR)
17217 {
17218 return lcommunity_list_unset_vty(vty, argc, argv,
17219 LARGE_COMMUNITY_LIST_STANDARD);
17220 }
17221
17222 DEFUN (no_lcommunity_list_expanded,
17223 no_bgp_lcommunity_list_expanded_cmd,
17224 "no bgp large-community-list (100-500) [seq (1-4294967295)] <deny|permit> LINE...",
17225 NO_STR
17226 BGP_STR
17227 LCOMMUNITY_LIST_STR
17228 "Large Community list number (expanded)\n"
17229 "Sequence number of an entry\n"
17230 "Sequence number\n"
17231 "Specify large community to reject\n"
17232 "Specify large community to accept\n"
17233 "An ordered list as a regular-expression\n")
17234 {
17235 return lcommunity_list_unset_vty(vty, argc, argv,
17236 LARGE_COMMUNITY_LIST_EXPANDED);
17237 }
17238
17239 DEFUN (no_lcommunity_list_name_standard,
17240 no_bgp_lcommunity_list_name_standard_cmd,
17241 "no bgp large-community-list standard WORD [seq (1-4294967295)] <deny|permit> AA:AA:NN...",
17242 NO_STR
17243 BGP_STR
17244 LCOMMUNITY_LIST_STR
17245 "Specify standard large-community-list\n"
17246 "Large Community list name\n"
17247 "Sequence number of an entry\n"
17248 "Sequence number\n"
17249 "Specify large community to reject\n"
17250 "Specify large community to accept\n"
17251 LCOMMUNITY_VAL_STR)
17252 {
17253 return lcommunity_list_unset_vty(vty, argc, argv,
17254 LARGE_COMMUNITY_LIST_STANDARD);
17255 }
17256
17257 DEFUN (no_lcommunity_list_name_expanded,
17258 no_bgp_lcommunity_list_name_expanded_cmd,
17259 "no bgp large-community-list expanded WORD [seq (1-4294967295)] <deny|permit> LINE...",
17260 NO_STR
17261 BGP_STR
17262 LCOMMUNITY_LIST_STR
17263 "Specify expanded large-community-list\n"
17264 "Large community list name\n"
17265 "Sequence number of an entry\n"
17266 "Sequence number\n"
17267 "Specify large community to reject\n"
17268 "Specify large community to accept\n"
17269 "An ordered list as a regular-expression\n")
17270 {
17271 return lcommunity_list_unset_vty(vty, argc, argv,
17272 LARGE_COMMUNITY_LIST_EXPANDED);
17273 }
17274
17275 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
17276 {
17277 struct community_entry *entry;
17278
17279 for (entry = list->head; entry; entry = entry->next) {
17280 if (entry == list->head) {
17281 if (all_digit(list->name))
17282 vty_out(vty, "Large community %s list %s\n",
17283 entry->style ==
17284 LARGE_COMMUNITY_LIST_STANDARD
17285 ? "standard"
17286 : "(expanded) access",
17287 list->name);
17288 else
17289 vty_out(vty,
17290 "Named large community %s list %s\n",
17291 entry->style ==
17292 LARGE_COMMUNITY_LIST_STANDARD
17293 ? "standard"
17294 : "expanded",
17295 list->name);
17296 }
17297 if (entry->any)
17298 vty_out(vty, " %s\n",
17299 community_direct_str(entry->direct));
17300 else
17301 vty_out(vty, " %s %s\n",
17302 community_direct_str(entry->direct),
17303 community_list_config_str(entry));
17304 }
17305 }
17306
17307 DEFUN (show_lcommunity_list,
17308 show_bgp_lcommunity_list_cmd,
17309 "show bgp large-community-list",
17310 SHOW_STR
17311 BGP_STR
17312 "List large-community list\n")
17313 {
17314 struct community_list *list;
17315 struct community_list_master *cm;
17316
17317 cm = community_list_master_lookup(bgp_clist,
17318 LARGE_COMMUNITY_LIST_MASTER);
17319 if (!cm)
17320 return CMD_SUCCESS;
17321
17322 for (list = cm->num.head; list; list = list->next)
17323 lcommunity_list_show(vty, list);
17324
17325 for (list = cm->str.head; list; list = list->next)
17326 lcommunity_list_show(vty, list);
17327
17328 return CMD_SUCCESS;
17329 }
17330
17331 DEFUN (show_lcommunity_list_arg,
17332 show_bgp_lcommunity_list_arg_cmd,
17333 "show bgp large-community-list <(1-500)|WORD> detail",
17334 SHOW_STR
17335 BGP_STR
17336 "List large-community list\n"
17337 "Large-community-list number\n"
17338 "Large-community-list name\n"
17339 "Detailed information on large-community-list\n")
17340 {
17341 struct community_list *list;
17342
17343 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
17344 LARGE_COMMUNITY_LIST_MASTER);
17345 if (!list) {
17346 vty_out(vty, "%% Can't find large-community-list\n");
17347 return CMD_WARNING;
17348 }
17349
17350 lcommunity_list_show(vty, list);
17351
17352 return CMD_SUCCESS;
17353 }
17354
17355 /* "extcommunity-list" keyword help string. */
17356 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
17357 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
17358
17359 DEFUN (extcommunity_list_standard,
17360 bgp_extcommunity_list_standard_cmd,
17361 "bgp extcommunity-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
17362 BGP_STR
17363 EXTCOMMUNITY_LIST_STR
17364 "Extended Community list number (standard)\n"
17365 "Specify standard extcommunity-list\n"
17366 "Community list name\n"
17367 "Sequence number of an entry\n"
17368 "Sequence number\n"
17369 "Specify community to reject\n"
17370 "Specify community to accept\n"
17371 EXTCOMMUNITY_VAL_STR)
17372 {
17373 int style = EXTCOMMUNITY_LIST_STANDARD;
17374 int direct = 0;
17375 char *cl_number_or_name = NULL;
17376 char *seq = NULL;
17377
17378 int idx = 0;
17379
17380 argv_find(argv, argc, "(1-99)", &idx);
17381 argv_find(argv, argc, "WORD", &idx);
17382 cl_number_or_name = argv[idx]->arg;
17383
17384 argv_find(argv, argc, "(1-4294967295)", &idx);
17385 if (idx)
17386 seq = argv[idx]->arg;
17387
17388 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
17389 : COMMUNITY_DENY;
17390 argv_find(argv, argc, "AA:NN", &idx);
17391 char *str = argv_concat(argv, argc, idx);
17392
17393 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
17394 direct, style);
17395
17396 XFREE(MTYPE_TMP, str);
17397
17398 if (ret < 0) {
17399 community_list_perror(vty, ret);
17400 return CMD_WARNING_CONFIG_FAILED;
17401 }
17402
17403 return CMD_SUCCESS;
17404 }
17405
17406 DEFUN (extcommunity_list_name_expanded,
17407 bgp_extcommunity_list_name_expanded_cmd,
17408 "bgp extcommunity-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> LINE...",
17409 BGP_STR
17410 EXTCOMMUNITY_LIST_STR
17411 "Extended Community list number (expanded)\n"
17412 "Specify expanded extcommunity-list\n"
17413 "Extended Community list name\n"
17414 "Sequence number of an entry\n"
17415 "Sequence number\n"
17416 "Specify community to reject\n"
17417 "Specify community to accept\n"
17418 "An ordered list as a regular-expression\n")
17419 {
17420 int style = EXTCOMMUNITY_LIST_EXPANDED;
17421 int direct = 0;
17422 char *cl_number_or_name = NULL;
17423 char *seq = NULL;
17424 int idx = 0;
17425
17426 argv_find(argv, argc, "(100-500)", &idx);
17427 argv_find(argv, argc, "WORD", &idx);
17428 cl_number_or_name = argv[idx]->arg;
17429
17430 argv_find(argv, argc, "(1-4294967295)", &idx);
17431 if (idx)
17432 seq = argv[idx]->arg;
17433
17434 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
17435 : COMMUNITY_DENY;
17436 argv_find(argv, argc, "LINE", &idx);
17437 char *str = argv_concat(argv, argc, idx);
17438
17439 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
17440 direct, style);
17441
17442 XFREE(MTYPE_TMP, str);
17443
17444 if (ret < 0) {
17445 community_list_perror(vty, ret);
17446 return CMD_WARNING_CONFIG_FAILED;
17447 }
17448
17449 return CMD_SUCCESS;
17450 }
17451
17452 DEFUN (no_extcommunity_list_standard_all,
17453 no_bgp_extcommunity_list_standard_all_cmd,
17454 "no bgp extcommunity-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
17455 NO_STR
17456 BGP_STR
17457 EXTCOMMUNITY_LIST_STR
17458 "Extended Community list number (standard)\n"
17459 "Specify standard extcommunity-list\n"
17460 "Community list name\n"
17461 "Sequence number of an entry\n"
17462 "Sequence number\n"
17463 "Specify community to reject\n"
17464 "Specify community to accept\n"
17465 EXTCOMMUNITY_VAL_STR)
17466 {
17467 int style = EXTCOMMUNITY_LIST_STANDARD;
17468 int direct = 0;
17469 char *cl_number_or_name = NULL;
17470 char *str = NULL;
17471 char *seq = NULL;
17472 int idx = 0;
17473
17474 argv_find(argv, argc, "(1-4294967295)", &idx);
17475 if (idx)
17476 seq = argv[idx]->arg;
17477
17478 idx = 0;
17479 argv_find(argv, argc, "permit", &idx);
17480 argv_find(argv, argc, "deny", &idx);
17481 if (idx) {
17482 direct = argv_find(argv, argc, "permit", &idx)
17483 ? COMMUNITY_PERMIT
17484 : COMMUNITY_DENY;
17485
17486 idx = 0;
17487 argv_find(argv, argc, "AA:NN", &idx);
17488 str = argv_concat(argv, argc, idx);
17489 }
17490
17491 idx = 0;
17492 argv_find(argv, argc, "(1-99)", &idx);
17493 argv_find(argv, argc, "WORD", &idx);
17494 cl_number_or_name = argv[idx]->arg;
17495
17496 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
17497 seq, direct, style);
17498
17499 XFREE(MTYPE_TMP, str);
17500
17501 if (ret < 0) {
17502 community_list_perror(vty, ret);
17503 return CMD_WARNING_CONFIG_FAILED;
17504 }
17505
17506 return CMD_SUCCESS;
17507 }
17508
17509 ALIAS(no_extcommunity_list_standard_all,
17510 no_bgp_extcommunity_list_standard_all_list_cmd,
17511 "no bgp extcommunity-list <(1-99)|standard WORD>",
17512 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
17513 "Extended Community list number (standard)\n"
17514 "Specify standard extcommunity-list\n"
17515 "Community list name\n")
17516
17517 DEFUN (no_extcommunity_list_expanded_all,
17518 no_bgp_extcommunity_list_expanded_all_cmd,
17519 "no bgp extcommunity-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> LINE...",
17520 NO_STR
17521 BGP_STR
17522 EXTCOMMUNITY_LIST_STR
17523 "Extended Community list number (expanded)\n"
17524 "Specify expanded extcommunity-list\n"
17525 "Extended Community list name\n"
17526 "Sequence number of an entry\n"
17527 "Sequence number\n"
17528 "Specify community to reject\n"
17529 "Specify community to accept\n"
17530 "An ordered list as a regular-expression\n")
17531 {
17532 int style = EXTCOMMUNITY_LIST_EXPANDED;
17533 int direct = 0;
17534 char *cl_number_or_name = NULL;
17535 char *str = NULL;
17536 char *seq = NULL;
17537 int idx = 0;
17538
17539 argv_find(argv, argc, "(1-4294967295)", &idx);
17540 if (idx)
17541 seq = argv[idx]->arg;
17542
17543 idx = 0;
17544 argv_find(argv, argc, "permit", &idx);
17545 argv_find(argv, argc, "deny", &idx);
17546
17547 if (idx) {
17548 direct = argv_find(argv, argc, "permit", &idx)
17549 ? COMMUNITY_PERMIT
17550 : COMMUNITY_DENY;
17551
17552 idx = 0;
17553 argv_find(argv, argc, "LINE", &idx);
17554 str = argv_concat(argv, argc, idx);
17555 }
17556
17557 idx = 0;
17558 argv_find(argv, argc, "(100-500)", &idx);
17559 argv_find(argv, argc, "WORD", &idx);
17560 cl_number_or_name = argv[idx]->arg;
17561
17562 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
17563 seq, direct, style);
17564
17565 XFREE(MTYPE_TMP, str);
17566
17567 if (ret < 0) {
17568 community_list_perror(vty, ret);
17569 return CMD_WARNING_CONFIG_FAILED;
17570 }
17571
17572 return CMD_SUCCESS;
17573 }
17574
17575 ALIAS(no_extcommunity_list_expanded_all,
17576 no_bgp_extcommunity_list_expanded_all_list_cmd,
17577 "no bgp extcommunity-list <(100-500)|expanded WORD>",
17578 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
17579 "Extended Community list number (expanded)\n"
17580 "Specify expanded extcommunity-list\n"
17581 "Extended Community list name\n")
17582
17583 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
17584 {
17585 struct community_entry *entry;
17586
17587 for (entry = list->head; entry; entry = entry->next) {
17588 if (entry == list->head) {
17589 if (all_digit(list->name))
17590 vty_out(vty, "Extended community %s list %s\n",
17591 entry->style == EXTCOMMUNITY_LIST_STANDARD
17592 ? "standard"
17593 : "(expanded) access",
17594 list->name);
17595 else
17596 vty_out(vty,
17597 "Named extended community %s list %s\n",
17598 entry->style == EXTCOMMUNITY_LIST_STANDARD
17599 ? "standard"
17600 : "expanded",
17601 list->name);
17602 }
17603 if (entry->any)
17604 vty_out(vty, " %s\n",
17605 community_direct_str(entry->direct));
17606 else
17607 vty_out(vty, " %s %s\n",
17608 community_direct_str(entry->direct),
17609 community_list_config_str(entry));
17610 }
17611 }
17612
17613 DEFUN (show_extcommunity_list,
17614 show_bgp_extcommunity_list_cmd,
17615 "show bgp extcommunity-list",
17616 SHOW_STR
17617 BGP_STR
17618 "List extended-community list\n")
17619 {
17620 struct community_list *list;
17621 struct community_list_master *cm;
17622
17623 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
17624 if (!cm)
17625 return CMD_SUCCESS;
17626
17627 for (list = cm->num.head; list; list = list->next)
17628 extcommunity_list_show(vty, list);
17629
17630 for (list = cm->str.head; list; list = list->next)
17631 extcommunity_list_show(vty, list);
17632
17633 return CMD_SUCCESS;
17634 }
17635
17636 DEFUN (show_extcommunity_list_arg,
17637 show_bgp_extcommunity_list_arg_cmd,
17638 "show bgp extcommunity-list <(1-500)|WORD> detail",
17639 SHOW_STR
17640 BGP_STR
17641 "List extended-community list\n"
17642 "Extcommunity-list number\n"
17643 "Extcommunity-list name\n"
17644 "Detailed information on extcommunity-list\n")
17645 {
17646 int idx_comm_list = 3;
17647 struct community_list *list;
17648
17649 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
17650 EXTCOMMUNITY_LIST_MASTER);
17651 if (!list) {
17652 vty_out(vty, "%% Can't find extcommunity-list\n");
17653 return CMD_WARNING;
17654 }
17655
17656 extcommunity_list_show(vty, list);
17657
17658 return CMD_SUCCESS;
17659 }
17660
17661 /* Display community-list and extcommunity-list configuration. */
17662 static int community_list_config_write(struct vty *vty)
17663 {
17664 struct community_list *list;
17665 struct community_entry *entry;
17666 struct community_list_master *cm;
17667 int write = 0;
17668
17669 /* Community-list. */
17670 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
17671
17672 for (list = cm->num.head; list; list = list->next)
17673 for (entry = list->head; entry; entry = entry->next) {
17674 vty_out(vty,
17675 "bgp community-list %s seq %" PRId64 " %s %s\n",
17676 list->name, entry->seq,
17677 community_direct_str(entry->direct),
17678 community_list_config_str(entry));
17679 write++;
17680 }
17681 for (list = cm->str.head; list; list = list->next)
17682 for (entry = list->head; entry; entry = entry->next) {
17683 vty_out(vty,
17684 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
17685 entry->style == COMMUNITY_LIST_STANDARD
17686 ? "standard"
17687 : "expanded",
17688 list->name, entry->seq,
17689 community_direct_str(entry->direct),
17690 community_list_config_str(entry));
17691 write++;
17692 }
17693
17694 /* Extcommunity-list. */
17695 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
17696
17697 for (list = cm->num.head; list; list = list->next)
17698 for (entry = list->head; entry; entry = entry->next) {
17699 vty_out(vty,
17700 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
17701 list->name, entry->seq,
17702 community_direct_str(entry->direct),
17703 community_list_config_str(entry));
17704 write++;
17705 }
17706 for (list = cm->str.head; list; list = list->next)
17707 for (entry = list->head; entry; entry = entry->next) {
17708 vty_out(vty,
17709 "bgp extcommunity-list %s %s seq %" PRId64
17710 " %s %s\n",
17711 entry->style == EXTCOMMUNITY_LIST_STANDARD
17712 ? "standard"
17713 : "expanded",
17714 list->name, entry->seq,
17715 community_direct_str(entry->direct),
17716 community_list_config_str(entry));
17717 write++;
17718 }
17719
17720
17721 /* lcommunity-list. */
17722 cm = community_list_master_lookup(bgp_clist,
17723 LARGE_COMMUNITY_LIST_MASTER);
17724
17725 for (list = cm->num.head; list; list = list->next)
17726 for (entry = list->head; entry; entry = entry->next) {
17727 vty_out(vty,
17728 "bgp large-community-list %s seq %" PRId64
17729 " %s %s\n",
17730 list->name, entry->seq,
17731 community_direct_str(entry->direct),
17732 community_list_config_str(entry));
17733 write++;
17734 }
17735 for (list = cm->str.head; list; list = list->next)
17736 for (entry = list->head; entry; entry = entry->next) {
17737 vty_out(vty,
17738 "bgp large-community-list %s %s seq %" PRId64
17739 " %s %s\n",
17740
17741 entry->style == LARGE_COMMUNITY_LIST_STANDARD
17742 ? "standard"
17743 : "expanded",
17744 list->name, entry->seq, community_direct_str(entry->direct),
17745 community_list_config_str(entry));
17746 write++;
17747 }
17748
17749 return write;
17750 }
17751
17752 static struct cmd_node community_list_node = {
17753 COMMUNITY_LIST_NODE, "", 1 /* Export to vtysh. */
17754 };
17755
17756 static void community_list_vty(void)
17757 {
17758 install_node(&community_list_node, community_list_config_write);
17759
17760 /* Community-list. */
17761 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
17762 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
17763 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
17764 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
17765 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
17766 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
17767 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
17768 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
17769
17770 /* Extcommunity-list. */
17771 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
17772 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
17773 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
17774 install_element(CONFIG_NODE,
17775 &no_bgp_extcommunity_list_standard_all_list_cmd);
17776 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
17777 install_element(CONFIG_NODE,
17778 &no_bgp_extcommunity_list_expanded_all_list_cmd);
17779 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
17780 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
17781
17782 /* Large Community List */
17783 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
17784 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
17785 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
17786 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
17787 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
17788 install_element(CONFIG_NODE,
17789 &no_bgp_lcommunity_list_name_standard_all_cmd);
17790 install_element(CONFIG_NODE,
17791 &no_bgp_lcommunity_list_name_expanded_all_cmd);
17792 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
17793 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
17794 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
17795 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
17796 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
17797 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
17798 }