]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
Merge pull request #5437 from ton31337/fix/replace_magic_number_to_readable
[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 "memory_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_addpath.h"
68 #include "bgpd/bgp_mac.h"
69
70 static struct peer_group *listen_range_exists(struct bgp *bgp,
71 struct prefix *range, int exact);
72
73 static enum node_type bgp_node_type(afi_t afi, safi_t safi)
74 {
75 switch (afi) {
76 case AFI_IP:
77 switch (safi) {
78 case SAFI_UNICAST:
79 return BGP_IPV4_NODE;
80 break;
81 case SAFI_MULTICAST:
82 return BGP_IPV4M_NODE;
83 break;
84 case SAFI_LABELED_UNICAST:
85 return BGP_IPV4L_NODE;
86 break;
87 case SAFI_MPLS_VPN:
88 return BGP_VPNV4_NODE;
89 break;
90 case SAFI_FLOWSPEC:
91 return BGP_FLOWSPECV4_NODE;
92 default:
93 /* not expected */
94 return BGP_IPV4_NODE;
95 break;
96 }
97 break;
98 case AFI_IP6:
99 switch (safi) {
100 case SAFI_UNICAST:
101 return BGP_IPV6_NODE;
102 break;
103 case SAFI_MULTICAST:
104 return BGP_IPV6M_NODE;
105 break;
106 case SAFI_LABELED_UNICAST:
107 return BGP_IPV6L_NODE;
108 break;
109 case SAFI_MPLS_VPN:
110 return BGP_VPNV6_NODE;
111 break;
112 case SAFI_FLOWSPEC:
113 return BGP_FLOWSPECV6_NODE;
114 default:
115 /* not expected */
116 return BGP_IPV4_NODE;
117 break;
118 }
119 break;
120 case AFI_L2VPN:
121 return BGP_EVPN_NODE;
122 break;
123 case AFI_UNSPEC:
124 case AFI_MAX:
125 // We should never be here but to clarify the switch statement..
126 return BGP_IPV4_NODE;
127 break;
128 }
129
130 // Impossible to happen
131 return BGP_IPV4_NODE;
132 }
133
134 static const char *get_afi_safi_vty_str(afi_t afi, safi_t safi)
135 {
136 if (afi == AFI_IP && safi == SAFI_UNICAST)
137 return "IPv4 Unicast";
138 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
139 return "IPv4 Multicast";
140 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
141 return "IPv4 Labeled Unicast";
142 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
143 return "IPv4 VPN";
144 else if (afi == AFI_IP && safi == SAFI_ENCAP)
145 return "IPv4 Encap";
146 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
147 return "IPv4 Flowspec";
148 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
149 return "IPv6 Unicast";
150 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
151 return "IPv6 Multicast";
152 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
153 return "IPv6 Labeled Unicast";
154 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
155 return "IPv6 VPN";
156 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
157 return "IPv6 Encap";
158 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
159 return "IPv6 Flowspec";
160 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
161 return "L2VPN EVPN";
162 else
163 return "Unknown";
164 }
165
166 /*
167 * Please note that we have intentionally camelCased
168 * the return strings here. So if you want
169 * to use this function, please ensure you
170 * are doing this within json output
171 */
172 static const char *get_afi_safi_json_str(afi_t afi, safi_t safi)
173 {
174 if (afi == AFI_IP && safi == SAFI_UNICAST)
175 return "ipv4Unicast";
176 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
177 return "ipv4Multicast";
178 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
179 return "ipv4LabeledUnicast";
180 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
181 return "ipv4Vpn";
182 else if (afi == AFI_IP && safi == SAFI_ENCAP)
183 return "ipv4Encap";
184 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
185 return "ipv4Flowspec";
186 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
187 return "ipv6Unicast";
188 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
189 return "ipv6Multicast";
190 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
191 return "ipv6LabeledUnicast";
192 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
193 return "ipv6Vpn";
194 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
195 return "ipv6Encap";
196 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
197 return "ipv6Flowspec";
198 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
199 return "l2VpnEvpn";
200 else
201 return "Unknown";
202 }
203
204 /* Utility function to get address family from current node. */
205 afi_t bgp_node_afi(struct vty *vty)
206 {
207 afi_t afi;
208 switch (vty->node) {
209 case BGP_IPV6_NODE:
210 case BGP_IPV6M_NODE:
211 case BGP_IPV6L_NODE:
212 case BGP_VPNV6_NODE:
213 case BGP_FLOWSPECV6_NODE:
214 afi = AFI_IP6;
215 break;
216 case BGP_EVPN_NODE:
217 afi = AFI_L2VPN;
218 break;
219 default:
220 afi = AFI_IP;
221 break;
222 }
223 return afi;
224 }
225
226 /* Utility function to get subsequent address family from current
227 node. */
228 safi_t bgp_node_safi(struct vty *vty)
229 {
230 safi_t safi;
231 switch (vty->node) {
232 case BGP_VPNV4_NODE:
233 case BGP_VPNV6_NODE:
234 safi = SAFI_MPLS_VPN;
235 break;
236 case BGP_IPV4M_NODE:
237 case BGP_IPV6M_NODE:
238 safi = SAFI_MULTICAST;
239 break;
240 case BGP_EVPN_NODE:
241 safi = SAFI_EVPN;
242 break;
243 case BGP_IPV4L_NODE:
244 case BGP_IPV6L_NODE:
245 safi = SAFI_LABELED_UNICAST;
246 break;
247 case BGP_FLOWSPECV4_NODE:
248 case BGP_FLOWSPECV6_NODE:
249 safi = SAFI_FLOWSPEC;
250 break;
251 default:
252 safi = SAFI_UNICAST;
253 break;
254 }
255 return safi;
256 }
257
258 /**
259 * Converts an AFI in string form to afi_t
260 *
261 * @param afi string, one of
262 * - "ipv4"
263 * - "ipv6"
264 * - "l2vpn"
265 * @return the corresponding afi_t
266 */
267 afi_t bgp_vty_afi_from_str(const char *afi_str)
268 {
269 afi_t afi = AFI_MAX; /* unknown */
270 if (strmatch(afi_str, "ipv4"))
271 afi = AFI_IP;
272 else if (strmatch(afi_str, "ipv6"))
273 afi = AFI_IP6;
274 else if (strmatch(afi_str, "l2vpn"))
275 afi = AFI_L2VPN;
276 return afi;
277 }
278
279 int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
280 afi_t *afi)
281 {
282 int ret = 0;
283 if (argv_find(argv, argc, "ipv4", index)) {
284 ret = 1;
285 if (afi)
286 *afi = AFI_IP;
287 } else if (argv_find(argv, argc, "ipv6", index)) {
288 ret = 1;
289 if (afi)
290 *afi = AFI_IP6;
291 } else if (argv_find(argv, argc, "l2vpn", index)) {
292 ret = 1;
293 if (afi)
294 *afi = AFI_L2VPN;
295 }
296 return ret;
297 }
298
299 /* supports <unicast|multicast|vpn|labeled-unicast> */
300 safi_t bgp_vty_safi_from_str(const char *safi_str)
301 {
302 safi_t safi = SAFI_MAX; /* unknown */
303 if (strmatch(safi_str, "multicast"))
304 safi = SAFI_MULTICAST;
305 else if (strmatch(safi_str, "unicast"))
306 safi = SAFI_UNICAST;
307 else if (strmatch(safi_str, "vpn"))
308 safi = SAFI_MPLS_VPN;
309 else if (strmatch(safi_str, "evpn"))
310 safi = SAFI_EVPN;
311 else if (strmatch(safi_str, "labeled-unicast"))
312 safi = SAFI_LABELED_UNICAST;
313 else if (strmatch(safi_str, "flowspec"))
314 safi = SAFI_FLOWSPEC;
315 return safi;
316 }
317
318 int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
319 safi_t *safi)
320 {
321 int ret = 0;
322 if (argv_find(argv, argc, "unicast", index)) {
323 ret = 1;
324 if (safi)
325 *safi = SAFI_UNICAST;
326 } else if (argv_find(argv, argc, "multicast", index)) {
327 ret = 1;
328 if (safi)
329 *safi = SAFI_MULTICAST;
330 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
331 ret = 1;
332 if (safi)
333 *safi = SAFI_LABELED_UNICAST;
334 } else if (argv_find(argv, argc, "vpn", index)) {
335 ret = 1;
336 if (safi)
337 *safi = SAFI_MPLS_VPN;
338 } else if (argv_find(argv, argc, "evpn", index)) {
339 ret = 1;
340 if (safi)
341 *safi = SAFI_EVPN;
342 } else if (argv_find(argv, argc, "flowspec", index)) {
343 ret = 1;
344 if (safi)
345 *safi = SAFI_FLOWSPEC;
346 }
347 return ret;
348 }
349
350 /*
351 * bgp_vty_find_and_parse_afi_safi_bgp
352 *
353 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
354 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
355 * to appropriate values for the calling function. This is to allow the
356 * calling function to make decisions appropriate for the show command
357 * that is being parsed.
358 *
359 * The show commands are generally of the form:
360 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
361 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
362 *
363 * Since we use argv_find if the show command in particular doesn't have:
364 * [ip]
365 * [<view|vrf> VIEWVRFNAME]
366 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
367 * The command parsing should still be ok.
368 *
369 * vty -> The vty for the command so we can output some useful data in
370 * the event of a parse error in the vrf.
371 * argv -> The command tokens
372 * argc -> How many command tokens we have
373 * idx -> The current place in the command, generally should be 0 for this
374 * function
375 * afi -> The parsed afi if it was included in the show command, returned here
376 * safi -> The parsed safi if it was included in the show command, returned here
377 * bgp -> Pointer to the bgp data structure we need to fill in.
378 * use_json -> json is configured or not
379 *
380 * The function returns the correct location in the parse tree for the
381 * last token found.
382 *
383 * Returns 0 for failure to parse correctly, else the idx position of where
384 * it found the last token.
385 */
386 int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
387 struct cmd_token **argv, int argc,
388 int *idx, afi_t *afi, safi_t *safi,
389 struct bgp **bgp, bool use_json)
390 {
391 char *vrf_name = NULL;
392
393 assert(afi);
394 assert(safi);
395 assert(bgp);
396
397 if (argv_find(argv, argc, "ip", idx))
398 *afi = AFI_IP;
399
400 if (argv_find(argv, argc, "view", idx))
401 vrf_name = argv[*idx + 1]->arg;
402 else if (argv_find(argv, argc, "vrf", idx)) {
403 vrf_name = argv[*idx + 1]->arg;
404 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
405 vrf_name = NULL;
406 }
407 if (vrf_name) {
408 if (strmatch(vrf_name, "all"))
409 *bgp = NULL;
410 else {
411 *bgp = bgp_lookup_by_name(vrf_name);
412 if (!*bgp) {
413 if (use_json) {
414 json_object *json = NULL;
415 json = json_object_new_object();
416 json_object_string_add(
417 json, "warning",
418 "View/Vrf is unknown");
419 vty_out(vty, "%s\n",
420 json_object_to_json_string_ext(json,
421 JSON_C_TO_STRING_PRETTY));
422 json_object_free(json);
423 }
424 else
425 vty_out(vty, "View/Vrf %s is unknown\n",
426 vrf_name);
427 *idx = 0;
428 return 0;
429 }
430 }
431 } else {
432 *bgp = bgp_get_default();
433 if (!*bgp) {
434 if (use_json) {
435 json_object *json = NULL;
436 json = json_object_new_object();
437 json_object_string_add(
438 json, "warning",
439 "Default BGP instance not found");
440 vty_out(vty, "%s\n",
441 json_object_to_json_string_ext(json,
442 JSON_C_TO_STRING_PRETTY));
443 json_object_free(json);
444 }
445 else
446 vty_out(vty,
447 "Default BGP instance not found\n");
448 *idx = 0;
449 return 0;
450 }
451 }
452
453 if (argv_find_and_parse_afi(argv, argc, idx, afi))
454 argv_find_and_parse_safi(argv, argc, idx, safi);
455
456 *idx += 1;
457 return *idx;
458 }
459
460 static int peer_address_self_check(struct bgp *bgp, union sockunion *su)
461 {
462 struct interface *ifp = NULL;
463
464 if (su->sa.sa_family == AF_INET)
465 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
466 else if (su->sa.sa_family == AF_INET6)
467 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
468 su->sin6.sin6_scope_id,
469 bgp->vrf_id);
470
471 if (ifp)
472 return 1;
473
474 return 0;
475 }
476
477 /* Utility function for looking up peer from VTY. */
478 /* This is used only for configuration, so disallow if attempted on
479 * a dynamic neighbor.
480 */
481 static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
482 {
483 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
484 int ret;
485 union sockunion su;
486 struct peer *peer;
487
488 if (!bgp) {
489 return NULL;
490 }
491
492 ret = str2sockunion(ip_str, &su);
493 if (ret < 0) {
494 peer = peer_lookup_by_conf_if(bgp, ip_str);
495 if (!peer) {
496 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
497 == NULL) {
498 vty_out(vty,
499 "%% Malformed address or name: %s\n",
500 ip_str);
501 return NULL;
502 }
503 }
504 } else {
505 peer = peer_lookup(bgp, &su);
506 if (!peer) {
507 vty_out(vty,
508 "%% Specify remote-as or peer-group commands first\n");
509 return NULL;
510 }
511 if (peer_dynamic_neighbor(peer)) {
512 vty_out(vty,
513 "%% Operation not allowed on a dynamic neighbor\n");
514 return NULL;
515 }
516 }
517 return peer;
518 }
519
520 /* Utility function for looking up peer or peer group. */
521 /* This is used only for configuration, so disallow if attempted on
522 * a dynamic neighbor.
523 */
524 struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
525 {
526 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
527 int ret;
528 union sockunion su;
529 struct peer *peer = NULL;
530 struct peer_group *group = NULL;
531
532 if (!bgp) {
533 return NULL;
534 }
535
536 ret = str2sockunion(peer_str, &su);
537 if (ret == 0) {
538 /* IP address, locate peer. */
539 peer = peer_lookup(bgp, &su);
540 } else {
541 /* Not IP, could match either peer configured on interface or a
542 * group. */
543 peer = peer_lookup_by_conf_if(bgp, peer_str);
544 if (!peer)
545 group = peer_group_lookup(bgp, peer_str);
546 }
547
548 if (peer) {
549 if (peer_dynamic_neighbor(peer)) {
550 vty_out(vty,
551 "%% Operation not allowed on a dynamic neighbor\n");
552 return NULL;
553 }
554
555 return peer;
556 }
557
558 if (group)
559 return group->conf;
560
561 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
562
563 return NULL;
564 }
565
566 int bgp_vty_return(struct vty *vty, int ret)
567 {
568 const char *str = NULL;
569
570 switch (ret) {
571 case BGP_ERR_INVALID_VALUE:
572 str = "Invalid value";
573 break;
574 case BGP_ERR_INVALID_FLAG:
575 str = "Invalid flag";
576 break;
577 case BGP_ERR_PEER_GROUP_SHUTDOWN:
578 str = "Peer-group has been shutdown. Activate the peer-group first";
579 break;
580 case BGP_ERR_PEER_FLAG_CONFLICT:
581 str = "Can't set override-capability and strict-capability-match at the same time";
582 break;
583 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
584 str = "Specify remote-as or peer-group remote AS first";
585 break;
586 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
587 str = "Cannot change the peer-group. Deconfigure first";
588 break;
589 case BGP_ERR_PEER_GROUP_MISMATCH:
590 str = "Peer is not a member of this peer-group";
591 break;
592 case BGP_ERR_PEER_FILTER_CONFLICT:
593 str = "Prefix/distribute list can not co-exist";
594 break;
595 case BGP_ERR_NOT_INTERNAL_PEER:
596 str = "Invalid command. Not an internal neighbor";
597 break;
598 case BGP_ERR_REMOVE_PRIVATE_AS:
599 str = "remove-private-AS cannot be configured for IBGP peers";
600 break;
601 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
602 str = "Local-AS allowed only for EBGP peers";
603 break;
604 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
605 str = "Cannot have local-as same as BGP AS number";
606 break;
607 case BGP_ERR_TCPSIG_FAILED:
608 str = "Error while applying TCP-Sig to session(s)";
609 break;
610 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
611 str = "ebgp-multihop and ttl-security cannot be configured together";
612 break;
613 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
614 str = "ttl-security only allowed for EBGP peers";
615 break;
616 case BGP_ERR_AS_OVERRIDE:
617 str = "as-override cannot be configured for IBGP peers";
618 break;
619 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
620 str = "Invalid limit for number of dynamic neighbors";
621 break;
622 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
623 str = "Dynamic neighbor listen range already exists";
624 break;
625 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
626 str = "Operation not allowed on a dynamic neighbor";
627 break;
628 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
629 str = "Operation not allowed on a directly connected neighbor";
630 break;
631 case BGP_ERR_PEER_SAFI_CONFLICT:
632 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
633 break;
634 }
635 if (str) {
636 vty_out(vty, "%% %s\n", str);
637 return CMD_WARNING_CONFIG_FAILED;
638 }
639 return CMD_SUCCESS;
640 }
641
642 /* BGP clear sort. */
643 enum clear_sort {
644 clear_all,
645 clear_peer,
646 clear_group,
647 clear_external,
648 clear_as
649 };
650
651 static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
652 safi_t safi, int error)
653 {
654 switch (error) {
655 case BGP_ERR_AF_UNCONFIGURED:
656 vty_out(vty,
657 "%%BGP: Enable %s address family for the neighbor %s\n",
658 get_afi_safi_str(afi, safi, false), peer->host);
659 break;
660 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
661 vty_out(vty,
662 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
663 peer->host);
664 break;
665 default:
666 break;
667 }
668 }
669
670 static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi,
671 struct listnode *nnode, enum bgp_clear_type stype)
672 {
673 int ret = 0;
674
675 /* if afi/.safi not specified, spin thru all of them */
676 if ((afi == AFI_UNSPEC) && (safi == SAFI_UNSPEC)) {
677 afi_t tmp_afi;
678 safi_t tmp_safi;
679
680 FOREACH_AFI_SAFI (tmp_afi, tmp_safi) {
681 if (!peer->afc[tmp_afi][tmp_safi])
682 continue;
683
684 if (stype == BGP_CLEAR_SOFT_NONE)
685 ret = peer_clear(peer, &nnode);
686 else
687 ret = peer_clear_soft(peer, tmp_afi, tmp_safi,
688 stype);
689 }
690 /* if afi specified and safi not, spin thru safis on this afi */
691 } else if (safi == SAFI_UNSPEC) {
692 safi_t tmp_safi;
693
694 for (tmp_safi = SAFI_UNICAST;
695 tmp_safi < SAFI_MAX; tmp_safi++) {
696 if (!peer->afc[afi][tmp_safi])
697 continue;
698
699 if (stype == BGP_CLEAR_SOFT_NONE)
700 ret = peer_clear(peer, &nnode);
701 else
702 ret = peer_clear_soft(peer, afi,
703 tmp_safi, stype);
704 }
705 /* both afi/safi specified, let the caller know if not defined */
706 } else {
707 if (!peer->afc[afi][safi])
708 return 1;
709
710 if (stype == BGP_CLEAR_SOFT_NONE)
711 ret = peer_clear(peer, &nnode);
712 else
713 ret = peer_clear_soft(peer, afi, safi, stype);
714 }
715
716 return ret;
717 }
718
719 /* `clear ip bgp' functions. */
720 static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
721 enum clear_sort sort, enum bgp_clear_type stype,
722 const char *arg)
723 {
724 int ret = 0;
725 bool found = false;
726 struct peer *peer;
727 struct listnode *node, *nnode;
728
729 /* Clear all neighbors. */
730 /*
731 * Pass along pointer to next node to peer_clear() when walking all
732 * nodes on the BGP instance as that may get freed if it is a
733 * doppelganger
734 */
735 if (sort == clear_all) {
736 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
737 ret = bgp_peer_clear(peer, afi, safi, nnode,
738 stype);
739
740 if (ret < 0)
741 bgp_clear_vty_error(vty, peer, afi, safi, ret);
742 }
743
744 /* This is to apply read-only mode on this clear. */
745 if (stype == BGP_CLEAR_SOFT_NONE)
746 bgp->update_delay_over = 0;
747
748 return CMD_SUCCESS;
749 }
750
751 /* Clear specified neighbor. */
752 if (sort == clear_peer) {
753 union sockunion su;
754
755 /* Make sockunion for lookup. */
756 ret = str2sockunion(arg, &su);
757 if (ret < 0) {
758 peer = peer_lookup_by_conf_if(bgp, arg);
759 if (!peer) {
760 peer = peer_lookup_by_hostname(bgp, arg);
761 if (!peer) {
762 vty_out(vty,
763 "Malformed address or name: %s\n",
764 arg);
765 return CMD_WARNING;
766 }
767 }
768 } else {
769 peer = peer_lookup(bgp, &su);
770 if (!peer) {
771 vty_out(vty,
772 "%%BGP: Unknown neighbor - \"%s\"\n",
773 arg);
774 return CMD_WARNING;
775 }
776 }
777
778 ret = bgp_peer_clear(peer, afi, safi, NULL, stype);
779
780 /* if afi/safi not defined for this peer, let caller know */
781 if (ret == 1)
782 ret = BGP_ERR_AF_UNCONFIGURED;
783
784 if (ret < 0)
785 bgp_clear_vty_error(vty, peer, afi, safi, ret);
786
787 return CMD_SUCCESS;
788 }
789
790 /* Clear all neighbors belonging to a specific peer-group. */
791 if (sort == clear_group) {
792 struct peer_group *group;
793
794 group = peer_group_lookup(bgp, arg);
795 if (!group) {
796 vty_out(vty, "%%BGP: No such peer-group %s\n", arg);
797 return CMD_WARNING;
798 }
799
800 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
801 ret = bgp_peer_clear(peer, afi, safi, nnode, stype);
802
803 if (ret < 0)
804 bgp_clear_vty_error(vty, peer, afi, safi, ret);
805 else
806 found = true;
807 }
808
809 if (!found)
810 vty_out(vty,
811 "%%BGP: No %s peer belonging to peer-group %s is configured\n",
812 get_afi_safi_str(afi, safi, false), arg);
813
814 return CMD_SUCCESS;
815 }
816
817 /* Clear all external (eBGP) neighbors. */
818 if (sort == clear_external) {
819 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
820 if (peer->sort == BGP_PEER_IBGP)
821 continue;
822
823 ret = bgp_peer_clear(peer, afi, safi, nnode, stype);
824
825 if (ret < 0)
826 bgp_clear_vty_error(vty, peer, afi, safi, ret);
827 else
828 found = true;
829 }
830
831 if (!found)
832 vty_out(vty,
833 "%%BGP: No external %s peer is configured\n",
834 get_afi_safi_str(afi, safi, false));
835
836 return CMD_SUCCESS;
837 }
838
839 /* Clear all neighbors belonging to a specific AS. */
840 if (sort == clear_as) {
841 as_t as = strtoul(arg, NULL, 10);
842
843 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
844 if (peer->as != as)
845 continue;
846
847 ret = bgp_peer_clear(peer, afi, safi, nnode, stype);
848
849 if (ret < 0)
850 bgp_clear_vty_error(vty, peer, afi, safi, ret);
851 else
852 found = true;
853 }
854
855 if (!found)
856 vty_out(vty,
857 "%%BGP: No %s peer is configured with AS %s\n",
858 get_afi_safi_str(afi, safi, false), arg);
859
860 return CMD_SUCCESS;
861 }
862
863 return CMD_SUCCESS;
864 }
865
866 static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
867 safi_t safi, enum clear_sort sort,
868 enum bgp_clear_type stype, const char *arg)
869 {
870 struct bgp *bgp;
871
872 /* BGP structure lookup. */
873 if (name) {
874 bgp = bgp_lookup_by_name(name);
875 if (bgp == NULL) {
876 vty_out(vty, "Can't find BGP instance %s\n", name);
877 return CMD_WARNING;
878 }
879 } else {
880 bgp = bgp_get_default();
881 if (bgp == NULL) {
882 vty_out(vty, "No BGP process is configured\n");
883 return CMD_WARNING;
884 }
885 }
886
887 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
888 }
889
890 /* clear soft inbound */
891 static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
892 {
893 afi_t afi;
894 safi_t safi;
895
896 FOREACH_AFI_SAFI (afi, safi)
897 bgp_clear_vty(vty, name, afi, safi, clear_all,
898 BGP_CLEAR_SOFT_IN, NULL);
899 }
900
901 /* clear soft outbound */
902 static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
903 {
904 afi_t afi;
905 safi_t safi;
906
907 FOREACH_AFI_SAFI (afi, safi)
908 bgp_clear_vty(vty, name, afi, safi, clear_all,
909 BGP_CLEAR_SOFT_OUT, NULL);
910 }
911
912
913 #ifndef VTYSH_EXTRACT_PL
914 #include "bgpd/bgp_vty_clippy.c"
915 #endif
916
917 DEFUN_HIDDEN (bgp_local_mac,
918 bgp_local_mac_cmd,
919 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
920 BGP_STR
921 "Local MAC config\n"
922 "VxLAN Network Identifier\n"
923 "VNI number\n"
924 "local mac\n"
925 "mac address\n"
926 "mac-mobility sequence\n"
927 "seq number\n")
928 {
929 int rv;
930 vni_t vni;
931 struct ethaddr mac;
932 struct ipaddr ip;
933 uint32_t seq;
934 struct bgp *bgp;
935
936 vni = strtoul(argv[3]->arg, NULL, 10);
937 if (!prefix_str2mac(argv[5]->arg, &mac)) {
938 vty_out(vty, "%% Malformed MAC address\n");
939 return CMD_WARNING;
940 }
941 memset(&ip, 0, sizeof(ip));
942 seq = strtoul(argv[7]->arg, NULL, 10);
943
944 bgp = bgp_get_default();
945 if (!bgp) {
946 vty_out(vty, "Default BGP instance is not there\n");
947 return CMD_WARNING;
948 }
949
950 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq);
951 if (rv < 0) {
952 vty_out(vty, "Internal error\n");
953 return CMD_WARNING;
954 }
955
956 return CMD_SUCCESS;
957 }
958
959 DEFUN_HIDDEN (no_bgp_local_mac,
960 no_bgp_local_mac_cmd,
961 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
962 NO_STR
963 BGP_STR
964 "Local MAC config\n"
965 "VxLAN Network Identifier\n"
966 "VNI number\n"
967 "local mac\n"
968 "mac address\n")
969 {
970 int rv;
971 vni_t vni;
972 struct ethaddr mac;
973 struct ipaddr ip;
974 struct bgp *bgp;
975
976 vni = strtoul(argv[4]->arg, NULL, 10);
977 if (!prefix_str2mac(argv[6]->arg, &mac)) {
978 vty_out(vty, "%% Malformed MAC address\n");
979 return CMD_WARNING;
980 }
981 memset(&ip, 0, sizeof(ip));
982
983 bgp = bgp_get_default();
984 if (!bgp) {
985 vty_out(vty, "Default BGP instance is not there\n");
986 return CMD_WARNING;
987 }
988
989 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
990 if (rv < 0) {
991 vty_out(vty, "Internal error\n");
992 return CMD_WARNING;
993 }
994
995 return CMD_SUCCESS;
996 }
997
998 DEFUN (no_synchronization,
999 no_synchronization_cmd,
1000 "no synchronization",
1001 NO_STR
1002 "Perform IGP synchronization\n")
1003 {
1004 return CMD_SUCCESS;
1005 }
1006
1007 DEFUN (no_auto_summary,
1008 no_auto_summary_cmd,
1009 "no auto-summary",
1010 NO_STR
1011 "Enable automatic network number summarization\n")
1012 {
1013 return CMD_SUCCESS;
1014 }
1015
1016 /* "router bgp" commands. */
1017 DEFUN_NOSH (router_bgp,
1018 router_bgp_cmd,
1019 "router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1020 ROUTER_STR
1021 BGP_STR
1022 AS_STR
1023 BGP_INSTANCE_HELP_STR)
1024 {
1025 int idx_asn = 2;
1026 int idx_view_vrf = 3;
1027 int idx_vrf = 4;
1028 int is_new_bgp = 0;
1029 int ret;
1030 as_t as;
1031 struct bgp *bgp;
1032 const char *name = NULL;
1033 enum bgp_instance_type inst_type;
1034
1035 // "router bgp" without an ASN
1036 if (argc == 2) {
1037 // Pending: Make VRF option available for ASN less config
1038 bgp = bgp_get_default();
1039
1040 if (bgp == NULL) {
1041 vty_out(vty, "%% No BGP process is configured\n");
1042 return CMD_WARNING_CONFIG_FAILED;
1043 }
1044
1045 if (listcount(bm->bgp) > 1) {
1046 vty_out(vty, "%% Please specify ASN and VRF\n");
1047 return CMD_WARNING_CONFIG_FAILED;
1048 }
1049 }
1050
1051 // "router bgp X"
1052 else {
1053 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1054
1055 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1056 if (argc > 3) {
1057 name = argv[idx_vrf]->arg;
1058
1059 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1060 if (strmatch(name, VRF_DEFAULT_NAME))
1061 name = NULL;
1062 else
1063 inst_type = BGP_INSTANCE_TYPE_VRF;
1064 } else if (!strcmp(argv[idx_view_vrf]->text, "view"))
1065 inst_type = BGP_INSTANCE_TYPE_VIEW;
1066 }
1067
1068 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1069 is_new_bgp = (bgp_lookup(as, name) == NULL);
1070
1071 ret = bgp_get(&bgp, &as, name, inst_type);
1072 switch (ret) {
1073 case BGP_ERR_AS_MISMATCH:
1074 vty_out(vty, "BGP is already running; AS is %u\n", as);
1075 return CMD_WARNING_CONFIG_FAILED;
1076 case BGP_ERR_INSTANCE_MISMATCH:
1077 vty_out(vty,
1078 "BGP instance name and AS number mismatch\n");
1079 vty_out(vty,
1080 "BGP instance is already running; AS is %u\n",
1081 as);
1082 return CMD_WARNING_CONFIG_FAILED;
1083 }
1084
1085 /*
1086 * If we just instantiated the default instance, complete
1087 * any pending VRF-VPN leaking that was configured via
1088 * earlier "router bgp X vrf FOO" blocks.
1089 */
1090 if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1091 vpn_leak_postchange_all();
1092
1093 if (inst_type == BGP_INSTANCE_TYPE_VRF)
1094 bgp_vpn_leak_export(bgp);
1095 /* Pending: handle when user tries to change a view to vrf n vv.
1096 */
1097 }
1098
1099 /* unset the auto created flag as the user config is now present */
1100 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
1101 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1102
1103 return CMD_SUCCESS;
1104 }
1105
1106 /* "no router bgp" commands. */
1107 DEFUN (no_router_bgp,
1108 no_router_bgp_cmd,
1109 "no router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1110 NO_STR
1111 ROUTER_STR
1112 BGP_STR
1113 AS_STR
1114 BGP_INSTANCE_HELP_STR)
1115 {
1116 int idx_asn = 3;
1117 int idx_vrf = 5;
1118 as_t as;
1119 struct bgp *bgp;
1120 const char *name = NULL;
1121
1122 // "no router bgp" without an ASN
1123 if (argc == 3) {
1124 // Pending: Make VRF option available for ASN less config
1125 bgp = bgp_get_default();
1126
1127 if (bgp == NULL) {
1128 vty_out(vty, "%% No BGP process is configured\n");
1129 return CMD_WARNING_CONFIG_FAILED;
1130 }
1131
1132 if (listcount(bm->bgp) > 1) {
1133 vty_out(vty, "%% Please specify ASN and VRF\n");
1134 return CMD_WARNING_CONFIG_FAILED;
1135 }
1136
1137 if (bgp->l3vni) {
1138 vty_out(vty, "%% Please unconfigure l3vni %u",
1139 bgp->l3vni);
1140 return CMD_WARNING_CONFIG_FAILED;
1141 }
1142 } else {
1143 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1144
1145 if (argc > 4)
1146 name = argv[idx_vrf]->arg;
1147
1148 /* Lookup bgp structure. */
1149 bgp = bgp_lookup(as, name);
1150 if (!bgp) {
1151 vty_out(vty, "%% Can't find BGP instance\n");
1152 return CMD_WARNING_CONFIG_FAILED;
1153 }
1154
1155 if (bgp->l3vni) {
1156 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1157 bgp->l3vni);
1158 return CMD_WARNING_CONFIG_FAILED;
1159 }
1160
1161 /* Cannot delete default instance if vrf instances exist */
1162 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
1163 struct listnode *node;
1164 struct bgp *tmp_bgp;
1165
1166 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, tmp_bgp)) {
1167 if (tmp_bgp->inst_type
1168 == BGP_INSTANCE_TYPE_VRF) {
1169 vty_out(vty,
1170 "%% Cannot delete default BGP instance. Dependent VRF instances exist\n");
1171 return CMD_WARNING_CONFIG_FAILED;
1172 }
1173 }
1174 }
1175 }
1176
1177 if (bgp_vpn_leak_unimport(bgp, vty))
1178 return CMD_WARNING_CONFIG_FAILED;
1179
1180 bgp_delete(bgp);
1181
1182 return CMD_SUCCESS;
1183 }
1184
1185
1186 /* BGP router-id. */
1187
1188 DEFPY (bgp_router_id,
1189 bgp_router_id_cmd,
1190 "bgp router-id A.B.C.D",
1191 BGP_STR
1192 "Override configured router identifier\n"
1193 "Manually configured router identifier\n")
1194 {
1195 VTY_DECLVAR_CONTEXT(bgp, bgp);
1196 bgp_router_id_static_set(bgp, router_id);
1197 return CMD_SUCCESS;
1198 }
1199
1200 DEFPY (no_bgp_router_id,
1201 no_bgp_router_id_cmd,
1202 "no bgp router-id [A.B.C.D]",
1203 NO_STR
1204 BGP_STR
1205 "Override configured router identifier\n"
1206 "Manually configured router identifier\n")
1207 {
1208 VTY_DECLVAR_CONTEXT(bgp, bgp);
1209
1210 if (router_id_str) {
1211 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1212 vty_out(vty, "%% BGP router-id doesn't match\n");
1213 return CMD_WARNING_CONFIG_FAILED;
1214 }
1215 }
1216
1217 router_id.s_addr = 0;
1218 bgp_router_id_static_set(bgp, router_id);
1219
1220 return CMD_SUCCESS;
1221 }
1222
1223
1224 /* BGP Cluster ID. */
1225 DEFUN (bgp_cluster_id,
1226 bgp_cluster_id_cmd,
1227 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1228 BGP_STR
1229 "Configure Route-Reflector Cluster-id\n"
1230 "Route-Reflector Cluster-id in IP address format\n"
1231 "Route-Reflector Cluster-id as 32 bit quantity\n")
1232 {
1233 VTY_DECLVAR_CONTEXT(bgp, bgp);
1234 int idx_ipv4 = 2;
1235 int ret;
1236 struct in_addr cluster;
1237
1238 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1239 if (!ret) {
1240 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1241 return CMD_WARNING_CONFIG_FAILED;
1242 }
1243
1244 bgp_cluster_id_set(bgp, &cluster);
1245 bgp_clear_star_soft_out(vty, bgp->name);
1246
1247 return CMD_SUCCESS;
1248 }
1249
1250 DEFUN (no_bgp_cluster_id,
1251 no_bgp_cluster_id_cmd,
1252 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1253 NO_STR
1254 BGP_STR
1255 "Configure Route-Reflector Cluster-id\n"
1256 "Route-Reflector Cluster-id in IP address format\n"
1257 "Route-Reflector Cluster-id as 32 bit quantity\n")
1258 {
1259 VTY_DECLVAR_CONTEXT(bgp, bgp);
1260 bgp_cluster_id_unset(bgp);
1261 bgp_clear_star_soft_out(vty, bgp->name);
1262
1263 return CMD_SUCCESS;
1264 }
1265
1266 DEFUN (bgp_confederation_identifier,
1267 bgp_confederation_identifier_cmd,
1268 "bgp confederation identifier (1-4294967295)",
1269 "BGP specific commands\n"
1270 "AS confederation parameters\n"
1271 "AS number\n"
1272 "Set routing domain confederation AS\n")
1273 {
1274 VTY_DECLVAR_CONTEXT(bgp, bgp);
1275 int idx_number = 3;
1276 as_t as;
1277
1278 as = strtoul(argv[idx_number]->arg, NULL, 10);
1279
1280 bgp_confederation_id_set(bgp, as);
1281
1282 return CMD_SUCCESS;
1283 }
1284
1285 DEFUN (no_bgp_confederation_identifier,
1286 no_bgp_confederation_identifier_cmd,
1287 "no bgp confederation identifier [(1-4294967295)]",
1288 NO_STR
1289 "BGP specific commands\n"
1290 "AS confederation parameters\n"
1291 "AS number\n"
1292 "Set routing domain confederation AS\n")
1293 {
1294 VTY_DECLVAR_CONTEXT(bgp, bgp);
1295 bgp_confederation_id_unset(bgp);
1296
1297 return CMD_SUCCESS;
1298 }
1299
1300 DEFUN (bgp_confederation_peers,
1301 bgp_confederation_peers_cmd,
1302 "bgp confederation peers (1-4294967295)...",
1303 "BGP specific commands\n"
1304 "AS confederation parameters\n"
1305 "Peer ASs in BGP confederation\n"
1306 AS_STR)
1307 {
1308 VTY_DECLVAR_CONTEXT(bgp, bgp);
1309 int idx_asn = 3;
1310 as_t as;
1311 int i;
1312
1313 for (i = idx_asn; i < argc; i++) {
1314 as = strtoul(argv[i]->arg, NULL, 10);
1315
1316 if (bgp->as == as) {
1317 vty_out(vty,
1318 "%% Local member-AS not allowed in confed peer list\n");
1319 continue;
1320 }
1321
1322 bgp_confederation_peers_add(bgp, as);
1323 }
1324 return CMD_SUCCESS;
1325 }
1326
1327 DEFUN (no_bgp_confederation_peers,
1328 no_bgp_confederation_peers_cmd,
1329 "no bgp confederation peers (1-4294967295)...",
1330 NO_STR
1331 "BGP specific commands\n"
1332 "AS confederation parameters\n"
1333 "Peer ASs in BGP confederation\n"
1334 AS_STR)
1335 {
1336 VTY_DECLVAR_CONTEXT(bgp, bgp);
1337 int idx_asn = 4;
1338 as_t as;
1339 int i;
1340
1341 for (i = idx_asn; i < argc; i++) {
1342 as = strtoul(argv[i]->arg, NULL, 10);
1343
1344 bgp_confederation_peers_remove(bgp, as);
1345 }
1346 return CMD_SUCCESS;
1347 }
1348
1349 /**
1350 * Central routine for maximum-paths configuration.
1351 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1352 * @set: 1 for setting values, 0 for removing the max-paths config.
1353 */
1354 static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
1355 const char *mpaths, uint16_t options,
1356 int set)
1357 {
1358 VTY_DECLVAR_CONTEXT(bgp, bgp);
1359 uint16_t maxpaths = 0;
1360 int ret;
1361 afi_t afi;
1362 safi_t safi;
1363
1364 afi = bgp_node_afi(vty);
1365 safi = bgp_node_safi(vty);
1366
1367 if (set) {
1368 maxpaths = strtol(mpaths, NULL, 10);
1369 if (maxpaths > multipath_num) {
1370 vty_out(vty,
1371 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1372 maxpaths, multipath_num);
1373 return CMD_WARNING_CONFIG_FAILED;
1374 }
1375 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1376 options);
1377 } else
1378 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1379
1380 if (ret < 0) {
1381 vty_out(vty,
1382 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1383 (set == 1) ? "" : "un",
1384 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1385 maxpaths, afi, safi);
1386 return CMD_WARNING_CONFIG_FAILED;
1387 }
1388
1389 bgp_recalculate_all_bestpaths(bgp);
1390
1391 return CMD_SUCCESS;
1392 }
1393
1394 DEFUN (bgp_maxmed_admin,
1395 bgp_maxmed_admin_cmd,
1396 "bgp max-med administrative ",
1397 BGP_STR
1398 "Advertise routes with max-med\n"
1399 "Administratively applied, for an indefinite period\n")
1400 {
1401 VTY_DECLVAR_CONTEXT(bgp, bgp);
1402
1403 bgp->v_maxmed_admin = 1;
1404 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1405
1406 bgp_maxmed_update(bgp);
1407
1408 return CMD_SUCCESS;
1409 }
1410
1411 DEFUN (bgp_maxmed_admin_medv,
1412 bgp_maxmed_admin_medv_cmd,
1413 "bgp max-med administrative (0-4294967295)",
1414 BGP_STR
1415 "Advertise routes with max-med\n"
1416 "Administratively applied, for an indefinite period\n"
1417 "Max MED value to be used\n")
1418 {
1419 VTY_DECLVAR_CONTEXT(bgp, bgp);
1420 int idx_number = 3;
1421
1422 bgp->v_maxmed_admin = 1;
1423 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
1424
1425 bgp_maxmed_update(bgp);
1426
1427 return CMD_SUCCESS;
1428 }
1429
1430 DEFUN (no_bgp_maxmed_admin,
1431 no_bgp_maxmed_admin_cmd,
1432 "no bgp max-med administrative [(0-4294967295)]",
1433 NO_STR
1434 BGP_STR
1435 "Advertise routes with max-med\n"
1436 "Administratively applied, for an indefinite period\n"
1437 "Max MED value to be used\n")
1438 {
1439 VTY_DECLVAR_CONTEXT(bgp, bgp);
1440 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1441 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1442 bgp_maxmed_update(bgp);
1443
1444 return CMD_SUCCESS;
1445 }
1446
1447 DEFUN (bgp_maxmed_onstartup,
1448 bgp_maxmed_onstartup_cmd,
1449 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
1450 BGP_STR
1451 "Advertise routes with max-med\n"
1452 "Effective on a startup\n"
1453 "Time (seconds) period for max-med\n"
1454 "Max MED value to be used\n")
1455 {
1456 VTY_DECLVAR_CONTEXT(bgp, bgp);
1457 int idx = 0;
1458
1459 argv_find(argv, argc, "(5-86400)", &idx);
1460 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
1461 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1462 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
1463 else
1464 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1465
1466 bgp_maxmed_update(bgp);
1467
1468 return CMD_SUCCESS;
1469 }
1470
1471 DEFUN (no_bgp_maxmed_onstartup,
1472 no_bgp_maxmed_onstartup_cmd,
1473 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
1474 NO_STR
1475 BGP_STR
1476 "Advertise routes with max-med\n"
1477 "Effective on a startup\n"
1478 "Time (seconds) period for max-med\n"
1479 "Max MED value to be used\n")
1480 {
1481 VTY_DECLVAR_CONTEXT(bgp, bgp);
1482
1483 /* Cancel max-med onstartup if its on */
1484 if (bgp->t_maxmed_onstartup) {
1485 THREAD_TIMER_OFF(bgp->t_maxmed_onstartup);
1486 bgp->maxmed_onstartup_over = 1;
1487 }
1488
1489 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
1490 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1491
1492 bgp_maxmed_update(bgp);
1493
1494 return CMD_SUCCESS;
1495 }
1496
1497 static int bgp_update_delay_config_vty(struct vty *vty, const char *delay,
1498 const char *wait)
1499 {
1500 VTY_DECLVAR_CONTEXT(bgp, bgp);
1501 uint16_t update_delay;
1502 uint16_t establish_wait;
1503
1504 update_delay = strtoul(delay, NULL, 10);
1505
1506 if (!wait) /* update-delay <delay> */
1507 {
1508 bgp->v_update_delay = update_delay;
1509 bgp->v_establish_wait = bgp->v_update_delay;
1510 return CMD_SUCCESS;
1511 }
1512
1513 /* update-delay <delay> <establish-wait> */
1514 establish_wait = atoi(wait);
1515 if (update_delay < establish_wait) {
1516 vty_out(vty,
1517 "%%Failed: update-delay less than the establish-wait!\n");
1518 return CMD_WARNING_CONFIG_FAILED;
1519 }
1520
1521 bgp->v_update_delay = update_delay;
1522 bgp->v_establish_wait = establish_wait;
1523
1524 return CMD_SUCCESS;
1525 }
1526
1527 static int bgp_update_delay_deconfig_vty(struct vty *vty)
1528 {
1529 VTY_DECLVAR_CONTEXT(bgp, bgp);
1530
1531 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
1532 bgp->v_establish_wait = bgp->v_update_delay;
1533
1534 return CMD_SUCCESS;
1535 }
1536
1537 void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
1538 {
1539 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1540 vty_out(vty, " update-delay %d", bgp->v_update_delay);
1541 if (bgp->v_update_delay != bgp->v_establish_wait)
1542 vty_out(vty, " %d", bgp->v_establish_wait);
1543 vty_out(vty, "\n");
1544 }
1545 }
1546
1547
1548 /* Update-delay configuration */
1549 DEFUN (bgp_update_delay,
1550 bgp_update_delay_cmd,
1551 "update-delay (0-3600)",
1552 "Force initial delay for best-path and updates\n"
1553 "Seconds\n")
1554 {
1555 int idx_number = 1;
1556 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg, NULL);
1557 }
1558
1559 DEFUN (bgp_update_delay_establish_wait,
1560 bgp_update_delay_establish_wait_cmd,
1561 "update-delay (0-3600) (1-3600)",
1562 "Force initial delay for best-path and updates\n"
1563 "Seconds\n"
1564 "Seconds\n")
1565 {
1566 int idx_number = 1;
1567 int idx_number_2 = 2;
1568 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg,
1569 argv[idx_number_2]->arg);
1570 }
1571
1572 /* Update-delay deconfiguration */
1573 DEFUN (no_bgp_update_delay,
1574 no_bgp_update_delay_cmd,
1575 "no update-delay [(0-3600) [(1-3600)]]",
1576 NO_STR
1577 "Force initial delay for best-path and updates\n"
1578 "Seconds\n"
1579 "Seconds\n")
1580 {
1581 return bgp_update_delay_deconfig_vty(vty);
1582 }
1583
1584
1585 static int bgp_wpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
1586 bool set)
1587 {
1588 VTY_DECLVAR_CONTEXT(bgp, bgp);
1589
1590 quanta = set ? quanta : BGP_WRITE_PACKET_MAX;
1591 atomic_store_explicit(&bgp->wpkt_quanta, quanta, memory_order_relaxed);
1592
1593 return CMD_SUCCESS;
1594 }
1595
1596 static int bgp_rpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
1597 bool set)
1598 {
1599 VTY_DECLVAR_CONTEXT(bgp, bgp);
1600
1601 quanta = set ? quanta : BGP_READ_PACKET_MAX;
1602 atomic_store_explicit(&bgp->rpkt_quanta, quanta, memory_order_relaxed);
1603
1604 return CMD_SUCCESS;
1605 }
1606
1607 void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
1608 {
1609 uint32_t quanta =
1610 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
1611 if (quanta != BGP_WRITE_PACKET_MAX)
1612 vty_out(vty, " write-quanta %d\n", quanta);
1613 }
1614
1615 void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
1616 {
1617 uint32_t quanta =
1618 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
1619 if (quanta != BGP_READ_PACKET_MAX)
1620 vty_out(vty, " read-quanta %d\n", quanta);
1621 }
1622
1623 /* Packet quanta configuration
1624 *
1625 * XXX: The value set here controls the size of a stack buffer in the IO
1626 * thread. When changing these limits be careful to prevent stack overflow.
1627 *
1628 * Furthermore, the maximums used here should correspond to
1629 * BGP_WRITE_PACKET_MAX and BGP_READ_PACKET_MAX.
1630 */
1631 DEFPY (bgp_wpkt_quanta,
1632 bgp_wpkt_quanta_cmd,
1633 "[no] write-quanta (1-64)$quanta",
1634 NO_STR
1635 "How many packets to write to peer socket per run\n"
1636 "Number of packets\n")
1637 {
1638 return bgp_wpkt_quanta_config_vty(vty, quanta, !no);
1639 }
1640
1641 DEFPY (bgp_rpkt_quanta,
1642 bgp_rpkt_quanta_cmd,
1643 "[no] read-quanta (1-10)$quanta",
1644 NO_STR
1645 "How many packets to read from peer socket per I/O cycle\n"
1646 "Number of packets\n")
1647 {
1648 return bgp_rpkt_quanta_config_vty(vty, quanta, !no);
1649 }
1650
1651 void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
1652 {
1653 if (!bgp->heuristic_coalesce)
1654 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
1655 }
1656
1657
1658 DEFUN (bgp_coalesce_time,
1659 bgp_coalesce_time_cmd,
1660 "coalesce-time (0-4294967295)",
1661 "Subgroup coalesce timer\n"
1662 "Subgroup coalesce timer value (in ms)\n")
1663 {
1664 VTY_DECLVAR_CONTEXT(bgp, bgp);
1665
1666 int idx = 0;
1667 argv_find(argv, argc, "(0-4294967295)", &idx);
1668 bgp->heuristic_coalesce = false;
1669 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
1670 return CMD_SUCCESS;
1671 }
1672
1673 DEFUN (no_bgp_coalesce_time,
1674 no_bgp_coalesce_time_cmd,
1675 "no coalesce-time (0-4294967295)",
1676 NO_STR
1677 "Subgroup coalesce timer\n"
1678 "Subgroup coalesce timer value (in ms)\n")
1679 {
1680 VTY_DECLVAR_CONTEXT(bgp, bgp);
1681
1682 bgp->heuristic_coalesce = true;
1683 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
1684 return CMD_SUCCESS;
1685 }
1686
1687 /* Maximum-paths configuration */
1688 DEFUN (bgp_maxpaths,
1689 bgp_maxpaths_cmd,
1690 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1691 "Forward packets over multiple paths\n"
1692 "Number of paths\n")
1693 {
1694 int idx_number = 1;
1695 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
1696 argv[idx_number]->arg, 0, 1);
1697 }
1698
1699 ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
1700 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1701 "Forward packets over multiple paths\n"
1702 "Number of paths\n")
1703
1704 DEFUN (bgp_maxpaths_ibgp,
1705 bgp_maxpaths_ibgp_cmd,
1706 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1707 "Forward packets over multiple paths\n"
1708 "iBGP-multipath\n"
1709 "Number of paths\n")
1710 {
1711 int idx_number = 2;
1712 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
1713 argv[idx_number]->arg, 0, 1);
1714 }
1715
1716 ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
1717 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1718 "Forward packets over multiple paths\n"
1719 "iBGP-multipath\n"
1720 "Number of paths\n")
1721
1722 DEFUN (bgp_maxpaths_ibgp_cluster,
1723 bgp_maxpaths_ibgp_cluster_cmd,
1724 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
1725 "Forward packets over multiple paths\n"
1726 "iBGP-multipath\n"
1727 "Number of paths\n"
1728 "Match the cluster length\n")
1729 {
1730 int idx_number = 2;
1731 return bgp_maxpaths_config_vty(
1732 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
1733 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
1734 }
1735
1736 ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
1737 "maximum-paths ibgp " CMD_RANGE_STR(
1738 1, MULTIPATH_NUM) " equal-cluster-length",
1739 "Forward packets over multiple paths\n"
1740 "iBGP-multipath\n"
1741 "Number of paths\n"
1742 "Match the cluster length\n")
1743
1744 DEFUN (no_bgp_maxpaths,
1745 no_bgp_maxpaths_cmd,
1746 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
1747 NO_STR
1748 "Forward packets over multiple paths\n"
1749 "Number of paths\n")
1750 {
1751 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
1752 }
1753
1754 ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
1755 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
1756 "Forward packets over multiple paths\n"
1757 "Number of paths\n")
1758
1759 DEFUN (no_bgp_maxpaths_ibgp,
1760 no_bgp_maxpaths_ibgp_cmd,
1761 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
1762 NO_STR
1763 "Forward packets over multiple paths\n"
1764 "iBGP-multipath\n"
1765 "Number of paths\n"
1766 "Match the cluster length\n")
1767 {
1768 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
1769 }
1770
1771 ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
1772 "no maximum-paths ibgp [" CMD_RANGE_STR(
1773 1, MULTIPATH_NUM) " [equal-cluster-length]]",
1774 NO_STR
1775 "Forward packets over multiple paths\n"
1776 "iBGP-multipath\n"
1777 "Number of paths\n"
1778 "Match the cluster length\n")
1779
1780 void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp, afi_t afi,
1781 safi_t safi)
1782 {
1783 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != MULTIPATH_NUM) {
1784 vty_out(vty, " maximum-paths %d\n",
1785 bgp->maxpaths[afi][safi].maxpaths_ebgp);
1786 }
1787
1788 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != MULTIPATH_NUM) {
1789 vty_out(vty, " maximum-paths ibgp %d",
1790 bgp->maxpaths[afi][safi].maxpaths_ibgp);
1791 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
1792 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
1793 vty_out(vty, " equal-cluster-length");
1794 vty_out(vty, "\n");
1795 }
1796 }
1797
1798 /* BGP timers. */
1799
1800 DEFUN (bgp_timers,
1801 bgp_timers_cmd,
1802 "timers bgp (0-65535) (0-65535)",
1803 "Adjust routing timers\n"
1804 "BGP timers\n"
1805 "Keepalive interval\n"
1806 "Holdtime\n")
1807 {
1808 VTY_DECLVAR_CONTEXT(bgp, bgp);
1809 int idx_number = 2;
1810 int idx_number_2 = 3;
1811 unsigned long keepalive = 0;
1812 unsigned long holdtime = 0;
1813
1814 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
1815 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
1816
1817 /* Holdtime value check. */
1818 if (holdtime < 3 && holdtime != 0) {
1819 vty_out(vty,
1820 "%% hold time value must be either 0 or greater than 3\n");
1821 return CMD_WARNING_CONFIG_FAILED;
1822 }
1823
1824 bgp_timers_set(bgp, keepalive, holdtime);
1825
1826 return CMD_SUCCESS;
1827 }
1828
1829 DEFUN (no_bgp_timers,
1830 no_bgp_timers_cmd,
1831 "no timers bgp [(0-65535) (0-65535)]",
1832 NO_STR
1833 "Adjust routing timers\n"
1834 "BGP timers\n"
1835 "Keepalive interval\n"
1836 "Holdtime\n")
1837 {
1838 VTY_DECLVAR_CONTEXT(bgp, bgp);
1839 bgp_timers_unset(bgp);
1840
1841 return CMD_SUCCESS;
1842 }
1843
1844
1845 DEFUN (bgp_client_to_client_reflection,
1846 bgp_client_to_client_reflection_cmd,
1847 "bgp client-to-client reflection",
1848 "BGP specific commands\n"
1849 "Configure client to client route reflection\n"
1850 "reflection of routes allowed\n")
1851 {
1852 VTY_DECLVAR_CONTEXT(bgp, bgp);
1853 bgp_flag_unset(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1854 bgp_clear_star_soft_out(vty, bgp->name);
1855
1856 return CMD_SUCCESS;
1857 }
1858
1859 DEFUN (no_bgp_client_to_client_reflection,
1860 no_bgp_client_to_client_reflection_cmd,
1861 "no bgp client-to-client reflection",
1862 NO_STR
1863 "BGP specific commands\n"
1864 "Configure client to client route reflection\n"
1865 "reflection of routes allowed\n")
1866 {
1867 VTY_DECLVAR_CONTEXT(bgp, bgp);
1868 bgp_flag_set(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1869 bgp_clear_star_soft_out(vty, bgp->name);
1870
1871 return CMD_SUCCESS;
1872 }
1873
1874 /* "bgp always-compare-med" configuration. */
1875 DEFUN (bgp_always_compare_med,
1876 bgp_always_compare_med_cmd,
1877 "bgp always-compare-med",
1878 "BGP specific commands\n"
1879 "Allow comparing MED from different neighbors\n")
1880 {
1881 VTY_DECLVAR_CONTEXT(bgp, bgp);
1882 bgp_flag_set(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1883 bgp_recalculate_all_bestpaths(bgp);
1884
1885 return CMD_SUCCESS;
1886 }
1887
1888 DEFUN (no_bgp_always_compare_med,
1889 no_bgp_always_compare_med_cmd,
1890 "no bgp always-compare-med",
1891 NO_STR
1892 "BGP specific commands\n"
1893 "Allow comparing MED from different neighbors\n")
1894 {
1895 VTY_DECLVAR_CONTEXT(bgp, bgp);
1896 bgp_flag_unset(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1897 bgp_recalculate_all_bestpaths(bgp);
1898
1899 return CMD_SUCCESS;
1900 }
1901
1902
1903 DEFUN(bgp_ebgp_requires_policy, bgp_ebgp_requires_policy_cmd,
1904 "bgp ebgp-requires-policy",
1905 "BGP specific commands\n"
1906 "Require in and out policy for eBGP peers (RFC8212)\n")
1907 {
1908 VTY_DECLVAR_CONTEXT(bgp, bgp);
1909 bgp->ebgp_requires_policy = DEFAULT_EBGP_POLICY_ENABLED;
1910 return CMD_SUCCESS;
1911 }
1912
1913 DEFUN(no_bgp_ebgp_requires_policy, no_bgp_ebgp_requires_policy_cmd,
1914 "no bgp ebgp-requires-policy",
1915 NO_STR
1916 "BGP specific commands\n"
1917 "Require in and out policy for eBGP peers (RFC8212)\n")
1918 {
1919 VTY_DECLVAR_CONTEXT(bgp, bgp);
1920 bgp->ebgp_requires_policy = DEFAULT_EBGP_POLICY_DISABLED;
1921 return CMD_SUCCESS;
1922 }
1923
1924
1925 /* "bgp deterministic-med" configuration. */
1926 DEFUN (bgp_deterministic_med,
1927 bgp_deterministic_med_cmd,
1928 "bgp deterministic-med",
1929 "BGP specific commands\n"
1930 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1931 {
1932 VTY_DECLVAR_CONTEXT(bgp, bgp);
1933
1934 if (!bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1935 bgp_flag_set(bgp, BGP_FLAG_DETERMINISTIC_MED);
1936 bgp_recalculate_all_bestpaths(bgp);
1937 }
1938
1939 return CMD_SUCCESS;
1940 }
1941
1942 DEFUN (no_bgp_deterministic_med,
1943 no_bgp_deterministic_med_cmd,
1944 "no bgp deterministic-med",
1945 NO_STR
1946 "BGP specific commands\n"
1947 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1948 {
1949 VTY_DECLVAR_CONTEXT(bgp, bgp);
1950 int bestpath_per_as_used;
1951 afi_t afi;
1952 safi_t safi;
1953 struct peer *peer;
1954 struct listnode *node, *nnode;
1955
1956 if (bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1957 bestpath_per_as_used = 0;
1958
1959 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1960 FOREACH_AFI_SAFI (afi, safi)
1961 if (bgp_addpath_dmed_required(
1962 peer->addpath_type[afi][safi])) {
1963 bestpath_per_as_used = 1;
1964 break;
1965 }
1966
1967 if (bestpath_per_as_used)
1968 break;
1969 }
1970
1971 if (bestpath_per_as_used) {
1972 vty_out(vty,
1973 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
1974 return CMD_WARNING_CONFIG_FAILED;
1975 } else {
1976 bgp_flag_unset(bgp, BGP_FLAG_DETERMINISTIC_MED);
1977 bgp_recalculate_all_bestpaths(bgp);
1978 }
1979 }
1980
1981 return CMD_SUCCESS;
1982 }
1983
1984 /* "bgp graceful-restart" configuration. */
1985 DEFUN (bgp_graceful_restart,
1986 bgp_graceful_restart_cmd,
1987 "bgp graceful-restart",
1988 "BGP specific commands\n"
1989 "Graceful restart capability parameters\n")
1990 {
1991 VTY_DECLVAR_CONTEXT(bgp, bgp);
1992 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_RESTART);
1993 return CMD_SUCCESS;
1994 }
1995
1996 DEFUN (no_bgp_graceful_restart,
1997 no_bgp_graceful_restart_cmd,
1998 "no bgp graceful-restart",
1999 NO_STR
2000 "BGP specific commands\n"
2001 "Graceful restart capability parameters\n")
2002 {
2003 VTY_DECLVAR_CONTEXT(bgp, bgp);
2004 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_RESTART);
2005 return CMD_SUCCESS;
2006 }
2007
2008 DEFUN (bgp_graceful_restart_stalepath_time,
2009 bgp_graceful_restart_stalepath_time_cmd,
2010 "bgp graceful-restart stalepath-time (1-4095)",
2011 "BGP specific commands\n"
2012 "Graceful restart capability parameters\n"
2013 "Set the max time to hold onto restarting peer's stale paths\n"
2014 "Delay value (seconds)\n")
2015 {
2016 VTY_DECLVAR_CONTEXT(bgp, bgp);
2017 int idx_number = 3;
2018 uint32_t stalepath;
2019
2020 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2021 bgp->stalepath_time = stalepath;
2022 return CMD_SUCCESS;
2023 }
2024
2025 DEFUN (bgp_graceful_restart_restart_time,
2026 bgp_graceful_restart_restart_time_cmd,
2027 "bgp graceful-restart restart-time (1-4095)",
2028 "BGP specific commands\n"
2029 "Graceful restart capability parameters\n"
2030 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2031 "Delay value (seconds)\n")
2032 {
2033 VTY_DECLVAR_CONTEXT(bgp, bgp);
2034 int idx_number = 3;
2035 uint32_t restart;
2036
2037 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2038 bgp->restart_time = restart;
2039 return CMD_SUCCESS;
2040 }
2041
2042 DEFUN (no_bgp_graceful_restart_stalepath_time,
2043 no_bgp_graceful_restart_stalepath_time_cmd,
2044 "no bgp graceful-restart stalepath-time [(1-4095)]",
2045 NO_STR
2046 "BGP specific commands\n"
2047 "Graceful restart capability parameters\n"
2048 "Set the max time to hold onto restarting peer's stale paths\n"
2049 "Delay value (seconds)\n")
2050 {
2051 VTY_DECLVAR_CONTEXT(bgp, bgp);
2052
2053 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2054 return CMD_SUCCESS;
2055 }
2056
2057 DEFUN (no_bgp_graceful_restart_restart_time,
2058 no_bgp_graceful_restart_restart_time_cmd,
2059 "no bgp graceful-restart restart-time [(1-4095)]",
2060 NO_STR
2061 "BGP specific commands\n"
2062 "Graceful restart capability parameters\n"
2063 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2064 "Delay value (seconds)\n")
2065 {
2066 VTY_DECLVAR_CONTEXT(bgp, bgp);
2067
2068 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2069 return CMD_SUCCESS;
2070 }
2071
2072 DEFUN (bgp_graceful_restart_preserve_fw,
2073 bgp_graceful_restart_preserve_fw_cmd,
2074 "bgp graceful-restart preserve-fw-state",
2075 "BGP specific commands\n"
2076 "Graceful restart capability parameters\n"
2077 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
2078 {
2079 VTY_DECLVAR_CONTEXT(bgp, bgp);
2080 bgp_flag_set(bgp, BGP_FLAG_GR_PRESERVE_FWD);
2081 return CMD_SUCCESS;
2082 }
2083
2084 DEFUN (no_bgp_graceful_restart_preserve_fw,
2085 no_bgp_graceful_restart_preserve_fw_cmd,
2086 "no bgp graceful-restart preserve-fw-state",
2087 NO_STR
2088 "BGP specific commands\n"
2089 "Graceful restart capability parameters\n"
2090 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
2091 {
2092 VTY_DECLVAR_CONTEXT(bgp, bgp);
2093 bgp_flag_unset(bgp, BGP_FLAG_GR_PRESERVE_FWD);
2094 return CMD_SUCCESS;
2095 }
2096
2097 /* "bgp graceful-shutdown" configuration */
2098 DEFUN (bgp_graceful_shutdown,
2099 bgp_graceful_shutdown_cmd,
2100 "bgp graceful-shutdown",
2101 BGP_STR
2102 "Graceful shutdown parameters\n")
2103 {
2104 VTY_DECLVAR_CONTEXT(bgp, bgp);
2105
2106 if (!bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2107 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
2108 bgp_static_redo_import_check(bgp);
2109 bgp_redistribute_redo(bgp);
2110 bgp_clear_star_soft_out(vty, bgp->name);
2111 bgp_clear_star_soft_in(vty, bgp->name);
2112 }
2113
2114 return CMD_SUCCESS;
2115 }
2116
2117 DEFUN (no_bgp_graceful_shutdown,
2118 no_bgp_graceful_shutdown_cmd,
2119 "no bgp graceful-shutdown",
2120 NO_STR
2121 BGP_STR
2122 "Graceful shutdown parameters\n")
2123 {
2124 VTY_DECLVAR_CONTEXT(bgp, bgp);
2125
2126 if (bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2127 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
2128 bgp_static_redo_import_check(bgp);
2129 bgp_redistribute_redo(bgp);
2130 bgp_clear_star_soft_out(vty, bgp->name);
2131 bgp_clear_star_soft_in(vty, bgp->name);
2132 }
2133
2134 return CMD_SUCCESS;
2135 }
2136
2137 /* "bgp fast-external-failover" configuration. */
2138 DEFUN (bgp_fast_external_failover,
2139 bgp_fast_external_failover_cmd,
2140 "bgp fast-external-failover",
2141 BGP_STR
2142 "Immediately reset session if a link to a directly connected external peer goes down\n")
2143 {
2144 VTY_DECLVAR_CONTEXT(bgp, bgp);
2145 bgp_flag_unset(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2146 return CMD_SUCCESS;
2147 }
2148
2149 DEFUN (no_bgp_fast_external_failover,
2150 no_bgp_fast_external_failover_cmd,
2151 "no bgp fast-external-failover",
2152 NO_STR
2153 BGP_STR
2154 "Immediately reset session if a link to a directly connected external peer goes down\n")
2155 {
2156 VTY_DECLVAR_CONTEXT(bgp, bgp);
2157 bgp_flag_set(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2158 return CMD_SUCCESS;
2159 }
2160
2161 /* "bgp bestpath compare-routerid" configuration. */
2162 DEFUN (bgp_bestpath_compare_router_id,
2163 bgp_bestpath_compare_router_id_cmd,
2164 "bgp bestpath compare-routerid",
2165 "BGP specific commands\n"
2166 "Change the default bestpath selection\n"
2167 "Compare router-id for identical EBGP paths\n")
2168 {
2169 VTY_DECLVAR_CONTEXT(bgp, bgp);
2170 bgp_flag_set(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2171 bgp_recalculate_all_bestpaths(bgp);
2172
2173 return CMD_SUCCESS;
2174 }
2175
2176 DEFUN (no_bgp_bestpath_compare_router_id,
2177 no_bgp_bestpath_compare_router_id_cmd,
2178 "no bgp bestpath compare-routerid",
2179 NO_STR
2180 "BGP specific commands\n"
2181 "Change the default bestpath selection\n"
2182 "Compare router-id for identical EBGP paths\n")
2183 {
2184 VTY_DECLVAR_CONTEXT(bgp, bgp);
2185 bgp_flag_unset(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2186 bgp_recalculate_all_bestpaths(bgp);
2187
2188 return CMD_SUCCESS;
2189 }
2190
2191 /* "bgp bestpath as-path ignore" configuration. */
2192 DEFUN (bgp_bestpath_aspath_ignore,
2193 bgp_bestpath_aspath_ignore_cmd,
2194 "bgp bestpath as-path ignore",
2195 "BGP specific commands\n"
2196 "Change the default bestpath selection\n"
2197 "AS-path attribute\n"
2198 "Ignore as-path length in selecting a route\n")
2199 {
2200 VTY_DECLVAR_CONTEXT(bgp, bgp);
2201 bgp_flag_set(bgp, BGP_FLAG_ASPATH_IGNORE);
2202 bgp_recalculate_all_bestpaths(bgp);
2203
2204 return CMD_SUCCESS;
2205 }
2206
2207 DEFUN (no_bgp_bestpath_aspath_ignore,
2208 no_bgp_bestpath_aspath_ignore_cmd,
2209 "no bgp bestpath as-path ignore",
2210 NO_STR
2211 "BGP specific commands\n"
2212 "Change the default bestpath selection\n"
2213 "AS-path attribute\n"
2214 "Ignore as-path length in selecting a route\n")
2215 {
2216 VTY_DECLVAR_CONTEXT(bgp, bgp);
2217 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_IGNORE);
2218 bgp_recalculate_all_bestpaths(bgp);
2219
2220 return CMD_SUCCESS;
2221 }
2222
2223 /* "bgp bestpath as-path confed" configuration. */
2224 DEFUN (bgp_bestpath_aspath_confed,
2225 bgp_bestpath_aspath_confed_cmd,
2226 "bgp bestpath as-path confed",
2227 "BGP specific commands\n"
2228 "Change the default bestpath selection\n"
2229 "AS-path attribute\n"
2230 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2231 {
2232 VTY_DECLVAR_CONTEXT(bgp, bgp);
2233 bgp_flag_set(bgp, BGP_FLAG_ASPATH_CONFED);
2234 bgp_recalculate_all_bestpaths(bgp);
2235
2236 return CMD_SUCCESS;
2237 }
2238
2239 DEFUN (no_bgp_bestpath_aspath_confed,
2240 no_bgp_bestpath_aspath_confed_cmd,
2241 "no bgp bestpath as-path confed",
2242 NO_STR
2243 "BGP specific commands\n"
2244 "Change the default bestpath selection\n"
2245 "AS-path attribute\n"
2246 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2247 {
2248 VTY_DECLVAR_CONTEXT(bgp, bgp);
2249 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_CONFED);
2250 bgp_recalculate_all_bestpaths(bgp);
2251
2252 return CMD_SUCCESS;
2253 }
2254
2255 /* "bgp bestpath as-path multipath-relax" configuration. */
2256 DEFUN (bgp_bestpath_aspath_multipath_relax,
2257 bgp_bestpath_aspath_multipath_relax_cmd,
2258 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
2259 "BGP specific commands\n"
2260 "Change the default bestpath selection\n"
2261 "AS-path attribute\n"
2262 "Allow load sharing across routes that have different AS paths (but same length)\n"
2263 "Generate an AS_SET\n"
2264 "Do not generate an AS_SET\n")
2265 {
2266 VTY_DECLVAR_CONTEXT(bgp, bgp);
2267 int idx = 0;
2268 bgp_flag_set(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2269
2270 /* no-as-set is now the default behavior so we can silently
2271 * ignore it */
2272 if (argv_find(argv, argc, "as-set", &idx))
2273 bgp_flag_set(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2274 else
2275 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2276
2277 bgp_recalculate_all_bestpaths(bgp);
2278
2279 return CMD_SUCCESS;
2280 }
2281
2282 DEFUN (no_bgp_bestpath_aspath_multipath_relax,
2283 no_bgp_bestpath_aspath_multipath_relax_cmd,
2284 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
2285 NO_STR
2286 "BGP specific commands\n"
2287 "Change the default bestpath selection\n"
2288 "AS-path attribute\n"
2289 "Allow load sharing across routes that have different AS paths (but same length)\n"
2290 "Generate an AS_SET\n"
2291 "Do not generate an AS_SET\n")
2292 {
2293 VTY_DECLVAR_CONTEXT(bgp, bgp);
2294 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2295 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2296 bgp_recalculate_all_bestpaths(bgp);
2297
2298 return CMD_SUCCESS;
2299 }
2300
2301 /* "bgp log-neighbor-changes" configuration. */
2302 DEFUN (bgp_log_neighbor_changes,
2303 bgp_log_neighbor_changes_cmd,
2304 "bgp log-neighbor-changes",
2305 "BGP specific commands\n"
2306 "Log neighbor up/down and reset reason\n")
2307 {
2308 VTY_DECLVAR_CONTEXT(bgp, bgp);
2309 bgp_flag_set(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2310 return CMD_SUCCESS;
2311 }
2312
2313 DEFUN (no_bgp_log_neighbor_changes,
2314 no_bgp_log_neighbor_changes_cmd,
2315 "no bgp log-neighbor-changes",
2316 NO_STR
2317 "BGP specific commands\n"
2318 "Log neighbor up/down and reset reason\n")
2319 {
2320 VTY_DECLVAR_CONTEXT(bgp, bgp);
2321 bgp_flag_unset(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2322 return CMD_SUCCESS;
2323 }
2324
2325 /* "bgp bestpath med" configuration. */
2326 DEFUN (bgp_bestpath_med,
2327 bgp_bestpath_med_cmd,
2328 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
2329 "BGP specific commands\n"
2330 "Change the default bestpath selection\n"
2331 "MED attribute\n"
2332 "Compare MED among confederation paths\n"
2333 "Treat missing MED as the least preferred one\n"
2334 "Treat missing MED as the least preferred one\n"
2335 "Compare MED among confederation paths\n")
2336 {
2337 VTY_DECLVAR_CONTEXT(bgp, bgp);
2338
2339 int idx = 0;
2340 if (argv_find(argv, argc, "confed", &idx))
2341 bgp_flag_set(bgp, BGP_FLAG_MED_CONFED);
2342 idx = 0;
2343 if (argv_find(argv, argc, "missing-as-worst", &idx))
2344 bgp_flag_set(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
2345
2346 bgp_recalculate_all_bestpaths(bgp);
2347
2348 return CMD_SUCCESS;
2349 }
2350
2351 DEFUN (no_bgp_bestpath_med,
2352 no_bgp_bestpath_med_cmd,
2353 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
2354 NO_STR
2355 "BGP specific commands\n"
2356 "Change the default bestpath selection\n"
2357 "MED attribute\n"
2358 "Compare MED among confederation paths\n"
2359 "Treat missing MED as the least preferred one\n"
2360 "Treat missing MED as the least preferred one\n"
2361 "Compare MED among confederation paths\n")
2362 {
2363 VTY_DECLVAR_CONTEXT(bgp, bgp);
2364
2365 int idx = 0;
2366 if (argv_find(argv, argc, "confed", &idx))
2367 bgp_flag_unset(bgp, BGP_FLAG_MED_CONFED);
2368 idx = 0;
2369 if (argv_find(argv, argc, "missing-as-worst", &idx))
2370 bgp_flag_unset(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
2371
2372 bgp_recalculate_all_bestpaths(bgp);
2373
2374 return CMD_SUCCESS;
2375 }
2376
2377 /* "no bgp default ipv4-unicast". */
2378 DEFUN (no_bgp_default_ipv4_unicast,
2379 no_bgp_default_ipv4_unicast_cmd,
2380 "no bgp default ipv4-unicast",
2381 NO_STR
2382 "BGP specific commands\n"
2383 "Configure BGP defaults\n"
2384 "Activate ipv4-unicast for a peer by default\n")
2385 {
2386 VTY_DECLVAR_CONTEXT(bgp, bgp);
2387 bgp_flag_set(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2388 return CMD_SUCCESS;
2389 }
2390
2391 DEFUN (bgp_default_ipv4_unicast,
2392 bgp_default_ipv4_unicast_cmd,
2393 "bgp default ipv4-unicast",
2394 "BGP specific commands\n"
2395 "Configure BGP defaults\n"
2396 "Activate ipv4-unicast for a peer by default\n")
2397 {
2398 VTY_DECLVAR_CONTEXT(bgp, bgp);
2399 bgp_flag_unset(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2400 return CMD_SUCCESS;
2401 }
2402
2403 /* Display hostname in certain command outputs */
2404 DEFUN (bgp_default_show_hostname,
2405 bgp_default_show_hostname_cmd,
2406 "bgp default show-hostname",
2407 "BGP specific commands\n"
2408 "Configure BGP defaults\n"
2409 "Show hostname in certain command outputs\n")
2410 {
2411 VTY_DECLVAR_CONTEXT(bgp, bgp);
2412 bgp_flag_set(bgp, BGP_FLAG_SHOW_HOSTNAME);
2413 return CMD_SUCCESS;
2414 }
2415
2416 DEFUN (no_bgp_default_show_hostname,
2417 no_bgp_default_show_hostname_cmd,
2418 "no bgp default show-hostname",
2419 NO_STR
2420 "BGP specific commands\n"
2421 "Configure BGP defaults\n"
2422 "Show hostname in certain command outputs\n")
2423 {
2424 VTY_DECLVAR_CONTEXT(bgp, bgp);
2425 bgp_flag_unset(bgp, BGP_FLAG_SHOW_HOSTNAME);
2426 return CMD_SUCCESS;
2427 }
2428
2429 /* "bgp network import-check" configuration. */
2430 DEFUN (bgp_network_import_check,
2431 bgp_network_import_check_cmd,
2432 "bgp network import-check",
2433 "BGP specific commands\n"
2434 "BGP network command\n"
2435 "Check BGP network route exists in IGP\n")
2436 {
2437 VTY_DECLVAR_CONTEXT(bgp, bgp);
2438 if (!bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2439 bgp_flag_set(bgp, BGP_FLAG_IMPORT_CHECK);
2440 bgp_static_redo_import_check(bgp);
2441 }
2442
2443 return CMD_SUCCESS;
2444 }
2445
2446 ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
2447 "bgp network import-check exact",
2448 "BGP specific commands\n"
2449 "BGP network command\n"
2450 "Check BGP network route exists in IGP\n"
2451 "Match route precisely\n")
2452
2453 DEFUN (no_bgp_network_import_check,
2454 no_bgp_network_import_check_cmd,
2455 "no bgp network import-check",
2456 NO_STR
2457 "BGP specific commands\n"
2458 "BGP network command\n"
2459 "Check BGP network route exists in IGP\n")
2460 {
2461 VTY_DECLVAR_CONTEXT(bgp, bgp);
2462 if (bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2463 bgp_flag_unset(bgp, BGP_FLAG_IMPORT_CHECK);
2464 bgp_static_redo_import_check(bgp);
2465 }
2466
2467 return CMD_SUCCESS;
2468 }
2469
2470 DEFUN (bgp_default_local_preference,
2471 bgp_default_local_preference_cmd,
2472 "bgp default local-preference (0-4294967295)",
2473 "BGP specific commands\n"
2474 "Configure BGP defaults\n"
2475 "local preference (higher=more preferred)\n"
2476 "Configure default local preference value\n")
2477 {
2478 VTY_DECLVAR_CONTEXT(bgp, bgp);
2479 int idx_number = 3;
2480 uint32_t local_pref;
2481
2482 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
2483
2484 bgp_default_local_preference_set(bgp, local_pref);
2485 bgp_clear_star_soft_in(vty, bgp->name);
2486
2487 return CMD_SUCCESS;
2488 }
2489
2490 DEFUN (no_bgp_default_local_preference,
2491 no_bgp_default_local_preference_cmd,
2492 "no bgp default local-preference [(0-4294967295)]",
2493 NO_STR
2494 "BGP specific commands\n"
2495 "Configure BGP defaults\n"
2496 "local preference (higher=more preferred)\n"
2497 "Configure default local preference value\n")
2498 {
2499 VTY_DECLVAR_CONTEXT(bgp, bgp);
2500 bgp_default_local_preference_unset(bgp);
2501 bgp_clear_star_soft_in(vty, bgp->name);
2502
2503 return CMD_SUCCESS;
2504 }
2505
2506
2507 DEFUN (bgp_default_subgroup_pkt_queue_max,
2508 bgp_default_subgroup_pkt_queue_max_cmd,
2509 "bgp default subgroup-pkt-queue-max (20-100)",
2510 "BGP specific commands\n"
2511 "Configure BGP defaults\n"
2512 "subgroup-pkt-queue-max\n"
2513 "Configure subgroup packet queue max\n")
2514 {
2515 VTY_DECLVAR_CONTEXT(bgp, bgp);
2516 int idx_number = 3;
2517 uint32_t max_size;
2518
2519 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
2520
2521 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
2522
2523 return CMD_SUCCESS;
2524 }
2525
2526 DEFUN (no_bgp_default_subgroup_pkt_queue_max,
2527 no_bgp_default_subgroup_pkt_queue_max_cmd,
2528 "no bgp default subgroup-pkt-queue-max [(20-100)]",
2529 NO_STR
2530 "BGP specific commands\n"
2531 "Configure BGP defaults\n"
2532 "subgroup-pkt-queue-max\n"
2533 "Configure subgroup packet queue max\n")
2534 {
2535 VTY_DECLVAR_CONTEXT(bgp, bgp);
2536 bgp_default_subgroup_pkt_queue_max_unset(bgp);
2537 return CMD_SUCCESS;
2538 }
2539
2540
2541 DEFUN (bgp_rr_allow_outbound_policy,
2542 bgp_rr_allow_outbound_policy_cmd,
2543 "bgp route-reflector allow-outbound-policy",
2544 "BGP specific commands\n"
2545 "Allow modifications made by out route-map\n"
2546 "on ibgp neighbors\n")
2547 {
2548 VTY_DECLVAR_CONTEXT(bgp, bgp);
2549
2550 if (!bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2551 bgp_flag_set(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2552 update_group_announce_rrclients(bgp);
2553 bgp_clear_star_soft_out(vty, bgp->name);
2554 }
2555
2556 return CMD_SUCCESS;
2557 }
2558
2559 DEFUN (no_bgp_rr_allow_outbound_policy,
2560 no_bgp_rr_allow_outbound_policy_cmd,
2561 "no bgp route-reflector allow-outbound-policy",
2562 NO_STR
2563 "BGP specific commands\n"
2564 "Allow modifications made by out route-map\n"
2565 "on ibgp neighbors\n")
2566 {
2567 VTY_DECLVAR_CONTEXT(bgp, bgp);
2568
2569 if (bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2570 bgp_flag_unset(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2571 update_group_announce_rrclients(bgp);
2572 bgp_clear_star_soft_out(vty, bgp->name);
2573 }
2574
2575 return CMD_SUCCESS;
2576 }
2577
2578 DEFUN (bgp_listen_limit,
2579 bgp_listen_limit_cmd,
2580 "bgp listen limit (1-5000)",
2581 "BGP specific commands\n"
2582 "Configure BGP defaults\n"
2583 "maximum number of BGP Dynamic Neighbors that can be created\n"
2584 "Configure Dynamic Neighbors listen limit value\n")
2585 {
2586 VTY_DECLVAR_CONTEXT(bgp, bgp);
2587 int idx_number = 3;
2588 int listen_limit;
2589
2590 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
2591
2592 bgp_listen_limit_set(bgp, listen_limit);
2593
2594 return CMD_SUCCESS;
2595 }
2596
2597 DEFUN (no_bgp_listen_limit,
2598 no_bgp_listen_limit_cmd,
2599 "no bgp listen limit [(1-5000)]",
2600 "BGP specific commands\n"
2601 "Configure BGP defaults\n"
2602 "unset maximum number of BGP Dynamic Neighbors that can be created\n"
2603 "Configure Dynamic Neighbors listen limit value to default\n"
2604 "Configure Dynamic Neighbors listen limit value\n")
2605 {
2606 VTY_DECLVAR_CONTEXT(bgp, bgp);
2607 bgp_listen_limit_unset(bgp);
2608 return CMD_SUCCESS;
2609 }
2610
2611
2612 /*
2613 * Check if this listen range is already configured. Check for exact
2614 * match or overlap based on input.
2615 */
2616 static struct peer_group *listen_range_exists(struct bgp *bgp,
2617 struct prefix *range, int exact)
2618 {
2619 struct listnode *node, *nnode;
2620 struct listnode *node1, *nnode1;
2621 struct peer_group *group;
2622 struct prefix *lr;
2623 afi_t afi;
2624 int match;
2625
2626 afi = family2afi(range->family);
2627 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2628 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
2629 lr)) {
2630 if (exact)
2631 match = prefix_same(range, lr);
2632 else
2633 match = (prefix_match(range, lr)
2634 || prefix_match(lr, range));
2635 if (match)
2636 return group;
2637 }
2638 }
2639
2640 return NULL;
2641 }
2642
2643 DEFUN (bgp_listen_range,
2644 bgp_listen_range_cmd,
2645 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
2646 "BGP specific commands\n"
2647 "Configure BGP dynamic neighbors listen range\n"
2648 "Configure BGP dynamic neighbors listen range\n"
2649 NEIGHBOR_ADDR_STR
2650 "Member of the peer-group\n"
2651 "Peer-group name\n")
2652 {
2653 VTY_DECLVAR_CONTEXT(bgp, bgp);
2654 struct prefix range;
2655 struct peer_group *group, *existing_group;
2656 afi_t afi;
2657 int ret;
2658 int idx = 0;
2659
2660 argv_find(argv, argc, "A.B.C.D/M", &idx);
2661 argv_find(argv, argc, "X:X::X:X/M", &idx);
2662 char *prefix = argv[idx]->arg;
2663 argv_find(argv, argc, "PGNAME", &idx);
2664 char *peergroup = argv[idx]->arg;
2665
2666 /* Convert IP prefix string to struct prefix. */
2667 ret = str2prefix(prefix, &range);
2668 if (!ret) {
2669 vty_out(vty, "%% Malformed listen range\n");
2670 return CMD_WARNING_CONFIG_FAILED;
2671 }
2672
2673 afi = family2afi(range.family);
2674
2675 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2676 vty_out(vty,
2677 "%% Malformed listen range (link-local address)\n");
2678 return CMD_WARNING_CONFIG_FAILED;
2679 }
2680
2681 apply_mask(&range);
2682
2683 /* Check if same listen range is already configured. */
2684 existing_group = listen_range_exists(bgp, &range, 1);
2685 if (existing_group) {
2686 if (strcmp(existing_group->name, peergroup) == 0)
2687 return CMD_SUCCESS;
2688 else {
2689 vty_out(vty,
2690 "%% Same listen range is attached to peer-group %s\n",
2691 existing_group->name);
2692 return CMD_WARNING_CONFIG_FAILED;
2693 }
2694 }
2695
2696 /* Check if an overlapping listen range exists. */
2697 if (listen_range_exists(bgp, &range, 0)) {
2698 vty_out(vty,
2699 "%% Listen range overlaps with existing listen range\n");
2700 return CMD_WARNING_CONFIG_FAILED;
2701 }
2702
2703 group = peer_group_lookup(bgp, peergroup);
2704 if (!group) {
2705 vty_out(vty, "%% Configure the peer-group first\n");
2706 return CMD_WARNING_CONFIG_FAILED;
2707 }
2708
2709 ret = peer_group_listen_range_add(group, &range);
2710 return bgp_vty_return(vty, ret);
2711 }
2712
2713 DEFUN (no_bgp_listen_range,
2714 no_bgp_listen_range_cmd,
2715 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
2716 NO_STR
2717 "BGP specific commands\n"
2718 "Unconfigure BGP dynamic neighbors listen range\n"
2719 "Unconfigure BGP dynamic neighbors listen range\n"
2720 NEIGHBOR_ADDR_STR
2721 "Member of the peer-group\n"
2722 "Peer-group name\n")
2723 {
2724 VTY_DECLVAR_CONTEXT(bgp, bgp);
2725 struct prefix range;
2726 struct peer_group *group;
2727 afi_t afi;
2728 int ret;
2729 int idx = 0;
2730
2731 argv_find(argv, argc, "A.B.C.D/M", &idx);
2732 argv_find(argv, argc, "X:X::X:X/M", &idx);
2733 char *prefix = argv[idx]->arg;
2734 argv_find(argv, argc, "WORD", &idx);
2735 char *peergroup = argv[idx]->arg;
2736
2737 /* Convert IP prefix string to struct prefix. */
2738 ret = str2prefix(prefix, &range);
2739 if (!ret) {
2740 vty_out(vty, "%% Malformed listen range\n");
2741 return CMD_WARNING_CONFIG_FAILED;
2742 }
2743
2744 afi = family2afi(range.family);
2745
2746 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2747 vty_out(vty,
2748 "%% Malformed listen range (link-local address)\n");
2749 return CMD_WARNING_CONFIG_FAILED;
2750 }
2751
2752 apply_mask(&range);
2753
2754 group = peer_group_lookup(bgp, peergroup);
2755 if (!group) {
2756 vty_out(vty, "%% Peer-group does not exist\n");
2757 return CMD_WARNING_CONFIG_FAILED;
2758 }
2759
2760 ret = peer_group_listen_range_del(group, &range);
2761 return bgp_vty_return(vty, ret);
2762 }
2763
2764 void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
2765 {
2766 struct peer_group *group;
2767 struct listnode *node, *nnode, *rnode, *nrnode;
2768 struct prefix *range;
2769 afi_t afi;
2770 char buf[PREFIX2STR_BUFFER];
2771
2772 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
2773 vty_out(vty, " bgp listen limit %d\n",
2774 bgp->dynamic_neighbors_limit);
2775
2776 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2777 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
2778 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
2779 nrnode, range)) {
2780 prefix2str(range, buf, sizeof(buf));
2781 vty_out(vty,
2782 " bgp listen range %s peer-group %s\n",
2783 buf, group->name);
2784 }
2785 }
2786 }
2787 }
2788
2789
2790 DEFUN (bgp_disable_connected_route_check,
2791 bgp_disable_connected_route_check_cmd,
2792 "bgp disable-ebgp-connected-route-check",
2793 "BGP specific commands\n"
2794 "Disable checking if nexthop is connected on ebgp sessions\n")
2795 {
2796 VTY_DECLVAR_CONTEXT(bgp, bgp);
2797 bgp_flag_set(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2798 bgp_clear_star_soft_in(vty, bgp->name);
2799
2800 return CMD_SUCCESS;
2801 }
2802
2803 DEFUN (no_bgp_disable_connected_route_check,
2804 no_bgp_disable_connected_route_check_cmd,
2805 "no bgp disable-ebgp-connected-route-check",
2806 NO_STR
2807 "BGP specific commands\n"
2808 "Disable checking if nexthop is connected on ebgp sessions\n")
2809 {
2810 VTY_DECLVAR_CONTEXT(bgp, bgp);
2811 bgp_flag_unset(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2812 bgp_clear_star_soft_in(vty, bgp->name);
2813
2814 return CMD_SUCCESS;
2815 }
2816
2817
2818 static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
2819 const char *as_str, afi_t afi, safi_t safi)
2820 {
2821 VTY_DECLVAR_CONTEXT(bgp, bgp);
2822 int ret;
2823 as_t as;
2824 int as_type = AS_SPECIFIED;
2825 union sockunion su;
2826
2827 if (as_str[0] == 'i') {
2828 as = 0;
2829 as_type = AS_INTERNAL;
2830 } else if (as_str[0] == 'e') {
2831 as = 0;
2832 as_type = AS_EXTERNAL;
2833 } else {
2834 /* Get AS number. */
2835 as = strtoul(as_str, NULL, 10);
2836 }
2837
2838 /* If peer is peer group or interface peer, call proper function. */
2839 ret = str2sockunion(peer_str, &su);
2840 if (ret < 0) {
2841 struct peer *peer;
2842
2843 /* Check if existing interface peer */
2844 peer = peer_lookup_by_conf_if(bgp, peer_str);
2845
2846 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, afi,
2847 safi);
2848
2849 /* if not interface peer, check peer-group settings */
2850 if (ret < 0 && !peer) {
2851 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
2852 if (ret < 0) {
2853 vty_out(vty,
2854 "%% Create the peer-group or interface first\n");
2855 return CMD_WARNING_CONFIG_FAILED;
2856 }
2857 return CMD_SUCCESS;
2858 }
2859 } else {
2860 if (peer_address_self_check(bgp, &su)) {
2861 vty_out(vty,
2862 "%% Can not configure the local system as neighbor\n");
2863 return CMD_WARNING_CONFIG_FAILED;
2864 }
2865 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, afi, safi);
2866 }
2867
2868 /* This peer belongs to peer group. */
2869 switch (ret) {
2870 case BGP_ERR_PEER_GROUP_MEMBER:
2871 vty_out(vty,
2872 "%% Peer-group member cannot override remote-as of peer-group\n");
2873 return CMD_WARNING_CONFIG_FAILED;
2874 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
2875 vty_out(vty,
2876 "%% Peer-group members must be all internal or all external\n");
2877 return CMD_WARNING_CONFIG_FAILED;
2878 }
2879 return bgp_vty_return(vty, ret);
2880 }
2881
2882 DEFUN (bgp_default_shutdown,
2883 bgp_default_shutdown_cmd,
2884 "[no] bgp default shutdown",
2885 NO_STR
2886 BGP_STR
2887 "Configure BGP defaults\n"
2888 "Apply administrative shutdown to newly configured peers\n")
2889 {
2890 VTY_DECLVAR_CONTEXT(bgp, bgp);
2891 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
2892 return CMD_SUCCESS;
2893 }
2894
2895 DEFUN (neighbor_remote_as,
2896 neighbor_remote_as_cmd,
2897 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
2898 NEIGHBOR_STR
2899 NEIGHBOR_ADDR_STR2
2900 "Specify a BGP neighbor\n"
2901 AS_STR
2902 "Internal BGP peer\n"
2903 "External BGP peer\n")
2904 {
2905 int idx_peer = 1;
2906 int idx_remote_as = 3;
2907 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
2908 argv[idx_remote_as]->arg, AFI_IP,
2909 SAFI_UNICAST);
2910 }
2911
2912 static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
2913 afi_t afi, safi_t safi, int v6only,
2914 const char *peer_group_name,
2915 const char *as_str)
2916 {
2917 VTY_DECLVAR_CONTEXT(bgp, bgp);
2918 as_t as = 0;
2919 int as_type = AS_UNSPECIFIED;
2920 struct peer *peer;
2921 struct peer_group *group;
2922 int ret = 0;
2923 union sockunion su;
2924
2925 group = peer_group_lookup(bgp, conf_if);
2926
2927 if (group) {
2928 vty_out(vty, "%% Name conflict with peer-group \n");
2929 return CMD_WARNING_CONFIG_FAILED;
2930 }
2931
2932 if (as_str) {
2933 if (as_str[0] == 'i') {
2934 as_type = AS_INTERNAL;
2935 } else if (as_str[0] == 'e') {
2936 as_type = AS_EXTERNAL;
2937 } else {
2938 /* Get AS number. */
2939 as = strtoul(as_str, NULL, 10);
2940 as_type = AS_SPECIFIED;
2941 }
2942 }
2943
2944 peer = peer_lookup_by_conf_if(bgp, conf_if);
2945 if (peer) {
2946 if (as_str)
2947 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type,
2948 afi, safi);
2949 } else {
2950 if (bgp_flag_check(bgp, BGP_FLAG_NO_DEFAULT_IPV4)
2951 && afi == AFI_IP && safi == SAFI_UNICAST)
2952 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2953 as_type, 0, 0, NULL);
2954 else
2955 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2956 as_type, afi, safi, NULL);
2957
2958 if (!peer) {
2959 vty_out(vty, "%% BGP failed to create peer\n");
2960 return CMD_WARNING_CONFIG_FAILED;
2961 }
2962
2963 if (v6only)
2964 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
2965
2966 /* Request zebra to initiate IPv6 RAs on this interface. We do
2967 * this
2968 * any unnumbered peer in order to not worry about run-time
2969 * transitions
2970 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
2971 * address
2972 * gets deleted later etc.)
2973 */
2974 if (peer->ifp)
2975 bgp_zebra_initiate_radv(bgp, peer);
2976 }
2977
2978 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
2979 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
2980 if (v6only)
2981 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
2982 else
2983 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
2984
2985 /* v6only flag changed. Reset bgp seesion */
2986 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2987 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
2988 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2989 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2990 } else
2991 bgp_session_reset(peer);
2992 }
2993
2994 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
2995 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
2996 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
2997 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
2998 }
2999
3000 if (peer_group_name) {
3001 group = peer_group_lookup(bgp, peer_group_name);
3002 if (!group) {
3003 vty_out(vty, "%% Configure the peer-group first\n");
3004 return CMD_WARNING_CONFIG_FAILED;
3005 }
3006
3007 ret = peer_group_bind(bgp, &su, peer, group, &as);
3008 }
3009
3010 return bgp_vty_return(vty, ret);
3011 }
3012
3013 DEFUN (neighbor_interface_config,
3014 neighbor_interface_config_cmd,
3015 "neighbor WORD interface [peer-group PGNAME]",
3016 NEIGHBOR_STR
3017 "Interface name or neighbor tag\n"
3018 "Enable BGP on interface\n"
3019 "Member of the peer-group\n"
3020 "Peer-group name\n")
3021 {
3022 int idx_word = 1;
3023 int idx_peer_group_word = 4;
3024
3025 if (argc > idx_peer_group_word)
3026 return peer_conf_interface_get(
3027 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
3028 argv[idx_peer_group_word]->arg, NULL);
3029 else
3030 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3031 SAFI_UNICAST, 0, NULL, NULL);
3032 }
3033
3034 DEFUN (neighbor_interface_config_v6only,
3035 neighbor_interface_config_v6only_cmd,
3036 "neighbor WORD interface v6only [peer-group PGNAME]",
3037 NEIGHBOR_STR
3038 "Interface name or neighbor tag\n"
3039 "Enable BGP on interface\n"
3040 "Enable BGP with v6 link-local only\n"
3041 "Member of the peer-group\n"
3042 "Peer-group name\n")
3043 {
3044 int idx_word = 1;
3045 int idx_peer_group_word = 5;
3046
3047 if (argc > idx_peer_group_word)
3048 return peer_conf_interface_get(
3049 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
3050 argv[idx_peer_group_word]->arg, NULL);
3051
3052 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3053 SAFI_UNICAST, 1, NULL, NULL);
3054 }
3055
3056
3057 DEFUN (neighbor_interface_config_remote_as,
3058 neighbor_interface_config_remote_as_cmd,
3059 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
3060 NEIGHBOR_STR
3061 "Interface name or neighbor tag\n"
3062 "Enable BGP on interface\n"
3063 "Specify a BGP neighbor\n"
3064 AS_STR
3065 "Internal BGP peer\n"
3066 "External BGP peer\n")
3067 {
3068 int idx_word = 1;
3069 int idx_remote_as = 4;
3070 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3071 SAFI_UNICAST, 0, NULL,
3072 argv[idx_remote_as]->arg);
3073 }
3074
3075 DEFUN (neighbor_interface_v6only_config_remote_as,
3076 neighbor_interface_v6only_config_remote_as_cmd,
3077 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
3078 NEIGHBOR_STR
3079 "Interface name or neighbor tag\n"
3080 "Enable BGP with v6 link-local only\n"
3081 "Enable BGP on interface\n"
3082 "Specify a BGP neighbor\n"
3083 AS_STR
3084 "Internal BGP peer\n"
3085 "External BGP peer\n")
3086 {
3087 int idx_word = 1;
3088 int idx_remote_as = 5;
3089 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3090 SAFI_UNICAST, 1, NULL,
3091 argv[idx_remote_as]->arg);
3092 }
3093
3094 DEFUN (neighbor_peer_group,
3095 neighbor_peer_group_cmd,
3096 "neighbor WORD peer-group",
3097 NEIGHBOR_STR
3098 "Interface name or neighbor tag\n"
3099 "Configure peer-group\n")
3100 {
3101 VTY_DECLVAR_CONTEXT(bgp, bgp);
3102 int idx_word = 1;
3103 struct peer *peer;
3104 struct peer_group *group;
3105
3106 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3107 if (peer) {
3108 vty_out(vty, "%% Name conflict with interface: \n");
3109 return CMD_WARNING_CONFIG_FAILED;
3110 }
3111
3112 group = peer_group_get(bgp, argv[idx_word]->arg);
3113 if (!group) {
3114 vty_out(vty, "%% BGP failed to find or create peer-group\n");
3115 return CMD_WARNING_CONFIG_FAILED;
3116 }
3117
3118 return CMD_SUCCESS;
3119 }
3120
3121 DEFUN (no_neighbor,
3122 no_neighbor_cmd,
3123 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
3124 NO_STR
3125 NEIGHBOR_STR
3126 NEIGHBOR_ADDR_STR2
3127 "Specify a BGP neighbor\n"
3128 AS_STR
3129 "Internal BGP peer\n"
3130 "External BGP peer\n")
3131 {
3132 VTY_DECLVAR_CONTEXT(bgp, bgp);
3133 int idx_peer = 2;
3134 int ret;
3135 union sockunion su;
3136 struct peer_group *group;
3137 struct peer *peer;
3138 struct peer *other;
3139
3140 ret = str2sockunion(argv[idx_peer]->arg, &su);
3141 if (ret < 0) {
3142 /* look up for neighbor by interface name config. */
3143 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3144 if (peer) {
3145 /* Request zebra to terminate IPv6 RAs on this
3146 * interface. */
3147 if (peer->ifp)
3148 bgp_zebra_terminate_radv(peer->bgp, peer);
3149 peer_notify_unconfig(peer);
3150 peer_delete(peer);
3151 return CMD_SUCCESS;
3152 }
3153
3154 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
3155 if (group) {
3156 peer_group_notify_unconfig(group);
3157 peer_group_delete(group);
3158 } else {
3159 vty_out(vty, "%% Create the peer-group first\n");
3160 return CMD_WARNING_CONFIG_FAILED;
3161 }
3162 } else {
3163 peer = peer_lookup(bgp, &su);
3164 if (peer) {
3165 if (peer_dynamic_neighbor(peer)) {
3166 vty_out(vty,
3167 "%% Operation not allowed on a dynamic neighbor\n");
3168 return CMD_WARNING_CONFIG_FAILED;
3169 }
3170
3171 other = peer->doppelganger;
3172 peer_notify_unconfig(peer);
3173 peer_delete(peer);
3174 if (other && other->status != Deleted) {
3175 peer_notify_unconfig(other);
3176 peer_delete(other);
3177 }
3178 }
3179 }
3180
3181 return CMD_SUCCESS;
3182 }
3183
3184 DEFUN (no_neighbor_interface_config,
3185 no_neighbor_interface_config_cmd,
3186 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
3187 NO_STR
3188 NEIGHBOR_STR
3189 "Interface name\n"
3190 "Configure BGP on interface\n"
3191 "Enable BGP with v6 link-local only\n"
3192 "Member of the peer-group\n"
3193 "Peer-group name\n"
3194 "Specify a BGP neighbor\n"
3195 AS_STR
3196 "Internal BGP peer\n"
3197 "External BGP peer\n")
3198 {
3199 VTY_DECLVAR_CONTEXT(bgp, bgp);
3200 int idx_word = 2;
3201 struct peer *peer;
3202
3203 /* look up for neighbor by interface name config. */
3204 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3205 if (peer) {
3206 /* Request zebra to terminate IPv6 RAs on this interface. */
3207 if (peer->ifp)
3208 bgp_zebra_terminate_radv(peer->bgp, peer);
3209 peer_notify_unconfig(peer);
3210 peer_delete(peer);
3211 } else {
3212 vty_out(vty, "%% Create the bgp interface first\n");
3213 return CMD_WARNING_CONFIG_FAILED;
3214 }
3215 return CMD_SUCCESS;
3216 }
3217
3218 DEFUN (no_neighbor_peer_group,
3219 no_neighbor_peer_group_cmd,
3220 "no neighbor WORD peer-group",
3221 NO_STR
3222 NEIGHBOR_STR
3223 "Neighbor tag\n"
3224 "Configure peer-group\n")
3225 {
3226 VTY_DECLVAR_CONTEXT(bgp, bgp);
3227 int idx_word = 2;
3228 struct peer_group *group;
3229
3230 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3231 if (group) {
3232 peer_group_notify_unconfig(group);
3233 peer_group_delete(group);
3234 } else {
3235 vty_out(vty, "%% Create the peer-group first\n");
3236 return CMD_WARNING_CONFIG_FAILED;
3237 }
3238 return CMD_SUCCESS;
3239 }
3240
3241 DEFUN (no_neighbor_interface_peer_group_remote_as,
3242 no_neighbor_interface_peer_group_remote_as_cmd,
3243 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
3244 NO_STR
3245 NEIGHBOR_STR
3246 "Interface name or neighbor tag\n"
3247 "Specify a BGP neighbor\n"
3248 AS_STR
3249 "Internal BGP peer\n"
3250 "External BGP peer\n")
3251 {
3252 VTY_DECLVAR_CONTEXT(bgp, bgp);
3253 int idx_word = 2;
3254 struct peer_group *group;
3255 struct peer *peer;
3256
3257 /* look up for neighbor by interface name config. */
3258 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3259 if (peer) {
3260 peer_as_change(peer, 0, AS_UNSPECIFIED);
3261 return CMD_SUCCESS;
3262 }
3263
3264 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3265 if (group)
3266 peer_group_remote_as_delete(group);
3267 else {
3268 vty_out(vty, "%% Create the peer-group or interface first\n");
3269 return CMD_WARNING_CONFIG_FAILED;
3270 }
3271 return CMD_SUCCESS;
3272 }
3273
3274 DEFUN (neighbor_local_as,
3275 neighbor_local_as_cmd,
3276 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
3277 NEIGHBOR_STR
3278 NEIGHBOR_ADDR_STR2
3279 "Specify a local-as number\n"
3280 "AS number used as local AS\n")
3281 {
3282 int idx_peer = 1;
3283 int idx_number = 3;
3284 struct peer *peer;
3285 int ret;
3286 as_t as;
3287
3288 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3289 if (!peer)
3290 return CMD_WARNING_CONFIG_FAILED;
3291
3292 as = strtoul(argv[idx_number]->arg, NULL, 10);
3293 ret = peer_local_as_set(peer, as, 0, 0);
3294 return bgp_vty_return(vty, ret);
3295 }
3296
3297 DEFUN (neighbor_local_as_no_prepend,
3298 neighbor_local_as_no_prepend_cmd,
3299 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
3300 NEIGHBOR_STR
3301 NEIGHBOR_ADDR_STR2
3302 "Specify a local-as number\n"
3303 "AS number used as local AS\n"
3304 "Do not prepend local-as to updates from ebgp peers\n")
3305 {
3306 int idx_peer = 1;
3307 int idx_number = 3;
3308 struct peer *peer;
3309 int ret;
3310 as_t as;
3311
3312 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3313 if (!peer)
3314 return CMD_WARNING_CONFIG_FAILED;
3315
3316 as = strtoul(argv[idx_number]->arg, NULL, 10);
3317 ret = peer_local_as_set(peer, as, 1, 0);
3318 return bgp_vty_return(vty, ret);
3319 }
3320
3321 DEFUN (neighbor_local_as_no_prepend_replace_as,
3322 neighbor_local_as_no_prepend_replace_as_cmd,
3323 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
3324 NEIGHBOR_STR
3325 NEIGHBOR_ADDR_STR2
3326 "Specify a local-as number\n"
3327 "AS number used as local AS\n"
3328 "Do not prepend local-as to updates from ebgp peers\n"
3329 "Do not prepend local-as to updates from ibgp peers\n")
3330 {
3331 int idx_peer = 1;
3332 int idx_number = 3;
3333 struct peer *peer;
3334 int ret;
3335 as_t as;
3336
3337 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3338 if (!peer)
3339 return CMD_WARNING_CONFIG_FAILED;
3340
3341 as = strtoul(argv[idx_number]->arg, NULL, 10);
3342 ret = peer_local_as_set(peer, as, 1, 1);
3343 return bgp_vty_return(vty, ret);
3344 }
3345
3346 DEFUN (no_neighbor_local_as,
3347 no_neighbor_local_as_cmd,
3348 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
3349 NO_STR
3350 NEIGHBOR_STR
3351 NEIGHBOR_ADDR_STR2
3352 "Specify a local-as number\n"
3353 "AS number used as local AS\n"
3354 "Do not prepend local-as to updates from ebgp peers\n"
3355 "Do not prepend local-as to updates from ibgp peers\n")
3356 {
3357 int idx_peer = 2;
3358 struct peer *peer;
3359 int ret;
3360
3361 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3362 if (!peer)
3363 return CMD_WARNING_CONFIG_FAILED;
3364
3365 ret = peer_local_as_unset(peer);
3366 return bgp_vty_return(vty, ret);
3367 }
3368
3369
3370 DEFUN (neighbor_solo,
3371 neighbor_solo_cmd,
3372 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3373 NEIGHBOR_STR
3374 NEIGHBOR_ADDR_STR2
3375 "Solo peer - part of its own update group\n")
3376 {
3377 int idx_peer = 1;
3378 struct peer *peer;
3379 int ret;
3380
3381 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3382 if (!peer)
3383 return CMD_WARNING_CONFIG_FAILED;
3384
3385 ret = update_group_adjust_soloness(peer, 1);
3386 return bgp_vty_return(vty, ret);
3387 }
3388
3389 DEFUN (no_neighbor_solo,
3390 no_neighbor_solo_cmd,
3391 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3392 NO_STR
3393 NEIGHBOR_STR
3394 NEIGHBOR_ADDR_STR2
3395 "Solo peer - part of its own update group\n")
3396 {
3397 int idx_peer = 2;
3398 struct peer *peer;
3399 int ret;
3400
3401 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3402 if (!peer)
3403 return CMD_WARNING_CONFIG_FAILED;
3404
3405 ret = update_group_adjust_soloness(peer, 0);
3406 return bgp_vty_return(vty, ret);
3407 }
3408
3409 DEFUN (neighbor_password,
3410 neighbor_password_cmd,
3411 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
3412 NEIGHBOR_STR
3413 NEIGHBOR_ADDR_STR2
3414 "Set a password\n"
3415 "The password\n")
3416 {
3417 int idx_peer = 1;
3418 int idx_line = 3;
3419 struct peer *peer;
3420 int ret;
3421
3422 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3423 if (!peer)
3424 return CMD_WARNING_CONFIG_FAILED;
3425
3426 ret = peer_password_set(peer, argv[idx_line]->arg);
3427 return bgp_vty_return(vty, ret);
3428 }
3429
3430 DEFUN (no_neighbor_password,
3431 no_neighbor_password_cmd,
3432 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
3433 NO_STR
3434 NEIGHBOR_STR
3435 NEIGHBOR_ADDR_STR2
3436 "Set a password\n"
3437 "The password\n")
3438 {
3439 int idx_peer = 2;
3440 struct peer *peer;
3441 int ret;
3442
3443 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3444 if (!peer)
3445 return CMD_WARNING_CONFIG_FAILED;
3446
3447 ret = peer_password_unset(peer);
3448 return bgp_vty_return(vty, ret);
3449 }
3450
3451 DEFUN (neighbor_activate,
3452 neighbor_activate_cmd,
3453 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3454 NEIGHBOR_STR
3455 NEIGHBOR_ADDR_STR2
3456 "Enable the Address Family for this Neighbor\n")
3457 {
3458 int idx_peer = 1;
3459 int ret;
3460 struct peer *peer;
3461
3462 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3463 if (!peer)
3464 return CMD_WARNING_CONFIG_FAILED;
3465
3466 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3467 return bgp_vty_return(vty, ret);
3468 }
3469
3470 ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
3471 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3472 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3473 "Enable the Address Family for this Neighbor\n")
3474
3475 DEFUN (no_neighbor_activate,
3476 no_neighbor_activate_cmd,
3477 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3478 NO_STR
3479 NEIGHBOR_STR
3480 NEIGHBOR_ADDR_STR2
3481 "Enable the Address Family for this Neighbor\n")
3482 {
3483 int idx_peer = 2;
3484 int ret;
3485 struct peer *peer;
3486
3487 /* Lookup peer. */
3488 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3489 if (!peer)
3490 return CMD_WARNING_CONFIG_FAILED;
3491
3492 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3493 return bgp_vty_return(vty, ret);
3494 }
3495
3496 ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
3497 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3498 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3499 "Enable the Address Family for this Neighbor\n")
3500
3501 DEFUN (neighbor_set_peer_group,
3502 neighbor_set_peer_group_cmd,
3503 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
3504 NEIGHBOR_STR
3505 NEIGHBOR_ADDR_STR2
3506 "Member of the peer-group\n"
3507 "Peer-group name\n")
3508 {
3509 VTY_DECLVAR_CONTEXT(bgp, bgp);
3510 int idx_peer = 1;
3511 int idx_word = 3;
3512 int ret;
3513 as_t as;
3514 union sockunion su;
3515 struct peer *peer;
3516 struct peer_group *group;
3517
3518 ret = str2sockunion(argv[idx_peer]->arg, &su);
3519 if (ret < 0) {
3520 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3521 if (!peer) {
3522 vty_out(vty, "%% Malformed address or name: %s\n",
3523 argv[idx_peer]->arg);
3524 return CMD_WARNING_CONFIG_FAILED;
3525 }
3526 } else {
3527 if (peer_address_self_check(bgp, &su)) {
3528 vty_out(vty,
3529 "%% Can not configure the local system as neighbor\n");
3530 return CMD_WARNING_CONFIG_FAILED;
3531 }
3532
3533 /* Disallow for dynamic neighbor. */
3534 peer = peer_lookup(bgp, &su);
3535 if (peer && peer_dynamic_neighbor(peer)) {
3536 vty_out(vty,
3537 "%% Operation not allowed on a dynamic neighbor\n");
3538 return CMD_WARNING_CONFIG_FAILED;
3539 }
3540 }
3541
3542 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3543 if (!group) {
3544 vty_out(vty, "%% Configure the peer-group first\n");
3545 return CMD_WARNING_CONFIG_FAILED;
3546 }
3547
3548 ret = peer_group_bind(bgp, &su, peer, group, &as);
3549
3550 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
3551 vty_out(vty,
3552 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
3553 as);
3554 return CMD_WARNING_CONFIG_FAILED;
3555 }
3556
3557 return bgp_vty_return(vty, ret);
3558 }
3559
3560 ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
3561 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
3562 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3563 "Member of the peer-group\n"
3564 "Peer-group name\n")
3565
3566 DEFUN (no_neighbor_set_peer_group,
3567 no_neighbor_set_peer_group_cmd,
3568 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
3569 NO_STR
3570 NEIGHBOR_STR
3571 NEIGHBOR_ADDR_STR2
3572 "Member of the peer-group\n"
3573 "Peer-group name\n")
3574 {
3575 VTY_DECLVAR_CONTEXT(bgp, bgp);
3576 int idx_peer = 2;
3577 int idx_word = 4;
3578 int ret;
3579 struct peer *peer;
3580 struct peer_group *group;
3581
3582 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
3583 if (!peer)
3584 return CMD_WARNING_CONFIG_FAILED;
3585
3586 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3587 if (!group) {
3588 vty_out(vty, "%% Configure the peer-group first\n");
3589 return CMD_WARNING_CONFIG_FAILED;
3590 }
3591
3592 peer_notify_unconfig(peer);
3593 ret = peer_delete(peer);
3594
3595 return bgp_vty_return(vty, ret);
3596 }
3597
3598 ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
3599 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
3600 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3601 "Member of the peer-group\n"
3602 "Peer-group name\n")
3603
3604 static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
3605 uint32_t flag, int set)
3606 {
3607 int ret;
3608 struct peer *peer;
3609
3610 peer = peer_and_group_lookup_vty(vty, ip_str);
3611 if (!peer)
3612 return CMD_WARNING_CONFIG_FAILED;
3613
3614 /*
3615 * If 'neighbor <interface>', then this is for directly connected peers,
3616 * we should not accept disable-connected-check.
3617 */
3618 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
3619 vty_out(vty,
3620 "%s is directly connected peer, cannot accept disable-"
3621 "connected-check\n",
3622 ip_str);
3623 return CMD_WARNING_CONFIG_FAILED;
3624 }
3625
3626 if (!set && flag == PEER_FLAG_SHUTDOWN)
3627 peer_tx_shutdown_message_unset(peer);
3628
3629 if (set)
3630 ret = peer_flag_set(peer, flag);
3631 else
3632 ret = peer_flag_unset(peer, flag);
3633
3634 return bgp_vty_return(vty, ret);
3635 }
3636
3637 static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
3638 {
3639 return peer_flag_modify_vty(vty, ip_str, flag, 1);
3640 }
3641
3642 static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
3643 uint32_t flag)
3644 {
3645 return peer_flag_modify_vty(vty, ip_str, flag, 0);
3646 }
3647
3648 /* neighbor passive. */
3649 DEFUN (neighbor_passive,
3650 neighbor_passive_cmd,
3651 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
3652 NEIGHBOR_STR
3653 NEIGHBOR_ADDR_STR2
3654 "Don't send open messages to this neighbor\n")
3655 {
3656 int idx_peer = 1;
3657 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
3658 }
3659
3660 DEFUN (no_neighbor_passive,
3661 no_neighbor_passive_cmd,
3662 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
3663 NO_STR
3664 NEIGHBOR_STR
3665 NEIGHBOR_ADDR_STR2
3666 "Don't send open messages to this neighbor\n")
3667 {
3668 int idx_peer = 2;
3669 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
3670 }
3671
3672 /* neighbor shutdown. */
3673 DEFUN (neighbor_shutdown_msg,
3674 neighbor_shutdown_msg_cmd,
3675 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3676 NEIGHBOR_STR
3677 NEIGHBOR_ADDR_STR2
3678 "Administratively shut down this neighbor\n"
3679 "Add a shutdown message (draft-ietf-idr-shutdown-06)\n"
3680 "Shutdown message\n")
3681 {
3682 int idx_peer = 1;
3683
3684 if (argc >= 5) {
3685 struct peer *peer =
3686 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3687 char *message;
3688
3689 if (!peer)
3690 return CMD_WARNING_CONFIG_FAILED;
3691 message = argv_concat(argv, argc, 4);
3692 peer_tx_shutdown_message_set(peer, message);
3693 XFREE(MTYPE_TMP, message);
3694 }
3695
3696 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
3697 }
3698
3699 ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
3700 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3701 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3702 "Administratively shut down this neighbor\n")
3703
3704 DEFUN (no_neighbor_shutdown_msg,
3705 no_neighbor_shutdown_msg_cmd,
3706 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3707 NO_STR
3708 NEIGHBOR_STR
3709 NEIGHBOR_ADDR_STR2
3710 "Administratively shut down this neighbor\n"
3711 "Remove a shutdown message (draft-ietf-idr-shutdown-06)\n"
3712 "Shutdown message\n")
3713 {
3714 int idx_peer = 2;
3715
3716 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3717 PEER_FLAG_SHUTDOWN);
3718 }
3719
3720 ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
3721 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3722 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3723 "Administratively shut down this neighbor\n")
3724
3725 /* neighbor capability dynamic. */
3726 DEFUN (neighbor_capability_dynamic,
3727 neighbor_capability_dynamic_cmd,
3728 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
3729 NEIGHBOR_STR
3730 NEIGHBOR_ADDR_STR2
3731 "Advertise capability to the peer\n"
3732 "Advertise dynamic capability to this neighbor\n")
3733 {
3734 int idx_peer = 1;
3735 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3736 PEER_FLAG_DYNAMIC_CAPABILITY);
3737 }
3738
3739 DEFUN (no_neighbor_capability_dynamic,
3740 no_neighbor_capability_dynamic_cmd,
3741 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
3742 NO_STR
3743 NEIGHBOR_STR
3744 NEIGHBOR_ADDR_STR2
3745 "Advertise capability to the peer\n"
3746 "Advertise dynamic capability to this neighbor\n")
3747 {
3748 int idx_peer = 2;
3749 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3750 PEER_FLAG_DYNAMIC_CAPABILITY);
3751 }
3752
3753 /* neighbor dont-capability-negotiate */
3754 DEFUN (neighbor_dont_capability_negotiate,
3755 neighbor_dont_capability_negotiate_cmd,
3756 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
3757 NEIGHBOR_STR
3758 NEIGHBOR_ADDR_STR2
3759 "Do not perform capability negotiation\n")
3760 {
3761 int idx_peer = 1;
3762 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3763 PEER_FLAG_DONT_CAPABILITY);
3764 }
3765
3766 DEFUN (no_neighbor_dont_capability_negotiate,
3767 no_neighbor_dont_capability_negotiate_cmd,
3768 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
3769 NO_STR
3770 NEIGHBOR_STR
3771 NEIGHBOR_ADDR_STR2
3772 "Do not perform capability negotiation\n")
3773 {
3774 int idx_peer = 2;
3775 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3776 PEER_FLAG_DONT_CAPABILITY);
3777 }
3778
3779 /* neighbor capability extended next hop encoding */
3780 DEFUN (neighbor_capability_enhe,
3781 neighbor_capability_enhe_cmd,
3782 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
3783 NEIGHBOR_STR
3784 NEIGHBOR_ADDR_STR2
3785 "Advertise capability to the peer\n"
3786 "Advertise extended next-hop capability to the peer\n")
3787 {
3788 int idx_peer = 1;
3789 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3790 PEER_FLAG_CAPABILITY_ENHE);
3791 }
3792
3793 DEFUN (no_neighbor_capability_enhe,
3794 no_neighbor_capability_enhe_cmd,
3795 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
3796 NO_STR
3797 NEIGHBOR_STR
3798 NEIGHBOR_ADDR_STR2
3799 "Advertise capability to the peer\n"
3800 "Advertise extended next-hop capability to the peer\n")
3801 {
3802 int idx_peer = 2;
3803 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3804 PEER_FLAG_CAPABILITY_ENHE);
3805 }
3806
3807 static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
3808 afi_t afi, safi_t safi, uint32_t flag,
3809 int set)
3810 {
3811 int ret;
3812 struct peer *peer;
3813
3814 peer = peer_and_group_lookup_vty(vty, peer_str);
3815 if (!peer)
3816 return CMD_WARNING_CONFIG_FAILED;
3817
3818 if (set)
3819 ret = peer_af_flag_set(peer, afi, safi, flag);
3820 else
3821 ret = peer_af_flag_unset(peer, afi, safi, flag);
3822
3823 return bgp_vty_return(vty, ret);
3824 }
3825
3826 static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
3827 afi_t afi, safi_t safi, uint32_t flag)
3828 {
3829 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
3830 }
3831
3832 static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
3833 afi_t afi, safi_t safi, uint32_t flag)
3834 {
3835 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
3836 }
3837
3838 /* neighbor capability orf prefix-list. */
3839 DEFUN (neighbor_capability_orf_prefix,
3840 neighbor_capability_orf_prefix_cmd,
3841 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3842 NEIGHBOR_STR
3843 NEIGHBOR_ADDR_STR2
3844 "Advertise capability to the peer\n"
3845 "Advertise ORF capability to the peer\n"
3846 "Advertise prefixlist ORF capability to this neighbor\n"
3847 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3848 "Capability to RECEIVE the ORF from this neighbor\n"
3849 "Capability to SEND the ORF to this neighbor\n")
3850 {
3851 int idx_peer = 1;
3852 int idx_send_recv = 5;
3853 uint16_t flag = 0;
3854
3855 if (strmatch(argv[idx_send_recv]->text, "send"))
3856 flag = PEER_FLAG_ORF_PREFIX_SM;
3857 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3858 flag = PEER_FLAG_ORF_PREFIX_RM;
3859 else if (strmatch(argv[idx_send_recv]->text, "both"))
3860 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3861 else {
3862 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3863 return CMD_WARNING_CONFIG_FAILED;
3864 }
3865
3866 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3867 bgp_node_safi(vty), flag);
3868 }
3869
3870 ALIAS_HIDDEN(
3871 neighbor_capability_orf_prefix,
3872 neighbor_capability_orf_prefix_hidden_cmd,
3873 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3874 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3875 "Advertise capability to the peer\n"
3876 "Advertise ORF capability to the peer\n"
3877 "Advertise prefixlist ORF capability to this neighbor\n"
3878 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3879 "Capability to RECEIVE the ORF from this neighbor\n"
3880 "Capability to SEND the ORF to this neighbor\n")
3881
3882 DEFUN (no_neighbor_capability_orf_prefix,
3883 no_neighbor_capability_orf_prefix_cmd,
3884 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3885 NO_STR
3886 NEIGHBOR_STR
3887 NEIGHBOR_ADDR_STR2
3888 "Advertise capability to the peer\n"
3889 "Advertise ORF capability to the peer\n"
3890 "Advertise prefixlist ORF capability to this neighbor\n"
3891 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3892 "Capability to RECEIVE the ORF from this neighbor\n"
3893 "Capability to SEND the ORF to this neighbor\n")
3894 {
3895 int idx_peer = 2;
3896 int idx_send_recv = 6;
3897 uint16_t flag = 0;
3898
3899 if (strmatch(argv[idx_send_recv]->text, "send"))
3900 flag = PEER_FLAG_ORF_PREFIX_SM;
3901 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3902 flag = PEER_FLAG_ORF_PREFIX_RM;
3903 else if (strmatch(argv[idx_send_recv]->text, "both"))
3904 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3905 else {
3906 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3907 return CMD_WARNING_CONFIG_FAILED;
3908 }
3909
3910 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3911 bgp_node_afi(vty), bgp_node_safi(vty),
3912 flag);
3913 }
3914
3915 ALIAS_HIDDEN(
3916 no_neighbor_capability_orf_prefix,
3917 no_neighbor_capability_orf_prefix_hidden_cmd,
3918 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3919 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3920 "Advertise capability to the peer\n"
3921 "Advertise ORF capability to the peer\n"
3922 "Advertise prefixlist ORF capability to this neighbor\n"
3923 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3924 "Capability to RECEIVE the ORF from this neighbor\n"
3925 "Capability to SEND the ORF to this neighbor\n")
3926
3927 /* neighbor next-hop-self. */
3928 DEFUN (neighbor_nexthop_self,
3929 neighbor_nexthop_self_cmd,
3930 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3931 NEIGHBOR_STR
3932 NEIGHBOR_ADDR_STR2
3933 "Disable the next hop calculation for this neighbor\n")
3934 {
3935 int idx_peer = 1;
3936 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3937 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
3938 }
3939
3940 ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
3941 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3942 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3943 "Disable the next hop calculation for this neighbor\n")
3944
3945 /* neighbor next-hop-self. */
3946 DEFUN (neighbor_nexthop_self_force,
3947 neighbor_nexthop_self_force_cmd,
3948 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3949 NEIGHBOR_STR
3950 NEIGHBOR_ADDR_STR2
3951 "Disable the next hop calculation for this neighbor\n"
3952 "Set the next hop to self for reflected routes\n")
3953 {
3954 int idx_peer = 1;
3955 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3956 bgp_node_safi(vty),
3957 PEER_FLAG_FORCE_NEXTHOP_SELF);
3958 }
3959
3960 ALIAS_HIDDEN(neighbor_nexthop_self_force,
3961 neighbor_nexthop_self_force_hidden_cmd,
3962 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3963 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3964 "Disable the next hop calculation for this neighbor\n"
3965 "Set the next hop to self for reflected routes\n")
3966
3967 ALIAS_HIDDEN(neighbor_nexthop_self_force,
3968 neighbor_nexthop_self_all_hidden_cmd,
3969 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
3970 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3971 "Disable the next hop calculation for this neighbor\n"
3972 "Set the next hop to self for reflected routes\n")
3973
3974 DEFUN (no_neighbor_nexthop_self,
3975 no_neighbor_nexthop_self_cmd,
3976 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3977 NO_STR
3978 NEIGHBOR_STR
3979 NEIGHBOR_ADDR_STR2
3980 "Disable the next hop calculation for this neighbor\n")
3981 {
3982 int idx_peer = 2;
3983 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3984 bgp_node_afi(vty), bgp_node_safi(vty),
3985 PEER_FLAG_NEXTHOP_SELF);
3986 }
3987
3988 ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
3989 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3990 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3991 "Disable the next hop calculation for this neighbor\n")
3992
3993 DEFUN (no_neighbor_nexthop_self_force,
3994 no_neighbor_nexthop_self_force_cmd,
3995 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3996 NO_STR
3997 NEIGHBOR_STR
3998 NEIGHBOR_ADDR_STR2
3999 "Disable the next hop calculation for this neighbor\n"
4000 "Set the next hop to self for reflected routes\n")
4001 {
4002 int idx_peer = 2;
4003 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4004 bgp_node_afi(vty), bgp_node_safi(vty),
4005 PEER_FLAG_FORCE_NEXTHOP_SELF);
4006 }
4007
4008 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
4009 no_neighbor_nexthop_self_force_hidden_cmd,
4010 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
4011 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4012 "Disable the next hop calculation for this neighbor\n"
4013 "Set the next hop to self for reflected routes\n")
4014
4015 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
4016 no_neighbor_nexthop_self_all_hidden_cmd,
4017 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
4018 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4019 "Disable the next hop calculation for this neighbor\n"
4020 "Set the next hop to self for reflected routes\n")
4021
4022 /* neighbor as-override */
4023 DEFUN (neighbor_as_override,
4024 neighbor_as_override_cmd,
4025 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4026 NEIGHBOR_STR
4027 NEIGHBOR_ADDR_STR2
4028 "Override ASNs in outbound updates if aspath equals remote-as\n")
4029 {
4030 int idx_peer = 1;
4031 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4032 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
4033 }
4034
4035 ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
4036 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4037 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4038 "Override ASNs in outbound updates if aspath equals remote-as\n")
4039
4040 DEFUN (no_neighbor_as_override,
4041 no_neighbor_as_override_cmd,
4042 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4043 NO_STR
4044 NEIGHBOR_STR
4045 NEIGHBOR_ADDR_STR2
4046 "Override ASNs in outbound updates if aspath equals remote-as\n")
4047 {
4048 int idx_peer = 2;
4049 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4050 bgp_node_afi(vty), bgp_node_safi(vty),
4051 PEER_FLAG_AS_OVERRIDE);
4052 }
4053
4054 ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
4055 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4056 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4057 "Override ASNs in outbound updates if aspath equals remote-as\n")
4058
4059 /* neighbor remove-private-AS. */
4060 DEFUN (neighbor_remove_private_as,
4061 neighbor_remove_private_as_cmd,
4062 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4063 NEIGHBOR_STR
4064 NEIGHBOR_ADDR_STR2
4065 "Remove private ASNs in outbound updates\n")
4066 {
4067 int idx_peer = 1;
4068 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4069 bgp_node_safi(vty),
4070 PEER_FLAG_REMOVE_PRIVATE_AS);
4071 }
4072
4073 ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
4074 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4075 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4076 "Remove private ASNs in outbound updates\n")
4077
4078 DEFUN (neighbor_remove_private_as_all,
4079 neighbor_remove_private_as_all_cmd,
4080 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4081 NEIGHBOR_STR
4082 NEIGHBOR_ADDR_STR2
4083 "Remove private ASNs in outbound updates\n"
4084 "Apply to all AS numbers\n")
4085 {
4086 int idx_peer = 1;
4087 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4088 bgp_node_safi(vty),
4089 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
4090 }
4091
4092 ALIAS_HIDDEN(neighbor_remove_private_as_all,
4093 neighbor_remove_private_as_all_hidden_cmd,
4094 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4095 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4096 "Remove private ASNs in outbound updates\n"
4097 "Apply to all AS numbers")
4098
4099 DEFUN (neighbor_remove_private_as_replace_as,
4100 neighbor_remove_private_as_replace_as_cmd,
4101 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4102 NEIGHBOR_STR
4103 NEIGHBOR_ADDR_STR2
4104 "Remove private ASNs in outbound updates\n"
4105 "Replace private ASNs with our ASN in outbound updates\n")
4106 {
4107 int idx_peer = 1;
4108 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4109 bgp_node_safi(vty),
4110 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
4111 }
4112
4113 ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
4114 neighbor_remove_private_as_replace_as_hidden_cmd,
4115 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4116 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4117 "Remove private ASNs in outbound updates\n"
4118 "Replace private ASNs with our ASN in outbound updates\n")
4119
4120 DEFUN (neighbor_remove_private_as_all_replace_as,
4121 neighbor_remove_private_as_all_replace_as_cmd,
4122 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4123 NEIGHBOR_STR
4124 NEIGHBOR_ADDR_STR2
4125 "Remove private ASNs in outbound updates\n"
4126 "Apply to all AS numbers\n"
4127 "Replace private ASNs with our ASN in outbound updates\n")
4128 {
4129 int idx_peer = 1;
4130 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4131 bgp_node_safi(vty),
4132 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
4133 }
4134
4135 ALIAS_HIDDEN(
4136 neighbor_remove_private_as_all_replace_as,
4137 neighbor_remove_private_as_all_replace_as_hidden_cmd,
4138 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4139 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4140 "Remove private ASNs in outbound updates\n"
4141 "Apply to all AS numbers\n"
4142 "Replace private ASNs with our ASN in outbound updates\n")
4143
4144 DEFUN (no_neighbor_remove_private_as,
4145 no_neighbor_remove_private_as_cmd,
4146 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4147 NO_STR
4148 NEIGHBOR_STR
4149 NEIGHBOR_ADDR_STR2
4150 "Remove private ASNs in outbound updates\n")
4151 {
4152 int idx_peer = 2;
4153 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4154 bgp_node_afi(vty), bgp_node_safi(vty),
4155 PEER_FLAG_REMOVE_PRIVATE_AS);
4156 }
4157
4158 ALIAS_HIDDEN(no_neighbor_remove_private_as,
4159 no_neighbor_remove_private_as_hidden_cmd,
4160 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4161 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4162 "Remove private ASNs in outbound updates\n")
4163
4164 DEFUN (no_neighbor_remove_private_as_all,
4165 no_neighbor_remove_private_as_all_cmd,
4166 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4167 NO_STR
4168 NEIGHBOR_STR
4169 NEIGHBOR_ADDR_STR2
4170 "Remove private ASNs in outbound updates\n"
4171 "Apply to all AS numbers\n")
4172 {
4173 int idx_peer = 2;
4174 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4175 bgp_node_afi(vty), bgp_node_safi(vty),
4176 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
4177 }
4178
4179 ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
4180 no_neighbor_remove_private_as_all_hidden_cmd,
4181 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4182 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4183 "Remove private ASNs in outbound updates\n"
4184 "Apply to all AS numbers\n")
4185
4186 DEFUN (no_neighbor_remove_private_as_replace_as,
4187 no_neighbor_remove_private_as_replace_as_cmd,
4188 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4189 NO_STR
4190 NEIGHBOR_STR
4191 NEIGHBOR_ADDR_STR2
4192 "Remove private ASNs in outbound updates\n"
4193 "Replace private ASNs with our ASN in outbound updates\n")
4194 {
4195 int idx_peer = 2;
4196 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4197 bgp_node_afi(vty), bgp_node_safi(vty),
4198 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
4199 }
4200
4201 ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
4202 no_neighbor_remove_private_as_replace_as_hidden_cmd,
4203 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4204 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4205 "Remove private ASNs in outbound updates\n"
4206 "Replace private ASNs with our ASN in outbound updates\n")
4207
4208 DEFUN (no_neighbor_remove_private_as_all_replace_as,
4209 no_neighbor_remove_private_as_all_replace_as_cmd,
4210 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4211 NO_STR
4212 NEIGHBOR_STR
4213 NEIGHBOR_ADDR_STR2
4214 "Remove private ASNs in outbound updates\n"
4215 "Apply to all AS numbers\n"
4216 "Replace private ASNs with our ASN in outbound updates\n")
4217 {
4218 int idx_peer = 2;
4219 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4220 bgp_node_afi(vty), bgp_node_safi(vty),
4221 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
4222 }
4223
4224 ALIAS_HIDDEN(
4225 no_neighbor_remove_private_as_all_replace_as,
4226 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
4227 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4228 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4229 "Remove private ASNs in outbound updates\n"
4230 "Apply to all AS numbers\n"
4231 "Replace private ASNs with our ASN in outbound updates\n")
4232
4233
4234 /* neighbor send-community. */
4235 DEFUN (neighbor_send_community,
4236 neighbor_send_community_cmd,
4237 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4238 NEIGHBOR_STR
4239 NEIGHBOR_ADDR_STR2
4240 "Send Community attribute to this neighbor\n")
4241 {
4242 int idx_peer = 1;
4243
4244 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4245 bgp_node_safi(vty),
4246 PEER_FLAG_SEND_COMMUNITY);
4247 }
4248
4249 ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
4250 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4251 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4252 "Send Community attribute to this neighbor\n")
4253
4254 DEFUN (no_neighbor_send_community,
4255 no_neighbor_send_community_cmd,
4256 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4257 NO_STR
4258 NEIGHBOR_STR
4259 NEIGHBOR_ADDR_STR2
4260 "Send Community attribute to this neighbor\n")
4261 {
4262 int idx_peer = 2;
4263
4264 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4265 bgp_node_afi(vty), bgp_node_safi(vty),
4266 PEER_FLAG_SEND_COMMUNITY);
4267 }
4268
4269 ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
4270 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4271 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4272 "Send Community attribute to this neighbor\n")
4273
4274 /* neighbor send-community extended. */
4275 DEFUN (neighbor_send_community_type,
4276 neighbor_send_community_type_cmd,
4277 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4278 NEIGHBOR_STR
4279 NEIGHBOR_ADDR_STR2
4280 "Send Community attribute to this neighbor\n"
4281 "Send Standard and Extended Community attributes\n"
4282 "Send Standard, Large and Extended Community attributes\n"
4283 "Send Extended Community attributes\n"
4284 "Send Standard Community attributes\n"
4285 "Send Large Community attributes\n")
4286 {
4287 int idx_peer = 1;
4288 uint32_t flag = 0;
4289 const char *type = argv[argc - 1]->text;
4290
4291 if (strmatch(type, "standard")) {
4292 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4293 } else if (strmatch(type, "extended")) {
4294 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4295 } else if (strmatch(type, "large")) {
4296 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4297 } else if (strmatch(type, "both")) {
4298 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4299 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4300 } else { /* if (strmatch(type, "all")) */
4301 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4302 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4303 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4304 }
4305
4306 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4307 bgp_node_safi(vty), flag);
4308 }
4309
4310 ALIAS_HIDDEN(
4311 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
4312 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4313 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4314 "Send Community attribute to this neighbor\n"
4315 "Send Standard and Extended Community attributes\n"
4316 "Send Standard, Large and Extended Community attributes\n"
4317 "Send Extended Community attributes\n"
4318 "Send Standard Community attributes\n"
4319 "Send Large Community attributes\n")
4320
4321 DEFUN (no_neighbor_send_community_type,
4322 no_neighbor_send_community_type_cmd,
4323 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4324 NO_STR
4325 NEIGHBOR_STR
4326 NEIGHBOR_ADDR_STR2
4327 "Send Community attribute to this neighbor\n"
4328 "Send Standard and Extended Community attributes\n"
4329 "Send Standard, Large and Extended Community attributes\n"
4330 "Send Extended Community attributes\n"
4331 "Send Standard Community attributes\n"
4332 "Send Large Community attributes\n")
4333 {
4334 int idx_peer = 2;
4335 uint32_t flag = 0;
4336 const char *type = argv[argc - 1]->text;
4337
4338 if (strmatch(type, "standard")) {
4339 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4340 } else if (strmatch(type, "extended")) {
4341 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4342 } else if (strmatch(type, "large")) {
4343 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4344 } else if (strmatch(type, "both")) {
4345 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4346 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4347 } else { /* if (strmatch(type, "all")) */
4348 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4349 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4350 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4351 }
4352
4353 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4354 bgp_node_afi(vty), bgp_node_safi(vty),
4355 flag);
4356 }
4357
4358 ALIAS_HIDDEN(
4359 no_neighbor_send_community_type,
4360 no_neighbor_send_community_type_hidden_cmd,
4361 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4362 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4363 "Send Community attribute to this neighbor\n"
4364 "Send Standard and Extended Community attributes\n"
4365 "Send Standard, Large and Extended Community attributes\n"
4366 "Send Extended Community attributes\n"
4367 "Send Standard Community attributes\n"
4368 "Send Large Community attributes\n")
4369
4370 /* neighbor soft-reconfig. */
4371 DEFUN (neighbor_soft_reconfiguration,
4372 neighbor_soft_reconfiguration_cmd,
4373 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4374 NEIGHBOR_STR
4375 NEIGHBOR_ADDR_STR2
4376 "Per neighbor soft reconfiguration\n"
4377 "Allow inbound soft reconfiguration for this neighbor\n")
4378 {
4379 int idx_peer = 1;
4380 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4381 bgp_node_safi(vty),
4382 PEER_FLAG_SOFT_RECONFIG);
4383 }
4384
4385 ALIAS_HIDDEN(neighbor_soft_reconfiguration,
4386 neighbor_soft_reconfiguration_hidden_cmd,
4387 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4388 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4389 "Per neighbor soft reconfiguration\n"
4390 "Allow inbound soft reconfiguration for this neighbor\n")
4391
4392 DEFUN (no_neighbor_soft_reconfiguration,
4393 no_neighbor_soft_reconfiguration_cmd,
4394 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4395 NO_STR
4396 NEIGHBOR_STR
4397 NEIGHBOR_ADDR_STR2
4398 "Per neighbor soft reconfiguration\n"
4399 "Allow inbound soft reconfiguration for this neighbor\n")
4400 {
4401 int idx_peer = 2;
4402 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4403 bgp_node_afi(vty), bgp_node_safi(vty),
4404 PEER_FLAG_SOFT_RECONFIG);
4405 }
4406
4407 ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
4408 no_neighbor_soft_reconfiguration_hidden_cmd,
4409 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4410 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4411 "Per neighbor soft reconfiguration\n"
4412 "Allow inbound soft reconfiguration for this neighbor\n")
4413
4414 DEFUN (neighbor_route_reflector_client,
4415 neighbor_route_reflector_client_cmd,
4416 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4417 NEIGHBOR_STR
4418 NEIGHBOR_ADDR_STR2
4419 "Configure a neighbor as Route Reflector client\n")
4420 {
4421 int idx_peer = 1;
4422 struct peer *peer;
4423
4424
4425 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4426 if (!peer)
4427 return CMD_WARNING_CONFIG_FAILED;
4428
4429 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4430 bgp_node_safi(vty),
4431 PEER_FLAG_REFLECTOR_CLIENT);
4432 }
4433
4434 ALIAS_HIDDEN(neighbor_route_reflector_client,
4435 neighbor_route_reflector_client_hidden_cmd,
4436 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4437 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4438 "Configure a neighbor as Route Reflector client\n")
4439
4440 DEFUN (no_neighbor_route_reflector_client,
4441 no_neighbor_route_reflector_client_cmd,
4442 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4443 NO_STR
4444 NEIGHBOR_STR
4445 NEIGHBOR_ADDR_STR2
4446 "Configure a neighbor as Route Reflector client\n")
4447 {
4448 int idx_peer = 2;
4449 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4450 bgp_node_afi(vty), bgp_node_safi(vty),
4451 PEER_FLAG_REFLECTOR_CLIENT);
4452 }
4453
4454 ALIAS_HIDDEN(no_neighbor_route_reflector_client,
4455 no_neighbor_route_reflector_client_hidden_cmd,
4456 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4457 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4458 "Configure a neighbor as Route Reflector client\n")
4459
4460 /* neighbor route-server-client. */
4461 DEFUN (neighbor_route_server_client,
4462 neighbor_route_server_client_cmd,
4463 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4464 NEIGHBOR_STR
4465 NEIGHBOR_ADDR_STR2
4466 "Configure a neighbor as Route Server client\n")
4467 {
4468 int idx_peer = 1;
4469 struct peer *peer;
4470
4471 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4472 if (!peer)
4473 return CMD_WARNING_CONFIG_FAILED;
4474 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4475 bgp_node_safi(vty),
4476 PEER_FLAG_RSERVER_CLIENT);
4477 }
4478
4479 ALIAS_HIDDEN(neighbor_route_server_client,
4480 neighbor_route_server_client_hidden_cmd,
4481 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4482 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4483 "Configure a neighbor as Route Server client\n")
4484
4485 DEFUN (no_neighbor_route_server_client,
4486 no_neighbor_route_server_client_cmd,
4487 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4488 NO_STR
4489 NEIGHBOR_STR
4490 NEIGHBOR_ADDR_STR2
4491 "Configure a neighbor as Route Server client\n")
4492 {
4493 int idx_peer = 2;
4494 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4495 bgp_node_afi(vty), bgp_node_safi(vty),
4496 PEER_FLAG_RSERVER_CLIENT);
4497 }
4498
4499 ALIAS_HIDDEN(no_neighbor_route_server_client,
4500 no_neighbor_route_server_client_hidden_cmd,
4501 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4502 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4503 "Configure a neighbor as Route Server client\n")
4504
4505 DEFUN (neighbor_nexthop_local_unchanged,
4506 neighbor_nexthop_local_unchanged_cmd,
4507 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
4508 NEIGHBOR_STR
4509 NEIGHBOR_ADDR_STR2
4510 "Configure treatment of outgoing link-local nexthop attribute\n"
4511 "Leave link-local nexthop unchanged for this peer\n")
4512 {
4513 int idx_peer = 1;
4514 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4515 bgp_node_safi(vty),
4516 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
4517 }
4518
4519 DEFUN (no_neighbor_nexthop_local_unchanged,
4520 no_neighbor_nexthop_local_unchanged_cmd,
4521 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
4522 NO_STR
4523 NEIGHBOR_STR
4524 NEIGHBOR_ADDR_STR2
4525 "Configure treatment of outgoing link-local-nexthop attribute\n"
4526 "Leave link-local nexthop unchanged for this peer\n")
4527 {
4528 int idx_peer = 2;
4529 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4530 bgp_node_afi(vty), bgp_node_safi(vty),
4531 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
4532 }
4533
4534 DEFUN (neighbor_attr_unchanged,
4535 neighbor_attr_unchanged_cmd,
4536 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4537 NEIGHBOR_STR
4538 NEIGHBOR_ADDR_STR2
4539 "BGP attribute is propagated unchanged to this neighbor\n"
4540 "As-path attribute\n"
4541 "Nexthop attribute\n"
4542 "Med attribute\n")
4543 {
4544 int idx = 0;
4545 char *peer_str = argv[1]->arg;
4546 struct peer *peer;
4547 uint16_t flags = 0;
4548 afi_t afi = bgp_node_afi(vty);
4549 safi_t safi = bgp_node_safi(vty);
4550
4551 peer = peer_and_group_lookup_vty(vty, peer_str);
4552 if (!peer)
4553 return CMD_WARNING_CONFIG_FAILED;
4554
4555 if (argv_find(argv, argc, "as-path", &idx))
4556 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4557 idx = 0;
4558 if (argv_find(argv, argc, "next-hop", &idx))
4559 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4560 idx = 0;
4561 if (argv_find(argv, argc, "med", &idx))
4562 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4563
4564 /* no flags means all of them! */
4565 if (!flags) {
4566 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4567 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4568 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4569 } else {
4570 if (!CHECK_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED)
4571 && peer_af_flag_check(peer, afi, safi,
4572 PEER_FLAG_AS_PATH_UNCHANGED)) {
4573 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4574 PEER_FLAG_AS_PATH_UNCHANGED);
4575 }
4576
4577 if (!CHECK_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED)
4578 && peer_af_flag_check(peer, afi, safi,
4579 PEER_FLAG_NEXTHOP_UNCHANGED)) {
4580 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4581 PEER_FLAG_NEXTHOP_UNCHANGED);
4582 }
4583
4584 if (!CHECK_FLAG(flags, PEER_FLAG_MED_UNCHANGED)
4585 && peer_af_flag_check(peer, afi, safi,
4586 PEER_FLAG_MED_UNCHANGED)) {
4587 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4588 PEER_FLAG_MED_UNCHANGED);
4589 }
4590 }
4591
4592 return peer_af_flag_set_vty(vty, peer_str, afi, safi, flags);
4593 }
4594
4595 ALIAS_HIDDEN(
4596 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
4597 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4598 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4599 "BGP attribute is propagated unchanged to this neighbor\n"
4600 "As-path attribute\n"
4601 "Nexthop attribute\n"
4602 "Med attribute\n")
4603
4604 DEFUN (no_neighbor_attr_unchanged,
4605 no_neighbor_attr_unchanged_cmd,
4606 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4607 NO_STR
4608 NEIGHBOR_STR
4609 NEIGHBOR_ADDR_STR2
4610 "BGP attribute is propagated unchanged to this neighbor\n"
4611 "As-path attribute\n"
4612 "Nexthop attribute\n"
4613 "Med attribute\n")
4614 {
4615 int idx = 0;
4616 char *peer = argv[2]->arg;
4617 uint16_t flags = 0;
4618
4619 if (argv_find(argv, argc, "as-path", &idx))
4620 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4621 idx = 0;
4622 if (argv_find(argv, argc, "next-hop", &idx))
4623 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4624 idx = 0;
4625 if (argv_find(argv, argc, "med", &idx))
4626 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4627
4628 if (!flags) // no flags means all of them!
4629 {
4630 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4631 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4632 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4633 }
4634
4635 return peer_af_flag_unset_vty(vty, peer, bgp_node_afi(vty),
4636 bgp_node_safi(vty), flags);
4637 }
4638
4639 ALIAS_HIDDEN(
4640 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
4641 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4642 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4643 "BGP attribute is propagated unchanged to this neighbor\n"
4644 "As-path attribute\n"
4645 "Nexthop attribute\n"
4646 "Med attribute\n")
4647
4648 /* EBGP multihop configuration. */
4649 static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
4650 const char *ttl_str)
4651 {
4652 struct peer *peer;
4653 unsigned int ttl;
4654
4655 peer = peer_and_group_lookup_vty(vty, ip_str);
4656 if (!peer)
4657 return CMD_WARNING_CONFIG_FAILED;
4658
4659 if (peer->conf_if)
4660 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
4661
4662 if (!ttl_str)
4663 ttl = MAXTTL;
4664 else
4665 ttl = strtoul(ttl_str, NULL, 10);
4666
4667 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
4668 }
4669
4670 static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
4671 {
4672 struct peer *peer;
4673
4674 peer = peer_and_group_lookup_vty(vty, ip_str);
4675 if (!peer)
4676 return CMD_WARNING_CONFIG_FAILED;
4677
4678 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
4679 }
4680
4681 /* neighbor ebgp-multihop. */
4682 DEFUN (neighbor_ebgp_multihop,
4683 neighbor_ebgp_multihop_cmd,
4684 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
4685 NEIGHBOR_STR
4686 NEIGHBOR_ADDR_STR2
4687 "Allow EBGP neighbors not on directly connected networks\n")
4688 {
4689 int idx_peer = 1;
4690 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
4691 }
4692
4693 DEFUN (neighbor_ebgp_multihop_ttl,
4694 neighbor_ebgp_multihop_ttl_cmd,
4695 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
4696 NEIGHBOR_STR
4697 NEIGHBOR_ADDR_STR2
4698 "Allow EBGP neighbors not on directly connected networks\n"
4699 "maximum hop count\n")
4700 {
4701 int idx_peer = 1;
4702 int idx_number = 3;
4703 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
4704 argv[idx_number]->arg);
4705 }
4706
4707 DEFUN (no_neighbor_ebgp_multihop,
4708 no_neighbor_ebgp_multihop_cmd,
4709 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
4710 NO_STR
4711 NEIGHBOR_STR
4712 NEIGHBOR_ADDR_STR2
4713 "Allow EBGP neighbors not on directly connected networks\n"
4714 "maximum hop count\n")
4715 {
4716 int idx_peer = 2;
4717 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
4718 }
4719
4720
4721 /* disable-connected-check */
4722 DEFUN (neighbor_disable_connected_check,
4723 neighbor_disable_connected_check_cmd,
4724 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
4725 NEIGHBOR_STR
4726 NEIGHBOR_ADDR_STR2
4727 "one-hop away EBGP peer using loopback address\n"
4728 "Enforce EBGP neighbors perform multihop\n")
4729 {
4730 int idx_peer = 1;
4731 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4732 PEER_FLAG_DISABLE_CONNECTED_CHECK);
4733 }
4734
4735 DEFUN (no_neighbor_disable_connected_check,
4736 no_neighbor_disable_connected_check_cmd,
4737 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
4738 NO_STR
4739 NEIGHBOR_STR
4740 NEIGHBOR_ADDR_STR2
4741 "one-hop away EBGP peer using loopback address\n"
4742 "Enforce EBGP neighbors perform multihop\n")
4743 {
4744 int idx_peer = 2;
4745 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4746 PEER_FLAG_DISABLE_CONNECTED_CHECK);
4747 }
4748
4749
4750 /* enforce-first-as */
4751 DEFUN (neighbor_enforce_first_as,
4752 neighbor_enforce_first_as_cmd,
4753 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4754 NEIGHBOR_STR
4755 NEIGHBOR_ADDR_STR2
4756 "Enforce the first AS for EBGP routes\n")
4757 {
4758 int idx_peer = 1;
4759
4760 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4761 PEER_FLAG_ENFORCE_FIRST_AS);
4762 }
4763
4764 DEFUN (no_neighbor_enforce_first_as,
4765 no_neighbor_enforce_first_as_cmd,
4766 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4767 NO_STR
4768 NEIGHBOR_STR
4769 NEIGHBOR_ADDR_STR2
4770 "Enforce the first AS for EBGP routes\n")
4771 {
4772 int idx_peer = 2;
4773
4774 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4775 PEER_FLAG_ENFORCE_FIRST_AS);
4776 }
4777
4778
4779 DEFUN (neighbor_description,
4780 neighbor_description_cmd,
4781 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4782 NEIGHBOR_STR
4783 NEIGHBOR_ADDR_STR2
4784 "Neighbor specific description\n"
4785 "Up to 80 characters describing this neighbor\n")
4786 {
4787 int idx_peer = 1;
4788 int idx_line = 3;
4789 struct peer *peer;
4790 char *str;
4791
4792 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4793 if (!peer)
4794 return CMD_WARNING_CONFIG_FAILED;
4795
4796 str = argv_concat(argv, argc, idx_line);
4797
4798 peer_description_set(peer, str);
4799
4800 XFREE(MTYPE_TMP, str);
4801
4802 return CMD_SUCCESS;
4803 }
4804
4805 DEFUN (no_neighbor_description,
4806 no_neighbor_description_cmd,
4807 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
4808 NO_STR
4809 NEIGHBOR_STR
4810 NEIGHBOR_ADDR_STR2
4811 "Neighbor specific description\n")
4812 {
4813 int idx_peer = 2;
4814 struct peer *peer;
4815
4816 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4817 if (!peer)
4818 return CMD_WARNING_CONFIG_FAILED;
4819
4820 peer_description_unset(peer);
4821
4822 return CMD_SUCCESS;
4823 }
4824
4825 ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
4826 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4827 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4828 "Neighbor specific description\n"
4829 "Up to 80 characters describing this neighbor\n")
4830
4831 /* Neighbor update-source. */
4832 static int peer_update_source_vty(struct vty *vty, const char *peer_str,
4833 const char *source_str)
4834 {
4835 struct peer *peer;
4836 struct prefix p;
4837 union sockunion su;
4838
4839 peer = peer_and_group_lookup_vty(vty, peer_str);
4840 if (!peer)
4841 return CMD_WARNING_CONFIG_FAILED;
4842
4843 if (peer->conf_if)
4844 return CMD_WARNING;
4845
4846 if (source_str) {
4847 if (str2sockunion(source_str, &su) == 0)
4848 peer_update_source_addr_set(peer, &su);
4849 else {
4850 if (str2prefix(source_str, &p)) {
4851 vty_out(vty,
4852 "%% Invalid update-source, remove prefix length \n");
4853 return CMD_WARNING_CONFIG_FAILED;
4854 } else
4855 peer_update_source_if_set(peer, source_str);
4856 }
4857 } else
4858 peer_update_source_unset(peer);
4859
4860 return CMD_SUCCESS;
4861 }
4862
4863 #define BGP_UPDATE_SOURCE_HELP_STR \
4864 "IPv4 address\n" \
4865 "IPv6 address\n" \
4866 "Interface name (requires zebra to be running)\n"
4867
4868 DEFUN (neighbor_update_source,
4869 neighbor_update_source_cmd,
4870 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
4871 NEIGHBOR_STR
4872 NEIGHBOR_ADDR_STR2
4873 "Source of routing updates\n"
4874 BGP_UPDATE_SOURCE_HELP_STR)
4875 {
4876 int idx_peer = 1;
4877 int idx_peer_2 = 3;
4878 return peer_update_source_vty(vty, argv[idx_peer]->arg,
4879 argv[idx_peer_2]->arg);
4880 }
4881
4882 DEFUN (no_neighbor_update_source,
4883 no_neighbor_update_source_cmd,
4884 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
4885 NO_STR
4886 NEIGHBOR_STR
4887 NEIGHBOR_ADDR_STR2
4888 "Source of routing updates\n"
4889 BGP_UPDATE_SOURCE_HELP_STR)
4890 {
4891 int idx_peer = 2;
4892 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
4893 }
4894
4895 static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
4896 afi_t afi, safi_t safi,
4897 const char *rmap, int set)
4898 {
4899 int ret;
4900 struct peer *peer;
4901 struct route_map *route_map = NULL;
4902
4903 peer = peer_and_group_lookup_vty(vty, peer_str);
4904 if (!peer)
4905 return CMD_WARNING_CONFIG_FAILED;
4906
4907 if (set) {
4908 if (rmap)
4909 route_map = route_map_lookup_warn_noexist(vty, rmap);
4910 ret = peer_default_originate_set(peer, afi, safi,
4911 rmap, route_map);
4912 } else
4913 ret = peer_default_originate_unset(peer, afi, safi);
4914
4915 return bgp_vty_return(vty, ret);
4916 }
4917
4918 /* neighbor default-originate. */
4919 DEFUN (neighbor_default_originate,
4920 neighbor_default_originate_cmd,
4921 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4922 NEIGHBOR_STR
4923 NEIGHBOR_ADDR_STR2
4924 "Originate default route to this neighbor\n")
4925 {
4926 int idx_peer = 1;
4927 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4928 bgp_node_afi(vty),
4929 bgp_node_safi(vty), NULL, 1);
4930 }
4931
4932 ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
4933 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4934 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4935 "Originate default route to this neighbor\n")
4936
4937 DEFUN (neighbor_default_originate_rmap,
4938 neighbor_default_originate_rmap_cmd,
4939 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4940 NEIGHBOR_STR
4941 NEIGHBOR_ADDR_STR2
4942 "Originate default route to this neighbor\n"
4943 "Route-map to specify criteria to originate default\n"
4944 "route-map name\n")
4945 {
4946 int idx_peer = 1;
4947 int idx_word = 4;
4948 return peer_default_originate_set_vty(
4949 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
4950 argv[idx_word]->arg, 1);
4951 }
4952
4953 ALIAS_HIDDEN(
4954 neighbor_default_originate_rmap,
4955 neighbor_default_originate_rmap_hidden_cmd,
4956 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4957 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4958 "Originate default route to this neighbor\n"
4959 "Route-map to specify criteria to originate default\n"
4960 "route-map name\n")
4961
4962 DEFUN (no_neighbor_default_originate,
4963 no_neighbor_default_originate_cmd,
4964 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4965 NO_STR
4966 NEIGHBOR_STR
4967 NEIGHBOR_ADDR_STR2
4968 "Originate default route to this neighbor\n"
4969 "Route-map to specify criteria to originate default\n"
4970 "route-map name\n")
4971 {
4972 int idx_peer = 2;
4973 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4974 bgp_node_afi(vty),
4975 bgp_node_safi(vty), NULL, 0);
4976 }
4977
4978 ALIAS_HIDDEN(
4979 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
4980 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4981 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4982 "Originate default route to this neighbor\n"
4983 "Route-map to specify criteria to originate default\n"
4984 "route-map name\n")
4985
4986
4987 /* Set neighbor's BGP port. */
4988 static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
4989 const char *port_str)
4990 {
4991 struct peer *peer;
4992 uint16_t port;
4993 struct servent *sp;
4994
4995 peer = peer_lookup_vty(vty, ip_str);
4996 if (!peer)
4997 return CMD_WARNING_CONFIG_FAILED;
4998
4999 if (!port_str) {
5000 sp = getservbyname("bgp", "tcp");
5001 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
5002 } else {
5003 port = strtoul(port_str, NULL, 10);
5004 }
5005
5006 peer_port_set(peer, port);
5007
5008 return CMD_SUCCESS;
5009 }
5010
5011 /* Set specified peer's BGP port. */
5012 DEFUN (neighbor_port,
5013 neighbor_port_cmd,
5014 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
5015 NEIGHBOR_STR
5016 NEIGHBOR_ADDR_STR
5017 "Neighbor's BGP port\n"
5018 "TCP port number\n")
5019 {
5020 int idx_ip = 1;
5021 int idx_number = 3;
5022 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
5023 argv[idx_number]->arg);
5024 }
5025
5026 DEFUN (no_neighbor_port,
5027 no_neighbor_port_cmd,
5028 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
5029 NO_STR
5030 NEIGHBOR_STR
5031 NEIGHBOR_ADDR_STR
5032 "Neighbor's BGP port\n"
5033 "TCP port number\n")
5034 {
5035 int idx_ip = 2;
5036 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
5037 }
5038
5039
5040 /* neighbor weight. */
5041 static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5042 safi_t safi, const char *weight_str)
5043 {
5044 int ret;
5045 struct peer *peer;
5046 unsigned long weight;
5047
5048 peer = peer_and_group_lookup_vty(vty, ip_str);
5049 if (!peer)
5050 return CMD_WARNING_CONFIG_FAILED;
5051
5052 weight = strtoul(weight_str, NULL, 10);
5053
5054 ret = peer_weight_set(peer, afi, safi, weight);
5055 return bgp_vty_return(vty, ret);
5056 }
5057
5058 static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5059 safi_t safi)
5060 {
5061 int ret;
5062 struct peer *peer;
5063
5064 peer = peer_and_group_lookup_vty(vty, ip_str);
5065 if (!peer)
5066 return CMD_WARNING_CONFIG_FAILED;
5067
5068 ret = peer_weight_unset(peer, afi, safi);
5069 return bgp_vty_return(vty, ret);
5070 }
5071
5072 DEFUN (neighbor_weight,
5073 neighbor_weight_cmd,
5074 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
5075 NEIGHBOR_STR
5076 NEIGHBOR_ADDR_STR2
5077 "Set default weight for routes from this neighbor\n"
5078 "default weight\n")
5079 {
5080 int idx_peer = 1;
5081 int idx_number = 3;
5082 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5083 bgp_node_safi(vty), argv[idx_number]->arg);
5084 }
5085
5086 ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
5087 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
5088 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5089 "Set default weight for routes from this neighbor\n"
5090 "default weight\n")
5091
5092 DEFUN (no_neighbor_weight,
5093 no_neighbor_weight_cmd,
5094 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
5095 NO_STR
5096 NEIGHBOR_STR
5097 NEIGHBOR_ADDR_STR2
5098 "Set default weight for routes from this neighbor\n"
5099 "default weight\n")
5100 {
5101 int idx_peer = 2;
5102 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
5103 bgp_node_afi(vty), bgp_node_safi(vty));
5104 }
5105
5106 ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
5107 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
5108 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5109 "Set default weight for routes from this neighbor\n"
5110 "default weight\n")
5111
5112
5113 /* Override capability negotiation. */
5114 DEFUN (neighbor_override_capability,
5115 neighbor_override_capability_cmd,
5116 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
5117 NEIGHBOR_STR
5118 NEIGHBOR_ADDR_STR2
5119 "Override capability negotiation result\n")
5120 {
5121 int idx_peer = 1;
5122 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5123 PEER_FLAG_OVERRIDE_CAPABILITY);
5124 }
5125
5126 DEFUN (no_neighbor_override_capability,
5127 no_neighbor_override_capability_cmd,
5128 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
5129 NO_STR
5130 NEIGHBOR_STR
5131 NEIGHBOR_ADDR_STR2
5132 "Override capability negotiation result\n")
5133 {
5134 int idx_peer = 2;
5135 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5136 PEER_FLAG_OVERRIDE_CAPABILITY);
5137 }
5138
5139 DEFUN (neighbor_strict_capability,
5140 neighbor_strict_capability_cmd,
5141 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
5142 NEIGHBOR_STR
5143 NEIGHBOR_ADDR_STR2
5144 "Strict capability negotiation match\n")
5145 {
5146 int idx_peer = 1;
5147
5148 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5149 PEER_FLAG_STRICT_CAP_MATCH);
5150 }
5151
5152 DEFUN (no_neighbor_strict_capability,
5153 no_neighbor_strict_capability_cmd,
5154 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
5155 NO_STR
5156 NEIGHBOR_STR
5157 NEIGHBOR_ADDR_STR2
5158 "Strict capability negotiation match\n")
5159 {
5160 int idx_peer = 2;
5161
5162 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5163 PEER_FLAG_STRICT_CAP_MATCH);
5164 }
5165
5166 static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
5167 const char *keep_str, const char *hold_str)
5168 {
5169 int ret;
5170 struct peer *peer;
5171 uint32_t keepalive;
5172 uint32_t holdtime;
5173
5174 peer = peer_and_group_lookup_vty(vty, ip_str);
5175 if (!peer)
5176 return CMD_WARNING_CONFIG_FAILED;
5177
5178 keepalive = strtoul(keep_str, NULL, 10);
5179 holdtime = strtoul(hold_str, NULL, 10);
5180
5181 ret = peer_timers_set(peer, keepalive, holdtime);
5182
5183 return bgp_vty_return(vty, ret);
5184 }
5185
5186 static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
5187 {
5188 int ret;
5189 struct peer *peer;
5190
5191 peer = peer_and_group_lookup_vty(vty, ip_str);
5192 if (!peer)
5193 return CMD_WARNING_CONFIG_FAILED;
5194
5195 ret = peer_timers_unset(peer);
5196
5197 return bgp_vty_return(vty, ret);
5198 }
5199
5200 DEFUN (neighbor_timers,
5201 neighbor_timers_cmd,
5202 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
5203 NEIGHBOR_STR
5204 NEIGHBOR_ADDR_STR2
5205 "BGP per neighbor timers\n"
5206 "Keepalive interval\n"
5207 "Holdtime\n")
5208 {
5209 int idx_peer = 1;
5210 int idx_number = 3;
5211 int idx_number_2 = 4;
5212 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
5213 argv[idx_number]->arg,
5214 argv[idx_number_2]->arg);
5215 }
5216
5217 DEFUN (no_neighbor_timers,
5218 no_neighbor_timers_cmd,
5219 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
5220 NO_STR
5221 NEIGHBOR_STR
5222 NEIGHBOR_ADDR_STR2
5223 "BGP per neighbor timers\n"
5224 "Keepalive interval\n"
5225 "Holdtime\n")
5226 {
5227 int idx_peer = 2;
5228 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
5229 }
5230
5231
5232 static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
5233 const char *time_str)
5234 {
5235 int ret;
5236 struct peer *peer;
5237 uint32_t connect;
5238
5239 peer = peer_and_group_lookup_vty(vty, ip_str);
5240 if (!peer)
5241 return CMD_WARNING_CONFIG_FAILED;
5242
5243 connect = strtoul(time_str, NULL, 10);
5244
5245 ret = peer_timers_connect_set(peer, connect);
5246
5247 return bgp_vty_return(vty, ret);
5248 }
5249
5250 static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
5251 {
5252 int ret;
5253 struct peer *peer;
5254
5255 peer = peer_and_group_lookup_vty(vty, ip_str);
5256 if (!peer)
5257 return CMD_WARNING_CONFIG_FAILED;
5258
5259 ret = peer_timers_connect_unset(peer);
5260
5261 return bgp_vty_return(vty, ret);
5262 }
5263
5264 DEFUN (neighbor_timers_connect,
5265 neighbor_timers_connect_cmd,
5266 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
5267 NEIGHBOR_STR
5268 NEIGHBOR_ADDR_STR2
5269 "BGP per neighbor timers\n"
5270 "BGP connect timer\n"
5271 "Connect timer\n")
5272 {
5273 int idx_peer = 1;
5274 int idx_number = 4;
5275 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
5276 argv[idx_number]->arg);
5277 }
5278
5279 DEFUN (no_neighbor_timers_connect,
5280 no_neighbor_timers_connect_cmd,
5281 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
5282 NO_STR
5283 NEIGHBOR_STR
5284 NEIGHBOR_ADDR_STR2
5285 "BGP per neighbor timers\n"
5286 "BGP connect timer\n"
5287 "Connect timer\n")
5288 {
5289 int idx_peer = 2;
5290 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
5291 }
5292
5293
5294 static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
5295 const char *time_str, int set)
5296 {
5297 int ret;
5298 struct peer *peer;
5299 uint32_t routeadv = 0;
5300
5301 peer = peer_and_group_lookup_vty(vty, ip_str);
5302 if (!peer)
5303 return CMD_WARNING_CONFIG_FAILED;
5304
5305 if (time_str)
5306 routeadv = strtoul(time_str, NULL, 10);
5307
5308 if (set)
5309 ret = peer_advertise_interval_set(peer, routeadv);
5310 else
5311 ret = peer_advertise_interval_unset(peer);
5312
5313 return bgp_vty_return(vty, ret);
5314 }
5315
5316 DEFUN (neighbor_advertise_interval,
5317 neighbor_advertise_interval_cmd,
5318 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
5319 NEIGHBOR_STR
5320 NEIGHBOR_ADDR_STR2
5321 "Minimum interval between sending BGP routing updates\n"
5322 "time in seconds\n")
5323 {
5324 int idx_peer = 1;
5325 int idx_number = 3;
5326 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
5327 argv[idx_number]->arg, 1);
5328 }
5329
5330 DEFUN (no_neighbor_advertise_interval,
5331 no_neighbor_advertise_interval_cmd,
5332 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
5333 NO_STR
5334 NEIGHBOR_STR
5335 NEIGHBOR_ADDR_STR2
5336 "Minimum interval between sending BGP routing updates\n"
5337 "time in seconds\n")
5338 {
5339 int idx_peer = 2;
5340 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
5341 }
5342
5343
5344 /* Time to wait before processing route-map updates */
5345 DEFUN (bgp_set_route_map_delay_timer,
5346 bgp_set_route_map_delay_timer_cmd,
5347 "bgp route-map delay-timer (0-600)",
5348 SET_STR
5349 "BGP route-map delay timer\n"
5350 "Time in secs to wait before processing route-map changes\n"
5351 "0 disables the timer, no route updates happen when route-maps change\n")
5352 {
5353 int idx_number = 3;
5354 uint32_t rmap_delay_timer;
5355
5356 if (argv[idx_number]->arg) {
5357 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
5358 bm->rmap_update_timer = rmap_delay_timer;
5359
5360 /* if the dynamic update handling is being disabled, and a timer
5361 * is
5362 * running, stop the timer and act as if the timer has already
5363 * fired.
5364 */
5365 if (!rmap_delay_timer && bm->t_rmap_update) {
5366 BGP_TIMER_OFF(bm->t_rmap_update);
5367 thread_execute(bm->master, bgp_route_map_update_timer,
5368 NULL, 0);
5369 }
5370 return CMD_SUCCESS;
5371 } else {
5372 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
5373 return CMD_WARNING_CONFIG_FAILED;
5374 }
5375 }
5376
5377 DEFUN (no_bgp_set_route_map_delay_timer,
5378 no_bgp_set_route_map_delay_timer_cmd,
5379 "no bgp route-map delay-timer [(0-600)]",
5380 NO_STR
5381 BGP_STR
5382 "Default BGP route-map delay timer\n"
5383 "Reset to default time to wait for processing route-map changes\n"
5384 "0 disables the timer, no route updates happen when route-maps change\n")
5385 {
5386
5387 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
5388
5389 return CMD_SUCCESS;
5390 }
5391
5392
5393 /* neighbor interface */
5394 static int peer_interface_vty(struct vty *vty, const char *ip_str,
5395 const char *str)
5396 {
5397 struct peer *peer;
5398
5399 peer = peer_lookup_vty(vty, ip_str);
5400 if (!peer || peer->conf_if) {
5401 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
5402 return CMD_WARNING_CONFIG_FAILED;
5403 }
5404
5405 if (str)
5406 peer_interface_set(peer, str);
5407 else
5408 peer_interface_unset(peer);
5409
5410 return CMD_SUCCESS;
5411 }
5412
5413 DEFUN (neighbor_interface,
5414 neighbor_interface_cmd,
5415 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
5416 NEIGHBOR_STR
5417 NEIGHBOR_ADDR_STR
5418 "Interface\n"
5419 "Interface name\n")
5420 {
5421 int idx_ip = 1;
5422 int idx_word = 3;
5423 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
5424 }
5425
5426 DEFUN (no_neighbor_interface,
5427 no_neighbor_interface_cmd,
5428 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
5429 NO_STR
5430 NEIGHBOR_STR
5431 NEIGHBOR_ADDR_STR2
5432 "Interface\n"
5433 "Interface name\n")
5434 {
5435 int idx_peer = 2;
5436 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
5437 }
5438
5439 DEFUN (neighbor_distribute_list,
5440 neighbor_distribute_list_cmd,
5441 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5442 NEIGHBOR_STR
5443 NEIGHBOR_ADDR_STR2
5444 "Filter updates to/from this neighbor\n"
5445 "IP access-list number\n"
5446 "IP access-list number (expanded range)\n"
5447 "IP Access-list name\n"
5448 "Filter incoming updates\n"
5449 "Filter outgoing updates\n")
5450 {
5451 int idx_peer = 1;
5452 int idx_acl = 3;
5453 int direct, ret;
5454 struct peer *peer;
5455
5456 const char *pstr = argv[idx_peer]->arg;
5457 const char *acl = argv[idx_acl]->arg;
5458 const char *inout = argv[argc - 1]->text;
5459
5460 peer = peer_and_group_lookup_vty(vty, pstr);
5461 if (!peer)
5462 return CMD_WARNING_CONFIG_FAILED;
5463
5464 /* Check filter direction. */
5465 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5466 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5467 direct, acl);
5468
5469 return bgp_vty_return(vty, ret);
5470 }
5471
5472 ALIAS_HIDDEN(
5473 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
5474 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5475 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5476 "Filter updates to/from this neighbor\n"
5477 "IP access-list number\n"
5478 "IP access-list number (expanded range)\n"
5479 "IP Access-list name\n"
5480 "Filter incoming updates\n"
5481 "Filter outgoing updates\n")
5482
5483 DEFUN (no_neighbor_distribute_list,
5484 no_neighbor_distribute_list_cmd,
5485 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5486 NO_STR
5487 NEIGHBOR_STR
5488 NEIGHBOR_ADDR_STR2
5489 "Filter updates to/from this neighbor\n"
5490 "IP access-list number\n"
5491 "IP access-list number (expanded range)\n"
5492 "IP Access-list name\n"
5493 "Filter incoming updates\n"
5494 "Filter outgoing updates\n")
5495 {
5496 int idx_peer = 2;
5497 int direct, ret;
5498 struct peer *peer;
5499
5500 const char *pstr = argv[idx_peer]->arg;
5501 const char *inout = argv[argc - 1]->text;
5502
5503 peer = peer_and_group_lookup_vty(vty, pstr);
5504 if (!peer)
5505 return CMD_WARNING_CONFIG_FAILED;
5506
5507 /* Check filter direction. */
5508 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5509 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5510 direct);
5511
5512 return bgp_vty_return(vty, ret);
5513 }
5514
5515 ALIAS_HIDDEN(
5516 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
5517 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5518 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5519 "Filter updates to/from this neighbor\n"
5520 "IP access-list number\n"
5521 "IP access-list number (expanded range)\n"
5522 "IP Access-list name\n"
5523 "Filter incoming updates\n"
5524 "Filter outgoing updates\n")
5525
5526 /* Set prefix list to the peer. */
5527 static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
5528 afi_t afi, safi_t safi,
5529 const char *name_str,
5530 const char *direct_str)
5531 {
5532 int ret;
5533 int direct = FILTER_IN;
5534 struct peer *peer;
5535
5536 peer = peer_and_group_lookup_vty(vty, ip_str);
5537 if (!peer)
5538 return CMD_WARNING_CONFIG_FAILED;
5539
5540 /* Check filter direction. */
5541 if (strncmp(direct_str, "i", 1) == 0)
5542 direct = FILTER_IN;
5543 else if (strncmp(direct_str, "o", 1) == 0)
5544 direct = FILTER_OUT;
5545
5546 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
5547
5548 return bgp_vty_return(vty, ret);
5549 }
5550
5551 static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
5552 afi_t afi, safi_t safi,
5553 const char *direct_str)
5554 {
5555 int ret;
5556 struct peer *peer;
5557 int direct = FILTER_IN;
5558
5559 peer = peer_and_group_lookup_vty(vty, ip_str);
5560 if (!peer)
5561 return CMD_WARNING_CONFIG_FAILED;
5562
5563 /* Check filter direction. */
5564 if (strncmp(direct_str, "i", 1) == 0)
5565 direct = FILTER_IN;
5566 else if (strncmp(direct_str, "o", 1) == 0)
5567 direct = FILTER_OUT;
5568
5569 ret = peer_prefix_list_unset(peer, afi, safi, direct);
5570
5571 return bgp_vty_return(vty, ret);
5572 }
5573
5574 DEFUN (neighbor_prefix_list,
5575 neighbor_prefix_list_cmd,
5576 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5577 NEIGHBOR_STR
5578 NEIGHBOR_ADDR_STR2
5579 "Filter updates to/from this neighbor\n"
5580 "Name of a prefix list\n"
5581 "Filter incoming updates\n"
5582 "Filter outgoing updates\n")
5583 {
5584 int idx_peer = 1;
5585 int idx_word = 3;
5586 int idx_in_out = 4;
5587 return peer_prefix_list_set_vty(
5588 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5589 argv[idx_word]->arg, argv[idx_in_out]->arg);
5590 }
5591
5592 ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
5593 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5594 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5595 "Filter updates to/from this neighbor\n"
5596 "Name of a prefix list\n"
5597 "Filter incoming updates\n"
5598 "Filter outgoing updates\n")
5599
5600 DEFUN (no_neighbor_prefix_list,
5601 no_neighbor_prefix_list_cmd,
5602 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5603 NO_STR
5604 NEIGHBOR_STR
5605 NEIGHBOR_ADDR_STR2
5606 "Filter updates to/from this neighbor\n"
5607 "Name of a prefix list\n"
5608 "Filter incoming updates\n"
5609 "Filter outgoing updates\n")
5610 {
5611 int idx_peer = 2;
5612 int idx_in_out = 5;
5613 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
5614 bgp_node_afi(vty), bgp_node_safi(vty),
5615 argv[idx_in_out]->arg);
5616 }
5617
5618 ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
5619 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5620 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5621 "Filter updates to/from this neighbor\n"
5622 "Name of a prefix list\n"
5623 "Filter incoming updates\n"
5624 "Filter outgoing updates\n")
5625
5626 static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5627 safi_t safi, const char *name_str,
5628 const char *direct_str)
5629 {
5630 int ret;
5631 struct peer *peer;
5632 int direct = FILTER_IN;
5633
5634 peer = peer_and_group_lookup_vty(vty, ip_str);
5635 if (!peer)
5636 return CMD_WARNING_CONFIG_FAILED;
5637
5638 /* Check filter direction. */
5639 if (strncmp(direct_str, "i", 1) == 0)
5640 direct = FILTER_IN;
5641 else if (strncmp(direct_str, "o", 1) == 0)
5642 direct = FILTER_OUT;
5643
5644 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
5645
5646 return bgp_vty_return(vty, ret);
5647 }
5648
5649 static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5650 safi_t safi, const char *direct_str)
5651 {
5652 int ret;
5653 struct peer *peer;
5654 int direct = FILTER_IN;
5655
5656 peer = peer_and_group_lookup_vty(vty, ip_str);
5657 if (!peer)
5658 return CMD_WARNING_CONFIG_FAILED;
5659
5660 /* Check filter direction. */
5661 if (strncmp(direct_str, "i", 1) == 0)
5662 direct = FILTER_IN;
5663 else if (strncmp(direct_str, "o", 1) == 0)
5664 direct = FILTER_OUT;
5665
5666 ret = peer_aslist_unset(peer, afi, safi, direct);
5667
5668 return bgp_vty_return(vty, ret);
5669 }
5670
5671 DEFUN (neighbor_filter_list,
5672 neighbor_filter_list_cmd,
5673 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5674 NEIGHBOR_STR
5675 NEIGHBOR_ADDR_STR2
5676 "Establish BGP filters\n"
5677 "AS path access-list name\n"
5678 "Filter incoming routes\n"
5679 "Filter outgoing routes\n")
5680 {
5681 int idx_peer = 1;
5682 int idx_word = 3;
5683 int idx_in_out = 4;
5684 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5685 bgp_node_safi(vty), argv[idx_word]->arg,
5686 argv[idx_in_out]->arg);
5687 }
5688
5689 ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
5690 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5691 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5692 "Establish BGP filters\n"
5693 "AS path access-list name\n"
5694 "Filter incoming routes\n"
5695 "Filter outgoing routes\n")
5696
5697 DEFUN (no_neighbor_filter_list,
5698 no_neighbor_filter_list_cmd,
5699 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5700 NO_STR
5701 NEIGHBOR_STR
5702 NEIGHBOR_ADDR_STR2
5703 "Establish BGP filters\n"
5704 "AS path access-list name\n"
5705 "Filter incoming routes\n"
5706 "Filter outgoing routes\n")
5707 {
5708 int idx_peer = 2;
5709 int idx_in_out = 5;
5710 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
5711 bgp_node_afi(vty), bgp_node_safi(vty),
5712 argv[idx_in_out]->arg);
5713 }
5714
5715 ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
5716 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5717 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5718 "Establish BGP filters\n"
5719 "AS path access-list name\n"
5720 "Filter incoming routes\n"
5721 "Filter outgoing routes\n")
5722
5723 /* Set route-map to the peer. */
5724 static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
5725 afi_t afi, safi_t safi, const char *name_str,
5726 const char *direct_str)
5727 {
5728 int ret;
5729 struct peer *peer;
5730 int direct = RMAP_IN;
5731 struct route_map *route_map;
5732
5733 peer = peer_and_group_lookup_vty(vty, ip_str);
5734 if (!peer)
5735 return CMD_WARNING_CONFIG_FAILED;
5736
5737 /* Check filter direction. */
5738 if (strncmp(direct_str, "in", 2) == 0)
5739 direct = RMAP_IN;
5740 else if (strncmp(direct_str, "o", 1) == 0)
5741 direct = RMAP_OUT;
5742
5743 route_map = route_map_lookup_warn_noexist(vty, name_str);
5744 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
5745
5746 return bgp_vty_return(vty, ret);
5747 }
5748
5749 static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
5750 afi_t afi, safi_t safi,
5751 const char *direct_str)
5752 {
5753 int ret;
5754 struct peer *peer;
5755 int direct = RMAP_IN;
5756
5757 peer = peer_and_group_lookup_vty(vty, ip_str);
5758 if (!peer)
5759 return CMD_WARNING_CONFIG_FAILED;
5760
5761 /* Check filter direction. */
5762 if (strncmp(direct_str, "in", 2) == 0)
5763 direct = RMAP_IN;
5764 else if (strncmp(direct_str, "o", 1) == 0)
5765 direct = RMAP_OUT;
5766
5767 ret = peer_route_map_unset(peer, afi, safi, direct);
5768
5769 return bgp_vty_return(vty, ret);
5770 }
5771
5772 DEFUN (neighbor_route_map,
5773 neighbor_route_map_cmd,
5774 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5775 NEIGHBOR_STR
5776 NEIGHBOR_ADDR_STR2
5777 "Apply route map to neighbor\n"
5778 "Name of route map\n"
5779 "Apply map to incoming routes\n"
5780 "Apply map to outbound routes\n")
5781 {
5782 int idx_peer = 1;
5783 int idx_word = 3;
5784 int idx_in_out = 4;
5785 return peer_route_map_set_vty(
5786 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5787 argv[idx_word]->arg, argv[idx_in_out]->arg);
5788 }
5789
5790 ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
5791 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5792 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5793 "Apply route map to neighbor\n"
5794 "Name of route map\n"
5795 "Apply map to incoming routes\n"
5796 "Apply map to outbound routes\n")
5797
5798 DEFUN (no_neighbor_route_map,
5799 no_neighbor_route_map_cmd,
5800 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5801 NO_STR
5802 NEIGHBOR_STR
5803 NEIGHBOR_ADDR_STR2
5804 "Apply route map to neighbor\n"
5805 "Name of route map\n"
5806 "Apply map to incoming routes\n"
5807 "Apply map to outbound routes\n")
5808 {
5809 int idx_peer = 2;
5810 int idx_in_out = 5;
5811 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
5812 bgp_node_afi(vty), bgp_node_safi(vty),
5813 argv[idx_in_out]->arg);
5814 }
5815
5816 ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
5817 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5818 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5819 "Apply route map to neighbor\n"
5820 "Name of route map\n"
5821 "Apply map to incoming routes\n"
5822 "Apply map to outbound routes\n")
5823
5824 /* Set unsuppress-map to the peer. */
5825 static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
5826 afi_t afi, safi_t safi,
5827 const char *name_str)
5828 {
5829 int ret;
5830 struct peer *peer;
5831 struct route_map *route_map;
5832
5833 peer = peer_and_group_lookup_vty(vty, ip_str);
5834 if (!peer)
5835 return CMD_WARNING_CONFIG_FAILED;
5836
5837 route_map = route_map_lookup_warn_noexist(vty, name_str);
5838 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
5839
5840 return bgp_vty_return(vty, ret);
5841 }
5842
5843 /* Unset route-map from the peer. */
5844 static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
5845 afi_t afi, safi_t safi)
5846 {
5847 int ret;
5848 struct peer *peer;
5849
5850 peer = peer_and_group_lookup_vty(vty, ip_str);
5851 if (!peer)
5852 return CMD_WARNING_CONFIG_FAILED;
5853
5854 ret = peer_unsuppress_map_unset(peer, afi, safi);
5855
5856 return bgp_vty_return(vty, ret);
5857 }
5858
5859 DEFUN (neighbor_unsuppress_map,
5860 neighbor_unsuppress_map_cmd,
5861 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5862 NEIGHBOR_STR
5863 NEIGHBOR_ADDR_STR2
5864 "Route-map to selectively unsuppress suppressed routes\n"
5865 "Name of route map\n")
5866 {
5867 int idx_peer = 1;
5868 int idx_word = 3;
5869 return peer_unsuppress_map_set_vty(
5870 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5871 argv[idx_word]->arg);
5872 }
5873
5874 ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
5875 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5876 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5877 "Route-map to selectively unsuppress suppressed routes\n"
5878 "Name of route map\n")
5879
5880 DEFUN (no_neighbor_unsuppress_map,
5881 no_neighbor_unsuppress_map_cmd,
5882 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5883 NO_STR
5884 NEIGHBOR_STR
5885 NEIGHBOR_ADDR_STR2
5886 "Route-map to selectively unsuppress suppressed routes\n"
5887 "Name of route map\n")
5888 {
5889 int idx_peer = 2;
5890 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
5891 bgp_node_afi(vty),
5892 bgp_node_safi(vty));
5893 }
5894
5895 ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
5896 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5897 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5898 "Route-map to selectively unsuppress suppressed routes\n"
5899 "Name of route map\n")
5900
5901 static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
5902 afi_t afi, safi_t safi,
5903 const char *num_str,
5904 const char *threshold_str, int warning,
5905 const char *restart_str)
5906 {
5907 int ret;
5908 struct peer *peer;
5909 uint32_t max;
5910 uint8_t threshold;
5911 uint16_t restart;
5912
5913 peer = peer_and_group_lookup_vty(vty, ip_str);
5914 if (!peer)
5915 return CMD_WARNING_CONFIG_FAILED;
5916
5917 max = strtoul(num_str, NULL, 10);
5918 if (threshold_str)
5919 threshold = atoi(threshold_str);
5920 else
5921 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
5922
5923 if (restart_str)
5924 restart = atoi(restart_str);
5925 else
5926 restart = 0;
5927
5928 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
5929 restart);
5930
5931 return bgp_vty_return(vty, ret);
5932 }
5933
5934 static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
5935 afi_t afi, safi_t safi)
5936 {
5937 int ret;
5938 struct peer *peer;
5939
5940 peer = peer_and_group_lookup_vty(vty, ip_str);
5941 if (!peer)
5942 return CMD_WARNING_CONFIG_FAILED;
5943
5944 ret = peer_maximum_prefix_unset(peer, afi, safi);
5945
5946 return bgp_vty_return(vty, ret);
5947 }
5948
5949 /* Maximum number of prefix configuration. prefix count is different
5950 for each peer configuration. So this configuration can be set for
5951 each peer configuration. */
5952 DEFUN (neighbor_maximum_prefix,
5953 neighbor_maximum_prefix_cmd,
5954 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5955 NEIGHBOR_STR
5956 NEIGHBOR_ADDR_STR2
5957 "Maximum number of prefix accept from this peer\n"
5958 "maximum no. of prefix limit\n")
5959 {
5960 int idx_peer = 1;
5961 int idx_number = 3;
5962 return peer_maximum_prefix_set_vty(
5963 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5964 argv[idx_number]->arg, NULL, 0, NULL);
5965 }
5966
5967 ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
5968 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5969 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5970 "Maximum number of prefix accept from this peer\n"
5971 "maximum no. of prefix limit\n")
5972
5973 DEFUN (neighbor_maximum_prefix_threshold,
5974 neighbor_maximum_prefix_threshold_cmd,
5975 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5976 NEIGHBOR_STR
5977 NEIGHBOR_ADDR_STR2
5978 "Maximum number of prefix accept from this peer\n"
5979 "maximum no. of prefix limit\n"
5980 "Threshold value (%) at which to generate a warning msg\n")
5981 {
5982 int idx_peer = 1;
5983 int idx_number = 3;
5984 int idx_number_2 = 4;
5985 return peer_maximum_prefix_set_vty(
5986 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5987 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL);
5988 }
5989
5990 ALIAS_HIDDEN(
5991 neighbor_maximum_prefix_threshold,
5992 neighbor_maximum_prefix_threshold_hidden_cmd,
5993 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5994 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5995 "Maximum number of prefix accept from this peer\n"
5996 "maximum no. of prefix limit\n"
5997 "Threshold value (%) at which to generate a warning msg\n")
5998
5999 DEFUN (neighbor_maximum_prefix_warning,
6000 neighbor_maximum_prefix_warning_cmd,
6001 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
6002 NEIGHBOR_STR
6003 NEIGHBOR_ADDR_STR2
6004 "Maximum number of prefix accept from this peer\n"
6005 "maximum no. of prefix limit\n"
6006 "Only give warning message when limit is exceeded\n")
6007 {
6008 int idx_peer = 1;
6009 int idx_number = 3;
6010 return peer_maximum_prefix_set_vty(
6011 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6012 argv[idx_number]->arg, NULL, 1, NULL);
6013 }
6014
6015 ALIAS_HIDDEN(
6016 neighbor_maximum_prefix_warning,
6017 neighbor_maximum_prefix_warning_hidden_cmd,
6018 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
6019 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6020 "Maximum number of prefix accept from this peer\n"
6021 "maximum no. of prefix limit\n"
6022 "Only give warning message when limit is exceeded\n")
6023
6024 DEFUN (neighbor_maximum_prefix_threshold_warning,
6025 neighbor_maximum_prefix_threshold_warning_cmd,
6026 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
6027 NEIGHBOR_STR
6028 NEIGHBOR_ADDR_STR2
6029 "Maximum number of prefix accept from this peer\n"
6030 "maximum no. of prefix limit\n"
6031 "Threshold value (%) at which to generate a warning msg\n"
6032 "Only give warning message when limit is exceeded\n")
6033 {
6034 int idx_peer = 1;
6035 int idx_number = 3;
6036 int idx_number_2 = 4;
6037 return peer_maximum_prefix_set_vty(
6038 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6039 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL);
6040 }
6041
6042 ALIAS_HIDDEN(
6043 neighbor_maximum_prefix_threshold_warning,
6044 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
6045 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
6046 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6047 "Maximum number of prefix accept from this peer\n"
6048 "maximum no. of prefix limit\n"
6049 "Threshold value (%) at which to generate a warning msg\n"
6050 "Only give warning message when limit is exceeded\n")
6051
6052 DEFUN (neighbor_maximum_prefix_restart,
6053 neighbor_maximum_prefix_restart_cmd,
6054 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
6055 NEIGHBOR_STR
6056 NEIGHBOR_ADDR_STR2
6057 "Maximum number of prefix accept from this peer\n"
6058 "maximum no. of prefix limit\n"
6059 "Restart bgp connection after limit is exceeded\n"
6060 "Restart interval in minutes\n")
6061 {
6062 int idx_peer = 1;
6063 int idx_number = 3;
6064 int idx_number_2 = 5;
6065 return peer_maximum_prefix_set_vty(
6066 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6067 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg);
6068 }
6069
6070 ALIAS_HIDDEN(
6071 neighbor_maximum_prefix_restart,
6072 neighbor_maximum_prefix_restart_hidden_cmd,
6073 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
6074 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6075 "Maximum number of prefix accept from this peer\n"
6076 "maximum no. of prefix limit\n"
6077 "Restart bgp connection after limit is exceeded\n"
6078 "Restart interval in minutes\n")
6079
6080 DEFUN (neighbor_maximum_prefix_threshold_restart,
6081 neighbor_maximum_prefix_threshold_restart_cmd,
6082 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
6083 NEIGHBOR_STR
6084 NEIGHBOR_ADDR_STR2
6085 "Maximum number of prefixes to accept from this peer\n"
6086 "maximum no. of prefix limit\n"
6087 "Threshold value (%) at which to generate a warning msg\n"
6088 "Restart bgp connection after limit is exceeded\n"
6089 "Restart interval in minutes\n")
6090 {
6091 int idx_peer = 1;
6092 int idx_number = 3;
6093 int idx_number_2 = 4;
6094 int idx_number_3 = 6;
6095 return peer_maximum_prefix_set_vty(
6096 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6097 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
6098 argv[idx_number_3]->arg);
6099 }
6100
6101 ALIAS_HIDDEN(
6102 neighbor_maximum_prefix_threshold_restart,
6103 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
6104 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
6105 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6106 "Maximum number of prefixes to accept from this peer\n"
6107 "maximum no. of prefix limit\n"
6108 "Threshold value (%) at which to generate a warning msg\n"
6109 "Restart bgp connection after limit is exceeded\n"
6110 "Restart interval in minutes\n")
6111
6112 DEFUN (no_neighbor_maximum_prefix,
6113 no_neighbor_maximum_prefix_cmd,
6114 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
6115 NO_STR
6116 NEIGHBOR_STR
6117 NEIGHBOR_ADDR_STR2
6118 "Maximum number of prefixes to accept from this peer\n"
6119 "maximum no. of prefix limit\n"
6120 "Threshold value (%) at which to generate a warning msg\n"
6121 "Restart bgp connection after limit is exceeded\n"
6122 "Restart interval in minutes\n"
6123 "Only give warning message when limit is exceeded\n")
6124 {
6125 int idx_peer = 2;
6126 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
6127 bgp_node_afi(vty),
6128 bgp_node_safi(vty));
6129 }
6130
6131 ALIAS_HIDDEN(
6132 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
6133 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
6134 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6135 "Maximum number of prefixes to accept from this peer\n"
6136 "maximum no. of prefix limit\n"
6137 "Threshold value (%) at which to generate a warning msg\n"
6138 "Restart bgp connection after limit is exceeded\n"
6139 "Restart interval in minutes\n"
6140 "Only give warning message when limit is exceeded\n")
6141
6142
6143 /* "neighbor allowas-in" */
6144 DEFUN (neighbor_allowas_in,
6145 neighbor_allowas_in_cmd,
6146 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6147 NEIGHBOR_STR
6148 NEIGHBOR_ADDR_STR2
6149 "Accept as-path with my AS present in it\n"
6150 "Number of occurrences of AS number\n"
6151 "Only accept my AS in the as-path if the route was originated in my AS\n")
6152 {
6153 int idx_peer = 1;
6154 int idx_number_origin = 3;
6155 int ret;
6156 int origin = 0;
6157 struct peer *peer;
6158 int allow_num = 0;
6159
6160 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6161 if (!peer)
6162 return CMD_WARNING_CONFIG_FAILED;
6163
6164 if (argc <= idx_number_origin)
6165 allow_num = 3;
6166 else {
6167 if (argv[idx_number_origin]->type == WORD_TKN)
6168 origin = 1;
6169 else
6170 allow_num = atoi(argv[idx_number_origin]->arg);
6171 }
6172
6173 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6174 allow_num, origin);
6175
6176 return bgp_vty_return(vty, ret);
6177 }
6178
6179 ALIAS_HIDDEN(
6180 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
6181 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6182 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6183 "Accept as-path with my AS present in it\n"
6184 "Number of occurrences of AS number\n"
6185 "Only accept my AS in the as-path if the route was originated in my AS\n")
6186
6187 DEFUN (no_neighbor_allowas_in,
6188 no_neighbor_allowas_in_cmd,
6189 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6190 NO_STR
6191 NEIGHBOR_STR
6192 NEIGHBOR_ADDR_STR2
6193 "allow local ASN appears in aspath attribute\n"
6194 "Number of occurrences of AS number\n"
6195 "Only accept my AS in the as-path if the route was originated in my AS\n")
6196 {
6197 int idx_peer = 2;
6198 int ret;
6199 struct peer *peer;
6200
6201 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6202 if (!peer)
6203 return CMD_WARNING_CONFIG_FAILED;
6204
6205 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
6206 bgp_node_safi(vty));
6207
6208 return bgp_vty_return(vty, ret);
6209 }
6210
6211 ALIAS_HIDDEN(
6212 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
6213 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6214 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6215 "allow local ASN appears in aspath attribute\n"
6216 "Number of occurrences of AS number\n"
6217 "Only accept my AS in the as-path if the route was originated in my AS\n")
6218
6219 DEFUN (neighbor_ttl_security,
6220 neighbor_ttl_security_cmd,
6221 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
6222 NEIGHBOR_STR
6223 NEIGHBOR_ADDR_STR2
6224 "BGP ttl-security parameters\n"
6225 "Specify the maximum number of hops to the BGP peer\n"
6226 "Number of hops to BGP peer\n")
6227 {
6228 int idx_peer = 1;
6229 int idx_number = 4;
6230 struct peer *peer;
6231 int gtsm_hops;
6232
6233 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6234 if (!peer)
6235 return CMD_WARNING_CONFIG_FAILED;
6236
6237 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
6238
6239 /*
6240 * If 'neighbor swpX', then this is for directly connected peers,
6241 * we should not accept a ttl-security hops value greater than 1.
6242 */
6243 if (peer->conf_if && (gtsm_hops > 1)) {
6244 vty_out(vty,
6245 "%s is directly connected peer, hops cannot exceed 1\n",
6246 argv[idx_peer]->arg);
6247 return CMD_WARNING_CONFIG_FAILED;
6248 }
6249
6250 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
6251 }
6252
6253 DEFUN (no_neighbor_ttl_security,
6254 no_neighbor_ttl_security_cmd,
6255 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
6256 NO_STR
6257 NEIGHBOR_STR
6258 NEIGHBOR_ADDR_STR2
6259 "BGP ttl-security parameters\n"
6260 "Specify the maximum number of hops to the BGP peer\n"
6261 "Number of hops to BGP peer\n")
6262 {
6263 int idx_peer = 2;
6264 struct peer *peer;
6265
6266 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6267 if (!peer)
6268 return CMD_WARNING_CONFIG_FAILED;
6269
6270 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
6271 }
6272
6273 DEFUN (neighbor_addpath_tx_all_paths,
6274 neighbor_addpath_tx_all_paths_cmd,
6275 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6276 NEIGHBOR_STR
6277 NEIGHBOR_ADDR_STR2
6278 "Use addpath to advertise all paths to a neighbor\n")
6279 {
6280 int idx_peer = 1;
6281 struct peer *peer;
6282
6283 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6284 if (!peer)
6285 return CMD_WARNING_CONFIG_FAILED;
6286
6287 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6288 BGP_ADDPATH_ALL);
6289 return CMD_SUCCESS;
6290 }
6291
6292 ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
6293 neighbor_addpath_tx_all_paths_hidden_cmd,
6294 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6295 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6296 "Use addpath to advertise all paths to a neighbor\n")
6297
6298 DEFUN (no_neighbor_addpath_tx_all_paths,
6299 no_neighbor_addpath_tx_all_paths_cmd,
6300 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6301 NO_STR
6302 NEIGHBOR_STR
6303 NEIGHBOR_ADDR_STR2
6304 "Use addpath to advertise all paths to a neighbor\n")
6305 {
6306 int idx_peer = 2;
6307 struct peer *peer;
6308
6309 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6310 if (!peer)
6311 return CMD_WARNING_CONFIG_FAILED;
6312
6313 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
6314 != BGP_ADDPATH_ALL) {
6315 vty_out(vty,
6316 "%% Peer not currently configured to transmit all paths.");
6317 return CMD_WARNING_CONFIG_FAILED;
6318 }
6319
6320 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6321 BGP_ADDPATH_NONE);
6322
6323 return CMD_SUCCESS;
6324 }
6325
6326 ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
6327 no_neighbor_addpath_tx_all_paths_hidden_cmd,
6328 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6329 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6330 "Use addpath to advertise all paths to a neighbor\n")
6331
6332 DEFUN (neighbor_addpath_tx_bestpath_per_as,
6333 neighbor_addpath_tx_bestpath_per_as_cmd,
6334 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6335 NEIGHBOR_STR
6336 NEIGHBOR_ADDR_STR2
6337 "Use addpath to advertise the bestpath per each neighboring AS\n")
6338 {
6339 int idx_peer = 1;
6340 struct peer *peer;
6341
6342 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6343 if (!peer)
6344 return CMD_WARNING_CONFIG_FAILED;
6345
6346 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6347 BGP_ADDPATH_BEST_PER_AS);
6348
6349 return CMD_SUCCESS;
6350 }
6351
6352 ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
6353 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6354 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6355 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6356 "Use addpath to advertise the bestpath per each neighboring AS\n")
6357
6358 DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
6359 no_neighbor_addpath_tx_bestpath_per_as_cmd,
6360 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6361 NO_STR
6362 NEIGHBOR_STR
6363 NEIGHBOR_ADDR_STR2
6364 "Use addpath to advertise the bestpath per each neighboring AS\n")
6365 {
6366 int idx_peer = 2;
6367 struct peer *peer;
6368
6369 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6370 if (!peer)
6371 return CMD_WARNING_CONFIG_FAILED;
6372
6373 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
6374 != BGP_ADDPATH_BEST_PER_AS) {
6375 vty_out(vty,
6376 "%% Peer not currently configured to transmit all best path per as.");
6377 return CMD_WARNING_CONFIG_FAILED;
6378 }
6379
6380 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6381 BGP_ADDPATH_NONE);
6382
6383 return CMD_SUCCESS;
6384 }
6385
6386 ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
6387 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6388 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6389 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6390 "Use addpath to advertise the bestpath per each neighboring AS\n")
6391
6392 DEFPY(
6393 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
6394 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
6395 NEIGHBOR_STR
6396 NEIGHBOR_ADDR_STR2
6397 "Detect AS loops before sending to neighbor\n")
6398 {
6399 struct peer *peer;
6400
6401 peer = peer_and_group_lookup_vty(vty, neighbor);
6402 if (!peer)
6403 return CMD_WARNING_CONFIG_FAILED;
6404
6405 peer->as_path_loop_detection = true;
6406
6407 return CMD_SUCCESS;
6408 }
6409
6410 DEFPY(
6411 no_neighbor_aspath_loop_detection,
6412 no_neighbor_aspath_loop_detection_cmd,
6413 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
6414 NO_STR
6415 NEIGHBOR_STR
6416 NEIGHBOR_ADDR_STR2
6417 "Detect AS loops before sending to neighbor\n")
6418 {
6419 struct peer *peer;
6420
6421 peer = peer_and_group_lookup_vty(vty, neighbor);
6422 if (!peer)
6423 return CMD_WARNING_CONFIG_FAILED;
6424
6425 peer->as_path_loop_detection = false;
6426
6427 return CMD_SUCCESS;
6428 }
6429
6430 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
6431 struct ecommunity **list)
6432 {
6433 struct ecommunity *ecom = NULL;
6434 struct ecommunity *ecomadd;
6435
6436 for (; argc; --argc, ++argv) {
6437
6438 ecomadd = ecommunity_str2com(argv[0]->arg,
6439 ECOMMUNITY_ROUTE_TARGET, 0);
6440 if (!ecomadd) {
6441 vty_out(vty, "Malformed community-list value\n");
6442 if (ecom)
6443 ecommunity_free(&ecom);
6444 return CMD_WARNING_CONFIG_FAILED;
6445 }
6446
6447 if (ecom) {
6448 ecommunity_merge(ecom, ecomadd);
6449 ecommunity_free(&ecomadd);
6450 } else {
6451 ecom = ecomadd;
6452 }
6453 }
6454
6455 if (*list) {
6456 ecommunity_free(&*list);
6457 }
6458 *list = ecom;
6459
6460 return CMD_SUCCESS;
6461 }
6462
6463 /*
6464 * v2vimport is true if we are handling a `import vrf ...` command
6465 */
6466 static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
6467 {
6468 afi_t afi;
6469
6470 switch (vty->node) {
6471 case BGP_IPV4_NODE:
6472 afi = AFI_IP;
6473 break;
6474 case BGP_IPV6_NODE:
6475 afi = AFI_IP6;
6476 break;
6477 default:
6478 vty_out(vty,
6479 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
6480 return AFI_MAX;
6481 }
6482
6483 if (!v2vimport) {
6484 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6485 BGP_CONFIG_VRF_TO_VRF_IMPORT)
6486 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6487 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
6488 vty_out(vty,
6489 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
6490 return AFI_MAX;
6491 }
6492 } else {
6493 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6494 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
6495 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6496 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
6497 vty_out(vty,
6498 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
6499 return AFI_MAX;
6500 }
6501 }
6502 return afi;
6503 }
6504
6505 DEFPY (af_rd_vpn_export,
6506 af_rd_vpn_export_cmd,
6507 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
6508 NO_STR
6509 "Specify route distinguisher\n"
6510 "Between current address-family and vpn\n"
6511 "For routes leaked from current address-family to vpn\n"
6512 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
6513 {
6514 VTY_DECLVAR_CONTEXT(bgp, bgp);
6515 struct prefix_rd prd;
6516 int ret;
6517 afi_t afi;
6518 int idx = 0;
6519 int yes = 1;
6520
6521 if (argv_find(argv, argc, "no", &idx))
6522 yes = 0;
6523
6524 if (yes) {
6525 ret = str2prefix_rd(rd_str, &prd);
6526 if (!ret) {
6527 vty_out(vty, "%% Malformed rd\n");
6528 return CMD_WARNING_CONFIG_FAILED;
6529 }
6530 }
6531
6532 afi = vpn_policy_getafi(vty, bgp, false);
6533 if (afi == AFI_MAX)
6534 return CMD_WARNING_CONFIG_FAILED;
6535
6536 /*
6537 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6538 */
6539 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6540 bgp_get_default(), bgp);
6541
6542 if (yes) {
6543 bgp->vpn_policy[afi].tovpn_rd = prd;
6544 SET_FLAG(bgp->vpn_policy[afi].flags,
6545 BGP_VPN_POLICY_TOVPN_RD_SET);
6546 } else {
6547 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6548 BGP_VPN_POLICY_TOVPN_RD_SET);
6549 }
6550
6551 /* post-change: re-export vpn routes */
6552 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6553 bgp_get_default(), bgp);
6554
6555 return CMD_SUCCESS;
6556 }
6557
6558 ALIAS (af_rd_vpn_export,
6559 af_no_rd_vpn_export_cmd,
6560 "no rd vpn export",
6561 NO_STR
6562 "Specify route distinguisher\n"
6563 "Between current address-family and vpn\n"
6564 "For routes leaked from current address-family to vpn\n")
6565
6566 DEFPY (af_label_vpn_export,
6567 af_label_vpn_export_cmd,
6568 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
6569 NO_STR
6570 "label value for VRF\n"
6571 "Between current address-family and vpn\n"
6572 "For routes leaked from current address-family to vpn\n"
6573 "Label Value <0-1048575>\n"
6574 "Automatically assign a label\n")
6575 {
6576 VTY_DECLVAR_CONTEXT(bgp, bgp);
6577 mpls_label_t label = MPLS_LABEL_NONE;
6578 afi_t afi;
6579 int idx = 0;
6580 int yes = 1;
6581
6582 if (argv_find(argv, argc, "no", &idx))
6583 yes = 0;
6584
6585 /* If "no ...", squash trailing parameter */
6586 if (!yes)
6587 label_auto = NULL;
6588
6589 if (yes) {
6590 if (!label_auto)
6591 label = label_val; /* parser should force unsigned */
6592 }
6593
6594 afi = vpn_policy_getafi(vty, bgp, false);
6595 if (afi == AFI_MAX)
6596 return CMD_WARNING_CONFIG_FAILED;
6597
6598
6599 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6600 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
6601 /* no change */
6602 return CMD_SUCCESS;
6603
6604 /*
6605 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6606 */
6607 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6608 bgp_get_default(), bgp);
6609
6610 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6611 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
6612
6613 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
6614
6615 /*
6616 * label has previously been automatically
6617 * assigned by labelpool: release it
6618 *
6619 * NB if tovpn_label == MPLS_LABEL_NONE it
6620 * means the automatic assignment is in flight
6621 * and therefore the labelpool callback must
6622 * detect that the auto label is not needed.
6623 */
6624
6625 bgp_lp_release(LP_TYPE_VRF,
6626 &bgp->vpn_policy[afi],
6627 bgp->vpn_policy[afi].tovpn_label);
6628 }
6629 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6630 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6631 }
6632
6633 bgp->vpn_policy[afi].tovpn_label = label;
6634 if (label_auto) {
6635 SET_FLAG(bgp->vpn_policy[afi].flags,
6636 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6637 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
6638 vpn_leak_label_callback);
6639 }
6640
6641 /* post-change: re-export vpn routes */
6642 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6643 bgp_get_default(), bgp);
6644
6645 return CMD_SUCCESS;
6646 }
6647
6648 ALIAS (af_label_vpn_export,
6649 af_no_label_vpn_export_cmd,
6650 "no label vpn export",
6651 NO_STR
6652 "label value for VRF\n"
6653 "Between current address-family and vpn\n"
6654 "For routes leaked from current address-family to vpn\n")
6655
6656 DEFPY (af_nexthop_vpn_export,
6657 af_nexthop_vpn_export_cmd,
6658 "[no] nexthop vpn export <A.B.C.D|X:X::X:X>$nexthop_str",
6659 NO_STR
6660 "Specify next hop to use for VRF advertised prefixes\n"
6661 "Between current address-family and vpn\n"
6662 "For routes leaked from current address-family to vpn\n"
6663 "IPv4 prefix\n"
6664 "IPv6 prefix\n")
6665 {
6666 VTY_DECLVAR_CONTEXT(bgp, bgp);
6667 afi_t afi;
6668 struct prefix p;
6669 int idx = 0;
6670 int yes = 1;
6671
6672 if (argv_find(argv, argc, "no", &idx))
6673 yes = 0;
6674
6675 if (yes) {
6676 if (!sockunion2hostprefix(nexthop_str, &p))
6677 return CMD_WARNING_CONFIG_FAILED;
6678 }
6679
6680 afi = vpn_policy_getafi(vty, bgp, false);
6681 if (afi == AFI_MAX)
6682 return CMD_WARNING_CONFIG_FAILED;
6683
6684 /*
6685 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6686 */
6687 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6688 bgp_get_default(), bgp);
6689
6690 if (yes) {
6691 bgp->vpn_policy[afi].tovpn_nexthop = p;
6692 SET_FLAG(bgp->vpn_policy[afi].flags,
6693 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6694 } else {
6695 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6696 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6697 }
6698
6699 /* post-change: re-export vpn routes */
6700 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6701 bgp_get_default(), bgp);
6702
6703 return CMD_SUCCESS;
6704 }
6705
6706 ALIAS (af_nexthop_vpn_export,
6707 af_no_nexthop_vpn_export_cmd,
6708 "no nexthop vpn export",
6709 NO_STR
6710 "Specify next hop to use for VRF advertised prefixes\n"
6711 "Between current address-family and vpn\n"
6712 "For routes leaked from current address-family to vpn\n")
6713
6714 static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
6715 {
6716 if (!strcmp(dstr, "import")) {
6717 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6718 } else if (!strcmp(dstr, "export")) {
6719 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6720 } else if (!strcmp(dstr, "both")) {
6721 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6722 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6723 } else {
6724 vty_out(vty, "%% direction parse error\n");
6725 return CMD_WARNING_CONFIG_FAILED;
6726 }
6727 return CMD_SUCCESS;
6728 }
6729
6730 DEFPY (af_rt_vpn_imexport,
6731 af_rt_vpn_imexport_cmd,
6732 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
6733 NO_STR
6734 "Specify route target list\n"
6735 "Specify route target list\n"
6736 "Between current address-family and vpn\n"
6737 "For routes leaked from vpn to current address-family: match any\n"
6738 "For routes leaked from current address-family to vpn: set\n"
6739 "both import: match any and export: set\n"
6740 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6741 {
6742 VTY_DECLVAR_CONTEXT(bgp, bgp);
6743 int ret;
6744 struct ecommunity *ecom = NULL;
6745 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6746 vpn_policy_direction_t dir;
6747 afi_t afi;
6748 int idx = 0;
6749 int yes = 1;
6750
6751 if (argv_find(argv, argc, "no", &idx))
6752 yes = 0;
6753
6754 afi = vpn_policy_getafi(vty, bgp, false);
6755 if (afi == AFI_MAX)
6756 return CMD_WARNING_CONFIG_FAILED;
6757
6758 ret = vpn_policy_getdirs(vty, direction_str, dodir);
6759 if (ret != CMD_SUCCESS)
6760 return ret;
6761
6762 if (yes) {
6763 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6764 vty_out(vty, "%% Missing RTLIST\n");
6765 return CMD_WARNING_CONFIG_FAILED;
6766 }
6767 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6768 if (ret != CMD_SUCCESS) {
6769 return ret;
6770 }
6771 }
6772
6773 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6774 if (!dodir[dir])
6775 continue;
6776
6777 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6778
6779 if (yes) {
6780 if (bgp->vpn_policy[afi].rtlist[dir])
6781 ecommunity_free(
6782 &bgp->vpn_policy[afi].rtlist[dir]);
6783 bgp->vpn_policy[afi].rtlist[dir] =
6784 ecommunity_dup(ecom);
6785 } else {
6786 if (bgp->vpn_policy[afi].rtlist[dir])
6787 ecommunity_free(
6788 &bgp->vpn_policy[afi].rtlist[dir]);
6789 bgp->vpn_policy[afi].rtlist[dir] = NULL;
6790 }
6791
6792 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6793 }
6794
6795 if (ecom)
6796 ecommunity_free(&ecom);
6797
6798 return CMD_SUCCESS;
6799 }
6800
6801 ALIAS (af_rt_vpn_imexport,
6802 af_no_rt_vpn_imexport_cmd,
6803 "no <rt|route-target> vpn <import|export|both>$direction_str",
6804 NO_STR
6805 "Specify route target list\n"
6806 "Specify route target list\n"
6807 "Between current address-family and vpn\n"
6808 "For routes leaked from vpn to current address-family\n"
6809 "For routes leaked from current address-family to vpn\n"
6810 "both import and export\n")
6811
6812 DEFPY (af_route_map_vpn_imexport,
6813 af_route_map_vpn_imexport_cmd,
6814 /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
6815 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
6816 NO_STR
6817 "Specify route map\n"
6818 "Between current address-family and vpn\n"
6819 "For routes leaked from vpn to current address-family\n"
6820 "For routes leaked from current address-family to vpn\n"
6821 "name of route-map\n")
6822 {
6823 VTY_DECLVAR_CONTEXT(bgp, bgp);
6824 int ret;
6825 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6826 vpn_policy_direction_t dir;
6827 afi_t afi;
6828 int idx = 0;
6829 int yes = 1;
6830
6831 if (argv_find(argv, argc, "no", &idx))
6832 yes = 0;
6833
6834 afi = vpn_policy_getafi(vty, bgp, false);
6835 if (afi == AFI_MAX)
6836 return CMD_WARNING_CONFIG_FAILED;
6837
6838 ret = vpn_policy_getdirs(vty, direction_str, dodir);
6839 if (ret != CMD_SUCCESS)
6840 return ret;
6841
6842 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6843 if (!dodir[dir])
6844 continue;
6845
6846 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6847
6848 if (yes) {
6849 if (bgp->vpn_policy[afi].rmap_name[dir])
6850 XFREE(MTYPE_ROUTE_MAP_NAME,
6851 bgp->vpn_policy[afi].rmap_name[dir]);
6852 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
6853 MTYPE_ROUTE_MAP_NAME, rmap_str);
6854 bgp->vpn_policy[afi].rmap[dir] =
6855 route_map_lookup_warn_noexist(vty, rmap_str);
6856 if (!bgp->vpn_policy[afi].rmap[dir])
6857 return CMD_SUCCESS;
6858 } else {
6859 if (bgp->vpn_policy[afi].rmap_name[dir])
6860 XFREE(MTYPE_ROUTE_MAP_NAME,
6861 bgp->vpn_policy[afi].rmap_name[dir]);
6862 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6863 bgp->vpn_policy[afi].rmap[dir] = NULL;
6864 }
6865
6866 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6867 }
6868
6869 return CMD_SUCCESS;
6870 }
6871
6872 ALIAS (af_route_map_vpn_imexport,
6873 af_no_route_map_vpn_imexport_cmd,
6874 "no route-map vpn <import|export>$direction_str",
6875 NO_STR
6876 "Specify route map\n"
6877 "Between current address-family and vpn\n"
6878 "For routes leaked from vpn to current address-family\n"
6879 "For routes leaked from current address-family to vpn\n")
6880
6881 DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
6882 "[no] import vrf route-map RMAP$rmap_str",
6883 NO_STR
6884 "Import routes from another VRF\n"
6885 "Vrf routes being filtered\n"
6886 "Specify route map\n"
6887 "name of route-map\n")
6888 {
6889 VTY_DECLVAR_CONTEXT(bgp, bgp);
6890 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
6891 afi_t afi;
6892 int idx = 0;
6893 int yes = 1;
6894 struct bgp *bgp_default;
6895
6896 if (argv_find(argv, argc, "no", &idx))
6897 yes = 0;
6898
6899 afi = vpn_policy_getafi(vty, bgp, true);
6900 if (afi == AFI_MAX)
6901 return CMD_WARNING_CONFIG_FAILED;
6902
6903 bgp_default = bgp_get_default();
6904 if (!bgp_default) {
6905 int32_t ret;
6906 as_t as = bgp->as;
6907
6908 /* Auto-create assuming the same AS */
6909 ret = bgp_get(&bgp_default, &as, NULL,
6910 BGP_INSTANCE_TYPE_DEFAULT);
6911
6912 if (ret) {
6913 vty_out(vty,
6914 "VRF default is not configured as a bgp instance\n");
6915 return CMD_WARNING;
6916 }
6917 }
6918
6919 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6920
6921 if (yes) {
6922 if (bgp->vpn_policy[afi].rmap_name[dir])
6923 XFREE(MTYPE_ROUTE_MAP_NAME,
6924 bgp->vpn_policy[afi].rmap_name[dir]);
6925 bgp->vpn_policy[afi].rmap_name[dir] =
6926 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
6927 bgp->vpn_policy[afi].rmap[dir] =
6928 route_map_lookup_warn_noexist(vty, rmap_str);
6929 if (!bgp->vpn_policy[afi].rmap[dir])
6930 return CMD_SUCCESS;
6931 } else {
6932 if (bgp->vpn_policy[afi].rmap_name[dir])
6933 XFREE(MTYPE_ROUTE_MAP_NAME,
6934 bgp->vpn_policy[afi].rmap_name[dir]);
6935 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6936 bgp->vpn_policy[afi].rmap[dir] = NULL;
6937 }
6938
6939 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6940
6941 return CMD_SUCCESS;
6942 }
6943
6944 ALIAS(af_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
6945 "no import vrf route-map",
6946 NO_STR
6947 "Import routes from another VRF\n"
6948 "Vrf routes being filtered\n"
6949 "Specify route map\n")
6950
6951 DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
6952 "[no] import vrf VIEWVRFNAME$import_name",
6953 NO_STR
6954 "Import routes from another VRF\n"
6955 "VRF to import from\n"
6956 "The name of the VRF\n")
6957 {
6958 VTY_DECLVAR_CONTEXT(bgp, bgp);
6959 struct listnode *node;
6960 struct bgp *vrf_bgp, *bgp_default;
6961 int32_t ret = 0;
6962 as_t as = bgp->as;
6963 bool remove = false;
6964 int32_t idx = 0;
6965 char *vname;
6966 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
6967 safi_t safi;
6968 afi_t afi;
6969
6970 if (import_name == NULL) {
6971 vty_out(vty, "%% Missing import name\n");
6972 return CMD_WARNING;
6973 }
6974
6975 if (argv_find(argv, argc, "no", &idx))
6976 remove = true;
6977
6978 afi = vpn_policy_getafi(vty, bgp, true);
6979 if (afi == AFI_MAX)
6980 return CMD_WARNING_CONFIG_FAILED;
6981
6982 safi = bgp_node_safi(vty);
6983
6984 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
6985 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
6986 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
6987 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
6988 remove ? "unimport" : "import", import_name);
6989 return CMD_WARNING;
6990 }
6991
6992 bgp_default = bgp_get_default();
6993 if (!bgp_default) {
6994 /* Auto-create assuming the same AS */
6995 ret = bgp_get(&bgp_default, &as, NULL,
6996 BGP_INSTANCE_TYPE_DEFAULT);
6997
6998 if (ret) {
6999 vty_out(vty,
7000 "VRF default is not configured as a bgp instance\n");
7001 return CMD_WARNING;
7002 }
7003 }
7004
7005 vrf_bgp = bgp_lookup_by_name(import_name);
7006 if (!vrf_bgp) {
7007 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
7008 vrf_bgp = bgp_default;
7009 else
7010 /* Auto-create assuming the same AS */
7011 ret = bgp_get(&vrf_bgp, &as, import_name, bgp_type);
7012
7013 if (ret) {
7014 vty_out(vty,
7015 "VRF %s is not configured as a bgp instance\n",
7016 import_name);
7017 return CMD_WARNING;
7018 }
7019 }
7020
7021 if (remove) {
7022 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
7023 } else {
7024 /* Already importing from "import_vrf"? */
7025 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
7026 vname)) {
7027 if (strcmp(vname, import_name) == 0)
7028 return CMD_WARNING;
7029 }
7030
7031 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
7032 }
7033
7034 return CMD_SUCCESS;
7035 }
7036
7037 /* This command is valid only in a bgp vrf instance or the default instance */
7038 DEFPY (bgp_imexport_vpn,
7039 bgp_imexport_vpn_cmd,
7040 "[no] <import|export>$direction_str vpn",
7041 NO_STR
7042 "Import routes to this address-family\n"
7043 "Export routes from this address-family\n"
7044 "to/from default instance VPN RIB\n")
7045 {
7046 VTY_DECLVAR_CONTEXT(bgp, bgp);
7047 int previous_state;
7048 afi_t afi;
7049 safi_t safi;
7050 int idx = 0;
7051 int yes = 1;
7052 int flag;
7053 vpn_policy_direction_t dir;
7054
7055 if (argv_find(argv, argc, "no", &idx))
7056 yes = 0;
7057
7058 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
7059 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
7060
7061 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
7062 return CMD_WARNING_CONFIG_FAILED;
7063 }
7064
7065 afi = bgp_node_afi(vty);
7066 safi = bgp_node_safi(vty);
7067 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
7068 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
7069 return CMD_WARNING_CONFIG_FAILED;
7070 }
7071
7072 if (!strcmp(direction_str, "import")) {
7073 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
7074 dir = BGP_VPN_POLICY_DIR_FROMVPN;
7075 } else if (!strcmp(direction_str, "export")) {
7076 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
7077 dir = BGP_VPN_POLICY_DIR_TOVPN;
7078 } else {
7079 vty_out(vty, "%% unknown direction %s\n", direction_str);
7080 return CMD_WARNING_CONFIG_FAILED;
7081 }
7082
7083 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
7084
7085 if (yes) {
7086 SET_FLAG(bgp->af_flags[afi][safi], flag);
7087 if (!previous_state) {
7088 /* trigger export current vrf */
7089 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
7090 }
7091 } else {
7092 if (previous_state) {
7093 /* trigger un-export current vrf */
7094 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
7095 }
7096 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
7097 }
7098
7099 return CMD_SUCCESS;
7100 }
7101
7102 DEFPY (af_routetarget_import,
7103 af_routetarget_import_cmd,
7104 "[no] <rt|route-target> redirect import RTLIST...",
7105 NO_STR
7106 "Specify route target list\n"
7107 "Specify route target list\n"
7108 "Flow-spec redirect type route target\n"
7109 "Import routes to this address-family\n"
7110 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
7111 {
7112 VTY_DECLVAR_CONTEXT(bgp, bgp);
7113 int ret;
7114 struct ecommunity *ecom = NULL;
7115 afi_t afi;
7116 int idx = 0;
7117 int yes = 1;
7118
7119 if (argv_find(argv, argc, "no", &idx))
7120 yes = 0;
7121
7122 afi = vpn_policy_getafi(vty, bgp, false);
7123 if (afi == AFI_MAX)
7124 return CMD_WARNING_CONFIG_FAILED;
7125
7126 if (yes) {
7127 if (!argv_find(argv, argc, "RTLIST", &idx)) {
7128 vty_out(vty, "%% Missing RTLIST\n");
7129 return CMD_WARNING_CONFIG_FAILED;
7130 }
7131 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
7132 if (ret != CMD_SUCCESS)
7133 return ret;
7134 }
7135
7136 if (yes) {
7137 if (bgp->vpn_policy[afi].import_redirect_rtlist)
7138 ecommunity_free(&bgp->vpn_policy[afi]
7139 .import_redirect_rtlist);
7140 bgp->vpn_policy[afi].import_redirect_rtlist =
7141 ecommunity_dup(ecom);
7142 } else {
7143 if (bgp->vpn_policy[afi].import_redirect_rtlist)
7144 ecommunity_free(&bgp->vpn_policy[afi]
7145 .import_redirect_rtlist);
7146 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
7147 }
7148
7149 if (ecom)
7150 ecommunity_free(&ecom);
7151
7152 return CMD_SUCCESS;
7153 }
7154
7155 DEFUN_NOSH (address_family_ipv4_safi,
7156 address_family_ipv4_safi_cmd,
7157 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
7158 "Enter Address Family command mode\n"
7159 "Address Family\n"
7160 BGP_SAFI_WITH_LABEL_HELP_STR)
7161 {
7162
7163 if (argc == 3) {
7164 VTY_DECLVAR_CONTEXT(bgp, bgp);
7165 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
7166 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
7167 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
7168 && safi != SAFI_EVPN) {
7169 vty_out(vty,
7170 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
7171 return CMD_WARNING_CONFIG_FAILED;
7172 }
7173 vty->node = bgp_node_type(AFI_IP, safi);
7174 } else
7175 vty->node = BGP_IPV4_NODE;
7176
7177 return CMD_SUCCESS;
7178 }
7179
7180 DEFUN_NOSH (address_family_ipv6_safi,
7181 address_family_ipv6_safi_cmd,
7182 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
7183 "Enter Address Family command mode\n"
7184 "Address Family\n"
7185 BGP_SAFI_WITH_LABEL_HELP_STR)
7186 {
7187 if (argc == 3) {
7188 VTY_DECLVAR_CONTEXT(bgp, bgp);
7189 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
7190 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
7191 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
7192 && safi != SAFI_EVPN) {
7193 vty_out(vty,
7194 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
7195 return CMD_WARNING_CONFIG_FAILED;
7196 }
7197 vty->node = bgp_node_type(AFI_IP6, safi);
7198 } else
7199 vty->node = BGP_IPV6_NODE;
7200
7201 return CMD_SUCCESS;
7202 }
7203
7204 #ifdef KEEP_OLD_VPN_COMMANDS
7205 DEFUN_NOSH (address_family_vpnv4,
7206 address_family_vpnv4_cmd,
7207 "address-family vpnv4 [unicast]",
7208 "Enter Address Family command mode\n"
7209 "Address Family\n"
7210 "Address Family modifier\n")
7211 {
7212 vty->node = BGP_VPNV4_NODE;
7213 return CMD_SUCCESS;
7214 }
7215
7216 DEFUN_NOSH (address_family_vpnv6,
7217 address_family_vpnv6_cmd,
7218 "address-family vpnv6 [unicast]",
7219 "Enter Address Family command mode\n"
7220 "Address Family\n"
7221 "Address Family modifier\n")
7222 {
7223 vty->node = BGP_VPNV6_NODE;
7224 return CMD_SUCCESS;
7225 }
7226 #endif /* KEEP_OLD_VPN_COMMANDS */
7227
7228 DEFUN_NOSH (address_family_evpn,
7229 address_family_evpn_cmd,
7230 "address-family l2vpn evpn",
7231 "Enter Address Family command mode\n"
7232 "Address Family\n"
7233 "Address Family modifier\n")
7234 {
7235 VTY_DECLVAR_CONTEXT(bgp, bgp);
7236 vty->node = BGP_EVPN_NODE;
7237 return CMD_SUCCESS;
7238 }
7239
7240 DEFUN_NOSH (exit_address_family,
7241 exit_address_family_cmd,
7242 "exit-address-family",
7243 "Exit from Address Family configuration mode\n")
7244 {
7245 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
7246 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
7247 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
7248 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
7249 || vty->node == BGP_EVPN_NODE
7250 || vty->node == BGP_FLOWSPECV4_NODE
7251 || vty->node == BGP_FLOWSPECV6_NODE)
7252 vty->node = BGP_NODE;
7253 return CMD_SUCCESS;
7254 }
7255
7256 /* Recalculate bestpath and re-advertise a prefix */
7257 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
7258 const char *ip_str, afi_t afi, safi_t safi,
7259 struct prefix_rd *prd)
7260 {
7261 int ret;
7262 struct prefix match;
7263 struct bgp_node *rn;
7264 struct bgp_node *rm;
7265 struct bgp *bgp;
7266 struct bgp_table *table;
7267 struct bgp_table *rib;
7268
7269 /* BGP structure lookup. */
7270 if (view_name) {
7271 bgp = bgp_lookup_by_name(view_name);
7272 if (bgp == NULL) {
7273 vty_out(vty, "%% Can't find BGP instance %s\n",
7274 view_name);
7275 return CMD_WARNING;
7276 }
7277 } else {
7278 bgp = bgp_get_default();
7279 if (bgp == NULL) {
7280 vty_out(vty, "%% No BGP process is configured\n");
7281 return CMD_WARNING;
7282 }
7283 }
7284
7285 /* Check IP address argument. */
7286 ret = str2prefix(ip_str, &match);
7287 if (!ret) {
7288 vty_out(vty, "%% address is malformed\n");
7289 return CMD_WARNING;
7290 }
7291
7292 match.family = afi2family(afi);
7293 rib = bgp->rib[afi][safi];
7294
7295 if (safi == SAFI_MPLS_VPN) {
7296 for (rn = bgp_table_top(rib); rn; rn = bgp_route_next(rn)) {
7297 if (prd && memcmp(rn->p.u.val, prd->val, 8) != 0)
7298 continue;
7299
7300 table = bgp_node_get_bgp_table_info(rn);
7301 if (table != NULL) {
7302
7303 if ((rm = bgp_node_match(table, &match))
7304 != NULL) {
7305 if (rm->p.prefixlen
7306 == match.prefixlen) {
7307 SET_FLAG(rm->flags,
7308 BGP_NODE_USER_CLEAR);
7309 bgp_process(bgp, rm, afi, safi);
7310 }
7311 bgp_unlock_node(rm);
7312 }
7313 }
7314 }
7315 } else {
7316 if ((rn = bgp_node_match(rib, &match)) != NULL) {
7317 if (rn->p.prefixlen == match.prefixlen) {
7318 SET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
7319 bgp_process(bgp, rn, afi, safi);
7320 }
7321 bgp_unlock_node(rn);
7322 }
7323 }
7324
7325 return CMD_SUCCESS;
7326 }
7327
7328 /* one clear bgp command to rule them all */
7329 DEFUN (clear_ip_bgp_all,
7330 clear_ip_bgp_all_cmd,
7331 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6|l2vpn> [<unicast|multicast|vpn|labeled-unicast|flowspec|evpn>]] <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> [<soft [<in|out>]|in [prefix-filter]|out>]",
7332 CLEAR_STR
7333 IP_STR
7334 BGP_STR
7335 BGP_INSTANCE_HELP_STR
7336 BGP_AFI_HELP_STR
7337 "Address Family\n"
7338 BGP_SAFI_WITH_LABEL_HELP_STR
7339 "Address Family modifier\n"
7340 "Clear all peers\n"
7341 "BGP neighbor address to clear\n"
7342 "BGP IPv6 neighbor to clear\n"
7343 "BGP neighbor on interface to clear\n"
7344 "Clear peers with the AS number\n"
7345 "Clear all external peers\n"
7346 "Clear all members of peer-group\n"
7347 "BGP peer-group name\n"
7348 BGP_SOFT_STR
7349 BGP_SOFT_IN_STR
7350 BGP_SOFT_OUT_STR
7351 BGP_SOFT_IN_STR
7352 "Push out prefix-list ORF and do inbound soft reconfig\n"
7353 BGP_SOFT_OUT_STR)
7354 {
7355 char *vrf = NULL;
7356
7357 afi_t afi = AFI_UNSPEC;
7358 safi_t safi = SAFI_UNSPEC;
7359 enum clear_sort clr_sort = clear_peer;
7360 enum bgp_clear_type clr_type;
7361 char *clr_arg = NULL;
7362
7363 int idx = 0;
7364
7365 /* clear [ip] bgp */
7366 if (argv_find(argv, argc, "ip", &idx))
7367 afi = AFI_IP;
7368
7369 /* [<vrf> VIEWVRFNAME] */
7370 if (argv_find(argv, argc, "vrf", &idx)) {
7371 vrf = argv[idx + 1]->arg;
7372 idx += 2;
7373 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
7374 vrf = NULL;
7375 } else if (argv_find(argv, argc, "view", &idx)) {
7376 /* [<view> VIEWVRFNAME] */
7377 vrf = argv[idx + 1]->arg;
7378 idx += 2;
7379 }
7380 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
7381 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
7382 argv_find_and_parse_safi(argv, argc, &idx, &safi);
7383
7384 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
7385 if (argv_find(argv, argc, "*", &idx)) {
7386 clr_sort = clear_all;
7387 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7388 clr_sort = clear_peer;
7389 clr_arg = argv[idx]->arg;
7390 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
7391 clr_sort = clear_peer;
7392 clr_arg = argv[idx]->arg;
7393 } else if (argv_find(argv, argc, "peer-group", &idx)) {
7394 clr_sort = clear_group;
7395 idx++;
7396 clr_arg = argv[idx]->arg;
7397 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
7398 clr_sort = clear_peer;
7399 clr_arg = argv[idx]->arg;
7400 } else if (argv_find(argv, argc, "WORD", &idx)) {
7401 clr_sort = clear_peer;
7402 clr_arg = argv[idx]->arg;
7403 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
7404 clr_sort = clear_as;
7405 clr_arg = argv[idx]->arg;
7406 } else if (argv_find(argv, argc, "external", &idx)) {
7407 clr_sort = clear_external;
7408 }
7409
7410 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
7411 if (argv_find(argv, argc, "soft", &idx)) {
7412 if (argv_find(argv, argc, "in", &idx)
7413 || argv_find(argv, argc, "out", &idx))
7414 clr_type = strmatch(argv[idx]->text, "in")
7415 ? BGP_CLEAR_SOFT_IN
7416 : BGP_CLEAR_SOFT_OUT;
7417 else
7418 clr_type = BGP_CLEAR_SOFT_BOTH;
7419 } else if (argv_find(argv, argc, "in", &idx)) {
7420 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
7421 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
7422 : BGP_CLEAR_SOFT_IN;
7423 } else if (argv_find(argv, argc, "out", &idx)) {
7424 clr_type = BGP_CLEAR_SOFT_OUT;
7425 } else
7426 clr_type = BGP_CLEAR_SOFT_NONE;
7427
7428 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
7429 }
7430
7431 DEFUN (clear_ip_bgp_prefix,
7432 clear_ip_bgp_prefix_cmd,
7433 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
7434 CLEAR_STR
7435 IP_STR
7436 BGP_STR
7437 BGP_INSTANCE_HELP_STR
7438 "Clear bestpath and re-advertise\n"
7439 "IPv4 prefix\n")
7440 {
7441 char *vrf = NULL;
7442 char *prefix = NULL;
7443
7444 int idx = 0;
7445
7446 /* [<view|vrf> VIEWVRFNAME] */
7447 if (argv_find(argv, argc, "vrf", &idx)) {
7448 vrf = argv[idx + 1]->arg;
7449 idx += 2;
7450 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
7451 vrf = NULL;
7452 } else if (argv_find(argv, argc, "view", &idx)) {
7453 /* [<view> VIEWVRFNAME] */
7454 vrf = argv[idx + 1]->arg;
7455 idx += 2;
7456 }
7457
7458 prefix = argv[argc - 1]->arg;
7459
7460 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
7461 }
7462
7463 DEFUN (clear_bgp_ipv6_safi_prefix,
7464 clear_bgp_ipv6_safi_prefix_cmd,
7465 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
7466 CLEAR_STR
7467 IP_STR
7468 BGP_STR
7469 "Address Family\n"
7470 BGP_SAFI_HELP_STR
7471 "Clear bestpath and re-advertise\n"
7472 "IPv6 prefix\n")
7473 {
7474 int idx_safi = 0;
7475 int idx_ipv6_prefix = 0;
7476 safi_t safi = SAFI_UNICAST;
7477 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7478 argv[idx_ipv6_prefix]->arg : NULL;
7479
7480 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7481 return bgp_clear_prefix(
7482 vty, NULL, prefix, AFI_IP6,
7483 safi, NULL);
7484 }
7485
7486 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
7487 clear_bgp_instance_ipv6_safi_prefix_cmd,
7488 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
7489 CLEAR_STR
7490 IP_STR
7491 BGP_STR
7492 BGP_INSTANCE_HELP_STR
7493 "Address Family\n"
7494 BGP_SAFI_HELP_STR
7495 "Clear bestpath and re-advertise\n"
7496 "IPv6 prefix\n")
7497 {
7498 int idx_safi = 0;
7499 int idx_vrfview = 0;
7500 int idx_ipv6_prefix = 0;
7501 safi_t safi = SAFI_UNICAST;
7502 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7503 argv[idx_ipv6_prefix]->arg : NULL;
7504 char *vrfview = NULL;
7505
7506 /* [<view|vrf> VIEWVRFNAME] */
7507 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
7508 vrfview = argv[idx_vrfview + 1]->arg;
7509 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
7510 vrfview = NULL;
7511 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
7512 /* [<view> VIEWVRFNAME] */
7513 vrfview = argv[idx_vrfview + 1]->arg;
7514 }
7515 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7516
7517 return bgp_clear_prefix(
7518 vty, vrfview, prefix,
7519 AFI_IP6, safi, NULL);
7520 }
7521
7522 DEFUN (show_bgp_views,
7523 show_bgp_views_cmd,
7524 "show [ip] bgp views",
7525 SHOW_STR
7526 IP_STR
7527 BGP_STR
7528 "Show the defined BGP views\n")
7529 {
7530 struct list *inst = bm->bgp;
7531 struct listnode *node;
7532 struct bgp *bgp;
7533
7534 vty_out(vty, "Defined BGP views:\n");
7535 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7536 /* Skip VRFs. */
7537 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
7538 continue;
7539 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
7540 bgp->as);
7541 }
7542
7543 return CMD_SUCCESS;
7544 }
7545
7546 DEFUN (show_bgp_vrfs,
7547 show_bgp_vrfs_cmd,
7548 "show [ip] bgp vrfs [json]",
7549 SHOW_STR
7550 IP_STR
7551 BGP_STR
7552 "Show BGP VRFs\n"
7553 JSON_STR)
7554 {
7555 char buf[ETHER_ADDR_STRLEN];
7556 struct list *inst = bm->bgp;
7557 struct listnode *node;
7558 struct bgp *bgp;
7559 bool uj = use_json(argc, argv);
7560 json_object *json = NULL;
7561 json_object *json_vrfs = NULL;
7562 int count = 0;
7563
7564 if (uj) {
7565 json = json_object_new_object();
7566 json_vrfs = json_object_new_object();
7567 }
7568
7569 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7570 const char *name, *type;
7571 struct peer *peer;
7572 struct listnode *node2, *nnode2;
7573 int peers_cfg, peers_estb;
7574 json_object *json_vrf = NULL;
7575
7576 /* Skip Views. */
7577 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
7578 continue;
7579
7580 count++;
7581 if (!uj && count == 1) {
7582 vty_out(vty,
7583 "%4s %-5s %-16s %9s %10s %-37s\n",
7584 "Type", "Id", "routerId", "#PeersVfg",
7585 "#PeersEstb", "Name");
7586 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
7587 "L3-VNI", "RouterMAC", "Interface");
7588 }
7589
7590 peers_cfg = peers_estb = 0;
7591 if (uj)
7592 json_vrf = json_object_new_object();
7593
7594
7595 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
7596 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7597 continue;
7598 peers_cfg++;
7599 if (peer->status == Established)
7600 peers_estb++;
7601 }
7602
7603 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
7604 name = VRF_DEFAULT_NAME;
7605 type = "DFLT";
7606 } else {
7607 name = bgp->name;
7608 type = "VRF";
7609 }
7610
7611
7612 if (uj) {
7613 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7614 ? -1
7615 : (int64_t)bgp->vrf_id;
7616 json_object_string_add(json_vrf, "type", type);
7617 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
7618 json_object_string_add(json_vrf, "routerId",
7619 inet_ntoa(bgp->router_id));
7620 json_object_int_add(json_vrf, "numConfiguredPeers",
7621 peers_cfg);
7622 json_object_int_add(json_vrf, "numEstablishedPeers",
7623 peers_estb);
7624
7625 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
7626 json_object_string_add(
7627 json_vrf, "rmac",
7628 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
7629 json_object_string_add(json_vrf, "interface",
7630 ifindex2ifname(bgp->l3vni_svi_ifindex,
7631 bgp->vrf_id));
7632 json_object_object_add(json_vrfs, name, json_vrf);
7633 } else {
7634 vty_out(vty,
7635 "%4s %-5d %-16s %-9u %-10u %-37s\n",
7636 type,
7637 bgp->vrf_id == VRF_UNKNOWN ? -1
7638 : (int)bgp->vrf_id,
7639 inet_ntoa(bgp->router_id), peers_cfg,
7640 peers_estb, name);
7641 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
7642 bgp->l3vni,
7643 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
7644 ifindex2ifname(bgp->l3vni_svi_ifindex,
7645 bgp->vrf_id));
7646 }
7647 }
7648
7649 if (uj) {
7650 json_object_object_add(json, "vrfs", json_vrfs);
7651
7652 json_object_int_add(json, "totalVrfs", count);
7653
7654 vty_out(vty, "%s\n", json_object_to_json_string_ext(
7655 json, JSON_C_TO_STRING_PRETTY));
7656 json_object_free(json);
7657 } else {
7658 if (count)
7659 vty_out(vty,
7660 "\nTotal number of VRFs (including default): %d\n",
7661 count);
7662 }
7663
7664 return CMD_SUCCESS;
7665 }
7666
7667 DEFUN (show_bgp_mac_hash,
7668 show_bgp_mac_hash_cmd,
7669 "show bgp mac hash",
7670 SHOW_STR
7671 BGP_STR
7672 "Mac Address\n"
7673 "Mac Address database\n")
7674 {
7675 bgp_mac_dump_table(vty);
7676
7677 return CMD_SUCCESS;
7678 }
7679
7680 static void show_tip_entry(struct hash_bucket *bucket, void *args)
7681 {
7682 struct vty *vty = (struct vty *)args;
7683 struct tip_addr *tip = (struct tip_addr *)bucket->data;
7684
7685 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(tip->addr),
7686 tip->refcnt);
7687 }
7688
7689 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
7690 {
7691 vty_out(vty, "self nexthop database:\n");
7692 bgp_nexthop_show_address_hash(vty, bgp);
7693
7694 vty_out(vty, "Tunnel-ip database:\n");
7695 hash_iterate(bgp->tip_hash,
7696 (void (*)(struct hash_bucket *, void *))show_tip_entry,
7697 vty);
7698 }
7699
7700 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
7701 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
7702 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
7703 "martian next-hops\n"
7704 "martian next-hop database\n")
7705 {
7706 struct bgp *bgp = NULL;
7707 int idx = 0;
7708 char *name = NULL;
7709
7710 /* [<vrf> VIEWVRFNAME] */
7711 if (argv_find(argv, argc, "vrf", &idx)) {
7712 name = argv[idx + 1]->arg;
7713 if (name && strmatch(name, VRF_DEFAULT_NAME))
7714 name = NULL;
7715 } else if (argv_find(argv, argc, "view", &idx))
7716 /* [<view> VIEWVRFNAME] */
7717 name = argv[idx + 1]->arg;
7718 if (name)
7719 bgp = bgp_lookup_by_name(name);
7720 else
7721 bgp = bgp_get_default();
7722
7723 if (!bgp) {
7724 vty_out(vty, "%% No BGP process is configured\n");
7725 return CMD_WARNING;
7726 }
7727 bgp_show_martian_nexthops(vty, bgp);
7728
7729 return CMD_SUCCESS;
7730 }
7731
7732 DEFUN (show_bgp_memory,
7733 show_bgp_memory_cmd,
7734 "show [ip] bgp memory",
7735 SHOW_STR
7736 IP_STR
7737 BGP_STR
7738 "Global BGP memory statistics\n")
7739 {
7740 char memstrbuf[MTYPE_MEMSTR_LEN];
7741 unsigned long count;
7742
7743 /* RIB related usage stats */
7744 count = mtype_stats_alloc(MTYPE_BGP_NODE);
7745 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
7746 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7747 count * sizeof(struct bgp_node)));
7748
7749 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
7750 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
7751 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7752 count * sizeof(struct bgp_path_info)));
7753 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
7754 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
7755 count,
7756 mtype_memstr(
7757 memstrbuf, sizeof(memstrbuf),
7758 count * sizeof(struct bgp_path_info_extra)));
7759
7760 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
7761 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
7762 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7763 count * sizeof(struct bgp_static)));
7764
7765 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
7766 vty_out(vty, "%ld Packets, using %s of memory\n", count,
7767 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7768 count * sizeof(struct bpacket)));
7769
7770 /* Adj-In/Out */
7771 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
7772 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
7773 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7774 count * sizeof(struct bgp_adj_in)));
7775 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
7776 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
7777 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7778 count * sizeof(struct bgp_adj_out)));
7779
7780 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
7781 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
7782 count,
7783 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7784 count * sizeof(struct bgp_nexthop_cache)));
7785
7786 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
7787 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
7788 count,
7789 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7790 count * sizeof(struct bgp_damp_info)));
7791
7792 /* Attributes */
7793 count = attr_count();
7794 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
7795 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7796 count * sizeof(struct attr)));
7797
7798 if ((count = attr_unknown_count()))
7799 vty_out(vty, "%ld unknown attributes\n", count);
7800
7801 /* AS_PATH attributes */
7802 count = aspath_count();
7803 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
7804 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7805 count * sizeof(struct aspath)));
7806
7807 count = mtype_stats_alloc(MTYPE_AS_SEG);
7808 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
7809 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7810 count * sizeof(struct assegment)));
7811
7812 /* Other attributes */
7813 if ((count = community_count()))
7814 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
7815 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7816 count * sizeof(struct community)));
7817 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
7818 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
7819 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7820 count * sizeof(struct ecommunity)));
7821 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
7822 vty_out(vty,
7823 "%ld BGP large-community entries, using %s of memory\n",
7824 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7825 count * sizeof(struct lcommunity)));
7826
7827 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
7828 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
7829 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7830 count * sizeof(struct cluster_list)));
7831
7832 /* Peer related usage */
7833 count = mtype_stats_alloc(MTYPE_BGP_PEER);
7834 vty_out(vty, "%ld peers, using %s of memory\n", count,
7835 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7836 count * sizeof(struct peer)));
7837
7838 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
7839 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
7840 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7841 count * sizeof(struct peer_group)));
7842
7843 /* Other */
7844 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
7845 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
7846 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7847 count * sizeof(regex_t)));
7848 return CMD_SUCCESS;
7849 }
7850
7851 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
7852 {
7853 json_object *bestpath = json_object_new_object();
7854
7855 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_IGNORE))
7856 json_object_string_add(bestpath, "asPath", "ignore");
7857
7858 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_CONFED))
7859 json_object_string_add(bestpath, "asPath", "confed");
7860
7861 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
7862 if (bgp_flag_check(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
7863 json_object_string_add(bestpath, "multiPathRelax",
7864 "as-set");
7865 else
7866 json_object_string_add(bestpath, "multiPathRelax",
7867 "true");
7868 } else
7869 json_object_string_add(bestpath, "multiPathRelax", "false");
7870
7871 if (bgp_flag_check(bgp, BGP_FLAG_COMPARE_ROUTER_ID))
7872 json_object_string_add(bestpath, "compareRouterId", "true");
7873 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED)
7874 || bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST)) {
7875 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED))
7876 json_object_string_add(bestpath, "med", "confed");
7877 if (bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST))
7878 json_object_string_add(bestpath, "med",
7879 "missing-as-worst");
7880 else
7881 json_object_string_add(bestpath, "med", "true");
7882 }
7883
7884 json_object_object_add(json, "bestPath", bestpath);
7885 }
7886
7887 /* Print the error code/subcode for why the peer is down */
7888 static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
7889 json_object *json_peer, bool use_json)
7890 {
7891 const char *code_str;
7892 const char *subcode_str;
7893
7894 if (use_json) {
7895 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
7896 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
7897 char errorcodesubcode_hexstr[5];
7898 char errorcodesubcode_str[256];
7899
7900 code_str = bgp_notify_code_str(peer->notify.code);
7901 subcode_str = bgp_notify_subcode_str(
7902 peer->notify.code,
7903 peer->notify.subcode);
7904
7905 sprintf(errorcodesubcode_hexstr, "%02X%02X",
7906 peer->notify.code, peer->notify.subcode);
7907 json_object_string_add(json_peer,
7908 "lastErrorCodeSubcode",
7909 errorcodesubcode_hexstr);
7910 snprintf(errorcodesubcode_str, 255, "%s%s",
7911 code_str, subcode_str);
7912 json_object_string_add(json_peer,
7913 "lastNotificationReason",
7914 errorcodesubcode_str);
7915 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
7916 && peer->notify.code == BGP_NOTIFY_CEASE
7917 && (peer->notify.subcode
7918 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
7919 || peer->notify.subcode
7920 == BGP_NOTIFY_CEASE_ADMIN_RESET)
7921 && peer->notify.length) {
7922 char msgbuf[1024];
7923 const char *msg_str;
7924
7925 msg_str = bgp_notify_admin_message(
7926 msgbuf, sizeof(msgbuf),
7927 (uint8_t *)peer->notify.data,
7928 peer->notify.length);
7929 if (msg_str)
7930 json_object_string_add(
7931 json_peer,
7932 "lastShutdownDescription",
7933 msg_str);
7934 }
7935
7936 }
7937 json_object_string_add(json_peer, "lastResetDueTo",
7938 peer_down_str[(int)peer->last_reset]);
7939 json_object_int_add(json_peer, "lastResetCode",
7940 peer->last_reset);
7941 } else {
7942 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
7943 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
7944 code_str = bgp_notify_code_str(peer->notify.code);
7945 subcode_str =
7946 bgp_notify_subcode_str(peer->notify.code,
7947 peer->notify.subcode);
7948 vty_out(vty, " Notification %s (%s%s)\n",
7949 peer->last_reset == PEER_DOWN_NOTIFY_SEND
7950 ? "sent"
7951 : "received",
7952 code_str, subcode_str);
7953 } else {
7954 vty_out(vty, " %s\n",
7955 peer_down_str[(int)peer->last_reset]);
7956 }
7957 }
7958 }
7959
7960 static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
7961 safi_t safi)
7962 {
7963 return ((peer->status != Established) ||
7964 !peer->afc_recv[afi][safi]);
7965 }
7966
7967 static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
7968 struct peer *peer, json_object *json_peer,
7969 int max_neighbor_width, bool use_json)
7970 {
7971 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
7972 int len;
7973
7974 if (use_json) {
7975 if (peer_dynamic_neighbor(peer))
7976 json_object_boolean_true_add(json_peer,
7977 "dynamicPeer");
7978 if (peer->hostname)
7979 json_object_string_add(json_peer, "hostname",
7980 peer->hostname);
7981
7982 if (peer->domainname)
7983 json_object_string_add(json_peer, "domainname",
7984 peer->domainname);
7985 json_object_int_add(json_peer, "connectionsEstablished",
7986 peer->established);
7987 json_object_int_add(json_peer, "connectionsDropped",
7988 peer->dropped);
7989 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
7990 use_json, json_peer);
7991 if (peer->status == Established)
7992 json_object_string_add(json_peer, "lastResetDueTo",
7993 "AFI/SAFI Not Negotiated");
7994 else
7995 bgp_show_peer_reset(NULL, peer, json_peer, true);
7996 } else {
7997 dn_flag[1] = '\0';
7998 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
7999 if (peer->hostname
8000 && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
8001 len = vty_out(vty, "%s%s(%s)", dn_flag,
8002 peer->hostname, peer->host);
8003 else
8004 len = vty_out(vty, "%s%s", dn_flag, peer->host);
8005
8006 /* pad the neighbor column with spaces */
8007 if (len < max_neighbor_width)
8008 vty_out(vty, "%*s", max_neighbor_width - len,
8009 " ");
8010 vty_out(vty, "%7d %7d %8s", peer->established,
8011 peer->dropped,
8012 peer_uptime(peer->uptime, timebuf,
8013 BGP_UPTIME_LEN, 0, NULL));
8014 if (peer->status == Established)
8015 vty_out(vty, " AFI/SAFI Not Negotiated\n");
8016 else
8017 bgp_show_peer_reset(vty, peer, NULL,
8018 false);
8019 }
8020 }
8021
8022
8023 /* Show BGP peer's summary information. */
8024 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
8025 bool show_failed, bool use_json)
8026 {
8027 struct peer *peer;
8028 struct listnode *node, *nnode;
8029 unsigned int count = 0, dn_count = 0;
8030 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
8031 char neighbor_buf[VTY_BUFSIZ];
8032 int neighbor_col_default_width = 16;
8033 int len, failed_count = 0;
8034 int max_neighbor_width = 0;
8035 int pfx_rcd_safi;
8036 json_object *json = NULL;
8037 json_object *json_peer = NULL;
8038 json_object *json_peers = NULL;
8039 struct peer_af *paf;
8040
8041 /* labeled-unicast routes are installed in the unicast table so in order
8042 * to
8043 * display the correct PfxRcd value we must look at SAFI_UNICAST
8044 */
8045
8046 if (safi == SAFI_LABELED_UNICAST)
8047 pfx_rcd_safi = SAFI_UNICAST;
8048 else
8049 pfx_rcd_safi = safi;
8050
8051 if (use_json) {
8052 json = json_object_new_object();
8053 json_peers = json_object_new_object();
8054 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8055 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
8056 continue;
8057
8058 if (peer->afc[afi][safi]) {
8059 /* See if we have at least a single failed peer */
8060 if (bgp_has_peer_failed(peer, afi, safi))
8061 failed_count++;
8062 count++;
8063 }
8064 if (peer_dynamic_neighbor(peer))
8065 dn_count++;
8066 }
8067
8068 } else {
8069 /* Loop over all neighbors that will be displayed to determine
8070 * how many
8071 * characters are needed for the Neighbor column
8072 */
8073 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8074 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
8075 continue;
8076
8077 if (peer->afc[afi][safi]) {
8078 memset(dn_flag, '\0', sizeof(dn_flag));
8079 if (peer_dynamic_neighbor(peer))
8080 dn_flag[0] = '*';
8081
8082 if (peer->hostname
8083 && bgp_flag_check(bgp,
8084 BGP_FLAG_SHOW_HOSTNAME))
8085 sprintf(neighbor_buf, "%s%s(%s) ",
8086 dn_flag, peer->hostname,
8087 peer->host);
8088 else
8089 sprintf(neighbor_buf, "%s%s ", dn_flag,
8090 peer->host);
8091
8092 len = strlen(neighbor_buf);
8093
8094 if (len > max_neighbor_width)
8095 max_neighbor_width = len;
8096
8097 /* See if we have at least a single failed peer */
8098 if (bgp_has_peer_failed(peer, afi, safi))
8099 failed_count++;
8100 count++;
8101 }
8102 }
8103
8104 /* Originally we displayed the Neighbor column as 16
8105 * characters wide so make that the default
8106 */
8107 if (max_neighbor_width < neighbor_col_default_width)
8108 max_neighbor_width = neighbor_col_default_width;
8109 }
8110
8111 if (show_failed && !failed_count) {
8112 if (use_json) {
8113 json_object_int_add(json, "failedPeersCount", 0);
8114 json_object_int_add(json, "dynamicPeers", dn_count);
8115 json_object_int_add(json, "totalPeers", count);
8116
8117 vty_out(vty, "%s\n", json_object_to_json_string_ext(
8118 json, JSON_C_TO_STRING_PRETTY));
8119 json_object_free(json);
8120 } else {
8121 vty_out(vty, "%% No failed BGP neighbors found\n");
8122 vty_out(vty, "\nTotal number of neighbors %d\n", count);
8123 }
8124 return CMD_SUCCESS;
8125 }
8126
8127 count = 0; /* Reset the value as its used again */
8128 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8129 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
8130 continue;
8131
8132 if (!peer->afc[afi][safi])
8133 continue;
8134
8135 if (!count) {
8136 unsigned long ents;
8137 char memstrbuf[MTYPE_MEMSTR_LEN];
8138 int64_t vrf_id_ui;
8139
8140 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
8141 ? -1
8142 : (int64_t)bgp->vrf_id;
8143
8144 /* Usage summary and header */
8145 if (use_json) {
8146 json_object_string_add(
8147 json, "routerId",
8148 inet_ntoa(bgp->router_id));
8149 json_object_int_add(json, "as", bgp->as);
8150 json_object_int_add(json, "vrfId", vrf_id_ui);
8151 json_object_string_add(
8152 json, "vrfName",
8153 (bgp->inst_type
8154 == BGP_INSTANCE_TYPE_DEFAULT)
8155 ? VRF_DEFAULT_NAME
8156 : bgp->name);
8157 } else {
8158 vty_out(vty,
8159 "BGP router identifier %s, local AS number %u vrf-id %d",
8160 inet_ntoa(bgp->router_id), bgp->as,
8161 bgp->vrf_id == VRF_UNKNOWN
8162 ? -1
8163 : (int)bgp->vrf_id);
8164 vty_out(vty, "\n");
8165 }
8166
8167 if (bgp_update_delay_configured(bgp)) {
8168 if (use_json) {
8169 json_object_int_add(
8170 json, "updateDelayLimit",
8171 bgp->v_update_delay);
8172
8173 if (bgp->v_update_delay
8174 != bgp->v_establish_wait)
8175 json_object_int_add(
8176 json,
8177 "updateDelayEstablishWait",
8178 bgp->v_establish_wait);
8179
8180 if (bgp_update_delay_active(bgp)) {
8181 json_object_string_add(
8182 json,
8183 "updateDelayFirstNeighbor",
8184 bgp->update_delay_begin_time);
8185 json_object_boolean_true_add(
8186 json,
8187 "updateDelayInProgress");
8188 } else {
8189 if (bgp->update_delay_over) {
8190 json_object_string_add(
8191 json,
8192 "updateDelayFirstNeighbor",
8193 bgp->update_delay_begin_time);
8194 json_object_string_add(
8195 json,
8196 "updateDelayBestpathResumed",
8197 bgp->update_delay_end_time);
8198 json_object_string_add(
8199 json,
8200 "updateDelayZebraUpdateResume",
8201 bgp->update_delay_zebra_resume_time);
8202 json_object_string_add(
8203 json,
8204 "updateDelayPeerUpdateResume",
8205 bgp->update_delay_peers_resume_time);
8206 }
8207 }
8208 } else {
8209 vty_out(vty,
8210 "Read-only mode update-delay limit: %d seconds\n",
8211 bgp->v_update_delay);
8212 if (bgp->v_update_delay
8213 != bgp->v_establish_wait)
8214 vty_out(vty,
8215 " Establish wait: %d seconds\n",
8216 bgp->v_establish_wait);
8217
8218 if (bgp_update_delay_active(bgp)) {
8219 vty_out(vty,
8220 " First neighbor established: %s\n",
8221 bgp->update_delay_begin_time);
8222 vty_out(vty,
8223 " Delay in progress\n");
8224 } else {
8225 if (bgp->update_delay_over) {
8226 vty_out(vty,
8227 " First neighbor established: %s\n",
8228 bgp->update_delay_begin_time);
8229 vty_out(vty,
8230 " Best-paths resumed: %s\n",
8231 bgp->update_delay_end_time);
8232 vty_out(vty,
8233 " zebra update resumed: %s\n",
8234 bgp->update_delay_zebra_resume_time);
8235 vty_out(vty,
8236 " peers update resumed: %s\n",
8237 bgp->update_delay_peers_resume_time);
8238 }
8239 }
8240 }
8241 }
8242
8243 if (use_json) {
8244 if (bgp_maxmed_onstartup_configured(bgp)
8245 && bgp->maxmed_active)
8246 json_object_boolean_true_add(
8247 json, "maxMedOnStartup");
8248 if (bgp->v_maxmed_admin)
8249 json_object_boolean_true_add(
8250 json, "maxMedAdministrative");
8251
8252 json_object_int_add(
8253 json, "tableVersion",
8254 bgp_table_version(bgp->rib[afi][safi]));
8255
8256 ents = bgp_table_count(bgp->rib[afi][safi]);
8257 json_object_int_add(json, "ribCount", ents);
8258 json_object_int_add(
8259 json, "ribMemory",
8260 ents * sizeof(struct bgp_node));
8261
8262 ents = bgp->af_peer_count[afi][safi];
8263 json_object_int_add(json, "peerCount", ents);
8264 json_object_int_add(json, "peerMemory",
8265 ents * sizeof(struct peer));
8266
8267 if ((ents = listcount(bgp->group))) {
8268 json_object_int_add(
8269 json, "peerGroupCount", ents);
8270 json_object_int_add(
8271 json, "peerGroupMemory",
8272 ents * sizeof(struct
8273 peer_group));
8274 }
8275
8276 if (CHECK_FLAG(bgp->af_flags[afi][safi],
8277 BGP_CONFIG_DAMPENING))
8278 json_object_boolean_true_add(
8279 json, "dampeningEnabled");
8280 } else {
8281 if (bgp_maxmed_onstartup_configured(bgp)
8282 && bgp->maxmed_active)
8283 vty_out(vty,
8284 "Max-med on-startup active\n");
8285 if (bgp->v_maxmed_admin)
8286 vty_out(vty,
8287 "Max-med administrative active\n");
8288
8289 vty_out(vty, "BGP table version %" PRIu64 "\n",
8290 bgp_table_version(bgp->rib[afi][safi]));
8291
8292 ents = bgp_table_count(bgp->rib[afi][safi]);
8293 vty_out(vty,
8294 "RIB entries %ld, using %s of memory\n",
8295 ents,
8296 mtype_memstr(memstrbuf,
8297 sizeof(memstrbuf),
8298 ents * sizeof(struct
8299 bgp_node)));
8300
8301 /* Peer related usage */
8302 ents = bgp->af_peer_count[afi][safi];
8303 vty_out(vty, "Peers %ld, using %s of memory\n",
8304 ents,
8305 mtype_memstr(
8306 memstrbuf, sizeof(memstrbuf),
8307 ents * sizeof(struct peer)));
8308
8309 if ((ents = listcount(bgp->group)))
8310 vty_out(vty,
8311 "Peer groups %ld, using %s of memory\n",
8312 ents,
8313 mtype_memstr(
8314 memstrbuf,
8315 sizeof(memstrbuf),
8316 ents * sizeof(struct
8317 peer_group)));
8318
8319 if (CHECK_FLAG(bgp->af_flags[afi][safi],
8320 BGP_CONFIG_DAMPENING))
8321 vty_out(vty, "Dampening enabled.\n");
8322 vty_out(vty, "\n");
8323
8324 /* Subtract 8 here because 'Neighbor' is
8325 * 8 characters */
8326 vty_out(vty, "Neighbor");
8327 vty_out(vty, "%*s", max_neighbor_width - 8,
8328 " ");
8329 if (show_failed)
8330 vty_out(vty, "EstdCnt DropCnt ResetTime Reason\n");
8331 else
8332 vty_out(vty,
8333 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd\n");
8334 }
8335 }
8336
8337 count++;
8338 /* Works for both failed & successful cases */
8339 if (peer_dynamic_neighbor(peer))
8340 dn_count++;
8341
8342 if (use_json) {
8343 json_peer = NULL;
8344
8345 if (show_failed &&
8346 bgp_has_peer_failed(peer, afi, safi)) {
8347 json_peer = json_object_new_object();
8348 bgp_show_failed_summary(vty, bgp, peer,
8349 json_peer, 0, use_json);
8350 } else if (!show_failed) {
8351 json_peer = json_object_new_object();
8352 if (peer_dynamic_neighbor(peer)) {
8353 json_object_boolean_true_add(json_peer,
8354 "dynamicPeer");
8355 }
8356
8357 if (peer->hostname)
8358 json_object_string_add(json_peer, "hostname",
8359 peer->hostname);
8360
8361 if (peer->domainname)
8362 json_object_string_add(json_peer, "domainname",
8363 peer->domainname);
8364
8365 json_object_int_add(json_peer, "remoteAs", peer->as);
8366 json_object_int_add(json_peer, "version", 4);
8367 json_object_int_add(json_peer, "msgRcvd",
8368 PEER_TOTAL_RX(peer));
8369 json_object_int_add(json_peer, "msgSent",
8370 PEER_TOTAL_TX(peer));
8371
8372 json_object_int_add(json_peer, "tableVersion",
8373 peer->version[afi][safi]);
8374 json_object_int_add(json_peer, "outq",
8375 peer->obuf->count);
8376 json_object_int_add(json_peer, "inq", 0);
8377 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
8378 use_json, json_peer);
8379
8380 /*
8381 * Adding "pfxRcd" field to match with the corresponding
8382 * CLI. "prefixReceivedCount" will be deprecated in
8383 * future.
8384 */
8385 json_object_int_add(json_peer, "prefixReceivedCount",
8386 peer->pcount[afi][pfx_rcd_safi]);
8387 json_object_int_add(json_peer, "pfxRcd",
8388 peer->pcount[afi][pfx_rcd_safi]);
8389
8390 paf = peer_af_find(peer, afi, pfx_rcd_safi);
8391 if (paf && PAF_SUBGRP(paf))
8392 json_object_int_add(json_peer,
8393 "pfxSnt",
8394 (PAF_SUBGRP(paf))->scount);
8395 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
8396 json_object_string_add(json_peer, "state",
8397 "Idle (Admin)");
8398 else if (peer->afc_recv[afi][safi])
8399 json_object_string_add(
8400 json_peer, "state",
8401 lookup_msg(bgp_status_msg, peer->status,
8402 NULL));
8403 else if (CHECK_FLAG(peer->sflags,
8404 PEER_STATUS_PREFIX_OVERFLOW))
8405 json_object_string_add(json_peer, "state",
8406 "Idle (PfxCt)");
8407 else
8408 json_object_string_add(
8409 json_peer, "state",
8410 lookup_msg(bgp_status_msg, peer->status,
8411 NULL));
8412 json_object_int_add(json_peer, "connectionsEstablished",
8413 peer->established);
8414 json_object_int_add(json_peer, "connectionsDropped",
8415 peer->dropped);
8416 }
8417 /* Avoid creating empty peer dicts in JSON */
8418 if (json_peer == NULL)
8419 continue;
8420
8421 if (peer->conf_if)
8422 json_object_string_add(json_peer, "idType",
8423 "interface");
8424 else if (peer->su.sa.sa_family == AF_INET)
8425 json_object_string_add(json_peer, "idType",
8426 "ipv4");
8427 else if (peer->su.sa.sa_family == AF_INET6)
8428 json_object_string_add(json_peer, "idType",
8429 "ipv6");
8430 json_object_object_add(json_peers, peer->host,
8431 json_peer);
8432 } else {
8433 if (show_failed &&
8434 bgp_has_peer_failed(peer, afi, safi)) {
8435 bgp_show_failed_summary(vty, bgp, peer, NULL,
8436 max_neighbor_width,
8437 use_json);
8438 } else if (!show_failed) {
8439 memset(dn_flag, '\0', sizeof(dn_flag));
8440 if (peer_dynamic_neighbor(peer)) {
8441 dn_flag[0] = '*';
8442 }
8443
8444 if (peer->hostname
8445 && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
8446 len = vty_out(vty, "%s%s(%s)", dn_flag,
8447 peer->hostname, peer->host);
8448 else
8449 len = vty_out(vty, "%s%s", dn_flag, peer->host);
8450
8451 /* pad the neighbor column with spaces */
8452 if (len < max_neighbor_width)
8453 vty_out(vty, "%*s", max_neighbor_width - len,
8454 " ");
8455
8456 vty_out(vty, "4 %10u %7u %7u %8" PRIu64 " %4d %4zd %8s",
8457 peer->as, PEER_TOTAL_RX(peer),
8458 PEER_TOTAL_TX(peer), peer->version[afi][safi],
8459 0, peer->obuf->count,
8460 peer_uptime(peer->uptime, timebuf,
8461 BGP_UPTIME_LEN, 0, NULL));
8462
8463 if (peer->status == Established)
8464 if (peer->afc_recv[afi][safi])
8465 vty_out(vty, " %12" PRIu32,
8466 peer->pcount
8467 [afi]
8468 [pfx_rcd_safi]);
8469 else
8470 vty_out(vty, " NoNeg");
8471 else {
8472 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
8473 vty_out(vty, " Idle (Admin)");
8474 else if (CHECK_FLAG(
8475 peer->sflags,
8476 PEER_STATUS_PREFIX_OVERFLOW))
8477 vty_out(vty, " Idle (PfxCt)");
8478 else
8479 vty_out(vty, " %12s",
8480 lookup_msg(bgp_status_msg,
8481 peer->status, NULL));
8482 }
8483 vty_out(vty, "\n");
8484 }
8485
8486 }
8487 }
8488
8489 if (use_json) {
8490 json_object_object_add(json, "peers", json_peers);
8491 json_object_int_add(json, "failedPeers", failed_count);
8492 json_object_int_add(json, "totalPeers", count);
8493 json_object_int_add(json, "dynamicPeers", dn_count);
8494
8495 if (!show_failed)
8496 bgp_show_bestpath_json(bgp, json);
8497
8498 vty_out(vty, "%s\n", json_object_to_json_string_ext(
8499 json, JSON_C_TO_STRING_PRETTY));
8500 json_object_free(json);
8501 } else {
8502 if (count)
8503 vty_out(vty, "\nTotal number of neighbors %d\n", count);
8504 else {
8505 vty_out(vty, "No %s neighbor is configured\n",
8506 get_afi_safi_str(afi, safi, false));
8507 }
8508
8509 if (dn_count) {
8510 vty_out(vty, "* - dynamic neighbor\n");
8511 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
8512 dn_count, bgp->dynamic_neighbors_limit);
8513 }
8514 }
8515
8516 return CMD_SUCCESS;
8517 }
8518
8519 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
8520 int safi, bool show_failed, bool use_json)
8521 {
8522 int is_first = 1;
8523 int afi_wildcard = (afi == AFI_MAX);
8524 int safi_wildcard = (safi == SAFI_MAX);
8525 int is_wildcard = (afi_wildcard || safi_wildcard);
8526 bool nbr_output = false;
8527
8528 if (use_json && is_wildcard)
8529 vty_out(vty, "{\n");
8530 if (afi_wildcard)
8531 afi = 1; /* AFI_IP */
8532 while (afi < AFI_MAX) {
8533 if (safi_wildcard)
8534 safi = 1; /* SAFI_UNICAST */
8535 while (safi < SAFI_MAX) {
8536 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
8537 nbr_output = true;
8538
8539 if (is_wildcard) {
8540 /*
8541 * So limit output to those afi/safi
8542 * pairs that
8543 * actualy have something interesting in
8544 * them
8545 */
8546 if (use_json) {
8547 if (!is_first)
8548 vty_out(vty, ",\n");
8549 else
8550 is_first = 0;
8551
8552 vty_out(vty, "\"%s\":",
8553 get_afi_safi_str(afi,
8554 safi,
8555 true));
8556 } else {
8557 vty_out(vty, "\n%s Summary:\n",
8558 get_afi_safi_str(afi,
8559 safi,
8560 false));
8561 }
8562 }
8563 bgp_show_summary(vty, bgp, afi, safi, show_failed,
8564 use_json);
8565 }
8566 safi++;
8567 if (!safi_wildcard)
8568 safi = SAFI_MAX;
8569 }
8570 afi++;
8571 if (!afi_wildcard)
8572 afi = AFI_MAX;
8573 }
8574
8575 if (use_json && is_wildcard)
8576 vty_out(vty, "}\n");
8577 else if (!nbr_output) {
8578 if (use_json)
8579 vty_out(vty, "{}\n");
8580 else
8581 vty_out(vty, "%% No BGP neighbors found\n");
8582 }
8583 }
8584
8585 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
8586 safi_t safi, bool show_failed,
8587 bool use_json)
8588 {
8589 struct listnode *node, *nnode;
8590 struct bgp *bgp;
8591 int is_first = 1;
8592 bool nbr_output = false;
8593
8594 if (use_json)
8595 vty_out(vty, "{\n");
8596
8597 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
8598 nbr_output = true;
8599 if (use_json) {
8600 if (!is_first)
8601 vty_out(vty, ",\n");
8602 else
8603 is_first = 0;
8604
8605 vty_out(vty, "\"%s\":",
8606 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8607 ? VRF_DEFAULT_NAME
8608 : bgp->name);
8609 } else {
8610 vty_out(vty, "\nInstance %s:\n",
8611 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8612 ? VRF_DEFAULT_NAME
8613 : bgp->name);
8614 }
8615 bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_failed,
8616 use_json);
8617 }
8618
8619 if (use_json)
8620 vty_out(vty, "}\n");
8621 else if (!nbr_output)
8622 vty_out(vty, "%% BGP instance not found\n");
8623 }
8624
8625 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
8626 safi_t safi, bool show_failed, bool use_json)
8627 {
8628 struct bgp *bgp;
8629
8630 if (name) {
8631 if (strmatch(name, "all")) {
8632 bgp_show_all_instances_summary_vty(vty, afi, safi,
8633 show_failed,
8634 use_json);
8635 return CMD_SUCCESS;
8636 } else {
8637 bgp = bgp_lookup_by_name(name);
8638
8639 if (!bgp) {
8640 if (use_json)
8641 vty_out(vty, "{}\n");
8642 else
8643 vty_out(vty,
8644 "%% BGP instance not found\n");
8645 return CMD_WARNING;
8646 }
8647
8648 bgp_show_summary_afi_safi(vty, bgp, afi, safi,
8649 show_failed, use_json);
8650 return CMD_SUCCESS;
8651 }
8652 }
8653
8654 bgp = bgp_get_default();
8655
8656 if (bgp)
8657 bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_failed,
8658 use_json);
8659 else {
8660 if (use_json)
8661 vty_out(vty, "{}\n");
8662 else
8663 vty_out(vty, "%% BGP instance not found\n");
8664 return CMD_WARNING;
8665 }
8666
8667 return CMD_SUCCESS;
8668 }
8669
8670 /* `show [ip] bgp summary' commands. */
8671 DEFUN (show_ip_bgp_summary,
8672 show_ip_bgp_summary_cmd,
8673 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [failed] [json]",
8674 SHOW_STR
8675 IP_STR
8676 BGP_STR
8677 BGP_INSTANCE_HELP_STR
8678 BGP_AFI_HELP_STR
8679 BGP_SAFI_WITH_LABEL_HELP_STR
8680 "Summary of BGP neighbor status\n"
8681 "Show only sessions not in Established state\n"
8682 JSON_STR)
8683 {
8684 char *vrf = NULL;
8685 afi_t afi = AFI_MAX;
8686 safi_t safi = SAFI_MAX;
8687 bool show_failed = false;
8688
8689 int idx = 0;
8690
8691 /* show [ip] bgp */
8692 if (argv_find(argv, argc, "ip", &idx))
8693 afi = AFI_IP;
8694 /* [<vrf> VIEWVRFNAME] */
8695 if (argv_find(argv, argc, "vrf", &idx)) {
8696 vrf = argv[idx + 1]->arg;
8697 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
8698 vrf = NULL;
8699 } else if (argv_find(argv, argc, "view", &idx))
8700 /* [<view> VIEWVRFNAME] */
8701 vrf = argv[idx + 1]->arg;
8702 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
8703 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
8704 argv_find_and_parse_safi(argv, argc, &idx, &safi);
8705 }
8706
8707 if (argv_find(argv, argc, "failed", &idx))
8708 show_failed = true;
8709
8710 bool uj = use_json(argc, argv);
8711
8712 return bgp_show_summary_vty(vty, vrf, afi, safi, show_failed, uj);
8713 }
8714
8715 const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
8716 {
8717 if (for_json)
8718 return get_afi_safi_json_str(afi, safi);
8719 else
8720 return get_afi_safi_vty_str(afi, safi);
8721 }
8722
8723 /* Show BGP peer's information. */
8724 enum show_type { show_all, show_peer, show_ipv4_all, show_ipv6_all, show_ipv4_peer, show_ipv6_peer };
8725
8726 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
8727 afi_t afi, safi_t safi,
8728 uint16_t adv_smcap, uint16_t adv_rmcap,
8729 uint16_t rcv_smcap, uint16_t rcv_rmcap,
8730 bool use_json, json_object *json_pref)
8731 {
8732 /* Send-Mode */
8733 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8734 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
8735 if (use_json) {
8736 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8737 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8738 json_object_string_add(json_pref, "sendMode",
8739 "advertisedAndReceived");
8740 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8741 json_object_string_add(json_pref, "sendMode",
8742 "advertised");
8743 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8744 json_object_string_add(json_pref, "sendMode",
8745 "received");
8746 } else {
8747 vty_out(vty, " Send-mode: ");
8748 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8749 vty_out(vty, "advertised");
8750 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8751 vty_out(vty, "%sreceived",
8752 CHECK_FLAG(p->af_cap[afi][safi],
8753 adv_smcap)
8754 ? ", "
8755 : "");
8756 vty_out(vty, "\n");
8757 }
8758 }
8759
8760 /* Receive-Mode */
8761 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8762 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
8763 if (use_json) {
8764 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8765 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8766 json_object_string_add(json_pref, "recvMode",
8767 "advertisedAndReceived");
8768 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8769 json_object_string_add(json_pref, "recvMode",
8770 "advertised");
8771 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8772 json_object_string_add(json_pref, "recvMode",
8773 "received");
8774 } else {
8775 vty_out(vty, " Receive-mode: ");
8776 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8777 vty_out(vty, "advertised");
8778 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8779 vty_out(vty, "%sreceived",
8780 CHECK_FLAG(p->af_cap[afi][safi],
8781 adv_rmcap)
8782 ? ", "
8783 : "");
8784 vty_out(vty, "\n");
8785 }
8786 }
8787 }
8788
8789 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
8790 safi_t safi, bool use_json,
8791 json_object *json_neigh)
8792 {
8793 struct bgp_filter *filter;
8794 struct peer_af *paf;
8795 char orf_pfx_name[BUFSIZ];
8796 int orf_pfx_count;
8797 json_object *json_af = NULL;
8798 json_object *json_prefA = NULL;
8799 json_object *json_prefB = NULL;
8800 json_object *json_addr = NULL;
8801
8802 if (use_json) {
8803 json_addr = json_object_new_object();
8804 json_af = json_object_new_object();
8805 filter = &p->filter[afi][safi];
8806
8807 if (peer_group_active(p))
8808 json_object_string_add(json_addr, "peerGroupMember",
8809 p->group->name);
8810
8811 paf = peer_af_find(p, afi, safi);
8812 if (paf && PAF_SUBGRP(paf)) {
8813 json_object_int_add(json_addr, "updateGroupId",
8814 PAF_UPDGRP(paf)->id);
8815 json_object_int_add(json_addr, "subGroupId",
8816 PAF_SUBGRP(paf)->id);
8817 json_object_int_add(json_addr, "packetQueueLength",
8818 bpacket_queue_virtual_length(paf));
8819 }
8820
8821 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8822 || CHECK_FLAG(p->af_cap[afi][safi],
8823 PEER_CAP_ORF_PREFIX_SM_RCV)
8824 || CHECK_FLAG(p->af_cap[afi][safi],
8825 PEER_CAP_ORF_PREFIX_RM_ADV)
8826 || CHECK_FLAG(p->af_cap[afi][safi],
8827 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8828 json_object_int_add(json_af, "orfType",
8829 ORF_TYPE_PREFIX);
8830 json_prefA = json_object_new_object();
8831 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
8832 PEER_CAP_ORF_PREFIX_SM_ADV,
8833 PEER_CAP_ORF_PREFIX_RM_ADV,
8834 PEER_CAP_ORF_PREFIX_SM_RCV,
8835 PEER_CAP_ORF_PREFIX_RM_RCV,
8836 use_json, json_prefA);
8837 json_object_object_add(json_af, "orfPrefixList",
8838 json_prefA);
8839 }
8840
8841 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8842 || CHECK_FLAG(p->af_cap[afi][safi],
8843 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8844 || CHECK_FLAG(p->af_cap[afi][safi],
8845 PEER_CAP_ORF_PREFIX_RM_ADV)
8846 || CHECK_FLAG(p->af_cap[afi][safi],
8847 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8848 json_object_int_add(json_af, "orfOldType",
8849 ORF_TYPE_PREFIX_OLD);
8850 json_prefB = json_object_new_object();
8851 bgp_show_peer_afi_orf_cap(
8852 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8853 PEER_CAP_ORF_PREFIX_RM_ADV,
8854 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8855 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
8856 json_prefB);
8857 json_object_object_add(json_af, "orfOldPrefixList",
8858 json_prefB);
8859 }
8860
8861 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8862 || CHECK_FLAG(p->af_cap[afi][safi],
8863 PEER_CAP_ORF_PREFIX_SM_RCV)
8864 || CHECK_FLAG(p->af_cap[afi][safi],
8865 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8866 || CHECK_FLAG(p->af_cap[afi][safi],
8867 PEER_CAP_ORF_PREFIX_RM_ADV)
8868 || CHECK_FLAG(p->af_cap[afi][safi],
8869 PEER_CAP_ORF_PREFIX_RM_RCV)
8870 || CHECK_FLAG(p->af_cap[afi][safi],
8871 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8872 json_object_object_add(json_addr, "afDependentCap",
8873 json_af);
8874 else
8875 json_object_free(json_af);
8876
8877 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8878 orf_pfx_count = prefix_bgp_show_prefix_list(
8879 NULL, afi, orf_pfx_name, use_json);
8880
8881 if (CHECK_FLAG(p->af_sflags[afi][safi],
8882 PEER_STATUS_ORF_PREFIX_SEND)
8883 || orf_pfx_count) {
8884 if (CHECK_FLAG(p->af_sflags[afi][safi],
8885 PEER_STATUS_ORF_PREFIX_SEND))
8886 json_object_boolean_true_add(json_neigh,
8887 "orfSent");
8888 if (orf_pfx_count)
8889 json_object_int_add(json_addr, "orfRecvCounter",
8890 orf_pfx_count);
8891 }
8892 if (CHECK_FLAG(p->af_sflags[afi][safi],
8893 PEER_STATUS_ORF_WAIT_REFRESH))
8894 json_object_string_add(
8895 json_addr, "orfFirstUpdate",
8896 "deferredUntilORFOrRouteRefreshRecvd");
8897
8898 if (CHECK_FLAG(p->af_flags[afi][safi],
8899 PEER_FLAG_REFLECTOR_CLIENT))
8900 json_object_boolean_true_add(json_addr,
8901 "routeReflectorClient");
8902 if (CHECK_FLAG(p->af_flags[afi][safi],
8903 PEER_FLAG_RSERVER_CLIENT))
8904 json_object_boolean_true_add(json_addr,
8905 "routeServerClient");
8906 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8907 json_object_boolean_true_add(json_addr,
8908 "inboundSoftConfigPermit");
8909
8910 if (CHECK_FLAG(p->af_flags[afi][safi],
8911 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8912 json_object_boolean_true_add(
8913 json_addr,
8914 "privateAsNumsAllReplacedInUpdatesToNbr");
8915 else if (CHECK_FLAG(p->af_flags[afi][safi],
8916 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8917 json_object_boolean_true_add(
8918 json_addr,
8919 "privateAsNumsReplacedInUpdatesToNbr");
8920 else if (CHECK_FLAG(p->af_flags[afi][safi],
8921 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8922 json_object_boolean_true_add(
8923 json_addr,
8924 "privateAsNumsAllRemovedInUpdatesToNbr");
8925 else if (CHECK_FLAG(p->af_flags[afi][safi],
8926 PEER_FLAG_REMOVE_PRIVATE_AS))
8927 json_object_boolean_true_add(
8928 json_addr,
8929 "privateAsNumsRemovedInUpdatesToNbr");
8930
8931 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
8932 json_object_boolean_true_add(
8933 json_addr,
8934 bgp_addpath_names(p->addpath_type[afi][safi])
8935 ->type_json_name);
8936
8937 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8938 json_object_string_add(json_addr,
8939 "overrideASNsInOutboundUpdates",
8940 "ifAspathEqualRemoteAs");
8941
8942 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8943 || CHECK_FLAG(p->af_flags[afi][safi],
8944 PEER_FLAG_FORCE_NEXTHOP_SELF))
8945 json_object_boolean_true_add(json_addr,
8946 "routerAlwaysNextHop");
8947 if (CHECK_FLAG(p->af_flags[afi][safi],
8948 PEER_FLAG_AS_PATH_UNCHANGED))
8949 json_object_boolean_true_add(
8950 json_addr, "unchangedAsPathPropogatedToNbr");
8951 if (CHECK_FLAG(p->af_flags[afi][safi],
8952 PEER_FLAG_NEXTHOP_UNCHANGED))
8953 json_object_boolean_true_add(
8954 json_addr, "unchangedNextHopPropogatedToNbr");
8955 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8956 json_object_boolean_true_add(
8957 json_addr, "unchangedMedPropogatedToNbr");
8958 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8959 || CHECK_FLAG(p->af_flags[afi][safi],
8960 PEER_FLAG_SEND_EXT_COMMUNITY)) {
8961 if (CHECK_FLAG(p->af_flags[afi][safi],
8962 PEER_FLAG_SEND_COMMUNITY)
8963 && CHECK_FLAG(p->af_flags[afi][safi],
8964 PEER_FLAG_SEND_EXT_COMMUNITY))
8965 json_object_string_add(json_addr,
8966 "commAttriSentToNbr",
8967 "extendedAndStandard");
8968 else if (CHECK_FLAG(p->af_flags[afi][safi],
8969 PEER_FLAG_SEND_EXT_COMMUNITY))
8970 json_object_string_add(json_addr,
8971 "commAttriSentToNbr",
8972 "extended");
8973 else
8974 json_object_string_add(json_addr,
8975 "commAttriSentToNbr",
8976 "standard");
8977 }
8978 if (CHECK_FLAG(p->af_flags[afi][safi],
8979 PEER_FLAG_DEFAULT_ORIGINATE)) {
8980 if (p->default_rmap[afi][safi].name)
8981 json_object_string_add(
8982 json_addr, "defaultRouteMap",
8983 p->default_rmap[afi][safi].name);
8984
8985 if (paf && PAF_SUBGRP(paf)
8986 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8987 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8988 json_object_boolean_true_add(json_addr,
8989 "defaultSent");
8990 else
8991 json_object_boolean_true_add(json_addr,
8992 "defaultNotSent");
8993 }
8994
8995 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
8996 if (is_evpn_enabled())
8997 json_object_boolean_true_add(
8998 json_addr, "advertiseAllVnis");
8999 }
9000
9001 if (filter->plist[FILTER_IN].name
9002 || filter->dlist[FILTER_IN].name
9003 || filter->aslist[FILTER_IN].name
9004 || filter->map[RMAP_IN].name)
9005 json_object_boolean_true_add(json_addr,
9006 "inboundPathPolicyConfig");
9007 if (filter->plist[FILTER_OUT].name
9008 || filter->dlist[FILTER_OUT].name
9009 || filter->aslist[FILTER_OUT].name
9010 || filter->map[RMAP_OUT].name || filter->usmap.name)
9011 json_object_boolean_true_add(
9012 json_addr, "outboundPathPolicyConfig");
9013
9014 /* prefix-list */
9015 if (filter->plist[FILTER_IN].name)
9016 json_object_string_add(json_addr,
9017 "incomingUpdatePrefixFilterList",
9018 filter->plist[FILTER_IN].name);
9019 if (filter->plist[FILTER_OUT].name)
9020 json_object_string_add(json_addr,
9021 "outgoingUpdatePrefixFilterList",
9022 filter->plist[FILTER_OUT].name);
9023
9024 /* distribute-list */
9025 if (filter->dlist[FILTER_IN].name)
9026 json_object_string_add(
9027 json_addr, "incomingUpdateNetworkFilterList",
9028 filter->dlist[FILTER_IN].name);
9029 if (filter->dlist[FILTER_OUT].name)
9030 json_object_string_add(
9031 json_addr, "outgoingUpdateNetworkFilterList",
9032 filter->dlist[FILTER_OUT].name);
9033
9034 /* filter-list. */
9035 if (filter->aslist[FILTER_IN].name)
9036 json_object_string_add(json_addr,
9037 "incomingUpdateAsPathFilterList",
9038 filter->aslist[FILTER_IN].name);
9039 if (filter->aslist[FILTER_OUT].name)
9040 json_object_string_add(json_addr,
9041 "outgoingUpdateAsPathFilterList",
9042 filter->aslist[FILTER_OUT].name);
9043
9044 /* route-map. */
9045 if (filter->map[RMAP_IN].name)
9046 json_object_string_add(
9047 json_addr, "routeMapForIncomingAdvertisements",
9048 filter->map[RMAP_IN].name);
9049 if (filter->map[RMAP_OUT].name)
9050 json_object_string_add(
9051 json_addr, "routeMapForOutgoingAdvertisements",
9052 filter->map[RMAP_OUT].name);
9053
9054 /* ebgp-requires-policy (inbound) */
9055 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
9056 && !bgp_inbound_policy_exists(p, filter))
9057 json_object_string_add(
9058 json_addr, "inboundEbgpRequiresPolicy",
9059 "Inbound updates discarded due to missing policy");
9060
9061 /* ebgp-requires-policy (outbound) */
9062 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
9063 && (!bgp_outbound_policy_exists(p, filter)))
9064 json_object_string_add(
9065 json_addr, "outboundEbgpRequiresPolicy",
9066 "Outbound updates discarded due to missing policy");
9067
9068 /* unsuppress-map */
9069 if (filter->usmap.name)
9070 json_object_string_add(json_addr,
9071 "selectiveUnsuppressRouteMap",
9072 filter->usmap.name);
9073
9074 /* Receive prefix count */
9075 json_object_int_add(json_addr, "acceptedPrefixCounter",
9076 p->pcount[afi][safi]);
9077 if (paf && PAF_SUBGRP(paf))
9078 json_object_int_add(json_addr, "sentPrefixCounter",
9079 (PAF_SUBGRP(paf))->scount);
9080
9081 /* Maximum prefix */
9082 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
9083 json_object_int_add(json_addr, "prefixAllowedMax",
9084 p->pmax[afi][safi]);
9085 if (CHECK_FLAG(p->af_flags[afi][safi],
9086 PEER_FLAG_MAX_PREFIX_WARNING))
9087 json_object_boolean_true_add(
9088 json_addr, "prefixAllowedMaxWarning");
9089 json_object_int_add(json_addr,
9090 "prefixAllowedWarningThresh",
9091 p->pmax_threshold[afi][safi]);
9092 if (p->pmax_restart[afi][safi])
9093 json_object_int_add(
9094 json_addr,
9095 "prefixAllowedRestartIntervalMsecs",
9096 p->pmax_restart[afi][safi] * 60000);
9097 }
9098 json_object_object_add(json_neigh, get_afi_safi_str(afi, safi, true),
9099 json_addr);
9100
9101 } else {
9102 filter = &p->filter[afi][safi];
9103
9104 vty_out(vty, " For address family: %s\n",
9105 get_afi_safi_str(afi, safi, false));
9106
9107 if (peer_group_active(p))
9108 vty_out(vty, " %s peer-group member\n",
9109 p->group->name);
9110
9111 paf = peer_af_find(p, afi, safi);
9112 if (paf && PAF_SUBGRP(paf)) {
9113 vty_out(vty, " Update group %" PRIu64
9114 ", subgroup %" PRIu64 "\n",
9115 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
9116 vty_out(vty, " Packet Queue length %d\n",
9117 bpacket_queue_virtual_length(paf));
9118 } else {
9119 vty_out(vty, " Not part of any update group\n");
9120 }
9121 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
9122 || CHECK_FLAG(p->af_cap[afi][safi],
9123 PEER_CAP_ORF_PREFIX_SM_RCV)
9124 || CHECK_FLAG(p->af_cap[afi][safi],
9125 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
9126 || CHECK_FLAG(p->af_cap[afi][safi],
9127 PEER_CAP_ORF_PREFIX_RM_ADV)
9128 || CHECK_FLAG(p->af_cap[afi][safi],
9129 PEER_CAP_ORF_PREFIX_RM_RCV)
9130 || CHECK_FLAG(p->af_cap[afi][safi],
9131 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
9132 vty_out(vty, " AF-dependant capabilities:\n");
9133
9134 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
9135 || CHECK_FLAG(p->af_cap[afi][safi],
9136 PEER_CAP_ORF_PREFIX_SM_RCV)
9137 || CHECK_FLAG(p->af_cap[afi][safi],
9138 PEER_CAP_ORF_PREFIX_RM_ADV)
9139 || CHECK_FLAG(p->af_cap[afi][safi],
9140 PEER_CAP_ORF_PREFIX_RM_RCV)) {
9141 vty_out(vty,
9142 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
9143 ORF_TYPE_PREFIX);
9144 bgp_show_peer_afi_orf_cap(
9145 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
9146 PEER_CAP_ORF_PREFIX_RM_ADV,
9147 PEER_CAP_ORF_PREFIX_SM_RCV,
9148 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
9149 }
9150 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
9151 || CHECK_FLAG(p->af_cap[afi][safi],
9152 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
9153 || CHECK_FLAG(p->af_cap[afi][safi],
9154 PEER_CAP_ORF_PREFIX_RM_ADV)
9155 || CHECK_FLAG(p->af_cap[afi][safi],
9156 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
9157 vty_out(vty,
9158 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
9159 ORF_TYPE_PREFIX_OLD);
9160 bgp_show_peer_afi_orf_cap(
9161 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
9162 PEER_CAP_ORF_PREFIX_RM_ADV,
9163 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
9164 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
9165 }
9166
9167 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
9168 orf_pfx_count = prefix_bgp_show_prefix_list(
9169 NULL, afi, orf_pfx_name, use_json);
9170
9171 if (CHECK_FLAG(p->af_sflags[afi][safi],
9172 PEER_STATUS_ORF_PREFIX_SEND)
9173 || orf_pfx_count) {
9174 vty_out(vty, " Outbound Route Filter (ORF):");
9175 if (CHECK_FLAG(p->af_sflags[afi][safi],
9176 PEER_STATUS_ORF_PREFIX_SEND))
9177 vty_out(vty, " sent;");
9178 if (orf_pfx_count)
9179 vty_out(vty, " received (%d entries)",
9180 orf_pfx_count);
9181 vty_out(vty, "\n");
9182 }
9183 if (CHECK_FLAG(p->af_sflags[afi][safi],
9184 PEER_STATUS_ORF_WAIT_REFRESH))
9185 vty_out(vty,
9186 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
9187
9188 if (CHECK_FLAG(p->af_flags[afi][safi],
9189 PEER_FLAG_REFLECTOR_CLIENT))
9190 vty_out(vty, " Route-Reflector Client\n");
9191 if (CHECK_FLAG(p->af_flags[afi][safi],
9192 PEER_FLAG_RSERVER_CLIENT))
9193 vty_out(vty, " Route-Server Client\n");
9194 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9195 vty_out(vty,
9196 " Inbound soft reconfiguration allowed\n");
9197
9198 if (CHECK_FLAG(p->af_flags[afi][safi],
9199 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
9200 vty_out(vty,
9201 " Private AS numbers (all) replaced in updates to this neighbor\n");
9202 else if (CHECK_FLAG(p->af_flags[afi][safi],
9203 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
9204 vty_out(vty,
9205 " Private AS numbers replaced in updates to this neighbor\n");
9206 else if (CHECK_FLAG(p->af_flags[afi][safi],
9207 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
9208 vty_out(vty,
9209 " Private AS numbers (all) removed in updates to this neighbor\n");
9210 else if (CHECK_FLAG(p->af_flags[afi][safi],
9211 PEER_FLAG_REMOVE_PRIVATE_AS))
9212 vty_out(vty,
9213 " Private AS numbers removed in updates to this neighbor\n");
9214
9215 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
9216 vty_out(vty, " %s\n",
9217 bgp_addpath_names(p->addpath_type[afi][safi])
9218 ->human_description);
9219
9220 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
9221 vty_out(vty,
9222 " Override ASNs in outbound updates if aspath equals remote-as\n");
9223
9224 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
9225 || CHECK_FLAG(p->af_flags[afi][safi],
9226 PEER_FLAG_FORCE_NEXTHOP_SELF))
9227 vty_out(vty, " NEXT_HOP is always this router\n");
9228 if (CHECK_FLAG(p->af_flags[afi][safi],
9229 PEER_FLAG_AS_PATH_UNCHANGED))
9230 vty_out(vty,
9231 " AS_PATH is propagated unchanged to this neighbor\n");
9232 if (CHECK_FLAG(p->af_flags[afi][safi],
9233 PEER_FLAG_NEXTHOP_UNCHANGED))
9234 vty_out(vty,
9235 " NEXT_HOP is propagated unchanged to this neighbor\n");
9236 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
9237 vty_out(vty,
9238 " MED is propagated unchanged to this neighbor\n");
9239 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
9240 || CHECK_FLAG(p->af_flags[afi][safi],
9241 PEER_FLAG_SEND_EXT_COMMUNITY)
9242 || CHECK_FLAG(p->af_flags[afi][safi],
9243 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
9244 vty_out(vty,
9245 " Community attribute sent to this neighbor");
9246 if (CHECK_FLAG(p->af_flags[afi][safi],
9247 PEER_FLAG_SEND_COMMUNITY)
9248 && CHECK_FLAG(p->af_flags[afi][safi],
9249 PEER_FLAG_SEND_EXT_COMMUNITY)
9250 && CHECK_FLAG(p->af_flags[afi][safi],
9251 PEER_FLAG_SEND_LARGE_COMMUNITY))
9252 vty_out(vty, "(all)\n");
9253 else if (CHECK_FLAG(p->af_flags[afi][safi],
9254 PEER_FLAG_SEND_LARGE_COMMUNITY))
9255 vty_out(vty, "(large)\n");
9256 else if (CHECK_FLAG(p->af_flags[afi][safi],
9257 PEER_FLAG_SEND_EXT_COMMUNITY))
9258 vty_out(vty, "(extended)\n");
9259 else
9260 vty_out(vty, "(standard)\n");
9261 }
9262 if (CHECK_FLAG(p->af_flags[afi][safi],
9263 PEER_FLAG_DEFAULT_ORIGINATE)) {
9264 vty_out(vty, " Default information originate,");
9265
9266 if (p->default_rmap[afi][safi].name)
9267 vty_out(vty, " default route-map %s%s,",
9268 p->default_rmap[afi][safi].map ? "*"
9269 : "",
9270 p->default_rmap[afi][safi].name);
9271 if (paf && PAF_SUBGRP(paf)
9272 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
9273 SUBGRP_STATUS_DEFAULT_ORIGINATE))
9274 vty_out(vty, " default sent\n");
9275 else
9276 vty_out(vty, " default not sent\n");
9277 }
9278
9279 /* advertise-vni-all */
9280 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
9281 if (is_evpn_enabled())
9282 vty_out(vty, " advertise-all-vni\n");
9283 }
9284
9285 if (filter->plist[FILTER_IN].name
9286 || filter->dlist[FILTER_IN].name
9287 || filter->aslist[FILTER_IN].name
9288 || filter->map[RMAP_IN].name)
9289 vty_out(vty, " Inbound path policy configured\n");
9290 if (filter->plist[FILTER_OUT].name
9291 || filter->dlist[FILTER_OUT].name
9292 || filter->aslist[FILTER_OUT].name
9293 || filter->map[RMAP_OUT].name || filter->usmap.name)
9294 vty_out(vty, " Outbound path policy configured\n");
9295
9296 /* prefix-list */
9297 if (filter->plist[FILTER_IN].name)
9298 vty_out(vty,
9299 " Incoming update prefix filter list is %s%s\n",
9300 filter->plist[FILTER_IN].plist ? "*" : "",
9301 filter->plist[FILTER_IN].name);
9302 if (filter->plist[FILTER_OUT].name)
9303 vty_out(vty,
9304 " Outgoing update prefix filter list is %s%s\n",
9305 filter->plist[FILTER_OUT].plist ? "*" : "",
9306 filter->plist[FILTER_OUT].name);
9307
9308 /* distribute-list */
9309 if (filter->dlist[FILTER_IN].name)
9310 vty_out(vty,
9311 " Incoming update network filter list is %s%s\n",
9312 filter->dlist[FILTER_IN].alist ? "*" : "",
9313 filter->dlist[FILTER_IN].name);
9314 if (filter->dlist[FILTER_OUT].name)
9315 vty_out(vty,
9316 " Outgoing update network filter list is %s%s\n",
9317 filter->dlist[FILTER_OUT].alist ? "*" : "",
9318 filter->dlist[FILTER_OUT].name);
9319
9320 /* filter-list. */
9321 if (filter->aslist[FILTER_IN].name)
9322 vty_out(vty,
9323 " Incoming update AS path filter list is %s%s\n",
9324 filter->aslist[FILTER_IN].aslist ? "*" : "",
9325 filter->aslist[FILTER_IN].name);
9326 if (filter->aslist[FILTER_OUT].name)
9327 vty_out(vty,
9328 " Outgoing update AS path filter list is %s%s\n",
9329 filter->aslist[FILTER_OUT].aslist ? "*" : "",
9330 filter->aslist[FILTER_OUT].name);
9331
9332 /* route-map. */
9333 if (filter->map[RMAP_IN].name)
9334 vty_out(vty,
9335 " Route map for incoming advertisements is %s%s\n",
9336 filter->map[RMAP_IN].map ? "*" : "",
9337 filter->map[RMAP_IN].name);
9338 if (filter->map[RMAP_OUT].name)
9339 vty_out(vty,
9340 " Route map for outgoing advertisements is %s%s\n",
9341 filter->map[RMAP_OUT].map ? "*" : "",
9342 filter->map[RMAP_OUT].name);
9343
9344 /* ebgp-requires-policy (inbound) */
9345 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
9346 && !bgp_inbound_policy_exists(p, filter))
9347 vty_out(vty,
9348 " Inbound updates discarded due to missing policy\n");
9349
9350 /* ebgp-requires-policy (outbound) */
9351 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
9352 && !bgp_outbound_policy_exists(p, filter))
9353 vty_out(vty,
9354 " Outbound updates discarded due to missing policy\n");
9355
9356 /* unsuppress-map */
9357 if (filter->usmap.name)
9358 vty_out(vty,
9359 " Route map for selective unsuppress is %s%s\n",
9360 filter->usmap.map ? "*" : "",
9361 filter->usmap.name);
9362
9363 /* Receive prefix count */
9364 vty_out(vty, " %" PRIu32 " accepted prefixes\n",
9365 p->pcount[afi][safi]);
9366
9367 /* Maximum prefix */
9368 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
9369 vty_out(vty,
9370 " Maximum prefixes allowed %" PRIu32 "%s\n",
9371 p->pmax[afi][safi],
9372 CHECK_FLAG(p->af_flags[afi][safi],
9373 PEER_FLAG_MAX_PREFIX_WARNING)
9374 ? " (warning-only)"
9375 : "");
9376 vty_out(vty, " Threshold for warning message %d%%",
9377 p->pmax_threshold[afi][safi]);
9378 if (p->pmax_restart[afi][safi])
9379 vty_out(vty, ", restart interval %d min",
9380 p->pmax_restart[afi][safi]);
9381 vty_out(vty, "\n");
9382 }
9383
9384 vty_out(vty, "\n");
9385 }
9386 }
9387
9388 static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
9389 json_object *json)
9390 {
9391 struct bgp *bgp;
9392 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
9393 char timebuf[BGP_UPTIME_LEN];
9394 char dn_flag[2];
9395 afi_t afi;
9396 safi_t safi;
9397 uint16_t i;
9398 uint8_t *msg;
9399 json_object *json_neigh = NULL;
9400 time_t epoch_tbuf;
9401
9402 bgp = p->bgp;
9403
9404 if (use_json)
9405 json_neigh = json_object_new_object();
9406
9407 memset(dn_flag, '\0', sizeof(dn_flag));
9408 if (!p->conf_if && peer_dynamic_neighbor(p))
9409 dn_flag[0] = '*';
9410
9411 if (!use_json) {
9412 if (p->conf_if) /* Configured interface name. */
9413 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
9414 BGP_PEER_SU_UNSPEC(p)
9415 ? "None"
9416 : sockunion2str(&p->su, buf,
9417 SU_ADDRSTRLEN));
9418 else /* Configured IP address. */
9419 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
9420 p->host);
9421 }
9422
9423 if (use_json) {
9424 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
9425 json_object_string_add(json_neigh, "bgpNeighborAddr",
9426 "none");
9427 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
9428 json_object_string_add(
9429 json_neigh, "bgpNeighborAddr",
9430 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
9431
9432 json_object_int_add(json_neigh, "remoteAs", p->as);
9433
9434 if (p->change_local_as)
9435 json_object_int_add(json_neigh, "localAs",
9436 p->change_local_as);
9437 else
9438 json_object_int_add(json_neigh, "localAs", p->local_as);
9439
9440 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
9441 json_object_boolean_true_add(json_neigh,
9442 "localAsNoPrepend");
9443
9444 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
9445 json_object_boolean_true_add(json_neigh,
9446 "localAsReplaceAs");
9447 } else {
9448 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
9449 || (p->as_type == AS_INTERNAL))
9450 vty_out(vty, "remote AS %u, ", p->as);
9451 else
9452 vty_out(vty, "remote AS Unspecified, ");
9453 vty_out(vty, "local AS %u%s%s, ",
9454 p->change_local_as ? p->change_local_as : p->local_as,
9455 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
9456 ? " no-prepend"
9457 : "",
9458 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
9459 ? " replace-as"
9460 : "");
9461 }
9462 /* peer type internal or confed-internal */
9463 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
9464 if (use_json) {
9465 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9466 json_object_boolean_true_add(
9467 json_neigh, "nbrConfedInternalLink");
9468 else
9469 json_object_boolean_true_add(json_neigh,
9470 "nbrInternalLink");
9471 } else {
9472 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9473 vty_out(vty, "confed-internal link\n");
9474 else
9475 vty_out(vty, "internal link\n");
9476 }
9477 /* peer type external or confed-external */
9478 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
9479 if (use_json) {
9480 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9481 json_object_boolean_true_add(
9482 json_neigh, "nbrConfedExternalLink");
9483 else
9484 json_object_boolean_true_add(json_neigh,
9485 "nbrExternalLink");
9486 } else {
9487 if (bgp_confederation_peers_check(bgp, p->as))
9488 vty_out(vty, "confed-external link\n");
9489 else
9490 vty_out(vty, "external link\n");
9491 }
9492 } else {
9493 if (use_json)
9494 json_object_boolean_true_add(json_neigh,
9495 "nbrUnspecifiedLink");
9496 else
9497 vty_out(vty, "unspecified link\n");
9498 }
9499
9500 /* Description. */
9501 if (p->desc) {
9502 if (use_json)
9503 json_object_string_add(json_neigh, "nbrDesc", p->desc);
9504 else
9505 vty_out(vty, " Description: %s\n", p->desc);
9506 }
9507
9508 if (p->hostname) {
9509 if (use_json) {
9510 if (p->hostname)
9511 json_object_string_add(json_neigh, "hostname",
9512 p->hostname);
9513
9514 if (p->domainname)
9515 json_object_string_add(json_neigh, "domainname",
9516 p->domainname);
9517 } else {
9518 if (p->domainname && (p->domainname[0] != '\0'))
9519 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
9520 p->domainname);
9521 else
9522 vty_out(vty, "Hostname: %s\n", p->hostname);
9523 }
9524 }
9525
9526 /* Peer-group */
9527 if (p->group) {
9528 if (use_json) {
9529 json_object_string_add(json_neigh, "peerGroup",
9530 p->group->name);
9531
9532 if (dn_flag[0]) {
9533 struct prefix prefix, *range = NULL;
9534
9535 sockunion2hostprefix(&(p->su), &prefix);
9536 range = peer_group_lookup_dynamic_neighbor_range(
9537 p->group, &prefix);
9538
9539 if (range) {
9540 prefix2str(range, buf1, sizeof(buf1));
9541 json_object_string_add(
9542 json_neigh,
9543 "peerSubnetRangeGroup", buf1);
9544 }
9545 }
9546 } else {
9547 vty_out(vty,
9548 " Member of peer-group %s for session parameters\n",
9549 p->group->name);
9550
9551 if (dn_flag[0]) {
9552 struct prefix prefix, *range = NULL;
9553
9554 sockunion2hostprefix(&(p->su), &prefix);
9555 range = peer_group_lookup_dynamic_neighbor_range(
9556 p->group, &prefix);
9557
9558 if (range) {
9559 prefix2str(range, buf1, sizeof(buf1));
9560 vty_out(vty,
9561 " Belongs to the subnet range group: %s\n",
9562 buf1);
9563 }
9564 }
9565 }
9566 }
9567
9568 if (use_json) {
9569 /* Administrative shutdown. */
9570 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9571 json_object_boolean_true_add(json_neigh,
9572 "adminShutDown");
9573
9574 /* BGP Version. */
9575 json_object_int_add(json_neigh, "bgpVersion", 4);
9576 json_object_string_add(
9577 json_neigh, "remoteRouterId",
9578 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9579 json_object_string_add(
9580 json_neigh, "localRouterId",
9581 inet_ntop(AF_INET, &bgp->router_id, buf1,
9582 sizeof(buf1)));
9583
9584 /* Confederation */
9585 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9586 && bgp_confederation_peers_check(bgp, p->as))
9587 json_object_boolean_true_add(json_neigh,
9588 "nbrCommonAdmin");
9589
9590 /* Status. */
9591 json_object_string_add(
9592 json_neigh, "bgpState",
9593 lookup_msg(bgp_status_msg, p->status, NULL));
9594
9595 if (p->status == Established) {
9596 time_t uptime;
9597
9598 uptime = bgp_clock();
9599 uptime -= p->uptime;
9600 epoch_tbuf = time(NULL) - uptime;
9601
9602 #if CONFDATE > 20200101
9603 CPP_NOTICE(
9604 "bgpTimerUp should be deprecated and can be removed now");
9605 #endif
9606 /*
9607 * bgpTimerUp was miliseconds that was accurate
9608 * up to 1 day, then the value returned
9609 * became garbage. So in order to provide
9610 * some level of backwards compatability,
9611 * we still provde the data, but now
9612 * we are returning the correct value
9613 * and also adding a new bgpTimerUpMsec
9614 * which will allow us to deprecate
9615 * this eventually
9616 */
9617 json_object_int_add(json_neigh, "bgpTimerUp",
9618 uptime * 1000);
9619 json_object_int_add(json_neigh, "bgpTimerUpMsec",
9620 uptime * 1000);
9621 json_object_string_add(json_neigh, "bgpTimerUpString",
9622 peer_uptime(p->uptime, timebuf,
9623 BGP_UPTIME_LEN, 0,
9624 NULL));
9625 json_object_int_add(json_neigh,
9626 "bgpTimerUpEstablishedEpoch",
9627 epoch_tbuf);
9628 }
9629
9630 else if (p->status == Active) {
9631 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9632 json_object_string_add(json_neigh, "bgpStateIs",
9633 "passive");
9634 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9635 json_object_string_add(json_neigh, "bgpStateIs",
9636 "passiveNSF");
9637 }
9638
9639 /* read timer */
9640 time_t uptime;
9641 struct tm *tm;
9642
9643 uptime = bgp_clock();
9644 uptime -= p->readtime;
9645 tm = gmtime(&uptime);
9646 json_object_int_add(json_neigh, "bgpTimerLastRead",
9647 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9648 + (tm->tm_hour * 3600000));
9649
9650 uptime = bgp_clock();
9651 uptime -= p->last_write;
9652 tm = gmtime(&uptime);
9653 json_object_int_add(json_neigh, "bgpTimerLastWrite",
9654 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9655 + (tm->tm_hour * 3600000));
9656
9657 uptime = bgp_clock();
9658 uptime -= p->update_time;
9659 tm = gmtime(&uptime);
9660 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
9661 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9662 + (tm->tm_hour * 3600000));
9663
9664 /* Configured timer values. */
9665 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
9666 p->v_holdtime * 1000);
9667 json_object_int_add(json_neigh,
9668 "bgpTimerKeepAliveIntervalMsecs",
9669 p->v_keepalive * 1000);
9670 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
9671 json_object_int_add(json_neigh,
9672 "bgpTimerConfiguredHoldTimeMsecs",
9673 p->holdtime * 1000);
9674 json_object_int_add(
9675 json_neigh,
9676 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9677 p->keepalive * 1000);
9678 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
9679 || (bgp->default_keepalive
9680 != BGP_DEFAULT_KEEPALIVE)) {
9681 json_object_int_add(json_neigh,
9682 "bgpTimerConfiguredHoldTimeMsecs",
9683 bgp->default_holdtime);
9684 json_object_int_add(
9685 json_neigh,
9686 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9687 bgp->default_keepalive);
9688 }
9689 } else {
9690 /* Administrative shutdown. */
9691 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9692 vty_out(vty, " Administratively shut down\n");
9693
9694 /* BGP Version. */
9695 vty_out(vty, " BGP version 4");
9696 vty_out(vty, ", remote router ID %s",
9697 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9698 vty_out(vty, ", local router ID %s\n",
9699 inet_ntop(AF_INET, &bgp->router_id, buf1,
9700 sizeof(buf1)));
9701
9702 /* Confederation */
9703 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9704 && bgp_confederation_peers_check(bgp, p->as))
9705 vty_out(vty,
9706 " Neighbor under common administration\n");
9707
9708 /* Status. */
9709 vty_out(vty, " BGP state = %s",
9710 lookup_msg(bgp_status_msg, p->status, NULL));
9711
9712 if (p->status == Established)
9713 vty_out(vty, ", up for %8s",
9714 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
9715 0, NULL));
9716
9717 else if (p->status == Active) {
9718 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9719 vty_out(vty, " (passive)");
9720 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9721 vty_out(vty, " (NSF passive)");
9722 }
9723 vty_out(vty, "\n");
9724
9725 /* read timer */
9726 vty_out(vty, " Last read %s",
9727 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
9728 NULL));
9729 vty_out(vty, ", Last write %s\n",
9730 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
9731 NULL));
9732
9733 /* Configured timer values. */
9734 vty_out(vty,
9735 " Hold time is %d, keepalive interval is %d seconds\n",
9736 p->v_holdtime, p->v_keepalive);
9737 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
9738 vty_out(vty, " Configured hold time is %d",
9739 p->holdtime);
9740 vty_out(vty, ", keepalive interval is %d seconds\n",
9741 p->keepalive);
9742 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
9743 || (bgp->default_keepalive
9744 != BGP_DEFAULT_KEEPALIVE)) {
9745 vty_out(vty, " Configured hold time is %d",
9746 bgp->default_holdtime);
9747 vty_out(vty, ", keepalive interval is %d seconds\n",
9748 bgp->default_keepalive);
9749 }
9750 }
9751 /* Capability. */
9752 if (p->status == Established) {
9753 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
9754 || p->afc_recv[AFI_IP][SAFI_UNICAST]
9755 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
9756 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
9757 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
9758 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
9759 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
9760 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
9761 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
9762 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
9763 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
9764 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
9765 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
9766 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
9767 || p->afc_adv[AFI_IP][SAFI_ENCAP]
9768 || p->afc_recv[AFI_IP][SAFI_ENCAP]
9769 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
9770 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
9771 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
9772 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
9773 if (use_json) {
9774 json_object *json_cap = NULL;
9775
9776 json_cap = json_object_new_object();
9777
9778 /* AS4 */
9779 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9780 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9781 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
9782 && CHECK_FLAG(p->cap,
9783 PEER_CAP_AS4_RCV))
9784 json_object_string_add(
9785 json_cap, "4byteAs",
9786 "advertisedAndReceived");
9787 else if (CHECK_FLAG(p->cap,
9788 PEER_CAP_AS4_ADV))
9789 json_object_string_add(
9790 json_cap, "4byteAs",
9791 "advertised");
9792 else if (CHECK_FLAG(p->cap,
9793 PEER_CAP_AS4_RCV))
9794 json_object_string_add(
9795 json_cap, "4byteAs",
9796 "received");
9797 }
9798
9799 /* AddPath */
9800 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9801 || CHECK_FLAG(p->cap,
9802 PEER_CAP_ADDPATH_ADV)) {
9803 json_object *json_add = NULL;
9804 const char *print_store;
9805
9806 json_add = json_object_new_object();
9807
9808 FOREACH_AFI_SAFI (afi, safi) {
9809 json_object *json_sub = NULL;
9810 json_sub =
9811 json_object_new_object();
9812 print_store = get_afi_safi_str(
9813 afi, safi, true);
9814
9815 if (CHECK_FLAG(
9816 p->af_cap[afi]
9817 [safi],
9818 PEER_CAP_ADDPATH_AF_TX_ADV)
9819 || CHECK_FLAG(
9820 p->af_cap[afi]
9821 [safi],
9822 PEER_CAP_ADDPATH_AF_TX_RCV)) {
9823 if (CHECK_FLAG(
9824 p->af_cap
9825 [afi]
9826 [safi],
9827 PEER_CAP_ADDPATH_AF_TX_ADV)
9828 && CHECK_FLAG(
9829 p->af_cap
9830 [afi]
9831 [safi],
9832 PEER_CAP_ADDPATH_AF_TX_RCV))
9833 json_object_boolean_true_add(
9834 json_sub,
9835 "txAdvertisedAndReceived");
9836 else if (
9837 CHECK_FLAG(
9838 p->af_cap
9839 [afi]
9840 [safi],
9841 PEER_CAP_ADDPATH_AF_TX_ADV))
9842 json_object_boolean_true_add(
9843 json_sub,
9844 "txAdvertised");
9845 else if (
9846 CHECK_FLAG(
9847 p->af_cap
9848 [afi]
9849 [safi],
9850 PEER_CAP_ADDPATH_AF_TX_RCV))
9851 json_object_boolean_true_add(
9852 json_sub,
9853 "txReceived");
9854 }
9855
9856 if (CHECK_FLAG(
9857 p->af_cap[afi]
9858 [safi],
9859 PEER_CAP_ADDPATH_AF_RX_ADV)
9860 || CHECK_FLAG(
9861 p->af_cap[afi]
9862 [safi],
9863 PEER_CAP_ADDPATH_AF_RX_RCV)) {
9864 if (CHECK_FLAG(
9865 p->af_cap
9866 [afi]
9867 [safi],
9868 PEER_CAP_ADDPATH_AF_RX_ADV)
9869 && CHECK_FLAG(
9870 p->af_cap
9871 [afi]
9872 [safi],
9873 PEER_CAP_ADDPATH_AF_RX_RCV))
9874 json_object_boolean_true_add(
9875 json_sub,
9876 "rxAdvertisedAndReceived");
9877 else if (
9878 CHECK_FLAG(
9879 p->af_cap
9880 [afi]
9881 [safi],
9882 PEER_CAP_ADDPATH_AF_RX_ADV))
9883 json_object_boolean_true_add(
9884 json_sub,
9885 "rxAdvertised");
9886 else if (
9887 CHECK_FLAG(
9888 p->af_cap
9889 [afi]
9890 [safi],
9891 PEER_CAP_ADDPATH_AF_RX_RCV))
9892 json_object_boolean_true_add(
9893 json_sub,
9894 "rxReceived");
9895 }
9896
9897 if (CHECK_FLAG(
9898 p->af_cap[afi]
9899 [safi],
9900 PEER_CAP_ADDPATH_AF_TX_ADV)
9901 || CHECK_FLAG(
9902 p->af_cap[afi]
9903 [safi],
9904 PEER_CAP_ADDPATH_AF_TX_RCV)
9905 || CHECK_FLAG(
9906 p->af_cap[afi]
9907 [safi],
9908 PEER_CAP_ADDPATH_AF_RX_ADV)
9909 || CHECK_FLAG(
9910 p->af_cap[afi]
9911 [safi],
9912 PEER_CAP_ADDPATH_AF_RX_RCV))
9913 json_object_object_add(
9914 json_add,
9915 print_store,
9916 json_sub);
9917 else
9918 json_object_free(
9919 json_sub);
9920 }
9921
9922 json_object_object_add(
9923 json_cap, "addPath", json_add);
9924 }
9925
9926 /* Dynamic */
9927 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9928 || CHECK_FLAG(p->cap,
9929 PEER_CAP_DYNAMIC_ADV)) {
9930 if (CHECK_FLAG(p->cap,
9931 PEER_CAP_DYNAMIC_ADV)
9932 && CHECK_FLAG(p->cap,
9933 PEER_CAP_DYNAMIC_RCV))
9934 json_object_string_add(
9935 json_cap, "dynamic",
9936 "advertisedAndReceived");
9937 else if (CHECK_FLAG(
9938 p->cap,
9939 PEER_CAP_DYNAMIC_ADV))
9940 json_object_string_add(
9941 json_cap, "dynamic",
9942 "advertised");
9943 else if (CHECK_FLAG(
9944 p->cap,
9945 PEER_CAP_DYNAMIC_RCV))
9946 json_object_string_add(
9947 json_cap, "dynamic",
9948 "received");
9949 }
9950
9951 /* Extended nexthop */
9952 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9953 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9954 json_object *json_nxt = NULL;
9955 const char *print_store;
9956
9957
9958 if (CHECK_FLAG(p->cap,
9959 PEER_CAP_ENHE_ADV)
9960 && CHECK_FLAG(p->cap,
9961 PEER_CAP_ENHE_RCV))
9962 json_object_string_add(
9963 json_cap,
9964 "extendedNexthop",
9965 "advertisedAndReceived");
9966 else if (CHECK_FLAG(p->cap,
9967 PEER_CAP_ENHE_ADV))
9968 json_object_string_add(
9969 json_cap,
9970 "extendedNexthop",
9971 "advertised");
9972 else if (CHECK_FLAG(p->cap,
9973 PEER_CAP_ENHE_RCV))
9974 json_object_string_add(
9975 json_cap,
9976 "extendedNexthop",
9977 "received");
9978
9979 if (CHECK_FLAG(p->cap,
9980 PEER_CAP_ENHE_RCV)) {
9981 json_nxt =
9982 json_object_new_object();
9983
9984 for (safi = SAFI_UNICAST;
9985 safi < SAFI_MAX; safi++) {
9986 if (CHECK_FLAG(
9987 p->af_cap
9988 [AFI_IP]
9989 [safi],
9990 PEER_CAP_ENHE_AF_RCV)) {
9991 print_store = get_afi_safi_str(
9992 AFI_IP,
9993 safi, true);
9994 json_object_string_add(
9995 json_nxt,
9996 print_store,
9997 "recieved"); /* misspelled for compatibility */
9998 }
9999 }
10000 json_object_object_add(
10001 json_cap,
10002 "extendedNexthopFamililesByPeer",
10003 json_nxt);
10004 }
10005 }
10006
10007 /* Route Refresh */
10008 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
10009 || CHECK_FLAG(p->cap,
10010 PEER_CAP_REFRESH_NEW_RCV)
10011 || CHECK_FLAG(p->cap,
10012 PEER_CAP_REFRESH_OLD_RCV)) {
10013 if (CHECK_FLAG(p->cap,
10014 PEER_CAP_REFRESH_ADV)
10015 && (CHECK_FLAG(
10016 p->cap,
10017 PEER_CAP_REFRESH_NEW_RCV)
10018 || CHECK_FLAG(
10019 p->cap,
10020 PEER_CAP_REFRESH_OLD_RCV))) {
10021 if (CHECK_FLAG(
10022 p->cap,
10023 PEER_CAP_REFRESH_OLD_RCV)
10024 && CHECK_FLAG(
10025 p->cap,
10026 PEER_CAP_REFRESH_NEW_RCV))
10027 json_object_string_add(
10028 json_cap,
10029 "routeRefresh",
10030 "advertisedAndReceivedOldNew");
10031 else {
10032 if (CHECK_FLAG(
10033 p->cap,
10034 PEER_CAP_REFRESH_OLD_RCV))
10035 json_object_string_add(
10036 json_cap,
10037 "routeRefresh",
10038 "advertisedAndReceivedOld");
10039 else
10040 json_object_string_add(
10041 json_cap,
10042 "routeRefresh",
10043 "advertisedAndReceivedNew");
10044 }
10045 } else if (
10046 CHECK_FLAG(
10047 p->cap,
10048 PEER_CAP_REFRESH_ADV))
10049 json_object_string_add(
10050 json_cap,
10051 "routeRefresh",
10052 "advertised");
10053 else if (
10054 CHECK_FLAG(
10055 p->cap,
10056 PEER_CAP_REFRESH_NEW_RCV)
10057 || CHECK_FLAG(
10058 p->cap,
10059 PEER_CAP_REFRESH_OLD_RCV))
10060 json_object_string_add(
10061 json_cap,
10062 "routeRefresh",
10063 "received");
10064 }
10065
10066 /* Multiprotocol Extensions */
10067 json_object *json_multi = NULL;
10068 json_multi = json_object_new_object();
10069
10070 FOREACH_AFI_SAFI (afi, safi) {
10071 if (p->afc_adv[afi][safi]
10072 || p->afc_recv[afi][safi]) {
10073 json_object *json_exten = NULL;
10074 json_exten =
10075 json_object_new_object();
10076
10077 if (p->afc_adv[afi][safi]
10078 && p->afc_recv[afi][safi])
10079 json_object_boolean_true_add(
10080 json_exten,
10081 "advertisedAndReceived");
10082 else if (p->afc_adv[afi][safi])
10083 json_object_boolean_true_add(
10084 json_exten,
10085 "advertised");
10086 else if (p->afc_recv[afi][safi])
10087 json_object_boolean_true_add(
10088 json_exten,
10089 "received");
10090
10091 json_object_object_add(
10092 json_multi,
10093 get_afi_safi_str(afi,
10094 safi,
10095 true),
10096 json_exten);
10097 }
10098 }
10099 json_object_object_add(
10100 json_cap, "multiprotocolExtensions",
10101 json_multi);
10102
10103 /* Hostname capabilities */
10104 json_object *json_hname = NULL;
10105
10106 json_hname = json_object_new_object();
10107
10108 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
10109 json_object_string_add(
10110 json_hname, "advHostName",
10111 bgp->peer_self->hostname
10112 ? bgp->peer_self
10113 ->hostname
10114 : "n/a");
10115 json_object_string_add(
10116 json_hname, "advDomainName",
10117 bgp->peer_self->domainname
10118 ? bgp->peer_self
10119 ->domainname
10120 : "n/a");
10121 }
10122
10123
10124 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
10125 json_object_string_add(
10126 json_hname, "rcvHostName",
10127 p->hostname ? p->hostname
10128 : "n/a");
10129 json_object_string_add(
10130 json_hname, "rcvDomainName",
10131 p->domainname ? p->domainname
10132 : "n/a");
10133 }
10134
10135 json_object_object_add(json_cap, "hostName",
10136 json_hname);
10137
10138 /* Gracefull Restart */
10139 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
10140 || CHECK_FLAG(p->cap,
10141 PEER_CAP_RESTART_ADV)) {
10142 if (CHECK_FLAG(p->cap,
10143 PEER_CAP_RESTART_ADV)
10144 && CHECK_FLAG(p->cap,
10145 PEER_CAP_RESTART_RCV))
10146 json_object_string_add(
10147 json_cap,
10148 "gracefulRestart",
10149 "advertisedAndReceived");
10150 else if (CHECK_FLAG(
10151 p->cap,
10152 PEER_CAP_RESTART_ADV))
10153 json_object_string_add(
10154 json_cap,
10155 "gracefulRestartCapability",
10156 "advertised");
10157 else if (CHECK_FLAG(
10158 p->cap,
10159 PEER_CAP_RESTART_RCV))
10160 json_object_string_add(
10161 json_cap,
10162 "gracefulRestartCapability",
10163 "received");
10164
10165 if (CHECK_FLAG(p->cap,
10166 PEER_CAP_RESTART_RCV)) {
10167 int restart_af_count = 0;
10168 json_object *json_restart =
10169 NULL;
10170 json_restart =
10171 json_object_new_object();
10172
10173 json_object_int_add(
10174 json_cap,
10175 "gracefulRestartRemoteTimerMsecs",
10176 p->v_gr_restart * 1000);
10177
10178 FOREACH_AFI_SAFI (afi, safi) {
10179 if (CHECK_FLAG(
10180 p->af_cap
10181 [afi]
10182 [safi],
10183 PEER_CAP_RESTART_AF_RCV)) {
10184 json_object *
10185 json_sub =
10186 NULL;
10187 json_sub =
10188 json_object_new_object();
10189
10190 if (CHECK_FLAG(
10191 p->af_cap
10192 [afi]
10193 [safi],
10194 PEER_CAP_RESTART_AF_PRESERVE_RCV))
10195 json_object_boolean_true_add(
10196 json_sub,
10197 "preserved");
10198 restart_af_count++;
10199 json_object_object_add(
10200 json_restart,
10201 get_afi_safi_str(
10202 afi,
10203 safi,
10204 true),
10205 json_sub);
10206 }
10207 }
10208 if (!restart_af_count) {
10209 json_object_string_add(
10210 json_cap,
10211 "addressFamiliesByPeer",
10212 "none");
10213 json_object_free(
10214 json_restart);
10215 } else
10216 json_object_object_add(
10217 json_cap,
10218 "addressFamiliesByPeer",
10219 json_restart);
10220 }
10221 }
10222 json_object_object_add(json_neigh,
10223 "neighborCapabilities",
10224 json_cap);
10225 } else {
10226 vty_out(vty, " Neighbor capabilities:\n");
10227
10228 /* AS4 */
10229 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
10230 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
10231 vty_out(vty, " 4 Byte AS:");
10232 if (CHECK_FLAG(p->cap,
10233 PEER_CAP_AS4_ADV))
10234 vty_out(vty, " advertised");
10235 if (CHECK_FLAG(p->cap,
10236 PEER_CAP_AS4_RCV))
10237 vty_out(vty, " %sreceived",
10238 CHECK_FLAG(
10239 p->cap,
10240 PEER_CAP_AS4_ADV)
10241 ? "and "
10242 : "");
10243 vty_out(vty, "\n");
10244 }
10245
10246 /* AddPath */
10247 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
10248 || CHECK_FLAG(p->cap,
10249 PEER_CAP_ADDPATH_ADV)) {
10250 vty_out(vty, " AddPath:\n");
10251
10252 FOREACH_AFI_SAFI (afi, safi) {
10253 if (CHECK_FLAG(
10254 p->af_cap[afi]
10255 [safi],
10256 PEER_CAP_ADDPATH_AF_TX_ADV)
10257 || CHECK_FLAG(
10258 p->af_cap[afi]
10259 [safi],
10260 PEER_CAP_ADDPATH_AF_TX_RCV)) {
10261 vty_out(vty,
10262 " %s: TX ",
10263 get_afi_safi_str(
10264 afi,
10265 safi,
10266 false));
10267
10268 if (CHECK_FLAG(
10269 p->af_cap
10270 [afi]
10271 [safi],
10272 PEER_CAP_ADDPATH_AF_TX_ADV))
10273 vty_out(vty,
10274 "advertised %s",
10275 get_afi_safi_str(
10276 afi,
10277 safi,
10278 false));
10279
10280 if (CHECK_FLAG(
10281 p->af_cap
10282 [afi]
10283 [safi],
10284 PEER_CAP_ADDPATH_AF_TX_RCV))
10285 vty_out(vty,
10286 "%sreceived",
10287 CHECK_FLAG(
10288 p->af_cap
10289 [afi]
10290 [safi],
10291 PEER_CAP_ADDPATH_AF_TX_ADV)
10292 ? " and "
10293 : "");
10294
10295 vty_out(vty, "\n");
10296 }
10297
10298 if (CHECK_FLAG(
10299 p->af_cap[afi]
10300 [safi],
10301 PEER_CAP_ADDPATH_AF_RX_ADV)
10302 || CHECK_FLAG(
10303 p->af_cap[afi]
10304 [safi],
10305 PEER_CAP_ADDPATH_AF_RX_RCV)) {
10306 vty_out(vty,
10307 " %s: RX ",
10308 get_afi_safi_str(
10309 afi,
10310 safi,
10311 false));
10312
10313 if (CHECK_FLAG(
10314 p->af_cap
10315 [afi]
10316 [safi],
10317 PEER_CAP_ADDPATH_AF_RX_ADV))
10318 vty_out(vty,
10319 "advertised %s",
10320 get_afi_safi_str(
10321 afi,
10322 safi,
10323 false));
10324
10325 if (CHECK_FLAG(
10326 p->af_cap
10327 [afi]
10328 [safi],
10329 PEER_CAP_ADDPATH_AF_RX_RCV))
10330 vty_out(vty,
10331 "%sreceived",
10332 CHECK_FLAG(
10333 p->af_cap
10334 [afi]
10335 [safi],
10336 PEER_CAP_ADDPATH_AF_RX_ADV)
10337 ? " and "
10338 : "");
10339
10340 vty_out(vty, "\n");
10341 }
10342 }
10343 }
10344
10345 /* Dynamic */
10346 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
10347 || CHECK_FLAG(p->cap,
10348 PEER_CAP_DYNAMIC_ADV)) {
10349 vty_out(vty, " Dynamic:");
10350 if (CHECK_FLAG(p->cap,
10351 PEER_CAP_DYNAMIC_ADV))
10352 vty_out(vty, " advertised");
10353 if (CHECK_FLAG(p->cap,
10354 PEER_CAP_DYNAMIC_RCV))
10355 vty_out(vty, " %sreceived",
10356 CHECK_FLAG(
10357 p->cap,
10358 PEER_CAP_DYNAMIC_ADV)
10359 ? "and "
10360 : "");
10361 vty_out(vty, "\n");
10362 }
10363
10364 /* Extended nexthop */
10365 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
10366 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
10367 vty_out(vty, " Extended nexthop:");
10368 if (CHECK_FLAG(p->cap,
10369 PEER_CAP_ENHE_ADV))
10370 vty_out(vty, " advertised");
10371 if (CHECK_FLAG(p->cap,
10372 PEER_CAP_ENHE_RCV))
10373 vty_out(vty, " %sreceived",
10374 CHECK_FLAG(
10375 p->cap,
10376 PEER_CAP_ENHE_ADV)
10377 ? "and "
10378 : "");
10379 vty_out(vty, "\n");
10380
10381 if (CHECK_FLAG(p->cap,
10382 PEER_CAP_ENHE_RCV)) {
10383 vty_out(vty,
10384 " Address families by peer:\n ");
10385 for (safi = SAFI_UNICAST;
10386 safi < SAFI_MAX; safi++)
10387 if (CHECK_FLAG(
10388 p->af_cap
10389 [AFI_IP]
10390 [safi],
10391 PEER_CAP_ENHE_AF_RCV))
10392 vty_out(vty,
10393 " %s\n",
10394 get_afi_safi_str(
10395 AFI_IP,
10396 safi,
10397 false));
10398 }
10399 }
10400
10401 /* Route Refresh */
10402 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
10403 || CHECK_FLAG(p->cap,
10404 PEER_CAP_REFRESH_NEW_RCV)
10405 || CHECK_FLAG(p->cap,
10406 PEER_CAP_REFRESH_OLD_RCV)) {
10407 vty_out(vty, " Route refresh:");
10408 if (CHECK_FLAG(p->cap,
10409 PEER_CAP_REFRESH_ADV))
10410 vty_out(vty, " advertised");
10411 if (CHECK_FLAG(p->cap,
10412 PEER_CAP_REFRESH_NEW_RCV)
10413 || CHECK_FLAG(
10414 p->cap,
10415 PEER_CAP_REFRESH_OLD_RCV))
10416 vty_out(vty, " %sreceived(%s)",
10417 CHECK_FLAG(
10418 p->cap,
10419 PEER_CAP_REFRESH_ADV)
10420 ? "and "
10421 : "",
10422 (CHECK_FLAG(
10423 p->cap,
10424 PEER_CAP_REFRESH_OLD_RCV)
10425 && CHECK_FLAG(
10426 p->cap,
10427 PEER_CAP_REFRESH_NEW_RCV))
10428 ? "old & new"
10429 : CHECK_FLAG(
10430 p->cap,
10431 PEER_CAP_REFRESH_OLD_RCV)
10432 ? "old"
10433 : "new");
10434
10435 vty_out(vty, "\n");
10436 }
10437
10438 /* Multiprotocol Extensions */
10439 FOREACH_AFI_SAFI (afi, safi)
10440 if (p->afc_adv[afi][safi]
10441 || p->afc_recv[afi][safi]) {
10442 vty_out(vty,
10443 " Address Family %s:",
10444 get_afi_safi_str(
10445 afi,
10446 safi,
10447 false));
10448 if (p->afc_adv[afi][safi])
10449 vty_out(vty,
10450 " advertised");
10451 if (p->afc_recv[afi][safi])
10452 vty_out(vty,
10453 " %sreceived",
10454 p->afc_adv[afi]
10455 [safi]
10456 ? "and "
10457 : "");
10458 vty_out(vty, "\n");
10459 }
10460
10461 /* Hostname capability */
10462 vty_out(vty, " Hostname Capability:");
10463
10464 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
10465 vty_out(vty,
10466 " advertised (name: %s,domain name: %s)",
10467 bgp->peer_self->hostname
10468 ? bgp->peer_self
10469 ->hostname
10470 : "n/a",
10471 bgp->peer_self->domainname
10472 ? bgp->peer_self
10473 ->domainname
10474 : "n/a");
10475 } else {
10476 vty_out(vty, " not advertised");
10477 }
10478
10479 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
10480 vty_out(vty,
10481 " received (name: %s,domain name: %s)",
10482 p->hostname ? p->hostname
10483 : "n/a",
10484 p->domainname ? p->domainname
10485 : "n/a");
10486 } else {
10487 vty_out(vty, " not received");
10488 }
10489
10490 vty_out(vty, "\n");
10491
10492 /* Gracefull Restart */
10493 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
10494 || CHECK_FLAG(p->cap,
10495 PEER_CAP_RESTART_ADV)) {
10496 vty_out(vty,
10497 " Graceful Restart Capabilty:");
10498 if (CHECK_FLAG(p->cap,
10499 PEER_CAP_RESTART_ADV))
10500 vty_out(vty, " advertised");
10501 if (CHECK_FLAG(p->cap,
10502 PEER_CAP_RESTART_RCV))
10503 vty_out(vty, " %sreceived",
10504 CHECK_FLAG(
10505 p->cap,
10506 PEER_CAP_RESTART_ADV)
10507 ? "and "
10508 : "");
10509 vty_out(vty, "\n");
10510
10511 if (CHECK_FLAG(p->cap,
10512 PEER_CAP_RESTART_RCV)) {
10513 int restart_af_count = 0;
10514
10515 vty_out(vty,
10516 " Remote Restart timer is %d seconds\n",
10517 p->v_gr_restart);
10518 vty_out(vty,
10519 " Address families by peer:\n ");
10520
10521 FOREACH_AFI_SAFI (afi, safi)
10522 if (CHECK_FLAG(
10523 p->af_cap
10524 [afi]
10525 [safi],
10526 PEER_CAP_RESTART_AF_RCV)) {
10527 vty_out(vty,
10528 "%s%s(%s)",
10529 restart_af_count
10530 ? ", "
10531 : "",
10532 get_afi_safi_str(
10533 afi,
10534 safi,
10535 false),
10536 CHECK_FLAG(
10537 p->af_cap
10538 [afi]
10539 [safi],
10540 PEER_CAP_RESTART_AF_PRESERVE_RCV)
10541 ? "preserved"
10542 : "not preserved");
10543 restart_af_count++;
10544 }
10545 if (!restart_af_count)
10546 vty_out(vty, "none");
10547 vty_out(vty, "\n");
10548 }
10549 }
10550 }
10551 }
10552 }
10553
10554 /* graceful restart information */
10555 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) || p->t_gr_restart
10556 || p->t_gr_stale) {
10557 json_object *json_grace = NULL;
10558 json_object *json_grace_send = NULL;
10559 json_object *json_grace_recv = NULL;
10560 int eor_send_af_count = 0;
10561 int eor_receive_af_count = 0;
10562
10563 if (use_json) {
10564 json_grace = json_object_new_object();
10565 json_grace_send = json_object_new_object();
10566 json_grace_recv = json_object_new_object();
10567
10568 if (p->status == Established) {
10569 FOREACH_AFI_SAFI (afi, safi) {
10570 if (CHECK_FLAG(p->af_sflags[afi][safi],
10571 PEER_STATUS_EOR_SEND)) {
10572 json_object_boolean_true_add(
10573 json_grace_send,
10574 get_afi_safi_str(afi,
10575 safi,
10576 true));
10577 eor_send_af_count++;
10578 }
10579 }
10580 FOREACH_AFI_SAFI (afi, safi) {
10581 if (CHECK_FLAG(
10582 p->af_sflags[afi][safi],
10583 PEER_STATUS_EOR_RECEIVED)) {
10584 json_object_boolean_true_add(
10585 json_grace_recv,
10586 get_afi_safi_str(afi,
10587 safi,
10588 true));
10589 eor_receive_af_count++;
10590 }
10591 }
10592 }
10593
10594 json_object_object_add(json_grace, "endOfRibSend",
10595 json_grace_send);
10596 json_object_object_add(json_grace, "endOfRibRecv",
10597 json_grace_recv);
10598
10599 if (p->t_gr_restart)
10600 json_object_int_add(json_grace,
10601 "gracefulRestartTimerMsecs",
10602 thread_timer_remain_second(
10603 p->t_gr_restart)
10604 * 1000);
10605
10606 if (p->t_gr_stale)
10607 json_object_int_add(
10608 json_grace,
10609 "gracefulStalepathTimerMsecs",
10610 thread_timer_remain_second(
10611 p->t_gr_stale)
10612 * 1000);
10613
10614 json_object_object_add(
10615 json_neigh, "gracefulRestartInfo", json_grace);
10616 } else {
10617 vty_out(vty, " Graceful restart information:\n");
10618 if (p->status == Established) {
10619 vty_out(vty, " End-of-RIB send: ");
10620 FOREACH_AFI_SAFI (afi, safi) {
10621 if (CHECK_FLAG(p->af_sflags[afi][safi],
10622 PEER_STATUS_EOR_SEND)) {
10623 vty_out(vty, "%s%s",
10624 eor_send_af_count ? ", "
10625 : "",
10626 get_afi_safi_str(afi,
10627 safi,
10628 false));
10629 eor_send_af_count++;
10630 }
10631 }
10632 vty_out(vty, "\n");
10633 vty_out(vty, " End-of-RIB received: ");
10634 FOREACH_AFI_SAFI (afi, safi) {
10635 if (CHECK_FLAG(
10636 p->af_sflags[afi][safi],
10637 PEER_STATUS_EOR_RECEIVED)) {
10638 vty_out(vty, "%s%s",
10639 eor_receive_af_count
10640 ? ", "
10641 : "",
10642 get_afi_safi_str(afi,
10643 safi,
10644 false));
10645 eor_receive_af_count++;
10646 }
10647 }
10648 vty_out(vty, "\n");
10649 }
10650
10651 if (p->t_gr_restart)
10652 vty_out(vty,
10653 " The remaining time of restart timer is %ld\n",
10654 thread_timer_remain_second(
10655 p->t_gr_restart));
10656
10657 if (p->t_gr_stale)
10658 vty_out(vty,
10659 " The remaining time of stalepath timer is %ld\n",
10660 thread_timer_remain_second(
10661 p->t_gr_stale));
10662 }
10663 }
10664 if (use_json) {
10665 json_object *json_stat = NULL;
10666 json_stat = json_object_new_object();
10667 /* Packet counts. */
10668 json_object_int_add(json_stat, "depthInq", 0);
10669 json_object_int_add(json_stat, "depthOutq",
10670 (unsigned long)p->obuf->count);
10671 json_object_int_add(json_stat, "opensSent",
10672 atomic_load_explicit(&p->open_out,
10673 memory_order_relaxed));
10674 json_object_int_add(json_stat, "opensRecv",
10675 atomic_load_explicit(&p->open_in,
10676 memory_order_relaxed));
10677 json_object_int_add(json_stat, "notificationsSent",
10678 atomic_load_explicit(&p->notify_out,
10679 memory_order_relaxed));
10680 json_object_int_add(json_stat, "notificationsRecv",
10681 atomic_load_explicit(&p->notify_in,
10682 memory_order_relaxed));
10683 json_object_int_add(json_stat, "updatesSent",
10684 atomic_load_explicit(&p->update_out,
10685 memory_order_relaxed));
10686 json_object_int_add(json_stat, "updatesRecv",
10687 atomic_load_explicit(&p->update_in,
10688 memory_order_relaxed));
10689 json_object_int_add(json_stat, "keepalivesSent",
10690 atomic_load_explicit(&p->keepalive_out,
10691 memory_order_relaxed));
10692 json_object_int_add(json_stat, "keepalivesRecv",
10693 atomic_load_explicit(&p->keepalive_in,
10694 memory_order_relaxed));
10695 json_object_int_add(json_stat, "routeRefreshSent",
10696 atomic_load_explicit(&p->refresh_out,
10697 memory_order_relaxed));
10698 json_object_int_add(json_stat, "routeRefreshRecv",
10699 atomic_load_explicit(&p->refresh_in,
10700 memory_order_relaxed));
10701 json_object_int_add(json_stat, "capabilitySent",
10702 atomic_load_explicit(&p->dynamic_cap_out,
10703 memory_order_relaxed));
10704 json_object_int_add(json_stat, "capabilityRecv",
10705 atomic_load_explicit(&p->dynamic_cap_in,
10706 memory_order_relaxed));
10707 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
10708 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
10709 json_object_object_add(json_neigh, "messageStats", json_stat);
10710 } else {
10711 /* Packet counts. */
10712 vty_out(vty, " Message statistics:\n");
10713 vty_out(vty, " Inq depth is 0\n");
10714 vty_out(vty, " Outq depth is %lu\n",
10715 (unsigned long)p->obuf->count);
10716 vty_out(vty, " Sent Rcvd\n");
10717 vty_out(vty, " Opens: %10d %10d\n",
10718 atomic_load_explicit(&p->open_out,
10719 memory_order_relaxed),
10720 atomic_load_explicit(&p->open_in,
10721 memory_order_relaxed));
10722 vty_out(vty, " Notifications: %10d %10d\n",
10723 atomic_load_explicit(&p->notify_out,
10724 memory_order_relaxed),
10725 atomic_load_explicit(&p->notify_in,
10726 memory_order_relaxed));
10727 vty_out(vty, " Updates: %10d %10d\n",
10728 atomic_load_explicit(&p->update_out,
10729 memory_order_relaxed),
10730 atomic_load_explicit(&p->update_in,
10731 memory_order_relaxed));
10732 vty_out(vty, " Keepalives: %10d %10d\n",
10733 atomic_load_explicit(&p->keepalive_out,
10734 memory_order_relaxed),
10735 atomic_load_explicit(&p->keepalive_in,
10736 memory_order_relaxed));
10737 vty_out(vty, " Route Refresh: %10d %10d\n",
10738 atomic_load_explicit(&p->refresh_out,
10739 memory_order_relaxed),
10740 atomic_load_explicit(&p->refresh_in,
10741 memory_order_relaxed));
10742 vty_out(vty, " Capability: %10d %10d\n",
10743 atomic_load_explicit(&p->dynamic_cap_out,
10744 memory_order_relaxed),
10745 atomic_load_explicit(&p->dynamic_cap_in,
10746 memory_order_relaxed));
10747 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
10748 PEER_TOTAL_RX(p));
10749 }
10750
10751 if (use_json) {
10752 /* advertisement-interval */
10753 json_object_int_add(json_neigh,
10754 "minBtwnAdvertisementRunsTimerMsecs",
10755 p->v_routeadv * 1000);
10756
10757 /* Update-source. */
10758 if (p->update_if || p->update_source) {
10759 if (p->update_if)
10760 json_object_string_add(json_neigh,
10761 "updateSource",
10762 p->update_if);
10763 else if (p->update_source)
10764 json_object_string_add(
10765 json_neigh, "updateSource",
10766 sockunion2str(p->update_source, buf1,
10767 SU_ADDRSTRLEN));
10768 }
10769 } else {
10770 /* advertisement-interval */
10771 vty_out(vty,
10772 " Minimum time between advertisement runs is %d seconds\n",
10773 p->v_routeadv);
10774
10775 /* Update-source. */
10776 if (p->update_if || p->update_source) {
10777 vty_out(vty, " Update source is ");
10778 if (p->update_if)
10779 vty_out(vty, "%s", p->update_if);
10780 else if (p->update_source)
10781 vty_out(vty, "%s",
10782 sockunion2str(p->update_source, buf1,
10783 SU_ADDRSTRLEN));
10784 vty_out(vty, "\n");
10785 }
10786
10787 vty_out(vty, "\n");
10788 }
10789
10790 /* Address Family Information */
10791 json_object *json_hold = NULL;
10792
10793 if (use_json)
10794 json_hold = json_object_new_object();
10795
10796 FOREACH_AFI_SAFI (afi, safi)
10797 if (p->afc[afi][safi])
10798 bgp_show_peer_afi(vty, p, afi, safi, use_json,
10799 json_hold);
10800
10801 if (use_json) {
10802 json_object_object_add(json_neigh, "addressFamilyInfo",
10803 json_hold);
10804 json_object_int_add(json_neigh, "connectionsEstablished",
10805 p->established);
10806 json_object_int_add(json_neigh, "connectionsDropped",
10807 p->dropped);
10808 } else
10809 vty_out(vty, " Connections established %d; dropped %d\n",
10810 p->established, p->dropped);
10811
10812 if (!p->last_reset) {
10813 if (use_json)
10814 json_object_string_add(json_neigh, "lastReset",
10815 "never");
10816 else
10817 vty_out(vty, " Last reset never\n");
10818 } else {
10819 if (use_json) {
10820 time_t uptime;
10821 struct tm *tm;
10822
10823 uptime = bgp_clock();
10824 uptime -= p->resettime;
10825 tm = gmtime(&uptime);
10826 json_object_int_add(json_neigh, "lastResetTimerMsecs",
10827 (tm->tm_sec * 1000)
10828 + (tm->tm_min * 60000)
10829 + (tm->tm_hour * 3600000));
10830 bgp_show_peer_reset(NULL, p, json_neigh, true);
10831 } else {
10832 vty_out(vty, " Last reset %s, ",
10833 peer_uptime(p->resettime, timebuf,
10834 BGP_UPTIME_LEN, 0, NULL));
10835
10836 bgp_show_peer_reset(vty, p, NULL, false);
10837 if (p->last_reset_cause_size) {
10838 msg = p->last_reset_cause;
10839 vty_out(vty,
10840 " Message received that caused BGP to send a NOTIFICATION:\n ");
10841 for (i = 1; i <= p->last_reset_cause_size;
10842 i++) {
10843 vty_out(vty, "%02X", *msg++);
10844
10845 if (i != p->last_reset_cause_size) {
10846 if (i % 16 == 0) {
10847 vty_out(vty, "\n ");
10848 } else if (i % 4 == 0) {
10849 vty_out(vty, " ");
10850 }
10851 }
10852 }
10853 vty_out(vty, "\n");
10854 }
10855 }
10856 }
10857
10858 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
10859 if (use_json)
10860 json_object_boolean_true_add(json_neigh,
10861 "prefixesConfigExceedMax");
10862 else
10863 vty_out(vty,
10864 " Peer had exceeded the max. no. of prefixes configured.\n");
10865
10866 if (p->t_pmax_restart) {
10867 if (use_json) {
10868 json_object_boolean_true_add(
10869 json_neigh, "reducePrefixNumFrom");
10870 json_object_int_add(json_neigh,
10871 "restartInTimerMsec",
10872 thread_timer_remain_second(
10873 p->t_pmax_restart)
10874 * 1000);
10875 } else
10876 vty_out(vty,
10877 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
10878 p->host, thread_timer_remain_second(
10879 p->t_pmax_restart));
10880 } else {
10881 if (use_json)
10882 json_object_boolean_true_add(
10883 json_neigh,
10884 "reducePrefixNumAndClearIpBgp");
10885 else
10886 vty_out(vty,
10887 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
10888 p->host);
10889 }
10890 }
10891
10892 /* EBGP Multihop and GTSM */
10893 if (p->sort != BGP_PEER_IBGP) {
10894 if (use_json) {
10895 if (p->gtsm_hops > 0)
10896 json_object_int_add(json_neigh,
10897 "externalBgpNbrMaxHopsAway",
10898 p->gtsm_hops);
10899 else if (p->ttl > BGP_DEFAULT_TTL)
10900 json_object_int_add(json_neigh,
10901 "externalBgpNbrMaxHopsAway",
10902 p->ttl);
10903 } else {
10904 if (p->gtsm_hops > 0)
10905 vty_out(vty,
10906 " External BGP neighbor may be up to %d hops away.\n",
10907 p->gtsm_hops);
10908 else if (p->ttl > BGP_DEFAULT_TTL)
10909 vty_out(vty,
10910 " External BGP neighbor may be up to %d hops away.\n",
10911 p->ttl);
10912 }
10913 } else {
10914 if (p->gtsm_hops > 0) {
10915 if (use_json)
10916 json_object_int_add(json_neigh,
10917 "internalBgpNbrMaxHopsAway",
10918 p->gtsm_hops);
10919 else
10920 vty_out(vty,
10921 " Internal BGP neighbor may be up to %d hops away.\n",
10922 p->gtsm_hops);
10923 }
10924 }
10925
10926 /* Local address. */
10927 if (p->su_local) {
10928 if (use_json) {
10929 json_object_string_add(json_neigh, "hostLocal",
10930 sockunion2str(p->su_local, buf1,
10931 SU_ADDRSTRLEN));
10932 json_object_int_add(json_neigh, "portLocal",
10933 ntohs(p->su_local->sin.sin_port));
10934 } else
10935 vty_out(vty, "Local host: %s, Local port: %d\n",
10936 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
10937 ntohs(p->su_local->sin.sin_port));
10938 }
10939
10940 /* Remote address. */
10941 if (p->su_remote) {
10942 if (use_json) {
10943 json_object_string_add(json_neigh, "hostForeign",
10944 sockunion2str(p->su_remote, buf1,
10945 SU_ADDRSTRLEN));
10946 json_object_int_add(json_neigh, "portForeign",
10947 ntohs(p->su_remote->sin.sin_port));
10948 } else
10949 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
10950 sockunion2str(p->su_remote, buf1,
10951 SU_ADDRSTRLEN),
10952 ntohs(p->su_remote->sin.sin_port));
10953 }
10954
10955 /* Nexthop display. */
10956 if (p->su_local) {
10957 if (use_json) {
10958 json_object_string_add(json_neigh, "nexthop",
10959 inet_ntop(AF_INET,
10960 &p->nexthop.v4, buf1,
10961 sizeof(buf1)));
10962 json_object_string_add(json_neigh, "nexthopGlobal",
10963 inet_ntop(AF_INET6,
10964 &p->nexthop.v6_global,
10965 buf1, sizeof(buf1)));
10966 json_object_string_add(json_neigh, "nexthopLocal",
10967 inet_ntop(AF_INET6,
10968 &p->nexthop.v6_local,
10969 buf1, sizeof(buf1)));
10970 if (p->shared_network)
10971 json_object_string_add(json_neigh,
10972 "bgpConnection",
10973 "sharedNetwork");
10974 else
10975 json_object_string_add(json_neigh,
10976 "bgpConnection",
10977 "nonSharedNetwork");
10978 } else {
10979 vty_out(vty, "Nexthop: %s\n",
10980 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
10981 sizeof(buf1)));
10982 vty_out(vty, "Nexthop global: %s\n",
10983 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
10984 sizeof(buf1)));
10985 vty_out(vty, "Nexthop local: %s\n",
10986 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
10987 sizeof(buf1)));
10988 vty_out(vty, "BGP connection: %s\n",
10989 p->shared_network ? "shared network"
10990 : "non shared network");
10991 }
10992 }
10993
10994 /* Timer information. */
10995 if (use_json) {
10996 json_object_int_add(json_neigh, "connectRetryTimer",
10997 p->v_connect);
10998 if (p->status == Established && p->rtt)
10999 json_object_int_add(json_neigh, "estimatedRttInMsecs",
11000 p->rtt);
11001 if (p->t_start)
11002 json_object_int_add(
11003 json_neigh, "nextStartTimerDueInMsecs",
11004 thread_timer_remain_second(p->t_start) * 1000);
11005 if (p->t_connect)
11006 json_object_int_add(
11007 json_neigh, "nextConnectTimerDueInMsecs",
11008 thread_timer_remain_second(p->t_connect)
11009 * 1000);
11010 if (p->t_routeadv) {
11011 json_object_int_add(json_neigh, "mraiInterval",
11012 p->v_routeadv);
11013 json_object_int_add(
11014 json_neigh, "mraiTimerExpireInMsecs",
11015 thread_timer_remain_second(p->t_routeadv)
11016 * 1000);
11017 }
11018 if (p->password)
11019 json_object_int_add(json_neigh, "authenticationEnabled",
11020 1);
11021
11022 if (p->t_read)
11023 json_object_string_add(json_neigh, "readThread", "on");
11024 else
11025 json_object_string_add(json_neigh, "readThread", "off");
11026
11027 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
11028 json_object_string_add(json_neigh, "writeThread", "on");
11029 else
11030 json_object_string_add(json_neigh, "writeThread",
11031 "off");
11032 } else {
11033 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
11034 p->v_connect);
11035 if (p->status == Established && p->rtt)
11036 vty_out(vty, "Estimated round trip time: %d ms\n",
11037 p->rtt);
11038 if (p->t_start)
11039 vty_out(vty, "Next start timer due in %ld seconds\n",
11040 thread_timer_remain_second(p->t_start));
11041 if (p->t_connect)
11042 vty_out(vty, "Next connect timer due in %ld seconds\n",
11043 thread_timer_remain_second(p->t_connect));
11044 if (p->t_routeadv)
11045 vty_out(vty,
11046 "MRAI (interval %u) timer expires in %ld seconds\n",
11047 p->v_routeadv,
11048 thread_timer_remain_second(p->t_routeadv));
11049 if (p->password)
11050 vty_out(vty, "Peer Authentication Enabled\n");
11051
11052 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
11053 p->t_read ? "on" : "off",
11054 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
11055 ? "on"
11056 : "off", p->fd);
11057 }
11058
11059 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
11060 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
11061 bgp_capability_vty_out(vty, p, use_json, json_neigh);
11062
11063 if (!use_json)
11064 vty_out(vty, "\n");
11065
11066 /* BFD information. */
11067 bgp_bfd_show_info(vty, p, use_json, json_neigh);
11068
11069 if (use_json) {
11070 if (p->conf_if) /* Configured interface name. */
11071 json_object_object_add(json, p->conf_if, json_neigh);
11072 else /* Configured IP address. */
11073 json_object_object_add(json, p->host, json_neigh);
11074 }
11075 }
11076
11077 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
11078 enum show_type type, union sockunion *su,
11079 const char *conf_if, bool use_json,
11080 json_object *json)
11081 {
11082 struct listnode *node, *nnode;
11083 struct peer *peer;
11084 int find = 0;
11085 bool nbr_output = false;
11086 afi_t afi = AFI_MAX;
11087 safi_t safi = SAFI_MAX;
11088
11089 if (type == show_ipv4_peer || type == show_ipv4_all) {
11090 afi = AFI_IP;
11091 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
11092 afi = AFI_IP6;
11093 }
11094
11095 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
11096 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
11097 continue;
11098
11099 switch (type) {
11100 case show_all:
11101 bgp_show_peer(vty, peer, use_json, json);
11102 nbr_output = true;
11103 break;
11104 case show_peer:
11105 if (conf_if) {
11106 if ((peer->conf_if
11107 && !strcmp(peer->conf_if, conf_if))
11108 || (peer->hostname
11109 && !strcmp(peer->hostname, conf_if))) {
11110 find = 1;
11111 bgp_show_peer(vty, peer, use_json,
11112 json);
11113 }
11114 } else {
11115 if (sockunion_same(&peer->su, su)) {
11116 find = 1;
11117 bgp_show_peer(vty, peer, use_json,
11118 json);
11119 }
11120 }
11121 break;
11122 case show_ipv4_peer:
11123 case show_ipv6_peer:
11124 FOREACH_SAFI (safi) {
11125 if (peer->afc[afi][safi]) {
11126 if (conf_if) {
11127 if ((peer->conf_if
11128 && !strcmp(peer->conf_if, conf_if))
11129 || (peer->hostname
11130 && !strcmp(peer->hostname, conf_if))) {
11131 find = 1;
11132 bgp_show_peer(vty, peer, use_json,
11133 json);
11134 break;
11135 }
11136 } else {
11137 if (sockunion_same(&peer->su, su)) {
11138 find = 1;
11139 bgp_show_peer(vty, peer, use_json,
11140 json);
11141 break;
11142 }
11143 }
11144 }
11145 }
11146 break;
11147 case show_ipv4_all:
11148 case show_ipv6_all:
11149 FOREACH_SAFI (safi) {
11150 if (peer->afc[afi][safi]) {
11151 bgp_show_peer(vty, peer, use_json, json);
11152 nbr_output = true;
11153 break;
11154 }
11155 }
11156 break;
11157 }
11158 }
11159
11160 if ((type == show_peer || type == show_ipv4_peer ||
11161 type == show_ipv6_peer) && !find) {
11162 if (use_json)
11163 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
11164 else
11165 vty_out(vty, "%% No such neighbor in this view/vrf\n");
11166 }
11167
11168 if (type != show_peer && type != show_ipv4_peer &&
11169 type != show_ipv6_peer && !nbr_output && !use_json)
11170 vty_out(vty, "%% No BGP neighbors found\n");
11171
11172 if (use_json) {
11173 vty_out(vty, "%s\n", json_object_to_json_string_ext(
11174 json, JSON_C_TO_STRING_PRETTY));
11175 } else {
11176 vty_out(vty, "\n");
11177 }
11178
11179 return CMD_SUCCESS;
11180 }
11181
11182 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
11183 enum show_type type,
11184 const char *ip_str,
11185 bool use_json)
11186 {
11187 struct listnode *node, *nnode;
11188 struct bgp *bgp;
11189 union sockunion su;
11190 json_object *json = NULL;
11191 int ret, is_first = 1;
11192 bool nbr_output = false;
11193
11194 if (use_json)
11195 vty_out(vty, "{\n");
11196
11197 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11198 nbr_output = true;
11199 if (use_json) {
11200 if (!(json = json_object_new_object())) {
11201 flog_err(
11202 EC_BGP_JSON_MEM_ERROR,
11203 "Unable to allocate memory for JSON object");
11204 vty_out(vty,
11205 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
11206 return;
11207 }
11208
11209 json_object_int_add(json, "vrfId",
11210 (bgp->vrf_id == VRF_UNKNOWN)
11211 ? -1
11212 : (int64_t)bgp->vrf_id);
11213 json_object_string_add(
11214 json, "vrfName",
11215 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11216 ? VRF_DEFAULT_NAME
11217 : bgp->name);
11218
11219 if (!is_first)
11220 vty_out(vty, ",\n");
11221 else
11222 is_first = 0;
11223
11224 vty_out(vty, "\"%s\":",
11225 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11226 ? VRF_DEFAULT_NAME
11227 : bgp->name);
11228 } else {
11229 vty_out(vty, "\nInstance %s:\n",
11230 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11231 ? VRF_DEFAULT_NAME
11232 : bgp->name);
11233 }
11234
11235 if (type == show_peer || type == show_ipv4_peer ||
11236 type == show_ipv6_peer) {
11237 ret = str2sockunion(ip_str, &su);
11238 if (ret < 0)
11239 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
11240 use_json, json);
11241 else
11242 bgp_show_neighbor(vty, bgp, type, &su, NULL,
11243 use_json, json);
11244 } else {
11245 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
11246 use_json, json);
11247 }
11248 json_object_free(json);
11249 }
11250
11251 if (use_json) {
11252 vty_out(vty, "}\n");
11253 json_object_free(json);
11254 }
11255 else if (!nbr_output)
11256 vty_out(vty, "%% BGP instance not found\n");
11257 }
11258
11259 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
11260 enum show_type type, const char *ip_str,
11261 bool use_json)
11262 {
11263 int ret;
11264 struct bgp *bgp;
11265 union sockunion su;
11266 json_object *json = NULL;
11267
11268 if (name) {
11269 if (strmatch(name, "all")) {
11270 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
11271 use_json);
11272 return CMD_SUCCESS;
11273 } else {
11274 bgp = bgp_lookup_by_name(name);
11275 if (!bgp) {
11276 if (use_json) {
11277 json = json_object_new_object();
11278 vty_out(vty, "%s\n",
11279 json_object_to_json_string_ext(
11280 json,
11281 JSON_C_TO_STRING_PRETTY));
11282 json_object_free(json);
11283 } else
11284 vty_out(vty,
11285 "%% BGP instance not found\n");
11286
11287 return CMD_WARNING;
11288 }
11289 }
11290 } else {
11291 bgp = bgp_get_default();
11292 }
11293
11294 if (bgp) {
11295 json = json_object_new_object();
11296 if (ip_str) {
11297 ret = str2sockunion(ip_str, &su);
11298 if (ret < 0)
11299 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
11300 use_json, json);
11301 else
11302 bgp_show_neighbor(vty, bgp, type, &su, NULL,
11303 use_json, json);
11304 } else {
11305 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
11306 json);
11307 }
11308 json_object_free(json);
11309 } else {
11310 if (use_json)
11311 vty_out(vty, "{}\n");
11312 else
11313 vty_out(vty, "%% BGP instance not found\n");
11314 }
11315
11316 return CMD_SUCCESS;
11317 }
11318
11319 /* "show [ip] bgp neighbors" commands. */
11320 DEFUN (show_ip_bgp_neighbors,
11321 show_ip_bgp_neighbors_cmd,
11322 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
11323 SHOW_STR
11324 IP_STR
11325 BGP_STR
11326 BGP_INSTANCE_HELP_STR
11327 "Address Family\n"
11328 "Address Family\n"
11329 "Detailed information on TCP and BGP neighbor connections\n"
11330 "Neighbor to display information about\n"
11331 "Neighbor to display information about\n"
11332 "Neighbor on BGP configured interface\n"
11333 JSON_STR)
11334 {
11335 char *vrf = NULL;
11336 char *sh_arg = NULL;
11337 enum show_type sh_type;
11338 afi_t afi = AFI_MAX;
11339
11340 bool uj = use_json(argc, argv);
11341
11342 int idx = 0;
11343
11344 /* [<vrf> VIEWVRFNAME] */
11345 if (argv_find(argv, argc, "vrf", &idx)) {
11346 vrf = argv[idx + 1]->arg;
11347 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11348 vrf = NULL;
11349 } else if (argv_find(argv, argc, "view", &idx))
11350 /* [<view> VIEWVRFNAME] */
11351 vrf = argv[idx + 1]->arg;
11352
11353 idx++;
11354
11355 if (argv_find(argv, argc, "ipv4", &idx)) {
11356 sh_type = show_ipv4_all;
11357 afi = AFI_IP;
11358 } else if (argv_find(argv, argc, "ipv6", &idx)) {
11359 sh_type = show_ipv6_all;
11360 afi = AFI_IP6;
11361 } else {
11362 sh_type = show_all;
11363 }
11364
11365 if (argv_find(argv, argc, "A.B.C.D", &idx)
11366 || argv_find(argv, argc, "X:X::X:X", &idx)
11367 || argv_find(argv, argc, "WORD", &idx)) {
11368 sh_type = show_peer;
11369 sh_arg = argv[idx]->arg;
11370 }
11371
11372 if (sh_type == show_peer && afi == AFI_IP) {
11373 sh_type = show_ipv4_peer;
11374 } else if (sh_type == show_peer && afi == AFI_IP6) {
11375 sh_type = show_ipv6_peer;
11376 }
11377
11378 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
11379 }
11380
11381 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
11382 paths' and `show ip mbgp paths'. Those functions results are the
11383 same.*/
11384 DEFUN (show_ip_bgp_paths,
11385 show_ip_bgp_paths_cmd,
11386 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
11387 SHOW_STR
11388 IP_STR
11389 BGP_STR
11390 BGP_SAFI_HELP_STR
11391 "Path information\n")
11392 {
11393 vty_out(vty, "Address Refcnt Path\n");
11394 aspath_print_all_vty(vty);
11395 return CMD_SUCCESS;
11396 }
11397
11398 #include "hash.h"
11399
11400 static void community_show_all_iterator(struct hash_bucket *bucket,
11401 struct vty *vty)
11402 {
11403 struct community *com;
11404
11405 com = (struct community *)bucket->data;
11406 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
11407 community_str(com, false));
11408 }
11409
11410 /* Show BGP's community internal data. */
11411 DEFUN (show_ip_bgp_community_info,
11412 show_ip_bgp_community_info_cmd,
11413 "show [ip] bgp community-info",
11414 SHOW_STR
11415 IP_STR
11416 BGP_STR
11417 "List all bgp community information\n")
11418 {
11419 vty_out(vty, "Address Refcnt Community\n");
11420
11421 hash_iterate(community_hash(),
11422 (void (*)(struct hash_bucket *,
11423 void *))community_show_all_iterator,
11424 vty);
11425
11426 return CMD_SUCCESS;
11427 }
11428
11429 static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
11430 struct vty *vty)
11431 {
11432 struct lcommunity *lcom;
11433
11434 lcom = (struct lcommunity *)bucket->data;
11435 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
11436 lcommunity_str(lcom, false));
11437 }
11438
11439 /* Show BGP's community internal data. */
11440 DEFUN (show_ip_bgp_lcommunity_info,
11441 show_ip_bgp_lcommunity_info_cmd,
11442 "show ip bgp large-community-info",
11443 SHOW_STR
11444 IP_STR
11445 BGP_STR
11446 "List all bgp large-community information\n")
11447 {
11448 vty_out(vty, "Address Refcnt Large-community\n");
11449
11450 hash_iterate(lcommunity_hash(),
11451 (void (*)(struct hash_bucket *,
11452 void *))lcommunity_show_all_iterator,
11453 vty);
11454
11455 return CMD_SUCCESS;
11456 }
11457
11458
11459 DEFUN (show_ip_bgp_attr_info,
11460 show_ip_bgp_attr_info_cmd,
11461 "show [ip] bgp attribute-info",
11462 SHOW_STR
11463 IP_STR
11464 BGP_STR
11465 "List all bgp attribute information\n")
11466 {
11467 attr_show_all(vty);
11468 return CMD_SUCCESS;
11469 }
11470
11471 static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
11472 afi_t afi, safi_t safi,
11473 bool use_json, json_object *json)
11474 {
11475 struct bgp *bgp;
11476 struct listnode *node;
11477 char *vname;
11478 char buf1[INET6_ADDRSTRLEN];
11479 char *ecom_str;
11480 vpn_policy_direction_t dir;
11481
11482 if (json) {
11483 json_object *json_import_vrfs = NULL;
11484 json_object *json_export_vrfs = NULL;
11485
11486 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11487
11488 if (!bgp) {
11489 vty_out(vty, "%s\n",
11490 json_object_to_json_string_ext(
11491 json,
11492 JSON_C_TO_STRING_PRETTY));
11493 json_object_free(json);
11494
11495 return CMD_WARNING;
11496 }
11497
11498 /* Provide context for the block */
11499 json_object_string_add(json, "vrf", name ? name : "default");
11500 json_object_string_add(json, "afiSafi",
11501 get_afi_safi_str(afi, safi, true));
11502
11503 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11504 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
11505 json_object_string_add(json, "importFromVrfs", "none");
11506 json_object_string_add(json, "importRts", "none");
11507 } else {
11508 json_import_vrfs = json_object_new_array();
11509
11510 for (ALL_LIST_ELEMENTS_RO(
11511 bgp->vpn_policy[afi].import_vrf,
11512 node, vname))
11513 json_object_array_add(json_import_vrfs,
11514 json_object_new_string(vname));
11515
11516 json_object_object_add(json, "importFromVrfs",
11517 json_import_vrfs);
11518 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11519 if (bgp->vpn_policy[afi].rtlist[dir]) {
11520 ecom_str = ecommunity_ecom2str(
11521 bgp->vpn_policy[afi].rtlist[dir],
11522 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11523 json_object_string_add(json, "importRts",
11524 ecom_str);
11525 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11526 } else
11527 json_object_string_add(json, "importRts",
11528 "none");
11529 }
11530
11531 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11532 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
11533 json_object_string_add(json, "exportToVrfs", "none");
11534 json_object_string_add(json, "routeDistinguisher",
11535 "none");
11536 json_object_string_add(json, "exportRts", "none");
11537 } else {
11538 json_export_vrfs = json_object_new_array();
11539
11540 for (ALL_LIST_ELEMENTS_RO(
11541 bgp->vpn_policy[afi].export_vrf,
11542 node, vname))
11543 json_object_array_add(json_export_vrfs,
11544 json_object_new_string(vname));
11545 json_object_object_add(json, "exportToVrfs",
11546 json_export_vrfs);
11547 json_object_string_add(json, "routeDistinguisher",
11548 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11549 buf1, RD_ADDRSTRLEN));
11550
11551 dir = BGP_VPN_POLICY_DIR_TOVPN;
11552 if (bgp->vpn_policy[afi].rtlist[dir]) {
11553 ecom_str = ecommunity_ecom2str(
11554 bgp->vpn_policy[afi].rtlist[dir],
11555 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11556 json_object_string_add(json, "exportRts",
11557 ecom_str);
11558 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11559 } else
11560 json_object_string_add(json, "exportRts",
11561 "none");
11562 }
11563
11564 if (use_json) {
11565 vty_out(vty, "%s\n",
11566 json_object_to_json_string_ext(json,
11567 JSON_C_TO_STRING_PRETTY));
11568 json_object_free(json);
11569 }
11570 } else {
11571 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11572
11573 if (!bgp) {
11574 vty_out(vty, "%% No such BGP instance exist\n");
11575 return CMD_WARNING;
11576 }
11577
11578 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11579 BGP_CONFIG_VRF_TO_VRF_IMPORT))
11580 vty_out(vty,
11581 "This VRF is not importing %s routes from any other VRF\n",
11582 get_afi_safi_str(afi, safi, false));
11583 else {
11584 vty_out(vty,
11585 "This VRF is importing %s routes from the following VRFs:\n",
11586 get_afi_safi_str(afi, safi, false));
11587
11588 for (ALL_LIST_ELEMENTS_RO(
11589 bgp->vpn_policy[afi].import_vrf,
11590 node, vname))
11591 vty_out(vty, " %s\n", vname);
11592
11593 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11594 ecom_str = NULL;
11595 if (bgp->vpn_policy[afi].rtlist[dir]) {
11596 ecom_str = ecommunity_ecom2str(
11597 bgp->vpn_policy[afi].rtlist[dir],
11598 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11599 vty_out(vty, "Import RT(s): %s\n", ecom_str);
11600
11601 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11602 } else
11603 vty_out(vty, "Import RT(s):\n");
11604 }
11605
11606 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11607 BGP_CONFIG_VRF_TO_VRF_EXPORT))
11608 vty_out(vty,
11609 "This VRF is not exporting %s routes to any other VRF\n",
11610 get_afi_safi_str(afi, safi, false));
11611 else {
11612 vty_out(vty,
11613 "This VRF is exporting %s routes to the following VRFs:\n",
11614 get_afi_safi_str(afi, safi, false));
11615
11616 for (ALL_LIST_ELEMENTS_RO(
11617 bgp->vpn_policy[afi].export_vrf,
11618 node, vname))
11619 vty_out(vty, " %s\n", vname);
11620
11621 vty_out(vty, "RD: %s\n",
11622 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11623 buf1, RD_ADDRSTRLEN));
11624
11625 dir = BGP_VPN_POLICY_DIR_TOVPN;
11626 if (bgp->vpn_policy[afi].rtlist[dir]) {
11627 ecom_str = ecommunity_ecom2str(
11628 bgp->vpn_policy[afi].rtlist[dir],
11629 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11630 vty_out(vty, "Export RT: %s\n", ecom_str);
11631 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11632 } else
11633 vty_out(vty, "Import RT(s):\n");
11634 }
11635 }
11636
11637 return CMD_SUCCESS;
11638 }
11639
11640 static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
11641 safi_t safi, bool use_json)
11642 {
11643 struct listnode *node, *nnode;
11644 struct bgp *bgp;
11645 char *vrf_name = NULL;
11646 json_object *json = NULL;
11647 json_object *json_vrf = NULL;
11648 json_object *json_vrfs = NULL;
11649
11650 if (use_json) {
11651 json = json_object_new_object();
11652 json_vrfs = json_object_new_object();
11653 }
11654
11655 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11656
11657 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
11658 vrf_name = bgp->name;
11659
11660 if (use_json) {
11661 json_vrf = json_object_new_object();
11662 } else {
11663 vty_out(vty, "\nInstance %s:\n",
11664 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11665 ? VRF_DEFAULT_NAME : bgp->name);
11666 }
11667 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
11668 if (use_json) {
11669 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11670 json_object_object_add(json_vrfs,
11671 VRF_DEFAULT_NAME, json_vrf);
11672 else
11673 json_object_object_add(json_vrfs, vrf_name,
11674 json_vrf);
11675 }
11676 }
11677
11678 if (use_json) {
11679 json_object_object_add(json, "vrfs", json_vrfs);
11680 vty_out(vty, "%s\n", json_object_to_json_string_ext(json,
11681 JSON_C_TO_STRING_PRETTY));
11682 json_object_free(json);
11683 }
11684
11685 return CMD_SUCCESS;
11686 }
11687
11688 /* "show [ip] bgp route-leak" command. */
11689 DEFUN (show_ip_bgp_route_leak,
11690 show_ip_bgp_route_leak_cmd,
11691 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
11692 SHOW_STR
11693 IP_STR
11694 BGP_STR
11695 BGP_INSTANCE_HELP_STR
11696 BGP_AFI_HELP_STR
11697 BGP_SAFI_HELP_STR
11698 "Route leaking information\n"
11699 JSON_STR)
11700 {
11701 char *vrf = NULL;
11702 afi_t afi = AFI_MAX;
11703 safi_t safi = SAFI_MAX;
11704
11705 bool uj = use_json(argc, argv);
11706 int idx = 0;
11707 json_object *json = NULL;
11708
11709 /* show [ip] bgp */
11710 if (argv_find(argv, argc, "ip", &idx)) {
11711 afi = AFI_IP;
11712 safi = SAFI_UNICAST;
11713 }
11714 /* [vrf VIEWVRFNAME] */
11715 if (argv_find(argv, argc, "view", &idx)) {
11716 vty_out(vty,
11717 "%% This command is not applicable to BGP views\n");
11718 return CMD_WARNING;
11719 }
11720
11721 if (argv_find(argv, argc, "vrf", &idx)) {
11722 vrf = argv[idx + 1]->arg;
11723 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11724 vrf = NULL;
11725 }
11726 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11727 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11728 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11729 }
11730
11731 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
11732 vty_out(vty,
11733 "%% This command is applicable only for unicast ipv4|ipv6\n");
11734 return CMD_WARNING;
11735 }
11736
11737 if (vrf && strmatch(vrf, "all"))
11738 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
11739
11740 if (uj)
11741 json = json_object_new_object();
11742
11743 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
11744 }
11745
11746 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
11747 safi_t safi)
11748 {
11749 struct listnode *node, *nnode;
11750 struct bgp *bgp;
11751
11752 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11753 vty_out(vty, "\nInstance %s:\n",
11754 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11755 ? VRF_DEFAULT_NAME
11756 : bgp->name);
11757 update_group_show(bgp, afi, safi, vty, 0);
11758 }
11759 }
11760
11761 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
11762 int safi, uint64_t subgrp_id)
11763 {
11764 struct bgp *bgp;
11765
11766 if (name) {
11767 if (strmatch(name, "all")) {
11768 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
11769 return CMD_SUCCESS;
11770 } else {
11771 bgp = bgp_lookup_by_name(name);
11772 }
11773 } else {
11774 bgp = bgp_get_default();
11775 }
11776
11777 if (bgp)
11778 update_group_show(bgp, afi, safi, vty, subgrp_id);
11779 return CMD_SUCCESS;
11780 }
11781
11782 DEFUN (show_ip_bgp_updgrps,
11783 show_ip_bgp_updgrps_cmd,
11784 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
11785 SHOW_STR
11786 IP_STR
11787 BGP_STR
11788 BGP_INSTANCE_HELP_STR
11789 BGP_AFI_HELP_STR
11790 BGP_SAFI_WITH_LABEL_HELP_STR
11791 "Detailed info about dynamic update groups\n"
11792 "Specific subgroup to display detailed info for\n")
11793 {
11794 char *vrf = NULL;
11795 afi_t afi = AFI_IP6;
11796 safi_t safi = SAFI_UNICAST;
11797 uint64_t subgrp_id = 0;
11798
11799 int idx = 0;
11800
11801 /* show [ip] bgp */
11802 if (argv_find(argv, argc, "ip", &idx))
11803 afi = AFI_IP;
11804 /* [<vrf> VIEWVRFNAME] */
11805 if (argv_find(argv, argc, "vrf", &idx)) {
11806 vrf = argv[idx + 1]->arg;
11807 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11808 vrf = NULL;
11809 } else if (argv_find(argv, argc, "view", &idx))
11810 /* [<view> VIEWVRFNAME] */
11811 vrf = argv[idx + 1]->arg;
11812 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11813 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11814 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11815 }
11816
11817 /* get subgroup id, if provided */
11818 idx = argc - 1;
11819 if (argv[idx]->type == VARIABLE_TKN)
11820 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
11821
11822 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
11823 }
11824
11825 DEFUN (show_bgp_instance_all_ipv6_updgrps,
11826 show_bgp_instance_all_ipv6_updgrps_cmd,
11827 "show [ip] bgp <view|vrf> all update-groups",
11828 SHOW_STR
11829 IP_STR
11830 BGP_STR
11831 BGP_INSTANCE_ALL_HELP_STR
11832 "Detailed info about dynamic update groups\n")
11833 {
11834 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
11835 return CMD_SUCCESS;
11836 }
11837
11838 DEFUN (show_bgp_l2vpn_evpn_updgrps,
11839 show_bgp_l2vpn_evpn_updgrps_cmd,
11840 "show [ip] bgp l2vpn evpn update-groups",
11841 SHOW_STR
11842 IP_STR
11843 BGP_STR
11844 "l2vpn address family\n"
11845 "evpn sub-address family\n"
11846 "Detailed info about dynamic update groups\n")
11847 {
11848 char *vrf = NULL;
11849 uint64_t subgrp_id = 0;
11850
11851 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
11852 return CMD_SUCCESS;
11853 }
11854
11855 DEFUN (show_bgp_updgrps_stats,
11856 show_bgp_updgrps_stats_cmd,
11857 "show [ip] bgp update-groups statistics",
11858 SHOW_STR
11859 IP_STR
11860 BGP_STR
11861 "Detailed info about dynamic update groups\n"
11862 "Statistics\n")
11863 {
11864 struct bgp *bgp;
11865
11866 bgp = bgp_get_default();
11867 if (bgp)
11868 update_group_show_stats(bgp, vty);
11869
11870 return CMD_SUCCESS;
11871 }
11872
11873 DEFUN (show_bgp_instance_updgrps_stats,
11874 show_bgp_instance_updgrps_stats_cmd,
11875 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
11876 SHOW_STR
11877 IP_STR
11878 BGP_STR
11879 BGP_INSTANCE_HELP_STR
11880 "Detailed info about dynamic update groups\n"
11881 "Statistics\n")
11882 {
11883 int idx_word = 3;
11884 struct bgp *bgp;
11885
11886 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
11887 if (bgp)
11888 update_group_show_stats(bgp, vty);
11889
11890 return CMD_SUCCESS;
11891 }
11892
11893 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
11894 afi_t afi, safi_t safi,
11895 const char *what, uint64_t subgrp_id)
11896 {
11897 struct bgp *bgp;
11898
11899 if (name)
11900 bgp = bgp_lookup_by_name(name);
11901 else
11902 bgp = bgp_get_default();
11903
11904 if (bgp) {
11905 if (!strcmp(what, "advertise-queue"))
11906 update_group_show_adj_queue(bgp, afi, safi, vty,
11907 subgrp_id);
11908 else if (!strcmp(what, "advertised-routes"))
11909 update_group_show_advertised(bgp, afi, safi, vty,
11910 subgrp_id);
11911 else if (!strcmp(what, "packet-queue"))
11912 update_group_show_packet_queue(bgp, afi, safi, vty,
11913 subgrp_id);
11914 }
11915 }
11916
11917 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
11918 show_ip_bgp_instance_updgrps_adj_s_cmd,
11919 "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",
11920 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11921 BGP_SAFI_HELP_STR
11922 "Detailed info about dynamic update groups\n"
11923 "Specific subgroup to display info for\n"
11924 "Advertisement queue\n"
11925 "Announced routes\n"
11926 "Packet queue\n")
11927 {
11928 uint64_t subgrp_id = 0;
11929 afi_t afiz;
11930 safi_t safiz;
11931 if (sgid)
11932 subgrp_id = strtoull(sgid, NULL, 10);
11933
11934 if (!ip && !afi)
11935 afiz = AFI_IP6;
11936 if (!ip && afi)
11937 afiz = bgp_vty_afi_from_str(afi);
11938 if (ip && !afi)
11939 afiz = AFI_IP;
11940 if (ip && afi) {
11941 afiz = bgp_vty_afi_from_str(afi);
11942 if (afiz != AFI_IP)
11943 vty_out(vty,
11944 "%% Cannot specify both 'ip' and 'ipv6'\n");
11945 return CMD_WARNING;
11946 }
11947
11948 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
11949
11950 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
11951 return CMD_SUCCESS;
11952 }
11953
11954 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
11955 {
11956 struct listnode *node, *nnode;
11957 struct prefix *range;
11958 struct peer *conf;
11959 struct peer *peer;
11960 char buf[PREFIX2STR_BUFFER];
11961 afi_t afi;
11962 safi_t safi;
11963 const char *peer_status;
11964 const char *af_str;
11965 int lr_count;
11966 int dynamic;
11967 int af_cfgd;
11968
11969 conf = group->conf;
11970
11971 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
11972 vty_out(vty, "\nBGP peer-group %s, remote AS %" PRIu32 "\n",
11973 group->name, conf->as);
11974 } else if (conf->as_type == AS_INTERNAL) {
11975 vty_out(vty, "\nBGP peer-group %s, remote AS %" PRIu32 "\n",
11976 group->name, group->bgp->as);
11977 } else {
11978 vty_out(vty, "\nBGP peer-group %s\n", group->name);
11979 }
11980
11981 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
11982 vty_out(vty, " Peer-group type is internal\n");
11983 else
11984 vty_out(vty, " Peer-group type is external\n");
11985
11986 /* Display AFs configured. */
11987 vty_out(vty, " Configured address-families:");
11988 FOREACH_AFI_SAFI (afi, safi) {
11989 if (conf->afc[afi][safi]) {
11990 af_cfgd = 1;
11991 vty_out(vty, " %s;", get_afi_safi_str(afi, safi, false));
11992 }
11993 }
11994 if (!af_cfgd)
11995 vty_out(vty, " none\n");
11996 else
11997 vty_out(vty, "\n");
11998
11999 /* Display listen ranges (for dynamic neighbors), if any */
12000 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
12001 if (afi == AFI_IP)
12002 af_str = "IPv4";
12003 else if (afi == AFI_IP6)
12004 af_str = "IPv6";
12005 else
12006 af_str = "???";
12007 lr_count = listcount(group->listen_range[afi]);
12008 if (lr_count) {
12009 vty_out(vty, " %d %s listen range(s)\n", lr_count,
12010 af_str);
12011
12012
12013 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
12014 nnode, range)) {
12015 prefix2str(range, buf, sizeof(buf));
12016 vty_out(vty, " %s\n", buf);
12017 }
12018 }
12019 }
12020
12021 /* Display group members and their status */
12022 if (listcount(group->peer)) {
12023 vty_out(vty, " Peer-group members:\n");
12024 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
12025 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
12026 peer_status = "Idle (Admin)";
12027 else if (CHECK_FLAG(peer->sflags,
12028 PEER_STATUS_PREFIX_OVERFLOW))
12029 peer_status = "Idle (PfxCt)";
12030 else
12031 peer_status = lookup_msg(bgp_status_msg,
12032 peer->status, NULL);
12033
12034 dynamic = peer_dynamic_neighbor(peer);
12035 vty_out(vty, " %s %s %s \n", peer->host,
12036 dynamic ? "(dynamic)" : "", peer_status);
12037 }
12038 }
12039
12040 return CMD_SUCCESS;
12041 }
12042
12043 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
12044 const char *group_name)
12045 {
12046 struct bgp *bgp;
12047 struct listnode *node, *nnode;
12048 struct peer_group *group;
12049 bool found = false;
12050
12051 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
12052
12053 if (!bgp) {
12054 vty_out(vty, "%% BGP instance not found\n");
12055 return CMD_WARNING;
12056 }
12057
12058 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
12059 if (group_name) {
12060 if (strmatch(group->name, group_name)) {
12061 bgp_show_one_peer_group(vty, group);
12062 found = true;
12063 break;
12064 }
12065 } else {
12066 bgp_show_one_peer_group(vty, group);
12067 }
12068 }
12069
12070 if (group_name && !found)
12071 vty_out(vty, "%% No such peer-group\n");
12072
12073 return CMD_SUCCESS;
12074 }
12075
12076 DEFUN (show_ip_bgp_peer_groups,
12077 show_ip_bgp_peer_groups_cmd,
12078 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
12079 SHOW_STR
12080 IP_STR
12081 BGP_STR
12082 BGP_INSTANCE_HELP_STR
12083 "Detailed information on BGP peer groups\n"
12084 "Peer group name\n")
12085 {
12086 char *vrf, *pg;
12087 int idx = 0;
12088
12089 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
12090 : NULL;
12091 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
12092
12093 return bgp_show_peer_group_vty(vty, vrf, pg);
12094 }
12095
12096
12097 /* Redistribute VTY commands. */
12098
12099 DEFUN (bgp_redistribute_ipv4,
12100 bgp_redistribute_ipv4_cmd,
12101 "redistribute " FRR_IP_REDIST_STR_BGPD,
12102 "Redistribute information from another routing protocol\n"
12103 FRR_IP_REDIST_HELP_STR_BGPD)
12104 {
12105 VTY_DECLVAR_CONTEXT(bgp, bgp);
12106 int idx_protocol = 1;
12107 int type;
12108
12109 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12110 if (type < 0) {
12111 vty_out(vty, "%% Invalid route type\n");
12112 return CMD_WARNING_CONFIG_FAILED;
12113 }
12114
12115 bgp_redist_add(bgp, AFI_IP, type, 0);
12116 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
12117 }
12118
12119 ALIAS_HIDDEN(
12120 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
12121 "redistribute " FRR_IP_REDIST_STR_BGPD,
12122 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
12123
12124 DEFUN (bgp_redistribute_ipv4_rmap,
12125 bgp_redistribute_ipv4_rmap_cmd,
12126 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
12127 "Redistribute information from another routing protocol\n"
12128 FRR_IP_REDIST_HELP_STR_BGPD
12129 "Route map reference\n"
12130 "Pointer to route-map entries\n")
12131 {
12132 VTY_DECLVAR_CONTEXT(bgp, bgp);
12133 int idx_protocol = 1;
12134 int idx_word = 3;
12135 int type;
12136 struct bgp_redist *red;
12137 bool changed;
12138 struct route_map *route_map = route_map_lookup_warn_noexist(
12139 vty, argv[idx_word]->arg);
12140
12141 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12142 if (type < 0) {
12143 vty_out(vty, "%% Invalid route type\n");
12144 return CMD_WARNING_CONFIG_FAILED;
12145 }
12146
12147 red = bgp_redist_add(bgp, AFI_IP, type, 0);
12148 changed =
12149 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12150 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
12151 }
12152
12153 ALIAS_HIDDEN(
12154 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
12155 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
12156 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12157 "Route map reference\n"
12158 "Pointer to route-map entries\n")
12159
12160 DEFUN (bgp_redistribute_ipv4_metric,
12161 bgp_redistribute_ipv4_metric_cmd,
12162 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
12163 "Redistribute information from another routing protocol\n"
12164 FRR_IP_REDIST_HELP_STR_BGPD
12165 "Metric for redistributed routes\n"
12166 "Default metric\n")
12167 {
12168 VTY_DECLVAR_CONTEXT(bgp, bgp);
12169 int idx_protocol = 1;
12170 int idx_number = 3;
12171 int type;
12172 uint32_t metric;
12173 struct bgp_redist *red;
12174 bool changed;
12175
12176 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12177 if (type < 0) {
12178 vty_out(vty, "%% Invalid route type\n");
12179 return CMD_WARNING_CONFIG_FAILED;
12180 }
12181 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12182
12183 red = bgp_redist_add(bgp, AFI_IP, type, 0);
12184 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
12185 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
12186 }
12187
12188 ALIAS_HIDDEN(
12189 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
12190 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
12191 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12192 "Metric for redistributed routes\n"
12193 "Default metric\n")
12194
12195 DEFUN (bgp_redistribute_ipv4_rmap_metric,
12196 bgp_redistribute_ipv4_rmap_metric_cmd,
12197 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
12198 "Redistribute information from another routing protocol\n"
12199 FRR_IP_REDIST_HELP_STR_BGPD
12200 "Route map reference\n"
12201 "Pointer to route-map entries\n"
12202 "Metric for redistributed routes\n"
12203 "Default metric\n")
12204 {
12205 VTY_DECLVAR_CONTEXT(bgp, bgp);
12206 int idx_protocol = 1;
12207 int idx_word = 3;
12208 int idx_number = 5;
12209 int type;
12210 uint32_t metric;
12211 struct bgp_redist *red;
12212 bool changed;
12213 struct route_map *route_map =
12214 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12215
12216 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12217 if (type < 0) {
12218 vty_out(vty, "%% Invalid route type\n");
12219 return CMD_WARNING_CONFIG_FAILED;
12220 }
12221 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12222
12223 red = bgp_redist_add(bgp, AFI_IP, type, 0);
12224 changed =
12225 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12226 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
12227 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
12228 }
12229
12230 ALIAS_HIDDEN(
12231 bgp_redistribute_ipv4_rmap_metric,
12232 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
12233 "redistribute " FRR_IP_REDIST_STR_BGPD
12234 " route-map WORD metric (0-4294967295)",
12235 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12236 "Route map reference\n"
12237 "Pointer to route-map entries\n"
12238 "Metric for redistributed routes\n"
12239 "Default metric\n")
12240
12241 DEFUN (bgp_redistribute_ipv4_metric_rmap,
12242 bgp_redistribute_ipv4_metric_rmap_cmd,
12243 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
12244 "Redistribute information from another routing protocol\n"
12245 FRR_IP_REDIST_HELP_STR_BGPD
12246 "Metric for redistributed routes\n"
12247 "Default metric\n"
12248 "Route map reference\n"
12249 "Pointer to route-map entries\n")
12250 {
12251 VTY_DECLVAR_CONTEXT(bgp, bgp);
12252 int idx_protocol = 1;
12253 int idx_number = 3;
12254 int idx_word = 5;
12255 int type;
12256 uint32_t metric;
12257 struct bgp_redist *red;
12258 bool changed;
12259 struct route_map *route_map =
12260 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12261
12262 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12263 if (type < 0) {
12264 vty_out(vty, "%% Invalid route type\n");
12265 return CMD_WARNING_CONFIG_FAILED;
12266 }
12267 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12268
12269 red = bgp_redist_add(bgp, AFI_IP, type, 0);
12270 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
12271 changed |=
12272 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12273 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
12274 }
12275
12276 ALIAS_HIDDEN(
12277 bgp_redistribute_ipv4_metric_rmap,
12278 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
12279 "redistribute " FRR_IP_REDIST_STR_BGPD
12280 " metric (0-4294967295) route-map WORD",
12281 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12282 "Metric for redistributed routes\n"
12283 "Default metric\n"
12284 "Route map reference\n"
12285 "Pointer to route-map entries\n")
12286
12287 DEFUN (bgp_redistribute_ipv4_ospf,
12288 bgp_redistribute_ipv4_ospf_cmd,
12289 "redistribute <ospf|table> (1-65535)",
12290 "Redistribute information from another routing protocol\n"
12291 "Open Shortest Path First (OSPFv2)\n"
12292 "Non-main Kernel Routing Table\n"
12293 "Instance ID/Table ID\n")
12294 {
12295 VTY_DECLVAR_CONTEXT(bgp, bgp);
12296 int idx_ospf_table = 1;
12297 int idx_number = 2;
12298 unsigned short instance;
12299 unsigned short protocol;
12300
12301 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12302
12303 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12304 protocol = ZEBRA_ROUTE_OSPF;
12305 else
12306 protocol = ZEBRA_ROUTE_TABLE;
12307
12308 bgp_redist_add(bgp, AFI_IP, protocol, instance);
12309 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
12310 }
12311
12312 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
12313 "redistribute <ospf|table> (1-65535)",
12314 "Redistribute information from another routing protocol\n"
12315 "Open Shortest Path First (OSPFv2)\n"
12316 "Non-main Kernel Routing Table\n"
12317 "Instance ID/Table ID\n")
12318
12319 DEFUN (bgp_redistribute_ipv4_ospf_rmap,
12320 bgp_redistribute_ipv4_ospf_rmap_cmd,
12321 "redistribute <ospf|table> (1-65535) route-map WORD",
12322 "Redistribute information from another routing protocol\n"
12323 "Open Shortest Path First (OSPFv2)\n"
12324 "Non-main Kernel Routing Table\n"
12325 "Instance ID/Table ID\n"
12326 "Route map reference\n"
12327 "Pointer to route-map entries\n")
12328 {
12329 VTY_DECLVAR_CONTEXT(bgp, bgp);
12330 int idx_ospf_table = 1;
12331 int idx_number = 2;
12332 int idx_word = 4;
12333 struct bgp_redist *red;
12334 unsigned short instance;
12335 int protocol;
12336 bool changed;
12337 struct route_map *route_map =
12338 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12339
12340 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12341 protocol = ZEBRA_ROUTE_OSPF;
12342 else
12343 protocol = ZEBRA_ROUTE_TABLE;
12344
12345 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12346 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12347 changed =
12348 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12349 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12350 }
12351
12352 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
12353 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
12354 "redistribute <ospf|table> (1-65535) route-map WORD",
12355 "Redistribute information from another routing protocol\n"
12356 "Open Shortest Path First (OSPFv2)\n"
12357 "Non-main Kernel Routing Table\n"
12358 "Instance ID/Table ID\n"
12359 "Route map reference\n"
12360 "Pointer to route-map entries\n")
12361
12362 DEFUN (bgp_redistribute_ipv4_ospf_metric,
12363 bgp_redistribute_ipv4_ospf_metric_cmd,
12364 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
12365 "Redistribute information from another routing protocol\n"
12366 "Open Shortest Path First (OSPFv2)\n"
12367 "Non-main Kernel Routing Table\n"
12368 "Instance ID/Table ID\n"
12369 "Metric for redistributed routes\n"
12370 "Default metric\n")
12371 {
12372 VTY_DECLVAR_CONTEXT(bgp, bgp);
12373 int idx_ospf_table = 1;
12374 int idx_number = 2;
12375 int idx_number_2 = 4;
12376 uint32_t metric;
12377 struct bgp_redist *red;
12378 unsigned short instance;
12379 int protocol;
12380 bool changed;
12381
12382 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12383 protocol = ZEBRA_ROUTE_OSPF;
12384 else
12385 protocol = ZEBRA_ROUTE_TABLE;
12386
12387 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12388 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12389
12390 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12391 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12392 metric);
12393 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12394 }
12395
12396 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
12397 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
12398 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
12399 "Redistribute information from another routing protocol\n"
12400 "Open Shortest Path First (OSPFv2)\n"
12401 "Non-main Kernel Routing Table\n"
12402 "Instance ID/Table ID\n"
12403 "Metric for redistributed routes\n"
12404 "Default metric\n")
12405
12406 DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
12407 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
12408 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
12409 "Redistribute information from another routing protocol\n"
12410 "Open Shortest Path First (OSPFv2)\n"
12411 "Non-main Kernel Routing Table\n"
12412 "Instance ID/Table ID\n"
12413 "Route map reference\n"
12414 "Pointer to route-map entries\n"
12415 "Metric for redistributed routes\n"
12416 "Default metric\n")
12417 {
12418 VTY_DECLVAR_CONTEXT(bgp, bgp);
12419 int idx_ospf_table = 1;
12420 int idx_number = 2;
12421 int idx_word = 4;
12422 int idx_number_2 = 6;
12423 uint32_t metric;
12424 struct bgp_redist *red;
12425 unsigned short instance;
12426 int protocol;
12427 bool changed;
12428 struct route_map *route_map =
12429 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12430
12431 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12432 protocol = ZEBRA_ROUTE_OSPF;
12433 else
12434 protocol = ZEBRA_ROUTE_TABLE;
12435
12436 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12437 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12438
12439 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12440 changed =
12441 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12442 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12443 metric);
12444 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12445 }
12446
12447 ALIAS_HIDDEN(
12448 bgp_redistribute_ipv4_ospf_rmap_metric,
12449 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
12450 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
12451 "Redistribute information from another routing protocol\n"
12452 "Open Shortest Path First (OSPFv2)\n"
12453 "Non-main Kernel Routing Table\n"
12454 "Instance ID/Table ID\n"
12455 "Route map reference\n"
12456 "Pointer to route-map entries\n"
12457 "Metric for redistributed routes\n"
12458 "Default metric\n")
12459
12460 DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
12461 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
12462 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
12463 "Redistribute information from another routing protocol\n"
12464 "Open Shortest Path First (OSPFv2)\n"
12465 "Non-main Kernel Routing Table\n"
12466 "Instance ID/Table ID\n"
12467 "Metric for redistributed routes\n"
12468 "Default metric\n"
12469 "Route map reference\n"
12470 "Pointer to route-map entries\n")
12471 {
12472 VTY_DECLVAR_CONTEXT(bgp, bgp);
12473 int idx_ospf_table = 1;
12474 int idx_number = 2;
12475 int idx_number_2 = 4;
12476 int idx_word = 6;
12477 uint32_t metric;
12478 struct bgp_redist *red;
12479 unsigned short instance;
12480 int protocol;
12481 bool changed;
12482 struct route_map *route_map =
12483 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12484
12485 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12486 protocol = ZEBRA_ROUTE_OSPF;
12487 else
12488 protocol = ZEBRA_ROUTE_TABLE;
12489
12490 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12491 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12492
12493 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12494 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12495 metric);
12496 changed |=
12497 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12498 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12499 }
12500
12501 ALIAS_HIDDEN(
12502 bgp_redistribute_ipv4_ospf_metric_rmap,
12503 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
12504 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
12505 "Redistribute information from another routing protocol\n"
12506 "Open Shortest Path First (OSPFv2)\n"
12507 "Non-main Kernel Routing Table\n"
12508 "Instance ID/Table ID\n"
12509 "Metric for redistributed routes\n"
12510 "Default metric\n"
12511 "Route map reference\n"
12512 "Pointer to route-map entries\n")
12513
12514 DEFUN (no_bgp_redistribute_ipv4_ospf,
12515 no_bgp_redistribute_ipv4_ospf_cmd,
12516 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
12517 NO_STR
12518 "Redistribute information from another routing protocol\n"
12519 "Open Shortest Path First (OSPFv2)\n"
12520 "Non-main Kernel Routing Table\n"
12521 "Instance ID/Table ID\n"
12522 "Metric for redistributed routes\n"
12523 "Default metric\n"
12524 "Route map reference\n"
12525 "Pointer to route-map entries\n")
12526 {
12527 VTY_DECLVAR_CONTEXT(bgp, bgp);
12528 int idx_ospf_table = 2;
12529 int idx_number = 3;
12530 unsigned short instance;
12531 int protocol;
12532
12533 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12534 protocol = ZEBRA_ROUTE_OSPF;
12535 else
12536 protocol = ZEBRA_ROUTE_TABLE;
12537
12538 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12539 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
12540 }
12541
12542 ALIAS_HIDDEN(
12543 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
12544 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
12545 NO_STR
12546 "Redistribute information from another routing protocol\n"
12547 "Open Shortest Path First (OSPFv2)\n"
12548 "Non-main Kernel Routing Table\n"
12549 "Instance ID/Table ID\n"
12550 "Metric for redistributed routes\n"
12551 "Default metric\n"
12552 "Route map reference\n"
12553 "Pointer to route-map entries\n")
12554
12555 DEFUN (no_bgp_redistribute_ipv4,
12556 no_bgp_redistribute_ipv4_cmd,
12557 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
12558 NO_STR
12559 "Redistribute information from another routing protocol\n"
12560 FRR_IP_REDIST_HELP_STR_BGPD
12561 "Metric for redistributed routes\n"
12562 "Default metric\n"
12563 "Route map reference\n"
12564 "Pointer to route-map entries\n")
12565 {
12566 VTY_DECLVAR_CONTEXT(bgp, bgp);
12567 int idx_protocol = 2;
12568 int type;
12569
12570 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12571 if (type < 0) {
12572 vty_out(vty, "%% Invalid route type\n");
12573 return CMD_WARNING_CONFIG_FAILED;
12574 }
12575 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
12576 }
12577
12578 ALIAS_HIDDEN(
12579 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
12580 "no redistribute " FRR_IP_REDIST_STR_BGPD
12581 " [{metric (0-4294967295)|route-map WORD}]",
12582 NO_STR
12583 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12584 "Metric for redistributed routes\n"
12585 "Default metric\n"
12586 "Route map reference\n"
12587 "Pointer to route-map entries\n")
12588
12589 DEFUN (bgp_redistribute_ipv6,
12590 bgp_redistribute_ipv6_cmd,
12591 "redistribute " FRR_IP6_REDIST_STR_BGPD,
12592 "Redistribute information from another routing protocol\n"
12593 FRR_IP6_REDIST_HELP_STR_BGPD)
12594 {
12595 VTY_DECLVAR_CONTEXT(bgp, bgp);
12596 int idx_protocol = 1;
12597 int type;
12598
12599 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12600 if (type < 0) {
12601 vty_out(vty, "%% Invalid route type\n");
12602 return CMD_WARNING_CONFIG_FAILED;
12603 }
12604
12605 bgp_redist_add(bgp, AFI_IP6, type, 0);
12606 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
12607 }
12608
12609 DEFUN (bgp_redistribute_ipv6_rmap,
12610 bgp_redistribute_ipv6_rmap_cmd,
12611 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
12612 "Redistribute information from another routing protocol\n"
12613 FRR_IP6_REDIST_HELP_STR_BGPD
12614 "Route map reference\n"
12615 "Pointer to route-map entries\n")
12616 {
12617 VTY_DECLVAR_CONTEXT(bgp, bgp);
12618 int idx_protocol = 1;
12619 int idx_word = 3;
12620 int type;
12621 struct bgp_redist *red;
12622 bool changed;
12623 struct route_map *route_map =
12624 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12625
12626 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12627 if (type < 0) {
12628 vty_out(vty, "%% Invalid route type\n");
12629 return CMD_WARNING_CONFIG_FAILED;
12630 }
12631
12632 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12633 changed =
12634 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12635 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12636 }
12637
12638 DEFUN (bgp_redistribute_ipv6_metric,
12639 bgp_redistribute_ipv6_metric_cmd,
12640 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
12641 "Redistribute information from another routing protocol\n"
12642 FRR_IP6_REDIST_HELP_STR_BGPD
12643 "Metric for redistributed routes\n"
12644 "Default metric\n")
12645 {
12646 VTY_DECLVAR_CONTEXT(bgp, bgp);
12647 int idx_protocol = 1;
12648 int idx_number = 3;
12649 int type;
12650 uint32_t metric;
12651 struct bgp_redist *red;
12652 bool changed;
12653
12654 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12655 if (type < 0) {
12656 vty_out(vty, "%% Invalid route type\n");
12657 return CMD_WARNING_CONFIG_FAILED;
12658 }
12659 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12660
12661 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12662 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
12663 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12664 }
12665
12666 DEFUN (bgp_redistribute_ipv6_rmap_metric,
12667 bgp_redistribute_ipv6_rmap_metric_cmd,
12668 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
12669 "Redistribute information from another routing protocol\n"
12670 FRR_IP6_REDIST_HELP_STR_BGPD
12671 "Route map reference\n"
12672 "Pointer to route-map entries\n"
12673 "Metric for redistributed routes\n"
12674 "Default metric\n")
12675 {
12676 VTY_DECLVAR_CONTEXT(bgp, bgp);
12677 int idx_protocol = 1;
12678 int idx_word = 3;
12679 int idx_number = 5;
12680 int type;
12681 uint32_t metric;
12682 struct bgp_redist *red;
12683 bool changed;
12684 struct route_map *route_map =
12685 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12686
12687 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12688 if (type < 0) {
12689 vty_out(vty, "%% Invalid route type\n");
12690 return CMD_WARNING_CONFIG_FAILED;
12691 }
12692 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12693
12694 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12695 changed =
12696 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12697 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
12698 metric);
12699 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12700 }
12701
12702 DEFUN (bgp_redistribute_ipv6_metric_rmap,
12703 bgp_redistribute_ipv6_metric_rmap_cmd,
12704 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
12705 "Redistribute information from another routing protocol\n"
12706 FRR_IP6_REDIST_HELP_STR_BGPD
12707 "Metric for redistributed routes\n"
12708 "Default metric\n"
12709 "Route map reference\n"
12710 "Pointer to route-map entries\n")
12711 {
12712 VTY_DECLVAR_CONTEXT(bgp, bgp);
12713 int idx_protocol = 1;
12714 int idx_number = 3;
12715 int idx_word = 5;
12716 int type;
12717 uint32_t metric;
12718 struct bgp_redist *red;
12719 bool changed;
12720 struct route_map *route_map =
12721 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12722
12723 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12724 if (type < 0) {
12725 vty_out(vty, "%% Invalid route type\n");
12726 return CMD_WARNING_CONFIG_FAILED;
12727 }
12728 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12729
12730 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12731 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
12732 metric);
12733 changed |=
12734 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12735 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12736 }
12737
12738 DEFUN (no_bgp_redistribute_ipv6,
12739 no_bgp_redistribute_ipv6_cmd,
12740 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
12741 NO_STR
12742 "Redistribute information from another routing protocol\n"
12743 FRR_IP6_REDIST_HELP_STR_BGPD
12744 "Metric for redistributed routes\n"
12745 "Default metric\n"
12746 "Route map reference\n"
12747 "Pointer to route-map entries\n")
12748 {
12749 VTY_DECLVAR_CONTEXT(bgp, bgp);
12750 int idx_protocol = 2;
12751 int type;
12752
12753 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12754 if (type < 0) {
12755 vty_out(vty, "%% Invalid route type\n");
12756 return CMD_WARNING_CONFIG_FAILED;
12757 }
12758
12759 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
12760 }
12761
12762 void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp, afi_t afi,
12763 safi_t safi)
12764 {
12765 int i;
12766
12767 /* Unicast redistribution only. */
12768 if (safi != SAFI_UNICAST)
12769 return;
12770
12771 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
12772 /* Redistribute BGP does not make sense. */
12773 if (i != ZEBRA_ROUTE_BGP) {
12774 struct list *red_list;
12775 struct listnode *node;
12776 struct bgp_redist *red;
12777
12778 red_list = bgp->redist[afi][i];
12779 if (!red_list)
12780 continue;
12781
12782 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
12783 /* "redistribute" configuration. */
12784 vty_out(vty, " redistribute %s",
12785 zebra_route_string(i));
12786 if (red->instance)
12787 vty_out(vty, " %d", red->instance);
12788 if (red->redist_metric_flag)
12789 vty_out(vty, " metric %u",
12790 red->redist_metric);
12791 if (red->rmap.name)
12792 vty_out(vty, " route-map %s",
12793 red->rmap.name);
12794 vty_out(vty, "\n");
12795 }
12796 }
12797 }
12798 }
12799
12800 /* This is part of the address-family block (unicast only) */
12801 void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
12802 afi_t afi)
12803 {
12804 int indent = 2;
12805
12806 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
12807 if (listcount(bgp->vpn_policy[afi].import_vrf))
12808 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
12809 bgp->vpn_policy[afi]
12810 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12811 else
12812 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
12813 bgp->vpn_policy[afi]
12814 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12815 }
12816 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12817 BGP_CONFIG_VRF_TO_VRF_IMPORT)
12818 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12819 BGP_CONFIG_VRF_TO_VRF_EXPORT))
12820 return;
12821
12822 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12823 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
12824
12825 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
12826
12827 } else {
12828 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
12829 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
12830 bgp->vpn_policy[afi].tovpn_label);
12831 }
12832 }
12833 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12834 BGP_VPN_POLICY_TOVPN_RD_SET)) {
12835 char buf[RD_ADDRSTRLEN];
12836 vty_out(vty, "%*srd vpn export %s\n", indent, "",
12837 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
12838 sizeof(buf)));
12839 }
12840 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12841 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
12842
12843 char buf[PREFIX_STRLEN];
12844 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
12845 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
12846 sizeof(buf))) {
12847
12848 vty_out(vty, "%*snexthop vpn export %s\n",
12849 indent, "", buf);
12850 }
12851 }
12852 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
12853 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
12854 && ecommunity_cmp(
12855 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12856 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
12857
12858 char *b = ecommunity_ecom2str(
12859 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12860 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
12861 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
12862 XFREE(MTYPE_ECOMMUNITY_STR, b);
12863 } else {
12864 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
12865 char *b = ecommunity_ecom2str(
12866 bgp->vpn_policy[afi]
12867 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12868 ECOMMUNITY_FORMAT_ROUTE_MAP,
12869 ECOMMUNITY_ROUTE_TARGET);
12870 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
12871 XFREE(MTYPE_ECOMMUNITY_STR, b);
12872 }
12873 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
12874 char *b = ecommunity_ecom2str(
12875 bgp->vpn_policy[afi]
12876 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12877 ECOMMUNITY_FORMAT_ROUTE_MAP,
12878 ECOMMUNITY_ROUTE_TARGET);
12879 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
12880 XFREE(MTYPE_ECOMMUNITY_STR, b);
12881 }
12882 }
12883
12884 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
12885 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
12886 bgp->vpn_policy[afi]
12887 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
12888
12889 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
12890 char *b = ecommunity_ecom2str(
12891 bgp->vpn_policy[afi]
12892 .import_redirect_rtlist,
12893 ECOMMUNITY_FORMAT_ROUTE_MAP,
12894 ECOMMUNITY_ROUTE_TARGET);
12895
12896 vty_out(vty, "%*srt redirect import %s\n", indent, "", b);
12897 XFREE(MTYPE_ECOMMUNITY_STR, b);
12898 }
12899 }
12900
12901
12902 /* BGP node structure. */
12903 static struct cmd_node bgp_node = {
12904 BGP_NODE, "%s(config-router)# ", 1,
12905 };
12906
12907 static struct cmd_node bgp_ipv4_unicast_node = {
12908 BGP_IPV4_NODE, "%s(config-router-af)# ", 1,
12909 };
12910
12911 static struct cmd_node bgp_ipv4_multicast_node = {
12912 BGP_IPV4M_NODE, "%s(config-router-af)# ", 1,
12913 };
12914
12915 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
12916 BGP_IPV4L_NODE, "%s(config-router-af)# ", 1,
12917 };
12918
12919 static struct cmd_node bgp_ipv6_unicast_node = {
12920 BGP_IPV6_NODE, "%s(config-router-af)# ", 1,
12921 };
12922
12923 static struct cmd_node bgp_ipv6_multicast_node = {
12924 BGP_IPV6M_NODE, "%s(config-router-af)# ", 1,
12925 };
12926
12927 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
12928 BGP_IPV6L_NODE, "%s(config-router-af)# ", 1,
12929 };
12930
12931 static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
12932 "%s(config-router-af)# ", 1};
12933
12934 static struct cmd_node bgp_vpnv6_node = {BGP_VPNV6_NODE,
12935 "%s(config-router-af-vpnv6)# ", 1};
12936
12937 static struct cmd_node bgp_evpn_node = {BGP_EVPN_NODE,
12938 "%s(config-router-evpn)# ", 1};
12939
12940 static struct cmd_node bgp_evpn_vni_node = {BGP_EVPN_VNI_NODE,
12941 "%s(config-router-af-vni)# ", 1};
12942
12943 static struct cmd_node bgp_flowspecv4_node = {BGP_FLOWSPECV4_NODE,
12944 "%s(config-router-af)# ", 1};
12945
12946 static struct cmd_node bgp_flowspecv6_node = {BGP_FLOWSPECV6_NODE,
12947 "%s(config-router-af-vpnv6)# ", 1};
12948
12949 static void community_list_vty(void);
12950
12951 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
12952 {
12953 struct bgp *bgp;
12954 struct peer *peer;
12955 struct listnode *lnbgp, *lnpeer;
12956
12957 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12958 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
12959 /* only provide suggestions on the appropriate input
12960 * token type,
12961 * they'll otherwise show up multiple times */
12962 enum cmd_token_type match_type;
12963 char *name = peer->host;
12964
12965 if (peer->conf_if) {
12966 match_type = VARIABLE_TKN;
12967 name = peer->conf_if;
12968 } else if (strchr(peer->host, ':'))
12969 match_type = IPV6_TKN;
12970 else
12971 match_type = IPV4_TKN;
12972
12973 if (token->type != match_type)
12974 continue;
12975
12976 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
12977 }
12978 }
12979 }
12980
12981 static const struct cmd_variable_handler bgp_var_neighbor[] = {
12982 {.varname = "neighbor", .completions = bgp_ac_neighbor},
12983 {.varname = "neighbors", .completions = bgp_ac_neighbor},
12984 {.varname = "peer", .completions = bgp_ac_neighbor},
12985 {.completions = NULL}};
12986
12987 static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
12988 {
12989 struct bgp *bgp;
12990 struct peer_group *group;
12991 struct listnode *lnbgp, *lnpeer;
12992
12993 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12994 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
12995 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
12996 group->name));
12997 }
12998 }
12999
13000 static const struct cmd_variable_handler bgp_var_peergroup[] = {
13001 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
13002 {.completions = NULL} };
13003
13004 void bgp_vty_init(void)
13005 {
13006 cmd_variable_handler_register(bgp_var_neighbor);
13007 cmd_variable_handler_register(bgp_var_peergroup);
13008
13009 /* Install bgp top node. */
13010 install_node(&bgp_node, bgp_config_write);
13011 install_node(&bgp_ipv4_unicast_node, NULL);
13012 install_node(&bgp_ipv4_multicast_node, NULL);
13013 install_node(&bgp_ipv4_labeled_unicast_node, NULL);
13014 install_node(&bgp_ipv6_unicast_node, NULL);
13015 install_node(&bgp_ipv6_multicast_node, NULL);
13016 install_node(&bgp_ipv6_labeled_unicast_node, NULL);
13017 install_node(&bgp_vpnv4_node, NULL);
13018 install_node(&bgp_vpnv6_node, NULL);
13019 install_node(&bgp_evpn_node, NULL);
13020 install_node(&bgp_evpn_vni_node, NULL);
13021 install_node(&bgp_flowspecv4_node, NULL);
13022 install_node(&bgp_flowspecv6_node, NULL);
13023
13024 /* Install default VTY commands to new nodes. */
13025 install_default(BGP_NODE);
13026 install_default(BGP_IPV4_NODE);
13027 install_default(BGP_IPV4M_NODE);
13028 install_default(BGP_IPV4L_NODE);
13029 install_default(BGP_IPV6_NODE);
13030 install_default(BGP_IPV6M_NODE);
13031 install_default(BGP_IPV6L_NODE);
13032 install_default(BGP_VPNV4_NODE);
13033 install_default(BGP_VPNV6_NODE);
13034 install_default(BGP_FLOWSPECV4_NODE);
13035 install_default(BGP_FLOWSPECV6_NODE);
13036 install_default(BGP_EVPN_NODE);
13037 install_default(BGP_EVPN_VNI_NODE);
13038
13039 /* "bgp local-mac" hidden commands. */
13040 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
13041 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
13042
13043 /* bgp route-map delay-timer commands. */
13044 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
13045 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
13046
13047 /* Dummy commands (Currently not supported) */
13048 install_element(BGP_NODE, &no_synchronization_cmd);
13049 install_element(BGP_NODE, &no_auto_summary_cmd);
13050
13051 /* "router bgp" commands. */
13052 install_element(CONFIG_NODE, &router_bgp_cmd);
13053
13054 /* "no router bgp" commands. */
13055 install_element(CONFIG_NODE, &no_router_bgp_cmd);
13056
13057 /* "bgp router-id" commands. */
13058 install_element(BGP_NODE, &bgp_router_id_cmd);
13059 install_element(BGP_NODE, &no_bgp_router_id_cmd);
13060
13061 /* "bgp cluster-id" commands. */
13062 install_element(BGP_NODE, &bgp_cluster_id_cmd);
13063 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
13064
13065 /* "bgp confederation" commands. */
13066 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
13067 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
13068
13069 /* "bgp confederation peers" commands. */
13070 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
13071 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
13072
13073 /* bgp max-med command */
13074 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
13075 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
13076 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
13077 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
13078 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
13079
13080 /* bgp disable-ebgp-connected-nh-check */
13081 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
13082 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
13083
13084 /* bgp update-delay command */
13085 install_element(BGP_NODE, &bgp_update_delay_cmd);
13086 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
13087 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
13088
13089 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
13090 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
13091
13092 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
13093 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
13094
13095 /* "maximum-paths" commands. */
13096 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
13097 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
13098 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
13099 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
13100 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
13101 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
13102 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
13103 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
13104 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
13105 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
13106 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
13107 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
13108 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
13109 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
13110 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
13111
13112 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
13113 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
13114 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
13115 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
13116 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
13117
13118 /* "timers bgp" commands. */
13119 install_element(BGP_NODE, &bgp_timers_cmd);
13120 install_element(BGP_NODE, &no_bgp_timers_cmd);
13121
13122 /* route-map delay-timer commands - per instance for backwards compat.
13123 */
13124 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
13125 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
13126
13127 /* "bgp client-to-client reflection" commands */
13128 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
13129 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
13130
13131 /* "bgp always-compare-med" commands */
13132 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
13133 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
13134
13135 /* bgp ebgp-requires-policy */
13136 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
13137 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
13138
13139 /* "bgp deterministic-med" commands */
13140 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
13141 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
13142
13143 /* "bgp graceful-restart" commands */
13144 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
13145 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
13146 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
13147 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
13148 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
13149 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
13150
13151 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
13152 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
13153
13154 /* "bgp graceful-shutdown" commands */
13155 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
13156 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
13157
13158 /* "bgp fast-external-failover" commands */
13159 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
13160 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
13161
13162 /* "bgp bestpath compare-routerid" commands */
13163 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
13164 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
13165
13166 /* "bgp bestpath as-path ignore" commands */
13167 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
13168 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
13169
13170 /* "bgp bestpath as-path confed" commands */
13171 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
13172 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
13173
13174 /* "bgp bestpath as-path multipath-relax" commands */
13175 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
13176 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
13177
13178 /* "bgp log-neighbor-changes" commands */
13179 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
13180 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
13181
13182 /* "bgp bestpath med" commands */
13183 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
13184 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
13185
13186 /* "no bgp default ipv4-unicast" commands. */
13187 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
13188 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
13189
13190 /* "bgp network import-check" commands. */
13191 install_element(BGP_NODE, &bgp_network_import_check_cmd);
13192 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
13193 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
13194
13195 /* "bgp default local-preference" commands. */
13196 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
13197 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
13198
13199 /* bgp default show-hostname */
13200 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
13201 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
13202
13203 /* "bgp default subgroup-pkt-queue-max" commands. */
13204 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
13205 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
13206
13207 /* bgp ibgp-allow-policy-mods command */
13208 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
13209 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
13210
13211 /* "bgp listen limit" commands. */
13212 install_element(BGP_NODE, &bgp_listen_limit_cmd);
13213 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
13214
13215 /* "bgp listen range" commands. */
13216 install_element(BGP_NODE, &bgp_listen_range_cmd);
13217 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
13218
13219 /* "bgp default shutdown" command */
13220 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
13221
13222 /* "neighbor remote-as" commands. */
13223 install_element(BGP_NODE, &neighbor_remote_as_cmd);
13224 install_element(BGP_NODE, &neighbor_interface_config_cmd);
13225 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
13226 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
13227 install_element(BGP_NODE,
13228 &neighbor_interface_v6only_config_remote_as_cmd);
13229 install_element(BGP_NODE, &no_neighbor_cmd);
13230 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
13231
13232 /* "neighbor peer-group" commands. */
13233 install_element(BGP_NODE, &neighbor_peer_group_cmd);
13234 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
13235 install_element(BGP_NODE,
13236 &no_neighbor_interface_peer_group_remote_as_cmd);
13237
13238 /* "neighbor local-as" commands. */
13239 install_element(BGP_NODE, &neighbor_local_as_cmd);
13240 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
13241 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
13242 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
13243
13244 /* "neighbor solo" commands. */
13245 install_element(BGP_NODE, &neighbor_solo_cmd);
13246 install_element(BGP_NODE, &no_neighbor_solo_cmd);
13247
13248 /* "neighbor password" commands. */
13249 install_element(BGP_NODE, &neighbor_password_cmd);
13250 install_element(BGP_NODE, &no_neighbor_password_cmd);
13251
13252 /* "neighbor activate" commands. */
13253 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
13254 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
13255 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
13256 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
13257 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
13258 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
13259 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
13260 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
13261 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
13262 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
13263 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
13264 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
13265
13266 /* "no neighbor activate" commands. */
13267 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
13268 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
13269 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
13270 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
13271 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
13272 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
13273 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
13274 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
13275 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
13276 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
13277 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
13278 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
13279
13280 /* "neighbor peer-group" set commands. */
13281 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
13282 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
13283 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
13284 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
13285 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
13286 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
13287 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
13288 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
13289 install_element(BGP_FLOWSPECV4_NODE,
13290 &neighbor_set_peer_group_hidden_cmd);
13291 install_element(BGP_FLOWSPECV6_NODE,
13292 &neighbor_set_peer_group_hidden_cmd);
13293
13294 /* "no neighbor peer-group unset" commands. */
13295 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
13296 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13297 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13298 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13299 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13300 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13301 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13302 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13303 install_element(BGP_FLOWSPECV4_NODE,
13304 &no_neighbor_set_peer_group_hidden_cmd);
13305 install_element(BGP_FLOWSPECV6_NODE,
13306 &no_neighbor_set_peer_group_hidden_cmd);
13307
13308 /* "neighbor softreconfiguration inbound" commands.*/
13309 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
13310 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
13311 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
13312 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
13313 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
13314 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
13315 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
13316 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
13317 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
13318 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
13319 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
13320 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
13321 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
13322 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
13323 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
13324 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
13325 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
13326 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
13327 install_element(BGP_FLOWSPECV4_NODE,
13328 &neighbor_soft_reconfiguration_cmd);
13329 install_element(BGP_FLOWSPECV4_NODE,
13330 &no_neighbor_soft_reconfiguration_cmd);
13331 install_element(BGP_FLOWSPECV6_NODE,
13332 &neighbor_soft_reconfiguration_cmd);
13333 install_element(BGP_FLOWSPECV6_NODE,
13334 &no_neighbor_soft_reconfiguration_cmd);
13335 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
13336 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
13337
13338 /* "neighbor attribute-unchanged" commands. */
13339 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
13340 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
13341 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
13342 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
13343 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
13344 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
13345 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
13346 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
13347 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
13348 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
13349 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
13350 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
13351 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
13352 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
13353 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
13354 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
13355 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
13356 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
13357
13358 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
13359 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
13360
13361 /* "nexthop-local unchanged" commands */
13362 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
13363 install_element(BGP_IPV6_NODE,
13364 &no_neighbor_nexthop_local_unchanged_cmd);
13365
13366 /* "neighbor next-hop-self" commands. */
13367 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
13368 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
13369 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
13370 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
13371 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
13372 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
13373 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
13374 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
13375 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
13376 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
13377 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
13378 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
13379 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
13380 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
13381 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
13382 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
13383 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
13384 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
13385 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
13386 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
13387
13388 /* "neighbor next-hop-self force" commands. */
13389 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
13390 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
13391 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13392 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
13393 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
13394 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
13395 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13396 install_element(BGP_IPV4_NODE,
13397 &no_neighbor_nexthop_self_all_hidden_cmd);
13398 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
13399 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
13400 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13401 install_element(BGP_IPV4M_NODE,
13402 &no_neighbor_nexthop_self_all_hidden_cmd);
13403 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
13404 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
13405 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13406 install_element(BGP_IPV4L_NODE,
13407 &no_neighbor_nexthop_self_all_hidden_cmd);
13408 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
13409 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
13410 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13411 install_element(BGP_IPV6_NODE,
13412 &no_neighbor_nexthop_self_all_hidden_cmd);
13413 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
13414 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
13415 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13416 install_element(BGP_IPV6M_NODE,
13417 &no_neighbor_nexthop_self_all_hidden_cmd);
13418 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
13419 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
13420 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13421 install_element(BGP_IPV6L_NODE,
13422 &no_neighbor_nexthop_self_all_hidden_cmd);
13423 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
13424 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
13425 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13426 install_element(BGP_VPNV4_NODE,
13427 &no_neighbor_nexthop_self_all_hidden_cmd);
13428 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
13429 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
13430 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13431 install_element(BGP_VPNV6_NODE,
13432 &no_neighbor_nexthop_self_all_hidden_cmd);
13433
13434 /* "neighbor as-override" commands. */
13435 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
13436 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
13437 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
13438 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
13439 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
13440 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
13441 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
13442 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
13443 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
13444 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
13445 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
13446 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
13447 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
13448 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
13449 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
13450 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
13451 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
13452 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
13453
13454 /* "neighbor remove-private-AS" commands. */
13455 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
13456 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
13457 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
13458 install_element(BGP_NODE,
13459 &no_neighbor_remove_private_as_all_hidden_cmd);
13460 install_element(BGP_NODE,
13461 &neighbor_remove_private_as_replace_as_hidden_cmd);
13462 install_element(BGP_NODE,
13463 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
13464 install_element(BGP_NODE,
13465 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
13466 install_element(
13467 BGP_NODE,
13468 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
13469 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
13470 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
13471 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
13472 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
13473 install_element(BGP_IPV4_NODE,
13474 &neighbor_remove_private_as_replace_as_cmd);
13475 install_element(BGP_IPV4_NODE,
13476 &no_neighbor_remove_private_as_replace_as_cmd);
13477 install_element(BGP_IPV4_NODE,
13478 &neighbor_remove_private_as_all_replace_as_cmd);
13479 install_element(BGP_IPV4_NODE,
13480 &no_neighbor_remove_private_as_all_replace_as_cmd);
13481 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
13482 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
13483 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
13484 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
13485 install_element(BGP_IPV4M_NODE,
13486 &neighbor_remove_private_as_replace_as_cmd);
13487 install_element(BGP_IPV4M_NODE,
13488 &no_neighbor_remove_private_as_replace_as_cmd);
13489 install_element(BGP_IPV4M_NODE,
13490 &neighbor_remove_private_as_all_replace_as_cmd);
13491 install_element(BGP_IPV4M_NODE,
13492 &no_neighbor_remove_private_as_all_replace_as_cmd);
13493 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
13494 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
13495 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
13496 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
13497 install_element(BGP_IPV4L_NODE,
13498 &neighbor_remove_private_as_replace_as_cmd);
13499 install_element(BGP_IPV4L_NODE,
13500 &no_neighbor_remove_private_as_replace_as_cmd);
13501 install_element(BGP_IPV4L_NODE,
13502 &neighbor_remove_private_as_all_replace_as_cmd);
13503 install_element(BGP_IPV4L_NODE,
13504 &no_neighbor_remove_private_as_all_replace_as_cmd);
13505 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
13506 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
13507 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
13508 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
13509 install_element(BGP_IPV6_NODE,
13510 &neighbor_remove_private_as_replace_as_cmd);
13511 install_element(BGP_IPV6_NODE,
13512 &no_neighbor_remove_private_as_replace_as_cmd);
13513 install_element(BGP_IPV6_NODE,
13514 &neighbor_remove_private_as_all_replace_as_cmd);
13515 install_element(BGP_IPV6_NODE,
13516 &no_neighbor_remove_private_as_all_replace_as_cmd);
13517 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
13518 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
13519 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
13520 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
13521 install_element(BGP_IPV6M_NODE,
13522 &neighbor_remove_private_as_replace_as_cmd);
13523 install_element(BGP_IPV6M_NODE,
13524 &no_neighbor_remove_private_as_replace_as_cmd);
13525 install_element(BGP_IPV6M_NODE,
13526 &neighbor_remove_private_as_all_replace_as_cmd);
13527 install_element(BGP_IPV6M_NODE,
13528 &no_neighbor_remove_private_as_all_replace_as_cmd);
13529 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
13530 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
13531 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
13532 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
13533 install_element(BGP_IPV6L_NODE,
13534 &neighbor_remove_private_as_replace_as_cmd);
13535 install_element(BGP_IPV6L_NODE,
13536 &no_neighbor_remove_private_as_replace_as_cmd);
13537 install_element(BGP_IPV6L_NODE,
13538 &neighbor_remove_private_as_all_replace_as_cmd);
13539 install_element(BGP_IPV6L_NODE,
13540 &no_neighbor_remove_private_as_all_replace_as_cmd);
13541 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
13542 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
13543 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
13544 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
13545 install_element(BGP_VPNV4_NODE,
13546 &neighbor_remove_private_as_replace_as_cmd);
13547 install_element(BGP_VPNV4_NODE,
13548 &no_neighbor_remove_private_as_replace_as_cmd);
13549 install_element(BGP_VPNV4_NODE,
13550 &neighbor_remove_private_as_all_replace_as_cmd);
13551 install_element(BGP_VPNV4_NODE,
13552 &no_neighbor_remove_private_as_all_replace_as_cmd);
13553 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
13554 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
13555 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
13556 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
13557 install_element(BGP_VPNV6_NODE,
13558 &neighbor_remove_private_as_replace_as_cmd);
13559 install_element(BGP_VPNV6_NODE,
13560 &no_neighbor_remove_private_as_replace_as_cmd);
13561 install_element(BGP_VPNV6_NODE,
13562 &neighbor_remove_private_as_all_replace_as_cmd);
13563 install_element(BGP_VPNV6_NODE,
13564 &no_neighbor_remove_private_as_all_replace_as_cmd);
13565
13566 /* "neighbor send-community" commands.*/
13567 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
13568 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
13569 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
13570 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
13571 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
13572 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
13573 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
13574 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
13575 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
13576 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
13577 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
13578 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
13579 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
13580 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
13581 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
13582 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
13583 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
13584 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
13585 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
13586 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
13587 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
13588 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
13589 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
13590 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
13591 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
13592 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
13593 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
13594 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
13595 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
13596 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
13597 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
13598 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
13599 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
13600 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
13601 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
13602 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
13603
13604 /* "neighbor route-reflector" commands.*/
13605 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
13606 install_element(BGP_NODE,
13607 &no_neighbor_route_reflector_client_hidden_cmd);
13608 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
13609 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
13610 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
13611 install_element(BGP_IPV4M_NODE,
13612 &no_neighbor_route_reflector_client_cmd);
13613 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
13614 install_element(BGP_IPV4L_NODE,
13615 &no_neighbor_route_reflector_client_cmd);
13616 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
13617 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
13618 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
13619 install_element(BGP_IPV6M_NODE,
13620 &no_neighbor_route_reflector_client_cmd);
13621 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
13622 install_element(BGP_IPV6L_NODE,
13623 &no_neighbor_route_reflector_client_cmd);
13624 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
13625 install_element(BGP_VPNV4_NODE,
13626 &no_neighbor_route_reflector_client_cmd);
13627 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
13628 install_element(BGP_VPNV6_NODE,
13629 &no_neighbor_route_reflector_client_cmd);
13630 install_element(BGP_FLOWSPECV4_NODE,
13631 &neighbor_route_reflector_client_cmd);
13632 install_element(BGP_FLOWSPECV4_NODE,
13633 &no_neighbor_route_reflector_client_cmd);
13634 install_element(BGP_FLOWSPECV6_NODE,
13635 &neighbor_route_reflector_client_cmd);
13636 install_element(BGP_FLOWSPECV6_NODE,
13637 &no_neighbor_route_reflector_client_cmd);
13638 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
13639 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
13640
13641 /* "neighbor route-server" commands.*/
13642 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
13643 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
13644 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
13645 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
13646 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
13647 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
13648 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
13649 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
13650 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
13651 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
13652 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
13653 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
13654 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
13655 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
13656 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
13657 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
13658 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
13659 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
13660 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
13661 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
13662 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
13663 install_element(BGP_FLOWSPECV4_NODE,
13664 &no_neighbor_route_server_client_cmd);
13665 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
13666 install_element(BGP_FLOWSPECV6_NODE,
13667 &no_neighbor_route_server_client_cmd);
13668
13669 /* "neighbor addpath-tx-all-paths" commands.*/
13670 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
13671 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
13672 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13673 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13674 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13675 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13676 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13677 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13678 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13679 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13680 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13681 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13682 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13683 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13684 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13685 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13686 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13687 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13688
13689 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
13690 install_element(BGP_NODE,
13691 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13692 install_element(BGP_NODE,
13693 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13694 install_element(BGP_IPV4_NODE,
13695 &neighbor_addpath_tx_bestpath_per_as_cmd);
13696 install_element(BGP_IPV4_NODE,
13697 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13698 install_element(BGP_IPV4M_NODE,
13699 &neighbor_addpath_tx_bestpath_per_as_cmd);
13700 install_element(BGP_IPV4M_NODE,
13701 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13702 install_element(BGP_IPV4L_NODE,
13703 &neighbor_addpath_tx_bestpath_per_as_cmd);
13704 install_element(BGP_IPV4L_NODE,
13705 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13706 install_element(BGP_IPV6_NODE,
13707 &neighbor_addpath_tx_bestpath_per_as_cmd);
13708 install_element(BGP_IPV6_NODE,
13709 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13710 install_element(BGP_IPV6M_NODE,
13711 &neighbor_addpath_tx_bestpath_per_as_cmd);
13712 install_element(BGP_IPV6M_NODE,
13713 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13714 install_element(BGP_IPV6L_NODE,
13715 &neighbor_addpath_tx_bestpath_per_as_cmd);
13716 install_element(BGP_IPV6L_NODE,
13717 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13718 install_element(BGP_VPNV4_NODE,
13719 &neighbor_addpath_tx_bestpath_per_as_cmd);
13720 install_element(BGP_VPNV4_NODE,
13721 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13722 install_element(BGP_VPNV6_NODE,
13723 &neighbor_addpath_tx_bestpath_per_as_cmd);
13724 install_element(BGP_VPNV6_NODE,
13725 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13726
13727 /* "neighbor sender-as-path-loop-detection" commands. */
13728 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
13729 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
13730
13731 /* "neighbor passive" commands. */
13732 install_element(BGP_NODE, &neighbor_passive_cmd);
13733 install_element(BGP_NODE, &no_neighbor_passive_cmd);
13734
13735
13736 /* "neighbor shutdown" commands. */
13737 install_element(BGP_NODE, &neighbor_shutdown_cmd);
13738 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
13739 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
13740 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
13741
13742 /* "neighbor capability extended-nexthop" commands.*/
13743 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
13744 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
13745
13746 /* "neighbor capability orf prefix-list" commands.*/
13747 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
13748 install_element(BGP_NODE,
13749 &no_neighbor_capability_orf_prefix_hidden_cmd);
13750 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
13751 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
13752 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
13753 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13754 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
13755 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13756 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
13757 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
13758 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
13759 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13760 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
13761 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13762
13763 /* "neighbor capability dynamic" commands.*/
13764 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
13765 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
13766
13767 /* "neighbor dont-capability-negotiate" commands. */
13768 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
13769 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
13770
13771 /* "neighbor ebgp-multihop" commands. */
13772 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
13773 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
13774 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
13775
13776 /* "neighbor disable-connected-check" commands. */
13777 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
13778 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
13779
13780 /* "neighbor enforce-first-as" commands. */
13781 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
13782 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
13783
13784 /* "neighbor description" commands. */
13785 install_element(BGP_NODE, &neighbor_description_cmd);
13786 install_element(BGP_NODE, &no_neighbor_description_cmd);
13787 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
13788
13789 /* "neighbor update-source" commands. "*/
13790 install_element(BGP_NODE, &neighbor_update_source_cmd);
13791 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
13792
13793 /* "neighbor default-originate" commands. */
13794 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
13795 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
13796 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
13797 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
13798 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
13799 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
13800 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
13801 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
13802 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
13803 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
13804 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
13805 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
13806 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
13807 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
13808 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
13809 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
13810 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
13811 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
13812 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
13813 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
13814 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
13815
13816 /* "neighbor port" commands. */
13817 install_element(BGP_NODE, &neighbor_port_cmd);
13818 install_element(BGP_NODE, &no_neighbor_port_cmd);
13819
13820 /* "neighbor weight" commands. */
13821 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
13822 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
13823
13824 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
13825 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
13826 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
13827 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
13828 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
13829 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
13830 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
13831 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
13832 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
13833 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
13834 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
13835 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
13836 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
13837 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
13838 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
13839 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
13840
13841 /* "neighbor override-capability" commands. */
13842 install_element(BGP_NODE, &neighbor_override_capability_cmd);
13843 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
13844
13845 /* "neighbor strict-capability-match" commands. */
13846 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
13847 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
13848
13849 /* "neighbor timers" commands. */
13850 install_element(BGP_NODE, &neighbor_timers_cmd);
13851 install_element(BGP_NODE, &no_neighbor_timers_cmd);
13852
13853 /* "neighbor timers connect" commands. */
13854 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
13855 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
13856
13857 /* "neighbor advertisement-interval" commands. */
13858 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
13859 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
13860
13861 /* "neighbor interface" commands. */
13862 install_element(BGP_NODE, &neighbor_interface_cmd);
13863 install_element(BGP_NODE, &no_neighbor_interface_cmd);
13864
13865 /* "neighbor distribute" commands. */
13866 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
13867 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
13868 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
13869 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
13870 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
13871 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
13872 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
13873 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
13874 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
13875 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
13876 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
13877 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
13878 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
13879 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
13880 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
13881 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
13882 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
13883 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
13884
13885 /* "neighbor prefix-list" commands. */
13886 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
13887 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
13888 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
13889 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
13890 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
13891 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
13892 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
13893 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
13894 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
13895 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
13896 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
13897 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
13898 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
13899 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
13900 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
13901 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
13902 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
13903 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
13904 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
13905 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
13906 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
13907 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
13908
13909 /* "neighbor filter-list" commands. */
13910 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
13911 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
13912 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
13913 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
13914 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
13915 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
13916 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
13917 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
13918 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
13919 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
13920 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
13921 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
13922 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
13923 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
13924 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
13925 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
13926 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
13927 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
13928 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
13929 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
13930 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
13931 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
13932
13933 /* "neighbor route-map" commands. */
13934 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
13935 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
13936 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
13937 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
13938 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
13939 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
13940 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
13941 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
13942 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
13943 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
13944 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
13945 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
13946 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
13947 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
13948 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
13949 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
13950 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
13951 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
13952 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
13953 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
13954 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
13955 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
13956 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
13957 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
13958
13959 /* "neighbor unsuppress-map" commands. */
13960 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
13961 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
13962 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
13963 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
13964 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
13965 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
13966 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
13967 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
13968 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
13969 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
13970 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
13971 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
13972 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
13973 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
13974 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
13975 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
13976 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
13977 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
13978
13979 /* "neighbor maximum-prefix" commands. */
13980 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
13981 install_element(BGP_NODE,
13982 &neighbor_maximum_prefix_threshold_hidden_cmd);
13983 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
13984 install_element(BGP_NODE,
13985 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
13986 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
13987 install_element(BGP_NODE,
13988 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
13989 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
13990 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
13991 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13992 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13993 install_element(BGP_IPV4_NODE,
13994 &neighbor_maximum_prefix_threshold_warning_cmd);
13995 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13996 install_element(BGP_IPV4_NODE,
13997 &neighbor_maximum_prefix_threshold_restart_cmd);
13998 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
13999 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
14000 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
14001 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
14002 install_element(BGP_IPV4M_NODE,
14003 &neighbor_maximum_prefix_threshold_warning_cmd);
14004 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
14005 install_element(BGP_IPV4M_NODE,
14006 &neighbor_maximum_prefix_threshold_restart_cmd);
14007 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
14008 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
14009 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
14010 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
14011 install_element(BGP_IPV4L_NODE,
14012 &neighbor_maximum_prefix_threshold_warning_cmd);
14013 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
14014 install_element(BGP_IPV4L_NODE,
14015 &neighbor_maximum_prefix_threshold_restart_cmd);
14016 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
14017 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
14018 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
14019 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
14020 install_element(BGP_IPV6_NODE,
14021 &neighbor_maximum_prefix_threshold_warning_cmd);
14022 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
14023 install_element(BGP_IPV6_NODE,
14024 &neighbor_maximum_prefix_threshold_restart_cmd);
14025 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
14026 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
14027 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
14028 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
14029 install_element(BGP_IPV6M_NODE,
14030 &neighbor_maximum_prefix_threshold_warning_cmd);
14031 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
14032 install_element(BGP_IPV6M_NODE,
14033 &neighbor_maximum_prefix_threshold_restart_cmd);
14034 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
14035 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
14036 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
14037 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
14038 install_element(BGP_IPV6L_NODE,
14039 &neighbor_maximum_prefix_threshold_warning_cmd);
14040 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
14041 install_element(BGP_IPV6L_NODE,
14042 &neighbor_maximum_prefix_threshold_restart_cmd);
14043 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
14044 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
14045 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
14046 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
14047 install_element(BGP_VPNV4_NODE,
14048 &neighbor_maximum_prefix_threshold_warning_cmd);
14049 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
14050 install_element(BGP_VPNV4_NODE,
14051 &neighbor_maximum_prefix_threshold_restart_cmd);
14052 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
14053 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
14054 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
14055 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
14056 install_element(BGP_VPNV6_NODE,
14057 &neighbor_maximum_prefix_threshold_warning_cmd);
14058 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
14059 install_element(BGP_VPNV6_NODE,
14060 &neighbor_maximum_prefix_threshold_restart_cmd);
14061 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
14062
14063 /* "neighbor allowas-in" */
14064 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
14065 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
14066 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
14067 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
14068 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
14069 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
14070 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
14071 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
14072 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
14073 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
14074 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
14075 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
14076 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
14077 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
14078 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
14079 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
14080 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
14081 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
14082 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
14083 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
14084
14085 /* address-family commands. */
14086 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
14087 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
14088 #ifdef KEEP_OLD_VPN_COMMANDS
14089 install_element(BGP_NODE, &address_family_vpnv4_cmd);
14090 install_element(BGP_NODE, &address_family_vpnv6_cmd);
14091 #endif /* KEEP_OLD_VPN_COMMANDS */
14092
14093 install_element(BGP_NODE, &address_family_evpn_cmd);
14094
14095 /* "exit-address-family" command. */
14096 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
14097 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
14098 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
14099 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
14100 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
14101 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
14102 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
14103 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
14104 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
14105 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
14106 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
14107
14108 /* "clear ip bgp commands" */
14109 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
14110
14111 /* clear ip bgp prefix */
14112 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
14113 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
14114 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
14115
14116 /* "show [ip] bgp summary" commands. */
14117 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
14118 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
14119 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
14120 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
14121 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
14122 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
14123 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
14124
14125 /* "show [ip] bgp neighbors" commands. */
14126 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
14127
14128 /* "show [ip] bgp peer-group" commands. */
14129 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
14130
14131 /* "show [ip] bgp paths" commands. */
14132 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
14133
14134 /* "show [ip] bgp community" commands. */
14135 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
14136
14137 /* "show ip bgp large-community" commands. */
14138 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
14139 /* "show [ip] bgp attribute-info" commands. */
14140 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
14141 /* "show [ip] bgp route-leak" command */
14142 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
14143
14144 /* "redistribute" commands. */
14145 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
14146 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
14147 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
14148 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
14149 install_element(BGP_NODE,
14150 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
14151 install_element(BGP_NODE,
14152 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
14153 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
14154 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
14155 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
14156 install_element(BGP_NODE,
14157 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
14158 install_element(BGP_NODE,
14159 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
14160 install_element(BGP_NODE,
14161 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
14162 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
14163 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
14164 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
14165 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
14166 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
14167 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
14168 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
14169 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
14170 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
14171 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
14172 install_element(BGP_IPV4_NODE,
14173 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
14174 install_element(BGP_IPV4_NODE,
14175 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
14176 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
14177 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
14178 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
14179 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
14180 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
14181 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
14182
14183 /* import|export vpn [route-map WORD] */
14184 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
14185 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
14186
14187 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
14188 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
14189
14190 /* ttl_security commands */
14191 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
14192 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
14193
14194 /* "show [ip] bgp memory" commands. */
14195 install_element(VIEW_NODE, &show_bgp_memory_cmd);
14196
14197 /* "show bgp martian next-hop" */
14198 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
14199
14200 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
14201
14202 /* "show [ip] bgp views" commands. */
14203 install_element(VIEW_NODE, &show_bgp_views_cmd);
14204
14205 /* "show [ip] bgp vrfs" commands. */
14206 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
14207
14208 /* Community-list. */
14209 community_list_vty();
14210
14211 /* vpn-policy commands */
14212 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
14213 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
14214 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
14215 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
14216 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
14217 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
14218 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
14219 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
14220 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
14221 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
14222 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
14223 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
14224
14225 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
14226 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
14227
14228 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
14229 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
14230 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
14231 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
14232 install_element(BGP_IPV4_NODE, &af_no_nexthop_vpn_export_cmd);
14233 install_element(BGP_IPV6_NODE, &af_no_nexthop_vpn_export_cmd);
14234 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
14235 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
14236 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
14237 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
14238 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
14239 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
14240 }
14241
14242 #include "memory.h"
14243 #include "bgp_regex.h"
14244 #include "bgp_clist.h"
14245 #include "bgp_ecommunity.h"
14246
14247 /* VTY functions. */
14248
14249 /* Direction value to string conversion. */
14250 static const char *community_direct_str(int direct)
14251 {
14252 switch (direct) {
14253 case COMMUNITY_DENY:
14254 return "deny";
14255 case COMMUNITY_PERMIT:
14256 return "permit";
14257 default:
14258 return "unknown";
14259 }
14260 }
14261
14262 /* Display error string. */
14263 static void community_list_perror(struct vty *vty, int ret)
14264 {
14265 switch (ret) {
14266 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
14267 vty_out(vty, "%% Can't find community-list\n");
14268 break;
14269 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
14270 vty_out(vty, "%% Malformed community-list value\n");
14271 break;
14272 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
14273 vty_out(vty,
14274 "%% Community name conflict, previously defined as standard community\n");
14275 break;
14276 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
14277 vty_out(vty,
14278 "%% Community name conflict, previously defined as expanded community\n");
14279 break;
14280 }
14281 }
14282
14283 /* "community-list" keyword help string. */
14284 #define COMMUNITY_LIST_STR "Add a community list entry\n"
14285
14286 /*community-list standard */
14287 DEFUN (community_list_standard,
14288 bgp_community_list_standard_cmd,
14289 "bgp community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14290 BGP_STR
14291 COMMUNITY_LIST_STR
14292 "Community list number (standard)\n"
14293 "Add an standard community-list entry\n"
14294 "Community list name\n"
14295 "Specify community to reject\n"
14296 "Specify community to accept\n"
14297 COMMUNITY_VAL_STR)
14298 {
14299 char *cl_name_or_number = NULL;
14300 int direct = 0;
14301 int style = COMMUNITY_LIST_STANDARD;
14302 int idx = 0;
14303
14304 argv_find(argv, argc, "(1-99)", &idx);
14305 argv_find(argv, argc, "WORD", &idx);
14306 cl_name_or_number = argv[idx]->arg;
14307 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14308 : COMMUNITY_DENY;
14309 argv_find(argv, argc, "AA:NN", &idx);
14310 char *str = argv_concat(argv, argc, idx);
14311
14312 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
14313 style);
14314
14315 XFREE(MTYPE_TMP, str);
14316
14317 if (ret < 0) {
14318 /* Display error string. */
14319 community_list_perror(vty, ret);
14320 return CMD_WARNING_CONFIG_FAILED;
14321 }
14322
14323 return CMD_SUCCESS;
14324 }
14325
14326 DEFUN (no_community_list_standard_all,
14327 no_bgp_community_list_standard_all_cmd,
14328 "no bgp community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14329 NO_STR
14330 BGP_STR
14331 COMMUNITY_LIST_STR
14332 "Community list number (standard)\n"
14333 "Add an standard community-list entry\n"
14334 "Community list name\n"
14335 "Specify community to reject\n"
14336 "Specify community to accept\n"
14337 COMMUNITY_VAL_STR)
14338 {
14339 char *cl_name_or_number = NULL;
14340 char *str = NULL;
14341 int direct = 0;
14342 int style = COMMUNITY_LIST_STANDARD;
14343
14344 int idx = 0;
14345
14346 argv_find(argv, argc, "permit", &idx);
14347 argv_find(argv, argc, "deny", &idx);
14348
14349 if (idx) {
14350 direct = argv_find(argv, argc, "permit", &idx)
14351 ? COMMUNITY_PERMIT
14352 : COMMUNITY_DENY;
14353
14354 idx = 0;
14355 argv_find(argv, argc, "AA:NN", &idx);
14356 str = argv_concat(argv, argc, idx);
14357 }
14358
14359 idx = 0;
14360 argv_find(argv, argc, "(1-99)", &idx);
14361 argv_find(argv, argc, "WORD", &idx);
14362 cl_name_or_number = argv[idx]->arg;
14363
14364 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
14365 direct, style);
14366
14367 XFREE(MTYPE_TMP, str);
14368
14369 if (ret < 0) {
14370 community_list_perror(vty, ret);
14371 return CMD_WARNING_CONFIG_FAILED;
14372 }
14373
14374 return CMD_SUCCESS;
14375 }
14376
14377 ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
14378 "no bgp community-list <(1-99)|standard WORD>",
14379 NO_STR BGP_STR COMMUNITY_LIST_STR
14380 "Community list number (standard)\n"
14381 "Add an standard community-list entry\n"
14382 "Community list name\n")
14383
14384 /*community-list expanded */
14385 DEFUN (community_list_expanded_all,
14386 bgp_community_list_expanded_all_cmd,
14387 "bgp community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14388 BGP_STR
14389 COMMUNITY_LIST_STR
14390 "Community list number (expanded)\n"
14391 "Add an expanded community-list entry\n"
14392 "Community list name\n"
14393 "Specify community to reject\n"
14394 "Specify community to accept\n"
14395 COMMUNITY_VAL_STR)
14396 {
14397 char *cl_name_or_number = NULL;
14398 int direct = 0;
14399 int style = COMMUNITY_LIST_EXPANDED;
14400
14401 int idx = 0;
14402
14403 argv_find(argv, argc, "(100-500)", &idx);
14404 argv_find(argv, argc, "WORD", &idx);
14405 cl_name_or_number = argv[idx]->arg;
14406 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14407 : COMMUNITY_DENY;
14408 argv_find(argv, argc, "AA:NN", &idx);
14409 char *str = argv_concat(argv, argc, idx);
14410
14411 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
14412 style);
14413
14414 XFREE(MTYPE_TMP, str);
14415
14416 if (ret < 0) {
14417 /* Display error string. */
14418 community_list_perror(vty, ret);
14419 return CMD_WARNING_CONFIG_FAILED;
14420 }
14421
14422 return CMD_SUCCESS;
14423 }
14424
14425 DEFUN (no_community_list_expanded_all,
14426 no_bgp_community_list_expanded_all_cmd,
14427 "no bgp community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14428 NO_STR
14429 BGP_STR
14430 COMMUNITY_LIST_STR
14431 "Community list number (expanded)\n"
14432 "Add an expanded community-list entry\n"
14433 "Community list name\n"
14434 "Specify community to reject\n"
14435 "Specify community to accept\n"
14436 COMMUNITY_VAL_STR)
14437 {
14438 char *cl_name_or_number = NULL;
14439 char *str = NULL;
14440 int direct = 0;
14441 int style = COMMUNITY_LIST_EXPANDED;
14442
14443 int idx = 0;
14444
14445 argv_find(argv, argc, "permit", &idx);
14446 argv_find(argv, argc, "deny", &idx);
14447
14448 if (idx) {
14449 direct = argv_find(argv, argc, "permit", &idx)
14450 ? COMMUNITY_PERMIT
14451 : COMMUNITY_DENY;
14452
14453 idx = 0;
14454 argv_find(argv, argc, "AA:NN", &idx);
14455 str = argv_concat(argv, argc, idx);
14456 }
14457
14458 idx = 0;
14459 argv_find(argv, argc, "(100-500)", &idx);
14460 argv_find(argv, argc, "WORD", &idx);
14461 cl_name_or_number = argv[idx]->arg;
14462
14463 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
14464 direct, style);
14465
14466 XFREE(MTYPE_TMP, str);
14467
14468 if (ret < 0) {
14469 community_list_perror(vty, ret);
14470 return CMD_WARNING_CONFIG_FAILED;
14471 }
14472
14473 return CMD_SUCCESS;
14474 }
14475
14476 ALIAS(no_community_list_expanded_all, no_bgp_community_list_expanded_all_list_cmd,
14477 "no bgp community-list <(100-500)|expanded WORD>",
14478 NO_STR IP_STR COMMUNITY_LIST_STR
14479 "Community list number (expanded)\n"
14480 "Add an expanded community-list entry\n"
14481 "Community list name\n")
14482
14483 /* Return configuration string of community-list entry. */
14484 static const char *community_list_config_str(struct community_entry *entry)
14485 {
14486 const char *str;
14487
14488 if (entry->any)
14489 str = "";
14490 else {
14491 if (entry->style == COMMUNITY_LIST_STANDARD)
14492 str = community_str(entry->u.com, false);
14493 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
14494 str = lcommunity_str(entry->u.lcom, false);
14495 else
14496 str = entry->config;
14497 }
14498 return str;
14499 }
14500
14501 static void community_list_show(struct vty *vty, struct community_list *list)
14502 {
14503 struct community_entry *entry;
14504
14505 for (entry = list->head; entry; entry = entry->next) {
14506 if (entry == list->head) {
14507 if (all_digit(list->name))
14508 vty_out(vty, "Community %s list %s\n",
14509 entry->style == COMMUNITY_LIST_STANDARD
14510 ? "standard"
14511 : "(expanded) access",
14512 list->name);
14513 else
14514 vty_out(vty, "Named Community %s list %s\n",
14515 entry->style == COMMUNITY_LIST_STANDARD
14516 ? "standard"
14517 : "expanded",
14518 list->name);
14519 }
14520 if (entry->any)
14521 vty_out(vty, " %s\n",
14522 community_direct_str(entry->direct));
14523 else
14524 vty_out(vty, " %s %s\n",
14525 community_direct_str(entry->direct),
14526 community_list_config_str(entry));
14527 }
14528 }
14529
14530 DEFUN (show_community_list,
14531 show_bgp_community_list_cmd,
14532 "show bgp community-list",
14533 SHOW_STR
14534 BGP_STR
14535 "List community-list\n")
14536 {
14537 struct community_list *list;
14538 struct community_list_master *cm;
14539
14540 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
14541 if (!cm)
14542 return CMD_SUCCESS;
14543
14544 for (list = cm->num.head; list; list = list->next)
14545 community_list_show(vty, list);
14546
14547 for (list = cm->str.head; list; list = list->next)
14548 community_list_show(vty, list);
14549
14550 return CMD_SUCCESS;
14551 }
14552
14553 DEFUN (show_community_list_arg,
14554 show_bgp_community_list_arg_cmd,
14555 "show bgp community-list <(1-500)|WORD> detail",
14556 SHOW_STR
14557 BGP_STR
14558 "List community-list\n"
14559 "Community-list number\n"
14560 "Community-list name\n"
14561 "Detailed information on community-list\n")
14562 {
14563 int idx_comm_list = 3;
14564 struct community_list *list;
14565
14566 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
14567 COMMUNITY_LIST_MASTER);
14568 if (!list) {
14569 vty_out(vty, "%% Can't find community-list\n");
14570 return CMD_WARNING;
14571 }
14572
14573 community_list_show(vty, list);
14574
14575 return CMD_SUCCESS;
14576 }
14577
14578 /*
14579 * Large Community code.
14580 */
14581 static int lcommunity_list_set_vty(struct vty *vty, int argc,
14582 struct cmd_token **argv, int style,
14583 int reject_all_digit_name)
14584 {
14585 int ret;
14586 int direct;
14587 char *str;
14588 int idx = 0;
14589 char *cl_name;
14590
14591 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14592 : COMMUNITY_DENY;
14593
14594 /* All digit name check. */
14595 idx = 0;
14596 argv_find(argv, argc, "WORD", &idx);
14597 argv_find(argv, argc, "(1-99)", &idx);
14598 argv_find(argv, argc, "(100-500)", &idx);
14599 cl_name = argv[idx]->arg;
14600 if (reject_all_digit_name && all_digit(cl_name)) {
14601 vty_out(vty, "%% Community name cannot have all digits\n");
14602 return CMD_WARNING_CONFIG_FAILED;
14603 }
14604
14605 idx = 0;
14606 argv_find(argv, argc, "AA:BB:CC", &idx);
14607 argv_find(argv, argc, "LINE", &idx);
14608 /* Concat community string argument. */
14609 if (idx)
14610 str = argv_concat(argv, argc, idx);
14611 else
14612 str = NULL;
14613
14614 ret = lcommunity_list_set(bgp_clist, cl_name, str, direct, style);
14615
14616 /* Free temporary community list string allocated by
14617 argv_concat(). */
14618 XFREE(MTYPE_TMP, str);
14619
14620 if (ret < 0) {
14621 community_list_perror(vty, ret);
14622 return CMD_WARNING_CONFIG_FAILED;
14623 }
14624 return CMD_SUCCESS;
14625 }
14626
14627 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
14628 struct cmd_token **argv, int style)
14629 {
14630 int ret;
14631 int direct = 0;
14632 char *str = NULL;
14633 int idx = 0;
14634
14635 argv_find(argv, argc, "permit", &idx);
14636 argv_find(argv, argc, "deny", &idx);
14637
14638 if (idx) {
14639 /* Check the list direct. */
14640 if (strncmp(argv[idx]->arg, "p", 1) == 0)
14641 direct = COMMUNITY_PERMIT;
14642 else
14643 direct = COMMUNITY_DENY;
14644
14645 idx = 0;
14646 argv_find(argv, argc, "LINE", &idx);
14647 argv_find(argv, argc, "AA:AA:NN", &idx);
14648 /* Concat community string argument. */
14649 str = argv_concat(argv, argc, idx);
14650 }
14651
14652 idx = 0;
14653 argv_find(argv, argc, "(1-99)", &idx);
14654 argv_find(argv, argc, "(100-500)", &idx);
14655 argv_find(argv, argc, "WORD", &idx);
14656
14657 /* Unset community list. */
14658 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, direct,
14659 style);
14660
14661 /* Free temporary community list string allocated by
14662 argv_concat(). */
14663 XFREE(MTYPE_TMP, str);
14664
14665 if (ret < 0) {
14666 community_list_perror(vty, ret);
14667 return CMD_WARNING_CONFIG_FAILED;
14668 }
14669
14670 return CMD_SUCCESS;
14671 }
14672
14673 /* "large-community-list" keyword help string. */
14674 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
14675 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
14676
14677 DEFUN (lcommunity_list_standard,
14678 bgp_lcommunity_list_standard_cmd,
14679 "bgp large-community-list (1-99) <deny|permit> AA:BB:CC...",
14680 BGP_STR
14681 LCOMMUNITY_LIST_STR
14682 "Large Community list number (standard)\n"
14683 "Specify large community to reject\n"
14684 "Specify large community to accept\n"
14685 LCOMMUNITY_VAL_STR)
14686 {
14687 return lcommunity_list_set_vty(vty, argc, argv,
14688 LARGE_COMMUNITY_LIST_STANDARD, 0);
14689 }
14690
14691 DEFUN (lcommunity_list_expanded,
14692 bgp_lcommunity_list_expanded_cmd,
14693 "bgp large-community-list (100-500) <deny|permit> LINE...",
14694 BGP_STR
14695 LCOMMUNITY_LIST_STR
14696 "Large Community list number (expanded)\n"
14697 "Specify large community to reject\n"
14698 "Specify large community to accept\n"
14699 "An ordered list as a regular-expression\n")
14700 {
14701 return lcommunity_list_set_vty(vty, argc, argv,
14702 LARGE_COMMUNITY_LIST_EXPANDED, 0);
14703 }
14704
14705 DEFUN (lcommunity_list_name_standard,
14706 bgp_lcommunity_list_name_standard_cmd,
14707 "bgp large-community-list standard WORD <deny|permit> AA:BB:CC...",
14708 BGP_STR
14709 LCOMMUNITY_LIST_STR
14710 "Specify standard large-community-list\n"
14711 "Large Community list name\n"
14712 "Specify large community to reject\n"
14713 "Specify large community to accept\n"
14714 LCOMMUNITY_VAL_STR)
14715 {
14716 return lcommunity_list_set_vty(vty, argc, argv,
14717 LARGE_COMMUNITY_LIST_STANDARD, 1);
14718 }
14719
14720 DEFUN (lcommunity_list_name_expanded,
14721 bgp_lcommunity_list_name_expanded_cmd,
14722 "bgp large-community-list expanded WORD <deny|permit> LINE...",
14723 BGP_STR
14724 LCOMMUNITY_LIST_STR
14725 "Specify expanded large-community-list\n"
14726 "Large Community list name\n"
14727 "Specify large community to reject\n"
14728 "Specify large community to accept\n"
14729 "An ordered list as a regular-expression\n")
14730 {
14731 return lcommunity_list_set_vty(vty, argc, argv,
14732 LARGE_COMMUNITY_LIST_EXPANDED, 1);
14733 }
14734
14735 DEFUN (no_lcommunity_list_standard_all,
14736 no_bgp_lcommunity_list_standard_all_cmd,
14737 "no bgp large-community-list <(1-99)|(100-500)|WORD>",
14738 NO_STR
14739 BGP_STR
14740 LCOMMUNITY_LIST_STR
14741 "Large Community list number (standard)\n"
14742 "Large Community list number (expanded)\n"
14743 "Large Community list name\n")
14744 {
14745 return lcommunity_list_unset_vty(vty, argc, argv,
14746 LARGE_COMMUNITY_LIST_STANDARD);
14747 }
14748
14749 DEFUN (no_lcommunity_list_name_expanded_all,
14750 no_bgp_lcommunity_list_name_expanded_all_cmd,
14751 "no bgp large-community-list expanded WORD",
14752 NO_STR
14753 BGP_STR
14754 LCOMMUNITY_LIST_STR
14755 "Specify expanded large-community-list\n"
14756 "Large Community list name\n")
14757 {
14758 return lcommunity_list_unset_vty(vty, argc, argv,
14759 LARGE_COMMUNITY_LIST_EXPANDED);
14760 }
14761
14762 DEFUN (no_lcommunity_list_standard,
14763 no_bgp_lcommunity_list_standard_cmd,
14764 "no bgp large-community-list (1-99) <deny|permit> AA:AA:NN...",
14765 NO_STR
14766 BGP_STR
14767 LCOMMUNITY_LIST_STR
14768 "Large Community list number (standard)\n"
14769 "Specify large community to reject\n"
14770 "Specify large community to accept\n"
14771 LCOMMUNITY_VAL_STR)
14772 {
14773 return lcommunity_list_unset_vty(vty, argc, argv,
14774 LARGE_COMMUNITY_LIST_STANDARD);
14775 }
14776
14777 DEFUN (no_lcommunity_list_expanded,
14778 no_bgp_lcommunity_list_expanded_cmd,
14779 "no bgp large-community-list (100-500) <deny|permit> LINE...",
14780 NO_STR
14781 BGP_STR
14782 LCOMMUNITY_LIST_STR
14783 "Large Community list number (expanded)\n"
14784 "Specify large community to reject\n"
14785 "Specify large community to accept\n"
14786 "An ordered list as a regular-expression\n")
14787 {
14788 return lcommunity_list_unset_vty(vty, argc, argv,
14789 LARGE_COMMUNITY_LIST_EXPANDED);
14790 }
14791
14792 DEFUN (no_lcommunity_list_name_standard,
14793 no_bgp_lcommunity_list_name_standard_cmd,
14794 "no bgp large-community-list standard WORD <deny|permit> AA:AA:NN...",
14795 NO_STR
14796 BGP_STR
14797 LCOMMUNITY_LIST_STR
14798 "Specify standard large-community-list\n"
14799 "Large Community list name\n"
14800 "Specify large community to reject\n"
14801 "Specify large community to accept\n"
14802 LCOMMUNITY_VAL_STR)
14803 {
14804 return lcommunity_list_unset_vty(vty, argc, argv,
14805 LARGE_COMMUNITY_LIST_STANDARD);
14806 }
14807
14808 DEFUN (no_lcommunity_list_name_expanded,
14809 no_bgp_lcommunity_list_name_expanded_cmd,
14810 "no bgp large-community-list expanded WORD <deny|permit> LINE...",
14811 NO_STR
14812 BGP_STR
14813 LCOMMUNITY_LIST_STR
14814 "Specify expanded large-community-list\n"
14815 "Large community list name\n"
14816 "Specify large community to reject\n"
14817 "Specify large community to accept\n"
14818 "An ordered list as a regular-expression\n")
14819 {
14820 return lcommunity_list_unset_vty(vty, argc, argv,
14821 LARGE_COMMUNITY_LIST_EXPANDED);
14822 }
14823
14824 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
14825 {
14826 struct community_entry *entry;
14827
14828 for (entry = list->head; entry; entry = entry->next) {
14829 if (entry == list->head) {
14830 if (all_digit(list->name))
14831 vty_out(vty, "Large community %s list %s\n",
14832 entry->style ==
14833 LARGE_COMMUNITY_LIST_STANDARD
14834 ? "standard"
14835 : "(expanded) access",
14836 list->name);
14837 else
14838 vty_out(vty,
14839 "Named large community %s list %s\n",
14840 entry->style ==
14841 LARGE_COMMUNITY_LIST_STANDARD
14842 ? "standard"
14843 : "expanded",
14844 list->name);
14845 }
14846 if (entry->any)
14847 vty_out(vty, " %s\n",
14848 community_direct_str(entry->direct));
14849 else
14850 vty_out(vty, " %s %s\n",
14851 community_direct_str(entry->direct),
14852 community_list_config_str(entry));
14853 }
14854 }
14855
14856 DEFUN (show_lcommunity_list,
14857 show_bgp_lcommunity_list_cmd,
14858 "show bgp large-community-list",
14859 SHOW_STR
14860 BGP_STR
14861 "List large-community list\n")
14862 {
14863 struct community_list *list;
14864 struct community_list_master *cm;
14865
14866 cm = community_list_master_lookup(bgp_clist,
14867 LARGE_COMMUNITY_LIST_MASTER);
14868 if (!cm)
14869 return CMD_SUCCESS;
14870
14871 for (list = cm->num.head; list; list = list->next)
14872 lcommunity_list_show(vty, list);
14873
14874 for (list = cm->str.head; list; list = list->next)
14875 lcommunity_list_show(vty, list);
14876
14877 return CMD_SUCCESS;
14878 }
14879
14880 DEFUN (show_lcommunity_list_arg,
14881 show_bgp_lcommunity_list_arg_cmd,
14882 "show bgp large-community-list <(1-500)|WORD> detail",
14883 SHOW_STR
14884 BGP_STR
14885 "List large-community list\n"
14886 "Large-community-list number\n"
14887 "Large-community-list name\n"
14888 "Detailed information on large-community-list\n")
14889 {
14890 struct community_list *list;
14891
14892 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
14893 LARGE_COMMUNITY_LIST_MASTER);
14894 if (!list) {
14895 vty_out(vty, "%% Can't find large-community-list\n");
14896 return CMD_WARNING;
14897 }
14898
14899 lcommunity_list_show(vty, list);
14900
14901 return CMD_SUCCESS;
14902 }
14903
14904 /* "extcommunity-list" keyword help string. */
14905 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
14906 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
14907
14908 DEFUN (extcommunity_list_standard,
14909 bgp_extcommunity_list_standard_cmd,
14910 "bgp extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14911 BGP_STR
14912 EXTCOMMUNITY_LIST_STR
14913 "Extended Community list number (standard)\n"
14914 "Specify standard extcommunity-list\n"
14915 "Community list name\n"
14916 "Specify community to reject\n"
14917 "Specify community to accept\n"
14918 EXTCOMMUNITY_VAL_STR)
14919 {
14920 int style = EXTCOMMUNITY_LIST_STANDARD;
14921 int direct = 0;
14922 char *cl_number_or_name = NULL;
14923
14924 int idx = 0;
14925
14926 argv_find(argv, argc, "(1-99)", &idx);
14927 argv_find(argv, argc, "WORD", &idx);
14928 cl_number_or_name = argv[idx]->arg;
14929 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14930 : COMMUNITY_DENY;
14931 argv_find(argv, argc, "AA:NN", &idx);
14932 char *str = argv_concat(argv, argc, idx);
14933
14934 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
14935 direct, style);
14936
14937 XFREE(MTYPE_TMP, str);
14938
14939 if (ret < 0) {
14940 community_list_perror(vty, ret);
14941 return CMD_WARNING_CONFIG_FAILED;
14942 }
14943
14944 return CMD_SUCCESS;
14945 }
14946
14947 DEFUN (extcommunity_list_name_expanded,
14948 bgp_extcommunity_list_name_expanded_cmd,
14949 "bgp extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
14950 BGP_STR
14951 EXTCOMMUNITY_LIST_STR
14952 "Extended Community list number (expanded)\n"
14953 "Specify expanded extcommunity-list\n"
14954 "Extended Community list name\n"
14955 "Specify community to reject\n"
14956 "Specify community to accept\n"
14957 "An ordered list as a regular-expression\n")
14958 {
14959 int style = EXTCOMMUNITY_LIST_EXPANDED;
14960 int direct = 0;
14961 char *cl_number_or_name = NULL;
14962 int idx = 0;
14963
14964 argv_find(argv, argc, "(100-500)", &idx);
14965 argv_find(argv, argc, "WORD", &idx);
14966 cl_number_or_name = argv[idx]->arg;
14967 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14968 : COMMUNITY_DENY;
14969 argv_find(argv, argc, "LINE", &idx);
14970 char *str = argv_concat(argv, argc, idx);
14971
14972 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
14973 direct, style);
14974
14975 XFREE(MTYPE_TMP, str);
14976
14977 if (ret < 0) {
14978 community_list_perror(vty, ret);
14979 return CMD_WARNING_CONFIG_FAILED;
14980 }
14981
14982 return CMD_SUCCESS;
14983 }
14984
14985 DEFUN (no_extcommunity_list_standard_all,
14986 no_bgp_extcommunity_list_standard_all_cmd,
14987 "no bgp extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14988 NO_STR
14989 BGP_STR
14990 EXTCOMMUNITY_LIST_STR
14991 "Extended Community list number (standard)\n"
14992 "Specify standard extcommunity-list\n"
14993 "Community list name\n"
14994 "Specify community to reject\n"
14995 "Specify community to accept\n"
14996 EXTCOMMUNITY_VAL_STR)
14997 {
14998 int style = EXTCOMMUNITY_LIST_STANDARD;
14999 int direct = 0;
15000 char *cl_number_or_name = NULL;
15001 char *str = NULL;
15002 int idx = 0;
15003
15004 argv_find(argv, argc, "permit", &idx);
15005 argv_find(argv, argc, "deny", &idx);
15006
15007 if (idx) {
15008 direct = argv_find(argv, argc, "permit", &idx)
15009 ? COMMUNITY_PERMIT
15010 : COMMUNITY_DENY;
15011
15012 idx = 0;
15013 argv_find(argv, argc, "AA:NN", &idx);
15014 str = argv_concat(argv, argc, idx);
15015 }
15016
15017 idx = 0;
15018 argv_find(argv, argc, "(1-99)", &idx);
15019 argv_find(argv, argc, "WORD", &idx);
15020 cl_number_or_name = argv[idx]->arg;
15021
15022 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
15023 direct, style);
15024
15025 XFREE(MTYPE_TMP, str);
15026
15027 if (ret < 0) {
15028 community_list_perror(vty, ret);
15029 return CMD_WARNING_CONFIG_FAILED;
15030 }
15031
15032 return CMD_SUCCESS;
15033 }
15034
15035 ALIAS(no_extcommunity_list_standard_all,
15036 no_bgp_extcommunity_list_standard_all_list_cmd,
15037 "no bgp extcommunity-list <(1-99)|standard WORD>",
15038 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15039 "Extended Community list number (standard)\n"
15040 "Specify standard extcommunity-list\n"
15041 "Community list name\n")
15042
15043 DEFUN (no_extcommunity_list_expanded_all,
15044 no_bgp_extcommunity_list_expanded_all_cmd,
15045 "no bgp extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15046 NO_STR
15047 BGP_STR
15048 EXTCOMMUNITY_LIST_STR
15049 "Extended Community list number (expanded)\n"
15050 "Specify expanded extcommunity-list\n"
15051 "Extended Community list name\n"
15052 "Specify community to reject\n"
15053 "Specify community to accept\n"
15054 "An ordered list as a regular-expression\n")
15055 {
15056 int style = EXTCOMMUNITY_LIST_EXPANDED;
15057 int direct = 0;
15058 char *cl_number_or_name = NULL;
15059 char *str = NULL;
15060 int idx = 0;
15061
15062 argv_find(argv, argc, "permit", &idx);
15063 argv_find(argv, argc, "deny", &idx);
15064
15065 if (idx) {
15066 direct = argv_find(argv, argc, "permit", &idx)
15067 ? COMMUNITY_PERMIT
15068 : COMMUNITY_DENY;
15069
15070 idx = 0;
15071 argv_find(argv, argc, "LINE", &idx);
15072 str = argv_concat(argv, argc, idx);
15073 }
15074
15075 idx = 0;
15076 argv_find(argv, argc, "(100-500)", &idx);
15077 argv_find(argv, argc, "WORD", &idx);
15078 cl_number_or_name = argv[idx]->arg;
15079
15080 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
15081 direct, style);
15082
15083 XFREE(MTYPE_TMP, str);
15084
15085 if (ret < 0) {
15086 community_list_perror(vty, ret);
15087 return CMD_WARNING_CONFIG_FAILED;
15088 }
15089
15090 return CMD_SUCCESS;
15091 }
15092
15093 ALIAS(no_extcommunity_list_expanded_all,
15094 no_bgp_extcommunity_list_expanded_all_list_cmd,
15095 "no bgp extcommunity-list <(100-500)|expanded WORD>",
15096 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15097 "Extended Community list number (expanded)\n"
15098 "Specify expanded extcommunity-list\n"
15099 "Extended Community list name\n")
15100
15101 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
15102 {
15103 struct community_entry *entry;
15104
15105 for (entry = list->head; entry; entry = entry->next) {
15106 if (entry == list->head) {
15107 if (all_digit(list->name))
15108 vty_out(vty, "Extended community %s list %s\n",
15109 entry->style == EXTCOMMUNITY_LIST_STANDARD
15110 ? "standard"
15111 : "(expanded) access",
15112 list->name);
15113 else
15114 vty_out(vty,
15115 "Named extended community %s list %s\n",
15116 entry->style == EXTCOMMUNITY_LIST_STANDARD
15117 ? "standard"
15118 : "expanded",
15119 list->name);
15120 }
15121 if (entry->any)
15122 vty_out(vty, " %s\n",
15123 community_direct_str(entry->direct));
15124 else
15125 vty_out(vty, " %s %s\n",
15126 community_direct_str(entry->direct),
15127 community_list_config_str(entry));
15128 }
15129 }
15130
15131 DEFUN (show_extcommunity_list,
15132 show_bgp_extcommunity_list_cmd,
15133 "show bgp extcommunity-list",
15134 SHOW_STR
15135 BGP_STR
15136 "List extended-community list\n")
15137 {
15138 struct community_list *list;
15139 struct community_list_master *cm;
15140
15141 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
15142 if (!cm)
15143 return CMD_SUCCESS;
15144
15145 for (list = cm->num.head; list; list = list->next)
15146 extcommunity_list_show(vty, list);
15147
15148 for (list = cm->str.head; list; list = list->next)
15149 extcommunity_list_show(vty, list);
15150
15151 return CMD_SUCCESS;
15152 }
15153
15154 DEFUN (show_extcommunity_list_arg,
15155 show_bgp_extcommunity_list_arg_cmd,
15156 "show bgp extcommunity-list <(1-500)|WORD> detail",
15157 SHOW_STR
15158 BGP_STR
15159 "List extended-community list\n"
15160 "Extcommunity-list number\n"
15161 "Extcommunity-list name\n"
15162 "Detailed information on extcommunity-list\n")
15163 {
15164 int idx_comm_list = 3;
15165 struct community_list *list;
15166
15167 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
15168 EXTCOMMUNITY_LIST_MASTER);
15169 if (!list) {
15170 vty_out(vty, "%% Can't find extcommunity-list\n");
15171 return CMD_WARNING;
15172 }
15173
15174 extcommunity_list_show(vty, list);
15175
15176 return CMD_SUCCESS;
15177 }
15178
15179 /* Display community-list and extcommunity-list configuration. */
15180 static int community_list_config_write(struct vty *vty)
15181 {
15182 struct community_list *list;
15183 struct community_entry *entry;
15184 struct community_list_master *cm;
15185 int write = 0;
15186
15187 /* Community-list. */
15188 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
15189
15190 for (list = cm->num.head; list; list = list->next)
15191 for (entry = list->head; entry; entry = entry->next) {
15192 vty_out(vty, "bgp community-list %s %s %s\n", list->name,
15193 community_direct_str(entry->direct),
15194 community_list_config_str(entry));
15195 write++;
15196 }
15197 for (list = cm->str.head; list; list = list->next)
15198 for (entry = list->head; entry; entry = entry->next) {
15199 vty_out(vty, "bgp community-list %s %s %s %s\n",
15200 entry->style == COMMUNITY_LIST_STANDARD
15201 ? "standard"
15202 : "expanded",
15203 list->name, community_direct_str(entry->direct),
15204 community_list_config_str(entry));
15205 write++;
15206 }
15207
15208 /* Extcommunity-list. */
15209 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
15210
15211 for (list = cm->num.head; list; list = list->next)
15212 for (entry = list->head; entry; entry = entry->next) {
15213 vty_out(vty, "bgp extcommunity-list %s %s %s\n",
15214 list->name, community_direct_str(entry->direct),
15215 community_list_config_str(entry));
15216 write++;
15217 }
15218 for (list = cm->str.head; list; list = list->next)
15219 for (entry = list->head; entry; entry = entry->next) {
15220 vty_out(vty, "bgp extcommunity-list %s %s %s %s\n",
15221 entry->style == EXTCOMMUNITY_LIST_STANDARD
15222 ? "standard"
15223 : "expanded",
15224 list->name, community_direct_str(entry->direct),
15225 community_list_config_str(entry));
15226 write++;
15227 }
15228
15229
15230 /* lcommunity-list. */
15231 cm = community_list_master_lookup(bgp_clist,
15232 LARGE_COMMUNITY_LIST_MASTER);
15233
15234 for (list = cm->num.head; list; list = list->next)
15235 for (entry = list->head; entry; entry = entry->next) {
15236 vty_out(vty, "bgp large-community-list %s %s %s\n",
15237 list->name, community_direct_str(entry->direct),
15238 community_list_config_str(entry));
15239 write++;
15240 }
15241 for (list = cm->str.head; list; list = list->next)
15242 for (entry = list->head; entry; entry = entry->next) {
15243 vty_out(vty, "bgp large-community-list %s %s %s %s\n",
15244 entry->style == LARGE_COMMUNITY_LIST_STANDARD
15245 ? "standard"
15246 : "expanded",
15247 list->name, community_direct_str(entry->direct),
15248 community_list_config_str(entry));
15249 write++;
15250 }
15251
15252 return write;
15253 }
15254
15255 static struct cmd_node community_list_node = {
15256 COMMUNITY_LIST_NODE, "", 1 /* Export to vtysh. */
15257 };
15258
15259 static void community_list_vty(void)
15260 {
15261 install_node(&community_list_node, community_list_config_write);
15262
15263 /* Community-list. */
15264 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
15265 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
15266 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
15267 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
15268 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
15269 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
15270 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
15271 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
15272
15273 /* Extcommunity-list. */
15274 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
15275 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
15276 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
15277 install_element(CONFIG_NODE,
15278 &no_bgp_extcommunity_list_standard_all_list_cmd);
15279 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
15280 install_element(CONFIG_NODE,
15281 &no_bgp_extcommunity_list_expanded_all_list_cmd);
15282 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
15283 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
15284
15285 /* Large Community List */
15286 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
15287 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
15288 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
15289 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
15290 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_all_cmd);
15291 install_element(CONFIG_NODE,
15292 &no_bgp_lcommunity_list_name_expanded_all_cmd);
15293 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
15294 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
15295 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
15296 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
15297 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
15298 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
15299 }