]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
bgpd: Reject routes having AS_SET or AS_CONFED_SET
[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 DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd,
1925 "bgp reject-as-sets",
1926 "BGP specific commands\n"
1927 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
1928 {
1929 VTY_DECLVAR_CONTEXT(bgp, bgp);
1930 struct listnode *node, *nnode;
1931 struct peer *peer;
1932
1933 bgp->reject_as_sets = BGP_REJECT_AS_SETS_ENABLED;
1934
1935 /* Reset existing BGP sessions to reject routes
1936 * with aspath containing AS_SET or AS_CONFED_SET.
1937 */
1938 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1939 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
1940 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
1941 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
1942 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
1943 }
1944 }
1945
1946 return CMD_SUCCESS;
1947 }
1948
1949 DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd,
1950 "no bgp reject-as-sets",
1951 NO_STR
1952 "BGP specific commands\n"
1953 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
1954 {
1955 VTY_DECLVAR_CONTEXT(bgp, bgp);
1956 struct listnode *node, *nnode;
1957 struct peer *peer;
1958
1959 bgp->reject_as_sets = BGP_REJECT_AS_SETS_DISABLED;
1960
1961 /* Reset existing BGP sessions to reject routes
1962 * with aspath containing AS_SET or AS_CONFED_SET.
1963 */
1964 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1965 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
1966 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
1967 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
1968 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
1969 }
1970 }
1971
1972 return CMD_SUCCESS;
1973 }
1974
1975 /* "bgp deterministic-med" configuration. */
1976 DEFUN (bgp_deterministic_med,
1977 bgp_deterministic_med_cmd,
1978 "bgp deterministic-med",
1979 "BGP specific commands\n"
1980 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1981 {
1982 VTY_DECLVAR_CONTEXT(bgp, bgp);
1983
1984 if (!bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1985 bgp_flag_set(bgp, BGP_FLAG_DETERMINISTIC_MED);
1986 bgp_recalculate_all_bestpaths(bgp);
1987 }
1988
1989 return CMD_SUCCESS;
1990 }
1991
1992 DEFUN (no_bgp_deterministic_med,
1993 no_bgp_deterministic_med_cmd,
1994 "no bgp deterministic-med",
1995 NO_STR
1996 "BGP specific commands\n"
1997 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1998 {
1999 VTY_DECLVAR_CONTEXT(bgp, bgp);
2000 int bestpath_per_as_used;
2001 afi_t afi;
2002 safi_t safi;
2003 struct peer *peer;
2004 struct listnode *node, *nnode;
2005
2006 if (bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
2007 bestpath_per_as_used = 0;
2008
2009 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2010 FOREACH_AFI_SAFI (afi, safi)
2011 if (bgp_addpath_dmed_required(
2012 peer->addpath_type[afi][safi])) {
2013 bestpath_per_as_used = 1;
2014 break;
2015 }
2016
2017 if (bestpath_per_as_used)
2018 break;
2019 }
2020
2021 if (bestpath_per_as_used) {
2022 vty_out(vty,
2023 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
2024 return CMD_WARNING_CONFIG_FAILED;
2025 } else {
2026 bgp_flag_unset(bgp, BGP_FLAG_DETERMINISTIC_MED);
2027 bgp_recalculate_all_bestpaths(bgp);
2028 }
2029 }
2030
2031 return CMD_SUCCESS;
2032 }
2033
2034 /* "bgp graceful-restart" configuration. */
2035 DEFUN (bgp_graceful_restart,
2036 bgp_graceful_restart_cmd,
2037 "bgp graceful-restart",
2038 "BGP specific commands\n"
2039 "Graceful restart capability parameters\n")
2040 {
2041 VTY_DECLVAR_CONTEXT(bgp, bgp);
2042 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_RESTART);
2043 return CMD_SUCCESS;
2044 }
2045
2046 DEFUN (no_bgp_graceful_restart,
2047 no_bgp_graceful_restart_cmd,
2048 "no bgp graceful-restart",
2049 NO_STR
2050 "BGP specific commands\n"
2051 "Graceful restart capability parameters\n")
2052 {
2053 VTY_DECLVAR_CONTEXT(bgp, bgp);
2054 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_RESTART);
2055 return CMD_SUCCESS;
2056 }
2057
2058 DEFUN (bgp_graceful_restart_stalepath_time,
2059 bgp_graceful_restart_stalepath_time_cmd,
2060 "bgp graceful-restart stalepath-time (1-4095)",
2061 "BGP specific commands\n"
2062 "Graceful restart capability parameters\n"
2063 "Set the max time to hold onto restarting peer's stale paths\n"
2064 "Delay value (seconds)\n")
2065 {
2066 VTY_DECLVAR_CONTEXT(bgp, bgp);
2067 int idx_number = 3;
2068 uint32_t stalepath;
2069
2070 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2071 bgp->stalepath_time = stalepath;
2072 return CMD_SUCCESS;
2073 }
2074
2075 DEFUN (bgp_graceful_restart_restart_time,
2076 bgp_graceful_restart_restart_time_cmd,
2077 "bgp graceful-restart restart-time (1-4095)",
2078 "BGP specific commands\n"
2079 "Graceful restart capability parameters\n"
2080 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2081 "Delay value (seconds)\n")
2082 {
2083 VTY_DECLVAR_CONTEXT(bgp, bgp);
2084 int idx_number = 3;
2085 uint32_t restart;
2086
2087 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2088 bgp->restart_time = restart;
2089 return CMD_SUCCESS;
2090 }
2091
2092 DEFUN (no_bgp_graceful_restart_stalepath_time,
2093 no_bgp_graceful_restart_stalepath_time_cmd,
2094 "no bgp graceful-restart stalepath-time [(1-4095)]",
2095 NO_STR
2096 "BGP specific commands\n"
2097 "Graceful restart capability parameters\n"
2098 "Set the max time to hold onto restarting peer's stale paths\n"
2099 "Delay value (seconds)\n")
2100 {
2101 VTY_DECLVAR_CONTEXT(bgp, bgp);
2102
2103 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2104 return CMD_SUCCESS;
2105 }
2106
2107 DEFUN (no_bgp_graceful_restart_restart_time,
2108 no_bgp_graceful_restart_restart_time_cmd,
2109 "no bgp graceful-restart restart-time [(1-4095)]",
2110 NO_STR
2111 "BGP specific commands\n"
2112 "Graceful restart capability parameters\n"
2113 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2114 "Delay value (seconds)\n")
2115 {
2116 VTY_DECLVAR_CONTEXT(bgp, bgp);
2117
2118 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2119 return CMD_SUCCESS;
2120 }
2121
2122 DEFUN (bgp_graceful_restart_preserve_fw,
2123 bgp_graceful_restart_preserve_fw_cmd,
2124 "bgp graceful-restart preserve-fw-state",
2125 "BGP specific commands\n"
2126 "Graceful restart capability parameters\n"
2127 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
2128 {
2129 VTY_DECLVAR_CONTEXT(bgp, bgp);
2130 bgp_flag_set(bgp, BGP_FLAG_GR_PRESERVE_FWD);
2131 return CMD_SUCCESS;
2132 }
2133
2134 DEFUN (no_bgp_graceful_restart_preserve_fw,
2135 no_bgp_graceful_restart_preserve_fw_cmd,
2136 "no bgp graceful-restart preserve-fw-state",
2137 NO_STR
2138 "BGP specific commands\n"
2139 "Graceful restart capability parameters\n"
2140 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
2141 {
2142 VTY_DECLVAR_CONTEXT(bgp, bgp);
2143 bgp_flag_unset(bgp, BGP_FLAG_GR_PRESERVE_FWD);
2144 return CMD_SUCCESS;
2145 }
2146
2147 /* "bgp graceful-shutdown" configuration */
2148 DEFUN (bgp_graceful_shutdown,
2149 bgp_graceful_shutdown_cmd,
2150 "bgp graceful-shutdown",
2151 BGP_STR
2152 "Graceful shutdown parameters\n")
2153 {
2154 VTY_DECLVAR_CONTEXT(bgp, bgp);
2155
2156 if (!bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2157 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
2158 bgp_static_redo_import_check(bgp);
2159 bgp_redistribute_redo(bgp);
2160 bgp_clear_star_soft_out(vty, bgp->name);
2161 bgp_clear_star_soft_in(vty, bgp->name);
2162 }
2163
2164 return CMD_SUCCESS;
2165 }
2166
2167 DEFUN (no_bgp_graceful_shutdown,
2168 no_bgp_graceful_shutdown_cmd,
2169 "no bgp graceful-shutdown",
2170 NO_STR
2171 BGP_STR
2172 "Graceful shutdown parameters\n")
2173 {
2174 VTY_DECLVAR_CONTEXT(bgp, bgp);
2175
2176 if (bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2177 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
2178 bgp_static_redo_import_check(bgp);
2179 bgp_redistribute_redo(bgp);
2180 bgp_clear_star_soft_out(vty, bgp->name);
2181 bgp_clear_star_soft_in(vty, bgp->name);
2182 }
2183
2184 return CMD_SUCCESS;
2185 }
2186
2187 /* "bgp fast-external-failover" configuration. */
2188 DEFUN (bgp_fast_external_failover,
2189 bgp_fast_external_failover_cmd,
2190 "bgp fast-external-failover",
2191 BGP_STR
2192 "Immediately reset session if a link to a directly connected external peer goes down\n")
2193 {
2194 VTY_DECLVAR_CONTEXT(bgp, bgp);
2195 bgp_flag_unset(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2196 return CMD_SUCCESS;
2197 }
2198
2199 DEFUN (no_bgp_fast_external_failover,
2200 no_bgp_fast_external_failover_cmd,
2201 "no bgp fast-external-failover",
2202 NO_STR
2203 BGP_STR
2204 "Immediately reset session if a link to a directly connected external peer goes down\n")
2205 {
2206 VTY_DECLVAR_CONTEXT(bgp, bgp);
2207 bgp_flag_set(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2208 return CMD_SUCCESS;
2209 }
2210
2211 /* "bgp bestpath compare-routerid" configuration. */
2212 DEFUN (bgp_bestpath_compare_router_id,
2213 bgp_bestpath_compare_router_id_cmd,
2214 "bgp bestpath compare-routerid",
2215 "BGP specific commands\n"
2216 "Change the default bestpath selection\n"
2217 "Compare router-id for identical EBGP paths\n")
2218 {
2219 VTY_DECLVAR_CONTEXT(bgp, bgp);
2220 bgp_flag_set(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2221 bgp_recalculate_all_bestpaths(bgp);
2222
2223 return CMD_SUCCESS;
2224 }
2225
2226 DEFUN (no_bgp_bestpath_compare_router_id,
2227 no_bgp_bestpath_compare_router_id_cmd,
2228 "no bgp bestpath compare-routerid",
2229 NO_STR
2230 "BGP specific commands\n"
2231 "Change the default bestpath selection\n"
2232 "Compare router-id for identical EBGP paths\n")
2233 {
2234 VTY_DECLVAR_CONTEXT(bgp, bgp);
2235 bgp_flag_unset(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2236 bgp_recalculate_all_bestpaths(bgp);
2237
2238 return CMD_SUCCESS;
2239 }
2240
2241 /* "bgp bestpath as-path ignore" configuration. */
2242 DEFUN (bgp_bestpath_aspath_ignore,
2243 bgp_bestpath_aspath_ignore_cmd,
2244 "bgp bestpath as-path ignore",
2245 "BGP specific commands\n"
2246 "Change the default bestpath selection\n"
2247 "AS-path attribute\n"
2248 "Ignore as-path length in selecting a route\n")
2249 {
2250 VTY_DECLVAR_CONTEXT(bgp, bgp);
2251 bgp_flag_set(bgp, BGP_FLAG_ASPATH_IGNORE);
2252 bgp_recalculate_all_bestpaths(bgp);
2253
2254 return CMD_SUCCESS;
2255 }
2256
2257 DEFUN (no_bgp_bestpath_aspath_ignore,
2258 no_bgp_bestpath_aspath_ignore_cmd,
2259 "no bgp bestpath as-path ignore",
2260 NO_STR
2261 "BGP specific commands\n"
2262 "Change the default bestpath selection\n"
2263 "AS-path attribute\n"
2264 "Ignore as-path length in selecting a route\n")
2265 {
2266 VTY_DECLVAR_CONTEXT(bgp, bgp);
2267 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_IGNORE);
2268 bgp_recalculate_all_bestpaths(bgp);
2269
2270 return CMD_SUCCESS;
2271 }
2272
2273 /* "bgp bestpath as-path confed" configuration. */
2274 DEFUN (bgp_bestpath_aspath_confed,
2275 bgp_bestpath_aspath_confed_cmd,
2276 "bgp bestpath as-path confed",
2277 "BGP specific commands\n"
2278 "Change the default bestpath selection\n"
2279 "AS-path attribute\n"
2280 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2281 {
2282 VTY_DECLVAR_CONTEXT(bgp, bgp);
2283 bgp_flag_set(bgp, BGP_FLAG_ASPATH_CONFED);
2284 bgp_recalculate_all_bestpaths(bgp);
2285
2286 return CMD_SUCCESS;
2287 }
2288
2289 DEFUN (no_bgp_bestpath_aspath_confed,
2290 no_bgp_bestpath_aspath_confed_cmd,
2291 "no bgp bestpath as-path confed",
2292 NO_STR
2293 "BGP specific commands\n"
2294 "Change the default bestpath selection\n"
2295 "AS-path attribute\n"
2296 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2297 {
2298 VTY_DECLVAR_CONTEXT(bgp, bgp);
2299 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_CONFED);
2300 bgp_recalculate_all_bestpaths(bgp);
2301
2302 return CMD_SUCCESS;
2303 }
2304
2305 /* "bgp bestpath as-path multipath-relax" configuration. */
2306 DEFUN (bgp_bestpath_aspath_multipath_relax,
2307 bgp_bestpath_aspath_multipath_relax_cmd,
2308 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
2309 "BGP specific commands\n"
2310 "Change the default bestpath selection\n"
2311 "AS-path attribute\n"
2312 "Allow load sharing across routes that have different AS paths (but same length)\n"
2313 "Generate an AS_SET\n"
2314 "Do not generate an AS_SET\n")
2315 {
2316 VTY_DECLVAR_CONTEXT(bgp, bgp);
2317 int idx = 0;
2318 bgp_flag_set(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2319
2320 /* no-as-set is now the default behavior so we can silently
2321 * ignore it */
2322 if (argv_find(argv, argc, "as-set", &idx))
2323 bgp_flag_set(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2324 else
2325 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2326
2327 bgp_recalculate_all_bestpaths(bgp);
2328
2329 return CMD_SUCCESS;
2330 }
2331
2332 DEFUN (no_bgp_bestpath_aspath_multipath_relax,
2333 no_bgp_bestpath_aspath_multipath_relax_cmd,
2334 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
2335 NO_STR
2336 "BGP specific commands\n"
2337 "Change the default bestpath selection\n"
2338 "AS-path attribute\n"
2339 "Allow load sharing across routes that have different AS paths (but same length)\n"
2340 "Generate an AS_SET\n"
2341 "Do not generate an AS_SET\n")
2342 {
2343 VTY_DECLVAR_CONTEXT(bgp, bgp);
2344 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2345 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2346 bgp_recalculate_all_bestpaths(bgp);
2347
2348 return CMD_SUCCESS;
2349 }
2350
2351 /* "bgp log-neighbor-changes" configuration. */
2352 DEFUN (bgp_log_neighbor_changes,
2353 bgp_log_neighbor_changes_cmd,
2354 "bgp log-neighbor-changes",
2355 "BGP specific commands\n"
2356 "Log neighbor up/down and reset reason\n")
2357 {
2358 VTY_DECLVAR_CONTEXT(bgp, bgp);
2359 bgp_flag_set(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2360 return CMD_SUCCESS;
2361 }
2362
2363 DEFUN (no_bgp_log_neighbor_changes,
2364 no_bgp_log_neighbor_changes_cmd,
2365 "no bgp log-neighbor-changes",
2366 NO_STR
2367 "BGP specific commands\n"
2368 "Log neighbor up/down and reset reason\n")
2369 {
2370 VTY_DECLVAR_CONTEXT(bgp, bgp);
2371 bgp_flag_unset(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2372 return CMD_SUCCESS;
2373 }
2374
2375 /* "bgp bestpath med" configuration. */
2376 DEFUN (bgp_bestpath_med,
2377 bgp_bestpath_med_cmd,
2378 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
2379 "BGP specific commands\n"
2380 "Change the default bestpath selection\n"
2381 "MED attribute\n"
2382 "Compare MED among confederation paths\n"
2383 "Treat missing MED as the least preferred one\n"
2384 "Treat missing MED as the least preferred one\n"
2385 "Compare MED among confederation paths\n")
2386 {
2387 VTY_DECLVAR_CONTEXT(bgp, bgp);
2388
2389 int idx = 0;
2390 if (argv_find(argv, argc, "confed", &idx))
2391 bgp_flag_set(bgp, BGP_FLAG_MED_CONFED);
2392 idx = 0;
2393 if (argv_find(argv, argc, "missing-as-worst", &idx))
2394 bgp_flag_set(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
2395
2396 bgp_recalculate_all_bestpaths(bgp);
2397
2398 return CMD_SUCCESS;
2399 }
2400
2401 DEFUN (no_bgp_bestpath_med,
2402 no_bgp_bestpath_med_cmd,
2403 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
2404 NO_STR
2405 "BGP specific commands\n"
2406 "Change the default bestpath selection\n"
2407 "MED attribute\n"
2408 "Compare MED among confederation paths\n"
2409 "Treat missing MED as the least preferred one\n"
2410 "Treat missing MED as the least preferred one\n"
2411 "Compare MED among confederation paths\n")
2412 {
2413 VTY_DECLVAR_CONTEXT(bgp, bgp);
2414
2415 int idx = 0;
2416 if (argv_find(argv, argc, "confed", &idx))
2417 bgp_flag_unset(bgp, BGP_FLAG_MED_CONFED);
2418 idx = 0;
2419 if (argv_find(argv, argc, "missing-as-worst", &idx))
2420 bgp_flag_unset(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
2421
2422 bgp_recalculate_all_bestpaths(bgp);
2423
2424 return CMD_SUCCESS;
2425 }
2426
2427 /* "no bgp default ipv4-unicast". */
2428 DEFUN (no_bgp_default_ipv4_unicast,
2429 no_bgp_default_ipv4_unicast_cmd,
2430 "no bgp default ipv4-unicast",
2431 NO_STR
2432 "BGP specific commands\n"
2433 "Configure BGP defaults\n"
2434 "Activate ipv4-unicast for a peer by default\n")
2435 {
2436 VTY_DECLVAR_CONTEXT(bgp, bgp);
2437 bgp_flag_set(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2438 return CMD_SUCCESS;
2439 }
2440
2441 DEFUN (bgp_default_ipv4_unicast,
2442 bgp_default_ipv4_unicast_cmd,
2443 "bgp default ipv4-unicast",
2444 "BGP specific commands\n"
2445 "Configure BGP defaults\n"
2446 "Activate ipv4-unicast for a peer by default\n")
2447 {
2448 VTY_DECLVAR_CONTEXT(bgp, bgp);
2449 bgp_flag_unset(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2450 return CMD_SUCCESS;
2451 }
2452
2453 /* Display hostname in certain command outputs */
2454 DEFUN (bgp_default_show_hostname,
2455 bgp_default_show_hostname_cmd,
2456 "bgp default show-hostname",
2457 "BGP specific commands\n"
2458 "Configure BGP defaults\n"
2459 "Show hostname in certain command outputs\n")
2460 {
2461 VTY_DECLVAR_CONTEXT(bgp, bgp);
2462 bgp_flag_set(bgp, BGP_FLAG_SHOW_HOSTNAME);
2463 return CMD_SUCCESS;
2464 }
2465
2466 DEFUN (no_bgp_default_show_hostname,
2467 no_bgp_default_show_hostname_cmd,
2468 "no bgp default show-hostname",
2469 NO_STR
2470 "BGP specific commands\n"
2471 "Configure BGP defaults\n"
2472 "Show hostname in certain command outputs\n")
2473 {
2474 VTY_DECLVAR_CONTEXT(bgp, bgp);
2475 bgp_flag_unset(bgp, BGP_FLAG_SHOW_HOSTNAME);
2476 return CMD_SUCCESS;
2477 }
2478
2479 /* "bgp network import-check" configuration. */
2480 DEFUN (bgp_network_import_check,
2481 bgp_network_import_check_cmd,
2482 "bgp network import-check",
2483 "BGP specific commands\n"
2484 "BGP network command\n"
2485 "Check BGP network route exists in IGP\n")
2486 {
2487 VTY_DECLVAR_CONTEXT(bgp, bgp);
2488 if (!bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2489 bgp_flag_set(bgp, BGP_FLAG_IMPORT_CHECK);
2490 bgp_static_redo_import_check(bgp);
2491 }
2492
2493 return CMD_SUCCESS;
2494 }
2495
2496 ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
2497 "bgp network import-check exact",
2498 "BGP specific commands\n"
2499 "BGP network command\n"
2500 "Check BGP network route exists in IGP\n"
2501 "Match route precisely\n")
2502
2503 DEFUN (no_bgp_network_import_check,
2504 no_bgp_network_import_check_cmd,
2505 "no bgp network import-check",
2506 NO_STR
2507 "BGP specific commands\n"
2508 "BGP network command\n"
2509 "Check BGP network route exists in IGP\n")
2510 {
2511 VTY_DECLVAR_CONTEXT(bgp, bgp);
2512 if (bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2513 bgp_flag_unset(bgp, BGP_FLAG_IMPORT_CHECK);
2514 bgp_static_redo_import_check(bgp);
2515 }
2516
2517 return CMD_SUCCESS;
2518 }
2519
2520 DEFUN (bgp_default_local_preference,
2521 bgp_default_local_preference_cmd,
2522 "bgp default local-preference (0-4294967295)",
2523 "BGP specific commands\n"
2524 "Configure BGP defaults\n"
2525 "local preference (higher=more preferred)\n"
2526 "Configure default local preference value\n")
2527 {
2528 VTY_DECLVAR_CONTEXT(bgp, bgp);
2529 int idx_number = 3;
2530 uint32_t local_pref;
2531
2532 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
2533
2534 bgp_default_local_preference_set(bgp, local_pref);
2535 bgp_clear_star_soft_in(vty, bgp->name);
2536
2537 return CMD_SUCCESS;
2538 }
2539
2540 DEFUN (no_bgp_default_local_preference,
2541 no_bgp_default_local_preference_cmd,
2542 "no bgp default local-preference [(0-4294967295)]",
2543 NO_STR
2544 "BGP specific commands\n"
2545 "Configure BGP defaults\n"
2546 "local preference (higher=more preferred)\n"
2547 "Configure default local preference value\n")
2548 {
2549 VTY_DECLVAR_CONTEXT(bgp, bgp);
2550 bgp_default_local_preference_unset(bgp);
2551 bgp_clear_star_soft_in(vty, bgp->name);
2552
2553 return CMD_SUCCESS;
2554 }
2555
2556
2557 DEFUN (bgp_default_subgroup_pkt_queue_max,
2558 bgp_default_subgroup_pkt_queue_max_cmd,
2559 "bgp default subgroup-pkt-queue-max (20-100)",
2560 "BGP specific commands\n"
2561 "Configure BGP defaults\n"
2562 "subgroup-pkt-queue-max\n"
2563 "Configure subgroup packet queue max\n")
2564 {
2565 VTY_DECLVAR_CONTEXT(bgp, bgp);
2566 int idx_number = 3;
2567 uint32_t max_size;
2568
2569 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
2570
2571 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
2572
2573 return CMD_SUCCESS;
2574 }
2575
2576 DEFUN (no_bgp_default_subgroup_pkt_queue_max,
2577 no_bgp_default_subgroup_pkt_queue_max_cmd,
2578 "no bgp default subgroup-pkt-queue-max [(20-100)]",
2579 NO_STR
2580 "BGP specific commands\n"
2581 "Configure BGP defaults\n"
2582 "subgroup-pkt-queue-max\n"
2583 "Configure subgroup packet queue max\n")
2584 {
2585 VTY_DECLVAR_CONTEXT(bgp, bgp);
2586 bgp_default_subgroup_pkt_queue_max_unset(bgp);
2587 return CMD_SUCCESS;
2588 }
2589
2590
2591 DEFUN (bgp_rr_allow_outbound_policy,
2592 bgp_rr_allow_outbound_policy_cmd,
2593 "bgp route-reflector allow-outbound-policy",
2594 "BGP specific commands\n"
2595 "Allow modifications made by out route-map\n"
2596 "on ibgp neighbors\n")
2597 {
2598 VTY_DECLVAR_CONTEXT(bgp, bgp);
2599
2600 if (!bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2601 bgp_flag_set(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2602 update_group_announce_rrclients(bgp);
2603 bgp_clear_star_soft_out(vty, bgp->name);
2604 }
2605
2606 return CMD_SUCCESS;
2607 }
2608
2609 DEFUN (no_bgp_rr_allow_outbound_policy,
2610 no_bgp_rr_allow_outbound_policy_cmd,
2611 "no bgp route-reflector allow-outbound-policy",
2612 NO_STR
2613 "BGP specific commands\n"
2614 "Allow modifications made by out route-map\n"
2615 "on ibgp neighbors\n")
2616 {
2617 VTY_DECLVAR_CONTEXT(bgp, bgp);
2618
2619 if (bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2620 bgp_flag_unset(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2621 update_group_announce_rrclients(bgp);
2622 bgp_clear_star_soft_out(vty, bgp->name);
2623 }
2624
2625 return CMD_SUCCESS;
2626 }
2627
2628 DEFUN (bgp_listen_limit,
2629 bgp_listen_limit_cmd,
2630 "bgp listen limit (1-5000)",
2631 "BGP specific commands\n"
2632 "Configure BGP defaults\n"
2633 "maximum number of BGP Dynamic Neighbors that can be created\n"
2634 "Configure Dynamic Neighbors listen limit value\n")
2635 {
2636 VTY_DECLVAR_CONTEXT(bgp, bgp);
2637 int idx_number = 3;
2638 int listen_limit;
2639
2640 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
2641
2642 bgp_listen_limit_set(bgp, listen_limit);
2643
2644 return CMD_SUCCESS;
2645 }
2646
2647 DEFUN (no_bgp_listen_limit,
2648 no_bgp_listen_limit_cmd,
2649 "no bgp listen limit [(1-5000)]",
2650 "BGP specific commands\n"
2651 "Configure BGP defaults\n"
2652 "unset maximum number of BGP Dynamic Neighbors that can be created\n"
2653 "Configure Dynamic Neighbors listen limit value to default\n"
2654 "Configure Dynamic Neighbors listen limit value\n")
2655 {
2656 VTY_DECLVAR_CONTEXT(bgp, bgp);
2657 bgp_listen_limit_unset(bgp);
2658 return CMD_SUCCESS;
2659 }
2660
2661
2662 /*
2663 * Check if this listen range is already configured. Check for exact
2664 * match or overlap based on input.
2665 */
2666 static struct peer_group *listen_range_exists(struct bgp *bgp,
2667 struct prefix *range, int exact)
2668 {
2669 struct listnode *node, *nnode;
2670 struct listnode *node1, *nnode1;
2671 struct peer_group *group;
2672 struct prefix *lr;
2673 afi_t afi;
2674 int match;
2675
2676 afi = family2afi(range->family);
2677 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2678 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
2679 lr)) {
2680 if (exact)
2681 match = prefix_same(range, lr);
2682 else
2683 match = (prefix_match(range, lr)
2684 || prefix_match(lr, range));
2685 if (match)
2686 return group;
2687 }
2688 }
2689
2690 return NULL;
2691 }
2692
2693 DEFUN (bgp_listen_range,
2694 bgp_listen_range_cmd,
2695 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
2696 "BGP specific commands\n"
2697 "Configure BGP dynamic neighbors listen range\n"
2698 "Configure BGP dynamic neighbors listen range\n"
2699 NEIGHBOR_ADDR_STR
2700 "Member of the peer-group\n"
2701 "Peer-group name\n")
2702 {
2703 VTY_DECLVAR_CONTEXT(bgp, bgp);
2704 struct prefix range;
2705 struct peer_group *group, *existing_group;
2706 afi_t afi;
2707 int ret;
2708 int idx = 0;
2709
2710 argv_find(argv, argc, "A.B.C.D/M", &idx);
2711 argv_find(argv, argc, "X:X::X:X/M", &idx);
2712 char *prefix = argv[idx]->arg;
2713 argv_find(argv, argc, "PGNAME", &idx);
2714 char *peergroup = argv[idx]->arg;
2715
2716 /* Convert IP prefix string to struct prefix. */
2717 ret = str2prefix(prefix, &range);
2718 if (!ret) {
2719 vty_out(vty, "%% Malformed listen range\n");
2720 return CMD_WARNING_CONFIG_FAILED;
2721 }
2722
2723 afi = family2afi(range.family);
2724
2725 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2726 vty_out(vty,
2727 "%% Malformed listen range (link-local address)\n");
2728 return CMD_WARNING_CONFIG_FAILED;
2729 }
2730
2731 apply_mask(&range);
2732
2733 /* Check if same listen range is already configured. */
2734 existing_group = listen_range_exists(bgp, &range, 1);
2735 if (existing_group) {
2736 if (strcmp(existing_group->name, peergroup) == 0)
2737 return CMD_SUCCESS;
2738 else {
2739 vty_out(vty,
2740 "%% Same listen range is attached to peer-group %s\n",
2741 existing_group->name);
2742 return CMD_WARNING_CONFIG_FAILED;
2743 }
2744 }
2745
2746 /* Check if an overlapping listen range exists. */
2747 if (listen_range_exists(bgp, &range, 0)) {
2748 vty_out(vty,
2749 "%% Listen range overlaps with existing listen range\n");
2750 return CMD_WARNING_CONFIG_FAILED;
2751 }
2752
2753 group = peer_group_lookup(bgp, peergroup);
2754 if (!group) {
2755 vty_out(vty, "%% Configure the peer-group first\n");
2756 return CMD_WARNING_CONFIG_FAILED;
2757 }
2758
2759 ret = peer_group_listen_range_add(group, &range);
2760 return bgp_vty_return(vty, ret);
2761 }
2762
2763 DEFUN (no_bgp_listen_range,
2764 no_bgp_listen_range_cmd,
2765 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
2766 NO_STR
2767 "BGP specific commands\n"
2768 "Unconfigure BGP dynamic neighbors listen range\n"
2769 "Unconfigure BGP dynamic neighbors listen range\n"
2770 NEIGHBOR_ADDR_STR
2771 "Member of the peer-group\n"
2772 "Peer-group name\n")
2773 {
2774 VTY_DECLVAR_CONTEXT(bgp, bgp);
2775 struct prefix range;
2776 struct peer_group *group;
2777 afi_t afi;
2778 int ret;
2779 int idx = 0;
2780
2781 argv_find(argv, argc, "A.B.C.D/M", &idx);
2782 argv_find(argv, argc, "X:X::X:X/M", &idx);
2783 char *prefix = argv[idx]->arg;
2784 argv_find(argv, argc, "WORD", &idx);
2785 char *peergroup = argv[idx]->arg;
2786
2787 /* Convert IP prefix string to struct prefix. */
2788 ret = str2prefix(prefix, &range);
2789 if (!ret) {
2790 vty_out(vty, "%% Malformed listen range\n");
2791 return CMD_WARNING_CONFIG_FAILED;
2792 }
2793
2794 afi = family2afi(range.family);
2795
2796 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2797 vty_out(vty,
2798 "%% Malformed listen range (link-local address)\n");
2799 return CMD_WARNING_CONFIG_FAILED;
2800 }
2801
2802 apply_mask(&range);
2803
2804 group = peer_group_lookup(bgp, peergroup);
2805 if (!group) {
2806 vty_out(vty, "%% Peer-group does not exist\n");
2807 return CMD_WARNING_CONFIG_FAILED;
2808 }
2809
2810 ret = peer_group_listen_range_del(group, &range);
2811 return bgp_vty_return(vty, ret);
2812 }
2813
2814 void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
2815 {
2816 struct peer_group *group;
2817 struct listnode *node, *nnode, *rnode, *nrnode;
2818 struct prefix *range;
2819 afi_t afi;
2820 char buf[PREFIX2STR_BUFFER];
2821
2822 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
2823 vty_out(vty, " bgp listen limit %d\n",
2824 bgp->dynamic_neighbors_limit);
2825
2826 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2827 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
2828 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
2829 nrnode, range)) {
2830 prefix2str(range, buf, sizeof(buf));
2831 vty_out(vty,
2832 " bgp listen range %s peer-group %s\n",
2833 buf, group->name);
2834 }
2835 }
2836 }
2837 }
2838
2839
2840 DEFUN (bgp_disable_connected_route_check,
2841 bgp_disable_connected_route_check_cmd,
2842 "bgp disable-ebgp-connected-route-check",
2843 "BGP specific commands\n"
2844 "Disable checking if nexthop is connected on ebgp sessions\n")
2845 {
2846 VTY_DECLVAR_CONTEXT(bgp, bgp);
2847 bgp_flag_set(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2848 bgp_clear_star_soft_in(vty, bgp->name);
2849
2850 return CMD_SUCCESS;
2851 }
2852
2853 DEFUN (no_bgp_disable_connected_route_check,
2854 no_bgp_disable_connected_route_check_cmd,
2855 "no bgp disable-ebgp-connected-route-check",
2856 NO_STR
2857 "BGP specific commands\n"
2858 "Disable checking if nexthop is connected on ebgp sessions\n")
2859 {
2860 VTY_DECLVAR_CONTEXT(bgp, bgp);
2861 bgp_flag_unset(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2862 bgp_clear_star_soft_in(vty, bgp->name);
2863
2864 return CMD_SUCCESS;
2865 }
2866
2867
2868 static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
2869 const char *as_str, afi_t afi, safi_t safi)
2870 {
2871 VTY_DECLVAR_CONTEXT(bgp, bgp);
2872 int ret;
2873 as_t as;
2874 int as_type = AS_SPECIFIED;
2875 union sockunion su;
2876
2877 if (as_str[0] == 'i') {
2878 as = 0;
2879 as_type = AS_INTERNAL;
2880 } else if (as_str[0] == 'e') {
2881 as = 0;
2882 as_type = AS_EXTERNAL;
2883 } else {
2884 /* Get AS number. */
2885 as = strtoul(as_str, NULL, 10);
2886 }
2887
2888 /* If peer is peer group or interface peer, call proper function. */
2889 ret = str2sockunion(peer_str, &su);
2890 if (ret < 0) {
2891 struct peer *peer;
2892
2893 /* Check if existing interface peer */
2894 peer = peer_lookup_by_conf_if(bgp, peer_str);
2895
2896 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, afi,
2897 safi);
2898
2899 /* if not interface peer, check peer-group settings */
2900 if (ret < 0 && !peer) {
2901 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
2902 if (ret < 0) {
2903 vty_out(vty,
2904 "%% Create the peer-group or interface first\n");
2905 return CMD_WARNING_CONFIG_FAILED;
2906 }
2907 return CMD_SUCCESS;
2908 }
2909 } else {
2910 if (peer_address_self_check(bgp, &su)) {
2911 vty_out(vty,
2912 "%% Can not configure the local system as neighbor\n");
2913 return CMD_WARNING_CONFIG_FAILED;
2914 }
2915 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, afi, safi);
2916 }
2917
2918 /* This peer belongs to peer group. */
2919 switch (ret) {
2920 case BGP_ERR_PEER_GROUP_MEMBER:
2921 vty_out(vty,
2922 "%% Peer-group member cannot override remote-as of peer-group\n");
2923 return CMD_WARNING_CONFIG_FAILED;
2924 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
2925 vty_out(vty,
2926 "%% Peer-group members must be all internal or all external\n");
2927 return CMD_WARNING_CONFIG_FAILED;
2928 }
2929 return bgp_vty_return(vty, ret);
2930 }
2931
2932 DEFUN (bgp_default_shutdown,
2933 bgp_default_shutdown_cmd,
2934 "[no] bgp default shutdown",
2935 NO_STR
2936 BGP_STR
2937 "Configure BGP defaults\n"
2938 "Apply administrative shutdown to newly configured peers\n")
2939 {
2940 VTY_DECLVAR_CONTEXT(bgp, bgp);
2941 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
2942 return CMD_SUCCESS;
2943 }
2944
2945 DEFUN (neighbor_remote_as,
2946 neighbor_remote_as_cmd,
2947 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
2948 NEIGHBOR_STR
2949 NEIGHBOR_ADDR_STR2
2950 "Specify a BGP neighbor\n"
2951 AS_STR
2952 "Internal BGP peer\n"
2953 "External BGP peer\n")
2954 {
2955 int idx_peer = 1;
2956 int idx_remote_as = 3;
2957 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
2958 argv[idx_remote_as]->arg, AFI_IP,
2959 SAFI_UNICAST);
2960 }
2961
2962 static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
2963 afi_t afi, safi_t safi, int v6only,
2964 const char *peer_group_name,
2965 const char *as_str)
2966 {
2967 VTY_DECLVAR_CONTEXT(bgp, bgp);
2968 as_t as = 0;
2969 int as_type = AS_UNSPECIFIED;
2970 struct peer *peer;
2971 struct peer_group *group;
2972 int ret = 0;
2973 union sockunion su;
2974
2975 group = peer_group_lookup(bgp, conf_if);
2976
2977 if (group) {
2978 vty_out(vty, "%% Name conflict with peer-group \n");
2979 return CMD_WARNING_CONFIG_FAILED;
2980 }
2981
2982 if (as_str) {
2983 if (as_str[0] == 'i') {
2984 as_type = AS_INTERNAL;
2985 } else if (as_str[0] == 'e') {
2986 as_type = AS_EXTERNAL;
2987 } else {
2988 /* Get AS number. */
2989 as = strtoul(as_str, NULL, 10);
2990 as_type = AS_SPECIFIED;
2991 }
2992 }
2993
2994 peer = peer_lookup_by_conf_if(bgp, conf_if);
2995 if (peer) {
2996 if (as_str)
2997 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type,
2998 afi, safi);
2999 } else {
3000 if (bgp_flag_check(bgp, BGP_FLAG_NO_DEFAULT_IPV4)
3001 && afi == AFI_IP && safi == SAFI_UNICAST)
3002 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
3003 as_type, 0, 0, NULL);
3004 else
3005 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
3006 as_type, afi, safi, NULL);
3007
3008 if (!peer) {
3009 vty_out(vty, "%% BGP failed to create peer\n");
3010 return CMD_WARNING_CONFIG_FAILED;
3011 }
3012
3013 if (v6only)
3014 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
3015
3016 /* Request zebra to initiate IPv6 RAs on this interface. We do
3017 * this
3018 * any unnumbered peer in order to not worry about run-time
3019 * transitions
3020 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
3021 * address
3022 * gets deleted later etc.)
3023 */
3024 if (peer->ifp)
3025 bgp_zebra_initiate_radv(bgp, peer);
3026 }
3027
3028 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
3029 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
3030 if (v6only)
3031 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
3032 else
3033 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
3034
3035 /* v6only flag changed. Reset bgp seesion */
3036 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
3037 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
3038 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
3039 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
3040 } else
3041 bgp_session_reset(peer);
3042 }
3043
3044 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
3045 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
3046 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
3047 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
3048 }
3049
3050 if (peer_group_name) {
3051 group = peer_group_lookup(bgp, peer_group_name);
3052 if (!group) {
3053 vty_out(vty, "%% Configure the peer-group first\n");
3054 return CMD_WARNING_CONFIG_FAILED;
3055 }
3056
3057 ret = peer_group_bind(bgp, &su, peer, group, &as);
3058 }
3059
3060 return bgp_vty_return(vty, ret);
3061 }
3062
3063 DEFUN (neighbor_interface_config,
3064 neighbor_interface_config_cmd,
3065 "neighbor WORD interface [peer-group PGNAME]",
3066 NEIGHBOR_STR
3067 "Interface name or neighbor tag\n"
3068 "Enable BGP on interface\n"
3069 "Member of the peer-group\n"
3070 "Peer-group name\n")
3071 {
3072 int idx_word = 1;
3073 int idx_peer_group_word = 4;
3074
3075 if (argc > idx_peer_group_word)
3076 return peer_conf_interface_get(
3077 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
3078 argv[idx_peer_group_word]->arg, NULL);
3079 else
3080 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3081 SAFI_UNICAST, 0, NULL, NULL);
3082 }
3083
3084 DEFUN (neighbor_interface_config_v6only,
3085 neighbor_interface_config_v6only_cmd,
3086 "neighbor WORD interface v6only [peer-group PGNAME]",
3087 NEIGHBOR_STR
3088 "Interface name or neighbor tag\n"
3089 "Enable BGP on interface\n"
3090 "Enable BGP with v6 link-local only\n"
3091 "Member of the peer-group\n"
3092 "Peer-group name\n")
3093 {
3094 int idx_word = 1;
3095 int idx_peer_group_word = 5;
3096
3097 if (argc > idx_peer_group_word)
3098 return peer_conf_interface_get(
3099 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
3100 argv[idx_peer_group_word]->arg, NULL);
3101
3102 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3103 SAFI_UNICAST, 1, NULL, NULL);
3104 }
3105
3106
3107 DEFUN (neighbor_interface_config_remote_as,
3108 neighbor_interface_config_remote_as_cmd,
3109 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
3110 NEIGHBOR_STR
3111 "Interface name or neighbor tag\n"
3112 "Enable BGP on interface\n"
3113 "Specify a BGP neighbor\n"
3114 AS_STR
3115 "Internal BGP peer\n"
3116 "External BGP peer\n")
3117 {
3118 int idx_word = 1;
3119 int idx_remote_as = 4;
3120 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3121 SAFI_UNICAST, 0, NULL,
3122 argv[idx_remote_as]->arg);
3123 }
3124
3125 DEFUN (neighbor_interface_v6only_config_remote_as,
3126 neighbor_interface_v6only_config_remote_as_cmd,
3127 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
3128 NEIGHBOR_STR
3129 "Interface name or neighbor tag\n"
3130 "Enable BGP with v6 link-local only\n"
3131 "Enable BGP on interface\n"
3132 "Specify a BGP neighbor\n"
3133 AS_STR
3134 "Internal BGP peer\n"
3135 "External BGP peer\n")
3136 {
3137 int idx_word = 1;
3138 int idx_remote_as = 5;
3139 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3140 SAFI_UNICAST, 1, NULL,
3141 argv[idx_remote_as]->arg);
3142 }
3143
3144 DEFUN (neighbor_peer_group,
3145 neighbor_peer_group_cmd,
3146 "neighbor WORD peer-group",
3147 NEIGHBOR_STR
3148 "Interface name or neighbor tag\n"
3149 "Configure peer-group\n")
3150 {
3151 VTY_DECLVAR_CONTEXT(bgp, bgp);
3152 int idx_word = 1;
3153 struct peer *peer;
3154 struct peer_group *group;
3155
3156 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3157 if (peer) {
3158 vty_out(vty, "%% Name conflict with interface: \n");
3159 return CMD_WARNING_CONFIG_FAILED;
3160 }
3161
3162 group = peer_group_get(bgp, argv[idx_word]->arg);
3163 if (!group) {
3164 vty_out(vty, "%% BGP failed to find or create peer-group\n");
3165 return CMD_WARNING_CONFIG_FAILED;
3166 }
3167
3168 return CMD_SUCCESS;
3169 }
3170
3171 DEFUN (no_neighbor,
3172 no_neighbor_cmd,
3173 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
3174 NO_STR
3175 NEIGHBOR_STR
3176 NEIGHBOR_ADDR_STR2
3177 "Specify a BGP neighbor\n"
3178 AS_STR
3179 "Internal BGP peer\n"
3180 "External BGP peer\n")
3181 {
3182 VTY_DECLVAR_CONTEXT(bgp, bgp);
3183 int idx_peer = 2;
3184 int ret;
3185 union sockunion su;
3186 struct peer_group *group;
3187 struct peer *peer;
3188 struct peer *other;
3189
3190 ret = str2sockunion(argv[idx_peer]->arg, &su);
3191 if (ret < 0) {
3192 /* look up for neighbor by interface name config. */
3193 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3194 if (peer) {
3195 /* Request zebra to terminate IPv6 RAs on this
3196 * interface. */
3197 if (peer->ifp)
3198 bgp_zebra_terminate_radv(peer->bgp, peer);
3199 peer_delete(peer);
3200 return CMD_SUCCESS;
3201 }
3202
3203 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
3204 if (group)
3205 peer_group_delete(group);
3206 else {
3207 vty_out(vty, "%% Create the peer-group first\n");
3208 return CMD_WARNING_CONFIG_FAILED;
3209 }
3210 } else {
3211 peer = peer_lookup(bgp, &su);
3212 if (peer) {
3213 if (peer_dynamic_neighbor(peer)) {
3214 vty_out(vty,
3215 "%% Operation not allowed on a dynamic neighbor\n");
3216 return CMD_WARNING_CONFIG_FAILED;
3217 }
3218
3219 other = peer->doppelganger;
3220 peer_delete(peer);
3221 if (other && other->status != Deleted)
3222 peer_delete(other);
3223 }
3224 }
3225
3226 return CMD_SUCCESS;
3227 }
3228
3229 DEFUN (no_neighbor_interface_config,
3230 no_neighbor_interface_config_cmd,
3231 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
3232 NO_STR
3233 NEIGHBOR_STR
3234 "Interface name\n"
3235 "Configure BGP on interface\n"
3236 "Enable BGP with v6 link-local only\n"
3237 "Member of the peer-group\n"
3238 "Peer-group name\n"
3239 "Specify a BGP neighbor\n"
3240 AS_STR
3241 "Internal BGP peer\n"
3242 "External BGP peer\n")
3243 {
3244 VTY_DECLVAR_CONTEXT(bgp, bgp);
3245 int idx_word = 2;
3246 struct peer *peer;
3247
3248 /* look up for neighbor by interface name config. */
3249 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3250 if (peer) {
3251 /* Request zebra to terminate IPv6 RAs on this interface. */
3252 if (peer->ifp)
3253 bgp_zebra_terminate_radv(peer->bgp, peer);
3254 peer_delete(peer);
3255 } else {
3256 vty_out(vty, "%% Create the bgp interface first\n");
3257 return CMD_WARNING_CONFIG_FAILED;
3258 }
3259 return CMD_SUCCESS;
3260 }
3261
3262 DEFUN (no_neighbor_peer_group,
3263 no_neighbor_peer_group_cmd,
3264 "no neighbor WORD peer-group",
3265 NO_STR
3266 NEIGHBOR_STR
3267 "Neighbor tag\n"
3268 "Configure peer-group\n")
3269 {
3270 VTY_DECLVAR_CONTEXT(bgp, bgp);
3271 int idx_word = 2;
3272 struct peer_group *group;
3273
3274 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3275 if (group)
3276 peer_group_delete(group);
3277 else {
3278 vty_out(vty, "%% Create the peer-group first\n");
3279 return CMD_WARNING_CONFIG_FAILED;
3280 }
3281 return CMD_SUCCESS;
3282 }
3283
3284 DEFUN (no_neighbor_interface_peer_group_remote_as,
3285 no_neighbor_interface_peer_group_remote_as_cmd,
3286 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
3287 NO_STR
3288 NEIGHBOR_STR
3289 "Interface name or neighbor tag\n"
3290 "Specify a BGP neighbor\n"
3291 AS_STR
3292 "Internal BGP peer\n"
3293 "External BGP peer\n")
3294 {
3295 VTY_DECLVAR_CONTEXT(bgp, bgp);
3296 int idx_word = 2;
3297 struct peer_group *group;
3298 struct peer *peer;
3299
3300 /* look up for neighbor by interface name config. */
3301 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3302 if (peer) {
3303 peer_as_change(peer, 0, AS_UNSPECIFIED);
3304 return CMD_SUCCESS;
3305 }
3306
3307 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3308 if (group)
3309 peer_group_remote_as_delete(group);
3310 else {
3311 vty_out(vty, "%% Create the peer-group or interface first\n");
3312 return CMD_WARNING_CONFIG_FAILED;
3313 }
3314 return CMD_SUCCESS;
3315 }
3316
3317 DEFUN (neighbor_local_as,
3318 neighbor_local_as_cmd,
3319 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
3320 NEIGHBOR_STR
3321 NEIGHBOR_ADDR_STR2
3322 "Specify a local-as number\n"
3323 "AS number used as local AS\n")
3324 {
3325 int idx_peer = 1;
3326 int idx_number = 3;
3327 struct peer *peer;
3328 int ret;
3329 as_t as;
3330
3331 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3332 if (!peer)
3333 return CMD_WARNING_CONFIG_FAILED;
3334
3335 as = strtoul(argv[idx_number]->arg, NULL, 10);
3336 ret = peer_local_as_set(peer, as, 0, 0);
3337 return bgp_vty_return(vty, ret);
3338 }
3339
3340 DEFUN (neighbor_local_as_no_prepend,
3341 neighbor_local_as_no_prepend_cmd,
3342 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
3343 NEIGHBOR_STR
3344 NEIGHBOR_ADDR_STR2
3345 "Specify a local-as number\n"
3346 "AS number used as local AS\n"
3347 "Do not prepend local-as to updates from ebgp peers\n")
3348 {
3349 int idx_peer = 1;
3350 int idx_number = 3;
3351 struct peer *peer;
3352 int ret;
3353 as_t as;
3354
3355 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3356 if (!peer)
3357 return CMD_WARNING_CONFIG_FAILED;
3358
3359 as = strtoul(argv[idx_number]->arg, NULL, 10);
3360 ret = peer_local_as_set(peer, as, 1, 0);
3361 return bgp_vty_return(vty, ret);
3362 }
3363
3364 DEFUN (neighbor_local_as_no_prepend_replace_as,
3365 neighbor_local_as_no_prepend_replace_as_cmd,
3366 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
3367 NEIGHBOR_STR
3368 NEIGHBOR_ADDR_STR2
3369 "Specify a local-as number\n"
3370 "AS number used as local AS\n"
3371 "Do not prepend local-as to updates from ebgp peers\n"
3372 "Do not prepend local-as to updates from ibgp peers\n")
3373 {
3374 int idx_peer = 1;
3375 int idx_number = 3;
3376 struct peer *peer;
3377 int ret;
3378 as_t as;
3379
3380 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3381 if (!peer)
3382 return CMD_WARNING_CONFIG_FAILED;
3383
3384 as = strtoul(argv[idx_number]->arg, NULL, 10);
3385 ret = peer_local_as_set(peer, as, 1, 1);
3386 return bgp_vty_return(vty, ret);
3387 }
3388
3389 DEFUN (no_neighbor_local_as,
3390 no_neighbor_local_as_cmd,
3391 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
3392 NO_STR
3393 NEIGHBOR_STR
3394 NEIGHBOR_ADDR_STR2
3395 "Specify a local-as number\n"
3396 "AS number used as local AS\n"
3397 "Do not prepend local-as to updates from ebgp peers\n"
3398 "Do not prepend local-as to updates from ibgp peers\n")
3399 {
3400 int idx_peer = 2;
3401 struct peer *peer;
3402 int ret;
3403
3404 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3405 if (!peer)
3406 return CMD_WARNING_CONFIG_FAILED;
3407
3408 ret = peer_local_as_unset(peer);
3409 return bgp_vty_return(vty, ret);
3410 }
3411
3412
3413 DEFUN (neighbor_solo,
3414 neighbor_solo_cmd,
3415 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3416 NEIGHBOR_STR
3417 NEIGHBOR_ADDR_STR2
3418 "Solo peer - part of its own update group\n")
3419 {
3420 int idx_peer = 1;
3421 struct peer *peer;
3422 int ret;
3423
3424 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3425 if (!peer)
3426 return CMD_WARNING_CONFIG_FAILED;
3427
3428 ret = update_group_adjust_soloness(peer, 1);
3429 return bgp_vty_return(vty, ret);
3430 }
3431
3432 DEFUN (no_neighbor_solo,
3433 no_neighbor_solo_cmd,
3434 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3435 NO_STR
3436 NEIGHBOR_STR
3437 NEIGHBOR_ADDR_STR2
3438 "Solo peer - part of its own update group\n")
3439 {
3440 int idx_peer = 2;
3441 struct peer *peer;
3442 int ret;
3443
3444 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3445 if (!peer)
3446 return CMD_WARNING_CONFIG_FAILED;
3447
3448 ret = update_group_adjust_soloness(peer, 0);
3449 return bgp_vty_return(vty, ret);
3450 }
3451
3452 DEFUN (neighbor_password,
3453 neighbor_password_cmd,
3454 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
3455 NEIGHBOR_STR
3456 NEIGHBOR_ADDR_STR2
3457 "Set a password\n"
3458 "The password\n")
3459 {
3460 int idx_peer = 1;
3461 int idx_line = 3;
3462 struct peer *peer;
3463 int ret;
3464
3465 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3466 if (!peer)
3467 return CMD_WARNING_CONFIG_FAILED;
3468
3469 ret = peer_password_set(peer, argv[idx_line]->arg);
3470 return bgp_vty_return(vty, ret);
3471 }
3472
3473 DEFUN (no_neighbor_password,
3474 no_neighbor_password_cmd,
3475 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
3476 NO_STR
3477 NEIGHBOR_STR
3478 NEIGHBOR_ADDR_STR2
3479 "Set a password\n"
3480 "The password\n")
3481 {
3482 int idx_peer = 2;
3483 struct peer *peer;
3484 int ret;
3485
3486 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3487 if (!peer)
3488 return CMD_WARNING_CONFIG_FAILED;
3489
3490 ret = peer_password_unset(peer);
3491 return bgp_vty_return(vty, ret);
3492 }
3493
3494 DEFUN (neighbor_activate,
3495 neighbor_activate_cmd,
3496 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3497 NEIGHBOR_STR
3498 NEIGHBOR_ADDR_STR2
3499 "Enable the Address Family for this Neighbor\n")
3500 {
3501 int idx_peer = 1;
3502 int ret;
3503 struct peer *peer;
3504
3505 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3506 if (!peer)
3507 return CMD_WARNING_CONFIG_FAILED;
3508
3509 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3510 return bgp_vty_return(vty, ret);
3511 }
3512
3513 ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
3514 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3515 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3516 "Enable the Address Family for this Neighbor\n")
3517
3518 DEFUN (no_neighbor_activate,
3519 no_neighbor_activate_cmd,
3520 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3521 NO_STR
3522 NEIGHBOR_STR
3523 NEIGHBOR_ADDR_STR2
3524 "Enable the Address Family for this Neighbor\n")
3525 {
3526 int idx_peer = 2;
3527 int ret;
3528 struct peer *peer;
3529
3530 /* Lookup peer. */
3531 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3532 if (!peer)
3533 return CMD_WARNING_CONFIG_FAILED;
3534
3535 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3536 return bgp_vty_return(vty, ret);
3537 }
3538
3539 ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
3540 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3541 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3542 "Enable the Address Family for this Neighbor\n")
3543
3544 DEFUN (neighbor_set_peer_group,
3545 neighbor_set_peer_group_cmd,
3546 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
3547 NEIGHBOR_STR
3548 NEIGHBOR_ADDR_STR2
3549 "Member of the peer-group\n"
3550 "Peer-group name\n")
3551 {
3552 VTY_DECLVAR_CONTEXT(bgp, bgp);
3553 int idx_peer = 1;
3554 int idx_word = 3;
3555 int ret;
3556 as_t as;
3557 union sockunion su;
3558 struct peer *peer;
3559 struct peer_group *group;
3560
3561 ret = str2sockunion(argv[idx_peer]->arg, &su);
3562 if (ret < 0) {
3563 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3564 if (!peer) {
3565 vty_out(vty, "%% Malformed address or name: %s\n",
3566 argv[idx_peer]->arg);
3567 return CMD_WARNING_CONFIG_FAILED;
3568 }
3569 } else {
3570 if (peer_address_self_check(bgp, &su)) {
3571 vty_out(vty,
3572 "%% Can not configure the local system as neighbor\n");
3573 return CMD_WARNING_CONFIG_FAILED;
3574 }
3575
3576 /* Disallow for dynamic neighbor. */
3577 peer = peer_lookup(bgp, &su);
3578 if (peer && peer_dynamic_neighbor(peer)) {
3579 vty_out(vty,
3580 "%% Operation not allowed on a dynamic neighbor\n");
3581 return CMD_WARNING_CONFIG_FAILED;
3582 }
3583 }
3584
3585 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3586 if (!group) {
3587 vty_out(vty, "%% Configure the peer-group first\n");
3588 return CMD_WARNING_CONFIG_FAILED;
3589 }
3590
3591 ret = peer_group_bind(bgp, &su, peer, group, &as);
3592
3593 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
3594 vty_out(vty,
3595 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
3596 as);
3597 return CMD_WARNING_CONFIG_FAILED;
3598 }
3599
3600 return bgp_vty_return(vty, ret);
3601 }
3602
3603 ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
3604 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
3605 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3606 "Member of the peer-group\n"
3607 "Peer-group name\n")
3608
3609 DEFUN (no_neighbor_set_peer_group,
3610 no_neighbor_set_peer_group_cmd,
3611 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
3612 NO_STR
3613 NEIGHBOR_STR
3614 NEIGHBOR_ADDR_STR2
3615 "Member of the peer-group\n"
3616 "Peer-group name\n")
3617 {
3618 VTY_DECLVAR_CONTEXT(bgp, bgp);
3619 int idx_peer = 2;
3620 int idx_word = 4;
3621 int ret;
3622 struct peer *peer;
3623 struct peer_group *group;
3624
3625 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
3626 if (!peer)
3627 return CMD_WARNING_CONFIG_FAILED;
3628
3629 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3630 if (!group) {
3631 vty_out(vty, "%% Configure the peer-group first\n");
3632 return CMD_WARNING_CONFIG_FAILED;
3633 }
3634
3635 ret = peer_delete(peer);
3636
3637 return bgp_vty_return(vty, ret);
3638 }
3639
3640 ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
3641 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
3642 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3643 "Member of the peer-group\n"
3644 "Peer-group name\n")
3645
3646 static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
3647 uint32_t flag, int set)
3648 {
3649 int ret;
3650 struct peer *peer;
3651
3652 peer = peer_and_group_lookup_vty(vty, ip_str);
3653 if (!peer)
3654 return CMD_WARNING_CONFIG_FAILED;
3655
3656 /*
3657 * If 'neighbor <interface>', then this is for directly connected peers,
3658 * we should not accept disable-connected-check.
3659 */
3660 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
3661 vty_out(vty,
3662 "%s is directly connected peer, cannot accept disable-"
3663 "connected-check\n",
3664 ip_str);
3665 return CMD_WARNING_CONFIG_FAILED;
3666 }
3667
3668 if (!set && flag == PEER_FLAG_SHUTDOWN)
3669 peer_tx_shutdown_message_unset(peer);
3670
3671 if (set)
3672 ret = peer_flag_set(peer, flag);
3673 else
3674 ret = peer_flag_unset(peer, flag);
3675
3676 return bgp_vty_return(vty, ret);
3677 }
3678
3679 static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
3680 {
3681 return peer_flag_modify_vty(vty, ip_str, flag, 1);
3682 }
3683
3684 static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
3685 uint32_t flag)
3686 {
3687 return peer_flag_modify_vty(vty, ip_str, flag, 0);
3688 }
3689
3690 /* neighbor passive. */
3691 DEFUN (neighbor_passive,
3692 neighbor_passive_cmd,
3693 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
3694 NEIGHBOR_STR
3695 NEIGHBOR_ADDR_STR2
3696 "Don't send open messages to this neighbor\n")
3697 {
3698 int idx_peer = 1;
3699 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
3700 }
3701
3702 DEFUN (no_neighbor_passive,
3703 no_neighbor_passive_cmd,
3704 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
3705 NO_STR
3706 NEIGHBOR_STR
3707 NEIGHBOR_ADDR_STR2
3708 "Don't send open messages to this neighbor\n")
3709 {
3710 int idx_peer = 2;
3711 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
3712 }
3713
3714 /* neighbor shutdown. */
3715 DEFUN (neighbor_shutdown_msg,
3716 neighbor_shutdown_msg_cmd,
3717 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3718 NEIGHBOR_STR
3719 NEIGHBOR_ADDR_STR2
3720 "Administratively shut down this neighbor\n"
3721 "Add a shutdown message (draft-ietf-idr-shutdown-06)\n"
3722 "Shutdown message\n")
3723 {
3724 int idx_peer = 1;
3725
3726 if (argc >= 5) {
3727 struct peer *peer =
3728 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3729 char *message;
3730
3731 if (!peer)
3732 return CMD_WARNING_CONFIG_FAILED;
3733 message = argv_concat(argv, argc, 4);
3734 peer_tx_shutdown_message_set(peer, message);
3735 XFREE(MTYPE_TMP, message);
3736 }
3737
3738 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
3739 }
3740
3741 ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
3742 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3743 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3744 "Administratively shut down this neighbor\n")
3745
3746 DEFUN (no_neighbor_shutdown_msg,
3747 no_neighbor_shutdown_msg_cmd,
3748 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3749 NO_STR
3750 NEIGHBOR_STR
3751 NEIGHBOR_ADDR_STR2
3752 "Administratively shut down this neighbor\n"
3753 "Remove a shutdown message (draft-ietf-idr-shutdown-06)\n"
3754 "Shutdown message\n")
3755 {
3756 int idx_peer = 2;
3757
3758 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3759 PEER_FLAG_SHUTDOWN);
3760 }
3761
3762 ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
3763 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3764 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3765 "Administratively shut down this neighbor\n")
3766
3767 /* neighbor capability dynamic. */
3768 DEFUN (neighbor_capability_dynamic,
3769 neighbor_capability_dynamic_cmd,
3770 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
3771 NEIGHBOR_STR
3772 NEIGHBOR_ADDR_STR2
3773 "Advertise capability to the peer\n"
3774 "Advertise dynamic capability to this neighbor\n")
3775 {
3776 int idx_peer = 1;
3777 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3778 PEER_FLAG_DYNAMIC_CAPABILITY);
3779 }
3780
3781 DEFUN (no_neighbor_capability_dynamic,
3782 no_neighbor_capability_dynamic_cmd,
3783 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
3784 NO_STR
3785 NEIGHBOR_STR
3786 NEIGHBOR_ADDR_STR2
3787 "Advertise capability to the peer\n"
3788 "Advertise dynamic capability to this neighbor\n")
3789 {
3790 int idx_peer = 2;
3791 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3792 PEER_FLAG_DYNAMIC_CAPABILITY);
3793 }
3794
3795 /* neighbor dont-capability-negotiate */
3796 DEFUN (neighbor_dont_capability_negotiate,
3797 neighbor_dont_capability_negotiate_cmd,
3798 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
3799 NEIGHBOR_STR
3800 NEIGHBOR_ADDR_STR2
3801 "Do not perform capability negotiation\n")
3802 {
3803 int idx_peer = 1;
3804 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3805 PEER_FLAG_DONT_CAPABILITY);
3806 }
3807
3808 DEFUN (no_neighbor_dont_capability_negotiate,
3809 no_neighbor_dont_capability_negotiate_cmd,
3810 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
3811 NO_STR
3812 NEIGHBOR_STR
3813 NEIGHBOR_ADDR_STR2
3814 "Do not perform capability negotiation\n")
3815 {
3816 int idx_peer = 2;
3817 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3818 PEER_FLAG_DONT_CAPABILITY);
3819 }
3820
3821 /* neighbor capability extended next hop encoding */
3822 DEFUN (neighbor_capability_enhe,
3823 neighbor_capability_enhe_cmd,
3824 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
3825 NEIGHBOR_STR
3826 NEIGHBOR_ADDR_STR2
3827 "Advertise capability to the peer\n"
3828 "Advertise extended next-hop capability to the peer\n")
3829 {
3830 int idx_peer = 1;
3831 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3832 PEER_FLAG_CAPABILITY_ENHE);
3833 }
3834
3835 DEFUN (no_neighbor_capability_enhe,
3836 no_neighbor_capability_enhe_cmd,
3837 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
3838 NO_STR
3839 NEIGHBOR_STR
3840 NEIGHBOR_ADDR_STR2
3841 "Advertise capability to the peer\n"
3842 "Advertise extended next-hop capability to the peer\n")
3843 {
3844 int idx_peer = 2;
3845 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3846 PEER_FLAG_CAPABILITY_ENHE);
3847 }
3848
3849 static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
3850 afi_t afi, safi_t safi, uint32_t flag,
3851 int set)
3852 {
3853 int ret;
3854 struct peer *peer;
3855
3856 peer = peer_and_group_lookup_vty(vty, peer_str);
3857 if (!peer)
3858 return CMD_WARNING_CONFIG_FAILED;
3859
3860 if (set)
3861 ret = peer_af_flag_set(peer, afi, safi, flag);
3862 else
3863 ret = peer_af_flag_unset(peer, afi, safi, flag);
3864
3865 return bgp_vty_return(vty, ret);
3866 }
3867
3868 static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
3869 afi_t afi, safi_t safi, uint32_t flag)
3870 {
3871 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
3872 }
3873
3874 static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
3875 afi_t afi, safi_t safi, uint32_t flag)
3876 {
3877 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
3878 }
3879
3880 /* neighbor capability orf prefix-list. */
3881 DEFUN (neighbor_capability_orf_prefix,
3882 neighbor_capability_orf_prefix_cmd,
3883 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3884 NEIGHBOR_STR
3885 NEIGHBOR_ADDR_STR2
3886 "Advertise capability to the peer\n"
3887 "Advertise ORF capability to the peer\n"
3888 "Advertise prefixlist ORF capability to this neighbor\n"
3889 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3890 "Capability to RECEIVE the ORF from this neighbor\n"
3891 "Capability to SEND the ORF to this neighbor\n")
3892 {
3893 int idx_peer = 1;
3894 int idx_send_recv = 5;
3895 uint16_t flag = 0;
3896
3897 if (strmatch(argv[idx_send_recv]->text, "send"))
3898 flag = PEER_FLAG_ORF_PREFIX_SM;
3899 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3900 flag = PEER_FLAG_ORF_PREFIX_RM;
3901 else if (strmatch(argv[idx_send_recv]->text, "both"))
3902 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3903 else {
3904 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3905 return CMD_WARNING_CONFIG_FAILED;
3906 }
3907
3908 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3909 bgp_node_safi(vty), flag);
3910 }
3911
3912 ALIAS_HIDDEN(
3913 neighbor_capability_orf_prefix,
3914 neighbor_capability_orf_prefix_hidden_cmd,
3915 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3916 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3917 "Advertise capability to the peer\n"
3918 "Advertise ORF capability to the peer\n"
3919 "Advertise prefixlist ORF capability to this neighbor\n"
3920 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3921 "Capability to RECEIVE the ORF from this neighbor\n"
3922 "Capability to SEND the ORF to this neighbor\n")
3923
3924 DEFUN (no_neighbor_capability_orf_prefix,
3925 no_neighbor_capability_orf_prefix_cmd,
3926 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3927 NO_STR
3928 NEIGHBOR_STR
3929 NEIGHBOR_ADDR_STR2
3930 "Advertise capability to the peer\n"
3931 "Advertise ORF capability to the peer\n"
3932 "Advertise prefixlist ORF capability to this neighbor\n"
3933 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3934 "Capability to RECEIVE the ORF from this neighbor\n"
3935 "Capability to SEND the ORF to this neighbor\n")
3936 {
3937 int idx_peer = 2;
3938 int idx_send_recv = 6;
3939 uint16_t flag = 0;
3940
3941 if (strmatch(argv[idx_send_recv]->text, "send"))
3942 flag = PEER_FLAG_ORF_PREFIX_SM;
3943 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3944 flag = PEER_FLAG_ORF_PREFIX_RM;
3945 else if (strmatch(argv[idx_send_recv]->text, "both"))
3946 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3947 else {
3948 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3949 return CMD_WARNING_CONFIG_FAILED;
3950 }
3951
3952 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3953 bgp_node_afi(vty), bgp_node_safi(vty),
3954 flag);
3955 }
3956
3957 ALIAS_HIDDEN(
3958 no_neighbor_capability_orf_prefix,
3959 no_neighbor_capability_orf_prefix_hidden_cmd,
3960 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3961 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3962 "Advertise capability to the peer\n"
3963 "Advertise ORF capability to the peer\n"
3964 "Advertise prefixlist ORF capability to this neighbor\n"
3965 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3966 "Capability to RECEIVE the ORF from this neighbor\n"
3967 "Capability to SEND the ORF to this neighbor\n")
3968
3969 /* neighbor next-hop-self. */
3970 DEFUN (neighbor_nexthop_self,
3971 neighbor_nexthop_self_cmd,
3972 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3973 NEIGHBOR_STR
3974 NEIGHBOR_ADDR_STR2
3975 "Disable the next hop calculation for this neighbor\n")
3976 {
3977 int idx_peer = 1;
3978 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3979 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
3980 }
3981
3982 ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
3983 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3984 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3985 "Disable the next hop calculation for this neighbor\n")
3986
3987 /* neighbor next-hop-self. */
3988 DEFUN (neighbor_nexthop_self_force,
3989 neighbor_nexthop_self_force_cmd,
3990 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3991 NEIGHBOR_STR
3992 NEIGHBOR_ADDR_STR2
3993 "Disable the next hop calculation for this neighbor\n"
3994 "Set the next hop to self for reflected routes\n")
3995 {
3996 int idx_peer = 1;
3997 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3998 bgp_node_safi(vty),
3999 PEER_FLAG_FORCE_NEXTHOP_SELF);
4000 }
4001
4002 ALIAS_HIDDEN(neighbor_nexthop_self_force,
4003 neighbor_nexthop_self_force_hidden_cmd,
4004 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
4005 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4006 "Disable the next hop calculation for this neighbor\n"
4007 "Set the next hop to self for reflected routes\n")
4008
4009 ALIAS_HIDDEN(neighbor_nexthop_self_force,
4010 neighbor_nexthop_self_all_hidden_cmd,
4011 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
4012 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4013 "Disable the next hop calculation for this neighbor\n"
4014 "Set the next hop to self for reflected routes\n")
4015
4016 DEFUN (no_neighbor_nexthop_self,
4017 no_neighbor_nexthop_self_cmd,
4018 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
4019 NO_STR
4020 NEIGHBOR_STR
4021 NEIGHBOR_ADDR_STR2
4022 "Disable the next hop calculation for this neighbor\n")
4023 {
4024 int idx_peer = 2;
4025 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4026 bgp_node_afi(vty), bgp_node_safi(vty),
4027 PEER_FLAG_NEXTHOP_SELF);
4028 }
4029
4030 ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
4031 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
4032 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4033 "Disable the next hop calculation for this neighbor\n")
4034
4035 DEFUN (no_neighbor_nexthop_self_force,
4036 no_neighbor_nexthop_self_force_cmd,
4037 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
4038 NO_STR
4039 NEIGHBOR_STR
4040 NEIGHBOR_ADDR_STR2
4041 "Disable the next hop calculation for this neighbor\n"
4042 "Set the next hop to self for reflected routes\n")
4043 {
4044 int idx_peer = 2;
4045 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4046 bgp_node_afi(vty), bgp_node_safi(vty),
4047 PEER_FLAG_FORCE_NEXTHOP_SELF);
4048 }
4049
4050 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
4051 no_neighbor_nexthop_self_force_hidden_cmd,
4052 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
4053 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4054 "Disable the next hop calculation for this neighbor\n"
4055 "Set the next hop to self for reflected routes\n")
4056
4057 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
4058 no_neighbor_nexthop_self_all_hidden_cmd,
4059 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
4060 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4061 "Disable the next hop calculation for this neighbor\n"
4062 "Set the next hop to self for reflected routes\n")
4063
4064 /* neighbor as-override */
4065 DEFUN (neighbor_as_override,
4066 neighbor_as_override_cmd,
4067 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4068 NEIGHBOR_STR
4069 NEIGHBOR_ADDR_STR2
4070 "Override ASNs in outbound updates if aspath equals remote-as\n")
4071 {
4072 int idx_peer = 1;
4073 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4074 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
4075 }
4076
4077 ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
4078 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4079 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4080 "Override ASNs in outbound updates if aspath equals remote-as\n")
4081
4082 DEFUN (no_neighbor_as_override,
4083 no_neighbor_as_override_cmd,
4084 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4085 NO_STR
4086 NEIGHBOR_STR
4087 NEIGHBOR_ADDR_STR2
4088 "Override ASNs in outbound updates if aspath equals remote-as\n")
4089 {
4090 int idx_peer = 2;
4091 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4092 bgp_node_afi(vty), bgp_node_safi(vty),
4093 PEER_FLAG_AS_OVERRIDE);
4094 }
4095
4096 ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
4097 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4098 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4099 "Override ASNs in outbound updates if aspath equals remote-as\n")
4100
4101 /* neighbor remove-private-AS. */
4102 DEFUN (neighbor_remove_private_as,
4103 neighbor_remove_private_as_cmd,
4104 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4105 NEIGHBOR_STR
4106 NEIGHBOR_ADDR_STR2
4107 "Remove private ASNs in outbound updates\n")
4108 {
4109 int idx_peer = 1;
4110 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4111 bgp_node_safi(vty),
4112 PEER_FLAG_REMOVE_PRIVATE_AS);
4113 }
4114
4115 ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
4116 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4117 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4118 "Remove private ASNs in outbound updates\n")
4119
4120 DEFUN (neighbor_remove_private_as_all,
4121 neighbor_remove_private_as_all_cmd,
4122 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4123 NEIGHBOR_STR
4124 NEIGHBOR_ADDR_STR2
4125 "Remove private ASNs in outbound updates\n"
4126 "Apply to all AS numbers\n")
4127 {
4128 int idx_peer = 1;
4129 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4130 bgp_node_safi(vty),
4131 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
4132 }
4133
4134 ALIAS_HIDDEN(neighbor_remove_private_as_all,
4135 neighbor_remove_private_as_all_hidden_cmd,
4136 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4137 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4138 "Remove private ASNs in outbound updates\n"
4139 "Apply to all AS numbers")
4140
4141 DEFUN (neighbor_remove_private_as_replace_as,
4142 neighbor_remove_private_as_replace_as_cmd,
4143 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4144 NEIGHBOR_STR
4145 NEIGHBOR_ADDR_STR2
4146 "Remove private ASNs in outbound updates\n"
4147 "Replace private ASNs with our ASN in outbound updates\n")
4148 {
4149 int idx_peer = 1;
4150 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4151 bgp_node_safi(vty),
4152 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
4153 }
4154
4155 ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
4156 neighbor_remove_private_as_replace_as_hidden_cmd,
4157 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4158 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4159 "Remove private ASNs in outbound updates\n"
4160 "Replace private ASNs with our ASN in outbound updates\n")
4161
4162 DEFUN (neighbor_remove_private_as_all_replace_as,
4163 neighbor_remove_private_as_all_replace_as_cmd,
4164 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4165 NEIGHBOR_STR
4166 NEIGHBOR_ADDR_STR2
4167 "Remove private ASNs in outbound updates\n"
4168 "Apply to all AS numbers\n"
4169 "Replace private ASNs with our ASN in outbound updates\n")
4170 {
4171 int idx_peer = 1;
4172 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4173 bgp_node_safi(vty),
4174 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
4175 }
4176
4177 ALIAS_HIDDEN(
4178 neighbor_remove_private_as_all_replace_as,
4179 neighbor_remove_private_as_all_replace_as_hidden_cmd,
4180 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4181 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4182 "Remove private ASNs in outbound updates\n"
4183 "Apply to all AS numbers\n"
4184 "Replace private ASNs with our ASN in outbound updates\n")
4185
4186 DEFUN (no_neighbor_remove_private_as,
4187 no_neighbor_remove_private_as_cmd,
4188 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4189 NO_STR
4190 NEIGHBOR_STR
4191 NEIGHBOR_ADDR_STR2
4192 "Remove private ASNs in outbound updates\n")
4193 {
4194 int idx_peer = 2;
4195 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4196 bgp_node_afi(vty), bgp_node_safi(vty),
4197 PEER_FLAG_REMOVE_PRIVATE_AS);
4198 }
4199
4200 ALIAS_HIDDEN(no_neighbor_remove_private_as,
4201 no_neighbor_remove_private_as_hidden_cmd,
4202 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4203 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4204 "Remove private ASNs in outbound updates\n")
4205
4206 DEFUN (no_neighbor_remove_private_as_all,
4207 no_neighbor_remove_private_as_all_cmd,
4208 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4209 NO_STR
4210 NEIGHBOR_STR
4211 NEIGHBOR_ADDR_STR2
4212 "Remove private ASNs in outbound updates\n"
4213 "Apply to all AS numbers\n")
4214 {
4215 int idx_peer = 2;
4216 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4217 bgp_node_afi(vty), bgp_node_safi(vty),
4218 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
4219 }
4220
4221 ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
4222 no_neighbor_remove_private_as_all_hidden_cmd,
4223 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4224 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4225 "Remove private ASNs in outbound updates\n"
4226 "Apply to all AS numbers\n")
4227
4228 DEFUN (no_neighbor_remove_private_as_replace_as,
4229 no_neighbor_remove_private_as_replace_as_cmd,
4230 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4231 NO_STR
4232 NEIGHBOR_STR
4233 NEIGHBOR_ADDR_STR2
4234 "Remove private ASNs in outbound updates\n"
4235 "Replace private ASNs with our ASN in outbound updates\n")
4236 {
4237 int idx_peer = 2;
4238 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4239 bgp_node_afi(vty), bgp_node_safi(vty),
4240 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
4241 }
4242
4243 ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
4244 no_neighbor_remove_private_as_replace_as_hidden_cmd,
4245 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4246 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4247 "Remove private ASNs in outbound updates\n"
4248 "Replace private ASNs with our ASN in outbound updates\n")
4249
4250 DEFUN (no_neighbor_remove_private_as_all_replace_as,
4251 no_neighbor_remove_private_as_all_replace_as_cmd,
4252 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4253 NO_STR
4254 NEIGHBOR_STR
4255 NEIGHBOR_ADDR_STR2
4256 "Remove private ASNs in outbound updates\n"
4257 "Apply to all AS numbers\n"
4258 "Replace private ASNs with our ASN in outbound updates\n")
4259 {
4260 int idx_peer = 2;
4261 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4262 bgp_node_afi(vty), bgp_node_safi(vty),
4263 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
4264 }
4265
4266 ALIAS_HIDDEN(
4267 no_neighbor_remove_private_as_all_replace_as,
4268 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
4269 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4270 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4271 "Remove private ASNs in outbound updates\n"
4272 "Apply to all AS numbers\n"
4273 "Replace private ASNs with our ASN in outbound updates\n")
4274
4275
4276 /* neighbor send-community. */
4277 DEFUN (neighbor_send_community,
4278 neighbor_send_community_cmd,
4279 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4280 NEIGHBOR_STR
4281 NEIGHBOR_ADDR_STR2
4282 "Send Community attribute to this neighbor\n")
4283 {
4284 int idx_peer = 1;
4285
4286 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4287 bgp_node_safi(vty),
4288 PEER_FLAG_SEND_COMMUNITY);
4289 }
4290
4291 ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
4292 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4293 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4294 "Send Community attribute to this neighbor\n")
4295
4296 DEFUN (no_neighbor_send_community,
4297 no_neighbor_send_community_cmd,
4298 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4299 NO_STR
4300 NEIGHBOR_STR
4301 NEIGHBOR_ADDR_STR2
4302 "Send Community attribute to this neighbor\n")
4303 {
4304 int idx_peer = 2;
4305
4306 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4307 bgp_node_afi(vty), bgp_node_safi(vty),
4308 PEER_FLAG_SEND_COMMUNITY);
4309 }
4310
4311 ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
4312 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4313 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4314 "Send Community attribute to this neighbor\n")
4315
4316 /* neighbor send-community extended. */
4317 DEFUN (neighbor_send_community_type,
4318 neighbor_send_community_type_cmd,
4319 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4320 NEIGHBOR_STR
4321 NEIGHBOR_ADDR_STR2
4322 "Send Community attribute to this neighbor\n"
4323 "Send Standard and Extended Community attributes\n"
4324 "Send Standard, Large and Extended Community attributes\n"
4325 "Send Extended Community attributes\n"
4326 "Send Standard Community attributes\n"
4327 "Send Large Community attributes\n")
4328 {
4329 int idx_peer = 1;
4330 uint32_t flag = 0;
4331 const char *type = argv[argc - 1]->text;
4332
4333 if (strmatch(type, "standard")) {
4334 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4335 } else if (strmatch(type, "extended")) {
4336 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4337 } else if (strmatch(type, "large")) {
4338 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4339 } else if (strmatch(type, "both")) {
4340 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4341 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4342 } else { /* if (strmatch(type, "all")) */
4343 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4344 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4345 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4346 }
4347
4348 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4349 bgp_node_safi(vty), flag);
4350 }
4351
4352 ALIAS_HIDDEN(
4353 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
4354 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4355 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4356 "Send Community attribute to this neighbor\n"
4357 "Send Standard and Extended Community attributes\n"
4358 "Send Standard, Large and Extended Community attributes\n"
4359 "Send Extended Community attributes\n"
4360 "Send Standard Community attributes\n"
4361 "Send Large Community attributes\n")
4362
4363 DEFUN (no_neighbor_send_community_type,
4364 no_neighbor_send_community_type_cmd,
4365 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4366 NO_STR
4367 NEIGHBOR_STR
4368 NEIGHBOR_ADDR_STR2
4369 "Send Community attribute to this neighbor\n"
4370 "Send Standard and Extended Community attributes\n"
4371 "Send Standard, Large and Extended Community attributes\n"
4372 "Send Extended Community attributes\n"
4373 "Send Standard Community attributes\n"
4374 "Send Large Community attributes\n")
4375 {
4376 int idx_peer = 2;
4377 uint32_t flag = 0;
4378 const char *type = argv[argc - 1]->text;
4379
4380 if (strmatch(type, "standard")) {
4381 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4382 } else if (strmatch(type, "extended")) {
4383 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4384 } else if (strmatch(type, "large")) {
4385 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4386 } else if (strmatch(type, "both")) {
4387 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4388 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4389 } else { /* if (strmatch(type, "all")) */
4390 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4391 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4392 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4393 }
4394
4395 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4396 bgp_node_afi(vty), bgp_node_safi(vty),
4397 flag);
4398 }
4399
4400 ALIAS_HIDDEN(
4401 no_neighbor_send_community_type,
4402 no_neighbor_send_community_type_hidden_cmd,
4403 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4404 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4405 "Send Community attribute to this neighbor\n"
4406 "Send Standard and Extended Community attributes\n"
4407 "Send Standard, Large and Extended Community attributes\n"
4408 "Send Extended Community attributes\n"
4409 "Send Standard Community attributes\n"
4410 "Send Large Community attributes\n")
4411
4412 /* neighbor soft-reconfig. */
4413 DEFUN (neighbor_soft_reconfiguration,
4414 neighbor_soft_reconfiguration_cmd,
4415 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4416 NEIGHBOR_STR
4417 NEIGHBOR_ADDR_STR2
4418 "Per neighbor soft reconfiguration\n"
4419 "Allow inbound soft reconfiguration for this neighbor\n")
4420 {
4421 int idx_peer = 1;
4422 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4423 bgp_node_safi(vty),
4424 PEER_FLAG_SOFT_RECONFIG);
4425 }
4426
4427 ALIAS_HIDDEN(neighbor_soft_reconfiguration,
4428 neighbor_soft_reconfiguration_hidden_cmd,
4429 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4430 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4431 "Per neighbor soft reconfiguration\n"
4432 "Allow inbound soft reconfiguration for this neighbor\n")
4433
4434 DEFUN (no_neighbor_soft_reconfiguration,
4435 no_neighbor_soft_reconfiguration_cmd,
4436 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4437 NO_STR
4438 NEIGHBOR_STR
4439 NEIGHBOR_ADDR_STR2
4440 "Per neighbor soft reconfiguration\n"
4441 "Allow inbound soft reconfiguration for this neighbor\n")
4442 {
4443 int idx_peer = 2;
4444 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4445 bgp_node_afi(vty), bgp_node_safi(vty),
4446 PEER_FLAG_SOFT_RECONFIG);
4447 }
4448
4449 ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
4450 no_neighbor_soft_reconfiguration_hidden_cmd,
4451 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4452 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4453 "Per neighbor soft reconfiguration\n"
4454 "Allow inbound soft reconfiguration for this neighbor\n")
4455
4456 DEFUN (neighbor_route_reflector_client,
4457 neighbor_route_reflector_client_cmd,
4458 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4459 NEIGHBOR_STR
4460 NEIGHBOR_ADDR_STR2
4461 "Configure a neighbor as Route Reflector client\n")
4462 {
4463 int idx_peer = 1;
4464 struct peer *peer;
4465
4466
4467 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4468 if (!peer)
4469 return CMD_WARNING_CONFIG_FAILED;
4470
4471 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4472 bgp_node_safi(vty),
4473 PEER_FLAG_REFLECTOR_CLIENT);
4474 }
4475
4476 ALIAS_HIDDEN(neighbor_route_reflector_client,
4477 neighbor_route_reflector_client_hidden_cmd,
4478 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4479 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4480 "Configure a neighbor as Route Reflector client\n")
4481
4482 DEFUN (no_neighbor_route_reflector_client,
4483 no_neighbor_route_reflector_client_cmd,
4484 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4485 NO_STR
4486 NEIGHBOR_STR
4487 NEIGHBOR_ADDR_STR2
4488 "Configure a neighbor as Route Reflector client\n")
4489 {
4490 int idx_peer = 2;
4491 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4492 bgp_node_afi(vty), bgp_node_safi(vty),
4493 PEER_FLAG_REFLECTOR_CLIENT);
4494 }
4495
4496 ALIAS_HIDDEN(no_neighbor_route_reflector_client,
4497 no_neighbor_route_reflector_client_hidden_cmd,
4498 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4499 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4500 "Configure a neighbor as Route Reflector client\n")
4501
4502 /* neighbor route-server-client. */
4503 DEFUN (neighbor_route_server_client,
4504 neighbor_route_server_client_cmd,
4505 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4506 NEIGHBOR_STR
4507 NEIGHBOR_ADDR_STR2
4508 "Configure a neighbor as Route Server client\n")
4509 {
4510 int idx_peer = 1;
4511 struct peer *peer;
4512
4513 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4514 if (!peer)
4515 return CMD_WARNING_CONFIG_FAILED;
4516 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4517 bgp_node_safi(vty),
4518 PEER_FLAG_RSERVER_CLIENT);
4519 }
4520
4521 ALIAS_HIDDEN(neighbor_route_server_client,
4522 neighbor_route_server_client_hidden_cmd,
4523 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4524 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4525 "Configure a neighbor as Route Server client\n")
4526
4527 DEFUN (no_neighbor_route_server_client,
4528 no_neighbor_route_server_client_cmd,
4529 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4530 NO_STR
4531 NEIGHBOR_STR
4532 NEIGHBOR_ADDR_STR2
4533 "Configure a neighbor as Route Server client\n")
4534 {
4535 int idx_peer = 2;
4536 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4537 bgp_node_afi(vty), bgp_node_safi(vty),
4538 PEER_FLAG_RSERVER_CLIENT);
4539 }
4540
4541 ALIAS_HIDDEN(no_neighbor_route_server_client,
4542 no_neighbor_route_server_client_hidden_cmd,
4543 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4544 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4545 "Configure a neighbor as Route Server client\n")
4546
4547 DEFUN (neighbor_nexthop_local_unchanged,
4548 neighbor_nexthop_local_unchanged_cmd,
4549 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
4550 NEIGHBOR_STR
4551 NEIGHBOR_ADDR_STR2
4552 "Configure treatment of outgoing link-local nexthop attribute\n"
4553 "Leave link-local nexthop unchanged for this peer\n")
4554 {
4555 int idx_peer = 1;
4556 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4557 bgp_node_safi(vty),
4558 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
4559 }
4560
4561 DEFUN (no_neighbor_nexthop_local_unchanged,
4562 no_neighbor_nexthop_local_unchanged_cmd,
4563 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
4564 NO_STR
4565 NEIGHBOR_STR
4566 NEIGHBOR_ADDR_STR2
4567 "Configure treatment of outgoing link-local-nexthop attribute\n"
4568 "Leave link-local nexthop unchanged for this peer\n")
4569 {
4570 int idx_peer = 2;
4571 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4572 bgp_node_afi(vty), bgp_node_safi(vty),
4573 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
4574 }
4575
4576 DEFUN (neighbor_attr_unchanged,
4577 neighbor_attr_unchanged_cmd,
4578 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4579 NEIGHBOR_STR
4580 NEIGHBOR_ADDR_STR2
4581 "BGP attribute is propagated unchanged to this neighbor\n"
4582 "As-path attribute\n"
4583 "Nexthop attribute\n"
4584 "Med attribute\n")
4585 {
4586 int idx = 0;
4587 char *peer_str = argv[1]->arg;
4588 struct peer *peer;
4589 uint16_t flags = 0;
4590 afi_t afi = bgp_node_afi(vty);
4591 safi_t safi = bgp_node_safi(vty);
4592
4593 peer = peer_and_group_lookup_vty(vty, peer_str);
4594 if (!peer)
4595 return CMD_WARNING_CONFIG_FAILED;
4596
4597 if (argv_find(argv, argc, "as-path", &idx))
4598 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4599 idx = 0;
4600 if (argv_find(argv, argc, "next-hop", &idx))
4601 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4602 idx = 0;
4603 if (argv_find(argv, argc, "med", &idx))
4604 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4605
4606 /* no flags means all of them! */
4607 if (!flags) {
4608 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4609 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4610 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4611 } else {
4612 if (!CHECK_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED)
4613 && peer_af_flag_check(peer, afi, safi,
4614 PEER_FLAG_AS_PATH_UNCHANGED)) {
4615 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4616 PEER_FLAG_AS_PATH_UNCHANGED);
4617 }
4618
4619 if (!CHECK_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED)
4620 && peer_af_flag_check(peer, afi, safi,
4621 PEER_FLAG_NEXTHOP_UNCHANGED)) {
4622 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4623 PEER_FLAG_NEXTHOP_UNCHANGED);
4624 }
4625
4626 if (!CHECK_FLAG(flags, PEER_FLAG_MED_UNCHANGED)
4627 && peer_af_flag_check(peer, afi, safi,
4628 PEER_FLAG_MED_UNCHANGED)) {
4629 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4630 PEER_FLAG_MED_UNCHANGED);
4631 }
4632 }
4633
4634 return peer_af_flag_set_vty(vty, peer_str, afi, safi, flags);
4635 }
4636
4637 ALIAS_HIDDEN(
4638 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
4639 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4640 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4641 "BGP attribute is propagated unchanged to this neighbor\n"
4642 "As-path attribute\n"
4643 "Nexthop attribute\n"
4644 "Med attribute\n")
4645
4646 DEFUN (no_neighbor_attr_unchanged,
4647 no_neighbor_attr_unchanged_cmd,
4648 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4649 NO_STR
4650 NEIGHBOR_STR
4651 NEIGHBOR_ADDR_STR2
4652 "BGP attribute is propagated unchanged to this neighbor\n"
4653 "As-path attribute\n"
4654 "Nexthop attribute\n"
4655 "Med attribute\n")
4656 {
4657 int idx = 0;
4658 char *peer = argv[2]->arg;
4659 uint16_t flags = 0;
4660
4661 if (argv_find(argv, argc, "as-path", &idx))
4662 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4663 idx = 0;
4664 if (argv_find(argv, argc, "next-hop", &idx))
4665 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4666 idx = 0;
4667 if (argv_find(argv, argc, "med", &idx))
4668 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4669
4670 if (!flags) // no flags means all of them!
4671 {
4672 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4673 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4674 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4675 }
4676
4677 return peer_af_flag_unset_vty(vty, peer, bgp_node_afi(vty),
4678 bgp_node_safi(vty), flags);
4679 }
4680
4681 ALIAS_HIDDEN(
4682 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
4683 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4684 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4685 "BGP attribute is propagated unchanged to this neighbor\n"
4686 "As-path attribute\n"
4687 "Nexthop attribute\n"
4688 "Med attribute\n")
4689
4690 /* EBGP multihop configuration. */
4691 static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
4692 const char *ttl_str)
4693 {
4694 struct peer *peer;
4695 unsigned int ttl;
4696
4697 peer = peer_and_group_lookup_vty(vty, ip_str);
4698 if (!peer)
4699 return CMD_WARNING_CONFIG_FAILED;
4700
4701 if (peer->conf_if)
4702 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
4703
4704 if (!ttl_str)
4705 ttl = MAXTTL;
4706 else
4707 ttl = strtoul(ttl_str, NULL, 10);
4708
4709 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
4710 }
4711
4712 static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
4713 {
4714 struct peer *peer;
4715
4716 peer = peer_and_group_lookup_vty(vty, ip_str);
4717 if (!peer)
4718 return CMD_WARNING_CONFIG_FAILED;
4719
4720 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
4721 }
4722
4723 /* neighbor ebgp-multihop. */
4724 DEFUN (neighbor_ebgp_multihop,
4725 neighbor_ebgp_multihop_cmd,
4726 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
4727 NEIGHBOR_STR
4728 NEIGHBOR_ADDR_STR2
4729 "Allow EBGP neighbors not on directly connected networks\n")
4730 {
4731 int idx_peer = 1;
4732 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
4733 }
4734
4735 DEFUN (neighbor_ebgp_multihop_ttl,
4736 neighbor_ebgp_multihop_ttl_cmd,
4737 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
4738 NEIGHBOR_STR
4739 NEIGHBOR_ADDR_STR2
4740 "Allow EBGP neighbors not on directly connected networks\n"
4741 "maximum hop count\n")
4742 {
4743 int idx_peer = 1;
4744 int idx_number = 3;
4745 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
4746 argv[idx_number]->arg);
4747 }
4748
4749 DEFUN (no_neighbor_ebgp_multihop,
4750 no_neighbor_ebgp_multihop_cmd,
4751 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
4752 NO_STR
4753 NEIGHBOR_STR
4754 NEIGHBOR_ADDR_STR2
4755 "Allow EBGP neighbors not on directly connected networks\n"
4756 "maximum hop count\n")
4757 {
4758 int idx_peer = 2;
4759 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
4760 }
4761
4762
4763 /* disable-connected-check */
4764 DEFUN (neighbor_disable_connected_check,
4765 neighbor_disable_connected_check_cmd,
4766 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
4767 NEIGHBOR_STR
4768 NEIGHBOR_ADDR_STR2
4769 "one-hop away EBGP peer using loopback address\n"
4770 "Enforce EBGP neighbors perform multihop\n")
4771 {
4772 int idx_peer = 1;
4773 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4774 PEER_FLAG_DISABLE_CONNECTED_CHECK);
4775 }
4776
4777 DEFUN (no_neighbor_disable_connected_check,
4778 no_neighbor_disable_connected_check_cmd,
4779 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
4780 NO_STR
4781 NEIGHBOR_STR
4782 NEIGHBOR_ADDR_STR2
4783 "one-hop away EBGP peer using loopback address\n"
4784 "Enforce EBGP neighbors perform multihop\n")
4785 {
4786 int idx_peer = 2;
4787 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4788 PEER_FLAG_DISABLE_CONNECTED_CHECK);
4789 }
4790
4791
4792 /* enforce-first-as */
4793 DEFUN (neighbor_enforce_first_as,
4794 neighbor_enforce_first_as_cmd,
4795 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4796 NEIGHBOR_STR
4797 NEIGHBOR_ADDR_STR2
4798 "Enforce the first AS for EBGP routes\n")
4799 {
4800 int idx_peer = 1;
4801
4802 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4803 PEER_FLAG_ENFORCE_FIRST_AS);
4804 }
4805
4806 DEFUN (no_neighbor_enforce_first_as,
4807 no_neighbor_enforce_first_as_cmd,
4808 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4809 NO_STR
4810 NEIGHBOR_STR
4811 NEIGHBOR_ADDR_STR2
4812 "Enforce the first AS for EBGP routes\n")
4813 {
4814 int idx_peer = 2;
4815
4816 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4817 PEER_FLAG_ENFORCE_FIRST_AS);
4818 }
4819
4820
4821 DEFUN (neighbor_description,
4822 neighbor_description_cmd,
4823 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4824 NEIGHBOR_STR
4825 NEIGHBOR_ADDR_STR2
4826 "Neighbor specific description\n"
4827 "Up to 80 characters describing this neighbor\n")
4828 {
4829 int idx_peer = 1;
4830 int idx_line = 3;
4831 struct peer *peer;
4832 char *str;
4833
4834 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4835 if (!peer)
4836 return CMD_WARNING_CONFIG_FAILED;
4837
4838 str = argv_concat(argv, argc, idx_line);
4839
4840 peer_description_set(peer, str);
4841
4842 XFREE(MTYPE_TMP, str);
4843
4844 return CMD_SUCCESS;
4845 }
4846
4847 DEFUN (no_neighbor_description,
4848 no_neighbor_description_cmd,
4849 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
4850 NO_STR
4851 NEIGHBOR_STR
4852 NEIGHBOR_ADDR_STR2
4853 "Neighbor specific description\n")
4854 {
4855 int idx_peer = 2;
4856 struct peer *peer;
4857
4858 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4859 if (!peer)
4860 return CMD_WARNING_CONFIG_FAILED;
4861
4862 peer_description_unset(peer);
4863
4864 return CMD_SUCCESS;
4865 }
4866
4867 ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
4868 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4869 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4870 "Neighbor specific description\n"
4871 "Up to 80 characters describing this neighbor\n")
4872
4873 /* Neighbor update-source. */
4874 static int peer_update_source_vty(struct vty *vty, const char *peer_str,
4875 const char *source_str)
4876 {
4877 struct peer *peer;
4878 struct prefix p;
4879 union sockunion su;
4880
4881 peer = peer_and_group_lookup_vty(vty, peer_str);
4882 if (!peer)
4883 return CMD_WARNING_CONFIG_FAILED;
4884
4885 if (peer->conf_if)
4886 return CMD_WARNING;
4887
4888 if (source_str) {
4889 if (str2sockunion(source_str, &su) == 0)
4890 peer_update_source_addr_set(peer, &su);
4891 else {
4892 if (str2prefix(source_str, &p)) {
4893 vty_out(vty,
4894 "%% Invalid update-source, remove prefix length \n");
4895 return CMD_WARNING_CONFIG_FAILED;
4896 } else
4897 peer_update_source_if_set(peer, source_str);
4898 }
4899 } else
4900 peer_update_source_unset(peer);
4901
4902 return CMD_SUCCESS;
4903 }
4904
4905 #define BGP_UPDATE_SOURCE_HELP_STR \
4906 "IPv4 address\n" \
4907 "IPv6 address\n" \
4908 "Interface name (requires zebra to be running)\n"
4909
4910 DEFUN (neighbor_update_source,
4911 neighbor_update_source_cmd,
4912 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
4913 NEIGHBOR_STR
4914 NEIGHBOR_ADDR_STR2
4915 "Source of routing updates\n"
4916 BGP_UPDATE_SOURCE_HELP_STR)
4917 {
4918 int idx_peer = 1;
4919 int idx_peer_2 = 3;
4920 return peer_update_source_vty(vty, argv[idx_peer]->arg,
4921 argv[idx_peer_2]->arg);
4922 }
4923
4924 DEFUN (no_neighbor_update_source,
4925 no_neighbor_update_source_cmd,
4926 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
4927 NO_STR
4928 NEIGHBOR_STR
4929 NEIGHBOR_ADDR_STR2
4930 "Source of routing updates\n"
4931 BGP_UPDATE_SOURCE_HELP_STR)
4932 {
4933 int idx_peer = 2;
4934 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
4935 }
4936
4937 static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
4938 afi_t afi, safi_t safi,
4939 const char *rmap, int set)
4940 {
4941 int ret;
4942 struct peer *peer;
4943 struct route_map *route_map = NULL;
4944
4945 peer = peer_and_group_lookup_vty(vty, peer_str);
4946 if (!peer)
4947 return CMD_WARNING_CONFIG_FAILED;
4948
4949 if (set) {
4950 if (rmap)
4951 route_map = route_map_lookup_warn_noexist(vty, rmap);
4952 ret = peer_default_originate_set(peer, afi, safi,
4953 rmap, route_map);
4954 } else
4955 ret = peer_default_originate_unset(peer, afi, safi);
4956
4957 return bgp_vty_return(vty, ret);
4958 }
4959
4960 /* neighbor default-originate. */
4961 DEFUN (neighbor_default_originate,
4962 neighbor_default_originate_cmd,
4963 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4964 NEIGHBOR_STR
4965 NEIGHBOR_ADDR_STR2
4966 "Originate default route to this neighbor\n")
4967 {
4968 int idx_peer = 1;
4969 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4970 bgp_node_afi(vty),
4971 bgp_node_safi(vty), NULL, 1);
4972 }
4973
4974 ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
4975 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4976 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4977 "Originate default route to this neighbor\n")
4978
4979 DEFUN (neighbor_default_originate_rmap,
4980 neighbor_default_originate_rmap_cmd,
4981 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4982 NEIGHBOR_STR
4983 NEIGHBOR_ADDR_STR2
4984 "Originate default route to this neighbor\n"
4985 "Route-map to specify criteria to originate default\n"
4986 "route-map name\n")
4987 {
4988 int idx_peer = 1;
4989 int idx_word = 4;
4990 return peer_default_originate_set_vty(
4991 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
4992 argv[idx_word]->arg, 1);
4993 }
4994
4995 ALIAS_HIDDEN(
4996 neighbor_default_originate_rmap,
4997 neighbor_default_originate_rmap_hidden_cmd,
4998 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4999 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5000 "Originate default route to this neighbor\n"
5001 "Route-map to specify criteria to originate default\n"
5002 "route-map name\n")
5003
5004 DEFUN (no_neighbor_default_originate,
5005 no_neighbor_default_originate_cmd,
5006 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
5007 NO_STR
5008 NEIGHBOR_STR
5009 NEIGHBOR_ADDR_STR2
5010 "Originate default route to this neighbor\n"
5011 "Route-map to specify criteria to originate default\n"
5012 "route-map name\n")
5013 {
5014 int idx_peer = 2;
5015 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
5016 bgp_node_afi(vty),
5017 bgp_node_safi(vty), NULL, 0);
5018 }
5019
5020 ALIAS_HIDDEN(
5021 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
5022 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
5023 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5024 "Originate default route to this neighbor\n"
5025 "Route-map to specify criteria to originate default\n"
5026 "route-map name\n")
5027
5028
5029 /* Set neighbor's BGP port. */
5030 static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
5031 const char *port_str)
5032 {
5033 struct peer *peer;
5034 uint16_t port;
5035 struct servent *sp;
5036
5037 peer = peer_lookup_vty(vty, ip_str);
5038 if (!peer)
5039 return CMD_WARNING_CONFIG_FAILED;
5040
5041 if (!port_str) {
5042 sp = getservbyname("bgp", "tcp");
5043 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
5044 } else {
5045 port = strtoul(port_str, NULL, 10);
5046 }
5047
5048 peer_port_set(peer, port);
5049
5050 return CMD_SUCCESS;
5051 }
5052
5053 /* Set specified peer's BGP port. */
5054 DEFUN (neighbor_port,
5055 neighbor_port_cmd,
5056 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
5057 NEIGHBOR_STR
5058 NEIGHBOR_ADDR_STR
5059 "Neighbor's BGP port\n"
5060 "TCP port number\n")
5061 {
5062 int idx_ip = 1;
5063 int idx_number = 3;
5064 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
5065 argv[idx_number]->arg);
5066 }
5067
5068 DEFUN (no_neighbor_port,
5069 no_neighbor_port_cmd,
5070 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
5071 NO_STR
5072 NEIGHBOR_STR
5073 NEIGHBOR_ADDR_STR
5074 "Neighbor's BGP port\n"
5075 "TCP port number\n")
5076 {
5077 int idx_ip = 2;
5078 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
5079 }
5080
5081
5082 /* neighbor weight. */
5083 static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5084 safi_t safi, const char *weight_str)
5085 {
5086 int ret;
5087 struct peer *peer;
5088 unsigned long weight;
5089
5090 peer = peer_and_group_lookup_vty(vty, ip_str);
5091 if (!peer)
5092 return CMD_WARNING_CONFIG_FAILED;
5093
5094 weight = strtoul(weight_str, NULL, 10);
5095
5096 ret = peer_weight_set(peer, afi, safi, weight);
5097 return bgp_vty_return(vty, ret);
5098 }
5099
5100 static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5101 safi_t safi)
5102 {
5103 int ret;
5104 struct peer *peer;
5105
5106 peer = peer_and_group_lookup_vty(vty, ip_str);
5107 if (!peer)
5108 return CMD_WARNING_CONFIG_FAILED;
5109
5110 ret = peer_weight_unset(peer, afi, safi);
5111 return bgp_vty_return(vty, ret);
5112 }
5113
5114 DEFUN (neighbor_weight,
5115 neighbor_weight_cmd,
5116 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
5117 NEIGHBOR_STR
5118 NEIGHBOR_ADDR_STR2
5119 "Set default weight for routes from this neighbor\n"
5120 "default weight\n")
5121 {
5122 int idx_peer = 1;
5123 int idx_number = 3;
5124 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5125 bgp_node_safi(vty), argv[idx_number]->arg);
5126 }
5127
5128 ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
5129 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
5130 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5131 "Set default weight for routes from this neighbor\n"
5132 "default weight\n")
5133
5134 DEFUN (no_neighbor_weight,
5135 no_neighbor_weight_cmd,
5136 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
5137 NO_STR
5138 NEIGHBOR_STR
5139 NEIGHBOR_ADDR_STR2
5140 "Set default weight for routes from this neighbor\n"
5141 "default weight\n")
5142 {
5143 int idx_peer = 2;
5144 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
5145 bgp_node_afi(vty), bgp_node_safi(vty));
5146 }
5147
5148 ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
5149 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
5150 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5151 "Set default weight for routes from this neighbor\n"
5152 "default weight\n")
5153
5154
5155 /* Override capability negotiation. */
5156 DEFUN (neighbor_override_capability,
5157 neighbor_override_capability_cmd,
5158 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
5159 NEIGHBOR_STR
5160 NEIGHBOR_ADDR_STR2
5161 "Override capability negotiation result\n")
5162 {
5163 int idx_peer = 1;
5164 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5165 PEER_FLAG_OVERRIDE_CAPABILITY);
5166 }
5167
5168 DEFUN (no_neighbor_override_capability,
5169 no_neighbor_override_capability_cmd,
5170 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
5171 NO_STR
5172 NEIGHBOR_STR
5173 NEIGHBOR_ADDR_STR2
5174 "Override capability negotiation result\n")
5175 {
5176 int idx_peer = 2;
5177 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5178 PEER_FLAG_OVERRIDE_CAPABILITY);
5179 }
5180
5181 DEFUN (neighbor_strict_capability,
5182 neighbor_strict_capability_cmd,
5183 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
5184 NEIGHBOR_STR
5185 NEIGHBOR_ADDR_STR2
5186 "Strict capability negotiation match\n")
5187 {
5188 int idx_peer = 1;
5189
5190 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5191 PEER_FLAG_STRICT_CAP_MATCH);
5192 }
5193
5194 DEFUN (no_neighbor_strict_capability,
5195 no_neighbor_strict_capability_cmd,
5196 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
5197 NO_STR
5198 NEIGHBOR_STR
5199 NEIGHBOR_ADDR_STR2
5200 "Strict capability negotiation match\n")
5201 {
5202 int idx_peer = 2;
5203
5204 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5205 PEER_FLAG_STRICT_CAP_MATCH);
5206 }
5207
5208 static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
5209 const char *keep_str, const char *hold_str)
5210 {
5211 int ret;
5212 struct peer *peer;
5213 uint32_t keepalive;
5214 uint32_t holdtime;
5215
5216 peer = peer_and_group_lookup_vty(vty, ip_str);
5217 if (!peer)
5218 return CMD_WARNING_CONFIG_FAILED;
5219
5220 keepalive = strtoul(keep_str, NULL, 10);
5221 holdtime = strtoul(hold_str, NULL, 10);
5222
5223 ret = peer_timers_set(peer, keepalive, holdtime);
5224
5225 return bgp_vty_return(vty, ret);
5226 }
5227
5228 static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
5229 {
5230 int ret;
5231 struct peer *peer;
5232
5233 peer = peer_and_group_lookup_vty(vty, ip_str);
5234 if (!peer)
5235 return CMD_WARNING_CONFIG_FAILED;
5236
5237 ret = peer_timers_unset(peer);
5238
5239 return bgp_vty_return(vty, ret);
5240 }
5241
5242 DEFUN (neighbor_timers,
5243 neighbor_timers_cmd,
5244 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
5245 NEIGHBOR_STR
5246 NEIGHBOR_ADDR_STR2
5247 "BGP per neighbor timers\n"
5248 "Keepalive interval\n"
5249 "Holdtime\n")
5250 {
5251 int idx_peer = 1;
5252 int idx_number = 3;
5253 int idx_number_2 = 4;
5254 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
5255 argv[idx_number]->arg,
5256 argv[idx_number_2]->arg);
5257 }
5258
5259 DEFUN (no_neighbor_timers,
5260 no_neighbor_timers_cmd,
5261 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
5262 NO_STR
5263 NEIGHBOR_STR
5264 NEIGHBOR_ADDR_STR2
5265 "BGP per neighbor timers\n"
5266 "Keepalive interval\n"
5267 "Holdtime\n")
5268 {
5269 int idx_peer = 2;
5270 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
5271 }
5272
5273
5274 static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
5275 const char *time_str)
5276 {
5277 int ret;
5278 struct peer *peer;
5279 uint32_t connect;
5280
5281 peer = peer_and_group_lookup_vty(vty, ip_str);
5282 if (!peer)
5283 return CMD_WARNING_CONFIG_FAILED;
5284
5285 connect = strtoul(time_str, NULL, 10);
5286
5287 ret = peer_timers_connect_set(peer, connect);
5288
5289 return bgp_vty_return(vty, ret);
5290 }
5291
5292 static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
5293 {
5294 int ret;
5295 struct peer *peer;
5296
5297 peer = peer_and_group_lookup_vty(vty, ip_str);
5298 if (!peer)
5299 return CMD_WARNING_CONFIG_FAILED;
5300
5301 ret = peer_timers_connect_unset(peer);
5302
5303 return bgp_vty_return(vty, ret);
5304 }
5305
5306 DEFUN (neighbor_timers_connect,
5307 neighbor_timers_connect_cmd,
5308 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
5309 NEIGHBOR_STR
5310 NEIGHBOR_ADDR_STR2
5311 "BGP per neighbor timers\n"
5312 "BGP connect timer\n"
5313 "Connect timer\n")
5314 {
5315 int idx_peer = 1;
5316 int idx_number = 4;
5317 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
5318 argv[idx_number]->arg);
5319 }
5320
5321 DEFUN (no_neighbor_timers_connect,
5322 no_neighbor_timers_connect_cmd,
5323 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
5324 NO_STR
5325 NEIGHBOR_STR
5326 NEIGHBOR_ADDR_STR2
5327 "BGP per neighbor timers\n"
5328 "BGP connect timer\n"
5329 "Connect timer\n")
5330 {
5331 int idx_peer = 2;
5332 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
5333 }
5334
5335
5336 static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
5337 const char *time_str, int set)
5338 {
5339 int ret;
5340 struct peer *peer;
5341 uint32_t routeadv = 0;
5342
5343 peer = peer_and_group_lookup_vty(vty, ip_str);
5344 if (!peer)
5345 return CMD_WARNING_CONFIG_FAILED;
5346
5347 if (time_str)
5348 routeadv = strtoul(time_str, NULL, 10);
5349
5350 if (set)
5351 ret = peer_advertise_interval_set(peer, routeadv);
5352 else
5353 ret = peer_advertise_interval_unset(peer);
5354
5355 return bgp_vty_return(vty, ret);
5356 }
5357
5358 DEFUN (neighbor_advertise_interval,
5359 neighbor_advertise_interval_cmd,
5360 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
5361 NEIGHBOR_STR
5362 NEIGHBOR_ADDR_STR2
5363 "Minimum interval between sending BGP routing updates\n"
5364 "time in seconds\n")
5365 {
5366 int idx_peer = 1;
5367 int idx_number = 3;
5368 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
5369 argv[idx_number]->arg, 1);
5370 }
5371
5372 DEFUN (no_neighbor_advertise_interval,
5373 no_neighbor_advertise_interval_cmd,
5374 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
5375 NO_STR
5376 NEIGHBOR_STR
5377 NEIGHBOR_ADDR_STR2
5378 "Minimum interval between sending BGP routing updates\n"
5379 "time in seconds\n")
5380 {
5381 int idx_peer = 2;
5382 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
5383 }
5384
5385
5386 /* Time to wait before processing route-map updates */
5387 DEFUN (bgp_set_route_map_delay_timer,
5388 bgp_set_route_map_delay_timer_cmd,
5389 "bgp route-map delay-timer (0-600)",
5390 SET_STR
5391 "BGP route-map delay timer\n"
5392 "Time in secs to wait before processing route-map changes\n"
5393 "0 disables the timer, no route updates happen when route-maps change\n")
5394 {
5395 int idx_number = 3;
5396 uint32_t rmap_delay_timer;
5397
5398 if (argv[idx_number]->arg) {
5399 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
5400 bm->rmap_update_timer = rmap_delay_timer;
5401
5402 /* if the dynamic update handling is being disabled, and a timer
5403 * is
5404 * running, stop the timer and act as if the timer has already
5405 * fired.
5406 */
5407 if (!rmap_delay_timer && bm->t_rmap_update) {
5408 BGP_TIMER_OFF(bm->t_rmap_update);
5409 thread_execute(bm->master, bgp_route_map_update_timer,
5410 NULL, 0);
5411 }
5412 return CMD_SUCCESS;
5413 } else {
5414 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
5415 return CMD_WARNING_CONFIG_FAILED;
5416 }
5417 }
5418
5419 DEFUN (no_bgp_set_route_map_delay_timer,
5420 no_bgp_set_route_map_delay_timer_cmd,
5421 "no bgp route-map delay-timer [(0-600)]",
5422 NO_STR
5423 BGP_STR
5424 "Default BGP route-map delay timer\n"
5425 "Reset to default time to wait for processing route-map changes\n"
5426 "0 disables the timer, no route updates happen when route-maps change\n")
5427 {
5428
5429 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
5430
5431 return CMD_SUCCESS;
5432 }
5433
5434
5435 /* neighbor interface */
5436 static int peer_interface_vty(struct vty *vty, const char *ip_str,
5437 const char *str)
5438 {
5439 struct peer *peer;
5440
5441 peer = peer_lookup_vty(vty, ip_str);
5442 if (!peer || peer->conf_if) {
5443 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
5444 return CMD_WARNING_CONFIG_FAILED;
5445 }
5446
5447 if (str)
5448 peer_interface_set(peer, str);
5449 else
5450 peer_interface_unset(peer);
5451
5452 return CMD_SUCCESS;
5453 }
5454
5455 DEFUN (neighbor_interface,
5456 neighbor_interface_cmd,
5457 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
5458 NEIGHBOR_STR
5459 NEIGHBOR_ADDR_STR
5460 "Interface\n"
5461 "Interface name\n")
5462 {
5463 int idx_ip = 1;
5464 int idx_word = 3;
5465 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
5466 }
5467
5468 DEFUN (no_neighbor_interface,
5469 no_neighbor_interface_cmd,
5470 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
5471 NO_STR
5472 NEIGHBOR_STR
5473 NEIGHBOR_ADDR_STR2
5474 "Interface\n"
5475 "Interface name\n")
5476 {
5477 int idx_peer = 2;
5478 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
5479 }
5480
5481 DEFUN (neighbor_distribute_list,
5482 neighbor_distribute_list_cmd,
5483 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5484 NEIGHBOR_STR
5485 NEIGHBOR_ADDR_STR2
5486 "Filter updates to/from this neighbor\n"
5487 "IP access-list number\n"
5488 "IP access-list number (expanded range)\n"
5489 "IP Access-list name\n"
5490 "Filter incoming updates\n"
5491 "Filter outgoing updates\n")
5492 {
5493 int idx_peer = 1;
5494 int idx_acl = 3;
5495 int direct, ret;
5496 struct peer *peer;
5497
5498 const char *pstr = argv[idx_peer]->arg;
5499 const char *acl = argv[idx_acl]->arg;
5500 const char *inout = argv[argc - 1]->text;
5501
5502 peer = peer_and_group_lookup_vty(vty, pstr);
5503 if (!peer)
5504 return CMD_WARNING_CONFIG_FAILED;
5505
5506 /* Check filter direction. */
5507 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5508 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5509 direct, acl);
5510
5511 return bgp_vty_return(vty, ret);
5512 }
5513
5514 ALIAS_HIDDEN(
5515 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
5516 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5517 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5518 "Filter updates to/from this neighbor\n"
5519 "IP access-list number\n"
5520 "IP access-list number (expanded range)\n"
5521 "IP Access-list name\n"
5522 "Filter incoming updates\n"
5523 "Filter outgoing updates\n")
5524
5525 DEFUN (no_neighbor_distribute_list,
5526 no_neighbor_distribute_list_cmd,
5527 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5528 NO_STR
5529 NEIGHBOR_STR
5530 NEIGHBOR_ADDR_STR2
5531 "Filter updates to/from this neighbor\n"
5532 "IP access-list number\n"
5533 "IP access-list number (expanded range)\n"
5534 "IP Access-list name\n"
5535 "Filter incoming updates\n"
5536 "Filter outgoing updates\n")
5537 {
5538 int idx_peer = 2;
5539 int direct, ret;
5540 struct peer *peer;
5541
5542 const char *pstr = argv[idx_peer]->arg;
5543 const char *inout = argv[argc - 1]->text;
5544
5545 peer = peer_and_group_lookup_vty(vty, pstr);
5546 if (!peer)
5547 return CMD_WARNING_CONFIG_FAILED;
5548
5549 /* Check filter direction. */
5550 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5551 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5552 direct);
5553
5554 return bgp_vty_return(vty, ret);
5555 }
5556
5557 ALIAS_HIDDEN(
5558 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
5559 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5560 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5561 "Filter updates to/from this neighbor\n"
5562 "IP access-list number\n"
5563 "IP access-list number (expanded range)\n"
5564 "IP Access-list name\n"
5565 "Filter incoming updates\n"
5566 "Filter outgoing updates\n")
5567
5568 /* Set prefix list to the peer. */
5569 static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
5570 afi_t afi, safi_t safi,
5571 const char *name_str,
5572 const char *direct_str)
5573 {
5574 int ret;
5575 int direct = FILTER_IN;
5576 struct peer *peer;
5577
5578 peer = peer_and_group_lookup_vty(vty, ip_str);
5579 if (!peer)
5580 return CMD_WARNING_CONFIG_FAILED;
5581
5582 /* Check filter direction. */
5583 if (strncmp(direct_str, "i", 1) == 0)
5584 direct = FILTER_IN;
5585 else if (strncmp(direct_str, "o", 1) == 0)
5586 direct = FILTER_OUT;
5587
5588 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
5589
5590 return bgp_vty_return(vty, ret);
5591 }
5592
5593 static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
5594 afi_t afi, safi_t safi,
5595 const char *direct_str)
5596 {
5597 int ret;
5598 struct peer *peer;
5599 int direct = FILTER_IN;
5600
5601 peer = peer_and_group_lookup_vty(vty, ip_str);
5602 if (!peer)
5603 return CMD_WARNING_CONFIG_FAILED;
5604
5605 /* Check filter direction. */
5606 if (strncmp(direct_str, "i", 1) == 0)
5607 direct = FILTER_IN;
5608 else if (strncmp(direct_str, "o", 1) == 0)
5609 direct = FILTER_OUT;
5610
5611 ret = peer_prefix_list_unset(peer, afi, safi, direct);
5612
5613 return bgp_vty_return(vty, ret);
5614 }
5615
5616 DEFUN (neighbor_prefix_list,
5617 neighbor_prefix_list_cmd,
5618 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5619 NEIGHBOR_STR
5620 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 int idx_peer = 1;
5627 int idx_word = 3;
5628 int idx_in_out = 4;
5629 return peer_prefix_list_set_vty(
5630 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5631 argv[idx_word]->arg, argv[idx_in_out]->arg);
5632 }
5633
5634 ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
5635 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5636 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5637 "Filter updates to/from this neighbor\n"
5638 "Name of a prefix list\n"
5639 "Filter incoming updates\n"
5640 "Filter outgoing updates\n")
5641
5642 DEFUN (no_neighbor_prefix_list,
5643 no_neighbor_prefix_list_cmd,
5644 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5645 NO_STR
5646 NEIGHBOR_STR
5647 NEIGHBOR_ADDR_STR2
5648 "Filter updates to/from this neighbor\n"
5649 "Name of a prefix list\n"
5650 "Filter incoming updates\n"
5651 "Filter outgoing updates\n")
5652 {
5653 int idx_peer = 2;
5654 int idx_in_out = 5;
5655 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
5656 bgp_node_afi(vty), bgp_node_safi(vty),
5657 argv[idx_in_out]->arg);
5658 }
5659
5660 ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
5661 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5662 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5663 "Filter updates to/from this neighbor\n"
5664 "Name of a prefix list\n"
5665 "Filter incoming updates\n"
5666 "Filter outgoing updates\n")
5667
5668 static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5669 safi_t safi, const char *name_str,
5670 const char *direct_str)
5671 {
5672 int ret;
5673 struct peer *peer;
5674 int direct = FILTER_IN;
5675
5676 peer = peer_and_group_lookup_vty(vty, ip_str);
5677 if (!peer)
5678 return CMD_WARNING_CONFIG_FAILED;
5679
5680 /* Check filter direction. */
5681 if (strncmp(direct_str, "i", 1) == 0)
5682 direct = FILTER_IN;
5683 else if (strncmp(direct_str, "o", 1) == 0)
5684 direct = FILTER_OUT;
5685
5686 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
5687
5688 return bgp_vty_return(vty, ret);
5689 }
5690
5691 static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5692 safi_t safi, const char *direct_str)
5693 {
5694 int ret;
5695 struct peer *peer;
5696 int direct = FILTER_IN;
5697
5698 peer = peer_and_group_lookup_vty(vty, ip_str);
5699 if (!peer)
5700 return CMD_WARNING_CONFIG_FAILED;
5701
5702 /* Check filter direction. */
5703 if (strncmp(direct_str, "i", 1) == 0)
5704 direct = FILTER_IN;
5705 else if (strncmp(direct_str, "o", 1) == 0)
5706 direct = FILTER_OUT;
5707
5708 ret = peer_aslist_unset(peer, afi, safi, direct);
5709
5710 return bgp_vty_return(vty, ret);
5711 }
5712
5713 DEFUN (neighbor_filter_list,
5714 neighbor_filter_list_cmd,
5715 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5716 NEIGHBOR_STR
5717 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 int idx_peer = 1;
5724 int idx_word = 3;
5725 int idx_in_out = 4;
5726 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5727 bgp_node_safi(vty), argv[idx_word]->arg,
5728 argv[idx_in_out]->arg);
5729 }
5730
5731 ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
5732 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5733 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5734 "Establish BGP filters\n"
5735 "AS path access-list name\n"
5736 "Filter incoming routes\n"
5737 "Filter outgoing routes\n")
5738
5739 DEFUN (no_neighbor_filter_list,
5740 no_neighbor_filter_list_cmd,
5741 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5742 NO_STR
5743 NEIGHBOR_STR
5744 NEIGHBOR_ADDR_STR2
5745 "Establish BGP filters\n"
5746 "AS path access-list name\n"
5747 "Filter incoming routes\n"
5748 "Filter outgoing routes\n")
5749 {
5750 int idx_peer = 2;
5751 int idx_in_out = 5;
5752 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
5753 bgp_node_afi(vty), bgp_node_safi(vty),
5754 argv[idx_in_out]->arg);
5755 }
5756
5757 ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
5758 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5759 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5760 "Establish BGP filters\n"
5761 "AS path access-list name\n"
5762 "Filter incoming routes\n"
5763 "Filter outgoing routes\n")
5764
5765 /* Set route-map to the peer. */
5766 static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
5767 afi_t afi, safi_t safi, const char *name_str,
5768 const char *direct_str)
5769 {
5770 int ret;
5771 struct peer *peer;
5772 int direct = RMAP_IN;
5773 struct route_map *route_map;
5774
5775 peer = peer_and_group_lookup_vty(vty, ip_str);
5776 if (!peer)
5777 return CMD_WARNING_CONFIG_FAILED;
5778
5779 /* Check filter direction. */
5780 if (strncmp(direct_str, "in", 2) == 0)
5781 direct = RMAP_IN;
5782 else if (strncmp(direct_str, "o", 1) == 0)
5783 direct = RMAP_OUT;
5784
5785 route_map = route_map_lookup_warn_noexist(vty, name_str);
5786 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
5787
5788 return bgp_vty_return(vty, ret);
5789 }
5790
5791 static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
5792 afi_t afi, safi_t safi,
5793 const char *direct_str)
5794 {
5795 int ret;
5796 struct peer *peer;
5797 int direct = RMAP_IN;
5798
5799 peer = peer_and_group_lookup_vty(vty, ip_str);
5800 if (!peer)
5801 return CMD_WARNING_CONFIG_FAILED;
5802
5803 /* Check filter direction. */
5804 if (strncmp(direct_str, "in", 2) == 0)
5805 direct = RMAP_IN;
5806 else if (strncmp(direct_str, "o", 1) == 0)
5807 direct = RMAP_OUT;
5808
5809 ret = peer_route_map_unset(peer, afi, safi, direct);
5810
5811 return bgp_vty_return(vty, ret);
5812 }
5813
5814 DEFUN (neighbor_route_map,
5815 neighbor_route_map_cmd,
5816 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5817 NEIGHBOR_STR
5818 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 int idx_peer = 1;
5825 int idx_word = 3;
5826 int idx_in_out = 4;
5827 return peer_route_map_set_vty(
5828 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5829 argv[idx_word]->arg, argv[idx_in_out]->arg);
5830 }
5831
5832 ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
5833 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5834 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5835 "Apply route map to neighbor\n"
5836 "Name of route map\n"
5837 "Apply map to incoming routes\n"
5838 "Apply map to outbound routes\n")
5839
5840 DEFUN (no_neighbor_route_map,
5841 no_neighbor_route_map_cmd,
5842 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5843 NO_STR
5844 NEIGHBOR_STR
5845 NEIGHBOR_ADDR_STR2
5846 "Apply route map to neighbor\n"
5847 "Name of route map\n"
5848 "Apply map to incoming routes\n"
5849 "Apply map to outbound routes\n")
5850 {
5851 int idx_peer = 2;
5852 int idx_in_out = 5;
5853 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
5854 bgp_node_afi(vty), bgp_node_safi(vty),
5855 argv[idx_in_out]->arg);
5856 }
5857
5858 ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
5859 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5860 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5861 "Apply route map to neighbor\n"
5862 "Name of route map\n"
5863 "Apply map to incoming routes\n"
5864 "Apply map to outbound routes\n")
5865
5866 /* Set unsuppress-map to the peer. */
5867 static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
5868 afi_t afi, safi_t safi,
5869 const char *name_str)
5870 {
5871 int ret;
5872 struct peer *peer;
5873 struct route_map *route_map;
5874
5875 peer = peer_and_group_lookup_vty(vty, ip_str);
5876 if (!peer)
5877 return CMD_WARNING_CONFIG_FAILED;
5878
5879 route_map = route_map_lookup_warn_noexist(vty, name_str);
5880 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
5881
5882 return bgp_vty_return(vty, ret);
5883 }
5884
5885 /* Unset route-map from the peer. */
5886 static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
5887 afi_t afi, safi_t safi)
5888 {
5889 int ret;
5890 struct peer *peer;
5891
5892 peer = peer_and_group_lookup_vty(vty, ip_str);
5893 if (!peer)
5894 return CMD_WARNING_CONFIG_FAILED;
5895
5896 ret = peer_unsuppress_map_unset(peer, afi, safi);
5897
5898 return bgp_vty_return(vty, ret);
5899 }
5900
5901 DEFUN (neighbor_unsuppress_map,
5902 neighbor_unsuppress_map_cmd,
5903 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5904 NEIGHBOR_STR
5905 NEIGHBOR_ADDR_STR2
5906 "Route-map to selectively unsuppress suppressed routes\n"
5907 "Name of route map\n")
5908 {
5909 int idx_peer = 1;
5910 int idx_word = 3;
5911 return peer_unsuppress_map_set_vty(
5912 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5913 argv[idx_word]->arg);
5914 }
5915
5916 ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
5917 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5918 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5919 "Route-map to selectively unsuppress suppressed routes\n"
5920 "Name of route map\n")
5921
5922 DEFUN (no_neighbor_unsuppress_map,
5923 no_neighbor_unsuppress_map_cmd,
5924 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5925 NO_STR
5926 NEIGHBOR_STR
5927 NEIGHBOR_ADDR_STR2
5928 "Route-map to selectively unsuppress suppressed routes\n"
5929 "Name of route map\n")
5930 {
5931 int idx_peer = 2;
5932 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
5933 bgp_node_afi(vty),
5934 bgp_node_safi(vty));
5935 }
5936
5937 ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
5938 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5939 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5940 "Route-map to selectively unsuppress suppressed routes\n"
5941 "Name of route map\n")
5942
5943 static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
5944 afi_t afi, safi_t safi,
5945 const char *num_str,
5946 const char *threshold_str, int warning,
5947 const char *restart_str)
5948 {
5949 int ret;
5950 struct peer *peer;
5951 uint32_t max;
5952 uint8_t threshold;
5953 uint16_t restart;
5954
5955 peer = peer_and_group_lookup_vty(vty, ip_str);
5956 if (!peer)
5957 return CMD_WARNING_CONFIG_FAILED;
5958
5959 max = strtoul(num_str, NULL, 10);
5960 if (threshold_str)
5961 threshold = atoi(threshold_str);
5962 else
5963 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
5964
5965 if (restart_str)
5966 restart = atoi(restart_str);
5967 else
5968 restart = 0;
5969
5970 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
5971 restart);
5972
5973 return bgp_vty_return(vty, ret);
5974 }
5975
5976 static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
5977 afi_t afi, safi_t safi)
5978 {
5979 int ret;
5980 struct peer *peer;
5981
5982 peer = peer_and_group_lookup_vty(vty, ip_str);
5983 if (!peer)
5984 return CMD_WARNING_CONFIG_FAILED;
5985
5986 ret = peer_maximum_prefix_unset(peer, afi, safi);
5987
5988 return bgp_vty_return(vty, ret);
5989 }
5990
5991 /* Maximum number of prefix configuration. prefix count is different
5992 for each peer configuration. So this configuration can be set for
5993 each peer configuration. */
5994 DEFUN (neighbor_maximum_prefix,
5995 neighbor_maximum_prefix_cmd,
5996 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5997 NEIGHBOR_STR
5998 NEIGHBOR_ADDR_STR2
5999 "Maximum number of prefix accept from this peer\n"
6000 "maximum no. of prefix limit\n")
6001 {
6002 int idx_peer = 1;
6003 int idx_number = 3;
6004 return peer_maximum_prefix_set_vty(
6005 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6006 argv[idx_number]->arg, NULL, 0, NULL);
6007 }
6008
6009 ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
6010 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
6011 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6012 "Maximum number of prefix accept from this peer\n"
6013 "maximum no. of prefix limit\n")
6014
6015 DEFUN (neighbor_maximum_prefix_threshold,
6016 neighbor_maximum_prefix_threshold_cmd,
6017 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
6018 NEIGHBOR_STR
6019 NEIGHBOR_ADDR_STR2
6020 "Maximum number of prefix accept from this peer\n"
6021 "maximum no. of prefix limit\n"
6022 "Threshold value (%) at which to generate a warning msg\n")
6023 {
6024 int idx_peer = 1;
6025 int idx_number = 3;
6026 int idx_number_2 = 4;
6027 return peer_maximum_prefix_set_vty(
6028 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6029 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL);
6030 }
6031
6032 ALIAS_HIDDEN(
6033 neighbor_maximum_prefix_threshold,
6034 neighbor_maximum_prefix_threshold_hidden_cmd,
6035 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
6036 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6037 "Maximum number of prefix accept from this peer\n"
6038 "maximum no. of prefix limit\n"
6039 "Threshold value (%) at which to generate a warning msg\n")
6040
6041 DEFUN (neighbor_maximum_prefix_warning,
6042 neighbor_maximum_prefix_warning_cmd,
6043 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
6044 NEIGHBOR_STR
6045 NEIGHBOR_ADDR_STR2
6046 "Maximum number of prefix accept from this peer\n"
6047 "maximum no. of prefix limit\n"
6048 "Only give warning message when limit is exceeded\n")
6049 {
6050 int idx_peer = 1;
6051 int idx_number = 3;
6052 return peer_maximum_prefix_set_vty(
6053 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6054 argv[idx_number]->arg, NULL, 1, NULL);
6055 }
6056
6057 ALIAS_HIDDEN(
6058 neighbor_maximum_prefix_warning,
6059 neighbor_maximum_prefix_warning_hidden_cmd,
6060 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
6061 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6062 "Maximum number of prefix accept from this peer\n"
6063 "maximum no. of prefix limit\n"
6064 "Only give warning message when limit is exceeded\n")
6065
6066 DEFUN (neighbor_maximum_prefix_threshold_warning,
6067 neighbor_maximum_prefix_threshold_warning_cmd,
6068 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
6069 NEIGHBOR_STR
6070 NEIGHBOR_ADDR_STR2
6071 "Maximum number of prefix accept from this peer\n"
6072 "maximum no. of prefix limit\n"
6073 "Threshold value (%) at which to generate a warning msg\n"
6074 "Only give warning message when limit is exceeded\n")
6075 {
6076 int idx_peer = 1;
6077 int idx_number = 3;
6078 int idx_number_2 = 4;
6079 return peer_maximum_prefix_set_vty(
6080 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6081 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL);
6082 }
6083
6084 ALIAS_HIDDEN(
6085 neighbor_maximum_prefix_threshold_warning,
6086 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
6087 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
6088 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6089 "Maximum number of prefix accept from this peer\n"
6090 "maximum no. of prefix limit\n"
6091 "Threshold value (%) at which to generate a warning msg\n"
6092 "Only give warning message when limit is exceeded\n")
6093
6094 DEFUN (neighbor_maximum_prefix_restart,
6095 neighbor_maximum_prefix_restart_cmd,
6096 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
6097 NEIGHBOR_STR
6098 NEIGHBOR_ADDR_STR2
6099 "Maximum number of prefix accept from this peer\n"
6100 "maximum no. of prefix limit\n"
6101 "Restart bgp connection after limit is exceeded\n"
6102 "Restart interval in minutes\n")
6103 {
6104 int idx_peer = 1;
6105 int idx_number = 3;
6106 int idx_number_2 = 5;
6107 return peer_maximum_prefix_set_vty(
6108 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6109 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg);
6110 }
6111
6112 ALIAS_HIDDEN(
6113 neighbor_maximum_prefix_restart,
6114 neighbor_maximum_prefix_restart_hidden_cmd,
6115 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
6116 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6117 "Maximum number of prefix accept from this peer\n"
6118 "maximum no. of prefix limit\n"
6119 "Restart bgp connection after limit is exceeded\n"
6120 "Restart interval in minutes\n")
6121
6122 DEFUN (neighbor_maximum_prefix_threshold_restart,
6123 neighbor_maximum_prefix_threshold_restart_cmd,
6124 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
6125 NEIGHBOR_STR
6126 NEIGHBOR_ADDR_STR2
6127 "Maximum number of prefixes to accept from this peer\n"
6128 "maximum no. of prefix limit\n"
6129 "Threshold value (%) at which to generate a warning msg\n"
6130 "Restart bgp connection after limit is exceeded\n"
6131 "Restart interval in minutes\n")
6132 {
6133 int idx_peer = 1;
6134 int idx_number = 3;
6135 int idx_number_2 = 4;
6136 int idx_number_3 = 6;
6137 return peer_maximum_prefix_set_vty(
6138 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6139 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
6140 argv[idx_number_3]->arg);
6141 }
6142
6143 ALIAS_HIDDEN(
6144 neighbor_maximum_prefix_threshold_restart,
6145 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
6146 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
6147 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6148 "Maximum number of prefixes to accept from this peer\n"
6149 "maximum no. of prefix limit\n"
6150 "Threshold value (%) at which to generate a warning msg\n"
6151 "Restart bgp connection after limit is exceeded\n"
6152 "Restart interval in minutes\n")
6153
6154 DEFUN (no_neighbor_maximum_prefix,
6155 no_neighbor_maximum_prefix_cmd,
6156 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
6157 NO_STR
6158 NEIGHBOR_STR
6159 NEIGHBOR_ADDR_STR2
6160 "Maximum number of prefixes to accept from this peer\n"
6161 "maximum no. of prefix limit\n"
6162 "Threshold value (%) at which to generate a warning msg\n"
6163 "Restart bgp connection after limit is exceeded\n"
6164 "Restart interval in minutes\n"
6165 "Only give warning message when limit is exceeded\n")
6166 {
6167 int idx_peer = 2;
6168 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
6169 bgp_node_afi(vty),
6170 bgp_node_safi(vty));
6171 }
6172
6173 ALIAS_HIDDEN(
6174 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
6175 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
6176 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6177 "Maximum number of prefixes to accept from this peer\n"
6178 "maximum no. of prefix limit\n"
6179 "Threshold value (%) at which to generate a warning msg\n"
6180 "Restart bgp connection after limit is exceeded\n"
6181 "Restart interval in minutes\n"
6182 "Only give warning message when limit is exceeded\n")
6183
6184
6185 /* "neighbor allowas-in" */
6186 DEFUN (neighbor_allowas_in,
6187 neighbor_allowas_in_cmd,
6188 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6189 NEIGHBOR_STR
6190 NEIGHBOR_ADDR_STR2
6191 "Accept as-path with my AS present in it\n"
6192 "Number of occurrences of AS number\n"
6193 "Only accept my AS in the as-path if the route was originated in my AS\n")
6194 {
6195 int idx_peer = 1;
6196 int idx_number_origin = 3;
6197 int ret;
6198 int origin = 0;
6199 struct peer *peer;
6200 int allow_num = 0;
6201
6202 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6203 if (!peer)
6204 return CMD_WARNING_CONFIG_FAILED;
6205
6206 if (argc <= idx_number_origin)
6207 allow_num = 3;
6208 else {
6209 if (argv[idx_number_origin]->type == WORD_TKN)
6210 origin = 1;
6211 else
6212 allow_num = atoi(argv[idx_number_origin]->arg);
6213 }
6214
6215 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6216 allow_num, origin);
6217
6218 return bgp_vty_return(vty, ret);
6219 }
6220
6221 ALIAS_HIDDEN(
6222 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
6223 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6224 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6225 "Accept as-path with my AS present in it\n"
6226 "Number of occurrences of AS number\n"
6227 "Only accept my AS in the as-path if the route was originated in my AS\n")
6228
6229 DEFUN (no_neighbor_allowas_in,
6230 no_neighbor_allowas_in_cmd,
6231 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6232 NO_STR
6233 NEIGHBOR_STR
6234 NEIGHBOR_ADDR_STR2
6235 "allow local ASN appears in aspath attribute\n"
6236 "Number of occurrences of AS number\n"
6237 "Only accept my AS in the as-path if the route was originated in my AS\n")
6238 {
6239 int idx_peer = 2;
6240 int ret;
6241 struct peer *peer;
6242
6243 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6244 if (!peer)
6245 return CMD_WARNING_CONFIG_FAILED;
6246
6247 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
6248 bgp_node_safi(vty));
6249
6250 return bgp_vty_return(vty, ret);
6251 }
6252
6253 ALIAS_HIDDEN(
6254 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
6255 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6256 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6257 "allow local ASN appears in aspath attribute\n"
6258 "Number of occurrences of AS number\n"
6259 "Only accept my AS in the as-path if the route was originated in my AS\n")
6260
6261 DEFUN (neighbor_ttl_security,
6262 neighbor_ttl_security_cmd,
6263 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
6264 NEIGHBOR_STR
6265 NEIGHBOR_ADDR_STR2
6266 "BGP ttl-security parameters\n"
6267 "Specify the maximum number of hops to the BGP peer\n"
6268 "Number of hops to BGP peer\n")
6269 {
6270 int idx_peer = 1;
6271 int idx_number = 4;
6272 struct peer *peer;
6273 int gtsm_hops;
6274
6275 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6276 if (!peer)
6277 return CMD_WARNING_CONFIG_FAILED;
6278
6279 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
6280
6281 /*
6282 * If 'neighbor swpX', then this is for directly connected peers,
6283 * we should not accept a ttl-security hops value greater than 1.
6284 */
6285 if (peer->conf_if && (gtsm_hops > 1)) {
6286 vty_out(vty,
6287 "%s is directly connected peer, hops cannot exceed 1\n",
6288 argv[idx_peer]->arg);
6289 return CMD_WARNING_CONFIG_FAILED;
6290 }
6291
6292 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
6293 }
6294
6295 DEFUN (no_neighbor_ttl_security,
6296 no_neighbor_ttl_security_cmd,
6297 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
6298 NO_STR
6299 NEIGHBOR_STR
6300 NEIGHBOR_ADDR_STR2
6301 "BGP ttl-security parameters\n"
6302 "Specify the maximum number of hops to the BGP peer\n"
6303 "Number of hops to BGP peer\n")
6304 {
6305 int idx_peer = 2;
6306 struct peer *peer;
6307
6308 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6309 if (!peer)
6310 return CMD_WARNING_CONFIG_FAILED;
6311
6312 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
6313 }
6314
6315 DEFUN (neighbor_addpath_tx_all_paths,
6316 neighbor_addpath_tx_all_paths_cmd,
6317 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6318 NEIGHBOR_STR
6319 NEIGHBOR_ADDR_STR2
6320 "Use addpath to advertise all paths to a neighbor\n")
6321 {
6322 int idx_peer = 1;
6323 struct peer *peer;
6324
6325 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6326 if (!peer)
6327 return CMD_WARNING_CONFIG_FAILED;
6328
6329 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6330 BGP_ADDPATH_ALL);
6331 return CMD_SUCCESS;
6332 }
6333
6334 ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
6335 neighbor_addpath_tx_all_paths_hidden_cmd,
6336 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6337 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6338 "Use addpath to advertise all paths to a neighbor\n")
6339
6340 DEFUN (no_neighbor_addpath_tx_all_paths,
6341 no_neighbor_addpath_tx_all_paths_cmd,
6342 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6343 NO_STR
6344 NEIGHBOR_STR
6345 NEIGHBOR_ADDR_STR2
6346 "Use addpath to advertise all paths to a neighbor\n")
6347 {
6348 int idx_peer = 2;
6349 struct peer *peer;
6350
6351 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6352 if (!peer)
6353 return CMD_WARNING_CONFIG_FAILED;
6354
6355 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
6356 != BGP_ADDPATH_ALL) {
6357 vty_out(vty,
6358 "%% Peer not currently configured to transmit all paths.");
6359 return CMD_WARNING_CONFIG_FAILED;
6360 }
6361
6362 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6363 BGP_ADDPATH_NONE);
6364
6365 return CMD_SUCCESS;
6366 }
6367
6368 ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
6369 no_neighbor_addpath_tx_all_paths_hidden_cmd,
6370 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6371 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6372 "Use addpath to advertise all paths to a neighbor\n")
6373
6374 DEFUN (neighbor_addpath_tx_bestpath_per_as,
6375 neighbor_addpath_tx_bestpath_per_as_cmd,
6376 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6377 NEIGHBOR_STR
6378 NEIGHBOR_ADDR_STR2
6379 "Use addpath to advertise the bestpath per each neighboring AS\n")
6380 {
6381 int idx_peer = 1;
6382 struct peer *peer;
6383
6384 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6385 if (!peer)
6386 return CMD_WARNING_CONFIG_FAILED;
6387
6388 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6389 BGP_ADDPATH_BEST_PER_AS);
6390
6391 return CMD_SUCCESS;
6392 }
6393
6394 ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
6395 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6396 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6397 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6398 "Use addpath to advertise the bestpath per each neighboring AS\n")
6399
6400 DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
6401 no_neighbor_addpath_tx_bestpath_per_as_cmd,
6402 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6403 NO_STR
6404 NEIGHBOR_STR
6405 NEIGHBOR_ADDR_STR2
6406 "Use addpath to advertise the bestpath per each neighboring AS\n")
6407 {
6408 int idx_peer = 2;
6409 struct peer *peer;
6410
6411 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6412 if (!peer)
6413 return CMD_WARNING_CONFIG_FAILED;
6414
6415 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
6416 != BGP_ADDPATH_BEST_PER_AS) {
6417 vty_out(vty,
6418 "%% Peer not currently configured to transmit all best path per as.");
6419 return CMD_WARNING_CONFIG_FAILED;
6420 }
6421
6422 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6423 BGP_ADDPATH_NONE);
6424
6425 return CMD_SUCCESS;
6426 }
6427
6428 ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
6429 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6430 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6431 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6432 "Use addpath to advertise the bestpath per each neighboring AS\n")
6433
6434 DEFPY(
6435 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
6436 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
6437 NEIGHBOR_STR
6438 NEIGHBOR_ADDR_STR2
6439 "Detect AS loops before sending to neighbor\n")
6440 {
6441 struct peer *peer;
6442
6443 peer = peer_and_group_lookup_vty(vty, neighbor);
6444 if (!peer)
6445 return CMD_WARNING_CONFIG_FAILED;
6446
6447 peer->as_path_loop_detection = true;
6448
6449 return CMD_SUCCESS;
6450 }
6451
6452 DEFPY(
6453 no_neighbor_aspath_loop_detection,
6454 no_neighbor_aspath_loop_detection_cmd,
6455 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
6456 NO_STR
6457 NEIGHBOR_STR
6458 NEIGHBOR_ADDR_STR2
6459 "Detect AS loops before sending to neighbor\n")
6460 {
6461 struct peer *peer;
6462
6463 peer = peer_and_group_lookup_vty(vty, neighbor);
6464 if (!peer)
6465 return CMD_WARNING_CONFIG_FAILED;
6466
6467 peer->as_path_loop_detection = false;
6468
6469 return CMD_SUCCESS;
6470 }
6471
6472 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
6473 struct ecommunity **list)
6474 {
6475 struct ecommunity *ecom = NULL;
6476 struct ecommunity *ecomadd;
6477
6478 for (; argc; --argc, ++argv) {
6479
6480 ecomadd = ecommunity_str2com(argv[0]->arg,
6481 ECOMMUNITY_ROUTE_TARGET, 0);
6482 if (!ecomadd) {
6483 vty_out(vty, "Malformed community-list value\n");
6484 if (ecom)
6485 ecommunity_free(&ecom);
6486 return CMD_WARNING_CONFIG_FAILED;
6487 }
6488
6489 if (ecom) {
6490 ecommunity_merge(ecom, ecomadd);
6491 ecommunity_free(&ecomadd);
6492 } else {
6493 ecom = ecomadd;
6494 }
6495 }
6496
6497 if (*list) {
6498 ecommunity_free(&*list);
6499 }
6500 *list = ecom;
6501
6502 return CMD_SUCCESS;
6503 }
6504
6505 /*
6506 * v2vimport is true if we are handling a `import vrf ...` command
6507 */
6508 static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
6509 {
6510 afi_t afi;
6511
6512 switch (vty->node) {
6513 case BGP_IPV4_NODE:
6514 afi = AFI_IP;
6515 break;
6516 case BGP_IPV6_NODE:
6517 afi = AFI_IP6;
6518 break;
6519 default:
6520 vty_out(vty,
6521 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
6522 return AFI_MAX;
6523 }
6524
6525 if (!v2vimport) {
6526 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6527 BGP_CONFIG_VRF_TO_VRF_IMPORT)
6528 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6529 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
6530 vty_out(vty,
6531 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
6532 return AFI_MAX;
6533 }
6534 } else {
6535 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6536 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
6537 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6538 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
6539 vty_out(vty,
6540 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
6541 return AFI_MAX;
6542 }
6543 }
6544 return afi;
6545 }
6546
6547 DEFPY (af_rd_vpn_export,
6548 af_rd_vpn_export_cmd,
6549 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
6550 NO_STR
6551 "Specify route distinguisher\n"
6552 "Between current address-family and vpn\n"
6553 "For routes leaked from current address-family to vpn\n"
6554 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
6555 {
6556 VTY_DECLVAR_CONTEXT(bgp, bgp);
6557 struct prefix_rd prd;
6558 int ret;
6559 afi_t afi;
6560 int idx = 0;
6561 int yes = 1;
6562
6563 if (argv_find(argv, argc, "no", &idx))
6564 yes = 0;
6565
6566 if (yes) {
6567 ret = str2prefix_rd(rd_str, &prd);
6568 if (!ret) {
6569 vty_out(vty, "%% Malformed rd\n");
6570 return CMD_WARNING_CONFIG_FAILED;
6571 }
6572 }
6573
6574 afi = vpn_policy_getafi(vty, bgp, false);
6575 if (afi == AFI_MAX)
6576 return CMD_WARNING_CONFIG_FAILED;
6577
6578 /*
6579 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6580 */
6581 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6582 bgp_get_default(), bgp);
6583
6584 if (yes) {
6585 bgp->vpn_policy[afi].tovpn_rd = prd;
6586 SET_FLAG(bgp->vpn_policy[afi].flags,
6587 BGP_VPN_POLICY_TOVPN_RD_SET);
6588 } else {
6589 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6590 BGP_VPN_POLICY_TOVPN_RD_SET);
6591 }
6592
6593 /* post-change: re-export vpn routes */
6594 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6595 bgp_get_default(), bgp);
6596
6597 return CMD_SUCCESS;
6598 }
6599
6600 ALIAS (af_rd_vpn_export,
6601 af_no_rd_vpn_export_cmd,
6602 "no rd vpn export",
6603 NO_STR
6604 "Specify route distinguisher\n"
6605 "Between current address-family and vpn\n"
6606 "For routes leaked from current address-family to vpn\n")
6607
6608 DEFPY (af_label_vpn_export,
6609 af_label_vpn_export_cmd,
6610 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
6611 NO_STR
6612 "label value for VRF\n"
6613 "Between current address-family and vpn\n"
6614 "For routes leaked from current address-family to vpn\n"
6615 "Label Value <0-1048575>\n"
6616 "Automatically assign a label\n")
6617 {
6618 VTY_DECLVAR_CONTEXT(bgp, bgp);
6619 mpls_label_t label = MPLS_LABEL_NONE;
6620 afi_t afi;
6621 int idx = 0;
6622 int yes = 1;
6623
6624 if (argv_find(argv, argc, "no", &idx))
6625 yes = 0;
6626
6627 /* If "no ...", squash trailing parameter */
6628 if (!yes)
6629 label_auto = NULL;
6630
6631 if (yes) {
6632 if (!label_auto)
6633 label = label_val; /* parser should force unsigned */
6634 }
6635
6636 afi = vpn_policy_getafi(vty, bgp, false);
6637 if (afi == AFI_MAX)
6638 return CMD_WARNING_CONFIG_FAILED;
6639
6640
6641 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6642 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
6643 /* no change */
6644 return CMD_SUCCESS;
6645
6646 /*
6647 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6648 */
6649 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6650 bgp_get_default(), bgp);
6651
6652 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6653 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
6654
6655 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
6656
6657 /*
6658 * label has previously been automatically
6659 * assigned by labelpool: release it
6660 *
6661 * NB if tovpn_label == MPLS_LABEL_NONE it
6662 * means the automatic assignment is in flight
6663 * and therefore the labelpool callback must
6664 * detect that the auto label is not needed.
6665 */
6666
6667 bgp_lp_release(LP_TYPE_VRF,
6668 &bgp->vpn_policy[afi],
6669 bgp->vpn_policy[afi].tovpn_label);
6670 }
6671 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6672 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6673 }
6674
6675 bgp->vpn_policy[afi].tovpn_label = label;
6676 if (label_auto) {
6677 SET_FLAG(bgp->vpn_policy[afi].flags,
6678 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6679 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
6680 vpn_leak_label_callback);
6681 }
6682
6683 /* post-change: re-export vpn routes */
6684 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6685 bgp_get_default(), bgp);
6686
6687 return CMD_SUCCESS;
6688 }
6689
6690 ALIAS (af_label_vpn_export,
6691 af_no_label_vpn_export_cmd,
6692 "no label vpn export",
6693 NO_STR
6694 "label value for VRF\n"
6695 "Between current address-family and vpn\n"
6696 "For routes leaked from current address-family to vpn\n")
6697
6698 DEFPY (af_nexthop_vpn_export,
6699 af_nexthop_vpn_export_cmd,
6700 "[no] nexthop vpn export <A.B.C.D|X:X::X:X>$nexthop_str",
6701 NO_STR
6702 "Specify next hop to use for VRF advertised prefixes\n"
6703 "Between current address-family and vpn\n"
6704 "For routes leaked from current address-family to vpn\n"
6705 "IPv4 prefix\n"
6706 "IPv6 prefix\n")
6707 {
6708 VTY_DECLVAR_CONTEXT(bgp, bgp);
6709 afi_t afi;
6710 struct prefix p;
6711 int idx = 0;
6712 int yes = 1;
6713
6714 if (argv_find(argv, argc, "no", &idx))
6715 yes = 0;
6716
6717 if (yes) {
6718 if (!sockunion2hostprefix(nexthop_str, &p))
6719 return CMD_WARNING_CONFIG_FAILED;
6720 }
6721
6722 afi = vpn_policy_getafi(vty, bgp, false);
6723 if (afi == AFI_MAX)
6724 return CMD_WARNING_CONFIG_FAILED;
6725
6726 /*
6727 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6728 */
6729 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6730 bgp_get_default(), bgp);
6731
6732 if (yes) {
6733 bgp->vpn_policy[afi].tovpn_nexthop = p;
6734 SET_FLAG(bgp->vpn_policy[afi].flags,
6735 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6736 } else {
6737 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6738 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6739 }
6740
6741 /* post-change: re-export vpn routes */
6742 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6743 bgp_get_default(), bgp);
6744
6745 return CMD_SUCCESS;
6746 }
6747
6748 ALIAS (af_nexthop_vpn_export,
6749 af_no_nexthop_vpn_export_cmd,
6750 "no nexthop vpn export",
6751 NO_STR
6752 "Specify next hop to use for VRF advertised prefixes\n"
6753 "Between current address-family and vpn\n"
6754 "For routes leaked from current address-family to vpn\n")
6755
6756 static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
6757 {
6758 if (!strcmp(dstr, "import")) {
6759 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6760 } else if (!strcmp(dstr, "export")) {
6761 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6762 } else if (!strcmp(dstr, "both")) {
6763 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6764 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6765 } else {
6766 vty_out(vty, "%% direction parse error\n");
6767 return CMD_WARNING_CONFIG_FAILED;
6768 }
6769 return CMD_SUCCESS;
6770 }
6771
6772 DEFPY (af_rt_vpn_imexport,
6773 af_rt_vpn_imexport_cmd,
6774 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
6775 NO_STR
6776 "Specify route target list\n"
6777 "Specify route target list\n"
6778 "Between current address-family and vpn\n"
6779 "For routes leaked from vpn to current address-family: match any\n"
6780 "For routes leaked from current address-family to vpn: set\n"
6781 "both import: match any and export: set\n"
6782 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6783 {
6784 VTY_DECLVAR_CONTEXT(bgp, bgp);
6785 int ret;
6786 struct ecommunity *ecom = NULL;
6787 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6788 vpn_policy_direction_t dir;
6789 afi_t afi;
6790 int idx = 0;
6791 int yes = 1;
6792
6793 if (argv_find(argv, argc, "no", &idx))
6794 yes = 0;
6795
6796 afi = vpn_policy_getafi(vty, bgp, false);
6797 if (afi == AFI_MAX)
6798 return CMD_WARNING_CONFIG_FAILED;
6799
6800 ret = vpn_policy_getdirs(vty, direction_str, dodir);
6801 if (ret != CMD_SUCCESS)
6802 return ret;
6803
6804 if (yes) {
6805 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6806 vty_out(vty, "%% Missing RTLIST\n");
6807 return CMD_WARNING_CONFIG_FAILED;
6808 }
6809 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6810 if (ret != CMD_SUCCESS) {
6811 return ret;
6812 }
6813 }
6814
6815 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6816 if (!dodir[dir])
6817 continue;
6818
6819 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6820
6821 if (yes) {
6822 if (bgp->vpn_policy[afi].rtlist[dir])
6823 ecommunity_free(
6824 &bgp->vpn_policy[afi].rtlist[dir]);
6825 bgp->vpn_policy[afi].rtlist[dir] =
6826 ecommunity_dup(ecom);
6827 } else {
6828 if (bgp->vpn_policy[afi].rtlist[dir])
6829 ecommunity_free(
6830 &bgp->vpn_policy[afi].rtlist[dir]);
6831 bgp->vpn_policy[afi].rtlist[dir] = NULL;
6832 }
6833
6834 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6835 }
6836
6837 if (ecom)
6838 ecommunity_free(&ecom);
6839
6840 return CMD_SUCCESS;
6841 }
6842
6843 ALIAS (af_rt_vpn_imexport,
6844 af_no_rt_vpn_imexport_cmd,
6845 "no <rt|route-target> vpn <import|export|both>$direction_str",
6846 NO_STR
6847 "Specify route target list\n"
6848 "Specify route target list\n"
6849 "Between current address-family and vpn\n"
6850 "For routes leaked from vpn to current address-family\n"
6851 "For routes leaked from current address-family to vpn\n"
6852 "both import and export\n")
6853
6854 DEFPY (af_route_map_vpn_imexport,
6855 af_route_map_vpn_imexport_cmd,
6856 /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
6857 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
6858 NO_STR
6859 "Specify route map\n"
6860 "Between current address-family and vpn\n"
6861 "For routes leaked from vpn to current address-family\n"
6862 "For routes leaked from current address-family to vpn\n"
6863 "name of route-map\n")
6864 {
6865 VTY_DECLVAR_CONTEXT(bgp, bgp);
6866 int ret;
6867 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6868 vpn_policy_direction_t dir;
6869 afi_t afi;
6870 int idx = 0;
6871 int yes = 1;
6872
6873 if (argv_find(argv, argc, "no", &idx))
6874 yes = 0;
6875
6876 afi = vpn_policy_getafi(vty, bgp, false);
6877 if (afi == AFI_MAX)
6878 return CMD_WARNING_CONFIG_FAILED;
6879
6880 ret = vpn_policy_getdirs(vty, direction_str, dodir);
6881 if (ret != CMD_SUCCESS)
6882 return ret;
6883
6884 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6885 if (!dodir[dir])
6886 continue;
6887
6888 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6889
6890 if (yes) {
6891 if (bgp->vpn_policy[afi].rmap_name[dir])
6892 XFREE(MTYPE_ROUTE_MAP_NAME,
6893 bgp->vpn_policy[afi].rmap_name[dir]);
6894 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
6895 MTYPE_ROUTE_MAP_NAME, rmap_str);
6896 bgp->vpn_policy[afi].rmap[dir] =
6897 route_map_lookup_warn_noexist(vty, rmap_str);
6898 if (!bgp->vpn_policy[afi].rmap[dir])
6899 return CMD_SUCCESS;
6900 } else {
6901 if (bgp->vpn_policy[afi].rmap_name[dir])
6902 XFREE(MTYPE_ROUTE_MAP_NAME,
6903 bgp->vpn_policy[afi].rmap_name[dir]);
6904 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6905 bgp->vpn_policy[afi].rmap[dir] = NULL;
6906 }
6907
6908 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6909 }
6910
6911 return CMD_SUCCESS;
6912 }
6913
6914 ALIAS (af_route_map_vpn_imexport,
6915 af_no_route_map_vpn_imexport_cmd,
6916 "no route-map vpn <import|export>$direction_str",
6917 NO_STR
6918 "Specify route map\n"
6919 "Between current address-family and vpn\n"
6920 "For routes leaked from vpn to current address-family\n"
6921 "For routes leaked from current address-family to vpn\n")
6922
6923 DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
6924 "[no] import vrf route-map RMAP$rmap_str",
6925 NO_STR
6926 "Import routes from another VRF\n"
6927 "Vrf routes being filtered\n"
6928 "Specify route map\n"
6929 "name of route-map\n")
6930 {
6931 VTY_DECLVAR_CONTEXT(bgp, bgp);
6932 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
6933 afi_t afi;
6934 int idx = 0;
6935 int yes = 1;
6936 struct bgp *bgp_default;
6937
6938 if (argv_find(argv, argc, "no", &idx))
6939 yes = 0;
6940
6941 afi = vpn_policy_getafi(vty, bgp, true);
6942 if (afi == AFI_MAX)
6943 return CMD_WARNING_CONFIG_FAILED;
6944
6945 bgp_default = bgp_get_default();
6946 if (!bgp_default) {
6947 int32_t ret;
6948 as_t as = bgp->as;
6949
6950 /* Auto-create assuming the same AS */
6951 ret = bgp_get(&bgp_default, &as, NULL,
6952 BGP_INSTANCE_TYPE_DEFAULT);
6953
6954 if (ret) {
6955 vty_out(vty,
6956 "VRF default is not configured as a bgp instance\n");
6957 return CMD_WARNING;
6958 }
6959 }
6960
6961 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6962
6963 if (yes) {
6964 if (bgp->vpn_policy[afi].rmap_name[dir])
6965 XFREE(MTYPE_ROUTE_MAP_NAME,
6966 bgp->vpn_policy[afi].rmap_name[dir]);
6967 bgp->vpn_policy[afi].rmap_name[dir] =
6968 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
6969 bgp->vpn_policy[afi].rmap[dir] =
6970 route_map_lookup_warn_noexist(vty, rmap_str);
6971 if (!bgp->vpn_policy[afi].rmap[dir])
6972 return CMD_SUCCESS;
6973 } else {
6974 if (bgp->vpn_policy[afi].rmap_name[dir])
6975 XFREE(MTYPE_ROUTE_MAP_NAME,
6976 bgp->vpn_policy[afi].rmap_name[dir]);
6977 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6978 bgp->vpn_policy[afi].rmap[dir] = NULL;
6979 }
6980
6981 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6982
6983 return CMD_SUCCESS;
6984 }
6985
6986 ALIAS(af_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
6987 "no import vrf route-map",
6988 NO_STR
6989 "Import routes from another VRF\n"
6990 "Vrf routes being filtered\n"
6991 "Specify route map\n")
6992
6993 DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
6994 "[no] import vrf VIEWVRFNAME$import_name",
6995 NO_STR
6996 "Import routes from another VRF\n"
6997 "VRF to import from\n"
6998 "The name of the VRF\n")
6999 {
7000 VTY_DECLVAR_CONTEXT(bgp, bgp);
7001 struct listnode *node;
7002 struct bgp *vrf_bgp, *bgp_default;
7003 int32_t ret = 0;
7004 as_t as = bgp->as;
7005 bool remove = false;
7006 int32_t idx = 0;
7007 char *vname;
7008 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
7009 safi_t safi;
7010 afi_t afi;
7011
7012 if (import_name == NULL) {
7013 vty_out(vty, "%% Missing import name\n");
7014 return CMD_WARNING;
7015 }
7016
7017 if (argv_find(argv, argc, "no", &idx))
7018 remove = true;
7019
7020 afi = vpn_policy_getafi(vty, bgp, true);
7021 if (afi == AFI_MAX)
7022 return CMD_WARNING_CONFIG_FAILED;
7023
7024 safi = bgp_node_safi(vty);
7025
7026 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
7027 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
7028 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
7029 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
7030 remove ? "unimport" : "import", import_name);
7031 return CMD_WARNING;
7032 }
7033
7034 bgp_default = bgp_get_default();
7035 if (!bgp_default) {
7036 /* Auto-create assuming the same AS */
7037 ret = bgp_get(&bgp_default, &as, NULL,
7038 BGP_INSTANCE_TYPE_DEFAULT);
7039
7040 if (ret) {
7041 vty_out(vty,
7042 "VRF default is not configured as a bgp instance\n");
7043 return CMD_WARNING;
7044 }
7045 }
7046
7047 vrf_bgp = bgp_lookup_by_name(import_name);
7048 if (!vrf_bgp) {
7049 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
7050 vrf_bgp = bgp_default;
7051 else
7052 /* Auto-create assuming the same AS */
7053 ret = bgp_get(&vrf_bgp, &as, import_name, bgp_type);
7054
7055 if (ret) {
7056 vty_out(vty,
7057 "VRF %s is not configured as a bgp instance\n",
7058 import_name);
7059 return CMD_WARNING;
7060 }
7061 }
7062
7063 if (remove) {
7064 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
7065 } else {
7066 /* Already importing from "import_vrf"? */
7067 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
7068 vname)) {
7069 if (strcmp(vname, import_name) == 0)
7070 return CMD_WARNING;
7071 }
7072
7073 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
7074 }
7075
7076 return CMD_SUCCESS;
7077 }
7078
7079 /* This command is valid only in a bgp vrf instance or the default instance */
7080 DEFPY (bgp_imexport_vpn,
7081 bgp_imexport_vpn_cmd,
7082 "[no] <import|export>$direction_str vpn",
7083 NO_STR
7084 "Import routes to this address-family\n"
7085 "Export routes from this address-family\n"
7086 "to/from default instance VPN RIB\n")
7087 {
7088 VTY_DECLVAR_CONTEXT(bgp, bgp);
7089 int previous_state;
7090 afi_t afi;
7091 safi_t safi;
7092 int idx = 0;
7093 int yes = 1;
7094 int flag;
7095 vpn_policy_direction_t dir;
7096
7097 if (argv_find(argv, argc, "no", &idx))
7098 yes = 0;
7099
7100 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
7101 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
7102
7103 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
7104 return CMD_WARNING_CONFIG_FAILED;
7105 }
7106
7107 afi = bgp_node_afi(vty);
7108 safi = bgp_node_safi(vty);
7109 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
7110 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
7111 return CMD_WARNING_CONFIG_FAILED;
7112 }
7113
7114 if (!strcmp(direction_str, "import")) {
7115 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
7116 dir = BGP_VPN_POLICY_DIR_FROMVPN;
7117 } else if (!strcmp(direction_str, "export")) {
7118 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
7119 dir = BGP_VPN_POLICY_DIR_TOVPN;
7120 } else {
7121 vty_out(vty, "%% unknown direction %s\n", direction_str);
7122 return CMD_WARNING_CONFIG_FAILED;
7123 }
7124
7125 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
7126
7127 if (yes) {
7128 SET_FLAG(bgp->af_flags[afi][safi], flag);
7129 if (!previous_state) {
7130 /* trigger export current vrf */
7131 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
7132 }
7133 } else {
7134 if (previous_state) {
7135 /* trigger un-export current vrf */
7136 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
7137 }
7138 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
7139 }
7140
7141 return CMD_SUCCESS;
7142 }
7143
7144 DEFPY (af_routetarget_import,
7145 af_routetarget_import_cmd,
7146 "[no] <rt|route-target> redirect import RTLIST...",
7147 NO_STR
7148 "Specify route target list\n"
7149 "Specify route target list\n"
7150 "Flow-spec redirect type route target\n"
7151 "Import routes to this address-family\n"
7152 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
7153 {
7154 VTY_DECLVAR_CONTEXT(bgp, bgp);
7155 int ret;
7156 struct ecommunity *ecom = NULL;
7157 afi_t afi;
7158 int idx = 0;
7159 int yes = 1;
7160
7161 if (argv_find(argv, argc, "no", &idx))
7162 yes = 0;
7163
7164 afi = vpn_policy_getafi(vty, bgp, false);
7165 if (afi == AFI_MAX)
7166 return CMD_WARNING_CONFIG_FAILED;
7167
7168 if (yes) {
7169 if (!argv_find(argv, argc, "RTLIST", &idx)) {
7170 vty_out(vty, "%% Missing RTLIST\n");
7171 return CMD_WARNING_CONFIG_FAILED;
7172 }
7173 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
7174 if (ret != CMD_SUCCESS)
7175 return ret;
7176 }
7177
7178 if (yes) {
7179 if (bgp->vpn_policy[afi].import_redirect_rtlist)
7180 ecommunity_free(&bgp->vpn_policy[afi]
7181 .import_redirect_rtlist);
7182 bgp->vpn_policy[afi].import_redirect_rtlist =
7183 ecommunity_dup(ecom);
7184 } else {
7185 if (bgp->vpn_policy[afi].import_redirect_rtlist)
7186 ecommunity_free(&bgp->vpn_policy[afi]
7187 .import_redirect_rtlist);
7188 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
7189 }
7190
7191 if (ecom)
7192 ecommunity_free(&ecom);
7193
7194 return CMD_SUCCESS;
7195 }
7196
7197 DEFUN_NOSH (address_family_ipv4_safi,
7198 address_family_ipv4_safi_cmd,
7199 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
7200 "Enter Address Family command mode\n"
7201 "Address Family\n"
7202 BGP_SAFI_WITH_LABEL_HELP_STR)
7203 {
7204
7205 if (argc == 3) {
7206 VTY_DECLVAR_CONTEXT(bgp, bgp);
7207 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
7208 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
7209 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
7210 && safi != SAFI_EVPN) {
7211 vty_out(vty,
7212 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
7213 return CMD_WARNING_CONFIG_FAILED;
7214 }
7215 vty->node = bgp_node_type(AFI_IP, safi);
7216 } else
7217 vty->node = BGP_IPV4_NODE;
7218
7219 return CMD_SUCCESS;
7220 }
7221
7222 DEFUN_NOSH (address_family_ipv6_safi,
7223 address_family_ipv6_safi_cmd,
7224 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
7225 "Enter Address Family command mode\n"
7226 "Address Family\n"
7227 BGP_SAFI_WITH_LABEL_HELP_STR)
7228 {
7229 if (argc == 3) {
7230 VTY_DECLVAR_CONTEXT(bgp, bgp);
7231 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
7232 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
7233 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
7234 && safi != SAFI_EVPN) {
7235 vty_out(vty,
7236 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
7237 return CMD_WARNING_CONFIG_FAILED;
7238 }
7239 vty->node = bgp_node_type(AFI_IP6, safi);
7240 } else
7241 vty->node = BGP_IPV6_NODE;
7242
7243 return CMD_SUCCESS;
7244 }
7245
7246 #ifdef KEEP_OLD_VPN_COMMANDS
7247 DEFUN_NOSH (address_family_vpnv4,
7248 address_family_vpnv4_cmd,
7249 "address-family vpnv4 [unicast]",
7250 "Enter Address Family command mode\n"
7251 "Address Family\n"
7252 "Address Family modifier\n")
7253 {
7254 vty->node = BGP_VPNV4_NODE;
7255 return CMD_SUCCESS;
7256 }
7257
7258 DEFUN_NOSH (address_family_vpnv6,
7259 address_family_vpnv6_cmd,
7260 "address-family vpnv6 [unicast]",
7261 "Enter Address Family command mode\n"
7262 "Address Family\n"
7263 "Address Family modifier\n")
7264 {
7265 vty->node = BGP_VPNV6_NODE;
7266 return CMD_SUCCESS;
7267 }
7268 #endif /* KEEP_OLD_VPN_COMMANDS */
7269
7270 DEFUN_NOSH (address_family_evpn,
7271 address_family_evpn_cmd,
7272 "address-family l2vpn evpn",
7273 "Enter Address Family command mode\n"
7274 "Address Family\n"
7275 "Address Family modifier\n")
7276 {
7277 VTY_DECLVAR_CONTEXT(bgp, bgp);
7278 vty->node = BGP_EVPN_NODE;
7279 return CMD_SUCCESS;
7280 }
7281
7282 DEFUN_NOSH (exit_address_family,
7283 exit_address_family_cmd,
7284 "exit-address-family",
7285 "Exit from Address Family configuration mode\n")
7286 {
7287 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
7288 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
7289 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
7290 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
7291 || vty->node == BGP_EVPN_NODE
7292 || vty->node == BGP_FLOWSPECV4_NODE
7293 || vty->node == BGP_FLOWSPECV6_NODE)
7294 vty->node = BGP_NODE;
7295 return CMD_SUCCESS;
7296 }
7297
7298 /* Recalculate bestpath and re-advertise a prefix */
7299 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
7300 const char *ip_str, afi_t afi, safi_t safi,
7301 struct prefix_rd *prd)
7302 {
7303 int ret;
7304 struct prefix match;
7305 struct bgp_node *rn;
7306 struct bgp_node *rm;
7307 struct bgp *bgp;
7308 struct bgp_table *table;
7309 struct bgp_table *rib;
7310
7311 /* BGP structure lookup. */
7312 if (view_name) {
7313 bgp = bgp_lookup_by_name(view_name);
7314 if (bgp == NULL) {
7315 vty_out(vty, "%% Can't find BGP instance %s\n",
7316 view_name);
7317 return CMD_WARNING;
7318 }
7319 } else {
7320 bgp = bgp_get_default();
7321 if (bgp == NULL) {
7322 vty_out(vty, "%% No BGP process is configured\n");
7323 return CMD_WARNING;
7324 }
7325 }
7326
7327 /* Check IP address argument. */
7328 ret = str2prefix(ip_str, &match);
7329 if (!ret) {
7330 vty_out(vty, "%% address is malformed\n");
7331 return CMD_WARNING;
7332 }
7333
7334 match.family = afi2family(afi);
7335 rib = bgp->rib[afi][safi];
7336
7337 if (safi == SAFI_MPLS_VPN) {
7338 for (rn = bgp_table_top(rib); rn; rn = bgp_route_next(rn)) {
7339 if (prd && memcmp(rn->p.u.val, prd->val, 8) != 0)
7340 continue;
7341
7342 table = bgp_node_get_bgp_table_info(rn);
7343 if (table != NULL) {
7344
7345 if ((rm = bgp_node_match(table, &match))
7346 != NULL) {
7347 if (rm->p.prefixlen
7348 == match.prefixlen) {
7349 SET_FLAG(rm->flags,
7350 BGP_NODE_USER_CLEAR);
7351 bgp_process(bgp, rm, afi, safi);
7352 }
7353 bgp_unlock_node(rm);
7354 }
7355 }
7356 }
7357 } else {
7358 if ((rn = bgp_node_match(rib, &match)) != NULL) {
7359 if (rn->p.prefixlen == match.prefixlen) {
7360 SET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
7361 bgp_process(bgp, rn, afi, safi);
7362 }
7363 bgp_unlock_node(rn);
7364 }
7365 }
7366
7367 return CMD_SUCCESS;
7368 }
7369
7370 /* one clear bgp command to rule them all */
7371 DEFUN (clear_ip_bgp_all,
7372 clear_ip_bgp_all_cmd,
7373 "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>]",
7374 CLEAR_STR
7375 IP_STR
7376 BGP_STR
7377 BGP_INSTANCE_HELP_STR
7378 BGP_AFI_HELP_STR
7379 "Address Family\n"
7380 BGP_SAFI_WITH_LABEL_HELP_STR
7381 "Address Family modifier\n"
7382 "Clear all peers\n"
7383 "BGP neighbor address to clear\n"
7384 "BGP IPv6 neighbor to clear\n"
7385 "BGP neighbor on interface to clear\n"
7386 "Clear peers with the AS number\n"
7387 "Clear all external peers\n"
7388 "Clear all members of peer-group\n"
7389 "BGP peer-group name\n"
7390 BGP_SOFT_STR
7391 BGP_SOFT_IN_STR
7392 BGP_SOFT_OUT_STR
7393 BGP_SOFT_IN_STR
7394 "Push out prefix-list ORF and do inbound soft reconfig\n"
7395 BGP_SOFT_OUT_STR)
7396 {
7397 char *vrf = NULL;
7398
7399 afi_t afi = AFI_UNSPEC;
7400 safi_t safi = SAFI_UNSPEC;
7401 enum clear_sort clr_sort = clear_peer;
7402 enum bgp_clear_type clr_type;
7403 char *clr_arg = NULL;
7404
7405 int idx = 0;
7406
7407 /* clear [ip] bgp */
7408 if (argv_find(argv, argc, "ip", &idx))
7409 afi = AFI_IP;
7410
7411 /* [<vrf> VIEWVRFNAME] */
7412 if (argv_find(argv, argc, "vrf", &idx)) {
7413 vrf = argv[idx + 1]->arg;
7414 idx += 2;
7415 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
7416 vrf = NULL;
7417 } else if (argv_find(argv, argc, "view", &idx)) {
7418 /* [<view> VIEWVRFNAME] */
7419 vrf = argv[idx + 1]->arg;
7420 idx += 2;
7421 }
7422 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
7423 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
7424 argv_find_and_parse_safi(argv, argc, &idx, &safi);
7425
7426 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
7427 if (argv_find(argv, argc, "*", &idx)) {
7428 clr_sort = clear_all;
7429 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7430 clr_sort = clear_peer;
7431 clr_arg = argv[idx]->arg;
7432 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
7433 clr_sort = clear_peer;
7434 clr_arg = argv[idx]->arg;
7435 } else if (argv_find(argv, argc, "peer-group", &idx)) {
7436 clr_sort = clear_group;
7437 idx++;
7438 clr_arg = argv[idx]->arg;
7439 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
7440 clr_sort = clear_peer;
7441 clr_arg = argv[idx]->arg;
7442 } else if (argv_find(argv, argc, "WORD", &idx)) {
7443 clr_sort = clear_peer;
7444 clr_arg = argv[idx]->arg;
7445 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
7446 clr_sort = clear_as;
7447 clr_arg = argv[idx]->arg;
7448 } else if (argv_find(argv, argc, "external", &idx)) {
7449 clr_sort = clear_external;
7450 }
7451
7452 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
7453 if (argv_find(argv, argc, "soft", &idx)) {
7454 if (argv_find(argv, argc, "in", &idx)
7455 || argv_find(argv, argc, "out", &idx))
7456 clr_type = strmatch(argv[idx]->text, "in")
7457 ? BGP_CLEAR_SOFT_IN
7458 : BGP_CLEAR_SOFT_OUT;
7459 else
7460 clr_type = BGP_CLEAR_SOFT_BOTH;
7461 } else if (argv_find(argv, argc, "in", &idx)) {
7462 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
7463 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
7464 : BGP_CLEAR_SOFT_IN;
7465 } else if (argv_find(argv, argc, "out", &idx)) {
7466 clr_type = BGP_CLEAR_SOFT_OUT;
7467 } else
7468 clr_type = BGP_CLEAR_SOFT_NONE;
7469
7470 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
7471 }
7472
7473 DEFUN (clear_ip_bgp_prefix,
7474 clear_ip_bgp_prefix_cmd,
7475 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
7476 CLEAR_STR
7477 IP_STR
7478 BGP_STR
7479 BGP_INSTANCE_HELP_STR
7480 "Clear bestpath and re-advertise\n"
7481 "IPv4 prefix\n")
7482 {
7483 char *vrf = NULL;
7484 char *prefix = NULL;
7485
7486 int idx = 0;
7487
7488 /* [<view|vrf> VIEWVRFNAME] */
7489 if (argv_find(argv, argc, "vrf", &idx)) {
7490 vrf = argv[idx + 1]->arg;
7491 idx += 2;
7492 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
7493 vrf = NULL;
7494 } else if (argv_find(argv, argc, "view", &idx)) {
7495 /* [<view> VIEWVRFNAME] */
7496 vrf = argv[idx + 1]->arg;
7497 idx += 2;
7498 }
7499
7500 prefix = argv[argc - 1]->arg;
7501
7502 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
7503 }
7504
7505 DEFUN (clear_bgp_ipv6_safi_prefix,
7506 clear_bgp_ipv6_safi_prefix_cmd,
7507 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
7508 CLEAR_STR
7509 IP_STR
7510 BGP_STR
7511 "Address Family\n"
7512 BGP_SAFI_HELP_STR
7513 "Clear bestpath and re-advertise\n"
7514 "IPv6 prefix\n")
7515 {
7516 int idx_safi = 0;
7517 int idx_ipv6_prefix = 0;
7518 safi_t safi = SAFI_UNICAST;
7519 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7520 argv[idx_ipv6_prefix]->arg : NULL;
7521
7522 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7523 return bgp_clear_prefix(
7524 vty, NULL, prefix, AFI_IP6,
7525 safi, NULL);
7526 }
7527
7528 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
7529 clear_bgp_instance_ipv6_safi_prefix_cmd,
7530 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
7531 CLEAR_STR
7532 IP_STR
7533 BGP_STR
7534 BGP_INSTANCE_HELP_STR
7535 "Address Family\n"
7536 BGP_SAFI_HELP_STR
7537 "Clear bestpath and re-advertise\n"
7538 "IPv6 prefix\n")
7539 {
7540 int idx_safi = 0;
7541 int idx_vrfview = 0;
7542 int idx_ipv6_prefix = 0;
7543 safi_t safi = SAFI_UNICAST;
7544 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7545 argv[idx_ipv6_prefix]->arg : NULL;
7546 char *vrfview = NULL;
7547
7548 /* [<view|vrf> VIEWVRFNAME] */
7549 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
7550 vrfview = argv[idx_vrfview + 1]->arg;
7551 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
7552 vrfview = NULL;
7553 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
7554 /* [<view> VIEWVRFNAME] */
7555 vrfview = argv[idx_vrfview + 1]->arg;
7556 }
7557 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7558
7559 return bgp_clear_prefix(
7560 vty, vrfview, prefix,
7561 AFI_IP6, safi, NULL);
7562 }
7563
7564 DEFUN (show_bgp_views,
7565 show_bgp_views_cmd,
7566 "show [ip] bgp views",
7567 SHOW_STR
7568 IP_STR
7569 BGP_STR
7570 "Show the defined BGP views\n")
7571 {
7572 struct list *inst = bm->bgp;
7573 struct listnode *node;
7574 struct bgp *bgp;
7575
7576 vty_out(vty, "Defined BGP views:\n");
7577 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7578 /* Skip VRFs. */
7579 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
7580 continue;
7581 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
7582 bgp->as);
7583 }
7584
7585 return CMD_SUCCESS;
7586 }
7587
7588 DEFUN (show_bgp_vrfs,
7589 show_bgp_vrfs_cmd,
7590 "show [ip] bgp vrfs [json]",
7591 SHOW_STR
7592 IP_STR
7593 BGP_STR
7594 "Show BGP VRFs\n"
7595 JSON_STR)
7596 {
7597 char buf[ETHER_ADDR_STRLEN];
7598 struct list *inst = bm->bgp;
7599 struct listnode *node;
7600 struct bgp *bgp;
7601 bool uj = use_json(argc, argv);
7602 json_object *json = NULL;
7603 json_object *json_vrfs = NULL;
7604 int count = 0;
7605
7606 if (uj) {
7607 json = json_object_new_object();
7608 json_vrfs = json_object_new_object();
7609 }
7610
7611 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7612 const char *name, *type;
7613 struct peer *peer;
7614 struct listnode *node2, *nnode2;
7615 int peers_cfg, peers_estb;
7616 json_object *json_vrf = NULL;
7617
7618 /* Skip Views. */
7619 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
7620 continue;
7621
7622 count++;
7623 if (!uj && count == 1) {
7624 vty_out(vty,
7625 "%4s %-5s %-16s %9s %10s %-37s\n",
7626 "Type", "Id", "routerId", "#PeersVfg",
7627 "#PeersEstb", "Name");
7628 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
7629 "L3-VNI", "RouterMAC", "Interface");
7630 }
7631
7632 peers_cfg = peers_estb = 0;
7633 if (uj)
7634 json_vrf = json_object_new_object();
7635
7636
7637 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
7638 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7639 continue;
7640 peers_cfg++;
7641 if (peer->status == Established)
7642 peers_estb++;
7643 }
7644
7645 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
7646 name = VRF_DEFAULT_NAME;
7647 type = "DFLT";
7648 } else {
7649 name = bgp->name;
7650 type = "VRF";
7651 }
7652
7653
7654 if (uj) {
7655 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7656 ? -1
7657 : (int64_t)bgp->vrf_id;
7658 json_object_string_add(json_vrf, "type", type);
7659 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
7660 json_object_string_add(json_vrf, "routerId",
7661 inet_ntoa(bgp->router_id));
7662 json_object_int_add(json_vrf, "numConfiguredPeers",
7663 peers_cfg);
7664 json_object_int_add(json_vrf, "numEstablishedPeers",
7665 peers_estb);
7666
7667 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
7668 json_object_string_add(
7669 json_vrf, "rmac",
7670 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
7671 json_object_string_add(json_vrf, "interface",
7672 ifindex2ifname(bgp->l3vni_svi_ifindex,
7673 bgp->vrf_id));
7674 json_object_object_add(json_vrfs, name, json_vrf);
7675 } else {
7676 vty_out(vty,
7677 "%4s %-5d %-16s %-9u %-10u %-37s\n",
7678 type,
7679 bgp->vrf_id == VRF_UNKNOWN ? -1
7680 : (int)bgp->vrf_id,
7681 inet_ntoa(bgp->router_id), peers_cfg,
7682 peers_estb, name);
7683 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
7684 bgp->l3vni,
7685 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
7686 ifindex2ifname(bgp->l3vni_svi_ifindex,
7687 bgp->vrf_id));
7688 }
7689 }
7690
7691 if (uj) {
7692 json_object_object_add(json, "vrfs", json_vrfs);
7693
7694 json_object_int_add(json, "totalVrfs", count);
7695
7696 vty_out(vty, "%s\n", json_object_to_json_string_ext(
7697 json, JSON_C_TO_STRING_PRETTY));
7698 json_object_free(json);
7699 } else {
7700 if (count)
7701 vty_out(vty,
7702 "\nTotal number of VRFs (including default): %d\n",
7703 count);
7704 }
7705
7706 return CMD_SUCCESS;
7707 }
7708
7709 DEFUN (show_bgp_mac_hash,
7710 show_bgp_mac_hash_cmd,
7711 "show bgp mac hash",
7712 SHOW_STR
7713 BGP_STR
7714 "Mac Address\n"
7715 "Mac Address database\n")
7716 {
7717 bgp_mac_dump_table(vty);
7718
7719 return CMD_SUCCESS;
7720 }
7721
7722 static void show_tip_entry(struct hash_bucket *bucket, void *args)
7723 {
7724 struct vty *vty = (struct vty *)args;
7725 struct tip_addr *tip = (struct tip_addr *)bucket->data;
7726
7727 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(tip->addr),
7728 tip->refcnt);
7729 }
7730
7731 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
7732 {
7733 vty_out(vty, "self nexthop database:\n");
7734 bgp_nexthop_show_address_hash(vty, bgp);
7735
7736 vty_out(vty, "Tunnel-ip database:\n");
7737 hash_iterate(bgp->tip_hash,
7738 (void (*)(struct hash_bucket *, void *))show_tip_entry,
7739 vty);
7740 }
7741
7742 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
7743 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
7744 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
7745 "martian next-hops\n"
7746 "martian next-hop database\n")
7747 {
7748 struct bgp *bgp = NULL;
7749 int idx = 0;
7750 char *name = NULL;
7751
7752 /* [<vrf> VIEWVRFNAME] */
7753 if (argv_find(argv, argc, "vrf", &idx)) {
7754 name = argv[idx + 1]->arg;
7755 if (name && strmatch(name, VRF_DEFAULT_NAME))
7756 name = NULL;
7757 } else if (argv_find(argv, argc, "view", &idx))
7758 /* [<view> VIEWVRFNAME] */
7759 name = argv[idx + 1]->arg;
7760 if (name)
7761 bgp = bgp_lookup_by_name(name);
7762 else
7763 bgp = bgp_get_default();
7764
7765 if (!bgp) {
7766 vty_out(vty, "%% No BGP process is configured\n");
7767 return CMD_WARNING;
7768 }
7769 bgp_show_martian_nexthops(vty, bgp);
7770
7771 return CMD_SUCCESS;
7772 }
7773
7774 DEFUN (show_bgp_memory,
7775 show_bgp_memory_cmd,
7776 "show [ip] bgp memory",
7777 SHOW_STR
7778 IP_STR
7779 BGP_STR
7780 "Global BGP memory statistics\n")
7781 {
7782 char memstrbuf[MTYPE_MEMSTR_LEN];
7783 unsigned long count;
7784
7785 /* RIB related usage stats */
7786 count = mtype_stats_alloc(MTYPE_BGP_NODE);
7787 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
7788 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7789 count * sizeof(struct bgp_node)));
7790
7791 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
7792 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
7793 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7794 count * sizeof(struct bgp_path_info)));
7795 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
7796 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
7797 count,
7798 mtype_memstr(
7799 memstrbuf, sizeof(memstrbuf),
7800 count * sizeof(struct bgp_path_info_extra)));
7801
7802 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
7803 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
7804 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7805 count * sizeof(struct bgp_static)));
7806
7807 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
7808 vty_out(vty, "%ld Packets, using %s of memory\n", count,
7809 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7810 count * sizeof(struct bpacket)));
7811
7812 /* Adj-In/Out */
7813 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
7814 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
7815 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7816 count * sizeof(struct bgp_adj_in)));
7817 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
7818 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
7819 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7820 count * sizeof(struct bgp_adj_out)));
7821
7822 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
7823 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
7824 count,
7825 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7826 count * sizeof(struct bgp_nexthop_cache)));
7827
7828 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
7829 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
7830 count,
7831 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7832 count * sizeof(struct bgp_damp_info)));
7833
7834 /* Attributes */
7835 count = attr_count();
7836 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
7837 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7838 count * sizeof(struct attr)));
7839
7840 if ((count = attr_unknown_count()))
7841 vty_out(vty, "%ld unknown attributes\n", count);
7842
7843 /* AS_PATH attributes */
7844 count = aspath_count();
7845 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
7846 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7847 count * sizeof(struct aspath)));
7848
7849 count = mtype_stats_alloc(MTYPE_AS_SEG);
7850 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
7851 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7852 count * sizeof(struct assegment)));
7853
7854 /* Other attributes */
7855 if ((count = community_count()))
7856 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
7857 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7858 count * sizeof(struct community)));
7859 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
7860 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
7861 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7862 count * sizeof(struct ecommunity)));
7863 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
7864 vty_out(vty,
7865 "%ld BGP large-community entries, using %s of memory\n",
7866 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7867 count * sizeof(struct lcommunity)));
7868
7869 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
7870 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
7871 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7872 count * sizeof(struct cluster_list)));
7873
7874 /* Peer related usage */
7875 count = mtype_stats_alloc(MTYPE_BGP_PEER);
7876 vty_out(vty, "%ld peers, using %s of memory\n", count,
7877 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7878 count * sizeof(struct peer)));
7879
7880 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
7881 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
7882 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7883 count * sizeof(struct peer_group)));
7884
7885 /* Other */
7886 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
7887 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
7888 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7889 count * sizeof(regex_t)));
7890 return CMD_SUCCESS;
7891 }
7892
7893 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
7894 {
7895 json_object *bestpath = json_object_new_object();
7896
7897 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_IGNORE))
7898 json_object_string_add(bestpath, "asPath", "ignore");
7899
7900 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_CONFED))
7901 json_object_string_add(bestpath, "asPath", "confed");
7902
7903 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
7904 if (bgp_flag_check(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
7905 json_object_string_add(bestpath, "multiPathRelax",
7906 "as-set");
7907 else
7908 json_object_string_add(bestpath, "multiPathRelax",
7909 "true");
7910 } else
7911 json_object_string_add(bestpath, "multiPathRelax", "false");
7912
7913 if (bgp_flag_check(bgp, BGP_FLAG_COMPARE_ROUTER_ID))
7914 json_object_string_add(bestpath, "compareRouterId", "true");
7915 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED)
7916 || bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST)) {
7917 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED))
7918 json_object_string_add(bestpath, "med", "confed");
7919 if (bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST))
7920 json_object_string_add(bestpath, "med",
7921 "missing-as-worst");
7922 else
7923 json_object_string_add(bestpath, "med", "true");
7924 }
7925
7926 json_object_object_add(json, "bestPath", bestpath);
7927 }
7928
7929 /* Print the error code/subcode for why the peer is down */
7930 static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
7931 json_object *json_peer, bool use_json)
7932 {
7933 const char *code_str;
7934 const char *subcode_str;
7935
7936 if (use_json) {
7937 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
7938 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
7939 char errorcodesubcode_hexstr[5];
7940 char errorcodesubcode_str[256];
7941
7942 code_str = bgp_notify_code_str(peer->notify.code);
7943 subcode_str = bgp_notify_subcode_str(
7944 peer->notify.code,
7945 peer->notify.subcode);
7946
7947 sprintf(errorcodesubcode_hexstr, "%02X%02X",
7948 peer->notify.code, peer->notify.subcode);
7949 json_object_string_add(json_peer,
7950 "lastErrorCodeSubcode",
7951 errorcodesubcode_hexstr);
7952 snprintf(errorcodesubcode_str, 255, "%s%s",
7953 code_str, subcode_str);
7954 json_object_string_add(json_peer,
7955 "lastNotificationReason",
7956 errorcodesubcode_str);
7957 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
7958 && peer->notify.code == BGP_NOTIFY_CEASE
7959 && (peer->notify.subcode
7960 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
7961 || peer->notify.subcode
7962 == BGP_NOTIFY_CEASE_ADMIN_RESET)
7963 && peer->notify.length) {
7964 char msgbuf[1024];
7965 const char *msg_str;
7966
7967 msg_str = bgp_notify_admin_message(
7968 msgbuf, sizeof(msgbuf),
7969 (uint8_t *)peer->notify.data,
7970 peer->notify.length);
7971 if (msg_str)
7972 json_object_string_add(
7973 json_peer,
7974 "lastShutdownDescription",
7975 msg_str);
7976 }
7977
7978 }
7979 json_object_string_add(json_peer, "lastResetDueTo",
7980 peer_down_str[(int)peer->last_reset]);
7981 json_object_int_add(json_peer, "lastResetCode",
7982 peer->last_reset);
7983 } else {
7984 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
7985 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
7986 code_str = bgp_notify_code_str(peer->notify.code);
7987 subcode_str =
7988 bgp_notify_subcode_str(peer->notify.code,
7989 peer->notify.subcode);
7990 vty_out(vty, " Notification %s (%s%s)\n",
7991 peer->last_reset == PEER_DOWN_NOTIFY_SEND
7992 ? "sent"
7993 : "received",
7994 code_str, subcode_str);
7995 } else {
7996 vty_out(vty, " %s\n",
7997 peer_down_str[(int)peer->last_reset]);
7998 }
7999 }
8000 }
8001
8002 static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
8003 safi_t safi)
8004 {
8005 return ((peer->status != Established) ||
8006 !peer->afc_recv[afi][safi]);
8007 }
8008
8009 static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
8010 struct peer *peer, json_object *json_peer,
8011 int max_neighbor_width, bool use_json)
8012 {
8013 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
8014 int len;
8015
8016 if (use_json) {
8017 if (peer_dynamic_neighbor(peer))
8018 json_object_boolean_true_add(json_peer,
8019 "dynamicPeer");
8020 if (peer->hostname)
8021 json_object_string_add(json_peer, "hostname",
8022 peer->hostname);
8023
8024 if (peer->domainname)
8025 json_object_string_add(json_peer, "domainname",
8026 peer->domainname);
8027 json_object_int_add(json_peer, "connectionsEstablished",
8028 peer->established);
8029 json_object_int_add(json_peer, "connectionsDropped",
8030 peer->dropped);
8031 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
8032 use_json, json_peer);
8033 if (peer->status == Established)
8034 json_object_string_add(json_peer, "lastResetDueTo",
8035 "AFI/SAFI Not Negotiated");
8036 else
8037 bgp_show_peer_reset(NULL, peer, json_peer, true);
8038 } else {
8039 dn_flag[1] = '\0';
8040 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
8041 if (peer->hostname
8042 && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
8043 len = vty_out(vty, "%s%s(%s)", dn_flag,
8044 peer->hostname, peer->host);
8045 else
8046 len = vty_out(vty, "%s%s", dn_flag, peer->host);
8047
8048 /* pad the neighbor column with spaces */
8049 if (len < max_neighbor_width)
8050 vty_out(vty, "%*s", max_neighbor_width - len,
8051 " ");
8052 vty_out(vty, "%7d %7d %8s", peer->established,
8053 peer->dropped,
8054 peer_uptime(peer->uptime, timebuf,
8055 BGP_UPTIME_LEN, 0, NULL));
8056 if (peer->status == Established)
8057 vty_out(vty, " AFI/SAFI Not Negotiated\n");
8058 else
8059 bgp_show_peer_reset(vty, peer, NULL,
8060 false);
8061 }
8062 }
8063
8064
8065 /* Show BGP peer's summary information. */
8066 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
8067 bool show_failed, bool use_json)
8068 {
8069 struct peer *peer;
8070 struct listnode *node, *nnode;
8071 unsigned int count = 0, dn_count = 0;
8072 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
8073 char neighbor_buf[VTY_BUFSIZ];
8074 int neighbor_col_default_width = 16;
8075 int len, failed_count = 0;
8076 int max_neighbor_width = 0;
8077 int pfx_rcd_safi;
8078 json_object *json = NULL;
8079 json_object *json_peer = NULL;
8080 json_object *json_peers = NULL;
8081 struct peer_af *paf;
8082
8083 /* labeled-unicast routes are installed in the unicast table so in order
8084 * to
8085 * display the correct PfxRcd value we must look at SAFI_UNICAST
8086 */
8087
8088 if (safi == SAFI_LABELED_UNICAST)
8089 pfx_rcd_safi = SAFI_UNICAST;
8090 else
8091 pfx_rcd_safi = safi;
8092
8093 if (use_json) {
8094 json = json_object_new_object();
8095 json_peers = json_object_new_object();
8096 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8097 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
8098 continue;
8099
8100 if (peer->afc[afi][safi]) {
8101 /* See if we have at least a single failed peer */
8102 if (bgp_has_peer_failed(peer, afi, safi))
8103 failed_count++;
8104 count++;
8105 }
8106 if (peer_dynamic_neighbor(peer))
8107 dn_count++;
8108 }
8109
8110 } else {
8111 /* Loop over all neighbors that will be displayed to determine
8112 * how many
8113 * characters are needed for the Neighbor column
8114 */
8115 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8116 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
8117 continue;
8118
8119 if (peer->afc[afi][safi]) {
8120 memset(dn_flag, '\0', sizeof(dn_flag));
8121 if (peer_dynamic_neighbor(peer))
8122 dn_flag[0] = '*';
8123
8124 if (peer->hostname
8125 && bgp_flag_check(bgp,
8126 BGP_FLAG_SHOW_HOSTNAME))
8127 sprintf(neighbor_buf, "%s%s(%s) ",
8128 dn_flag, peer->hostname,
8129 peer->host);
8130 else
8131 sprintf(neighbor_buf, "%s%s ", dn_flag,
8132 peer->host);
8133
8134 len = strlen(neighbor_buf);
8135
8136 if (len > max_neighbor_width)
8137 max_neighbor_width = len;
8138
8139 /* See if we have at least a single failed peer */
8140 if (bgp_has_peer_failed(peer, afi, safi))
8141 failed_count++;
8142 count++;
8143 }
8144 }
8145
8146 /* Originally we displayed the Neighbor column as 16
8147 * characters wide so make that the default
8148 */
8149 if (max_neighbor_width < neighbor_col_default_width)
8150 max_neighbor_width = neighbor_col_default_width;
8151 }
8152
8153 if (show_failed && !failed_count) {
8154 if (use_json) {
8155 json_object_int_add(json, "failedPeersCount", 0);
8156 json_object_int_add(json, "dynamicPeers", dn_count);
8157 json_object_int_add(json, "totalPeers", count);
8158
8159 vty_out(vty, "%s\n", json_object_to_json_string_ext(
8160 json, JSON_C_TO_STRING_PRETTY));
8161 json_object_free(json);
8162 } else {
8163 vty_out(vty, "%% No failed BGP neighbors found\n");
8164 vty_out(vty, "\nTotal number of neighbors %d\n", count);
8165 }
8166 return CMD_SUCCESS;
8167 }
8168
8169 count = 0; /* Reset the value as its used again */
8170 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8171 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
8172 continue;
8173
8174 if (!peer->afc[afi][safi])
8175 continue;
8176
8177 if (!count) {
8178 unsigned long ents;
8179 char memstrbuf[MTYPE_MEMSTR_LEN];
8180 int64_t vrf_id_ui;
8181
8182 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
8183 ? -1
8184 : (int64_t)bgp->vrf_id;
8185
8186 /* Usage summary and header */
8187 if (use_json) {
8188 json_object_string_add(
8189 json, "routerId",
8190 inet_ntoa(bgp->router_id));
8191 json_object_int_add(json, "as", bgp->as);
8192 json_object_int_add(json, "vrfId", vrf_id_ui);
8193 json_object_string_add(
8194 json, "vrfName",
8195 (bgp->inst_type
8196 == BGP_INSTANCE_TYPE_DEFAULT)
8197 ? VRF_DEFAULT_NAME
8198 : bgp->name);
8199 } else {
8200 vty_out(vty,
8201 "BGP router identifier %s, local AS number %u vrf-id %d",
8202 inet_ntoa(bgp->router_id), bgp->as,
8203 bgp->vrf_id == VRF_UNKNOWN
8204 ? -1
8205 : (int)bgp->vrf_id);
8206 vty_out(vty, "\n");
8207 }
8208
8209 if (bgp_update_delay_configured(bgp)) {
8210 if (use_json) {
8211 json_object_int_add(
8212 json, "updateDelayLimit",
8213 bgp->v_update_delay);
8214
8215 if (bgp->v_update_delay
8216 != bgp->v_establish_wait)
8217 json_object_int_add(
8218 json,
8219 "updateDelayEstablishWait",
8220 bgp->v_establish_wait);
8221
8222 if (bgp_update_delay_active(bgp)) {
8223 json_object_string_add(
8224 json,
8225 "updateDelayFirstNeighbor",
8226 bgp->update_delay_begin_time);
8227 json_object_boolean_true_add(
8228 json,
8229 "updateDelayInProgress");
8230 } else {
8231 if (bgp->update_delay_over) {
8232 json_object_string_add(
8233 json,
8234 "updateDelayFirstNeighbor",
8235 bgp->update_delay_begin_time);
8236 json_object_string_add(
8237 json,
8238 "updateDelayBestpathResumed",
8239 bgp->update_delay_end_time);
8240 json_object_string_add(
8241 json,
8242 "updateDelayZebraUpdateResume",
8243 bgp->update_delay_zebra_resume_time);
8244 json_object_string_add(
8245 json,
8246 "updateDelayPeerUpdateResume",
8247 bgp->update_delay_peers_resume_time);
8248 }
8249 }
8250 } else {
8251 vty_out(vty,
8252 "Read-only mode update-delay limit: %d seconds\n",
8253 bgp->v_update_delay);
8254 if (bgp->v_update_delay
8255 != bgp->v_establish_wait)
8256 vty_out(vty,
8257 " Establish wait: %d seconds\n",
8258 bgp->v_establish_wait);
8259
8260 if (bgp_update_delay_active(bgp)) {
8261 vty_out(vty,
8262 " First neighbor established: %s\n",
8263 bgp->update_delay_begin_time);
8264 vty_out(vty,
8265 " Delay in progress\n");
8266 } else {
8267 if (bgp->update_delay_over) {
8268 vty_out(vty,
8269 " First neighbor established: %s\n",
8270 bgp->update_delay_begin_time);
8271 vty_out(vty,
8272 " Best-paths resumed: %s\n",
8273 bgp->update_delay_end_time);
8274 vty_out(vty,
8275 " zebra update resumed: %s\n",
8276 bgp->update_delay_zebra_resume_time);
8277 vty_out(vty,
8278 " peers update resumed: %s\n",
8279 bgp->update_delay_peers_resume_time);
8280 }
8281 }
8282 }
8283 }
8284
8285 if (use_json) {
8286 if (bgp_maxmed_onstartup_configured(bgp)
8287 && bgp->maxmed_active)
8288 json_object_boolean_true_add(
8289 json, "maxMedOnStartup");
8290 if (bgp->v_maxmed_admin)
8291 json_object_boolean_true_add(
8292 json, "maxMedAdministrative");
8293
8294 json_object_int_add(
8295 json, "tableVersion",
8296 bgp_table_version(bgp->rib[afi][safi]));
8297
8298 ents = bgp_table_count(bgp->rib[afi][safi]);
8299 json_object_int_add(json, "ribCount", ents);
8300 json_object_int_add(
8301 json, "ribMemory",
8302 ents * sizeof(struct bgp_node));
8303
8304 ents = bgp->af_peer_count[afi][safi];
8305 json_object_int_add(json, "peerCount", ents);
8306 json_object_int_add(json, "peerMemory",
8307 ents * sizeof(struct peer));
8308
8309 if ((ents = listcount(bgp->group))) {
8310 json_object_int_add(
8311 json, "peerGroupCount", ents);
8312 json_object_int_add(
8313 json, "peerGroupMemory",
8314 ents * sizeof(struct
8315 peer_group));
8316 }
8317
8318 if (CHECK_FLAG(bgp->af_flags[afi][safi],
8319 BGP_CONFIG_DAMPENING))
8320 json_object_boolean_true_add(
8321 json, "dampeningEnabled");
8322 } else {
8323 if (bgp_maxmed_onstartup_configured(bgp)
8324 && bgp->maxmed_active)
8325 vty_out(vty,
8326 "Max-med on-startup active\n");
8327 if (bgp->v_maxmed_admin)
8328 vty_out(vty,
8329 "Max-med administrative active\n");
8330
8331 vty_out(vty, "BGP table version %" PRIu64 "\n",
8332 bgp_table_version(bgp->rib[afi][safi]));
8333
8334 ents = bgp_table_count(bgp->rib[afi][safi]);
8335 vty_out(vty,
8336 "RIB entries %ld, using %s of memory\n",
8337 ents,
8338 mtype_memstr(memstrbuf,
8339 sizeof(memstrbuf),
8340 ents * sizeof(struct
8341 bgp_node)));
8342
8343 /* Peer related usage */
8344 ents = bgp->af_peer_count[afi][safi];
8345 vty_out(vty, "Peers %ld, using %s of memory\n",
8346 ents,
8347 mtype_memstr(
8348 memstrbuf, sizeof(memstrbuf),
8349 ents * sizeof(struct peer)));
8350
8351 if ((ents = listcount(bgp->group)))
8352 vty_out(vty,
8353 "Peer groups %ld, using %s of memory\n",
8354 ents,
8355 mtype_memstr(
8356 memstrbuf,
8357 sizeof(memstrbuf),
8358 ents * sizeof(struct
8359 peer_group)));
8360
8361 if (CHECK_FLAG(bgp->af_flags[afi][safi],
8362 BGP_CONFIG_DAMPENING))
8363 vty_out(vty, "Dampening enabled.\n");
8364 vty_out(vty, "\n");
8365
8366 /* Subtract 8 here because 'Neighbor' is
8367 * 8 characters */
8368 vty_out(vty, "Neighbor");
8369 vty_out(vty, "%*s", max_neighbor_width - 8,
8370 " ");
8371 if (show_failed)
8372 vty_out(vty, "EstdCnt DropCnt ResetTime Reason\n");
8373 else
8374 vty_out(vty,
8375 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd\n");
8376 }
8377 }
8378
8379 count++;
8380 /* Works for both failed & successful cases */
8381 if (peer_dynamic_neighbor(peer))
8382 dn_count++;
8383
8384 if (use_json) {
8385 json_peer = NULL;
8386
8387 if (show_failed &&
8388 bgp_has_peer_failed(peer, afi, safi)) {
8389 json_peer = json_object_new_object();
8390 bgp_show_failed_summary(vty, bgp, peer,
8391 json_peer, 0, use_json);
8392 } else if (!show_failed) {
8393 json_peer = json_object_new_object();
8394 if (peer_dynamic_neighbor(peer)) {
8395 json_object_boolean_true_add(json_peer,
8396 "dynamicPeer");
8397 }
8398
8399 if (peer->hostname)
8400 json_object_string_add(json_peer, "hostname",
8401 peer->hostname);
8402
8403 if (peer->domainname)
8404 json_object_string_add(json_peer, "domainname",
8405 peer->domainname);
8406
8407 json_object_int_add(json_peer, "remoteAs", peer->as);
8408 json_object_int_add(json_peer, "version", 4);
8409 json_object_int_add(json_peer, "msgRcvd",
8410 PEER_TOTAL_RX(peer));
8411 json_object_int_add(json_peer, "msgSent",
8412 PEER_TOTAL_TX(peer));
8413
8414 json_object_int_add(json_peer, "tableVersion",
8415 peer->version[afi][safi]);
8416 json_object_int_add(json_peer, "outq",
8417 peer->obuf->count);
8418 json_object_int_add(json_peer, "inq", 0);
8419 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
8420 use_json, json_peer);
8421
8422 /*
8423 * Adding "pfxRcd" field to match with the corresponding
8424 * CLI. "prefixReceivedCount" will be deprecated in
8425 * future.
8426 */
8427 json_object_int_add(json_peer, "prefixReceivedCount",
8428 peer->pcount[afi][pfx_rcd_safi]);
8429 json_object_int_add(json_peer, "pfxRcd",
8430 peer->pcount[afi][pfx_rcd_safi]);
8431
8432 paf = peer_af_find(peer, afi, pfx_rcd_safi);
8433 if (paf && PAF_SUBGRP(paf))
8434 json_object_int_add(json_peer,
8435 "pfxSnt",
8436 (PAF_SUBGRP(paf))->scount);
8437 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
8438 json_object_string_add(json_peer, "state",
8439 "Idle (Admin)");
8440 else if (peer->afc_recv[afi][safi])
8441 json_object_string_add(
8442 json_peer, "state",
8443 lookup_msg(bgp_status_msg, peer->status,
8444 NULL));
8445 else if (CHECK_FLAG(peer->sflags,
8446 PEER_STATUS_PREFIX_OVERFLOW))
8447 json_object_string_add(json_peer, "state",
8448 "Idle (PfxCt)");
8449 else
8450 json_object_string_add(
8451 json_peer, "state",
8452 lookup_msg(bgp_status_msg, peer->status,
8453 NULL));
8454 json_object_int_add(json_peer, "connectionsEstablished",
8455 peer->established);
8456 json_object_int_add(json_peer, "connectionsDropped",
8457 peer->dropped);
8458 }
8459 /* Avoid creating empty peer dicts in JSON */
8460 if (json_peer == NULL)
8461 continue;
8462
8463 if (peer->conf_if)
8464 json_object_string_add(json_peer, "idType",
8465 "interface");
8466 else if (peer->su.sa.sa_family == AF_INET)
8467 json_object_string_add(json_peer, "idType",
8468 "ipv4");
8469 else if (peer->su.sa.sa_family == AF_INET6)
8470 json_object_string_add(json_peer, "idType",
8471 "ipv6");
8472 json_object_object_add(json_peers, peer->host,
8473 json_peer);
8474 } else {
8475 if (show_failed &&
8476 bgp_has_peer_failed(peer, afi, safi)) {
8477 bgp_show_failed_summary(vty, bgp, peer, NULL,
8478 max_neighbor_width,
8479 use_json);
8480 } else if (!show_failed) {
8481 memset(dn_flag, '\0', sizeof(dn_flag));
8482 if (peer_dynamic_neighbor(peer)) {
8483 dn_flag[0] = '*';
8484 }
8485
8486 if (peer->hostname
8487 && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
8488 len = vty_out(vty, "%s%s(%s)", dn_flag,
8489 peer->hostname, peer->host);
8490 else
8491 len = vty_out(vty, "%s%s", dn_flag, peer->host);
8492
8493 /* pad the neighbor column with spaces */
8494 if (len < max_neighbor_width)
8495 vty_out(vty, "%*s", max_neighbor_width - len,
8496 " ");
8497
8498 vty_out(vty, "4 %10u %7u %7u %8" PRIu64 " %4d %4zd %8s",
8499 peer->as, PEER_TOTAL_RX(peer),
8500 PEER_TOTAL_TX(peer), peer->version[afi][safi],
8501 0, peer->obuf->count,
8502 peer_uptime(peer->uptime, timebuf,
8503 BGP_UPTIME_LEN, 0, NULL));
8504
8505 if (peer->status == Established)
8506 if (peer->afc_recv[afi][safi])
8507 vty_out(vty, " %12" PRIu32,
8508 peer->pcount
8509 [afi]
8510 [pfx_rcd_safi]);
8511 else
8512 vty_out(vty, " NoNeg");
8513 else {
8514 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
8515 vty_out(vty, " Idle (Admin)");
8516 else if (CHECK_FLAG(
8517 peer->sflags,
8518 PEER_STATUS_PREFIX_OVERFLOW))
8519 vty_out(vty, " Idle (PfxCt)");
8520 else
8521 vty_out(vty, " %12s",
8522 lookup_msg(bgp_status_msg,
8523 peer->status, NULL));
8524 }
8525 vty_out(vty, "\n");
8526 }
8527
8528 }
8529 }
8530
8531 if (use_json) {
8532 json_object_object_add(json, "peers", json_peers);
8533 json_object_int_add(json, "failedPeers", failed_count);
8534 json_object_int_add(json, "totalPeers", count);
8535 json_object_int_add(json, "dynamicPeers", dn_count);
8536
8537 if (!show_failed)
8538 bgp_show_bestpath_json(bgp, json);
8539
8540 vty_out(vty, "%s\n", json_object_to_json_string_ext(
8541 json, JSON_C_TO_STRING_PRETTY));
8542 json_object_free(json);
8543 } else {
8544 if (count)
8545 vty_out(vty, "\nTotal number of neighbors %d\n", count);
8546 else {
8547 vty_out(vty, "No %s neighbor is configured\n",
8548 get_afi_safi_str(afi, safi, false));
8549 }
8550
8551 if (dn_count) {
8552 vty_out(vty, "* - dynamic neighbor\n");
8553 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
8554 dn_count, bgp->dynamic_neighbors_limit);
8555 }
8556 }
8557
8558 return CMD_SUCCESS;
8559 }
8560
8561 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
8562 int safi, bool show_failed, bool use_json)
8563 {
8564 int is_first = 1;
8565 int afi_wildcard = (afi == AFI_MAX);
8566 int safi_wildcard = (safi == SAFI_MAX);
8567 int is_wildcard = (afi_wildcard || safi_wildcard);
8568 bool nbr_output = false;
8569
8570 if (use_json && is_wildcard)
8571 vty_out(vty, "{\n");
8572 if (afi_wildcard)
8573 afi = 1; /* AFI_IP */
8574 while (afi < AFI_MAX) {
8575 if (safi_wildcard)
8576 safi = 1; /* SAFI_UNICAST */
8577 while (safi < SAFI_MAX) {
8578 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
8579 nbr_output = true;
8580
8581 if (is_wildcard) {
8582 /*
8583 * So limit output to those afi/safi
8584 * pairs that
8585 * actualy have something interesting in
8586 * them
8587 */
8588 if (use_json) {
8589 if (!is_first)
8590 vty_out(vty, ",\n");
8591 else
8592 is_first = 0;
8593
8594 vty_out(vty, "\"%s\":",
8595 get_afi_safi_str(afi,
8596 safi,
8597 true));
8598 } else {
8599 vty_out(vty, "\n%s Summary:\n",
8600 get_afi_safi_str(afi,
8601 safi,
8602 false));
8603 }
8604 }
8605 bgp_show_summary(vty, bgp, afi, safi, show_failed,
8606 use_json);
8607 }
8608 safi++;
8609 if (!safi_wildcard)
8610 safi = SAFI_MAX;
8611 }
8612 afi++;
8613 if (!afi_wildcard)
8614 afi = AFI_MAX;
8615 }
8616
8617 if (use_json && is_wildcard)
8618 vty_out(vty, "}\n");
8619 else if (!nbr_output) {
8620 if (use_json)
8621 vty_out(vty, "{}\n");
8622 else
8623 vty_out(vty, "%% No BGP neighbors found\n");
8624 }
8625 }
8626
8627 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
8628 safi_t safi, bool show_failed,
8629 bool use_json)
8630 {
8631 struct listnode *node, *nnode;
8632 struct bgp *bgp;
8633 int is_first = 1;
8634 bool nbr_output = false;
8635
8636 if (use_json)
8637 vty_out(vty, "{\n");
8638
8639 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
8640 nbr_output = true;
8641 if (use_json) {
8642 if (!is_first)
8643 vty_out(vty, ",\n");
8644 else
8645 is_first = 0;
8646
8647 vty_out(vty, "\"%s\":",
8648 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8649 ? VRF_DEFAULT_NAME
8650 : bgp->name);
8651 } else {
8652 vty_out(vty, "\nInstance %s:\n",
8653 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8654 ? VRF_DEFAULT_NAME
8655 : bgp->name);
8656 }
8657 bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_failed,
8658 use_json);
8659 }
8660
8661 if (use_json)
8662 vty_out(vty, "}\n");
8663 else if (!nbr_output)
8664 vty_out(vty, "%% BGP instance not found\n");
8665 }
8666
8667 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
8668 safi_t safi, bool show_failed, bool use_json)
8669 {
8670 struct bgp *bgp;
8671
8672 if (name) {
8673 if (strmatch(name, "all")) {
8674 bgp_show_all_instances_summary_vty(vty, afi, safi,
8675 show_failed,
8676 use_json);
8677 return CMD_SUCCESS;
8678 } else {
8679 bgp = bgp_lookup_by_name(name);
8680
8681 if (!bgp) {
8682 if (use_json)
8683 vty_out(vty, "{}\n");
8684 else
8685 vty_out(vty,
8686 "%% BGP instance not found\n");
8687 return CMD_WARNING;
8688 }
8689
8690 bgp_show_summary_afi_safi(vty, bgp, afi, safi,
8691 show_failed, use_json);
8692 return CMD_SUCCESS;
8693 }
8694 }
8695
8696 bgp = bgp_get_default();
8697
8698 if (bgp)
8699 bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_failed,
8700 use_json);
8701 else {
8702 if (use_json)
8703 vty_out(vty, "{}\n");
8704 else
8705 vty_out(vty, "%% BGP instance not found\n");
8706 return CMD_WARNING;
8707 }
8708
8709 return CMD_SUCCESS;
8710 }
8711
8712 /* `show [ip] bgp summary' commands. */
8713 DEFUN (show_ip_bgp_summary,
8714 show_ip_bgp_summary_cmd,
8715 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [failed] [json]",
8716 SHOW_STR
8717 IP_STR
8718 BGP_STR
8719 BGP_INSTANCE_HELP_STR
8720 BGP_AFI_HELP_STR
8721 BGP_SAFI_WITH_LABEL_HELP_STR
8722 "Summary of BGP neighbor status\n"
8723 "Show only sessions not in Established state\n"
8724 JSON_STR)
8725 {
8726 char *vrf = NULL;
8727 afi_t afi = AFI_MAX;
8728 safi_t safi = SAFI_MAX;
8729 bool show_failed = false;
8730
8731 int idx = 0;
8732
8733 /* show [ip] bgp */
8734 if (argv_find(argv, argc, "ip", &idx))
8735 afi = AFI_IP;
8736 /* [<vrf> VIEWVRFNAME] */
8737 if (argv_find(argv, argc, "vrf", &idx)) {
8738 vrf = argv[idx + 1]->arg;
8739 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
8740 vrf = NULL;
8741 } else if (argv_find(argv, argc, "view", &idx))
8742 /* [<view> VIEWVRFNAME] */
8743 vrf = argv[idx + 1]->arg;
8744 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
8745 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
8746 argv_find_and_parse_safi(argv, argc, &idx, &safi);
8747 }
8748
8749 if (argv_find(argv, argc, "failed", &idx))
8750 show_failed = true;
8751
8752 bool uj = use_json(argc, argv);
8753
8754 return bgp_show_summary_vty(vty, vrf, afi, safi, show_failed, uj);
8755 }
8756
8757 const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
8758 {
8759 if (for_json)
8760 return get_afi_safi_json_str(afi, safi);
8761 else
8762 return get_afi_safi_vty_str(afi, safi);
8763 }
8764
8765 /* Show BGP peer's information. */
8766 enum show_type { show_all, show_peer, show_ipv4_all, show_ipv6_all, show_ipv4_peer, show_ipv6_peer };
8767
8768 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
8769 afi_t afi, safi_t safi,
8770 uint16_t adv_smcap, uint16_t adv_rmcap,
8771 uint16_t rcv_smcap, uint16_t rcv_rmcap,
8772 bool use_json, json_object *json_pref)
8773 {
8774 /* Send-Mode */
8775 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8776 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
8777 if (use_json) {
8778 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8779 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8780 json_object_string_add(json_pref, "sendMode",
8781 "advertisedAndReceived");
8782 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8783 json_object_string_add(json_pref, "sendMode",
8784 "advertised");
8785 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8786 json_object_string_add(json_pref, "sendMode",
8787 "received");
8788 } else {
8789 vty_out(vty, " Send-mode: ");
8790 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8791 vty_out(vty, "advertised");
8792 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8793 vty_out(vty, "%sreceived",
8794 CHECK_FLAG(p->af_cap[afi][safi],
8795 adv_smcap)
8796 ? ", "
8797 : "");
8798 vty_out(vty, "\n");
8799 }
8800 }
8801
8802 /* Receive-Mode */
8803 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8804 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
8805 if (use_json) {
8806 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8807 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8808 json_object_string_add(json_pref, "recvMode",
8809 "advertisedAndReceived");
8810 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8811 json_object_string_add(json_pref, "recvMode",
8812 "advertised");
8813 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8814 json_object_string_add(json_pref, "recvMode",
8815 "received");
8816 } else {
8817 vty_out(vty, " Receive-mode: ");
8818 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8819 vty_out(vty, "advertised");
8820 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8821 vty_out(vty, "%sreceived",
8822 CHECK_FLAG(p->af_cap[afi][safi],
8823 adv_rmcap)
8824 ? ", "
8825 : "");
8826 vty_out(vty, "\n");
8827 }
8828 }
8829 }
8830
8831 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
8832 safi_t safi, bool use_json,
8833 json_object *json_neigh)
8834 {
8835 struct bgp_filter *filter;
8836 struct peer_af *paf;
8837 char orf_pfx_name[BUFSIZ];
8838 int orf_pfx_count;
8839 json_object *json_af = NULL;
8840 json_object *json_prefA = NULL;
8841 json_object *json_prefB = NULL;
8842 json_object *json_addr = NULL;
8843
8844 if (use_json) {
8845 json_addr = json_object_new_object();
8846 json_af = json_object_new_object();
8847 filter = &p->filter[afi][safi];
8848
8849 if (peer_group_active(p))
8850 json_object_string_add(json_addr, "peerGroupMember",
8851 p->group->name);
8852
8853 paf = peer_af_find(p, afi, safi);
8854 if (paf && PAF_SUBGRP(paf)) {
8855 json_object_int_add(json_addr, "updateGroupId",
8856 PAF_UPDGRP(paf)->id);
8857 json_object_int_add(json_addr, "subGroupId",
8858 PAF_SUBGRP(paf)->id);
8859 json_object_int_add(json_addr, "packetQueueLength",
8860 bpacket_queue_virtual_length(paf));
8861 }
8862
8863 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8864 || CHECK_FLAG(p->af_cap[afi][safi],
8865 PEER_CAP_ORF_PREFIX_SM_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 json_object_int_add(json_af, "orfType",
8871 ORF_TYPE_PREFIX);
8872 json_prefA = json_object_new_object();
8873 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
8874 PEER_CAP_ORF_PREFIX_SM_ADV,
8875 PEER_CAP_ORF_PREFIX_RM_ADV,
8876 PEER_CAP_ORF_PREFIX_SM_RCV,
8877 PEER_CAP_ORF_PREFIX_RM_RCV,
8878 use_json, json_prefA);
8879 json_object_object_add(json_af, "orfPrefixList",
8880 json_prefA);
8881 }
8882
8883 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8884 || CHECK_FLAG(p->af_cap[afi][safi],
8885 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8886 || CHECK_FLAG(p->af_cap[afi][safi],
8887 PEER_CAP_ORF_PREFIX_RM_ADV)
8888 || CHECK_FLAG(p->af_cap[afi][safi],
8889 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8890 json_object_int_add(json_af, "orfOldType",
8891 ORF_TYPE_PREFIX_OLD);
8892 json_prefB = json_object_new_object();
8893 bgp_show_peer_afi_orf_cap(
8894 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8895 PEER_CAP_ORF_PREFIX_RM_ADV,
8896 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8897 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
8898 json_prefB);
8899 json_object_object_add(json_af, "orfOldPrefixList",
8900 json_prefB);
8901 }
8902
8903 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8904 || CHECK_FLAG(p->af_cap[afi][safi],
8905 PEER_CAP_ORF_PREFIX_SM_RCV)
8906 || CHECK_FLAG(p->af_cap[afi][safi],
8907 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8908 || CHECK_FLAG(p->af_cap[afi][safi],
8909 PEER_CAP_ORF_PREFIX_RM_ADV)
8910 || CHECK_FLAG(p->af_cap[afi][safi],
8911 PEER_CAP_ORF_PREFIX_RM_RCV)
8912 || CHECK_FLAG(p->af_cap[afi][safi],
8913 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8914 json_object_object_add(json_addr, "afDependentCap",
8915 json_af);
8916 else
8917 json_object_free(json_af);
8918
8919 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8920 orf_pfx_count = prefix_bgp_show_prefix_list(
8921 NULL, afi, orf_pfx_name, use_json);
8922
8923 if (CHECK_FLAG(p->af_sflags[afi][safi],
8924 PEER_STATUS_ORF_PREFIX_SEND)
8925 || orf_pfx_count) {
8926 if (CHECK_FLAG(p->af_sflags[afi][safi],
8927 PEER_STATUS_ORF_PREFIX_SEND))
8928 json_object_boolean_true_add(json_neigh,
8929 "orfSent");
8930 if (orf_pfx_count)
8931 json_object_int_add(json_addr, "orfRecvCounter",
8932 orf_pfx_count);
8933 }
8934 if (CHECK_FLAG(p->af_sflags[afi][safi],
8935 PEER_STATUS_ORF_WAIT_REFRESH))
8936 json_object_string_add(
8937 json_addr, "orfFirstUpdate",
8938 "deferredUntilORFOrRouteRefreshRecvd");
8939
8940 if (CHECK_FLAG(p->af_flags[afi][safi],
8941 PEER_FLAG_REFLECTOR_CLIENT))
8942 json_object_boolean_true_add(json_addr,
8943 "routeReflectorClient");
8944 if (CHECK_FLAG(p->af_flags[afi][safi],
8945 PEER_FLAG_RSERVER_CLIENT))
8946 json_object_boolean_true_add(json_addr,
8947 "routeServerClient");
8948 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8949 json_object_boolean_true_add(json_addr,
8950 "inboundSoftConfigPermit");
8951
8952 if (CHECK_FLAG(p->af_flags[afi][safi],
8953 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8954 json_object_boolean_true_add(
8955 json_addr,
8956 "privateAsNumsAllReplacedInUpdatesToNbr");
8957 else if (CHECK_FLAG(p->af_flags[afi][safi],
8958 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8959 json_object_boolean_true_add(
8960 json_addr,
8961 "privateAsNumsReplacedInUpdatesToNbr");
8962 else if (CHECK_FLAG(p->af_flags[afi][safi],
8963 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8964 json_object_boolean_true_add(
8965 json_addr,
8966 "privateAsNumsAllRemovedInUpdatesToNbr");
8967 else if (CHECK_FLAG(p->af_flags[afi][safi],
8968 PEER_FLAG_REMOVE_PRIVATE_AS))
8969 json_object_boolean_true_add(
8970 json_addr,
8971 "privateAsNumsRemovedInUpdatesToNbr");
8972
8973 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
8974 json_object_boolean_true_add(
8975 json_addr,
8976 bgp_addpath_names(p->addpath_type[afi][safi])
8977 ->type_json_name);
8978
8979 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8980 json_object_string_add(json_addr,
8981 "overrideASNsInOutboundUpdates",
8982 "ifAspathEqualRemoteAs");
8983
8984 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8985 || CHECK_FLAG(p->af_flags[afi][safi],
8986 PEER_FLAG_FORCE_NEXTHOP_SELF))
8987 json_object_boolean_true_add(json_addr,
8988 "routerAlwaysNextHop");
8989 if (CHECK_FLAG(p->af_flags[afi][safi],
8990 PEER_FLAG_AS_PATH_UNCHANGED))
8991 json_object_boolean_true_add(
8992 json_addr, "unchangedAsPathPropogatedToNbr");
8993 if (CHECK_FLAG(p->af_flags[afi][safi],
8994 PEER_FLAG_NEXTHOP_UNCHANGED))
8995 json_object_boolean_true_add(
8996 json_addr, "unchangedNextHopPropogatedToNbr");
8997 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8998 json_object_boolean_true_add(
8999 json_addr, "unchangedMedPropogatedToNbr");
9000 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
9001 || CHECK_FLAG(p->af_flags[afi][safi],
9002 PEER_FLAG_SEND_EXT_COMMUNITY)) {
9003 if (CHECK_FLAG(p->af_flags[afi][safi],
9004 PEER_FLAG_SEND_COMMUNITY)
9005 && CHECK_FLAG(p->af_flags[afi][safi],
9006 PEER_FLAG_SEND_EXT_COMMUNITY))
9007 json_object_string_add(json_addr,
9008 "commAttriSentToNbr",
9009 "extendedAndStandard");
9010 else if (CHECK_FLAG(p->af_flags[afi][safi],
9011 PEER_FLAG_SEND_EXT_COMMUNITY))
9012 json_object_string_add(json_addr,
9013 "commAttriSentToNbr",
9014 "extended");
9015 else
9016 json_object_string_add(json_addr,
9017 "commAttriSentToNbr",
9018 "standard");
9019 }
9020 if (CHECK_FLAG(p->af_flags[afi][safi],
9021 PEER_FLAG_DEFAULT_ORIGINATE)) {
9022 if (p->default_rmap[afi][safi].name)
9023 json_object_string_add(
9024 json_addr, "defaultRouteMap",
9025 p->default_rmap[afi][safi].name);
9026
9027 if (paf && PAF_SUBGRP(paf)
9028 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
9029 SUBGRP_STATUS_DEFAULT_ORIGINATE))
9030 json_object_boolean_true_add(json_addr,
9031 "defaultSent");
9032 else
9033 json_object_boolean_true_add(json_addr,
9034 "defaultNotSent");
9035 }
9036
9037 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
9038 if (is_evpn_enabled())
9039 json_object_boolean_true_add(
9040 json_addr, "advertiseAllVnis");
9041 }
9042
9043 if (filter->plist[FILTER_IN].name
9044 || filter->dlist[FILTER_IN].name
9045 || filter->aslist[FILTER_IN].name
9046 || filter->map[RMAP_IN].name)
9047 json_object_boolean_true_add(json_addr,
9048 "inboundPathPolicyConfig");
9049 if (filter->plist[FILTER_OUT].name
9050 || filter->dlist[FILTER_OUT].name
9051 || filter->aslist[FILTER_OUT].name
9052 || filter->map[RMAP_OUT].name || filter->usmap.name)
9053 json_object_boolean_true_add(
9054 json_addr, "outboundPathPolicyConfig");
9055
9056 /* prefix-list */
9057 if (filter->plist[FILTER_IN].name)
9058 json_object_string_add(json_addr,
9059 "incomingUpdatePrefixFilterList",
9060 filter->plist[FILTER_IN].name);
9061 if (filter->plist[FILTER_OUT].name)
9062 json_object_string_add(json_addr,
9063 "outgoingUpdatePrefixFilterList",
9064 filter->plist[FILTER_OUT].name);
9065
9066 /* distribute-list */
9067 if (filter->dlist[FILTER_IN].name)
9068 json_object_string_add(
9069 json_addr, "incomingUpdateNetworkFilterList",
9070 filter->dlist[FILTER_IN].name);
9071 if (filter->dlist[FILTER_OUT].name)
9072 json_object_string_add(
9073 json_addr, "outgoingUpdateNetworkFilterList",
9074 filter->dlist[FILTER_OUT].name);
9075
9076 /* filter-list. */
9077 if (filter->aslist[FILTER_IN].name)
9078 json_object_string_add(json_addr,
9079 "incomingUpdateAsPathFilterList",
9080 filter->aslist[FILTER_IN].name);
9081 if (filter->aslist[FILTER_OUT].name)
9082 json_object_string_add(json_addr,
9083 "outgoingUpdateAsPathFilterList",
9084 filter->aslist[FILTER_OUT].name);
9085
9086 /* route-map. */
9087 if (filter->map[RMAP_IN].name)
9088 json_object_string_add(
9089 json_addr, "routeMapForIncomingAdvertisements",
9090 filter->map[RMAP_IN].name);
9091 if (filter->map[RMAP_OUT].name)
9092 json_object_string_add(
9093 json_addr, "routeMapForOutgoingAdvertisements",
9094 filter->map[RMAP_OUT].name);
9095
9096 /* ebgp-requires-policy (inbound) */
9097 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
9098 && !bgp_inbound_policy_exists(p, filter))
9099 json_object_string_add(
9100 json_addr, "inboundEbgpRequiresPolicy",
9101 "Inbound updates discarded due to missing policy");
9102
9103 /* ebgp-requires-policy (outbound) */
9104 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
9105 && (!bgp_outbound_policy_exists(p, filter)))
9106 json_object_string_add(
9107 json_addr, "outboundEbgpRequiresPolicy",
9108 "Outbound updates discarded due to missing policy");
9109
9110 /* unsuppress-map */
9111 if (filter->usmap.name)
9112 json_object_string_add(json_addr,
9113 "selectiveUnsuppressRouteMap",
9114 filter->usmap.name);
9115
9116 /* Receive prefix count */
9117 json_object_int_add(json_addr, "acceptedPrefixCounter",
9118 p->pcount[afi][safi]);
9119 if (paf && PAF_SUBGRP(paf))
9120 json_object_int_add(json_addr, "sentPrefixCounter",
9121 (PAF_SUBGRP(paf))->scount);
9122
9123 /* Maximum prefix */
9124 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
9125 json_object_int_add(json_addr, "prefixAllowedMax",
9126 p->pmax[afi][safi]);
9127 if (CHECK_FLAG(p->af_flags[afi][safi],
9128 PEER_FLAG_MAX_PREFIX_WARNING))
9129 json_object_boolean_true_add(
9130 json_addr, "prefixAllowedMaxWarning");
9131 json_object_int_add(json_addr,
9132 "prefixAllowedWarningThresh",
9133 p->pmax_threshold[afi][safi]);
9134 if (p->pmax_restart[afi][safi])
9135 json_object_int_add(
9136 json_addr,
9137 "prefixAllowedRestartIntervalMsecs",
9138 p->pmax_restart[afi][safi] * 60000);
9139 }
9140 json_object_object_add(json_neigh, get_afi_safi_str(afi, safi, true),
9141 json_addr);
9142
9143 } else {
9144 filter = &p->filter[afi][safi];
9145
9146 vty_out(vty, " For address family: %s\n",
9147 get_afi_safi_str(afi, safi, false));
9148
9149 if (peer_group_active(p))
9150 vty_out(vty, " %s peer-group member\n",
9151 p->group->name);
9152
9153 paf = peer_af_find(p, afi, safi);
9154 if (paf && PAF_SUBGRP(paf)) {
9155 vty_out(vty, " Update group %" PRIu64
9156 ", subgroup %" PRIu64 "\n",
9157 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
9158 vty_out(vty, " Packet Queue length %d\n",
9159 bpacket_queue_virtual_length(paf));
9160 } else {
9161 vty_out(vty, " Not part of any update group\n");
9162 }
9163 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
9164 || CHECK_FLAG(p->af_cap[afi][safi],
9165 PEER_CAP_ORF_PREFIX_SM_RCV)
9166 || CHECK_FLAG(p->af_cap[afi][safi],
9167 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
9168 || CHECK_FLAG(p->af_cap[afi][safi],
9169 PEER_CAP_ORF_PREFIX_RM_ADV)
9170 || CHECK_FLAG(p->af_cap[afi][safi],
9171 PEER_CAP_ORF_PREFIX_RM_RCV)
9172 || CHECK_FLAG(p->af_cap[afi][safi],
9173 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
9174 vty_out(vty, " AF-dependant capabilities:\n");
9175
9176 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
9177 || CHECK_FLAG(p->af_cap[afi][safi],
9178 PEER_CAP_ORF_PREFIX_SM_RCV)
9179 || CHECK_FLAG(p->af_cap[afi][safi],
9180 PEER_CAP_ORF_PREFIX_RM_ADV)
9181 || CHECK_FLAG(p->af_cap[afi][safi],
9182 PEER_CAP_ORF_PREFIX_RM_RCV)) {
9183 vty_out(vty,
9184 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
9185 ORF_TYPE_PREFIX);
9186 bgp_show_peer_afi_orf_cap(
9187 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
9188 PEER_CAP_ORF_PREFIX_RM_ADV,
9189 PEER_CAP_ORF_PREFIX_SM_RCV,
9190 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
9191 }
9192 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
9193 || CHECK_FLAG(p->af_cap[afi][safi],
9194 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
9195 || CHECK_FLAG(p->af_cap[afi][safi],
9196 PEER_CAP_ORF_PREFIX_RM_ADV)
9197 || CHECK_FLAG(p->af_cap[afi][safi],
9198 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
9199 vty_out(vty,
9200 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
9201 ORF_TYPE_PREFIX_OLD);
9202 bgp_show_peer_afi_orf_cap(
9203 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
9204 PEER_CAP_ORF_PREFIX_RM_ADV,
9205 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
9206 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
9207 }
9208
9209 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
9210 orf_pfx_count = prefix_bgp_show_prefix_list(
9211 NULL, afi, orf_pfx_name, use_json);
9212
9213 if (CHECK_FLAG(p->af_sflags[afi][safi],
9214 PEER_STATUS_ORF_PREFIX_SEND)
9215 || orf_pfx_count) {
9216 vty_out(vty, " Outbound Route Filter (ORF):");
9217 if (CHECK_FLAG(p->af_sflags[afi][safi],
9218 PEER_STATUS_ORF_PREFIX_SEND))
9219 vty_out(vty, " sent;");
9220 if (orf_pfx_count)
9221 vty_out(vty, " received (%d entries)",
9222 orf_pfx_count);
9223 vty_out(vty, "\n");
9224 }
9225 if (CHECK_FLAG(p->af_sflags[afi][safi],
9226 PEER_STATUS_ORF_WAIT_REFRESH))
9227 vty_out(vty,
9228 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
9229
9230 if (CHECK_FLAG(p->af_flags[afi][safi],
9231 PEER_FLAG_REFLECTOR_CLIENT))
9232 vty_out(vty, " Route-Reflector Client\n");
9233 if (CHECK_FLAG(p->af_flags[afi][safi],
9234 PEER_FLAG_RSERVER_CLIENT))
9235 vty_out(vty, " Route-Server Client\n");
9236 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9237 vty_out(vty,
9238 " Inbound soft reconfiguration allowed\n");
9239
9240 if (CHECK_FLAG(p->af_flags[afi][safi],
9241 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
9242 vty_out(vty,
9243 " Private AS numbers (all) replaced in updates to this neighbor\n");
9244 else if (CHECK_FLAG(p->af_flags[afi][safi],
9245 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
9246 vty_out(vty,
9247 " Private AS numbers replaced in updates to this neighbor\n");
9248 else if (CHECK_FLAG(p->af_flags[afi][safi],
9249 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
9250 vty_out(vty,
9251 " Private AS numbers (all) removed in updates to this neighbor\n");
9252 else if (CHECK_FLAG(p->af_flags[afi][safi],
9253 PEER_FLAG_REMOVE_PRIVATE_AS))
9254 vty_out(vty,
9255 " Private AS numbers removed in updates to this neighbor\n");
9256
9257 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
9258 vty_out(vty, " %s\n",
9259 bgp_addpath_names(p->addpath_type[afi][safi])
9260 ->human_description);
9261
9262 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
9263 vty_out(vty,
9264 " Override ASNs in outbound updates if aspath equals remote-as\n");
9265
9266 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
9267 || CHECK_FLAG(p->af_flags[afi][safi],
9268 PEER_FLAG_FORCE_NEXTHOP_SELF))
9269 vty_out(vty, " NEXT_HOP is always this router\n");
9270 if (CHECK_FLAG(p->af_flags[afi][safi],
9271 PEER_FLAG_AS_PATH_UNCHANGED))
9272 vty_out(vty,
9273 " AS_PATH is propagated unchanged to this neighbor\n");
9274 if (CHECK_FLAG(p->af_flags[afi][safi],
9275 PEER_FLAG_NEXTHOP_UNCHANGED))
9276 vty_out(vty,
9277 " NEXT_HOP is propagated unchanged to this neighbor\n");
9278 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
9279 vty_out(vty,
9280 " MED is propagated unchanged to this neighbor\n");
9281 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
9282 || CHECK_FLAG(p->af_flags[afi][safi],
9283 PEER_FLAG_SEND_EXT_COMMUNITY)
9284 || CHECK_FLAG(p->af_flags[afi][safi],
9285 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
9286 vty_out(vty,
9287 " Community attribute sent to this neighbor");
9288 if (CHECK_FLAG(p->af_flags[afi][safi],
9289 PEER_FLAG_SEND_COMMUNITY)
9290 && CHECK_FLAG(p->af_flags[afi][safi],
9291 PEER_FLAG_SEND_EXT_COMMUNITY)
9292 && CHECK_FLAG(p->af_flags[afi][safi],
9293 PEER_FLAG_SEND_LARGE_COMMUNITY))
9294 vty_out(vty, "(all)\n");
9295 else if (CHECK_FLAG(p->af_flags[afi][safi],
9296 PEER_FLAG_SEND_LARGE_COMMUNITY))
9297 vty_out(vty, "(large)\n");
9298 else if (CHECK_FLAG(p->af_flags[afi][safi],
9299 PEER_FLAG_SEND_EXT_COMMUNITY))
9300 vty_out(vty, "(extended)\n");
9301 else
9302 vty_out(vty, "(standard)\n");
9303 }
9304 if (CHECK_FLAG(p->af_flags[afi][safi],
9305 PEER_FLAG_DEFAULT_ORIGINATE)) {
9306 vty_out(vty, " Default information originate,");
9307
9308 if (p->default_rmap[afi][safi].name)
9309 vty_out(vty, " default route-map %s%s,",
9310 p->default_rmap[afi][safi].map ? "*"
9311 : "",
9312 p->default_rmap[afi][safi].name);
9313 if (paf && PAF_SUBGRP(paf)
9314 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
9315 SUBGRP_STATUS_DEFAULT_ORIGINATE))
9316 vty_out(vty, " default sent\n");
9317 else
9318 vty_out(vty, " default not sent\n");
9319 }
9320
9321 /* advertise-vni-all */
9322 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
9323 if (is_evpn_enabled())
9324 vty_out(vty, " advertise-all-vni\n");
9325 }
9326
9327 if (filter->plist[FILTER_IN].name
9328 || filter->dlist[FILTER_IN].name
9329 || filter->aslist[FILTER_IN].name
9330 || filter->map[RMAP_IN].name)
9331 vty_out(vty, " Inbound path policy configured\n");
9332 if (filter->plist[FILTER_OUT].name
9333 || filter->dlist[FILTER_OUT].name
9334 || filter->aslist[FILTER_OUT].name
9335 || filter->map[RMAP_OUT].name || filter->usmap.name)
9336 vty_out(vty, " Outbound path policy configured\n");
9337
9338 /* prefix-list */
9339 if (filter->plist[FILTER_IN].name)
9340 vty_out(vty,
9341 " Incoming update prefix filter list is %s%s\n",
9342 filter->plist[FILTER_IN].plist ? "*" : "",
9343 filter->plist[FILTER_IN].name);
9344 if (filter->plist[FILTER_OUT].name)
9345 vty_out(vty,
9346 " Outgoing update prefix filter list is %s%s\n",
9347 filter->plist[FILTER_OUT].plist ? "*" : "",
9348 filter->plist[FILTER_OUT].name);
9349
9350 /* distribute-list */
9351 if (filter->dlist[FILTER_IN].name)
9352 vty_out(vty,
9353 " Incoming update network filter list is %s%s\n",
9354 filter->dlist[FILTER_IN].alist ? "*" : "",
9355 filter->dlist[FILTER_IN].name);
9356 if (filter->dlist[FILTER_OUT].name)
9357 vty_out(vty,
9358 " Outgoing update network filter list is %s%s\n",
9359 filter->dlist[FILTER_OUT].alist ? "*" : "",
9360 filter->dlist[FILTER_OUT].name);
9361
9362 /* filter-list. */
9363 if (filter->aslist[FILTER_IN].name)
9364 vty_out(vty,
9365 " Incoming update AS path filter list is %s%s\n",
9366 filter->aslist[FILTER_IN].aslist ? "*" : "",
9367 filter->aslist[FILTER_IN].name);
9368 if (filter->aslist[FILTER_OUT].name)
9369 vty_out(vty,
9370 " Outgoing update AS path filter list is %s%s\n",
9371 filter->aslist[FILTER_OUT].aslist ? "*" : "",
9372 filter->aslist[FILTER_OUT].name);
9373
9374 /* route-map. */
9375 if (filter->map[RMAP_IN].name)
9376 vty_out(vty,
9377 " Route map for incoming advertisements is %s%s\n",
9378 filter->map[RMAP_IN].map ? "*" : "",
9379 filter->map[RMAP_IN].name);
9380 if (filter->map[RMAP_OUT].name)
9381 vty_out(vty,
9382 " Route map for outgoing advertisements is %s%s\n",
9383 filter->map[RMAP_OUT].map ? "*" : "",
9384 filter->map[RMAP_OUT].name);
9385
9386 /* ebgp-requires-policy (inbound) */
9387 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
9388 && !bgp_inbound_policy_exists(p, filter))
9389 vty_out(vty,
9390 " Inbound updates discarded due to missing policy\n");
9391
9392 /* ebgp-requires-policy (outbound) */
9393 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
9394 && !bgp_outbound_policy_exists(p, filter))
9395 vty_out(vty,
9396 " Outbound updates discarded due to missing policy\n");
9397
9398 /* unsuppress-map */
9399 if (filter->usmap.name)
9400 vty_out(vty,
9401 " Route map for selective unsuppress is %s%s\n",
9402 filter->usmap.map ? "*" : "",
9403 filter->usmap.name);
9404
9405 /* Receive prefix count */
9406 vty_out(vty, " %" PRIu32 " accepted prefixes\n",
9407 p->pcount[afi][safi]);
9408
9409 /* Maximum prefix */
9410 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
9411 vty_out(vty,
9412 " Maximum prefixes allowed %" PRIu32 "%s\n",
9413 p->pmax[afi][safi],
9414 CHECK_FLAG(p->af_flags[afi][safi],
9415 PEER_FLAG_MAX_PREFIX_WARNING)
9416 ? " (warning-only)"
9417 : "");
9418 vty_out(vty, " Threshold for warning message %d%%",
9419 p->pmax_threshold[afi][safi]);
9420 if (p->pmax_restart[afi][safi])
9421 vty_out(vty, ", restart interval %d min",
9422 p->pmax_restart[afi][safi]);
9423 vty_out(vty, "\n");
9424 }
9425
9426 vty_out(vty, "\n");
9427 }
9428 }
9429
9430 static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
9431 json_object *json)
9432 {
9433 struct bgp *bgp;
9434 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
9435 char timebuf[BGP_UPTIME_LEN];
9436 char dn_flag[2];
9437 afi_t afi;
9438 safi_t safi;
9439 uint16_t i;
9440 uint8_t *msg;
9441 json_object *json_neigh = NULL;
9442 time_t epoch_tbuf;
9443
9444 bgp = p->bgp;
9445
9446 if (use_json)
9447 json_neigh = json_object_new_object();
9448
9449 memset(dn_flag, '\0', sizeof(dn_flag));
9450 if (!p->conf_if && peer_dynamic_neighbor(p))
9451 dn_flag[0] = '*';
9452
9453 if (!use_json) {
9454 if (p->conf_if) /* Configured interface name. */
9455 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
9456 BGP_PEER_SU_UNSPEC(p)
9457 ? "None"
9458 : sockunion2str(&p->su, buf,
9459 SU_ADDRSTRLEN));
9460 else /* Configured IP address. */
9461 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
9462 p->host);
9463 }
9464
9465 if (use_json) {
9466 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
9467 json_object_string_add(json_neigh, "bgpNeighborAddr",
9468 "none");
9469 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
9470 json_object_string_add(
9471 json_neigh, "bgpNeighborAddr",
9472 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
9473
9474 json_object_int_add(json_neigh, "remoteAs", p->as);
9475
9476 if (p->change_local_as)
9477 json_object_int_add(json_neigh, "localAs",
9478 p->change_local_as);
9479 else
9480 json_object_int_add(json_neigh, "localAs", p->local_as);
9481
9482 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
9483 json_object_boolean_true_add(json_neigh,
9484 "localAsNoPrepend");
9485
9486 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
9487 json_object_boolean_true_add(json_neigh,
9488 "localAsReplaceAs");
9489 } else {
9490 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
9491 || (p->as_type == AS_INTERNAL))
9492 vty_out(vty, "remote AS %u, ", p->as);
9493 else
9494 vty_out(vty, "remote AS Unspecified, ");
9495 vty_out(vty, "local AS %u%s%s, ",
9496 p->change_local_as ? p->change_local_as : p->local_as,
9497 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
9498 ? " no-prepend"
9499 : "",
9500 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
9501 ? " replace-as"
9502 : "");
9503 }
9504 /* peer type internal or confed-internal */
9505 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
9506 if (use_json) {
9507 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9508 json_object_boolean_true_add(
9509 json_neigh, "nbrConfedInternalLink");
9510 else
9511 json_object_boolean_true_add(json_neigh,
9512 "nbrInternalLink");
9513 } else {
9514 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9515 vty_out(vty, "confed-internal link\n");
9516 else
9517 vty_out(vty, "internal link\n");
9518 }
9519 /* peer type external or confed-external */
9520 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
9521 if (use_json) {
9522 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9523 json_object_boolean_true_add(
9524 json_neigh, "nbrConfedExternalLink");
9525 else
9526 json_object_boolean_true_add(json_neigh,
9527 "nbrExternalLink");
9528 } else {
9529 if (bgp_confederation_peers_check(bgp, p->as))
9530 vty_out(vty, "confed-external link\n");
9531 else
9532 vty_out(vty, "external link\n");
9533 }
9534 } else {
9535 if (use_json)
9536 json_object_boolean_true_add(json_neigh,
9537 "nbrUnspecifiedLink");
9538 else
9539 vty_out(vty, "unspecified link\n");
9540 }
9541
9542 /* Description. */
9543 if (p->desc) {
9544 if (use_json)
9545 json_object_string_add(json_neigh, "nbrDesc", p->desc);
9546 else
9547 vty_out(vty, " Description: %s\n", p->desc);
9548 }
9549
9550 if (p->hostname) {
9551 if (use_json) {
9552 if (p->hostname)
9553 json_object_string_add(json_neigh, "hostname",
9554 p->hostname);
9555
9556 if (p->domainname)
9557 json_object_string_add(json_neigh, "domainname",
9558 p->domainname);
9559 } else {
9560 if (p->domainname && (p->domainname[0] != '\0'))
9561 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
9562 p->domainname);
9563 else
9564 vty_out(vty, "Hostname: %s\n", p->hostname);
9565 }
9566 }
9567
9568 /* Peer-group */
9569 if (p->group) {
9570 if (use_json) {
9571 json_object_string_add(json_neigh, "peerGroup",
9572 p->group->name);
9573
9574 if (dn_flag[0]) {
9575 struct prefix prefix, *range = NULL;
9576
9577 sockunion2hostprefix(&(p->su), &prefix);
9578 range = peer_group_lookup_dynamic_neighbor_range(
9579 p->group, &prefix);
9580
9581 if (range) {
9582 prefix2str(range, buf1, sizeof(buf1));
9583 json_object_string_add(
9584 json_neigh,
9585 "peerSubnetRangeGroup", buf1);
9586 }
9587 }
9588 } else {
9589 vty_out(vty,
9590 " Member of peer-group %s for session parameters\n",
9591 p->group->name);
9592
9593 if (dn_flag[0]) {
9594 struct prefix prefix, *range = NULL;
9595
9596 sockunion2hostprefix(&(p->su), &prefix);
9597 range = peer_group_lookup_dynamic_neighbor_range(
9598 p->group, &prefix);
9599
9600 if (range) {
9601 prefix2str(range, buf1, sizeof(buf1));
9602 vty_out(vty,
9603 " Belongs to the subnet range group: %s\n",
9604 buf1);
9605 }
9606 }
9607 }
9608 }
9609
9610 if (use_json) {
9611 /* Administrative shutdown. */
9612 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9613 json_object_boolean_true_add(json_neigh,
9614 "adminShutDown");
9615
9616 /* BGP Version. */
9617 json_object_int_add(json_neigh, "bgpVersion", 4);
9618 json_object_string_add(
9619 json_neigh, "remoteRouterId",
9620 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9621 json_object_string_add(
9622 json_neigh, "localRouterId",
9623 inet_ntop(AF_INET, &bgp->router_id, buf1,
9624 sizeof(buf1)));
9625
9626 /* Confederation */
9627 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9628 && bgp_confederation_peers_check(bgp, p->as))
9629 json_object_boolean_true_add(json_neigh,
9630 "nbrCommonAdmin");
9631
9632 /* Status. */
9633 json_object_string_add(
9634 json_neigh, "bgpState",
9635 lookup_msg(bgp_status_msg, p->status, NULL));
9636
9637 if (p->status == Established) {
9638 time_t uptime;
9639
9640 uptime = bgp_clock();
9641 uptime -= p->uptime;
9642 epoch_tbuf = time(NULL) - uptime;
9643
9644 #if CONFDATE > 20200101
9645 CPP_NOTICE(
9646 "bgpTimerUp should be deprecated and can be removed now");
9647 #endif
9648 /*
9649 * bgpTimerUp was miliseconds that was accurate
9650 * up to 1 day, then the value returned
9651 * became garbage. So in order to provide
9652 * some level of backwards compatability,
9653 * we still provde the data, but now
9654 * we are returning the correct value
9655 * and also adding a new bgpTimerUpMsec
9656 * which will allow us to deprecate
9657 * this eventually
9658 */
9659 json_object_int_add(json_neigh, "bgpTimerUp",
9660 uptime * 1000);
9661 json_object_int_add(json_neigh, "bgpTimerUpMsec",
9662 uptime * 1000);
9663 json_object_string_add(json_neigh, "bgpTimerUpString",
9664 peer_uptime(p->uptime, timebuf,
9665 BGP_UPTIME_LEN, 0,
9666 NULL));
9667 json_object_int_add(json_neigh,
9668 "bgpTimerUpEstablishedEpoch",
9669 epoch_tbuf);
9670 }
9671
9672 else if (p->status == Active) {
9673 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9674 json_object_string_add(json_neigh, "bgpStateIs",
9675 "passive");
9676 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9677 json_object_string_add(json_neigh, "bgpStateIs",
9678 "passiveNSF");
9679 }
9680
9681 /* read timer */
9682 time_t uptime;
9683 struct tm *tm;
9684
9685 uptime = bgp_clock();
9686 uptime -= p->readtime;
9687 tm = gmtime(&uptime);
9688 json_object_int_add(json_neigh, "bgpTimerLastRead",
9689 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9690 + (tm->tm_hour * 3600000));
9691
9692 uptime = bgp_clock();
9693 uptime -= p->last_write;
9694 tm = gmtime(&uptime);
9695 json_object_int_add(json_neigh, "bgpTimerLastWrite",
9696 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9697 + (tm->tm_hour * 3600000));
9698
9699 uptime = bgp_clock();
9700 uptime -= p->update_time;
9701 tm = gmtime(&uptime);
9702 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
9703 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9704 + (tm->tm_hour * 3600000));
9705
9706 /* Configured timer values. */
9707 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
9708 p->v_holdtime * 1000);
9709 json_object_int_add(json_neigh,
9710 "bgpTimerKeepAliveIntervalMsecs",
9711 p->v_keepalive * 1000);
9712 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
9713 json_object_int_add(json_neigh,
9714 "bgpTimerConfiguredHoldTimeMsecs",
9715 p->holdtime * 1000);
9716 json_object_int_add(
9717 json_neigh,
9718 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9719 p->keepalive * 1000);
9720 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
9721 || (bgp->default_keepalive
9722 != BGP_DEFAULT_KEEPALIVE)) {
9723 json_object_int_add(json_neigh,
9724 "bgpTimerConfiguredHoldTimeMsecs",
9725 bgp->default_holdtime);
9726 json_object_int_add(
9727 json_neigh,
9728 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9729 bgp->default_keepalive);
9730 }
9731 } else {
9732 /* Administrative shutdown. */
9733 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9734 vty_out(vty, " Administratively shut down\n");
9735
9736 /* BGP Version. */
9737 vty_out(vty, " BGP version 4");
9738 vty_out(vty, ", remote router ID %s",
9739 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9740 vty_out(vty, ", local router ID %s\n",
9741 inet_ntop(AF_INET, &bgp->router_id, buf1,
9742 sizeof(buf1)));
9743
9744 /* Confederation */
9745 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9746 && bgp_confederation_peers_check(bgp, p->as))
9747 vty_out(vty,
9748 " Neighbor under common administration\n");
9749
9750 /* Status. */
9751 vty_out(vty, " BGP state = %s",
9752 lookup_msg(bgp_status_msg, p->status, NULL));
9753
9754 if (p->status == Established)
9755 vty_out(vty, ", up for %8s",
9756 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
9757 0, NULL));
9758
9759 else if (p->status == Active) {
9760 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9761 vty_out(vty, " (passive)");
9762 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9763 vty_out(vty, " (NSF passive)");
9764 }
9765 vty_out(vty, "\n");
9766
9767 /* read timer */
9768 vty_out(vty, " Last read %s",
9769 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
9770 NULL));
9771 vty_out(vty, ", Last write %s\n",
9772 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
9773 NULL));
9774
9775 /* Configured timer values. */
9776 vty_out(vty,
9777 " Hold time is %d, keepalive interval is %d seconds\n",
9778 p->v_holdtime, p->v_keepalive);
9779 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
9780 vty_out(vty, " Configured hold time is %d",
9781 p->holdtime);
9782 vty_out(vty, ", keepalive interval is %d seconds\n",
9783 p->keepalive);
9784 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
9785 || (bgp->default_keepalive
9786 != BGP_DEFAULT_KEEPALIVE)) {
9787 vty_out(vty, " Configured hold time is %d",
9788 bgp->default_holdtime);
9789 vty_out(vty, ", keepalive interval is %d seconds\n",
9790 bgp->default_keepalive);
9791 }
9792 }
9793 /* Capability. */
9794 if (p->status == Established) {
9795 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
9796 || p->afc_recv[AFI_IP][SAFI_UNICAST]
9797 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
9798 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
9799 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
9800 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
9801 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
9802 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
9803 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
9804 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
9805 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
9806 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
9807 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
9808 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
9809 || p->afc_adv[AFI_IP][SAFI_ENCAP]
9810 || p->afc_recv[AFI_IP][SAFI_ENCAP]
9811 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
9812 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
9813 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
9814 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
9815 if (use_json) {
9816 json_object *json_cap = NULL;
9817
9818 json_cap = json_object_new_object();
9819
9820 /* AS4 */
9821 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9822 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9823 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
9824 && CHECK_FLAG(p->cap,
9825 PEER_CAP_AS4_RCV))
9826 json_object_string_add(
9827 json_cap, "4byteAs",
9828 "advertisedAndReceived");
9829 else if (CHECK_FLAG(p->cap,
9830 PEER_CAP_AS4_ADV))
9831 json_object_string_add(
9832 json_cap, "4byteAs",
9833 "advertised");
9834 else if (CHECK_FLAG(p->cap,
9835 PEER_CAP_AS4_RCV))
9836 json_object_string_add(
9837 json_cap, "4byteAs",
9838 "received");
9839 }
9840
9841 /* AddPath */
9842 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9843 || CHECK_FLAG(p->cap,
9844 PEER_CAP_ADDPATH_ADV)) {
9845 json_object *json_add = NULL;
9846 const char *print_store;
9847
9848 json_add = json_object_new_object();
9849
9850 FOREACH_AFI_SAFI (afi, safi) {
9851 json_object *json_sub = NULL;
9852 json_sub =
9853 json_object_new_object();
9854 print_store = get_afi_safi_str(
9855 afi, safi, true);
9856
9857 if (CHECK_FLAG(
9858 p->af_cap[afi]
9859 [safi],
9860 PEER_CAP_ADDPATH_AF_TX_ADV)
9861 || CHECK_FLAG(
9862 p->af_cap[afi]
9863 [safi],
9864 PEER_CAP_ADDPATH_AF_TX_RCV)) {
9865 if (CHECK_FLAG(
9866 p->af_cap
9867 [afi]
9868 [safi],
9869 PEER_CAP_ADDPATH_AF_TX_ADV)
9870 && CHECK_FLAG(
9871 p->af_cap
9872 [afi]
9873 [safi],
9874 PEER_CAP_ADDPATH_AF_TX_RCV))
9875 json_object_boolean_true_add(
9876 json_sub,
9877 "txAdvertisedAndReceived");
9878 else if (
9879 CHECK_FLAG(
9880 p->af_cap
9881 [afi]
9882 [safi],
9883 PEER_CAP_ADDPATH_AF_TX_ADV))
9884 json_object_boolean_true_add(
9885 json_sub,
9886 "txAdvertised");
9887 else if (
9888 CHECK_FLAG(
9889 p->af_cap
9890 [afi]
9891 [safi],
9892 PEER_CAP_ADDPATH_AF_TX_RCV))
9893 json_object_boolean_true_add(
9894 json_sub,
9895 "txReceived");
9896 }
9897
9898 if (CHECK_FLAG(
9899 p->af_cap[afi]
9900 [safi],
9901 PEER_CAP_ADDPATH_AF_RX_ADV)
9902 || CHECK_FLAG(
9903 p->af_cap[afi]
9904 [safi],
9905 PEER_CAP_ADDPATH_AF_RX_RCV)) {
9906 if (CHECK_FLAG(
9907 p->af_cap
9908 [afi]
9909 [safi],
9910 PEER_CAP_ADDPATH_AF_RX_ADV)
9911 && CHECK_FLAG(
9912 p->af_cap
9913 [afi]
9914 [safi],
9915 PEER_CAP_ADDPATH_AF_RX_RCV))
9916 json_object_boolean_true_add(
9917 json_sub,
9918 "rxAdvertisedAndReceived");
9919 else if (
9920 CHECK_FLAG(
9921 p->af_cap
9922 [afi]
9923 [safi],
9924 PEER_CAP_ADDPATH_AF_RX_ADV))
9925 json_object_boolean_true_add(
9926 json_sub,
9927 "rxAdvertised");
9928 else if (
9929 CHECK_FLAG(
9930 p->af_cap
9931 [afi]
9932 [safi],
9933 PEER_CAP_ADDPATH_AF_RX_RCV))
9934 json_object_boolean_true_add(
9935 json_sub,
9936 "rxReceived");
9937 }
9938
9939 if (CHECK_FLAG(
9940 p->af_cap[afi]
9941 [safi],
9942 PEER_CAP_ADDPATH_AF_TX_ADV)
9943 || CHECK_FLAG(
9944 p->af_cap[afi]
9945 [safi],
9946 PEER_CAP_ADDPATH_AF_TX_RCV)
9947 || CHECK_FLAG(
9948 p->af_cap[afi]
9949 [safi],
9950 PEER_CAP_ADDPATH_AF_RX_ADV)
9951 || CHECK_FLAG(
9952 p->af_cap[afi]
9953 [safi],
9954 PEER_CAP_ADDPATH_AF_RX_RCV))
9955 json_object_object_add(
9956 json_add,
9957 print_store,
9958 json_sub);
9959 else
9960 json_object_free(
9961 json_sub);
9962 }
9963
9964 json_object_object_add(
9965 json_cap, "addPath", json_add);
9966 }
9967
9968 /* Dynamic */
9969 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9970 || CHECK_FLAG(p->cap,
9971 PEER_CAP_DYNAMIC_ADV)) {
9972 if (CHECK_FLAG(p->cap,
9973 PEER_CAP_DYNAMIC_ADV)
9974 && CHECK_FLAG(p->cap,
9975 PEER_CAP_DYNAMIC_RCV))
9976 json_object_string_add(
9977 json_cap, "dynamic",
9978 "advertisedAndReceived");
9979 else if (CHECK_FLAG(
9980 p->cap,
9981 PEER_CAP_DYNAMIC_ADV))
9982 json_object_string_add(
9983 json_cap, "dynamic",
9984 "advertised");
9985 else if (CHECK_FLAG(
9986 p->cap,
9987 PEER_CAP_DYNAMIC_RCV))
9988 json_object_string_add(
9989 json_cap, "dynamic",
9990 "received");
9991 }
9992
9993 /* Extended nexthop */
9994 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9995 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9996 json_object *json_nxt = NULL;
9997 const char *print_store;
9998
9999
10000 if (CHECK_FLAG(p->cap,
10001 PEER_CAP_ENHE_ADV)
10002 && CHECK_FLAG(p->cap,
10003 PEER_CAP_ENHE_RCV))
10004 json_object_string_add(
10005 json_cap,
10006 "extendedNexthop",
10007 "advertisedAndReceived");
10008 else if (CHECK_FLAG(p->cap,
10009 PEER_CAP_ENHE_ADV))
10010 json_object_string_add(
10011 json_cap,
10012 "extendedNexthop",
10013 "advertised");
10014 else if (CHECK_FLAG(p->cap,
10015 PEER_CAP_ENHE_RCV))
10016 json_object_string_add(
10017 json_cap,
10018 "extendedNexthop",
10019 "received");
10020
10021 if (CHECK_FLAG(p->cap,
10022 PEER_CAP_ENHE_RCV)) {
10023 json_nxt =
10024 json_object_new_object();
10025
10026 for (safi = SAFI_UNICAST;
10027 safi < SAFI_MAX; safi++) {
10028 if (CHECK_FLAG(
10029 p->af_cap
10030 [AFI_IP]
10031 [safi],
10032 PEER_CAP_ENHE_AF_RCV)) {
10033 print_store = get_afi_safi_str(
10034 AFI_IP,
10035 safi, true);
10036 json_object_string_add(
10037 json_nxt,
10038 print_store,
10039 "recieved"); /* misspelled for compatibility */
10040 }
10041 }
10042 json_object_object_add(
10043 json_cap,
10044 "extendedNexthopFamililesByPeer",
10045 json_nxt);
10046 }
10047 }
10048
10049 /* Route Refresh */
10050 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
10051 || CHECK_FLAG(p->cap,
10052 PEER_CAP_REFRESH_NEW_RCV)
10053 || CHECK_FLAG(p->cap,
10054 PEER_CAP_REFRESH_OLD_RCV)) {
10055 if (CHECK_FLAG(p->cap,
10056 PEER_CAP_REFRESH_ADV)
10057 && (CHECK_FLAG(
10058 p->cap,
10059 PEER_CAP_REFRESH_NEW_RCV)
10060 || CHECK_FLAG(
10061 p->cap,
10062 PEER_CAP_REFRESH_OLD_RCV))) {
10063 if (CHECK_FLAG(
10064 p->cap,
10065 PEER_CAP_REFRESH_OLD_RCV)
10066 && CHECK_FLAG(
10067 p->cap,
10068 PEER_CAP_REFRESH_NEW_RCV))
10069 json_object_string_add(
10070 json_cap,
10071 "routeRefresh",
10072 "advertisedAndReceivedOldNew");
10073 else {
10074 if (CHECK_FLAG(
10075 p->cap,
10076 PEER_CAP_REFRESH_OLD_RCV))
10077 json_object_string_add(
10078 json_cap,
10079 "routeRefresh",
10080 "advertisedAndReceivedOld");
10081 else
10082 json_object_string_add(
10083 json_cap,
10084 "routeRefresh",
10085 "advertisedAndReceivedNew");
10086 }
10087 } else if (
10088 CHECK_FLAG(
10089 p->cap,
10090 PEER_CAP_REFRESH_ADV))
10091 json_object_string_add(
10092 json_cap,
10093 "routeRefresh",
10094 "advertised");
10095 else if (
10096 CHECK_FLAG(
10097 p->cap,
10098 PEER_CAP_REFRESH_NEW_RCV)
10099 || CHECK_FLAG(
10100 p->cap,
10101 PEER_CAP_REFRESH_OLD_RCV))
10102 json_object_string_add(
10103 json_cap,
10104 "routeRefresh",
10105 "received");
10106 }
10107
10108 /* Multiprotocol Extensions */
10109 json_object *json_multi = NULL;
10110 json_multi = json_object_new_object();
10111
10112 FOREACH_AFI_SAFI (afi, safi) {
10113 if (p->afc_adv[afi][safi]
10114 || p->afc_recv[afi][safi]) {
10115 json_object *json_exten = NULL;
10116 json_exten =
10117 json_object_new_object();
10118
10119 if (p->afc_adv[afi][safi]
10120 && p->afc_recv[afi][safi])
10121 json_object_boolean_true_add(
10122 json_exten,
10123 "advertisedAndReceived");
10124 else if (p->afc_adv[afi][safi])
10125 json_object_boolean_true_add(
10126 json_exten,
10127 "advertised");
10128 else if (p->afc_recv[afi][safi])
10129 json_object_boolean_true_add(
10130 json_exten,
10131 "received");
10132
10133 json_object_object_add(
10134 json_multi,
10135 get_afi_safi_str(afi,
10136 safi,
10137 true),
10138 json_exten);
10139 }
10140 }
10141 json_object_object_add(
10142 json_cap, "multiprotocolExtensions",
10143 json_multi);
10144
10145 /* Hostname capabilities */
10146 json_object *json_hname = NULL;
10147
10148 json_hname = json_object_new_object();
10149
10150 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
10151 json_object_string_add(
10152 json_hname, "advHostName",
10153 bgp->peer_self->hostname
10154 ? bgp->peer_self
10155 ->hostname
10156 : "n/a");
10157 json_object_string_add(
10158 json_hname, "advDomainName",
10159 bgp->peer_self->domainname
10160 ? bgp->peer_self
10161 ->domainname
10162 : "n/a");
10163 }
10164
10165
10166 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
10167 json_object_string_add(
10168 json_hname, "rcvHostName",
10169 p->hostname ? p->hostname
10170 : "n/a");
10171 json_object_string_add(
10172 json_hname, "rcvDomainName",
10173 p->domainname ? p->domainname
10174 : "n/a");
10175 }
10176
10177 json_object_object_add(json_cap, "hostName",
10178 json_hname);
10179
10180 /* Gracefull Restart */
10181 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
10182 || CHECK_FLAG(p->cap,
10183 PEER_CAP_RESTART_ADV)) {
10184 if (CHECK_FLAG(p->cap,
10185 PEER_CAP_RESTART_ADV)
10186 && CHECK_FLAG(p->cap,
10187 PEER_CAP_RESTART_RCV))
10188 json_object_string_add(
10189 json_cap,
10190 "gracefulRestart",
10191 "advertisedAndReceived");
10192 else if (CHECK_FLAG(
10193 p->cap,
10194 PEER_CAP_RESTART_ADV))
10195 json_object_string_add(
10196 json_cap,
10197 "gracefulRestartCapability",
10198 "advertised");
10199 else if (CHECK_FLAG(
10200 p->cap,
10201 PEER_CAP_RESTART_RCV))
10202 json_object_string_add(
10203 json_cap,
10204 "gracefulRestartCapability",
10205 "received");
10206
10207 if (CHECK_FLAG(p->cap,
10208 PEER_CAP_RESTART_RCV)) {
10209 int restart_af_count = 0;
10210 json_object *json_restart =
10211 NULL;
10212 json_restart =
10213 json_object_new_object();
10214
10215 json_object_int_add(
10216 json_cap,
10217 "gracefulRestartRemoteTimerMsecs",
10218 p->v_gr_restart * 1000);
10219
10220 FOREACH_AFI_SAFI (afi, safi) {
10221 if (CHECK_FLAG(
10222 p->af_cap
10223 [afi]
10224 [safi],
10225 PEER_CAP_RESTART_AF_RCV)) {
10226 json_object *
10227 json_sub =
10228 NULL;
10229 json_sub =
10230 json_object_new_object();
10231
10232 if (CHECK_FLAG(
10233 p->af_cap
10234 [afi]
10235 [safi],
10236 PEER_CAP_RESTART_AF_PRESERVE_RCV))
10237 json_object_boolean_true_add(
10238 json_sub,
10239 "preserved");
10240 restart_af_count++;
10241 json_object_object_add(
10242 json_restart,
10243 get_afi_safi_str(
10244 afi,
10245 safi,
10246 true),
10247 json_sub);
10248 }
10249 }
10250 if (!restart_af_count) {
10251 json_object_string_add(
10252 json_cap,
10253 "addressFamiliesByPeer",
10254 "none");
10255 json_object_free(
10256 json_restart);
10257 } else
10258 json_object_object_add(
10259 json_cap,
10260 "addressFamiliesByPeer",
10261 json_restart);
10262 }
10263 }
10264 json_object_object_add(json_neigh,
10265 "neighborCapabilities",
10266 json_cap);
10267 } else {
10268 vty_out(vty, " Neighbor capabilities:\n");
10269
10270 /* AS4 */
10271 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
10272 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
10273 vty_out(vty, " 4 Byte AS:");
10274 if (CHECK_FLAG(p->cap,
10275 PEER_CAP_AS4_ADV))
10276 vty_out(vty, " advertised");
10277 if (CHECK_FLAG(p->cap,
10278 PEER_CAP_AS4_RCV))
10279 vty_out(vty, " %sreceived",
10280 CHECK_FLAG(
10281 p->cap,
10282 PEER_CAP_AS4_ADV)
10283 ? "and "
10284 : "");
10285 vty_out(vty, "\n");
10286 }
10287
10288 /* AddPath */
10289 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
10290 || CHECK_FLAG(p->cap,
10291 PEER_CAP_ADDPATH_ADV)) {
10292 vty_out(vty, " AddPath:\n");
10293
10294 FOREACH_AFI_SAFI (afi, safi) {
10295 if (CHECK_FLAG(
10296 p->af_cap[afi]
10297 [safi],
10298 PEER_CAP_ADDPATH_AF_TX_ADV)
10299 || CHECK_FLAG(
10300 p->af_cap[afi]
10301 [safi],
10302 PEER_CAP_ADDPATH_AF_TX_RCV)) {
10303 vty_out(vty,
10304 " %s: TX ",
10305 get_afi_safi_str(
10306 afi,
10307 safi,
10308 false));
10309
10310 if (CHECK_FLAG(
10311 p->af_cap
10312 [afi]
10313 [safi],
10314 PEER_CAP_ADDPATH_AF_TX_ADV))
10315 vty_out(vty,
10316 "advertised %s",
10317 get_afi_safi_str(
10318 afi,
10319 safi,
10320 false));
10321
10322 if (CHECK_FLAG(
10323 p->af_cap
10324 [afi]
10325 [safi],
10326 PEER_CAP_ADDPATH_AF_TX_RCV))
10327 vty_out(vty,
10328 "%sreceived",
10329 CHECK_FLAG(
10330 p->af_cap
10331 [afi]
10332 [safi],
10333 PEER_CAP_ADDPATH_AF_TX_ADV)
10334 ? " and "
10335 : "");
10336
10337 vty_out(vty, "\n");
10338 }
10339
10340 if (CHECK_FLAG(
10341 p->af_cap[afi]
10342 [safi],
10343 PEER_CAP_ADDPATH_AF_RX_ADV)
10344 || CHECK_FLAG(
10345 p->af_cap[afi]
10346 [safi],
10347 PEER_CAP_ADDPATH_AF_RX_RCV)) {
10348 vty_out(vty,
10349 " %s: RX ",
10350 get_afi_safi_str(
10351 afi,
10352 safi,
10353 false));
10354
10355 if (CHECK_FLAG(
10356 p->af_cap
10357 [afi]
10358 [safi],
10359 PEER_CAP_ADDPATH_AF_RX_ADV))
10360 vty_out(vty,
10361 "advertised %s",
10362 get_afi_safi_str(
10363 afi,
10364 safi,
10365 false));
10366
10367 if (CHECK_FLAG(
10368 p->af_cap
10369 [afi]
10370 [safi],
10371 PEER_CAP_ADDPATH_AF_RX_RCV))
10372 vty_out(vty,
10373 "%sreceived",
10374 CHECK_FLAG(
10375 p->af_cap
10376 [afi]
10377 [safi],
10378 PEER_CAP_ADDPATH_AF_RX_ADV)
10379 ? " and "
10380 : "");
10381
10382 vty_out(vty, "\n");
10383 }
10384 }
10385 }
10386
10387 /* Dynamic */
10388 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
10389 || CHECK_FLAG(p->cap,
10390 PEER_CAP_DYNAMIC_ADV)) {
10391 vty_out(vty, " Dynamic:");
10392 if (CHECK_FLAG(p->cap,
10393 PEER_CAP_DYNAMIC_ADV))
10394 vty_out(vty, " advertised");
10395 if (CHECK_FLAG(p->cap,
10396 PEER_CAP_DYNAMIC_RCV))
10397 vty_out(vty, " %sreceived",
10398 CHECK_FLAG(
10399 p->cap,
10400 PEER_CAP_DYNAMIC_ADV)
10401 ? "and "
10402 : "");
10403 vty_out(vty, "\n");
10404 }
10405
10406 /* Extended nexthop */
10407 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
10408 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
10409 vty_out(vty, " Extended nexthop:");
10410 if (CHECK_FLAG(p->cap,
10411 PEER_CAP_ENHE_ADV))
10412 vty_out(vty, " advertised");
10413 if (CHECK_FLAG(p->cap,
10414 PEER_CAP_ENHE_RCV))
10415 vty_out(vty, " %sreceived",
10416 CHECK_FLAG(
10417 p->cap,
10418 PEER_CAP_ENHE_ADV)
10419 ? "and "
10420 : "");
10421 vty_out(vty, "\n");
10422
10423 if (CHECK_FLAG(p->cap,
10424 PEER_CAP_ENHE_RCV)) {
10425 vty_out(vty,
10426 " Address families by peer:\n ");
10427 for (safi = SAFI_UNICAST;
10428 safi < SAFI_MAX; safi++)
10429 if (CHECK_FLAG(
10430 p->af_cap
10431 [AFI_IP]
10432 [safi],
10433 PEER_CAP_ENHE_AF_RCV))
10434 vty_out(vty,
10435 " %s\n",
10436 get_afi_safi_str(
10437 AFI_IP,
10438 safi,
10439 false));
10440 }
10441 }
10442
10443 /* Route Refresh */
10444 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
10445 || CHECK_FLAG(p->cap,
10446 PEER_CAP_REFRESH_NEW_RCV)
10447 || CHECK_FLAG(p->cap,
10448 PEER_CAP_REFRESH_OLD_RCV)) {
10449 vty_out(vty, " Route refresh:");
10450 if (CHECK_FLAG(p->cap,
10451 PEER_CAP_REFRESH_ADV))
10452 vty_out(vty, " advertised");
10453 if (CHECK_FLAG(p->cap,
10454 PEER_CAP_REFRESH_NEW_RCV)
10455 || CHECK_FLAG(
10456 p->cap,
10457 PEER_CAP_REFRESH_OLD_RCV))
10458 vty_out(vty, " %sreceived(%s)",
10459 CHECK_FLAG(
10460 p->cap,
10461 PEER_CAP_REFRESH_ADV)
10462 ? "and "
10463 : "",
10464 (CHECK_FLAG(
10465 p->cap,
10466 PEER_CAP_REFRESH_OLD_RCV)
10467 && CHECK_FLAG(
10468 p->cap,
10469 PEER_CAP_REFRESH_NEW_RCV))
10470 ? "old & new"
10471 : CHECK_FLAG(
10472 p->cap,
10473 PEER_CAP_REFRESH_OLD_RCV)
10474 ? "old"
10475 : "new");
10476
10477 vty_out(vty, "\n");
10478 }
10479
10480 /* Multiprotocol Extensions */
10481 FOREACH_AFI_SAFI (afi, safi)
10482 if (p->afc_adv[afi][safi]
10483 || p->afc_recv[afi][safi]) {
10484 vty_out(vty,
10485 " Address Family %s:",
10486 get_afi_safi_str(
10487 afi,
10488 safi,
10489 false));
10490 if (p->afc_adv[afi][safi])
10491 vty_out(vty,
10492 " advertised");
10493 if (p->afc_recv[afi][safi])
10494 vty_out(vty,
10495 " %sreceived",
10496 p->afc_adv[afi]
10497 [safi]
10498 ? "and "
10499 : "");
10500 vty_out(vty, "\n");
10501 }
10502
10503 /* Hostname capability */
10504 vty_out(vty, " Hostname Capability:");
10505
10506 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
10507 vty_out(vty,
10508 " advertised (name: %s,domain name: %s)",
10509 bgp->peer_self->hostname
10510 ? bgp->peer_self
10511 ->hostname
10512 : "n/a",
10513 bgp->peer_self->domainname
10514 ? bgp->peer_self
10515 ->domainname
10516 : "n/a");
10517 } else {
10518 vty_out(vty, " not advertised");
10519 }
10520
10521 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
10522 vty_out(vty,
10523 " received (name: %s,domain name: %s)",
10524 p->hostname ? p->hostname
10525 : "n/a",
10526 p->domainname ? p->domainname
10527 : "n/a");
10528 } else {
10529 vty_out(vty, " not received");
10530 }
10531
10532 vty_out(vty, "\n");
10533
10534 /* Gracefull Restart */
10535 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
10536 || CHECK_FLAG(p->cap,
10537 PEER_CAP_RESTART_ADV)) {
10538 vty_out(vty,
10539 " Graceful Restart Capabilty:");
10540 if (CHECK_FLAG(p->cap,
10541 PEER_CAP_RESTART_ADV))
10542 vty_out(vty, " advertised");
10543 if (CHECK_FLAG(p->cap,
10544 PEER_CAP_RESTART_RCV))
10545 vty_out(vty, " %sreceived",
10546 CHECK_FLAG(
10547 p->cap,
10548 PEER_CAP_RESTART_ADV)
10549 ? "and "
10550 : "");
10551 vty_out(vty, "\n");
10552
10553 if (CHECK_FLAG(p->cap,
10554 PEER_CAP_RESTART_RCV)) {
10555 int restart_af_count = 0;
10556
10557 vty_out(vty,
10558 " Remote Restart timer is %d seconds\n",
10559 p->v_gr_restart);
10560 vty_out(vty,
10561 " Address families by peer:\n ");
10562
10563 FOREACH_AFI_SAFI (afi, safi)
10564 if (CHECK_FLAG(
10565 p->af_cap
10566 [afi]
10567 [safi],
10568 PEER_CAP_RESTART_AF_RCV)) {
10569 vty_out(vty,
10570 "%s%s(%s)",
10571 restart_af_count
10572 ? ", "
10573 : "",
10574 get_afi_safi_str(
10575 afi,
10576 safi,
10577 false),
10578 CHECK_FLAG(
10579 p->af_cap
10580 [afi]
10581 [safi],
10582 PEER_CAP_RESTART_AF_PRESERVE_RCV)
10583 ? "preserved"
10584 : "not preserved");
10585 restart_af_count++;
10586 }
10587 if (!restart_af_count)
10588 vty_out(vty, "none");
10589 vty_out(vty, "\n");
10590 }
10591 }
10592 }
10593 }
10594 }
10595
10596 /* graceful restart information */
10597 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) || p->t_gr_restart
10598 || p->t_gr_stale) {
10599 json_object *json_grace = NULL;
10600 json_object *json_grace_send = NULL;
10601 json_object *json_grace_recv = NULL;
10602 int eor_send_af_count = 0;
10603 int eor_receive_af_count = 0;
10604
10605 if (use_json) {
10606 json_grace = json_object_new_object();
10607 json_grace_send = json_object_new_object();
10608 json_grace_recv = json_object_new_object();
10609
10610 if (p->status == Established) {
10611 FOREACH_AFI_SAFI (afi, safi) {
10612 if (CHECK_FLAG(p->af_sflags[afi][safi],
10613 PEER_STATUS_EOR_SEND)) {
10614 json_object_boolean_true_add(
10615 json_grace_send,
10616 get_afi_safi_str(afi,
10617 safi,
10618 true));
10619 eor_send_af_count++;
10620 }
10621 }
10622 FOREACH_AFI_SAFI (afi, safi) {
10623 if (CHECK_FLAG(
10624 p->af_sflags[afi][safi],
10625 PEER_STATUS_EOR_RECEIVED)) {
10626 json_object_boolean_true_add(
10627 json_grace_recv,
10628 get_afi_safi_str(afi,
10629 safi,
10630 true));
10631 eor_receive_af_count++;
10632 }
10633 }
10634 }
10635
10636 json_object_object_add(json_grace, "endOfRibSend",
10637 json_grace_send);
10638 json_object_object_add(json_grace, "endOfRibRecv",
10639 json_grace_recv);
10640
10641 if (p->t_gr_restart)
10642 json_object_int_add(json_grace,
10643 "gracefulRestartTimerMsecs",
10644 thread_timer_remain_second(
10645 p->t_gr_restart)
10646 * 1000);
10647
10648 if (p->t_gr_stale)
10649 json_object_int_add(
10650 json_grace,
10651 "gracefulStalepathTimerMsecs",
10652 thread_timer_remain_second(
10653 p->t_gr_stale)
10654 * 1000);
10655
10656 json_object_object_add(
10657 json_neigh, "gracefulRestartInfo", json_grace);
10658 } else {
10659 vty_out(vty, " Graceful restart information:\n");
10660 if (p->status == Established) {
10661 vty_out(vty, " End-of-RIB send: ");
10662 FOREACH_AFI_SAFI (afi, safi) {
10663 if (CHECK_FLAG(p->af_sflags[afi][safi],
10664 PEER_STATUS_EOR_SEND)) {
10665 vty_out(vty, "%s%s",
10666 eor_send_af_count ? ", "
10667 : "",
10668 get_afi_safi_str(afi,
10669 safi,
10670 false));
10671 eor_send_af_count++;
10672 }
10673 }
10674 vty_out(vty, "\n");
10675 vty_out(vty, " End-of-RIB received: ");
10676 FOREACH_AFI_SAFI (afi, safi) {
10677 if (CHECK_FLAG(
10678 p->af_sflags[afi][safi],
10679 PEER_STATUS_EOR_RECEIVED)) {
10680 vty_out(vty, "%s%s",
10681 eor_receive_af_count
10682 ? ", "
10683 : "",
10684 get_afi_safi_str(afi,
10685 safi,
10686 false));
10687 eor_receive_af_count++;
10688 }
10689 }
10690 vty_out(vty, "\n");
10691 }
10692
10693 if (p->t_gr_restart)
10694 vty_out(vty,
10695 " The remaining time of restart timer is %ld\n",
10696 thread_timer_remain_second(
10697 p->t_gr_restart));
10698
10699 if (p->t_gr_stale)
10700 vty_out(vty,
10701 " The remaining time of stalepath timer is %ld\n",
10702 thread_timer_remain_second(
10703 p->t_gr_stale));
10704 }
10705 }
10706 if (use_json) {
10707 json_object *json_stat = NULL;
10708 json_stat = json_object_new_object();
10709 /* Packet counts. */
10710 json_object_int_add(json_stat, "depthInq", 0);
10711 json_object_int_add(json_stat, "depthOutq",
10712 (unsigned long)p->obuf->count);
10713 json_object_int_add(json_stat, "opensSent",
10714 atomic_load_explicit(&p->open_out,
10715 memory_order_relaxed));
10716 json_object_int_add(json_stat, "opensRecv",
10717 atomic_load_explicit(&p->open_in,
10718 memory_order_relaxed));
10719 json_object_int_add(json_stat, "notificationsSent",
10720 atomic_load_explicit(&p->notify_out,
10721 memory_order_relaxed));
10722 json_object_int_add(json_stat, "notificationsRecv",
10723 atomic_load_explicit(&p->notify_in,
10724 memory_order_relaxed));
10725 json_object_int_add(json_stat, "updatesSent",
10726 atomic_load_explicit(&p->update_out,
10727 memory_order_relaxed));
10728 json_object_int_add(json_stat, "updatesRecv",
10729 atomic_load_explicit(&p->update_in,
10730 memory_order_relaxed));
10731 json_object_int_add(json_stat, "keepalivesSent",
10732 atomic_load_explicit(&p->keepalive_out,
10733 memory_order_relaxed));
10734 json_object_int_add(json_stat, "keepalivesRecv",
10735 atomic_load_explicit(&p->keepalive_in,
10736 memory_order_relaxed));
10737 json_object_int_add(json_stat, "routeRefreshSent",
10738 atomic_load_explicit(&p->refresh_out,
10739 memory_order_relaxed));
10740 json_object_int_add(json_stat, "routeRefreshRecv",
10741 atomic_load_explicit(&p->refresh_in,
10742 memory_order_relaxed));
10743 json_object_int_add(json_stat, "capabilitySent",
10744 atomic_load_explicit(&p->dynamic_cap_out,
10745 memory_order_relaxed));
10746 json_object_int_add(json_stat, "capabilityRecv",
10747 atomic_load_explicit(&p->dynamic_cap_in,
10748 memory_order_relaxed));
10749 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
10750 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
10751 json_object_object_add(json_neigh, "messageStats", json_stat);
10752 } else {
10753 /* Packet counts. */
10754 vty_out(vty, " Message statistics:\n");
10755 vty_out(vty, " Inq depth is 0\n");
10756 vty_out(vty, " Outq depth is %lu\n",
10757 (unsigned long)p->obuf->count);
10758 vty_out(vty, " Sent Rcvd\n");
10759 vty_out(vty, " Opens: %10d %10d\n",
10760 atomic_load_explicit(&p->open_out,
10761 memory_order_relaxed),
10762 atomic_load_explicit(&p->open_in,
10763 memory_order_relaxed));
10764 vty_out(vty, " Notifications: %10d %10d\n",
10765 atomic_load_explicit(&p->notify_out,
10766 memory_order_relaxed),
10767 atomic_load_explicit(&p->notify_in,
10768 memory_order_relaxed));
10769 vty_out(vty, " Updates: %10d %10d\n",
10770 atomic_load_explicit(&p->update_out,
10771 memory_order_relaxed),
10772 atomic_load_explicit(&p->update_in,
10773 memory_order_relaxed));
10774 vty_out(vty, " Keepalives: %10d %10d\n",
10775 atomic_load_explicit(&p->keepalive_out,
10776 memory_order_relaxed),
10777 atomic_load_explicit(&p->keepalive_in,
10778 memory_order_relaxed));
10779 vty_out(vty, " Route Refresh: %10d %10d\n",
10780 atomic_load_explicit(&p->refresh_out,
10781 memory_order_relaxed),
10782 atomic_load_explicit(&p->refresh_in,
10783 memory_order_relaxed));
10784 vty_out(vty, " Capability: %10d %10d\n",
10785 atomic_load_explicit(&p->dynamic_cap_out,
10786 memory_order_relaxed),
10787 atomic_load_explicit(&p->dynamic_cap_in,
10788 memory_order_relaxed));
10789 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
10790 PEER_TOTAL_RX(p));
10791 }
10792
10793 if (use_json) {
10794 /* advertisement-interval */
10795 json_object_int_add(json_neigh,
10796 "minBtwnAdvertisementRunsTimerMsecs",
10797 p->v_routeadv * 1000);
10798
10799 /* Update-source. */
10800 if (p->update_if || p->update_source) {
10801 if (p->update_if)
10802 json_object_string_add(json_neigh,
10803 "updateSource",
10804 p->update_if);
10805 else if (p->update_source)
10806 json_object_string_add(
10807 json_neigh, "updateSource",
10808 sockunion2str(p->update_source, buf1,
10809 SU_ADDRSTRLEN));
10810 }
10811 } else {
10812 /* advertisement-interval */
10813 vty_out(vty,
10814 " Minimum time between advertisement runs is %d seconds\n",
10815 p->v_routeadv);
10816
10817 /* Update-source. */
10818 if (p->update_if || p->update_source) {
10819 vty_out(vty, " Update source is ");
10820 if (p->update_if)
10821 vty_out(vty, "%s", p->update_if);
10822 else if (p->update_source)
10823 vty_out(vty, "%s",
10824 sockunion2str(p->update_source, buf1,
10825 SU_ADDRSTRLEN));
10826 vty_out(vty, "\n");
10827 }
10828
10829 vty_out(vty, "\n");
10830 }
10831
10832 /* Address Family Information */
10833 json_object *json_hold = NULL;
10834
10835 if (use_json)
10836 json_hold = json_object_new_object();
10837
10838 FOREACH_AFI_SAFI (afi, safi)
10839 if (p->afc[afi][safi])
10840 bgp_show_peer_afi(vty, p, afi, safi, use_json,
10841 json_hold);
10842
10843 if (use_json) {
10844 json_object_object_add(json_neigh, "addressFamilyInfo",
10845 json_hold);
10846 json_object_int_add(json_neigh, "connectionsEstablished",
10847 p->established);
10848 json_object_int_add(json_neigh, "connectionsDropped",
10849 p->dropped);
10850 } else
10851 vty_out(vty, " Connections established %d; dropped %d\n",
10852 p->established, p->dropped);
10853
10854 if (!p->last_reset) {
10855 if (use_json)
10856 json_object_string_add(json_neigh, "lastReset",
10857 "never");
10858 else
10859 vty_out(vty, " Last reset never\n");
10860 } else {
10861 if (use_json) {
10862 time_t uptime;
10863 struct tm *tm;
10864
10865 uptime = bgp_clock();
10866 uptime -= p->resettime;
10867 tm = gmtime(&uptime);
10868 json_object_int_add(json_neigh, "lastResetTimerMsecs",
10869 (tm->tm_sec * 1000)
10870 + (tm->tm_min * 60000)
10871 + (tm->tm_hour * 3600000));
10872 bgp_show_peer_reset(NULL, p, json_neigh, true);
10873 } else {
10874 vty_out(vty, " Last reset %s, ",
10875 peer_uptime(p->resettime, timebuf,
10876 BGP_UPTIME_LEN, 0, NULL));
10877
10878 bgp_show_peer_reset(vty, p, NULL, false);
10879 if (p->last_reset_cause_size) {
10880 msg = p->last_reset_cause;
10881 vty_out(vty,
10882 " Message received that caused BGP to send a NOTIFICATION:\n ");
10883 for (i = 1; i <= p->last_reset_cause_size;
10884 i++) {
10885 vty_out(vty, "%02X", *msg++);
10886
10887 if (i != p->last_reset_cause_size) {
10888 if (i % 16 == 0) {
10889 vty_out(vty, "\n ");
10890 } else if (i % 4 == 0) {
10891 vty_out(vty, " ");
10892 }
10893 }
10894 }
10895 vty_out(vty, "\n");
10896 }
10897 }
10898 }
10899
10900 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
10901 if (use_json)
10902 json_object_boolean_true_add(json_neigh,
10903 "prefixesConfigExceedMax");
10904 else
10905 vty_out(vty,
10906 " Peer had exceeded the max. no. of prefixes configured.\n");
10907
10908 if (p->t_pmax_restart) {
10909 if (use_json) {
10910 json_object_boolean_true_add(
10911 json_neigh, "reducePrefixNumFrom");
10912 json_object_int_add(json_neigh,
10913 "restartInTimerMsec",
10914 thread_timer_remain_second(
10915 p->t_pmax_restart)
10916 * 1000);
10917 } else
10918 vty_out(vty,
10919 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
10920 p->host, thread_timer_remain_second(
10921 p->t_pmax_restart));
10922 } else {
10923 if (use_json)
10924 json_object_boolean_true_add(
10925 json_neigh,
10926 "reducePrefixNumAndClearIpBgp");
10927 else
10928 vty_out(vty,
10929 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
10930 p->host);
10931 }
10932 }
10933
10934 /* EBGP Multihop and GTSM */
10935 if (p->sort != BGP_PEER_IBGP) {
10936 if (use_json) {
10937 if (p->gtsm_hops > 0)
10938 json_object_int_add(json_neigh,
10939 "externalBgpNbrMaxHopsAway",
10940 p->gtsm_hops);
10941 else if (p->ttl > 1)
10942 json_object_int_add(json_neigh,
10943 "externalBgpNbrMaxHopsAway",
10944 p->ttl);
10945 } else {
10946 if (p->gtsm_hops > 0)
10947 vty_out(vty,
10948 " External BGP neighbor may be up to %d hops away.\n",
10949 p->gtsm_hops);
10950 else if (p->ttl > 1)
10951 vty_out(vty,
10952 " External BGP neighbor may be up to %d hops away.\n",
10953 p->ttl);
10954 }
10955 } else {
10956 if (p->gtsm_hops > 0) {
10957 if (use_json)
10958 json_object_int_add(json_neigh,
10959 "internalBgpNbrMaxHopsAway",
10960 p->gtsm_hops);
10961 else
10962 vty_out(vty,
10963 " Internal BGP neighbor may be up to %d hops away.\n",
10964 p->gtsm_hops);
10965 }
10966 }
10967
10968 /* Local address. */
10969 if (p->su_local) {
10970 if (use_json) {
10971 json_object_string_add(json_neigh, "hostLocal",
10972 sockunion2str(p->su_local, buf1,
10973 SU_ADDRSTRLEN));
10974 json_object_int_add(json_neigh, "portLocal",
10975 ntohs(p->su_local->sin.sin_port));
10976 } else
10977 vty_out(vty, "Local host: %s, Local port: %d\n",
10978 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
10979 ntohs(p->su_local->sin.sin_port));
10980 }
10981
10982 /* Remote address. */
10983 if (p->su_remote) {
10984 if (use_json) {
10985 json_object_string_add(json_neigh, "hostForeign",
10986 sockunion2str(p->su_remote, buf1,
10987 SU_ADDRSTRLEN));
10988 json_object_int_add(json_neigh, "portForeign",
10989 ntohs(p->su_remote->sin.sin_port));
10990 } else
10991 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
10992 sockunion2str(p->su_remote, buf1,
10993 SU_ADDRSTRLEN),
10994 ntohs(p->su_remote->sin.sin_port));
10995 }
10996
10997 /* Nexthop display. */
10998 if (p->su_local) {
10999 if (use_json) {
11000 json_object_string_add(json_neigh, "nexthop",
11001 inet_ntop(AF_INET,
11002 &p->nexthop.v4, buf1,
11003 sizeof(buf1)));
11004 json_object_string_add(json_neigh, "nexthopGlobal",
11005 inet_ntop(AF_INET6,
11006 &p->nexthop.v6_global,
11007 buf1, sizeof(buf1)));
11008 json_object_string_add(json_neigh, "nexthopLocal",
11009 inet_ntop(AF_INET6,
11010 &p->nexthop.v6_local,
11011 buf1, sizeof(buf1)));
11012 if (p->shared_network)
11013 json_object_string_add(json_neigh,
11014 "bgpConnection",
11015 "sharedNetwork");
11016 else
11017 json_object_string_add(json_neigh,
11018 "bgpConnection",
11019 "nonSharedNetwork");
11020 } else {
11021 vty_out(vty, "Nexthop: %s\n",
11022 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
11023 sizeof(buf1)));
11024 vty_out(vty, "Nexthop global: %s\n",
11025 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
11026 sizeof(buf1)));
11027 vty_out(vty, "Nexthop local: %s\n",
11028 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
11029 sizeof(buf1)));
11030 vty_out(vty, "BGP connection: %s\n",
11031 p->shared_network ? "shared network"
11032 : "non shared network");
11033 }
11034 }
11035
11036 /* Timer information. */
11037 if (use_json) {
11038 json_object_int_add(json_neigh, "connectRetryTimer",
11039 p->v_connect);
11040 if (p->status == Established && p->rtt)
11041 json_object_int_add(json_neigh, "estimatedRttInMsecs",
11042 p->rtt);
11043 if (p->t_start)
11044 json_object_int_add(
11045 json_neigh, "nextStartTimerDueInMsecs",
11046 thread_timer_remain_second(p->t_start) * 1000);
11047 if (p->t_connect)
11048 json_object_int_add(
11049 json_neigh, "nextConnectTimerDueInMsecs",
11050 thread_timer_remain_second(p->t_connect)
11051 * 1000);
11052 if (p->t_routeadv) {
11053 json_object_int_add(json_neigh, "mraiInterval",
11054 p->v_routeadv);
11055 json_object_int_add(
11056 json_neigh, "mraiTimerExpireInMsecs",
11057 thread_timer_remain_second(p->t_routeadv)
11058 * 1000);
11059 }
11060 if (p->password)
11061 json_object_int_add(json_neigh, "authenticationEnabled",
11062 1);
11063
11064 if (p->t_read)
11065 json_object_string_add(json_neigh, "readThread", "on");
11066 else
11067 json_object_string_add(json_neigh, "readThread", "off");
11068
11069 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
11070 json_object_string_add(json_neigh, "writeThread", "on");
11071 else
11072 json_object_string_add(json_neigh, "writeThread",
11073 "off");
11074 } else {
11075 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
11076 p->v_connect);
11077 if (p->status == Established && p->rtt)
11078 vty_out(vty, "Estimated round trip time: %d ms\n",
11079 p->rtt);
11080 if (p->t_start)
11081 vty_out(vty, "Next start timer due in %ld seconds\n",
11082 thread_timer_remain_second(p->t_start));
11083 if (p->t_connect)
11084 vty_out(vty, "Next connect timer due in %ld seconds\n",
11085 thread_timer_remain_second(p->t_connect));
11086 if (p->t_routeadv)
11087 vty_out(vty,
11088 "MRAI (interval %u) timer expires in %ld seconds\n",
11089 p->v_routeadv,
11090 thread_timer_remain_second(p->t_routeadv));
11091 if (p->password)
11092 vty_out(vty, "Peer Authentication Enabled\n");
11093
11094 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
11095 p->t_read ? "on" : "off",
11096 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
11097 ? "on"
11098 : "off", p->fd);
11099 }
11100
11101 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
11102 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
11103 bgp_capability_vty_out(vty, p, use_json, json_neigh);
11104
11105 if (!use_json)
11106 vty_out(vty, "\n");
11107
11108 /* BFD information. */
11109 bgp_bfd_show_info(vty, p, use_json, json_neigh);
11110
11111 if (use_json) {
11112 if (p->conf_if) /* Configured interface name. */
11113 json_object_object_add(json, p->conf_if, json_neigh);
11114 else /* Configured IP address. */
11115 json_object_object_add(json, p->host, json_neigh);
11116 }
11117 }
11118
11119 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
11120 enum show_type type, union sockunion *su,
11121 const char *conf_if, bool use_json,
11122 json_object *json)
11123 {
11124 struct listnode *node, *nnode;
11125 struct peer *peer;
11126 int find = 0;
11127 bool nbr_output = false;
11128 afi_t afi = AFI_MAX;
11129 safi_t safi = SAFI_MAX;
11130
11131 if (type == show_ipv4_peer || type == show_ipv4_all) {
11132 afi = AFI_IP;
11133 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
11134 afi = AFI_IP6;
11135 }
11136
11137 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
11138 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
11139 continue;
11140
11141 switch (type) {
11142 case show_all:
11143 bgp_show_peer(vty, peer, use_json, json);
11144 nbr_output = true;
11145 break;
11146 case show_peer:
11147 if (conf_if) {
11148 if ((peer->conf_if
11149 && !strcmp(peer->conf_if, conf_if))
11150 || (peer->hostname
11151 && !strcmp(peer->hostname, conf_if))) {
11152 find = 1;
11153 bgp_show_peer(vty, peer, use_json,
11154 json);
11155 }
11156 } else {
11157 if (sockunion_same(&peer->su, su)) {
11158 find = 1;
11159 bgp_show_peer(vty, peer, use_json,
11160 json);
11161 }
11162 }
11163 break;
11164 case show_ipv4_peer:
11165 case show_ipv6_peer:
11166 FOREACH_SAFI (safi) {
11167 if (peer->afc[afi][safi]) {
11168 if (conf_if) {
11169 if ((peer->conf_if
11170 && !strcmp(peer->conf_if, conf_if))
11171 || (peer->hostname
11172 && !strcmp(peer->hostname, conf_if))) {
11173 find = 1;
11174 bgp_show_peer(vty, peer, use_json,
11175 json);
11176 break;
11177 }
11178 } else {
11179 if (sockunion_same(&peer->su, su)) {
11180 find = 1;
11181 bgp_show_peer(vty, peer, use_json,
11182 json);
11183 break;
11184 }
11185 }
11186 }
11187 }
11188 break;
11189 case show_ipv4_all:
11190 case show_ipv6_all:
11191 FOREACH_SAFI (safi) {
11192 if (peer->afc[afi][safi]) {
11193 bgp_show_peer(vty, peer, use_json, json);
11194 nbr_output = true;
11195 break;
11196 }
11197 }
11198 break;
11199 }
11200 }
11201
11202 if ((type == show_peer || type == show_ipv4_peer ||
11203 type == show_ipv6_peer) && !find) {
11204 if (use_json)
11205 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
11206 else
11207 vty_out(vty, "%% No such neighbor in this view/vrf\n");
11208 }
11209
11210 if (type != show_peer && type != show_ipv4_peer &&
11211 type != show_ipv6_peer && !nbr_output && !use_json)
11212 vty_out(vty, "%% No BGP neighbors found\n");
11213
11214 if (use_json) {
11215 vty_out(vty, "%s\n", json_object_to_json_string_ext(
11216 json, JSON_C_TO_STRING_PRETTY));
11217 } else {
11218 vty_out(vty, "\n");
11219 }
11220
11221 return CMD_SUCCESS;
11222 }
11223
11224 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
11225 enum show_type type,
11226 const char *ip_str,
11227 bool use_json)
11228 {
11229 struct listnode *node, *nnode;
11230 struct bgp *bgp;
11231 union sockunion su;
11232 json_object *json = NULL;
11233 int ret, is_first = 1;
11234 bool nbr_output = false;
11235
11236 if (use_json)
11237 vty_out(vty, "{\n");
11238
11239 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11240 nbr_output = true;
11241 if (use_json) {
11242 if (!(json = json_object_new_object())) {
11243 flog_err(
11244 EC_BGP_JSON_MEM_ERROR,
11245 "Unable to allocate memory for JSON object");
11246 vty_out(vty,
11247 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
11248 return;
11249 }
11250
11251 json_object_int_add(json, "vrfId",
11252 (bgp->vrf_id == VRF_UNKNOWN)
11253 ? -1
11254 : (int64_t)bgp->vrf_id);
11255 json_object_string_add(
11256 json, "vrfName",
11257 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11258 ? VRF_DEFAULT_NAME
11259 : bgp->name);
11260
11261 if (!is_first)
11262 vty_out(vty, ",\n");
11263 else
11264 is_first = 0;
11265
11266 vty_out(vty, "\"%s\":",
11267 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11268 ? VRF_DEFAULT_NAME
11269 : bgp->name);
11270 } else {
11271 vty_out(vty, "\nInstance %s:\n",
11272 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11273 ? VRF_DEFAULT_NAME
11274 : bgp->name);
11275 }
11276
11277 if (type == show_peer || type == show_ipv4_peer ||
11278 type == show_ipv6_peer) {
11279 ret = str2sockunion(ip_str, &su);
11280 if (ret < 0)
11281 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
11282 use_json, json);
11283 else
11284 bgp_show_neighbor(vty, bgp, type, &su, NULL,
11285 use_json, json);
11286 } else {
11287 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
11288 use_json, json);
11289 }
11290 json_object_free(json);
11291 }
11292
11293 if (use_json) {
11294 vty_out(vty, "}\n");
11295 json_object_free(json);
11296 }
11297 else if (!nbr_output)
11298 vty_out(vty, "%% BGP instance not found\n");
11299 }
11300
11301 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
11302 enum show_type type, const char *ip_str,
11303 bool use_json)
11304 {
11305 int ret;
11306 struct bgp *bgp;
11307 union sockunion su;
11308 json_object *json = NULL;
11309
11310 if (name) {
11311 if (strmatch(name, "all")) {
11312 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
11313 use_json);
11314 return CMD_SUCCESS;
11315 } else {
11316 bgp = bgp_lookup_by_name(name);
11317 if (!bgp) {
11318 if (use_json) {
11319 json = json_object_new_object();
11320 vty_out(vty, "%s\n",
11321 json_object_to_json_string_ext(
11322 json,
11323 JSON_C_TO_STRING_PRETTY));
11324 json_object_free(json);
11325 } else
11326 vty_out(vty,
11327 "%% BGP instance not found\n");
11328
11329 return CMD_WARNING;
11330 }
11331 }
11332 } else {
11333 bgp = bgp_get_default();
11334 }
11335
11336 if (bgp) {
11337 json = json_object_new_object();
11338 if (ip_str) {
11339 ret = str2sockunion(ip_str, &su);
11340 if (ret < 0)
11341 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
11342 use_json, json);
11343 else
11344 bgp_show_neighbor(vty, bgp, type, &su, NULL,
11345 use_json, json);
11346 } else {
11347 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
11348 json);
11349 }
11350 json_object_free(json);
11351 } else {
11352 if (use_json)
11353 vty_out(vty, "{}\n");
11354 else
11355 vty_out(vty, "%% BGP instance not found\n");
11356 }
11357
11358 return CMD_SUCCESS;
11359 }
11360
11361 /* "show [ip] bgp neighbors" commands. */
11362 DEFUN (show_ip_bgp_neighbors,
11363 show_ip_bgp_neighbors_cmd,
11364 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
11365 SHOW_STR
11366 IP_STR
11367 BGP_STR
11368 BGP_INSTANCE_HELP_STR
11369 "Address Family\n"
11370 "Address Family\n"
11371 "Detailed information on TCP and BGP neighbor connections\n"
11372 "Neighbor to display information about\n"
11373 "Neighbor to display information about\n"
11374 "Neighbor on BGP configured interface\n"
11375 JSON_STR)
11376 {
11377 char *vrf = NULL;
11378 char *sh_arg = NULL;
11379 enum show_type sh_type;
11380 afi_t afi = AFI_MAX;
11381
11382 bool uj = use_json(argc, argv);
11383
11384 int idx = 0;
11385
11386 /* [<vrf> VIEWVRFNAME] */
11387 if (argv_find(argv, argc, "vrf", &idx)) {
11388 vrf = argv[idx + 1]->arg;
11389 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11390 vrf = NULL;
11391 } else if (argv_find(argv, argc, "view", &idx))
11392 /* [<view> VIEWVRFNAME] */
11393 vrf = argv[idx + 1]->arg;
11394
11395 idx++;
11396
11397 if (argv_find(argv, argc, "ipv4", &idx)) {
11398 sh_type = show_ipv4_all;
11399 afi = AFI_IP;
11400 } else if (argv_find(argv, argc, "ipv6", &idx)) {
11401 sh_type = show_ipv6_all;
11402 afi = AFI_IP6;
11403 } else {
11404 sh_type = show_all;
11405 }
11406
11407 if (argv_find(argv, argc, "A.B.C.D", &idx)
11408 || argv_find(argv, argc, "X:X::X:X", &idx)
11409 || argv_find(argv, argc, "WORD", &idx)) {
11410 sh_type = show_peer;
11411 sh_arg = argv[idx]->arg;
11412 }
11413
11414 if (sh_type == show_peer && afi == AFI_IP) {
11415 sh_type = show_ipv4_peer;
11416 } else if (sh_type == show_peer && afi == AFI_IP6) {
11417 sh_type = show_ipv6_peer;
11418 }
11419
11420 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
11421 }
11422
11423 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
11424 paths' and `show ip mbgp paths'. Those functions results are the
11425 same.*/
11426 DEFUN (show_ip_bgp_paths,
11427 show_ip_bgp_paths_cmd,
11428 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
11429 SHOW_STR
11430 IP_STR
11431 BGP_STR
11432 BGP_SAFI_HELP_STR
11433 "Path information\n")
11434 {
11435 vty_out(vty, "Address Refcnt Path\n");
11436 aspath_print_all_vty(vty);
11437 return CMD_SUCCESS;
11438 }
11439
11440 #include "hash.h"
11441
11442 static void community_show_all_iterator(struct hash_bucket *bucket,
11443 struct vty *vty)
11444 {
11445 struct community *com;
11446
11447 com = (struct community *)bucket->data;
11448 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
11449 community_str(com, false));
11450 }
11451
11452 /* Show BGP's community internal data. */
11453 DEFUN (show_ip_bgp_community_info,
11454 show_ip_bgp_community_info_cmd,
11455 "show [ip] bgp community-info",
11456 SHOW_STR
11457 IP_STR
11458 BGP_STR
11459 "List all bgp community information\n")
11460 {
11461 vty_out(vty, "Address Refcnt Community\n");
11462
11463 hash_iterate(community_hash(),
11464 (void (*)(struct hash_bucket *,
11465 void *))community_show_all_iterator,
11466 vty);
11467
11468 return CMD_SUCCESS;
11469 }
11470
11471 static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
11472 struct vty *vty)
11473 {
11474 struct lcommunity *lcom;
11475
11476 lcom = (struct lcommunity *)bucket->data;
11477 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
11478 lcommunity_str(lcom, false));
11479 }
11480
11481 /* Show BGP's community internal data. */
11482 DEFUN (show_ip_bgp_lcommunity_info,
11483 show_ip_bgp_lcommunity_info_cmd,
11484 "show ip bgp large-community-info",
11485 SHOW_STR
11486 IP_STR
11487 BGP_STR
11488 "List all bgp large-community information\n")
11489 {
11490 vty_out(vty, "Address Refcnt Large-community\n");
11491
11492 hash_iterate(lcommunity_hash(),
11493 (void (*)(struct hash_bucket *,
11494 void *))lcommunity_show_all_iterator,
11495 vty);
11496
11497 return CMD_SUCCESS;
11498 }
11499
11500
11501 DEFUN (show_ip_bgp_attr_info,
11502 show_ip_bgp_attr_info_cmd,
11503 "show [ip] bgp attribute-info",
11504 SHOW_STR
11505 IP_STR
11506 BGP_STR
11507 "List all bgp attribute information\n")
11508 {
11509 attr_show_all(vty);
11510 return CMD_SUCCESS;
11511 }
11512
11513 static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
11514 afi_t afi, safi_t safi,
11515 bool use_json, json_object *json)
11516 {
11517 struct bgp *bgp;
11518 struct listnode *node;
11519 char *vname;
11520 char buf1[INET6_ADDRSTRLEN];
11521 char *ecom_str;
11522 vpn_policy_direction_t dir;
11523
11524 if (json) {
11525 json_object *json_import_vrfs = NULL;
11526 json_object *json_export_vrfs = NULL;
11527
11528 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11529
11530 if (!bgp) {
11531 vty_out(vty, "%s\n",
11532 json_object_to_json_string_ext(
11533 json,
11534 JSON_C_TO_STRING_PRETTY));
11535 json_object_free(json);
11536
11537 return CMD_WARNING;
11538 }
11539
11540 /* Provide context for the block */
11541 json_object_string_add(json, "vrf", name ? name : "default");
11542 json_object_string_add(json, "afiSafi",
11543 get_afi_safi_str(afi, safi, true));
11544
11545 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11546 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
11547 json_object_string_add(json, "importFromVrfs", "none");
11548 json_object_string_add(json, "importRts", "none");
11549 } else {
11550 json_import_vrfs = json_object_new_array();
11551
11552 for (ALL_LIST_ELEMENTS_RO(
11553 bgp->vpn_policy[afi].import_vrf,
11554 node, vname))
11555 json_object_array_add(json_import_vrfs,
11556 json_object_new_string(vname));
11557
11558 json_object_object_add(json, "importFromVrfs",
11559 json_import_vrfs);
11560 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11561 if (bgp->vpn_policy[afi].rtlist[dir]) {
11562 ecom_str = ecommunity_ecom2str(
11563 bgp->vpn_policy[afi].rtlist[dir],
11564 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11565 json_object_string_add(json, "importRts",
11566 ecom_str);
11567 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11568 } else
11569 json_object_string_add(json, "importRts",
11570 "none");
11571 }
11572
11573 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11574 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
11575 json_object_string_add(json, "exportToVrfs", "none");
11576 json_object_string_add(json, "routeDistinguisher",
11577 "none");
11578 json_object_string_add(json, "exportRts", "none");
11579 } else {
11580 json_export_vrfs = json_object_new_array();
11581
11582 for (ALL_LIST_ELEMENTS_RO(
11583 bgp->vpn_policy[afi].export_vrf,
11584 node, vname))
11585 json_object_array_add(json_export_vrfs,
11586 json_object_new_string(vname));
11587 json_object_object_add(json, "exportToVrfs",
11588 json_export_vrfs);
11589 json_object_string_add(json, "routeDistinguisher",
11590 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11591 buf1, RD_ADDRSTRLEN));
11592
11593 dir = BGP_VPN_POLICY_DIR_TOVPN;
11594 if (bgp->vpn_policy[afi].rtlist[dir]) {
11595 ecom_str = ecommunity_ecom2str(
11596 bgp->vpn_policy[afi].rtlist[dir],
11597 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11598 json_object_string_add(json, "exportRts",
11599 ecom_str);
11600 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11601 } else
11602 json_object_string_add(json, "exportRts",
11603 "none");
11604 }
11605
11606 if (use_json) {
11607 vty_out(vty, "%s\n",
11608 json_object_to_json_string_ext(json,
11609 JSON_C_TO_STRING_PRETTY));
11610 json_object_free(json);
11611 }
11612 } else {
11613 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11614
11615 if (!bgp) {
11616 vty_out(vty, "%% No such BGP instance exist\n");
11617 return CMD_WARNING;
11618 }
11619
11620 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11621 BGP_CONFIG_VRF_TO_VRF_IMPORT))
11622 vty_out(vty,
11623 "This VRF is not importing %s routes from any other VRF\n",
11624 get_afi_safi_str(afi, safi, false));
11625 else {
11626 vty_out(vty,
11627 "This VRF is importing %s routes from the following VRFs:\n",
11628 get_afi_safi_str(afi, safi, false));
11629
11630 for (ALL_LIST_ELEMENTS_RO(
11631 bgp->vpn_policy[afi].import_vrf,
11632 node, vname))
11633 vty_out(vty, " %s\n", vname);
11634
11635 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11636 ecom_str = NULL;
11637 if (bgp->vpn_policy[afi].rtlist[dir]) {
11638 ecom_str = ecommunity_ecom2str(
11639 bgp->vpn_policy[afi].rtlist[dir],
11640 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11641 vty_out(vty, "Import RT(s): %s\n", ecom_str);
11642
11643 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11644 } else
11645 vty_out(vty, "Import RT(s):\n");
11646 }
11647
11648 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11649 BGP_CONFIG_VRF_TO_VRF_EXPORT))
11650 vty_out(vty,
11651 "This VRF is not exporting %s routes to any other VRF\n",
11652 get_afi_safi_str(afi, safi, false));
11653 else {
11654 vty_out(vty,
11655 "This VRF is exporting %s routes to the following VRFs:\n",
11656 get_afi_safi_str(afi, safi, false));
11657
11658 for (ALL_LIST_ELEMENTS_RO(
11659 bgp->vpn_policy[afi].export_vrf,
11660 node, vname))
11661 vty_out(vty, " %s\n", vname);
11662
11663 vty_out(vty, "RD: %s\n",
11664 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11665 buf1, RD_ADDRSTRLEN));
11666
11667 dir = BGP_VPN_POLICY_DIR_TOVPN;
11668 if (bgp->vpn_policy[afi].rtlist[dir]) {
11669 ecom_str = ecommunity_ecom2str(
11670 bgp->vpn_policy[afi].rtlist[dir],
11671 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11672 vty_out(vty, "Export RT: %s\n", ecom_str);
11673 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11674 } else
11675 vty_out(vty, "Import RT(s):\n");
11676 }
11677 }
11678
11679 return CMD_SUCCESS;
11680 }
11681
11682 static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
11683 safi_t safi, bool use_json)
11684 {
11685 struct listnode *node, *nnode;
11686 struct bgp *bgp;
11687 char *vrf_name = NULL;
11688 json_object *json = NULL;
11689 json_object *json_vrf = NULL;
11690 json_object *json_vrfs = NULL;
11691
11692 if (use_json) {
11693 json = json_object_new_object();
11694 json_vrfs = json_object_new_object();
11695 }
11696
11697 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11698
11699 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
11700 vrf_name = bgp->name;
11701
11702 if (use_json) {
11703 json_vrf = json_object_new_object();
11704 } else {
11705 vty_out(vty, "\nInstance %s:\n",
11706 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11707 ? VRF_DEFAULT_NAME : bgp->name);
11708 }
11709 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
11710 if (use_json) {
11711 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11712 json_object_object_add(json_vrfs,
11713 VRF_DEFAULT_NAME, json_vrf);
11714 else
11715 json_object_object_add(json_vrfs, vrf_name,
11716 json_vrf);
11717 }
11718 }
11719
11720 if (use_json) {
11721 json_object_object_add(json, "vrfs", json_vrfs);
11722 vty_out(vty, "%s\n", json_object_to_json_string_ext(json,
11723 JSON_C_TO_STRING_PRETTY));
11724 json_object_free(json);
11725 }
11726
11727 return CMD_SUCCESS;
11728 }
11729
11730 /* "show [ip] bgp route-leak" command. */
11731 DEFUN (show_ip_bgp_route_leak,
11732 show_ip_bgp_route_leak_cmd,
11733 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
11734 SHOW_STR
11735 IP_STR
11736 BGP_STR
11737 BGP_INSTANCE_HELP_STR
11738 BGP_AFI_HELP_STR
11739 BGP_SAFI_HELP_STR
11740 "Route leaking information\n"
11741 JSON_STR)
11742 {
11743 char *vrf = NULL;
11744 afi_t afi = AFI_MAX;
11745 safi_t safi = SAFI_MAX;
11746
11747 bool uj = use_json(argc, argv);
11748 int idx = 0;
11749 json_object *json = NULL;
11750
11751 /* show [ip] bgp */
11752 if (argv_find(argv, argc, "ip", &idx)) {
11753 afi = AFI_IP;
11754 safi = SAFI_UNICAST;
11755 }
11756 /* [vrf VIEWVRFNAME] */
11757 if (argv_find(argv, argc, "view", &idx)) {
11758 vty_out(vty,
11759 "%% This command is not applicable to BGP views\n");
11760 return CMD_WARNING;
11761 }
11762
11763 if (argv_find(argv, argc, "vrf", &idx)) {
11764 vrf = argv[idx + 1]->arg;
11765 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11766 vrf = NULL;
11767 }
11768 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11769 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11770 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11771 }
11772
11773 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
11774 vty_out(vty,
11775 "%% This command is applicable only for unicast ipv4|ipv6\n");
11776 return CMD_WARNING;
11777 }
11778
11779 if (vrf && strmatch(vrf, "all"))
11780 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
11781
11782 if (uj)
11783 json = json_object_new_object();
11784
11785 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
11786 }
11787
11788 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
11789 safi_t safi)
11790 {
11791 struct listnode *node, *nnode;
11792 struct bgp *bgp;
11793
11794 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11795 vty_out(vty, "\nInstance %s:\n",
11796 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11797 ? VRF_DEFAULT_NAME
11798 : bgp->name);
11799 update_group_show(bgp, afi, safi, vty, 0);
11800 }
11801 }
11802
11803 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
11804 int safi, uint64_t subgrp_id)
11805 {
11806 struct bgp *bgp;
11807
11808 if (name) {
11809 if (strmatch(name, "all")) {
11810 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
11811 return CMD_SUCCESS;
11812 } else {
11813 bgp = bgp_lookup_by_name(name);
11814 }
11815 } else {
11816 bgp = bgp_get_default();
11817 }
11818
11819 if (bgp)
11820 update_group_show(bgp, afi, safi, vty, subgrp_id);
11821 return CMD_SUCCESS;
11822 }
11823
11824 DEFUN (show_ip_bgp_updgrps,
11825 show_ip_bgp_updgrps_cmd,
11826 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
11827 SHOW_STR
11828 IP_STR
11829 BGP_STR
11830 BGP_INSTANCE_HELP_STR
11831 BGP_AFI_HELP_STR
11832 BGP_SAFI_WITH_LABEL_HELP_STR
11833 "Detailed info about dynamic update groups\n"
11834 "Specific subgroup to display detailed info for\n")
11835 {
11836 char *vrf = NULL;
11837 afi_t afi = AFI_IP6;
11838 safi_t safi = SAFI_UNICAST;
11839 uint64_t subgrp_id = 0;
11840
11841 int idx = 0;
11842
11843 /* show [ip] bgp */
11844 if (argv_find(argv, argc, "ip", &idx))
11845 afi = AFI_IP;
11846 /* [<vrf> VIEWVRFNAME] */
11847 if (argv_find(argv, argc, "vrf", &idx)) {
11848 vrf = argv[idx + 1]->arg;
11849 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11850 vrf = NULL;
11851 } else if (argv_find(argv, argc, "view", &idx))
11852 /* [<view> VIEWVRFNAME] */
11853 vrf = argv[idx + 1]->arg;
11854 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11855 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11856 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11857 }
11858
11859 /* get subgroup id, if provided */
11860 idx = argc - 1;
11861 if (argv[idx]->type == VARIABLE_TKN)
11862 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
11863
11864 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
11865 }
11866
11867 DEFUN (show_bgp_instance_all_ipv6_updgrps,
11868 show_bgp_instance_all_ipv6_updgrps_cmd,
11869 "show [ip] bgp <view|vrf> all update-groups",
11870 SHOW_STR
11871 IP_STR
11872 BGP_STR
11873 BGP_INSTANCE_ALL_HELP_STR
11874 "Detailed info about dynamic update groups\n")
11875 {
11876 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
11877 return CMD_SUCCESS;
11878 }
11879
11880 DEFUN (show_bgp_l2vpn_evpn_updgrps,
11881 show_bgp_l2vpn_evpn_updgrps_cmd,
11882 "show [ip] bgp l2vpn evpn update-groups",
11883 SHOW_STR
11884 IP_STR
11885 BGP_STR
11886 "l2vpn address family\n"
11887 "evpn sub-address family\n"
11888 "Detailed info about dynamic update groups\n")
11889 {
11890 char *vrf = NULL;
11891 uint64_t subgrp_id = 0;
11892
11893 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
11894 return CMD_SUCCESS;
11895 }
11896
11897 DEFUN (show_bgp_updgrps_stats,
11898 show_bgp_updgrps_stats_cmd,
11899 "show [ip] bgp update-groups statistics",
11900 SHOW_STR
11901 IP_STR
11902 BGP_STR
11903 "Detailed info about dynamic update groups\n"
11904 "Statistics\n")
11905 {
11906 struct bgp *bgp;
11907
11908 bgp = bgp_get_default();
11909 if (bgp)
11910 update_group_show_stats(bgp, vty);
11911
11912 return CMD_SUCCESS;
11913 }
11914
11915 DEFUN (show_bgp_instance_updgrps_stats,
11916 show_bgp_instance_updgrps_stats_cmd,
11917 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
11918 SHOW_STR
11919 IP_STR
11920 BGP_STR
11921 BGP_INSTANCE_HELP_STR
11922 "Detailed info about dynamic update groups\n"
11923 "Statistics\n")
11924 {
11925 int idx_word = 3;
11926 struct bgp *bgp;
11927
11928 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
11929 if (bgp)
11930 update_group_show_stats(bgp, vty);
11931
11932 return CMD_SUCCESS;
11933 }
11934
11935 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
11936 afi_t afi, safi_t safi,
11937 const char *what, uint64_t subgrp_id)
11938 {
11939 struct bgp *bgp;
11940
11941 if (name)
11942 bgp = bgp_lookup_by_name(name);
11943 else
11944 bgp = bgp_get_default();
11945
11946 if (bgp) {
11947 if (!strcmp(what, "advertise-queue"))
11948 update_group_show_adj_queue(bgp, afi, safi, vty,
11949 subgrp_id);
11950 else if (!strcmp(what, "advertised-routes"))
11951 update_group_show_advertised(bgp, afi, safi, vty,
11952 subgrp_id);
11953 else if (!strcmp(what, "packet-queue"))
11954 update_group_show_packet_queue(bgp, afi, safi, vty,
11955 subgrp_id);
11956 }
11957 }
11958
11959 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
11960 show_ip_bgp_instance_updgrps_adj_s_cmd,
11961 "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",
11962 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11963 BGP_SAFI_HELP_STR
11964 "Detailed info about dynamic update groups\n"
11965 "Specific subgroup to display info for\n"
11966 "Advertisement queue\n"
11967 "Announced routes\n"
11968 "Packet queue\n")
11969 {
11970 uint64_t subgrp_id = 0;
11971 afi_t afiz;
11972 safi_t safiz;
11973 if (sgid)
11974 subgrp_id = strtoull(sgid, NULL, 10);
11975
11976 if (!ip && !afi)
11977 afiz = AFI_IP6;
11978 if (!ip && afi)
11979 afiz = bgp_vty_afi_from_str(afi);
11980 if (ip && !afi)
11981 afiz = AFI_IP;
11982 if (ip && afi) {
11983 afiz = bgp_vty_afi_from_str(afi);
11984 if (afiz != AFI_IP)
11985 vty_out(vty,
11986 "%% Cannot specify both 'ip' and 'ipv6'\n");
11987 return CMD_WARNING;
11988 }
11989
11990 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
11991
11992 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
11993 return CMD_SUCCESS;
11994 }
11995
11996 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
11997 {
11998 struct listnode *node, *nnode;
11999 struct prefix *range;
12000 struct peer *conf;
12001 struct peer *peer;
12002 char buf[PREFIX2STR_BUFFER];
12003 afi_t afi;
12004 safi_t safi;
12005 const char *peer_status;
12006 const char *af_str;
12007 int lr_count;
12008 int dynamic;
12009 int af_cfgd;
12010
12011 conf = group->conf;
12012
12013 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
12014 vty_out(vty, "\nBGP peer-group %s, remote AS %" PRIu32 "\n",
12015 group->name, conf->as);
12016 } else if (conf->as_type == AS_INTERNAL) {
12017 vty_out(vty, "\nBGP peer-group %s, remote AS %" PRIu32 "\n",
12018 group->name, group->bgp->as);
12019 } else {
12020 vty_out(vty, "\nBGP peer-group %s\n", group->name);
12021 }
12022
12023 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
12024 vty_out(vty, " Peer-group type is internal\n");
12025 else
12026 vty_out(vty, " Peer-group type is external\n");
12027
12028 /* Display AFs configured. */
12029 vty_out(vty, " Configured address-families:");
12030 FOREACH_AFI_SAFI (afi, safi) {
12031 if (conf->afc[afi][safi]) {
12032 af_cfgd = 1;
12033 vty_out(vty, " %s;", get_afi_safi_str(afi, safi, false));
12034 }
12035 }
12036 if (!af_cfgd)
12037 vty_out(vty, " none\n");
12038 else
12039 vty_out(vty, "\n");
12040
12041 /* Display listen ranges (for dynamic neighbors), if any */
12042 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
12043 if (afi == AFI_IP)
12044 af_str = "IPv4";
12045 else if (afi == AFI_IP6)
12046 af_str = "IPv6";
12047 else
12048 af_str = "???";
12049 lr_count = listcount(group->listen_range[afi]);
12050 if (lr_count) {
12051 vty_out(vty, " %d %s listen range(s)\n", lr_count,
12052 af_str);
12053
12054
12055 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
12056 nnode, range)) {
12057 prefix2str(range, buf, sizeof(buf));
12058 vty_out(vty, " %s\n", buf);
12059 }
12060 }
12061 }
12062
12063 /* Display group members and their status */
12064 if (listcount(group->peer)) {
12065 vty_out(vty, " Peer-group members:\n");
12066 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
12067 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
12068 peer_status = "Idle (Admin)";
12069 else if (CHECK_FLAG(peer->sflags,
12070 PEER_STATUS_PREFIX_OVERFLOW))
12071 peer_status = "Idle (PfxCt)";
12072 else
12073 peer_status = lookup_msg(bgp_status_msg,
12074 peer->status, NULL);
12075
12076 dynamic = peer_dynamic_neighbor(peer);
12077 vty_out(vty, " %s %s %s \n", peer->host,
12078 dynamic ? "(dynamic)" : "", peer_status);
12079 }
12080 }
12081
12082 return CMD_SUCCESS;
12083 }
12084
12085 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
12086 const char *group_name)
12087 {
12088 struct bgp *bgp;
12089 struct listnode *node, *nnode;
12090 struct peer_group *group;
12091 bool found = false;
12092
12093 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
12094
12095 if (!bgp) {
12096 vty_out(vty, "%% BGP instance not found\n");
12097 return CMD_WARNING;
12098 }
12099
12100 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
12101 if (group_name) {
12102 if (strmatch(group->name, group_name)) {
12103 bgp_show_one_peer_group(vty, group);
12104 found = true;
12105 break;
12106 }
12107 } else {
12108 bgp_show_one_peer_group(vty, group);
12109 }
12110 }
12111
12112 if (group_name && !found)
12113 vty_out(vty, "%% No such peer-group\n");
12114
12115 return CMD_SUCCESS;
12116 }
12117
12118 DEFUN (show_ip_bgp_peer_groups,
12119 show_ip_bgp_peer_groups_cmd,
12120 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
12121 SHOW_STR
12122 IP_STR
12123 BGP_STR
12124 BGP_INSTANCE_HELP_STR
12125 "Detailed information on BGP peer groups\n"
12126 "Peer group name\n")
12127 {
12128 char *vrf, *pg;
12129 int idx = 0;
12130
12131 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
12132 : NULL;
12133 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
12134
12135 return bgp_show_peer_group_vty(vty, vrf, pg);
12136 }
12137
12138
12139 /* Redistribute VTY commands. */
12140
12141 DEFUN (bgp_redistribute_ipv4,
12142 bgp_redistribute_ipv4_cmd,
12143 "redistribute " FRR_IP_REDIST_STR_BGPD,
12144 "Redistribute information from another routing protocol\n"
12145 FRR_IP_REDIST_HELP_STR_BGPD)
12146 {
12147 VTY_DECLVAR_CONTEXT(bgp, bgp);
12148 int idx_protocol = 1;
12149 int type;
12150
12151 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12152 if (type < 0) {
12153 vty_out(vty, "%% Invalid route type\n");
12154 return CMD_WARNING_CONFIG_FAILED;
12155 }
12156
12157 bgp_redist_add(bgp, AFI_IP, type, 0);
12158 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
12159 }
12160
12161 ALIAS_HIDDEN(
12162 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
12163 "redistribute " FRR_IP_REDIST_STR_BGPD,
12164 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
12165
12166 DEFUN (bgp_redistribute_ipv4_rmap,
12167 bgp_redistribute_ipv4_rmap_cmd,
12168 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
12169 "Redistribute information from another routing protocol\n"
12170 FRR_IP_REDIST_HELP_STR_BGPD
12171 "Route map reference\n"
12172 "Pointer to route-map entries\n")
12173 {
12174 VTY_DECLVAR_CONTEXT(bgp, bgp);
12175 int idx_protocol = 1;
12176 int idx_word = 3;
12177 int type;
12178 struct bgp_redist *red;
12179 bool changed;
12180 struct route_map *route_map = route_map_lookup_warn_noexist(
12181 vty, argv[idx_word]->arg);
12182
12183 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12184 if (type < 0) {
12185 vty_out(vty, "%% Invalid route type\n");
12186 return CMD_WARNING_CONFIG_FAILED;
12187 }
12188
12189 red = bgp_redist_add(bgp, AFI_IP, type, 0);
12190 changed =
12191 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12192 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
12193 }
12194
12195 ALIAS_HIDDEN(
12196 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
12197 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
12198 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12199 "Route map reference\n"
12200 "Pointer to route-map entries\n")
12201
12202 DEFUN (bgp_redistribute_ipv4_metric,
12203 bgp_redistribute_ipv4_metric_cmd,
12204 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
12205 "Redistribute information from another routing protocol\n"
12206 FRR_IP_REDIST_HELP_STR_BGPD
12207 "Metric for redistributed routes\n"
12208 "Default metric\n")
12209 {
12210 VTY_DECLVAR_CONTEXT(bgp, bgp);
12211 int idx_protocol = 1;
12212 int idx_number = 3;
12213 int type;
12214 uint32_t metric;
12215 struct bgp_redist *red;
12216 bool changed;
12217
12218 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12219 if (type < 0) {
12220 vty_out(vty, "%% Invalid route type\n");
12221 return CMD_WARNING_CONFIG_FAILED;
12222 }
12223 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12224
12225 red = bgp_redist_add(bgp, AFI_IP, type, 0);
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_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
12232 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
12233 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12234 "Metric for redistributed routes\n"
12235 "Default metric\n")
12236
12237 DEFUN (bgp_redistribute_ipv4_rmap_metric,
12238 bgp_redistribute_ipv4_rmap_metric_cmd,
12239 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
12240 "Redistribute information from another routing protocol\n"
12241 FRR_IP_REDIST_HELP_STR_BGPD
12242 "Route map reference\n"
12243 "Pointer to route-map entries\n"
12244 "Metric for redistributed routes\n"
12245 "Default metric\n")
12246 {
12247 VTY_DECLVAR_CONTEXT(bgp, bgp);
12248 int idx_protocol = 1;
12249 int idx_word = 3;
12250 int idx_number = 5;
12251 int type;
12252 uint32_t metric;
12253 struct bgp_redist *red;
12254 bool changed;
12255 struct route_map *route_map =
12256 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12257
12258 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12259 if (type < 0) {
12260 vty_out(vty, "%% Invalid route type\n");
12261 return CMD_WARNING_CONFIG_FAILED;
12262 }
12263 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12264
12265 red = bgp_redist_add(bgp, AFI_IP, type, 0);
12266 changed =
12267 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12268 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
12269 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
12270 }
12271
12272 ALIAS_HIDDEN(
12273 bgp_redistribute_ipv4_rmap_metric,
12274 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
12275 "redistribute " FRR_IP_REDIST_STR_BGPD
12276 " route-map WORD metric (0-4294967295)",
12277 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12278 "Route map reference\n"
12279 "Pointer to route-map entries\n"
12280 "Metric for redistributed routes\n"
12281 "Default metric\n")
12282
12283 DEFUN (bgp_redistribute_ipv4_metric_rmap,
12284 bgp_redistribute_ipv4_metric_rmap_cmd,
12285 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
12286 "Redistribute information from another routing protocol\n"
12287 FRR_IP_REDIST_HELP_STR_BGPD
12288 "Metric for redistributed routes\n"
12289 "Default metric\n"
12290 "Route map reference\n"
12291 "Pointer to route-map entries\n")
12292 {
12293 VTY_DECLVAR_CONTEXT(bgp, bgp);
12294 int idx_protocol = 1;
12295 int idx_number = 3;
12296 int idx_word = 5;
12297 int type;
12298 uint32_t metric;
12299 struct bgp_redist *red;
12300 bool changed;
12301 struct route_map *route_map =
12302 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12303
12304 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12305 if (type < 0) {
12306 vty_out(vty, "%% Invalid route type\n");
12307 return CMD_WARNING_CONFIG_FAILED;
12308 }
12309 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12310
12311 red = bgp_redist_add(bgp, AFI_IP, type, 0);
12312 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
12313 changed |=
12314 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12315 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
12316 }
12317
12318 ALIAS_HIDDEN(
12319 bgp_redistribute_ipv4_metric_rmap,
12320 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
12321 "redistribute " FRR_IP_REDIST_STR_BGPD
12322 " metric (0-4294967295) route-map WORD",
12323 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12324 "Metric for redistributed routes\n"
12325 "Default metric\n"
12326 "Route map reference\n"
12327 "Pointer to route-map entries\n")
12328
12329 DEFUN (bgp_redistribute_ipv4_ospf,
12330 bgp_redistribute_ipv4_ospf_cmd,
12331 "redistribute <ospf|table> (1-65535)",
12332 "Redistribute information from another routing protocol\n"
12333 "Open Shortest Path First (OSPFv2)\n"
12334 "Non-main Kernel Routing Table\n"
12335 "Instance ID/Table ID\n")
12336 {
12337 VTY_DECLVAR_CONTEXT(bgp, bgp);
12338 int idx_ospf_table = 1;
12339 int idx_number = 2;
12340 unsigned short instance;
12341 unsigned short protocol;
12342
12343 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12344
12345 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12346 protocol = ZEBRA_ROUTE_OSPF;
12347 else
12348 protocol = ZEBRA_ROUTE_TABLE;
12349
12350 bgp_redist_add(bgp, AFI_IP, protocol, instance);
12351 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
12352 }
12353
12354 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
12355 "redistribute <ospf|table> (1-65535)",
12356 "Redistribute information from another routing protocol\n"
12357 "Open Shortest Path First (OSPFv2)\n"
12358 "Non-main Kernel Routing Table\n"
12359 "Instance ID/Table ID\n")
12360
12361 DEFUN (bgp_redistribute_ipv4_ospf_rmap,
12362 bgp_redistribute_ipv4_ospf_rmap_cmd,
12363 "redistribute <ospf|table> (1-65535) route-map WORD",
12364 "Redistribute information from another routing protocol\n"
12365 "Open Shortest Path First (OSPFv2)\n"
12366 "Non-main Kernel Routing Table\n"
12367 "Instance ID/Table ID\n"
12368 "Route map reference\n"
12369 "Pointer to route-map entries\n")
12370 {
12371 VTY_DECLVAR_CONTEXT(bgp, bgp);
12372 int idx_ospf_table = 1;
12373 int idx_number = 2;
12374 int idx_word = 4;
12375 struct bgp_redist *red;
12376 unsigned short instance;
12377 int protocol;
12378 bool changed;
12379 struct route_map *route_map =
12380 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
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 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12389 changed =
12390 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12391 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12392 }
12393
12394 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
12395 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
12396 "redistribute <ospf|table> (1-65535) route-map WORD",
12397 "Redistribute information from another routing protocol\n"
12398 "Open Shortest Path First (OSPFv2)\n"
12399 "Non-main Kernel Routing Table\n"
12400 "Instance ID/Table ID\n"
12401 "Route map reference\n"
12402 "Pointer to route-map entries\n")
12403
12404 DEFUN (bgp_redistribute_ipv4_ospf_metric,
12405 bgp_redistribute_ipv4_ospf_metric_cmd,
12406 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
12407 "Redistribute information from another routing protocol\n"
12408 "Open Shortest Path First (OSPFv2)\n"
12409 "Non-main Kernel Routing Table\n"
12410 "Instance ID/Table ID\n"
12411 "Metric for redistributed routes\n"
12412 "Default metric\n")
12413 {
12414 VTY_DECLVAR_CONTEXT(bgp, bgp);
12415 int idx_ospf_table = 1;
12416 int idx_number = 2;
12417 int idx_number_2 = 4;
12418 uint32_t metric;
12419 struct bgp_redist *red;
12420 unsigned short instance;
12421 int protocol;
12422 bool changed;
12423
12424 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12425 protocol = ZEBRA_ROUTE_OSPF;
12426 else
12427 protocol = ZEBRA_ROUTE_TABLE;
12428
12429 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12430 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12431
12432 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12433 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12434 metric);
12435 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12436 }
12437
12438 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
12439 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
12440 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
12441 "Redistribute information from another routing protocol\n"
12442 "Open Shortest Path First (OSPFv2)\n"
12443 "Non-main Kernel Routing Table\n"
12444 "Instance ID/Table ID\n"
12445 "Metric for redistributed routes\n"
12446 "Default metric\n")
12447
12448 DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
12449 bgp_redistribute_ipv4_ospf_rmap_metric_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 VTY_DECLVAR_CONTEXT(bgp, bgp);
12461 int idx_ospf_table = 1;
12462 int idx_number = 2;
12463 int idx_word = 4;
12464 int idx_number_2 = 6;
12465 uint32_t metric;
12466 struct bgp_redist *red;
12467 unsigned short instance;
12468 int protocol;
12469 bool changed;
12470 struct route_map *route_map =
12471 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12472
12473 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12474 protocol = ZEBRA_ROUTE_OSPF;
12475 else
12476 protocol = ZEBRA_ROUTE_TABLE;
12477
12478 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12479 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12480
12481 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12482 changed =
12483 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12484 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12485 metric);
12486 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12487 }
12488
12489 ALIAS_HIDDEN(
12490 bgp_redistribute_ipv4_ospf_rmap_metric,
12491 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
12492 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
12493 "Redistribute information from another routing protocol\n"
12494 "Open Shortest Path First (OSPFv2)\n"
12495 "Non-main Kernel Routing Table\n"
12496 "Instance ID/Table ID\n"
12497 "Route map reference\n"
12498 "Pointer to route-map entries\n"
12499 "Metric for redistributed routes\n"
12500 "Default metric\n")
12501
12502 DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
12503 bgp_redistribute_ipv4_ospf_metric_rmap_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 VTY_DECLVAR_CONTEXT(bgp, bgp);
12515 int idx_ospf_table = 1;
12516 int idx_number = 2;
12517 int idx_number_2 = 4;
12518 int idx_word = 6;
12519 uint32_t metric;
12520 struct bgp_redist *red;
12521 unsigned short instance;
12522 int protocol;
12523 bool changed;
12524 struct route_map *route_map =
12525 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12526
12527 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12528 protocol = ZEBRA_ROUTE_OSPF;
12529 else
12530 protocol = ZEBRA_ROUTE_TABLE;
12531
12532 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12533 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12534
12535 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12536 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12537 metric);
12538 changed |=
12539 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12540 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12541 }
12542
12543 ALIAS_HIDDEN(
12544 bgp_redistribute_ipv4_ospf_metric_rmap,
12545 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
12546 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
12547 "Redistribute information from another routing protocol\n"
12548 "Open Shortest Path First (OSPFv2)\n"
12549 "Non-main Kernel Routing Table\n"
12550 "Instance ID/Table ID\n"
12551 "Metric for redistributed routes\n"
12552 "Default metric\n"
12553 "Route map reference\n"
12554 "Pointer to route-map entries\n")
12555
12556 DEFUN (no_bgp_redistribute_ipv4_ospf,
12557 no_bgp_redistribute_ipv4_ospf_cmd,
12558 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
12559 NO_STR
12560 "Redistribute information from another routing protocol\n"
12561 "Open Shortest Path First (OSPFv2)\n"
12562 "Non-main Kernel Routing Table\n"
12563 "Instance ID/Table ID\n"
12564 "Metric for redistributed routes\n"
12565 "Default metric\n"
12566 "Route map reference\n"
12567 "Pointer to route-map entries\n")
12568 {
12569 VTY_DECLVAR_CONTEXT(bgp, bgp);
12570 int idx_ospf_table = 2;
12571 int idx_number = 3;
12572 unsigned short instance;
12573 int protocol;
12574
12575 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12576 protocol = ZEBRA_ROUTE_OSPF;
12577 else
12578 protocol = ZEBRA_ROUTE_TABLE;
12579
12580 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12581 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
12582 }
12583
12584 ALIAS_HIDDEN(
12585 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
12586 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
12587 NO_STR
12588 "Redistribute information from another routing protocol\n"
12589 "Open Shortest Path First (OSPFv2)\n"
12590 "Non-main Kernel Routing Table\n"
12591 "Instance ID/Table ID\n"
12592 "Metric for redistributed routes\n"
12593 "Default metric\n"
12594 "Route map reference\n"
12595 "Pointer to route-map entries\n")
12596
12597 DEFUN (no_bgp_redistribute_ipv4,
12598 no_bgp_redistribute_ipv4_cmd,
12599 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
12600 NO_STR
12601 "Redistribute information from another routing protocol\n"
12602 FRR_IP_REDIST_HELP_STR_BGPD
12603 "Metric for redistributed routes\n"
12604 "Default metric\n"
12605 "Route map reference\n"
12606 "Pointer to route-map entries\n")
12607 {
12608 VTY_DECLVAR_CONTEXT(bgp, bgp);
12609 int idx_protocol = 2;
12610 int type;
12611
12612 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12613 if (type < 0) {
12614 vty_out(vty, "%% Invalid route type\n");
12615 return CMD_WARNING_CONFIG_FAILED;
12616 }
12617 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
12618 }
12619
12620 ALIAS_HIDDEN(
12621 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
12622 "no redistribute " FRR_IP_REDIST_STR_BGPD
12623 " [{metric (0-4294967295)|route-map WORD}]",
12624 NO_STR
12625 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12626 "Metric for redistributed routes\n"
12627 "Default metric\n"
12628 "Route map reference\n"
12629 "Pointer to route-map entries\n")
12630
12631 DEFUN (bgp_redistribute_ipv6,
12632 bgp_redistribute_ipv6_cmd,
12633 "redistribute " FRR_IP6_REDIST_STR_BGPD,
12634 "Redistribute information from another routing protocol\n"
12635 FRR_IP6_REDIST_HELP_STR_BGPD)
12636 {
12637 VTY_DECLVAR_CONTEXT(bgp, bgp);
12638 int idx_protocol = 1;
12639 int type;
12640
12641 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12642 if (type < 0) {
12643 vty_out(vty, "%% Invalid route type\n");
12644 return CMD_WARNING_CONFIG_FAILED;
12645 }
12646
12647 bgp_redist_add(bgp, AFI_IP6, type, 0);
12648 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
12649 }
12650
12651 DEFUN (bgp_redistribute_ipv6_rmap,
12652 bgp_redistribute_ipv6_rmap_cmd,
12653 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
12654 "Redistribute information from another routing protocol\n"
12655 FRR_IP6_REDIST_HELP_STR_BGPD
12656 "Route map reference\n"
12657 "Pointer to route-map entries\n")
12658 {
12659 VTY_DECLVAR_CONTEXT(bgp, bgp);
12660 int idx_protocol = 1;
12661 int idx_word = 3;
12662 int type;
12663 struct bgp_redist *red;
12664 bool changed;
12665 struct route_map *route_map =
12666 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12667
12668 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12669 if (type < 0) {
12670 vty_out(vty, "%% Invalid route type\n");
12671 return CMD_WARNING_CONFIG_FAILED;
12672 }
12673
12674 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12675 changed =
12676 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12677 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12678 }
12679
12680 DEFUN (bgp_redistribute_ipv6_metric,
12681 bgp_redistribute_ipv6_metric_cmd,
12682 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
12683 "Redistribute information from another routing protocol\n"
12684 FRR_IP6_REDIST_HELP_STR_BGPD
12685 "Metric for redistributed routes\n"
12686 "Default metric\n")
12687 {
12688 VTY_DECLVAR_CONTEXT(bgp, bgp);
12689 int idx_protocol = 1;
12690 int idx_number = 3;
12691 int type;
12692 uint32_t metric;
12693 struct bgp_redist *red;
12694 bool changed;
12695
12696 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12697 if (type < 0) {
12698 vty_out(vty, "%% Invalid route type\n");
12699 return CMD_WARNING_CONFIG_FAILED;
12700 }
12701 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12702
12703 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12704 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
12705 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12706 }
12707
12708 DEFUN (bgp_redistribute_ipv6_rmap_metric,
12709 bgp_redistribute_ipv6_rmap_metric_cmd,
12710 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
12711 "Redistribute information from another routing protocol\n"
12712 FRR_IP6_REDIST_HELP_STR_BGPD
12713 "Route map reference\n"
12714 "Pointer to route-map entries\n"
12715 "Metric for redistributed routes\n"
12716 "Default metric\n")
12717 {
12718 VTY_DECLVAR_CONTEXT(bgp, bgp);
12719 int idx_protocol = 1;
12720 int idx_word = 3;
12721 int idx_number = 5;
12722 int type;
12723 uint32_t metric;
12724 struct bgp_redist *red;
12725 bool changed;
12726 struct route_map *route_map =
12727 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12728
12729 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12730 if (type < 0) {
12731 vty_out(vty, "%% Invalid route type\n");
12732 return CMD_WARNING_CONFIG_FAILED;
12733 }
12734 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12735
12736 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12737 changed =
12738 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12739 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
12740 metric);
12741 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12742 }
12743
12744 DEFUN (bgp_redistribute_ipv6_metric_rmap,
12745 bgp_redistribute_ipv6_metric_rmap_cmd,
12746 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
12747 "Redistribute information from another routing protocol\n"
12748 FRR_IP6_REDIST_HELP_STR_BGPD
12749 "Metric for redistributed routes\n"
12750 "Default metric\n"
12751 "Route map reference\n"
12752 "Pointer to route-map entries\n")
12753 {
12754 VTY_DECLVAR_CONTEXT(bgp, bgp);
12755 int idx_protocol = 1;
12756 int idx_number = 3;
12757 int idx_word = 5;
12758 int type;
12759 uint32_t metric;
12760 struct bgp_redist *red;
12761 bool changed;
12762 struct route_map *route_map =
12763 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12764
12765 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12766 if (type < 0) {
12767 vty_out(vty, "%% Invalid route type\n");
12768 return CMD_WARNING_CONFIG_FAILED;
12769 }
12770 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12771
12772 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12773 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
12774 metric);
12775 changed |=
12776 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12777 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12778 }
12779
12780 DEFUN (no_bgp_redistribute_ipv6,
12781 no_bgp_redistribute_ipv6_cmd,
12782 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
12783 NO_STR
12784 "Redistribute information from another routing protocol\n"
12785 FRR_IP6_REDIST_HELP_STR_BGPD
12786 "Metric for redistributed routes\n"
12787 "Default metric\n"
12788 "Route map reference\n"
12789 "Pointer to route-map entries\n")
12790 {
12791 VTY_DECLVAR_CONTEXT(bgp, bgp);
12792 int idx_protocol = 2;
12793 int type;
12794
12795 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12796 if (type < 0) {
12797 vty_out(vty, "%% Invalid route type\n");
12798 return CMD_WARNING_CONFIG_FAILED;
12799 }
12800
12801 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
12802 }
12803
12804 void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp, afi_t afi,
12805 safi_t safi)
12806 {
12807 int i;
12808
12809 /* Unicast redistribution only. */
12810 if (safi != SAFI_UNICAST)
12811 return;
12812
12813 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
12814 /* Redistribute BGP does not make sense. */
12815 if (i != ZEBRA_ROUTE_BGP) {
12816 struct list *red_list;
12817 struct listnode *node;
12818 struct bgp_redist *red;
12819
12820 red_list = bgp->redist[afi][i];
12821 if (!red_list)
12822 continue;
12823
12824 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
12825 /* "redistribute" configuration. */
12826 vty_out(vty, " redistribute %s",
12827 zebra_route_string(i));
12828 if (red->instance)
12829 vty_out(vty, " %d", red->instance);
12830 if (red->redist_metric_flag)
12831 vty_out(vty, " metric %u",
12832 red->redist_metric);
12833 if (red->rmap.name)
12834 vty_out(vty, " route-map %s",
12835 red->rmap.name);
12836 vty_out(vty, "\n");
12837 }
12838 }
12839 }
12840 }
12841
12842 /* This is part of the address-family block (unicast only) */
12843 void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
12844 afi_t afi)
12845 {
12846 int indent = 2;
12847
12848 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
12849 if (listcount(bgp->vpn_policy[afi].import_vrf))
12850 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
12851 bgp->vpn_policy[afi]
12852 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12853 else
12854 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
12855 bgp->vpn_policy[afi]
12856 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12857 }
12858 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12859 BGP_CONFIG_VRF_TO_VRF_IMPORT)
12860 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12861 BGP_CONFIG_VRF_TO_VRF_EXPORT))
12862 return;
12863
12864 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12865 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
12866
12867 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
12868
12869 } else {
12870 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
12871 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
12872 bgp->vpn_policy[afi].tovpn_label);
12873 }
12874 }
12875 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12876 BGP_VPN_POLICY_TOVPN_RD_SET)) {
12877 char buf[RD_ADDRSTRLEN];
12878 vty_out(vty, "%*srd vpn export %s\n", indent, "",
12879 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
12880 sizeof(buf)));
12881 }
12882 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12883 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
12884
12885 char buf[PREFIX_STRLEN];
12886 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
12887 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
12888 sizeof(buf))) {
12889
12890 vty_out(vty, "%*snexthop vpn export %s\n",
12891 indent, "", buf);
12892 }
12893 }
12894 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
12895 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
12896 && ecommunity_cmp(
12897 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12898 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
12899
12900 char *b = ecommunity_ecom2str(
12901 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12902 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
12903 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
12904 XFREE(MTYPE_ECOMMUNITY_STR, b);
12905 } else {
12906 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
12907 char *b = ecommunity_ecom2str(
12908 bgp->vpn_policy[afi]
12909 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12910 ECOMMUNITY_FORMAT_ROUTE_MAP,
12911 ECOMMUNITY_ROUTE_TARGET);
12912 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
12913 XFREE(MTYPE_ECOMMUNITY_STR, b);
12914 }
12915 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
12916 char *b = ecommunity_ecom2str(
12917 bgp->vpn_policy[afi]
12918 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12919 ECOMMUNITY_FORMAT_ROUTE_MAP,
12920 ECOMMUNITY_ROUTE_TARGET);
12921 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
12922 XFREE(MTYPE_ECOMMUNITY_STR, b);
12923 }
12924 }
12925
12926 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
12927 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
12928 bgp->vpn_policy[afi]
12929 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
12930
12931 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
12932 char *b = ecommunity_ecom2str(
12933 bgp->vpn_policy[afi]
12934 .import_redirect_rtlist,
12935 ECOMMUNITY_FORMAT_ROUTE_MAP,
12936 ECOMMUNITY_ROUTE_TARGET);
12937
12938 vty_out(vty, "%*srt redirect import %s\n", indent, "", b);
12939 XFREE(MTYPE_ECOMMUNITY_STR, b);
12940 }
12941 }
12942
12943
12944 /* BGP node structure. */
12945 static struct cmd_node bgp_node = {
12946 BGP_NODE, "%s(config-router)# ", 1,
12947 };
12948
12949 static struct cmd_node bgp_ipv4_unicast_node = {
12950 BGP_IPV4_NODE, "%s(config-router-af)# ", 1,
12951 };
12952
12953 static struct cmd_node bgp_ipv4_multicast_node = {
12954 BGP_IPV4M_NODE, "%s(config-router-af)# ", 1,
12955 };
12956
12957 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
12958 BGP_IPV4L_NODE, "%s(config-router-af)# ", 1,
12959 };
12960
12961 static struct cmd_node bgp_ipv6_unicast_node = {
12962 BGP_IPV6_NODE, "%s(config-router-af)# ", 1,
12963 };
12964
12965 static struct cmd_node bgp_ipv6_multicast_node = {
12966 BGP_IPV6M_NODE, "%s(config-router-af)# ", 1,
12967 };
12968
12969 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
12970 BGP_IPV6L_NODE, "%s(config-router-af)# ", 1,
12971 };
12972
12973 static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
12974 "%s(config-router-af)# ", 1};
12975
12976 static struct cmd_node bgp_vpnv6_node = {BGP_VPNV6_NODE,
12977 "%s(config-router-af-vpnv6)# ", 1};
12978
12979 static struct cmd_node bgp_evpn_node = {BGP_EVPN_NODE,
12980 "%s(config-router-evpn)# ", 1};
12981
12982 static struct cmd_node bgp_evpn_vni_node = {BGP_EVPN_VNI_NODE,
12983 "%s(config-router-af-vni)# ", 1};
12984
12985 static struct cmd_node bgp_flowspecv4_node = {BGP_FLOWSPECV4_NODE,
12986 "%s(config-router-af)# ", 1};
12987
12988 static struct cmd_node bgp_flowspecv6_node = {BGP_FLOWSPECV6_NODE,
12989 "%s(config-router-af-vpnv6)# ", 1};
12990
12991 static void community_list_vty(void);
12992
12993 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
12994 {
12995 struct bgp *bgp;
12996 struct peer *peer;
12997 struct listnode *lnbgp, *lnpeer;
12998
12999 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
13000 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
13001 /* only provide suggestions on the appropriate input
13002 * token type,
13003 * they'll otherwise show up multiple times */
13004 enum cmd_token_type match_type;
13005 char *name = peer->host;
13006
13007 if (peer->conf_if) {
13008 match_type = VARIABLE_TKN;
13009 name = peer->conf_if;
13010 } else if (strchr(peer->host, ':'))
13011 match_type = IPV6_TKN;
13012 else
13013 match_type = IPV4_TKN;
13014
13015 if (token->type != match_type)
13016 continue;
13017
13018 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
13019 }
13020 }
13021 }
13022
13023 static const struct cmd_variable_handler bgp_var_neighbor[] = {
13024 {.varname = "neighbor", .completions = bgp_ac_neighbor},
13025 {.varname = "neighbors", .completions = bgp_ac_neighbor},
13026 {.varname = "peer", .completions = bgp_ac_neighbor},
13027 {.completions = NULL}};
13028
13029 static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
13030 {
13031 struct bgp *bgp;
13032 struct peer_group *group;
13033 struct listnode *lnbgp, *lnpeer;
13034
13035 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
13036 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
13037 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
13038 group->name));
13039 }
13040 }
13041
13042 static const struct cmd_variable_handler bgp_var_peergroup[] = {
13043 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
13044 {.completions = NULL} };
13045
13046 void bgp_vty_init(void)
13047 {
13048 cmd_variable_handler_register(bgp_var_neighbor);
13049 cmd_variable_handler_register(bgp_var_peergroup);
13050
13051 /* Install bgp top node. */
13052 install_node(&bgp_node, bgp_config_write);
13053 install_node(&bgp_ipv4_unicast_node, NULL);
13054 install_node(&bgp_ipv4_multicast_node, NULL);
13055 install_node(&bgp_ipv4_labeled_unicast_node, NULL);
13056 install_node(&bgp_ipv6_unicast_node, NULL);
13057 install_node(&bgp_ipv6_multicast_node, NULL);
13058 install_node(&bgp_ipv6_labeled_unicast_node, NULL);
13059 install_node(&bgp_vpnv4_node, NULL);
13060 install_node(&bgp_vpnv6_node, NULL);
13061 install_node(&bgp_evpn_node, NULL);
13062 install_node(&bgp_evpn_vni_node, NULL);
13063 install_node(&bgp_flowspecv4_node, NULL);
13064 install_node(&bgp_flowspecv6_node, NULL);
13065
13066 /* Install default VTY commands to new nodes. */
13067 install_default(BGP_NODE);
13068 install_default(BGP_IPV4_NODE);
13069 install_default(BGP_IPV4M_NODE);
13070 install_default(BGP_IPV4L_NODE);
13071 install_default(BGP_IPV6_NODE);
13072 install_default(BGP_IPV6M_NODE);
13073 install_default(BGP_IPV6L_NODE);
13074 install_default(BGP_VPNV4_NODE);
13075 install_default(BGP_VPNV6_NODE);
13076 install_default(BGP_FLOWSPECV4_NODE);
13077 install_default(BGP_FLOWSPECV6_NODE);
13078 install_default(BGP_EVPN_NODE);
13079 install_default(BGP_EVPN_VNI_NODE);
13080
13081 /* "bgp local-mac" hidden commands. */
13082 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
13083 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
13084
13085 /* bgp route-map delay-timer commands. */
13086 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
13087 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
13088
13089 /* Dummy commands (Currently not supported) */
13090 install_element(BGP_NODE, &no_synchronization_cmd);
13091 install_element(BGP_NODE, &no_auto_summary_cmd);
13092
13093 /* "router bgp" commands. */
13094 install_element(CONFIG_NODE, &router_bgp_cmd);
13095
13096 /* "no router bgp" commands. */
13097 install_element(CONFIG_NODE, &no_router_bgp_cmd);
13098
13099 /* "bgp router-id" commands. */
13100 install_element(BGP_NODE, &bgp_router_id_cmd);
13101 install_element(BGP_NODE, &no_bgp_router_id_cmd);
13102
13103 /* "bgp cluster-id" commands. */
13104 install_element(BGP_NODE, &bgp_cluster_id_cmd);
13105 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
13106
13107 /* "bgp confederation" commands. */
13108 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
13109 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
13110
13111 /* "bgp confederation peers" commands. */
13112 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
13113 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
13114
13115 /* bgp max-med command */
13116 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
13117 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
13118 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
13119 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
13120 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
13121
13122 /* bgp disable-ebgp-connected-nh-check */
13123 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
13124 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
13125
13126 /* bgp update-delay command */
13127 install_element(BGP_NODE, &bgp_update_delay_cmd);
13128 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
13129 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
13130
13131 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
13132 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
13133
13134 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
13135 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
13136
13137 /* "maximum-paths" commands. */
13138 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
13139 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
13140 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
13141 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
13142 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
13143 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
13144 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
13145 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
13146 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
13147 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
13148 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
13149 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
13150 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
13151 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
13152 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
13153
13154 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
13155 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
13156 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
13157 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
13158 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
13159
13160 /* "timers bgp" commands. */
13161 install_element(BGP_NODE, &bgp_timers_cmd);
13162 install_element(BGP_NODE, &no_bgp_timers_cmd);
13163
13164 /* route-map delay-timer commands - per instance for backwards compat.
13165 */
13166 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
13167 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
13168
13169 /* "bgp client-to-client reflection" commands */
13170 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
13171 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
13172
13173 /* "bgp always-compare-med" commands */
13174 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
13175 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
13176
13177 /* bgp ebgp-requires-policy */
13178 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
13179 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
13180
13181 /* bgp reject-as-sets */
13182 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
13183 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
13184
13185 /* "bgp deterministic-med" commands */
13186 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
13187 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
13188
13189 /* "bgp graceful-restart" commands */
13190 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
13191 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
13192 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
13193 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
13194 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
13195 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
13196
13197 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
13198 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
13199
13200 /* "bgp graceful-shutdown" commands */
13201 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
13202 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
13203
13204 /* "bgp fast-external-failover" commands */
13205 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
13206 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
13207
13208 /* "bgp bestpath compare-routerid" commands */
13209 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
13210 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
13211
13212 /* "bgp bestpath as-path ignore" commands */
13213 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
13214 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
13215
13216 /* "bgp bestpath as-path confed" commands */
13217 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
13218 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
13219
13220 /* "bgp bestpath as-path multipath-relax" commands */
13221 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
13222 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
13223
13224 /* "bgp log-neighbor-changes" commands */
13225 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
13226 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
13227
13228 /* "bgp bestpath med" commands */
13229 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
13230 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
13231
13232 /* "no bgp default ipv4-unicast" commands. */
13233 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
13234 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
13235
13236 /* "bgp network import-check" commands. */
13237 install_element(BGP_NODE, &bgp_network_import_check_cmd);
13238 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
13239 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
13240
13241 /* "bgp default local-preference" commands. */
13242 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
13243 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
13244
13245 /* bgp default show-hostname */
13246 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
13247 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
13248
13249 /* "bgp default subgroup-pkt-queue-max" commands. */
13250 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
13251 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
13252
13253 /* bgp ibgp-allow-policy-mods command */
13254 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
13255 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
13256
13257 /* "bgp listen limit" commands. */
13258 install_element(BGP_NODE, &bgp_listen_limit_cmd);
13259 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
13260
13261 /* "bgp listen range" commands. */
13262 install_element(BGP_NODE, &bgp_listen_range_cmd);
13263 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
13264
13265 /* "bgp default shutdown" command */
13266 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
13267
13268 /* "neighbor remote-as" commands. */
13269 install_element(BGP_NODE, &neighbor_remote_as_cmd);
13270 install_element(BGP_NODE, &neighbor_interface_config_cmd);
13271 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
13272 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
13273 install_element(BGP_NODE,
13274 &neighbor_interface_v6only_config_remote_as_cmd);
13275 install_element(BGP_NODE, &no_neighbor_cmd);
13276 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
13277
13278 /* "neighbor peer-group" commands. */
13279 install_element(BGP_NODE, &neighbor_peer_group_cmd);
13280 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
13281 install_element(BGP_NODE,
13282 &no_neighbor_interface_peer_group_remote_as_cmd);
13283
13284 /* "neighbor local-as" commands. */
13285 install_element(BGP_NODE, &neighbor_local_as_cmd);
13286 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
13287 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
13288 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
13289
13290 /* "neighbor solo" commands. */
13291 install_element(BGP_NODE, &neighbor_solo_cmd);
13292 install_element(BGP_NODE, &no_neighbor_solo_cmd);
13293
13294 /* "neighbor password" commands. */
13295 install_element(BGP_NODE, &neighbor_password_cmd);
13296 install_element(BGP_NODE, &no_neighbor_password_cmd);
13297
13298 /* "neighbor activate" commands. */
13299 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
13300 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
13301 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
13302 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
13303 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
13304 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
13305 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
13306 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
13307 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
13308 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
13309 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
13310 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
13311
13312 /* "no neighbor activate" commands. */
13313 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
13314 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
13315 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
13316 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
13317 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
13318 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
13319 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
13320 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
13321 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
13322 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
13323 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
13324 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
13325
13326 /* "neighbor peer-group" set commands. */
13327 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
13328 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
13329 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
13330 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
13331 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
13332 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
13333 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
13334 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
13335 install_element(BGP_FLOWSPECV4_NODE,
13336 &neighbor_set_peer_group_hidden_cmd);
13337 install_element(BGP_FLOWSPECV6_NODE,
13338 &neighbor_set_peer_group_hidden_cmd);
13339
13340 /* "no neighbor peer-group unset" commands. */
13341 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
13342 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13343 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13344 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13345 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13346 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13347 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13348 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13349 install_element(BGP_FLOWSPECV4_NODE,
13350 &no_neighbor_set_peer_group_hidden_cmd);
13351 install_element(BGP_FLOWSPECV6_NODE,
13352 &no_neighbor_set_peer_group_hidden_cmd);
13353
13354 /* "neighbor softreconfiguration inbound" commands.*/
13355 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
13356 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
13357 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
13358 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
13359 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
13360 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
13361 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
13362 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
13363 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
13364 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
13365 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
13366 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
13367 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
13368 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
13369 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
13370 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
13371 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
13372 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
13373 install_element(BGP_FLOWSPECV4_NODE,
13374 &neighbor_soft_reconfiguration_cmd);
13375 install_element(BGP_FLOWSPECV4_NODE,
13376 &no_neighbor_soft_reconfiguration_cmd);
13377 install_element(BGP_FLOWSPECV6_NODE,
13378 &neighbor_soft_reconfiguration_cmd);
13379 install_element(BGP_FLOWSPECV6_NODE,
13380 &no_neighbor_soft_reconfiguration_cmd);
13381 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
13382 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
13383
13384 /* "neighbor attribute-unchanged" commands. */
13385 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
13386 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
13387 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
13388 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
13389 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
13390 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
13391 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
13392 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
13393 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
13394 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
13395 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
13396 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
13397 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
13398 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
13399 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
13400 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
13401 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
13402 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
13403
13404 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
13405 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
13406
13407 /* "nexthop-local unchanged" commands */
13408 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
13409 install_element(BGP_IPV6_NODE,
13410 &no_neighbor_nexthop_local_unchanged_cmd);
13411
13412 /* "neighbor next-hop-self" commands. */
13413 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
13414 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
13415 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
13416 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
13417 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
13418 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
13419 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
13420 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
13421 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
13422 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
13423 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
13424 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
13425 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
13426 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
13427 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
13428 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
13429 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
13430 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
13431 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
13432 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
13433
13434 /* "neighbor next-hop-self force" commands. */
13435 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
13436 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
13437 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13438 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
13439 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
13440 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
13441 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13442 install_element(BGP_IPV4_NODE,
13443 &no_neighbor_nexthop_self_all_hidden_cmd);
13444 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
13445 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
13446 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13447 install_element(BGP_IPV4M_NODE,
13448 &no_neighbor_nexthop_self_all_hidden_cmd);
13449 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
13450 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
13451 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13452 install_element(BGP_IPV4L_NODE,
13453 &no_neighbor_nexthop_self_all_hidden_cmd);
13454 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
13455 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
13456 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13457 install_element(BGP_IPV6_NODE,
13458 &no_neighbor_nexthop_self_all_hidden_cmd);
13459 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
13460 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
13461 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13462 install_element(BGP_IPV6M_NODE,
13463 &no_neighbor_nexthop_self_all_hidden_cmd);
13464 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
13465 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
13466 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13467 install_element(BGP_IPV6L_NODE,
13468 &no_neighbor_nexthop_self_all_hidden_cmd);
13469 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
13470 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
13471 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13472 install_element(BGP_VPNV4_NODE,
13473 &no_neighbor_nexthop_self_all_hidden_cmd);
13474 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
13475 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
13476 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13477 install_element(BGP_VPNV6_NODE,
13478 &no_neighbor_nexthop_self_all_hidden_cmd);
13479
13480 /* "neighbor as-override" commands. */
13481 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
13482 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
13483 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
13484 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
13485 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
13486 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
13487 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
13488 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
13489 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
13490 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
13491 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
13492 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
13493 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
13494 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
13495 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
13496 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
13497 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
13498 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
13499
13500 /* "neighbor remove-private-AS" commands. */
13501 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
13502 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
13503 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
13504 install_element(BGP_NODE,
13505 &no_neighbor_remove_private_as_all_hidden_cmd);
13506 install_element(BGP_NODE,
13507 &neighbor_remove_private_as_replace_as_hidden_cmd);
13508 install_element(BGP_NODE,
13509 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
13510 install_element(BGP_NODE,
13511 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
13512 install_element(
13513 BGP_NODE,
13514 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
13515 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
13516 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
13517 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
13518 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
13519 install_element(BGP_IPV4_NODE,
13520 &neighbor_remove_private_as_replace_as_cmd);
13521 install_element(BGP_IPV4_NODE,
13522 &no_neighbor_remove_private_as_replace_as_cmd);
13523 install_element(BGP_IPV4_NODE,
13524 &neighbor_remove_private_as_all_replace_as_cmd);
13525 install_element(BGP_IPV4_NODE,
13526 &no_neighbor_remove_private_as_all_replace_as_cmd);
13527 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
13528 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
13529 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
13530 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
13531 install_element(BGP_IPV4M_NODE,
13532 &neighbor_remove_private_as_replace_as_cmd);
13533 install_element(BGP_IPV4M_NODE,
13534 &no_neighbor_remove_private_as_replace_as_cmd);
13535 install_element(BGP_IPV4M_NODE,
13536 &neighbor_remove_private_as_all_replace_as_cmd);
13537 install_element(BGP_IPV4M_NODE,
13538 &no_neighbor_remove_private_as_all_replace_as_cmd);
13539 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
13540 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
13541 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
13542 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
13543 install_element(BGP_IPV4L_NODE,
13544 &neighbor_remove_private_as_replace_as_cmd);
13545 install_element(BGP_IPV4L_NODE,
13546 &no_neighbor_remove_private_as_replace_as_cmd);
13547 install_element(BGP_IPV4L_NODE,
13548 &neighbor_remove_private_as_all_replace_as_cmd);
13549 install_element(BGP_IPV4L_NODE,
13550 &no_neighbor_remove_private_as_all_replace_as_cmd);
13551 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
13552 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
13553 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
13554 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
13555 install_element(BGP_IPV6_NODE,
13556 &neighbor_remove_private_as_replace_as_cmd);
13557 install_element(BGP_IPV6_NODE,
13558 &no_neighbor_remove_private_as_replace_as_cmd);
13559 install_element(BGP_IPV6_NODE,
13560 &neighbor_remove_private_as_all_replace_as_cmd);
13561 install_element(BGP_IPV6_NODE,
13562 &no_neighbor_remove_private_as_all_replace_as_cmd);
13563 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
13564 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
13565 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
13566 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
13567 install_element(BGP_IPV6M_NODE,
13568 &neighbor_remove_private_as_replace_as_cmd);
13569 install_element(BGP_IPV6M_NODE,
13570 &no_neighbor_remove_private_as_replace_as_cmd);
13571 install_element(BGP_IPV6M_NODE,
13572 &neighbor_remove_private_as_all_replace_as_cmd);
13573 install_element(BGP_IPV6M_NODE,
13574 &no_neighbor_remove_private_as_all_replace_as_cmd);
13575 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
13576 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
13577 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
13578 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
13579 install_element(BGP_IPV6L_NODE,
13580 &neighbor_remove_private_as_replace_as_cmd);
13581 install_element(BGP_IPV6L_NODE,
13582 &no_neighbor_remove_private_as_replace_as_cmd);
13583 install_element(BGP_IPV6L_NODE,
13584 &neighbor_remove_private_as_all_replace_as_cmd);
13585 install_element(BGP_IPV6L_NODE,
13586 &no_neighbor_remove_private_as_all_replace_as_cmd);
13587 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
13588 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
13589 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
13590 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
13591 install_element(BGP_VPNV4_NODE,
13592 &neighbor_remove_private_as_replace_as_cmd);
13593 install_element(BGP_VPNV4_NODE,
13594 &no_neighbor_remove_private_as_replace_as_cmd);
13595 install_element(BGP_VPNV4_NODE,
13596 &neighbor_remove_private_as_all_replace_as_cmd);
13597 install_element(BGP_VPNV4_NODE,
13598 &no_neighbor_remove_private_as_all_replace_as_cmd);
13599 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
13600 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
13601 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
13602 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
13603 install_element(BGP_VPNV6_NODE,
13604 &neighbor_remove_private_as_replace_as_cmd);
13605 install_element(BGP_VPNV6_NODE,
13606 &no_neighbor_remove_private_as_replace_as_cmd);
13607 install_element(BGP_VPNV6_NODE,
13608 &neighbor_remove_private_as_all_replace_as_cmd);
13609 install_element(BGP_VPNV6_NODE,
13610 &no_neighbor_remove_private_as_all_replace_as_cmd);
13611
13612 /* "neighbor send-community" commands.*/
13613 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
13614 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
13615 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
13616 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
13617 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
13618 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
13619 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
13620 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
13621 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
13622 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
13623 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
13624 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
13625 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
13626 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
13627 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
13628 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
13629 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
13630 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
13631 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
13632 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
13633 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
13634 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
13635 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
13636 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
13637 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
13638 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
13639 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
13640 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
13641 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
13642 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
13643 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
13644 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
13645 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
13646 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
13647 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
13648 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
13649
13650 /* "neighbor route-reflector" commands.*/
13651 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
13652 install_element(BGP_NODE,
13653 &no_neighbor_route_reflector_client_hidden_cmd);
13654 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
13655 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
13656 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
13657 install_element(BGP_IPV4M_NODE,
13658 &no_neighbor_route_reflector_client_cmd);
13659 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
13660 install_element(BGP_IPV4L_NODE,
13661 &no_neighbor_route_reflector_client_cmd);
13662 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
13663 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
13664 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
13665 install_element(BGP_IPV6M_NODE,
13666 &no_neighbor_route_reflector_client_cmd);
13667 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
13668 install_element(BGP_IPV6L_NODE,
13669 &no_neighbor_route_reflector_client_cmd);
13670 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
13671 install_element(BGP_VPNV4_NODE,
13672 &no_neighbor_route_reflector_client_cmd);
13673 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
13674 install_element(BGP_VPNV6_NODE,
13675 &no_neighbor_route_reflector_client_cmd);
13676 install_element(BGP_FLOWSPECV4_NODE,
13677 &neighbor_route_reflector_client_cmd);
13678 install_element(BGP_FLOWSPECV4_NODE,
13679 &no_neighbor_route_reflector_client_cmd);
13680 install_element(BGP_FLOWSPECV6_NODE,
13681 &neighbor_route_reflector_client_cmd);
13682 install_element(BGP_FLOWSPECV6_NODE,
13683 &no_neighbor_route_reflector_client_cmd);
13684 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
13685 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
13686
13687 /* "neighbor route-server" commands.*/
13688 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
13689 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
13690 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
13691 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
13692 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
13693 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
13694 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
13695 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
13696 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
13697 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
13698 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
13699 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
13700 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
13701 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
13702 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
13703 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
13704 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
13705 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
13706 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
13707 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
13708 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
13709 install_element(BGP_FLOWSPECV4_NODE,
13710 &no_neighbor_route_server_client_cmd);
13711 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
13712 install_element(BGP_FLOWSPECV6_NODE,
13713 &no_neighbor_route_server_client_cmd);
13714
13715 /* "neighbor addpath-tx-all-paths" commands.*/
13716 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
13717 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
13718 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13719 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13720 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13721 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13722 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13723 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13724 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13725 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13726 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13727 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13728 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13729 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13730 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13731 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13732 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13733 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13734
13735 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
13736 install_element(BGP_NODE,
13737 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13738 install_element(BGP_NODE,
13739 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13740 install_element(BGP_IPV4_NODE,
13741 &neighbor_addpath_tx_bestpath_per_as_cmd);
13742 install_element(BGP_IPV4_NODE,
13743 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13744 install_element(BGP_IPV4M_NODE,
13745 &neighbor_addpath_tx_bestpath_per_as_cmd);
13746 install_element(BGP_IPV4M_NODE,
13747 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13748 install_element(BGP_IPV4L_NODE,
13749 &neighbor_addpath_tx_bestpath_per_as_cmd);
13750 install_element(BGP_IPV4L_NODE,
13751 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13752 install_element(BGP_IPV6_NODE,
13753 &neighbor_addpath_tx_bestpath_per_as_cmd);
13754 install_element(BGP_IPV6_NODE,
13755 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13756 install_element(BGP_IPV6M_NODE,
13757 &neighbor_addpath_tx_bestpath_per_as_cmd);
13758 install_element(BGP_IPV6M_NODE,
13759 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13760 install_element(BGP_IPV6L_NODE,
13761 &neighbor_addpath_tx_bestpath_per_as_cmd);
13762 install_element(BGP_IPV6L_NODE,
13763 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13764 install_element(BGP_VPNV4_NODE,
13765 &neighbor_addpath_tx_bestpath_per_as_cmd);
13766 install_element(BGP_VPNV4_NODE,
13767 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13768 install_element(BGP_VPNV6_NODE,
13769 &neighbor_addpath_tx_bestpath_per_as_cmd);
13770 install_element(BGP_VPNV6_NODE,
13771 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13772
13773 /* "neighbor sender-as-path-loop-detection" commands. */
13774 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
13775 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
13776
13777 /* "neighbor passive" commands. */
13778 install_element(BGP_NODE, &neighbor_passive_cmd);
13779 install_element(BGP_NODE, &no_neighbor_passive_cmd);
13780
13781
13782 /* "neighbor shutdown" commands. */
13783 install_element(BGP_NODE, &neighbor_shutdown_cmd);
13784 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
13785 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
13786 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
13787
13788 /* "neighbor capability extended-nexthop" commands.*/
13789 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
13790 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
13791
13792 /* "neighbor capability orf prefix-list" commands.*/
13793 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
13794 install_element(BGP_NODE,
13795 &no_neighbor_capability_orf_prefix_hidden_cmd);
13796 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
13797 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
13798 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
13799 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13800 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
13801 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13802 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
13803 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
13804 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
13805 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13806 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
13807 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13808
13809 /* "neighbor capability dynamic" commands.*/
13810 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
13811 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
13812
13813 /* "neighbor dont-capability-negotiate" commands. */
13814 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
13815 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
13816
13817 /* "neighbor ebgp-multihop" commands. */
13818 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
13819 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
13820 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
13821
13822 /* "neighbor disable-connected-check" commands. */
13823 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
13824 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
13825
13826 /* "neighbor enforce-first-as" commands. */
13827 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
13828 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
13829
13830 /* "neighbor description" commands. */
13831 install_element(BGP_NODE, &neighbor_description_cmd);
13832 install_element(BGP_NODE, &no_neighbor_description_cmd);
13833 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
13834
13835 /* "neighbor update-source" commands. "*/
13836 install_element(BGP_NODE, &neighbor_update_source_cmd);
13837 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
13838
13839 /* "neighbor default-originate" commands. */
13840 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
13841 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
13842 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
13843 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
13844 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
13845 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
13846 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
13847 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
13848 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
13849 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
13850 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
13851 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
13852 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
13853 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
13854 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
13855 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
13856 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
13857 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
13858 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
13859 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
13860 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
13861
13862 /* "neighbor port" commands. */
13863 install_element(BGP_NODE, &neighbor_port_cmd);
13864 install_element(BGP_NODE, &no_neighbor_port_cmd);
13865
13866 /* "neighbor weight" commands. */
13867 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
13868 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
13869
13870 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
13871 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
13872 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
13873 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
13874 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
13875 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
13876 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
13877 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
13878 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
13879 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
13880 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
13881 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
13882 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
13883 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
13884 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
13885 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
13886
13887 /* "neighbor override-capability" commands. */
13888 install_element(BGP_NODE, &neighbor_override_capability_cmd);
13889 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
13890
13891 /* "neighbor strict-capability-match" commands. */
13892 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
13893 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
13894
13895 /* "neighbor timers" commands. */
13896 install_element(BGP_NODE, &neighbor_timers_cmd);
13897 install_element(BGP_NODE, &no_neighbor_timers_cmd);
13898
13899 /* "neighbor timers connect" commands. */
13900 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
13901 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
13902
13903 /* "neighbor advertisement-interval" commands. */
13904 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
13905 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
13906
13907 /* "neighbor interface" commands. */
13908 install_element(BGP_NODE, &neighbor_interface_cmd);
13909 install_element(BGP_NODE, &no_neighbor_interface_cmd);
13910
13911 /* "neighbor distribute" commands. */
13912 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
13913 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
13914 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
13915 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
13916 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
13917 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
13918 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
13919 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
13920 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
13921 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
13922 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
13923 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
13924 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
13925 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
13926 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
13927 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
13928 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
13929 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
13930
13931 /* "neighbor prefix-list" commands. */
13932 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
13933 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
13934 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
13935 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
13936 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
13937 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
13938 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
13939 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
13940 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
13941 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
13942 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
13943 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
13944 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
13945 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
13946 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
13947 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
13948 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
13949 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
13950 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
13951 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
13952 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
13953 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
13954
13955 /* "neighbor filter-list" commands. */
13956 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
13957 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
13958 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
13959 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
13960 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
13961 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
13962 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
13963 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
13964 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
13965 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
13966 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
13967 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
13968 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
13969 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
13970 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
13971 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
13972 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
13973 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
13974 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
13975 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
13976 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
13977 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
13978
13979 /* "neighbor route-map" commands. */
13980 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
13981 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
13982 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
13983 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
13984 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
13985 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
13986 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
13987 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
13988 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
13989 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
13990 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
13991 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
13992 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
13993 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
13994 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
13995 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
13996 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
13997 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
13998 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
13999 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
14000 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
14001 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
14002 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
14003 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
14004
14005 /* "neighbor unsuppress-map" commands. */
14006 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
14007 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
14008 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
14009 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
14010 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
14011 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
14012 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
14013 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
14014 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
14015 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
14016 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
14017 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
14018 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
14019 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
14020 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
14021 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
14022 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
14023 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
14024
14025 /* "neighbor maximum-prefix" commands. */
14026 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
14027 install_element(BGP_NODE,
14028 &neighbor_maximum_prefix_threshold_hidden_cmd);
14029 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
14030 install_element(BGP_NODE,
14031 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
14032 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
14033 install_element(BGP_NODE,
14034 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
14035 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
14036 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
14037 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
14038 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
14039 install_element(BGP_IPV4_NODE,
14040 &neighbor_maximum_prefix_threshold_warning_cmd);
14041 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
14042 install_element(BGP_IPV4_NODE,
14043 &neighbor_maximum_prefix_threshold_restart_cmd);
14044 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
14045 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
14046 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
14047 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
14048 install_element(BGP_IPV4M_NODE,
14049 &neighbor_maximum_prefix_threshold_warning_cmd);
14050 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
14051 install_element(BGP_IPV4M_NODE,
14052 &neighbor_maximum_prefix_threshold_restart_cmd);
14053 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
14054 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
14055 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
14056 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
14057 install_element(BGP_IPV4L_NODE,
14058 &neighbor_maximum_prefix_threshold_warning_cmd);
14059 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
14060 install_element(BGP_IPV4L_NODE,
14061 &neighbor_maximum_prefix_threshold_restart_cmd);
14062 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
14063 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
14064 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
14065 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
14066 install_element(BGP_IPV6_NODE,
14067 &neighbor_maximum_prefix_threshold_warning_cmd);
14068 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
14069 install_element(BGP_IPV6_NODE,
14070 &neighbor_maximum_prefix_threshold_restart_cmd);
14071 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
14072 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
14073 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
14074 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
14075 install_element(BGP_IPV6M_NODE,
14076 &neighbor_maximum_prefix_threshold_warning_cmd);
14077 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
14078 install_element(BGP_IPV6M_NODE,
14079 &neighbor_maximum_prefix_threshold_restart_cmd);
14080 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
14081 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
14082 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
14083 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
14084 install_element(BGP_IPV6L_NODE,
14085 &neighbor_maximum_prefix_threshold_warning_cmd);
14086 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
14087 install_element(BGP_IPV6L_NODE,
14088 &neighbor_maximum_prefix_threshold_restart_cmd);
14089 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
14090 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
14091 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
14092 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
14093 install_element(BGP_VPNV4_NODE,
14094 &neighbor_maximum_prefix_threshold_warning_cmd);
14095 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
14096 install_element(BGP_VPNV4_NODE,
14097 &neighbor_maximum_prefix_threshold_restart_cmd);
14098 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
14099 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
14100 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
14101 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
14102 install_element(BGP_VPNV6_NODE,
14103 &neighbor_maximum_prefix_threshold_warning_cmd);
14104 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
14105 install_element(BGP_VPNV6_NODE,
14106 &neighbor_maximum_prefix_threshold_restart_cmd);
14107 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
14108
14109 /* "neighbor allowas-in" */
14110 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
14111 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
14112 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
14113 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
14114 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
14115 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
14116 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
14117 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
14118 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
14119 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
14120 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
14121 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
14122 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
14123 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
14124 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
14125 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
14126 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
14127 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
14128 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
14129 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
14130
14131 /* address-family commands. */
14132 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
14133 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
14134 #ifdef KEEP_OLD_VPN_COMMANDS
14135 install_element(BGP_NODE, &address_family_vpnv4_cmd);
14136 install_element(BGP_NODE, &address_family_vpnv6_cmd);
14137 #endif /* KEEP_OLD_VPN_COMMANDS */
14138
14139 install_element(BGP_NODE, &address_family_evpn_cmd);
14140
14141 /* "exit-address-family" command. */
14142 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
14143 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
14144 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
14145 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
14146 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
14147 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
14148 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
14149 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
14150 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
14151 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
14152 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
14153
14154 /* "clear ip bgp commands" */
14155 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
14156
14157 /* clear ip bgp prefix */
14158 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
14159 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
14160 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
14161
14162 /* "show [ip] bgp summary" commands. */
14163 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
14164 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
14165 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
14166 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
14167 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
14168 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
14169 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
14170
14171 /* "show [ip] bgp neighbors" commands. */
14172 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
14173
14174 /* "show [ip] bgp peer-group" commands. */
14175 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
14176
14177 /* "show [ip] bgp paths" commands. */
14178 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
14179
14180 /* "show [ip] bgp community" commands. */
14181 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
14182
14183 /* "show ip bgp large-community" commands. */
14184 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
14185 /* "show [ip] bgp attribute-info" commands. */
14186 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
14187 /* "show [ip] bgp route-leak" command */
14188 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
14189
14190 /* "redistribute" commands. */
14191 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
14192 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
14193 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
14194 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
14195 install_element(BGP_NODE,
14196 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
14197 install_element(BGP_NODE,
14198 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
14199 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
14200 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
14201 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
14202 install_element(BGP_NODE,
14203 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
14204 install_element(BGP_NODE,
14205 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
14206 install_element(BGP_NODE,
14207 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
14208 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
14209 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
14210 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
14211 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
14212 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
14213 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
14214 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
14215 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
14216 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
14217 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
14218 install_element(BGP_IPV4_NODE,
14219 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
14220 install_element(BGP_IPV4_NODE,
14221 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
14222 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
14223 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
14224 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
14225 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
14226 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
14227 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
14228
14229 /* import|export vpn [route-map WORD] */
14230 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
14231 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
14232
14233 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
14234 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
14235
14236 /* ttl_security commands */
14237 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
14238 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
14239
14240 /* "show [ip] bgp memory" commands. */
14241 install_element(VIEW_NODE, &show_bgp_memory_cmd);
14242
14243 /* "show bgp martian next-hop" */
14244 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
14245
14246 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
14247
14248 /* "show [ip] bgp views" commands. */
14249 install_element(VIEW_NODE, &show_bgp_views_cmd);
14250
14251 /* "show [ip] bgp vrfs" commands. */
14252 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
14253
14254 /* Community-list. */
14255 community_list_vty();
14256
14257 /* vpn-policy commands */
14258 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
14259 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
14260 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
14261 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
14262 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
14263 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
14264 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
14265 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
14266 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
14267 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
14268 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
14269 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
14270
14271 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
14272 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
14273
14274 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
14275 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
14276 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
14277 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
14278 install_element(BGP_IPV4_NODE, &af_no_nexthop_vpn_export_cmd);
14279 install_element(BGP_IPV6_NODE, &af_no_nexthop_vpn_export_cmd);
14280 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
14281 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
14282 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
14283 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
14284 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
14285 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
14286 }
14287
14288 #include "memory.h"
14289 #include "bgp_regex.h"
14290 #include "bgp_clist.h"
14291 #include "bgp_ecommunity.h"
14292
14293 /* VTY functions. */
14294
14295 /* Direction value to string conversion. */
14296 static const char *community_direct_str(int direct)
14297 {
14298 switch (direct) {
14299 case COMMUNITY_DENY:
14300 return "deny";
14301 case COMMUNITY_PERMIT:
14302 return "permit";
14303 default:
14304 return "unknown";
14305 }
14306 }
14307
14308 /* Display error string. */
14309 static void community_list_perror(struct vty *vty, int ret)
14310 {
14311 switch (ret) {
14312 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
14313 vty_out(vty, "%% Can't find community-list\n");
14314 break;
14315 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
14316 vty_out(vty, "%% Malformed community-list value\n");
14317 break;
14318 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
14319 vty_out(vty,
14320 "%% Community name conflict, previously defined as standard community\n");
14321 break;
14322 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
14323 vty_out(vty,
14324 "%% Community name conflict, previously defined as expanded community\n");
14325 break;
14326 }
14327 }
14328
14329 /* "community-list" keyword help string. */
14330 #define COMMUNITY_LIST_STR "Add a community list entry\n"
14331
14332 /*community-list standard */
14333 DEFUN (community_list_standard,
14334 bgp_community_list_standard_cmd,
14335 "bgp community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14336 BGP_STR
14337 COMMUNITY_LIST_STR
14338 "Community list number (standard)\n"
14339 "Add an standard community-list entry\n"
14340 "Community list name\n"
14341 "Specify community to reject\n"
14342 "Specify community to accept\n"
14343 COMMUNITY_VAL_STR)
14344 {
14345 char *cl_name_or_number = NULL;
14346 int direct = 0;
14347 int style = COMMUNITY_LIST_STANDARD;
14348 int idx = 0;
14349
14350 argv_find(argv, argc, "(1-99)", &idx);
14351 argv_find(argv, argc, "WORD", &idx);
14352 cl_name_or_number = argv[idx]->arg;
14353 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14354 : COMMUNITY_DENY;
14355 argv_find(argv, argc, "AA:NN", &idx);
14356 char *str = argv_concat(argv, argc, idx);
14357
14358 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
14359 style);
14360
14361 XFREE(MTYPE_TMP, str);
14362
14363 if (ret < 0) {
14364 /* Display error string. */
14365 community_list_perror(vty, ret);
14366 return CMD_WARNING_CONFIG_FAILED;
14367 }
14368
14369 return CMD_SUCCESS;
14370 }
14371
14372 DEFUN (no_community_list_standard_all,
14373 no_bgp_community_list_standard_all_cmd,
14374 "no bgp community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14375 NO_STR
14376 BGP_STR
14377 COMMUNITY_LIST_STR
14378 "Community list number (standard)\n"
14379 "Add an standard community-list entry\n"
14380 "Community list name\n"
14381 "Specify community to reject\n"
14382 "Specify community to accept\n"
14383 COMMUNITY_VAL_STR)
14384 {
14385 char *cl_name_or_number = NULL;
14386 char *str = NULL;
14387 int direct = 0;
14388 int style = COMMUNITY_LIST_STANDARD;
14389
14390 int idx = 0;
14391
14392 argv_find(argv, argc, "permit", &idx);
14393 argv_find(argv, argc, "deny", &idx);
14394
14395 if (idx) {
14396 direct = argv_find(argv, argc, "permit", &idx)
14397 ? COMMUNITY_PERMIT
14398 : COMMUNITY_DENY;
14399
14400 idx = 0;
14401 argv_find(argv, argc, "AA:NN", &idx);
14402 str = argv_concat(argv, argc, idx);
14403 }
14404
14405 idx = 0;
14406 argv_find(argv, argc, "(1-99)", &idx);
14407 argv_find(argv, argc, "WORD", &idx);
14408 cl_name_or_number = argv[idx]->arg;
14409
14410 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
14411 direct, style);
14412
14413 XFREE(MTYPE_TMP, str);
14414
14415 if (ret < 0) {
14416 community_list_perror(vty, ret);
14417 return CMD_WARNING_CONFIG_FAILED;
14418 }
14419
14420 return CMD_SUCCESS;
14421 }
14422
14423 ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
14424 "no bgp community-list <(1-99)|standard WORD>",
14425 NO_STR BGP_STR COMMUNITY_LIST_STR
14426 "Community list number (standard)\n"
14427 "Add an standard community-list entry\n"
14428 "Community list name\n")
14429
14430 /*community-list expanded */
14431 DEFUN (community_list_expanded_all,
14432 bgp_community_list_expanded_all_cmd,
14433 "bgp community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14434 BGP_STR
14435 COMMUNITY_LIST_STR
14436 "Community list number (expanded)\n"
14437 "Add an expanded community-list entry\n"
14438 "Community list name\n"
14439 "Specify community to reject\n"
14440 "Specify community to accept\n"
14441 COMMUNITY_VAL_STR)
14442 {
14443 char *cl_name_or_number = NULL;
14444 int direct = 0;
14445 int style = COMMUNITY_LIST_EXPANDED;
14446
14447 int idx = 0;
14448
14449 argv_find(argv, argc, "(100-500)", &idx);
14450 argv_find(argv, argc, "WORD", &idx);
14451 cl_name_or_number = argv[idx]->arg;
14452 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14453 : COMMUNITY_DENY;
14454 argv_find(argv, argc, "AA:NN", &idx);
14455 char *str = argv_concat(argv, argc, idx);
14456
14457 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
14458 style);
14459
14460 XFREE(MTYPE_TMP, str);
14461
14462 if (ret < 0) {
14463 /* Display error string. */
14464 community_list_perror(vty, ret);
14465 return CMD_WARNING_CONFIG_FAILED;
14466 }
14467
14468 return CMD_SUCCESS;
14469 }
14470
14471 DEFUN (no_community_list_expanded_all,
14472 no_bgp_community_list_expanded_all_cmd,
14473 "no bgp community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14474 NO_STR
14475 BGP_STR
14476 COMMUNITY_LIST_STR
14477 "Community list number (expanded)\n"
14478 "Add an expanded community-list entry\n"
14479 "Community list name\n"
14480 "Specify community to reject\n"
14481 "Specify community to accept\n"
14482 COMMUNITY_VAL_STR)
14483 {
14484 char *cl_name_or_number = NULL;
14485 char *str = NULL;
14486 int direct = 0;
14487 int style = COMMUNITY_LIST_EXPANDED;
14488
14489 int idx = 0;
14490
14491 argv_find(argv, argc, "permit", &idx);
14492 argv_find(argv, argc, "deny", &idx);
14493
14494 if (idx) {
14495 direct = argv_find(argv, argc, "permit", &idx)
14496 ? COMMUNITY_PERMIT
14497 : COMMUNITY_DENY;
14498
14499 idx = 0;
14500 argv_find(argv, argc, "AA:NN", &idx);
14501 str = argv_concat(argv, argc, idx);
14502 }
14503
14504 idx = 0;
14505 argv_find(argv, argc, "(100-500)", &idx);
14506 argv_find(argv, argc, "WORD", &idx);
14507 cl_name_or_number = argv[idx]->arg;
14508
14509 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
14510 direct, style);
14511
14512 XFREE(MTYPE_TMP, str);
14513
14514 if (ret < 0) {
14515 community_list_perror(vty, ret);
14516 return CMD_WARNING_CONFIG_FAILED;
14517 }
14518
14519 return CMD_SUCCESS;
14520 }
14521
14522 ALIAS(no_community_list_expanded_all, no_bgp_community_list_expanded_all_list_cmd,
14523 "no bgp community-list <(100-500)|expanded WORD>",
14524 NO_STR IP_STR COMMUNITY_LIST_STR
14525 "Community list number (expanded)\n"
14526 "Add an expanded community-list entry\n"
14527 "Community list name\n")
14528
14529 /* Return configuration string of community-list entry. */
14530 static const char *community_list_config_str(struct community_entry *entry)
14531 {
14532 const char *str;
14533
14534 if (entry->any)
14535 str = "";
14536 else {
14537 if (entry->style == COMMUNITY_LIST_STANDARD)
14538 str = community_str(entry->u.com, false);
14539 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
14540 str = lcommunity_str(entry->u.lcom, false);
14541 else
14542 str = entry->config;
14543 }
14544 return str;
14545 }
14546
14547 static void community_list_show(struct vty *vty, struct community_list *list)
14548 {
14549 struct community_entry *entry;
14550
14551 for (entry = list->head; entry; entry = entry->next) {
14552 if (entry == list->head) {
14553 if (all_digit(list->name))
14554 vty_out(vty, "Community %s list %s\n",
14555 entry->style == COMMUNITY_LIST_STANDARD
14556 ? "standard"
14557 : "(expanded) access",
14558 list->name);
14559 else
14560 vty_out(vty, "Named Community %s list %s\n",
14561 entry->style == COMMUNITY_LIST_STANDARD
14562 ? "standard"
14563 : "expanded",
14564 list->name);
14565 }
14566 if (entry->any)
14567 vty_out(vty, " %s\n",
14568 community_direct_str(entry->direct));
14569 else
14570 vty_out(vty, " %s %s\n",
14571 community_direct_str(entry->direct),
14572 community_list_config_str(entry));
14573 }
14574 }
14575
14576 DEFUN (show_community_list,
14577 show_bgp_community_list_cmd,
14578 "show bgp community-list",
14579 SHOW_STR
14580 BGP_STR
14581 "List community-list\n")
14582 {
14583 struct community_list *list;
14584 struct community_list_master *cm;
14585
14586 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
14587 if (!cm)
14588 return CMD_SUCCESS;
14589
14590 for (list = cm->num.head; list; list = list->next)
14591 community_list_show(vty, list);
14592
14593 for (list = cm->str.head; list; list = list->next)
14594 community_list_show(vty, list);
14595
14596 return CMD_SUCCESS;
14597 }
14598
14599 DEFUN (show_community_list_arg,
14600 show_bgp_community_list_arg_cmd,
14601 "show bgp community-list <(1-500)|WORD> detail",
14602 SHOW_STR
14603 BGP_STR
14604 "List community-list\n"
14605 "Community-list number\n"
14606 "Community-list name\n"
14607 "Detailed information on community-list\n")
14608 {
14609 int idx_comm_list = 3;
14610 struct community_list *list;
14611
14612 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
14613 COMMUNITY_LIST_MASTER);
14614 if (!list) {
14615 vty_out(vty, "%% Can't find community-list\n");
14616 return CMD_WARNING;
14617 }
14618
14619 community_list_show(vty, list);
14620
14621 return CMD_SUCCESS;
14622 }
14623
14624 /*
14625 * Large Community code.
14626 */
14627 static int lcommunity_list_set_vty(struct vty *vty, int argc,
14628 struct cmd_token **argv, int style,
14629 int reject_all_digit_name)
14630 {
14631 int ret;
14632 int direct;
14633 char *str;
14634 int idx = 0;
14635 char *cl_name;
14636
14637 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14638 : COMMUNITY_DENY;
14639
14640 /* All digit name check. */
14641 idx = 0;
14642 argv_find(argv, argc, "WORD", &idx);
14643 argv_find(argv, argc, "(1-99)", &idx);
14644 argv_find(argv, argc, "(100-500)", &idx);
14645 cl_name = argv[idx]->arg;
14646 if (reject_all_digit_name && all_digit(cl_name)) {
14647 vty_out(vty, "%% Community name cannot have all digits\n");
14648 return CMD_WARNING_CONFIG_FAILED;
14649 }
14650
14651 idx = 0;
14652 argv_find(argv, argc, "AA:BB:CC", &idx);
14653 argv_find(argv, argc, "LINE", &idx);
14654 /* Concat community string argument. */
14655 if (idx)
14656 str = argv_concat(argv, argc, idx);
14657 else
14658 str = NULL;
14659
14660 ret = lcommunity_list_set(bgp_clist, cl_name, str, direct, style);
14661
14662 /* Free temporary community list string allocated by
14663 argv_concat(). */
14664 XFREE(MTYPE_TMP, str);
14665
14666 if (ret < 0) {
14667 community_list_perror(vty, ret);
14668 return CMD_WARNING_CONFIG_FAILED;
14669 }
14670 return CMD_SUCCESS;
14671 }
14672
14673 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
14674 struct cmd_token **argv, int style)
14675 {
14676 int ret;
14677 int direct = 0;
14678 char *str = NULL;
14679 int idx = 0;
14680
14681 argv_find(argv, argc, "permit", &idx);
14682 argv_find(argv, argc, "deny", &idx);
14683
14684 if (idx) {
14685 /* Check the list direct. */
14686 if (strncmp(argv[idx]->arg, "p", 1) == 0)
14687 direct = COMMUNITY_PERMIT;
14688 else
14689 direct = COMMUNITY_DENY;
14690
14691 idx = 0;
14692 argv_find(argv, argc, "LINE", &idx);
14693 argv_find(argv, argc, "AA:AA:NN", &idx);
14694 /* Concat community string argument. */
14695 str = argv_concat(argv, argc, idx);
14696 }
14697
14698 idx = 0;
14699 argv_find(argv, argc, "(1-99)", &idx);
14700 argv_find(argv, argc, "(100-500)", &idx);
14701 argv_find(argv, argc, "WORD", &idx);
14702
14703 /* Unset community list. */
14704 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, direct,
14705 style);
14706
14707 /* Free temporary community list string allocated by
14708 argv_concat(). */
14709 XFREE(MTYPE_TMP, str);
14710
14711 if (ret < 0) {
14712 community_list_perror(vty, ret);
14713 return CMD_WARNING_CONFIG_FAILED;
14714 }
14715
14716 return CMD_SUCCESS;
14717 }
14718
14719 /* "large-community-list" keyword help string. */
14720 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
14721 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
14722
14723 DEFUN (lcommunity_list_standard,
14724 bgp_lcommunity_list_standard_cmd,
14725 "bgp large-community-list (1-99) <deny|permit> AA:BB:CC...",
14726 BGP_STR
14727 LCOMMUNITY_LIST_STR
14728 "Large Community list number (standard)\n"
14729 "Specify large community to reject\n"
14730 "Specify large community to accept\n"
14731 LCOMMUNITY_VAL_STR)
14732 {
14733 return lcommunity_list_set_vty(vty, argc, argv,
14734 LARGE_COMMUNITY_LIST_STANDARD, 0);
14735 }
14736
14737 DEFUN (lcommunity_list_expanded,
14738 bgp_lcommunity_list_expanded_cmd,
14739 "bgp large-community-list (100-500) <deny|permit> LINE...",
14740 BGP_STR
14741 LCOMMUNITY_LIST_STR
14742 "Large Community list number (expanded)\n"
14743 "Specify large community to reject\n"
14744 "Specify large community to accept\n"
14745 "An ordered list as a regular-expression\n")
14746 {
14747 return lcommunity_list_set_vty(vty, argc, argv,
14748 LARGE_COMMUNITY_LIST_EXPANDED, 0);
14749 }
14750
14751 DEFUN (lcommunity_list_name_standard,
14752 bgp_lcommunity_list_name_standard_cmd,
14753 "bgp large-community-list standard WORD <deny|permit> AA:BB:CC...",
14754 BGP_STR
14755 LCOMMUNITY_LIST_STR
14756 "Specify standard large-community-list\n"
14757 "Large Community list name\n"
14758 "Specify large community to reject\n"
14759 "Specify large community to accept\n"
14760 LCOMMUNITY_VAL_STR)
14761 {
14762 return lcommunity_list_set_vty(vty, argc, argv,
14763 LARGE_COMMUNITY_LIST_STANDARD, 1);
14764 }
14765
14766 DEFUN (lcommunity_list_name_expanded,
14767 bgp_lcommunity_list_name_expanded_cmd,
14768 "bgp large-community-list expanded WORD <deny|permit> LINE...",
14769 BGP_STR
14770 LCOMMUNITY_LIST_STR
14771 "Specify expanded large-community-list\n"
14772 "Large Community list name\n"
14773 "Specify large community to reject\n"
14774 "Specify large community to accept\n"
14775 "An ordered list as a regular-expression\n")
14776 {
14777 return lcommunity_list_set_vty(vty, argc, argv,
14778 LARGE_COMMUNITY_LIST_EXPANDED, 1);
14779 }
14780
14781 DEFUN (no_lcommunity_list_standard_all,
14782 no_bgp_lcommunity_list_standard_all_cmd,
14783 "no bgp large-community-list <(1-99)|(100-500)|WORD>",
14784 NO_STR
14785 BGP_STR
14786 LCOMMUNITY_LIST_STR
14787 "Large Community list number (standard)\n"
14788 "Large Community list number (expanded)\n"
14789 "Large Community list name\n")
14790 {
14791 return lcommunity_list_unset_vty(vty, argc, argv,
14792 LARGE_COMMUNITY_LIST_STANDARD);
14793 }
14794
14795 DEFUN (no_lcommunity_list_name_expanded_all,
14796 no_bgp_lcommunity_list_name_expanded_all_cmd,
14797 "no bgp large-community-list expanded WORD",
14798 NO_STR
14799 BGP_STR
14800 LCOMMUNITY_LIST_STR
14801 "Specify expanded large-community-list\n"
14802 "Large Community list name\n")
14803 {
14804 return lcommunity_list_unset_vty(vty, argc, argv,
14805 LARGE_COMMUNITY_LIST_EXPANDED);
14806 }
14807
14808 DEFUN (no_lcommunity_list_standard,
14809 no_bgp_lcommunity_list_standard_cmd,
14810 "no bgp large-community-list (1-99) <deny|permit> AA:AA:NN...",
14811 NO_STR
14812 BGP_STR
14813 LCOMMUNITY_LIST_STR
14814 "Large Community list number (standard)\n"
14815 "Specify large community to reject\n"
14816 "Specify large community to accept\n"
14817 LCOMMUNITY_VAL_STR)
14818 {
14819 return lcommunity_list_unset_vty(vty, argc, argv,
14820 LARGE_COMMUNITY_LIST_STANDARD);
14821 }
14822
14823 DEFUN (no_lcommunity_list_expanded,
14824 no_bgp_lcommunity_list_expanded_cmd,
14825 "no bgp large-community-list (100-500) <deny|permit> LINE...",
14826 NO_STR
14827 BGP_STR
14828 LCOMMUNITY_LIST_STR
14829 "Large Community list number (expanded)\n"
14830 "Specify large community to reject\n"
14831 "Specify large community to accept\n"
14832 "An ordered list as a regular-expression\n")
14833 {
14834 return lcommunity_list_unset_vty(vty, argc, argv,
14835 LARGE_COMMUNITY_LIST_EXPANDED);
14836 }
14837
14838 DEFUN (no_lcommunity_list_name_standard,
14839 no_bgp_lcommunity_list_name_standard_cmd,
14840 "no bgp large-community-list standard WORD <deny|permit> AA:AA:NN...",
14841 NO_STR
14842 BGP_STR
14843 LCOMMUNITY_LIST_STR
14844 "Specify standard large-community-list\n"
14845 "Large Community list name\n"
14846 "Specify large community to reject\n"
14847 "Specify large community to accept\n"
14848 LCOMMUNITY_VAL_STR)
14849 {
14850 return lcommunity_list_unset_vty(vty, argc, argv,
14851 LARGE_COMMUNITY_LIST_STANDARD);
14852 }
14853
14854 DEFUN (no_lcommunity_list_name_expanded,
14855 no_bgp_lcommunity_list_name_expanded_cmd,
14856 "no bgp large-community-list expanded WORD <deny|permit> LINE...",
14857 NO_STR
14858 BGP_STR
14859 LCOMMUNITY_LIST_STR
14860 "Specify expanded large-community-list\n"
14861 "Large community list name\n"
14862 "Specify large community to reject\n"
14863 "Specify large community to accept\n"
14864 "An ordered list as a regular-expression\n")
14865 {
14866 return lcommunity_list_unset_vty(vty, argc, argv,
14867 LARGE_COMMUNITY_LIST_EXPANDED);
14868 }
14869
14870 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
14871 {
14872 struct community_entry *entry;
14873
14874 for (entry = list->head; entry; entry = entry->next) {
14875 if (entry == list->head) {
14876 if (all_digit(list->name))
14877 vty_out(vty, "Large community %s list %s\n",
14878 entry->style ==
14879 LARGE_COMMUNITY_LIST_STANDARD
14880 ? "standard"
14881 : "(expanded) access",
14882 list->name);
14883 else
14884 vty_out(vty,
14885 "Named large community %s list %s\n",
14886 entry->style ==
14887 LARGE_COMMUNITY_LIST_STANDARD
14888 ? "standard"
14889 : "expanded",
14890 list->name);
14891 }
14892 if (entry->any)
14893 vty_out(vty, " %s\n",
14894 community_direct_str(entry->direct));
14895 else
14896 vty_out(vty, " %s %s\n",
14897 community_direct_str(entry->direct),
14898 community_list_config_str(entry));
14899 }
14900 }
14901
14902 DEFUN (show_lcommunity_list,
14903 show_bgp_lcommunity_list_cmd,
14904 "show bgp large-community-list",
14905 SHOW_STR
14906 BGP_STR
14907 "List large-community list\n")
14908 {
14909 struct community_list *list;
14910 struct community_list_master *cm;
14911
14912 cm = community_list_master_lookup(bgp_clist,
14913 LARGE_COMMUNITY_LIST_MASTER);
14914 if (!cm)
14915 return CMD_SUCCESS;
14916
14917 for (list = cm->num.head; list; list = list->next)
14918 lcommunity_list_show(vty, list);
14919
14920 for (list = cm->str.head; list; list = list->next)
14921 lcommunity_list_show(vty, list);
14922
14923 return CMD_SUCCESS;
14924 }
14925
14926 DEFUN (show_lcommunity_list_arg,
14927 show_bgp_lcommunity_list_arg_cmd,
14928 "show bgp large-community-list <(1-500)|WORD> detail",
14929 SHOW_STR
14930 BGP_STR
14931 "List large-community list\n"
14932 "Large-community-list number\n"
14933 "Large-community-list name\n"
14934 "Detailed information on large-community-list\n")
14935 {
14936 struct community_list *list;
14937
14938 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
14939 LARGE_COMMUNITY_LIST_MASTER);
14940 if (!list) {
14941 vty_out(vty, "%% Can't find large-community-list\n");
14942 return CMD_WARNING;
14943 }
14944
14945 lcommunity_list_show(vty, list);
14946
14947 return CMD_SUCCESS;
14948 }
14949
14950 /* "extcommunity-list" keyword help string. */
14951 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
14952 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
14953
14954 DEFUN (extcommunity_list_standard,
14955 bgp_extcommunity_list_standard_cmd,
14956 "bgp extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14957 BGP_STR
14958 EXTCOMMUNITY_LIST_STR
14959 "Extended Community list number (standard)\n"
14960 "Specify standard extcommunity-list\n"
14961 "Community list name\n"
14962 "Specify community to reject\n"
14963 "Specify community to accept\n"
14964 EXTCOMMUNITY_VAL_STR)
14965 {
14966 int style = EXTCOMMUNITY_LIST_STANDARD;
14967 int direct = 0;
14968 char *cl_number_or_name = NULL;
14969
14970 int idx = 0;
14971
14972 argv_find(argv, argc, "(1-99)", &idx);
14973 argv_find(argv, argc, "WORD", &idx);
14974 cl_number_or_name = argv[idx]->arg;
14975 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14976 : COMMUNITY_DENY;
14977 argv_find(argv, argc, "AA:NN", &idx);
14978 char *str = argv_concat(argv, argc, idx);
14979
14980 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
14981 direct, style);
14982
14983 XFREE(MTYPE_TMP, str);
14984
14985 if (ret < 0) {
14986 community_list_perror(vty, ret);
14987 return CMD_WARNING_CONFIG_FAILED;
14988 }
14989
14990 return CMD_SUCCESS;
14991 }
14992
14993 DEFUN (extcommunity_list_name_expanded,
14994 bgp_extcommunity_list_name_expanded_cmd,
14995 "bgp extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
14996 BGP_STR
14997 EXTCOMMUNITY_LIST_STR
14998 "Extended Community list number (expanded)\n"
14999 "Specify expanded extcommunity-list\n"
15000 "Extended Community list name\n"
15001 "Specify community to reject\n"
15002 "Specify community to accept\n"
15003 "An ordered list as a regular-expression\n")
15004 {
15005 int style = EXTCOMMUNITY_LIST_EXPANDED;
15006 int direct = 0;
15007 char *cl_number_or_name = NULL;
15008 int idx = 0;
15009
15010 argv_find(argv, argc, "(100-500)", &idx);
15011 argv_find(argv, argc, "WORD", &idx);
15012 cl_number_or_name = argv[idx]->arg;
15013 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
15014 : COMMUNITY_DENY;
15015 argv_find(argv, argc, "LINE", &idx);
15016 char *str = argv_concat(argv, argc, idx);
15017
15018 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
15019 direct, style);
15020
15021 XFREE(MTYPE_TMP, str);
15022
15023 if (ret < 0) {
15024 community_list_perror(vty, ret);
15025 return CMD_WARNING_CONFIG_FAILED;
15026 }
15027
15028 return CMD_SUCCESS;
15029 }
15030
15031 DEFUN (no_extcommunity_list_standard_all,
15032 no_bgp_extcommunity_list_standard_all_cmd,
15033 "no bgp extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
15034 NO_STR
15035 BGP_STR
15036 EXTCOMMUNITY_LIST_STR
15037 "Extended Community list number (standard)\n"
15038 "Specify standard extcommunity-list\n"
15039 "Community list name\n"
15040 "Specify community to reject\n"
15041 "Specify community to accept\n"
15042 EXTCOMMUNITY_VAL_STR)
15043 {
15044 int style = EXTCOMMUNITY_LIST_STANDARD;
15045 int direct = 0;
15046 char *cl_number_or_name = NULL;
15047 char *str = NULL;
15048 int idx = 0;
15049
15050 argv_find(argv, argc, "permit", &idx);
15051 argv_find(argv, argc, "deny", &idx);
15052
15053 if (idx) {
15054 direct = argv_find(argv, argc, "permit", &idx)
15055 ? COMMUNITY_PERMIT
15056 : COMMUNITY_DENY;
15057
15058 idx = 0;
15059 argv_find(argv, argc, "AA:NN", &idx);
15060 str = argv_concat(argv, argc, idx);
15061 }
15062
15063 idx = 0;
15064 argv_find(argv, argc, "(1-99)", &idx);
15065 argv_find(argv, argc, "WORD", &idx);
15066 cl_number_or_name = argv[idx]->arg;
15067
15068 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
15069 direct, style);
15070
15071 XFREE(MTYPE_TMP, str);
15072
15073 if (ret < 0) {
15074 community_list_perror(vty, ret);
15075 return CMD_WARNING_CONFIG_FAILED;
15076 }
15077
15078 return CMD_SUCCESS;
15079 }
15080
15081 ALIAS(no_extcommunity_list_standard_all,
15082 no_bgp_extcommunity_list_standard_all_list_cmd,
15083 "no bgp extcommunity-list <(1-99)|standard WORD>",
15084 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15085 "Extended Community list number (standard)\n"
15086 "Specify standard extcommunity-list\n"
15087 "Community list name\n")
15088
15089 DEFUN (no_extcommunity_list_expanded_all,
15090 no_bgp_extcommunity_list_expanded_all_cmd,
15091 "no bgp extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15092 NO_STR
15093 BGP_STR
15094 EXTCOMMUNITY_LIST_STR
15095 "Extended Community list number (expanded)\n"
15096 "Specify expanded extcommunity-list\n"
15097 "Extended Community list name\n"
15098 "Specify community to reject\n"
15099 "Specify community to accept\n"
15100 "An ordered list as a regular-expression\n")
15101 {
15102 int style = EXTCOMMUNITY_LIST_EXPANDED;
15103 int direct = 0;
15104 char *cl_number_or_name = NULL;
15105 char *str = NULL;
15106 int idx = 0;
15107
15108 argv_find(argv, argc, "permit", &idx);
15109 argv_find(argv, argc, "deny", &idx);
15110
15111 if (idx) {
15112 direct = argv_find(argv, argc, "permit", &idx)
15113 ? COMMUNITY_PERMIT
15114 : COMMUNITY_DENY;
15115
15116 idx = 0;
15117 argv_find(argv, argc, "LINE", &idx);
15118 str = argv_concat(argv, argc, idx);
15119 }
15120
15121 idx = 0;
15122 argv_find(argv, argc, "(100-500)", &idx);
15123 argv_find(argv, argc, "WORD", &idx);
15124 cl_number_or_name = argv[idx]->arg;
15125
15126 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
15127 direct, style);
15128
15129 XFREE(MTYPE_TMP, str);
15130
15131 if (ret < 0) {
15132 community_list_perror(vty, ret);
15133 return CMD_WARNING_CONFIG_FAILED;
15134 }
15135
15136 return CMD_SUCCESS;
15137 }
15138
15139 ALIAS(no_extcommunity_list_expanded_all,
15140 no_bgp_extcommunity_list_expanded_all_list_cmd,
15141 "no bgp extcommunity-list <(100-500)|expanded WORD>",
15142 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15143 "Extended Community list number (expanded)\n"
15144 "Specify expanded extcommunity-list\n"
15145 "Extended Community list name\n")
15146
15147 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
15148 {
15149 struct community_entry *entry;
15150
15151 for (entry = list->head; entry; entry = entry->next) {
15152 if (entry == list->head) {
15153 if (all_digit(list->name))
15154 vty_out(vty, "Extended community %s list %s\n",
15155 entry->style == EXTCOMMUNITY_LIST_STANDARD
15156 ? "standard"
15157 : "(expanded) access",
15158 list->name);
15159 else
15160 vty_out(vty,
15161 "Named extended community %s list %s\n",
15162 entry->style == EXTCOMMUNITY_LIST_STANDARD
15163 ? "standard"
15164 : "expanded",
15165 list->name);
15166 }
15167 if (entry->any)
15168 vty_out(vty, " %s\n",
15169 community_direct_str(entry->direct));
15170 else
15171 vty_out(vty, " %s %s\n",
15172 community_direct_str(entry->direct),
15173 community_list_config_str(entry));
15174 }
15175 }
15176
15177 DEFUN (show_extcommunity_list,
15178 show_bgp_extcommunity_list_cmd,
15179 "show bgp extcommunity-list",
15180 SHOW_STR
15181 BGP_STR
15182 "List extended-community list\n")
15183 {
15184 struct community_list *list;
15185 struct community_list_master *cm;
15186
15187 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
15188 if (!cm)
15189 return CMD_SUCCESS;
15190
15191 for (list = cm->num.head; list; list = list->next)
15192 extcommunity_list_show(vty, list);
15193
15194 for (list = cm->str.head; list; list = list->next)
15195 extcommunity_list_show(vty, list);
15196
15197 return CMD_SUCCESS;
15198 }
15199
15200 DEFUN (show_extcommunity_list_arg,
15201 show_bgp_extcommunity_list_arg_cmd,
15202 "show bgp extcommunity-list <(1-500)|WORD> detail",
15203 SHOW_STR
15204 BGP_STR
15205 "List extended-community list\n"
15206 "Extcommunity-list number\n"
15207 "Extcommunity-list name\n"
15208 "Detailed information on extcommunity-list\n")
15209 {
15210 int idx_comm_list = 3;
15211 struct community_list *list;
15212
15213 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
15214 EXTCOMMUNITY_LIST_MASTER);
15215 if (!list) {
15216 vty_out(vty, "%% Can't find extcommunity-list\n");
15217 return CMD_WARNING;
15218 }
15219
15220 extcommunity_list_show(vty, list);
15221
15222 return CMD_SUCCESS;
15223 }
15224
15225 /* Display community-list and extcommunity-list configuration. */
15226 static int community_list_config_write(struct vty *vty)
15227 {
15228 struct community_list *list;
15229 struct community_entry *entry;
15230 struct community_list_master *cm;
15231 int write = 0;
15232
15233 /* Community-list. */
15234 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
15235
15236 for (list = cm->num.head; list; list = list->next)
15237 for (entry = list->head; entry; entry = entry->next) {
15238 vty_out(vty, "bgp community-list %s %s %s\n", list->name,
15239 community_direct_str(entry->direct),
15240 community_list_config_str(entry));
15241 write++;
15242 }
15243 for (list = cm->str.head; list; list = list->next)
15244 for (entry = list->head; entry; entry = entry->next) {
15245 vty_out(vty, "bgp community-list %s %s %s %s\n",
15246 entry->style == COMMUNITY_LIST_STANDARD
15247 ? "standard"
15248 : "expanded",
15249 list->name, community_direct_str(entry->direct),
15250 community_list_config_str(entry));
15251 write++;
15252 }
15253
15254 /* Extcommunity-list. */
15255 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
15256
15257 for (list = cm->num.head; list; list = list->next)
15258 for (entry = list->head; entry; entry = entry->next) {
15259 vty_out(vty, "bgp extcommunity-list %s %s %s\n",
15260 list->name, community_direct_str(entry->direct),
15261 community_list_config_str(entry));
15262 write++;
15263 }
15264 for (list = cm->str.head; list; list = list->next)
15265 for (entry = list->head; entry; entry = entry->next) {
15266 vty_out(vty, "bgp extcommunity-list %s %s %s %s\n",
15267 entry->style == EXTCOMMUNITY_LIST_STANDARD
15268 ? "standard"
15269 : "expanded",
15270 list->name, community_direct_str(entry->direct),
15271 community_list_config_str(entry));
15272 write++;
15273 }
15274
15275
15276 /* lcommunity-list. */
15277 cm = community_list_master_lookup(bgp_clist,
15278 LARGE_COMMUNITY_LIST_MASTER);
15279
15280 for (list = cm->num.head; list; list = list->next)
15281 for (entry = list->head; entry; entry = entry->next) {
15282 vty_out(vty, "bgp large-community-list %s %s %s\n",
15283 list->name, community_direct_str(entry->direct),
15284 community_list_config_str(entry));
15285 write++;
15286 }
15287 for (list = cm->str.head; list; list = list->next)
15288 for (entry = list->head; entry; entry = entry->next) {
15289 vty_out(vty, "bgp large-community-list %s %s %s %s\n",
15290 entry->style == LARGE_COMMUNITY_LIST_STANDARD
15291 ? "standard"
15292 : "expanded",
15293 list->name, community_direct_str(entry->direct),
15294 community_list_config_str(entry));
15295 write++;
15296 }
15297
15298 return write;
15299 }
15300
15301 static struct cmd_node community_list_node = {
15302 COMMUNITY_LIST_NODE, "", 1 /* Export to vtysh. */
15303 };
15304
15305 static void community_list_vty(void)
15306 {
15307 install_node(&community_list_node, community_list_config_write);
15308
15309 /* Community-list. */
15310 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
15311 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
15312 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
15313 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
15314 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
15315 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
15316 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
15317 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
15318
15319 /* Extcommunity-list. */
15320 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
15321 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
15322 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
15323 install_element(CONFIG_NODE,
15324 &no_bgp_extcommunity_list_standard_all_list_cmd);
15325 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
15326 install_element(CONFIG_NODE,
15327 &no_bgp_extcommunity_list_expanded_all_list_cmd);
15328 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
15329 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
15330
15331 /* Large Community List */
15332 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
15333 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
15334 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
15335 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
15336 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_all_cmd);
15337 install_element(CONFIG_NODE,
15338 &no_bgp_lcommunity_list_name_expanded_all_cmd);
15339 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
15340 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
15341 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
15342 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
15343 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
15344 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
15345 }