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